OSDN Git Service

* Changed Feature
[modchxj/mod_chxj.git] / src / chxj_chtml20.c
index 1fdd8ff..ea1c82c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2008 Atsushi Konno All rights reserved.
+ * Copyright (C) 2005-2009 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_qr_code.h"
 #include "chxj_encoding.h"
 #include "chxj_buffered_write.h"
+#include "chxj_header_inf.h"
+#include "chxj_conv_z2h.h"
 
 
 #define GET_CHTML20(X) ((chtml20_t*)(X))
@@ -440,7 +442,7 @@ chxj_convert_chtml20(
   chtml20.entryp = entryp;
   chtml20.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.                           */
@@ -566,6 +568,66 @@ s_chtml20_search_emoji(chtml20_t *chtml20, char *txt, char **rslt)
   return 0;
 }
 
+char *
+chxj_chtml20_emoji_only_converter(request_rec *r, device_table *spec, const char *src, apr_size_t len)
+{
+  apr_size_t ii;
+  Doc __doc;
+  Doc *doc;
+  chtml20_t __chtml20;
+  chtml20_t *chtml20;
+  char one_byte[2];
+  char two_byte[3];
+  apr_pool_t *pool;
+
+  chtml20 = &__chtml20;
+  doc     = &__doc;
+
+  DBG(r, "REQ[%X] start chxj_chtml20_emoji_eonly_converter()", (unsigned int)(apr_size_t)r);
+  memset(doc,     0, sizeof(Doc));
+  memset(chtml20, 0, sizeof(chtml20_t));
+
+  doc->r        = r;
+  chtml20->doc  = doc;
+  chtml20->spec = spec;
+  chtml20->out  = qs_alloc_zero_byte_string(r->pool);
+  chtml20->conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
+  chtml20->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_chtml20_search_emoji(chtml20, (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);
+    }
+  }
+  chtml20->out = chxj_buffered_write_flush(chtml20->out, &doc->buf);
+
+  DBG(r, "REQ[%X] end chxj_chtml20_emoji_eonly_converter()", (unsigned int)(apr_size_t)r);
+  return chtml20->out;
+}
+
 
 /**
  * It is a handler who processes the HTML tag.
@@ -677,7 +739,9 @@ s_chtml20_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) {
           char *buf = apr_pstrdup(r->pool, value);
@@ -1069,7 +1133,9 @@ s_chtml20_start_a_tag(void *pdoc, Node *node)
         /* CHTML1.0                                                           */
         /*--------------------------------------------------------------------*/
         value = chxj_encoding_parameter(r, value);
-        value = chxj_add_cookie_parameter(r, value, chtml20->cookie);
+        if (! chxj_starts_with(value, "mailto:") && ! chxj_starts_with(value, "tel:")) {
+          value = chxj_add_cookie_parameter(r, value, chtml20->cookie);
+        }
         W_L(" href=\"");
         W_V(value);
         W_L("\"");
@@ -1491,15 +1557,20 @@ s_chtml20_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, chtml20->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) {
@@ -1606,6 +1677,9 @@ s_chtml20_start_input_tag(void *pdoc, Node *node)
     W_L("\"");
   }
   if (value && *value) {
+    apr_size_t value_len = strlen(value);
+    value = chxj_conv_z2h(r, value, &value_len, chtml20->entryp);
+
     W_L(" value=\"");
     W_V(chxj_add_slash_to_doublequote(doc->pool, value));
     W_L("\"");
@@ -2065,13 +2139,7 @@ s_chtml20_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, chtml20->cookie);
-        if (value) {
-          value = apr_psprintf(doc->buf.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("\"");
@@ -2079,13 +2147,7 @@ s_chtml20_start_img_tag(void *pdoc, Node *node)
         value = chxj_img_conv(r, spec, value);
         value = chxj_encoding_parameter(r, value);
         value = chxj_add_cookie_parameter(r, value, chtml20->cookie);
-        if (value) {
-          value = apr_psprintf(doc->buf.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("\"");
@@ -2356,7 +2418,7 @@ s_chtml20_start_option_tag(void *pdoc, Node *child)
     }
   }
 
-  if (value && *value) {
+  if (value) {
     W_L(" value=\"");
     W_V(value);
     W_L("\"");
@@ -3065,6 +3127,7 @@ s_chtml20_text_tag(void *pdoc, Node *child)
   char        one_byte[2];
   int         ii;
   int         tdst_len;
+  apr_size_t  z2h_input_len;
 
   chtml20 = GET_CHTML20(pdoc);
   doc     = chtml20->doc;
@@ -3113,6 +3176,9 @@ s_chtml20_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, chtml20->entryp);
+
   W_V(tdst);
   return chtml20->out;
 }