2 * Copyright (C) 2005-2009 Atsushi Konno All rights reserved.
3 * Copyright (C) 2005 QSDN,Inc. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 #ifndef __MOD_CHXJ_H__
18 #define __MOD_CHXJ_H__
21 #define CHXJ_FALSE (0)
23 /* #define DEBUG_FD(X,args...) {FILE*fp=fopen("/tmp/error.log", "ab");fprintf(fp, X, ##args);fflush(fp);fclose(fp);} */
26 #elif defined(__GNUC__)
27 # define UNUSED(x) UNUSED_ ## x __attribute__((unused))
28 #elif defined(__LCLINT__)
29 # define UNUSED(x) /*@unused@*/ x
37 #include "chxj_apache.h"
39 #include "apr_strings.h"
40 #include "apr_buckets.h"
42 #include "apr_tables.h"
44 #include "apr_general.h"
45 #include "apr_pools.h"
47 #if defined(AP_NEED_SET_MUTEX_PERMS)
50 #if !defined(AP_NEED_SET_MUTEX_PERMS)
51 # if !defined(OS2) && !defined(WIN32) && !defined(BEOS) && !defined(NETWARE)
52 # define AP_NEED_SET_MUTEX_PERMS
56 #define STRCASEEQ(a,b,c,d) \
57 ((((a) == *(d))|| ((b) == *(d))) && strcasecmp((c),(d)) == 0)
58 #define STRNCASEEQ(a,b,c,d,e) \
59 ((((a) == *(d))|| ((b) == *(d))) && strncasecmp((c),(d),(e)) == 0)
61 #define CHXJ_QUERY_STRING_PARAM_PREFIX "_chxj_qs_"
62 #define CHXJ_QUERY_STRING_PARAM_PREFIX_ENC "%5Fchxj%5Fqs%5F"
65 #include "qs_ignore_sp.h"
67 #include "qs_malloc.h"
68 #include "qs_parse_attr.h"
69 #include "qs_parse_file.h"
70 #include "qs_parse_string.h"
71 #include "qs_parse_tag.h"
73 #if defined(HAVE_AP_REGEX_H) && HAVE_AP_REGEX_H == 1
74 # include "ap_regex.h"
76 # include "pcreposix.h"
78 # if !defined(AP_REG_ASSERT)
79 # define AP_REG_ASSERT REG_ASSERT
81 # if !defined(AP_REG_BADBR)
82 # define AP_REG_BADBR REG_BADBR
84 # if !defined(AP_REG_BADPAT)
85 # define AP_REG_BADPAT REG_BADPAT
87 # if !defined(AP_REG_BADRPT)
88 # define AP_REG_BADRPT REG_BADRPT
90 # if !defined(AP_REG_EBRACE)
91 # define AP_REG_EBRACE REG_EBRACE
93 # if !defined(AP_REG_EBRACK)
94 # define AP_REG_EBRACK REG_EBRACK
96 # if !defined(AP_REG_ECOLLATE)
97 # define AP_REG_ECOLLATE REG_ECOLLATE
99 # if !defined(AP_REG_ECTYPE)
100 # define AP_REG_ECTYPE REG_ECTYPE
102 # if !defined(AP_REG_EESCAPE)
103 # define AP_REG_EESCAPE REG_EESCAPE
105 # if !defined(AP_REG_EMPTY)
106 # define AP_REG_EMPTY REG_EMPTY
108 # if !defined(AP_REG_EPAREN)
109 # define AP_REG_EPAREN REG_EPAREN
111 # if !defined(AP_REG_ERANGE)
112 # define AP_REG_ERANGE REG_ERANGE
114 # if !defined(AP_REG_ESIZE)
115 # define AP_REG_ESIZE REG_ESIZE
117 # if !defined(AP_REG_ESPACE)
118 # define AP_REG_ESPACE REG_ESPACE
120 # if !defined(AP_REG_ESUBREG)
121 # define AP_REG_ESUBREG REG_ESUBREG
123 # if !defined(AP_REG_INVARG)
124 # define AP_REG_INVARG REG_INVARG
126 # if !defined(AP_REG_NOMATCH)
127 # define AP_REG_NOMATCH REG_NOMATCH
130 # if !defined(AP_REG_ICASE)
131 # define AP_REG_ICASE REG_ICASE
133 # if !defined(AP_REG_NEWLINE)
134 # define AP_REG_NEWLINE REG_NEWLINE
136 # if !defined(AP_REG_NOTBOL)
137 # define AP_REG_NOTBOL REG_NOTBOL
139 # if !defined(AP_REG_NOTEOL)
140 # define AP_REG_NOTEOL REG_NOTEOL
143 # if !defined(AP_REG_EXTENDED)
144 # define AP_REG_EXTENDED REG_EXTENDED
146 # if !defined(AP_REG_NOSUB)
147 # define AP_REG_NOSUB REG_NOSUB
150 # define ap_regex_t regex_t
151 # define ap_regmatch_t regmatch_t
157 #ifdef HAVE_APR_GLOBAL_MUTEX_H
158 # include "apr_global_mutex.h"
161 #ifdef HAVE_APR_SHM_H
162 # include "apr_shm.h"
166 typedef struct imode_emoji_t imode_emoji_t;
168 struct imode_emoji_t {
175 typedef struct ezweb_emoji_t ezweb_emoji_t;
177 struct ezweb_emoji_t {
184 typedef struct jphone_emoji_t jphone_emoji_t;
186 struct jphone_emoji_t {
190 typedef struct emoji_t emoji_t;
193 struct emoji_t* next;
195 imode_emoji_t* imode;
196 ezweb_emoji_t* ezweb;
197 jphone_emoji_t* jphone;
200 typedef struct chxjconvrule_entry chxjconvrule_entry;
202 struct chxjconvrule_entry {
212 typedef struct tag_handler tag_handler;
215 char* (*start_tag_handler)(void* doc, Node* node);
216 char* (*end_tag_handler)(void* doc, Node* node);
219 #include "chxj_specified_device.h"
223 tag_handler* handler;
280 tagNLMARK, /* New Line Code */
283 typedef struct mod_chxj_config mod_chxj_config;
285 #if defined(USE_MYSQL_COOKIE)
286 # include "chxj_mysql.h"
288 #if defined(USE_MEMCACHE_COOKIE)
289 # include "chxj_memcache.h"
292 /* cookie store type */
293 #define CHXJ_COOKIE_STORE_TYPE_DBM "dbm"
294 #define CHXJ_COOKIE_STORE_TYPE_MYSQL "mysql"
295 #define CHXJ_COOKIE_STORE_TYPE_MEMCACHE "memcache"
297 COOKIE_STORE_TYPE_NONE = 0,
298 COOKIE_STORE_TYPE_DBM = 1,
299 COOKIE_STORE_TYPE_MYSQL = 2,
300 COOKIE_STORE_TYPE_MEMCACHE = 3,
301 } cookie_store_type_t;
304 #define CHXJ_NEW_LINE_TYPE_CRLF "crlf"
305 #define CHXJ_NEW_LINE_TYPE_LF "lf"
306 #define CHXJ_NEW_LINE_TYPE_CR "cr"
307 #define CHXJ_NEW_LINE_TYPE_NONE "none"
314 } chxj_new_line_type_t;
315 #define IS_NLTYPE_CRLF(X) ((X)->new_line_type == NLTYPE_CRLF)
316 #define IS_NLTYPE_LF(X) ((X)->new_line_type == NLTYPE_LF)
317 #define IS_NLTYPE_CR(X) ((X)->new_line_type == NLTYPE_CR)
318 #define IS_NLTYPE_NONE(X) ((X)->new_line_type == NLTYPE_NONE)
319 #define TO_NLCODE(X) (IS_NLTYPE_CRLF(X) ? "\r\n" : \
320 IS_NLTYPE_LF(X) ? "\n" : \
321 IS_NLTYPE_CR(X) ? "\r" : \
322 IS_NLTYPE_NONE(X) ? "" : "\r\n")
324 struct mod_chxj_config {
327 char *device_data_file;
328 char *emoji_data_file;
330 char *image_cache_dir;
331 char *image_copyright;
332 unsigned long image_cache_limit;
333 device_table_list *devices;
336 char *server_side_encoding;
338 char *dir; /* for LOG */
340 apr_array_header_t *convrules;
344 cookie_store_type_t cookie_store_type;
345 int cookie_lazy_mode;
347 #if defined(USE_MYSQL_COOKIE)
350 #if defined(USE_MEMCACHE_COOKIE)
353 char *forward_url_base; /* use input filter */
354 char *forward_server_ip; /* use input filter */
356 chxj_new_line_type_t new_line_type;
359 #define IS_COOKIE_STORE_DBM(X) ((X) == COOKIE_STORE_TYPE_DBM)
360 #define IS_COOKIE_STORE_MYSQL(X) ((X) == COOKIE_STORE_TYPE_MYSQL)
361 #define IS_COOKIE_STORE_MEMCACHE(X) ((X) == COOKIE_STORE_TYPE_MEMCACHE)
362 #define IS_COOKIE_STORE_NONE(X) ((X) == COOKIE_STORE_TYPE_NONE)
364 #define COOKIE_LAZY_ON (2)
365 #define COOKIE_LAZY_OFF (1)
366 #define IS_COOKIE_LAZY(X) ((X)->cookie_lazy_mode == COOKIE_LAZY_ON)
369 #define CONVRULE_ENGINE_ON_BIT (0x00000001)
370 #define CONVRULE_ENGINE_OFF_BIT (0x00000002)
371 #define CONVRULE_COOKIE_ON_BIT (0x00000004)
372 #define CONVRULE_Z2H_ON_BIT (0x00000008)
373 #define CONVRULE_Z2H_OFF_BIT (0x00000010)
374 #define CONVRULE_Z2H_ALPHA_ON_BIT (0x00000020)
375 #define CONVRULE_Z2H_ALPHA_OFF_BIT (0x00000040)
376 #define CONVRULE_Z2H_NUM_ON_BIT (0x00000080)
377 #define CONVRULE_Z2H_NUM_OFF_BIT (0x00000100)
378 #define CONVRULE_QSCONV_OFF_BIT (0x00000200)
379 #define CONVRULE_JRCONV_OFF_BIT (0x00000400)
380 #define CONVRULE_NOCACHE_ON_BIT (0x00000800)
382 #define CONVRULE_ENGINE_ON_CMD "EngineOn"
383 #define CONVRULE_ENGINE_OFF_CMD "EngineOff"
384 #define CONVRULE_COOKIE_ON_CMD "CookieOn"
385 #define CONVRULE_COOKIE_OFF_CMD "CookieOff"
386 #define CONVRULE_Z2H_ON_CMD "Z2hOn"
387 #define CONVRULE_Z2H_OFF_CMD "Z2hOff"
388 #define CONVRULE_Z2H_ALPHA_ON_CMD "Z2hAlphaOn"
389 #define CONVRULE_Z2H_ALPHA_OFF_CMD "Z2hAlphaOff"
390 #define CONVRULE_Z2H_NUM_ON_CMD "Z2hNumOn"
391 #define CONVRULE_Z2H_NUM_OFF_CMD "Z2hNumOff"
392 #define CONVRULE_Z2H_ALL_ON_CMD "Z2hAllOn"
393 #define CONVRULE_Z2H_ALL_OFF_CMD "Z2hAllOff"
394 #define CONVRULE_QSCONV_OFF_CMD "QSConvOff"
395 #define CONVRULE_JRCONV_OFF_CMD "JRConvOff"
396 #define CONVRULE_NOCACHE_ON_CMD "NoCacheOn"
399 #define CONVRULE_FLAG_NOTMATCH (0x00000001)
401 #define CONVRULE_PC_FLAG_ON_CMD "PC"
403 #define CONVRULE_PC_FLAG_ON_BIT (0x00000001)
404 #define CONVRULE_PC_FLAG_OFF_BIT (0x00000002)
408 apr_global_mutex_t* cookie_db_lock;
409 } mod_chxj_global_config;
413 chxjconvrule_entry *entryp;
416 apr_bucket_brigade *bb;
422 #include "chxj_tag_util.h"
424 #define CHXJ_MOD_CONFIG_KEY "chxj_module_key"
426 #define HTTP_USER_AGENT "User-Agent"
427 #define HTTP_HOST "Host"
428 #define CHXJ_HTTP_USER_AGENT "CHXJ_HTTP_USER_AGENT"
429 #define CHXJ_HEADER_ORIG_CLIENT_IP "X-Chxj-Orig-Client-Ip"
431 module AP_MODULE_DECLARE_DATA chxj_module;
433 #define CHXJ_IMG_ON (2)
434 #define CHXJ_IMG_OFF (1)
435 #define CHXJ_IMG_NONE (0)
438 #define DBG(X,args...) chxj_log_rerror(APLOG_MARK,APLOG_DEBUG,0,(request_rec*)(X),##args)
439 #define SDBG(X,Y) chxj_log_error(APLOG_MARK,APLOG_DEBUG,0,(X),(Y))
440 #define PDBG(X,args...) chxj_log_perror(APLOG_MARK,APLOG_DEBUG,0,(apr_pool_t *)(X),##args)
441 #define ERR(X,args...) chxj_log_rerror(APLOG_MARK,APLOG_ERR,0,(X), ##args)
442 #define SERR(X,args...) chxj_log_error(APLOG_MARK,APLOG_ERR,0,(X),##args)
443 #define PERR(X,args...) chxj_log_perror(APLOG_MARK,APLOG_ERR,0,(apr_pool_t *)(X),##args)
444 #define WRN(rec,format,args...) chxj_log_rerror(APLOG_MARK,APLOG_WARNING,0,(rec),(format), ##args)
446 extern tag_handlers chxj_tag_handlers[];
447 extern tag_handler chtml10_handler[];
448 extern tag_handler chtml20_handler[];
449 extern tag_handler chtml30_handler[];
450 extern tag_handler chtml40_handler[];
451 extern tag_handler chtml50_handler[];
452 extern tag_handler xhtml_handler[];
453 extern tag_handler hdml_handler[];
454 extern tag_handler jhtml_handler[];
455 extern tag_handler jxhtml_handler[];
457 extern char* chxj_node_convert(
466 #define IMAGE_CACHE_LIMIT_FMT_LEN (20)
470 extern void *rpl_malloc(size_t n);