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"
73 #define CHXJ_VERSION_PREFIX PACKAGE_NAME "/"
74 #define CHXJ_VERSION PACKAGE_VERSION
75 #define CHXJ_POST_MAX (0x1000000)
77 converter_t convert_routine[] = {
79 /* CHXJ_SPEC_UNKNOWN */
84 /* CHXJ_SPEC_Chtml_1_0 */
85 .converter = chxj_convert_chtml10,
86 .encoder = chxj_encoding,
89 /* CHXJ_SPEC_Chtml_2_0 */
90 .converter = chxj_convert_chtml20,
91 .encoder = chxj_encoding,
94 /* CHXJ_SPEC_Chtml_3_0 */
95 .converter = chxj_convert_chtml30,
96 .encoder = chxj_encoding,
99 /* CHXJ_SPEC_Chtml_4_0 */
100 .converter = chxj_convert_chtml40,
101 .encoder = chxj_encoding,
104 /* CHXJ_SPEC_Chtml_5_0 */
105 .converter = chxj_convert_chtml50,
106 .encoder = chxj_encoding,
109 /* CHXJ_SPEC_Chtml_6_0 */
110 .converter = chxj_convert_chtml50,
111 .encoder = chxj_encoding,
114 /* CHXJ_SPEC_Chtml_7_0 */
115 .converter = chxj_convert_chtml50,
116 .encoder = chxj_encoding,
119 /* CHXJ_SPEC_XHtml_Mobile_1_0 */
120 .converter = chxj_convert_xhtml_mobile_1_0,
121 .encoder = chxj_encoding,
125 .converter = chxj_convert_hdml,
126 .encoder = chxj_encoding,
129 /* CHXJ_SPEC_Jhtml */
130 .converter = chxj_convert_jhtml,
131 .encoder = chxj_encoding,
134 /* CHXJ_SPEC_Jxhtml */
135 .converter = chxj_convert_jxhtml,
136 .encoder = chxj_encoding,
145 static int chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp);
146 static void s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie);
147 static void s_clear_cookie_header(request_rec *r, device_table *spec);
150 * Only when User-Agent is specified, the User-Agent header is camouflaged.
155 chxj_headers_fixup(request_rec *r)
157 mod_chxj_config* dconf;
158 chxjconvrule_entry* entryp;
164 DBG(r, "REQ[%X] start chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
166 DBG(r, "REQ[%X] detect internal redirect.", (unsigned int)(apr_size_t)r);
167 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
171 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
173 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
174 spec = chxj_specified_device(r, user_agent);
176 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
178 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
179 DBG(r, "REQ[%X] detect multipart/form-data ==> no target", (unsigned int)(apr_size_t)r);
180 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
183 if (r->method_number == M_POST) {
184 if (!apr_table_get(r->headers_in, "X-Chxj-Forward")) {
185 s_clear_cookie_header(r, spec);
189 s_clear_cookie_header(r, spec);
192 switch(spec->html_spec_type) {
193 case CHXJ_SPEC_Chtml_1_0:
194 case CHXJ_SPEC_Chtml_2_0:
195 case CHXJ_SPEC_Chtml_3_0:
196 case CHXJ_SPEC_Chtml_4_0:
197 case CHXJ_SPEC_Chtml_5_0:
198 case CHXJ_SPEC_Chtml_6_0:
199 case CHXJ_SPEC_Chtml_7_0:
200 case CHXJ_SPEC_XHtml_Mobile_1_0:
202 case CHXJ_SPEC_Jhtml:
203 case CHXJ_SPEC_Jxhtml:
204 entryp = chxj_apply_convrule(r, dconf->convrules);
206 DBG(r, "REQ[%X] end chxj_headers_fixup() (no pattern)", (unsigned int)(apr_size_t)r);
209 if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
210 DBG(r, "REQ[%X] end chxj_headers_fixup() (engine off)", (unsigned int)(apr_size_t)r);
214 apr_table_setn(r->headers_in,
215 CHXJ_HTTP_USER_AGENT,
218 if (entryp->user_agent)
219 apr_table_setn(r->headers_in,
223 chxj_convert_input_header(r,entryp);
228 DBG(r, "REQ[%X] end chxj_headers_fixup() (not mobile)", (unsigned int)(apr_size_t)r);
234 if (r->method_number == M_POST) {
235 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
236 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);
237 r->proxyreq = PROXYREQ_NONE;
238 r->handler = apr_psprintf(r->pool, "chxj-input-handler");
241 char *client_ip = (char *)apr_table_get(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP);
243 apr_sockaddr_t *address = NULL;
244 apr_status_t rv = apr_sockaddr_info_get(&address, ap_get_server_name(r), APR_UNSPEC, ap_get_server_port(r), 0, r->pool);
245 if (rv != APR_SUCCESS) {
247 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));
248 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
252 if (dconf->forward_server_ip) {
253 addr = dconf->forward_server_ip;
256 apr_sockaddr_ip_get(&addr, address);
258 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);
259 if (strcmp(addr, r->connection->remote_ip) == 0) {
260 r->connection->remote_ip = apr_pstrdup(r->connection->pool, client_ip);
262 if (! apr_table_get(r->headers_in, "Content-Length")) {
263 contentLength = (char *)apr_table_get(r->headers_in, "X-Chxj-Content-Length");
265 apr_table_set(r->headers_in, "Content-Length", contentLength);
272 chxj_add_device_env(r, spec);
274 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
281 s_clear_cookie_header(request_rec *r, device_table *spec)
283 switch(spec->html_spec_type) {
284 case CHXJ_SPEC_Chtml_1_0:
285 case CHXJ_SPEC_Chtml_2_0:
286 case CHXJ_SPEC_Chtml_3_0:
287 case CHXJ_SPEC_Chtml_4_0:
288 case CHXJ_SPEC_Chtml_5_0:
289 case CHXJ_SPEC_Chtml_6_0:
290 case CHXJ_SPEC_Chtml_7_0:
291 case CHXJ_SPEC_XHtml_Mobile_1_0:
292 case CHXJ_SPEC_Jhtml:
293 apr_table_unset(r->headers_in, "Cookie");
302 * It converts it from CHTML into XXML corresponding to each model.
305 * @param src [i] It is former HTML character string.
306 * @param len [i/o] It is length of former HTML character string.
309 chxj_convert(request_rec *r, const char **src, apr_size_t *len, device_table *spec, const char *ua, cookie_t **cookiep)
315 mod_chxj_config *dconf;
316 chxjconvrule_entry *entryp;
318 DBG(r,"REQ[%X] start of chxj_convert() input:[%.*s]", (unsigned int)(apr_size_t)r, (int)*len, *src);
319 dst = apr_pstrcat(r->pool, (char *)*src, NULL);
321 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
324 entryp = chxj_apply_convrule(r, dconf->convrules);
326 if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
327 DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
332 /*------------------------------------------------------------------------*/
333 /* get UserAgent from http header */
334 /*------------------------------------------------------------------------*/
335 if (entryp->user_agent)
336 user_agent = (char *)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
338 user_agent = (char *)apr_table_get(r->headers_in, HTTP_USER_AGENT);
340 DBG(r,"REQ[%X] User-Agent:[%s]", (unsigned int)(apr_size_t)r, user_agent);
341 DBG(r,"REQ[%X] content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
344 if ( ! STRNCASEEQ('t','T', "text/html", r->content_type, sizeof("text/html")-1)
345 && ! STRNCASEEQ('a','A', "application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)) {
346 DBG(r,"REQ[%X] no convert. content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
347 DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
351 if (ua && user_agent && strcasecmp(user_agent, ua) != 0) {
353 spec = chxj_specified_device(r, user_agent);
360 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
361 switch(spec->html_spec_type) {
362 case CHXJ_SPEC_Chtml_1_0:
363 case CHXJ_SPEC_Chtml_2_0:
364 case CHXJ_SPEC_Chtml_3_0:
365 case CHXJ_SPEC_Chtml_4_0:
366 case CHXJ_SPEC_Chtml_5_0:
367 case CHXJ_SPEC_Chtml_6_0:
368 case CHXJ_SPEC_Chtml_7_0:
369 case CHXJ_SPEC_XHtml_Mobile_1_0:
370 case CHXJ_SPEC_Jhtml:
371 cookie = chxj_save_cookie(r);
378 if (!r->header_only) {
381 if (convert_routine[spec->html_spec_type].encoder)
382 tmp = convert_routine[spec->html_spec_type].encoder(r,
386 if (convert_routine[spec->html_spec_type].converter) {
388 dst = convert_routine[spec->html_spec_type].converter(r,
396 dst = convert_routine[spec->html_spec_type].converter(r,
405 ap_set_content_length(r, *len);
408 dst = apr_psprintf(r->pool, "\n");
416 DBG(r, "REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
423 * It converts it from HEADER.
428 chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp)
440 cookie_t *cookie = NULL;
441 int no_update_flag = 0;
443 DBG(r, "REQ[%X] start chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
446 DBG(r, "REQ[%X] r->args=[null]", (unsigned int)(apr_size_t)r);
447 DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
450 urilen = strlen(r->args);
452 result = qs_alloc_zero_byte_string(r->pool);
454 buff_pre = apr_pstrdup(r->pool, r->args);
459 pair = apr_strtok(buff_pre, "&", &pstate);
465 pair_sv = apr_pstrdup(r->pool, pair);
467 name = apr_strtok(pair, "=", &vstate);
468 value = apr_strtok(NULL, "=", &vstate);
469 if (! name) continue;
470 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
471 DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
476 buff = apr_pstrdup(r->pool, r->args);
477 DBG(r, "REQ[%X] r->args=[%s]", (unsigned int)(apr_size_t)r, buff);
486 pair = apr_strtok(buff, "&", &pstate);
492 pair_sv = apr_pstrdup(r->pool, pair);
494 name = apr_strtok(pair, "=", &vstate);
495 value = apr_strtok(NULL, "=", &vstate);
496 if (! name) continue;
497 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
498 if (strlen(result) != 0)
499 result = apr_pstrcat(r->pool, result, "&", NULL);
501 if (strcasecmp(entryp->encoding, "NONE") != 0) {
506 if (value && *value != 0) {
507 value = chxj_url_decode(r->pool, value);
508 dlen = strlen(value);
509 DBG(r, "************ before encoding[%s]", value);
511 dvalue = chxj_rencoding(r, value, &dlen);
512 dvalue = chxj_url_encode(r->pool, dvalue);
514 DBG(r, "************ after encoding[%s]", dvalue);
520 if (name && *name != 0) {
521 name = chxj_url_decode(r->pool, name);
523 dname = chxj_rencoding(r, name, &dlen);
524 dname = chxj_url_encode(r->pool, dname);
530 result = apr_pstrcat(r->pool, result, dname, "=", dvalue, NULL);
533 if (strcmp(name, pair_sv) != 0)
534 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
536 result = apr_pstrcat(r->pool, result, name, NULL);
540 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
541 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
542 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
546 if (strlen(value) == 0)
549 if (strlen(result) != 0)
550 result = apr_pstrcat(r->pool, result, "&", NULL);
552 result = apr_pstrcat(r->pool, result, &name[8], "=", value, NULL);
555 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
557 apr_table_unset(r->headers_in, "Cookie");
558 DBG(r, "REQ[%X] found cookie parameter[%s]", (unsigned int)(apr_size_t)r, value);
559 DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
560 cookie_lock_t *lock = chxj_cookie_lock(r);
561 cookie = chxj_load_cookie(r, value);
562 DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
563 if (! no_update_flag && cookie) {
564 cookie = chxj_update_cookie(r, cookie);
566 chxj_cookie_unlock(r, lock);
568 if (cookie && cookie->cookie_id) {
569 if (strlen(result) != 0)
570 result = apr_pstrcat(r->pool, result, "&", NULL);
571 result = apr_pstrcat(r->pool, result, name, "=", cookie->cookie_id, NULL);
575 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
576 if (strlen(result) != 0)
577 result = apr_pstrcat(r->pool, result, "&", NULL);
578 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
581 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
582 if (! no_update_flag) {
583 result = apr_pstrcat(r->pool, result, "&_chxj_nc=true", NULL);
587 DBG(r, "REQ[%X] result r->args=[%s]", (unsigned int)(apr_size_t)r, r->args);
588 DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
594 * It converts it from POSTDATA .
597 * @param src [i] It is POSTDATA character string.
598 * @param len [i/o] It is length of former HTML character string.
605 chxjconvrule_entry *entryp)
614 cookie_t *cookie = NULL;
616 int no_update_flag = 0;
621 DBG(r, "REQ[%X] start of chxj_input_convert()", (unsigned int)(apr_size_t)r);
624 DBG(r, "REQ[%X] end of chxj_input_convert() (input is null)", (unsigned int)(apr_size_t)r);
625 return apr_pstrdup(r->pool, "");
628 apr_pool_create(&pool, r->pool);
630 s = apr_pstrdup(pool, *src);
632 buff_pre = apr_pstrdup(pool, *src);
634 result = qs_alloc_zero_byte_string(pool);
636 DBG(r, "REQ[%X] +-------------------------------------------------------------------+", (unsigned int)(apr_size_t)r);
637 DBG(r, "REQ[%X] | BEFORE input convert source |", (unsigned int)(apr_size_t)r);
638 DBG(r, "REQ[%X] +-------------------------------------------------------------------+", (unsigned int)(apr_size_t)r);
639 for (ii=0; ii<ilen-64; ii+=64) {
640 DBG(r, "REQ[%X] | [%-*.*s] |", (unsigned int)(apr_size_t)r, 64, 64, &s[ii]);
645 if (ilen >= 64 && ((ilen-64) % 64 != 0)) {
646 DBG(r, "REQ[%X] | [%-*.*s] |", (unsigned int)(apr_size_t)r, 64, 64, &s[ii]);
648 DBG(r, "REQ[%X] +--------------------------------------------------------------------+", (unsigned int)(apr_size_t)r);
653 pair = apr_strtok(buff_pre, "&", &pstate);
659 pair_sv = apr_pstrdup(pool, pair);
661 name = apr_strtok(pair, "=", &vstate);
662 value = apr_strtok(NULL, "=", &vstate);
663 if (! name) continue;
664 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
665 DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
675 pair = apr_strtok(s, "&", &pstate);
680 name = apr_strtok(pair, "=", &vstate);
681 value = apr_strtok(NULL, "=", &vstate);
682 if (! name) continue;
683 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
684 if (strlen(result) != 0)
685 result = apr_pstrcat(pool, result, "&", NULL);
687 if (strcasecmp(entryp->encoding, "NONE") != 0) {
692 if (value && *value != 0) {
693 value = chxj_url_decode(pool, value);
694 dlen = strlen(value);
695 dvalue = chxj_rencoding(r, value, &dlen);
696 dvalue = chxj_url_encode(pool, dvalue);
702 if (name && *name != 0) {
703 name = chxj_url_decode(pool, name);
705 dname = chxj_rencoding(r, name, &dlen);
706 dname = chxj_url_encode(pool, dname);
712 result = apr_pstrcat(pool, result, dname, "=", dvalue, NULL);
715 result = apr_pstrcat(pool, result, name, "=", value, NULL);
719 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
720 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
721 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
725 if (strlen(value) == 0)
728 if (strlen(result) != 0)
729 result = apr_pstrcat(pool, result, "&", NULL);
731 if (strcasecmp(entryp->encoding, "NONE") != 0 && value && strlen(value)) {
735 dlen = strlen(value);
736 value = chxj_url_decode(pool, value);
737 dvalue = chxj_rencoding(r, value, &dlen);
738 dvalue = chxj_url_encode(pool,dvalue);
739 result = apr_pstrcat(pool, result, &name[8], "=", dvalue, NULL);
743 result = apr_pstrcat(pool, result, &name[8], "=", value, NULL);
747 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
749 apr_table_unset(r->headers_in, "Cookie");
750 DBG(r, "REQ[%X] found cookie parameter[%s]", (unsigned int)(apr_size_t)r, value);
751 DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
752 cookie_lock_t *lock = chxj_cookie_lock(r);
753 cookie = chxj_load_cookie(r, value);
754 DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
755 if (! no_update_flag && cookie) {
756 cookie = chxj_update_cookie(r, cookie);
758 chxj_cookie_unlock(r, lock);
760 if (cookie && cookie->cookie_id) {
761 if (strlen(result) != 0)
762 result = apr_pstrcat(pool, result, "&", NULL);
763 result = apr_pstrcat(pool, result, name, "=", cookie->cookie_id, NULL);
767 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
768 if (strlen(result) != 0)
769 result = apr_pstrcat(pool, result, "&", NULL);
770 result = apr_pstrcat(pool, result, name, "=", value, NULL);
773 if ( strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1) == 0) {
776 dlen = strlen(value);
778 value = chxj_url_decode(pool, value);
779 dvalue = chxj_rencoding(r, value, &dlen);
780 dvalue = chxj_url_encode(pool,dvalue);
781 if (r->args && strlen(r->args) > 0) {
782 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
785 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
790 if (strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX_ENC, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1) == 0) {
793 dlen = strlen(value);
795 value = chxj_url_decode(pool, value);
796 dvalue = chxj_rencoding(r, value, &dlen);
797 dvalue = chxj_url_encode(pool,dvalue);
798 if (r->args && strlen(r->args) > 0) {
799 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
802 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
806 DBG(r, "REQ[%X] ************************ name:[%s]", (unsigned int)(apr_size_t)r, name);
808 *len = strlen(result);
809 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
810 if (! no_update_flag) {
811 result = apr_pstrcat(pool, result, "&_chxj_nc=true", NULL);
814 DBG(r, "REQ[%X] AFTER input convert result = [%s]", (unsigned int)(apr_size_t)r, result);
815 DBG(r, "REQ[%X] end chxj_input_convert()", (unsigned int)(apr_size_t)r);
822 * The received data is returned to the filter.
824 * @param f [i/o] It is a filter.
825 * @param data [i] It is data returned to the filter.
826 * @param len [i] It is length of the data returned to the filter.
829 pass_data_to_filter(ap_filter_t *f, const char *data,
832 request_rec *r = f->r;
833 conn_rec *c = r->connection;
835 apr_bucket_brigade *bb;
838 DBG(r, "REQ[%X] start pass_data_to_filter()", (unsigned int)(apr_size_t)r);
840 bb = apr_brigade_create(r->pool, c->bucket_alloc);
841 b = apr_bucket_transient_create(data, len, c->bucket_alloc);
843 APR_BRIGADE_INSERT_TAIL(bb, b);
844 b = apr_bucket_eos_create(f->c->bucket_alloc);
845 APR_BRIGADE_INSERT_TAIL(bb, b);
847 rv = ap_pass_brigade(f->next, bb);
848 if (rv != APR_SUCCESS) {
849 DBG(r, "REQ[%X] end pass_data_to_filter() (apr_pass_brigade)", (unsigned int)(apr_size_t)r);
853 DBG(r, "REQ[%X] end pass_data_to_filter()", (unsigned int)(apr_size_t)r);
860 * It is the main loop of the output filter.
862 * @param f [i/o] It is a filter.
866 chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
872 char *user_agent = NULL;
874 mod_chxj_ctx *ctx = (mod_chxj_ctx *)f->ctx;
875 cookie_t *cookie = NULL;
876 mod_chxj_config *dconf;
877 chxjconvrule_entry *entryp = NULL;
878 device_table *spec = NULL;
882 DBG(f->r, "REQ[%X] start of chxj_output_filter()", (unsigned int)(apr_size_t)r);
885 apr_pool_create(&pool, r->pool);
887 entryp = ctx->entryp;
889 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
891 if (r->content_type) {
892 if (! STRNCASEEQ('t','T',"text/html",r->content_type, sizeof("text/html")-1)
893 && ! STRNCASEEQ('t','T',"text/xml", r->content_type, sizeof("text/xml")-1)
894 && ! STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
895 && ! (dconf->image == CHXJ_IMG_ON
896 && ! apr_table_get(r->headers_in, "CHXJ_IMG_CONV")
897 && STRNCASEEQ('i','I',"image/", r->content_type, sizeof("image/") -1)
898 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
899 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
900 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
901 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
902 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
903 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
904 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
905 || STRCASEEQ('g','G',"gif", &r->content_type[6])))) { /* GIF */
907 DBG(r, "REQ[%X] not convert content-type:[%s] dconf->image:[%d]", (unsigned int)(apr_size_t)r, r->content_type, dconf->image);
908 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
909 cookie_lock_t *lock = NULL;
910 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
911 switch(spec->html_spec_type) {
912 case CHXJ_SPEC_Chtml_1_0:
913 case CHXJ_SPEC_Chtml_2_0:
914 case CHXJ_SPEC_Chtml_3_0:
915 case CHXJ_SPEC_Chtml_4_0:
916 case CHXJ_SPEC_Chtml_5_0:
917 case CHXJ_SPEC_Chtml_6_0:
918 case CHXJ_SPEC_Chtml_7_0:
919 case CHXJ_SPEC_XHtml_Mobile_1_0:
920 case CHXJ_SPEC_Jhtml:
921 lock = chxj_cookie_lock(r);
922 cookie = chxj_save_cookie(r);
923 s_add_cookie_id_if_has_location_header(r, cookie);
924 chxj_cookie_unlock(r, lock);
930 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
931 if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
932 r->status = HTTP_MOVED_TEMPORARILY;
935 ap_pass_brigade(f->next, bb);
936 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
941 DBG(r, "REQ[%X] not convert content-type:[(null)]", (unsigned int)(apr_size_t)r);
942 ap_pass_brigade(f->next, bb);
943 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
948 for (b = APR_BRIGADE_FIRST(bb);
949 b != APR_BRIGADE_SENTINEL(bb);
950 b = APR_BUCKET_NEXT(b)) {
952 if (apr_bucket_read(b, &data, &len, APR_BLOCK_READ) == APR_SUCCESS) {
953 DBG(r, "REQ[%X] read data[%.*s]",(unsigned int)(apr_size_t)r, (int)len, data);
955 /*--------------------------------------------------------------------*/
957 /*--------------------------------------------------------------------*/
959 DBG(r, "append data start");
960 ctx = (mod_chxj_ctx *)f->ctx;
963 tmp = apr_palloc(r->pool, ctx->len);
964 memcpy(tmp, ctx->buffer, ctx->len);
966 ctx->buffer = apr_palloc(pool, ctx->len + len);
968 memcpy(ctx->buffer, tmp, ctx->len);
969 memcpy(&ctx->buffer[ctx->len], data, len);
973 DBG(r, "REQ[%X] append data end", (unsigned int)(apr_size_t)r);
976 if (APR_BUCKET_IS_EOS(b)) {
978 DBG(r, "REQ[%X] eos", (unsigned int)(apr_size_t)r);
979 /*----------------------------------------------------------------------*/
981 /*----------------------------------------------------------------------*/
983 cookie_lock_t *lock = NULL;
984 ctx = (mod_chxj_ctx *)f->ctx;
986 DBG(r, "REQ[%X] content_type=[%s]", (unsigned int)(apr_size_t)r, r->content_type);
987 lock = chxj_cookie_lock(r);
989 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
991 && (STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
992 || STRNCASEEQ('t','T',"text/html", r->content_type, sizeof("text/html")-1))) {
993 DBG(r, "REQ[%X] detect convert target:[%s]", (unsigned int)(apr_size_t)r, r->content_type);
998 tmp = apr_palloc(pool, ctx->len + 1);
1000 memset(tmp, 0, ctx->len + 1);
1001 memcpy(tmp, ctx->buffer, ctx->len);
1003 ctx->buffer = chxj_convert(r,
1004 (const char **)&tmp,
1005 (apr_size_t *)&ctx->len,
1007 user_agent, &cookie);
1011 ctx->buffer = apr_psprintf(r->pool, "\n");
1013 ctx->buffer = chxj_convert(r,
1014 (const char **)&ctx->buffer,
1015 (apr_size_t *)&ctx->len,
1017 user_agent, &cookie);
1022 && *(char *)r->content_type == 't'
1023 && strncmp(r->content_type, "text/xml", 8) == 0) {
1024 DBG(r, "REQ[%X] text/XML", (unsigned int)(apr_size_t)r);
1032 memset(&doc, 0, sizeof(Doc));
1033 memset(&qrcode, 0, sizeof(qr_code_t));
1035 doc.parse_mode = PARSE_MODE_CHTML;
1039 qs_init_malloc(&doc);
1041 root = qs_parse_string(&doc, ctx->buffer, ctx->len);
1044 for (child = qs_get_child_node(&doc,root);
1046 child = qs_get_next_node(&doc,child)) {
1047 char *name = qs_get_node_name(&doc,child);
1048 if (strcasecmp("qrcode",name) == 0) {
1053 qs_all_free(&doc,QX_LOGMARK);
1055 r->handler = apr_psprintf(r->pool, "chxj-qrcode");
1056 chxj_qrcode_node_to_qrcode(&qrcode, root);
1057 sts = chxj_qrcode_create_image_data(&qrcode, &ctx->buffer, &ctx->len);
1059 ERR(r, "REQ[%X] qrcode create failed.", (unsigned int)(apr_size_t)r);
1060 chxj_cookie_unlock(r, lock);
1061 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1064 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1068 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
1070 && ( *r->content_type == 'i' || *r->content_type == 'I')
1071 && dconf->image == CHXJ_IMG_ON
1072 && strncasecmp("image/", r->content_type, 6) == 0
1073 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
1074 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
1075 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
1076 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
1077 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
1078 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
1079 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
1080 || STRCASEEQ('g','G',"gif", &r->content_type[6]))) { /* GIF */
1084 tmp = apr_palloc(pool, ctx->len + 1);
1086 memset(tmp, 0, ctx->len + 1);
1087 memcpy(tmp, ctx->buffer, ctx->len);
1089 chxj_convert_image(r,
1090 (const char **)&tmp,
1091 (apr_size_t *)&ctx->len);
1092 if (ctx->buffer == NULL) {
1098 apr_table_unset(r->headers_out, "Content-Length");
1099 apr_table_unset(r->err_headers_out, "Content-Length");
1100 ap_set_content_length(r, (apr_off_t)ctx->len);
1104 DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1105 s_add_cookie_id_if_has_location_header(r, cookie);
1106 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1107 if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
1108 r->status = HTTP_MOVED_TEMPORARILY;
1111 chxj_cookie_unlock(r,lock);
1112 rv = pass_data_to_filter(f,
1113 (const char *)ctx->buffer,
1114 (apr_size_t)ctx->len);
1117 chxj_cookie_unlock(r, lock);
1120 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1124 DBG(r, "REQ[%X] SAVE COOKIE[%x]", (unsigned int)(apr_size_t)r, entryp->action);
1129 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
1130 cookie_lock_t *lock = NULL;
1131 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
1132 switch(spec->html_spec_type) {
1133 case CHXJ_SPEC_Chtml_1_0:
1134 case CHXJ_SPEC_Chtml_2_0:
1135 case CHXJ_SPEC_Chtml_3_0:
1136 case CHXJ_SPEC_Chtml_4_0:
1137 case CHXJ_SPEC_Chtml_5_0:
1138 case CHXJ_SPEC_Chtml_6_0:
1139 case CHXJ_SPEC_Chtml_7_0:
1140 case CHXJ_SPEC_XHtml_Mobile_1_0:
1141 case CHXJ_SPEC_Jhtml:
1142 lock = chxj_cookie_lock(r);
1143 cookie = chxj_save_cookie(r);
1145 * Location Header Check to add cookie parameter.
1147 s_add_cookie_id_if_has_location_header(r, cookie);
1148 chxj_cookie_unlock(r, lock);
1149 apr_table_unset(r->headers_out, "Set-Cookie");
1150 apr_table_unset(r->err_headers_out, "Set-Cookie");
1157 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1158 if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
1159 r->status = HTTP_MOVED_TEMPORARILY;
1162 apr_table_setn(r->headers_out, "Content-Length", "0");
1163 DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1164 rv = pass_data_to_filter(f, (const char *)"", (apr_size_t)0);
1165 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1170 apr_brigade_destroy(bb);
1172 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1178 * Add Cookie_id if it has location header.
1181 s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie)
1183 char *location_header = (char *)apr_table_get(r->headers_out, "Location");
1184 if (! location_header) {
1185 location_header = (char *)apr_table_get(r->err_headers_out, "Location");
1187 if (cookie && location_header) {
1188 DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1189 location_header = chxj_add_cookie_parameter(r,
1192 apr_table_unset(r->headers_out, "Location");
1193 apr_table_setn(r->headers_out, "Location", location_header);
1194 DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1195 if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
1196 r->status = HTTP_MOVED_TEMPORARILY;
1202 * It is the main loop of the input filter handler.
1206 chxj_input_handler(request_rec *r)
1208 mod_chxj_config *dconf;
1209 chxjconvrule_entry *entryp = NULL;
1210 device_table *spec = NULL;
1211 char *post_data = NULL;
1212 apr_size_t post_data_len = 0;
1218 DBG(r, "start of chxj_input_handler()");
1220 if (strcasecmp(r->handler, "chxj-input-handler")) {
1221 DBG(r, "end chxj_input_handler()");
1224 apr_pool_create(&pool, r->pool);
1226 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1227 user_agent = (char*)apr_table_get(r->headers_in, "User-Agent");
1228 spec = chxj_specified_device(r, user_agent);
1229 entryp = chxj_apply_convrule(r, dconf->convrules);
1231 post_data = apr_pstrdup(pool, "");
1232 if (ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK) == OK) {
1233 if (ap_should_client_block(r)) {
1234 while (post_data_len < CHXJ_POST_MAX) {
1237 int read_bytes = ap_get_client_block(r, buffer, BUFSZ-1);
1238 if (read_bytes<=0) {
1241 buffer[read_bytes] = '\0';
1242 post_data = apr_pstrcat(pool, post_data, buffer, NULL);
1243 post_data_len += read_bytes;
1252 if (post_data_len > 0) {
1253 post_data = chxj_input_convert(r, (const char**)&post_data, (apr_size_t*)&post_data_len, entryp);
1254 DBG(r, "(in:exchange)POSTDATA:[%s]", post_data);
1258 if (dconf->forward_url_base) {
1259 url_path = apr_psprintf(pool, "%s%s", dconf->forward_url_base, r->uri);
1262 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);
1265 url_path = apr_pstrcat(pool, url_path, "?", r->args, NULL);
1267 DBG(r, "==> new url_path:[%s]", url_path);
1270 apr_table_setn(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP, r->connection->remote_ip);
1271 apr_table_unset(r->headers_in, "Content-Length");
1272 apr_table_setn(r->headers_in, "Content-Length", apr_psprintf(pool, "%" APR_SIZE_T_FMT, post_data_len));
1273 response = chxj_serf_post(r, pool, url_path, post_data, post_data_len, 1, &res_len);
1274 DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1275 DBG(r, "REQ[%X] response length:[%" APR_SIZE_T_FMT "]", (unsigned int)(apr_size_t)r, res_len);
1276 for (ii=0; ii<res_len/64; ii++) {
1277 DBG(r, "REQ[%X] response:[%.*s]", (unsigned int)(apr_size_t)r, 64, &response[ii*64]);
1279 DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1282 if ((chunked = (char *)apr_table_get(r->headers_out, "Transfer-Encoding")) != NULL) {
1283 if (strcasecmp(chunked, "chunked") == 0) {
1285 apr_table_unset(r->headers_out, "Transfer-Encoding");
1290 apr_pool_create(&wpool, r->pool);
1291 apr_bucket_brigade *bb;
1294 conn_rec *c = r->connection;
1296 bb = apr_brigade_create(wpool, c->bucket_alloc);
1297 e = apr_bucket_transient_create(response, res_len, c->bucket_alloc);
1298 APR_BRIGADE_INSERT_TAIL(bb, e);
1299 e = apr_bucket_eos_create(c->bucket_alloc);
1300 APR_BRIGADE_INSERT_TAIL(bb, e);
1301 if ((rv = ap_pass_brigade(r->output_filters, bb)) != APR_SUCCESS) {
1302 ERR(r, "REQ[%X] %s:%d failed ap_pass_brigade()", (unsigned int)(apr_size_t)r, APLOG_MARK);
1305 apr_brigade_cleanup(bb);
1308 DBG(r, "REQ[%X] end of chxj_input_handler()", (unsigned int)(apr_size_t)r);
1312 static mod_chxj_global_config *
1313 chxj_global_config_create(apr_pool_t *pool, server_rec *s)
1315 mod_chxj_global_config *conf;
1317 SDBG(s, "start chxj_global_config_create()");
1319 /*--------------------------------------------------------------------------*/
1320 /* allocate an own subpool which survives server restarts */
1321 /*--------------------------------------------------------------------------*/
1322 conf = (mod_chxj_global_config *)apr_palloc(pool,
1323 sizeof(mod_chxj_global_config));
1325 conf->cookie_db_lock = NULL;
1327 SDBG(s, "end chxj_global_config_create()");
1334 * initialize chxj module
1337 chxj_init_module(apr_pool_t *p,
1338 apr_pool_t *UNUSED(plog),
1339 apr_pool_t *UNUSED(ptemp),
1345 SDBG(s, "start chxj_init_module()");
1347 apr_pool_userdata_get(&user_data, CHXJ_MOD_CONFIG_KEY, s->process->pool);
1349 if (user_data == NULL) {
1352 * dummy user_data set.
1354 apr_pool_userdata_set(
1356 CHXJ_MOD_CONFIG_KEY,
1357 apr_pool_cleanup_null,
1359 SDBG(s, "end chxj_init_module()");
1363 ap_add_version_component(p, CHXJ_VERSION_PREFIX CHXJ_VERSION);
1365 if ((rv = apr_proc_mutex_create(&global_cookie_mutex, NULL, APR_LOCK_FCNTL, s->process->pool)) != APR_SUCCESS) {
1367 SERR(s, "%s:%d end chxj_init_module(). mutex create failure.(%d:%s)",APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1368 return HTTP_INTERNAL_SERVER_ERROR;
1371 SDBG(s, "end chxj_init_module()");
1378 chxj_child_init(apr_pool_t *UNUSED(p), server_rec *s)
1381 SDBG(s, "start chxj_child_init()");
1382 if ((rv = apr_proc_mutex_child_init(&global_cookie_mutex, NULL, s->process->pool)) != APR_SUCCESS) {
1384 SERR(s, "%s:%d ERROR end chxj_init_module(). mutex create failure.(%d:%s)", APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1386 SDBG(s, "end chxj_child_init()");
1391 * A set structure of each server is generated.
1397 chxj_config_server_create(apr_pool_t *p, server_rec *s)
1399 mod_chxj_global_config *gc;
1401 gc = chxj_global_config_create(p,s);
1408 chxj_translate_name(request_rec *r)
1410 DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1411 DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1412 DBG(r, "REQ[%X] START REQUEST (uri:[%s] args:[%s])", (unsigned int)(apr_size_t)r, r->unparsed_uri, r->args ? r->args : "");
1413 DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1414 DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1415 return chxj_trans_name(r);
1420 chxj_insert_filter(request_rec *r)
1424 mod_chxj_config *dconf;
1425 chxjconvrule_entry *entryp;
1430 DBG(r, "start chxj_insert_filter()");
1432 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1434 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
1436 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
1438 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
1439 DBG(r, "detect multipart/form-data ==> no target");
1443 spec = chxj_specified_device(r, user_agent);
1444 entryp = chxj_apply_convrule(r, dconf->convrules);
1446 DBG(r, "end chxj_insert_filter()");
1449 ctx = apr_palloc(r->pool, sizeof(*ctx));
1450 memset(ctx, 0, sizeof(*ctx));
1451 if ((rv = apr_pool_create(&ctx->pool, r->pool)) != APR_SUCCESS) {
1452 ERR(r, "failed: new pool create. rv:[%d]", rv);
1455 ctx->entryp = entryp;
1457 ctx->buffer = apr_palloc(ctx->pool, 1);
1460 if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
1465 switch(spec->html_spec_type) {
1466 case CHXJ_SPEC_Chtml_1_0:
1467 case CHXJ_SPEC_Chtml_2_0:
1468 case CHXJ_SPEC_Chtml_3_0:
1469 case CHXJ_SPEC_Chtml_4_0:
1470 case CHXJ_SPEC_Chtml_5_0:
1471 case CHXJ_SPEC_Chtml_6_0:
1472 case CHXJ_SPEC_Chtml_7_0:
1473 case CHXJ_SPEC_XHtml_Mobile_1_0:
1474 case CHXJ_SPEC_Hdml:
1475 case CHXJ_SPEC_Jhtml:
1476 case CHXJ_SPEC_Jxhtml:
1484 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
1485 ap_add_output_filter("chxj_output_filter", ctx, r, r->connection);
1486 DBG(r, "added Output Filter");
1489 DBG(r, "end chxj_insert_filter()");
1494 * The hook is registered.
1499 chxj_register_hooks(apr_pool_t *UNUSED(p))
1501 ap_hook_post_config(chxj_init_module,
1504 APR_HOOK_REALLY_FIRST);
1505 ap_hook_child_init(chxj_child_init,
1508 APR_HOOK_REALLY_FIRST);
1509 ap_register_output_filter (
1510 "chxj_output_filter",
1514 ap_hook_insert_filter(chxj_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
1515 ap_hook_handler(chxj_img_conv_format_handler, NULL, NULL, APR_HOOK_MIDDLE);
1516 ap_hook_handler(chxj_qr_code_handler, NULL, NULL, APR_HOOK_MIDDLE);
1517 ap_hook_handler(chxj_input_handler, NULL, NULL, APR_HOOK_MIDDLE);
1518 ap_hook_translate_name(chxj_translate_name, NULL, NULL, APR_HOOK_MIDDLE);
1519 ap_hook_fixups(chxj_headers_fixup, NULL, NULL, APR_HOOK_FIRST);
1524 * A set structure according to the directory is generated.
1530 chxj_create_per_dir_config(apr_pool_t *p, char *arg)
1532 mod_chxj_config *conf;
1534 conf = apr_pcalloc(p, sizeof(mod_chxj_config));
1535 conf->device_data_file = NULL;
1536 conf->devices = NULL;
1537 conf->emoji_data_file = NULL;
1539 conf->emoji_tail = NULL;
1540 conf->image = CHXJ_IMG_NONE;
1541 conf->image_cache_dir = apr_psprintf(p, "%s",DEFAULT_IMAGE_CACHE_DIR);
1542 conf->image_cache_limit = 0;
1543 conf->server_side_encoding = NULL;
1544 conf->cookie_db_dir = NULL;
1545 conf->cookie_timeout = 0;
1546 conf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
1547 conf->cookie_lazy_mode = 0;
1548 #if defined(USE_MYSQL_COOKIE)
1549 memset((void *)&conf->mysql, 0, sizeof(mysql_t));
1550 conf->mysql.port = MYSQL_PORT;
1551 conf->mysql.host = NULL;
1553 #if defined(USE_MEMCACHE_COOKIE)
1554 memset((void *)&conf->memcache, 0, sizeof(memcache_t));
1555 conf->memcache.host = NULL;
1556 conf->memcache.port = 0;
1558 conf->forward_url_base = NULL;
1559 conf->forward_server_ip = NULL;
1565 conf->dir = apr_pcalloc(p, strlen(arg)+1);
1566 memset(conf->dir, 0, strlen(arg)+1);
1567 strcpy(conf->dir, arg);
1569 conf->convrules = apr_array_make(p, 2, sizeof(chxjconvrule_entry));
1571 /* Default is copyleft */
1572 conf->image_copyright = NULL;
1579 * Merge per-directory CHXJ configurations
1582 chxj_merge_per_dir_config(apr_pool_t *p, void *basev, void *addv)
1584 mod_chxj_config *base;
1585 mod_chxj_config *add;
1586 mod_chxj_config *mrg;
1588 base = (mod_chxj_config *)basev;
1589 add = (mod_chxj_config *)addv;
1590 mrg = (mod_chxj_config *)apr_palloc(p, sizeof(mod_chxj_config));
1592 mrg->device_data_file = NULL;
1593 mrg->devices = NULL;
1594 mrg->emoji_data_file = NULL;
1595 mrg->image = CHXJ_IMG_NONE;
1596 mrg->image_cache_dir = NULL;
1597 mrg->image_copyright = NULL;
1598 mrg->image_cache_limit = 0;
1600 mrg->emoji_tail = NULL;
1601 mrg->new_line_type = NLTYPE_NIL;
1602 mrg->forward_url_base = NULL;
1603 mrg->forward_server_ip = NULL;
1605 mrg->dir = apr_pstrdup(p, add->dir);
1607 if (! add->device_data_file) {
1608 mrg->devices = base->devices;
1609 mrg->device_data_file = apr_pstrdup(p, base->device_data_file);
1612 mrg->devices = add->devices;
1613 mrg->device_data_file = apr_pstrdup(p, add->device_data_file);
1616 if (! add->emoji_data_file) {
1617 mrg->emoji = base->emoji;
1618 mrg->emoji_tail = base->emoji_tail;
1619 mrg->emoji_data_file = apr_pstrdup(p, base->emoji_data_file);
1622 mrg->emoji = add->emoji;
1623 mrg->emoji_tail = add->emoji_tail;
1624 mrg->emoji_data_file = apr_pstrdup(p, add->emoji_data_file);
1627 if (add->image == CHXJ_IMG_NONE) {
1628 mrg->image = base->image;
1631 mrg->image = add->image;
1634 if (strcasecmp(add->image_cache_dir ,DEFAULT_IMAGE_CACHE_DIR)==0) {
1635 mrg->image_cache_dir = apr_pstrdup(p, base->image_cache_dir);
1638 mrg->image_cache_dir = apr_pstrdup(p, add->image_cache_dir);
1641 if (add->image_cache_limit) {
1642 mrg->image_cache_limit = add->image_cache_limit;
1645 mrg->image_cache_limit = base->image_cache_limit;
1648 if (add->image_copyright)
1649 mrg->image_copyright = apr_pstrdup(p, add->image_copyright);
1651 mrg->image_copyright = apr_pstrdup(p, base->image_copyright);
1653 if (add->server_side_encoding) {
1654 mrg->server_side_encoding = apr_pstrdup(p, add->server_side_encoding);
1657 if (base->server_side_encoding) {
1658 mrg->server_side_encoding = apr_pstrdup(p, base->server_side_encoding);
1661 mrg->server_side_encoding = apr_pstrdup(p, DEFAULT_SERVER_SIDE_ENCODING);
1664 mrg->convrules = apr_array_append(p, add->convrules, base->convrules);
1666 if (add->cookie_db_dir) {
1667 mrg->cookie_db_dir = apr_pstrdup(p, add->cookie_db_dir);
1670 if (base->cookie_db_dir) {
1671 mrg->cookie_db_dir = apr_pstrdup(p, base->cookie_db_dir);
1674 mrg->cookie_db_dir = NULL;
1677 if (add->cookie_timeout) {
1678 mrg->cookie_timeout = add->cookie_timeout;
1681 if (base->cookie_db_dir) {
1682 mrg->cookie_timeout = base->cookie_timeout;
1685 mrg->cookie_timeout = 0;
1688 #if defined(USE_MYSQL_COOKIE)
1689 if (add->mysql.host) {
1690 mrg->mysql.host = apr_pstrdup(p, add->mysql.host);
1692 else if (base->mysql.host) {
1693 mrg->mysql.host = apr_pstrdup(p, base->mysql.host);
1696 mrg->mysql.host = NULL;
1698 if (add->mysql.port) {
1699 mrg->mysql.port = add->mysql.port;
1701 else if (base->mysql.port) {
1702 mrg->mysql.port = base->mysql.port;
1705 mrg->mysql.port = 0;
1708 if (add->mysql.database) {
1709 mrg->mysql.database = apr_pstrdup(p, add->mysql.database);
1711 else if (base->mysql.database) {
1712 mrg->mysql.database = apr_pstrdup(p, base->mysql.database);
1715 mrg->mysql.database = NULL;
1718 if (add->mysql.username) {
1719 mrg->mysql.username = apr_pstrdup(p, add->mysql.username);
1721 else if (base->mysql.username) {
1722 mrg->mysql.username = apr_pstrdup(p, base->mysql.username);
1725 mrg->mysql.username = NULL;
1728 if (add->mysql.password) {
1729 mrg->mysql.password = apr_pstrdup(p, add->mysql.password);
1731 else if (base->mysql.password) {
1732 mrg->mysql.password = apr_pstrdup(p, base->mysql.password);
1735 mrg->mysql.password = NULL;
1738 if (add->mysql.tablename) {
1739 mrg->mysql.tablename = apr_pstrdup(p, add->mysql.tablename);
1741 else if (base->mysql.tablename) {
1742 mrg->mysql.tablename = apr_pstrdup(p, base->mysql.tablename);
1745 mrg->mysql.tablename = NULL;
1748 if (add->mysql.socket_path) {
1749 mrg->mysql.socket_path = apr_pstrdup(p, add->mysql.socket_path);
1751 else if (base->mysql.socket_path) {
1752 mrg->mysql.socket_path = apr_pstrdup(p, base->mysql.socket_path);
1755 mrg->mysql.socket_path = NULL;
1758 if (add->mysql.charset) {
1759 mrg->mysql.charset = apr_pstrdup(p, add->mysql.charset);
1761 else if (base->mysql.charset) {
1762 mrg->mysql.charset = apr_pstrdup(p, base->mysql.charset);
1765 mrg->mysql.charset = NULL;
1768 #if defined(USE_MEMCACHE_COOKIE)
1769 if (add->memcache.host) {
1770 mrg->memcache.host = apr_pstrdup(p, add->memcache.host);
1772 else if (base->memcache.host) {
1773 mrg->memcache.host = apr_pstrdup(p, base->memcache.host);
1776 mrg->memcache.host = NULL;
1778 if (add->memcache.port) {
1779 mrg->memcache.port = add->memcache.port;
1781 else if (base->memcache.port) {
1782 mrg->memcache.port = base->memcache.port;
1785 mrg->memcache.port = 0;
1788 if (add->cookie_store_type) {
1789 mrg->cookie_store_type = add->cookie_store_type;
1791 else if (base->cookie_store_type) {
1792 mrg->cookie_store_type = base->cookie_store_type;
1795 mrg->cookie_store_type = COOKIE_STORE_TYPE_NONE;
1797 if (add->cookie_lazy_mode) {
1798 mrg->cookie_lazy_mode = add->cookie_lazy_mode;
1800 else if (base->cookie_lazy_mode) {
1801 mrg->cookie_lazy_mode = base->cookie_lazy_mode;
1804 mrg->cookie_lazy_mode = 0;
1806 if (add->new_line_type) {
1807 mrg->new_line_type = add->new_line_type;
1809 else if (base->new_line_type) {
1810 mrg->new_line_type = base->new_line_type;
1813 mrg->new_line_type = NLTYPE_NIL;
1820 chxj_command_parse_take5(
1833 for (;*strp == ' '||*strp == '\t'; strp++) ;
1843 for (; *strp != '\0'; strp++) {
1844 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1845 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1850 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1851 || (isquoted && *strp == '"'))
1865 for (;*strp == ' '||*strp == '\t'; strp++) ;
1874 for (; *strp != '\0'; strp++) {
1875 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1876 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1881 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1882 || (isquoted && *strp == '"'))
1895 for (;*strp == ' '||*strp == '\t'; strp++);
1903 for (; *strp != '\0'; strp++) {
1904 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1905 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1910 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1911 || (isquoted && *strp == '"'))
1923 for (;*strp == ' '||*strp == '\t'; strp++);
1931 for (; *strp != '\0'; strp++) {
1932 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1933 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1938 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1939 || (isquoted && *strp == '"'))
1950 for (;*strp == ' '||*strp == '\t'; strp++);
1958 for (; *strp != '\0'; strp++) {
1959 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1960 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1965 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1966 || (isquoted && *strp == '"'))
1976 * The device definition file is loaded.
1978 * @param arg [i] The name of the device definition file is specified.
1979 * @param mconfig [i/o] The pointer to a set structure is specified.
1983 cmd_load_device_data(cmd_parms *parms, void *mconfig, const char *arg)
1985 mod_chxj_config *conf;
1990 if (strlen(arg) > 256)
1991 return "mod_chxj: device data filename too long.";
1993 conf = (mod_chxj_config *)mconfig;
1994 conf->device_data_file = apr_pstrdup(parms->pool, arg);
1996 qs_init_malloc(&doc);
1997 qs_init_root_node(&doc);
1999 qs_parse_file((Doc *)&doc, (const char *)arg);
2000 chxj_load_device_data(&doc,parms->pool, conf);
2001 qs_all_free(&doc, QX_LOGMARK);
2008 * Device definition information is loaded.
2011 * @param arg [i] The name of the device definition file is specified.
2012 * @param mconfig [i/o] The pointer to a set structure is specified.
2016 cmd_load_emoji_data(cmd_parms *parms, void *mconfig, const char *arg)
2018 mod_chxj_config *conf;
2025 if (strlen(arg) > 256)
2026 return "mod_chxj: emoji data filename too long.";
2028 conf = (mod_chxj_config *)mconfig;
2029 conf->emoji_data_file = apr_pstrdup(parms->pool, arg);
2030 qs_init_malloc(&doc);
2031 qs_init_root_node(&doc);
2033 qs_parse_file((Doc *)&doc, (const char *)arg);
2035 rtn = chxj_load_emoji_data(&doc,parms->pool, conf);
2037 qs_all_free(&doc, QX_LOGMARK);
2045 cmd_set_image_engine(cmd_parms * UNUSED(parms), void *mconfig, const char *arg)
2047 mod_chxj_config *conf;
2052 if (strlen(arg) > 256)
2053 return "image uri is too long.";
2055 conf = (mod_chxj_config*)mconfig;
2056 if (strcasecmp("ON", arg) == 0) {
2057 conf->image = CHXJ_IMG_ON;
2060 conf->image = CHXJ_IMG_OFF;
2068 cmd_set_image_cache_dir(cmd_parms *parms, void *mconfig, const char *arg)
2070 mod_chxj_config *conf;
2075 if (strlen(arg) > 256)
2076 return "cache dir name is too long.";
2078 conf = (mod_chxj_config *)mconfig;
2079 conf->image_cache_dir = apr_pstrdup(parms->pool, arg);
2086 cmd_set_image_cache_limit(cmd_parms *parms, void *mconfig, const char *arg)
2088 mod_chxj_config *conf;
2093 if (strlen(arg) > IMAGE_CACHE_LIMIT_FMT_LEN)
2094 return "cache size is too long.";
2096 conf = (mod_chxj_config *)mconfig;
2099 * I use strtol function because strtoul is not portable function.
2101 conf->image_cache_limit = (unsigned long)strtol(arg, NULL, 10);
2104 return apr_psprintf(parms->pool, "ChxjImageCacheLimit invalid value [%s] errno:[%d]", arg, errno);
2106 return apr_psprintf(parms->pool, "ChxjImageCacheLimit Out of range [%s] errno:[%d]", arg, errno);
2115 cmd_set_image_copyright(cmd_parms *parms, void *mconfig, const char *arg)
2117 mod_chxj_config *conf;
2122 if (strlen(arg) > 256)
2123 return "Copyright Flag is too long.";
2125 conf = (mod_chxj_config *)mconfig;
2126 conf->image_copyright = apr_pstrdup(parms->pool, arg);
2133 cmd_convert_rule(cmd_parms *cmd, void *mconfig, const char *arg)
2137 mod_chxj_config *dconf;
2138 chxjconvrule_entry *newrule;
2148 dconf = (mod_chxj_config *)mconfig;
2150 if (strlen(arg) > 4096)
2151 return "mod_chxj: ChxjConvertRule: is too long.";
2153 dconf = (mod_chxj_config *)mconfig;
2154 if (dconf->convrules == NULL)
2155 dconf->convrules = apr_array_make(cmd->pool,
2157 sizeof(chxjconvrule_entry));
2159 newrule = apr_array_push(dconf->convrules);
2162 newrule->action = 0;
2164 if (chxj_command_parse_take5(arg, &prm1, &prm2, &prm3, &prm4, &prm5))
2165 return "ChxjConvertRule: bad argument line";
2167 newrule->pattern = apr_pstrdup(cmd->pool, prm1);
2171 if ((action = apr_strtok(prm2, ",", &pstate)) == NULL)
2177 if (strcasecmp(CONVRULE_ENGINE_ON_CMD, action) == 0) {
2178 newrule->action |= CONVRULE_ENGINE_ON_BIT;
2181 if (strcasecmp(CONVRULE_ENGINE_OFF_CMD, action) == 0) {
2182 newrule->action |= CONVRULE_ENGINE_OFF_BIT;
2188 if (strcasecmp(CONVRULE_COOKIE_ON_CMD, action) == 0) {
2189 newrule->action |= CONVRULE_COOKIE_ON_BIT;
2199 newrule->flags |= CONVRULE_FLAG_NOTMATCH;
2203 mode = AP_REG_EXTENDED;
2204 if ((regexp = ap_pregcomp((apr_pool_t *)cmd->pool, (const char *)pp, mode)) == NULL)
2205 return "RewriteRule: cannot compile regular expression ";
2207 newrule->regexp = regexp;
2209 newrule->encoding = apr_pstrdup(cmd->pool, prm3);
2211 newrule->encoding = apr_pstrdup(cmd->pool, "none");
2213 newrule->pc_flag = CONVRULE_PC_FLAG_OFF_BIT;
2215 if (strcasecmp(CONVRULE_PC_FLAG_ON_CMD, prm4) == 0)
2216 newrule->pc_flag = CONVRULE_PC_FLAG_ON_BIT;
2218 newrule->user_agent = NULL;
2220 newrule->user_agent = apr_pstrdup(cmd->pool, prm5);
2232 mod_chxj_config *dconf;
2235 if (strlen(arg) > 4096)
2236 return "mod_chxj: ChxjCookieDir is too long.";
2238 dconf = (mod_chxj_config *)mconfig;
2240 dconf->cookie_db_dir = apr_pstrdup(cmd->pool, arg);
2247 cmd_set_cookie_timeout(
2248 cmd_parms *UNUSED(cmd),
2252 mod_chxj_config *dconf;
2254 if (strlen(arg) > 4096)
2255 return "mod_chxj: ChxjCookieTimeout is too long.";
2257 if (chxj_chk_numeric(arg) != 0)
2258 return "mod_chxj: ChxjCookieTimeout is not numeric.";
2260 dconf = (mod_chxj_config *)mconfig;
2262 dconf->cookie_timeout = atoi(arg);
2268 #if defined(USE_MYSQL_COOKIE)
2270 cmd_set_cookie_mysql_database(
2275 mod_chxj_config *dconf;
2277 if (strlen(arg) > 255)
2278 return "mod_chxj: ChxjCookieMysqlDatabase is too long.";
2280 dconf = (mod_chxj_config *)mconfig;
2282 dconf->mysql.database = apr_pstrdup(cmd->pool, arg);
2289 cmd_set_cookie_mysql_username(
2294 mod_chxj_config *dconf;
2296 if (strlen(arg) > 255)
2297 return "mod_chxj: ChxjCookieMysqlUsername is too long.";
2299 dconf = (mod_chxj_config *)mconfig;
2301 dconf->mysql.username = apr_pstrdup(cmd->pool, arg);
2308 cmd_set_cookie_mysql_password(
2313 mod_chxj_config *dconf;
2315 if (strlen(arg) > 255)
2316 return "mod_chxj: ChxjCookieMysqlPassword is too long.";
2318 dconf = (mod_chxj_config *)mconfig;
2320 dconf->mysql.password = apr_pstrdup(cmd->pool, arg);
2327 cmd_set_cookie_mysql_table_name(
2332 mod_chxj_config *dconf;
2334 if (strlen(arg) > 255)
2335 return "mod_chxj: ChxjCookieMysqlTableName is too long.";
2337 dconf = (mod_chxj_config *)mconfig;
2339 dconf->mysql.tablename = apr_pstrdup(cmd->pool, arg);
2345 cmd_set_cookie_mysql_port(
2346 cmd_parms *UNUSED(cmd),
2350 mod_chxj_config *dconf;
2352 if (strlen(arg) > 255)
2353 return "mod_chxj: ChxjCookieMysqlPort is too long.";
2355 dconf = (mod_chxj_config *)mconfig;
2357 if (chxj_chk_numeric(arg) != 0)
2358 return "mod_chxj: ChxjCookieMysqlPort is not numeric.";
2360 dconf = (mod_chxj_config *)mconfig;
2362 dconf->mysql.port = chxj_atoi(arg);
2369 cmd_set_cookie_mysql_host(
2374 mod_chxj_config *dconf;
2376 if (strlen(arg) > 255)
2377 return "mod_chxj: ChxjCookieMysqlHost is too long.";
2379 dconf = (mod_chxj_config *)mconfig;
2381 dconf->mysql.host = apr_pstrdup(cmd->pool, arg);
2388 cmd_set_cookie_mysql_socket_path(
2393 mod_chxj_config *dconf;
2395 if (strlen(arg) > 4096)
2396 return "mod_chxj: ChxjCookieMysqlSocketPath is too long.";
2398 dconf = (mod_chxj_config *)mconfig;
2400 dconf->mysql.socket_path = apr_pstrdup(cmd->pool, arg);
2407 cmd_set_cookie_mysql_charset(
2412 mod_chxj_config *dconf;
2414 if (strlen(arg) > 255)
2415 return "mod_chxj: ChxjCookieMysqlCharset is too long.";
2417 dconf = (mod_chxj_config *)mconfig;
2419 dconf->mysql.charset = apr_pstrdup(cmd->pool, arg);
2424 #if defined(USE_MEMCACHE_COOKIE)
2426 cmd_set_cookie_memcache_port(
2427 cmd_parms *UNUSED(cmd),
2431 mod_chxj_config *dconf;
2433 if (strlen(arg) > 255)
2434 return "mod_chxj: ChxjCookieMemcachePort is too long.";
2436 dconf = (mod_chxj_config *)mconfig;
2438 if (chxj_chk_numeric(arg) != 0)
2439 return "mod_chxj: ChxjCookieMemcachePort is not numeric.";
2441 dconf = (mod_chxj_config *)mconfig;
2443 dconf->memcache.port = (apr_port_t)chxj_atoi(arg);
2450 cmd_set_cookie_memcache_host(
2455 mod_chxj_config *dconf;
2457 if (strlen(arg) > 255)
2458 return "mod_chxj: ChxjCookieMemcacheHost is too long.";
2460 dconf = (mod_chxj_config *)mconfig;
2462 dconf->memcache.host = apr_pstrdup(cmd->pool, arg);
2469 cmd_set_cookie_lazy_mode(
2470 cmd_parms *UNUSED(cmd),
2474 mod_chxj_config *dconf;
2476 if (strlen(arg) > 255)
2477 return "mod_chxj: ChxjCookieLazyMode is too long.";
2479 dconf = (mod_chxj_config *)mconfig;
2481 if (strcasecmp("TRUE",arg) == 0) {
2482 dconf->cookie_lazy_mode = COOKIE_LAZY_ON;
2485 dconf->cookie_lazy_mode = COOKIE_LAZY_OFF;
2492 cmd_set_cookie_store_type(
2493 cmd_parms *UNUSED(cmd),
2497 mod_chxj_config *dconf;
2499 if (strlen(arg) > 255)
2500 return "mod_chxj: ChxjCookieStoreType is too long.";
2502 dconf = (mod_chxj_config *)mconfig;
2504 if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_DBM, arg) == 0) {
2505 dconf->cookie_store_type = COOKIE_STORE_TYPE_DBM;
2507 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MYSQL, arg) == 0) {
2508 dconf->cookie_store_type = COOKIE_STORE_TYPE_MYSQL;
2510 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MEMCACHE, arg) == 0) {
2511 dconf->cookie_store_type = COOKIE_STORE_TYPE_MEMCACHE;
2514 dconf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
2521 cmd_set_forward_url_base(
2526 mod_chxj_config *dconf;
2528 if (strlen(arg) > 255)
2529 return "mod_chxj: ChxjForwardUrlBase is too long.";
2531 dconf = (mod_chxj_config *)mconfig;
2533 dconf->forward_url_base = apr_pstrdup(cmd->pool, arg);
2539 cmd_set_forward_server_ip(
2544 mod_chxj_config *dconf;
2546 if (strlen(arg) > 255)
2547 return "mod_chxj: ChxjForwardServerIp is too long.";
2549 dconf = (mod_chxj_config *)mconfig;
2551 dconf->forward_server_ip = apr_pstrdup(cmd->pool, arg);
2557 cmd_set_new_line_type(
2558 cmd_parms *UNUSED(cmd),
2562 mod_chxj_config *dconf;
2563 if (strlen(arg) > 255)
2564 return "mod_chxj: ChxjNewLineType is too long.";
2566 dconf = (mod_chxj_config *)mconfig;
2568 if (strcasecmp(CHXJ_NEW_LINE_TYPE_CRLF, arg) == 0) {
2569 dconf->new_line_type = NLTYPE_CRLF;
2571 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_LF, arg) == 0) {
2572 dconf->new_line_type = NLTYPE_LF;
2574 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_CR, arg) == 0) {
2575 dconf->new_line_type = NLTYPE_CR;
2577 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_NONE, arg) == 0) {
2578 dconf->new_line_type = NLTYPE_NONE;
2581 return "mod_chxj: invalid value (ChxjNewLineType)";
2587 static const command_rec cmds[] = {
2589 "ChxjLoadDeviceData",
2590 cmd_load_device_data,
2593 "Load Device Data"),
2595 "ChxjLoadEmojiData",
2596 cmd_load_emoji_data,
2602 cmd_set_image_engine,
2605 "Convert Target URI"),
2607 "ChxjImageCacheDir",
2608 cmd_set_image_cache_dir,
2611 "Image Cache Directory"),
2613 "ChxjImageCacheLimit",
2614 cmd_set_image_cache_limit,
2617 "Image Cache Limit"),
2619 "ChxjImageCopyright",
2620 cmd_set_image_copyright,
2629 "an URL-applied regexp-pattern and a substitution URL"),
2635 "save cookie.db directory."),
2637 "ChxjCookieTimeout",
2638 cmd_set_cookie_timeout,
2641 "The compulsion time-out time of the cookie is specified. "),
2643 "ChxjCookieStoreType",
2644 cmd_set_cookie_store_type,
2647 "It specifies preserving of the cookie ahead. (DBM/MYSQL/MEMCACHE)"),
2649 "ChxjCookieLazyMode",
2650 cmd_set_cookie_lazy_mode,
2653 "OneTimeID is negligently done. (TRUE/FALSE)"),
2654 #if defined(USE_MYSQL_COOKIE)
2656 "ChxjCookieMysqlHost",
2657 cmd_set_cookie_mysql_host,
2660 "The MySQL database host used by saving Cookie"),
2662 "ChxjCookieMysqlPort",
2663 cmd_set_cookie_mysql_port,
2666 "The MySQL database port used by saving Cookie"),
2668 "ChxjCookieMysqlDatabase",
2669 cmd_set_cookie_mysql_database,
2672 "The MySQL database name used by saving Cookie"),
2674 "ChxjCookieMysqlUsername",
2675 cmd_set_cookie_mysql_username,
2678 "The MySQL username used by saving Cookie"),
2680 "ChxjCookieMysqlPassword",
2681 cmd_set_cookie_mysql_password,
2684 "The MySQL password used by saving Cookie"),
2686 "ChxjCookieMysqlTableName",
2687 cmd_set_cookie_mysql_table_name,
2690 "The MySQL table name used by saving Cookie"),
2692 "ChxjCookieMysqlSocketPath",
2693 cmd_set_cookie_mysql_socket_path,
2696 "The MySQL socket path used by saving Cookie"),
2698 "ChxjCookieMysqlCharset",
2699 cmd_set_cookie_mysql_charset,
2702 "The MySQL charset used by saving Cookie"),
2704 #if defined(USE_MEMCACHE_COOKIE)
2706 "ChxjCookieMemcacheHost",
2707 cmd_set_cookie_memcache_host,
2710 "The Memcached host used by saving Cookie"),
2712 "ChxjCookieMemcachePort",
2713 cmd_set_cookie_memcache_port,
2716 "The Memcached port used by saving Cookie"),
2720 cmd_set_new_line_type,
2723 "HTML new line type (NONE|CRLF|LF|CR). default is CRLF"),
2725 "ChxjForwardUrlBase",
2726 cmd_set_forward_url_base,
2729 "The forward url base(default: {request protocol}://{this server}:{this server port}"),
2731 "ChxjForwardServerIp",
2732 cmd_set_forward_server_ip,
2735 "The forward server ip(default: this server ip)"),
2740 /*----------------------------------------------------------------------------*/
2741 /* Dispatch list for API hooks */
2742 /*----------------------------------------------------------------------------*/
2743 module AP_MODULE_DECLARE_DATA chxj_module = {
2744 STANDARD20_MODULE_STUFF,
2745 chxj_create_per_dir_config, /* create per-dir config structures */
2746 chxj_merge_per_dir_config, /* merge per-dir config structures */
2747 chxj_config_server_create, /* create per-server config structures */
2748 NULL, /* merge per-server config structures */
2749 cmds, /* table of config file commands */
2750 chxj_register_hooks /* register hooks */