OSDN Git Service

* Changed internal features.
authorAtsushi Konno <konn@users.sourceforge.jp>
Mon, 7 Mar 2011 07:58:23 +0000 (16:58 +0900)
committerAtsushi Konno <konn@users.sourceforge.jp>
Mon, 7 Mar 2011 07:58:23 +0000 (16:58 +0900)
    - To abolish the use of the thread local storage and to use
      r->request_config

include/chxj_apache.h
include/mod_chxj.h
src/chxj_apache.c
src/chxj_specified_device.c
src/mod_chxj.c

index bf520cf..75c3e26 100644 (file)
@@ -129,6 +129,7 @@ extern const char *chxj_apache_run_http_scheme(request_rec *r);
 extern char * chxj_os_escape_path(apr_pool_t *p, const char *path, int partial);
 extern void chxj_set_content_type(request_rec *r, const char *ct);
 extern void * chxj_get_module_config(const ap_conf_vector_t *cv, const module *m);
+extern void chxj_set_module_config(const ap_conf_vector_t *cv, const module *m, void *val);
 extern char *chxj_ap_escape_html(apr_pool_t *p, const char *s);
 extern ap_regex_t *chxj_ap_pregcomp(apr_pool_t *p, const char *pattern, int cflags);
 extern void chxj_ap_pregfree(apr_pool_t *p, ap_regex_t *reg);
index feaa46a..74e300e 100755 (executable)
@@ -288,6 +288,7 @@ typedef enum {
 } tag_type;
 
 typedef struct mod_chxj_config mod_chxj_config;
+typedef struct mod_chxj_req_config_t mod_chxj_req_config;
 
 #if defined(USE_MYSQL_COOKIE)
 #  include "chxj_mysql.h"
@@ -378,6 +379,10 @@ struct mod_chxj_config {
   int                   image_rewrite_mode;
 };
 
+struct mod_chxj_req_config_t {
+  device_table *spec;
+};
+
 #define IS_COOKIE_STORE_DBM(X)      ((X) == COOKIE_STORE_TYPE_DBM)
 #define IS_COOKIE_STORE_MYSQL(X)    ((X) == COOKIE_STORE_TYPE_MYSQL)
 #define IS_COOKIE_STORE_MEMCACHE(X) ((X) == COOKIE_STORE_TYPE_MEMCACHE)
index 15569fb..3021230 100644 (file)
@@ -69,6 +69,14 @@ chxj_get_module_config(const ap_conf_vector_t *cv, const module *m)
 #endif
 }
 
+void
+chxj_set_module_config(const ap_conf_vector_t *cv, const module *m, void *val)
+{
+#if defined(CHXJ_TEST)
+#else
+  ap_set_module_config(cv,m,val);
+#endif
+}
 
 char *
 chxj_ap_escape_html(apr_pool_t *p, const char *s) 
index a4a5860..f2633d1 100755 (executable)
@@ -62,7 +62,6 @@ static device_table  UNKNOWN_DEVICE      = {
   .output_encoding = "Shift_JIS",
 };
 /* spec cache */
-static __thread device_table *v_spec = NULL;
 static device_table *s_get_device_data(request_rec *r, const char *device_id, device_table_list *dtl);
 static device_table *s_specified_device_from_xml(request_rec *r, mod_chxj_config * conf, const char *user_agent);
 static device_table *s_specified_device_from_tsv(request_rec *r,device_table *spec,const char *user_agent);
@@ -101,20 +100,18 @@ chxj_specified_device(request_rec *r, const char *user_agent)
   device_table         *dt = &UNKNOWN_DEVICE;
   mod_chxj_config      *conf;
   char                 *spec_check = NULL;
+  mod_chxj_req_config  *request_conf;
   
   DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
 
-  /*
-   * if I have spec cache, I will use it.
-   */
-  spec_check = (char *)apr_table_get(r->headers_in, "X-Chxj-Spec-Check");
-  if (spec_check && STRCASEEQ('d','D',"done",spec_check)) {
-    dt = v_spec;
+  request_conf = (mod_chxj_req_config *)chxj_get_module_config(r->request_config, &chxj_module);
+  if (request_conf && request_conf->spec) {
     DBG(r, "REQ[%x] Use spec cache.", TO_ADDR(r));
-    DBG(r, "REQ[%x] end %s() (Spec-Check-Done)", (unsigned int)(apr_size_t)r, __func__);
-    return dt;
+    DBG(r, "REQ[%x] end %s() (Exist spec cache)", (unsigned int)(apr_size_t)r, __func__);
+    return request_conf->spec;
   }
   
+  
   conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
   if(! user_agent){
     DBG(r, "REQ[%X] end %s() %d", TO_ADDR(r), __func__,conf->detect_device_type);
@@ -127,8 +124,7 @@ chxj_specified_device(request_rec *r, const char *user_agent)
     s_specified_device_from_tsv(r,dt,user_agent);
   }
   /* save to spec cache */
-  v_spec = dt;
-  apr_table_setn(r->headers_in, "X-Chxj-Spec-Check", "done");
+  request_conf->spec = dt;
   
   DBG(r, "REQ[%X] end %s() %d",TO_ADDR(r), __func__,conf->detect_device_type);
   return dt;
@@ -395,7 +391,6 @@ void
 chxj_specified_cleanup(request_rec *r)
 {
   DBG(r,"REQ[%X] start %s()",TO_ADDR(r),__func__);
-  v_spec = NULL;
   DBG(r,"REQ[%X] end %s()",TO_ADDR(r),__func__);
 }
 
index 28bdd03..b1ce43d 100755 (executable)
@@ -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,6 +189,12 @@ 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;
+    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);