21#define XML2ENC_DECLARE_EXPORT
28#pragma clang diagnostic push
29#pragma clang diagnostic warning "-Wcomment"
30#elif defined(__GNUC__)
31#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
32#pragma GCC diagnostic push
33#pragma GCC diagnostic warning "-Wcomment"
38#include <libxml/encoding.h>
41#pragma clang diagnostic pop
42#elif defined(__GNUC__)
43#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
44#pragma GCC diagnostic pop
57module AP_MODULE_DECLARE_DATA xml2enc_module;
61#define APR_BRIGADE_DO(b,bb) for (b = APR_BRIGADE_FIRST(bb); \
62 b != APR_BRIGADE_SENTINEL(bb); \
63 b = APR_BUCKET_NEXT(b))
65#define ENC_INITIALISED 0x100
66#define ENC_SEEN_EOS 0x200
67#define ENC_SKIPTO ENCIO_SKIPTO
69#define HAVE_ENCODING(enc) \
70 (((enc)!=XML_CHAR_ENCODING_NONE)&&((enc)!=XML_CHAR_ENCODING_ERROR))
124 "xml2enc: bad mode %x",
mode);
130 ctx->convset = convset;
138 "xml2enc: Charset %s not supported.", enc) ;
170 "Skipped to first <%s> element",
179 "Failed to find start of recognised HTML!");
196 "Content-Type is %s", ctype) ;
204 "Got charset %s from HTTP headers",
ctx->encoding) ;
216 "Got charset from XML rules.") ;
241 "Got charset %s from HTML META",
ctx->encoding) ;
265 if (!
ctx->encoding) {
270 "Charset %s not supported by libxml2; trying apr_xlate",
277 "Charset %s not supported. Consider aliasing it?",
285 "No usable charset information; using configuration default");
289 if (ctype &&
ctx->encoding) {
329 if (!
ctx || !
f->r->content_type) {
343 || (strlen(
mtype) > 7
345 && strlen(
p) == 4 ))) {
352 f->r->connection->bucket_alloc);
379 if (
ctx->bblen == -1) {
405 f->r->connection->bucket_alloc);
464 " unconverted bytes",
bytes);
480 " bytes flattened",
bytes);
489 " bytes from bucket",
bytes);
498 if (
ctx->bytes ==
ctx->bblen) {
507 " unconsumed bytes from bucket",
insz);
537 "Skipping invalid byte(s) in input stream!");
545 "Failed to convert input; trying it raw") ;
556 "xml2enc: error reading data") ;
588#define PROTO_FLAGS AP_FILTER_PROTO_CHANGE|AP_FILTER_PROTO_CHANGE_LENGTH
597 "(<meta[^>]*http-equiv[ \t\r\n='\"]*content-type[^>]*>)",
603 const char* charset,
const char* alias)
611 return "Error setting charset alias";
621 return "Default charset not found";
623 return "Invalid or unsupported default charset";
641 "Usage: xml2EncDefault charset"),
643 "EncodingAlias charset alias [more aliases]"),
645 "Ignore anything in front of the first of these elements"),
int int const char ** match
char * strstr(char *s1, char *s2)
APR-UTIL registration of functions exported by modules.
APR I18N translation library.
#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_ITERATE(directive, func, mconfig, where, help)
#define ap_set_module_config(v, m, val)
#define ap_fwrite(f, bb, data, nbyte)
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)
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)
void ap_remove_output_filter(ap_filter_t *f)
const unsigned char * buf
#define APR_BUCKET_IS_FLUSH(e)
#define APR_BUCKET_REMOVE(e)
#define APR_BUCKET_IS_METADATA(e)
#define APR_BRIGADE_INSERT_TAIL(b, e)
#define APR_BRIGADE_INSERT_HEAD(b, e)
#define APR_BUCKET_NEXT(e)
#define APR_BRIGADE_CONCAT(a, b)
#define APR_BRIGADE_EMPTY(b)
#define apr_bucket_delete(e)
#define APR_BUCKET_IS_EOS(e)
apr_brigade_flush void * ctx
#define apr_bucket_setaside(e, p)
#define APR_BRIGADE_FIRST(b)
#define apr_bucket_read(e, str, len, block)
#define apr_bucket_destroy(e)
apr_dbd_transaction_t int mode
const char apr_ssize_t int flags
#define APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ns, link, ret, name, args_decl, args_use, ok, decline)
#define APR_REGISTER_OPTIONAL_FN(name)
struct apr_xlate_t apr_xlate_t
#define STANDARD20_MODULE_STUFF
char * ap_strcasestr(const char *s1, const char *s2)
void ap_str_tolower(char *s)
ap_regex_t * ap_pregcomp(apr_pool_t *p, const char *pattern, int cflags)
const char * ap_check_cmd_context(cmd_parms *cmd, unsigned forbidden)
const char int apr_pool_t * pool
int strncasecmp(const char *a, const char *b, size_t n)
#define apr_pcalloc(p, size)
const void apr_size_t bytes
const char const char *const const char *const apr_procattr_t * attr
static apr_status_t(* xml2enc_filter)(request_rec *, const char *, unsigned int)
static apr_status_t(* xml2enc_charset)(request_rec *, xmlCharEncoding *, const char **)
static apr_status_t xml2enc_ffunc(ap_filter_t *f, apr_bucket_brigade *bb)
static ap_regex_t * seek_charset
static void * xml2enc_merge(apr_pool_t *pool, void *BASE, void *ADD)
int xml2enc_run_preprocess(ap_filter_t *f, char **bufp, apr_size_t *bytesp)
static void sniff_encoding(request_rec *r, xml2ctx *ctx)
static const char * set_alias(cmd_parms *cmd, void *CFG, const char *charset, const char *alias)
static const char * set_skipto(cmd_parms *cmd, void *CFG, const char *arg)
static void * xml2enc_config(apr_pool_t *pool, char *x)
static void fix_skipto(request_rec *r, xml2ctx *ctx)
#define HAVE_ENCODING(enc)
static const char * set_default(cmd_parms *cmd, void *CFG, const char *charset)
static ap_regex_t * seek_meta_ctype
static void xml2enc_hooks(apr_pool_t *pool)
#define APR_BRIGADE_DO(b, bb)
static apr_status_t xml2enc_filter_init(ap_filter_t *f)
static const command_rec xml2enc_cmds[]
#define ENCIO_INPUT_CHECKS
The representation of a filter chain.
apr_bucket_alloc_t * bucket_alloc
A structure that represents the current request.
const char * content_type
struct ap_conf_vector_t * request_config
struct ap_conf_vector_t * per_dir_config
apr_array_header_t * skipto
const char * default_charset
xmlCharEncoding default_encoding
apr_bucket_brigade * bbnext
apr_bucket_brigade * bbsave