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 chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
186 DBG(r, "REQ[%X] detect internal redirect.", (unsigned int)(apr_size_t)r);
187 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
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", (unsigned int)(apr_size_t)r);
200 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
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 chxj_headers_fixup() (no pattern)", (unsigned int)(apr_size_t)r);
222 if (!(entryp->action & CONVRULE_ENGINE_ON_BIT) && !(entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
223 DBG(r, "REQ[%X] end chxj_headers_fixup() (engine off)", (unsigned int)(apr_size_t)r);
226 if (entryp->action & CONVRULE_EMOJI_ONLY_BIT) {
227 DBG(r, "REQ[%X] end chxj_headers_fixup() (emoji only)", (unsigned int)(apr_size_t)r);
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 chxj_headers_fixup() (not mobile) spec->device_name[%s] User-Agent:[%s]", (unsigned int)(apr_size_t)r, 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]", (unsigned int)(apr_size_t)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]", (unsigned int)(apr_size_t)r, APLOG_MARK, rv, apr_strerror(rv, buf, 256));
292 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
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]", (unsigned int)(apr_size_t)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]", (unsigned int)(apr_size_t)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(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 chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
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,"start chxj_image_redirect_handler");
372 ap_internal_redirect(apr_pstrcat(r->pool, r->filename+13,
373 r->args ? "?" : NULL, r->args, NULL), r);
374 DBG(r,"end chxj_image_redirect_handler");
380 s_clear_cookie_header(request_rec *r, device_table *spec)
382 DBG(r, "REQ[%X] start s_clear_cookie_header()", TO_ADDR(r));
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_clear_cookie_header()", TO_ADDR(r));
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 of chxj_convert()", (unsigned int)(apr_size_t)r);
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 of chxj_convert()", (unsigned int)(apr_size_t)r);
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]", (unsigned int)(apr_size_t)r, user_agent);
446 DBG(r,"REQ[%X] content type is %s", (unsigned int)(apr_size_t)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", (unsigned int)(apr_size_t)r, r->content_type);
452 DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
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 of chxj_convert()(emoji only)", (unsigned int)(apr_size_t)r);
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 of chxj_convert()", (unsigned int)(apr_size_t)r);
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_convert_guid_parameter() param:[%s]", (unsigned int)(apr_size_t)r, 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_convert_guid_parameter()", (unsigned int)(apr_size_t)r);
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 chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
632 DBG(r, "REQ[%X] r->args=[null]", (unsigned int)(apr_size_t)r);
633 DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
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", (unsigned int)(apr_size_t)r);
662 buff = apr_pstrdup(r->pool, r->args);
663 DBG(r, "REQ[%X] r->args=[%s]", (unsigned int)(apr_size_t)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, "************ before encoding[%s]", value);
698 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
699 dvalue = chxj_url_encode(r->pool, dvalue);
701 DBG(r, "************ after encoding[%s]", 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]", (unsigned int)(apr_size_t)r, value);
749 DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
750 cookie_lock_t *lock = chxj_cookie_lock(r);
751 cookie = chxj_load_cookie(r, value);
752 DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
753 if (! no_update_flag && cookie) {
754 cookie = chxj_update_cookie(r, cookie);
756 chxj_cookie_unlock(r, lock);
758 if (cookie && cookie->cookie_id) {
759 if (strlen(result) != 0)
760 result = apr_pstrcat(r->pool, result, "&", NULL);
761 result = apr_pstrcat(r->pool, result, name, "=", cookie->cookie_id, NULL);
765 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
766 if (strlen(result) != 0)
767 result = apr_pstrcat(r->pool, result, "&", NULL);
768 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
771 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
772 if (! no_update_flag) {
773 result = apr_pstrcat(r->pool, result, "&_chxj_nc=true", NULL);
777 DBG(r, "REQ[%X] result r->args=[%s]", (unsigned int)(apr_size_t)r, r->args);
778 DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
784 * It converts it from POSTDATA .
787 * @param src [i] It is POSTDATA character string.
788 * @param len [i/o] It is length of former HTML character string.
795 chxjconvrule_entry *entryp,
805 cookie_t *cookie = NULL;
807 int no_update_flag = 0;
811 DBG(r, "REQ[%X] start of chxj_input_convert()", (unsigned int)(apr_size_t)r);
814 DBG(r, "REQ[%X] end of chxj_input_convert() (input is null)", (unsigned int)(apr_size_t)r);
815 return apr_pstrdup(r->pool, "");
818 apr_pool_create(&pool, r->pool);
820 s = apr_pstrdup(pool, *src);
822 buff_pre = apr_pstrdup(pool, *src);
824 result = qs_alloc_zero_byte_string(pool);
826 chxj_dump_string(r, APLOG_MARK, "BEFORE input convert source", s, ilen);
831 pair = apr_strtok(buff_pre, "&", &pstate);
837 pair_sv = apr_pstrdup(pool, pair);
839 name = apr_strtok(pair, "=", &vstate);
840 value = apr_strtok(NULL, "=", &vstate);
841 if (! name) continue;
842 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
843 DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
853 pair = apr_strtok(s, "&", &pstate);
858 name = apr_strtok(pair, "=", &vstate);
859 value = apr_strtok(NULL, "=", &vstate);
860 if (! name) continue;
861 name = chxj_safe_to_jreserved_tag(r, name);
863 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
864 if (strlen(result) != 0)
865 result = apr_pstrcat(pool, result, "&", NULL);
867 if (strcasecmp(entryp->encoding, "NONE") != 0) {
872 if (value && *value != 0) {
873 value = chxj_url_decode(pool, value);
874 dlen = strlen(value);
875 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
876 dvalue = chxj_url_encode(pool, dvalue);
882 if (name && *name != 0) {
883 name = chxj_url_decode(pool, name);
885 dname = chxj_rencoding(r, name, &dlen,spec->output_encoding);
886 dname = chxj_url_encode(pool, dname);
893 result = apr_pstrcat(pool, result, dname, "=", dvalue, NULL);
896 result = apr_pstrcat(pool, result, name, "=", value, NULL);
900 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
901 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
902 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
906 if (strlen(value) == 0)
909 if (strlen(result) != 0)
910 result = apr_pstrcat(pool, result, "&", NULL);
912 if (strcasecmp(entryp->encoding, "NONE") != 0 && value && strlen(value)) {
916 dlen = strlen(value);
917 value = chxj_url_decode(pool, value);
918 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
919 dvalue = chxj_url_encode(pool,dvalue);
920 result = apr_pstrcat(pool, result, &name[8], "=", dvalue, NULL);
924 result = apr_pstrcat(pool, result, &name[8], "=", value, NULL);
928 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
930 apr_table_unset(r->headers_in, "Cookie");
931 DBG(r, "REQ[%X] found cookie parameter[%s]", (unsigned int)(apr_size_t)r, value);
932 DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
933 cookie_lock_t *lock = chxj_cookie_lock(r);
934 cookie = chxj_load_cookie(r, value);
935 DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
936 if (! no_update_flag && cookie) {
937 cookie = chxj_update_cookie(r, cookie);
939 chxj_cookie_unlock(r, lock);
941 if (cookie && cookie->cookie_id) {
942 if (strlen(result) != 0)
943 result = apr_pstrcat(pool, result, "&", NULL);
944 result = apr_pstrcat(pool, result, name, "=", cookie->cookie_id, NULL);
948 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
949 if (strlen(result) != 0)
950 result = apr_pstrcat(pool, result, "&", NULL);
951 result = apr_pstrcat(pool, result, name, "=", value, NULL);
954 if ( strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1) == 0) {
958 dlen = strlen(value);
961 value = chxj_url_decode(pool, value);
962 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
963 dvalue = chxj_url_encode(pool,dvalue);
964 if (r->args && strlen(r->args) > 0) {
965 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
968 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
970 s_convert_guid_parameter_to_header(r, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], spec);
974 if (strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX_ENC, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1) == 0) {
977 dlen = strlen(value);
979 value = chxj_url_decode(pool, value);
980 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
981 dvalue = chxj_url_encode(pool,dvalue);
982 if (r->args && strlen(r->args) > 0) {
983 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
986 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
988 s_convert_guid_parameter_to_header(r, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], spec);
991 DBG(r, "REQ[%X] ************************ name:[%s]", (unsigned int)(apr_size_t)r, name);
993 *len = strlen(result);
994 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
995 if (! no_update_flag) {
996 result = apr_pstrcat(pool, result, "&_chxj_nc=true", NULL);
999 DBG(r, "REQ[%X] AFTER input convert result = [%s]", (unsigned int)(apr_size_t)r, result);
1000 DBG(r, "REQ[%X] end chxj_input_convert()", (unsigned int)(apr_size_t)r);
1007 * The received data is returned to the filter.
1009 * @param f [i/o] It is a filter.
1010 * @param data [i] It is data returned to the filter.
1011 * @param len [i] It is length of the data returned to the filter.
1014 pass_data_to_filter(ap_filter_t *f, const char *data,
1017 request_rec *r = f->r;
1018 conn_rec *c = r->connection;
1020 apr_bucket_brigade *bb;
1023 DBG(r, "REQ[%X] start pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1025 chxj_header_inf_clear(r);
1027 bb = apr_brigade_create(r->pool, c->bucket_alloc);
1028 b = apr_bucket_transient_create(data, len, c->bucket_alloc);
1030 APR_BRIGADE_INSERT_TAIL(bb, b);
1031 b = apr_bucket_eos_create(f->c->bucket_alloc);
1032 APR_BRIGADE_INSERT_TAIL(bb, b);
1034 rv = ap_pass_brigade(f->next, bb);
1035 if (rv != APR_SUCCESS) {
1036 DBG(r, "REQ[%X] end pass_data_to_filter() (apr_pass_brigade)", (unsigned int)(apr_size_t)r);
1040 DBG(r, "REQ[%X] end pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1046 * Add No Cache Header
1049 s_add_no_cache_headers(request_rec *r, chxjconvrule_entry *entryp)
1051 if (entryp->action & CONVRULE_NOCACHE_ON_BIT) {
1052 apr_table_unset(r->headers_out, "Pragma");
1053 apr_table_unset(r->err_headers_out, "Pragma");
1054 apr_table_unset(r->headers_out, "Expires");
1055 apr_table_unset(r->err_headers_out, "Expires");
1056 apr_table_unset(r->headers_out, "Cache-Control");
1057 apr_table_unset(r->err_headers_out, "Cache-Control");
1059 apr_table_setn(r->err_headers_out, "Pragma", "no-cache");
1060 apr_table_setn(r->err_headers_out, "Expires", "Thu, 01 Jan 1970 00:00:00 GMT");
1061 apr_table_setn(r->err_headers_out, "Cache-Control", "no-cache, no-store");
1067 * It is the main loop of the output filter.
1069 * @param f [i/o] It is a filter.
1073 chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
1079 char *user_agent = NULL;
1081 mod_chxj_ctx *ctx = (mod_chxj_ctx *)f->ctx;
1082 cookie_t *cookie = NULL;
1083 mod_chxj_config *dconf;
1084 chxjconvrule_entry *entryp = NULL;
1085 device_table *spec = NULL;
1089 DBG(f->r, "REQ[%X] start of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1092 apr_pool_create(&pool, r->pool);
1094 entryp = ctx->entryp;
1096 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1099 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1100 DBG(r, "REQ[%X] found Location header", TO_ADDR(r));
1101 if ((entryp->action & CONVRULE_COOKIE_ON_BIT) || (entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
1102 cookie_lock_t *lock = NULL;
1103 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", TO_ADDR(r));
1104 switch(spec->html_spec_type) {
1105 case CHXJ_SPEC_Chtml_1_0:
1106 case CHXJ_SPEC_Chtml_2_0:
1107 case CHXJ_SPEC_Chtml_3_0:
1108 case CHXJ_SPEC_Chtml_4_0:
1109 case CHXJ_SPEC_Chtml_5_0:
1110 case CHXJ_SPEC_Chtml_6_0:
1111 case CHXJ_SPEC_Chtml_7_0:
1112 case CHXJ_SPEC_XHtml_Mobile_1_0:
1113 case CHXJ_SPEC_Jhtml:
1114 case CHXJ_SPEC_Jxhtml:
1115 lock = chxj_cookie_lock(r);
1116 cookie = chxj_save_cookie(r);
1117 s_add_cookie_id_if_has_location_header(r, cookie);
1118 chxj_cookie_unlock(r, lock);
1124 if (! ap_is_HTTP_REDIRECT(r->status)) {
1125 r->status = HTTP_MOVED_TEMPORARILY;
1127 s_add_no_cache_headers(r, entryp);
1128 /* must not send body. */
1129 rv = pass_data_to_filter(f, "", 0);
1130 DBG(f->r, "REQ[%X] end of chxj_output_filter()", TO_ADDR(r));
1135 if (r->content_type) {
1136 if (! STRNCASEEQ('t','T',"text/html",r->content_type, sizeof("text/html")-1)
1137 && ! STRNCASEEQ('t','T',"text/xml", r->content_type, sizeof("text/xml")-1)
1138 && ! STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
1139 && ! (dconf->image == CHXJ_IMG_ON
1140 && ! apr_table_get(r->headers_in, "CHXJ_IMG_CONV")
1141 && STRNCASEEQ('i','I',"image/", r->content_type, sizeof("image/") -1)
1142 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
1143 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
1144 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
1145 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
1146 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
1147 || STRCASEEQ('x','X',"x-ms-bmp", &r->content_type[6]) /* BMP */
1148 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
1149 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
1150 || STRCASEEQ('g','G',"gif", &r->content_type[6])))) { /* GIF */
1152 DBG(r, "REQ[%X] not convert content-type:[%s] dconf->image:[%d]", (unsigned int)(apr_size_t)r, r->content_type, dconf->image);
1153 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
1154 cookie_lock_t *lock = NULL;
1155 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
1156 switch(spec->html_spec_type) {
1157 case CHXJ_SPEC_Chtml_1_0:
1158 case CHXJ_SPEC_Chtml_2_0:
1159 case CHXJ_SPEC_Chtml_3_0:
1160 case CHXJ_SPEC_Chtml_4_0:
1161 case CHXJ_SPEC_Chtml_5_0:
1162 case CHXJ_SPEC_Chtml_6_0:
1163 case CHXJ_SPEC_Chtml_7_0:
1164 case CHXJ_SPEC_XHtml_Mobile_1_0:
1165 case CHXJ_SPEC_Jhtml:
1166 case CHXJ_SPEC_Jxhtml:
1167 lock = chxj_cookie_lock(r);
1168 cookie = chxj_save_cookie(r);
1169 s_add_cookie_id_if_has_location_header(r, cookie);
1170 chxj_cookie_unlock(r, lock);
1176 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1177 if (! ap_is_HTTP_REDIRECT(r->status)) {
1178 r->status = HTTP_MOVED_TEMPORARILY;
1181 s_add_no_cache_headers(r, entryp);
1182 ap_pass_brigade(f->next, bb);
1183 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1188 DBG(r, "REQ[%X] not convert content-type:[(null)]", (unsigned int)(apr_size_t)r);
1189 ap_pass_brigade(f->next, bb);
1190 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1195 for (b = APR_BRIGADE_FIRST(bb);
1196 b != APR_BRIGADE_SENTINEL(bb);
1197 b = APR_BUCKET_NEXT(b)) {
1199 if (apr_bucket_read(b, &data, &len, APR_BLOCK_READ) == APR_SUCCESS) {
1200 chxj_dump_string(r, APLOG_MARK, "READ Data", data, len);
1202 /*--------------------------------------------------------------------*/
1204 /*--------------------------------------------------------------------*/
1206 DBG(r, "append data start");
1207 ctx = (mod_chxj_ctx *)f->ctx;
1210 tmp = apr_palloc(r->pool, ctx->len);
1211 memcpy(tmp, ctx->buffer, ctx->len);
1213 ctx->buffer = apr_palloc(pool, ctx->len + len);
1215 memcpy(ctx->buffer, tmp, ctx->len);
1216 memcpy(&ctx->buffer[ctx->len], data, len);
1220 DBG(r, "REQ[%X] append data end", (unsigned int)(apr_size_t)r);
1223 if (APR_BUCKET_IS_EOS(b)) {
1225 DBG(r, "REQ[%X] eos", (unsigned int)(apr_size_t)r);
1226 /*----------------------------------------------------------------------*/
1228 /*----------------------------------------------------------------------*/
1230 cookie_lock_t *lock = NULL;
1231 ctx = (mod_chxj_ctx *)f->ctx;
1233 DBG(r, "REQ[%X] content_type=[%s]", (unsigned int)(apr_size_t)r, r->content_type);
1234 lock = chxj_cookie_lock(r);
1236 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
1238 && (STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
1239 || STRNCASEEQ('t','T',"text/html", r->content_type, sizeof("text/html")-1))) {
1240 DBG(r, "REQ[%X] detect convert target:[%s]", (unsigned int)(apr_size_t)r, r->content_type);
1245 tmp = apr_palloc(pool, ctx->len + 1);
1247 memset(tmp, 0, ctx->len + 1);
1248 memcpy(tmp, ctx->buffer, ctx->len);
1250 ctx->buffer = chxj_convert(r,
1251 (const char **)&tmp,
1252 (apr_size_t *)&ctx->len,
1254 user_agent, &cookie);
1258 ctx->buffer = apr_psprintf(r->pool, "\n");
1260 ctx->buffer = chxj_convert(r,
1261 (const char **)&ctx->buffer,
1262 (apr_size_t *)&ctx->len,
1264 user_agent, &cookie);
1269 && *(char *)r->content_type == 't'
1270 && strncmp(r->content_type, "text/xml", 8) == 0) {
1271 DBG(r, "REQ[%X] text/XML", (unsigned int)(apr_size_t)r);
1279 memset(&doc, 0, sizeof(Doc));
1280 memset(&qrcode, 0, sizeof(qr_code_t));
1282 doc.parse_mode = PARSE_MODE_CHTML;
1286 qs_init_malloc(&doc);
1288 root = qs_parse_string(&doc, ctx->buffer, ctx->len);
1291 for (child = qs_get_child_node(&doc,root);
1293 child = qs_get_next_node(&doc,child)) {
1294 char *name = qs_get_node_name(&doc,child);
1295 if (strcasecmp("qrcode",name) == 0) {
1300 qs_all_free(&doc,QX_LOGMARK);
1302 r->handler = apr_psprintf(r->pool, "chxj-qrcode");
1303 chxj_qrcode_node_to_qrcode(&qrcode, root);
1304 sts = chxj_qrcode_create_image_data(&qrcode, &ctx->buffer, &ctx->len);
1306 ERR(r, "REQ[%X] qrcode create failed.", (unsigned int)(apr_size_t)r);
1307 chxj_cookie_unlock(r, lock);
1308 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1311 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1315 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
1317 && ( *r->content_type == 'i' || *r->content_type == 'I')
1318 && dconf->image == CHXJ_IMG_ON
1319 && strncasecmp("image/", r->content_type, 6) == 0
1320 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
1321 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
1322 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
1323 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
1324 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
1325 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
1326 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
1327 || STRCASEEQ('x','X',"x-ms-bmp", &r->content_type[6]) /* BMP */
1328 || STRCASEEQ('g','G',"gif", &r->content_type[6]))) { /* GIF */
1329 DBG(r, "REQ[%X] detect convert target:[%s]", (unsigned int)(apr_size_t)r, r->content_type);
1333 DBG(r, "REQ[%X] ctx->len[%d]", (unsigned int)(apr_size_t)r, (unsigned int)ctx->len);
1334 tmp = apr_palloc(pool, ctx->len + 1);
1336 memset(tmp, 0, ctx->len + 1);
1337 memcpy(tmp, ctx->buffer, ctx->len);
1339 chxj_convert_image(r,
1340 (const char **)&tmp,
1341 (apr_size_t *)&ctx->len);
1345 apr_table_unset(r->headers_out, "Content-Length");
1346 apr_table_unset(r->err_headers_out, "Content-Length");
1347 ap_set_content_length(r, (apr_off_t)ctx->len);
1351 DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1352 s_add_cookie_id_if_has_location_header(r, cookie);
1353 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1354 if (! ap_is_HTTP_REDIRECT(r->status)) {
1355 r->status = HTTP_MOVED_TEMPORARILY;
1358 if (ctx->len && ap_is_HTTP_REDIRECT(r->status)) {
1359 ctx->buffer = apr_pstrdup(pool, "");
1361 ap_set_content_length(r, (apr_off_t)ctx->len);
1363 chxj_cookie_unlock(r,lock);
1364 s_add_no_cache_headers(r, entryp);
1365 rv = pass_data_to_filter(f,
1366 (const char *)ctx->buffer,
1367 (apr_size_t)ctx->len);
1370 ctx->buffer = apr_pstrdup(pool, "");
1372 ap_set_content_length(r, (apr_off_t)ctx->len);
1373 chxj_cookie_unlock(r, lock);
1374 s_add_no_cache_headers(r, entryp);
1375 rv = pass_data_to_filter(f,
1376 (const char *)ctx->buffer,
1377 (apr_size_t)ctx->len);
1379 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1383 DBG(r, "REQ[%X] SAVE COOKIE[%x]", (unsigned int)(apr_size_t)r, entryp->action);
1388 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
1389 cookie_lock_t *lock = NULL;
1390 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
1391 switch(spec->html_spec_type) {
1392 case CHXJ_SPEC_Chtml_1_0:
1393 case CHXJ_SPEC_Chtml_2_0:
1394 case CHXJ_SPEC_Chtml_3_0:
1395 case CHXJ_SPEC_Chtml_4_0:
1396 case CHXJ_SPEC_Chtml_5_0:
1397 case CHXJ_SPEC_Chtml_6_0:
1398 case CHXJ_SPEC_Chtml_7_0:
1399 case CHXJ_SPEC_XHtml_Mobile_1_0:
1400 case CHXJ_SPEC_Jhtml:
1401 case CHXJ_SPEC_Jxhtml:
1402 lock = chxj_cookie_lock(r);
1403 cookie = chxj_save_cookie(r);
1405 * Location Header Check to add cookie parameter.
1407 s_add_cookie_id_if_has_location_header(r, cookie);
1408 chxj_cookie_unlock(r, lock);
1409 apr_table_unset(r->headers_out, "Set-Cookie");
1410 apr_table_unset(r->err_headers_out, "Set-Cookie");
1417 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1418 if (! ap_is_HTTP_REDIRECT(r->status)) {
1419 r->status = HTTP_MOVED_TEMPORARILY;
1422 apr_table_setn(r->headers_out, "Content-Length", "0");
1423 DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1424 s_add_no_cache_headers(r, entryp);
1425 rv = pass_data_to_filter(f, (const char *)"", (apr_size_t)0);
1426 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1431 apr_brigade_destroy(bb);
1433 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1439 * Add Cookie_id if it has location header.
1442 s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie)
1444 char *location_header = (char *)apr_table_get(r->headers_out, "Location");
1445 if (! location_header) {
1446 location_header = (char *)apr_table_get(r->err_headers_out, "Location");
1448 if (cookie && location_header) {
1449 DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1450 location_header = chxj_add_cookie_parameter(r,
1453 apr_table_unset(r->headers_out, "Location");
1454 apr_table_setn(r->headers_out, "Location", location_header);
1455 DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1456 if (!ap_is_HTTP_REDIRECT(r->status)) {
1457 r->status = HTTP_MOVED_TEMPORARILY;
1463 * It is the main loop of the input filter handler.
1467 chxj_input_handler(request_rec *r)
1469 mod_chxj_config *dconf;
1470 chxjconvrule_entry *entryp = NULL;
1471 device_table *spec = NULL;
1472 char *post_data = NULL;
1473 apr_size_t post_data_len = 0;
1477 int response_code = 0;
1479 DBG(r, "start of chxj_input_handler()");
1481 if (strcasecmp(r->handler, "chxj-input-handler")) {
1482 DBG(r, "end chxj_input_handler()");
1485 apr_pool_create(&pool, r->pool);
1487 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1488 user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
1490 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
1492 spec = chxj_specified_device(r, user_agent);
1493 entryp = chxj_apply_convrule(r, dconf->convrules);
1495 post_data = apr_pstrdup(pool, "");
1496 if (ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK) == OK) {
1497 if (ap_should_client_block(r)) {
1498 while (post_data_len < CHXJ_POST_MAX) {
1501 int read_bytes = ap_get_client_block(r, buffer, BUFSZ-1);
1502 if (read_bytes<=0) {
1505 buffer[read_bytes] = '\0';
1506 post_data = apr_pstrcat(pool, post_data, buffer, NULL);
1507 post_data_len += read_bytes;
1516 if (post_data_len > 0) {
1517 post_data = chxj_input_convert(r, (const char**)&post_data, (apr_size_t*)&post_data_len, entryp, spec);
1518 DBG(r, "(in:exchange)POSTDATA:[%s]", post_data);
1522 if (dconf->forward_url_base) {
1523 url_path = apr_psprintf(pool, "%s%s", dconf->forward_url_base, r->uri);
1526 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);
1529 url_path = apr_pstrcat(pool, url_path, "?", r->args, NULL);
1531 DBG(r, "==> new url_path:[%s]", url_path);
1534 apr_table_setn(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP, r->connection->remote_ip);
1535 char *x_client_type = (char *)apr_table_get(r->headers_in, "X-Client-Type");
1536 if (x_client_type) {
1537 apr_table_setn(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_TYPE, x_client_type); /* for mod_cidr_lookup */
1540 apr_table_unset(r->headers_in, "X-Client-Type");
1542 apr_table_unset(r->headers_in, "Content-Length");
1543 apr_table_setn(r->headers_in, "Content-Length", apr_psprintf(pool, "%" APR_SIZE_T_FMT, post_data_len));
1544 response = chxj_serf_post(r, pool, url_path, post_data, post_data_len, 1, &res_len, &response_code);
1546 DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1547 DBG(r, "REQ[%X] response length:[%" APR_SIZE_T_FMT "]", (unsigned int)(apr_size_t)r, res_len);
1548 for (ii=0; ii<res_len/64; ii++) {
1549 DBG(r, "REQ[%X] response:[%.*s]", (unsigned int)(apr_size_t)r, 64, &response[ii*64]);
1551 DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1555 if ((chunked = (char *)apr_table_get(r->headers_out, "Transfer-Encoding")) != NULL) {
1556 if (strcasecmp(chunked, "chunked") == 0) {
1558 apr_table_unset(r->headers_out, "Transfer-Encoding");
1561 if (ap_is_HTTP_ERROR(response_code)) {
1562 DBG(r, "REQ[%X] end of chxj_input_handler() (HTTP-ERROR received. response code:[%d])", (unsigned int)(apr_size_t)r, response_code);
1563 return response_code;
1567 apr_pool_create(&wpool, r->pool);
1568 apr_bucket_brigade *bb;
1571 conn_rec *c = r->connection;
1573 bb = apr_brigade_create(wpool, c->bucket_alloc);
1574 e = apr_bucket_transient_create(response, res_len, c->bucket_alloc);
1575 APR_BRIGADE_INSERT_TAIL(bb, e);
1576 e = apr_bucket_eos_create(c->bucket_alloc);
1577 APR_BRIGADE_INSERT_TAIL(bb, e);
1578 if ((rv = ap_pass_brigade(r->output_filters, bb)) != APR_SUCCESS) {
1579 ERR(r, "REQ[%X] %s:%d failed ap_pass_brigade()", (unsigned int)(apr_size_t)r, APLOG_MARK);
1582 apr_brigade_cleanup(bb);
1585 DBG(r, "REQ[%X] end of chxj_input_handler()", (unsigned int)(apr_size_t)r);
1589 static mod_chxj_global_config *
1590 chxj_global_config_create(apr_pool_t *pool, server_rec *s)
1592 mod_chxj_global_config *conf;
1594 SDBG(s, "start chxj_global_config_create()");
1596 /*--------------------------------------------------------------------------*/
1597 /* allocate an own subpool which survives server restarts */
1598 /*--------------------------------------------------------------------------*/
1599 conf = (mod_chxj_global_config *)apr_palloc(pool,
1600 sizeof(mod_chxj_global_config));
1602 conf->cookie_db_lock = NULL;
1604 SDBG(s, "end chxj_global_config_create()");
1611 * initialize chxj module
1614 chxj_init_module(apr_pool_t *p,
1615 apr_pool_t *UNUSED(plog),
1616 apr_pool_t *UNUSED(ptemp),
1622 SDBG(s, "start chxj_init_module()");
1624 apr_pool_userdata_get(&user_data, CHXJ_MOD_CONFIG_KEY, s->process->pool);
1626 if (user_data == NULL) {
1629 * dummy user_data set.
1631 apr_pool_userdata_set(
1633 CHXJ_MOD_CONFIG_KEY,
1634 apr_pool_cleanup_null,
1636 SDBG(s, "end chxj_init_module()");
1640 ap_add_version_component(p, CHXJ_VERSION_PREFIX CHXJ_VERSION);
1642 if ((rv = apr_proc_mutex_create(&global_cookie_mutex, NULL, APR_LOCK_FCNTL, s->process->pool)) != APR_SUCCESS) {
1644 SERR(s, "%s:%d end chxj_init_module(). mutex create failure.(%d:%s)",APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1645 return HTTP_INTERNAL_SERVER_ERROR;
1648 SDBG(s, "end chxj_init_module()");
1655 chxj_child_init(apr_pool_t *UNUSED(p), server_rec *s)
1658 SDBG(s, "start chxj_child_init()");
1659 if ((rv = apr_proc_mutex_child_init(&global_cookie_mutex, NULL, s->process->pool)) != APR_SUCCESS) {
1661 SERR(s, "%s:%d ERROR end chxj_init_module(). mutex create failure.(%d:%s)", APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1663 SDBG(s, "end chxj_child_init()");
1668 * A set structure of each server is generated.
1674 chxj_config_server_create(apr_pool_t *p, server_rec *s)
1676 mod_chxj_global_config *gc;
1678 gc = chxj_global_config_create(p,s);
1685 chxj_translate_name(request_rec *r)
1687 DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1688 DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1689 DBG(r, "REQ[%X] START REQUEST (uri:[%s] args:[%s])", (unsigned int)(apr_size_t)r, r->unparsed_uri, r->args ? r->args : "");
1690 DBG(r, "REQ[%X] METHOD [%s]", TO_ADDR(r), r->method);
1691 DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1692 DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1694 mod_chxj_config *dconf;
1695 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1697 if (dconf->image_rewrite ==CHXJ_IMG_REWRITE_ON ){
1698 if(r->args && strcasecmp(r->args,"rewrite") == 0){
1699 DBG(r, "image rewrite is ON [%s] - %s", dconf->image_rewrite_url ,r->content_type);
1700 r->filename = apr_pstrcat(r->pool,dconf->image_rewrite_url,NULL);
1707 return chxj_trans_name(r);
1715 chxj_insert_filter(request_rec *r)
1719 mod_chxj_config *dconf;
1720 chxjconvrule_entry *entryp;
1725 DBG(r, "REQ[%X] start chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1727 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1729 /* we get User-Agent from CHXJ_HTTP_USER_AGENT header if any */
1730 user_agent = (char *)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
1732 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
1735 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
1737 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
1738 DBG(r, "REQ[%X] detect multipart/form-data ==> no target", (unsigned int)(apr_size_t)r);
1739 DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1743 spec = chxj_specified_device(r, user_agent);
1744 entryp = chxj_apply_convrule(r, dconf->convrules);
1746 DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1749 ctx = apr_palloc(r->pool, sizeof(*ctx));
1750 memset(ctx, 0, sizeof(*ctx));
1751 if ((rv = apr_pool_create(&ctx->pool, r->pool)) != APR_SUCCESS) {
1752 ERR(r, "%s:%d: failed: new pool create. rv:[%d]", __FILE__,__LINE__,rv);
1753 DBG(r, "REQ:[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1756 ctx->entryp = entryp;
1758 ctx->buffer = apr_palloc(ctx->pool, 1);
1761 if (!entryp || (!(entryp->action & CONVRULE_ENGINE_ON_BIT) && !(entryp->action & CONVRULE_COOKIE_ONLY_BIT))) {
1762 DBG(r,"REQ[%X] EngineOff", (unsigned int)(apr_size_t)r);
1763 DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1767 switch(spec->html_spec_type) {
1768 case CHXJ_SPEC_Chtml_1_0:
1769 case CHXJ_SPEC_Chtml_2_0:
1770 case CHXJ_SPEC_Chtml_3_0:
1771 case CHXJ_SPEC_Chtml_4_0:
1772 case CHXJ_SPEC_Chtml_5_0:
1773 case CHXJ_SPEC_Chtml_6_0:
1774 case CHXJ_SPEC_Chtml_7_0:
1775 case CHXJ_SPEC_XHtml_Mobile_1_0:
1776 case CHXJ_SPEC_Hdml:
1777 case CHXJ_SPEC_Jhtml:
1778 case CHXJ_SPEC_Jxhtml:
1782 DBG(r, "REQ[%X] end chxj_insert_filter() Unknown spec type(%d).", (unsigned int)(apr_size_t)r, spec->html_spec_type);
1787 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
1788 ap_add_output_filter("chxj_output_filter", ctx, r, r->connection);
1789 DBG(r, "REQ[%X] added Output Filter", (unsigned int)(apr_size_t)r);
1792 DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1797 * The hook is registered.
1802 chxj_register_hooks(apr_pool_t *UNUSED(p))
1804 ap_hook_post_config(chxj_init_module,
1807 APR_HOOK_REALLY_FIRST);
1808 ap_hook_child_init(chxj_child_init,
1811 APR_HOOK_REALLY_FIRST);
1812 ap_register_output_filter (
1813 "chxj_output_filter",
1817 ap_hook_insert_filter(chxj_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
1818 ap_hook_handler(chxj_img_conv_format_handler, NULL, NULL, APR_HOOK_MIDDLE);
1819 ap_hook_handler(chxj_qr_code_handler, NULL, NULL, APR_HOOK_MIDDLE);
1820 ap_hook_handler(chxj_input_handler, NULL, NULL, APR_HOOK_MIDDLE);
1822 ap_hook_handler(chxj_image_redirect_handler, NULL, NULL, APR_HOOK_MIDDLE);
1824 ap_hook_translate_name(chxj_translate_name, NULL, NULL, APR_HOOK_MIDDLE);
1825 ap_hook_fixups(chxj_headers_fixup, NULL, NULL, APR_HOOK_FIRST);
1831 * A set structure according to the directory is generated.
1837 chxj_create_per_dir_config(apr_pool_t *p, char *arg)
1839 mod_chxj_config *conf;
1841 conf = apr_pcalloc(p, sizeof(mod_chxj_config));
1842 conf->device_data_file = NULL;
1843 conf->devices = NULL;
1844 conf->emoji_data_file = NULL;
1846 conf->emoji_tail = NULL;
1847 conf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_NONE;
1848 conf->image = CHXJ_IMG_NONE;
1849 conf->image_cache_dir = apr_psprintf(p, "%s",DEFAULT_IMAGE_CACHE_DIR);
1850 conf->image_cache_limit = 0;
1851 conf->server_side_encoding = NULL;
1852 conf->cookie_db_dir = NULL;
1853 conf->cookie_timeout = 0;
1854 conf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
1855 conf->cookie_lazy_mode = 0;
1856 conf->cookie_dbm_type = NULL;
1858 conf->detect_device_type = CHXJ_ADD_DETECT_DEVICE_TYPE_NONE;
1860 #if defined(USE_MYSQL_COOKIE)
1861 memset((void *)&conf->mysql, 0, sizeof(mysql_t));
1862 conf->mysql.port = MYSQL_PORT;
1863 conf->mysql.host = NULL;
1865 #if defined(USE_MEMCACHE_COOKIE)
1866 memset((void *)&conf->memcache, 0, sizeof(memcache_t));
1867 conf->memcache.host = NULL;
1868 conf->memcache.port = 0;
1870 conf->forward_url_base = NULL;
1871 conf->forward_server_ip = NULL;
1872 conf->allowed_cookie_domain = NULL;
1873 conf->post_log = NULL;
1879 conf->dir = apr_pcalloc(p, strlen(arg)+1);
1880 memset(conf->dir, 0, strlen(arg)+1);
1881 strcpy(conf->dir, arg);
1883 conf->convrules = apr_array_make(p, 2, sizeof(chxjconvrule_entry));
1885 /* Default is copyleft */
1886 conf->image_copyright = NULL;
1888 conf->image_rewrite = CHXJ_IMG_REWRITE_NONE;
1889 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_NONE;
1890 conf->image_rewrite_url = NULL;
1897 * Merge per-directory CHXJ configurations
1900 chxj_merge_per_dir_config(apr_pool_t *p, void *basev, void *addv)
1902 mod_chxj_config *base;
1903 mod_chxj_config *add;
1904 mod_chxj_config *mrg;
1906 base = (mod_chxj_config *)basev;
1907 add = (mod_chxj_config *)addv;
1908 mrg = (mod_chxj_config *)apr_palloc(p, sizeof(mod_chxj_config));
1910 mrg->device_data_file = NULL;
1911 mrg->devices = NULL;
1912 mrg->emoji_data_file = NULL;
1913 mrg->image = CHXJ_IMG_NONE;
1914 mrg->image_cache_dir = NULL;
1915 mrg->image_copyright = NULL;
1916 mrg->image_cache_limit = 0;
1918 mrg->emoji_tail = NULL;
1919 mrg->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_NONE;
1920 mrg->new_line_type = NLTYPE_NIL;
1921 mrg->forward_url_base = NULL;
1922 mrg->forward_server_ip = NULL;
1923 mrg->allowed_cookie_domain = NULL;
1924 mrg->post_log = NULL;
1925 mrg->cookie_dbm_type = NULL;
1927 mrg->device_keys = NULL;
1928 mrg->device_hash = NULL;
1930 mrg->dir = apr_pstrdup(p, add->dir);
1932 if (! add->device_data_file) {
1933 mrg->devices = base->devices;
1934 mrg->device_data_file = apr_pstrdup(p, base->device_data_file);
1937 mrg->devices = add->devices;
1938 mrg->device_data_file = apr_pstrdup(p, add->device_data_file);
1941 if (! add->emoji_data_file) {
1942 mrg->emoji = base->emoji;
1943 mrg->emoji_tail = base->emoji_tail;
1944 mrg->emoji_data_file = apr_pstrdup(p, base->emoji_data_file);
1947 mrg->emoji = add->emoji;
1948 mrg->emoji_tail = add->emoji_tail;
1949 mrg->emoji_data_file = apr_pstrdup(p, add->emoji_data_file);
1952 if (add->image == CHXJ_IMG_NONE) {
1953 mrg->image = base->image;
1956 mrg->image = add->image;
1959 if (strcasecmp(add->image_cache_dir ,DEFAULT_IMAGE_CACHE_DIR)==0) {
1960 mrg->image_cache_dir = apr_pstrdup(p, base->image_cache_dir);
1963 mrg->image_cache_dir = apr_pstrdup(p, add->image_cache_dir);
1966 if (add->image_cache_limit) {
1967 mrg->image_cache_limit = add->image_cache_limit;
1970 mrg->image_cache_limit = base->image_cache_limit;
1973 if (add->image_copyright)
1974 mrg->image_copyright = apr_pstrdup(p, add->image_copyright);
1976 mrg->image_copyright = apr_pstrdup(p, base->image_copyright);
1978 if (add->server_side_encoding) {
1979 mrg->server_side_encoding = apr_pstrdup(p, add->server_side_encoding);
1982 if (base->server_side_encoding) {
1983 mrg->server_side_encoding = apr_pstrdup(p, base->server_side_encoding);
1986 mrg->server_side_encoding = apr_pstrdup(p, DEFAULT_SERVER_SIDE_ENCODING);
1989 mrg->convrules = apr_array_append(p, add->convrules, base->convrules);
1991 if (add->cookie_db_dir) {
1992 mrg->cookie_db_dir = apr_pstrdup(p, add->cookie_db_dir);
1995 if (base->cookie_db_dir) {
1996 mrg->cookie_db_dir = apr_pstrdup(p, base->cookie_db_dir);
1999 mrg->cookie_db_dir = NULL;
2002 if (add->cookie_timeout) {
2003 mrg->cookie_timeout = add->cookie_timeout;
2006 if (base->cookie_db_dir) {
2007 mrg->cookie_timeout = base->cookie_timeout;
2010 mrg->cookie_timeout = 0;
2013 #if defined(USE_MYSQL_COOKIE)
2014 if (add->mysql.host) {
2015 mrg->mysql.host = apr_pstrdup(p, add->mysql.host);
2017 else if (base->mysql.host) {
2018 mrg->mysql.host = apr_pstrdup(p, base->mysql.host);
2021 mrg->mysql.host = NULL;
2023 if (add->mysql.port) {
2024 mrg->mysql.port = add->mysql.port;
2026 else if (base->mysql.port) {
2027 mrg->mysql.port = base->mysql.port;
2030 mrg->mysql.port = 0;
2033 if (add->mysql.database) {
2034 mrg->mysql.database = apr_pstrdup(p, add->mysql.database);
2036 else if (base->mysql.database) {
2037 mrg->mysql.database = apr_pstrdup(p, base->mysql.database);
2040 mrg->mysql.database = NULL;
2043 if (add->mysql.username) {
2044 mrg->mysql.username = apr_pstrdup(p, add->mysql.username);
2046 else if (base->mysql.username) {
2047 mrg->mysql.username = apr_pstrdup(p, base->mysql.username);
2050 mrg->mysql.username = NULL;
2053 if (add->mysql.password) {
2054 mrg->mysql.password = apr_pstrdup(p, add->mysql.password);
2056 else if (base->mysql.password) {
2057 mrg->mysql.password = apr_pstrdup(p, base->mysql.password);
2060 mrg->mysql.password = NULL;
2063 if (add->mysql.tablename) {
2064 mrg->mysql.tablename = apr_pstrdup(p, add->mysql.tablename);
2066 else if (base->mysql.tablename) {
2067 mrg->mysql.tablename = apr_pstrdup(p, base->mysql.tablename);
2070 mrg->mysql.tablename = NULL;
2073 if (add->mysql.socket_path) {
2074 mrg->mysql.socket_path = apr_pstrdup(p, add->mysql.socket_path);
2076 else if (base->mysql.socket_path) {
2077 mrg->mysql.socket_path = apr_pstrdup(p, base->mysql.socket_path);
2080 mrg->mysql.socket_path = NULL;
2083 if (add->mysql.charset) {
2084 mrg->mysql.charset = apr_pstrdup(p, add->mysql.charset);
2086 else if (base->mysql.charset) {
2087 mrg->mysql.charset = apr_pstrdup(p, base->mysql.charset);
2090 mrg->mysql.charset = NULL;
2093 #if defined(USE_MEMCACHE_COOKIE)
2094 if (add->memcache.host) {
2095 mrg->memcache.host = apr_pstrdup(p, add->memcache.host);
2097 else if (base->memcache.host) {
2098 mrg->memcache.host = apr_pstrdup(p, base->memcache.host);
2101 mrg->memcache.host = NULL;
2103 if (add->memcache.port) {
2104 mrg->memcache.port = add->memcache.port;
2106 else if (base->memcache.port) {
2107 mrg->memcache.port = base->memcache.port;
2110 mrg->memcache.port = 0;
2113 if (add->cookie_store_type) {
2114 mrg->cookie_store_type = add->cookie_store_type;
2116 else if (base->cookie_store_type) {
2117 mrg->cookie_store_type = base->cookie_store_type;
2120 mrg->cookie_store_type = COOKIE_STORE_TYPE_NONE;
2122 if (add->cookie_lazy_mode) {
2123 mrg->cookie_lazy_mode = add->cookie_lazy_mode;
2125 else if (base->cookie_lazy_mode) {
2126 mrg->cookie_lazy_mode = base->cookie_lazy_mode;
2129 mrg->cookie_lazy_mode = 0;
2131 if (add->new_line_type) {
2132 mrg->new_line_type = add->new_line_type;
2134 else if (base->new_line_type) {
2135 mrg->new_line_type = base->new_line_type;
2138 mrg->new_line_type = NLTYPE_NIL;
2141 if (add->forward_url_base) {
2142 mrg->forward_url_base = add->forward_url_base;
2144 else if (base->forward_url_base) {
2145 mrg->forward_url_base = base->forward_url_base;
2148 if (add->allowed_cookie_domain) {
2149 mrg->allowed_cookie_domain = add->allowed_cookie_domain;
2152 mrg->allowed_cookie_domain = base->allowed_cookie_domain;
2154 if (add->post_log) {
2155 mrg->post_log = add->post_log;
2158 mrg->post_log = base->post_log;
2160 if (add->cookie_dbm_type) {
2161 mrg->cookie_dbm_type = add->cookie_dbm_type;
2164 mrg->cookie_dbm_type = base->cookie_dbm_type;
2167 if (add->imode_emoji_color == CHXJ_IMODE_EMOJI_COLOR_NONE) {
2168 mrg->imode_emoji_color = base->imode_emoji_color;
2171 mrg->imode_emoji_color = add->imode_emoji_color;
2174 if (add->detect_device_type == CHXJ_ADD_DETECT_DEVICE_TYPE_NONE) {
2175 mrg->detect_device_type = base->detect_device_type;
2178 mrg->detect_device_type = add->detect_device_type;
2181 if (add->device_keys) {
2182 mrg->device_keys = add->device_keys;
2185 mrg->device_keys = base->device_keys;
2188 if (add->device_hash) {
2189 mrg->device_hash = add->device_hash;
2192 mrg->device_hash = base->device_hash;
2195 if (add->image_rewrite == CHXJ_IMG_REWRITE_NONE){
2196 mrg->image_rewrite = base->image_rewrite;
2199 mrg->image_rewrite = add->image_rewrite;
2202 if (add->image_rewrite_url) {
2203 mrg->image_rewrite_url = add->image_rewrite_url;
2206 mrg->image_rewrite_url = base->image_rewrite_url;
2209 if (add->image_rewrite_mode == CHXJ_IMG_REWRITE_MODE_NONE){
2210 mrg->image_rewrite_mode = base->image_rewrite_mode;
2213 mrg->image_rewrite_mode = add->image_rewrite_mode;
2221 chxj_command_parse_take5(
2234 for (;*strp == ' '||*strp == '\t'; strp++) ;
2244 for (; *strp != '\0'; strp++) {
2245 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2246 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2251 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2252 || (isquoted && *strp == '"'))
2266 for (;*strp == ' '||*strp == '\t'; strp++) ;
2275 for (; *strp != '\0'; strp++) {
2276 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2277 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2282 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2283 || (isquoted && *strp == '"'))
2296 for (;*strp == ' '||*strp == '\t'; strp++);
2304 for (; *strp != '\0'; strp++) {
2305 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2306 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2311 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2312 || (isquoted && *strp == '"'))
2324 for (;*strp == ' '||*strp == '\t'; strp++);
2332 for (; *strp != '\0'; strp++) {
2333 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2334 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2339 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2340 || (isquoted && *strp == '"'))
2351 for (;*strp == ' '||*strp == '\t'; strp++);
2359 for (; *strp != '\0'; strp++) {
2360 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2361 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2366 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2367 || (isquoted && *strp == '"'))
2377 * The device definition file is loaded.
2379 * @param arg [i] The name of the device definition file is specified.
2380 * @param mconfig [i/o] The pointer to a set structure is specified.
2384 cmd_load_device_data(cmd_parms *parms, void *mconfig, const char *arg)
2386 mod_chxj_config *conf;
2391 if (strlen(arg) > 256)
2392 return "mod_chxj: device data filename too long.";
2394 conf = (mod_chxj_config *)mconfig;
2395 conf->device_data_file = apr_pstrdup(parms->pool, arg);
2397 qs_init_malloc(&doc);
2398 qs_init_root_node(&doc);
2400 qs_parse_file((Doc *)&doc, (const char *)arg);
2401 chxj_load_device_data(&doc,parms->pool, conf);
2402 qs_all_free(&doc, QX_LOGMARK);
2409 * Device definition information is loaded.
2412 * @param arg [i] The name of the device definition file is specified.
2413 * @param mconfig [i/o] The pointer to a set structure is specified.
2417 cmd_load_emoji_data(cmd_parms *parms, void *mconfig, const char *arg)
2419 mod_chxj_config *conf;
2426 if (strlen(arg) > 256)
2427 return "mod_chxj: emoji data filename too long.";
2429 conf = (mod_chxj_config *)mconfig;
2430 conf->emoji_data_file = apr_pstrdup(parms->pool, arg);
2431 qs_init_malloc(&doc);
2432 qs_init_root_node(&doc);
2434 qs_parse_file((Doc *)&doc, (const char *)arg);
2436 rtn = chxj_load_emoji_data(&doc,parms->pool, conf);
2438 qs_all_free(&doc, QX_LOGMARK);
2446 cmd_set_image_engine(cmd_parms * UNUSED(parms), void *mconfig, const char *arg)
2448 mod_chxj_config *conf;
2453 if (strlen(arg) > 256)
2454 return "image uri is too long.";
2456 conf = (mod_chxj_config*)mconfig;
2457 if (strcasecmp("ON", arg) == 0) {
2458 conf->image = CHXJ_IMG_ON;
2461 conf->image = CHXJ_IMG_OFF;
2469 cmd_set_image_cache_dir(cmd_parms *parms, void *mconfig, const char *arg)
2471 mod_chxj_config *conf;
2476 if (strlen(arg) > 256)
2477 return "cache dir name is too long.";
2480 apr_status_t res = apr_stat(&info,arg,APR_FINFO_TYPE,parms->pool);
2481 if(res != APR_SUCCESS){
2482 return apr_psprintf(parms->pool,"ChxjImageCacheDir [%s]: not found ",arg);
2485 if(info.filetype != APR_DIR){
2486 return apr_psprintf(parms->pool,"ChxjImageCacheDir [%s]: is not directory ",arg);
2490 conf = (mod_chxj_config *)mconfig;
2491 conf->image_cache_dir = apr_pstrdup(parms->pool, arg);
2498 cmd_set_image_cache_limit(cmd_parms *parms, void *mconfig, const char *arg)
2500 mod_chxj_config *conf;
2505 if (strlen(arg) > IMAGE_CACHE_LIMIT_FMT_LEN)
2506 return "cache size is too long.";
2508 conf = (mod_chxj_config *)mconfig;
2511 * I use strtol function because strtoul is not portable function.
2513 conf->image_cache_limit = (unsigned long)strtol(arg, NULL, 10);
2516 return apr_psprintf(parms->pool, "ChxjImageCacheLimit invalid value [%s] errno:[%d]", arg, errno);
2518 return apr_psprintf(parms->pool, "ChxjImageCacheLimit Out of range [%s] errno:[%d]", arg, errno);
2527 cmd_set_image_copyright(cmd_parms *parms, void *mconfig, const char *arg)
2529 mod_chxj_config *conf;
2534 if (strlen(arg) > 256)
2535 return "Copyright Flag is too long.";
2537 conf = (mod_chxj_config *)mconfig;
2538 conf->image_copyright = apr_pstrdup(parms->pool, arg);
2545 cmd_convert_rule(cmd_parms *cmd, void *mconfig, const char *arg)
2549 mod_chxj_config *dconf;
2550 chxjconvrule_entry *newrule;
2560 dconf = (mod_chxj_config *)mconfig;
2562 if (strlen(arg) > 4096)
2563 return "mod_chxj: ChxjConvertRule: is too long.";
2565 dconf = (mod_chxj_config *)mconfig;
2566 if (dconf->convrules == NULL)
2567 dconf->convrules = apr_array_make(cmd->pool,
2569 sizeof(chxjconvrule_entry));
2571 newrule = apr_array_push(dconf->convrules);
2574 newrule->action = 0;
2576 if (chxj_command_parse_take5(arg, &prm1, &prm2, &prm3, &prm4, &prm5))
2577 return "ChxjConvertRule: bad argument line";
2579 newrule->pattern = apr_pstrdup(cmd->pool, prm1);
2583 if ((action = apr_strtok(prm2, ",", &pstate)) == NULL)
2589 if (strcasecmp(CONVRULE_ENGINE_ON_CMD, action) == 0) {
2590 newrule->action |= CONVRULE_ENGINE_ON_BIT;
2593 if (strcasecmp(CONVRULE_ENGINE_OFF_CMD, action) == 0) {
2594 newrule->action |= CONVRULE_ENGINE_OFF_BIT;
2597 if (strcasecmp(CONVRULE_EMOJI_ONLY_CMD, action) == 0) {
2598 newrule->action |= CONVRULE_EMOJI_ONLY_BIT;
2601 if (strcasecmp(CONVRULE_ENVINFO_ONLY_CMD, action) == 0) {
2602 newrule->action |= CONVRULE_ENVINFO_ONLY_BIT;
2608 if (strcasecmp(CONVRULE_OVERWRITE_X_CLIENT_TYPE_CMD, action) == 0) {
2609 newrule->action |= CONVRULE_OVERWRITE_X_CLIENT_TYPE_BIT;
2615 if (strcasecmp(CONVRULE_COOKIE_ON_CMD, action) == 0) {
2616 newrule->action |= CONVRULE_COOKIE_ON_BIT;
2618 else if (strcasecmp(CONVRULE_COOKIE_OFF_CMD, action) == 0) {
2619 newrule->action &= (0xffffffff ^ CONVRULE_COOKIE_ON_BIT);
2621 else if (strcasecmp(CONVRULE_CSS_ON_CMD, action) == 0) {
2622 newrule->action |= CONVRULE_CSS_ON_BIT;
2624 else if (strcasecmp(CONVRULE_CSS_OFF_CMD, action) == 0) {
2625 newrule->action &= (0xffffffff ^ CONVRULE_CSS_ON_BIT);
2627 else if (strcasecmp(CONVRULE_COOKIE_ONLY_CMD, action) == 0) {
2628 newrule->action |= CONVRULE_COOKIE_ONLY_BIT;
2634 if (strcasecmp(CONVRULE_JRCONV_OFF_CMD, action) == 0) {
2635 newrule->action |= CONVRULE_JRCONV_OFF_BIT;
2641 if (strcasecmp(CONVRULE_NOCACHE_ON_CMD, action) == 0) {
2642 newrule->action |= CONVRULE_NOCACHE_ON_BIT;
2648 if (strcasecmp(CONVRULE_QSCONV_OFF_CMD, action) == 0) {
2649 newrule->action |= CONVRULE_QSCONV_OFF_BIT;
2655 if (strcasecmp(CONVRULE_Z2H_ON_CMD, action) == 0) {
2656 newrule->action |= CONVRULE_Z2H_ON_BIT;
2659 if (strcasecmp(CONVRULE_Z2H_OFF_CMD, action) == 0) {
2660 newrule->action |= CONVRULE_Z2H_OFF_BIT;
2663 if (strcasecmp(CONVRULE_Z2H_ALPHA_ON_CMD, action) == 0) {
2664 newrule->action |= CONVRULE_Z2H_ALPHA_ON_BIT;
2667 if (strcasecmp(CONVRULE_Z2H_ALPHA_OFF_CMD, action) == 0) {
2668 newrule->action |= CONVRULE_Z2H_ALPHA_OFF_BIT;
2671 if (strcasecmp(CONVRULE_Z2H_NUM_ON_CMD, action) == 0) {
2672 newrule->action |= CONVRULE_Z2H_NUM_ON_BIT;
2675 if (strcasecmp(CONVRULE_Z2H_NUM_OFF_CMD, action) == 0) {
2676 newrule->action |= CONVRULE_Z2H_NUM_OFF_BIT;
2679 if (strcasecmp(CONVRULE_Z2H_ALL_ON_CMD, action) == 0) {
2680 newrule->action |= CONVRULE_Z2H_ON_BIT | CONVRULE_Z2H_ALPHA_ON_BIT | CONVRULE_Z2H_NUM_ON_BIT;
2683 if (strcasecmp(CONVRULE_Z2H_NUM_OFF_CMD, action) == 0) {
2684 newrule->action |= CONVRULE_Z2H_OFF_BIT | CONVRULE_Z2H_ALPHA_OFF_BIT | CONVRULE_Z2H_NUM_OFF_BIT;
2695 newrule->flags |= CONVRULE_FLAG_NOTMATCH;
2699 mode = AP_REG_EXTENDED;
2700 if ((regexp = ap_pregcomp((apr_pool_t *)cmd->pool, (const char *)pp, mode)) == NULL)
2701 return "RewriteRule: cannot compile regular expression ";
2703 newrule->regexp = regexp;
2705 newrule->encoding = apr_pstrdup(cmd->pool, prm3);
2707 newrule->encoding = apr_pstrdup(cmd->pool, "none");
2709 newrule->pc_flag = CONVRULE_PC_FLAG_OFF_BIT;
2711 if (strcasecmp(CONVRULE_PC_FLAG_ON_CMD, prm4) == 0)
2712 newrule->pc_flag = CONVRULE_PC_FLAG_ON_BIT;
2714 newrule->user_agent = NULL;
2716 newrule->user_agent = apr_pstrdup(cmd->pool, prm5);
2728 mod_chxj_config *dconf;
2731 if (strlen(arg) > 4096)
2732 return "mod_chxj: ChxjCookieDir is too long.";
2734 dconf = (mod_chxj_config *)mconfig;
2736 dconf->cookie_db_dir = apr_pstrdup(cmd->pool, arg);
2743 cmd_set_cookie_timeout(
2744 cmd_parms *UNUSED(cmd),
2748 mod_chxj_config *dconf;
2750 if (strlen(arg) > 4096)
2751 return "mod_chxj: ChxjCookieTimeout is too long.";
2753 if (chxj_chk_numeric(arg) != 0)
2754 return "mod_chxj: ChxjCookieTimeout is not numeric.";
2756 dconf = (mod_chxj_config *)mconfig;
2758 dconf->cookie_timeout = atoi(arg);
2764 #if defined(USE_MYSQL_COOKIE)
2766 cmd_set_cookie_mysql_database(
2771 mod_chxj_config *dconf;
2773 if (strlen(arg) > 255)
2774 return "mod_chxj: ChxjCookieMysqlDatabase is too long.";
2776 dconf = (mod_chxj_config *)mconfig;
2778 dconf->mysql.database = apr_pstrdup(cmd->pool, arg);
2785 cmd_set_cookie_mysql_username(
2790 mod_chxj_config *dconf;
2792 if (strlen(arg) > 255)
2793 return "mod_chxj: ChxjCookieMysqlUsername is too long.";
2795 dconf = (mod_chxj_config *)mconfig;
2797 dconf->mysql.username = apr_pstrdup(cmd->pool, arg);
2804 cmd_set_cookie_mysql_password(
2809 mod_chxj_config *dconf;
2811 if (strlen(arg) > 255)
2812 return "mod_chxj: ChxjCookieMysqlPassword is too long.";
2814 dconf = (mod_chxj_config *)mconfig;
2816 dconf->mysql.password = apr_pstrdup(cmd->pool, arg);
2823 cmd_set_cookie_mysql_table_name(
2828 mod_chxj_config *dconf;
2830 if (strlen(arg) > 255)
2831 return "mod_chxj: ChxjCookieMysqlTableName is too long.";
2833 dconf = (mod_chxj_config *)mconfig;
2835 dconf->mysql.tablename = apr_pstrdup(cmd->pool, arg);
2841 cmd_set_cookie_mysql_port(
2842 cmd_parms *UNUSED(cmd),
2846 mod_chxj_config *dconf;
2848 if (strlen(arg) > 255)
2849 return "mod_chxj: ChxjCookieMysqlPort is too long.";
2851 dconf = (mod_chxj_config *)mconfig;
2853 if (chxj_chk_numeric(arg) != 0)
2854 return "mod_chxj: ChxjCookieMysqlPort is not numeric.";
2856 dconf = (mod_chxj_config *)mconfig;
2858 dconf->mysql.port = chxj_atoi(arg);
2865 cmd_set_cookie_mysql_host(
2870 mod_chxj_config *dconf;
2872 if (strlen(arg) > 255)
2873 return "mod_chxj: ChxjCookieMysqlHost is too long.";
2875 dconf = (mod_chxj_config *)mconfig;
2877 dconf->mysql.host = apr_pstrdup(cmd->pool, arg);
2884 cmd_set_cookie_mysql_socket_path(
2889 mod_chxj_config *dconf;
2891 if (strlen(arg) > 4096)
2892 return "mod_chxj: ChxjCookieMysqlSocketPath is too long.";
2894 dconf = (mod_chxj_config *)mconfig;
2896 dconf->mysql.socket_path = apr_pstrdup(cmd->pool, arg);
2903 cmd_set_cookie_mysql_charset(
2908 mod_chxj_config *dconf;
2910 if (strlen(arg) > 255)
2911 return "mod_chxj: ChxjCookieMysqlCharset is too long.";
2913 dconf = (mod_chxj_config *)mconfig;
2915 dconf->mysql.charset = apr_pstrdup(cmd->pool, arg);
2920 #if defined(USE_MEMCACHE_COOKIE)
2922 cmd_set_cookie_memcache_port(
2923 cmd_parms *UNUSED(cmd),
2927 mod_chxj_config *dconf;
2929 if (strlen(arg) > 255)
2930 return "mod_chxj: ChxjCookieMemcachePort is too long.";
2932 dconf = (mod_chxj_config *)mconfig;
2934 if (chxj_chk_numeric(arg) != 0)
2935 return "mod_chxj: ChxjCookieMemcachePort is not numeric.";
2937 dconf = (mod_chxj_config *)mconfig;
2939 dconf->memcache.port = (apr_port_t)chxj_atoi(arg);
2946 cmd_set_cookie_memcache_host(
2951 mod_chxj_config *dconf;
2953 if (strlen(arg) > 255)
2954 return "mod_chxj: ChxjCookieMemcacheHost is too long.";
2956 dconf = (mod_chxj_config *)mconfig;
2958 dconf->memcache.host = apr_pstrdup(cmd->pool, arg);
2965 cmd_set_cookie_lazy_mode(
2966 cmd_parms *UNUSED(cmd),
2970 mod_chxj_config *dconf;
2972 if (strlen(arg) > 255)
2973 return "mod_chxj: ChxjCookieLazyMode is too long.";
2975 dconf = (mod_chxj_config *)mconfig;
2977 if (strcasecmp("TRUE",arg) == 0) {
2978 dconf->cookie_lazy_mode = COOKIE_LAZY_ON;
2981 dconf->cookie_lazy_mode = COOKIE_LAZY_OFF;
2988 cmd_set_cookie_store_type(
2989 cmd_parms *UNUSED(cmd),
2993 mod_chxj_config *dconf;
2995 if (strlen(arg) > 255)
2996 return "mod_chxj: ChxjCookieStoreType is too long.";
2998 dconf = (mod_chxj_config *)mconfig;
3000 if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_DBM, arg) == 0) {
3001 dconf->cookie_store_type = COOKIE_STORE_TYPE_DBM;
3003 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MYSQL, arg) == 0) {
3004 dconf->cookie_store_type = COOKIE_STORE_TYPE_MYSQL;
3006 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MEMCACHE, arg) == 0) {
3007 dconf->cookie_store_type = COOKIE_STORE_TYPE_MEMCACHE;
3010 dconf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
3017 cmd_set_forward_url_base(
3022 mod_chxj_config *dconf;
3024 if (strlen(arg) > 255)
3025 return "mod_chxj: ChxjForwardUrlBase is too long.";
3027 dconf = (mod_chxj_config *)mconfig;
3029 dconf->forward_url_base = apr_pstrdup(cmd->pool, arg);
3035 cmd_set_forward_server_ip(
3040 mod_chxj_config *dconf;
3042 if (strlen(arg) > 255)
3043 return "mod_chxj: ChxjForwardServerIp is too long.";
3045 dconf = (mod_chxj_config *)mconfig;
3047 dconf->forward_server_ip = apr_pstrdup(cmd->pool, arg);
3053 cmd_allowed_cookie_domain(
3058 mod_chxj_config *dconf;
3060 if (strlen(arg) > 255)
3061 return "mod_chxj: ChxjAllowedCookieDomain is too long.";
3063 dconf = (mod_chxj_config *)mconfig;
3065 dconf->allowed_cookie_domain = apr_pstrdup(cmd->pool, arg);
3071 cmd_set_new_line_type(
3072 cmd_parms *UNUSED(cmd),
3076 mod_chxj_config *dconf;
3077 if (strlen(arg) > 255)
3078 return "mod_chxj: ChxjNewLineType is too long.";
3080 dconf = (mod_chxj_config *)mconfig;
3082 if (strcasecmp(CHXJ_NEW_LINE_TYPE_CRLF, arg) == 0) {
3083 dconf->new_line_type = NLTYPE_CRLF;
3085 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_LF, arg) == 0) {
3086 dconf->new_line_type = NLTYPE_LF;
3088 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_CR, arg) == 0) {
3089 dconf->new_line_type = NLTYPE_CR;
3091 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_NONE, arg) == 0) {
3092 dconf->new_line_type = NLTYPE_NONE;
3095 return "mod_chxj: invalid value (ChxjNewLineType)";
3106 mod_chxj_config *dconf;
3107 if (strlen(arg) > 255)
3108 return "mod_chxj: ChxjPostLogEnv is too long.";
3110 dconf = (mod_chxj_config *)mconfig;
3112 dconf->post_log = apr_pstrdup(cmd->pool, arg);
3118 cmd_cookie_dbm_type(
3123 mod_chxj_config *dconf;
3124 if (strlen(arg) > 255)
3125 return "mod_chxj: ChxjCookieDbmType is too long.";
3127 dconf = (mod_chxj_config *)mconfig;
3129 dconf->cookie_dbm_type = apr_pstrdup(cmd->pool, arg);
3135 cmd_imode_emoji_color(
3140 mod_chxj_config *dconf;
3142 if (strlen(arg) > 256)
3143 return "imode emoji color is too long.";
3145 dconf = (mod_chxj_config *)mconfig;
3146 if (strcasecmp("ON", arg) == 0) {
3147 dconf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_ON;
3149 else if(strcasecmp("AUTO",arg) == 0) {
3150 dconf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_AUTO;
3153 dconf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_OFF;
3160 cmd_add_device_data_tsv(cmd_parms *parms, void *mconfig, const char *arg)
3162 mod_chxj_config *conf;
3164 if (strlen(arg) > 256)
3165 return "mod_chxj: device tsv filename too long.";
3167 conf = (mod_chxj_config *)mconfig;
3169 conf->detect_device_type = CHXJ_ADD_DETECT_DEVICE_TYPE_TSV;
3172 apr_status_t res = apr_stat(&info,arg,APR_FINFO_TYPE,parms->pool);
3173 if(res != APR_SUCCESS){
3174 return apr_psprintf(parms->pool,"ChxjDeviceTSV [%s]: not found ",arg);
3177 if(info.filetype != APR_REG ){
3178 return apr_psprintf(parms->pool,"ChxjDeviceTSV [%s]: is not file ",arg);
3182 apr_file_open(&fp, arg, APR_READ|APR_BUFFERED, APR_OS_DEFAULT, parms->pool);
3184 chxj_load_device_tsv_data(fp,parms->pool,conf);
3191 cmd_image_rewrite(cmd_parms *parms, void *mconfig, const char *arg)
3193 mod_chxj_config *conf;
3194 if (strlen(arg) > 256){
3195 return "mod_chxj: set rewrite too long.";
3197 conf = (mod_chxj_config *)mconfig;
3198 if (strcasecmp("ON", arg) == 0) {
3199 conf->image_rewrite = CHXJ_IMG_REWRITE_ON;
3201 else if(strcasecmp("OFF",arg) == 0) {
3202 conf->image_rewrite = CHXJ_IMG_REWRITE_OFF;
3205 conf->image_rewrite = CHXJ_IMG_REWRITE_NONE;
3211 cmd_image_rewrite_url(cmd_parms *parms, void *mconfig, const char *arg)
3213 mod_chxj_config *conf;
3214 if (strlen(arg) > 256){
3215 return "mod_chxj: set rewrite url too long.";
3217 conf = (mod_chxj_config *)mconfig;
3218 conf->image_rewrite_url = apr_pstrdup(parms->pool, arg);;
3223 cmd_image_rewrite_mode(cmd_parms *parms, void *mconfig, const char *arg)
3225 mod_chxj_config *conf;
3226 if (strlen(arg) > 256){
3227 return "mod_chxj: set rewrite mode is too long.";
3230 conf = (mod_chxj_config *)mconfig;
3231 if (strcasecmp("all",arg) == 0) {
3232 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_ALL;
3234 else if (strcasecmp("user",arg) == 0) {
3235 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_USER;
3237 else if (strcasecmp("tag",arg) == 0) {
3238 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_TAG;
3241 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_NONE;
3246 static const command_rec cmds[] = {
3248 "ChxjLoadDeviceData",
3249 cmd_load_device_data,
3252 "Load Device Data"),
3254 "ChxjLoadEmojiData",
3255 cmd_load_emoji_data,
3261 cmd_set_image_engine,
3264 "Convert Target URI"),
3266 "ChxjImageCacheDir",
3267 cmd_set_image_cache_dir,
3270 "Image Cache Directory"),
3272 "ChxjImageCacheLimit",
3273 cmd_set_image_cache_limit,
3276 "Image Cache Limit"),
3278 "ChxjImageCopyright",
3279 cmd_set_image_copyright,
3288 "an URL-applied regexp-pattern and a substitution URL"),
3294 "save cookie.db directory."),
3296 "ChxjCookieTimeout",
3297 cmd_set_cookie_timeout,
3300 "The compulsion time-out time of the cookie is specified. "),
3302 "ChxjCookieStoreType",
3303 cmd_set_cookie_store_type,
3306 "It specifies preserving of the cookie ahead. (DBM/MYSQL/MEMCACHE)"),
3308 "ChxjCookieLazyMode",
3309 cmd_set_cookie_lazy_mode,
3312 "OneTimeID is negligently done. (TRUE/FALSE)"),
3313 #if defined(USE_MYSQL_COOKIE)
3315 "ChxjCookieMysqlHost",
3316 cmd_set_cookie_mysql_host,
3319 "The MySQL database host used by saving Cookie"),
3321 "ChxjCookieMysqlPort",
3322 cmd_set_cookie_mysql_port,
3325 "The MySQL database port used by saving Cookie"),
3327 "ChxjCookieMysqlDatabase",
3328 cmd_set_cookie_mysql_database,
3331 "The MySQL database name used by saving Cookie"),
3333 "ChxjCookieMysqlUsername",
3334 cmd_set_cookie_mysql_username,
3337 "The MySQL username used by saving Cookie"),
3339 "ChxjCookieMysqlPassword",
3340 cmd_set_cookie_mysql_password,
3343 "The MySQL password used by saving Cookie"),
3345 "ChxjCookieMysqlTableName",
3346 cmd_set_cookie_mysql_table_name,
3349 "The MySQL table name used by saving Cookie"),
3351 "ChxjCookieMysqlSocketPath",
3352 cmd_set_cookie_mysql_socket_path,
3355 "The MySQL socket path used by saving Cookie"),
3357 "ChxjCookieMysqlCharset",
3358 cmd_set_cookie_mysql_charset,
3361 "The MySQL charset used by saving Cookie"),
3363 #if defined(USE_MEMCACHE_COOKIE)
3365 "ChxjCookieMemcacheHost",
3366 cmd_set_cookie_memcache_host,
3369 "The Memcached host used by saving Cookie"),
3371 "ChxjCookieMemcachePort",
3372 cmd_set_cookie_memcache_port,
3375 "The Memcached port used by saving Cookie"),
3379 cmd_set_new_line_type,
3382 "HTML new line type (NONE|CRLF|LF|CR). default is CRLF"),
3384 "ChxjForwardUrlBase",
3385 cmd_set_forward_url_base,
3388 "The forward url base(default: {request protocol}://{this server}:{this server port}"),
3390 "ChxjForwardServerIp",
3391 cmd_set_forward_server_ip,
3394 "The forward server ip(default: this server ip)"),
3396 "ChxjAllowedCookieDomain",
3397 cmd_allowed_cookie_domain,
3400 "Domain that permits parameter addition for cookie besides hostname.(Default:hostname Only)"),
3406 "for CustomLog directive. mod_chxj's internal POST log environment name.(Default:chxj-post-log)"),
3408 "ChxjCookieDbmType",
3409 cmd_cookie_dbm_type,
3412 "Kind of DBM used with Cookie simulator.(default|GDBM|SDBM|DB|NDBM)"),
3414 "ChxjImodeEmojiColor",
3415 cmd_imode_emoji_color,
3418 "Auto i-mode emoji color"),
3420 "ChxjAddDeviceDataTSV",
3421 cmd_add_device_data_tsv,
3424 "Additional devices TSV data"),
3433 "ChxjImageRewriteUrl",
3434 cmd_image_rewrite_url,
3437 "Set rewrite Image url"
3440 "ChxjImageRewriteMode",
3441 cmd_image_rewrite_mode,
3444 "Set rewrite Image rewrite url mode"
3446 {NULL,{NULL},NULL,0,0,NULL},
3450 /*----------------------------------------------------------------------------*/
3451 /* Dispatch list for API hooks */
3452 /*----------------------------------------------------------------------------*/
3453 module AP_MODULE_DECLARE_DATA chxj_module = {
3454 STANDARD20_MODULE_STUFF,
3455 chxj_create_per_dir_config, /* create per-dir config structures */
3456 chxj_merge_per_dir_config, /* merge per-dir config structures */
3457 chxj_config_server_create, /* create per-server config structures */
3458 NULL, /* merge per-server config structures */
3459 cmds, /* table of config file commands */
3460 chxj_register_hooks /* register hooks */