request_rec* r,
apr_file_t* file);
-extern void chxj_delete_cookie(
- request_rec* r,
- char* cookie_id);
+extern void chxj_delete_cookie(request_rec *r, const char *cookie_id);
extern char* chxj_cookie_db_name_create(
request_rec* r,
--- /dev/null
+/*
+ * Copyright (C) 2005-2008 Atsushi Konno All rights reserved.
+ * Copyright (C) 2005 QSDN,Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __CHXJ_DBM_H__
+#define __CHXJ_DBM_H__
+
+#include "mod_chxj.h"
+#include "apr.h"
+#include "apu.h"
+#include "apr_dbm.h"
+#include "apr_uuid.h"
+#include "apr_md5.h"
+#include "apr_base64.h"
+#include "apr_uri.h"
+#include "apr_time.h"
+#include "apr_date.h"
+
+extern void chxj_cookie_db_unlock(request_rec *r, apr_file_t *file);
+extern apr_file_t *chxj_cookie_db_lock(request_rec *r);
+extern char *chxj_cookie_db_lock_name_create(request_rec *r, const char *dir);
+extern char *chxj_cookie_db_name_create(request_rec *r, const char *dir);
+extern char *chxj_cookie_expire_db_lock_name_create(request_rec *r, const char *dir);
+extern apr_file_t *chxj_cookie_expire_db_lock(request_rec *r);
+extern void chxj_cookie_expire_db_unlock(request_rec *r, apr_file_t *file);
+
+/* operation for cookie */
+extern int chxj_save_cookie_dbm(request_rec *r, mod_chxj_config *m, const char *cookie_id, const char *store_string);
+extern int chxj_update_cookie_dbm(request_rec *r, mod_chxj_config *m, const char *cookie_id, const char *store_string);
+extern char *chxj_load_cookie_dbm(request_rec *r, mod_chxj_config *m, const char *cookie_id);
+extern int chxj_delete_cookie_dbm(request_rec *r, mod_chxj_config *m, const char *cookie_id);
+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);
+#endif
extern int chxj_memcache_delete_cookie(request_rec *r, mod_chxj_config *m, const char *cookie_id);
extern int chxj_memcache_reset_cookie(request_rec *r, mod_chxj_config *m, const char *cookie_id);
+
+/* operation for cookie */
+extern int chxj_save_cookie_memcache(request_rec *r, mod_chxj_config *m, const char *cookie_id, const char *store_string);
+extern int chxj_update_cookie_memcache(request_rec *, mod_chxj_config *m, const char *cookie_id, const char *store_string);
+extern char *chxj_load_cookie_memcache(request_rec *r, mod_chxj_config *m, const char *cookie_id);
+extern int chxj_delete_cookie_memcache(request_rec *r, mod_chxj_config *m, const char *cookie_id);
+extern int chxj_save_cookie_expire_memcache(request_rec *r, mod_chxj_config *m, const char *cookie_id);
+extern int chxj_delete_cookie_expire_memcache(request_rec *r, mod_chxj_config *m, const char *cookie_id);
+extern int chxj_cookie_expire_gc_memcache(request_rec *r, mod_chxj_config *m);
#endif
#endif
extern int chxj_mysql_exist_cookie_table_expire(request_rec *r, mod_chxj_config *m);
extern char *chxj_mysql_get_timeout_localtime(request_rec *r, mod_chxj_config *m);
extern int chxj_mysql_delete_expired_cookie(request_rec *r, mod_chxj_config *m);
+
+
+/* operation for cookie */
+extern int chxj_save_cookie_mysql(request_rec *r, mod_chxj_config *m, const char *cookie_id, const char *store_string);
+extern int chxj_update_cookie_mysql(request_rec *r, mod_chxj_config *m, const char *cookie_id, const char *store_string);
+extern char *chxj_load_cookie_mysql(request_rec *r, mod_chxj_config *m, const char *cookie_id);
+extern int chxj_delete_cookie_mysql(request_rec *r, mod_chxj_config *m, const char *cookie_id);
+extern int chxj_save_cookie_expire_mysql(request_rec *r, mod_chxj_config *m, const char *cookie_id);
+extern int chxj_delete_cookie_expire_mysql(request_rec *r, mod_chxj_config *m, const char *cookie_id);
+extern int chxj_cookie_expire_gc_mysql(request_rec *r, mod_chxj_config *m);
#endif
#endif
#if defined(USE_MYSQL_COOKIE)
# include "chxj_mysql.h"
-#elif defined(USE_MEMCACHE_COOKIE)
+#endif
+#if defined(USE_MEMCACHE_COOKIE)
# include "chxj_memcache.h"
#endif
+
+/* cookie store type */
+#define CHXJ_COOKIE_STORE_TYPE_DBM "dbm"
+#define CHXJ_COOKIE_STORE_TYPE_MYSQL "mysql"
+#define CHXJ_COOKIE_STORE_TYPE_MEMCACHE "memcache"
+typedef enum {
+ COOKIE_STORE_TYPE_NONE = 0,
+ COOKIE_STORE_TYPE_DBM = 1,
+ COOKIE_STORE_TYPE_MYSQL = 2,
+ COOKIE_STORE_TYPE_MEMCACHE = 3,
+} cookie_store_type_t;
+
struct mod_chxj_config {
int image;
char *cookie_db_dir;
long cookie_timeout;
+ cookie_store_type_t cookie_store_type;
+ int cookie_lazy_mode;
#if defined(USE_MYSQL_COOKIE)
mysql_t mysql;
-#elif defined(USE_MEMCACHE_COOKIE)
+#endif
+#if defined(USE_MEMCACHE_COOKIE)
memcache_t memcache;
#endif
};
+#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)
+#define IS_COOKIE_STORE_NONE(X) ((X) == COOKIE_STORE_TYPE_NONE)
+
#define CONVRULE_ENGINE_ON_BIT (0x00000001)
#define CONVRULE_ENGINE_OFF_BIT (0x00000002)
#define CONVRULE_PC_FLAG_ON_BIT (0x00000001)
#define CONVRULE_PC_FLAG_OFF_BIT (0x00000002)
+
typedef struct {
apr_global_mutex_t* cookie_db_lock;
} mod_chxj_global_config;
chxj_preg_replace.c \
chxj_cookie.c \
chxj_mysql.c \
- chxj_memcache.c
+ chxj_memcache.c \
+ chxj_dbm.c
libmod_chxj_la_CFLAGS = -O2 -prefer-pic @QDEFS@ @DDEFS@ -I. -I../include -I@with_apache_header@
libmod_chxj_la-chxj_url_encode.lo \
libmod_chxj_la-chxj_preg_replace.lo \
libmod_chxj_la-chxj_cookie.lo libmod_chxj_la-chxj_mysql.lo \
- libmod_chxj_la-chxj_memcache.lo
+ libmod_chxj_la-chxj_memcache.lo libmod_chxj_la-chxj_dbm.lo
libmod_chxj_la_OBJECTS = $(am_libmod_chxj_la_OBJECTS)
libmod_chxj_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(libmod_chxj_la_CFLAGS) \
chxj_preg_replace.c \
chxj_cookie.c \
chxj_mysql.c \
- chxj_memcache.c
+ chxj_memcache.c \
+ chxj_dbm.c
libmod_chxj_la_CFLAGS = -O2 -prefer-pic @QDEFS@ @DDEFS@ -I. -I../include -I@with_apache_header@
AM_CFLAGS = @CFLAGS@ -O2 -prefer-pic @QDEFS@ @DDEFS@ -I. -I../include -I@with_apache_header@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmod_chxj_la-chxj_chtml20.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmod_chxj_la-chxj_chtml30.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmod_chxj_la-chxj_cookie.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmod_chxj_la-chxj_dbm.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmod_chxj_la-chxj_dump.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmod_chxj_la-chxj_encoding.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmod_chxj_la-chxj_hdml.Plo@am__quote@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libmod_chxj_la_CFLAGS) $(CFLAGS) -c -o libmod_chxj_la-chxj_memcache.lo `test -f 'chxj_memcache.c' || echo '$(srcdir)/'`chxj_memcache.c
+libmod_chxj_la-chxj_dbm.lo: chxj_dbm.c
+@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libmod_chxj_la_CFLAGS) $(CFLAGS) -MT libmod_chxj_la-chxj_dbm.lo -MD -MP -MF $(DEPDIR)/libmod_chxj_la-chxj_dbm.Tpo -c -o libmod_chxj_la-chxj_dbm.lo `test -f 'chxj_dbm.c' || echo '$(srcdir)/'`chxj_dbm.c
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/libmod_chxj_la-chxj_dbm.Tpo $(DEPDIR)/libmod_chxj_la-chxj_dbm.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='chxj_dbm.c' object='libmod_chxj_la-chxj_dbm.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libmod_chxj_la_CFLAGS) $(CFLAGS) -c -o libmod_chxj_la-chxj_dbm.lo `test -f 'chxj_dbm.c' || echo '$(srcdir)/'`chxj_dbm.c
+
mostlyclean-libtool:
-rm -f *.lo
#if defined(USE_MYSQL_COOKIE)
# include "chxj_mysql.h"
-#elif defined(USE_MEMCACHE_COOKIE)
+#endif
+#if defined(USE_MEMCACHE_COOKIE)
# include "chxj_memcache.h"
#endif
+#include "chxj_dbm.h"
static char* s_get_hostname_from_url(request_rec* r, char* value);
char *store_string;
mod_chxj_config *dconf;
chxjconvrule_entry *entryp;
-#if !defined(USE_MYSQL_COOKIE) && !defined(USE_MEMCACHE_COOKIE)
- apr_status_t retval;
- apr_datum_t dbmkey;
- apr_datum_t dbmval;
- apr_dbm_t* f;
- apr_file_t* file;
-#endif
apr_table_t* new_cookie_table;
int has_cookie = 0;
cookie_t* cookie;
cookie->cookie_id = alloc_cookie_id(r);
+DBG(r, "TYPE:[%d]", dconf->cookie_store_type);
+ {
+ int done_proc = 0;
#if defined(USE_MYSQL_COOKIE)
-
- if (! chxj_open_mysql_handle(r, dconf)) {
- ERR(r, "Cannot open mysql connection");
- goto on_error;
- }
-
- if (!chxj_mysql_exist_cookie_table(r, dconf)) {
- DBG(r, "not found cookie table:[%s]", dconf->mysql.tablename);
- if (!chxj_mysql_create_cookie_table(r, dconf)) {
- ERR(r, "cannot create cookie table:[%s]", dconf->mysql.tablename);
- goto on_error;
+ if (IS_COOKIE_STORE_MYSQL(dconf->cookie_store_type)) {
+ if (! chxj_save_cookie_mysql(r, dconf, cookie->cookie_id, store_string)) {
+ ERR(r, "faild: chxj_save_cookie_mysql() cookie_id:[%s]", cookie->cookie_id);
+ goto on_error;
+ }
+ done_proc = 1;
+ }
+#endif
+#if defined(USE_MEMCACHE_COOKIE)
+ if (IS_COOKIE_STORE_MEMCACHE(dconf->cookie_store_type)) {
+ if (! chxj_save_cookie_memcache(r, dconf, cookie->cookie_id, store_string)) {
+ ERR(r, "failed: chxj_save_cookie_memcache() cookie_id:[%s]", cookie->cookie_id);
+ goto on_error;
+ }
+ done_proc = 1;
}
- }
- if (! chxj_mysql_insert_or_update_cookie(r, dconf, cookie->cookie_id, store_string)) {
- ERR(r, "cannot store to cookie table:[%s]", dconf->mysql.tablename);
- goto on_error;
- }
-
- /* *NEED NOT* close database. */
- /* chxj_close_mysql_handle(); */
-
-#elif defined(USE_MEMCACHE_COOKIE)
-
- if (! chxj_memcache_init(r, dconf)) {
- ERR(r, "Cannot create memcache server");
- goto on_error;
- }
-
- if (! chxj_memcache_set_cookie(r, dconf, cookie->cookie_id, store_string)) {
- ERR(r, "cannot store to memcache host:[%s] port:[%d]", dconf->memcache.host, dconf->memcache.port);
- goto on_error;
- }
- DBG(r, "stored DATA:[%s]", chxj_memcache_get_cookie(r, dconf, cookie->cookie_id));
-
-#else
- file = chxj_cookie_db_lock(r);
- if (! file) {
- ERR(r, "mod_chxj: Can't lock cookie db");
- DBG(r, "end chxj_save_cookie()");
- return NULL;
- }
-
- retval = apr_dbm_open_ex(&f,
- "default",
- chxj_cookie_db_name_create(r, dconf->cookie_db_dir),
- APR_DBM_RWCREATE,
- APR_OS_DEFAULT,
- r->pool);
- if (retval != APR_SUCCESS) {
- DBG(r, "end chxj_save_cookie()");
- ERR(r, "could not open dbm (type %s) auth file: %s",
- "default",
- chxj_cookie_db_name_create(r,dconf->cookie_db_dir));
- chxj_cookie_db_unlock(r, file);
- return NULL;
- }
-
-
- /*
- * create key
- */
-
- dbmkey.dptr = cookie->cookie_id;
- dbmkey.dsize = strlen(cookie->cookie_id);
- dbmval.dptr = store_string;
- dbmval.dsize = strlen(store_string);
-
- /*
- * store to db
- */
- retval = apr_dbm_store(f, dbmkey, dbmval);
- if (retval != APR_SUCCESS) {
- ERR(r, "Cannot store Cookie data to DBM file `%s'",
- chxj_cookie_db_name_create(r, dconf->cookie_db_dir));
- goto on_error;
- }
#endif
+ if (IS_COOKIE_STORE_DBM(dconf->cookie_store_type) || ! done_proc) {
+ if (! chxj_save_cookie_dbm(r, dconf, cookie->cookie_id, store_string)) {
+ ERR(r, "failed: chxj_save_cookie_dbm() cookie_id:[%s]", cookie->cookie_id);
+ goto on_error;
+ }
+ }
+ }
chxj_save_cookie_expire(r, cookie);
on_error:
-#if !defined(USE_MYSQL_COOKIE) && !defined(USE_MEMCACHE_COOKIE)
- apr_dbm_close(f);
- chxj_cookie_db_unlock(r, file);
-#endif
-
DBG(r, "end chxj_save_cookie()");
return cookie;
}
char* store_string;
mod_chxj_config* dconf;
chxjconvrule_entry* entryp;
-#if !defined(USE_MYSQL_COOKIE) && !defined(USE_MEMCACHE_COOKIE)
- apr_dbm_t *f;
- apr_file_t *file;
- apr_datum_t dbmkey;
- apr_datum_t dbmval;
- apr_status_t retval;
-#endif
cookie_t* cookie;
NULL);
}
+ {
+ int done_proc = 0;
#if defined(USE_MYSQL_COOKIE)
- if (! chxj_open_mysql_handle(r, dconf)) {
- ERR(r, "Cannot open mysql connection");
- goto on_error;
- }
-
- if (!chxj_mysql_exist_cookie_table(r, dconf)) {
- DBG(r, "not found cookie table:[%s]", dconf->mysql.tablename);
- if (!chxj_mysql_create_cookie_table(r, dconf)) {
- ERR(r, "cannot create cookie table:[%s]", dconf->mysql.tablename);
- goto on_error;
+ if (IS_COOKIE_STORE_MYSQL(dconf->cookie_store_type)) {
+ if (!chxj_update_cookie_mysql(r, dconf, cookie->cookie_id, store_string)) {
+ ERR(r, "failed: chxj_update_cookie_mysql() cookie_id:[%s]", cookie->cookie_id);
+ goto on_error;
+ }
+ done_proc = 1;
}
- }
- if (! chxj_mysql_insert_or_update_cookie(r, dconf, cookie->cookie_id, store_string)) {
- ERR(r, "cannot create cookie table:[%s]", dconf->mysql.tablename);
- goto on_error;
- }
-
- /* *NEED NOT* close database. */
- /* chxj_close_mysql_handle(); */
-#elif defined(USE_MEMCACHE_COOKIE)
-
- if (! chxj_memcache_init(r, dconf)) {
- ERR(r, "Cannot create memcache server");
- goto on_error;
- }
-
- if (! chxj_memcache_set_cookie(r, dconf, cookie->cookie_id, store_string)) {
- ERR(r, "cannot store to memcache host:[%s] port:[%d]", dconf->memcache.host, dconf->memcache.port);
- goto on_error;
- }
-
-#else
- file = chxj_cookie_db_lock(r);
- if (! file) {
- ERR(r, "mod_chxj: Can't lock cookie db");
- return NULL;
- }
-
- retval = apr_dbm_open_ex(&f,
- "default",
- chxj_cookie_db_name_create(r, dconf->cookie_db_dir),
- APR_DBM_RWCREATE,
- APR_OS_DEFAULT,
- r->pool);
- if (retval != APR_SUCCESS) {
- ERR(r, "could not open dbm (type %s) auth file: %s",
- "default",
- chxj_cookie_db_name_create(r,dconf->cookie_db_dir));
- chxj_cookie_db_unlock(r, file);
- return NULL;
- }
-
-
- /*
- * create key
- */
-
- dbmkey.dptr = cookie->cookie_id;
- dbmkey.dsize = strlen(cookie->cookie_id);
-
- /*
- * create val
- */
- dbmval.dptr = store_string;
- dbmval.dsize = strlen(store_string);
+#endif
- /*
- * store to db
- */
- retval = apr_dbm_store(f, dbmkey, dbmval);
- if (retval != APR_SUCCESS) {
- ERR(r, "Cannot store Cookie data to DBM file `%s'",
- chxj_cookie_db_name_create(r, dconf->cookie_db_dir));
- goto on_error;
- }
+#if defined(USE_MEMCACHE_COOKIE)
+ if (IS_COOKIE_STORE_MEMCACHE(dconf->cookie_store_type)) {
+ if (! chxj_update_cookie_memcache(r, dconf, cookie->cookie_id, store_string)) {
+ ERR(r, "failed: chxj_update_cookie_memcache() cookie_id:[%s]", cookie->cookie_id);
+ goto on_error;
+ }
+ done_proc = 1;
+ }
#endif
+ if (!done_proc || IS_COOKIE_STORE_DBM(dconf->cookie_store_type)) {
+ if (! chxj_update_cookie_dbm(r, dconf, cookie->cookie_id, store_string)) {
+ ERR(r, "failed: chxj_update_cookie_dbm() cookie_id:[%s]", cookie->cookie_id);
+ goto on_error;
+ }
+ }
+ }
chxj_save_cookie_expire(r, cookie);
on_error:
-#if !defined(USE_MYSQL_COOKIE) && !defined(USE_MEMCACHE_COOKIE)
- apr_dbm_close(f);
- chxj_cookie_db_unlock(r, file);
-#endif
-
DBG(r, "end chxj_update_cookie()");
return cookie;
}
{
mod_chxj_config *dconf;
chxjconvrule_entry *entryp;
-#if !defined(USE_MYSQL_COOKIE) && !defined(USE_MEMCACHE_COOKIE)
- apr_status_t retval;
- apr_dbm_t *f;
- apr_file_t *file;
- apr_datum_t dbmval;
- apr_datum_t dbmkey;
-#endif
cookie_t *cookie;
apr_table_t *load_cookie_table;
char *load_string = NULL;
}
load_cookie_table = apr_table_make(r->pool, 0);
+ {
+ int done_proc = 0;
#if defined(USE_MYSQL_COOKIE)
-
- if (! chxj_open_mysql_handle(r, dconf)) {
- ERR(r, "Cannot open mysql connection");
- goto on_error0;
- }
-
- if (!chxj_mysql_exist_cookie_table(r, dconf)) {
- DBG(r, "not found cookie table:[%s]", dconf->mysql.tablename);
- if (!chxj_mysql_create_cookie_table(r, dconf)) {
- ERR(r, "cannot create cookie table:[%s]", dconf->mysql.tablename);
- goto on_error0;
+ if (IS_COOKIE_STORE_MYSQL(dconf->cookie_store_type)) {
+ if (! (load_string = chxj_load_cookie_mysql(r, dconf, cookie->cookie_id))) {
+ ERR(r, "failed: chxj_load_cookie_mysql() cookie_id:[%s]", cookie_id);
+ goto on_error0;
+ }
+ done_proc = 1;
}
- }
- if (!(load_string = chxj_mysql_load_cookie(r, dconf, cookie->cookie_id))) {
- ERR(r, "not found cookie. cookie_id:[%s]", cookie->cookie_id);
- goto on_error0;
- }
-
- /* *NEED NOT* close database. */
- /* chxj_close_mysql_handle(); */
-
-#elif defined(USE_MEMCACHE_COOKIE)
-
- if (! chxj_memcache_init(r, dconf)) {
- ERR(r, "Cannot create memcache server");
- goto on_error0;
- }
-
- if (! (load_string = chxj_memcache_get_cookie(r, dconf, cookie->cookie_id))) {
- ERR(r, "cannot store to memcache host:[%s] port:[%d]", dconf->memcache.host, dconf->memcache.port);
- goto on_error0;
- }
-
-#else
- file = chxj_cookie_db_lock(r);
- if (! file) {
- ERR(r, "mod_chxj: Can't lock cookie db");
- goto on_error0;
- }
-
- retval = apr_dbm_open_ex(&f,
- "default",
- chxj_cookie_db_name_create(r, dconf->cookie_db_dir),
- APR_DBM_RWCREATE,
- APR_OS_DEFAULT,
- r->pool);
- if (retval != APR_SUCCESS) {
- ERR(r,
- "could not open dbm (type %s) auth file: %s",
- "default",
- chxj_cookie_db_name_create(r, dconf->cookie_db_dir));
- goto on_error1;
- }
-
- /*
- * create key
- */
- dbmkey.dptr = apr_pstrdup(r->pool, cookie->cookie_id);
- dbmkey.dsize = strlen(dbmkey.dptr);
-
- if (apr_dbm_exists(f, dbmkey)) {
- retval = apr_dbm_fetch(f, dbmkey, &dbmval);
- if (retval != APR_SUCCESS) {
- ERR(r,
- "could not fetch dbm (type %s) auth file: %s", "default",
- chxj_cookie_db_name_create(r, dconf->cookie_db_dir));
- goto on_error2;
+#endif
+#if defined(USE_MEMCACHE_COOKIE)
+ if (IS_COOKIE_STORE_MEMCACHE(dconf->cookie_store_type)) {
+ if (! (load_string = chxj_load_cookie_memcache(r, dconf, cookie->cookie_id))) {
+ ERR(r, "failed: chxj_load_cookie_memcache() cookie_id:[%s]", cookie_id);
+ goto on_error0;
+ }
+ done_proc = 1;
}
- load_string = apr_palloc(r->pool, dbmval.dsize+1);
-
- memset(load_string, 0, dbmval.dsize+1);
- memcpy(load_string, dbmval.dptr, dbmval.dsize);
- }
- apr_dbm_close(f);
- chxj_cookie_db_unlock(r, file);
-
#endif
+ if (!done_proc || IS_COOKIE_STORE_DBM(dconf->cookie_store_type)) {
+ if (! (load_string = chxj_load_cookie_dbm(r, dconf, cookie->cookie_id))) {
+ ERR(r, "failed: chxj_load_cookie_dbm() cookie_id:[%s]", cookie_id);
+ goto on_error0;
+ }
+ }
+ }
if (load_string) {
DBG(r, "load_string=[%s]", load_string);
key = tmp_pair;
*val++ = 0;
apr_table_add(load_cookie_table, key, val);
+ DBG(r, "ADD key:[%s] val:[%s]", key, val);
}
tmp_pair = apr_pstrdup(r->pool, pair);
tmp_sem = strchr(tmp_pair, ';');
return cookie;
-#if !defined(USE_MYSQL_COOKIE) && !defined(USE_MEMCACHE_COOKIE)
-on_error2:
- apr_dbm_close(f);
-
-on_error1:
- chxj_cookie_db_unlock(r, file);
-#endif
-
on_error0:
DBG(r, "end chxj_load_cookie()");
}
-#if !defined(USE_MYSQL_COOKIE) && !defined(USE_MEMCACHE_COOKIE)
-apr_file_t*
-chxj_cookie_db_lock(request_rec* r)
-{
- apr_file_t* file;
- apr_status_t rv;
- mod_chxj_config* dconf;
-
- dconf = (mod_chxj_config*)ap_get_module_config(r->per_dir_config, &chxj_module);
-
- rv = apr_file_open(&file,
- chxj_cookie_db_lock_name_create(r, dconf->cookie_db_dir),
- APR_CREATE|APR_WRITE,
- APR_OS_DEFAULT,
- r->pool);
- if (rv != APR_SUCCESS) {
- ERR(r, "cookie lock file open failed.");
- return NULL;
- }
-
- rv = apr_file_lock(file,APR_FLOCK_EXCLUSIVE);
- if (rv != APR_SUCCESS) {
- ERR(r, "cookie lock file open failed.");
- apr_file_close(file);
- return NULL;
- }
-
- return file;
-}
-
void
-chxj_cookie_db_unlock(request_rec* r, apr_file_t* file)
+chxj_delete_cookie(request_rec *r, const char *cookie_id)
{
- apr_status_t rv;
-
- rv = apr_file_unlock(file);
- if (rv != APR_SUCCESS) {
- ERR(r, "cookie lock file open failed.");
- return;
- }
-
- apr_file_close(file);
-}
-#endif
-
-
-void
-chxj_delete_cookie(request_rec* r, char* cookie_id)
-{
-#if !defined(USE_MYSQL_COOKIE) && !defined(USE_MEMCACHE_COOKIE)
- apr_status_t retval;
- apr_file_t *file;
- apr_datum_t dbmkey;
- apr_dbm_t* f;
-#endif
- mod_chxj_config* dconf;
+ int done_proc = 0;
+ mod_chxj_config *dconf;
DBG(r, "start chxj_delete_cookie()");
dconf = ap_get_module_config(r->per_dir_config, &chxj_module);
#if defined(USE_MYSQL_COOKIE)
- if (!chxj_mysql_delete_cookie(r, dconf, cookie_id)) {
- ERR(r, "failed: chxj_mysql_delete_cookie() cookie_id:[%s]", cookie_id);
- goto on_error0;
- }
-
-#elif defined(USE_MEMCACHE_COOKIE)
-
- if (! chxj_memcache_init(r, dconf)) {
- ERR(r, "Cannot create memcache server");
- goto on_error0;
- }
-
- if (! chxj_memcache_delete_cookie(r, dconf, cookie_id)) {
- ERR(r, "cannot store to memcache host:[%s] port:[%d]", dconf->memcache.host, dconf->memcache.port);
- goto on_error0;
- }
-
-#else
-
- file = chxj_cookie_db_lock(r);
- if (! file) {
- ERR(r, "mod_chxj: Can't lock cookie db");
- goto on_error0;
- }
-
- retval = apr_dbm_open_ex(&f,
- "default",
- chxj_cookie_db_name_create(r, dconf->cookie_db_dir),
- APR_DBM_RWCREATE,
- APR_OS_DEFAULT,
- r->pool);
- if (retval != APR_SUCCESS) {
- ERR(r,
- "could not open dbm (type %s) auth file: %s",
- "default",
- chxj_cookie_db_name_create(r,dconf->cookie_db_dir));
- goto on_error1;
- }
-
- /*
- * create key
- */
- dbmkey.dptr = apr_pstrdup(r->pool, cookie_id);
- dbmkey.dsize = strlen(dbmkey.dptr);
- if (apr_dbm_exists(f, dbmkey)) {
- apr_dbm_delete(f, dbmkey);
+ if (IS_COOKIE_STORE_MYSQL(dconf->cookie_store_type)) {
+ if (! chxj_delete_cookie_mysql(r, dconf, cookie_id)) {
+ ERR(r, "failed: chxj_delete_cookie_mysql() cookie_id:[%s]", cookie_id);
+ DBG(r, "end chxj_delete_cookie()");
+ return;
+ }
+ done_proc = 1;
}
- apr_dbm_close(f);
- chxj_cookie_db_unlock(r, file);
#endif
- DBG(r, "end chxj_delete_cookie()");
-
- return;
-
-#if !defined (USE_MYSQL_COOKIE) && !defined(USE_MEMCACHE_COOKIE)
-on_error1:
- chxj_cookie_db_unlock(r, file);
-#endif
-
-on_error0:
- return;
-
-}
-
-
-#if !defined(USE_MYSQL_COOKIE) && !defined(USE_MEMCACHE_COOKIE)
-char*
-chxj_cookie_db_name_create(request_rec* r, const char* dir)
-{
- char* dst;
-
- if (!dir) {
- dst = apr_pstrdup(r->pool, DEFAULT_COOKIE_DB_DIR);
- }
- else {
- dst = apr_pstrdup(r->pool, dir);
- }
-
- if (dst[strlen(dst)-1] != '/') {
- dst = apr_pstrcat(r->pool, dst, "/", COOKIE_DB_NAME, NULL);
+#if defined(USE_MEMCACHE_COOKIE)
+ if (IS_COOKIE_STORE_MEMCACHE(dconf->cookie_store_type)) {
+ if (! chxj_delete_cookie_memcache(r, dconf, cookie_id)) {
+ ERR(r, "failed: chxj_delete_cookie_memcache() cookie_id:[%s]", cookie_id);
+ DBG(r, "end chxj_delete_cookie()");
+ return;
+ }
+ done_proc = 1;
}
- else {
- dst = apr_pstrcat(r->pool, dst, COOKIE_DB_NAME, NULL);
+#endif
+ if (!done_proc || IS_COOKIE_STORE_DBM(dconf->cookie_store_type)) {
+ if (! chxj_delete_cookie_dbm(r, dconf, cookie_id)) {
+ ERR(r, "failed: chxj_delete_cookie_dbm() cookie_id:[%s]", cookie_id);
+ DBG(r, "end chxj_delete_cookie()");
+ return;
+ }
}
- return dst;
+ DBG(r, "end chxj_delete_cookie()");
}
-char*
-chxj_cookie_db_lock_name_create(request_rec* r, const char* dir)
-{
- char* dst;
- DBG(r, "start chxj_cookie_db_lock_name_create()");
-
- if (!dir) {
- DBG(r, " ");
- dst = apr_pstrdup(r->pool, DEFAULT_COOKIE_DB_DIR);
- DBG(r, " ");
- }
- else {
- dst = apr_pstrdup(r->pool, dir);
- DBG(r, " ");
- }
- DBG(r, "dst[strlen(dst)-1]=[%c]", dst[strlen(dst)-1]);
- if (dst[strlen(dst)-1] != '/') {
- dst = apr_pstrcat(r->pool, dst, "/", COOKIE_DB_LOCK_NAME, NULL);
- }
- else {
- dst = apr_pstrcat(r->pool, dst, COOKIE_DB_LOCK_NAME, NULL);
- }
- DBG(r, "end chxj_cookie_db_lock_name_create()");
- return dst;
-}
-#endif
/*
*
*/
void
chxj_save_cookie_expire(request_rec* r, cookie_t* cookie)
{
+ int done_proc = 0;
mod_chxj_config *dconf;
-#if !defined(USE_MYSQL_COOKIE) && !defined(USE_MEMCACHE_COOKIE)
- apr_status_t retval;
- char *store_string;
- apr_file_t *file;
- apr_datum_t dbmkey;
- apr_datum_t dbmval;
- apr_dbm_t* f;
-#endif
DBG(r, "start chxj_save_cookie_expire()");
if (!cookie) {
}
#if defined(USE_MYSQL_COOKIE)
- if (! chxj_open_mysql_handle(r, dconf)) {
- ERR(r, "Cannot open mysql connection");
- DBG(r, "end chxj_save_cookie_expire()");
- return;
- }
-
- if (!chxj_mysql_exist_cookie_table_expire(r, dconf)) {
- DBG(r, "not found cookie table:[%s_expire]", dconf->mysql.tablename);
- if (!chxj_mysql_create_cookie_expire_table(r, dconf)) {
- ERR(r, "cannot create cookie table:[%s_expire]", dconf->mysql.tablename);
+ if (IS_COOKIE_STORE_MYSQL(dconf->cookie_store_type)) {
+ if (! chxj_save_cookie_expire_mysql(r, dconf, cookie->cookie_id)) {
+ ERR(r, "failed: chxj_save_cookie_expire_mysql() cookie_id:[%s]", cookie->cookie_id);
DBG(r, "end chxj_save_cookie_expire()");
return;
}
+ done_proc = 1;
}
- if (! chxj_mysql_insert_or_update_cookie_expire(r, dconf, cookie->cookie_id)) {
- ERR(r, "cannot create cookie table:[%s_expire]", dconf->mysql.tablename);
- DBG(r, "end chxj_save_cookie_expire()");
- return;
- }
-
- /* *NEED NOT* close database. */
- /* chxj_close_mysql_handle(); */
-#elif defined(USE_MEMCACHE_COOKIE)
-
- if (! chxj_memcache_init(r, dconf)) {
- ERR(r, "Cannot create memcache server");
- return;
- }
-
- if (! chxj_memcache_reset_cookie(r, dconf, cookie->cookie_id)) {
- ERR(r, "cannot store to memcache host:[%s] port:[%d]", dconf->memcache.host, dconf->memcache.port);
- return;
- }
-
-#else
- file = chxj_cookie_expire_db_lock(r);
- if (! file) {
- ERR(r, "mod_chxj: Can't lock cookie db");
- return;
- }
-
- DBG(r, " ");
-
- retval = apr_dbm_open_ex(&f,
- "default",
- chxj_cookie_expire_db_name_create(r, dconf->cookie_db_dir),
- APR_DBM_RWCREATE,
- APR_OS_DEFAULT,
- r->pool);
- if (retval != APR_SUCCESS) {
- ERR(r, "could not open dbm (type %s) auth file: %s",
- "default",
- chxj_cookie_expire_db_name_create(r,dconf->cookie_db_dir));
- chxj_cookie_expire_db_unlock(r, file);
- return;
- }
- /*
- * create key
- */
-
- dbmkey.dptr = cookie->cookie_id;
- dbmkey.dsize = strlen(cookie->cookie_id);
-
- /*
- * create val
- */
-
- store_string = apr_psprintf(r->pool, "%d", (int)time(NULL));
- dbmval.dptr = store_string;
- dbmval.dsize = strlen(store_string);
-
- /*
- * store to db
- */
- retval = apr_dbm_store(f, dbmkey, dbmval);
- if (retval != APR_SUCCESS) {
- ERR(r, "Cannot store Cookie data to DBM file `%s'",
- chxj_cookie_db_name_create(r, dconf->cookie_db_dir));
- }
-
-
- apr_dbm_close(f);
- chxj_cookie_expire_db_unlock(r, file);
#endif
-
- DBG(r, "end chxj_save_cookie_expire()");
-}
-
-
-#if !defined(USE_MYSQL_COOKIE) && !defined(USE_MEMCACHE_COOKIE)
-char*
-chxj_cookie_expire_db_name_create(request_rec* r, const char* dir)
-{
- char* dst;
-
- if (!dir) {
- dst = apr_pstrdup(r->pool, DEFAULT_COOKIE_DB_DIR);
- }
- else {
- dst = apr_pstrdup(r->pool, dir);
- }
-
- if (dst[strlen(dst)-1] != '/') {
- dst = apr_pstrcat(r->pool, dst, "/", COOKIE_EXPIRE_DB_NAME, NULL);
- }
- else {
- dst = apr_pstrcat(r->pool, dst, COOKIE_EXPIRE_DB_NAME, NULL);
- }
-
- return dst;
-}
-
-
-char*
-chxj_cookie_expire_db_lock_name_create(request_rec* r, const char* dir)
-{
- char* dst;
-
- if (!dir) {
- dst = apr_pstrdup(r->pool, DEFAULT_COOKIE_DB_DIR);
- }
- else {
- dst = apr_pstrdup(r->pool, dir);
- }
- if (dst[strlen(dst)-1] != '/') {
- dst = apr_pstrcat(r->pool, dst, "/", COOKIE_EXPIRE_DB_LOCK_NAME, NULL);
- }
- else {
- dst = apr_pstrcat(r->pool, dst, COOKIE_EXPIRE_DB_LOCK_NAME, NULL);
- }
-
- return dst;
-}
-
-
-apr_file_t*
-chxj_cookie_expire_db_lock(request_rec* r)
-{
- apr_file_t* file;
- apr_status_t rv;
- mod_chxj_config* dconf;
-
- dconf = (mod_chxj_config*)ap_get_module_config(r->per_dir_config, &chxj_module);
-
- rv = apr_file_open(&file,
- chxj_cookie_expire_db_lock_name_create(r, dconf->cookie_db_dir),
- APR_CREATE|APR_WRITE,
- APR_OS_DEFAULT,
- r->pool);
- if (rv != APR_SUCCESS) {
- ERR(r, "cookie lock file open failed.");
- return NULL;
+#if defined(USE_MEMCACHE_COOKIE)
+ if (IS_COOKIE_STORE_MEMCACHE(dconf->cookie_store_type)) {
+ if (! chxj_save_cookie_expire_memcache(r, dconf, cookie->cookie_id)) {
+ ERR(r, "failed: chxj_save_cookie_expire_memcache() cookie_id:[%s]", cookie->cookie_id);
+ DBG(r, "end chxj_save_cookie_expire()");
+ return;
+ }
+ done_proc = 1;
}
-
- rv = apr_file_lock(file,APR_FLOCK_EXCLUSIVE);
- if (rv != APR_SUCCESS) {
- ERR(r, "cookie lock file open failed.");
- apr_file_close(file);
- return NULL;
+#endif
+ if (!done_proc || IS_COOKIE_STORE_DBM(dconf->cookie_store_type)) {
+ if (! chxj_save_cookie_expire_dbm(r, dconf, cookie->cookie_id)) {
+ ERR(r, "failed: chxj_save_cookie_expire_dbm() cookie_id:[%s]", cookie->cookie_id);
+ DBG(r, "end chxj_save_cookie_expire()");
+ return;
+ }
}
- return file;
+ DBG(r, "end chxj_save_cookie_expire()");
}
-void
-chxj_cookie_expire_db_unlock(request_rec* r, apr_file_t* file)
-{
- apr_status_t rv;
-
- rv = apr_file_unlock(file);
- if (rv != APR_SUCCESS) {
- ERR(r, "cookie lock file open failed.");
- return;
- }
-
- apr_file_close(file);
-}
-#endif
-
void
chxj_delete_cookie_expire(request_rec* r, char* cookie_id)
{
-#if !defined(USE_MYSQL_COOKIE) && !defined(USE_MEMCACHE_COOKIE)
- apr_status_t retval;
- apr_datum_t dbmkey;
- apr_dbm_t* f;
- apr_file_t* file;
-#endif
+ int done_proc = 0;
mod_chxj_config* dconf;
DBG(r, "start chxj_delete_cookie_expire()");
dconf = ap_get_module_config(r->per_dir_config, &chxj_module);
#if defined(USE_MYSQL_COOKIE)
- if (!chxj_mysql_delete_cookie_expire(r, dconf, cookie_id)) {
- ERR(r, "failed: chxj_mysql_delete_cookie() cookie_id:[%s]", cookie_id);
- goto on_error0;
- }
-#elif defined(USE_MEMCACHE_COOKIE)
-
- /* nothing */
- DBG(r, "nothing: cookie_id:[%s]", cookie_id);
-
-#else
- file = chxj_cookie_expire_db_lock(r);
- if (! file) {
- ERR(r, "mod_chxj: Can't lock cookie db");
- goto on_error0;
- }
- dconf = ap_get_module_config(r->per_dir_config, &chxj_module);
-
- retval = apr_dbm_open_ex(&f,
- "default",
- chxj_cookie_expire_db_name_create(r, dconf->cookie_db_dir),
- APR_DBM_RWCREATE,
- APR_OS_DEFAULT,
- r->pool);
- if (retval != APR_SUCCESS) {
- ERR(r,
- "could not open dbm (type %s) auth file: %s",
- "default",
- chxj_cookie_expire_db_name_create(r,dconf->cookie_db_dir));
- goto on_error1;
+ if (IS_COOKIE_STORE_MYSQL(dconf->cookie_store_type)) {
+ if (! chxj_delete_cookie_expire_mysql(r, dconf, cookie_id)) {
+ ERR(r, "failed: chxj_delete_cookie_expire_mysql() cookie_id:[%s]", cookie_id);
+ return;
+ }
+ done_proc = 1;
}
-
- /*
- * create key
- */
- dbmkey.dptr = apr_pstrdup(r->pool, cookie_id);
- dbmkey.dsize = strlen(dbmkey.dptr);
- if (apr_dbm_exists(f, dbmkey)) {
- apr_dbm_delete(f, dbmkey);
+#endif
+#if defined(USE_MEMCACHE_COOKIE)
+ if (IS_COOKIE_STORE_MEMCACHE(dconf->cookie_store_type)) {
+ if (!chxj_delete_cookie_expire_memcache(r, dconf, cookie_id)) {
+ ERR(r, "failed: chxj_delete_cookie_expire_memcache() cookie_id:[%s]", cookie_id);
+ return;
+ }
+ done_proc = 1;
}
- apr_dbm_close(f);
- chxj_cookie_expire_db_unlock(r, file);
#endif
+ if (!done_proc || IS_COOKIE_STORE_DBM(dconf->cookie_store_type)) {
+ if (!chxj_delete_cookie_expire_dbm(r, dconf, cookie_id)) {
+ ERR(r, "failed: chxj_delete_cookie_expire_dbm() cookie_id:[%s]", cookie_id);
+ return;
+ }
+ }
DBG(r, "end chxj_delete_cookie_expire()");
return;
-
-#if !defined(USE_MYSQL_COOKIE) && !defined(USE_MEMCACHE_COOKIE)
-on_error1:
- chxj_cookie_expire_db_unlock(r, file);
-#endif
-
-#if !defined(USE_MEMCACHE_COOKIE)
-on_error0:
-#endif
- return;
-
}
void
chxj_cookie_expire_gc(request_rec* r)
{
-#if !defined(USE_MYSQL_COOKIE) && !defined(USE_MEMCACHE_COOKIE)
- apr_status_t retval;
- apr_datum_t dbmkey;
- apr_datum_t dbmval;
- apr_dbm_t* f;
- apr_file_t* file;
- time_t now_time;
-#endif
mod_chxj_config *dconf;
+ int done_proc = 0;
DBG(r, "start chxj_cookie_expire_gc()");
dconf = ap_get_module_config(r->per_dir_config, &chxj_module);
#if defined(USE_MYSQL_COOKIE)
- if (!chxj_mysql_delete_expired_cookie(r, dconf)) {
- ERR(r, "failed chxj_mysql_delete_expired_cookie()");
- return;
- }
-
-#elif defined(USE_MEMCACHE_COOKIE)
-
- /* nothing */
- DBG(r, "nothing:");
-
-#else
- file = chxj_cookie_expire_db_lock(r);
- if (! file) {
- ERR(r, "mod_chxj: Can't lock cookie db");
- goto on_error0;
- }
-
- retval = apr_dbm_open_ex(&f,
- "default",
- chxj_cookie_expire_db_name_create(r, dconf->cookie_db_dir),
- APR_DBM_RWCREATE,
- APR_OS_DEFAULT,
- r->pool);
- if (retval != APR_SUCCESS) {
- ERR(r,
- "could not open dbm (type %s) auth file: %s",
- "default",
- chxj_cookie_expire_db_name_create(r,dconf->cookie_db_dir));
- goto on_error1;
- }
-
- /*
- * create key
- */
- memset(&dbmkey, 0, sizeof(apr_datum_t));
-
- now_time = time(NULL);
-
- retval = apr_dbm_firstkey(f, &dbmkey);
- if (retval == APR_SUCCESS) {
- DBG(r, "firstkey=[%.*s]", (int)dbmkey.dsize, dbmkey.dptr);
- do {
- char* tmp;
- char* old_cookie_id;
- int val_time;
- int cmp_time;
-
- retval = apr_dbm_fetch(f, dbmkey, &dbmval);
- if (retval != APR_SUCCESS) {
- break;
- }
- tmp = apr_palloc(r->pool, dbmval.dsize+1);
- memset(tmp, 0, dbmval.dsize+1);
- memcpy(tmp, dbmval.dptr, dbmval.dsize);
-
-
- val_time = atoi(tmp);
-
- if (dconf->cookie_timeout == 0)
- cmp_time = now_time - DEFAULT_COOKIE_TIMEOUT;
- else
- cmp_time = now_time - dconf->cookie_timeout;
-
- DBG(r, "dconf->cookie_timeout=[%d]", (int)dconf->cookie_timeout);
- DBG(r, "key=[%.*s] cmp_time=[%d] val_time=[%d]", (int)dbmkey.dsize, dbmkey.dptr, cmp_time, val_time);
- if (cmp_time >= val_time) {
- apr_dbm_delete(f, dbmkey);
-
- old_cookie_id = apr_palloc(r->pool, dbmkey.dsize+1);
- memset(old_cookie_id, 0, dbmkey.dsize+1);
- memcpy(old_cookie_id, dbmkey.dptr, dbmkey.dsize);
-
- chxj_delete_cookie(r,old_cookie_id);
- DBG(r, "detect timeout cookie [%s]", old_cookie_id);
- }
-
- retval = apr_dbm_nextkey(f, &dbmkey);
- } while(retval == APR_SUCCESS && dbmkey.dptr != NULL);
- }
-
- apr_dbm_close(f);
- chxj_cookie_expire_db_unlock(r, file);
+ if (IS_COOKIE_STORE_MYSQL(dconf->cookie_store_type)) {
+ if (! chxj_cookie_expire_gc_mysql(r, dconf)) {
+ ERR(r, "failed: chxj_cookie_expire_gc_mysql()");
+ return;
+ }
+ done_proc = 1;
+ }
#endif
-
- DBG(r, "end chxj_cookie_expire_gc()");
-
- return;
-
-#if !defined(USE_MYSQL_COOKIE) && !defined(USE_MEMCACHE_COOKIE)
-on_error1:
- chxj_cookie_expire_db_unlock(r, file);
-on_error0:
+#if defined(USE_MEMCACHE_COOKIE)
+ if (IS_COOKIE_STORE_MEMCACHE(dconf->cookie_store_type)) {
+ if (! chxj_cookie_expire_gc_memcache(r, dconf)) {
+ ERR(r, "failed: chxj_cookie_expire_gc_memcache()");
+ return;
+ }
+ done_proc = 1;
+ }
#endif
-
- return;
-
+ if (!done_proc) {
+ if (! chxj_cookie_expire_gc_dbm(r, dconf)) {
+ ERR(r, "failed: chxj_cookie_expire_gc_dbm()");
+ return;
+ }
+ }
+ DBG(r, "end chxj_cookie_expire_gc()");
}
apr_time_t
--- /dev/null
+/*
+ * Copyright (C) 2005-2008 Atsushi Konno All rights reserved.
+ * Copyright (C) 2005 QSDN,Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "mod_chxj.h"
+#include "chxj_cookie.h"
+#include "chxj_dbm.h"
+#include "chxj_url_encode.h"
+#include "chxj_apply_convrule.h"
+#include "chxj_str_util.h"
+
+#include "ap_release.h"
+
+#include "apu.h"
+#include "apr_uuid.h"
+#include "apr_md5.h"
+#include "apr_base64.h"
+#include "apr_uri.h"
+
+#include <unistd.h>
+
+int
+chxj_save_cookie_dbm(request_rec *r, mod_chxj_config *m, const char *cookie_id, const char *store_string)
+{
+ apr_status_t retval;
+ apr_datum_t dbmkey;
+ apr_datum_t dbmval;
+ apr_dbm_t *f;
+ apr_file_t *file;
+
+ DBG(r, "start chxj_save_cookie_dbm() cookie_id:[%s]", cookie_id);
+
+ file = chxj_cookie_db_lock(r);
+ if (! file) {
+ ERR(r, "mod_chxj: Can't lock cookie db");
+ DBG(r, "end chxj_save_cookie_dbm() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+
+ retval = apr_dbm_open_ex(&f,
+ "default",
+ chxj_cookie_db_name_create(r, m->cookie_db_dir),
+ APR_DBM_RWCREATE,
+ APR_OS_DEFAULT,
+ r->pool);
+ if (retval != APR_SUCCESS) {
+ ERR(r, "could not open dbm (type %s) auth file: %s",
+ "default",
+ chxj_cookie_db_name_create(r,m->cookie_db_dir));
+ chxj_cookie_db_unlock(r, file);
+ DBG(r, "end chxj_save_cookie_dbm() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+
+
+ /*
+ * create key
+ */
+
+ dbmkey.dptr = apr_pstrdup(r->pool, cookie_id);
+ dbmkey.dsize = strlen(cookie_id);
+ dbmval.dptr = apr_pstrdup(r->pool, store_string);
+ dbmval.dsize = strlen(store_string);
+
+ /*
+ * store to db
+ */
+ retval = apr_dbm_store(f, dbmkey, dbmval);
+ if (retval != APR_SUCCESS) {
+ ERR(r, "Cannot store Cookie data to DBM file `%s'",
+ chxj_cookie_db_name_create(r, m->cookie_db_dir));
+ apr_dbm_close(f);
+ chxj_cookie_db_unlock(r, file);
+ DBG(r, "end chxj_save_cookie_dbm() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+
+ apr_dbm_close(f);
+ chxj_cookie_db_unlock(r, file);
+ DBG(r, "end chxj_save_cookie_dbm() cookie_id:[%s]", cookie_id);
+ return CHXJ_TRUE;
+}
+
+
+void
+chxj_cookie_db_unlock(request_rec *r, apr_file_t *file)
+{
+ apr_status_t rv;
+
+ rv = apr_file_unlock(file);
+ if (rv != APR_SUCCESS) {
+ ERR(r, "cookie lock file open failed.");
+ return;
+ }
+
+ apr_file_close(file);
+}
+
+
+apr_file_t *
+chxj_cookie_db_lock(request_rec *r)
+{
+ apr_file_t *file;
+ apr_status_t rv;
+ mod_chxj_config *dconf;
+
+ dconf = (mod_chxj_config*)ap_get_module_config(r->per_dir_config, &chxj_module);
+
+ rv = apr_file_open(&file,
+ chxj_cookie_db_lock_name_create(r, dconf->cookie_db_dir),
+ APR_CREATE|APR_WRITE,
+ APR_OS_DEFAULT,
+ r->pool);
+ if (rv != APR_SUCCESS) {
+ ERR(r, "cookie lock file open failed.");
+ return NULL;
+ }
+
+ rv = apr_file_lock(file,APR_FLOCK_EXCLUSIVE);
+ if (rv != APR_SUCCESS) {
+ ERR(r, "cookie lock file open failed.");
+ apr_file_close(file);
+ return NULL;
+ }
+
+ return file;
+}
+
+
+char *
+chxj_cookie_db_name_create(request_rec *r, const char *dir)
+{
+ char *dst;
+
+ if (!dir) {
+ dst = apr_pstrdup(r->pool, DEFAULT_COOKIE_DB_DIR);
+ }
+ else {
+ dst = apr_pstrdup(r->pool, dir);
+ }
+
+ if (dst[strlen(dst)-1] != '/') {
+ dst = apr_pstrcat(r->pool, dst, "/", COOKIE_DB_NAME, NULL);
+ }
+ else {
+ dst = apr_pstrcat(r->pool, dst, COOKIE_DB_NAME, NULL);
+ }
+
+ return dst;
+}
+
+
+char *
+chxj_cookie_db_lock_name_create(request_rec *r, const char *dir)
+{
+ char *dst;
+ DBG(r, "start chxj_cookie_db_lock_name_create()");
+
+ if (!dir) {
+ DBG(r, " ");
+ dst = apr_pstrdup(r->pool, DEFAULT_COOKIE_DB_DIR);
+ DBG(r, " ");
+ }
+ else {
+ dst = apr_pstrdup(r->pool, dir);
+ DBG(r, " ");
+ }
+ DBG(r, "dst[strlen(dst)-1]=[%c]", dst[strlen(dst)-1]);
+ if (dst[strlen(dst)-1] != '/') {
+ dst = apr_pstrcat(r->pool, dst, "/", COOKIE_DB_LOCK_NAME, NULL);
+ }
+ else {
+ dst = apr_pstrcat(r->pool, dst, COOKIE_DB_LOCK_NAME, NULL);
+ }
+ DBG(r, "end chxj_cookie_db_lock_name_create()");
+ return dst;
+}
+
+
+
+char *
+chxj_cookie_expire_db_name_create(request_rec *r, const char *dir)
+{
+ char *dst;
+
+ if (!dir) {
+ dst = apr_pstrdup(r->pool, DEFAULT_COOKIE_DB_DIR);
+ }
+ else {
+ dst = apr_pstrdup(r->pool, dir);
+ }
+
+ if (dst[strlen(dst)-1] != '/') {
+ dst = apr_pstrcat(r->pool, dst, "/", COOKIE_EXPIRE_DB_NAME, NULL);
+ }
+ else {
+ dst = apr_pstrcat(r->pool, dst, COOKIE_EXPIRE_DB_NAME, NULL);
+ }
+
+ return dst;
+}
+
+
+char *
+chxj_cookie_expire_db_lock_name_create(request_rec *r, const char *dir)
+{
+ char *dst;
+
+ if (!dir) {
+ dst = apr_pstrdup(r->pool, DEFAULT_COOKIE_DB_DIR);
+ }
+ else {
+ dst = apr_pstrdup(r->pool, dir);
+ }
+ if (dst[strlen(dst)-1] != '/') {
+ dst = apr_pstrcat(r->pool, dst, "/", COOKIE_EXPIRE_DB_LOCK_NAME, NULL);
+ }
+ else {
+ dst = apr_pstrcat(r->pool, dst, COOKIE_EXPIRE_DB_LOCK_NAME, NULL);
+ }
+
+ return dst;
+}
+
+
+apr_file_t *
+chxj_cookie_expire_db_lock(request_rec *r)
+{
+ apr_file_t *file;
+ apr_status_t rv;
+ mod_chxj_config *dconf;
+
+ dconf = (mod_chxj_config *)ap_get_module_config(r->per_dir_config, &chxj_module);
+
+ rv = apr_file_open(&file,
+ chxj_cookie_expire_db_lock_name_create(r, dconf->cookie_db_dir),
+ APR_CREATE|APR_WRITE,
+ APR_OS_DEFAULT,
+ r->pool);
+ if (rv != APR_SUCCESS) {
+ ERR(r, "cookie lock file open failed.");
+ return NULL;
+ }
+
+ rv = apr_file_lock(file,APR_FLOCK_EXCLUSIVE);
+ if (rv != APR_SUCCESS) {
+ ERR(r, "cookie lock file open failed.");
+ apr_file_close(file);
+ return NULL;
+ }
+
+ return file;
+}
+
+
+void
+chxj_cookie_expire_db_unlock(request_rec *r, apr_file_t *file)
+{
+ apr_status_t rv;
+
+ rv = apr_file_unlock(file);
+ if (rv != APR_SUCCESS) {
+ ERR(r, "cookie lock file open failed.");
+ return;
+ }
+
+ apr_file_close(file);
+}
+
+int
+chxj_update_cookie_dbm(request_rec *r, mod_chxj_config *m, const char *cookie_id, const char *store_string)
+{
+ apr_dbm_t *f;
+ apr_file_t *file;
+ apr_datum_t dbmkey;
+ apr_datum_t dbmval;
+ apr_status_t retval;
+
+ DBG(r, "start chxj_update_cookie_dbm() cookie_id:[%s]", cookie_id);
+
+ file = chxj_cookie_db_lock(r);
+ if (! file) {
+ ERR(r, "mod_chxj: Can't lock cookie db");
+ DBG(r, "end chxj_update_cookie_dbm() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+
+ retval = apr_dbm_open_ex(&f,
+ "default",
+ chxj_cookie_db_name_create(r, m->cookie_db_dir),
+ APR_DBM_RWCREATE,
+ APR_OS_DEFAULT,
+ r->pool);
+ if (retval != APR_SUCCESS) {
+ ERR(r, "could not open dbm (type %s) auth file: %s",
+ "default",
+ chxj_cookie_db_name_create(r,m->cookie_db_dir));
+ chxj_cookie_db_unlock(r, file);
+ DBG(r, "end chxj_update_cookie_dbm() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+
+
+ /*
+ * create key
+ */
+
+ dbmkey.dptr = apr_pstrdup(r->pool, cookie_id);
+ dbmkey.dsize = strlen(cookie_id);
+
+ /*
+ * create val
+ */
+ dbmval.dptr = apr_pstrdup(r->pool, store_string);
+ dbmval.dsize = strlen(store_string);
+
+ /*
+ * store to db
+ */
+ retval = apr_dbm_store(f, dbmkey, dbmval);
+ if (retval != APR_SUCCESS) {
+ ERR(r, "Cannot store Cookie data to DBM file `%s'",
+ chxj_cookie_db_name_create(r, m->cookie_db_dir));
+ apr_dbm_close(f);
+ chxj_cookie_db_unlock(r, file);
+ DBG(r, "end chxj_update_cookie_dbm() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+ apr_dbm_close(f);
+ chxj_cookie_db_unlock(r, file);
+ DBG(r, "end chxj_update_cookie_dbm() cookie_id:[%s]", cookie_id);
+ return CHXJ_TRUE;
+}
+
+
+char *
+chxj_load_cookie_dbm(request_rec *r, mod_chxj_config *m, const char *cookie_id)
+{
+ char *load_string = NULL;
+ apr_status_t retval;
+ apr_dbm_t *f;
+ apr_file_t *file;
+ apr_datum_t dbmval;
+ apr_datum_t dbmkey;
+
+ DBG(r, "start chxj_load_cookie_dbm() cookie_id:[%s]", cookie_id);
+ file = chxj_cookie_db_lock(r);
+ if (! file) {
+ ERR(r, "mod_chxj: Can't lock cookie db");
+ DBG(r, "end chxj_load_cookie_dbm() cookie_id:[%s]", cookie_id);
+ return NULL;
+ }
+
+ retval = apr_dbm_open_ex(&f,
+ "default",
+ chxj_cookie_db_name_create(r, m->cookie_db_dir),
+ APR_DBM_RWCREATE,
+ APR_OS_DEFAULT,
+ r->pool);
+ if (retval != APR_SUCCESS) {
+ ERR(r,
+ "could not open dbm (type %s) auth file: %s",
+ "default",
+ chxj_cookie_db_name_create(r, m->cookie_db_dir));
+ chxj_cookie_db_unlock(r, file);
+ DBG(r, "end chxj_load_cookie_dbm() cookie_id:[%s]", cookie_id);
+ return NULL;
+ }
+
+ /*
+ * create key
+ */
+ dbmkey.dptr = apr_pstrdup(r->pool, cookie_id);
+ dbmkey.dsize = strlen(dbmkey.dptr);
+
+ if (apr_dbm_exists(f, dbmkey)) {
+ retval = apr_dbm_fetch(f, dbmkey, &dbmval);
+ if (retval != APR_SUCCESS) {
+ ERR(r,
+ "could not fetch dbm (type %s) auth file: %s", "default",
+ chxj_cookie_db_name_create(r, m->cookie_db_dir));
+ apr_dbm_close(f);
+ chxj_cookie_db_unlock(r, file);
+ DBG(r, "end chxj_load_cookie_dbm() cookie_id:[%s]", cookie_id);
+ return NULL;
+ }
+ load_string = apr_palloc(r->pool, dbmval.dsize+1);
+
+ memset(load_string, 0, dbmval.dsize+1);
+ memcpy(load_string, dbmval.dptr, dbmval.dsize);
+ }
+ apr_dbm_close(f);
+ chxj_cookie_db_unlock(r, file);
+ DBG(r, "end chxj_load_cookie_dbm() cookie_id:[%s]", cookie_id);
+ return load_string;
+}
+
+
+int
+chxj_delete_cookie_dbm(request_rec *r, mod_chxj_config *m, const char *cookie_id)
+{
+ apr_status_t retval;
+ apr_file_t *file;
+ apr_datum_t dbmkey;
+ apr_dbm_t* f;
+
+ DBG(r, "start chxj_delete_cookie_dbm() cookie_id:[%s]", cookie_id);
+ file = chxj_cookie_db_lock(r);
+ if (! file) {
+ ERR(r, "mod_chxj: Can't lock cookie db");
+ DBG(r, "end chxj_delete_cookie_dbm() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+
+ retval = apr_dbm_open_ex(&f,
+ "default",
+ chxj_cookie_db_name_create(r, m->cookie_db_dir),
+ APR_DBM_RWCREATE,
+ APR_OS_DEFAULT,
+ r->pool);
+ if (retval != APR_SUCCESS) {
+ ERR(r,
+ "could not open dbm (type %s) auth file: %s",
+ "default",
+ chxj_cookie_db_name_create(r,m->cookie_db_dir));
+ chxj_cookie_db_unlock(r, file);
+ DBG(r, "end chxj_delete_cookie_dbm() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+
+ /*
+ * create key
+ */
+ dbmkey.dptr = apr_pstrdup(r->pool, cookie_id);
+ dbmkey.dsize = strlen(dbmkey.dptr);
+ if (apr_dbm_exists(f, dbmkey)) {
+ apr_dbm_delete(f, dbmkey);
+ }
+ apr_dbm_close(f);
+ chxj_cookie_db_unlock(r, file);
+ DBG(r, "end chxj_delete_cookie_dbm() cookie_id:[%s]", cookie_id);
+ return CHXJ_TRUE;
+}
+
+
+int
+chxj_save_cookie_expire_dbm(request_rec *r, mod_chxj_config *m, const char *cookie_id)
+{
+ apr_status_t retval;
+ char *store_string;
+ apr_file_t *file;
+ apr_datum_t dbmkey;
+ apr_datum_t dbmval;
+ apr_dbm_t* f;
+
+ DBG(r, "start chxj_save_cookie_expire_dbm() cookie_id:[%s]", cookie_id);
+ file = chxj_cookie_expire_db_lock(r);
+ if (! file) {
+ ERR(r, "mod_chxj: Can't lock cookie db");
+ DBG(r, "end chxj_save_cookie_expire_dbm() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+
+ DBG(r, " ");
+
+ retval = apr_dbm_open_ex(&f,
+ "default",
+ chxj_cookie_expire_db_name_create(r, m->cookie_db_dir),
+ APR_DBM_RWCREATE,
+ APR_OS_DEFAULT,
+ r->pool);
+ if (retval != APR_SUCCESS) {
+ ERR(r, "could not open dbm (type %s) auth file: %s",
+ "default",
+ chxj_cookie_expire_db_name_create(r,m->cookie_db_dir));
+ chxj_cookie_expire_db_unlock(r, file);
+ DBG(r, "end chxj_save_cookie_expire_dbm() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+ /*
+ * create key
+ */
+
+ dbmkey.dptr = apr_pstrdup(r->pool, cookie_id);
+ dbmkey.dsize = strlen(cookie_id);
+
+ /*
+ * create val
+ */
+
+ store_string = apr_psprintf(r->pool, "%d", (int)time(NULL));
+ dbmval.dptr = store_string;
+ dbmval.dsize = strlen(store_string);
+
+ /*
+ * store to db
+ */
+ retval = apr_dbm_store(f, dbmkey, dbmval);
+ if (retval != APR_SUCCESS) {
+ ERR(r, "Cannot store Cookie data to DBM file `%s'",
+ chxj_cookie_db_name_create(r, m->cookie_db_dir));
+ DBG(r, "end chxj_save_cookie_expire_dbm() cookie_id:[%s]", cookie_id);
+ apr_dbm_close(f);
+ chxj_cookie_expire_db_unlock(r, file);
+ return CHXJ_FALSE;
+ }
+
+
+ apr_dbm_close(f);
+ chxj_cookie_expire_db_unlock(r, file);
+ DBG(r, "end chxj_save_cookie_expire_dbm() cookie_id:[%s]", cookie_id);
+
+ return CHXJ_TRUE;
+}
+
+
+int
+chxj_delete_cookie_expire_dbm(request_rec *r, mod_chxj_config *m, const char *cookie_id)
+{
+ apr_status_t retval;
+ apr_datum_t dbmkey;
+ apr_dbm_t* f;
+ apr_file_t* file;
+
+ DBG(r, "start chxj_delete_cookie_expire_dbm() cookie_id:[%s]", cookie_id);
+ file = chxj_cookie_expire_db_lock(r);
+ if (! file) {
+ ERR(r, "mod_chxj: Can't lock cookie db");
+ DBG(r, "end chxj_delete_cookie_expire_dbm() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+ retval = apr_dbm_open_ex(&f,
+ "default",
+ chxj_cookie_expire_db_name_create(r, m->cookie_db_dir),
+ APR_DBM_RWCREATE,
+ APR_OS_DEFAULT,
+ r->pool);
+ if (retval != APR_SUCCESS) {
+ ERR(r,
+ "could not open dbm (type %s) auth file: %s",
+ "default",
+ chxj_cookie_expire_db_name_create(r,m->cookie_db_dir));
+ chxj_cookie_expire_db_unlock(r, file);
+ DBG(r, "end chxj_delete_cookie_expire_dbm() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+
+ /*
+ * * create key
+ * */
+ dbmkey.dptr = apr_pstrdup(r->pool, cookie_id);
+ dbmkey.dsize = strlen(dbmkey.dptr);
+ if (apr_dbm_exists(f, dbmkey)) {
+ apr_dbm_delete(f, dbmkey);
+ }
+ apr_dbm_close(f);
+ chxj_cookie_expire_db_unlock(r, file);
+ DBG(r, "end chxj_delete_cookie_expire_dbm() cookie_id:[%s]", cookie_id);
+
+ return CHXJ_TRUE;
+}
+
+
+int
+chxj_cookie_expire_gc_dbm(request_rec *r, mod_chxj_config *m)
+{
+ apr_status_t retval;
+ apr_datum_t dbmkey;
+ apr_datum_t dbmval;
+ apr_dbm_t* f;
+ apr_file_t* file;
+ time_t now_time;
+
+ DBG(r, "start chxj_cookie_expire_gc_dbm()");
+
+ file = chxj_cookie_expire_db_lock(r);
+ if (! file) {
+ ERR(r, "mod_chxj: Can't lock cookie db");
+ DBG(r, "end chxj_cookie_expire_gc_dbm()");
+ return CHXJ_FALSE;
+ }
+
+ retval = apr_dbm_open_ex(&f,
+ "default",
+ chxj_cookie_expire_db_name_create(r, m->cookie_db_dir),
+ APR_DBM_RWCREATE,
+ APR_OS_DEFAULT,
+ r->pool);
+ if (retval != APR_SUCCESS) {
+ ERR(r,
+ "could not open dbm (type %s) auth file: %s",
+ "default",
+ chxj_cookie_expire_db_name_create(r,m->cookie_db_dir));
+ chxj_cookie_expire_db_unlock(r, file);
+ DBG(r, "end chxj_cookie_expire_gc_dbm()");
+ return CHXJ_FALSE;
+ }
+
+ /*
+ * create key
+ */
+ memset(&dbmkey, 0, sizeof(apr_datum_t));
+
+ now_time = time(NULL);
+
+ retval = apr_dbm_firstkey(f, &dbmkey);
+ if (retval == APR_SUCCESS) {
+ DBG(r, "firstkey=[%.*s]", (int)dbmkey.dsize, dbmkey.dptr);
+ do {
+ char* tmp;
+ char* old_cookie_id;
+ int val_time;
+ int cmp_time;
+
+ retval = apr_dbm_fetch(f, dbmkey, &dbmval);
+ if (retval != APR_SUCCESS) {
+ break;
+ }
+ tmp = apr_palloc(r->pool, dbmval.dsize+1);
+ memset(tmp, 0, dbmval.dsize+1);
+ memcpy(tmp, dbmval.dptr, dbmval.dsize);
+
+
+ val_time = atoi(tmp);
+
+ if (m->cookie_timeout == 0)
+ cmp_time = now_time - DEFAULT_COOKIE_TIMEOUT;
+ else
+ cmp_time = now_time - m->cookie_timeout;
+
+ DBG(r, "m->cookie_timeout=[%d]", (int)m->cookie_timeout);
+ DBG(r, "key=[%.*s] cmp_time=[%d] val_time=[%d]", (int)dbmkey.dsize, dbmkey.dptr, cmp_time, val_time);
+ if (cmp_time >= val_time) {
+ apr_dbm_delete(f, dbmkey);
+
+ old_cookie_id = apr_palloc(r->pool, dbmkey.dsize+1);
+ memset(old_cookie_id, 0, dbmkey.dsize+1);
+ memcpy(old_cookie_id, dbmkey.dptr, dbmkey.dsize);
+
+ chxj_delete_cookie(r,old_cookie_id);
+ DBG(r, "detect timeout cookie [%s]", old_cookie_id);
+ }
+
+ retval = apr_dbm_nextkey(f, &dbmkey);
+ } while(retval == APR_SUCCESS && dbmkey.dptr != NULL);
+ }
+
+ apr_dbm_close(f);
+ chxj_cookie_expire_db_unlock(r, file);
+ DBG(r, "end chxj_cookie_expire_gc_dbm()");
+ return CHXJ_TRUE;
+}
+/*
+ * vim:ts=2 et
+ */
+int
+chxj_save_cookie_memcache(request_rec *r, mod_chxj_config *m, const char *cookie_id, const char *store_string)
+{
+ DBG(r, "start chxj_save_cookie_memcache() cookie_id:[%s]", cookie_id);
+ if (! chxj_memcache_init(r, m)) {
+ ERR(r, "Cannot create memcache server");
+ DBG(r, "end chxj_save_cookie_memcache() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+
+ if (! chxj_memcache_set_cookie(r, m, cookie_id, store_string)) {
+ ERR(r, "cannot store to memcache host:[%s] port:[%d]", m->memcache.host, m->memcache.port);
+ DBG(r, "end chxj_save_cookie_memcache() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+ DBG(r, "stored DATA:[%s]", chxj_memcache_get_cookie(r, m, cookie_id));
+ DBG(r, "end chxj_save_cookie_memcache() cookie_id:[%s]", cookie_id);
+ return CHXJ_TRUE;
+}
+
+
+int
+chxj_update_cookie_memcache(request_rec *r, mod_chxj_config *m, const char *cookie_id, const char *store_string)
+{
+ DBG(r, "start chxj_update_cookie_memcache() cookie_id:[%s]", cookie_id);
+ if (! chxj_memcache_init(r, m)) {
+ ERR(r, "Cannot create memcache server");
+ DBG(r, "end chxj_update_cookie_memcache() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+
+ if (! chxj_memcache_set_cookie(r, m, cookie_id, store_string)) {
+ ERR(r, "cannot store to memcache host:[%s] port:[%d]", m->memcache.host, m->memcache.port);
+ DBG(r, "end chxj_update_cookie_memcache() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+ DBG(r, "end chxj_update_cookie_memcache() cookie_id:[%s]", cookie_id);
+ return CHXJ_TRUE;
+}
+
+
+char *
+chxj_load_cookie_memcache(request_rec *r, mod_chxj_config *m, const char *cookie_id)
+{
+ char *load_string;
+ DBG(r, "start chxj_load_cookie_memcache() cookie_id:[%s]", cookie_id);
+
+ if (! chxj_memcache_init(r, m)) {
+ ERR(r, "Cannot create memcache server");
+ DBG(r, "end chxj_load_cookie_memcache() cookie_id:[%s]", cookie_id);
+ return NULL;
+ }
+
+ if (! (load_string = chxj_memcache_get_cookie(r, m, cookie_id))) {
+ ERR(r, "cannot store to memcache host:[%s] port:[%d]", m->memcache.host, m->memcache.port);
+ DBG(r, "end chxj_load_cookie_memcache() cookie_id:[%s]", cookie_id);
+ return NULL;
+ }
+ DBG(r, "end chxj_load_cookie_memcache() cookie_id:[%s]", cookie_id);
+ return load_string;
+}
+
+
+int
+chxj_delete_cookie_memcache(request_rec *r, mod_chxj_config *m, const char *cookie_id)
+{
+ DBG(r, "start chxj_delete_cookie_memcache() cookie_id:[%s]", cookie_id);
+ if (! chxj_memcache_init(r, m)) {
+ ERR(r, "Cannot create memcache server");
+ DBG(r, "end chxj_delete_cookie_memcache() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+
+ if (! chxj_memcache_delete_cookie(r, m, cookie_id)) {
+ ERR(r, "cannot store to memcache host:[%s] port:[%d]", m->memcache.host, m->memcache.port);
+ DBG(r, "end chxj_delete_cookie_memcache() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+ DBG(r, "end chxj_delete_cookie_memcache() cookie_id:[%s]", cookie_id);
+ return CHXJ_TRUE;
+}
+
+
+int
+chxj_save_cookie_expire_memcache(request_rec *r, mod_chxj_config *m, const char *cookie_id)
+{
+ DBG(r, "start chxj_save_cookie_expire_memcache() cookie_id:[%s]", cookie_id);
+ if (! chxj_memcache_init(r, m)) {
+ ERR(r, "Cannot create memcache server");
+ DBG(r, "end chxj_save_cookie_expire_memcache() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+
+ if (! chxj_memcache_reset_cookie(r, m, cookie_id)) {
+ ERR(r, "cannot store to memcache host:[%s] port:[%d]", m->memcache.host, m->memcache.port);
+ DBG(r, "end chxj_save_cookie_expire_memcache() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+ DBG(r, "end chxj_save_cookie_expire_memcache() cookie_id:[%s]", cookie_id);
+ return CHXJ_TRUE;
+}
+
+
+int
+chxj_delete_cookie_expire_memcache(request_rec *r, mod_chxj_config *m, const char *cookie_id)
+{
+ DBG(r, "start chxj_delete_cookie_expire_memcache() cookie_id:[%s]", cookie_id);
+ /* PASS */
+ DBG(r, "end chxj_delete_cookie_expire_memcache() cookie_id:[%s]", cookie_id);
+ return CHXJ_TRUE;
+}
+
+
+int
+chxj_cookie_expire_gc_memcache(request_rec *r, mod_chxj_config *m)
+{
+ DBG(r, "start chxj_cookie_expire_gc_memcache()");
+ /* PASS */
+ DBG(r, "end chxj_cookie_expire_gc_memcache()");
+ return CHXJ_TRUE;
+}
+
#endif
/*
* vim:ts=2 et
return 1;
}
+
+int
+chxj_save_cookie_mysql(request_rec *r, mod_chxj_config *m, const char *cookie_id, const char *store_string)
+{
+ if (! chxj_open_mysql_handle(r, m)) {
+ ERR(r, "Cannot open mysql connection");
+ return CHXJ_FALSE;
+ }
+
+ if (!chxj_mysql_exist_cookie_table(r, m)) {
+ DBG(r, "not found cookie table:[%s]", m->mysql.tablename);
+ if (!chxj_mysql_create_cookie_table(r, m)) {
+ ERR(r, "cannot create cookie table:[%s]", m->mysql.tablename);
+ return CHXJ_FALSE;
+ }
+ }
+ if (! chxj_mysql_insert_or_update_cookie(r, m, cookie_id, store_string)) {
+ ERR(r, "cannot store to cookie table:[%s]", m->mysql.tablename);
+ return CHXJ_FALSE;
+ }
+
+ /* *NEED NOT* close database. */
+ return CHXJ_TRUE;
+}
+
+int
+chxj_update_cookie_mysql(request_rec *r, mod_chxj_config *m, const char *cookie_id, const char *store_string)
+{
+ DBG(r, "start chxj_update_cookie_mysql() cookie_id:[%s]", cookie_id);
+ if (! chxj_open_mysql_handle(r, m)) {
+ ERR(r, "Cannot open mysql connection");
+ DBG(r, "end chxj_update_cookie_mysql() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+
+ if (!chxj_mysql_exist_cookie_table(r, m)) {
+ DBG(r, "not found cookie table:[%s]", m->mysql.tablename);
+ if (!chxj_mysql_create_cookie_table(r, m)) {
+ ERR(r, "cannot create cookie table:[%s]", m->mysql.tablename);
+ DBG(r, "end chxj_update_cookie_mysql() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+ }
+ if (! chxj_mysql_insert_or_update_cookie(r, m, cookie_id, store_string)) {
+ ERR(r, "cannot create cookie table:[%s]", m->mysql.tablename);
+ DBG(r, "end chxj_update_cookie_mysql() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+
+ /* *NEED NOT* close database. */
+ /* chxj_close_mysql_handle(); */
+ DBG(r, "end chxj_update_cookie_mysql() cookie_id:[%s]", cookie_id);
+ return CHXJ_TRUE;
+}
+
+
+char *
+chxj_load_cookie_mysql(request_rec *r, mod_chxj_config *m, const char *cookie_id)
+{
+ char *load_string;
+
+ DBG(r, "start chxj_load_cookie_mysql() cookie_id:[%s]", cookie_id);
+ if (! chxj_open_mysql_handle(r, m)) {
+ ERR(r, "Cannot open mysql connection");
+ DBG(r, "end chxj_load_cookie_mysql() cookie_id:[%s]", cookie_id);
+ return NULL;
+ }
+
+ if (!chxj_mysql_exist_cookie_table(r, m)) {
+ DBG(r, "not found cookie table:[%s]", m->mysql.tablename);
+ if (!chxj_mysql_create_cookie_table(r, m)) {
+ ERR(r, "cannot create cookie table:[%s]", m->mysql.tablename);
+ DBG(r, "end chxj_load_cookie_mysql() cookie_id:[%s]", cookie_id);
+ return NULL;
+ }
+ }
+ if (!(load_string = chxj_mysql_load_cookie(r, m, cookie_id))) {
+ ERR(r, "not found cookie. cookie_id:[%s]", cookie_id);
+ DBG(r, "end chxj_load_cookie_mysql() cookie_id:[%s]", cookie_id);
+ return NULL;
+ }
+
+ /* *NEED NOT* close database. */
+ /* chxj_close_mysql_handle(); */
+ DBG(r, "end chxj_load_cookie_mysql() cookie_id:[%s]", cookie_id);
+ return load_string;
+}
+
+
+int
+chxj_delete_cookie_mysql(request_rec *r, mod_chxj_config *m, const char *cookie_id)
+{
+ DBG(r, "start chxj_delete_cookie_mysql() cookie_id=[%s]", cookie_id);
+ if (!chxj_mysql_delete_cookie(r, m, cookie_id)) {
+ ERR(r, "failed: chxj_mysql_delete_cookie() cookie_id:[%s]", cookie_id);
+ DBG(r, "end chxj_delete_cookie_mysql() cookie_id=[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+ DBG(r, "end chxj_delete_cookie_mysql() cookie_id=[%s]", cookie_id);
+ return CHXJ_TRUE;
+}
+
+
+int
+chxj_save_cookie_expire_mysql(request_rec *r, mod_chxj_config *m, const char *cookie_id)
+{
+ DBG(r, "start chxj_save_cookie_expire_mysql() cookie_id:[%s]", cookie_id);
+ if (! chxj_open_mysql_handle(r, m)) {
+ ERR(r, "Cannot open mysql connection");
+ DBG(r, "end chxj_save_cookie_expire_mysql()");
+ return CHXJ_FALSE;
+ }
+
+ if (!chxj_mysql_exist_cookie_table_expire(r, m)) {
+ DBG(r, "not found cookie table:[%s_expire]", m->mysql.tablename);
+ if (!chxj_mysql_create_cookie_expire_table(r, m)) {
+ ERR(r, "cannot create cookie table:[%s_expire]", m->mysql.tablename);
+ DBG(r, "end chxj_save_cookie_expire_mysql()");
+ return CHXJ_FALSE;
+ }
+ }
+ if (! chxj_mysql_insert_or_update_cookie_expire(r, m, cookie_id)) {
+ ERR(r, "cannot create cookie table:[%s_expire]", m->mysql.tablename);
+ DBG(r, "end chxj_save_cookie_expire_mysql()");
+ return CHXJ_FALSE;
+ }
+
+ /* *NEED NOT* close database. */
+ /* chxj_close_mysql_handle(); */
+
+ DBG(r, "end chxj_save_cookie_expire_mysql() cookie_id:[%s]", cookie_id);
+ return CHXJ_TRUE;
+}
+
+
+int
+chxj_delete_cookie_expire_mysql(request_rec *r, mod_chxj_config *m, const char *cookie_id)
+{
+ DBG(r, "start chxj_delete_cookie_expire_mysql() cookie_id:[%s]", cookie_id);
+ if (!chxj_mysql_delete_cookie_expire(r, m, cookie_id)) {
+ ERR(r, "failed: chxj_mysql_delete_cookie() cookie_id:[%s]", cookie_id);
+ DBG(r, "end chxj_delete_cookie_expire_mysql() cookie_id:[%s]", cookie_id);
+ return CHXJ_FALSE;
+ }
+ DBG(r, "end chxj_delete_cookie_expire_mysql() cookie_id:[%s]", cookie_id);
+ return CHXJ_TRUE;
+}
+
+
+int
+chxj_cookie_expire_gc_mysql(request_rec *r, mod_chxj_config *m)
+{
+ DBG(r, "start chxj_cookie_expire_gc_mysql()");
+ if (!chxj_mysql_delete_expired_cookie(r, m)) {
+ ERR(r, "failed: chxj_mysql_delete_expired_cookie()");
+ DBG(r, "end chxj_cookie_expire_gc_mysql()");
+ return CHXJ_FALSE;
+ }
+ DBG(r, "end chxj_cookie_expire_gc_mysql()");
+ return CHXJ_TRUE;
+}
#endif
/*
* vim:ts=2 et
#include "chxj_cookie.h"
#include "chxj_url_encode.h"
#include "chxj_str_util.h"
+#if defined(USE_MYSQL_COOKIE)
+# include "chxj_mysql.h"
+#endif
#define CHXJ_VERSION_PREFIX PACKAGE_NAME "/"
conf->server_side_encoding = NULL;
conf->cookie_db_dir = NULL;
conf->cookie_timeout = 0;
+ conf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
+ conf->cookie_lazy_mode = 0;
#if defined(USE_MYSQL_COOKIE)
memset((void*)&conf->mysql, 0, sizeof(mysql_t));
conf->mysql.port = MYSQL_PORT;
conf->mysql.host = NULL;
-#elif defined(USE_MEMCACHE_COOKIE)
+#endif
+#if defined(USE_MEMCACHE_COOKIE)
memset((void*)&conf->memcache, 0, sizeof(memcache_t));
conf->memcache.host = NULL;
conf->memcache.port = 0;
else {
mrg->mysql.charset = NULL;
}
-
-#elif defined(USE_MEMCACHE_COOKIE)
+#endif
+#if defined(USE_MEMCACHE_COOKIE)
if (add->memcache.host) {
mrg->memcache.host = apr_pstrdup(p, add->memcache.host);
}
else {
mrg->memcache.port = 0;
}
-
#endif
+ if (add->cookie_store_type) {
+ mrg->cookie_store_type = add->cookie_store_type;
+ }
+ else if (base->cookie_store_type) {
+ mrg->cookie_store_type = base->cookie_store_type;
+ }
+ else {
+ mrg->cookie_store_type = COOKIE_STORE_TYPE_NONE;
+ }
+ if (add->cookie_lazy_mode) {
+ mrg->cookie_lazy_mode = add->cookie_lazy_mode;
+ }
+ else if (base->cookie_lazy_mode) {
+ mrg->cookie_lazy_mode = base->cookie_lazy_mode;
+ }
+ else {
+ mrg->cookie_lazy_mode = 0;
+ }
return mrg;
}
return NULL;
}
-#elif defined(USE_MEMCACHE_COOKIE)
+#endif
+#if defined(USE_MEMCACHE_COOKIE)
static const char *
cmd_set_cookie_memcache_port(
cmd_parms *UNUSED(cmd),
}
#endif
+static const char *
+cmd_set_cookie_lazy_mode(
+ cmd_parms *UNUSED(cmd),
+ void *mconfig,
+ const char *arg)
+{
+ mod_chxj_config *dconf;
+
+ if (strlen(arg) > 255)
+ return "mod_chxj: ChxjCookieLazyMode is too long.";
+
+ dconf = (mod_chxj_config *)mconfig;
+
+ if (strcasecmp("TRUE",arg) == 0) {
+ dconf->cookie_lazy_mode = 2;
+ }
+ else {
+ dconf->cookie_lazy_mode = 1;
+ }
+
+ return NULL;
+}
+
+static const char *
+cmd_set_cookie_store_type(
+ cmd_parms *UNUSED(cmd),
+ void *mconfig,
+ const char *arg)
+{
+ mod_chxj_config *dconf;
+
+ if (strlen(arg) > 255)
+ return "mod_chxj: ChxjCookieStoreType is too long.";
+
+ dconf = (mod_chxj_config *)mconfig;
+
+ if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_DBM, arg) == 0) {
+ dconf->cookie_store_type = COOKIE_STORE_TYPE_DBM;
+ }
+ else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MYSQL, arg) == 0) {
+ dconf->cookie_store_type = COOKIE_STORE_TYPE_MYSQL;
+ }
+ else if (strcasecmp(CHXJ_COOKIE_STORE_TYPE_MEMCACHE, arg) == 0) {
+ dconf->cookie_store_type = COOKIE_STORE_TYPE_MEMCACHE;
+ }
+ else {
+ dconf->cookie_store_type = COOKIE_STORE_TYPE_NONE;
+ }
+
+ return NULL;
+}
+
static const command_rec cmds[] = {
NULL,
OR_ALL,
"The compulsion time-out time of the cookie is specified. "),
+ AP_INIT_TAKE1(
+ "ChxjCookieStoreType",
+ cmd_set_cookie_store_type,
+ NULL,
+ OR_ALL,
+ "It specifies preserving of the cookie ahead. (DBM/MYSQL/MEMCACHE)"),
+ AP_INIT_TAKE1(
+ "ChxjCookieLasyMode",
+ cmd_set_cookie_lazy_mode,
+ NULL,
+ OR_ALL,
+ "OneTimeID is negligently done. (TRUE/FALSE)"),
#if defined(USE_MYSQL_COOKIE)
AP_INIT_TAKE1(
"ChxjCookieMysqlHost",
NULL,
OR_ALL,
"The MySQL charset used by saving Cookie"),
-#elif defined(USE_MEMCACHE_COOKIE)
+#endif
+#if defined(USE_MEMCACHE_COOKIE)
AP_INIT_TAKE1(
"ChxjCookieMemcacheHost",
cmd_set_cookie_memcache_host,