浏览代码

2010-07-09 Tatsuhiro Tsujikawa <[email protected]>

	Added Chromium/Google Chrome Cookies file support. Thanks to
	gotrunks for original patch.
	* src/CookieStorage.cc
	* src/Makefile.am
	* src/Sqlite3CookieParser.cc
	* src/Sqlite3CookieParser.h
	* src/Sqlite3CookieParserImpl.cc
	* src/Sqlite3CookieParserImpl.h
	* src/Sqlite3MozCookieParser.cc: Removed
	* src/Sqlite3MozCookieParser.h: Removed
	* test/Makefile.am
	* test/Sqlite3CookieParserTest.cc
	* test/Sqlite3MozCookieParserTest.cc: Removed
	* test/chromium_cookies.sqlite
Tatsuhiro Tsujikawa 15 年之前
父节点
当前提交
95af338895

+ 17 - 0
ChangeLog

@@ -1,3 +1,20 @@
+2010-07-09  Tatsuhiro Tsujikawa  <[email protected]>
+
+	Added Chromium/Google Chrome Cookies file support. Thanks to
+	gotrunks for original patch.
+	* src/CookieStorage.cc
+	* src/Makefile.am
+	* src/Sqlite3CookieParser.cc
+	* src/Sqlite3CookieParser.h
+	* src/Sqlite3CookieParserImpl.cc
+	* src/Sqlite3CookieParserImpl.h
+	* src/Sqlite3MozCookieParser.cc: Removed
+	* src/Sqlite3MozCookieParser.h: Removed
+	* test/Makefile.am
+	* test/Sqlite3CookieParserTest.cc
+	* test/Sqlite3MozCookieParserTest.cc: Removed
+	* test/chromium_cookies.sqlite
+
 2010-07-04  Tatsuhiro Tsujikawa  <[email protected]>
 2010-07-04  Tatsuhiro Tsujikawa  <[email protected]>
 
 
 	When allocating disk space, for Linux system with fallocate()
 	When allocating disk space, for Linux system with fallocate()

+ 14 - 2
src/CookieStorage.cc

@@ -47,8 +47,9 @@
 #include "File.h"
 #include "File.h"
 #include "a2functional.h"
 #include "a2functional.h"
 #include "A2STR.h"
 #include "A2STR.h"
+#include "message.h"
 #ifdef HAVE_SQLITE3
 #ifdef HAVE_SQLITE3
-# include "Sqlite3MozCookieParser.h"
+# include "Sqlite3CookieParserImpl.h"
 #endif // HAVE_SQLITE3
 #endif // HAVE_SQLITE3
 
 
 namespace aria2 {
 namespace aria2 {
@@ -300,7 +301,18 @@ bool CookieStorage::load(const std::string& filename)
   try {
   try {
     if(std::string(header) == "SQLite format 3") {
     if(std::string(header) == "SQLite format 3") {
 #ifdef HAVE_SQLITE3
 #ifdef HAVE_SQLITE3
-      std::vector<Cookie> cookies = Sqlite3MozCookieParser().parse(filename);
+      std::vector<Cookie> cookies;
+      try {
+        Sqlite3MozCookieParser(filename).parse(cookies);
+      } catch(RecoverableException& e) {
+        if(logger_->info()) {
+          logger_->info(EX_EXCEPTION_CAUGHT, e);
+          logger_->info("This does not look like Firefox3 cookie file."
+                        " Retrying, assuming it is Chromium cookie file.");
+        }
+        // Try chrome cookie format
+        Sqlite3ChromiumCookieParser(filename).parse(cookies);
+      }
       storeCookies(cookies.begin(), cookies.end());
       storeCookies(cookies.begin(), cookies.end());
 #else // !HAVE_SQLITE3
 #else // !HAVE_SQLITE3
       throw DL_ABORT_EX
       throw DL_ABORT_EX

+ 2 - 1
src/Makefile.am

@@ -262,7 +262,8 @@ SRCS += GZipDecoder.cc GZipDecoder.h\
 endif # HAVE_LIBZ
 endif # HAVE_LIBZ
 
 
 if HAVE_SQLITE3
 if HAVE_SQLITE3
-SRCS += Sqlite3MozCookieParser.cc Sqlite3MozCookieParser.h
+SRCS += Sqlite3CookieParser.cc Sqlite3CookieParser.h\
+	Sqlite3CookieParserImpl.cc Sqlite3CookieParserImpl.h
 endif # HAVE_SQLITE3
 endif # HAVE_SQLITE3
 
 
 if ENABLE_ASYNC_DNS
 if ENABLE_ASYNC_DNS

+ 9 - 4
src/Makefile.in

@@ -64,7 +64,9 @@ bin_PROGRAMS = aria2c$(EXEEXT)
 @HAVE_LIBZ_TRUE@am__append_9 = GZipDecoder.cc GZipDecoder.h\
 @HAVE_LIBZ_TRUE@am__append_9 = GZipDecoder.cc GZipDecoder.h\
 @HAVE_LIBZ_TRUE@	GZipEncoder.cc GZipEncoder.h
 @HAVE_LIBZ_TRUE@	GZipEncoder.cc GZipEncoder.h
 
 
-@HAVE_SQLITE3_TRUE@am__append_10 = Sqlite3MozCookieParser.cc Sqlite3MozCookieParser.h
+@HAVE_SQLITE3_TRUE@am__append_10 = Sqlite3CookieParser.cc Sqlite3CookieParser.h\
+@HAVE_SQLITE3_TRUE@	Sqlite3CookieParserImpl.cc Sqlite3CookieParserImpl.h
+
 @ENABLE_ASYNC_DNS_TRUE@am__append_11 = AsyncNameResolver.cc AsyncNameResolver.h
 @ENABLE_ASYNC_DNS_TRUE@am__append_11 = AsyncNameResolver.cc AsyncNameResolver.h
 @ENABLE_MESSAGE_DIGEST_TRUE@am__append_12 = IteratableChunkChecksumValidator.cc IteratableChunkChecksumValidator.h\
 @ENABLE_MESSAGE_DIGEST_TRUE@am__append_12 = IteratableChunkChecksumValidator.cc IteratableChunkChecksumValidator.h\
 @ENABLE_MESSAGE_DIGEST_TRUE@	IteratableChecksumValidator.cc IteratableChecksumValidator.h\
 @ENABLE_MESSAGE_DIGEST_TRUE@	IteratableChecksumValidator.cc IteratableChecksumValidator.h\
@@ -461,7 +463,8 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
 	LibgnutlsTLSContext.cc LibgnutlsTLSContext.h \
 	LibgnutlsTLSContext.cc LibgnutlsTLSContext.h \
 	LibsslTLSContext.cc LibsslTLSContext.h GZipDecoder.cc \
 	LibsslTLSContext.cc LibsslTLSContext.h GZipDecoder.cc \
 	GZipDecoder.h GZipEncoder.cc GZipEncoder.h \
 	GZipDecoder.h GZipEncoder.cc GZipEncoder.h \
-	Sqlite3MozCookieParser.cc Sqlite3MozCookieParser.h \
+	Sqlite3CookieParser.cc Sqlite3CookieParser.h \
+	Sqlite3CookieParserImpl.cc Sqlite3CookieParserImpl.h \
 	AsyncNameResolver.cc AsyncNameResolver.h \
 	AsyncNameResolver.cc AsyncNameResolver.h \
 	IteratableChunkChecksumValidator.cc \
 	IteratableChunkChecksumValidator.cc \
 	IteratableChunkChecksumValidator.h \
 	IteratableChunkChecksumValidator.h \
@@ -638,7 +641,8 @@ am__objects_6 =
 @HAVE_LIBSSL_TRUE@am__objects_8 = LibsslTLSContext.$(OBJEXT)
 @HAVE_LIBSSL_TRUE@am__objects_8 = LibsslTLSContext.$(OBJEXT)
 @HAVE_LIBZ_TRUE@am__objects_9 = GZipDecoder.$(OBJEXT) \
 @HAVE_LIBZ_TRUE@am__objects_9 = GZipDecoder.$(OBJEXT) \
 @HAVE_LIBZ_TRUE@	GZipEncoder.$(OBJEXT)
 @HAVE_LIBZ_TRUE@	GZipEncoder.$(OBJEXT)
-@HAVE_SQLITE3_TRUE@am__objects_10 = Sqlite3MozCookieParser.$(OBJEXT)
+@HAVE_SQLITE3_TRUE@am__objects_10 = Sqlite3CookieParser.$(OBJEXT) \
+@HAVE_SQLITE3_TRUE@	Sqlite3CookieParserImpl.$(OBJEXT)
 @ENABLE_ASYNC_DNS_TRUE@am__objects_11 = AsyncNameResolver.$(OBJEXT)
 @ENABLE_ASYNC_DNS_TRUE@am__objects_11 = AsyncNameResolver.$(OBJEXT)
 @ENABLE_MESSAGE_DIGEST_TRUE@am__objects_12 = IteratableChunkChecksumValidator.$(OBJEXT) \
 @ENABLE_MESSAGE_DIGEST_TRUE@am__objects_12 = IteratableChunkChecksumValidator.$(OBJEXT) \
 @ENABLE_MESSAGE_DIGEST_TRUE@	IteratableChecksumValidator.$(OBJEXT) \
 @ENABLE_MESSAGE_DIGEST_TRUE@	IteratableChecksumValidator.$(OBJEXT) \
@@ -1606,7 +1610,8 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SocketBuffer.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SocketBuffer.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SocketCore.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SocketCore.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SpeedCalc.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SpeedCalc.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Sqlite3MozCookieParser.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Sqlite3CookieParser.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Sqlite3CookieParserImpl.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StreamCheckIntegrityEntry.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StreamCheckIntegrityEntry.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StreamFileAllocationEntry.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StreamFileAllocationEntry.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StringFormat.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StringFormat.Po@am__quote@

+ 31 - 37
src/Sqlite3MozCookieParser.cc → src/Sqlite3CookieParser.cc

@@ -2,7 +2,7 @@
 /*
 /*
  * aria2 - The high speed download utility
  * aria2 - The high speed download utility
  *
  *
- * Copyright (C) 2006 Tatsuhiro Tsujikawa
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
  *
  *
  * This program is free software; you can redistribute it and/or modify
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * it under the terms of the GNU General Public License as published by
@@ -32,12 +32,10 @@
  * files in the program, then also delete it here.
  * files in the program, then also delete it here.
  */
  */
 /* copyright --> */
 /* copyright --> */
-#include "Sqlite3MozCookieParser.h"
+#include "Sqlite3CookieParser.h"
 
 
 #include <cstring>
 #include <cstring>
 
 
-#include <sqlite3.h>
-
 #include "DlAbortEx.h"
 #include "DlAbortEx.h"
 #include "util.h"
 #include "util.h"
 #include "StringFormat.h"
 #include "StringFormat.h"
@@ -48,9 +46,27 @@
 
 
 namespace aria2 {
 namespace aria2 {
 
 
-Sqlite3MozCookieParser::Sqlite3MozCookieParser() {}
+Sqlite3CookieParser::Sqlite3CookieParser(const std::string& filename):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()) {
+    return;
+  }
+  ret = sqlite3_open(filename.c_str(), &db_);
+#endif // !HAVE_SQLITE3_OPEN_V2
+  if(SQLITE_OK != ret) {
+    sqlite3_close(db_);
+    db_ = 0;
+  }
+}
 
 
-Sqlite3MozCookieParser::~Sqlite3MozCookieParser() {}
+Sqlite3CookieParser::~Sqlite3CookieParser()
+{
+  sqlite3_close(db_);
+}
 
 
 static std::string toString(const char* str)
 static std::string toString(const char* str)
 {
 {
@@ -91,47 +107,25 @@ static int cookieRowMapper(void* data, int rowIndex,
   return 0;
   return 0;
 }
 }
 
 
-std::vector<Cookie>
-Sqlite3MozCookieParser::parse(const std::string& filename) const
+void Sqlite3CookieParser::parse(std::vector<Cookie>& cookies)
 {
 {
-  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 DL_ABORT_EX
-      (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);
-    throw DL_ABORT_EX
-      (StringFormat("Failed to open SQLite3 database: %s",
-                    errMsg.c_str()).str());
+  if(!db_) {
+    throw DL_ABORT_EX(StringFormat("SQLite3 database is not opened.").str());
   }
   }
-  std::vector<Cookie> cookies;
+  std::vector<Cookie> tcookies;
   char* sqlite3ErrMsg = 0;
   char* sqlite3ErrMsg = 0;
-  static const char* QUERY =
-    "SELECT host, path, isSecure, expiry, name, value FROM moz_cookies";
-  ret = sqlite3_exec(db, QUERY, cookieRowMapper, &cookies, &sqlite3ErrMsg);
+  int ret = sqlite3_exec(db_, getQuery().c_str(), cookieRowMapper,
+                         &tcookies, &sqlite3ErrMsg);
   std::string errMsg;
   std::string errMsg;
   if(sqlite3ErrMsg) {
   if(sqlite3ErrMsg) {
     errMsg = sqlite3ErrMsg;
     errMsg = sqlite3ErrMsg;
     sqlite3_free(sqlite3ErrMsg);
     sqlite3_free(sqlite3ErrMsg);
   }
   }
   if(SQLITE_OK != ret) {
   if(SQLITE_OK != ret) {
-    sqlite3_close(db);
-    throw DL_ABORT_EX
-      (StringFormat("Failed to read SQLite3 database: %s",
-                    errMsg.c_str()).str());
+    throw DL_ABORT_EX(StringFormat("Failed to read SQLite3 database: %s",
+                                   errMsg.c_str()).str());
   }
   }
-  sqlite3_close(db);
-  return cookies;
+  cookies.swap(tcookies);
 }
 }
 
 
 } // namespace aria2
 } // namespace aria2

+ 71 - 0
src/Sqlite3CookieParser.h

@@ -0,0 +1,71 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#ifndef D_SQLITE3_COOKIE_PARSER_H
+#define D_SQLITE3_COOKIE_PARSER_H
+
+#include "common.h"
+
+#include <string>
+#include <vector>
+
+#include <sqlite3.h>
+
+#include "Cookie.h"
+
+namespace aria2 {
+
+class Sqlite3CookieParser {
+public:
+  Sqlite3CookieParser(const std::string& filename);
+
+  virtual ~Sqlite3CookieParser();
+
+  // Loads cookies from sqlite3 database and stores them in cookies.
+  // When loading is successful, cookies stored in cookies initially
+  // are removed. Otherwise, the content of cookies is unchanged.
+  void parse(std::vector<Cookie>& cookies);
+protected:
+  // Returns SQL select statement to get 1 record of cookie.  The sql
+  // must return 6 columns in the following order: host, path,
+  // secure(1 for secure, 0 for not), expiry(utc, unix time), name,
+  // value
+  virtual const std::string& getQuery() const = 0;
+private:
+  sqlite3* db_;
+};
+
+} // namespace aria2
+
+#endif // D_SQLITE3_COOKIE_PARSER_H

+ 63 - 0
src/Sqlite3CookieParserImpl.cc

@@ -0,0 +1,63 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#include "Sqlite3CookieParserImpl.h"
+
+namespace aria2 {
+
+Sqlite3MozCookieParser::Sqlite3MozCookieParser(const std::string& filename):
+  Sqlite3CookieParser(filename) {}
+
+Sqlite3MozCookieParser::~Sqlite3MozCookieParser() {}
+
+const std::string& Sqlite3MozCookieParser::getQuery() const
+{
+  static const std::string& sql =
+    "SELECT host, path, isSecure, expiry, name, value FROM moz_cookies";
+  return sql;
+}
+
+Sqlite3ChromiumCookieParser::Sqlite3ChromiumCookieParser
+(const std::string& filename):Sqlite3CookieParser(filename) {}
+
+Sqlite3ChromiumCookieParser::~Sqlite3ChromiumCookieParser() {}
+
+const std::string& Sqlite3ChromiumCookieParser::getQuery() const
+{
+  static const std::string& sql =
+    "SELECT host_key, path, secure, expires_utc, name, value FROM cookies";
+  return sql;
+}
+
+} // namespace aria2

+ 17 - 15
src/Sqlite3MozCookieParser.h → src/Sqlite3CookieParserImpl.h

@@ -2,7 +2,7 @@
 /*
 /*
  * aria2 - The high speed download utility
  * aria2 - The high speed download utility
  *
  *
- * Copyright (C) 2006 Tatsuhiro Tsujikawa
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
  *
  *
  * This program is free software; you can redistribute it and/or modify
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * it under the terms of the GNU General Public License as published by
@@ -32,27 +32,29 @@
  * files in the program, then also delete it here.
  * files in the program, then also delete it here.
  */
  */
 /* copyright --> */
 /* copyright --> */
-#ifndef _D_SQLITE3_MOZ_COOKIE_PARSER_H_
-#define _D_SQLITE3_MOZ_COOKIE_PARSER_H_
+#ifndef D_SQLITE3_COOKIE_PARSER_IMPL_H
+#define D_SQLITE3_COOKIE_PARSER_IMPL_H
 
 
-#include "common.h"
-
-#include <string>
-#include <vector>
-
-#include "Cookie.h"
+#include "Sqlite3CookieParser.h"
 
 
 namespace aria2 {
 namespace aria2 {
 
 
-class Sqlite3MozCookieParser {
+class Sqlite3MozCookieParser:public Sqlite3CookieParser {
 public:
 public:
-  Sqlite3MozCookieParser();
-
-  ~Sqlite3MozCookieParser();
+  Sqlite3MozCookieParser(const std::string& filename);
+  virtual ~Sqlite3MozCookieParser();
+protected:
+  virtual const std::string& getQuery() const;
+};
 
 
-  std::vector<Cookie> parse(const std::string& filename) const;
+class Sqlite3ChromiumCookieParser:public Sqlite3CookieParser {
+public:
+  Sqlite3ChromiumCookieParser(const std::string& filename);
+  virtual ~Sqlite3ChromiumCookieParser();
+protected:
+  virtual const std::string& getQuery() const;
 };
 };
 
 
 } // namespace aria2
 } // namespace aria2
 
 
-#endif // _D_SQLITE3_MOZ_COOKIE_PARSER_H_
+#endif // D_SQLITE3_COOKIE_PARSER_IMPL_H

+ 2 - 1
test/Makefile.am

@@ -90,7 +90,7 @@ aria2c_SOURCES += GZipDecoderTest.cc\
 endif # HAVE_LIBZ
 endif # HAVE_LIBZ
 
 
 if HAVE_SQLITE3
 if HAVE_SQLITE3
-aria2c_SOURCES += Sqlite3MozCookieParserTest.cc
+aria2c_SOURCES += Sqlite3CookieParserTest.cc
 endif # HAVE_SQLITE3
 endif # HAVE_SQLITE3
 
 
 if ENABLE_MESSAGE_DIGEST
 if ENABLE_MESSAGE_DIGEST
@@ -226,6 +226,7 @@ AM_CPPFLAGS =  -Wall\
 EXTRA_DIST = 4096chunk.txt\
 EXTRA_DIST = 4096chunk.txt\
 	chunkChecksumTestFile250.txt\
 	chunkChecksumTestFile250.txt\
 	cookies.sqlite\
 	cookies.sqlite\
+	chromium_cookies.sqlite\
 	emptyfile\
 	emptyfile\
 	file1r.txt\
 	file1r.txt\
 	file2r.txt\
 	file2r.txt\

+ 5 - 5
test/Makefile.in

@@ -44,7 +44,7 @@ check_PROGRAMS = $(am__EXEEXT_1)
 @HAVE_LIBZ_TRUE@am__append_3 = GZipDecoderTest.cc\
 @HAVE_LIBZ_TRUE@am__append_3 = GZipDecoderTest.cc\
 @HAVE_LIBZ_TRUE@	GZipEncoderTest.cc
 @HAVE_LIBZ_TRUE@	GZipEncoderTest.cc
 
 
-@HAVE_SQLITE3_TRUE@am__append_4 = Sqlite3MozCookieParserTest.cc
+@HAVE_SQLITE3_TRUE@am__append_4 = Sqlite3CookieParserTest.cc
 @ENABLE_MESSAGE_DIGEST_TRUE@am__append_5 = MessageDigestHelperTest.cc\
 @ENABLE_MESSAGE_DIGEST_TRUE@am__append_5 = MessageDigestHelperTest.cc\
 @ENABLE_MESSAGE_DIGEST_TRUE@	IteratableChunkChecksumValidatorTest.cc\
 @ENABLE_MESSAGE_DIGEST_TRUE@	IteratableChunkChecksumValidatorTest.cc\
 @ENABLE_MESSAGE_DIGEST_TRUE@	IteratableChecksumValidatorTest.cc
 @ENABLE_MESSAGE_DIGEST_TRUE@	IteratableChecksumValidatorTest.cc
@@ -216,7 +216,7 @@ am__aria2c_SOURCES_DIST = AllTest.cc TestUtil.cc TestUtil.h \
 	XmlRpcRequestParserControllerTest.cc \
 	XmlRpcRequestParserControllerTest.cc \
 	XmlRpcRequestProcessorTest.cc XmlRpcMethodTest.cc \
 	XmlRpcRequestProcessorTest.cc XmlRpcMethodTest.cc \
 	FallocFileAllocationIteratorTest.cc GZipDecoderTest.cc \
 	FallocFileAllocationIteratorTest.cc GZipDecoderTest.cc \
-	GZipEncoderTest.cc Sqlite3MozCookieParserTest.cc \
+	GZipEncoderTest.cc Sqlite3CookieParserTest.cc \
 	MessageDigestHelperTest.cc \
 	MessageDigestHelperTest.cc \
 	IteratableChunkChecksumValidatorTest.cc \
 	IteratableChunkChecksumValidatorTest.cc \
 	IteratableChecksumValidatorTest.cc BtAllowedFastMessageTest.cc \
 	IteratableChecksumValidatorTest.cc BtAllowedFastMessageTest.cc \
@@ -278,8 +278,7 @@ am__aria2c_SOURCES_DIST = AllTest.cc TestUtil.cc TestUtil.h \
 @HAVE_SOME_FALLOCATE_TRUE@am__objects_2 = FallocFileAllocationIteratorTest.$(OBJEXT)
 @HAVE_SOME_FALLOCATE_TRUE@am__objects_2 = FallocFileAllocationIteratorTest.$(OBJEXT)
 @HAVE_LIBZ_TRUE@am__objects_3 = GZipDecoderTest.$(OBJEXT) \
 @HAVE_LIBZ_TRUE@am__objects_3 = GZipDecoderTest.$(OBJEXT) \
 @HAVE_LIBZ_TRUE@	GZipEncoderTest.$(OBJEXT)
 @HAVE_LIBZ_TRUE@	GZipEncoderTest.$(OBJEXT)
-@HAVE_SQLITE3_TRUE@am__objects_4 =  \
-@HAVE_SQLITE3_TRUE@	Sqlite3MozCookieParserTest.$(OBJEXT)
+@HAVE_SQLITE3_TRUE@am__objects_4 = Sqlite3CookieParserTest.$(OBJEXT)
 @ENABLE_MESSAGE_DIGEST_TRUE@am__objects_5 =  \
 @ENABLE_MESSAGE_DIGEST_TRUE@am__objects_5 =  \
 @ENABLE_MESSAGE_DIGEST_TRUE@	MessageDigestHelperTest.$(OBJEXT) \
 @ENABLE_MESSAGE_DIGEST_TRUE@	MessageDigestHelperTest.$(OBJEXT) \
 @ENABLE_MESSAGE_DIGEST_TRUE@	IteratableChunkChecksumValidatorTest.$(OBJEXT) \
 @ENABLE_MESSAGE_DIGEST_TRUE@	IteratableChunkChecksumValidatorTest.$(OBJEXT) \
@@ -664,6 +663,7 @@ AM_CPPFLAGS = -Wall\
 EXTRA_DIST = 4096chunk.txt\
 EXTRA_DIST = 4096chunk.txt\
 	chunkChecksumTestFile250.txt\
 	chunkChecksumTestFile250.txt\
 	cookies.sqlite\
 	cookies.sqlite\
+	chromium_cookies.sqlite\
 	emptyfile\
 	emptyfile\
 	file1r.txt\
 	file1r.txt\
 	file2r.txt\
 	file2r.txt\
@@ -879,7 +879,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SingletonHolderTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SingletonHolderTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SocketCoreTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SocketCoreTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SpeedCalcTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SpeedCalcTest.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Sqlite3MozCookieParserTest.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Sqlite3CookieParserTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StringFormatTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StringFormatTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TestUtil.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TestUtil.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TimeSeedCriteriaTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TimeSeedCriteriaTest.Po@am__quote@

+ 118 - 0
test/Sqlite3CookieParserTest.cc

@@ -0,0 +1,118 @@
+#include "Sqlite3CookieParserImpl.h"
+
+#include <iostream>
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "RecoverableException.h"
+#include "util.h"
+
+namespace aria2 {
+
+class Sqlite3CookieParserTest:public CppUnit::TestFixture {
+
+  CPPUNIT_TEST_SUITE(Sqlite3CookieParserTest);
+  CPPUNIT_TEST(testMozParse);
+  CPPUNIT_TEST(testMozParse_fileNotFound);
+  CPPUNIT_TEST(testMozParse_badfile);
+  CPPUNIT_TEST(testChromumParse);
+  CPPUNIT_TEST_SUITE_END();
+public:
+  void setUp() {}
+
+  void tearDown() {}
+
+  void testMozParse();
+  void testMozParse_fileNotFound();
+  void testMozParse_badfile();
+  void testChromumParse();
+};
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Sqlite3CookieParserTest);
+
+void Sqlite3CookieParserTest::testMozParse()
+{
+  Sqlite3MozCookieParser parser("cookies.sqlite");
+  std::vector<Cookie> cookies;
+  parser.parse(cookies);
+  CPPUNIT_ASSERT_EQUAL((size_t)3, cookies.size());
+
+  const Cookie& localhost = cookies[0];
+  CPPUNIT_ASSERT_EQUAL(std::string("localhost.local"), localhost.getDomain());
+  CPPUNIT_ASSERT_EQUAL(std::string("/"), localhost.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), localhost.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("123456789"), localhost.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)INT32_MAX, localhost.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(true, localhost.isSecureCookie());
+
+  const Cookie& nullValue = cookies[1];
+  CPPUNIT_ASSERT_EQUAL(std::string(".null_value.com"), nullValue.getDomain());
+  CPPUNIT_ASSERT_EQUAL(std::string("/path/to"), nullValue.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("uid"), nullValue.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string(""), nullValue.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)0, nullValue.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(false, nullValue.isSecureCookie());
+
+  // See row id=3 has no name, so it is skipped.
+
+  const Cookie& overflowTime = cookies[2];
+  CPPUNIT_ASSERT_EQUAL(std::string(".overflow.time_t.org"),
+                       overflowTime.getDomain());
+  CPPUNIT_ASSERT_EQUAL(std::string("/path/to"), overflowTime.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("foo"), overflowTime.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("bar"), overflowTime.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)INT32_MAX, overflowTime.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(false, overflowTime.isSecureCookie());
+}
+
+void Sqlite3CookieParserTest::testMozParse_fileNotFound()
+{
+  Sqlite3MozCookieParser parser("fileNotFound");
+  try {
+    std::vector<Cookie> cookies;
+    parser.parse(cookies);
+    CPPUNIT_FAIL("exception must be thrown.");
+  } catch(RecoverableException& e) {
+    // SUCCESS
+    CPPUNIT_ASSERT(util::startsWith(e.what(),
+                                    "SQLite3 database is not opened"));
+  }
+}
+
+void Sqlite3CookieParserTest::testMozParse_badfile()
+{
+  Sqlite3MozCookieParser parser("badcookies.sqlite");
+  try {
+    std::vector<Cookie> cookies;
+    parser.parse(cookies);
+    CPPUNIT_FAIL("exception must be thrown.");
+  } catch(RecoverableException& e) {
+    // SUCCESS
+  }
+}
+
+void Sqlite3CookieParserTest::testChromumParse()
+{
+  Sqlite3ChromiumCookieParser parser("chromium_cookies.sqlite");
+  std::vector<Cookie> cookies;
+  parser.parse(cookies);
+  const Cookie& sfnet = cookies[0];
+  CPPUNIT_ASSERT_EQUAL(std::string(".aria2.sourceforge.net"),
+                       sfnet.getDomain());
+  CPPUNIT_ASSERT_EQUAL(std::string("/"), sfnet.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("mykey"), sfnet.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("pass"), sfnet.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)12345679, sfnet.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(false, sfnet.isSecureCookie());
+
+  const Cookie& sfjp = cookies[1];
+  CPPUNIT_ASSERT_EQUAL(std::string(".aria2.sourceforge.jp"), sfjp.getDomain());
+  CPPUNIT_ASSERT_EQUAL(std::string("/profile"), sfjp.getPath());
+  CPPUNIT_ASSERT_EQUAL(std::string("myseckey"), sfjp.getName());
+  CPPUNIT_ASSERT_EQUAL(std::string("pass2"), sfjp.getValue());
+  CPPUNIT_ASSERT_EQUAL((time_t)0, sfjp.getExpiry());
+  CPPUNIT_ASSERT_EQUAL(true, sfjp.isSecureCookie());
+}
+
+} // namespace aria2

+ 0 - 90
test/Sqlite3MozCookieParserTest.cc

@@ -1,90 +0,0 @@
-#include "Sqlite3MozCookieParser.h"
-
-#include <iostream>
-
-#include <cppunit/extensions/HelperMacros.h>
-
-#include "RecoverableException.h"
-#include "util.h"
-
-namespace aria2 {
-
-class Sqlite3MozCookieParserTest:public CppUnit::TestFixture {
-
-  CPPUNIT_TEST_SUITE(Sqlite3MozCookieParserTest);
-  CPPUNIT_TEST(testParse);
-  CPPUNIT_TEST(testParse_fileNotFound);
-  CPPUNIT_TEST(testParse_badfile);
-  CPPUNIT_TEST_SUITE_END();
-public:
-  void setUp() {}
-
-  void tearDown() {}
-
-  void testParse();
-  void testParse_fileNotFound();
-  void testParse_badfile();
-};
-
-
-CPPUNIT_TEST_SUITE_REGISTRATION(Sqlite3MozCookieParserTest);
-
-void Sqlite3MozCookieParserTest::testParse()
-{
-  Sqlite3MozCookieParser parser;
-  std::vector<Cookie> cookies = parser.parse("cookies.sqlite");
-  CPPUNIT_ASSERT_EQUAL((size_t)3, cookies.size());
-
-  const Cookie& localhost = cookies[0];
-  CPPUNIT_ASSERT_EQUAL(std::string("localhost.local"), localhost.getDomain());
-  CPPUNIT_ASSERT_EQUAL(std::string("/"), localhost.getPath());
-  CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), localhost.getName());
-  CPPUNIT_ASSERT_EQUAL(std::string("123456789"), localhost.getValue());
-  CPPUNIT_ASSERT_EQUAL((time_t)INT32_MAX, localhost.getExpiry());
-  CPPUNIT_ASSERT_EQUAL(true, localhost.isSecureCookie());
-
-  const Cookie& nullValue = cookies[1];
-  CPPUNIT_ASSERT_EQUAL(std::string(".null_value.com"), nullValue.getDomain());
-  CPPUNIT_ASSERT_EQUAL(std::string("/path/to"), nullValue.getPath());
-  CPPUNIT_ASSERT_EQUAL(std::string("uid"), nullValue.getName());
-  CPPUNIT_ASSERT_EQUAL(std::string(""), nullValue.getValue());
-  CPPUNIT_ASSERT_EQUAL((time_t)0, nullValue.getExpiry());
-  CPPUNIT_ASSERT_EQUAL(false, nullValue.isSecureCookie());
-
-  // See row id=3 has no name, so it is skipped.
-
-  const Cookie& overflowTime = cookies[2];
-  CPPUNIT_ASSERT_EQUAL(std::string(".overflow.time_t.org"),
-                       overflowTime.getDomain());
-  CPPUNIT_ASSERT_EQUAL(std::string("/path/to"), overflowTime.getPath());
-  CPPUNIT_ASSERT_EQUAL(std::string("foo"), overflowTime.getName());
-  CPPUNIT_ASSERT_EQUAL(std::string("bar"), overflowTime.getValue());
-  CPPUNIT_ASSERT_EQUAL((time_t)INT32_MAX, overflowTime.getExpiry());
-  CPPUNIT_ASSERT_EQUAL(false, overflowTime.isSecureCookie());
-}
-
-void Sqlite3MozCookieParserTest::testParse_fileNotFound()
-{
-  Sqlite3MozCookieParser parser;
-  try {
-    parser.parse("fileNotFound");
-    CPPUNIT_FAIL("exception must be thrown.");
-  } catch(RecoverableException& e) {
-    // SUCCESS
-    CPPUNIT_ASSERT(util::startsWith(e.what(),
-                                    "Failed to open SQLite3 database:"));
-  }
-}
-
-void Sqlite3MozCookieParserTest::testParse_badfile()
-{
-  Sqlite3MozCookieParser parser;
-  try {
-    parser.parse("badcookies.sqlite");
-    CPPUNIT_FAIL("exception must be thrown.");
-  } catch(RecoverableException& e) {
-    // SUCCESS
-  }
-}
-
-} // namespace aria2

二进制
test/chromium_cookies.sqlite