2 * Copyright (C) 2005-2008 Atsushi Konno All rights reserved.
3 * Copyright (C) 2005 QSDN,Inc. All rights reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "chxj_jhtml.h"
18 #include "chxj_hdml.h"
19 #include "chxj_dump.h"
20 #include "chxj_img_conv.h"
21 #include "chxj_qr_code.h"
22 #include "chxj_encoding.h"
23 #include "chxj_url_encode.h"
26 #define GET_JHTML(X) ((jhtml_t *)(X))
29 #define W_L(X) do { jhtml->out = BUFFERED_WRITE_LITERAL(jhtml->out, &doc->buf, (X)); } while(0)
30 #define W_V(X) do { jhtml->out = (X) ? BUFFERED_WRITE_VALUE(jhtml->out, &doc->buf, (X)) \
31 : BUFFERED_WRITE_LITERAL(jhtml->out, &doc->buf, ""); } while(0)
33 static char *s_jhtml_start_html_tag (void *pdoc, Node *node);
34 static char *s_jhtml_end_html_tag (void *pdoc, Node *node);
35 static char *s_jhtml_start_meta_tag (void *pdoc, Node *node);
36 static char *s_jhtml_end_meta_tag (void *pdoc, Node *node);
37 static char *s_jhtml_start_head_tag (void *pdoc, Node *node);
38 static char *s_jhtml_end_head_tag (void *pdoc, Node *node);
39 static char *s_jhtml_start_title_tag (void *pdoc, Node *node);
40 static char *s_jhtml_end_title_tag (void *pdoc, Node *node);
41 static char *s_jhtml_start_base_tag (void *pdoc, Node *node);
42 static char *s_jhtml_end_base_tag (void *pdoc, Node *node);
43 static char *s_jhtml_start_body_tag (void *pdoc, Node *node);
44 static char *s_jhtml_end_body_tag (void *pdoc, Node *node);
45 static char *s_jhtml_start_a_tag (void *pdoc, Node *node);
46 static char *s_jhtml_end_a_tag (void *pdoc, Node *node);
47 static char *s_jhtml_start_pre_tag (void *pdoc, Node *node);
48 static char *s_jhtml_end_pre_tag (void *pdoc, Node *node);
49 static char *s_jhtml_start_p_tag (void *pdoc, Node *node);
50 static char *s_jhtml_end_p_tag (void *pdoc, Node *node);
51 static char *s_jhtml_start_ul_tag (void *pdoc, Node *node);
52 static char *s_jhtml_end_ul_tag (void *pdoc, Node *node);
53 static char *s_jhtml_start_ol_tag (void *pdoc, Node *node);
54 static char *s_jhtml_end_ol_tag (void *pdoc, Node *node);
55 static char *s_jhtml_start_li_tag (void *pdoc, Node *node);
56 static char *s_jhtml_end_li_tag (void *pdoc, Node *node);
57 static char *s_jhtml_start_br_tag (void *pdoc, Node *node);
58 static char *s_jhtml_end_br_tag (void *pdoc, Node *node);
59 static char *s_jhtml_start_tr_tag (void *pdoc, Node *node);
60 static char *s_jhtml_end_tr_tag (void *pdoc, Node *node);
61 static char *s_jhtml_start_font_tag (void *pdoc, Node *node);
62 static char *s_jhtml_end_font_tag (void *pdoc, Node *node);
63 static char *s_jhtml_start_form_tag (void *pdoc, Node *node);
64 static char *s_jhtml_end_form_tag (void *pdoc, Node *node);
65 static char *s_jhtml_start_input_tag (void *pdoc, Node *node);
66 static char *s_jhtml_end_input_tag (void *pdoc, Node *node);
67 static char *s_jhtml_start_center_tag (void *pdoc, Node *node);
68 static char *s_jhtml_end_center_tag (void *pdoc, Node *node);
69 static char *s_jhtml_start_hr_tag (void *pdoc, Node *node);
70 static char *s_jhtml_end_hr_tag (void *pdoc, Node *node);
71 static char *s_jhtml_start_img_tag (void *pdoc, Node *node);
72 static char *s_jhtml_end_img_tag (void *pdoc, Node *node);
73 static char *s_jhtml_start_select_tag (void *pdoc, Node *node);
74 static char *s_jhtml_end_select_tag (void *pdoc, Node *node);
75 static char *s_jhtml_start_option_tag (void *pdoc, Node *node);
76 static char *s_jhtml_end_option_tag (void *pdoc, Node *node);
77 static char *s_jhtml_start_div_tag (void *pdoc, Node *node);
78 static char *s_jhtml_end_div_tag (void *pdoc, Node *node);
79 static char *s_jhtml_start_textarea_tag (void *pdoc, Node *node);
80 static char *s_jhtml_end_textarea_tag (void *pdoc, Node *node);
81 static char *s_jhtml_start_b_tag (void *pdoc, Node *node);
82 static char *s_jhtml_end_b_tag (void *pdoc, Node *node);
83 static char *s_jhtml_chxjif_tag (void *pdoc, Node *node);
84 static char *s_jhtml_text_tag (void *pdoc, Node *node);
86 static void s_init_jhtml(jhtml_t *jhtml, Doc *doc, request_rec *r, device_table *spec);
88 static int s_jhtml_search_emoji(jhtml_t *jhtml, char *txt, char **rslt);
90 static char *chxj_istyle_to_mode(request_rec *r, const char *s);
94 tag_handler jhtml_handler[] = {
97 s_jhtml_start_html_tag,
102 s_jhtml_start_meta_tag,
103 s_jhtml_end_meta_tag,
107 s_jhtml_start_textarea_tag,
108 s_jhtml_end_textarea_tag,
117 s_jhtml_start_pre_tag,
122 s_jhtml_start_ul_tag,
127 s_jhtml_start_li_tag,
132 s_jhtml_start_ol_tag,
167 s_jhtml_start_head_tag,
168 s_jhtml_end_head_tag,
172 s_jhtml_start_title_tag,
173 s_jhtml_end_title_tag,
177 s_jhtml_start_base_tag,
178 s_jhtml_end_base_tag,
182 s_jhtml_start_body_tag,
183 s_jhtml_end_body_tag,
192 s_jhtml_start_br_tag,
202 s_jhtml_start_tr_tag,
217 s_jhtml_start_font_tag,
218 s_jhtml_end_font_tag,
222 s_jhtml_start_form_tag,
223 s_jhtml_end_form_tag,
227 s_jhtml_start_input_tag,
228 s_jhtml_end_input_tag,
232 s_jhtml_start_center_tag,
233 s_jhtml_end_center_tag,
237 s_jhtml_start_hr_tag,
242 s_jhtml_start_img_tag,
247 s_jhtml_start_select_tag,
248 s_jhtml_end_select_tag,
252 s_jhtml_start_option_tag,
253 s_jhtml_end_option_tag,
257 s_jhtml_start_div_tag,
364 * converts from CHTML5.0 to JHTML.
366 * @param r [i] Requet_rec is appointed.
367 * @param spec [i] The result of the device specification processing which
368 * was done in advance is appointed.
369 * @param src [i] The character string before the converting is appointed.
370 * @return The character string after the converting is returned.
379 chxjconvrule_entry *entryp,
390 /*--------------------------------------------------------------------------*/
392 /*--------------------------------------------------------------------------*/
394 dst = chxj_qr_code_blob_handler(r, src, (size_t*)dstlen);
396 DBG(r,"I found qrcode xml");
399 DBG(r,"not found qrcode xml");
401 /*--------------------------------------------------------------------------*/
402 /* The CHTML structure is initialized. */
403 /*--------------------------------------------------------------------------*/
404 s_init_jhtml(&jhtml, &doc, r, spec);
406 jhtml.entryp = entryp;
407 jhtml.cookie = cookie;
409 chxj_set_content_type(r, "text/html; charset=Windows-31J");
411 /*--------------------------------------------------------------------------*/
412 /* The character string of the input is analyzed. */
413 /*--------------------------------------------------------------------------*/
414 qs_init_malloc(&doc);
415 qs_init_root_node(&doc);
417 ss = apr_pcalloc(r->pool, srclen + 1);
419 memset(ss, 0, srclen + 1);
420 memcpy(ss, src, srclen);
423 chxj_dump_out("[src] CHTML -> JHTML", ss, srclen);
426 qs_parse_string(&doc,ss,strlen(ss));
428 chxj_buffered_write_init(r->pool, &doc.buf);
429 /*--------------------------------------------------------------------------*/
430 /* It converts it from CHTML to JHTML. */
431 /*--------------------------------------------------------------------------*/
432 chxj_node_exchange(spec,r,(void*)&jhtml, &doc, qs_get_root(&doc), 0);
433 jhtml.out = chxj_buffered_write_flush(jhtml.out, &doc.buf);
434 dst = apr_pstrdup(r->pool, jhtml.out);
435 chxj_buffered_write_terminate(&doc.buf);
438 qs_all_free(&doc,QX_LOGMARK);
441 return apr_pstrdup(r->pool,ss);
444 dst = apr_psprintf(r->pool, "\n");
446 *dstlen = strlen(dst);
449 chxj_dump_out("[dst] CHTML -> JHTML", dst, *dstlen);
457 * The CHTML structure is initialized.
459 * @param jhtml [i/o] The pointer to the JHTML structure that wants to be
460 * initialized is specified.
461 * @param doc [i] The Doc structure that should be set to the initialized
462 * JHTML structure is specified.
463 * @param r [i] To use POOL, the pointer to request_rec is specified.
464 * @param spec [i] The pointer to the device_table
467 s_init_jhtml(jhtml_t* jhtml, Doc* doc, request_rec* r, device_table* spec)
469 memset(doc, 0, sizeof(Doc));
470 memset(jhtml, 0, sizeof(jhtml_t));
475 jhtml->out = qs_alloc_zero_byte_string(r);
476 jhtml->conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
477 jhtml->doc->parse_mode = PARSE_MODE_CHTML;
482 * Corresponding EMOJI to a current character-code is retrieved.
483 * The substitution character string is stored in the rslt pointer if agreeing.
485 * @param jhtml [i] The pointer to the CHTML structure is specified.
486 * @param txt [i] The character string to want to examine whether it is
487 * EMOJI is specified.
488 * @param rslt [o] The pointer to the pointer that stores the result is
490 * @return When corresponding EMOJI exists, it returns it excluding 0.
493 s_jhtml_search_emoji(jhtml_t *jhtml, char *txt, char **rslt)
505 if (! spec) DBG(r,"spec is NULL");
507 for (ee = jhtml->conf->emoji;
511 unsigned char hex1byte;
512 unsigned char hex2byte;
515 DBG(r,"emoji->imode is NULL");
519 hex1byte = ee->imode->hex1byte & 0xff;
520 hex2byte = ee->imode->hex2byte & 0xff;
522 if (ee->imode->string
523 && strlen(ee->imode->string) > 0
524 && strncasecmp(ee->imode->string, txt, strlen(ee->imode->string)) == 0) {
525 if (spec == NULL || spec->emoji_type == NULL) {
526 *rslt = apr_psprintf(r->pool,"
\e%s
\ f", ee->jphone->string);
527 return strlen(ee->imode->string);
534 && ((unsigned char)txt[0] & 0xff) == ((unsigned char)hex1byte)
535 && ((unsigned char)txt[1] & 0xff) == ((unsigned char)hex2byte)) {
536 if (spec == NULL || spec->emoji_type == NULL) {
537 *rslt = apr_psprintf(r->pool,"
\e%s
\ f", ee->jphone->string);
550 * It is a handler who processes the HTML tag.
552 * @param pdoc [i/o] The pointer to the CHTML structure at the output
553 * destination is specified.
554 * @param node [i] The HTML tag node is specified.
555 * @return The conversion result is returned.
558 s_jhtml_start_html_tag(void *pdoc, Node *UNUSED(node))
565 jhtml = GET_JHTML(pdoc);
568 DBG(r, "start s_jhtml_start_html_tag()");
570 /*--------------------------------------------------------------------------*/
572 /*--------------------------------------------------------------------------*/
575 DBG(r, "end s_jhtml_start_html_tag()");
582 * It is a handler who processes the HTML tag.
584 * @param pdoc [i/o] The pointer to the CHTML structure at the output
585 * destination is specified.
586 * @param node [i] The HTML tag node is specified.
587 * @return The conversion result is returned.
590 s_jhtml_end_html_tag(void *pdoc, Node *UNUSED(child))
592 jhtml_t *jhtml = GET_JHTML(pdoc);
593 Doc *doc = jhtml->doc;
602 * It is a handler who processes the META tag.
604 * @param pdoc [i/o] The pointer to the CHTML structure at the output
605 * destination is specified.
606 * @param node [i] The META tag node is specified.
607 * @return The conversion result is returned.
610 s_jhtml_start_meta_tag(void *pdoc, Node *node)
616 int content_type_flag;
619 jhtml = GET_JHTML(pdoc);
623 content_type_flag = 0;
626 /*--------------------------------------------------------------------------*/
628 /*--------------------------------------------------------------------------*/
629 for (attr = qs_get_attr(doc,node);
631 attr = qs_get_next_attr(doc,attr)) {
632 char *name = qs_get_attr_name(doc,attr);
633 char *value = qs_get_attr_value(doc,attr);
637 if (strcasecmp(name, "http-equiv") == 0) {
638 /*----------------------------------------------------------------------*/
640 /*----------------------------------------------------------------------*/
641 W_L(" http-equiv=\"");
644 if (STRCASEEQ('c','C',"content-type",value)) {
645 content_type_flag = 1;
647 if (STRCASEEQ('r','R',"refresh",value)) {
655 if (strcasecmp(name, "content") == 0) {
656 /*----------------------------------------------------------------------*/
658 /*----------------------------------------------------------------------*/
659 if (content_type_flag) {
663 W_L("text/html; charset=Windows-31J");
672 buf = apr_pstrdup(r->pool, value);
674 url = strchr(buf, ';');
676 sec = apr_pstrdup(r->pool, buf);
679 url = chxj_encoding_parameter(r, url);
680 url = chxj_add_cookie_parameter(r, url, jhtml->cookie);
710 * It is a handler who processes the META tag.
712 * @param pdoc [i/o] The pointer to the CHTML structure at the output
713 * destination is specified.
714 * @param node [i] The META tag node is specified.
715 * @return The conversion result is returned.
718 s_jhtml_end_meta_tag(void *pdoc, Node *UNUSED(child))
720 jhtml_t *jhtml = GET_JHTML(pdoc);
727 * It is a handler who processes the HEAD tag.
729 * @param pdoc [i/o] The pointer to the CHTML structure at the output
730 * destination is specified.
731 * @param node [i] The HEAD tag node is specified.
732 * @return The conversion result is returned.
735 s_jhtml_start_head_tag(void *pdoc, Node *UNUSED(node))
741 jhtml = GET_JHTML(pdoc);
751 * It is a handler who processes the HEAD tag.
753 * @param pdoc [i/o] The pointer to the CHTML structure at the output
754 * destination is specified.
755 * @param node [i] The HEAD tag node is specified.
756 * @return The conversion result is returned.
759 s_jhtml_end_head_tag(void *pdoc, Node *UNUSED(child))
765 jhtml = GET_JHTML(pdoc);
775 * It is a handler who processes the TITLE tag.
777 * @param pdoc [i/o] The pointer to the CHTML structure at the output
778 * destination is specified.
779 * @param node [i] The TITLE tag node is specified.
780 * @return The conversion result is returned.
783 s_jhtml_start_title_tag(void *pdoc, Node *UNUSED(node))
789 jhtml = GET_JHTML(pdoc);
799 * It is a handler who processes the TITLE tag.
801 * @param pdoc [i/o] The pointer to the CHTML structure at the output
802 * destination is specified.
803 * @param node [i] The TITLE tag node is specified.
804 * @return The conversion result is returned.
807 s_jhtml_end_title_tag(void *pdoc, Node *UNUSED(child))
813 jhtml = GET_JHTML(pdoc);
823 * It is a handler who processes the BASE tag.
825 * @param pdoc [i/o] The pointer to the CHTML structure at the output
826 * destination is specified.
827 * @param node [i] The BASE tag node is specified.
828 * @return The conversion result is returned.
831 s_jhtml_start_base_tag(void *pdoc, Node *node)
838 jhtml = GET_JHTML(pdoc);
843 /*--------------------------------------------------------------------------*/
845 /*--------------------------------------------------------------------------*/
846 for (attr = qs_get_attr(doc,node);
848 attr = qs_get_next_attr(doc,attr)) {
849 char *name = qs_get_attr_name(doc,attr);
850 char *value = qs_get_attr_value(doc,attr);
851 if (STRCASEEQ('h','H',"href",name)) {
863 * It is a handler who processes the BASE tag.
865 * @param pdoc [i/o] The pointer to the CHTML structure at the output
866 * destination is specified.
867 * @param node [i] The BASE tag node is specified.
868 * @return The conversion result is returned.
871 s_jhtml_end_base_tag(void *pdoc, Node *UNUSED(child))
873 jhtml_t *jhtml = GET_JHTML(pdoc);
879 * It is a handler who processes the BODY tag.
881 * @param pdoc [i/o] The pointer to the CHTML structure at the output
882 * destination is specified.
883 * @param node [i] The BODY tag node is specified.
884 * @return The conversion result is returned.
887 s_jhtml_start_body_tag(void *pdoc, Node *node)
894 jhtml = GET_JHTML(pdoc);
899 /*--------------------------------------------------------------------------*/
901 /*--------------------------------------------------------------------------*/
902 for (attr = qs_get_attr(doc,node);
904 attr = qs_get_next_attr(doc,attr)) {
905 char *name = qs_get_attr_name(doc,attr);
906 char *value = qs_get_attr_value(doc,attr);
907 if (STRCASEEQ('b','B',"bgcolor",name)) {
908 /*----------------------------------------------------------------------*/
910 /*----------------------------------------------------------------------*/
915 else if (STRCASEEQ('t','T',"text",name)) {
916 /*----------------------------------------------------------------------*/
918 /*----------------------------------------------------------------------*/
923 else if (STRCASEEQ('l','L',"link",name)) {
924 /*----------------------------------------------------------------------*/
926 /*----------------------------------------------------------------------*/
931 else if (STRCASEEQ('a','A',"alink",name)) {
932 /*----------------------------------------------------------------------*/
934 /*----------------------------------------------------------------------*/
937 else if (STRCASEEQ('v','V',"vlink",name)) {
938 /*----------------------------------------------------------------------*/
940 /*----------------------------------------------------------------------*/
950 * It is a handler who processes the BODY tag.
952 * @param pdoc [i/o] The pointer to the CHTML structure at the output
953 * destination is specified.
954 * @param node [i] The BODY tag node is specified.
955 * @return The conversion result is returned.
958 s_jhtml_end_body_tag(void *pdoc, Node *UNUSED(child))
964 jhtml = GET_JHTML(pdoc);
974 * It is a handler who processes the A tag.
976 * @param pdoc [i/o] The pointer to the CHTML structure at the output
977 * destination is specified.
978 * @param node [i] The A tag node is specified.
979 * @return The conversion result is returned.
982 s_jhtml_start_a_tag(void *pdoc, Node *node)
989 jhtml = GET_JHTML(pdoc);
994 /*--------------------------------------------------------------------------*/
996 /*--------------------------------------------------------------------------*/
997 for (attr = qs_get_attr(doc,node);
999 attr = qs_get_next_attr(doc,attr)) {
1000 char *name = qs_get_attr_name(doc,attr);
1001 char *value = qs_get_attr_value(doc,attr);
1002 if (STRCASEEQ('n','N',"name",name)) {
1003 /*----------------------------------------------------------------------*/
1005 /*----------------------------------------------------------------------*/
1010 else if (STRCASEEQ('h','H',"href",name)) {
1011 /*----------------------------------------------------------------------*/
1013 /*----------------------------------------------------------------------*/
1014 value = chxj_encoding_parameter(r, value);
1015 value = chxj_add_cookie_parameter(r, value, jhtml->cookie);
1020 else if (STRCASEEQ('a','A',"accesskey",name)) {
1021 /*----------------------------------------------------------------------*/
1023 /*----------------------------------------------------------------------*/
1024 W_L(" accesskey=\"");
1028 else if (STRCASEEQ('c','C',"cti",name)) {
1029 /*----------------------------------------------------------------------*/
1031 /*----------------------------------------------------------------------*/
1036 else if (STRCASEEQ('i','I',"ijam",name)) {
1037 /*----------------------------------------------------------------------*/
1039 /*----------------------------------------------------------------------*/
1042 else if (STRCASEEQ('u','U',"utn",name)) {
1043 /*----------------------------------------------------------------------*/
1045 /* It is special only for CHTML. */
1046 /*----------------------------------------------------------------------*/
1049 else if (STRCASEEQ('t','T',"telbook",name)) {
1050 /*----------------------------------------------------------------------*/
1052 /*----------------------------------------------------------------------*/
1055 else if (STRCASEEQ('k','K',"kana",name)) {
1056 /*----------------------------------------------------------------------*/
1058 /*----------------------------------------------------------------------*/
1061 else if (STRCASEEQ('e','E',"email",name)) {
1062 /*----------------------------------------------------------------------*/
1064 /*----------------------------------------------------------------------*/
1067 else if (STRCASEEQ('i','I',"ista",name)) {
1068 /*----------------------------------------------------------------------*/
1070 /*----------------------------------------------------------------------*/
1073 else if (STRCASEEQ('i','I',"ilet",name)) {
1074 /*----------------------------------------------------------------------*/
1076 /*----------------------------------------------------------------------*/
1079 else if (STRCASEEQ('i','I',"iswf",name)) {
1080 /*----------------------------------------------------------------------*/
1082 /*----------------------------------------------------------------------*/
1085 else if (STRCASEEQ('i','I',"irst",name)) {
1086 /*----------------------------------------------------------------------*/
1088 /*----------------------------------------------------------------------*/
1098 * It is a handler who processes the A tag.
1100 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1101 * destination is specified.
1102 * @param node [i] The A tag node is specified.
1103 * @return The conversion result is returned.
1106 s_jhtml_end_a_tag(void *pdoc, Node *UNUSED(child))
1112 jhtml = GET_JHTML(pdoc);
1122 * It is a handler who processes the BR tag.
1124 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1125 * destination is specified.
1126 * @param node [i] The BR tag node is specified.
1127 * @return The conversion result is returned.
1130 s_jhtml_start_br_tag(void *pdoc, Node *UNUSED(node))
1136 jhtml = GET_JHTML(pdoc);
1146 * It is a handler who processes the BR tag.
1148 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1149 * destination is specified.
1150 * @param node [i] The BR tag node is specified.
1151 * @return The conversion result is returned.
1154 s_jhtml_end_br_tag(void *pdoc, Node *UNUSED(child))
1156 jhtml_t *jhtml = GET_JHTML(pdoc);
1162 * It is a handler who processes the TR tag.
1164 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1165 * destination is specified.
1166 * @param node [i] The TR tag node is specified.
1167 * @return The conversion result is returned.
1170 s_jhtml_start_tr_tag(void *pdoc, Node *UNUSED(node))
1176 jhtml = GET_JHTML(pdoc);
1186 * It is a handler who processes the TR tag.
1188 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1189 * destination is specified.
1190 * @param node [i] The TR tag node is specified.
1191 * @return The conversion result is returned.
1194 s_jhtml_end_tr_tag(void *pdoc, Node *UNUSED(child))
1196 jhtml_t *jhtml = GET_JHTML(pdoc);
1202 * It is a handler who processes the FONT tag.
1204 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1205 * destination is specified.
1206 * @param node [i] The FONT tag node is specified.
1207 * @return The conversion result is returned.
1210 s_jhtml_start_font_tag(void *pdoc, Node *node)
1217 jhtml = GET_JHTML(pdoc);
1222 /*--------------------------------------------------------------------------*/
1223 /* Get Attributes */
1224 /*--------------------------------------------------------------------------*/
1225 for (attr = qs_get_attr(doc,node);
1227 attr = qs_get_next_attr(doc,attr)) {
1228 char *name = qs_get_attr_name(doc,attr);
1229 char *value = qs_get_attr_value(doc,attr);
1230 if (STRCASEEQ('c','C',"color",name)) {
1235 else if (STRCASEEQ('s','S',"size",name)) {
1236 /*----------------------------------------------------------------------*/
1238 /*----------------------------------------------------------------------*/
1248 * It is a handler who processes the FONT tag.
1250 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1251 * destination is specified.
1252 * @param node [i] The FONT tag node is specified.
1253 * @return The conversion result is returned.
1256 s_jhtml_end_font_tag(void *pdoc, Node *UNUSED(child))
1262 jhtml = GET_JHTML(pdoc);
1272 * It is a handler who processes the FORM tag.
1274 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1275 * destination is specified.
1276 * @param node [i] The FORM tag node is specified.
1277 * @return The conversion result is returned.
1280 s_jhtml_start_form_tag(void *pdoc, Node *node)
1287 jhtml = GET_JHTML(pdoc);
1291 /*--------------------------------------------------------------------------*/
1292 /* Get Attributes */
1293 /*--------------------------------------------------------------------------*/
1294 for (attr = qs_get_attr(doc,node);
1296 attr = qs_get_next_attr(doc,attr)) {
1297 char *name = qs_get_attr_name(doc,attr);
1298 char *value = qs_get_attr_value(doc,attr);
1299 if (STRCASEEQ('a','A',"action",name)) {
1300 /*----------------------------------------------------------------------*/
1302 /*----------------------------------------------------------------------*/
1307 else if (STRCASEEQ('m','M',"method",name)) {
1308 /*----------------------------------------------------------------------*/
1310 /*----------------------------------------------------------------------*/
1315 else if (STRCASEEQ('u','U',"utn",name)) {
1316 /*----------------------------------------------------------------------*/
1318 /* It is special only for CHTML. */
1319 /*----------------------------------------------------------------------*/
1324 if (jhtml->cookie && jhtml->cookie->cookie_id) {
1325 char *vv = apr_psprintf(doc->buf.pool, "%s<input type='hidden' name='%s' value='%s'>",
1328 chxj_url_decode(r, jhtml->cookie->cookie_id));
1336 * It is a handler who processes the FORM tag.
1338 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1339 * destination is specified.
1340 * @param node [i] The FORM tag node is specified.
1341 * @return The conversion result is returned.
1344 s_jhtml_end_form_tag(void *pdoc, Node *UNUSED(child))
1346 jhtml_t *jhtml = GET_JHTML(pdoc);
1347 Doc *doc = jhtml->doc;
1354 * It is a handler who processes the INPUT tag.
1356 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1357 * destination is specified.
1358 * @param node [i] The INPUT tag node is specified.
1359 * @return The conversion result is returned.
1362 s_jhtml_start_input_tag(void *pdoc, Node *node)
1376 jhtml = GET_JHTML(pdoc);
1389 /*--------------------------------------------------------------------------*/
1390 /* Get Attributes */
1391 /*--------------------------------------------------------------------------*/
1392 type = qs_get_type_attr(doc, node, r);
1393 name = qs_get_name_attr(doc, node, r);
1394 value = qs_get_value_attr(doc,node,r);
1395 istyle = qs_get_istyle_attr(doc,node,r);
1396 max_length = qs_get_maxlength_attr(doc,node,r);
1397 checked = qs_get_checked_attr(doc,node,r);
1398 accesskey = qs_get_accesskey_attr(doc, node, r);
1399 size = qs_get_size_attr(doc, node, r);
1422 W_L(" accesskey=\"");
1427 /*------------------------------------------------------------------------*/
1429 /*------------------------------------------------------------------------*/
1430 if (STRCASEEQ('p','P',"password", type) && ! jhtml->entryp->pc_flag ) {
1436 char *vv = chxj_istyle_to_mode(r,istyle);
1442 else if (istyle == NULL && type != NULL && STRCASEEQ('p','P',"password",type)) {
1447 /*--------------------------------------------------------------------------*/
1448 /* The figure is default for the password. */
1449 /*--------------------------------------------------------------------------*/
1451 W_L(" maxlength=\"");
1465 * It is a handler who processes the INPUT tag.
1467 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1468 * destination is specified.
1469 * @param node [i] The INPUT tag node is specified.
1470 * @return The conversion result is returned.
1473 s_jhtml_end_input_tag(void *pdoc, Node *UNUSED(child))
1475 jhtml_t *jhtml = GET_JHTML(pdoc);
1481 * It is a handler who processes the CENTER tag.
1483 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1484 * destination is specified.
1485 * @param node [i] The CENTER tag node is specified.
1486 * @return The conversion result is returned.
1489 s_jhtml_start_center_tag(void *pdoc, Node *UNUSED(node))
1491 jhtml_t *jhtml = GET_JHTML(pdoc);
1492 Doc *doc = jhtml->doc;
1499 * It is a handler who processes the CENTER tag.
1501 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1502 * destination is specified.
1503 * @param node [i] The CENTER tag node is specified.
1504 * @return The conversion result is returned.
1507 s_jhtml_end_center_tag(void *pdoc, Node *UNUSED(child))
1513 jhtml = GET_JHTML(pdoc);
1523 * It is a handler who processes the li tag.
1525 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1526 * destination is specified.
1527 * @param node [i] The li tag node is specified.
1528 * @return The conversion result is returned.
1531 s_jhtml_start_li_tag(void *pdoc, Node *UNUSED(node))
1537 jhtml = GET_JHTML(pdoc);
1547 * It is a handler who processes the li tag.
1549 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1550 * destination is specified.
1551 * @param node [i] The li tag node is specified.
1552 * @return The conversion result is returned.
1555 s_jhtml_end_li_tag(void *pdoc, Node *UNUSED(child))
1561 jhtml = GET_JHTML(pdoc);
1571 * It is a handler who processes the OL tag.
1573 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1574 * destination is specified.
1575 * @param node [i] The OL tag node is specified.
1576 * @return The conversion result is returned.
1579 s_jhtml_start_ol_tag(void *pdoc, Node *UNUSED(node))
1585 jhtml = GET_JHTML(pdoc);
1595 * It is a handler who processes the OL tag.
1597 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1598 * destination is specified.
1599 * @param node [i] The OL tag node is specified.
1600 * @return The conversion result is returned.
1603 s_jhtml_end_ol_tag(void *pdoc, Node *UNUSED(child))
1609 jhtml = GET_JHTML(pdoc);
1619 * It is a handler who processes the P tag.
1621 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1622 * destination is specified.
1623 * @param node [i] The P tag node is specified.
1624 * @return The conversion result is returned.
1627 s_jhtml_start_p_tag(void *pdoc, Node *UNUSED(node))
1633 jhtml = GET_JHTML(pdoc);
1643 * It is a handler who processes the P tag.
1645 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1646 * destination is specified.
1647 * @param node [i] The P tag node is specified.
1648 * @return The conversion result is returned.
1651 s_jhtml_end_p_tag(void *pdoc, Node *UNUSED(child))
1653 jhtml_t *jhtml = GET_JHTML(pdoc);
1654 Doc *doc = jhtml->doc;
1662 * It is a handler who processes the PRE tag.
1664 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1665 * destination is specified.
1666 * @param node [i] The PRE tag node is specified.
1667 * @return The conversion result is returned.
1670 s_jhtml_start_pre_tag(void *pdoc, Node *UNUSED(node))
1672 jhtml_t *jhtml = GET_JHTML(pdoc);
1673 Doc *doc = jhtml->doc;
1682 * It is a handler who processes the PRE tag.
1684 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1685 * destination is specified.
1686 * @param node [i] The PRE tag node is specified.
1687 * @return The conversion result is returned.
1690 s_jhtml_end_pre_tag(void *pdoc, Node *UNUSED(child))
1692 jhtml_t *jhtml = GET_JHTML(pdoc);
1693 Doc *doc = jhtml->doc;
1703 * It is a handler who processes the UL tag.
1705 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1706 * destination is specified.
1707 * @param node [i] The UL tag node is specified.
1708 * @return The conversion result is returned.
1711 s_jhtml_start_ul_tag(void *pdoc, Node *UNUSED(node))
1713 jhtml_t *jhtml = GET_JHTML(pdoc);
1714 Doc *doc = jhtml->doc;
1722 * It is a handler who processes the UL tag.
1724 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1725 * destination is specified.
1726 * @param node [i] The UL tag node is specified.
1727 * @return The conversion result is returned.
1730 s_jhtml_end_ul_tag(void *pdoc, Node *UNUSED(child))
1732 jhtml_t *jhtml = GET_JHTML(pdoc);
1733 Doc *doc = jhtml->doc;
1741 * It is a handler who processes the HR tag.
1743 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1744 * destination is specified.
1745 * @param node [i] The HR tag node is specified.
1746 * @return The conversion result is returned.
1749 s_jhtml_start_hr_tag(void *pdoc, Node *node)
1751 jhtml_t *jhtml = GET_JHTML(pdoc);
1752 Doc *doc = jhtml->doc;
1756 for (attr = qs_get_attr(doc,node);
1758 attr = qs_get_next_attr(doc,attr)) {
1759 char *name = qs_get_attr_name(doc,attr);
1760 char *value = qs_get_attr_value(doc,attr);
1761 if (STRCASEEQ('a','A',"align",name)) {
1762 /*----------------------------------------------------------------------*/
1764 /*----------------------------------------------------------------------*/
1769 else if (STRCASEEQ('s','S',"size",name)) {
1770 /*----------------------------------------------------------------------*/
1772 /*----------------------------------------------------------------------*/
1777 else if (STRCASEEQ('w','W',"width",name)) {
1778 /*----------------------------------------------------------------------*/
1780 /*----------------------------------------------------------------------*/
1785 else if (STRCASEEQ('n','N',"noshade",name)) {
1786 /*----------------------------------------------------------------------*/
1788 /*----------------------------------------------------------------------*/
1791 else if (STRCASEEQ('c','C',"color",name)) {
1792 /*----------------------------------------------------------------------*/
1794 /*----------------------------------------------------------------------*/
1804 * It is a handler who processes the HR tag.
1806 * @param jhtml [i/o] The pointer to the CHTML structure at the output
1807 * destination is specified.
1808 * @param node [i] The HR tag node is specified.
1809 * @return The conversion result is returned.
1812 s_jhtml_end_hr_tag(void *pdoc, Node *UNUSED(child))
1814 jhtml_t *jhtml = GET_JHTML(pdoc);
1820 * It is a handler who processes the IMG tag.
1822 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1823 * destination is specified.
1824 * @param node [i] The IMG tag node is specified.
1825 * @return The conversion result is returned.
1828 s_jhtml_start_img_tag(void *pdoc, Node *node)
1830 jhtml_t *jhtml = GET_JHTML(pdoc);
1831 Doc *doc = jhtml->doc;
1832 request_rec *r = doc->r;
1834 #ifndef IMG_NOT_CONVERT_FILENAME
1835 device_table *spec = jhtml->spec;
1839 /*--------------------------------------------------------------------------*/
1840 /* Get Attributes */
1841 /*--------------------------------------------------------------------------*/
1842 for (attr = qs_get_attr(doc,node);
1844 attr = qs_get_next_attr(doc,attr)) {
1845 char *name = qs_get_attr_name(doc,attr);
1846 char *value = qs_get_attr_value(doc,attr);
1847 if (STRCASEEQ('s','S',"src",name)) {
1848 /*----------------------------------------------------------------------*/
1850 /*----------------------------------------------------------------------*/
1851 #ifdef IMG_NOT_CONVERT_FILENAME
1852 value = chxj_encoding_parameter(r, value);
1853 value = chxj_add_cookie_parameter(r, value, jhtml->cookie);
1855 value = apr_psprintf(r->pool,
1858 (strchr(value, '?')) ? '&' : '?',
1859 CHXJ_COOKIE_NOUPDATE_PARAM);
1865 value = chxj_img_conv(r, spec, value);
1866 value = chxj_encoding_parameter(r, value);
1867 value = chxj_add_cookie_parameter(r, value, jhtml->cookie);
1869 value = apr_psprintf(r->pool,
1872 (strchr(value, '?')) ? '&' : '?',
1873 CHXJ_COOKIE_NOUPDATE_PARAM);
1880 else if (STRCASEEQ('a','A',"align",name)) {
1881 /*----------------------------------------------------------------------*/
1883 /*----------------------------------------------------------------------*/
1888 else if (STRCASEEQ('w','W',"width",name)) {
1889 /*----------------------------------------------------------------------*/
1891 /*----------------------------------------------------------------------*/
1896 else if (STRCASEEQ('h','H',"height",name)) {
1897 /*----------------------------------------------------------------------*/
1899 /*----------------------------------------------------------------------*/
1904 else if (STRCASEEQ('h','H',"hspace",name)) {
1905 /*----------------------------------------------------------------------*/
1907 /*----------------------------------------------------------------------*/
1912 else if (STRCASEEQ('v','V',"vspace",name)) {
1913 /*----------------------------------------------------------------------*/
1915 /*----------------------------------------------------------------------*/
1920 else if (STRCASEEQ('a','A',"alt",name)) {
1921 /*----------------------------------------------------------------------*/
1923 /*----------------------------------------------------------------------*/
1928 else if (STRCASEEQ('a','A',"align",name)) {
1929 /*----------------------------------------------------------------------*/
1931 /*----------------------------------------------------------------------*/
1941 * It is a handler who processes the IMG tag.
1943 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1944 * destination is specified.
1945 * @param node [i] The IMG tag node is specified.
1946 * @return The conversion result is returned.
1949 s_jhtml_end_img_tag(void *pdoc, Node *UNUSED(child))
1951 jhtml_t *jhtml = GET_JHTML(pdoc);
1957 * It is a handler who processes the SELECT tag.
1959 * @param pdoc [i/o] The pointer to the CHTML structure at the output
1960 * destination is specified.
1961 * @param node [i] The SELECT tag node is specified.
1962 * @return The conversion result is returned.
1965 s_jhtml_start_select_tag(void *pdoc, Node *child)
1967 jhtml_t *jhtml = GET_JHTML(pdoc);
1968 Doc *doc = jhtml->doc;
1975 for (attr = qs_get_attr(doc,child);
1977 attr = qs_get_next_attr(doc,attr)) {
1978 char *nm = qs_get_attr_name(doc,attr);
1979 char *val = qs_get_attr_value(doc,attr);
1980 if (STRCASEEQ('s','S',"size",nm)) {
1981 /*----------------------------------------------------------------------*/
1982 /* CHTML 1.0 version 2.0 */
1983 /*----------------------------------------------------------------------*/
1984 size = apr_pstrdup(doc->buf.pool, val);
1986 else if (STRCASEEQ('n','N',"name",nm)) {
1987 /*----------------------------------------------------------------------*/
1988 /* CHTML 1.0 version 2.0 */
1989 /*----------------------------------------------------------------------*/
1990 name = apr_pstrdup(doc->buf.pool, val);
1992 else if (STRCASEEQ('m','M',"multiple",nm)) {
1993 /*----------------------------------------------------------------------*/
1994 /* CHTML 1.0 version 2.0 */
1995 /*----------------------------------------------------------------------*/
2016 * It is a handler who processes the SELECT tag.
2018 * @param pdoc [i/o] The pointer to the CHTML structure at the output
2019 * destination is specified.
2020 * @param node [i] The SELECT tag node is specified.
2021 * @return The conversion result is returned.
2024 s_jhtml_end_select_tag(void *pdoc, Node *UNUSED(child))
2026 jhtml_t *jhtml = GET_JHTML(pdoc);
2027 Doc *doc = jhtml->doc;
2034 * It is a handler who processes the OPTION tag.
2036 * @param pdoc [i/o] The pointer to the CHTML structure at the output
2037 * destination is specified.
2038 * @param node [i] The OPTION tag node is specified.
2039 * @return The conversion result is returned.
2042 s_jhtml_start_option_tag(void *pdoc, Node *child)
2044 jhtml_t *jhtml = GET_JHTML(pdoc);
2045 Doc *doc = jhtml->doc;
2048 char *selected = NULL;
2052 for (attr = qs_get_attr(doc,child);
2054 attr = qs_get_next_attr(doc,attr)) {
2055 char *nm = qs_get_attr_name(doc,attr);
2056 char *val = qs_get_attr_value(doc,attr);
2057 if (STRCASEEQ('s','S',"selected",nm)) {
2058 /*----------------------------------------------------------------------*/
2059 /* CHTML 1.0 version 2.0 */
2060 /*----------------------------------------------------------------------*/
2061 selected = apr_pstrdup(doc->buf.pool, val);
2063 else if (STRCASEEQ('v','V',"value",nm)) {
2064 /*----------------------------------------------------------------------*/
2065 /* CHTML 1.0 version 2.0 */
2066 /*----------------------------------------------------------------------*/
2067 value = apr_pstrdup(doc->buf.pool, val);
2089 * It is a handler who processes the OPTION tag.
2091 * @param pdoc [i/o] The pointer to the CHTML structure at the output
2092 * destination is specified.
2093 * @param node [i] The OPTION tag node is specified.
2094 * @return The conversion result is returned.
2097 s_jhtml_end_option_tag(void *pdoc, Node *UNUSED(child))
2099 jhtml_t *jhtml = GET_JHTML(pdoc);
2106 * It is a handler who processes the DIV tag.
2108 * @param pdoc [i/o] The pointer to the CHTML structure at the output
2109 * destination is specified.
2110 * @param node [i] The DIV tag node is specified.
2111 * @return The conversion result is returned.
2114 s_jhtml_start_div_tag(void *pdoc, Node *child)
2122 jhtml = GET_JHTML(pdoc);
2129 for (attr = qs_get_attr(doc,child);
2131 attr = qs_get_next_attr(doc,attr)) {
2132 char *nm = qs_get_attr_name(doc,attr);
2133 char *val = qs_get_attr_value(doc,attr);
2134 if (STRCASEEQ('a','A',"align",nm)) {
2135 /*----------------------------------------------------------------------*/
2136 /* CHTML 1.0 (W3C version 3.2) */
2137 /*----------------------------------------------------------------------*/
2138 align = apr_pstrdup(doc->buf.pool, val);
2153 * It is a handler who processes the DIV tag.
2155 * @param pdoc [i/o] The pointer to the CHTML structure at the output
2156 * destination is specified.
2157 * @param node [i] The DIV tag node is specified.
2158 * @return The conversion result is returned.
2161 s_jhtml_end_div_tag(void *pdoc, Node *UNUSED(child))
2167 jhtml = GET_JHTML(pdoc);
2177 chxj_istyle_to_mode(request_rec *r, const char *s)
2183 case '1': return apr_psprintf(r->pool, "hiragana");
2184 case '2': return apr_psprintf(r->pool, "hankakukana");
2185 case '3': return apr_psprintf(r->pool, "alphabet");
2186 case '4': return apr_psprintf(r->pool, "numeric");
2188 tmp = apr_palloc(r->pool, 1);
2190 return apr_pstrdup(r->pool, tmp);
2194 tmp = apr_palloc(r->pool, 1);
2196 return apr_pstrdup(r->pool,tmp);
2201 s_jhtml_chxjif_tag(void *pdoc, Node *node)
2208 jhtml = GET_JHTML(pdoc);
2212 for (child = qs_get_child_node(doc, node);
2214 child = qs_get_next_node(doc, child)) {
2216 s_jhtml_chxjif_tag(jhtml, child);
2223 * It is a handler who processes the TEXTARE tag.
2225 * @param pdoc [i/o] The pointer to the CHTML structure at the output
2226 * destination is specified.
2227 * @param node [i] The TEXTAREA tag node is specified.
2228 * @return The conversion result is returned.
2231 s_jhtml_start_textarea_tag(void* pdoc, Node* node)
2238 jhtml = GET_JHTML(pdoc);
2242 jhtml->textarea_flag++;
2244 for (attr = qs_get_attr(doc,node);
2246 attr = qs_get_next_attr(doc,attr)) {
2251 name = qs_get_attr_name(doc,attr);
2252 value = qs_get_attr_value(doc,attr);
2254 if (STRCASEEQ('n','N',"name",name)) {
2259 else if (STRCASEEQ('r','R',"rows",name)) {
2264 else if (STRCASEEQ('c','C',"cols",name)) {
2276 * It is a handler who processes the TEXTAREA tag.
2278 * @param pdoc [i/o] The pointer to the CHTML structure at the output
2279 * destination is specified.
2280 * @param node [i] The TEXTAREA tag node is specified.
2281 * @return The conversion result is returned.
2284 s_jhtml_end_textarea_tag(void* pdoc, Node* UNUSED(child))
2290 jhtml = GET_JHTML(pdoc);
2294 W_L("</textarea>\r\n");
2295 jhtml->textarea_flag--;
2302 * It is a handler who processes the B tag.
2304 * @param pdoc [i/o] The pointer to the CHTML structure at the output
2305 * destination is specified.
2306 * @param node [i] The B tag node is specified.
2307 * @return The conversion result is returned.
2310 s_jhtml_start_b_tag(void* pdoc, Node* UNUSED(node))
2316 jhtml = GET_JHTML(pdoc);
2326 * It is a handler who processes the B tag.
2328 * @param pdoc [i/o] The pointer to the CHTML structure at the output
2329 * destination is specified.
2330 * @param node [i] The B tag node is specified.
2331 * @return The conversion result is returned.
2334 s_jhtml_end_b_tag(void* pdoc, Node* UNUSED(child))
2336 jhtml_t* jhtml = GET_JHTML(pdoc);
2337 Doc* doc = jhtml->doc;
2344 s_jhtml_text_tag(void* pdoc, Node* child)
2356 jhtml = GET_JHTML(pdoc);
2360 textval = qs_get_node_value(doc,child);
2361 textval = qs_trim_string(doc->buf.pool, textval);
2362 if (strlen(textval) == 0)
2365 tmp = apr_palloc(r->pool, qs_get_node_size(doc,child)+1);
2366 memset(tmp, 0, qs_get_node_size(doc,child)+1);
2368 tdst = qs_alloc_zero_byte_string(r);
2369 memset(one_byte, 0, sizeof(one_byte));
2372 for (ii=0; ii<qs_get_node_size(doc,child); ii++) {
2374 int rtn = s_jhtml_search_emoji(jhtml, &textval[ii], &out);
2376 tdst = qs_out_apr_pstrcat(r, tdst, out, &tdst_len);
2381 if (is_sjis_kanji(textval[ii])) {
2382 one_byte[0] = textval[ii+0];
2383 tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2384 one_byte[0] = textval[ii+1];
2385 tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2389 if (jhtml->pre_flag) {
2390 one_byte[0] = textval[ii+0];
2391 tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2394 if (jhtml->textarea_flag) {
2395 one_byte[0] = textval[ii+0];
2396 tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2399 if (textval[ii] != '\r' && textval[ii] != '\n') {
2400 one_byte[0] = textval[ii+0];
2401 tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);