OSDN Git Service

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