OSDN Git Service

* Changed Mode=WP action for iPhone/Android.
[modchxj/mod_chxj.git] / src / chxj_iphone.c
1 /*
2  * Copyright (C) 2005-2011 Atsushi Konno All rights reserved.
3  * Copyright (C) 2005 QSDN,Inc. All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #include "chxj_iphone.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"
24 #include "chxj_str_util.h"
25 #include "chxj_header_inf.h"
26 #include "chxj_jreserved_tag.h"
27 #include "chxj_conv_z2h.h"
28 #include "chxj_google.h"
29
30
31 #define GET_IPHONE(X) ((iphone_t *)(X))
32 #undef W_L
33 #undef W_V
34 #define W_L(X)          do { iphone->out = BUFFERED_WRITE_LITERAL(iphone->out, &doc->buf, (X)); } while(0)
35 #define W_V(X)          do { iphone->out = (X) ? BUFFERED_WRITE_VALUE(iphone->out, &doc->buf, (X))  \
36                                                : BUFFERED_WRITE_LITERAL(iphone->out, &doc->buf, ""); } while(0)
37 #undef W_NLCODE
38 #define W_NLCODE()     do { char *nlcode = TO_NLCODE(iphone->conf); W_V(nlcode); } while (0)
39
40 #define BLINK_KEYFRAME \
41 "@-webkit-keyframes blink {" \
42 " 0% {" \
43 "   opacity: 1.0;" \
44 " }" \
45 " 100% {" \
46 "   opacity: 0.0;" \
47 " }" \
48 "}" 
49
50 #define STYLE_BLINK \
51 "-webkit-animation-name: blink;" \
52 "-webkit-animation-duration: 0.6s;" \
53 "-webkit-animation-iteration-count:infinite;" \
54 "-webkit-animation-timing-function:ease-in-out;" \
55 "-webkit-animation-direction: alternate;" \
56 "-webkit-animation-delay: 0s;"
57
58
59
60 static char *s_iphone_start_html_tag     (void *pdoc, Node *node);
61 static char *s_iphone_end_html_tag       (void *pdoc, Node *node);
62 static char *s_iphone_start_meta_tag     (void *pdoc, Node *node);
63 static char *s_iphone_end_meta_tag       (void *pdoc, Node *node);
64 static char *s_iphone_start_head_tag     (void *pdoc, Node *node);
65 static char *s_iphone_end_head_tag       (void *pdoc, Node *node);
66 static char *s_iphone_start_title_tag    (void *pdoc, Node *node);
67 static char *s_iphone_end_title_tag      (void *pdoc, Node *node);
68 static char *s_iphone_start_base_tag     (void *pdoc, Node *node);
69 static char *s_iphone_end_base_tag       (void *pdoc, Node *node);
70 static char *s_iphone_start_body_tag     (void *pdoc, Node *node);
71 static char *s_iphone_end_body_tag       (void *pdoc, Node *node);
72 static char *s_iphone_start_a_tag        (void *pdoc, Node *node);
73 static char *s_iphone_end_a_tag          (void *pdoc, Node *node);
74 static char *s_iphone_start_pre_tag      (void *pdoc, Node *node);
75 static char *s_iphone_end_pre_tag        (void *pdoc, Node *node);
76 static char *s_iphone_start_p_tag        (void *pdoc, Node *node);
77 static char *s_iphone_end_p_tag          (void *pdoc, Node *node);
78 static char *s_iphone_start_ul_tag       (void *pdoc, Node *node);
79 static char *s_iphone_end_ul_tag         (void *pdoc, Node *node);
80 static char *s_iphone_start_ol_tag       (void *pdoc, Node *node);
81 static char *s_iphone_end_ol_tag         (void *pdoc, Node *node);
82 static char *s_iphone_start_li_tag       (void *pdoc, Node *node);
83 static char *s_iphone_end_li_tag         (void *pdoc, Node *node);
84 static char *s_iphone_start_br_tag       (void *pdoc, Node *node);
85 static char *s_iphone_end_br_tag         (void *pdoc, Node *node);
86
87 static char *s_iphone_start_table_tag    (void *pdoc, Node *node);
88 static char *s_iphone_end_table_tag      (void *pdoc, Node *node);
89 static char *s_iphone_start_tr_tag       (void *pdoc, Node *node);
90 static char *s_iphone_end_tr_tag         (void *pdoc, Node *node);
91 static char *s_iphone_start_td_or_th_tag       (void *pdoc, Node *node,char *tagName);
92 static char *s_iphone_end_td_or_th_tag         (void *pdoc, Node *node,char *tagName);
93 static char *s_iphone_start_td_tag       (void *pdoc, Node *node);
94 static char *s_iphone_end_td_tag         (void *pdoc, Node *node);
95 static char *s_iphone_start_th_tag       (void *pdoc, Node *node);
96 static char *s_iphone_end_th_tag         (void *pdoc, Node *node);
97
98 static char *s_iphone_start_font_tag     (void *pdoc, Node *node);
99 static char *s_iphone_end_font_tag       (void *pdoc, Node *node);
100 static char *s_iphone_start_form_tag     (void *pdoc, Node *node);
101 static char *s_iphone_end_form_tag       (void *pdoc, Node *node);
102 static char *s_iphone_start_input_tag    (void *pdoc, Node *node);
103 static char *s_iphone_end_input_tag      (void *pdoc, Node *node);
104 static char *s_iphone_start_center_tag   (void *pdoc, Node *node);
105 static char *s_iphone_end_center_tag     (void *pdoc, Node *node);
106 static char *s_iphone_start_hr_tag       (void *pdoc, Node *node);
107 static char *s_iphone_end_hr_tag         (void *pdoc, Node *node);
108 static char *s_iphone_start_img_tag      (void *pdoc, Node *node);
109 static char *s_iphone_end_img_tag        (void *pdoc, Node *node);
110 static char *s_iphone_start_select_tag   (void *pdoc, Node *node);
111 static char *s_iphone_end_select_tag     (void *pdoc, Node *node);
112 static char *s_iphone_start_option_tag   (void *pdoc, Node *node);
113 static char *s_iphone_end_option_tag     (void *pdoc, Node *node);
114 static char *s_iphone_start_div_tag      (void *pdoc, Node *node);
115 static char *s_iphone_end_div_tag        (void *pdoc, Node *node);
116 static char *s_iphone_start_textarea_tag (void *pdoc, Node *node);
117 static char *s_iphone_end_textarea_tag   (void *pdoc, Node *node);
118 static char *s_iphone_start_b_tag        (void *pdoc, Node *node);
119 static char *s_iphone_end_b_tag          (void *pdoc, Node *node);
120 static char *s_iphone_chxjif_tag         (void *pdoc, Node *node); 
121 static char *s_iphone_text_tag           (void *pdoc, Node *node);
122 static char *s_iphone_start_blockquote_tag (void *pdoc, Node *node);
123 static char *s_iphone_end_blockquote_tag  (void *pdoc, Node *node);
124 static char *s_iphone_start_dir_tag      (void *pdoc, Node *node);
125 static char *s_iphone_end_dir_tag        (void *pdoc, Node *node);
126 static char *s_iphone_start_dl_tag       (void *pdoc, Node *node);
127 static char *s_iphone_end_dl_tag         (void *pdoc, Node *node);
128 static char *s_iphone_start_dt_tag       (void *pdoc, Node *node);
129 static char *s_iphone_end_dt_tag         (void *pdoc, Node *node);
130 static char *s_iphone_start_dd_tag       (void *pdoc, Node *node);
131 static char *s_iphone_end_dd_tag         (void *pdoc, Node *node);
132 static char *s_iphone_start_h1_tag       (void *pdoc, Node *node);
133 static char *s_iphone_end_h1_tag         (void *pdoc, Node *node);
134 static char *s_iphone_start_h2_tag       (void *pdoc, Node *node);
135 static char *s_iphone_end_h2_tag         (void *pdoc, Node *node);
136 static char *s_iphone_start_h3_tag       (void *pdoc, Node *node);
137 static char *s_iphone_end_h3_tag         (void *pdoc, Node *node);
138 static char *s_iphone_start_h4_tag       (void *pdoc, Node *node);
139 static char *s_iphone_end_h4_tag         (void *pdoc, Node *node);
140 static char *s_iphone_start_h5_tag       (void *pdoc, Node *node);
141 static char *s_iphone_end_h5_tag         (void *pdoc, Node *node);
142 static char *s_iphone_start_h6_tag       (void *pdoc, Node *node);
143 static char *s_iphone_end_h6_tag         (void *pdoc, Node *node);
144 static char *s_iphone_start_menu_tag     (void *pdoc, Node *node);
145 static char *s_iphone_end_menu_tag       (void *pdoc, Node *node);
146 static char *s_iphone_start_plaintext_tag       (void *pdoc, Node *node);
147 static char *s_iphone_start_plaintext_tag_inner (void *pdoc, Node *node);
148 static char *s_iphone_end_plaintext_tag         (void *pdoc, Node *node);
149 static char *s_iphone_start_blink_tag  (void *pdoc, Node *node);
150 static char *s_iphone_end_blink_tag    (void *pdoc, Node *node);
151 static char *s_iphone_start_marquee_tag (void *pdoc, Node *node);
152 static char *s_iphone_end_marquee_tag  (void *pdoc, Node *node);
153 static char *s_iphone_newline_mark       (void *pdoc, Node *node);
154 static char *s_iphone_link_tag           (void *pdoc, Node *node);
155 static char *s_iphone_start_span_tag     (void *pdoc, Node *node);
156 static char *s_iphone_end_span_tag       (void *pdoc, Node *node);
157 static char *s_iphone_style_tag       (void *pdoc, Node *node);
158 static char *s_iphone_start_object_tag     (void *pdoc, Node *node);
159 static char *s_iphone_end_object_tag       (void *pdoc, Node *node);
160 static char *s_iphone_start_param_tag     (void *pdoc, Node *node);
161 static char *s_iphone_start_caption_tag     (void *pdoc, Node *node);
162 static char *s_iphone_end_caption_tag       (void *pdoc, Node *node);
163
164 static void  s_init_iphone(iphone_t *iphone, Doc *doc, request_rec *r, device_table *spec);
165
166 static int   s_iphone_search_emoji(iphone_t *iphone, char *txt, char **rslt);
167
168 static css_prop_list_t *s_iphone_nopush_and_get_now_style(void *pdoc, Node *node, const char *style_attr_value);
169 static css_prop_list_t *s_iphone_push_and_get_now_style(void *pdoc, Node *node, const char *style_attr_value);
170 static char *s_iphone_create_style_data(apr_pool_t *pool, const char *style_data);
171
172
173
174 tag_handler iphone_handler[] = {
175   /* tagHTML */
176   {
177     s_iphone_start_html_tag,
178     s_iphone_end_html_tag,
179   },
180   /* tagMETA */
181   {
182     s_iphone_start_meta_tag,
183     s_iphone_end_meta_tag,
184   },
185   /* tagTEXTAREA */
186   {
187     s_iphone_start_textarea_tag,
188     s_iphone_end_textarea_tag,
189   },
190   /* tagP */
191   {
192     s_iphone_start_p_tag,
193     s_iphone_end_p_tag,
194   },
195   /* tagPRE */
196   {
197     s_iphone_start_pre_tag,
198     s_iphone_end_pre_tag,
199   },
200   /* tagUL */
201   {
202     s_iphone_start_ul_tag,
203     s_iphone_end_ul_tag,
204   },
205   /* tagLI */
206   {
207     s_iphone_start_li_tag,
208     s_iphone_end_li_tag,
209   },
210   /* tagOL */
211   {
212     s_iphone_start_ol_tag,
213     s_iphone_end_ol_tag,
214   },
215   /* tagH1 */
216   {
217     s_iphone_start_h1_tag,
218     s_iphone_end_h1_tag,
219   },
220   /* tagH2 */
221   {
222     s_iphone_start_h2_tag,
223     s_iphone_end_h2_tag,
224   },
225   /* tagH3 */
226   {
227     s_iphone_start_h3_tag,
228     s_iphone_end_h3_tag,
229   },
230   /* tagH4 */
231   {
232     s_iphone_start_h4_tag,
233     s_iphone_end_h4_tag,
234   },
235   /* tagH5 */
236   {
237     s_iphone_start_h5_tag,
238     s_iphone_end_h5_tag,
239   },
240   /* tagH6 */
241   {
242     s_iphone_start_h6_tag,
243     s_iphone_end_h6_tag,
244   },
245   /* tagHEAD */
246   {
247     s_iphone_start_head_tag,
248     s_iphone_end_head_tag,
249   },
250   /* tagTITLE */
251   {
252     s_iphone_start_title_tag,
253     s_iphone_end_title_tag,
254   },
255   /* tagBASE */
256   {
257     s_iphone_start_base_tag,
258     s_iphone_end_base_tag,
259   },
260   /* tagBODY */
261   {
262     s_iphone_start_body_tag,
263     s_iphone_end_body_tag,
264   },
265   /* tagA */
266   {
267     s_iphone_start_a_tag,
268     s_iphone_end_a_tag,
269   },
270   /* tagBR */
271   {
272     s_iphone_start_br_tag,
273     s_iphone_end_br_tag,
274   },
275   /* tagTABLE */
276   {
277     s_iphone_start_table_tag,
278     s_iphone_end_table_tag,
279   },
280   /* tagTR */
281   {
282     s_iphone_start_tr_tag,
283     s_iphone_end_tr_tag,
284   },
285   /* tagTD */
286   {
287     s_iphone_start_td_tag,
288     s_iphone_end_td_tag,
289   },
290   /* tagTBODY */
291   {
292     NULL,
293     NULL,
294   },
295   /* tagFONT */
296   {
297     s_iphone_start_font_tag,
298     s_iphone_end_font_tag,
299   },
300   /* tagFORM */
301   {
302     s_iphone_start_form_tag,
303     s_iphone_end_form_tag,
304   },
305   /* tagINPUT */
306   {
307     s_iphone_start_input_tag,
308     s_iphone_end_input_tag,
309   },
310   /* tagCENTER */
311   {
312     s_iphone_start_center_tag,
313     s_iphone_end_center_tag,
314   },
315   /* tagHR */
316   {
317     s_iphone_start_hr_tag,
318     s_iphone_end_hr_tag,
319   },
320   /* tagIMG */
321   {
322     s_iphone_start_img_tag,
323     s_iphone_end_img_tag,
324   },
325   /* tagSELECT */
326   {
327     s_iphone_start_select_tag,
328     s_iphone_end_select_tag,
329   },
330   /* tagOPTION */
331   {
332     s_iphone_start_option_tag,
333     s_iphone_end_option_tag,
334   },
335   /* tagDIV */
336   {
337     s_iphone_start_div_tag,
338     s_iphone_end_div_tag,
339   },
340   /* tagCHXJIF */
341   {
342     s_iphone_chxjif_tag,
343     NULL,
344   },
345   /* tagCHXJRAW */
346   {
347     s_iphone_chxjif_tag,
348     NULL,
349   },
350   /* tagNOBR */
351   {
352     NULL,
353     NULL,
354   },
355   /* tagSMALL */
356   {
357     NULL,
358     NULL,
359   },
360   /* tagSTYLE */
361   {
362     s_iphone_style_tag,
363     NULL,
364   },
365   /* tagSPAN */
366   {
367     s_iphone_start_span_tag,
368     s_iphone_end_span_tag,
369   },
370   /* tagTEXT */
371   {
372     s_iphone_text_tag,
373     NULL,
374   },
375   /* tagTH */
376   {
377     s_iphone_start_th_tag,
378     s_iphone_end_th_tag,
379   },
380   /* tagB */
381   {
382     s_iphone_start_b_tag,
383     s_iphone_end_b_tag,
384   },
385   /* tagFIELDSET */
386   {
387     NULL,
388     NULL,
389   },
390   /* tagDT */
391   {
392     s_iphone_start_dt_tag,
393     s_iphone_end_dt_tag,
394   },
395   /* tagLEGEND */
396   {
397     NULL,
398     NULL,
399   },
400   /* tagLABEL */
401   {
402     NULL,
403     NULL,
404   },
405   /* tagBLOCKQUOTE */
406   {
407     s_iphone_start_blockquote_tag,
408     s_iphone_end_blockquote_tag,
409   },
410   /* tagDIR */
411   {
412     s_iphone_start_dir_tag,
413     s_iphone_end_dir_tag,
414   },
415   /* tagDL */
416   {
417     s_iphone_start_dl_tag,
418     s_iphone_end_dl_tag,
419   },
420   /* tagDD */
421   {
422     s_iphone_start_dd_tag,
423     s_iphone_end_dd_tag,
424   },
425   /* tagMENU */
426   {
427     s_iphone_start_menu_tag,
428     s_iphone_end_menu_tag,
429   },
430   /* tagPLAINTEXT */
431   {
432     s_iphone_start_plaintext_tag,
433     s_iphone_end_plaintext_tag,
434   },
435   /* tagBLINK */
436   {
437     s_iphone_start_blink_tag,
438     s_iphone_end_blink_tag,
439   },
440   /* tagMARQUEE */
441   {
442     s_iphone_start_marquee_tag,
443     s_iphone_end_marquee_tag,
444   },
445   /* tagLINK */
446   {
447     s_iphone_link_tag,
448     NULL,
449   },
450   /* tagNLMARK */
451   {
452     s_iphone_newline_mark,
453     NULL,
454   },
455   /* tagObject */
456   {
457     s_iphone_start_object_tag,
458     s_iphone_end_object_tag,
459   },
460   /* tagParam */
461   {
462     s_iphone_start_param_tag,
463     NULL,
464   },
465   /* tagCAPTION */
466   {
467     s_iphone_start_caption_tag,
468     s_iphone_end_caption_tag,
469   },
470 };
471
472
473 /**
474  * converts from CHTML5.0 to IPHONE.
475  *
476  * @param r     [i]   Requet_rec is appointed.
477  * @param spec  [i]   The result of the device specification processing which 
478  *                    was done in advance is appointed.
479  * @param src   [i]   The character string before the converting is appointed.
480  * @return The character string after the converting is returned.
481  */
482 char *
483 chxj_convert_iphone(
484   request_rec         *r,
485   device_table        *spec,
486   const char          *src,
487   apr_size_t          srclen,
488   apr_size_t          *dstlen,
489   chxjconvrule_entry  *entryp,
490   cookie_t            *cookie
491 )
492 {
493   char      *dst;
494   char      *ss;
495   iphone_t   iphone;
496   Doc       doc;
497
498   dst = NULL;
499
500   /*--------------------------------------------------------------------------*/
501   /* If qrcode xml                                                            */
502   /*--------------------------------------------------------------------------*/
503   *dstlen = srclen;
504   dst = chxj_qr_code_blob_handler(r, src, (size_t*)dstlen);
505   if (dst) {
506     DBG(r,"REQ[%X] I found qrcode xml",TO_ADDR(r));
507     return dst;
508   }
509
510   /*--------------------------------------------------------------------------*/
511   /* The CHTML structure is initialized.                                      */
512   /*--------------------------------------------------------------------------*/
513   s_init_iphone(&iphone, &doc, r, spec);
514
515   iphone.entryp = entryp;
516   iphone.cookie = cookie;
517   iphone.head_tag_out = 0;
518   if (strcasecmp(spec->output_encoding,"UTF-8") == 0 ){
519     apr_table_setn(r->headers_out,HTTP_X_CHXJ_SET_CONTENT_TYPE,"application/xhtml+xml; charset=UTF-8");
520   }
521   chxj_set_content_type(r, chxj_header_inf_set_content_type(r, "application/xhtml+xml; charset=Windows-31J"));
522
523   /*--------------------------------------------------------------------------*/
524   /* The character string of the input is analyzed.                           */
525   /*--------------------------------------------------------------------------*/
526   qs_init_malloc(&doc);
527   qs_init_root_node(&doc);
528
529   ss = apr_pcalloc(r->pool, srclen + 1);
530
531   memset(ss,   0, srclen + 1);
532   memcpy(ss, src, srclen);
533
534   if (IS_CSS_ON(iphone.entryp)) {
535     /* current property list */
536     iphone.css_prop_stack = chxj_new_prop_list_stack(&doc);
537   }
538 #ifdef DUMP_LOG
539   chxj_dump_out("[src] CHTML -> IPHONE", ss, srclen);
540 #endif
541
542   qs_parse_string(&doc,ss,strlen(ss));
543
544   chxj_buffered_write_init(r->pool, &doc.buf);
545   /*--------------------------------------------------------------------------*/
546   /* It converts it from CHTML to IPHONE.                                     */
547   /*--------------------------------------------------------------------------*/
548   chxj_node_convert(spec,r,(void*)&iphone, &doc, qs_get_root(&doc), 0);
549   iphone.out = chxj_buffered_write_flush(iphone.out, &doc.buf);
550   dst = apr_pstrcat(r->pool, (! iphone.prev_style_data) ? "" : iphone.prev_style_data,
551                              s_iphone_create_style_data(doc.pool, iphone.style_data),
552                              iphone.out, NULL);
553   chxj_buffered_write_terminate(&doc.buf);
554
555
556   qs_all_free(&doc,QX_LOGMARK);
557
558   if (! dst) 
559     return apr_pstrdup(r->pool,ss);
560
561   if (! strlen(dst)) 
562     dst = apr_psprintf(r->pool, "\n");
563
564   *dstlen = strlen(dst);
565
566 #ifdef DUMP_LOG
567   chxj_dump_out("[dst] CHTML -> IPHONE", dst, *dstlen);
568 #endif
569
570   return dst;
571 }
572
573
574 /**
575  * The IPHONE structure is initialized.
576  *
577  * @param iphone [i/o] The pointer to the IPHONE structure that wants to be
578  *                   initialized is specified.
579  * @param doc   [i]   The Doc structure that should be set to the initialized
580  *                   IPHONE structure is specified.
581  * @param r     [i]   To use POOL, the pointer to request_rec is specified.
582  * @param spec  [i]   The pointer to the device_table
583  */
584 static void
585 s_init_iphone(iphone_t *iphone, Doc *doc, request_rec *r, device_table *spec)
586 {
587   memset(doc,   0, sizeof(Doc));
588   memset(iphone, 0, sizeof(iphone_t));
589
590   doc->r      = r;
591   iphone->doc  = doc;
592   iphone->spec = spec;
593   iphone->out  = qs_alloc_zero_byte_string(r->pool);
594   iphone->conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
595   iphone->doc->parse_mode = PARSE_MODE_CHTML;
596   iphone->prev_style_data = NULL;
597   iphone->style_data = NULL;
598   iphone->blink_keyframe_out = 0;
599 }
600
601
602 /**
603  * Corresponding EMOJI to a current character-code is retrieved. 
604  * The substitution character string is stored in the rslt pointer if agreeing.
605  *
606  * @param iphone   [i]   The pointer to the IPHONE structure is specified. 
607  * @param txt     [i]   The character string to want to examine whether it is 
608  *                      EMOJI is specified. 
609  * @param rslt    [o]   The pointer to the pointer that stores the result is 
610  *                      specified. 
611  * @return When corresponding EMOJI exists, it returns it excluding 0. 
612  */
613 static int
614 s_iphone_search_emoji(iphone_t *iphone, char *txt, char **rslt)
615 {
616   emoji_t       *ee;
617   request_rec   *r;
618   device_table  *spec;
619   int           len;
620
621   spec = iphone->spec;
622
623   len = strlen(txt);
624   r = iphone->doc->r;
625
626   if (! spec) DBG(r,"REQ[%X] spec is NULL",TO_ADDR(r));
627
628   for (ee = iphone->conf->emoji;
629        ee;
630        ee = ee->next) {
631
632     unsigned char hex1byte;
633     unsigned char hex2byte;
634
635     if (! ee->imode) { 
636       DBG(r,"REQ[%X] emoji->imode is NULL",TO_ADDR(r));
637       continue;
638     }
639
640     hex1byte = ee->imode->hex1byte & 0xff;
641     hex2byte = ee->imode->hex2byte & 0xff;
642
643     if (ee->imode->string
644     &&  strlen(ee->imode->string) > 0
645     &&  strncasecmp(ee->imode->string, txt, strlen(ee->imode->string)) == 0) {
646       if (spec == NULL || spec->emoji_type == NULL) {
647         if (ee->iphone != NULL && ee->iphone->string != NULL) {
648           if (iphone->conf->use_emoji_image
649               && iphone->conf->emoji_image_url
650               && (spec->html_spec_type == CHXJ_SPEC_iPhone2
651                 || strcasecmp(ee->iphone->string,"image") == 0)) {
652             *rslt = apr_psprintf(r->pool, "<img src=\"%s/%d\" />",iphone->conf->emoji_image_url, ee->no);
653           }
654           else if (strncasecmp(ee->iphone->string, "raw:", 4) == 0) {
655             *rslt = apr_psprintf(r->pool,"%s", &(ee->iphone->string[4]));
656           }
657           else {
658             *rslt = apr_psprintf(r->pool,"%s;", ee->iphone->string);
659           }
660         }
661         return strlen(ee->imode->string);
662       }
663       return 0;
664     }
665
666     if (len >= 2
667     && ((unsigned char)txt[0] & 0xff) == ((unsigned char)hex1byte)
668     && ((unsigned char)txt[1] & 0xff) == ((unsigned char)hex2byte)) {
669       if (spec == NULL || spec->emoji_type == NULL) {
670         if (ee->iphone != NULL && ee->iphone->string != NULL) {
671           if (iphone->conf->use_emoji_image
672               && iphone->conf->emoji_image_url
673               && (spec->html_spec_type == CHXJ_SPEC_iPhone2
674                 || strcasecmp(ee->iphone->string,"image") == 0)) {
675             *rslt = apr_psprintf(r->pool, "<img src=\"%s/%d\" />",iphone->conf->emoji_image_url, ee->no);
676           }
677           else if (strncasecmp(ee->iphone->string, "raw:", 4) == 0) {
678             *rslt = apr_psprintf(r->pool,"%s", &(ee->iphone->string[4]));
679           }
680           else {
681             *rslt = apr_psprintf(r->pool,"%s;", ee->iphone->string);
682           }
683         }
684         return 2;
685       }
686
687       return 0;
688     }
689   }
690
691   return 0;
692 }
693
694
695 char *
696 chxj_iphone_emoji_only_converter(request_rec *r, device_table *spec, const char *src, apr_size_t len)
697 {
698   apr_size_t ii;
699   Doc __doc;
700   Doc *doc;
701   iphone_t __iphone;
702   iphone_t *iphone;
703   char one_byte[2];
704   char two_byte[3];
705   apr_pool_t *pool;
706
707   iphone = &__iphone;
708   doc    = &__doc;
709
710   DBG(r,"REQ[%X] start %s()",TO_ADDR(r),__func__);
711   memset(doc,    0, sizeof(Doc));
712   memset(iphone, 0, sizeof(iphone_t));
713
714   doc->r       = r;
715   iphone->doc  = doc;
716   iphone->spec = spec;
717   iphone->out  = qs_alloc_zero_byte_string(r->pool);
718   iphone->conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
719   iphone->doc->parse_mode = PARSE_MODE_CHTML;
720
721   apr_pool_create(&pool, r->pool);
722
723   chxj_buffered_write_init(pool, &doc->buf);
724
725   for (ii=0; ii<len; ii++) {
726     char *out;
727     int   rtn;
728
729     rtn = s_iphone_search_emoji(iphone, (char *)&src[ii], &out);
730     if (rtn) {
731       W_V(out);
732       ii+=(rtn - 1);
733       continue;
734     }
735
736     if (is_sjis_kanji(src[ii])) {
737       two_byte[0] = src[ii+0];
738       two_byte[1] = src[ii+1];
739       two_byte[2] = 0;
740       W_V(two_byte);
741       ii++;
742     }
743     else {
744       one_byte[0] = src[ii+0];
745       one_byte[1] = 0;
746       W_V(one_byte);
747     }
748   }
749   iphone->out = chxj_buffered_write_flush(iphone->out, &doc->buf);
750
751   DBG(r,"REQ[%X] end %s()",TO_ADDR(r),__func__);
752   return iphone->out;
753 }
754
755
756 /**
757  * It is a handler who processes the HTML tag.
758  *
759  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
760  *                     destination is specified.
761  * @param node   [i]   The HTML tag node is specified.
762  * @return The conversion result is returned.
763  */
764 static char *
765 s_iphone_start_html_tag(void *pdoc, Node *UNUSED(node)) 
766 {
767   iphone_t       *iphone;
768   Doc           *doc;
769   request_rec   *r;
770
771
772   iphone  = GET_IPHONE(pdoc);
773   doc    = iphone->doc;
774   r      = doc->r;
775   DBG(r,"REQ[%X] start %s()",TO_ADDR(r),__func__);
776
777   W_L("<?xml version=\"1.0\" encoding=\"");
778   W_V(iphone->spec->output_encoding);
779   W_L("\" ?>");
780   W_NLCODE();
781   W_L("<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.1//EN\" \"http://www.openmobilealliance.org/tech/DTD/xhtml-mobile11.dtd\">");
782   W_NLCODE();
783
784
785   /*--------------------------------------------------------------------------*/
786   /* start HTML tag                                                           */
787   /*--------------------------------------------------------------------------*/
788   W_L("<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"ja\" xml:lang=\"ja\">");
789
790   iphone->start_html_flag = 1;
791
792   DBG(r,"REQ[%X] end %s()",TO_ADDR(r),__func__);
793
794   return iphone->out;
795 }
796
797
798 /**
799  * It is a handler who processes the HTML tag.
800  *
801  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
802  *                     destination is specified.
803  * @param node   [i]   The HTML tag node is specified.
804  * @return The conversion result is returned.
805  */
806 static char *
807 s_iphone_end_html_tag(void *pdoc, Node *UNUSED(child)) 
808 {
809   iphone_t      *iphone = GET_IPHONE(pdoc);
810   Doc           *doc = iphone->doc;
811
812   W_L("</html>");
813
814   return iphone->out;
815 }
816
817
818 /**
819  * It is a handler who processes the META tag.
820  *
821  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
822  *                     destination is specified.
823  * @param node   [i]   The META tag node is specified.
824  * @return The conversion result is returned.
825  */
826 static char *
827 s_iphone_start_meta_tag(void *pdoc, Node *node) 
828 {
829   iphone_t     *iphone;
830   Doc          *doc;
831   request_rec  *r;
832   Attr         *attr;
833   int          content_type_flag;
834   int          refresh_flag;
835
836   iphone             = GET_IPHONE(pdoc);
837   doc               = iphone->doc;
838   r                 = doc->r;
839   refresh_flag      = 0;
840   content_type_flag = 0;
841
842   W_L("<meta");
843   /*--------------------------------------------------------------------------*/
844   /* Get Attributes                                                           */
845   /*--------------------------------------------------------------------------*/
846   for (attr = qs_get_attr(doc,node);
847        attr;
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     switch(*name) {
852     case 'h':
853     case 'H':
854       if (strcasecmp(name, "http-equiv") == 0 && value && *value) {
855         /*----------------------------------------------------------------------*/
856         /* CHTML 2.0                                                            */
857         /*----------------------------------------------------------------------*/
858         W_L(" http-equiv=\"");
859         W_V(value);
860         W_L("\"");
861         if (STRCASEEQ('c','C',"content-type",value)) {
862           content_type_flag = 1;
863         }
864         if (STRCASEEQ('r','R',"refresh",value)) {
865           refresh_flag = 1;
866         }
867       }
868       break;
869
870     case 'c':
871     case 'C':
872       if (strcasecmp(name, "content") == 0 && value && *value) {
873         /*----------------------------------------------------------------------*/
874         /* CHTML 2.0                                                            */
875         /*----------------------------------------------------------------------*/
876         if (content_type_flag)  {
877           W_L(" ");
878           W_V(name);
879           W_L("=\"");
880           W_V(chxj_header_inf_set_content_type(r, "application/xhtml+xml; charset=SHIFT_JIS"));
881           W_L("\"");
882         }
883         else
884         if (refresh_flag) {
885           char *buf;
886           char *sec;
887           char *url;
888   
889           buf = apr_pstrdup(r->pool, value);
890   
891           url = strchr(buf, ';');
892           if (url) {
893             sec = apr_pstrdup(r->pool, buf);
894             sec[url-buf] = 0;
895             url++;
896             url = chxj_encoding_parameter(r, url, 1);
897             W_L(" ");
898             W_V(name);
899             W_L("=\"");
900             W_V(sec);
901             W_L(";");
902             W_V(url);
903             W_L("\"");
904           }
905         }
906         else {
907           W_L(" ");
908           W_V(name);
909           W_L("=\"");
910           W_V(value);
911           W_L("\"");
912         }
913       }
914       break;
915     case 'n':
916     case 'N':
917       if (strcasecmp(name, "name") == 0 && value && *value) {
918         W_L(" name=\"");
919         W_V(value);
920         W_L("\"");
921       }
922       break;
923     default:
924       break;
925     }
926   }
927   W_L(" />");
928   return iphone->out;
929 }
930
931
932 /**
933  * It is a handler who processes the META tag.
934  *
935  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
936  *                     destination is specified.
937  * @param node   [i]   The META tag node is specified.
938  * @return The conversion result is returned.
939  */
940 static char *
941 s_iphone_end_meta_tag(void *pdoc, Node *UNUSED(child)) 
942 {
943   iphone_t *iphone = GET_IPHONE(pdoc);
944
945   return iphone->out;
946 }
947
948
949 /**
950  * It is a handler who processes the HEAD tag.
951  *
952  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
953  *                     destination is specified.
954  * @param node   [i]   The HEAD tag node is specified.
955  * @return The conversion result is returned.
956  */
957 static char *
958 s_iphone_start_head_tag(void *pdoc, Node *node) 
959 {
960   iphone_t      *iphone;
961   Attr          *attr;
962   Doc           *doc;
963   Node          *child;
964   request_rec   *r;
965
966   iphone = GET_IPHONE(pdoc);
967   doc   = iphone->doc;
968   r     = doc->r;
969   iphone->head_tag_out = 1;
970
971   W_L("<head>");
972
973   /* search <meta name="viewport"> */
974   int found_viewport = 0;
975   for (child = qs_get_child_node(doc,node);
976        child;
977        child = qs_get_next_node(doc,child)) {
978     char *name = qs_get_node_name(doc,child);
979     switch(*name) {
980     case 'm':
981     case 'M':
982       if (strcasecmp("meta",name) == 0) {
983         for (attr = qs_get_attr(doc,child);
984              attr;
985              attr = qs_get_next_attr(doc,attr)) {
986           char *aname  = qs_get_attr_name(doc,attr);
987           char *avalue = qs_get_attr_value(doc,attr);
988           if (STRCASEEQ('n','N',"name",aname)) {
989             if (STRCASEEQ('v','V',"viewport",avalue)) {
990               found_viewport = 1;
991               DBG(r, "REQ[%X] viewport Found!!",TO_ADDR(r));
992               break;
993             }
994           }
995         }
996       }
997       break;
998
999     default: 
1000       break;
1001     }
1002     if (found_viewport) {
1003       break;
1004     }
1005   }
1006
1007   if (!found_viewport) {
1008     W_L("<meta ");
1009     W_L("name=\"viewport\" ");
1010     W_L("id=\"iphone-viewport\" ");
1011     W_L("content=\"width=");
1012     char *ww = apr_psprintf(r->pool, "%d", (int)((double)iphone->spec->width * (double)1.5));
1013     W_V(ww);
1014     W_L(",user-scalable=no,maximum-scale=0.6667\" />");
1015     W_L("<meta name=\"format-detection\" content=\"telephone=no\" />");
1016   }
1017   return iphone->out;
1018 }
1019
1020
1021 /**
1022  * It is a handler who processes the HEAD tag.
1023  *
1024  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
1025  *                     destination is specified.
1026  * @param node   [i]   The HEAD tag node is specified.
1027  * @return The conversion result is returned.
1028  */
1029 static char *
1030 s_iphone_end_head_tag(void *pdoc, Node *UNUSED(child)) 
1031 {
1032   iphone_t       *iphone;
1033   Doc           *doc;
1034   request_rec   *r;
1035
1036   iphone = GET_IPHONE(pdoc);
1037   doc   = iphone->doc;
1038   r     = doc->r;
1039
1040 #if 0
1041   W_L("<style>");
1042   W_NLCODE();
1043   W_L(BLINK_KEYFRAME);
1044   W_NLCODE();
1045   W_L("</style>");
1046 #endif
1047   iphone->out = chxj_buffered_write_flush(iphone->out, &doc->buf);
1048   iphone->prev_style_data = apr_pstrdup(doc->pool, iphone->out);
1049   iphone->out = qs_alloc_zero_byte_string(r->pool);
1050
1051   W_L("</head>");
1052   return iphone->out;
1053 }
1054
1055
1056 /**
1057  * It is a handler who processes the TITLE tag.
1058  *
1059  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
1060  *                     destination is specified.
1061  * @param node   [i]   The TITLE tag node is specified.
1062  * @return The conversion result is returned.
1063  */
1064 static char *
1065 s_iphone_start_title_tag(void *pdoc, Node *node)
1066 {
1067   iphone_t      *iphone;
1068   Doc          *doc;
1069   request_rec  *r;
1070
1071   iphone = GET_IPHONE(pdoc);
1072   doc   = iphone->doc;
1073   r     = doc->r;
1074
1075   W_L("<title>");
1076   if (iphone->conf->use_google_analytics) {
1077     iphone->pagetitle = "";
1078     Node         *child;
1079     for (child = qs_get_child_node(doc,node);
1080          child;
1081          child = qs_get_next_node(doc,child)) {
1082       char *textval = qs_get_node_value(doc,child);
1083       iphone->pagetitle = apr_pstrcat(doc->r->pool, iphone->pagetitle, textval, NULL);
1084     }
1085   }
1086   return iphone->out;
1087 }
1088
1089
1090 /**
1091  * It is a handler who processes the TITLE tag.
1092  *
1093  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
1094  *                     destination is specified.
1095  * @param node   [i]   The TITLE tag node is specified.
1096  * @return The conversion result is returned.
1097  */
1098 static char *
1099 s_iphone_end_title_tag(void *pdoc, Node *UNUSED(child)) 
1100 {
1101   iphone_t      *iphone;
1102   Doc           *doc;
1103   request_rec   *r;
1104
1105   iphone = GET_IPHONE(pdoc);
1106   doc   = iphone->doc;
1107   r     = doc->r;
1108
1109   W_L("</title>");
1110   return iphone->out;
1111 }
1112
1113
1114 /**
1115  * It is a handler who processes the BASE tag.
1116  *
1117  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
1118  *                     destination is specified.
1119  * @param node   [i]   The BASE tag node is specified.
1120  * @return The conversion result is returned.
1121  */
1122 static char *
1123 s_iphone_start_base_tag(void *pdoc, Node *node) 
1124 {
1125   iphone_t      *iphone;
1126   Attr          *attr;
1127   Doc           *doc;
1128   request_rec   *r;
1129
1130   iphone = GET_IPHONE(pdoc);
1131   doc   = iphone->doc;
1132   r     = doc->r;
1133
1134   W_L("<base");
1135   /*--------------------------------------------------------------------------*/
1136   /* Get Attributes                                                           */
1137   /*--------------------------------------------------------------------------*/
1138   for (attr = qs_get_attr(doc,node);
1139        attr;
1140        attr = qs_get_next_attr(doc,attr)) {
1141     char *name  = qs_get_attr_name(doc,attr);
1142     char *value = qs_get_attr_value(doc,attr);
1143     if (STRCASEEQ('h','H',"href",name)) {
1144       W_L(" href=\"");
1145       W_V(value);
1146       W_L("\"");
1147     }
1148   }
1149   W_L(" />");
1150   return iphone->out;
1151 }
1152
1153
1154 /**
1155  * It is a handler who processes the BASE tag.
1156  *
1157  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
1158  *                     destination is specified.
1159  * @param node   [i]   The BASE tag node is specified.
1160  * @return The conversion result is returned.
1161  */
1162 static char *
1163 s_iphone_end_base_tag(void *pdoc, Node *UNUSED(child)) 
1164 {
1165   iphone_t *iphone = GET_IPHONE(pdoc);
1166   return iphone->out;
1167 }
1168
1169
1170 /**
1171  * It is a handler who processes the BODY tag.
1172  *
1173  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
1174  *                     destination is specified.
1175  * @param node   [i]   The BODY tag node is specified.
1176  * @return The conversion result is returned.
1177  */
1178 static char *
1179 s_iphone_start_body_tag(void *pdoc, Node *node) 
1180 {
1181   iphone_t    *iphone;
1182   Doc         *doc;
1183   request_rec *r;
1184   Attr        *attr;
1185   char        *attr_bgcolor = NULL;
1186   char        *attr_text    = NULL;
1187   char        *attr_link    = NULL;
1188   char        *attr_vlink   = NULL;
1189   char        *attr_alink   = NULL;
1190   char        *attr_style   = NULL;
1191   char        *attr_background   = NULL;
1192   char        *style_data   = NULL;
1193
1194   iphone = GET_IPHONE(pdoc);
1195   doc   = iphone->doc;
1196   r     = doc->r;
1197
1198
1199   /*--------------------------------------------------------------------------*/
1200   /* Get Attributes                                                           */
1201   /*--------------------------------------------------------------------------*/
1202   for (attr = qs_get_attr(doc,node);
1203        attr;
1204        attr = qs_get_next_attr(doc,attr)) {
1205     char *name   = qs_get_attr_name(doc,attr);
1206     char *value  = qs_get_attr_value(doc,attr);
1207     if (STRCASEEQ('b','B',"bgcolor",name) && value && *value) {
1208       /*----------------------------------------------------------------------*/
1209       /* CHTML 2.0                                                            */
1210       /*----------------------------------------------------------------------*/
1211       attr_bgcolor = value;
1212     }
1213     else if (STRCASEEQ('t','T',"text",name) && value && *value) {
1214       /*----------------------------------------------------------------------*/
1215       /* CHTML 2.0                                                            */
1216       /*----------------------------------------------------------------------*/
1217       attr_text = value;
1218     }
1219     else if (STRCASEEQ('l','L',"link",name) && value && *value) {
1220       /*----------------------------------------------------------------------*/
1221       /* CHTML 2.0                                                            */
1222       /*----------------------------------------------------------------------*/
1223       attr_link = value;
1224     }
1225     else if (STRCASEEQ('a','A',"alink",name)) {
1226       /*----------------------------------------------------------------------*/
1227       /* CHTML 4.0                                                            */
1228       /*----------------------------------------------------------------------*/
1229       attr_alink = value;
1230     }
1231     else if (STRCASEEQ('v','V',"vlink",name)) {
1232       /*----------------------------------------------------------------------*/
1233       /* CHTML 4.0                                                            */
1234       /*----------------------------------------------------------------------*/
1235       attr_vlink = value;
1236     }
1237     else if (STRCASEEQ('b','B',"background",name) && value && *value) {
1238       /*----------------------------------------------------------------------*/
1239       /* CHTML 6.0                                                            */
1240       /*----------------------------------------------------------------------*/
1241       attr_background = value;
1242     }
1243     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
1244       attr_style = value;
1245     }
1246   }
1247
1248   if (IS_CSS_ON(iphone->entryp)) {
1249     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
1250     if (style) {
1251       css_property_t *color_prop      = chxj_css_get_property_value(doc, style, "color");
1252       css_property_t *bgcolor_prop    = chxj_css_get_property_value(doc, style, "background-color");
1253       css_property_t *bgimage_prop    = chxj_css_get_property_value(doc, style, "background-image");
1254       css_property_t *cur;
1255       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
1256         if (cur->value && *cur->value) {
1257           attr_text = apr_pstrdup(doc->pool, cur->value);
1258         }
1259       }
1260       for (cur = bgcolor_prop->next; cur != bgcolor_prop; cur = cur->next) {
1261         if (cur->value && *cur->value) {
1262           attr_bgcolor = apr_pstrdup(doc->pool, cur->value);
1263         }
1264       }
1265       for (cur = bgimage_prop->next; cur != bgimage_prop; cur = cur->next) {
1266         if (cur->value && *cur->value) {
1267           char *tmp = apr_pstrdup(doc->pool, cur->value);
1268           char *tmps = strstr(tmp,"(");
1269           if(tmps){
1270             char *tmpe = strstr(tmp,")");
1271             size_t len = strlen(tmps) - strlen(tmpe) -1 ;
1272             tmps++;
1273             attr_background = apr_pstrndup(doc->pool, tmps,len);
1274           }
1275         }
1276       }
1277     }
1278     if (iphone->style) {
1279       css_stylesheet_t *pseudos = chxj_find_pseudo_selectors(doc, iphone->style);
1280       css_selector_t *cur_sel;
1281       for (cur_sel = pseudos->selector_head.next; cur_sel != &pseudos->selector_head; cur_sel = cur_sel->next) {
1282         if (cur_sel->name && strcasecmp(cur_sel->name, "a:link") == 0) {
1283           css_property_t *cur;
1284           for (cur = cur_sel->property_head.next; cur != &cur_sel->property_head; cur = cur->next) {
1285             if (cur->name && strcasecmp(cur->name, "color") == 0) {
1286               attr_link = apr_pstrdup(doc->pool, cur->value);
1287             }
1288           }
1289         }
1290         else if (cur_sel->name && strcasecmp(cur_sel->name, "a:visited") == 0) {
1291           css_property_t *cur;
1292           for (cur = cur_sel->property_head.next; cur != &cur_sel->property_head; cur = cur->next) {
1293             if (cur->name && strcasecmp(cur->name, "color") == 0) {
1294               attr_vlink = apr_pstrdup(doc->pool, cur->value);
1295             }
1296           }
1297         }
1298       }
1299     }
1300   }
1301
1302
1303   W_L("<body");
1304   if (attr_bgcolor || attr_text) {
1305     W_L(" style=\"");
1306     if (attr_bgcolor) {
1307       attr_bgcolor = chxj_css_rgb_func_to_value(doc->pool, attr_bgcolor);
1308       W_L("background-color:");
1309       W_V(attr_bgcolor);
1310       W_L(";");
1311     }
1312     if (attr_text) {
1313       attr_text = chxj_css_rgb_func_to_value(doc->pool, attr_text);
1314       W_L("color:");
1315       W_V(attr_text);
1316       W_L(";");
1317     }
1318     W_L("\"");
1319   }
1320   if (attr_link) {
1321     attr_link = chxj_css_rgb_func_to_value(doc->pool, attr_link);
1322     W_L(" link=\"");
1323     W_V(attr_link);
1324     W_L("\"");
1325   }
1326   if (attr_vlink) {
1327     attr_vlink = chxj_css_rgb_func_to_value(doc->pool, attr_vlink);
1328     W_L(" vlink=\"");
1329     W_V(attr_vlink);
1330     W_L("\"");
1331   }
1332   if (attr_alink) {
1333     attr_alink = chxj_css_rgb_func_to_value(doc->pool, attr_alink);
1334     style_data = apr_pstrcat(doc->pool, (style_data) ? style_data : "",
1335                                         apr_psprintf(doc->pool, "a:focus { color:%s; }", attr_alink), NULL);
1336   }
1337   if (attr_background) {
1338     W_L(" background=\"");
1339     W_V(attr_background);
1340     W_L("\"");
1341   }
1342   if (style_data) {
1343     iphone->style_data = apr_pstrcat(doc->pool, (iphone->style_data) ? iphone->style_data : "",
1344                                                 style_data,
1345                                                 NULL);
1346   }
1347   W_L("><div>");
1348   return iphone->out;
1349 }
1350
1351
1352 /**
1353  * It is a handler who processes the BODY tag.
1354  *
1355  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
1356  *                     destination is specified.
1357  * @param node   [i]   The BODY tag node is specified.
1358  * @return The conversion result is returned.
1359  */
1360 static char *
1361 s_iphone_end_body_tag(void *pdoc, Node *UNUSED(child)) 
1362 {
1363   iphone_t       *iphone;
1364   Doc           *doc;
1365   request_rec   *r;
1366
1367   iphone = GET_IPHONE(pdoc);
1368   doc   = iphone->doc;
1369   r     = doc->r;
1370
1371   if (iphone->conf->use_google_analytics) {
1372     char *src = chxj_google_analytics_get_image_url(r, iphone->pagetitle);
1373     W_L("<img src=\"");
1374     W_V(src);
1375     W_L("\" />");
1376   }
1377
1378   W_L("</div></body>");
1379   if (IS_CSS_ON(iphone->entryp)) {
1380     chxj_css_pop_prop_list(iphone->css_prop_stack);
1381   }
1382   return iphone->out;
1383 }
1384
1385
1386 /**
1387  * It is a handler who processes the A tag.
1388  *
1389  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
1390  *                     destination is specified.
1391  * @param node   [i]   The A tag node is specified.
1392  * @return The conversion result is returned.
1393  */
1394 static char *
1395 s_iphone_start_a_tag(void *pdoc, Node *node) 
1396 {
1397   iphone_t    *iphone;
1398   Doc         *doc;
1399   request_rec *r;
1400   Attr        *attr;
1401   char        *attr_style = NULL;
1402   char        *attr_id    = NULL;
1403   char        *attr_name  = NULL;
1404
1405   iphone = GET_IPHONE(pdoc);
1406   doc   = iphone->doc;
1407   r     = doc->r;
1408
1409   W_L("<a");
1410   /*--------------------------------------------------------------------------*/
1411   /* Get Attributes                                                           */
1412   /*--------------------------------------------------------------------------*/
1413   for (attr = qs_get_attr(doc,node);
1414        attr; 
1415        attr = qs_get_next_attr(doc,attr)) {
1416     char *name  = qs_get_attr_name(doc,attr);
1417     char *value = qs_get_attr_value(doc,attr);
1418     if (STRCASEEQ('i','I',"id",name)){
1419       attr_id = chxj_jreserved_to_safe_tag(r, value, iphone->entryp);
1420     }
1421     else if (STRCASEEQ('n','N',"name",name)) {
1422       attr_name = chxj_jreserved_to_safe_tag(r, value, iphone->entryp);
1423     }
1424     else if (STRCASEEQ('h','H',"href",name)) {
1425       /*----------------------------------------------------------------------*/
1426       /* CHTML1.0                                                             */
1427       /*----------------------------------------------------------------------*/
1428       value = chxj_encoding_parameter(r, value, 1);
1429       if (! chxj_starts_with(value, "mailto:") && ! chxj_starts_with(value, "tel:")) {
1430         value = chxj_jreserved_tag_to_safe_for_query_string(r, value, iphone->entryp, 1);
1431       }
1432       W_L(" href=\"");
1433       W_V(value);
1434       W_L("\"");
1435     }
1436     else if (STRCASEEQ('a','A',"accesskey",name)) {
1437       /*----------------------------------------------------------------------*/
1438       /* CHTML1.0                                                             */
1439       /*----------------------------------------------------------------------*/
1440       /* not need */
1441     }
1442     else if (STRCASEEQ('c','C',"cti",name)) {
1443       /*----------------------------------------------------------------------*/
1444       /* CHTML 2.0                                                            */
1445       /*----------------------------------------------------------------------*/
1446       /* ignore */
1447     }
1448     else if (STRCASEEQ('i','I',"ijam",name)) {
1449       /*----------------------------------------------------------------------*/
1450       /* CHTML 3.0                                                            */
1451       /*----------------------------------------------------------------------*/
1452       /* ignore */
1453     }
1454     else if (STRCASEEQ('u','U',"utn",name)) {
1455       /*----------------------------------------------------------------------*/
1456       /* CHTML 3.0                                                            */
1457       /* It is special only for CHTML.                                        */
1458       /*----------------------------------------------------------------------*/
1459       /* ignore */
1460     }
1461     else if (STRCASEEQ('t','T',"telbook",name)) {
1462       /*----------------------------------------------------------------------*/
1463       /* CHTML 3.0                                                            */
1464       /*----------------------------------------------------------------------*/
1465       /* not support */
1466     }
1467     else if (STRCASEEQ('k','K',"kana",name)) {
1468       /*----------------------------------------------------------------------*/
1469       /* CHTML 3.0                                                            */
1470       /*----------------------------------------------------------------------*/
1471       /* not support */
1472     }
1473     else if (STRCASEEQ('e','E',"email",name)) {
1474       /*----------------------------------------------------------------------*/
1475       /* CHTML 3.0                                                            */
1476       /*----------------------------------------------------------------------*/
1477       /* not support */
1478     }
1479     else if (STRCASEEQ('i','I',"ista",name)) {
1480       /*----------------------------------------------------------------------*/
1481       /* CHTML 4.0                                                            */
1482       /*----------------------------------------------------------------------*/
1483       /* ignore */
1484     }
1485     else if (STRCASEEQ('i','I',"ilet",name)) {
1486       /*----------------------------------------------------------------------*/
1487       /* CHTML 5.0                                                            */
1488       /*----------------------------------------------------------------------*/
1489       /* ignore */
1490     }
1491     else if (STRCASEEQ('i','I',"iswf",name)) {
1492       /*----------------------------------------------------------------------*/
1493       /* CHTML 5.0                                                            */
1494       /*----------------------------------------------------------------------*/
1495       /* ignore */
1496     }
1497     else if (STRCASEEQ('i','I',"irst",name)) {
1498       /*----------------------------------------------------------------------*/
1499       /* CHTML 5.0                                                            */
1500       /*----------------------------------------------------------------------*/
1501       /* ignore */
1502     }
1503     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
1504       /*----------------------------------------------------------------------*/
1505       /* CHTML 5.0                                                            */
1506       /*----------------------------------------------------------------------*/
1507       attr_style = value;
1508     }
1509   }
1510   if(attr_id){
1511     W_L(" id=\"");
1512     W_V(attr_id);
1513     W_L("\"");
1514   }
1515   if (attr_name) {
1516     W_L(" name=\"");
1517     W_V(attr_name);
1518     W_L("\"");
1519   }
1520   W_L(">");
1521
1522   if (IS_CSS_ON(iphone->entryp)) {
1523     s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
1524   }
1525
1526   return iphone->out;
1527 }
1528
1529
1530 /**
1531  * It is a handler who processes the A tag.
1532  *
1533  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
1534  *                     destination is specified.
1535  * @param node   [i]   The A tag node is specified.
1536  * @return The conversion result is returned.
1537  */
1538 static char *
1539 s_iphone_end_a_tag(void *pdoc, Node *UNUSED(child)) 
1540 {
1541   iphone_t      *iphone;
1542   Doc          *doc;
1543   request_rec  *r;
1544
1545   iphone = GET_IPHONE(pdoc);
1546   doc   = iphone->doc;
1547   r     = doc->r;
1548
1549   W_L("</a>");
1550
1551   if (IS_CSS_ON(iphone->entryp)) {
1552     chxj_css_pop_prop_list(iphone->css_prop_stack);
1553   }
1554
1555   return iphone->out;
1556 }
1557
1558
1559 /**
1560  * It is a handler who processes the BR tag.
1561  *
1562  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
1563  *                     destination is specified.
1564  * @param node   [i]   The BR tag node is specified.
1565  * @return The conversion result is returned.
1566  */
1567 static char *
1568 s_iphone_start_br_tag(void *pdoc, Node *node)
1569 {
1570   iphone_t     *iphone;
1571   Doc          *doc;
1572   request_rec  *r;
1573   Attr         *attr;
1574
1575   iphone = GET_IPHONE(pdoc);
1576   doc   = iphone->doc;
1577   r     = doc->r;
1578   
1579   char         *attr_style = NULL;
1580   char         *attr_clear = NULL;
1581
1582   /*--------------------------------------------------------------------------*/
1583   /* Get Attributes                                                           */
1584   /*--------------------------------------------------------------------------*/
1585   for (attr = qs_get_attr(doc,node);
1586        attr;
1587        attr = qs_get_next_attr(doc,attr)) {
1588     char *name  = qs_get_attr_name(doc,attr);
1589     char *value = qs_get_attr_value(doc,attr);
1590     if (STRCASEEQ('c','C',"clear",name)) {
1591       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('a','A',"all",value))) {
1592         attr_clear = value;
1593       }
1594     }
1595     else if (STRCASEEQ('s','S',"style",name)) {
1596       attr_style = apr_pstrdup(doc->buf.pool, value);
1597     }
1598   }
1599   if (IS_CSS_ON(iphone->entryp)) {
1600     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
1601     if (style) {
1602       css_property_t *clear_prop = chxj_css_get_property_value(doc, style, "clear");
1603       css_property_t *cur;
1604       for (cur = clear_prop->next; cur != clear_prop; cur = cur->next) {
1605         if (cur->value && *cur->value) {
1606           if ( STRCASEEQ('l','L',"left",  cur->value)
1607             || STRCASEEQ('r','R',"right", cur->value)) {
1608             attr_clear = apr_pstrdup(doc->pool, cur->value);
1609           }
1610           else if(STRCASEEQ('b','B',"both"  ,cur->value)) {
1611             attr_clear = apr_pstrdup(doc->pool, "all");
1612           }
1613         }
1614       }
1615     }
1616   }
1617   W_L("<br");
1618   if(attr_clear){
1619     W_L(" clear=\"");
1620     W_V(attr_clear);
1621     W_L("\"");
1622   }
1623   W_L(" />");
1624   return iphone->out;
1625 }
1626
1627
1628 /**
1629  * It is a handler who processes the BR tag.
1630  *
1631  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
1632  *                     destination is specified.
1633  * @param node   [i]   The BR tag node is specified.
1634  * @return The conversion result is returned.
1635  */
1636 static char *
1637 s_iphone_end_br_tag(void *pdoc, Node *UNUSED(child)) 
1638 {
1639   iphone_t *iphone = GET_IPHONE(pdoc);
1640   return iphone->out;
1641 }
1642
1643 /**
1644  * It is a handler who processes the TABLE tag.
1645  *
1646  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
1647  *                     destination is specified.
1648  * @param node   [i]   The TR tag node is specified.
1649  * @return The conversion result is returned.
1650  */
1651 static char *
1652 s_iphone_start_table_tag(void *pdoc, Node *node) 
1653 {
1654   iphone_t     *iphone;
1655   Doc          *doc;
1656   request_rec  *r;
1657   Attr         *attr;
1658   
1659   char         *attr_style  = NULL;
1660   char         *attr_align  = NULL;
1661   char         *attr_width  = NULL;
1662   char         *attr_height = NULL;
1663   char         *attr_bgcolor = NULL;
1664   char         *attr_border_width  = NULL;
1665   char         *attr_border_color  = NULL;
1666
1667   iphone = GET_IPHONE(pdoc);
1668   doc   = iphone->doc;
1669   r     = doc->r;
1670   
1671   /*--------------------------------------------------------------------------*/
1672   /* Get Attributes                                                           */
1673   /*--------------------------------------------------------------------------*/
1674   for (attr = qs_get_attr(doc,node);
1675        attr;
1676        attr = qs_get_next_attr(doc,attr)) {
1677     char *name  = qs_get_attr_name(doc,attr);
1678     char *val   = qs_get_attr_value(doc,attr);
1679     if (STRCASEEQ('a','A',"align",name)) {
1680       if (val && (STRCASEEQ('l','L',"left",val) || STRCASEEQ('r','R',"right",val) || STRCASEEQ('c','C',"center",val))) {
1681         attr_align = apr_pstrdup(doc->buf.pool, val);
1682       }
1683     }
1684     else if (STRCASEEQ('h','H',"height",name) && val && *val) {
1685       attr_height = apr_pstrdup(doc->buf.pool, val);
1686     }
1687     else if (STRCASEEQ('w','W',"width",name) && val && *val) {
1688       attr_width = apr_pstrdup(doc->buf.pool, val);
1689     }
1690     else if (STRCASEEQ('s','S',"style",name) && val && *val) {
1691       attr_style = apr_pstrdup(doc->buf.pool, val);
1692     }
1693     else if (STRCASEEQ('b','B',"bgcolor",name) && val && *val) {
1694       attr_bgcolor = apr_pstrdup(doc->buf.pool, val);
1695       attr_bgcolor = chxj_css_rgb_func_to_value(doc->pool, attr_bgcolor);
1696     }
1697     else if (STRCASEEQ('b','B',"border",name) && val && *val) {
1698       attr_border_width = apr_pstrdup(doc->buf.pool, val);
1699     }
1700     else if (STRCASEEQ('b','B',"bordercolor",name) && val && *val) {
1701       attr_border_color = apr_pstrdup(doc->buf.pool, val);
1702       attr_border_color = chxj_css_rgb_func_to_value(doc->pool, attr_border_color);
1703     }
1704   }
1705   
1706   if (IS_CSS_ON(iphone->entryp)) {
1707     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
1708     if (style) {
1709       css_property_t *width_prop             = chxj_css_get_property_value(doc, style, "width");
1710       css_property_t *height_prop            = chxj_css_get_property_value(doc, style, "height");
1711       css_property_t *align_prop             = chxj_css_get_property_value(doc, style, "text-align");
1712       css_property_t *bgcolor_prop           = chxj_css_get_property_value(doc, style, "background-color");
1713       css_property_t *border_width_prop      = chxj_css_get_property_value(doc, style, "border-width");
1714       css_property_t *border_color_prop      = chxj_css_get_property_value(doc, style, "border-color");
1715       
1716       css_property_t *cur;
1717       for (cur = width_prop->next; cur != width_prop; cur = cur->next) {
1718         char *tmp = apr_pstrdup(doc->pool, cur->value);
1719         char *tmpp = strstr(tmp, "px");
1720         if (tmpp) {
1721           size_t len = strlen(tmp) - strlen(tmpp);
1722           attr_width = apr_pstrndup(doc->pool, tmp,len);
1723         }
1724         else{
1725           attr_width = apr_pstrdup(doc->pool, tmp);
1726         }
1727       }
1728       for (cur = height_prop->next; cur != height_prop; cur = cur->next) {
1729         char *tmp = apr_pstrdup(doc->pool, cur->value);
1730         char *tmpp = strstr(tmp, "px");
1731         if (tmpp) {
1732           size_t len = strlen(tmp) - strlen(tmpp);
1733           attr_height = apr_pstrndup(doc->pool, tmp,len);
1734         }
1735         else{
1736           attr_height = apr_pstrdup(doc->pool, tmp);
1737         }
1738       }
1739       for (cur = align_prop->next; cur != align_prop; cur = cur->next) {
1740         if (cur->value && (STRCASEEQ('l','L',"left",cur->value) || STRCASEEQ('r','R',"right",cur->value) || STRCASEEQ('c','C',"center",cur->value))) {
1741           attr_align = apr_pstrdup(doc->buf.pool, cur->value);
1742         }
1743       }
1744       for (cur = bgcolor_prop->next; cur != bgcolor_prop; cur = cur->next) {
1745         attr_bgcolor = apr_pstrdup(doc->pool, cur->value);
1746         attr_bgcolor = chxj_css_rgb_func_to_value(doc->pool, attr_bgcolor);
1747       }
1748       for (cur = border_width_prop->next; cur != border_width_prop; cur = cur->next) {
1749         char *tmp = apr_pstrdup(doc->pool, cur->value);
1750         char *tmpp = strstr(tmp, "px");
1751         if (tmpp) {
1752           size_t len = strlen(tmp) - strlen(tmpp);
1753           attr_border_width = apr_pstrndup(doc->pool, tmp,len);
1754         }
1755         else{
1756           attr_border_width = apr_pstrdup(doc->pool, tmp);
1757         }
1758       }
1759       for (cur = border_color_prop->next; cur != border_color_prop; cur = cur->next) {
1760         attr_border_color = apr_pstrdup(doc->pool, cur->value);
1761         attr_border_color = chxj_css_rgb_func_to_value(doc->pool, attr_border_color);
1762       }
1763     }
1764   }
1765
1766   W_L("<table");
1767   if (attr_align){
1768     W_L(" align=\"");
1769     W_V(attr_align);
1770     W_L("\"");
1771   }
1772   if (attr_height){
1773     W_L(" height=\"");
1774     W_V(attr_height);
1775     W_L("\"");
1776   }
1777   if (attr_width){
1778     W_L(" width=\"");
1779     W_V(attr_width);
1780     W_L("\"");
1781   }
1782   if (attr_bgcolor && *attr_bgcolor){
1783     W_L(" bgcolor=\"");
1784     W_V(attr_bgcolor);
1785     W_L("\"");
1786   }
1787   if (attr_border_width || attr_border_color ){
1788     W_L(" style=\"border:");
1789     if (attr_border_width){
1790       W_V(attr_border_width);
1791     }
1792     else{
1793       W_L("1");
1794     }
1795     W_L("px solid");
1796     
1797     if (attr_border_color && *attr_border_color){
1798       W_L(" ");
1799       W_V(attr_border_color);
1800     }
1801     W_L(";\"");
1802   }
1803   W_L(">");
1804   
1805   return iphone->out;
1806 }
1807
1808 /**
1809  * It is a handler who processes the TABLE tag.
1810  *
1811  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
1812  *                     destination is specified.
1813  * @param node   [i]   The TR tag node is specified.
1814  * @return The conversion result is returned.
1815  */
1816 static char *
1817 s_iphone_end_table_tag(void *pdoc, Node *UNUSED(node)) 
1818 {
1819   iphone_t      *iphone;
1820   request_rec  *r;
1821   Doc          *doc;
1822
1823   iphone = GET_IPHONE(pdoc);
1824   doc   = iphone->doc;
1825   r     = iphone->doc->r;
1826   
1827   W_L("</table>");
1828   return iphone->out;
1829 }
1830
1831
1832 /**
1833  * It is a handler who processes the TR tag.
1834  *
1835  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
1836  *                     destination is specified.
1837  * @param node   [i]   The TR tag node is specified.
1838  * @return The conversion result is returned.
1839  */
1840 static char *
1841 s_iphone_start_tr_tag(void *pdoc, Node *node) 
1842 {
1843   iphone_t      *iphone;
1844   Doc          *doc;
1845   request_rec  *r;
1846   
1847   Attr         *attr;
1848   
1849   char         *attr_style  = NULL;
1850   char         *attr_align  = NULL;
1851   char         *attr_valign = NULL;
1852   char         *attr_bgcolor = NULL;
1853
1854   iphone = GET_IPHONE(pdoc);
1855   doc   = iphone->doc;
1856   r     = doc->r;
1857   
1858   /*--------------------------------------------------------------------------*/
1859   /* Get Attributes                                                           */
1860   /*--------------------------------------------------------------------------*/
1861   for (attr = qs_get_attr(doc,node);
1862        attr;
1863        attr = qs_get_next_attr(doc,attr)) {
1864     char *name  = qs_get_attr_name(doc,attr);
1865     char *val   = qs_get_attr_value(doc,attr);
1866     if (STRCASEEQ('a','A',"align",name)) {
1867       if (val && (STRCASEEQ('l','L',"left",val) || STRCASEEQ('r','R',"right",val) || STRCASEEQ('c','C',"center",val))) {
1868         attr_align = apr_pstrdup(doc->buf.pool, val);
1869       }
1870     }
1871     else if (STRCASEEQ('v','V',"valign",name) && val && *val) {
1872       if (val && (STRCASEEQ('t','T',"top",val) || STRCASEEQ('m','M',"middle",val) || STRCASEEQ('b','B',"bottom",val))) {
1873         attr_valign = apr_pstrdup(doc->buf.pool, val);
1874       }
1875     }
1876     else if (STRCASEEQ('s','S',"style",name) && val && *val) {
1877       attr_style = apr_pstrdup(doc->buf.pool, val);
1878     }
1879     else if (STRCASEEQ('b','B',"bgcolor",name) && val && *val) {
1880       attr_bgcolor = apr_pstrdup(doc->buf.pool, val);
1881       attr_bgcolor = chxj_css_rgb_func_to_value(doc->pool, attr_bgcolor);
1882     }
1883   }
1884   
1885   if (IS_CSS_ON(iphone->entryp)) {
1886     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
1887     if (style) {
1888       css_property_t *align_prop             = chxj_css_get_property_value(doc, style, "text-align");
1889       css_property_t *valign_prop            = chxj_css_get_property_value(doc, style, "vertical-align");
1890       css_property_t *bgcolor_prop           = chxj_css_get_property_value(doc, style, "background-color");
1891       
1892       css_property_t *cur;
1893       for (cur = align_prop->next; cur != align_prop; cur = cur->next) {
1894         if (cur->value && (STRCASEEQ('l','L',"left",cur->value) || STRCASEEQ('r','R',"right",cur->value) || STRCASEEQ('c','C',"center",cur->value))) {
1895           attr_align = apr_pstrdup(doc->buf.pool, cur->value);
1896         }
1897       }
1898       for (cur = valign_prop->next; cur != valign_prop; cur = cur->next) {
1899         if (cur->value && (STRCASEEQ('t','T',"top",cur->value) || STRCASEEQ('m','M',"middle",cur->value) || STRCASEEQ('b','B',"bottom",cur->value))) {
1900           attr_valign = apr_pstrdup(doc->buf.pool, cur->value);
1901         }
1902       }
1903       for (cur = bgcolor_prop->next; cur != bgcolor_prop; cur = cur->next) {
1904         attr_bgcolor = apr_pstrdup(doc->pool, cur->value);
1905         attr_bgcolor = chxj_css_rgb_func_to_value(doc->pool, attr_bgcolor);
1906       }
1907     }
1908   }
1909
1910   W_L("<tr");
1911   if (attr_align){
1912     W_L(" align=\"");
1913     W_V(attr_align);
1914     W_L("\"");
1915   }
1916   if (attr_valign){
1917     W_L(" valign=\"");
1918     W_V(attr_valign);
1919     W_L("\"");
1920   }
1921   if (attr_bgcolor && *attr_bgcolor){
1922     W_L(" bgcolor=\"");
1923     W_V(attr_bgcolor);
1924     W_L("\"");
1925   }
1926   W_L(">");
1927   return iphone->out;
1928 }
1929
1930
1931 /**
1932  * It is a handler who processes the TR tag.
1933  *
1934  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
1935  *                     destination is specified.
1936  * @param node   [i]   The TR tag node is specified.
1937  * @return The conversion result is returned.
1938  */
1939 static char *
1940 s_iphone_end_tr_tag(void *pdoc, Node *UNUSED(child)) 
1941 {
1942   iphone_t      *iphone;
1943   request_rec  *r;
1944   Doc          *doc;
1945
1946   iphone = GET_IPHONE(pdoc);
1947   doc   = iphone->doc;
1948   r     = iphone->doc->r;
1949   
1950   W_L("</tr>");
1951   return iphone->out;
1952 }
1953
1954 /**
1955  * It is a handler who processes the TD tag.
1956  *
1957  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
1958  *                     destination is specified.
1959  * @param node   [i]   The TR tag node is specified.
1960  * @return The conversion result is returned.
1961  */
1962 static char *
1963 s_iphone_start_td_or_th_tag(void *pdoc, Node *node,char *tagName) 
1964 {
1965   iphone_t      *iphone;
1966   Doc          *doc;
1967   request_rec  *r;
1968
1969   Attr         *attr;
1970   
1971   char         *attr_style  = NULL;
1972   char         *attr_align  = NULL;
1973   char         *attr_valign = NULL;
1974   char         *attr_bgcolor = NULL;
1975   char         *attr_colspan = NULL;
1976   char         *attr_rowspan = NULL;
1977   char         *attr_width   = NULL;
1978   char         *attr_height  = NULL;
1979
1980   iphone = GET_IPHONE(pdoc);
1981   doc   = iphone->doc;
1982   r     = doc->r;
1983   
1984   /*--------------------------------------------------------------------------*/
1985   /* Get Attributes                                                           */
1986   /*--------------------------------------------------------------------------*/
1987   for (attr = qs_get_attr(doc,node);
1988        attr;
1989        attr = qs_get_next_attr(doc,attr)) {
1990     char *name  = qs_get_attr_name(doc,attr);
1991     char *val   = qs_get_attr_value(doc,attr);
1992     if (STRCASEEQ('a','A',"align",name)) {
1993       if (val && (STRCASEEQ('l','L',"left",val) || STRCASEEQ('r','R',"right",val) || STRCASEEQ('c','C',"center",val))) {
1994         attr_align = apr_pstrdup(doc->buf.pool, val);
1995       }
1996     }
1997     else if (STRCASEEQ('v','V',"valign",name) && val && *val) {
1998       if (val && (STRCASEEQ('t','T',"top",val) || STRCASEEQ('m','M',"middle",val) || STRCASEEQ('b','B',"bottom",val))) {
1999         attr_valign = apr_pstrdup(doc->buf.pool, val);
2000       }
2001     }
2002     else if (STRCASEEQ('s','S',"style",name) && val && *val) {
2003       attr_style = apr_pstrdup(doc->buf.pool, val);
2004     }
2005     else if (STRCASEEQ('b','B',"bgcolor",name) && val && *val) {
2006       attr_bgcolor = apr_pstrdup(doc->buf.pool, val);
2007       attr_bgcolor = chxj_css_rgb_func_to_value(doc->pool, attr_bgcolor);
2008     }
2009     else if (STRCASEEQ('c','C',"colspan",name) && val && *val) {
2010       attr_colspan = apr_pstrdup(doc->buf.pool, val);
2011     }
2012     else if (STRCASEEQ('r','R',"rowspan",name) && val && *val) {
2013       attr_rowspan = apr_pstrdup(doc->buf.pool, val);
2014     }
2015     else if (STRCASEEQ('w','W',"width",name) && val && *val) {
2016       char *tmp = strstr(val, "%");
2017       if(tmp){
2018         attr_width = apr_pstrdup(doc->buf.pool, val);
2019       }
2020       else{
2021         attr_width = apr_psprintf(doc->buf.pool,"%spx",val);
2022       }
2023     }
2024     else if (STRCASEEQ('h','H',"height",name) && val && *val) {
2025       char *tmp = strstr(val, "%");
2026       if(tmp){
2027         attr_height = apr_pstrdup(doc->buf.pool, val);
2028       }
2029       else{
2030         attr_height = apr_psprintf(doc->buf.pool,"%spx",val);
2031       }
2032     }
2033   }
2034   
2035   if (IS_CSS_ON(iphone->entryp)) {
2036     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
2037     if (style) {
2038       css_property_t *align_prop             = chxj_css_get_property_value(doc, style, "text-align");
2039       css_property_t *valign_prop            = chxj_css_get_property_value(doc, style, "vertical-align");
2040       css_property_t *bgcolor_prop           = chxj_css_get_property_value(doc, style, "background-color");
2041       css_property_t *width_prop             = chxj_css_get_property_value(doc, style, "width");
2042       css_property_t *height_prop            = chxj_css_get_property_value(doc, style, "height");
2043       
2044       css_property_t *cur;
2045       for (cur = align_prop->next; cur != align_prop; cur = cur->next) {
2046         if (cur->value && (STRCASEEQ('l','L',"left",cur->value) || STRCASEEQ('r','R',"right",cur->value) || STRCASEEQ('c','C',"center",cur->value))) {
2047           attr_align = apr_pstrdup(doc->buf.pool, cur->value);
2048         }
2049       }
2050       for (cur = valign_prop->next; cur != valign_prop; cur = cur->next) {
2051         if (cur->value && (STRCASEEQ('t','T',"top",cur->value) || STRCASEEQ('m','M',"middle",cur->value) || STRCASEEQ('b','B',"bottom",cur->value))) {
2052           attr_valign = apr_pstrdup(doc->buf.pool, cur->value);
2053         }
2054       }
2055       for (cur = bgcolor_prop->next; cur != bgcolor_prop; cur = cur->next) {
2056         attr_bgcolor = apr_pstrdup(doc->pool, cur->value);
2057         attr_bgcolor = chxj_css_rgb_func_to_value(doc->pool, attr_bgcolor);
2058       }
2059       for (cur = width_prop->next; cur != width_prop; cur = cur->next) {
2060         attr_width = apr_pstrdup(doc->pool, cur->value);
2061       }
2062       for (cur = height_prop->next; cur != height_prop; cur = cur->next) {
2063         attr_height = apr_pstrdup(doc->pool, cur->value);
2064       }
2065     }
2066   }
2067
2068   W_L("<");
2069   W_V(tagName);
2070   if (attr_align){
2071     W_L(" align=\"");
2072     W_V(attr_align);
2073     W_L("\"");
2074   }
2075   if (attr_valign){
2076     W_L(" valign=\"");
2077     W_V(attr_valign);
2078     W_L("\"");
2079   }
2080   if (attr_colspan){
2081     W_L(" colspan=\"");
2082     W_V(attr_colspan);
2083     W_L("\"");
2084   }
2085   if (attr_rowspan){
2086     W_L(" rowspan=\"");
2087     W_V(attr_rowspan);
2088     W_L("\"");
2089   }
2090   if (attr_bgcolor && *attr_bgcolor){
2091     W_L(" bgcolor=\"");
2092     W_V(attr_bgcolor);
2093     W_L("\"");
2094   }
2095   if (attr_width || attr_height ){
2096     W_L(" style=\"");
2097     if (attr_width){
2098       W_L("width:");
2099       W_V(attr_width);
2100       W_L(";");
2101     }
2102     if (attr_height){
2103       W_L("height:");
2104       W_V(attr_height);
2105       W_L(";");
2106     }
2107     W_L("\"");
2108   }
2109   W_L(">");
2110   return iphone->out;
2111 }
2112
2113
2114 /**
2115  * It is a handler who processes the TD tag.
2116  *
2117  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
2118  *                     destination is specified.
2119  * @param node   [i]   The TR tag node is specified.
2120  * @return The conversion result is returned.
2121  */
2122 static char *
2123 s_iphone_end_td_or_th_tag(void *pdoc, Node *UNUSED(child),char *tagName) 
2124 {
2125   iphone_t      *iphone;
2126   request_rec  *r;
2127   Doc          *doc;
2128
2129   iphone = GET_IPHONE(pdoc);
2130   doc   = iphone->doc;
2131   r     = iphone->doc->r;
2132   
2133   W_L("</");
2134   W_V(tagName);
2135   W_L(">");
2136   return iphone->out;
2137 }
2138
2139 /**
2140  * It is a handler who processes the TD tag.
2141  *
2142  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
2143  *                     destination is specified.
2144  * @param node   [i]   The TD tag node is specified.
2145  * @return The conversion result is returned.
2146  */
2147 static char *
2148 s_iphone_start_td_tag(void *pdoc, Node *node) 
2149 {
2150   return s_iphone_start_td_or_th_tag(pdoc,node,"td");
2151 }
2152 /**
2153  * It is a handler who processes the TD tag.
2154  *
2155  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
2156  *                     destination is specified.
2157  * @param node   [i]   The TD tag node is specified.
2158  * @return The conversion result is returned.
2159  */
2160 static char *
2161 s_iphone_end_td_tag(void *pdoc, Node *node) 
2162 {
2163   return s_iphone_end_td_or_th_tag(pdoc,node,"td");
2164 }
2165
2166 /**
2167  * It is a handler who processes the TD tag.
2168  *
2169  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
2170  *                     destination is specified.
2171  * @param node   [i]   The TD tag node is specified.
2172  * @return The conversion result is returned.
2173  */
2174 static char *
2175 s_iphone_start_th_tag(void *pdoc, Node *node) 
2176 {
2177   return s_iphone_start_td_or_th_tag(pdoc,node,"th");
2178 }
2179 /**
2180  * It is a handler who processes the TD tag.
2181  *
2182  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
2183  *                     destination is specified.
2184  * @param node   [i]   The TD tag node is specified.
2185  * @return The conversion result is returned.
2186  */
2187 static char *
2188 s_iphone_end_th_tag(void *pdoc, Node *node) 
2189 {
2190   return s_iphone_end_td_or_th_tag(pdoc,node,"th");
2191 }
2192
2193 /**
2194  * It is a handler who processes the FONT tag.
2195  *
2196  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
2197  *                     destination is specified.
2198  * @param node   [i]   The FONT tag node is specified.
2199  * @return The conversion result is returned.
2200  */
2201 static char *
2202 s_iphone_start_font_tag(void *pdoc, Node *node) 
2203 {
2204   iphone_t      *iphone;
2205   Doc           *doc;
2206   request_rec   *r;
2207   Attr          *attr;
2208   char          *attr_color = NULL;
2209   char          *attr_size  = NULL;
2210   char          *attr_style = NULL;
2211
2212   iphone = GET_IPHONE(pdoc);
2213   doc   = iphone->doc;
2214   r     = doc->r;
2215
2216   /*--------------------------------------------------------------------------*/
2217   /* Get Attributes                                                           */
2218   /*--------------------------------------------------------------------------*/
2219   for (attr = qs_get_attr(doc,node);
2220        attr; 
2221        attr = qs_get_next_attr(doc,attr)) {
2222     char *name  = qs_get_attr_name(doc,attr);
2223     char *value = qs_get_attr_value(doc,attr);
2224     if (STRCASEEQ('c','C',"color",name) && value && *value) {
2225       attr_color = apr_pstrdup(doc->buf.pool, value);
2226     }
2227     else if (STRCASEEQ('s','S',"size",name) && value && *value) {
2228       /*----------------------------------------------------------------------*/
2229       /* CHTML 5.0                                                            */
2230       /*----------------------------------------------------------------------*/
2231       attr_size = apr_pstrdup(doc->buf.pool, value);
2232     }
2233     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
2234       attr_style = apr_pstrdup(doc->buf.pool, value);
2235     }
2236   }
2237   if (IS_CSS_ON(iphone->entryp)) {
2238     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
2239     if (style) {
2240       css_property_t *color_prop = chxj_css_get_property_value(doc, style, "color");
2241       css_property_t *size_prop  = chxj_css_get_property_value(doc, style, "font-size");
2242       css_property_t *cur;
2243       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
2244         if (cur->value && *cur->value) {
2245           attr_color = apr_pstrdup(doc->pool, cur->value);
2246         }
2247       }
2248       for (cur = size_prop->next; cur != size_prop; cur = cur->next) {
2249         if (cur->value && *cur->value) {
2250           attr_size = apr_pstrdup(doc->pool, cur->value);
2251           if (STRCASEEQ('x','X',"xx-small",attr_size)) {
2252             attr_size = apr_pstrdup(doc->pool, "1");
2253           }
2254           else if (STRCASEEQ('x','X',"x-small",attr_size)) {
2255             attr_size = apr_pstrdup(doc->pool, "2");
2256           }
2257           else if (STRCASEEQ('s','S',"small",attr_size)) {
2258             attr_size = apr_pstrdup(doc->pool, "3");
2259           }
2260           else if (STRCASEEQ('m','M',"medium",attr_size)) {
2261             attr_size = apr_pstrdup(doc->pool, "4");
2262           }
2263           else if (STRCASEEQ('l','L',"large",attr_size)) {
2264             attr_size = apr_pstrdup(doc->pool, "5");
2265           }
2266           else if (STRCASEEQ('x','X',"x-large",attr_size)) {
2267             attr_size = apr_pstrdup(doc->pool, "6");
2268           }
2269           else if (STRCASEEQ('x','X',"xx-large",attr_size)) {
2270             attr_size = apr_pstrdup(doc->pool, "7");
2271           }
2272         }
2273       }
2274     }
2275   }
2276   iphone_flags_t *flg = (iphone_flags_t *)apr_palloc(doc->pool, sizeof(*flg));
2277   memset(flg, 0, sizeof(*flg));
2278   if (attr_color) {
2279     attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
2280     W_L("<font color=\"");
2281     W_V(attr_color);
2282     W_L("\">");
2283     flg->font_color_flag = 1;
2284   }
2285   if (attr_size) {
2286     flg->font_size_flag = 1;
2287     switch(*attr_size) {
2288     case '1': W_L("<span style=\"font-size: xx-small\">"); break;
2289     case '2': W_L("<span style=\"font-size: x-small\">");  break;
2290     case '3': W_L("<span style=\"font-size: small\">");    break;
2291     case '4': W_L("<span style=\"font-size: medium\">");   break;
2292     case '5': W_L("<span style=\"font-size: large\">");    break;
2293     case '6': W_L("<span style=\"font-size: x-large\">");  break;
2294     case '7': W_L("<span style=\"font-size: xx-large\">"); break;
2295     case '-':
2296       if (*(attr_size + 1) == '1') {
2297         W_L("<span style=\"font-size: small\">");
2298         break;
2299       }
2300       if (*(attr_size + 1) == '2') {
2301         W_L("<span style=\"font-size: x-small\">");
2302         break;
2303       }
2304       if (*(attr_size + 1) == '3') {
2305         W_L("<span style=\"font-size: xx-small\">");
2306         break;
2307       }
2308       flg->font_size_flag = 0;
2309       break;
2310
2311     case '+':
2312       if (*(attr_size + 1) == '1') {
2313         W_L("<span style=\"font-size: large\">");
2314         break;
2315       }
2316       if (*(attr_size + 1) == '2') {
2317         W_L("<span style=\"font-size: x-large\">");
2318         break;
2319       }
2320       if (*(attr_size + 1) == '3') {
2321         W_L("<span style=\"font-size: xx-large\">");
2322         break;
2323       }
2324       flg->font_size_flag = 0;
2325       break;
2326
2327     default:
2328       WRN(doc->r, "invlalid font size. [%s] != (1|2|3|4|5|6|7|+1|+2|+3|-1|-2|-3)", attr_size);
2329       flg->font_size_flag = 0;
2330     }
2331   }
2332   node->userData = flg;
2333   return iphone->out;
2334 }
2335
2336
2337 /**
2338  * It is a handler who processes the FONT tag.
2339  *
2340  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
2341  *                     destination is specified.
2342  * @param node   [i]   The FONT tag node is specified.
2343  * @return The conversion result is returned.
2344  */
2345 static char *
2346 s_iphone_end_font_tag(void *pdoc, Node *node)
2347 {
2348   iphone_t      *iphone;
2349   request_rec  *r;
2350   Doc          *doc;
2351
2352   iphone = GET_IPHONE(pdoc);
2353   doc   = iphone->doc;
2354   r     = iphone->doc->r;
2355
2356   iphone_flags_t *flg = (iphone_flags_t *)node->userData;
2357   if (flg && flg->font_size_flag) {
2358     W_L("</span>");
2359   }
2360   if (flg && flg->font_color_flag) {
2361     W_L("</font>");
2362   }
2363   if (IS_CSS_ON(iphone->entryp)) {
2364     chxj_css_pop_prop_list(iphone->css_prop_stack);
2365   }
2366
2367   return iphone->out;
2368 }
2369
2370
2371 /**
2372  * It is a handler who processes the FORM tag.
2373  *
2374  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
2375  *                     destination is specified.
2376  * @param node   [i]   The FORM tag node is specified.
2377  * @return The conversion result is returned.
2378  */
2379 static char *
2380 s_iphone_start_form_tag(void *pdoc, Node *node) 
2381 {
2382   iphone_t    *iphone;
2383   Doc         *doc;
2384   request_rec *r;
2385   Attr        *attr;
2386   char        *attr_action = NULL;
2387   char        *attr_method = NULL;
2388   char        *attr_style  = NULL;
2389   char        *attr_color  = NULL;
2390   char        *attr_align  = NULL;
2391   char        *attr_name   = NULL;
2392   char        *css_clear   = NULL;
2393   char        *new_hidden_tag = NULL;
2394
2395   iphone  = GET_IPHONE(pdoc);
2396   doc     = iphone->doc;
2397   r       = doc->r;
2398
2399   /*--------------------------------------------------------------------------*/
2400   /* Get Attributes                                                           */
2401   /*--------------------------------------------------------------------------*/
2402   for (attr = qs_get_attr(doc,node);
2403        attr;
2404        attr = qs_get_next_attr(doc,attr)) {
2405     char *name  = qs_get_attr_name(doc,attr);
2406     char *value = qs_get_attr_value(doc,attr);
2407     switch(*name) {
2408     case 'a':
2409     case 'A':
2410       if (strcasecmp(name, "action") == 0) {
2411         /*--------------------------------------------------------------------*/
2412         /* CHTML 1.0                                                          */
2413         /*--------------------------------------------------------------------*/
2414         attr_action = value;
2415       }
2416       break;
2417
2418     case 'm':
2419     case 'M':
2420       if (strcasecmp(name, "method") == 0) {
2421         /*--------------------------------------------------------------------*/
2422         /* CHTML 1.0                                                          */
2423         /*--------------------------------------------------------------------*/
2424         attr_method = value;
2425       }
2426       break;
2427
2428     case 'n':
2429     case 'N':
2430       if (strcasecmp(name, "name") == 0) {
2431         /*--------------------------------------------------------------------*/
2432         /* CHTML 1.0                                                          */
2433         /*--------------------------------------------------------------------*/
2434         attr_name = value;
2435       }
2436       break;
2437
2438     case 's':
2439     case 'S':
2440       if (strcasecmp(name, "style") == 0) {
2441         attr_style = value;
2442       }
2443       break;
2444
2445     default:
2446       break;
2447     }
2448   }
2449   if (IS_CSS_ON(iphone->entryp)) {
2450     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
2451     if (style) {
2452       css_property_t *text_align_prop = chxj_css_get_property_value(doc, style, "text-align");
2453       css_property_t *color_prop      = chxj_css_get_property_value(doc, style, "color");
2454       css_property_t *clear_prop      = chxj_css_get_property_value(doc, style, "clear");
2455       css_property_t *cur;
2456       for (cur = text_align_prop->next; cur != text_align_prop; cur = cur->next) {
2457         if (STRCASEEQ('l','L',"left", cur->value)) {
2458           attr_align = apr_pstrdup(doc->pool, "left");
2459         }
2460         else if (STRCASEEQ('c','C',"center",cur->value)) {
2461           attr_align = apr_pstrdup(doc->pool, "center");
2462         }
2463         else if (STRCASEEQ('r','R',"right",cur->value)) {
2464           attr_align = apr_pstrdup(doc->pool, "right");
2465         }
2466       }
2467       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
2468         attr_color = apr_pstrdup(doc->pool, cur->value);
2469       }
2470       for (cur = clear_prop->next; cur != clear_prop; cur = cur->next) {
2471         css_clear = apr_pstrdup(doc->pool, cur->value);
2472       }
2473     }
2474   }
2475
2476   int post_flag = (attr_method && strcasecmp(attr_method, "post") == 0) ? 1 : 0;
2477
2478   W_L("<form");
2479   if (attr_action) {
2480     attr_action = chxj_encoding_parameter(r, attr_action, 1);
2481     attr_action = chxj_add_cookie_parameter(r, attr_action, iphone->cookie);
2482     char *q;
2483     char *old_qs = NULL;
2484     q = strchr(attr_action, '?');
2485     if (q) {
2486       new_hidden_tag = chxj_form_action_to_hidden_tag(r, doc->pool, attr_action, 1, post_flag, &old_qs, CHXJ_FALSE, CHXJ_TRUE, iphone->entryp);
2487       if (new_hidden_tag || old_qs) {
2488         *q = 0;
2489       }
2490     }
2491     W_L(" action=\"");
2492     W_V(attr_action);
2493     if (old_qs) {
2494       W_L("?");
2495       W_V(old_qs);
2496     }
2497     W_L("\"");
2498   }
2499   if (attr_method) {
2500     W_L(" method=\"");
2501     W_V(attr_method);
2502     W_L("\"");
2503   }
2504   if (attr_name) {
2505     W_L(" name=\"");
2506     W_V(attr_name);
2507     W_L("\"");
2508   }
2509   if (css_clear) {
2510     W_L(" style=\"");
2511     W_L("clear:");
2512     W_V(css_clear);
2513     W_L("\"");
2514   }
2515   W_L(">");
2516
2517   iphone_flags_t *flg = (iphone_flags_t *)apr_palloc(doc->pool, sizeof(iphone_flags_t));
2518   memset(flg, 0, sizeof(*flg));
2519   if (attr_color) {
2520     attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
2521     W_L("<font color=\"");
2522     W_V(attr_color);
2523     W_L("\">");
2524     flg->with_font_flag = 1;
2525   }
2526   if (attr_align) {
2527     W_L("<div align=\"");
2528     W_V(attr_align);
2529     W_L("\">");
2530     flg->with_div_flag = 1;
2531   }
2532   node->userData = flg;
2533   if (new_hidden_tag) {
2534     W_V(new_hidden_tag);
2535   }
2536   return iphone->out;
2537 }
2538
2539
2540 /**
2541  * It is a handler who processes the FORM tag.
2542  *
2543  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
2544  *                     destination is specified.
2545  * @param node   [i]   The FORM tag node is specified.
2546  * @return The conversion result is returned.
2547  */
2548 static char *
2549 s_iphone_end_form_tag(void *pdoc, Node *node)
2550 {
2551   iphone_t *iphone = GET_IPHONE(pdoc);
2552   Doc      *doc    = iphone->doc;
2553
2554   iphone_flags_t *flg = (iphone_flags_t *)node->userData;
2555   if (flg && flg->with_div_flag) {
2556     W_L("</div>");
2557   }
2558   if (flg && flg->with_font_flag) {
2559     W_L("</font>");
2560   }
2561   W_L("</form>");
2562   if (IS_CSS_ON(iphone->entryp)) {
2563     chxj_css_pop_prop_list(iphone->css_prop_stack);
2564   }
2565
2566   return iphone->out;
2567 }
2568
2569 static char *
2570 s_iphone_istyle_to_wap_input_format(apr_pool_t *p, const char *s)
2571 {
2572   if (s) {
2573     switch (s[0]) {
2574     case '1': return apr_psprintf(p, "&quot;*&lt;ja:h&gt;&quot;");
2575     case '2': return apr_psprintf(p, "&quot;*&lt;ja:hk&gt;&quot;");
2576     case '3': return apr_psprintf(p, "&quot;*&lt;ja:en&gt;&quot;");
2577     case '4': return apr_psprintf(p, "&quot;*&lt;ja:n&gt;&quot;");
2578     default:
2579       return apr_pstrdup(p, "");
2580     }
2581   }
2582
2583   return apr_pstrdup(p,"");
2584 }
2585
2586
2587 /**
2588  * It is a handler who processes the INPUT tag.
2589  *
2590  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
2591  *                     destination is specified.
2592  * @param node   [i]   The INPUT tag node is specified.
2593  * @return The conversion result is returned.
2594  */
2595 static char *
2596 s_iphone_start_input_tag(void *pdoc, Node *node) 
2597 {
2598   iphone_t    *iphone;
2599   Doc         *doc;
2600   request_rec *r;
2601   Attr        *attr;
2602   char        *attr_accesskey  = NULL;
2603   char        *attr_max_length = NULL;
2604   char        *attr_type       = NULL;
2605   char        *attr_name       = NULL;
2606   char        *attr_value      = NULL;
2607   char        *attr_istyle     = NULL;
2608   char        *attr_size       = NULL;
2609   char        *attr_checked    = NULL;
2610   char        *attr_style      = NULL;
2611
2612   iphone  = GET_IPHONE(pdoc);
2613   doc     = iphone->doc;
2614   r       = doc->r;
2615
2616   /*--------------------------------------------------------------------------*/
2617   /* Get Attributes                                                           */
2618   /*--------------------------------------------------------------------------*/
2619   for (attr = qs_get_attr(doc,node);
2620        attr;
2621        attr = qs_get_next_attr(doc,attr)) {
2622     char *name  = qs_get_attr_name(doc,attr);
2623     char *value = qs_get_attr_value(doc,attr);
2624     if (STRCASEEQ('t','T',"type",name) && value && *value) {
2625       char *tmp_type = qs_trim_string(doc->buf.pool, value);
2626       if (tmp_type && (STRCASEEQ('t','T',"text",    tmp_type) ||
2627                        STRCASEEQ('p','P',"password",tmp_type) ||
2628                        STRCASEEQ('c','C',"checkbox",tmp_type) ||
2629                        STRCASEEQ('r','R',"radio",   tmp_type) ||
2630                        STRCASEEQ('h','H',"hidden",  tmp_type) ||
2631                        STRCASEEQ('s','S',"submit",  tmp_type) ||
2632                        STRCASEEQ('r','R',"reset",   tmp_type))) {
2633         attr_type = tmp_type;
2634       }
2635     }
2636     else if (STRCASEEQ('n','N',"name",name) && value && *value) {
2637       attr_name = value;
2638     }
2639     else if (STRCASEEQ('v','V',"value",name) && value && *value) {
2640       attr_value = value;
2641     }
2642     else if (STRCASEEQ('i','I',"istyle",name) && value && *value) {
2643       attr_istyle = value;
2644     }
2645     else if (STRCASEEQ('m','M',"maxlength",name) && value && *value) {
2646       attr_max_length = value;
2647     }
2648     else if (STRCASEEQ('c','C',"checked", name)) {
2649       attr_checked = value;
2650     }
2651     else if (STRCASEEQ('a','A',"accesskey", name) && value && *value) {
2652       attr_accesskey = value;
2653     }
2654     else if (STRCASEEQ('s','S',"size", name) && value && *value) {
2655       attr_size = value;
2656     }
2657     else if (STRCASEEQ('s','S',"style", name) && value && *value) {
2658       attr_style = value;
2659     }
2660   }
2661
2662   if (IS_CSS_ON(iphone->entryp)) {
2663     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
2664     if (style) {
2665       css_property_t *wap_input_format = chxj_css_get_property_value(doc, style, "-wap-input-format");
2666       css_property_t *cur;
2667       for (cur = wap_input_format->next; cur != wap_input_format; cur = cur->next) {
2668         if (strcasestr(cur->value, "<ja:n>")) {
2669           attr_istyle = "4";
2670         }
2671         else if (strcasestr(cur->value, "<ja:en>")) {
2672           attr_istyle = "3";
2673         }
2674         else if (strcasestr(cur->value, "<ja:hk>")) {
2675           attr_istyle = "2";
2676         }
2677         else if (strcasestr(cur->value, "<ja:h>")) {
2678           attr_istyle = "1";
2679         }
2680       }
2681     }
2682   }
2683
2684   W_L("<input");
2685   if (attr_size) {
2686     W_L(" size=\"");
2687     W_V(attr_size);
2688     W_L("\"");
2689   }
2690   if (attr_name) {
2691     W_L(" name=\"");
2692     W_V(chxj_jreserved_to_safe_tag(r, attr_name, iphone->entryp));
2693     W_L("\"");
2694   }
2695   if (attr_value) {
2696     W_L(" value=\"");
2697     W_V(chxj_add_slash_to_doublequote(doc->pool, attr_value));
2698     W_L("\"");
2699   }
2700   if (attr_istyle && (*attr_istyle == '1' || *attr_istyle == '2' || *attr_istyle == '3' || *attr_istyle == '4')) {
2701     if (attr_type && STRCASEEQ('t','T',"text",attr_type)) {
2702       /* 1 => ignore */ 
2703       /* 2 => ignore */
2704       /* 3 => ignore */
2705       /* 4 => number */
2706       if (*attr_istyle == '4') {
2707         attr_type = apr_pstrdup(r->pool, "number");
2708       }
2709     }
2710   }
2711   if (attr_type) {
2712     W_L(" type=\"");
2713     W_V(attr_type);
2714     W_L("\"");
2715   }
2716   /*--------------------------------------------------------------------------*/
2717   /* The figure is default for the password.                                  */
2718   /*--------------------------------------------------------------------------*/
2719   if (attr_max_length && *attr_max_length) {
2720     if (chxj_chk_numeric(attr_max_length) == 0) {
2721       W_L(" maxlength=\"");
2722       W_V(attr_max_length);
2723       W_L("\"");
2724     }
2725   }
2726   if (attr_checked) {
2727     W_L(" checked=\"checked\"");
2728   }
2729   W_L(" />");
2730   return iphone->out;
2731 }
2732
2733
2734 /**
2735  * It is a handler who processes the INPUT tag.
2736  *
2737  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
2738  *                     destination is specified.
2739  * @param node   [i]   The INPUT tag node is specified.
2740  * @return The conversion result is returned.
2741  */
2742 static char *
2743 s_iphone_end_input_tag(void *pdoc, Node *UNUSED(child)) 
2744 {
2745   iphone_t *iphone = GET_IPHONE(pdoc);
2746   return iphone->out;
2747 }
2748
2749
2750 /**
2751  * It is a handler who processes the CENTER tag.
2752  *
2753  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
2754  *                     destination is specified.
2755  * @param node   [i]   The CENTER tag node is specified.
2756  * @return The conversion result is returned.
2757  */
2758 static char *
2759 s_iphone_start_center_tag(void *pdoc, Node *node)
2760 {
2761   iphone_t *iphone;
2762   Doc       *doc;
2763   Attr      *attr;
2764   char      *attr_style = NULL;
2765   char      *attr_color = NULL;
2766   char      *attr_size  = NULL;
2767
2768   iphone = GET_IPHONE(pdoc);
2769   doc    = iphone->doc;
2770
2771   for (attr = qs_get_attr(doc,node);
2772        attr;
2773        attr = qs_get_next_attr(doc,attr)) {
2774     char *name  = qs_get_attr_name(doc,attr);
2775     char *value = qs_get_attr_value(doc,attr);
2776     if (STRCASEEQ('s','S',"style",name) && value && *value) {
2777       attr_style = value;
2778     }
2779   }
2780   if (IS_CSS_ON(iphone->entryp)) {
2781     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
2782     if (style) {
2783       css_property_t *color_prop      = chxj_css_get_property_value(doc, style, "color");
2784       css_property_t *size_prop       = chxj_css_get_property_value(doc, style, "font-size");
2785       css_property_t *cur;
2786       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
2787         if (cur->value && *cur->value) {
2788           attr_color = apr_pstrdup(doc->pool, cur->value);
2789         }
2790       }
2791       for (cur = size_prop->next; cur != size_prop; cur = cur->next) {
2792         if (cur->value && *cur->value) {
2793           attr_size = apr_pstrdup(doc->pool, cur->value);
2794         }
2795       }
2796     }
2797   }
2798
2799   W_L("<center");
2800   if (attr_size || attr_color) {
2801     W_L(" style=\"");
2802     if (attr_size) {
2803       W_L("font-size:");
2804       W_V(attr_size);
2805       W_L(";");
2806     }
2807     if (attr_color) {
2808       attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
2809       W_L("color:");
2810       W_V(attr_color);
2811       W_L(";");
2812     }
2813     W_L("\"");
2814   }
2815   W_L(">");
2816   
2817   return iphone->out;
2818 }
2819
2820
2821 /**
2822  * It is a handler who processes the CENTER tag.
2823  *
2824  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
2825  *                     destination is specified.
2826  * @param node   [i]   The CENTER tag node is specified.
2827  * @return The conversion result is returned.
2828  */
2829 static char *
2830 s_iphone_end_center_tag(void *pdoc, Node *UNUSED(node))
2831 {
2832   iphone_t    *iphone;
2833   Doc         *doc;
2834   request_rec *r;
2835
2836   iphone = GET_IPHONE(pdoc);
2837   doc    = iphone->doc;
2838   r      = doc->r;
2839
2840   W_L("</center>");
2841   if (IS_CSS_ON(iphone->entryp)) {
2842     chxj_css_pop_prop_list(iphone->css_prop_stack);
2843   }
2844   return iphone->out;
2845 }
2846
2847
2848 /**
2849  * It is a handler who processes the li tag.
2850  *
2851  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
2852  *                     destination is specified.
2853  * @param node   [i]   The li tag node is specified.
2854  * @return The conversion result is returned.
2855  */
2856 static char *
2857 s_iphone_start_li_tag(void *pdoc, Node *node)
2858 {
2859   iphone_t    *iphone;
2860   Doc         *doc;
2861   request_rec *r;
2862   Attr        *attr;
2863   char        *attr_type  = NULL;
2864   char        *attr_value = NULL;
2865   char        *attr_style = NULL;
2866
2867   iphone = GET_IPHONE(pdoc);
2868   doc   = iphone->doc;
2869   r     = doc->r;
2870
2871   for (attr = qs_get_attr(doc,node);
2872        attr;
2873        attr = qs_get_next_attr(doc,attr)) {
2874     char *name  = qs_get_attr_name(doc,attr);
2875     char *value = qs_get_attr_value(doc,attr);
2876     if (STRCASEEQ('t','T',"type",name)) {
2877       if (value && (*value == '1' || *value == 'a' || *value == 'A' || STRCASEEQ('d','D',"disc",value) || STRCASEEQ('s','S',"square",value) || STRCASEEQ('c','C',"circle",value))) {
2878         if (*value == '1') {
2879           attr_type = apr_pstrdup(doc->pool, "decimal");
2880         }
2881         else if (*value == 'a') {
2882           attr_type = apr_pstrdup(doc->pool, "lower-alpha");
2883         }
2884         else if (*value == 'A') {
2885           attr_type = apr_pstrdup(doc->pool, "upper-alpha");
2886         }
2887         else {
2888           attr_type = value;
2889         }
2890       }
2891     }
2892     else if (STRCASEEQ('v','V',"value", name) && value && *value) {
2893       attr_value = value;
2894     }
2895     else if (STRCASEEQ('s','S',"style", name) && value && *value) {
2896       attr_style = value;
2897     }
2898   }
2899   if (IS_CSS_ON(iphone->entryp)) {
2900     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
2901     if (style) {
2902       css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "list-style-type");
2903       css_property_t *cur;
2904       for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
2905         if (STRCASEEQ('d','D',"decimal", cur->value)) {
2906           attr_type = apr_pstrdup(doc->pool, "decimal");
2907         }
2908         else if (STRCASEEQ('u','U',"upper-alpha", cur->value)) {
2909           attr_type = apr_pstrdup(doc->pool, "upper-alpha");
2910         }
2911         else if (STRCASEEQ('l','L',"lower-alpha", cur->value)) {
2912           attr_type = apr_pstrdup(doc->pool, "lower-alpha");
2913         }
2914         else if (STRCASEEQ('d','D',"disc", cur->value)) {
2915           attr_type = apr_pstrdup(doc->pool, "disc");
2916         }
2917         else if (STRCASEEQ('s','S',"square", cur->value)) {
2918           attr_type = apr_pstrdup(doc->pool, "square");
2919         }
2920         else if (STRCASEEQ('c','C',"circle", cur->value)) {
2921           attr_type = apr_pstrdup(doc->pool, "circle");
2922         }
2923       }
2924     }
2925   }
2926
2927
2928   W_L("<li");
2929   if (attr_type) {
2930     W_L(" style=\"");
2931     W_L("list-style-type:");
2932     W_V(attr_type);
2933     W_L(";");
2934     W_L("\"");
2935   }
2936   if (attr_value) {
2937     W_L(" value=\"");
2938     W_V(attr_value);
2939     W_L("\"");
2940   }
2941   W_L(">");
2942   return iphone->out;
2943 }
2944
2945
2946 /**
2947  * It is a handler who processes the li tag.
2948  *
2949  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
2950  *                     destination is specified.
2951  * @param node   [i]   The li tag node is specified.
2952  * @return The conversion result is returned.
2953  */
2954 static char *
2955 s_iphone_end_li_tag(void *pdoc, Node *UNUSED(child)) 
2956 {
2957   iphone_t     *iphone;
2958   Doc         *doc;
2959   request_rec *r;
2960
2961   iphone = GET_IPHONE(pdoc);
2962   doc   = iphone->doc;
2963   r     = doc->r;
2964
2965   if (IS_CSS_ON(iphone->entryp)) {
2966     chxj_css_pop_prop_list(iphone->css_prop_stack);
2967   }
2968   W_L("</li>");
2969   return iphone->out;
2970 }
2971
2972
2973 /**
2974  * It is a handler who processes the OL tag.
2975  *
2976  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
2977  *                     destination is specified.
2978  * @param node   [i]   The OL tag node is specified.
2979  * @return The conversion result is returned.
2980  */
2981 static char *
2982 s_iphone_start_ol_tag(void *pdoc, Node *node)
2983 {
2984   iphone_t    *iphone;
2985   Doc         *doc;
2986   request_rec *r;
2987   Attr        *attr;
2988   char        *attr_style = NULL;
2989   char        *attr_start = NULL;
2990   char        *attr_type  = NULL;
2991   char        *css_clear  = NULL;
2992
2993   iphone = GET_IPHONE(pdoc);
2994   doc   = iphone->doc;
2995   r     = doc->r;
2996
2997   /*--------------------------------------------------------------------------*/
2998   /* Get Attributes                                                           */
2999   /*--------------------------------------------------------------------------*/
3000   for (attr = qs_get_attr(doc,node);
3001        attr;
3002        attr = qs_get_next_attr(doc,attr)) {
3003     char *name = qs_get_attr_name(doc,attr);
3004     char *value = qs_get_attr_value(doc,attr);
3005     if (STRCASEEQ('t','T',"type",name) && value) {
3006       if (*value == '1') {
3007         attr_type = apr_pstrdup(doc->pool, "decimal");
3008       }
3009       else if (*value == 'a') {
3010         attr_type = apr_pstrdup(doc->pool, "lower-alpha");
3011       }
3012       else if (*value == 'A') {
3013         attr_type = apr_pstrdup(doc->pool, "upper-alpha");
3014       }
3015     }
3016     else if (STRCASEEQ('s','S',"start",name) && value && *value) {
3017       attr_start = value;
3018     }
3019     else if (STRCASEEQ('s','S',"style", name) && value && *value) {
3020       attr_style = value;
3021     }
3022   }
3023   if (IS_CSS_ON(iphone->entryp)) {
3024     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
3025     if (style) {
3026       css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "list-style-type");
3027       css_property_t *clear_prop           = chxj_css_get_property_value(doc, style, "clear");
3028       
3029       css_property_t *cur;
3030       for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
3031         if (STRCASEEQ('d','D',"decimal", cur->value)) {
3032           attr_type = apr_pstrdup(doc->pool, "decimal");
3033         }
3034         else if (STRCASEEQ('u','U',"upper-alpha", cur->value)) {
3035           attr_type = apr_pstrdup(doc->pool, "upper-alpha");
3036         }
3037         else if (STRCASEEQ('l','L',"lower-alpha", cur->value)) {
3038           attr_type = apr_pstrdup(doc->pool, "lower-alpha");
3039         }
3040       }
3041       for (cur = clear_prop->next; cur != clear_prop; cur = cur->next) {
3042         css_clear = apr_pstrdup(doc->pool, cur->value);
3043       }
3044     }
3045   }
3046   W_L("<ol");
3047   if (attr_type || css_clear) {
3048     W_L(" style=\"");
3049     if (attr_type) {
3050       W_L("list-style-type:");
3051       W_V(attr_type);
3052       W_L(";");
3053     }
3054     if (css_clear){
3055       W_L("clear:");
3056       W_V(css_clear);
3057       W_L(";");
3058     }
3059     W_L("\"");
3060   }
3061   if (attr_start) {
3062     W_L(" start=\"");
3063     W_V(attr_start);
3064     W_L("\"");
3065   }
3066   W_L(">");
3067
3068   return iphone->out;
3069 }
3070
3071
3072 /**
3073  * It is a handler who processes the OL tag.
3074  *
3075  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
3076  *                     destination is specified.
3077  * @param node   [i]   The OL tag node is specified.
3078  * @return The conversion result is returned.
3079  */
3080 static char *
3081 s_iphone_end_ol_tag(void *pdoc, Node *UNUSED(child)) 
3082 {
3083   iphone_t     *iphone;
3084   Doc         *doc;
3085   request_rec *r;
3086
3087   iphone = GET_IPHONE(pdoc);
3088   doc   = iphone->doc;
3089   r     = doc->r;
3090
3091   W_L("</ol>");
3092   if (IS_CSS_ON(iphone->entryp)) {
3093     chxj_css_pop_prop_list(iphone->css_prop_stack);
3094   }
3095   return iphone->out;
3096 }
3097
3098
3099 /**
3100  * It is a handler who processes the P tag.
3101  *
3102  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
3103  *                     destination is specified.
3104  * @param node   [i]   The P tag node is specified.
3105  * @return The conversion result is returned.
3106  */
3107 static char *
3108 s_iphone_start_p_tag(void *pdoc, Node *node)
3109 {
3110   iphone_t    *iphone;
3111   Doc         *doc;
3112   request_rec *r;
3113   Attr        *attr;
3114   char        *attr_align = NULL;
3115   char        *attr_style = NULL;
3116   char        *attr_color = NULL;
3117   char        *attr_blink = NULL;
3118   char        *css_clear  = NULL;
3119
3120   iphone = GET_IPHONE(pdoc);
3121   doc   = iphone->doc;
3122   r     = doc->r;
3123
3124   for (attr = qs_get_attr(doc,node);
3125        attr;
3126        attr = qs_get_next_attr(doc,attr)) {
3127     char *nm  = qs_get_attr_name(doc,attr);
3128     char *val = qs_get_attr_value(doc,attr);
3129     if (STRCASEEQ('a','A',"align", nm)) {
3130       /*----------------------------------------------------------------------*/
3131       /* CHTML 1.0 (W3C version 3.2)                                          */
3132       /*----------------------------------------------------------------------*/
3133       if (val && (STRCASEEQ('l','L',"left",val) || STRCASEEQ('r','R',"right",val) || STRCASEEQ('c','C',"center",val))) {
3134         attr_align = apr_pstrdup(doc->buf.pool, val);
3135         break;
3136       }
3137     }
3138     else if (STRCASEEQ('s','S',"style", nm) && val && *val) {
3139       attr_style = apr_pstrdup(doc->buf.pool, val);
3140     }
3141   }
3142   if (IS_CSS_ON(iphone->entryp)) {
3143     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
3144     if (style) {
3145       css_property_t *text_align_prop = chxj_css_get_property_value(doc, style, "text-align");
3146       css_property_t *color_prop      = chxj_css_get_property_value(doc, style, "color");
3147       css_property_t *text_deco_prop  = chxj_css_get_property_value(doc, style, "text-decoration");
3148       css_property_t *clear_prop      = chxj_css_get_property_value(doc, style, "clear");
3149       css_property_t *cur;
3150       for (cur = text_align_prop->next; cur != text_align_prop; cur = cur->next) {
3151         if (STRCASEEQ('l','L',"left",cur->value)) {
3152           attr_align = apr_pstrdup(doc->pool, "left");
3153         }
3154         else if (STRCASEEQ('c','C',"center",cur->value)) {
3155           attr_align = apr_pstrdup(doc->pool, "center");
3156         }
3157         else if (STRCASEEQ('r','R',"right",cur->value)) {
3158           attr_align = apr_pstrdup(doc->pool, "right");
3159         }
3160       }
3161       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
3162         if (cur->value && *cur->value) {
3163           attr_color = apr_pstrdup(doc->pool, cur->value);
3164         }
3165       }
3166       for (cur = text_deco_prop->next; cur != text_deco_prop; cur = cur->next) {
3167         if (cur->value && *cur->value && STRCASEEQ('b','B',"blink",cur->value)) {
3168           attr_blink = apr_pstrdup(doc->pool, cur->value);
3169         }
3170       }
3171       for (cur = clear_prop->next; cur != clear_prop; cur = cur->next) {
3172         css_clear = apr_pstrdup(doc->pool, cur->value);
3173       }
3174     }
3175   }
3176   W_L("<p");
3177   if ((attr_align && *attr_align) || (attr_color && *attr_color) || (attr_blink && *attr_blink) || css_clear) {
3178     W_L(" style=\"");
3179     if (attr_align) {
3180       W_L("text-align:");
3181       W_V(attr_align);
3182       W_L(";");
3183     }
3184     if (attr_color) {
3185       attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
3186       W_L("color:");
3187       W_V(attr_color);
3188       W_L(";");
3189     }
3190     if (attr_blink) {
3191       W_L("text-decoration:");
3192       W_V(attr_blink);
3193       W_L(";");
3194     }
3195     if (css_clear){
3196       W_L("clear:");
3197       W_V(css_clear);
3198       W_L(";");
3199     }
3200     W_L("\"");
3201   }
3202   W_L(">");
3203   return iphone->out;
3204 }
3205
3206
3207 /**
3208  * It is a handler who processes the P tag.
3209  *
3210  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
3211  *                     destination is specified.
3212  * @param node   [i]   The P tag node is specified.
3213  * @return The conversion result is returned.
3214  */
3215 static char *
3216 s_iphone_end_p_tag(void *pdoc, Node *UNUSED(child)) 
3217 {
3218   iphone_t  *iphone = GET_IPHONE(pdoc);
3219   Doc       *doc    = iphone->doc;
3220
3221   W_L("</p>");
3222   if (IS_CSS_ON(iphone->entryp)) {
3223     chxj_css_pop_prop_list(iphone->css_prop_stack);
3224   }
3225   return iphone->out;
3226 }
3227
3228
3229 /**
3230  * It is a handler who processes the PRE tag.
3231  *
3232  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
3233  *                     destination is specified.
3234  * @param node   [i]   The PRE tag node is specified.
3235  * @return The conversion result is returned.
3236  */
3237 static char *
3238 s_iphone_start_pre_tag(void *pdoc, Node *node)
3239 {
3240   iphone_t  *iphone = GET_IPHONE(pdoc);
3241   Doc       *doc   = iphone->doc;
3242   Attr      *attr;
3243   char      *attr_style = NULL;
3244   char      *css_clear  = NULL;
3245
3246   for (attr = qs_get_attr(doc,node);
3247        attr;
3248        attr = qs_get_next_attr(doc,attr)) {
3249     char *nm  = qs_get_attr_name(doc,attr);
3250     char *val = qs_get_attr_value(doc,attr);
3251     if (val && STRCASEEQ('s','S',"style", nm)) {
3252       attr_style = val;
3253     }
3254   }
3255
3256   if (IS_CSS_ON(iphone->entryp)) {
3257     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
3258     if (style) {
3259       css_property_t *clear_prop           = chxj_css_get_property_value(doc, style, "clear");
3260       
3261       css_property_t *cur;
3262       for (cur = clear_prop->next; cur != clear_prop; cur = cur->next) {
3263         css_clear = apr_pstrdup(doc->pool, cur->value);
3264       }
3265     }
3266   }
3267
3268   iphone->pre_flag++;
3269   W_L("<pre");
3270   if (css_clear) {
3271     W_L(" style=\"");
3272     W_L("clear:");
3273     W_V(css_clear);
3274     W_L(";");
3275     W_L("\"");
3276   }
3277   W_L(">");
3278   return iphone->out;
3279 }
3280
3281
3282 /**
3283  * It is a handler who processes the PRE tag.
3284  *
3285  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
3286  *                     destination is specified.
3287  * @param node   [i]   The PRE tag node is specified.
3288  * @return The conversion result is returned.
3289  */
3290 static char *
3291 s_iphone_end_pre_tag(void *pdoc, Node *UNUSED(child)) 
3292 {
3293   iphone_t *iphone = GET_IPHONE(pdoc);
3294   Doc     *doc   = iphone->doc;
3295
3296   W_L("</pre>");
3297   iphone->pre_flag--;
3298   if (IS_CSS_ON(iphone->entryp)) {
3299     chxj_css_pop_prop_list(iphone->css_prop_stack);
3300   }
3301
3302   return iphone->out;
3303 }
3304
3305
3306 /**
3307  * It is a handler who processes the UL tag.
3308  *
3309  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
3310  *                     destination is specified.
3311  * @param node   [i]   The UL tag node is specified.
3312  * @return The conversion result is returned.
3313  */
3314 static char *
3315 s_iphone_start_ul_tag(void *pdoc, Node *node)
3316 {
3317   iphone_t *iphone = GET_IPHONE(pdoc);
3318   Doc      *doc    = iphone->doc;
3319   Attr     *attr;
3320   char     *attr_type = NULL;
3321   char     *attr_style = NULL;
3322   char     *css_clear  = NULL;
3323   
3324   /*--------------------------------------------------------------------------*/
3325   /* Get Attributes                                                           */
3326   /*--------------------------------------------------------------------------*/
3327   for (attr = qs_get_attr(doc,node);
3328        attr;
3329        attr = qs_get_next_attr(doc,attr)) {
3330     char *name   = qs_get_attr_name(doc,attr);
3331     char *value  = qs_get_attr_value(doc,attr);
3332     if (STRCASEEQ('t','T',"type",name)) {
3333       if (value && (STRCASEEQ('d','D',"disc",value) || STRCASEEQ('c','C',"circle",value) || STRCASEEQ('s','S',"square",value))) {
3334         attr_type = value;
3335       }
3336     }
3337     else if (value && *value && STRCASEEQ('s','S',"style", name)) {
3338       attr_style = value;
3339     }
3340   }
3341   if (IS_CSS_ON(iphone->entryp)) {
3342     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
3343     if (style) {
3344       css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "list-style-type");
3345       css_property_t *clear_prop           = chxj_css_get_property_value(doc, style, "clear");
3346       
3347       css_property_t *cur;
3348       for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
3349         if (STRCASEEQ('d','D',"disc",cur->value)) {
3350           attr_type = apr_pstrdup(doc->pool, "disc");
3351         }
3352         else if (STRCASEEQ('c','C',"circle",cur->value)) {
3353           attr_type = apr_pstrdup(doc->pool, "circle");
3354         }
3355         else if (STRCASEEQ('s','S',"square",cur->value)) {
3356           attr_type = apr_pstrdup(doc->pool, "square");
3357         }
3358       }
3359       for (cur = clear_prop->next; cur != clear_prop; cur = cur->next) {
3360         css_clear = apr_pstrdup(doc->pool, cur->value);
3361       }
3362     }
3363   }
3364   W_L("<ul");
3365   if (attr_type || css_clear) {
3366     W_L(" style=\"");
3367     if (attr_type ){
3368       W_L("list-style-type:");
3369       W_V(attr_type);
3370       W_L(";");
3371     }
3372     if (css_clear){
3373       W_L("clear:");
3374       W_V(css_clear);
3375       W_L(";");
3376     }
3377     W_L("\"");
3378   }
3379   W_L(">");
3380   return iphone->out;
3381 }
3382
3383
3384 /**
3385  * It is a handler who processes the UL tag.
3386  *
3387  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
3388  *                     destination is specified.
3389  * @param node   [i]   The UL tag node is specified.
3390  * @return The conversion result is returned.
3391  */
3392 static char *
3393 s_iphone_end_ul_tag(void *pdoc, Node *UNUSED(child)) 
3394 {
3395   iphone_t *iphone = GET_IPHONE(pdoc);
3396   Doc     *doc   = iphone->doc;
3397
3398   W_L("</ul>");
3399   if (IS_CSS_ON(iphone->entryp)) {
3400     chxj_css_pop_prop_list(iphone->css_prop_stack);
3401   }
3402   return iphone->out;
3403 }
3404
3405
3406 /**
3407  * It is a handler who processes the HR tag.
3408  *
3409  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
3410  *                     destination is specified.
3411  * @param node   [i]   The HR tag node is specified.
3412  * @return The conversion result is returned.
3413  */
3414 static char *
3415 s_iphone_start_hr_tag(void *pdoc, Node *node) 
3416 {
3417   Attr        *attr;
3418   iphone_t     *iphone;
3419   Doc         *doc;
3420   request_rec *r;
3421   char        *attr_align   = NULL;
3422   char        *attr_size    = NULL;
3423   char        *attr_width   = NULL;
3424   char        *attr_noshade = NULL;
3425   char        *attr_style   = NULL;
3426   char        *attr_color   = NULL;
3427   char        *attr_bgcolor = NULL;
3428   
3429   char        *style_border_color = NULL;
3430   char        *css_clear          = NULL;
3431
3432   iphone   = GET_IPHONE(pdoc);
3433   doc     = iphone->doc;
3434   r       = doc->r;
3435
3436   for (attr = qs_get_attr(doc,node);
3437        attr; 
3438        attr = qs_get_next_attr(doc,attr)) {
3439     char *name  = qs_get_attr_name (doc,attr);
3440     char *value = qs_get_attr_value(doc,attr);
3441     switch(*name) {
3442     case 'a':
3443     case 'A':
3444       if (strcasecmp(name, "align") == 0) {
3445         /*--------------------------------------------------------------------*/
3446         /* CHTML 1.0                                                          */
3447         /*--------------------------------------------------------------------*/
3448         if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
3449           if (value[0] == 'c' || value[0] == 'C') {
3450             attr_align = apr_pstrdup(doc->pool, "none");
3451           }
3452           else {
3453             attr_align = value;
3454           }
3455         }
3456       }
3457       break;
3458
3459     case 's':
3460     case 'S':
3461       if (strcasecmp(name, "size") == 0) {
3462         /*--------------------------------------------------------------------*/
3463         /* CHTML 1.0                                                          */
3464         /*--------------------------------------------------------------------*/
3465         if (value && *value) {
3466           attr_size = value;
3467         }
3468       }
3469       else if (strcasecmp(name, "style") == 0) {
3470         if (value && *value) {
3471           attr_style = value;
3472         }
3473       }
3474       break;
3475
3476     case 'w':
3477     case 'W':
3478       if (strcasecmp(name, "width") == 0) {
3479         /*--------------------------------------------------------------------*/
3480         /* CHTML 1.0                                                          */
3481         /*--------------------------------------------------------------------*/
3482         if (value && *value) {
3483           attr_width = value;
3484         }
3485       }
3486       break;
3487
3488     case 'n':
3489     case 'N':
3490       if (strcasecmp(name, "noshade") == 0) {
3491         /*--------------------------------------------------------------------*/
3492         /* CHTML 1.0                                                          */
3493         /*--------------------------------------------------------------------*/
3494         attr_noshade = apr_pstrdup(doc->pool, "noshade");
3495       }
3496       break;
3497
3498     case 'c':
3499     case 'C':
3500       if (strcasecmp(name, "color") == 0 && value && *value) {
3501         /*--------------------------------------------------------------------*/
3502         /* CHTML 4.0                                                          */
3503         /*--------------------------------------------------------------------*/
3504         attr_color = value;
3505       }
3506       break;
3507
3508     default:
3509       break;
3510     }
3511   }
3512   if (IS_CSS_ON(iphone->entryp)) {
3513     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
3514     if (style) {
3515       css_property_t *border_style_prop = chxj_css_get_property_value(doc, style, "border-style");
3516       css_property_t *height_prop       = chxj_css_get_property_value(doc, style, "height");
3517       css_property_t *width_prop        = chxj_css_get_property_value(doc, style, "width");
3518       
3519       css_property_t *bgcolor_prop      = chxj_css_get_property_value(doc, style, "background-color");
3520       css_property_t *float_prop        = chxj_css_get_property_value(doc, style, "float");
3521       css_property_t *border_color_prop = chxj_css_get_property_value(doc, style, "border-color");
3522       css_property_t *clear_prop        = chxj_css_get_property_value(doc, style, "clear");
3523       css_property_t *cur;
3524       
3525       for (cur = border_style_prop->next; cur != border_style_prop; cur = cur->next) {
3526         if (STRCASEEQ('s','S',"solid",cur->value)) {
3527           attr_noshade = "noshade";
3528         }
3529       }
3530       for (cur = height_prop->next; cur != height_prop; cur = cur->next) {
3531         attr_size = apr_pstrdup(doc->pool, cur->value);
3532       }
3533       for (cur = bgcolor_prop->next; cur != bgcolor_prop; cur = cur->next) {
3534         attr_bgcolor = apr_pstrdup(doc->pool, cur->value);
3535       }
3536       if (!attr_align) {
3537         for (cur = float_prop->next; cur != float_prop; cur = cur->next) {
3538           attr_align = apr_pstrdup(doc->pool,cur->value);
3539         }
3540       }
3541       
3542       
3543       for (cur = width_prop->next; cur != width_prop; cur = cur->next) {
3544         char *tmp = apr_pstrdup(doc->pool, cur->value);
3545         char *tmpp = strstr(tmp, "px");
3546         if (tmpp) {
3547           attr_width = apr_pstrdup(doc->pool, tmp);
3548         }
3549         else {
3550           tmpp = strstr(tmp, "%");
3551           if (tmpp) {
3552             attr_width = apr_pstrdup(doc->pool, tmp);
3553           }
3554         }
3555       }
3556       
3557       for (cur = border_color_prop->next; cur != border_color_prop; cur = cur->next) {
3558         char *tmp = apr_pstrdup(doc->pool, cur->value);
3559         if(tmp){
3560           style_border_color = apr_pstrdup(doc->pool, tmp);
3561         }
3562       }
3563       for (cur = clear_prop->next; cur != clear_prop; cur = cur->next) {
3564         css_clear = apr_pstrdup(doc->pool, cur->value);
3565       }
3566     }
3567   }
3568   W_L("<hr");
3569   if (attr_align || attr_size || attr_width || attr_noshade || style_border_color || css_clear || attr_bgcolor) {
3570     W_L(" style=\"");
3571     if (attr_align) {
3572       W_L("float:");
3573       W_V(attr_align);
3574       W_L(";");
3575     }
3576     if (attr_size) {
3577       W_L("height:");
3578       W_V(attr_size);
3579       if (chxj_chk_numeric(attr_size) == 0) {
3580         W_L("px");
3581       }
3582       W_L(";");
3583     }
3584     if (attr_width) {
3585       W_L("width:");
3586       W_V(attr_width);
3587       if (!strstr(attr_width, "px") && !strstr(attr_width, "%")) {
3588         W_L("px");
3589       }
3590       W_L(";");
3591     }
3592     if (attr_noshade) {
3593       W_L("border-style:solid;");
3594     }
3595     if(style_border_color){
3596       W_L("border-color:");
3597       W_V(style_border_color);
3598       W_L(";");
3599     }
3600     if (attr_bgcolor) {
3601       W_L("background-color:");
3602       W_V(attr_bgcolor);
3603       W_L(";");
3604     }
3605     if (css_clear){
3606       W_L("clear:");
3607       W_V(css_clear);
3608       W_L(";");
3609     }
3610     W_L("\"");
3611   }
3612   if (attr_color) {
3613     W_L(" color=\"");
3614     W_V(attr_color);
3615     W_L("\"");
3616   }
3617   
3618   W_L(" />");
3619
3620   return iphone->out;
3621 }
3622
3623
3624 /**
3625  * It is a handler who processes the HR tag.
3626  *
3627  * @param iphone  [i/o] The pointer to the IPHONE structure at the output
3628  *                     destination is specified.
3629  * @param node   [i]   The HR tag node is specified.
3630  * @return The conversion result is returned.
3631  */
3632 static char *
3633 s_iphone_end_hr_tag(void *pdoc, Node *UNUSED(child)) 
3634 {
3635   iphone_t *iphone = GET_IPHONE(pdoc);
3636   return iphone->out;
3637 }
3638
3639
3640 /**
3641  * It is a handler who processes the IMG tag.
3642  *
3643  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
3644  *                     destination is specified.
3645  * @param node   [i]   The IMG tag node is specified.
3646  * @return The conversion result is returned.
3647  */
3648 static char *
3649 s_iphone_start_img_tag(void *pdoc, Node *node) 
3650 {
3651   iphone_t    *iphone = GET_IPHONE(pdoc);
3652   Doc         *doc   = iphone->doc;
3653   request_rec *r     = doc->r;
3654   Attr        *attr;
3655   char        *attr_src    = NULL;
3656   char        *attr_height = NULL;
3657   char        *attr_width  = NULL;
3658   char        *attr_alt    = NULL;
3659   char        *attr_style  = NULL;
3660   char        *attr_hspace = NULL;
3661   char        *attr_vspace = NULL;
3662   
3663   char        *css_float          = NULL;
3664   char        *css_margin_left    = NULL;
3665   char        *css_margin_right   = NULL;
3666   char        *css_margin_top     = NULL;
3667   char        *css_margin_bottom  = NULL;
3668   char        *css_display        = NULL;
3669   char        *css_valign         = NULL;
3670   
3671 #ifndef IMG_NOT_CONVERT_FILENAME
3672   device_table  *spec = iphone->spec;
3673 #endif
3674
3675   /*--------------------------------------------------------------------------*/
3676   /* Get Attributes                                                           */
3677   /*--------------------------------------------------------------------------*/
3678   for (attr = qs_get_attr(doc,node);
3679        attr;
3680        attr = qs_get_next_attr(doc,attr)) {
3681     char *name  = qs_get_attr_name(doc,attr);
3682     char *value = qs_get_attr_value(doc,attr);
3683     if (STRCASEEQ('s','S',"src",name)) {
3684       /*----------------------------------------------------------------------*/
3685       /* CHTML 1.0                                                            */
3686       /*----------------------------------------------------------------------*/
3687 #ifdef IMG_NOT_CONVERT_FILENAME
3688       value = chxj_encoding_parameter(r, value, 1);
3689       value = chxj_jreserved_tag_to_safe_for_query_string(r, value, iphone->entryp, 1);
3690       value = chxj_add_cookie_no_update_parameter(r, value, 1);
3691       value = chxj_img_rewrite_parameter(r,iphone->conf,value);
3692       attr_src = value;
3693 #else
3694       value = chxj_img_conv(r, spec, value);
3695       value = chxj_encoding_parameter(r, value, 1);
3696       value = chxj_jreserved_tag_to_safe_for_query_string(r, value, iphone->entryp, 1);
3697       value = chxj_add_cookie_no_update_parameter(r, value, 1);
3698       value = chxj_img_rewrite_parameter(r,iphone->conf,value);
3699       attr_src = value;
3700 #endif
3701     }
3702     else if (STRCASEEQ('a','A',"align",name)) {
3703       /*----------------------------------------------------------------------*/
3704       /* CHTML 1.0                                                            */
3705       /*----------------------------------------------------------------------*/
3706       if (value) {
3707         if (STRCASEEQ('t','T',"top",   value) ||
3708             STRCASEEQ('m','M',"middle",value) ||
3709             STRCASEEQ('b','B',"bottom",value)){
3710           css_valign = value;
3711         }else if (STRCASEEQ('l','L',"left",  value) || STRCASEEQ('r','R',"right", value)) {
3712           css_float = value;
3713         }
3714         else if (STRCASEEQ('c','C',"center",value)) {
3715           css_valign = apr_pstrdup(doc->pool, "middle");
3716         }
3717       }
3718     }
3719     else if (STRCASEEQ('w','W',"width",name) && value && *value) {
3720       /*----------------------------------------------------------------------*/
3721       /* CHTML 1.0                                                            */
3722       /*----------------------------------------------------------------------*/
3723       attr_width = value;
3724     }
3725     else if (STRCASEEQ('h','H',"height",name) && value && *value) {
3726       /*----------------------------------------------------------------------*/
3727       /* CHTML 1.0                                                            */
3728       /*----------------------------------------------------------------------*/
3729       attr_height = value;
3730     }
3731     else if (STRCASEEQ('h','H',"hspace",name)) {
3732       /*----------------------------------------------------------------------*/
3733       /* CHTML 1.0                                                            */
3734       /*----------------------------------------------------------------------*/
3735       attr_hspace = value;
3736     }
3737     else if (STRCASEEQ('v','V',"vspace",name)) {
3738       /*----------------------------------------------------------------------*/
3739       /* CHTML 1.0                                                            */
3740       /*----------------------------------------------------------------------*/
3741       attr_vspace = value;
3742     }
3743     else if (STRCASEEQ('a','A',"alt",name) && value && *value) {
3744       /*----------------------------------------------------------------------*/
3745       /* CHTML 1.0                                                            */
3746       /*----------------------------------------------------------------------*/
3747       attr_alt = value;
3748     }
3749     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
3750       /*----------------------------------------------------------------------*/
3751       /* CHTML 1.0                                                            */
3752       /*----------------------------------------------------------------------*/
3753       attr_style = value;
3754     }
3755   }
3756
3757   if (IS_CSS_ON(iphone->entryp)) {
3758     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
3759     if (style) {
3760       css_property_t *height_prop = chxj_css_get_property_value(doc, style, "height");
3761       css_property_t *width_prop  = chxj_css_get_property_value(doc, style, "width");
3762       css_property_t *valign_prop = chxj_css_get_property_value(doc, style, "vertical-align");
3763       css_property_t *margin_left_prop   = chxj_css_get_property_value(doc, style, "margin-left");
3764       css_property_t *margin_right_prop  = chxj_css_get_property_value(doc, style, "margin-right");
3765       css_property_t *margin_top_prop    = chxj_css_get_property_value(doc, style, "margin-top");
3766       css_property_t *margin_bottom_prop = chxj_css_get_property_value(doc, style, "margin-bottom");
3767       
3768       
3769       css_property_t *cur;
3770       for (cur = height_prop->next; cur != height_prop; cur = cur->next) {
3771         attr_height = apr_pstrdup(doc->pool, cur->value);
3772       }
3773       for (cur = width_prop->next; cur != width_prop; cur = cur->next) {
3774         attr_width = apr_pstrdup(doc->pool, cur->value);
3775       }
3776       if(!css_valign){
3777         for (cur = valign_prop->next; cur != valign_prop; cur = cur->next) {
3778           css_valign = apr_pstrdup(doc->pool, cur->value);
3779         }
3780       }
3781       if (! attr_hspace) {
3782         for (cur = margin_left_prop->next; cur != margin_left_prop; cur = cur->next) {
3783           css_margin_left   = apr_pstrdup(doc->pool, cur->value);
3784         }
3785         for (cur = margin_right_prop->next; cur != margin_right_prop; cur = cur->next) {
3786           css_margin_right  = apr_pstrdup(doc->pool, cur->value);
3787         }
3788       }
3789       if (! attr_vspace) {
3790         for (cur = margin_top_prop->next; cur != margin_top_prop; cur = cur->next) {
3791           css_margin_top = apr_pstrdup(doc->pool, cur->value);
3792         }
3793         for (cur = margin_bottom_prop->next; cur != margin_bottom_prop; cur = cur->next) {
3794           css_margin_bottom = apr_pstrdup(doc->pool, cur->value);
3795         }
3796       }
3797       if(!css_float){
3798         css_property_t *float_prop = chxj_css_get_property_value(doc, style, "float");
3799         for (cur = float_prop->next; cur != float_prop; cur = cur->next) {
3800           css_float = apr_pstrdup(doc->pool, cur->value);
3801         }
3802       }
3803       
3804       css_property_t *display_prop       = chxj_css_get_property_value(doc, style, "display");
3805       for (cur = display_prop->next; cur != display_prop; cur = cur->next) {
3806         char *tmp = apr_pstrdup(doc->pool, cur->value);
3807         char *tmpp = strstr(tmp, "none");
3808         if(tmpp){
3809           css_display = apr_pstrdup(doc->pool, tmp);
3810         }
3811       }
3812     }
3813   }
3814
3815   W_L("<img");
3816   if (attr_src) {
3817     W_L(" src=\"");
3818     W_V(attr_src);
3819     W_L("\"");
3820   }
3821   if (attr_hspace || attr_vspace || css_float || css_margin_left || css_margin_right || css_margin_top || css_margin_bottom || css_valign || css_display) {
3822     W_L(" style=\"");
3823     if(css_float){
3824       W_L("float:");
3825       W_V(css_float);
3826       W_L(";");
3827     }
3828     if(css_valign){
3829       W_L("vertical-align:");
3830       W_V(css_valign);
3831       W_L(";");
3832     }
3833     if (attr_hspace) {
3834       W_L("margin-left:");
3835       W_V(attr_hspace);
3836       W_L(";");
3837       W_L("margin-right:");
3838       W_V(attr_hspace);
3839       W_L(";");
3840     }
3841     else{
3842       if(css_margin_left){
3843         W_L("margin-left:");
3844         W_V(css_margin_left);
3845         W_L(";");
3846       }
3847       if(css_margin_right){
3848         W_L("margin-right:");
3849         W_V(css_margin_right);
3850         W_L(";");
3851       }
3852     }
3853     if (attr_vspace) {
3854       W_L("margin-top:");
3855       W_V(attr_vspace);
3856       W_L(";");
3857       W_L("margin-bottom:");
3858       W_V(attr_vspace);
3859       W_L(";");
3860     }
3861     else{
3862       if(css_margin_top){
3863         W_L("margin-top:");
3864         W_V(css_margin_top);
3865         W_L(";");
3866       }
3867       if(css_margin_bottom){
3868         W_L("margin-bottom:");
3869         W_V(css_margin_bottom);
3870         W_L(";");
3871       }
3872     }
3873     if(css_display){
3874       W_L("display:none;");
3875     }
3876     W_L("\"");
3877   }
3878   
3879   if (attr_width) {
3880     W_L(" width=\"");
3881     W_V(attr_width);
3882     W_L("\"");
3883   }
3884   if (attr_height) {
3885     W_L(" height=\"");
3886     W_V(attr_height);
3887     W_L("\"");
3888   }
3889   if (attr_alt) {
3890     W_L(" alt=\"");
3891     W_V(attr_alt);
3892     W_L("\"");
3893   } 
3894   else {
3895     W_L(" alt=\"\"");
3896   }
3897   W_L(" />");
3898   return iphone->out;
3899 }
3900
3901
3902 /**
3903  * It is a handler who processes the IMG tag.
3904  *
3905  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
3906  *                     destination is specified.
3907  * @param node   [i]   The IMG tag node is specified.
3908  * @return The conversion result is returned.
3909  */
3910 static char *
3911 s_iphone_end_img_tag(void *pdoc, Node *UNUSED(child)) 
3912 {
3913   iphone_t *iphone = GET_IPHONE(pdoc);
3914   return iphone->out;
3915 }
3916
3917
3918 /**
3919  * It is a handler who processes the SELECT tag.
3920  *
3921  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
3922  *                     destination is specified.
3923  * @param node   [i]   The SELECT tag node is specified.
3924  * @return The conversion result is returned.
3925  */
3926 static char *
3927 s_iphone_start_select_tag(void *pdoc, Node *node)
3928 {
3929   iphone_t *iphone    = GET_IPHONE(pdoc);
3930   Doc     *doc      = iphone->doc;
3931   Attr    *attr;
3932   char    *size     = NULL;
3933   char    *name     = NULL;
3934   char    *multiple = NULL;
3935   char    *attr_style = NULL;
3936
3937   W_L("<select");
3938   for (attr = qs_get_attr(doc,node);
3939        attr;
3940        attr = qs_get_next_attr(doc,attr)) {
3941     char *nm  = qs_get_attr_name(doc,attr);
3942     char *val = qs_get_attr_value(doc,attr);
3943     if (STRCASEEQ('s','S',"size",nm)) {
3944       /*----------------------------------------------------------------------*/
3945       /* CHTML 1.0 version 2.0                                                */
3946       /*----------------------------------------------------------------------*/
3947       size = apr_pstrdup(doc->buf.pool, val);
3948     }
3949     else if (STRCASEEQ('s','S',"style",nm) && val && *val) {
3950       /*----------------------------------------------------------------------*/
3951       /* CHTML 1.0 version 2.0                                                */
3952       /*----------------------------------------------------------------------*/
3953       attr_style = apr_pstrdup(doc->buf.pool, val);
3954     }
3955     else if (STRCASEEQ('n','N',"name",nm)) {
3956       /*----------------------------------------------------------------------*/
3957       /* CHTML 1.0 version 2.0                                                */
3958       /*----------------------------------------------------------------------*/
3959       name = apr_pstrdup(doc->buf.pool, val);
3960     }
3961     else if (STRCASEEQ('m','M',"multiple", nm)) {
3962       /*----------------------------------------------------------------------*/
3963       /* CHTML 1.0 version 2.0                                                */
3964       /*----------------------------------------------------------------------*/
3965       multiple = apr_pstrdup(doc->buf.pool, val);
3966     }
3967   }
3968   if (size && *size) {
3969     W_L(" size=\"");
3970     W_V(size);
3971     W_L("\"");
3972   }
3973   if (name && *name) {
3974     W_L(" name=\"");
3975     W_V(name);
3976     W_L("\"");
3977   }
3978   if (multiple) {
3979     W_L(" multiple=\"multiple\"");
3980   }
3981   W_L(">");
3982
3983   if (IS_CSS_ON(iphone->entryp)) {
3984     s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
3985   }
3986
3987   return iphone->out;
3988 }
3989
3990
3991 /**
3992  * It is a handler who processes the SELECT tag.
3993  *
3994  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
3995  *                     destination is specified.
3996  * @param node   [i]   The SELECT tag node is specified.
3997  * @return The conversion result is returned.
3998  */
3999 static char *
4000 s_iphone_end_select_tag(void *pdoc, Node *UNUSED(child))
4001 {
4002   iphone_t *iphone = GET_IPHONE(pdoc);
4003   Doc     *doc   = iphone->doc;
4004
4005   W_L("</select>");
4006   if (IS_CSS_ON(iphone->entryp)) {
4007     chxj_css_pop_prop_list(iphone->css_prop_stack);
4008   }
4009
4010   return iphone->out;
4011 }
4012
4013 /**
4014  * It is a handler who processes the OPTION tag.
4015  *
4016  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
4017  *                     destination is specified.
4018  * @param node   [i]   The OPTION tag node is specified.
4019  * @return The conversion result is returned.
4020  */
4021 static char *
4022 s_iphone_start_option_tag(void *pdoc, Node *node)
4023 {
4024   iphone_t *iphone = GET_IPHONE(pdoc);
4025   Doc     *doc   = iphone->doc;
4026   Attr    *attr;
4027
4028   char *selected   = NULL;
4029   char *value      = NULL;
4030   char *attr_style = NULL;
4031
4032   W_L("<option");
4033   for (attr = qs_get_attr(doc,node);
4034        attr;
4035        attr = qs_get_next_attr(doc,attr)) {
4036     char *nm  = qs_get_attr_name(doc,attr);
4037     char *val = qs_get_attr_value(doc,attr);
4038     if (STRCASEEQ('s','S',"selected",nm)) {
4039       /*----------------------------------------------------------------------*/
4040       /* CHTML 1.0 version 2.0                                                */
4041       /*----------------------------------------------------------------------*/
4042       selected = apr_pstrdup(doc->buf.pool, val);
4043     }
4044     else if (STRCASEEQ('s','S',"style",nm) && val && *val) {
4045       /*----------------------------------------------------------------------*/
4046       /* CHTML 1.0 version 2.0                                                */
4047       /*----------------------------------------------------------------------*/
4048       attr_style = apr_pstrdup(doc->buf.pool, val);
4049     }
4050     else if (STRCASEEQ('v','V',"value",nm)) {
4051       /*----------------------------------------------------------------------*/
4052       /* CHTML 1.0 version 2.0                                                */
4053       /*----------------------------------------------------------------------*/
4054       value = apr_pstrdup(doc->buf.pool, val);
4055     }
4056   }
4057   if (value) {
4058     W_L(" value=\"");
4059     W_V(value);
4060     W_L("\"");
4061   }
4062   if (selected) {
4063     W_L(" selected=\"selected\"");
4064   }
4065   W_L(">");
4066
4067   if (IS_CSS_ON(iphone->entryp)) {
4068     s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
4069   }
4070
4071   return iphone->out;
4072 }
4073
4074
4075 /**
4076  * It is a handler who processes the OPTION tag.
4077  *
4078  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
4079  *                     destination is specified.
4080  * @param node   [i]   The OPTION tag node is specified.
4081  * @return The conversion result is returned.
4082  */
4083 static char *
4084 s_iphone_end_option_tag(void *pdoc, Node *UNUSED(child))
4085 {
4086   iphone_t *iphone = GET_IPHONE(pdoc);
4087   Doc      *doc = iphone->doc;
4088
4089   W_L("</option>");
4090   if (IS_CSS_ON(iphone->entryp)) {
4091     chxj_css_pop_prop_list(iphone->css_prop_stack);
4092   }
4093
4094   return iphone->out;
4095 }
4096
4097
4098 /**
4099  * It is a handler who processes the DIV tag.
4100  *
4101  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
4102  *                     destination is specified.
4103  * @param node   [i]   The DIV tag node is specified.
4104  * @return The conversion result is returned.
4105  */
4106 static char *
4107 s_iphone_start_div_tag(void *pdoc, Node *node)
4108 {
4109   iphone_t    *iphone;
4110   Doc         *doc;
4111   request_rec *r;
4112   Attr        *attr;
4113   char        *attr_style             = NULL;
4114   char        *attr_align             = NULL;
4115   char        *attr_display           = NULL;
4116   char        *attr_decoration        = NULL;
4117   char        *attr_wap_marquee_style = NULL;
4118   char        *attr_wap_marquee_dir   = NULL;
4119   char        *attr_wap_marquee_loop  = NULL;
4120   char        *attr_wap_marquee_speed = NULL;
4121   char        *attr_color             = NULL;
4122   char        *attr_bgcolor           = NULL;
4123   char        *attr_font_size         = NULL;
4124   char        *css_clear              = NULL;
4125
4126   iphone = GET_IPHONE(pdoc);
4127   doc   = iphone->doc;
4128   r     = doc->r;
4129
4130   for (attr = qs_get_attr(doc,node);
4131        attr;
4132        attr = qs_get_next_attr(doc,attr)) {
4133     char *nm  = qs_get_attr_name(doc,attr);
4134     char *val = qs_get_attr_value(doc,attr);
4135     if (STRCASEEQ('a','A',"align",nm)) {
4136       /*----------------------------------------------------------------------*/
4137       /* CHTML 1.0 (W3C version 3.2)                                          */
4138       /*----------------------------------------------------------------------*/
4139       if (val && (STRCASEEQ('l','L',"left",val) || STRCASEEQ('r','R',"right",val) || STRCASEEQ('c','C',"center",val))) {
4140         attr_align = apr_pstrdup(doc->buf.pool, val);
4141       }
4142     }
4143     else if (STRCASEEQ('s','S',"style",nm) && val && *val) {
4144       attr_style = apr_pstrdup(doc->buf.pool, val);
4145     }
4146   }
4147
4148   if (IS_CSS_ON(iphone->entryp)) {
4149     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
4150     if (style) {
4151       css_property_t *display_prop           = chxj_css_get_property_value(doc, style, "display");
4152       css_property_t *text_decoration_prop   = chxj_css_get_property_value(doc, style, "text-decoration");
4153       css_property_t *color_prop             = chxj_css_get_property_value(doc, style, "color");
4154       css_property_t *text_align_prop        = chxj_css_get_property_value(doc, style, "text-align");
4155       css_property_t *font_size_prop         = chxj_css_get_property_value(doc, style, "font-size");
4156       css_property_t *background_color_prop  = chxj_css_get_property_value(doc, style, "background-color");
4157       css_property_t *background_prop        = chxj_css_get_property_value(doc, style, "background");
4158       css_property_t *clear_prop             = chxj_css_get_property_value(doc, style, "clear");
4159
4160       css_property_t *cur;
4161       for (cur = display_prop->next; cur != display_prop; cur = cur->next) {
4162         if (strcasecmp("-wap-marquee", cur->value) == 0) {
4163           attr_display = apr_pstrdup(doc->pool, cur->value);
4164         }
4165       }
4166       for (cur = text_decoration_prop->next; cur != text_decoration_prop; cur = cur->next) {
4167         if (STRCASEEQ('b','B',"blink", cur->value)) {
4168           attr_decoration = apr_pstrdup(doc->pool, cur->value);
4169         }
4170       }
4171       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
4172         attr_color = apr_pstrdup(doc->pool, cur->value);
4173       }
4174       for (cur = background_color_prop->next; cur != background_color_prop; cur = cur->next) {
4175         attr_bgcolor = apr_pstrdup(doc->pool, cur->value);
4176         attr_bgcolor = chxj_css_rgb_func_to_value(doc->pool, attr_bgcolor);
4177       }
4178       for (cur = background_prop->next; cur != background_prop; cur = cur->next) {
4179         char *ss = strchr(cur->value, '#');
4180         if (!ss || !*ss) {
4181           ss = strstr(cur->value, "rgb");
4182         }
4183         if (ss && *ss) {
4184           attr_bgcolor = apr_pstrdup(doc->pool, cur->value);
4185           attr_bgcolor = chxj_css_rgb_func_to_value(doc->pool, attr_bgcolor);
4186         }
4187       }
4188       for (cur = text_align_prop->next; cur != text_align_prop; cur = cur->next) {
4189         attr_align = apr_pstrdup(doc->pool, cur->value);
4190       }
4191       for (cur = font_size_prop->next; cur != font_size_prop; cur = cur->next) {
4192         if (   STRCASEEQ('x','X',"xx-small",cur->value)
4193             || STRCASEEQ('x','X',"x-small",cur->value)
4194             || STRCASEEQ('s','S',"small",cur->value)
4195             || STRCASEEQ('m','M',"medium",cur->value)
4196             || STRCASEEQ('l','L',"large",cur->value)
4197             || STRCASEEQ('x','X',"x-large",cur->value)
4198             || STRCASEEQ('x','X',"xx-large",cur->value)) {
4199           attr_font_size = apr_pstrdup(doc->pool, cur->value);
4200         }
4201       }
4202       if (attr_display) {
4203         css_property_t *wap_marquee_style_prop = chxj_css_get_property_value(doc, style, "-wap-marquee-style");
4204         css_property_t *wap_marquee_dir_prop   = chxj_css_get_property_value(doc, style, "-wap-marquee-dir");
4205         css_property_t *wap_marquee_loop_prop  = chxj_css_get_property_value(doc, style, "-wap-marquee-loop");
4206         css_property_t *wap_marquee_speed_prop = chxj_css_get_property_value(doc, style, "-wap-marquee-speed");
4207         for (cur = wap_marquee_style_prop->next; cur != wap_marquee_style_prop; cur = cur->next) {
4208           if (STRCASEEQ('s','S',"scroll", cur->value) || STRCASEEQ('s','S',"slide",cur->value) || STRCASEEQ('a','A',"alternate",cur->value)) {
4209             attr_wap_marquee_style = apr_pstrdup(doc->pool, cur->value);
4210           }
4211         }
4212         for (cur = wap_marquee_dir_prop->next; cur != wap_marquee_dir_prop; cur = cur->next) {
4213           if (STRCASEEQ('l','L',"ltr",cur->value)) {
4214             attr_wap_marquee_dir = apr_pstrdup(doc->pool, cur->value);
4215           }
4216           else if (STRCASEEQ('r','R',"rtl",cur->value)) {
4217             attr_wap_marquee_dir = apr_pstrdup(doc->pool, cur->value);
4218           }
4219         }
4220         for (cur = wap_marquee_loop_prop->next; cur != wap_marquee_loop_prop; cur = cur->next) {
4221           if(strcmp(cur->value,"0") == 0 || strcmp(cur->value,"-1") == 0){
4222             attr_wap_marquee_loop = "infinite";
4223           }
4224           else{
4225             attr_wap_marquee_loop = apr_pstrdup(doc->pool, cur->value);
4226           }
4227         }
4228         for (cur = wap_marquee_speed_prop->next; cur != wap_marquee_speed_prop; cur = cur->next) {
4229           attr_wap_marquee_speed = apr_pstrdup(doc->pool, cur->value);
4230         }
4231       }
4232       for (cur = clear_prop->next; cur != clear_prop; cur = cur->next) {
4233         css_clear = apr_pstrdup(doc->pool, cur->value);
4234       }
4235     }
4236   }  
4237   W_L("<div");
4238   if (attr_align
4239       || attr_display
4240       || attr_decoration
4241       || attr_wap_marquee_style
4242       || attr_wap_marquee_dir
4243       || attr_wap_marquee_loop
4244       || attr_wap_marquee_speed
4245       || attr_color
4246       || attr_bgcolor
4247       || attr_font_size
4248       || css_clear ) {
4249     W_L(" style=\"");
4250     if (attr_align) {
4251       W_L("text-align:");
4252       W_V(attr_align);
4253       W_L(";");
4254     }
4255     if (attr_display) {
4256       /* only marquee */
4257       W_L("overflow:-webkit-marquee;");
4258     }
4259     if (attr_decoration) {
4260       if (STRCASEEQ('b','B',"blink",attr_decoration)) {
4261         W_L(STYLE_BLINK);
4262         if (iphone->blink_keyframe_out == 0) {
4263           iphone->style_data = apr_pstrcat(doc->pool, (iphone->style_data) ? iphone->style_data : "",
4264                                                       BLINK_KEYFRAME,
4265                                                       NULL);
4266           iphone->blink_keyframe_out = 1;
4267         }
4268       }
4269       else {
4270         W_L("text-decoration:");
4271         W_V(attr_decoration);
4272         W_L(";");
4273       }
4274     }
4275     if (attr_wap_marquee_style) {
4276       W_L("-webkit-marquee-style:");
4277       W_V(attr_wap_marquee_style);
4278       W_L(";");
4279     }
4280     if (attr_wap_marquee_dir) {
4281       W_L("-webkit-marquee-direction:");
4282       if (STRCASEEQ('r','R',"rtl",attr_wap_marquee_dir)) {
4283         W_L("left");
4284       }
4285       else if (STRCASEEQ('l','L',"ltr",attr_wap_marquee_dir)) {
4286         W_L("right");
4287       }
4288       W_L(";");
4289     }
4290     if (attr_wap_marquee_loop) {
4291       W_L("-webkit-marquee-repetition:");
4292       W_V(attr_wap_marquee_loop);
4293       W_L(";");
4294     }
4295     if (attr_wap_marquee_speed) {
4296       W_L("-webkit-marquee-speed:");
4297       W_V(attr_wap_marquee_speed);
4298       W_L(";");
4299     }
4300     if (attr_color) {
4301       W_L("color:");
4302       W_V(attr_color);
4303       W_L(";");
4304     }
4305     if (attr_bgcolor) {
4306       W_L("background-color:");
4307       W_V(attr_bgcolor);
4308       W_L(";");
4309     }
4310     if (attr_font_size) {
4311       W_L("font-size:");
4312       W_V(attr_font_size);
4313       W_L(";");
4314     }
4315     if (css_clear){
4316       W_L("clear:");
4317       W_V(css_clear);
4318       W_L(";");
4319     }
4320     W_L("\"");
4321   }
4322   W_L(">");
4323   return iphone->out;
4324 }
4325
4326
4327 /**
4328  * It is a handler who processes the DIV tag.
4329  *
4330  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
4331  *                     destination is specified.
4332  * @param node   [i]   The DIV tag node is specified.
4333  * @return The conversion result is returned.
4334  */
4335 static char *
4336 s_iphone_end_div_tag(void *pdoc, Node *UNUSED(child))
4337 {
4338   iphone_t      *iphone;
4339   Doc          *doc;
4340   request_rec  *r;
4341
4342   iphone = GET_IPHONE(pdoc);
4343   doc   = iphone->doc;
4344   r     = doc->r;
4345
4346   W_L("</div>");
4347   if (IS_CSS_ON(iphone->entryp)) {
4348     chxj_css_pop_prop_list(iphone->css_prop_stack);
4349   }
4350   return iphone->out;
4351 }
4352
4353
4354 static char *
4355 s_iphone_chxjif_tag(void *pdoc, Node *node)
4356 {
4357   iphone_t *iphone;
4358   Doc     *doc;
4359   Node    *child;
4360   request_rec *r;
4361
4362   iphone = GET_IPHONE(pdoc);
4363   doc   = iphone->doc;
4364   r     = doc->r;
4365
4366   for (child = qs_get_child_node(doc, node);
4367        child;
4368        child = qs_get_next_node(doc, child)) {
4369     W_V(child->otext);
4370     s_iphone_chxjif_tag(iphone, child);
4371   }
4372   return NULL;
4373 }
4374
4375
4376 /**
4377  * It is a handler who processes the TEXTARE tag.
4378  *
4379  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
4380  *                     destination is specified.
4381  * @param node   [i]   The TEXTAREA tag node is specified.
4382  * @return The conversion result is returned.
4383  */
4384 static char *
4385 s_iphone_start_textarea_tag(void *pdoc, Node *node) 
4386 {
4387   iphone_t      *iphone;
4388   Doc           *doc;
4389   request_rec   *r;
4390   Attr          *attr;
4391   char          *attr_accesskey = NULL;
4392   char          *attr_name      = NULL;
4393   char          *attr_rows      = NULL;
4394   char          *attr_cols      = NULL;
4395   char          *attr_istyle    = NULL;
4396   char          *attr_style     = NULL;
4397
4398
4399   iphone = GET_IPHONE(pdoc);
4400   doc   = iphone->doc;
4401   r     = doc->r;
4402
4403   iphone->textarea_flag++;
4404   for (attr = qs_get_attr(doc,node);
4405        attr;
4406        attr = qs_get_next_attr(doc,attr)) {
4407     char *name  = qs_get_attr_name(doc,attr);
4408     char *value = qs_get_attr_value(doc,attr);
4409     if (STRCASEEQ('a','A',"accesskey",name) && value && *value != 0) {
4410       attr_accesskey = value;
4411     }
4412     else if (STRCASEEQ('i','I',"istyle", name) && value && (*value == '1' || *value == '2' || *value == '3' || *value == '4')) {
4413       attr_istyle = value;
4414     }
4415     else if (STRCASEEQ('n','N',"name", name) && value && *value) {
4416       attr_name = value;
4417     }
4418     else if (STRCASEEQ('r','R',"rows", name) && value && *value) {
4419       attr_rows = value;
4420     }
4421     else if (STRCASEEQ('c','C',"cols", name) && value && *value) {
4422       attr_cols = value;
4423     }
4424     else if (STRCASEEQ('s','S',"style", name) && value && *value) {
4425       attr_style = value;
4426     }
4427   }
4428   if (IS_CSS_ON(iphone->entryp)) {
4429     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
4430     if (style) {
4431       css_property_t *wap_input_format = chxj_css_get_property_value(doc, style, "-wap-input-format");
4432       css_property_t *cur;
4433       for (cur = wap_input_format->next; cur != wap_input_format; cur = cur->next) {
4434         if (strcasestr(cur->value, "<ja:n>")) {
4435           attr_istyle = "4";
4436         }
4437         else if (strcasestr(cur->value, "<ja:en>")) {
4438           attr_istyle = "3";
4439         }
4440         else if (strcasestr(cur->value, "<ja:hk>")) {
4441           attr_istyle = "2";
4442         }
4443         else if (strcasestr(cur->value, "<ja:h>")) {
4444           attr_istyle = "1";
4445         }
4446       }
4447     }
4448   }
4449   W_L("<textarea");
4450   if (attr_name) {
4451     W_L(" name=\"");
4452     W_V(attr_name);
4453     W_L("\"");
4454   }
4455   if (attr_rows) {
4456     W_L(" rows=\"");
4457     W_V(attr_rows);
4458     W_L("\"");
4459   }
4460   if (attr_cols) {
4461     W_L(" cols=\"");
4462     W_V(attr_cols);
4463     W_L("\"");
4464   }
4465   W_L(">");
4466   return iphone->out;
4467 }
4468
4469
4470 /**
4471  * It is a handler who processes the TEXTAREA tag.
4472  *
4473  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
4474  *                     destination is specified.
4475  * @param node   [i]   The TEXTAREA tag node is specified.
4476  * @return The conversion result is returned.
4477  */
4478 static char *
4479 s_iphone_end_textarea_tag(void *pdoc, Node *UNUSED(child)) 
4480 {
4481   iphone_t       *iphone;
4482   Doc           *doc;
4483   request_rec   *r;
4484
4485   iphone = GET_IPHONE(pdoc);
4486   doc   = iphone->doc;
4487   r     = doc->r;
4488
4489   W_L("</textarea>");
4490   iphone->textarea_flag--;
4491
4492   return iphone->out;
4493 }
4494
4495
4496 /**
4497  * It is a handler who processes the B tag.
4498  *
4499  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
4500  *                     destination is specified.
4501  * @param node   [i]   The B tag node is specified.
4502  * @return The conversion result is returned.
4503  */
4504 static char*
4505 s_iphone_start_b_tag(void* pdoc, Node* UNUSED(node)) 
4506 {
4507   iphone_t*      iphone;
4508   Doc*          doc;
4509   request_rec*  r;
4510
4511   iphone = GET_IPHONE(pdoc);
4512   doc   = iphone->doc;
4513   r     = doc->r;
4514
4515   W_L("<b>");
4516   return iphone->out;
4517 }
4518
4519
4520 /**
4521  * It is a handler who processes the B tag.
4522  *
4523  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
4524  *                     destination is specified.
4525  * @param node   [i]   The B tag node is specified.
4526  * @return The conversion result is returned.
4527  */
4528 static char*
4529 s_iphone_end_b_tag(void* pdoc, Node* UNUSED(child)) 
4530 {
4531   iphone_t*      iphone = GET_IPHONE(pdoc);
4532   Doc*          doc   = iphone->doc;
4533
4534   W_L("</b>");
4535   return iphone->out;
4536 }
4537
4538 static char*
4539 s_iphone_text_tag(void* pdoc, Node* child)
4540 {
4541   iphone_t*     iphone;
4542   Doc*         doc;
4543   char*        textval;
4544   char*        tmp;
4545   char*        tdst;
4546   char         one_byte[2];
4547   int          ii;
4548   int          tdst_len;
4549   request_rec* r;
4550   apr_size_t   z2h_input_len;
4551
4552   iphone = GET_IPHONE(pdoc);
4553   doc   = iphone->doc;
4554   r     = doc->r;
4555
4556   textval = qs_get_node_value(doc,child);
4557   if (strlen(textval) == 0) {
4558     return iphone->out;
4559   }
4560
4561   tmp = apr_palloc(r->pool, qs_get_node_size(doc,child)+1);
4562   memset(tmp, 0, qs_get_node_size(doc,child)+1);
4563
4564   tdst     = qs_alloc_zero_byte_string(doc->buf.pool);
4565   memset(one_byte, 0, sizeof(one_byte));
4566   tdst_len = 0;
4567
4568   for (ii=0; ii<qs_get_node_size(doc,child); ii++) {
4569     char* out;
4570     int rtn = s_iphone_search_emoji(iphone, &textval[ii], &out);
4571     if (rtn) {
4572       tdst = qs_out_apr_pstrcat(r, tdst, out, &tdst_len);
4573       ii+=(rtn - 1);
4574       continue;
4575     }
4576
4577     if (is_sjis_kanji(textval[ii])) {
4578       one_byte[0] = textval[ii+0];
4579       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
4580       one_byte[0] = textval[ii+1];
4581       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
4582       ii++;
4583     }
4584     else 
4585     if (iphone->pre_flag) {
4586       one_byte[0] = textval[ii+0];
4587       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
4588     }
4589     else
4590     if (iphone->textarea_flag) {
4591       one_byte[0] = textval[ii+0];
4592       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
4593     }
4594     else {
4595       if (textval[ii] != '\r' && textval[ii] != '\n') {
4596         one_byte[0] = textval[ii+0];
4597         tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
4598       }
4599     }
4600   }
4601   z2h_input_len = strlen(tdst);
4602   tdst = chxj_conv_z2h(r, tdst, &z2h_input_len, iphone->entryp);
4603
4604   W_V(tdst);
4605   return iphone->out;
4606 }
4607
4608
4609 /**
4610  * It is a handler who processes the BLOCKQUOTE tag.
4611  *
4612  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
4613  *                     destination is specified.
4614  * @param node   [i]   The BLOCKQUOTE tag node is specified.
4615  * @return The conversion result is returned.
4616  */
4617 static char *
4618 s_iphone_start_blockquote_tag(void *pdoc, Node *node)
4619 {
4620   iphone_t *iphone;
4621   Doc      *doc;
4622   Attr     *attr;
4623   char     *attr_style = NULL;
4624   char     *attr_color = NULL;
4625   char     *attr_size  = NULL;
4626   char     *css_clear  = NULL;
4627
4628   iphone  = GET_IPHONE(pdoc);
4629   doc     = iphone->doc;
4630   for (attr = qs_get_attr(doc,node);
4631        attr;
4632        attr = qs_get_next_attr(doc,attr)) {
4633     char *nm  = qs_get_attr_name(doc,attr);
4634     char *val = qs_get_attr_value(doc,attr);
4635     if (val && STRCASEEQ('s','S',"style", nm)) {
4636       attr_style = val;
4637     }
4638   }
4639   if (IS_CSS_ON(iphone->entryp)) {
4640     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
4641     if (style) {
4642       css_property_t *color_prop = chxj_css_get_property_value(doc, style, "color");
4643       css_property_t *font_size_prop = chxj_css_get_property_value(doc, style, "font-size");
4644       css_property_t *clear_prop           = chxj_css_get_property_value(doc, style, "clear");
4645       
4646       css_property_t *cur;
4647       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
4648         if (cur->value && *cur->value) {
4649           attr_color = apr_pstrdup(doc->pool, cur->value);
4650         }
4651       }
4652       for (cur = font_size_prop->next; cur != font_size_prop; cur = cur->next) {
4653         if (cur->value && *cur->value) {
4654           if (STRCASEEQ('x','X',"xx-small",cur->value)) {
4655             attr_size = apr_pstrdup(doc->pool, cur->value);
4656           }
4657           else if (STRCASEEQ('x','X',"x-small",cur->value)) {
4658             attr_size = apr_pstrdup(doc->pool, cur->value);
4659           }
4660           else if (STRCASEEQ('s','S',"small",cur->value)) {
4661             attr_size = apr_pstrdup(doc->pool, cur->value);
4662           }
4663           else if (STRCASEEQ('m','M',"medium",cur->value)) {
4664             attr_size = apr_pstrdup(doc->pool, cur->value);
4665           }
4666           else if (STRCASEEQ('l','L',"large",cur->value)) {
4667             attr_size = apr_pstrdup(doc->pool, cur->value);
4668           }
4669           else if (STRCASEEQ('x','X',"x-large",cur->value)) {
4670             attr_size = apr_pstrdup(doc->pool, cur->value);
4671           }
4672           else if (STRCASEEQ('x','X',"xx-large",cur->value)) {
4673             attr_size = apr_pstrdup(doc->pool, cur->value);
4674           }
4675         }
4676       }
4677       for (cur = clear_prop->next; cur != clear_prop; cur = cur->next) {
4678         css_clear = apr_pstrdup(doc->pool, cur->value);
4679       }
4680     }
4681   }
4682   W_L("<blockquote");
4683   if (attr_color || attr_size || css_clear) {
4684     W_L(" style=\"");
4685     if (attr_color) {
4686       attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
4687       W_L("color:");
4688       W_V(attr_color);
4689       W_L(";");
4690     }
4691     if (attr_size) {
4692       W_L("font-size:");
4693       W_V(attr_size);
4694       W_L(";");
4695     }
4696     if (css_clear){
4697       W_L("clear:");
4698       W_V(css_clear);
4699       W_L(";");
4700     }
4701     W_L("\"");
4702   }
4703   W_L(">");
4704   return iphone->out;
4705 }
4706
4707
4708 /**
4709  * It is a handler who processes the BLOCKQUOTE tag.
4710  *
4711  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
4712  *                     destination is specified.
4713  * @param node   [i]   The BLOCKQUOTE tag node is specified.
4714  * @return The conversion result is returned.
4715  */
4716 static char *
4717 s_iphone_end_blockquote_tag(void *pdoc, Node *UNUSED(child))
4718 {
4719   iphone_t *iphone = GET_IPHONE(pdoc);
4720   Doc     *doc   = iphone->doc;
4721   W_L("</blockquote>");
4722   if (IS_CSS_ON(iphone->entryp)) {
4723     chxj_css_pop_prop_list(iphone->css_prop_stack);
4724   }
4725   return iphone->out;
4726 }
4727
4728
4729 /**
4730  * It is a handler who processes the DIR tag.
4731  *
4732  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
4733  *                     destination is specified.
4734  * @param node   [i]   The DIR tag node is specified.
4735  * @return The conversion result is returned.
4736  */
4737 static char *
4738 s_iphone_start_dir_tag(void *pdoc, Node *node)
4739 {
4740   iphone_t *iphone      = GET_IPHONE(pdoc);
4741   Doc       *doc        = iphone->doc;
4742   Attr      *attr;
4743   char      *attr_style = NULL;
4744   char      *attr_color = NULL;
4745   char      *attr_type  = NULL;
4746   char      *attr_size  = NULL;
4747   for (attr = qs_get_attr(doc,node);
4748        attr;
4749        attr = qs_get_next_attr(doc,attr)) {
4750     char *name   = qs_get_attr_name(doc,attr);
4751     char *value  = qs_get_attr_value(doc,attr);
4752     if (STRCASEEQ('t','T',"type",name)) {
4753       if (value && (STRCASEEQ('d','D',"disc",value) || STRCASEEQ('c','C',"circle",value) || STRCASEEQ('s','S',"square",value))) {
4754         attr_type = value;
4755       }
4756     }
4757     else if (STRCASEEQ('s','S',"style", name) && value && *value) {
4758       attr_style = value;
4759     }
4760   }
4761   if (IS_CSS_ON(iphone->entryp)) {
4762     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
4763     if (style) {
4764       css_property_t *color_prop           = chxj_css_get_property_value(doc, style, "color");
4765       css_property_t *size_prop            = chxj_css_get_property_value(doc, style, "font-size");
4766       css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "list-style-type");
4767       css_property_t *cur;
4768       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
4769         if (cur->value && *cur->value) {
4770           attr_color = apr_pstrdup(doc->pool, cur->value);
4771         }
4772       }
4773       for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
4774         if (cur->value && *cur->value) {
4775           attr_type = apr_pstrdup(doc->pool, cur->value);
4776         }
4777       }
4778       for (cur = size_prop->next; cur != size_prop; cur = cur->next) {
4779         if (cur->value && *cur->value) {
4780           if (STRCASEEQ('x','X',"xx-small",cur->value)) {
4781             attr_size = apr_pstrdup(doc->pool, cur->value);
4782           }
4783           else if (STRCASEEQ('x','X',"x-small",cur->value)) {
4784             attr_size = apr_pstrdup(doc->pool, cur->value);
4785           }
4786           else if (STRCASEEQ('s','S',"small",cur->value)) {
4787             attr_size = apr_pstrdup(doc->pool, cur->value);
4788           }
4789           else if (STRCASEEQ('m','M',"medium",cur->value)) {
4790             attr_size = apr_pstrdup(doc->pool, cur->value);
4791           }
4792           else if (STRCASEEQ('l','L',"large",cur->value)) {
4793             attr_size = apr_pstrdup(doc->pool, cur->value);
4794           }
4795           else if (STRCASEEQ('x','X',"x-large",cur->value)) {
4796             attr_size = apr_pstrdup(doc->pool, cur->value);
4797           }
4798           else if (STRCASEEQ('x','X',"xx-large",cur->value)) {
4799             attr_size = apr_pstrdup(doc->pool, cur->value);
4800           }
4801         }
4802       }
4803     }
4804   }
4805   W_L("<dir");
4806   if (attr_type || attr_color || attr_size) {
4807     W_L(" style=\"");
4808     if (attr_type) {
4809       W_L("list-style-type:");
4810       W_V(attr_type);
4811       W_L(";");
4812     }
4813     if (attr_color) {
4814       attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
4815       W_L("color:");
4816       W_V(attr_color);
4817       W_L(";");
4818     }
4819     if (attr_size) {
4820       W_L("font-size:");
4821       W_V(attr_size);
4822       W_L(";");
4823     }
4824     W_L("\"");
4825   }
4826   W_L(">");
4827   return iphone->out;
4828 }
4829
4830
4831 /**
4832  * It is a handler who processes the DIR tag.
4833  *
4834  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
4835  *                     destination is specified.
4836  * @param node   [i]   The DIR tag node is specified.
4837  * @return The conversion result is returned.
4838  */
4839 static char *
4840 s_iphone_end_dir_tag(void *pdoc, Node *UNUSED(child))
4841 {
4842   iphone_t *iphone = GET_IPHONE(pdoc);
4843   Doc *doc = iphone->doc;
4844   W_L("</dir>");
4845   if (IS_CSS_ON(iphone->entryp)) {
4846     chxj_css_pop_prop_list(iphone->css_prop_stack);
4847   }
4848   return iphone->out;
4849 }
4850
4851
4852 /**
4853  * It is a handler who processes the DL tag.
4854  *
4855  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
4856  *                     destination is specified.
4857  * @param node   [i]   The DL tag node is specified.
4858  * @return The conversion result is returned.
4859  */
4860 static char *
4861 s_iphone_start_dl_tag(void *pdoc, Node *node)
4862 {
4863   iphone_t *iphone      = GET_IPHONE(pdoc);
4864   Doc       *doc        = iphone->doc;
4865   Attr      *attr;
4866   char      *attr_style = NULL;
4867   char      *attr_color = NULL;
4868   char      *attr_size  = NULL;
4869   char      *css_clear  = NULL;
4870   
4871   for (attr = qs_get_attr(doc,node);
4872        attr;
4873        attr = qs_get_next_attr(doc,attr)) {
4874     char *name   = qs_get_attr_name(doc,attr);
4875     char *value  = qs_get_attr_value(doc,attr);
4876     if (STRCASEEQ('s','S',"style", name) && value && *value) {
4877       attr_style = value;
4878     }
4879   }
4880   if (IS_CSS_ON(iphone->entryp)) {
4881     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
4882     if (style) {
4883       css_property_t *color_prop           = chxj_css_get_property_value(doc, style, "color");
4884       css_property_t *size_prop            = chxj_css_get_property_value(doc, style, "font-size");
4885       css_property_t *clear_prop           = chxj_css_get_property_value(doc, style, "clear");
4886       
4887       css_property_t *cur;
4888       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
4889         if (cur->value && *cur->value) {
4890           attr_color = apr_pstrdup(doc->pool, cur->value);
4891         }
4892       }
4893       for (cur = size_prop->next; cur != size_prop; cur = cur->next) {
4894         if (cur->value && *cur->value) {
4895           if (STRCASEEQ('x','X',"xx-small",cur->value)) {
4896             attr_size = apr_pstrdup(doc->pool, cur->value);
4897           }
4898           else if (STRCASEEQ('x','X',"x-small",cur->value)) {
4899             attr_size = apr_pstrdup(doc->pool, cur->value);
4900           }
4901           else if (STRCASEEQ('s','S',"small",cur->value)) {
4902             attr_size = apr_pstrdup(doc->pool, cur->value);
4903           }
4904           else if (STRCASEEQ('m','M',"medium",cur->value)) {
4905             attr_size = apr_pstrdup(doc->pool, cur->value);
4906           }
4907           else if (STRCASEEQ('l','L',"large",cur->value)) {
4908             attr_size = apr_pstrdup(doc->pool, cur->value);
4909           }
4910           else if (STRCASEEQ('x','X',"x-large",cur->value)) {
4911             attr_size = apr_pstrdup(doc->pool, cur->value);
4912           }
4913           else if (STRCASEEQ('x','X',"xx-large",cur->value)) {
4914             attr_size = apr_pstrdup(doc->pool, cur->value);
4915           }
4916         }
4917       }
4918       for (cur = clear_prop->next; cur != clear_prop; cur = cur->next) {
4919         css_clear = apr_pstrdup(doc->pool, cur->value);
4920       }
4921     }
4922   }
4923   W_L("<dl");
4924   if (attr_color || attr_size || css_clear) {
4925     W_L(" style=\"");
4926     if (attr_color) {
4927       attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
4928       W_L("color:");
4929       W_V(attr_color);
4930       W_L(";");
4931     }
4932     if (attr_size) {
4933       W_L("font-size:");
4934       W_V(attr_size);
4935       W_L(";");
4936     }
4937     if (css_clear){
4938       W_L("clear:");
4939       W_V(css_clear);
4940       W_L(";");
4941     }
4942     W_L("\"");
4943   }
4944   W_L(">");
4945   return iphone->out;
4946 }
4947
4948
4949 /**
4950  * It is a handler who processes the DL tag.
4951  *
4952  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
4953  *                     destination is specified.
4954  * @param node   [i]   The DL tag node is specified.
4955  * @return The conversion result is returned.
4956  */
4957 static char *
4958 s_iphone_end_dl_tag(void *pdoc, Node *UNUSED(child))
4959 {
4960   iphone_t *iphone = GET_IPHONE(pdoc);
4961   Doc *doc = iphone->doc;
4962   W_L("</dl>");
4963   if (IS_CSS_ON(iphone->entryp)) {
4964     chxj_css_pop_prop_list(iphone->css_prop_stack);
4965   }
4966   return iphone->out;
4967 }
4968
4969
4970 /**
4971  * It is a handler who processes the DT tag.
4972  *
4973  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
4974  *                     destination is specified.
4975  * @param node   [i]   The DT tag node is specified.
4976  * @return The conversion result is returned.
4977  */
4978 static char *
4979 s_iphone_start_dt_tag(void *pdoc, Node *node)
4980 {
4981   iphone_t *iphone      = GET_IPHONE(pdoc);
4982   Doc       *doc        = iphone->doc;
4983   Attr      *attr;
4984   char      *attr_style = NULL;
4985   char      *attr_color = NULL;
4986   char      *attr_size  = NULL;
4987   for (attr = qs_get_attr(doc,node);
4988        attr;
4989        attr = qs_get_next_attr(doc,attr)) {
4990     char *name   = qs_get_attr_name(doc,attr);
4991     char *value  = qs_get_attr_value(doc,attr);
4992     if (STRCASEEQ('s','S',"style", name) && value && *value) {
4993       attr_style = value;
4994     }
4995   }
4996   if (IS_CSS_ON(iphone->entryp)) {
4997     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
4998     if (style) {
4999       css_property_t *color_prop           = chxj_css_get_property_value(doc, style, "color");
5000       css_property_t *size_prop            = chxj_css_get_property_value(doc, style, "font-size");
5001       css_property_t *cur;
5002       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
5003         if (cur->value && *cur->value) {
5004           attr_color = apr_pstrdup(doc->pool, cur->value);
5005         }
5006       }
5007       for (cur = size_prop->next; cur != size_prop; cur = cur->next) {
5008         if (cur->value && *cur->value) {
5009           if (STRCASEEQ('x','X',"xx-small",cur->value)) {
5010             attr_size = apr_pstrdup(doc->pool, cur->value);
5011           }
5012           else if (STRCASEEQ('x','X',"x-small",cur->value)) {
5013             attr_size = apr_pstrdup(doc->pool, cur->value);
5014           }
5015           else if (STRCASEEQ('s','S',"small",cur->value)) {
5016             attr_size = apr_pstrdup(doc->pool, cur->value);
5017           }
5018           else if (STRCASEEQ('m','M',"medium",cur->value)) {
5019             attr_size = apr_pstrdup(doc->pool, cur->value);
5020           }
5021           else if (STRCASEEQ('l','L',"large",cur->value)) {
5022             attr_size = apr_pstrdup(doc->pool, cur->value);
5023           }
5024           else if (STRCASEEQ('x','X',"x-large",cur->value)) {
5025             attr_size = apr_pstrdup(doc->pool, cur->value);
5026           }
5027           else if (STRCASEEQ('x','X',"xx-large",cur->value)) {
5028             attr_size = apr_pstrdup(doc->pool, cur->value);
5029           }
5030         }
5031       }
5032     }
5033   }
5034   W_L("<dt");
5035   if (attr_color || attr_size) {
5036     W_L(" style=\"");
5037     if (attr_color) {
5038       attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
5039       W_L("color:");
5040       W_V(attr_color);
5041       W_L(";");
5042     }
5043     if (attr_size) {
5044       W_L("font-size:");
5045       W_V(attr_size);
5046       W_L(";");
5047     }
5048     W_L("\"");
5049   }
5050   W_L(">");
5051   return iphone->out;
5052 }
5053
5054
5055 /**
5056  * It is a handler who processes the DT tag.
5057  *
5058  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
5059  *                     destination is specified.
5060  * @param node   [i]   The DT tag node is specified.
5061  * @return The conversion result is returned.
5062  */
5063 static char *
5064 s_iphone_end_dt_tag(void *pdoc, Node *UNUSED(child))
5065 {
5066   iphone_t *iphone = GET_IPHONE(pdoc);
5067   Doc      *doc    = iphone->doc;
5068   W_L("</dt>");
5069   if (IS_CSS_ON(iphone->entryp)) {
5070     chxj_css_pop_prop_list(iphone->css_prop_stack);
5071   }
5072   return iphone->out;
5073 }
5074
5075
5076 /**
5077  * It is a handler who processes the DD tag.
5078  *
5079  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
5080  *                     destination is specified.
5081  * @param node   [i]   The DD tag node is specified.
5082  * @return The conversion result is returned.
5083  */
5084 static char *
5085 s_iphone_start_dd_tag(void *pdoc, Node *node)
5086 {
5087   iphone_t *iphone      = GET_IPHONE(pdoc);
5088   Doc       *doc        = iphone->doc;
5089   Attr      *attr;
5090   char      *attr_style = NULL;
5091   char      *attr_color = NULL;
5092   char      *attr_size  = NULL;
5093   for (attr = qs_get_attr(doc,node);
5094        attr;
5095        attr = qs_get_next_attr(doc,attr)) {
5096     char *name   = qs_get_attr_name(doc,attr);
5097     char *value  = qs_get_attr_value(doc,attr);
5098     if (STRCASEEQ('s','S',"style", name) && value && *value) {
5099       attr_style = value;
5100     }
5101   }
5102   if (IS_CSS_ON(iphone->entryp)) {
5103     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
5104     if (style) {
5105       css_property_t *color_prop           = chxj_css_get_property_value(doc, style, "color");
5106       css_property_t *size_prop            = chxj_css_get_property_value(doc, style, "font-size");
5107       css_property_t *cur;
5108       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
5109         if (cur->value && *cur->value) {
5110           attr_color = apr_pstrdup(doc->pool, cur->value);
5111         }
5112       }
5113       for (cur = size_prop->next; cur != size_prop; cur = cur->next) {
5114         if (cur->value && *cur->value) {
5115           if (STRCASEEQ('x','X',"xx-small",cur->value)) {
5116             attr_size = apr_pstrdup(doc->pool, cur->value);
5117           }
5118           else if (STRCASEEQ('x','X',"x-small",cur->value)) {
5119             attr_size = apr_pstrdup(doc->pool, cur->value);
5120           }
5121           else if (STRCASEEQ('s','S',"small",cur->value)) {
5122             attr_size = apr_pstrdup(doc->pool, cur->value);
5123           }
5124           else if (STRCASEEQ('m','M',"medium",cur->value)) {
5125             attr_size = apr_pstrdup(doc->pool, cur->value);
5126           }
5127           else if (STRCASEEQ('l','L',"large",cur->value)) {
5128             attr_size = apr_pstrdup(doc->pool, cur->value);
5129           }
5130           else if (STRCASEEQ('x','X',"x-large",cur->value)) {
5131             attr_size = apr_pstrdup(doc->pool, cur->value);
5132           }
5133           else if (STRCASEEQ('x','X',"xx-large",cur->value)) {
5134             attr_size = apr_pstrdup(doc->pool, cur->value);
5135           }
5136         }
5137       }
5138     }
5139   }
5140   W_L("<dd");
5141   if (attr_color || attr_size) {
5142     W_L(" style=\"");
5143     if (attr_color) {
5144       attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
5145       W_L("color:");
5146       W_V(attr_color);
5147       W_L(";");
5148     }
5149     if (attr_size) {
5150       W_L("font-size:");
5151       W_V(attr_size);
5152       W_L(";");
5153     }
5154     W_L("\"");
5155   }
5156   W_L(">");
5157   return iphone->out;
5158 }
5159
5160
5161 /**
5162  * It is a handler who processes the DD tag.
5163  *
5164  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
5165  *                     destination is specified.
5166  * @param node   [i]   The DD tag node is specified.
5167  * @return The conversion result is returned.
5168  */
5169 static char *
5170 s_iphone_end_dd_tag(void *pdoc, Node *UNUSED(child))
5171 {
5172   iphone_t *iphone = GET_IPHONE(pdoc);
5173   Doc      *doc = iphone->doc;
5174   W_L("</dd>");
5175   if (IS_CSS_ON(iphone->entryp)) {
5176     chxj_css_pop_prop_list(iphone->css_prop_stack);
5177   }
5178   return iphone->out;
5179 }
5180
5181
5182 /**
5183  * It is a handler who processes the H1 tag.
5184  *
5185  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
5186  *                     destination is specified.
5187  * @param node   [i]   The H1 tag node is specified.
5188  * @return The conversion result is returned.
5189  */
5190 static char *
5191 s_iphone_start_h1_tag(void *pdoc, Node *node)
5192 {
5193   iphone_t    *iphone;
5194   Doc         *doc;
5195   request_rec *r;
5196   Attr        *attr;
5197   char        *attr_style = NULL;
5198   char        *attr_align = NULL;
5199   char        *css_clear  = NULL;
5200
5201   iphone = GET_IPHONE(pdoc);
5202   doc    = iphone->doc;
5203   r      = doc->r;
5204
5205   for (attr = qs_get_attr(doc,node);
5206        attr;
5207        attr = qs_get_next_attr(doc,attr)) {
5208     char *name  = qs_get_attr_name(doc,attr);
5209     char *value = qs_get_attr_value(doc,attr);
5210     if (STRCASEEQ('a','A',"align", name)) {
5211       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
5212         attr_align = value;
5213       }
5214     }
5215     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
5216       attr_style = value;
5217     }
5218   }
5219   if (IS_CSS_ON(iphone->entryp)) {
5220     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
5221     if (style) {
5222       css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "text-align");
5223       css_property_t *clear_prop           = chxj_css_get_property_value(doc, style, "clear");
5224       css_property_t *cur;
5225       for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
5226         if (STRCASEEQ('l','L',"left", cur->value)) {
5227           attr_align = apr_pstrdup(doc->pool, "left");
5228         }
5229         else if (STRCASEEQ('c','C',"center",cur->value)) {
5230           attr_align = apr_pstrdup(doc->pool, "center");
5231         }
5232         else if (STRCASEEQ('r','R',"right",cur->value)) {
5233           attr_align = apr_pstrdup(doc->pool, "right");
5234         }
5235       }
5236       for (cur = clear_prop->next; cur != clear_prop; cur = cur->next) {
5237         if (STRCASEEQ('b','B',"both", cur->value)) {
5238           css_clear = apr_pstrdup(doc->pool, "both");
5239         }
5240         else if (STRCASEEQ('r','R',"right", cur->value)) {
5241           css_clear = apr_pstrdup(doc->pool, "right");
5242         }
5243         else if (STRCASEEQ('l','L',"left", cur->value)) {
5244           css_clear = apr_pstrdup(doc->pool, "left");
5245         }
5246       }
5247     }
5248   }
5249   W_L("<h1");
5250   if (attr_align || css_clear ) {
5251     W_L(" style=\"");
5252     if(attr_align){
5253       W_L("text-align:");
5254       W_V(attr_align);
5255       W_L(";");
5256     }
5257     if(css_clear){
5258       W_L("clear:");
5259       W_V(css_clear);
5260       W_L(";");
5261     }
5262     W_L("\"");
5263   }
5264   W_L(">");
5265
5266   return iphone->out;
5267 }
5268
5269
5270 /**
5271  * It is a handler who processes the H1 tag.
5272  *
5273  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
5274  *                     destination is specified.
5275  * @param node   [i]   The H1 tag node is specified.
5276  * @return The conversion result is returned.
5277  */
5278 static char *
5279 s_iphone_end_h1_tag(void *pdoc, Node *UNUSED(child)) 
5280 {
5281   iphone_t*    iphone;
5282   Doc*          doc;
5283   request_rec*  r;
5284
5285   iphone = GET_IPHONE(pdoc);
5286   doc     = iphone->doc;
5287   r       = doc->r;
5288   
5289   W_L("</h1>");
5290   if (IS_CSS_ON(iphone->entryp)) {
5291     chxj_css_pop_prop_list(iphone->css_prop_stack);
5292   }
5293
5294   return iphone->out;
5295 }
5296
5297
5298 /**
5299  * It is a handler who processes the H2 tag.
5300  *
5301  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
5302  *                     destination is specified.
5303  * @param node   [i]   The H1 tag node is specified.
5304  * @return The conversion result is returned.
5305  */
5306 static char *
5307 s_iphone_start_h2_tag(void *pdoc, Node *node)
5308 {
5309   iphone_t    *iphone;
5310   Doc         *doc;
5311   request_rec *r;
5312   Attr        *attr;
5313   char        *attr_style = NULL;
5314   char        *attr_align = NULL;
5315   char        *css_clear  = NULL;
5316
5317   iphone   = GET_IPHONE(pdoc);
5318   doc     = iphone->doc;
5319   r       = doc->r;
5320
5321   for (attr = qs_get_attr(doc,node);
5322        attr;
5323        attr = qs_get_next_attr(doc,attr)) {
5324     char *name  = qs_get_attr_name(doc,attr);
5325     char *value = qs_get_attr_value(doc,attr);
5326     if (STRCASEEQ('a','A',"align", name)) {
5327       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
5328         attr_align = value;
5329       }
5330     }
5331     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
5332       attr_style = value;
5333     }
5334   }
5335   if (IS_CSS_ON(iphone->entryp)) {
5336     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
5337     if (style) {
5338       css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "text-align");
5339       css_property_t *clear_prop           = chxj_css_get_property_value(doc, style, "clear");
5340       css_property_t *cur;
5341       for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
5342         if (STRCASEEQ('l','L',"left", cur->value)) {
5343           attr_align = apr_pstrdup(doc->pool, "left");
5344         }
5345         else if (STRCASEEQ('c','C',"center",cur->value)) {
5346           attr_align = apr_pstrdup(doc->pool, "center");
5347         }
5348         else if (STRCASEEQ('r','R',"right",cur->value)) {
5349           attr_align = apr_pstrdup(doc->pool, "right");
5350         }
5351       }
5352       for (cur = clear_prop->next; cur != clear_prop; cur = cur->next) {
5353         if (STRCASEEQ('b','B',"both", cur->value)) {
5354           css_clear = apr_pstrdup(doc->pool, "both");
5355         }
5356         else if (STRCASEEQ('r','R',"right", cur->value)) {
5357           css_clear = apr_pstrdup(doc->pool, "right");
5358         }
5359         else if (STRCASEEQ('l','L',"left", cur->value)) {
5360           css_clear = apr_pstrdup(doc->pool, "left");
5361         }
5362       }
5363     }
5364   }
5365   W_L("<h2");
5366   if (attr_align || css_clear ) {
5367     W_L(" style=\"");
5368     if(attr_align){
5369       W_L("text-align:");
5370       W_V(attr_align);
5371       W_L(";");
5372     }
5373     if(css_clear){
5374       W_L("clear:");
5375       W_V(css_clear);
5376       W_L(";");
5377     }
5378     W_L("\"");
5379   }
5380   W_L(">");
5381
5382   return iphone->out;
5383 }
5384
5385
5386 /**
5387  * It is a handler who processes the H2 tag.
5388  *
5389  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
5390  *                     destination is specified.
5391  * @param node   [i]   The H1 tag node is specified.
5392  * @return The conversion result is returned.
5393  */
5394 static char *
5395 s_iphone_end_h2_tag(void *pdoc, Node *UNUSED(child)) 
5396 {
5397   iphone_t*    iphone;
5398   Doc*          doc;
5399   request_rec*  r;
5400
5401   iphone = GET_IPHONE(pdoc);
5402   doc     = iphone->doc;
5403   r       = doc->r;
5404   
5405   W_L("</h2>");
5406   if (IS_CSS_ON(iphone->entryp)) {
5407     chxj_css_pop_prop_list(iphone->css_prop_stack);
5408   }
5409   return iphone->out;
5410 }
5411
5412
5413 /**
5414  * It is a handler who processes the H3 tag.
5415  *
5416  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
5417  *                     destination is specified.
5418  * @param node   [i]   The H1 tag node is specified.
5419  * @return The conversion result is returned.
5420  */
5421 static char *
5422 s_iphone_start_h3_tag(void *pdoc, Node *node)
5423 {
5424   iphone_t    *iphone;
5425   Doc         *doc;
5426   request_rec *r;
5427   Attr        *attr;
5428   char        *attr_style = NULL;
5429   char        *attr_align = NULL;
5430   char        *css_clear  = NULL;
5431
5432   iphone   = GET_IPHONE(pdoc);
5433   doc     = iphone->doc;
5434   r       = doc->r;
5435
5436   for (attr = qs_get_attr(doc,node);
5437        attr;
5438        attr = qs_get_next_attr(doc,attr)) {
5439     char *name  = qs_get_attr_name(doc,attr);
5440     char *value = qs_get_attr_value(doc,attr);
5441     if (STRCASEEQ('a','A',"align", name)) {
5442       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
5443         attr_align = value;
5444       }
5445     }
5446     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
5447       attr_style = value;
5448     }
5449   }
5450   if (IS_CSS_ON(iphone->entryp)) {
5451     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
5452     if (style) {
5453       css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "text-align");
5454       css_property_t *clear_prop           = chxj_css_get_property_value(doc, style, "clear");
5455       css_property_t *cur;
5456       for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
5457         if (STRCASEEQ('l','L',"left", cur->value)) {
5458           attr_align = apr_pstrdup(doc->pool, "left");
5459         }
5460         else if (STRCASEEQ('c','C',"center",cur->value)) {
5461           attr_align = apr_pstrdup(doc->pool, "center");
5462         }
5463         else if (STRCASEEQ('r','R',"right",cur->value)) {
5464           attr_align = apr_pstrdup(doc->pool, "right");
5465         }
5466       }
5467       for (cur = clear_prop->next; cur != clear_prop; cur = cur->next) {
5468         if (STRCASEEQ('b','B',"both", cur->value)) {
5469           css_clear = apr_pstrdup(doc->pool, "both");
5470         }
5471         else if (STRCASEEQ('r','R',"right", cur->value)) {
5472           css_clear = apr_pstrdup(doc->pool, "right");
5473         }
5474         else if (STRCASEEQ('l','L',"left", cur->value)) {
5475           css_clear = apr_pstrdup(doc->pool, "left");
5476         }
5477       }
5478     }
5479   }
5480   W_L("<h3");
5481   if (attr_align || css_clear ) {
5482     W_L(" style=\"");
5483     if(attr_align){
5484       W_L("text-align:");
5485       W_V(attr_align);
5486       W_L(";");
5487     }
5488     if(css_clear){
5489       W_L("clear:");
5490       W_V(css_clear);
5491       W_L(";");
5492     }
5493     W_L("\"");
5494   }
5495   W_L(">");
5496
5497   return iphone->out;
5498 }
5499
5500
5501 /**
5502  * It is a handler who processes the H3 tag.
5503  *
5504  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
5505  *                     destination is specified.
5506  * @param node   [i]   The H1 tag node is specified.
5507  * @return The conversion result is returned.
5508  */
5509 static char *
5510 s_iphone_end_h3_tag(void *pdoc, Node *UNUSED(child)) 
5511 {
5512   iphone_t*    iphone;
5513   Doc*          doc;
5514   request_rec*  r;
5515
5516   iphone = GET_IPHONE(pdoc);
5517   doc     = iphone->doc;
5518   r       = doc->r;
5519
5520   W_L("</h3>");
5521   if (IS_CSS_ON(iphone->entryp)) {
5522     chxj_css_pop_prop_list(iphone->css_prop_stack);
5523   }
5524   return iphone->out;
5525 }
5526
5527
5528 /**
5529  * It is a handler who processes the H4 tag.
5530  *
5531  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
5532  *                     destination is specified.
5533  * @param node   [i]   The H1 tag node is specified.
5534  * @return The conversion result is returned.
5535  */
5536 static char *
5537 s_iphone_start_h4_tag(void *pdoc, Node *node)
5538 {
5539   iphone_t    *iphone;
5540   Doc         *doc;
5541   request_rec *r;
5542   Attr        *attr;
5543   char        *attr_style = NULL;
5544   char        *attr_align = NULL;
5545   char        *css_clear  = NULL;
5546
5547   iphone   = GET_IPHONE(pdoc);
5548   doc     = iphone->doc;
5549   r       = doc->r;
5550
5551   for (attr = qs_get_attr(doc,node);
5552        attr;
5553        attr = qs_get_next_attr(doc,attr)) {
5554     char *name  = qs_get_attr_name(doc,attr);
5555     char *value = qs_get_attr_value(doc,attr);
5556     if (STRCASEEQ('a','A',"align", name)) {
5557       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
5558         attr_align = value;
5559       }
5560     }
5561     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
5562       attr_style = value;
5563     }
5564   }
5565   if (IS_CSS_ON(iphone->entryp)) {
5566     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
5567     if (style) {
5568       css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "text-align");
5569       css_property_t *clear_prop           = chxj_css_get_property_value(doc, style, "clear");
5570       css_property_t *cur;
5571       for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
5572         if (STRCASEEQ('l','L',"left", cur->value)) {
5573           attr_align = apr_pstrdup(doc->pool, "left");
5574         }
5575         else if (STRCASEEQ('c','C',"center",cur->value)) {
5576           attr_align = apr_pstrdup(doc->pool, "center");
5577         }
5578         else if (STRCASEEQ('r','R',"right",cur->value)) {
5579           attr_align = apr_pstrdup(doc->pool, "right");
5580         }
5581       }
5582       for (cur = clear_prop->next; cur != clear_prop; cur = cur->next) {
5583         if (STRCASEEQ('b','B',"both", cur->value)) {
5584           css_clear = apr_pstrdup(doc->pool, "both");
5585         }
5586         else if (STRCASEEQ('r','R',"right", cur->value)) {
5587           css_clear = apr_pstrdup(doc->pool, "right");
5588         }
5589         else if (STRCASEEQ('l','L',"left", cur->value)) {
5590           css_clear = apr_pstrdup(doc->pool, "left");
5591         }
5592       }
5593     }
5594   }
5595   W_L("<h4");
5596   if (attr_align || css_clear ) {
5597     W_L(" style=\"");
5598     if(attr_align){
5599       W_L("text-align:");
5600       W_V(attr_align);
5601       W_L(";");
5602     }
5603     if(css_clear){
5604       W_L("clear:");
5605       W_V(css_clear);
5606       W_L(";");
5607     }
5608     W_L("\"");
5609   }
5610   W_L(">");
5611
5612   return iphone->out;
5613 }
5614
5615
5616 /**
5617  * It is a handler who processes the H4 tag.
5618  *
5619  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
5620  *                     destination is specified.
5621  * @param node   [i]   The H1 tag node is specified.
5622  * @return The conversion result is returned.
5623  */
5624 static char *
5625 s_iphone_end_h4_tag(void *pdoc, Node *UNUSED(child)) 
5626 {
5627   iphone_t      *iphone;
5628   Doc           *doc;
5629   request_rec   *r;
5630
5631   iphone = GET_IPHONE(pdoc);
5632   doc     = iphone->doc;
5633   r       = doc->r;
5634   
5635   W_L("</h4>");
5636   if (IS_CSS_ON(iphone->entryp)) {
5637     chxj_css_pop_prop_list(iphone->css_prop_stack);
5638   }
5639
5640   return iphone->out;
5641 }
5642
5643
5644 /**
5645  * It is a handler who processes the H5 tag.
5646  *
5647  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
5648  *                     destination is specified.
5649  * @param node   [i]   The H1 tag node is specified.
5650  * @return The conversion result is returned.
5651  */
5652 static char *
5653 s_iphone_start_h5_tag(void *pdoc, Node *node)
5654 {
5655   iphone_t    *iphone;
5656   Doc         *doc;
5657   request_rec *r;
5658   Attr        *attr;
5659   char        *attr_style = NULL;
5660   char        *attr_align = NULL;
5661   char        *css_clear  = NULL;
5662
5663   iphone   = GET_IPHONE(pdoc);
5664   doc     = iphone->doc;
5665   r       = doc->r;
5666
5667   for (attr = qs_get_attr(doc,node);
5668        attr;
5669        attr = qs_get_next_attr(doc,attr)) {
5670     char *name  = qs_get_attr_name(doc,attr);
5671     char *value = qs_get_attr_value(doc,attr);
5672     if (STRCASEEQ('a','A',"align", name)) {
5673       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
5674         attr_align = value;
5675       }
5676     }
5677     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
5678       attr_style = value;
5679     }
5680   }
5681   if (IS_CSS_ON(iphone->entryp)) {
5682     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
5683     if (style) {
5684       css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "text-align");
5685       css_property_t *clear_prop           = chxj_css_get_property_value(doc, style, "clear");
5686       css_property_t *cur;
5687       for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
5688         if (STRCASEEQ('l','L',"left", cur->value)) {
5689           attr_align = apr_pstrdup(doc->pool, "left");
5690         }
5691         else if (STRCASEEQ('c','C',"center",cur->value)) {
5692           attr_align = apr_pstrdup(doc->pool, "center");
5693         }
5694         else if (STRCASEEQ('r','R',"right",cur->value)) {
5695           attr_align = apr_pstrdup(doc->pool, "right");
5696         }
5697       }
5698       for (cur = clear_prop->next; cur != clear_prop; cur = cur->next) {
5699         if (STRCASEEQ('b','B',"both", cur->value)) {
5700           css_clear = apr_pstrdup(doc->pool, "both");
5701         }
5702         else if (STRCASEEQ('r','R',"right", cur->value)) {
5703           css_clear = apr_pstrdup(doc->pool, "right");
5704         }
5705         else if (STRCASEEQ('l','L',"left", cur->value)) {
5706           css_clear = apr_pstrdup(doc->pool, "left");
5707         }
5708       }
5709     }
5710   }
5711   W_L("<h5");
5712   if (attr_align || css_clear ) {
5713     W_L(" style=\"");
5714     if(attr_align){
5715       W_L("text-align:");
5716       W_V(attr_align);
5717       W_L(";");
5718     }
5719     if(css_clear){
5720       W_L("clear:");
5721       W_V(css_clear);
5722       W_L(";");
5723     }
5724     W_L("\"");
5725   }
5726   W_L(">");
5727
5728   return iphone->out;
5729 }
5730
5731
5732 /**
5733  * It is a handler who processes the H5 tag.
5734  *
5735  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
5736  *                     destination is specified.
5737  * @param node   [i]   The H1 tag node is specified.
5738  * @return The conversion result is returned.
5739  */
5740 static char *
5741 s_iphone_end_h5_tag(void *pdoc, Node *UNUSED(child)) 
5742 {
5743   iphone_t    *iphone;
5744   Doc         *doc;
5745   request_rec *r;
5746
5747   iphone = GET_IPHONE(pdoc);
5748   doc     = iphone->doc;
5749   r       = doc->r;
5750   
5751   W_L("</h5>");
5752   if (IS_CSS_ON(iphone->entryp)) {
5753     chxj_css_pop_prop_list(iphone->css_prop_stack);
5754   }
5755
5756   return iphone->out;
5757 }
5758
5759
5760 /**
5761  * It is a handler who processes the H6 tag.
5762  *
5763  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
5764  *                     destination is specified.
5765  * @param node   [i]   The H1 tag node is specified.
5766  * @return The conversion result is returned.
5767  */
5768 static char *
5769 s_iphone_start_h6_tag(void *pdoc, Node *node)
5770 {
5771   iphone_t    *iphone;
5772   Doc         *doc;
5773   request_rec *r;
5774   Attr        *attr;
5775   char        *attr_style = NULL;
5776   char        *attr_align = NULL;
5777   char        *css_clear  = NULL;
5778
5779   iphone   = GET_IPHONE(pdoc);
5780   doc     = iphone->doc;
5781   r       = doc->r;
5782
5783   for (attr = qs_get_attr(doc,node);
5784        attr;
5785        attr = qs_get_next_attr(doc,attr)) {
5786     char *name  = qs_get_attr_name(doc,attr);
5787     char *value = qs_get_attr_value(doc,attr);
5788     if (STRCASEEQ('a','A',"align", name)) {
5789       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
5790         attr_align = value;
5791       }
5792     }
5793     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
5794       attr_style = value;
5795     }
5796   }
5797   if (IS_CSS_ON(iphone->entryp)) {
5798     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
5799     if (style) {
5800       css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "text-align");
5801       css_property_t *clear_prop           = chxj_css_get_property_value(doc, style, "clear");
5802       css_property_t *cur;
5803       for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
5804         if (STRCASEEQ('l','L',"left", cur->value)) {
5805           attr_align = apr_pstrdup(doc->pool, "left");
5806         }
5807         else if (STRCASEEQ('c','C',"center",cur->value)) {
5808           attr_align = apr_pstrdup(doc->pool, "center");
5809         }
5810         else if (STRCASEEQ('r','R',"right",cur->value)) {
5811           attr_align = apr_pstrdup(doc->pool, "right");
5812         }
5813       }
5814       for (cur = clear_prop->next; cur != clear_prop; cur = cur->next) {
5815         if (STRCASEEQ('b','B',"both", cur->value)) {
5816           css_clear = apr_pstrdup(doc->pool, "both");
5817         }
5818         else if (STRCASEEQ('r','R',"right", cur->value)) {
5819           css_clear = apr_pstrdup(doc->pool, "right");
5820         }
5821         else if (STRCASEEQ('l','L',"left", cur->value)) {
5822           css_clear = apr_pstrdup(doc->pool, "left");
5823         }
5824       }
5825     }
5826   }
5827   W_L("<h6");
5828   if (attr_align || css_clear ) {
5829     W_L(" style=\"");
5830     if(attr_align){
5831       W_L("text-align:");
5832       W_V(attr_align);
5833       W_L(";");
5834     }
5835     if(css_clear){
5836       W_L("clear:");
5837       W_V(css_clear);
5838       W_L(";");
5839     }
5840     W_L("\"");
5841   }
5842   W_L(">");
5843
5844   return iphone->out;
5845 }
5846
5847
5848 /**
5849  * It is a handler who processes the H6 tag.
5850  *
5851  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
5852  *                     destination is specified.
5853  * @param node   [i]   The H1 tag node is specified.
5854  * @return The conversion result is returned.
5855  */
5856 static char *
5857 s_iphone_end_h6_tag(void *pdoc, Node *UNUSED(child)) 
5858 {
5859   iphone_t    *iphone;
5860   Doc         *doc;
5861   request_rec *r;
5862
5863   iphone = GET_IPHONE(pdoc);
5864   doc     = iphone->doc;
5865   r       = doc->r;
5866   
5867   W_L("</h6>");
5868   if (IS_CSS_ON(iphone->entryp)) {
5869     chxj_css_pop_prop_list(iphone->css_prop_stack);
5870   }
5871
5872   return iphone->out;
5873 }
5874
5875
5876 /**
5877  * It is a handler who processes the MENU tag.
5878  *
5879  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
5880  *                     destination is specified.
5881  * @param node   [i]   The MENU tag node is specified.
5882  * @return The conversion result is returned.
5883  */
5884 static char *
5885 s_iphone_start_menu_tag(void *pdoc, Node *node)
5886 {
5887   iphone_t *iphone      = GET_IPHONE(pdoc);
5888   Doc       *doc        = iphone->doc;
5889   Attr      *attr;
5890   char      *attr_style = NULL;
5891   char      *attr_color = NULL;
5892   char      *attr_type  = NULL;
5893   char      *attr_size  = NULL;
5894   for (attr = qs_get_attr(doc,node);
5895        attr;
5896        attr = qs_get_next_attr(doc,attr)) {
5897     char *name   = qs_get_attr_name(doc,attr);
5898     char *value  = qs_get_attr_value(doc,attr);
5899     if (STRCASEEQ('t','T',"type",name)) {
5900       if (value && (STRCASEEQ('d','D',"disc",value) || STRCASEEQ('c','C',"circle",value) || STRCASEEQ('s','S',"square",value))) {
5901         attr_type = value;
5902       }
5903     }
5904     else if (STRCASEEQ('s','S',"style", name) && value && *value) {
5905       attr_style = value;
5906     }
5907   }
5908   if (IS_CSS_ON(iphone->entryp)) {
5909     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
5910     if (style) {
5911       css_property_t *color_prop           = chxj_css_get_property_value(doc, style, "color");
5912       css_property_t *size_prop            = chxj_css_get_property_value(doc, style, "font-size");
5913       css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "list-style-type");
5914       css_property_t *cur;
5915       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
5916         if (cur->value && *cur->value) {
5917           attr_color = apr_pstrdup(doc->pool, cur->value);
5918         }
5919       }
5920       for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
5921         if (cur->value && *cur->value) {
5922           attr_type = apr_pstrdup(doc->pool, cur->value);
5923         }
5924       }
5925       for (cur = size_prop->next; cur != size_prop; cur = cur->next) {
5926         if (cur->value && *cur->value) {
5927           if (STRCASEEQ('x','X',"xx-small",cur->value)) {
5928             attr_size = apr_pstrdup(doc->pool, cur->value);
5929           }
5930           else if (STRCASEEQ('x','X',"x-small",cur->value)) {
5931             attr_size = apr_pstrdup(doc->pool, cur->value);
5932           }
5933           else if (STRCASEEQ('s','S',"small",cur->value)) {
5934             attr_size = apr_pstrdup(doc->pool, cur->value);
5935           }
5936           else if (STRCASEEQ('m','M',"medium",cur->value)) {
5937             attr_size = apr_pstrdup(doc->pool, cur->value);
5938           }
5939           else if (STRCASEEQ('l','L',"large",cur->value)) {
5940             attr_size = apr_pstrdup(doc->pool, cur->value);
5941           }
5942           else if (STRCASEEQ('x','X',"x-large",cur->value)) {
5943             attr_size = apr_pstrdup(doc->pool, cur->value);
5944           }
5945           else if (STRCASEEQ('x','X',"xx-large",cur->value)) {
5946             attr_size = apr_pstrdup(doc->pool, cur->value);
5947           }
5948         }
5949       }
5950     }
5951   }
5952   W_L("<menu");
5953   if (attr_type || attr_color || attr_size) {
5954     W_L(" style=\"");
5955     if (attr_type) {
5956       W_L("list-style-type:");
5957       W_V(attr_type);
5958       W_L(";");
5959     }
5960     if (attr_color) {
5961       attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
5962       W_L("color:");
5963       W_V(attr_color);
5964       W_L(";");
5965     }
5966     if (attr_size) {
5967       W_L("font-size:");
5968       W_V(attr_size);
5969       W_L(";");
5970     }
5971     W_L("\"");
5972   }
5973   W_L(">");
5974   return iphone->out;
5975 }
5976
5977
5978 /**
5979  * It is a handler who processes the MENU tag.
5980  *
5981  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
5982  *                     destination is specified.
5983  * @param node   [i]   The MENU tag node is specified.
5984  * @return The conversion result is returned.
5985  */
5986 static char *
5987 s_iphone_end_menu_tag(void *pdoc, Node *UNUSED(child))
5988 {
5989   iphone_t *iphone = GET_IPHONE(pdoc);
5990   Doc *doc = iphone->doc;
5991   W_L("</menu>");
5992   if (IS_CSS_ON(iphone->entryp)) {
5993     chxj_css_pop_prop_list(iphone->css_prop_stack);
5994   }
5995   return iphone->out;
5996 }
5997
5998
5999 /**
6000  * It is a handler who processes the PLAINTEXT tag.
6001  *
6002  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
6003  *                     destination is specified.
6004  * @param node   [i]   The PLAINTEXT tag node is specified.
6005  * @return The conversion result is returned.
6006  */
6007 static char *
6008 s_iphone_start_plaintext_tag(void *pdoc, Node *node)
6009 {
6010   iphone_t *iphone;
6011   Doc *doc;
6012
6013   iphone = GET_IPHONE(pdoc);
6014   doc     = iphone->doc;
6015   W_L("<plaintext>");
6016   s_iphone_start_plaintext_tag_inner(pdoc,node);
6017   return iphone->out;
6018 }
6019
6020 static char *
6021 s_iphone_start_plaintext_tag_inner(void *pdoc, Node *node)
6022 {
6023   iphone_t *iphone;
6024   Doc *doc;
6025   Node *child;
6026   iphone = GET_IPHONE(pdoc);
6027   doc     = iphone->doc;
6028   for (child = qs_get_child_node(doc, node);
6029        child;
6030        child = qs_get_next_node(doc, child)) {
6031     W_V(child->otext);
6032     s_iphone_start_plaintext_tag_inner(pdoc, child);
6033   }
6034   return iphone->out;
6035 }
6036
6037
6038 /**
6039  * It is a handler who processes the PLAINTEXT tag.
6040  *
6041  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
6042  *                     destination is specified.
6043  * @param node   [i]   The PLAINTEXT tag node is specified.
6044  * @return The conversion result is returned.
6045  */
6046 static char *
6047 s_iphone_end_plaintext_tag(void *pdoc, Node *UNUSED(child))
6048 {
6049   iphone_t *iphone = GET_IPHONE(pdoc);
6050   return iphone->out;
6051 }
6052
6053
6054 /**
6055  * It is a handler who processes the BLINK tag.
6056  *
6057  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
6058  *                     destination is specified.
6059  * @param node   [i]   The BLINK tag node is specified.
6060  * @return The conversion result is returned.
6061  */
6062 static char *
6063 s_iphone_start_blink_tag(void *pdoc, Node *node)
6064 {
6065   iphone_t *iphone      = GET_IPHONE(pdoc);
6066   Doc       *doc        = iphone->doc;
6067   Attr      *attr;
6068   char      *attr_style = NULL;
6069   char      *attr_color = NULL;
6070   char      *attr_size  = NULL;
6071   for (attr = qs_get_attr(doc,node);
6072        attr;
6073        attr = qs_get_next_attr(doc,attr)) {
6074     char *name   = qs_get_attr_name(doc,attr);
6075     char *value  = qs_get_attr_value(doc,attr);
6076     if (STRCASEEQ('s','S',"style", name) && value && *value) {
6077       attr_style = value;
6078     }
6079   }
6080   if (IS_CSS_ON(iphone->entryp)) {
6081     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
6082     if (style) {
6083       css_property_t *color_prop           = chxj_css_get_property_value(doc, style, "color");
6084       css_property_t *size_prop            = chxj_css_get_property_value(doc, style, "font-size");
6085       css_property_t *cur;
6086       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
6087         if (cur->value && *cur->value) {
6088           attr_color = apr_pstrdup(doc->pool, cur->value);
6089         }
6090       }
6091       for (cur = size_prop->next; cur != size_prop; cur = cur->next) {
6092         if (cur->value && *cur->value) {
6093           if (STRCASEEQ('x','X',"xx-small",cur->value)) {
6094             attr_size = apr_pstrdup(doc->pool, cur->value);
6095           }
6096           else if (STRCASEEQ('x','X',"x-small",cur->value)) {
6097             attr_size = apr_pstrdup(doc->pool, cur->value);
6098           }
6099           else if (STRCASEEQ('s','S',"small",cur->value)) {
6100             attr_size = apr_pstrdup(doc->pool, cur->value);
6101           }
6102           else if (STRCASEEQ('m','M',"medium",cur->value)) {
6103             attr_size = apr_pstrdup(doc->pool, cur->value);
6104           }
6105           else if (STRCASEEQ('l','L',"large",cur->value)) {
6106             attr_size = apr_pstrdup(doc->pool, cur->value);
6107           }
6108           else if (STRCASEEQ('x','X',"x-large",cur->value)) {
6109             attr_size = apr_pstrdup(doc->pool, cur->value);
6110           }
6111           else if (STRCASEEQ('x','X',"xx-large",cur->value)) {
6112             attr_size = apr_pstrdup(doc->pool, cur->value);
6113           }
6114         }
6115       }
6116     }
6117   }
6118
6119   W_L("<span");
6120   W_L(" style=\"");
6121   W_L(STYLE_BLINK);
6122   if (iphone->blink_keyframe_out == 0) {
6123     iphone->style_data = apr_pstrcat(doc->pool, (iphone->style_data) ? iphone->style_data : "",
6124                                                 BLINK_KEYFRAME,
6125                                                 NULL);
6126     iphone->blink_keyframe_out = 1;
6127   }
6128   if (attr_color) {
6129     attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
6130     W_L("color:");
6131     W_V(attr_color);
6132     W_L(";");
6133   }
6134   if (attr_size) {
6135     W_L("font-size:");
6136     W_V(attr_size);
6137     W_L(";");
6138   }
6139   W_L("\"");
6140   W_L(">");
6141   
6142   return iphone->out;
6143 }
6144
6145
6146 /**
6147  * It is a handler who processes the BLINK tag.
6148  *
6149  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
6150  *                     destination is specified.
6151  * @param node   [i]   The BLINK tag node is specified.
6152  * @return The conversion result is returned.
6153  */
6154 static char *
6155 s_iphone_end_blink_tag(void *pdoc, Node *UNUSED(child))
6156 {
6157   iphone_t *iphone = GET_IPHONE(pdoc);
6158   Doc      *doc = iphone->doc;
6159   W_L("</span>");
6160   if (IS_CSS_ON(iphone->entryp)) {
6161     chxj_css_pop_prop_list(iphone->css_prop_stack);
6162   }
6163   return iphone->out;
6164 }
6165
6166
6167 /**
6168  * It is a handler who processes the MARQUEE tag.
6169  *
6170  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
6171  *                     destination is specified.
6172  * @param node   [i]   The MARQUEE tag node is specified.
6173  * @return The conversion result is returned.
6174  */
6175 static char *
6176 s_iphone_start_marquee_tag(void *pdoc, Node *node)
6177 {
6178   iphone_t *iphone = GET_IPHONE(pdoc);
6179   Doc       *doc = iphone->doc;
6180   Attr      *attr;
6181   char      *attr_style     = NULL;
6182   char      *attr_color     = NULL;
6183   char      *attr_size      = NULL;
6184   char      *attr_wap_marquee_loop  = NULL;
6185   char      *attr_wap_marquee_style = NULL;
6186   char      *attr_wap_marquee_dir   = NULL;
6187   char      *attr_wap_marquee_speed = NULL;
6188   char      *attr_bgcolor   = NULL;
6189   /*--------------------------------------------------------------------------*/
6190   /* Get Attributes                                                           */
6191   /*--------------------------------------------------------------------------*/
6192   for (attr = qs_get_attr(doc,node);
6193        attr;
6194        attr = qs_get_next_attr(doc,attr)) {
6195     char *name   = qs_get_attr_name(doc,attr);
6196     char *value  = qs_get_attr_value(doc,attr);
6197     if (STRCASEEQ('d','D',"direction", name)) {
6198       if (value) {
6199         if (STRCASEEQ('l','L',"left",value)) {
6200           attr_wap_marquee_dir = "rtl";
6201         }
6202         else if (STRCASEEQ('r','R',"right",value)) {
6203           attr_wap_marquee_dir = "ltr";
6204         }
6205       }
6206     }
6207     else if (STRCASEEQ('b','B',"behavior",name)) {
6208       if (value && *value) {
6209         attr_wap_marquee_style = value;
6210       }
6211     }
6212     else if (STRCASEEQ('l','L',"loop",name)) {
6213       if (value && *value) {
6214         if(strcmp(value,"0") == 0 || strcmp(value,"-1") == 0){
6215           attr_wap_marquee_loop = "infinite";
6216         }
6217         else{
6218           attr_wap_marquee_loop = value;
6219         }
6220       }
6221     }
6222     else if (STRCASEEQ('b','B',"bgcolor",name)) {
6223       if (value && *value) {
6224         attr_bgcolor = value;
6225       }
6226     }
6227     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
6228       attr_style = value;
6229     }
6230   }
6231   if (IS_CSS_ON(iphone->entryp)) {
6232     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
6233     if (style) {
6234       css_property_t *color_prop = chxj_css_get_property_value(doc, style, "color");
6235       css_property_t *size_prop  = chxj_css_get_property_value(doc, style, "font-size");
6236       css_property_t *bgcolor_prop  = chxj_css_get_property_value(doc, style, "background-color");
6237       css_property_t *wap_marquee_style_prop = chxj_css_get_property_value(doc, style, "-wap-marquee-style");
6238       css_property_t *wap_marquee_dir_prop   = chxj_css_get_property_value(doc, style, "-wap-marquee-dir");
6239       css_property_t *wap_marquee_loop_prop  = chxj_css_get_property_value(doc, style, "-wap-marquee-loop");
6240       css_property_t *wap_marquee_speed_prop = chxj_css_get_property_value(doc, style, "-wap-marquee-speed");
6241       css_property_t *cur;
6242       if (!attr_wap_marquee_style) {
6243         for (cur = wap_marquee_style_prop->next; cur != wap_marquee_style_prop; cur = cur->next) {
6244           if (STRCASEEQ('s','S',"scroll", cur->value) || STRCASEEQ('s','S',"slide",cur->value) || STRCASEEQ('a','A',"alternate",cur->value)) {
6245             attr_wap_marquee_style = apr_pstrdup(doc->pool, cur->value);
6246           }
6247         }
6248       }
6249       if (!attr_wap_marquee_dir) {
6250         for (cur = wap_marquee_dir_prop->next; cur != wap_marquee_dir_prop; cur = cur->next) {
6251           if (STRCASEEQ('l','L',"ltr",cur->value)) {
6252             attr_wap_marquee_dir = apr_pstrdup(doc->pool, cur->value);
6253           }
6254           else if (STRCASEEQ('r','R',"rtl",cur->value)) {
6255             attr_wap_marquee_dir = apr_pstrdup(doc->pool, cur->value);
6256           }
6257         }
6258       }
6259       if (!attr_wap_marquee_loop) {
6260         for (cur = wap_marquee_loop_prop->next; cur != wap_marquee_loop_prop; cur = cur->next) {
6261           if(strcmp(cur->value,"0") == 0 || strcmp(cur->value,"-1") == 0){
6262             attr_wap_marquee_loop = "infinite";
6263           }
6264           else{
6265             attr_wap_marquee_loop = apr_pstrdup(doc->pool, cur->value);
6266           }
6267         }
6268       }
6269       if (!attr_wap_marquee_speed) {
6270         for (cur = wap_marquee_speed_prop->next; cur != wap_marquee_speed_prop; cur = cur->next) {
6271           attr_wap_marquee_speed = apr_pstrdup(doc->pool, cur->value);
6272         }
6273       }
6274       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
6275         if (cur->value && *cur->value) {
6276           attr_color = apr_pstrdup(doc->pool, cur->value);
6277         }
6278       }
6279       for (cur = bgcolor_prop->next; cur != bgcolor_prop; cur = cur->next) {
6280         if (cur->value && *cur->value) {
6281           attr_bgcolor = apr_pstrdup(doc->pool, cur->value);
6282         }
6283       }
6284       for (cur = size_prop->next; cur != size_prop; cur = cur->next) {
6285         if (cur->value && *cur->value) {
6286           if ( STRCASEEQ('x','X',"xx-small",cur->value)
6287             || STRCASEEQ('x','X',"x-small", cur->value)
6288             || STRCASEEQ('s','S',"small",   cur->value)
6289             || STRCASEEQ('m','M',"medium",  cur->value)
6290             || STRCASEEQ('l','L',"large",   cur->value)
6291             || STRCASEEQ('x','X',"x-large", cur->value)
6292             || STRCASEEQ('x','X',"xx-large",cur->value)) {
6293             attr_size = apr_pstrdup(doc->pool, cur->value);
6294           }
6295         }
6296       }
6297     }
6298   }
6299
6300   W_L("<div style=\"");
6301   W_L("overflow:-webkit-marquee;");
6302   if (attr_wap_marquee_dir) {
6303     W_L("-webkit-marquee-direction:");
6304     if (STRCASEEQ('r','R',"rtl",attr_wap_marquee_dir)) {
6305       W_L("left");
6306     }
6307     else if (STRCASEEQ('l','L',"ltr",attr_wap_marquee_dir)) {
6308       W_L("right");
6309     }
6310     W_L(";");
6311   }
6312   if (attr_wap_marquee_style) {
6313     W_L("-webkit-marquee-style:");
6314     W_V(attr_wap_marquee_style);
6315     W_L(";");
6316   }
6317   if (attr_wap_marquee_loop) {
6318     W_L("-webkit-marquee-repetition:");
6319     W_V(attr_wap_marquee_loop);
6320     W_L(";");
6321   }
6322   if (attr_wap_marquee_speed) {
6323     W_L("-webkit-marquee-speed:");
6324     W_V(attr_wap_marquee_speed);
6325     W_L(";");
6326   }
6327   if (attr_bgcolor) {
6328     attr_bgcolor = chxj_css_rgb_func_to_value(doc->pool, attr_bgcolor);
6329     W_L("background-color:");
6330     W_V(attr_bgcolor);
6331     W_L(";");
6332   }
6333   if (attr_color) {
6334     attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
6335     W_L("color:");
6336     W_V(attr_color);
6337     W_L(";");
6338   }
6339   if (attr_size) {
6340     W_L("font-size:");
6341     W_V(attr_size);
6342     W_L(";");
6343   }
6344   W_L("\"");
6345   W_L(">");
6346
6347   return iphone->out;
6348 }
6349
6350
6351 /**
6352  * It is a handler who processes the MARQUEE tag.
6353  *
6354  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
6355  *                     destination is specified.
6356  * @param node   [i]   The MARQUEE tag node is specified.
6357  * @return The conversion result is returned.
6358  */
6359 static char *
6360 s_iphone_end_marquee_tag(void *pdoc, Node *UNUSED(node))
6361 {
6362   iphone_t *iphone = GET_IPHONE(pdoc);
6363   Doc      *doc     = iphone->doc;
6364   W_L("</div>");
6365   if (IS_CSS_ON(iphone->entryp)) {
6366     chxj_css_pop_prop_list(iphone->css_prop_stack);
6367   }
6368   return iphone->out;
6369 }
6370
6371
6372 /**
6373  * It is handler who processes the New Line Code.
6374  */
6375 static char *
6376 s_iphone_newline_mark(void *pdoc, Node *UNUSED(node))
6377 {
6378   iphone_t *iphone = GET_IPHONE(pdoc);
6379   if (iphone->start_html_flag) {
6380     Doc *doc = iphone->doc;
6381     W_NLCODE();
6382   }
6383   return iphone->out;
6384 }
6385
6386
6387 /**
6388  * It is a handler who processes the LINK tag.
6389  *
6390  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
6391  *                     destination is specified.
6392  * @param node   [i]   The LINK tag node is specified.
6393  * @return The conversion result is returned.
6394  */
6395 static char *
6396 s_iphone_link_tag(void *pdoc, Node *node)
6397 {
6398   iphone_t      *iphone;
6399   Doc           *doc;
6400   Attr          *attr;
6401   char          *rel  = NULL;
6402   char          *href = NULL;
6403   char          *type = NULL;
6404
6405   iphone = GET_IPHONE(pdoc);
6406   doc    = iphone->doc;
6407
6408   if (! IS_CSS_ON(iphone->entryp)) {
6409     return iphone->out;
6410   }
6411
6412   for (attr = qs_get_attr(doc,node);
6413        attr;
6414        attr = qs_get_next_attr(doc,attr)) {
6415     char *name  = qs_get_attr_name(doc,attr);
6416     char *value = qs_get_attr_value(doc,attr);
6417     if (STRCASEEQ('r','R',"rel", name)) {
6418       if (value && *value && STRCASEEQ('s','S',"stylesheet", value)) {
6419         rel = value;
6420       }
6421     }
6422     else if (STRCASEEQ('h','H',"href", name)) {
6423       if (value && *value) {
6424         href = value;
6425       }
6426     }
6427     else if (STRCASEEQ('t','T',"type", name)) {
6428       if (value && *value && STRCASEEQ('t','T',"text/css",value)) {
6429         type = value;
6430       }
6431     }
6432   }
6433
6434   if (rel && href && type) {
6435     DBG(doc->r,"REQ[%X] start load CSS. url:[%s]", TO_ADDR(doc->r),href);
6436     iphone->style = chxj_css_parse_from_uri(doc->r, doc->pool, iphone->style, href);
6437     DBG(doc->r,"REQ[%X] end load CSS. url:[%s]", TO_ADDR(doc->r),href);
6438   }
6439
6440   return iphone->out;
6441 }
6442
6443
6444 static css_prop_list_t *
6445 s_iphone_push_and_get_now_style(void *pdoc, Node *node, const char *style_attr_value)
6446 {
6447   iphone_t *iphone = GET_IPHONE(pdoc);
6448   Doc *doc = iphone->doc;
6449   css_prop_list_t *last_css = NULL;
6450   if (IS_CSS_ON(iphone->entryp)) {
6451     css_prop_list_t *dup_css;
6452     css_selector_t  *selector;
6453
6454     last_css = chxj_css_get_last_prop_list(iphone->css_prop_stack);
6455     dup_css  = chxj_dup_css_prop_list(doc, last_css);
6456     selector = chxj_css_find_selector(doc, iphone->style, node);
6457     if (selector) {
6458       chxj_css_prop_list_merge_property(doc, dup_css, selector);
6459     }
6460     chxj_css_push_prop_list(iphone->css_prop_stack, dup_css);
6461     last_css = chxj_css_get_last_prop_list(iphone->css_prop_stack);
6462
6463     if (style_attr_value) {
6464       css_stylesheet_t *ssheet = chxj_css_parse_style_attr(doc, NULL, apr_pstrdup(doc->pool, node->name), NULL, NULL, apr_pstrdup(doc->pool, style_attr_value));
6465       if (ssheet) {
6466         chxj_css_prop_list_merge_property(doc, last_css, ssheet->selector_head.next);
6467       }
6468     }
6469   }
6470   return last_css;
6471 }
6472
6473
6474 static css_prop_list_t *
6475 s_iphone_nopush_and_get_now_style(void *pdoc, Node *node, const char *style_attr_value)
6476 {
6477   iphone_t *iphone = GET_IPHONE(pdoc);
6478   Doc *doc = iphone->doc;
6479   css_prop_list_t *last_css = NULL;
6480   if (IS_CSS_ON(iphone->entryp)) {
6481     css_prop_list_t *dup_css;
6482     css_selector_t  *selector;
6483
6484     last_css = chxj_css_get_last_prop_list(iphone->css_prop_stack);
6485     dup_css  = chxj_dup_css_prop_list(doc, last_css);
6486     selector = chxj_css_find_selector(doc, iphone->style, node);
6487     if (selector) {
6488       chxj_css_prop_list_merge_property(doc, dup_css, selector);
6489     }
6490     last_css = dup_css;
6491
6492     if (style_attr_value) {
6493       css_stylesheet_t *ssheet = chxj_css_parse_style_attr(doc, NULL, apr_pstrdup(doc->pool, node->name), NULL, NULL, apr_pstrdup(doc->pool, style_attr_value));
6494       if (ssheet) {
6495         chxj_css_prop_list_merge_property(doc, last_css, ssheet->selector_head.next);
6496       }
6497     }
6498   }
6499   return last_css;
6500 }
6501
6502
6503 /**
6504  * It is a handler who processes the SPAN tag.
6505  *
6506  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
6507  *                     destination is specified.
6508  * @param node   [i]   The SPAN tag node is specified.
6509  * @return The conversion result is returned.
6510  */
6511 static char *
6512 s_iphone_start_span_tag(void *pdoc, Node *node)
6513 {
6514   iphone_t *iphone;
6515   Doc *doc;
6516   Attr *attr;
6517   char *attr_style = NULL;
6518   char *attr_color = NULL;
6519   char *attr_size = NULL;
6520   char *attr_align = NULL;
6521   char *attr_blink = NULL;
6522   char *attr_marquee = NULL;
6523   char *attr_marquee_dir = NULL;
6524   char *attr_marquee_style = NULL;
6525   char *attr_marquee_loop = NULL;
6526   char *attr_marquee_speed = NULL;
6527   char *css_bgcolor        = NULL;
6528
6529   iphone = GET_IPHONE(pdoc);
6530   doc     = iphone->doc;
6531
6532   for (attr = qs_get_attr(doc,node);
6533        attr;
6534        attr = qs_get_next_attr(doc,attr)) {
6535     char *nm  = qs_get_attr_name(doc,attr);
6536     char *val = qs_get_attr_value(doc,attr);
6537     if (val && STRCASEEQ('s','S',"style", nm)) {
6538       attr_style = val;
6539     }
6540   }
6541   if (IS_CSS_ON(iphone->entryp)) {
6542     css_prop_list_t *style = s_iphone_nopush_and_get_now_style(pdoc, node, attr_style);
6543     if (style) {
6544       css_property_t *color_prop = chxj_css_get_property_value(doc, style, "color");
6545       css_property_t *size_prop = chxj_css_get_property_value(doc, style, "font-size");
6546       css_property_t *text_align_prop = chxj_css_get_property_value(doc, style, "text-align");
6547       css_property_t *decoration_prop = chxj_css_get_property_value(doc, style, "text-decoration");
6548       css_property_t *display_prop = chxj_css_get_property_value(doc, style, "display");
6549       css_property_t *marquee_dir_prop = chxj_css_get_property_value(doc, style, "-wap-marquee-dir");
6550       css_property_t *marquee_style_prop = chxj_css_get_property_value(doc, style, "-wap-marquee-style");
6551       css_property_t *marquee_loop_prop = chxj_css_get_property_value(doc, style, "-wap-marquee-loop");
6552       css_property_t *marquee_speed_prop = chxj_css_get_property_value(doc, style, "-wap-marquee-speed");
6553       css_property_t *bgcolor_prop = chxj_css_get_property_value(doc, style, "background-color");
6554       
6555       css_property_t *cur;
6556       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
6557         attr_color = apr_pstrdup(doc->pool, cur->value);
6558       }
6559       for (cur = size_prop->next; cur != size_prop; cur = cur->next) {
6560         if (cur->value && *cur->value) {
6561           if ( STRCASEEQ('x','X',"xx-small",cur->value)
6562             || STRCASEEQ('x','X',"x-small", cur->value)
6563             || STRCASEEQ('s','S',"small",   cur->value)
6564             || STRCASEEQ('m','M',"medium",  cur->value)
6565             || STRCASEEQ('l','L',"large",   cur->value)
6566             || STRCASEEQ('x','X',"x-large", cur->value)
6567             || STRCASEEQ('x','X',"xx-large",cur->value)) {
6568             attr_size = apr_pstrdup(doc->pool, cur->value);
6569           }
6570         }
6571       }
6572       for (cur = decoration_prop->next; cur != decoration_prop; cur = cur->next) {
6573         if (cur->value && STRCASEEQ('b','B',"blink",cur->value)) {
6574           attr_blink = apr_pstrdup(doc->pool, cur->value);
6575         }
6576       }
6577       for (cur = display_prop->next; cur != display_prop; cur = cur->next) {
6578         if (cur->value && strcasecmp("-wap-marquee",cur->value) == 0) {
6579           attr_marquee = apr_pstrdup(doc->pool, cur->value);
6580         }
6581       }
6582       for (cur = marquee_dir_prop->next; cur != marquee_dir_prop; cur = cur->next) {
6583         if (cur->value && *cur->value) {
6584           if ( STRCASEEQ('l','L',"ltr",cur->value)
6585             || STRCASEEQ('r','R',"rtl",cur->value)) {
6586             attr_marquee_dir = apr_pstrdup(doc->pool, cur->value);
6587           }
6588         }
6589       }
6590       for (cur = marquee_style_prop->next; cur != marquee_style_prop; cur = cur->next) {
6591         if (cur->value && *cur->value) {
6592           if ( STRCASEEQ('s','S',"scroll",cur->value)
6593             || STRCASEEQ('s','S',"slide",cur->value)
6594             || STRCASEEQ('a','A',"alternate",cur->value)) {
6595             attr_marquee_style = apr_pstrdup(doc->pool, cur->value);
6596           }
6597         }
6598       }
6599       for (cur = marquee_loop_prop->next; cur != marquee_loop_prop; cur = cur->next) {
6600         if (cur->value && *cur->value) {
6601           if(strcmp(cur->value,"0") == 0 || strcmp(cur->value,"-1") == 0){
6602             attr_marquee_loop = "infinite";
6603           }
6604           else{
6605             attr_marquee_loop = apr_pstrdup(doc->pool, cur->value);
6606           }
6607         }
6608       }
6609       for (cur = marquee_speed_prop->next; cur != marquee_speed_prop; cur = cur->next) {
6610         if (cur->value && *cur->value) {
6611           attr_marquee_speed = apr_pstrdup(doc->pool, cur->value);
6612         }
6613       }
6614       for (cur = text_align_prop->next; cur != text_align_prop; cur = cur->next) {
6615         if (STRCASEEQ('l','L',"left", cur->value)) {
6616           attr_align = apr_pstrdup(doc->pool, "left");
6617         }
6618         else if (STRCASEEQ('c','C',"center",cur->value)) {
6619           attr_align = apr_pstrdup(doc->pool, "center");
6620         }
6621         else if (STRCASEEQ('r','R',"right",cur->value)) {
6622           attr_align = apr_pstrdup(doc->pool, "right");
6623         }
6624       }
6625       for (cur = bgcolor_prop->next; cur != bgcolor_prop; cur = cur->next) {
6626         if (cur->value && *cur->value) {
6627           css_bgcolor = apr_pstrdup(doc->pool, cur->value);
6628         }
6629       }
6630     }
6631   }
6632
6633   W_L("<div");
6634   if (attr_marquee) {
6635     W_L(" style=\"");
6636     W_L("overflow:-webkit-marquee;");
6637     if (attr_marquee_style) {
6638       W_L("-webkit-marquee-style:");
6639       W_V(attr_marquee_style);
6640       W_L(";");
6641     }
6642     if (attr_marquee_dir) {
6643       W_L("-webkit-marquee-direction:");
6644       if (STRCASEEQ('r','R',"rtl",attr_marquee_dir)) {
6645         W_L("left");
6646       }
6647       else if (STRCASEEQ('l','L',"ltr",attr_marquee_dir)) {
6648         W_L("right");
6649       }
6650       W_L(";");
6651     }
6652     if (attr_marquee_loop) {
6653       W_L("-webkit-marquee-repetition:");
6654       W_V(attr_marquee_loop);
6655       W_L(";");
6656     }
6657     if (attr_marquee_speed) {
6658       W_L("-webkit-marquee-speed:");
6659       W_V(attr_marquee_speed);
6660       W_L(";");
6661     }
6662     W_L("\"");
6663   }
6664   W_L(">");
6665   W_L("<span");
6666   if (attr_color || attr_size || attr_align || attr_blink || attr_marquee || css_bgcolor) {
6667     W_L(" style=\"");
6668     if (attr_color) {
6669       attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
6670       W_L("color:");
6671       W_V(attr_color);
6672       W_L(";");
6673     }
6674     if (attr_size) {
6675       W_L("font-size:");
6676       W_V(attr_size);
6677       W_L(";");
6678     }
6679     if (attr_align) {
6680       W_L("text-align:");
6681       W_V(attr_align);
6682       W_L(";");
6683     }
6684     if (attr_blink) {
6685       W_L(STYLE_BLINK);
6686       if (iphone->blink_keyframe_out == 0) {
6687         iphone->style_data = apr_pstrcat(doc->pool, (iphone->style_data) ? iphone->style_data : "",
6688                                                     BLINK_KEYFRAME,
6689                                                     NULL);
6690         iphone->blink_keyframe_out = 1;
6691       }
6692     }
6693     if(css_bgcolor){
6694       W_L("background-color:");
6695       W_V(css_bgcolor);
6696       W_L(";");
6697     }
6698     W_L("\"");
6699   }
6700   W_L(">");
6701   return iphone->out;
6702 }
6703
6704
6705 /**
6706  * It is a handler who processes the SPAN tag.
6707  *
6708  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
6709  *                     destination is specified.
6710  * @param node   [i]   The SPAN tag node is specified.
6711  * @return The conversion result is returned.
6712  */
6713 static char *
6714 s_iphone_end_span_tag(void *pdoc, Node *UNUSED(node))
6715 {
6716   iphone_t *iphone = GET_IPHONE(pdoc);
6717   Doc *doc = iphone->doc;
6718
6719   W_L("</span>");
6720   W_L("</div>");
6721   if (IS_CSS_ON(iphone->entryp)) {
6722     chxj_css_pop_prop_list(iphone->css_prop_stack);
6723   }
6724   return iphone->out;
6725 }
6726
6727
6728 /**
6729  * It is a handler who processes the STYLE tag.
6730  *
6731  * @param pdoc  [i/o] The pointer to the SoftBank XHTML structure at the output
6732  *                     destination is specified.
6733  * @param node   [i]   The STYLE tag node is specified.
6734  * @return The conversion result is returned.
6735  */
6736 static char *
6737 s_iphone_style_tag(void *pdoc, Node *node)
6738 {
6739   iphone_t     *iphone;
6740   Doc           *doc;
6741   Attr          *attr;
6742   char          *type = NULL;
6743   Node          *child   = NULL;
6744   char          *style;
6745
6746   iphone = GET_IPHONE(pdoc);
6747   doc     = iphone->doc;
6748
6749   if (! IS_CSS_ON(iphone->entryp)) {
6750     return iphone->out;
6751   }
6752
6753   for (attr = qs_get_attr(doc,node);
6754        attr;
6755        attr = qs_get_next_attr(doc,attr)) {
6756     char *name  = qs_get_attr_name(doc,attr);
6757     char *value = qs_get_attr_value(doc,attr);
6758     if (STRCASEEQ('t','T',"type", name)) {
6759       if (value && *value && STRCASEEQ('t','T',"text/css",value)) {
6760         type = value;
6761       }
6762     }
6763   }
6764   if (type) {
6765     style = "";
6766     for (child = qs_get_child_node(doc, node);
6767          child;
6768          child = qs_get_next_node(doc, child)) {
6769       char *name = qs_get_node_name(doc, child);
6770       if (STRCASEEQ('t','T',"text", name)) {
6771         char *value = qs_get_node_value(doc, child);
6772         if (value && *value) {
6773           style = apr_pstrcat(doc->r->pool, style, value, NULL);
6774         }
6775       }
6776     }
6777     if (strlen(style) > 0) {
6778       DBG(doc->r,"REQ[%X] start load CSS. buf:[%s]", TO_ADDR(doc->r),style);
6779       iphone->style = chxj_css_parse_style_value(doc, iphone->style, style);
6780       DBG(doc->r,"REQ[%X] end load CSS. value:[%s]", TO_ADDR(doc->r),style);
6781     }
6782   }
6783   return iphone->out;
6784 }
6785
6786
6787 static char *
6788 s_iphone_create_style_data(apr_pool_t *pool, const char *style_data)
6789 {
6790   if (! style_data) {
6791     return "";
6792   }
6793   return apr_pstrcat(pool, "<style type=\"text/css\"><![CDATA[",style_data, "]]></style>", NULL);
6794 }
6795
6796 /**
6797  * It is a handler who processes the OBJECT tag.
6798  *
6799  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
6800  *                     destination is specified.
6801  * @param node   [i]   The OBJECT tag node is specified.
6802  * @return The conversion result is returned.
6803  */
6804 static char *
6805 s_iphone_start_object_tag(void *pdoc, Node *node)
6806 {
6807   iphone_t *iphone = GET_IPHONE(pdoc);
6808   Doc *doc = iphone->doc;
6809   Attr *attr;
6810   
6811   char *attr_id            = NULL;
6812   char *attr_width         = NULL;
6813   char *attr_height        = NULL;
6814   char *attr_data          = NULL;
6815   char *attr_type          = NULL;
6816   char *attr_declare       = NULL;
6817   char *attr_classid       = NULL;
6818   char *attr_codebase      = NULL;
6819   
6820   /*--------------------------------------------------------------------------*/
6821   /* Get Attributes                                                           */
6822   /*--------------------------------------------------------------------------*/
6823   for (attr = qs_get_attr(doc,node);
6824        attr;
6825        attr = qs_get_next_attr(doc,attr)) {
6826     char *name   = qs_get_attr_name(doc,attr);
6827     char *value  = qs_get_attr_value(doc,attr);
6828     if (STRCASEEQ('i','I',"id",name)) {
6829       attr_id = apr_pstrdup(doc->pool, value);
6830     }
6831     else if (STRCASEEQ('w','W',"width",name)) {
6832       attr_width = apr_pstrdup(doc->pool, value);
6833     }
6834     else if (STRCASEEQ('h','H',"height",name)) {
6835       attr_height = apr_pstrdup(doc->pool, value);
6836     }
6837     else if (STRCASEEQ('d','D',"data",name)) {
6838       attr_data = apr_pstrdup(doc->pool, value);
6839     }
6840     else if  (STRCASEEQ('t','T',"type",name)) {
6841       attr_type = apr_pstrdup(doc->pool, value);
6842     }
6843     else if  (STRCASEEQ('d','D',"declare",name)) {
6844       attr_declare = apr_pstrdup(doc->pool, value);
6845     }
6846     else if (STRCASEEQ('c','C',"classid",name)) {
6847       attr_classid = apr_pstrdup(doc->pool, value);
6848     }
6849     else if (STRCASEEQ('c','C',"codebase",name)) {
6850       attr_codebase = apr_pstrdup(doc->pool, value);
6851     }
6852     
6853   }
6854   W_L("<object");
6855   
6856   if(attr_id){
6857     W_L(" id=\"");
6858     W_V(attr_id);
6859     W_L("\"");
6860   }
6861   if(attr_width){
6862     W_L(" width=\"");
6863     W_V(attr_width);
6864     W_L("\"");
6865   }
6866   if(attr_height){
6867     W_L(" height=\"");
6868     W_V(attr_height);
6869     W_L("\"");
6870   }
6871   if(attr_data){
6872     W_L(" data=\"");
6873     W_V(attr_data);
6874     W_L("\"");
6875   }
6876   if(attr_type){
6877     W_L(" type=\"");
6878     W_V(attr_type);
6879     W_L("\"");
6880   }
6881   if(attr_declare){
6882     W_L(" declare=\"declare\"");
6883   }
6884   if(attr_classid){
6885     W_L(" classid=\"");
6886     W_V(attr_classid);
6887     W_L("\"");
6888   }
6889   if(attr_codebase){
6890     W_L(" codebase=\"");
6891     W_V(attr_codebase);
6892     W_L("\"");
6893   }
6894   
6895   W_L(">");
6896   return iphone->out;
6897 }
6898 /**
6899  * It is a handler who processes the OBJECT tag.
6900  *
6901  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
6902  *                     destination is specified.
6903  * @param node   [i]   The OBJECT tag node is specified.
6904  * @return The conversion result is returned.
6905  */
6906 static char *
6907 s_iphone_end_object_tag(void *pdoc, Node *UNUSED(node))
6908 {
6909   iphone_t *iphone = GET_IPHONE(pdoc);
6910   Doc *doc = iphone->doc;
6911
6912   W_L("</object>");
6913   return iphone->out;
6914 }
6915 /**
6916  * It is a handler who processes the OBJECT tag.
6917  *
6918  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
6919  *                     destination is specified.
6920  * @param node   [i]   The OBJECT tag node is specified.
6921  * @return The conversion result is returned.
6922  */
6923 static char *
6924 s_iphone_start_param_tag(void *pdoc, Node *node)
6925 {
6926   iphone_t *iphone = GET_IPHONE(pdoc);
6927   Doc *doc = iphone->doc;
6928
6929   Attr *attr;
6930   char *attr_name          = NULL;
6931   char *attr_value         = NULL;
6932   char *attr_valuetype     = NULL;
6933   
6934   /*--------------------------------------------------------------------------*/
6935   /* Get Attributes                                                           */
6936   /*--------------------------------------------------------------------------*/
6937   for (attr = qs_get_attr(doc,node);
6938        attr;
6939        attr = qs_get_next_attr(doc,attr)) {
6940     char *name   = qs_get_attr_name(doc,attr);
6941     char *value  = qs_get_attr_value(doc,attr);
6942     if (STRCASEEQ('n','N',"name",name)) {
6943       attr_name = apr_pstrdup(doc->pool, value);
6944     }
6945     else if (STRCASEEQ('v','V',"value",name)) {
6946       attr_value = apr_pstrdup(doc->pool, value);
6947     }
6948     else if (STRCASEEQ('v','V',"valuetype",name)) {
6949       attr_valuetype = apr_pstrdup(doc->pool, value);
6950     }
6951   }
6952   W_L("<param");
6953   
6954   if(attr_name){
6955     W_L(" name=\"");
6956     W_V(attr_name);
6957     W_L("\"");
6958   }
6959   if(attr_value){
6960     W_L(" value=\"");
6961     W_V(attr_value);
6962     W_L("\"");
6963   }
6964   if(attr_valuetype){
6965     W_L(" valuetype=\"");
6966     W_V(attr_valuetype);
6967     W_L("\"");
6968   }
6969   W_L(" />");
6970   return iphone->out;
6971 }
6972 /**
6973  * It is a handler who processes the CAPTION tag.
6974  *
6975  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
6976  *                     destination is specified.
6977  * @param node   [i]   The CAPTION tag node is specified.
6978  * @return The conversion result is returned.
6979  */
6980 static char *
6981 s_iphone_start_caption_tag(void *pdoc, Node *node)
6982 {
6983   iphone_t    *iphone;
6984   Doc         *doc;
6985   request_rec *r;
6986   Attr        *attr;
6987   char        *attr_style = NULL;
6988   char        *attr_align = NULL;
6989
6990   iphone = GET_IPHONE(pdoc);
6991   doc    = iphone->doc;
6992   r      = doc->r;
6993
6994   for (attr = qs_get_attr(doc,node);
6995        attr;
6996        attr = qs_get_next_attr(doc,attr)) {
6997     char *name  = qs_get_attr_name(doc,attr);
6998     char *value = qs_get_attr_value(doc,attr);
6999     if (STRCASEEQ('a','A',"align", name)) {
7000       if (value && 
7001           (STRCASEEQ('l','L',"left",value) 
7002         || STRCASEEQ('r','R',"right",value) 
7003         || STRCASEEQ('t','T',"top",value)
7004         || STRCASEEQ('b','B',"bottom",value) 
7005         )) {
7006         attr_align = value;
7007       }
7008     }
7009     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
7010       attr_style = value;
7011     }
7012   }
7013   
7014   W_L("<caption");
7015   if(attr_align){
7016     W_L(" align=\"");
7017     W_V(attr_align);
7018     W_L("\"");
7019   }
7020   W_L(">");
7021
7022   return iphone->out;
7023 }
7024
7025
7026 /**
7027  * It is a handler who processes the CAPTION tag.
7028  *
7029  * @param pdoc  [i/o] The pointer to the IPHONE structure at the output
7030  *                     destination is specified.
7031  * @param node   [i]   The CAPTION tag node is specified.
7032  * @return The conversion result is returned.
7033  */
7034 static char *
7035 s_iphone_end_caption_tag(void *pdoc, Node *UNUSED(child)) 
7036 {
7037   iphone_t*    iphone = GET_IPHONE(pdoc);
7038   Doc*          doc   = iphone->doc;
7039   
7040   W_L("</caption>");
7041   
7042   return iphone->out;
7043 }
7044
7045
7046 /*
7047  * vim:ts=2 et
7048  */