1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * mod_ext_filter allows Unix-style filters to filter http content.
22 #include "http_config.h"
24 #include "http_protocol.h"
26 #include "http_core.h"
27 #include "apr_buckets.h"
28 #include "util_filter.h"
29 #include "util_script.h"
30 #include "util_time.h"
31 #include "apr_strings.h"
35 #define APR_WANT_STRFUNC
38 typedef struct ef_server_t {
43 typedef struct ef_filter_t {
45 enum {INPUT_FILTER=1, OUTPUT_FILTER} mode;
48 const char *enable_env;
49 const char *disable_env;
51 const char *intype; /* list of IMTs we process (well, just one for now) */
52 #define INTYPE_ALL (char *)1
53 const char *outtype; /* IMT of filtered output */
54 #define OUTTYPE_UNCHANGED (char *)1
55 int preserves_content_length;
58 typedef struct ef_dir_t {
63 typedef struct ef_ctx_t {
66 apr_procattr_t *procattr;
70 #if APR_FILES_AS_SOCKETS
71 apr_pollset_t *pollset;
75 module AP_MODULE_DECLARE_DATA ext_filter_module;
76 static const server_rec *main_server;
78 static apr_status_t ef_output_filter(ap_filter_t *, apr_bucket_brigade *);
79 static apr_status_t ef_input_filter(ap_filter_t *, apr_bucket_brigade *,
80 ap_input_mode_t, apr_read_type_e,
83 #define ERRFN_USERDATA_KEY "EXTFILTCHILDERRFN"
85 static void *create_ef_dir_conf(apr_pool_t *p, char *dummy)
87 ef_dir_t *dc = (ef_dir_t *)apr_pcalloc(p, sizeof(ef_dir_t));
95 static void *create_ef_server_conf(apr_pool_t *p, server_rec *s)
99 conf = (ef_server_t *)apr_pcalloc(p, sizeof(ef_server_t));
101 conf->h = apr_hash_make(conf->p);
105 static void *merge_ef_dir_conf(apr_pool_t *p, void *basev, void *overridesv)
107 ef_dir_t *a = (ef_dir_t *)apr_pcalloc (p, sizeof(ef_dir_t));
108 ef_dir_t *base = (ef_dir_t *)basev, *over = (ef_dir_t *)overridesv;
110 if (over->log_stderr != -1) { /* if admin coded something... */
111 a->log_stderr = over->log_stderr;
114 a->log_stderr = base->log_stderr;
117 if (over->onfail != -1) { /* if admin coded something... */
118 a->onfail = over->onfail;
121 a->onfail = base->onfail;
127 static const char *add_options(cmd_parms *cmd, void *in_dc,
130 ef_dir_t *dc = in_dc;
132 if (!strcasecmp(arg, "LogStderr")) {
135 else if (!strcasecmp(arg, "NoLogStderr")) {
138 else if (!strcasecmp(arg, "Onfail=remove")) {
141 else if (!strcasecmp(arg, "Onfail=abort")) {
145 return apr_pstrcat(cmd->temp_pool,
146 "Invalid ExtFilterOptions option: ",
154 static const char *parse_cmd(apr_pool_t *p, const char **args, ef_filter_t *filter)
157 const char *start = *args + 1;
162 ++*args; /* move past leading " */
163 /* find true end of args string (accounting for escaped quotes) */
164 while (**args && (**args != '"' || (**args == '"' && escaping))) {
168 else if (**args == '\\') {
174 return "Expected cmd= delimiter";
176 /* copy *just* the arg string for parsing, */
177 parms = apr_pstrndup(p, start, *args - start);
178 ++*args; /* move past trailing " */
180 /* parse and tokenize the args. */
181 rv = apr_tokenize_to_argv(parms, &(filter->args), p);
182 if (rv != APR_SUCCESS) {
183 return "cmd= parse error";
189 /* Allocate space for two argv pointers and parse the args. */
190 filter->args = (char **)apr_palloc(p, 2 * sizeof(char *));
191 filter->args[0] = ap_getword_white(p, args);
192 filter->args[1] = NULL; /* end of args */
194 if (!filter->args[0]) {
195 return "Invalid cmd= parameter";
197 filter->command = filter->args[0];
202 static const char *define_filter(cmd_parms *cmd, void *dummy, const char *args)
204 ef_server_t *conf = ap_get_module_config(cmd->server->module_config,
208 char *normalized_name;
211 name = ap_getword_white(cmd->pool, &args);
213 return "Filter name not found";
216 /* During request processing, we find information about the filter
217 * by looking up the filter name provided by core server in our
218 * hash table. But the core server has normalized the filter
219 * name by converting it to lower case. Thus, when adding the
220 * filter to our hash table we have to use lower case as well.
222 normalized_name = apr_pstrdup(cmd->pool, name);
223 ap_str_tolower(normalized_name);
225 if (apr_hash_get(conf->h, normalized_name, APR_HASH_KEY_STRING)) {
226 return apr_psprintf(cmd->pool, "ExtFilter %s is already defined",
230 filter = (ef_filter_t *)apr_pcalloc(conf->p, sizeof(ef_filter_t));
232 filter->mode = OUTPUT_FILTER;
233 filter->ftype = AP_FTYPE_RESOURCE;
234 apr_hash_set(conf->h, normalized_name, APR_HASH_KEY_STRING, filter);
237 while (apr_isspace(*args)) {
241 /* Nasty parsing... I wish I could simply use ap_getword_white()
242 * here and then look at the token, but ap_getword_white() doesn't
243 * do the right thing when we have cmd="word word word"
245 if (!strncasecmp(args, "preservescontentlength", 22)) {
246 token = ap_getword_white(cmd->pool, &args);
247 if (!strcasecmp(token, "preservescontentlength")) {
248 filter->preserves_content_length = 1;
251 return apr_psprintf(cmd->pool,
252 "mangled argument `%s'",
258 if (!strncasecmp(args, "mode=", 5)) {
260 token = ap_getword_white(cmd->pool, &args);
261 if (!strcasecmp(token, "output")) {
262 filter->mode = OUTPUT_FILTER;
264 else if (!strcasecmp(token, "input")) {
265 filter->mode = INPUT_FILTER;
268 return apr_psprintf(cmd->pool, "Invalid mode: `%s'",
274 if (!strncasecmp(args, "ftype=", 6)) {
276 token = ap_getword_white(cmd->pool, &args);
277 filter->ftype = atoi(token);
281 if (!strncasecmp(args, "enableenv=", 10)) {
283 token = ap_getword_white(cmd->pool, &args);
284 filter->enable_env = token;
288 if (!strncasecmp(args, "disableenv=", 11)) {
290 token = ap_getword_white(cmd->pool, &args);
291 filter->disable_env = token;
295 if (!strncasecmp(args, "intype=", 7)) {
297 filter->intype = ap_getword_white(cmd->pool, &args);
301 if (!strncasecmp(args, "outtype=", 8)) {
303 filter->outtype = ap_getword_white(cmd->pool, &args);
307 if (!strncasecmp(args, "cmd=", 4)) {
309 if ((token = parse_cmd(cmd->pool, &args, filter))) {
315 return apr_psprintf(cmd->pool, "Unexpected parameter: `%s'",
319 /* parsing is done... register the filter
321 if (filter->mode == OUTPUT_FILTER) {
322 /* XXX need a way to ensure uniqueness among all filters */
323 ap_register_output_filter(filter->name, ef_output_filter, NULL, filter->ftype);
325 else if (filter->mode == INPUT_FILTER) {
326 /* XXX need a way to ensure uniqueness among all filters */
327 ap_register_input_filter(filter->name, ef_input_filter, NULL, filter->ftype);
330 ap_assert(1 != 1); /* we set the field wrong somehow */
336 static const command_rec cmds[] =
338 AP_INIT_ITERATE("ExtFilterOptions",
341 ACCESS_CONF, /* same as SetInputFilter/SetOutputFilter */
342 "valid options: LogStderr, NoLogStderr"),
343 AP_INIT_RAW_ARGS("ExtFilterDefine",
347 "Define an external filter"),
351 static int ef_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *main_s)
353 main_server = main_s;
357 static void register_hooks(apr_pool_t *p)
359 ap_hook_post_config(ef_init, NULL, NULL, APR_HOOK_MIDDLE);
362 static apr_status_t set_resource_limits(request_rec *r,
363 apr_procattr_t *procattr)
365 #if defined(RLIMIT_CPU) || defined(RLIMIT_NPROC) || \
366 defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined (RLIMIT_AS)
367 core_dir_config *conf =
368 (core_dir_config *)ap_get_core_module_config(r->per_dir_config);
372 rv = apr_procattr_limit_set(procattr, APR_LIMIT_CPU, conf->limit_cpu);
373 ap_assert(rv == APR_SUCCESS); /* otherwise, we're out of sync with APR */
375 #if defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_AS)
376 rv = apr_procattr_limit_set(procattr, APR_LIMIT_MEM, conf->limit_mem);
377 ap_assert(rv == APR_SUCCESS); /* otherwise, we're out of sync with APR */
380 rv = apr_procattr_limit_set(procattr, APR_LIMIT_NPROC, conf->limit_nproc);
381 ap_assert(rv == APR_SUCCESS); /* otherwise, we're out of sync with APR */
384 #endif /* if at least one limit defined */
389 static apr_status_t ef_close_file(void *vfile)
391 return apr_file_close(vfile);
394 static void child_errfn(apr_pool_t *pool, apr_status_t err, const char *description)
398 apr_file_t *stderr_log;
400 char time_str[APR_CTIME_LEN];
402 apr_pool_userdata_get(&vr, ERRFN_USERDATA_KEY, pool);
404 apr_file_open_stderr(&stderr_log, pool);
405 ap_recent_ctime(time_str, apr_time_now());
406 apr_file_printf(stderr_log,
407 "[%s] [client %s] mod_ext_filter (%d)%s: %s\n",
411 apr_strerror(err, errbuf, sizeof(errbuf)),
415 /* init_ext_filter_process: get the external filter process going
416 * This is per-filter-instance (i.e., per-request) initialization.
418 static apr_status_t init_ext_filter_process(ap_filter_t *f)
420 ef_ctx_t *ctx = f->ctx;
422 ef_dir_t *dc = ctx->dc;
423 const char * const *env;
425 ctx->proc = apr_pcalloc(ctx->p, sizeof(*ctx->proc));
427 rc = apr_procattr_create(&ctx->procattr, ctx->p);
428 ap_assert(rc == APR_SUCCESS);
430 rc = apr_procattr_io_set(ctx->procattr,
434 ap_assert(rc == APR_SUCCESS);
436 rc = set_resource_limits(f->r, ctx->procattr);
437 ap_assert(rc == APR_SUCCESS);
439 if (dc->log_stderr > 0) {
440 rc = apr_procattr_child_err_set(ctx->procattr,
441 f->r->server->error_log, /* stderr in child */
443 ap_assert(rc == APR_SUCCESS);
446 rc = apr_procattr_child_errfn_set(ctx->procattr, child_errfn);
447 ap_assert(rc == APR_SUCCESS);
448 apr_pool_userdata_set(f->r, ERRFN_USERDATA_KEY, apr_pool_cleanup_null, ctx->p);
450 rc = apr_procattr_error_check_set(ctx->procattr, 1);
451 if (rc != APR_SUCCESS) {
455 /* add standard CGI variables as well as DOCUMENT_URI, DOCUMENT_PATH_INFO,
456 * and QUERY_STRING_UNESCAPED
458 ap_add_cgi_vars(f->r);
459 ap_add_common_vars(f->r);
460 apr_table_setn(f->r->subprocess_env, "DOCUMENT_URI", f->r->uri);
461 apr_table_setn(f->r->subprocess_env, "DOCUMENT_PATH_INFO", f->r->path_info);
463 /* QUERY_STRING is added by ap_add_cgi_vars */
464 char *arg_copy = apr_pstrdup(f->r->pool, f->r->args);
465 ap_unescape_url(arg_copy);
466 apr_table_setn(f->r->subprocess_env, "QUERY_STRING_UNESCAPED",
467 ap_escape_shell_cmd(f->r->pool, arg_copy));
470 env = (const char * const *) ap_create_environment(ctx->p,
471 f->r->subprocess_env);
473 rc = apr_proc_create(ctx->proc,
474 ctx->filter->command,
475 (const char * const *)ctx->filter->args,
476 env, /* environment */
479 if (rc != APR_SUCCESS) {
480 ap_log_rerror(APLOG_MARK, APLOG_ERR, rc, f->r, APLOGNO(01458)
481 "couldn't create child process to run `%s'",
482 ctx->filter->command);
486 apr_pool_note_subprocess(ctx->p, ctx->proc, APR_KILL_AFTER_TIMEOUT);
488 /* We don't want the handle to the child's stdin inherited by any
489 * other processes created by httpd. Otherwise, when we close our
490 * handle, the child won't see EOF because another handle will still
494 apr_pool_cleanup_register(ctx->p, ctx->proc->in,
495 apr_pool_cleanup_null, /* other mechanism */
498 #if APR_FILES_AS_SOCKETS
500 apr_pollfd_t pfd = { 0 };
502 rc = apr_pollset_create(&ctx->pollset, 2, ctx->p, 0);
503 ap_assert(rc == APR_SUCCESS);
506 pfd.desc_type = APR_POLL_FILE;
507 pfd.reqevents = APR_POLLOUT;
508 pfd.desc.f = ctx->proc->in;
509 rc = apr_pollset_add(ctx->pollset, &pfd);
510 ap_assert(rc == APR_SUCCESS);
512 pfd.reqevents = APR_POLLIN;
513 pfd.desc.f = ctx->proc->out;
514 rc = apr_pollset_add(ctx->pollset, &pfd);
515 ap_assert(rc == APR_SUCCESS);
522 static const char *get_cfg_string(ef_dir_t *dc, ef_filter_t *filter, apr_pool_t *p)
524 const char *log_stderr_str = dc->log_stderr < 1 ?
525 "NoLogStderr" : "LogStderr";
526 const char *preserve_content_length_str = filter->preserves_content_length ?
527 "PreservesContentLength" : "!PreserveContentLength";
528 const char *intype_str = !filter->intype ?
529 "*/*" : filter->intype;
530 const char *outtype_str = !filter->outtype ?
531 "(unchanged)" : filter->outtype;
533 return apr_psprintf(p,
534 "ExtFilterOptions %s %s ExtFilterInType %s "
535 "ExtFilterOuttype %s",
536 log_stderr_str, preserve_content_length_str,
537 intype_str, outtype_str);
540 static ef_filter_t *find_filter_def(const server_rec *s, const char *fname)
545 sc = ap_get_module_config(s->module_config, &ext_filter_module);
546 f = apr_hash_get(sc->h, fname, APR_HASH_KEY_STRING);
547 if (!f && s != main_server) {
549 sc = ap_get_module_config(s->module_config, &ext_filter_module);
550 f = apr_hash_get(sc->h, fname, APR_HASH_KEY_STRING);
555 static apr_status_t init_filter_instance(ap_filter_t *f)
561 f->ctx = ctx = apr_pcalloc(f->r->pool, sizeof(ef_ctx_t));
562 dc = ap_get_module_config(f->r->per_dir_config,
565 /* look for the user-defined filter */
566 ctx->filter = find_filter_def(f->r->server, f->frec->name);
568 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, f->r, APLOGNO(01459)
569 "couldn't find definition of filter '%s'",
574 if (ctx->filter->intype &&
575 ctx->filter->intype != INTYPE_ALL) {
578 if (ctx->filter->mode == INPUT_FILTER) {
579 ctypes = apr_table_get(f->r->headers_in, "Content-Type");
582 ctypes = f->r->content_type;
586 const char *ctype = ap_getword(f->r->pool, &ctypes, ';');
588 if (strcasecmp(ctx->filter->intype, ctype)) {
589 /* wrong IMT for us; don't mess with the output */
597 if (ctx->filter->enable_env &&
598 !apr_table_get(f->r->subprocess_env, ctx->filter->enable_env)) {
599 /* an environment variable that enables the filter isn't set; bail */
602 if (ctx->filter->disable_env &&
603 apr_table_get(f->r->subprocess_env, ctx->filter->disable_env)) {
604 /* an environment variable that disables the filter is set; bail */
608 rv = init_ext_filter_process(f);
609 if (rv != APR_SUCCESS) {
612 if (ctx->filter->outtype &&
613 ctx->filter->outtype != OUTTYPE_UNCHANGED) {
614 ap_set_content_type(f->r, ctx->filter->outtype);
616 if (ctx->filter->preserves_content_length != 1) {
617 /* nasty, but needed to avoid confusing the browser
619 apr_table_unset(f->r->headers_out, "Content-Length");
623 if (APLOGrtrace1(f->r)) {
624 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, f->r,
625 "%sfiltering `%s' of type `%s' through `%s', cfg %s",
626 ctx->noop ? "NOT " : "",
627 f->r->uri ? f->r->uri : f->r->filename,
628 f->r->content_type ? f->r->content_type : "(unspecified)",
629 ctx->filter->command,
630 get_cfg_string(dc, ctx->filter, f->r->pool));
636 /* drain_available_output():
638 * if any data is available from the filter, read it and append it
639 * to the the bucket brigade
641 static apr_status_t drain_available_output(ap_filter_t *f,
642 apr_bucket_brigade *bb)
644 request_rec *r = f->r;
645 conn_rec *c = r->connection;
646 ef_ctx_t *ctx = f->ctx;
653 int lvl = APLOG_TRACE5;
655 rv = apr_file_read(ctx->proc->out, buf, &len);
656 if (rv && !APR_STATUS_IS_EAGAIN(rv))
658 ap_log_rerror(APLOG_MARK, lvl, rv, r, APLOGNO(01460)
659 "apr_file_read(child output), len %" APR_SIZE_T_FMT,
661 if (rv != APR_SUCCESS) {
664 b = apr_bucket_heap_create(buf, len, NULL, c->bucket_alloc);
665 APR_BRIGADE_INSERT_TAIL(bb, b);
668 /* we should never get here; if we do, a bogus error message would be
669 * the least of our problems
671 return APR_ANONYMOUS;
674 static apr_status_t pass_data_to_filter(ap_filter_t *f, const char *data,
675 apr_size_t len, apr_bucket_brigade *bb)
677 ef_ctx_t *ctx = f->ctx;
679 apr_size_t bytes_written = 0;
683 tmplen = len - bytes_written;
684 rv = apr_file_write(ctx->proc->in,
685 (const char *)data + bytes_written,
687 bytes_written += tmplen;
688 if (rv != APR_SUCCESS && !APR_STATUS_IS_EAGAIN(rv)) {
689 ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, f->r, APLOGNO(01461)
690 "apr_file_write(child input), len %" APR_SIZE_T_FMT,
694 if (APR_STATUS_IS_EAGAIN(rv)) {
695 /* XXX handle blocking conditions here... if we block, we need
696 * to read data from the child process and pass it down to the
699 rv = drain_available_output(f, bb);
700 if (APR_STATUS_IS_EAGAIN(rv)) {
701 #if APR_FILES_AS_SOCKETS
703 const apr_pollfd_t *pdesc;
705 rv = apr_pollset_poll(ctx->pollset, f->r->server->timeout,
706 &num_events, &pdesc);
707 if (rv != APR_SUCCESS && !APR_STATUS_IS_EINTR(rv)) {
708 ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, f->r, APLOGNO(01462)
709 "apr_pollset_poll()");
710 /* some error such as APR_TIMEUP */
713 ap_log_rerror(APLOG_MARK, APLOG_TRACE6, rv, f->r,
714 "apr_pollset_poll()");
715 #else /* APR_FILES_AS_SOCKETS */
716 /* Yuck... I'd really like to wait until I can read
717 * or write, but instead I have to sleep and try again
719 apr_sleep(100000); /* 100 milliseconds */
720 ap_log_rerror(APLOG_MARK, APLOG_TRACE6, 0, f->r, "apr_sleep()");
721 #endif /* APR_FILES_AS_SOCKETS */
723 else if (rv != APR_SUCCESS) {
727 } while (bytes_written < len);
731 /* ef_unified_filter:
733 * runs the bucket brigade bb through the filter and puts the result into
734 * bb, dropping the previous content of bb (the input)
737 static int ef_unified_filter(ap_filter_t *f, apr_bucket_brigade *bb)
739 request_rec *r = f->r;
740 conn_rec *c = r->connection;
741 ef_ctx_t *ctx = f->ctx;
747 apr_bucket *eos = NULL;
748 apr_bucket_brigade *bb_tmp;
750 bb_tmp = apr_brigade_create(r->pool, c->bucket_alloc);
752 for (b = APR_BRIGADE_FIRST(bb);
753 b != APR_BRIGADE_SENTINEL(bb);
754 b = APR_BUCKET_NEXT(b))
756 if (APR_BUCKET_IS_EOS(b)) {
761 rv = apr_bucket_read(b, &data, &len, APR_BLOCK_READ);
762 if (rv != APR_SUCCESS) {
763 ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01463) "apr_bucket_read()");
767 /* Good cast, we just tested len isn't negative */
769 (rv = pass_data_to_filter(f, data, (apr_size_t)len, bb_tmp))
775 apr_brigade_cleanup(bb);
776 APR_BRIGADE_CONCAT(bb, bb_tmp);
777 apr_brigade_destroy(bb_tmp);
780 /* close the child's stdin to signal that no more data is coming;
781 * that will cause the child to finish generating output
783 if ((rv = apr_file_close(ctx->proc->in)) != APR_SUCCESS) {
784 ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01464)
785 "apr_file_close(child input)");
788 /* since we've seen eos and closed the child's stdin, set the proper pipe
789 * timeout; we don't care if we don't return from apr_file_read() for a while...
791 rv = apr_file_pipe_timeout_set(ctx->proc->out,
794 ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01465)
795 "apr_file_pipe_timeout_set(child output)");
801 int lvl = APLOG_TRACE6;
803 rv = apr_file_read(ctx->proc->out, buf, &len);
804 if (rv && !APR_STATUS_IS_EOF(rv) && !APR_STATUS_IS_EAGAIN(rv))
806 ap_log_rerror(APLOG_MARK, lvl, rv, r, APLOGNO(01466)
807 "apr_file_read(child output), len %" APR_SIZE_T_FMT,
809 if (APR_STATUS_IS_EAGAIN(rv)) {
811 /* should not occur, because we have an APR timeout in place */
812 AP_DEBUG_ASSERT(1 != 1);
817 if (rv == APR_SUCCESS) {
818 b = apr_bucket_heap_create(buf, len, NULL, c->bucket_alloc);
819 APR_BRIGADE_INSERT_TAIL(bb, b);
821 } while (rv == APR_SUCCESS);
823 if (!APR_STATUS_IS_EOF(rv)) {
828 b = apr_bucket_eos_create(c->bucket_alloc);
829 APR_BRIGADE_INSERT_TAIL(bb, b);
835 static apr_status_t ef_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
837 request_rec *r = f->r;
838 ef_ctx_t *ctx = f->ctx;
842 if ((rv = init_filter_instance(f)) != APR_SUCCESS) {
844 ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01467)
845 "can't initialise output filter %s: %s",
847 (ctx->dc->onfail == 1) ? "removing" : "aborting");
848 ap_remove_output_filter(f);
849 if (ctx->dc->onfail == 1) {
850 return ap_pass_brigade(f->next, bb);
854 f->r->status_line = "500 Internal Server Error";
856 apr_brigade_cleanup(bb);
857 e = ap_bucket_error_create(HTTP_INTERNAL_SERVER_ERROR,
860 APR_BRIGADE_INSERT_TAIL(bb, e);
861 e = apr_bucket_eos_create(f->c->bucket_alloc);
862 APR_BRIGADE_INSERT_TAIL(bb, e);
863 ap_pass_brigade(f->next, bb);
864 return AP_FILTER_ERROR;
870 ap_remove_output_filter(f);
871 return ap_pass_brigade(f->next, bb);
874 rv = ef_unified_filter(f, bb);
875 if (rv != APR_SUCCESS) {
876 ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01468)
877 "ef_unified_filter() failed");
880 if ((rv = ap_pass_brigade(f->next, bb)) != APR_SUCCESS) {
881 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, rv, r, APLOGNO(01469)
882 "ap_pass_brigade() failed");
887 static int ef_input_filter(ap_filter_t *f, apr_bucket_brigade *bb,
888 ap_input_mode_t mode, apr_read_type_e block,
891 ef_ctx_t *ctx = f->ctx;
895 if ((rv = init_filter_instance(f)) != APR_SUCCESS) {
897 ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, f->r, APLOGNO(01470)
898 "can't initialise input filter %s: %s",
900 (ctx->dc->onfail == 1) ? "removing" : "aborting");
901 ap_remove_input_filter(f);
902 if (ctx->dc->onfail == 1) {
903 return ap_get_brigade(f->next, bb, mode, block, readbytes);
906 f->r->status = HTTP_INTERNAL_SERVER_ERROR;
907 return HTTP_INTERNAL_SERVER_ERROR;
914 ap_remove_input_filter(f);
915 return ap_get_brigade(f->next, bb, mode, block, readbytes);
918 rv = ap_get_brigade(f->next, bb, mode, block, readbytes);
919 if (rv != APR_SUCCESS) {
923 rv = ef_unified_filter(f, bb);
927 AP_DECLARE_MODULE(ext_filter) =
929 STANDARD20_MODULE_STUFF,
932 create_ef_server_conf,