2 * Copyright (C) 2005-2009 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"
36 #include "apr_file_info.h"
39 #include "chxj_encoding.h"
40 #include "qs_ignore_sp.h"
42 #include "qs_malloc.h"
43 #include "qs_parse_attr.h"
44 #include "qs_parse_file.h"
45 #include "qs_parse_string.h"
46 #include "qs_parse_tag.h"
47 #include "chxj_load_device_data.h"
48 #include "chxj_load_emoji_data.h"
49 #include "chxj_specified_device.h"
50 #include "chxj_tag_util.h"
51 #include "chxj_xhtml_mobile_1_0.h"
52 #include "chxj_hdml.h"
53 #include "chxj_chtml10.h"
54 #include "chxj_chtml20.h"
55 #include "chxj_chtml30.h"
56 #include "chxj_chtml40.h"
57 #include "chxj_chtml50.h"
58 #include "chxj_ixhtml10.h"
59 #include "chxj_jhtml.h"
60 #include "chxj_jxhtml.h"
61 #include "chxj_img_conv_format.h"
62 #include "chxj_qr_code.h"
63 #include "chxj_encoding.h"
64 #include "chxj_apply_convrule.h"
65 #include "chxj_cookie.h"
66 #include "chxj_url_encode.h"
67 #include "chxj_str_util.h"
68 #include "chxj_dump_string.h"
69 #if defined(USE_MYSQL_COOKIE)
70 # include "chxj_mysql.h"
72 #include "chxj_serf.h"
73 #include "chxj_add_device_env.h"
74 #include "chxj_header_inf.h"
75 #include "chxj_jreserved_tag.h"
78 #define CHXJ_VERSION_PREFIX PACKAGE_NAME "/"
79 #define CHXJ_VERSION PACKAGE_VERSION
80 #define CHXJ_POST_MAX (0x1000000)
82 converter_t convert_routine[] = {
84 /* CHXJ_SPEC_UNKNOWN */
87 .emoji_only_converter = NULL,
90 /* CHXJ_SPEC_Chtml_1_0 */
91 .converter = chxj_convert_chtml10,
92 .encoder = chxj_encoding,
93 .emoji_only_converter = chxj_chtml10_emoji_only_converter,
96 /* CHXJ_SPEC_Chtml_2_0 */
97 .converter = chxj_convert_chtml20,
98 .encoder = chxj_encoding,
99 .emoji_only_converter = chxj_chtml20_emoji_only_converter,
102 /* CHXJ_SPEC_Chtml_3_0 */
103 .converter = chxj_convert_chtml30,
104 .encoder = chxj_encoding,
105 .emoji_only_converter = chxj_chtml30_emoji_only_converter,
108 /* CHXJ_SPEC_Chtml_4_0 */
109 .converter = chxj_convert_chtml40,
110 .encoder = chxj_encoding,
111 .emoji_only_converter = chxj_chtml40_emoji_only_converter,
114 /* CHXJ_SPEC_Chtml_5_0 */
115 .converter = chxj_convert_chtml50,
116 .encoder = chxj_encoding,
117 .emoji_only_converter = chxj_chtml50_emoji_only_converter,
120 /* CHXJ_SPEC_Chtml_6_0 */
121 .converter = chxj_convert_ixhtml10,
122 .encoder = chxj_encoding,
123 .emoji_only_converter = chxj_chtml50_emoji_only_converter, /* XXX: TODO */
126 /* CHXJ_SPEC_Chtml_7_0 */
127 .converter = chxj_convert_ixhtml10,
128 .encoder = chxj_encoding,
129 .emoji_only_converter = chxj_chtml50_emoji_only_converter, /* XXX: TODO */
132 /* CHXJ_SPEC_XHtml_Mobile_1_0 */
133 .converter = chxj_convert_xhtml_mobile_1_0,
134 .encoder = chxj_encoding,
135 .emoji_only_converter = chxj_xhtml_emoji_only_converter,
139 .converter = chxj_convert_hdml,
140 .encoder = chxj_encoding,
141 .emoji_only_converter = NULL,
144 /* CHXJ_SPEC_Jhtml */
145 .converter = chxj_convert_jhtml,
146 .encoder = chxj_encoding,
147 .emoji_only_converter = chxj_jhtml_emoji_only_converter,
150 /* CHXJ_SPEC_Jxhtml */
151 .converter = chxj_convert_jxhtml,
152 .encoder = chxj_encoding,
153 .emoji_only_converter = chxj_jxhtml_emoji_only_converter,
159 .emoji_only_converter = NULL,
163 static int chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp, device_table *spec);
164 static void s_convert_guid_parameter_to_header(request_rec *r, const char *param, device_table *spec);
165 static void s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie);
166 static void s_clear_cookie_header(request_rec *r, device_table *spec);
167 static void s_add_no_cache_headers(request_rec *r, chxjconvrule_entry *entryp);
170 * Only when User-Agent is specified, the User-Agent header is camouflaged.
175 chxj_headers_fixup(request_rec *r)
177 mod_chxj_config* dconf;
178 chxjconvrule_entry* entryp;
184 DBG(r, "REQ[%X] start %s()", TO_ADDR(r), __func__);
186 DBG(r, "REQ[%X] detect internal redirect.", TO_ADDR(r));
187 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
191 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
193 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
194 spec = chxj_specified_device(r, user_agent);
196 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
198 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
199 DBG(r, "REQ[%X] detect multipart/form-data ==> no target", TO_ADDR(r));
200 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
205 switch(spec->html_spec_type) {
206 case CHXJ_SPEC_Chtml_1_0:
207 case CHXJ_SPEC_Chtml_2_0:
208 case CHXJ_SPEC_Chtml_3_0:
209 case CHXJ_SPEC_Chtml_4_0:
210 case CHXJ_SPEC_Chtml_5_0:
211 case CHXJ_SPEC_Chtml_6_0:
212 case CHXJ_SPEC_Chtml_7_0:
213 case CHXJ_SPEC_XHtml_Mobile_1_0:
215 case CHXJ_SPEC_Jhtml:
216 case CHXJ_SPEC_Jxhtml:
217 entryp = chxj_apply_convrule(r, dconf->convrules);
219 DBG(r, "REQ[%X] end %s() (no pattern)", TO_ADDR(r),__func__);
222 if (!(entryp->action & CONVRULE_ENGINE_ON_BIT) && !(entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
223 DBG(r, "REQ[%X] end %s() (engine off)", TO_ADDR(r),__func__);
226 if (entryp->action & CONVRULE_EMOJI_ONLY_BIT) {
227 DBG(r, "REQ[%X] end %s() (emoji only)", TO_ADDR(r),__func__);
231 apr_table_setn(r->headers_in,
232 CHXJ_HTTP_USER_AGENT,
235 if (entryp->user_agent)
236 apr_table_setn(r->headers_in,
240 * this clear process must do before chxj_convert_input_header function.
242 if ((entryp->action & CONVRULE_COOKIE_ON_BIT) || (entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
243 if (r->method_number == M_POST) {
244 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
245 s_clear_cookie_header(r, spec);
249 s_clear_cookie_header(r, spec);
253 chxj_convert_input_header(r,entryp, spec);
258 DBG(r, "REQ[%X] end %s() (not mobile) spec->device_name[%s] User-Agent:[%s]", TO_ADDR(r),__func__, spec->device_name, user_agent);
263 char *x_client_type = (char *)apr_table_get(r->headers_out, "X-Client-Type");
264 apr_table_unset(r->headers_out, "X-Client-Type");
266 apr_table_setn(r->headers_in, "X-Client-Type", x_client_type);
269 apr_table_setn(r->headers_in, "X-Client-Type", "");
272 if (r->method_number == M_POST) {
273 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
274 DBG(r, "REQ[%X] set Input handler old:[%s] proxyreq:[%d] uri:[%s] filename:[%s]", TO_ADDR(r), r->handler, r->proxyreq, r->uri, r->filename);
275 r->proxyreq = PROXYREQ_NONE;
276 r->handler = apr_psprintf(r->pool, "chxj-input-handler");
279 char *client_ip = (char *)apr_table_get(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP);
281 if (dconf->post_log) {
282 apr_table_setn(r->subprocess_env, dconf->post_log, dconf->post_log);
285 apr_table_setn(r->subprocess_env, "chxj-post-log", "chxj-post-log");
287 apr_sockaddr_t *address = NULL;
288 apr_status_t rv = apr_sockaddr_info_get(&address, ap_get_server_name(r), APR_UNSPEC, ap_get_server_port(r), 0, r->pool);
289 if (rv != APR_SUCCESS) {
291 ERR(r, "REQ[%X] %s:%d apr_sockaddr_info_get() failed: rv:[%d|%s]", TO_ADDR(r), APLOG_MARK, rv, apr_strerror(rv, buf, 256));
292 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
296 if (dconf->forward_server_ip) {
297 addr = dconf->forward_server_ip;
300 apr_sockaddr_ip_get(&addr, address);
302 DBG(r, "REQ[%X] Client IP:[%s] vs Orig Client IP:[%s] vs Server IP:[%s]", TO_ADDR(r), r->connection->remote_ip, client_ip, addr);
303 if (strcmp(addr, r->connection->remote_ip) == 0) {
304 r->connection->remote_ip = apr_pstrdup(r->connection->pool, client_ip);
305 /* For mod_cidr_lookup */
306 if (entryp->action & CONVRULE_OVERWRITE_X_CLIENT_TYPE_BIT) {
307 char *client_type = (char *)apr_table_get(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_TYPE);
308 DBG(r, "REQ[%X] Overwrite X-Client-Type to [%s]", TO_ADDR(r), client_type);
310 apr_table_setn(r->subprocess_env, "X_CLIENT_TYPE", client_type);
311 apr_table_setn(r->headers_in, "X-Client-Type", client_type);
314 apr_table_unset(r->headers_in, "X-Client-Type");
318 if (! apr_table_get(r->headers_in, "Content-Length")) {
319 contentLength = (char *)apr_table_get(r->headers_in, "X-Chxj-Content-Length");
321 apr_table_set(r->headers_in, "Content-Length", contentLength);
328 if(r->content_type && strncmp(r->content_type,"image/",6) == 0){
329 if (dconf->image_rewrite == CHXJ_IMG_REWRITE_ON && !apr_table_get(r->headers_in, CHXJ_IMG_X_HTTP_IMAGE_FILENAME)){
330 if(dconf->image_rewrite_mode == CHXJ_IMG_REWRITE_MODE_ALL){
332 apr_table_set(r->headers_in, CHXJ_IMG_X_HTTP_IMAGE_FILENAME, r->filename);
333 apr_table_set(r->headers_in, CHXJ_IMG_X_HTTP_IMAGE_TYPE,r->content_type);
334 r->filename = apr_pstrcat(r->pool,"img-redirect:",dconf->image_rewrite_url,NULL);
335 r->handler = "chxj-image-redirect-handler";
339 // has _chxj_imgrewrite=on in args
340 char *args_tmp = chxj_url_decode(r->pool, r->args);
341 if (strstr(args_tmp,CHXJ_IMG_REWRITE_URL_STRING)){
342 apr_table_set(r->headers_in, CHXJ_IMG_X_HTTP_IMAGE_FILENAME, r->filename);
343 apr_table_set(r->headers_in, CHXJ_IMG_X_HTTP_IMAGE_TYPE,r->content_type);
344 r->filename = apr_pstrcat(r->pool,"img-redirect:",dconf->image_rewrite_url,NULL);
345 r->handler = "chxj-image-redirect-handler";
353 chxj_add_device_env(r, spec);
355 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
361 chxj_image_redirect_handler(request_rec *r)
364 if (strcmp(r->handler, "chxj-image-redirect-handler")) {
368 if (strncmp(r->filename, "img-redirect:", 13) != 0) {
371 DBG(r,"REQ[%X] start %s()",TO_ADDR(r),__func__);
372 ap_internal_redirect(apr_pstrcat(r->pool, r->filename+13,
373 r->args ? "?" : NULL, r->args, NULL), r);
374 DBG(r,"REQ[%X] end %s()", TO_ADDR(r),__func__);
380 s_clear_cookie_header(request_rec *r, device_table *spec)
382 DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
383 switch(spec->html_spec_type) {
384 case CHXJ_SPEC_Chtml_1_0:
385 case CHXJ_SPEC_Chtml_2_0:
386 case CHXJ_SPEC_Chtml_3_0:
387 case CHXJ_SPEC_Chtml_4_0:
388 case CHXJ_SPEC_Chtml_5_0:
389 case CHXJ_SPEC_Chtml_6_0:
390 case CHXJ_SPEC_Chtml_7_0:
391 case CHXJ_SPEC_XHtml_Mobile_1_0:
392 case CHXJ_SPEC_Jhtml:
393 case CHXJ_SPEC_Jxhtml:
394 apr_table_unset(r->headers_in, "Cookie");
399 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
404 * It converts it from CHTML into XXML corresponding to each model.
407 * @param src [i] It is former HTML character string.
408 * @param len [i/o] It is length of former HTML character string.
411 chxj_convert(request_rec *r, const char **src, apr_size_t *len, device_table *spec, const char *ua, cookie_t **cookiep)
417 mod_chxj_config *dconf;
418 chxjconvrule_entry *entryp;
420 DBG(r,"REQ[%X] start %s()", TO_ADDR(r),__func__);
422 chxj_dump_string(r, APLOG_MARK, "INPUT Data", *src, *len);
424 dst = apr_pstrcat(r->pool, (char *)*src, NULL);
426 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
429 entryp = chxj_apply_convrule(r, dconf->convrules);
431 if (!entryp || (!(entryp->action & CONVRULE_ENGINE_ON_BIT) && !(entryp->action & CONVRULE_COOKIE_ONLY_BIT))) {
432 DBG(r,"REQ[%X] end %s()", TO_ADDR(r),__func__);
437 /*------------------------------------------------------------------------*/
438 /* get UserAgent from http header */
439 /*------------------------------------------------------------------------*/
440 if (entryp->user_agent)
441 user_agent = (char *)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
443 user_agent = (char *)apr_table_get(r->headers_in, HTTP_USER_AGENT);
445 DBG(r,"REQ[%X] User-Agent:[%s]", TO_ADDR(r), user_agent);
446 DBG(r,"REQ[%X] content type is [%s]", TO_ADDR(r), r->content_type);
449 if ( ! STRNCASEEQ('t','T', "text/html", r->content_type, sizeof("text/html")-1)
450 && ! STRNCASEEQ('a','A', "application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)) {
451 DBG(r,"REQ[%X] no convert. content type is [%s]", TO_ADDR(r), r->content_type);
452 DBG(r,"REQ[%X] end %s()", TO_ADDR(r),__func__);
456 if (ua && user_agent && strcasecmp(user_agent, ua) != 0) {
458 spec = chxj_specified_device(r, user_agent);
465 if ((entryp->action & CONVRULE_COOKIE_ON_BIT
466 && !(entryp->action & CONVRULE_EMOJI_ONLY_BIT)
467 && !(entryp->action & CONVRULE_ENVINFO_ONLY_BIT))
468 || (entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
469 switch(spec->html_spec_type) {
470 case CHXJ_SPEC_Chtml_1_0:
471 case CHXJ_SPEC_Chtml_2_0:
472 case CHXJ_SPEC_Chtml_3_0:
473 case CHXJ_SPEC_Chtml_4_0:
474 case CHXJ_SPEC_Chtml_5_0:
475 case CHXJ_SPEC_Chtml_6_0:
476 case CHXJ_SPEC_Chtml_7_0:
477 case CHXJ_SPEC_XHtml_Mobile_1_0:
478 case CHXJ_SPEC_Jhtml:
479 case CHXJ_SPEC_Jxhtml:
480 cookie = chxj_save_cookie(r);
487 if (!r->header_only) {
489 if ((entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
491 dst = chxj_cookie_only_mode(r, *src, (apr_size_t *)len, cookie);
499 if (convert_routine[spec->html_spec_type].encoder)
500 tmp = convert_routine[spec->html_spec_type].encoder(r,
504 if (entryp->action & CONVRULE_EMOJI_ONLY_BIT) {
506 tmp = chxj_node_convert_chxjif_only(r, spec, (const char*)tmp, (apr_size_t *)len);
509 tmp = chxj_node_convert_chxjif_only(r, spec, (const char *)*src, (apr_size_t *)len);
511 if (convert_routine[spec->html_spec_type].emoji_only_converter) {
512 dst = convert_routine[spec->html_spec_type].emoji_only_converter(r,spec, tmp,*len);
517 dst = apr_palloc(r->pool, 1);
522 DBG(r, "REQ[%X] end %s()(emoji only)", TO_ADDR(r),__func__);
525 if ( !(entryp->action & CONVRULE_EMOJI_ONLY_BIT)
526 && !(entryp->action & CONVRULE_ENVINFO_ONLY_BIT)) {
527 if (convert_routine[spec->html_spec_type].converter) {
529 dst = convert_routine[spec->html_spec_type].converter(r,
537 dst = convert_routine[spec->html_spec_type].converter(r,
549 if (strcasecmp(spec->output_encoding,"UTF-8") == 0){
550 dst = chxj_iconv(r,r->pool,dst,len,"CP932","UTF-8");
555 ap_set_content_length(r, *len);
558 dst = apr_psprintf(r->pool, "\n");
568 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
575 * convert GUID parameter.
579 s_convert_guid_parameter_to_header(request_rec *r, const char *param, device_table *spec)
581 DBG(r, "REQ[%X] start %s() param:[%s]", TO_ADDR(r),__func__, param);
582 if (strcasecmp(param, "guid") == 0) {
583 switch(spec->html_spec_type) {
584 case CHXJ_SPEC_XHtml_Mobile_1_0:
586 char *x_up_subno = (char *)apr_table_get(r->headers_in, "x-up-subno");
588 apr_table_setn(r->headers_in, "X-DCMGUID", x_up_subno);
592 case CHXJ_SPEC_Jhtml:
593 case CHXJ_SPEC_Jxhtml:
595 char *x_jphone_uid = (char *)apr_table_get(r->headers_in, "x-jphone-uid");
597 apr_table_setn(r->headers_in, "X-DCMGUID", x_jphone_uid);
605 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
609 * It converts it from HEADER.
614 chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp, device_table *spec)
626 cookie_t *cookie = NULL;
627 int no_update_flag = 0;
629 DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
632 DBG(r, "REQ[%X] r->args=[null]", TO_ADDR(r));
633 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
636 urilen = strlen(r->args);
638 result = qs_alloc_zero_byte_string(r->pool);
640 buff_pre = apr_pstrdup(r->pool, r->args);
645 pair = apr_strtok(buff_pre, "&", &pstate);
651 pair_sv = apr_pstrdup(r->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", TO_ADDR(r));
662 buff = apr_pstrdup(r->pool, r->args);
663 DBG(r, "REQ[%X] r->args=[%s]", TO_ADDR(r), buff);
672 pair = apr_strtok(buff, "&", &pstate);
678 pair_sv = apr_pstrdup(r->pool, pair);
680 name = apr_strtok(pair, "=", &vstate);
681 value = apr_strtok(NULL, "=", &vstate);
682 if (! name) continue;
683 name = chxj_safe_to_jreserved_tag(r, name);
684 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
685 if (strlen(result) != 0)
686 result = apr_pstrcat(r->pool, result, "&", NULL);
688 if (strcasecmp(entryp->encoding, "NONE") != 0) {
693 if (value && *value != 0) {
694 value = chxj_url_decode(r->pool, value);
695 dlen = strlen(value);
696 DBG(r, "REQ[%X] ************ before encoding[%s]", TO_ADDR(r),value);
698 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
699 dvalue = chxj_url_encode(r->pool, dvalue);
701 DBG(r, "REQ[%X] ************ after encoding[%s]", TO_ADDR(r),dvalue);
707 if (name && *name != 0) {
708 name = chxj_url_decode(r->pool, name);
710 dname = chxj_rencoding(r, name, &dlen,spec->output_encoding);
711 dname = chxj_url_encode(r->pool, dname);
716 s_convert_guid_parameter_to_header(r, dname, spec);
717 result = apr_pstrcat(r->pool, result, dname, "=", dvalue, NULL);
720 s_convert_guid_parameter_to_header(r, name, spec);
721 if (strcmp(name, pair_sv) != 0) {
722 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
725 result = apr_pstrcat(r->pool, result, name, NULL);
730 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
731 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
732 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
736 if (strlen(value) == 0)
739 if (strlen(result) != 0)
740 result = apr_pstrcat(r->pool, result, "&", NULL);
742 result = apr_pstrcat(r->pool, result, &name[8], "=", value, NULL);
745 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
747 apr_table_unset(r->headers_in, "Cookie");
748 DBG(r, "REQ[%X] found cookie parameter[%s]", TO_ADDR(r), value);
749 cookie_lock_t *lock = chxj_cookie_lock(r);
750 cookie = chxj_load_cookie(r, value);
751 if (! no_update_flag && cookie) {
752 cookie = chxj_update_cookie(r, cookie);
754 chxj_cookie_unlock(r, lock);
756 if (cookie && cookie->cookie_id) {
757 if (strlen(result) != 0)
758 result = apr_pstrcat(r->pool, result, "&", NULL);
759 result = apr_pstrcat(r->pool, result, name, "=", cookie->cookie_id, NULL);
763 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
764 if (strlen(result) != 0)
765 result = apr_pstrcat(r->pool, result, "&", NULL);
766 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
769 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
770 if (! no_update_flag) {
771 result = apr_pstrcat(r->pool, result, "&_chxj_nc=true", NULL);
775 DBG(r, "REQ[%X] result r->args=[%s]", TO_ADDR(r), r->args);
776 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
782 * It converts it from POSTDATA .
785 * @param src [i] It is POSTDATA character string.
786 * @param len [i/o] It is length of former HTML character string.
793 chxjconvrule_entry *entryp,
803 cookie_t *cookie = NULL;
805 int no_update_flag = 0;
809 DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
812 DBG(r, "REQ[%X] end %s() (input is null)", TO_ADDR(r),__func__);
813 return apr_pstrdup(r->pool, "");
816 apr_pool_create(&pool, r->pool);
818 s = apr_pstrdup(pool, *src);
820 buff_pre = apr_pstrdup(pool, *src);
822 result = qs_alloc_zero_byte_string(pool);
824 chxj_dump_string(r, APLOG_MARK, "BEFORE input convert source", s, ilen);
829 pair = apr_strtok(buff_pre, "&", &pstate);
835 pair_sv = apr_pstrdup(pool, pair);
837 name = apr_strtok(pair, "=", &vstate);
838 value = apr_strtok(NULL, "=", &vstate);
839 if (! name) continue;
840 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
841 DBG(r, "REQ[%X] found cookie no update parameter", TO_ADDR(r));
851 pair = apr_strtok(s, "&", &pstate);
856 name = apr_strtok(pair, "=", &vstate);
857 value = apr_strtok(NULL, "=", &vstate);
858 if (! name) continue;
859 name = chxj_safe_to_jreserved_tag(r, name);
861 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
862 if (strlen(result) != 0)
863 result = apr_pstrcat(pool, result, "&", NULL);
865 if (strcasecmp(entryp->encoding, "NONE") != 0) {
870 if (value && *value != 0) {
871 value = chxj_url_decode(pool, value);
872 dlen = strlen(value);
873 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
874 dvalue = chxj_url_encode(pool, dvalue);
880 if (name && *name != 0) {
881 name = chxj_url_decode(pool, name);
883 dname = chxj_rencoding(r, name, &dlen,spec->output_encoding);
884 dname = chxj_url_encode(pool, dname);
891 result = apr_pstrcat(pool, result, dname, "=", dvalue, NULL);
894 result = apr_pstrcat(pool, result, name, "=", value, NULL);
898 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
899 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
900 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
904 if (strlen(value) == 0)
907 if (strlen(result) != 0)
908 result = apr_pstrcat(pool, result, "&", NULL);
910 if (strcasecmp(entryp->encoding, "NONE") != 0 && value && strlen(value)) {
914 dlen = strlen(value);
915 value = chxj_url_decode(pool, value);
916 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
917 dvalue = chxj_url_encode(pool,dvalue);
918 result = apr_pstrcat(pool, result, &name[8], "=", dvalue, NULL);
922 result = apr_pstrcat(pool, result, &name[8], "=", value, NULL);
926 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
928 apr_table_unset(r->headers_in, "Cookie");
929 DBG(r, "REQ[%X] found cookie parameter[%s]", TO_ADDR(r), value);
930 cookie_lock_t *lock = chxj_cookie_lock(r);
931 cookie = chxj_load_cookie(r, value);
932 if (! no_update_flag && cookie) {
933 cookie = chxj_update_cookie(r, cookie);
935 chxj_cookie_unlock(r, lock);
937 if (cookie && cookie->cookie_id) {
938 if (strlen(result) != 0)
939 result = apr_pstrcat(pool, result, "&", NULL);
940 result = apr_pstrcat(pool, result, name, "=", cookie->cookie_id, NULL);
944 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
945 if (strlen(result) != 0)
946 result = apr_pstrcat(pool, result, "&", NULL);
947 result = apr_pstrcat(pool, result, name, "=", value, NULL);
950 if ( strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1) == 0) {
954 dlen = strlen(value);
957 value = chxj_url_decode(pool, value);
958 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
959 dvalue = chxj_url_encode(pool,dvalue);
960 if (r->args && strlen(r->args) > 0) {
961 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
964 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
966 s_convert_guid_parameter_to_header(r, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], spec);
970 if (strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX_ENC, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1) == 0) {
973 dlen = strlen(value);
975 value = chxj_url_decode(pool, value);
976 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
977 dvalue = chxj_url_encode(pool,dvalue);
978 if (r->args && strlen(r->args) > 0) {
979 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
982 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
984 s_convert_guid_parameter_to_header(r, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], spec);
987 DBG(r, "REQ[%X] ************************ name:[%s]", TO_ADDR(r), name);
989 *len = strlen(result);
990 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
991 if (! no_update_flag) {
992 result = apr_pstrcat(pool, result, "&_chxj_nc=true", NULL);
995 DBG(r, "REQ[%X] AFTER input convert result = [%s]", TO_ADDR(r), result);
996 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1003 * The received data is returned to the filter.
1005 * @param f [i/o] It is a filter.
1006 * @param data [i] It is data returned to the filter.
1007 * @param len [i] It is length of the data returned to the filter.
1010 pass_data_to_filter(ap_filter_t *f, const char *data,
1013 request_rec *r = f->r;
1014 conn_rec *c = r->connection;
1016 apr_bucket_brigade *bb;
1019 DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
1021 chxj_header_inf_clear(r);
1023 bb = apr_brigade_create(r->pool, c->bucket_alloc);
1024 b = apr_bucket_transient_create(data, len, c->bucket_alloc);
1026 APR_BRIGADE_INSERT_TAIL(bb, b);
1027 b = apr_bucket_eos_create(f->c->bucket_alloc);
1028 APR_BRIGADE_INSERT_TAIL(bb, b);
1030 rv = ap_pass_brigade(f->next, bb);
1031 if (rv != APR_SUCCESS) {
1032 DBG(r, "REQ[%X] end %s() (apr_pass_brigade)", TO_ADDR(r),__func__);
1036 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1042 * Add No Cache Header
1045 s_add_no_cache_headers(request_rec *r, chxjconvrule_entry *entryp)
1047 if (entryp->action & CONVRULE_NOCACHE_ON_BIT) {
1048 apr_table_unset(r->headers_out, "Pragma");
1049 apr_table_unset(r->err_headers_out, "Pragma");
1050 apr_table_unset(r->headers_out, "Expires");
1051 apr_table_unset(r->err_headers_out, "Expires");
1052 apr_table_unset(r->headers_out, "Cache-Control");
1053 apr_table_unset(r->err_headers_out, "Cache-Control");
1055 apr_table_setn(r->err_headers_out, "Pragma", "no-cache");
1056 apr_table_setn(r->err_headers_out, "Expires", "Thu, 01 Jan 1970 00:00:00 GMT");
1057 apr_table_setn(r->err_headers_out, "Cache-Control", "no-cache, no-store");
1063 * It is the main loop of the output filter.
1065 * @param f [i/o] It is a filter.
1069 chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
1075 char *user_agent = NULL;
1077 mod_chxj_ctx *ctx = (mod_chxj_ctx *)f->ctx;
1078 cookie_t *cookie = NULL;
1079 mod_chxj_config *dconf;
1080 chxjconvrule_entry *entryp = NULL;
1081 device_table *spec = NULL;
1085 DBG(f->r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
1088 apr_pool_create(&pool, r->pool);
1090 entryp = ctx->entryp;
1092 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1095 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1096 DBG(r, "REQ[%X] found Location header", TO_ADDR(r));
1097 if ((entryp->action & CONVRULE_COOKIE_ON_BIT) || (entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
1098 cookie_lock_t *lock = NULL;
1099 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", TO_ADDR(r));
1100 switch(spec->html_spec_type) {
1101 case CHXJ_SPEC_Chtml_1_0:
1102 case CHXJ_SPEC_Chtml_2_0:
1103 case CHXJ_SPEC_Chtml_3_0:
1104 case CHXJ_SPEC_Chtml_4_0:
1105 case CHXJ_SPEC_Chtml_5_0:
1106 case CHXJ_SPEC_Chtml_6_0:
1107 case CHXJ_SPEC_Chtml_7_0:
1108 case CHXJ_SPEC_XHtml_Mobile_1_0:
1109 case CHXJ_SPEC_Jhtml:
1110 case CHXJ_SPEC_Jxhtml:
1111 lock = chxj_cookie_lock(r);
1112 cookie = chxj_save_cookie(r);
1113 s_add_cookie_id_if_has_location_header(r, cookie);
1114 chxj_cookie_unlock(r, lock);
1120 if (! ap_is_HTTP_REDIRECT(r->status)) {
1121 r->status = HTTP_MOVED_TEMPORARILY;
1123 s_add_no_cache_headers(r, entryp);
1124 /* must not send body. */
1125 rv = pass_data_to_filter(f, "", 0);
1126 DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1131 if (r->content_type) {
1132 if (! STRNCASEEQ('t','T',"text/html",r->content_type, sizeof("text/html")-1)
1133 && ! STRNCASEEQ('t','T',"text/xml", r->content_type, sizeof("text/xml")-1)
1134 && ! STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
1135 && ! (dconf->image == CHXJ_IMG_ON
1136 && ! apr_table_get(r->headers_in, "CHXJ_IMG_CONV")
1137 && STRNCASEEQ('i','I',"image/", r->content_type, sizeof("image/") -1)
1138 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
1139 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
1140 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
1141 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
1142 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
1143 || STRCASEEQ('x','X',"x-ms-bmp", &r->content_type[6]) /* BMP */
1144 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
1145 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
1146 || STRCASEEQ('g','G',"gif", &r->content_type[6])))) { /* GIF */
1148 DBG(r, "REQ[%X] not convert content-type:[%s] dconf->image:[%d]", TO_ADDR(r), r->content_type, dconf->image);
1149 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
1150 cookie_lock_t *lock = NULL;
1151 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", TO_ADDR(r));
1152 switch(spec->html_spec_type) {
1153 case CHXJ_SPEC_Chtml_1_0:
1154 case CHXJ_SPEC_Chtml_2_0:
1155 case CHXJ_SPEC_Chtml_3_0:
1156 case CHXJ_SPEC_Chtml_4_0:
1157 case CHXJ_SPEC_Chtml_5_0:
1158 case CHXJ_SPEC_Chtml_6_0:
1159 case CHXJ_SPEC_Chtml_7_0:
1160 case CHXJ_SPEC_XHtml_Mobile_1_0:
1161 case CHXJ_SPEC_Jhtml:
1162 case CHXJ_SPEC_Jxhtml:
1163 lock = chxj_cookie_lock(r);
1164 cookie = chxj_save_cookie(r);
1165 s_add_cookie_id_if_has_location_header(r, cookie);
1166 chxj_cookie_unlock(r, lock);
1172 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1173 if (! ap_is_HTTP_REDIRECT(r->status)) {
1174 r->status = HTTP_MOVED_TEMPORARILY;
1177 s_add_no_cache_headers(r, entryp);
1178 ap_pass_brigade(f->next, bb);
1179 DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1184 DBG(r, "REQ[%X] not convert content-type:[(null)]", TO_ADDR(r));
1185 ap_pass_brigade(f->next, bb);
1186 DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1191 for (b = APR_BRIGADE_FIRST(bb);
1192 b != APR_BRIGADE_SENTINEL(bb);
1193 b = APR_BUCKET_NEXT(b)) {
1195 if (apr_bucket_read(b, &data, &len, APR_BLOCK_READ) == APR_SUCCESS) {
1196 chxj_dump_string(r, APLOG_MARK, "READ Data", data, len);
1198 /*--------------------------------------------------------------------*/
1200 /*--------------------------------------------------------------------*/
1202 DBG(r, "REQ[%X] append data start", TO_ADDR(r));
1203 ctx = (mod_chxj_ctx *)f->ctx;
1206 tmp = apr_palloc(r->pool, ctx->len);
1207 memcpy(tmp, ctx->buffer, ctx->len);
1209 ctx->buffer = apr_palloc(pool, ctx->len + len);
1211 memcpy(ctx->buffer, tmp, ctx->len);
1212 memcpy(&ctx->buffer[ctx->len], data, len);
1216 DBG(r, "REQ[%X] append data end", TO_ADDR(r));
1219 if (APR_BUCKET_IS_EOS(b)) {
1221 DBG(r, "REQ[%X] eos", TO_ADDR(r));
1222 /*----------------------------------------------------------------------*/
1224 /*----------------------------------------------------------------------*/
1226 cookie_lock_t *lock = NULL;
1227 ctx = (mod_chxj_ctx *)f->ctx;
1229 DBG(r, "REQ[%X] content_type=[%s]", TO_ADDR(r), r->content_type);
1230 lock = chxj_cookie_lock(r);
1232 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
1234 && (STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
1235 || STRNCASEEQ('t','T',"text/html", r->content_type, sizeof("text/html")-1))) {
1236 DBG(r, "REQ[%X] detect convert target:[%s]", TO_ADDR(r), r->content_type);
1241 tmp = apr_palloc(pool, ctx->len + 1);
1243 memset(tmp, 0, ctx->len + 1);
1244 memcpy(tmp, ctx->buffer, ctx->len);
1246 ctx->buffer = chxj_convert(r,
1247 (const char **)&tmp,
1248 (apr_size_t *)&ctx->len,
1250 user_agent, &cookie);
1254 ctx->buffer = apr_psprintf(r->pool, "\n");
1256 ctx->buffer = chxj_convert(r,
1257 (const char **)&ctx->buffer,
1258 (apr_size_t *)&ctx->len,
1260 user_agent, &cookie);
1265 && *(char *)r->content_type == 't'
1266 && strncmp(r->content_type, "text/xml", 8) == 0) {
1267 DBG(r, "REQ[%X] text/XML", TO_ADDR(r));
1275 memset(&doc, 0, sizeof(Doc));
1276 memset(&qrcode, 0, sizeof(qr_code_t));
1278 doc.parse_mode = PARSE_MODE_CHTML;
1282 qs_init_malloc(&doc);
1284 root = qs_parse_string(&doc, ctx->buffer, ctx->len);
1287 for (child = qs_get_child_node(&doc,root);
1289 child = qs_get_next_node(&doc,child)) {
1290 char *name = qs_get_node_name(&doc,child);
1291 if (strcasecmp("qrcode",name) == 0) {
1296 qs_all_free(&doc,QX_LOGMARK);
1298 r->handler = apr_psprintf(r->pool, "chxj-qrcode");
1299 chxj_qrcode_node_to_qrcode(&qrcode, root);
1300 sts = chxj_qrcode_create_image_data(&qrcode, &ctx->buffer, &ctx->len);
1302 ERR(r, "REQ[%X] qrcode create failed.", TO_ADDR(r));
1303 chxj_cookie_unlock(r, lock);
1304 DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1307 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1311 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
1313 && ( *r->content_type == 'i' || *r->content_type == 'I')
1314 && dconf->image == CHXJ_IMG_ON
1315 && strncasecmp("image/", r->content_type, 6) == 0
1316 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
1317 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
1318 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
1319 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
1320 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
1321 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
1322 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
1323 || STRCASEEQ('x','X',"x-ms-bmp", &r->content_type[6]) /* BMP */
1324 || STRCASEEQ('g','G',"gif", &r->content_type[6]))) { /* GIF */
1325 DBG(r, "REQ[%X] detect convert target:[%s]", TO_ADDR(r), r->content_type);
1329 DBG(r, "REQ[%X] ctx->len[%d]", TO_ADDR(r), (unsigned int)ctx->len);
1330 tmp = apr_palloc(pool, ctx->len + 1);
1332 memset(tmp, 0, ctx->len + 1);
1333 memcpy(tmp, ctx->buffer, ctx->len);
1335 chxj_convert_image(r,
1336 (const char **)&tmp,
1337 (apr_size_t *)&ctx->len);
1341 apr_table_unset(r->headers_out, "Content-Length");
1342 apr_table_unset(r->err_headers_out, "Content-Length");
1343 ap_set_content_length(r, (apr_off_t)ctx->len);
1347 DBG(r, "REQ[%X] call %s()", TO_ADDR(r),__func__);
1348 s_add_cookie_id_if_has_location_header(r, cookie);
1349 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1350 if (! ap_is_HTTP_REDIRECT(r->status)) {
1351 r->status = HTTP_MOVED_TEMPORARILY;
1354 if (ctx->len && ap_is_HTTP_REDIRECT(r->status)) {
1355 ctx->buffer = apr_pstrdup(pool, "");
1357 ap_set_content_length(r, (apr_off_t)ctx->len);
1359 chxj_cookie_unlock(r,lock);
1360 s_add_no_cache_headers(r, entryp);
1361 rv = pass_data_to_filter(f,
1362 (const char *)ctx->buffer,
1363 (apr_size_t)ctx->len);
1366 ctx->buffer = apr_pstrdup(pool, "");
1368 ap_set_content_length(r, (apr_off_t)ctx->len);
1369 chxj_cookie_unlock(r, lock);
1370 s_add_no_cache_headers(r, entryp);
1371 rv = pass_data_to_filter(f,
1372 (const char *)ctx->buffer,
1373 (apr_size_t)ctx->len);
1375 DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1379 DBG(r, "REQ[%X] SAVE COOKIE[%x]", TO_ADDR(r), entryp->action);
1384 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
1385 cookie_lock_t *lock = NULL;
1386 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", TO_ADDR(r));
1387 switch(spec->html_spec_type) {
1388 case CHXJ_SPEC_Chtml_1_0:
1389 case CHXJ_SPEC_Chtml_2_0:
1390 case CHXJ_SPEC_Chtml_3_0:
1391 case CHXJ_SPEC_Chtml_4_0:
1392 case CHXJ_SPEC_Chtml_5_0:
1393 case CHXJ_SPEC_Chtml_6_0:
1394 case CHXJ_SPEC_Chtml_7_0:
1395 case CHXJ_SPEC_XHtml_Mobile_1_0:
1396 case CHXJ_SPEC_Jhtml:
1397 case CHXJ_SPEC_Jxhtml:
1398 lock = chxj_cookie_lock(r);
1399 cookie = chxj_save_cookie(r);
1401 * Location Header Check to add cookie parameter.
1403 s_add_cookie_id_if_has_location_header(r, cookie);
1404 chxj_cookie_unlock(r, lock);
1405 apr_table_unset(r->headers_out, "Set-Cookie");
1406 apr_table_unset(r->err_headers_out, "Set-Cookie");
1413 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1414 if (! ap_is_HTTP_REDIRECT(r->status)) {
1415 r->status = HTTP_MOVED_TEMPORARILY;
1418 apr_table_setn(r->headers_out, "Content-Length", "0");
1419 s_add_no_cache_headers(r, entryp);
1420 rv = pass_data_to_filter(f, (const char *)"", (apr_size_t)0);
1425 apr_brigade_destroy(bb);
1427 DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1433 * Add Cookie_id if it has location header.
1436 s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie)
1438 DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
1439 char *location_header = (char *)apr_table_get(r->headers_out, "Location");
1440 if (! location_header) {
1441 location_header = (char *)apr_table_get(r->err_headers_out, "Location");
1443 if (cookie && location_header) {
1444 DBG(r, "REQ[%X] Location Header=[%s]", TO_ADDR(r), location_header);
1445 location_header = chxj_add_cookie_parameter(r,
1448 apr_table_unset(r->headers_out, "Location");
1449 apr_table_setn(r->headers_out, "Location", location_header);
1450 DBG(r, "REQ[%X] Location Header=[%s]", TO_ADDR(r), location_header);
1451 if (!ap_is_HTTP_REDIRECT(r->status)) {
1452 r->status = HTTP_MOVED_TEMPORARILY;
1455 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1459 * It is the main loop of the input filter handler.
1463 chxj_input_handler(request_rec *r)
1465 mod_chxj_config *dconf;
1466 chxjconvrule_entry *entryp = NULL;
1467 device_table *spec = NULL;
1468 char *post_data = NULL;
1469 apr_size_t post_data_len = 0;
1473 int response_code = 0;
1475 DBG(r, "REQ[%X] start %s()",TO_ADDR(r),__func__);
1477 if (strcasecmp(r->handler, "chxj-input-handler")) {
1478 DBG(r, "REQ[%X] end %s()",TO_ADDR(r),__func__);
1481 apr_pool_create(&pool, r->pool);
1483 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1484 user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
1486 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
1488 spec = chxj_specified_device(r, user_agent);
1489 entryp = chxj_apply_convrule(r, dconf->convrules);
1491 post_data = apr_pstrdup(pool, "");
1492 if (ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK) == OK) {
1493 if (ap_should_client_block(r)) {
1494 while (post_data_len < CHXJ_POST_MAX) {
1497 int read_bytes = ap_get_client_block(r, buffer, BUFSZ-1);
1498 if (read_bytes<=0) {
1501 buffer[read_bytes] = '\0';
1502 post_data = apr_pstrcat(pool, post_data, buffer, NULL);
1503 post_data_len += read_bytes;
1512 if (post_data_len > 0) {
1513 post_data = chxj_input_convert(r, (const char**)&post_data, (apr_size_t*)&post_data_len, entryp, spec);
1514 DBG(r, "REQ[%X] (in:exchange)POSTDATA:[%s]", TO_ADDR(r),post_data);
1518 if (dconf->forward_url_base) {
1519 url_path = apr_psprintf(pool, "%s%s", dconf->forward_url_base, r->uri);
1522 url_path = apr_psprintf(pool, "%s://%s:%d%s", chxj_apache_run_http_scheme(r), ap_get_server_name(r), ap_get_server_port(r), r->uri);
1525 url_path = apr_pstrcat(pool, url_path, "?", r->args, NULL);
1527 DBG(r, "REQ[%X] ==> new url_path:[%s]", TO_ADDR(r),url_path);
1530 apr_table_setn(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP, r->connection->remote_ip);
1531 char *x_client_type = (char *)apr_table_get(r->headers_in, "X-Client-Type");
1532 if (x_client_type) {
1533 apr_table_setn(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_TYPE, x_client_type); /* for mod_cidr_lookup */
1536 apr_table_unset(r->headers_in, "X-Client-Type");
1538 apr_table_unset(r->headers_in, "Content-Length");
1539 apr_table_setn(r->headers_in, "Content-Length", apr_psprintf(pool, "%" APR_SIZE_T_FMT, post_data_len));
1540 response = chxj_serf_post(r, pool, url_path, post_data, post_data_len, 1, &res_len, &response_code);
1542 DBG(r, "REQ[%X] -------------------------------------------------------", TO_ADDR(r));
1543 DBG(r, "REQ[%X] response length:[%" APR_SIZE_T_FMT "]", (unsigned int)(apr_size_t)r, res_len);
1544 for (ii=0; ii<res_len/64; ii++) {
1545 DBG(r, "REQ[%X] response:[%.*s]", TO_ADDR(r), 64, &response[ii*64]);
1547 DBG(r, "REQ[%X] -------------------------------------------------------", TO_ADDR(r));
1551 if ((chunked = (char *)apr_table_get(r->headers_out, "Transfer-Encoding")) != NULL) {
1552 if (strcasecmp(chunked, "chunked") == 0) {
1554 apr_table_unset(r->headers_out, "Transfer-Encoding");
1557 if (ap_is_HTTP_ERROR(response_code)) {
1558 DBG(r, "REQ[%X] end %s() (HTTP-ERROR received. response code:[%d])", TO_ADDR(r), __func__,response_code);
1559 return response_code;
1563 apr_pool_create(&wpool, r->pool);
1564 apr_bucket_brigade *bb;
1567 conn_rec *c = r->connection;
1569 bb = apr_brigade_create(wpool, c->bucket_alloc);
1570 e = apr_bucket_transient_create(response, res_len, c->bucket_alloc);
1571 APR_BRIGADE_INSERT_TAIL(bb, e);
1572 e = apr_bucket_eos_create(c->bucket_alloc);
1573 APR_BRIGADE_INSERT_TAIL(bb, e);
1574 if ((rv = ap_pass_brigade(r->output_filters, bb)) != APR_SUCCESS) {
1575 ERR(r, "REQ[%X] %s:%d failed ap_pass_brigade()", TO_ADDR(r), APLOG_MARK);
1578 apr_brigade_cleanup(bb);
1581 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1585 static mod_chxj_global_config *
1586 chxj_global_config_create(apr_pool_t *pool, server_rec *s)
1588 mod_chxj_global_config *conf;
1590 SDBG(s, "start chxj_global_config_create()");
1592 /*--------------------------------------------------------------------------*/
1593 /* allocate an own subpool which survives server restarts */
1594 /*--------------------------------------------------------------------------*/
1595 conf = (mod_chxj_global_config *)apr_palloc(pool,
1596 sizeof(mod_chxj_global_config));
1598 conf->cookie_db_lock = NULL;
1600 SDBG(s, "end chxj_global_config_create()");
1607 * initialize chxj module
1610 chxj_init_module(apr_pool_t *p,
1611 apr_pool_t *UNUSED(plog),
1612 apr_pool_t *UNUSED(ptemp),
1618 SDBG(s, "start chxj_init_module()");
1620 apr_pool_userdata_get(&user_data, CHXJ_MOD_CONFIG_KEY, s->process->pool);
1622 if (user_data == NULL) {
1625 * dummy user_data set.
1627 apr_pool_userdata_set(
1629 CHXJ_MOD_CONFIG_KEY,
1630 apr_pool_cleanup_null,
1632 SDBG(s, "end chxj_init_module()");
1636 ap_add_version_component(p, CHXJ_VERSION_PREFIX CHXJ_VERSION);
1638 if ((rv = apr_proc_mutex_create(&global_cookie_mutex, NULL, APR_LOCK_FCNTL, s->process->pool)) != APR_SUCCESS) {
1640 SERR(s, "%s:%d end chxj_init_module(). mutex create failure.(%d:%s)",APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1641 return HTTP_INTERNAL_SERVER_ERROR;
1644 SDBG(s, "end chxj_init_module()");
1651 chxj_child_init(apr_pool_t *UNUSED(p), server_rec *s)
1654 SDBG(s, "start chxj_child_init()");
1655 if ((rv = apr_proc_mutex_child_init(&global_cookie_mutex, NULL, s->process->pool)) != APR_SUCCESS) {
1657 SERR(s, "%s:%d ERROR end chxj_init_module(). mutex create failure.(%d:%s)", APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1659 SDBG(s, "end chxj_child_init()");
1664 * A set structure of each server is generated.
1670 chxj_config_server_create(apr_pool_t *p, server_rec *s)
1672 mod_chxj_global_config *gc;
1674 gc = chxj_global_config_create(p,s);
1681 chxj_translate_name(request_rec *r)
1683 DBG(r, "REQ[%X] =======================================================================", TO_ADDR(r));
1684 DBG(r, "REQ[%X] ", TO_ADDR(r));
1685 DBG(r, "REQ[%X] START REQUEST (uri:[%s] args:[%s])", TO_ADDR(r), r->unparsed_uri, r->args ? r->args : "");
1686 DBG(r, "REQ[%X] METHOD [%s]", TO_ADDR(r), r->method);
1687 DBG(r, "REQ[%X] ", TO_ADDR(r));
1688 DBG(r, "REQ[%X] =======================================================================", TO_ADDR(r));
1690 mod_chxj_config *dconf;
1691 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1693 if (dconf->image_rewrite ==CHXJ_IMG_REWRITE_ON ){
1694 if(r->args && strcasecmp(r->args,"rewrite") == 0){
1695 DBG(r, "image rewrite is ON [%s] - %s", dconf->image_rewrite_url ,r->content_type);
1696 r->filename = apr_pstrcat(r->pool,dconf->image_rewrite_url,NULL);
1703 return chxj_trans_name(r);
1711 chxj_insert_filter(request_rec *r)
1715 mod_chxj_config *dconf;
1716 chxjconvrule_entry *entryp;
1721 DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
1723 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1725 /* we get User-Agent from CHXJ_HTTP_USER_AGENT header if any */
1726 user_agent = (char *)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
1728 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
1731 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
1733 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
1734 DBG(r, "REQ[%X] detect multipart/form-data ==> no target", TO_ADDR(r));
1735 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1739 spec = chxj_specified_device(r, user_agent);
1740 entryp = chxj_apply_convrule(r, dconf->convrules);
1742 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1745 ctx = apr_palloc(r->pool, sizeof(*ctx));
1746 memset(ctx, 0, sizeof(*ctx));
1747 if ((rv = apr_pool_create(&ctx->pool, r->pool)) != APR_SUCCESS) {
1748 ERR(r, "REQ[%X] %s:%d: failed: new pool create. rv:[%d]", TO_ADDR(r),__FILE__,__LINE__,rv);
1749 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1752 ctx->entryp = entryp;
1754 ctx->buffer = apr_palloc(ctx->pool, 1);
1757 if (!entryp || (!(entryp->action & CONVRULE_ENGINE_ON_BIT) && !(entryp->action & CONVRULE_COOKIE_ONLY_BIT))) {
1758 DBG(r,"REQ[%X] EngineOff", TO_ADDR(r));
1759 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1763 switch(spec->html_spec_type) {
1764 case CHXJ_SPEC_Chtml_1_0:
1765 case CHXJ_SPEC_Chtml_2_0:
1766 case CHXJ_SPEC_Chtml_3_0:
1767 case CHXJ_SPEC_Chtml_4_0:
1768 case CHXJ_SPEC_Chtml_5_0:
1769 case CHXJ_SPEC_Chtml_6_0:
1770 case CHXJ_SPEC_Chtml_7_0:
1771 case CHXJ_SPEC_XHtml_Mobile_1_0:
1772 case CHXJ_SPEC_Hdml:
1773 case CHXJ_SPEC_Jhtml:
1774 case CHXJ_SPEC_Jxhtml:
1778 DBG(r, "REQ[%X] end %s() Unknown spec type(%d).", TO_ADDR(r), __func__,spec->html_spec_type);
1783 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
1784 ap_add_output_filter("chxj_output_filter", ctx, r, r->connection);
1785 DBG(r, "REQ[%X] added Output Filter", TO_ADDR(r));
1788 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1793 * The hook is registered.
1798 chxj_register_hooks(apr_pool_t *UNUSED(p))
1800 ap_hook_post_config(chxj_init_module,
1803 APR_HOOK_REALLY_FIRST);
1804 ap_hook_child_init(chxj_child_init,
1807 APR_HOOK_REALLY_FIRST);
1808 ap_register_output_filter (
1809 "chxj_output_filter",
1813 ap_hook_insert_filter(chxj_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
1814 ap_hook_handler(chxj_img_conv_format_handler, NULL, NULL, APR_HOOK_MIDDLE);
1815 ap_hook_handler(chxj_qr_code_handler, NULL, NULL, APR_HOOK_MIDDLE);
1816 ap_hook_handler(chxj_input_handler, NULL, NULL, APR_HOOK_MIDDLE);
1818 ap_hook_handler(chxj_image_redirect_handler, NULL, NULL, APR_HOOK_MIDDLE);
1820 ap_hook_translate_name(chxj_translate_name, NULL, NULL, APR_HOOK_MIDDLE);
1821 ap_hook_fixups(chxj_headers_fixup, NULL, NULL, APR_HOOK_FIRST);
1827 * A set structure according to the directory is generated.
1833 chxj_create_per_dir_config(apr_pool_t *p, char *arg)
1835 mod_chxj_config *conf;
1837 conf = apr_pcalloc(p, sizeof(mod_chxj_config));
1838 conf->device_data_file = NULL;
1839 conf->devices = NULL;
1840 conf->emoji_data_file = NULL;
1842 conf->emoji_tail = NULL;
1843 conf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_NONE;
1844 conf->image = CHXJ_IMG_NONE;
1845 conf->image_cache_dir = apr_psprintf(p, "%s",DEFAULT_IMAGE_CACHE_DIR);
1846 conf->image_cache_limit = 0;
1847 conf->server_side_encoding = NULL;
1848 conf->cookie_db_dir = NULL;
1849 conf->cookie_timeout = 0;
1850 conf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
1851 conf->cookie_lazy_mode = 0;
1852 conf->cookie_dbm_type = NULL;
1854 conf->detect_device_type = CHXJ_ADD_DETECT_DEVICE_TYPE_NONE;
1856 #if defined(USE_MYSQL_COOKIE)
1857 memset((void *)&conf->mysql, 0, sizeof(mysql_t));
1858 conf->mysql.port = MYSQL_PORT;
1859 conf->mysql.host = NULL;
1861 #if defined(USE_MEMCACHE_COOKIE)
1862 memset((void *)&conf->memcache, 0, sizeof(memcache_t));
1863 conf->memcache.host = NULL;
1864 conf->memcache.port = 0;
1866 conf->forward_url_base = NULL;
1867 conf->forward_server_ip = NULL;
1868 conf->allowed_cookie_domain = NULL;
1869 conf->post_log = NULL;
1875 conf->dir = apr_pcalloc(p, strlen(arg)+1);
1876 memset(conf->dir, 0, strlen(arg)+1);
1877 strcpy(conf->dir, arg);
1879 conf->convrules = apr_array_make(p, 2, sizeof(chxjconvrule_entry));
1881 /* Default is copyleft */
1882 conf->image_copyright = NULL;
1884 conf->image_rewrite = CHXJ_IMG_REWRITE_NONE;
1885 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_NONE;
1886 conf->image_rewrite_url = NULL;
1893 * Merge per-directory CHXJ configurations
1896 chxj_merge_per_dir_config(apr_pool_t *p, void *basev, void *addv)
1898 mod_chxj_config *base;
1899 mod_chxj_config *add;
1900 mod_chxj_config *mrg;
1902 base = (mod_chxj_config *)basev;
1903 add = (mod_chxj_config *)addv;
1904 mrg = (mod_chxj_config *)apr_palloc(p, sizeof(mod_chxj_config));
1906 mrg->device_data_file = NULL;
1907 mrg->devices = NULL;
1908 mrg->emoji_data_file = NULL;
1909 mrg->image = CHXJ_IMG_NONE;
1910 mrg->image_cache_dir = NULL;
1911 mrg->image_copyright = NULL;
1912 mrg->image_cache_limit = 0;
1914 mrg->emoji_tail = NULL;
1915 mrg->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_NONE;
1916 mrg->new_line_type = NLTYPE_NIL;
1917 mrg->forward_url_base = NULL;
1918 mrg->forward_server_ip = NULL;
1919 mrg->allowed_cookie_domain = NULL;
1920 mrg->post_log = NULL;
1921 mrg->cookie_dbm_type = NULL;
1923 mrg->device_keys = NULL;
1924 mrg->device_hash = NULL;
1926 mrg->dir = apr_pstrdup(p, add->dir);
1928 if (! add->device_data_file) {
1929 mrg->devices = base->devices;
1930 mrg->device_data_file = apr_pstrdup(p, base->device_data_file);
1933 mrg->devices = add->devices;
1934 mrg->device_data_file = apr_pstrdup(p, add->device_data_file);
1937 if (! add->emoji_data_file) {
1938 mrg->emoji = base->emoji;
1939 mrg->emoji_tail = base->emoji_tail;
1940 mrg->emoji_data_file = apr_pstrdup(p, base->emoji_data_file);
1943 mrg->emoji = add->emoji;
1944 mrg->emoji_tail = add->emoji_tail;
1945 mrg->emoji_data_file = apr_pstrdup(p, add->emoji_data_file);
1948 if (add->image == CHXJ_IMG_NONE) {
1949 mrg->image = base->image;
1952 mrg->image = add->image;
1955 if (strcasecmp(add->image_cache_dir ,DEFAULT_IMAGE_CACHE_DIR)==0) {
1956 mrg->image_cache_dir = apr_pstrdup(p, base->image_cache_dir);
1959 mrg->image_cache_dir = apr_pstrdup(p, add->image_cache_dir);
1962 if (add->image_cache_limit) {
1963 mrg->image_cache_limit = add->image_cache_limit;
1966 mrg->image_cache_limit = base->image_cache_limit;
1969 if (add->image_copyright)
1970 mrg->image_copyright = apr_pstrdup(p, add->image_copyright);
1972 mrg->image_copyright = apr_pstrdup(p, base->image_copyright);
1974 if (add->server_side_encoding) {
1975 mrg->server_side_encoding = apr_pstrdup(p, add->server_side_encoding);
1978 if (base->server_side_encoding) {
1979 mrg->server_side_encoding = apr_pstrdup(p, base->server_side_encoding);
1982 mrg->server_side_encoding = apr_pstrdup(p, DEFAULT_SERVER_SIDE_ENCODING);
1985 mrg->convrules = apr_array_append(p, add->convrules, base->convrules);
1987 if (add->cookie_db_dir) {
1988 mrg->cookie_db_dir = apr_pstrdup(p, add->cookie_db_dir);
1991 if (base->cookie_db_dir) {
1992 mrg->cookie_db_dir = apr_pstrdup(p, base->cookie_db_dir);
1995 mrg->cookie_db_dir = NULL;
1998 if (add->cookie_timeout) {
1999 mrg->cookie_timeout = add->cookie_timeout;
2002 if (base->cookie_db_dir) {
2003 mrg->cookie_timeout = base->cookie_timeout;
2006 mrg->cookie_timeout = 0;
2009 #if defined(USE_MYSQL_COOKIE)
2010 if (add->mysql.host) {
2011 mrg->mysql.host = apr_pstrdup(p, add->mysql.host);
2013 else if (base->mysql.host) {
2014 mrg->mysql.host = apr_pstrdup(p, base->mysql.host);
2017 mrg->mysql.host = NULL;
2019 if (add->mysql.port) {
2020 mrg->mysql.port = add->mysql.port;
2022 else if (base->mysql.port) {
2023 mrg->mysql.port = base->mysql.port;
2026 mrg->mysql.port = 0;
2029 if (add->mysql.database) {
2030 mrg->mysql.database = apr_pstrdup(p, add->mysql.database);
2032 else if (base->mysql.database) {
2033 mrg->mysql.database = apr_pstrdup(p, base->mysql.database);
2036 mrg->mysql.database = NULL;
2039 if (add->mysql.username) {
2040 mrg->mysql.username = apr_pstrdup(p, add->mysql.username);
2042 else if (base->mysql.username) {
2043 mrg->mysql.username = apr_pstrdup(p, base->mysql.username);
2046 mrg->mysql.username = NULL;
2049 if (add->mysql.password) {
2050 mrg->mysql.password = apr_pstrdup(p, add->mysql.password);
2052 else if (base->mysql.password) {
2053 mrg->mysql.password = apr_pstrdup(p, base->mysql.password);
2056 mrg->mysql.password = NULL;
2059 if (add->mysql.tablename) {
2060 mrg->mysql.tablename = apr_pstrdup(p, add->mysql.tablename);
2062 else if (base->mysql.tablename) {
2063 mrg->mysql.tablename = apr_pstrdup(p, base->mysql.tablename);
2066 mrg->mysql.tablename = NULL;
2069 if (add->mysql.socket_path) {
2070 mrg->mysql.socket_path = apr_pstrdup(p, add->mysql.socket_path);
2072 else if (base->mysql.socket_path) {
2073 mrg->mysql.socket_path = apr_pstrdup(p, base->mysql.socket_path);
2076 mrg->mysql.socket_path = NULL;
2079 if (add->mysql.charset) {
2080 mrg->mysql.charset = apr_pstrdup(p, add->mysql.charset);
2082 else if (base->mysql.charset) {
2083 mrg->mysql.charset = apr_pstrdup(p, base->mysql.charset);
2086 mrg->mysql.charset = NULL;
2089 #if defined(USE_MEMCACHE_COOKIE)
2090 if (add->memcache.host) {
2091 mrg->memcache.host = apr_pstrdup(p, add->memcache.host);
2093 else if (base->memcache.host) {
2094 mrg->memcache.host = apr_pstrdup(p, base->memcache.host);
2097 mrg->memcache.host = NULL;
2099 if (add->memcache.port) {
2100 mrg->memcache.port = add->memcache.port;
2102 else if (base->memcache.port) {
2103 mrg->memcache.port = base->memcache.port;
2106 mrg->memcache.port = 0;
2109 if (add->cookie_store_type) {
2110 mrg->cookie_store_type = add->cookie_store_type;
2112 else if (base->cookie_store_type) {
2113 mrg->cookie_store_type = base->cookie_store_type;
2116 mrg->cookie_store_type = COOKIE_STORE_TYPE_NONE;
2118 if (add->cookie_lazy_mode) {
2119 mrg->cookie_lazy_mode = add->cookie_lazy_mode;
2121 else if (base->cookie_lazy_mode) {
2122 mrg->cookie_lazy_mode = base->cookie_lazy_mode;
2125 mrg->cookie_lazy_mode = 0;
2127 if (add->new_line_type) {
2128 mrg->new_line_type = add->new_line_type;
2130 else if (base->new_line_type) {
2131 mrg->new_line_type = base->new_line_type;
2134 mrg->new_line_type = NLTYPE_NIL;
2137 if (add->forward_url_base) {
2138 mrg->forward_url_base = add->forward_url_base;
2140 else if (base->forward_url_base) {
2141 mrg->forward_url_base = base->forward_url_base;
2144 if (add->allowed_cookie_domain) {
2145 mrg->allowed_cookie_domain = add->allowed_cookie_domain;
2148 mrg->allowed_cookie_domain = base->allowed_cookie_domain;
2150 if (add->post_log) {
2151 mrg->post_log = add->post_log;
2154 mrg->post_log = base->post_log;
2156 if (add->cookie_dbm_type) {
2157 mrg->cookie_dbm_type = add->cookie_dbm_type;
2160 mrg->cookie_dbm_type = base->cookie_dbm_type;
2163 if (add->imode_emoji_color == CHXJ_IMODE_EMOJI_COLOR_NONE) {
2164 mrg->imode_emoji_color = base->imode_emoji_color;
2167 mrg->imode_emoji_color = add->imode_emoji_color;
2170 if (add->detect_device_type == CHXJ_ADD_DETECT_DEVICE_TYPE_NONE) {
2171 mrg->detect_device_type = base->detect_device_type;
2174 mrg->detect_device_type = add->detect_device_type;
2177 if (add->device_keys) {
2178 mrg->device_keys = add->device_keys;
2181 mrg->device_keys = base->device_keys;
2184 if (add->device_hash) {
2185 mrg->device_hash = add->device_hash;
2188 mrg->device_hash = base->device_hash;
2191 if (add->image_rewrite == CHXJ_IMG_REWRITE_NONE){
2192 mrg->image_rewrite = base->image_rewrite;
2195 mrg->image_rewrite = add->image_rewrite;
2198 if (add->image_rewrite_url) {
2199 mrg->image_rewrite_url = add->image_rewrite_url;
2202 mrg->image_rewrite_url = base->image_rewrite_url;
2205 if (add->image_rewrite_mode == CHXJ_IMG_REWRITE_MODE_NONE){
2206 mrg->image_rewrite_mode = base->image_rewrite_mode;
2209 mrg->image_rewrite_mode = add->image_rewrite_mode;
2217 chxj_command_parse_take5(
2230 for (;*strp == ' '||*strp == '\t'; strp++) ;
2240 for (; *strp != '\0'; strp++) {
2241 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2242 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2247 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2248 || (isquoted && *strp == '"'))
2262 for (;*strp == ' '||*strp == '\t'; strp++) ;
2271 for (; *strp != '\0'; strp++) {
2272 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2273 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2278 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2279 || (isquoted && *strp == '"'))
2292 for (;*strp == ' '||*strp == '\t'; strp++);
2300 for (; *strp != '\0'; strp++) {
2301 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2302 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2307 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2308 || (isquoted && *strp == '"'))
2320 for (;*strp == ' '||*strp == '\t'; strp++);
2328 for (; *strp != '\0'; strp++) {
2329 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2330 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2335 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2336 || (isquoted && *strp == '"'))
2347 for (;*strp == ' '||*strp == '\t'; strp++);
2355 for (; *strp != '\0'; strp++) {
2356 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2357 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2362 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2363 || (isquoted && *strp == '"'))
2373 * The device definition file is loaded.
2375 * @param arg [i] The name of the device definition file is specified.
2376 * @param mconfig [i/o] The pointer to a set structure is specified.
2380 cmd_load_device_data(cmd_parms *parms, void *mconfig, const char *arg)
2382 mod_chxj_config *conf;
2387 if (strlen(arg) > 256)
2388 return "mod_chxj: device data filename too long.";
2390 conf = (mod_chxj_config *)mconfig;
2391 conf->device_data_file = apr_pstrdup(parms->pool, arg);
2393 qs_init_malloc(&doc);
2394 qs_init_root_node(&doc);
2396 qs_parse_file((Doc *)&doc, (const char *)arg);
2397 chxj_load_device_data(&doc,parms->pool, conf);
2398 qs_all_free(&doc, QX_LOGMARK);
2405 * Device definition information is loaded.
2408 * @param arg [i] The name of the device definition file is specified.
2409 * @param mconfig [i/o] The pointer to a set structure is specified.
2413 cmd_load_emoji_data(cmd_parms *parms, void *mconfig, const char *arg)
2415 mod_chxj_config *conf;
2422 if (strlen(arg) > 256)
2423 return "mod_chxj: emoji data filename too long.";
2425 conf = (mod_chxj_config *)mconfig;
2426 conf->emoji_data_file = apr_pstrdup(parms->pool, arg);
2427 qs_init_malloc(&doc);
2428 qs_init_root_node(&doc);
2430 qs_parse_file((Doc *)&doc, (const char *)arg);
2432 rtn = chxj_load_emoji_data(&doc,parms->pool, conf);
2434 qs_all_free(&doc, QX_LOGMARK);
2442 cmd_set_image_engine(cmd_parms * UNUSED(parms), void *mconfig, const char *arg)
2444 mod_chxj_config *conf;
2449 if (strlen(arg) > 256)
2450 return "image uri is too long.";
2452 conf = (mod_chxj_config*)mconfig;
2453 if (strcasecmp("ON", arg) == 0) {
2454 conf->image = CHXJ_IMG_ON;
2457 conf->image = CHXJ_IMG_OFF;
2465 cmd_set_image_cache_dir(cmd_parms *parms, void *mconfig, const char *arg)
2467 mod_chxj_config *conf;
2472 if (strlen(arg) > 256)
2473 return "cache dir name is too long.";
2476 apr_status_t res = apr_stat(&info,arg,APR_FINFO_TYPE,parms->pool);
2477 if(res != APR_SUCCESS){
2478 return apr_psprintf(parms->pool,"ChxjImageCacheDir [%s]: not found ",arg);
2481 if(info.filetype != APR_DIR){
2482 return apr_psprintf(parms->pool,"ChxjImageCacheDir [%s]: is not directory ",arg);
2486 conf = (mod_chxj_config *)mconfig;
2487 conf->image_cache_dir = apr_pstrdup(parms->pool, arg);
2494 cmd_set_image_cache_limit(cmd_parms *parms, void *mconfig, const char *arg)
2496 mod_chxj_config *conf;
2501 if (strlen(arg) > IMAGE_CACHE_LIMIT_FMT_LEN)
2502 return "cache size is too long.";
2504 conf = (mod_chxj_config *)mconfig;
2507 * I use strtol function because strtoul is not portable function.
2509 conf->image_cache_limit = (unsigned long)strtol(arg, NULL, 10);
2512 return apr_psprintf(parms->pool, "ChxjImageCacheLimit invalid value [%s] errno:[%d]", arg, errno);
2514 return apr_psprintf(parms->pool, "ChxjImageCacheLimit Out of range [%s] errno:[%d]", arg, errno);
2523 cmd_set_image_copyright(cmd_parms *parms, void *mconfig, const char *arg)
2525 mod_chxj_config *conf;
2530 if (strlen(arg) > 256)
2531 return "Copyright Flag is too long.";
2533 conf = (mod_chxj_config *)mconfig;
2534 conf->image_copyright = apr_pstrdup(parms->pool, arg);
2541 cmd_convert_rule(cmd_parms *cmd, void *mconfig, const char *arg)
2545 mod_chxj_config *dconf;
2546 chxjconvrule_entry *newrule;
2556 dconf = (mod_chxj_config *)mconfig;
2558 if (strlen(arg) > 4096)
2559 return "mod_chxj: ChxjConvertRule: is too long.";
2561 dconf = (mod_chxj_config *)mconfig;
2562 if (dconf->convrules == NULL)
2563 dconf->convrules = apr_array_make(cmd->pool,
2565 sizeof(chxjconvrule_entry));
2567 newrule = apr_array_push(dconf->convrules);
2570 newrule->action = 0;
2572 if (chxj_command_parse_take5(arg, &prm1, &prm2, &prm3, &prm4, &prm5))
2573 return "ChxjConvertRule: bad argument line";
2575 newrule->pattern = apr_pstrdup(cmd->pool, prm1);
2579 if ((action = apr_strtok(prm2, ",", &pstate)) == NULL)
2585 if (strcasecmp(CONVRULE_ENGINE_ON_CMD, action) == 0) {
2586 newrule->action |= CONVRULE_ENGINE_ON_BIT;
2589 if (strcasecmp(CONVRULE_ENGINE_OFF_CMD, action) == 0) {
2590 newrule->action |= CONVRULE_ENGINE_OFF_BIT;
2593 if (strcasecmp(CONVRULE_EMOJI_ONLY_CMD, action) == 0) {
2594 newrule->action |= CONVRULE_EMOJI_ONLY_BIT;
2597 if (strcasecmp(CONVRULE_ENVINFO_ONLY_CMD, action) == 0) {
2598 newrule->action |= CONVRULE_ENVINFO_ONLY_BIT;
2604 if (strcasecmp(CONVRULE_OVERWRITE_X_CLIENT_TYPE_CMD, action) == 0) {
2605 newrule->action |= CONVRULE_OVERWRITE_X_CLIENT_TYPE_BIT;
2611 if (strcasecmp(CONVRULE_COOKIE_ON_CMD, action) == 0) {
2612 newrule->action |= CONVRULE_COOKIE_ON_BIT;
2614 else if (strcasecmp(CONVRULE_COOKIE_OFF_CMD, action) == 0) {
2615 newrule->action &= (0xffffffff ^ CONVRULE_COOKIE_ON_BIT);
2617 else if (strcasecmp(CONVRULE_CSS_ON_CMD, action) == 0) {
2618 newrule->action |= CONVRULE_CSS_ON_BIT;
2620 else if (strcasecmp(CONVRULE_CSS_OFF_CMD, action) == 0) {
2621 newrule->action &= (0xffffffff ^ CONVRULE_CSS_ON_BIT);
2623 else if (strcasecmp(CONVRULE_COOKIE_ONLY_CMD, action) == 0) {
2624 newrule->action |= CONVRULE_COOKIE_ONLY_BIT;
2630 if (strcasecmp(CONVRULE_JRCONV_OFF_CMD, action) == 0) {
2631 newrule->action |= CONVRULE_JRCONV_OFF_BIT;
2637 if (strcasecmp(CONVRULE_NOCACHE_ON_CMD, action) == 0) {
2638 newrule->action |= CONVRULE_NOCACHE_ON_BIT;
2644 if (strcasecmp(CONVRULE_QSCONV_OFF_CMD, action) == 0) {
2645 newrule->action |= CONVRULE_QSCONV_OFF_BIT;
2651 if (strcasecmp(CONVRULE_Z2H_ON_CMD, action) == 0) {
2652 newrule->action |= CONVRULE_Z2H_ON_BIT;
2655 if (strcasecmp(CONVRULE_Z2H_OFF_CMD, action) == 0) {
2656 newrule->action |= CONVRULE_Z2H_OFF_BIT;
2659 if (strcasecmp(CONVRULE_Z2H_ALPHA_ON_CMD, action) == 0) {
2660 newrule->action |= CONVRULE_Z2H_ALPHA_ON_BIT;
2663 if (strcasecmp(CONVRULE_Z2H_ALPHA_OFF_CMD, action) == 0) {
2664 newrule->action |= CONVRULE_Z2H_ALPHA_OFF_BIT;
2667 if (strcasecmp(CONVRULE_Z2H_NUM_ON_CMD, action) == 0) {
2668 newrule->action |= CONVRULE_Z2H_NUM_ON_BIT;
2671 if (strcasecmp(CONVRULE_Z2H_NUM_OFF_CMD, action) == 0) {
2672 newrule->action |= CONVRULE_Z2H_NUM_OFF_BIT;
2675 if (strcasecmp(CONVRULE_Z2H_ALL_ON_CMD, action) == 0) {
2676 newrule->action |= CONVRULE_Z2H_ON_BIT | CONVRULE_Z2H_ALPHA_ON_BIT | CONVRULE_Z2H_NUM_ON_BIT;
2679 if (strcasecmp(CONVRULE_Z2H_NUM_OFF_CMD, action) == 0) {
2680 newrule->action |= CONVRULE_Z2H_OFF_BIT | CONVRULE_Z2H_ALPHA_OFF_BIT | CONVRULE_Z2H_NUM_OFF_BIT;
2691 newrule->flags |= CONVRULE_FLAG_NOTMATCH;
2695 mode = AP_REG_EXTENDED;
2696 if ((regexp = ap_pregcomp((apr_pool_t *)cmd->pool, (const char *)pp, mode)) == NULL)
2697 return "RewriteRule: cannot compile regular expression ";
2699 newrule->regexp = regexp;
2701 newrule->encoding = apr_pstrdup(cmd->pool, prm3);
2703 newrule->encoding = apr_pstrdup(cmd->pool, "none");
2705 newrule->pc_flag = CONVRULE_PC_FLAG_OFF_BIT;
2707 if (strcasecmp(CONVRULE_PC_FLAG_ON_CMD, prm4) == 0)
2708 newrule->pc_flag = CONVRULE_PC_FLAG_ON_BIT;
2710 newrule->user_agent = NULL;
2712 newrule->user_agent = apr_pstrdup(cmd->pool, prm5);
2724 mod_chxj_config *dconf;
2727 if (strlen(arg) > 4096)
2728 return "mod_chxj: ChxjCookieDir is too long.";
2730 dconf = (mod_chxj_config *)mconfig;
2732 dconf->cookie_db_dir = apr_pstrdup(cmd->pool, arg);
2739 cmd_set_cookie_timeout(
2740 cmd_parms *UNUSED(cmd),
2744 mod_chxj_config *dconf;
2746 if (strlen(arg) > 4096)
2747 return "mod_chxj: ChxjCookieTimeout is too long.";
2749 if (chxj_chk_numeric(arg) != 0)
2750 return "mod_chxj: ChxjCookieTimeout is not numeric.";
2752 dconf = (mod_chxj_config *)mconfig;
2754 dconf->cookie_timeout = atoi(arg);
2760 #if defined(USE_MYSQL_COOKIE)
2762 cmd_set_cookie_mysql_database(
2767 mod_chxj_config *dconf;
2769 if (strlen(arg) > 255)
2770 return "mod_chxj: ChxjCookieMysqlDatabase is too long.";
2772 dconf = (mod_chxj_config *)mconfig;
2774 dconf->mysql.database = apr_pstrdup(cmd->pool, arg);
2781 cmd_set_cookie_mysql_username(
2786 mod_chxj_config *dconf;
2788 if (strlen(arg) > 255)
2789 return "mod_chxj: ChxjCookieMysqlUsername is too long.";
2791 dconf = (mod_chxj_config *)mconfig;
2793 dconf->mysql.username = apr_pstrdup(cmd->pool, arg);
2800 cmd_set_cookie_mysql_password(
2805 mod_chxj_config *dconf;
2807 if (strlen(arg) > 255)
2808 return "mod_chxj: ChxjCookieMysqlPassword is too long.";
2810 dconf = (mod_chxj_config *)mconfig;
2812 dconf->mysql.password = apr_pstrdup(cmd->pool, arg);
2819 cmd_set_cookie_mysql_table_name(
2824 mod_chxj_config *dconf;
2826 if (strlen(arg) > 255)
2827 return "mod_chxj: ChxjCookieMysqlTableName is too long.";
2829 dconf = (mod_chxj_config *)mconfig;
2831 dconf->mysql.tablename = apr_pstrdup(cmd->pool, arg);
2837 cmd_set_cookie_mysql_port(
2838 cmd_parms *UNUSED(cmd),
2842 mod_chxj_config *dconf;
2844 if (strlen(arg) > 255)
2845 return "mod_chxj: ChxjCookieMysqlPort is too long.";
2847 dconf = (mod_chxj_config *)mconfig;
2849 if (chxj_chk_numeric(arg) != 0)
2850 return "mod_chxj: ChxjCookieMysqlPort is not numeric.";
2852 dconf = (mod_chxj_config *)mconfig;
2854 dconf->mysql.port = chxj_atoi(arg);
2861 cmd_set_cookie_mysql_host(
2866 mod_chxj_config *dconf;
2868 if (strlen(arg) > 255)
2869 return "mod_chxj: ChxjCookieMysqlHost is too long.";
2871 dconf = (mod_chxj_config *)mconfig;
2873 dconf->mysql.host = apr_pstrdup(cmd->pool, arg);
2880 cmd_set_cookie_mysql_socket_path(
2885 mod_chxj_config *dconf;
2887 if (strlen(arg) > 4096)
2888 return "mod_chxj: ChxjCookieMysqlSocketPath is too long.";
2890 dconf = (mod_chxj_config *)mconfig;
2892 dconf->mysql.socket_path = apr_pstrdup(cmd->pool, arg);
2899 cmd_set_cookie_mysql_charset(
2904 mod_chxj_config *dconf;
2906 if (strlen(arg) > 255)
2907 return "mod_chxj: ChxjCookieMysqlCharset is too long.";
2909 dconf = (mod_chxj_config *)mconfig;
2911 dconf->mysql.charset = apr_pstrdup(cmd->pool, arg);
2916 #if defined(USE_MEMCACHE_COOKIE)
2918 cmd_set_cookie_memcache_port(
2919 cmd_parms *UNUSED(cmd),
2923 mod_chxj_config *dconf;
2925 if (strlen(arg) > 255)
2926 return "mod_chxj: ChxjCookieMemcachePort is too long.";
2928 dconf = (mod_chxj_config *)mconfig;
2930 if (chxj_chk_numeric(arg) != 0)
2931 return "mod_chxj: ChxjCookieMemcachePort is not numeric.";
2933 dconf = (mod_chxj_config *)mconfig;
2935 dconf->memcache.port = (apr_port_t)chxj_atoi(arg);
2942 cmd_set_cookie_memcache_host(
2947 mod_chxj_config *dconf;
2949 if (strlen(arg) > 255)
2950 return "mod_chxj: ChxjCookieMemcacheHost is too long.";
2952 dconf = (mod_chxj_config *)mconfig;
2954 dconf->memcache.host = apr_pstrdup(cmd->pool, arg);
2961 cmd_set_cookie_lazy_mode(
2962 cmd_parms *UNUSED(cmd),
2966 mod_chxj_config *dconf;
2968 if (strlen(arg) > 255)
2969 return "mod_chxj: ChxjCookieLazyMode is too long.";
2971 dconf = (mod_chxj_config *)mconfig;
2973 if (strcasecmp("TRUE",arg) == 0) {
2974 dconf->cookie_lazy_mode = COOKIE_LAZY_ON;
2977 dconf->cookie_lazy_mode = COOKIE_LAZY_OFF;
2984 cmd_set_cookie_store_type(
2985 cmd_parms *UNUSED(cmd),
2989 mod_chxj_config *dconf;
2991 if (strlen(arg) > 255)
2992 return "mod_chxj: ChxjCookieStoreType is too long.";
2994 dconf = (mod_chxj_config *)mconfig;
2996 if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_DBM, arg) == 0) {
2997 dconf->cookie_store_type = COOKIE_STORE_TYPE_DBM;
2999 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MYSQL, arg) == 0) {
3000 dconf->cookie_store_type = COOKIE_STORE_TYPE_MYSQL;
3002 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MEMCACHE, arg) == 0) {
3003 dconf->cookie_store_type = COOKIE_STORE_TYPE_MEMCACHE;
3006 dconf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
3013 cmd_set_forward_url_base(
3018 mod_chxj_config *dconf;
3020 if (strlen(arg) > 255)
3021 return "mod_chxj: ChxjForwardUrlBase is too long.";
3023 dconf = (mod_chxj_config *)mconfig;
3025 dconf->forward_url_base = apr_pstrdup(cmd->pool, arg);
3031 cmd_set_forward_server_ip(
3036 mod_chxj_config *dconf;
3038 if (strlen(arg) > 255)
3039 return "mod_chxj: ChxjForwardServerIp is too long.";
3041 dconf = (mod_chxj_config *)mconfig;
3043 dconf->forward_server_ip = apr_pstrdup(cmd->pool, arg);
3049 cmd_allowed_cookie_domain(
3054 mod_chxj_config *dconf;
3056 if (strlen(arg) > 255)
3057 return "mod_chxj: ChxjAllowedCookieDomain is too long.";
3059 dconf = (mod_chxj_config *)mconfig;
3061 dconf->allowed_cookie_domain = apr_pstrdup(cmd->pool, arg);
3067 cmd_set_new_line_type(
3068 cmd_parms *UNUSED(cmd),
3072 mod_chxj_config *dconf;
3073 if (strlen(arg) > 255)
3074 return "mod_chxj: ChxjNewLineType is too long.";
3076 dconf = (mod_chxj_config *)mconfig;
3078 if (strcasecmp(CHXJ_NEW_LINE_TYPE_CRLF, arg) == 0) {
3079 dconf->new_line_type = NLTYPE_CRLF;
3081 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_LF, arg) == 0) {
3082 dconf->new_line_type = NLTYPE_LF;
3084 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_CR, arg) == 0) {
3085 dconf->new_line_type = NLTYPE_CR;
3087 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_NONE, arg) == 0) {
3088 dconf->new_line_type = NLTYPE_NONE;
3091 return "mod_chxj: invalid value (ChxjNewLineType)";
3102 mod_chxj_config *dconf;
3103 if (strlen(arg) > 255)
3104 return "mod_chxj: ChxjPostLogEnv is too long.";
3106 dconf = (mod_chxj_config *)mconfig;
3108 dconf->post_log = apr_pstrdup(cmd->pool, arg);
3114 cmd_cookie_dbm_type(
3119 mod_chxj_config *dconf;
3120 if (strlen(arg) > 255)
3121 return "mod_chxj: ChxjCookieDbmType is too long.";
3123 dconf = (mod_chxj_config *)mconfig;
3125 dconf->cookie_dbm_type = apr_pstrdup(cmd->pool, arg);
3131 cmd_imode_emoji_color(
3136 mod_chxj_config *dconf;
3138 if (strlen(arg) > 256)
3139 return "imode emoji color is too long.";
3141 dconf = (mod_chxj_config *)mconfig;
3142 if (strcasecmp("ON", arg) == 0) {
3143 dconf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_ON;
3145 else if(strcasecmp("AUTO",arg) == 0) {
3146 dconf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_AUTO;
3149 dconf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_OFF;
3156 cmd_add_device_data_tsv(cmd_parms *parms, void *mconfig, const char *arg)
3158 mod_chxj_config *conf;
3160 if (strlen(arg) > 256)
3161 return "mod_chxj: device tsv filename too long.";
3163 conf = (mod_chxj_config *)mconfig;
3165 conf->detect_device_type = CHXJ_ADD_DETECT_DEVICE_TYPE_TSV;
3168 apr_status_t res = apr_stat(&info,arg,APR_FINFO_TYPE,parms->pool);
3169 if(res != APR_SUCCESS){
3170 return apr_psprintf(parms->pool,"ChxjDeviceTSV [%s]: not found ",arg);
3173 if(info.filetype != APR_REG ){
3174 return apr_psprintf(parms->pool,"ChxjDeviceTSV [%s]: is not file ",arg);
3178 apr_file_open(&fp, arg, APR_READ|APR_BUFFERED, APR_OS_DEFAULT, parms->pool);
3180 chxj_load_device_tsv_data(fp,parms->pool,conf);
3187 cmd_image_rewrite(cmd_parms *parms, void *mconfig, const char *arg)
3189 mod_chxj_config *conf;
3190 if (strlen(arg) > 256){
3191 return "mod_chxj: set rewrite too long.";
3193 conf = (mod_chxj_config *)mconfig;
3194 if (strcasecmp("ON", arg) == 0) {
3195 conf->image_rewrite = CHXJ_IMG_REWRITE_ON;
3197 else if(strcasecmp("OFF",arg) == 0) {
3198 conf->image_rewrite = CHXJ_IMG_REWRITE_OFF;
3201 conf->image_rewrite = CHXJ_IMG_REWRITE_NONE;
3207 cmd_image_rewrite_url(cmd_parms *parms, void *mconfig, const char *arg)
3209 mod_chxj_config *conf;
3210 if (strlen(arg) > 256){
3211 return "mod_chxj: set rewrite url too long.";
3213 conf = (mod_chxj_config *)mconfig;
3214 conf->image_rewrite_url = apr_pstrdup(parms->pool, arg);;
3219 cmd_image_rewrite_mode(cmd_parms *parms, void *mconfig, const char *arg)
3221 mod_chxj_config *conf;
3222 if (strlen(arg) > 256){
3223 return "mod_chxj: set rewrite mode is too long.";
3226 conf = (mod_chxj_config *)mconfig;
3227 if (strcasecmp("all",arg) == 0) {
3228 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_ALL;
3230 else if (strcasecmp("user",arg) == 0) {
3231 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_USER;
3233 else if (strcasecmp("tag",arg) == 0) {
3234 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_TAG;
3237 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_NONE;
3242 static const command_rec cmds[] = {
3244 "ChxjLoadDeviceData",
3245 cmd_load_device_data,
3248 "Load Device Data"),
3250 "ChxjLoadEmojiData",
3251 cmd_load_emoji_data,
3257 cmd_set_image_engine,
3260 "Convert Target URI"),
3262 "ChxjImageCacheDir",
3263 cmd_set_image_cache_dir,
3266 "Image Cache Directory"),
3268 "ChxjImageCacheLimit",
3269 cmd_set_image_cache_limit,
3272 "Image Cache Limit"),
3274 "ChxjImageCopyright",
3275 cmd_set_image_copyright,
3284 "an URL-applied regexp-pattern and a substitution URL"),
3290 "save cookie.db directory."),
3292 "ChxjCookieTimeout",
3293 cmd_set_cookie_timeout,
3296 "The compulsion time-out time of the cookie is specified. "),
3298 "ChxjCookieStoreType",
3299 cmd_set_cookie_store_type,
3302 "It specifies preserving of the cookie ahead. (DBM/MYSQL/MEMCACHE)"),
3304 "ChxjCookieLazyMode",
3305 cmd_set_cookie_lazy_mode,
3308 "OneTimeID is negligently done. (TRUE/FALSE)"),
3309 #if defined(USE_MYSQL_COOKIE)
3311 "ChxjCookieMysqlHost",
3312 cmd_set_cookie_mysql_host,
3315 "The MySQL database host used by saving Cookie"),
3317 "ChxjCookieMysqlPort",
3318 cmd_set_cookie_mysql_port,
3321 "The MySQL database port used by saving Cookie"),
3323 "ChxjCookieMysqlDatabase",
3324 cmd_set_cookie_mysql_database,
3327 "The MySQL database name used by saving Cookie"),
3329 "ChxjCookieMysqlUsername",
3330 cmd_set_cookie_mysql_username,
3333 "The MySQL username used by saving Cookie"),
3335 "ChxjCookieMysqlPassword",
3336 cmd_set_cookie_mysql_password,
3339 "The MySQL password used by saving Cookie"),
3341 "ChxjCookieMysqlTableName",
3342 cmd_set_cookie_mysql_table_name,
3345 "The MySQL table name used by saving Cookie"),
3347 "ChxjCookieMysqlSocketPath",
3348 cmd_set_cookie_mysql_socket_path,
3351 "The MySQL socket path used by saving Cookie"),
3353 "ChxjCookieMysqlCharset",
3354 cmd_set_cookie_mysql_charset,
3357 "The MySQL charset used by saving Cookie"),
3359 #if defined(USE_MEMCACHE_COOKIE)
3361 "ChxjCookieMemcacheHost",
3362 cmd_set_cookie_memcache_host,
3365 "The Memcached host used by saving Cookie"),
3367 "ChxjCookieMemcachePort",
3368 cmd_set_cookie_memcache_port,
3371 "The Memcached port used by saving Cookie"),
3375 cmd_set_new_line_type,
3378 "HTML new line type (NONE|CRLF|LF|CR). default is CRLF"),
3380 "ChxjForwardUrlBase",
3381 cmd_set_forward_url_base,
3384 "The forward url base(default: {request protocol}://{this server}:{this server port}"),
3386 "ChxjForwardServerIp",
3387 cmd_set_forward_server_ip,
3390 "The forward server ip(default: this server ip)"),
3392 "ChxjAllowedCookieDomain",
3393 cmd_allowed_cookie_domain,
3396 "Domain that permits parameter addition for cookie besides hostname.(Default:hostname Only)"),
3402 "for CustomLog directive. mod_chxj's internal POST log environment name.(Default:chxj-post-log)"),
3404 "ChxjCookieDbmType",
3405 cmd_cookie_dbm_type,
3408 "Kind of DBM used with Cookie simulator.(default|GDBM|SDBM|DB|NDBM)"),
3410 "ChxjImodeEmojiColor",
3411 cmd_imode_emoji_color,
3414 "Auto i-mode emoji color"),
3416 "ChxjAddDeviceDataTSV",
3417 cmd_add_device_data_tsv,
3420 "Additional devices TSV data"),
3429 "ChxjImageRewriteUrl",
3430 cmd_image_rewrite_url,
3433 "Set rewrite Image url"
3436 "ChxjImageRewriteMode",
3437 cmd_image_rewrite_mode,
3440 "Set rewrite Image rewrite url mode"
3442 {NULL,{NULL},NULL,0,0,NULL},
3446 /*----------------------------------------------------------------------------*/
3447 /* Dispatch list for API hooks */
3448 /*----------------------------------------------------------------------------*/
3449 module AP_MODULE_DECLARE_DATA chxj_module = {
3450 STANDARD20_MODULE_STUFF,
3451 chxj_create_per_dir_config, /* create per-dir config structures */
3452 chxj_merge_per_dir_config, /* merge per-dir config structures */
3453 chxj_config_server_create, /* create per-server config structures */
3454 NULL, /* merge per-server config structures */
3455 cmds, /* table of config file commands */
3456 chxj_register_hooks /* register hooks */