2 * Copyright (C) 2005-2011 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_iphone.h"
62 #include "chxj_img_conv_format.h"
63 #include "chxj_qr_code.h"
64 #include "chxj_encoding.h"
65 #include "chxj_apply_convrule.h"
66 #include "chxj_cookie.h"
67 #include "chxj_url_encode.h"
68 #include "chxj_str_util.h"
69 #include "chxj_dump_string.h"
70 #if defined(USE_MYSQL_COOKIE)
71 # include "chxj_mysql.h"
73 #include "chxj_serf.h"
74 #include "chxj_add_device_env.h"
75 #include "chxj_header_inf.h"
76 #include "chxj_jreserved_tag.h"
79 #define CHXJ_VERSION_PREFIX PACKAGE_NAME "/"
80 #define CHXJ_VERSION PACKAGE_VERSION
81 #define CHXJ_POST_MAX (0x1000000)
83 converter_t convert_routine[] = {
85 /* CHXJ_SPEC_UNKNOWN */
88 .emoji_only_converter = NULL,
91 /* CHXJ_SPEC_Chtml_1_0 */
92 .converter = chxj_convert_chtml10,
93 .encoder = chxj_encoding,
94 .emoji_only_converter = chxj_chtml10_emoji_only_converter,
97 /* CHXJ_SPEC_Chtml_2_0 */
98 .converter = chxj_convert_chtml20,
99 .encoder = chxj_encoding,
100 .emoji_only_converter = chxj_chtml20_emoji_only_converter,
103 /* CHXJ_SPEC_Chtml_3_0 */
104 .converter = chxj_convert_chtml30,
105 .encoder = chxj_encoding,
106 .emoji_only_converter = chxj_chtml30_emoji_only_converter,
109 /* CHXJ_SPEC_Chtml_4_0 */
110 .converter = chxj_convert_chtml40,
111 .encoder = chxj_encoding,
112 .emoji_only_converter = chxj_chtml40_emoji_only_converter,
115 /* CHXJ_SPEC_Chtml_5_0 */
116 .converter = chxj_convert_chtml50,
117 .encoder = chxj_encoding,
118 .emoji_only_converter = chxj_chtml50_emoji_only_converter,
121 /* CHXJ_SPEC_Chtml_6_0 */
122 .converter = chxj_convert_ixhtml10,
123 .encoder = chxj_encoding,
124 .emoji_only_converter = chxj_chtml50_emoji_only_converter, /* XXX: TODO */
127 /* CHXJ_SPEC_Chtml_7_0 */
128 .converter = chxj_convert_ixhtml10,
129 .encoder = chxj_encoding,
130 .emoji_only_converter = chxj_chtml50_emoji_only_converter, /* XXX: TODO */
133 /* CHXJ_SPEC_XHtml_Mobile_1_0 */
134 .converter = chxj_convert_xhtml_mobile_1_0,
135 .encoder = chxj_encoding,
136 .emoji_only_converter = chxj_xhtml_emoji_only_converter,
140 .converter = chxj_convert_hdml,
141 .encoder = chxj_encoding,
142 .emoji_only_converter = NULL,
145 /* CHXJ_SPEC_Jhtml */
146 .converter = chxj_convert_jhtml,
147 .encoder = chxj_encoding,
148 .emoji_only_converter = chxj_jhtml_emoji_only_converter,
151 /* CHXJ_SPEC_Jxhtml */
152 .converter = chxj_convert_jxhtml,
153 .encoder = chxj_encoding,
154 .emoji_only_converter = chxj_jxhtml_emoji_only_converter,
157 /* CHXJ_SPEC_iPhone2 */
158 .converter = chxj_convert_iphone,
159 .encoder = chxj_encoding,
160 .emoji_only_converter = chxj_iphone_emoji_only_converter,
163 /* CHXJ_SPEC_iPhone3 */
164 .converter = chxj_convert_iphone,
165 .encoder = chxj_encoding,
166 .emoji_only_converter = chxj_iphone_emoji_only_converter,
169 /* CHXJ_SPEC_iPhone4 */
170 .converter = chxj_convert_iphone,
171 .encoder = chxj_encoding,
172 .emoji_only_converter = chxj_iphone_emoji_only_converter,
178 .emoji_only_converter = NULL,
182 static int chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp, device_table *spec);
183 static void s_convert_guid_parameter_to_header(request_rec *r, const char *param, device_table *spec);
184 static void s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie);
185 static void s_clear_cookie_header(request_rec *r, device_table *spec);
186 static void s_add_no_cache_headers(request_rec *r, chxjconvrule_entry *entryp);
188 mod_chxj_req_config *
189 chxj_get_req_config(request_rec *r)
191 mod_chxj_req_config *request_conf;
192 request_conf = (mod_chxj_req_config *)chxj_get_module_config(r->request_config, &chxj_module);
193 if (! request_conf) {
194 request_conf = apr_pcalloc(r->pool, sizeof(mod_chxj_req_config));
195 request_conf->spec = NULL;
196 request_conf->user_agent = NULL;
197 request_conf->f = NULL;
198 request_conf->entryp = NULL;
199 chxj_set_module_config(r->request_config, &chxj_module, request_conf);
205 * Only when User-Agent is specified, the User-Agent header is camouflaged.
210 chxj_headers_fixup(request_rec *r)
212 mod_chxj_config* dconf;
213 mod_chxj_req_config *request_conf;
214 chxjconvrule_entry* entryp;
220 DBG(r, "REQ[%X] start %s()", TO_ADDR(r), __func__);
222 request_conf = chxj_get_req_config(r);
224 DBG(r, "REQ[%X] detect internal redirect.", TO_ADDR(r));
225 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
228 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
230 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
233 * check and get mobile type.
234 * and request_conf->user_agent , request_conf->spec is set.
236 spec = chxj_specified_device(r, user_agent);
238 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
240 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
241 DBG(r, "REQ[%X] detect multipart/form-data ==> no target", TO_ADDR(r));
242 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
247 switch(spec->html_spec_type) {
248 case CHXJ_SPEC_Chtml_1_0:
249 case CHXJ_SPEC_Chtml_2_0:
250 case CHXJ_SPEC_Chtml_3_0:
251 case CHXJ_SPEC_Chtml_4_0:
252 case CHXJ_SPEC_Chtml_5_0:
253 case CHXJ_SPEC_Chtml_6_0:
254 case CHXJ_SPEC_Chtml_7_0:
255 case CHXJ_SPEC_XHtml_Mobile_1_0:
257 case CHXJ_SPEC_Jhtml:
258 case CHXJ_SPEC_Jxhtml:
259 case CHXJ_SPEC_iPhone2:
260 case CHXJ_SPEC_iPhone3:
261 case CHXJ_SPEC_iPhone4:
262 request_conf->entryp = entryp = chxj_apply_convrule(r, dconf->convrules);
263 if (dconf->image != CHXJ_IMG_ON) {
265 DBG(r, "REQ[%X] end %s() (no pattern)", TO_ADDR(r), __func__);
268 if (!(entryp->action & CONVRULE_ENGINE_ON_BIT) && !(entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
269 DBG(r, "REQ[%X] end %s() (engine off)", TO_ADDR(r), __func__);
272 if (entryp->action & CONVRULE_EMOJI_ONLY_BIT) {
273 DBG(r, "REQ[%X] end %s() (emoji only)", TO_ADDR(r), __func__);
277 apr_table_setn(r->headers_in,
278 CHXJ_HTTP_USER_AGENT,
281 if (entryp && entryp->user_agent)
282 apr_table_setn(r->headers_in,
286 * this clear process must do before chxj_convert_input_header function.
289 if ((entryp->action & CONVRULE_COOKIE_ON_BIT) || (entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
290 if (r->method_number == M_POST) {
291 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
292 s_clear_cookie_header(r, spec);
296 s_clear_cookie_header(r, spec);
301 chxj_convert_input_header(r,entryp, spec);
306 DBG(r, "REQ[%X] end %s() (not mobile) spec->device_name[%s] User-Agent:[%s]", TO_ADDR(r),__func__, spec->device_name, user_agent);
311 char *x_client_type = (char *)apr_table_get(r->headers_out, "X-Client-Type");
312 apr_table_unset(r->headers_out, "X-Client-Type");
314 apr_table_setn(r->headers_in, "X-Client-Type", x_client_type);
317 apr_table_setn(r->headers_in, "X-Client-Type", "");
320 if (r->method_number == M_POST) {
321 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
322 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);
323 r->proxyreq = PROXYREQ_NONE;
324 r->handler = apr_psprintf(r->pool, "chxj-input-handler");
327 char *client_ip = (char *)apr_table_get(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP);
329 if (dconf->post_log) {
330 apr_table_setn(r->subprocess_env, dconf->post_log, dconf->post_log);
333 apr_table_setn(r->subprocess_env, "chxj-post-log", "chxj-post-log");
335 apr_sockaddr_t *address = NULL;
336 apr_status_t rv = apr_sockaddr_info_get(&address, ap_get_server_name(r), APR_UNSPEC, ap_get_server_port(r), 0, r->pool);
337 if (rv != APR_SUCCESS) {
339 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));
340 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
344 if (dconf->forward_server_ip) {
345 addr = dconf->forward_server_ip;
348 apr_sockaddr_ip_get(&addr, address);
350 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);
351 if (strcmp(addr, r->connection->remote_ip) == 0) {
352 r->connection->remote_ip = apr_pstrdup(r->connection->pool, client_ip);
353 /* For mod_cidr_lookup */
354 if (entryp && (entryp->action & CONVRULE_OVERWRITE_X_CLIENT_TYPE_BIT)) {
355 char *client_type = (char *)apr_table_get(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_TYPE);
356 DBG(r, "REQ[%X] Overwrite X-Client-Type to [%s]", TO_ADDR(r), client_type);
358 apr_table_setn(r->subprocess_env, "X_CLIENT_TYPE", client_type);
359 apr_table_setn(r->headers_in, "X-Client-Type", client_type);
362 apr_table_unset(r->headers_in, "X-Client-Type");
366 if (! apr_table_get(r->headers_in, "Content-Length")) {
367 contentLength = (char *)apr_table_get(r->headers_in, "X-Chxj-Content-Length");
369 apr_table_set(r->headers_in, "Content-Length", contentLength);
376 if(r->content_type && strncmp(r->content_type,"image/",6) == 0){
377 if (dconf->image_rewrite == CHXJ_IMG_REWRITE_ON && !apr_table_get(r->headers_in, CHXJ_IMG_X_HTTP_IMAGE_FILENAME)){
378 if(dconf->image_rewrite_mode == CHXJ_IMG_REWRITE_MODE_ALL){
380 apr_table_set(r->headers_in, CHXJ_IMG_X_HTTP_IMAGE_FILENAME, r->filename);
381 apr_table_set(r->headers_in, CHXJ_IMG_X_HTTP_IMAGE_TYPE,r->content_type);
382 r->filename = apr_pstrcat(r->pool,"img-redirect:",dconf->image_rewrite_url,NULL);
383 r->handler = "chxj-image-redirect-handler";
387 // has _chxj_imgrewrite=on in args
388 char *args_tmp = chxj_url_decode(r->pool, r->args);
389 if (strstr(args_tmp,CHXJ_IMG_REWRITE_URL_STRING)){
390 apr_table_set(r->headers_in, CHXJ_IMG_X_HTTP_IMAGE_FILENAME, r->filename);
391 apr_table_set(r->headers_in, CHXJ_IMG_X_HTTP_IMAGE_TYPE,r->content_type);
392 r->filename = apr_pstrcat(r->pool,"img-redirect:",dconf->image_rewrite_url,NULL);
393 r->handler = "chxj-image-redirect-handler";
401 chxj_add_device_env(r, spec);
403 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
409 chxj_image_redirect_handler(request_rec *r)
412 if (strcmp(r->handler, "chxj-image-redirect-handler")) {
416 if (strncmp(r->filename, "img-redirect:", 13) != 0) {
419 DBG(r,"REQ[%X] start %s()",TO_ADDR(r),__func__);
420 ap_internal_redirect(apr_pstrcat(r->pool, r->filename+13,
421 r->args ? "?" : NULL, r->args, NULL), r);
422 DBG(r,"REQ[%X] end %s()", TO_ADDR(r),__func__);
428 s_clear_cookie_header(request_rec *r, device_table *spec)
430 DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
431 switch(spec->html_spec_type) {
432 case CHXJ_SPEC_Chtml_1_0:
433 case CHXJ_SPEC_Chtml_2_0:
434 case CHXJ_SPEC_Chtml_3_0:
435 case CHXJ_SPEC_Chtml_4_0:
436 case CHXJ_SPEC_Chtml_5_0:
437 case CHXJ_SPEC_Chtml_6_0:
438 case CHXJ_SPEC_Chtml_7_0:
439 case CHXJ_SPEC_XHtml_Mobile_1_0:
440 case CHXJ_SPEC_Jhtml:
441 case CHXJ_SPEC_Jxhtml:
442 apr_table_unset(r->headers_in, "Cookie");
444 case CHXJ_SPEC_iPhone2:
445 case CHXJ_SPEC_iPhone3:
446 case CHXJ_SPEC_iPhone4:
450 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
455 * It converts it from CHTML into XXML corresponding to each model.
458 * @param src [i] It is former HTML character string.
459 * @param len [i/o] It is length of former HTML character string.
462 chxj_convert(request_rec *r, const char **src, apr_size_t *len, device_table *spec, const char *ua, cookie_t **cookiep)
468 mod_chxj_config *dconf;
469 mod_chxj_req_config *request_conf;
470 chxjconvrule_entry *entryp;
472 DBG(r,"REQ[%X] start %s()", TO_ADDR(r),__func__);
474 chxj_dump_string(r, APLOG_MARK, "INPUT Data", *src, *len);
476 dst = apr_pstrcat(r->pool, (char *)*src, NULL);
478 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
479 request_conf = chxj_get_req_config(r);
482 /*-------------------------------------------------------------------------*/
483 /* already setup entryp if request_conf->user_agent is not null */
484 /*-------------------------------------------------------------------------*/
485 if (request_conf->user_agent) {
486 entryp = request_conf->entryp;
489 entryp = chxj_apply_convrule(r, dconf->convrules);
493 || ( !(entryp->action & CONVRULE_ENGINE_ON_BIT)
494 && !(entryp->action & CONVRULE_COOKIE_ONLY_BIT)
495 && !(entryp->action & CONVRULE_EMOJI_ONLY_BIT)
497 DBG(r,"REQ[%X] end %s()", TO_ADDR(r),__func__);
502 /*------------------------------------------------------------------------*/
503 /* get UserAgent from http header */
504 /*------------------------------------------------------------------------*/
505 if (entryp->user_agent)
506 user_agent = (char *)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
508 user_agent = (char *)apr_table_get(r->headers_in, HTTP_USER_AGENT);
510 DBG(r,"REQ[%X] User-Agent:[%s]", TO_ADDR(r), user_agent);
511 DBG(r,"REQ[%X] content type is [%s]", TO_ADDR(r), r->content_type);
514 if ( ! STRNCASEEQ('t','T', "text/html", r->content_type, sizeof("text/html")-1)
515 && ! STRNCASEEQ('a','A', "application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)) {
516 DBG(r,"REQ[%X] no convert. content type is [%s]", TO_ADDR(r), r->content_type);
517 DBG(r,"REQ[%X] end %s()", TO_ADDR(r),__func__);
521 if (ua && user_agent && strcasecmp(user_agent, ua) != 0) {
523 spec = chxj_specified_device(r, user_agent);
526 spec = request_conf->spec;
533 if ((entryp->action & CONVRULE_COOKIE_ON_BIT
534 && !(entryp->action & CONVRULE_EMOJI_ONLY_BIT)
535 && !(entryp->action & CONVRULE_ENVINFO_ONLY_BIT))
536 || (entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
537 switch(spec->html_spec_type) {
538 case CHXJ_SPEC_Chtml_1_0:
539 case CHXJ_SPEC_Chtml_2_0:
540 case CHXJ_SPEC_Chtml_3_0:
541 case CHXJ_SPEC_Chtml_4_0:
542 case CHXJ_SPEC_Chtml_5_0:
543 case CHXJ_SPEC_Chtml_6_0:
544 case CHXJ_SPEC_Chtml_7_0:
545 case CHXJ_SPEC_XHtml_Mobile_1_0:
546 case CHXJ_SPEC_Jhtml:
547 case CHXJ_SPEC_Jxhtml:
548 cookie = chxj_save_cookie(r);
550 case CHXJ_SPEC_iPhone2:
551 case CHXJ_SPEC_iPhone3:
552 case CHXJ_SPEC_iPhone4:
558 if (!r->header_only) {
560 if ((entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
562 dst = chxj_cookie_only_mode(r, *src, (apr_size_t *)len, cookie);
568 else if (!(entryp->action & CONVRULE_ENGINE_ON_BIT) && (entryp->action & CONVRULE_EMOJI_ONLY_BIT)) {
569 /*---------------------------------------------------------------------*/
570 /* force emoji only mode */
571 /*---------------------------------------------------------------------*/
573 if (convert_routine[spec->html_spec_type].encoder)
574 tmp = convert_routine[spec->html_spec_type].encoder(r,
577 if (convert_routine[spec->html_spec_type].emoji_only_converter) {
578 dst = convert_routine[spec->html_spec_type].emoji_only_converter(r,spec, tmp,*len);
583 dst = apr_palloc(r->pool, 1);
591 if (convert_routine[spec->html_spec_type].encoder)
592 tmp = convert_routine[spec->html_spec_type].encoder(r,
596 if (entryp->action & CONVRULE_EMOJI_ONLY_BIT) {
598 tmp = chxj_node_convert_chxjif_only(r, spec, (const char*)tmp, (apr_size_t *)len);
601 tmp = chxj_node_convert_chxjif_only(r, spec, (const char *)*src, (apr_size_t *)len);
603 if (convert_routine[spec->html_spec_type].emoji_only_converter) {
604 dst = convert_routine[spec->html_spec_type].emoji_only_converter(r,spec, tmp,*len);
609 dst = apr_palloc(r->pool, 1);
614 DBG(r, "REQ[%X] end %s()(emoji only)", TO_ADDR(r),__func__);
617 if ( !(entryp->action & CONVRULE_EMOJI_ONLY_BIT)
618 && !(entryp->action & CONVRULE_ENVINFO_ONLY_BIT)) {
619 if (convert_routine[spec->html_spec_type].converter) {
621 dst = convert_routine[spec->html_spec_type].converter(r,
629 dst = convert_routine[spec->html_spec_type].converter(r,
641 if (strcasecmp(spec->output_encoding,"UTF-8") == 0){
642 dst = chxj_iconv(r,r->pool,dst,len,"CP932","UTF-8");
647 ap_set_content_length(r, *len);
650 dst = apr_psprintf(r->pool, "\n");
660 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
667 * convert GUID parameter.
671 s_convert_guid_parameter_to_header(request_rec *r, const char *param, device_table *spec)
673 DBG(r, "REQ[%X] start %s() param:[%s]", TO_ADDR(r),__func__, param);
674 if (strcasecmp(param, "guid") == 0) {
675 switch(spec->html_spec_type) {
676 case CHXJ_SPEC_XHtml_Mobile_1_0:
678 char *x_up_subno = (char *)apr_table_get(r->headers_in, "x-up-subno");
680 apr_table_setn(r->headers_in, "X-DCMGUID", x_up_subno);
684 case CHXJ_SPEC_Jhtml:
685 case CHXJ_SPEC_Jxhtml:
687 char *x_jphone_uid = (char *)apr_table_get(r->headers_in, "x-jphone-uid");
689 apr_table_setn(r->headers_in, "X-DCMGUID", x_jphone_uid);
697 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
701 * It converts it from HEADER.
706 chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp, device_table *spec)
718 cookie_t *cookie = NULL;
719 int no_update_flag = 0;
721 DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
724 DBG(r, "REQ[%X] r->args=[null]", TO_ADDR(r));
725 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
728 urilen = strlen(r->args);
730 result = qs_alloc_zero_byte_string(r->pool);
732 buff_pre = apr_pstrdup(r->pool, r->args);
737 pair = apr_strtok(buff_pre, "&", &pstate);
743 pair_sv = apr_pstrdup(r->pool, pair);
745 name = apr_strtok(pair, "=", &vstate);
746 value = apr_strtok(NULL, "=", &vstate);
747 if (! name) continue;
748 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
749 DBG(r, "REQ[%X] found cookie no update parameter", TO_ADDR(r));
754 buff = apr_pstrdup(r->pool, r->args);
755 DBG(r, "REQ[%X] r->args=[%s]", TO_ADDR(r), buff);
764 pair = apr_strtok(buff, "&", &pstate);
770 pair_sv = apr_pstrdup(r->pool, pair);
772 name = apr_strtok(pair, "=", &vstate);
773 value = apr_strtok(NULL, "=", &vstate);
774 if (! name) continue;
775 name = chxj_safe_to_jreserved_tag(r, name);
776 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
777 if (strlen(result) != 0)
778 result = apr_pstrcat(r->pool, result, "&", NULL);
780 if (entryp && strcasecmp(entryp->encoding, "NONE") != 0) {
785 if (value && *value != 0) {
786 value = chxj_url_decode(r->pool, value);
787 dlen = strlen(value);
788 DBG(r, "REQ[%X] ************ before encoding[%s]", TO_ADDR(r),value);
790 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
791 dvalue = chxj_url_encode(r->pool, dvalue);
793 DBG(r, "REQ[%X] ************ after encoding[%s]", TO_ADDR(r),dvalue);
799 if (name && *name != 0) {
800 name = chxj_url_decode(r->pool, name);
802 dname = chxj_rencoding(r, name, &dlen,spec->output_encoding);
803 dname = chxj_url_encode(r->pool, dname);
808 s_convert_guid_parameter_to_header(r, dname, spec);
809 result = apr_pstrcat(r->pool, result, dname, "=", dvalue, NULL);
812 s_convert_guid_parameter_to_header(r, name, spec);
813 if (strcmp(name, pair_sv) != 0) {
814 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
817 result = apr_pstrcat(r->pool, result, name, NULL);
822 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
823 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
824 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
828 if (strlen(value) == 0)
831 if (strlen(result) != 0)
832 result = apr_pstrcat(r->pool, result, "&", NULL);
834 result = apr_pstrcat(r->pool, result, &name[8], "=", value, NULL);
837 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
839 apr_table_unset(r->headers_in, "Cookie");
840 DBG(r, "REQ[%X] found cookie parameter[%s]", TO_ADDR(r), value);
841 cookie_lock_t *lock = chxj_cookie_lock(r);
842 cookie = chxj_load_cookie(r, value);
843 if (! no_update_flag && cookie) {
844 cookie = chxj_update_cookie(r, cookie);
846 chxj_cookie_unlock(r, lock);
848 if (cookie && cookie->cookie_id) {
849 if (strlen(result) != 0)
850 result = apr_pstrcat(r->pool, result, "&", NULL);
851 result = apr_pstrcat(r->pool, result, name, "=", cookie->cookie_id, NULL);
855 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
856 if (strlen(result) != 0)
857 result = apr_pstrcat(r->pool, result, "&", NULL);
858 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
861 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
862 if (! no_update_flag) {
863 result = apr_pstrcat(r->pool, result, "&_chxj_nc=true", NULL);
867 DBG(r, "REQ[%X] result r->args=[%s]", TO_ADDR(r), r->args);
868 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
874 * It converts it from POSTDATA .
877 * @param src [i] It is POSTDATA character string.
878 * @param len [i/o] It is length of former HTML character string.
885 chxjconvrule_entry *entryp,
895 cookie_t *cookie = NULL;
897 int no_update_flag = 0;
901 DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
904 DBG(r, "REQ[%X] end %s() (input is null)", TO_ADDR(r),__func__);
905 return apr_pstrdup(r->pool, "");
908 apr_pool_create(&pool, r->pool);
910 s = apr_pstrdup(pool, *src);
912 buff_pre = apr_pstrdup(pool, *src);
914 result = qs_alloc_zero_byte_string(pool);
916 chxj_dump_string(r, APLOG_MARK, "BEFORE input convert source", s, ilen);
921 pair = apr_strtok(buff_pre, "&", &pstate);
927 pair_sv = apr_pstrdup(pool, pair);
929 name = apr_strtok(pair, "=", &vstate);
930 value = apr_strtok(NULL, "=", &vstate);
931 if (! name) continue;
932 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
933 DBG(r, "REQ[%X] found cookie no update parameter", TO_ADDR(r));
943 pair = apr_strtok(s, "&", &pstate);
948 name = apr_strtok(pair, "=", &vstate);
949 value = apr_strtok(NULL, "=", &vstate);
950 if (! name) continue;
951 name = chxj_safe_to_jreserved_tag(r, name);
953 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
954 if (strlen(result) != 0)
955 result = apr_pstrcat(pool, result, "&", NULL);
957 if (entryp && strcasecmp(entryp->encoding, "NONE") != 0) {
962 if (value && *value != 0) {
963 value = chxj_url_decode(pool, value);
964 dlen = strlen(value);
965 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
966 dvalue = chxj_url_encode(pool, dvalue);
972 if (name && *name != 0) {
973 name = chxj_url_decode(pool, name);
975 dname = chxj_rencoding(r, name, &dlen,spec->output_encoding);
976 dname = chxj_url_encode(pool, dname);
983 result = apr_pstrcat(pool, result, dname, "=", dvalue, NULL);
986 result = apr_pstrcat(pool, result, name, "=", value, NULL);
990 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
991 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
992 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
996 if (strlen(value) == 0)
999 if (strlen(result) != 0)
1000 result = apr_pstrcat(pool, result, "&", NULL);
1002 if (entryp && strcasecmp(entryp->encoding, "NONE") != 0 && value && strlen(value)) {
1006 dlen = strlen(value);
1007 value = chxj_url_decode(pool, value);
1008 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
1009 dvalue = chxj_url_encode(pool,dvalue);
1010 result = apr_pstrcat(pool, result, &name[8], "=", dvalue, NULL);
1014 result = apr_pstrcat(pool, result, &name[8], "=", value, NULL);
1018 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
1020 apr_table_unset(r->headers_in, "Cookie");
1021 DBG(r, "REQ[%X] found cookie parameter[%s]", TO_ADDR(r), value);
1022 cookie_lock_t *lock = chxj_cookie_lock(r);
1023 cookie = chxj_load_cookie(r, value);
1024 if (! no_update_flag && cookie) {
1025 cookie = chxj_update_cookie(r, cookie);
1027 chxj_cookie_unlock(r, lock);
1029 if (cookie && cookie->cookie_id) {
1030 if (strlen(result) != 0)
1031 result = apr_pstrcat(pool, result, "&", NULL);
1032 result = apr_pstrcat(pool, result, name, "=", cookie->cookie_id, NULL);
1036 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
1037 if (strlen(result) != 0)
1038 result = apr_pstrcat(pool, result, "&", NULL);
1039 result = apr_pstrcat(pool, result, name, "=", value, NULL);
1042 if ( strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1) == 0) {
1043 apr_size_t dlen = 0;
1046 dlen = strlen(value);
1049 value = chxj_url_decode(pool, value);
1050 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
1051 dvalue = chxj_url_encode(pool,dvalue);
1052 if (r->args && strlen(r->args) > 0) {
1053 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
1056 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
1058 s_convert_guid_parameter_to_header(r, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], spec);
1062 if (strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX_ENC, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1) == 0) {
1065 dlen = strlen(value);
1066 if (dlen && value) {
1067 value = chxj_url_decode(pool, value);
1068 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
1069 dvalue = chxj_url_encode(pool,dvalue);
1070 if (r->args && strlen(r->args) > 0) {
1071 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
1074 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
1076 s_convert_guid_parameter_to_header(r, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], spec);
1079 DBG(r, "REQ[%X] ************************ name:[%s]", TO_ADDR(r), name);
1081 *len = strlen(result);
1082 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
1083 if (! no_update_flag) {
1084 result = apr_pstrcat(pool, result, "&_chxj_nc=true", NULL);
1087 DBG(r, "REQ[%X] AFTER input convert result = [%s]", TO_ADDR(r), result);
1088 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1095 * The received data is returned to the filter.
1097 * @param f [i/o] It is a filter.
1098 * @param data [i] It is data returned to the filter.
1099 * @param len [i] It is length of the data returned to the filter.
1102 pass_data_to_filter(ap_filter_t *f, const char *data,
1105 request_rec *r = f->r;
1106 conn_rec *c = r->connection;
1108 apr_bucket_brigade *bb;
1111 DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
1113 chxj_header_inf_clear(r);
1115 bb = apr_brigade_create(r->pool, c->bucket_alloc);
1116 b = apr_bucket_transient_create(data, len, c->bucket_alloc);
1118 APR_BRIGADE_INSERT_TAIL(bb, b);
1119 b = apr_bucket_eos_create(f->c->bucket_alloc);
1120 APR_BRIGADE_INSERT_TAIL(bb, b);
1122 rv = ap_pass_brigade(f->next, bb);
1123 if (rv != APR_SUCCESS) {
1124 DBG(r, "REQ[%X] end %s() (apr_pass_brigade)", TO_ADDR(r),__func__);
1128 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1134 * Add No Cache Header
1137 s_add_no_cache_headers(request_rec *r, chxjconvrule_entry *entryp)
1139 if (entryp && (entryp->action & CONVRULE_NOCACHE_ON_BIT)) {
1140 apr_table_unset(r->headers_out, "Pragma");
1141 apr_table_unset(r->err_headers_out, "Pragma");
1142 apr_table_unset(r->headers_out, "Expires");
1143 apr_table_unset(r->err_headers_out, "Expires");
1144 apr_table_unset(r->headers_out, "Cache-Control");
1145 apr_table_unset(r->err_headers_out, "Cache-Control");
1147 apr_table_setn(r->err_headers_out, "Pragma", "no-cache");
1148 apr_table_setn(r->err_headers_out, "Expires", "Thu, 01 Jan 1970 00:00:00 GMT");
1149 apr_table_setn(r->err_headers_out, "Cache-Control", "no-cache, no-store");
1155 * It is the main loop of the output filter.
1157 * @param f [i/o] It is a filter.
1161 chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
1167 char *user_agent = NULL;
1169 mod_chxj_ctx *ctx = (mod_chxj_ctx *)f->ctx;
1170 cookie_t *cookie = NULL;
1171 mod_chxj_config *dconf;
1172 chxjconvrule_entry *entryp = NULL;
1173 device_table *spec = NULL;
1177 DBG(f->r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
1180 apr_pool_create(&pool, r->pool);
1182 entryp = ctx->entryp;
1184 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1187 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1188 DBG(r, "REQ[%X] found Location header", TO_ADDR(r));
1189 if ((entryp->action & CONVRULE_COOKIE_ON_BIT) || (entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
1190 cookie_lock_t *lock = NULL;
1191 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", TO_ADDR(r));
1192 switch(spec->html_spec_type) {
1193 case CHXJ_SPEC_Chtml_1_0:
1194 case CHXJ_SPEC_Chtml_2_0:
1195 case CHXJ_SPEC_Chtml_3_0:
1196 case CHXJ_SPEC_Chtml_4_0:
1197 case CHXJ_SPEC_Chtml_5_0:
1198 case CHXJ_SPEC_Chtml_6_0:
1199 case CHXJ_SPEC_Chtml_7_0:
1200 case CHXJ_SPEC_XHtml_Mobile_1_0:
1201 case CHXJ_SPEC_Jhtml:
1202 case CHXJ_SPEC_Jxhtml:
1203 lock = chxj_cookie_lock(r);
1204 cookie = chxj_save_cookie(r);
1205 s_add_cookie_id_if_has_location_header(r, cookie);
1206 chxj_cookie_unlock(r, lock);
1208 case CHXJ_SPEC_iPhone2:
1209 case CHXJ_SPEC_iPhone3:
1210 case CHXJ_SPEC_iPhone4:
1215 if (! ap_is_HTTP_REDIRECT(r->status)) {
1216 r->status = HTTP_MOVED_TEMPORARILY;
1218 s_add_no_cache_headers(r, entryp);
1219 /* must not send body. */
1220 rv = pass_data_to_filter(f, "", 0);
1221 DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1226 if (r->content_type) {
1227 if (! STRNCASEEQ('t','T',"text/html",r->content_type, sizeof("text/html")-1)
1228 && ! STRNCASEEQ('t','T',"text/xml", r->content_type, sizeof("text/xml")-1)
1229 && ! STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
1230 && ! (dconf->image == CHXJ_IMG_ON
1231 && ! apr_table_get(r->headers_in, "CHXJ_IMG_CONV")
1232 && STRNCASEEQ('i','I',"image/", r->content_type, sizeof("image/") -1)
1233 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
1234 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
1235 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
1236 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
1237 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
1238 || STRCASEEQ('x','X',"x-ms-bmp", &r->content_type[6]) /* BMP */
1239 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
1240 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
1241 || STRCASEEQ('g','G',"gif", &r->content_type[6])))) { /* GIF */
1243 DBG(r, "REQ[%X] not convert content-type:[%s] dconf->image:[%d]", TO_ADDR(r), r->content_type, dconf->image);
1244 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
1245 cookie_lock_t *lock = NULL;
1246 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", TO_ADDR(r));
1247 switch(spec->html_spec_type) {
1248 case CHXJ_SPEC_Chtml_1_0:
1249 case CHXJ_SPEC_Chtml_2_0:
1250 case CHXJ_SPEC_Chtml_3_0:
1251 case CHXJ_SPEC_Chtml_4_0:
1252 case CHXJ_SPEC_Chtml_5_0:
1253 case CHXJ_SPEC_Chtml_6_0:
1254 case CHXJ_SPEC_Chtml_7_0:
1255 case CHXJ_SPEC_XHtml_Mobile_1_0:
1256 case CHXJ_SPEC_Jhtml:
1257 case CHXJ_SPEC_Jxhtml:
1258 lock = chxj_cookie_lock(r);
1259 cookie = chxj_save_cookie(r);
1260 s_add_cookie_id_if_has_location_header(r, cookie);
1261 chxj_cookie_unlock(r, lock);
1263 case CHXJ_SPEC_iPhone2:
1264 case CHXJ_SPEC_iPhone3:
1265 case CHXJ_SPEC_iPhone4:
1270 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1271 if (! ap_is_HTTP_REDIRECT(r->status)) {
1272 r->status = HTTP_MOVED_TEMPORARILY;
1275 s_add_no_cache_headers(r, entryp);
1276 ap_pass_brigade(f->next, bb);
1277 DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1282 DBG(r, "REQ[%X] not convert content-type:[(null)]", TO_ADDR(r));
1283 ap_pass_brigade(f->next, bb);
1284 DBG(f->r, "REQ[%X] end %s()", TO_ADDR(f->r),__func__);
1289 for (b = APR_BRIGADE_FIRST(bb);
1290 b != APR_BRIGADE_SENTINEL(bb);
1291 b = APR_BUCKET_NEXT(b)) {
1293 if (apr_bucket_read(b, &data, &len, APR_BLOCK_READ) == APR_SUCCESS) {
1294 chxj_dump_string(r, APLOG_MARK, "READ Data", data, len);
1296 /*--------------------------------------------------------------------*/
1298 /*--------------------------------------------------------------------*/
1300 DBG(r, "REQ[%X] append data start", TO_ADDR(r));
1301 ctx = (mod_chxj_ctx *)f->ctx;
1304 tmp = apr_palloc(r->pool, ctx->len);
1305 memcpy(tmp, ctx->buffer, ctx->len);
1307 ctx->buffer = apr_palloc(pool, ctx->len + len);
1309 memcpy(ctx->buffer, tmp, ctx->len);
1310 memcpy(&ctx->buffer[ctx->len], data, len);
1314 DBG(r, "REQ[%X] append data end", TO_ADDR(r));
1317 if (APR_BUCKET_IS_EOS(b)) {
1319 DBG(r, "REQ[%X] eos", TO_ADDR(r));
1320 /*----------------------------------------------------------------------*/
1322 /*----------------------------------------------------------------------*/
1324 cookie_lock_t *lock = NULL;
1325 ctx = (mod_chxj_ctx *)f->ctx;
1327 DBG(r, "REQ[%X] content_type=[%s]", TO_ADDR(r), r->content_type);
1328 lock = chxj_cookie_lock(r);
1330 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
1332 && (STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
1333 || STRNCASEEQ('t','T',"text/html", r->content_type, sizeof("text/html")-1))) {
1334 DBG(r, "REQ[%X] detect convert target:[%s]", TO_ADDR(r), r->content_type);
1339 tmp = apr_palloc(pool, ctx->len + 1);
1341 memset(tmp, 0, ctx->len + 1);
1342 memcpy(tmp, ctx->buffer, ctx->len);
1344 ctx->buffer = chxj_convert(r,
1345 (const char **)&tmp,
1346 (apr_size_t *)&ctx->len,
1348 user_agent, &cookie);
1352 ctx->buffer = apr_psprintf(r->pool, "\n");
1354 ctx->buffer = chxj_convert(r,
1355 (const char **)&ctx->buffer,
1356 (apr_size_t *)&ctx->len,
1358 user_agent, &cookie);
1363 && *(char *)r->content_type == 't'
1364 && strncmp(r->content_type, "text/xml", 8) == 0) {
1365 DBG(r, "REQ[%X] text/XML", TO_ADDR(r));
1373 memset(&doc, 0, sizeof(Doc));
1374 memset(&qrcode, 0, sizeof(qr_code_t));
1376 doc.parse_mode = PARSE_MODE_CHTML;
1380 qs_init_malloc(&doc);
1382 root = qs_parse_string(&doc, ctx->buffer, ctx->len);
1385 for (child = qs_get_child_node(&doc,root);
1387 child = qs_get_next_node(&doc,child)) {
1388 char *name = qs_get_node_name(&doc,child);
1389 if (strcasecmp("qrcode",name) == 0) {
1394 qs_all_free(&doc,QX_LOGMARK);
1396 r->handler = apr_psprintf(r->pool, "chxj-qrcode");
1397 chxj_qrcode_node_to_qrcode(&qrcode, root);
1398 sts = chxj_qrcode_create_image_data(&qrcode, &ctx->buffer, &ctx->len);
1400 ERR(r, "REQ[%X] qrcode create failed.", TO_ADDR(r));
1401 chxj_cookie_unlock(r, lock);
1402 DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1405 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1409 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
1411 && ( *r->content_type == 'i' || *r->content_type == 'I')
1412 && dconf->image == CHXJ_IMG_ON
1413 && strncasecmp("image/", r->content_type, 6) == 0
1414 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
1415 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
1416 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
1417 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
1418 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
1419 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
1420 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
1421 || STRCASEEQ('x','X',"x-ms-bmp", &r->content_type[6]) /* BMP */
1422 || STRCASEEQ('g','G',"gif", &r->content_type[6]))) { /* GIF */
1423 DBG(r, "REQ[%X] detect convert target:[%s]", TO_ADDR(r), r->content_type);
1427 DBG(r, "REQ[%X] ctx->len[%d]", TO_ADDR(r), (unsigned int)ctx->len);
1428 tmp = apr_palloc(pool, ctx->len + 1);
1430 memset(tmp, 0, ctx->len + 1);
1431 memcpy(tmp, ctx->buffer, ctx->len);
1433 chxj_convert_image(r,
1434 (const char **)&tmp,
1435 (apr_size_t *)&ctx->len);
1439 apr_table_unset(r->headers_out, "Content-Length");
1440 apr_table_unset(r->err_headers_out, "Content-Length");
1441 ap_set_content_length(r, (apr_off_t)ctx->len);
1445 DBG(r, "REQ[%X] call %s()", TO_ADDR(r),__func__);
1446 s_add_cookie_id_if_has_location_header(r, cookie);
1447 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1448 if (! ap_is_HTTP_REDIRECT(r->status)) {
1449 r->status = HTTP_MOVED_TEMPORARILY;
1452 if (ctx->len && ap_is_HTTP_REDIRECT(r->status)) {
1453 ctx->buffer = apr_pstrdup(pool, "");
1455 ap_set_content_length(r, (apr_off_t)ctx->len);
1457 chxj_cookie_unlock(r,lock);
1458 s_add_no_cache_headers(r, entryp);
1459 rv = pass_data_to_filter(f,
1460 (const char *)ctx->buffer,
1461 (apr_size_t)ctx->len);
1464 ctx->buffer = apr_pstrdup(pool, "");
1466 ap_set_content_length(r, (apr_off_t)ctx->len);
1467 chxj_cookie_unlock(r, lock);
1468 s_add_no_cache_headers(r, entryp);
1469 rv = pass_data_to_filter(f,
1470 (const char *)ctx->buffer,
1471 (apr_size_t)ctx->len);
1473 DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1477 DBG(r, "REQ[%X] SAVE COOKIE[%x]", TO_ADDR(r), entryp->action);
1482 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
1483 cookie_lock_t *lock = NULL;
1484 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", TO_ADDR(r));
1485 switch(spec->html_spec_type) {
1486 case CHXJ_SPEC_Chtml_1_0:
1487 case CHXJ_SPEC_Chtml_2_0:
1488 case CHXJ_SPEC_Chtml_3_0:
1489 case CHXJ_SPEC_Chtml_4_0:
1490 case CHXJ_SPEC_Chtml_5_0:
1491 case CHXJ_SPEC_Chtml_6_0:
1492 case CHXJ_SPEC_Chtml_7_0:
1493 case CHXJ_SPEC_XHtml_Mobile_1_0:
1494 case CHXJ_SPEC_Jhtml:
1495 case CHXJ_SPEC_Jxhtml:
1496 lock = chxj_cookie_lock(r);
1497 cookie = chxj_save_cookie(r);
1499 * Location Header Check to add cookie parameter.
1501 s_add_cookie_id_if_has_location_header(r, cookie);
1502 chxj_cookie_unlock(r, lock);
1503 apr_table_unset(r->headers_out, "Set-Cookie");
1504 apr_table_unset(r->err_headers_out, "Set-Cookie");
1507 case CHXJ_SPEC_iPhone2:
1508 case CHXJ_SPEC_iPhone3:
1509 case CHXJ_SPEC_iPhone4:
1514 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1515 if (! ap_is_HTTP_REDIRECT(r->status)) {
1516 r->status = HTTP_MOVED_TEMPORARILY;
1519 apr_table_setn(r->headers_out, "Content-Length", "0");
1520 s_add_no_cache_headers(r, entryp);
1521 rv = pass_data_to_filter(f, (const char *)"", (apr_size_t)0);
1526 apr_brigade_destroy(bb);
1528 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1534 * Add Cookie_id if it has location header.
1537 s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie)
1539 DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
1540 char *location_header = (char *)apr_table_get(r->headers_out, "Location");
1541 if (! location_header) {
1542 location_header = (char *)apr_table_get(r->err_headers_out, "Location");
1544 if (cookie && location_header) {
1545 DBG(r, "REQ[%X] Location Header=[%s]", TO_ADDR(r), location_header);
1546 location_header = chxj_add_cookie_parameter(r,
1549 apr_table_unset(r->headers_out, "Location");
1550 apr_table_setn(r->headers_out, "Location", location_header);
1551 DBG(r, "REQ[%X] Location Header=[%s]", TO_ADDR(r), location_header);
1552 if (!ap_is_HTTP_REDIRECT(r->status)) {
1553 r->status = HTTP_MOVED_TEMPORARILY;
1556 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1560 * It is the main loop of the input filter handler.
1564 chxj_input_handler(request_rec *r)
1566 mod_chxj_config *dconf;
1567 mod_chxj_req_config *request_conf;
1568 chxjconvrule_entry *entryp = NULL;
1569 device_table *spec = NULL;
1570 char *post_data = NULL;
1571 apr_size_t post_data_len = 0;
1575 int response_code = 0;
1577 DBG(r, "REQ[%X] start %s()",TO_ADDR(r),__func__);
1579 if (strcasecmp(r->handler, "chxj-input-handler")) {
1580 DBG(r, "REQ[%X] end %s()",TO_ADDR(r),__func__);
1583 apr_pool_create(&pool, r->pool);
1585 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1586 request_conf = chxj_get_req_config(r);
1587 user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
1589 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
1592 if (!request_conf->spec || !request_conf->user_agent) {
1593 spec = chxj_specified_device(r, user_agent);
1595 else if (request_conf->user_agent && strcmp(user_agent, request_conf->user_agent)) {
1596 spec = chxj_specified_device(r, user_agent);
1599 spec = request_conf->spec;
1603 /*-------------------------------------------------------------------------*/
1604 /* already setup entryp if request_conf->user_agent is not null */
1605 /*-------------------------------------------------------------------------*/
1606 if (request_conf->user_agent) {
1607 entryp = request_conf->entryp;
1610 entryp = chxj_apply_convrule(r, dconf->convrules);
1613 post_data = apr_pstrdup(pool, "");
1614 if (ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK) == OK) {
1615 if (ap_should_client_block(r)) {
1616 while (post_data_len < CHXJ_POST_MAX) {
1619 int read_bytes = ap_get_client_block(r, buffer, BUFSZ-1);
1620 if (read_bytes<=0) {
1623 buffer[read_bytes] = '\0';
1624 post_data = apr_pstrcat(pool, post_data, buffer, NULL);
1625 post_data_len += read_bytes;
1634 if (post_data_len > 0) {
1635 post_data = chxj_input_convert(r, (const char**)&post_data, (apr_size_t*)&post_data_len, entryp, spec);
1636 DBG(r, "REQ[%X] (in:exchange)POSTDATA:[%s]", TO_ADDR(r),post_data);
1640 if (dconf->forward_url_base) {
1641 url_path = apr_psprintf(pool, "%s%s", dconf->forward_url_base, r->uri);
1644 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);
1647 url_path = apr_pstrcat(pool, url_path, "?", r->args, NULL);
1649 DBG(r, "REQ[%X] ==> new url_path:[%s]", TO_ADDR(r),url_path);
1652 apr_table_setn(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP, r->connection->remote_ip);
1653 char *x_client_type = (char *)apr_table_get(r->headers_in, "X-Client-Type");
1654 if (x_client_type) {
1655 apr_table_setn(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_TYPE, x_client_type); /* for mod_cidr_lookup */
1658 apr_table_unset(r->headers_in, "X-Client-Type");
1660 apr_table_unset(r->headers_in, "Content-Length");
1661 apr_table_setn(r->headers_in, "Content-Length", apr_psprintf(pool, "%" APR_SIZE_T_FMT, post_data_len));
1662 response = chxj_serf_post(r, pool, url_path, post_data, post_data_len, 1, &res_len, &response_code);
1665 if ((chunked = (char *)apr_table_get(r->headers_out, "Transfer-Encoding")) != NULL) {
1666 if (strcasecmp(chunked, "chunked") == 0) {
1668 apr_table_unset(r->headers_out, "Transfer-Encoding");
1671 if (ap_is_HTTP_ERROR(response_code)) {
1672 DBG(r, "REQ[%X] end %s() (HTTP-ERROR received. response code:[%d])", TO_ADDR(r), __func__,response_code);
1673 return response_code;
1677 apr_pool_create(&wpool, r->pool);
1678 apr_bucket_brigade *bb;
1681 conn_rec *c = r->connection;
1683 bb = apr_brigade_create(wpool, c->bucket_alloc);
1684 e = apr_bucket_transient_create(response, res_len, c->bucket_alloc);
1685 APR_BRIGADE_INSERT_TAIL(bb, e);
1686 e = apr_bucket_eos_create(c->bucket_alloc);
1687 APR_BRIGADE_INSERT_TAIL(bb, e);
1688 if ((rv = ap_pass_brigade(r->output_filters, bb)) != APR_SUCCESS) {
1689 ERR(r, "REQ[%X] %s:%d failed ap_pass_brigade()", TO_ADDR(r), APLOG_MARK);
1692 apr_brigade_cleanup(bb);
1695 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1699 static mod_chxj_global_config *
1700 chxj_global_config_create(apr_pool_t *pool, server_rec *s)
1702 mod_chxj_global_config *conf;
1704 SDBG(s, "start chxj_global_config_create()");
1706 /*--------------------------------------------------------------------------*/
1707 /* allocate an own subpool which survives server restarts */
1708 /*--------------------------------------------------------------------------*/
1709 conf = (mod_chxj_global_config *)apr_palloc(pool,
1710 sizeof(mod_chxj_global_config));
1712 conf->cookie_db_lock = NULL;
1714 SDBG(s, "end chxj_global_config_create()");
1721 * initialize chxj module
1724 chxj_init_module(apr_pool_t *p,
1725 apr_pool_t *UNUSED(plog),
1726 apr_pool_t *UNUSED(ptemp),
1732 SDBG(s, "start chxj_init_module()");
1734 apr_pool_userdata_get(&user_data, CHXJ_MOD_CONFIG_KEY, s->process->pool);
1736 if (user_data == NULL) {
1739 * dummy user_data set.
1741 apr_pool_userdata_set(
1743 CHXJ_MOD_CONFIG_KEY,
1744 apr_pool_cleanup_null,
1746 SDBG(s, "end chxj_init_module()");
1750 ap_add_version_component(p, CHXJ_VERSION_PREFIX CHXJ_VERSION);
1752 if ((rv = apr_proc_mutex_create(&global_cookie_mutex, NULL, APR_LOCK_FCNTL, s->process->pool)) != APR_SUCCESS) {
1754 SERR(s, "%s:%d end chxj_init_module(). mutex create failure.(%d:%s)",APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1755 return HTTP_INTERNAL_SERVER_ERROR;
1758 SDBG(s, "end chxj_init_module()");
1765 chxj_child_init(apr_pool_t *UNUSED(p), server_rec *s)
1768 SDBG(s, "start chxj_child_init()");
1769 if ((rv = apr_proc_mutex_child_init(&global_cookie_mutex, NULL, s->process->pool)) != APR_SUCCESS) {
1771 SERR(s, "%s:%d ERROR end chxj_init_module(). mutex create failure.(%d:%s)", APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1773 SDBG(s, "end chxj_child_init()");
1778 * A set structure of each server is generated.
1784 chxj_config_server_create(apr_pool_t *p, server_rec *s)
1786 mod_chxj_global_config *gc;
1788 gc = chxj_global_config_create(p,s);
1795 chxj_translate_name(request_rec *r)
1797 DBG(r, "REQ[%X] =======================================================================", TO_ADDR(r));
1798 DBG(r, "REQ[%X] ", TO_ADDR(r));
1799 DBG(r, "REQ[%X] START REQUEST (uri:[%s] args:[%s])", TO_ADDR(r), r->unparsed_uri, r->args ? r->args : "");
1800 DBG(r, "REQ[%X] METHOD [%s]", TO_ADDR(r), r->method);
1801 DBG(r, "REQ[%X] ", TO_ADDR(r));
1802 DBG(r, "REQ[%X] =======================================================================", TO_ADDR(r));
1804 mod_chxj_config *dconf;
1805 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1807 if (dconf->image_rewrite ==CHXJ_IMG_REWRITE_ON ){
1808 if(r->args && strcasecmp(r->args,"rewrite") == 0){
1809 DBG(r, "image rewrite is ON [%s] - %s", dconf->image_rewrite_url ,r->content_type);
1810 r->filename = apr_pstrcat(r->pool,dconf->image_rewrite_url,NULL);
1817 return chxj_trans_name(r);
1825 chxj_insert_filter(request_rec *r)
1829 mod_chxj_config *dconf;
1830 mod_chxj_req_config *req_conf;
1831 chxjconvrule_entry *entryp;
1836 DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
1838 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1839 req_conf = chxj_get_req_config(r);
1841 /* we get User-Agent from CHXJ_HTTP_USER_AGENT header if any */
1842 user_agent = (char *)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
1844 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
1847 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
1849 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
1850 DBG(r, "REQ[%X] detect multipart/form-data ==> no target", TO_ADDR(r));
1851 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1856 if (!req_conf->spec || !req_conf->user_agent) {
1857 spec = chxj_specified_device(r, user_agent);
1859 else if (req_conf->user_agent && strcmp(user_agent, req_conf->user_agent)) {
1860 spec = chxj_specified_device(r, user_agent);
1863 spec = req_conf->spec;
1866 req_conf = chxj_get_req_config(r);
1867 /*-------------------------------------------------------------------------*/
1868 /* already setup entryp if request_conf->user_agent is not null */
1869 /*-------------------------------------------------------------------------*/
1870 if (req_conf->user_agent) {
1871 entryp = req_conf->entryp;
1874 entryp = chxj_apply_convrule(r, dconf->convrules);
1876 if (!entryp && dconf->image != CHXJ_IMG_ON) {
1877 DBG(r, "REQ[%X] entryp is NULL and ChxjImageEngine Off", TO_ADDR(r));
1878 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1881 ctx = apr_palloc(r->pool, sizeof(*ctx));
1882 memset(ctx, 0, sizeof(*ctx));
1883 if ((rv = apr_pool_create(&ctx->pool, r->pool)) != APR_SUCCESS) {
1884 ERR(r, "REQ[%X] %s:%d: failed: new pool create. rv:[%d]", TO_ADDR(r),__FILE__,__LINE__,rv);
1885 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1888 ctx->entryp = entryp;
1890 ctx->buffer = apr_palloc(ctx->pool, 1);
1893 if (dconf->image != CHXJ_IMG_ON
1895 || ( !(entryp->action & CONVRULE_ENGINE_ON_BIT)
1896 && !(entryp->action & CONVRULE_COOKIE_ONLY_BIT)
1897 && !(entryp->action & CONVRULE_EMOJI_ONLY_BIT)
1899 DBG(r,"REQ[%X] EngineOff and ChxjImageEngine Off and No EmojiOnly", TO_ADDR(r));
1900 DBG(r,"REQ[%X] end %s()", TO_ADDR(r),__func__);
1903 switch(spec->html_spec_type) {
1904 case CHXJ_SPEC_Chtml_1_0:
1905 case CHXJ_SPEC_Chtml_2_0:
1906 case CHXJ_SPEC_Chtml_3_0:
1907 case CHXJ_SPEC_Chtml_4_0:
1908 case CHXJ_SPEC_Chtml_5_0:
1909 case CHXJ_SPEC_Chtml_6_0:
1910 case CHXJ_SPEC_Chtml_7_0:
1911 case CHXJ_SPEC_XHtml_Mobile_1_0:
1912 case CHXJ_SPEC_Hdml:
1913 case CHXJ_SPEC_Jhtml:
1914 case CHXJ_SPEC_Jxhtml:
1915 case CHXJ_SPEC_iPhone2:
1916 case CHXJ_SPEC_iPhone3:
1917 case CHXJ_SPEC_iPhone4:
1921 DBG(r, "REQ[%X] end %s() Unknown spec type(%d).", TO_ADDR(r), __func__,spec->html_spec_type);
1926 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
1927 req_conf->f = ap_add_output_filter("chxj_output_filter", ctx, r, r->connection);
1928 DBG(r, "REQ[%X] added Output Filter", TO_ADDR(r));
1931 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1936 chxj_remove_filter(request_rec *r)
1938 mod_chxj_req_config *req_conf;
1940 DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
1941 req_conf = chxj_get_req_config(r);
1942 if (req_conf && req_conf->f) {
1943 ap_remove_output_filter(req_conf->f);
1944 DBG(r, "REQ[%X] REMOVE Output Filter", TO_ADDR(r));
1946 DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
1951 * The hook is registered.
1956 chxj_register_hooks(apr_pool_t *UNUSED(p))
1958 ap_hook_post_config(chxj_init_module,
1961 APR_HOOK_REALLY_FIRST);
1962 ap_hook_child_init(chxj_child_init,
1965 APR_HOOK_REALLY_FIRST);
1966 ap_register_output_filter (
1967 "chxj_output_filter",
1971 ap_hook_insert_filter(chxj_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
1972 ap_hook_handler(chxj_img_conv_format_handler, NULL, NULL, APR_HOOK_MIDDLE);
1973 ap_hook_handler(chxj_qr_code_handler, NULL, NULL, APR_HOOK_MIDDLE);
1974 ap_hook_handler(chxj_input_handler, NULL, NULL, APR_HOOK_MIDDLE);
1976 ap_hook_handler(chxj_image_redirect_handler, NULL, NULL, APR_HOOK_MIDDLE);
1978 ap_hook_translate_name(chxj_translate_name, NULL, NULL, APR_HOOK_MIDDLE);
1979 ap_hook_fixups(chxj_headers_fixup, NULL, NULL, APR_HOOK_FIRST);
1985 * A set structure according to the directory is generated.
1991 chxj_create_per_dir_config(apr_pool_t *p, char *arg)
1993 mod_chxj_config *conf;
1995 conf = apr_pcalloc(p, sizeof(mod_chxj_config));
1996 conf->device_data_file = NULL;
1997 conf->devices = NULL;
1998 conf->emoji_data_file = NULL;
2000 conf->emoji_tail = NULL;
2001 conf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_NONE;
2002 conf->image = CHXJ_IMG_NONE;
2003 conf->image_cache_dir = apr_psprintf(p, "%s",DEFAULT_IMAGE_CACHE_DIR);
2004 conf->image_cache_limit = 0;
2005 conf->server_side_encoding = NULL;
2006 conf->cookie_db_dir = NULL;
2007 conf->cookie_timeout = 0;
2008 conf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
2009 conf->cookie_lazy_mode = 0;
2010 conf->cookie_dbm_type = NULL;
2012 conf->detect_device_type = CHXJ_ADD_DETECT_DEVICE_TYPE_NONE;
2014 #if defined(USE_MYSQL_COOKIE)
2015 memset((void *)&conf->mysql, 0, sizeof(mysql_t));
2016 conf->mysql.port = MYSQL_PORT;
2017 conf->mysql.host = NULL;
2019 #if defined(USE_MEMCACHE_COOKIE)
2020 memset((void *)&conf->memcache, 0, sizeof(memcache_t));
2021 conf->memcache.host = NULL;
2022 conf->memcache.port = 0;
2024 conf->forward_url_base = NULL;
2025 conf->forward_server_ip = NULL;
2026 conf->allowed_cookie_domain = NULL;
2027 conf->post_log = NULL;
2033 conf->dir = apr_pcalloc(p, strlen(arg)+1);
2034 memset(conf->dir, 0, strlen(arg)+1);
2035 strcpy(conf->dir, arg);
2037 conf->convrules = apr_array_make(p, 2, sizeof(chxjconvrule_entry));
2039 /* Default is copyleft */
2040 conf->image_copyright = NULL;
2042 conf->image_rewrite = CHXJ_IMG_REWRITE_NONE;
2043 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_NONE;
2044 conf->image_rewrite_url = NULL;
2046 conf->use_emoji_image = 0;
2047 conf->emoji_image_url = NULL;
2054 * Merge per-directory CHXJ configurations
2057 chxj_merge_per_dir_config(apr_pool_t *p, void *basev, void *addv)
2059 mod_chxj_config *base;
2060 mod_chxj_config *add;
2061 mod_chxj_config *mrg;
2063 base = (mod_chxj_config *)basev;
2064 add = (mod_chxj_config *)addv;
2065 mrg = (mod_chxj_config *)apr_palloc(p, sizeof(mod_chxj_config));
2067 mrg->device_data_file = NULL;
2068 mrg->devices = NULL;
2069 mrg->emoji_data_file = NULL;
2070 mrg->image = CHXJ_IMG_NONE;
2071 mrg->image_cache_dir = NULL;
2072 mrg->image_copyright = NULL;
2073 mrg->image_cache_limit = 0;
2075 mrg->emoji_tail = NULL;
2076 mrg->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_NONE;
2077 mrg->new_line_type = NLTYPE_NIL;
2078 mrg->forward_url_base = NULL;
2079 mrg->forward_server_ip = NULL;
2080 mrg->allowed_cookie_domain = NULL;
2081 mrg->post_log = NULL;
2082 mrg->cookie_dbm_type = NULL;
2084 mrg->device_keys = NULL;
2085 mrg->device_hash = NULL;
2087 mrg->dir = apr_pstrdup(p, add->dir);
2089 if (! add->device_data_file) {
2090 mrg->devices = base->devices;
2091 mrg->device_data_file = apr_pstrdup(p, base->device_data_file);
2094 mrg->devices = add->devices;
2095 mrg->device_data_file = apr_pstrdup(p, add->device_data_file);
2098 if (! add->emoji_data_file) {
2099 mrg->emoji = base->emoji;
2100 mrg->emoji_tail = base->emoji_tail;
2101 mrg->emoji_data_file = apr_pstrdup(p, base->emoji_data_file);
2104 mrg->emoji = add->emoji;
2105 mrg->emoji_tail = add->emoji_tail;
2106 mrg->emoji_data_file = apr_pstrdup(p, add->emoji_data_file);
2109 if (add->image == CHXJ_IMG_NONE) {
2110 mrg->image = base->image;
2113 mrg->image = add->image;
2116 if (strcasecmp(add->image_cache_dir ,DEFAULT_IMAGE_CACHE_DIR)==0) {
2117 mrg->image_cache_dir = apr_pstrdup(p, base->image_cache_dir);
2120 mrg->image_cache_dir = apr_pstrdup(p, add->image_cache_dir);
2123 if (add->image_cache_limit) {
2124 mrg->image_cache_limit = add->image_cache_limit;
2127 mrg->image_cache_limit = base->image_cache_limit;
2130 if (add->image_copyright)
2131 mrg->image_copyright = apr_pstrdup(p, add->image_copyright);
2133 mrg->image_copyright = apr_pstrdup(p, base->image_copyright);
2135 if (add->server_side_encoding) {
2136 mrg->server_side_encoding = apr_pstrdup(p, add->server_side_encoding);
2139 if (base->server_side_encoding) {
2140 mrg->server_side_encoding = apr_pstrdup(p, base->server_side_encoding);
2143 mrg->server_side_encoding = apr_pstrdup(p, DEFAULT_SERVER_SIDE_ENCODING);
2146 mrg->convrules = apr_array_append(p, add->convrules, base->convrules);
2148 if (add->cookie_db_dir) {
2149 mrg->cookie_db_dir = apr_pstrdup(p, add->cookie_db_dir);
2152 if (base->cookie_db_dir) {
2153 mrg->cookie_db_dir = apr_pstrdup(p, base->cookie_db_dir);
2156 mrg->cookie_db_dir = NULL;
2159 if (add->cookie_timeout) {
2160 mrg->cookie_timeout = add->cookie_timeout;
2163 if (base->cookie_db_dir) {
2164 mrg->cookie_timeout = base->cookie_timeout;
2167 mrg->cookie_timeout = 0;
2170 #if defined(USE_MYSQL_COOKIE)
2171 if (add->mysql.host) {
2172 mrg->mysql.host = apr_pstrdup(p, add->mysql.host);
2174 else if (base->mysql.host) {
2175 mrg->mysql.host = apr_pstrdup(p, base->mysql.host);
2178 mrg->mysql.host = NULL;
2180 if (add->mysql.port) {
2181 mrg->mysql.port = add->mysql.port;
2183 else if (base->mysql.port) {
2184 mrg->mysql.port = base->mysql.port;
2187 mrg->mysql.port = 0;
2190 if (add->mysql.database) {
2191 mrg->mysql.database = apr_pstrdup(p, add->mysql.database);
2193 else if (base->mysql.database) {
2194 mrg->mysql.database = apr_pstrdup(p, base->mysql.database);
2197 mrg->mysql.database = NULL;
2200 if (add->mysql.username) {
2201 mrg->mysql.username = apr_pstrdup(p, add->mysql.username);
2203 else if (base->mysql.username) {
2204 mrg->mysql.username = apr_pstrdup(p, base->mysql.username);
2207 mrg->mysql.username = NULL;
2210 if (add->mysql.password) {
2211 mrg->mysql.password = apr_pstrdup(p, add->mysql.password);
2213 else if (base->mysql.password) {
2214 mrg->mysql.password = apr_pstrdup(p, base->mysql.password);
2217 mrg->mysql.password = NULL;
2220 if (add->mysql.tablename) {
2221 mrg->mysql.tablename = apr_pstrdup(p, add->mysql.tablename);
2223 else if (base->mysql.tablename) {
2224 mrg->mysql.tablename = apr_pstrdup(p, base->mysql.tablename);
2227 mrg->mysql.tablename = NULL;
2230 if (add->mysql.socket_path) {
2231 mrg->mysql.socket_path = apr_pstrdup(p, add->mysql.socket_path);
2233 else if (base->mysql.socket_path) {
2234 mrg->mysql.socket_path = apr_pstrdup(p, base->mysql.socket_path);
2237 mrg->mysql.socket_path = NULL;
2240 if (add->mysql.charset) {
2241 mrg->mysql.charset = apr_pstrdup(p, add->mysql.charset);
2243 else if (base->mysql.charset) {
2244 mrg->mysql.charset = apr_pstrdup(p, base->mysql.charset);
2247 mrg->mysql.charset = NULL;
2250 #if defined(USE_MEMCACHE_COOKIE)
2251 if (add->memcache.host) {
2252 mrg->memcache.host = apr_pstrdup(p, add->memcache.host);
2254 else if (base->memcache.host) {
2255 mrg->memcache.host = apr_pstrdup(p, base->memcache.host);
2258 mrg->memcache.host = NULL;
2260 if (add->memcache.port) {
2261 mrg->memcache.port = add->memcache.port;
2263 else if (base->memcache.port) {
2264 mrg->memcache.port = base->memcache.port;
2267 mrg->memcache.port = 0;
2270 if (add->cookie_store_type) {
2271 mrg->cookie_store_type = add->cookie_store_type;
2273 else if (base->cookie_store_type) {
2274 mrg->cookie_store_type = base->cookie_store_type;
2277 mrg->cookie_store_type = COOKIE_STORE_TYPE_NONE;
2279 if (add->cookie_lazy_mode) {
2280 mrg->cookie_lazy_mode = add->cookie_lazy_mode;
2282 else if (base->cookie_lazy_mode) {
2283 mrg->cookie_lazy_mode = base->cookie_lazy_mode;
2286 mrg->cookie_lazy_mode = 0;
2288 if (add->new_line_type) {
2289 mrg->new_line_type = add->new_line_type;
2291 else if (base->new_line_type) {
2292 mrg->new_line_type = base->new_line_type;
2295 mrg->new_line_type = NLTYPE_NIL;
2298 if (add->forward_url_base) {
2299 mrg->forward_url_base = add->forward_url_base;
2301 else if (base->forward_url_base) {
2302 mrg->forward_url_base = base->forward_url_base;
2305 if (add->allowed_cookie_domain) {
2306 mrg->allowed_cookie_domain = add->allowed_cookie_domain;
2309 mrg->allowed_cookie_domain = base->allowed_cookie_domain;
2311 if (add->post_log) {
2312 mrg->post_log = add->post_log;
2315 mrg->post_log = base->post_log;
2317 if (add->cookie_dbm_type) {
2318 mrg->cookie_dbm_type = add->cookie_dbm_type;
2321 mrg->cookie_dbm_type = base->cookie_dbm_type;
2324 if (add->imode_emoji_color == CHXJ_IMODE_EMOJI_COLOR_NONE) {
2325 mrg->imode_emoji_color = base->imode_emoji_color;
2328 mrg->imode_emoji_color = add->imode_emoji_color;
2331 if (add->detect_device_type == CHXJ_ADD_DETECT_DEVICE_TYPE_NONE) {
2332 mrg->detect_device_type = base->detect_device_type;
2335 mrg->detect_device_type = add->detect_device_type;
2338 if (add->device_keys) {
2339 mrg->device_keys = add->device_keys;
2342 mrg->device_keys = base->device_keys;
2345 if (add->device_hash) {
2346 mrg->device_hash = add->device_hash;
2349 mrg->device_hash = base->device_hash;
2352 if (add->image_rewrite == CHXJ_IMG_REWRITE_NONE){
2353 mrg->image_rewrite = base->image_rewrite;
2356 mrg->image_rewrite = add->image_rewrite;
2359 if (add->image_rewrite_url) {
2360 mrg->image_rewrite_url = add->image_rewrite_url;
2363 mrg->image_rewrite_url = base->image_rewrite_url;
2366 if (add->image_rewrite_mode == CHXJ_IMG_REWRITE_MODE_NONE){
2367 mrg->image_rewrite_mode = base->image_rewrite_mode;
2370 mrg->image_rewrite_mode = add->image_rewrite_mode;
2373 if (add->use_emoji_image != 1){
2374 mrg->use_emoji_image = base->use_emoji_image;
2377 mrg->use_emoji_image = add->use_emoji_image;
2380 if (add->emoji_image_url){
2381 mrg->emoji_image_url = add->emoji_image_url;
2384 mrg->emoji_image_url = base->emoji_image_url;
2392 chxj_command_parse_take5(
2405 for (;*strp == ' '||*strp == '\t'; strp++) ;
2415 for (; *strp != '\0'; strp++) {
2416 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2417 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2422 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2423 || (isquoted && *strp == '"'))
2437 for (;*strp == ' '||*strp == '\t'; strp++) ;
2446 for (; *strp != '\0'; strp++) {
2447 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2448 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2453 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2454 || (isquoted && *strp == '"'))
2467 for (;*strp == ' '||*strp == '\t'; strp++);
2475 for (; *strp != '\0'; strp++) {
2476 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2477 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2482 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2483 || (isquoted && *strp == '"'))
2495 for (;*strp == ' '||*strp == '\t'; strp++);
2503 for (; *strp != '\0'; strp++) {
2504 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2505 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2510 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2511 || (isquoted && *strp == '"'))
2522 for (;*strp == ' '||*strp == '\t'; strp++);
2530 for (; *strp != '\0'; strp++) {
2531 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2532 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2537 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2538 || (isquoted && *strp == '"'))
2548 * The device definition file is loaded.
2550 * @param arg [i] The name of the device definition file is specified.
2551 * @param mconfig [i/o] The pointer to a set structure is specified.
2555 cmd_load_device_data(cmd_parms *parms, void *mconfig, const char *arg)
2557 mod_chxj_config *conf;
2562 if (strlen(arg) > 256)
2563 return "mod_chxj: device data filename too long.";
2565 conf = (mod_chxj_config *)mconfig;
2566 conf->device_data_file = apr_pstrdup(parms->pool, arg);
2568 qs_init_malloc(&doc);
2569 qs_init_root_node(&doc);
2571 qs_parse_file((Doc *)&doc, (const char *)arg);
2572 chxj_load_device_data(&doc,parms->pool, conf);
2573 qs_all_free(&doc, QX_LOGMARK);
2580 * Device definition information is loaded.
2583 * @param arg [i] The name of the device definition file is specified.
2584 * @param mconfig [i/o] The pointer to a set structure is specified.
2588 cmd_load_emoji_data(cmd_parms *parms, void *mconfig, const char *arg)
2590 mod_chxj_config *conf;
2597 if (strlen(arg) > 256)
2598 return "mod_chxj: emoji data filename too long.";
2600 conf = (mod_chxj_config *)mconfig;
2601 conf->emoji_data_file = apr_pstrdup(parms->pool, arg);
2602 qs_init_malloc(&doc);
2603 qs_init_root_node(&doc);
2605 qs_parse_file((Doc *)&doc, (const char *)arg);
2607 rtn = chxj_load_emoji_data(&doc,parms->pool, conf);
2609 qs_all_free(&doc, QX_LOGMARK);
2617 cmd_set_image_engine(cmd_parms * UNUSED(parms), void *mconfig, const char *arg)
2619 mod_chxj_config *conf;
2624 if (strlen(arg) > 256)
2625 return "image uri is too long.";
2627 conf = (mod_chxj_config*)mconfig;
2628 if (strcasecmp("ON", arg) == 0) {
2629 conf->image = CHXJ_IMG_ON;
2632 conf->image = CHXJ_IMG_OFF;
2640 cmd_set_image_cache_dir(cmd_parms *parms, void *mconfig, const char *arg)
2642 mod_chxj_config *conf;
2647 if (strlen(arg) > 256)
2648 return "cache dir name is too long.";
2651 apr_status_t res = apr_stat(&info,arg,APR_FINFO_TYPE,parms->pool);
2652 if(res != APR_SUCCESS){
2653 return apr_psprintf(parms->pool,"ChxjImageCacheDir [%s]: not found ",arg);
2656 if(info.filetype != APR_DIR){
2657 return apr_psprintf(parms->pool,"ChxjImageCacheDir [%s]: is not directory ",arg);
2661 conf = (mod_chxj_config *)mconfig;
2662 conf->image_cache_dir = apr_pstrdup(parms->pool, arg);
2669 cmd_set_image_cache_limit(cmd_parms *parms, void *mconfig, const char *arg)
2671 mod_chxj_config *conf;
2676 if (strlen(arg) > IMAGE_CACHE_LIMIT_FMT_LEN)
2677 return "cache size is too long.";
2679 conf = (mod_chxj_config *)mconfig;
2682 * I use strtol function because strtoul is not portable function.
2684 conf->image_cache_limit = (unsigned long)strtol(arg, NULL, 10);
2687 return apr_psprintf(parms->pool, "ChxjImageCacheLimit invalid value [%s] errno:[%d]", arg, errno);
2689 return apr_psprintf(parms->pool, "ChxjImageCacheLimit Out of range [%s] errno:[%d]", arg, errno);
2698 cmd_set_image_copyright(cmd_parms *parms, void *mconfig, const char *arg)
2700 mod_chxj_config *conf;
2705 if (strlen(arg) > 256)
2706 return "Copyright Flag is too long.";
2708 conf = (mod_chxj_config *)mconfig;
2709 conf->image_copyright = apr_pstrdup(parms->pool, arg);
2716 cmd_convert_rule(cmd_parms *cmd, void *mconfig, const char *arg)
2720 mod_chxj_config *dconf;
2721 chxjconvrule_entry *newrule;
2731 dconf = (mod_chxj_config *)mconfig;
2733 if (strlen(arg) > 4096)
2734 return "mod_chxj: ChxjConvertRule: is too long.";
2736 dconf = (mod_chxj_config *)mconfig;
2737 if (dconf->convrules == NULL)
2738 dconf->convrules = apr_array_make(cmd->pool,
2740 sizeof(chxjconvrule_entry));
2742 newrule = apr_array_push(dconf->convrules);
2745 newrule->action = 0;
2747 if (chxj_command_parse_take5(arg, &prm1, &prm2, &prm3, &prm4, &prm5))
2748 return "ChxjConvertRule: bad argument line";
2750 newrule->pattern = apr_pstrdup(cmd->pool, prm1);
2754 if ((action = apr_strtok(prm2, ",", &pstate)) == NULL)
2760 if (strcasecmp(CONVRULE_ENGINE_ON_CMD, action) == 0) {
2761 newrule->action |= CONVRULE_ENGINE_ON_BIT;
2764 if (strcasecmp(CONVRULE_ENGINE_OFF_CMD, action) == 0) {
2765 newrule->action |= CONVRULE_ENGINE_OFF_BIT;
2768 if (strcasecmp(CONVRULE_EMOJI_ONLY_CMD, action) == 0) {
2769 newrule->action |= CONVRULE_EMOJI_ONLY_BIT;
2772 if (strcasecmp(CONVRULE_ENVINFO_ONLY_CMD, action) == 0) {
2773 newrule->action |= CONVRULE_ENVINFO_ONLY_BIT;
2779 if (strcasecmp(CONVRULE_OVERWRITE_X_CLIENT_TYPE_CMD, action) == 0) {
2780 newrule->action |= CONVRULE_OVERWRITE_X_CLIENT_TYPE_BIT;
2786 if (strcasecmp(CONVRULE_COOKIE_ON_CMD, action) == 0) {
2787 newrule->action |= CONVRULE_COOKIE_ON_BIT;
2789 else if (strcasecmp(CONVRULE_COOKIE_OFF_CMD, action) == 0) {
2790 newrule->action &= (0xffffffff ^ CONVRULE_COOKIE_ON_BIT);
2792 else if (strcasecmp(CONVRULE_CSS_ON_CMD, action) == 0) {
2793 newrule->action |= CONVRULE_CSS_ON_BIT;
2795 else if (strcasecmp(CONVRULE_CSS_OFF_CMD, action) == 0) {
2796 newrule->action &= (0xffffffff ^ CONVRULE_CSS_ON_BIT);
2798 else if (strcasecmp(CONVRULE_COOKIE_ONLY_CMD, action) == 0) {
2799 newrule->action |= CONVRULE_COOKIE_ONLY_BIT;
2805 if (strcasecmp(CONVRULE_JRCONV_OFF_CMD, action) == 0) {
2806 newrule->action |= CONVRULE_JRCONV_OFF_BIT;
2812 if (strcasecmp(CONVRULE_NOCACHE_ON_CMD, action) == 0) {
2813 newrule->action |= CONVRULE_NOCACHE_ON_BIT;
2819 if (strcasecmp(CONVRULE_QSCONV_OFF_CMD, action) == 0) {
2820 newrule->action |= CONVRULE_QSCONV_OFF_BIT;
2826 if (strcasecmp(CONVRULE_Z2H_ON_CMD, action) == 0) {
2827 newrule->action |= CONVRULE_Z2H_ON_BIT;
2830 if (strcasecmp(CONVRULE_Z2H_OFF_CMD, action) == 0) {
2831 newrule->action |= CONVRULE_Z2H_OFF_BIT;
2834 if (strcasecmp(CONVRULE_Z2H_ALPHA_ON_CMD, action) == 0) {
2835 newrule->action |= CONVRULE_Z2H_ALPHA_ON_BIT;
2838 if (strcasecmp(CONVRULE_Z2H_ALPHA_OFF_CMD, action) == 0) {
2839 newrule->action |= CONVRULE_Z2H_ALPHA_OFF_BIT;
2842 if (strcasecmp(CONVRULE_Z2H_NUM_ON_CMD, action) == 0) {
2843 newrule->action |= CONVRULE_Z2H_NUM_ON_BIT;
2846 if (strcasecmp(CONVRULE_Z2H_NUM_OFF_CMD, action) == 0) {
2847 newrule->action |= CONVRULE_Z2H_NUM_OFF_BIT;
2850 if (strcasecmp(CONVRULE_Z2H_ALL_ON_CMD, action) == 0) {
2851 newrule->action |= CONVRULE_Z2H_ON_BIT | CONVRULE_Z2H_ALPHA_ON_BIT | CONVRULE_Z2H_NUM_ON_BIT;
2854 if (strcasecmp(CONVRULE_Z2H_NUM_OFF_CMD, action) == 0) {
2855 newrule->action |= CONVRULE_Z2H_OFF_BIT | CONVRULE_Z2H_ALPHA_OFF_BIT | CONVRULE_Z2H_NUM_OFF_BIT;
2866 newrule->flags |= CONVRULE_FLAG_NOTMATCH;
2870 mode = AP_REG_EXTENDED;
2871 if ((regexp = ap_pregcomp((apr_pool_t *)cmd->pool, (const char *)pp, mode)) == NULL)
2872 return "RewriteRule: cannot compile regular expression ";
2874 newrule->regexp = regexp;
2876 newrule->encoding = apr_pstrdup(cmd->pool, prm3);
2878 newrule->encoding = apr_pstrdup(cmd->pool, "none");
2880 newrule->pc_flag = CONVRULE_PC_FLAG_OFF_BIT;
2882 if (strcasecmp(CONVRULE_PC_FLAG_ON_CMD, prm4) == 0)
2883 newrule->pc_flag = CONVRULE_PC_FLAG_ON_BIT;
2885 newrule->user_agent = NULL;
2887 newrule->user_agent = apr_pstrdup(cmd->pool, prm5);
2899 mod_chxj_config *dconf;
2902 if (strlen(arg) > 4096)
2903 return "mod_chxj: ChxjCookieDir is too long.";
2905 dconf = (mod_chxj_config *)mconfig;
2907 dconf->cookie_db_dir = apr_pstrdup(cmd->pool, arg);
2914 cmd_set_cookie_timeout(
2915 cmd_parms *UNUSED(cmd),
2919 mod_chxj_config *dconf;
2921 if (strlen(arg) > 4096)
2922 return "mod_chxj: ChxjCookieTimeout is too long.";
2924 if (chxj_chk_numeric(arg) != 0)
2925 return "mod_chxj: ChxjCookieTimeout is not numeric.";
2927 dconf = (mod_chxj_config *)mconfig;
2929 dconf->cookie_timeout = atoi(arg);
2935 #if defined(USE_MYSQL_COOKIE)
2937 cmd_set_cookie_mysql_database(
2942 mod_chxj_config *dconf;
2944 if (strlen(arg) > 255)
2945 return "mod_chxj: ChxjCookieMysqlDatabase is too long.";
2947 dconf = (mod_chxj_config *)mconfig;
2949 dconf->mysql.database = apr_pstrdup(cmd->pool, arg);
2956 cmd_set_cookie_mysql_username(
2961 mod_chxj_config *dconf;
2963 if (strlen(arg) > 255)
2964 return "mod_chxj: ChxjCookieMysqlUsername is too long.";
2966 dconf = (mod_chxj_config *)mconfig;
2968 dconf->mysql.username = apr_pstrdup(cmd->pool, arg);
2975 cmd_set_cookie_mysql_password(
2980 mod_chxj_config *dconf;
2982 if (strlen(arg) > 255)
2983 return "mod_chxj: ChxjCookieMysqlPassword is too long.";
2985 dconf = (mod_chxj_config *)mconfig;
2987 dconf->mysql.password = apr_pstrdup(cmd->pool, arg);
2994 cmd_set_cookie_mysql_table_name(
2999 mod_chxj_config *dconf;
3001 if (strlen(arg) > 255)
3002 return "mod_chxj: ChxjCookieMysqlTableName is too long.";
3004 dconf = (mod_chxj_config *)mconfig;
3006 dconf->mysql.tablename = apr_pstrdup(cmd->pool, arg);
3012 cmd_set_cookie_mysql_port(
3013 cmd_parms *UNUSED(cmd),
3017 mod_chxj_config *dconf;
3019 if (strlen(arg) > 255)
3020 return "mod_chxj: ChxjCookieMysqlPort is too long.";
3022 dconf = (mod_chxj_config *)mconfig;
3024 if (chxj_chk_numeric(arg) != 0)
3025 return "mod_chxj: ChxjCookieMysqlPort is not numeric.";
3027 dconf = (mod_chxj_config *)mconfig;
3029 dconf->mysql.port = chxj_atoi(arg);
3036 cmd_set_cookie_mysql_host(
3041 mod_chxj_config *dconf;
3043 if (strlen(arg) > 255)
3044 return "mod_chxj: ChxjCookieMysqlHost is too long.";
3046 dconf = (mod_chxj_config *)mconfig;
3048 dconf->mysql.host = apr_pstrdup(cmd->pool, arg);
3055 cmd_set_cookie_mysql_socket_path(
3060 mod_chxj_config *dconf;
3062 if (strlen(arg) > 4096)
3063 return "mod_chxj: ChxjCookieMysqlSocketPath is too long.";
3065 dconf = (mod_chxj_config *)mconfig;
3067 dconf->mysql.socket_path = apr_pstrdup(cmd->pool, arg);
3074 cmd_set_cookie_mysql_charset(
3079 mod_chxj_config *dconf;
3081 if (strlen(arg) > 255)
3082 return "mod_chxj: ChxjCookieMysqlCharset is too long.";
3084 dconf = (mod_chxj_config *)mconfig;
3086 dconf->mysql.charset = apr_pstrdup(cmd->pool, arg);
3091 #if defined(USE_MEMCACHE_COOKIE)
3093 cmd_set_cookie_memcache_port(
3094 cmd_parms *UNUSED(cmd),
3098 mod_chxj_config *dconf;
3100 if (strlen(arg) > 255)
3101 return "mod_chxj: ChxjCookieMemcachePort is too long.";
3103 dconf = (mod_chxj_config *)mconfig;
3105 if (chxj_chk_numeric(arg) != 0)
3106 return "mod_chxj: ChxjCookieMemcachePort is not numeric.";
3108 dconf = (mod_chxj_config *)mconfig;
3110 dconf->memcache.port = (apr_port_t)chxj_atoi(arg);
3117 cmd_set_cookie_memcache_host(
3122 mod_chxj_config *dconf;
3124 if (strlen(arg) > 255)
3125 return "mod_chxj: ChxjCookieMemcacheHost is too long.";
3127 dconf = (mod_chxj_config *)mconfig;
3129 dconf->memcache.host = apr_pstrdup(cmd->pool, arg);
3136 cmd_set_cookie_lazy_mode(
3137 cmd_parms *UNUSED(cmd),
3141 mod_chxj_config *dconf;
3143 if (strlen(arg) > 255)
3144 return "mod_chxj: ChxjCookieLazyMode is too long.";
3146 dconf = (mod_chxj_config *)mconfig;
3148 if (strcasecmp("TRUE",arg) == 0) {
3149 dconf->cookie_lazy_mode = COOKIE_LAZY_ON;
3152 dconf->cookie_lazy_mode = COOKIE_LAZY_OFF;
3159 cmd_set_cookie_store_type(
3160 cmd_parms *UNUSED(cmd),
3164 mod_chxj_config *dconf;
3166 if (strlen(arg) > 255)
3167 return "mod_chxj: ChxjCookieStoreType is too long.";
3169 dconf = (mod_chxj_config *)mconfig;
3171 if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_DBM, arg) == 0) {
3172 dconf->cookie_store_type = COOKIE_STORE_TYPE_DBM;
3174 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MYSQL, arg) == 0) {
3175 dconf->cookie_store_type = COOKIE_STORE_TYPE_MYSQL;
3177 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MEMCACHE, arg) == 0) {
3178 dconf->cookie_store_type = COOKIE_STORE_TYPE_MEMCACHE;
3181 dconf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
3188 cmd_set_forward_url_base(
3193 mod_chxj_config *dconf;
3195 if (strlen(arg) > 255)
3196 return "mod_chxj: ChxjForwardUrlBase is too long.";
3198 dconf = (mod_chxj_config *)mconfig;
3200 dconf->forward_url_base = apr_pstrdup(cmd->pool, arg);
3206 cmd_set_forward_server_ip(
3211 mod_chxj_config *dconf;
3213 if (strlen(arg) > 255)
3214 return "mod_chxj: ChxjForwardServerIp is too long.";
3216 dconf = (mod_chxj_config *)mconfig;
3218 dconf->forward_server_ip = apr_pstrdup(cmd->pool, arg);
3224 cmd_allowed_cookie_domain(
3229 mod_chxj_config *dconf;
3231 if (strlen(arg) > 255)
3232 return "mod_chxj: ChxjAllowedCookieDomain is too long.";
3234 dconf = (mod_chxj_config *)mconfig;
3236 dconf->allowed_cookie_domain = apr_pstrdup(cmd->pool, arg);
3242 cmd_set_new_line_type(
3243 cmd_parms *UNUSED(cmd),
3247 mod_chxj_config *dconf;
3248 if (strlen(arg) > 255)
3249 return "mod_chxj: ChxjNewLineType is too long.";
3251 dconf = (mod_chxj_config *)mconfig;
3253 if (strcasecmp(CHXJ_NEW_LINE_TYPE_CRLF, arg) == 0) {
3254 dconf->new_line_type = NLTYPE_CRLF;
3256 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_LF, arg) == 0) {
3257 dconf->new_line_type = NLTYPE_LF;
3259 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_CR, arg) == 0) {
3260 dconf->new_line_type = NLTYPE_CR;
3262 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_NONE, arg) == 0) {
3263 dconf->new_line_type = NLTYPE_NONE;
3266 return "mod_chxj: invalid value (ChxjNewLineType)";
3277 mod_chxj_config *dconf;
3278 if (strlen(arg) > 255)
3279 return "mod_chxj: ChxjPostLogEnv is too long.";
3281 dconf = (mod_chxj_config *)mconfig;
3283 dconf->post_log = apr_pstrdup(cmd->pool, arg);
3289 cmd_cookie_dbm_type(
3294 mod_chxj_config *dconf;
3295 if (strlen(arg) > 255)
3296 return "mod_chxj: ChxjCookieDbmType is too long.";
3298 dconf = (mod_chxj_config *)mconfig;
3300 dconf->cookie_dbm_type = apr_pstrdup(cmd->pool, arg);
3306 cmd_imode_emoji_color(
3311 mod_chxj_config *dconf;
3313 if (strlen(arg) > 256)
3314 return "imode emoji color is too long.";
3316 dconf = (mod_chxj_config *)mconfig;
3317 if (strcasecmp("ON", arg) == 0) {
3318 dconf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_ON;
3320 else if(strcasecmp("AUTO",arg) == 0) {
3321 dconf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_AUTO;
3324 dconf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_OFF;
3331 cmd_add_device_data_tsv(cmd_parms *parms, void *mconfig, const char *arg)
3333 mod_chxj_config *conf;
3335 if (strlen(arg) > 256)
3336 return "mod_chxj: device tsv filename too long.";
3338 conf = (mod_chxj_config *)mconfig;
3340 conf->detect_device_type = CHXJ_ADD_DETECT_DEVICE_TYPE_TSV;
3343 apr_status_t res = apr_stat(&info,arg,APR_FINFO_TYPE,parms->pool);
3344 if(res != APR_SUCCESS){
3345 return apr_psprintf(parms->pool,"ChxjDeviceTSV [%s]: not found ",arg);
3348 if(info.filetype != APR_REG ){
3349 return apr_psprintf(parms->pool,"ChxjDeviceTSV [%s]: is not file ",arg);
3353 apr_file_open(&fp, arg, APR_READ|APR_BUFFERED, APR_OS_DEFAULT, parms->pool);
3355 chxj_load_device_tsv_data(fp,parms->pool,conf);
3362 cmd_image_rewrite(cmd_parms *parms, void *mconfig, const char *arg)
3364 mod_chxj_config *conf;
3365 if (strlen(arg) > 256){
3366 return "mod_chxj: set rewrite too long.";
3368 conf = (mod_chxj_config *)mconfig;
3369 if (strcasecmp("ON", arg) == 0) {
3370 conf->image_rewrite = CHXJ_IMG_REWRITE_ON;
3372 else if(strcasecmp("OFF",arg) == 0) {
3373 conf->image_rewrite = CHXJ_IMG_REWRITE_OFF;
3376 conf->image_rewrite = CHXJ_IMG_REWRITE_NONE;
3382 cmd_image_rewrite_url(cmd_parms *parms, void *mconfig, const char *arg)
3384 mod_chxj_config *conf;
3385 if (strlen(arg) > 256){
3386 return "mod_chxj: set rewrite url too long.";
3388 conf = (mod_chxj_config *)mconfig;
3389 conf->image_rewrite_url = apr_pstrdup(parms->pool, arg);;
3394 cmd_image_rewrite_mode(cmd_parms *parms, void *mconfig, const char *arg)
3396 mod_chxj_config *conf;
3397 if (strlen(arg) > 256){
3398 return "mod_chxj: set rewrite mode is too long.";
3401 conf = (mod_chxj_config *)mconfig;
3402 if (strcasecmp("all",arg) == 0) {
3403 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_ALL;
3405 else if (strcasecmp("user",arg) == 0) {
3406 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_USER;
3408 else if (strcasecmp("tag",arg) == 0) {
3409 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_TAG;
3412 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_NONE;
3419 cmd_use_emoji_image(cmd_parms *parms, void *mconfig, const char *arg)
3421 mod_chxj_config *conf;
3422 conf = (mod_chxj_config *)mconfig;
3423 if (strcasecmp("on", arg) == 0) {
3424 conf->use_emoji_image = 1;
3431 cmd_emoji_image_url(cmd_parms *parms, void *mconfig, const char *arg)
3433 mod_chxj_config *conf;
3434 if (strlen(arg) > 256){
3435 return "mod_chxj: set ChxjEmojiImageUrl is too long.";
3437 conf = (mod_chxj_config *)mconfig;
3438 conf->emoji_image_url = apr_pstrdup(parms->pool, arg);
3442 static const command_rec cmds[] = {
3444 "ChxjLoadDeviceData",
3445 cmd_load_device_data,
3448 "Load Device Data"),
3450 "ChxjLoadEmojiData",
3451 cmd_load_emoji_data,
3457 cmd_set_image_engine,
3460 "Convert Target URI"),
3462 "ChxjImageCacheDir",
3463 cmd_set_image_cache_dir,
3466 "Image Cache Directory"),
3468 "ChxjImageCacheLimit",
3469 cmd_set_image_cache_limit,
3472 "Image Cache Limit"),
3474 "ChxjImageCopyright",
3475 cmd_set_image_copyright,
3484 "an URL-applied regexp-pattern and a substitution URL"),
3490 "save cookie.db directory."),
3492 "ChxjCookieTimeout",
3493 cmd_set_cookie_timeout,
3496 "The compulsion time-out time of the cookie is specified. "),
3498 "ChxjCookieStoreType",
3499 cmd_set_cookie_store_type,
3502 "It specifies preserving of the cookie ahead. (DBM/MYSQL/MEMCACHE)"),
3504 "ChxjCookieLazyMode",
3505 cmd_set_cookie_lazy_mode,
3508 "OneTimeID is negligently done. (TRUE/FALSE)"),
3509 #if defined(USE_MYSQL_COOKIE)
3511 "ChxjCookieMysqlHost",
3512 cmd_set_cookie_mysql_host,
3515 "The MySQL database host used by saving Cookie"),
3517 "ChxjCookieMysqlPort",
3518 cmd_set_cookie_mysql_port,
3521 "The MySQL database port used by saving Cookie"),
3523 "ChxjCookieMysqlDatabase",
3524 cmd_set_cookie_mysql_database,
3527 "The MySQL database name used by saving Cookie"),
3529 "ChxjCookieMysqlUsername",
3530 cmd_set_cookie_mysql_username,
3533 "The MySQL username used by saving Cookie"),
3535 "ChxjCookieMysqlPassword",
3536 cmd_set_cookie_mysql_password,
3539 "The MySQL password used by saving Cookie"),
3541 "ChxjCookieMysqlTableName",
3542 cmd_set_cookie_mysql_table_name,
3545 "The MySQL table name used by saving Cookie"),
3547 "ChxjCookieMysqlSocketPath",
3548 cmd_set_cookie_mysql_socket_path,
3551 "The MySQL socket path used by saving Cookie"),
3553 "ChxjCookieMysqlCharset",
3554 cmd_set_cookie_mysql_charset,
3557 "The MySQL charset used by saving Cookie"),
3559 #if defined(USE_MEMCACHE_COOKIE)
3561 "ChxjCookieMemcacheHost",
3562 cmd_set_cookie_memcache_host,
3565 "The Memcached host used by saving Cookie"),
3567 "ChxjCookieMemcachePort",
3568 cmd_set_cookie_memcache_port,
3571 "The Memcached port used by saving Cookie"),
3575 cmd_set_new_line_type,
3578 "HTML new line type (NONE|CRLF|LF|CR). default is CRLF"),
3580 "ChxjForwardUrlBase",
3581 cmd_set_forward_url_base,
3584 "The forward url base(default: {request protocol}://{this server}:{this server port}"),
3586 "ChxjForwardServerIp",
3587 cmd_set_forward_server_ip,
3590 "The forward server ip(default: this server ip)"),
3592 "ChxjAllowedCookieDomain",
3593 cmd_allowed_cookie_domain,
3596 "Domain that permits parameter addition for cookie besides hostname.(Default:hostname Only)"),
3602 "for CustomLog directive. mod_chxj's internal POST log environment name.(Default:chxj-post-log)"),
3604 "ChxjCookieDbmType",
3605 cmd_cookie_dbm_type,
3608 "Kind of DBM used with Cookie simulator.(default|GDBM|SDBM|DB|NDBM)"),
3610 "ChxjImodeEmojiColor",
3611 cmd_imode_emoji_color,
3614 "Auto i-mode emoji color"),
3616 "ChxjAddDeviceDataTSV",
3617 cmd_add_device_data_tsv,
3620 "Additional devices TSV data"),
3629 "ChxjImageRewriteUrl",
3630 cmd_image_rewrite_url,
3633 "Set rewrite Image url"
3636 "ChxjImageRewriteMode",
3637 cmd_image_rewrite_mode,
3640 "Set rewrite Image rewrite url mode"
3643 "ChxjUseEmojiImage",
3644 cmd_use_emoji_image,
3647 "It is specified whether to use image for emoji. (Default:off)"
3650 "ChxjEmojiImageUrl",
3651 cmd_emoji_image_url,
3654 "When image is used for emoji, url with the emoji image is specified. "
3656 {NULL,{NULL},NULL,0,0,NULL},
3660 /*----------------------------------------------------------------------------*/
3661 /* Dispatch list for API hooks */
3662 /*----------------------------------------------------------------------------*/
3663 module AP_MODULE_DECLARE_DATA chxj_module = {
3664 STANDARD20_MODULE_STUFF,
3665 chxj_create_per_dir_config, /* create per-dir config structures */
3666 chxj_merge_per_dir_config, /* merge per-dir config structures */
3667 chxj_config_server_create, /* create per-server config structures */
3668 NULL, /* merge per-server config structures */
3669 cmds, /* table of config file commands */
3670 chxj_register_hooks /* register hooks */