28#define VERBOSE(x) if (verbose) x
29#define VERBOSEB(x) if (verbose) {x}
34#pragma clang diagnostic push
35#pragma clang diagnostic warning "-Wcomment"
36#elif defined(__GNUC__)
37#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
38#pragma GCC diagnostic push
39#pragma GCC diagnostic warning "-Wcomment"
44#include <libxml/HTMLparser.h>
47#pragma clang diagnostic pop
48#elif defined(__GNUC__)
49#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
50#pragma GCC diagnostic pop
74module AP_MODULE_DECLARE_DATA proxy_html_module;
84#define M_INTERPOLATE_TO 0x100
85#define M_INTERPOLATE_FROM 0x200
137#define NORM_MSSLASH 0x2
138#define NORM_RESET 0x4
144 "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n";
146 "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
148 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
150 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
151static const char *
const fpi_html5 =
"<!DOCTYPE html>\n";
156#define DEFAULT_ETAG html_etag
171#define consume_buffer(ctx,inbuf,bytes,flag) \
172 htmlParseChunk(ctx->parser, inbuf, bytes, flag)
174#define AP_fwrite(ctx,inbuf,bytes,flush) \
175 ap_fwrite(ctx->f->next, ctx->bb, inbuf, bytes);
178#define FLUSH AP_fwrite(ctx, (chars+begin), (i-begin), 0); begin = i+1
202 else while (
len > (
ctx->avail -
ctx->offset))
203 ctx->avail +=
ctx->cfg->bufsz;
209 (
int(*)(
void*))free);
259 "C/RX: match at %s, substituting %s",
f,
subs);
277 s_to = strlen(
m->to);
287 "C: matched %s, substituting %s",
309 if (
ctx->cfg->extfix) {
323 if (
ctx->cfg->strip_comments)
326 if (
ctx->cfg->extfix) {
341 const char *
name = (
const char*) uname;
346 if (!desc || desc->depr)
359 if (
ctx->offset > 0) {
363 if (!desc || !desc->empty) {
388 const char *
name = (
const char*) uname;
398 if (!desc || desc->depr) {
400 "Bogus HTML element %s dropped",
name);
410 "Deprecated HTML element %s dropped",
name);
426 for (
a = desc->attrs_req; *
a;
a++)
436 "Bogus HTML attribute %s of %s dropped",
441 "Deprecated HTML attribute %s of %s dropped",
465 && (
ctx->cfg->events !=
NULL)) {
466 for (
i=0;
i <
ctx->cfg->events->nelts; ++
i) {
495 "H/RX: match at %s, substituting %s",
518 s_to = strlen(
m->to);
522 "H: matched %s, substituting %s",
563 "E/RX: match at %s, substituting %s",
592 s_to = strlen(
m->to);
606 "E: matched %s, substituting %s",
637 if (
ctx->cfg->flags != 0)
650 if (desc && desc->empty)
658 "HTML element %s is missing %d required attributes",
696 if ((*
p ==
'\'') || (*
p ==
'"')) {
698 for (q =
p; *q && *q !=
delim; ++q);
703 for (q =
p; *q && !
apr_isspace(*q) && (*q !=
'>'); ++q);
718 "Adding header [%s: %s] from HTML META",
735 const char *replacement;
768 "Interpolating %s => %s",
var, replacement);
779 for (
p =
ctx->cfg->map;
p;
p =
p->next) {
780 if (
p->cond !=
NULL) {
785 "Error evaluating expr: %s",
err);
796 if (!
newp->from.c || !*
newp->from.c)
828 const char *errmsg =
NULL;
833 if (!
f->r->proxyreq) {
834 errmsg =
"Non-proxy request; not inserting proxy-html filter";
836 else if (!
f->r->content_type) {
837 errmsg =
"No content-type; bailing out of proxy-html filter";
841 "application/xhtml+xml", 21)) {
842 errmsg =
"Non-HTML content; not inserting proxy-html filter";
846 errmsg =
"No links configured: nothing for proxy-html filter to do";
860 f->r->connection->bucket_alloc);
893#ifndef USE_OLD_LIBXML2
936 if (
ctxt->rmin <
sizeof(
ctxt->rbuf)) {
953 "No i18n support found. Install mod_xml2enc if required");
962 if (*
ctxt->cfg->charset_out !=
'*')
967 "text/html;charset=",
997#ifndef USE_OLD_LIBXML2
1000 "Unsupported parser opts %x",
xmlopts);
1002 if (
ctxt->cfg->metafix)
1018 "Error in bucket read");
1089#define REGFLAG(n,s,c) ((s&&(ap_strchr_c((s),(c))!=NULL)) ? (n) : 0)
1090#define XREGFLAG(n,s,c) ((!s||(ap_strchr_c((s),(c))==NULL)) ? (n) : 0)
1092 const char *from,
const char *
to,
1093 const char *
flags,
const char *cond)
1135 if ((cond[0] ==
'!') && !
ap_strchr_c(cond,
'=')) {
1156 "Usage: ProxyHTMLURLMap from-pattern to-pattern [flags] [cond]";
1160 const char *cond =
NULL;
1186 const char *
t,
const char *l)
1209 if (l && ((l[0] ==
'x') || (l[0] ==
'X')))
1243 const char *elt,
const char *
att)
1264 "Strings to be treated as scripting events"),
1279 "Support interpolation and conditions in URLMaps"),
1295 "Enable proxy-html and xml2enc filters"),
1313 "I18n support in mod_proxy_html requires mod_xml2enc. "
1314 "Without it, non-ASCII characters in proxied pages are "
1315 "likely to display incorrectly.");
1334 static const char *
aszSucc[] = {
"mod_filter.c",
NULL };
int int const char ** match
const char apr_size_t ap_regmatch_t * pmatch
const char apr_size_t len
const char apr_size_t nmatch
char * strstr(char *s1, char *s2)
APR general purpose library routines.
APR-UTIL registration of functions exported by modules.
APR-UTIL string matching routines.
#define AP_INIT_TAKE1(directive, func, mconfig, where, help)
#define ap_get_module_config(v, m)
#define AP_INIT_ITERATE2(directive, func, mconfig, where, help)
#define AP_DECLARE_MODULE(foo)
#define AP_INIT_FLAG(directive, func, mconfig, where, help)
#define AP_INIT_ITERATE(directive, func, mconfig, where, help)
const char * ap_set_int_slot(cmd_parms *cmd, void *struct_ptr, const char *arg)
#define AP_INIT_RAW_ARGS(directive, func, mconfig, where, help)
const char * ap_set_string_slot(cmd_parms *cmd, void *struct_ptr, const char *arg)
void ap_hook_pre_config(ap_HOOK_pre_config_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
#define AP_INIT_TAKE12(directive, func, mconfig, where, help)
const char * ap_set_flag_slot(cmd_parms *cmd, void *struct_ptr, int arg)
#define AP_FILTER_PROTO_CHANGE
apr_status_t ap_fflush(ap_filter_t *f, apr_bucket_brigade *bb)
ap_filter_rec_t * ap_register_output_filter_protocol(const char *name, ap_out_filter_func filter_func, ap_init_filter_func filter_init, ap_filter_type ftype, unsigned int proto_flags)
#define ap_fputs(f, bb, str)
#define AP_FILTER_PROTO_CHANGE_LENGTH
#define ap_fputc(f, bb, c)
apr_status_t ap_pass_brigade(ap_filter_t *filter, apr_bucket_brigade *bucket)
ap_filter_t * ap_add_output_filter(const char *name, void *ctx, request_rec *r, conn_rec *c)
apr_status_t ap_fputstrs(ap_filter_t *f, apr_bucket_brigade *bb,...)
apr_status_t ap_fprintf(ap_filter_t *f, apr_bucket_brigade *bb, const char *fmt,...) __attribute__((format(printf
void ap_remove_output_filter(ap_filter_t *f)
const unsigned char * buf
void ap_set_content_type_ex(request_rec *r, const char *ct, int trusted)
void ap_set_content_type(request_rec *r, const char *ct)
void ap_hook_insert_filter(ap_HOOK_insert_filter_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
#define APR_BUCKET_IS_FLUSH(e)
#define APR_BUCKET_IS_METADATA(e)
#define APR_BRIGADE_INSERT_TAIL(b, e)
apr_file_t apr_off_t start
#define APR_BRIGADE_INSERT_HEAD(b, e)
#define APR_BUCKET_NEXT(e)
#define APR_BRIGADE_SENTINEL(b)
#define APR_BUCKET_IS_EOS(e)
apr_brigade_flush void * ctx
apr_bucket apr_bucket_brigade * a
#define APR_BRIGADE_FIRST(b)
#define apr_bucket_read(e, str, len, block)
const char apr_ssize_t int flags
const char *const const char *const * aszSucc
#define APR_RETRIEVE_OPTIONAL_FN(name)
#define apr_strmatch(pattern, s, slen)
#define ap_expr_parse_cmd(cmd, expr, flags, err, lookup_fn)
int ap_expr_exec(request_rec *r, const ap_expr_info_t *expr, const char **err)
#define STANDARD20_MODULE_STUFF
#define ap_strstr_c(s, c)
#define ap_strchr_c(s, c)
char * ap_pregsub(apr_pool_t *p, const char *input, const char *source, apr_size_t nmatch, ap_regmatch_t pmatch[])
int ap_cstr_casecmpn(const char *s1, const char *s2, apr_size_t n)
ap_regex_t * ap_pregcomp(apr_pool_t *p, const char *pattern, int cflags)
char * ap_getword_conf(apr_pool_t *p, const char **line)
const char int apr_pool_t * pool
int strcasecmp(const char *a, const char *b)
int strncasecmp(const char *a, const char *b, size_t n)
#define APR_HASH_KEY_STRING
apr_vformatter_buff_t * c
#define apr_pcalloc(p, size)
const void apr_size_t bytes
apr_int32_t apr_int32_t apr_int32_t err
const char const char *const const char *const apr_procattr_t * attr
const char const char *const * args
apr_time_t apr_int32_t offs
static void usage(process_rec *process)
static const char * set_flags(cmd_parms *cmd, void *CFG, const char *arg)
static ap_rxplus_t * old_expr
static const char * set_events(cmd_parms *cmd, void *CFG, const char *arg)
static void prepend_rbuf(saxctxt *ctxt, apr_bucket_brigade *bb)
static const char *const html_etag
static void proxy_html_insert(request_rec *r)
static const char * set_links(cmd_parms *cmd, void *CFG, const char *elt, const char *att)
#define AP_fwrite(ctx, inbuf, bytes, flush)
static apr_status_t(* xml2enc_filter)(request_rec *, const char *, unsigned int)
#define XREGFLAG(n, s, c)
static const char * comp_urlmap(cmd_parms *cmd, urlmap *newmap, const char *from, const char *to, const char *flags, const char *cond)
static void normalise(unsigned int flags, char *str)
static void pcharacters(void *ctxt, const xmlChar *uchars, int length)
static const apr_strmatch_pattern * seek_content
static saxctxt * check_filter_init(ap_filter_t *f)
static const char *const fpi_html5
static void dump_content(saxctxt *ctx)
#define M_INTERPOLATE_FROM
static const char *const DEFAULT_DOCTYPE
static const char * set_doctype(cmd_parms *cmd, void *CFG, const char *t, const char *l)
static const char *const fpi_html
static void pappend(saxctxt *ctx, const char *buf, const size_t len)
static void fixup_rules(saxctxt *ctx)
static const char *const fpi_xhtml_legacy
static apr_status_t(* xml2enc_charset)(request_rec *, xmlCharEncoding *, const char **)
static void proxy_html_hooks(apr_pool_t *p)
static void * proxy_html_merge(apr_pool_t *pool, void *BASE, void *ADD)
static void pstartElement(void *ctxt, const xmlChar *uname, const xmlChar **uattrs)
#define consume_buffer(ctx, inbuf, bytes, flag)
static htmlSAXHandler sax
static const char * interpolate_vars(request_rec *r, const char *str)
static int mod_proxy_html(apr_pool_t *p, apr_pool_t *p1, apr_pool_t *p2)
static const char * set_urlmap(cmd_parms *cmd, void *CFG, const char *args)
static void pcomment(void *ctxt, const xmlChar *uchars)
static const char *const xhtml_etag
static void pendElement(void *ctxt, const xmlChar *uname)
static meta * metafix(request_rec *r, const char *buf, apr_size_t len)
static void pcdata(void *ctxt, const xmlChar *uchars, int length)
static const char *const fpi_xhtml
static const command_rec proxy_html_cmds[]
static void preserve(saxctxt *ctx, const size_t len)
static const char *const fpi_html_legacy
static ap_regex_t * seek_meta
static void * proxy_html_config(apr_pool_t *pool, char *x)
static apr_status_t proxy_html_filter(ap_filter_t *f, apr_bucket_brigade *bb)
#define ENCIO_INPUT_CHECKS
The representation of a filter chain.
apr_bucket_alloc_t * bucket_alloc
struct apr_bucket *volatile next
apr_array_header_t * events
A structure that represents the current request.
apr_table_t * subprocess_env
struct ap_conf_vector_t * per_dir_config
apr_table_t * headers_out
int ap_rxplus_exec(apr_pool_t *pool, ap_rxplus_t *rx, const char *pattern, char **newpattern)
ap_rxplus_t * ap_rxplus_compile(apr_pool_t *pool, const char *pattern)
typedef int(WSAAPI *apr_winapi_fpt_WSAPoll)(IN OUT LPWSAPOLLFD fdArray