2 * Copyright (C) 2005-2008 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"
38 #include "chxj_encoding.h"
39 #include "qs_ignore_sp.h"
41 #include "qs_malloc.h"
42 #include "qs_parse_attr.h"
43 #include "qs_parse_file.h"
44 #include "qs_parse_string.h"
45 #include "qs_parse_tag.h"
46 #include "chxj_load_device_data.h"
47 #include "chxj_load_emoji_data.h"
48 #include "chxj_specified_device.h"
49 #include "chxj_tag_util.h"
50 #include "chxj_xhtml_mobile_1_0.h"
51 #include "chxj_hdml.h"
52 #include "chxj_chtml10.h"
53 #include "chxj_chtml20.h"
54 #include "chxj_chtml30.h"
55 #include "chxj_chtml40.h"
56 #include "chxj_chtml50.h"
57 #include "chxj_jhtml.h"
58 #include "chxj_jxhtml.h"
59 #include "chxj_img_conv_format.h"
60 #include "chxj_qr_code.h"
61 #include "chxj_encoding.h"
62 #include "chxj_apply_convrule.h"
63 #include "chxj_cookie.h"
64 #include "chxj_url_encode.h"
65 #include "chxj_str_util.h"
66 #if defined(USE_MYSQL_COOKIE)
67 # include "chxj_mysql.h"
69 #include "chxj_serf.h"
70 #include "chxj_add_device_env.h"
71 #include "chxj_conv_z2h.h"
72 #include "chxj_header_inf.h"
75 #define CHXJ_VERSION_PREFIX PACKAGE_NAME "/"
76 #define CHXJ_VERSION PACKAGE_VERSION
77 #define CHXJ_POST_MAX (0x1000000)
79 converter_t convert_routine[] = {
81 /* CHXJ_SPEC_UNKNOWN */
86 /* CHXJ_SPEC_Chtml_1_0 */
87 .converter = chxj_convert_chtml10,
88 .encoder = chxj_encoding,
91 /* CHXJ_SPEC_Chtml_2_0 */
92 .converter = chxj_convert_chtml20,
93 .encoder = chxj_encoding,
96 /* CHXJ_SPEC_Chtml_3_0 */
97 .converter = chxj_convert_chtml30,
98 .encoder = chxj_encoding,
101 /* CHXJ_SPEC_Chtml_4_0 */
102 .converter = chxj_convert_chtml40,
103 .encoder = chxj_encoding,
106 /* CHXJ_SPEC_Chtml_5_0 */
107 .converter = chxj_convert_chtml50,
108 .encoder = chxj_encoding,
111 /* CHXJ_SPEC_Chtml_6_0 */
112 .converter = chxj_convert_chtml50,
113 .encoder = chxj_encoding,
116 /* CHXJ_SPEC_Chtml_7_0 */
117 .converter = chxj_convert_chtml50,
118 .encoder = chxj_encoding,
121 /* CHXJ_SPEC_XHtml_Mobile_1_0 */
122 .converter = chxj_convert_xhtml_mobile_1_0,
123 .encoder = chxj_encoding,
127 .converter = chxj_convert_hdml,
128 .encoder = chxj_encoding,
131 /* CHXJ_SPEC_Jhtml */
132 .converter = chxj_convert_jhtml,
133 .encoder = chxj_encoding,
136 /* CHXJ_SPEC_Jxhtml */
137 .converter = chxj_convert_jxhtml,
138 .encoder = chxj_encoding,
147 static int chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp, device_table *spec);
148 static void s_convert_guid_parameter_to_header(request_rec *r, const char *param, device_table *spec);
149 static void s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie);
150 static void s_clear_cookie_header(request_rec *r, device_table *spec);
153 * Only when User-Agent is specified, the User-Agent header is camouflaged.
158 chxj_headers_fixup(request_rec *r)
160 mod_chxj_config* dconf;
161 chxjconvrule_entry* entryp;
167 DBG(r, "REQ[%X] start chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
169 DBG(r, "REQ[%X] detect internal redirect.", (unsigned int)(apr_size_t)r);
170 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
174 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
176 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
177 spec = chxj_specified_device(r, user_agent);
179 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
181 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
182 DBG(r, "REQ[%X] detect multipart/form-data ==> no target", (unsigned int)(apr_size_t)r);
183 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
186 if (r->method_number == M_POST) {
187 if (!apr_table_get(r->headers_in, "X-Chxj-Forward")) {
188 s_clear_cookie_header(r, spec);
192 s_clear_cookie_header(r, spec);
195 switch(spec->html_spec_type) {
196 case CHXJ_SPEC_Chtml_1_0:
197 case CHXJ_SPEC_Chtml_2_0:
198 case CHXJ_SPEC_Chtml_3_0:
199 case CHXJ_SPEC_Chtml_4_0:
200 case CHXJ_SPEC_Chtml_5_0:
201 case CHXJ_SPEC_Chtml_6_0:
202 case CHXJ_SPEC_Chtml_7_0:
203 case CHXJ_SPEC_XHtml_Mobile_1_0:
205 case CHXJ_SPEC_Jhtml:
206 case CHXJ_SPEC_Jxhtml:
207 entryp = chxj_apply_convrule(r, dconf->convrules);
209 DBG(r, "REQ[%X] end chxj_headers_fixup() (no pattern)", (unsigned int)(apr_size_t)r);
212 if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
213 DBG(r, "REQ[%X] end chxj_headers_fixup() (engine off)", (unsigned int)(apr_size_t)r);
217 apr_table_setn(r->headers_in,
218 CHXJ_HTTP_USER_AGENT,
221 if (entryp->user_agent)
222 apr_table_setn(r->headers_in,
226 chxj_convert_input_header(r,entryp, spec);
231 DBG(r, "REQ[%X] end chxj_headers_fixup() (not mobile)", (unsigned int)(apr_size_t)r);
237 if (r->method_number == M_POST) {
238 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
239 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);
240 r->proxyreq = PROXYREQ_NONE;
241 r->handler = apr_psprintf(r->pool, "chxj-input-handler");
244 char *client_ip = (char *)apr_table_get(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP);
246 apr_sockaddr_t *address = NULL;
247 apr_status_t rv = apr_sockaddr_info_get(&address, ap_get_server_name(r), APR_UNSPEC, ap_get_server_port(r), 0, r->pool);
248 if (rv != APR_SUCCESS) {
250 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));
251 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
255 if (dconf->forward_server_ip) {
256 addr = dconf->forward_server_ip;
259 apr_sockaddr_ip_get(&addr, address);
261 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);
262 if (strcmp(addr, r->connection->remote_ip) == 0) {
263 r->connection->remote_ip = apr_pstrdup(r->connection->pool, client_ip);
265 if (! apr_table_get(r->headers_in, "Content-Length")) {
266 contentLength = (char *)apr_table_get(r->headers_in, "X-Chxj-Content-Length");
268 apr_table_set(r->headers_in, "Content-Length", contentLength);
275 chxj_add_device_env(r, spec);
277 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
284 s_clear_cookie_header(request_rec *r, device_table *spec)
286 switch(spec->html_spec_type) {
287 case CHXJ_SPEC_Chtml_1_0:
288 case CHXJ_SPEC_Chtml_2_0:
289 case CHXJ_SPEC_Chtml_3_0:
290 case CHXJ_SPEC_Chtml_4_0:
291 case CHXJ_SPEC_Chtml_5_0:
292 case CHXJ_SPEC_Chtml_6_0:
293 case CHXJ_SPEC_Chtml_7_0:
294 case CHXJ_SPEC_XHtml_Mobile_1_0:
295 case CHXJ_SPEC_Jhtml:
296 apr_table_unset(r->headers_in, "Cookie");
305 * It converts it from CHTML into XXML corresponding to each model.
308 * @param src [i] It is former HTML character string.
309 * @param len [i/o] It is length of former HTML character string.
312 chxj_convert(request_rec *r, const char **src, apr_size_t *len, device_table *spec, const char *ua, cookie_t **cookiep)
318 mod_chxj_config *dconf;
319 chxjconvrule_entry *entryp;
321 DBG(r,"REQ[%X] start of chxj_convert() input:[%.*s]", (unsigned int)(apr_size_t)r, (int)*len, *src);
322 dst = apr_pstrcat(r->pool, (char *)*src, NULL);
324 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
327 entryp = chxj_apply_convrule(r, dconf->convrules);
329 if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
330 DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
335 /*------------------------------------------------------------------------*/
336 /* get UserAgent from http header */
337 /*------------------------------------------------------------------------*/
338 if (entryp->user_agent)
339 user_agent = (char *)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
341 user_agent = (char *)apr_table_get(r->headers_in, HTTP_USER_AGENT);
343 DBG(r,"REQ[%X] User-Agent:[%s]", (unsigned int)(apr_size_t)r, user_agent);
344 DBG(r,"REQ[%X] content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
347 if ( ! STRNCASEEQ('t','T', "text/html", r->content_type, sizeof("text/html")-1)
348 && ! STRNCASEEQ('a','A', "application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)) {
349 DBG(r,"REQ[%X] no convert. content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
350 DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
354 if (ua && user_agent && strcasecmp(user_agent, ua) != 0) {
356 spec = chxj_specified_device(r, user_agent);
363 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
364 switch(spec->html_spec_type) {
365 case CHXJ_SPEC_Chtml_1_0:
366 case CHXJ_SPEC_Chtml_2_0:
367 case CHXJ_SPEC_Chtml_3_0:
368 case CHXJ_SPEC_Chtml_4_0:
369 case CHXJ_SPEC_Chtml_5_0:
370 case CHXJ_SPEC_Chtml_6_0:
371 case CHXJ_SPEC_Chtml_7_0:
372 case CHXJ_SPEC_XHtml_Mobile_1_0:
373 case CHXJ_SPEC_Jhtml:
374 cookie = chxj_save_cookie(r);
381 if (!r->header_only) {
384 if (convert_routine[spec->html_spec_type].encoder)
385 tmp = convert_routine[spec->html_spec_type].encoder(r,
389 if (convert_routine[spec->html_spec_type].converter) {
391 dst = convert_routine[spec->html_spec_type].converter(r,
399 dst = convert_routine[spec->html_spec_type].converter(r,
408 dst = chxj_conv_z2h(r, dst, len, entryp);
411 ap_set_content_length(r, *len);
414 dst = apr_psprintf(r->pool, "\n");
423 DBG(r, "REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
430 * convert GUID parameter.
434 s_convert_guid_parameter_to_header(request_rec *r, const char *param, device_table *spec)
436 if (strcasecmp(param, "guid") == 0) {
437 switch(spec->html_spec_type) {
438 case CHXJ_SPEC_XHtml_Mobile_1_0:
440 char *x_up_subno = (char *)apr_table_get(r->headers_in, "x-up-subno");
442 apr_table_setn(r->headers_in, "X-DCMGUID", x_up_subno);
446 case CHXJ_SPEC_Jhtml:
447 case CHXJ_SPEC_Jxhtml:
449 char *x_jphone_uid = (char *)apr_table_get(r->headers_in, "x-jphone-uid");
451 apr_table_setn(r->headers_in, "X-DCMGUID", x_jphone_uid);
462 * It converts it from HEADER.
467 chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp, device_table *spec)
479 cookie_t *cookie = NULL;
480 int no_update_flag = 0;
482 DBG(r, "REQ[%X] start chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
485 DBG(r, "REQ[%X] r->args=[null]", (unsigned int)(apr_size_t)r);
486 DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
489 urilen = strlen(r->args);
491 result = qs_alloc_zero_byte_string(r->pool);
493 buff_pre = apr_pstrdup(r->pool, r->args);
498 pair = apr_strtok(buff_pre, "&", &pstate);
504 pair_sv = apr_pstrdup(r->pool, pair);
506 name = apr_strtok(pair, "=", &vstate);
507 value = apr_strtok(NULL, "=", &vstate);
508 if (! name) continue;
509 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
510 DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
515 buff = apr_pstrdup(r->pool, r->args);
516 DBG(r, "REQ[%X] r->args=[%s]", (unsigned int)(apr_size_t)r, buff);
525 pair = apr_strtok(buff, "&", &pstate);
531 pair_sv = apr_pstrdup(r->pool, pair);
533 name = apr_strtok(pair, "=", &vstate);
534 value = apr_strtok(NULL, "=", &vstate);
535 if (! name) continue;
536 name = chxj_safe_to_jreserved_tag(r, name);
538 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
539 if (strlen(result) != 0)
540 result = apr_pstrcat(r->pool, result, "&", NULL);
542 if (strcasecmp(entryp->encoding, "NONE") != 0) {
547 if (value && *value != 0) {
548 value = chxj_url_decode(r->pool, value);
549 dlen = strlen(value);
550 DBG(r, "************ before encoding[%s]", value);
552 dvalue = chxj_rencoding(r, value, &dlen);
553 dvalue = chxj_url_encode(r->pool, dvalue);
555 DBG(r, "************ after encoding[%s]", dvalue);
561 if (name && *name != 0) {
562 name = chxj_url_decode(r->pool, name);
564 dname = chxj_rencoding(r, name, &dlen);
565 dname = chxj_url_encode(r->pool, dname);
570 s_convert_guid_parameter_to_header(r, dname, spec);
571 result = apr_pstrcat(r->pool, result, dname, "=", dvalue, NULL);
574 if (strcmp(name, pair_sv) != 0)
575 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
577 result = apr_pstrcat(r->pool, result, name, NULL);
581 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
582 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
583 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
587 if (strlen(value) == 0)
590 if (strlen(result) != 0)
591 result = apr_pstrcat(r->pool, result, "&", NULL);
593 result = apr_pstrcat(r->pool, result, &name[8], "=", value, NULL);
596 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
598 apr_table_unset(r->headers_in, "Cookie");
599 DBG(r, "REQ[%X] found cookie parameter[%s]", (unsigned int)(apr_size_t)r, value);
600 DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
601 cookie_lock_t *lock = chxj_cookie_lock(r);
602 cookie = chxj_load_cookie(r, value);
603 DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
604 if (! no_update_flag && cookie) {
605 cookie = chxj_update_cookie(r, cookie);
607 chxj_cookie_unlock(r, lock);
609 if (cookie && cookie->cookie_id) {
610 if (strlen(result) != 0)
611 result = apr_pstrcat(r->pool, result, "&", NULL);
612 result = apr_pstrcat(r->pool, result, name, "=", cookie->cookie_id, NULL);
616 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
617 if (strlen(result) != 0)
618 result = apr_pstrcat(r->pool, result, "&", NULL);
619 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
622 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
623 if (! no_update_flag) {
624 result = apr_pstrcat(r->pool, result, "&_chxj_nc=true", NULL);
628 DBG(r, "REQ[%X] result r->args=[%s]", (unsigned int)(apr_size_t)r, r->args);
629 DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
635 * It converts it from POSTDATA .
638 * @param src [i] It is POSTDATA character string.
639 * @param len [i/o] It is length of former HTML character string.
646 chxjconvrule_entry *entryp,
656 cookie_t *cookie = NULL;
658 int no_update_flag = 0;
663 DBG(r, "REQ[%X] start of chxj_input_convert()", (unsigned int)(apr_size_t)r);
666 DBG(r, "REQ[%X] end of chxj_input_convert() (input is null)", (unsigned int)(apr_size_t)r);
667 return apr_pstrdup(r->pool, "");
670 apr_pool_create(&pool, r->pool);
672 s = apr_pstrdup(pool, *src);
674 buff_pre = apr_pstrdup(pool, *src);
676 result = qs_alloc_zero_byte_string(pool);
678 DBG(r, "REQ[%X] +-------------------------------------------------------------------+", (unsigned int)(apr_size_t)r);
679 DBG(r, "REQ[%X] | BEFORE input convert source |", (unsigned int)(apr_size_t)r);
680 DBG(r, "REQ[%X] +-------------------------------------------------------------------+", (unsigned int)(apr_size_t)r);
681 for (ii=0; ii<ilen-64; ii+=64) {
682 DBG(r, "REQ[%X] | [%-*.*s] |", (unsigned int)(apr_size_t)r, 64, 64, &s[ii]);
687 if (ilen >= 64 && ((ilen-64) % 64 != 0)) {
688 DBG(r, "REQ[%X] | [%-*.*s] |", (unsigned int)(apr_size_t)r, 64, 64, &s[ii]);
690 DBG(r, "REQ[%X] +--------------------------------------------------------------------+", (unsigned int)(apr_size_t)r);
695 pair = apr_strtok(buff_pre, "&", &pstate);
701 pair_sv = apr_pstrdup(pool, pair);
703 name = apr_strtok(pair, "=", &vstate);
704 value = apr_strtok(NULL, "=", &vstate);
705 if (! name) continue;
706 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
707 DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
717 pair = apr_strtok(s, "&", &pstate);
722 name = apr_strtok(pair, "=", &vstate);
723 value = apr_strtok(NULL, "=", &vstate);
724 if (! name) continue;
725 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
726 if (strlen(result) != 0)
727 result = apr_pstrcat(pool, result, "&", NULL);
729 if (strcasecmp(entryp->encoding, "NONE") != 0) {
734 if (value && *value != 0) {
735 value = chxj_url_decode(pool, value);
736 dlen = strlen(value);
737 dvalue = chxj_rencoding(r, value, &dlen);
738 dvalue = chxj_url_encode(pool, dvalue);
744 if (name && *name != 0) {
745 name = chxj_url_decode(pool, name);
747 dname = chxj_rencoding(r, name, &dlen);
748 dname = chxj_url_encode(pool, dname);
755 result = apr_pstrcat(pool, result, dname, "=", dvalue, NULL);
758 result = apr_pstrcat(pool, result, name, "=", value, NULL);
762 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
763 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
764 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
768 if (strlen(value) == 0)
771 if (strlen(result) != 0)
772 result = apr_pstrcat(pool, result, "&", NULL);
774 if (strcasecmp(entryp->encoding, "NONE") != 0 && value && strlen(value)) {
778 dlen = strlen(value);
779 value = chxj_url_decode(pool, value);
780 dvalue = chxj_rencoding(r, value, &dlen);
781 dvalue = chxj_url_encode(pool,dvalue);
782 result = apr_pstrcat(pool, result, &name[8], "=", dvalue, NULL);
786 result = apr_pstrcat(pool, result, &name[8], "=", value, NULL);
790 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
792 apr_table_unset(r->headers_in, "Cookie");
793 DBG(r, "REQ[%X] found cookie parameter[%s]", (unsigned int)(apr_size_t)r, value);
794 DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
795 cookie_lock_t *lock = chxj_cookie_lock(r);
796 cookie = chxj_load_cookie(r, value);
797 DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
798 if (! no_update_flag && cookie) {
799 cookie = chxj_update_cookie(r, cookie);
801 chxj_cookie_unlock(r, lock);
803 if (cookie && cookie->cookie_id) {
804 if (strlen(result) != 0)
805 result = apr_pstrcat(pool, result, "&", NULL);
806 result = apr_pstrcat(pool, result, name, "=", cookie->cookie_id, NULL);
810 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
811 if (strlen(result) != 0)
812 result = apr_pstrcat(pool, result, "&", NULL);
813 result = apr_pstrcat(pool, result, name, "=", value, NULL);
816 if ( strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1) == 0) {
819 dlen = strlen(value);
821 value = chxj_url_decode(pool, value);
822 dvalue = chxj_rencoding(r, value, &dlen);
823 dvalue = chxj_url_encode(pool,dvalue);
824 if (r->args && strlen(r->args) > 0) {
825 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
828 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
830 s_convert_guid_parameter_to_header(r, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], spec);
834 if (strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX_ENC, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1) == 0) {
837 dlen = strlen(value);
839 value = chxj_url_decode(pool, value);
840 dvalue = chxj_rencoding(r, value, &dlen);
841 dvalue = chxj_url_encode(pool,dvalue);
842 if (r->args && strlen(r->args) > 0) {
843 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
846 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
848 s_convert_guid_parameter_to_header(r, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], spec);
851 DBG(r, "REQ[%X] ************************ name:[%s]", (unsigned int)(apr_size_t)r, name);
853 *len = strlen(result);
854 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
855 if (! no_update_flag) {
856 result = apr_pstrcat(pool, result, "&_chxj_nc=true", NULL);
859 DBG(r, "REQ[%X] AFTER input convert result = [%s]", (unsigned int)(apr_size_t)r, result);
860 DBG(r, "REQ[%X] end chxj_input_convert()", (unsigned int)(apr_size_t)r);
867 * The received data is returned to the filter.
869 * @param f [i/o] It is a filter.
870 * @param data [i] It is data returned to the filter.
871 * @param len [i] It is length of the data returned to the filter.
874 pass_data_to_filter(ap_filter_t *f, const char *data,
877 request_rec *r = f->r;
878 conn_rec *c = r->connection;
880 apr_bucket_brigade *bb;
883 DBG(r, "REQ[%X] start pass_data_to_filter()", (unsigned int)(apr_size_t)r);
885 chxj_header_inf_clear(r);
887 bb = apr_brigade_create(r->pool, c->bucket_alloc);
888 b = apr_bucket_transient_create(data, len, c->bucket_alloc);
890 APR_BRIGADE_INSERT_TAIL(bb, b);
891 b = apr_bucket_eos_create(f->c->bucket_alloc);
892 APR_BRIGADE_INSERT_TAIL(bb, b);
894 rv = ap_pass_brigade(f->next, bb);
895 if (rv != APR_SUCCESS) {
896 DBG(r, "REQ[%X] end pass_data_to_filter() (apr_pass_brigade)", (unsigned int)(apr_size_t)r);
900 DBG(r, "REQ[%X] end pass_data_to_filter()", (unsigned int)(apr_size_t)r);
907 * It is the main loop of the output filter.
909 * @param f [i/o] It is a filter.
913 chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
919 char *user_agent = NULL;
921 mod_chxj_ctx *ctx = (mod_chxj_ctx *)f->ctx;
922 cookie_t *cookie = NULL;
923 mod_chxj_config *dconf;
924 chxjconvrule_entry *entryp = NULL;
925 device_table *spec = NULL;
929 DBG(f->r, "REQ[%X] start of chxj_output_filter()", (unsigned int)(apr_size_t)r);
932 apr_pool_create(&pool, r->pool);
934 entryp = ctx->entryp;
936 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
938 if (r->content_type) {
939 if (! STRNCASEEQ('t','T',"text/html",r->content_type, sizeof("text/html")-1)
940 && ! STRNCASEEQ('t','T',"text/xml", r->content_type, sizeof("text/xml")-1)
941 && ! STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
942 && ! (dconf->image == CHXJ_IMG_ON
943 && ! apr_table_get(r->headers_in, "CHXJ_IMG_CONV")
944 && STRNCASEEQ('i','I',"image/", r->content_type, sizeof("image/") -1)
945 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
946 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
947 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
948 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
949 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
950 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
951 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
952 || STRCASEEQ('g','G',"gif", &r->content_type[6])))) { /* GIF */
954 DBG(r, "REQ[%X] not convert content-type:[%s] dconf->image:[%d]", (unsigned int)(apr_size_t)r, r->content_type, dconf->image);
955 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
956 cookie_lock_t *lock = NULL;
957 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
958 switch(spec->html_spec_type) {
959 case CHXJ_SPEC_Chtml_1_0:
960 case CHXJ_SPEC_Chtml_2_0:
961 case CHXJ_SPEC_Chtml_3_0:
962 case CHXJ_SPEC_Chtml_4_0:
963 case CHXJ_SPEC_Chtml_5_0:
964 case CHXJ_SPEC_Chtml_6_0:
965 case CHXJ_SPEC_Chtml_7_0:
966 case CHXJ_SPEC_XHtml_Mobile_1_0:
967 case CHXJ_SPEC_Jhtml:
968 lock = chxj_cookie_lock(r);
969 cookie = chxj_save_cookie(r);
970 s_add_cookie_id_if_has_location_header(r, cookie);
971 chxj_cookie_unlock(r, lock);
977 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
978 if (! ap_is_HTTP_REDIRECT(r->status)) {
979 r->status = HTTP_MOVED_TEMPORARILY;
982 ap_pass_brigade(f->next, bb);
983 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
988 DBG(r, "REQ[%X] not convert content-type:[(null)]", (unsigned int)(apr_size_t)r);
989 ap_pass_brigade(f->next, bb);
990 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
995 for (b = APR_BRIGADE_FIRST(bb);
996 b != APR_BRIGADE_SENTINEL(bb);
997 b = APR_BUCKET_NEXT(b)) {
999 if (apr_bucket_read(b, &data, &len, APR_BLOCK_READ) == APR_SUCCESS) {
1000 DBG(r, "REQ[%X] read data[%.*s]",(unsigned int)(apr_size_t)r, (int)len, data);
1002 /*--------------------------------------------------------------------*/
1004 /*--------------------------------------------------------------------*/
1006 DBG(r, "append data start");
1007 ctx = (mod_chxj_ctx *)f->ctx;
1010 tmp = apr_palloc(r->pool, ctx->len);
1011 memcpy(tmp, ctx->buffer, ctx->len);
1013 ctx->buffer = apr_palloc(pool, ctx->len + len);
1015 memcpy(ctx->buffer, tmp, ctx->len);
1016 memcpy(&ctx->buffer[ctx->len], data, len);
1020 DBG(r, "REQ[%X] append data end", (unsigned int)(apr_size_t)r);
1023 if (APR_BUCKET_IS_EOS(b)) {
1025 DBG(r, "REQ[%X] eos", (unsigned int)(apr_size_t)r);
1026 /*----------------------------------------------------------------------*/
1028 /*----------------------------------------------------------------------*/
1030 cookie_lock_t *lock = NULL;
1031 ctx = (mod_chxj_ctx *)f->ctx;
1033 DBG(r, "REQ[%X] content_type=[%s]", (unsigned int)(apr_size_t)r, r->content_type);
1034 lock = chxj_cookie_lock(r);
1036 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
1038 && (STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
1039 || STRNCASEEQ('t','T',"text/html", r->content_type, sizeof("text/html")-1))) {
1040 DBG(r, "REQ[%X] detect convert target:[%s]", (unsigned int)(apr_size_t)r, r->content_type);
1045 tmp = apr_palloc(pool, ctx->len + 1);
1047 memset(tmp, 0, ctx->len + 1);
1048 memcpy(tmp, ctx->buffer, ctx->len);
1050 ctx->buffer = chxj_convert(r,
1051 (const char **)&tmp,
1052 (apr_size_t *)&ctx->len,
1054 user_agent, &cookie);
1058 ctx->buffer = apr_psprintf(r->pool, "\n");
1060 ctx->buffer = chxj_convert(r,
1061 (const char **)&ctx->buffer,
1062 (apr_size_t *)&ctx->len,
1064 user_agent, &cookie);
1069 && *(char *)r->content_type == 't'
1070 && strncmp(r->content_type, "text/xml", 8) == 0) {
1071 DBG(r, "REQ[%X] text/XML", (unsigned int)(apr_size_t)r);
1079 memset(&doc, 0, sizeof(Doc));
1080 memset(&qrcode, 0, sizeof(qr_code_t));
1082 doc.parse_mode = PARSE_MODE_CHTML;
1086 qs_init_malloc(&doc);
1088 root = qs_parse_string(&doc, ctx->buffer, ctx->len);
1091 for (child = qs_get_child_node(&doc,root);
1093 child = qs_get_next_node(&doc,child)) {
1094 char *name = qs_get_node_name(&doc,child);
1095 if (strcasecmp("qrcode",name) == 0) {
1100 qs_all_free(&doc,QX_LOGMARK);
1102 r->handler = apr_psprintf(r->pool, "chxj-qrcode");
1103 chxj_qrcode_node_to_qrcode(&qrcode, root);
1104 sts = chxj_qrcode_create_image_data(&qrcode, &ctx->buffer, &ctx->len);
1106 ERR(r, "REQ[%X] qrcode create failed.", (unsigned int)(apr_size_t)r);
1107 chxj_cookie_unlock(r, lock);
1108 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1111 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1115 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
1117 && ( *r->content_type == 'i' || *r->content_type == 'I')
1118 && dconf->image == CHXJ_IMG_ON
1119 && strncasecmp("image/", r->content_type, 6) == 0
1120 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
1121 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
1122 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
1123 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
1124 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
1125 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
1126 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
1127 || STRCASEEQ('g','G',"gif", &r->content_type[6]))) { /* GIF */
1131 tmp = apr_palloc(pool, ctx->len + 1);
1133 memset(tmp, 0, ctx->len + 1);
1134 memcpy(tmp, ctx->buffer, ctx->len);
1136 chxj_convert_image(r,
1137 (const char **)&tmp,
1138 (apr_size_t *)&ctx->len);
1139 if (ctx->buffer == NULL) {
1145 apr_table_unset(r->headers_out, "Content-Length");
1146 apr_table_unset(r->err_headers_out, "Content-Length");
1147 ap_set_content_length(r, (apr_off_t)ctx->len);
1151 DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1152 s_add_cookie_id_if_has_location_header(r, cookie);
1153 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1154 if (! ap_is_HTTP_REDIRECT(r->status)) {
1155 r->status = HTTP_MOVED_TEMPORARILY;
1158 chxj_cookie_unlock(r,lock);
1159 rv = pass_data_to_filter(f,
1160 (const char *)ctx->buffer,
1161 (apr_size_t)ctx->len);
1164 chxj_cookie_unlock(r, lock);
1167 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1171 DBG(r, "REQ[%X] SAVE COOKIE[%x]", (unsigned int)(apr_size_t)r, entryp->action);
1176 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
1177 cookie_lock_t *lock = NULL;
1178 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
1179 switch(spec->html_spec_type) {
1180 case CHXJ_SPEC_Chtml_1_0:
1181 case CHXJ_SPEC_Chtml_2_0:
1182 case CHXJ_SPEC_Chtml_3_0:
1183 case CHXJ_SPEC_Chtml_4_0:
1184 case CHXJ_SPEC_Chtml_5_0:
1185 case CHXJ_SPEC_Chtml_6_0:
1186 case CHXJ_SPEC_Chtml_7_0:
1187 case CHXJ_SPEC_XHtml_Mobile_1_0:
1188 case CHXJ_SPEC_Jhtml:
1189 lock = chxj_cookie_lock(r);
1190 cookie = chxj_save_cookie(r);
1192 * Location Header Check to add cookie parameter.
1194 s_add_cookie_id_if_has_location_header(r, cookie);
1195 chxj_cookie_unlock(r, lock);
1196 apr_table_unset(r->headers_out, "Set-Cookie");
1197 apr_table_unset(r->err_headers_out, "Set-Cookie");
1204 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1205 if (! ap_is_HTTP_REDIRECT(r->status)) {
1206 r->status = HTTP_MOVED_TEMPORARILY;
1209 apr_table_setn(r->headers_out, "Content-Length", "0");
1210 DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1211 rv = pass_data_to_filter(f, (const char *)"", (apr_size_t)0);
1212 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1217 apr_brigade_destroy(bb);
1219 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1225 * Add Cookie_id if it has location header.
1228 s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie)
1230 char *location_header = (char *)apr_table_get(r->headers_out, "Location");
1231 if (! location_header) {
1232 location_header = (char *)apr_table_get(r->err_headers_out, "Location");
1234 if (cookie && location_header) {
1235 DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1236 location_header = chxj_add_cookie_parameter(r,
1239 apr_table_unset(r->headers_out, "Location");
1240 apr_table_setn(r->headers_out, "Location", location_header);
1241 DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1242 if (!ap_is_HTTP_REDIRECT(r->status)) {
1243 r->status = HTTP_MOVED_TEMPORARILY;
1249 * It is the main loop of the input filter handler.
1253 chxj_input_handler(request_rec *r)
1255 mod_chxj_config *dconf;
1256 chxjconvrule_entry *entryp = NULL;
1257 device_table *spec = NULL;
1258 char *post_data = NULL;
1259 apr_size_t post_data_len = 0;
1264 int response_code = 0;
1266 DBG(r, "start of chxj_input_handler()");
1268 if (strcasecmp(r->handler, "chxj-input-handler")) {
1269 DBG(r, "end chxj_input_handler()");
1272 apr_pool_create(&pool, r->pool);
1274 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1275 user_agent = (char*)apr_table_get(r->headers_in, "User-Agent");
1276 spec = chxj_specified_device(r, user_agent);
1277 entryp = chxj_apply_convrule(r, dconf->convrules);
1279 post_data = apr_pstrdup(pool, "");
1280 if (ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK) == OK) {
1281 if (ap_should_client_block(r)) {
1282 while (post_data_len < CHXJ_POST_MAX) {
1285 int read_bytes = ap_get_client_block(r, buffer, BUFSZ-1);
1286 if (read_bytes<=0) {
1289 buffer[read_bytes] = '\0';
1290 post_data = apr_pstrcat(pool, post_data, buffer, NULL);
1291 post_data_len += read_bytes;
1300 if (post_data_len > 0) {
1301 post_data = chxj_input_convert(r, (const char**)&post_data, (apr_size_t*)&post_data_len, entryp, spec);
1302 DBG(r, "(in:exchange)POSTDATA:[%s]", post_data);
1306 if (dconf->forward_url_base) {
1307 url_path = apr_psprintf(pool, "%s%s", dconf->forward_url_base, r->uri);
1310 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);
1313 url_path = apr_pstrcat(pool, url_path, "?", r->args, NULL);
1315 DBG(r, "==> new url_path:[%s]", url_path);
1318 apr_table_setn(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP, r->connection->remote_ip);
1319 apr_table_unset(r->headers_in, "Content-Length");
1320 apr_table_setn(r->headers_in, "Content-Length", apr_psprintf(pool, "%" APR_SIZE_T_FMT, post_data_len));
1321 response = chxj_serf_post(r, pool, url_path, post_data, post_data_len, 1, &res_len, &response_code);
1322 DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1323 DBG(r, "REQ[%X] response length:[%" APR_SIZE_T_FMT "]", (unsigned int)(apr_size_t)r, res_len);
1324 for (ii=0; ii<res_len/64; ii++) {
1325 DBG(r, "REQ[%X] response:[%.*s]", (unsigned int)(apr_size_t)r, 64, &response[ii*64]);
1327 DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1330 if ((chunked = (char *)apr_table_get(r->headers_out, "Transfer-Encoding")) != NULL) {
1331 if (strcasecmp(chunked, "chunked") == 0) {
1333 apr_table_unset(r->headers_out, "Transfer-Encoding");
1336 if (ap_is_HTTP_ERROR(response_code)) {
1337 DBG(r, "REQ[%X] end of chxj_input_handler() (HTTP-ERROR received. response code:[%d])", (unsigned int)(apr_size_t)r, response_code);
1338 return response_code;
1342 apr_pool_create(&wpool, r->pool);
1343 apr_bucket_brigade *bb;
1346 conn_rec *c = r->connection;
1348 bb = apr_brigade_create(wpool, c->bucket_alloc);
1349 e = apr_bucket_transient_create(response, res_len, c->bucket_alloc);
1350 APR_BRIGADE_INSERT_TAIL(bb, e);
1351 e = apr_bucket_eos_create(c->bucket_alloc);
1352 APR_BRIGADE_INSERT_TAIL(bb, e);
1353 if ((rv = ap_pass_brigade(r->output_filters, bb)) != APR_SUCCESS) {
1354 ERR(r, "REQ[%X] %s:%d failed ap_pass_brigade()", (unsigned int)(apr_size_t)r, APLOG_MARK);
1357 apr_brigade_cleanup(bb);
1360 DBG(r, "REQ[%X] end of chxj_input_handler()", (unsigned int)(apr_size_t)r);
1364 static mod_chxj_global_config *
1365 chxj_global_config_create(apr_pool_t *pool, server_rec *s)
1367 mod_chxj_global_config *conf;
1369 SDBG(s, "start chxj_global_config_create()");
1371 /*--------------------------------------------------------------------------*/
1372 /* allocate an own subpool which survives server restarts */
1373 /*--------------------------------------------------------------------------*/
1374 conf = (mod_chxj_global_config *)apr_palloc(pool,
1375 sizeof(mod_chxj_global_config));
1377 conf->cookie_db_lock = NULL;
1379 SDBG(s, "end chxj_global_config_create()");
1386 * initialize chxj module
1389 chxj_init_module(apr_pool_t *p,
1390 apr_pool_t *UNUSED(plog),
1391 apr_pool_t *UNUSED(ptemp),
1397 SDBG(s, "start chxj_init_module()");
1399 apr_pool_userdata_get(&user_data, CHXJ_MOD_CONFIG_KEY, s->process->pool);
1401 if (user_data == NULL) {
1404 * dummy user_data set.
1406 apr_pool_userdata_set(
1408 CHXJ_MOD_CONFIG_KEY,
1409 apr_pool_cleanup_null,
1411 SDBG(s, "end chxj_init_module()");
1415 ap_add_version_component(p, CHXJ_VERSION_PREFIX CHXJ_VERSION);
1417 if ((rv = apr_proc_mutex_create(&global_cookie_mutex, NULL, APR_LOCK_FCNTL, s->process->pool)) != APR_SUCCESS) {
1419 SERR(s, "%s:%d end chxj_init_module(). mutex create failure.(%d:%s)",APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1420 return HTTP_INTERNAL_SERVER_ERROR;
1423 SDBG(s, "end chxj_init_module()");
1430 chxj_child_init(apr_pool_t *UNUSED(p), server_rec *s)
1433 SDBG(s, "start chxj_child_init()");
1434 if ((rv = apr_proc_mutex_child_init(&global_cookie_mutex, NULL, s->process->pool)) != APR_SUCCESS) {
1436 SERR(s, "%s:%d ERROR end chxj_init_module(). mutex create failure.(%d:%s)", APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1438 SDBG(s, "end chxj_child_init()");
1443 * A set structure of each server is generated.
1449 chxj_config_server_create(apr_pool_t *p, server_rec *s)
1451 mod_chxj_global_config *gc;
1453 gc = chxj_global_config_create(p,s);
1460 chxj_translate_name(request_rec *r)
1462 DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1463 DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1464 DBG(r, "REQ[%X] START REQUEST (uri:[%s] args:[%s])", (unsigned int)(apr_size_t)r, r->unparsed_uri, r->args ? r->args : "");
1465 DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1466 DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1467 return chxj_trans_name(r);
1472 chxj_insert_filter(request_rec *r)
1476 mod_chxj_config *dconf;
1477 chxjconvrule_entry *entryp;
1482 DBG(r, "start chxj_insert_filter()");
1484 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1486 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
1488 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
1490 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
1491 DBG(r, "detect multipart/form-data ==> no target");
1495 spec = chxj_specified_device(r, user_agent);
1496 entryp = chxj_apply_convrule(r, dconf->convrules);
1498 DBG(r, "end chxj_insert_filter()");
1501 ctx = apr_palloc(r->pool, sizeof(*ctx));
1502 memset(ctx, 0, sizeof(*ctx));
1503 if ((rv = apr_pool_create(&ctx->pool, r->pool)) != APR_SUCCESS) {
1504 ERR(r, "failed: new pool create. rv:[%d]", rv);
1507 ctx->entryp = entryp;
1509 ctx->buffer = apr_palloc(ctx->pool, 1);
1512 if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
1517 switch(spec->html_spec_type) {
1518 case CHXJ_SPEC_Chtml_1_0:
1519 case CHXJ_SPEC_Chtml_2_0:
1520 case CHXJ_SPEC_Chtml_3_0:
1521 case CHXJ_SPEC_Chtml_4_0:
1522 case CHXJ_SPEC_Chtml_5_0:
1523 case CHXJ_SPEC_Chtml_6_0:
1524 case CHXJ_SPEC_Chtml_7_0:
1525 case CHXJ_SPEC_XHtml_Mobile_1_0:
1526 case CHXJ_SPEC_Hdml:
1527 case CHXJ_SPEC_Jhtml:
1528 case CHXJ_SPEC_Jxhtml:
1536 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
1537 ap_add_output_filter("chxj_output_filter", ctx, r, r->connection);
1538 DBG(r, "added Output Filter");
1541 DBG(r, "end chxj_insert_filter()");
1546 * The hook is registered.
1551 chxj_register_hooks(apr_pool_t *UNUSED(p))
1553 ap_hook_post_config(chxj_init_module,
1556 APR_HOOK_REALLY_FIRST);
1557 ap_hook_child_init(chxj_child_init,
1560 APR_HOOK_REALLY_FIRST);
1561 ap_register_output_filter (
1562 "chxj_output_filter",
1566 ap_hook_insert_filter(chxj_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
1567 ap_hook_handler(chxj_img_conv_format_handler, NULL, NULL, APR_HOOK_MIDDLE);
1568 ap_hook_handler(chxj_qr_code_handler, NULL, NULL, APR_HOOK_MIDDLE);
1569 ap_hook_handler(chxj_input_handler, NULL, NULL, APR_HOOK_MIDDLE);
1570 ap_hook_translate_name(chxj_translate_name, NULL, NULL, APR_HOOK_MIDDLE);
1571 ap_hook_fixups(chxj_headers_fixup, NULL, NULL, APR_HOOK_FIRST);
1576 * A set structure according to the directory is generated.
1582 chxj_create_per_dir_config(apr_pool_t *p, char *arg)
1584 mod_chxj_config *conf;
1586 conf = apr_pcalloc(p, sizeof(mod_chxj_config));
1587 conf->device_data_file = NULL;
1588 conf->devices = NULL;
1589 conf->emoji_data_file = NULL;
1591 conf->emoji_tail = NULL;
1592 conf->image = CHXJ_IMG_NONE;
1593 conf->image_cache_dir = apr_psprintf(p, "%s",DEFAULT_IMAGE_CACHE_DIR);
1594 conf->image_cache_limit = 0;
1595 conf->server_side_encoding = NULL;
1596 conf->cookie_db_dir = NULL;
1597 conf->cookie_timeout = 0;
1598 conf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
1599 conf->cookie_lazy_mode = 0;
1600 #if defined(USE_MYSQL_COOKIE)
1601 memset((void *)&conf->mysql, 0, sizeof(mysql_t));
1602 conf->mysql.port = MYSQL_PORT;
1603 conf->mysql.host = NULL;
1605 #if defined(USE_MEMCACHE_COOKIE)
1606 memset((void *)&conf->memcache, 0, sizeof(memcache_t));
1607 conf->memcache.host = NULL;
1608 conf->memcache.port = 0;
1610 conf->forward_url_base = NULL;
1611 conf->forward_server_ip = NULL;
1617 conf->dir = apr_pcalloc(p, strlen(arg)+1);
1618 memset(conf->dir, 0, strlen(arg)+1);
1619 strcpy(conf->dir, arg);
1621 conf->convrules = apr_array_make(p, 2, sizeof(chxjconvrule_entry));
1623 /* Default is copyleft */
1624 conf->image_copyright = NULL;
1631 * Merge per-directory CHXJ configurations
1634 chxj_merge_per_dir_config(apr_pool_t *p, void *basev, void *addv)
1636 mod_chxj_config *base;
1637 mod_chxj_config *add;
1638 mod_chxj_config *mrg;
1640 base = (mod_chxj_config *)basev;
1641 add = (mod_chxj_config *)addv;
1642 mrg = (mod_chxj_config *)apr_palloc(p, sizeof(mod_chxj_config));
1644 mrg->device_data_file = NULL;
1645 mrg->devices = NULL;
1646 mrg->emoji_data_file = NULL;
1647 mrg->image = CHXJ_IMG_NONE;
1648 mrg->image_cache_dir = NULL;
1649 mrg->image_copyright = NULL;
1650 mrg->image_cache_limit = 0;
1652 mrg->emoji_tail = NULL;
1653 mrg->new_line_type = NLTYPE_NIL;
1654 mrg->forward_url_base = NULL;
1655 mrg->forward_server_ip = NULL;
1657 mrg->dir = apr_pstrdup(p, add->dir);
1659 if (! add->device_data_file) {
1660 mrg->devices = base->devices;
1661 mrg->device_data_file = apr_pstrdup(p, base->device_data_file);
1664 mrg->devices = add->devices;
1665 mrg->device_data_file = apr_pstrdup(p, add->device_data_file);
1668 if (! add->emoji_data_file) {
1669 mrg->emoji = base->emoji;
1670 mrg->emoji_tail = base->emoji_tail;
1671 mrg->emoji_data_file = apr_pstrdup(p, base->emoji_data_file);
1674 mrg->emoji = add->emoji;
1675 mrg->emoji_tail = add->emoji_tail;
1676 mrg->emoji_data_file = apr_pstrdup(p, add->emoji_data_file);
1679 if (add->image == CHXJ_IMG_NONE) {
1680 mrg->image = base->image;
1683 mrg->image = add->image;
1686 if (strcasecmp(add->image_cache_dir ,DEFAULT_IMAGE_CACHE_DIR)==0) {
1687 mrg->image_cache_dir = apr_pstrdup(p, base->image_cache_dir);
1690 mrg->image_cache_dir = apr_pstrdup(p, add->image_cache_dir);
1693 if (add->image_cache_limit) {
1694 mrg->image_cache_limit = add->image_cache_limit;
1697 mrg->image_cache_limit = base->image_cache_limit;
1700 if (add->image_copyright)
1701 mrg->image_copyright = apr_pstrdup(p, add->image_copyright);
1703 mrg->image_copyright = apr_pstrdup(p, base->image_copyright);
1705 if (add->server_side_encoding) {
1706 mrg->server_side_encoding = apr_pstrdup(p, add->server_side_encoding);
1709 if (base->server_side_encoding) {
1710 mrg->server_side_encoding = apr_pstrdup(p, base->server_side_encoding);
1713 mrg->server_side_encoding = apr_pstrdup(p, DEFAULT_SERVER_SIDE_ENCODING);
1716 mrg->convrules = apr_array_append(p, add->convrules, base->convrules);
1718 if (add->cookie_db_dir) {
1719 mrg->cookie_db_dir = apr_pstrdup(p, add->cookie_db_dir);
1722 if (base->cookie_db_dir) {
1723 mrg->cookie_db_dir = apr_pstrdup(p, base->cookie_db_dir);
1726 mrg->cookie_db_dir = NULL;
1729 if (add->cookie_timeout) {
1730 mrg->cookie_timeout = add->cookie_timeout;
1733 if (base->cookie_db_dir) {
1734 mrg->cookie_timeout = base->cookie_timeout;
1737 mrg->cookie_timeout = 0;
1740 #if defined(USE_MYSQL_COOKIE)
1741 if (add->mysql.host) {
1742 mrg->mysql.host = apr_pstrdup(p, add->mysql.host);
1744 else if (base->mysql.host) {
1745 mrg->mysql.host = apr_pstrdup(p, base->mysql.host);
1748 mrg->mysql.host = NULL;
1750 if (add->mysql.port) {
1751 mrg->mysql.port = add->mysql.port;
1753 else if (base->mysql.port) {
1754 mrg->mysql.port = base->mysql.port;
1757 mrg->mysql.port = 0;
1760 if (add->mysql.database) {
1761 mrg->mysql.database = apr_pstrdup(p, add->mysql.database);
1763 else if (base->mysql.database) {
1764 mrg->mysql.database = apr_pstrdup(p, base->mysql.database);
1767 mrg->mysql.database = NULL;
1770 if (add->mysql.username) {
1771 mrg->mysql.username = apr_pstrdup(p, add->mysql.username);
1773 else if (base->mysql.username) {
1774 mrg->mysql.username = apr_pstrdup(p, base->mysql.username);
1777 mrg->mysql.username = NULL;
1780 if (add->mysql.password) {
1781 mrg->mysql.password = apr_pstrdup(p, add->mysql.password);
1783 else if (base->mysql.password) {
1784 mrg->mysql.password = apr_pstrdup(p, base->mysql.password);
1787 mrg->mysql.password = NULL;
1790 if (add->mysql.tablename) {
1791 mrg->mysql.tablename = apr_pstrdup(p, add->mysql.tablename);
1793 else if (base->mysql.tablename) {
1794 mrg->mysql.tablename = apr_pstrdup(p, base->mysql.tablename);
1797 mrg->mysql.tablename = NULL;
1800 if (add->mysql.socket_path) {
1801 mrg->mysql.socket_path = apr_pstrdup(p, add->mysql.socket_path);
1803 else if (base->mysql.socket_path) {
1804 mrg->mysql.socket_path = apr_pstrdup(p, base->mysql.socket_path);
1807 mrg->mysql.socket_path = NULL;
1810 if (add->mysql.charset) {
1811 mrg->mysql.charset = apr_pstrdup(p, add->mysql.charset);
1813 else if (base->mysql.charset) {
1814 mrg->mysql.charset = apr_pstrdup(p, base->mysql.charset);
1817 mrg->mysql.charset = NULL;
1820 #if defined(USE_MEMCACHE_COOKIE)
1821 if (add->memcache.host) {
1822 mrg->memcache.host = apr_pstrdup(p, add->memcache.host);
1824 else if (base->memcache.host) {
1825 mrg->memcache.host = apr_pstrdup(p, base->memcache.host);
1828 mrg->memcache.host = NULL;
1830 if (add->memcache.port) {
1831 mrg->memcache.port = add->memcache.port;
1833 else if (base->memcache.port) {
1834 mrg->memcache.port = base->memcache.port;
1837 mrg->memcache.port = 0;
1840 if (add->cookie_store_type) {
1841 mrg->cookie_store_type = add->cookie_store_type;
1843 else if (base->cookie_store_type) {
1844 mrg->cookie_store_type = base->cookie_store_type;
1847 mrg->cookie_store_type = COOKIE_STORE_TYPE_NONE;
1849 if (add->cookie_lazy_mode) {
1850 mrg->cookie_lazy_mode = add->cookie_lazy_mode;
1852 else if (base->cookie_lazy_mode) {
1853 mrg->cookie_lazy_mode = base->cookie_lazy_mode;
1856 mrg->cookie_lazy_mode = 0;
1858 if (add->new_line_type) {
1859 mrg->new_line_type = add->new_line_type;
1861 else if (base->new_line_type) {
1862 mrg->new_line_type = base->new_line_type;
1865 mrg->new_line_type = NLTYPE_NIL;
1868 if (add->forward_url_base) {
1869 mrg->forward_url_base = add->forward_url_base;
1871 else if (base->forward_url_base) {
1872 mrg->forward_url_base = base->forward_url_base;
1879 chxj_command_parse_take5(
1892 for (;*strp == ' '||*strp == '\t'; strp++) ;
1902 for (; *strp != '\0'; strp++) {
1903 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1904 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1909 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1910 || (isquoted && *strp == '"'))
1924 for (;*strp == ' '||*strp == '\t'; strp++) ;
1933 for (; *strp != '\0'; strp++) {
1934 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1935 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1940 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1941 || (isquoted && *strp == '"'))
1954 for (;*strp == ' '||*strp == '\t'; strp++);
1962 for (; *strp != '\0'; strp++) {
1963 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1964 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1969 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1970 || (isquoted && *strp == '"'))
1982 for (;*strp == ' '||*strp == '\t'; strp++);
1990 for (; *strp != '\0'; strp++) {
1991 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1992 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1997 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1998 || (isquoted && *strp == '"'))
2009 for (;*strp == ' '||*strp == '\t'; strp++);
2017 for (; *strp != '\0'; strp++) {
2018 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2019 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2024 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2025 || (isquoted && *strp == '"'))
2035 * The device definition file is loaded.
2037 * @param arg [i] The name of the device definition file is specified.
2038 * @param mconfig [i/o] The pointer to a set structure is specified.
2042 cmd_load_device_data(cmd_parms *parms, void *mconfig, const char *arg)
2044 mod_chxj_config *conf;
2049 if (strlen(arg) > 256)
2050 return "mod_chxj: device data filename too long.";
2052 conf = (mod_chxj_config *)mconfig;
2053 conf->device_data_file = apr_pstrdup(parms->pool, arg);
2055 qs_init_malloc(&doc);
2056 qs_init_root_node(&doc);
2058 qs_parse_file((Doc *)&doc, (const char *)arg);
2059 chxj_load_device_data(&doc,parms->pool, conf);
2060 qs_all_free(&doc, QX_LOGMARK);
2067 * Device definition information is loaded.
2070 * @param arg [i] The name of the device definition file is specified.
2071 * @param mconfig [i/o] The pointer to a set structure is specified.
2075 cmd_load_emoji_data(cmd_parms *parms, void *mconfig, const char *arg)
2077 mod_chxj_config *conf;
2084 if (strlen(arg) > 256)
2085 return "mod_chxj: emoji data filename too long.";
2087 conf = (mod_chxj_config *)mconfig;
2088 conf->emoji_data_file = apr_pstrdup(parms->pool, arg);
2089 qs_init_malloc(&doc);
2090 qs_init_root_node(&doc);
2092 qs_parse_file((Doc *)&doc, (const char *)arg);
2094 rtn = chxj_load_emoji_data(&doc,parms->pool, conf);
2096 qs_all_free(&doc, QX_LOGMARK);
2104 cmd_set_image_engine(cmd_parms * UNUSED(parms), void *mconfig, const char *arg)
2106 mod_chxj_config *conf;
2111 if (strlen(arg) > 256)
2112 return "image uri is too long.";
2114 conf = (mod_chxj_config*)mconfig;
2115 if (strcasecmp("ON", arg) == 0) {
2116 conf->image = CHXJ_IMG_ON;
2119 conf->image = CHXJ_IMG_OFF;
2127 cmd_set_image_cache_dir(cmd_parms *parms, void *mconfig, const char *arg)
2129 mod_chxj_config *conf;
2134 if (strlen(arg) > 256)
2135 return "cache dir name is too long.";
2137 conf = (mod_chxj_config *)mconfig;
2138 conf->image_cache_dir = apr_pstrdup(parms->pool, arg);
2145 cmd_set_image_cache_limit(cmd_parms *parms, void *mconfig, const char *arg)
2147 mod_chxj_config *conf;
2152 if (strlen(arg) > IMAGE_CACHE_LIMIT_FMT_LEN)
2153 return "cache size is too long.";
2155 conf = (mod_chxj_config *)mconfig;
2158 * I use strtol function because strtoul is not portable function.
2160 conf->image_cache_limit = (unsigned long)strtol(arg, NULL, 10);
2163 return apr_psprintf(parms->pool, "ChxjImageCacheLimit invalid value [%s] errno:[%d]", arg, errno);
2165 return apr_psprintf(parms->pool, "ChxjImageCacheLimit Out of range [%s] errno:[%d]", arg, errno);
2174 cmd_set_image_copyright(cmd_parms *parms, void *mconfig, const char *arg)
2176 mod_chxj_config *conf;
2181 if (strlen(arg) > 256)
2182 return "Copyright Flag is too long.";
2184 conf = (mod_chxj_config *)mconfig;
2185 conf->image_copyright = apr_pstrdup(parms->pool, arg);
2192 cmd_convert_rule(cmd_parms *cmd, void *mconfig, const char *arg)
2196 mod_chxj_config *dconf;
2197 chxjconvrule_entry *newrule;
2207 dconf = (mod_chxj_config *)mconfig;
2209 if (strlen(arg) > 4096)
2210 return "mod_chxj: ChxjConvertRule: is too long.";
2212 dconf = (mod_chxj_config *)mconfig;
2213 if (dconf->convrules == NULL)
2214 dconf->convrules = apr_array_make(cmd->pool,
2216 sizeof(chxjconvrule_entry));
2218 newrule = apr_array_push(dconf->convrules);
2221 newrule->action = 0;
2223 if (chxj_command_parse_take5(arg, &prm1, &prm2, &prm3, &prm4, &prm5))
2224 return "ChxjConvertRule: bad argument line";
2226 newrule->pattern = apr_pstrdup(cmd->pool, prm1);
2230 if ((action = apr_strtok(prm2, ",", &pstate)) == NULL)
2236 if (strcasecmp(CONVRULE_ENGINE_ON_CMD, action) == 0) {
2237 newrule->action |= CONVRULE_ENGINE_ON_BIT;
2240 if (strcasecmp(CONVRULE_ENGINE_OFF_CMD, action) == 0) {
2241 newrule->action |= CONVRULE_ENGINE_OFF_BIT;
2247 if (strcasecmp(CONVRULE_COOKIE_ON_CMD, action) == 0) {
2248 newrule->action |= CONVRULE_COOKIE_ON_BIT;
2254 if (strcasecmp(CONVRULE_Z2H_ON_CMD, action) == 0) {
2255 newrule->action |= CONVRULE_Z2H_ON_BIT;
2258 if (strcasecmp(CONVRULE_Z2H_OFF_CMD, action) == 0) {
2259 newrule->action |= CONVRULE_Z2H_OFF_BIT;
2262 if (strcasecmp(CONVRULE_Z2H_ALPHA_ON_CMD, action) == 0) {
2263 newrule->action |= CONVRULE_Z2H_ALPHA_ON_BIT;
2266 if (strcasecmp(CONVRULE_Z2H_ALPHA_OFF_CMD, action) == 0) {
2267 newrule->action |= CONVRULE_Z2H_ALPHA_OFF_BIT;
2270 if (strcasecmp(CONVRULE_Z2H_NUM_ON_CMD, action) == 0) {
2271 newrule->action |= CONVRULE_Z2H_NUM_ON_BIT;
2274 if (strcasecmp(CONVRULE_Z2H_NUM_OFF_CMD, action) == 0) {
2275 newrule->action |= CONVRULE_Z2H_NUM_OFF_BIT;
2278 if (strcasecmp(CONVRULE_Z2H_ALL_ON_CMD, action) == 0) {
2279 newrule->action |= CONVRULE_Z2H_ON_BIT | CONVRULE_Z2H_ALPHA_ON_BIT | CONVRULE_Z2H_NUM_ON_BIT;
2282 if (strcasecmp(CONVRULE_Z2H_NUM_OFF_CMD, action) == 0) {
2283 newrule->action |= CONVRULE_Z2H_OFF_BIT | CONVRULE_Z2H_ALPHA_OFF_BIT | CONVRULE_Z2H_NUM_OFF_BIT;
2294 newrule->flags |= CONVRULE_FLAG_NOTMATCH;
2298 mode = AP_REG_EXTENDED;
2299 if ((regexp = ap_pregcomp((apr_pool_t *)cmd->pool, (const char *)pp, mode)) == NULL)
2300 return "RewriteRule: cannot compile regular expression ";
2302 newrule->regexp = regexp;
2304 newrule->encoding = apr_pstrdup(cmd->pool, prm3);
2306 newrule->encoding = apr_pstrdup(cmd->pool, "none");
2308 newrule->pc_flag = CONVRULE_PC_FLAG_OFF_BIT;
2310 if (strcasecmp(CONVRULE_PC_FLAG_ON_CMD, prm4) == 0)
2311 newrule->pc_flag = CONVRULE_PC_FLAG_ON_BIT;
2313 newrule->user_agent = NULL;
2315 newrule->user_agent = apr_pstrdup(cmd->pool, prm5);
2327 mod_chxj_config *dconf;
2330 if (strlen(arg) > 4096)
2331 return "mod_chxj: ChxjCookieDir is too long.";
2333 dconf = (mod_chxj_config *)mconfig;
2335 dconf->cookie_db_dir = apr_pstrdup(cmd->pool, arg);
2342 cmd_set_cookie_timeout(
2343 cmd_parms *UNUSED(cmd),
2347 mod_chxj_config *dconf;
2349 if (strlen(arg) > 4096)
2350 return "mod_chxj: ChxjCookieTimeout is too long.";
2352 if (chxj_chk_numeric(arg) != 0)
2353 return "mod_chxj: ChxjCookieTimeout is not numeric.";
2355 dconf = (mod_chxj_config *)mconfig;
2357 dconf->cookie_timeout = atoi(arg);
2363 #if defined(USE_MYSQL_COOKIE)
2365 cmd_set_cookie_mysql_database(
2370 mod_chxj_config *dconf;
2372 if (strlen(arg) > 255)
2373 return "mod_chxj: ChxjCookieMysqlDatabase is too long.";
2375 dconf = (mod_chxj_config *)mconfig;
2377 dconf->mysql.database = apr_pstrdup(cmd->pool, arg);
2384 cmd_set_cookie_mysql_username(
2389 mod_chxj_config *dconf;
2391 if (strlen(arg) > 255)
2392 return "mod_chxj: ChxjCookieMysqlUsername is too long.";
2394 dconf = (mod_chxj_config *)mconfig;
2396 dconf->mysql.username = apr_pstrdup(cmd->pool, arg);
2403 cmd_set_cookie_mysql_password(
2408 mod_chxj_config *dconf;
2410 if (strlen(arg) > 255)
2411 return "mod_chxj: ChxjCookieMysqlPassword is too long.";
2413 dconf = (mod_chxj_config *)mconfig;
2415 dconf->mysql.password = apr_pstrdup(cmd->pool, arg);
2422 cmd_set_cookie_mysql_table_name(
2427 mod_chxj_config *dconf;
2429 if (strlen(arg) > 255)
2430 return "mod_chxj: ChxjCookieMysqlTableName is too long.";
2432 dconf = (mod_chxj_config *)mconfig;
2434 dconf->mysql.tablename = apr_pstrdup(cmd->pool, arg);
2440 cmd_set_cookie_mysql_port(
2441 cmd_parms *UNUSED(cmd),
2445 mod_chxj_config *dconf;
2447 if (strlen(arg) > 255)
2448 return "mod_chxj: ChxjCookieMysqlPort is too long.";
2450 dconf = (mod_chxj_config *)mconfig;
2452 if (chxj_chk_numeric(arg) != 0)
2453 return "mod_chxj: ChxjCookieMysqlPort is not numeric.";
2455 dconf = (mod_chxj_config *)mconfig;
2457 dconf->mysql.port = chxj_atoi(arg);
2464 cmd_set_cookie_mysql_host(
2469 mod_chxj_config *dconf;
2471 if (strlen(arg) > 255)
2472 return "mod_chxj: ChxjCookieMysqlHost is too long.";
2474 dconf = (mod_chxj_config *)mconfig;
2476 dconf->mysql.host = apr_pstrdup(cmd->pool, arg);
2483 cmd_set_cookie_mysql_socket_path(
2488 mod_chxj_config *dconf;
2490 if (strlen(arg) > 4096)
2491 return "mod_chxj: ChxjCookieMysqlSocketPath is too long.";
2493 dconf = (mod_chxj_config *)mconfig;
2495 dconf->mysql.socket_path = apr_pstrdup(cmd->pool, arg);
2502 cmd_set_cookie_mysql_charset(
2507 mod_chxj_config *dconf;
2509 if (strlen(arg) > 255)
2510 return "mod_chxj: ChxjCookieMysqlCharset is too long.";
2512 dconf = (mod_chxj_config *)mconfig;
2514 dconf->mysql.charset = apr_pstrdup(cmd->pool, arg);
2519 #if defined(USE_MEMCACHE_COOKIE)
2521 cmd_set_cookie_memcache_port(
2522 cmd_parms *UNUSED(cmd),
2526 mod_chxj_config *dconf;
2528 if (strlen(arg) > 255)
2529 return "mod_chxj: ChxjCookieMemcachePort is too long.";
2531 dconf = (mod_chxj_config *)mconfig;
2533 if (chxj_chk_numeric(arg) != 0)
2534 return "mod_chxj: ChxjCookieMemcachePort is not numeric.";
2536 dconf = (mod_chxj_config *)mconfig;
2538 dconf->memcache.port = (apr_port_t)chxj_atoi(arg);
2545 cmd_set_cookie_memcache_host(
2550 mod_chxj_config *dconf;
2552 if (strlen(arg) > 255)
2553 return "mod_chxj: ChxjCookieMemcacheHost is too long.";
2555 dconf = (mod_chxj_config *)mconfig;
2557 dconf->memcache.host = apr_pstrdup(cmd->pool, arg);
2564 cmd_set_cookie_lazy_mode(
2565 cmd_parms *UNUSED(cmd),
2569 mod_chxj_config *dconf;
2571 if (strlen(arg) > 255)
2572 return "mod_chxj: ChxjCookieLazyMode is too long.";
2574 dconf = (mod_chxj_config *)mconfig;
2576 if (strcasecmp("TRUE",arg) == 0) {
2577 dconf->cookie_lazy_mode = COOKIE_LAZY_ON;
2580 dconf->cookie_lazy_mode = COOKIE_LAZY_OFF;
2587 cmd_set_cookie_store_type(
2588 cmd_parms *UNUSED(cmd),
2592 mod_chxj_config *dconf;
2594 if (strlen(arg) > 255)
2595 return "mod_chxj: ChxjCookieStoreType is too long.";
2597 dconf = (mod_chxj_config *)mconfig;
2599 if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_DBM, arg) == 0) {
2600 dconf->cookie_store_type = COOKIE_STORE_TYPE_DBM;
2602 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MYSQL, arg) == 0) {
2603 dconf->cookie_store_type = COOKIE_STORE_TYPE_MYSQL;
2605 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MEMCACHE, arg) == 0) {
2606 dconf->cookie_store_type = COOKIE_STORE_TYPE_MEMCACHE;
2609 dconf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
2616 cmd_set_forward_url_base(
2621 mod_chxj_config *dconf;
2623 if (strlen(arg) > 255)
2624 return "mod_chxj: ChxjForwardUrlBase is too long.";
2626 dconf = (mod_chxj_config *)mconfig;
2628 dconf->forward_url_base = apr_pstrdup(cmd->pool, arg);
2634 cmd_set_forward_server_ip(
2639 mod_chxj_config *dconf;
2641 if (strlen(arg) > 255)
2642 return "mod_chxj: ChxjForwardServerIp is too long.";
2644 dconf = (mod_chxj_config *)mconfig;
2646 dconf->forward_server_ip = apr_pstrdup(cmd->pool, arg);
2652 cmd_set_new_line_type(
2653 cmd_parms *UNUSED(cmd),
2657 mod_chxj_config *dconf;
2658 if (strlen(arg) > 255)
2659 return "mod_chxj: ChxjNewLineType is too long.";
2661 dconf = (mod_chxj_config *)mconfig;
2663 if (strcasecmp(CHXJ_NEW_LINE_TYPE_CRLF, arg) == 0) {
2664 dconf->new_line_type = NLTYPE_CRLF;
2666 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_LF, arg) == 0) {
2667 dconf->new_line_type = NLTYPE_LF;
2669 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_CR, arg) == 0) {
2670 dconf->new_line_type = NLTYPE_CR;
2672 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_NONE, arg) == 0) {
2673 dconf->new_line_type = NLTYPE_NONE;
2676 return "mod_chxj: invalid value (ChxjNewLineType)";
2682 static const command_rec cmds[] = {
2684 "ChxjLoadDeviceData",
2685 cmd_load_device_data,
2688 "Load Device Data"),
2690 "ChxjLoadEmojiData",
2691 cmd_load_emoji_data,
2697 cmd_set_image_engine,
2700 "Convert Target URI"),
2702 "ChxjImageCacheDir",
2703 cmd_set_image_cache_dir,
2706 "Image Cache Directory"),
2708 "ChxjImageCacheLimit",
2709 cmd_set_image_cache_limit,
2712 "Image Cache Limit"),
2714 "ChxjImageCopyright",
2715 cmd_set_image_copyright,
2724 "an URL-applied regexp-pattern and a substitution URL"),
2730 "save cookie.db directory."),
2732 "ChxjCookieTimeout",
2733 cmd_set_cookie_timeout,
2736 "The compulsion time-out time of the cookie is specified. "),
2738 "ChxjCookieStoreType",
2739 cmd_set_cookie_store_type,
2742 "It specifies preserving of the cookie ahead. (DBM/MYSQL/MEMCACHE)"),
2744 "ChxjCookieLazyMode",
2745 cmd_set_cookie_lazy_mode,
2748 "OneTimeID is negligently done. (TRUE/FALSE)"),
2749 #if defined(USE_MYSQL_COOKIE)
2751 "ChxjCookieMysqlHost",
2752 cmd_set_cookie_mysql_host,
2755 "The MySQL database host used by saving Cookie"),
2757 "ChxjCookieMysqlPort",
2758 cmd_set_cookie_mysql_port,
2761 "The MySQL database port used by saving Cookie"),
2763 "ChxjCookieMysqlDatabase",
2764 cmd_set_cookie_mysql_database,
2767 "The MySQL database name used by saving Cookie"),
2769 "ChxjCookieMysqlUsername",
2770 cmd_set_cookie_mysql_username,
2773 "The MySQL username used by saving Cookie"),
2775 "ChxjCookieMysqlPassword",
2776 cmd_set_cookie_mysql_password,
2779 "The MySQL password used by saving Cookie"),
2781 "ChxjCookieMysqlTableName",
2782 cmd_set_cookie_mysql_table_name,
2785 "The MySQL table name used by saving Cookie"),
2787 "ChxjCookieMysqlSocketPath",
2788 cmd_set_cookie_mysql_socket_path,
2791 "The MySQL socket path used by saving Cookie"),
2793 "ChxjCookieMysqlCharset",
2794 cmd_set_cookie_mysql_charset,
2797 "The MySQL charset used by saving Cookie"),
2799 #if defined(USE_MEMCACHE_COOKIE)
2801 "ChxjCookieMemcacheHost",
2802 cmd_set_cookie_memcache_host,
2805 "The Memcached host used by saving Cookie"),
2807 "ChxjCookieMemcachePort",
2808 cmd_set_cookie_memcache_port,
2811 "The Memcached port used by saving Cookie"),
2815 cmd_set_new_line_type,
2818 "HTML new line type (NONE|CRLF|LF|CR). default is CRLF"),
2820 "ChxjForwardUrlBase",
2821 cmd_set_forward_url_base,
2824 "The forward url base(default: {request protocol}://{this server}:{this server port}"),
2826 "ChxjForwardServerIp",
2827 cmd_set_forward_server_ip,
2830 "The forward server ip(default: this server ip)"),
2835 /*----------------------------------------------------------------------------*/
2836 /* Dispatch list for API hooks */
2837 /*----------------------------------------------------------------------------*/
2838 module AP_MODULE_DECLARE_DATA chxj_module = {
2839 STANDARD20_MODULE_STUFF,
2840 chxj_create_per_dir_config, /* create per-dir config structures */
2841 chxj_merge_per_dir_config, /* merge per-dir config structures */
2842 chxj_config_server_create, /* create per-server config structures */
2843 NULL, /* merge per-server config structures */
2844 cmds, /* table of config file commands */
2845 chxj_register_hooks /* register hooks */