OSDN Git Service

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