OSDN Git Service

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