summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-02-21 15:01:05 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-02-21 15:01:05 +0000
commit28fc3405dddd3998e3cb66242ef40b8d6fdad129 (patch)
tree868b987dbe1e47cc24820d4ca9d3b6c613be98db /src
parent32e8f2b011d1e1db9f724108894d9e2cd01d9f2a (diff)
Diffstat (limited to 'src')
-rw-r--r--src/FtpConnection.cc18
-rw-r--r--src/HttpConnection.cc4
-rw-r--r--src/SimpleLogger.cc10
-rw-r--r--src/Util.cc18
-rw-r--r--src/Util.h2
-rw-r--r--src/message.h3
6 files changed, 40 insertions, 15 deletions
diff --git a/src/FtpConnection.cc b/src/FtpConnection.cc
index 4614304e..1d478f1b 100644
--- a/src/FtpConnection.cc
+++ b/src/FtpConnection.cc
@@ -32,13 +32,13 @@ FtpConnection::~FtpConnection() {}
void FtpConnection::sendUser() const {
string request = "USER "+option->get(PREF_FTP_USER)+"\r\n";
- logger->info(MSG_SENDING_FTP_REQUEST, cuid, request.c_str());
+ logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request);
}
void FtpConnection::sendPass() const {
string request = "PASS "+option->get(PREF_FTP_PASSWD)+"\r\n";
- logger->info(MSG_SENDING_FTP_REQUEST, cuid, "PASS ********");
+ logger->info(MSG_SENDING_REQUEST, cuid, "PASS ********");
socket->writeData(request);
}
@@ -50,25 +50,25 @@ void FtpConnection::sendType() const {
type = "I";
}
string request = "TYPE "+type+"\r\n";
- logger->info(MSG_SENDING_FTP_REQUEST, cuid, request.c_str());
+ logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request);
}
void FtpConnection::sendCwd() const {
string request = "CWD "+req->getDir()+"\r\n";
- logger->info(MSG_SENDING_FTP_REQUEST, cuid, request.c_str());
+ logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request);
}
void FtpConnection::sendSize() const {
string request = "SIZE "+req->getFile()+"\r\n";
- logger->info(MSG_SENDING_FTP_REQUEST, cuid, request.c_str());
+ logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request);
}
void FtpConnection::sendPasv() const {
string request = "PASV\r\n";
- logger->info(MSG_SENDING_FTP_REQUEST, cuid, request.c_str());
+ logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request);
}
@@ -87,7 +87,7 @@ Socket* FtpConnection::sendPort() const {
Util::itos(ipaddr[0])+","+Util::itos(ipaddr[1])+","+
Util::itos(ipaddr[2])+","+Util::itos(ipaddr[3])+","+
Util::itos(addrinfo.second/256)+","+Util::itos(addrinfo.second%256)+"\r\n";
- logger->info(MSG_SENDING_FTP_REQUEST, cuid, request.c_str());
+ logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request);
} catch (Exception* ex) {
delete serverSocket;
@@ -98,13 +98,13 @@ Socket* FtpConnection::sendPort() const {
void FtpConnection::sendRest(const Segment& segment) const {
string request = "REST "+Util::llitos(segment.sp+segment.ds)+"\r\n";
- logger->info(MSG_SENDING_FTP_REQUEST, cuid, request.c_str());
+ logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request);
}
void FtpConnection::sendRetr() const {
string request = "RETR "+req->getFile()+"\r\n";
- logger->info(MSG_SENDING_FTP_REQUEST, cuid, request.c_str());
+ logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request);
}
diff --git a/src/HttpConnection.cc b/src/HttpConnection.cc
index 535e745f..38949bd0 100644
--- a/src/HttpConnection.cc
+++ b/src/HttpConnection.cc
@@ -31,7 +31,7 @@ HttpConnection::HttpConnection(int cuid, const Socket* socket, const Request* re
void HttpConnection::sendRequest(const Segment& segment) const {
string request = createRequest(segment);
- logger->info(MSG_SENDING_HTTP_REQUEST, cuid, request.c_str());
+ logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request.c_str(), request.size());
}
@@ -46,7 +46,7 @@ void HttpConnection::sendProxyRequest() const {
option->get(PREF_HTTP_PROXY_PORT))+"\r\n";
}
request += "\r\n";
- logger->info(MSG_SENDING_HTTP_REQUEST, cuid, request.c_str());
+ logger->info(MSG_SENDING_REQUEST, cuid, request.c_str());
socket->writeData(request.c_str(), request.size());
}
diff --git a/src/SimpleLogger.cc b/src/SimpleLogger.cc
index 476428fd..efb95374 100644
--- a/src/SimpleLogger.cc
+++ b/src/SimpleLogger.cc
@@ -20,6 +20,8 @@
*/
/* copyright --> */
#include "SimpleLogger.h"
+#include "Util.h"
+#include <time.h>
#include <stdarg.h>
SimpleLogger::SimpleLogger(string filename) {
@@ -50,9 +52,13 @@ void SimpleLogger::writeLog(int level, string msg, va_list ap, Exception* e) con
default:
levelStr = "INFO";
}
- vfprintf(file, string(levelStr+" - "+msg+"\n").c_str(), ap);
+ time_t now = time(NULL);
+ char datestr[26];
+ ctime_r(&now, datestr);
+ datestr[strlen(datestr)-1] = '\0';
+ vfprintf(file, string(string(datestr)+" - "+levelStr+" - "+Util::replace(msg, "\r", "")+"\n").c_str(), ap);
if(e != NULL) {
- fprintf(file, string(levelStr+" - exception: "+e->getMsg()+"\n").c_str());
+ fprintf(file, string(string(datestr)+" - "+levelStr+" - exception: "+Util::replace(e->getMsg(), "\r", "")+"\n").c_str());
}
fflush(stdout);
}
diff --git a/src/Util.cc b/src/Util.cc
index 99b70785..72e487e4 100644
--- a/src/Util.cc
+++ b/src/Util.cc
@@ -119,3 +119,21 @@ bool Util::endsWith(string target, string part) {
return false;
}
}
+
+string Util::replace(string target, string oldstr, string newstr) {
+ if(target == "" || oldstr == "" ) {
+ return target;
+ }
+ string result;
+ string::size_type p = 0;
+ string::size_type np = target.find(oldstr);
+ while(np != string::npos) {
+ result += target.substr(p, np-p)+newstr;
+ p = np+oldstr.size();
+ np = target.find(oldstr, p);
+ }
+ result += target.substr(p);
+
+ return result;
+}
+
diff --git a/src/Util.h b/src/Util.h
index ebe67910..0377234b 100644
--- a/src/Util.h
+++ b/src/Util.h
@@ -51,6 +51,8 @@ public:
static string trim(string src);
static bool endsWith(string target, string part);
+
+ static string replace(string target, string oldstr, string newstr);
};
#endif // _D_UTIL_H_
diff --git a/src/message.h b/src/message.h
index 7323c58e..0a75b239 100644
--- a/src/message.h
+++ b/src/message.h
@@ -27,8 +27,7 @@
#define MSG_CONNECTING_TO_SERVER "CUID#%d - Connecting to %s:%d"
#define MSG_SEGMENT_CHANGED "CUID#%d - The segment changed. We send the request again with new Range header."
#define MSG_REDIRECT "CUID#%d - Redirecting to %s"
-#define MSG_SENDING_HTTP_REQUEST "CUID#%d - Sending the request:\n%s"
-#define MSG_SENDING_FTP_REQUEST "CUID#%d - Sending the request: %s"
+#define MSG_SENDING_REQUEST "CUID#%d - Requesting:\n%s"
#define MSG_RECEIVE_RESPONSE "CUID#%d - Response received:\n%s"
#define MSG_DOWNLOAD_ABORTED "CUID#%d - Download aborted."
#define MSG_RESTARTING_DOWNLOAD "CUID#%d - Restarting the download."