OSDN Git Service

Merge branch 'branch_0.12.0' into branch_0.13.0
[modchxj/mod_chxj.git] / src / mod_chxj.c
1 /*
2  * Copyright (C) 2005-2009 Atsushi Konno All rights reserved.
3  * Copyright (C) 2005 QSDN,Inc. All rights reserved.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17 #include <unistd.h>
18 #include <string.h>
19 #include <limits.h>
20 #include <errno.h>
21
22 #include "httpd.h"
23 #include "http_config.h"
24 #include "http_core.h"
25 #include "http_protocol.h"
26 #include "http_log.h"
27 #include "ap_config.h"
28 #include "apr_strings.h"
29 #include "util_filter.h"
30 #include "apr_buckets.h"
31 #include "apr_lib.h"
32 #include "apr_tables.h"
33 #include "apr_dso.h"
34 #include "apr_general.h"
35 #include "apr_pools.h"
36
37 #include "mod_chxj.h"
38 #include "chxj_encoding.h"
39 #include "qs_ignore_sp.h"
40 #include "qs_log.h"
41 #include "qs_malloc.h"
42 #include "qs_parse_attr.h"
43 #include "qs_parse_file.h"
44 #include "qs_parse_string.h"
45 #include "qs_parse_tag.h"
46 #include "chxj_load_device_data.h"
47 #include "chxj_load_emoji_data.h"
48 #include "chxj_specified_device.h"
49 #include "chxj_tag_util.h"
50 #include "chxj_xhtml_mobile_1_0.h"
51 #include "chxj_hdml.h"
52 #include "chxj_chtml10.h"
53 #include "chxj_chtml20.h"
54 #include "chxj_chtml30.h"
55 #include "chxj_chtml40.h"
56 #include "chxj_chtml50.h"
57 #include "chxj_ixhtml10.h"
58 #include "chxj_jhtml.h"
59 #include "chxj_jxhtml.h"
60 #include "chxj_img_conv_format.h"
61 #include "chxj_qr_code.h"
62 #include "chxj_encoding.h"
63 #include "chxj_apply_convrule.h"
64 #include "chxj_cookie.h"
65 #include "chxj_url_encode.h"
66 #include "chxj_str_util.h"
67 #include "chxj_dump_string.h"
68 #if defined(USE_MYSQL_COOKIE)
69 #  include "chxj_mysql.h"
70 #endif
71 #include "chxj_serf.h"
72 #include "chxj_add_device_env.h"
73 #include "chxj_header_inf.h"
74 #include "chxj_jreserved_tag.h"
75
76
77 #define CHXJ_VERSION_PREFIX PACKAGE_NAME "/"
78 #define CHXJ_VERSION        PACKAGE_VERSION
79 #define CHXJ_POST_MAX       (0x1000000)
80
81 converter_t convert_routine[] = {
82   {
83     /* CHXJ_SPEC_UNKNOWN          */
84     .converter            = NULL,
85     .encoder              = NULL,
86     .emoji_only_converter = NULL,
87   },
88   {
89     /* CHXJ_SPEC_Chtml_1_0        */
90     .converter            = chxj_convert_chtml10,
91     .encoder              = chxj_encoding,
92     .emoji_only_converter = chxj_chtml10_emoji_only_converter,
93   },
94   {
95     /* CHXJ_SPEC_Chtml_2_0        */
96     .converter            = chxj_convert_chtml20,
97     .encoder              = chxj_encoding,
98     .emoji_only_converter = chxj_chtml20_emoji_only_converter,
99   },
100   {
101     /* CHXJ_SPEC_Chtml_3_0        */
102     .converter            = chxj_convert_chtml30,
103     .encoder              = chxj_encoding,
104     .emoji_only_converter = chxj_chtml30_emoji_only_converter,
105   },
106   {
107     /* CHXJ_SPEC_Chtml_4_0        */
108     .converter            = chxj_convert_chtml40,
109     .encoder              = chxj_encoding,
110     .emoji_only_converter = chxj_chtml40_emoji_only_converter,
111   },
112   {
113     /* CHXJ_SPEC_Chtml_5_0        */
114     .converter            = chxj_convert_chtml50,
115     .encoder              = chxj_encoding,
116     .emoji_only_converter = chxj_chtml50_emoji_only_converter,
117   },
118   {
119     /* CHXJ_SPEC_Chtml_6_0        */
120     .converter = chxj_convert_ixhtml10,
121     .encoder  = chxj_encoding,
122     .emoji_only_converter = chxj_chtml50_emoji_only_converter, /* XXX: TODO */
123   },
124   {
125     /* CHXJ_SPEC_Chtml_7_0        */
126     .converter = chxj_convert_ixhtml10,
127     .encoder  = chxj_encoding,
128     .emoji_only_converter = chxj_chtml50_emoji_only_converter, /* XXX: TODO */
129   },
130   {
131     /* CHXJ_SPEC_XHtml_Mobile_1_0 */
132     .converter            = chxj_convert_xhtml_mobile_1_0,
133     .encoder              = chxj_encoding,
134     .emoji_only_converter = chxj_xhtml_emoji_only_converter,
135   },
136   {
137     /* CHXJ_SPEC_Hdml             */
138     .converter            = chxj_convert_hdml,
139     .encoder              = chxj_encoding,
140     .emoji_only_converter = NULL,
141   },
142   {
143     /* CHXJ_SPEC_Jhtml            */
144     .converter            = chxj_convert_jhtml,
145     .encoder              = chxj_encoding,
146     .emoji_only_converter = chxj_jhtml_emoji_only_converter,
147   },
148   {
149     /* CHXJ_SPEC_Jxhtml            */
150     .converter            = chxj_convert_jxhtml,
151     .encoder              = chxj_encoding,
152     .emoji_only_converter = chxj_jxhtml_emoji_only_converter,
153   },
154   {
155     /* CHXJ_SPEC_HTML             */
156     .converter = NULL,
157     .encoder  = NULL,
158     .emoji_only_converter = NULL,
159   },
160 };
161
162 static int chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp, device_table *spec);
163 static void s_convert_guid_parameter_to_header(request_rec *r, const char *param, device_table *spec);
164 static void s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie);
165 static void s_clear_cookie_header(request_rec *r, device_table *spec);
166 static void s_add_no_cache_headers(request_rec *r, chxjconvrule_entry  *entryp);
167
168 /**
169  * Only when User-Agent is specified, the User-Agent header is camouflaged. 
170  *
171  * @param r   [i]
172  */
173 static apr_status_t 
174 chxj_headers_fixup(request_rec *r)
175 {
176   mod_chxj_config*    dconf; 
177   chxjconvrule_entry* entryp;
178   char*               user_agent;
179   device_table*       spec;
180   char                *contentType;
181   char                *contentLength;
182
183   DBG(r, "REQ[%X] start chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
184   if (r->main) {
185     DBG(r, "REQ[%X] detect internal redirect.", (unsigned int)(apr_size_t)r);
186     DBG(r, "REQ[%X] end chxj_headers_fixup()",  (unsigned int)(apr_size_t)r);
187     return DECLINED;
188   }
189
190   dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
191
192   user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
193   spec = chxj_specified_device(r, user_agent);
194
195   contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
196   if (contentType
197       && strncasecmp("multipart/form-data", contentType, 19) == 0) {
198     DBG(r, "REQ[%X] detect multipart/form-data ==> no target", (unsigned int)(apr_size_t)r);
199     DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
200     return DECLINED;
201   }
202
203
204   switch(spec->html_spec_type) {
205   case CHXJ_SPEC_Chtml_1_0:
206   case CHXJ_SPEC_Chtml_2_0:
207   case CHXJ_SPEC_Chtml_3_0:
208   case CHXJ_SPEC_Chtml_4_0:
209   case CHXJ_SPEC_Chtml_5_0:
210   case CHXJ_SPEC_Chtml_6_0:
211   case CHXJ_SPEC_Chtml_7_0:
212   case CHXJ_SPEC_XHtml_Mobile_1_0:
213   case CHXJ_SPEC_Hdml:
214   case CHXJ_SPEC_Jhtml:
215   case CHXJ_SPEC_Jxhtml:
216     entryp = chxj_apply_convrule(r, dconf->convrules);
217     if (! entryp) {
218       DBG(r, "REQ[%X] end chxj_headers_fixup() (no pattern)", (unsigned int)(apr_size_t)r);
219       return DECLINED;
220     }
221     if (!(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
222       DBG(r, "REQ[%X] end chxj_headers_fixup() (engine off)", (unsigned int)(apr_size_t)r);
223       return DECLINED;
224     }
225     if (entryp->action & CONVRULE_EMOJI_ONLY_BIT) {
226       DBG(r, "REQ[%X] end chxj_headers_fixup() (emoji only)", (unsigned int)(apr_size_t)r);
227       return DECLINED;
228     } 
229   
230     apr_table_setn(r->headers_in, 
231                    CHXJ_HTTP_USER_AGENT, 
232                    user_agent);
233   
234     if (entryp->user_agent)
235       apr_table_setn(r->headers_in, 
236                      HTTP_USER_AGENT, 
237                      entryp->user_agent);
238     /*
239      * this clear process must do before chxj_convert_input_header function.
240      */
241     if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
242       if (r->method_number == M_POST) {
243         if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
244           s_clear_cookie_header(r, spec);
245         }
246       }
247       else {
248         s_clear_cookie_header(r, spec);
249       }
250     }
251
252     chxj_convert_input_header(r,entryp, spec);
253
254     break;
255   
256   default:
257     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);
258     return DECLINED;
259
260   }
261
262
263   if (r->method_number == M_POST) {
264     if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
265         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);
266         r->proxyreq = PROXYREQ_NONE;
267         r->handler = apr_psprintf(r->pool, "chxj-input-handler");
268     }
269     else {
270       char *client_ip = (char *)apr_table_get(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP);
271       if (client_ip) {
272         if (dconf->post_log) {
273           apr_table_setn(r->subprocess_env, dconf->post_log, dconf->post_log);
274         }
275         else {
276           apr_table_setn(r->subprocess_env, "chxj-post-log", "chxj-post-log");
277         }
278         apr_sockaddr_t *address = NULL;
279         apr_status_t rv = apr_sockaddr_info_get(&address, ap_get_server_name(r), APR_UNSPEC, ap_get_server_port(r), 0, r->pool);
280         if (rv != APR_SUCCESS) {
281           char buf[256];
282           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));
283           DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
284           return DECLINED;
285         }
286         char *addr;
287         if (dconf->forward_server_ip) {
288           addr = dconf->forward_server_ip;
289         }
290         else {
291           apr_sockaddr_ip_get(&addr, address);
292         }
293         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);
294         if (strcmp(addr, r->connection->remote_ip) == 0) {
295           r->connection->remote_ip = apr_pstrdup(r->connection->pool, client_ip);
296         }
297         if (! apr_table_get(r->headers_in, "Content-Length")) {
298           contentLength = (char *)apr_table_get(r->headers_in, "X-Chxj-Content-Length");
299           if (contentLength) {
300             apr_table_set(r->headers_in, "Content-Length", contentLength);
301           }
302         }
303       }
304     }
305   }
306
307   chxj_add_device_env(r, spec);
308
309   DBG(r, "REQ[%X] end chxj_headers_fixup()", (unsigned int)(apr_size_t)r);
310
311   return DECLINED;
312 }
313
314
315 static void
316 s_clear_cookie_header(request_rec *r, device_table *spec)
317 {
318   DBG(r, "REQ[%X] start s_clear_cookie_header()", TO_ADDR(r));
319   switch(spec->html_spec_type) {
320   case CHXJ_SPEC_Chtml_1_0:
321   case CHXJ_SPEC_Chtml_2_0:
322   case CHXJ_SPEC_Chtml_3_0:
323   case CHXJ_SPEC_Chtml_4_0:
324   case CHXJ_SPEC_Chtml_5_0:
325   case CHXJ_SPEC_Chtml_6_0:
326   case CHXJ_SPEC_Chtml_7_0:
327   case CHXJ_SPEC_XHtml_Mobile_1_0:
328   case CHXJ_SPEC_Jhtml:
329     apr_table_unset(r->headers_in, "Cookie");
330     break;
331   default:
332     break;
333   }
334   DBG(r, "REQ[%X] end   s_clear_cookie_header()", TO_ADDR(r));
335 }
336
337
338 /**
339  * It converts it from CHTML into XXML corresponding to each model. 
340  *
341  * @param r   [i]
342  * @param src [i]   It is former HTML character string. 
343  * @param len [i/o] It is length of former HTML character string. 
344  */
345 static char * 
346 chxj_convert(request_rec *r, const char **src, apr_size_t *len, device_table *spec, const char *ua, cookie_t **cookiep)
347 {
348   char                *user_agent;
349   char                *dst;
350   char                *tmp;
351   cookie_t            *cookie;
352   mod_chxj_config     *dconf; 
353   chxjconvrule_entry  *entryp;
354
355   DBG(r,"REQ[%X] start of chxj_convert()", (unsigned int)(apr_size_t)r);
356
357   chxj_dump_string(r, APLOG_MARK, "INPUT Data", *src, *len);
358
359   dst  = apr_pstrcat(r->pool, (char *)*src, NULL);
360
361   dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
362
363
364   entryp = chxj_apply_convrule(r, dconf->convrules);
365
366   if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
367     DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
368     return (char *)*src;
369   }
370
371
372   /*------------------------------------------------------------------------*/
373   /* get UserAgent from http header                                         */
374   /*------------------------------------------------------------------------*/
375   if (entryp->user_agent)
376     user_agent = (char *)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
377   else
378     user_agent = (char *)apr_table_get(r->headers_in, HTTP_USER_AGENT);
379
380   DBG(r,"REQ[%X] User-Agent:[%s]", (unsigned int)(apr_size_t)r, user_agent);
381   DBG(r,"REQ[%X] content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
382
383
384   if (  ! STRNCASEEQ('t','T', "text/html", r->content_type, sizeof("text/html")-1)
385     &&  ! STRNCASEEQ('a','A', "application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)) {
386     DBG(r,"REQ[%X] no convert. content type is %s", (unsigned int)(apr_size_t)r, r->content_type);
387     DBG(r,"REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
388     return (char *)*src;
389   }
390
391   if (ua && user_agent && strcasecmp(user_agent, ua) != 0) {
392     /* again */
393     spec = chxj_specified_device(r, user_agent);
394   }
395
396   /*
397    * save cookie.
398    */
399   cookie = NULL;
400   if (entryp->action & CONVRULE_COOKIE_ON_BIT 
401       && !(entryp->action & CONVRULE_EMOJI_ONLY_BIT)
402       && !(entryp->action & CONVRULE_ENVINFO_ONLY_BIT)) {
403     switch(spec->html_spec_type) {
404     case CHXJ_SPEC_Chtml_1_0:
405     case CHXJ_SPEC_Chtml_2_0:
406     case CHXJ_SPEC_Chtml_3_0:
407     case CHXJ_SPEC_Chtml_4_0:
408     case CHXJ_SPEC_Chtml_5_0:
409     case CHXJ_SPEC_Chtml_6_0:
410     case CHXJ_SPEC_Chtml_7_0:
411     case CHXJ_SPEC_XHtml_Mobile_1_0:
412     case CHXJ_SPEC_Jhtml:
413       cookie = chxj_save_cookie(r);
414       break;
415     default:
416       break;
417     }
418   }
419
420   if (!r->header_only) {
421
422     tmp = NULL;
423     if (convert_routine[spec->html_spec_type].encoder)
424       tmp = convert_routine[spec->html_spec_type].encoder(r, 
425                                                           *src, 
426                                                           (apr_size_t *)len);
427
428     if (entryp->action & CONVRULE_EMOJI_ONLY_BIT) {
429       if (tmp) {
430         tmp = chxj_node_convert_chxjif_only(r, spec, (const char*)tmp, (apr_size_t *)len);
431       }
432       else {
433         tmp = chxj_node_convert_chxjif_only(r, spec, (const char *)*src, (apr_size_t *)len);
434       }
435       if (convert_routine[spec->html_spec_type].emoji_only_converter) {
436         dst = convert_routine[spec->html_spec_type].emoji_only_converter(r,spec, tmp,*len);
437         if (dst != NULL) {
438           *len = strlen(dst);
439         }
440         else {
441           dst = apr_palloc(r->pool, 1);
442           *dst = 0;
443           *len = 0;
444         }
445       }
446       DBG(r, "REQ[%X] end of chxj_convert()(emoji only)", (unsigned int)(apr_size_t)r);
447     }
448
449     if (   !(entryp->action & CONVRULE_EMOJI_ONLY_BIT) 
450         && !(entryp->action & CONVRULE_ENVINFO_ONLY_BIT)) {
451       if (convert_routine[spec->html_spec_type].converter) {
452         if (tmp)
453           dst = convert_routine[spec->html_spec_type].converter(r, 
454                                                                 spec, 
455                                                                 tmp, 
456                                                                 *len, 
457                                                                 len, 
458                                                                 entryp, 
459                                                                 cookie);
460         else
461           dst = convert_routine[spec->html_spec_type].converter(r,
462                                                                 spec, 
463                                                                 *src, 
464                                                                 *len, 
465                                                                 len, 
466                                                                 entryp, 
467                                                                 cookie);
468       }
469     }
470   }
471   ap_set_content_length(r, *len);
472
473   if (*len == 0) {
474     dst = apr_psprintf(r->pool, "\n");
475     *len = 1;
476   }
477   dst[*len] = 0;
478   if (cookie) {
479     *cookiep = cookie;
480   }
481
482
483   DBG(r, "REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
484
485   return dst;
486 }
487
488
489 /**
490  * convert GUID parameter.
491  *
492  */
493 static void
494 s_convert_guid_parameter_to_header(request_rec *r, const char *param, device_table *spec)
495 {
496   DBG(r, "REQ[%X] start s_convert_guid_parameter() param:[%s]", (unsigned int)(apr_size_t)r, param);
497   if (strcasecmp(param, "guid") == 0) {
498     switch(spec->html_spec_type) {
499     case CHXJ_SPEC_XHtml_Mobile_1_0:
500       do {
501         char *x_up_subno = (char *)apr_table_get(r->headers_in, "x-up-subno");
502         if (x_up_subno) {
503           apr_table_setn(r->headers_in, "X-DCMGUID", x_up_subno);
504         }
505       } while(0);
506       break;
507     case CHXJ_SPEC_Jhtml:
508     case CHXJ_SPEC_Jxhtml:
509       do {
510         char *x_jphone_uid = (char *)apr_table_get(r->headers_in, "x-jphone-uid");
511         if (x_jphone_uid) {
512           apr_table_setn(r->headers_in, "X-DCMGUID", x_jphone_uid);
513         }
514       } while(0);
515       break;
516     default:
517       break;
518     }
519   }
520   DBG(r, "REQ[%X] end s_convert_guid_parameter()", (unsigned int)(apr_size_t)r);
521 }
522
523 /**
524  * It converts it from HEADER.
525  *
526  * @param r   [i]
527  */
528 static int
529 chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp, device_table *spec) 
530 {
531
532   char       *buff;
533   char       *buff_pre;
534   apr_size_t urilen;
535   char       *result;
536   char       *pair;
537   char       *name;
538   char       *value;
539   char       *pstate;
540   char       *vstate;
541   cookie_t   *cookie = NULL;
542   int        no_update_flag = 0;
543
544   DBG(r, "REQ[%X] start chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
545
546   if (! r->args) {
547     DBG(r, "REQ[%X] r->args=[null]", (unsigned int)(apr_size_t)r);
548     DBG(r, "REQ[%X] end   chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
549     return 0;
550   }
551   urilen = strlen(r->args);
552
553   result = qs_alloc_zero_byte_string(r->pool);
554
555   buff_pre = apr_pstrdup(r->pool, r->args);
556
557   for (;;) {
558     char *pair_sv;
559
560     pair = apr_strtok(buff_pre, "&", &pstate);
561     if (pair == NULL)
562       break;
563
564     buff_pre = NULL;
565
566     pair_sv = apr_pstrdup(r->pool, pair);
567
568     name  = apr_strtok(pair, "=", &vstate);
569     value = apr_strtok(NULL, "=", &vstate);
570     if (! name) continue;
571     if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
572       DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
573       no_update_flag++;
574     }
575   }
576
577   buff = apr_pstrdup(r->pool, r->args);
578   DBG(r, "REQ[%X] r->args=[%s]", (unsigned int)(apr_size_t)r, buff);
579
580   /* _chxj_dmy */
581   /* _chxj_c_ */
582   /* _chxj_r_ */
583   /* _chxj_s_ */
584   for (;;) {
585     char *pair_sv;
586
587     pair = apr_strtok(buff, "&", &pstate);
588     if (pair == NULL)
589       break;
590
591     buff = NULL;
592
593     pair_sv = apr_pstrdup(r->pool, pair);
594
595     name  = apr_strtok(pair, "=", &vstate);
596     value = apr_strtok(NULL, "=", &vstate);
597     if (! name) continue;
598     name = chxj_safe_to_jreserved_tag(r, name);
599     if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
600       if (strlen(result) != 0) 
601         result = apr_pstrcat(r->pool, result, "&", NULL);
602
603       if (strcasecmp(entryp->encoding, "NONE") != 0) {
604         apr_size_t dlen;
605         char *dvalue;
606         char *dname;
607
608         if (value && *value != 0) {
609           value = chxj_url_decode(r->pool, value);
610           dlen   = strlen(value);
611           DBG(r, "************ before encoding[%s]", value);
612   
613           dvalue = chxj_rencoding(r, value, &dlen);
614           dvalue = chxj_url_encode(r->pool, dvalue);
615   
616           DBG(r, "************ after encoding[%s]", dvalue);
617         }
618         else {
619           dvalue = "";
620         }
621
622         if (name && *name != 0) {
623           name = chxj_url_decode(r->pool, name);
624           dlen = strlen(name);
625           dname = chxj_rencoding(r, name, &dlen);
626           dname = chxj_url_encode(r->pool, dname);
627         }
628         else {
629           dname = "";
630         }
631         s_convert_guid_parameter_to_header(r, dname, spec);
632         result = apr_pstrcat(r->pool, result, dname, "=", dvalue, NULL);
633       }
634       else {
635         s_convert_guid_parameter_to_header(r, name, spec);
636         if (strcmp(name, pair_sv) != 0) {
637           result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
638         } 
639         else {
640           result = apr_pstrcat(r->pool, result, name, NULL);
641         }
642       }
643     }
644     else
645     if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
646       || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
647       || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
648       if (value == NULL)
649         continue;
650
651       if (strlen(value) == 0)
652         continue;
653
654       if (strlen(result) != 0)
655         result = apr_pstrcat(r->pool, result, "&", NULL);
656
657       result = apr_pstrcat(r->pool, result, &name[8], "=", value, NULL);
658     }
659     else
660     if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
661       if (! cookie) {
662         apr_table_unset(r->headers_in, "Cookie");
663         DBG(r, "REQ[%X] found cookie parameter[%s]",    (unsigned int)(apr_size_t)r, value);
664         DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
665         cookie_lock_t *lock = chxj_cookie_lock(r);
666         cookie = chxj_load_cookie(r, value);
667         DBG(r, "REQ[%X] call end   chxj_load_cookie()", (unsigned int)(apr_size_t)r);
668         if (! no_update_flag && cookie) {
669           cookie = chxj_update_cookie(r, cookie);
670         }
671         chxj_cookie_unlock(r, lock);
672       }
673       if (cookie && cookie->cookie_id) {
674         if (strlen(result) != 0)
675           result = apr_pstrcat(r->pool, result, "&", NULL);
676         result = apr_pstrcat(r->pool, result, name, "=", cookie->cookie_id, NULL);
677       }
678     }
679     else
680     if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
681       if (strlen(result) != 0)
682         result = apr_pstrcat(r->pool, result, "&", NULL);
683       result = apr_pstrcat(r->pool, result, name, "=", value, NULL);
684     }
685   }
686   apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
687   if (! no_update_flag) {
688     result = apr_pstrcat(r->pool, result, "&_chxj_nc=true", NULL);
689   }
690   r->args = result;
691
692   DBG(r, "REQ[%X] result r->args=[%s]",               (unsigned int)(apr_size_t)r, r->args);
693   DBG(r, "REQ[%X] end   chxj_convert_input_header()", (unsigned int)(apr_size_t)r);
694   return 0;
695 }
696
697
698 /**
699  * It converts it from POSTDATA .
700  *
701  * @param r   [i]
702  * @param src [i]   It is POSTDATA character string.
703  * @param len [i/o] It is length of former HTML character string.
704  */
705 static char *
706 chxj_input_convert(
707   request_rec         *r, 
708   const char          **src, 
709   apr_size_t          *len, 
710   chxjconvrule_entry  *entryp,
711   device_table        *spec)
712 {
713   char     *pair;
714   char     *name;
715   char     *value;
716   char     *pstate;
717   char     *vstate;
718   char     *s;
719   char     *result;
720   cookie_t *cookie = NULL;
721   char     *buff_pre;
722   int      no_update_flag = 0;
723   apr_size_t ilen = 0;
724   apr_pool_t *pool;
725
726   DBG(r, "REQ[%X] start of chxj_input_convert()", (unsigned int)(apr_size_t)r);
727
728   if (! *src) {
729     DBG(r, "REQ[%X] end of chxj_input_convert() (input is null)", (unsigned int)(apr_size_t)r);
730     return apr_pstrdup(r->pool, "");
731   }
732
733   apr_pool_create(&pool, r->pool);
734
735   s        = apr_pstrdup(pool, *src);
736   ilen     = strlen(s);
737   buff_pre = apr_pstrdup(pool, *src);
738
739   result   = qs_alloc_zero_byte_string(pool);
740
741   chxj_dump_string(r, APLOG_MARK, "BEFORE input convert source", s, ilen);
742
743   for (;;) {
744     char *pair_sv;
745
746     pair = apr_strtok(buff_pre, "&", &pstate);
747     if (pair == NULL)
748       break;
749
750     buff_pre = NULL;
751
752     pair_sv = apr_pstrdup(pool, pair);
753
754     name  = apr_strtok(pair, "=", &vstate);
755     value = apr_strtok(NULL, "=", &vstate);
756     if (! name) continue;
757     if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0 || strcasecmp(name, chxj_url_encode(r->pool, CHXJ_COOKIE_NOUPDATE_PARAM)) == 0) {
758       DBG(r, "REQ[%X] found cookie no update parameter", (unsigned int)(apr_size_t)r);
759       no_update_flag++;
760     }
761   }
762
763   /* _chxj_dmy */
764   /* _chxj_c_ */
765   /* _chxj_r_ */
766   /* _chxj_s_ */
767   for (;;) {
768     pair = apr_strtok(s, "&", &pstate);
769     if (pair == NULL)
770       break;
771     s = NULL;
772
773     name  = apr_strtok(pair, "=", &vstate);
774     value = apr_strtok(NULL, "=", &vstate);
775     if (! name) continue;
776     name  = chxj_safe_to_jreserved_tag(r, name);
777
778     if (strncasecmp(name, "_chxj", 5) != 0 && strncasecmp(name, "%5Fchxj", sizeof("%5Fchxj")-1) != 0) {
779       if (strlen(result) != 0) 
780         result = apr_pstrcat(pool, result, "&", NULL);
781
782       if (strcasecmp(entryp->encoding, "NONE") != 0) {
783         apr_size_t dlen;
784         char *dvalue;
785         char *dname;
786
787         if (value && *value != 0) {
788           value = chxj_url_decode(pool, value);
789           dlen   = strlen(value);
790           dvalue = chxj_rencoding(r, value, &dlen);
791           dvalue = chxj_url_encode(pool, dvalue);
792         }
793         else {
794           dvalue = "";
795         }
796
797         if (name && *name != 0) {
798           name = chxj_url_decode(pool, name);
799           dlen = strlen(name);
800           dname = chxj_rencoding(r, name, &dlen);
801           dname = chxj_url_encode(pool, dname);
802         }
803         else {
804           dname = "";
805         }
806
807
808         result = apr_pstrcat(pool, result, dname, "=", dvalue, NULL);
809       }
810       else {
811         result = apr_pstrcat(pool, result, name, "=", value, NULL);
812       }
813     }
814     else
815     if ( (strncasecmp(name, "_chxj_c_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fc%5F", sizeof("%5Fchxj%5Fc%5F")-1) == 0)
816       || (strncasecmp(name, "_chxj_r_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fr%5F", sizeof("%5Fchxj%5Fr%5F")-1) == 0)
817       || (strncasecmp(name, "_chxj_s_", 8) == 0 || strncasecmp(name, "%5Fchxj%5Fs%5F", sizeof("%5Fchxj%5Fs%5F")-1) == 0)) {
818       if (value == NULL)
819         continue;
820
821       if (strlen(value) == 0)
822         continue;
823
824       if (strlen(result) != 0)
825         result = apr_pstrcat(pool, result, "&", NULL);
826
827       if (strcasecmp(entryp->encoding, "NONE") != 0 && value && strlen(value)) {
828         apr_size_t dlen;
829         char       *dvalue;
830
831         dlen   = strlen(value);
832         value = chxj_url_decode(pool, value);
833         dvalue = chxj_rencoding(r, value, &dlen);
834         dvalue = chxj_url_encode(pool,dvalue);
835         result = apr_pstrcat(pool, result, &name[8], "=", dvalue, NULL);
836
837       }
838       else {
839         result = apr_pstrcat(pool, result, &name[8], "=", value, NULL);
840       }
841     }
842     else
843     if (strcasecmp(name, CHXJ_COOKIE_PARAM) == 0 || strcasecmp(name, "%5Fchxj%5Fcc") == 0) {
844       if (! cookie) {
845         apr_table_unset(r->headers_in, "Cookie");
846         DBG(r, "REQ[%X] found cookie parameter[%s]",    (unsigned int)(apr_size_t)r, value);
847         DBG(r, "REQ[%X] call start chxj_load_cookie()", (unsigned int)(apr_size_t)r);
848         cookie_lock_t *lock = chxj_cookie_lock(r);
849         cookie = chxj_load_cookie(r, value);
850         DBG(r, "REQ[%X] call end   chxj_load_cookie()", (unsigned int)(apr_size_t)r);
851         if (! no_update_flag && cookie) {
852           cookie = chxj_update_cookie(r, cookie);
853         }
854         chxj_cookie_unlock(r, lock);
855       }
856       if (cookie && cookie->cookie_id) {
857         if (strlen(result) != 0)
858           result = apr_pstrcat(pool, result, "&", NULL);
859         result = apr_pstrcat(pool, result, name, "=", cookie->cookie_id, NULL);
860       }
861     }
862     else
863     if (strcasecmp(name, CHXJ_COOKIE_NOUPDATE_PARAM) == 0) {
864       if (strlen(result) != 0)
865         result = apr_pstrcat(pool, result, "&", NULL);
866       result = apr_pstrcat(pool, result, name, "=", value, NULL);
867     }
868     else
869     if ( strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX,     sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1) == 0) {
870       apr_size_t dlen;
871       char*      dvalue;
872       dlen   = strlen(value);
873       if (dlen && value) {
874         value = chxj_url_decode(pool, value);
875         dvalue = chxj_rencoding(r, value, &dlen);
876         dvalue = chxj_url_encode(pool,dvalue);
877         if (r->args && strlen(r->args) > 0) {
878           r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
879         }
880         else {
881           r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
882         }
883         s_convert_guid_parameter_to_header(r, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], spec);
884       }
885     }
886     else
887     if (strncasecmp(name, CHXJ_QUERY_STRING_PARAM_PREFIX_ENC, sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1) == 0) {
888       apr_size_t dlen;
889       char*      dvalue;
890       dlen   = strlen(value);
891       if (dlen && value) {
892         value = chxj_url_decode(pool, value);
893         dvalue = chxj_rencoding(r, value, &dlen);
894         dvalue = chxj_url_encode(pool,dvalue);
895         if (r->args && strlen(r->args) > 0) {
896           r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
897         }
898         else {
899           r->args = apr_pstrcat(pool, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);
900         }
901         s_convert_guid_parameter_to_header(r, &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], spec);
902       }
903     }
904     DBG(r, "REQ[%X] ************************ name:[%s]", (unsigned int)(apr_size_t)r, name);
905   }
906   *len = strlen(result);
907   apr_table_setn(r->headers_in, "X-Chxj-Cookie-No-Update", "true");
908   if (! no_update_flag) {
909     result = apr_pstrcat(pool, result, "&_chxj_nc=true", NULL);
910   }
911
912   DBG(r, "REQ[%X] AFTER input convert result = [%s]", (unsigned int)(apr_size_t)r, result);
913   DBG(r, "REQ[%X] end chxj_input_convert()", (unsigned int)(apr_size_t)r);
914
915   return result;
916 }
917
918
919 /**
920  * The received data is returned to the filter.
921  *
922  * @param f    [i/o] It is a filter. 
923  * @param data [i]   It is data returned to the filter. 
924  * @param len  [i]   It is length of the data returned to the filter. 
925  */
926 static apr_status_t 
927 pass_data_to_filter(ap_filter_t *f, const char *data, 
928                                         apr_size_t len)
929 {
930   request_rec         *r = f->r;
931   conn_rec            *c = r->connection;
932   apr_status_t        rv;
933   apr_bucket_brigade  *bb;
934   apr_bucket          *b;
935
936   DBG(r, "REQ[%X] start pass_data_to_filter()", (unsigned int)(apr_size_t)r);
937
938   chxj_header_inf_clear(r);
939
940   bb = apr_brigade_create(r->pool, c->bucket_alloc);
941   b  = apr_bucket_transient_create(data, len, c->bucket_alloc);
942
943   APR_BRIGADE_INSERT_TAIL(bb, b);
944   b = apr_bucket_eos_create(f->c->bucket_alloc);
945   APR_BRIGADE_INSERT_TAIL(bb, b);
946
947   rv = ap_pass_brigade(f->next, bb);
948   if (rv != APR_SUCCESS) {
949     DBG(r, "REQ[%X] end pass_data_to_filter() (apr_pass_brigade)", (unsigned int)(apr_size_t)r);
950     return rv;
951   }
952
953   DBG(r, "REQ[%X] end pass_data_to_filter()", (unsigned int)(apr_size_t)r);
954
955   return rv;
956 }
957
958 /**
959  * Add No Cache Header
960  */
961 static void
962 s_add_no_cache_headers(request_rec *r, chxjconvrule_entry  *entryp)
963 {
964   if (entryp->action & CONVRULE_NOCACHE_ON_BIT) {
965     apr_table_unset(r->headers_out,     "Pragma");
966     apr_table_unset(r->err_headers_out, "Pragma");
967     apr_table_unset(r->headers_out,     "Expires");
968     apr_table_unset(r->err_headers_out, "Expires");
969     apr_table_unset(r->headers_out,     "Cache-Control");
970     apr_table_unset(r->err_headers_out, "Cache-Control");
971
972     apr_table_setn(r->err_headers_out, "Pragma", "no-cache");
973     apr_table_setn(r->err_headers_out, "Expires", "Thu, 01 Jan 1970 00:00:00 GMT");
974     apr_table_setn(r->err_headers_out, "Cache-Control", "no-cache, no-store");
975   }
976 }
977
978
979 /**
980  * It is the main loop of the output filter. 
981  *
982  * @param f   [i/o] It is a filter.
983  * @param bb  [i]   
984  */
985 static apr_status_t 
986 chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
987 {
988   request_rec         *r;
989   apr_status_t        rv;
990   apr_bucket          *b;
991   const char          *data;
992   char                *user_agent = NULL;
993   apr_size_t          len;
994   mod_chxj_ctx        *ctx = (mod_chxj_ctx *)f->ctx;
995   cookie_t            *cookie = NULL;
996   mod_chxj_config     *dconf;
997   chxjconvrule_entry  *entryp = NULL;
998   device_table        *spec = NULL;
999   apr_pool_t          *pool;
1000
1001   r  = f->r;
1002   DBG(f->r, "REQ[%X] start of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1003   rv = APR_SUCCESS;
1004
1005   apr_pool_create(&pool, r->pool);
1006
1007   entryp = ctx->entryp;
1008   spec   = ctx->spec;
1009   dconf  = chxj_get_module_config(r->per_dir_config, &chxj_module);
1010
1011
1012   if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1013     DBG(r, "REQ[%X] found Location header", TO_ADDR(r));
1014     if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
1015       cookie_lock_t *lock = NULL;
1016       DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", TO_ADDR(r));
1017       switch(spec->html_spec_type) {
1018       case CHXJ_SPEC_Chtml_1_0:
1019       case CHXJ_SPEC_Chtml_2_0:
1020       case CHXJ_SPEC_Chtml_3_0:
1021       case CHXJ_SPEC_Chtml_4_0:
1022       case CHXJ_SPEC_Chtml_5_0:
1023       case CHXJ_SPEC_Chtml_6_0:
1024       case CHXJ_SPEC_Chtml_7_0:
1025       case CHXJ_SPEC_XHtml_Mobile_1_0:
1026       case CHXJ_SPEC_Jhtml:
1027         lock = chxj_cookie_lock(r);
1028         cookie = chxj_save_cookie(r);
1029         s_add_cookie_id_if_has_location_header(r, cookie);
1030         chxj_cookie_unlock(r, lock);
1031         break;
1032       default:
1033         break;
1034       }
1035     }
1036     if (! ap_is_HTTP_REDIRECT(r->status)) {
1037       r->status = HTTP_MOVED_TEMPORARILY;
1038     }
1039     s_add_no_cache_headers(r, entryp);
1040     /* must not send body. */
1041     rv = pass_data_to_filter(f, "", 0);
1042     DBG(f->r, "REQ[%X] end of chxj_output_filter()", TO_ADDR(r));
1043     return rv;
1044   }
1045
1046
1047   if (r->content_type) {
1048     if (! STRNCASEEQ('t','T',"text/html",r->content_type, sizeof("text/html")-1)
1049     &&  ! STRNCASEEQ('t','T',"text/xml", r->content_type, sizeof("text/xml")-1)
1050     &&  ! STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
1051     &&  ! (dconf->image == CHXJ_IMG_ON
1052           && ! apr_table_get(r->headers_in, "CHXJ_IMG_CONV")
1053           && STRNCASEEQ('i','I',"image/",  r->content_type, sizeof("image/") -1)
1054           && ( STRCASEEQ('j','J',"jpeg",            &r->content_type[6])         /* JPEG */
1055             || STRCASEEQ('j','J',"jp2",             &r->content_type[6])         /* JPEG2000 */
1056             || STRCASEEQ('j','J',"jpeg2000",        &r->content_type[6])         /* JPEG2000 */
1057             || STRCASEEQ('j','J',"jpeg2000-image",  &r->content_type[6])         /* JPEG2000 */
1058             || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6])         /* JPEG2000 */
1059             || STRCASEEQ('x','X',"x-ms-bmp",        &r->content_type[6])         /* BMP */
1060             || STRCASEEQ('p','P',"png",             &r->content_type[6])         /* PNG */
1061             || STRCASEEQ('x','X',"x-png",           &r->content_type[6])         /* PNG */
1062             || STRCASEEQ('g','G',"gif",             &r->content_type[6])))) {     /* GIF */
1063       
1064       DBG(r, "REQ[%X] not convert content-type:[%s] dconf->image:[%d]", (unsigned int)(apr_size_t)r, r->content_type, dconf->image);
1065       if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
1066         cookie_lock_t *lock = NULL;
1067         DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
1068         switch(spec->html_spec_type) {
1069         case CHXJ_SPEC_Chtml_1_0:
1070         case CHXJ_SPEC_Chtml_2_0:
1071         case CHXJ_SPEC_Chtml_3_0:
1072         case CHXJ_SPEC_Chtml_4_0:
1073         case CHXJ_SPEC_Chtml_5_0:
1074         case CHXJ_SPEC_Chtml_6_0:
1075         case CHXJ_SPEC_Chtml_7_0:
1076         case CHXJ_SPEC_XHtml_Mobile_1_0:
1077         case CHXJ_SPEC_Jhtml:
1078           lock = chxj_cookie_lock(r);
1079           cookie = chxj_save_cookie(r);
1080           s_add_cookie_id_if_has_location_header(r, cookie);
1081           chxj_cookie_unlock(r, lock);
1082           break;
1083         default:
1084           break;
1085         }
1086       }
1087       if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1088         if (! ap_is_HTTP_REDIRECT(r->status)) {
1089           r->status = HTTP_MOVED_TEMPORARILY;
1090         }
1091       }
1092       s_add_no_cache_headers(r, entryp);
1093       ap_pass_brigade(f->next, bb);
1094       DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1095       return APR_SUCCESS;
1096     }
1097   }
1098   else {
1099     DBG(r, "REQ[%X] not convert content-type:[(null)]", (unsigned int)(apr_size_t)r);
1100     ap_pass_brigade(f->next, bb);
1101     DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1102     return APR_SUCCESS;
1103   }
1104
1105
1106   for (b = APR_BRIGADE_FIRST(bb);
1107        b != APR_BRIGADE_SENTINEL(bb); 
1108        b = APR_BUCKET_NEXT(b)) {
1109
1110     if (apr_bucket_read(b, &data, &len, APR_BLOCK_READ) == APR_SUCCESS) {
1111       chxj_dump_string(r, APLOG_MARK, "READ Data", data, len);
1112
1113       /*--------------------------------------------------------------------*/
1114       /* append data                                                        */
1115       /*--------------------------------------------------------------------*/
1116       char *tmp;
1117       DBG(r, "append data start");
1118       ctx = (mod_chxj_ctx *)f->ctx;
1119
1120       if (len > 0) {
1121         tmp = apr_palloc(r->pool, ctx->len);
1122         memcpy(tmp, ctx->buffer, ctx->len);
1123
1124         ctx->buffer = apr_palloc(pool, ctx->len + len);
1125
1126         memcpy(ctx->buffer, tmp, ctx->len);
1127         memcpy(&ctx->buffer[ctx->len], data, len);
1128
1129         ctx->len += len;
1130       }
1131       DBG(r, "REQ[%X] append data end", (unsigned int)(apr_size_t)r);
1132     }
1133
1134     if (APR_BUCKET_IS_EOS(b)) {
1135
1136       DBG(r, "REQ[%X] eos", (unsigned int)(apr_size_t)r);
1137       /*----------------------------------------------------------------------*/
1138       /* End Of File                                                          */
1139       /*----------------------------------------------------------------------*/
1140       if (ctx) {
1141         cookie_lock_t *lock = NULL;
1142         ctx = (mod_chxj_ctx *)f->ctx;
1143
1144         DBG(r, "REQ[%X] content_type=[%s]", (unsigned int)(apr_size_t)r, r->content_type);
1145         lock = chxj_cookie_lock(r);
1146
1147         if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN 
1148             && r->content_type 
1149             && (STRNCASEEQ('a','A',"application/xhtml+xml", r->content_type, sizeof("application/xhtml+xml")-1)
1150             ||  STRNCASEEQ('t','T',"text/html", r->content_type, sizeof("text/html")-1))) {
1151           DBG(r, "REQ[%X] detect convert target:[%s]", (unsigned int)(apr_size_t)r, r->content_type);
1152
1153           if (ctx->len) {
1154             char *tmp;
1155
1156             tmp = apr_palloc(pool, ctx->len + 1);
1157
1158             memset(tmp, 0, ctx->len + 1);
1159             memcpy(tmp, ctx->buffer, ctx->len);
1160
1161             ctx->buffer = chxj_convert(r, 
1162                                        (const char **)&tmp, 
1163                                        (apr_size_t *)&ctx->len,
1164                                        spec,
1165                                        user_agent, &cookie);
1166
1167           }
1168           else {
1169             ctx->buffer = apr_psprintf(r->pool, "\n");
1170             ctx->len += 1;
1171             ctx->buffer = chxj_convert(r, 
1172                                        (const char **)&ctx->buffer, 
1173                                        (apr_size_t *)&ctx->len,
1174                                        spec,
1175                                        user_agent, &cookie);
1176
1177           }
1178         }
1179         if (r->content_type
1180             && *(char *)r->content_type == 't'
1181             && strncmp(r->content_type, "text/xml",   8) == 0) {
1182           DBG(r, "REQ[%X] text/XML", (unsigned int)(apr_size_t)r);
1183
1184           Doc       doc;
1185           Node      *root;
1186           Node      *child;
1187           qr_code_t qrcode;
1188           int       sts;
1189       
1190           memset(&doc,    0, sizeof(Doc));
1191           memset(&qrcode, 0, sizeof(qr_code_t));
1192           doc.r = r;
1193           doc.parse_mode  = PARSE_MODE_CHTML;
1194           qrcode.doc      = &doc;
1195           qrcode.r        = r;
1196       
1197           qs_init_malloc(&doc);
1198       
1199           root = qs_parse_string(&doc, ctx->buffer, ctx->len);
1200
1201           sts = 0;
1202           for (child = qs_get_child_node(&doc,root);
1203                child ;
1204                child = qs_get_next_node(&doc,child)) {
1205             char *name = qs_get_node_name(&doc,child);
1206             if (strcasecmp("qrcode",name) == 0) {
1207               sts++;
1208               break;
1209             }
1210           }
1211           qs_all_free(&doc,QX_LOGMARK);
1212           if (sts) {
1213             r->handler = apr_psprintf(r->pool, "chxj-qrcode");
1214             chxj_qrcode_node_to_qrcode(&qrcode, root);
1215             sts = chxj_qrcode_create_image_data(&qrcode, &ctx->buffer, &ctx->len);
1216             if (sts != OK) {
1217               ERR(r, "REQ[%X] qrcode create failed.", (unsigned int)(apr_size_t)r);
1218               chxj_cookie_unlock(r, lock);
1219               DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1220               return sts;
1221             }
1222             r->content_type = apr_psprintf(r->pool, "image/jpeg");
1223           }
1224         }
1225
1226         if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN 
1227             && r->content_type 
1228             && ( *r->content_type == 'i' || *r->content_type == 'I')
1229             && dconf->image == CHXJ_IMG_ON
1230             && strncasecmp("image/", r->content_type, 6) == 0
1231             && ( STRCASEEQ('j','J',"jpeg",            &r->content_type[6])         /* JPEG */
1232               || STRCASEEQ('j','J',"jp2",             &r->content_type[6])         /* JPEG2000 */
1233               || STRCASEEQ('j','J',"jpeg2000",        &r->content_type[6])         /* JPEG2000 */
1234               || STRCASEEQ('j','J',"jpeg2000-image",  &r->content_type[6])         /* JPEG2000 */
1235               || STRCASEEQ('x','X',"x-jpeg2000-image",&r->content_type[6])         /* JPEG2000 */
1236               || STRCASEEQ('p','P',"png",             &r->content_type[6])         /* PNG */
1237               || STRCASEEQ('x','X',"x-png",           &r->content_type[6])         /* PNG */
1238               || STRCASEEQ('x','X',"x-ms-bmp",     &r->content_type[6])         /* BMP */
1239               || STRCASEEQ('g','G',"gif",             &r->content_type[6]))) {     /* GIF */
1240           DBG(r, "REQ[%X] detect convert target:[%s]", (unsigned int)(apr_size_t)r, r->content_type);
1241           if (ctx->len) {
1242             char *tmp;
1243
1244             tmp = apr_palloc(pool, ctx->len + 1);
1245
1246             memset(tmp, 0, ctx->len + 1);
1247             memcpy(tmp, ctx->buffer, ctx->len);
1248             ctx->buffer = 
1249               chxj_convert_image(r, 
1250                                   (const char **)&tmp,
1251                                   (apr_size_t *)&ctx->len);
1252             if (ctx->buffer == NULL) {
1253               ctx->buffer = tmp;
1254             }
1255           }
1256         }
1257
1258         apr_table_unset(r->headers_out, "Content-Length");
1259         apr_table_unset(r->err_headers_out, "Content-Length");
1260         ap_set_content_length(r, (apr_off_t)ctx->len);
1261
1262         
1263         if (ctx->len > 0) {
1264           DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1265           s_add_cookie_id_if_has_location_header(r, cookie);
1266           if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1267             if (! ap_is_HTTP_REDIRECT(r->status)) {
1268               r->status = HTTP_MOVED_TEMPORARILY;
1269             }
1270           }
1271           if (ctx->len && ap_is_HTTP_REDIRECT(r->status)) {
1272             ctx->buffer = apr_pstrdup(pool, "");
1273             ctx->len    = 0;
1274             ap_set_content_length(r, (apr_off_t)ctx->len);
1275           }
1276           chxj_cookie_unlock(r,lock);
1277           s_add_no_cache_headers(r, entryp);
1278           rv = pass_data_to_filter(f, 
1279                                    (const char *)ctx->buffer, 
1280                                    (apr_size_t)ctx->len);
1281         }
1282         else {
1283           ctx->buffer = apr_pstrdup(pool, "");
1284           ctx->len    = 0;
1285           ap_set_content_length(r, (apr_off_t)ctx->len);
1286           chxj_cookie_unlock(r, lock);
1287           s_add_no_cache_headers(r, entryp);
1288           rv = pass_data_to_filter(f, 
1289                                    (const char *)ctx->buffer, 
1290                                    (apr_size_t)ctx->len);
1291         }
1292         DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1293         return rv;
1294       }
1295       else {
1296         DBG(r, "REQ[%X] SAVE COOKIE[%x]", (unsigned int)(apr_size_t)r, entryp->action);
1297
1298         /*
1299          * save cookie.
1300          */
1301         if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
1302           cookie_lock_t *lock = NULL;
1303           DBG(r, "REQ[%X] entryp->action == COOKIE_ON_BIT", (unsigned int)(apr_size_t)r);
1304           switch(spec->html_spec_type) {
1305           case CHXJ_SPEC_Chtml_1_0:
1306           case CHXJ_SPEC_Chtml_2_0:
1307           case CHXJ_SPEC_Chtml_3_0:
1308           case CHXJ_SPEC_Chtml_4_0:
1309           case CHXJ_SPEC_Chtml_5_0:
1310           case CHXJ_SPEC_Chtml_6_0:
1311           case CHXJ_SPEC_Chtml_7_0:
1312           case CHXJ_SPEC_XHtml_Mobile_1_0:
1313           case CHXJ_SPEC_Jhtml:
1314             lock = chxj_cookie_lock(r);
1315             cookie = chxj_save_cookie(r);
1316             /*
1317              * Location Header Check to add cookie parameter.
1318              */
1319             s_add_cookie_id_if_has_location_header(r, cookie);
1320             chxj_cookie_unlock(r, lock);
1321             apr_table_unset(r->headers_out, "Set-Cookie");
1322             apr_table_unset(r->err_headers_out, "Set-Cookie");
1323             break;
1324
1325           default:
1326             break;
1327           }
1328         }
1329         if (apr_table_get(r->headers_out, "Location") || apr_table_get(r->err_headers_out, "Location")) {
1330           if (! ap_is_HTTP_REDIRECT(r->status)) {
1331             r->status = HTTP_MOVED_TEMPORARILY;
1332           }
1333         }
1334         apr_table_setn(r->headers_out, "Content-Length", "0");
1335         DBG(r, "REQ[%X] call pass_data_to_filter()", (unsigned int)(apr_size_t)r);
1336         s_add_no_cache_headers(r, entryp);
1337         rv = pass_data_to_filter(f, (const char *)"", (apr_size_t)0);
1338         DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1339         return rv;
1340       }
1341     }
1342   }
1343   apr_brigade_destroy(bb);
1344
1345   DBG(f->r, "REQ[%X] end of chxj_output_filter()", (unsigned int)(apr_size_t)r);
1346
1347   return APR_SUCCESS;
1348 }
1349
1350 /**
1351  * Add Cookie_id if it has location header.
1352  */
1353 static void
1354 s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie)
1355 {
1356   char *location_header = (char *)apr_table_get(r->headers_out, "Location");
1357   if (! location_header) {
1358     location_header = (char *)apr_table_get(r->err_headers_out, "Location");
1359   }
1360   if (cookie && location_header) {
1361     DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1362     location_header = chxj_add_cookie_parameter(r,
1363                                                 location_header,
1364                                                 cookie);
1365     apr_table_unset(r->headers_out, "Location");
1366     apr_table_setn(r->headers_out, "Location", location_header);
1367     DBG(r, "REQ[%X] Location Header=[%s]", (unsigned int)(apr_size_t)r, location_header);
1368     if (!ap_is_HTTP_REDIRECT(r->status)) {
1369       r->status = HTTP_MOVED_TEMPORARILY;
1370     }
1371   }
1372 }
1373
1374 /**
1375  * It is the main loop of the input filter handler. 
1376  *
1377  */
1378 static apr_status_t
1379 chxj_input_handler(request_rec *r)
1380 {
1381   mod_chxj_config     *dconf;
1382   chxjconvrule_entry  *entryp = NULL;
1383   device_table        *spec   = NULL;
1384   char                *post_data = NULL;
1385   apr_size_t          post_data_len = 0;
1386   char                *response;
1387   char                *user_agent;
1388   apr_pool_t          *pool;
1389   apr_size_t          ii;
1390   int                 response_code = 0;
1391   
1392   DBG(r, "start of chxj_input_handler()");
1393
1394   if (strcasecmp(r->handler, "chxj-input-handler")) {
1395     DBG(r, "end chxj_input_handler()");
1396     return DECLINED;
1397   }
1398   apr_pool_create(&pool, r->pool);
1399
1400   dconf      = chxj_get_module_config(r->per_dir_config, &chxj_module);
1401   user_agent = (char*)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
1402   if (!user_agent) {
1403     user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
1404   }
1405   spec       = chxj_specified_device(r, user_agent);
1406   entryp     = chxj_apply_convrule(r, dconf->convrules);
1407
1408   post_data = apr_pstrdup(pool, "");
1409   if (ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK) == OK) {
1410     if (ap_should_client_block(r)) {
1411       while (post_data_len < CHXJ_POST_MAX) {
1412 #define BUFSZ (256)
1413         char buffer[BUFSZ];
1414         int read_bytes = ap_get_client_block(r, buffer, BUFSZ-1);
1415         if (read_bytes<=0) {
1416           break;
1417         }
1418         buffer[read_bytes] = '\0';
1419         post_data = apr_pstrcat(pool, post_data, buffer, NULL);
1420         post_data_len += read_bytes;
1421 #undef BUFSZ
1422       }
1423     }
1424   }
1425
1426   /* 
1427    * now convert.
1428    */
1429   if (post_data_len > 0) {
1430     post_data = chxj_input_convert(r, (const char**)&post_data, (apr_size_t*)&post_data_len, entryp, spec);
1431     DBG(r, "(in:exchange)POSTDATA:[%s]", post_data);
1432   }
1433
1434   char *url_path;
1435   if (dconf->forward_url_base) {
1436     url_path = apr_psprintf(pool, "%s%s", dconf->forward_url_base, r->uri);
1437   }
1438   else {
1439     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);
1440   }
1441   if (r->args) {
1442     url_path = apr_pstrcat(pool, url_path, "?", r->args, NULL);
1443   }
1444   DBG(r, "==> new url_path:[%s]", url_path);
1445
1446   apr_size_t res_len;
1447   apr_table_setn(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP, r->connection->remote_ip);
1448   apr_table_unset(r->headers_in, "Content-Length");
1449   apr_table_setn(r->headers_in, "Content-Length", apr_psprintf(pool, "%" APR_SIZE_T_FMT, post_data_len));
1450   response = chxj_serf_post(r, pool, url_path, post_data, post_data_len, 1, &res_len, &response_code);
1451   DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1452   DBG(r, "REQ[%X] response length:[%" APR_SIZE_T_FMT "]", (unsigned int)(apr_size_t)r, res_len);
1453   for (ii=0; ii<res_len/64; ii++) {
1454     DBG(r, "REQ[%X] response:[%.*s]", (unsigned int)(apr_size_t)r, 64, &response[ii*64]);
1455   }
1456   DBG(r, "REQ[%X] -------------------------------------------------------", (unsigned int)(apr_size_t)r);
1457
1458   char *chunked;
1459   if ((chunked = (char *)apr_table_get(r->headers_out, "Transfer-Encoding")) != NULL) {
1460     if (strcasecmp(chunked, "chunked") == 0) {
1461       r->chunked = 1;  
1462       apr_table_unset(r->headers_out, "Transfer-Encoding");
1463     }
1464   }
1465   if (ap_is_HTTP_ERROR(response_code)) {
1466     DBG(r, "REQ[%X] end of chxj_input_handler() (HTTP-ERROR received. response code:[%d])", (unsigned int)(apr_size_t)r, response_code);
1467     return response_code;
1468   }
1469   {
1470     apr_pool_t *wpool;
1471     apr_pool_create(&wpool, r->pool);
1472     apr_bucket_brigade *bb;
1473     apr_bucket *e;
1474     apr_status_t rv;
1475     conn_rec *c = r->connection;
1476     
1477     bb = apr_brigade_create(wpool, c->bucket_alloc);
1478     e  = apr_bucket_transient_create(response, res_len, c->bucket_alloc);
1479     APR_BRIGADE_INSERT_TAIL(bb, e);
1480     e = apr_bucket_eos_create(c->bucket_alloc);
1481     APR_BRIGADE_INSERT_TAIL(bb, e);
1482     if ((rv = ap_pass_brigade(r->output_filters, bb)) != APR_SUCCESS) {
1483       ERR(r, "REQ[%X] %s:%d failed ap_pass_brigade()", (unsigned int)(apr_size_t)r, APLOG_MARK);
1484       return rv;
1485     }
1486     apr_brigade_cleanup(bb);
1487   }
1488
1489   DBG(r, "REQ[%X] end of chxj_input_handler()", (unsigned int)(apr_size_t)r);
1490   return APR_SUCCESS;
1491 }
1492
1493 static mod_chxj_global_config *
1494 chxj_global_config_create(apr_pool_t *pool, server_rec *s)
1495 {
1496   mod_chxj_global_config *conf;
1497
1498   SDBG(s, "start chxj_global_config_create()");
1499
1500   /*--------------------------------------------------------------------------*/
1501   /* allocate an own subpool which survives server restarts                   */
1502   /*--------------------------------------------------------------------------*/
1503   conf = (mod_chxj_global_config *)apr_palloc(pool, 
1504                   sizeof(mod_chxj_global_config));
1505 #if 0
1506   conf->cookie_db_lock = NULL;
1507 #endif
1508   SDBG(s, "end   chxj_global_config_create()");
1509
1510   return conf;
1511 }
1512
1513
1514 /**
1515  * initialize chxj module
1516  */
1517 static int 
1518 chxj_init_module(apr_pool_t *p, 
1519                  apr_pool_t *UNUSED(plog), 
1520                  apr_pool_t *UNUSED(ptemp), 
1521                  server_rec *s)
1522 {
1523   void *user_data;
1524   apr_status_t rv;
1525
1526   SDBG(s, "start chxj_init_module()");
1527
1528   apr_pool_userdata_get(&user_data, CHXJ_MOD_CONFIG_KEY, s->process->pool);
1529   SDBG(s, " ");
1530   if (user_data == NULL) {
1531     SDBG(s, " ");
1532     /*
1533      * dummy user_data set.
1534      */
1535     apr_pool_userdata_set(
1536       (const void *)(1), 
1537       CHXJ_MOD_CONFIG_KEY, 
1538       apr_pool_cleanup_null, 
1539       s->process->pool);
1540     SDBG(s, "end  chxj_init_module()");
1541     return OK;
1542   }
1543
1544   ap_add_version_component(p, CHXJ_VERSION_PREFIX CHXJ_VERSION);
1545
1546   if ((rv = apr_proc_mutex_create(&global_cookie_mutex, NULL,  APR_LOCK_FCNTL, s->process->pool)) != APR_SUCCESS) {
1547     char errstr[255];
1548     SERR(s, "%s:%d end chxj_init_module(). mutex create failure.(%d:%s)",APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1549     return HTTP_INTERNAL_SERVER_ERROR;
1550   }
1551
1552   SDBG(s, "end  chxj_init_module()");
1553
1554   return OK;
1555 }
1556
1557
1558 static void 
1559 chxj_child_init(apr_pool_t *UNUSED(p), server_rec *s)
1560 {
1561   apr_status_t rv;
1562   SDBG(s, "start chxj_child_init()");
1563   if ((rv = apr_proc_mutex_child_init(&global_cookie_mutex, NULL, s->process->pool)) != APR_SUCCESS) {
1564     char errstr[255];
1565     SERR(s, "%s:%d ERROR end chxj_init_module(). mutex create failure.(%d:%s)", APLOG_MARK, rv,apr_strerror(rv,errstr,255));
1566   }
1567   SDBG(s, "end   chxj_child_init()");
1568 }
1569
1570
1571 /**
1572  * A set structure of each server is generated. 
1573  * 
1574  * @param p
1575  * @param s
1576  */
1577 static void *
1578 chxj_config_server_create(apr_pool_t *p, server_rec *s)
1579 {
1580   mod_chxj_global_config *gc;
1581
1582   gc = chxj_global_config_create(p,s);
1583
1584   return gc;
1585 }
1586
1587
1588 static int
1589 chxj_translate_name(request_rec *r)
1590 {
1591   DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1592   DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1593   DBG(r, "REQ[%X] START REQUEST (uri:[%s] args:[%s])", (unsigned int)(apr_size_t)r, r->unparsed_uri, r->args ? r->args : "");
1594   DBG(r, "REQ[%X] METHOD [%s]", TO_ADDR(r), r->method);
1595   DBG(r, "REQ[%X] ", (unsigned int)(apr_size_t)r);
1596   DBG(r, "REQ[%X] =======================================================================", (unsigned int)(apr_size_t)r);
1597 #if 0
1598   return chxj_trans_name(r);
1599 #else
1600   return DECLINED;
1601 #endif
1602 }
1603
1604
1605 static void 
1606 chxj_insert_filter(request_rec *r)
1607 {
1608   char                *user_agent;
1609   device_table        *spec;
1610   mod_chxj_config     *dconf;
1611   chxjconvrule_entry  *entryp;
1612   mod_chxj_ctx        *ctx;
1613   apr_status_t        rv;
1614   char                *contentType;
1615
1616   DBG(r, "REQ[%X] start chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1617
1618   dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
1619
1620   /* we get User-Agent from CHXJ_HTTP_USER_AGENT header if any */
1621   user_agent = (char *)apr_table_get(r->headers_in, CHXJ_HTTP_USER_AGENT);
1622   if (!user_agent) {
1623     user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
1624   }
1625
1626   contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
1627   if (contentType
1628       && strncasecmp("multipart/form-data", contentType, 19) == 0) {
1629     DBG(r, "REQ[%X] detect multipart/form-data ==> no target", (apr_size_t)(unsigned int)r);
1630     DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1631     return;
1632   }
1633
1634   spec = chxj_specified_device(r, user_agent);
1635   entryp = chxj_apply_convrule(r, dconf->convrules);
1636   if (!entryp) {
1637     DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1638     return;
1639   }
1640   ctx = apr_palloc(r->pool, sizeof(*ctx));
1641   memset(ctx, 0, sizeof(*ctx));
1642   if ((rv = apr_pool_create(&ctx->pool, r->pool)) != APR_SUCCESS) {
1643     ERR(r, "%s:%d: failed: new pool create. rv:[%d]", __FILE__,__LINE__,rv);
1644     DBG(r, "REQ:[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1645     return;
1646   }
1647   ctx->entryp = entryp;
1648   ctx->spec   = spec;
1649   ctx->buffer = apr_palloc(ctx->pool, 1);
1650   ctx->buffer[0] = 0;
1651
1652   if (!entryp || !(entryp->action & CONVRULE_ENGINE_ON_BIT)) {
1653     DBG(r,"REQ[%X] EngineOff", (unsigned int)(apr_size_t)r);
1654     DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1655     return;
1656   }
1657
1658   switch(spec->html_spec_type) {
1659   case CHXJ_SPEC_Chtml_1_0:
1660   case CHXJ_SPEC_Chtml_2_0:
1661   case CHXJ_SPEC_Chtml_3_0:
1662   case CHXJ_SPEC_Chtml_4_0:
1663   case CHXJ_SPEC_Chtml_5_0:
1664   case CHXJ_SPEC_Chtml_6_0:
1665   case CHXJ_SPEC_Chtml_7_0:
1666   case CHXJ_SPEC_XHtml_Mobile_1_0:
1667   case CHXJ_SPEC_Hdml:
1668   case CHXJ_SPEC_Jhtml:
1669   case CHXJ_SPEC_Jxhtml:
1670     break;
1671
1672   default:
1673     DBG(r, "REQ[%X] end chxj_insert_filter() Unknown spec type(%d).", (unsigned int)(apr_size_t)r, spec->html_spec_type);
1674     return;
1675   }
1676
1677
1678   if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
1679     ap_add_output_filter("chxj_output_filter", ctx, r, r->connection);
1680     DBG(r, "REQ[%X] added Output Filter", (unsigned int)(apr_size_t)r);
1681   }
1682
1683   DBG(r, "REQ[%X] end chxj_insert_filter()", (unsigned int)(apr_size_t)r);
1684 }
1685
1686
1687 /**
1688  * The hook is registered.
1689  *
1690  * @param p
1691  */
1692 static void 
1693 chxj_register_hooks(apr_pool_t *UNUSED(p))
1694 {
1695   ap_hook_post_config(chxj_init_module,
1696                       NULL,
1697                       NULL,
1698                       APR_HOOK_REALLY_FIRST);
1699   ap_hook_child_init(chxj_child_init, 
1700                      NULL, 
1701                      NULL, 
1702                      APR_HOOK_REALLY_FIRST);
1703   ap_register_output_filter (
1704                       "chxj_output_filter", 
1705                       chxj_output_filter, 
1706                       NULL, 
1707                       AP_FTYPE_RESOURCE);
1708   ap_hook_insert_filter(chxj_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
1709   ap_hook_handler(chxj_img_conv_format_handler, NULL, NULL, APR_HOOK_MIDDLE);
1710   ap_hook_handler(chxj_qr_code_handler, NULL, NULL, APR_HOOK_MIDDLE);
1711   ap_hook_handler(chxj_input_handler, NULL, NULL, APR_HOOK_MIDDLE);
1712   ap_hook_translate_name(chxj_translate_name, NULL, NULL, APR_HOOK_MIDDLE);
1713   ap_hook_fixups(chxj_headers_fixup, NULL, NULL, APR_HOOK_FIRST);
1714 }
1715
1716
1717 /**
1718  * A set structure according to the directory is generated. 
1719  *
1720  * @param p
1721  * @param arg
1722  */
1723 static void * 
1724 chxj_create_per_dir_config(apr_pool_t *p, char *arg) 
1725 {
1726   mod_chxj_config *conf;
1727
1728   conf = apr_pcalloc(p, sizeof(mod_chxj_config));
1729   conf->device_data_file = NULL;
1730   conf->devices          = NULL;
1731   conf->emoji_data_file  = NULL;
1732   conf->emoji            = NULL;
1733   conf->emoji_tail       = NULL;
1734   conf->image            = CHXJ_IMG_NONE;
1735   conf->image_cache_dir  = apr_psprintf(p, "%s",DEFAULT_IMAGE_CACHE_DIR);
1736   conf->image_cache_limit = 0;
1737   conf->server_side_encoding = NULL;
1738   conf->cookie_db_dir    = NULL;
1739   conf->cookie_timeout   = 0;
1740   conf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
1741   conf->cookie_lazy_mode  = 0;
1742   conf->cookie_dbm_type  = NULL;
1743 #if defined(USE_MYSQL_COOKIE)
1744   memset((void *)&conf->mysql, 0, sizeof(mysql_t));
1745   conf->mysql.port       = MYSQL_PORT;
1746   conf->mysql.host       = NULL;
1747 #endif
1748 #if defined(USE_MEMCACHE_COOKIE)
1749   memset((void *)&conf->memcache, 0, sizeof(memcache_t));
1750   conf->memcache.host    = NULL;
1751   conf->memcache.port    = 0;
1752 #endif
1753   conf->forward_url_base = NULL;
1754   conf->forward_server_ip = NULL;
1755   conf->allowed_cookie_domain = NULL;
1756   conf->post_log              = NULL;
1757
1758   if (arg == NULL) {
1759     conf->dir                  = NULL;
1760   }
1761   else {
1762     conf->dir                  = apr_pcalloc(p, strlen(arg)+1);
1763     memset(conf->dir, 0, strlen(arg)+1);
1764     strcpy(conf->dir, arg);
1765   }
1766   conf->convrules   = apr_array_make(p, 2, sizeof(chxjconvrule_entry));
1767
1768   /* Default is copyleft */
1769   conf->image_copyright = NULL; 
1770
1771   return conf;
1772 }
1773
1774
1775 /*
1776  *  Merge per-directory CHXJ configurations
1777  */
1778 static void *
1779 chxj_merge_per_dir_config(apr_pool_t *p, void *basev, void *addv)
1780 {
1781   mod_chxj_config *base;
1782   mod_chxj_config *add;
1783   mod_chxj_config *mrg;
1784
1785   base = (mod_chxj_config *)basev;
1786   add  = (mod_chxj_config *)addv;
1787   mrg  = (mod_chxj_config *)apr_palloc(p, sizeof(mod_chxj_config));
1788
1789   mrg->device_data_file = NULL;
1790   mrg->devices          = NULL;
1791   mrg->emoji_data_file  = NULL;
1792   mrg->image            = CHXJ_IMG_NONE;
1793   mrg->image_cache_dir  = NULL;
1794   mrg->image_copyright  = NULL;
1795   mrg->image_cache_limit  = 0;
1796   mrg->emoji            = NULL;
1797   mrg->emoji_tail       = NULL;
1798   mrg->new_line_type    = NLTYPE_NIL;
1799   mrg->forward_url_base = NULL;
1800   mrg->forward_server_ip = NULL;
1801   mrg->allowed_cookie_domain = NULL;
1802   mrg->post_log         = NULL;
1803   mrg->cookie_dbm_type  = NULL;
1804
1805   mrg->dir = apr_pstrdup(p, add->dir);
1806
1807   if (! add->device_data_file) {
1808     mrg->devices = base->devices;
1809     mrg->device_data_file = apr_pstrdup(p, base->device_data_file);
1810   }
1811   else {
1812     mrg->devices = add->devices;
1813     mrg->device_data_file = apr_pstrdup(p, add->device_data_file);
1814   }
1815
1816   if (! add->emoji_data_file) {
1817     mrg->emoji = base->emoji;
1818     mrg->emoji_tail = base->emoji_tail;
1819     mrg->emoji_data_file = apr_pstrdup(p, base->emoji_data_file);
1820   }
1821   else {
1822     mrg->emoji = add->emoji;
1823     mrg->emoji_tail = add->emoji_tail;
1824     mrg->emoji_data_file = apr_pstrdup(p, add->emoji_data_file);
1825   }
1826
1827   if (add->image == CHXJ_IMG_NONE) {
1828     mrg->image = base->image;
1829   }
1830   else {
1831     mrg->image = add->image;
1832   }
1833
1834   if (strcasecmp(add->image_cache_dir ,DEFAULT_IMAGE_CACHE_DIR)==0) {
1835     mrg->image_cache_dir = apr_pstrdup(p, base->image_cache_dir);
1836   }
1837   else {
1838     mrg->image_cache_dir = apr_pstrdup(p, add->image_cache_dir);
1839   }
1840
1841   if (add->image_cache_limit) {
1842     mrg->image_cache_limit = add->image_cache_limit;
1843   }
1844   else {
1845     mrg->image_cache_limit = base->image_cache_limit;
1846   }
1847
1848   if (add->image_copyright) 
1849     mrg->image_copyright = apr_pstrdup(p, add->image_copyright);
1850   else
1851     mrg->image_copyright = apr_pstrdup(p, base->image_copyright);
1852
1853   if (add->server_side_encoding) {
1854     mrg->server_side_encoding = apr_pstrdup(p, add->server_side_encoding);
1855   }
1856   else 
1857   if (base->server_side_encoding) {
1858     mrg->server_side_encoding = apr_pstrdup(p, base->server_side_encoding);
1859   }
1860   else {
1861     mrg->server_side_encoding = apr_pstrdup(p, DEFAULT_SERVER_SIDE_ENCODING);
1862   }
1863
1864   mrg->convrules    = apr_array_append(p, add->convrules, base->convrules);
1865
1866   if (add->cookie_db_dir) {
1867     mrg->cookie_db_dir = apr_pstrdup(p, add->cookie_db_dir);
1868   }
1869   else
1870   if (base->cookie_db_dir) {
1871     mrg->cookie_db_dir = apr_pstrdup(p, base->cookie_db_dir);
1872   }
1873   else {
1874     mrg->cookie_db_dir = NULL;
1875   }
1876
1877   if (add->cookie_timeout) {
1878     mrg->cookie_timeout   = add->cookie_timeout;
1879   }
1880   else
1881   if (base->cookie_db_dir) {
1882     mrg->cookie_timeout   = base->cookie_timeout;
1883   }
1884   else {
1885     mrg->cookie_timeout   = 0;
1886   }
1887
1888 #if defined(USE_MYSQL_COOKIE)
1889   if (add->mysql.host) {
1890     mrg->mysql.host = apr_pstrdup(p, add->mysql.host);
1891   }
1892   else if (base->mysql.host) {
1893     mrg->mysql.host = apr_pstrdup(p, base->mysql.host);
1894   }
1895   else {
1896     mrg->mysql.host = NULL;
1897   }
1898   if (add->mysql.port) {
1899     mrg->mysql.port = add->mysql.port;
1900   }
1901   else if (base->mysql.port) {
1902     mrg->mysql.port = base->mysql.port;
1903   }
1904   else {
1905     mrg->mysql.port = 0;
1906   }
1907
1908   if (add->mysql.database) {
1909     mrg->mysql.database = apr_pstrdup(p, add->mysql.database);
1910   }
1911   else if (base->mysql.database) {
1912     mrg->mysql.database = apr_pstrdup(p, base->mysql.database);
1913   }
1914   else {
1915     mrg->mysql.database = NULL;
1916   }
1917
1918   if (add->mysql.username) {
1919     mrg->mysql.username = apr_pstrdup(p, add->mysql.username);
1920   }
1921   else if (base->mysql.username) {
1922     mrg->mysql.username = apr_pstrdup(p, base->mysql.username);
1923   }
1924   else {
1925     mrg->mysql.username = NULL;
1926   }
1927
1928   if (add->mysql.password) {
1929     mrg->mysql.password = apr_pstrdup(p, add->mysql.password);
1930   }
1931   else if (base->mysql.password) {
1932     mrg->mysql.password = apr_pstrdup(p, base->mysql.password);
1933   }
1934   else {
1935     mrg->mysql.password = NULL;
1936   }
1937
1938   if (add->mysql.tablename) {
1939     mrg->mysql.tablename = apr_pstrdup(p, add->mysql.tablename);
1940   }
1941   else if (base->mysql.tablename) {
1942     mrg->mysql.tablename = apr_pstrdup(p, base->mysql.tablename);
1943   }
1944   else {
1945     mrg->mysql.tablename = NULL;
1946   }
1947
1948   if (add->mysql.socket_path) {
1949     mrg->mysql.socket_path = apr_pstrdup(p, add->mysql.socket_path);
1950   }
1951   else if (base->mysql.socket_path) {
1952     mrg->mysql.socket_path = apr_pstrdup(p, base->mysql.socket_path);
1953   }
1954   else {
1955     mrg->mysql.socket_path = NULL;
1956   }
1957
1958   if (add->mysql.charset) {
1959     mrg->mysql.charset = apr_pstrdup(p, add->mysql.charset);
1960   }
1961   else if (base->mysql.charset) {
1962     mrg->mysql.charset = apr_pstrdup(p, base->mysql.charset);
1963   }
1964   else {
1965     mrg->mysql.charset = NULL;
1966   }
1967 #endif
1968 #if defined(USE_MEMCACHE_COOKIE)
1969   if (add->memcache.host) {
1970     mrg->memcache.host = apr_pstrdup(p, add->memcache.host);
1971   }
1972   else if (base->memcache.host) {
1973     mrg->memcache.host = apr_pstrdup(p, base->memcache.host);
1974   }
1975   else {
1976     mrg->memcache.host = NULL;
1977   }
1978   if (add->memcache.port) {
1979     mrg->memcache.port = add->memcache.port;
1980   }
1981   else if (base->memcache.port) {
1982     mrg->memcache.port = base->memcache.port;
1983   }
1984   else {
1985     mrg->memcache.port = 0;
1986   }
1987 #endif
1988   if (add->cookie_store_type) {
1989     mrg->cookie_store_type = add->cookie_store_type;
1990   }
1991   else if (base->cookie_store_type) {
1992     mrg->cookie_store_type = base->cookie_store_type;
1993   }
1994   else {
1995     mrg->cookie_store_type = COOKIE_STORE_TYPE_NONE;
1996   }
1997   if (add->cookie_lazy_mode) {
1998     mrg->cookie_lazy_mode = add->cookie_lazy_mode;
1999   }
2000   else if (base->cookie_lazy_mode) {
2001     mrg->cookie_lazy_mode = base->cookie_lazy_mode;
2002   }
2003   else {
2004     mrg->cookie_lazy_mode = 0;
2005   }
2006   if (add->new_line_type) {
2007     mrg->new_line_type = add->new_line_type;
2008   }
2009   else if (base->new_line_type) {
2010     mrg->new_line_type = base->new_line_type;
2011   }
2012   else {
2013     mrg->new_line_type = NLTYPE_NIL;
2014   }
2015
2016   if (add->forward_url_base) {
2017     mrg->forward_url_base = add->forward_url_base;
2018   }
2019   else if (base->forward_url_base) {
2020     mrg->forward_url_base = base->forward_url_base;
2021   }
2022
2023   if (add->allowed_cookie_domain) {
2024     mrg->allowed_cookie_domain = add->allowed_cookie_domain;
2025   }
2026   else {
2027     mrg->allowed_cookie_domain = base->allowed_cookie_domain;
2028   }
2029   if (add->post_log) {
2030     mrg->post_log = add->post_log;
2031   }
2032   else {
2033     mrg->post_log = base->post_log;
2034   }
2035   if (add->cookie_dbm_type) {
2036     mrg->cookie_dbm_type = add->cookie_dbm_type;
2037   }
2038   else {
2039     mrg->cookie_dbm_type = base->cookie_dbm_type;
2040   }
2041   return mrg;
2042 }
2043
2044
2045 static int
2046 chxj_command_parse_take5(
2047   const char *arg, 
2048   char       **prm1, 
2049   char       **prm2, 
2050   char       **prm3, 
2051   char       **prm4, 
2052   char       **prm5)
2053 {
2054   int  isquoted;
2055   char *strp;
2056
2057   strp = (char *)arg;
2058
2059   for (;*strp == ' '||*strp == '\t'; strp++) ;
2060
2061   isquoted = 0; 
2062   if (*strp == '"') { 
2063     isquoted = 1;
2064     strp++;
2065   }
2066
2067   *prm1 = strp;
2068
2069   for (; *strp != '\0'; strp++) {
2070     if ((isquoted && (*strp == ' ' || *strp == '\t'))
2071     ||  (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2072       strp++;
2073       continue;
2074     }
2075
2076     if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2077     ||  (isquoted  && *strp == '"'))
2078       break;
2079   }
2080
2081   if (! *strp) {
2082     *prm2 = strp;
2083     *prm3 = strp;
2084     *prm4 = strp;
2085     *prm5 = strp;
2086     return 1;
2087   }
2088
2089   *strp++ = '\0';
2090
2091   for (;*strp == ' '||*strp == '\t'; strp++) ;
2092
2093   isquoted = 0; 
2094   if (*strp == '"') { 
2095     isquoted = 1;
2096     strp++;
2097   }
2098
2099   *prm2 = strp;
2100   for (; *strp != '\0'; strp++) {
2101     if ((isquoted && (*strp == ' ' || *strp == '\t'))
2102     ||  (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2103       strp++;
2104       continue;
2105     }
2106
2107     if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2108     ||  (isquoted  && *strp == '"'))
2109       break;
2110   }
2111
2112   if (! *strp) {
2113     *prm3 = strp;
2114     *prm4 = strp;
2115     *prm5 = strp;
2116     return 0;
2117   }
2118
2119   *strp++ = '\0';
2120
2121   for (;*strp == ' '||*strp == '\t'; strp++);
2122
2123   isquoted = 0; 
2124   if (*strp == '"') { 
2125     isquoted = 1;
2126     strp++;
2127   }
2128   *prm3 = strp;
2129   for (; *strp != '\0'; strp++) {
2130     if ((isquoted && (*strp == ' ' || *strp == '\t'))
2131     ||  (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2132       strp++;
2133       continue;
2134     }
2135
2136     if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2137     ||  (isquoted  && *strp == '"'))
2138       break;
2139   }
2140
2141   if (! *strp) {
2142     *prm4 = strp;
2143     *prm5 = strp;
2144     return 0;
2145   }
2146
2147   *strp++ = '\0';
2148
2149   for (;*strp == ' '||*strp == '\t'; strp++);
2150
2151   isquoted = 0; 
2152   if (*strp == '"') { 
2153     isquoted = 1;
2154     strp++;
2155   }
2156   *prm4 = strp;
2157   for (; *strp != '\0'; strp++) {
2158     if ((isquoted && (*strp == ' ' || *strp == '\t'))
2159     ||  (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2160       strp++;
2161       continue;
2162     }
2163
2164     if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2165     ||  (isquoted  && *strp == '"'))
2166       break;
2167   }
2168
2169   if (! *strp) {
2170     *prm5 = strp;
2171     return 0;
2172   }
2173
2174   *strp++ = '\0';
2175
2176   for (;*strp == ' '||*strp == '\t'; strp++);
2177
2178   isquoted = 0; 
2179   if (*strp == '"') { 
2180     isquoted = 1;
2181     strp++;
2182   }
2183   *prm5 = strp;
2184   for (; *strp != '\0'; strp++) {
2185     if ((isquoted && (*strp == ' ' || *strp == '\t'))
2186     ||  (*strp == '\\' && (*(strp+1) == ' ' || *(strp+1) == '\t'))) {
2187       strp++;
2188       continue;
2189     }
2190
2191     if ((!isquoted && (*strp == ' ' || *strp == '\t'))
2192     ||  (isquoted  && *strp == '"'))
2193       break;
2194   }
2195   *strp = '\0';
2196
2197   return 0;
2198 }
2199
2200
2201 /**
2202  * The device definition file is loaded. 
2203  *
2204  * @param arg     [i]   The name of the device definition file is specified.
2205  * @param mconfig [i/o] The pointer to a set structure is specified. 
2206  * @param parms   [i]   
2207  */
2208 static const char * 
2209 cmd_load_device_data(cmd_parms *parms, void *mconfig, const char *arg) 
2210 {
2211   mod_chxj_config  *conf;
2212   Doc              doc;
2213
2214   doc.r = NULL;
2215
2216   if (strlen(arg) > 256) 
2217     return "mod_chxj: device data filename too long.";
2218
2219   conf = (mod_chxj_config *)mconfig;
2220   conf->device_data_file = apr_pstrdup(parms->pool, arg);
2221
2222   qs_init_malloc(&doc);
2223   qs_init_root_node(&doc);
2224
2225   qs_parse_file((Doc *)&doc, (const char *)arg);
2226   chxj_load_device_data(&doc,parms->pool, conf);
2227   qs_all_free(&doc, QX_LOGMARK);
2228
2229   return NULL;
2230 }
2231
2232
2233 /**
2234  * Device definition information is loaded. 
2235  *
2236  * @param parms 
2237  * @param arg     [i]   The name of the device definition file is specified. 
2238  * @param mconfig [i/o] The pointer to a set structure is specified. 
2239  * @return 
2240  */
2241 static const char * 
2242 cmd_load_emoji_data(cmd_parms *parms, void *mconfig, const char *arg) 
2243 {
2244   mod_chxj_config *conf;
2245   char            *rtn;
2246   Doc              doc;
2247
2248   doc.r = NULL;
2249
2250
2251   if (strlen(arg) > 256) 
2252     return "mod_chxj: emoji data filename too long.";
2253
2254   conf = (mod_chxj_config *)mconfig;
2255   conf->emoji_data_file = apr_pstrdup(parms->pool, arg);
2256   qs_init_malloc(&doc);
2257   qs_init_root_node(&doc);
2258
2259   qs_parse_file((Doc *)&doc, (const char *)arg);
2260
2261   rtn = chxj_load_emoji_data(&doc,parms->pool, conf);
2262
2263   qs_all_free(&doc, QX_LOGMARK);
2264
2265
2266   return rtn;
2267 }
2268
2269
2270 static const char * 
2271 cmd_set_image_engine(cmd_parms * UNUSED(parms), void *mconfig, const char *arg) 
2272 {
2273   mod_chxj_config *conf;
2274   Doc              doc;
2275
2276   doc.r = NULL;
2277
2278   if (strlen(arg) > 256) 
2279     return "image uri is too long.";
2280
2281   conf = (mod_chxj_config*)mconfig;
2282   if (strcasecmp("ON", arg) == 0) {
2283     conf->image = CHXJ_IMG_ON;
2284   }
2285   else {
2286     conf->image = CHXJ_IMG_OFF;
2287   }
2288
2289   return NULL;
2290 }
2291
2292
2293 static const char * 
2294 cmd_set_image_cache_dir(cmd_parms *parms, void *mconfig, const char *arg) 
2295 {
2296   mod_chxj_config *conf;
2297   Doc              doc;
2298
2299   doc.r = NULL;
2300
2301   if (strlen(arg) > 256) 
2302     return "cache dir name is too long.";
2303
2304   conf = (mod_chxj_config *)mconfig;
2305   conf->image_cache_dir = apr_pstrdup(parms->pool, arg);
2306
2307   return NULL;
2308 }
2309
2310
2311 static const char * 
2312 cmd_set_image_cache_limit(cmd_parms *parms, void *mconfig, const char *arg) 
2313 {
2314   mod_chxj_config *conf;
2315   Doc              doc;
2316
2317   doc.r = NULL;
2318
2319   if (strlen(arg) > IMAGE_CACHE_LIMIT_FMT_LEN) 
2320     return "cache size is too long.";
2321
2322   conf = (mod_chxj_config *)mconfig;
2323   errno = 0;
2324   /* 
2325    * I use strtol function because strtoul is not portable function. 
2326    */
2327   conf->image_cache_limit = (unsigned long)strtol(arg, NULL, 10);
2328   switch (errno) {
2329   case EINVAL:
2330     return apr_psprintf(parms->pool, "ChxjImageCacheLimit invalid value [%s] errno:[%d]", arg, errno);
2331   case ERANGE:
2332     return apr_psprintf(parms->pool, "ChxjImageCacheLimit Out of range [%s] errno:[%d]", arg, errno);
2333   default:
2334     break;
2335   }
2336   return NULL;
2337 }
2338
2339
2340 static const char * 
2341 cmd_set_image_copyright(cmd_parms *parms, void *mconfig, const char *arg) 
2342 {
2343   mod_chxj_config *conf;
2344   Doc              doc;
2345
2346   doc.r = NULL;
2347
2348   if (strlen(arg) > 256) 
2349     return "Copyright Flag is too long.";
2350
2351   conf = (mod_chxj_config *)mconfig;
2352   conf->image_copyright = apr_pstrdup(parms->pool, arg);
2353
2354   return NULL;
2355 }
2356
2357
2358 static const char *
2359 cmd_convert_rule(cmd_parms *cmd, void *mconfig, const char *arg)
2360 {
2361   int                 mode;
2362   ap_regex_t          *regexp;
2363   mod_chxj_config     *dconf;
2364   chxjconvrule_entry  *newrule;
2365   char                *prm1;
2366   char                *prm2;
2367   char                *prm3;
2368   char                *prm4;
2369   char                *prm5;
2370   char                *pstate;
2371   char                *action;
2372   char                *pp;
2373
2374   dconf = (mod_chxj_config *)mconfig;
2375
2376   if (strlen(arg) > 4096) 
2377     return "mod_chxj: ChxjConvertRule: is too long.";
2378
2379   dconf = (mod_chxj_config *)mconfig;
2380   if (dconf->convrules == NULL)
2381     dconf->convrules   = apr_array_make(cmd->pool, 
2382                                         2, 
2383                                         sizeof(chxjconvrule_entry));
2384
2385   newrule = apr_array_push(dconf->convrules);
2386
2387   newrule->flags  = 0;
2388   newrule->action = 0;
2389
2390   if (chxj_command_parse_take5(arg, &prm1, &prm2, &prm3, &prm4, &prm5))
2391     return "ChxjConvertRule: bad argument line";
2392
2393   newrule->pattern = apr_pstrdup(cmd->pool, prm1);
2394
2395   /* Parse action */
2396   for (;;) {
2397     if ((action = apr_strtok(prm2, ",", &pstate)) == NULL)
2398       break;
2399     prm2 = NULL;
2400     switch(*action) {
2401     case 'e':
2402     case 'E':
2403       if (strcasecmp(CONVRULE_ENGINE_ON_CMD, action) == 0) {
2404         newrule->action |= CONVRULE_ENGINE_ON_BIT;
2405       }
2406       else
2407       if (strcasecmp(CONVRULE_ENGINE_OFF_CMD, action) == 0) {
2408         newrule->action |= CONVRULE_ENGINE_OFF_BIT;
2409       }
2410       else
2411       if (strcasecmp(CONVRULE_EMOJI_ONLY_CMD, action) == 0) {
2412         newrule->action |= CONVRULE_EMOJI_ONLY_BIT;
2413       }
2414       else
2415       if (strcasecmp(CONVRULE_ENVINFO_ONLY_CMD, action) == 0) {
2416         newrule->action |= CONVRULE_ENVINFO_ONLY_BIT;
2417       }
2418       break;
2419
2420     case 'C':
2421     case 'c':
2422       if (strcasecmp(CONVRULE_COOKIE_ON_CMD, action) == 0) {
2423         newrule->action |= CONVRULE_COOKIE_ON_BIT;
2424       }
2425       else if (strcasecmp(CONVRULE_COOKIE_OFF_CMD, action) == 0) {
2426         newrule->action &= (0xffffffff ^ CONVRULE_COOKIE_ON_BIT);
2427       }
2428       else if (strcasecmp(CONVRULE_CSS_ON_CMD, action) == 0) {
2429         newrule->action |= CONVRULE_CSS_ON_BIT;
2430       }
2431       else if (strcasecmp(CONVRULE_CSS_OFF_CMD, action) == 0) {
2432         newrule->action &= (0xffffffff ^ CONVRULE_CSS_ON_BIT);
2433       }
2434       break;
2435
2436     case 'J':
2437     case 'j':
2438       if (strcasecmp(CONVRULE_JRCONV_OFF_CMD, action) == 0) {
2439         newrule->action |= CONVRULE_JRCONV_OFF_BIT;
2440       }
2441       break;
2442
2443     case 'N':
2444     case 'n':
2445       if (strcasecmp(CONVRULE_NOCACHE_ON_CMD, action) == 0) {
2446         newrule->action |= CONVRULE_NOCACHE_ON_BIT;
2447       }
2448       break;
2449
2450     case 'Q':
2451     case 'q':
2452       if (strcasecmp(CONVRULE_QSCONV_OFF_CMD, action) == 0) {
2453         newrule->action |= CONVRULE_QSCONV_OFF_BIT;
2454       }
2455       break;
2456
2457     case 'Z':
2458     case 'z':
2459       if (strcasecmp(CONVRULE_Z2H_ON_CMD, action) == 0) {
2460         newrule->action |= CONVRULE_Z2H_ON_BIT;
2461       }
2462       else
2463       if (strcasecmp(CONVRULE_Z2H_OFF_CMD, action) == 0) {
2464         newrule->action |= CONVRULE_Z2H_OFF_BIT;
2465       }
2466       else
2467       if (strcasecmp(CONVRULE_Z2H_ALPHA_ON_CMD, action) == 0) {
2468         newrule->action |= CONVRULE_Z2H_ALPHA_ON_BIT;
2469       }
2470       else
2471       if (strcasecmp(CONVRULE_Z2H_ALPHA_OFF_CMD, action) == 0) {
2472         newrule->action |= CONVRULE_Z2H_ALPHA_OFF_BIT;
2473       }
2474       else
2475       if (strcasecmp(CONVRULE_Z2H_NUM_ON_CMD, action) == 0) {
2476         newrule->action |= CONVRULE_Z2H_NUM_ON_BIT;
2477       }
2478       else
2479       if (strcasecmp(CONVRULE_Z2H_NUM_OFF_CMD, action) == 0) {
2480         newrule->action |= CONVRULE_Z2H_NUM_OFF_BIT;
2481       }
2482       else
2483       if (strcasecmp(CONVRULE_Z2H_ALL_ON_CMD, action) == 0) {
2484         newrule->action |= CONVRULE_Z2H_ON_BIT | CONVRULE_Z2H_ALPHA_ON_BIT | CONVRULE_Z2H_NUM_ON_BIT;
2485       }
2486       else
2487       if (strcasecmp(CONVRULE_Z2H_NUM_OFF_CMD, action) == 0) {
2488         newrule->action |= CONVRULE_Z2H_OFF_BIT | CONVRULE_Z2H_ALPHA_OFF_BIT | CONVRULE_Z2H_NUM_OFF_BIT;
2489       }
2490       break;
2491
2492     default:
2493       break;
2494     }
2495   }
2496   
2497   pp = prm1;
2498   if (*pp == '!') {
2499     newrule->flags |= CONVRULE_FLAG_NOTMATCH;
2500     pp++;
2501   }
2502
2503   mode = AP_REG_EXTENDED;
2504   if ((regexp = ap_pregcomp((apr_pool_t *)cmd->pool, (const char *)pp, mode)) == NULL)
2505     return "RewriteRule: cannot compile regular expression ";
2506
2507   newrule->regexp = regexp;
2508   if (*prm3)
2509     newrule->encoding = apr_pstrdup(cmd->pool, prm3);
2510   else
2511     newrule->encoding = apr_pstrdup(cmd->pool, "none");
2512
2513   newrule->pc_flag = CONVRULE_PC_FLAG_OFF_BIT;
2514   if (*prm4)
2515     if (strcasecmp(CONVRULE_PC_FLAG_ON_CMD, prm4) == 0)
2516       newrule->pc_flag = CONVRULE_PC_FLAG_ON_BIT;
2517
2518   newrule->user_agent = NULL;
2519   if (*prm5)
2520     newrule->user_agent = apr_pstrdup(cmd->pool, prm5);
2521     
2522   return NULL;
2523 }
2524
2525
2526 static const char *
2527 cmd_set_cookie_dir(
2528   cmd_parms   *cmd, 
2529   void        *mconfig, 
2530   const char  *arg)
2531 {
2532   mod_chxj_config *dconf;
2533
2534
2535   if (strlen(arg) > 4096) 
2536     return "mod_chxj: ChxjCookieDir is too long.";
2537
2538   dconf = (mod_chxj_config *)mconfig;
2539
2540   dconf->cookie_db_dir = apr_pstrdup(cmd->pool, arg);
2541
2542   return NULL;
2543 }
2544
2545
2546 static const char *
2547 cmd_set_cookie_timeout(
2548   cmd_parms   *UNUSED(cmd), 
2549   void        *mconfig, 
2550   const char  *arg)
2551 {
2552   mod_chxj_config *dconf;
2553
2554   if (strlen(arg) > 4096) 
2555     return "mod_chxj: ChxjCookieTimeout is too long.";
2556
2557   if (chxj_chk_numeric(arg) != 0)
2558     return "mod_chxj: ChxjCookieTimeout is not numeric.";
2559
2560   dconf = (mod_chxj_config *)mconfig;
2561
2562   dconf->cookie_timeout = atoi(arg);
2563
2564   return NULL;
2565 }
2566
2567
2568 #if defined(USE_MYSQL_COOKIE)
2569 static const char *
2570 cmd_set_cookie_mysql_database(
2571   cmd_parms   *cmd, 
2572   void        *mconfig, 
2573   const char  *arg)
2574 {
2575   mod_chxj_config  *dconf;
2576
2577   if (strlen(arg) > 255) 
2578     return "mod_chxj: ChxjCookieMysqlDatabase is too long.";
2579
2580   dconf = (mod_chxj_config *)mconfig;
2581
2582   dconf->mysql.database = apr_pstrdup(cmd->pool, arg);
2583
2584   return NULL;
2585 }
2586
2587
2588 static const char *
2589 cmd_set_cookie_mysql_username(
2590   cmd_parms   *cmd, 
2591   void        *mconfig, 
2592   const char  *arg)
2593 {
2594   mod_chxj_config  *dconf;
2595
2596   if (strlen(arg) > 255) 
2597     return "mod_chxj: ChxjCookieMysqlUsername is too long.";
2598
2599   dconf = (mod_chxj_config *)mconfig;
2600
2601   dconf->mysql.username = apr_pstrdup(cmd->pool, arg);
2602
2603   return NULL;
2604 }
2605
2606
2607 static const char *
2608 cmd_set_cookie_mysql_password(
2609   cmd_parms   *cmd, 
2610   void        *mconfig, 
2611   const char  *arg)
2612 {
2613   mod_chxj_config  *dconf;
2614
2615   if (strlen(arg) > 255) 
2616     return "mod_chxj: ChxjCookieMysqlPassword is too long.";
2617
2618   dconf = (mod_chxj_config *)mconfig;
2619
2620   dconf->mysql.password = apr_pstrdup(cmd->pool, arg);
2621
2622   return NULL;
2623 }
2624
2625
2626 static const char *
2627 cmd_set_cookie_mysql_table_name(
2628   cmd_parms   *cmd, 
2629   void        *mconfig, 
2630   const char  *arg)
2631 {
2632   mod_chxj_config  *dconf;
2633
2634   if (strlen(arg) > 255) 
2635     return "mod_chxj: ChxjCookieMysqlTableName is too long.";
2636
2637   dconf = (mod_chxj_config *)mconfig;
2638
2639   dconf->mysql.tablename = apr_pstrdup(cmd->pool, arg);
2640
2641   return NULL;
2642 }
2643
2644 static const char *
2645 cmd_set_cookie_mysql_port(
2646   cmd_parms   *UNUSED(cmd), 
2647   void        *mconfig, 
2648   const char  *arg)
2649 {
2650   mod_chxj_config *dconf;
2651
2652   if (strlen(arg) > 255) 
2653     return "mod_chxj: ChxjCookieMysqlPort is too long.";
2654
2655   dconf = (mod_chxj_config *)mconfig;
2656
2657   if (chxj_chk_numeric(arg) != 0)
2658     return "mod_chxj: ChxjCookieMysqlPort is not numeric.";
2659
2660   dconf = (mod_chxj_config *)mconfig;
2661
2662   dconf->mysql.port = chxj_atoi(arg);
2663
2664   return NULL;
2665 }
2666
2667
2668 static const char *
2669 cmd_set_cookie_mysql_host(
2670   cmd_parms   *cmd, 
2671   void        *mconfig, 
2672   const char  *arg)
2673 {
2674   mod_chxj_config  *dconf;
2675
2676   if (strlen(arg) > 255) 
2677     return "mod_chxj: ChxjCookieMysqlHost is too long.";
2678
2679   dconf = (mod_chxj_config *)mconfig;
2680
2681   dconf->mysql.host = apr_pstrdup(cmd->pool, arg);
2682
2683   return NULL;
2684 }
2685
2686
2687 static const char *
2688 cmd_set_cookie_mysql_socket_path(
2689   cmd_parms   *cmd, 
2690   void        *mconfig, 
2691   const char  *arg)
2692 {
2693   mod_chxj_config  *dconf;
2694
2695   if (strlen(arg) > 4096) 
2696     return "mod_chxj: ChxjCookieMysqlSocketPath is too long.";
2697
2698   dconf = (mod_chxj_config *)mconfig;
2699
2700   dconf->mysql.socket_path = apr_pstrdup(cmd->pool, arg);
2701
2702   return NULL;
2703 }
2704
2705
2706 static const char *
2707 cmd_set_cookie_mysql_charset(
2708   cmd_parms   *cmd, 
2709   void        *mconfig, 
2710   const char  *arg)
2711 {
2712   mod_chxj_config  *dconf;
2713
2714   if (strlen(arg) > 255) 
2715     return "mod_chxj: ChxjCookieMysqlCharset is too long.";
2716
2717   dconf = (mod_chxj_config *)mconfig;
2718
2719   dconf->mysql.charset = apr_pstrdup(cmd->pool, arg);
2720
2721   return NULL;
2722 }
2723 #endif
2724 #if defined(USE_MEMCACHE_COOKIE)
2725 static const char *
2726 cmd_set_cookie_memcache_port(
2727   cmd_parms   *UNUSED(cmd), 
2728   void        *mconfig, 
2729   const char  *arg)
2730 {
2731   mod_chxj_config *dconf;
2732
2733   if (strlen(arg) > 255) 
2734     return "mod_chxj: ChxjCookieMemcachePort is too long.";
2735
2736   dconf = (mod_chxj_config *)mconfig;
2737
2738   if (chxj_chk_numeric(arg) != 0)
2739     return "mod_chxj: ChxjCookieMemcachePort is not numeric.";
2740
2741   dconf = (mod_chxj_config *)mconfig;
2742
2743   dconf->memcache.port = (apr_port_t)chxj_atoi(arg);
2744
2745   return NULL;
2746 }
2747
2748
2749 static const char *
2750 cmd_set_cookie_memcache_host(
2751   cmd_parms   *cmd, 
2752   void        *mconfig, 
2753   const char  *arg)
2754 {
2755   mod_chxj_config  *dconf;
2756
2757   if (strlen(arg) > 255) 
2758     return "mod_chxj: ChxjCookieMemcacheHost is too long.";
2759
2760   dconf = (mod_chxj_config *)mconfig;
2761
2762   dconf->memcache.host = apr_pstrdup(cmd->pool, arg);
2763
2764   return NULL;
2765 }
2766 #endif
2767
2768 static const char *
2769 cmd_set_cookie_lazy_mode(
2770   cmd_parms   *UNUSED(cmd), 
2771   void        *mconfig, 
2772   const char  *arg)
2773 {
2774   mod_chxj_config  *dconf;
2775
2776   if (strlen(arg) > 255) 
2777     return "mod_chxj: ChxjCookieLazyMode is too long.";
2778
2779   dconf = (mod_chxj_config *)mconfig;
2780
2781   if (strcasecmp("TRUE",arg) == 0) {
2782     dconf->cookie_lazy_mode = COOKIE_LAZY_ON;
2783   }
2784   else {
2785     dconf->cookie_lazy_mode = COOKIE_LAZY_OFF;
2786   }
2787
2788   return NULL;
2789 }
2790
2791 static const char *
2792 cmd_set_cookie_store_type(
2793   cmd_parms   *UNUSED(cmd), 
2794   void        *mconfig, 
2795   const char  *arg)
2796 {
2797   mod_chxj_config  *dconf;
2798
2799   if (strlen(arg) > 255) 
2800     return "mod_chxj: ChxjCookieStoreType is too long.";
2801
2802   dconf = (mod_chxj_config *)mconfig;
2803
2804   if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_DBM, arg) == 0) {
2805     dconf->cookie_store_type = COOKIE_STORE_TYPE_DBM;
2806   }
2807   else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MYSQL, arg) == 0) {
2808     dconf->cookie_store_type = COOKIE_STORE_TYPE_MYSQL;
2809   }
2810   else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MEMCACHE, arg) == 0) {
2811     dconf->cookie_store_type = COOKIE_STORE_TYPE_MEMCACHE;
2812   }
2813   else {
2814     dconf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
2815   }
2816
2817   return NULL;
2818 }
2819
2820 static const char *
2821 cmd_set_forward_url_base(
2822   cmd_parms   *cmd,
2823   void        *mconfig,
2824   const char  *arg)
2825 {
2826  mod_chxj_config *dconf;
2827
2828   if (strlen(arg) > 255)
2829     return "mod_chxj: ChxjForwardUrlBase is too long.";
2830
2831   dconf = (mod_chxj_config *)mconfig;
2832
2833   dconf->forward_url_base = apr_pstrdup(cmd->pool, arg);
2834
2835   return NULL;
2836 }
2837
2838 static const char *
2839 cmd_set_forward_server_ip(
2840   cmd_parms   *cmd,
2841   void        *mconfig,
2842   const char  *arg)
2843 {
2844   mod_chxj_config *dconf;
2845
2846   if (strlen(arg) > 255)
2847     return "mod_chxj: ChxjForwardServerIp is too long.";
2848
2849   dconf = (mod_chxj_config *)mconfig;
2850
2851   dconf->forward_server_ip = apr_pstrdup(cmd->pool, arg);
2852
2853   return NULL;
2854 }
2855
2856 static const char *
2857 cmd_allowed_cookie_domain(
2858   cmd_parms   *cmd,
2859   void        *mconfig,
2860   const char  *arg)
2861 {
2862   mod_chxj_config *dconf;
2863
2864   if (strlen(arg) > 255)
2865     return "mod_chxj: ChxjAllowedCookieDomain is too long.";
2866
2867   dconf = (mod_chxj_config *)mconfig;
2868
2869   dconf->allowed_cookie_domain = apr_pstrdup(cmd->pool, arg);
2870
2871   return NULL;
2872 }
2873
2874 static const char *
2875 cmd_set_new_line_type(
2876   cmd_parms   *UNUSED(cmd), 
2877   void        *mconfig, 
2878   const char  *arg)
2879 {
2880   mod_chxj_config  *dconf;
2881   if (strlen(arg) > 255)
2882     return "mod_chxj: ChxjNewLineType is too long.";
2883
2884   dconf = (mod_chxj_config *)mconfig;
2885
2886   if (strcasecmp(CHXJ_NEW_LINE_TYPE_CRLF, arg) == 0) {
2887     dconf->new_line_type = NLTYPE_CRLF;
2888   }
2889   else if (strcasecmp(CHXJ_NEW_LINE_TYPE_LF, arg) == 0) {
2890     dconf->new_line_type = NLTYPE_LF;
2891   }
2892   else if (strcasecmp(CHXJ_NEW_LINE_TYPE_CR, arg) == 0) {
2893     dconf->new_line_type = NLTYPE_CR;
2894   }
2895   else if (strcasecmp(CHXJ_NEW_LINE_TYPE_NONE, arg) == 0) {
2896     dconf->new_line_type = NLTYPE_NONE;
2897   }
2898   else {
2899     return "mod_chxj: invalid value (ChxjNewLineType)";
2900   }
2901   return NULL;
2902 }
2903
2904 static const char *
2905 cmd_post_log_env(
2906   cmd_parms   *cmd, 
2907   void        *mconfig, 
2908   const char  *arg)
2909 {
2910   mod_chxj_config  *dconf;
2911   if (strlen(arg) > 255)
2912     return "mod_chxj: ChxjPostLogEnv is too long.";
2913
2914   dconf = (mod_chxj_config *)mconfig;
2915
2916   dconf->post_log = apr_pstrdup(cmd->pool, arg);
2917
2918   return NULL;
2919 }
2920
2921 static const char *
2922 cmd_cookie_dbm_type(
2923   cmd_parms   *cmd, 
2924   void        *mconfig, 
2925   const char  *arg)
2926 {
2927   mod_chxj_config  *dconf;
2928   if (strlen(arg) > 255)
2929     return "mod_chxj: ChxjCookieDbmType is too long.";
2930
2931   dconf = (mod_chxj_config *)mconfig;
2932
2933   dconf->cookie_dbm_type = apr_pstrdup(cmd->pool, arg);
2934
2935   return NULL;
2936 }
2937
2938
2939 static const command_rec cmds[] = {
2940   AP_INIT_TAKE1(
2941     "ChxjLoadDeviceData",
2942     cmd_load_device_data,
2943     NULL,
2944     OR_ALL,
2945     "Load Device Data"),
2946   AP_INIT_TAKE1(
2947     "ChxjLoadEmojiData",
2948     cmd_load_emoji_data,
2949     NULL,
2950     OR_ALL,
2951     "Load Emoji Data"),
2952   AP_INIT_TAKE1(
2953     "ChxjImageEngine",
2954     cmd_set_image_engine,
2955     NULL,
2956     OR_ALL,
2957     "Convert Target URI"),
2958   AP_INIT_TAKE1(
2959     "ChxjImageCacheDir",
2960     cmd_set_image_cache_dir,
2961     NULL,
2962     OR_ALL,
2963     "Image Cache Directory"),
2964   AP_INIT_TAKE1(
2965     "ChxjImageCacheLimit",
2966     cmd_set_image_cache_limit,
2967     NULL,
2968     OR_ALL,
2969     "Image Cache Limit"),
2970   AP_INIT_TAKE1(
2971     "ChxjImageCopyright",
2972     cmd_set_image_copyright,
2973     NULL,
2974     OR_ALL,
2975     "Copyright Flag"),
2976   AP_INIT_RAW_ARGS(
2977     "ChxjConvertRule",
2978     cmd_convert_rule,
2979     NULL, 
2980     OR_FILEINFO,
2981     "an URL-applied regexp-pattern and a substitution URL"),
2982   AP_INIT_TAKE1(
2983     "ChxjCookieDir",
2984     cmd_set_cookie_dir,
2985     NULL,
2986     OR_ALL,
2987     "save cookie.db directory."),
2988   AP_INIT_TAKE1(
2989     "ChxjCookieTimeout",
2990     cmd_set_cookie_timeout,
2991     NULL,
2992     OR_ALL,
2993     "The compulsion time-out time of the cookie is specified. "),
2994   AP_INIT_TAKE1(
2995     "ChxjCookieStoreType",
2996     cmd_set_cookie_store_type,
2997     NULL,
2998     OR_ALL,
2999     "It specifies preserving of the cookie ahead. (DBM/MYSQL/MEMCACHE)"),
3000   AP_INIT_TAKE1(
3001     "ChxjCookieLazyMode",
3002     cmd_set_cookie_lazy_mode,
3003     NULL,
3004     OR_ALL,
3005     "OneTimeID is negligently done. (TRUE/FALSE)"),
3006 #if defined(USE_MYSQL_COOKIE)
3007   AP_INIT_TAKE1(
3008     "ChxjCookieMysqlHost",
3009     cmd_set_cookie_mysql_host,
3010     NULL,
3011     OR_ALL,
3012     "The MySQL database host used by saving Cookie"),
3013   AP_INIT_TAKE1(
3014     "ChxjCookieMysqlPort",
3015     cmd_set_cookie_mysql_port,
3016     NULL,
3017     OR_ALL,
3018     "The MySQL database port used by saving Cookie"),
3019   AP_INIT_TAKE1(
3020     "ChxjCookieMysqlDatabase",
3021     cmd_set_cookie_mysql_database,
3022     NULL,
3023     OR_ALL,
3024     "The MySQL database name used by saving Cookie"),
3025   AP_INIT_TAKE1(
3026     "ChxjCookieMysqlUsername",
3027     cmd_set_cookie_mysql_username,
3028     NULL,
3029     OR_ALL,
3030     "The MySQL username used by saving Cookie"),
3031   AP_INIT_TAKE1(
3032     "ChxjCookieMysqlPassword",
3033     cmd_set_cookie_mysql_password,
3034     NULL,
3035     OR_ALL,
3036     "The MySQL password used by saving Cookie"),
3037   AP_INIT_TAKE1(
3038     "ChxjCookieMysqlTableName",
3039     cmd_set_cookie_mysql_table_name,
3040     NULL,
3041     OR_ALL,
3042     "The MySQL table name used by saving Cookie"),
3043   AP_INIT_TAKE1(
3044     "ChxjCookieMysqlSocketPath",
3045     cmd_set_cookie_mysql_socket_path,
3046     NULL,
3047     OR_ALL,
3048     "The MySQL socket path used by saving Cookie"),
3049   AP_INIT_TAKE1(
3050     "ChxjCookieMysqlCharset",
3051     cmd_set_cookie_mysql_charset,
3052     NULL,
3053     OR_ALL,
3054     "The MySQL charset used by saving Cookie"),
3055 #endif
3056 #if defined(USE_MEMCACHE_COOKIE)
3057   AP_INIT_TAKE1(
3058     "ChxjCookieMemcacheHost",
3059     cmd_set_cookie_memcache_host,
3060     NULL,
3061     OR_ALL,
3062     "The Memcached host used by saving Cookie"),
3063   AP_INIT_TAKE1(
3064     "ChxjCookieMemcachePort",
3065     cmd_set_cookie_memcache_port,
3066     NULL,
3067     OR_ALL,
3068     "The Memcached port used by saving Cookie"),
3069 #endif
3070   AP_INIT_TAKE1(
3071     "ChxjNewLineType",
3072     cmd_set_new_line_type,
3073     NULL,
3074     OR_ALL,
3075     "HTML new line type (NONE|CRLF|LF|CR). default is CRLF"),
3076   AP_INIT_TAKE1(
3077     "ChxjForwardUrlBase",
3078     cmd_set_forward_url_base,
3079     NULL,
3080     OR_ALL,
3081     "The forward url base(default: {request protocol}://{this server}:{this server port}"),
3082   AP_INIT_TAKE1(
3083     "ChxjForwardServerIp",
3084     cmd_set_forward_server_ip,
3085     NULL,
3086     OR_ALL,
3087     "The forward server ip(default: this server ip)"),
3088   AP_INIT_TAKE1(
3089     "ChxjAllowedCookieDomain",
3090     cmd_allowed_cookie_domain,
3091     NULL,
3092     OR_ALL,
3093     "Domain that permits parameter addition for cookie besides hostname.(Default:hostname Only)"),
3094   AP_INIT_TAKE1(
3095     "ChxjPostLogEnv",
3096     cmd_post_log_env,
3097     NULL,
3098     OR_ALL,
3099     "for CustomLog directive. mod_chxj's internal POST log environment name.(Default:chxj-post-log)"),
3100   AP_INIT_TAKE1(
3101     "ChxjCookieDbmType",
3102     cmd_cookie_dbm_type,
3103     NULL,
3104     OR_ALL,
3105     "Kind of DBM used with Cookie simulator.(default|GDBM|SDBM|DB|NDBM)"),
3106   {NULL,{NULL},NULL,0,0,NULL},
3107 };
3108
3109
3110 /*----------------------------------------------------------------------------*/
3111 /* Dispatch list for API hooks                                                */
3112 /*----------------------------------------------------------------------------*/
3113 module AP_MODULE_DECLARE_DATA chxj_module = {
3114   STANDARD20_MODULE_STUFF, 
3115   chxj_create_per_dir_config,          /* create per-dir    config structures */
3116   chxj_merge_per_dir_config,           /* merge  per-dir    config structures */
3117   chxj_config_server_create,           /* create per-server config structures */
3118   NULL,                                /* merge  per-server config structures */
3119   cmds,                                /* table of config file commands       */
3120   chxj_register_hooks                  /* register hooks                      */
3121 };
3122 /*
3123  * vim:ts=2 et
3124  */