2 * Copyright (C) 2005-2009 Atsushi Konno All rights reserved.
3 * Copyright (C) 2005 QSDN,Inc. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
23 #include "http_config.h"
24 #include "http_core.h"
25 #include "http_protocol.h"
27 #include "ap_config.h"
28 #include "apr_strings.h"
29 #include "util_filter.h"
30 #include "apr_buckets.h"
32 #include "apr_tables.h"
34 #include "apr_general.h"
35 #include "apr_pools.h"
36 #include "apr_file_info.h"
39 #include "chxj_encoding.h"
40 #include "qs_ignore_sp.h"
42 #include "qs_malloc.h"
43 #include "qs_parse_attr.h"
44 #include "qs_parse_file.h"
45 #include "qs_parse_string.h"
46 #include "qs_parse_tag.h"
47 #include "chxj_load_device_data.h"
48 #include "chxj_load_emoji_data.h"
49 #include "chxj_specified_device.h"
50 #include "chxj_tag_util.h"
51 #include "chxj_xhtml_mobile_1_0.h"
52 #include "chxj_hdml.h"
53 #include "chxj_chtml10.h"
54 #include "chxj_chtml20.h"
55 #include "chxj_chtml30.h"
56 #include "chxj_chtml40.h"
57 #include "chxj_chtml50.h"
58 #include "chxj_ixhtml10.h"
59 #include "chxj_jhtml.h"
60 #include "chxj_jxhtml.h"
61 #include "chxj_img_conv_format.h"
62 #include "chxj_qr_code.h"
63 #include "chxj_encoding.h"
64 #include "chxj_apply_convrule.h"
65 #include "chxj_cookie.h"
66 #include "chxj_url_encode.h"
67 #include "chxj_str_util.h"
68 #include "chxj_dump_string.h"
69 #if defined(USE_MYSQL_COOKIE)
70 # include "chxj_mysql.h"
72 #include "chxj_serf.h"
73 #include "chxj_add_device_env.h"
74 #include "chxj_header_inf.h"
75 #include "chxj_jreserved_tag.h"
78 #define CHXJ_VERSION_PREFIX PACKAGE_NAME "/"
79 #define CHXJ_VERSION PACKAGE_VERSION
80 #define CHXJ_POST_MAX (0x1000000)
82 converter_t convert_routine[] = {
84 /* CHXJ_SPEC_UNKNOWN */
87 .emoji_only_converter = NULL,
90 /* CHXJ_SPEC_Chtml_1_0 */
91 .converter = chxj_convert_chtml10,
92 .encoder = chxj_encoding,
93 .emoji_only_converter = chxj_chtml10_emoji_only_converter,
96 /* CHXJ_SPEC_Chtml_2_0 */
97 .converter = chxj_convert_chtml20,
98 .encoder = chxj_encoding,
99 .emoji_only_converter = chxj_chtml20_emoji_only_converter,
102 /* CHXJ_SPEC_Chtml_3_0 */
103 .converter = chxj_convert_chtml30,
104 .encoder = chxj_encoding,
105 .emoji_only_converter = chxj_chtml30_emoji_only_converter,
108 /* CHXJ_SPEC_Chtml_4_0 */
109 .converter = chxj_convert_chtml40,
110 .encoder = chxj_encoding,
111 .emoji_only_converter = chxj_chtml40_emoji_only_converter,
114 /* CHXJ_SPEC_Chtml_5_0 */
115 .converter = chxj_convert_chtml50,
116 .encoder = chxj_encoding,
117 .emoji_only_converter = chxj_chtml50_emoji_only_converter,
120 /* CHXJ_SPEC_Chtml_6_0 */
121 .converter = chxj_convert_ixhtml10,
122 .encoder = chxj_encoding,
123 .emoji_only_converter = chxj_chtml50_emoji_only_converter, /* XXX: TODO */
126 /* CHXJ_SPEC_Chtml_7_0 */
127 .converter = chxj_convert_ixhtml10,
128 .encoder = chxj_encoding,
129 .emoji_only_converter = chxj_chtml50_emoji_only_converter, /* XXX: TODO */
132 /* CHXJ_SPEC_XHtml_Mobile_1_0 */
133 .converter = chxj_convert_xhtml_mobile_1_0,
134 .encoder = chxj_encoding,
135 .emoji_only_converter = chxj_xhtml_emoji_only_converter,
139 .converter = chxj_convert_hdml,
140 .encoder = chxj_encoding,
141 .emoji_only_converter = NULL,
144 /* CHXJ_SPEC_Jhtml */
145 .converter = chxj_convert_jhtml,
146 .encoder = chxj_encoding,
147 .emoji_only_converter = chxj_jhtml_emoji_only_converter,
150 /* CHXJ_SPEC_Jxhtml */
151 .converter = chxj_convert_jxhtml,
152 .encoder = chxj_encoding,
153 .emoji_only_converter = chxj_jxhtml_emoji_only_converter,
159 .emoji_only_converter = NULL,
163 static int chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp, device_table *spec);
164 static void s_convert_guid_parameter_to_header(request_rec *r, const char *param, device_table *spec);
165 static void s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie);
166 static void s_clear_cookie_header(request_rec *r, device_table *spec);
167 static void s_add_no_cache_headers(request_rec *r, chxjconvrule_entry *entryp);
170 * Only when User-Agent is specified, the User-Agent header is camouflaged.
175 chxj_headers_fixup(request_rec *r)
177 mod_chxj_config* dconf;
178 chxjconvrule_entry* entryp;
184 DBG(r, "REQ[%X] start chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
186 DBG(r, "REQ[%X] detect internal redirect.", (unsigned int)(apr_size_t)r);
187 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
191 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
193 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
194 spec = chxj_specified_device(r, user_agent);
196 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
198 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
199 DBG(r, "REQ[%X] detect multipart/form-data ==> no target", (unsigned int)(apr_size_t)r);
200 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
205 switch(spec->html_spec_type) {
206 case CHXJ_SPEC_Chtml_1_0:
207 case CHXJ_SPEC_Chtml_2_0:
208 case CHXJ_SPEC_Chtml_3_0:
209 case CHXJ_SPEC_Chtml_4_0:
210 case CHXJ_SPEC_Chtml_5_0:
211 case CHXJ_SPEC_Chtml_6_0:
212 case CHXJ_SPEC_Chtml_7_0:
213 case CHXJ_SPEC_XHtml_Mobile_1_0:
215 case CHXJ_SPEC_Jhtml:
216 case CHXJ_SPEC_Jxhtml:
217 entryp = chxj_apply_convrule(r, dconf->convrules);
219 DBG(r, "REQ[%X] end chxj_headers_fixup() (no pattern)", (unsigned int)(apr_size_t)r);
222 if (!(entryp->action & CONVRULE_ENGINE_ON_BIT) && !(entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
223 DBG(r, "REQ[%X] end chxj_headers_fixup() (engine off)", (unsigned int)(apr_size_t)r);
226 if (entryp->action & CONVRULE_EMOJI_ONLY_BIT) {
227 DBG(r, "REQ[%X] end chxj_headers_fixup() (emoji only)", (unsigned int)(apr_size_t)r);
231 apr_table_setn(r->headers_in,
232 CHXJ_HTTP_USER_AGENT,
235 if (entryp->user_agent)
236 apr_table_setn(r->headers_in,
240 * this clear process must do before chxj_convert_input_header function.
242 if ((entryp->action & CONVRULE_COOKIE_ON_BIT) || (entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
243 if (r->method_number == M_POST) {
244 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
245 s_clear_cookie_header(r, spec);
249 s_clear_cookie_header(r, spec);
253 chxj_convert_input_header(r,entryp, spec);
258 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);
264 if (r->method_number == M_POST) {
265 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
266 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);
267 r->proxyreq = PROXYREQ_NONE;
268 r->handler = apr_psprintf(r->pool, "chxj-input-handler");
271 char *client_ip = (char *)apr_table_get(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP);
273 if (dconf->post_log) {
274 apr_table_setn(r->subprocess_env, dconf->post_log, dconf->post_log);
277 apr_table_setn(r->subprocess_env, "chxj-post-log", "chxj-post-log");
279 apr_sockaddr_t *address = NULL;
280 apr_status_t rv = apr_sockaddr_info_get(&address, ap_get_server_name(r), APR_UNSPEC, ap_get_server_port(r), 0, r->pool);
281 if (rv != APR_SUCCESS) {
283 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));
284 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
288 if (dconf->forward_server_ip) {
289 addr = dconf->forward_server_ip;
292 apr_sockaddr_ip_get(&addr, address);
294 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);
295 if (strcmp(addr, r->connection->remote_ip) == 0) {
296 r->connection->remote_ip = apr_pstrdup(r->connection->pool, client_ip);
298 if (! apr_table_get(r->headers_in, "Content-Length")) {
299 contentLength = (char *)apr_table_get(r->headers_in, "X-Chxj-Content-Length");
301 apr_table_set(r->headers_in, "Content-Length", contentLength);
308 chxj_add_device_env(r, spec);
310 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
317 s_clear_cookie_header(request_rec *r, device_table *spec)
319 DBG(r, "REQ[%X] start s_clear_cookie_header()", TO_ADDR(r));
320 switch(spec->html_spec_type) {
321 case CHXJ_SPEC_Chtml_1_0:
322 case CHXJ_SPEC_Chtml_2_0:
323 case CHXJ_SPEC_Chtml_3_0:
324 case CHXJ_SPEC_Chtml_4_0:
325 case CHXJ_SPEC_Chtml_5_0:
326 case CHXJ_SPEC_Chtml_6_0:
327 case CHXJ_SPEC_Chtml_7_0:
328 case CHXJ_SPEC_XHtml_Mobile_1_0:
329 case CHXJ_SPEC_Jhtml:
330 apr_table_unset(r->headers_in, "Cookie");
335 DBG(r, "REQ[%X] end s_clear_cookie_header()", TO_ADDR(r));
340 * It converts it from CHTML into XXML corresponding to each model.
343 * @param src [i] It is former HTML character string.
344 * @param len [i/o] It is length of former HTML character string.
347 chxj_convert(request_rec *r, const char **src, apr_size_t *len, device_table *spec, const char *ua, cookie_t **cookiep)
353 mod_chxj_config *dconf;
354 chxjconvrule_entry *entryp;
356 DBG(r,"REQ[%X] start of chxj_convert()", (unsigned int)(apr_size_t)r);
358 chxj_dump_string(r, APLOG_MARK, "INPUT Data", *src, *len);
360 dst = apr_pstrcat(r->pool, (char *)*src, NULL);
362 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
365 entryp = chxj_apply_convrule(r, dconf->convrules);
367 if (!entryp || (!(entryp->action & CONVRULE_ENGINE_ON_BIT) && !(entryp->action & CONVRULE_COOKIE_ONLY_BIT))) {
368 DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
373 /*------------------------------------------------------------------------*/
374 /* get UserAgent from http header */
375 /*------------------------------------------------------------------------*/
376 if (entryp->user_agent)
377 user_agent = (char *)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
379 user_agent = (char *)apr_table_get(r->headers_in, HTTP_USER_AGENT);
381 DBG(r,"REQ[%X] User-Agent:[%s]", (unsigned int)(apr_size_t)r, user_agent);
382 DBG(r,"REQ[%X] content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
385 if ( ! STRNCASEEQ('t','T', "text/html", r->content_type, sizeof("text/html")-1)
386 && ! STRNCASEEQ('a','A', "application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)) {
387 DBG(r,"REQ[%X] no convert. content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
388 DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
392 if (ua && user_agent && strcasecmp(user_agent, ua) != 0) {
394 spec = chxj_specified_device(r, user_agent);
401 if ((entryp->action & CONVRULE_COOKIE_ON_BIT
402 && !(entryp->action & CONVRULE_EMOJI_ONLY_BIT)
403 && !(entryp->action & CONVRULE_ENVINFO_ONLY_BIT))
404 || (entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
405 switch(spec->html_spec_type) {
406 case CHXJ_SPEC_Chtml_1_0:
407 case CHXJ_SPEC_Chtml_2_0:
408 case CHXJ_SPEC_Chtml_3_0:
409 case CHXJ_SPEC_Chtml_4_0:
410 case CHXJ_SPEC_Chtml_5_0:
411 case CHXJ_SPEC_Chtml_6_0:
412 case CHXJ_SPEC_Chtml_7_0:
413 case CHXJ_SPEC_XHtml_Mobile_1_0:
414 case CHXJ_SPEC_Jhtml:
415 cookie = chxj_save_cookie(r);
422 if (!r->header_only) {
424 if ((entryp->action & CONVRULE_COOKIE_ONLY_BIT) && cookie) {
425 dst = chxj_cookie_only_mode(r, *src, (apr_size_t *)len, cookie);
429 if (convert_routine[spec->html_spec_type].encoder)
430 tmp = convert_routine[spec->html_spec_type].encoder(r,
434 if (entryp->action & CONVRULE_EMOJI_ONLY_BIT) {
436 tmp = chxj_node_convert_chxjif_only(r, spec, (const char*)tmp, (apr_size_t *)len);
439 tmp = chxj_node_convert_chxjif_only(r, spec, (const char *)*src, (apr_size_t *)len);
441 if (convert_routine[spec->html_spec_type].emoji_only_converter) {
442 dst = convert_routine[spec->html_spec_type].emoji_only_converter(r,spec, tmp,*len);
447 dst = apr_palloc(r->pool, 1);
452 DBG(r, "REQ[%X] end of chxj_convert()(emoji only)", (unsigned int)(apr_size_t)r);
455 if ( !(entryp->action & CONVRULE_EMOJI_ONLY_BIT)
456 && !(entryp->action & CONVRULE_ENVINFO_ONLY_BIT)) {
457 if (convert_routine[spec->html_spec_type].converter) {
459 dst = convert_routine[spec->html_spec_type].converter(r,
467 dst = convert_routine[spec->html_spec_type].converter(r,
479 if (strcasecmp(spec->output_encoding,"UTF-8") == 0){
480 dst = chxj_iconv(r,r->pool,dst,len,"CP932","UTF-8");
485 ap_set_content_length(r, *len);
488 dst = apr_psprintf(r->pool, "\n");
498 DBG(r, "REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
505 * convert GUID parameter.
509 s_convert_guid_parameter_to_header(request_rec *r, const char *param, device_table *spec)
511 DBG(r, "REQ[%X] start s_convert_guid_parameter() param:[%s]", (unsigned int)(apr_size_t)r, param);
512 if (strcasecmp(param, "guid") == 0) {
513 switch(spec->html_spec_type) {
514 case CHXJ_SPEC_XHtml_Mobile_1_0:
516 char *x_up_subno = (char *)apr_table_get(r->headers_in, "x-up-subno");
518 apr_table_setn(r->headers_in, "X-DCMGUID", x_up_subno);
522 case CHXJ_SPEC_Jhtml:
523 case CHXJ_SPEC_Jxhtml:
525 char *x_jphone_uid = (char *)apr_table_get(r->headers_in, "x-jphone-uid");
527 apr_table_setn(r->headers_in, "X-DCMGUID", x_jphone_uid);
535 DBG(r, "REQ[%X] end s_convert_guid_parameter()", (unsigned int)(apr_size_t)r);
539 * It converts it from HEADER.
544 chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp, device_table *spec)
556 cookie_t *cookie = NULL;
557 int no_update_flag = 0;
559 DBG(r, "REQ[%X] start chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
562 DBG(r, "REQ[%X] r->args=[null]", (unsigned int)(apr_size_t)r);
563 DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
566 urilen = strlen(r->args);
568 result = qs_alloc_zero_byte_string(r->pool);
570 buff_pre = apr_pstrdup(r->pool, r->args);
575 pair = apr_strtok(buff_pre, "&", &pstate);
581 pair_sv = apr_pstrdup(r->pool, pair);
583 name = apr_strtok(pair, "=", &vstate);
584 value = apr_strtok(NULL, "=", &vstate);
585 if (! name) continue;
586 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
587 DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
592 buff = apr_pstrdup(r->pool, r->args);
593 DBG(r, "REQ[%X] r->args=[%s]", (unsigned int)(apr_size_t)r, buff);
602 pair = apr_strtok(buff, "&", &pstate);
608 pair_sv = apr_pstrdup(r->pool, pair);
610 name = apr_strtok(pair, "=", &vstate);
611 value = apr_strtok(NULL, "=", &vstate);
612 if (! name) continue;
613 name = chxj_safe_to_jreserved_tag(r, name);
614 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
615 if (strlen(result) != 0)
616 result = apr_pstrcat(r->pool, result, "&", NULL);
618 if (strcasecmp(entryp->encoding, "NONE") != 0) {
623 if (value && *value != 0) {
624 value = chxj_url_decode(r->pool, value);
625 dlen = strlen(value);
626 DBG(r, "************ before encoding[%s]", value);
628 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
629 dvalue = chxj_url_encode(r->pool, dvalue);
631 DBG(r, "************ after encoding[%s]", dvalue);
637 if (name && *name != 0) {
638 name = chxj_url_decode(r->pool, name);
640 dname = chxj_rencoding(r, name, &dlen,spec->output_encoding);
641 dname = chxj_url_encode(r->pool, dname);
646 s_convert_guid_parameter_to_header(r, dname, spec);
647 result = apr_pstrcat(r->pool, result, dname, "=", dvalue, NULL);
650 s_convert_guid_parameter_to_header(r, name, spec);
651 if (strcmp(name, pair_sv) != 0) {
652 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
655 result = apr_pstrcat(r->pool, result, name, NULL);
660 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
661 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
662 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
666 if (strlen(value) == 0)
669 if (strlen(result) != 0)
670 result = apr_pstrcat(r->pool, result, "&", NULL);
672 result = apr_pstrcat(r->pool, result, &name[8], "=", value, NULL);
675 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
677 apr_table_unset(r->headers_in, "Cookie");
678 DBG(r, "REQ[%X] found cookie parameter[%s]", (unsigned int)(apr_size_t)r, value);
679 DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
680 cookie_lock_t *lock = chxj_cookie_lock(r);
681 cookie = chxj_load_cookie(r, value);
682 DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
683 if (! no_update_flag && cookie) {
684 cookie = chxj_update_cookie(r, cookie);
686 chxj_cookie_unlock(r, lock);
688 if (cookie && cookie->cookie_id) {
689 if (strlen(result) != 0)
690 result = apr_pstrcat(r->pool, result, "&", NULL);
691 result = apr_pstrcat(r->pool, result, name, "=", cookie->cookie_id, NULL);
695 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
696 if (strlen(result) != 0)
697 result = apr_pstrcat(r->pool, result, "&", NULL);
698 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
701 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
702 if (! no_update_flag) {
703 result = apr_pstrcat(r->pool, result, "&_chxj_nc=true", NULL);
707 DBG(r, "REQ[%X] result r->args=[%s]", (unsigned int)(apr_size_t)r, r->args);
708 DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
714 * It converts it from POSTDATA .
717 * @param src [i] It is POSTDATA character string.
718 * @param len [i/o] It is length of former HTML character string.
725 chxjconvrule_entry *entryp,
735 cookie_t *cookie = NULL;
737 int no_update_flag = 0;
741 DBG(r, "REQ[%X] start of chxj_input_convert()", (unsigned int)(apr_size_t)r);
744 DBG(r, "REQ[%X] end of chxj_input_convert() (input is null)", (unsigned int)(apr_size_t)r);
745 return apr_pstrdup(r->pool, "");
748 apr_pool_create(&pool, r->pool);
750 s = apr_pstrdup(pool, *src);
752 buff_pre = apr_pstrdup(pool, *src);
754 result = qs_alloc_zero_byte_string(pool);
756 chxj_dump_string(r, APLOG_MARK, "BEFORE input convert source", s, ilen);
761 pair = apr_strtok(buff_pre, "&", &pstate);
767 pair_sv = apr_pstrdup(pool, pair);
769 name = apr_strtok(pair, "=", &vstate);
770 value = apr_strtok(NULL, "=", &vstate);
771 if (! name) continue;
772 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
773 DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
783 pair = apr_strtok(s, "&", &pstate);
788 name = apr_strtok(pair, "=", &vstate);
789 value = apr_strtok(NULL, "=", &vstate);
790 if (! name) continue;
791 name = chxj_safe_to_jreserved_tag(r, name);
793 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
794 if (strlen(result) != 0)
795 result = apr_pstrcat(pool, result, "&", NULL);
797 if (strcasecmp(entryp->encoding, "NONE") != 0) {
802 if (value && *value != 0) {
803 value = chxj_url_decode(pool, value);
804 dlen = strlen(value);
805 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
806 dvalue = chxj_url_encode(pool, dvalue);
812 if (name && *name != 0) {
813 name = chxj_url_decode(pool, name);
815 dname = chxj_rencoding(r, name, &dlen,spec->output_encoding);
816 dname = chxj_url_encode(pool, dname);
823 result = apr_pstrcat(pool, result, dname, "=", dvalue, NULL);
826 result = apr_pstrcat(pool, result, name, "=", value, NULL);
830 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
831 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
832 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
836 if (strlen(value) == 0)
839 if (strlen(result) != 0)
840 result = apr_pstrcat(pool, result, "&", NULL);
842 if (strcasecmp(entryp->encoding, "NONE") != 0 && value && strlen(value)) {
846 dlen = strlen(value);
847 value = chxj_url_decode(pool, value);
848 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
849 dvalue = chxj_url_encode(pool,dvalue);
850 result = apr_pstrcat(pool, result, &name[8], "=", dvalue, NULL);
854 result = apr_pstrcat(pool, result, &name[8], "=", value, NULL);
858 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
860 apr_table_unset(r->headers_in, "Cookie");
861 DBG(r, "REQ[%X] found cookie parameter[%s]", (unsigned int)(apr_size_t)r, value);
862 DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
863 cookie_lock_t *lock = chxj_cookie_lock(r);
864 cookie = chxj_load_cookie(r, value);
865 DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
866 if (! no_update_flag && cookie) {
867 cookie = chxj_update_cookie(r, cookie);
869 chxj_cookie_unlock(r, lock);
871 if (cookie && cookie->cookie_id) {
872 if (strlen(result) != 0)
873 result = apr_pstrcat(pool, result, "&", NULL);
874 result = apr_pstrcat(pool, result, name, "=", cookie->cookie_id, NULL);
878 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
879 if (strlen(result) != 0)
880 result = apr_pstrcat(pool, result, "&", NULL);
881 result = apr_pstrcat(pool, result, name, "=", value, NULL);
884 if ( strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1) == 0) {
888 dlen = strlen(value);
891 value = chxj_url_decode(pool, value);
892 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
893 dvalue = chxj_url_encode(pool,dvalue);
894 if (r->args && strlen(r->args) > 0) {
895 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
898 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
900 s_convert_guid_parameter_to_header(r, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], spec);
904 if (strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX_ENC, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1) == 0) {
907 dlen = strlen(value);
909 value = chxj_url_decode(pool, value);
910 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
911 dvalue = chxj_url_encode(pool,dvalue);
912 if (r->args && strlen(r->args) > 0) {
913 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
916 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
918 s_convert_guid_parameter_to_header(r, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], spec);
921 DBG(r, "REQ[%X] ************************ name:[%s]", (unsigned int)(apr_size_t)r, name);
923 *len = strlen(result);
924 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
925 if (! no_update_flag) {
926 result = apr_pstrcat(pool, result, "&_chxj_nc=true", NULL);
929 DBG(r, "REQ[%X] AFTER input convert result = [%s]", (unsigned int)(apr_size_t)r, result);
930 DBG(r, "REQ[%X] end chxj_input_convert()", (unsigned int)(apr_size_t)r);
937 * The received data is returned to the filter.
939 * @param f [i/o] It is a filter.
940 * @param data [i] It is data returned to the filter.
941 * @param len [i] It is length of the data returned to the filter.
944 pass_data_to_filter(ap_filter_t *f, const char *data,
947 request_rec *r = f->r;
948 conn_rec *c = r->connection;
950 apr_bucket_brigade *bb;
953 DBG(r, "REQ[%X] start pass_data_to_filter()", (unsigned int)(apr_size_t)r);
955 chxj_header_inf_clear(r);
957 bb = apr_brigade_create(r->pool, c->bucket_alloc);
958 b = apr_bucket_transient_create(data, len, c->bucket_alloc);
960 APR_BRIGADE_INSERT_TAIL(bb, b);
961 b = apr_bucket_eos_create(f->c->bucket_alloc);
962 APR_BRIGADE_INSERT_TAIL(bb, b);
964 rv = ap_pass_brigade(f->next, bb);
965 if (rv != APR_SUCCESS) {
966 DBG(r, "REQ[%X] end pass_data_to_filter() (apr_pass_brigade)", (unsigned int)(apr_size_t)r);
970 DBG(r, "REQ[%X] end pass_data_to_filter()", (unsigned int)(apr_size_t)r);
976 * Add No Cache Header
979 s_add_no_cache_headers(request_rec *r, chxjconvrule_entry *entryp)
981 if (entryp->action & CONVRULE_NOCACHE_ON_BIT) {
982 apr_table_unset(r->headers_out, "Pragma");
983 apr_table_unset(r->err_headers_out, "Pragma");
984 apr_table_unset(r->headers_out, "Expires");
985 apr_table_unset(r->err_headers_out, "Expires");
986 apr_table_unset(r->headers_out, "Cache-Control");
987 apr_table_unset(r->err_headers_out, "Cache-Control");
989 apr_table_setn(r->err_headers_out, "Pragma", "no-cache");
990 apr_table_setn(r->err_headers_out, "Expires", "Thu, 01 Jan 1970 00:00:00 GMT");
991 apr_table_setn(r->err_headers_out, "Cache-Control", "no-cache, no-store");
997 * It is the main loop of the output filter.
999 * @param f [i/o] It is a filter.
1003 chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
1009 char *user_agent = NULL;
1011 mod_chxj_ctx *ctx = (mod_chxj_ctx *)f->ctx;
1012 cookie_t *cookie = NULL;
1013 mod_chxj_config *dconf;
1014 chxjconvrule_entry *entryp = NULL;
1015 device_table *spec = NULL;
1019 DBG(f->r, "REQ[%X] start of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1022 apr_pool_create(&pool, r->pool);
1024 entryp = ctx->entryp;
1026 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1029 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1030 DBG(r, "REQ[%X] found Location header", TO_ADDR(r));
1031 if ((entryp->action & CONVRULE_COOKIE_ON_BIT) || (entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
1032 cookie_lock_t *lock = NULL;
1033 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", TO_ADDR(r));
1034 switch(spec->html_spec_type) {
1035 case CHXJ_SPEC_Chtml_1_0:
1036 case CHXJ_SPEC_Chtml_2_0:
1037 case CHXJ_SPEC_Chtml_3_0:
1038 case CHXJ_SPEC_Chtml_4_0:
1039 case CHXJ_SPEC_Chtml_5_0:
1040 case CHXJ_SPEC_Chtml_6_0:
1041 case CHXJ_SPEC_Chtml_7_0:
1042 case CHXJ_SPEC_XHtml_Mobile_1_0:
1043 case CHXJ_SPEC_Jhtml:
1044 lock = chxj_cookie_lock(r);
1045 cookie = chxj_save_cookie(r);
1046 s_add_cookie_id_if_has_location_header(r, cookie);
1047 chxj_cookie_unlock(r, lock);
1053 if (! ap_is_HTTP_REDIRECT(r->status)) {
1054 r->status = HTTP_MOVED_TEMPORARILY;
1056 s_add_no_cache_headers(r, entryp);
1057 /* must not send body. */
1058 rv = pass_data_to_filter(f, "", 0);
1059 DBG(f->r, "REQ[%X] end of chxj_output_filter()", TO_ADDR(r));
1064 if (r->content_type) {
1065 if (! STRNCASEEQ('t','T',"text/html",r->content_type, sizeof("text/html")-1)
1066 && ! STRNCASEEQ('t','T',"text/xml", r->content_type, sizeof("text/xml")-1)
1067 && ! STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
1068 && ! (dconf->image == CHXJ_IMG_ON
1069 && ! apr_table_get(r->headers_in, "CHXJ_IMG_CONV")
1070 && STRNCASEEQ('i','I',"image/", r->content_type, sizeof("image/") -1)
1071 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
1072 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
1073 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
1074 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
1075 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
1076 || STRCASEEQ('x','X',"x-ms-bmp", &r->content_type[6]) /* BMP */
1077 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
1078 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
1079 || STRCASEEQ('g','G',"gif", &r->content_type[6])))) { /* GIF */
1081 DBG(r, "REQ[%X] not convert content-type:[%s] dconf->image:[%d]", (unsigned int)(apr_size_t)r, r->content_type, dconf->image);
1082 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
1083 cookie_lock_t *lock = NULL;
1084 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
1085 switch(spec->html_spec_type) {
1086 case CHXJ_SPEC_Chtml_1_0:
1087 case CHXJ_SPEC_Chtml_2_0:
1088 case CHXJ_SPEC_Chtml_3_0:
1089 case CHXJ_SPEC_Chtml_4_0:
1090 case CHXJ_SPEC_Chtml_5_0:
1091 case CHXJ_SPEC_Chtml_6_0:
1092 case CHXJ_SPEC_Chtml_7_0:
1093 case CHXJ_SPEC_XHtml_Mobile_1_0:
1094 case CHXJ_SPEC_Jhtml:
1095 lock = chxj_cookie_lock(r);
1096 cookie = chxj_save_cookie(r);
1097 s_add_cookie_id_if_has_location_header(r, cookie);
1098 chxj_cookie_unlock(r, lock);
1104 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1105 if (! ap_is_HTTP_REDIRECT(r->status)) {
1106 r->status = HTTP_MOVED_TEMPORARILY;
1109 s_add_no_cache_headers(r, entryp);
1110 ap_pass_brigade(f->next, bb);
1111 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1116 DBG(r, "REQ[%X] not convert content-type:[(null)]", (unsigned int)(apr_size_t)r);
1117 ap_pass_brigade(f->next, bb);
1118 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1123 for (b = APR_BRIGADE_FIRST(bb);
1124 b != APR_BRIGADE_SENTINEL(bb);
1125 b = APR_BUCKET_NEXT(b)) {
1127 if (apr_bucket_read(b, &data, &len, APR_BLOCK_READ) == APR_SUCCESS) {
1128 chxj_dump_string(r, APLOG_MARK, "READ Data", data, len);
1130 /*--------------------------------------------------------------------*/
1132 /*--------------------------------------------------------------------*/
1134 DBG(r, "append data start");
1135 ctx = (mod_chxj_ctx *)f->ctx;
1138 tmp = apr_palloc(r->pool, ctx->len);
1139 memcpy(tmp, ctx->buffer, ctx->len);
1141 ctx->buffer = apr_palloc(pool, ctx->len + len);
1143 memcpy(ctx->buffer, tmp, ctx->len);
1144 memcpy(&ctx->buffer[ctx->len], data, len);
1148 DBG(r, "REQ[%X] append data end", (unsigned int)(apr_size_t)r);
1151 if (APR_BUCKET_IS_EOS(b)) {
1153 DBG(r, "REQ[%X] eos", (unsigned int)(apr_size_t)r);
1154 /*----------------------------------------------------------------------*/
1156 /*----------------------------------------------------------------------*/
1158 cookie_lock_t *lock = NULL;
1159 ctx = (mod_chxj_ctx *)f->ctx;
1161 DBG(r, "REQ[%X] content_type=[%s]", (unsigned int)(apr_size_t)r, r->content_type);
1162 lock = chxj_cookie_lock(r);
1164 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
1166 && (STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
1167 || STRNCASEEQ('t','T',"text/html", r->content_type, sizeof("text/html")-1))) {
1168 DBG(r, "REQ[%X] detect convert target:[%s]", (unsigned int)(apr_size_t)r, r->content_type);
1173 tmp = apr_palloc(pool, ctx->len + 1);
1175 memset(tmp, 0, ctx->len + 1);
1176 memcpy(tmp, ctx->buffer, ctx->len);
1178 ctx->buffer = chxj_convert(r,
1179 (const char **)&tmp,
1180 (apr_size_t *)&ctx->len,
1182 user_agent, &cookie);
1186 ctx->buffer = apr_psprintf(r->pool, "\n");
1188 ctx->buffer = chxj_convert(r,
1189 (const char **)&ctx->buffer,
1190 (apr_size_t *)&ctx->len,
1192 user_agent, &cookie);
1197 && *(char *)r->content_type == 't'
1198 && strncmp(r->content_type, "text/xml", 8) == 0) {
1199 DBG(r, "REQ[%X] text/XML", (unsigned int)(apr_size_t)r);
1207 memset(&doc, 0, sizeof(Doc));
1208 memset(&qrcode, 0, sizeof(qr_code_t));
1210 doc.parse_mode = PARSE_MODE_CHTML;
1214 qs_init_malloc(&doc);
1216 root = qs_parse_string(&doc, ctx->buffer, ctx->len);
1219 for (child = qs_get_child_node(&doc,root);
1221 child = qs_get_next_node(&doc,child)) {
1222 char *name = qs_get_node_name(&doc,child);
1223 if (strcasecmp("qrcode",name) == 0) {
1228 qs_all_free(&doc,QX_LOGMARK);
1230 r->handler = apr_psprintf(r->pool, "chxj-qrcode");
1231 chxj_qrcode_node_to_qrcode(&qrcode, root);
1232 sts = chxj_qrcode_create_image_data(&qrcode, &ctx->buffer, &ctx->len);
1234 ERR(r, "REQ[%X] qrcode create failed.", (unsigned int)(apr_size_t)r);
1235 chxj_cookie_unlock(r, lock);
1236 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1239 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1243 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
1245 && ( *r->content_type == 'i' || *r->content_type == 'I')
1246 && dconf->image == CHXJ_IMG_ON
1247 && strncasecmp("image/", r->content_type, 6) == 0
1248 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
1249 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
1250 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
1251 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
1252 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
1253 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
1254 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
1255 || STRCASEEQ('x','X',"x-ms-bmp", &r->content_type[6]) /* BMP */
1256 || STRCASEEQ('g','G',"gif", &r->content_type[6]))) { /* GIF */
1257 DBG(r, "REQ[%X] detect convert target:[%s]", (unsigned int)(apr_size_t)r, r->content_type);
1261 tmp = apr_palloc(pool, ctx->len + 1);
1263 memset(tmp, 0, ctx->len + 1);
1264 memcpy(tmp, ctx->buffer, ctx->len);
1266 chxj_convert_image(r,
1267 (const char **)&tmp,
1268 (apr_size_t *)&ctx->len);
1269 if (ctx->buffer == NULL) {
1275 apr_table_unset(r->headers_out, "Content-Length");
1276 apr_table_unset(r->err_headers_out, "Content-Length");
1277 ap_set_content_length(r, (apr_off_t)ctx->len);
1281 DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1282 s_add_cookie_id_if_has_location_header(r, cookie);
1283 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1284 if (! ap_is_HTTP_REDIRECT(r->status)) {
1285 r->status = HTTP_MOVED_TEMPORARILY;
1288 if (ctx->len && ap_is_HTTP_REDIRECT(r->status)) {
1289 ctx->buffer = apr_pstrdup(pool, "");
1291 ap_set_content_length(r, (apr_off_t)ctx->len);
1293 chxj_cookie_unlock(r,lock);
1294 s_add_no_cache_headers(r, entryp);
1295 rv = pass_data_to_filter(f,
1296 (const char *)ctx->buffer,
1297 (apr_size_t)ctx->len);
1300 ctx->buffer = apr_pstrdup(pool, "");
1302 ap_set_content_length(r, (apr_off_t)ctx->len);
1303 chxj_cookie_unlock(r, lock);
1304 s_add_no_cache_headers(r, entryp);
1305 rv = pass_data_to_filter(f,
1306 (const char *)ctx->buffer,
1307 (apr_size_t)ctx->len);
1309 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1313 DBG(r, "REQ[%X] SAVE COOKIE[%x]", (unsigned int)(apr_size_t)r, entryp->action);
1318 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
1319 cookie_lock_t *lock = NULL;
1320 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
1321 switch(spec->html_spec_type) {
1322 case CHXJ_SPEC_Chtml_1_0:
1323 case CHXJ_SPEC_Chtml_2_0:
1324 case CHXJ_SPEC_Chtml_3_0:
1325 case CHXJ_SPEC_Chtml_4_0:
1326 case CHXJ_SPEC_Chtml_5_0:
1327 case CHXJ_SPEC_Chtml_6_0:
1328 case CHXJ_SPEC_Chtml_7_0:
1329 case CHXJ_SPEC_XHtml_Mobile_1_0:
1330 case CHXJ_SPEC_Jhtml:
1331 lock = chxj_cookie_lock(r);
1332 cookie = chxj_save_cookie(r);
1334 * Location Header Check to add cookie parameter.
1336 s_add_cookie_id_if_has_location_header(r, cookie);
1337 chxj_cookie_unlock(r, lock);
1338 apr_table_unset(r->headers_out, "Set-Cookie");
1339 apr_table_unset(r->err_headers_out, "Set-Cookie");
1346 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1347 if (! ap_is_HTTP_REDIRECT(r->status)) {
1348 r->status = HTTP_MOVED_TEMPORARILY;
1351 apr_table_setn(r->headers_out, "Content-Length", "0");
1352 DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1353 s_add_no_cache_headers(r, entryp);
1354 rv = pass_data_to_filter(f, (const char *)"", (apr_size_t)0);
1355 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1360 apr_brigade_destroy(bb);
1362 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1368 * Add Cookie_id if it has location header.
1371 s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie)
1373 char *location_header = (char *)apr_table_get(r->headers_out, "Location");
1374 if (! location_header) {
1375 location_header = (char *)apr_table_get(r->err_headers_out, "Location");
1377 if (cookie && location_header) {
1378 DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1379 location_header = chxj_add_cookie_parameter(r,
1382 apr_table_unset(r->headers_out, "Location");
1383 apr_table_setn(r->headers_out, "Location", location_header);
1384 DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1385 if (!ap_is_HTTP_REDIRECT(r->status)) {
1386 r->status = HTTP_MOVED_TEMPORARILY;
1392 * It is the main loop of the input filter handler.
1396 chxj_input_handler(request_rec *r)
1398 mod_chxj_config *dconf;
1399 chxjconvrule_entry *entryp = NULL;
1400 device_table *spec = NULL;
1401 char *post_data = NULL;
1402 apr_size_t post_data_len = 0;
1407 int response_code = 0;
1409 DBG(r, "start of chxj_input_handler()");
1411 if (strcasecmp(r->handler, "chxj-input-handler")) {
1412 DBG(r, "end chxj_input_handler()");
1415 apr_pool_create(&pool, r->pool);
1417 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1418 user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
1420 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
1422 spec = chxj_specified_device(r, user_agent);
1423 entryp = chxj_apply_convrule(r, dconf->convrules);
1425 post_data = apr_pstrdup(pool, "");
1426 if (ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK) == OK) {
1427 if (ap_should_client_block(r)) {
1428 while (post_data_len < CHXJ_POST_MAX) {
1431 int read_bytes = ap_get_client_block(r, buffer, BUFSZ-1);
1432 if (read_bytes<=0) {
1435 buffer[read_bytes] = '\0';
1436 post_data = apr_pstrcat(pool, post_data, buffer, NULL);
1437 post_data_len += read_bytes;
1446 if (post_data_len > 0) {
1447 post_data = chxj_input_convert(r, (const char**)&post_data, (apr_size_t*)&post_data_len, entryp, spec);
1448 DBG(r, "(in:exchange)POSTDATA:[%s]", post_data);
1452 if (dconf->forward_url_base) {
1453 url_path = apr_psprintf(pool, "%s%s", dconf->forward_url_base, r->uri);
1456 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);
1459 url_path = apr_pstrcat(pool, url_path, "?", r->args, NULL);
1461 DBG(r, "==> new url_path:[%s]", url_path);
1464 apr_table_setn(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP, r->connection->remote_ip);
1465 apr_table_unset(r->headers_in, "Content-Length");
1466 apr_table_setn(r->headers_in, "Content-Length", apr_psprintf(pool, "%" APR_SIZE_T_FMT, post_data_len));
1467 response = chxj_serf_post(r, pool, url_path, post_data, post_data_len, 1, &res_len, &response_code);
1468 DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1469 DBG(r, "REQ[%X] response length:[%" APR_SIZE_T_FMT "]", (unsigned int)(apr_size_t)r, res_len);
1470 for (ii=0; ii<res_len/64; ii++) {
1471 DBG(r, "REQ[%X] response:[%.*s]", (unsigned int)(apr_size_t)r, 64, &response[ii*64]);
1473 DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1476 if ((chunked = (char *)apr_table_get(r->headers_out, "Transfer-Encoding")) != NULL) {
1477 if (strcasecmp(chunked, "chunked") == 0) {
1479 apr_table_unset(r->headers_out, "Transfer-Encoding");
1482 if (ap_is_HTTP_ERROR(response_code)) {
1483 DBG(r, "REQ[%X] end of chxj_input_handler() (HTTP-ERROR received. response code:[%d])", (unsigned int)(apr_size_t)r, response_code);
1484 return response_code;
1488 apr_pool_create(&wpool, r->pool);
1489 apr_bucket_brigade *bb;
1492 conn_rec *c = r->connection;
1494 bb = apr_brigade_create(wpool, c->bucket_alloc);
1495 e = apr_bucket_transient_create(response, res_len, c->bucket_alloc);
1496 APR_BRIGADE_INSERT_TAIL(bb, e);
1497 e = apr_bucket_eos_create(c->bucket_alloc);
1498 APR_BRIGADE_INSERT_TAIL(bb, e);
1499 if ((rv = ap_pass_brigade(r->output_filters, bb)) != APR_SUCCESS) {
1500 ERR(r, "REQ[%X] %s:%d failed ap_pass_brigade()", (unsigned int)(apr_size_t)r, APLOG_MARK);
1503 apr_brigade_cleanup(bb);
1506 DBG(r, "REQ[%X] end of chxj_input_handler()", (unsigned int)(apr_size_t)r);
1510 static mod_chxj_global_config *
1511 chxj_global_config_create(apr_pool_t *pool, server_rec *s)
1513 mod_chxj_global_config *conf;
1515 SDBG(s, "start chxj_global_config_create()");
1517 /*--------------------------------------------------------------------------*/
1518 /* allocate an own subpool which survives server restarts */
1519 /*--------------------------------------------------------------------------*/
1520 conf = (mod_chxj_global_config *)apr_palloc(pool,
1521 sizeof(mod_chxj_global_config));
1523 conf->cookie_db_lock = NULL;
1525 SDBG(s, "end chxj_global_config_create()");
1532 * initialize chxj module
1535 chxj_init_module(apr_pool_t *p,
1536 apr_pool_t *UNUSED(plog),
1537 apr_pool_t *UNUSED(ptemp),
1543 SDBG(s, "start chxj_init_module()");
1545 apr_pool_userdata_get(&user_data, CHXJ_MOD_CONFIG_KEY, s->process->pool);
1547 if (user_data == NULL) {
1550 * dummy user_data set.
1552 apr_pool_userdata_set(
1554 CHXJ_MOD_CONFIG_KEY,
1555 apr_pool_cleanup_null,
1557 SDBG(s, "end chxj_init_module()");
1561 ap_add_version_component(p, CHXJ_VERSION_PREFIX CHXJ_VERSION);
1563 if ((rv = apr_proc_mutex_create(&global_cookie_mutex, NULL, APR_LOCK_FCNTL, s->process->pool)) != APR_SUCCESS) {
1565 SERR(s, "%s:%d end chxj_init_module(). mutex create failure.(%d:%s)",APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1566 return HTTP_INTERNAL_SERVER_ERROR;
1569 SDBG(s, "end chxj_init_module()");
1576 chxj_child_init(apr_pool_t *UNUSED(p), server_rec *s)
1579 SDBG(s, "start chxj_child_init()");
1580 if ((rv = apr_proc_mutex_child_init(&global_cookie_mutex, NULL, s->process->pool)) != APR_SUCCESS) {
1582 SERR(s, "%s:%d ERROR end chxj_init_module(). mutex create failure.(%d:%s)", APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1584 SDBG(s, "end chxj_child_init()");
1589 * A set structure of each server is generated.
1595 chxj_config_server_create(apr_pool_t *p, server_rec *s)
1597 mod_chxj_global_config *gc;
1599 gc = chxj_global_config_create(p,s);
1606 chxj_translate_name(request_rec *r)
1608 DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1609 DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1610 DBG(r, "REQ[%X] START REQUEST (uri:[%s] args:[%s])", (unsigned int)(apr_size_t)r, r->unparsed_uri, r->args ? r->args : "");
1611 DBG(r, "REQ[%X] METHOD [%s]", TO_ADDR(r), r->method);
1612 DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1613 DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1615 return chxj_trans_name(r);
1623 chxj_insert_filter(request_rec *r)
1627 mod_chxj_config *dconf;
1628 chxjconvrule_entry *entryp;
1633 DBG(r, "REQ[%X] start chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1635 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1637 /* we get User-Agent from CHXJ_HTTP_USER_AGENT header if any */
1638 user_agent = (char *)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
1640 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
1643 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
1645 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
1646 DBG(r, "REQ[%X] detect multipart/form-data ==> no target", (unsigned int)(apr_size_t)r);
1647 DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1651 spec = chxj_specified_device(r, user_agent);
1652 entryp = chxj_apply_convrule(r, dconf->convrules);
1654 DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1657 ctx = apr_palloc(r->pool, sizeof(*ctx));
1658 memset(ctx, 0, sizeof(*ctx));
1659 if ((rv = apr_pool_create(&ctx->pool, r->pool)) != APR_SUCCESS) {
1660 ERR(r, "%s:%d: failed: new pool create. rv:[%d]", __FILE__,__LINE__,rv);
1661 DBG(r, "REQ:[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1664 ctx->entryp = entryp;
1666 ctx->buffer = apr_palloc(ctx->pool, 1);
1669 if (!entryp || (!(entryp->action & CONVRULE_ENGINE_ON_BIT) && !(entryp->action & CONVRULE_COOKIE_ONLY_BIT))) {
1670 DBG(r,"REQ[%X] EngineOff", (unsigned int)(apr_size_t)r);
1671 DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1675 switch(spec->html_spec_type) {
1676 case CHXJ_SPEC_Chtml_1_0:
1677 case CHXJ_SPEC_Chtml_2_0:
1678 case CHXJ_SPEC_Chtml_3_0:
1679 case CHXJ_SPEC_Chtml_4_0:
1680 case CHXJ_SPEC_Chtml_5_0:
1681 case CHXJ_SPEC_Chtml_6_0:
1682 case CHXJ_SPEC_Chtml_7_0:
1683 case CHXJ_SPEC_XHtml_Mobile_1_0:
1684 case CHXJ_SPEC_Hdml:
1685 case CHXJ_SPEC_Jhtml:
1686 case CHXJ_SPEC_Jxhtml:
1690 DBG(r, "REQ[%X] end chxj_insert_filter() Unknown spec type(%d).", (unsigned int)(apr_size_t)r, spec->html_spec_type);
1695 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
1696 ap_add_output_filter("chxj_output_filter", ctx, r, r->connection);
1697 DBG(r, "REQ[%X] added Output Filter", (unsigned int)(apr_size_t)r);
1700 DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1705 * The hook is registered.
1710 chxj_register_hooks(apr_pool_t *UNUSED(p))
1712 ap_hook_post_config(chxj_init_module,
1715 APR_HOOK_REALLY_FIRST);
1716 ap_hook_child_init(chxj_child_init,
1719 APR_HOOK_REALLY_FIRST);
1720 ap_register_output_filter (
1721 "chxj_output_filter",
1725 ap_hook_insert_filter(chxj_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
1726 ap_hook_handler(chxj_img_conv_format_handler, NULL, NULL, APR_HOOK_MIDDLE);
1727 ap_hook_handler(chxj_qr_code_handler, NULL, NULL, APR_HOOK_MIDDLE);
1728 ap_hook_handler(chxj_input_handler, NULL, NULL, APR_HOOK_MIDDLE);
1729 ap_hook_translate_name(chxj_translate_name, NULL, NULL, APR_HOOK_MIDDLE);
1730 ap_hook_fixups(chxj_headers_fixup, NULL, NULL, APR_HOOK_FIRST);
1735 * A set structure according to the directory is generated.
1741 chxj_create_per_dir_config(apr_pool_t *p, char *arg)
1743 mod_chxj_config *conf;
1745 conf = apr_pcalloc(p, sizeof(mod_chxj_config));
1746 conf->device_data_file = NULL;
1747 conf->devices = NULL;
1748 conf->emoji_data_file = NULL;
1750 conf->emoji_tail = NULL;
1751 conf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_NONE;
1752 conf->image = CHXJ_IMG_NONE;
1753 conf->image_cache_dir = apr_psprintf(p, "%s",DEFAULT_IMAGE_CACHE_DIR);
1754 conf->image_cache_limit = 0;
1755 conf->server_side_encoding = NULL;
1756 conf->cookie_db_dir = NULL;
1757 conf->cookie_timeout = 0;
1758 conf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
1759 conf->cookie_lazy_mode = 0;
1760 conf->cookie_dbm_type = NULL;
1762 conf->detect_device_type = CHXJ_ADD_DETECT_DEVICE_TYPE_NONE;
1764 #if defined(USE_MYSQL_COOKIE)
1765 memset((void *)&conf->mysql, 0, sizeof(mysql_t));
1766 conf->mysql.port = MYSQL_PORT;
1767 conf->mysql.host = NULL;
1769 #if defined(USE_MEMCACHE_COOKIE)
1770 memset((void *)&conf->memcache, 0, sizeof(memcache_t));
1771 conf->memcache.host = NULL;
1772 conf->memcache.port = 0;
1774 conf->forward_url_base = NULL;
1775 conf->forward_server_ip = NULL;
1776 conf->allowed_cookie_domain = NULL;
1777 conf->post_log = NULL;
1783 conf->dir = apr_pcalloc(p, strlen(arg)+1);
1784 memset(conf->dir, 0, strlen(arg)+1);
1785 strcpy(conf->dir, arg);
1787 conf->convrules = apr_array_make(p, 2, sizeof(chxjconvrule_entry));
1789 /* Default is copyleft */
1790 conf->image_copyright = NULL;
1797 * Merge per-directory CHXJ configurations
1800 chxj_merge_per_dir_config(apr_pool_t *p, void *basev, void *addv)
1802 mod_chxj_config *base;
1803 mod_chxj_config *add;
1804 mod_chxj_config *mrg;
1806 base = (mod_chxj_config *)basev;
1807 add = (mod_chxj_config *)addv;
1808 mrg = (mod_chxj_config *)apr_palloc(p, sizeof(mod_chxj_config));
1810 mrg->device_data_file = NULL;
1811 mrg->devices = NULL;
1812 mrg->emoji_data_file = NULL;
1813 mrg->image = CHXJ_IMG_NONE;
1814 mrg->image_cache_dir = NULL;
1815 mrg->image_copyright = NULL;
1816 mrg->image_cache_limit = 0;
1818 mrg->emoji_tail = NULL;
1819 mrg->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_NONE;
1820 mrg->new_line_type = NLTYPE_NIL;
1821 mrg->forward_url_base = NULL;
1822 mrg->forward_server_ip = NULL;
1823 mrg->allowed_cookie_domain = NULL;
1824 mrg->post_log = NULL;
1825 mrg->cookie_dbm_type = NULL;
1827 mrg->device_keys = NULL;
1828 mrg->device_hash = NULL;
1830 mrg->dir = apr_pstrdup(p, add->dir);
1832 if (! add->device_data_file) {
1833 mrg->devices = base->devices;
1834 mrg->device_data_file = apr_pstrdup(p, base->device_data_file);
1837 mrg->devices = add->devices;
1838 mrg->device_data_file = apr_pstrdup(p, add->device_data_file);
1841 if (! add->emoji_data_file) {
1842 mrg->emoji = base->emoji;
1843 mrg->emoji_tail = base->emoji_tail;
1844 mrg->emoji_data_file = apr_pstrdup(p, base->emoji_data_file);
1847 mrg->emoji = add->emoji;
1848 mrg->emoji_tail = add->emoji_tail;
1849 mrg->emoji_data_file = apr_pstrdup(p, add->emoji_data_file);
1852 if (add->image == CHXJ_IMG_NONE) {
1853 mrg->image = base->image;
1856 mrg->image = add->image;
1859 if (strcasecmp(add->image_cache_dir ,DEFAULT_IMAGE_CACHE_DIR)==0) {
1860 mrg->image_cache_dir = apr_pstrdup(p, base->image_cache_dir);
1863 mrg->image_cache_dir = apr_pstrdup(p, add->image_cache_dir);
1866 if (add->image_cache_limit) {
1867 mrg->image_cache_limit = add->image_cache_limit;
1870 mrg->image_cache_limit = base->image_cache_limit;
1873 if (add->image_copyright)
1874 mrg->image_copyright = apr_pstrdup(p, add->image_copyright);
1876 mrg->image_copyright = apr_pstrdup(p, base->image_copyright);
1878 if (add->server_side_encoding) {
1879 mrg->server_side_encoding = apr_pstrdup(p, add->server_side_encoding);
1882 if (base->server_side_encoding) {
1883 mrg->server_side_encoding = apr_pstrdup(p, base->server_side_encoding);
1886 mrg->server_side_encoding = apr_pstrdup(p, DEFAULT_SERVER_SIDE_ENCODING);
1889 mrg->convrules = apr_array_append(p, add->convrules, base->convrules);
1891 if (add->cookie_db_dir) {
1892 mrg->cookie_db_dir = apr_pstrdup(p, add->cookie_db_dir);
1895 if (base->cookie_db_dir) {
1896 mrg->cookie_db_dir = apr_pstrdup(p, base->cookie_db_dir);
1899 mrg->cookie_db_dir = NULL;
1902 if (add->cookie_timeout) {
1903 mrg->cookie_timeout = add->cookie_timeout;
1906 if (base->cookie_db_dir) {
1907 mrg->cookie_timeout = base->cookie_timeout;
1910 mrg->cookie_timeout = 0;
1913 #if defined(USE_MYSQL_COOKIE)
1914 if (add->mysql.host) {
1915 mrg->mysql.host = apr_pstrdup(p, add->mysql.host);
1917 else if (base->mysql.host) {
1918 mrg->mysql.host = apr_pstrdup(p, base->mysql.host);
1921 mrg->mysql.host = NULL;
1923 if (add->mysql.port) {
1924 mrg->mysql.port = add->mysql.port;
1926 else if (base->mysql.port) {
1927 mrg->mysql.port = base->mysql.port;
1930 mrg->mysql.port = 0;
1933 if (add->mysql.database) {
1934 mrg->mysql.database = apr_pstrdup(p, add->mysql.database);
1936 else if (base->mysql.database) {
1937 mrg->mysql.database = apr_pstrdup(p, base->mysql.database);
1940 mrg->mysql.database = NULL;
1943 if (add->mysql.username) {
1944 mrg->mysql.username = apr_pstrdup(p, add->mysql.username);
1946 else if (base->mysql.username) {
1947 mrg->mysql.username = apr_pstrdup(p, base->mysql.username);
1950 mrg->mysql.username = NULL;
1953 if (add->mysql.password) {
1954 mrg->mysql.password = apr_pstrdup(p, add->mysql.password);
1956 else if (base->mysql.password) {
1957 mrg->mysql.password = apr_pstrdup(p, base->mysql.password);
1960 mrg->mysql.password = NULL;
1963 if (add->mysql.tablename) {
1964 mrg->mysql.tablename = apr_pstrdup(p, add->mysql.tablename);
1966 else if (base->mysql.tablename) {
1967 mrg->mysql.tablename = apr_pstrdup(p, base->mysql.tablename);
1970 mrg->mysql.tablename = NULL;
1973 if (add->mysql.socket_path) {
1974 mrg->mysql.socket_path = apr_pstrdup(p, add->mysql.socket_path);
1976 else if (base->mysql.socket_path) {
1977 mrg->mysql.socket_path = apr_pstrdup(p, base->mysql.socket_path);
1980 mrg->mysql.socket_path = NULL;
1983 if (add->mysql.charset) {
1984 mrg->mysql.charset = apr_pstrdup(p, add->mysql.charset);
1986 else if (base->mysql.charset) {
1987 mrg->mysql.charset = apr_pstrdup(p, base->mysql.charset);
1990 mrg->mysql.charset = NULL;
1993 #if defined(USE_MEMCACHE_COOKIE)
1994 if (add->memcache.host) {
1995 mrg->memcache.host = apr_pstrdup(p, add->memcache.host);
1997 else if (base->memcache.host) {
1998 mrg->memcache.host = apr_pstrdup(p, base->memcache.host);
2001 mrg->memcache.host = NULL;
2003 if (add->memcache.port) {
2004 mrg->memcache.port = add->memcache.port;
2006 else if (base->memcache.port) {
2007 mrg->memcache.port = base->memcache.port;
2010 mrg->memcache.port = 0;
2013 if (add->cookie_store_type) {
2014 mrg->cookie_store_type = add->cookie_store_type;
2016 else if (base->cookie_store_type) {
2017 mrg->cookie_store_type = base->cookie_store_type;
2020 mrg->cookie_store_type = COOKIE_STORE_TYPE_NONE;
2022 if (add->cookie_lazy_mode) {
2023 mrg->cookie_lazy_mode = add->cookie_lazy_mode;
2025 else if (base->cookie_lazy_mode) {
2026 mrg->cookie_lazy_mode = base->cookie_lazy_mode;
2029 mrg->cookie_lazy_mode = 0;
2031 if (add->new_line_type) {
2032 mrg->new_line_type = add->new_line_type;
2034 else if (base->new_line_type) {
2035 mrg->new_line_type = base->new_line_type;
2038 mrg->new_line_type = NLTYPE_NIL;
2041 if (add->forward_url_base) {
2042 mrg->forward_url_base = add->forward_url_base;
2044 else if (base->forward_url_base) {
2045 mrg->forward_url_base = base->forward_url_base;
2048 if (add->allowed_cookie_domain) {
2049 mrg->allowed_cookie_domain = add->allowed_cookie_domain;
2052 mrg->allowed_cookie_domain = base->allowed_cookie_domain;
2054 if (add->post_log) {
2055 mrg->post_log = add->post_log;
2058 mrg->post_log = base->post_log;
2060 if (add->cookie_dbm_type) {
2061 mrg->cookie_dbm_type = add->cookie_dbm_type;
2064 mrg->cookie_dbm_type = base->cookie_dbm_type;
2067 if (add->imode_emoji_color == CHXJ_IMODE_EMOJI_COLOR_NONE) {
2068 mrg->imode_emoji_color = base->imode_emoji_color;
2071 mrg->imode_emoji_color = add->imode_emoji_color;
2074 if (add->detect_device_type == CHXJ_ADD_DETECT_DEVICE_TYPE_NONE) {
2075 mrg->detect_device_type = base->detect_device_type;
2078 mrg->detect_device_type = add->detect_device_type;
2081 if (add->device_keys) {
2082 mrg->device_keys = add->device_keys;
2085 mrg->device_keys = base->device_keys;
2088 if (add->device_hash) {
2089 mrg->device_hash = add->device_hash;
2092 mrg->device_hash = base->device_hash;
2100 chxj_command_parse_take5(
2113 for (;*strp == ' '||*strp == '\t'; strp++) ;
2123 for (; *strp != '\0'; strp++) {
2124 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2125 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2130 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2131 || (isquoted && *strp == '"'))
2145 for (;*strp == ' '||*strp == '\t'; strp++) ;
2154 for (; *strp != '\0'; strp++) {
2155 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2156 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2161 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2162 || (isquoted && *strp == '"'))
2175 for (;*strp == ' '||*strp == '\t'; strp++);
2183 for (; *strp != '\0'; strp++) {
2184 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2185 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2190 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2191 || (isquoted && *strp == '"'))
2203 for (;*strp == ' '||*strp == '\t'; strp++);
2211 for (; *strp != '\0'; strp++) {
2212 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2213 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2218 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2219 || (isquoted && *strp == '"'))
2230 for (;*strp == ' '||*strp == '\t'; strp++);
2238 for (; *strp != '\0'; strp++) {
2239 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2240 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2245 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2246 || (isquoted && *strp == '"'))
2256 * The device definition file is loaded.
2258 * @param arg [i] The name of the device definition file is specified.
2259 * @param mconfig [i/o] The pointer to a set structure is specified.
2263 cmd_load_device_data(cmd_parms *parms, void *mconfig, const char *arg)
2265 mod_chxj_config *conf;
2270 if (strlen(arg) > 256)
2271 return "mod_chxj: device data filename too long.";
2273 conf = (mod_chxj_config *)mconfig;
2274 conf->device_data_file = apr_pstrdup(parms->pool, arg);
2276 qs_init_malloc(&doc);
2277 qs_init_root_node(&doc);
2279 qs_parse_file((Doc *)&doc, (const char *)arg);
2280 chxj_load_device_data(&doc,parms->pool, conf);
2281 qs_all_free(&doc, QX_LOGMARK);
2288 * Device definition information is loaded.
2291 * @param arg [i] The name of the device definition file is specified.
2292 * @param mconfig [i/o] The pointer to a set structure is specified.
2296 cmd_load_emoji_data(cmd_parms *parms, void *mconfig, const char *arg)
2298 mod_chxj_config *conf;
2305 if (strlen(arg) > 256)
2306 return "mod_chxj: emoji data filename too long.";
2308 conf = (mod_chxj_config *)mconfig;
2309 conf->emoji_data_file = apr_pstrdup(parms->pool, arg);
2310 qs_init_malloc(&doc);
2311 qs_init_root_node(&doc);
2313 qs_parse_file((Doc *)&doc, (const char *)arg);
2315 rtn = chxj_load_emoji_data(&doc,parms->pool, conf);
2317 qs_all_free(&doc, QX_LOGMARK);
2325 cmd_set_image_engine(cmd_parms * UNUSED(parms), void *mconfig, const char *arg)
2327 mod_chxj_config *conf;
2332 if (strlen(arg) > 256)
2333 return "image uri is too long.";
2335 conf = (mod_chxj_config*)mconfig;
2336 if (strcasecmp("ON", arg) == 0) {
2337 conf->image = CHXJ_IMG_ON;
2340 conf->image = CHXJ_IMG_OFF;
2348 cmd_set_image_cache_dir(cmd_parms *parms, void *mconfig, const char *arg)
2350 mod_chxj_config *conf;
2355 if (strlen(arg) > 256)
2356 return "cache dir name is too long.";
2359 apr_status_t res = apr_stat(&info,arg,APR_FINFO_TYPE,parms->pool);
2360 if(res != APR_SUCCESS){
2361 return apr_psprintf(parms->pool,"ChxjImageCacheDir [%s]: not found ",arg);
2364 if(info.filetype != APR_DIR){
2365 return apr_psprintf(parms->pool,"ChxjImageCacheDir [%s]: is not directory ",arg);
2369 conf = (mod_chxj_config *)mconfig;
2370 conf->image_cache_dir = apr_pstrdup(parms->pool, arg);
2377 cmd_set_image_cache_limit(cmd_parms *parms, void *mconfig, const char *arg)
2379 mod_chxj_config *conf;
2384 if (strlen(arg) > IMAGE_CACHE_LIMIT_FMT_LEN)
2385 return "cache size is too long.";
2387 conf = (mod_chxj_config *)mconfig;
2390 * I use strtol function because strtoul is not portable function.
2392 conf->image_cache_limit = (unsigned long)strtol(arg, NULL, 10);
2395 return apr_psprintf(parms->pool, "ChxjImageCacheLimit invalid value [%s] errno:[%d]", arg, errno);
2397 return apr_psprintf(parms->pool, "ChxjImageCacheLimit Out of range [%s] errno:[%d]", arg, errno);
2406 cmd_set_image_copyright(cmd_parms *parms, void *mconfig, const char *arg)
2408 mod_chxj_config *conf;
2413 if (strlen(arg) > 256)
2414 return "Copyright Flag is too long.";
2416 conf = (mod_chxj_config *)mconfig;
2417 conf->image_copyright = apr_pstrdup(parms->pool, arg);
2424 cmd_convert_rule(cmd_parms *cmd, void *mconfig, const char *arg)
2428 mod_chxj_config *dconf;
2429 chxjconvrule_entry *newrule;
2439 dconf = (mod_chxj_config *)mconfig;
2441 if (strlen(arg) > 4096)
2442 return "mod_chxj: ChxjConvertRule: is too long.";
2444 dconf = (mod_chxj_config *)mconfig;
2445 if (dconf->convrules == NULL)
2446 dconf->convrules = apr_array_make(cmd->pool,
2448 sizeof(chxjconvrule_entry));
2450 newrule = apr_array_push(dconf->convrules);
2453 newrule->action = 0;
2455 if (chxj_command_parse_take5(arg, &prm1, &prm2, &prm3, &prm4, &prm5))
2456 return "ChxjConvertRule: bad argument line";
2458 newrule->pattern = apr_pstrdup(cmd->pool, prm1);
2462 if ((action = apr_strtok(prm2, ",", &pstate)) == NULL)
2468 if (strcasecmp(CONVRULE_ENGINE_ON_CMD, action) == 0) {
2469 newrule->action |= CONVRULE_ENGINE_ON_BIT;
2472 if (strcasecmp(CONVRULE_ENGINE_OFF_CMD, action) == 0) {
2473 newrule->action |= CONVRULE_ENGINE_OFF_BIT;
2476 if (strcasecmp(CONVRULE_EMOJI_ONLY_CMD, action) == 0) {
2477 newrule->action |= CONVRULE_EMOJI_ONLY_BIT;
2480 if (strcasecmp(CONVRULE_ENVINFO_ONLY_CMD, action) == 0) {
2481 newrule->action |= CONVRULE_ENVINFO_ONLY_BIT;
2487 if (strcasecmp(CONVRULE_COOKIE_ON_CMD, action) == 0) {
2488 newrule->action |= CONVRULE_COOKIE_ON_BIT;
2490 else if (strcasecmp(CONVRULE_COOKIE_OFF_CMD, action) == 0) {
2491 newrule->action &= (0xffffffff ^ CONVRULE_COOKIE_ON_BIT);
2493 else if (strcasecmp(CONVRULE_CSS_ON_CMD, action) == 0) {
2494 newrule->action |= CONVRULE_CSS_ON_BIT;
2496 else if (strcasecmp(CONVRULE_CSS_OFF_CMD, action) == 0) {
2497 newrule->action &= (0xffffffff ^ CONVRULE_CSS_ON_BIT);
2499 else if (strcasecmp(CONVRULE_COOKIE_ONLY_CMD, action) == 0) {
2500 newrule->action |= CONVRULE_COOKIE_ONLY_BIT;
2506 if (strcasecmp(CONVRULE_JRCONV_OFF_CMD, action) == 0) {
2507 newrule->action |= CONVRULE_JRCONV_OFF_BIT;
2513 if (strcasecmp(CONVRULE_NOCACHE_ON_CMD, action) == 0) {
2514 newrule->action |= CONVRULE_NOCACHE_ON_BIT;
2520 if (strcasecmp(CONVRULE_QSCONV_OFF_CMD, action) == 0) {
2521 newrule->action |= CONVRULE_QSCONV_OFF_BIT;
2527 if (strcasecmp(CONVRULE_Z2H_ON_CMD, action) == 0) {
2528 newrule->action |= CONVRULE_Z2H_ON_BIT;
2531 if (strcasecmp(CONVRULE_Z2H_OFF_CMD, action) == 0) {
2532 newrule->action |= CONVRULE_Z2H_OFF_BIT;
2535 if (strcasecmp(CONVRULE_Z2H_ALPHA_ON_CMD, action) == 0) {
2536 newrule->action |= CONVRULE_Z2H_ALPHA_ON_BIT;
2539 if (strcasecmp(CONVRULE_Z2H_ALPHA_OFF_CMD, action) == 0) {
2540 newrule->action |= CONVRULE_Z2H_ALPHA_OFF_BIT;
2543 if (strcasecmp(CONVRULE_Z2H_NUM_ON_CMD, action) == 0) {
2544 newrule->action |= CONVRULE_Z2H_NUM_ON_BIT;
2547 if (strcasecmp(CONVRULE_Z2H_NUM_OFF_CMD, action) == 0) {
2548 newrule->action |= CONVRULE_Z2H_NUM_OFF_BIT;
2551 if (strcasecmp(CONVRULE_Z2H_ALL_ON_CMD, action) == 0) {
2552 newrule->action |= CONVRULE_Z2H_ON_BIT | CONVRULE_Z2H_ALPHA_ON_BIT | CONVRULE_Z2H_NUM_ON_BIT;
2555 if (strcasecmp(CONVRULE_Z2H_NUM_OFF_CMD, action) == 0) {
2556 newrule->action |= CONVRULE_Z2H_OFF_BIT | CONVRULE_Z2H_ALPHA_OFF_BIT | CONVRULE_Z2H_NUM_OFF_BIT;
2567 newrule->flags |= CONVRULE_FLAG_NOTMATCH;
2571 mode = AP_REG_EXTENDED;
2572 if ((regexp = ap_pregcomp((apr_pool_t *)cmd->pool, (const char *)pp, mode)) == NULL)
2573 return "RewriteRule: cannot compile regular expression ";
2575 newrule->regexp = regexp;
2577 newrule->encoding = apr_pstrdup(cmd->pool, prm3);
2579 newrule->encoding = apr_pstrdup(cmd->pool, "none");
2581 newrule->pc_flag = CONVRULE_PC_FLAG_OFF_BIT;
2583 if (strcasecmp(CONVRULE_PC_FLAG_ON_CMD, prm4) == 0)
2584 newrule->pc_flag = CONVRULE_PC_FLAG_ON_BIT;
2586 newrule->user_agent = NULL;
2588 newrule->user_agent = apr_pstrdup(cmd->pool, prm5);
2600 mod_chxj_config *dconf;
2603 if (strlen(arg) > 4096)
2604 return "mod_chxj: ChxjCookieDir is too long.";
2606 dconf = (mod_chxj_config *)mconfig;
2608 dconf->cookie_db_dir = apr_pstrdup(cmd->pool, arg);
2615 cmd_set_cookie_timeout(
2616 cmd_parms *UNUSED(cmd),
2620 mod_chxj_config *dconf;
2622 if (strlen(arg) > 4096)
2623 return "mod_chxj: ChxjCookieTimeout is too long.";
2625 if (chxj_chk_numeric(arg) != 0)
2626 return "mod_chxj: ChxjCookieTimeout is not numeric.";
2628 dconf = (mod_chxj_config *)mconfig;
2630 dconf->cookie_timeout = atoi(arg);
2636 #if defined(USE_MYSQL_COOKIE)
2638 cmd_set_cookie_mysql_database(
2643 mod_chxj_config *dconf;
2645 if (strlen(arg) > 255)
2646 return "mod_chxj: ChxjCookieMysqlDatabase is too long.";
2648 dconf = (mod_chxj_config *)mconfig;
2650 dconf->mysql.database = apr_pstrdup(cmd->pool, arg);
2657 cmd_set_cookie_mysql_username(
2662 mod_chxj_config *dconf;
2664 if (strlen(arg) > 255)
2665 return "mod_chxj: ChxjCookieMysqlUsername is too long.";
2667 dconf = (mod_chxj_config *)mconfig;
2669 dconf->mysql.username = apr_pstrdup(cmd->pool, arg);
2676 cmd_set_cookie_mysql_password(
2681 mod_chxj_config *dconf;
2683 if (strlen(arg) > 255)
2684 return "mod_chxj: ChxjCookieMysqlPassword is too long.";
2686 dconf = (mod_chxj_config *)mconfig;
2688 dconf->mysql.password = apr_pstrdup(cmd->pool, arg);
2695 cmd_set_cookie_mysql_table_name(
2700 mod_chxj_config *dconf;
2702 if (strlen(arg) > 255)
2703 return "mod_chxj: ChxjCookieMysqlTableName is too long.";
2705 dconf = (mod_chxj_config *)mconfig;
2707 dconf->mysql.tablename = apr_pstrdup(cmd->pool, arg);
2713 cmd_set_cookie_mysql_port(
2714 cmd_parms *UNUSED(cmd),
2718 mod_chxj_config *dconf;
2720 if (strlen(arg) > 255)
2721 return "mod_chxj: ChxjCookieMysqlPort is too long.";
2723 dconf = (mod_chxj_config *)mconfig;
2725 if (chxj_chk_numeric(arg) != 0)
2726 return "mod_chxj: ChxjCookieMysqlPort is not numeric.";
2728 dconf = (mod_chxj_config *)mconfig;
2730 dconf->mysql.port = chxj_atoi(arg);
2737 cmd_set_cookie_mysql_host(
2742 mod_chxj_config *dconf;
2744 if (strlen(arg) > 255)
2745 return "mod_chxj: ChxjCookieMysqlHost is too long.";
2747 dconf = (mod_chxj_config *)mconfig;
2749 dconf->mysql.host = apr_pstrdup(cmd->pool, arg);
2756 cmd_set_cookie_mysql_socket_path(
2761 mod_chxj_config *dconf;
2763 if (strlen(arg) > 4096)
2764 return "mod_chxj: ChxjCookieMysqlSocketPath is too long.";
2766 dconf = (mod_chxj_config *)mconfig;
2768 dconf->mysql.socket_path = apr_pstrdup(cmd->pool, arg);
2775 cmd_set_cookie_mysql_charset(
2780 mod_chxj_config *dconf;
2782 if (strlen(arg) > 255)
2783 return "mod_chxj: ChxjCookieMysqlCharset is too long.";
2785 dconf = (mod_chxj_config *)mconfig;
2787 dconf->mysql.charset = apr_pstrdup(cmd->pool, arg);
2792 #if defined(USE_MEMCACHE_COOKIE)
2794 cmd_set_cookie_memcache_port(
2795 cmd_parms *UNUSED(cmd),
2799 mod_chxj_config *dconf;
2801 if (strlen(arg) > 255)
2802 return "mod_chxj: ChxjCookieMemcachePort is too long.";
2804 dconf = (mod_chxj_config *)mconfig;
2806 if (chxj_chk_numeric(arg) != 0)
2807 return "mod_chxj: ChxjCookieMemcachePort is not numeric.";
2809 dconf = (mod_chxj_config *)mconfig;
2811 dconf->memcache.port = (apr_port_t)chxj_atoi(arg);
2818 cmd_set_cookie_memcache_host(
2823 mod_chxj_config *dconf;
2825 if (strlen(arg) > 255)
2826 return "mod_chxj: ChxjCookieMemcacheHost is too long.";
2828 dconf = (mod_chxj_config *)mconfig;
2830 dconf->memcache.host = apr_pstrdup(cmd->pool, arg);
2837 cmd_set_cookie_lazy_mode(
2838 cmd_parms *UNUSED(cmd),
2842 mod_chxj_config *dconf;
2844 if (strlen(arg) > 255)
2845 return "mod_chxj: ChxjCookieLazyMode is too long.";
2847 dconf = (mod_chxj_config *)mconfig;
2849 if (strcasecmp("TRUE",arg) == 0) {
2850 dconf->cookie_lazy_mode = COOKIE_LAZY_ON;
2853 dconf->cookie_lazy_mode = COOKIE_LAZY_OFF;
2860 cmd_set_cookie_store_type(
2861 cmd_parms *UNUSED(cmd),
2865 mod_chxj_config *dconf;
2867 if (strlen(arg) > 255)
2868 return "mod_chxj: ChxjCookieStoreType is too long.";
2870 dconf = (mod_chxj_config *)mconfig;
2872 if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_DBM, arg) == 0) {
2873 dconf->cookie_store_type = COOKIE_STORE_TYPE_DBM;
2875 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MYSQL, arg) == 0) {
2876 dconf->cookie_store_type = COOKIE_STORE_TYPE_MYSQL;
2878 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MEMCACHE, arg) == 0) {
2879 dconf->cookie_store_type = COOKIE_STORE_TYPE_MEMCACHE;
2882 dconf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
2889 cmd_set_forward_url_base(
2894 mod_chxj_config *dconf;
2896 if (strlen(arg) > 255)
2897 return "mod_chxj: ChxjForwardUrlBase is too long.";
2899 dconf = (mod_chxj_config *)mconfig;
2901 dconf->forward_url_base = apr_pstrdup(cmd->pool, arg);
2907 cmd_set_forward_server_ip(
2912 mod_chxj_config *dconf;
2914 if (strlen(arg) > 255)
2915 return "mod_chxj: ChxjForwardServerIp is too long.";
2917 dconf = (mod_chxj_config *)mconfig;
2919 dconf->forward_server_ip = apr_pstrdup(cmd->pool, arg);
2925 cmd_allowed_cookie_domain(
2930 mod_chxj_config *dconf;
2932 if (strlen(arg) > 255)
2933 return "mod_chxj: ChxjAllowedCookieDomain is too long.";
2935 dconf = (mod_chxj_config *)mconfig;
2937 dconf->allowed_cookie_domain = apr_pstrdup(cmd->pool, arg);
2943 cmd_set_new_line_type(
2944 cmd_parms *UNUSED(cmd),
2948 mod_chxj_config *dconf;
2949 if (strlen(arg) > 255)
2950 return "mod_chxj: ChxjNewLineType is too long.";
2952 dconf = (mod_chxj_config *)mconfig;
2954 if (strcasecmp(CHXJ_NEW_LINE_TYPE_CRLF, arg) == 0) {
2955 dconf->new_line_type = NLTYPE_CRLF;
2957 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_LF, arg) == 0) {
2958 dconf->new_line_type = NLTYPE_LF;
2960 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_CR, arg) == 0) {
2961 dconf->new_line_type = NLTYPE_CR;
2963 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_NONE, arg) == 0) {
2964 dconf->new_line_type = NLTYPE_NONE;
2967 return "mod_chxj: invalid value (ChxjNewLineType)";
2978 mod_chxj_config *dconf;
2979 if (strlen(arg) > 255)
2980 return "mod_chxj: ChxjPostLogEnv is too long.";
2982 dconf = (mod_chxj_config *)mconfig;
2984 dconf->post_log = apr_pstrdup(cmd->pool, arg);
2990 cmd_cookie_dbm_type(
2995 mod_chxj_config *dconf;
2996 if (strlen(arg) > 255)
2997 return "mod_chxj: ChxjCookieDbmType is too long.";
2999 dconf = (mod_chxj_config *)mconfig;
3001 dconf->cookie_dbm_type = apr_pstrdup(cmd->pool, arg);
3007 cmd_imode_emoji_color(
3012 mod_chxj_config *dconf;
3014 if (strlen(arg) > 256)
3015 return "imode emoji color is too long.";
3017 dconf = (mod_chxj_config *)mconfig;
3018 if (strcasecmp("ON", arg) == 0) {
3019 dconf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_ON;
3021 else if(strcasecmp("AUTO",arg) == 0) {
3022 dconf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_AUTO;
3025 dconf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_OFF;
3032 cmd_add_device_data_tsv(cmd_parms *parms, void *mconfig, const char *arg)
3034 mod_chxj_config *conf;
3036 if (strlen(arg) > 256)
3037 return "mod_chxj: device tsv filename too long.";
3039 conf = (mod_chxj_config *)mconfig;
3041 conf->detect_device_type = CHXJ_ADD_DETECT_DEVICE_TYPE_TSV;
3044 apr_status_t res = apr_stat(&info,arg,APR_FINFO_TYPE,parms->pool);
3045 if(res != APR_SUCCESS){
3046 return apr_psprintf(parms->pool,"ChxjDeviceTSV [%s]: not found ",arg);
3049 if(info.filetype != APR_REG ){
3050 return apr_psprintf(parms->pool,"ChxjDeviceTSV [%s]: is not file ",arg);
3054 apr_file_open(&fp, arg, APR_READ|APR_BUFFERED, APR_OS_DEFAULT, parms->pool);
3056 chxj_load_device_tsv_data(fp,parms->pool,conf);
3062 static const command_rec cmds[] = {
3064 "ChxjLoadDeviceData",
3065 cmd_load_device_data,
3068 "Load Device Data"),
3070 "ChxjLoadEmojiData",
3071 cmd_load_emoji_data,
3077 cmd_set_image_engine,
3080 "Convert Target URI"),
3082 "ChxjImageCacheDir",
3083 cmd_set_image_cache_dir,
3086 "Image Cache Directory"),
3088 "ChxjImageCacheLimit",
3089 cmd_set_image_cache_limit,
3092 "Image Cache Limit"),
3094 "ChxjImageCopyright",
3095 cmd_set_image_copyright,
3104 "an URL-applied regexp-pattern and a substitution URL"),
3110 "save cookie.db directory."),
3112 "ChxjCookieTimeout",
3113 cmd_set_cookie_timeout,
3116 "The compulsion time-out time of the cookie is specified. "),
3118 "ChxjCookieStoreType",
3119 cmd_set_cookie_store_type,
3122 "It specifies preserving of the cookie ahead. (DBM/MYSQL/MEMCACHE)"),
3124 "ChxjCookieLazyMode",
3125 cmd_set_cookie_lazy_mode,
3128 "OneTimeID is negligently done. (TRUE/FALSE)"),
3129 #if defined(USE_MYSQL_COOKIE)
3131 "ChxjCookieMysqlHost",
3132 cmd_set_cookie_mysql_host,
3135 "The MySQL database host used by saving Cookie"),
3137 "ChxjCookieMysqlPort",
3138 cmd_set_cookie_mysql_port,
3141 "The MySQL database port used by saving Cookie"),
3143 "ChxjCookieMysqlDatabase",
3144 cmd_set_cookie_mysql_database,
3147 "The MySQL database name used by saving Cookie"),
3149 "ChxjCookieMysqlUsername",
3150 cmd_set_cookie_mysql_username,
3153 "The MySQL username used by saving Cookie"),
3155 "ChxjCookieMysqlPassword",
3156 cmd_set_cookie_mysql_password,
3159 "The MySQL password used by saving Cookie"),
3161 "ChxjCookieMysqlTableName",
3162 cmd_set_cookie_mysql_table_name,
3165 "The MySQL table name used by saving Cookie"),
3167 "ChxjCookieMysqlSocketPath",
3168 cmd_set_cookie_mysql_socket_path,
3171 "The MySQL socket path used by saving Cookie"),
3173 "ChxjCookieMysqlCharset",
3174 cmd_set_cookie_mysql_charset,
3177 "The MySQL charset used by saving Cookie"),
3179 #if defined(USE_MEMCACHE_COOKIE)
3181 "ChxjCookieMemcacheHost",
3182 cmd_set_cookie_memcache_host,
3185 "The Memcached host used by saving Cookie"),
3187 "ChxjCookieMemcachePort",
3188 cmd_set_cookie_memcache_port,
3191 "The Memcached port used by saving Cookie"),
3195 cmd_set_new_line_type,
3198 "HTML new line type (NONE|CRLF|LF|CR). default is CRLF"),
3200 "ChxjForwardUrlBase",
3201 cmd_set_forward_url_base,
3204 "The forward url base(default: {request protocol}://{this server}:{this server port}"),
3206 "ChxjForwardServerIp",
3207 cmd_set_forward_server_ip,
3210 "The forward server ip(default: this server ip)"),
3212 "ChxjAllowedCookieDomain",
3213 cmd_allowed_cookie_domain,
3216 "Domain that permits parameter addition for cookie besides hostname.(Default:hostname Only)"),
3222 "for CustomLog directive. mod_chxj's internal POST log environment name.(Default:chxj-post-log)"),
3224 "ChxjCookieDbmType",
3225 cmd_cookie_dbm_type,
3228 "Kind of DBM used with Cookie simulator.(default|GDBM|SDBM|DB|NDBM)"),
3230 "ChxjImodeEmojiColor",
3231 cmd_imode_emoji_color,
3234 "Auto i-mode emoji color"),
3236 "ChxjAddDeviceDataTSV",
3237 cmd_add_device_data_tsv,
3240 "Additional devices TSV data"),
3241 {NULL,{NULL},NULL,0,0,NULL},
3245 /*----------------------------------------------------------------------------*/
3246 /* Dispatch list for API hooks */
3247 /*----------------------------------------------------------------------------*/
3248 module AP_MODULE_DECLARE_DATA chxj_module = {
3249 STANDARD20_MODULE_STUFF,
3250 chxj_create_per_dir_config, /* create per-dir config structures */
3251 chxj_merge_per_dir_config, /* merge per-dir config structures */
3252 chxj_config_server_create, /* create per-server config structures */
3253 NULL, /* merge per-server config structures */
3254 cmds, /* table of config file commands */
3255 chxj_register_hooks /* register hooks */