#include "apr_buckets.h" #include "apr_strings.h" #include "ap_config.h" #include "util_filter.h" #include "httpd.h" #include "http_config.h" #include "http_request.h" #include "http_core.h" #include "http_protocol.h" #include "http_log.h" #include "http_main.h" #include "util_script.h" #include "http_core.h" module AP_MODULE_DECLARE_DATA swap_module; typedef struct swap_struct { apr_bucket_brigade *bb; char *word; } swap_struct; static int swap_filter(ap_filter_t *f, apr_bucket_brigade *bb) { swap_struct *ctx = f->ctx; apr_bucket *e; apr_pool_t *p = f->r->pool; char *word1 = NULL, *word2 = NULL; if (ctx == NULL) { f->ctx = ctx = apr_pcalloc(f->r->pool, sizeof(*ctx)); ctx->bb = apr_brigade_create(f->r->pool); } else { word1 = ctx->word; } APR_BRIGADE_FOREACH(e, bb) { const char *str; apr_size_t len; if (APR_BUCKET_IS_EOS(e) || APR_BUCKET_IS_FLUSH(e)) { APR_BUCKET_REMOVE(e); APR_BRIGADE_INSERT_TAIL(ctx->bb, e); ap_pass_brigade(f->next, ctx->bb); return APR_SUCCESS; } apr_bucket_read(e, &str, &len, APR_NONBLOCK_READ); while (str && strcmp(str, "")) { if (word1 == NULL) { word1 = ap_getword_white(p, &str); if (!strcmp(str, "")) { break; } } word2 = ap_getword_white(p, &str); ap_fputstrs(f->next, ctx->bb, word2, " ", word1, NULL); word1 = word2 = NULL; } } if (word1) { ctx->word = apr_pstrdup(p, word1); } return APR_SUCCESS; } static void swap_register_hook(apr_pool_t *p) { ap_register_output_filter("SWAP", swap_filter, AP_FTYPE_CONTENT); } module AP_MODULE_DECLARE_DATA swap_module = { STANDARD20_MODULE_STUFF, NULL, /* create per-directory config structure */ NULL, /* merge per-directory config structures */ NULL, /* create per-server config structure */ NULL, /* merge per-server config structures */ NULL, /* command apr_table_t */ swap_register_hook /* register hooks */ };