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"
72 #define CHXJ_VERSION_PREFIX PACKAGE_NAME "/"
73 #define CHXJ_VERSION PACKAGE_VERSION
74 #define CHXJ_POST_MAX (0x1000000)
76 converter_t convert_routine[] = {
78 /* CHXJ_SPEC_UNKNOWN */
83 /* CHXJ_SPEC_Chtml_1_0 */
84 .converter = chxj_convert_chtml10,
85 .encoder = chxj_encoding,
88 /* CHXJ_SPEC_Chtml_2_0 */
89 .converter = chxj_convert_chtml20,
90 .encoder = chxj_encoding,
93 /* CHXJ_SPEC_Chtml_3_0 */
94 .converter = chxj_convert_chtml30,
95 .encoder = chxj_encoding,
98 /* CHXJ_SPEC_Chtml_4_0 */
99 .converter = chxj_convert_chtml40,
100 .encoder = chxj_encoding,
103 /* CHXJ_SPEC_Chtml_5_0 */
104 .converter = chxj_convert_chtml50,
105 .encoder = chxj_encoding,
108 /* CHXJ_SPEC_Chtml_6_0 */
109 .converter = chxj_convert_chtml50,
110 .encoder = chxj_encoding,
113 /* CHXJ_SPEC_Chtml_7_0 */
114 .converter = chxj_convert_chtml50,
115 .encoder = chxj_encoding,
118 /* CHXJ_SPEC_XHtml_Mobile_1_0 */
119 .converter = chxj_convert_xhtml_mobile_1_0,
120 .encoder = chxj_encoding,
124 .converter = chxj_convert_hdml,
125 .encoder = chxj_encoding,
128 /* CHXJ_SPEC_Jhtml */
129 .converter = chxj_convert_jhtml,
130 .encoder = chxj_encoding,
133 /* CHXJ_SPEC_Jxhtml */
134 .converter = chxj_convert_jxhtml,
135 .encoder = chxj_encoding,
144 static int chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp);
145 static void s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie);
146 static void s_clear_cookie_header(request_rec *r, device_table *spec);
149 * Only when User-Agent is specified, the User-Agent header is camouflaged.
154 chxj_headers_fixup(request_rec *r)
156 mod_chxj_config* dconf;
157 chxjconvrule_entry* entryp;
163 DBG(r, "REQ[%X] start chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
165 DBG(r, "REQ[%X] detect internal redirect.", (unsigned int)(apr_size_t)r);
166 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
170 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
172 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
173 spec = chxj_specified_device(r, user_agent);
175 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
177 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
178 DBG(r, "REQ[%X] detect multipart/form-data ==> no target", (unsigned int)(apr_size_t)r);
179 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
182 if (r->method_number == M_POST) {
183 if (!apr_table_get(r->headers_in, "X-Chxj-Forward")) {
184 s_clear_cookie_header(r, spec);
188 s_clear_cookie_header(r, spec);
191 switch(spec->html_spec_type) {
192 case CHXJ_SPEC_Chtml_1_0:
193 case CHXJ_SPEC_Chtml_2_0:
194 case CHXJ_SPEC_Chtml_3_0:
195 case CHXJ_SPEC_Chtml_4_0:
196 case CHXJ_SPEC_Chtml_5_0:
197 case CHXJ_SPEC_Chtml_6_0:
198 case CHXJ_SPEC_Chtml_7_0:
199 case CHXJ_SPEC_XHtml_Mobile_1_0:
201 case CHXJ_SPEC_Jhtml:
202 case CHXJ_SPEC_Jxhtml:
203 entryp = chxj_apply_convrule(r, dconf->convrules);
205 DBG(r, "REQ[%X] end chxj_headers_fixup() (no pattern)", (unsigned int)(apr_size_t)r);
208 if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
209 DBG(r, "REQ[%X] end chxj_headers_fixup() (engine off)", (unsigned int)(apr_size_t)r);
213 apr_table_setn(r->headers_in,
214 CHXJ_HTTP_USER_AGENT,
217 if (entryp->user_agent)
218 apr_table_setn(r->headers_in,
222 chxj_convert_input_header(r,entryp);
227 DBG(r, "REQ[%X] end chxj_headers_fixup() (not mobile)", (unsigned int)(apr_size_t)r);
233 if (r->method_number == M_POST) {
234 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
235 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);
236 r->proxyreq = PROXYREQ_NONE;
237 r->handler = apr_psprintf(r->pool, "chxj-input-handler");
240 char *client_ip = (char *)apr_table_get(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP);
242 apr_sockaddr_t *address = NULL;
243 apr_status_t rv = apr_sockaddr_info_get(&address, ap_get_server_name(r), APR_UNSPEC, ap_get_server_port(r), 0, r->pool);
244 if (rv != APR_SUCCESS) {
246 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));
247 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
251 if (dconf->forward_server_ip) {
252 addr = dconf->forward_server_ip;
255 apr_sockaddr_ip_get(&addr, address);
257 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);
258 if (strcmp(addr, r->connection->remote_ip) == 0) {
259 r->connection->remote_ip = apr_pstrdup(r->connection->pool, client_ip);
261 if (! apr_table_get(r->headers_in, "Content-Length")) {
262 contentLength = (char *)apr_table_get(r->headers_in, "X-Chxj-Content-Length");
264 apr_table_set(r->headers_in, "Content-Length", contentLength);
271 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
278 s_clear_cookie_header(request_rec *r, device_table *spec)
280 switch(spec->html_spec_type) {
281 case CHXJ_SPEC_Chtml_1_0:
282 case CHXJ_SPEC_Chtml_2_0:
283 case CHXJ_SPEC_Chtml_3_0:
284 case CHXJ_SPEC_Chtml_4_0:
285 case CHXJ_SPEC_Chtml_5_0:
286 case CHXJ_SPEC_Chtml_6_0:
287 case CHXJ_SPEC_Chtml_7_0:
288 case CHXJ_SPEC_XHtml_Mobile_1_0:
289 case CHXJ_SPEC_Jhtml:
290 apr_table_unset(r->headers_in, "Cookie");
299 * It converts it from CHTML into XXML corresponding to each model.
302 * @param src [i] It is former HTML character string.
303 * @param len [i/o] It is length of former HTML character string.
306 chxj_convert(request_rec *r, const char **src, apr_size_t *len, device_table *spec, const char *ua, cookie_t **cookiep)
312 mod_chxj_config *dconf;
313 chxjconvrule_entry *entryp;
315 DBG(r,"REQ[%X] start of chxj_convert() input:[%.*s]", (unsigned int)(apr_size_t)r, (int)*len, *src);
316 dst = apr_pstrcat(r->pool, (char *)*src, NULL);
318 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
321 entryp = chxj_apply_convrule(r, dconf->convrules);
323 if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
324 DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
329 /*------------------------------------------------------------------------*/
330 /* get UserAgent from http header */
331 /*------------------------------------------------------------------------*/
332 if (entryp->user_agent)
333 user_agent = (char *)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
335 user_agent = (char *)apr_table_get(r->headers_in, HTTP_USER_AGENT);
337 DBG(r,"REQ[%X] User-Agent:[%s]", (unsigned int)(apr_size_t)r, user_agent);
338 DBG(r,"REQ[%X] content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
341 if ( ! STRNCASEEQ('t','T', "text/html", r->content_type, sizeof("text/html")-1)
342 && ! STRNCASEEQ('a','A', "application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)) {
343 DBG(r,"REQ[%X] no convert. content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
344 DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
348 if (ua && user_agent && strcasecmp(user_agent, ua) != 0) {
350 spec = chxj_specified_device(r, user_agent);
357 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
358 switch(spec->html_spec_type) {
359 case CHXJ_SPEC_Chtml_1_0:
360 case CHXJ_SPEC_Chtml_2_0:
361 case CHXJ_SPEC_Chtml_3_0:
362 case CHXJ_SPEC_Chtml_4_0:
363 case CHXJ_SPEC_Chtml_5_0:
364 case CHXJ_SPEC_Chtml_6_0:
365 case CHXJ_SPEC_Chtml_7_0:
366 case CHXJ_SPEC_XHtml_Mobile_1_0:
367 case CHXJ_SPEC_Jhtml:
368 cookie = chxj_save_cookie(r);
375 if (!r->header_only) {
378 if (convert_routine[spec->html_spec_type].encoder)
379 tmp = convert_routine[spec->html_spec_type].encoder(r,
383 if (convert_routine[spec->html_spec_type].converter) {
385 dst = convert_routine[spec->html_spec_type].converter(r,
393 dst = convert_routine[spec->html_spec_type].converter(r,
402 ap_set_content_length(r, *len);
405 dst = apr_psprintf(r->pool, "\n");
413 DBG(r, "REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
420 * It converts it from HEADER.
425 chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp)
437 cookie_t *cookie = NULL;
438 int no_update_flag = 0;
440 DBG(r, "REQ[%X] start chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
443 DBG(r, "REQ[%X] r->args=[null]", (unsigned int)(apr_size_t)r);
444 DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
447 urilen = strlen(r->args);
449 result = qs_alloc_zero_byte_string(r->pool);
451 buff_pre = apr_pstrdup(r->pool, r->args);
456 pair = apr_strtok(buff_pre, "&", &pstate);
462 pair_sv = apr_pstrdup(r->pool, pair);
464 name = apr_strtok(pair, "=", &vstate);
465 value = apr_strtok(NULL, "=", &vstate);
466 if (! name) continue;
467 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
468 DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
473 buff = apr_pstrdup(r->pool, r->args);
474 DBG(r, "REQ[%X] r->args=[%s]", (unsigned int)(apr_size_t)r, buff);
483 pair = apr_strtok(buff, "&", &pstate);
489 pair_sv = apr_pstrdup(r->pool, pair);
491 name = apr_strtok(pair, "=", &vstate);
492 value = apr_strtok(NULL, "=", &vstate);
493 if (! name) continue;
494 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
495 if (strlen(result) != 0)
496 result = apr_pstrcat(r->pool, result, "&", NULL);
498 if (strcasecmp(entryp->encoding, "NONE") != 0) {
503 if (value && *value != 0) {
504 value = chxj_url_decode(r->pool, value);
505 dlen = strlen(value);
506 DBG(r, "************ before encoding[%s]", value);
508 dvalue = chxj_rencoding(r, value, &dlen);
509 dvalue = chxj_url_encode(r->pool, dvalue);
511 DBG(r, "************ after encoding[%s]", dvalue);
517 if (name && *name != 0) {
518 name = chxj_url_decode(r->pool, name);
520 dname = chxj_rencoding(r, name, &dlen);
521 dname = chxj_url_encode(r->pool, dname);
527 result = apr_pstrcat(r->pool, result, dname, "=", dvalue, NULL);
530 if (strcmp(name, pair_sv) != 0)
531 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
533 result = apr_pstrcat(r->pool, result, name, NULL);
537 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
538 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
539 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
543 if (strlen(value) == 0)
546 if (strlen(result) != 0)
547 result = apr_pstrcat(r->pool, result, "&", NULL);
549 result = apr_pstrcat(r->pool, result, &name[8], "=", value, NULL);
552 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
554 apr_table_unset(r->headers_in, "Cookie");
555 DBG(r, "REQ[%X] found cookie parameter[%s]", (unsigned int)(apr_size_t)r, value);
556 DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
557 cookie_lock_t *lock = chxj_cookie_lock(r);
558 cookie = chxj_load_cookie(r, value);
559 DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
560 if (! no_update_flag && cookie) {
561 cookie = chxj_update_cookie(r, cookie);
563 chxj_cookie_unlock(r, lock);
565 if (cookie && cookie->cookie_id) {
566 if (strlen(result) != 0)
567 result = apr_pstrcat(r->pool, result, "&", NULL);
568 result = apr_pstrcat(r->pool, result, name, "=", cookie->cookie_id, NULL);
572 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
573 if (strlen(result) != 0)
574 result = apr_pstrcat(r->pool, result, "&", NULL);
575 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
578 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
579 if (! no_update_flag) {
580 result = apr_pstrcat(r->pool, result, "&_chxj_nc=true", NULL);
584 DBG(r, "REQ[%X] result r->args=[%s]", (unsigned int)(apr_size_t)r, r->args);
585 DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
591 * It converts it from POSTDATA .
594 * @param src [i] It is POSTDATA character string.
595 * @param len [i/o] It is length of former HTML character string.
602 chxjconvrule_entry *entryp)
611 cookie_t *cookie = NULL;
613 int no_update_flag = 0;
618 DBG(r, "REQ[%X] start of chxj_input_convert()", (unsigned int)(apr_size_t)r);
621 DBG(r, "REQ[%X] end of chxj_input_convert() (input is null)", (unsigned int)(apr_size_t)r);
622 return apr_pstrdup(r->pool, "");
625 apr_pool_create(&pool, r->pool);
627 s = apr_pstrdup(pool, *src);
629 buff_pre = apr_pstrdup(pool, *src);
631 result = qs_alloc_zero_byte_string(pool);
633 DBG(r, "REQ[%X] +-------------------------------------------------------------------+", (unsigned int)(apr_size_t)r);
634 DBG(r, "REQ[%X] | BEFORE input convert source |", (unsigned int)(apr_size_t)r);
635 DBG(r, "REQ[%X] +-------------------------------------------------------------------+", (unsigned int)(apr_size_t)r);
636 for (ii=0; ii<ilen-64; ii+=64) {
637 DBG(r, "REQ[%X] | [%-*.*s] |", (unsigned int)(apr_size_t)r, 64, 64, &s[ii]);
639 DBG(r, "REQ[%X] | [%-*.*s] |", (unsigned int)(apr_size_t)r, 64, 64, &s[ii]);
640 DBG(r, "REQ[%X] +--------------------------------------------------------------------+", (unsigned int)(apr_size_t)r);
645 pair = apr_strtok(buff_pre, "&", &pstate);
651 pair_sv = apr_pstrdup(pool, pair);
653 name = apr_strtok(pair, "=", &vstate);
654 value = apr_strtok(NULL, "=", &vstate);
655 if (! name) continue;
656 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
657 DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
667 pair = apr_strtok(s, "&", &pstate);
672 name = apr_strtok(pair, "=", &vstate);
673 value = apr_strtok(NULL, "=", &vstate);
674 if (! name) continue;
675 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
676 if (strlen(result) != 0)
677 result = apr_pstrcat(pool, result, "&", NULL);
679 if (strcasecmp(entryp->encoding, "NONE") != 0) {
684 if (value && *value != 0) {
685 value = chxj_url_decode(pool, value);
686 dlen = strlen(value);
687 dvalue = chxj_rencoding(r, value, &dlen);
688 dvalue = chxj_url_encode(pool, dvalue);
694 if (name && *name != 0) {
695 name = chxj_url_decode(pool, name);
697 dname = chxj_rencoding(r, name, &dlen);
698 dname = chxj_url_encode(pool, dname);
704 result = apr_pstrcat(pool, result, dname, "=", dvalue, NULL);
707 result = apr_pstrcat(pool, result, name, "=", value, NULL);
711 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
712 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
713 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
717 if (strlen(value) == 0)
720 if (strlen(result) != 0)
721 result = apr_pstrcat(pool, result, "&", NULL);
723 if (strcasecmp(entryp->encoding, "NONE") != 0 && value && strlen(value)) {
727 dlen = strlen(value);
728 value = chxj_url_decode(pool, value);
729 dvalue = chxj_rencoding(r, value, &dlen);
730 dvalue = chxj_url_encode(pool,dvalue);
731 result = apr_pstrcat(pool, result, &name[8], "=", dvalue, NULL);
735 result = apr_pstrcat(pool, result, &name[8], "=", value, NULL);
739 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
741 apr_table_unset(r->headers_in, "Cookie");
742 DBG(r, "REQ[%X] found cookie parameter[%s]", (unsigned int)(apr_size_t)r, value);
743 DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
744 cookie_lock_t *lock = chxj_cookie_lock(r);
745 cookie = chxj_load_cookie(r, value);
746 DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
747 if (! no_update_flag && cookie) {
748 cookie = chxj_update_cookie(r, cookie);
750 chxj_cookie_unlock(r, lock);
752 if (cookie && cookie->cookie_id) {
753 if (strlen(result) != 0)
754 result = apr_pstrcat(pool, result, "&", NULL);
755 result = apr_pstrcat(pool, result, name, "=", cookie->cookie_id, NULL);
759 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
760 if (strlen(result) != 0)
761 result = apr_pstrcat(pool, result, "&", NULL);
762 result = apr_pstrcat(pool, result, name, "=", value, NULL);
765 if ( strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1) == 0) {
768 dlen = strlen(value);
770 value = chxj_url_decode(pool, value);
771 dvalue = chxj_rencoding(r, value, &dlen);
772 dvalue = chxj_url_encode(pool,dvalue);
773 if (r->args && strlen(r->args) > 0) {
774 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
777 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
782 if (strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX_ENC, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1) == 0) {
785 dlen = strlen(value);
787 value = chxj_url_decode(pool, value);
788 dvalue = chxj_rencoding(r, value, &dlen);
789 dvalue = chxj_url_encode(pool,dvalue);
790 if (r->args && strlen(r->args) > 0) {
791 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
794 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
798 DBG(r, "REQ[%X] ************************ name:[%s]", (unsigned int)(apr_size_t)r, name);
800 *len = strlen(result);
801 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
802 if (! no_update_flag) {
803 result = apr_pstrcat(pool, result, "&_chxj_nc=true", NULL);
806 DBG(r, "REQ[%X] AFTER input convert result = [%s]", (unsigned int)(apr_size_t)r, result);
807 DBG(r, "REQ[%X] end chxj_input_convert()", (unsigned int)(apr_size_t)r);
814 * The received data is returned to the filter.
816 * @param f [i/o] It is a filter.
817 * @param data [i] It is data returned to the filter.
818 * @param len [i] It is length of the data returned to the filter.
821 pass_data_to_filter(ap_filter_t *f, const char *data,
824 request_rec *r = f->r;
825 conn_rec *c = r->connection;
827 apr_bucket_brigade *bb;
830 DBG(r, "REQ[%X] start pass_data_to_filter()", (unsigned int)(apr_size_t)r);
832 bb = apr_brigade_create(r->pool, c->bucket_alloc);
833 b = apr_bucket_transient_create(data, len, c->bucket_alloc);
835 APR_BRIGADE_INSERT_TAIL(bb, b);
836 b = apr_bucket_eos_create(f->c->bucket_alloc);
837 APR_BRIGADE_INSERT_TAIL(bb, b);
839 rv = ap_pass_brigade(f->next, bb);
840 if (rv != APR_SUCCESS) {
841 DBG(r, "REQ[%X] end pass_data_to_filter() (apr_pass_brigade)", (unsigned int)(apr_size_t)r);
845 DBG(r, "REQ[%X] end pass_data_to_filter()", (unsigned int)(apr_size_t)r);
852 * It is the main loop of the output filter.
854 * @param f [i/o] It is a filter.
858 chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
864 char *user_agent = NULL;
866 mod_chxj_ctx *ctx = (mod_chxj_ctx *)f->ctx;
867 cookie_t *cookie = NULL;
868 mod_chxj_config *dconf;
869 chxjconvrule_entry *entryp = NULL;
870 device_table *spec = NULL;
874 DBG(f->r, "REQ[%X] start of chxj_output_filter()", (unsigned int)(apr_size_t)r);
877 apr_pool_create(&pool, r->pool);
879 entryp = ctx->entryp;
881 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
883 if (r->content_type) {
884 if (! STRNCASEEQ('t','T',"text/html",r->content_type, sizeof("text/html")-1)
885 && ! STRNCASEEQ('t','T',"text/xml", r->content_type, sizeof("text/xml")-1)
886 && ! STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
887 && ! (dconf->image == CHXJ_IMG_ON
888 && ! apr_table_get(r->headers_in, "CHXJ_IMG_CONV")
889 && STRNCASEEQ('i','I',"image/", r->content_type, sizeof("image/") -1)
890 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
891 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
892 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
893 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
894 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
895 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
896 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
897 || STRCASEEQ('g','G',"gif", &r->content_type[6])))) { /* GIF */
899 DBG(r, "REQ[%X] not convert content-type:[%s] dconf->image:[%d]", (unsigned int)(apr_size_t)r, r->content_type, dconf->image);
900 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
901 cookie_lock_t *lock = NULL;
902 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
903 switch(spec->html_spec_type) {
904 case CHXJ_SPEC_Chtml_1_0:
905 case CHXJ_SPEC_Chtml_2_0:
906 case CHXJ_SPEC_Chtml_3_0:
907 case CHXJ_SPEC_Chtml_4_0:
908 case CHXJ_SPEC_Chtml_5_0:
909 case CHXJ_SPEC_Chtml_6_0:
910 case CHXJ_SPEC_Chtml_7_0:
911 case CHXJ_SPEC_XHtml_Mobile_1_0:
912 case CHXJ_SPEC_Jhtml:
913 lock = chxj_cookie_lock(r);
914 cookie = chxj_save_cookie(r);
915 s_add_cookie_id_if_has_location_header(r, cookie);
916 chxj_cookie_unlock(r, lock);
922 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
923 if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
924 r->status = HTTP_MOVED_TEMPORARILY;
927 ap_pass_brigade(f->next, bb);
928 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
933 DBG(r, "REQ[%X] not convert content-type:[(null)]", (unsigned int)(apr_size_t)r);
934 ap_pass_brigade(f->next, bb);
935 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
940 for (b = APR_BRIGADE_FIRST(bb);
941 b != APR_BRIGADE_SENTINEL(bb);
942 b = APR_BUCKET_NEXT(b)) {
944 if (apr_bucket_read(b, &data, &len, APR_BLOCK_READ) == APR_SUCCESS) {
945 DBG(r, "REQ[%X] read data[%.*s]",(unsigned int)(apr_size_t)r, (int)len, data);
947 /*--------------------------------------------------------------------*/
949 /*--------------------------------------------------------------------*/
951 DBG(r, "append data start");
952 ctx = (mod_chxj_ctx *)f->ctx;
955 tmp = apr_palloc(r->pool, ctx->len);
956 memcpy(tmp, ctx->buffer, ctx->len);
958 ctx->buffer = apr_palloc(pool, ctx->len + len);
960 memcpy(ctx->buffer, tmp, ctx->len);
961 memcpy(&ctx->buffer[ctx->len], data, len);
965 DBG(r, "REQ[%X] append data end", (unsigned int)(apr_size_t)r);
968 if (APR_BUCKET_IS_EOS(b)) {
970 DBG(r, "REQ[%X] eos", (unsigned int)(apr_size_t)r);
971 /*----------------------------------------------------------------------*/
973 /*----------------------------------------------------------------------*/
975 cookie_lock_t *lock = NULL;
976 ctx = (mod_chxj_ctx *)f->ctx;
978 DBG(r, "REQ[%X] content_type=[%s]", (unsigned int)(apr_size_t)r, r->content_type);
979 lock = chxj_cookie_lock(r);
981 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
983 && (STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
984 || STRNCASEEQ('t','T',"text/html", r->content_type, sizeof("text/html")-1))) {
985 DBG(r, "REQ[%X] detect convert target:[%s]", (unsigned int)(apr_size_t)r, r->content_type);
990 tmp = apr_palloc(pool, ctx->len + 1);
992 memset(tmp, 0, ctx->len + 1);
993 memcpy(tmp, ctx->buffer, ctx->len);
995 ctx->buffer = chxj_convert(r,
997 (apr_size_t *)&ctx->len,
999 user_agent, &cookie);
1003 ctx->buffer = apr_psprintf(r->pool, "\n");
1005 ctx->buffer = chxj_convert(r,
1006 (const char **)&ctx->buffer,
1007 (apr_size_t *)&ctx->len,
1009 user_agent, &cookie);
1014 && *(char *)r->content_type == 't'
1015 && strncmp(r->content_type, "text/xml", 8) == 0) {
1016 DBG(r, "REQ[%X] text/XML", (unsigned int)(apr_size_t)r);
1024 memset(&doc, 0, sizeof(Doc));
1025 memset(&qrcode, 0, sizeof(qr_code_t));
1027 doc.parse_mode = PARSE_MODE_CHTML;
1031 qs_init_malloc(&doc);
1033 root = qs_parse_string(&doc, ctx->buffer, ctx->len);
1036 for (child = qs_get_child_node(&doc,root);
1038 child = qs_get_next_node(&doc,child)) {
1039 char *name = qs_get_node_name(&doc,child);
1040 if (strcasecmp("qrcode",name) == 0) {
1045 qs_all_free(&doc,QX_LOGMARK);
1047 r->handler = apr_psprintf(r->pool, "chxj-qrcode");
1048 chxj_qrcode_node_to_qrcode(&qrcode, root);
1049 sts = chxj_qrcode_create_image_data(&qrcode, &ctx->buffer, &ctx->len);
1051 ERR(r, "REQ[%X] qrcode create failed.", (unsigned int)(apr_size_t)r);
1052 chxj_cookie_unlock(r, lock);
1053 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1056 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1060 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
1062 && ( *r->content_type == 'i' || *r->content_type == 'I')
1063 && dconf->image == CHXJ_IMG_ON
1064 && strncasecmp("image/", r->content_type, 6) == 0
1065 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
1066 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
1067 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
1068 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
1069 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
1070 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
1071 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
1072 || STRCASEEQ('g','G',"gif", &r->content_type[6]))) { /* GIF */
1076 tmp = apr_palloc(pool, ctx->len + 1);
1078 memset(tmp, 0, ctx->len + 1);
1079 memcpy(tmp, ctx->buffer, ctx->len);
1081 chxj_convert_image(r,
1082 (const char **)&tmp,
1083 (apr_size_t *)&ctx->len);
1084 if (ctx->buffer == NULL) {
1090 apr_table_unset(r->headers_out, "Content-Length");
1091 apr_table_unset(r->err_headers_out, "Content-Length");
1092 ap_set_content_length(r, (apr_off_t)ctx->len);
1096 DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1097 s_add_cookie_id_if_has_location_header(r, cookie);
1098 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1099 if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
1100 r->status = HTTP_MOVED_TEMPORARILY;
1103 chxj_cookie_unlock(r,lock);
1104 rv = pass_data_to_filter(f,
1105 (const char *)ctx->buffer,
1106 (apr_size_t)ctx->len);
1109 chxj_cookie_unlock(r, lock);
1112 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1116 DBG(r, "REQ[%X] SAVE COOKIE[%x]", (unsigned int)(apr_size_t)r, entryp->action);
1121 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
1122 cookie_lock_t *lock = NULL;
1123 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
1124 switch(spec->html_spec_type) {
1125 case CHXJ_SPEC_Chtml_1_0:
1126 case CHXJ_SPEC_Chtml_2_0:
1127 case CHXJ_SPEC_Chtml_3_0:
1128 case CHXJ_SPEC_Chtml_4_0:
1129 case CHXJ_SPEC_Chtml_5_0:
1130 case CHXJ_SPEC_Chtml_6_0:
1131 case CHXJ_SPEC_Chtml_7_0:
1132 case CHXJ_SPEC_XHtml_Mobile_1_0:
1133 case CHXJ_SPEC_Jhtml:
1134 lock = chxj_cookie_lock(r);
1135 cookie = chxj_save_cookie(r);
1137 * Location Header Check to add cookie parameter.
1139 s_add_cookie_id_if_has_location_header(r, cookie);
1140 chxj_cookie_unlock(r, lock);
1141 apr_table_unset(r->headers_out, "Set-Cookie");
1142 apr_table_unset(r->err_headers_out, "Set-Cookie");
1149 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1150 if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
1151 r->status = HTTP_MOVED_TEMPORARILY;
1154 apr_table_setn(r->headers_out, "Content-Length", "0");
1155 DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1156 rv = pass_data_to_filter(f, (const char *)"", (apr_size_t)0);
1157 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1162 apr_brigade_destroy(bb);
1164 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1170 * Add Cookie_id if it has location header.
1173 s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie)
1175 char *location_header = (char *)apr_table_get(r->headers_out, "Location");
1176 if (! location_header) {
1177 location_header = (char *)apr_table_get(r->err_headers_out, "Location");
1179 if (cookie && location_header) {
1180 DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1181 location_header = chxj_add_cookie_parameter(r,
1184 apr_table_unset(r->headers_out, "Location");
1185 apr_table_setn(r->headers_out, "Location", location_header);
1186 DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1187 if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
1188 r->status = HTTP_MOVED_TEMPORARILY;
1194 * It is the main loop of the input filter handler.
1198 chxj_input_handler(request_rec *r)
1200 mod_chxj_config *dconf;
1201 chxjconvrule_entry *entryp = NULL;
1202 device_table *spec = NULL;
1203 char *post_data = NULL;
1204 apr_size_t post_data_len = 0;
1210 DBG(r, "start of chxj_input_handler()");
1212 if (strcasecmp(r->handler, "chxj-input-handler")) {
1213 DBG(r, "end chxj_input_handler()");
1216 apr_pool_create(&pool, r->pool);
1218 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1219 user_agent = (char*)apr_table_get(r->headers_in, "User-Agent");
1220 spec = chxj_specified_device(r, user_agent);
1221 entryp = chxj_apply_convrule(r, dconf->convrules);
1223 post_data = apr_pstrdup(pool, "");
1224 if (ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK) == OK) {
1225 if (ap_should_client_block(r)) {
1226 while (post_data_len < CHXJ_POST_MAX) {
1229 int read_bytes = ap_get_client_block(r, buffer, BUFSZ-1);
1230 if (read_bytes<=0) {
1233 buffer[read_bytes] = '\0';
1234 post_data = apr_pstrcat(pool, post_data, buffer, NULL);
1235 post_data_len += read_bytes;
1244 if (post_data_len > 0) {
1245 post_data = chxj_input_convert(r, (const char**)&post_data, (apr_size_t*)&post_data_len, entryp);
1246 DBG(r, "(in:exchange)POSTDATA:[%s]", post_data);
1250 if (dconf->forward_url_base) {
1251 url_path = apr_psprintf(pool, "%s%s", dconf->forward_url_base, r->uri);
1254 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);
1257 url_path = apr_pstrcat(pool, url_path, "?", r->args, NULL);
1259 DBG(r, "==> new url_path:[%s]", url_path);
1262 apr_table_setn(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP, r->connection->remote_ip);
1263 apr_table_unset(r->headers_in, "Content-Length");
1264 apr_table_setn(r->headers_in, "Content-Length", apr_psprintf(pool, "%" APR_SIZE_T_FMT, post_data_len));
1265 response = chxj_serf_post(r, pool, url_path, post_data, post_data_len, 1, &res_len);
1266 DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1267 DBG(r, "REQ[%X] response length:[%" APR_SIZE_T_FMT "]", (unsigned int)(apr_size_t)r, res_len);
1268 for (ii=0; ii<res_len/64; ii++) {
1269 DBG(r, "REQ[%X] response:[%.*s]", (unsigned int)(apr_size_t)r, 64, &response[ii*64]);
1271 DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1274 if ((chunked = (char *)apr_table_get(r->headers_out, "Transfer-Encoding")) != NULL) {
1275 if (strcasecmp(chunked, "chunked") == 0) {
1277 apr_table_unset(r->headers_out, "Transfer-Encoding");
1282 apr_pool_create(&wpool, r->pool);
1283 apr_bucket_brigade *bb;
1286 conn_rec *c = r->connection;
1288 bb = apr_brigade_create(wpool, c->bucket_alloc);
1289 e = apr_bucket_transient_create(response, res_len, c->bucket_alloc);
1290 APR_BRIGADE_INSERT_TAIL(bb, e);
1291 e = apr_bucket_eos_create(c->bucket_alloc);
1292 APR_BRIGADE_INSERT_TAIL(bb, e);
1293 if ((rv = ap_pass_brigade(r->output_filters, bb)) != APR_SUCCESS) {
1294 ERR(r, "REQ[%X] %s:%d failed ap_pass_brigade()", (unsigned int)(apr_size_t)r, APLOG_MARK);
1297 apr_brigade_cleanup(bb);
1300 DBG(r, "REQ[%X] end of chxj_input_handler()", (unsigned int)(apr_size_t)r);
1304 static mod_chxj_global_config *
1305 chxj_global_config_create(apr_pool_t *pool, server_rec *s)
1307 mod_chxj_global_config *conf;
1309 SDBG(s, "start chxj_global_config_create()");
1311 /*--------------------------------------------------------------------------*/
1312 /* allocate an own subpool which survives server restarts */
1313 /*--------------------------------------------------------------------------*/
1314 conf = (mod_chxj_global_config *)apr_palloc(pool,
1315 sizeof(mod_chxj_global_config));
1317 conf->cookie_db_lock = NULL;
1319 SDBG(s, "end chxj_global_config_create()");
1326 * initialize chxj module
1329 chxj_init_module(apr_pool_t *p,
1330 apr_pool_t *UNUSED(plog),
1331 apr_pool_t *UNUSED(ptemp),
1337 SDBG(s, "start chxj_init_module()");
1339 apr_pool_userdata_get(&user_data, CHXJ_MOD_CONFIG_KEY, s->process->pool);
1341 if (user_data == NULL) {
1344 * dummy user_data set.
1346 apr_pool_userdata_set(
1348 CHXJ_MOD_CONFIG_KEY,
1349 apr_pool_cleanup_null,
1351 SDBG(s, "end chxj_init_module()");
1355 ap_add_version_component(p, CHXJ_VERSION_PREFIX CHXJ_VERSION);
1357 if ((rv = apr_proc_mutex_create(&global_cookie_mutex, NULL, APR_LOCK_FCNTL, s->process->pool)) != APR_SUCCESS) {
1359 SERR(s, "%s:%d end chxj_init_module(). mutex create failure.(%d:%s)",APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1360 return HTTP_INTERNAL_SERVER_ERROR;
1363 SDBG(s, "end chxj_init_module()");
1370 chxj_child_init(apr_pool_t *UNUSED(p), server_rec *s)
1373 SDBG(s, "start chxj_child_init()");
1374 if ((rv = apr_proc_mutex_child_init(&global_cookie_mutex, NULL, s->process->pool)) != APR_SUCCESS) {
1376 SERR(s, "%s:%d ERROR end chxj_init_module(). mutex create failure.(%d:%s)", APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1378 SDBG(s, "end chxj_child_init()");
1383 * A set structure of each server is generated.
1389 chxj_config_server_create(apr_pool_t *p, server_rec *s)
1391 mod_chxj_global_config *gc;
1393 gc = chxj_global_config_create(p,s);
1400 chxj_translate_name(request_rec *r)
1402 DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1403 DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1404 DBG(r, "REQ[%X] START REQUEST (uri:[%s] args:[%s])", (unsigned int)(apr_size_t)r, r->unparsed_uri, r->args ? r->args : "");
1405 DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1406 DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1407 return chxj_trans_name(r);
1412 chxj_insert_filter(request_rec *r)
1416 mod_chxj_config *dconf;
1417 chxjconvrule_entry *entryp;
1422 DBG(r, "start chxj_insert_filter()");
1424 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1426 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
1428 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
1430 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
1431 DBG(r, "detect multipart/form-data ==> no target");
1435 spec = chxj_specified_device(r, user_agent);
1436 entryp = chxj_apply_convrule(r, dconf->convrules);
1438 DBG(r, "end chxj_insert_filter()");
1441 ctx = apr_palloc(r->pool, sizeof(*ctx));
1442 memset(ctx, 0, sizeof(*ctx));
1443 if ((rv = apr_pool_create(&ctx->pool, r->pool)) != APR_SUCCESS) {
1444 ERR(r, "failed: new pool create. rv:[%d]", rv);
1447 ctx->entryp = entryp;
1449 ctx->buffer = apr_palloc(ctx->pool, 1);
1452 if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
1457 switch(spec->html_spec_type) {
1458 case CHXJ_SPEC_Chtml_1_0:
1459 case CHXJ_SPEC_Chtml_2_0:
1460 case CHXJ_SPEC_Chtml_3_0:
1461 case CHXJ_SPEC_Chtml_4_0:
1462 case CHXJ_SPEC_Chtml_5_0:
1463 case CHXJ_SPEC_Chtml_6_0:
1464 case CHXJ_SPEC_Chtml_7_0:
1465 case CHXJ_SPEC_XHtml_Mobile_1_0:
1466 case CHXJ_SPEC_Hdml:
1467 case CHXJ_SPEC_Jhtml:
1468 case CHXJ_SPEC_Jxhtml:
1476 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
1477 ap_add_output_filter("chxj_output_filter", ctx, r, r->connection);
1478 DBG(r, "added Output Filter");
1481 DBG(r, "end chxj_insert_filter()");
1486 * The hook is registered.
1491 chxj_register_hooks(apr_pool_t *UNUSED(p))
1493 ap_hook_post_config(chxj_init_module,
1496 APR_HOOK_REALLY_FIRST);
1497 ap_hook_child_init(chxj_child_init,
1500 APR_HOOK_REALLY_FIRST);
1501 ap_register_output_filter (
1502 "chxj_output_filter",
1506 ap_hook_insert_filter(chxj_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
1507 ap_hook_handler(chxj_img_conv_format_handler, NULL, NULL, APR_HOOK_MIDDLE);
1508 ap_hook_handler(chxj_qr_code_handler, NULL, NULL, APR_HOOK_MIDDLE);
1509 ap_hook_handler(chxj_input_handler, NULL, NULL, APR_HOOK_MIDDLE);
1510 ap_hook_translate_name(chxj_translate_name, NULL, NULL, APR_HOOK_MIDDLE);
1511 ap_hook_fixups(chxj_headers_fixup, NULL, NULL, APR_HOOK_FIRST);
1516 * A set structure according to the directory is generated.
1522 chxj_create_per_dir_config(apr_pool_t *p, char *arg)
1524 mod_chxj_config *conf;
1526 conf = apr_pcalloc(p, sizeof(mod_chxj_config));
1527 conf->device_data_file = NULL;
1528 conf->devices = NULL;
1529 conf->emoji_data_file = NULL;
1531 conf->emoji_tail = NULL;
1532 conf->image = CHXJ_IMG_NONE;
1533 conf->image_cache_dir = apr_psprintf(p, "%s",DEFAULT_IMAGE_CACHE_DIR);
1534 conf->image_cache_limit = 0;
1535 conf->server_side_encoding = NULL;
1536 conf->cookie_db_dir = NULL;
1537 conf->cookie_timeout = 0;
1538 conf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
1539 conf->cookie_lazy_mode = 0;
1540 #if defined(USE_MYSQL_COOKIE)
1541 memset((void *)&conf->mysql, 0, sizeof(mysql_t));
1542 conf->mysql.port = MYSQL_PORT;
1543 conf->mysql.host = NULL;
1545 #if defined(USE_MEMCACHE_COOKIE)
1546 memset((void *)&conf->memcache, 0, sizeof(memcache_t));
1547 conf->memcache.host = NULL;
1548 conf->memcache.port = 0;
1550 conf->forward_url_base = NULL;
1551 conf->forward_server_ip = NULL;
1557 conf->dir = apr_pcalloc(p, strlen(arg)+1);
1558 memset(conf->dir, 0, strlen(arg)+1);
1559 strcpy(conf->dir, arg);
1561 conf->convrules = apr_array_make(p, 2, sizeof(chxjconvrule_entry));
1563 /* Default is copyleft */
1564 conf->image_copyright = NULL;
1571 * Merge per-directory CHXJ configurations
1574 chxj_merge_per_dir_config(apr_pool_t *p, void *basev, void *addv)
1576 mod_chxj_config *base;
1577 mod_chxj_config *add;
1578 mod_chxj_config *mrg;
1580 base = (mod_chxj_config *)basev;
1581 add = (mod_chxj_config *)addv;
1582 mrg = (mod_chxj_config *)apr_palloc(p, sizeof(mod_chxj_config));
1584 mrg->device_data_file = NULL;
1585 mrg->devices = NULL;
1586 mrg->emoji_data_file = NULL;
1587 mrg->image = CHXJ_IMG_NONE;
1588 mrg->image_cache_dir = NULL;
1589 mrg->image_copyright = NULL;
1590 mrg->image_cache_limit = 0;
1592 mrg->emoji_tail = NULL;
1593 mrg->new_line_type = NLTYPE_NIL;
1594 mrg->forward_url_base = NULL;
1595 mrg->forward_server_ip = NULL;
1597 mrg->dir = apr_pstrdup(p, add->dir);
1599 if (! add->device_data_file) {
1600 mrg->devices = base->devices;
1601 mrg->device_data_file = apr_pstrdup(p, base->device_data_file);
1604 mrg->devices = add->devices;
1605 mrg->device_data_file = apr_pstrdup(p, add->device_data_file);
1608 if (! add->emoji_data_file) {
1609 mrg->emoji = base->emoji;
1610 mrg->emoji_tail = base->emoji_tail;
1611 mrg->emoji_data_file = apr_pstrdup(p, base->emoji_data_file);
1614 mrg->emoji = add->emoji;
1615 mrg->emoji_tail = add->emoji_tail;
1616 mrg->emoji_data_file = apr_pstrdup(p, add->emoji_data_file);
1619 if (add->image == CHXJ_IMG_NONE) {
1620 mrg->image = base->image;
1623 mrg->image = add->image;
1626 if (strcasecmp(add->image_cache_dir ,DEFAULT_IMAGE_CACHE_DIR)==0) {
1627 mrg->image_cache_dir = apr_pstrdup(p, base->image_cache_dir);
1630 mrg->image_cache_dir = apr_pstrdup(p, add->image_cache_dir);
1633 if (add->image_cache_limit) {
1634 mrg->image_cache_limit = add->image_cache_limit;
1637 mrg->image_cache_limit = base->image_cache_limit;
1640 if (add->image_copyright)
1641 mrg->image_copyright = apr_pstrdup(p, add->image_copyright);
1643 mrg->image_copyright = apr_pstrdup(p, base->image_copyright);
1645 if (add->server_side_encoding) {
1646 mrg->server_side_encoding = apr_pstrdup(p, add->server_side_encoding);
1649 if (base->server_side_encoding) {
1650 mrg->server_side_encoding = apr_pstrdup(p, base->server_side_encoding);
1653 mrg->server_side_encoding = apr_pstrdup(p, DEFAULT_SERVER_SIDE_ENCODING);
1656 mrg->convrules = apr_array_append(p, add->convrules, base->convrules);
1658 if (add->cookie_db_dir) {
1659 mrg->cookie_db_dir = apr_pstrdup(p, add->cookie_db_dir);
1662 if (base->cookie_db_dir) {
1663 mrg->cookie_db_dir = apr_pstrdup(p, base->cookie_db_dir);
1666 mrg->cookie_db_dir = NULL;
1669 if (add->cookie_timeout) {
1670 mrg->cookie_timeout = add->cookie_timeout;
1673 if (base->cookie_db_dir) {
1674 mrg->cookie_timeout = base->cookie_timeout;
1677 mrg->cookie_timeout = 0;
1680 #if defined(USE_MYSQL_COOKIE)
1681 if (add->mysql.host) {
1682 mrg->mysql.host = apr_pstrdup(p, add->mysql.host);
1684 else if (base->mysql.host) {
1685 mrg->mysql.host = apr_pstrdup(p, base->mysql.host);
1688 mrg->mysql.host = NULL;
1690 if (add->mysql.port) {
1691 mrg->mysql.port = add->mysql.port;
1693 else if (base->mysql.port) {
1694 mrg->mysql.port = base->mysql.port;
1697 mrg->mysql.port = 0;
1700 if (add->mysql.database) {
1701 mrg->mysql.database = apr_pstrdup(p, add->mysql.database);
1703 else if (base->mysql.database) {
1704 mrg->mysql.database = apr_pstrdup(p, base->mysql.database);
1707 mrg->mysql.database = NULL;
1710 if (add->mysql.username) {
1711 mrg->mysql.username = apr_pstrdup(p, add->mysql.username);
1713 else if (base->mysql.username) {
1714 mrg->mysql.username = apr_pstrdup(p, base->mysql.username);
1717 mrg->mysql.username = NULL;
1720 if (add->mysql.password) {
1721 mrg->mysql.password = apr_pstrdup(p, add->mysql.password);
1723 else if (base->mysql.password) {
1724 mrg->mysql.password = apr_pstrdup(p, base->mysql.password);
1727 mrg->mysql.password = NULL;
1730 if (add->mysql.tablename) {
1731 mrg->mysql.tablename = apr_pstrdup(p, add->mysql.tablename);
1733 else if (base->mysql.tablename) {
1734 mrg->mysql.tablename = apr_pstrdup(p, base->mysql.tablename);
1737 mrg->mysql.tablename = NULL;
1740 if (add->mysql.socket_path) {
1741 mrg->mysql.socket_path = apr_pstrdup(p, add->mysql.socket_path);
1743 else if (base->mysql.socket_path) {
1744 mrg->mysql.socket_path = apr_pstrdup(p, base->mysql.socket_path);
1747 mrg->mysql.socket_path = NULL;
1750 if (add->mysql.charset) {
1751 mrg->mysql.charset = apr_pstrdup(p, add->mysql.charset);
1753 else if (base->mysql.charset) {
1754 mrg->mysql.charset = apr_pstrdup(p, base->mysql.charset);
1757 mrg->mysql.charset = NULL;
1760 #if defined(USE_MEMCACHE_COOKIE)
1761 if (add->memcache.host) {
1762 mrg->memcache.host = apr_pstrdup(p, add->memcache.host);
1764 else if (base->memcache.host) {
1765 mrg->memcache.host = apr_pstrdup(p, base->memcache.host);
1768 mrg->memcache.host = NULL;
1770 if (add->memcache.port) {
1771 mrg->memcache.port = add->memcache.port;
1773 else if (base->memcache.port) {
1774 mrg->memcache.port = base->memcache.port;
1777 mrg->memcache.port = 0;
1780 if (add->cookie_store_type) {
1781 mrg->cookie_store_type = add->cookie_store_type;
1783 else if (base->cookie_store_type) {
1784 mrg->cookie_store_type = base->cookie_store_type;
1787 mrg->cookie_store_type = COOKIE_STORE_TYPE_NONE;
1789 if (add->cookie_lazy_mode) {
1790 mrg->cookie_lazy_mode = add->cookie_lazy_mode;
1792 else if (base->cookie_lazy_mode) {
1793 mrg->cookie_lazy_mode = base->cookie_lazy_mode;
1796 mrg->cookie_lazy_mode = 0;
1798 if (add->new_line_type) {
1799 mrg->new_line_type = add->new_line_type;
1801 else if (base->new_line_type) {
1802 mrg->new_line_type = base->new_line_type;
1805 mrg->new_line_type = NLTYPE_NIL;
1812 chxj_command_parse_take5(
1825 for (;*strp == ' '||*strp == '\t'; strp++) ;
1835 for (; *strp != '\0'; strp++) {
1836 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1837 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1842 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1843 || (isquoted && *strp == '"'))
1857 for (;*strp == ' '||*strp == '\t'; strp++) ;
1866 for (; *strp != '\0'; strp++) {
1867 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1868 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1873 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1874 || (isquoted && *strp == '"'))
1887 for (;*strp == ' '||*strp == '\t'; strp++);
1895 for (; *strp != '\0'; strp++) {
1896 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1897 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1902 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1903 || (isquoted && *strp == '"'))
1915 for (;*strp == ' '||*strp == '\t'; strp++);
1923 for (; *strp != '\0'; strp++) {
1924 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1925 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1930 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1931 || (isquoted && *strp == '"'))
1942 for (;*strp == ' '||*strp == '\t'; strp++);
1950 for (; *strp != '\0'; strp++) {
1951 if ((isquoted && (*strp == ' ' || *strp == '\t'))
1952 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
1957 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
1958 || (isquoted && *strp == '"'))
1968 * The device definition file is loaded.
1970 * @param arg [i] The name of the device definition file is specified.
1971 * @param mconfig [i/o] The pointer to a set structure is specified.
1975 cmd_load_device_data(cmd_parms *parms, void *mconfig, const char *arg)
1977 mod_chxj_config *conf;
1982 if (strlen(arg) > 256)
1983 return "mod_chxj: device data filename too long.";
1985 conf = (mod_chxj_config *)mconfig;
1986 conf->device_data_file = apr_pstrdup(parms->pool, arg);
1988 qs_init_malloc(&doc);
1989 qs_init_root_node(&doc);
1991 qs_parse_file((Doc *)&doc, (const char *)arg);
1992 chxj_load_device_data(&doc,parms->pool, conf);
1993 qs_all_free(&doc, QX_LOGMARK);
2000 * Device definition information is loaded.
2003 * @param arg [i] The name of the device definition file is specified.
2004 * @param mconfig [i/o] The pointer to a set structure is specified.
2008 cmd_load_emoji_data(cmd_parms *parms, void *mconfig, const char *arg)
2010 mod_chxj_config *conf;
2017 if (strlen(arg) > 256)
2018 return "mod_chxj: emoji data filename too long.";
2020 conf = (mod_chxj_config *)mconfig;
2021 conf->emoji_data_file = apr_pstrdup(parms->pool, arg);
2022 qs_init_malloc(&doc);
2023 qs_init_root_node(&doc);
2025 qs_parse_file((Doc *)&doc, (const char *)arg);
2027 rtn = chxj_load_emoji_data(&doc,parms->pool, conf);
2029 qs_all_free(&doc, QX_LOGMARK);
2037 cmd_set_image_engine(cmd_parms * UNUSED(parms), void *mconfig, const char *arg)
2039 mod_chxj_config *conf;
2044 if (strlen(arg) > 256)
2045 return "image uri is too long.";
2047 conf = (mod_chxj_config*)mconfig;
2048 if (strcasecmp("ON", arg) == 0) {
2049 conf->image = CHXJ_IMG_ON;
2052 conf->image = CHXJ_IMG_OFF;
2060 cmd_set_image_cache_dir(cmd_parms *parms, void *mconfig, const char *arg)
2062 mod_chxj_config *conf;
2067 if (strlen(arg) > 256)
2068 return "cache dir name is too long.";
2070 conf = (mod_chxj_config *)mconfig;
2071 conf->image_cache_dir = apr_pstrdup(parms->pool, arg);
2078 cmd_set_image_cache_limit(cmd_parms *parms, void *mconfig, const char *arg)
2080 mod_chxj_config *conf;
2085 if (strlen(arg) > IMAGE_CACHE_LIMIT_FMT_LEN)
2086 return "cache size is too long.";
2088 conf = (mod_chxj_config *)mconfig;
2091 * I use strtol function because strtoul is not portable function.
2093 conf->image_cache_limit = (unsigned long)strtol(arg, NULL, 10);
2096 return apr_psprintf(parms->pool, "ChxjImageCacheLimit invalid value [%s] errno:[%d]", arg, errno);
2098 return apr_psprintf(parms->pool, "ChxjImageCacheLimit Out of range [%s] errno:[%d]", arg, errno);
2107 cmd_set_image_copyright(cmd_parms *parms, void *mconfig, const char *arg)
2109 mod_chxj_config *conf;
2114 if (strlen(arg) > 256)
2115 return "Copyright Flag is too long.";
2117 conf = (mod_chxj_config *)mconfig;
2118 conf->image_copyright = apr_pstrdup(parms->pool, arg);
2125 cmd_convert_rule(cmd_parms *cmd, void *mconfig, const char *arg)
2129 mod_chxj_config *dconf;
2130 chxjconvrule_entry *newrule;
2140 dconf = (mod_chxj_config *)mconfig;
2142 if (strlen(arg) > 4096)
2143 return "mod_chxj: ChxjConvertRule: is too long.";
2145 dconf = (mod_chxj_config *)mconfig;
2146 if (dconf->convrules == NULL)
2147 dconf->convrules = apr_array_make(cmd->pool,
2149 sizeof(chxjconvrule_entry));
2151 newrule = apr_array_push(dconf->convrules);
2154 newrule->action = 0;
2156 if (chxj_command_parse_take5(arg, &prm1, &prm2, &prm3, &prm4, &prm5))
2157 return "ChxjConvertRule: bad argument line";
2159 newrule->pattern = apr_pstrdup(cmd->pool, prm1);
2163 if ((action = apr_strtok(prm2, ",", &pstate)) == NULL)
2169 if (strcasecmp(CONVRULE_ENGINE_ON_CMD, action) == 0) {
2170 newrule->action |= CONVRULE_ENGINE_ON_BIT;
2173 if (strcasecmp(CONVRULE_ENGINE_OFF_CMD, action) == 0) {
2174 newrule->action |= CONVRULE_ENGINE_OFF_BIT;
2180 if (strcasecmp(CONVRULE_COOKIE_ON_CMD, action) == 0) {
2181 newrule->action |= CONVRULE_COOKIE_ON_BIT;
2191 newrule->flags |= CONVRULE_FLAG_NOTMATCH;
2195 mode = AP_REG_EXTENDED;
2196 if ((regexp = ap_pregcomp((apr_pool_t *)cmd->pool, (const char *)pp, mode)) == NULL)
2197 return "RewriteRule: cannot compile regular expression ";
2199 newrule->regexp = regexp;
2201 newrule->encoding = apr_pstrdup(cmd->pool, prm3);
2203 newrule->encoding = apr_pstrdup(cmd->pool, "none");
2205 newrule->pc_flag = CONVRULE_PC_FLAG_OFF_BIT;
2207 if (strcasecmp(CONVRULE_PC_FLAG_ON_CMD, prm4) == 0)
2208 newrule->pc_flag = CONVRULE_PC_FLAG_ON_BIT;
2210 newrule->user_agent = NULL;
2212 newrule->user_agent = apr_pstrdup(cmd->pool, prm5);
2224 mod_chxj_config *dconf;
2227 if (strlen(arg) > 4096)
2228 return "mod_chxj: ChxjCookieDir is too long.";
2230 dconf = (mod_chxj_config *)mconfig;
2232 dconf->cookie_db_dir = apr_pstrdup(cmd->pool, arg);
2239 cmd_set_cookie_timeout(
2240 cmd_parms *UNUSED(cmd),
2244 mod_chxj_config *dconf;
2246 if (strlen(arg) > 4096)
2247 return "mod_chxj: ChxjCookieTimeout is too long.";
2249 if (chxj_chk_numeric(arg) != 0)
2250 return "mod_chxj: ChxjCookieTimeout is not numeric.";
2252 dconf = (mod_chxj_config *)mconfig;
2254 dconf->cookie_timeout = atoi(arg);
2260 #if defined(USE_MYSQL_COOKIE)
2262 cmd_set_cookie_mysql_database(
2267 mod_chxj_config *dconf;
2269 if (strlen(arg) > 255)
2270 return "mod_chxj: ChxjCookieMysqlDatabase is too long.";
2272 dconf = (mod_chxj_config *)mconfig;
2274 dconf->mysql.database = apr_pstrdup(cmd->pool, arg);
2281 cmd_set_cookie_mysql_username(
2286 mod_chxj_config *dconf;
2288 if (strlen(arg) > 255)
2289 return "mod_chxj: ChxjCookieMysqlUsername is too long.";
2291 dconf = (mod_chxj_config *)mconfig;
2293 dconf->mysql.username = apr_pstrdup(cmd->pool, arg);
2300 cmd_set_cookie_mysql_password(
2305 mod_chxj_config *dconf;
2307 if (strlen(arg) > 255)
2308 return "mod_chxj: ChxjCookieMysqlPassword is too long.";
2310 dconf = (mod_chxj_config *)mconfig;
2312 dconf->mysql.password = apr_pstrdup(cmd->pool, arg);
2319 cmd_set_cookie_mysql_table_name(
2324 mod_chxj_config *dconf;
2326 if (strlen(arg) > 255)
2327 return "mod_chxj: ChxjCookieMysqlTableName is too long.";
2329 dconf = (mod_chxj_config *)mconfig;
2331 dconf->mysql.tablename = apr_pstrdup(cmd->pool, arg);
2337 cmd_set_cookie_mysql_port(
2338 cmd_parms *UNUSED(cmd),
2342 mod_chxj_config *dconf;
2344 if (strlen(arg) > 255)
2345 return "mod_chxj: ChxjCookieMysqlPort is too long.";
2347 dconf = (mod_chxj_config *)mconfig;
2349 if (chxj_chk_numeric(arg) != 0)
2350 return "mod_chxj: ChxjCookieMysqlPort is not numeric.";
2352 dconf = (mod_chxj_config *)mconfig;
2354 dconf->mysql.port = chxj_atoi(arg);
2361 cmd_set_cookie_mysql_host(
2366 mod_chxj_config *dconf;
2368 if (strlen(arg) > 255)
2369 return "mod_chxj: ChxjCookieMysqlHost is too long.";
2371 dconf = (mod_chxj_config *)mconfig;
2373 dconf->mysql.host = apr_pstrdup(cmd->pool, arg);
2380 cmd_set_cookie_mysql_socket_path(
2385 mod_chxj_config *dconf;
2387 if (strlen(arg) > 4096)
2388 return "mod_chxj: ChxjCookieMysqlSocketPath is too long.";
2390 dconf = (mod_chxj_config *)mconfig;
2392 dconf->mysql.socket_path = apr_pstrdup(cmd->pool, arg);
2399 cmd_set_cookie_mysql_charset(
2404 mod_chxj_config *dconf;
2406 if (strlen(arg) > 255)
2407 return "mod_chxj: ChxjCookieMysqlCharset is too long.";
2409 dconf = (mod_chxj_config *)mconfig;
2411 dconf->mysql.charset = apr_pstrdup(cmd->pool, arg);
2416 #if defined(USE_MEMCACHE_COOKIE)
2418 cmd_set_cookie_memcache_port(
2419 cmd_parms *UNUSED(cmd),
2423 mod_chxj_config *dconf;
2425 if (strlen(arg) > 255)
2426 return "mod_chxj: ChxjCookieMemcachePort is too long.";
2428 dconf = (mod_chxj_config *)mconfig;
2430 if (chxj_chk_numeric(arg) != 0)
2431 return "mod_chxj: ChxjCookieMemcachePort is not numeric.";
2433 dconf = (mod_chxj_config *)mconfig;
2435 dconf->memcache.port = (apr_port_t)chxj_atoi(arg);
2442 cmd_set_cookie_memcache_host(
2447 mod_chxj_config *dconf;
2449 if (strlen(arg) > 255)
2450 return "mod_chxj: ChxjCookieMemcacheHost is too long.";
2452 dconf = (mod_chxj_config *)mconfig;
2454 dconf->memcache.host = apr_pstrdup(cmd->pool, arg);
2461 cmd_set_cookie_lazy_mode(
2462 cmd_parms *UNUSED(cmd),
2466 mod_chxj_config *dconf;
2468 if (strlen(arg) > 255)
2469 return "mod_chxj: ChxjCookieLazyMode is too long.";
2471 dconf = (mod_chxj_config *)mconfig;
2473 if (strcasecmp("TRUE",arg) == 0) {
2474 dconf->cookie_lazy_mode = COOKIE_LAZY_ON;
2477 dconf->cookie_lazy_mode = COOKIE_LAZY_OFF;
2484 cmd_set_cookie_store_type(
2485 cmd_parms *UNUSED(cmd),
2489 mod_chxj_config *dconf;
2491 if (strlen(arg) > 255)
2492 return "mod_chxj: ChxjCookieStoreType is too long.";
2494 dconf = (mod_chxj_config *)mconfig;
2496 if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_DBM, arg) == 0) {
2497 dconf->cookie_store_type = COOKIE_STORE_TYPE_DBM;
2499 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MYSQL, arg) == 0) {
2500 dconf->cookie_store_type = COOKIE_STORE_TYPE_MYSQL;
2502 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MEMCACHE, arg) == 0) {
2503 dconf->cookie_store_type = COOKIE_STORE_TYPE_MEMCACHE;
2506 dconf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
2513 cmd_set_forward_url_base(
2518 mod_chxj_config *dconf;
2520 if (strlen(arg) > 255)
2521 return "mod_chxj: ChxjForwardUrlBase is too long.";
2523 dconf = (mod_chxj_config *)mconfig;
2525 dconf->forward_url_base = apr_pstrdup(cmd->pool, arg);
2531 cmd_set_forward_server_ip(
2536 mod_chxj_config *dconf;
2538 if (strlen(arg) > 255)
2539 return "mod_chxj: ChxjForwardServerIp is too long.";
2541 dconf = (mod_chxj_config *)mconfig;
2543 dconf->forward_server_ip = apr_pstrdup(cmd->pool, arg);
2549 cmd_set_new_line_type(
2550 cmd_parms *UNUSED(cmd),
2554 mod_chxj_config *dconf;
2555 if (strlen(arg) > 255)
2556 return "mod_chxj: ChxjNewLineType is too long.";
2558 dconf = (mod_chxj_config *)mconfig;
2560 if (strcasecmp(CHXJ_NEW_LINE_TYPE_CRLF, arg) == 0) {
2561 dconf->new_line_type = NLTYPE_CRLF;
2563 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_LF, arg) == 0) {
2564 dconf->new_line_type = NLTYPE_LF;
2566 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_CR, arg) == 0) {
2567 dconf->new_line_type = NLTYPE_CR;
2569 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_NONE, arg) == 0) {
2570 dconf->new_line_type = NLTYPE_NONE;
2573 return "mod_chxj: invalid value (ChxjNewLineType)";
2579 static const command_rec cmds[] = {
2581 "ChxjLoadDeviceData",
2582 cmd_load_device_data,
2585 "Load Device Data"),
2587 "ChxjLoadEmojiData",
2588 cmd_load_emoji_data,
2594 cmd_set_image_engine,
2597 "Convert Target URI"),
2599 "ChxjImageCacheDir",
2600 cmd_set_image_cache_dir,
2603 "Image Cache Directory"),
2605 "ChxjImageCacheLimit",
2606 cmd_set_image_cache_limit,
2609 "Image Cache Limit"),
2611 "ChxjImageCopyright",
2612 cmd_set_image_copyright,
2621 "an URL-applied regexp-pattern and a substitution URL"),
2627 "save cookie.db directory."),
2629 "ChxjCookieTimeout",
2630 cmd_set_cookie_timeout,
2633 "The compulsion time-out time of the cookie is specified. "),
2635 "ChxjCookieStoreType",
2636 cmd_set_cookie_store_type,
2639 "It specifies preserving of the cookie ahead. (DBM/MYSQL/MEMCACHE)"),
2641 "ChxjCookieLazyMode",
2642 cmd_set_cookie_lazy_mode,
2645 "OneTimeID is negligently done. (TRUE/FALSE)"),
2646 #if defined(USE_MYSQL_COOKIE)
2648 "ChxjCookieMysqlHost",
2649 cmd_set_cookie_mysql_host,
2652 "The MySQL database host used by saving Cookie"),
2654 "ChxjCookieMysqlPort",
2655 cmd_set_cookie_mysql_port,
2658 "The MySQL database port used by saving Cookie"),
2660 "ChxjCookieMysqlDatabase",
2661 cmd_set_cookie_mysql_database,
2664 "The MySQL database name used by saving Cookie"),
2666 "ChxjCookieMysqlUsername",
2667 cmd_set_cookie_mysql_username,
2670 "The MySQL username used by saving Cookie"),
2672 "ChxjCookieMysqlPassword",
2673 cmd_set_cookie_mysql_password,
2676 "The MySQL password used by saving Cookie"),
2678 "ChxjCookieMysqlTableName",
2679 cmd_set_cookie_mysql_table_name,
2682 "The MySQL table name used by saving Cookie"),
2684 "ChxjCookieMysqlSocketPath",
2685 cmd_set_cookie_mysql_socket_path,
2688 "The MySQL socket path used by saving Cookie"),
2690 "ChxjCookieMysqlCharset",
2691 cmd_set_cookie_mysql_charset,
2694 "The MySQL charset used by saving Cookie"),
2696 #if defined(USE_MEMCACHE_COOKIE)
2698 "ChxjCookieMemcacheHost",
2699 cmd_set_cookie_memcache_host,
2702 "The Memcached host used by saving Cookie"),
2704 "ChxjCookieMemcachePort",
2705 cmd_set_cookie_memcache_port,
2708 "The Memcached port used by saving Cookie"),
2712 cmd_set_new_line_type,
2715 "HTML new line type (NONE|CRLF|LF|CR). default is CRLF"),
2717 "ChxjForwardUrlBase",
2718 cmd_set_forward_url_base,
2721 "The forward url base(default: {request protocol}://{this server}:{this server port}"),
2723 "ChxjForwardServerIp",
2724 cmd_set_forward_server_ip,
2727 "The forward server ip(default: this server ip)"),
2732 /*----------------------------------------------------------------------------*/
2733 /* Dispatch list for API hooks */
2734 /*----------------------------------------------------------------------------*/
2735 module AP_MODULE_DECLARE_DATA chxj_module = {
2736 STANDARD20_MODULE_STUFF,
2737 chxj_create_per_dir_config, /* create per-dir config structures */
2738 chxj_merge_per_dir_config, /* merge per-dir config structures */
2739 chxj_config_server_create, /* create per-server config structures */
2740 NULL, /* merge per-server config structures */
2741 cmds, /* table of config file commands */
2742 chxj_register_hooks /* register hooks */