/*
- * Copyright (C) 2005-2009 Atsushi Konno All rights reserved.
+ * Copyright (C) 2005-2011 Atsushi Konno All rights reserved.
* Copyright (C) 2005 QSDN,Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
chxj_headers_fixup(request_rec *r)
{
mod_chxj_config* dconf;
+ mod_chxj_req_config *request_conf;
chxjconvrule_entry* entryp;
char* user_agent;
device_table* spec;
char *contentType;
char *contentLength;
- DBG(r, "REQ[%X] start chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] start %s()", TO_ADDR(r), __func__);
if (r->main) {
- DBG(r, "REQ[%X] detect internal redirect.", (unsigned int)(apr_size_t)r);
- DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] detect internal redirect.", TO_ADDR(r));
+ DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
return DECLINED;
}
+ request_conf = (mod_chxj_req_config *)chxj_get_module_config(r->request_config, &chxj_module);
+ if (!request_conf) {
+ request_conf = apr_palloc(r->pool, sizeof(mod_chxj_req_config));
+ request_conf->spec = NULL;
+ request_conf->user_agent = NULL;
+ request_conf->f = NULL;
+ chxj_set_module_config(r->request_config, &chxj_module, request_conf);
+ }
dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
+
+ /*
+ * check and get mobile type.
+ * and request_conf->user_agent , request_conf->spec is set.
+ */
spec = chxj_specified_device(r, user_agent);
contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
if (contentType
&& strncasecmp("multipart/form-data", contentType, 19) == 0) {
- DBG(r, "REQ[%X] detect multipart/form-data ==> no target", (unsigned int)(apr_size_t)r);
- DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] detect multipart/form-data ==> no target", TO_ADDR(r));
+ DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
return DECLINED;
}
case CHXJ_SPEC_Jhtml:
case CHXJ_SPEC_Jxhtml:
entryp = chxj_apply_convrule(r, dconf->convrules);
- if (! entryp) {
- DBG(r, "REQ[%X] end chxj_headers_fixup() (no pattern)", (unsigned int)(apr_size_t)r);
- return DECLINED;
- }
- if (!(entryp->action & CONVRULE_ENGINE_ON_BIT) && !(entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
- DBG(r, "REQ[%X] end chxj_headers_fixup() (engine off)", (unsigned int)(apr_size_t)r);
- return DECLINED;
- }
- if (entryp->action & CONVRULE_EMOJI_ONLY_BIT) {
- DBG(r, "REQ[%X] end chxj_headers_fixup() (emoji only)", (unsigned int)(apr_size_t)r);
- return DECLINED;
+ if (dconf->image != CHXJ_IMG_ON) {
+ if (! entryp) {
+ DBG(r, "REQ[%X] end %s() (no pattern)", TO_ADDR(r), __func__);
+ return DECLINED;
+ }
+ if (!(entryp->action & CONVRULE_ENGINE_ON_BIT) && !(entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
+ DBG(r, "REQ[%X] end %s() (engine off)", TO_ADDR(r), __func__);
+ return DECLINED;
+ }
+ if (entryp->action & CONVRULE_EMOJI_ONLY_BIT) {
+ DBG(r, "REQ[%X] end %s() (emoji only)", TO_ADDR(r), __func__);
+ return DECLINED;
+ }
}
-
apr_table_setn(r->headers_in,
CHXJ_HTTP_USER_AGENT,
user_agent);
- if (entryp->user_agent)
+ if (entryp && entryp->user_agent)
apr_table_setn(r->headers_in,
HTTP_USER_AGENT,
entryp->user_agent);
/*
* this clear process must do before chxj_convert_input_header function.
*/
- if ((entryp->action & CONVRULE_COOKIE_ON_BIT) || (entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
- if (r->method_number == M_POST) {
- if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
+ if (entryp) {
+ if ((entryp->action & CONVRULE_COOKIE_ON_BIT) || (entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
+ if (r->method_number == M_POST) {
+ if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
+ s_clear_cookie_header(r, spec);
+ }
+ }
+ else {
s_clear_cookie_header(r, spec);
}
}
- else {
- s_clear_cookie_header(r, spec);
- }
}
chxj_convert_input_header(r,entryp, spec);
break;
default:
- DBG(r, "REQ[%X] end chxj_headers_fixup() (not mobile) spec->device_name[%s] User-Agent:[%s]", (unsigned int)(apr_size_t)r, spec->device_name, user_agent);
+ DBG(r, "REQ[%X] end %s() (not mobile) spec->device_name[%s] User-Agent:[%s]", TO_ADDR(r),__func__, spec->device_name, user_agent);
return DECLINED;
}
+ char *x_client_type = (char *)apr_table_get(r->headers_out, "X-Client-Type");
+ apr_table_unset(r->headers_out, "X-Client-Type");
+ if (x_client_type) {
+ apr_table_setn(r->headers_in, "X-Client-Type", x_client_type);
+ }
+ else {
+ apr_table_setn(r->headers_in, "X-Client-Type", "");
+ }
if (r->method_number == M_POST) {
if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
- DBG(r, "REQ[%X] set Input handler old:[%s] proxyreq:[%d] uri:[%s] filename:[%s]", (unsigned int)(apr_size_t)r, r->handler, r->proxyreq, r->uri, r->filename);
- r->proxyreq = PROXYREQ_NONE;
- r->handler = apr_psprintf(r->pool, "chxj-input-handler");
+ DBG(r, "REQ[%X] set Input handler old:[%s] proxyreq:[%d] uri:[%s] filename:[%s]", TO_ADDR(r), r->handler, r->proxyreq, r->uri, r->filename);
+ r->proxyreq = PROXYREQ_NONE;
+ r->handler = apr_psprintf(r->pool, "chxj-input-handler");
}
else {
char *client_ip = (char *)apr_table_get(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP);
apr_status_t rv = apr_sockaddr_info_get(&address, ap_get_server_name(r), APR_UNSPEC, ap_get_server_port(r), 0, r->pool);
if (rv != APR_SUCCESS) {
char buf[256];
- ERR(r, "REQ[%X] %s:%d apr_sockaddr_info_get() failed: rv:[%d|%s]", (unsigned int)(apr_size_t)r, APLOG_MARK, rv, apr_strerror(rv, buf, 256));
- DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
+ ERR(r, "REQ[%X] %s:%d apr_sockaddr_info_get() failed: rv:[%d|%s]", TO_ADDR(r), APLOG_MARK, rv, apr_strerror(rv, buf, 256));
+ DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
return DECLINED;
}
char *addr;
else {
apr_sockaddr_ip_get(&addr, address);
}
- DBG(r, "REQ[%X] Client IP:[%s] vs Orig Client IP:[%s] vs Server IP:[%s]", (unsigned int)(apr_size_t)r, r->connection->remote_ip, client_ip, addr);
+ DBG(r, "REQ[%X] Client IP:[%s] vs Orig Client IP:[%s] vs Server IP:[%s]", TO_ADDR(r), r->connection->remote_ip, client_ip, addr);
if (strcmp(addr, r->connection->remote_ip) == 0) {
r->connection->remote_ip = apr_pstrdup(r->connection->pool, client_ip);
+ /* For mod_cidr_lookup */
+ if (entryp && (entryp->action & CONVRULE_OVERWRITE_X_CLIENT_TYPE_BIT)) {
+ char *client_type = (char *)apr_table_get(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_TYPE);
+ DBG(r, "REQ[%X] Overwrite X-Client-Type to [%s]", TO_ADDR(r), client_type);
+ if (client_type) {
+ apr_table_setn(r->subprocess_env, "X_CLIENT_TYPE", client_type);
+ apr_table_setn(r->headers_in, "X-Client-Type", client_type);
+ }
+ else {
+ apr_table_unset(r->headers_in, "X-Client-Type");
+ }
+ }
}
if (! apr_table_get(r->headers_in, "Content-Length")) {
contentLength = (char *)apr_table_get(r->headers_in, "X-Chxj-Content-Length");
}
}
else{
- if(strncmp(r->content_type,"image/",6) == 0){
+ if(r->content_type && strncmp(r->content_type,"image/",6) == 0){
if (dconf->image_rewrite == CHXJ_IMG_REWRITE_ON && !apr_table_get(r->headers_in, CHXJ_IMG_X_HTTP_IMAGE_FILENAME)){
if(dconf->image_rewrite_mode == CHXJ_IMG_REWRITE_MODE_ALL){
// all image
chxj_add_device_env(r, spec);
- DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
return DECLINED;
}
if (strncmp(r->filename, "img-redirect:", 13) != 0) {
return DECLINED;
}
- DBG(r,"start chxj_image_redirect_handler");
+ DBG(r,"REQ[%X] start %s()",TO_ADDR(r),__func__);
ap_internal_redirect(apr_pstrcat(r->pool, r->filename+13,
r->args ? "?" : NULL, r->args, NULL), r);
- DBG(r,"end chxj_image_redirect_handler");
+ DBG(r,"REQ[%X] end %s()", TO_ADDR(r),__func__);
return OK;
}
static void
s_clear_cookie_header(request_rec *r, device_table *spec)
{
- DBG(r, "REQ[%X] start s_clear_cookie_header()", TO_ADDR(r));
+ DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
switch(spec->html_spec_type) {
case CHXJ_SPEC_Chtml_1_0:
case CHXJ_SPEC_Chtml_2_0:
case CHXJ_SPEC_Chtml_7_0:
case CHXJ_SPEC_XHtml_Mobile_1_0:
case CHXJ_SPEC_Jhtml:
+ case CHXJ_SPEC_Jxhtml:
apr_table_unset(r->headers_in, "Cookie");
break;
default:
break;
}
- DBG(r, "REQ[%X] end s_clear_cookie_header()", TO_ADDR(r));
+ DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
}
char *tmp;
cookie_t *cookie;
mod_chxj_config *dconf;
+ mod_chxj_req_config *request_conf;
chxjconvrule_entry *entryp;
- DBG(r,"REQ[%X] start of chxj_convert()", (unsigned int)(apr_size_t)r);
+ DBG(r,"REQ[%X] start %s()", TO_ADDR(r),__func__);
chxj_dump_string(r, APLOG_MARK, "INPUT Data", *src, *len);
dst = apr_pstrcat(r->pool, (char *)*src, NULL);
dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
+ request_conf = chxj_get_module_config(r->request_config, &chxj_module);
entryp = chxj_apply_convrule(r, dconf->convrules);
if (!entryp || (!(entryp->action & CONVRULE_ENGINE_ON_BIT) && !(entryp->action & CONVRULE_COOKIE_ONLY_BIT))) {
- DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
+ DBG(r,"REQ[%X] end %s()", TO_ADDR(r),__func__);
return (char *)*src;
}
else
user_agent = (char *)apr_table_get(r->headers_in, HTTP_USER_AGENT);
- DBG(r,"REQ[%X] User-Agent:[%s]", (unsigned int)(apr_size_t)r, user_agent);
- DBG(r,"REQ[%X] content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
+ DBG(r,"REQ[%X] User-Agent:[%s]", TO_ADDR(r), user_agent);
+ DBG(r,"REQ[%X] content type is [%s]", TO_ADDR(r), r->content_type);
if ( ! STRNCASEEQ('t','T', "text/html", r->content_type, sizeof("text/html")-1)
&& ! STRNCASEEQ('a','A', "application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)) {
- DBG(r,"REQ[%X] no convert. content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
- DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
+ DBG(r,"REQ[%X] no convert. content type is [%s]", TO_ADDR(r), r->content_type);
+ DBG(r,"REQ[%X] end %s()", TO_ADDR(r),__func__);
return (char *)*src;
}
/* again */
spec = chxj_specified_device(r, user_agent);
}
+ else {
+ spec = request_conf->spec;
+ }
/*
* save cookie.
case CHXJ_SPEC_Chtml_7_0:
case CHXJ_SPEC_XHtml_Mobile_1_0:
case CHXJ_SPEC_Jhtml:
+ case CHXJ_SPEC_Jxhtml:
cookie = chxj_save_cookie(r);
break;
default:
if (!r->header_only) {
- if ((entryp->action & CONVRULE_COOKIE_ONLY_BIT) && cookie) {
- dst = chxj_cookie_only_mode(r, *src, (apr_size_t *)len, cookie);
+ if ((entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
+ if (cookie) {
+ dst = chxj_cookie_only_mode(r, *src, (apr_size_t *)len, cookie);
+ }
+ else {
+ /* ignore */
+ }
}
else {
tmp = NULL;
*len = 0;
}
}
- DBG(r, "REQ[%X] end of chxj_convert()(emoji only)", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] end %s()(emoji only)", TO_ADDR(r),__func__);
}
if ( !(entryp->action & CONVRULE_EMOJI_ONLY_BIT)
- DBG(r, "REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
return dst;
}
static void
s_convert_guid_parameter_to_header(request_rec *r, const char *param, device_table *spec)
{
- DBG(r, "REQ[%X] start s_convert_guid_parameter() param:[%s]", (unsigned int)(apr_size_t)r, param);
+ DBG(r, "REQ[%X] start %s() param:[%s]", TO_ADDR(r),__func__, param);
if (strcasecmp(param, "guid") == 0) {
switch(spec->html_spec_type) {
case CHXJ_SPEC_XHtml_Mobile_1_0:
break;
}
}
- DBG(r, "REQ[%X] end s_convert_guid_parameter()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
}
/**
cookie_t *cookie = NULL;
int no_update_flag = 0;
- DBG(r, "REQ[%X] start chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
if (! r->args) {
- DBG(r, "REQ[%X] r->args=[null]", (unsigned int)(apr_size_t)r);
- DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] r->args=[null]", TO_ADDR(r));
+ DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
return 0;
}
urilen = strlen(r->args);
value = apr_strtok(NULL, "=", &vstate);
if (! name) continue;
if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
- DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] found cookie no update parameter", TO_ADDR(r));
no_update_flag++;
}
}
buff = apr_pstrdup(r->pool, r->args);
- DBG(r, "REQ[%X] r->args=[%s]", (unsigned int)(apr_size_t)r, buff);
+ DBG(r, "REQ[%X] r->args=[%s]", TO_ADDR(r), buff);
/* _chxj_dmy */
/* _chxj_c_ */
if (strlen(result) != 0)
result = apr_pstrcat(r->pool, result, "&", NULL);
- if (strcasecmp(entryp->encoding, "NONE") != 0) {
+ if (entryp && strcasecmp(entryp->encoding, "NONE") != 0) {
apr_size_t dlen;
char *dvalue;
char *dname;
if (value && *value != 0) {
value = chxj_url_decode(r->pool, value);
dlen = strlen(value);
- DBG(r, "************ before encoding[%s]", value);
+ DBG(r, "REQ[%X] ************ before encoding[%s]", TO_ADDR(r),value);
dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
dvalue = chxj_url_encode(r->pool, dvalue);
- DBG(r, "************ after encoding[%s]", dvalue);
+ DBG(r, "REQ[%X] ************ after encoding[%s]", TO_ADDR(r),dvalue);
}
else {
dvalue = "";
if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
if (! cookie) {
apr_table_unset(r->headers_in, "Cookie");
- DBG(r, "REQ[%X] found cookie parameter[%s]", (unsigned int)(apr_size_t)r, value);
- DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] found cookie parameter[%s]", TO_ADDR(r), value);
cookie_lock_t *lock = chxj_cookie_lock(r);
cookie = chxj_load_cookie(r, value);
- DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
if (! no_update_flag && cookie) {
cookie = chxj_update_cookie(r, cookie);
}
}
r->args = result;
- DBG(r, "REQ[%X] result r->args=[%s]", (unsigned int)(apr_size_t)r, r->args);
- DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] result r->args=[%s]", TO_ADDR(r), r->args);
+ DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
return 0;
}
apr_size_t ilen = 0;
apr_pool_t *pool;
- DBG(r, "REQ[%X] start of chxj_input_convert()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
if (! *src) {
- DBG(r, "REQ[%X] end of chxj_input_convert() (input is null)", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] end %s() (input is null)", TO_ADDR(r),__func__);
return apr_pstrdup(r->pool, "");
}
value = apr_strtok(NULL, "=", &vstate);
if (! name) continue;
if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
- DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] found cookie no update parameter", TO_ADDR(r));
no_update_flag++;
}
}
if (strlen(result) != 0)
result = apr_pstrcat(pool, result, "&", NULL);
- if (strcasecmp(entryp->encoding, "NONE") != 0 && value && strlen(value)) {
+ if (entryp && strcasecmp(entryp->encoding, "NONE") != 0 && value && strlen(value)) {
apr_size_t dlen;
char *dvalue;
if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
if (! cookie) {
apr_table_unset(r->headers_in, "Cookie");
- DBG(r, "REQ[%X] found cookie parameter[%s]", (unsigned int)(apr_size_t)r, value);
- DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] found cookie parameter[%s]", TO_ADDR(r), value);
cookie_lock_t *lock = chxj_cookie_lock(r);
cookie = chxj_load_cookie(r, value);
- DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
if (! no_update_flag && cookie) {
cookie = chxj_update_cookie(r, cookie);
}
s_convert_guid_parameter_to_header(r, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], spec);
}
}
- DBG(r, "REQ[%X] ************************ name:[%s]", (unsigned int)(apr_size_t)r, name);
+ DBG(r, "REQ[%X] ************************ name:[%s]", TO_ADDR(r), name);
}
*len = strlen(result);
apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
result = apr_pstrcat(pool, result, "&_chxj_nc=true", NULL);
}
- DBG(r, "REQ[%X] AFTER input convert result = [%s]", (unsigned int)(apr_size_t)r, result);
- DBG(r, "REQ[%X] end chxj_input_convert()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] AFTER input convert result = [%s]", TO_ADDR(r), result);
+ DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
return result;
}
apr_bucket_brigade *bb;
apr_bucket *b;
- DBG(r, "REQ[%X] start pass_data_to_filter()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
chxj_header_inf_clear(r);
rv = ap_pass_brigade(f->next, bb);
if (rv != APR_SUCCESS) {
- DBG(r, "REQ[%X] end pass_data_to_filter() (apr_pass_brigade)", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] end %s() (apr_pass_brigade)", TO_ADDR(r),__func__);
return rv;
}
- DBG(r, "REQ[%X] end pass_data_to_filter()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
return rv;
}
static void
s_add_no_cache_headers(request_rec *r, chxjconvrule_entry *entryp)
{
- if (entryp->action & CONVRULE_NOCACHE_ON_BIT) {
+ if (entryp && (entryp->action & CONVRULE_NOCACHE_ON_BIT)) {
apr_table_unset(r->headers_out, "Pragma");
apr_table_unset(r->err_headers_out, "Pragma");
apr_table_unset(r->headers_out, "Expires");
apr_pool_t *pool;
r = f->r;
- DBG(f->r, "REQ[%X] start of chxj_output_filter()", (unsigned int)(apr_size_t)r);
+ DBG(f->r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
rv = APR_SUCCESS;
apr_pool_create(&pool, r->pool);
case CHXJ_SPEC_Chtml_7_0:
case CHXJ_SPEC_XHtml_Mobile_1_0:
case CHXJ_SPEC_Jhtml:
+ case CHXJ_SPEC_Jxhtml:
lock = chxj_cookie_lock(r);
cookie = chxj_save_cookie(r);
s_add_cookie_id_if_has_location_header(r, cookie);
s_add_no_cache_headers(r, entryp);
/* must not send body. */
rv = pass_data_to_filter(f, "", 0);
- DBG(f->r, "REQ[%X] end of chxj_output_filter()", TO_ADDR(r));
+ DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
return rv;
}
|| STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
|| STRCASEEQ('g','G',"gif", &r->content_type[6])))) { /* GIF */
- DBG(r, "REQ[%X] not convert content-type:[%s] dconf->image:[%d]", (unsigned int)(apr_size_t)r, r->content_type, dconf->image);
+ DBG(r, "REQ[%X] not convert content-type:[%s] dconf->image:[%d]", TO_ADDR(r), r->content_type, dconf->image);
if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
cookie_lock_t *lock = NULL;
- DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", TO_ADDR(r));
switch(spec->html_spec_type) {
case CHXJ_SPEC_Chtml_1_0:
case CHXJ_SPEC_Chtml_2_0:
case CHXJ_SPEC_Chtml_7_0:
case CHXJ_SPEC_XHtml_Mobile_1_0:
case CHXJ_SPEC_Jhtml:
+ case CHXJ_SPEC_Jxhtml:
lock = chxj_cookie_lock(r);
cookie = chxj_save_cookie(r);
s_add_cookie_id_if_has_location_header(r, cookie);
}
s_add_no_cache_headers(r, entryp);
ap_pass_brigade(f->next, bb);
- DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
+ DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
return APR_SUCCESS;
}
}
else {
- DBG(r, "REQ[%X] not convert content-type:[(null)]", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] not convert content-type:[(null)]", TO_ADDR(r));
ap_pass_brigade(f->next, bb);
- DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
+ DBG(f->r, "REQ[%X] end %s()", TO_ADDR(f->r),__func__);
return APR_SUCCESS;
}
/* append data */
/*--------------------------------------------------------------------*/
char *tmp;
- DBG(r, "append data start");
+ DBG(r, "REQ[%X] append data start", TO_ADDR(r));
ctx = (mod_chxj_ctx *)f->ctx;
if (len > 0) {
ctx->len += len;
}
- DBG(r, "REQ[%X] append data end", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] append data end", TO_ADDR(r));
}
if (APR_BUCKET_IS_EOS(b)) {
- DBG(r, "REQ[%X] eos", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] eos", TO_ADDR(r));
/*----------------------------------------------------------------------*/
/* End Of File */
/*----------------------------------------------------------------------*/
cookie_lock_t *lock = NULL;
ctx = (mod_chxj_ctx *)f->ctx;
- DBG(r, "REQ[%X] content_type=[%s]", (unsigned int)(apr_size_t)r, r->content_type);
+ DBG(r, "REQ[%X] content_type=[%s]", TO_ADDR(r), r->content_type);
lock = chxj_cookie_lock(r);
if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
&& r->content_type
&& (STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
|| STRNCASEEQ('t','T',"text/html", r->content_type, sizeof("text/html")-1))) {
- DBG(r, "REQ[%X] detect convert target:[%s]", (unsigned int)(apr_size_t)r, r->content_type);
+ DBG(r, "REQ[%X] detect convert target:[%s]", TO_ADDR(r), r->content_type);
if (ctx->len) {
char *tmp;
if (r->content_type
&& *(char *)r->content_type == 't'
&& strncmp(r->content_type, "text/xml", 8) == 0) {
- DBG(r, "REQ[%X] text/XML", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] text/XML", TO_ADDR(r));
Doc doc;
Node *root;
chxj_qrcode_node_to_qrcode(&qrcode, root);
sts = chxj_qrcode_create_image_data(&qrcode, &ctx->buffer, &ctx->len);
if (sts != OK) {
- ERR(r, "REQ[%X] qrcode create failed.", (unsigned int)(apr_size_t)r);
+ ERR(r, "REQ[%X] qrcode create failed.", TO_ADDR(r));
chxj_cookie_unlock(r, lock);
- DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
+ DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
return sts;
}
r->content_type = apr_psprintf(r->pool, "image/jpeg");
|| STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
|| STRCASEEQ('x','X',"x-ms-bmp", &r->content_type[6]) /* BMP */
|| STRCASEEQ('g','G',"gif", &r->content_type[6]))) { /* GIF */
- DBG(r, "REQ[%X] detect convert target:[%s]", (unsigned int)(apr_size_t)r, r->content_type);
+ DBG(r, "REQ[%X] detect convert target:[%s]", TO_ADDR(r), r->content_type);
if (ctx->len) {
char *tmp;
+ DBG(r, "REQ[%X] ctx->len[%d]", TO_ADDR(r), (unsigned int)ctx->len);
tmp = apr_palloc(pool, ctx->len + 1);
memset(tmp, 0, ctx->len + 1);
chxj_convert_image(r,
(const char **)&tmp,
(apr_size_t *)&ctx->len);
- if (ctx->buffer == NULL) {
- ctx->buffer = tmp;
- }
}
}
if (ctx->len > 0) {
- DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] call %s()", TO_ADDR(r),__func__);
s_add_cookie_id_if_has_location_header(r, cookie);
if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
if (! ap_is_HTTP_REDIRECT(r->status)) {
(const char *)ctx->buffer,
(apr_size_t)ctx->len);
}
- DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
+ DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
return rv;
}
else {
- DBG(r, "REQ[%X] SAVE COOKIE[%x]", (unsigned int)(apr_size_t)r, entryp->action);
+ DBG(r, "REQ[%X] SAVE COOKIE[%x]", TO_ADDR(r), entryp->action);
/*
* save cookie.
*/
if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
cookie_lock_t *lock = NULL;
- DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", TO_ADDR(r));
switch(spec->html_spec_type) {
case CHXJ_SPEC_Chtml_1_0:
case CHXJ_SPEC_Chtml_2_0:
case CHXJ_SPEC_Chtml_7_0:
case CHXJ_SPEC_XHtml_Mobile_1_0:
case CHXJ_SPEC_Jhtml:
+ case CHXJ_SPEC_Jxhtml:
lock = chxj_cookie_lock(r);
cookie = chxj_save_cookie(r);
/*
}
}
apr_table_setn(r->headers_out, "Content-Length", "0");
- DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
s_add_no_cache_headers(r, entryp);
rv = pass_data_to_filter(f, (const char *)"", (apr_size_t)0);
- DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
return rv;
}
}
}
apr_brigade_destroy(bb);
- DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
return APR_SUCCESS;
}
static void
s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie)
{
+ DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
char *location_header = (char *)apr_table_get(r->headers_out, "Location");
if (! location_header) {
location_header = (char *)apr_table_get(r->err_headers_out, "Location");
}
if (cookie && location_header) {
- DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
+ DBG(r, "REQ[%X] Location Header=[%s]", TO_ADDR(r), location_header);
location_header = chxj_add_cookie_parameter(r,
location_header,
cookie);
apr_table_unset(r->headers_out, "Location");
apr_table_setn(r->headers_out, "Location", location_header);
- DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
+ DBG(r, "REQ[%X] Location Header=[%s]", TO_ADDR(r), location_header);
if (!ap_is_HTTP_REDIRECT(r->status)) {
r->status = HTTP_MOVED_TEMPORARILY;
}
}
+ DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
}
/**
chxj_input_handler(request_rec *r)
{
mod_chxj_config *dconf;
+ mod_chxj_req_config *request_conf;
chxjconvrule_entry *entryp = NULL;
device_table *spec = NULL;
char *post_data = NULL;
char *response;
char *user_agent;
apr_pool_t *pool;
- apr_size_t ii;
int response_code = 0;
- DBG(r, "start of chxj_input_handler()");
+ DBG(r, "REQ[%X] start %s()",TO_ADDR(r),__func__);
if (strcasecmp(r->handler, "chxj-input-handler")) {
- DBG(r, "end chxj_input_handler()");
+ DBG(r, "REQ[%X] end %s()",TO_ADDR(r),__func__);
return DECLINED;
}
apr_pool_create(&pool, r->pool);
dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
+ request_conf = chxj_get_module_config(r->request_config, &chxj_module);
user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
if (!user_agent) {
user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
}
- spec = chxj_specified_device(r, user_agent);
- entryp = chxj_apply_convrule(r, dconf->convrules);
+ if (user_agent && request_conf->user_agent && strcmp(user_agent, request_conf->user_agent)) {
+ spec = chxj_specified_device(r, user_agent);
+ }
+ else {
+ spec = request_conf->spec;
+ }
+ entryp = chxj_apply_convrule(r, dconf->convrules);
post_data = apr_pstrdup(pool, "");
if (ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK) == OK) {
*/
if (post_data_len > 0) {
post_data = chxj_input_convert(r, (const char**)&post_data, (apr_size_t*)&post_data_len, entryp, spec);
- DBG(r, "(in:exchange)POSTDATA:[%s]", post_data);
+ DBG(r, "REQ[%X] (in:exchange)POSTDATA:[%s]", TO_ADDR(r),post_data);
}
char *url_path;
if (r->args) {
url_path = apr_pstrcat(pool, url_path, "?", r->args, NULL);
}
- DBG(r, "==> new url_path:[%s]", url_path);
+ DBG(r, "REQ[%X] ==> new url_path:[%s]", TO_ADDR(r),url_path);
apr_size_t res_len;
apr_table_setn(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP, r->connection->remote_ip);
+ char *x_client_type = (char *)apr_table_get(r->headers_in, "X-Client-Type");
+ if (x_client_type) {
+ apr_table_setn(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_TYPE, x_client_type); /* for mod_cidr_lookup */
+ }
+ else {
+ apr_table_unset(r->headers_in, "X-Client-Type");
+ }
apr_table_unset(r->headers_in, "Content-Length");
apr_table_setn(r->headers_in, "Content-Length", apr_psprintf(pool, "%" APR_SIZE_T_FMT, post_data_len));
response = chxj_serf_post(r, pool, url_path, post_data, post_data_len, 1, &res_len, &response_code);
- DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
- DBG(r, "REQ[%X] response length:[%" APR_SIZE_T_FMT "]", (unsigned int)(apr_size_t)r, res_len);
- for (ii=0; ii<res_len/64; ii++) {
- DBG(r, "REQ[%X] response:[%.*s]", (unsigned int)(apr_size_t)r, 64, &response[ii*64]);
- }
- DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
char *chunked;
if ((chunked = (char *)apr_table_get(r->headers_out, "Transfer-Encoding")) != NULL) {
}
}
if (ap_is_HTTP_ERROR(response_code)) {
- DBG(r, "REQ[%X] end of chxj_input_handler() (HTTP-ERROR received. response code:[%d])", (unsigned int)(apr_size_t)r, response_code);
+ DBG(r, "REQ[%X] end %s() (HTTP-ERROR received. response code:[%d])", TO_ADDR(r), __func__,response_code);
return response_code;
}
{
e = apr_bucket_eos_create(c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(bb, e);
if ((rv = ap_pass_brigade(r->output_filters, bb)) != APR_SUCCESS) {
- ERR(r, "REQ[%X] %s:%d failed ap_pass_brigade()", (unsigned int)(apr_size_t)r, APLOG_MARK);
+ ERR(r, "REQ[%X] %s:%d failed ap_pass_brigade()", TO_ADDR(r), APLOG_MARK);
return rv;
}
apr_brigade_cleanup(bb);
}
- DBG(r, "REQ[%X] end of chxj_input_handler()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
return APR_SUCCESS;
}
static int
chxj_translate_name(request_rec *r)
{
- DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
- DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
- DBG(r, "REQ[%X] START REQUEST (uri:[%s] args:[%s])", (unsigned int)(apr_size_t)r, r->unparsed_uri, r->args ? r->args : "");
- DBG(r, "REQ[%X] METHOD [%s]", TO_ADDR(r), r->method);
- DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
- DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] =======================================================================", TO_ADDR(r));
+ DBG(r, "REQ[%X] ", TO_ADDR(r));
+ DBG(r, "REQ[%X] START REQUEST (uri:[%s] args:[%s])", TO_ADDR(r), r->unparsed_uri, r->args ? r->args : "");
+ DBG(r, "REQ[%X] METHOD [%s]", TO_ADDR(r), r->method);
+ DBG(r, "REQ[%X] ", TO_ADDR(r));
+ DBG(r, "REQ[%X] =======================================================================", TO_ADDR(r));
mod_chxj_config *dconf;
dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
char *user_agent;
device_table *spec;
mod_chxj_config *dconf;
+ mod_chxj_req_config *req_conf;
chxjconvrule_entry *entryp;
mod_chxj_ctx *ctx;
apr_status_t rv;
char *contentType;
- DBG(r, "REQ[%X] start chxj_insert_filter()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
+ req_conf = chxj_get_module_config(r->request_config, &chxj_module);
/* we get User-Agent from CHXJ_HTTP_USER_AGENT header if any */
user_agent = (char *)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
if (contentType
&& strncasecmp("multipart/form-data", contentType, 19) == 0) {
- DBG(r, "REQ[%X] detect multipart/form-data ==> no target", (unsigned int)(apr_size_t)r);
- DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] detect multipart/form-data ==> no target", TO_ADDR(r));
+ DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
return;
}
- spec = chxj_specified_device(r, user_agent);
+ if (user_agent && req_conf->user_agent && strcmp(user_agent, req_conf->user_agent)) {
+ spec = chxj_specified_device(r, user_agent);
+ }
+ else {
+ spec = req_conf->spec;
+ }
entryp = chxj_apply_convrule(r, dconf->convrules);
- if (!entryp) {
- DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
+ if (!entryp && dconf->image != CHXJ_IMG_ON) {
+ DBG(r, "REQ[%X] entryp is NULL and ChxjImageEngine Off", TO_ADDR(r));
+ DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
return;
}
ctx = apr_palloc(r->pool, sizeof(*ctx));
memset(ctx, 0, sizeof(*ctx));
if ((rv = apr_pool_create(&ctx->pool, r->pool)) != APR_SUCCESS) {
- ERR(r, "%s:%d: failed: new pool create. rv:[%d]", __FILE__,__LINE__,rv);
- DBG(r, "REQ:[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
+ ERR(r, "REQ[%X] %s:%d: failed: new pool create. rv:[%d]", TO_ADDR(r),__FILE__,__LINE__,rv);
+ DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
return;
}
ctx->entryp = entryp;
ctx->buffer = apr_palloc(ctx->pool, 1);
ctx->buffer[0] = 0;
- if (!entryp || (!(entryp->action & CONVRULE_ENGINE_ON_BIT) && !(entryp->action & CONVRULE_COOKIE_ONLY_BIT))) {
- DBG(r,"REQ[%X] EngineOff", (unsigned int)(apr_size_t)r);
- DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
+ if (dconf->image != CHXJ_IMG_ON && (!entryp || (!(entryp->action & CONVRULE_ENGINE_ON_BIT) && !(entryp->action & CONVRULE_COOKIE_ONLY_BIT)))) {
+ DBG(r,"REQ[%X] EngineOff and ChxjImageEngine Off", TO_ADDR(r));
+ DBG(r,"REQ[%X] end %s()", TO_ADDR(r),__func__);
return;
}
-
switch(spec->html_spec_type) {
case CHXJ_SPEC_Chtml_1_0:
case CHXJ_SPEC_Chtml_2_0:
break;
default:
- DBG(r, "REQ[%X] end chxj_insert_filter() Unknown spec type(%d).", (unsigned int)(apr_size_t)r, spec->html_spec_type);
+ DBG(r, "REQ[%X] end %s() Unknown spec type(%d).", TO_ADDR(r), __func__,spec->html_spec_type);
return;
}
if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
- ap_add_output_filter("chxj_output_filter", ctx, r, r->connection);
- DBG(r, "REQ[%X] added Output Filter", (unsigned int)(apr_size_t)r);
+ req_conf->f = ap_add_output_filter("chxj_output_filter", ctx, r, r->connection);
+ DBG(r, "REQ[%X] added Output Filter", TO_ADDR(r));
}
- DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
+ DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
+}
+
+
+void
+chxj_remove_filter(request_rec *r)
+{
+ mod_chxj_req_config *req_conf;
+
+ DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
+ req_conf = chxj_get_module_config(r->request_config, &chxj_module);
+ if (req_conf && req_conf->f) {
+ ap_remove_output_filter(req_conf->f);
+ DBG(r, "REQ[%X] REMOVE Output Filter", TO_ADDR(r));
+ }
+ DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
}
}
break;
+ case 'O':
+ case 'o':
+ if (strcasecmp(CONVRULE_OVERWRITE_X_CLIENT_TYPE_CMD, action) == 0) {
+ newrule->action |= CONVRULE_OVERWRITE_X_CLIENT_TYPE_BIT;
+ }
+ break;
+
case 'C':
case 'c':
if (strcasecmp(CONVRULE_COOKIE_ON_CMD, action) == 0) {