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);
148 static void s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie);
149 static void s_clear_cookie_header(request_rec *r, device_table *spec);
152 * Only when User-Agent is specified, the User-Agent header is camouflaged.
157 chxj_headers_fixup(request_rec *r)
159 mod_chxj_config* dconf;
160 chxjconvrule_entry* entryp;
166 DBG(r, "REQ[%X] start chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
168 DBG(r, "REQ[%X] detect internal redirect.", (unsigned int)(apr_size_t)r);
169 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
173 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
175 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
176 spec = chxj_specified_device(r, user_agent);
178 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
180 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
181 DBG(r, "REQ[%X] detect multipart/form-data ==> no target", (unsigned int)(apr_size_t)r);
182 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
185 if (r->method_number == M_POST) {
186 if (!apr_table_get(r->headers_in, "X-Chxj-Forward")) {
187 s_clear_cookie_header(r, spec);
191 s_clear_cookie_header(r, spec);
194 switch(spec->html_spec_type) {
195 case CHXJ_SPEC_Chtml_1_0:
196 case CHXJ_SPEC_Chtml_2_0:
197 case CHXJ_SPEC_Chtml_3_0:
198 case CHXJ_SPEC_Chtml_4_0:
199 case CHXJ_SPEC_Chtml_5_0:
200 case CHXJ_SPEC_Chtml_6_0:
201 case CHXJ_SPEC_Chtml_7_0:
202 case CHXJ_SPEC_XHtml_Mobile_1_0:
204 case CHXJ_SPEC_Jhtml:
205 case CHXJ_SPEC_Jxhtml:
206 entryp = chxj_apply_convrule(r, dconf->convrules);
208 DBG(r, "REQ[%X] end chxj_headers_fixup() (no pattern)", (unsigned int)(apr_size_t)r);
211 if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
212 DBG(r, "REQ[%X] end chxj_headers_fixup() (engine off)", (unsigned int)(apr_size_t)r);
216 apr_table_setn(r->headers_in,
217 CHXJ_HTTP_USER_AGENT,
220 if (entryp->user_agent)
221 apr_table_setn(r->headers_in,
225 chxj_convert_input_header(r,entryp);
230 DBG(r, "REQ[%X] end chxj_headers_fixup() (not mobile)", (unsigned int)(apr_size_t)r);
236 if (r->method_number == M_POST) {
237 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
238 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);
239 r->proxyreq = PROXYREQ_NONE;
240 r->handler = apr_psprintf(r->pool, "chxj-input-handler");
243 char *client_ip = (char *)apr_table_get(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP);
245 apr_sockaddr_t *address = NULL;
246 apr_status_t rv = apr_sockaddr_info_get(&address, ap_get_server_name(r), APR_UNSPEC, ap_get_server_port(r), 0, r->pool);
247 if (rv != APR_SUCCESS) {
249 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));
250 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
254 if (dconf->forward_server_ip) {
255 addr = dconf->forward_server_ip;
258 apr_sockaddr_ip_get(&addr, address);
260 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);
261 if (strcmp(addr, r->connection->remote_ip) == 0) {
262 r->connection->remote_ip = apr_pstrdup(r->connection->pool, client_ip);
264 if (! apr_table_get(r->headers_in, "Content-Length")) {
265 contentLength = (char *)apr_table_get(r->headers_in, "X-Chxj-Content-Length");
267 apr_table_set(r->headers_in, "Content-Length", contentLength);
274 chxj_add_device_env(r, spec);
276 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
283 s_clear_cookie_header(request_rec *r, device_table *spec)
285 switch(spec->html_spec_type) {
286 case CHXJ_SPEC_Chtml_1_0:
287 case CHXJ_SPEC_Chtml_2_0:
288 case CHXJ_SPEC_Chtml_3_0:
289 case CHXJ_SPEC_Chtml_4_0:
290 case CHXJ_SPEC_Chtml_5_0:
291 case CHXJ_SPEC_Chtml_6_0:
292 case CHXJ_SPEC_Chtml_7_0:
293 case CHXJ_SPEC_XHtml_Mobile_1_0:
294 case CHXJ_SPEC_Jhtml:
295 apr_table_unset(r->headers_in, "Cookie");
304 * It converts it from CHTML into XXML corresponding to each model.
307 * @param src [i] It is former HTML character string.
308 * @param len [i/o] It is length of former HTML character string.
311 chxj_convert(request_rec *r, const char **src, apr_size_t *len, device_table *spec, const char *ua, cookie_t **cookiep)
317 mod_chxj_config *dconf;
318 chxjconvrule_entry *entryp;
320 DBG(r,"REQ[%X] start of chxj_convert() input:[%.*s]", (unsigned int)(apr_size_t)r, (int)*len, *src);
321 dst = apr_pstrcat(r->pool, (char *)*src, NULL);
323 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
326 entryp = chxj_apply_convrule(r, dconf->convrules);
328 if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
329 DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
334 /*------------------------------------------------------------------------*/
335 /* get UserAgent from http header */
336 /*------------------------------------------------------------------------*/
337 if (entryp->user_agent)
338 user_agent = (char *)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
340 user_agent = (char *)apr_table_get(r->headers_in, HTTP_USER_AGENT);
342 DBG(r,"REQ[%X] User-Agent:[%s]", (unsigned int)(apr_size_t)r, user_agent);
343 DBG(r,"REQ[%X] content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
346 if ( ! STRNCASEEQ('t','T', "text/html", r->content_type, sizeof("text/html")-1)
347 && ! STRNCASEEQ('a','A', "application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)) {
348 DBG(r,"REQ[%X] no convert. content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
349 DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
353 if (ua && user_agent && strcasecmp(user_agent, ua) != 0) {
355 spec = chxj_specified_device(r, user_agent);
362 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
363 switch(spec->html_spec_type) {
364 case CHXJ_SPEC_Chtml_1_0:
365 case CHXJ_SPEC_Chtml_2_0:
366 case CHXJ_SPEC_Chtml_3_0:
367 case CHXJ_SPEC_Chtml_4_0:
368 case CHXJ_SPEC_Chtml_5_0:
369 case CHXJ_SPEC_Chtml_6_0:
370 case CHXJ_SPEC_Chtml_7_0:
371 case CHXJ_SPEC_XHtml_Mobile_1_0:
372 case CHXJ_SPEC_Jhtml:
373 cookie = chxj_save_cookie(r);
380 if (!r->header_only) {
383 if (convert_routine[spec->html_spec_type].encoder)
384 tmp = convert_routine[spec->html_spec_type].encoder(r,
388 if (convert_routine[spec->html_spec_type].converter) {
390 dst = convert_routine[spec->html_spec_type].converter(r,
398 dst = convert_routine[spec->html_spec_type].converter(r,
407 dst = chxj_conv_z2h(r, dst, len, entryp);
410 ap_set_content_length(r, *len);
413 dst = apr_psprintf(r->pool, "\n");
422 DBG(r, "REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
429 * It converts it from HEADER.
434 chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp)
446 cookie_t *cookie = NULL;
447 int no_update_flag = 0;
449 DBG(r, "REQ[%X] start chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
452 DBG(r, "REQ[%X] r->args=[null]", (unsigned int)(apr_size_t)r);
453 DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
456 urilen = strlen(r->args);
458 result = qs_alloc_zero_byte_string(r->pool);
460 buff_pre = apr_pstrdup(r->pool, r->args);
465 pair = apr_strtok(buff_pre, "&", &pstate);
471 pair_sv = apr_pstrdup(r->pool, pair);
473 name = apr_strtok(pair, "=", &vstate);
474 value = apr_strtok(NULL, "=", &vstate);
475 if (! name) continue;
476 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
477 DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
482 buff = apr_pstrdup(r->pool, r->args);
483 DBG(r, "REQ[%X] r->args=[%s]", (unsigned int)(apr_size_t)r, buff);
492 pair = apr_strtok(buff, "&", &pstate);
498 pair_sv = apr_pstrdup(r->pool, pair);
500 name = apr_strtok(pair, "=", &vstate);
501 value = apr_strtok(NULL, "=", &vstate);
502 if (! name) continue;
503 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
504 if (strlen(result) != 0)
505 result = apr_pstrcat(r->pool, result, "&", NULL);
507 if (strcasecmp(entryp->encoding, "NONE") != 0) {
512 if (value && *value != 0) {
513 value = chxj_url_decode(r->pool, value);
514 dlen = strlen(value);
515 DBG(r, "************ before encoding[%s]", value);
517 dvalue = chxj_rencoding(r, value, &dlen);
518 dvalue = chxj_url_encode(r->pool, dvalue);
520 DBG(r, "************ after encoding[%s]", dvalue);
526 if (name && *name != 0) {
527 name = chxj_url_decode(r->pool, name);
529 dname = chxj_rencoding(r, name, &dlen);
530 dname = chxj_url_encode(r->pool, dname);
536 result = apr_pstrcat(r->pool, result, dname, "=", dvalue, NULL);
539 if (strcmp(name, pair_sv) != 0)
540 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
542 result = apr_pstrcat(r->pool, result, name, NULL);
546 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
547 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
548 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
552 if (strlen(value) == 0)
555 if (strlen(result) != 0)
556 result = apr_pstrcat(r->pool, result, "&", NULL);
558 result = apr_pstrcat(r->pool, result, &name[8], "=", value, NULL);
561 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
563 apr_table_unset(r->headers_in, "Cookie");
564 DBG(r, "REQ[%X] found cookie parameter[%s]", (unsigned int)(apr_size_t)r, value);
565 DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
566 cookie_lock_t *lock = chxj_cookie_lock(r);
567 cookie = chxj_load_cookie(r, value);
568 DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
569 if (! no_update_flag && cookie) {
570 cookie = chxj_update_cookie(r, cookie);
572 chxj_cookie_unlock(r, lock);
574 if (cookie && cookie->cookie_id) {
575 if (strlen(result) != 0)
576 result = apr_pstrcat(r->pool, result, "&", NULL);
577 result = apr_pstrcat(r->pool, result, name, "=", cookie->cookie_id, NULL);
581 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
582 if (strlen(result) != 0)
583 result = apr_pstrcat(r->pool, result, "&", NULL);
584 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
587 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
588 if (! no_update_flag) {
589 result = apr_pstrcat(r->pool, result, "&_chxj_nc=true", NULL);
593 DBG(r, "REQ[%X] result r->args=[%s]", (unsigned int)(apr_size_t)r, r->args);
594 DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
600 * It converts it from POSTDATA .
603 * @param src [i] It is POSTDATA character string.
604 * @param len [i/o] It is length of former HTML character string.
611 chxjconvrule_entry *entryp)
620 cookie_t *cookie = NULL;
622 int no_update_flag = 0;
627 DBG(r, "REQ[%X] start of chxj_input_convert()", (unsigned int)(apr_size_t)r);
630 DBG(r, "REQ[%X] end of chxj_input_convert() (input is null)", (unsigned int)(apr_size_t)r);
631 return apr_pstrdup(r->pool, "");
634 apr_pool_create(&pool, r->pool);
636 s = apr_pstrdup(pool, *src);
638 buff_pre = apr_pstrdup(pool, *src);
640 result = qs_alloc_zero_byte_string(pool);
642 DBG(r, "REQ[%X] +-------------------------------------------------------------------+", (unsigned int)(apr_size_t)r);
643 DBG(r, "REQ[%X] | BEFORE input convert source |", (unsigned int)(apr_size_t)r);
644 DBG(r, "REQ[%X] +-------------------------------------------------------------------+", (unsigned int)(apr_size_t)r);
645 for (ii=0; ii<ilen-64; ii+=64) {
646 DBG(r, "REQ[%X] | [%-*.*s] |", (unsigned int)(apr_size_t)r, 64, 64, &s[ii]);
651 if (ilen >= 64 && ((ilen-64) % 64 != 0)) {
652 DBG(r, "REQ[%X] | [%-*.*s] |", (unsigned int)(apr_size_t)r, 64, 64, &s[ii]);
654 DBG(r, "REQ[%X] +--------------------------------------------------------------------+", (unsigned int)(apr_size_t)r);
659 pair = apr_strtok(buff_pre, "&", &pstate);
665 pair_sv = apr_pstrdup(pool, pair);
667 name = apr_strtok(pair, "=", &vstate);
668 value = apr_strtok(NULL, "=", &vstate);
669 if (! name) continue;
670 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
671 DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
681 pair = apr_strtok(s, "&", &pstate);
686 name = apr_strtok(pair, "=", &vstate);
687 value = apr_strtok(NULL, "=", &vstate);
688 if (! name) continue;
689 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
690 if (strlen(result) != 0)
691 result = apr_pstrcat(pool, result, "&", NULL);
693 if (strcasecmp(entryp->encoding, "NONE") != 0) {
698 if (value && *value != 0) {
699 value = chxj_url_decode(pool, value);
700 dlen = strlen(value);
701 dvalue = chxj_rencoding(r, value, &dlen);
702 dvalue = chxj_url_encode(pool, dvalue);
708 if (name && *name != 0) {
709 name = chxj_url_decode(pool, name);
711 dname = chxj_rencoding(r, name, &dlen);
712 dname = chxj_url_encode(pool, dname);
718 result = apr_pstrcat(pool, result, dname, "=", dvalue, NULL);
721 result = apr_pstrcat(pool, result, name, "=", value, NULL);
725 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
726 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
727 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
731 if (strlen(value) == 0)
734 if (strlen(result) != 0)
735 result = apr_pstrcat(pool, result, "&", NULL);
737 if (strcasecmp(entryp->encoding, "NONE") != 0 && value && strlen(value)) {
741 dlen = strlen(value);
742 value = chxj_url_decode(pool, value);
743 dvalue = chxj_rencoding(r, value, &dlen);
744 dvalue = chxj_url_encode(pool,dvalue);
745 result = apr_pstrcat(pool, result, &name[8], "=", dvalue, NULL);
749 result = apr_pstrcat(pool, result, &name[8], "=", value, NULL);
753 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
755 apr_table_unset(r->headers_in, "Cookie");
756 DBG(r, "REQ[%X] found cookie parameter[%s]", (unsigned int)(apr_size_t)r, value);
757 DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
758 cookie_lock_t *lock = chxj_cookie_lock(r);
759 cookie = chxj_load_cookie(r, value);
760 DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
761 if (! no_update_flag && cookie) {
762 cookie = chxj_update_cookie(r, cookie);
764 chxj_cookie_unlock(r, lock);
766 if (cookie && cookie->cookie_id) {
767 if (strlen(result) != 0)
768 result = apr_pstrcat(pool, result, "&", NULL);
769 result = apr_pstrcat(pool, result, name, "=", cookie->cookie_id, NULL);
773 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
774 if (strlen(result) != 0)
775 result = apr_pstrcat(pool, result, "&", NULL);
776 result = apr_pstrcat(pool, result, name, "=", value, NULL);
779 if ( strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1) == 0) {
782 dlen = strlen(value);
784 value = chxj_url_decode(pool, value);
785 dvalue = chxj_rencoding(r, value, &dlen);
786 dvalue = chxj_url_encode(pool,dvalue);
787 if (r->args && strlen(r->args) > 0) {
788 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
791 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
796 if (strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX_ENC, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1) == 0) {
799 dlen = strlen(value);
801 value = chxj_url_decode(pool, value);
802 dvalue = chxj_rencoding(r, value, &dlen);
803 dvalue = chxj_url_encode(pool,dvalue);
804 if (r->args && strlen(r->args) > 0) {
805 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
808 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
812 DBG(r, "REQ[%X] ************************ name:[%s]", (unsigned int)(apr_size_t)r, name);
814 *len = strlen(result);
815 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
816 if (! no_update_flag) {
817 result = apr_pstrcat(pool, result, "&_chxj_nc=true", NULL);
820 DBG(r, "REQ[%X] AFTER input convert result = [%s]", (unsigned int)(apr_size_t)r, result);
821 DBG(r, "REQ[%X] end chxj_input_convert()", (unsigned int)(apr_size_t)r);
828 * The received data is returned to the filter.
830 * @param f [i/o] It is a filter.
831 * @param data [i] It is data returned to the filter.
832 * @param len [i] It is length of the data returned to the filter.
835 pass_data_to_filter(ap_filter_t *f, const char *data,
838 request_rec *r = f->r;
839 conn_rec *c = r->connection;
841 apr_bucket_brigade *bb;
844 DBG(r, "REQ[%X] start pass_data_to_filter()", (unsigned int)(apr_size_t)r);
846 chxj_header_inf_clear(r);
848 bb = apr_brigade_create(r->pool, c->bucket_alloc);
849 b = apr_bucket_transient_create(data, len, c->bucket_alloc);
851 APR_BRIGADE_INSERT_TAIL(bb, b);
852 b = apr_bucket_eos_create(f->c->bucket_alloc);
853 APR_BRIGADE_INSERT_TAIL(bb, b);
855 rv = ap_pass_brigade(f->next, bb);
856 if (rv != APR_SUCCESS) {
857 DBG(r, "REQ[%X] end pass_data_to_filter() (apr_pass_brigade)", (unsigned int)(apr_size_t)r);
861 DBG(r, "REQ[%X] end pass_data_to_filter()", (unsigned int)(apr_size_t)r);
868 * It is the main loop of the output filter.
870 * @param f [i/o] It is a filter.
874 chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
880 char *user_agent = NULL;
882 mod_chxj_ctx *ctx = (mod_chxj_ctx *)f->ctx;
883 cookie_t *cookie = NULL;
884 mod_chxj_config *dconf;
885 chxjconvrule_entry *entryp = NULL;
886 device_table *spec = NULL;
890 DBG(f->r, "REQ[%X] start of chxj_output_filter()", (unsigned int)(apr_size_t)r);
893 apr_pool_create(&pool, r->pool);
895 entryp = ctx->entryp;
897 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
899 if (r->content_type) {
900 if (! STRNCASEEQ('t','T',"text/html",r->content_type, sizeof("text/html")-1)
901 && ! STRNCASEEQ('t','T',"text/xml", r->content_type, sizeof("text/xml")-1)
902 && ! STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
903 && ! (dconf->image == CHXJ_IMG_ON
904 && ! apr_table_get(r->headers_in, "CHXJ_IMG_CONV")
905 && STRNCASEEQ('i','I',"image/", r->content_type, sizeof("image/") -1)
906 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
907 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
908 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
909 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
910 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
911 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
912 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
913 || STRCASEEQ('g','G',"gif", &r->content_type[6])))) { /* GIF */
915 DBG(r, "REQ[%X] not convert content-type:[%s] dconf->image:[%d]", (unsigned int)(apr_size_t)r, r->content_type, dconf->image);
916 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
917 cookie_lock_t *lock = NULL;
918 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
919 switch(spec->html_spec_type) {
920 case CHXJ_SPEC_Chtml_1_0:
921 case CHXJ_SPEC_Chtml_2_0:
922 case CHXJ_SPEC_Chtml_3_0:
923 case CHXJ_SPEC_Chtml_4_0:
924 case CHXJ_SPEC_Chtml_5_0:
925 case CHXJ_SPEC_Chtml_6_0:
926 case CHXJ_SPEC_Chtml_7_0:
927 case CHXJ_SPEC_XHtml_Mobile_1_0:
928 case CHXJ_SPEC_Jhtml:
929 lock = chxj_cookie_lock(r);
930 cookie = chxj_save_cookie(r);
931 s_add_cookie_id_if_has_location_header(r, cookie);
932 chxj_cookie_unlock(r, lock);
938 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
939 if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
940 r->status = HTTP_MOVED_TEMPORARILY;
943 ap_pass_brigade(f->next, bb);
944 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
949 DBG(r, "REQ[%X] not convert content-type:[(null)]", (unsigned int)(apr_size_t)r);
950 ap_pass_brigade(f->next, bb);
951 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
956 for (b = APR_BRIGADE_FIRST(bb);
957 b != APR_BRIGADE_SENTINEL(bb);
958 b = APR_BUCKET_NEXT(b)) {
960 if (apr_bucket_read(b, &data, &len, APR_BLOCK_READ) == APR_SUCCESS) {
961 DBG(r, "REQ[%X] read data[%.*s]",(unsigned int)(apr_size_t)r, (int)len, data);
963 /*--------------------------------------------------------------------*/
965 /*--------------------------------------------------------------------*/
967 DBG(r, "append data start");
968 ctx = (mod_chxj_ctx *)f->ctx;
971 tmp = apr_palloc(r->pool, ctx->len);
972 memcpy(tmp, ctx->buffer, ctx->len);
974 ctx->buffer = apr_palloc(pool, ctx->len + len);
976 memcpy(ctx->buffer, tmp, ctx->len);
977 memcpy(&ctx->buffer[ctx->len], data, len);
981 DBG(r, "REQ[%X] append data end", (unsigned int)(apr_size_t)r);
984 if (APR_BUCKET_IS_EOS(b)) {
986 DBG(r, "REQ[%X] eos", (unsigned int)(apr_size_t)r);
987 /*----------------------------------------------------------------------*/
989 /*----------------------------------------------------------------------*/
991 cookie_lock_t *lock = NULL;
992 ctx = (mod_chxj_ctx *)f->ctx;
994 DBG(r, "REQ[%X] content_type=[%s]", (unsigned int)(apr_size_t)r, r->content_type);
995 lock = chxj_cookie_lock(r);
997 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
999 && (STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
1000 || STRNCASEEQ('t','T',"text/html", r->content_type, sizeof("text/html")-1))) {
1001 DBG(r, "REQ[%X] detect convert target:[%s]", (unsigned int)(apr_size_t)r, r->content_type);
1006 tmp = apr_palloc(pool, ctx->len + 1);
1008 memset(tmp, 0, ctx->len + 1);
1009 memcpy(tmp, ctx->buffer, ctx->len);
1011 ctx->buffer = chxj_convert(r,
1012 (const char **)&tmp,
1013 (apr_size_t *)&ctx->len,
1015 user_agent, &cookie);
1019 ctx->buffer = apr_psprintf(r->pool, "\n");
1021 ctx->buffer = chxj_convert(r,
1022 (const char **)&ctx->buffer,
1023 (apr_size_t *)&ctx->len,
1025 user_agent, &cookie);
1030 && *(char *)r->content_type == 't'
1031 && strncmp(r->content_type, "text/xml", 8) == 0) {
1032 DBG(r, "REQ[%X] text/XML", (unsigned int)(apr_size_t)r);
1040 memset(&doc, 0, sizeof(Doc));
1041 memset(&qrcode, 0, sizeof(qr_code_t));
1043 doc.parse_mode = PARSE_MODE_CHTML;
1047 qs_init_malloc(&doc);
1049 root = qs_parse_string(&doc, ctx->buffer, ctx->len);
1052 for (child = qs_get_child_node(&doc,root);
1054 child = qs_get_next_node(&doc,child)) {
1055 char *name = qs_get_node_name(&doc,child);
1056 if (strcasecmp("qrcode",name) == 0) {
1061 qs_all_free(&doc,QX_LOGMARK);
1063 r->handler = apr_psprintf(r->pool, "chxj-qrcode");
1064 chxj_qrcode_node_to_qrcode(&qrcode, root);
1065 sts = chxj_qrcode_create_image_data(&qrcode, &ctx->buffer, &ctx->len);
1067 ERR(r, "REQ[%X] qrcode create failed.", (unsigned int)(apr_size_t)r);
1068 chxj_cookie_unlock(r, lock);
1069 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1072 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1076 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
1078 && ( *r->content_type == 'i' || *r->content_type == 'I')
1079 && dconf->image == CHXJ_IMG_ON
1080 && strncasecmp("image/", r->content_type, 6) == 0
1081 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
1082 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
1083 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
1084 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
1085 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
1086 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
1087 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
1088 || STRCASEEQ('g','G',"gif", &r->content_type[6]))) { /* GIF */
1092 tmp = apr_palloc(pool, ctx->len + 1);
1094 memset(tmp, 0, ctx->len + 1);
1095 memcpy(tmp, ctx->buffer, ctx->len);
1097 chxj_convert_image(r,
1098 (const char **)&tmp,
1099 (apr_size_t *)&ctx->len);
1100 if (ctx->buffer == NULL) {
1106 apr_table_unset(r->headers_out, "Content-Length");
1107 apr_table_unset(r->err_headers_out, "Content-Length");
1108 ap_set_content_length(r, (apr_off_t)ctx->len);
1112 DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1113 s_add_cookie_id_if_has_location_header(r, cookie);
1114 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1115 if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
1116 r->status = HTTP_MOVED_TEMPORARILY;
1119 chxj_cookie_unlock(r,lock);
1120 rv = pass_data_to_filter(f,
1121 (const char *)ctx->buffer,
1122 (apr_size_t)ctx->len);
1125 chxj_cookie_unlock(r, lock);
1128 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1132 DBG(r, "REQ[%X] SAVE COOKIE[%x]", (unsigned int)(apr_size_t)r, entryp->action);
1137 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
1138 cookie_lock_t *lock = NULL;
1139 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
1140 switch(spec->html_spec_type) {
1141 case CHXJ_SPEC_Chtml_1_0:
1142 case CHXJ_SPEC_Chtml_2_0:
1143 case CHXJ_SPEC_Chtml_3_0:
1144 case CHXJ_SPEC_Chtml_4_0:
1145 case CHXJ_SPEC_Chtml_5_0:
1146 case CHXJ_SPEC_Chtml_6_0:
1147 case CHXJ_SPEC_Chtml_7_0:
1148 case CHXJ_SPEC_XHtml_Mobile_1_0:
1149 case CHXJ_SPEC_Jhtml:
1150 lock = chxj_cookie_lock(r);
1151 cookie = chxj_save_cookie(r);
1153 * Location Header Check to add cookie parameter.
1155 s_add_cookie_id_if_has_location_header(r, cookie);
1156 chxj_cookie_unlock(r, lock);
1157 apr_table_unset(r->headers_out, "Set-Cookie");
1158 apr_table_unset(r->err_headers_out, "Set-Cookie");
1165 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1166 if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
1167 r->status = HTTP_MOVED_TEMPORARILY;
1170 apr_table_setn(r->headers_out, "Content-Length", "0");
1171 DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1172 rv = pass_data_to_filter(f, (const char *)"", (apr_size_t)0);
1173 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1178 apr_brigade_destroy(bb);
1180 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1186 * Add Cookie_id if it has location header.
1189 s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie)
1191 char *location_header = (char *)apr_table_get(r->headers_out, "Location");
1192 if (! location_header) {
1193 location_header = (char *)apr_table_get(r->err_headers_out, "Location");
1195 if (cookie && location_header) {
1196 DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1197 location_header = chxj_add_cookie_parameter(r,
1200 apr_table_unset(r->headers_out, "Location");
1201 apr_table_setn(r->headers_out, "Location", location_header);
1202 DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1203 if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
1204 r->status = HTTP_MOVED_TEMPORARILY;
1210 * It is the main loop of the input filter handler.
1214 chxj_input_handler(request_rec *r)
1216 mod_chxj_config *dconf;
1217 chxjconvrule_entry *entryp = NULL;
1218 device_table *spec = NULL;
1219 char *post_data = NULL;
1220 apr_size_t post_data_len = 0;
1226 DBG(r, "start of chxj_input_handler()");
1228 if (strcasecmp(r->handler, "chxj-input-handler")) {
1229 DBG(r, "end chxj_input_handler()");
1232 apr_pool_create(&pool, r->pool);
1234 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1235 user_agent = (char*)apr_table_get(r->headers_in, "User-Agent");
1236 spec = chxj_specified_device(r, user_agent);
1237 entryp = chxj_apply_convrule(r, dconf->convrules);
1239 post_data = apr_pstrdup(pool, "");
1240 if (ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK) == OK) {
1241 if (ap_should_client_block(r)) {
1242 while (post_data_len < CHXJ_POST_MAX) {
1245 int read_bytes = ap_get_client_block(r, buffer, BUFSZ-1);
1246 if (read_bytes<=0) {
1249 buffer[read_bytes] = '\0';
1250 post_data = apr_pstrcat(pool, post_data, buffer, NULL);
1251 post_data_len += read_bytes;
1260 if (post_data_len > 0) {
1261 post_data = chxj_input_convert(r, (const char**)&post_data, (apr_size_t*)&post_data_len, entryp);
1262 DBG(r, "(in:exchange)POSTDATA:[%s]", post_data);
1266 if (dconf->forward_url_base) {
1267 url_path = apr_psprintf(pool, "%s%s", dconf->forward_url_base, r->uri);
1270 url_path = apr_psprintf(pool, "%s://%s:%d%s", chxj_apache_run_http_scheme(r), "127.0.0.1", ap_get_server_port(r), r->uri);
1273 url_path = apr_pstrcat(pool, url_path, "?", r->args, NULL);
1275 DBG(r, "==> new url_path:[%s]", url_path);
1278 apr_table_setn(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP, r->connection->remote_ip);
1279 apr_table_unset(r->headers_in, "Content-Length");
1280 apr_table_setn(r->headers_in, "Content-Length", apr_psprintf(pool, "%" APR_SIZE_T_FMT, post_data_len));
1281 response = chxj_serf_post(r, pool, url_path, post_data, post_data_len, 1, &res_len);
1282 DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1283 DBG(r, "REQ[%X] response length:[%" APR_SIZE_T_FMT "]", (unsigned int)(apr_size_t)r, res_len);
1284 for (ii=0; ii<res_len/64; ii++) {
1285 DBG(r, "REQ[%X] response:[%.*s]", (unsigned int)(apr_size_t)r, 64, &response[ii*64]);
1287 DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1290 if ((chunked = (char *)apr_table_get(r->headers_out, "Transfer-Encoding")) != NULL) {
1291 if (strcasecmp(chunked, "chunked") == 0) {
1293 apr_table_unset(r->headers_out, "Transfer-Encoding");
1298 apr_pool_create(&wpool, r->pool);
1299 apr_bucket_brigade *bb;
1302 conn_rec *c = r->connection;
1304 bb = apr_brigade_create(wpool, c->bucket_alloc);
1305 e = apr_bucket_transient_create(response, res_len, c->bucket_alloc);
1306 APR_BRIGADE_INSERT_TAIL(bb, e);
1307 e = apr_bucket_eos_create(c->bucket_alloc);
1308 APR_BRIGADE_INSERT_TAIL(bb, e);
1309 if ((rv = ap_pass_brigade(r->output_filters, bb)) != APR_SUCCESS) {
1310 ERR(r, "REQ[%X] %s:%d failed ap_pass_brigade()", (unsigned int)(apr_size_t)r, APLOG_MARK);
1313 apr_brigade_cleanup(bb);
1316 DBG(r, "REQ[%X] end of chxj_input_handler()", (unsigned int)(apr_size_t)r);
1320 static mod_chxj_global_config *
1321 chxj_global_config_create(apr_pool_t *pool, server_rec *s)
1323 mod_chxj_global_config *conf;
1325 SDBG(s, "start chxj_global_config_create()");
1327 /*--------------------------------------------------------------------------*/
1328 /* allocate an own subpool which survives server restarts */
1329 /*--------------------------------------------------------------------------*/
1330 conf = (mod_chxj_global_config *)apr_palloc(pool,
1331 sizeof(mod_chxj_global_config));
1333 conf->cookie_db_lock = NULL;
1335 SDBG(s, "end chxj_global_config_create()");
1342 * initialize chxj module
1345 chxj_init_module(apr_pool_t *p,
1346 apr_pool_t *UNUSED(plog),
1347 apr_pool_t *UNUSED(ptemp),
1353 SDBG(s, "start chxj_init_module()");
1355 apr_pool_userdata_get(&user_data, CHXJ_MOD_CONFIG_KEY, s->process->pool);
1357 if (user_data == NULL) {
1360 * dummy user_data set.
1362 apr_pool_userdata_set(
1364 CHXJ_MOD_CONFIG_KEY,
1365 apr_pool_cleanup_null,
1367 SDBG(s, "end chxj_init_module()");
1371 ap_add_version_component(p, CHXJ_VERSION_PREFIX CHXJ_VERSION);
1373 if ((rv = apr_proc_mutex_create(&global_cookie_mutex, NULL, APR_LOCK_FCNTL, s->process->pool)) != APR_SUCCESS) {
1375 SERR(s, "%s:%d end chxj_init_module(). mutex create failure.(%d:%s)",APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1376 return HTTP_INTERNAL_SERVER_ERROR;
1379 SDBG(s, "end chxj_init_module()");
1386 chxj_child_init(apr_pool_t *UNUSED(p), server_rec *s)
1389 SDBG(s, "start chxj_child_init()");
1390 if ((rv = apr_proc_mutex_child_init(&global_cookie_mutex, NULL, s->process->pool)) != APR_SUCCESS) {
1392 SERR(s, "%s:%d ERROR end chxj_init_module(). mutex create failure.(%d:%s)", APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1394 SDBG(s, "end chxj_child_init()");
1399 * A set structure of each server is generated.
1405 chxj_config_server_create(apr_pool_t *p, server_rec *s)
1407 mod_chxj_global_config *gc;
1409 gc = chxj_global_config_create(p,s);
1416 chxj_translate_name(request_rec *r)
1418 DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1419 DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1420 DBG(r, "REQ[%X] START REQUEST (uri:[%s] args:[%s])", (unsigned int)(apr_size_t)r, r->unparsed_uri, r->args ? r->args : "");
1421 DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1422 DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1423 return chxj_trans_name(r);
1428 chxj_insert_filter(request_rec *r)
1432 mod_chxj_config *dconf;
1433 chxjconvrule_entry *entryp;
1438 DBG(r, "start chxj_insert_filter()");
1440 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1442 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
1444 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
1446 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
1447 DBG(r, "detect multipart/form-data ==> no target");
1451 spec = chxj_specified_device(r, user_agent);
1452 entryp = chxj_apply_convrule(r, dconf->convrules);
1454 DBG(r, "end chxj_insert_filter()");
1457 ctx = apr_palloc(r->pool, sizeof(*ctx));
1458 memset(ctx, 0, sizeof(*ctx));
1459 if ((rv = apr_pool_create(&ctx->pool, r->pool)) != APR_SUCCESS) {
1460 ERR(r, "failed: new pool create. rv:[%d]", rv);
1463 ctx->entryp = entryp;
1465 ctx->buffer = apr_palloc(ctx->pool, 1);
1468 if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
1473 switch(spec->html_spec_type) {
1474 case CHXJ_SPEC_Chtml_1_0:
1475 case CHXJ_SPEC_Chtml_2_0:
1476 case CHXJ_SPEC_Chtml_3_0:
1477 case CHXJ_SPEC_Chtml_4_0:
1478 case CHXJ_SPEC_Chtml_5_0:
1479 case CHXJ_SPEC_Chtml_6_0:
1480 case CHXJ_SPEC_Chtml_7_0:
1481 case CHXJ_SPEC_XHtml_Mobile_1_0:
1482 case CHXJ_SPEC_Hdml:
1483 case CHXJ_SPEC_Jhtml:
1484 case CHXJ_SPEC_Jxhtml:
1492 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
1493 ap_add_output_filter("chxj_output_filter", ctx, r, r->connection);
1494 DBG(r, "added Output Filter");
1497 DBG(r, "end chxj_insert_filter()");
1502 * The hook is registered.
1507 chxj_register_hooks(apr_pool_t *UNUSED(p))
1509 ap_hook_post_config(chxj_init_module,
1512 APR_HOOK_REALLY_FIRST);
1513 ap_hook_child_init(chxj_child_init,
1516 APR_HOOK_REALLY_FIRST);
1517 ap_register_output_filter (
1518 "chxj_output_filter",
1522 ap_hook_insert_filter(chxj_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
1523 ap_hook_handler(chxj_img_conv_format_handler, NULL, NULL, APR_HOOK_MIDDLE);
1524 ap_hook_handler(chxj_qr_code_handler, NULL, NULL, APR_HOOK_MIDDLE);
1525 ap_hook_handler(chxj_input_handler, NULL, NULL, APR_HOOK_MIDDLE);
1526 ap_hook_translate_name(chxj_translate_name, NULL, NULL, APR_HOOK_MIDDLE);
1527 ap_hook_fixups(chxj_headers_fixup, NULL, NULL, APR_HOOK_FIRST);
1532 * A set structure according to the directory is generated.
1538 chxj_create_per_dir_config(apr_pool_t *p, char *arg)
1540 mod_chxj_config *conf;
1542 conf = apr_pcalloc(p, sizeof(mod_chxj_config));
1543 conf->device_data_file = NULL;
1544 conf->devices = NULL;
1545 conf->emoji_data_file = NULL;
1547 conf->emoji_tail = NULL;
1548 conf->image = CHXJ_IMG_NONE;
1549 conf->image_cache_dir = apr_psprintf(p, "%s",DEFAULT_IMAGE_CACHE_DIR);
1550 conf->image_cache_limit = 0;
1551 conf->server_side_encoding = NULL;
1552 conf->cookie_db_dir = NULL;
1553 conf->cookie_timeout = 0;
1554 conf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
1555 conf->cookie_lazy_mode = 0;
1556 #if defined(USE_MYSQL_COOKIE)
1557 memset((void *)&conf->mysql, 0, sizeof(mysql_t));
1558 conf->mysql.port = MYSQL_PORT;
1559 conf->mysql.host = NULL;
1561 #if defined(USE_MEMCACHE_COOKIE)
1562 memset((void *)&conf->memcache, 0, sizeof(memcache_t));
1563 conf->memcache.host = NULL;
1564 conf->memcache.port = 0;
1566 conf->forward_url_base = NULL;
1567 conf->forward_server_ip = NULL;
1573 conf->dir = apr_pcalloc(p, strlen(arg)+1);
1574 memset(conf->dir, 0, strlen(arg)+1);
1575 strcpy(conf->dir, arg);
1577 conf->convrules = apr_array_make(p, 2, sizeof(chxjconvrule_entry));
1579 /* Default is copyleft */
1580 conf->image_copyright = NULL;
1587 * Merge per-directory CHXJ configurations
1590 chxj_merge_per_dir_config(apr_pool_t *p, void *basev, void *addv)
1592 mod_chxj_config *base;
1593 mod_chxj_config *add;
1594 mod_chxj_config *mrg;
1596 base = (mod_chxj_config *)basev;
1597 add = (mod_chxj_config *)addv;
1598 mrg = (mod_chxj_config *)apr_palloc(p, sizeof(mod_chxj_config));
1600 mrg->device_data_file = NULL;
1601 mrg->devices = NULL;
1602 mrg->emoji_data_file = NULL;
1603 mrg->image = CHXJ_IMG_NONE;
1604 mrg->image_cache_dir = NULL;
1605 mrg->image_copyright = NULL;
1606 mrg->image_cache_limit = 0;
1608 mrg->emoji_tail = NULL;
1609 mrg->new_line_type = NLTYPE_NIL;
1610 mrg->forward_url_base = NULL;
1611 mrg->forward_server_ip = NULL;
1613 mrg->dir = apr_pstrdup(p, add->dir);
1615 if (! add->device_data_file) {
1616 mrg->devices = base->devices;
1617 mrg->device_data_file = apr_pstrdup(p, base->device_data_file);
1620 mrg->devices = add->devices;
1621 mrg->device_data_file = apr_pstrdup(p, add->device_data_file);
1624 if (! add->emoji_data_file) {
1625 mrg->emoji = base->emoji;
1626 mrg->emoji_tail = base->emoji_tail;
1627 mrg->emoji_data_file = apr_pstrdup(p, base->emoji_data_file);
1630 mrg->emoji = add->emoji;
1631 mrg->emoji_tail = add->emoji_tail;
1632 mrg->emoji_data_file = apr_pstrdup(p, add->emoji_data_file);
1635 if (add->image == CHXJ_IMG_NONE) {
1636 mrg->image = base->image;
1639 mrg->image = add->image;
1642 if (strcasecmp(add->image_cache_dir ,DEFAULT_IMAGE_CACHE_DIR)==0) {
1643 mrg->image_cache_dir = apr_pstrdup(p, base->image_cache_dir);
1646 mrg->image_cache_dir = apr_pstrdup(p, add->image_cache_dir);
1649 if (add->image_cache_limit) {
1650 mrg->image_cache_limit = add->image_cache_limit;
1653 mrg->image_cache_limit = base->image_cache_limit;
1656 if (add->image_copyright)
1657 mrg->image_copyright = apr_pstrdup(p, add->image_copyright);
1659 mrg->image_copyright = apr_pstrdup(p, base->image_copyright);
1661 if (add->server_side_encoding) {
1662 mrg->server_side_encoding = apr_pstrdup(p, add->server_side_encoding);
1665 if (base->server_side_encoding) {
1666 mrg->server_side_encoding = apr_pstrdup(p, base->server_side_encoding);
1669 mrg->server_side_encoding = apr_pstrdup(p, DEFAULT_SERVER_SIDE_ENCODING);
1672 mrg->convrules = apr_array_append(p, add->convrules, base->convrules);
1674 if (add->cookie_db_dir) {
1675 mrg->cookie_db_dir = apr_pstrdup(p, add->cookie_db_dir);
1678 if (base->cookie_db_dir) {
1679 mrg->cookie_db_dir = apr_pstrdup(p, base->cookie_db_dir);
1682 mrg->cookie_db_dir = NULL;
1685 if (add->cookie_timeout) {
1686 mrg->cookie_timeout = add->cookie_timeout;
1689 if (base->cookie_db_dir) {
1690 mrg->cookie_timeout = base->cookie_timeout;
1693 mrg->cookie_timeout = 0;
1696 #if defined(USE_MYSQL_COOKIE)
1697 if (add->mysql.host) {
1698 mrg->mysql.host = apr_pstrdup(p, add->mysql.host);
1700 else if (base->mysql.host) {
1701 mrg->mysql.host = apr_pstrdup(p, base->mysql.host);
1704 mrg->mysql.host = NULL;
1706 if (add->mysql.port) {
1707 mrg->mysql.port = add->mysql.port;
1709 else if (base->mysql.port) {
1710 mrg->mysql.port = base->mysql.port;
1713 mrg->mysql.port = 0;
1716 if (add->mysql.database) {
1717 mrg->mysql.database = apr_pstrdup(p, add->mysql.database);
1719 else if (base->mysql.database) {
1720 mrg->mysql.database = apr_pstrdup(p, base->mysql.database);
1723 mrg->mysql.database = NULL;
1726 if (add->mysql.username) {
1727 mrg->mysql.username = apr_pstrdup(p, add->mysql.username);
1729 else if (base->mysql.username) {
1730 mrg->mysql.username = apr_pstrdup(p, base->mysql.username);
1733 mrg->mysql.username = NULL;
1736 if (add->mysql.password) {
1737 mrg->mysql.password = apr_pstrdup(p, add->mysql.password);
1739 else if (base->mysql.password) {
1740 mrg->mysql.password = apr_pstrdup(p, base->mysql.password);
1743 mrg->mysql.password = NULL;
1746 if (add->mysql.tablename) {
1747 mrg->mysql.tablename = apr_pstrdup(p, add->mysql.tablename);
1749 else if (base->mysql.tablename) {
1750 mrg->mysql.tablename = apr_pstrdup(p, base->mysql.tablename);
1753 mrg->mysql.tablename = NULL;
1756 if (add->mysql.socket_path) {
1757 mrg->mysql.socket_path = apr_pstrdup(p, add->mysql.socket_path);
1759 else if (base->mysql.socket_path) {
1760 mrg->mysql.socket_path = apr_pstrdup(p, base->mysql.socket_path);
1763 mrg->mysql.socket_path = NULL;
1766 if (add->mysql.charset) {
1767 mrg->mysql.charset = apr_pstrdup(p, add->mysql.charset);
1769 else if (base->mysql.charset) {
1770 mrg->mysql.charset = apr_pstrdup(p, base->mysql.charset);
1773 mrg->mysql.charset = NULL;
1776 #if defined(USE_MEMCACHE_COOKIE)
1777 if (add->memcache.host) {
1778 mrg->memcache.host = apr_pstrdup(p, add->memcache.host);
1780 else if (base->memcache.host) {
1781 mrg->memcache.host = apr_pstrdup(p, base->memcache.host);
1784 mrg->memcache.host = NULL;
1786 if (add->memcache.port) {
1787 mrg->memcache.port = add->memcache.port;
1789 else if (base->memcache.port) {
1790 mrg->memcache.port = base->memcache.port;
1793 mrg->memcache.port = 0;
1796 if (add->cookie_store_type) {
1797 mrg->cookie_store_type = add->cookie_store_type;
1799 else if (base->cookie_store_type) {
1800 mrg->cookie_store_type = base->cookie_store_type;
1803 mrg->cookie_store_type = COOKIE_STORE_TYPE_NONE;
1805 if (add->cookie_lazy_mode) {
1806 mrg->cookie_lazy_mode = add->cookie_lazy_mode;
1808 else if (base->cookie_lazy_mode) {
1809 mrg->cookie_lazy_mode = base->cookie_lazy_mode;
1812 mrg->cookie_lazy_mode = 0;
1814 if (add->new_line_type) {
1815 mrg->new_line_type = add->new_line_type;
1817 else if (base->new_line_type) {
1818 mrg->new_line_type = base->new_line_type;
1821 mrg->new_line_type = NLTYPE_NIL;
1824 if (add->forward_url_base) {
1825 mrg->forward_url_base = add->forward_url_base;
1827 else if (base->forward_url_base) {
1828 mrg->forward_url_base = base->forward_url_base;
1835 chxj_command_parse_take5(
1848 for (;*strp == ' '||*strp == '\t'; strp++) ;
1858 for (; *strp != '\0'; strp++) {
1859 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1860 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1865 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1866 || (isquoted && *strp == '"'))
1880 for (;*strp == ' '||*strp == '\t'; strp++) ;
1889 for (; *strp != '\0'; strp++) {
1890 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1891 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1896 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1897 || (isquoted && *strp == '"'))
1910 for (;*strp == ' '||*strp == '\t'; strp++);
1918 for (; *strp != '\0'; strp++) {
1919 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1920 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1925 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1926 || (isquoted && *strp == '"'))
1938 for (;*strp == ' '||*strp == '\t'; strp++);
1946 for (; *strp != '\0'; strp++) {
1947 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1948 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1953 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1954 || (isquoted && *strp == '"'))
1965 for (;*strp == ' '||*strp == '\t'; strp++);
1973 for (; *strp != '\0'; strp++) {
1974 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1975 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1980 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1981 || (isquoted && *strp == '"'))
1991 * The device definition file is loaded.
1993 * @param arg [i] The name of the device definition file is specified.
1994 * @param mconfig [i/o] The pointer to a set structure is specified.
1998 cmd_load_device_data(cmd_parms *parms, void *mconfig, const char *arg)
2000 mod_chxj_config *conf;
2005 if (strlen(arg) > 256)
2006 return "mod_chxj: device data filename too long.";
2008 conf = (mod_chxj_config *)mconfig;
2009 conf->device_data_file = apr_pstrdup(parms->pool, arg);
2011 qs_init_malloc(&doc);
2012 qs_init_root_node(&doc);
2014 qs_parse_file((Doc *)&doc, (const char *)arg);
2015 chxj_load_device_data(&doc,parms->pool, conf);
2016 qs_all_free(&doc, QX_LOGMARK);
2023 * Device definition information is loaded.
2026 * @param arg [i] The name of the device definition file is specified.
2027 * @param mconfig [i/o] The pointer to a set structure is specified.
2031 cmd_load_emoji_data(cmd_parms *parms, void *mconfig, const char *arg)
2033 mod_chxj_config *conf;
2040 if (strlen(arg) > 256)
2041 return "mod_chxj: emoji data filename too long.";
2043 conf = (mod_chxj_config *)mconfig;
2044 conf->emoji_data_file = apr_pstrdup(parms->pool, arg);
2045 qs_init_malloc(&doc);
2046 qs_init_root_node(&doc);
2048 qs_parse_file((Doc *)&doc, (const char *)arg);
2050 rtn = chxj_load_emoji_data(&doc,parms->pool, conf);
2052 qs_all_free(&doc, QX_LOGMARK);
2060 cmd_set_image_engine(cmd_parms * UNUSED(parms), void *mconfig, const char *arg)
2062 mod_chxj_config *conf;
2067 if (strlen(arg) > 256)
2068 return "image uri is too long.";
2070 conf = (mod_chxj_config*)mconfig;
2071 if (strcasecmp("ON", arg) == 0) {
2072 conf->image = CHXJ_IMG_ON;
2075 conf->image = CHXJ_IMG_OFF;
2083 cmd_set_image_cache_dir(cmd_parms *parms, void *mconfig, const char *arg)
2085 mod_chxj_config *conf;
2090 if (strlen(arg) > 256)
2091 return "cache dir name is too long.";
2093 conf = (mod_chxj_config *)mconfig;
2094 conf->image_cache_dir = apr_pstrdup(parms->pool, arg);
2101 cmd_set_image_cache_limit(cmd_parms *parms, void *mconfig, const char *arg)
2103 mod_chxj_config *conf;
2108 if (strlen(arg) > IMAGE_CACHE_LIMIT_FMT_LEN)
2109 return "cache size is too long.";
2111 conf = (mod_chxj_config *)mconfig;
2114 * I use strtol function because strtoul is not portable function.
2116 conf->image_cache_limit = (unsigned long)strtol(arg, NULL, 10);
2119 return apr_psprintf(parms->pool, "ChxjImageCacheLimit invalid value [%s] errno:[%d]", arg, errno);
2121 return apr_psprintf(parms->pool, "ChxjImageCacheLimit Out of range [%s] errno:[%d]", arg, errno);
2130 cmd_set_image_copyright(cmd_parms *parms, void *mconfig, const char *arg)
2132 mod_chxj_config *conf;
2137 if (strlen(arg) > 256)
2138 return "Copyright Flag is too long.";
2140 conf = (mod_chxj_config *)mconfig;
2141 conf->image_copyright = apr_pstrdup(parms->pool, arg);
2148 cmd_convert_rule(cmd_parms *cmd, void *mconfig, const char *arg)
2152 mod_chxj_config *dconf;
2153 chxjconvrule_entry *newrule;
2163 dconf = (mod_chxj_config *)mconfig;
2165 if (strlen(arg) > 4096)
2166 return "mod_chxj: ChxjConvertRule: is too long.";
2168 dconf = (mod_chxj_config *)mconfig;
2169 if (dconf->convrules == NULL)
2170 dconf->convrules = apr_array_make(cmd->pool,
2172 sizeof(chxjconvrule_entry));
2174 newrule = apr_array_push(dconf->convrules);
2177 newrule->action = 0;
2179 if (chxj_command_parse_take5(arg, &prm1, &prm2, &prm3, &prm4, &prm5))
2180 return "ChxjConvertRule: bad argument line";
2182 newrule->pattern = apr_pstrdup(cmd->pool, prm1);
2186 if ((action = apr_strtok(prm2, ",", &pstate)) == NULL)
2192 if (strcasecmp(CONVRULE_ENGINE_ON_CMD, action) == 0) {
2193 newrule->action |= CONVRULE_ENGINE_ON_BIT;
2196 if (strcasecmp(CONVRULE_ENGINE_OFF_CMD, action) == 0) {
2197 newrule->action |= CONVRULE_ENGINE_OFF_BIT;
2203 if (strcasecmp(CONVRULE_COOKIE_ON_CMD, action) == 0) {
2204 newrule->action |= CONVRULE_COOKIE_ON_BIT;
2210 if (strcasecmp(CONVRULE_Z2H_ON_CMD, action) == 0) {
2211 newrule->action |= CONVRULE_Z2H_ON_BIT;
2214 if (strcasecmp(CONVRULE_Z2H_OFF_CMD, action) == 0) {
2215 newrule->action |= CONVRULE_Z2H_OFF_BIT;
2218 if (strcasecmp(CONVRULE_Z2H_ALPHA_ON_CMD, action) == 0) {
2219 newrule->action |= CONVRULE_Z2H_ALPHA_ON_BIT;
2222 if (strcasecmp(CONVRULE_Z2H_ALPHA_OFF_CMD, action) == 0) {
2223 newrule->action |= CONVRULE_Z2H_ALPHA_OFF_BIT;
2226 if (strcasecmp(CONVRULE_Z2H_NUM_ON_CMD, action) == 0) {
2227 newrule->action |= CONVRULE_Z2H_NUM_ON_BIT;
2230 if (strcasecmp(CONVRULE_Z2H_NUM_OFF_CMD, action) == 0) {
2231 newrule->action |= CONVRULE_Z2H_NUM_OFF_BIT;
2234 if (strcasecmp(CONVRULE_Z2H_ALL_ON_CMD, action) == 0) {
2235 newrule->action |= CONVRULE_Z2H_ON_BIT | CONVRULE_Z2H_ALPHA_ON_BIT | CONVRULE_Z2H_NUM_ON_BIT;
2238 if (strcasecmp(CONVRULE_Z2H_NUM_OFF_CMD, action) == 0) {
2239 newrule->action |= CONVRULE_Z2H_OFF_BIT | CONVRULE_Z2H_ALPHA_OFF_BIT | CONVRULE_Z2H_NUM_OFF_BIT;
2250 newrule->flags |= CONVRULE_FLAG_NOTMATCH;
2254 mode = AP_REG_EXTENDED;
2255 if ((regexp = ap_pregcomp((apr_pool_t *)cmd->pool, (const char *)pp, mode)) == NULL)
2256 return "RewriteRule: cannot compile regular expression ";
2258 newrule->regexp = regexp;
2260 newrule->encoding = apr_pstrdup(cmd->pool, prm3);
2262 newrule->encoding = apr_pstrdup(cmd->pool, "none");
2264 newrule->pc_flag = CONVRULE_PC_FLAG_OFF_BIT;
2266 if (strcasecmp(CONVRULE_PC_FLAG_ON_CMD, prm4) == 0)
2267 newrule->pc_flag = CONVRULE_PC_FLAG_ON_BIT;
2269 newrule->user_agent = NULL;
2271 newrule->user_agent = apr_pstrdup(cmd->pool, prm5);
2283 mod_chxj_config *dconf;
2286 if (strlen(arg) > 4096)
2287 return "mod_chxj: ChxjCookieDir is too long.";
2289 dconf = (mod_chxj_config *)mconfig;
2291 dconf->cookie_db_dir = apr_pstrdup(cmd->pool, arg);
2298 cmd_set_cookie_timeout(
2299 cmd_parms *UNUSED(cmd),
2303 mod_chxj_config *dconf;
2305 if (strlen(arg) > 4096)
2306 return "mod_chxj: ChxjCookieTimeout is too long.";
2308 if (chxj_chk_numeric(arg) != 0)
2309 return "mod_chxj: ChxjCookieTimeout is not numeric.";
2311 dconf = (mod_chxj_config *)mconfig;
2313 dconf->cookie_timeout = atoi(arg);
2319 #if defined(USE_MYSQL_COOKIE)
2321 cmd_set_cookie_mysql_database(
2326 mod_chxj_config *dconf;
2328 if (strlen(arg) > 255)
2329 return "mod_chxj: ChxjCookieMysqlDatabase is too long.";
2331 dconf = (mod_chxj_config *)mconfig;
2333 dconf->mysql.database = apr_pstrdup(cmd->pool, arg);
2340 cmd_set_cookie_mysql_username(
2345 mod_chxj_config *dconf;
2347 if (strlen(arg) > 255)
2348 return "mod_chxj: ChxjCookieMysqlUsername is too long.";
2350 dconf = (mod_chxj_config *)mconfig;
2352 dconf->mysql.username = apr_pstrdup(cmd->pool, arg);
2359 cmd_set_cookie_mysql_password(
2364 mod_chxj_config *dconf;
2366 if (strlen(arg) > 255)
2367 return "mod_chxj: ChxjCookieMysqlPassword is too long.";
2369 dconf = (mod_chxj_config *)mconfig;
2371 dconf->mysql.password = apr_pstrdup(cmd->pool, arg);
2378 cmd_set_cookie_mysql_table_name(
2383 mod_chxj_config *dconf;
2385 if (strlen(arg) > 255)
2386 return "mod_chxj: ChxjCookieMysqlTableName is too long.";
2388 dconf = (mod_chxj_config *)mconfig;
2390 dconf->mysql.tablename = apr_pstrdup(cmd->pool, arg);
2396 cmd_set_cookie_mysql_port(
2397 cmd_parms *UNUSED(cmd),
2401 mod_chxj_config *dconf;
2403 if (strlen(arg) > 255)
2404 return "mod_chxj: ChxjCookieMysqlPort is too long.";
2406 dconf = (mod_chxj_config *)mconfig;
2408 if (chxj_chk_numeric(arg) != 0)
2409 return "mod_chxj: ChxjCookieMysqlPort is not numeric.";
2411 dconf = (mod_chxj_config *)mconfig;
2413 dconf->mysql.port = chxj_atoi(arg);
2420 cmd_set_cookie_mysql_host(
2425 mod_chxj_config *dconf;
2427 if (strlen(arg) > 255)
2428 return "mod_chxj: ChxjCookieMysqlHost is too long.";
2430 dconf = (mod_chxj_config *)mconfig;
2432 dconf->mysql.host = apr_pstrdup(cmd->pool, arg);
2439 cmd_set_cookie_mysql_socket_path(
2444 mod_chxj_config *dconf;
2446 if (strlen(arg) > 4096)
2447 return "mod_chxj: ChxjCookieMysqlSocketPath is too long.";
2449 dconf = (mod_chxj_config *)mconfig;
2451 dconf->mysql.socket_path = apr_pstrdup(cmd->pool, arg);
2458 cmd_set_cookie_mysql_charset(
2463 mod_chxj_config *dconf;
2465 if (strlen(arg) > 255)
2466 return "mod_chxj: ChxjCookieMysqlCharset is too long.";
2468 dconf = (mod_chxj_config *)mconfig;
2470 dconf->mysql.charset = apr_pstrdup(cmd->pool, arg);
2475 #if defined(USE_MEMCACHE_COOKIE)
2477 cmd_set_cookie_memcache_port(
2478 cmd_parms *UNUSED(cmd),
2482 mod_chxj_config *dconf;
2484 if (strlen(arg) > 255)
2485 return "mod_chxj: ChxjCookieMemcachePort is too long.";
2487 dconf = (mod_chxj_config *)mconfig;
2489 if (chxj_chk_numeric(arg) != 0)
2490 return "mod_chxj: ChxjCookieMemcachePort is not numeric.";
2492 dconf = (mod_chxj_config *)mconfig;
2494 dconf->memcache.port = (apr_port_t)chxj_atoi(arg);
2501 cmd_set_cookie_memcache_host(
2506 mod_chxj_config *dconf;
2508 if (strlen(arg) > 255)
2509 return "mod_chxj: ChxjCookieMemcacheHost is too long.";
2511 dconf = (mod_chxj_config *)mconfig;
2513 dconf->memcache.host = apr_pstrdup(cmd->pool, arg);
2520 cmd_set_cookie_lazy_mode(
2521 cmd_parms *UNUSED(cmd),
2525 mod_chxj_config *dconf;
2527 if (strlen(arg) > 255)
2528 return "mod_chxj: ChxjCookieLazyMode is too long.";
2530 dconf = (mod_chxj_config *)mconfig;
2532 if (strcasecmp("TRUE",arg) == 0) {
2533 dconf->cookie_lazy_mode = COOKIE_LAZY_ON;
2536 dconf->cookie_lazy_mode = COOKIE_LAZY_OFF;
2543 cmd_set_cookie_store_type(
2544 cmd_parms *UNUSED(cmd),
2548 mod_chxj_config *dconf;
2550 if (strlen(arg) > 255)
2551 return "mod_chxj: ChxjCookieStoreType is too long.";
2553 dconf = (mod_chxj_config *)mconfig;
2555 if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_DBM, arg) == 0) {
2556 dconf->cookie_store_type = COOKIE_STORE_TYPE_DBM;
2558 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MYSQL, arg) == 0) {
2559 dconf->cookie_store_type = COOKIE_STORE_TYPE_MYSQL;
2561 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MEMCACHE, arg) == 0) {
2562 dconf->cookie_store_type = COOKIE_STORE_TYPE_MEMCACHE;
2565 dconf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
2572 cmd_set_forward_url_base(
2577 mod_chxj_config *dconf;
2579 if (strlen(arg) > 255)
2580 return "mod_chxj: ChxjForwardUrlBase is too long.";
2582 dconf = (mod_chxj_config *)mconfig;
2584 dconf->forward_url_base = apr_pstrdup(cmd->pool, arg);
2590 cmd_set_forward_server_ip(
2595 mod_chxj_config *dconf;
2597 if (strlen(arg) > 255)
2598 return "mod_chxj: ChxjForwardServerIp is too long.";
2600 dconf = (mod_chxj_config *)mconfig;
2602 dconf->forward_server_ip = apr_pstrdup(cmd->pool, arg);
2608 cmd_set_new_line_type(
2609 cmd_parms *UNUSED(cmd),
2613 mod_chxj_config *dconf;
2614 if (strlen(arg) > 255)
2615 return "mod_chxj: ChxjNewLineType is too long.";
2617 dconf = (mod_chxj_config *)mconfig;
2619 if (strcasecmp(CHXJ_NEW_LINE_TYPE_CRLF, arg) == 0) {
2620 dconf->new_line_type = NLTYPE_CRLF;
2622 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_LF, arg) == 0) {
2623 dconf->new_line_type = NLTYPE_LF;
2625 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_CR, arg) == 0) {
2626 dconf->new_line_type = NLTYPE_CR;
2628 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_NONE, arg) == 0) {
2629 dconf->new_line_type = NLTYPE_NONE;
2632 return "mod_chxj: invalid value (ChxjNewLineType)";
2638 static const command_rec cmds[] = {
2640 "ChxjLoadDeviceData",
2641 cmd_load_device_data,
2644 "Load Device Data"),
2646 "ChxjLoadEmojiData",
2647 cmd_load_emoji_data,
2653 cmd_set_image_engine,
2656 "Convert Target URI"),
2658 "ChxjImageCacheDir",
2659 cmd_set_image_cache_dir,
2662 "Image Cache Directory"),
2664 "ChxjImageCacheLimit",
2665 cmd_set_image_cache_limit,
2668 "Image Cache Limit"),
2670 "ChxjImageCopyright",
2671 cmd_set_image_copyright,
2680 "an URL-applied regexp-pattern and a substitution URL"),
2686 "save cookie.db directory."),
2688 "ChxjCookieTimeout",
2689 cmd_set_cookie_timeout,
2692 "The compulsion time-out time of the cookie is specified. "),
2694 "ChxjCookieStoreType",
2695 cmd_set_cookie_store_type,
2698 "It specifies preserving of the cookie ahead. (DBM/MYSQL/MEMCACHE)"),
2700 "ChxjCookieLazyMode",
2701 cmd_set_cookie_lazy_mode,
2704 "OneTimeID is negligently done. (TRUE/FALSE)"),
2705 #if defined(USE_MYSQL_COOKIE)
2707 "ChxjCookieMysqlHost",
2708 cmd_set_cookie_mysql_host,
2711 "The MySQL database host used by saving Cookie"),
2713 "ChxjCookieMysqlPort",
2714 cmd_set_cookie_mysql_port,
2717 "The MySQL database port used by saving Cookie"),
2719 "ChxjCookieMysqlDatabase",
2720 cmd_set_cookie_mysql_database,
2723 "The MySQL database name used by saving Cookie"),
2725 "ChxjCookieMysqlUsername",
2726 cmd_set_cookie_mysql_username,
2729 "The MySQL username used by saving Cookie"),
2731 "ChxjCookieMysqlPassword",
2732 cmd_set_cookie_mysql_password,
2735 "The MySQL password used by saving Cookie"),
2737 "ChxjCookieMysqlTableName",
2738 cmd_set_cookie_mysql_table_name,
2741 "The MySQL table name used by saving Cookie"),
2743 "ChxjCookieMysqlSocketPath",
2744 cmd_set_cookie_mysql_socket_path,
2747 "The MySQL socket path used by saving Cookie"),
2749 "ChxjCookieMysqlCharset",
2750 cmd_set_cookie_mysql_charset,
2753 "The MySQL charset used by saving Cookie"),
2755 #if defined(USE_MEMCACHE_COOKIE)
2757 "ChxjCookieMemcacheHost",
2758 cmd_set_cookie_memcache_host,
2761 "The Memcached host used by saving Cookie"),
2763 "ChxjCookieMemcachePort",
2764 cmd_set_cookie_memcache_port,
2767 "The Memcached port used by saving Cookie"),
2771 cmd_set_new_line_type,
2774 "HTML new line type (NONE|CRLF|LF|CR). default is CRLF"),
2776 "ChxjForwardUrlBase",
2777 cmd_set_forward_url_base,
2780 "The forward url base(default: {request protocol}://{this server}:{this server port}"),
2782 "ChxjForwardServerIp",
2783 cmd_set_forward_server_ip,
2786 "The forward server ip(default: this server ip)"),
2791 /*----------------------------------------------------------------------------*/
2792 /* Dispatch list for API hooks */
2793 /*----------------------------------------------------------------------------*/
2794 module AP_MODULE_DECLARE_DATA chxj_module = {
2795 STANDARD20_MODULE_STUFF,
2796 chxj_create_per_dir_config, /* create per-dir config structures */
2797 chxj_merge_per_dir_config, /* merge per-dir config structures */
2798 chxj_config_server_create, /* create per-server config structures */
2799 NULL, /* merge per-server config structures */
2800 cmds, /* table of config file commands */
2801 chxj_register_hooks /* register hooks */