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_kana.h"
74 #define CHXJ_VERSION_PREFIX PACKAGE_NAME "/"
75 #define CHXJ_VERSION PACKAGE_VERSION
76 #define CHXJ_POST_MAX (0x1000000)
78 converter_t convert_routine[] = {
80 /* CHXJ_SPEC_UNKNOWN */
85 /* CHXJ_SPEC_Chtml_1_0 */
86 .converter = chxj_convert_chtml10,
87 .encoder = chxj_encoding,
90 /* CHXJ_SPEC_Chtml_2_0 */
91 .converter = chxj_convert_chtml20,
92 .encoder = chxj_encoding,
95 /* CHXJ_SPEC_Chtml_3_0 */
96 .converter = chxj_convert_chtml30,
97 .encoder = chxj_encoding,
100 /* CHXJ_SPEC_Chtml_4_0 */
101 .converter = chxj_convert_chtml40,
102 .encoder = chxj_encoding,
105 /* CHXJ_SPEC_Chtml_5_0 */
106 .converter = chxj_convert_chtml50,
107 .encoder = chxj_encoding,
110 /* CHXJ_SPEC_Chtml_6_0 */
111 .converter = chxj_convert_chtml50,
112 .encoder = chxj_encoding,
115 /* CHXJ_SPEC_Chtml_7_0 */
116 .converter = chxj_convert_chtml50,
117 .encoder = chxj_encoding,
120 /* CHXJ_SPEC_XHtml_Mobile_1_0 */
121 .converter = chxj_convert_xhtml_mobile_1_0,
122 .encoder = chxj_encoding,
126 .converter = chxj_convert_hdml,
127 .encoder = chxj_encoding,
130 /* CHXJ_SPEC_Jhtml */
131 .converter = chxj_convert_jhtml,
132 .encoder = chxj_encoding,
135 /* CHXJ_SPEC_Jxhtml */
136 .converter = chxj_convert_jxhtml,
137 .encoder = chxj_encoding,
146 static int chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp);
147 static void s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie);
148 static void s_clear_cookie_header(request_rec *r, device_table *spec);
151 * Only when User-Agent is specified, the User-Agent header is camouflaged.
156 chxj_headers_fixup(request_rec *r)
158 mod_chxj_config* dconf;
159 chxjconvrule_entry* entryp;
165 DBG(r, "REQ[%X] start chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
167 DBG(r, "REQ[%X] detect internal redirect.", (unsigned int)(apr_size_t)r);
168 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
172 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
174 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
175 spec = chxj_specified_device(r, user_agent);
177 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
179 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
180 DBG(r, "REQ[%X] detect multipart/form-data ==> no target", (unsigned int)(apr_size_t)r);
181 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
184 if (r->method_number == M_POST) {
185 if (!apr_table_get(r->headers_in, "X-Chxj-Forward")) {
186 s_clear_cookie_header(r, spec);
190 s_clear_cookie_header(r, spec);
193 switch(spec->html_spec_type) {
194 case CHXJ_SPEC_Chtml_1_0:
195 case CHXJ_SPEC_Chtml_2_0:
196 case CHXJ_SPEC_Chtml_3_0:
197 case CHXJ_SPEC_Chtml_4_0:
198 case CHXJ_SPEC_Chtml_5_0:
199 case CHXJ_SPEC_Chtml_6_0:
200 case CHXJ_SPEC_Chtml_7_0:
201 case CHXJ_SPEC_XHtml_Mobile_1_0:
203 case CHXJ_SPEC_Jhtml:
204 case CHXJ_SPEC_Jxhtml:
205 entryp = chxj_apply_convrule(r, dconf->convrules);
207 DBG(r, "REQ[%X] end chxj_headers_fixup() (no pattern)", (unsigned int)(apr_size_t)r);
210 if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
211 DBG(r, "REQ[%X] end chxj_headers_fixup() (engine off)", (unsigned int)(apr_size_t)r);
215 apr_table_setn(r->headers_in,
216 CHXJ_HTTP_USER_AGENT,
219 if (entryp->user_agent)
220 apr_table_setn(r->headers_in,
224 chxj_convert_input_header(r,entryp);
229 DBG(r, "REQ[%X] end chxj_headers_fixup() (not mobile)", (unsigned int)(apr_size_t)r);
235 if (r->method_number == M_POST) {
236 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
237 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);
238 r->proxyreq = PROXYREQ_NONE;
239 r->handler = apr_psprintf(r->pool, "chxj-input-handler");
242 char *client_ip = (char *)apr_table_get(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP);
244 apr_sockaddr_t *address = NULL;
245 apr_status_t rv = apr_sockaddr_info_get(&address, ap_get_server_name(r), APR_UNSPEC, ap_get_server_port(r), 0, r->pool);
246 if (rv != APR_SUCCESS) {
248 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));
249 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
253 if (dconf->forward_server_ip) {
254 addr = dconf->forward_server_ip;
257 apr_sockaddr_ip_get(&addr, address);
259 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);
260 if (strcmp(addr, r->connection->remote_ip) == 0) {
261 r->connection->remote_ip = apr_pstrdup(r->connection->pool, client_ip);
263 if (! apr_table_get(r->headers_in, "Content-Length")) {
264 contentLength = (char *)apr_table_get(r->headers_in, "X-Chxj-Content-Length");
266 apr_table_set(r->headers_in, "Content-Length", contentLength);
273 chxj_add_device_env(r, spec);
275 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
282 s_clear_cookie_header(request_rec *r, device_table *spec)
284 switch(spec->html_spec_type) {
285 case CHXJ_SPEC_Chtml_1_0:
286 case CHXJ_SPEC_Chtml_2_0:
287 case CHXJ_SPEC_Chtml_3_0:
288 case CHXJ_SPEC_Chtml_4_0:
289 case CHXJ_SPEC_Chtml_5_0:
290 case CHXJ_SPEC_Chtml_6_0:
291 case CHXJ_SPEC_Chtml_7_0:
292 case CHXJ_SPEC_XHtml_Mobile_1_0:
293 case CHXJ_SPEC_Jhtml:
294 apr_table_unset(r->headers_in, "Cookie");
303 * It converts it from CHTML into XXML corresponding to each model.
306 * @param src [i] It is former HTML character string.
307 * @param len [i/o] It is length of former HTML character string.
310 chxj_convert(request_rec *r, const char **src, apr_size_t *len, device_table *spec, const char *ua, cookie_t **cookiep)
316 mod_chxj_config *dconf;
317 chxjconvrule_entry *entryp;
319 DBG(r,"REQ[%X] start of chxj_convert() input:[%.*s]", (unsigned int)(apr_size_t)r, (int)*len, *src);
320 dst = apr_pstrcat(r->pool, (char *)*src, NULL);
322 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
325 entryp = chxj_apply_convrule(r, dconf->convrules);
327 if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
328 DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
333 /*------------------------------------------------------------------------*/
334 /* get UserAgent from http header */
335 /*------------------------------------------------------------------------*/
336 if (entryp->user_agent)
337 user_agent = (char *)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
339 user_agent = (char *)apr_table_get(r->headers_in, HTTP_USER_AGENT);
341 DBG(r,"REQ[%X] User-Agent:[%s]", (unsigned int)(apr_size_t)r, user_agent);
342 DBG(r,"REQ[%X] content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
345 if ( ! STRNCASEEQ('t','T', "text/html", r->content_type, sizeof("text/html")-1)
346 && ! STRNCASEEQ('a','A', "application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)) {
347 DBG(r,"REQ[%X] no convert. content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
348 DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
352 if (ua && user_agent && strcasecmp(user_agent, ua) != 0) {
354 spec = chxj_specified_device(r, user_agent);
361 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
362 switch(spec->html_spec_type) {
363 case CHXJ_SPEC_Chtml_1_0:
364 case CHXJ_SPEC_Chtml_2_0:
365 case CHXJ_SPEC_Chtml_3_0:
366 case CHXJ_SPEC_Chtml_4_0:
367 case CHXJ_SPEC_Chtml_5_0:
368 case CHXJ_SPEC_Chtml_6_0:
369 case CHXJ_SPEC_Chtml_7_0:
370 case CHXJ_SPEC_XHtml_Mobile_1_0:
371 case CHXJ_SPEC_Jhtml:
372 cookie = chxj_save_cookie(r);
379 if (!r->header_only) {
382 if (convert_routine[spec->html_spec_type].encoder)
383 tmp = convert_routine[spec->html_spec_type].encoder(r,
387 if (convert_routine[spec->html_spec_type].converter) {
389 dst = convert_routine[spec->html_spec_type].converter(r,
397 dst = convert_routine[spec->html_spec_type].converter(r,
406 dst = chxj_conv_z2h_kana(r, dst, len, entryp);
409 ap_set_content_length(r, *len);
412 dst = apr_psprintf(r->pool, "\n");
421 DBG(r, "REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
428 * It converts it from HEADER.
433 chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp)
445 cookie_t *cookie = NULL;
446 int no_update_flag = 0;
448 DBG(r, "REQ[%X] start chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
451 DBG(r, "REQ[%X] r->args=[null]", (unsigned int)(apr_size_t)r);
452 DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
455 urilen = strlen(r->args);
457 result = qs_alloc_zero_byte_string(r->pool);
459 buff_pre = apr_pstrdup(r->pool, r->args);
464 pair = apr_strtok(buff_pre, "&", &pstate);
470 pair_sv = apr_pstrdup(r->pool, pair);
472 name = apr_strtok(pair, "=", &vstate);
473 value = apr_strtok(NULL, "=", &vstate);
474 if (! name) continue;
475 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
476 DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
481 buff = apr_pstrdup(r->pool, r->args);
482 DBG(r, "REQ[%X] r->args=[%s]", (unsigned int)(apr_size_t)r, buff);
491 pair = apr_strtok(buff, "&", &pstate);
497 pair_sv = apr_pstrdup(r->pool, pair);
499 name = apr_strtok(pair, "=", &vstate);
500 value = apr_strtok(NULL, "=", &vstate);
501 if (! name) continue;
502 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
503 if (strlen(result) != 0)
504 result = apr_pstrcat(r->pool, result, "&", NULL);
506 if (strcasecmp(entryp->encoding, "NONE") != 0) {
511 if (value && *value != 0) {
512 value = chxj_url_decode(r->pool, value);
513 dlen = strlen(value);
514 DBG(r, "************ before encoding[%s]", value);
516 dvalue = chxj_rencoding(r, value, &dlen);
517 dvalue = chxj_url_encode(r->pool, dvalue);
519 DBG(r, "************ after encoding[%s]", dvalue);
525 if (name && *name != 0) {
526 name = chxj_url_decode(r->pool, name);
528 dname = chxj_rencoding(r, name, &dlen);
529 dname = chxj_url_encode(r->pool, dname);
535 result = apr_pstrcat(r->pool, result, dname, "=", dvalue, NULL);
538 if (strcmp(name, pair_sv) != 0)
539 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
541 result = apr_pstrcat(r->pool, result, name, NULL);
545 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
546 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
547 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
551 if (strlen(value) == 0)
554 if (strlen(result) != 0)
555 result = apr_pstrcat(r->pool, result, "&", NULL);
557 result = apr_pstrcat(r->pool, result, &name[8], "=", value, NULL);
560 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
562 apr_table_unset(r->headers_in, "Cookie");
563 DBG(r, "REQ[%X] found cookie parameter[%s]", (unsigned int)(apr_size_t)r, value);
564 DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
565 cookie_lock_t *lock = chxj_cookie_lock(r);
566 cookie = chxj_load_cookie(r, value);
567 DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
568 if (! no_update_flag && cookie) {
569 cookie = chxj_update_cookie(r, cookie);
571 chxj_cookie_unlock(r, lock);
573 if (cookie && cookie->cookie_id) {
574 if (strlen(result) != 0)
575 result = apr_pstrcat(r->pool, result, "&", NULL);
576 result = apr_pstrcat(r->pool, result, name, "=", cookie->cookie_id, NULL);
580 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
581 if (strlen(result) != 0)
582 result = apr_pstrcat(r->pool, result, "&", NULL);
583 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
586 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
587 if (! no_update_flag) {
588 result = apr_pstrcat(r->pool, result, "&_chxj_nc=true", NULL);
592 DBG(r, "REQ[%X] result r->args=[%s]", (unsigned int)(apr_size_t)r, r->args);
593 DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
599 * It converts it from POSTDATA .
602 * @param src [i] It is POSTDATA character string.
603 * @param len [i/o] It is length of former HTML character string.
610 chxjconvrule_entry *entryp)
619 cookie_t *cookie = NULL;
621 int no_update_flag = 0;
626 DBG(r, "REQ[%X] start of chxj_input_convert()", (unsigned int)(apr_size_t)r);
629 DBG(r, "REQ[%X] end of chxj_input_convert() (input is null)", (unsigned int)(apr_size_t)r);
630 return apr_pstrdup(r->pool, "");
633 apr_pool_create(&pool, r->pool);
635 s = apr_pstrdup(pool, *src);
637 buff_pre = apr_pstrdup(pool, *src);
639 result = qs_alloc_zero_byte_string(pool);
641 DBG(r, "REQ[%X] +-------------------------------------------------------------------+", (unsigned int)(apr_size_t)r);
642 DBG(r, "REQ[%X] | BEFORE input convert source |", (unsigned int)(apr_size_t)r);
643 DBG(r, "REQ[%X] +-------------------------------------------------------------------+", (unsigned int)(apr_size_t)r);
644 for (ii=0; ii<ilen-64; ii+=64) {
645 DBG(r, "REQ[%X] | [%-*.*s] |", (unsigned int)(apr_size_t)r, 64, 64, &s[ii]);
650 if (ilen >= 64 && ((ilen-64) % 64 != 0)) {
651 DBG(r, "REQ[%X] | [%-*.*s] |", (unsigned int)(apr_size_t)r, 64, 64, &s[ii]);
653 DBG(r, "REQ[%X] +--------------------------------------------------------------------+", (unsigned int)(apr_size_t)r);
658 pair = apr_strtok(buff_pre, "&", &pstate);
664 pair_sv = apr_pstrdup(pool, pair);
666 name = apr_strtok(pair, "=", &vstate);
667 value = apr_strtok(NULL, "=", &vstate);
668 if (! name) continue;
669 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
670 DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
680 pair = apr_strtok(s, "&", &pstate);
685 name = apr_strtok(pair, "=", &vstate);
686 value = apr_strtok(NULL, "=", &vstate);
687 if (! name) continue;
688 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
689 if (strlen(result) != 0)
690 result = apr_pstrcat(pool, result, "&", NULL);
692 if (strcasecmp(entryp->encoding, "NONE") != 0) {
697 if (value && *value != 0) {
698 value = chxj_url_decode(pool, value);
699 dlen = strlen(value);
700 dvalue = chxj_rencoding(r, value, &dlen);
701 dvalue = chxj_url_encode(pool, dvalue);
707 if (name && *name != 0) {
708 name = chxj_url_decode(pool, name);
710 dname = chxj_rencoding(r, name, &dlen);
711 dname = chxj_url_encode(pool, dname);
717 result = apr_pstrcat(pool, result, dname, "=", dvalue, NULL);
720 result = apr_pstrcat(pool, result, name, "=", value, NULL);
724 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
725 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
726 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
730 if (strlen(value) == 0)
733 if (strlen(result) != 0)
734 result = apr_pstrcat(pool, result, "&", NULL);
736 if (strcasecmp(entryp->encoding, "NONE") != 0 && value && strlen(value)) {
740 dlen = strlen(value);
741 value = chxj_url_decode(pool, value);
742 dvalue = chxj_rencoding(r, value, &dlen);
743 dvalue = chxj_url_encode(pool,dvalue);
744 result = apr_pstrcat(pool, result, &name[8], "=", dvalue, NULL);
748 result = apr_pstrcat(pool, result, &name[8], "=", value, NULL);
752 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
754 apr_table_unset(r->headers_in, "Cookie");
755 DBG(r, "REQ[%X] found cookie parameter[%s]", (unsigned int)(apr_size_t)r, value);
756 DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
757 cookie_lock_t *lock = chxj_cookie_lock(r);
758 cookie = chxj_load_cookie(r, value);
759 DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
760 if (! no_update_flag && cookie) {
761 cookie = chxj_update_cookie(r, cookie);
763 chxj_cookie_unlock(r, lock);
765 if (cookie && cookie->cookie_id) {
766 if (strlen(result) != 0)
767 result = apr_pstrcat(pool, result, "&", NULL);
768 result = apr_pstrcat(pool, result, name, "=", cookie->cookie_id, NULL);
772 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
773 if (strlen(result) != 0)
774 result = apr_pstrcat(pool, result, "&", NULL);
775 result = apr_pstrcat(pool, result, name, "=", value, NULL);
778 if ( strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1) == 0) {
781 dlen = strlen(value);
783 value = chxj_url_decode(pool, value);
784 dvalue = chxj_rencoding(r, value, &dlen);
785 dvalue = chxj_url_encode(pool,dvalue);
786 if (r->args && strlen(r->args) > 0) {
787 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
790 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
795 if (strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX_ENC, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1) == 0) {
798 dlen = strlen(value);
800 value = chxj_url_decode(pool, value);
801 dvalue = chxj_rencoding(r, value, &dlen);
802 dvalue = chxj_url_encode(pool,dvalue);
803 if (r->args && strlen(r->args) > 0) {
804 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
807 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
811 DBG(r, "REQ[%X] ************************ name:[%s]", (unsigned int)(apr_size_t)r, name);
813 *len = strlen(result);
814 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
815 if (! no_update_flag) {
816 result = apr_pstrcat(pool, result, "&_chxj_nc=true", NULL);
819 DBG(r, "REQ[%X] AFTER input convert result = [%s]", (unsigned int)(apr_size_t)r, result);
820 DBG(r, "REQ[%X] end chxj_input_convert()", (unsigned int)(apr_size_t)r);
827 * The received data is returned to the filter.
829 * @param f [i/o] It is a filter.
830 * @param data [i] It is data returned to the filter.
831 * @param len [i] It is length of the data returned to the filter.
834 pass_data_to_filter(ap_filter_t *f, const char *data,
837 request_rec *r = f->r;
838 conn_rec *c = r->connection;
840 apr_bucket_brigade *bb;
843 DBG(r, "REQ[%X] start pass_data_to_filter()", (unsigned int)(apr_size_t)r);
845 bb = apr_brigade_create(r->pool, c->bucket_alloc);
846 b = apr_bucket_transient_create(data, len, c->bucket_alloc);
848 APR_BRIGADE_INSERT_TAIL(bb, b);
849 b = apr_bucket_eos_create(f->c->bucket_alloc);
850 APR_BRIGADE_INSERT_TAIL(bb, b);
852 rv = ap_pass_brigade(f->next, bb);
853 if (rv != APR_SUCCESS) {
854 DBG(r, "REQ[%X] end pass_data_to_filter() (apr_pass_brigade)", (unsigned int)(apr_size_t)r);
858 DBG(r, "REQ[%X] end pass_data_to_filter()", (unsigned int)(apr_size_t)r);
865 * It is the main loop of the output filter.
867 * @param f [i/o] It is a filter.
871 chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
877 char *user_agent = NULL;
879 mod_chxj_ctx *ctx = (mod_chxj_ctx *)f->ctx;
880 cookie_t *cookie = NULL;
881 mod_chxj_config *dconf;
882 chxjconvrule_entry *entryp = NULL;
883 device_table *spec = NULL;
887 DBG(f->r, "REQ[%X] start of chxj_output_filter()", (unsigned int)(apr_size_t)r);
890 apr_pool_create(&pool, r->pool);
892 entryp = ctx->entryp;
894 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
896 if (r->content_type) {
897 if (! STRNCASEEQ('t','T',"text/html",r->content_type, sizeof("text/html")-1)
898 && ! STRNCASEEQ('t','T',"text/xml", r->content_type, sizeof("text/xml")-1)
899 && ! STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
900 && ! (dconf->image == CHXJ_IMG_ON
901 && ! apr_table_get(r->headers_in, "CHXJ_IMG_CONV")
902 && STRNCASEEQ('i','I',"image/", r->content_type, sizeof("image/") -1)
903 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
904 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
905 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
906 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
907 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
908 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
909 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
910 || STRCASEEQ('g','G',"gif", &r->content_type[6])))) { /* GIF */
912 DBG(r, "REQ[%X] not convert content-type:[%s] dconf->image:[%d]", (unsigned int)(apr_size_t)r, r->content_type, dconf->image);
913 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
914 cookie_lock_t *lock = NULL;
915 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
916 switch(spec->html_spec_type) {
917 case CHXJ_SPEC_Chtml_1_0:
918 case CHXJ_SPEC_Chtml_2_0:
919 case CHXJ_SPEC_Chtml_3_0:
920 case CHXJ_SPEC_Chtml_4_0:
921 case CHXJ_SPEC_Chtml_5_0:
922 case CHXJ_SPEC_Chtml_6_0:
923 case CHXJ_SPEC_Chtml_7_0:
924 case CHXJ_SPEC_XHtml_Mobile_1_0:
925 case CHXJ_SPEC_Jhtml:
926 lock = chxj_cookie_lock(r);
927 cookie = chxj_save_cookie(r);
928 s_add_cookie_id_if_has_location_header(r, cookie);
929 chxj_cookie_unlock(r, lock);
935 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
936 if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
937 r->status = HTTP_MOVED_TEMPORARILY;
940 ap_pass_brigade(f->next, bb);
941 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
946 DBG(r, "REQ[%X] not convert content-type:[(null)]", (unsigned int)(apr_size_t)r);
947 ap_pass_brigade(f->next, bb);
948 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
953 for (b = APR_BRIGADE_FIRST(bb);
954 b != APR_BRIGADE_SENTINEL(bb);
955 b = APR_BUCKET_NEXT(b)) {
957 if (apr_bucket_read(b, &data, &len, APR_BLOCK_READ) == APR_SUCCESS) {
958 DBG(r, "REQ[%X] read data[%.*s]",(unsigned int)(apr_size_t)r, (int)len, data);
960 /*--------------------------------------------------------------------*/
962 /*--------------------------------------------------------------------*/
964 DBG(r, "append data start");
965 ctx = (mod_chxj_ctx *)f->ctx;
968 tmp = apr_palloc(r->pool, ctx->len);
969 memcpy(tmp, ctx->buffer, ctx->len);
971 ctx->buffer = apr_palloc(pool, ctx->len + len);
973 memcpy(ctx->buffer, tmp, ctx->len);
974 memcpy(&ctx->buffer[ctx->len], data, len);
978 DBG(r, "REQ[%X] append data end", (unsigned int)(apr_size_t)r);
981 if (APR_BUCKET_IS_EOS(b)) {
983 DBG(r, "REQ[%X] eos", (unsigned int)(apr_size_t)r);
984 /*----------------------------------------------------------------------*/
986 /*----------------------------------------------------------------------*/
988 cookie_lock_t *lock = NULL;
989 ctx = (mod_chxj_ctx *)f->ctx;
991 DBG(r, "REQ[%X] content_type=[%s]", (unsigned int)(apr_size_t)r, r->content_type);
992 lock = chxj_cookie_lock(r);
994 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
996 && (STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
997 || STRNCASEEQ('t','T',"text/html", r->content_type, sizeof("text/html")-1))) {
998 DBG(r, "REQ[%X] detect convert target:[%s]", (unsigned int)(apr_size_t)r, r->content_type);
1003 tmp = apr_palloc(pool, ctx->len + 1);
1005 memset(tmp, 0, ctx->len + 1);
1006 memcpy(tmp, ctx->buffer, ctx->len);
1008 ctx->buffer = chxj_convert(r,
1009 (const char **)&tmp,
1010 (apr_size_t *)&ctx->len,
1012 user_agent, &cookie);
1016 ctx->buffer = apr_psprintf(r->pool, "\n");
1018 ctx->buffer = chxj_convert(r,
1019 (const char **)&ctx->buffer,
1020 (apr_size_t *)&ctx->len,
1022 user_agent, &cookie);
1027 && *(char *)r->content_type == 't'
1028 && strncmp(r->content_type, "text/xml", 8) == 0) {
1029 DBG(r, "REQ[%X] text/XML", (unsigned int)(apr_size_t)r);
1037 memset(&doc, 0, sizeof(Doc));
1038 memset(&qrcode, 0, sizeof(qr_code_t));
1040 doc.parse_mode = PARSE_MODE_CHTML;
1044 qs_init_malloc(&doc);
1046 root = qs_parse_string(&doc, ctx->buffer, ctx->len);
1049 for (child = qs_get_child_node(&doc,root);
1051 child = qs_get_next_node(&doc,child)) {
1052 char *name = qs_get_node_name(&doc,child);
1053 if (strcasecmp("qrcode",name) == 0) {
1058 qs_all_free(&doc,QX_LOGMARK);
1060 r->handler = apr_psprintf(r->pool, "chxj-qrcode");
1061 chxj_qrcode_node_to_qrcode(&qrcode, root);
1062 sts = chxj_qrcode_create_image_data(&qrcode, &ctx->buffer, &ctx->len);
1064 ERR(r, "REQ[%X] qrcode create failed.", (unsigned int)(apr_size_t)r);
1065 chxj_cookie_unlock(r, lock);
1066 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1069 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1073 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
1075 && ( *r->content_type == 'i' || *r->content_type == 'I')
1076 && dconf->image == CHXJ_IMG_ON
1077 && strncasecmp("image/", r->content_type, 6) == 0
1078 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
1079 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
1080 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
1081 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
1082 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
1083 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
1084 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
1085 || STRCASEEQ('g','G',"gif", &r->content_type[6]))) { /* GIF */
1089 tmp = apr_palloc(pool, ctx->len + 1);
1091 memset(tmp, 0, ctx->len + 1);
1092 memcpy(tmp, ctx->buffer, ctx->len);
1094 chxj_convert_image(r,
1095 (const char **)&tmp,
1096 (apr_size_t *)&ctx->len);
1097 if (ctx->buffer == NULL) {
1103 apr_table_unset(r->headers_out, "Content-Length");
1104 apr_table_unset(r->err_headers_out, "Content-Length");
1105 ap_set_content_length(r, (apr_off_t)ctx->len);
1109 DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1110 s_add_cookie_id_if_has_location_header(r, cookie);
1111 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1112 if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
1113 r->status = HTTP_MOVED_TEMPORARILY;
1116 chxj_cookie_unlock(r,lock);
1117 rv = pass_data_to_filter(f,
1118 (const char *)ctx->buffer,
1119 (apr_size_t)ctx->len);
1122 chxj_cookie_unlock(r, lock);
1125 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1129 DBG(r, "REQ[%X] SAVE COOKIE[%x]", (unsigned int)(apr_size_t)r, entryp->action);
1134 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
1135 cookie_lock_t *lock = NULL;
1136 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
1137 switch(spec->html_spec_type) {
1138 case CHXJ_SPEC_Chtml_1_0:
1139 case CHXJ_SPEC_Chtml_2_0:
1140 case CHXJ_SPEC_Chtml_3_0:
1141 case CHXJ_SPEC_Chtml_4_0:
1142 case CHXJ_SPEC_Chtml_5_0:
1143 case CHXJ_SPEC_Chtml_6_0:
1144 case CHXJ_SPEC_Chtml_7_0:
1145 case CHXJ_SPEC_XHtml_Mobile_1_0:
1146 case CHXJ_SPEC_Jhtml:
1147 lock = chxj_cookie_lock(r);
1148 cookie = chxj_save_cookie(r);
1150 * Location Header Check to add cookie parameter.
1152 s_add_cookie_id_if_has_location_header(r, cookie);
1153 chxj_cookie_unlock(r, lock);
1154 apr_table_unset(r->headers_out, "Set-Cookie");
1155 apr_table_unset(r->err_headers_out, "Set-Cookie");
1162 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1163 if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
1164 r->status = HTTP_MOVED_TEMPORARILY;
1167 apr_table_setn(r->headers_out, "Content-Length", "0");
1168 DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1169 rv = pass_data_to_filter(f, (const char *)"", (apr_size_t)0);
1170 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1175 apr_brigade_destroy(bb);
1177 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1183 * Add Cookie_id if it has location header.
1186 s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie)
1188 char *location_header = (char *)apr_table_get(r->headers_out, "Location");
1189 if (! location_header) {
1190 location_header = (char *)apr_table_get(r->err_headers_out, "Location");
1192 if (cookie && location_header) {
1193 DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1194 location_header = chxj_add_cookie_parameter(r,
1197 apr_table_unset(r->headers_out, "Location");
1198 apr_table_setn(r->headers_out, "Location", location_header);
1199 DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1200 if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
1201 r->status = HTTP_MOVED_TEMPORARILY;
1207 * It is the main loop of the input filter handler.
1211 chxj_input_handler(request_rec *r)
1213 mod_chxj_config *dconf;
1214 chxjconvrule_entry *entryp = NULL;
1215 device_table *spec = NULL;
1216 char *post_data = NULL;
1217 apr_size_t post_data_len = 0;
1223 DBG(r, "start of chxj_input_handler()");
1225 if (strcasecmp(r->handler, "chxj-input-handler")) {
1226 DBG(r, "end chxj_input_handler()");
1229 apr_pool_create(&pool, r->pool);
1231 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1232 user_agent = (char*)apr_table_get(r->headers_in, "User-Agent");
1233 spec = chxj_specified_device(r, user_agent);
1234 entryp = chxj_apply_convrule(r, dconf->convrules);
1236 post_data = apr_pstrdup(pool, "");
1237 if (ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK) == OK) {
1238 if (ap_should_client_block(r)) {
1239 while (post_data_len < CHXJ_POST_MAX) {
1242 int read_bytes = ap_get_client_block(r, buffer, BUFSZ-1);
1243 if (read_bytes<=0) {
1246 buffer[read_bytes] = '\0';
1247 post_data = apr_pstrcat(pool, post_data, buffer, NULL);
1248 post_data_len += read_bytes;
1257 if (post_data_len > 0) {
1258 post_data = chxj_input_convert(r, (const char**)&post_data, (apr_size_t*)&post_data_len, entryp);
1259 DBG(r, "(in:exchange)POSTDATA:[%s]", post_data);
1263 if (dconf->forward_url_base) {
1264 url_path = apr_psprintf(pool, "%s%s", dconf->forward_url_base, r->uri);
1267 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);
1270 url_path = apr_pstrcat(pool, url_path, "?", r->args, NULL);
1272 DBG(r, "==> new url_path:[%s]", url_path);
1275 apr_table_setn(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP, r->connection->remote_ip);
1276 apr_table_unset(r->headers_in, "Content-Length");
1277 apr_table_setn(r->headers_in, "Content-Length", apr_psprintf(pool, "%" APR_SIZE_T_FMT, post_data_len));
1278 response = chxj_serf_post(r, pool, url_path, post_data, post_data_len, 1, &res_len);
1279 DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1280 DBG(r, "REQ[%X] response length:[%" APR_SIZE_T_FMT "]", (unsigned int)(apr_size_t)r, res_len);
1281 for (ii=0; ii<res_len/64; ii++) {
1282 DBG(r, "REQ[%X] response:[%.*s]", (unsigned int)(apr_size_t)r, 64, &response[ii*64]);
1284 DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1287 if ((chunked = (char *)apr_table_get(r->headers_out, "Transfer-Encoding")) != NULL) {
1288 if (strcasecmp(chunked, "chunked") == 0) {
1290 apr_table_unset(r->headers_out, "Transfer-Encoding");
1295 apr_pool_create(&wpool, r->pool);
1296 apr_bucket_brigade *bb;
1299 conn_rec *c = r->connection;
1301 bb = apr_brigade_create(wpool, c->bucket_alloc);
1302 e = apr_bucket_transient_create(response, res_len, c->bucket_alloc);
1303 APR_BRIGADE_INSERT_TAIL(bb, e);
1304 e = apr_bucket_eos_create(c->bucket_alloc);
1305 APR_BRIGADE_INSERT_TAIL(bb, e);
1306 if ((rv = ap_pass_brigade(r->output_filters, bb)) != APR_SUCCESS) {
1307 ERR(r, "REQ[%X] %s:%d failed ap_pass_brigade()", (unsigned int)(apr_size_t)r, APLOG_MARK);
1310 apr_brigade_cleanup(bb);
1313 DBG(r, "REQ[%X] end of chxj_input_handler()", (unsigned int)(apr_size_t)r);
1317 static mod_chxj_global_config *
1318 chxj_global_config_create(apr_pool_t *pool, server_rec *s)
1320 mod_chxj_global_config *conf;
1322 SDBG(s, "start chxj_global_config_create()");
1324 /*--------------------------------------------------------------------------*/
1325 /* allocate an own subpool which survives server restarts */
1326 /*--------------------------------------------------------------------------*/
1327 conf = (mod_chxj_global_config *)apr_palloc(pool,
1328 sizeof(mod_chxj_global_config));
1330 conf->cookie_db_lock = NULL;
1332 SDBG(s, "end chxj_global_config_create()");
1339 * initialize chxj module
1342 chxj_init_module(apr_pool_t *p,
1343 apr_pool_t *UNUSED(plog),
1344 apr_pool_t *UNUSED(ptemp),
1350 SDBG(s, "start chxj_init_module()");
1352 apr_pool_userdata_get(&user_data, CHXJ_MOD_CONFIG_KEY, s->process->pool);
1354 if (user_data == NULL) {
1357 * dummy user_data set.
1359 apr_pool_userdata_set(
1361 CHXJ_MOD_CONFIG_KEY,
1362 apr_pool_cleanup_null,
1364 SDBG(s, "end chxj_init_module()");
1368 ap_add_version_component(p, CHXJ_VERSION_PREFIX CHXJ_VERSION);
1370 if ((rv = apr_proc_mutex_create(&global_cookie_mutex, NULL, APR_LOCK_FCNTL, s->process->pool)) != APR_SUCCESS) {
1372 SERR(s, "%s:%d end chxj_init_module(). mutex create failure.(%d:%s)",APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1373 return HTTP_INTERNAL_SERVER_ERROR;
1376 SDBG(s, "end chxj_init_module()");
1383 chxj_child_init(apr_pool_t *UNUSED(p), server_rec *s)
1386 SDBG(s, "start chxj_child_init()");
1387 if ((rv = apr_proc_mutex_child_init(&global_cookie_mutex, NULL, s->process->pool)) != APR_SUCCESS) {
1389 SERR(s, "%s:%d ERROR end chxj_init_module(). mutex create failure.(%d:%s)", APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1391 SDBG(s, "end chxj_child_init()");
1396 * A set structure of each server is generated.
1402 chxj_config_server_create(apr_pool_t *p, server_rec *s)
1404 mod_chxj_global_config *gc;
1406 gc = chxj_global_config_create(p,s);
1413 chxj_translate_name(request_rec *r)
1415 DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1416 DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1417 DBG(r, "REQ[%X] START REQUEST (uri:[%s] args:[%s])", (unsigned int)(apr_size_t)r, r->unparsed_uri, r->args ? r->args : "");
1418 DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1419 DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1420 return chxj_trans_name(r);
1425 chxj_insert_filter(request_rec *r)
1429 mod_chxj_config *dconf;
1430 chxjconvrule_entry *entryp;
1435 DBG(r, "start chxj_insert_filter()");
1437 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1439 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
1441 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
1443 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
1444 DBG(r, "detect multipart/form-data ==> no target");
1448 spec = chxj_specified_device(r, user_agent);
1449 entryp = chxj_apply_convrule(r, dconf->convrules);
1451 DBG(r, "end chxj_insert_filter()");
1454 ctx = apr_palloc(r->pool, sizeof(*ctx));
1455 memset(ctx, 0, sizeof(*ctx));
1456 if ((rv = apr_pool_create(&ctx->pool, r->pool)) != APR_SUCCESS) {
1457 ERR(r, "failed: new pool create. rv:[%d]", rv);
1460 ctx->entryp = entryp;
1462 ctx->buffer = apr_palloc(ctx->pool, 1);
1465 if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
1470 switch(spec->html_spec_type) {
1471 case CHXJ_SPEC_Chtml_1_0:
1472 case CHXJ_SPEC_Chtml_2_0:
1473 case CHXJ_SPEC_Chtml_3_0:
1474 case CHXJ_SPEC_Chtml_4_0:
1475 case CHXJ_SPEC_Chtml_5_0:
1476 case CHXJ_SPEC_Chtml_6_0:
1477 case CHXJ_SPEC_Chtml_7_0:
1478 case CHXJ_SPEC_XHtml_Mobile_1_0:
1479 case CHXJ_SPEC_Hdml:
1480 case CHXJ_SPEC_Jhtml:
1481 case CHXJ_SPEC_Jxhtml:
1489 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
1490 ap_add_output_filter("chxj_output_filter", ctx, r, r->connection);
1491 DBG(r, "added Output Filter");
1494 DBG(r, "end chxj_insert_filter()");
1499 * The hook is registered.
1504 chxj_register_hooks(apr_pool_t *UNUSED(p))
1506 ap_hook_post_config(chxj_init_module,
1509 APR_HOOK_REALLY_FIRST);
1510 ap_hook_child_init(chxj_child_init,
1513 APR_HOOK_REALLY_FIRST);
1514 ap_register_output_filter (
1515 "chxj_output_filter",
1519 ap_hook_insert_filter(chxj_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
1520 ap_hook_handler(chxj_img_conv_format_handler, NULL, NULL, APR_HOOK_MIDDLE);
1521 ap_hook_handler(chxj_qr_code_handler, NULL, NULL, APR_HOOK_MIDDLE);
1522 ap_hook_handler(chxj_input_handler, NULL, NULL, APR_HOOK_MIDDLE);
1523 ap_hook_translate_name(chxj_translate_name, NULL, NULL, APR_HOOK_MIDDLE);
1524 ap_hook_fixups(chxj_headers_fixup, NULL, NULL, APR_HOOK_FIRST);
1529 * A set structure according to the directory is generated.
1535 chxj_create_per_dir_config(apr_pool_t *p, char *arg)
1537 mod_chxj_config *conf;
1539 conf = apr_pcalloc(p, sizeof(mod_chxj_config));
1540 conf->device_data_file = NULL;
1541 conf->devices = NULL;
1542 conf->emoji_data_file = NULL;
1544 conf->emoji_tail = NULL;
1545 conf->image = CHXJ_IMG_NONE;
1546 conf->image_cache_dir = apr_psprintf(p, "%s",DEFAULT_IMAGE_CACHE_DIR);
1547 conf->image_cache_limit = 0;
1548 conf->server_side_encoding = NULL;
1549 conf->cookie_db_dir = NULL;
1550 conf->cookie_timeout = 0;
1551 conf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
1552 conf->cookie_lazy_mode = 0;
1553 #if defined(USE_MYSQL_COOKIE)
1554 memset((void *)&conf->mysql, 0, sizeof(mysql_t));
1555 conf->mysql.port = MYSQL_PORT;
1556 conf->mysql.host = NULL;
1558 #if defined(USE_MEMCACHE_COOKIE)
1559 memset((void *)&conf->memcache, 0, sizeof(memcache_t));
1560 conf->memcache.host = NULL;
1561 conf->memcache.port = 0;
1563 conf->forward_url_base = NULL;
1564 conf->forward_server_ip = NULL;
1570 conf->dir = apr_pcalloc(p, strlen(arg)+1);
1571 memset(conf->dir, 0, strlen(arg)+1);
1572 strcpy(conf->dir, arg);
1574 conf->convrules = apr_array_make(p, 2, sizeof(chxjconvrule_entry));
1576 /* Default is copyleft */
1577 conf->image_copyright = NULL;
1584 * Merge per-directory CHXJ configurations
1587 chxj_merge_per_dir_config(apr_pool_t *p, void *basev, void *addv)
1589 mod_chxj_config *base;
1590 mod_chxj_config *add;
1591 mod_chxj_config *mrg;
1593 base = (mod_chxj_config *)basev;
1594 add = (mod_chxj_config *)addv;
1595 mrg = (mod_chxj_config *)apr_palloc(p, sizeof(mod_chxj_config));
1597 mrg->device_data_file = NULL;
1598 mrg->devices = NULL;
1599 mrg->emoji_data_file = NULL;
1600 mrg->image = CHXJ_IMG_NONE;
1601 mrg->image_cache_dir = NULL;
1602 mrg->image_copyright = NULL;
1603 mrg->image_cache_limit = 0;
1605 mrg->emoji_tail = NULL;
1606 mrg->new_line_type = NLTYPE_NIL;
1607 mrg->forward_url_base = NULL;
1608 mrg->forward_server_ip = NULL;
1610 mrg->dir = apr_pstrdup(p, add->dir);
1612 if (! add->device_data_file) {
1613 mrg->devices = base->devices;
1614 mrg->device_data_file = apr_pstrdup(p, base->device_data_file);
1617 mrg->devices = add->devices;
1618 mrg->device_data_file = apr_pstrdup(p, add->device_data_file);
1621 if (! add->emoji_data_file) {
1622 mrg->emoji = base->emoji;
1623 mrg->emoji_tail = base->emoji_tail;
1624 mrg->emoji_data_file = apr_pstrdup(p, base->emoji_data_file);
1627 mrg->emoji = add->emoji;
1628 mrg->emoji_tail = add->emoji_tail;
1629 mrg->emoji_data_file = apr_pstrdup(p, add->emoji_data_file);
1632 if (add->image == CHXJ_IMG_NONE) {
1633 mrg->image = base->image;
1636 mrg->image = add->image;
1639 if (strcasecmp(add->image_cache_dir ,DEFAULT_IMAGE_CACHE_DIR)==0) {
1640 mrg->image_cache_dir = apr_pstrdup(p, base->image_cache_dir);
1643 mrg->image_cache_dir = apr_pstrdup(p, add->image_cache_dir);
1646 if (add->image_cache_limit) {
1647 mrg->image_cache_limit = add->image_cache_limit;
1650 mrg->image_cache_limit = base->image_cache_limit;
1653 if (add->image_copyright)
1654 mrg->image_copyright = apr_pstrdup(p, add->image_copyright);
1656 mrg->image_copyright = apr_pstrdup(p, base->image_copyright);
1658 if (add->server_side_encoding) {
1659 mrg->server_side_encoding = apr_pstrdup(p, add->server_side_encoding);
1662 if (base->server_side_encoding) {
1663 mrg->server_side_encoding = apr_pstrdup(p, base->server_side_encoding);
1666 mrg->server_side_encoding = apr_pstrdup(p, DEFAULT_SERVER_SIDE_ENCODING);
1669 mrg->convrules = apr_array_append(p, add->convrules, base->convrules);
1671 if (add->cookie_db_dir) {
1672 mrg->cookie_db_dir = apr_pstrdup(p, add->cookie_db_dir);
1675 if (base->cookie_db_dir) {
1676 mrg->cookie_db_dir = apr_pstrdup(p, base->cookie_db_dir);
1679 mrg->cookie_db_dir = NULL;
1682 if (add->cookie_timeout) {
1683 mrg->cookie_timeout = add->cookie_timeout;
1686 if (base->cookie_db_dir) {
1687 mrg->cookie_timeout = base->cookie_timeout;
1690 mrg->cookie_timeout = 0;
1693 #if defined(USE_MYSQL_COOKIE)
1694 if (add->mysql.host) {
1695 mrg->mysql.host = apr_pstrdup(p, add->mysql.host);
1697 else if (base->mysql.host) {
1698 mrg->mysql.host = apr_pstrdup(p, base->mysql.host);
1701 mrg->mysql.host = NULL;
1703 if (add->mysql.port) {
1704 mrg->mysql.port = add->mysql.port;
1706 else if (base->mysql.port) {
1707 mrg->mysql.port = base->mysql.port;
1710 mrg->mysql.port = 0;
1713 if (add->mysql.database) {
1714 mrg->mysql.database = apr_pstrdup(p, add->mysql.database);
1716 else if (base->mysql.database) {
1717 mrg->mysql.database = apr_pstrdup(p, base->mysql.database);
1720 mrg->mysql.database = NULL;
1723 if (add->mysql.username) {
1724 mrg->mysql.username = apr_pstrdup(p, add->mysql.username);
1726 else if (base->mysql.username) {
1727 mrg->mysql.username = apr_pstrdup(p, base->mysql.username);
1730 mrg->mysql.username = NULL;
1733 if (add->mysql.password) {
1734 mrg->mysql.password = apr_pstrdup(p, add->mysql.password);
1736 else if (base->mysql.password) {
1737 mrg->mysql.password = apr_pstrdup(p, base->mysql.password);
1740 mrg->mysql.password = NULL;
1743 if (add->mysql.tablename) {
1744 mrg->mysql.tablename = apr_pstrdup(p, add->mysql.tablename);
1746 else if (base->mysql.tablename) {
1747 mrg->mysql.tablename = apr_pstrdup(p, base->mysql.tablename);
1750 mrg->mysql.tablename = NULL;
1753 if (add->mysql.socket_path) {
1754 mrg->mysql.socket_path = apr_pstrdup(p, add->mysql.socket_path);
1756 else if (base->mysql.socket_path) {
1757 mrg->mysql.socket_path = apr_pstrdup(p, base->mysql.socket_path);
1760 mrg->mysql.socket_path = NULL;
1763 if (add->mysql.charset) {
1764 mrg->mysql.charset = apr_pstrdup(p, add->mysql.charset);
1766 else if (base->mysql.charset) {
1767 mrg->mysql.charset = apr_pstrdup(p, base->mysql.charset);
1770 mrg->mysql.charset = NULL;
1773 #if defined(USE_MEMCACHE_COOKIE)
1774 if (add->memcache.host) {
1775 mrg->memcache.host = apr_pstrdup(p, add->memcache.host);
1777 else if (base->memcache.host) {
1778 mrg->memcache.host = apr_pstrdup(p, base->memcache.host);
1781 mrg->memcache.host = NULL;
1783 if (add->memcache.port) {
1784 mrg->memcache.port = add->memcache.port;
1786 else if (base->memcache.port) {
1787 mrg->memcache.port = base->memcache.port;
1790 mrg->memcache.port = 0;
1793 if (add->cookie_store_type) {
1794 mrg->cookie_store_type = add->cookie_store_type;
1796 else if (base->cookie_store_type) {
1797 mrg->cookie_store_type = base->cookie_store_type;
1800 mrg->cookie_store_type = COOKIE_STORE_TYPE_NONE;
1802 if (add->cookie_lazy_mode) {
1803 mrg->cookie_lazy_mode = add->cookie_lazy_mode;
1805 else if (base->cookie_lazy_mode) {
1806 mrg->cookie_lazy_mode = base->cookie_lazy_mode;
1809 mrg->cookie_lazy_mode = 0;
1811 if (add->new_line_type) {
1812 mrg->new_line_type = add->new_line_type;
1814 else if (base->new_line_type) {
1815 mrg->new_line_type = base->new_line_type;
1818 mrg->new_line_type = NLTYPE_NIL;
1825 chxj_command_parse_take5(
1838 for (;*strp == ' '||*strp == '\t'; strp++) ;
1848 for (; *strp != '\0'; strp++) {
1849 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1850 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1855 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1856 || (isquoted && *strp == '"'))
1870 for (;*strp == ' '||*strp == '\t'; strp++) ;
1879 for (; *strp != '\0'; strp++) {
1880 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1881 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1886 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1887 || (isquoted && *strp == '"'))
1900 for (;*strp == ' '||*strp == '\t'; strp++);
1908 for (; *strp != '\0'; strp++) {
1909 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1910 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1915 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1916 || (isquoted && *strp == '"'))
1928 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 == '"'))
1955 for (;*strp == ' '||*strp == '\t'; strp++);
1963 for (; *strp != '\0'; strp++) {
1964 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1965 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1970 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1971 || (isquoted && *strp == '"'))
1981 * The device definition file is loaded.
1983 * @param arg [i] The name of the device definition file is specified.
1984 * @param mconfig [i/o] The pointer to a set structure is specified.
1988 cmd_load_device_data(cmd_parms *parms, void *mconfig, const char *arg)
1990 mod_chxj_config *conf;
1995 if (strlen(arg) > 256)
1996 return "mod_chxj: device data filename too long.";
1998 conf = (mod_chxj_config *)mconfig;
1999 conf->device_data_file = apr_pstrdup(parms->pool, arg);
2001 qs_init_malloc(&doc);
2002 qs_init_root_node(&doc);
2004 qs_parse_file((Doc *)&doc, (const char *)arg);
2005 chxj_load_device_data(&doc,parms->pool, conf);
2006 qs_all_free(&doc, QX_LOGMARK);
2013 * Device definition information is loaded.
2016 * @param arg [i] The name of the device definition file is specified.
2017 * @param mconfig [i/o] The pointer to a set structure is specified.
2021 cmd_load_emoji_data(cmd_parms *parms, void *mconfig, const char *arg)
2023 mod_chxj_config *conf;
2030 if (strlen(arg) > 256)
2031 return "mod_chxj: emoji data filename too long.";
2033 conf = (mod_chxj_config *)mconfig;
2034 conf->emoji_data_file = apr_pstrdup(parms->pool, arg);
2035 qs_init_malloc(&doc);
2036 qs_init_root_node(&doc);
2038 qs_parse_file((Doc *)&doc, (const char *)arg);
2040 rtn = chxj_load_emoji_data(&doc,parms->pool, conf);
2042 qs_all_free(&doc, QX_LOGMARK);
2050 cmd_set_image_engine(cmd_parms * UNUSED(parms), void *mconfig, const char *arg)
2052 mod_chxj_config *conf;
2057 if (strlen(arg) > 256)
2058 return "image uri is too long.";
2060 conf = (mod_chxj_config*)mconfig;
2061 if (strcasecmp("ON", arg) == 0) {
2062 conf->image = CHXJ_IMG_ON;
2065 conf->image = CHXJ_IMG_OFF;
2073 cmd_set_image_cache_dir(cmd_parms *parms, void *mconfig, const char *arg)
2075 mod_chxj_config *conf;
2080 if (strlen(arg) > 256)
2081 return "cache dir name is too long.";
2083 conf = (mod_chxj_config *)mconfig;
2084 conf->image_cache_dir = apr_pstrdup(parms->pool, arg);
2091 cmd_set_image_cache_limit(cmd_parms *parms, void *mconfig, const char *arg)
2093 mod_chxj_config *conf;
2098 if (strlen(arg) > IMAGE_CACHE_LIMIT_FMT_LEN)
2099 return "cache size is too long.";
2101 conf = (mod_chxj_config *)mconfig;
2104 * I use strtol function because strtoul is not portable function.
2106 conf->image_cache_limit = (unsigned long)strtol(arg, NULL, 10);
2109 return apr_psprintf(parms->pool, "ChxjImageCacheLimit invalid value [%s] errno:[%d]", arg, errno);
2111 return apr_psprintf(parms->pool, "ChxjImageCacheLimit Out of range [%s] errno:[%d]", arg, errno);
2120 cmd_set_image_copyright(cmd_parms *parms, void *mconfig, const char *arg)
2122 mod_chxj_config *conf;
2127 if (strlen(arg) > 256)
2128 return "Copyright Flag is too long.";
2130 conf = (mod_chxj_config *)mconfig;
2131 conf->image_copyright = apr_pstrdup(parms->pool, arg);
2138 cmd_convert_rule(cmd_parms *cmd, void *mconfig, const char *arg)
2142 mod_chxj_config *dconf;
2143 chxjconvrule_entry *newrule;
2153 dconf = (mod_chxj_config *)mconfig;
2155 if (strlen(arg) > 4096)
2156 return "mod_chxj: ChxjConvertRule: is too long.";
2158 dconf = (mod_chxj_config *)mconfig;
2159 if (dconf->convrules == NULL)
2160 dconf->convrules = apr_array_make(cmd->pool,
2162 sizeof(chxjconvrule_entry));
2164 newrule = apr_array_push(dconf->convrules);
2167 newrule->action = 0;
2169 if (chxj_command_parse_take5(arg, &prm1, &prm2, &prm3, &prm4, &prm5))
2170 return "ChxjConvertRule: bad argument line";
2172 newrule->pattern = apr_pstrdup(cmd->pool, prm1);
2176 if ((action = apr_strtok(prm2, ",", &pstate)) == NULL)
2182 if (strcasecmp(CONVRULE_ENGINE_ON_CMD, action) == 0) {
2183 newrule->action |= CONVRULE_ENGINE_ON_BIT;
2186 if (strcasecmp(CONVRULE_ENGINE_OFF_CMD, action) == 0) {
2187 newrule->action |= CONVRULE_ENGINE_OFF_BIT;
2193 if (strcasecmp(CONVRULE_COOKIE_ON_CMD, action) == 0) {
2194 newrule->action |= CONVRULE_COOKIE_ON_BIT;
2200 if (strcasecmp(CONVRULE_Z2H_ON_CMD, action) == 0) {
2201 newrule->action |= CONVRULE_Z2H_ON_BIT;
2204 if (strcasecmp(CONVRULE_Z2H_OFF_CMD, action) == 0) {
2205 newrule->action |= CONVRULE_Z2H_OFF_BIT;
2216 newrule->flags |= CONVRULE_FLAG_NOTMATCH;
2220 mode = AP_REG_EXTENDED;
2221 if ((regexp = ap_pregcomp((apr_pool_t *)cmd->pool, (const char *)pp, mode)) == NULL)
2222 return "RewriteRule: cannot compile regular expression ";
2224 newrule->regexp = regexp;
2226 newrule->encoding = apr_pstrdup(cmd->pool, prm3);
2228 newrule->encoding = apr_pstrdup(cmd->pool, "none");
2230 newrule->pc_flag = CONVRULE_PC_FLAG_OFF_BIT;
2232 if (strcasecmp(CONVRULE_PC_FLAG_ON_CMD, prm4) == 0)
2233 newrule->pc_flag = CONVRULE_PC_FLAG_ON_BIT;
2235 newrule->user_agent = NULL;
2237 newrule->user_agent = apr_pstrdup(cmd->pool, prm5);
2249 mod_chxj_config *dconf;
2252 if (strlen(arg) > 4096)
2253 return "mod_chxj: ChxjCookieDir is too long.";
2255 dconf = (mod_chxj_config *)mconfig;
2257 dconf->cookie_db_dir = apr_pstrdup(cmd->pool, arg);
2264 cmd_set_cookie_timeout(
2265 cmd_parms *UNUSED(cmd),
2269 mod_chxj_config *dconf;
2271 if (strlen(arg) > 4096)
2272 return "mod_chxj: ChxjCookieTimeout is too long.";
2274 if (chxj_chk_numeric(arg) != 0)
2275 return "mod_chxj: ChxjCookieTimeout is not numeric.";
2277 dconf = (mod_chxj_config *)mconfig;
2279 dconf->cookie_timeout = atoi(arg);
2285 #if defined(USE_MYSQL_COOKIE)
2287 cmd_set_cookie_mysql_database(
2292 mod_chxj_config *dconf;
2294 if (strlen(arg) > 255)
2295 return "mod_chxj: ChxjCookieMysqlDatabase is too long.";
2297 dconf = (mod_chxj_config *)mconfig;
2299 dconf->mysql.database = apr_pstrdup(cmd->pool, arg);
2306 cmd_set_cookie_mysql_username(
2311 mod_chxj_config *dconf;
2313 if (strlen(arg) > 255)
2314 return "mod_chxj: ChxjCookieMysqlUsername is too long.";
2316 dconf = (mod_chxj_config *)mconfig;
2318 dconf->mysql.username = apr_pstrdup(cmd->pool, arg);
2325 cmd_set_cookie_mysql_password(
2330 mod_chxj_config *dconf;
2332 if (strlen(arg) > 255)
2333 return "mod_chxj: ChxjCookieMysqlPassword is too long.";
2335 dconf = (mod_chxj_config *)mconfig;
2337 dconf->mysql.password = apr_pstrdup(cmd->pool, arg);
2344 cmd_set_cookie_mysql_table_name(
2349 mod_chxj_config *dconf;
2351 if (strlen(arg) > 255)
2352 return "mod_chxj: ChxjCookieMysqlTableName is too long.";
2354 dconf = (mod_chxj_config *)mconfig;
2356 dconf->mysql.tablename = apr_pstrdup(cmd->pool, arg);
2362 cmd_set_cookie_mysql_port(
2363 cmd_parms *UNUSED(cmd),
2367 mod_chxj_config *dconf;
2369 if (strlen(arg) > 255)
2370 return "mod_chxj: ChxjCookieMysqlPort is too long.";
2372 dconf = (mod_chxj_config *)mconfig;
2374 if (chxj_chk_numeric(arg) != 0)
2375 return "mod_chxj: ChxjCookieMysqlPort is not numeric.";
2377 dconf = (mod_chxj_config *)mconfig;
2379 dconf->mysql.port = chxj_atoi(arg);
2386 cmd_set_cookie_mysql_host(
2391 mod_chxj_config *dconf;
2393 if (strlen(arg) > 255)
2394 return "mod_chxj: ChxjCookieMysqlHost is too long.";
2396 dconf = (mod_chxj_config *)mconfig;
2398 dconf->mysql.host = apr_pstrdup(cmd->pool, arg);
2405 cmd_set_cookie_mysql_socket_path(
2410 mod_chxj_config *dconf;
2412 if (strlen(arg) > 4096)
2413 return "mod_chxj: ChxjCookieMysqlSocketPath is too long.";
2415 dconf = (mod_chxj_config *)mconfig;
2417 dconf->mysql.socket_path = apr_pstrdup(cmd->pool, arg);
2424 cmd_set_cookie_mysql_charset(
2429 mod_chxj_config *dconf;
2431 if (strlen(arg) > 255)
2432 return "mod_chxj: ChxjCookieMysqlCharset is too long.";
2434 dconf = (mod_chxj_config *)mconfig;
2436 dconf->mysql.charset = apr_pstrdup(cmd->pool, arg);
2441 #if defined(USE_MEMCACHE_COOKIE)
2443 cmd_set_cookie_memcache_port(
2444 cmd_parms *UNUSED(cmd),
2448 mod_chxj_config *dconf;
2450 if (strlen(arg) > 255)
2451 return "mod_chxj: ChxjCookieMemcachePort is too long.";
2453 dconf = (mod_chxj_config *)mconfig;
2455 if (chxj_chk_numeric(arg) != 0)
2456 return "mod_chxj: ChxjCookieMemcachePort is not numeric.";
2458 dconf = (mod_chxj_config *)mconfig;
2460 dconf->memcache.port = (apr_port_t)chxj_atoi(arg);
2467 cmd_set_cookie_memcache_host(
2472 mod_chxj_config *dconf;
2474 if (strlen(arg) > 255)
2475 return "mod_chxj: ChxjCookieMemcacheHost is too long.";
2477 dconf = (mod_chxj_config *)mconfig;
2479 dconf->memcache.host = apr_pstrdup(cmd->pool, arg);
2486 cmd_set_cookie_lazy_mode(
2487 cmd_parms *UNUSED(cmd),
2491 mod_chxj_config *dconf;
2493 if (strlen(arg) > 255)
2494 return "mod_chxj: ChxjCookieLazyMode is too long.";
2496 dconf = (mod_chxj_config *)mconfig;
2498 if (strcasecmp("TRUE",arg) == 0) {
2499 dconf->cookie_lazy_mode = COOKIE_LAZY_ON;
2502 dconf->cookie_lazy_mode = COOKIE_LAZY_OFF;
2509 cmd_set_cookie_store_type(
2510 cmd_parms *UNUSED(cmd),
2514 mod_chxj_config *dconf;
2516 if (strlen(arg) > 255)
2517 return "mod_chxj: ChxjCookieStoreType is too long.";
2519 dconf = (mod_chxj_config *)mconfig;
2521 if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_DBM, arg) == 0) {
2522 dconf->cookie_store_type = COOKIE_STORE_TYPE_DBM;
2524 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MYSQL, arg) == 0) {
2525 dconf->cookie_store_type = COOKIE_STORE_TYPE_MYSQL;
2527 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MEMCACHE, arg) == 0) {
2528 dconf->cookie_store_type = COOKIE_STORE_TYPE_MEMCACHE;
2531 dconf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
2538 cmd_set_forward_url_base(
2543 mod_chxj_config *dconf;
2545 if (strlen(arg) > 255)
2546 return "mod_chxj: ChxjForwardUrlBase is too long.";
2548 dconf = (mod_chxj_config *)mconfig;
2550 dconf->forward_url_base = apr_pstrdup(cmd->pool, arg);
2556 cmd_set_forward_server_ip(
2561 mod_chxj_config *dconf;
2563 if (strlen(arg) > 255)
2564 return "mod_chxj: ChxjForwardServerIp is too long.";
2566 dconf = (mod_chxj_config *)mconfig;
2568 dconf->forward_server_ip = apr_pstrdup(cmd->pool, arg);
2574 cmd_set_new_line_type(
2575 cmd_parms *UNUSED(cmd),
2579 mod_chxj_config *dconf;
2580 if (strlen(arg) > 255)
2581 return "mod_chxj: ChxjNewLineType is too long.";
2583 dconf = (mod_chxj_config *)mconfig;
2585 if (strcasecmp(CHXJ_NEW_LINE_TYPE_CRLF, arg) == 0) {
2586 dconf->new_line_type = NLTYPE_CRLF;
2588 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_LF, arg) == 0) {
2589 dconf->new_line_type = NLTYPE_LF;
2591 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_CR, arg) == 0) {
2592 dconf->new_line_type = NLTYPE_CR;
2594 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_NONE, arg) == 0) {
2595 dconf->new_line_type = NLTYPE_NONE;
2598 return "mod_chxj: invalid value (ChxjNewLineType)";
2604 static const command_rec cmds[] = {
2606 "ChxjLoadDeviceData",
2607 cmd_load_device_data,
2610 "Load Device Data"),
2612 "ChxjLoadEmojiData",
2613 cmd_load_emoji_data,
2619 cmd_set_image_engine,
2622 "Convert Target URI"),
2624 "ChxjImageCacheDir",
2625 cmd_set_image_cache_dir,
2628 "Image Cache Directory"),
2630 "ChxjImageCacheLimit",
2631 cmd_set_image_cache_limit,
2634 "Image Cache Limit"),
2636 "ChxjImageCopyright",
2637 cmd_set_image_copyright,
2646 "an URL-applied regexp-pattern and a substitution URL"),
2652 "save cookie.db directory."),
2654 "ChxjCookieTimeout",
2655 cmd_set_cookie_timeout,
2658 "The compulsion time-out time of the cookie is specified. "),
2660 "ChxjCookieStoreType",
2661 cmd_set_cookie_store_type,
2664 "It specifies preserving of the cookie ahead. (DBM/MYSQL/MEMCACHE)"),
2666 "ChxjCookieLazyMode",
2667 cmd_set_cookie_lazy_mode,
2670 "OneTimeID is negligently done. (TRUE/FALSE)"),
2671 #if defined(USE_MYSQL_COOKIE)
2673 "ChxjCookieMysqlHost",
2674 cmd_set_cookie_mysql_host,
2677 "The MySQL database host used by saving Cookie"),
2679 "ChxjCookieMysqlPort",
2680 cmd_set_cookie_mysql_port,
2683 "The MySQL database port used by saving Cookie"),
2685 "ChxjCookieMysqlDatabase",
2686 cmd_set_cookie_mysql_database,
2689 "The MySQL database name used by saving Cookie"),
2691 "ChxjCookieMysqlUsername",
2692 cmd_set_cookie_mysql_username,
2695 "The MySQL username used by saving Cookie"),
2697 "ChxjCookieMysqlPassword",
2698 cmd_set_cookie_mysql_password,
2701 "The MySQL password used by saving Cookie"),
2703 "ChxjCookieMysqlTableName",
2704 cmd_set_cookie_mysql_table_name,
2707 "The MySQL table name used by saving Cookie"),
2709 "ChxjCookieMysqlSocketPath",
2710 cmd_set_cookie_mysql_socket_path,
2713 "The MySQL socket path used by saving Cookie"),
2715 "ChxjCookieMysqlCharset",
2716 cmd_set_cookie_mysql_charset,
2719 "The MySQL charset used by saving Cookie"),
2721 #if defined(USE_MEMCACHE_COOKIE)
2723 "ChxjCookieMemcacheHost",
2724 cmd_set_cookie_memcache_host,
2727 "The Memcached host used by saving Cookie"),
2729 "ChxjCookieMemcachePort",
2730 cmd_set_cookie_memcache_port,
2733 "The Memcached port used by saving Cookie"),
2737 cmd_set_new_line_type,
2740 "HTML new line type (NONE|CRLF|LF|CR). default is CRLF"),
2742 "ChxjForwardUrlBase",
2743 cmd_set_forward_url_base,
2746 "The forward url base(default: {request protocol}://{this server}:{this server port}"),
2748 "ChxjForwardServerIp",
2749 cmd_set_forward_server_ip,
2752 "The forward server ip(default: this server ip)"),
2757 /*----------------------------------------------------------------------------*/
2758 /* Dispatch list for API hooks */
2759 /*----------------------------------------------------------------------------*/
2760 module AP_MODULE_DECLARE_DATA chxj_module = {
2761 STANDARD20_MODULE_STUFF,
2762 chxj_create_per_dir_config, /* create per-dir config structures */
2763 chxj_merge_per_dir_config, /* merge per-dir config structures */
2764 chxj_config_server_create, /* create per-server config structures */
2765 NULL, /* merge per-server config structures */
2766 cmds, /* table of config file commands */
2767 chxj_register_hooks /* register hooks */