OSDN Git Service

* Fixed bug.
authorkonn <konn@1a406e8e-add9-4483-a2c8-d8cac5b7c224>
Thu, 3 Jul 2008 13:14:19 +0000 (13:14 +0000)
committerkonn <konn@1a406e8e-add9-4483-a2c8-d8cac5b7c224>
Thu, 3 Jul 2008 13:14:19 +0000 (13:14 +0000)
    - BUG #12945

git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/modchxj/mod_chxj/branches/RELEASE_0_12_0@2785 1a406e8e-add9-4483-a2c8-d8cac5b7c224

Makefile.in
src/chxj_cookie.c
src/chxj_encoding.c
src/mod_chxj.c

index 4539e22..a18fc68 100644 (file)
@@ -37,7 +37,7 @@ DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
        $(srcdir)/Makefile.in $(top_srcdir)/configure \
        $(top_srcdir)/include/config.h.in AUTHORS COPYING ChangeLog \
        INSTALL NEWS TODO compile config.guess config.sub depcomp \
-       install-sh ltmain.sh missing
+       install-sh ltmain.sh missing ylwrap
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/configure.ac
 am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
index 9319221..ad337ef 100644 (file)
 #endif
 #include "chxj_dbm.h"
 
+#define DUMP_HEADERS(X) do { \
+  int __ii; \
+  apr_array_header_t  *__headers = (apr_array_header_t*)apr_table_elts((X)); \
+  apr_table_entry_t   *__hentryp = (apr_table_entry_t*)__headers->elts; \
+  for (__ii=0; __ii<__headers->nelts; __ii++) { \
+    DBG(r, "key:[%s] val:[%s]", __hentryp[__ii].key, __hentryp[__ii].val); \
+  } \
+} while (0) 
+
+
 
 static char* s_get_hostname_from_url(request_rec* r, char* value);
 static char* s_cut_until_end_hostname(request_rec*, char* value);
@@ -112,11 +122,14 @@ chxj_save_cookie(request_rec *r)
   char                *refer_string;
   apr_uri_t           parsed_uri;
   int                 has_refer;
+  apr_pool_t          *pool;
 
 
   DBG(r, "start chxj_save_cookie()");
 
-  cookie = (cookie_t*)apr_palloc(r->pool, sizeof(cookie_t));
+  apr_pool_create(&pool, r->pool);
+
+  cookie = (cookie_t*)apr_palloc(pool, sizeof(cookie_t));
   cookie->cookie_id = NULL;
 
   has_cookie = 0;
@@ -141,7 +154,7 @@ chxj_save_cookie(request_rec *r)
   err_hentryp = (apr_table_entry_t*)err_headers->elts;
 
 
-  new_cookie_table = apr_table_make(r->pool, 0);
+  new_cookie_table = apr_table_make(pool, 0);
 
   for (ii=0; ii<headers->nelts; ii++) {
     if (strcasecmp(hentryp[ii].key, "Set-Cookie") == 0) {
@@ -153,7 +166,7 @@ chxj_save_cookie(request_rec *r)
       char* buff;
 
 
-      buff = apr_pstrdup(r->pool, hentryp[ii].val);
+      buff = apr_pstrdup(pool, hentryp[ii].val);
       val = strchr(buff, '=');
       if (val) {
         key = buff;
@@ -177,7 +190,7 @@ chxj_save_cookie(request_rec *r)
       char* buff;
 
 
-      buff = apr_pstrdup(r->pool, err_hentryp[ii].val);
+      buff = apr_pstrdup(pool, err_hentryp[ii].val);
       val = strchr(buff, '=');
       if (val) {
         key = buff;
@@ -195,16 +208,16 @@ chxj_save_cookie(request_rec *r)
   apr_table_unset(r->err_headers_out, "Set-Cookie");
 
   if (! has_refer) {
-    apr_uri_parse(r->pool,r->uri, &parsed_uri);
-    refer_string = apr_psprintf(r->pool, 
+    apr_uri_parse(pool,r->uri, &parsed_uri);
+    refer_string = apr_psprintf(pool, 
                                 "%s://%s%s", 
                                 chxj_run_http_scheme(r),
                                 r->hostname,
-                                apr_uri_unparse(r->pool,
+                                apr_uri_unparse(pool,
                                                 &parsed_uri,
                                                 APR_URI_UNP_OMITSITEPART));
     if (r->args && strlen(r->args)) {
-      refer_string = apr_pstrcat(r->pool, refer_string, "?", r->args, NULL);
+      refer_string = apr_pstrcat(pool, refer_string, "?", r->args, NULL);
     }
     apr_table_setn(new_cookie_table, REFERER_COOKIE_KEY, refer_string);
     DBG(r, "ADD REFER[%s]", refer_string);
@@ -241,27 +254,28 @@ chxj_save_cookie(request_rec *r)
    * create val
    */
   cookie->cookie_headers = (apr_array_header_t*)apr_table_elts(new_cookie_table);
-  store_string = apr_palloc(r->pool, 1);
-  store_string[0] = 0;
   hentryp = (apr_table_entry_t*)cookie->cookie_headers->elts;
-
+  apr_size_t store_string_len = 0;
   for (ii=0; ii<cookie->cookie_headers->nelts; ii++) {
-    if (ii) store_string = apr_pstrcat(r->pool,
-                               store_string, 
-                               "\n",
-                               NULL);
+    if (ii) store_string_len++;
+    store_string_len += (strlen(hentryp[ii].key) + strlen(hentryp[ii].val) + 1);
+  }
+  store_string = apr_palloc(pool, store_string_len + 1);
+  memset(store_string, 0, store_string_len + 1);
+  apr_size_t npos = 0;
 
-    store_string = apr_pstrcat(r->pool, 
-                               store_string, 
-                               hentryp[ii].key, 
-                               "=",
-                               hentryp[ii].val, 
-                               NULL);
+  for (ii=0; ii<cookie->cookie_headers->nelts; ii++) {
+    if (ii) store_string[npos++] = '\n';
+    memcpy(&store_string[npos], hentryp[ii].key, strlen(hentryp[ii].key));
+    npos += strlen(hentryp[ii].key);
+    store_string[npos++] = '=';
+    memcpy(&store_string[npos], hentryp[ii].val, strlen(hentryp[ii].val));
+    npos += strlen(hentryp[ii].val);
   }
 
   if (old_cookie_id && IS_COOKIE_LAZY(dconf)) {
     DBG(r, "LAZY COOKIE save");
-    cookie->cookie_id = apr_pstrdup(r->pool, old_cookie_id);
+    cookie->cookie_id = apr_pstrdup(pool, old_cookie_id);
   }
   else {
     DBG(r, "NO LAZY COOKIE save. old_cookie_id:[%s] LAZY:[%d]", old_cookie_id,IS_COOKIE_LAZY(dconf));
index bf67460..41e0a3f 100644 (file)
@@ -35,6 +35,7 @@ chxj_encoding(request_rec *r, const char *src, apr_size_t *len)
   apr_size_t          olen;
   mod_chxj_config     *dconf;
   chxjconvrule_entry  *entryp;
+  apr_pool_t          *pool;
 
 
   DBG(r,"start chxj_encoding()");
@@ -60,8 +61,10 @@ chxj_encoding(request_rec *r, const char *src, apr_size_t *len)
     DBG(r,"none encoding.");
     return (char*)src;
   }
+
+  apr_pool_create(&pool, r->pool);
   ilen = *len;
-  ibuf = apr_palloc(r->pool, ilen+1);
+  ibuf = apr_palloc(pool, ilen+1);
   if (ibuf == NULL) {
     ERR(r, "runtime exception: chxj_encoding(): Out of memory.");
     return (char *)src;
@@ -70,7 +73,7 @@ chxj_encoding(request_rec *r, const char *src, apr_size_t *len)
   memcpy(ibuf, src, ilen);
 
   olen = ilen * 4 + 1;
-  spos = obuf = apr_palloc(r->pool, olen);
+  spos = obuf = apr_palloc(pool, olen);
   if (obuf == NULL) {
     DBG(r,"end   chxj_encoding()");
     return ibuf;
index 1a55479..b78592b 100644 (file)
@@ -1018,8 +1018,12 @@ s_add_cookie_id_if_has_location_header(request_rec *r, cookie_t *cookie)
     location_header = chxj_add_cookie_parameter(r,
                                                 location_header,
                                                 cookie);
+    apr_table_unset(r->headers_out, "Location");
     apr_table_setn(r->headers_out, "Location", location_header);
     DBG(r, "Location Header=[%s]", location_header);
+    if (r->status < HTTP_MULTIPLE_CHOICES || r->status > HTTP_TEMPORARY_REDIRECT) {
+      r->status = HTTP_MOVED_TEMPORARILY;
+    }
   }
 }