--disable-libtool-lock avoid locking (might break parallel builds)
--enable-img-conv-f Please specify it when you change the file name of the image being written in the
source by the automatic operation.
+ --enable-mysql-cookie Please specify it when you save Cookie in MySQL.
--enable-dump-log When the log of conversion is output, it specifies it with the output file.
Optional Packages:
--with-apxs=ARG Path of apxs program file.
--with-apr-config=ARG Path of apr-config program file.
--with-apu-config=ARG Path of apu-config program file.
+ --with-mysql-header=ARG Path of "mysql.h"
+ --with-mysql-lib-dir=ARG Path of libmysqlclient
Some influential environment variables:
CC C compiler command
;;
*-*-irix6*)
# Find out which ABI we are using.
- echo '#line 5465 "configure"' > conftest.$ac_ext
+ echo '#line 5468 "configure"' > conftest.$ac_ext
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>&5
ac_status=$?
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:7961: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:7964: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:7965: \$? = $ac_status" >&5
+ echo "$as_me:7968: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:8229: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:8232: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:8233: \$? = $ac_status" >&5
+ echo "$as_me:8236: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:8333: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:8336: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:8337: \$? = $ac_status" >&5
+ echo "$as_me:8340: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<EOF
-#line 10630 "configure"
+#line 10633 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<EOF
-#line 10730 "configure"
+#line 10733 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:13066: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:13069: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:13070: \$? = $ac_status" >&5
+ echo "$as_me:13073: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:13170: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:13173: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:13174: \$? = $ac_status" >&5
+ echo "$as_me:13177: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:14731: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:14734: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:14735: \$? = $ac_status" >&5
+ echo "$as_me:14738: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:14835: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:14838: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:14839: \$? = $ac_status" >&5
+ echo "$as_me:14842: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:17022: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:17025: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:17026: \$? = $ac_status" >&5
+ echo "$as_me:17029: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:17290: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:17293: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:17294: \$? = $ac_status" >&5
+ echo "$as_me:17297: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:17394: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:17397: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:17398: \$? = $ac_status" >&5
+ echo "$as_me:17401: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
{ (exit 1); exit 1; }; }
fi
-
# Check whether --enable-img-conv-f was given.
if test "${enable_img_conv_f+set}" = set; then
enableval=$enable_img_conv_f;
QDEFS="-DIMG_NOT_CONVERT_FILENAME"
fi
+
+# Check whether --enable-mysql-cookie was given.
+if test "${enable_mysql_cookie+set}" = set; then
+ enableval=$enable_mysql_cookie;
+fi
+
+
+# Check whether --with-mysql-header was given.
+if test "${with_mysql_header+set}" = set; then
+ withval=$with_mysql_header;
+fi
+
+
+# Check whether --with-mysql-lib-dir was given.
+if test "${with_mysql_lib_dir+set}" = set; then
+ withval=$with_mysql_lib_dir;
+fi
+
+if test "x$enable_mysql_cookie" = "xyes"; then
+ if test "x$with_mysql_header" = "x" -o "x$with_mysql_header" = "xyes" ; then
+ { { echo "$as_me:$LINENO: error:
+Please specify the --with-mysql-header And, please specify the place of the \"mysql.h\" header file.
+" >&5
+echo "$as_me: error:
+Please specify the --with-mysql-header And, please specify the place of the \"mysql.h\" header file.
+" >&2;}
+ { (exit 1); exit 1; }; }
+ fi
+ if test "x$with_mysql_lib_dir" = "x" -o "x$with_mysql_lib_dir" = "xyes" ; then
+ { { echo "$as_me:$LINENO: error:
+Please specify the --with-mysql-lib-dir And, please specify the place of mysql library directory.
+" >&5
+echo "$as_me: error:
+Please specify the --with-mysql-lib-dir And, please specify the place of mysql library directory.
+" >&2;}
+ { (exit 1); exit 1; }; }
+ fi
+ MYSQL_COOKIE_DEFS="-DUSE_MYSQL_COOKIE -I${with_mysql_header}"
+ MYSQL_COOKIE_LIBS="-L${with_mysql_lib_dir} -lmysqlclient_r"
+else
+ MYSQL_COOKIE_DEFS=""
+ MYSQL_COOKIE_LIBS=""
+fi
+
# Check whether --enable-dump-log was given.
if test "${enable_dump_log+set}" = set; then
enableval=$enable_dump_log;
esac
+
+
LIBS="${LIBS} `${WAND_CONFIG} --ldflags` `${WAND_CONFIG} --libs | sed -e s/-ldpstk//` "
LIBS="${LIBS} `${APR_CONFIG} --ldflags` `${APR_CONFIG} --libs` "
LIBS="${LIBS} `${APU_CONFIG} --ldflags` `${APU_CONFIG} --libs` "
+LIBS="${LIBS} ${MYSQL_COOKIE_LIBS}"
CFLAGS="${CFLAGS} `${WAND_CONFIG} --cppflags` `${WAND_CONFIG} --cflags`"
CFLAGS="${CFLAGS} `${APR_CONFIG} --includes` `${APR_CONFIG} --cflags` `${APR_CONFIG} --cppflags`"
CFLAGS="${CFLAGS} `${APU_CONFIG} --includes`"
CFLAGS="${CFLAGS} -I${with_apache_header}"
+CFLAGS="${CFLAGS} ${MYSQL_COOKIE_DEFS}"
CPPFLAGS="${CPPFLAGS} `${APR_CONFIG} --includes` "
CPPFLAGS="${CPPFLAGS} -I${with_apache_header}"
+CPPFLAGS="${CPPFLAGS} ${MYSQL_COOKIE_DEFS}"
+
# Checks for header files.
{ echo "$as_me:$LINENO: checking for ANSI C header files" >&5
])
fi
+dnl ==================================================
+dnl
+dnl apxs
+dnl
+dnl ==================================================
AC_ARG_WITH(apxs, [ --with-apxs=ARG Path of apxs program file.])
if test "x$with_apxs" = "x" ; then
APXS=""
])
fi
+dnl ==================================================
+dnl
+dnl apr-config
+dnl
+dnl ==================================================
AC_ARG_WITH(apr-config, [ --with-apr-config=ARG Path of apr-config program file.])
if test "x$with_apr_config" = "xyes" ; then
AC_MSG_ERROR([
])
fi
+dnl ==================================================
+dnl
+dnl apu-config
+dnl
+dnl ==================================================
AC_ARG_WITH(apu-config, [ --with-apu-config=ARG Path of apu-config program file.])
if test "x$with_apu_config" = "xyes" ; then
AC_MSG_ERROR([
])
fi
-
+dnl ==================================================
+dnl
+dnl filename in img tag convertion.
+dnl
+dnl ==================================================
AC_ARG_ENABLE(img-conv-f, [ --enable-img-conv-f Please specify it when you change the file name of the image being written in the
source by the automatic operation.])
if test "x$enable_img_conv_f" = "xyes"; then
QDEFS="-DIMG_NOT_CONVERT_FILENAME"
fi
+
+dnl ==================================================
+dnl
+dnl SAVE COOKIE to MySQL Mode
+dnl
+dnl ==================================================
+AC_ARG_ENABLE(mysql-cookie, [ --enable-mysql-cookie Please specify it when you save Cookie in MySQL. ])
+AC_ARG_WITH(mysql-header, [ --with-mysql-header=ARG Path of "mysql.h"])
+AC_ARG_WITH(mysql-lib-dir, [ --with-mysql-lib-dir=ARG Path of libmysqlclient])
+if test "x$enable_mysql_cookie" = "xyes"; then
+ dnl ======================================
+ dnl use MYSQL COOKIE
+ dnl ======================================
+ if test "x$with_mysql_header" = "x" -o "x$with_mysql_header" = "xyes" ; then
+ AC_MSG_ERROR([
+Please specify the --with-mysql-header And, please specify the place of the "mysql.h" header file.
+])
+ fi
+ if test "x$with_mysql_lib_dir" = "x" -o "x$with_mysql_lib_dir" = "xyes" ; then
+ AC_MSG_ERROR([
+Please specify the --with-mysql-lib-dir And, please specify the place of mysql library directory.
+])
+ fi
+ MYSQL_COOKIE_DEFS="-DUSE_MYSQL_COOKIE -I${with_mysql_header}"
+ MYSQL_COOKIE_LIBS="-L${with_mysql_lib_dir} -lmysqlclient_r"
+else
+ dnl ======================================
+ dnl no use MYSQL COOKIE
+ dnl ======================================
+ MYSQL_COOKIE_DEFS=""
+ MYSQL_COOKIE_LIBS=""
+fi
+
+dnl ==================================================
+dnl
+dnl dump log for DEBUG
+dnl
+dnl ==================================================
AC_ARG_ENABLE(dump-log, [ --enable-dump-log When the log of conversion is output, it specifies it with the output file. ])
if test "x$enable_dump_log" = "xyes"; then
DDEFS="-DDUMP_LOG=\\\"/tmp/dump.log\\\""
esac
+
+
LIBS="${LIBS} `${WAND_CONFIG} --ldflags` `${WAND_CONFIG} --libs | sed -e s/-ldpstk//` "
LIBS="${LIBS} `${APR_CONFIG} --ldflags` `${APR_CONFIG} --libs` "
LIBS="${LIBS} `${APU_CONFIG} --ldflags` `${APU_CONFIG} --libs` "
+LIBS="${LIBS} ${MYSQL_COOKIE_LIBS}"
CFLAGS="${CFLAGS} `${WAND_CONFIG} --cppflags` `${WAND_CONFIG} --cflags`"
CFLAGS="${CFLAGS} `${APR_CONFIG} --includes` `${APR_CONFIG} --cflags` `${APR_CONFIG} --cppflags`"
CFLAGS="${CFLAGS} `${APU_CONFIG} --includes`"
CFLAGS="${CFLAGS} -I${with_apache_header}"
+CFLAGS="${CFLAGS} ${MYSQL_COOKIE_DEFS}"
CPPFLAGS="${CPPFLAGS} `${APR_CONFIG} --includes` "
CPPFLAGS="${CPPFLAGS} -I${with_apache_header}"
+CPPFLAGS="${CPPFLAGS} ${MYSQL_COOKIE_DEFS}"
+
# Checks for header files.
AC_HEADER_STDC
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta name="generator" content="SmartDoc 1.1">
<meta name="author" content="Atsushi Konno" lang="ja">
-<meta name="date" content="Last modified: Wed, 13 Feb 2008 18:35:16 +0900" lang="ja">
+<meta name="date" content="Last modified: Sat, 23 Mar 2008 03:21:16 +0900" lang="ja">
<title>mod_chxj</title>
<style type="text/css">
<!--
<h1 class="title">mod_chxj<br><span class="subtitle"></span></h1>
-<div class="date">Last modified: Wed, 13 Feb 2008 18:35:16 +0900</div>
+<div class="date">Last modified: Sat, 23 Mar 2008 03:21:16 +0900</div>
<div class="author">Atsushi Konno</div>
<h2>\96Ú\8e\9f</h2>
<li> <a href="#doc1_1909" onmouseover="hilightSelflink(this)" onmouseout="normal(this)">Cookie\83V\83~\83\85\83\8c\81[\83g\8b@\94\(EXPERIMENTAL)</a>
<li> <a href="#doc1_1915" onmouseover="hilightSelflink(this)" onmouseout="normal(this)">One-Time ID</a>
<li> <a href="#doc1_1918" onmouseover="hilightSelflink(this)" onmouseout="normal(this)">Cookie\82Ì\95Û\91¶\8fê\8f\8a</a>
-<li> <a href="#doc1_1924" onmouseover="hilightSelflink(this)" onmouseout="normal(this)">Cookie\82Ì\95Û\8e\9d\8aú\8aÔ</a>
+<li> <a href="#doc1_1991" onmouseover="hilightSelflink(this)" onmouseout="normal(this)">Cookie\82Ì\95Û\8e\9d\8aú\8aÔ</a>
</ul>
-<li> <a href="#doc1_1931" onmouseover="hilightSelflink(this)" onmouseout="normal(this)">Referer\83V\83~\83\85\83\8c\81[\83g\8b@\94\(EXPERIMENTAL)</a>
+<li> <a href="#doc1_1998" onmouseover="hilightSelflink(this)" onmouseout="normal(this)">Referer\83V\83~\83\85\83\8c\81[\83g\8b@\94\(EXPERIMENTAL)</a>
<ul>
-<li> <a href="#doc1_1933" onmouseover="hilightSelflink(this)" onmouseout="normal(this)">Referer\83V\83~\83\85\83\8c\81[\83g\8b@\94\(EXPERIMENTAL)</a>
+<li> <a href="#doc1_2000" onmouseover="hilightSelflink(this)" onmouseout="normal(this)">Referer\83V\83~\83\85\83\8c\81[\83g\8b@\94\(EXPERIMENTAL)</a>
</ul>
</ul>
</div>
<h3 id="doc1_1918">Cookie\82Ì\95Û\91¶\8fê\8f\8a</h3>
-<p class="first_ja">Cookie\82Ì\93à\97e\82Í\81A\83T\81[\83o\91¤\82É\95Û\91¶\82³\82ê\82Ü\82·\81B\95Û\91¶\83f\83B\83\8c\83N\83g\83\8a\82ÍChxjCookieDir\83f\83B\83\8c\83N\83e\83B\83u\82ð\8eg\97p\82·\82é\82±\82Æ\82Å\8ew\92è\82·\82é\82±\82Æ\82ª\82Å\82«\82Ü\82·\81B\8ew\92è\82µ\82È\82©\82Á\82½\8fê\8d\87\82Í\81A/tmp\82É\95Û\91¶\82³\82ê\82Ü\82·\81B</p>
+<p class="first_ja">Cookie\82Ì\93à\97e\82Í\83T\81[\83o\91¤\82É\95Û\91¶\82³\82ê\82Ü\82·\81B\83f\83t\83H\83\8b\83g\82Å\82ÍDBM\82ð\8eg\97p\82µ\81A\95Û\91¶\83f\83B\83\8c\83N\83g\83\8a\82ÍChxjCookieDir\83f\83B\83\8c\83N\83e\83B\83u\82ð\8eg\97p\82·\82é\82±\82Æ\82Å\8ew\92è\82·\82é\82±\82Æ\82ª\82Å\82«\82Ü\82·\81B\8ew\92è\82µ\82È\82©\82Á\82½\8fê\8d\87\82Í\81A/tmp\82É\95Û\91¶\82³\82ê\82Ü\82·\81B</p>
<div id="doc1_1920" class="caption">ChxjCookieDir\82Ì\97á</div>
<pre class="program" style="margin-top:0">
</pre>
+<p>DBM\82Ì\91ã\82í\82è\82ÉMySQL\82ð\8ew\92è\82·\82é\82±\82Æ\82à\82Å\82«\82Ü\82·\81B\82»\82Ì\8dÛ\82Í\81AChxjCookieDir\82Í\8ew\92è\82·\82é\95K\97v\82Í\82 \82è\82Ü\82¹\82ñ\81BMySQL\82ð\8eg\97p\82·\82é\82É\82Í\81A\88È\89º\82Ì\83f\83B\83\8c\83N\83e\83B\83u\82ð\8ew\92è\82·\82é\95K\97v\82ª\82 \82è\82Ü\82·\81B</p>
-<h3 id="doc1_1924">Cookie\82Ì\95Û\8e\9d\8aú\8aÔ</h3>
+<ol>
+<li> ChxjCookieMysqlHost<br></br> MySQL\83T\81[\83o\82Ì\93®\8dì\82·\82é\83z\83X\83g\82ð\8ew\92è\82µ\82Ü\82·\81B
+<div id="doc1_1929" class="caption">ChxjCookieMysqlHost\82Ì\97á</div>
+<pre class="program" style="margin-top:0">
+ ChxjCookieMysqlHost "localhost"
+
+</pre>
+<li> ChxjCookieMysqlPort<br></br> MySQL\83T\81[\83o\82Ì\83|\81[\83g\94Ô\8d\86\82ð\8ew\92è\82µ\82Ü\82·\81B
+<div id="doc1_1937" class="caption">ChxjCookieMysqlPort\82Ì\97á</div>
+<pre class="program" style="margin-top:0">
+ ChxjCookieMysqlPort 3306
+
+</pre>
+<li> ChxjCookieMysqlDatabase<br></br> MySQL\83T\81[\83o\82Ì\83f\81[\83^\83x\81[\83X\96¼\82ð\8ew\92è\82µ\82Ü\82·\81B
+<div id="doc1_1945" class="caption">ChxjCookieMysqlDatabase\82Ì\97á</div>
+<pre class="program" style="margin-top:0">
+ ChxjCookieMysqlDatabase "test_db"
+
+</pre>
+<li> ChxjCookieMysqlUsername<br></br> MySQL\83T\81[\83o\82É\90Ú\91±\82·\82é\8dÛ\82É\8eg\97p\82·\82é\83\86\81[\83U\96¼\82ð\8ew\92è\82µ\82Ü\82·\81B
+<div id="doc1_1953" class="caption">ChxjCookieMysqlUsername\82Ì\97á</div>
+<pre class="program" style="margin-top:0">
+ ChxjCookieMysqlUsername "roottest"
+
+</pre>
+<li> ChxjCookieMysqlPassword<br></br> MySQL\83T\81[\83o\82É\90Ú\91±\82·\82é\8dÛ\82É\8eg\97p\82·\82é\83p\83X\83\8f\81[\83h\82ð\8ew\92è\82µ\82Ü\82·\81B
+<div id="doc1_1961" class="caption">ChxjCookieMysqlPassword\82Ì\97á</div>
+<pre class="program" style="margin-top:0">
+ ChxjCookieMysqlPassword "pwtest"
+
+</pre>
+<li> ChxjCookieMysqlSocketPath<br></br> MySQL\82Ì\83\\83P\83b\83g\83p\83X\82ð\8ew\92è\82µ\82Ü\82·\81B
+<div id="doc1_1969" class="caption">ChxjCookieMysqlSocketPath\82Ì\97á</div>
+<pre class="program" style="margin-top:0">
+ ChxjCookieMysqlSocketPath "/tmp/mysql.sock"
+
+</pre>
+<li> ChxjCookieMysqlCharset<br></br> MySQL\82Ì\83G\83\93\83R\81[\83h\82ð\8ew\92è\82µ\82Ü\82·\81B
+<div id="doc1_1977" class="caption">ChxjCookieMysqlCharset\82Ì\97á</div>
+<pre class="program" style="margin-top:0">
+ ChxjCookieMysqlCharset "utf8"
+
+</pre>
+<li> <p>ChxjCookieMysqlTablename<br></br> MySQL\82Ì\83N\83b\83L\81[\82ð\95Û\91¶\82·\82é\83e\81[\83u\83\8b\96¼\82ð\8ew\92è\82µ\82Ü\82·\81B</p>
+
+<div id="doc1_1985" class="caption">ChxjCookieMysqlTablename\82Ì\97á</div>
+<pre class="program" style="margin-top:0">
+ ChxjCookieMysqlTablename "chxj_cookie"
+
+</pre>
+
+<p>\8fã\8bL\82Ì\82æ\82¤\82É"chxj_cookie"\82Æ\8ew\92è\82·\82é\82Æ\81A\8eÀ\8dÛ\82É\8dì\90¬\82³\82ê\82é\83e\81[\83u\83\8b\82Í\81Achxj_cookie\82Æchxj_cookie_expire\83e\81[\83u\83\8b\82Ì2\82Â\82É\82È\82è\82Ü\82·\81B</p></ol>
+
+
+<h3 id="doc1_1991">Cookie\82Ì\95Û\8e\9d\8aú\8aÔ</h3>
<p class="first_ja">ChxjCookieTimeout\83f\83B\83\8c\83N\83e\83B\83u\82Å\95Û\8e\9d\8aú\8aÔ\82ð\8ew\92è\82·\82é\82±\82Æ\82ª\82Å\82«\82Ü\82·\81B\8ew\92è\82µ\82È\82©\82Á\82½\8fê\8d\87\82Í1800\95b\82Å\83T\81[\83o\82É\95Û\91¶\82³\82ê\82Ä\82¢\82éCookie\82Í\8dí\8f\9c\82³\82ê\82Ü\82·\81B</p>
-<div id="doc1_1926" class="caption">ChxjCookieTimeout\82Ì\97á</div>
+<div id="doc1_1993" class="caption">ChxjCookieTimeout\82Ì\97á</div>
<pre class="program" style="margin-top:0">
<Location />
ChxjCookieTimeout 10
<p>\8fã\8bL\82Ì\97á\82Í\81A10\95b\82Å\83^\83C\83\80\83A\83E\83g(\83T\81[\83o\82©\82ç\8dí\8f\9c)\82·\82é\82æ\82¤\82É\8ew\92è\82µ\82Ä\82¢\82Ü\82·\81B</p>
-<h2 id="doc1_1931">Referer\83V\83~\83\85\83\8c\81[\83g\8b@\94\(EXPERIMENTAL)</h2>
+<h2 id="doc1_1998">Referer\83V\83~\83\85\83\8c\81[\83g\8b@\94\(EXPERIMENTAL)</h2>
-<h3 id="doc1_1933">Referer\83V\83~\83\85\83\8c\81[\83g\8b@\94\(EXPERIMENTAL)</h3>
+<h3 id="doc1_2000">Referer\83V\83~\83\85\83\8c\81[\83g\8b@\94\(EXPERIMENTAL)</h3>
<p class="first_ja">DoCoMo\92[\96\96\82È\82Ç\82ÌReferer\82É\91Î\89\9e\82µ\82Ä\82¢\82È\82¢\8b@\8eí\82Ì\82½\82ß\82ÉReferer\83V\83~\83\85\83\8c\81[\83g\8b@\94\\82ð\92ñ\8b\9f\82µ\82Ü\82·\81B\96{\8b@\94\\82Í\81ACookie\83V\83~\83\85\83\8c\81[\83g\8b@\94\\82ð\97L\8cø\82É\82·\82é\82Æ\81A\8e©\93®\82Å\97L\8cø\82É\82È\82è\82Ü\82·(\8f«\97\88\93I\82É\82Í\95Ï\8dX\97\\92è)\81B</p>
</body>
<subtitle></subtitle>
<author>Atsushi Konno</author>
<date>29 Mar 2005</date>
- <date>Last modified: Wed, 13 Feb 2008 18:35:16 +0900</date>
+ <date>Last modified: Sat, 23 Mar 2008 03:21:16 +0900</date>
</head>
<body>
<section title="Overview">
¤½¤Î¤¿¤á¡¢¥æ¡¼¥¶¤¬¥Ö¥é¥¦¥¶¤ÎÌá¤ë¥Ü¥¿¥óÅù¤ÇÌá¤Ã¤¿¾ì¹ç¤ÏCookie¤ò¼èÆÀ¤Ç¤¤Ê¤¯¤Ê¤ê¤Þ¤¹¡£
</subsection>
<subsection title="Cookie¤ÎÊݸ¾ì½ê">
-Cookie¤ÎÆâÍƤϡ¢¥µ¡¼¥Ð¦¤ËÊݸ¤µ¤ì¤Þ¤¹¡£Êݸ¥Ç¥£¥ì¥¯¥È¥ê¤ÏChxjCookieDir¥Ç¥£¥ì¥¯¥Æ¥£¥Ö¤ò»ÈÍѤ¹¤ë¤³¤È¤Ç»ØÄꤹ¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£»ØÄꤷ¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï¡¢/tmp¤ËÊݸ¤µ¤ì¤Þ¤¹¡£
+Cookie¤ÎÆâÍƤϥµ¡¼¥Ð¦¤ËÊݸ¤µ¤ì¤Þ¤¹¡£
+¥Ç¥Õ¥©¥ë¥È¤Ç¤ÏDBM¤ò»ÈÍѤ·¡¢Êݸ¥Ç¥£¥ì¥¯¥È¥ê¤ÏChxjCookieDir¥Ç¥£¥ì¥¯¥Æ¥£¥Ö¤ò»ÈÍѤ¹¤ë¤³¤È¤Ç»ØÄꤹ¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£»ØÄꤷ¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï¡¢/tmp¤ËÊݸ¤µ¤ì¤Þ¤¹¡£
<program title="ChxjCookieDir¤ÎÎã">
ChxjCookieDir /var/abc
</program>
+
+DBM¤ÎÂå¤ï¤ê¤ËMySQL¤ò»ØÄꤹ¤ë¤³¤È¤â¤Ç¤¤Þ¤¹¡£¤½¤ÎºÝ¤Ï¡¢ChxjCookieDir¤Ï»ØÄꤹ¤ëɬÍפϤ¢¤ê¤Þ¤»¤ó¡£
+MySQL¤ò»ÈÍѤ¹¤ë¤Ë¤Ï¡¢°Ê²¼¤Î¥Ç¥£¥ì¥¯¥Æ¥£¥Ö¤ò»ØÄꤹ¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
+<ol>
+ <li>ChxjCookieMysqlHost<br />
+ MySQL¥µ¡¼¥Ð¤ÎÆ°ºî¤¹¤ë¥Û¥¹¥È¤ò»ØÄꤷ¤Þ¤¹¡£
+ <program title="ChxjCookieMysqlHost¤ÎÎã">
+ ChxjCookieMysqlHost "localhost"
+ </program>
+ </li>
+ <li>ChxjCookieMysqlPort<br />
+ MySQL¥µ¡¼¥Ð¤Î¥Ý¡¼¥ÈÈÖ¹æ¤ò»ØÄꤷ¤Þ¤¹¡£
+ <program title="ChxjCookieMysqlPort¤ÎÎã">
+ ChxjCookieMysqlPort 3306
+ </program>
+ </li>
+ <li>ChxjCookieMysqlDatabase<br />
+ MySQL¥µ¡¼¥Ð¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹Ì¾¤ò»ØÄꤷ¤Þ¤¹¡£
+ <program title="ChxjCookieMysqlDatabase¤ÎÎã">
+ ChxjCookieMysqlDatabase "test_db"
+ </program>
+ </li>
+ <li>ChxjCookieMysqlUsername<br />
+ MySQL¥µ¡¼¥Ð¤ËÀܳ¤¹¤ëºÝ¤Ë»ÈÍѤ¹¤ë¥æ¡¼¥¶Ì¾¤ò»ØÄꤷ¤Þ¤¹¡£
+ <program title="ChxjCookieMysqlUsername¤ÎÎã">
+ ChxjCookieMysqlUsername "roottest"
+ </program>
+ </li>
+ <li>ChxjCookieMysqlPassword<br />
+ MySQL¥µ¡¼¥Ð¤ËÀܳ¤¹¤ëºÝ¤Ë»ÈÍѤ¹¤ë¥Ñ¥¹¥ï¡¼¥É¤ò»ØÄꤷ¤Þ¤¹¡£
+ <program title="ChxjCookieMysqlPassword¤ÎÎã">
+ ChxjCookieMysqlPassword "pwtest"
+ </program>
+ </li>
+ <li>ChxjCookieMysqlSocketPath<br />
+ MySQL¤Î¥½¥±¥Ã¥È¥Ñ¥¹¤ò»ØÄꤷ¤Þ¤¹¡£
+ <program title="ChxjCookieMysqlSocketPath¤ÎÎã">
+ ChxjCookieMysqlSocketPath "/tmp/mysql.sock"
+ </program>
+ </li>
+ <li>ChxjCookieMysqlCharset<br />
+ MySQL¤Î¥¨¥ó¥³¡¼¥É¤ò»ØÄꤷ¤Þ¤¹¡£
+ <program title="ChxjCookieMysqlCharset¤ÎÎã">
+ ChxjCookieMysqlCharset "utf8"
+ </program>
+ </li>
+ <li>ChxjCookieMysqlTablename<br />
+ MySQL¤Î¥¯¥Ã¥¡¼¤òÊݸ¤¹¤ë¥Æ¡¼¥Ö¥ë̾¤ò»ØÄꤷ¤Þ¤¹¡£
+ <program title="ChxjCookieMysqlTablename¤ÎÎã">
+ ChxjCookieMysqlTablename "chxj_cookie"
+ </program>
+ ¾åµ¤Î¤è¤¦¤Ë"chxj_cookie"¤È»ØÄꤹ¤ë¤È¡¢¼ÂºÝ¤ËºîÀ®¤µ¤ì¤ë¥Æ¡¼¥Ö¥ë¤Ï¡¢chxj_cookie¤Èchxj_cookie_expire¥Æ¡¼¥Ö¥ë¤Î2¤Ä¤Ë¤Ê¤ê¤Þ¤¹¡£
+ </li>
+</ol>
</subsection>
<subsection title="Cookie¤ÎÊÝ»ý´ü´Ö">
ChxjCookieTimeout¥Ç¥£¥ì¥¯¥Æ¥£¥Ö¤ÇÊÝ»ý´ü´Ö¤ò»ØÄꤹ¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£»ØÄꤷ¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï1800Éäǥµ¡¼¥Ð¤ËÊݸ¤µ¤ì¤Æ¤¤¤ëCookie¤Ïºï½ü¤µ¤ì¤Þ¤¹¡£
#ifndef __CHXJ_MYSQL_H__
#define __CHXJ_MYSQL_H__
+#include <mysql.h>
#include "mod_chxj.h"
+#include "apr.h"
-typedef struct __mysql_t {
+typedef struct {
+ char *host;
+ int port;
char *database;
char *username;
char *password;
char *tablename;
-} *mysql_t;
+ int keep_alive;
+ char *socket_path;
+ char *charset;
+} mysql_t;
+#define DEFAULT_MYSQL_HOST "localhost"
+#define DEFAULT_MYSQL_CHARSET "utf8"
+
+extern int chxj_open_mysql_handle(request_rec *r, mod_chxj_config *m);
+extern void chxj_close_mysql_handle();
+extern int chxj_mysql_exist_cookie_table(request_rec *r, mod_chxj_config *m);
+extern int chxj_mysql_create_cookie_table(request_rec *r, mod_chxj_config *m);
+extern char *chxj_mysql_get_cookie_from_cookie_id(request_rec *r, mod_chxj_config *m, const char *cookie_id);
+extern int chxj_mysql_insert_or_update_cookie(request_rec *r, mod_chxj_config *m, const char *cookie_id, const char *data);
+extern int chxj_mysql_rollback(request_rec *r, mod_chxj_config *m);
+extern char *chxj_mysql_load_cookie(request_rec *r, mod_chxj_config *m, const char *cookie_id);
+extern int chxj_mysql_delete_cookie(request_rec *r, mod_chxj_config *m, const char *cookie_id);
+
+/* expire table */
+extern int chxj_mysql_create_cookie_expire_table(request_rec *r, mod_chxj_config *m);
+extern char *chxj_mysql_get_cookie_expire_from_cookie_id(request_rec *r, mod_chxj_config *m, const char *cookie_id);
+extern int chxj_mysql_insert_or_update_cookie_expire(request_rec *r, mod_chxj_config *m, const char *cookie_id);
+extern char *chxj_mysql_load_cookie_expire(request_rec *r, mod_chxj_config *m, const char *cookie_id);
+extern int chxj_mysql_delete_cookie_expire(request_rec *r, mod_chxj_config *m, const char *cookie_id);
+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);
#endif
#endif
tagDD,
} tag_type;
+
typedef struct mod_chxj_config mod_chxj_config;
#include "chxj_emoji.h"
+#ifdef USE_MYSQL_COOKIE
+#include "chxj_mysql.h"
+#endif
struct mod_chxj_config {
int image;
softbank2imode_t *emoji_softbank2imode_webcode[EMOJI_SOFTBANK2IMODE_COUNT];
softbank2imode_t *emoji_softbank2imode_sjis[EMOJI_SOFTBANK2IMODE_COUNT];
softbank2imode_t *emoji_softbank2imode_utf8[EMOJI_SOFTBANK2IMODE_COUNT];
+
+
+#ifdef USE_MYSQL_COOKIE
+ mysql_t mysql;
+#endif
};
chxj_cookie.c \
chxj_preg_replace.c \
chxj_emoji.c \
- chxj_jreserved_tag.c
+ chxj_jreserved_tag.c \
+ chxj_mysql.c
libmod_chxj_la_CFLAGS = $(AM_CFLAGS) -O2 -prefer-pic @QDEFS@ @DDEFS@ -I. -I../include
libmod_chxj_la-chxj_cookie.lo \
libmod_chxj_la-chxj_preg_replace.lo \
libmod_chxj_la-chxj_emoji.lo \
- libmod_chxj_la-chxj_jreserved_tag.lo
+ libmod_chxj_la-chxj_jreserved_tag.lo \
+ libmod_chxj_la-chxj_mysql.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_cookie.c \
chxj_preg_replace.c \
chxj_emoji.c \
- chxj_jreserved_tag.c
+ chxj_jreserved_tag.c \
+ chxj_mysql.c
libmod_chxj_la_CFLAGS = $(AM_CFLAGS) -O2 -prefer-pic @QDEFS@ @DDEFS@ -I. -I../include
AM_CFLAGS = @CFLAGS@ -O2 -prefer-pic @QDEFS@ @DDEFS@ -I. -I../include
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmod_chxj_la-chxj_jreserved_tag.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmod_chxj_la-chxj_load_device_data.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmod_chxj_la-chxj_load_emoji_data.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmod_chxj_la-chxj_mysql.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmod_chxj_la-chxj_node_convert.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmod_chxj_la-chxj_preg_replace.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmod_chxj_la-chxj_qr_code.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_jreserved_tag.lo `test -f 'chxj_jreserved_tag.c' || echo '$(srcdir)/'`chxj_jreserved_tag.c
+libmod_chxj_la-chxj_mysql.lo: chxj_mysql.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_mysql.lo -MD -MP -MF $(DEPDIR)/libmod_chxj_la-chxj_mysql.Tpo -c -o libmod_chxj_la-chxj_mysql.lo `test -f 'chxj_mysql.c' || echo '$(srcdir)/'`chxj_mysql.c
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/libmod_chxj_la-chxj_mysql.Tpo $(DEPDIR)/libmod_chxj_la-chxj_mysql.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='chxj_mysql.c' object='libmod_chxj_la-chxj_mysql.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_mysql.lo `test -f 'chxj_mysql.c' || echo '$(srcdir)/'`chxj_mysql.c
+
mostlyclean-libtool:
-rm -f *.lo
#include "apr_base64.h"
#include "apr_uri.h"
+#ifdef USE_MYSQL_COOKIE
+#include "chxj_mysql.h"
+#endif
+
static char *s_get_hostname_from_url(request_rec *r, char *value);
static char *s_cut_until_end_hostname(request_rec *, char *value);
+static char *
+alloc_cookie_id(request_rec *r)
+{
+ char *cookie_id;
+ char *uuid_string;
+ unsigned char *md5_value;
+ apr_uuid_t uuid;
+ apr_status_t retval;
+
+ apr_uuid_get(&uuid);
+ uuid_string = apr_palloc(r->pool, APR_UUID_FORMATTED_LENGTH + 1);
+ memset(uuid_string, 0, APR_UUID_FORMATTED_LENGTH + 1);
+ apr_uuid_format(uuid_string, &uuid);;
+
+ md5_value = (unsigned char*)apr_palloc(r->pool, APR_MD5_DIGESTSIZE + 1);
+ memset(md5_value, 0, APR_MD5_DIGESTSIZE + 1);
+
+ retval = apr_md5(md5_value,
+ (const char*)uuid_string,
+ APR_UUID_FORMATTED_LENGTH);
+ if (retval != APR_SUCCESS) {
+ ERR(r, "md5 failed.");
+ return NULL;
+ }
+
+ cookie_id = apr_palloc(r->pool, apr_base64_encode_len(APR_MD5_DIGESTSIZE)+1);
+ memset(cookie_id, 0, APR_MD5_DIGESTSIZE+1);
+ apr_base64_encode(cookie_id, (char*)md5_value, APR_MD5_DIGESTSIZE);
+
+ DBG(r, "cookie_id=[%s]", cookie_id);
+
+ cookie_id = chxj_url_encode(r,cookie_id);
+
+ DBG(r, "cookie_id=[%s]", cookie_id);
+ return cookie_id;
+}
+
/*
*
*/
int ii;
apr_array_header_t *headers;
apr_table_entry_t *hentryp;
+ char *old_cookie_id;
+ 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_uuid_t uuid;
char *uuid_string;
- unsigned char *md5_value;
- char *old_cookie_id;
- char *store_string;
- mod_chxj_config *dconf;
- chxjconvrule_entry *entryp;
apr_file_t *file;
+#endif
apr_table_t *new_cookie_table;
int has_cookie = 0;
cookie_t *cookie;
return NULL;
}
+ /*
+ * create val
+ */
+ cookie->cookie_headers = (apr_array_header_t*)apr_table_elts(new_cookie_table);
+ store_string = apr_palloc(r->pool, 1);
+ store_string[0] = 0;
+ hentryp = (apr_table_entry_t*)cookie->cookie_headers->elts;
+
+ for (ii=0; ii<cookie->cookie_headers->nelts; ii++) {
+ if (ii) store_string = apr_pstrcat(r->pool,
+ store_string,
+ "\n",
+ NULL);
+
+ store_string = apr_pstrcat(r->pool,
+ store_string,
+ hentryp[ii].key,
+ "=",
+ hentryp[ii].val,
+ NULL);
+ }
+
+ cookie->cookie_id = alloc_cookie_id(r);
+
+#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 (! 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)
+
+#else
file = chxj_cookie_db_lock(r);
if (! file) {
ERR(r, "mod_chxj: Can't lock cookie db");
return NULL;
}
- DBG(r, " ");
-
retval = apr_dbm_open_ex(&f,
"default",
chxj_cookie_db_name_create(r, dconf->cookie_db_dir),
return NULL;
}
- apr_uuid_get(&uuid);
- uuid_string = apr_palloc(r->pool, APR_UUID_FORMATTED_LENGTH + 1);
- memset(uuid_string, 0, APR_UUID_FORMATTED_LENGTH + 1);
- apr_uuid_format(uuid_string, &uuid);;
-
- md5_value = (unsigned char*)apr_palloc(r->pool, APR_MD5_DIGESTSIZE + 1);
- memset(md5_value, 0, APR_MD5_DIGESTSIZE + 1);
-
- retval = apr_md5(md5_value,
- (const char*)uuid_string,
- (apr_size_t)APR_UUID_FORMATTED_LENGTH);
- if (retval != APR_SUCCESS) {
- ERR(r, "md5 failed.");
- goto on_error;
- }
-
- cookie->cookie_id = apr_palloc(r->pool, apr_base64_encode_len(APR_MD5_DIGESTSIZE)+1);
- memset(cookie->cookie_id, 0, APR_MD5_DIGESTSIZE+1);
- apr_base64_encode(cookie->cookie_id, (char*)md5_value, APR_MD5_DIGESTSIZE);
-
- DBG(r, "cookie->cookie_id=[%s]", cookie->cookie_id);
-
- cookie->cookie_id = chxj_url_encode(r,cookie->cookie_id);
-
- DBG(r, "cookie->cookie_id=[%s]", cookie->cookie_id);
/*
* create key
dbmkey.dptr = cookie->cookie_id;
dbmkey.dsize = strlen(cookie->cookie_id);
-
- /*
- * create val
- */
- cookie->cookie_headers = (apr_array_header_t*)apr_table_elts(new_cookie_table);
- store_string = apr_palloc(r->pool, 1);
- store_string[0] = 0;
- hentryp = (apr_table_entry_t*)cookie->cookie_headers->elts;
-
- for (ii=0; ii<cookie->cookie_headers->nelts; ii++) {
- if (ii) store_string = apr_pstrcat(r->pool,
- store_string,
- "\n",
- NULL);
-
- store_string = apr_pstrcat(r->pool,
- store_string,
- hentryp[ii].key,
- "=",
- hentryp[ii].val,
- NULL);
- }
dbmval.dptr = store_string;
dbmval.dsize = strlen(store_string);
chxj_cookie_db_name_create(r, dconf->cookie_db_dir));
goto on_error;
}
+#endif
+
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;
int ii;
apr_array_header_t *headers;
apr_table_entry_t *hentryp;
- apr_status_t retval;
- apr_datum_t dbmkey;
- apr_datum_t dbmval;
- apr_dbm_t *f;
- apr_uuid_t uuid;
- char *uuid_string;
- unsigned char *md5_value;
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;
chxj_delete_cookie(r, old_cookie->cookie_id);
chxj_delete_cookie_expire(r, old_cookie->cookie_id);
+ cookie->cookie_id = alloc_cookie_id(r);
+
+ cookie->cookie_headers = old_cookie->cookie_headers;
+ store_string = apr_palloc(r->pool, 1);
+ store_string[0] = 0;
+ hentryp = (apr_table_entry_t*)cookie->cookie_headers->elts;
+
+ for (ii=0; ii<cookie->cookie_headers->nelts; ii++) {
+ if (ii) store_string = apr_pstrcat(r->pool,
+ store_string,
+ "\n",
+ NULL);
+
+ DBG(r, "OLD COOKIE VALUE=[%s][%s]", hentryp[ii].key, hentryp[ii].val);
+ store_string = apr_pstrcat(r->pool,
+ store_string,
+ hentryp[ii].key,
+ "=",
+ hentryp[ii].val,
+ NULL);
+ }
+
+#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 (! 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)
+#else
file = chxj_cookie_db_lock(r);
if (! file) {
ERR(r, "mod_chxj: Can't lock cookie db");
return NULL;
}
- DBG(r, " ");
-
retval = apr_dbm_open_ex(&f,
"default",
chxj_cookie_db_name_create(r, dconf->cookie_db_dir),
chxj_cookie_db_unlock(r, file);
return NULL;
}
- DBG(r, " ");
-
- apr_uuid_get(&uuid);
- uuid_string = apr_palloc(r->pool, APR_UUID_FORMATTED_LENGTH + 1);
- memset(uuid_string, 0, APR_UUID_FORMATTED_LENGTH + 1);
- apr_uuid_format(uuid_string, &uuid);;
-
- md5_value = (unsigned char*)apr_palloc(r->pool, APR_MD5_DIGESTSIZE + 1);
- memset(md5_value, 0, APR_MD5_DIGESTSIZE + 1);
-
- retval = apr_md5(md5_value,
- (const char*)uuid_string,
- (apr_size_t)APR_UUID_FORMATTED_LENGTH);
- if (retval != APR_SUCCESS) {
- ERR(r, "md5 failed.");
- goto on_error;
- }
- DBG(r, " ");
-
- cookie->cookie_id = apr_palloc(r->pool, apr_base64_encode_len(APR_MD5_DIGESTSIZE)+1);
- memset(cookie->cookie_id, 0, APR_MD5_DIGESTSIZE+1);
- apr_base64_encode(cookie->cookie_id, (char*)md5_value, APR_MD5_DIGESTSIZE);
- cookie->cookie_id = chxj_url_encode(r,cookie->cookie_id);
-
- DBG(r, " ");
/*
* create key
/*
* create val
*/
- cookie->cookie_headers = old_cookie->cookie_headers;
- store_string = apr_palloc(r->pool, 1);
- store_string[0] = 0;
- hentryp = (apr_table_entry_t*)cookie->cookie_headers->elts;
-
- for (ii=0; ii<cookie->cookie_headers->nelts; ii++) {
- if (ii) store_string = apr_pstrcat(r->pool,
- store_string,
- "\n",
- NULL);
-
- DBG(r, "OLD COOKIE VALUE=[%s][%s]", hentryp[ii].key, hentryp[ii].val);
- store_string = apr_pstrcat(r->pool,
- store_string,
- hentryp[ii].key,
- "=",
- hentryp[ii].val,
- NULL);
- }
dbmval.dptr = store_string;
dbmval.dsize = strlen(store_string);
chxj_cookie_db_name_create(r, dconf->cookie_db_dir));
goto on_error;
}
+#endif
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;
cookie_t *
chxj_load_cookie(request_rec *r, char *cookie_id)
{
- apr_status_t retval;
- apr_datum_t dbmkey;
- apr_datum_t dbmval;
- apr_dbm_t *f;
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;
+ char *load_string = NULL;
char *pstat;
char *key;
char *val;
char *pair;
+ char *header_cookie;
DBG(r, "========================================================");
DBG(r, "========================================================");
DBG(r, "end chxj_load_cookie() CookieOff");
goto on_error0;
}
+ load_cookie_table = apr_table_make(r->pool, 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 (!(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)
+#else
file = chxj_cookie_db_lock(r);
if (! file) {
ERR(r, "mod_chxj: Can't lock cookie db");
dbmkey.dsize = strlen(dbmkey.dptr);
if (apr_dbm_exists(f, dbmkey)) {
-
retval = apr_dbm_fetch(f, dbmkey, &dbmval);
if (retval != APR_SUCCESS) {
ERR(r,
chxj_cookie_db_name_create(r, dconf->cookie_db_dir));
goto on_error2;
}
- load_cookie_table = apr_table_make(r->pool, 0);
load_string = apr_palloc(r->pool, dbmval.dsize+1);
memset(load_string, 0, dbmval.dsize+1);
memcpy(load_string, dbmval.dptr, dbmval.dsize);
- char *header_cookie = apr_palloc(r->pool, 1);
+ }
+ apr_dbm_close(f);
+ chxj_cookie_db_unlock(r, file);
+
+#endif
+
+ if (load_string) {
+ DBG(r, "load_string=[%s]", load_string);
+ header_cookie = apr_palloc(r->pool, 1);
header_cookie[0] = 0;
for (;;) {
*/
apr_table_setn(r->headers_in, "CHXJ_COOKIE_ID", cookie->cookie_id);
}
- apr_dbm_close(f);
- chxj_cookie_db_unlock(r, file);
+
DBG(r, "end chxj_load_cookie()");
DBG(r, "========================================================");
DBG(r, "========================================================");
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:
}
+#if !defined(USE_MYSQL_COOKIE) && !defined(USE_MEMCACHE_COOKIE)
apr_file_t *
chxj_cookie_db_lock(request_rec *r)
{
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;
- apr_file_t *file;
+#endif
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)
+#else
file = chxj_cookie_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",
}
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)
{
return dst;
}
-
char *
chxj_cookie_db_lock_name_create(request_rec *r, const char *dir)
{
DBG(r, "end chxj_cookie_db_lock_name_create()");
return dst;
}
+#endif
/*
*
*/
void
chxj_save_cookie_expire(request_rec *r, cookie_t *cookie)
{
+ 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;
- apr_file_t *file;
- mod_chxj_config *dconf;
- char *store_string;
+#endif
DBG(r, "start chxj_save_cookie_expire()");
+
if (!cookie) {
DBG(r, "cookie is NULL");
return;
}
+ if (!cookie->cookie_id) {
+ DBG(r, "cookie->cookie_id is NULL");
+ return;
+ }
dconf = ap_get_module_config(r->per_dir_config, &chxj_module);
if (!dconf) {
return;
}
+#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);
+ DBG(r, "end chxj_save_cookie_expire()");
+ return;
+ }
+ }
+ 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)
+#else
file = chxj_cookie_expire_db_lock(r);
if (! file) {
ERR(r, "mod_chxj: Can't lock cookie db");
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)
{
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
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)
+#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",
}
apr_dbm_close(f);
chxj_cookie_expire_db_unlock(r, file);
+#endif
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
on_error0:
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;
- mod_chxj_config *dconf;
time_t now_time;
+#endif
+ mod_chxj_config *dconf;
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)
+#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",
apr_dbm_close(f);
chxj_cookie_expire_db_unlock(r, file);
+#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:
+#endif
+
return;
}
#include "ap_release.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 <unistd.h>
+
+/* for MySQL */
+#include <mysql.h>
+#include <errmsg.h>
+
+
+#define CHXJ_MYSQL_RECONNECT_WAIT_TIME (1)
+#define CHXJ_MYSQL_RECONNECT_COUNT (3)
+
+typedef struct {
+ MYSQL * handle;
+ char host[255];
+ char username[255];
+ char database[255];
+ time_t last_used;
+ int reconnect;
+} mysql_connection;
+
+static mysql_connection connection = {NULL, "", "", "", 0, 0};
+
+
+static apr_status_t
+_mysql_cleanup(void *UNUSED(notused))
+{
+ chxj_close_mysql_handle();
+ return APR_SUCCESS;
+}
+
+static apr_status_t
+_mysql_cleanup_child(void *UNUSED(notused))
+{
+ return APR_SUCCESS;
+}
+
+
+void
+chxj_close_mysql_handle()
+{
+ if (connection.handle) {
+ mysql_close(connection.handle);
+ connection.handle = NULL;
+ }
+}
+
+int
+chxj_open_mysql_handle(request_rec *r, mod_chxj_config *m)
+{
+ static MYSQL mysql_conn;
+ char query[MAX_STRING_LEN];
+
+ if (connection.handle && connection.reconnect == 0) {
+ if ((!m->mysql.host || (strcasecmp(m->mysql.host, "localhost") == 0)) && connection.host[0] == '\0'
+ && (!m->mysql.username || (strcmp(m->mysql.username, connection.username) == 0))) {
+
+ if (m->mysql.database && strcmp(m->mysql.database, connection.database) == 0) {
+ return 1;
+ }
+ else {
+ if (mysql_select_db(connection.handle,m->mysql.database) != 0) {
+ ERR(r, "MySQL ERROR: %s", mysql_error(connection.handle));
+ return 0;
+ }
+ else {
+ strcpy (connection.database, m->mysql.database);
+ return 1;
+ }
+ }
+ }
+ else {
+ chxj_close_mysql_handle();
+ }
+ }
+
+ connection.handle = mysql_init(&mysql_conn);
+ if (! connection.handle) {
+ ERR(r, "MySQL ERROR: %s", mysql_error(&mysql_conn));
+ }
+
+ if (!m->mysql.host || strcmp(m->mysql.host,"localhost") == 0) {
+ connection.host[0] = '\0';
+ } else {
+ strcpy(connection.host, m->mysql.host);
+ }
+
+ connection.handle = mysql_real_connect(&mysql_conn,connection.host,m->mysql.username,
+ m->mysql.password, NULL, m->mysql.port, m->mysql.socket_path, 0);
+ if (!connection.handle) {
+ ERR(r, "MySQL ERROR: %s. host:[%s] username:[%s] password:[%s] port:[%d] socket_path:[%s]", mysql_error(&mysql_conn),
+ connection.host,
+ m->mysql.username,
+ m->mysql.password,
+ m->mysql.port,
+ m->mysql.socket_path);
+ return 0;
+ }
+
+ if (!m->mysql.keep_alive) {
+ apr_pool_cleanup_register(r->pool, (void *)NULL, _mysql_cleanup, _mysql_cleanup_child);
+ }
+
+ if (m->mysql.username) {
+ strcpy(connection.username, m->mysql.username);
+ }
+ else {
+ connection.username[0] = '\0';
+ }
+
+ if (mysql_select_db(connection.handle,m->mysql.database) != 0) {
+ ERR(r, "MySQL ERROR: %s", mysql_error(connection.handle));
+ return 0;
+ }
+
+ strcpy (connection.database, m->mysql.database);
+ if (m->mysql.charset) {
+ apr_snprintf(query, sizeof(query)-1, "SET CHARACTER SET %s", m->mysql.charset);
+ if (mysql_query(connection.handle, query) != 0) {
+ ERR(r, "MySQL ERROR: %s: %s", mysql_error(connection.handle), r->uri);
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+
+int
+chxj_mysql_exist_cookie_table(request_rec *r, mod_chxj_config *m)
+{
+ MYSQL_RES *result;
+ char query[MAX_STRING_LEN];
+
+ apr_snprintf(query, sizeof(query)-1, "desc %s", m->mysql.tablename);
+ DBG(r, "start chxj_mysql_exist_cookie_table() query:[%s]", query);
+ do {
+ if (!chxj_open_mysql_handle(r, m)) {
+ ERR(r, "failed chxj_open_mysql_handle() query:[%s]", query);
+ return 0;
+ }
+ connection.reconnect = 0;
+ if (mysql_query(connection.handle, query) != 0) {
+ if (mysql_errno(connection.handle) == CR_SERVER_GONE_ERROR) {
+ connection.reconnect = 1;
+ sleep(CHXJ_MYSQL_RECONNECT_WAIT_TIME);
+ continue;
+ }
+ WRN(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ return 0;
+ }
+ }
+ while(0);
+
+ result = mysql_store_result(connection.handle);
+ if (result) mysql_free_result(result);
+
+ DBG(r, "end chxj_mysql_exist_cookie_table() query:[%s]", query);
+
+ return 1;
+}
+
+
+int
+chxj_mysql_exist_cookie_table_expire(request_rec *r, mod_chxj_config *m)
+{
+ MYSQL_RES *result;
+ char query[MAX_STRING_LEN];
+
+ apr_snprintf(query, sizeof(query)-1, "desc %s_expire", m->mysql.tablename);
+
+ DBG(r, "start chxj_mysql_exist_cookie_table_expire() query:[%s]", query);
+
+ do {
+ if (!chxj_open_mysql_handle(r, m)) {
+ ERR(r, "failed chxj_open_mysql_handle() query:[%s]", query);
+ return 0;
+ }
+ connection.reconnect = 0;
+ if (mysql_query(connection.handle, query) != 0) {
+ if (mysql_errno(connection.handle) == CR_SERVER_GONE_ERROR) {
+ connection.reconnect = 1;
+ sleep(CHXJ_MYSQL_RECONNECT_WAIT_TIME);
+ continue;
+ }
+ WRN(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ return 0;
+ }
+ } while(0);
+
+ result = mysql_store_result(connection.handle);
+ if (result) mysql_free_result(result);
+
+ DBG(r, "end chxj_mysql_exist_cookie_table_expire() query:[%s]", query);
+
+ return 1;
+}
+
+
+int
+chxj_mysql_create_cookie_table(request_rec *r, mod_chxj_config *m)
+{
+ MYSQL_RES *result;
+ char query[MAX_STRING_LEN];
+
+ apr_snprintf(query, sizeof(query)-1, "CREATE TABLE %s (cookie_id VARCHAR(%d) NOT NULL, data TEXT, PRIMARY KEY(cookie_id)) TYPE=InnoDB;",
+ m->mysql.tablename,
+ apr_base64_encode_len(APR_MD5_DIGESTSIZE) * 3);
+ DBG(r, "start chxj_mysql_create_cookie_table() query:[%s]", query);
+ do {
+ if (!chxj_open_mysql_handle(r, m)) {
+ ERR(r, "failed chxj_open_mysql_handle() query:[%s]", query);
+ return 0;
+ }
+ connection.reconnect = 0;
+ if (mysql_query(connection.handle, query) != 0) {
+ if (mysql_errno(connection.handle) == CR_SERVER_GONE_ERROR) {
+ connection.reconnect = 1;
+ sleep(CHXJ_MYSQL_RECONNECT_WAIT_TIME);
+ continue;
+ }
+ WRN(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ return 0;
+ }
+ }
+ while(0);
+
+ result = mysql_store_result(connection.handle);
+ if (result) mysql_free_result(result);
+
+ DBG(r, "end chxj_mysql_create_cookie_table() query:[%s]", query);
+
+ return 1;
+}
+
+int
+chxj_mysql_create_cookie_expire_table(request_rec *r, mod_chxj_config *m)
+{
+ MYSQL_RES *result;
+ char query[MAX_STRING_LEN];
+
+ apr_snprintf(query, sizeof(query)-1, "CREATE TABLE %s_expire (cookie_id VARCHAR(%d) NOT NULL, created_at DATETIME, PRIMARY KEY(cookie_id)) TYPE=InnoDB;",
+ m->mysql.tablename,
+ apr_base64_encode_len(APR_MD5_DIGESTSIZE) * 3);
+
+ DBG(r, "start chxj_mysql_create_cookie_expire_table() query:[%s]", query);
+
+ do {
+ if (!chxj_open_mysql_handle(r, m)) {
+ ERR(r, "failed chxj_open_mysql_handle() query:[%s]", query);
+ return 0;
+ }
+ connection.reconnect = 0;
+ if (mysql_query(connection.handle, query) != 0) {
+ if (mysql_errno(connection.handle) == CR_SERVER_GONE_ERROR) {
+ connection.reconnect = 1;
+ sleep(CHXJ_MYSQL_RECONNECT_WAIT_TIME);
+ continue;
+ }
+ WRN(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ return 0;
+ }
+ }
+ while(0);
+
+ result = mysql_store_result(connection.handle);
+ if (result) mysql_free_result(result);
+
+ DBG(r, "end chxj_mysql_create_cookie_expire_table() query:[%s]", query);
+
+ return 1;
+}
+
+
+char *
+chxj_mysql_get_cookie_from_cookie_id(request_rec *r, mod_chxj_config *m, const char *cookie_id)
+{
+ MYSQL_RES *result;
+ char query[MAX_STRING_LEN];
+ char *tmp = ap_escape_logitem(r->pool, cookie_id);
+ char *retval = NULL;
+
+ apr_snprintf(query, sizeof(query)-1, "SELECT data, length(data) FROM %s WHERE cookie_id = '%s' FOR UPDATE;", m->mysql.tablename, tmp);
+ DBG(r, "start chxj_mysql_get_cookie_from_cookie_id() query:[%s]", query);
+ do {
+ if (!chxj_open_mysql_handle(r, m)) {
+ ERR(r, "failed chxj_open_mysql_handle() query:[%s]", query);
+ return 0;
+ }
+ connection.reconnect = 0;
+ if (mysql_query(connection.handle, query) != 0) {
+ if (mysql_errno(connection.handle) == CR_SERVER_GONE_ERROR) {
+ connection.reconnect = 1;
+ sleep(CHXJ_MYSQL_RECONNECT_WAIT_TIME);
+ continue;
+ }
+ WRN(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ return NULL;
+ }
+ }
+ while(0);
+
+ result = mysql_store_result(connection.handle);
+ if (result && (mysql_num_rows(result) >= 1)) {
+ MYSQL_ROW data = mysql_fetch_row(result);
+ int len;
+ if (! data[0]) {
+ ERR(r, "MySQL cookie_id:[%s] has no valid cookie_id. %s", cookie_id, r->uri);
+ mysql_free_result(result);
+ return NULL;
+ }
+ len = atoi(data[1]);
+ retval = (char *) apr_palloc(r->pool, len + 1);
+ memcpy(retval, data[0], len);
+ }
+ if (result) mysql_free_result(result);
+
+ DBG(r, "end chxj_mysql_get_cookie_from_cookie_id() query:[%s]", query);
+
+ return retval;
+}
+
+
+char *
+chxj_mysql_get_cookie_expire_from_cookie_id(request_rec *r, mod_chxj_config *m, const char *cookie_id)
+{
+ MYSQL_RES *result;
+ char query[MAX_STRING_LEN];
+ char *tmp = ap_escape_logitem(r->pool, cookie_id);
+ char *retval = NULL;
+
+ apr_snprintf(query, sizeof(query)-1, "SELECT DATE_FORMAT(created_at, '%%Y%%m%%d%%H%%i%%s') FROM %s_expire WHERE cookie_id = '%s' FOR UPDATE;",
+ m->mysql.tablename, tmp);
+
+ DBG(r, "start chxj_mysql_get_cookie_expire_from_cookie_id() query:[%s]", query);
+
+ do {
+ if (!chxj_open_mysql_handle(r, m)) {
+ ERR(r, "failed chxj_open_mysql_handle() query:[%s]", query);
+ return NULL;
+ }
+ connection.reconnect = 0;
+ if (mysql_query(connection.handle, query) != 0) {
+ if (mysql_errno(connection.handle) == CR_SERVER_GONE_ERROR) {
+ connection.reconnect = 1;
+ sleep(CHXJ_MYSQL_RECONNECT_WAIT_TIME);
+ continue;
+ }
+ WRN(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ return NULL;
+ }
+ }
+ while(0);
+
+ result = mysql_store_result(connection.handle);
+ if (result && (mysql_num_rows(result) >= 1)) {
+ MYSQL_ROW data = mysql_fetch_row(result);
+ if (! data[0]) {
+ ERR(r, "MySQL cookie_id:[%s] has no valid cookie_id. %s", cookie_id, r->uri);
+ mysql_free_result(result);
+ return NULL;
+ }
+ retval = (char *) apr_palloc(r->pool, 19 + 1);
+ memset(retval, 0, 19+1);
+ memcpy(retval, data[0], 19);
+ }
+ if (result) mysql_free_result(result);
+
+ DBG(r, "end chxj_mysql_get_cookie_expire_from_cookie_id() query:[%s]", query);
+
+ return retval;
+}
+
+
+int
+chxj_mysql_insert_or_update_cookie(request_rec *r, mod_chxj_config *m, const char *cookie_id, const char *data)
+{
+ MYSQL_RES *result;
+ char query[MAX_STRING_LEN];
+ char *cid = ap_escape_logitem(r->pool, cookie_id);
+ char *cdt = ap_escape_logitem(r->pool, data);
+
+ DBG(r, "start chxj_mysql_insert_or_update_cookie()");
+ do {
+ if (!chxj_open_mysql_handle(r, m)) {
+ ERR(r, "failed chxj_open_mysql_handle()");
+ return 0;
+ }
+ connection.reconnect = 0;
+ apr_snprintf(query, sizeof(query)-1, "BEGIN;");
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ if (mysql_errno(connection.handle) == CR_SERVER_GONE_ERROR) {
+ connection.reconnect = 1;
+ sleep(CHXJ_MYSQL_RECONNECT_WAIT_TIME);
+ continue;
+ }
+ ERR(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ return 0;
+ }
+ }
+ while(0);
+
+ apr_snprintf(query, sizeof(query)-1, "INSERT INTO %s (cookie_id, data) VALUES ('%s','%s');", m->mysql.tablename, cid, cdt);
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ WRN(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ if (!chxj_mysql_get_cookie_from_cookie_id(r, m, cookie_id)) {
+ ERR(r, "failed chxj_mysql_get_cookie_from_cookie_id() cookie_id:[%s]", cookie_id);
+ return 0;
+ }
+ apr_snprintf(query, sizeof(query)-1, "UPDATE %s set data = '%s' WHERE cookie_id = '%s';", m->mysql.tablename, cdt, cid);
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ ERR(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ chxj_mysql_rollback(r, m);
+ return 0;
+ }
+ }
+
+ apr_snprintf(query, sizeof(query)-1, "COMMIT;");
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ ERR(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ chxj_mysql_rollback(r, m);
+ return 0;
+ }
+
+ result = mysql_store_result(connection.handle);
+ if (result) mysql_free_result(result);
+
+ DBG(r, "end chxj_mysql_get_cookie_from_cookie_id()");
+
+ return 1;
+}
+
+
+int
+chxj_mysql_insert_or_update_cookie_expire(request_rec *r, mod_chxj_config *m, const char *cookie_id)
+{
+ MYSQL_RES *result;
+ char query[MAX_STRING_LEN];
+ char *cid = ap_escape_logitem(r->pool, cookie_id);
+
+ DBG(r, "start chxj_mysql_insert_or_update_cookie_expire()");
+
+ do {
+ if (!chxj_open_mysql_handle(r, m)) {
+ ERR(r, "failed chxj_open_mysql_handle()");
+ return 0;
+ }
+ connection.reconnect = 0;
+ apr_snprintf(query, sizeof(query)-1, "BEGIN;");
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ if (mysql_errno(connection.handle) == CR_SERVER_GONE_ERROR) {
+ connection.reconnect = 1;
+ sleep(CHXJ_MYSQL_RECONNECT_WAIT_TIME);
+ continue;
+ }
+ ERR(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ return 0;
+ }
+ }
+ while(0);
+
+ apr_snprintf(query, sizeof(query)-1, "INSERT INTO %s_expire (cookie_id, created_at) VALUES ('%s',localtime);", m->mysql.tablename, cid);
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ WRN(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ if (!chxj_mysql_get_cookie_from_cookie_id(r, m, cookie_id)) {
+ ERR(r, "failed chxj_mysql_get_cookie_from_cookie_id() cookie_id:[%s]", cookie_id);
+ return 0;
+ }
+ apr_snprintf(query, sizeof(query)-1, "UPDATE %s_expire set created_at = localtime WHERE cookie_id = '%s';", m->mysql.tablename, cid);
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ ERR(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ chxj_mysql_rollback(r, m);
+ return 0;
+ }
+ }
+
+ apr_snprintf(query, sizeof(query)-1, "COMMIT;");
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ ERR(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ chxj_mysql_rollback(r, m);
+ return 0;
+ }
+
+ result = mysql_store_result(connection.handle);
+ if (result) mysql_free_result(result);
+
+ DBG(r, "end chxj_mysql_insert_or_update_cookie_expire()");
+
+ return 1;
+}
+
+
+int
+chxj_mysql_rollback(request_rec *r, mod_chxj_config *m)
+{
+ char query[MAX_STRING_LEN];
+
+ DBG(r, "start chxj_mysql_rollback()");
+
+ apr_snprintf(query, sizeof(query)-1, "ROLLBACK;");
+
+ if (!chxj_open_mysql_handle(r, m)) {
+ return 1; /* TRUE */
+ }
+ if (mysql_query(connection.handle, query) != 0) {
+ ERR(r, "MySQL ERROR: %s: %s", mysql_error(connection.handle), r->uri);
+ return 0; /* FALSE */
+ }
+ DBG(r, "end chxj_mysql_rollback()");
+ return 1;
+}
+
+char *
+chxj_mysql_load_cookie(request_rec *r, mod_chxj_config *m, const char *cookie_id)
+{
+ MYSQL_RES *result;
+ char query[MAX_STRING_LEN];
+ char *tmp = ap_escape_logitem(r->pool, cookie_id);
+ char *retval = NULL;
+
+ apr_snprintf(query, sizeof(query)-1, "SELECT data, length(data) FROM %s WHERE cookie_id = '%s';", m->mysql.tablename, tmp);
+
+ DBG(r, "start chxj_mysql_load_cookie() query:[%s]", query);
+
+ do {
+ if (!chxj_open_mysql_handle(r, m)) {
+ ERR(r, "failed chxj_open_mysql_handle() query:[%s]", query);
+ return NULL;
+ }
+ connection.reconnect = 1;
+ if (mysql_query(connection.handle, query) != 0) {
+ if (mysql_errno(connection.handle) == CR_SERVER_GONE_ERROR) {
+ connection.reconnect = 1;
+ sleep(CHXJ_MYSQL_RECONNECT_WAIT_TIME);
+ continue;
+ }
+ WRN(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ return NULL;
+ }
+ }
+ while(0);
+
+ result = mysql_store_result(connection.handle);
+ if (result && (mysql_num_rows(result) >= 1)) {
+ MYSQL_ROW data = mysql_fetch_row(result);
+ int len;
+ if (! data[0]) {
+ ERR(r, "MySQL cookie_id:[%s] has no valid cookie_id. %s", cookie_id, r->uri);
+ mysql_free_result(result);
+ return NULL;
+ }
+ len = atoi(data[1]);
+ retval = (char *) apr_palloc(r->pool, len + 1);
+ memcpy(retval, data[0], len);
+ }
+ if (result) mysql_free_result(result);
+
+ DBG(r, "end chxj_load_mysql_cookie() query:[%s]", query);
+
+ return retval;
+}
+
+
+char *
+chxj_mysql_load_cookie_expire(request_rec *r, mod_chxj_config *m, const char *cookie_id)
+{
+ MYSQL_RES *result;
+ char query[MAX_STRING_LEN];
+ char *tmp = ap_escape_logitem(r->pool, cookie_id);
+ char *retval = NULL;
+
+ apr_snprintf(query, sizeof(query)-1, "SELECT DATE_FORMAT(created_at, '%%Y%%m%%d%%H%%i%%s') FROM %s_expire WHERE cookie_id = '%s';", m->mysql.tablename, tmp);
+
+ DBG(r, "start chxj_mysql_load_cookie_expire() query:[%s]", query);
+
+ do {
+ if (!chxj_open_mysql_handle(r, m)) {
+ ERR(r, "failed chxj_open_mysql_handle() query:[%s]", query);
+ return NULL;
+ }
+ connection.reconnect = 0;
+ if (mysql_query(connection.handle, query) != 0) {
+ if (mysql_errno(connection.handle) == CR_SERVER_GONE_ERROR) {
+ connection.reconnect = 1;
+ sleep(CHXJ_MYSQL_RECONNECT_WAIT_TIME);
+ continue;
+ }
+ WRN(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ return NULL;
+ }
+ }
+ while(0);
+
+ result = mysql_store_result(connection.handle);
+ if (result && (mysql_num_rows(result) >= 1)) {
+ MYSQL_ROW data = mysql_fetch_row(result);
+ if (! data[0]) {
+ ERR(r, "MySQL cookie_id:[%s] has no valid cookie_id. %s", cookie_id, r->uri);
+ mysql_free_result(result);
+ return NULL;
+ }
+ retval = (char *) apr_palloc(r->pool, 14 + 1);
+ memcpy(retval, data[0], 14);
+ }
+ if (result) mysql_free_result(result);
+
+ DBG(r, "end chxj_mysql_load_cookie_expire() query:[%s]", query);
+
+ return retval;
+}
+
+
+int
+chxj_mysql_delete_cookie(request_rec *r, mod_chxj_config *m, const char *cookie_id)
+{
+ MYSQL_RES *result;
+ char query[MAX_STRING_LEN];
+ char *cid = ap_escape_logitem(r->pool, cookie_id);
+
+ DBG(r, "start chxj_mysql_delete_cookie() cookie_id:[%s]", cookie_id);
+
+ do {
+ if (!chxj_open_mysql_handle(r, m)) {
+ ERR(r, "failed chxj_open_mysql_handle()");
+ return 0;
+ }
+ connection.reconnect = 0;
+ apr_snprintf(query, sizeof(query)-1, "BEGIN;");
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ if (mysql_errno(connection.handle) == CR_SERVER_GONE_ERROR) {
+ connection.reconnect = 1;
+ sleep(CHXJ_MYSQL_RECONNECT_WAIT_TIME);
+ continue;
+ }
+ ERR(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ return 0;
+ }
+ }
+ while(0);
+
+ if (!chxj_mysql_get_cookie_from_cookie_id(r, m, cookie_id)) {
+ ERR(r, "failed chxj_mysql_get_cookie_from_cookie_id() cookie_id:[%s]", cookie_id);
+ return 0;
+ }
+ apr_snprintf(query, sizeof(query)-1, "DELETE FROM %s WHERE cookie_id = '%s';", m->mysql.tablename, cid);
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ ERR(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ chxj_mysql_rollback(r, m);
+ return 0;
+ }
+
+ apr_snprintf(query, sizeof(query)-1, "COMMIT;");
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ ERR(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ chxj_mysql_rollback(r, m);
+ return 0;
+ }
+
+ result = mysql_store_result(connection.handle);
+ if (result) mysql_free_result(result);
+
+ DBG(r, "end chxj_mysql_delete_cookie()");
+
+ return 1;
+}
+
+
+int
+chxj_mysql_delete_cookie_expire(request_rec *r, mod_chxj_config *m, const char *cookie_id)
+{
+ MYSQL_RES *result;
+ char query[MAX_STRING_LEN];
+ char *cid = ap_escape_logitem(r->pool, cookie_id);
+
+ DBG(r, "start chxj_mysql_delete_cookie_expire() cookie_id:[%s]", cookie_id);
+
+ do {
+ if (!chxj_open_mysql_handle(r, m)) {
+ ERR(r, "failed chxj_open_mysql_handle()");
+ return 0;
+ }
+ connection.reconnect = 0;
+ apr_snprintf(query, sizeof(query)-1, "BEGIN;");
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ if (mysql_errno(connection.handle) == CR_SERVER_GONE_ERROR) {
+ connection.reconnect = 1;
+ sleep(CHXJ_MYSQL_RECONNECT_WAIT_TIME);
+ continue;
+ }
+ ERR(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ return 0;
+ }
+ }
+ while(0);
+
+ if (!chxj_mysql_get_cookie_expire_from_cookie_id(r, m, cookie_id)) {
+ ERR(r, "failed chxj_mysql_get_cookie_expire_from_cookie_id() cookie_id:[%s]", cookie_id);
+ return 0;
+ }
+ apr_snprintf(query, sizeof(query)-1, "DELETE FROM %s_expire WHERE cookie_id = '%s';", m->mysql.tablename, cid);
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ ERR(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ chxj_mysql_rollback(r, m);
+ return 0;
+ }
+
+ apr_snprintf(query, sizeof(query)-1, "COMMIT;");
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ ERR(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ chxj_mysql_rollback(r, m);
+ return 0;
+ }
+
+ result = mysql_store_result(connection.handle);
+ if (result) mysql_free_result(result);
+
+ DBG(r, "end chxj_mysql_delete_cookie_expire() cookie_id:[%s]", cookie_id);
+
+ return 1;
+}
+
+char *
+chxj_mysql_get_timeout_localtime(request_rec *r, mod_chxj_config *m)
+{
+ MYSQL_RES *result;
+ char query[MAX_STRING_LEN];
+ char *retval = NULL;
+
+ DBG(r, "start chxj_mysql_get_timeout_localtime()");
+ do {
+ if (!chxj_open_mysql_handle(r, m)) {
+ ERR(r, "failed chxj_open_mysql_handle()");
+ return 0;
+ }
+ connection.reconnect = 0;
+
+ apr_snprintf(query, sizeof(query)-1, "SELECT DATE_SUB(localtime, interval %ld second);",
+ (m->cookie_timeout == 0) ? DEFAULT_COOKIE_TIMEOUT : m->cookie_timeout);
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ if (mysql_errno(connection.handle) == CR_SERVER_GONE_ERROR) {
+ connection.reconnect = 1;
+ sleep(CHXJ_MYSQL_RECONNECT_WAIT_TIME);
+ continue;
+ }
+ ERR(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ return NULL;
+ }
+ }
+ while(0);
+ result = mysql_store_result(connection.handle);
+ if (result && (mysql_num_rows(result) >= 1)) {
+ MYSQL_ROW data = mysql_fetch_row(result);
+ if (! data[0]) {
+ ERR(r, "MySQL ERROR: %s: %s", mysql_error(connection.handle), r->uri);
+ mysql_free_result(result);
+ return NULL;
+ }
+ retval = (char *) apr_palloc(r->pool, 19 + 1);
+ memset(retval, 0, 19+1);
+ memcpy(retval, data[0], 19);
+ }
+ if (result) mysql_free_result(result);
+
+ DBG(r, "end chxj_mysql_get_timeout_localtime()");
+
+ return retval;
+}
+
+int
+chxj_mysql_delete_expired_cookie(request_rec *r, mod_chxj_config *m)
+{
+ MYSQL_RES *result;
+ char query[MAX_STRING_LEN];
+ char *timeout;
+ DBG(r, "start chxj_mysql_delete_expired_cookie()");
+
+ do {
+ if (!chxj_open_mysql_handle(r, m)) {
+ ERR(r, "failed chxj_open_mysql_handle()");
+ return 0;
+ }
+ connection.reconnect = 0;
+ apr_snprintf(query, sizeof(query)-1, "BEGIN;");
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ if (mysql_errno(connection.handle) == CR_SERVER_GONE_ERROR) {
+ connection.reconnect = 1;
+ sleep(CHXJ_MYSQL_RECONNECT_WAIT_TIME);
+ continue;
+ }
+ ERR(r, "MySQL ERROR: %s: %s", mysql_error(connection.handle), r->uri);
+ return 0;
+ }
+ }
+ while (0);
+
+ timeout = chxj_mysql_get_timeout_localtime(r, m);
+ if (! timeout) {
+ ERR(r, "MySQL ERROR: %s: %s", mysql_error(connection.handle), r->uri);
+ return 0;
+ }
+
+ apr_snprintf(query, sizeof(query)-1, "SELECT * FROM %s_expire WHERE created_at <= '%s'", m->mysql.tablename, timeout);
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ ERR(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ chxj_mysql_rollback(r, m);
+ return 0;
+ }
+ result = mysql_store_result(connection.handle);
+ if (result) mysql_free_result(result);
+ result = NULL;
+
+ /* delete from chxj_cookie */
+ apr_snprintf(query, sizeof(query)-1, "DELETE %s FROM %s, %s_expire WHERE %s_expire.created_at <= '%s' AND %s.cookie_id = %s_expire.cookie_id;",
+ m->mysql.tablename,
+ m->mysql.tablename,
+ m->mysql.tablename,
+ m->mysql.tablename,
+ timeout,
+ m->mysql.tablename,
+ m->mysql.tablename);
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ ERR(r, "MySQL ERROR: %s: %s", mysql_error(connection.handle), r->uri);
+ chxj_mysql_rollback(r, m);
+ return 0;
+ }
+ result = mysql_store_result(connection.handle);
+ if (result) mysql_free_result(result);
+ result = NULL;
+
+ /* delete from chxj_cookie_expire */
+ apr_snprintf(query, sizeof(query)-1, "DELETE %s_expire FROM %s_expire WHERE %s_expire.created_at <= '%s';",
+ m->mysql.tablename,
+ m->mysql.tablename,
+ m->mysql.tablename,
+ timeout);
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ ERR(r, "MySQL ERROR: %s: %s", mysql_error(connection.handle), r->uri);
+ chxj_mysql_rollback(r, m);
+ return 0;
+ }
+ result = mysql_store_result(connection.handle);
+ if (result) mysql_free_result(result);
+ result = NULL;
+
+ apr_snprintf(query, sizeof(query)-1, "COMMIT;");
+ DBG(r, "query:[%s]", query);
+ if (mysql_query(connection.handle, query) != 0) {
+ ERR(r, "MySQL WARN: %s: %s", mysql_error(connection.handle), r->uri);
+ chxj_mysql_rollback(r, m);
+ return 0;
+ }
+
+ result = mysql_store_result(connection.handle);
+ if (result) mysql_free_result(result);
+
+ DBG(r, "end chxj_mysql_delete_expired_cookie()");
+ return 1;
+}
#endif
/*
#include "chxj_chtml20.h"
#include "chxj_chtml30.h"
#include "chxj_jhtml.h"
+#ifdef USE_MYSQL_COOKIE
+#include "chxj_mysql.h"
+#endif
#include "chxj_img_conv_format.h"
#include "chxj_qr_code.h"
DBG(r, "call start chxj_load_cookie()");
cookie = chxj_load_cookie(r, value);
DBG(r, "call end chxj_load_cookie()");
- if (! no_update_flag) {
+ if (! no_update_flag && cookie) {
chxj_update_cookie(r, cookie);
}
}
DBG(r, "call start chxj_load_cookie()");
cookie = chxj_load_cookie(r, value);
DBG(r, "call end chxj_load_cookie()");
- if (! no_update_flag) {
+ if (! no_update_flag && cookie) {
chxj_update_cookie(r, cookie);
}
}
conf->server_side_encoding = NULL;
conf->cookie_db_dir = NULL;
conf->cookie_timeout = 0;
+#ifdef USE_MYSQL_COOKIE
+ memset((void*)&conf->mysql, 0, sizeof(mysql_t));
+ conf->mysql.port = MYSQL_PORT;
+ conf->mysql.host = NULL;
+#endif
if (arg == NULL) {
conf->dir = NULL;
mrg->cookie_timeout = 0;
}
+#ifdef USE_MYSQL_COOKIE
+ if (add->mysql.host) {
+ mrg->mysql.host = apr_pstrdup(p, add->mysql.host);
+ }
+ else if (base->mysql.host) {
+ mrg->mysql.host = apr_pstrdup(p, base->mysql.host);
+ }
+ else {
+ mrg->mysql.host = NULL;
+ }
+ if (add->mysql.port) {
+ mrg->mysql.port = add->mysql.port;
+ }
+ else if (base->mysql.port) {
+ mrg->mysql.port = base->mysql.port;
+ }
+ else {
+ mrg->mysql.port = 0;
+ }
+
+ if (add->mysql.database) {
+ mrg->mysql.database = apr_pstrdup(p, add->mysql.database);
+ }
+ else if (base->mysql.database) {
+ mrg->mysql.database = apr_pstrdup(p, base->mysql.database);
+ }
+ else {
+ mrg->mysql.database = NULL;
+ }
+
+ if (add->mysql.username) {
+ mrg->mysql.username = apr_pstrdup(p, add->mysql.username);
+ }
+ else if (base->mysql.username) {
+ mrg->mysql.username = apr_pstrdup(p, base->mysql.username);
+ }
+ else {
+ mrg->mysql.username = NULL;
+ }
+
+ if (add->mysql.password) {
+ mrg->mysql.password = apr_pstrdup(p, add->mysql.password);
+ }
+ else if (base->mysql.password) {
+ mrg->mysql.password = apr_pstrdup(p, base->mysql.password);
+ }
+ else {
+ mrg->mysql.password = NULL;
+ }
+
+ if (add->mysql.tablename) {
+ mrg->mysql.tablename = apr_pstrdup(p, add->mysql.tablename);
+ }
+ else if (base->mysql.tablename) {
+ mrg->mysql.tablename = apr_pstrdup(p, base->mysql.tablename);
+ }
+ else {
+ mrg->mysql.tablename = NULL;
+ }
+
+ if (add->mysql.socket_path) {
+ mrg->mysql.socket_path = apr_pstrdup(p, add->mysql.socket_path);
+ }
+ else if (base->mysql.socket_path) {
+ mrg->mysql.socket_path = apr_pstrdup(p, base->mysql.socket_path);
+ }
+ else {
+ mrg->mysql.socket_path = NULL;
+ }
+
+ if (add->mysql.charset) {
+ mrg->mysql.charset = apr_pstrdup(p, add->mysql.charset);
+ }
+ else if (base->mysql.charset) {
+ mrg->mysql.charset = apr_pstrdup(p, base->mysql.charset);
+ }
+ else {
+ mrg->mysql.charset = NULL;
+ }
+
+#endif
return mrg;
}
}
+#ifdef USE_MYSQL_COOKIE
+static const char *
+cmd_set_cookie_mysql_database(
+ cmd_parms *cmd,
+ void *mconfig,
+ const char *arg)
+{
+ mod_chxj_config *dconf;
+
+ if (strlen(arg) > 255)
+ return "mod_chxj: ChxjCookieMysqlDatabase is too long.";
+
+ dconf = (mod_chxj_config *)mconfig;
+
+ dconf->mysql.database = apr_pstrdup(cmd->pool, arg);
+
+ return NULL;
+}
+
+
+static const char *
+cmd_set_cookie_mysql_username(
+ cmd_parms *cmd,
+ void *mconfig,
+ const char *arg)
+{
+ mod_chxj_config *dconf;
+
+ if (strlen(arg) > 255)
+ return "mod_chxj: ChxjCookieMysqlUsername is too long.";
+
+ dconf = (mod_chxj_config *)mconfig;
+
+ dconf->mysql.username = apr_pstrdup(cmd->pool, arg);
+
+ return NULL;
+}
+
+
+static const char *
+cmd_set_cookie_mysql_password(
+ cmd_parms *cmd,
+ void *mconfig,
+ const char *arg)
+{
+ mod_chxj_config *dconf;
+
+ if (strlen(arg) > 255)
+ return "mod_chxj: ChxjCookieMysqlPassword is too long.";
+
+ dconf = (mod_chxj_config *)mconfig;
+
+ dconf->mysql.password = apr_pstrdup(cmd->pool, arg);
+
+ return NULL;
+}
+
+
+static const char *
+cmd_set_cookie_mysql_table_name(
+ cmd_parms *cmd,
+ void *mconfig,
+ const char *arg)
+{
+ mod_chxj_config *dconf;
+
+ if (strlen(arg) > 255)
+ return "mod_chxj: ChxjCookieMysqlTableName is too long.";
+
+ dconf = (mod_chxj_config *)mconfig;
+
+ dconf->mysql.tablename = apr_pstrdup(cmd->pool, arg);
+
+ return NULL;
+}
+
+static const char *
+cmd_set_cookie_mysql_port(
+ cmd_parms *UNUSED(cmd),
+ void *mconfig,
+ const char *arg)
+{
+ mod_chxj_config *dconf;
+
+ if (strlen(arg) > 255)
+ return "mod_chxj: ChxjCookieMysqlPort is too long.";
+
+ dconf = (mod_chxj_config *)mconfig;
+
+ if (chxj_chk_numeric(arg) != 0)
+ return "mod_chxj: ChxjCookieMysqlPort is not numeric.";
+
+ dconf = (mod_chxj_config *)mconfig;
+
+ dconf->mysql.port = chxj_atoi(arg);
+
+ return NULL;
+}
+
+
+static const char *
+cmd_set_cookie_mysql_host(
+ cmd_parms *cmd,
+ void *mconfig,
+ const char *arg)
+{
+ mod_chxj_config *dconf;
+
+ if (strlen(arg) > 255)
+ return "mod_chxj: ChxjCookieMysqlHost is too long.";
+
+ dconf = (mod_chxj_config *)mconfig;
+
+ dconf->mysql.host = apr_pstrdup(cmd->pool, arg);
+fprintf(stderr, "mysql.host=[%s]\n", dconf->mysql.host);
+
+ return NULL;
+}
+
+
+static const char *
+cmd_set_cookie_mysql_socket_path(
+ cmd_parms *cmd,
+ void *mconfig,
+ const char *arg)
+{
+ mod_chxj_config *dconf;
+
+ if (strlen(arg) > 4096)
+ return "mod_chxj: ChxjCookieMysqlSocketPath is too long.";
+
+ dconf = (mod_chxj_config *)mconfig;
+
+ dconf->mysql.socket_path = apr_pstrdup(cmd->pool, arg);
+
+ return NULL;
+}
+
+
+static const char *
+cmd_set_cookie_mysql_charset(
+ cmd_parms *cmd,
+ void *mconfig,
+ const char *arg)
+{
+ mod_chxj_config *dconf;
+
+ if (strlen(arg) > 255)
+ return "mod_chxj: ChxjCookieMysqlCharset is too long.";
+
+ dconf = (mod_chxj_config *)mconfig;
+
+ dconf->mysql.charset = apr_pstrdup(cmd->pool, arg);
+
+ return NULL;
+}
+#endif
+
+
static const command_rec cmds[] = {
AP_INIT_TAKE1(
"ChxjLoadDeviceData",
NULL,
OR_ALL,
"The compulsion time-out time of the cookie is specified. "),
+#ifdef USE_MYSQL_COOKIE
+ AP_INIT_TAKE1(
+ "ChxjCookieMysqlHost",
+ cmd_set_cookie_mysql_host,
+ NULL,
+ OR_ALL,
+ "The MySQL database host used by saving Cookie"),
+ AP_INIT_TAKE1(
+ "ChxjCookieMysqlPort",
+ cmd_set_cookie_mysql_port,
+ NULL,
+ OR_ALL,
+ "The MySQL database port used by saving Cookie"),
+ AP_INIT_TAKE1(
+ "ChxjCookieMysqlDatabase",
+ cmd_set_cookie_mysql_database,
+ NULL,
+ OR_ALL,
+ "The MySQL database name used by saving Cookie"),
+ AP_INIT_TAKE1(
+ "ChxjCookieMysqlUsername",
+ cmd_set_cookie_mysql_username,
+ NULL,
+ OR_ALL,
+ "The MySQL username used by saving Cookie"),
+ AP_INIT_TAKE1(
+ "ChxjCookieMysqlPassword",
+ cmd_set_cookie_mysql_password,
+ NULL,
+ OR_ALL,
+ "The MySQL password used by saving Cookie"),
+ AP_INIT_TAKE1(
+ "ChxjCookieMysqlTableName",
+ cmd_set_cookie_mysql_table_name,
+ NULL,
+ OR_ALL,
+ "The MySQL table name used by saving Cookie"),
+ AP_INIT_TAKE1(
+ "ChxjCookieMysqlSocketPath",
+ cmd_set_cookie_mysql_socket_path,
+ NULL,
+ OR_ALL,
+ "The MySQL socket path used by saving Cookie"),
+ AP_INIT_TAKE1(
+ "ChxjCookieMysqlCharset",
+ cmd_set_cookie_mysql_charset,
+ NULL,
+ OR_ALL,
+ "The MySQL charset used by saving Cookie"),
+#endif
{NULL}
};