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);
264 if (r->method_number == M_POST) {
265 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
266 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);
267 r->proxyreq = PROXYREQ_NONE;
268 r->handler = apr_psprintf(r->pool, "chxj-input-handler");
271 char *client_ip = (char *)apr_table_get(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP);
273 if (dconf->post_log) {
274 apr_table_setn(r->subprocess_env, dconf->post_log, dconf->post_log);
277 apr_table_setn(r->subprocess_env, "chxj-post-log", "chxj-post-log");
279 apr_sockaddr_t *address = NULL;
280 apr_status_t rv = apr_sockaddr_info_get(&address, ap_get_server_name(r), APR_UNSPEC, ap_get_server_port(r), 0, r->pool);
281 if (rv != APR_SUCCESS) {
283 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));
284 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
288 if (dconf->forward_server_ip) {
289 addr = dconf->forward_server_ip;
292 apr_sockaddr_ip_get(&addr, address);
294 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);
295 if (strcmp(addr, r->connection->remote_ip) == 0) {
296 r->connection->remote_ip = apr_pstrdup(r->connection->pool, client_ip);
298 if (! apr_table_get(r->headers_in, "Content-Length")) {
299 contentLength = (char *)apr_table_get(r->headers_in, "X-Chxj-Content-Length");
301 apr_table_set(r->headers_in, "Content-Length", contentLength);
308 chxj_add_device_env(r, spec);
310 DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
317 s_clear_cookie_header(request_rec *r, device_table *spec)
319 DBG(r, "REQ[%X] start s_clear_cookie_header()", TO_ADDR(r));
320 switch(spec->html_spec_type) {
321 case CHXJ_SPEC_Chtml_1_0:
322 case CHXJ_SPEC_Chtml_2_0:
323 case CHXJ_SPEC_Chtml_3_0:
324 case CHXJ_SPEC_Chtml_4_0:
325 case CHXJ_SPEC_Chtml_5_0:
326 case CHXJ_SPEC_Chtml_6_0:
327 case CHXJ_SPEC_Chtml_7_0:
328 case CHXJ_SPEC_XHtml_Mobile_1_0:
329 case CHXJ_SPEC_Jhtml:
330 apr_table_unset(r->headers_in, "Cookie");
335 DBG(r, "REQ[%X] end s_clear_cookie_header()", TO_ADDR(r));
340 * It converts it from CHTML into XXML corresponding to each model.
343 * @param src [i] It is former HTML character string.
344 * @param len [i/o] It is length of former HTML character string.
347 chxj_convert(request_rec *r, const char **src, apr_size_t *len, device_table *spec, const char *ua, cookie_t **cookiep)
353 mod_chxj_config *dconf;
354 chxjconvrule_entry *entryp;
356 DBG(r,"REQ[%X] start of chxj_convert()", (unsigned int)(apr_size_t)r);
358 chxj_dump_string(r, APLOG_MARK, "INPUT Data", *src, *len);
360 dst = apr_pstrcat(r->pool, (char *)*src, NULL);
362 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
365 entryp = chxj_apply_convrule(r, dconf->convrules);
367 if (!entryp || (!(entryp->action & CONVRULE_ENGINE_ON_BIT) && !(entryp->action & CONVRULE_COOKIE_ONLY_BIT))) {
368 DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
373 /*------------------------------------------------------------------------*/
374 /* get UserAgent from http header */
375 /*------------------------------------------------------------------------*/
376 if (entryp->user_agent)
377 user_agent = (char *)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
379 user_agent = (char *)apr_table_get(r->headers_in, HTTP_USER_AGENT);
381 DBG(r,"REQ[%X] User-Agent:[%s]", (unsigned int)(apr_size_t)r, user_agent);
382 DBG(r,"REQ[%X] content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
385 if ( ! STRNCASEEQ('t','T', "text/html", r->content_type, sizeof("text/html")-1)
386 && ! STRNCASEEQ('a','A', "application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)) {
387 DBG(r,"REQ[%X] no convert. content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
388 DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
392 if (ua && user_agent && strcasecmp(user_agent, ua) != 0) {
394 spec = chxj_specified_device(r, user_agent);
401 if ((entryp->action & CONVRULE_COOKIE_ON_BIT
402 && !(entryp->action & CONVRULE_EMOJI_ONLY_BIT)
403 && !(entryp->action & CONVRULE_ENVINFO_ONLY_BIT))
404 || (entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
405 switch(spec->html_spec_type) {
406 case CHXJ_SPEC_Chtml_1_0:
407 case CHXJ_SPEC_Chtml_2_0:
408 case CHXJ_SPEC_Chtml_3_0:
409 case CHXJ_SPEC_Chtml_4_0:
410 case CHXJ_SPEC_Chtml_5_0:
411 case CHXJ_SPEC_Chtml_6_0:
412 case CHXJ_SPEC_Chtml_7_0:
413 case CHXJ_SPEC_XHtml_Mobile_1_0:
414 case CHXJ_SPEC_Jhtml:
415 cookie = chxj_save_cookie(r);
422 if (!r->header_only) {
424 if ((entryp->action & CONVRULE_COOKIE_ONLY_BIT) && cookie) {
425 dst = chxj_cookie_only_mode(r, *src, (apr_size_t *)len, cookie);
429 if (convert_routine[spec->html_spec_type].encoder)
430 tmp = convert_routine[spec->html_spec_type].encoder(r,
434 if (entryp->action & CONVRULE_EMOJI_ONLY_BIT) {
436 tmp = chxj_node_convert_chxjif_only(r, spec, (const char*)tmp, (apr_size_t *)len);
439 tmp = chxj_node_convert_chxjif_only(r, spec, (const char *)*src, (apr_size_t *)len);
441 if (convert_routine[spec->html_spec_type].emoji_only_converter) {
442 dst = convert_routine[spec->html_spec_type].emoji_only_converter(r,spec, tmp,*len);
447 dst = apr_palloc(r->pool, 1);
452 DBG(r, "REQ[%X] end of chxj_convert()(emoji only)", (unsigned int)(apr_size_t)r);
455 if ( !(entryp->action & CONVRULE_EMOJI_ONLY_BIT)
456 && !(entryp->action & CONVRULE_ENVINFO_ONLY_BIT)) {
457 if (convert_routine[spec->html_spec_type].converter) {
459 dst = convert_routine[spec->html_spec_type].converter(r,
467 dst = convert_routine[spec->html_spec_type].converter(r,
479 if (strcasecmp(spec->output_encoding,"UTF-8") == 0){
480 dst = chxj_iconv(r,r->pool,dst,len,"CP932","UTF-8");
485 ap_set_content_length(r, *len);
488 dst = apr_psprintf(r->pool, "\n");
498 DBG(r, "REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
505 * convert GUID parameter.
509 s_convert_guid_parameter_to_header(request_rec *r, const char *param, device_table *spec)
511 DBG(r, "REQ[%X] start s_convert_guid_parameter() param:[%s]", (unsigned int)(apr_size_t)r, param);
512 if (strcasecmp(param, "guid") == 0) {
513 switch(spec->html_spec_type) {
514 case CHXJ_SPEC_XHtml_Mobile_1_0:
516 char *x_up_subno = (char *)apr_table_get(r->headers_in, "x-up-subno");
518 apr_table_setn(r->headers_in, "X-DCMGUID", x_up_subno);
522 case CHXJ_SPEC_Jhtml:
523 case CHXJ_SPEC_Jxhtml:
525 char *x_jphone_uid = (char *)apr_table_get(r->headers_in, "x-jphone-uid");
527 apr_table_setn(r->headers_in, "X-DCMGUID", x_jphone_uid);
535 DBG(r, "REQ[%X] end s_convert_guid_parameter()", (unsigned int)(apr_size_t)r);
539 * It converts it from HEADER.
544 chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp, device_table *spec)
556 cookie_t *cookie = NULL;
557 int no_update_flag = 0;
559 DBG(r, "REQ[%X] start chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
562 DBG(r, "REQ[%X] r->args=[null]", (unsigned int)(apr_size_t)r);
563 DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
566 urilen = strlen(r->args);
568 result = qs_alloc_zero_byte_string(r->pool);
570 buff_pre = apr_pstrdup(r->pool, r->args);
575 pair = apr_strtok(buff_pre, "&", &pstate);
581 pair_sv = apr_pstrdup(r->pool, pair);
583 name = apr_strtok(pair, "=", &vstate);
584 value = apr_strtok(NULL, "=", &vstate);
585 if (! name) continue;
586 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
587 DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
592 buff = apr_pstrdup(r->pool, r->args);
593 DBG(r, "REQ[%X] r->args=[%s]", (unsigned int)(apr_size_t)r, buff);
602 pair = apr_strtok(buff, "&", &pstate);
608 pair_sv = apr_pstrdup(r->pool, pair);
610 name = apr_strtok(pair, "=", &vstate);
611 value = apr_strtok(NULL, "=", &vstate);
612 if (! name) continue;
613 name = chxj_safe_to_jreserved_tag(r, name);
614 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
615 if (strlen(result) != 0)
616 result = apr_pstrcat(r->pool, result, "&", NULL);
618 if (strcasecmp(entryp->encoding, "NONE") != 0) {
623 if (value && *value != 0) {
624 value = chxj_url_decode(r->pool, value);
625 dlen = strlen(value);
626 DBG(r, "************ before encoding[%s]", value);
628 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
629 dvalue = chxj_url_encode(r->pool, dvalue);
631 DBG(r, "************ after encoding[%s]", dvalue);
637 if (name && *name != 0) {
638 name = chxj_url_decode(r->pool, name);
640 dname = chxj_rencoding(r, name, &dlen,spec->output_encoding);
641 dname = chxj_url_encode(r->pool, dname);
646 s_convert_guid_parameter_to_header(r, dname, spec);
647 result = apr_pstrcat(r->pool, result, dname, "=", dvalue, NULL);
650 s_convert_guid_parameter_to_header(r, name, spec);
651 if (strcmp(name, pair_sv) != 0) {
652 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
655 result = apr_pstrcat(r->pool, result, name, NULL);
660 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
661 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
662 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
666 if (strlen(value) == 0)
669 if (strlen(result) != 0)
670 result = apr_pstrcat(r->pool, result, "&", NULL);
672 result = apr_pstrcat(r->pool, result, &name[8], "=", value, NULL);
675 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
677 apr_table_unset(r->headers_in, "Cookie");
678 DBG(r, "REQ[%X] found cookie parameter[%s]", (unsigned int)(apr_size_t)r, value);
679 DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
680 cookie_lock_t *lock = chxj_cookie_lock(r);
681 cookie = chxj_load_cookie(r, value);
682 DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
683 if (! no_update_flag && cookie) {
684 cookie = chxj_update_cookie(r, cookie);
686 chxj_cookie_unlock(r, lock);
688 if (cookie && cookie->cookie_id) {
689 if (strlen(result) != 0)
690 result = apr_pstrcat(r->pool, result, "&", NULL);
691 result = apr_pstrcat(r->pool, result, name, "=", cookie->cookie_id, NULL);
695 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
696 if (strlen(result) != 0)
697 result = apr_pstrcat(r->pool, result, "&", NULL);
698 result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
701 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
702 if (! no_update_flag) {
703 result = apr_pstrcat(r->pool, result, "&_chxj_nc=true", NULL);
707 DBG(r, "REQ[%X] result r->args=[%s]", (unsigned int)(apr_size_t)r, r->args);
708 DBG(r, "REQ[%X] end chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
714 * It converts it from POSTDATA .
717 * @param src [i] It is POSTDATA character string.
718 * @param len [i/o] It is length of former HTML character string.
725 chxjconvrule_entry *entryp,
735 cookie_t *cookie = NULL;
737 int no_update_flag = 0;
741 DBG(r, "REQ[%X] start of chxj_input_convert()", (unsigned int)(apr_size_t)r);
744 DBG(r, "REQ[%X] end of chxj_input_convert() (input is null)", (unsigned int)(apr_size_t)r);
745 return apr_pstrdup(r->pool, "");
748 apr_pool_create(&pool, r->pool);
750 s = apr_pstrdup(pool, *src);
752 buff_pre = apr_pstrdup(pool, *src);
754 result = qs_alloc_zero_byte_string(pool);
756 chxj_dump_string(r, APLOG_MARK, "BEFORE input convert source", s, ilen);
761 pair = apr_strtok(buff_pre, "&", &pstate);
767 pair_sv = apr_pstrdup(pool, pair);
769 name = apr_strtok(pair, "=", &vstate);
770 value = apr_strtok(NULL, "=", &vstate);
771 if (! name) continue;
772 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
773 DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
783 pair = apr_strtok(s, "&", &pstate);
788 name = apr_strtok(pair, "=", &vstate);
789 value = apr_strtok(NULL, "=", &vstate);
790 if (! name) continue;
791 name = chxj_safe_to_jreserved_tag(r, name);
793 if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
794 if (strlen(result) != 0)
795 result = apr_pstrcat(pool, result, "&", NULL);
797 if (strcasecmp(entryp->encoding, "NONE") != 0) {
802 if (value && *value != 0) {
803 value = chxj_url_decode(pool, value);
804 dlen = strlen(value);
805 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
806 dvalue = chxj_url_encode(pool, dvalue);
812 if (name && *name != 0) {
813 name = chxj_url_decode(pool, name);
815 dname = chxj_rencoding(r, name, &dlen,spec->output_encoding);
816 dname = chxj_url_encode(pool, dname);
823 result = apr_pstrcat(pool, result, dname, "=", dvalue, NULL);
826 result = apr_pstrcat(pool, result, name, "=", value, NULL);
830 if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
831 || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
832 || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
836 if (strlen(value) == 0)
839 if (strlen(result) != 0)
840 result = apr_pstrcat(pool, result, "&", NULL);
842 if (strcasecmp(entryp->encoding, "NONE") != 0 && value && strlen(value)) {
846 dlen = strlen(value);
847 value = chxj_url_decode(pool, value);
848 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
849 dvalue = chxj_url_encode(pool,dvalue);
850 result = apr_pstrcat(pool, result, &name[8], "=", dvalue, NULL);
854 result = apr_pstrcat(pool, result, &name[8], "=", value, NULL);
858 if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
860 apr_table_unset(r->headers_in, "Cookie");
861 DBG(r, "REQ[%X] found cookie parameter[%s]", (unsigned int)(apr_size_t)r, value);
862 DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
863 cookie_lock_t *lock = chxj_cookie_lock(r);
864 cookie = chxj_load_cookie(r, value);
865 DBG(r, "REQ[%X] call end chxj_load_cookie()", (unsigned int)(apr_size_t)r);
866 if (! no_update_flag && cookie) {
867 cookie = chxj_update_cookie(r, cookie);
869 chxj_cookie_unlock(r, lock);
871 if (cookie && cookie->cookie_id) {
872 if (strlen(result) != 0)
873 result = apr_pstrcat(pool, result, "&", NULL);
874 result = apr_pstrcat(pool, result, name, "=", cookie->cookie_id, NULL);
878 if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
879 if (strlen(result) != 0)
880 result = apr_pstrcat(pool, result, "&", NULL);
881 result = apr_pstrcat(pool, result, name, "=", value, NULL);
884 if ( strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1) == 0) {
888 dlen = strlen(value);
891 value = chxj_url_decode(pool, value);
892 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
893 dvalue = chxj_url_encode(pool,dvalue);
894 if (r->args && strlen(r->args) > 0) {
895 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
898 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
900 s_convert_guid_parameter_to_header(r, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], spec);
904 if (strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX_ENC, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1) == 0) {
907 dlen = strlen(value);
909 value = chxj_url_decode(pool, value);
910 dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
911 dvalue = chxj_url_encode(pool,dvalue);
912 if (r->args && strlen(r->args) > 0) {
913 r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
916 r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
918 s_convert_guid_parameter_to_header(r, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], spec);
921 DBG(r, "REQ[%X] ************************ name:[%s]", (unsigned int)(apr_size_t)r, name);
923 *len = strlen(result);
924 apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
925 if (! no_update_flag) {
926 result = apr_pstrcat(pool, result, "&_chxj_nc=true", NULL);
929 DBG(r, "REQ[%X] AFTER input convert result = [%s]", (unsigned int)(apr_size_t)r, result);
930 DBG(r, "REQ[%X] end chxj_input_convert()", (unsigned int)(apr_size_t)r);
937 * The received data is returned to the filter.
939 * @param f [i/o] It is a filter.
940 * @param data [i] It is data returned to the filter.
941 * @param len [i] It is length of the data returned to the filter.
944 pass_data_to_filter(ap_filter_t *f, const char *data,
947 request_rec *r = f->r;
948 conn_rec *c = r->connection;
950 apr_bucket_brigade *bb;
953 DBG(r, "REQ[%X] start pass_data_to_filter()", (unsigned int)(apr_size_t)r);
955 chxj_header_inf_clear(r);
957 bb = apr_brigade_create(r->pool, c->bucket_alloc);
958 b = apr_bucket_transient_create(data, len, c->bucket_alloc);
960 APR_BRIGADE_INSERT_TAIL(bb, b);
961 b = apr_bucket_eos_create(f->c->bucket_alloc);
962 APR_BRIGADE_INSERT_TAIL(bb, b);
964 rv = ap_pass_brigade(f->next, bb);
965 if (rv != APR_SUCCESS) {
966 DBG(r, "REQ[%X] end pass_data_to_filter() (apr_pass_brigade)", (unsigned int)(apr_size_t)r);
970 DBG(r, "REQ[%X] end pass_data_to_filter()", (unsigned int)(apr_size_t)r);
976 * Add No Cache Header
979 s_add_no_cache_headers(request_rec *r, chxjconvrule_entry *entryp)
981 if (entryp->action & CONVRULE_NOCACHE_ON_BIT) {
982 apr_table_unset(r->headers_out, "Pragma");
983 apr_table_unset(r->err_headers_out, "Pragma");
984 apr_table_unset(r->headers_out, "Expires");
985 apr_table_unset(r->err_headers_out, "Expires");
986 apr_table_unset(r->headers_out, "Cache-Control");
987 apr_table_unset(r->err_headers_out, "Cache-Control");
989 apr_table_setn(r->err_headers_out, "Pragma", "no-cache");
990 apr_table_setn(r->err_headers_out, "Expires", "Thu, 01 Jan 1970 00:00:00 GMT");
991 apr_table_setn(r->err_headers_out, "Cache-Control", "no-cache, no-store");
997 * It is the main loop of the output filter.
999 * @param f [i/o] It is a filter.
1003 chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
1009 char *user_agent = NULL;
1011 mod_chxj_ctx *ctx = (mod_chxj_ctx *)f->ctx;
1012 cookie_t *cookie = NULL;
1013 mod_chxj_config *dconf;
1014 chxjconvrule_entry *entryp = NULL;
1015 device_table *spec = NULL;
1019 DBG(f->r, "REQ[%X] start of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1022 apr_pool_create(&pool, r->pool);
1024 entryp = ctx->entryp;
1026 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1029 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1030 DBG(r, "REQ[%X] found Location header", TO_ADDR(r));
1031 if ((entryp->action & CONVRULE_COOKIE_ON_BIT) || (entryp->action & CONVRULE_COOKIE_ONLY_BIT)) {
1032 cookie_lock_t *lock = NULL;
1033 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", TO_ADDR(r));
1034 switch(spec->html_spec_type) {
1035 case CHXJ_SPEC_Chtml_1_0:
1036 case CHXJ_SPEC_Chtml_2_0:
1037 case CHXJ_SPEC_Chtml_3_0:
1038 case CHXJ_SPEC_Chtml_4_0:
1039 case CHXJ_SPEC_Chtml_5_0:
1040 case CHXJ_SPEC_Chtml_6_0:
1041 case CHXJ_SPEC_Chtml_7_0:
1042 case CHXJ_SPEC_XHtml_Mobile_1_0:
1043 case CHXJ_SPEC_Jhtml:
1044 lock = chxj_cookie_lock(r);
1045 cookie = chxj_save_cookie(r);
1046 s_add_cookie_id_if_has_location_header(r, cookie);
1047 chxj_cookie_unlock(r, lock);
1053 if (! ap_is_HTTP_REDIRECT(r->status)) {
1054 r->status = HTTP_MOVED_TEMPORARILY;
1056 s_add_no_cache_headers(r, entryp);
1057 /* must not send body. */
1058 rv = pass_data_to_filter(f, "", 0);
1059 DBG(f->r, "REQ[%X] end of chxj_output_filter()", TO_ADDR(r));
1064 if (r->content_type) {
1065 if (! STRNCASEEQ('t','T',"text/html",r->content_type, sizeof("text/html")-1)
1066 && ! STRNCASEEQ('t','T',"text/xml", r->content_type, sizeof("text/xml")-1)
1067 && ! STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
1068 && ! (dconf->image == CHXJ_IMG_ON
1069 && ! apr_table_get(r->headers_in, "CHXJ_IMG_CONV")
1070 && STRNCASEEQ('i','I',"image/", r->content_type, sizeof("image/") -1)
1071 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
1072 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
1073 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
1074 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
1075 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
1076 || STRCASEEQ('x','X',"x-ms-bmp", &r->content_type[6]) /* BMP */
1077 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
1078 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
1079 || STRCASEEQ('g','G',"gif", &r->content_type[6])))) { /* GIF */
1081 DBG(r, "REQ[%X] not convert content-type:[%s] dconf->image:[%d]", (unsigned int)(apr_size_t)r, r->content_type, dconf->image);
1082 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
1083 cookie_lock_t *lock = NULL;
1084 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
1085 switch(spec->html_spec_type) {
1086 case CHXJ_SPEC_Chtml_1_0:
1087 case CHXJ_SPEC_Chtml_2_0:
1088 case CHXJ_SPEC_Chtml_3_0:
1089 case CHXJ_SPEC_Chtml_4_0:
1090 case CHXJ_SPEC_Chtml_5_0:
1091 case CHXJ_SPEC_Chtml_6_0:
1092 case CHXJ_SPEC_Chtml_7_0:
1093 case CHXJ_SPEC_XHtml_Mobile_1_0:
1094 case CHXJ_SPEC_Jhtml:
1095 lock = chxj_cookie_lock(r);
1096 cookie = chxj_save_cookie(r);
1097 s_add_cookie_id_if_has_location_header(r, cookie);
1098 chxj_cookie_unlock(r, lock);
1104 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1105 if (! ap_is_HTTP_REDIRECT(r->status)) {
1106 r->status = HTTP_MOVED_TEMPORARILY;
1109 s_add_no_cache_headers(r, entryp);
1110 ap_pass_brigade(f->next, bb);
1111 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1116 DBG(r, "REQ[%X] not convert content-type:[(null)]", (unsigned int)(apr_size_t)r);
1117 ap_pass_brigade(f->next, bb);
1118 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1123 for (b = APR_BRIGADE_FIRST(bb);
1124 b != APR_BRIGADE_SENTINEL(bb);
1125 b = APR_BUCKET_NEXT(b)) {
1127 if (apr_bucket_read(b, &data, &len, APR_BLOCK_READ) == APR_SUCCESS) {
1128 chxj_dump_string(r, APLOG_MARK, "READ Data", data, len);
1130 /*--------------------------------------------------------------------*/
1132 /*--------------------------------------------------------------------*/
1134 DBG(r, "append data start");
1135 ctx = (mod_chxj_ctx *)f->ctx;
1138 tmp = apr_palloc(r->pool, ctx->len);
1139 memcpy(tmp, ctx->buffer, ctx->len);
1141 ctx->buffer = apr_palloc(pool, ctx->len + len);
1143 memcpy(ctx->buffer, tmp, ctx->len);
1144 memcpy(&ctx->buffer[ctx->len], data, len);
1148 DBG(r, "REQ[%X] append data end", (unsigned int)(apr_size_t)r);
1151 if (APR_BUCKET_IS_EOS(b)) {
1153 DBG(r, "REQ[%X] eos", (unsigned int)(apr_size_t)r);
1154 /*----------------------------------------------------------------------*/
1156 /*----------------------------------------------------------------------*/
1158 cookie_lock_t *lock = NULL;
1159 ctx = (mod_chxj_ctx *)f->ctx;
1161 DBG(r, "REQ[%X] content_type=[%s]", (unsigned int)(apr_size_t)r, r->content_type);
1162 lock = chxj_cookie_lock(r);
1164 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
1166 && (STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
1167 || STRNCASEEQ('t','T',"text/html", r->content_type, sizeof("text/html")-1))) {
1168 DBG(r, "REQ[%X] detect convert target:[%s]", (unsigned int)(apr_size_t)r, r->content_type);
1173 tmp = apr_palloc(pool, ctx->len + 1);
1175 memset(tmp, 0, ctx->len + 1);
1176 memcpy(tmp, ctx->buffer, ctx->len);
1178 ctx->buffer = chxj_convert(r,
1179 (const char **)&tmp,
1180 (apr_size_t *)&ctx->len,
1182 user_agent, &cookie);
1186 ctx->buffer = apr_psprintf(r->pool, "\n");
1188 ctx->buffer = chxj_convert(r,
1189 (const char **)&ctx->buffer,
1190 (apr_size_t *)&ctx->len,
1192 user_agent, &cookie);
1197 && *(char *)r->content_type == 't'
1198 && strncmp(r->content_type, "text/xml", 8) == 0) {
1199 DBG(r, "REQ[%X] text/XML", (unsigned int)(apr_size_t)r);
1207 memset(&doc, 0, sizeof(Doc));
1208 memset(&qrcode, 0, sizeof(qr_code_t));
1210 doc.parse_mode = PARSE_MODE_CHTML;
1214 qs_init_malloc(&doc);
1216 root = qs_parse_string(&doc, ctx->buffer, ctx->len);
1219 for (child = qs_get_child_node(&doc,root);
1221 child = qs_get_next_node(&doc,child)) {
1222 char *name = qs_get_node_name(&doc,child);
1223 if (strcasecmp("qrcode",name) == 0) {
1228 qs_all_free(&doc,QX_LOGMARK);
1230 r->handler = apr_psprintf(r->pool, "chxj-qrcode");
1231 chxj_qrcode_node_to_qrcode(&qrcode, root);
1232 sts = chxj_qrcode_create_image_data(&qrcode, &ctx->buffer, &ctx->len);
1234 ERR(r, "REQ[%X] qrcode create failed.", (unsigned int)(apr_size_t)r);
1235 chxj_cookie_unlock(r, lock);
1236 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1239 r->content_type = apr_psprintf(r->pool, "image/jpeg");
1243 if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN
1245 && ( *r->content_type == 'i' || *r->content_type == 'I')
1246 && dconf->image == CHXJ_IMG_ON
1247 && strncasecmp("image/", r->content_type, 6) == 0
1248 && ( STRCASEEQ('j','J',"jpeg", &r->content_type[6]) /* JPEG */
1249 || STRCASEEQ('j','J',"jp2", &r->content_type[6]) /* JPEG2000 */
1250 || STRCASEEQ('j','J',"jpeg2000", &r->content_type[6]) /* JPEG2000 */
1251 || STRCASEEQ('j','J',"jpeg2000-image", &r->content_type[6]) /* JPEG2000 */
1252 || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6]) /* JPEG2000 */
1253 || STRCASEEQ('p','P',"png", &r->content_type[6]) /* PNG */
1254 || STRCASEEQ('x','X',"x-png", &r->content_type[6]) /* PNG */
1255 || STRCASEEQ('x','X',"x-ms-bmp", &r->content_type[6]) /* BMP */
1256 || STRCASEEQ('g','G',"gif", &r->content_type[6]))) { /* GIF */
1257 DBG(r, "REQ[%X] detect convert target:[%s]", (unsigned int)(apr_size_t)r, r->content_type);
1261 tmp = apr_palloc(pool, ctx->len + 1);
1263 memset(tmp, 0, ctx->len + 1);
1264 memcpy(tmp, ctx->buffer, ctx->len);
1266 chxj_convert_image(r,
1267 (const char **)&tmp,
1268 (apr_size_t *)&ctx->len);
1269 if (ctx->buffer == NULL) {
1275 apr_table_unset(r->headers_out, "Content-Length");
1276 apr_table_unset(r->err_headers_out, "Content-Length");
1277 ap_set_content_length(r, (apr_off_t)ctx->len);
1281 DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1282 s_add_cookie_id_if_has_location_header(r, cookie);
1283 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1284 if (! ap_is_HTTP_REDIRECT(r->status)) {
1285 r->status = HTTP_MOVED_TEMPORARILY;
1288 if (ctx->len && ap_is_HTTP_REDIRECT(r->status)) {
1289 ctx->buffer = apr_pstrdup(pool, "");
1291 ap_set_content_length(r, (apr_off_t)ctx->len);
1293 chxj_cookie_unlock(r,lock);
1294 s_add_no_cache_headers(r, entryp);
1295 rv = pass_data_to_filter(f,
1296 (const char *)ctx->buffer,
1297 (apr_size_t)ctx->len);
1300 ctx->buffer = apr_pstrdup(pool, "");
1302 ap_set_content_length(r, (apr_off_t)ctx->len);
1303 chxj_cookie_unlock(r, lock);
1304 s_add_no_cache_headers(r, entryp);
1305 rv = pass_data_to_filter(f,
1306 (const char *)ctx->buffer,
1307 (apr_size_t)ctx->len);
1309 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1313 DBG(r, "REQ[%X] SAVE COOKIE[%x]", (unsigned int)(apr_size_t)r, entryp->action);
1318 if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
1319 cookie_lock_t *lock = NULL;
1320 DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
1321 switch(spec->html_spec_type) {
1322 case CHXJ_SPEC_Chtml_1_0:
1323 case CHXJ_SPEC_Chtml_2_0:
1324 case CHXJ_SPEC_Chtml_3_0:
1325 case CHXJ_SPEC_Chtml_4_0:
1326 case CHXJ_SPEC_Chtml_5_0:
1327 case CHXJ_SPEC_Chtml_6_0:
1328 case CHXJ_SPEC_Chtml_7_0:
1329 case CHXJ_SPEC_XHtml_Mobile_1_0:
1330 case CHXJ_SPEC_Jhtml:
1331 lock = chxj_cookie_lock(r);
1332 cookie = chxj_save_cookie(r);
1334 * Location Header Check to add cookie parameter.
1336 s_add_cookie_id_if_has_location_header(r, cookie);
1337 chxj_cookie_unlock(r, lock);
1338 apr_table_unset(r->headers_out, "Set-Cookie");
1339 apr_table_unset(r->err_headers_out, "Set-Cookie");
1346 if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1347 if (! ap_is_HTTP_REDIRECT(r->status)) {
1348 r->status = HTTP_MOVED_TEMPORARILY;
1351 apr_table_setn(r->headers_out, "Content-Length", "0");
1352 DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1353 s_add_no_cache_headers(r, entryp);
1354 rv = pass_data_to_filter(f, (const char *)"", (apr_size_t)0);
1355 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1360 apr_brigade_destroy(bb);
1362 DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1368 * Add Cookie_id if it has location header.
1371 s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie)
1373 char *location_header = (char *)apr_table_get(r->headers_out, "Location");
1374 if (! location_header) {
1375 location_header = (char *)apr_table_get(r->err_headers_out, "Location");
1377 if (cookie && location_header) {
1378 DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1379 location_header = chxj_add_cookie_parameter(r,
1382 apr_table_unset(r->headers_out, "Location");
1383 apr_table_setn(r->headers_out, "Location", location_header);
1384 DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1385 if (!ap_is_HTTP_REDIRECT(r->status)) {
1386 r->status = HTTP_MOVED_TEMPORARILY;
1392 * It is the main loop of the input filter handler.
1396 chxj_input_handler(request_rec *r)
1398 mod_chxj_config *dconf;
1399 chxjconvrule_entry *entryp = NULL;
1400 device_table *spec = NULL;
1401 char *post_data = NULL;
1402 apr_size_t post_data_len = 0;
1407 int response_code = 0;
1409 DBG(r, "start of chxj_input_handler()");
1411 if (strcasecmp(r->handler, "chxj-input-handler")) {
1412 DBG(r, "end chxj_input_handler()");
1415 apr_pool_create(&pool, r->pool);
1417 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1418 user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
1420 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
1422 spec = chxj_specified_device(r, user_agent);
1423 entryp = chxj_apply_convrule(r, dconf->convrules);
1425 post_data = apr_pstrdup(pool, "");
1426 if (ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK) == OK) {
1427 if (ap_should_client_block(r)) {
1428 while (post_data_len < CHXJ_POST_MAX) {
1431 int read_bytes = ap_get_client_block(r, buffer, BUFSZ-1);
1432 if (read_bytes<=0) {
1435 buffer[read_bytes] = '\0';
1436 post_data = apr_pstrcat(pool, post_data, buffer, NULL);
1437 post_data_len += read_bytes;
1446 if (post_data_len > 0) {
1447 post_data = chxj_input_convert(r, (const char**)&post_data, (apr_size_t*)&post_data_len, entryp, spec);
1448 DBG(r, "(in:exchange)POSTDATA:[%s]", post_data);
1452 if (dconf->forward_url_base) {
1453 url_path = apr_psprintf(pool, "%s%s", dconf->forward_url_base, r->uri);
1456 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);
1459 url_path = apr_pstrcat(pool, url_path, "?", r->args, NULL);
1461 DBG(r, "==> new url_path:[%s]", url_path);
1464 apr_table_setn(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP, r->connection->remote_ip);
1465 apr_table_unset(r->headers_in, "Content-Length");
1466 apr_table_setn(r->headers_in, "Content-Length", apr_psprintf(pool, "%" APR_SIZE_T_FMT, post_data_len));
1467 response = chxj_serf_post(r, pool, url_path, post_data, post_data_len, 1, &res_len, &response_code);
1468 DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1469 DBG(r, "REQ[%X] response length:[%" APR_SIZE_T_FMT "]", (unsigned int)(apr_size_t)r, res_len);
1470 for (ii=0; ii<res_len/64; ii++) {
1471 DBG(r, "REQ[%X] response:[%.*s]", (unsigned int)(apr_size_t)r, 64, &response[ii*64]);
1473 DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1476 if ((chunked = (char *)apr_table_get(r->headers_out, "Transfer-Encoding")) != NULL) {
1477 if (strcasecmp(chunked, "chunked") == 0) {
1479 apr_table_unset(r->headers_out, "Transfer-Encoding");
1482 if (ap_is_HTTP_ERROR(response_code)) {
1483 DBG(r, "REQ[%X] end of chxj_input_handler() (HTTP-ERROR received. response code:[%d])", (unsigned int)(apr_size_t)r, response_code);
1484 return response_code;
1488 apr_pool_create(&wpool, r->pool);
1489 apr_bucket_brigade *bb;
1492 conn_rec *c = r->connection;
1494 bb = apr_brigade_create(wpool, c->bucket_alloc);
1495 e = apr_bucket_transient_create(response, res_len, c->bucket_alloc);
1496 APR_BRIGADE_INSERT_TAIL(bb, e);
1497 e = apr_bucket_eos_create(c->bucket_alloc);
1498 APR_BRIGADE_INSERT_TAIL(bb, e);
1499 if ((rv = ap_pass_brigade(r->output_filters, bb)) != APR_SUCCESS) {
1500 ERR(r, "REQ[%X] %s:%d failed ap_pass_brigade()", (unsigned int)(apr_size_t)r, APLOG_MARK);
1503 apr_brigade_cleanup(bb);
1506 DBG(r, "REQ[%X] end of chxj_input_handler()", (unsigned int)(apr_size_t)r);
1510 static mod_chxj_global_config *
1511 chxj_global_config_create(apr_pool_t *pool, server_rec *s)
1513 mod_chxj_global_config *conf;
1515 SDBG(s, "start chxj_global_config_create()");
1517 /*--------------------------------------------------------------------------*/
1518 /* allocate an own subpool which survives server restarts */
1519 /*--------------------------------------------------------------------------*/
1520 conf = (mod_chxj_global_config *)apr_palloc(pool,
1521 sizeof(mod_chxj_global_config));
1523 conf->cookie_db_lock = NULL;
1525 SDBG(s, "end chxj_global_config_create()");
1532 * initialize chxj module
1535 chxj_init_module(apr_pool_t *p,
1536 apr_pool_t *UNUSED(plog),
1537 apr_pool_t *UNUSED(ptemp),
1543 SDBG(s, "start chxj_init_module()");
1545 apr_pool_userdata_get(&user_data, CHXJ_MOD_CONFIG_KEY, s->process->pool);
1547 if (user_data == NULL) {
1550 * dummy user_data set.
1552 apr_pool_userdata_set(
1554 CHXJ_MOD_CONFIG_KEY,
1555 apr_pool_cleanup_null,
1557 SDBG(s, "end chxj_init_module()");
1561 ap_add_version_component(p, CHXJ_VERSION_PREFIX CHXJ_VERSION);
1563 if ((rv = apr_proc_mutex_create(&global_cookie_mutex, NULL, APR_LOCK_FCNTL, s->process->pool)) != APR_SUCCESS) {
1565 SERR(s, "%s:%d end chxj_init_module(). mutex create failure.(%d:%s)",APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1566 return HTTP_INTERNAL_SERVER_ERROR;
1569 SDBG(s, "end chxj_init_module()");
1576 chxj_child_init(apr_pool_t *UNUSED(p), server_rec *s)
1579 SDBG(s, "start chxj_child_init()");
1580 if ((rv = apr_proc_mutex_child_init(&global_cookie_mutex, NULL, s->process->pool)) != APR_SUCCESS) {
1582 SERR(s, "%s:%d ERROR end chxj_init_module(). mutex create failure.(%d:%s)", APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1584 SDBG(s, "end chxj_child_init()");
1589 * A set structure of each server is generated.
1595 chxj_config_server_create(apr_pool_t *p, server_rec *s)
1597 mod_chxj_global_config *gc;
1599 gc = chxj_global_config_create(p,s);
1606 chxj_translate_name(request_rec *r)
1608 DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1609 DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1610 DBG(r, "REQ[%X] START REQUEST (uri:[%s] args:[%s])", (unsigned int)(apr_size_t)r, r->unparsed_uri, r->args ? r->args : "");
1611 DBG(r, "REQ[%X] METHOD [%s]", TO_ADDR(r), r->method);
1612 DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1613 DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1615 return chxj_trans_name(r);
1623 chxj_insert_filter(request_rec *r)
1627 mod_chxj_config *dconf;
1628 chxjconvrule_entry *entryp;
1633 DBG(r, "REQ[%X] start chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1635 dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1637 /* we get User-Agent from CHXJ_HTTP_USER_AGENT header if any */
1638 user_agent = (char *)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
1640 user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
1643 contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
1645 && strncasecmp("multipart/form-data", contentType, 19) == 0) {
1646 DBG(r, "REQ[%X] detect multipart/form-data ==> no target", (unsigned int)(apr_size_t)r);
1647 DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1651 spec = chxj_specified_device(r, user_agent);
1652 entryp = chxj_apply_convrule(r, dconf->convrules);
1654 DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1657 ctx = apr_palloc(r->pool, sizeof(*ctx));
1658 memset(ctx, 0, sizeof(*ctx));
1659 if ((rv = apr_pool_create(&ctx->pool, r->pool)) != APR_SUCCESS) {
1660 ERR(r, "%s:%d: failed: new pool create. rv:[%d]", __FILE__,__LINE__,rv);
1661 DBG(r, "REQ:[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1664 ctx->entryp = entryp;
1666 ctx->buffer = apr_palloc(ctx->pool, 1);
1669 if (!entryp || (!(entryp->action & CONVRULE_ENGINE_ON_BIT) && !(entryp->action & CONVRULE_COOKIE_ONLY_BIT))) {
1670 DBG(r,"REQ[%X] EngineOff", (unsigned int)(apr_size_t)r);
1671 DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1675 switch(spec->html_spec_type) {
1676 case CHXJ_SPEC_Chtml_1_0:
1677 case CHXJ_SPEC_Chtml_2_0:
1678 case CHXJ_SPEC_Chtml_3_0:
1679 case CHXJ_SPEC_Chtml_4_0:
1680 case CHXJ_SPEC_Chtml_5_0:
1681 case CHXJ_SPEC_Chtml_6_0:
1682 case CHXJ_SPEC_Chtml_7_0:
1683 case CHXJ_SPEC_XHtml_Mobile_1_0:
1684 case CHXJ_SPEC_Hdml:
1685 case CHXJ_SPEC_Jhtml:
1686 case CHXJ_SPEC_Jxhtml:
1690 DBG(r, "REQ[%X] end chxj_insert_filter() Unknown spec type(%d).", (unsigned int)(apr_size_t)r, spec->html_spec_type);
1695 if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
1696 ap_add_output_filter("chxj_output_filter", ctx, r, r->connection);
1697 DBG(r, "REQ[%X] added Output Filter", (unsigned int)(apr_size_t)r);
1700 DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1705 * The hook is registered.
1710 chxj_register_hooks(apr_pool_t *UNUSED(p))
1712 ap_hook_post_config(chxj_init_module,
1715 APR_HOOK_REALLY_FIRST);
1716 ap_hook_child_init(chxj_child_init,
1719 APR_HOOK_REALLY_FIRST);
1720 ap_register_output_filter (
1721 "chxj_output_filter",
1725 ap_hook_insert_filter(chxj_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
1726 ap_hook_handler(chxj_img_conv_format_handler, NULL, NULL, APR_HOOK_MIDDLE);
1727 ap_hook_handler(chxj_qr_code_handler, NULL, NULL, APR_HOOK_MIDDLE);
1728 ap_hook_handler(chxj_input_handler, NULL, NULL, APR_HOOK_MIDDLE);
1729 ap_hook_translate_name(chxj_translate_name, NULL, NULL, APR_HOOK_MIDDLE);
1730 ap_hook_fixups(chxj_headers_fixup, NULL, NULL, APR_HOOK_FIRST);
1735 * A set structure according to the directory is generated.
1741 chxj_create_per_dir_config(apr_pool_t *p, char *arg)
1743 mod_chxj_config *conf;
1745 conf = apr_pcalloc(p, sizeof(mod_chxj_config));
1746 conf->device_data_file = NULL;
1747 conf->devices = NULL;
1748 conf->emoji_data_file = NULL;
1750 conf->emoji_tail = NULL;
1751 conf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_NONE;
1752 conf->image = CHXJ_IMG_NONE;
1753 conf->image_cache_dir = apr_psprintf(p, "%s",DEFAULT_IMAGE_CACHE_DIR);
1754 conf->image_cache_limit = 0;
1755 conf->server_side_encoding = NULL;
1756 conf->cookie_db_dir = NULL;
1757 conf->cookie_timeout = 0;
1758 conf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
1759 conf->cookie_lazy_mode = 0;
1760 conf->cookie_dbm_type = NULL;
1762 conf->detect_device_type = CHXJ_ADD_DETECT_DEVICE_TYPE_NONE;
1764 #if defined(USE_MYSQL_COOKIE)
1765 memset((void *)&conf->mysql, 0, sizeof(mysql_t));
1766 conf->mysql.port = MYSQL_PORT;
1767 conf->mysql.host = NULL;
1769 #if defined(USE_MEMCACHE_COOKIE)
1770 memset((void *)&conf->memcache, 0, sizeof(memcache_t));
1771 conf->memcache.host = NULL;
1772 conf->memcache.port = 0;
1774 conf->forward_url_base = NULL;
1775 conf->forward_server_ip = NULL;
1776 conf->allowed_cookie_domain = NULL;
1777 conf->post_log = NULL;
1783 conf->dir = apr_pcalloc(p, strlen(arg)+1);
1784 memset(conf->dir, 0, strlen(arg)+1);
1785 strcpy(conf->dir, arg);
1787 conf->convrules = apr_array_make(p, 2, sizeof(chxjconvrule_entry));
1789 /* Default is copyleft */
1790 conf->image_copyright = NULL;
1792 conf->image_rewrite = CHXJ_IMG_REWRITE_NONE;
1793 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_NONE;
1794 conf->image_rewrite_url = NULL;
1801 * Merge per-directory CHXJ configurations
1804 chxj_merge_per_dir_config(apr_pool_t *p, void *basev, void *addv)
1806 mod_chxj_config *base;
1807 mod_chxj_config *add;
1808 mod_chxj_config *mrg;
1810 base = (mod_chxj_config *)basev;
1811 add = (mod_chxj_config *)addv;
1812 mrg = (mod_chxj_config *)apr_palloc(p, sizeof(mod_chxj_config));
1814 mrg->device_data_file = NULL;
1815 mrg->devices = NULL;
1816 mrg->emoji_data_file = NULL;
1817 mrg->image = CHXJ_IMG_NONE;
1818 mrg->image_cache_dir = NULL;
1819 mrg->image_copyright = NULL;
1820 mrg->image_cache_limit = 0;
1822 mrg->emoji_tail = NULL;
1823 mrg->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_NONE;
1824 mrg->new_line_type = NLTYPE_NIL;
1825 mrg->forward_url_base = NULL;
1826 mrg->forward_server_ip = NULL;
1827 mrg->allowed_cookie_domain = NULL;
1828 mrg->post_log = NULL;
1829 mrg->cookie_dbm_type = NULL;
1831 mrg->device_keys = NULL;
1832 mrg->device_hash = NULL;
1834 mrg->dir = apr_pstrdup(p, add->dir);
1836 if (! add->device_data_file) {
1837 mrg->devices = base->devices;
1838 mrg->device_data_file = apr_pstrdup(p, base->device_data_file);
1841 mrg->devices = add->devices;
1842 mrg->device_data_file = apr_pstrdup(p, add->device_data_file);
1845 if (! add->emoji_data_file) {
1846 mrg->emoji = base->emoji;
1847 mrg->emoji_tail = base->emoji_tail;
1848 mrg->emoji_data_file = apr_pstrdup(p, base->emoji_data_file);
1851 mrg->emoji = add->emoji;
1852 mrg->emoji_tail = add->emoji_tail;
1853 mrg->emoji_data_file = apr_pstrdup(p, add->emoji_data_file);
1856 if (add->image == CHXJ_IMG_NONE) {
1857 mrg->image = base->image;
1860 mrg->image = add->image;
1863 if (strcasecmp(add->image_cache_dir ,DEFAULT_IMAGE_CACHE_DIR)==0) {
1864 mrg->image_cache_dir = apr_pstrdup(p, base->image_cache_dir);
1867 mrg->image_cache_dir = apr_pstrdup(p, add->image_cache_dir);
1870 if (add->image_cache_limit) {
1871 mrg->image_cache_limit = add->image_cache_limit;
1874 mrg->image_cache_limit = base->image_cache_limit;
1877 if (add->image_copyright)
1878 mrg->image_copyright = apr_pstrdup(p, add->image_copyright);
1880 mrg->image_copyright = apr_pstrdup(p, base->image_copyright);
1882 if (add->server_side_encoding) {
1883 mrg->server_side_encoding = apr_pstrdup(p, add->server_side_encoding);
1886 if (base->server_side_encoding) {
1887 mrg->server_side_encoding = apr_pstrdup(p, base->server_side_encoding);
1890 mrg->server_side_encoding = apr_pstrdup(p, DEFAULT_SERVER_SIDE_ENCODING);
1893 mrg->convrules = apr_array_append(p, add->convrules, base->convrules);
1895 if (add->cookie_db_dir) {
1896 mrg->cookie_db_dir = apr_pstrdup(p, add->cookie_db_dir);
1899 if (base->cookie_db_dir) {
1900 mrg->cookie_db_dir = apr_pstrdup(p, base->cookie_db_dir);
1903 mrg->cookie_db_dir = NULL;
1906 if (add->cookie_timeout) {
1907 mrg->cookie_timeout = add->cookie_timeout;
1910 if (base->cookie_db_dir) {
1911 mrg->cookie_timeout = base->cookie_timeout;
1914 mrg->cookie_timeout = 0;
1917 #if defined(USE_MYSQL_COOKIE)
1918 if (add->mysql.host) {
1919 mrg->mysql.host = apr_pstrdup(p, add->mysql.host);
1921 else if (base->mysql.host) {
1922 mrg->mysql.host = apr_pstrdup(p, base->mysql.host);
1925 mrg->mysql.host = NULL;
1927 if (add->mysql.port) {
1928 mrg->mysql.port = add->mysql.port;
1930 else if (base->mysql.port) {
1931 mrg->mysql.port = base->mysql.port;
1934 mrg->mysql.port = 0;
1937 if (add->mysql.database) {
1938 mrg->mysql.database = apr_pstrdup(p, add->mysql.database);
1940 else if (base->mysql.database) {
1941 mrg->mysql.database = apr_pstrdup(p, base->mysql.database);
1944 mrg->mysql.database = NULL;
1947 if (add->mysql.username) {
1948 mrg->mysql.username = apr_pstrdup(p, add->mysql.username);
1950 else if (base->mysql.username) {
1951 mrg->mysql.username = apr_pstrdup(p, base->mysql.username);
1954 mrg->mysql.username = NULL;
1957 if (add->mysql.password) {
1958 mrg->mysql.password = apr_pstrdup(p, add->mysql.password);
1960 else if (base->mysql.password) {
1961 mrg->mysql.password = apr_pstrdup(p, base->mysql.password);
1964 mrg->mysql.password = NULL;
1967 if (add->mysql.tablename) {
1968 mrg->mysql.tablename = apr_pstrdup(p, add->mysql.tablename);
1970 else if (base->mysql.tablename) {
1971 mrg->mysql.tablename = apr_pstrdup(p, base->mysql.tablename);
1974 mrg->mysql.tablename = NULL;
1977 if (add->mysql.socket_path) {
1978 mrg->mysql.socket_path = apr_pstrdup(p, add->mysql.socket_path);
1980 else if (base->mysql.socket_path) {
1981 mrg->mysql.socket_path = apr_pstrdup(p, base->mysql.socket_path);
1984 mrg->mysql.socket_path = NULL;
1987 if (add->mysql.charset) {
1988 mrg->mysql.charset = apr_pstrdup(p, add->mysql.charset);
1990 else if (base->mysql.charset) {
1991 mrg->mysql.charset = apr_pstrdup(p, base->mysql.charset);
1994 mrg->mysql.charset = NULL;
1997 #if defined(USE_MEMCACHE_COOKIE)
1998 if (add->memcache.host) {
1999 mrg->memcache.host = apr_pstrdup(p, add->memcache.host);
2001 else if (base->memcache.host) {
2002 mrg->memcache.host = apr_pstrdup(p, base->memcache.host);
2005 mrg->memcache.host = NULL;
2007 if (add->memcache.port) {
2008 mrg->memcache.port = add->memcache.port;
2010 else if (base->memcache.port) {
2011 mrg->memcache.port = base->memcache.port;
2014 mrg->memcache.port = 0;
2017 if (add->cookie_store_type) {
2018 mrg->cookie_store_type = add->cookie_store_type;
2020 else if (base->cookie_store_type) {
2021 mrg->cookie_store_type = base->cookie_store_type;
2024 mrg->cookie_store_type = COOKIE_STORE_TYPE_NONE;
2026 if (add->cookie_lazy_mode) {
2027 mrg->cookie_lazy_mode = add->cookie_lazy_mode;
2029 else if (base->cookie_lazy_mode) {
2030 mrg->cookie_lazy_mode = base->cookie_lazy_mode;
2033 mrg->cookie_lazy_mode = 0;
2035 if (add->new_line_type) {
2036 mrg->new_line_type = add->new_line_type;
2038 else if (base->new_line_type) {
2039 mrg->new_line_type = base->new_line_type;
2042 mrg->new_line_type = NLTYPE_NIL;
2045 if (add->forward_url_base) {
2046 mrg->forward_url_base = add->forward_url_base;
2048 else if (base->forward_url_base) {
2049 mrg->forward_url_base = base->forward_url_base;
2052 if (add->allowed_cookie_domain) {
2053 mrg->allowed_cookie_domain = add->allowed_cookie_domain;
2056 mrg->allowed_cookie_domain = base->allowed_cookie_domain;
2058 if (add->post_log) {
2059 mrg->post_log = add->post_log;
2062 mrg->post_log = base->post_log;
2064 if (add->cookie_dbm_type) {
2065 mrg->cookie_dbm_type = add->cookie_dbm_type;
2068 mrg->cookie_dbm_type = base->cookie_dbm_type;
2071 if (add->imode_emoji_color == CHXJ_IMODE_EMOJI_COLOR_NONE) {
2072 mrg->imode_emoji_color = base->imode_emoji_color;
2075 mrg->imode_emoji_color = add->imode_emoji_color;
2078 if (add->detect_device_type == CHXJ_ADD_DETECT_DEVICE_TYPE_NONE) {
2079 mrg->detect_device_type = base->detect_device_type;
2082 mrg->detect_device_type = add->detect_device_type;
2085 if (add->device_keys) {
2086 mrg->device_keys = add->device_keys;
2089 mrg->device_keys = base->device_keys;
2092 if (add->device_hash) {
2093 mrg->device_hash = add->device_hash;
2096 mrg->device_hash = base->device_hash;
2099 if (add->image_rewrite == CHXJ_IMG_REWRITE_NONE){
2100 mrg->image_rewrite = base->image_rewrite;
2103 mrg->image_rewrite = add->image_rewrite;
2106 if (add->image_rewrite_url) {
2107 mrg->image_rewrite_url = add->image_rewrite_url;
2110 mrg->image_rewrite_url = base->image_rewrite_url;
2113 if (add->image_rewrite_mode == CHXJ_IMG_REWRITE_MODE_NONE){
2114 mrg->image_rewrite_mode = base->image_rewrite_mode;
2117 mrg->image_rewrite_mode = add->image_rewrite_mode;
2125 chxj_command_parse_take5(
2138 for (;*strp == ' '||*strp == '\t'; strp++) ;
2148 for (; *strp != '\0'; strp++) {
2149 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2150 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2155 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2156 || (isquoted && *strp == '"'))
2170 for (;*strp == ' '||*strp == '\t'; strp++) ;
2179 for (; *strp != '\0'; strp++) {
2180 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2181 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2186 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2187 || (isquoted && *strp == '"'))
2200 for (;*strp == ' '||*strp == '\t'; strp++);
2208 for (; *strp != '\0'; strp++) {
2209 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2210 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2215 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2216 || (isquoted && *strp == '"'))
2228 for (;*strp == ' '||*strp == '\t'; strp++);
2236 for (; *strp != '\0'; strp++) {
2237 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2238 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2243 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2244 || (isquoted && *strp == '"'))
2255 for (;*strp == ' '||*strp == '\t'; strp++);
2263 for (; *strp != '\0'; strp++) {
2264 if ((isquoted && (*strp == ' ' || *strp == '\t'))
2265 || (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2270 if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2271 || (isquoted && *strp == '"'))
2281 * The device definition file is loaded.
2283 * @param arg [i] The name of the device definition file is specified.
2284 * @param mconfig [i/o] The pointer to a set structure is specified.
2288 cmd_load_device_data(cmd_parms *parms, void *mconfig, const char *arg)
2290 mod_chxj_config *conf;
2295 if (strlen(arg) > 256)
2296 return "mod_chxj: device data filename too long.";
2298 conf = (mod_chxj_config *)mconfig;
2299 conf->device_data_file = apr_pstrdup(parms->pool, arg);
2301 qs_init_malloc(&doc);
2302 qs_init_root_node(&doc);
2304 qs_parse_file((Doc *)&doc, (const char *)arg);
2305 chxj_load_device_data(&doc,parms->pool, conf);
2306 qs_all_free(&doc, QX_LOGMARK);
2313 * Device definition information is loaded.
2316 * @param arg [i] The name of the device definition file is specified.
2317 * @param mconfig [i/o] The pointer to a set structure is specified.
2321 cmd_load_emoji_data(cmd_parms *parms, void *mconfig, const char *arg)
2323 mod_chxj_config *conf;
2330 if (strlen(arg) > 256)
2331 return "mod_chxj: emoji data filename too long.";
2333 conf = (mod_chxj_config *)mconfig;
2334 conf->emoji_data_file = apr_pstrdup(parms->pool, arg);
2335 qs_init_malloc(&doc);
2336 qs_init_root_node(&doc);
2338 qs_parse_file((Doc *)&doc, (const char *)arg);
2340 rtn = chxj_load_emoji_data(&doc,parms->pool, conf);
2342 qs_all_free(&doc, QX_LOGMARK);
2350 cmd_set_image_engine(cmd_parms * UNUSED(parms), void *mconfig, const char *arg)
2352 mod_chxj_config *conf;
2357 if (strlen(arg) > 256)
2358 return "image uri is too long.";
2360 conf = (mod_chxj_config*)mconfig;
2361 if (strcasecmp("ON", arg) == 0) {
2362 conf->image = CHXJ_IMG_ON;
2365 conf->image = CHXJ_IMG_OFF;
2373 cmd_set_image_cache_dir(cmd_parms *parms, void *mconfig, const char *arg)
2375 mod_chxj_config *conf;
2380 if (strlen(arg) > 256)
2381 return "cache dir name is too long.";
2384 apr_status_t res = apr_stat(&info,arg,APR_FINFO_TYPE,parms->pool);
2385 if(res != APR_SUCCESS){
2386 return apr_psprintf(parms->pool,"ChxjImageCacheDir [%s]: not found ",arg);
2389 if(info.filetype != APR_DIR){
2390 return apr_psprintf(parms->pool,"ChxjImageCacheDir [%s]: is not directory ",arg);
2394 conf = (mod_chxj_config *)mconfig;
2395 conf->image_cache_dir = apr_pstrdup(parms->pool, arg);
2402 cmd_set_image_cache_limit(cmd_parms *parms, void *mconfig, const char *arg)
2404 mod_chxj_config *conf;
2409 if (strlen(arg) > IMAGE_CACHE_LIMIT_FMT_LEN)
2410 return "cache size is too long.";
2412 conf = (mod_chxj_config *)mconfig;
2415 * I use strtol function because strtoul is not portable function.
2417 conf->image_cache_limit = (unsigned long)strtol(arg, NULL, 10);
2420 return apr_psprintf(parms->pool, "ChxjImageCacheLimit invalid value [%s] errno:[%d]", arg, errno);
2422 return apr_psprintf(parms->pool, "ChxjImageCacheLimit Out of range [%s] errno:[%d]", arg, errno);
2431 cmd_set_image_copyright(cmd_parms *parms, void *mconfig, const char *arg)
2433 mod_chxj_config *conf;
2438 if (strlen(arg) > 256)
2439 return "Copyright Flag is too long.";
2441 conf = (mod_chxj_config *)mconfig;
2442 conf->image_copyright = apr_pstrdup(parms->pool, arg);
2449 cmd_convert_rule(cmd_parms *cmd, void *mconfig, const char *arg)
2453 mod_chxj_config *dconf;
2454 chxjconvrule_entry *newrule;
2464 dconf = (mod_chxj_config *)mconfig;
2466 if (strlen(arg) > 4096)
2467 return "mod_chxj: ChxjConvertRule: is too long.";
2469 dconf = (mod_chxj_config *)mconfig;
2470 if (dconf->convrules == NULL)
2471 dconf->convrules = apr_array_make(cmd->pool,
2473 sizeof(chxjconvrule_entry));
2475 newrule = apr_array_push(dconf->convrules);
2478 newrule->action = 0;
2480 if (chxj_command_parse_take5(arg, &prm1, &prm2, &prm3, &prm4, &prm5))
2481 return "ChxjConvertRule: bad argument line";
2483 newrule->pattern = apr_pstrdup(cmd->pool, prm1);
2487 if ((action = apr_strtok(prm2, ",", &pstate)) == NULL)
2493 if (strcasecmp(CONVRULE_ENGINE_ON_CMD, action) == 0) {
2494 newrule->action |= CONVRULE_ENGINE_ON_BIT;
2497 if (strcasecmp(CONVRULE_ENGINE_OFF_CMD, action) == 0) {
2498 newrule->action |= CONVRULE_ENGINE_OFF_BIT;
2501 if (strcasecmp(CONVRULE_EMOJI_ONLY_CMD, action) == 0) {
2502 newrule->action |= CONVRULE_EMOJI_ONLY_BIT;
2505 if (strcasecmp(CONVRULE_ENVINFO_ONLY_CMD, action) == 0) {
2506 newrule->action |= CONVRULE_ENVINFO_ONLY_BIT;
2512 if (strcasecmp(CONVRULE_COOKIE_ON_CMD, action) == 0) {
2513 newrule->action |= CONVRULE_COOKIE_ON_BIT;
2515 else if (strcasecmp(CONVRULE_COOKIE_OFF_CMD, action) == 0) {
2516 newrule->action &= (0xffffffff ^ CONVRULE_COOKIE_ON_BIT);
2518 else if (strcasecmp(CONVRULE_CSS_ON_CMD, action) == 0) {
2519 newrule->action |= CONVRULE_CSS_ON_BIT;
2521 else if (strcasecmp(CONVRULE_CSS_OFF_CMD, action) == 0) {
2522 newrule->action &= (0xffffffff ^ CONVRULE_CSS_ON_BIT);
2524 else if (strcasecmp(CONVRULE_COOKIE_ONLY_CMD, action) == 0) {
2525 newrule->action |= CONVRULE_COOKIE_ONLY_BIT;
2531 if (strcasecmp(CONVRULE_JRCONV_OFF_CMD, action) == 0) {
2532 newrule->action |= CONVRULE_JRCONV_OFF_BIT;
2538 if (strcasecmp(CONVRULE_NOCACHE_ON_CMD, action) == 0) {
2539 newrule->action |= CONVRULE_NOCACHE_ON_BIT;
2545 if (strcasecmp(CONVRULE_QSCONV_OFF_CMD, action) == 0) {
2546 newrule->action |= CONVRULE_QSCONV_OFF_BIT;
2552 if (strcasecmp(CONVRULE_Z2H_ON_CMD, action) == 0) {
2553 newrule->action |= CONVRULE_Z2H_ON_BIT;
2556 if (strcasecmp(CONVRULE_Z2H_OFF_CMD, action) == 0) {
2557 newrule->action |= CONVRULE_Z2H_OFF_BIT;
2560 if (strcasecmp(CONVRULE_Z2H_ALPHA_ON_CMD, action) == 0) {
2561 newrule->action |= CONVRULE_Z2H_ALPHA_ON_BIT;
2564 if (strcasecmp(CONVRULE_Z2H_ALPHA_OFF_CMD, action) == 0) {
2565 newrule->action |= CONVRULE_Z2H_ALPHA_OFF_BIT;
2568 if (strcasecmp(CONVRULE_Z2H_NUM_ON_CMD, action) == 0) {
2569 newrule->action |= CONVRULE_Z2H_NUM_ON_BIT;
2572 if (strcasecmp(CONVRULE_Z2H_NUM_OFF_CMD, action) == 0) {
2573 newrule->action |= CONVRULE_Z2H_NUM_OFF_BIT;
2576 if (strcasecmp(CONVRULE_Z2H_ALL_ON_CMD, action) == 0) {
2577 newrule->action |= CONVRULE_Z2H_ON_BIT | CONVRULE_Z2H_ALPHA_ON_BIT | CONVRULE_Z2H_NUM_ON_BIT;
2580 if (strcasecmp(CONVRULE_Z2H_NUM_OFF_CMD, action) == 0) {
2581 newrule->action |= CONVRULE_Z2H_OFF_BIT | CONVRULE_Z2H_ALPHA_OFF_BIT | CONVRULE_Z2H_NUM_OFF_BIT;
2592 newrule->flags |= CONVRULE_FLAG_NOTMATCH;
2596 mode = AP_REG_EXTENDED;
2597 if ((regexp = ap_pregcomp((apr_pool_t *)cmd->pool, (const char *)pp, mode)) == NULL)
2598 return "RewriteRule: cannot compile regular expression ";
2600 newrule->regexp = regexp;
2602 newrule->encoding = apr_pstrdup(cmd->pool, prm3);
2604 newrule->encoding = apr_pstrdup(cmd->pool, "none");
2606 newrule->pc_flag = CONVRULE_PC_FLAG_OFF_BIT;
2608 if (strcasecmp(CONVRULE_PC_FLAG_ON_CMD, prm4) == 0)
2609 newrule->pc_flag = CONVRULE_PC_FLAG_ON_BIT;
2611 newrule->user_agent = NULL;
2613 newrule->user_agent = apr_pstrdup(cmd->pool, prm5);
2625 mod_chxj_config *dconf;
2628 if (strlen(arg) > 4096)
2629 return "mod_chxj: ChxjCookieDir is too long.";
2631 dconf = (mod_chxj_config *)mconfig;
2633 dconf->cookie_db_dir = apr_pstrdup(cmd->pool, arg);
2640 cmd_set_cookie_timeout(
2641 cmd_parms *UNUSED(cmd),
2645 mod_chxj_config *dconf;
2647 if (strlen(arg) > 4096)
2648 return "mod_chxj: ChxjCookieTimeout is too long.";
2650 if (chxj_chk_numeric(arg) != 0)
2651 return "mod_chxj: ChxjCookieTimeout is not numeric.";
2653 dconf = (mod_chxj_config *)mconfig;
2655 dconf->cookie_timeout = atoi(arg);
2661 #if defined(USE_MYSQL_COOKIE)
2663 cmd_set_cookie_mysql_database(
2668 mod_chxj_config *dconf;
2670 if (strlen(arg) > 255)
2671 return "mod_chxj: ChxjCookieMysqlDatabase is too long.";
2673 dconf = (mod_chxj_config *)mconfig;
2675 dconf->mysql.database = apr_pstrdup(cmd->pool, arg);
2682 cmd_set_cookie_mysql_username(
2687 mod_chxj_config *dconf;
2689 if (strlen(arg) > 255)
2690 return "mod_chxj: ChxjCookieMysqlUsername is too long.";
2692 dconf = (mod_chxj_config *)mconfig;
2694 dconf->mysql.username = apr_pstrdup(cmd->pool, arg);
2701 cmd_set_cookie_mysql_password(
2706 mod_chxj_config *dconf;
2708 if (strlen(arg) > 255)
2709 return "mod_chxj: ChxjCookieMysqlPassword is too long.";
2711 dconf = (mod_chxj_config *)mconfig;
2713 dconf->mysql.password = apr_pstrdup(cmd->pool, arg);
2720 cmd_set_cookie_mysql_table_name(
2725 mod_chxj_config *dconf;
2727 if (strlen(arg) > 255)
2728 return "mod_chxj: ChxjCookieMysqlTableName is too long.";
2730 dconf = (mod_chxj_config *)mconfig;
2732 dconf->mysql.tablename = apr_pstrdup(cmd->pool, arg);
2738 cmd_set_cookie_mysql_port(
2739 cmd_parms *UNUSED(cmd),
2743 mod_chxj_config *dconf;
2745 if (strlen(arg) > 255)
2746 return "mod_chxj: ChxjCookieMysqlPort is too long.";
2748 dconf = (mod_chxj_config *)mconfig;
2750 if (chxj_chk_numeric(arg) != 0)
2751 return "mod_chxj: ChxjCookieMysqlPort is not numeric.";
2753 dconf = (mod_chxj_config *)mconfig;
2755 dconf->mysql.port = chxj_atoi(arg);
2762 cmd_set_cookie_mysql_host(
2767 mod_chxj_config *dconf;
2769 if (strlen(arg) > 255)
2770 return "mod_chxj: ChxjCookieMysqlHost is too long.";
2772 dconf = (mod_chxj_config *)mconfig;
2774 dconf->mysql.host = apr_pstrdup(cmd->pool, arg);
2781 cmd_set_cookie_mysql_socket_path(
2786 mod_chxj_config *dconf;
2788 if (strlen(arg) > 4096)
2789 return "mod_chxj: ChxjCookieMysqlSocketPath is too long.";
2791 dconf = (mod_chxj_config *)mconfig;
2793 dconf->mysql.socket_path = apr_pstrdup(cmd->pool, arg);
2800 cmd_set_cookie_mysql_charset(
2805 mod_chxj_config *dconf;
2807 if (strlen(arg) > 255)
2808 return "mod_chxj: ChxjCookieMysqlCharset is too long.";
2810 dconf = (mod_chxj_config *)mconfig;
2812 dconf->mysql.charset = apr_pstrdup(cmd->pool, arg);
2817 #if defined(USE_MEMCACHE_COOKIE)
2819 cmd_set_cookie_memcache_port(
2820 cmd_parms *UNUSED(cmd),
2824 mod_chxj_config *dconf;
2826 if (strlen(arg) > 255)
2827 return "mod_chxj: ChxjCookieMemcachePort is too long.";
2829 dconf = (mod_chxj_config *)mconfig;
2831 if (chxj_chk_numeric(arg) != 0)
2832 return "mod_chxj: ChxjCookieMemcachePort is not numeric.";
2834 dconf = (mod_chxj_config *)mconfig;
2836 dconf->memcache.port = (apr_port_t)chxj_atoi(arg);
2843 cmd_set_cookie_memcache_host(
2848 mod_chxj_config *dconf;
2850 if (strlen(arg) > 255)
2851 return "mod_chxj: ChxjCookieMemcacheHost is too long.";
2853 dconf = (mod_chxj_config *)mconfig;
2855 dconf->memcache.host = apr_pstrdup(cmd->pool, arg);
2862 cmd_set_cookie_lazy_mode(
2863 cmd_parms *UNUSED(cmd),
2867 mod_chxj_config *dconf;
2869 if (strlen(arg) > 255)
2870 return "mod_chxj: ChxjCookieLazyMode is too long.";
2872 dconf = (mod_chxj_config *)mconfig;
2874 if (strcasecmp("TRUE",arg) == 0) {
2875 dconf->cookie_lazy_mode = COOKIE_LAZY_ON;
2878 dconf->cookie_lazy_mode = COOKIE_LAZY_OFF;
2885 cmd_set_cookie_store_type(
2886 cmd_parms *UNUSED(cmd),
2890 mod_chxj_config *dconf;
2892 if (strlen(arg) > 255)
2893 return "mod_chxj: ChxjCookieStoreType is too long.";
2895 dconf = (mod_chxj_config *)mconfig;
2897 if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_DBM, arg) == 0) {
2898 dconf->cookie_store_type = COOKIE_STORE_TYPE_DBM;
2900 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MYSQL, arg) == 0) {
2901 dconf->cookie_store_type = COOKIE_STORE_TYPE_MYSQL;
2903 else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MEMCACHE, arg) == 0) {
2904 dconf->cookie_store_type = COOKIE_STORE_TYPE_MEMCACHE;
2907 dconf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
2914 cmd_set_forward_url_base(
2919 mod_chxj_config *dconf;
2921 if (strlen(arg) > 255)
2922 return "mod_chxj: ChxjForwardUrlBase is too long.";
2924 dconf = (mod_chxj_config *)mconfig;
2926 dconf->forward_url_base = apr_pstrdup(cmd->pool, arg);
2932 cmd_set_forward_server_ip(
2937 mod_chxj_config *dconf;
2939 if (strlen(arg) > 255)
2940 return "mod_chxj: ChxjForwardServerIp is too long.";
2942 dconf = (mod_chxj_config *)mconfig;
2944 dconf->forward_server_ip = apr_pstrdup(cmd->pool, arg);
2950 cmd_allowed_cookie_domain(
2955 mod_chxj_config *dconf;
2957 if (strlen(arg) > 255)
2958 return "mod_chxj: ChxjAllowedCookieDomain is too long.";
2960 dconf = (mod_chxj_config *)mconfig;
2962 dconf->allowed_cookie_domain = apr_pstrdup(cmd->pool, arg);
2968 cmd_set_new_line_type(
2969 cmd_parms *UNUSED(cmd),
2973 mod_chxj_config *dconf;
2974 if (strlen(arg) > 255)
2975 return "mod_chxj: ChxjNewLineType is too long.";
2977 dconf = (mod_chxj_config *)mconfig;
2979 if (strcasecmp(CHXJ_NEW_LINE_TYPE_CRLF, arg) == 0) {
2980 dconf->new_line_type = NLTYPE_CRLF;
2982 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_LF, arg) == 0) {
2983 dconf->new_line_type = NLTYPE_LF;
2985 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_CR, arg) == 0) {
2986 dconf->new_line_type = NLTYPE_CR;
2988 else if (strcasecmp(CHXJ_NEW_LINE_TYPE_NONE, arg) == 0) {
2989 dconf->new_line_type = NLTYPE_NONE;
2992 return "mod_chxj: invalid value (ChxjNewLineType)";
3003 mod_chxj_config *dconf;
3004 if (strlen(arg) > 255)
3005 return "mod_chxj: ChxjPostLogEnv is too long.";
3007 dconf = (mod_chxj_config *)mconfig;
3009 dconf->post_log = apr_pstrdup(cmd->pool, arg);
3015 cmd_cookie_dbm_type(
3020 mod_chxj_config *dconf;
3021 if (strlen(arg) > 255)
3022 return "mod_chxj: ChxjCookieDbmType is too long.";
3024 dconf = (mod_chxj_config *)mconfig;
3026 dconf->cookie_dbm_type = apr_pstrdup(cmd->pool, arg);
3032 cmd_imode_emoji_color(
3037 mod_chxj_config *dconf;
3039 if (strlen(arg) > 256)
3040 return "imode emoji color is too long.";
3042 dconf = (mod_chxj_config *)mconfig;
3043 if (strcasecmp("ON", arg) == 0) {
3044 dconf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_ON;
3046 else if(strcasecmp("AUTO",arg) == 0) {
3047 dconf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_AUTO;
3050 dconf->imode_emoji_color = CHXJ_IMODE_EMOJI_COLOR_OFF;
3057 cmd_add_device_data_tsv(cmd_parms *parms, void *mconfig, const char *arg)
3059 mod_chxj_config *conf;
3061 if (strlen(arg) > 256)
3062 return "mod_chxj: device tsv filename too long.";
3064 conf = (mod_chxj_config *)mconfig;
3066 conf->detect_device_type = CHXJ_ADD_DETECT_DEVICE_TYPE_TSV;
3069 apr_status_t res = apr_stat(&info,arg,APR_FINFO_TYPE,parms->pool);
3070 if(res != APR_SUCCESS){
3071 return apr_psprintf(parms->pool,"ChxjDeviceTSV [%s]: not found ",arg);
3074 if(info.filetype != APR_REG ){
3075 return apr_psprintf(parms->pool,"ChxjDeviceTSV [%s]: is not file ",arg);
3079 apr_file_open(&fp, arg, APR_READ|APR_BUFFERED, APR_OS_DEFAULT, parms->pool);
3081 chxj_load_device_tsv_data(fp,parms->pool,conf);
3088 cmd_image_rewrite(cmd_parms *parms, void *mconfig, const char *arg)
3090 mod_chxj_config *conf;
3091 if (strlen(arg) > 256){
3092 return "mod_chxj: set rewrite too long.";
3094 conf = (mod_chxj_config *)mconfig;
3095 if (strcasecmp("ON", arg) == 0) {
3096 conf->image_rewrite = CHXJ_IMG_REWRITE_ON;
3098 else if(strcasecmp("OFF",arg) == 0) {
3099 conf->image_rewrite = CHXJ_IMG_REWRITE_OFF;
3102 conf->image_rewrite = CHXJ_IMG_REWRITE_NONE;
3108 cmd_image_rewrite_url(cmd_parms *parms, void *mconfig, const char *arg)
3110 mod_chxj_config *conf;
3111 if (strlen(arg) > 256){
3112 return "mod_chxj: set rewrite url too long.";
3114 conf = (mod_chxj_config *)mconfig;
3115 conf->image_rewrite_url = apr_pstrdup(parms->pool, arg);;
3120 cmd_image_rewrite_mode(cmd_parms *parms, void *mconfig, const char *arg)
3122 mod_chxj_config *conf;
3123 if (strlen(arg) > 256){
3124 return "mod_chxj: set rewrite mode is too long.";
3127 conf = (mod_chxj_config *)mconfig;
3128 if (strcasecmp("all",arg) == 0) {
3129 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_ALL;
3131 else if (strcasecmp("user",arg) == 0) {
3132 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_USER;
3134 else if (strcasecmp("tag",arg) == 0) {
3135 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_USER;
3138 conf->image_rewrite_mode = CHXJ_IMG_REWRITE_MODE_NONE;
3143 static const command_rec cmds[] = {
3145 "ChxjLoadDeviceData",
3146 cmd_load_device_data,
3149 "Load Device Data"),
3151 "ChxjLoadEmojiData",
3152 cmd_load_emoji_data,
3158 cmd_set_image_engine,
3161 "Convert Target URI"),
3163 "ChxjImageCacheDir",
3164 cmd_set_image_cache_dir,
3167 "Image Cache Directory"),
3169 "ChxjImageCacheLimit",
3170 cmd_set_image_cache_limit,
3173 "Image Cache Limit"),
3175 "ChxjImageCopyright",
3176 cmd_set_image_copyright,
3185 "an URL-applied regexp-pattern and a substitution URL"),
3191 "save cookie.db directory."),
3193 "ChxjCookieTimeout",
3194 cmd_set_cookie_timeout,
3197 "The compulsion time-out time of the cookie is specified. "),
3199 "ChxjCookieStoreType",
3200 cmd_set_cookie_store_type,
3203 "It specifies preserving of the cookie ahead. (DBM/MYSQL/MEMCACHE)"),
3205 "ChxjCookieLazyMode",
3206 cmd_set_cookie_lazy_mode,
3209 "OneTimeID is negligently done. (TRUE/FALSE)"),
3210 #if defined(USE_MYSQL_COOKIE)
3212 "ChxjCookieMysqlHost",
3213 cmd_set_cookie_mysql_host,
3216 "The MySQL database host used by saving Cookie"),
3218 "ChxjCookieMysqlPort",
3219 cmd_set_cookie_mysql_port,
3222 "The MySQL database port used by saving Cookie"),
3224 "ChxjCookieMysqlDatabase",
3225 cmd_set_cookie_mysql_database,
3228 "The MySQL database name used by saving Cookie"),
3230 "ChxjCookieMysqlUsername",
3231 cmd_set_cookie_mysql_username,
3234 "The MySQL username used by saving Cookie"),
3236 "ChxjCookieMysqlPassword",
3237 cmd_set_cookie_mysql_password,
3240 "The MySQL password used by saving Cookie"),
3242 "ChxjCookieMysqlTableName",
3243 cmd_set_cookie_mysql_table_name,
3246 "The MySQL table name used by saving Cookie"),
3248 "ChxjCookieMysqlSocketPath",
3249 cmd_set_cookie_mysql_socket_path,
3252 "The MySQL socket path used by saving Cookie"),
3254 "ChxjCookieMysqlCharset",
3255 cmd_set_cookie_mysql_charset,
3258 "The MySQL charset used by saving Cookie"),
3260 #if defined(USE_MEMCACHE_COOKIE)
3262 "ChxjCookieMemcacheHost",
3263 cmd_set_cookie_memcache_host,
3266 "The Memcached host used by saving Cookie"),
3268 "ChxjCookieMemcachePort",
3269 cmd_set_cookie_memcache_port,
3272 "The Memcached port used by saving Cookie"),
3276 cmd_set_new_line_type,
3279 "HTML new line type (NONE|CRLF|LF|CR). default is CRLF"),
3281 "ChxjForwardUrlBase",
3282 cmd_set_forward_url_base,
3285 "The forward url base(default: {request protocol}://{this server}:{this server port}"),
3287 "ChxjForwardServerIp",
3288 cmd_set_forward_server_ip,
3291 "The forward server ip(default: this server ip)"),
3293 "ChxjAllowedCookieDomain",
3294 cmd_allowed_cookie_domain,
3297 "Domain that permits parameter addition for cookie besides hostname.(Default:hostname Only)"),
3303 "for CustomLog directive. mod_chxj's internal POST log environment name.(Default:chxj-post-log)"),
3305 "ChxjCookieDbmType",
3306 cmd_cookie_dbm_type,
3309 "Kind of DBM used with Cookie simulator.(default|GDBM|SDBM|DB|NDBM)"),
3311 "ChxjImodeEmojiColor",
3312 cmd_imode_emoji_color,
3315 "Auto i-mode emoji color"),
3317 "ChxjAddDeviceDataTSV",
3318 cmd_add_device_data_tsv,
3321 "Additional devices TSV data"),
3330 "ChxjImageRewriteUrl",
3331 cmd_image_rewrite_url,
3334 "Set rewrite Image url"
3337 "ChxjImageRewriteMode",
3338 cmd_image_rewrite_mode,
3341 "Set rewrite Image rewrite url mode"
3343 {NULL,{NULL},NULL,0,0,NULL},
3347 /*----------------------------------------------------------------------------*/
3348 /* Dispatch list for API hooks */
3349 /*----------------------------------------------------------------------------*/
3350 module AP_MODULE_DECLARE_DATA chxj_module = {
3351 STANDARD20_MODULE_STUFF,
3352 chxj_create_per_dir_config, /* create per-dir config structures */
3353 chxj_merge_per_dir_config, /* merge per-dir config structures */
3354 chxj_config_server_create, /* create per-server config structures */
3355 NULL, /* merge per-server config structures */
3356 cmds, /* table of config file commands */
3357 chxj_register_hooks /* register hooks */