/*
- * Copyright (C) 2005-2008 Atsushi Konno All rights reserved.
+ * Copyright (C) 2005-2009 Atsushi Konno All rights reserved.
* Copyright (C) 2005 QSDN,Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
#include "chxj_add_device_env.h"
#include "chxj_conv_z2h.h"
#include "chxj_header_inf.h"
+#include "chxj_jreserved_tag.h"
#define CHXJ_VERSION_PREFIX PACKAGE_NAME "/"
converter_t convert_routine[] = {
{
/* CHXJ_SPEC_UNKNOWN */
- .converter = NULL,
- .encoder = NULL,
+ .converter = NULL,
+ .encoder = NULL,
+ .emoji_only_converter = NULL,
},
{
/* CHXJ_SPEC_Chtml_1_0 */
- .converter = chxj_convert_chtml10,
- .encoder = chxj_encoding,
+ .converter = chxj_convert_chtml10,
+ .encoder = chxj_encoding,
+ .emoji_only_converter = chxj_chtml10_emoji_only_converter,
},
{
/* CHXJ_SPEC_Chtml_2_0 */
- .converter = chxj_convert_chtml20,
- .encoder = chxj_encoding,
+ .converter = chxj_convert_chtml20,
+ .encoder = chxj_encoding,
+ .emoji_only_converter = chxj_chtml20_emoji_only_converter,
},
{
/* CHXJ_SPEC_Chtml_3_0 */
- .converter = chxj_convert_chtml30,
- .encoder = chxj_encoding,
+ .converter = chxj_convert_chtml30,
+ .encoder = chxj_encoding,
+ .emoji_only_converter = chxj_chtml30_emoji_only_converter,
},
{
/* CHXJ_SPEC_Chtml_4_0 */
- .converter = chxj_convert_chtml40,
- .encoder = chxj_encoding,
+ .converter = chxj_convert_chtml40,
+ .encoder = chxj_encoding,
+ .emoji_only_converter = chxj_chtml40_emoji_only_converter,
},
{
/* CHXJ_SPEC_Chtml_5_0 */
- .converter = chxj_convert_chtml50,
- .encoder = chxj_encoding,
+ .converter = chxj_convert_chtml50,
+ .encoder = chxj_encoding,
+ .emoji_only_converter = chxj_chtml50_emoji_only_converter,
},
{
/* CHXJ_SPEC_Chtml_6_0 */
- .converter = chxj_convert_chtml50,
- .encoder = chxj_encoding,
+ .converter = chxj_convert_chtml50,
+ .encoder = chxj_encoding,
+ .emoji_only_converter = chxj_chtml50_emoji_only_converter,
},
{
/* CHXJ_SPEC_Chtml_7_0 */
- .converter = chxj_convert_chtml50,
- .encoder = chxj_encoding,
+ .converter = chxj_convert_chtml50,
+ .encoder = chxj_encoding,
+ .emoji_only_converter = chxj_chtml50_emoji_only_converter,
},
{
/* CHXJ_SPEC_XHtml_Mobile_1_0 */
- .converter = chxj_convert_xhtml_mobile_1_0,
- .encoder = chxj_encoding,
+ .converter = chxj_convert_xhtml_mobile_1_0,
+ .encoder = chxj_encoding,
+ .emoji_only_converter = chxj_xhtml_emoji_only_converter,
},
{
/* CHXJ_SPEC_Hdml */
- .converter = chxj_convert_hdml,
- .encoder = chxj_encoding,
+ .converter = chxj_convert_hdml,
+ .encoder = chxj_encoding,
+ .emoji_only_converter = NULL,
},
{
/* CHXJ_SPEC_Jhtml */
- .converter = chxj_convert_jhtml,
- .encoder = chxj_encoding,
+ .converter = chxj_convert_jhtml,
+ .encoder = chxj_encoding,
+ .emoji_only_converter = chxj_jhtml_emoji_only_converter,
},
{
/* CHXJ_SPEC_Jxhtml */
- .converter = chxj_convert_jxhtml,
- .encoder = chxj_encoding,
+ .converter = chxj_convert_jxhtml,
+ .encoder = chxj_encoding,
+ .emoji_only_converter = chxj_jxhtml_emoji_only_converter,
},
{
/* CHXJ_SPEC_HTML */
.converter = NULL,
.encoder = NULL,
+ .emoji_only_converter = NULL,
},
};
-static int chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp);
+static int chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp, device_table *spec);
+static void s_convert_guid_parameter_to_header(request_rec *r, const char *param, device_table *spec);
static void s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie);
static void s_clear_cookie_header(request_rec *r, device_table *spec);
+static void s_add_no_cache_headers(request_rec *r, chxjconvrule_entry *entryp);
/**
* Only when User-Agent is specified, the User-Agent header is camouflaged.
DBG(r, "REQ[%X] end chxj_headers_fixup() (no pattern)", (unsigned int)(apr_size_t)r);
return DECLINED;
}
- if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
+ if (!(entryp->action & CONVRULE_ENGINE_ON_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;
+ }
apr_table_setn(r->headers_in,
CHXJ_HTTP_USER_AGENT,
HTTP_USER_AGENT,
entryp->user_agent);
- chxj_convert_input_header(r,entryp);
+ chxj_convert_input_header(r,entryp, spec);
break;
* save cookie.
*/
cookie = NULL;
- if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
+ if (entryp->action & CONVRULE_COOKIE_ON_BIT && !(entryp->action & CONVRULE_EMOJI_ONLY_BIT)) {
switch(spec->html_spec_type) {
case CHXJ_SPEC_Chtml_1_0:
case CHXJ_SPEC_Chtml_2_0:
*src,
(apr_size_t *)len);
+ if (entryp->action & CONVRULE_EMOJI_ONLY_BIT) {
+ if (tmp) {
+ tmp = chxj_node_convert_chxjif_only(r, spec, (const char*)tmp, (apr_size_t *)len);
+ }
+ else {
+ tmp = chxj_node_convert_chxjif_only(r, spec, (const char *)*src, (apr_size_t *)len);
+ }
+ if (convert_routine[spec->html_spec_type].emoji_only_converter) {
+ dst = convert_routine[spec->html_spec_type].emoji_only_converter(r,spec, tmp,*len);
+ if (dst != NULL) {
+ *len = strlen(dst);
+ }
+ else {
+ dst = apr_palloc(r->pool, 1);
+ *dst = 0;
+ *len = 0;
+ }
+ }
+ DBG(r, "REQ[%X] end of chxj_convert()(emoji only)", (unsigned int)(apr_size_t)r);
+ return dst;
+ }
+
if (convert_routine[spec->html_spec_type].converter) {
if (tmp)
dst = convert_routine[spec->html_spec_type].converter(r,
else
dst = convert_routine[spec->html_spec_type].converter(r,
spec,
- tmp,
+ *src,
*len,
len,
entryp,
/**
+ * convert GUID parameter.
+ *
+ */
+static void
+s_convert_guid_parameter_to_header(request_rec *r, const char *param, device_table *spec)
+{
+ if (strcasecmp(param, "guid") == 0) {
+ switch(spec->html_spec_type) {
+ case CHXJ_SPEC_XHtml_Mobile_1_0:
+ do {
+ char *x_up_subno = (char *)apr_table_get(r->headers_in, "x-up-subno");
+ if (x_up_subno) {
+ apr_table_setn(r->headers_in, "X-DCMGUID", x_up_subno);
+ }
+ } while(0);
+ break;
+ case CHXJ_SPEC_Jhtml:
+ case CHXJ_SPEC_Jxhtml:
+ do {
+ char *x_jphone_uid = (char *)apr_table_get(r->headers_in, "x-jphone-uid");
+ if (x_jphone_uid) {
+ apr_table_setn(r->headers_in, "X-DCMGUID", x_jphone_uid);
+ }
+ } while(0);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+/**
* It converts it from HEADER.
*
* @param r [i]
*/
static int
-chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp)
+chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp, device_table *spec)
{
char *buff;
name = apr_strtok(pair, "=", &vstate);
value = apr_strtok(NULL, "=", &vstate);
if (! name) continue;
+ name = chxj_safe_to_jreserved_tag(r, name);
+
if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
if (strlen(result) != 0)
result = apr_pstrcat(r->pool, result, "&", NULL);
else {
dname = "";
}
-
+ s_convert_guid_parameter_to_header(r, dname, spec);
result = apr_pstrcat(r->pool, result, dname, "=", dvalue, NULL);
}
else {
request_rec *r,
const char **src,
apr_size_t *len,
- chxjconvrule_entry *entryp)
+ chxjconvrule_entry *entryp,
+ device_table *spec)
{
char *pair;
char *name;
name = apr_strtok(pair, "=", &vstate);
value = apr_strtok(NULL, "=", &vstate);
if (! name) continue;
+ name = chxj_safe_to_jreserved_tag(r, name);
+
if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
if (strlen(result) != 0)
result = apr_pstrcat(pool, result, "&", NULL);
dname = "";
}
+
result = apr_pstrcat(pool, result, dname, "=", dvalue, NULL);
}
else {
else {
r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
}
+ s_convert_guid_parameter_to_header(r, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], spec);
}
}
else
else {
r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
}
+ 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);
/**
+ * Add No Cache Header
+ */
+static void
+s_add_no_cache_headers(request_rec *r, chxjconvrule_entry *entryp)
+{
+ if (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_table_unset(r->err_headers_out, "Expires");
+ apr_table_unset(r->headers_out, "Cache-Control");
+ apr_table_unset(r->err_headers_out, "Cache-Control");
+
+ apr_table_setn(r->err_headers_out, "Pragma", "no-cache");
+ apr_table_setn(r->err_headers_out, "Expires", "Thu, 01 Jan 1970 00:00:00 GMT");
+ apr_table_setn(r->err_headers_out, "Cache-Control", "no-cache, no-store");
+ }
+}
+
+
+/**
* It is the main loop of the output filter.
*
* @param f [i/o] It is a filter.
}
}
if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
- if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
+ if (! ap_is_HTTP_REDIRECT(r->status)) {
r->status = HTTP_MOVED_TEMPORARILY;
}
}
+ 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);
return APR_SUCCESS;
DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
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 (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
+ if (! ap_is_HTTP_REDIRECT(r->status)) {
r->status = HTTP_MOVED_TEMPORARILY;
}
}
chxj_cookie_unlock(r,lock);
+ s_add_no_cache_headers(r, entryp);
rv = pass_data_to_filter(f,
(const char *)ctx->buffer,
(apr_size_t)ctx->len);
}
}
if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
- if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
+ if (! ap_is_HTTP_REDIRECT(r->status)) {
r->status = HTTP_MOVED_TEMPORARILY;
}
}
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_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);
- if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
+ if (!ap_is_HTTP_REDIRECT(r->status)) {
r->status = HTTP_MOVED_TEMPORARILY;
}
}
char *user_agent;
apr_pool_t *pool;
apr_size_t ii;
+ int response_code = 0;
DBG(r, "start of chxj_input_handler()");
* now convert.
*/
if (post_data_len > 0) {
- post_data = chxj_input_convert(r, (const char**)&post_data, (apr_size_t*)&post_data_len, entryp);
+ 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);
}
url_path = apr_psprintf(pool, "%s%s", dconf->forward_url_base, r->uri);
}
else {
- url_path = apr_psprintf(pool, "%s://%s:%d%s", chxj_apache_run_http_scheme(r), "127.0.0.1", ap_get_server_port(r), r->uri);
+ url_path = apr_psprintf(pool, "%s://%s:%d%s", chxj_apache_run_http_scheme(r), ap_get_server_name(r), ap_get_server_port(r), r->uri);
}
if (r->args) {
url_path = apr_pstrcat(pool, url_path, "?", r->args, NULL);
apr_table_setn(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP, r->connection->remote_ip);
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 = 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++) {
apr_table_unset(r->headers_out, "Transfer-Encoding");
}
}
+ 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);
+ return response_code;
+ }
{
apr_pool_t *wpool;
apr_pool_create(&wpool, r->pool);
#endif
conf->forward_url_base = NULL;
conf->forward_server_ip = NULL;
+ conf->allowed_cookie_domain = NULL;
if (arg == NULL) {
conf->dir = NULL;
mrg->new_line_type = NLTYPE_NIL;
mrg->forward_url_base = NULL;
mrg->forward_server_ip = NULL;
+ mrg->allowed_cookie_domain = NULL;
mrg->dir = apr_pstrdup(p, add->dir);
else {
mrg->new_line_type = NLTYPE_NIL;
}
+
+ if (add->forward_url_base) {
+ mrg->forward_url_base = add->forward_url_base;
+ }
+ else if (base->forward_url_base) {
+ mrg->forward_url_base = base->forward_url_base;
+ }
+
+ if (add->allowed_cookie_domain) {
+ mrg->allowed_cookie_domain = add->allowed_cookie_domain;
+ }
+ else {
+ mrg->allowed_cookie_domain = base->allowed_cookie_domain;
+ }
return mrg;
}
if (strcasecmp(CONVRULE_ENGINE_OFF_CMD, action) == 0) {
newrule->action |= CONVRULE_ENGINE_OFF_BIT;
}
+ else
+ if (strcasecmp(CONVRULE_EMOJI_ONLY_CMD, action) == 0) {
+ newrule->action |= CONVRULE_EMOJI_ONLY_BIT;
+ }
break;
case 'C':
}
break;
+ case 'J':
+ case 'j':
+ if (strcasecmp(CONVRULE_JRCONV_OFF_CMD, action) == 0) {
+ newrule->action |= CONVRULE_JRCONV_OFF_BIT;
+ }
+ break;
+
+ case 'N':
+ case 'n':
+ if (strcasecmp(CONVRULE_NOCACHE_ON_CMD, action) == 0) {
+ newrule->action |= CONVRULE_NOCACHE_ON_BIT;
+ }
+ break;
+
+ case 'Q':
+ case 'q':
+ if (strcasecmp(CONVRULE_QSCONV_OFF_CMD, action) == 0) {
+ newrule->action |= CONVRULE_QSCONV_OFF_BIT;
+ }
+ break;
+
case 'Z':
case 'z':
if (strcasecmp(CONVRULE_Z2H_ON_CMD, action) == 0) {
}
static const char *
+cmd_allowed_cookie_domain(
+ cmd_parms *cmd,
+ void *mconfig,
+ const char *arg)
+{
+ mod_chxj_config *dconf;
+
+ if (strlen(arg) > 255)
+ return "mod_chxj: ChxjAllowedCookieDomain is too long.";
+
+ dconf = (mod_chxj_config *)mconfig;
+
+ dconf->allowed_cookie_domain = apr_pstrdup(cmd->pool, arg);
+
+ return NULL;
+}
+
+static const char *
cmd_set_new_line_type(
cmd_parms *UNUSED(cmd),
void *mconfig,
NULL,
OR_ALL,
"The forward server ip(default: this server ip)"),
+ AP_INIT_TAKE1(
+ "ChxjAllowedCookieDomain",
+ cmd_allowed_cookie_domain,
+ NULL,
+ OR_ALL,
+ "Domain that permits parameter addition for cookie besides hostname.(Default:hostname Only)"),
{NULL}
};