[sword-svn] r3782 - in trunk: include src/mgr

scribe at crosswire.org scribe at crosswire.org
Thu Aug 27 10:08:33 EDT 2020


Author: scribe
Date: 2020-08-27 10:08:33 -0400 (Thu, 27 Aug 2020)
New Revision: 3782

Modified:
   trunk/include/installmgr.h
   trunk/include/remotetrans.h
   trunk/include/swversion.h
   trunk/src/mgr/curlftpt.cpp
   trunk/src/mgr/curlhttpt.cpp
   trunk/src/mgr/ftplibftpt.cpp
   trunk/src/mgr/installmgr.cpp
Log:
Added TimoutMillis property to InstallMgr


Modified: trunk/include/installmgr.h
===================================================================
--- trunk/include/installmgr.h	2020-08-23 10:25:31 UTC (rev 3781)
+++ trunk/include/installmgr.h	2020-08-27 14:08:33 UTC (rev 3782)
@@ -74,6 +74,7 @@
 	SWBuf confPath;
 	StatusReporter *statusReporter;
 	bool passive;
+	long timeoutMillis;
 	SWBuf u, p;
 	bool unverifiedPeerAllowed;
 
@@ -264,6 +265,9 @@
 	void setFTPPassive(bool passive) { this->passive = passive; }
 	bool isFTPPassive() { return passive; }
 
+	void setTimeoutMillis(long timeoutMillis) { this->timeoutMillis = timeoutMillis; }
+	long getTimeoutMillis() { return timeoutMillis; }
+
 	void setUnverifiedPeerAllowed(bool allowed) { this->unverifiedPeerAllowed = allowed; }
 	bool isUnverifiedPeerAllowed() { return unverifiedPeerAllowed; }
 

Modified: trunk/include/remotetrans.h
===================================================================
--- trunk/include/remotetrans.h	2020-08-23 10:25:31 UTC (rev 3781)
+++ trunk/include/remotetrans.h	2020-08-27 14:08:33 UTC (rev 3782)
@@ -52,6 +52,7 @@
 protected:
 	StatusReporter *statusReporter;
 	bool passive;
+	long timeoutMillis;
 	bool term;
 	bool unverifiedPeerAllowed;
 	SWBuf host;
@@ -66,6 +67,7 @@
 	 * override this method in your real impl
 	 *
 	 * if destBuf then write to buffer instead of file
+	 * @return -1 simple error (resource not found); -2 more serious (connection error)
 	 */
 	virtual char getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf = 0);
 
@@ -73,6 +75,7 @@
 	 * override this method in your real impl
 	 *
 	 * if sourceBuf then read from buffer instead of file
+	 * @return -1 simple error (resource not found); -2 more serious (connection error)
 	 */
 	virtual char putURL(const char *destURL, const char *sourcePath, SWBuf *sourceBuf = 0);
 
@@ -81,6 +84,8 @@
 
 	virtual std::vector<struct DirEntry> getDirList(const char *dirURL);
 	void setPassive(bool passive) { this->passive = passive; }
+	void setTimeoutMillis(long timeoutMillis) { this->timeoutMillis = timeoutMillis; }
+	long getTimeoutMillis() { return timeoutMillis; }
 	bool isPassive() { return passive; }
 	void setUser(const char *user) { u = user; }
 	void setPasswd(const char *passwd) { p = passwd; }

Modified: trunk/include/swversion.h
===================================================================
--- trunk/include/swversion.h	2020-08-23 10:25:31 UTC (rev 3781)
+++ trunk/include/swversion.h	2020-08-27 14:08:33 UTC (rev 3782)
@@ -3,7 +3,7 @@
  * swversion.h -	definition of class SWVersion used to compare version
  *			info
  *
- * $Id: swversion.h.in 2959 2013-08-13 03:55:38Z chrislit $
+ * $Id: swversion.h.in 3765 2020-07-26 10:31:09Z scribe $
  *
  * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org)
  *	CrossWire Bible Society
@@ -24,12 +24,12 @@
 #ifndef SWVERSION_H
 #define SWVERSION_H
 
-#define SWORD_VERSION_NUM 1089003763
-#define SWORD_VERSION_STR "1.8.900.3763:3764M"
+#define SWORD_VERSION_NUM 1089003781
+#define SWORD_VERSION_STR "1.8.900.3781"
 #define SWORD_VERSION_MAJOR 1
 #define SWORD_VERSION_MINOR 8
 #define SWORD_VERSION_MICRO 900
-#define SWORD_VERSION_NANO 3763
+#define SWORD_VERSION_NANO 3781
 
 #include <defs.h>
 SWORD_NAMESPACE_START

Modified: trunk/src/mgr/curlftpt.cpp
===================================================================
--- trunk/src/mgr/curlftpt.cpp	2020-08-23 10:25:31 UTC (rev 3781)
+++ trunk/src/mgr/curlftpt.cpp	2020-08-27 14:08:33 UTC (rev 3782)
@@ -155,13 +155,16 @@
 		curl_easy_setopt(session, CURLOPT_NOPROGRESS, 0);
 		curl_easy_setopt(session, CURLOPT_PROGRESSDATA, &pd);
 		curl_easy_setopt(session, CURLOPT_PROGRESSFUNCTION, my_fprogress);
+
+
 		curl_easy_setopt(session, CURLOPT_DEBUGFUNCTION, my_trace);
 		/* Set a pointer to our struct to pass to the callback */
 		curl_easy_setopt(session, CURLOPT_FILE, &ftpfile);
 
 		/* Switch on full protocol/debug output */
 		curl_easy_setopt(session, CURLOPT_VERBOSE, true);
-		curl_easy_setopt(session, CURLOPT_CONNECTTIMEOUT, 45);
+		curl_easy_setopt(session, CURLOPT_CONNECTTIMEOUT_MS, timeoutMillis);
+		curl_easy_setopt(session, CURLOPT_TIMEOUT_MS, timeoutMillis);
 
 		/* FTP connection settings */
 
@@ -186,8 +189,13 @@
 		// it seems CURL tries to use this option data later for some reason, so we unset here
 		curl_easy_setopt(session, CURLOPT_PROGRESSDATA, (void*)NULL);
 
-		if(CURLE_OK != res) {
-			retVal = -1;
+		if (CURLE_OK != res) {
+			if (CURLE_FTP_ACCEPT_TIMEOUT == res || CURLE_OPERATION_TIMEDOUT == res) {
+				retVal = -2;
+			}
+			else {
+				retVal = -1;
+			}
 		}
 	}
 

Modified: trunk/src/mgr/curlhttpt.cpp
===================================================================
--- trunk/src/mgr/curlhttpt.cpp	2020-08-23 10:25:31 UTC (rev 3781)
+++ trunk/src/mgr/curlhttpt.cpp	2020-08-27 14:08:33 UTC (rev 3782)
@@ -136,7 +136,8 @@
 
 		/* Switch on full protocol/debug output */
 		curl_easy_setopt(session, CURLOPT_VERBOSE, true);
-		curl_easy_setopt(session, CURLOPT_CONNECTTIMEOUT, 45);
+		curl_easy_setopt(session, CURLOPT_CONNECTTIMEOUT_MS, timeoutMillis);
+		curl_easy_setopt(session, CURLOPT_TIMEOUT_MS, timeoutMillis);
 		
 		/* Disable checking host certificate */
 		if (isUnverifiedPeerAllowed()) {
@@ -164,7 +165,12 @@
 		SWLog::getSystemLog()->logDebug("***** Finished performing curl easy action. \n");
 
 		if(CURLE_OK != res) {
-			retVal = -1;
+			if (CURLE_FTP_ACCEPT_TIMEOUT == res || CURLE_OPERATION_TIMEDOUT == res) {
+				retVal = -3;
+			}
+			else {
+				retVal = -1;
+			}
 		}
 	}
 

Modified: trunk/src/mgr/ftplibftpt.cpp
===================================================================
--- trunk/src/mgr/ftplibftpt.cpp	2020-08-23 10:25:31 UTC (rev 3781)
+++ trunk/src/mgr/ftplibftpt.cpp	2020-08-27 14:08:33 UTC (rev 3782)
@@ -109,6 +109,7 @@
 		SWLog::getSystemLog()->logDebug("connecting to host: %s...\n", host.c_str());
 		if (FtpConnect(host, &ftpConnection)) {
 			FtpOptions(FTPLIB_CONNMODE, (passive) ? FTPLIB_PASSIVE : FTPLIB_PORT, ftpConnection);
+			FtpOptions(FTPLIB_IDLETIME, timeoutMillis, ftpConnection);
 
 			SWLog::getSystemLog()->logDebug("connected. logging in...\n");
 			if (FtpLogin(u.c_str(), p.c_str(), ftpConnection)) {
@@ -122,7 +123,7 @@
 		}
 		else {
 			SWLog::getSystemLog()->logError("Failed to connect to %s\n", host.c_str());
-			retVal = -1;
+			retVal = -3;
 		}
 	}
 	return retVal;

Modified: trunk/src/mgr/installmgr.cpp
===================================================================
--- trunk/src/mgr/installmgr.cpp	2020-08-23 10:25:31 UTC (rev 3781)
+++ trunk/src/mgr/installmgr.cpp	2020-08-27 14:08:33 UTC (rev 3782)
@@ -98,6 +98,7 @@
 
 InstallMgr::InstallMgr(const char *privatePath, StatusReporter *sr, SWBuf u, SWBuf p) {
 	passive = true;
+	timeoutMillis = 10000;
 	unverifiedPeerAllowed = true;
 	statusReporter = sr;
 	this->u = u;
@@ -143,6 +144,8 @@
 	clearSources();
 	
 	setFTPPassive(stricmp((*installConf)["General"]["PassiveFTP"].c_str(), "false") != 0);
+	long t = atol((*installConf)["General"]["TimeoutMillis"].c_str());
+	if (t > 0) setTimeoutMillis(t);
 	setUnverifiedPeerAllowed(stricmp((*installConf)["General"]["UnverifiedPeerAllowed"].c_str(), "false") != 0);
 
 	SectionMap::iterator confSection = installConf->getSections().find("Sources");
@@ -310,6 +313,7 @@
 
 		trans = createFTPTransport(is->source, statusReporter);
 		trans->setPassive(passive);
+		trans->setTimeoutMillis(timeoutMillis);
 	}
 	else if (is->type == "HTTP" || is->type == "HTTPS") {
 		trans = createHTTPTransport(is->source, statusReporter);
@@ -366,13 +370,13 @@
 			SWBuf url = urlPrefix + is->directory.c_str();
 			removeTrailingSlash(url);
 			url += (SWBuf)"/" + src; //dont forget the final slash
-			if (trans->getURL(dest, url.c_str())) {
+			retVal = trans->getURL(dest, url.c_str());
+			if (retVal) {
 				SWLog::getSystemLog()->logDebug("netCopy: failed to get file %s", url.c_str());
-				retVal = -1;
 			}
 		}
 		SWCATCH (...) {
-			retVal = -1;
+			retVal = -3;
 		}
 	}
 	SWTRY {
@@ -566,7 +570,7 @@
 		ZipCompress::unTarGZ(fd, root.c_str());
 		FileMgr::getSystemFileMgr()->close(fd);
 	}
-	else
+	else if (errorCode > -2) // -2 and greater errors are connection errors
 #endif
 	errorCode = remoteCopy(is, "mods.d", target.c_str(), true, ".conf"); //copy the whole directory
 



More information about the sword-cvs mailing list