summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-02-28 02:25:45 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-02-28 02:25:45 +0000
commit20ba8c707adc2cafd76b2b29c59531d3ec0a7d94 (patch)
tree88cfbe969aa3acfa7ab1b34f718b3f43cdc8096e /src
parent87a229cab18679042beb06076e5dec1dcfadaeae (diff)
* 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.
Diffstat (limited to 'src')
-rw-r--r--src/AbstractCommand.h2
-rw-r--r--src/Base64.h1
-rw-r--r--src/ChunkedEncoding.h1
-rw-r--r--src/Command.h2
-rw-r--r--src/CookieBox.cc6
-rw-r--r--src/CookieBox.h1
-rw-r--r--src/DownloadCommand.h1
-rw-r--r--src/DownloadEngine.cc2
-rw-r--r--src/Exception.h2
-rw-r--r--src/File.h1
-rw-r--r--src/FtpConnection.h1
-rw-r--r--src/HttpConnection.h1
-rw-r--r--src/HttpHeader.h1
-rw-r--r--src/Logger.h2
-rw-r--r--src/Option.h1
-rw-r--r--src/Segment.h1
-rw-r--r--src/SegmentSplitter.h1
-rw-r--r--src/SocketCore.cc1
-rw-r--r--src/TransferEncoding.h2
-rw-r--r--src/Util.cc27
-rw-r--r--src/Util.h3
-rw-r--r--src/common.h1
-rw-r--r--src/message.h2
-rw-r--r--src/prefs.h2
24 files changed, 50 insertions, 15 deletions
diff --git a/src/AbstractCommand.h b/src/AbstractCommand.h
index 10b36462..0a4075e7 100644
--- a/src/AbstractCommand.h
+++ b/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:
diff --git a/src/Base64.h b/src/Base64.h
index e5d06d60..8223a67f 100644
--- a/src/Base64.h
+++ b/src/Base64.h
@@ -22,6 +22,7 @@
#ifndef _BASE64_H_
#define _BASE64_H_
#include <string>
+#include "common.h"
using namespace std;
class Base64
diff --git a/src/ChunkedEncoding.h b/src/ChunkedEncoding.h
index bce035ee..954f4bf9 100644
--- a/src/ChunkedEncoding.h
+++ b/src/ChunkedEncoding.h
@@ -23,7 +23,6 @@
#define _D_CHUNKED_ENCODING_H_
#include "TransferEncoding.h"
-#include "common.h"
class ChunkedEncoding:public TransferEncoding {
private:
diff --git a/src/Command.h b/src/Command.h
index a6fd6d90..c79a8588 100644
--- a/src/Command.h
+++ b/src/Command.h
@@ -22,6 +22,8 @@
#ifndef _D_COMMAND_H_
#define _D_COMMAND_H_
+#include "common.h"
+
class Command {
protected:
int cuid;
diff --git a/src/CookieBox.cc b/src/CookieBox.cc
index f6f818e8..96d6e24c 100644
--- a/src/CookieBox.cc
+++ b/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);
}
diff --git a/src/CookieBox.h b/src/CookieBox.h
index d2056a17..12c1f442 100644
--- a/src/CookieBox.h
+++ b/src/CookieBox.h
@@ -22,6 +22,7 @@
#ifndef _D_COOKIE_BOX_H_
#define _D_COOKIE_BOX_H_
+#include "common.h"
#include <string>
#include <vector>
diff --git a/src/DownloadCommand.h b/src/DownloadCommand.h
index 3dd374e7..4e26eb7c 100644
--- a/src/DownloadCommand.h
+++ b/src/DownloadCommand.h
@@ -24,6 +24,7 @@
#include "AbstractCommand.h"
#include "TransferEncoding.h"
+#include <sys/time.h>
#include <string>
using namespace std;
diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc
index 80b98141..ff38fa17 100644
--- a/src/DownloadEngine.cc
+++ b/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;
diff --git a/src/Exception.h b/src/Exception.h
index 83b62bce..28fe3ee4 100644
--- a/src/Exception.h
+++ b/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;
diff --git a/src/File.h b/src/File.h
index 51cde9a3..f450fb97 100644
--- a/src/File.h
+++ b/src/File.h
@@ -22,6 +22,7 @@
#ifndef _D_FILE_H_
#define _D_FILE_H_
+#include "common.h"
#include <string>
using namespace std;
diff --git a/src/FtpConnection.h b/src/FtpConnection.h
index 6dab8e68..7b5ec17e 100644
--- a/src/FtpConnection.h
+++ b/src/FtpConnection.h
@@ -27,6 +27,7 @@
#include "Logger.h"
#include "Segment.h"
#include "Request.h"
+#include "common.h"
#include <utility>
using namespace std;
diff --git a/src/HttpConnection.h b/src/HttpConnection.h
index f37ed892..f4926f0b 100644
--- a/src/HttpConnection.h
+++ b/src/HttpConnection.h
@@ -28,6 +28,7 @@
#include "Option.h"
#include "Logger.h"
#include "HttpHeader.h"
+#include "common.h"
#include <map>
#include <string>
diff --git a/src/HttpHeader.h b/src/HttpHeader.h
index 3bcaa479..3f7fc550 100644
--- a/src/HttpHeader.h
+++ b/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>
diff --git a/src/Logger.h b/src/Logger.h
index 7e842b76..66c5db8b 100644
--- a/src/Logger.h
+++ b/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;
diff --git a/src/Option.h b/src/Option.h
index 7cacef50..0d3ff5ee 100644
--- a/src/Option.h
+++ b/src/Option.h
@@ -22,6 +22,7 @@
#ifndef _D_OPTION_H_
#define _D_OPTION_H_
+#include "common.h"
#include <string>
#include <map>
diff --git a/src/Segment.h b/src/Segment.h
index 035282ae..21db6de3 100644
--- a/src/Segment.h
+++ b/src/Segment.h
@@ -22,6 +22,7 @@
#ifndef _D_SEGMENT_H_
#define _D_SEGMENT_H_
+#include "common.h"
#include <vector>
using namespace std;
diff --git a/src/SegmentSplitter.h b/src/SegmentSplitter.h
index 887250ae..c12ed9b0 100644
--- a/src/SegmentSplitter.h
+++ b/src/SegmentSplitter.h
@@ -24,6 +24,7 @@
#include "Segment.h"
#include "Logger.h"
+#include "common.h"
class SegmentSplitter {
protected:
diff --git a/src/SocketCore.cc b/src/SocketCore.cc
index 53051679..f4d02dce 100644
--- a/src/SocketCore.cc
+++ b/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;
diff --git a/src/TransferEncoding.h b/src/TransferEncoding.h
index 41eed716..0bd141c7 100644
--- a/src/TransferEncoding.h
+++ b/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() {}
diff --git a/src/Util.cc b/src/Util.cc
index 72e487e4..e19ef451 100644
--- a/src/Util.cc
+++ b/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;
diff --git a/src/Util.h b/src/Util.h
index 98bb116e..a208e802 100644
--- a/src/Util.h
+++ b/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);
diff --git a/src/common.h b/src/common.h
index 2ef416fc..aa046c6d 100644
--- a/src/common.h
+++ b/src/common.h
@@ -21,6 +21,7 @@
/* copyright --> */
#include <iostream>
#include <assert.h>
+#include <limits.h>
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
diff --git a/src/message.h b/src/message.h
index ca8514f3..cfbeca10 100644
--- a/src/message.h
+++ b/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"
diff --git a/src/prefs.h b/src/prefs.h
index 080ee961..8127bb09 100644
--- a/src/prefs.h
+++ b/src/prefs.h
@@ -22,6 +22,8 @@
#ifndef _D_PREFS_H_
#define _D_PREFS_H_
+#include "common.h"
+
/**
* Constants
*/