OSDN Git Service

* Changed internal feature.
authorAtsushi Konno <konn@users.sourceforge.jp>
Mon, 7 Mar 2011 07:41:46 +0000 (16:41 +0900)
committerAtsushi Konno <konn@users.sourceforge.jp>
Mon, 7 Mar 2011 07:41:46 +0000 (16:41 +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 36fb1d1..6cc25ab 100644 (file)
@@ -114,6 +114,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(ap_conf_vector_t *cv, const module *m, void *val);
 extern char *chxj_ap_escape_html(apr_pool_t *p, const char *s);
 
 
index ee0b930..a681879 100644 (file)
@@ -282,6 +282,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"
@@ -362,6 +363,10 @@ struct mod_chxj_config {
   char                  *post_log;              /* post log environment name. */
 };
 
+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 b3b03e4..9c240ab 100644 (file)
@@ -61,6 +61,15 @@ chxj_get_module_config(const ap_conf_vector_t *cv, const module *m)
 #endif
 }
 
+void
+chxj_set_module_config(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 20d1ade..1bfcd33 100644 (file)
@@ -58,7 +58,6 @@ static device_table  UNKNOWN_DEVICE      = {
   .color = 15680000,
   .emoji_type = NULL,
 };
-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);
 
 /**
@@ -74,8 +73,8 @@ chxj_specified_device(request_rec *r, const char *user_agent)
   device_table         *returnType = &UNKNOWN_DEVICE;
   device_table_list    *dtl;
   mod_chxj_config      *conf; 
+  mod_chxj_req_config  *request_conf; 
   char                 *device_id;
-  char                 *spec_check = NULL;
 
   DBG(r,"REQ[%x] start %s()", TO_ADDR(r), __func__ );
 
@@ -84,20 +83,21 @@ chxj_specified_device(request_rec *r, const char *user_agent)
     return returnType;
   }
 
-
-
-  spec_check = (char *)apr_table_get(r->headers_in, "X-Chxj-Spec-Check");
-  if (spec_check && STRCASEEQ('d','D',"done",spec_check)) {
+  /*
+   * Get per request config.
+   */
+  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.", (unsigned int)(apr_size_t)r);
-    returnType = v_spec;
-    DBG(r,"REQ[%x] end %s() (Spec-Check-Done)", TO_ADDR(r),__func__);
+    returnType = request_conf->spec;
+    DBG(r,"REQ[%x] end %s() (Exist requestConf)", TO_ADDR(r),__func__);
     return returnType;
   }
 
   conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
   if (! conf->devices) {
     ERR(r,"REQ[%X] device_data.xml load failure", TO_ADDR(r));
-    DBG(r,"REQ[%x] end %s() (Spec-Check-Done)", TO_ADDR(r),__func__);
+    DBG(r,"REQ[%x] end %s()", TO_ADDR(r),__func__);
     return returnType;
   }
 
@@ -110,7 +110,7 @@ chxj_specified_device(request_rec *r, const char *user_agent)
     /* DBG(r, "REQ[%X] pattern is [%s]", TO_ADDR(r), dtl->pattern); */
     if (! dtl->regexp) {
       ERR(r,"REQ[%X] compile failed.", TO_ADDR(r));
-      DBG(r,"REQ[%x] end %s() (Spec-Check-Done)", TO_ADDR(r),__func__);
+      DBG(r,"REQ[%x] end %s()", TO_ADDR(r),__func__);
       return returnType;
     }
 
@@ -126,15 +126,13 @@ chxj_specified_device(request_rec *r, const char *user_agent)
           returnType = &UNKNOWN_DEVICE;
         }
       }
-      v_spec = returnType;
-      apr_table_setn(r->headers_in, "X-Chxj-Spec-Check", "done");
+      request_conf->spec = returnType;
       DBG(r,"REQ[%X] end %s() (Found User-Agent Type)", TO_ADDR(r),__func__);
       return returnType;
     }
   }
 
-  v_spec = &UNKNOWN_DEVICE;
-  apr_table_setn(r->headers_in, "X-Chxj-Spec-Check", "done");
+  request_conf->spec = &UNKNOWN_DEVICE;
   DBG(r,"REQ[%X] end %s() (Not Found User-Agent Type) [%s]",TO_ADDR(r), __func__,user_agent);
 
   return &UNKNOWN_DEVICE;
@@ -144,7 +142,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 9da0116..d6a76a7 100644 (file)
@@ -172,6 +172,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,20 @@ chxj_headers_fixup(request_rec *r)
   dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
 
   user_agent = (char*)apr_table_get(r->headers_in, HTTP_USER_AGENT);
+
+  /*
+   * make space for the per request config
+   */
+  request_conf = (mod_chxj_req_config *)chxj_get_module_config(r->request_config, &chxj_module);
+  if (! request_conf) {
+    request_conf = apr_pcalloc(r->pool, sizeof(mod_chxj_req_config));
+    request_conf->spec = NULL;
+    chxj_set_module_config(r->request_config, &chxj_module, request_conf);
+  }
+
+  /*
+   * check and get mobile type.
+   */
   spec = chxj_specified_device(r, user_agent);
 
   contentType = (char *)apr_table_get(r->headers_in, "Content-Type");