From 6556ff33ca2610d4f8ebddb750bb773f6bae4d16 Mon Sep 17 00:00:00 2001 From: Emmanuel Lacour Date: Wed, 20 Aug 2008 10:05:34 +0000 Subject: [PATCH] Upstream 3.0.1. --- README | 1 + mod_proxy_html.c | 71 +++++++++++++++++++++++++++++++------------------------- 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/README b/README index 296798b..2c2f65d 100644 --- a/README +++ b/README @@ -8,6 +8,7 @@ some new configuration. You can Include proxy_html.conf from this bundle in your httpd.conf (or apache.conf) to use Version 3 as a drop-in replacement for Version 2. + WINDOWS USERS: You may need to install some prerequisite libraries before you can diff --git a/mod_proxy_html.c b/mod_proxy_html.c index 6a4e59b..0157c2f 100644 --- a/mod_proxy_html.c +++ b/mod_proxy_html.c @@ -1,5 +1,5 @@ /******************************************************************** - Copyright (c) 2003-7, WebThing Ltd + Copyright (c) 2003-8, WebThing Ltd Author: Nick Kew This program is free software; you can redistribute it and/or modify @@ -51,11 +51,13 @@ http://apache.webthing.com/COPYING.txt #ifdef GO_FASTER #define VERBOSE(x) +#define VERBOSEB(x) #else -#define VERBOSE(x) if ( verbose ) x +#define VERBOSE(x) if (verbose) x +#define VERBOSEB(x) if (verbose) {x} #endif -#define VERSION_STRING "proxy_html/3.0.0" +#define VERSION_STRING "proxy_html/3.0.1" #include @@ -231,11 +233,15 @@ static void consume_buffer(saxctxt* ctx, const char* inbuf, switch (rv) { case APR_SUCCESS: continue; - case APR_EINCOMPLETE: /* save dangling byte(s) and return */ - ctx->conv_in->bytes = insz; - ctx->conv_in->buf = (buf != inbuf) ? buf + (bytes-insz) + case APR_EINCOMPLETE: + if (insz < 32) {/* save dangling byte(s) and return */ + ctx->conv_in->bytes = insz; + ctx->conv_in->buf = (buf != inbuf) ? buf + (bytes-insz) : apr_pmemdup(ctx->f->r->pool, buf + (bytes-insz), insz); - break; + return; + } else { /*OK, maybe 4096 wasn't big enough, and ended mid-char */ + continue; + } case APR_EINVAL: /* try skipping one bad byte */ VERBOSE( ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, ctx->f->r, "Skipping invalid byte in input stream!") ) ; @@ -249,7 +255,7 @@ static void consume_buffer(saxctxt* ctx, const char* inbuf, "Failed to convert input; trying it raw") ; htmlParseChunk(ctx->parser, buf + (bytes - insz), insz, flag) ; ctx->conv_in = NULL; /* don't try converting any more */ - break; + return; } } } @@ -386,12 +392,12 @@ static void dump_content(saxctxt* ctx) { s_to = strlen(subs) ; len = strlen(ctx->buf) ; offs += match ; - VERBOSE( { + VERBOSEB( const char* f = apr_pstrndup(ctx->f->r->pool, ctx->buf + offs , s_from ) ; ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, ctx->f->r, "C/RX: match at %s, substituting %s", f, subs) ; - } ) + ) if ( s_to > s_from) { preserve(ctx, s_to - s_from) ; memmove(ctx->buf+offs+s_to, ctx->buf+offs+s_from, @@ -1004,33 +1010,36 @@ static void fixup_rules(saxctxt* ctx) { } static saxctxt* check_filter_init (ap_filter_t* f) { saxctxt* fctx ; - proxy_html_conf* cfg + if ( ! f->ctx) { + proxy_html_conf* cfg = ap_get_module_config(f->r->per_dir_config, &proxy_html_module); - const char* force = apr_table_get(f->r->subprocess_env, "PROXY_HTML_FORCE"); - - const char* errmsg = NULL ; - if ( !force ) { - if ( ! f->r->proxyreq ) { - errmsg = "Non-proxy request; not inserting proxy-html filter" ; - } else if ( ! f->r->content_type ) { - errmsg = "No content-type; bailing out of proxy-html filter" ; - } else if ( strncasecmp(f->r->content_type, "text/html", 9) && - strncasecmp(f->r->content_type, "application/xhtml+xml", 21) ) { - errmsg = "Non-HTML content; not inserting proxy-html filter" ; + const char* force = apr_table_get(f->r->subprocess_env, "PROXY_HTML_FORCE"); + + const char* errmsg = NULL ; + if ( !force ) { + if ( ! f->r->proxyreq ) { + errmsg = "Non-proxy request; not inserting proxy-html filter" ; + } else if ( ! f->r->content_type ) { + errmsg = "No content-type; bailing out of proxy-html filter" ; + } else if ( strncasecmp(f->r->content_type, "text/html", 9) && + strncasecmp(f->r->content_type, "application/xhtml+xml", 21) ) { + errmsg = "Non-HTML content; not inserting proxy-html filter" ; + } + } + if (!cfg->links) { + errmsg = "No links configured: nothing for proxy-html filter to do"; } - } - if ( errmsg ) { + if ( errmsg ) { #ifndef GO_FASTER - if ( cfg->verbose ) { - ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, f->r, errmsg) ; - } + if ( cfg->verbose ) { + ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, f->r, errmsg) ; + } #endif - ap_remove_output_filter(f) ; - return NULL ; - } + ap_remove_output_filter(f) ; + return NULL ; + } - if ( ! f->ctx) { fctx = f->ctx = apr_pcalloc(f->r->pool, sizeof(saxctxt)) ; fctx->f = f ; fctx->bb = apr_brigade_create(f->r->pool, f->r->connection->bucket_alloc) ; -- 2.11.0