From a00c9ca392f7462c3f3342bb37a9d2ff8322384a Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 4 Oct 2008 03:02:35 +0000 Subject: [PATCH] 2008-10-04 Tatsuhiro Tsujikawa Use sqlite3_open if sqlite3_open_v2 is not available. * src/Sqlite3MozCookieParser.cc * src/Sqlite3MozCookieParser.h * m4/sqlite3.m4 * test/Sqlite3MozCookieParserTest.cc --- ChangeLog | 8 +++ config.h.in | 3 + configure | 94 ++++++++++++++++++++++++++++++ m4/sqlite3.m4 | 1 + src/Sqlite3MozCookieParser.cc | 19 +++++- src/Sqlite3MozCookieParser.h | 4 +- test/Sqlite3MozCookieParserTest.cc | 9 ++- 7 files changed, 133 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2b7e5550..5a890a44 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-10-04 Tatsuhiro Tsujikawa + + Use sqlite3_open if sqlite3_open_v2 is not available. + * src/Sqlite3MozCookieParser.cc + * src/Sqlite3MozCookieParser.h + * m4/sqlite3.m4 + * test/Sqlite3MozCookieParserTest.cc + 2008-10-02 Tatsuhiro Tsujikawa Replaced '%zu' with '%lu' since mingw32 doesn't recognize '%zu'. diff --git a/config.h.in b/config.h.in index d7e3bcda..58029226 100644 --- a/config.h.in +++ b/config.h.in @@ -328,6 +328,9 @@ /* Define to 1 if you have sqlite3. */ #undef HAVE_SQLITE3 +/* Define to 1 if you have the `sqlite3_open_v2' function. */ +#undef HAVE_SQLITE3_OPEN_V2 + /* Define to 1 if `stat' has the bug that it succeeds when given the zero-length file name argument. */ #undef HAVE_STAT_EMPTY_STRING_BUG diff --git a/configure b/configure index 5a0a48fe..b28abee2 100755 --- a/configure +++ b/configure @@ -6069,6 +6069,100 @@ fi fi if test "x$have_sqlite3" = "xyes"; then +for ac_func in sqlite3_open_v2 +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +{ echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6; } +if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define $ac_func to an innocuous variant, in case declares $ac_func. + For example, HP-UX 11i declares gettimeofday. */ +#define $ac_func innocuous_$ac_func + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $ac_func + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined __stub_$ac_func || defined __stub___$ac_func +choke me +#endif + +int +main () +{ +return $ac_func (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + eval "$as_ac_var=no" +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +fi +ac_res=`eval echo '${'$as_ac_var'}'` + { echo "$as_me:$LINENO: result: $ac_res" >&5 +echo "${ECHO_T}$ac_res" >&6; } +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + cat >>confdefs.h <<\_ACEOF #define HAVE_SQLITE3 1 _ACEOF diff --git a/m4/sqlite3.m4 b/m4/sqlite3.m4 index aa987819..bc6e18a5 100644 --- a/m4/sqlite3.m4 +++ b/m4/sqlite3.m4 @@ -42,6 +42,7 @@ if test "x$have_sqlite3" != "xyes"; then fi fi if test "x$have_sqlite3" = "xyes"; then + AC_CHECK_FUNCS([sqlite3_open_v2]) AC_DEFINE([HAVE_SQLITE3], [1], [Define to 1 if you have sqlite3.]) AC_SUBST(SQLITE3_LIBS) AC_SUBST(SQLITE3_CPPFLAGS) diff --git a/src/Sqlite3MozCookieParser.cc b/src/Sqlite3MozCookieParser.cc index c02eecaf..cf6b69b9 100644 --- a/src/Sqlite3MozCookieParser.cc +++ b/src/Sqlite3MozCookieParser.cc @@ -33,12 +33,18 @@ */ /* copyright --> */ #include "Sqlite3MozCookieParser.h" + +#include + +#include + #include "RecoverableException.h" #include "Util.h" #include "StringFormat.h" #include "A2STR.h" -#include -#include +#ifndef HAVE_SQLITE3_OPEN_V2 +# include "File.h" +#endif // !HAVE_SQLITE3_OPEN_V2 namespace aria2 { @@ -88,7 +94,16 @@ Sqlite3MozCookieParser::parse(const std::string& filename) const sqlite3* db = 0; int ret; +#ifdef HAVE_SQLITE3_OPEN_V2 ret = sqlite3_open_v2(filename.c_str(), &db, SQLITE_OPEN_READONLY, 0); +#else // !HAVE_SQLITE3_OPEN_V2 + if(!File(filename).isFile()) { + throw RecoverableException + (StringFormat("Failed to open SQLite3 database: %s", + filename.c_str()).str()); + } + ret = sqlite3_open(filename.c_str(), &db); +#endif // !HAVE_SQLITE3_OPEN_V2 if(SQLITE_OK != ret) { std::string errMsg = sqlite3_errmsg(db); sqlite3_close(db); diff --git a/src/Sqlite3MozCookieParser.h b/src/Sqlite3MozCookieParser.h index 103ce279..ecf07dd7 100644 --- a/src/Sqlite3MozCookieParser.h +++ b/src/Sqlite3MozCookieParser.h @@ -36,10 +36,12 @@ #define _D_SQLITE3_MOZ_COOKIE_PARSER_H_ #include "common.h" -#include "Cookie.h" + #include #include +#include "Cookie.h" + namespace aria2 { class Sqlite3MozCookieParser { diff --git a/test/Sqlite3MozCookieParserTest.cc b/test/Sqlite3MozCookieParserTest.cc index 20abf180..8460e944 100644 --- a/test/Sqlite3MozCookieParserTest.cc +++ b/test/Sqlite3MozCookieParserTest.cc @@ -1,8 +1,11 @@ #include "Sqlite3MozCookieParser.h" + +#include + +#include + #include "RecoverableException.h" #include "Util.h" -#include -#include namespace aria2 { @@ -68,6 +71,8 @@ void Sqlite3MozCookieParserTest::testParse_fileNotFound() CPPUNIT_FAIL("exception must be thrown."); } catch(RecoverableException& e) { // SUCCESS + CPPUNIT_ASSERT(Util::startsWith(e.what(), + "Failed to open SQLite3 database:")); } }