From 87b0d2acc50be7a209e13d7152e80fd615057a11 Mon Sep 17 00:00:00 2001 From: Atsushi Konno Date: Mon, 7 Mar 2011 16:41:46 +0900 Subject: [PATCH] * Changed internal feature. - to abolish the use of the thread local storage and to use r->request_config. --- include/chxj_apache.h | 1 + include/mod_chxj.h | 5 +++++ src/chxj_apache.c | 9 +++++++++ src/chxj_specified_device.c | 27 ++++++++++++--------------- src/mod_chxj.c | 15 +++++++++++++++ 5 files changed, 42 insertions(+), 15 deletions(-) diff --git a/include/chxj_apache.h b/include/chxj_apache.h index 36fb1d11..6cc25ab4 100644 --- a/include/chxj_apache.h +++ b/include/chxj_apache.h @@ -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); diff --git a/include/mod_chxj.h b/include/mod_chxj.h index ee0b9300..a6818793 100644 --- a/include/mod_chxj.h +++ b/include/mod_chxj.h @@ -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) diff --git a/src/chxj_apache.c b/src/chxj_apache.c index b3b03e42..9c240ab5 100644 --- a/src/chxj_apache.c +++ b/src/chxj_apache.c @@ -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) diff --git a/src/chxj_specified_device.c b/src/chxj_specified_device.c index 20d1aded..1bfcd334 100644 --- a/src/chxj_specified_device.c +++ b/src/chxj_specified_device.c @@ -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__); } diff --git a/src/mod_chxj.c b/src/mod_chxj.c index 9da01166..d6a76a7a 100644 --- a/src/mod_chxj.c +++ b/src/mod_chxj.c @@ -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"); -- 2.11.0