فهرست منبع

* Util.{h,cc}: added startsWith().
* CookieBox.cc: rewrited criteriaFind() using Util::startsWith()
and
Util::endsWith().
* SocketCore.cc: struct addrinfo is now zero-initialized.
* common.h: added #include directive of limit.h.
* DownloadEngine.cc: added #include directive of sys/time.h and
algorithm.
* Exception.h: added #include directive of stdio.h.
* AbstractCommand.h: added #include directive of sys/time.h.
* DownloadCommand.h: added #include directive of sys/time.h.
* *.h: added #include directive of common.h to all base classes.
subclasses' one was removed.

Tatsuhiro Tsujikawa 19 سال پیش
والد
کامیت
20ba8c707a
26فایلهای تغییر یافته به همراه101 افزوده شده و 15 حذف شده
  1. 15 0
      ChangeLog
  2. 1 1
      src/AbstractCommand.h
  3. 1 0
      src/Base64.h
  4. 0 1
      src/ChunkedEncoding.h
  5. 2 0
      src/Command.h
  6. 2 4
      src/CookieBox.cc
  7. 1 0
      src/CookieBox.h
  8. 1 0
      src/DownloadCommand.h
  9. 2 0
      src/DownloadEngine.cc
  10. 2 0
      src/Exception.h
  11. 1 0
      src/File.h
  12. 1 0
      src/FtpConnection.h
  13. 1 0
      src/HttpConnection.h
  14. 1 0
      src/HttpHeader.h
  15. 2 0
      src/Logger.h
  16. 1 0
      src/Option.h
  17. 1 0
      src/Segment.h
  18. 1 0
      src/SegmentSplitter.h
  19. 1 0
      src/SocketCore.cc
  20. 2 0
      src/TransferEncoding.h
  21. 18 9
      src/Util.cc
  22. 3 0
      src/Util.h
  23. 1 0
      src/common.h
  24. 2 0
      src/message.h
  25. 2 0
      src/prefs.h
  26. 36 0
      test/UtilTest.cc

+ 15 - 0
ChangeLog

@@ -1,3 +1,18 @@
+2006-02-28  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	* Util.{h,cc}: added startsWith().
+	* CookieBox.cc: rewrited criteriaFind() using Util::startsWith() and
+	Util::endsWith().
+	* SocketCore.cc: struct addrinfo is now  zero-initialized.
+	* common.h: added #include directive of limit.h.
+	* DownloadEngine.cc: added #include directive of sys/time.h and
+	algorithm.
+	* Exception.h: added #include directive of stdio.h.
+	* AbstractCommand.h: added #include directive of sys/time.h.
+	* DownloadCommand.h: added #include directive of sys/time.h.
+	* *.h: added #include directive of common.h to all base classes.
+	subclasses' one was removed.
+	
 2006-02-23  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	* Release 0.2.0

+ 1 - 1
src/AbstractCommand.h

@@ -26,7 +26,7 @@
 #include "Request.h"
 #include "DownloadEngine.h"
 #include "SegmentMan.h"
-#include "common.h"
+#include <sys/time.h>
 
 class AbstractCommand : public Command {
 private:

+ 1 - 0
src/Base64.h

@@ -22,6 +22,7 @@
 #ifndef _BASE64_H_
 #define _BASE64_H_
 #include <string>
+#include "common.h"
 using namespace std;
 
 class Base64

+ 0 - 1
src/ChunkedEncoding.h

@@ -23,7 +23,6 @@
 #define _D_CHUNKED_ENCODING_H_
 
 #include "TransferEncoding.h"
-#include "common.h"
 
 class ChunkedEncoding:public TransferEncoding {
 private:

+ 2 - 0
src/Command.h

@@ -22,6 +22,8 @@
 #ifndef _D_COMMAND_H_
 #define _D_COMMAND_H_
 
+#include "common.h"
+
 class Command {
 protected:
   int cuid;

+ 2 - 4
src/CookieBox.cc

@@ -68,10 +68,8 @@ vector<Cookie> CookieBox::criteriaFind(string host, string dir, bool secure) con
   for(vector<Cookie>::const_iterator itr = cookies.begin(); itr != cookies.end(); itr++) {
     const Cookie& c = *itr;
     if((secure || !c.secure && !secure) &&
-       c.domain.size() <= host.size() &&
-       c.path.size() <= dir.size() && 
-       c.domain.compare(0, c.domain.size(), host, host.size()-c.domain.size(), c.domain.size()) == 0 &&
-       c.path.compare(0, c.path.size(), dir, 0, c.path.size()) == 0) {
+       Util::endsWith(host, c.domain) &&
+       Util::startsWith(dir, c.path)) {
       // TODO we currently ignore expire date.
       result.push_back(c);
     }

+ 1 - 0
src/CookieBox.h

@@ -22,6 +22,7 @@
 #ifndef _D_COOKIE_BOX_H_
 #define _D_COOKIE_BOX_H_
 
+#include "common.h"
 #include <string>
 #include <vector>
 

+ 1 - 0
src/DownloadCommand.h

@@ -24,6 +24,7 @@
 
 #include "AbstractCommand.h"
 #include "TransferEncoding.h"
+#include <sys/time.h>
 #include <string>
 
 using namespace std;

+ 2 - 0
src/DownloadEngine.cc

@@ -24,7 +24,9 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/time.h>
 #include <fcntl.h>
+#include <algorithm>
 
 using namespace std;
 

+ 2 - 0
src/Exception.h

@@ -22,7 +22,9 @@
 #ifndef _D_EXCEPTION_H_
 #define _D_EXCEPTION_H_
 
+#include "common.h"
 #include <string>
+#include <stdio.h>
 #include <stdarg.h>
 
 using namespace std;

+ 1 - 0
src/File.h

@@ -22,6 +22,7 @@
 #ifndef _D_FILE_H_
 #define _D_FILE_H_
 
+#include "common.h"
 #include <string>
 
 using namespace std;

+ 1 - 0
src/FtpConnection.h

@@ -27,6 +27,7 @@
 #include "Logger.h"
 #include "Segment.h"
 #include "Request.h"
+#include "common.h"
 #include <utility>
 
 using namespace std;

+ 1 - 0
src/HttpConnection.h

@@ -28,6 +28,7 @@
 #include "Option.h"
 #include "Logger.h"
 #include "HttpHeader.h"
+#include "common.h"
 #include <map>
 #include <string>
 

+ 1 - 0
src/HttpHeader.h

@@ -22,6 +22,7 @@
 #ifndef _D_HTTP_HEADER_H_
 #define _D_HTTP_HEADER_H_
 
+#include "common.h"
 #include <map>
 #include <vector>
 #include <string>

+ 2 - 0
src/Logger.h

@@ -21,8 +21,10 @@
 /* copyright --> */
 #ifndef _D_LOGGER_H_
 #define _D_LOGGER_H_
+
 #include <string>
 #include "Exception.h"
+#include "common.h"
 
 using namespace std;
 

+ 1 - 0
src/Option.h

@@ -22,6 +22,7 @@
 #ifndef _D_OPTION_H_
 #define _D_OPTION_H_
 
+#include "common.h"
 #include <string>
 #include <map>
 

+ 1 - 0
src/Segment.h

@@ -22,6 +22,7 @@
 #ifndef _D_SEGMENT_H_
 #define _D_SEGMENT_H_
 
+#include "common.h"
 #include <vector>
 
 using namespace std;

+ 1 - 0
src/SegmentSplitter.h

@@ -24,6 +24,7 @@
 
 #include "Segment.h"
 #include "Logger.h"
+#include "common.h"
 
 class SegmentSplitter {
 protected:

+ 1 - 0
src/SocketCore.cc

@@ -129,6 +129,7 @@ void SocketCore::establishConnection(string host, int port) {
     // ok
   } else {
     struct addrinfo ai;
+    memset((char*)&ai, 0, sizeof(ai));
     ai.ai_flags = 0;
     ai.ai_family = PF_INET;
     ai.ai_socktype = SOCK_STREAM;

+ 2 - 0
src/TransferEncoding.h

@@ -22,6 +22,8 @@
 #ifndef _D_TRANSFER_ENCODING_H_
 #define _D_TRANSFER_ENCODING_H_
 
+#include "common.h"
+
 class TransferEncoding {
 public:
   virtual ~TransferEncoding() {}

+ 18 - 9
src/Util.cc

@@ -73,14 +73,6 @@ void Util::split(pair<string, string>& hp, string src, char delim) {
   } else {
     hp.first = trim(src.substr(0, p));
     hp.second = trim(src.substr(p+1));
-    /*
-    unsigned int p2 = src.find_first_not_of(" ", p+1);
-    if(p2 == string::npos) {
-      hp.second = "";
-    } else {
-      hp.second = src.substr(p2);
-    }
-    */
   }
 }
 
@@ -109,11 +101,28 @@ void Util::slice(vector<string>& result, string src, char delim) {
   } 
 }
 
+bool Util::startsWith(string target, string part) {
+  if(target.size() < part.size()) {
+    return false;
+  }
+  if(part == "") {
+    return true;
+  }
+  if(target.find(part) == 0) {
+    return true;
+  } else {
+    return false;
+  }
+}
+
 bool Util::endsWith(string target, string part) {
   if(target.size() < part.size()) {
     return false;
   }
-  if(target.compare(target.size()-part.size(), part.size(), part, 0, part.size()) == 0) {
+  if(part == "") {
+    return true;
+  }
+  if(target.find(part) == target.size()-part.size()) {
     return true;
   } else {
     return false;

+ 3 - 0
src/Util.h

@@ -22,6 +22,7 @@
 #ifndef _D_UTIL_H_
 #define _D_UTIL_H_
 
+#include "common.h"
 #include <string>
 #include <utility>
 #include <vector>
@@ -50,6 +51,8 @@ public:
   
   static string trim(string src);
 
+  static bool startsWith(string target, string part);
+
   static bool endsWith(string target, string part);
 
   static string replace(string target, string oldstr, string newstr);

+ 1 - 0
src/common.h

@@ -21,6 +21,7 @@
 /* copyright --> */
 #include <iostream>
 #include <assert.h>
+#include <limits.h>
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif

+ 2 - 0
src/message.h

@@ -22,6 +22,8 @@
 #ifndef _D_MESSAGE_H_
 #define _D_MESSAGE_H_
 
+#include "common.h"
+
 #define MSG_DOWNLOAD_COMPLETED "CUID#%d - The download for one segment completed successfully."
 #define MSG_NO_SEGMENT_AVAILABLE "CUID#%d - No segment available."
 #define MSG_CONNECTING_TO_SERVER "CUID#%d - Connecting to %s:%d"

+ 2 - 0
src/prefs.h

@@ -22,6 +22,8 @@
 #ifndef _D_PREFS_H_
 #define _D_PREFS_H_
 
+#include "common.h"
+
 /**
  * Constants
  */

+ 36 - 0
test/UtilTest.cc

@@ -12,6 +12,7 @@ class UtilTest:public CppUnit::TestFixture {
   CPPUNIT_TEST(testSlice);
   CPPUNIT_TEST(testEndsWith);
   CPPUNIT_TEST(testReplace);
+  CPPUNIT_TEST(testStartsWith);
   CPPUNIT_TEST_SUITE_END();
 private:
 
@@ -24,6 +25,7 @@ public:
   void testSlice();
   void testEndsWith();
   void testReplace();
+  void testStartsWith();
 };
 
 
@@ -121,3 +123,37 @@ void UtilTest::testReplace() {
   CPPUNIT_ASSERT_EQUAL(string("abc"), Util::replace("abc", "", "a"));
   CPPUNIT_ASSERT_EQUAL(string("xbc"), Util::replace("abc", "a", "x"));
 }
+
+void UtilTest::testStartsWith() {
+  string target;
+  string part;
+
+  target = "abcdefg";
+  part = "abc";
+  CPPUNIT_ASSERT(Util::startsWith(target, part));
+
+  target = "abcdefg";
+  part = "abx";
+  CPPUNIT_ASSERT(!Util::startsWith(target, part));
+
+  target = "abcdefg";
+  part = "bcd";
+  CPPUNIT_ASSERT(!Util::startsWith(target, part));
+
+  target = "";
+  part = "a";
+  CPPUNIT_ASSERT(!Util::startsWith(target, part));
+
+  target = "";
+  part = "";
+  CPPUNIT_ASSERT(Util::startsWith(target, part));
+  
+  target = "a";
+  part = "";
+  CPPUNIT_ASSERT(Util::startsWith(target, part));
+
+  target = "a";
+  part = "a";
+  CPPUNIT_ASSERT(Util::startsWith(target, part));
+
+}