OSDN Git Service

766d55a34b736b185cfcf3c7f33522dbc4b812e3
[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   chtml30->out = apr_pstrcat(r->pool, chtml30->out, ">", NULL);
1105
1106   return chtml30->out;
1107 }
1108
1109
1110 /**
1111  * It is a handler who processes the A tag.
1112  *
1113  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1114  *                     destination is specified.
1115  * @param node   [i]   The A tag node is specified.
1116  * @return The conversion result is returned.
1117  */
1118 static char*
1119 s_chtml30_end_a_tag(void* pdoc, Node* child) 
1120 {
1121   chtml30_t*    chtml30;
1122   Doc*          doc;
1123   request_rec*  r;
1124
1125   chtml30 = GET_CHTML30(pdoc);
1126   doc     = chtml30->doc;
1127   r       = doc->r;
1128
1129   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "</a>", NULL);
1130
1131   return chtml30->out;
1132 }
1133
1134
1135 /**
1136  * It is a handler who processes the BR tag.
1137  *
1138  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1139  *                     destination is specified.
1140  * @param node   [i]   The BR tag node is specified.
1141  * @return The conversion result is returned.
1142  */
1143 static char*
1144 s_chtml30_start_br_tag(void* pdoc, Node* node) 
1145 {
1146   chtml30_t*    chtml30;
1147   Doc*          doc;
1148   request_rec*  r;
1149
1150   chtml30 = GET_CHTML30(pdoc);
1151   doc     = chtml30->doc;
1152   r       = doc->r;
1153
1154   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<br>\r\n", NULL);
1155
1156   return chtml30->out;
1157 }
1158
1159
1160 /**
1161  * It is a handler who processes the BR tag.
1162  *
1163  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1164  *                     destination is specified.
1165  * @param node   [i]   The BR tag node is specified.
1166  * @return The conversion result is returned.
1167  */
1168 static char*
1169 s_chtml30_end_br_tag(void* pdoc, Node* child) 
1170 {
1171   chtml30_t*    chtml30;
1172
1173   chtml30 = GET_CHTML30(pdoc);
1174
1175   return chtml30->out;
1176 }
1177
1178
1179 /**
1180  * It is a handler who processes the TR tag.
1181  *
1182  * @param chtml30  [i/o] The pointer to the CHTML structure at the output
1183  *                     destination is specified.
1184  * @param node   [i]   The TR tag node is specified.
1185  * @return The conversion result is returned.
1186  */
1187 static char*
1188 s_chtml30_start_tr_tag(void* pdoc, Node* node) 
1189 {
1190   chtml30_t*    chtml30;
1191
1192   chtml30 = GET_CHTML30(pdoc);
1193
1194   return chtml30->out;
1195 }
1196
1197
1198 /**
1199  * It is a handler who processes the TR tag.
1200  *
1201  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1202  *                     destination is specified.
1203  * @param node   [i]   The TR tag node is specified.
1204  * @return The conversion result is returned.
1205  */
1206 static char*
1207 s_chtml30_end_tr_tag(void* pdoc, Node* child) 
1208 {
1209   chtml30_t*    chtml30;
1210   Doc*          doc;
1211   request_rec*  r;
1212
1213   chtml30 = GET_CHTML30(pdoc);
1214   doc     = chtml30->doc;
1215   r       = doc->r;
1216
1217   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<br>\r\n", NULL);
1218
1219   return chtml30->out;
1220 }
1221
1222
1223 /**
1224  * It is a handler who processes the FONT tag.
1225  *
1226  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1227  *                     destination is specified.
1228  * @param node   [i]   The FONT tag node is specified.
1229  * @return The conversion result is returned.
1230  */
1231 static char*
1232 s_chtml30_start_font_tag(void* pdoc, Node* node) 
1233 {
1234   Attr*         attr;
1235   chtml30_t*    chtml30;
1236   Doc*          doc;
1237   request_rec*  r;
1238
1239   chtml30 = GET_CHTML30(pdoc);
1240   doc     = chtml30->doc;
1241   r       = doc->r;
1242
1243   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<font", NULL);
1244
1245   /*--------------------------------------------------------------------------*/
1246   /* Get Attributes                                                           */
1247   /*--------------------------------------------------------------------------*/
1248   for (attr = qs_get_attr(doc,node);
1249        attr; 
1250        attr = qs_get_next_attr(doc,attr)) {
1251     char* name  = qs_get_attr_name(doc,attr);
1252     char* value = qs_get_attr_value(doc,attr);
1253
1254     if (strcasecmp(name, "color") == 0) {
1255       chtml30->out = apr_pstrcat(r->pool, 
1256                       chtml30->out, 
1257                       " color=\"", 
1258                       value, 
1259                       "\"", 
1260                       NULL);
1261     }
1262     else
1263     if (strcasecmp(name, "size") == 0) {
1264       /*----------------------------------------------------------------------*/
1265       /* CHTML 5.0                                                            */
1266       /*----------------------------------------------------------------------*/
1267       /* ignore */
1268     }
1269   }
1270
1271   chtml30->out = apr_pstrcat(r->pool, chtml30->out, ">", NULL);
1272
1273   return chtml30->out;
1274 }
1275
1276
1277 /**
1278  * It is a handler who processes the FONT tag.
1279  *
1280  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1281  *                     destination is specified.
1282  * @param node   [i]   The FONT tag node is specified.
1283  * @return The conversion result is returned.
1284  */
1285 static char*
1286 s_chtml30_end_font_tag(void* pdoc, Node* child) 
1287 {
1288   chtml30_t*    chtml30;
1289   Doc*          doc;
1290   request_rec*  r;
1291
1292   chtml30 = GET_CHTML30(pdoc);
1293   doc     = chtml30->doc;
1294   r       = doc->r;
1295
1296   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "</font>", NULL);
1297
1298   return chtml30->out;
1299 }
1300
1301
1302 /**
1303  * It is a handler who processes the FORM tag.
1304  *
1305  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1306  *                     destination is specified.
1307  * @param node   [i]   The FORM tag node is specified.
1308  * @return The conversion result is returned.
1309  */
1310 static char*
1311 s_chtml30_start_form_tag(void* pdoc, Node* node) 
1312 {
1313   chtml30_t*    chtml30;
1314   Doc*          doc;
1315   request_rec*  r;
1316   Attr*         attr;
1317
1318   chtml30 = GET_CHTML30(pdoc);
1319   doc     = chtml30->doc;
1320   r       = doc->r;
1321
1322   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<form", NULL);
1323
1324   /*--------------------------------------------------------------------------*/
1325   /* Get Attributes                                                           */
1326   /*--------------------------------------------------------------------------*/
1327   for (attr = qs_get_attr(doc,node);
1328        attr;
1329        attr = qs_get_next_attr(doc,attr)) {
1330     char* name = qs_get_attr_name(doc,attr);
1331     char* value = qs_get_attr_value(doc,attr);
1332     if (strcasecmp(name, "action") == 0) {
1333       /*----------------------------------------------------------------------*/
1334       /* CHTML 1.0                                                            */
1335       /*----------------------------------------------------------------------*/
1336       value = chxj_encoding_parameter(r, value);
1337       value = chxj_add_cookie_parameter(r, value, chtml30->cookie);
1338       chtml30->out = apr_pstrcat(r->pool, 
1339                       chtml30->out, 
1340                       " action=\"",
1341                       value,
1342                       "\"", 
1343                       NULL);
1344     }
1345     else
1346     if (strcasecmp(name, "method") == 0) {
1347       /*----------------------------------------------------------------------*/
1348       /* CHTML 1.0                                                            */
1349       /*----------------------------------------------------------------------*/
1350       chtml30->out = apr_pstrcat(r->pool, 
1351                       chtml30->out, 
1352                       " method=\"",
1353                       value,
1354                       "\"", 
1355                       NULL);
1356     }
1357     else
1358     if (strcasecmp(name, "utn") == 0) {
1359       /*----------------------------------------------------------------------*/
1360       /* CHTML 3.0                                                            */
1361       /* It is special only for CHTML.                                        */
1362       /*----------------------------------------------------------------------*/
1363       chtml30->out = apr_pstrcat(r->pool, 
1364                       chtml30->out, 
1365                       " utn ", 
1366                       NULL);
1367     }
1368   }
1369   chtml30->out = apr_pstrcat(r->pool, chtml30->out, ">", NULL);
1370
1371   return chtml30->out;
1372 }
1373
1374
1375 /**
1376  * It is a handler who processes the FORM tag.
1377  *
1378  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1379  *                     destination is specified.
1380  * @param node   [i]   The FORM tag node is specified.
1381  * @return The conversion result is returned.
1382  */
1383 static char*
1384 s_chtml30_end_form_tag(void* pdoc, Node* child) 
1385 {
1386   chtml30_t*    chtml30;
1387   Doc*          doc;
1388   request_rec*  r;
1389
1390   chtml30 = GET_CHTML30(pdoc);
1391   doc     = chtml30->doc;
1392   r       = doc->r;
1393
1394   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "</form>", NULL);
1395
1396   return chtml30->out;
1397 }
1398
1399
1400 /**
1401  * It is a handler who processes the INPUT tag.
1402  *
1403  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1404  *                     destination is specified.
1405  * @param node   [i]   The INPUT tag node is specified.
1406  * @return The conversion result is returned.
1407  */
1408 static char*
1409 s_chtml30_start_input_tag(void* pdoc, Node* node) 
1410 {
1411   chtml30_t*    chtml30;
1412   Doc*          doc;
1413   request_rec*  r;
1414   char*         max_length  = NULL;
1415   char*         type        = NULL;
1416   char*         name        = NULL;
1417   char*         value       = NULL;
1418   char*         istyle      = NULL;
1419   char*         size        = NULL;
1420   char*         checked     = NULL;
1421   char*         accesskey   = NULL;
1422
1423   chtml30   = GET_CHTML30(pdoc);
1424   doc       = chtml30->doc;
1425   r         = doc->r;
1426
1427
1428   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<input", NULL);
1429
1430   /*--------------------------------------------------------------------------*/
1431   /* Get Attributes                                                           */
1432   /*--------------------------------------------------------------------------*/
1433
1434   type       = qs_get_type_attr(doc, node, r);
1435   name       = qs_get_name_attr(doc, node, r);
1436   value      = qs_get_value_attr(doc,node,r);
1437   istyle     = qs_get_istyle_attr(doc,node,r);
1438   max_length = qs_get_maxlength_attr(doc,node,r);
1439   checked    = qs_get_checked_attr(doc,node,r);
1440   accesskey  = qs_get_accesskey_attr(doc, node, r);
1441   size       = qs_get_size_attr(doc, node, r);
1442
1443   if (type)
1444     chtml30->out = apr_pstrcat(r->pool,
1445                     chtml30->out, 
1446                     " type=\"", 
1447                     type, 
1448                     "\" ", 
1449                     NULL);
1450
1451   if (size)
1452     chtml30->out = apr_pstrcat(r->pool, 
1453                     chtml30->out, 
1454                     " size=\"", 
1455                     size, 
1456                     "\" ", 
1457                     NULL);
1458   if (name)
1459     chtml30->out = apr_pstrcat(r->pool, 
1460                     chtml30->out, 
1461                     " name=\"", 
1462                     name, 
1463                     "\" ", 
1464                     NULL);
1465
1466   if (value)
1467     chtml30->out = apr_pstrcat(r->pool, 
1468                     chtml30->out, 
1469                     " value=\"", 
1470                     value, 
1471                     "\" ", 
1472                     NULL);
1473
1474   if (accesskey)
1475     chtml30->out = apr_pstrcat(r->pool, 
1476                     chtml30->out, 
1477                     " accesskey=\"", 
1478                     accesskey, "\" ", 
1479                     NULL);
1480
1481   if (istyle != NULL)
1482     /*------------------------------------------------------------------------*/
1483     /* CHTML 2.0                                                              */
1484     /*------------------------------------------------------------------------*/
1485     chtml30->out = apr_pstrcat(r->pool, 
1486                     chtml30->out, 
1487                     " istyle=\"", 
1488                     istyle, "\" ", 
1489                     NULL);
1490
1491   /*--------------------------------------------------------------------------*/
1492   /* The figure is default for the password.                                  */
1493   /*--------------------------------------------------------------------------*/
1494   if (max_length) {
1495     if (chxj_chk_numeric(max_length) != 0)
1496       max_length = apr_psprintf(r->pool, "0");
1497
1498     if (istyle != NULL && strcasecmp(istyle, "1") == 0)
1499       chtml30->out = apr_pstrcat(r->pool, 
1500                       chtml30->out, 
1501                       apr_psprintf(r->pool, " maxlength=\"%d\"", chxj_atoi(max_length) * 2), 
1502                       NULL);
1503     else 
1504       chtml30->out = apr_pstrcat(r->pool, 
1505                       chtml30->out, 
1506                       apr_psprintf(r->pool, " maxlength=\"%d\"", chxj_atoi(max_length)), 
1507                       NULL);
1508   }
1509
1510   if (checked)
1511     chtml30->out = apr_pstrcat(r->pool, 
1512                     chtml30->out, " checked ", NULL);
1513
1514   chtml30->out = apr_pstrcat(r->pool, chtml30->out, " >", NULL);
1515
1516   return chtml30->out;
1517 }
1518
1519
1520 /**
1521  * It is a handler who processes the INPUT tag.
1522  *
1523  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1524  *                     destination is specified.
1525  * @param node   [i]   The INPUT tag node is specified.
1526  * @return The conversion result is returned.
1527  */
1528 static char*
1529 s_chtml30_end_input_tag(void* pdoc, Node* child) 
1530 {
1531   chtml30_t*    chtml30;
1532
1533   chtml30 = GET_CHTML30(pdoc);
1534
1535   return chtml30->out;
1536 }
1537
1538
1539 /**
1540  * It is a handler who processes the CENTER tag.
1541  *
1542  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1543  *                     destination is specified.
1544  * @param node   [i]   The CENTER tag node is specified.
1545  * @return The conversion result is returned.
1546  */
1547 static char*
1548 s_chtml30_start_center_tag(void* pdoc, Node* node) 
1549 {
1550   chtml30_t*    chtml30;
1551   Doc*          doc;
1552   request_rec*  r;
1553
1554   chtml30 = GET_CHTML30(pdoc);
1555   doc     = chtml30->doc;
1556   r       = doc->r;
1557
1558   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<center>", NULL);
1559
1560   return chtml30->out;
1561 }
1562
1563
1564 /**
1565  * It is a handler who processes the CENTER tag.
1566  *
1567  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1568  *                     destination is specified.
1569  * @param node   [i]   The CENTER tag node is specified.
1570  * @return The conversion result is returned.
1571  */
1572 static char*
1573 s_chtml30_end_center_tag(void* pdoc, Node* child) 
1574 {
1575   chtml30_t*    chtml30;
1576   Doc*          doc;
1577   request_rec*  r;
1578
1579   chtml30 = GET_CHTML30(pdoc);
1580   doc     = chtml30->doc;
1581   r       = doc->r;
1582
1583   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "</center>", NULL);
1584
1585   return chtml30->out;
1586 }
1587
1588
1589 /**
1590  * It is a handler who processes the HR tag.
1591  *
1592  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1593  *                     destination is specified.
1594  * @param node   [i]   The HR tag node is specified.
1595  * @return The conversion result is returned.
1596  */
1597 static char*
1598 s_chtml30_start_hr_tag(void* pdoc, Node* node) 
1599 {
1600   Attr*         attr;
1601   chtml30_t*    chtml30;
1602   Doc*          doc;
1603   request_rec*  r;
1604
1605   chtml30 = GET_CHTML30(pdoc);
1606   doc     = chtml30->doc;
1607   r       = doc->r;
1608
1609   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<hr ", NULL);
1610  
1611   for (attr = qs_get_attr(doc,node);
1612        attr; 
1613        attr = qs_get_next_attr(doc,attr)) {
1614     char* name = qs_get_attr_name(doc,attr);
1615     char* value = qs_get_attr_value(doc,attr);
1616     if (strcasecmp(name, "align") == 0) {
1617       /*----------------------------------------------------------------------*/
1618       /* CHTML 1.0                                                            */
1619       /*----------------------------------------------------------------------*/
1620       chtml30->out = apr_pstrcat(r->pool,
1621                         chtml30->out, 
1622                         " align=\"", value, "\" ", NULL);
1623     }
1624     else
1625     if (strcasecmp(name, "size") == 0) {
1626       /*----------------------------------------------------------------------*/
1627       /* CHTML 1.0                                                            */
1628       /*----------------------------------------------------------------------*/
1629       chtml30->out = apr_pstrcat(r->pool,
1630                         chtml30->out, 
1631                         " size=\"", value, "\" ", NULL);
1632     }
1633     else
1634     if (strcasecmp(name, "width") == 0) {
1635       /*----------------------------------------------------------------------*/
1636       /* CHTML 1.0                                                            */
1637       /*----------------------------------------------------------------------*/
1638       chtml30->out = apr_pstrcat(r->pool,
1639                         chtml30->out, 
1640                         " width=\"", value, "\" ", NULL);
1641     }
1642     else
1643     if (strcasecmp(name, "noshade") == 0) {
1644       /*----------------------------------------------------------------------*/
1645       /* CHTML 1.0                                                            */
1646       /*----------------------------------------------------------------------*/
1647       chtml30->out = apr_pstrcat(r->pool,
1648                         chtml30->out, 
1649                         " noshade ", NULL);
1650     }
1651     else
1652     if (strcasecmp(name, "color") == 0) {
1653       /*----------------------------------------------------------------------*/
1654       /* CHTML 4.0                                                            */
1655       /*----------------------------------------------------------------------*/
1656       /* ignore */
1657     }
1658   }
1659   chtml30->out = apr_pstrcat(r->pool, chtml30->out, " >", NULL);
1660
1661   return chtml30->out;
1662 }
1663
1664
1665 /**
1666  * It is a handler who processes the HR tag.
1667  *
1668  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1669  *                     destination is specified.
1670  * @param node   [i]   The HR tag node is specified.
1671  * @return The conversion result is returned.
1672  */
1673 static char*
1674 s_chtml30_end_hr_tag(void* pdoc, Node* child) 
1675 {
1676   chtml30_t*    chtml30;
1677
1678   chtml30 = GET_CHTML30(pdoc);
1679
1680   return chtml30->out;
1681 }
1682
1683
1684 /**
1685  * It is a handler who processes the IMG tag.
1686  *
1687  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1688  *                     destination is specified.
1689  * @param node   [i]   The IMG tag node is specified.
1690  * @return The conversion result is returned.
1691  */
1692 static char*
1693 s_chtml30_start_img_tag(void* pdoc, Node* node) 
1694 {
1695 #ifndef IMG_NOT_CONVERT_FILENAME
1696   device_table* spec;
1697 #endif
1698   chtml30_t*    chtml30;
1699   Doc*          doc;
1700   request_rec*  r;
1701   Attr*         attr;
1702
1703   chtml30 = GET_CHTML30(pdoc);
1704   doc     = chtml30->doc;
1705   r       = doc->r;
1706 #ifndef IMG_NOT_CONVERT_FILENAME
1707   spec    = chtml30->spec;
1708 #endif
1709
1710   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<img", NULL);
1711  
1712
1713   /*--------------------------------------------------------------------------*/
1714   /* Get Attributes                                                           */
1715   /*--------------------------------------------------------------------------*/
1716   for (attr = qs_get_attr(doc,node);
1717        attr;
1718        attr = qs_get_next_attr(doc,attr)) {
1719     char* name  = qs_get_attr_name(doc,attr);
1720     char* value = qs_get_attr_value(doc,attr);
1721
1722     if (strcasecmp(name, "src") == 0) {
1723       /*----------------------------------------------------------------------*/
1724       /* CHTML 1.0                                                            */
1725       /*----------------------------------------------------------------------*/
1726 #ifdef IMG_NOT_CONVERT_FILENAME
1727       value = chxj_encoding_parameter(r, value);
1728       value = chxj_add_cookie_parameter(r, value, chtml30->cookie);
1729
1730       chtml30->out = apr_pstrcat(r->pool, 
1731                       chtml30->out, " src=\"",value,"\"", NULL);
1732 #else
1733       value = chxj_img_conv(r,spec,value);
1734       value = chxj_encoding_parameter(r, value);
1735       value = chxj_add_cookie_parameter(r, value, chtml30->cookie);
1736
1737       chtml30->out = apr_pstrcat(r->pool, 
1738                       chtml30->out, " src=\"", 
1739                       value, NULL);
1740
1741       chtml30->out = apr_pstrcat(r->pool, chtml30->out, "\"", NULL);
1742 #endif
1743     }
1744     else
1745     if (strcasecmp(name, "align" ) == 0) {
1746       /*----------------------------------------------------------------------*/
1747       /* CHTML 1.0                                                            */
1748       /*----------------------------------------------------------------------*/
1749       chtml30->out = apr_pstrcat(r->pool, 
1750                       chtml30->out, " align=\"",value,"\"", NULL);
1751     }
1752     else
1753     if (strcasecmp(name, "width" ) == 0) {
1754       /*----------------------------------------------------------------------*/
1755       /* CHTML 1.0                                                            */
1756       /*----------------------------------------------------------------------*/
1757       chtml30->out = apr_pstrcat(r->pool, 
1758                       chtml30->out, " width=\"",value,"\"", NULL);
1759     }
1760     else
1761     if (strcasecmp(name, "height") == 0) {
1762       /*----------------------------------------------------------------------*/
1763       /* CHTML 1.0                                                            */
1764       /*----------------------------------------------------------------------*/
1765       chtml30->out = apr_pstrcat(r->pool, 
1766                       chtml30->out, " height=\"",value,"\"", NULL);
1767     }
1768     else
1769     if (strcasecmp(name, "hspace") == 0) {
1770       /*----------------------------------------------------------------------*/
1771       /* CHTML 1.0                                                            */
1772       /*----------------------------------------------------------------------*/
1773       chtml30->out = apr_pstrcat(r->pool, 
1774                       chtml30->out, " hspace=\"",value,"\"", NULL);
1775     }
1776     else
1777     if (strcasecmp(name, "vspace") == 0) {
1778       /*----------------------------------------------------------------------*/
1779       /* CHTML 1.0                                                            */
1780       /*----------------------------------------------------------------------*/
1781       chtml30->out = apr_pstrcat(r->pool, 
1782                       chtml30->out, " vspace=\"",value,"\"", NULL);
1783     }
1784     else
1785     if (strcasecmp(name, "alt"   ) == 0) {
1786       /*----------------------------------------------------------------------*/
1787       /* CHTML 1.0                                                            */
1788       /*----------------------------------------------------------------------*/
1789       chtml30->out = apr_pstrcat(r->pool, 
1790                       chtml30->out, " alt=\"",value,"\"", NULL);
1791     }
1792     else
1793     if (strcasecmp(name, "align" ) == 0) {
1794       /*----------------------------------------------------------------------*/
1795       /* CHTML 4.0                                                            */
1796       /*----------------------------------------------------------------------*/
1797       /* ignore */
1798     }
1799   }
1800
1801   chtml30->out = apr_pstrcat(r->pool, chtml30->out, ">", NULL);
1802
1803   return chtml30->out;
1804 }
1805
1806
1807 /**
1808  * It is a handler who processes the IMG tag.
1809  *
1810  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1811  *                     destination is specified.
1812  * @param node   [i]   The IMG tag node is specified.
1813  * @return The conversion result is returned.
1814  */
1815 static char*
1816 s_chtml30_end_img_tag(void* pdoc, Node* child) 
1817 {
1818   chtml30_t*    chtml30;
1819
1820   chtml30 = GET_CHTML30(pdoc);
1821
1822   return chtml30->out;
1823 }
1824
1825
1826 /**
1827  * It is a handler who processes the SELECT tag.
1828  *
1829  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1830  *                     destination is specified.
1831  * @param node   [i]   The SELECT tag node is specified.
1832  * @return The conversion result is returned.
1833  */
1834 static char*
1835 s_chtml30_start_select_tag(void* pdoc, Node* child)
1836 {
1837
1838   char*         size;
1839   char*         name;
1840   Attr*         attr;
1841   chtml30_t*    chtml30;
1842   Doc*          doc;
1843   request_rec*  r;
1844
1845   chtml30 = GET_CHTML30(pdoc);
1846   doc     = chtml30->doc;
1847   r       = doc->r;
1848   size    = NULL;
1849   name    = NULL;
1850
1851   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<select", NULL);
1852   for (attr = qs_get_attr(doc,child);
1853        attr;
1854        attr = qs_get_next_attr(doc,attr)) {
1855     char* nm  = qs_get_attr_name(doc,attr);
1856     char* val = qs_get_attr_value(doc,attr);
1857
1858     if (strcasecmp(nm, "size") == 0) {
1859       /*----------------------------------------------------------------------*/
1860       /* CHTML 1.0 version 2.0                                                */
1861       /*----------------------------------------------------------------------*/
1862       size = apr_pstrdup(r->pool, val);
1863     }
1864     else
1865     if (strcasecmp(nm, "name") == 0) {
1866       /*----------------------------------------------------------------------*/
1867       /* CHTML 1.0 version 2.0                                                */
1868       /*----------------------------------------------------------------------*/
1869       name = apr_pstrdup(r->pool, val);
1870     }
1871     else
1872     if (strcasecmp(nm, "multiple") == 0) {
1873       /*----------------------------------------------------------------------*/
1874       /* CHTML 1.0 version 2.0                                                */
1875       /*----------------------------------------------------------------------*/
1876       /* not support */
1877     }
1878   }
1879
1880   if (size)
1881     chtml30->out = apr_pstrcat(r->pool, chtml30->out, " size=\"",size,"\"", NULL);
1882
1883   if (name)
1884     chtml30->out = apr_pstrcat(r->pool, chtml30->out, " name=\"",name,"\"", NULL);
1885
1886   chtml30->out = apr_pstrcat(r->pool, chtml30->out, ">\n", NULL);
1887
1888   return chtml30->out;
1889 }
1890
1891
1892 /**
1893  * It is a handler who processes the SELECT tag.
1894  *
1895  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1896  *                     destination is specified.
1897  * @param node   [i]   The SELECT tag node is specified.
1898  * @return The conversion result is returned.
1899  */
1900 static char*
1901 s_chtml30_end_select_tag(void* pdoc, Node* child)
1902 {
1903   chtml30_t*    chtml30;
1904   Doc*          doc;
1905   request_rec*  r;
1906
1907   chtml30 = GET_CHTML30(pdoc);
1908   doc   = chtml30->doc;
1909   r     = doc->r;
1910
1911   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "</select>\n", NULL);
1912
1913   return chtml30->out;
1914 }
1915
1916
1917 /**
1918  * It is a handler who processes the OPTION tag.
1919  *
1920  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1921  *                     destination is specified.
1922  * @param node   [i]   The OPTION tag node is specified.
1923  * @return The conversion result is returned.
1924  */
1925 static char*
1926 s_chtml30_start_option_tag(void* pdoc, Node* child)
1927 {
1928   Attr*         attr;
1929   chtml30_t*    chtml30;
1930   Doc*          doc;
1931   request_rec*  r;
1932   char*         selected;
1933   char*         value;
1934
1935   chtml30    = GET_CHTML30(pdoc);
1936   doc        = chtml30->doc;
1937   r          = doc->r;
1938   selected   = NULL;
1939   value      = NULL;
1940
1941   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<option", NULL);
1942   for (attr = qs_get_attr(doc,child);
1943        attr;
1944        attr = qs_get_next_attr(doc,attr)) {
1945     char* nm  = qs_get_attr_name(doc,attr);
1946     char* val = qs_get_attr_value(doc,attr);
1947
1948     if (strcasecmp(nm, "selected") == 0) {
1949       /*----------------------------------------------------------------------*/
1950       /* CHTML 1.0 version 2.0                                                */
1951       /*----------------------------------------------------------------------*/
1952       selected = apr_pstrdup(r->pool, val);
1953     }
1954     else
1955     if (strcasecmp(nm, "value") == 0) {
1956       /*----------------------------------------------------------------------*/
1957       /* CHTML 1.0 version 2.0                                                */
1958       /*----------------------------------------------------------------------*/
1959       value = apr_pstrdup(r->pool, val);
1960     }
1961   }
1962
1963   if (value)
1964     chtml30->out = apr_pstrcat(r->pool, chtml30->out, " value=\"",value,"\"", NULL);
1965   else
1966     chtml30->out = apr_pstrcat(r->pool, chtml30->out, " value=\"\"", NULL);
1967
1968   if (selected)
1969     chtml30->out = apr_pstrcat(r->pool, chtml30->out, " selected ", NULL);
1970
1971   chtml30->out = apr_pstrcat(r->pool, chtml30->out, ">", NULL);
1972
1973   return chtml30->out;
1974 }
1975
1976
1977 /**
1978  * It is a handler who processes the OPTION tag.
1979  *
1980  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1981  *                     destination is specified.
1982  * @param node   [i]   The OPTION tag node is specified.
1983  * @return The conversion result is returned.
1984  */
1985 static char*
1986 s_chtml30_end_option_tag(void* pdoc, Node* child)
1987 {
1988   chtml30_t*    chtml30;
1989
1990   chtml30 = GET_CHTML30(pdoc);
1991
1992   /* Don't close */
1993
1994   return chtml30->out;
1995 }
1996
1997
1998 /**
1999  * It is a handler who processes the DIV tag.
2000  *
2001  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2002  *                     destination is specified.
2003  * @param node   [i]   The DIV tag node is specified.
2004  * @return The conversion result is returned.
2005  */
2006 static char*
2007 s_chtml30_start_div_tag(void* pdoc, Node* child)
2008 {
2009   Attr*         attr;
2010   chtml30_t*    chtml30;
2011   Doc*          doc;
2012   request_rec*  r;
2013   char*         align;
2014
2015   chtml30 = GET_CHTML30(pdoc);
2016   doc     = chtml30->doc;
2017   r       = doc->r;
2018   align   = NULL;
2019
2020
2021   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<div", NULL);
2022   for (attr = qs_get_attr(doc,child);
2023        attr;
2024        attr = qs_get_next_attr(doc,attr)) {
2025     char* nm  = qs_get_attr_name(doc,attr);
2026     char* val = qs_get_attr_value(doc,attr);
2027
2028     if (strcasecmp(nm, "align") == 0) {
2029       /*----------------------------------------------------------------------*/
2030       /* CHTML 1.0 (W3C version 3.2)                                          */
2031       /*----------------------------------------------------------------------*/
2032       align = apr_pstrdup(r->pool, val);
2033     }
2034   }
2035
2036   if (align)
2037     chtml30->out = apr_pstrcat(r->pool, 
2038                     chtml30->out, " align=\"", align, "\"", NULL);
2039
2040   chtml30->out = apr_pstrcat(r->pool, chtml30->out, ">", NULL);
2041
2042   return chtml30->out;
2043 }
2044
2045
2046 /**
2047  * It is a handler who processes the DIV tag.
2048  *
2049  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2050  *                     destination is specified.
2051  * @param node   [i]   The DIV tag node is specified.
2052  * @return The conversion result is returned.
2053  */
2054 static char*
2055 s_chtml30_end_div_tag(void* pdoc, Node* node)
2056 {
2057   chtml30_t*    chtml30;
2058   Doc*          doc;
2059   request_rec*  r;
2060
2061   chtml30 = GET_CHTML30(pdoc);
2062   doc     = chtml30->doc;
2063   r       = doc->r;
2064
2065   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "</div>\n", NULL);
2066
2067   return chtml30->out;
2068 }
2069
2070
2071 /**
2072  * It is a handler who processes the UL tag.
2073  *
2074  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2075  *                     destination is specified.
2076  * @param node   [i]   The UL tag node is specified.
2077  * @return The conversion result is returned.
2078  */
2079 static char*
2080 s_chtml30_start_ul_tag(void* pdoc, Node* node) 
2081 {
2082   chtml30_t*    chtml30;
2083   Doc*          doc;
2084   request_rec*  r;
2085
2086   chtml30 = GET_CHTML30(pdoc);
2087   doc     = chtml30->doc;
2088   r       = doc->r;
2089
2090   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<ul>", NULL);
2091
2092   return chtml30->out;
2093 }
2094
2095
2096 /**
2097  * It is a handler who processes the UL tag.
2098  *
2099  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2100  *                     destination is specified.
2101  * @param node   [i]   The UL tag node is specified.
2102  * @return The conversion result is returned.
2103  */
2104 static char*
2105 s_chtml30_end_ul_tag(void* pdoc, Node* child) 
2106 {
2107   chtml30_t*    chtml30;
2108   Doc*          doc;
2109   request_rec*  r;
2110
2111   chtml30 = GET_CHTML30(pdoc);
2112   doc     = chtml30->doc;
2113   r       = doc->r;
2114
2115   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "</ul>", NULL);
2116
2117   return chtml30->out;
2118 }
2119
2120
2121 /**
2122  * It is a handler who processes the PRE tag.
2123  *
2124  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2125  *                     destination is specified.
2126  * @param node   [i]   The PRE tag node is specified.
2127  * @return The conversion result is returned.
2128  */
2129 static char*
2130 s_chtml30_start_pre_tag(void* pdoc, Node* node) 
2131 {
2132   chtml30_t*    chtml30;
2133   Doc*          doc;
2134   request_rec*  r;
2135
2136   chtml30 = GET_CHTML30(pdoc);
2137   doc     = chtml30->doc;
2138   r       = doc->r;
2139
2140   chtml30->pre_flag++;
2141   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<pre>", NULL);
2142
2143   return chtml30->out;
2144 }
2145
2146 /**
2147  * It is a handler who processes the PRE tag.
2148  *
2149  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2150  *                     destination is specified.
2151  * @param node   [i]   The PRE tag node is specified.
2152  * @return The conversion result is returned.
2153  */
2154 static char*
2155 s_chtml30_end_pre_tag(void* pdoc, Node* child) 
2156 {
2157   chtml30_t*    chtml30;
2158   Doc*          doc;
2159   request_rec*  r;
2160
2161   chtml30 = GET_CHTML30(pdoc);
2162   doc     = chtml30->doc;
2163   r       = doc->r;
2164
2165   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "</pre>", NULL);
2166   chtml30->pre_flag--;
2167
2168   return chtml30->out;
2169 }
2170
2171
2172 /**
2173  * It is a handler who processes the P tag.
2174  *
2175  * @param pdoc  [i/o] The pointer to the XHTML structure at the output
2176  *                     destination is specified.
2177  * @param node   [i]   The P tag node is specified.
2178  * @return The conversion result is returned.
2179  */
2180 static char*
2181 s_chtml30_start_p_tag(void* pdoc, Node* node) 
2182 {
2183   chtml30_t*    chtml30;
2184   Doc*          doc;
2185   request_rec*  r;
2186
2187   chtml30 = GET_CHTML30(pdoc);
2188   doc     = chtml30->doc;
2189   r       = doc->r;
2190
2191   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<p>", NULL);
2192
2193   return chtml30->out;
2194 }
2195
2196
2197 /**
2198  * It is a handler who processes the P tag.
2199  *
2200  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2201  *                     destination is specified.
2202  * @param node   [i]   The P tag node is specified.
2203  * @return The conversion result is returned.
2204  */
2205 static char*
2206 s_chtml30_end_p_tag(void* pdoc, Node* child) 
2207 {
2208   chtml30_t*    chtml30;
2209   Doc*          doc;
2210   request_rec*  r;
2211
2212   chtml30 = GET_CHTML30(pdoc);
2213   doc     = chtml30->doc;
2214   r       = doc->r;
2215
2216   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "</p>", NULL);
2217
2218   return chtml30->out;
2219 }
2220
2221
2222 /**
2223  * It is a handler who processes the OL tag.
2224  *
2225  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2226  *                     destination is specified.
2227  * @param node   [i]   The OL tag node is specified.
2228  * @return The conversion result is returned.
2229  */
2230 static char*
2231 s_chtml30_start_ol_tag(void* pdoc, Node* node) 
2232 {
2233   chtml30_t*    chtml30;
2234   Doc*          doc;
2235   request_rec*  r;
2236
2237   chtml30 = GET_CHTML30(pdoc);
2238   doc     = chtml30->doc;
2239   r       = doc->r;
2240
2241   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<ol>", NULL);
2242
2243   return chtml30->out;
2244 }
2245
2246
2247 /**
2248  * It is a handler who processes the OL tag.
2249  *
2250  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2251  *                     destination is specified.
2252  * @param node   [i]   The OL tag node is specified.
2253  * @return The conversion result is returned.
2254  */
2255 static char*
2256 s_chtml30_end_ol_tag(void* pdoc, Node* node) 
2257 {
2258   chtml30_t*    chtml30;
2259   Doc*          doc;
2260   request_rec*  r;
2261
2262   chtml30 = GET_CHTML30(pdoc);
2263   doc     = chtml30->doc;
2264   r       = doc->r;
2265
2266   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "</ol>", NULL);
2267
2268   return chtml30->out;
2269 }
2270
2271
2272 /**
2273  * It is a handler who processes the LI tag.
2274  *
2275  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2276  *                     destination is specified.
2277  * @param node   [i]   The LI tag node is specified.
2278  * @return The conversion result is returned.
2279  */
2280 static char*
2281 s_chtml30_start_li_tag(void* pdoc, Node* node) 
2282 {
2283   chtml30_t*    chtml30;
2284   Doc*          doc;
2285   request_rec*  r;
2286
2287   chtml30 = GET_CHTML30(pdoc);
2288   doc     = chtml30->doc;
2289   r       = doc->r;
2290
2291   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<li>", NULL);
2292
2293   return chtml30->out;
2294 }
2295
2296
2297 /**
2298  * It is a handler who processes the LI tag.
2299  *
2300  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2301  *                     destination is specified.
2302  * @param node   [i]   The LI tag node is specified.
2303  * @return The conversion result is returned.
2304  */
2305 static char*
2306 s_chtml30_end_li_tag(void* pdoc, Node* child) 
2307 {
2308   chtml30_t*    chtml30;
2309   Doc*          doc;
2310   request_rec*  r;
2311
2312   chtml30 = GET_CHTML30(pdoc);
2313   doc     = chtml30->doc;
2314   r       = doc->r;
2315
2316   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "</li>", NULL);
2317
2318   return chtml30->out;
2319 }
2320
2321
2322 /**
2323  * It is a handler who processes the H1 tag.
2324  *
2325  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2326  *                     destination is specified.
2327  * @param node   [i]   The H1 tag node is specified.
2328  * @return The conversion result is returned.
2329  */
2330 static char*
2331 s_chtml30_start_h1_tag(void* pdoc, Node* node) 
2332 {
2333   chtml30_t*    chtml30;
2334   Doc*          doc;
2335   request_rec*  r;
2336
2337   chtml30 = GET_CHTML30(pdoc);
2338   doc     = chtml30->doc;
2339   r       = doc->r;
2340
2341   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<h1>\r\n", NULL);
2342
2343   return chtml30->out;
2344 }
2345
2346
2347 /**
2348  * It is a handler who processes the H1 tag.
2349  *
2350  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2351  *                     destination is specified.
2352  * @param node   [i]   The H1 tag node is specified.
2353  * @return The conversion result is returned.
2354  */
2355 static char*
2356 s_chtml30_end_h1_tag(void* pdoc, Node* child) 
2357 {
2358   chtml30_t*    chtml30;
2359   Doc*          doc;
2360   request_rec*  r;
2361
2362   chtml30 = GET_CHTML30(pdoc);
2363   doc     = chtml30->doc;
2364   r       = doc->r;
2365
2366   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "</h1>\r\n", NULL);
2367
2368   return chtml30->out;
2369 }
2370
2371
2372 /**
2373  * It is a handler who processes the H2 tag.
2374  *
2375  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2376  *                     destination is specified.
2377  * @param node   [i]   The H2 tag node is specified.
2378  * @return The conversion result is returned.
2379  */
2380 static char*
2381 s_chtml30_start_h2_tag(void* pdoc, Node* node) 
2382 {
2383   chtml30_t*    chtml30;
2384   Doc*          doc;
2385   request_rec*  r;
2386
2387   chtml30 = GET_CHTML30(pdoc);
2388   doc     = chtml30->doc;
2389   r       = doc->r;
2390
2391   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<h2>\r\n", NULL);
2392
2393   return chtml30->out;
2394 }
2395
2396
2397 /**
2398  * It is a handler who processes the H2 tag.
2399  *
2400  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2401  *                     destination is specified.
2402  * @param node   [i]   The H2 tag node is specified.
2403  * @return The conversion result is returned.
2404  */
2405 static char*
2406 s_chtml30_end_h2_tag(void* pdoc, Node* child) 
2407 {
2408   chtml30_t*    chtml30;
2409   Doc*          doc;
2410   request_rec*  r;
2411
2412   chtml30 = GET_CHTML30(pdoc);
2413   doc     = chtml30->doc;
2414   r       = doc->r;
2415
2416   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "</h2>\r\n", NULL);
2417
2418   return chtml30->out;
2419 }
2420
2421
2422 /**
2423  * It is a handler who processes the H3 tag.
2424  *
2425  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2426  *                     destination is specified.
2427  * @param node   [i]   The H3 tag node is specified.
2428  * @return The conversion result is returned.
2429  */
2430 static char*
2431 s_chtml30_start_h3_tag(void* pdoc, Node* node) 
2432 {
2433   chtml30_t*    chtml30;
2434   Doc*          doc;
2435   request_rec*  r;
2436
2437   chtml30 = GET_CHTML30(pdoc);
2438   doc     = chtml30->doc;
2439   r       = doc->r;
2440
2441   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<h3>\r\n", NULL);
2442
2443   return chtml30->out;
2444 }
2445
2446
2447 /**
2448  * It is a handler who processes the H3 tag.
2449  *
2450  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2451  *                     destination is specified.
2452  * @param node   [i]   The H3 tag node is specified.
2453  * @return The conversion result is returned.
2454  */
2455 static char*
2456 s_chtml30_end_h3_tag(void* pdoc, Node* child) 
2457 {
2458   chtml30_t*    chtml30;
2459   Doc*          doc;
2460   request_rec*  r;
2461
2462   chtml30 = GET_CHTML30(pdoc);
2463   doc   = chtml30->doc;
2464   r     = doc->r;
2465
2466   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "</h3>\r\n", NULL);
2467
2468   return chtml30->out;
2469 }
2470
2471
2472 /**
2473  * It is a handler who processes the H4 tag.
2474  *
2475  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2476  *                     destination is specified.
2477  * @param node   [i]   The H4 tag node is specified.
2478  * @return The conversion result is returned.
2479  */
2480 static char*
2481 s_chtml30_start_h4_tag(void* pdoc, Node* node) 
2482 {
2483   chtml30_t*    chtml30;
2484   Doc*          doc;
2485   request_rec*  r;
2486
2487   chtml30 = GET_CHTML30(pdoc);
2488   doc     = chtml30->doc;
2489   r       = doc->r;
2490
2491   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<h4>\r\n", NULL);
2492
2493   return chtml30->out;
2494 }
2495
2496
2497 /**
2498  * It is a handler who processes the H4 tag.
2499  *
2500  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2501  *                     destination is specified.
2502  * @param node   [i]   The H4 tag node is specified.
2503  * @return The conversion result is returned.
2504  */
2505 static char*
2506 s_chtml30_end_h4_tag(void* pdoc, Node* child) 
2507 {
2508   chtml30_t*    chtml30;
2509   Doc*          doc;
2510   request_rec*  r;
2511
2512   chtml30 = GET_CHTML30(pdoc);
2513   doc     = chtml30->doc;
2514   r       = doc->r;
2515
2516   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "</h4>\r\n", NULL);
2517
2518   return chtml30->out;
2519 }
2520
2521
2522 /**
2523  * It is a handler who processes the H5 tag.
2524  *
2525  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2526  *                     destination is specified.
2527  * @param node   [i]   The H5 tag node is specified.
2528  * @return The conversion result is returned.
2529  */
2530 static char*
2531 s_chtml30_start_h5_tag(void* pdoc, Node* node) 
2532 {
2533   chtml30_t*    chtml30;
2534   Doc*          doc;
2535   request_rec*  r;
2536
2537   chtml30 = GET_CHTML30(pdoc);
2538   doc     = chtml30->doc;
2539   r       = doc->r;
2540
2541   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<h5>\r\n", NULL);
2542
2543   return chtml30->out;
2544 }
2545
2546
2547 /**
2548  * It is a handler who processes the H5 tag.
2549  *
2550  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2551  *                     destination is specified.
2552  * @param node   [i]   The H5 tag node is specified.
2553  * @return The conversion result is returned.
2554  */
2555 static char*
2556 s_chtml30_end_h5_tag(void* pdoc, Node* child) 
2557 {
2558   chtml30_t*    chtml30;
2559   Doc*          doc;
2560   request_rec*  r;
2561
2562   chtml30 = GET_CHTML30(pdoc);
2563   doc     = chtml30->doc;
2564   r       = doc->r;
2565
2566   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "</h5>\r\n", NULL);
2567
2568   return chtml30->out;
2569 }
2570
2571
2572 /**
2573  * It is a handler who processes the H6 tag.
2574  *
2575  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2576  *                     destination is specified.
2577  * @param node   [i]   The H6 tag node is specified.
2578  * @return The conversion result is returned.
2579  */
2580 static char*
2581 s_chtml30_start_h6_tag(void* pdoc, Node* node) 
2582 {
2583   chtml30_t*    chtml30;
2584   Doc*          doc;
2585   request_rec*  r;
2586
2587   chtml30 = GET_CHTML30(pdoc);
2588   doc     = chtml30->doc;
2589   r       = doc->r;
2590
2591   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<h6>\r\n", NULL);
2592
2593   return chtml30->out;
2594 }
2595
2596
2597 /**
2598  * It is a handler who processes the H6 tag.
2599  *
2600  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2601  *                     destination is specified.
2602  * @param node   [i]   The H6 tag node is specified.
2603  * @return The conversion result is returned.
2604  */
2605 static char*
2606 s_chtml30_end_h6_tag(void* pdoc, Node* child) 
2607 {
2608   chtml30_t*    chtml30;
2609   Doc*          doc;
2610   request_rec*  r;
2611
2612   chtml30 = GET_CHTML30(pdoc);
2613   doc     = chtml30->doc;
2614   r       = doc->r;
2615
2616   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "</h6>\r\n", NULL);
2617
2618   return chtml30->out;
2619 }
2620
2621
2622 /**
2623  * It is a handler who processes the TEXTARE tag.
2624  *
2625  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2626  *                     destination is specified.
2627  * @param node   [i]   The TEXTAREA tag node is specified.
2628  * @return The conversion result is returned.
2629  */
2630 static char*
2631 s_chtml30_start_textarea_tag(void* pdoc, Node* node) 
2632 {
2633   chtml30_t*    chtml30;
2634   Doc*          doc;
2635   request_rec*  r;
2636   Attr*         attr;
2637
2638   chtml30 = GET_CHTML30(pdoc);
2639   doc     = chtml30->doc;
2640   r       = doc->r;
2641
2642   chtml30->textarea_flag++;
2643   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "<textarea ", NULL);
2644
2645   for (attr = qs_get_attr(doc,node);
2646        attr;
2647        attr = qs_get_next_attr(doc,attr)) {
2648
2649     char* name  = qs_get_attr_name(doc,attr);
2650     char* value = qs_get_attr_value(doc,attr);
2651
2652     if ((*name == 'n' || *name == 'N') && strcasecmp(name, "name") == 0) {
2653       chtml30->out = apr_pstrcat(r->pool, chtml30->out, " name=\"",value,"\"", NULL);
2654     }
2655     else 
2656     if ((*name == 'r' || *name == 'R') && strcasecmp(name, "rows") == 0) {
2657       chtml30->out = apr_pstrcat(r->pool, chtml30->out, " rows=\"",value,"\"", NULL);
2658     }
2659     else 
2660     if ((*name == 'c' || *name == 'C') && strcasecmp(name, "cols") == 0) {
2661       chtml30->out = apr_pstrcat(r->pool, chtml30->out, " cols=\"",value,"\"", NULL);
2662     }
2663   }
2664
2665   chtml30->out = apr_pstrcat(r->pool, chtml30->out, ">\r\n", NULL);
2666
2667   return chtml30->out;
2668 }
2669
2670
2671 /**
2672  * It is a handler who processes the TEXTAREA tag.
2673  *
2674  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2675  *                     destination is specified.
2676  * @param node   [i]   The TEXTAREA tag node is specified.
2677  * @return The conversion result is returned.
2678  */
2679 static char*
2680 s_chtml30_end_textarea_tag(void* pdoc, Node* child) 
2681 {
2682   chtml30_t*    chtml30;
2683   Doc*          doc;
2684   request_rec*  r;
2685
2686   chtml30 = GET_CHTML30(pdoc);
2687   doc     = chtml30->doc;
2688   r       = doc->r;
2689
2690   chtml30->out = apr_pstrcat(r->pool, chtml30->out, "</textarea>\r\n", NULL);
2691   chtml30->textarea_flag--;
2692
2693   return chtml30->out;
2694 }
2695
2696
2697 static char*
2698 s_chtml30_chxjif_tag(void* pdoc, Node* node)
2699 {
2700   Node*         child;
2701   chtml30_t*    chtml30;
2702   Doc*          doc;
2703   request_rec*  r;
2704
2705   chtml30 = GET_CHTML30(pdoc);
2706   doc     = chtml30->doc;
2707   r       = doc->r;
2708
2709   for (child = qs_get_child_node(doc, node);
2710        child;
2711        child = qs_get_next_node(doc, child)) {
2712     chtml30->out = apr_pstrcat(r->pool, chtml30->out, child->otext, NULL);
2713     s_chtml30_chxjif_tag(chtml30, child);
2714   }
2715
2716   return NULL;
2717 }
2718
2719 static char*
2720 s_chtml30_text_tag(void* pdoc, Node* child)
2721 {
2722   chtml30_t*    chtml30;
2723   Doc*          doc;
2724   request_rec*  r;
2725
2726   char*   textval;
2727   char*   tmp;
2728   char*   tdst;
2729   char    one_byte[2];
2730   int     ii;
2731   int     tdst_len;
2732
2733   chtml30 = GET_CHTML30(pdoc);
2734   doc     = chtml30->doc;
2735   r       = doc->r;
2736   
2737   textval = qs_get_node_value(doc,child);
2738   textval = qs_trim_string(chtml30->doc->r, textval);
2739   if (strlen(textval) == 0)
2740     return chtml30->out;
2741   
2742   tmp = apr_palloc(r->pool, qs_get_node_size(doc,child)+1);
2743   memset(tmp, 0, qs_get_node_size(doc,child)+1);
2744   
2745   tdst     = qs_alloc_zero_byte_string(r);
2746   memset(one_byte, 0, sizeof(one_byte));
2747   tdst_len = 0;
2748   
2749   for (ii=0; ii<qs_get_node_size(doc,child); ii++) {
2750     char* out;
2751     int rtn = s_chtml30_search_emoji(chtml30, &textval[ii], &out);
2752     if (rtn) {
2753       tdst = qs_out_apr_pstrcat(r, tdst, out, &tdst_len);
2754       ii+=(rtn - 1);
2755       continue;
2756     }
2757   
2758     if (is_sjis_kanji(textval[ii])) {
2759       one_byte[0] = textval[ii+0];
2760       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2761       one_byte[0] = textval[ii+1];
2762       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2763       ii++;
2764     }
2765     else if (chtml30->pre_flag) {
2766       one_byte[0] = textval[ii+0];
2767       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2768     }
2769     else if (chtml30->textarea_flag) {
2770       one_byte[0] = textval[ii+0];
2771       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2772     }
2773     else if (textval[ii] != '\r' && textval[ii] != '\n') {
2774       one_byte[0] = textval[ii+0];
2775       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2776     }
2777   }
2778   chtml30->out = apr_pstrcat(r->pool, chtml30->out, tdst, NULL);
2779
2780   return chtml30->out;
2781 }
2782
2783 /*
2784  * vim:ts=2 et
2785  */