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"
73 #include "chxj_jreserved_tag.h"
76 #define CHXJ_VERSION_PREFIX PACKAGE_NAME "/"
77 #define CHXJ_VERSION PACKAGE_VERSION
78 #define CHXJ_POST_MAX (0x1000000)
80 converter_t convert_routine[] = {
82 /* CHXJ_SPEC_UNKNOWN */
87 /* CHXJ_SPEC_Chtml_1_0 */
88 .converter = chxj_convert_chtml10,
89 .encoder = chxj_encoding,
92 /* CHXJ_SPEC_Chtml_2_0 */
93 .converter = chxj_convert_chtml20,
94 .encoder = chxj_encoding,
97 /* CHXJ_SPEC_Chtml_3_0 */
98 .converter = chxj_convert_chtml30,
99 .encoder = chxj_encoding,
102 /* CHXJ_SPEC_Chtml_4_0 */
103 .converter = chxj_convert_chtml40,
104 .encoder = chxj_encoding,
107 /* CHXJ_SPEC_Chtml_5_0 */
108 .converter = chxj_convert_chtml50,
109 .encoder = chxj_encoding,
112 /* CHXJ_SPEC_Chtml_6_0 */
113 .converter = chxj_convert_chtml50,
114 .encoder = chxj_encoding,
117 /* CHXJ_SPEC_Chtml_7_0 */
118 .converter = chxj_convert_chtml50,
119 .encoder = chxj_encoding,
122 /* CHXJ_SPEC_XHtml_Mobile_1_0 */
123 .converter = chxj_convert_xhtml_mobile_1_0,
124 .encoder = chxj_encoding,
128 .converter = chxj_convert_hdml,
129 .encoder = chxj_encoding,
132 /* CHXJ_SPEC_Jhtml */
133 .converter = chxj_convert_jhtml,
134 .encoder = chxj_encoding,
137 /* CHXJ_SPEC_Jxhtml */
138 .converter = chxj_convert_jxhtml,
139 .encoder = chxj_encoding,
148 static int chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp, device_table *spec);
149 static void s_convert_guid_parameter_to_header(request_rec *r, const char *param, device_table *spec);
150 static void s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie);
151 static void s_clear_cookie_header(request_rec *r, device_table *spec);
154 * Only when User-Agent is specified, the User-Agent header is camouflaged.
159 chxj_headers_fixup(request_rec *r)
161 mod_chxj_config* dconf;
162 chxjconvrule_entry* entryp;
168 DBG(r, "REQ[%X] start chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
170 DBG(r, "REQ[%X] detect internal redirect.", (unsigned int)(apr_size_t)r);
171 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
175 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
177 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
178 spec = chxj_specified_device(r, user_agent);
180 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
182 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
183 DBG(r, "REQ[%X] detect multipart/form-data ==> no target", (unsigned int)(apr_size_t)r);
184 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
187 if (r->method_number == M_POST) {
188 if (!apr_table_get(r->headers_in, "X-Chxj-Forward")) {
189 s_clear_cookie_header(r, spec);
193 s_clear_cookie_header(r, spec);
196 switch(spec->html_spec_type) {
197 case CHXJ_SPEC_Chtml_1_0:
198 case CHXJ_SPEC_Chtml_2_0:
199 case CHXJ_SPEC_Chtml_3_0:
200 case CHXJ_SPEC_Chtml_4_0:
201 case CHXJ_SPEC_Chtml_5_0:
202 case CHXJ_SPEC_Chtml_6_0:
203 case CHXJ_SPEC_Chtml_7_0:
204 case CHXJ_SPEC_XHtml_Mobile_1_0:
206 case CHXJ_SPEC_Jhtml:
207 case CHXJ_SPEC_Jxhtml:
208 entryp = chxj_apply_convrule(r, dconf->convrules);
210 DBG(r, "REQ[%X] end chxj_headers_fixup() (no pattern)", (unsigned int)(apr_size_t)r);
213 if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
214 DBG(r, "REQ[%X] end chxj_headers_fixup() (engine off)", (unsigned int)(apr_size_t)r);
218 apr_table_setn(r->headers_in,
219 CHXJ_HTTP_USER_AGENT,
222 if (entryp->user_agent)
223 apr_table_setn(r->headers_in,
227 chxj_convert_input_header(r,entryp, spec);
232 DBG(r, "REQ[%X] end chxj_headers_fixup() (not mobile)", (unsigned int)(apr_size_t)r);
238 if (r->method_number == M_POST) {
239 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
240 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);
241 r->proxyreq = PROXYREQ_NONE;
242 r->handler = apr_psprintf(r->pool, "chxj-input-handler");
245 char *client_ip = (char *)apr_table_get(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP);
247 apr_sockaddr_t *address = NULL;
248 apr_status_t rv = apr_sockaddr_info_get(&address, ap_get_server_name(r), APR_UNSPEC, ap_get_server_port(r), 0, r->pool);
249 if (rv != APR_SUCCESS) {
251 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));
252 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
256 if (dconf->forward_server_ip) {
257 addr = dconf->forward_server_ip;
260 apr_sockaddr_ip_get(&addr, address);
262 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);
263 if (strcmp(addr, r->connection->remote_ip) == 0) {
264 r->connection->remote_ip = apr_pstrdup(r->connection->pool, client_ip);
266 if (! apr_table_get(r->headers_in, "Content-Length")) {
267 contentLength = (char *)apr_table_get(r->headers_in, "X-Chxj-Content-Length");
269 apr_table_set(r->headers_in, "Content-Length", contentLength);
276 chxj_add_device_env(r, spec);
278 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
285 s_clear_cookie_header(request_rec *r, device_table *spec)
287 switch(spec->html_spec_type) {
288 case CHXJ_SPEC_Chtml_1_0:
289 case CHXJ_SPEC_Chtml_2_0:
290 case CHXJ_SPEC_Chtml_3_0:
291 case CHXJ_SPEC_Chtml_4_0:
292 case CHXJ_SPEC_Chtml_5_0:
293 case CHXJ_SPEC_Chtml_6_0:
294 case CHXJ_SPEC_Chtml_7_0:
295 case CHXJ_SPEC_XHtml_Mobile_1_0:
296 case CHXJ_SPEC_Jhtml:
297 apr_table_unset(r->headers_in, "Cookie");
306 * It converts it from CHTML into XXML corresponding to each model.
309 * @param src [i] It is former HTML character string.
310 * @param len [i/o] It is length of former HTML character string.
313 chxj_convert(request_rec *r, const char **src, apr_size_t *len, device_table *spec, const char *ua, cookie_t **cookiep)
319 mod_chxj_config *dconf;
320 chxjconvrule_entry *entryp;
322 DBG(r,"REQ[%X] start of chxj_convert() input:[%.*s]", (unsigned int)(apr_size_t)r, (int)*len, *src);
323 dst = apr_pstrcat(r->pool, (char *)*src, NULL);
325 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
328 entryp = chxj_apply_convrule(r, dconf->convrules);
330 if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
331 DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
336 /*------------------------------------------------------------------------*/
337 /* get UserAgent from http header */
338 /*------------------------------------------------------------------------*/
339 if (entryp->user_agent)
340 user_agent = (char *)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
342 user_agent = (char *)apr_table_get(r->headers_in, HTTP_USER_AGENT);
344 DBG(r,"REQ[%X] User-Agent:[%s]", (unsigned int)(apr_size_t)r, user_agent);
345 DBG(r,"REQ[%X] content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
348 if ( ! STRNCASEEQ('t','T', "text/html", r->content_type, sizeof("text/html")-1)
349 && ! STRNCASEEQ('a','A', "application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)) {
350 DBG(r,"REQ[%X] no convert. content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
351 DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
355 if (ua && user_agent && strcasecmp(user_agent, ua) != 0) {
357 spec = chxj_specified_device(r, user_agent);
364 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
365 switch(spec->html_spec_type) {
366 case CHXJ_SPEC_Chtml_1_0:
367 case CHXJ_SPEC_Chtml_2_0:
368 case CHXJ_SPEC_Chtml_3_0:
369 case CHXJ_SPEC_Chtml_4_0:
370 case CHXJ_SPEC_Chtml_5_0:
371 case CHXJ_SPEC_Chtml_6_0:
372 case CHXJ_SPEC_Chtml_7_0:
373 case CHXJ_SPEC_XHtml_Mobile_1_0:
374 case CHXJ_SPEC_Jhtml:
375 cookie = chxj_save_cookie(r);
382 if (!r->header_only) {
385 if (convert_routine[spec->html_spec_type].encoder)
386 tmp = convert_routine[spec->html_spec_type].encoder(r,
390 if (convert_routine[spec->html_spec_type].converter) {
392 dst = convert_routine[spec->html_spec_type].converter(r,
400 dst = convert_routine[spec->html_spec_type].converter(r,
409 dst = chxj_conv_z2h(r, dst, len, entryp);
412 ap_set_content_length(r, *len);
415 dst = apr_psprintf(r->pool, "\n");
424 DBG(r, "REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
431 * convert GUID parameter.
435 s_convert_guid_parameter_to_header(request_rec *r, const char *param, device_table *spec)
437 if (strcasecmp(param, "guid") == 0) {
438 switch(spec->html_spec_type) {
439 case CHXJ_SPEC_XHtml_Mobile_1_0:
441 char *x_up_subno = (char *)apr_table_get(r->headers_in, "x-up-subno");
443 apr_table_setn(r->headers_in, "X-DCMGUID", x_up_subno);
447 case CHXJ_SPEC_Jhtml:
448 case CHXJ_SPEC_Jxhtml:
450 char *x_jphone_uid = (char *)apr_table_get(r->headers_in, "x-jphone-uid");
452 apr_table_setn(r->headers_in, "X-DCMGUID", x_jphone_uid);
463 * It converts it from HEADER.
468 chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp, device_table *spec)
480 cookie_t *cookie = NULL;
481 int no_update_flag = 0;
483 DBG(r, "REQ[%X] start chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
486 DBG(r, "REQ[%X] r->args=[null]", (unsigned int)(apr_size_t)r);
487 DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
490 urilen = strlen(r->args);
492 result = qs_alloc_zero_byte_string(r->pool);
494 buff_pre = apr_pstrdup(r->pool, r->args);
499 pair = apr_strtok(buff_pre, "&", &pstate);
505 pair_sv = apr_pstrdup(r->pool, pair);
507 name = apr_strtok(pair, "=", &vstate);
508 value = apr_strtok(NULL, "=", &vstate);
509 if (! name) continue;
510 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
511 DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
516 buff = apr_pstrdup(r->pool, r->args);
517 DBG(r, "REQ[%X] r->args=[%s]", (unsigned int)(apr_size_t)r, buff);
526 pair = apr_strtok(buff, "&", &pstate);
532 pair_sv = apr_pstrdup(r->pool, pair);
534 name = apr_strtok(pair, "=", &vstate);
535 value = apr_strtok(NULL, "=", &vstate);
536 if (! name) continue;
537 name = chxj_safe_to_jreserved_tag(r, name);
539 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
540 if (strlen(result) != 0)
541 result = apr_pstrcat(r->pool, result, "&", NULL);
543 if (strcasecmp(entryp->encoding, "NONE") != 0) {
548 if (value && *value != 0) {
549 value = chxj_url_decode(r->pool, value);
550 dlen = strlen(value);
551 DBG(r, "************ before encoding[%s]", value);
553 dvalue = chxj_rencoding(r, value, &dlen);
554 dvalue = chxj_url_encode(r->pool, dvalue);
556 DBG(r, "************ after encoding[%s]", dvalue);
562 if (name && *name != 0) {
563 name = chxj_url_decode(r->pool, name);
565 dname = chxj_rencoding(r, name, &dlen);
566 dname = chxj_url_encode(r->pool, dname);
571 s_convert_guid_parameter_to_header(r, dname, spec);
572 result = apr_pstrcat(r->pool, result, dname, "=", dvalue, NULL);
575 if (strcmp(name, pair_sv) != 0)
576 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
578 result = apr_pstrcat(r->pool, result, name, NULL);
582 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
583 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
584 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
588 if (strlen(value) == 0)
591 if (strlen(result) != 0)
592 result = apr_pstrcat(r->pool, result, "&", NULL);
594 result = apr_pstrcat(r->pool, result, &name[8], "=", value, NULL);
597 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
599 apr_table_unset(r->headers_in, "Cookie");
600 DBG(r, "REQ[%X] found cookie parameter[%s]", (unsigned int)(apr_size_t)r, value);
601 DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
602 cookie_lock_t *lock = chxj_cookie_lock(r);
603 cookie = chxj_load_cookie(r, value);
604 DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
605 if (! no_update_flag && cookie) {
606 cookie = chxj_update_cookie(r, cookie);
608 chxj_cookie_unlock(r, lock);
610 if (cookie && cookie->cookie_id) {
611 if (strlen(result) != 0)
612 result = apr_pstrcat(r->pool, result, "&", NULL);
613 result = apr_pstrcat(r->pool, result, name, "=", cookie->cookie_id, NULL);
617 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
618 if (strlen(result) != 0)
619 result = apr_pstrcat(r->pool, result, "&", NULL);
620 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
623 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
624 if (! no_update_flag) {
625 result = apr_pstrcat(r->pool, result, "&_chxj_nc=true", NULL);
629 DBG(r, "REQ[%X] result r->args=[%s]", (unsigned int)(apr_size_t)r, r->args);
630 DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
636 * It converts it from POSTDATA .
639 * @param src [i] It is POSTDATA character string.
640 * @param len [i/o] It is length of former HTML character string.
647 chxjconvrule_entry *entryp,
657 cookie_t *cookie = NULL;
659 int no_update_flag = 0;
664 DBG(r, "REQ[%X] start of chxj_input_convert()", (unsigned int)(apr_size_t)r);
667 DBG(r, "REQ[%X] end of chxj_input_convert() (input is null)", (unsigned int)(apr_size_t)r);
668 return apr_pstrdup(r->pool, "");
671 apr_pool_create(&pool, r->pool);
673 s = apr_pstrdup(pool, *src);
675 buff_pre = apr_pstrdup(pool, *src);
677 result = qs_alloc_zero_byte_string(pool);
679 DBG(r, "REQ[%X] +-------------------------------------------------------------------+", (unsigned int)(apr_size_t)r);
680 DBG(r, "REQ[%X] | BEFORE input convert source |", (unsigned int)(apr_size_t)r);
681 DBG(r, "REQ[%X] +-------------------------------------------------------------------+", (unsigned int)(apr_size_t)r);
682 for (ii=0; ii<ilen-64; ii+=64) {
683 DBG(r, "REQ[%X] | [%-*.*s] |", (unsigned int)(apr_size_t)r, 64, 64, &s[ii]);
688 if (ilen >= 64 && ((ilen-64) % 64 != 0)) {
689 DBG(r, "REQ[%X] | [%-*.*s] |", (unsigned int)(apr_size_t)r, 64, 64, &s[ii]);
691 DBG(r, "REQ[%X] +--------------------------------------------------------------------+", (unsigned int)(apr_size_t)r);
696 pair = apr_strtok(buff_pre, "&", &pstate);
702 pair_sv = apr_pstrdup(pool, pair);
704 name = apr_strtok(pair, "=", &vstate);
705 value = apr_strtok(NULL, "=", &vstate);
706 if (! name) continue;
707 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
708 DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
718 pair = apr_strtok(s, "&", &pstate);
723 name = apr_strtok(pair, "=", &vstate);
724 value = apr_strtok(NULL, "=", &vstate);
725 if (! name) continue;
726 name = chxj_safe_to_jreserved_tag(r, name);
728 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
729 if (strlen(result) != 0)
730 result = apr_pstrcat(pool, result, "&", NULL);
732 if (strcasecmp(entryp->encoding, "NONE") != 0) {
737 if (value && *value != 0) {
738 value = chxj_url_decode(pool, value);
739 dlen = strlen(value);
740 dvalue = chxj_rencoding(r, value, &dlen);
741 dvalue = chxj_url_encode(pool, dvalue);
747 if (name && *name != 0) {
748 name = chxj_url_decode(pool, name);
750 dname = chxj_rencoding(r, name, &dlen);
751 dname = chxj_url_encode(pool, dname);
758 result = apr_pstrcat(pool, result, dname, "=", dvalue, NULL);
761 result = apr_pstrcat(pool, result, name, "=", value, NULL);
765 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
766 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
767 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
771 if (strlen(value) == 0)
774 if (strlen(result) != 0)
775 result = apr_pstrcat(pool, result, "&", NULL);
777 if (strcasecmp(entryp->encoding, "NONE") != 0 && value && strlen(value)) {
781 dlen = strlen(value);
782 value = chxj_url_decode(pool, value);
783 dvalue = chxj_rencoding(r, value, &dlen);
784 dvalue = chxj_url_encode(pool,dvalue);
785 result = apr_pstrcat(pool, result, &name[8], "=", dvalue, NULL);
789 result = apr_pstrcat(pool, result, &name[8], "=", value, NULL);
793 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
795 apr_table_unset(r->headers_in, "Cookie");
796 DBG(r, "REQ[%X] found cookie parameter[%s]", (unsigned int)(apr_size_t)r, value);
797 DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
798 cookie_lock_t *lock = chxj_cookie_lock(r);
799 cookie = chxj_load_cookie(r, value);
800 DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
801 if (! no_update_flag && cookie) {
802 cookie = chxj_update_cookie(r, cookie);
804 chxj_cookie_unlock(r, lock);
806 if (cookie && cookie->cookie_id) {
807 if (strlen(result) != 0)
808 result = apr_pstrcat(pool, result, "&", NULL);
809 result = apr_pstrcat(pool, result, name, "=", cookie->cookie_id, NULL);
813 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
814 if (strlen(result) != 0)
815 result = apr_pstrcat(pool, result, "&", NULL);
816 result = apr_pstrcat(pool, result, name, "=", value, NULL);
819 if ( strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1) == 0) {
822 dlen = strlen(value);
824 value = chxj_url_decode(pool, value);
825 dvalue = chxj_rencoding(r, value, &dlen);
826 dvalue = chxj_url_encode(pool,dvalue);
827 if (r->args && strlen(r->args) > 0) {
828 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
831 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
833 s_convert_guid_parameter_to_header(r, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], spec);
837 if (strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX_ENC, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1) == 0) {
840 dlen = strlen(value);
842 value = chxj_url_decode(pool, value);
843 dvalue = chxj_rencoding(r, value, &dlen);
844 dvalue = chxj_url_encode(pool,dvalue);
845 if (r->args && strlen(r->args) > 0) {
846 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
849 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
851 s_convert_guid_parameter_to_header(r, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], spec);
854 DBG(r, "REQ[%X] ************************ name:[%s]", (unsigned int)(apr_size_t)r, name);
856 *len = strlen(result);
857 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
858 if (! no_update_flag) {
859 result = apr_pstrcat(pool, result, "&_chxj_nc=true", NULL);
862 DBG(r, "REQ[%X] AFTER input convert result = [%s]", (unsigned int)(apr_size_t)r, result);
863 DBG(r, "REQ[%X] end chxj_input_convert()", (unsigned int)(apr_size_t)r);
870 * The received data is returned to the filter.
872 * @param f [i/o] It is a filter.
873 * @param data [i] It is data returned to the filter.
874 * @param len [i] It is length of the data returned to the filter.
877 pass_data_to_filter(ap_filter_t *f, const char *data,
880 request_rec *r = f->r;
881 conn_rec *c = r->connection;
883 apr_bucket_brigade *bb;
886 DBG(r, "REQ[%X] start pass_data_to_filter()", (unsigned int)(apr_size_t)r);
888 chxj_header_inf_clear(r);
890 bb = apr_brigade_create(r->pool, c->bucket_alloc);
891 b = apr_bucket_transient_create(data, len, c->bucket_alloc);
893 APR_BRIGADE_INSERT_TAIL(bb, b);
894 b = apr_bucket_eos_create(f->c->bucket_alloc);
895 APR_BRIGADE_INSERT_TAIL(bb, b);
897 rv = ap_pass_brigade(f->next, bb);
898 if (rv != APR_SUCCESS) {
899 DBG(r, "REQ[%X] end pass_data_to_filter() (apr_pass_brigade)", (unsigned int)(apr_size_t)r);
903 DBG(r, "REQ[%X] end pass_data_to_filter()", (unsigned int)(apr_size_t)r);
910 * It is the main loop of the output filter.
912 * @param f [i/o] It is a filter.
916 chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
922 char *user_agent = NULL;
924 mod_chxj_ctx *ctx = (mod_chxj_ctx *)f->ctx;
925 cookie_t *cookie = NULL;
926 mod_chxj_config *dconf;
927 chxjconvrule_entry *entryp = NULL;
928 device_table *spec = NULL;
932 DBG(f->r, "REQ[%X] start of chxj_output_filter()", (unsigned int)(apr_size_t)r);
935 apr_pool_create(&pool, r->pool);
937 entryp = ctx->entryp;
939 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
941 if (r->content_type) {
942 if (! STRNCASEEQ('t','T',"text/html",r->content_type, sizeof("text/html")-1)
943 && ! STRNCASEEQ('t','T',"text/xml", r->content_type, sizeof("text/xml")-1)
944 && ! STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
945 && ! (dconf->image == CHXJ_IMG_ON
946 && ! apr_table_get(r->headers_in, "CHXJ_IMG_CONV")
947 && STRNCASEEQ('i','I',"image/", r->content_type, sizeof("image/") -1)
948 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
949 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
950 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
951 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
952 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
953 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
954 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
955 || STRCASEEQ('g','G',"gif", &r->content_type[6])))) { /* GIF */
957 DBG(r, "REQ[%X] not convert content-type:[%s] dconf->image:[%d]", (unsigned int)(apr_size_t)r, r->content_type, dconf->image);
958 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
959 cookie_lock_t *lock = NULL;
960 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
961 switch(spec->html_spec_type) {
962 case CHXJ_SPEC_Chtml_1_0:
963 case CHXJ_SPEC_Chtml_2_0:
964 case CHXJ_SPEC_Chtml_3_0:
965 case CHXJ_SPEC_Chtml_4_0:
966 case CHXJ_SPEC_Chtml_5_0:
967 case CHXJ_SPEC_Chtml_6_0:
968 case CHXJ_SPEC_Chtml_7_0:
969 case CHXJ_SPEC_XHtml_Mobile_1_0:
970 case CHXJ_SPEC_Jhtml:
971 lock = chxj_cookie_lock(r);
972 cookie = chxj_save_cookie(r);
973 s_add_cookie_id_if_has_location_header(r, cookie);
974 chxj_cookie_unlock(r, lock);
980 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
981 if (! ap_is_HTTP_REDIRECT(r->status)) {
982 r->status = HTTP_MOVED_TEMPORARILY;
985 ap_pass_brigade(f->next, bb);
986 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
991 DBG(r, "REQ[%X] not convert content-type:[(null)]", (unsigned int)(apr_size_t)r);
992 ap_pass_brigade(f->next, bb);
993 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
998 for (b = APR_BRIGADE_FIRST(bb);
999 b != APR_BRIGADE_SENTINEL(bb);
1000 b = APR_BUCKET_NEXT(b)) {
1002 if (apr_bucket_read(b, &data, &len, APR_BLOCK_READ) == APR_SUCCESS) {
1003 DBG(r, "REQ[%X] read data[%.*s]",(unsigned int)(apr_size_t)r, (int)len, data);
1005 /*--------------------------------------------------------------------*/
1007 /*--------------------------------------------------------------------*/
1009 DBG(r, "append data start");
1010 ctx = (mod_chxj_ctx *)f->ctx;
1013 tmp = apr_palloc(r->pool, ctx->len);
1014 memcpy(tmp, ctx->buffer, ctx->len);
1016 ctx->buffer = apr_palloc(pool, ctx->len + len);
1018 memcpy(ctx->buffer, tmp, ctx->len);
1019 memcpy(&ctx->buffer[ctx->len], data, len);
1023 DBG(r, "REQ[%X] append data end", (unsigned int)(apr_size_t)r);
1026 if (APR_BUCKET_IS_EOS(b)) {
1028 DBG(r, "REQ[%X] eos", (unsigned int)(apr_size_t)r);
1029 /*----------------------------------------------------------------------*/
1031 /*----------------------------------------------------------------------*/
1033 cookie_lock_t *lock = NULL;
1034 ctx = (mod_chxj_ctx *)f->ctx;
1036 DBG(r, "REQ[%X] content_type=[%s]", (unsigned int)(apr_size_t)r, r->content_type);
1037 lock = chxj_cookie_lock(r);
1039 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
1041 && (STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
1042 || STRNCASEEQ('t','T',"text/html", r->content_type, sizeof("text/html")-1))) {
1043 DBG(r, "REQ[%X] detect convert target:[%s]", (unsigned int)(apr_size_t)r, r->content_type);
1048 tmp = apr_palloc(pool, ctx->len + 1);
1050 memset(tmp, 0, ctx->len + 1);
1051 memcpy(tmp, ctx->buffer, ctx->len);
1053 ctx->buffer = chxj_convert(r,
1054 (const char **)&tmp,
1055 (apr_size_t *)&ctx->len,
1057 user_agent, &cookie);
1061 ctx->buffer = apr_psprintf(r->pool, "\n");
1063 ctx->buffer = chxj_convert(r,
1064 (const char **)&ctx->buffer,
1065 (apr_size_t *)&ctx->len,
1067 user_agent, &cookie);
1072 && *(char *)r->content_type == 't'
1073 && strncmp(r->content_type, "text/xml", 8) == 0) {
1074 DBG(r, "REQ[%X] text/XML", (unsigned int)(apr_size_t)r);
1082 memset(&doc, 0, sizeof(Doc));
1083 memset(&qrcode, 0, sizeof(qr_code_t));
1085 doc.parse_mode = PARSE_MODE_CHTML;
1089 qs_init_malloc(&doc);
1091 root = qs_parse_string(&doc, ctx->buffer, ctx->len);
1094 for (child = qs_get_child_node(&doc,root);
1096 child = qs_get_next_node(&doc,child)) {
1097 char *name = qs_get_node_name(&doc,child);
1098 if (strcasecmp("qrcode",name) == 0) {
1103 qs_all_free(&doc,QX_LOGMARK);
1105 r->handler = apr_psprintf(r->pool, "chxj-qrcode");
1106 chxj_qrcode_node_to_qrcode(&qrcode, root);
1107 sts = chxj_qrcode_create_image_data(&qrcode, &ctx->buffer, &ctx->len);
1109 ERR(r, "REQ[%X] qrcode create failed.", (unsigned int)(apr_size_t)r);
1110 chxj_cookie_unlock(r, lock);
1111 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1114 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1118 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
1120 && ( *r->content_type == 'i' || *r->content_type == 'I')
1121 && dconf->image == CHXJ_IMG_ON
1122 && strncasecmp("image/", r->content_type, 6) == 0
1123 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
1124 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
1125 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
1126 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
1127 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
1128 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
1129 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
1130 || STRCASEEQ('g','G',"gif", &r->content_type[6]))) { /* GIF */
1134 tmp = apr_palloc(pool, ctx->len + 1);
1136 memset(tmp, 0, ctx->len + 1);
1137 memcpy(tmp, ctx->buffer, ctx->len);
1139 chxj_convert_image(r,
1140 (const char **)&tmp,
1141 (apr_size_t *)&ctx->len);
1142 if (ctx->buffer == NULL) {
1148 apr_table_unset(r->headers_out, "Content-Length");
1149 apr_table_unset(r->err_headers_out, "Content-Length");
1150 ap_set_content_length(r, (apr_off_t)ctx->len);
1154 DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1155 s_add_cookie_id_if_has_location_header(r, cookie);
1156 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1157 if (! ap_is_HTTP_REDIRECT(r->status)) {
1158 r->status = HTTP_MOVED_TEMPORARILY;
1161 chxj_cookie_unlock(r,lock);
1162 rv = pass_data_to_filter(f,
1163 (const char *)ctx->buffer,
1164 (apr_size_t)ctx->len);
1167 chxj_cookie_unlock(r, lock);
1170 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1174 DBG(r, "REQ[%X] SAVE COOKIE[%x]", (unsigned int)(apr_size_t)r, entryp->action);
1179 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
1180 cookie_lock_t *lock = NULL;
1181 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
1182 switch(spec->html_spec_type) {
1183 case CHXJ_SPEC_Chtml_1_0:
1184 case CHXJ_SPEC_Chtml_2_0:
1185 case CHXJ_SPEC_Chtml_3_0:
1186 case CHXJ_SPEC_Chtml_4_0:
1187 case CHXJ_SPEC_Chtml_5_0:
1188 case CHXJ_SPEC_Chtml_6_0:
1189 case CHXJ_SPEC_Chtml_7_0:
1190 case CHXJ_SPEC_XHtml_Mobile_1_0:
1191 case CHXJ_SPEC_Jhtml:
1192 lock = chxj_cookie_lock(r);
1193 cookie = chxj_save_cookie(r);
1195 * Location Header Check to add cookie parameter.
1197 s_add_cookie_id_if_has_location_header(r, cookie);
1198 chxj_cookie_unlock(r, lock);
1199 apr_table_unset(r->headers_out, "Set-Cookie");
1200 apr_table_unset(r->err_headers_out, "Set-Cookie");
1207 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1208 if (! ap_is_HTTP_REDIRECT(r->status)) {
1209 r->status = HTTP_MOVED_TEMPORARILY;
1212 apr_table_setn(r->headers_out, "Content-Length", "0");
1213 DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1214 rv = pass_data_to_filter(f, (const char *)"", (apr_size_t)0);
1215 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1220 apr_brigade_destroy(bb);
1222 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1228 * Add Cookie_id if it has location header.
1231 s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie)
1233 char *location_header = (char *)apr_table_get(r->headers_out, "Location");
1234 if (! location_header) {
1235 location_header = (char *)apr_table_get(r->err_headers_out, "Location");
1237 if (cookie && location_header) {
1238 DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1239 location_header = chxj_add_cookie_parameter(r,
1242 apr_table_unset(r->headers_out, "Location");
1243 apr_table_setn(r->headers_out, "Location", location_header);
1244 DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1245 if (!ap_is_HTTP_REDIRECT(r->status)) {
1246 r->status = HTTP_MOVED_TEMPORARILY;
1252 * It is the main loop of the input filter handler.
1256 chxj_input_handler(request_rec *r)
1258 mod_chxj_config *dconf;
1259 chxjconvrule_entry *entryp = NULL;
1260 device_table *spec = NULL;
1261 char *post_data = NULL;
1262 apr_size_t post_data_len = 0;
1267 int response_code = 0;
1269 DBG(r, "start of chxj_input_handler()");
1271 if (strcasecmp(r->handler, "chxj-input-handler")) {
1272 DBG(r, "end chxj_input_handler()");
1275 apr_pool_create(&pool, r->pool);
1277 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1278 user_agent = (char*)apr_table_get(r->headers_in, "User-Agent");
1279 spec = chxj_specified_device(r, user_agent);
1280 entryp = chxj_apply_convrule(r, dconf->convrules);
1282 post_data = apr_pstrdup(pool, "");
1283 if (ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK) == OK) {
1284 if (ap_should_client_block(r)) {
1285 while (post_data_len < CHXJ_POST_MAX) {
1288 int read_bytes = ap_get_client_block(r, buffer, BUFSZ-1);
1289 if (read_bytes<=0) {
1292 buffer[read_bytes] = '\0';
1293 post_data = apr_pstrcat(pool, post_data, buffer, NULL);
1294 post_data_len += read_bytes;
1303 if (post_data_len > 0) {
1304 post_data = chxj_input_convert(r, (const char**)&post_data, (apr_size_t*)&post_data_len, entryp, spec);
1305 DBG(r, "(in:exchange)POSTDATA:[%s]", post_data);
1309 if (dconf->forward_url_base) {
1310 url_path = apr_psprintf(pool, "%s%s", dconf->forward_url_base, r->uri);
1313 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);
1316 url_path = apr_pstrcat(pool, url_path, "?", r->args, NULL);
1318 DBG(r, "==> new url_path:[%s]", url_path);
1321 apr_table_setn(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP, r->connection->remote_ip);
1322 apr_table_unset(r->headers_in, "Content-Length");
1323 apr_table_setn(r->headers_in, "Content-Length", apr_psprintf(pool, "%" APR_SIZE_T_FMT, post_data_len));
1324 response = chxj_serf_post(r, pool, url_path, post_data, post_data_len, 1, &res_len, &response_code);
1325 DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1326 DBG(r, "REQ[%X] response length:[%" APR_SIZE_T_FMT "]", (unsigned int)(apr_size_t)r, res_len);
1327 for (ii=0; ii<res_len/64; ii++) {
1328 DBG(r, "REQ[%X] response:[%.*s]", (unsigned int)(apr_size_t)r, 64, &response[ii*64]);
1330 DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1333 if ((chunked = (char *)apr_table_get(r->headers_out, "Transfer-Encoding")) != NULL) {
1334 if (strcasecmp(chunked, "chunked") == 0) {
1336 apr_table_unset(r->headers_out, "Transfer-Encoding");
1339 if (ap_is_HTTP_ERROR(response_code)) {
1340 DBG(r, "REQ[%X] end of chxj_input_handler() (HTTP-ERROR received. response code:[%d])", (unsigned int)(apr_size_t)r, response_code);
1341 return response_code;
1345 apr_pool_create(&wpool, r->pool);
1346 apr_bucket_brigade *bb;
1349 conn_rec *c = r->connection;
1351 bb = apr_brigade_create(wpool, c->bucket_alloc);
1352 e = apr_bucket_transient_create(response, res_len, c->bucket_alloc);
1353 APR_BRIGADE_INSERT_TAIL(bb, e);
1354 e = apr_bucket_eos_create(c->bucket_alloc);
1355 APR_BRIGADE_INSERT_TAIL(bb, e);
1356 if ((rv = ap_pass_brigade(r->output_filters, bb)) != APR_SUCCESS) {
1357 ERR(r, "REQ[%X] %s:%d failed ap_pass_brigade()", (unsigned int)(apr_size_t)r, APLOG_MARK);
1360 apr_brigade_cleanup(bb);
1363 DBG(r, "REQ[%X] end of chxj_input_handler()", (unsigned int)(apr_size_t)r);
1367 static mod_chxj_global_config *
1368 chxj_global_config_create(apr_pool_t *pool, server_rec *s)
1370 mod_chxj_global_config *conf;
1372 SDBG(s, "start chxj_global_config_create()");
1374 /*--------------------------------------------------------------------------*/
1375 /* allocate an own subpool which survives server restarts */
1376 /*--------------------------------------------------------------------------*/
1377 conf = (mod_chxj_global_config *)apr_palloc(pool,
1378 sizeof(mod_chxj_global_config));
1380 conf->cookie_db_lock = NULL;
1382 SDBG(s, "end chxj_global_config_create()");
1389 * initialize chxj module
1392 chxj_init_module(apr_pool_t *p,
1393 apr_pool_t *UNUSED(plog),
1394 apr_pool_t *UNUSED(ptemp),
1400 SDBG(s, "start chxj_init_module()");
1402 apr_pool_userdata_get(&user_data, CHXJ_MOD_CONFIG_KEY, s->process->pool);
1404 if (user_data == NULL) {
1407 * dummy user_data set.
1409 apr_pool_userdata_set(
1411 CHXJ_MOD_CONFIG_KEY,
1412 apr_pool_cleanup_null,
1414 SDBG(s, "end chxj_init_module()");
1418 ap_add_version_component(p, CHXJ_VERSION_PREFIX CHXJ_VERSION);
1420 if ((rv = apr_proc_mutex_create(&global_cookie_mutex, NULL, APR_LOCK_FCNTL, s->process->pool)) != APR_SUCCESS) {
1422 SERR(s, "%s:%d end chxj_init_module(). mutex create failure.(%d:%s)",APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1423 return HTTP_INTERNAL_SERVER_ERROR;
1426 SDBG(s, "end chxj_init_module()");
1433 chxj_child_init(apr_pool_t *UNUSED(p), server_rec *s)
1436 SDBG(s, "start chxj_child_init()");
1437 if ((rv = apr_proc_mutex_child_init(&global_cookie_mutex, NULL, s->process->pool)) != APR_SUCCESS) {
1439 SERR(s, "%s:%d ERROR end chxj_init_module(). mutex create failure.(%d:%s)", APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1441 SDBG(s, "end chxj_child_init()");
1446 * A set structure of each server is generated.
1452 chxj_config_server_create(apr_pool_t *p, server_rec *s)
1454 mod_chxj_global_config *gc;
1456 gc = chxj_global_config_create(p,s);
1463 chxj_translate_name(request_rec *r)
1465 DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1466 DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1467 DBG(r, "REQ[%X] START REQUEST (uri:[%s] args:[%s])", (unsigned int)(apr_size_t)r, r->unparsed_uri, r->args ? r->args : "");
1468 DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1469 DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1470 return chxj_trans_name(r);
1475 chxj_insert_filter(request_rec *r)
1479 mod_chxj_config *dconf;
1480 chxjconvrule_entry *entryp;
1485 DBG(r, "start chxj_insert_filter()");
1487 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1489 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
1491 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
1493 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
1494 DBG(r, "detect multipart/form-data ==> no target");
1498 spec = chxj_specified_device(r, user_agent);
1499 entryp = chxj_apply_convrule(r, dconf->convrules);
1501 DBG(r, "end chxj_insert_filter()");
1504 ctx = apr_palloc(r->pool, sizeof(*ctx));
1505 memset(ctx, 0, sizeof(*ctx));
1506 if ((rv = apr_pool_create(&ctx->pool, r->pool)) != APR_SUCCESS) {
1507 ERR(r, "failed: new pool create. rv:[%d]", rv);
1510 ctx->entryp = entryp;
1512 ctx->buffer = apr_palloc(ctx->pool, 1);
1515 if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
1520 switch(spec->html_spec_type) {
1521 case CHXJ_SPEC_Chtml_1_0:
1522 case CHXJ_SPEC_Chtml_2_0:
1523 case CHXJ_SPEC_Chtml_3_0:
1524 case CHXJ_SPEC_Chtml_4_0:
1525 case CHXJ_SPEC_Chtml_5_0:
1526 case CHXJ_SPEC_Chtml_6_0:
1527 case CHXJ_SPEC_Chtml_7_0:
1528 case CHXJ_SPEC_XHtml_Mobile_1_0:
1529 case CHXJ_SPEC_Hdml:
1530 case CHXJ_SPEC_Jhtml:
1531 case CHXJ_SPEC_Jxhtml:
1539 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
1540 ap_add_output_filter("chxj_output_filter", ctx, r, r->connection);
1541 DBG(r, "added Output Filter");
1544 DBG(r, "end chxj_insert_filter()");
1549 * The hook is registered.
1554 chxj_register_hooks(apr_pool_t *UNUSED(p))
1556 ap_hook_post_config(chxj_init_module,
1559 APR_HOOK_REALLY_FIRST);
1560 ap_hook_child_init(chxj_child_init,
1563 APR_HOOK_REALLY_FIRST);
1564 ap_register_output_filter (
1565 "chxj_output_filter",
1569 ap_hook_insert_filter(chxj_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
1570 ap_hook_handler(chxj_img_conv_format_handler, NULL, NULL, APR_HOOK_MIDDLE);
1571 ap_hook_handler(chxj_qr_code_handler, NULL, NULL, APR_HOOK_MIDDLE);
1572 ap_hook_handler(chxj_input_handler, NULL, NULL, APR_HOOK_MIDDLE);
1573 ap_hook_translate_name(chxj_translate_name, NULL, NULL, APR_HOOK_MIDDLE);
1574 ap_hook_fixups(chxj_headers_fixup, NULL, NULL, APR_HOOK_FIRST);
1579 * A set structure according to the directory is generated.
1585 chxj_create_per_dir_config(apr_pool_t *p, char *arg)
1587 mod_chxj_config *conf;
1589 conf = apr_pcalloc(p, sizeof(mod_chxj_config));
1590 conf->device_data_file = NULL;
1591 conf->devices = NULL;
1592 conf->emoji_data_file = NULL;
1594 conf->emoji_tail = NULL;
1595 conf->image = CHXJ_IMG_NONE;
1596 conf->image_cache_dir = apr_psprintf(p, "%s",DEFAULT_IMAGE_CACHE_DIR);
1597 conf->image_cache_limit = 0;
1598 conf->server_side_encoding = NULL;
1599 conf->cookie_db_dir = NULL;
1600 conf->cookie_timeout = 0;
1601 conf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
1602 conf->cookie_lazy_mode = 0;
1603 #if defined(USE_MYSQL_COOKIE)
1604 memset((void *)&conf->mysql, 0, sizeof(mysql_t));
1605 conf->mysql.port = MYSQL_PORT;
1606 conf->mysql.host = NULL;
1608 #if defined(USE_MEMCACHE_COOKIE)
1609 memset((void *)&conf->memcache, 0, sizeof(memcache_t));
1610 conf->memcache.host = NULL;
1611 conf->memcache.port = 0;
1613 conf->forward_url_base = NULL;
1614 conf->forward_server_ip = NULL;
1620 conf->dir = apr_pcalloc(p, strlen(arg)+1);
1621 memset(conf->dir, 0, strlen(arg)+1);
1622 strcpy(conf->dir, arg);
1624 conf->convrules = apr_array_make(p, 2, sizeof(chxjconvrule_entry));
1626 /* Default is copyleft */
1627 conf->image_copyright = NULL;
1634 * Merge per-directory CHXJ configurations
1637 chxj_merge_per_dir_config(apr_pool_t *p, void *basev, void *addv)
1639 mod_chxj_config *base;
1640 mod_chxj_config *add;
1641 mod_chxj_config *mrg;
1643 base = (mod_chxj_config *)basev;
1644 add = (mod_chxj_config *)addv;
1645 mrg = (mod_chxj_config *)apr_palloc(p, sizeof(mod_chxj_config));
1647 mrg->device_data_file = NULL;
1648 mrg->devices = NULL;
1649 mrg->emoji_data_file = NULL;
1650 mrg->image = CHXJ_IMG_NONE;
1651 mrg->image_cache_dir = NULL;
1652 mrg->image_copyright = NULL;
1653 mrg->image_cache_limit = 0;
1655 mrg->emoji_tail = NULL;
1656 mrg->new_line_type = NLTYPE_NIL;
1657 mrg->forward_url_base = NULL;
1658 mrg->forward_server_ip = NULL;
1660 mrg->dir = apr_pstrdup(p, add->dir);
1662 if (! add->device_data_file) {
1663 mrg->devices = base->devices;
1664 mrg->device_data_file = apr_pstrdup(p, base->device_data_file);
1667 mrg->devices = add->devices;
1668 mrg->device_data_file = apr_pstrdup(p, add->device_data_file);
1671 if (! add->emoji_data_file) {
1672 mrg->emoji = base->emoji;
1673 mrg->emoji_tail = base->emoji_tail;
1674 mrg->emoji_data_file = apr_pstrdup(p, base->emoji_data_file);
1677 mrg->emoji = add->emoji;
1678 mrg->emoji_tail = add->emoji_tail;
1679 mrg->emoji_data_file = apr_pstrdup(p, add->emoji_data_file);
1682 if (add->image == CHXJ_IMG_NONE) {
1683 mrg->image = base->image;
1686 mrg->image = add->image;
1689 if (strcasecmp(add->image_cache_dir ,DEFAULT_IMAGE_CACHE_DIR)==0) {
1690 mrg->image_cache_dir = apr_pstrdup(p, base->image_cache_dir);
1693 mrg->image_cache_dir = apr_pstrdup(p, add->image_cache_dir);
1696 if (add->image_cache_limit) {
1697 mrg->image_cache_limit = add->image_cache_limit;
1700 mrg->image_cache_limit = base->image_cache_limit;
1703 if (add->image_copyright)
1704 mrg->image_copyright = apr_pstrdup(p, add->image_copyright);
1706 mrg->image_copyright = apr_pstrdup(p, base->image_copyright);
1708 if (add->server_side_encoding) {
1709 mrg->server_side_encoding = apr_pstrdup(p, add->server_side_encoding);
1712 if (base->server_side_encoding) {
1713 mrg->server_side_encoding = apr_pstrdup(p, base->server_side_encoding);
1716 mrg->server_side_encoding = apr_pstrdup(p, DEFAULT_SERVER_SIDE_ENCODING);
1719 mrg->convrules = apr_array_append(p, add->convrules, base->convrules);
1721 if (add->cookie_db_dir) {
1722 mrg->cookie_db_dir = apr_pstrdup(p, add->cookie_db_dir);
1725 if (base->cookie_db_dir) {
1726 mrg->cookie_db_dir = apr_pstrdup(p, base->cookie_db_dir);
1729 mrg->cookie_db_dir = NULL;
1732 if (add->cookie_timeout) {
1733 mrg->cookie_timeout = add->cookie_timeout;
1736 if (base->cookie_db_dir) {
1737 mrg->cookie_timeout = base->cookie_timeout;
1740 mrg->cookie_timeout = 0;
1743 #if defined(USE_MYSQL_COOKIE)
1744 if (add->mysql.host) {
1745 mrg->mysql.host = apr_pstrdup(p, add->mysql.host);
1747 else if (base->mysql.host) {
1748 mrg->mysql.host = apr_pstrdup(p, base->mysql.host);
1751 mrg->mysql.host = NULL;
1753 if (add->mysql.port) {
1754 mrg->mysql.port = add->mysql.port;
1756 else if (base->mysql.port) {
1757 mrg->mysql.port = base->mysql.port;
1760 mrg->mysql.port = 0;
1763 if (add->mysql.database) {
1764 mrg->mysql.database = apr_pstrdup(p, add->mysql.database);
1766 else if (base->mysql.database) {
1767 mrg->mysql.database = apr_pstrdup(p, base->mysql.database);
1770 mrg->mysql.database = NULL;
1773 if (add->mysql.username) {
1774 mrg->mysql.username = apr_pstrdup(p, add->mysql.username);
1776 else if (base->mysql.username) {
1777 mrg->mysql.username = apr_pstrdup(p, base->mysql.username);
1780 mrg->mysql.username = NULL;
1783 if (add->mysql.password) {
1784 mrg->mysql.password = apr_pstrdup(p, add->mysql.password);
1786 else if (base->mysql.password) {
1787 mrg->mysql.password = apr_pstrdup(p, base->mysql.password);
1790 mrg->mysql.password = NULL;
1793 if (add->mysql.tablename) {
1794 mrg->mysql.tablename = apr_pstrdup(p, add->mysql.tablename);
1796 else if (base->mysql.tablename) {
1797 mrg->mysql.tablename = apr_pstrdup(p, base->mysql.tablename);
1800 mrg->mysql.tablename = NULL;
1803 if (add->mysql.socket_path) {
1804 mrg->mysql.socket_path = apr_pstrdup(p, add->mysql.socket_path);
1806 else if (base->mysql.socket_path) {
1807 mrg->mysql.socket_path = apr_pstrdup(p, base->mysql.socket_path);
1810 mrg->mysql.socket_path = NULL;
1813 if (add->mysql.charset) {
1814 mrg->mysql.charset = apr_pstrdup(p, add->mysql.charset);
1816 else if (base->mysql.charset) {
1817 mrg->mysql.charset = apr_pstrdup(p, base->mysql.charset);
1820 mrg->mysql.charset = NULL;
1823 #if defined(USE_MEMCACHE_COOKIE)
1824 if (add->memcache.host) {
1825 mrg->memcache.host = apr_pstrdup(p, add->memcache.host);
1827 else if (base->memcache.host) {
1828 mrg->memcache.host = apr_pstrdup(p, base->memcache.host);
1831 mrg->memcache.host = NULL;
1833 if (add->memcache.port) {
1834 mrg->memcache.port = add->memcache.port;
1836 else if (base->memcache.port) {
1837 mrg->memcache.port = base->memcache.port;
1840 mrg->memcache.port = 0;
1843 if (add->cookie_store_type) {
1844 mrg->cookie_store_type = add->cookie_store_type;
1846 else if (base->cookie_store_type) {
1847 mrg->cookie_store_type = base->cookie_store_type;
1850 mrg->cookie_store_type = COOKIE_STORE_TYPE_NONE;
1852 if (add->cookie_lazy_mode) {
1853 mrg->cookie_lazy_mode = add->cookie_lazy_mode;
1855 else if (base->cookie_lazy_mode) {
1856 mrg->cookie_lazy_mode = base->cookie_lazy_mode;
1859 mrg->cookie_lazy_mode = 0;
1861 if (add->new_line_type) {
1862 mrg->new_line_type = add->new_line_type;
1864 else if (base->new_line_type) {
1865 mrg->new_line_type = base->new_line_type;
1868 mrg->new_line_type = NLTYPE_NIL;
1871 if (add->forward_url_base) {
1872 mrg->forward_url_base = add->forward_url_base;
1874 else if (base->forward_url_base) {
1875 mrg->forward_url_base = base->forward_url_base;
1882 chxj_command_parse_take5(
1895 for (;*strp == ' '||*strp == '\t'; strp++) ;
1905 for (; *strp != '\0'; strp++) {
1906 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1907 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1912 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1913 || (isquoted && *strp == '"'))
1927 for (;*strp == ' '||*strp == '\t'; strp++) ;
1936 for (; *strp != '\0'; strp++) {
1937 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1938 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1943 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1944 || (isquoted && *strp == '"'))
1957 for (;*strp == ' '||*strp == '\t'; strp++);
1965 for (; *strp != '\0'; strp++) {
1966 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1967 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1972 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1973 || (isquoted && *strp == '"'))
1985 for (;*strp == ' '||*strp == '\t'; strp++);
1993 for (; *strp != '\0'; strp++) {
1994 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1995 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2000 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2001 || (isquoted && *strp == '"'))
2012 for (;*strp == ' '||*strp == '\t'; strp++);
2020 for (; *strp != '\0'; strp++) {
2021 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2022 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2027 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2028 || (isquoted && *strp == '"'))
2038 * The device definition file is loaded.
2040 * @param arg [i] The name of the device definition file is specified.
2041 * @param mconfig [i/o] The pointer to a set structure is specified.
2045 cmd_load_device_data(cmd_parms *parms, void *mconfig, const char *arg)
2047 mod_chxj_config *conf;
2052 if (strlen(arg) > 256)
2053 return "mod_chxj: device data filename too long.";
2055 conf = (mod_chxj_config *)mconfig;
2056 conf->device_data_file = apr_pstrdup(parms->pool, arg);
2058 qs_init_malloc(&doc);
2059 qs_init_root_node(&doc);
2061 qs_parse_file((Doc *)&doc, (const char *)arg);
2062 chxj_load_device_data(&doc,parms->pool, conf);
2063 qs_all_free(&doc, QX_LOGMARK);
2070 * Device definition information is loaded.
2073 * @param arg [i] The name of the device definition file is specified.
2074 * @param mconfig [i/o] The pointer to a set structure is specified.
2078 cmd_load_emoji_data(cmd_parms *parms, void *mconfig, const char *arg)
2080 mod_chxj_config *conf;
2087 if (strlen(arg) > 256)
2088 return "mod_chxj: emoji data filename too long.";
2090 conf = (mod_chxj_config *)mconfig;
2091 conf->emoji_data_file = apr_pstrdup(parms->pool, arg);
2092 qs_init_malloc(&doc);
2093 qs_init_root_node(&doc);
2095 qs_parse_file((Doc *)&doc, (const char *)arg);
2097 rtn = chxj_load_emoji_data(&doc,parms->pool, conf);
2099 qs_all_free(&doc, QX_LOGMARK);
2107 cmd_set_image_engine(cmd_parms * UNUSED(parms), void *mconfig, const char *arg)
2109 mod_chxj_config *conf;
2114 if (strlen(arg) > 256)
2115 return "image uri is too long.";
2117 conf = (mod_chxj_config*)mconfig;
2118 if (strcasecmp("ON", arg) == 0) {
2119 conf->image = CHXJ_IMG_ON;
2122 conf->image = CHXJ_IMG_OFF;
2130 cmd_set_image_cache_dir(cmd_parms *parms, void *mconfig, const char *arg)
2132 mod_chxj_config *conf;
2137 if (strlen(arg) > 256)
2138 return "cache dir name is too long.";
2140 conf = (mod_chxj_config *)mconfig;
2141 conf->image_cache_dir = apr_pstrdup(parms->pool, arg);
2148 cmd_set_image_cache_limit(cmd_parms *parms, void *mconfig, const char *arg)
2150 mod_chxj_config *conf;
2155 if (strlen(arg) > IMAGE_CACHE_LIMIT_FMT_LEN)
2156 return "cache size is too long.";
2158 conf = (mod_chxj_config *)mconfig;
2161 * I use strtol function because strtoul is not portable function.
2163 conf->image_cache_limit = (unsigned long)strtol(arg, NULL, 10);
2166 return apr_psprintf(parms->pool, "ChxjImageCacheLimit invalid value [%s] errno:[%d]", arg, errno);
2168 return apr_psprintf(parms->pool, "ChxjImageCacheLimit Out of range [%s] errno:[%d]", arg, errno);
2177 cmd_set_image_copyright(cmd_parms *parms, void *mconfig, const char *arg)
2179 mod_chxj_config *conf;
2184 if (strlen(arg) > 256)
2185 return "Copyright Flag is too long.";
2187 conf = (mod_chxj_config *)mconfig;
2188 conf->image_copyright = apr_pstrdup(parms->pool, arg);
2195 cmd_convert_rule(cmd_parms *cmd, void *mconfig, const char *arg)
2199 mod_chxj_config *dconf;
2200 chxjconvrule_entry *newrule;
2210 dconf = (mod_chxj_config *)mconfig;
2212 if (strlen(arg) > 4096)
2213 return "mod_chxj: ChxjConvertRule: is too long.";
2215 dconf = (mod_chxj_config *)mconfig;
2216 if (dconf->convrules == NULL)
2217 dconf->convrules = apr_array_make(cmd->pool,
2219 sizeof(chxjconvrule_entry));
2221 newrule = apr_array_push(dconf->convrules);
2224 newrule->action = 0;
2226 if (chxj_command_parse_take5(arg, &prm1, &prm2, &prm3, &prm4, &prm5))
2227 return "ChxjConvertRule: bad argument line";
2229 newrule->pattern = apr_pstrdup(cmd->pool, prm1);
2233 if ((action = apr_strtok(prm2, ",", &pstate)) == NULL)
2239 if (strcasecmp(CONVRULE_ENGINE_ON_CMD, action) == 0) {
2240 newrule->action |= CONVRULE_ENGINE_ON_BIT;
2243 if (strcasecmp(CONVRULE_ENGINE_OFF_CMD, action) == 0) {
2244 newrule->action |= CONVRULE_ENGINE_OFF_BIT;
2250 if (strcasecmp(CONVRULE_COOKIE_ON_CMD, action) == 0) {
2251 newrule->action |= CONVRULE_COOKIE_ON_BIT;
2257 if (strcasecmp(CONVRULE_JRCONV_OFF_CMD, action) == 0) {
2258 newrule->action |= CONVRULE_JRCONV_OFF_BIT;
2264 if (strcasecmp(CONVRULE_QSCONV_OFF_CMD, action) == 0) {
2265 newrule->action |= CONVRULE_QSCONV_OFF_BIT;
2271 if (strcasecmp(CONVRULE_Z2H_ON_CMD, action) == 0) {
2272 newrule->action |= CONVRULE_Z2H_ON_BIT;
2275 if (strcasecmp(CONVRULE_Z2H_OFF_CMD, action) == 0) {
2276 newrule->action |= CONVRULE_Z2H_OFF_BIT;
2279 if (strcasecmp(CONVRULE_Z2H_ALPHA_ON_CMD, action) == 0) {
2280 newrule->action |= CONVRULE_Z2H_ALPHA_ON_BIT;
2283 if (strcasecmp(CONVRULE_Z2H_ALPHA_OFF_CMD, action) == 0) {
2284 newrule->action |= CONVRULE_Z2H_ALPHA_OFF_BIT;
2287 if (strcasecmp(CONVRULE_Z2H_NUM_ON_CMD, action) == 0) {
2288 newrule->action |= CONVRULE_Z2H_NUM_ON_BIT;
2291 if (strcasecmp(CONVRULE_Z2H_NUM_OFF_CMD, action) == 0) {
2292 newrule->action |= CONVRULE_Z2H_NUM_OFF_BIT;
2295 if (strcasecmp(CONVRULE_Z2H_ALL_ON_CMD, action) == 0) {
2296 newrule->action |= CONVRULE_Z2H_ON_BIT | CONVRULE_Z2H_ALPHA_ON_BIT | CONVRULE_Z2H_NUM_ON_BIT;
2299 if (strcasecmp(CONVRULE_Z2H_NUM_OFF_CMD, action) == 0) {
2300 newrule->action |= CONVRULE_Z2H_OFF_BIT | CONVRULE_Z2H_ALPHA_OFF_BIT | CONVRULE_Z2H_NUM_OFF_BIT;
2311 newrule->flags |= CONVRULE_FLAG_NOTMATCH;
2315 mode = AP_REG_EXTENDED;
2316 if ((regexp = ap_pregcomp((apr_pool_t *)cmd->pool, (const char *)pp, mode)) == NULL)
2317 return "RewriteRule: cannot compile regular expression ";
2319 newrule->regexp = regexp;
2321 newrule->encoding = apr_pstrdup(cmd->pool, prm3);
2323 newrule->encoding = apr_pstrdup(cmd->pool, "none");
2325 newrule->pc_flag = CONVRULE_PC_FLAG_OFF_BIT;
2327 if (strcasecmp(CONVRULE_PC_FLAG_ON_CMD, prm4) == 0)
2328 newrule->pc_flag = CONVRULE_PC_FLAG_ON_BIT;
2330 newrule->user_agent = NULL;
2332 newrule->user_agent = apr_pstrdup(cmd->pool, prm5);
2344 mod_chxj_config *dconf;
2347 if (strlen(arg) > 4096)
2348 return "mod_chxj: ChxjCookieDir is too long.";
2350 dconf = (mod_chxj_config *)mconfig;
2352 dconf->cookie_db_dir = apr_pstrdup(cmd->pool, arg);
2359 cmd_set_cookie_timeout(
2360 cmd_parms *UNUSED(cmd),
2364 mod_chxj_config *dconf;
2366 if (strlen(arg) > 4096)
2367 return "mod_chxj: ChxjCookieTimeout is too long.";
2369 if (chxj_chk_numeric(arg) != 0)
2370 return "mod_chxj: ChxjCookieTimeout is not numeric.";
2372 dconf = (mod_chxj_config *)mconfig;
2374 dconf->cookie_timeout = atoi(arg);
2380 #if defined(USE_MYSQL_COOKIE)
2382 cmd_set_cookie_mysql_database(
2387 mod_chxj_config *dconf;
2389 if (strlen(arg) > 255)
2390 return "mod_chxj: ChxjCookieMysqlDatabase is too long.";
2392 dconf = (mod_chxj_config *)mconfig;
2394 dconf->mysql.database = apr_pstrdup(cmd->pool, arg);
2401 cmd_set_cookie_mysql_username(
2406 mod_chxj_config *dconf;
2408 if (strlen(arg) > 255)
2409 return "mod_chxj: ChxjCookieMysqlUsername is too long.";
2411 dconf = (mod_chxj_config *)mconfig;
2413 dconf->mysql.username = apr_pstrdup(cmd->pool, arg);
2420 cmd_set_cookie_mysql_password(
2425 mod_chxj_config *dconf;
2427 if (strlen(arg) > 255)
2428 return "mod_chxj: ChxjCookieMysqlPassword is too long.";
2430 dconf = (mod_chxj_config *)mconfig;
2432 dconf->mysql.password = apr_pstrdup(cmd->pool, arg);
2439 cmd_set_cookie_mysql_table_name(
2444 mod_chxj_config *dconf;
2446 if (strlen(arg) > 255)
2447 return "mod_chxj: ChxjCookieMysqlTableName is too long.";
2449 dconf = (mod_chxj_config *)mconfig;
2451 dconf->mysql.tablename = apr_pstrdup(cmd->pool, arg);
2457 cmd_set_cookie_mysql_port(
2458 cmd_parms *UNUSED(cmd),
2462 mod_chxj_config *dconf;
2464 if (strlen(arg) > 255)
2465 return "mod_chxj: ChxjCookieMysqlPort is too long.";
2467 dconf = (mod_chxj_config *)mconfig;
2469 if (chxj_chk_numeric(arg) != 0)
2470 return "mod_chxj: ChxjCookieMysqlPort is not numeric.";
2472 dconf = (mod_chxj_config *)mconfig;
2474 dconf->mysql.port = chxj_atoi(arg);
2481 cmd_set_cookie_mysql_host(
2486 mod_chxj_config *dconf;
2488 if (strlen(arg) > 255)
2489 return "mod_chxj: ChxjCookieMysqlHost is too long.";
2491 dconf = (mod_chxj_config *)mconfig;
2493 dconf->mysql.host = apr_pstrdup(cmd->pool, arg);
2500 cmd_set_cookie_mysql_socket_path(
2505 mod_chxj_config *dconf;
2507 if (strlen(arg) > 4096)
2508 return "mod_chxj: ChxjCookieMysqlSocketPath is too long.";
2510 dconf = (mod_chxj_config *)mconfig;
2512 dconf->mysql.socket_path = apr_pstrdup(cmd->pool, arg);
2519 cmd_set_cookie_mysql_charset(
2524 mod_chxj_config *dconf;
2526 if (strlen(arg) > 255)
2527 return "mod_chxj: ChxjCookieMysqlCharset is too long.";
2529 dconf = (mod_chxj_config *)mconfig;
2531 dconf->mysql.charset = apr_pstrdup(cmd->pool, arg);
2536 #if defined(USE_MEMCACHE_COOKIE)
2538 cmd_set_cookie_memcache_port(
2539 cmd_parms *UNUSED(cmd),
2543 mod_chxj_config *dconf;
2545 if (strlen(arg) > 255)
2546 return "mod_chxj: ChxjCookieMemcachePort is too long.";
2548 dconf = (mod_chxj_config *)mconfig;
2550 if (chxj_chk_numeric(arg) != 0)
2551 return "mod_chxj: ChxjCookieMemcachePort is not numeric.";
2553 dconf = (mod_chxj_config *)mconfig;
2555 dconf->memcache.port = (apr_port_t)chxj_atoi(arg);
2562 cmd_set_cookie_memcache_host(
2567 mod_chxj_config *dconf;
2569 if (strlen(arg) > 255)
2570 return "mod_chxj: ChxjCookieMemcacheHost is too long.";
2572 dconf = (mod_chxj_config *)mconfig;
2574 dconf->memcache.host = apr_pstrdup(cmd->pool, arg);
2581 cmd_set_cookie_lazy_mode(
2582 cmd_parms *UNUSED(cmd),
2586 mod_chxj_config *dconf;
2588 if (strlen(arg) > 255)
2589 return "mod_chxj: ChxjCookieLazyMode is too long.";
2591 dconf = (mod_chxj_config *)mconfig;
2593 if (strcasecmp("TRUE",arg) == 0) {
2594 dconf->cookie_lazy_mode = COOKIE_LAZY_ON;
2597 dconf->cookie_lazy_mode = COOKIE_LAZY_OFF;
2604 cmd_set_cookie_store_type(
2605 cmd_parms *UNUSED(cmd),
2609 mod_chxj_config *dconf;
2611 if (strlen(arg) > 255)
2612 return "mod_chxj: ChxjCookieStoreType is too long.";
2614 dconf = (mod_chxj_config *)mconfig;
2616 if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_DBM, arg) == 0) {
2617 dconf->cookie_store_type = COOKIE_STORE_TYPE_DBM;
2619 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MYSQL, arg) == 0) {
2620 dconf->cookie_store_type = COOKIE_STORE_TYPE_MYSQL;
2622 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MEMCACHE, arg) == 0) {
2623 dconf->cookie_store_type = COOKIE_STORE_TYPE_MEMCACHE;
2626 dconf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
2633 cmd_set_forward_url_base(
2638 mod_chxj_config *dconf;
2640 if (strlen(arg) > 255)
2641 return "mod_chxj: ChxjForwardUrlBase is too long.";
2643 dconf = (mod_chxj_config *)mconfig;
2645 dconf->forward_url_base = apr_pstrdup(cmd->pool, arg);
2651 cmd_set_forward_server_ip(
2656 mod_chxj_config *dconf;
2658 if (strlen(arg) > 255)
2659 return "mod_chxj: ChxjForwardServerIp is too long.";
2661 dconf = (mod_chxj_config *)mconfig;
2663 dconf->forward_server_ip = apr_pstrdup(cmd->pool, arg);
2669 cmd_set_new_line_type(
2670 cmd_parms *UNUSED(cmd),
2674 mod_chxj_config *dconf;
2675 if (strlen(arg) > 255)
2676 return "mod_chxj: ChxjNewLineType is too long.";
2678 dconf = (mod_chxj_config *)mconfig;
2680 if (strcasecmp(CHXJ_NEW_LINE_TYPE_CRLF, arg) == 0) {
2681 dconf->new_line_type = NLTYPE_CRLF;
2683 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_LF, arg) == 0) {
2684 dconf->new_line_type = NLTYPE_LF;
2686 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_CR, arg) == 0) {
2687 dconf->new_line_type = NLTYPE_CR;
2689 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_NONE, arg) == 0) {
2690 dconf->new_line_type = NLTYPE_NONE;
2693 return "mod_chxj: invalid value (ChxjNewLineType)";
2699 static const command_rec cmds[] = {
2701 "ChxjLoadDeviceData",
2702 cmd_load_device_data,
2705 "Load Device Data"),
2707 "ChxjLoadEmojiData",
2708 cmd_load_emoji_data,
2714 cmd_set_image_engine,
2717 "Convert Target URI"),
2719 "ChxjImageCacheDir",
2720 cmd_set_image_cache_dir,
2723 "Image Cache Directory"),
2725 "ChxjImageCacheLimit",
2726 cmd_set_image_cache_limit,
2729 "Image Cache Limit"),
2731 "ChxjImageCopyright",
2732 cmd_set_image_copyright,
2741 "an URL-applied regexp-pattern and a substitution URL"),
2747 "save cookie.db directory."),
2749 "ChxjCookieTimeout",
2750 cmd_set_cookie_timeout,
2753 "The compulsion time-out time of the cookie is specified. "),
2755 "ChxjCookieStoreType",
2756 cmd_set_cookie_store_type,
2759 "It specifies preserving of the cookie ahead. (DBM/MYSQL/MEMCACHE)"),
2761 "ChxjCookieLazyMode",
2762 cmd_set_cookie_lazy_mode,
2765 "OneTimeID is negligently done. (TRUE/FALSE)"),
2766 #if defined(USE_MYSQL_COOKIE)
2768 "ChxjCookieMysqlHost",
2769 cmd_set_cookie_mysql_host,
2772 "The MySQL database host used by saving Cookie"),
2774 "ChxjCookieMysqlPort",
2775 cmd_set_cookie_mysql_port,
2778 "The MySQL database port used by saving Cookie"),
2780 "ChxjCookieMysqlDatabase",
2781 cmd_set_cookie_mysql_database,
2784 "The MySQL database name used by saving Cookie"),
2786 "ChxjCookieMysqlUsername",
2787 cmd_set_cookie_mysql_username,
2790 "The MySQL username used by saving Cookie"),
2792 "ChxjCookieMysqlPassword",
2793 cmd_set_cookie_mysql_password,
2796 "The MySQL password used by saving Cookie"),
2798 "ChxjCookieMysqlTableName",
2799 cmd_set_cookie_mysql_table_name,
2802 "The MySQL table name used by saving Cookie"),
2804 "ChxjCookieMysqlSocketPath",
2805 cmd_set_cookie_mysql_socket_path,
2808 "The MySQL socket path used by saving Cookie"),
2810 "ChxjCookieMysqlCharset",
2811 cmd_set_cookie_mysql_charset,
2814 "The MySQL charset used by saving Cookie"),
2816 #if defined(USE_MEMCACHE_COOKIE)
2818 "ChxjCookieMemcacheHost",
2819 cmd_set_cookie_memcache_host,
2822 "The Memcached host used by saving Cookie"),
2824 "ChxjCookieMemcachePort",
2825 cmd_set_cookie_memcache_port,
2828 "The Memcached port used by saving Cookie"),
2832 cmd_set_new_line_type,
2835 "HTML new line type (NONE|CRLF|LF|CR). default is CRLF"),
2837 "ChxjForwardUrlBase",
2838 cmd_set_forward_url_base,
2841 "The forward url base(default: {request protocol}://{this server}:{this server port}"),
2843 "ChxjForwardServerIp",
2844 cmd_set_forward_server_ip,
2847 "The forward server ip(default: this server ip)"),
2852 /*----------------------------------------------------------------------------*/
2853 /* Dispatch list for API hooks */
2854 /*----------------------------------------------------------------------------*/
2855 module AP_MODULE_DECLARE_DATA chxj_module = {
2856 STANDARD20_MODULE_STUFF,
2857 chxj_create_per_dir_config, /* create per-dir config structures */
2858 chxj_merge_per_dir_config, /* merge per-dir config structures */
2859 chxj_config_server_create, /* create per-server config structures */
2860 NULL, /* merge per-server config structures */
2861 cmds, /* table of config file commands */
2862 chxj_register_hooks /* register hooks */