OSDN Git Service

* Bug Fix.
authorkonn <konn@1a406e8e-add9-4483-a2c8-d8cac5b7c224>
Mon, 22 Sep 2008 15:47:16 +0000 (15:47 +0000)
committerkonn <konn@1a406e8e-add9-4483-a2c8-d8cac5b7c224>
Mon, 22 Sep 2008 15:47:16 +0000 (15:47 +0000)
    - Load and save are locked by a set.

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

include/chxj_cookie.h
include/chxj_dbm.h
src/chxj_cookie.c
src/chxj_dbm.c
src/mod_chxj.c

index 2b6a495..212dd62 100644 (file)
@@ -51,6 +51,13 @@ struct cookie_t {
   apr_array_header_t* cookie_headers;
 };
 
+typedef struct cookie_lock_t cookie_lock_t;
+
+struct cookie_lock_t {
+  apr_file_t *file;
+};
+
+
 
 extern cookie_t* chxj_save_cookie(
   request_rec*            r);
@@ -116,8 +123,13 @@ extern cookie_t* chxj_update_cookie(
   cookie_t*    old_cookie);
 
 extern apr_time_t chxj_parse_cookie_expires(const char *s);
-extern int chxj_cookie_lock(request_rec *r);
-extern int chxj_cookie_unlock(request_rec *r);
+
+extern cookie_lock_t *__chxj_cookie_lock(request_rec *r, const char *filename, int line);
+extern int __chxj_cookie_unlock(request_rec *r, cookie_lock_t *lock, const char *filename, int line);
+
+#define chxj_cookie_lock(X) __chxj_cookie_lock((X),__FILE__,__LINE__)
+#define chxj_cookie_unlock(X,L) __chxj_cookie_unlock((X),(L),__FILE__,__LINE__)
+
 #endif
 /*
  * vim:ts=2 et
index 19ae3e4..9acedbe 100644 (file)
@@ -44,6 +44,6 @@ extern int chxj_delete_cookie_dbm(request_rec *r, mod_chxj_config *m, const char
 extern int chxj_save_cookie_expire_dbm(request_rec *r, mod_chxj_config *m, const char *cookie_id);
 extern int chxj_delete_cookie_expire_dbm(request_rec *r, mod_chxj_config *m, const char *cookie_id);
 extern int chxj_cookie_expire_gc_dbm(request_rec *r, mod_chxj_config *m);
-extern int chxj_cookie_lock_dbm(request_rec *r, mod_chxj_config *m);
-extern int chxj_cookie_unlock_dbm(request_rec *r, mod_chxj_config *m);
+extern cookie_lock_t *chxj_cookie_lock_dbm(request_rec *r, mod_chxj_config *UNUSED(m));
+extern int chxj_cookie_unlock_dbm(request_rec *r, cookie_lock_t *lock, mod_chxj_config *UNUSED(m));
 #endif
index c229d09..4f6fca5 100644 (file)
@@ -1039,58 +1039,64 @@ chxj_parse_cookie_expires(const char *s)
 }
 
 
-int
-chxj_cookie_lock(request_rec *r)
+cookie_lock_t *
+__chxj_cookie_lock(request_rec *r, const char *filename, int line)
 {
   mod_chxj_config *dconf;
   apr_status_t rv;
   int done_proc = 0;
+  cookie_lock_t *ret = NULL;
 
-  DBG(r, "start chxj_cookie_lock()");
+  DBG(r, "start chxj_cookie_lock() call from %s:%d", filename, line);
   if ((rv = apr_proc_mutex_lock(global_cookie_mutex)) != APR_SUCCESS) {
     char errstr[255];
     ERR(r, "%s:%d apr_proc_mutex_lock failure.(%d:%s)", APLOG_MARK, rv, apr_strerror(rv, errstr, 255));
-    return 0;
+    return NULL;
   }
   dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
 #if defined(USE_MYSQL_COOKIE)
   if (IS_COOKIE_STORE_MYSQL(dconf->cookie_store_type)) {
     if (! chxj_cookie_lock_mysql(r, dconf)) {
       ERR(r, "%s:%d end chxj_cookie_lock(): failed: chxj_cookie_lock_mysql()", APLOG_MARK);
-      return 0;
+      return NULL;
     }
     done_proc = 1;
-  } 
+    ret = apr_palloc(r->pool, sizeof(*ret));
+    memset(ret, 0, sizeof(*ret));
+  }
 #endif
 #if defined(USE_MEMCACHE_COOKIE)
   if (IS_COOKIE_STORE_MEMCACHE(dconf->cookie_store_type)) {
     if (! chxj_cookie_lock_memcache(r, dconf)) {
       ERR(r, "%s:%d end chxj_cookie_lock(): failed: chxj_cookie_lock_memcache()", APLOG_MARK);
-      return 0;
+      return NULL;
     }
     done_proc = 1;
-  } 
+    ret = apr_palloc(r->pool, sizeof(*ret));
+    memset(ret, 0, sizeof(*ret));
+  }
 #endif
   if (!done_proc) {
-    if (! chxj_cookie_lock_dbm(r, dconf)) {
+    if (!(ret = chxj_cookie_lock_dbm(r, dconf))) {
       ERR(r, "%s:%d end chxj_cookie_lock(): failed: chxj_cookie_lock_dbm()", APLOG_MARK);
-      return 0;
+      DBG(r, "end chxj_cookie_lock() call from %s:%d", filename, line);
+      return NULL;
     }
   }
-  DBG(r, "end   chxj_cookie_lock()");
-  return 1;
+  DBG(r, "REQ:[%X] end chxj_cookie_lock() call from %s:%d", (unsigned int)(apr_size_t)r, filename, line);
+  return ret;
 }
 
 
 int
-chxj_cookie_unlock(request_rec *r)
+__chxj_cookie_unlock(request_rec *r, cookie_lock_t *lock, const char *filename, int line)
 {
   mod_chxj_config *dconf;
   int done_proc = 0;
   apr_status_t rv;
   int rtn = 1;
 
-  DBG(r, "start chxj_cookie_unlock()");
+  DBG(r, "start chxj_cookie_unlock() call from %s:%d", filename, line);
 
   dconf = chxj_get_module_config(r->per_dir_config, &chxj_module);
 #if defined(USE_MYSQL_COOKIE)
@@ -1101,7 +1107,7 @@ chxj_cookie_unlock(request_rec *r)
       goto end_chxj_cookie_unlock;
     }
     done_proc = 1;
-  } 
+  }
 #endif
 #if defined(USE_MEMCACHE_COOKIE)
   if (IS_COOKIE_STORE_MEMCACHE(dconf->cookie_store_type)) {
@@ -1111,10 +1117,10 @@ chxj_cookie_unlock(request_rec *r)
       goto end_chxj_cookie_unlock;
     }
     done_proc = 1;
-  } 
+  }
 #endif
   if (!done_proc) {
-    if (! chxj_cookie_unlock_dbm(r, dconf)) {
+    if (! chxj_cookie_unlock_dbm(r, lock, dconf)) {
       ERR(r, "failed: chxj_cookie_unlock_dbm()");
       rtn = 0;
       goto end_chxj_cookie_unlock;
@@ -1124,9 +1130,10 @@ end_chxj_cookie_unlock:
   if ((rv = apr_proc_mutex_unlock(global_cookie_mutex)) != APR_SUCCESS) {
     char errstr[255];
     ERR(r, "%s:%d apr_proc_mutex_unlock failure.(%d:%s)", APLOG_MARK, rv, apr_strerror(rv, errstr, 255));
+    DBG(r, "end chxj_cookie_unlock() call from %s:%d", filename, line);
     return 0;
   }
-  DBG(r, "end   chxj_cookie_unlock()");
+  DBG(r, "end chxj_cookie_unlock() call from %s:%d", filename, line);
 
   return rtn;
 }
index ad35444..1f90311 100644 (file)
@@ -662,16 +662,19 @@ chxj_cookie_expire_gc_dbm(request_rec *r, mod_chxj_config *m)
 }
 
 
-int
-chxj_cookie_lock_dbm(request_rec *UNUSED(r), mod_chxj_config *UNUSED(m))
+cookie_lock_t *
+chxj_cookie_lock_dbm(request_rec *r, mod_chxj_config *UNUSED(m))
 {
-  return 1;  /* allways true */
+  cookie_lock_t *ret = apr_palloc(r->pool, sizeof(*ret));
+  ret->file = chxj_cookie_db_lock(r);
+  return ret;
 }
 
 
 int
-chxj_cookie_unlock_dbm(request_rec *UNUSED(r), mod_chxj_config *UNUSED(m))
+chxj_cookie_unlock_dbm(request_rec *r, cookie_lock_t *lock, mod_chxj_config *UNUSED(m))
 {
+  chxj_cookie_expire_db_unlock(r, lock->file);
   return 1; /* allways true */
 }
 /*
index bdc1698..a64d447 100644 (file)
@@ -542,13 +542,13 @@ chxj_convert_input_header(request_rec *r,chxjconvrule_entry *entryp)
       apr_table_unset(r->headers_in, "Cookie");
       DBG(r, "found cookie parameter[%s]", value);
       DBG(r, "call start chxj_load_cookie()");
-      chxj_cookie_lock(r);
+      cookie_lock_t *lock = chxj_cookie_lock(r);
       cookie = chxj_load_cookie(r, value);
       DBG(r, "call end   chxj_load_cookie()");
       if (! no_update_flag && cookie) {
         chxj_update_cookie(r, cookie);
       }
-      chxj_cookie_unlock(r);
+      chxj_cookie_unlock(r, lock);
     }
   }
   r->args = result;
@@ -802,6 +802,7 @@ chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
       
       DBG(r, "not convert content-type:[%s] dconf->image:[%d]", r->content_type, dconf->image);
       if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
+        cookie_lock_t *lock = NULL;
         DBG(r, "entryp->action == COOKIE_ON_BIT");
         switch(spec->html_spec_type) {
         case CHXJ_SPEC_Chtml_1_0:
@@ -813,10 +814,10 @@ chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
         case CHXJ_SPEC_Chtml_7_0:
         case CHXJ_SPEC_XHtml_Mobile_1_0:
         case CHXJ_SPEC_Jhtml:
-          chxj_cookie_lock(r);
+          lock = chxj_cookie_lock(r);
           cookie = chxj_save_cookie(r);
           s_add_cookie_id_if_has_location_header(r, cookie);
-          chxj_cookie_unlock(r);
+          chxj_cookie_unlock(r, lock);
           break;
         default:
           break;
@@ -873,10 +874,11 @@ chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
       /* End Of File                                                          */
       /*----------------------------------------------------------------------*/
       if (ctx) {
+        cookie_lock_t *lock = NULL;
         ctx = (mod_chxj_ctx *)f->ctx;
 
         DBG(r, "content_type=[%s]", r->content_type);
-        chxj_cookie_lock(r);
+        lock = chxj_cookie_lock(r);
 
         if (spec->html_spec_type != CHXJ_SPEC_UNKNOWN 
             && r->content_type 
@@ -949,7 +951,7 @@ chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
             sts = chxj_qrcode_create_image_data(&qrcode, &ctx->buffer, &ctx->len);
             if (sts != OK) {
               ERR(r, "qrcode create failed.");
-              chxj_cookie_unlock(r);
+              chxj_cookie_unlock(r, lock);
               return sts;
             }
             r->content_type = apr_psprintf(r->pool, "image/jpeg");
@@ -999,13 +1001,14 @@ chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
         if (ctx->len > 0) {
           DBG(r, "call pass_data_to_filter()");
           s_add_cookie_id_if_has_location_header(r, cookie);
-          chxj_cookie_unlock(r);
+          chxj_cookie_unlock(r,lock);
           rv = pass_data_to_filter(f, 
                                    (const char *)ctx->buffer, 
                                    (apr_size_t)ctx->len);
         }
         else {
-          chxj_cookie_unlock(r);
+          chxj_cookie_unlock(r, lock);
+
         }
         return rv;
       }
@@ -1016,6 +1019,7 @@ chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
          * save cookie.
          */
         if (entryp->action & CONVRULE_COOKIE_ON_BIT) {
+          cookie_lock_t *lock = NULL;
           DBG(r, "entryp->action == COOKIE_ON_BIT");
           switch(spec->html_spec_type) {
           case CHXJ_SPEC_Chtml_1_0:
@@ -1027,13 +1031,13 @@ chxj_output_filter(ap_filter_t *f, apr_bucket_brigade *bb)
           case CHXJ_SPEC_Chtml_7_0:
           case CHXJ_SPEC_XHtml_Mobile_1_0:
           case CHXJ_SPEC_Jhtml:
-            chxj_cookie_lock(r);
+            lock = chxj_cookie_lock(r);
             cookie = chxj_save_cookie(r);
             /*
              * Location Header Check to add cookie parameter.
              */
             s_add_cookie_id_if_has_location_header(r, cookie);
-            chxj_cookie_unlock(r);
+            chxj_cookie_unlock(r, lock);
             apr_table_unset(r->headers_out, "Set-Cookie");
             apr_table_unset(r->err_headers_out, "Set-Cookie");
             break;