OSDN Git Service

* updated copyright.
[modchxj/mod_chxj.git] / src / chxj_xhtml_mobile_1_0.c
1 /*
2  * Copyright (C) 2005-2011 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 "mod_chxj.h"
18 #include "chxj_encoding.h"
19 #include "chxj_xhtml_mobile_1_0.h"
20 #include "chxj_hdml.h"
21 #include "chxj_dump.h"
22 #include "chxj_img_conv.h"
23 #include "chxj_qr_code.h"
24 #include "chxj_buffered_write.h"
25 #include "chxj_str_util.h"
26 #include "chxj_header_inf.h"
27 #include "chxj_conv_z2h.h"
28
29 #define GET_XHTML(X) ((xhtml_t*)(X))
30 #undef W_L
31 #undef W_V
32 #define W_L(X)          do { xhtml->out = BUFFERED_WRITE_LITERAL(xhtml->out, &doc->buf, (X)); } while(0)
33 #define W_V(X)          do { xhtml->out = (X) ? BUFFERED_WRITE_VALUE(xhtml->out, &doc->buf, (X))  \
34                                                : BUFFERED_WRITE_LITERAL(xhtml->out, &doc->buf, ""); } while(0)
35 #undef W_NLCODE
36 #define W_NLCODE()     do { char *nlcode = TO_NLCODE(xhtml->conf); W_V(nlcode); } while (0)
37
38 static char *s_xhtml_1_0_start_html_tag   (void *pdoc, Node *node);
39 static char *s_xhtml_1_0_end_html_tag     (void *pdoc, Node *node);
40 static char *s_xhtml_1_0_start_p_tag      (void *pdoc, Node *node);
41 static char *s_xhtml_1_0_end_p_tag        (void *pdoc, Node *node);
42 static char *s_xhtml_1_0_start_pre_tag    (void *pdoc, Node *node);
43 static char *s_xhtml_1_0_end_pre_tag      (void *pdoc, Node *node);
44 static char *s_xhtml_1_0_start_ul_tag     (void *pdoc, Node *node);
45 static char *s_xhtml_1_0_end_ul_tag       (void *pdoc, Node *node);
46 static char *s_xhtml_1_0_start_h1_tag     (void *pdoc, Node *node);
47 static char *s_xhtml_1_0_end_h1_tag       (void *pdoc, Node *node);
48 static char *s_xhtml_1_0_start_h2_tag     (void *pdoc, Node *node);
49 static char *s_xhtml_1_0_end_h2_tag       (void *pdoc, Node *node);
50 static char *s_xhtml_1_0_start_h3_tag     (void *pdoc, Node *node);
51 static char *s_xhtml_1_0_end_h3_tag       (void *pdoc, Node *node);
52 static char *s_xhtml_1_0_start_h4_tag     (void *pdoc, Node *node);
53 static char *s_xhtml_1_0_end_h4_tag       (void *pdoc, Node *node);
54 static char *s_xhtml_1_0_start_h5_tag     (void *pdoc, Node *node);
55 static char *s_xhtml_1_0_end_h5_tag       (void *pdoc, Node *node);
56 static char *s_xhtml_1_0_start_h6_tag     (void *pdoc, Node *node);
57 static char *s_xhtml_1_0_end_h6_tag       (void *pdoc, Node *node);
58 static char *s_xhtml_1_0_start_ol_tag     (void *pdoc, Node *node);
59 static char *s_xhtml_1_0_end_ol_tag       (void *pdoc, Node *node);
60 static char *s_xhtml_1_0_start_li_tag     (void *pdoc, Node *node);
61 static char *s_xhtml_1_0_end_li_tag       (void *pdoc, Node *node);
62 static char *s_xhtml_1_0_start_meta_tag   (void *pdoc, Node *node);
63 static char *s_xhtml_1_0_end_meta_tag     (void *pdoc, Node *node);
64 static char *s_xhtml_1_0_start_head_tag   (void *pdoc, Node *node);
65 static char *s_xhtml_1_0_end_head_tag     (void *pdoc, Node *node);
66 static char *s_xhtml_1_0_start_title_tag  (void *pdoc, Node *node);
67 static char *s_xhtml_1_0_end_title_tag    (void *pdoc, Node *node);
68 static char *s_xhtml_1_0_start_base_tag   (void *pdoc, Node *node);
69 static char *s_xhtml_1_0_end_base_tag     (void *pdoc, Node *node);
70 static char *s_xhtml_1_0_start_body_tag   (void *pdoc, Node *node);
71 static char *s_xhtml_1_0_end_body_tag     (void *pdoc, Node *node);
72 static char *s_xhtml_1_0_start_a_tag      (void *pdoc, Node *node);
73 static char *s_xhtml_1_0_end_a_tag        (void *pdoc, Node *node);
74 static char *s_xhtml_1_0_start_br_tag     (void *pdoc, Node *node);
75 static char *s_xhtml_1_0_end_br_tag       (void *pdoc, Node *node);
76 static char *s_xhtml_1_0_start_tr_tag     (void *pdoc, Node *node);
77 static char *s_xhtml_1_0_end_tr_tag       (void *pdoc, Node *node);
78 static char *s_xhtml_1_0_start_font_tag   (void *pdoc, Node *node);
79 static char *s_xhtml_1_0_end_font_tag     (void *pdoc, Node *node);
80 static char *s_xhtml_1_0_start_form_tag   (void *pdoc, Node *node);
81 static char *s_xhtml_1_0_end_form_tag     (void *pdoc, Node *node);
82 static char *s_xhtml_1_0_start_input_tag  (void *pdoc, Node *node);
83 static char *s_xhtml_1_0_end_input_tag    (void *pdoc, Node *node);
84 static char *s_xhtml_1_0_start_center_tag (void *pdoc, Node *node);
85 static char *s_xhtml_1_0_end_center_tag   (void *pdoc, Node *node);
86 static char *s_xhtml_1_0_start_hr_tag     (void *pdoc, Node *node);
87 static char *s_xhtml_1_0_end_hr_tag       (void *pdoc, Node *node);
88 static char *s_xhtml_1_0_start_img_tag    (void *pdoc, Node *node);
89 static char *s_xhtml_1_0_end_img_tag      (void *pdoc, Node *node);
90 static char *s_xhtml_1_0_start_select_tag (void *pdoc, Node *node);
91 static char *s_xhtml_1_0_end_select_tag   (void *pdoc, Node *node);
92 static char *s_xhtml_1_0_start_option_tag (void *pdoc, Node *node);
93 static char *s_xhtml_1_0_end_option_tag   (void *pdoc, Node *node);
94 static char *s_xhtml_1_0_start_div_tag       (void *pdoc, Node *node);
95 static char *s_xhtml_1_0_end_div_tag         (void *pdoc, Node *node);
96 static char *s_xhtml_1_0_start_textarea_tag  (void *pdoc, Node *node);
97 static char *s_xhtml_1_0_end_textarea_tag    (void *pdoc, Node *node);
98 static char *s_xhtml_1_0_start_b_tag         (void *pdoc, Node *node);
99 static char *s_xhtml_1_0_end_b_tag           (void *pdoc, Node *node);
100 static char *s_xhtml_1_0_chxjif_tag          (void *pdoc, Node *node);
101 static char *s_xhtml_1_0_start_blockquote_tag(void *pdoc, Node *node);
102 static char *s_xhtml_1_0_end_blockquote_tag  (void *pdoc, Node *node);
103 static char *s_xhtml_1_0_start_dir_tag       (void *pdoc, Node *node);
104 static char *s_xhtml_1_0_end_dir_tag         (void *pdoc, Node *node);
105 static char *s_xhtml_1_0_start_dl_tag        (void *pdoc, Node *node);
106 static char *s_xhtml_1_0_end_dl_tag          (void *pdoc, Node *node);
107 static char *s_xhtml_1_0_start_dt_tag        (void *pdoc, Node *node);
108 static char *s_xhtml_1_0_end_dt_tag          (void *pdoc, Node *node);
109 static char *s_xhtml_1_0_start_dd_tag        (void *pdoc, Node *node);
110 static char *s_xhtml_1_0_end_dd_tag          (void *pdoc, Node *node);
111 static char *s_xhtml_1_0_start_menu_tag      (void *pdoc, Node *node);
112 static char *s_xhtml_1_0_end_menu_tag        (void *pdoc, Node *node);
113 static char *s_xhtml_1_0_start_plaintext_tag       (void *pdoc, Node *node);
114 static char *s_xhtml_1_0_start_plaintext_tag_inner (void *pdoc, Node *node);
115 static char *s_xhtml_1_0_end_plaintext_tag         (void *pdoc, Node *node);
116 static char *s_xhtml_1_0_start_blink_tag     (void *pdoc, Node *node);
117 static char *s_xhtml_1_0_end_blink_tag       (void *pdoc, Node *node);
118 static char *s_xhtml_1_0_start_marquee_tag   (void *pdoc, Node *node);
119 static char *s_xhtml_1_0_end_marquee_tag     (void *pdoc, Node *node);
120 static char *s_xhtml_1_0_newline_mark       (void *pdoc, Node *node);
121
122 static void  s_init_xhtml(xhtml_t *xhtml, Doc *doc, request_rec *r, device_table *spec);
123 static int   s_xhtml_search_emoji(xhtml_t *xhtml, char *txt, char **rslt);
124 static char *s_xhtml_1_0_text_tag(void *pdoc, Node *child);
125
126
127 tag_handler xhtml_handler[] = {
128   /* tagHTML */
129   {
130     s_xhtml_1_0_start_html_tag,
131     s_xhtml_1_0_end_html_tag,
132   },
133   /* tagMETA */
134   {
135     s_xhtml_1_0_start_meta_tag,
136     s_xhtml_1_0_end_meta_tag,
137   },
138   /* tagTEXTAREA */
139   {
140     s_xhtml_1_0_start_textarea_tag,
141     s_xhtml_1_0_end_textarea_tag,
142   },
143   /* tagP */
144   {
145     s_xhtml_1_0_start_p_tag,
146     s_xhtml_1_0_end_p_tag,
147   },
148   /* tagPRE */
149   {
150     s_xhtml_1_0_start_pre_tag,
151     s_xhtml_1_0_end_pre_tag,
152   },
153   /* tagUL */
154   {
155     s_xhtml_1_0_start_ul_tag,
156     s_xhtml_1_0_end_ul_tag,
157   },
158   /* tagLI */
159   {
160     s_xhtml_1_0_start_li_tag,
161     s_xhtml_1_0_end_li_tag,
162   },
163   /* tagOL */
164   {
165     s_xhtml_1_0_start_ol_tag,
166     s_xhtml_1_0_end_ol_tag,
167   },
168   /* tagH1 */
169   {
170     s_xhtml_1_0_start_h1_tag,
171     s_xhtml_1_0_end_h1_tag,
172   },
173   /* tagH2 */
174   {
175     s_xhtml_1_0_start_h2_tag,
176     s_xhtml_1_0_end_h2_tag,
177   },
178   /* tagH3 */
179   {
180     s_xhtml_1_0_start_h3_tag,
181     s_xhtml_1_0_end_h3_tag,
182   },
183   /* tagH4 */
184   {
185     s_xhtml_1_0_start_h4_tag,
186     s_xhtml_1_0_end_h4_tag,
187   },
188   /* tagH5 */
189   {
190     s_xhtml_1_0_start_h5_tag,
191     s_xhtml_1_0_end_h5_tag,
192   },
193   /* tagH6 */
194   {
195     s_xhtml_1_0_start_h6_tag,
196     s_xhtml_1_0_end_h6_tag,
197   },
198   /* tagHEAD */
199   {
200     s_xhtml_1_0_start_head_tag,
201     s_xhtml_1_0_end_head_tag,
202   },
203   /* tagTITLE */
204   {
205     s_xhtml_1_0_start_title_tag,
206     s_xhtml_1_0_end_title_tag,
207   },
208   /* tagBASE */
209   {
210     s_xhtml_1_0_start_base_tag,
211     s_xhtml_1_0_end_base_tag,
212   },
213   /* tagBODY */
214   {
215     s_xhtml_1_0_start_body_tag,
216     s_xhtml_1_0_end_body_tag,
217   },
218   /* tagA */
219   {
220     s_xhtml_1_0_start_a_tag,
221     s_xhtml_1_0_end_a_tag,
222   },
223   /* tagBR */
224   {
225     s_xhtml_1_0_start_br_tag,
226     s_xhtml_1_0_end_br_tag,
227   },
228   /* tagTABLE */
229   {
230     NULL,
231     NULL,
232   },
233   /* tagTR */
234   {
235     s_xhtml_1_0_start_tr_tag,
236     s_xhtml_1_0_end_tr_tag,
237   },
238   /* tagTD */
239   {
240     NULL,
241     NULL,
242   },
243   /* tagTBODY */
244   {
245     NULL,
246     NULL,
247   },
248   /* tagFONT */
249   {
250     s_xhtml_1_0_start_font_tag,
251     s_xhtml_1_0_end_font_tag,
252   },
253   /* tagFORM */
254   {
255     s_xhtml_1_0_start_form_tag,
256     s_xhtml_1_0_end_form_tag,
257   },
258   /* tagINPUT */
259   {
260     s_xhtml_1_0_start_input_tag,
261     s_xhtml_1_0_end_input_tag,
262   },
263   /* tagCENTER */
264   {
265     s_xhtml_1_0_start_center_tag,
266     s_xhtml_1_0_end_center_tag,
267   },
268   /* tagHR */
269   {
270     s_xhtml_1_0_start_hr_tag,
271     s_xhtml_1_0_end_hr_tag,
272   },
273   /* tagIMG */
274   {
275     s_xhtml_1_0_start_img_tag,
276     s_xhtml_1_0_end_img_tag,
277   },
278   /* tagSELECT */
279   {
280     s_xhtml_1_0_start_select_tag,
281     s_xhtml_1_0_end_select_tag,
282   },
283   /* tagOPTION */
284   {
285     s_xhtml_1_0_start_option_tag,
286     s_xhtml_1_0_end_option_tag,
287   },
288   /* tagDIV */
289   {
290     s_xhtml_1_0_start_div_tag,
291     s_xhtml_1_0_end_div_tag,
292   },
293   /* tagCHXJIF */
294   {
295     s_xhtml_1_0_chxjif_tag,
296     NULL,
297   },
298   /* tagCHXJRAW */
299   {
300     s_xhtml_1_0_chxjif_tag,
301     NULL,
302   },
303   /* tagNOBR */
304   {
305     NULL,
306     NULL,
307   },
308   /* tagSMALL */
309   {
310     NULL,
311     NULL,
312   },
313   /* tagSTYLE */
314   {
315     NULL,
316     NULL,
317   },
318   /* tagSPAN */
319   {
320     NULL,
321     NULL,
322   },
323   /* tagTEXT */
324   {
325     s_xhtml_1_0_text_tag,
326     NULL,
327   },
328   /* tagTH */
329   {
330     NULL,
331     NULL,
332   },
333   /* tagB */
334   {
335     s_xhtml_1_0_start_b_tag,
336     s_xhtml_1_0_end_b_tag,
337   },
338   /* tagFIELDSET */
339   {
340     NULL,
341     NULL,
342   },
343   /* tagDT */
344   {
345     s_xhtml_1_0_start_dt_tag,
346     s_xhtml_1_0_end_dt_tag,
347   },
348   /* tagLEGEND */
349   {
350     NULL,
351     NULL,
352   },
353   /* tagLABEL */
354   {
355     NULL,
356     NULL,
357   },
358   /* tagBLOCKQUOTE */
359   {
360     s_xhtml_1_0_start_blockquote_tag,
361     s_xhtml_1_0_end_blockquote_tag,
362   },
363   /* tagDIR */
364   {
365     s_xhtml_1_0_start_dir_tag,
366     s_xhtml_1_0_end_dir_tag,
367   },
368   /* tagDL */
369   {
370     s_xhtml_1_0_start_dl_tag,
371     s_xhtml_1_0_end_dl_tag,
372   },
373   /* tagDD */
374   {
375     s_xhtml_1_0_start_dd_tag,
376     s_xhtml_1_0_end_dd_tag,
377   },
378   /* tagMENU */
379   {
380     s_xhtml_1_0_start_menu_tag,
381     s_xhtml_1_0_end_menu_tag,
382   },
383   /* tagPLAINTEXT */
384   {
385     s_xhtml_1_0_start_plaintext_tag,
386     s_xhtml_1_0_end_plaintext_tag,
387   },
388   /* tagBLINK */
389   {
390     s_xhtml_1_0_start_blink_tag,
391     s_xhtml_1_0_end_blink_tag,
392   },
393   /* tagMARQUEE */
394   {
395     s_xhtml_1_0_start_marquee_tag,
396     s_xhtml_1_0_end_marquee_tag,
397   },
398   /* tagNLMARK */
399   {
400     s_xhtml_1_0_newline_mark,
401     NULL,
402   },
403 };
404  
405 /**
406  * converts from CHTML to XHTML.
407  *
408  * @param r     [i]   Requet_rec is appointed.
409  * @param spec  [i]   The result of the device specification processing which 
410  *                    was done in advance is appointed.
411  * @param src   [i]   The character string before the converting is appointed.
412  * @return The character string after the converting is returned.
413  */
414 char *
415 chxj_convert_xhtml_mobile_1_0(
416   request_rec        *r,
417   device_table       *spec,
418   const char         *src,
419   apr_size_t         srclen,
420   apr_size_t         *dstlen,
421   chxjconvrule_entry *entryp,
422   cookie_t           *cookie
423 )
424 {
425   char      *dst = NULL;
426   char      *ss;
427   xhtml_t   xhtml;
428   Doc       doc;
429
430   DBG(r,"REQ[%X] start %s()",TO_ADDR(r),__func__);
431   /*--------------------------------------------------------------------------*/
432   /* If qrcode xml                                                            */
433   /*--------------------------------------------------------------------------*/
434   *dstlen = srclen;
435   dst = chxj_qr_code_blob_handler(r, src, (size_t*)dstlen);
436   if (dst != NULL) {
437     DBG(r,"REQ[%X] found qrcode.xml", TO_ADDR(r));
438     DBG(r,"REQ[%X] end %s()",TO_ADDR(r),__func__);
439     return dst;
440   }
441
442   /*--------------------------------------------------------------------------*/
443   /* The XHTML structure is initialized.                                      */
444   /*--------------------------------------------------------------------------*/
445   s_init_xhtml(&xhtml, &doc, r, spec);
446
447   xhtml.entryp = entryp;
448   xhtml.cookie = cookie;
449
450   chxj_set_content_type(r, chxj_header_inf_set_content_type(r, "text/html; charset=Windows-31J"));
451
452   /*--------------------------------------------------------------------------*/
453   /* The character string of the input is analyzed.                           */
454   /*--------------------------------------------------------------------------*/
455   qs_init_malloc(&doc);
456   qs_init_root_node(&doc);
457
458   ss = apr_pcalloc(r->pool, srclen + 1);
459   memset(ss,   0, srclen + 1);
460   memcpy(ss, src, srclen);
461
462 #ifdef DUMP_LOG
463   chxj_dump_out("[src] CHTML->XHTML", ss, srclen);
464 #endif
465   qs_parse_string(&doc,ss, strlen(ss));
466
467   chxj_buffered_write_init(r->pool, &doc.buf);
468   /*--------------------------------------------------------------------------*/
469   /* It converts it from CHTML to XHTML.                                      */
470   /*--------------------------------------------------------------------------*/
471   chxj_node_convert(spec,r,(void *)&xhtml, &doc, qs_get_root(&doc), 0);
472   xhtml.out = chxj_buffered_write_flush(xhtml.out, &doc.buf);
473   dst = apr_pstrdup(r->pool, xhtml.out);
474   chxj_buffered_write_terminate(&doc.buf);
475
476   qs_all_free(&doc,QX_LOGMARK);
477
478   if (! dst) {
479     return apr_pstrdup(r->pool,ss);
480   }
481
482   if (! *dst) {
483     dst = apr_psprintf(r->pool, "\n");
484   }
485   *dstlen = strlen(dst);
486
487 #ifdef DUMP_LOG
488   chxj_dump_out("[dst] CHTML->XHTML", dst, *dstlen);
489 #endif
490
491   DBG(r,"REQ[%X] end %s()",TO_ADDR(r),__func__);
492   return dst;
493 }
494
495
496 /**
497  * The XHTML structure is initialized.
498  *
499  * @param xhtml [i/o] The pointer to the HDML structure that wants to be
500  *                   initialized is specified.
501  * @param doc   [i]   The Doc structure that should be set to the initialized
502  *                   HDML structure is specified.
503  * @param r     [i]   To use POOL, the pointer to request_rec is specified.
504  * @param spec  [i]   The pointer to the device_table
505  */
506 static void
507 s_init_xhtml(xhtml_t *xhtml, Doc *doc, request_rec *r, device_table *spec)
508 {
509   memset(doc,   0, sizeof(Doc));
510   memset(xhtml, 0, sizeof(xhtml_t));
511
512   doc->r      = r;
513   xhtml->doc  = doc;
514   xhtml->spec = spec;
515   xhtml->out  = qs_alloc_zero_byte_string(r->pool);
516   xhtml->conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
517   xhtml->doc->parse_mode = PARSE_MODE_CHTML;
518 }
519
520
521 /**
522  * Corresponding EMOJI to a current character-code is retrieved. 
523  * The substitution character string is stored in the rslt pointer if agreeing.
524  *
525  * @param xhtml   [i]   The pointer to the XHTML structure is specified. 
526  * @param txt     [i]   The character string to want to examine whether it is 
527  *                      EMOJI is specified. 
528  * @param rslt    [o]   The pointer to the pointer that stores the result is 
529  *                      specified. 
530  * @return When corresponding EMOJI exists, it returns it excluding 0. 
531  */
532 static int
533 s_xhtml_search_emoji(xhtml_t *xhtml, char *txt, char **rslt)
534 {
535   emoji_t       *ee;
536   request_rec   *r;
537   device_table  *spec;
538   int           len;
539
540   spec = xhtml->spec;
541
542   len = strlen(txt);
543   r = xhtml->doc->r;
544
545   if (spec == NULL) {
546     DBG(r,"REQ[%X] spec is NULL", TO_ADDR(r));
547   }
548
549   for (ee = xhtml->conf->emoji;
550        ee;
551        ee = ee->next) {
552     unsigned char hex1byte;
553     unsigned char hex2byte;
554     if (!ee->imode) {
555       DBG(r,"REQ[%X] emoji->imode is NULL", TO_ADDR(r));
556       continue;
557     }
558
559     if (ee->imode->string != NULL
560     &&  strlen(ee->imode->string) > 0
561     &&  strncasecmp(ee->imode->string, txt, strlen(ee->imode->string)) == 0) {
562       if (spec == NULL || spec->emoji_type == NULL) {
563         *rslt = apr_psprintf(r->pool,
564                         "<img localsrc=%s>",
565                         ee->ezweb->typeA);
566         return strlen(ee->imode->string);
567       }
568
569       if (strcasecmp(xhtml->spec->emoji_type, "a") == 0) {
570         *rslt = apr_psprintf(r->pool,
571                         "<img localsrc=%s>",
572                         ee->ezweb->typeA);
573         return strlen(ee->imode->string);
574       } 
575       else
576       if (strcasecmp(xhtml->spec->emoji_type, "b") == 0) {
577         *rslt = apr_psprintf(r->pool,
578                         "<img localsrc=%s>",
579                         ee->ezweb->typeB);
580         return strlen(ee->imode->string);
581       }
582       else
583       if (strcasecmp(xhtml->spec->emoji_type, "c") == 0) {
584         *rslt = apr_psprintf(r->pool,
585                         "<img localsrc=%s>",
586                         ee->ezweb->typeC);
587         return strlen(ee->imode->string);
588       }
589       else
590       if (strcasecmp(xhtml->spec->emoji_type, "d") == 0) {
591         *rslt = apr_psprintf(r->pool,
592                         "<img localsrc=%s>",
593                         ee->ezweb->typeD);
594         return strlen(ee->imode->string);
595       }
596       else {
597         *rslt = apr_psprintf(r->pool,
598                         "<img localsrc=%s>",
599                         ee->ezweb->typeA);
600         return strlen(ee->imode->string);
601       }
602       return 0;
603     }
604     hex1byte = ee->imode->hex1byte & 0xff;
605     hex2byte = ee->imode->hex2byte & 0xff;
606     if (len >= 2
607     && ((unsigned char)txt[0] & 0xff) == ((unsigned char)hex1byte)
608     && ((unsigned char)txt[1] & 0xff) == ((unsigned char)hex2byte)) {
609       if (spec == NULL || spec->emoji_type == NULL) {
610         *rslt = apr_psprintf(r->pool,
611                         "<img localsrc=\"%s\">",
612                         ee->ezweb->typeA);
613         return 2;
614       }
615
616       if (strcasecmp(xhtml->spec->emoji_type, "a") == 0) {
617         *rslt = apr_psprintf(r->pool,
618                         "<img localsrc=\"%s\">",
619                         ee->ezweb->typeA);
620         return 2;
621       } 
622       else
623       if (strcasecmp(xhtml->spec->emoji_type, "b") == 0) {
624         *rslt = apr_psprintf(r->pool,
625                         "<img localsrc=\"%s\">",
626                         ee->ezweb->typeB);
627         return 2;
628       }
629       else
630       if (strcasecmp(xhtml->spec->emoji_type, "c") == 0) {
631         *rslt = apr_psprintf(r->pool,
632                         "<img localsrc=\"%s\">",
633                         ee->ezweb->typeC);
634         return 2;
635       }
636       else
637       if (strcasecmp(xhtml->spec->emoji_type, "d") == 0) {
638         *rslt = apr_psprintf(r->pool,
639                         "<img localsrc=\"%s\">",
640                         ee->ezweb->typeD);
641         return 2;
642       }
643       else {
644         *rslt = apr_psprintf(r->pool,
645                         "<img localsrc=\"%s\">",
646                         ee->ezweb->typeD);
647         return 2;
648       }
649       return 0;
650     }
651   }
652   return 0;
653 }
654
655
656 char *
657 chxj_xhtml_emoji_only_converter(request_rec *r, device_table *spec, const char *src, apr_size_t len)
658 {
659   apr_size_t ii;
660   Doc __doc;
661   Doc *doc;
662   xhtml_t __xhtml;
663   xhtml_t *xhtml;
664   char one_byte[2];
665   char two_byte[3];
666   apr_pool_t *pool;
667
668   xhtml = &__xhtml;
669   doc   = &__doc;
670
671   DBG(r,"REQ[%X] start %s()",TO_ADDR(r),__func__);
672   memset(doc,     0, sizeof(Doc));
673   memset(xhtml, 0, sizeof(xhtml_t));
674
675   doc->r        = r;
676   xhtml->doc  = doc;
677   xhtml->spec = spec;
678   xhtml->out  = qs_alloc_zero_byte_string(r->pool);
679   xhtml->conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
680   xhtml->doc->parse_mode = PARSE_MODE_CHTML;
681
682   apr_pool_create(&pool, r->pool);
683
684   chxj_buffered_write_init(pool, &doc->buf);
685
686   for (ii=0; ii<len; ii++) {
687     char *out;
688     int   rtn;
689
690     rtn = s_xhtml_search_emoji(xhtml, (char *)&src[ii], &out);
691     if (rtn) {
692       W_V(out);
693       ii+=(rtn - 1);
694       continue;
695     }
696
697     if (is_sjis_kanji(src[ii])) {
698       two_byte[0] = src[ii+0];
699       two_byte[1] = src[ii+1];
700       two_byte[2] = 0;
701       W_V(two_byte);
702       ii++;
703     }
704     else {
705       one_byte[0] = src[ii+0];
706       one_byte[1] = 0;
707       W_V(one_byte);
708     }
709   }
710   xhtml->out = chxj_buffered_write_flush(xhtml->out, &doc->buf);
711
712   DBG(r,"REQ[%X] end %s()",TO_ADDR(r),__func__);
713   return xhtml->out;
714 }
715
716
717 /**
718  * It is a handler who processes the HTML tag.
719  *
720  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
721  *                     destination is specified.
722  * @param node   [i]   The HTML tag node is specified.
723  * @return The conversion result is returned.
724  */
725 static char *
726 s_xhtml_1_0_start_html_tag(void *pdoc, Node *node) 
727 {
728   xhtml_t       *xhtml = GET_XHTML(pdoc);
729   Attr          *attr;
730   Doc           *doc   = xhtml->doc;
731
732   /*--------------------------------------------------------------------------*/
733   /* Add XML Declare                                                          */
734   /*--------------------------------------------------------------------------*/
735   W_L("<?xml version=\"1.0\" encoding=\"Windows-31J\"?>");
736   W_NLCODE();
737   /*--------------------------------------------------------------------------*/
738   /* Add DocType                                                              */
739   /*--------------------------------------------------------------------------*/
740   W_L("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML Basic 1.0//EN\"");
741   W_NLCODE();
742   W_L(" \"http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd\">");
743   W_NLCODE();
744   /*--------------------------------------------------------------------------*/
745   /* start HTML tag                                                           */
746   /*--------------------------------------------------------------------------*/
747   W_L("<html xmlns=\"http://www.w3.org/1999/xhtml\"");
748   /*--------------------------------------------------------------------------*/
749   /* Get Attributes                                                           */
750   /*--------------------------------------------------------------------------*/
751   for (attr = qs_get_attr(doc,node);
752        attr; 
753        attr = qs_get_next_attr(doc,attr)) {
754     char* name  = qs_get_attr_name(doc,attr);
755     char* value = qs_get_attr_value(doc,attr);
756     if (STRCASEEQ('l','L',"lang", name)) {
757       W_L(" xml:lang=\"");
758       W_V(value);
759       W_L("\"");
760     }
761     else if (STRCASEEQ('v','V',"version", name)) {
762       W_L(" version=\"-//OPENWAVE//DTD XHTML Mobile 1.0//EN\"");
763     }
764   }
765   W_L(">");
766   return xhtml->out;
767 }
768
769
770 /**
771  * It is a handler who processes the HTML tag.
772  *
773  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
774  *                     destination is specified.
775  * @param node   [i]   The HTML tag node is specified.
776  * @return The conversion result is returned.
777  */
778 static char *
779 s_xhtml_1_0_end_html_tag(void *pdoc, Node *UNUSED(child)) 
780 {
781   xhtml_t       *xhtml = GET_XHTML(pdoc);
782   Doc           *doc   = xhtml->doc;
783   W_L("</html>");
784   return xhtml->out;
785 }
786
787
788 /**
789  * It is a handler who processes the META tag.
790  *
791  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
792  *                     destination is specified.
793  * @param node   [i]   The META tag node is specified.
794  * @return The conversion result is returned.
795  */
796 static char *
797 s_xhtml_1_0_start_meta_tag(void *pdoc, Node *node) 
798 {
799   xhtml_t       *xhtml = GET_XHTML(pdoc);
800   Attr          *attr;
801   Doc           *doc   = xhtml->doc;
802   int           content_type_flag = 0;
803   request_rec   *r = doc->r;
804
805   W_L("<meta");
806   /*--------------------------------------------------------------------------*/
807   /* Get Attributes                                                           */
808   /*--------------------------------------------------------------------------*/
809   for (attr = qs_get_attr(doc,node);
810        attr; 
811        attr = qs_get_next_attr(doc,attr)) {
812     char *name  = qs_get_attr_name(doc,attr);
813     char *value = qs_get_attr_value(doc,attr);
814     if (STRCASEEQ('n','N',"name", name) && value && *value) {
815       W_L(" ");
816       W_V(name);
817       W_L("=\"");
818       W_V(value);
819       W_L("\"");
820     }
821     else if (STRCASEEQ('h','H',"http-equiv", name) && value && *value) {
822       W_L(" ");
823       W_V(name);
824       W_L("=\"");
825       W_V(value);
826       W_L("\"");
827       if (STRCASEEQ('c','C', "content-type", value)) {
828         content_type_flag = 1;
829       }
830     }
831     else if (STRCASEEQ('c','C',"content", name) && value && *value) {
832       if (content_type_flag) {
833         W_L(" ");
834         W_V(name);
835         W_L("=\"");
836         W_V(chxj_header_inf_set_content_type(r, "text/html; charset=Windows-31J"));
837         W_L("\"");
838       }
839       else {
840         W_L(" ");
841         W_V(name);
842         W_L("=\"");
843         W_V(value);
844         W_L("\"");
845       }
846     }
847   }
848   W_L(" />");
849   return xhtml->out;
850 }
851
852
853 /**
854  * It is a handler who processes the META tag.
855  *
856  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
857  *                     destination is specified.
858  * @param node   [i]   The META tag node is specified.
859  * @return The conversion result is returned.
860  */
861 static char *
862 s_xhtml_1_0_end_meta_tag(void *pdoc, Node *UNUSED(child)) 
863 {
864   xhtml_t *xhtml = GET_XHTML(pdoc);
865
866   return xhtml->out;
867 }
868
869
870 /**
871  * It is a handler who processes the HEAD tag.
872  *
873  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
874  *                     destination is specified.
875  * @param node   [i]   The HEAD tag node is specified.
876  * @return The conversion result is returned.
877  */
878 static char *
879 s_xhtml_1_0_start_head_tag(void *pdoc, Node *UNUSED(node)) 
880 {
881   xhtml_t       *xhtml = GET_XHTML(pdoc);
882   Doc           *doc   = xhtml->doc;
883
884   W_L("<head>");
885   return xhtml->out;
886 }
887
888
889 /**
890  * It is a handler who processes the HEAD tag.
891  *
892  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
893  *                     destination is specified.
894  * @param node   [i]   The HEAD tag node is specified.
895  * @return The conversion result is returned.
896  */
897 static char *
898 s_xhtml_1_0_end_head_tag(void *pdoc, Node *UNUSED(child)) 
899 {
900   xhtml_t       *xhtml = GET_XHTML(pdoc);
901   Doc           *doc   = xhtml->doc;
902
903   W_L("</head>");
904   return xhtml->out;
905 }
906
907
908 /**
909  * It is a handler who processes the TITLE tag.
910  *
911  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
912  *                     destination is specified.
913  * @param node   [i]   The TITLE tag node is specified.
914  * @return The conversion result is returned.
915  */
916 static char *
917 s_xhtml_1_0_start_title_tag(void *pdoc, Node *UNUSED(node)) 
918 {
919   xhtml_t      *xhtml = GET_XHTML(pdoc);
920   Doc          *doc   = xhtml->doc;
921
922   W_L("<title>");
923   return xhtml->out;
924 }
925
926
927 /**
928  * It is a handler who processes the TITLE tag.
929  *
930  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
931  *                     destination is specified.
932  * @param node   [i]   The TITLE tag node is specified.
933  * @return The conversion result is returned.
934  */
935 static char *
936 s_xhtml_1_0_end_title_tag(void *pdoc, Node *UNUSED(child)) 
937 {
938   xhtml_t       *xhtml = GET_XHTML(pdoc);
939   Doc           *doc   = xhtml->doc;
940
941   W_L("</title>");
942
943   return xhtml->out;
944 }
945
946
947 /**
948  * It is a handler who processes the BASE tag.
949  *
950  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
951  *                     destination is specified.
952  * @param node   [i]   The BASE tag node is specified.
953  * @return The conversion result is returned.
954  */
955 static char *
956 s_xhtml_1_0_start_base_tag(void *pdoc, Node *node) 
957 {
958   xhtml_t       *xhtml = GET_XHTML(pdoc);
959   Attr          *attr;
960   Doc           *doc   = xhtml->doc;
961
962   W_L("<base");
963   /*--------------------------------------------------------------------------*/
964   /* Get Attributes                                                           */
965   /*--------------------------------------------------------------------------*/
966   for (attr = qs_get_attr(doc,node);
967        attr;
968        attr = qs_get_next_attr(doc,attr)) {
969     char *name = qs_get_attr_name(doc,attr);
970     char *value = qs_get_attr_value(doc,attr);
971     if (STRCASEEQ('h','H',"href",name)) {
972       W_L(" href=\"");
973       W_V(value);
974       W_L("\"");
975       break;
976     }
977   }
978   W_L(" />");
979
980   return xhtml->out;
981 }
982
983
984 /**
985  * It is a handler who processes the BASE tag.
986  *
987  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
988  *                     destination is specified.
989  * @param node   [i]   The BASE tag node is specified.
990  * @return The conversion result is returned.
991  */
992 static char *
993 s_xhtml_1_0_end_base_tag(void *pdoc, Node *UNUSED(child)) 
994 {
995   xhtml_t *xhtml = GET_XHTML(pdoc);
996
997   return xhtml->out;
998 }
999
1000
1001 /**
1002  * It is a handler who processes the BODY tag.
1003  *
1004  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1005  *                     destination is specified.
1006  * @param node   [i]   The BODY tag node is specified.
1007  * @return The conversion result is returned.
1008  */
1009 static char *
1010 s_xhtml_1_0_start_body_tag(void *pdoc, Node *node) 
1011 {
1012   xhtml_t      *xhtml = GET_XHTML(pdoc);
1013   Doc          *doc   = xhtml->doc;
1014   Attr         *attr;
1015
1016   W_L("<body");
1017   /*--------------------------------------------------------------------------*/
1018   /* Get Attributes                                                           */
1019   /*--------------------------------------------------------------------------*/
1020   for (attr = qs_get_attr(doc,node);
1021        attr;
1022        attr = qs_get_next_attr(doc,attr)) {
1023     char *name  = qs_get_attr_name(doc,attr);
1024     char *value = qs_get_attr_value(doc,attr);
1025     if (STRCASEEQ('b','B',"bgcolor", name) && value && *value) {
1026       W_L(" bgcolor=\"");
1027       W_V(value);
1028       W_L("\"");
1029     }
1030     else if (STRCASEEQ('t','T',"text",name) && value && *value) {
1031       W_L(" text=\"");
1032       W_V(value);
1033       W_L("\"");
1034     }
1035     else if (STRCASEEQ('l','L',"link", name) && value && *value) {
1036       W_L(" link=\"");
1037       W_V(value);
1038       W_L("\"");
1039     }
1040     else if (STRCASEEQ('a','A',"alink", name)) {
1041       /* ignore */
1042     }
1043     else if (STRCASEEQ('v','V',"vlink",name)) {
1044       /* ignore */
1045     }
1046   }
1047   W_L(">");
1048   return xhtml->out;
1049 }
1050
1051
1052 /**
1053  * It is a handler who processes the BODY tag.
1054  *
1055  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1056  *                     destination is specified.
1057  * @param node   [i]   The BODY tag node is specified.
1058  * @return The conversion result is returned.
1059  */
1060 static char *
1061 s_xhtml_1_0_end_body_tag(void *pdoc, Node *UNUSED(child)) 
1062 {
1063   xhtml_t       *xhtml = GET_XHTML(pdoc);
1064   Doc           *doc   = xhtml->doc;
1065
1066   W_L("</body>");
1067   return xhtml->out;
1068 }
1069
1070
1071 /**
1072  * It is a handler who processes the A tag.
1073  *
1074  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1075  *                     destination is specified.
1076  * @param node   [i]   The A tag node is specified.
1077  * @return The conversion result is returned.
1078  */
1079 static char *
1080 s_xhtml_1_0_start_a_tag(void *pdoc, Node *node) 
1081 {
1082   xhtml_t       *xhtml = GET_XHTML(pdoc);
1083   Doc           *doc   = xhtml->doc;
1084   request_rec   *r     = doc->r;
1085   Attr          *attr;
1086
1087   W_L("<a");
1088   /*--------------------------------------------------------------------------*/
1089   /* Get Attributes                                                           */
1090   /*--------------------------------------------------------------------------*/
1091   for (attr = qs_get_attr(doc,node);
1092        attr; 
1093        attr = qs_get_next_attr(doc,attr)) {
1094     char* name  = qs_get_attr_name(doc,attr);
1095     char* value = qs_get_attr_value(doc,attr);
1096     if (STRCASEEQ('n','N',"name",name) && value && *value) {
1097       W_L(" id=\"");
1098       W_V(value);
1099       W_L("\"");
1100     }
1101     else if (STRCASEEQ('h','H',"href", name) && value && *value) {
1102       value = chxj_encoding_parameter(r, value);
1103       if (! chxj_starts_with(value, "mailto:") && ! chxj_starts_with(value, "tel:")) {
1104         value = chxj_add_cookie_parameter(r, value, xhtml->cookie);
1105       }
1106       W_L(" href=\"");
1107       W_V(value);
1108       W_L("\"");
1109     }
1110     else if (STRCASEEQ('a','A',"accesskey", name)) {
1111       W_L(" accesskey=\"");
1112       W_V(value);
1113       W_L("\"");
1114     }
1115     else if (STRCASEEQ('c','C',"cti",name)) {
1116       /* ignore */
1117     }
1118     else if (STRCASEEQ('i','I',"ijam", name)) {
1119       /* ignore */
1120     }
1121     else if (STRCASEEQ('u','U',"utn", name)) {
1122       /* ignore */
1123     }
1124     else if (STRCASEEQ('t','T',"telbook",name)) {
1125       /* ignore */
1126     }
1127     else if (STRCASEEQ('k','K',"kana",name)) {
1128       /* ignore */
1129     }
1130     else if (STRCASEEQ('e','E',"email",name)) {
1131       /* ignore */
1132     }
1133     else if (STRCASEEQ('i','I',"ista",name)) {
1134       /* ignore */
1135     }
1136     else if (STRCASEEQ('i','I',"ilet",name)) {
1137       /* ignore */
1138     }
1139     else if (STRCASEEQ('i','I',"iswf",name)) {
1140       /* ignore */
1141     }
1142     else if (STRCASEEQ('i','I',"irst",name)) {
1143       /* ignore */
1144     }
1145   }
1146   W_L(">");
1147   return xhtml->out;
1148 }
1149
1150
1151 /**
1152  * It is a handler who processes the A tag.
1153  *
1154  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1155  *                     destination is specified.
1156  * @param node   [i]   The A tag node is specified.
1157  * @return The conversion result is returned.
1158  */
1159 static char *
1160 s_xhtml_1_0_end_a_tag(void *pdoc, Node *UNUSED(child)) 
1161 {
1162   xhtml_t *xhtml = GET_XHTML(pdoc);
1163   Doc     *doc   = xhtml->doc;
1164
1165   W_L("</a>");
1166
1167   return xhtml->out;
1168 }
1169
1170
1171 /**
1172  * It is a handler who processes the BR tag.
1173  *
1174  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1175  *                     destination is specified.
1176  * @param node   [i]   The BR tag node is specified.
1177  * @return The conversion result is returned.
1178  */
1179 static char *
1180 s_xhtml_1_0_start_br_tag(void *pdoc, Node *node) 
1181 {
1182   xhtml_t *xhtml = GET_XHTML(pdoc);
1183   Doc     *doc   = xhtml->doc;
1184   Attr    *attr;
1185
1186   W_L("<br");
1187   /*--------------------------------------------------------------------------*/
1188   /* Get Attributes                                                           */
1189   /*--------------------------------------------------------------------------*/
1190   for (attr = qs_get_attr(doc,node);
1191        attr;
1192        attr = qs_get_next_attr(doc,attr)) {
1193     char *name  = qs_get_attr_name(doc,attr);
1194     char *value = qs_get_attr_value(doc,attr);
1195     if (STRCASEEQ('c','C',"clear",name)) {
1196       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('a','A',"all",value))) {
1197         W_L(" clear=\"");
1198         W_V(value);
1199         W_L("\"");
1200       }
1201     }
1202   }
1203   W_L(" />");
1204
1205   return xhtml->out;
1206 }
1207
1208
1209 /**
1210  * It is a handler who processes the BR tag.
1211  *
1212  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1213  *                     destination is specified.
1214  * @param node   [i]   The BR tag node is specified.
1215  * @return The conversion result is returned.
1216  */
1217 static char *
1218 s_xhtml_1_0_end_br_tag(void *pdoc, Node *UNUSED(child)) 
1219 {
1220   xhtml_t *xhtml = GET_XHTML(pdoc);
1221
1222   return xhtml->out;
1223 }
1224
1225
1226 /**
1227  * It is a handler who processes the TR tag.
1228  *
1229  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1230  *                     destination is specified.
1231  * @param node   [i]   The TR tag node is specified.
1232  * @return The conversion result is returned.
1233  */
1234 static char *
1235 s_xhtml_1_0_start_tr_tag(void *pdoc, Node *UNUSED(node)) 
1236 {
1237   xhtml_t *xhtml = GET_XHTML(pdoc);
1238   Doc     *doc   = xhtml->doc;
1239
1240   W_L("<br />");
1241
1242   return xhtml->out;
1243 }
1244
1245
1246 /**
1247  * It is a handler who processes the TR tag.
1248  *
1249  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1250  *                     destination is specified.
1251  * @param node   [i]   The TR tag node is specified.
1252  * @return The conversion result is returned.
1253  */
1254 static char *
1255 s_xhtml_1_0_end_tr_tag(void *pdoc, Node *UNUSED(child)) 
1256 {
1257   xhtml_t *xhtml = GET_XHTML(pdoc);
1258
1259   return xhtml->out;
1260 }
1261
1262
1263 /**
1264  * It is a handler who processes the FONT tag.
1265  *
1266  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1267  *                     destination is specified.
1268  * @param node   [i]   The FONT tag node is specified.
1269  * @return The conversion result is returned.
1270  */
1271 static char *
1272 s_xhtml_1_0_start_font_tag(void *pdoc, Node *node) 
1273 {
1274   xhtml_t *xhtml = GET_XHTML(pdoc);
1275   Doc     *doc   = xhtml->doc;
1276   Attr    *attr;
1277   char    *size = NULL;
1278   char    *color = NULL;
1279
1280   /*=========================================================================*/
1281   /* Get Attributes                                                          */
1282   /*=========================================================================*/
1283   for (attr = qs_get_attr(doc,node);
1284        attr;
1285        attr = qs_get_next_attr(doc,attr)) {
1286     char *name = qs_get_attr_name(doc,attr);
1287     char *value = qs_get_attr_value(doc,attr);
1288     if (STRCASEEQ('c','C',"color",name) && value && *value) {
1289       color = apr_pstrdup(doc->buf.pool, value);
1290     }
1291     else if (STRCASEEQ('s','S',"size",name) && value && *value) {
1292       size = apr_pstrdup(doc->buf.pool, value);
1293     }
1294   }
1295   if (color) {
1296     W_L("<font color=\"");
1297     W_V(color);
1298     W_L("\">");
1299     xhtml->font_color_flag++;
1300   }
1301   if (size) {
1302     xhtml->font_size_flag++;
1303     switch(*size) {
1304     case '1': W_L("<span style=\"font-size: xx-small\">"); break;
1305     case '2': W_L("<span style=\"font-size: x-small\">");  break;
1306     case '3': W_L("<span style=\"font-size: small\">");    break;
1307     case '4': W_L("<span style=\"font-size: medium\">");   break;
1308     case '5': W_L("<span style=\"font-size: large\">");    break;
1309     case '6': W_L("<span style=\"font-size: x-large\">");  break;
1310     case '7': W_L("<span style=\"font-size: xx-large\">"); break;
1311     case '-':
1312       if (*(size + 1) == '1') {
1313         W_L("<span style=\"font-size: small\">");
1314         break;
1315       }
1316       if (*(size + 1) == '2') {
1317         W_L("<span style=\"font-size: x-small\">");
1318         break;
1319       }
1320       if (*(size + 1) == '3') {
1321         W_L("<span style=\"font-size: xx-small\">");
1322         break;
1323       }
1324       xhtml->font_size_flag--;
1325       break;
1326
1327     case '+':
1328       if (*(size + 1) == '1') {
1329         W_L("<span style=\"font-size: large\">");
1330         break;
1331       }
1332       if (*(size + 1) == '2') {
1333         W_L("<span style=\"font-size: x-large\">");
1334         break;
1335       }
1336       if (*(size + 1) == '3') {
1337         W_L("<span style=\"font-size: xx-large\">");
1338         break;
1339       }
1340       xhtml->font_size_flag--;
1341       break;
1342
1343     default:
1344       WRN(doc->r, "invlalid font size. [%s] != (1|2|3|4|5|6|7|+1|+2|+3|-1|-2|-3)", size);
1345       xhtml->font_size_flag--;
1346     }
1347   }
1348   return xhtml->out;
1349 }
1350
1351
1352 /**
1353  * It is a handler who processes the FONT tag.
1354  *
1355  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1356  *                     destination is specified.
1357  * @param node   [i]   The FONT tag node is specified.
1358  * @return The conversion result is returned.
1359  */
1360 static char *
1361 s_xhtml_1_0_end_font_tag(void *pdoc, Node *UNUSED(child)) 
1362 {
1363   xhtml_t *xhtml = GET_XHTML(pdoc);
1364   Doc     *doc   = xhtml->doc;
1365
1366   if (xhtml->font_size_flag) {
1367     W_L("</span>");
1368     xhtml->font_size_flag--;
1369   }
1370   if (xhtml->font_color_flag) {
1371     W_L("</font>");
1372     xhtml->font_color_flag--;
1373   }
1374   return xhtml->out;
1375 }
1376
1377
1378 /**
1379  * It is a handler who processes the FORM tag.
1380  *
1381  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1382  *                     destination is specified.
1383  * @param node   [i]   The FORM tag node is specified.
1384  * @return The conversion result is returned.
1385  */
1386 static char *
1387 s_xhtml_1_0_start_form_tag(void *pdoc, Node *node) 
1388 {
1389   xhtml_t     *xhtml = GET_XHTML(pdoc);
1390   Doc         *doc   = xhtml->doc;
1391   request_rec *r     = doc->r;
1392   Attr        *attr;
1393   char        *new_hidden_tag = NULL;
1394   char        *attr_action = NULL;
1395   char        *attr_method = NULL;
1396   char        *attr_name = NULL;
1397
1398   /*--------------------------------------------------------------------------*/
1399   /* Get Attributes                                                           */
1400   /*--------------------------------------------------------------------------*/
1401   for (attr = qs_get_attr(doc,node);
1402        attr;
1403        attr = qs_get_next_attr(doc,attr)) {
1404     char *name = qs_get_attr_name(doc,attr);
1405     char *value = qs_get_attr_value(doc,attr);
1406     if (STRCASEEQ('a','A',"action",name)) {
1407       attr_action = chxj_encoding_parameter(r, value);
1408       attr_action = chxj_add_cookie_parameter(r, attr_action, xhtml->cookie);
1409     }
1410     else if (STRCASEEQ('m','M',"method",name)) {
1411       attr_method = apr_pstrdup(doc->pool, value);
1412     }
1413     else if (STRCASEEQ('u','U',"utn",name)) {
1414       /* ignore */
1415     }
1416     else if (STRCASEEQ('n','N',"name",name)) {
1417       attr_name = apr_pstrdup(doc->pool, value);
1418     }
1419   }
1420
1421   int post_flag = (attr_method && strcasecmp(attr_method, "post") == 0) ? 1 : 0;
1422
1423   W_L("<form");
1424   if (attr_action) {
1425     char *q;
1426     char *old_qs = NULL;
1427     q = strchr(attr_action, '?');
1428     if (q) {
1429       new_hidden_tag = chxj_form_action_to_hidden_tag(r, doc->pool, attr_action, 1, post_flag, &old_qs, CHXJ_FALSE, CHXJ_FALSE, xhtml->entryp);
1430       if (new_hidden_tag || old_qs) {
1431         *q = 0;
1432       }
1433     }
1434     W_L(" action=\"");
1435     W_V(attr_action);
1436     if (old_qs) {
1437       W_L("?");
1438       W_V(old_qs);
1439     }
1440     W_L("\"");
1441   }
1442   if (attr_method) {
1443     W_L(" method=\"");
1444     W_V(attr_method);
1445     W_L("\"");
1446   }
1447   if (attr_name) {
1448     W_L(" name=\"");
1449     W_V(attr_name);
1450     W_L("\"");
1451   }
1452   W_L(">");
1453   if (new_hidden_tag) {
1454     W_V(new_hidden_tag);
1455   }
1456   return xhtml->out;
1457 }
1458
1459
1460 /**
1461  * It is a handler who processes the FORM tag.
1462  *
1463  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1464  *                     destination is specified.
1465  * @param node   [i]   The FORM tag node is specified.
1466  * @return The conversion result is returned.
1467  */
1468 static char *
1469 s_xhtml_1_0_end_form_tag(void *pdoc, Node *UNUSED(child)) 
1470 {
1471   xhtml_t *xhtml = GET_XHTML(pdoc);
1472   Doc     *doc   = xhtml->doc;
1473
1474   W_L("</form>");
1475
1476   return xhtml->out;
1477 }
1478
1479
1480 /**
1481  * It is a handler who processes the INPUT tag.
1482  *
1483  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1484  *                     destination is specified.
1485  * @param node   [i]   The INPUT tag node is specified.
1486  * @return The conversion result is returned.
1487  */
1488 static char *
1489 s_xhtml_1_0_start_input_tag(void *pdoc, Node *node) 
1490 {
1491   xhtml_t     *xhtml       = GET_XHTML(pdoc);
1492   Doc         *doc         = xhtml->doc;
1493   request_rec *r           = doc->r;
1494   char        *max_length  = NULL;
1495   char        *type        = NULL;
1496   char        *name        = NULL;
1497   char        *value       = NULL;
1498   char        *istyle      = NULL;
1499   char        *size        = NULL;
1500   char        *checked     = NULL;
1501   char        *accesskey   = NULL;
1502
1503   W_L("<input");
1504   /*--------------------------------------------------------------------------*/
1505   /* Get Attributes                                                           */
1506   /*--------------------------------------------------------------------------*/
1507   type       = qs_get_type_attr(doc, node, doc->buf.pool);
1508   name       = qs_get_name_attr(doc, node, doc->buf.pool);
1509   value      = qs_get_value_attr(doc,node, doc->buf.pool);
1510   istyle     = qs_get_istyle_attr(doc,node,doc->buf.pool);
1511   max_length = qs_get_maxlength_attr(doc,node,doc->buf.pool);
1512   checked    = qs_get_checked_attr(doc,node, doc->buf.pool);
1513   accesskey  = qs_get_accesskey_attr(doc, node, doc->buf.pool);
1514   size       = qs_get_size_attr(doc, node, doc->buf.pool);
1515
1516   if (type) {
1517     type = qs_trim_string(doc->buf.pool, type);
1518     if (type && (STRCASEEQ('t','T',"text",    type) ||
1519                  STRCASEEQ('p','P',"password",type) ||
1520                  STRCASEEQ('c','C',"checkbox",type) ||
1521                  STRCASEEQ('r','R',"radio",   type) ||
1522                  STRCASEEQ('h','H',"hidden",  type) ||
1523                  STRCASEEQ('s','S',"submit",  type) ||
1524                  STRCASEEQ('r','R',"reset",   type))) {
1525       W_L(" type=\"");
1526       W_V(type);
1527       W_L("\"");
1528     }
1529   }
1530   if (size && *size) {
1531     W_L(" size=\"");
1532     W_V(size);
1533     W_L("\"");
1534   }
1535   if (name && *name) {
1536     W_L(" name=\"");
1537     W_V(name);
1538     W_L("\"");
1539   }
1540   if (value && *value) {
1541     if (type && (STRCASEEQ('s','S',"submit",type) || STRCASEEQ('r','R',"reset",type))) {
1542       apr_size_t value_len = strlen(value);
1543       value = chxj_conv_z2h(r, value, &value_len, xhtml->entryp);
1544     }
1545
1546     W_L(" value=\"");
1547     W_V(chxj_add_slash_to_doublequote(doc->pool, value));
1548     W_L("\"");
1549   }
1550   if (accesskey && *accesskey) {
1551     W_L(" accesskey=\"");
1552     W_V(accesskey);
1553     W_L("\"");
1554   }
1555   if (istyle && *istyle && (*istyle == '1' || *istyle == '2' || *istyle == '3' || *istyle == '4')) {
1556     char *fmt = qs_conv_istyle_to_format(r,istyle);
1557     if (max_length && *max_length) {
1558       int ii;
1559       for (ii=0; (unsigned int)ii<strlen(max_length); ii++) {
1560         if (max_length[ii] < '0' || max_length[ii] > '9') {
1561           max_length = apr_psprintf(r->pool, "0");
1562           break;
1563         }
1564       }
1565
1566       if (strcmp(max_length, "0")) {
1567         char *vv = apr_psprintf(r->pool, " FORMAT=\"%d%s\"", atoi(max_length), fmt);
1568         W_V(vv);
1569       }
1570     }
1571     else {
1572       W_L(" FORMAT=\"");
1573       W_L("*");
1574       W_V(fmt);
1575       W_L("\"");
1576     }
1577   }
1578   else {
1579     if (max_length && *max_length) {
1580       if (chxj_chk_numeric(max_length) != 0) {
1581         max_length = apr_psprintf(r->pool, "0");
1582       }
1583       if (strcmp(max_length, "0")) {
1584         char *vv = apr_psprintf(r->pool, " FORMAT=\"%dm\"", atoi(max_length));
1585         W_V(vv);
1586       }
1587     }
1588   }
1589   /*--------------------------------------------------------------------------*/
1590   /* The figure is default for the password.                                  */
1591   /*--------------------------------------------------------------------------*/
1592   if (type && (istyle == NULL || *istyle == 0) && STRCASEEQ('p','P',"password", type) && ! xhtml->entryp->pc_flag) {
1593     if (max_length) {
1594       W_L(" FORMAT=\"");
1595       W_V(max_length);
1596       W_L("N\"");
1597     }
1598     else {
1599       W_L(" FORMAT=\"*N\"");
1600     }
1601   }
1602   if (checked) {
1603     W_L(" checked=\"checked\"");
1604   }
1605   W_L(" />");
1606
1607   return xhtml->out;
1608 }
1609
1610
1611 /**
1612  * It is a handler who processes the INPUT tag.
1613  *
1614  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1615  *                     destination is specified.
1616  * @param node   [i]   The INPUT tag node is specified.
1617  * @return The conversion result is returned.
1618  */
1619 static char *
1620 s_xhtml_1_0_end_input_tag(void *pdoc, Node *UNUSED(child)) 
1621 {
1622   xhtml_t *xhtml = GET_XHTML(pdoc);
1623
1624   return xhtml->out;
1625 }
1626
1627
1628 /**
1629  * It is a handler who processes the CENTER tag.
1630  *
1631  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1632  *                     destination is specified.
1633  * @param node   [i]   The CENTER tag node is specified.
1634  * @return The conversion result is returned.
1635  */
1636 static char *
1637 s_xhtml_1_0_start_center_tag(void *pdoc, Node *UNUSED(node)) 
1638 {
1639   xhtml_t *xhtml = GET_XHTML(pdoc);
1640   Doc     *doc   = xhtml->doc;
1641
1642   W_L("<center>");
1643   return xhtml->out;
1644 }
1645
1646
1647 /**
1648  * It is a handler who processes the CENTER tag.
1649  *
1650  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1651  *                     destination is specified.
1652  * @param node   [i]   The CENTER tag node is specified.
1653  * @return The conversion result is returned.
1654  */
1655 static char *
1656 s_xhtml_1_0_end_center_tag(void *pdoc, Node *UNUSED(child)) 
1657 {
1658   xhtml_t *xhtml = GET_XHTML(pdoc);
1659   Doc     *doc   = xhtml->doc;
1660
1661   W_L("</center>");
1662   return xhtml->out;
1663 }
1664
1665
1666 /**
1667  * It is a handler who processes the HR tag.
1668  *
1669  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1670  *                     destination is specified.
1671  * @param node   [i]   The HR tag node is specified.
1672  * @return The conversion result is returned.
1673  */
1674 static char *
1675 s_xhtml_1_0_start_hr_tag(void *pdoc, Node *node)
1676 {
1677   xhtml_t *xhtml = GET_XHTML(pdoc);
1678   Doc     *doc   = xhtml->doc;
1679   Attr    *attr;
1680
1681   W_L("<hr");
1682  
1683   for (attr = qs_get_attr(doc,node);
1684        attr; 
1685        attr = qs_get_next_attr(doc,attr)) {
1686     char *name = qs_get_attr_name(doc,attr);
1687     char *value = qs_get_attr_value(doc,attr);
1688     if (STRCASEEQ('a','A',"align", name)) {
1689       /*----------------------------------------------------------------------*/
1690       /* CHTML 1.0                                                            */
1691       /*----------------------------------------------------------------------*/
1692       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
1693         W_L(" align=\"");
1694         W_V(value);
1695         W_L("\"");
1696       }
1697     }
1698     else if (STRCASEEQ('s','S',"size", name)) {
1699       /*----------------------------------------------------------------------*/
1700       /* CHTML 1.0                                                            */
1701       /*----------------------------------------------------------------------*/
1702       if (value && *value) {
1703         W_L(" size=\"");
1704         W_V(value);
1705         W_L("\"");
1706       }
1707     }
1708     else if (STRCASEEQ('w','W',"width", name)) {
1709       /*----------------------------------------------------------------------*/
1710       /* CHTML 1.0                                                            */
1711       /*----------------------------------------------------------------------*/
1712       if (value && *value) {
1713         W_L(" width=\"");
1714         W_V(value);
1715         W_L("\"");
1716       }
1717     }
1718     else if (STRCASEEQ('n','N',"noshade", name)) {
1719       /*----------------------------------------------------------------------*/
1720       /* CHTML 1.0                                                            */
1721       /*----------------------------------------------------------------------*/
1722       /* ignore */
1723     }
1724     else if (STRCASEEQ('c','C',"color", name) && value && *value) {
1725       /*----------------------------------------------------------------------*/
1726       /* CHTML 4.0                                                            */
1727       /*----------------------------------------------------------------------*/
1728       W_L(" color=\"");
1729       W_V(value);
1730       W_L("\"");
1731     }
1732   }
1733   W_L(" />");
1734   return xhtml->out;
1735 }
1736
1737
1738 /**
1739  * It is a handler who processes the HR tag.
1740  *
1741  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1742  *                     destination is specified.
1743  * @param node   [i]   The HR tag node is specified.
1744  * @return The conversion result is returned.
1745  */
1746 static char *
1747 s_xhtml_1_0_end_hr_tag(void *pdoc, Node *UNUSED(child)) 
1748 {
1749   xhtml_t *xhtml = GET_XHTML(pdoc);
1750
1751   return xhtml->out;
1752 }
1753
1754
1755 /**
1756  * It is a handler who processes the PRE tag.
1757  *
1758  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1759  *                     destination is specified.
1760  * @param node   [i]   The PRE tag node is specified.
1761  * @return The conversion result is returned.
1762  */
1763 static char *
1764 s_xhtml_1_0_start_pre_tag(void* pdoc, Node* UNUSED(node)) 
1765 {
1766   xhtml_t *xhtml = GET_XHTML(pdoc);
1767   Doc     *doc   = xhtml->doc;
1768
1769   xhtml->pre_flag++;
1770   W_L("<pre>");
1771   return xhtml->out;
1772 }
1773
1774
1775 /**
1776  * It is a handler who processes the PRE tag.
1777  *
1778  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1779  *                     destination is specified.
1780  * @param node   [i]   The PRE tag node is specified.
1781  * @return The conversion result is returned.
1782  */
1783 static char *
1784 s_xhtml_1_0_end_pre_tag(void *pdoc, Node *UNUSED(child)) 
1785 {
1786   xhtml_t *xhtml = GET_XHTML(pdoc);
1787   Doc     *doc   = xhtml->doc;
1788
1789   W_L("</pre>");
1790   xhtml->pre_flag--;
1791
1792   return xhtml->out;
1793 }
1794
1795
1796 /**
1797  * It is a handler who processes the P tag.
1798  *
1799  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1800  *                     destination is specified.
1801  * @param node   [i]   The P tag node is specified.
1802  * @return The conversion result is returned.
1803  */
1804 static char *
1805 s_xhtml_1_0_start_p_tag(void *pdoc, Node *node) 
1806 {
1807   xhtml_t *xhtml = GET_XHTML(pdoc);
1808   Doc     *doc   = xhtml->doc;
1809   Attr    *attr;
1810   char    *align = NULL;
1811
1812   W_L("<p");
1813   for (attr = qs_get_attr(doc,node);
1814        attr;
1815        attr = qs_get_next_attr(doc,attr)) {
1816     char *nm  = qs_get_attr_name(doc,attr);
1817     char *val = qs_get_attr_value(doc,attr);
1818     if (STRCASEEQ('a','A',"align", nm)) {
1819       /*----------------------------------------------------------------------*/
1820       /* CHTML 1.0 (W3C version 3.2)                                          */
1821       /*----------------------------------------------------------------------*/
1822       if (val && (STRCASEEQ('l','L',"left",val) || STRCASEEQ('r','R',"right",val) || STRCASEEQ('c','C',"center",val))) {
1823         align = apr_pstrdup(doc->buf.pool, val);
1824         break;
1825       }
1826     }
1827   }
1828   if (align) {
1829     W_L(" align=\"");
1830     W_V(align);
1831     W_L("\"");
1832   }
1833   W_L(">");
1834   return xhtml->out;
1835 }
1836
1837
1838 /**
1839  * It is a handler who processes the P tag.
1840  *
1841  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1842  *                     destination is specified.
1843  * @param node   [i]   The P tag node is specified.
1844  * @return The conversion result is returned.
1845  */
1846 static char *
1847 s_xhtml_1_0_end_p_tag(void *pdoc, Node *UNUSED(child)) 
1848 {
1849   xhtml_t *xhtml = GET_XHTML(pdoc);
1850   Doc     *doc   = xhtml->doc;
1851
1852   W_L("</p>");
1853   return xhtml->out;
1854 }
1855
1856
1857 /**
1858  * It is a handler who processes the UL tag.
1859  *
1860  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1861  *                     destination is specified.
1862  * @param node   [i]   The UL tag node is specified.
1863  * @return The conversion result is returned.
1864  */
1865 static char *
1866 s_xhtml_1_0_start_ul_tag(void *pdoc, Node *node)
1867 {
1868   xhtml_t *xhtml = GET_XHTML(pdoc);
1869   Doc     *doc   = xhtml->doc;
1870   Attr    *attr;
1871   W_L("<ul");
1872   /*--------------------------------------------------------------------------*/
1873   /* Get Attributes                                                           */
1874   /*--------------------------------------------------------------------------*/
1875   for (attr = qs_get_attr(doc,node);
1876        attr;
1877        attr = qs_get_next_attr(doc,attr)) {
1878     char *name   = qs_get_attr_name(doc,attr);
1879     char *value  = qs_get_attr_value(doc,attr);
1880     if (STRCASEEQ('t','T',"type",name)) {
1881       if (value && (STRCASEEQ('d','D',"disc",value) || STRCASEEQ('c','C',"circle",value) || STRCASEEQ('s','S',"square",value))) {
1882         W_L(" type=\"");
1883         W_V(value);
1884         W_L("\"");
1885       }
1886     }
1887   }
1888   W_L(">");
1889   return xhtml->out;
1890 }
1891
1892
1893 /**
1894  * It is a handler who processes the UL tag.
1895  *
1896  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1897  *                     destination is specified.
1898  * @param node   [i]   The UL tag node is specified.
1899  * @return The conversion result is returned.
1900  */
1901 static char *
1902 s_xhtml_1_0_end_ul_tag(void *pdoc, Node *UNUSED(child)) 
1903 {
1904   xhtml_t *xhtml = GET_XHTML(pdoc);
1905   Doc     *doc   = xhtml->doc;
1906
1907   W_L("</ul>");
1908   return xhtml->out;
1909 }
1910
1911
1912 /**
1913  * It is a handler who processes the H1 tag.
1914  *
1915  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1916  *                     destination is specified.
1917  * @param node   [i]   The H1 tag node is specified.
1918  * @return The conversion result is returned.
1919  */
1920 static char *
1921 s_xhtml_1_0_start_h1_tag(void *pdoc, Node *node) 
1922 {
1923   xhtml_t *xhtml = GET_XHTML(pdoc);
1924   Doc     *doc   = xhtml->doc;
1925   Attr    *attr;
1926
1927   W_L("<h1");
1928   for (attr = qs_get_attr(doc,node);
1929        attr;
1930        attr = qs_get_next_attr(doc,attr)) {
1931     char* name;
1932     char* value;
1933     name  = qs_get_attr_name(doc,attr);
1934     value = qs_get_attr_value(doc,attr);
1935     if (STRCASEEQ('a','A',"align", name)) {
1936       if (value) {
1937         if (STRCASEEQ('l','L',"left",value)) {
1938           W_L(" style=\"");
1939           W_L("text-align:left");
1940           W_L("\"");
1941         }
1942         else if (STRCASEEQ('r','R',"right",value)) {
1943           W_L(" style=\"");
1944           W_L("text-align:right");
1945           W_L("\"");
1946         }
1947         else if (STRCASEEQ('c','C',"center",value)) {
1948           W_L(" style=\"");
1949           W_L("text-align:center");
1950           W_L("\"");
1951         }
1952         break;
1953       }
1954     }
1955   }
1956   W_L(">");
1957   return xhtml->out;
1958 }
1959
1960
1961 /**
1962  * It is a handler who processes the H1 tag.
1963  *
1964  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1965  *                     destination is specified.
1966  * @param node   [i]   The H1 tag node is specified.
1967  * @return The conversion result is returned.
1968  */
1969 static char *
1970 s_xhtml_1_0_end_h1_tag(void *pdoc, Node *UNUSED(child)) 
1971 {
1972   xhtml_t *xhtml = GET_XHTML(pdoc);
1973   Doc     *doc   = xhtml->doc;
1974
1975   W_L("</h1>");
1976   return xhtml->out;
1977 }
1978
1979
1980 /**
1981  * It is a handler who processes the H2 tag.
1982  *
1983  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
1984  *                     destination is specified.
1985  * @param node   [i]   The H2 tag node is specified.
1986  * @return The conversion result is returned.
1987  */
1988 static char *
1989 s_xhtml_1_0_start_h2_tag(void *pdoc, Node *node)
1990 {
1991   xhtml_t *xhtml = GET_XHTML(pdoc);
1992   Doc     *doc = xhtml->doc;
1993   Attr    *attr;
1994
1995   W_L("<h2");
1996   for (attr = qs_get_attr(doc,node);
1997        attr;
1998        attr = qs_get_next_attr(doc,attr)) {
1999     char* name;
2000     char* value;
2001     name  = qs_get_attr_name(doc,attr);
2002     value = qs_get_attr_value(doc,attr);
2003     if (STRCASEEQ('a','A',"align", name)) {
2004       if (value) {
2005         if (STRCASEEQ('l','L',"left",value)) {
2006           W_L(" style=\"");
2007           W_L("text-align:left");
2008           W_L("\"");
2009         }
2010         else if (STRCASEEQ('r','R',"right",value)) {
2011           W_L(" style=\"");
2012           W_L("text-align:right");
2013           W_L("\"");
2014         }
2015         else if (STRCASEEQ('c','C',"center",value)) {
2016           W_L(" style=\"");
2017           W_L("text-align:center");
2018           W_L("\"");
2019         }
2020         break;
2021       }
2022     }
2023   }
2024   W_L(">");
2025   return xhtml->out;
2026 }
2027
2028
2029 /**
2030  * It is a handler who processes the H2 tag.
2031  *
2032  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2033  *                     destination is specified.
2034  * @param node   [i]   The H2 tag node is specified.
2035  * @return The conversion result is returned.
2036  */
2037 static char *
2038 s_xhtml_1_0_end_h2_tag(void *pdoc, Node *UNUSED(child)) 
2039 {
2040   xhtml_t *xhtml = GET_XHTML(pdoc);
2041   Doc     *doc   = xhtml->doc;
2042
2043   W_L("</h2>");
2044   return xhtml->out;
2045 }
2046
2047
2048 /**
2049  * It is a handler who processes the H3 tag.
2050  *
2051  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2052  *                     destination is specified.
2053  * @param node   [i]   The H3 tag node is specified.
2054  * @return The conversion result is returned.
2055  */
2056 static char *
2057 s_xhtml_1_0_start_h3_tag(void *pdoc, Node *node)
2058 {
2059   xhtml_t *xhtml = GET_XHTML(pdoc);
2060   Doc     *doc   = xhtml->doc;
2061   Attr    *attr;
2062
2063   W_L("<h3");
2064   for (attr = qs_get_attr(doc,node);
2065        attr;
2066        attr = qs_get_next_attr(doc,attr)) {
2067     char* name;
2068     char* value;
2069     name  = qs_get_attr_name(doc,attr);
2070     value = qs_get_attr_value(doc,attr);
2071     if (STRCASEEQ('a','A',"align", name)) {
2072       if (value) {
2073         if (STRCASEEQ('l','L',"left",value)) {
2074           W_L(" style=\"");
2075           W_L("text-align:left");
2076           W_L("\"");
2077         }
2078         else if (STRCASEEQ('r','R',"right",value)) {
2079           W_L(" style=\"");
2080           W_L("text-align:right");
2081           W_L("\"");
2082         }
2083         else if (STRCASEEQ('c','C',"center",value)) {
2084           W_L(" style=\"");
2085           W_L("text-align:center");
2086           W_L("\"");
2087         }
2088         break;
2089       }
2090     }
2091   }
2092   W_L(">");
2093   return xhtml->out;
2094 }
2095
2096
2097 /**
2098  * It is a handler who processes the H3 tag.
2099  *
2100  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2101  *                     destination is specified.
2102  * @param node   [i]   The H3 tag node is specified.
2103  * @return The conversion result is returned.
2104  */
2105 static char *
2106 s_xhtml_1_0_end_h3_tag(void *pdoc, Node *UNUSED(child)) 
2107 {
2108   xhtml_t *xhtml = GET_XHTML(pdoc);
2109   Doc     *doc   = xhtml->doc;
2110
2111   W_L("</h3>");
2112   return xhtml->out;
2113 }
2114
2115
2116 /**
2117  * It is a handler who processes the H4 tag.
2118  *
2119  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2120  *                     destination is specified.
2121  * @param node   [i]   The H4 tag node is specified.
2122  * @return The conversion result is returned.
2123  */
2124 static char *
2125 s_xhtml_1_0_start_h4_tag(void *pdoc, Node *node)
2126 {
2127   xhtml_t *xhtml = GET_XHTML(pdoc);
2128   Doc     *doc   = xhtml->doc;
2129   Attr    *attr;
2130
2131   W_L("<h4");
2132   for (attr = qs_get_attr(doc,node);
2133        attr;
2134        attr = qs_get_next_attr(doc,attr)) {
2135     char* name;
2136     char* value;
2137     name  = qs_get_attr_name(doc,attr);
2138     value = qs_get_attr_value(doc,attr);
2139     if (STRCASEEQ('a','A',"align", name)) {
2140       if (value) {
2141         if (STRCASEEQ('l','L',"left",value)) {
2142           W_L(" style=\"");
2143           W_L("text-align:left");
2144           W_L("\"");
2145         }
2146         else if (STRCASEEQ('r','R',"right",value)) {
2147           W_L(" style=\"");
2148           W_L("text-align:right");
2149           W_L("\"");
2150         }
2151         else if (STRCASEEQ('c','C',"center",value)) {
2152           W_L(" style=\"");
2153           W_L("text-align:center");
2154           W_L("\"");
2155         }
2156         break;
2157       }
2158     }
2159   }
2160   W_L(">");
2161   return xhtml->out;
2162 }
2163
2164
2165 /**
2166  * It is a handler who processes the H4 tag.
2167  *
2168  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2169  *                     destination is specified.
2170  * @param node   [i]   The H4 tag node is specified.
2171  * @return The conversion result is returned.
2172  */
2173 static char *
2174 s_xhtml_1_0_end_h4_tag(void *pdoc, Node *UNUSED(child)) 
2175 {
2176   xhtml_t *xhtml = GET_XHTML(pdoc);
2177   Doc     *doc   = xhtml->doc;
2178
2179   W_L("</h4>");
2180   return xhtml->out;
2181 }
2182
2183
2184 /**
2185  * It is a handler who processes the H5 tag.
2186  *
2187  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2188  *                     destination is specified.
2189  * @param node   [i]   The H5 tag node is specified.
2190  * @return The conversion result is returned.
2191  */
2192 static char *
2193 s_xhtml_1_0_start_h5_tag(void *pdoc, Node *node)
2194 {
2195   xhtml_t *xhtml = GET_XHTML(pdoc);
2196   Doc     *doc   = xhtml->doc;
2197   Attr    *attr;
2198
2199   W_L("<h5");
2200   for (attr = qs_get_attr(doc,node);
2201        attr;
2202        attr = qs_get_next_attr(doc,attr)) {
2203     char* name;
2204     char* value;
2205     name  = qs_get_attr_name(doc,attr);
2206     value = qs_get_attr_value(doc,attr);
2207     if (STRCASEEQ('a','A',"align", name)) {
2208       if (value) {
2209         if (STRCASEEQ('l','L',"left",value)) {
2210           W_L(" style=\"");
2211           W_L("text-align:left");
2212           W_L("\"");
2213         }
2214         else if (STRCASEEQ('r','R',"right",value)) {
2215           W_L(" style=\"");
2216           W_L("text-align:right");
2217           W_L("\"");
2218         }
2219         else if (STRCASEEQ('c','C',"center",value)) {
2220           W_L(" style=\"");
2221           W_L("text-align:center");
2222           W_L("\"");
2223         }
2224         break;
2225       }
2226     }
2227   }
2228   W_L(">");
2229   return xhtml->out;
2230 }
2231
2232
2233 /**
2234  * It is a handler who processes the H5 tag.
2235  *
2236  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2237  *                     destination is specified.
2238  * @param node   [i]   The H5 tag node is specified.
2239  * @return The conversion result is returned.
2240  */
2241 static char *
2242 s_xhtml_1_0_end_h5_tag(void *pdoc, Node *UNUSED(child)) 
2243 {
2244   xhtml_t *xhtml = GET_XHTML(pdoc);
2245   Doc     *doc   = xhtml->doc;
2246
2247   W_L("</h5>");
2248   return xhtml->out;
2249 }
2250
2251
2252 /**
2253  * It is a handler who processes the H6 tag.
2254  *
2255  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2256  *                     destination is specified.
2257  * @param node   [i]   The H6 tag node is specified.
2258  * @return The conversion result is returned.
2259  */
2260 static char *
2261 s_xhtml_1_0_start_h6_tag(void *pdoc, Node *node)
2262 {
2263   xhtml_t *xhtml = GET_XHTML(pdoc);
2264   Doc     *doc   = xhtml->doc;
2265   Attr    *attr;
2266
2267   W_L("<h6");
2268   for (attr = qs_get_attr(doc,node);
2269        attr;
2270        attr = qs_get_next_attr(doc,attr)) {
2271     char* name;
2272     char* value;
2273     name  = qs_get_attr_name(doc,attr);
2274     value = qs_get_attr_value(doc,attr);
2275     if (STRCASEEQ('a','A',"align", name)) {
2276       if (value) {
2277         if (STRCASEEQ('l','L',"left",value)) {
2278           W_L(" style=\"");
2279           W_L("text-align:left");
2280           W_L("\"");
2281         }
2282         else if (STRCASEEQ('r','R',"right",value)) {
2283           W_L(" style=\"");
2284           W_L("text-align:right");
2285           W_L("\"");
2286         }
2287         else if (STRCASEEQ('c','C',"center",value)) {
2288           W_L(" style=\"");
2289           W_L("text-align:center");
2290           W_L("\"");
2291         }
2292         break;
2293       }
2294     }
2295   }
2296   W_L(">");
2297   return xhtml->out;
2298 }
2299
2300
2301 /**
2302  * It is a handler who processes the H6 tag.
2303  *
2304  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2305  *                     destination is specified.
2306  * @param node   [i]   The H6 tag node is specified.
2307  * @return The conversion result is returned.
2308  */
2309 static char *
2310 s_xhtml_1_0_end_h6_tag(void *pdoc, Node *UNUSED(child)) 
2311 {
2312   xhtml_t *xhtml = GET_XHTML(pdoc);
2313   Doc     *doc   = xhtml->doc;
2314
2315   W_L("</h6>");
2316   return xhtml->out;
2317 }
2318
2319
2320 /**
2321  * It is a handler who processes the OL tag.
2322  *
2323  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2324  *                     destination is specified.
2325  * @param node   [i]   The OL tag node is specified.
2326  * @return The conversion result is returned.
2327  */
2328 static char *
2329 s_xhtml_1_0_start_ol_tag(void *pdoc, Node *node)
2330 {
2331   xhtml_t *xhtml = GET_XHTML(pdoc);
2332   Doc     *doc   = xhtml->doc;
2333   Attr    *attr;
2334
2335   W_L("<ol");
2336   /*--------------------------------------------------------------------------*/
2337   /* Get Attributes                                                           */
2338   /*--------------------------------------------------------------------------*/
2339   for (attr = qs_get_attr(doc,node);
2340        attr;
2341        attr = qs_get_next_attr(doc,attr)) {
2342     char *name = qs_get_attr_name(doc,attr);
2343     char *value = qs_get_attr_value(doc,attr);
2344     if (STRCASEEQ('t','T',"type",name) && value && (*value == '1' || *value == 'a' || *value == 'A')) {
2345       W_L(" type=\"");
2346       W_V(value);
2347       W_L("\"");
2348     }
2349     else if (STRCASEEQ('s','S',"start",name) && value && *value) {
2350       W_L(" start=\"");
2351       W_V(value);
2352       W_L("\"");
2353     }
2354   }
2355   W_L(">");
2356   return xhtml->out;
2357 }
2358
2359
2360 /**
2361  * It is a handler who processes the OL tag.
2362  *
2363  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2364  *                     destination is specified.
2365  * @param node   [i]   The OL tag node is specified.
2366  * @return The conversion result is returned.
2367  */
2368 static char *
2369 s_xhtml_1_0_end_ol_tag(void *pdoc, Node *UNUSED(child)) 
2370 {
2371   xhtml_t *xhtml = GET_XHTML(pdoc);
2372   Doc     *doc   = xhtml->doc;
2373
2374   W_L("</ol>");
2375   return xhtml->out;
2376 }
2377
2378
2379 /**
2380  * It is a handler who processes the LI tag.
2381  *
2382  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2383  *                     destination is specified.
2384  * @param node   [i]   The LI tag node is specified.
2385  * @return The conversion result is returned.
2386  */
2387 static char *
2388 s_xhtml_1_0_start_li_tag(void *pdoc, Node *node)
2389 {
2390   xhtml_t *xhtml = GET_XHTML(pdoc);
2391   Doc     *doc   = xhtml->doc;
2392   Attr    *attr;
2393
2394   W_L("<li");
2395   /*--------------------------------------------------------------------------*/
2396   /* Get Attributes                                                           */
2397   /*--------------------------------------------------------------------------*/
2398   for (attr = qs_get_attr(doc,node);
2399        attr;
2400        attr = qs_get_next_attr(doc,attr)) {
2401     char *name  = qs_get_attr_name(doc,attr);
2402     char *value = qs_get_attr_value(doc,attr);
2403     if (STRCASEEQ('t','T',"type",name)) {
2404       if (value && (*value == '1' || *value == 'a' || *value == 'A' || STRCASEEQ('d','D',"disc",value) || STRCASEEQ('c','C',"circle",value) || STRCASEEQ('s','S',"square",value))) {
2405         W_L(" type=\"");
2406         W_V(value);
2407         W_L("\"");
2408       }
2409     }
2410     else if (STRCASEEQ('v','V',"value", name) && value && *value) {
2411       W_L(" value=\"");
2412       W_V(value);
2413       W_L("\"");
2414     }
2415   }
2416   W_L(">");
2417   return xhtml->out;
2418 }
2419
2420
2421 /**
2422  ** It is a handler who processes the LI tag.
2423  *
2424  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2425  *                     destination is specified.
2426  * @param node   [i]   The LI tag node is specified.
2427  * @return The conversion result is returned.
2428  */
2429 static char *
2430 s_xhtml_1_0_end_li_tag(void *pdoc, Node *UNUSED(child)) 
2431 {
2432   xhtml_t *xhtml = GET_XHTML(pdoc);
2433   Doc     *doc   = xhtml->doc;
2434
2435   W_L("</li>");
2436   return xhtml->out;
2437 }
2438
2439 /**
2440  * It is a handler who processes the IMG tag.
2441  *
2442  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2443  *                     destination is specified.
2444  * @param node   [i]   The IMG tag node is specified.
2445  * @return The conversion result is returned.
2446  */
2447 static char *
2448 s_xhtml_1_0_start_img_tag(void *pdoc, Node *node) 
2449 {
2450   xhtml_t       *xhtml = GET_XHTML(pdoc);
2451   Doc           *doc   = xhtml->doc;
2452   request_rec   *r     = doc->r;
2453   Attr          *attr;
2454
2455 #ifndef IMG_NOT_CONVERT_FILENAME
2456   device_table  *spec = xhtml->spec;
2457 #endif
2458
2459   W_L("<img");
2460   /*--------------------------------------------------------------------------*/
2461   /* Get Attributes                                                           */
2462   /*--------------------------------------------------------------------------*/
2463   for (attr = qs_get_attr(doc,node);
2464        attr;
2465        attr = qs_get_next_attr(doc,attr)) {
2466     char *name  = qs_get_attr_name(doc,attr);
2467     char *value = qs_get_attr_value(doc,attr);
2468
2469     if (STRCASEEQ('s','S',"src",name)) {
2470       value = chxj_encoding_parameter(r, value);
2471       value = chxj_add_cookie_parameter(r, value, xhtml->cookie);
2472       value = chxj_add_cookie_no_update_parameter(r, value);
2473 #ifdef IMG_NOT_CONVERT_FILENAME
2474
2475       W_L(" src=\"");
2476       W_V(value);
2477       W_L("\"");
2478
2479 #else
2480
2481       W_L(" src=\"");
2482       {
2483         char *vv = chxj_img_conv(r,spec,value);
2484         W_V(vv);
2485       }
2486       W_L("\"");
2487
2488 #endif
2489     }
2490     else 
2491     if (STRCASEEQ('a','A',"align",name)) {
2492       if (value) {
2493         if (STRCASEEQ('t','T',"top",   value) ||
2494             STRCASEEQ('m','M',"middle",value) ||
2495             STRCASEEQ('b','B',"bottom",value) ||
2496             STRCASEEQ('l','L',"left",  value) ||
2497             STRCASEEQ('r','R',"right", value)) {
2498           W_L(" align=\"");
2499           W_V(value);
2500           W_L("\"");
2501         }
2502         else if (STRCASEEQ('c','C',"center",  value)) {
2503           W_L(" align=\"");
2504           W_L("middle");
2505           W_L("\"");
2506         }
2507       }
2508     }
2509     else if (STRCASEEQ('a','A',"alt",name) && value && *value) {
2510       W_L(" alt=\"");
2511       W_V(value);
2512       W_L("\"");
2513     }
2514     else if (STRCASEEQ('w','W',"width",name) && value && *value) {
2515       W_L(" width=\"");
2516       W_V(value);
2517       W_L("\"");
2518     }
2519     else if (STRCASEEQ('h','H',"height",name) && value && *value) {
2520       W_L(" height=\"");
2521       W_V(value);
2522       W_L("\"");
2523     }
2524     else if (STRCASEEQ('h','H',"hspace",name) && value && *value) {
2525       W_L(" hspace=\"");
2526       W_V(value);
2527       W_L("\"");
2528     }
2529     else if (STRCASEEQ('v','V',"vspace",name) && value && *value) {
2530       W_L(" vspace=\"");
2531       W_V(value);
2532       W_L("\"");
2533     }
2534   }
2535   W_L(" />");
2536   return xhtml->out;
2537 }
2538
2539
2540 /**
2541  * It is a handler who processes the IMG tag.
2542  *
2543  * @param xhtml  [i/o] The pointer to the XHTML structure at the output
2544  *                     destination is specified.
2545  * @param node   [i]   The IMG tag node is specified.
2546  * @return The conversion result is returned.
2547  */
2548 static char *
2549 s_xhtml_1_0_end_img_tag(void *pdoc, Node *UNUSED(child)) 
2550 {
2551   xhtml_t *xhtml = GET_XHTML(pdoc);
2552
2553   return xhtml->out;
2554 }
2555
2556
2557 /**
2558  * It is a handler who processes the SELECT tag.
2559  *
2560  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2561  *                     destination is specified.
2562  * @param node   [i]   The SELECT tag node is specified.
2563  * @return The conversion result is returned.
2564  */
2565 static char *
2566 s_xhtml_1_0_start_select_tag(void *pdoc, Node *child)
2567 {
2568   xhtml_t *xhtml    = GET_XHTML(pdoc);
2569   Doc     *doc      = xhtml->doc;
2570   char    *size     = NULL;
2571   char    *name     = NULL;
2572   char    *multiple = NULL;
2573   Attr    *attr;
2574
2575
2576   W_L("<select");
2577   for (attr = qs_get_attr(doc,child);
2578        attr;
2579        attr = qs_get_next_attr(doc,attr)) {
2580     char *nm  = qs_get_attr_name(doc,attr);
2581     char *val = qs_get_attr_value(doc,attr);
2582     if (STRCASEEQ('s','S',"size",nm)) {
2583       /*----------------------------------------------------------------------*/
2584       /* CHTML 1.0 version 2.0                                                */
2585       /*----------------------------------------------------------------------*/
2586       size = apr_pstrdup(doc->buf.pool, val);
2587     }
2588     else if (STRCASEEQ('n','N',"name",nm)) {
2589       /*----------------------------------------------------------------------*/
2590       /* CHTML 1.0 version 2.0                                                */
2591       /*----------------------------------------------------------------------*/
2592       name = apr_pstrdup(doc->buf.pool, val);
2593     }
2594     else if (STRCASEEQ('m','M',"multiple",nm)) {
2595       /*----------------------------------------------------------------------*/
2596       /* CHTML 1.0 version 2.0                                                */
2597       /*----------------------------------------------------------------------*/
2598       multiple = apr_pstrdup(doc->buf.pool, val);
2599     }
2600   }
2601   if (size && *size) {
2602     W_L(" size=\"");
2603     W_V(size);
2604     W_L("\"");
2605   }
2606   if (name && *name) {
2607     W_L(" name=\"");
2608     W_V(name);
2609     W_L("\"");
2610   }
2611   if (multiple) {
2612     /* "true" is *NOT* W3C. it is specification of WAP2.0 for EZWEB */
2613     W_L(" multiple=\"true\"");
2614   }
2615   W_L(">");
2616   return xhtml->out;
2617 }
2618
2619
2620 /**
2621  * It is a handler who processes the SELECT tag.
2622  *
2623  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2624  *                     destination is specified.
2625  * @param node   [i]   The SELECT tag node is specified.
2626  * @return The conversion result is returned.
2627  */
2628 static char *
2629 s_xhtml_1_0_end_select_tag(void *pdoc, Node *UNUSED(child))
2630 {
2631   xhtml_t *xhtml = GET_XHTML(pdoc);
2632   Doc     *doc   = xhtml->doc;
2633
2634   W_L("</select>");
2635   return xhtml->out;
2636 }
2637
2638
2639 /**
2640  * It is a handler who processes the OPTION tag.
2641  *
2642  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2643  *                     destination is specified.
2644  * @param node   [i]   The OPTION tag node is specified.
2645  * @return The conversion result is returned.
2646  */
2647 static char *
2648 s_xhtml_1_0_start_option_tag(void *pdoc, Node *child)
2649 {
2650   xhtml_t *xhtml = GET_XHTML(pdoc);
2651   Doc     *doc   = xhtml->doc;
2652   Attr    *attr;
2653
2654   char *selected   = NULL;
2655   char *value      = NULL;
2656
2657   W_L("<option");
2658   for (attr = qs_get_attr(doc,child);
2659        attr;
2660        attr = qs_get_next_attr(doc,attr)) {
2661     char *nm  = qs_get_attr_name(doc,attr);
2662     char *val = qs_get_attr_value(doc,attr);
2663     if (STRCASEEQ('s','S',"selected",nm)) {
2664       /* CHTML version 2.0 */
2665       selected = apr_pstrdup(doc->buf.pool, val);
2666     }
2667     else if (STRCASEEQ('v','V',"value",nm)) {
2668       /* CHTML version 2.0 */
2669       value = apr_pstrdup(doc->buf.pool, val);
2670     }
2671   }
2672   if (value) {
2673     W_L(" value=\"");
2674     W_V(value);
2675     W_L("\"");
2676   }
2677   if (selected) {
2678     W_L(" selected=\"selected\"");
2679   }
2680   W_L(">");
2681   return xhtml->out;
2682 }
2683
2684
2685 /**
2686  * It is a handler who processes the OPTION tag.
2687  *
2688  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2689  *                     destination is specified.
2690  * @param node   [i]   The OPTION tag node is specified.
2691  * @return The conversion result is returned.
2692  */
2693 static char *
2694 s_xhtml_1_0_end_option_tag(void *pdoc, Node *UNUSED(child))
2695 {
2696   xhtml_t *xhtml = GET_XHTML(pdoc);
2697   Doc     *doc   = xhtml->doc;
2698
2699   W_L("</option>");
2700   return xhtml->out;
2701 }
2702
2703
2704 /**
2705  * It is a handler who processes the DIV tag.
2706  *
2707  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2708  *                     destination is specified.
2709  * @param node   [i]   The DIV tag node is specified.
2710  * @return The conversion result is returned.
2711  */
2712 static char *
2713 s_xhtml_1_0_start_div_tag(void *pdoc, Node *child)
2714 {
2715   xhtml_t *xhtml = GET_XHTML(pdoc);
2716   Doc     *doc   = xhtml->doc;
2717   Attr    *attr;
2718   char    *align   = NULL;
2719
2720   W_L("<div");
2721   for (attr = qs_get_attr(doc,child);
2722        attr;
2723        attr = qs_get_next_attr(doc,attr)) {
2724     char *nm  = qs_get_attr_name(doc,attr);
2725     char *val = qs_get_attr_value(doc,attr);
2726     if (STRCASEEQ('a','A',"align",nm)) {
2727       /*=====================================================================*/
2728       /* CHTML version 3.2                                                   */
2729       /*=====================================================================*/
2730       if (val && (STRCASEEQ('l','L',"left",val) || STRCASEEQ('r','R',"right",val) || STRCASEEQ('c','C',"center",val))) {
2731         align = apr_pstrdup(doc->buf.pool, val);
2732       }
2733     }
2734   }
2735   if (align) {
2736     W_L(" align=\"");
2737     W_V(align);
2738     W_L("\"");
2739   }
2740   W_L(">");
2741   return xhtml->out;
2742 }
2743
2744
2745 /**
2746  * It is a handler who processes the DIV tag.
2747  *
2748  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2749  *                     destination is specified.
2750  * @param node   [i]   The DIV tag node is specified.
2751  * @return The conversion result is returned.
2752  */
2753 static char *
2754 s_xhtml_1_0_end_div_tag(void *pdoc, Node *UNUSED(child))
2755 {
2756   xhtml_t *xhtml = GET_XHTML(pdoc);
2757   Doc     *doc   = xhtml->doc;
2758   W_L("</div>");
2759   return xhtml->out;
2760 }
2761
2762
2763 /**
2764  * It is a handler who processes the B tag.
2765  *
2766  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2767  *                     destination is specified.
2768  * @param node   [i]   The B tag node is specified.
2769  * @return The conversion result is returned.
2770  */
2771 static char *
2772 s_xhtml_1_0_start_b_tag(void *pdoc, Node *UNUSED(child))
2773 {
2774   xhtml_t *xhtml = GET_XHTML(pdoc);
2775   Doc     *doc   = xhtml->doc;
2776
2777   W_L("<div style=\"font-weight:bold\">");
2778   return xhtml->out;
2779 }
2780
2781
2782 /**
2783  * It is a handler who processes the B tag.
2784  *
2785  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2786  *                     destination is specified.
2787  * @param node   [i]   The B tag node is specified.
2788  * @return The conversion result is returned.
2789  */
2790 static char *
2791 s_xhtml_1_0_end_b_tag(void *pdoc, Node *UNUSED(child))
2792 {
2793   xhtml_t *xhtml = GET_XHTML(pdoc);
2794   Doc     *doc   = xhtml->doc;
2795
2796   W_L("</div>");
2797   return xhtml->out;
2798 }
2799
2800
2801 /**
2802  * It is a handler who processes the CHXJ:IF tag.
2803  *
2804  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2805  *                     destination is specified.
2806  * @param node   [i]   The CHXJ:IF tag node is specified.
2807  */
2808 static char *
2809 s_xhtml_1_0_chxjif_tag(void *pdoc, Node *node)
2810 {
2811   xhtml_t      *xhtml = GET_XHTML(pdoc);
2812   Doc          *doc   = xhtml->doc;
2813   Node         *child;
2814
2815   for (child = qs_get_child_node(doc, node);
2816        child;
2817        child = qs_get_next_node(doc, child)) {
2818     W_V(child->otext);
2819     s_xhtml_1_0_chxjif_tag(xhtml, child);
2820   }
2821
2822   return NULL;
2823 }
2824
2825
2826 /**
2827  * It is a handler who processes the TEXTARE tag.
2828  *
2829  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2830  *                     destination is specified.
2831  * @param node   [i]   The TEXTAREA tag node is specified.
2832  * @return The conversion result is returned.
2833  */
2834 static char *
2835 s_xhtml_1_0_start_textarea_tag(void *pdoc, Node *node) 
2836 {
2837   xhtml_t *xhtml = GET_XHTML(pdoc);
2838   Doc     *doc   = xhtml->doc;
2839   Attr    *attr;
2840
2841   xhtml->textarea_flag++;
2842   W_L("<textarea");
2843   for (attr = qs_get_attr(doc,node);
2844        attr;
2845        attr = qs_get_next_attr(doc,attr)) {
2846     char *name  = qs_get_attr_name(doc,attr);
2847     char *value = qs_get_attr_value(doc,attr);
2848     if (STRCASEEQ('n','N',"name",name) && value && *value) {
2849       W_L(" name=\"");
2850       W_V(value);
2851       W_L("\"");
2852     }
2853     else if (STRCASEEQ('r','R',"rows",name) && value && *value) {
2854       W_L(" rows=\"");
2855       W_V(value);
2856       W_L("\"");
2857     }
2858     else if (STRCASEEQ('c','C',"cols",name) && value && *value) {
2859       W_L(" cols=\"");
2860       W_V(value);
2861       W_L("\"");
2862     }
2863     else if (STRCASEEQ('i','I',"istyle", name) && value && (*value == '1' || *value == '2' || *value == '3' || *value == '4')) {
2864       char *fmt = qs_conv_istyle_to_format(doc->r,value);
2865       W_L(" FORMAT=\"*");
2866       W_V(fmt);
2867       W_L("\"");
2868     }
2869     else if (STRCASEEQ('a','A',"accesskey",name) && value && *value != 0) {
2870       W_L(" accesskey=\"");
2871       W_V(value);
2872       W_L("\"");
2873     }
2874   }
2875   W_L(">");
2876   return xhtml->out;
2877 }
2878
2879
2880 /**
2881  * It is a handler who processes the TEXTAREA tag.
2882  *
2883  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2884  *                     destination is specified.
2885  * @param node   [i]   The TEXTAREA tag node is specified.
2886  * @return The conversion result is returned.
2887  */
2888 static char *
2889 s_xhtml_1_0_end_textarea_tag(void *pdoc, Node *UNUSED(child)) 
2890 {
2891   xhtml_t *xhtml = GET_XHTML(pdoc);
2892   Doc     *doc   = xhtml->doc;
2893
2894   W_L("</textarea>");
2895   xhtml->textarea_flag--;
2896
2897   return xhtml->out;
2898 }
2899
2900 static char *
2901 s_xhtml_1_0_text_tag(void *pdoc, Node *child)
2902 {
2903   xhtml_t     *xhtml   = GET_XHTML(pdoc);
2904   Doc         *doc     = xhtml->doc;
2905   request_rec *r       = doc->r;
2906   char        *textval;
2907   char        *tmp;
2908   char        *tdst;
2909   char        one_byte[2];
2910   int         ii;
2911   int         tdst_len;
2912   apr_size_t  z2h_input_len;
2913   
2914   textval = qs_get_node_value(doc,child);
2915   if (strlen(textval) == 0) {
2916     return xhtml->out;
2917   }
2918   
2919   tmp = apr_palloc(r->pool, qs_get_node_size(doc,child)+1);
2920   memset(tmp, 0, qs_get_node_size(doc,child)+1);
2921   
2922   tdst     = qs_alloc_zero_byte_string(doc->buf.pool);
2923   memset(one_byte, 0, sizeof(one_byte));
2924   tdst_len = 0;
2925   
2926   for (ii=0; ii<qs_get_node_size(doc,child); ii++) {
2927     char *out;
2928     int rtn = s_xhtml_search_emoji(xhtml, &textval[ii], &out);
2929     if (rtn != 0) {
2930       DBG(r,"REQ[%X] [%s][%d]", TO_ADDR(r), out, rtn);
2931       tdst = qs_out_apr_pstrcat(r, tdst, out, &tdst_len);
2932       ii+=(rtn - 1);
2933       continue;
2934     }
2935     if (is_sjis_kanji(textval[ii])) {
2936       one_byte[0] = textval[ii+0];
2937       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2938       one_byte[0] = textval[ii+1];
2939       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2940       ii++;
2941     }
2942     else if (xhtml->pre_flag) {
2943       one_byte[0] = textval[ii+0];
2944       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2945     }
2946     else if (xhtml->textarea_flag) {
2947       one_byte[0] = textval[ii+0];
2948       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2949     }
2950     else if (textval[ii] != '\r' && textval[ii] != '\n') {
2951       one_byte[0] = textval[ii+0];
2952       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2953     }
2954   }
2955   z2h_input_len = strlen(tdst);
2956   tdst = chxj_conv_z2h(r, tdst, &z2h_input_len, xhtml->entryp);
2957
2958   W_V(tdst);
2959   return xhtml->out;
2960 }
2961
2962
2963 /**
2964  * It is a handler who processes the BLOCKQUOTE tag.
2965  *
2966  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2967  *                     destination is specified.
2968  * @param node   [i]   The BLOCKQUOTE tag node is specified.
2969  * @return The conversion result is returned.
2970  */
2971 static char *
2972 s_xhtml_1_0_start_blockquote_tag(void *pdoc, Node *UNUSED(child))
2973 {
2974   xhtml_t *xhtml = GET_XHTML(pdoc);
2975   Doc     *doc   = xhtml->doc;
2976   W_L("<blockquote>");
2977   return xhtml->out;
2978 }
2979
2980
2981 /**
2982  * It is a handler who processes the BLOCKQUOTE tag.
2983  *
2984  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2985  *                     destination is specified.
2986  * @param node   [i]   The BLOCKQUOTE tag node is specified.
2987  * @return The conversion result is returned.
2988  */
2989 static char *
2990 s_xhtml_1_0_end_blockquote_tag(void *pdoc, Node *UNUSED(child))
2991 {
2992   xhtml_t *xhtml = GET_XHTML(pdoc);
2993   Doc     *doc   = xhtml->doc;
2994   W_L("</blockquote>");
2995   return xhtml->out;
2996 }
2997
2998
2999 /**
3000  * It is a handler who processes the DIR tag.
3001  *
3002  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
3003  *                     destination is specified.
3004  * @param node   [i]   The DIR tag node is specified.
3005  * @return The conversion result is returned.
3006  */
3007 static char *
3008 s_xhtml_1_0_start_dir_tag(void *pdoc, Node *node)
3009 {
3010   xhtml_t *xhtml = GET_XHTML(pdoc);
3011   Doc     *doc = xhtml->doc;
3012   Attr      *attr;
3013   W_L("<dir");
3014   for (attr = qs_get_attr(doc,node);
3015        attr;
3016        attr = qs_get_next_attr(doc,attr)) {
3017     char *name   = qs_get_attr_name(doc,attr);
3018     char *value  = qs_get_attr_value(doc,attr);
3019     if (STRCASEEQ('t','T',"type",name)) {
3020       if (value && (STRCASEEQ('d','D',"disc",value) || STRCASEEQ('c','C',"circle",value) || STRCASEEQ('s','S',"square",value))) {
3021         W_L(" type=\"");
3022         W_V(value);
3023         W_L("\"");
3024       }
3025     }
3026   }
3027   W_L(">");
3028   return xhtml->out;
3029 }
3030
3031
3032 /**
3033  * It is a handler who processes the DIR tag.
3034  *
3035  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
3036  *                     destination is specified.
3037  * @param node   [i]   The DIR tag node is specified.
3038  * @return The conversion result is returned.
3039  */
3040 static char *
3041 s_xhtml_1_0_end_dir_tag(void *pdoc, Node *UNUSED(child))
3042 {
3043   xhtml_t *xhtml = GET_XHTML(pdoc);
3044   Doc     *doc = xhtml->doc;
3045   W_L("</dir>");
3046   return xhtml->out;
3047 }
3048
3049
3050 /**
3051  * It is a handler who processes the DL tag.
3052  *
3053  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
3054  *                     destination is specified.
3055  * @param node   [i]   The DL tag node is specified.
3056  * @return The conversion result is returned.
3057  */
3058 static char *
3059 s_xhtml_1_0_start_dl_tag(void *pdoc, Node *UNUSED(child))
3060 {
3061   xhtml_t *xhtml = GET_XHTML(pdoc);
3062   Doc *doc = xhtml->doc;
3063   W_L("<dl>");
3064   return xhtml->out;
3065 }
3066
3067
3068 /**
3069  * It is a handler who processes the DL tag.
3070  *
3071  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
3072  *                     destination is specified.
3073  * @param node   [i]   The DL tag node is specified.
3074  * @return The conversion result is returned.
3075  */
3076 static char *
3077 s_xhtml_1_0_end_dl_tag(void *pdoc, Node *UNUSED(child))
3078 {
3079   xhtml_t *xhtml = GET_XHTML(pdoc);
3080   Doc *doc = xhtml->doc;
3081   W_L("</dl>");
3082   return xhtml->out;
3083 }
3084
3085
3086 /**
3087  * It is a handter who processes the DT tag.
3088  *
3089  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
3090  *                     destination is specified.
3091  * @param node   [i]   The DT tag node is specified.
3092  * @return The conversion result is returned.
3093  */
3094 static char *
3095 s_xhtml_1_0_start_dt_tag(void *pdoc, Node *UNUSED(child))
3096 {
3097   xhtml_t *xhtml = GET_XHTML(pdoc);
3098   Doc     *doc   = xhtml->doc;
3099   W_L("<dt>");
3100   return xhtml->out;
3101 }
3102
3103
3104 /**
3105  * It is a handter who processes the DT tag.
3106  *
3107  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
3108  *                     destination is specified.
3109  * @param node   [i]   The DT tag node is specified.
3110  * @return The conversion result is returned.
3111  */
3112 static char *
3113 s_xhtml_1_0_end_dt_tag(void *pdoc, Node *UNUSED(child))
3114 {
3115   xhtml_t *xhtml = GET_XHTML(pdoc);
3116   Doc     *doc   = xhtml->doc;
3117   W_L("</dt>");
3118   return xhtml->out;
3119 }
3120
3121
3122 /**
3123  * It is a handder who processes the DD tag.
3124  *
3125  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
3126  *                     destination is specified.
3127  * @param node   [i]   The DD tag node is specified.
3128  * @return The conversion result is returned.
3129  */
3130 static char *
3131 s_xhtml_1_0_start_dd_tag(void *pdoc, Node *UNUSED(child))
3132 {
3133   xhtml_t *xhtml = GET_XHTML(pdoc);
3134   Doc     *doc   = xhtml->doc;
3135   W_L("<dd>");
3136   return xhtml->out;
3137 }
3138
3139
3140 /**
3141  * It is a handder who processes the DD tag.
3142  *
3143  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
3144  *                     destination is specified.
3145  * @param node   [i]   The DD tag node is specified.
3146  * @return The conversion result is returned.
3147  */
3148 static char *
3149 s_xhtml_1_0_end_dd_tag(void *pdoc, Node *UNUSED(child))
3150 {
3151   xhtml_t *xhtml = GET_XHTML(pdoc);
3152   Doc     *doc   = xhtml->doc;
3153   W_L("</dd>");
3154   return xhtml->out;
3155 }
3156
3157
3158 /**
3159  * It is a handler who processes the MENU tag.
3160  *
3161  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
3162  *                     destination is specified.
3163  * @param node   [i]   The MENU tag node is specified.
3164  * @return The conversion result is returned.
3165  */
3166 static char *
3167 s_xhtml_1_0_start_menu_tag(void *pdoc, Node *node)
3168 {
3169   xhtml_t *xhtml = GET_XHTML(pdoc);
3170   Doc     *doc   = xhtml->doc;
3171   Attr    *attr;
3172   W_L("<menu");
3173   /*--------------------------------------------------------------------------*/
3174   /* Get Attributes                                                           */
3175   /*--------------------------------------------------------------------------*/
3176   for (attr = qs_get_attr(doc,node);
3177        attr;
3178        attr = qs_get_next_attr(doc,attr)) {
3179     char *name   = qs_get_attr_name(doc,attr);
3180     char *value  = qs_get_attr_value(doc,attr);
3181     if (STRCASEEQ('t','T',"type",name)) {
3182       if (value && (STRCASEEQ('d','D',"disc",value) || STRCASEEQ('c','C',"circle",value) || STRCASEEQ('s','S',"square",value))) {
3183         W_L(" type=\"");
3184         W_V(value);
3185         W_L("\"");
3186       }
3187     }
3188   }
3189   W_L(">");
3190   return xhtml->out;
3191 }
3192
3193
3194 /**
3195  * It is a hanmenuer who processes the MENU tag.
3196  *
3197  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
3198  *                     destination is specified.
3199  * @param node   [i]   The MENU tag node is specified.
3200  * @return The conversion result is returned.
3201  */
3202 static char *
3203 s_xhtml_1_0_end_menu_tag(void *pdoc, Node *UNUSED(child))
3204 {
3205   xhtml_t *xhtml = GET_XHTML(pdoc);
3206   Doc *doc = xhtml->doc;
3207   W_L("</menu>");
3208   return xhtml->out;
3209 }
3210
3211
3212 /**
3213  * It is a handler who processes the PLAINTEXT tag.
3214  *
3215  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
3216  *                     destination is specified.
3217  * @param node   [i]   The PLAINTEXT tag node is specified.
3218  * @return The conversion result is returned.
3219  */
3220 static char *
3221 s_xhtml_1_0_start_plaintext_tag(void *pdoc, Node *node)
3222 {
3223   xhtml_t *xhtml = GET_XHTML(pdoc);
3224   Doc     *doc     = xhtml->doc;
3225   W_L("<plaintext>");
3226   s_xhtml_1_0_start_plaintext_tag_inner(pdoc,node);
3227   return xhtml->out;
3228 }
3229
3230 static char *
3231 s_xhtml_1_0_start_plaintext_tag_inner(void *pdoc, Node *node)
3232 {
3233   xhtml_t *xhtml = GET_XHTML(pdoc);
3234   Doc     *doc     = xhtml->doc;
3235   Node    *child;
3236   for (child = qs_get_child_node(doc, node);
3237        child;
3238        child = qs_get_next_node(doc, child)) {
3239     W_V(child->otext);
3240     s_xhtml_1_0_start_plaintext_tag_inner(pdoc, child);
3241   }
3242   return xhtml->out;
3243 }
3244
3245
3246 /**
3247  * It is a handler who processes the PLAINTEXT tag.
3248  *
3249  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
3250  *                     destination is specified.
3251  * @param node   [i]   The PLAINTEXT tag node is specified.
3252  * @return The conversion result is returned.
3253  */
3254 static char *
3255 s_xhtml_1_0_end_plaintext_tag(void *pdoc, Node *UNUSED(child))
3256 {
3257   xhtml_t *xhtml = GET_XHTML(pdoc);
3258   Doc     *doc     = xhtml->doc;
3259   W_L("</plaintext>");
3260   return xhtml->out;
3261 }
3262
3263
3264 /**
3265  * It is a hanblinker who processes the BLINK tag.
3266  *
3267  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
3268  *                     destination is specified.
3269  * @param node   [i]   The BLINK tag node is specified.
3270  * @return The conversion result is returned.
3271  */
3272 static char *
3273 s_xhtml_1_0_start_blink_tag(void *pdoc, Node *UNUSED(child))
3274 {
3275   xhtml_t *xhtml = GET_XHTML(pdoc);
3276   Doc     *doc = xhtml->doc;
3277   W_L("<blink>");
3278   return xhtml->out;
3279 }
3280
3281
3282 /**
3283  * It is a hanblinker who processes the BLINK tag.
3284  *
3285  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
3286  *                     destination is specified.
3287  * @param node   [i]   The BLINK tag node is specified.
3288  * @return The conversion result is returned.
3289  */
3290 static char *
3291 s_xhtml_1_0_end_blink_tag(void *pdoc, Node *UNUSED(child))
3292 {
3293   xhtml_t *xhtml = GET_XHTML(pdoc);
3294   Doc     *doc = xhtml->doc;
3295   W_L("</blink>");
3296   return xhtml->out;
3297 }
3298
3299
3300 /**
3301  * It is a handler who processes the MARQUEE tag.
3302  *
3303  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
3304  *                     destination is specified.
3305  * @param node   [i]   The MARQUEE tag node is specified.
3306  * @return The conversion result is returned.
3307  */
3308 static char *
3309 s_xhtml_1_0_start_marquee_tag(void *pdoc, Node *node)
3310 {
3311   xhtml_t *xhtml = GET_XHTML(pdoc);
3312   Doc     *doc = xhtml->doc;
3313   Attr *attr;
3314   W_L("<marquee");
3315   /*--------------------------------------------------------------------------*/
3316   /* Get Attributes                                                           */
3317   /*--------------------------------------------------------------------------*/
3318   for (attr = qs_get_attr(doc,node);
3319        attr;
3320        attr = qs_get_next_attr(doc,attr)) {
3321     char *name   = qs_get_attr_name(doc,attr);
3322     char *value  = qs_get_attr_value(doc,attr);
3323     if (STRCASEEQ('d','D',"direction", name)) {
3324       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value))) {
3325         W_L(" direction=\"");
3326         W_V(value);
3327         W_L("\"");
3328       }
3329     }
3330     else if (STRCASEEQ('b','B',"behavior",name)) {
3331       if (value && (STRCASEEQ('s','S',"scroll",value) || STRCASEEQ('s','S',"slide",value) || STRCASEEQ('a','A',"alternate",value))) {
3332         W_L(" behavior=\""); 
3333         W_V(value);
3334         W_L("\"");
3335       }
3336     }
3337     else if (STRCASEEQ('l','L',"loop",name)) {
3338       if (value && *value) {
3339         W_L(" loop=\"");
3340         W_V(value);
3341         W_L("\"");
3342       }
3343     }
3344     else if (STRCASEEQ('b','B',"bgcolor",name)) {
3345       if (value && *value) {
3346         W_L(" bgcolor=\"");
3347         W_V(value);
3348         W_L("\"");
3349       }
3350     }
3351   }
3352   W_L(">");
3353   return xhtml->out;
3354 }
3355
3356
3357 /**
3358  * It is a handler who processes the MARQUEE tag.
3359  *
3360  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
3361  *                     destination is specified.
3362  * @param node   [i]   The MARQUEE tag node is specified.
3363  * @return The conversion result is returned.
3364  */
3365 static char *
3366 s_xhtml_1_0_end_marquee_tag(void *pdoc, Node *UNUSED(child))
3367 {
3368   xhtml_t *xhtml = GET_XHTML(pdoc);
3369   Doc     *doc = xhtml->doc;
3370   W_L("</marquee>");
3371   return xhtml->out;
3372 }
3373
3374
3375 /**
3376  * It is handler who processes the New Line Code.
3377  */
3378 static char *
3379 s_xhtml_1_0_newline_mark(void *pdoc, Node *UNUSED(node))
3380 {
3381   xhtml_t *xhtml = GET_XHTML(pdoc);
3382   Doc *doc = xhtml->doc;
3383   W_NLCODE();
3384   return xhtml->out;
3385 }
3386 /*
3387  * vim:ts=2 et
3388  */