mod_charset_lite.c revision 2fc50921b88defeb7127985dfe4b4130175e069e
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess/* ====================================================================
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * The Apache Software License, Version 1.1
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * reserved.
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * Redistribution and use in source and binary forms, with or without
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * modification, are permitted provided that the following conditions
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * are met:
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * 1. Redistributions of source code must retain the above copyright
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * notice, this list of conditions and the following disclaimer.
2e545ce2450a9953665f701bb05350f0d3f26275nd * 2. Redistributions in binary form must reproduce the above copyright
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * notice, this list of conditions and the following disclaimer in
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * the documentation and/or other materials provided with the
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * distribution.
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen * 3. The end-user documentation included with the redistribution,
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * if any, must include the following acknowledgment:
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * "This product includes software developed by the
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * Apache Software Foundation (http://www.apache.org/)."
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * Alternately, this acknowledgment may appear in the software itself,
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * if and wherever such third-party acknowledgments normally appear.
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * 4. The names "Apache" and "Apache Software Foundation" must
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * not be used to endorse or promote products derived from this
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * software without prior written permission. For written
1c8f2418892d98febb00a06b9a4f45f8bcfd80a3nd * permission, please contact apache@apache.org.
fac8c35bfb158112226ab43ddf84d59daca5dc30nd * 5. Products derived from this software may not be called "Apache",
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen * nor may "Apache" appear in their name, without prior written
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen * permission of the Apache Software Foundation.
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * SUCH DAMAGE.
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * ====================================================================
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * This software consists of voluntary contributions made by many
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * individuals on behalf of the Apache Software Foundation. For more
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * information on the Apache Software Foundation, please see
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * Portions of this software are based upon public domain software
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * originally written at the National Center for Supercomputing Applications,
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * University of Illinois, Urbana-Champaign.
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * simple hokey charset recoding configuration module
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * See mod_ebcdic and mod_charset for more thought-out examples. This
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * one is just so Jeff can learn how a module works and experiment with
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * basic character set recoding configuration.
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * !!!This is an extremely cheap ripoff of mod_charset.c from Russian Apache!!!
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess#define OUTPUT_XLATE_BUF_SIZE (16*1024) /* size of translation buffer used on output */
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess#define INPUT_XLATE_BUF_SIZE (8*1024) /* size of translation buffer used on input */
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess#define XLATE_MIN_BUFF_LEFT 128 /* flush once there is no more than this much
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * space left in the translation buffer
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess#define FATTEST_CHAR 8 /* we don't handle chars wider than this that straddle
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * two buckets
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess/* extended error status codes; this is used in addition to an apr_status_t to
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * track errors in the translation filter
e655a84bbb62bb1c66993fda5e74b04feda14dc6kesstypedef enum {
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess EES_INIT = 0, /* no error info yet; value must be 0 for easy init */
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess EES_INCOMPLETE_CHAR, /* incomplete multi-byte char at end of content */
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess EES_DOWNSTREAM, /* something bad happened in a filter below xlate */
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess/* registered name of the output translation filter */
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess/* registered name of input translation filter */
e655a84bbb62bb1c66993fda5e74b04feda14dc6kesstypedef struct charset_dir_t {
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess /** debug level; -1 means uninitialized, 0 means no debug */
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess /** module does ap_add_*_filter()? */
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess/* charset_filter_ctx_t is created for each filter instance; because the same
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * filter code is used for translating in both directions, we need this context
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * data to tell the filter which translation handle to use; it also can hold a
e655a84bbb62bb1c66993fda5e74b04feda14dc6kess * character which was split between buckets
e655a84bbb62bb1c66993fda5e74b04feda14dc6kesstypedef struct charset_filter_ctx_t {
fac8c35bfb158112226ab43ddf84d59daca5dc30nd char buf[FATTEST_CHAR]; /* we want to be able to build a complete char here */
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen int noop; /* should we pass brigades through unchanged? */
0d0ba3a410038e179b695446bb149cce6264e0abnd apr_bucket_brigade *bb; /* input buckets we couldn't finish translating */
0d0ba3a410038e179b695446bb149cce6264e0abnd/* charset_req_t is available via r->request_config if any translation is
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh * being performed
0d0ba3a410038e179b695446bb149cce6264e0abndtypedef struct charset_req_t {
0d0ba3a410038e179b695446bb149cce6264e0abnd/* debug level definitions */
727872d18412fc021f03969b8641810d8896820bhumbedooh#define DBGLVL_FLOW 4 /* enough messages to see what happens on
0d0ba3a410038e179b695446bb149cce6264e0abnd * each request */
0d0ba3a410038e179b695446bb149cce6264e0abnd#define DBGLVL_PMC 2 /* messages about possible misconfiguration */
0d0ba3a410038e179b695446bb149cce6264e0abndstatic void *create_charset_dir_conf(apr_pool_t *p,char *dummy)
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd charset_dir_t *dc = (charset_dir_t *)apr_pcalloc(p,sizeof(charset_dir_t));
return dc;
a->debug =
a->charset_default =
a->charset_source =
a->implicit_add =
const char *name)
return NULL;
const char *name)
return NULL;
const char *flag)
flag,
NULL);
return NULL;
const char *mime_type;
return DECLINED;
return DECLINED;
sizeof(charset_req_t) +
sizeof(charset_filter_ctx_t));
return HTTP_INTERNAL_SERVER_ERROR;
switch (r->method_number) {
case M_PUT:
case M_POST:
return HTTP_INTERNAL_SERVER_ERROR;
return DECLINED;
while (filter) {
if (reqinfo) {
r->connection);
r->connection);
request_rec *r = f->r;
apr_bucket *b;
return rv;
request_rec *r = f->r;
apr_bucket *b;
return rv;
const char *partial,
return rv;
const char **cur_str,
char **out_str,
++*cur_str;
--*cur_len;
*out_str,
out_len);
return rv;
const char *msg;
int cur;
case EES_LIMIT:
case EES_BAD_INPUT:
case EES_BUCKET_READ:
case EES_INCOMPLETE_CHAR:
cur = 0;
++cur;
case EES_DOWNSTREAM:
while (curf) {
if (!last_xlate_ctx) {
char *buffer,
int *hit_eos)
const char *bucket;
*hit_eos = 0;
bucket_avail = 0;
if (consumed_bucket) {
APR_BUCKET_IS_EOS(b)) {
if (bucket_avail) {
bucket_avail = 0;
if (bucket_avail) {
if (APR_BUCKET_IS_EOS(b)) {
return rv;
const char *cur_str;
int done;
if (!ctx) {
if (reqinfo) {
chk_filter_chain(f);
done = 0;
cur_len = 0;
while (!done) {
if (consumed_bucket) {
char *tmp_tmp;
cur_len = 0;
return rv;
int hit_eos;
if (!ctx) {
if (reqinfo) {
chk_filter_chain(f);
return rv;
if (!hit_eos) {
apr_bucket *e;
return rv;
NULL,
NULL,
NULL,
{NULL}
NULL,
NULL,
cmds,