OSDN Git Service

* Fixed Bug.
[modchxj/mod_chxj.git] / src / mod_chxj.c
old mode 100755 (executable)
new mode 100644 (file)
index 28bdd03..4353534
@@ -175,6 +175,7 @@ static apr_status_t
 chxj_headers_fixup(request_rec *r)
 {
   mod_chxj_config*    dconf; 
+  mod_chxj_req_config *request_conf; 
   chxjconvrule_entry* entryp;
   char*               user_agent;
   device_table*       spec;
@@ -188,9 +189,21 @@ chxj_headers_fixup(request_rec *r)
     return DECLINED;
   }
 
+  request_conf = (mod_chxj_req_config *)chxj_get_module_config(r->request_config, &chxj_module);
+  if (!request_conf) {
+    request_conf = apr_palloc(r->pool, sizeof(mod_chxj_req_config));
+    request_conf->spec = NULL;
+    request_conf->user_agent = NULL;
+    chxj_set_module_config(r->request_config, &chxj_module, request_conf);
+  }
   dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
 
   user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
+
+  /*
+   * check and get mobile type.
+   * and request_conf->user_agent , request_conf->spec is set.
+   */
   spec = chxj_specified_device(r, user_agent);
 
   contentType = (char *)apr_table_get(r->headers_in, "Content-Type");
@@ -271,9 +284,9 @@ chxj_headers_fixup(request_rec *r)
 
   if (r->method_number == M_POST) {
     if (! apr_table_get(r->headers_in, "X-Chxj-Forward")) {
-        DBG(r, "REQ[%X] set Input handler old:[%s] proxyreq:[%d] uri:[%s] filename:[%s]", TO_ADDR(r), r->handler, r->proxyreq, r->uri, r->filename);
-        r->proxyreq = PROXYREQ_NONE;
-        r->handler = apr_psprintf(r->pool, "chxj-input-handler");
+      DBG(r, "REQ[%X] set Input handler old:[%s] proxyreq:[%d] uri:[%s] filename:[%s]", TO_ADDR(r), r->handler, r->proxyreq, r->uri, r->filename);
+      r->proxyreq = PROXYREQ_NONE;
+      r->handler = apr_psprintf(r->pool, "chxj-input-handler");
     }
     else {
       char *client_ip = (char *)apr_table_get(r->headers_in, CHXJ_HEADER_ORIG_CLIENT_IP);
@@ -1123,7 +1136,6 @@ chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
     s_add_no_cache_headers(r, entryp);
     /* must not send body. */
     rv = pass_data_to_filter(f, "", 0);
-    chxj_specified_cleanup(r);
     DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
     return rv;
   }
@@ -1178,15 +1190,13 @@ chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
       s_add_no_cache_headers(r, entryp);
       ap_pass_brigade(f->next, bb);
       DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
-      chxj_specified_cleanup(r);
       return APR_SUCCESS;
     }
   }
   else {
     DBG(r, "REQ[%X] not convert content-type:[(null)]", TO_ADDR(r));
     ap_pass_brigade(f->next, bb);
-    chxj_specified_cleanup(r);
-    DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
+    DBG(f->r, "REQ[%X] end %s()", TO_ADDR(f->r),__func__);
     return APR_SUCCESS;
   }
 
@@ -1304,7 +1314,6 @@ chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
             if (sts != OK) {
               ERR(r, "REQ[%X] qrcode create failed.", TO_ADDR(r));
               chxj_cookie_unlock(r, lock);
-              chxj_specified_cleanup(r);
               DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
               return sts;
             }
@@ -1376,7 +1385,6 @@ chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
                                    (const char *)ctx->buffer, 
                                    (apr_size_t)ctx->len);
         }
-        chxj_specified_cleanup(r);
         DBG(f->r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
         return rv;
       }
@@ -1423,14 +1431,12 @@ chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
         apr_table_setn(r->headers_out, "Content-Length", "0");
         s_add_no_cache_headers(r, entryp);
         rv = pass_data_to_filter(f, (const char *)"", (apr_size_t)0);
-        chxj_specified_cleanup(r);
         return rv;
       }
     }
   }
   apr_brigade_destroy(bb);
 
-  chxj_specified_cleanup(r);
   DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
 
   return APR_SUCCESS;
@@ -1545,14 +1551,6 @@ chxj_input_handler(request_rec *r)
   apr_table_unset(r->headers_in, "Content-Length");
   apr_table_setn(r->headers_in, "Content-Length", apr_psprintf(pool, "%" APR_SIZE_T_FMT, post_data_len));
   response = chxj_serf_post(r, pool, url_path, post_data, post_data_len, 1, &res_len, &response_code);
-#if 0
-  DBG(r, "REQ[%X] -------------------------------------------------------", TO_ADDR(r));
-  DBG(r, "REQ[%X] response length:[%" APR_SIZE_T_FMT "]", (unsigned int)(apr_size_t)r, res_len);
-  for (ii=0; ii<res_len/64; ii++) {
-    DBG(r, "REQ[%X] response:[%.*s]", TO_ADDR(r), 64, &response[ii*64]);
-  }
-  DBG(r, "REQ[%X] -------------------------------------------------------", TO_ADDR(r));
-#endif
 
   char *chunked;
   if ((chunked = (char *)apr_table_get(r->headers_out, "Transfer-Encoding")) != NULL) {