OSDN Git Service

Changed: Output encoding new feature device output_encoding attribute controls html...
authorcoltware <coltware@94a86f0a-4377-0410-8349-a3afc59ff858>
Tue, 27 Apr 2010 16:37:50 +0000 (16:37 +0000)
committerAtsushi Konno <konn@users.sourceforge.jp>
Wed, 29 Sep 2010 18:16:30 +0000 (03:16 +0900)
include/chxj_encoding.h
include/chxj_specified_device.h
src/chxj_cookie.c
src/chxj_encoding.c
src/chxj_ixhtml10.c
src/chxj_jxhtml.c
src/chxj_load_device_data.c
src/chxj_specified_device.c
src/chxj_xhtml_mobile_1_0.c
src/mod_chxj.c

index 4926ef8..43ef5d2 100644 (file)
@@ -32,7 +32,8 @@ extern char *chxj_encoding(
 extern char *chxj_rencoding(
   request_rec *r, 
   const char *src, 
-  apr_size_t *len);
+  apr_size_t *len,
+  const char *enc);
 
 extern char *chxj_encoding_parameter(
   request_rec *r, 
index 459e450..246e63e 100755 (executable)
@@ -86,6 +86,7 @@ struct device_table_t {
   /*--------------------------------------------------------------------------*/
   int                    color;
   char*                  emoji_type;
+  char*                  output_encoding;  /* Output encoding */
 };
 
 typedef struct device_table_list_t  device_table_list;
index f278c50..454f0c4 100644 (file)
@@ -1478,7 +1478,7 @@ chxj_cookie_only_mode(request_rec *r, const char *src, apr_size_t *len, cookie_t
   dst = s_convert_img_tag(r, dst, len, cookie);
   dst = s_convert_form_tag(r, dst, len, cookie);
 
-  result = chxj_rencoding(r, dst, len);
+  result = chxj_rencoding(r, dst, len, NULL);
   DBG(r, "REQ[%X] end chxj_cookie_only_mode()", TO_ADDR(r));
   return result;
 }
index 47f8976..c479a70 100644 (file)
@@ -241,7 +241,7 @@ chxj_convert_illegal_charactor_sequence(request_rec *r, chxjconvrule_entry  *ent
 
 
 char *
-chxj_rencoding(request_rec *r, const char *src, apr_size_t *len)
+chxj_rencoding(request_rec *r, const char *src, apr_size_t *len,const char *enc)
 {
   char                *obuf;
   char                *ibuf;
@@ -298,11 +298,17 @@ chxj_rencoding(request_rec *r, const char *src, apr_size_t *len)
     DBG(r,"REQ[%X] end   chxj_rencoding()", (unsigned int)(apr_size_t)r);
     return ibuf;
   }
-  DBG(r,"encode convert [%s] -> [%s]", "CP932", entryp->encoding);
-
+  char *from_enc = enc;
+  if (!enc){
+    from_enc = "CP932";
+  }
+  if (strcasecmp(enc,"Shift_JIS") == 0){
+    from_enc = "CP932";
+  }
+  DBG(r,"encode convert [%s] -> [%s]", from_enc, entryp->encoding);
   memset(obuf, 0, olen);
 
-  cd = iconv_open(entryp->encoding, "CP932");
+  cd = iconv_open(entryp->encoding, from_enc);
   if (cd == (iconv_t)-1) {
     if (EINVAL == errno) {
       ERR(r, "The conversion from %s to %s is not supported by the implementation.", "CP932", entryp->encoding);
index 061df8f..13eac0c 100755 (executable)
@@ -498,6 +498,9 @@ chxj_convert_ixhtml10(
   ixhtml10.entryp = entryp;
   ixhtml10.cookie = cookie;
 
+  if (strcasecmp(spec->output_encoding,"UTF-8") == 0 ){
+    apr_table_setn(r->headers_out,HTTP_X_CHXJ_SET_CONTENT_TYPE,"application/xhtml+xml; charset=UTF-8");
+  }
   chxj_set_content_type(r, chxj_header_inf_set_content_type(r, "application/xhtml+xml; charset=Shift_JIS"));
 
   /*--------------------------------------------------------------------------*/
@@ -670,7 +673,9 @@ s_ixhtml10_start_html_tag(void *pdoc, Node *UNUSED(node))
   r      = doc->r;
   DBG(r, "REQ[%X] start s_ixhtml10_start_html_tag()", (unsigned int)(apr_size_t)r);
 
-  W_L("<?xml version=\"1.0\" encoding=\"Shift_JIS\" ?>");
+  W_L("<?xml version=\"1.0\" encoding=\"");
+  W_V(ixhtml10->spec->output_encoding);
+  W_L("\" ?>");
   W_NLCODE();
   W_L("<!DOCTYPE html PUBLIC \"-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/2.0) 1.0//EN\" \"i-xhtml_4ja_10.dtd\">");
   W_NLCODE();
index a280e11..7d5fdbd 100755 (executable)
@@ -493,7 +493,9 @@ chxj_convert_jxhtml(
 
   jxhtml.entryp = entryp;
   jxhtml.cookie = cookie;
-
+  if (strcasecmp(spec->output_encoding,"UTF-8") == 0 ){
+    apr_table_setn(r->headers_out,HTTP_X_CHXJ_SET_CONTENT_TYPE,"application/xhtml+xml; charset=UTF-8");
+  }
   chxj_set_content_type(r, chxj_header_inf_set_content_type(r, "application/xhtml+xml; charset=Windows-31J"));
 
   /*--------------------------------------------------------------------------*/
@@ -720,7 +722,9 @@ s_jxhtml_start_html_tag(void *pdoc, Node *UNUSED(node))
   r      = doc->r;
   DBG(r, "REQ[%X] start s_jxhtml_start_html_tag()", TO_ADDR(r));
 
-  W_L("<?xml version=\"1.0\" encoding=\"Shift_JIS\" ?>");
+  W_L("<?xml version=\"1.0\" encoding=\"");
+  W_V(jxhtml->spec->output_encoding);
+  W_L("\" ?>");
   W_NLCODE();
   W_L("<!DOCTYPE html PUBLIC \"-//J-PHONE//DTD XHTML Basic 1.0 Plus//EN\" \"xhtml-basic10-plus.dtd\">");
   W_NLCODE();
index 980d43d..5a7d42b 100755 (executable)
@@ -149,6 +149,7 @@ s_set_device_data(Doc *doc, apr_pool_t *p, device_table_list *dtl, Node *node)
   dt->color          = 256;
   dt->dpi_width      = 96;
   dt->dpi_heigh      = 96;
+  dt->output_encoding = "Shift_JIS";
 
   for (child = qs_get_child_node(doc,node); 
        child ;
@@ -452,6 +453,15 @@ s_set_device_data(Doc *doc, apr_pool_t *p, device_table_list *dtl, Node *node)
           dt->emoji_type = apr_pstrdup(p, qs_get_node_value(doc, ch));
       }
       break;
+    case 'o':
+    case 'O':
+      if (strcasecmp(name, "output_encoding") == 0) {
+        Node *ch = qs_get_child_node(doc, child);
+        if (ch && strcasecmp(qs_get_node_name(doc,ch), "text") == 0){
+          dt->output_encoding = apr_pstrdup(p, qs_get_node_value(doc, ch));
+        }
+      }
+      break;
     default:
       break;
     }
index de332af..4adb685 100755 (executable)
@@ -57,6 +57,7 @@ static device_table  UNKNOWN_DEVICE      = {
   /*--------------------------------------------------------------------------*/
   .color = 15680000,
   .emoji_type = NULL,
+  .output_encoding = "Shift_JIS",
 };
 
 int
@@ -335,6 +336,9 @@ chxj_specified_device_from_tsv(request_rec *r,device_table *spec,const char *use
           spec->html_spec_type = CHXJ_SPEC_Jxhtml;
         }
       }
+      else if (STRCASEEQ('o','O',"output_encoding",k)){
+          spec->output_encoding = apr_pstrdup(r->pool,val);
+      }
     }
   }
   
index d8cafec..4fb8a97 100755 (executable)
@@ -486,6 +486,9 @@ chxj_convert_xhtml_mobile_1_0(
   xhtml.entryp = entryp;
   xhtml.cookie = cookie;
 
+  if (strcasecmp(spec->output_encoding,"UTF-8") == 0 ){
+    apr_table_setn(r->headers_out,HTTP_X_CHXJ_SET_CONTENT_TYPE,"text/html; charset=UTF-8");
+  }
   chxj_set_content_type(r, chxj_header_inf_set_content_type(r, "text/html; charset=Windows-31J"));
 
   /*--------------------------------------------------------------------------*/
@@ -774,7 +777,9 @@ s_xhtml_1_0_start_html_tag(void *pdoc, Node *UNUSED(node))
   /*--------------------------------------------------------------------------*/
   /* Add XML Declare                                                          */
   /*--------------------------------------------------------------------------*/
-  W_L("<?xml version=\"1.0\" encoding=\"Shift_JIS\"?>");
+  W_L("<?xml version=\"1.0\" encoding=\"");
+  W_V(xhtml->spec->output_encoding);
+  W_L("\"?>");
   W_NLCODE();
   /*--------------------------------------------------------------------------*/
   /* Add DocType                                                              */
index b79cdde..1d07aaf 100755 (executable)
@@ -420,6 +420,7 @@ chxj_convert(request_rec *r, const char **src, apr_size_t *len, device_table *sp
   }
 
   if (!r->header_only) {
+
     if ((entryp->action & CONVRULE_COOKIE_ONLY_BIT) && cookie) {
       dst = chxj_cookie_only_mode(r, *src, (apr_size_t *)len, cookie);
     }
@@ -474,6 +475,13 @@ chxj_convert(request_rec *r, const char **src, apr_size_t *len, device_table *sp
       }
     }
   }
+  if (*len > 0){
+    if (strcasecmp(spec->output_encoding,"UTF-8") == 0){
+      dst = chxj_iconv(r,r->pool,dst,len,"CP932","UTF-8");
+    }
+  }
+
+
   ap_set_content_length(r, *len);
 
   if (*len == 0) {
@@ -486,6 +494,7 @@ chxj_convert(request_rec *r, const char **src, apr_size_t *len, device_table *sp
   }
 
 
+
   DBG(r, "REQ[%X] end of chxj_convert()", (unsigned int)(apr_size_t)r);
 
   return dst;
@@ -616,7 +625,7 @@ chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp, device_tabl
           dlen   = strlen(value);
           DBG(r, "************ before encoding[%s]", value);
   
-          dvalue = chxj_rencoding(r, value, &dlen);
+          dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
           dvalue = chxj_url_encode(r->pool, dvalue);
   
           DBG(r, "************ after encoding[%s]", dvalue);
@@ -628,7 +637,7 @@ chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp, device_tabl
         if (name && *name != 0) {
           name = chxj_url_decode(r->pool, name);
           dlen = strlen(name);
-          dname = chxj_rencoding(r, name, &dlen);
+          dname = chxj_rencoding(r, name, &dlen,spec->output_encoding);
           dname = chxj_url_encode(r->pool, dname);
         }
         else {
@@ -793,7 +802,7 @@ chxj_input_convert(
         if (value && *value != 0) {
           value = chxj_url_decode(pool, value);
           dlen   = strlen(value);
-          dvalue = chxj_rencoding(r, value, &dlen);
+          dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
           dvalue = chxj_url_encode(pool, dvalue);
         }
         else {
@@ -803,7 +812,7 @@ chxj_input_convert(
         if (name && *name != 0) {
           name = chxj_url_decode(pool, name);
           dlen = strlen(name);
-          dname = chxj_rencoding(r, name, &dlen);
+          dname = chxj_rencoding(r, name, &dlen,spec->output_encoding);
           dname = chxj_url_encode(pool, dname);
         }
         else {
@@ -836,7 +845,7 @@ chxj_input_convert(
 
         dlen   = strlen(value);
         value = chxj_url_decode(pool, value);
-        dvalue = chxj_rencoding(r, value, &dlen);
+        dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
         dvalue = chxj_url_encode(pool,dvalue);
         result = apr_pstrcat(pool, result, &name[8], "=", dvalue, NULL);
 
@@ -880,7 +889,7 @@ chxj_input_convert(
       }
       if (dlen) {
         value = chxj_url_decode(pool, value);
-        dvalue = chxj_rencoding(r, value, &dlen);
+        dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
         dvalue = chxj_url_encode(pool,dvalue);
         if (r->args && strlen(r->args) > 0) {
           r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX)-1], "=", dvalue, NULL);
@@ -898,7 +907,7 @@ chxj_input_convert(
       dlen   = strlen(value);
       if (dlen && value) {
         value = chxj_url_decode(pool, value);
-        dvalue = chxj_rencoding(r, value, &dlen);
+        dvalue = chxj_rencoding(r, value, &dlen,spec->output_encoding);
         dvalue = chxj_url_encode(pool,dvalue);
         if (r->args && strlen(r->args) > 0) {
           r->args = apr_pstrcat(pool, r->args, "&", &name[sizeof(CHXJ_QUERY_STRING_PARAM_PREFIX_ENC)-1], "=", dvalue, NULL);