OSDN Git Service

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