2 * Copyright (C) 2005-2008 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 #include "qs_ignore_sp.h"
63 #include "qs_malloc.h"
64 #include "qs_parse_attr.h"
65 #include "qs_parse_file.h"
66 #include "qs_parse_string.h"
67 #include "qs_parse_tag.h"
69 #if defined(HAVE_AP_REGEX_H) && HAVE_AP_REGEX_H == 1
70 # include "ap_regex.h"
72 # include "pcreposix.h"
74 # if !defined(AP_REG_ASSERT)
75 # define AP_REG_ASSERT REG_ASSERT
77 # if !defined(AP_REG_BADBR)
78 # define AP_REG_BADBR REG_BADBR
80 # if !defined(AP_REG_BADPAT)
81 # define AP_REG_BADPAT REG_BADPAT
83 # if !defined(AP_REG_BADRPT)
84 # define AP_REG_BADRPT REG_BADRPT
86 # if !defined(AP_REG_EBRACE)
87 # define AP_REG_EBRACE REG_EBRACE
89 # if !defined(AP_REG_EBRACK)
90 # define AP_REG_EBRACK REG_EBRACK
92 # if !defined(AP_REG_ECOLLATE)
93 # define AP_REG_ECOLLATE REG_ECOLLATE
95 # if !defined(AP_REG_ECTYPE)
96 # define AP_REG_ECTYPE REG_ECTYPE
98 # if !defined(AP_REG_EESCAPE)
99 # define AP_REG_EESCAPE REG_EESCAPE
101 # if !defined(AP_REG_EMPTY)
102 # define AP_REG_EMPTY REG_EMPTY
104 # if !defined(AP_REG_EPAREN)
105 # define AP_REG_EPAREN REG_EPAREN
107 # if !defined(AP_REG_ERANGE)
108 # define AP_REG_ERANGE REG_ERANGE
110 # if !defined(AP_REG_ESIZE)
111 # define AP_REG_ESIZE REG_ESIZE
113 # if !defined(AP_REG_ESPACE)
114 # define AP_REG_ESPACE REG_ESPACE
116 # if !defined(AP_REG_ESUBREG)
117 # define AP_REG_ESUBREG REG_ESUBREG
119 # if !defined(AP_REG_INVARG)
120 # define AP_REG_INVARG REG_INVARG
122 # if !defined(AP_REG_NOMATCH)
123 # define AP_REG_NOMATCH REG_NOMATCH
126 # if !defined(AP_REG_ICASE)
127 # define AP_REG_ICASE REG_ICASE
129 # if !defined(AP_REG_NEWLINE)
130 # define AP_REG_NEWLINE REG_NEWLINE
132 # if !defined(AP_REG_NOTBOL)
133 # define AP_REG_NOTBOL REG_NOTBOL
135 # if !defined(AP_REG_NOTEOL)
136 # define AP_REG_NOTEOL REG_NOTEOL
139 # if !defined(AP_REG_EXTENDED)
140 # define AP_REG_EXTENDED REG_EXTENDED
142 # if !defined(AP_REG_NOSUB)
143 # define AP_REG_NOSUB REG_NOSUB
146 # define ap_regex_t regex_t
147 # define ap_regmatch_t regmatch_t
153 #ifdef HAVE_APR_GLOBAL_MUTEX_H
154 # include "apr_global_mutex.h"
157 #ifdef HAVE_APR_SHM_H
158 # include "apr_shm.h"
162 typedef struct imode_emoji_t imode_emoji_t;
164 struct imode_emoji_t {
171 typedef struct ezweb_emoji_t ezweb_emoji_t;
173 struct ezweb_emoji_t {
180 typedef struct jphone_emoji_t jphone_emoji_t;
182 struct jphone_emoji_t {
186 typedef struct emoji_t emoji_t;
189 struct emoji_t* next;
191 imode_emoji_t* imode;
192 ezweb_emoji_t* ezweb;
193 jphone_emoji_t* jphone;
196 typedef struct chxjconvrule_entry chxjconvrule_entry;
198 struct chxjconvrule_entry {
208 typedef struct tag_handler tag_handler;
211 char* (*start_tag_handler)(void* doc, Node* node);
212 char* (*end_tag_handler)(void* doc, Node* node);
215 #include "chxj_specified_device.h"
219 tag_handler* handler;
276 tagNLMARK, /* New Line Code */
279 typedef struct mod_chxj_config mod_chxj_config;
281 #if defined(USE_MYSQL_COOKIE)
282 # include "chxj_mysql.h"
284 #if defined(USE_MEMCACHE_COOKIE)
285 # include "chxj_memcache.h"
288 /* cookie store type */
289 #define CHXJ_COOKIE_STORE_TYPE_DBM "dbm"
290 #define CHXJ_COOKIE_STORE_TYPE_MYSQL "mysql"
291 #define CHXJ_COOKIE_STORE_TYPE_MEMCACHE "memcache"
293 COOKIE_STORE_TYPE_NONE = 0,
294 COOKIE_STORE_TYPE_DBM = 1,
295 COOKIE_STORE_TYPE_MYSQL = 2,
296 COOKIE_STORE_TYPE_MEMCACHE = 3,
297 } cookie_store_type_t;
300 #define CHXJ_NEW_LINE_TYPE_CRLF "crlf"
301 #define CHXJ_NEW_LINE_TYPE_LF "lf"
302 #define CHXJ_NEW_LINE_TYPE_CR "cr"
303 #define CHXJ_NEW_LINE_TYPE_NONE "none"
310 } chxj_new_line_type_t;
311 #define IS_NLTYPE_CRLF(X) ((X)->new_line_type == NLTYPE_CRLF)
312 #define IS_NLTYPE_LF(X) ((X)->new_line_type == NLTYPE_LF)
313 #define IS_NLTYPE_CR(X) ((X)->new_line_type == NLTYPE_CR)
314 #define IS_NLTYPE_NONE(X) ((X)->new_line_type == NLTYPE_NONE)
315 #define TO_NLCODE(X) (IS_NLTYPE_CRLF(X) ? "\r\n" : \
316 IS_NLTYPE_LF(X) ? "\n" : \
317 IS_NLTYPE_CR(X) ? "\r" : \
318 IS_NLTYPE_NONE(X) ? "" : "\r\n")
320 struct mod_chxj_config {
323 char *device_data_file;
324 char *emoji_data_file;
326 char *image_cache_dir;
327 char *image_copyright;
328 unsigned long image_cache_limit;
329 device_table_list *devices;
332 char *server_side_encoding;
334 char *dir; /* for LOG */
336 apr_array_header_t *convrules;
340 cookie_store_type_t cookie_store_type;
341 int cookie_lazy_mode;
343 #if defined(USE_MYSQL_COOKIE)
346 #if defined(USE_MEMCACHE_COOKIE)
349 char *forward_url_base; /* use input filter */
350 char *forward_server_ip; /* use input filter */
352 chxj_new_line_type_t new_line_type;
355 #define IS_COOKIE_STORE_DBM(X) ((X) == COOKIE_STORE_TYPE_DBM)
356 #define IS_COOKIE_STORE_MYSQL(X) ((X) == COOKIE_STORE_TYPE_MYSQL)
357 #define IS_COOKIE_STORE_MEMCACHE(X) ((X) == COOKIE_STORE_TYPE_MEMCACHE)
358 #define IS_COOKIE_STORE_NONE(X) ((X) == COOKIE_STORE_TYPE_NONE)
360 #define COOKIE_LAZY_ON (2)
361 #define COOKIE_LAZY_OFF (1)
362 #define IS_COOKIE_LAZY(X) ((X)->cookie_lazy_mode == COOKIE_LAZY_ON)
365 #define CONVRULE_ENGINE_ON_BIT (0x00000001)
366 #define CONVRULE_ENGINE_OFF_BIT (0x00000002)
367 #define CONVRULE_COOKIE_ON_BIT (0x00000004)
369 #define CONVRULE_ENGINE_ON_CMD "EngineOn"
370 #define CONVRULE_ENGINE_OFF_CMD "EngineOff"
371 #define CONVRULE_COOKIE_ON_CMD "CookieOn"
372 #define CONVRULE_COOKIE_OFF_CMD "CookieOff"
375 #define CONVRULE_FLAG_NOTMATCH (0x00000001)
377 #define CONVRULE_PC_FLAG_ON_CMD "PC"
379 #define CONVRULE_PC_FLAG_ON_BIT (0x00000001)
380 #define CONVRULE_PC_FLAG_OFF_BIT (0x00000002)
384 apr_global_mutex_t* cookie_db_lock;
385 } mod_chxj_global_config;
389 chxjconvrule_entry *entryp;
392 apr_bucket_brigade *bb;
398 #include "chxj_tag_util.h"
400 #define CHXJ_MOD_CONFIG_KEY "chxj_module_key"
402 #define HTTP_USER_AGENT "User-Agent"
403 #define HTTP_HOST "Host"
404 #define CHXJ_HTTP_USER_AGENT "CHXJ_HTTP_USER_AGENT"
405 #define CHXJ_HEADER_ORIG_CLIENT_IP "X-Chxj-Orig-Client-Ip"
407 module AP_MODULE_DECLARE_DATA chxj_module;
409 #define CHXJ_IMG_ON (2)
410 #define CHXJ_IMG_OFF (1)
411 #define CHXJ_IMG_NONE (0)
414 #define DBG(X,args...) chxj_log_rerror(APLOG_MARK,APLOG_DEBUG,0,(request_rec*)(X),##args)
415 #define SDBG(X,Y) chxj_log_error(APLOG_MARK,APLOG_DEBUG,0,(X),(Y))
416 #define PDBG(X,args...) chxj_log_perror(APLOG_MARK,APLOG_DEBUG,0,(apr_pool_t *)(X),##args)
417 #define ERR(X,args...) chxj_log_rerror(APLOG_MARK,APLOG_ERR,0,(X), ##args)
418 #define SERR(X,args...) chxj_log_error(APLOG_MARK,APLOG_ERR,0,(X),##args)
419 #define PERR(X,args...) chxj_log_perror(APLOG_MARK,APLOG_ERR,0,(apr_pool_t *)(X),##args)
420 #define WRN(rec,format,args...) chxj_log_rerror(APLOG_MARK,APLOG_WARNING,0,(rec),(format), ##args)
422 extern tag_handlers chxj_tag_handlers[];
423 extern tag_handler chtml10_handler[];
424 extern tag_handler chtml20_handler[];
425 extern tag_handler chtml30_handler[];
426 extern tag_handler chtml40_handler[];
427 extern tag_handler chtml50_handler[];
428 extern tag_handler xhtml_handler[];
429 extern tag_handler hdml_handler[];
430 extern tag_handler jhtml_handler[];
431 extern tag_handler jxhtml_handler[];
433 extern char* chxj_node_convert(
442 #define IMAGE_CACHE_LIMIT_FMT_LEN (20)
446 extern void *rpl_malloc(size_t n);