OSDN Git Service

* merge from RELEASE_0_8_0
[modchxj/mod_chxj.git] / include / mod_chxj.h
1 /*
2  * Copyright (C) 2005 QSDN,Inc. All rights reserved.
3  * Copyright (C) 2005 Atsushi Konno 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 #ifndef __MOD_CHXJ_H__
18 #define __MOD_CHXJ_H__
19
20 #if !defined(OS2) && !defined(WIN32) && !defined(BEOS) && !defined(NETWARE)
21 #  define AP_NEED_SET_MUTEX_PERMS
22 #endif
23
24
25 #include <string.h>
26
27 #include "httpd.h"
28 #include "http_config.h"
29 #include "http_protocol.h"
30 #include "http_request.h"
31 #include "http_log.h"
32 #include "ap_config.h"
33 #include "apr_strings.h"
34 #include "apr_buckets.h"
35 #include "apr_lib.h"
36 #include "apr_tables.h"
37 #include "apr_dso.h"
38 #include "apr_general.h"
39 #include "apr_pools.h"
40 #include "util_filter.h"
41
42 #if defined(AP_NEED_SET_MUTEX_PERMS)
43 #  include "unixd.h"
44 #endif
45
46 #include "qs_ignore_sp.h"
47 #include "qs_log.h"
48 #include "qs_malloc.h"
49 #include "qs_parse_attr.h"
50 #include "qs_parse_file.h"
51 #include "qs_parse_string.h"
52 #include "qs_parse_tag.h"
53
54 #ifndef __CONFIG_H__
55 #define __CONFIG_H__
56
57 #undef PACKAGE_NAME
58 #undef PACKAGE_STRING
59 #undef PACKAGE_TARNAME
60 #undef PACKAGE_VERSION
61
62 #include "config.h"
63 #endif
64 #ifdef HAVE_AP_REGEX_H
65 #  include "ap_regex.h"
66 #else
67 #  include "pcreposix.h"
68 #  include "pcre.h"
69 #  if !defined(AP_REG_ASSERT)
70 #    define AP_REG_ASSERT   REG_ASSERT
71 #  endif
72 #  if !defined(AP_REG_BADBR)
73 #    define AP_REG_BADBR    REG_BADBR
74 #  endif
75 #  if !defined(AP_REG_BADPAT)
76 #    define AP_REG_BADPAT   REG_BADPAT
77 #  endif
78 #  if !defined(AP_REG_BADRPT)
79 #    define AP_REG_BADRPT   REG_BADRPT
80 #  endif
81 #  if !defined(AP_REG_EBRACE)
82 #    define AP_REG_EBRACE   REG_EBRACE
83 #  endif
84 #  if !defined(AP_REG_EBRACK)
85 #    define AP_REG_EBRACK   REG_EBRACK
86 #  endif
87 #  if !defined(AP_REG_ECOLLATE)
88 #    define AP_REG_ECOLLATE REG_ECOLLATE
89 #  endif
90 #  if !defined(AP_REG_ECTYPE)
91 #    define AP_REG_ECTYPE   REG_ECTYPE
92 #  endif
93 #  if !defined(AP_REG_EESCAPE)
94 #    define AP_REG_EESCAPE  REG_EESCAPE
95 #  endif
96 #  if !defined(AP_REG_EMPTY)
97 #    define AP_REG_EMPTY    REG_EMPTY
98 #  endif
99 #  if !defined(AP_REG_EPAREN)
100 #    define AP_REG_EPAREN   REG_EPAREN
101 #  endif
102 #  if !defined(AP_REG_ERANGE)
103 #    define AP_REG_ERANGE   REG_ERANGE
104 #  endif
105 #  if !defined(AP_REG_ESIZE)
106 #    define AP_REG_ESIZE    REG_ESIZE
107 #  endif
108 #  if !defined(AP_REG_ESPACE)
109 #    define AP_REG_ESPACE   REG_ESPACE
110 #  endif
111 #  if !defined(AP_REG_ESUBREG)
112 #    define AP_REG_ESUBREG  REG_ESUBREG
113 #  endif
114 #  if !defined(AP_REG_INVARG)
115 #    define AP_REG_INVARG   REG_INVARG
116 #  endif
117 #  if !defined(AP_REG_NOMATCH)
118 #    define AP_REG_NOMATCH  REG_NOMATCH
119 #  endif
120
121 #  if !defined(AP_REG_ICASE)
122 #    define AP_REG_ICASE    REG_ICASE
123 #  endif
124 #  if !defined(AP_REG_NEWLINE)
125 #    define AP_REG_NEWLINE  REG_NEWLINE
126 #  endif
127 #  if !defined(AP_REG_NOTBOL)
128 #    define AP_REG_NOTBOL   REG_NOTBOL
129 #  endif
130 #  if !defined(AP_REG_NOTEOL)
131 #    define AP_REG_NOTEOL   REG_NOTEOL
132 #  endif
133
134 #  if !defined(AP_REG_EXTENDED)
135 #    define AP_REG_EXTENDED REG_EXTENDED
136 #  endif
137 #  if !defined(AP_REG_NOSUB)
138 #    define AP_REG_NOSUB    REG_NOSUB
139 #  endif
140
141 #  define ap_regex_t      regex_t
142 #  define ap_regmatch_t   regmatch_t
143 #endif
144
145
146
147
148 #ifdef HAVE_APR_GLOBAL_MUTEX_H
149 #  include "apr_global_mutex.h"
150 #endif
151
152 #ifdef HAVE_APR_SHM_H
153 #  include "apr_shm.h"
154 #endif
155
156
157 typedef struct imode_emoji_t imode_emoji_t;
158
159 struct imode_emoji_t {
160   char  hex1byte;
161   char  hex2byte;
162   char* string;
163   char *description;
164 };
165
166 typedef struct ezweb_emoji_t ezweb_emoji_t;
167
168 struct ezweb_emoji_t {
169   char* typeA;
170   char* typeB;
171   char* typeC;
172   char* typeD;
173 };
174
175 typedef struct jphone_emoji_t jphone_emoji_t;
176
177 struct jphone_emoji_t {
178   char* string;
179 };
180
181 typedef struct emoji_t emoji_t;
182
183 struct emoji_t {
184   struct emoji_t*  next;
185   int              no;
186   imode_emoji_t*   imode;
187   ezweb_emoji_t*   ezweb;
188   jphone_emoji_t*  jphone;
189 };
190
191 typedef struct chxjconvrule_entry chxjconvrule_entry;
192
193 struct chxjconvrule_entry {
194   char       *pattern;
195   ap_regex_t *regexp;
196   int        flags;
197   int        action;
198   char       *encoding;
199   int        pc_flag;
200   char       *user_agent;
201 };
202
203 typedef struct tag_handler tag_handler;
204
205 struct tag_handler {
206   char* (*start_tag_handler)(void* doc, Node* node); 
207   char* (*end_tag_handler)(void* doc, Node* node); 
208 };
209
210 #include "chxj_specified_device.h"
211
212 typedef struct {
213   spec_type    type; 
214   tag_handler* handler;
215 } tag_handlers;
216
217 typedef enum {
218   tagHTML = 0,
219   tagMETA,  
220   tagTEXTAREA,
221   tagP,
222   tagPRE,
223   tagUL,
224   tagLI,
225   tagOL,
226   tagH1,
227   tagH2,
228   tagH3,
229   tagH4,
230   tagH5,
231   tagH6,
232   tagHEAD,
233   tagTITLE,
234   tagBASE,
235   tagBODY,
236   tagA,
237   tagBR,
238   tagTABLE,
239   tagTR,
240   tagTD,
241   tagTBODY,
242   tagFONT,
243   tagFORM,
244   tagINPUT,
245   tagCENTER,
246   tagHR,
247   tagIMG,
248   tagSELECT,
249   tagOPTION,
250   tagDIV,
251   tagCHXJIF,  
252   tagNOBR,  
253   tagSMALL,  
254   tagSTYLE,  
255   tagSPAN,  
256   tagTEXT,  
257   tagTH,  
258   tagB,
259   tagFIELDSET,
260   tagDT,
261   tagLEGEND,
262   tagLABEL,
263 } tag_type;
264
265 typedef struct mod_chxj_config mod_chxj_config;
266
267 struct mod_chxj_config {
268   int                   image;
269
270   char*                 device_data_file;
271   char*                 emoji_data_file;
272
273   char*                 image_cache_dir;
274   char*                 image_copyright;
275   device_table_list*    devices;
276   emoji_t*              emoji;
277   emoji_t*              emoji_tail;
278   char*                 server_side_encoding;
279
280   char*                 dir; /* for LOG */
281
282   apr_array_header_t   *convrules;
283
284   char*                 cookie_db_dir;
285   long                  cookie_timeout;
286 };
287
288
289 #define CONVRULE_ENGINE_ON_BIT        (0x00000001)
290 #define CONVRULE_ENGINE_OFF_BIT       (0x00000002)
291 #define CONVRULE_COOKIE_ON_BIT        (0x00000004)
292
293 #define CONVRULE_ENGINE_ON_CMD        "EngineOn"
294 #define CONVRULE_ENGINE_OFF_CMD       "EngineOff"
295 #define CONVRULE_COOKIE_ON_CMD        "CookieOn"
296 #define CONVRULE_COOKIE_OFF_CMD       "CookieOff"
297
298
299 #define CONVRULE_FLAG_NOTMATCH        (0x00000001)
300
301 #define CONVRULE_PC_FLAG_ON_CMD       "PC"
302
303 #define CONVRULE_PC_FLAG_ON_BIT       (0x00000001)
304 #define CONVRULE_PC_FLAG_OFF_BIT      (0x00000002)
305
306 typedef struct {
307   apr_global_mutex_t* cookie_db_lock;
308 } mod_chxj_global_config;
309
310 typedef struct {
311   unsigned int len;
312
313   apr_bucket_brigade *bb;
314
315   char* buffer;
316 } mod_chxj_ctx;
317
318 #include "chxj_tag_util.h"
319
320 #define CHXJ_MOD_CONFIG_KEY   "chxj_module_key"
321
322 #define HTTP_USER_AGENT       "User-Agent"
323 #define CHXJ_HTTP_USER_AGENT  "CHXJ_HTTP_USER_AGENT"
324
325 module AP_MODULE_DECLARE_DATA chxj_module;
326
327 #define CHXJ_IMG_ON     (1)
328 #define CHXJ_IMG_OFF    (0)
329
330
331 #define DBG(X,Y)  ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0,(request_rec*)(X),(Y))
332 #define DBG1(X,Y,Za)  ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0,(X),(Y),(Za))
333 #define DBG2(X,Y,Za,Zb)  ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0,(X),(Y),(Za),(Zb))
334 #define DBG3(X,Y,Za,Zb,Zc)  ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0,(X),(Y),(Za),(Zb),(Zc))
335 #define DBG4(X,Y,Za,Zb,Zc,Zd)  ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0,(X),(Y),(Za),(Zb),(Zc),(Zd))
336 #define DBG5(X,Y,Za,Zb,Zc,Zd,Ze)  ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0,(X),(Y),(Za),(Zb),(Zc),(Zd),(Ze))
337 #define SDBG(X,Y)  ap_log_error(APLOG_MARK,APLOG_DEBUG,0,(X),(Y))
338 #define SDBG1(X,Y,Za)  ap_log_error(APLOG_MARK,APLOG_DEBUG,0,(X),(Y),(Za))
339 #define SDBG2(X,Y,Za,Zb)  ap_log_error(APLOG_MARK,APLOG_DEBUG,0,(X),(Y),(Za),(Zb))
340 #define SDBG3(X,Y,Za,Zb,Zc)  ap_log_error(APLOG_MARK,APLOG_DEBUG,0,(X),(Y),(Za),(Zb),(Zc))
341 #define SDBG4(X,Y,Za,Zb,Zc,Zd)  ap_log_error(APLOG_MARK,APLOG_DEBUG,0,(X),(Y),(Za),(Zb),(Zc),(Zd))
342 #define SDBG5(X,Y,Za,Zb,Zc,Zd,Ze)  ap_log_error(APLOG_MARK,APLOG_DEBUG,0,(X),(Y),(Za),(Zb),(Zc),(Zd),(Ze))
343 #define ERR(X,Y)  ap_log_rerror(APLOG_MARK,APLOG_ERR,0,(X),(Y))
344 #define ERR1(X,Y,Za)  ap_log_rerror(APLOG_MARK,APLOG_ERR,0,(X),(Y),(Za))
345 #define ERR2(X,Y,Za,Zb)  ap_log_rerror(APLOG_MARK,APLOG_ERR,0,(X),(Y),(Za),(Zb))
346 #define SERR(X,Y)  ap_log_error(APLOG_MARK,APLOG_ERR,0,(X),(Y))
347 #define SERR1(X,Y,Za)  ap_log_error(APLOG_MARK,APLOG_ERR,0,(X),(Y),(Za))
348 #define SERR2(X,Y,Za,Zb)  ap_log_error(APLOG_MARK,APLOG_ERR,0,(X),(Y),(Za),(Zb))
349
350 extern tag_handlers chxj_tag_handlers[];
351 extern tag_handler  chtml10_handler[];
352 extern tag_handler  chtml20_handler[];
353 extern tag_handler  chtml30_handler[];
354 extern tag_handler  xhtml_handler[];
355 extern tag_handler  hdml_handler[];
356 extern tag_handler  jhtml_handler[];
357
358 extern char* chxj_node_exchange( 
359   device_table* spec,
360   request_rec*  r,
361   void*         pdoc,
362   Doc*          doc,
363   Node*         node,
364   int           indent
365 );
366
367
368
369 #endif
370 /*
371  * vim:ts=2 et
372  */