|
Packit |
90a5c9 |
/* Copyright (c) 2007-11, WebThing Ltd
|
|
Packit |
90a5c9 |
* Copyright (c) 2011-, The Apache Software Foundation
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
* contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
* this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
* (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
* the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
* See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
* limitations under the License.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if defined(WIN32)
|
|
Packit |
90a5c9 |
#define XML2ENC_DECLARE_EXPORT
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include <ctype.h>
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* libxml2 */
|
|
Packit |
90a5c9 |
#include <libxml/encoding.h>
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "http_protocol.h"
|
|
Packit |
90a5c9 |
#include "http_config.h"
|
|
Packit |
90a5c9 |
#include "http_log.h"
|
|
Packit |
90a5c9 |
#include "apr_strings.h"
|
|
Packit |
90a5c9 |
#include "apr_xlate.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "apr_optional.h"
|
|
Packit |
90a5c9 |
#include "mod_xml2enc.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
module AP_MODULE_DECLARE_DATA xml2enc_module;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define BUFLEN 8192
|
|
Packit |
90a5c9 |
#define BUF_MIN 4096
|
|
Packit |
90a5c9 |
#define APR_BRIGADE_DO(b,bb) for (b = APR_BRIGADE_FIRST(bb); \
|
|
Packit |
90a5c9 |
b != APR_BRIGADE_SENTINEL(bb); \
|
|
Packit |
90a5c9 |
b = APR_BUCKET_NEXT(b))
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define ENC_INITIALISED 0x100
|
|
Packit |
90a5c9 |
#define ENC_SEEN_EOS 0x200
|
|
Packit |
90a5c9 |
#define ENC_SKIPTO ENCIO_SKIPTO
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define HAVE_ENCODING(enc) \
|
|
Packit |
90a5c9 |
(((enc)!=XML_CHAR_ENCODING_NONE)&&((enc)!=XML_CHAR_ENCODING_ERROR))
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* XXX: Check all those ap_assert()s ans replace those that should not happen
|
|
Packit |
90a5c9 |
* XXX: with AP_DEBUG_ASSERT and those that may happen with proper error
|
|
Packit |
90a5c9 |
* XXX: handling.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
typedef struct {
|
|
Packit |
90a5c9 |
xmlCharEncoding xml2enc;
|
|
Packit |
90a5c9 |
char* buf;
|
|
Packit |
90a5c9 |
apr_size_t bytes;
|
|
Packit |
90a5c9 |
apr_xlate_t* convset;
|
|
Packit |
90a5c9 |
unsigned int flags;
|
|
Packit |
90a5c9 |
apr_off_t bblen;
|
|
Packit |
90a5c9 |
apr_bucket_brigade* bbnext;
|
|
Packit |
90a5c9 |
apr_bucket_brigade* bbsave;
|
|
Packit |
90a5c9 |
const char* encoding;
|
|
Packit |
90a5c9 |
} xml2ctx;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef struct {
|
|
Packit |
90a5c9 |
const char* default_charset;
|
|
Packit |
90a5c9 |
xmlCharEncoding default_encoding;
|
|
Packit |
90a5c9 |
apr_array_header_t* skipto;
|
|
Packit |
90a5c9 |
} xml2cfg;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef struct {
|
|
Packit |
90a5c9 |
const char* val;
|
|
Packit |
90a5c9 |
} tattr;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static ap_regex_t* seek_meta_ctype;
|
|
Packit |
90a5c9 |
static ap_regex_t* seek_charset;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t xml2enc_filter(request_rec* r, const char* enc,
|
|
Packit |
90a5c9 |
unsigned int mode)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
/* set up a ready-initialised ctx to convert to enc, and insert filter */
|
|
Packit |
90a5c9 |
apr_xlate_t* convset;
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
unsigned int flags = (mode ^ ENCIO);
|
|
Packit |
90a5c9 |
if ((mode & ENCIO) == ENCIO_OUTPUT) {
|
|
Packit |
90a5c9 |
rv = apr_xlate_open(&convset, enc, "UTF-8", r->pool);
|
|
Packit |
90a5c9 |
flags |= ENC_INITIALISED;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if ((mode & ENCIO) == ENCIO_INPUT) {
|
|
Packit |
90a5c9 |
rv = apr_xlate_open(&convset, "UTF-8", enc, r->pool);
|
|
Packit |
90a5c9 |
flags |= ENC_INITIALISED;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if ((mode & ENCIO) == ENCIO_INPUT_CHECKS) {
|
|
Packit |
90a5c9 |
convset = NULL;
|
|
Packit |
90a5c9 |
rv = APR_SUCCESS; /* we'll initialise later by sniffing */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
rv = APR_EGENERAL;
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01426)
|
|
Packit |
90a5c9 |
"xml2enc: bad mode %x", mode);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (rv == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
xml2ctx* ctx = apr_pcalloc(r->pool, sizeof(xml2ctx));
|
|
Packit |
90a5c9 |
ctx->flags = flags;
|
|
Packit |
90a5c9 |
if (flags & ENC_INITIALISED) {
|
|
Packit |
90a5c9 |
ctx->convset = convset;
|
|
Packit |
90a5c9 |
ctx->bblen = BUFLEN;
|
|
Packit |
90a5c9 |
ctx->buf = apr_palloc(r->pool, (apr_size_t)ctx->bblen);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_add_output_filter("xml2enc", ctx, r, r->connection);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01427)
|
|
Packit |
90a5c9 |
"xml2enc: Charset %s not supported.", enc) ;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* This needs to operate only when we're using htmlParser */
|
|
Packit |
90a5c9 |
/* Different modules may apply different rules here. Ho, hum. */
|
|
Packit |
90a5c9 |
static void fix_skipto(request_rec* r, xml2ctx* ctx)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
xml2cfg* cfg = ap_get_module_config(r->per_dir_config, &xml2enc_module);
|
|
Packit |
90a5c9 |
if ((cfg->skipto != NULL) && (ctx->flags & ENC_SKIPTO)) {
|
|
Packit |
90a5c9 |
int found = 0;
|
|
Packit |
90a5c9 |
char* p = ap_strchr(ctx->buf, '<');
|
|
Packit |
90a5c9 |
tattr* starts = (tattr*) cfg->skipto->elts;
|
|
Packit |
90a5c9 |
while (!found && p && *p) {
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
for (i = 0; i < cfg->skipto->nelts; ++i) {
|
|
Packit |
90a5c9 |
if (!strncasecmp(p+1, starts[i].val, strlen(starts[i].val))) {
|
|
Packit |
90a5c9 |
/* found a starting element. Strip all that comes before. */
|
|
Packit |
90a5c9 |
apr_bucket* b;
|
|
Packit |
90a5c9 |
apr_bucket* bstart;
|
|
Packit |
90a5c9 |
rv = apr_brigade_partition(ctx->bbsave, (p-ctx->buf),
|
|
Packit |
90a5c9 |
&bstart);
|
|
Packit |
90a5c9 |
ap_assert(rv == APR_SUCCESS);
|
|
Packit |
90a5c9 |
while (b = APR_BRIGADE_FIRST(ctx->bbsave), b != bstart) {
|
|
Packit |
90a5c9 |
apr_bucket_delete(b);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ctx->bytes -= (p-ctx->buf);
|
|
Packit |
90a5c9 |
ctx->buf = p ;
|
|
Packit |
90a5c9 |
found = 1;
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01428)
|
|
Packit |
90a5c9 |
"Skipped to first <%s> element",
|
|
Packit |
90a5c9 |
starts[i].val) ;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
p = ap_strchr(p+1, '<');
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (p == NULL) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(01429)
|
|
Packit |
90a5c9 |
"Failed to find start of recognised HTML!");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
static void sniff_encoding(request_rec* r, xml2ctx* ctx)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
xml2cfg* cfg = NULL; /* initialise to shut compiler warnings up */
|
|
Packit |
90a5c9 |
char* p ;
|
|
Packit |
90a5c9 |
apr_bucket* cutb;
|
|
Packit |
90a5c9 |
apr_bucket* cute;
|
|
Packit |
90a5c9 |
apr_bucket* b;
|
|
Packit |
90a5c9 |
ap_regmatch_t match[2] ;
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
const char* ctype = r->content_type;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (ctype) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01430)
|
|
Packit |
90a5c9 |
"Content-Type is %s", ctype) ;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* If we've got it in the HTTP headers, there's nothing to do */
|
|
Packit |
90a5c9 |
if (ctype && (p = ap_strcasestr(ctype, "charset=") , p != NULL)) {
|
|
Packit |
90a5c9 |
p += 8 ;
|
|
Packit |
90a5c9 |
if (ctx->encoding = apr_pstrndup(r->pool, p, strcspn(p, " ;") ),
|
|
Packit |
90a5c9 |
ctx->encoding) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(01431)
|
|
Packit |
90a5c9 |
"Got charset %s from HTTP headers", ctx->encoding) ;
|
|
Packit |
90a5c9 |
ctx->xml2enc = xmlParseCharEncoding(ctx->encoding);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* to sniff, first we look for BOM */
|
|
Packit |
90a5c9 |
if (ctx->xml2enc == XML_CHAR_ENCODING_NONE) {
|
|
Packit |
90a5c9 |
ctx->xml2enc = xmlDetectCharEncoding((const xmlChar*)ctx->buf,
|
|
Packit |
90a5c9 |
ctx->bytes);
|
|
Packit |
90a5c9 |
if (HAVE_ENCODING(ctx->xml2enc)) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(01432)
|
|
Packit |
90a5c9 |
"Got charset from XML rules.") ;
|
|
Packit |
90a5c9 |
ctx->encoding = xmlGetCharEncodingName(ctx->xml2enc);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* If none of the above, look for a META-thingey */
|
|
Packit |
90a5c9 |
/* also we're probably about to invalidate it, so we remove it. */
|
|
Packit |
90a5c9 |
if (ap_regexec(seek_meta_ctype, ctx->buf, 1, match, 0) == 0 ) {
|
|
Packit |
90a5c9 |
/* get markers on the start and end of the match */
|
|
Packit |
90a5c9 |
rv = apr_brigade_partition(ctx->bbsave, match[0].rm_eo, &cute);
|
|
Packit |
90a5c9 |
ap_assert(rv == APR_SUCCESS);
|
|
Packit |
90a5c9 |
rv = apr_brigade_partition(ctx->bbsave, match[0].rm_so, &cutb);
|
|
Packit |
90a5c9 |
ap_assert(rv == APR_SUCCESS);
|
|
Packit |
90a5c9 |
/* now set length of useful buf for start-of-data hooks */
|
|
Packit |
90a5c9 |
ctx->bytes = match[0].rm_so;
|
|
Packit |
90a5c9 |
if (ctx->encoding == NULL) {
|
|
Packit |
90a5c9 |
p = apr_pstrndup(r->pool, ctx->buf + match[0].rm_so,
|
|
Packit |
90a5c9 |
match[0].rm_eo - match[0].rm_so) ;
|
|
Packit |
90a5c9 |
if (ap_regexec(seek_charset, p, 2, match, 0) == 0) {
|
|
Packit |
90a5c9 |
if (ctx->encoding = apr_pstrndup(r->pool, p+match[1].rm_so,
|
|
Packit |
90a5c9 |
match[1].rm_eo - match[1].rm_so),
|
|
Packit |
90a5c9 |
ctx->encoding) {
|
|
Packit |
90a5c9 |
ctx->xml2enc = xmlParseCharEncoding(ctx->encoding);
|
|
Packit |
90a5c9 |
if (HAVE_ENCODING(ctx->xml2enc))
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(01433)
|
|
Packit |
90a5c9 |
"Got charset %s from HTML META", ctx->encoding) ;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* cut out the <meta> we're invalidating */
|
|
Packit |
90a5c9 |
while (cutb != cute) {
|
|
Packit |
90a5c9 |
b = APR_BUCKET_NEXT(cutb);
|
|
Packit |
90a5c9 |
apr_bucket_delete(cutb);
|
|
Packit |
90a5c9 |
cutb = b;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* and leave a string */
|
|
Packit |
90a5c9 |
ctx->buf[ctx->bytes] = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* either it's set to something we found or it's still the default */
|
|
Packit |
90a5c9 |
/* Aaargh! libxml2 has undocumented <META-crap> support. So this fails
|
|
Packit |
90a5c9 |
* if metafix is not active. Have to make it conditional.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* No, that means no-metafix breaks things. Deal immediately with
|
|
Packit |
90a5c9 |
* this particular instance of metafix.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (!HAVE_ENCODING(ctx->xml2enc)) {
|
|
Packit |
90a5c9 |
cfg = ap_get_module_config(r->per_dir_config, &xml2enc_module);
|
|
Packit |
90a5c9 |
if (!ctx->encoding) {
|
|
Packit |
90a5c9 |
ctx->encoding = cfg->default_charset?cfg->default_charset:"ISO-8859-1";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* Unsupported charset. Can we get (iconv) support through apr_xlate? */
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01434)
|
|
Packit |
90a5c9 |
"Charset %s not supported by libxml2; trying apr_xlate",
|
|
Packit |
90a5c9 |
ctx->encoding);
|
|
Packit |
90a5c9 |
if (apr_xlate_open(&ctx->convset, "UTF-8", ctx->encoding, r->pool)
|
|
Packit |
90a5c9 |
== APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ctx->xml2enc = XML_CHAR_ENCODING_UTF8 ;
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01435)
|
|
Packit |
90a5c9 |
"Charset %s not supported. Consider aliasing it?",
|
|
Packit |
90a5c9 |
ctx->encoding) ;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!HAVE_ENCODING(ctx->xml2enc)) {
|
|
Packit |
90a5c9 |
/* Use configuration default as a last resort */
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(01436)
|
|
Packit |
90a5c9 |
"No usable charset information; using configuration default");
|
|
Packit |
90a5c9 |
ctx->xml2enc = (cfg->default_encoding == XML_CHAR_ENCODING_NONE)
|
|
Packit |
90a5c9 |
? XML_CHAR_ENCODING_8859_1 : cfg->default_encoding ;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (ctype && ctx->encoding) {
|
|
Packit |
90a5c9 |
if (ap_regexec(seek_charset, ctype, 2, match, 0)) {
|
|
Packit |
90a5c9 |
r->content_type = apr_pstrcat(r->pool, ctype, ";charset=utf-8",
|
|
Packit |
90a5c9 |
NULL);
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
char* str = apr_palloc(r->pool, strlen(r->content_type) + 13
|
|
Packit |
90a5c9 |
- (match[0].rm_eo - match[0].rm_so) + 1);
|
|
Packit |
90a5c9 |
memcpy(str, r->content_type, match[1].rm_so);
|
|
Packit |
90a5c9 |
memcpy(str + match[1].rm_so, "utf-8", 5);
|
|
Packit |
90a5c9 |
strcpy(str + match[1].rm_so + 5, r->content_type+match[1].rm_eo);
|
|
Packit |
90a5c9 |
r->content_type = str;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t xml2enc_filter_init(ap_filter_t* f)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
xml2ctx* ctx;
|
|
Packit |
90a5c9 |
if (!f->ctx) {
|
|
Packit |
90a5c9 |
xml2cfg* cfg = ap_get_module_config(f->r->per_dir_config,
|
|
Packit |
90a5c9 |
&xml2enc_module);
|
|
Packit |
90a5c9 |
f->ctx = ctx = apr_pcalloc(f->r->pool, sizeof(xml2ctx));
|
|
Packit |
90a5c9 |
ctx->xml2enc = XML_CHAR_ENCODING_NONE;
|
|
Packit |
90a5c9 |
if (cfg->skipto != NULL) {
|
|
Packit |
90a5c9 |
ctx->flags |= ENC_SKIPTO;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
static apr_status_t xml2enc_ffunc(ap_filter_t* f, apr_bucket_brigade* bb)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
xml2ctx* ctx = f->ctx;
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
apr_bucket* b;
|
|
Packit |
90a5c9 |
apr_bucket* bstart;
|
|
Packit |
90a5c9 |
apr_size_t insz = 0;
|
|
Packit |
90a5c9 |
int pending_meta = 0;
|
|
Packit |
90a5c9 |
char *ctype;
|
|
Packit |
90a5c9 |
char *p;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!ctx || !f->r->content_type) {
|
|
Packit |
90a5c9 |
/* log error about configuring this */
|
|
Packit |
90a5c9 |
ap_remove_output_filter(f);
|
|
Packit |
90a5c9 |
return ap_pass_brigade(f->next, bb) ;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ctype = apr_pstrdup(f->r->pool, f->r->content_type);
|
|
Packit |
90a5c9 |
for (p = ctype; *p; ++p)
|
|
Packit |
90a5c9 |
if (isupper(*p))
|
|
Packit |
90a5c9 |
*p = tolower(*p);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* only act if starts-with "text/" or contains "xml" */
|
|
Packit |
90a5c9 |
if (strncmp(ctype, "text/", 5) && !strstr(ctype, "xml")) {
|
|
Packit |
90a5c9 |
ap_remove_output_filter(f);
|
|
Packit |
90a5c9 |
return ap_pass_brigade(f->next, bb) ;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (ctx->bbsave == NULL) {
|
|
Packit |
90a5c9 |
ctx->bbsave = apr_brigade_create(f->r->pool,
|
|
Packit |
90a5c9 |
f->r->connection->bucket_alloc);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* append to any data left over from last time */
|
|
Packit |
90a5c9 |
APR_BRIGADE_CONCAT(ctx->bbsave, bb);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!(ctx->flags & ENC_INITIALISED)) {
|
|
Packit |
90a5c9 |
/* some kind of initialisation required */
|
|
Packit |
90a5c9 |
/* Turn all this off when post-processing */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* if we don't have enough data to sniff but more's to come, wait */
|
|
Packit |
90a5c9 |
apr_brigade_length(ctx->bbsave, 0, &ctx->bblen);
|
|
Packit |
90a5c9 |
if ((ctx->bblen < BUF_MIN) && (ctx->bblen != -1)) {
|
|
Packit |
90a5c9 |
APR_BRIGADE_DO(b, ctx->bbsave) {
|
|
Packit |
90a5c9 |
if (APR_BUCKET_IS_EOS(b)) {
|
|
Packit |
90a5c9 |
ctx->flags |= ENC_SEEN_EOS;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!(ctx->flags & ENC_SEEN_EOS)) {
|
|
Packit |
90a5c9 |
/* not enough data to sniff. Wait for more */
|
|
Packit |
90a5c9 |
APR_BRIGADE_DO(b, ctx->bbsave) {
|
|
Packit |
90a5c9 |
rv = apr_bucket_setaside(b, f->r->pool);
|
|
Packit |
90a5c9 |
ap_assert(rv == APR_SUCCESS);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (ctx->bblen == -1) {
|
|
Packit |
90a5c9 |
ctx->bblen = BUFLEN-1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* flatten it into a NULL-terminated string */
|
|
Packit |
90a5c9 |
ctx->buf = apr_palloc(f->r->pool, (apr_size_t)(ctx->bblen+1));
|
|
Packit |
90a5c9 |
ctx->bytes = (apr_size_t)ctx->bblen;
|
|
Packit |
90a5c9 |
rv = apr_brigade_flatten(ctx->bbsave, ctx->buf, &ctx->bytes);
|
|
Packit |
90a5c9 |
ap_assert(rv == APR_SUCCESS);
|
|
Packit |
90a5c9 |
ctx->buf[ctx->bytes] = 0;
|
|
Packit |
90a5c9 |
sniff_encoding(f->r, ctx);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* FIXME: hook here for rewriting start-of-data? */
|
|
Packit |
90a5c9 |
/* nah, we only have one action here - call it inline */
|
|
Packit |
90a5c9 |
fix_skipto(f->r, ctx);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* we might change the Content-Length, so let's force its re-calculation */
|
|
Packit |
90a5c9 |
apr_table_unset(f->r->headers_out, "Content-Length");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* consume the data we just sniffed */
|
|
Packit |
90a5c9 |
/* we need to omit any <meta> we just invalidated */
|
|
Packit |
90a5c9 |
ctx->flags |= ENC_INITIALISED;
|
|
Packit |
90a5c9 |
ap_set_module_config(f->r->request_config, &xml2enc_module, ctx);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (ctx->bbnext == NULL) {
|
|
Packit |
90a5c9 |
ctx->bbnext = apr_brigade_create(f->r->pool,
|
|
Packit |
90a5c9 |
f->r->connection->bucket_alloc);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!ctx->convset) {
|
|
Packit |
90a5c9 |
rv = ap_pass_brigade(f->next, ctx->bbsave);
|
|
Packit |
90a5c9 |
apr_brigade_cleanup(ctx->bbsave);
|
|
Packit |
90a5c9 |
ap_remove_output_filter(f);
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* move the data back to bb */
|
|
Packit |
90a5c9 |
APR_BRIGADE_CONCAT(bb, ctx->bbsave);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while (!APR_BRIGADE_EMPTY(bb)) {
|
|
Packit |
90a5c9 |
b = APR_BRIGADE_FIRST(bb);
|
|
Packit |
90a5c9 |
ctx->bytes = 0;
|
|
Packit |
90a5c9 |
if (APR_BUCKET_IS_METADATA(b)) {
|
|
Packit |
90a5c9 |
APR_BUCKET_REMOVE(b);
|
|
Packit |
90a5c9 |
APR_BRIGADE_INSERT_TAIL(ctx->bbnext, b);
|
|
Packit |
90a5c9 |
/* Besides FLUSH, aggregate meta buckets to send them at
|
|
Packit |
90a5c9 |
* once below. This resource filter is over on EOS.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
pending_meta = 1;
|
|
Packit |
90a5c9 |
if (APR_BUCKET_IS_EOS(b)) {
|
|
Packit |
90a5c9 |
ap_remove_output_filter(f);
|
|
Packit |
90a5c9 |
APR_BRIGADE_CONCAT(ctx->bbnext, bb);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!APR_BUCKET_IS_FLUSH(b)) {
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (pending_meta) {
|
|
Packit |
90a5c9 |
pending_meta = 0;
|
|
Packit |
90a5c9 |
/* passing meta bucket down the chain */
|
|
Packit |
90a5c9 |
rv = ap_pass_brigade(f->next, ctx->bbnext);
|
|
Packit |
90a5c9 |
apr_brigade_cleanup(ctx->bbnext);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* data bucket */
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char* buf;
|
|
Packit |
90a5c9 |
apr_size_t bytes = 0;
|
|
Packit |
90a5c9 |
char fixbuf[BUFLEN];
|
|
Packit |
90a5c9 |
apr_bucket* bdestroy = NULL;
|
|
Packit |
90a5c9 |
if (insz > 0) { /* we have dangling data. Flatten it. */
|
|
Packit |
90a5c9 |
buf = fixbuf;
|
|
Packit |
90a5c9 |
bytes = BUFLEN;
|
|
Packit |
90a5c9 |
rv = apr_brigade_flatten(bb, buf, &bytes);
|
|
Packit |
90a5c9 |
ap_assert(rv == APR_SUCCESS);
|
|
Packit |
90a5c9 |
if (bytes == insz) {
|
|
Packit |
90a5c9 |
/* this is only what we've already tried to convert.
|
|
Packit |
90a5c9 |
* The brigade is exhausted.
|
|
Packit |
90a5c9 |
* Save remaining data for next time round
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, f->r, APLOGNO(01437)
|
|
Packit |
90a5c9 |
"xml2enc: Setting aside %" APR_SIZE_T_FMT
|
|
Packit |
90a5c9 |
" unconverted bytes", bytes);
|
|
Packit |
90a5c9 |
rv = ap_fflush(f->next, ctx->bbnext);
|
|
Packit |
90a5c9 |
APR_BRIGADE_CONCAT(ctx->bbsave, bb);
|
|
Packit |
90a5c9 |
APR_BRIGADE_DO(b, ctx->bbsave) {
|
|
Packit |
90a5c9 |
ap_assert(apr_bucket_setaside(b, f->r->pool)
|
|
Packit |
90a5c9 |
== APR_SUCCESS);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* remove the data we've just read */
|
|
Packit |
90a5c9 |
rv = apr_brigade_partition(bb, bytes, &bstart);
|
|
Packit |
90a5c9 |
while (b = APR_BRIGADE_FIRST(bb), b != bstart) {
|
|
Packit |
90a5c9 |
apr_bucket_delete(b);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, f->r, APLOGNO(01438)
|
|
Packit |
90a5c9 |
"xml2enc: consuming %" APR_SIZE_T_FMT
|
|
Packit |
90a5c9 |
" bytes flattened", bytes);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
rv = apr_bucket_read(b, (const char**)&buf, &bytes,
|
|
Packit |
90a5c9 |
APR_BLOCK_READ);
|
|
Packit |
90a5c9 |
APR_BUCKET_REMOVE(b);
|
|
Packit |
90a5c9 |
bdestroy = b; /* can't destroy until finished with the data */
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, f->r, APLOGNO(01439)
|
|
Packit |
90a5c9 |
"xml2enc: consuming %" APR_SIZE_T_FMT
|
|
Packit |
90a5c9 |
" bytes from bucket", bytes);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* OK, we've got some input we can use in [buf,bytes] */
|
|
Packit |
90a5c9 |
if (rv == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
apr_size_t consumed;
|
|
Packit |
90a5c9 |
xml2enc_run_preprocess(f, &buf, &bytes);
|
|
Packit |
90a5c9 |
consumed = insz = bytes;
|
|
Packit |
90a5c9 |
while (insz > 0) {
|
|
Packit |
90a5c9 |
apr_status_t rv2;
|
|
Packit |
90a5c9 |
if (ctx->bytes == ctx->bblen) {
|
|
Packit |
90a5c9 |
/* nothing was converted last time!
|
|
Packit |
90a5c9 |
* break out of this loop!
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
b = apr_bucket_transient_create(buf+(bytes - insz), insz,
|
|
Packit |
90a5c9 |
bb->bucket_alloc);
|
|
Packit |
90a5c9 |
APR_BRIGADE_INSERT_HEAD(bb, b);
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, f->r, APLOGNO(01440)
|
|
Packit |
90a5c9 |
"xml2enc: reinserting %" APR_SIZE_T_FMT
|
|
Packit |
90a5c9 |
" unconsumed bytes from bucket", insz);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ctx->bytes = (apr_size_t)ctx->bblen;
|
|
Packit |
90a5c9 |
rv = apr_xlate_conv_buffer(ctx->convset, buf+(bytes - insz),
|
|
Packit |
90a5c9 |
&insz, ctx->buf, &ctx->bytes);
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, rv, f->r, APLOGNO(01441)
|
|
Packit |
90a5c9 |
"xml2enc: converted %" APR_SIZE_T_FMT
|
|
Packit |
90a5c9 |
"/%" APR_OFF_T_FMT " bytes", consumed - insz,
|
|
Packit |
90a5c9 |
ctx->bblen - ctx->bytes);
|
|
Packit |
90a5c9 |
consumed = insz;
|
|
Packit |
90a5c9 |
rv2 = ap_fwrite(f->next, ctx->bbnext, ctx->buf,
|
|
Packit |
90a5c9 |
(apr_size_t)ctx->bblen - ctx->bytes);
|
|
Packit |
90a5c9 |
if (rv2 != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, rv2, f->r, APLOGNO(01442)
|
|
Packit |
90a5c9 |
"ap_fwrite failed");
|
|
Packit |
90a5c9 |
return rv2;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
switch (rv) {
|
|
Packit |
90a5c9 |
case APR_SUCCESS:
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
case APR_EINCOMPLETE:
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, f->r, APLOGNO(01443)
|
|
Packit |
90a5c9 |
"INCOMPLETE");
|
|
Packit |
90a5c9 |
continue; /* If outbuf too small, go round again.
|
|
Packit |
90a5c9 |
* If it was inbuf, we'll break out when
|
|
Packit |
90a5c9 |
* we test ctx->bytes == ctx->bblen
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
case APR_EINVAL: /* try skipping one bad byte */
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, f->r, APLOGNO(01444)
|
|
Packit |
90a5c9 |
"Skipping invalid byte(s) in input stream!");
|
|
Packit |
90a5c9 |
--insz;
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
/* Erk! What's this?
|
|
Packit |
90a5c9 |
* Bail out, flush, and hope to eat the buf raw
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, f->r, APLOGNO(01445)
|
|
Packit |
90a5c9 |
"Failed to convert input; trying it raw") ;
|
|
Packit |
90a5c9 |
ctx->convset = NULL;
|
|
Packit |
90a5c9 |
rv = ap_fflush(f->next, ctx->bbnext);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS)
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, rv, f->r, APLOGNO(01446)
|
|
Packit |
90a5c9 |
"ap_fflush failed");
|
|
Packit |
90a5c9 |
apr_brigade_cleanup(ctx->bbnext);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, f->r, APLOGNO(01447)
|
|
Packit |
90a5c9 |
"xml2enc: error reading data") ;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (bdestroy)
|
|
Packit |
90a5c9 |
apr_bucket_destroy(bdestroy);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS)
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (pending_meta) {
|
|
Packit |
90a5c9 |
/* passing pending meta bucket down the chain before leaving */
|
|
Packit |
90a5c9 |
rv = ap_pass_brigade(f->next, ctx->bbnext);
|
|
Packit |
90a5c9 |
apr_brigade_cleanup(ctx->bbnext);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t xml2enc_charset(request_rec* r, xmlCharEncoding* encp,
|
|
Packit |
90a5c9 |
const char** encoding)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
xml2ctx* ctx = ap_get_module_config(r->request_config, &xml2enc_module);
|
|
Packit |
90a5c9 |
if (!ctx || !(ctx->flags & ENC_INITIALISED)) {
|
|
Packit |
90a5c9 |
return APR_EAGAIN;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
*encp = ctx->xml2enc;
|
|
Packit |
90a5c9 |
*encoding = ctx->encoding;
|
|
Packit |
90a5c9 |
return HAVE_ENCODING(ctx->xml2enc) ? APR_SUCCESS : APR_EGENERAL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define PROTO_FLAGS AP_FILTER_PROTO_CHANGE|AP_FILTER_PROTO_CHANGE_LENGTH
|
|
Packit |
90a5c9 |
static void xml2enc_hooks(apr_pool_t* pool)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
ap_register_output_filter_protocol("xml2enc", xml2enc_ffunc,
|
|
Packit |
90a5c9 |
xml2enc_filter_init,
|
|
Packit |
90a5c9 |
AP_FTYPE_RESOURCE, PROTO_FLAGS);
|
|
Packit |
90a5c9 |
APR_REGISTER_OPTIONAL_FN(xml2enc_filter);
|
|
Packit |
90a5c9 |
APR_REGISTER_OPTIONAL_FN(xml2enc_charset);
|
|
Packit |
90a5c9 |
seek_meta_ctype = ap_pregcomp(pool,
|
|
Packit |
90a5c9 |
"(<meta[^>]*http-equiv[ \t\r\n='\"]*content-type[^>]*>)",
|
|
Packit |
90a5c9 |
AP_REG_EXTENDED|AP_REG_ICASE) ;
|
|
Packit |
90a5c9 |
seek_charset = ap_pregcomp(pool, "charset=([A-Za-z0-9_-]+)",
|
|
Packit |
90a5c9 |
AP_REG_EXTENDED|AP_REG_ICASE) ;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
static const char* set_alias(cmd_parms* cmd, void* CFG,
|
|
Packit |
90a5c9 |
const char* charset, const char* alias)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
const char* errmsg = ap_check_cmd_context(cmd, GLOBAL_ONLY);
|
|
Packit |
90a5c9 |
if (errmsg != NULL)
|
|
Packit |
90a5c9 |
return errmsg ;
|
|
Packit |
90a5c9 |
else if (xmlAddEncodingAlias(charset, alias) == 0)
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
return "Error setting charset alias";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char* set_default(cmd_parms* cmd, void* CFG, const char* charset)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
xml2cfg* cfg = CFG;
|
|
Packit |
90a5c9 |
cfg->default_charset = charset;
|
|
Packit |
90a5c9 |
cfg->default_encoding = xmlParseCharEncoding(charset);
|
|
Packit |
90a5c9 |
switch(cfg->default_encoding) {
|
|
Packit |
90a5c9 |
case XML_CHAR_ENCODING_NONE:
|
|
Packit |
90a5c9 |
return "Default charset not found";
|
|
Packit |
90a5c9 |
case XML_CHAR_ENCODING_ERROR:
|
|
Packit |
90a5c9 |
return "Invalid or unsupported default charset";
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
static const char* set_skipto(cmd_parms* cmd, void* CFG, const char* arg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
tattr* attr;
|
|
Packit |
90a5c9 |
xml2cfg* cfg = CFG;
|
|
Packit |
90a5c9 |
if (cfg->skipto == NULL)
|
|
Packit |
90a5c9 |
cfg->skipto = apr_array_make(cmd->pool, 4, sizeof(tattr));
|
|
Packit |
90a5c9 |
attr = apr_array_push(cfg->skipto) ;
|
|
Packit |
90a5c9 |
attr->val = arg;
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const command_rec xml2enc_cmds[] = {
|
|
Packit |
90a5c9 |
AP_INIT_TAKE1("xml2EncDefault", set_default, NULL, OR_ALL,
|
|
Packit |
90a5c9 |
"Usage: xml2EncDefault charset"),
|
|
Packit |
90a5c9 |
AP_INIT_ITERATE2("xml2EncAlias", set_alias, NULL, RSRC_CONF,
|
|
Packit |
90a5c9 |
"EncodingAlias charset alias [more aliases]"),
|
|
Packit |
90a5c9 |
AP_INIT_ITERATE("xml2StartParse", set_skipto, NULL, OR_ALL,
|
|
Packit |
90a5c9 |
"Ignore anything in front of the first of these elements"),
|
|
Packit |
90a5c9 |
{ NULL }
|
|
Packit |
90a5c9 |
};
|
|
Packit |
90a5c9 |
static void* xml2enc_config(apr_pool_t* pool, char* x)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
xml2cfg* ret = apr_pcalloc(pool, sizeof(xml2cfg));
|
|
Packit |
90a5c9 |
ret->default_encoding = XML_CHAR_ENCODING_NONE ;
|
|
Packit |
90a5c9 |
return ret;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void* xml2enc_merge(apr_pool_t* pool, void* BASE, void* ADD)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
xml2cfg* base = BASE;
|
|
Packit |
90a5c9 |
xml2cfg* add = ADD;
|
|
Packit |
90a5c9 |
xml2cfg* ret = apr_pcalloc(pool, sizeof(xml2cfg));
|
|
Packit |
90a5c9 |
ret->default_encoding = (add->default_encoding == XML_CHAR_ENCODING_NONE)
|
|
Packit |
90a5c9 |
? base->default_encoding : add->default_encoding ;
|
|
Packit |
90a5c9 |
ret->default_charset = add->default_charset
|
|
Packit |
90a5c9 |
? add->default_charset : base->default_charset;
|
|
Packit |
90a5c9 |
ret->skipto = add->skipto ? add->skipto : base->skipto;
|
|
Packit |
90a5c9 |
return ret;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE_MODULE(xml2enc) = {
|
|
Packit |
90a5c9 |
STANDARD20_MODULE_STUFF,
|
|
Packit |
90a5c9 |
xml2enc_config,
|
|
Packit |
90a5c9 |
xml2enc_merge,
|
|
Packit |
90a5c9 |
NULL,
|
|
Packit |
90a5c9 |
NULL,
|
|
Packit |
90a5c9 |
xml2enc_cmds,
|
|
Packit |
90a5c9 |
xml2enc_hooks
|
|
Packit |
90a5c9 |
};
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(xml2enc, XML2ENC, int, preprocess,
|
|
Packit |
90a5c9 |
(ap_filter_t *f, char** bufp, apr_size_t* bytesp),
|
|
Packit |
90a5c9 |
(f, bufp, bytesp), OK, DECLINED)
|