forked from pool/apache2-mod_encoding
309 lines
11 KiB
Diff
309 lines
11 KiB
Diff
--- mod_encoding.c 2002-06-11 11:07:14.000000000 +0200
|
|
+++ mod_encoding.c.oden 2006-04-15 23:18:25.000000000 +0200
|
|
@@ -10,6 +10,7 @@
|
|
#include <http_log.h>
|
|
#include <http_protocol.h>
|
|
#include <http_request.h>
|
|
+#include <apr_strings.h>
|
|
|
|
#include <iconv.h>
|
|
|
|
@@ -33,13 +34,15 @@
|
|
|
|
#define DBG(expr) if (MOD_ENCODING_DEBUG) { expr; }
|
|
|
|
-#ifdef __GNUC__
|
|
+#define LOG(...)
|
|
+/*#ifdef __GNUC__
|
|
#define LOG(level, server, args...) \
|
|
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|level, server, ##args)
|
|
+ ap_log_error(APLOG_MARK, 0, APLOG_NOERRNO|level, server, ##args)
|
|
#else
|
|
#define LOG(level, server, ...) \
|
|
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|level, server, __VA_ARGS__)
|
|
+ ap_log_error(APLOG_MARK, 0, APLOG_NOERRNO|level, server, __VA_ARGS__)
|
|
#endif
|
|
+*/
|
|
|
|
#define ENABLE_FLAG_UNSET 0
|
|
#define ENABLE_FLAG_OFF 1
|
|
@@ -55,13 +58,13 @@
|
|
typedef struct {
|
|
int enable_function; /* flag to enable this module */
|
|
char *server_encoding; /* server-side filesystem encoding */
|
|
- array_header *client_encoding; /* useragent-to-encoding-list sets */
|
|
- array_header *default_encoding; /* useragent-to-encoding-list sets */
|
|
+ apr_array_header_t *client_encoding; /* useragent-to-encoding-list sets */
|
|
+ apr_array_header_t *default_encoding; /* useragent-to-encoding-list sets */
|
|
|
|
int strip_msaccount; /* normalize wierd WinXP username */
|
|
} encoding_config;
|
|
|
|
-module MODULE_VAR_EXPORT encoding_module;
|
|
+module AP_MODULE_DECLARE_DATA encoding_module;
|
|
|
|
/***************************************************************************
|
|
* utility methods
|
|
@@ -88,7 +91,7 @@
|
|
}
|
|
|
|
/* Allocate space for conversion. Note max bloat factor is 4 of UCS-4 */
|
|
- marker = outbuf = (char *)ap_palloc(r->pool, outlen = srclen * 4 + 1);
|
|
+ marker = outbuf = (char *)apr_palloc(r->pool, outlen = srclen * 4 + 1);
|
|
|
|
if (outbuf == NULL) {
|
|
LOG(APLOG_WARNING, r->server, "iconv_string: no more memory");
|
|
@@ -140,11 +143,11 @@
|
|
|
|
/* Normalize encoding in HTTP request header(s) */
|
|
for (i = 0 ; keys[i] ; i++) {
|
|
- if ((buff = (char *)ap_table_get(r->headers_in, keys[i])) != NULL) {
|
|
+ if ((buff = (char *)apr_table_get(r->headers_in, keys[i])) != NULL) {
|
|
ap_unescape_url(buff);
|
|
if ((buff = iconv_string(r, cd, buff, strlen(buff))) == NULL)
|
|
return -1;
|
|
- ap_table_set(r->headers_in, keys[i], buff);
|
|
+ apr_table_set(r->headers_in, keys[i], buff);
|
|
}
|
|
}
|
|
|
|
@@ -159,18 +162,18 @@
|
|
* @param encmap Table of UA-to-encoding(s)
|
|
* @param lookup Name of the useragent to look for
|
|
*/
|
|
-static array_header *
|
|
+static apr_array_header_t *
|
|
get_client_encoding(request_rec *r,
|
|
- array_header *encmap, const char *lookup) {
|
|
+ apr_array_header_t *encmap, const char *lookup) {
|
|
void **list = (void **)encmap->elts;
|
|
- array_header *encs = ap_make_array(r->pool, 1, sizeof(char *));
|
|
+ apr_array_header_t *encs = apr_array_make(r->pool, 1, sizeof(char *));
|
|
|
|
int i;
|
|
|
|
LOG(APLOG_DEBUG, r->server, "get_client_encoding: entered");
|
|
|
|
/* push UTF-8 as the first candidate of expected encoding */
|
|
- *((char **)ap_push_array(encs)) = ap_pstrdup(r->pool, "UTF-8");
|
|
+ *((char **)apr_array_push(encs)) = apr_pstrdup(r->pool, "UTF-8");
|
|
|
|
if (! lookup)
|
|
return encs;
|
|
@@ -178,9 +181,9 @@
|
|
LOG(APLOG_DEBUG, r->server, "get_client_encoding: lookup == %s", lookup);
|
|
|
|
for (i = 0 ; i < encmap->nelts ; i += 2) {
|
|
- if (ap_regexec((regex_t *)list[i], lookup, 0, NULL, 0) == 0) {
|
|
+ if (ap_regexec((ap_regex_t *)list[i], lookup, 0, NULL, 0) == 0) {
|
|
LOG(APLOG_DEBUG, r->server, "get_client_encoding: entry found");
|
|
- ap_array_cat(encs, (array_header *)list[i + 1]);
|
|
+ apr_array_cat(encs, (apr_array_header_t *)list[i + 1]);
|
|
return encs;
|
|
}
|
|
}
|
|
@@ -216,7 +219,7 @@
|
|
if (! cmd->path) {
|
|
conf = ap_get_module_config(cmd->server->module_config, &encoding_module);
|
|
}
|
|
- conf->server_encoding = ap_pstrdup(cmd->pool, arg);
|
|
+ conf->server_encoding = apr_pstrdup(cmd->pool, arg);
|
|
|
|
return NULL;
|
|
}
|
|
@@ -229,7 +232,7 @@
|
|
*/
|
|
static const char *
|
|
add_client_encoding(cmd_parms *cmd, encoding_config *conf, char *args) {
|
|
- array_header *encs;
|
|
+ apr_array_header_t *encs;
|
|
char *arg;
|
|
|
|
LOG(APLOG_DEBUG, cmd->server, "add_client_encoding: entered");
|
|
@@ -239,21 +242,21 @@
|
|
conf = ap_get_module_config(cmd->server->module_config, &encoding_module);
|
|
}
|
|
|
|
- encs = ap_make_array(cmd->pool, 1, sizeof(void *));
|
|
+ encs = apr_array_make(cmd->pool, 1, sizeof(void *));
|
|
|
|
/* register useragent with UserAgent: pattern */
|
|
if (*args && (arg = ap_getword_conf_nc(cmd->pool, &args))) {
|
|
LOG(APLOG_DEBUG, cmd->server, "add_client_encoding: agent: %s", arg);
|
|
- *(void **)ap_push_array(conf->client_encoding) =
|
|
- ap_pregcomp(cmd->pool, arg, REG_EXTENDED|REG_ICASE|REG_NOSUB);
|
|
+ *(void **)apr_array_push(conf->client_encoding) =
|
|
+ ap_pregcomp(cmd->pool, arg, AP_REG_EXTENDED|AP_REG_ICASE|AP_REG_NOSUB);
|
|
}
|
|
|
|
/* register list of possible encodings from above useragent */
|
|
while (*args && (arg = ap_getword_conf_nc(cmd->pool, &args))) {
|
|
LOG(APLOG_DEBUG, cmd->server, "add_client_encoding: encname: %s", arg);
|
|
- *(void **)ap_push_array(encs) = ap_pstrdup(cmd->pool, arg);
|
|
+ *(void **)apr_array_push(encs) = apr_pstrdup(cmd->pool, arg);
|
|
}
|
|
- *(void **)ap_push_array(conf->client_encoding) = encs;
|
|
+ *(void **)apr_array_push(conf->client_encoding) = encs;
|
|
|
|
return NULL;
|
|
}
|
|
@@ -274,13 +277,13 @@
|
|
conf = ap_get_module_config(cmd->server->module_config, &encoding_module);
|
|
}
|
|
|
|
- conf->default_encoding = ap_make_array(cmd->pool, 1, sizeof(char *));
|
|
+ conf->default_encoding = apr_array_make(cmd->pool, 1, sizeof(char *));
|
|
|
|
/* register list of possible encodings as a default */
|
|
while (*args && (arg = ap_getword_conf_nc(cmd->pool, &args))) {
|
|
LOG(APLOG_DEBUG, cmd->server, "default_client_encoding: encname: %s", arg);
|
|
- *(void **)ap_push_array(conf->default_encoding)
|
|
- = ap_pstrdup(cmd->pool, arg);
|
|
+ *(void **)apr_array_push(conf->default_encoding)
|
|
+ = apr_pstrdup(cmd->pool, arg);
|
|
}
|
|
|
|
return NULL;
|
|
@@ -343,15 +346,15 @@
|
|
* Setup server-level module internal data strcuture.
|
|
*/
|
|
static void *
|
|
-server_setup(pool *p, server_rec *s) {
|
|
+server_setup(apr_pool_t *p, server_rec *s) {
|
|
encoding_config *conf;
|
|
|
|
DBG(fprintf(stderr, "server_setup: entered\n"));
|
|
|
|
- conf = (encoding_config *)ap_pcalloc(p, sizeof(encoding_config));
|
|
+ conf = (encoding_config *)apr_pcalloc(p, sizeof(encoding_config));
|
|
conf->enable_function = ENABLE_FLAG_UNSET;
|
|
conf->server_encoding = NULL;
|
|
- conf->client_encoding = ap_make_array(p, 2, sizeof(void *));
|
|
+ conf->client_encoding = apr_array_make(p, 2, sizeof(void *));
|
|
conf->default_encoding = NULL;
|
|
conf->strip_msaccount = STRIP_FLAG_UNSET;
|
|
|
|
@@ -362,7 +365,7 @@
|
|
* Setup folder-level module internal data strcuture.
|
|
*/
|
|
static void *
|
|
-folder_setup(pool *p, char *dir) {
|
|
+folder_setup(apr_pool_t *p, char *dir) {
|
|
DBG(fprintf(stderr, "folder_setup: entered\n"));
|
|
return server_setup(p, NULL);
|
|
}
|
|
@@ -371,14 +374,14 @@
|
|
* Merge configuration.
|
|
*/
|
|
static void *
|
|
-config_merge(pool *p, void *base, void *override) {
|
|
+config_merge(apr_pool_t *p, void *base, void *override) {
|
|
encoding_config *parent = base;
|
|
encoding_config *child = override;
|
|
encoding_config *merge;
|
|
|
|
DBG(fprintf(stderr, "config_merge: entered\n"));
|
|
|
|
- merge = (encoding_config *)ap_pcalloc(p, sizeof(encoding_config));
|
|
+ merge = (encoding_config *)apr_pcalloc(p, sizeof(encoding_config));
|
|
|
|
if (child->enable_function != ENABLE_FLAG_UNSET)
|
|
merge->enable_function = child->enable_function;
|
|
@@ -410,7 +413,7 @@
|
|
merge->default_encoding = parent->default_encoding;
|
|
|
|
merge->client_encoding =
|
|
- ap_append_arrays(p, child->client_encoding, parent->client_encoding);
|
|
+ apr_array_append(p, child->client_encoding, parent->client_encoding);
|
|
|
|
return merge;
|
|
}
|
|
@@ -427,7 +430,7 @@
|
|
encoding_config *conf, *dconf, *sconf;
|
|
|
|
const char *oenc; /* server-side encoding */
|
|
- array_header *ienc; /* list of possible encodings */
|
|
+ apr_array_header_t *ienc; /* list of possible encodings */
|
|
void **list; /* same as above (for iteration) */
|
|
|
|
iconv_t cd; /* conversion descriptor */
|
|
@@ -446,10 +449,10 @@
|
|
|
|
oenc = conf->server_encoding ? conf->server_encoding : "UTF-8";
|
|
ienc = get_client_encoding(r, conf->client_encoding,
|
|
- ap_table_get(r->headers_in, "User-Agent"));
|
|
+ apr_table_get(r->headers_in, "User-Agent"));
|
|
|
|
if (conf->default_encoding)
|
|
- ap_array_cat(ienc, conf->default_encoding);
|
|
+ apr_array_cat(ienc, conf->default_encoding);
|
|
|
|
list = (void **)ienc->elts;
|
|
|
|
@@ -513,15 +516,15 @@
|
|
return DECLINED;
|
|
|
|
/* Is this username broken? */
|
|
- if ((user = index(r->connection->user, '\\')) == NULL)
|
|
+ if ((user = index(r->user, '\\')) == NULL)
|
|
return DECLINED;
|
|
|
|
/* Re-generate authorization header */
|
|
if (*(user + 1)) {
|
|
buff = ap_pbase64encode(r->pool,
|
|
- ap_psprintf(r->pool, "%s:%s", user + 1, pass));
|
|
- ap_table_set(r->headers_in, "Authorization",
|
|
- ap_pstrcat(r->pool, "Basic ", buff, NULL));
|
|
+ apr_psprintf(r->pool, "%s:%s", user + 1, pass));
|
|
+ apr_table_set(r->headers_in, "Authorization",
|
|
+ apr_pstrcat(r->pool, "Basic ", buff, NULL));
|
|
|
|
ap_get_basic_auth_pw(r, &pass); /* update */
|
|
}
|
|
@@ -530,28 +533,25 @@
|
|
return DECLINED;
|
|
}
|
|
|
|
+static void register_hooks(apr_pool_t *p)
|
|
+{
|
|
+ /* filename-to-URI translation */
|
|
+/* ap_hook_translate_name(mod_enc_convert,NULL,NULL,APR_HOOK_FIRST); */
|
|
+ ap_hook_post_read_request(mod_enc_convert,NULL,NULL,APR_HOOK_FIRST);
|
|
+ ap_hook_header_parser(mod_enc_parse,NULL,NULL,APR_HOOK_FIRST);
|
|
+}
|
|
+
|
|
+
|
|
/***************************************************************************
|
|
* exported module structure
|
|
***************************************************************************/
|
|
|
|
-module MODULE_VAR_EXPORT encoding_module = {
|
|
- STANDARD_MODULE_STUFF,
|
|
- NULL, /* initializer */
|
|
- folder_setup, /* dir config */
|
|
- config_merge, /* dir config merger */
|
|
- server_setup, /* server config */
|
|
- config_merge, /* server config merger */
|
|
- mod_enc_commands, /* command table */
|
|
- NULL, /* handlers */
|
|
- NULL, /* filename translation */
|
|
- NULL, /* check_user_id */
|
|
- NULL, /* check auth */
|
|
- NULL, /* check access */
|
|
- NULL, /* type_checker */
|
|
- NULL, /* fixups */
|
|
- NULL, /* logger */
|
|
- mod_enc_parse, /* header parser */
|
|
- NULL, /* child_init */
|
|
- NULL, /* child_exit */
|
|
- mod_enc_convert, /* post read-request */
|
|
+module AP_MODULE_DECLARE_DATA encoding_module = {
|
|
+ STANDARD20_MODULE_STUFF,
|
|
+ folder_setup, /* create per-directory config structure */
|
|
+ config_merge, /* merge per-directory (?) config structure */
|
|
+ server_setup, /* create per-server config structure */
|
|
+ config_merge, /* merge per-server config */
|
|
+ mod_enc_commands, /* command hanlders */
|
|
+ register_hooks
|
|
};
|