← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3297: make "force attempt" work for HTTP downloads

 

------------------------------------------------------------
revno: 3297
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Thu 2013-05-16 23:03:53 +0200
message:
  make "force attempt" work for HTTP downloads
modified:
  dcpp/FavoriteManager.cpp
  dcpp/HttpConnection.cpp
  dcpp/HttpConnection.h
  dcpp/HttpManager.cpp
  dcpp/HttpManager.h
  win32/TransferView.cpp
  win32/TransferView.h


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'dcpp/FavoriteManager.cpp'
--- dcpp/FavoriteManager.cpp	2013-04-16 16:11:50 +0000
+++ dcpp/FavoriteManager.cpp	2013-05-16 21:03:53 +0000
@@ -675,7 +675,7 @@
 	}
 
 	publicListServer = sl[(lastServer) % sl.size()];
-	if(Util::strnicmp(publicListServer.c_str(), "http://";, 7) != 0) {
+	if(Util::findSubString(publicListServer, "http://";) != 0 && Util::findSubString(publicListServer, "https://";) != 0) {
 		lastServer++;
 		fire(FavoriteManagerListener::DownloadFailed(), str(F_("Invalid URL: %1%") % Util::addBrackets(publicListServer)));
 		return;

=== modified file 'dcpp/HttpConnection.cpp'
--- dcpp/HttpConnection.cpp	2013-04-16 17:13:02 +0000
+++ dcpp/HttpConnection.cpp	2013-05-16 21:03:53 +0000
@@ -46,9 +46,7 @@
 }
 
 HttpConnection::~HttpConnection() {
-	if(socket) {
-		abortRequest(true);
-	}
+	abort();
 }
 
 /**
@@ -77,6 +75,12 @@
 	prepareRequest(TYPE_POST);
 }
 
+void HttpConnection::abort() {
+	if(socket) {
+		abortRequest(true);
+	}
+}
+
 void HttpConnection::prepareRequest(RequestType type) {
 	dcassert(Util::findSubString(url, "http://";) == 0 || Util::findSubString(url, "https://";) == 0);
 	Util::sanitizeUrl(url);

=== modified file 'dcpp/HttpConnection.h'
--- dcpp/HttpConnection.h	2013-04-14 22:01:23 +0000
+++ dcpp/HttpConnection.h	2013-05-16 21:03:53 +0000
@@ -40,6 +40,8 @@
 	void download();
 	void download(const StringMap& postData);
 
+	void abort();
+
 	const string& getMimeType() const { return mimeType; }
 
 	int64_t getSize() const { return size; }

=== modified file 'dcpp/HttpManager.cpp'
--- dcpp/HttpManager.cpp	2013-04-14 22:01:23 +0000
+++ dcpp/HttpManager.cpp	2013-05-16 21:03:53 +0000
@@ -47,29 +47,47 @@
 
 void HttpManager::disconnect(const string& url) {
 	HttpConnection* c = nullptr;
-	OutputStream* stream = nullptr;
 
 	{
 		Lock l(cs);
-		conns.erase(std::remove_if(conns.begin(), conns.end(), [&](const Conn& conn) -> bool {
+		for(auto& conn: conns) {
 			if(conn.c->getUrl() == url) {
-				c = conn.c;
-				if(conn.manageStream) {
-					stream = conn.stream;
+				if(!conn.remove) {
+					c = conn.c;
 				}
-				return true;
+				break;
 			}
-			return false;
-		}), conns.end());
+		}
 	}
 
 	if(c) {
+		c->abort();
+		resetStream(c);
 		fire(HttpManagerListener::Failed(), c, _("Disconnected"));
+		removeLater(c);
+	}
+}
+
+void HttpManager::force(const string& url) {
+	HttpConnection* c = nullptr;
+
+	{
+		Lock l(cs);
+		for(auto& conn: conns) {
+			if(conn.c->getUrl() == url) {
+				if(conn.remove) {
+					conn.remove = 0;
+					c = conn.c;
+				}
+				break;
+			}
+		}
+	}
+
+	if(c) {
 		fire(HttpManagerListener::Removed(), c);
-		delete c;
-		if(stream) {
-			delete stream;
-		}
+		fire(HttpManagerListener::Added(), c);
+		c->download();
 	}
 }
 
@@ -144,7 +162,9 @@
 	resetStream(c);
 
 	if(c->getCoralized()) {
+		fire(HttpManagerListener::Removed(), c);
 		c->setCoralized(false);
+		fire(HttpManagerListener::Added(), c);
 		c->download();
 		return;
 	}
@@ -165,8 +185,9 @@
 }
 
 void HttpManager::on(HttpConnectionListener::Redirected, HttpConnection* c, const string& redirect) noexcept {
+	resetStream(c);
+
 	fire(HttpManagerListener::Removed(), c);
-	resetStream(c);
 	c->setUrl(redirect);
 	fire(HttpManagerListener::Added(), c);
 }

=== modified file 'dcpp/HttpManager.h'
--- dcpp/HttpManager.h	2013-04-14 22:01:23 +0000
+++ dcpp/HttpManager.h	2013-05-16 21:03:53 +0000
@@ -49,6 +49,7 @@
 	HttpConnection* download(string url, const StringMap& postData, OutputStream* stream = nullptr);
 
 	void disconnect(const string& url);
+	void force(const string& url);
 
 	void shutdown();
 

=== modified file 'win32/TransferView.cpp'
--- win32/TransferView.cpp	2013-04-14 22:01:23 +0000
+++ win32/TransferView.cpp	2013-05-16 21:03:53 +0000
@@ -413,7 +413,7 @@
 		size = ui.size;
 
 		if(transferred > 0) {
-			columns[COLUMN_TRANSFERRED] = str(TF_("%1%") % Text::toT(Util::formatBytes(transferred)));
+			columns[COLUMN_TRANSFERRED] = Text::toT(Util::formatBytes(transferred));
 		} else {
 			columns[COLUMN_TRANSFERRED].clear();
 		}
@@ -441,6 +441,10 @@
 	}
 }
 
+void TransferView::HttpInfo::force() {
+	HttpManager::getInstance()->force(path);
+}
+
 void TransferView::HttpInfo::disconnect() {
 	HttpManager::getInstance()->disconnect(path);
 }

=== modified file 'win32/TransferView.h'
--- win32/TransferView.h	2013-04-14 22:01:23 +0000
+++ win32/TransferView.h	2013-05-16 21:03:53 +0000
@@ -160,6 +160,7 @@
 
 		void update(const UpdateInfo& ui);
 
+		virtual void force();
 		virtual void disconnect();
 
 		Status status;