OSDN Git Service

* updated copyright.
[modchxj/mod_chxj.git] / src / chxj_chtml30.c
index 62db025..05f49b5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2008 Atsushi Konno All rights reserved.
+ * Copyright (C) 2005-2011 Atsushi Konno All rights reserved.
  * Copyright (C) 2005 QSDN,Inc. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,8 @@
 #include "chxj_img_conv.h"
 #include "chxj_qr_code.h"
 #include "chxj_encoding.h"
+#include "chxj_header_inf.h"
+#include "chxj_conv_z2h.h"
 
 #define GET_CHTML30(X) ((chtml30_t *)(X))
 #undef W_L
@@ -291,6 +293,11 @@ tag_handler chtml30_handler[] = {
     s_chtml30_chxjif_tag,
     NULL,
   },
+  /* tagCHXJRAW */
+  {
+    s_chtml30_chxjif_tag,
+    NULL,
+  },
   /* tagNOBR */
   {
     NULL,
@@ -419,7 +426,7 @@ chxj_convert_chtml30(
   chtml30_t chtml30;
   Doc       doc;
 
-  DBG(r, "start chxj_convert_chtml30()");
+  DBG(r, "REQ[%X] start %s()",TO_ADDR(r),__func__);
 
   /*--------------------------------------------------------------------------*/
   /* If qrcode xml                                                            */
@@ -427,11 +434,11 @@ chxj_convert_chtml30(
   *dstlen = srclen;
   dst = chxj_qr_code_blob_handler(r, src, (size_t*)dstlen);
   if (dst) {
-    DBG(r,"i found qrcode xml");
-    DBG(r, "end chxj_convert_chtml30()");
+    DBG(r,"REQ[%X] found qrcode xml", TO_ADDR(r));
+    DBG(r, "REQ[%X] end %s()",TO_ADDR(r),__func__);
     return dst;
   }
-  DBG(r,"not found qrcode xml");
+  DBG(r,"REQ[%X] not found qrcode xml", TO_ADDR(r));
 
   /*--------------------------------------------------------------------------*/
   /* The CHTML structure is initialized.                                      */
@@ -441,7 +448,7 @@ chxj_convert_chtml30(
   chtml30.entryp = entryp;
   chtml30.cookie = cookie;
 
-  chxj_set_content_type(r, "text/html; charset=Windows-31J");
+  chxj_set_content_type(r, chxj_header_inf_set_content_type(r, "text/html; charset=Windows-31J"));
 
   /*--------------------------------------------------------------------------*/
   /* The character string of the input is analyzed.                           */
@@ -483,7 +490,7 @@ chxj_convert_chtml30(
   chxj_dump_out("[src] CHTML -> CHTML3.0", dst, *dstlen);
 #endif
 
-  DBG(r, "end chxj_convert_chtml30()");
+  DBG(r, "REQ[%X] end %s()",TO_ADDR(r),__func__);
   return dst;
 }
 
@@ -538,14 +545,14 @@ s_chtml30_search_emoji(chtml30_t *chtml30, char *txt, char **rslt)
   r   = chtml30->doc->r;
 
   if (!spec) {
-    DBG(r,"spec is NULL");
+    DBG(r,"REQ[%X] spec is NULL", TO_ADDR(r));
   }
 
   for (ee = chtml30->conf->emoji;
        ee;
        ee = ee->next) {
     if (ee->imode == NULL) {
-      DBG(r, "emoji->imode is NULL");
+      DBG(r, "REQ[%X] emoji->imode is NULL", TO_ADDR(r));
       continue;
     }
 
@@ -569,6 +576,67 @@ s_chtml30_search_emoji(chtml30_t *chtml30, char *txt, char **rslt)
 }
 
 
+char *
+chxj_chtml30_emoji_only_converter(request_rec *r, device_table *spec, const char *src, apr_size_t len)
+{
+  apr_size_t ii;
+  Doc __doc;
+  Doc *doc;
+  chtml30_t __chtml30;
+  chtml30_t *chtml30;
+  char one_byte[2];
+  char two_byte[3];
+  apr_pool_t *pool;
+
+  chtml30 = &__chtml30;
+  doc     = &__doc;
+
+  DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
+  memset(doc,     0, sizeof(Doc));
+  memset(chtml30, 0, sizeof(chtml30_t));
+
+  doc->r        = r;
+  chtml30->doc  = doc;
+  chtml30->spec = spec;
+  chtml30->out  = qs_alloc_zero_byte_string(r->pool);
+  chtml30->conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
+  chtml30->doc->parse_mode = PARSE_MODE_CHTML;
+
+  apr_pool_create(&pool, r->pool);
+
+  chxj_buffered_write_init(pool, &doc->buf);
+
+  for (ii=0; ii<len; ii++) {
+    char *out;
+    int   rtn;
+
+    rtn = s_chtml30_search_emoji(chtml30, (char *)&src[ii], &out);
+    if (rtn) {
+      W_V(out);
+      ii+=(rtn - 1);
+      continue;
+    }
+
+    if (is_sjis_kanji(src[ii])) {
+      two_byte[0] = src[ii+0];
+      two_byte[1] = src[ii+1];
+      two_byte[2] = 0;
+      W_V(two_byte);
+      ii++;
+    }
+    else {
+      one_byte[0] = src[ii+0];
+      one_byte[1] = 0;
+      W_V(one_byte);
+    }
+  }
+  chtml30->out = chxj_buffered_write_flush(chtml30->out, &doc->buf);
+
+  DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
+  return chtml30->out;
+}
+
+
 /**
  * It is a handler who processes the HTML tag.
  *
@@ -670,7 +738,9 @@ s_chtml30_start_meta_tag(void *pdoc, Node *node)
         if (content_type_flag) {
           W_L(" ");
           W_V(name);
-          W_L("=\"text/html; charset=Windows-31J\"");
+          W_L("=\"");
+          W_V(chxj_header_inf_set_content_type(r, "text/html; charset=SHIFT_JIS"));
+          W_L("\"");
         }
         else
         if (refresh_flag) {
@@ -1003,7 +1073,7 @@ s_chtml30_start_a_tag(void *pdoc, Node *node)
       /* CHTML1.0                                                             */
       /*----------------------------------------------------------------------*/
       value = chxj_encoding_parameter(r, value);
-      if (! chxj_starts_with(value, "mailto:") && ! chxj_starts_with(value, "telto:")) {
+      if (! chxj_starts_with(value, "mailto:") && ! chxj_starts_with(value, "tel:")) {
         value = chxj_add_cookie_parameter(r, value, chtml30->cookie);
       }
       W_L(" href=\"");
@@ -1347,15 +1417,20 @@ s_chtml30_start_form_tag(void *pdoc, Node *node)
   W_L("<form");
   if (attr_action) {
     char *q;
+    char *new_query_string = NULL;
     q = strchr(attr_action, '?');
     if (q) {
-      new_hidden_tag = chxj_form_action_to_hidden_tag(r, doc->pool, attr_action, 0, post_flag);
-      if (new_hidden_tag) {
+      new_hidden_tag = chxj_form_action_to_hidden_tag(r, doc->pool, attr_action, 0, post_flag, &new_query_string, CHXJ_TRUE, CHXJ_FALSE, chtml30->entryp);
+      if (new_hidden_tag || new_query_string) {
         *q = 0;
       }
     }
     W_L(" action=\"");
     W_V(attr_action);
+    if (new_query_string) {
+      W_L("?");
+      W_V(new_query_string);
+    }
     W_L("\"");
   }
   if (attr_method) {
@@ -1461,6 +1536,11 @@ s_chtml30_start_input_tag(void *pdoc, Node *node)
     W_L("\"");
   }
   if (value && *value) {
+    if (type && (STRCASEEQ('s','S',"submit",type) || STRCASEEQ('r','R',"reset",type))) {
+      apr_size_t value_len = strlen(value);
+      value = chxj_conv_z2h(r, value, &value_len, chtml30->entryp);
+    }
+
     W_L(" value=\"");
     W_V(chxj_add_slash_to_doublequote(doc->pool, value));
     W_L("\"");
@@ -1703,28 +1783,15 @@ s_chtml30_start_img_tag(void *pdoc, Node *node)
 #ifdef IMG_NOT_CONVERT_FILENAME
       value = chxj_encoding_parameter(r, value);
       value = chxj_add_cookie_parameter(r, value, chtml30->cookie);
-      if (value) {
-        value = apr_psprintf(r->pool,
-                             "%s%c%s=true",
-                             value,
-                             (strchr(value, '?')) ? '&' : '?',
-                             CHXJ_COOKIE_NOUPDATE_PARAM);
-        W_L(" src=\"");
-        W_V(value);
-        W_L("\"");
-      }
-
+      value = chxj_add_cookie_no_update_parameter(r, value);
+      W_L(" src=\"");
+      W_V(value);
+      W_L("\"");
 #else
       value = chxj_img_conv(r,spec,value);
       value = chxj_encoding_parameter(r, value);
       value = chxj_add_cookie_parameter(r, value, chtml30->cookie);
-      if (value) {
-        value = apr_psprintf(r->pool,
-                             "%s%c%s=true",
-                             value,
-                             (strchr(value, '?')) ? '&' : '?',
-                             CHXJ_COOKIE_NOUPDATE_PARAM);
-      }
+      value = chxj_add_cookie_no_update_parameter(r, value);
       W_L(" src=\"");
       W_V(value);
       W_L("\"");
@@ -1944,7 +2011,7 @@ s_chtml30_start_option_tag(void *pdoc, Node *child)
       value = apr_pstrdup(doc->buf.pool, val);
     }
   }
-  if (value && *value) {
+  if (value) {
     W_L(" value=\"");
     W_V(value);
     W_L("\"");
@@ -2799,6 +2866,7 @@ s_chtml30_text_tag(void *pdoc, Node *child)
   char        one_byte[2];
   int         ii;
   int         tdst_len;
+  apr_size_t  z2h_input_len;
 
   chtml30 = GET_CHTML30(pdoc);
   doc     = chtml30->doc;
@@ -2845,6 +2913,9 @@ s_chtml30_text_tag(void *pdoc, Node *child)
       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
     }
   }
+  z2h_input_len = strlen(tdst);
+  tdst = chxj_conv_z2h(r, tdst, &z2h_input_len, chtml30->entryp);
+
   W_V(tdst);
   return chtml30->out;
 }