|
| 1 | + |
| 2 | +#include "msc_utils.h" |
| 3 | + |
| 4 | + |
| 5 | +int id(const char *fn, const char *format, ...) |
| 6 | +{ |
| 7 | + va_list args; |
| 8 | + va_start(args, format); |
| 9 | + FILE *f = fopen(fn, "a"); |
| 10 | + vfprintf(f, format, args); |
| 11 | + fclose(f); |
| 12 | + va_end(args); |
| 13 | +} |
| 14 | + |
| 15 | + |
| 16 | +/** |
| 17 | + * Sends a brigade with an error bucket down the filter chain. |
| 18 | + */ |
| 19 | +apr_status_t send_error_bucket(msc_t *msr, ap_filter_t *f, int status) |
| 20 | +{ |
| 21 | + apr_bucket_brigade *brigade = NULL; |
| 22 | + apr_bucket *bucket = NULL; |
| 23 | + |
| 24 | + /* Set the status line explicitly for the error document */ |
| 25 | + f->r->status_line = ap_get_status_line(status); |
| 26 | + |
| 27 | + brigade = apr_brigade_create(f->r->pool, f->r->connection->bucket_alloc); |
| 28 | + if (brigade == NULL) |
| 29 | + { |
| 30 | + return APR_EGENERAL; |
| 31 | + } |
| 32 | + |
| 33 | + bucket = ap_bucket_error_create(status, NULL, f->r->pool, |
| 34 | + f->r->connection->bucket_alloc); |
| 35 | + if (bucket == NULL) |
| 36 | + { |
| 37 | + return APR_EGENERAL; |
| 38 | + } |
| 39 | + |
| 40 | + APR_BRIGADE_INSERT_TAIL(brigade, bucket); |
| 41 | + |
| 42 | + bucket = apr_bucket_eos_create(f->r->connection->bucket_alloc); |
| 43 | + if (bucket == NULL) |
| 44 | + { |
| 45 | + return APR_EGENERAL; |
| 46 | + } |
| 47 | + |
| 48 | + APR_BRIGADE_INSERT_TAIL(brigade, bucket); |
| 49 | + |
| 50 | + ap_pass_brigade(f->next, brigade); |
| 51 | + |
| 52 | + /* NOTE: |
| 53 | + * It may not matter what we do from the filter as it may be too |
| 54 | + * late to even generate an error (already sent to client). Nick Kew |
| 55 | + * recommends to return APR_EGENERAL in hopes that the handler in control |
| 56 | + * will notice and do The Right Thing. So, that is what we do now. |
| 57 | + */ |
| 58 | + return APR_EGENERAL; |
| 59 | +} |
| 60 | + |
0 commit comments