/********************************************************************
- Copyright (c) 2003-7, WebThing Ltd
+ Copyright (c) 2003-8, WebThing Ltd
Author: Nick Kew <nick@webthing.com>
This program is free software; you can redistribute it and/or modify
#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 <ctype.h>
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!") ) ;
"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;
}
}
}
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,
}
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) ;