OSDN Git Service

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