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

scribe at crosswire.org scribe at crosswire.org
Mon Oct 12 10:11:29 MST 2009


Author: scribe
Date: 2009-10-12 10:11:29 -0700 (Mon, 12 Oct 2009)
New Revision: 2459

Modified:
   trunk/ChangeLog
   trunk/include/curlhttpt.h
   trunk/include/defs.h
   trunk/include/sysdata.h
   trunk/src/mgr/curlhttpt.cpp
   trunk/src/mgr/filemgr.cpp
   trunk/src/mgr/ftptrans.cpp
   trunk/src/mgr/installmgr.cpp
Log:
	Added initial impl for CurlHTTPTransport submitted
		by Nic Carter <niccarter at mac.com>
	Added initial Android ifdefs to get things compiling
		under the Android NDK.



Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-10-12 15:36:16 UTC (rev 2458)
+++ trunk/ChangeLog	2009-10-12 17:11:29 UTC (rev 2459)
@@ -1,6 +1,12 @@
 API ChangeLog 
 
 
+12-Oct-2009	Troy A. Griffitts <scribe at crosswire.org>
+	Added initial impl for CurlHTTPTransport submitted
+		by Nic Carter <niccarter at mac.com>
+	Added initial Android ifdefs to get things compiling
+		under the Android NDK.
+
 09-Aug-2009	Troy A. Griffitts <scribe at crosswire.org>
 	Added checks for Hebrew and Arabic when stripping
 		for searching

Modified: trunk/include/curlhttpt.h
===================================================================
--- trunk/include/curlhttpt.h	2009-10-12 15:36:16 UTC (rev 2458)
+++ trunk/include/curlhttpt.h	2009-10-12 17:11:29 UTC (rev 2459)
@@ -43,6 +43,7 @@
 	CURLHTTPTransport(const char *host, StatusReporter *statusReporter = 0);
 	~CURLHTTPTransport();
 
+	virtual std::vector<struct DirEntry> getDirList(const char *dirURL);
 	virtual char getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf = 0);
 };
 

Modified: trunk/include/defs.h
===================================================================
--- trunk/include/defs.h	2009-10-12 15:36:16 UTC (rev 2458)
+++ trunk/include/defs.h	2009-10-12 17:11:29 UTC (rev 2459)
@@ -12,18 +12,25 @@
  #define SWORD_NAMESPACE_END }
 #endif
 
-
 SWORD_NAMESPACE_START
 
+#define SWTRY try
+#define SWCATCH(x) catch (x)
+
 #ifdef _WIN32_WCE
 #define SWTRY
 #define SWCATCH(x) if (0)
 #define GLOBCONFPATH "/Program Files/sword/sword.conf"
-#else
-#define SWTRY try
-#define SWCATCH(x) catch (x)
 #endif
 
+#ifdef ANDROID
+#define _NO_IOSTREAM_
+#undef SWTRY
+#undef SWCATCH
+#define SWTRY
+#define SWCATCH(x) if (0)
+#endif
+
 // _declspec works in BC++ 5 and later, as well as VC++
 #if defined(_MSC_VER)
 

Modified: trunk/include/sysdata.h
===================================================================
--- trunk/include/sysdata.h	2009-10-12 15:36:16 UTC (rev 2458)
+++ trunk/include/sysdata.h	2009-10-12 17:11:29 UTC (rev 2459)
@@ -23,6 +23,9 @@
 //typedef unsigned long long __u64;
 #endif
 
+#undef __swap16
+#undef __swap32
+#undef __swap64
 
 #define __swap16(x) \
 	((__u16)( \

Modified: trunk/src/mgr/curlhttpt.cpp
===================================================================
--- trunk/src/mgr/curlhttpt.cpp	2009-10-12 15:36:16 UTC (rev 2458)
+++ trunk/src/mgr/curlhttpt.cpp	2009-10-12 17:11:29 UTC (rev 2459)
@@ -19,18 +19,21 @@
  *
  */
 
+#include <fcntl.h>
 
+#include <vector>
+#include <cctype>
 
-#include <curlhttpt.h>
-
-#include <fcntl.h>
-
 #include <curl/curl.h>
 #include <curl/types.h>
 #include <curl/easy.h>
 
 #include <swlog.h>
+#include <filemgr.h>
+#include <curlhttpt.h>
 
+using std::vector;
+
 SWORD_NAMESPACE_START
 
 
@@ -174,5 +177,78 @@
 }
 
 
+// we need to find the 2nd "<td" & then find the ">" after that.  The size starts with the next non-space char
+char *findSizeStart(const char *buffer) {
+	const char *listing = buffer;
+	char *pEnd;
+	
+	pEnd = strstr(listing, "<td");
+	if(pEnd == NULL) {
+		return NULL;
+	}
+	listing = pEnd+2;
+	pEnd = strstr(listing, "<td");
+	if(pEnd == NULL)
+		return NULL;
+	listing = pEnd+2;
+	pEnd = strchr(listing, '>');
+	if(pEnd == NULL)
+		return NULL;
+
+	return pEnd+1;
+}
+
+
+vector<struct DirEntry> CURLHTTPTransport::getDirList(const char *dirURL) {
+	
+	vector<struct DirEntry> dirList;
+	
+	SWBuf dirBuf;
+	char *pBuf;
+	char *pBufRes;
+	char possibleName[400];
+	double fSize;
+	int possibleNameLength = 0;
+	
+	if (!getURL("", dirURL, &dirBuf)) {
+		pBuf = strstr(dirBuf, "<a href=\"");//Find the next link to a possible file name.
+		while (pBuf != NULL) {
+			pBuf += 9;//move to the start of the actual name.
+			pBufRes = strchr(pBuf, '\"');//Find the end of the possible file name
+			possibleNameLength = pBufRes - pBuf;
+			sprintf(possibleName, "%.*s", possibleNameLength, pBuf);
+			if (isalnum(possibleName[0])) {
+				SWLog::getSystemLog()->logDebug("getDirListHTTP: Found a file: %s", possibleName);
+				pBuf = pBufRes;
+				pBufRes = findSizeStart(pBuf);
+				fSize = 0;
+				if(pBufRes != NULL) {
+					pBuf = pBufRes;
+					fSize = strtod(pBuf, &pBufRes);
+					if (pBufRes[0] == 'K')
+						fSize *= 1024;
+					else if (pBufRes[0] == 'M')
+						fSize *= 1048576;
+				}
+				struct DirEntry i;
+				i.name = possibleName;
+				i.size = fSize;
+				i.isDirectory = (possibleName[possibleNameLength-1] == '/');
+				dirList.push_back(i);
+				pBuf = pBufRes;
+			} else {
+				pBuf += possibleNameLength;
+			}
+			pBuf++;
+			pBuf = strstr(pBuf, "<a href=\"");//Find the next link to a possible file name.
+		}
+	}
+	else
+	{
+		SWLog::getSystemLog()->logWarning("FTPURLGetDir: failed to get dir %s\n", dirURL);
+	}
+	return dirList;
+}
+
 SWORD_NAMESPACE_END
 

Modified: trunk/src/mgr/filemgr.cpp
===================================================================
--- trunk/src/mgr/filemgr.cpp	2009-10-12 15:36:16 UTC (rev 2458)
+++ trunk/src/mgr/filemgr.cpp	2009-10-12 17:11:29 UTC (rev 2459)
@@ -59,7 +59,16 @@
 #endif
 // -----------
 
+// ------- if we still don't have something
+#ifndef S_IREAD
+#define S_IREAD 0400
+#endif
+#ifndef S_IWRITE
+#define S_IWRITE 0200
+#endif
+// -------
 
+
 SWORD_NAMESPACE_START
 
 

Modified: trunk/src/mgr/ftptrans.cpp
===================================================================
--- trunk/src/mgr/ftptrans.cpp	2009-10-12 15:36:16 UTC (rev 2458)
+++ trunk/src/mgr/ftptrans.cpp	2009-10-12 17:11:29 UTC (rev 2459)
@@ -128,11 +128,11 @@
 	removeTrailingSlash(url);
 	url += '/';
 	
-	SWLog::getSystemLog()->logWarning("FTPCopy: getting dir %s\n", url.c_str());
+	SWLog::getSystemLog()->logWarning("NetTransport: getting dir %s\n", url.c_str());
 	vector<struct DirEntry> dirList = getDirList(url.c_str());
 
 	if (!dirList.size()) {
-		SWLog::getSystemLog()->logWarning("FTPCopy: failed to read dir %s\n", url.c_str());
+		SWLog::getSystemLog()->logWarning("NetTransport: failed to read dir %s\n", url.c_str());
 		return -1;
 	}
 				

Modified: trunk/src/mgr/installmgr.cpp
===================================================================
--- trunk/src/mgr/installmgr.cpp	2009-10-12 15:36:16 UTC (rev 2458)
+++ trunk/src/mgr/installmgr.cpp	2009-10-12 17:11:29 UTC (rev 2459)
@@ -158,6 +158,17 @@
 			is->localShadow = (SWBuf)privatePath + "/" + is->uid;
 			sourceBegin++;
 		}
+		sourceBegin = confSection->second.lower_bound("HTTPSource");
+		sourceEnd = confSection->second.upper_bound("HTTPSource");
+
+		while (sourceBegin != sourceEnd) {
+			InstallSource *is = new InstallSource("HTTP", sourceBegin->second.c_str());
+			sources[is->caption] = is;
+			SWBuf parent = (SWBuf)privatePath + "/" + is->uid + "/file";
+			FileMgr::createParent(parent.c_str());
+			is->localShadow = (SWBuf)privatePath + "/" + is->uid;
+			sourceBegin++;
+		}
 	}
 
 	defaultMods.clear();
@@ -176,11 +187,11 @@
 
 void InstallMgr::saveInstallConf() {
 
-	installConf->Sections["Sources"].erase("FTPSource");
+	installConf->Sections["Sources"].clear();
 
 	for (InstallSourceMap::iterator it = sources.begin(); it != sources.end(); ++it) {
 		if (it->second) {
-			installConf->Sections["Sources"].insert(ConfigEntMap::value_type("FTPSource", it->second->getConfEnt().c_str()));
+			installConf->Sections["Sources"].insert(ConfigEntMap::value_type(it->second->type + "Source", it->second->getConfEnt().c_str()));
 		}
 	}
 	(*installConf)["General"]["PassiveFTP"] = (isFTPPassive()) ? "true" : "false";
@@ -258,13 +269,21 @@
 }
 
 
+// TODO: rename to netCopy
 int InstallMgr::ftpCopy(InstallSource *is, const char *src, const char *dest, bool dirTransfer, const char *suffix) {
 
 	// assert user disclaimer has been confirmed
 	if (!isUserDisclaimerConfirmed()) return -1;
 
 	int retVal = 0;
-	FTPTransport *trans = createFTPTransport(is->source, statusReporter);
+	FTPTransport *trans = 0;
+	if (is->type == "FTP") {
+		trans = createFTPTransport(is->source, statusReporter);
+		trans->setPassive(passive);
+	}
+	else if (is->type == "HTTP") {
+		trans = createHTTPTransport(is->source, statusReporter);
+	}
 	transport = trans; // set classwide current transport for other thread terminate() call
 	if (is->u.length()) {
 		trans->setUser(is->u);
@@ -274,9 +293,8 @@
 		trans->setUser(u);
 		trans->setPasswd(p);
 	}
-	trans->setPassive(passive);
 
-	SWBuf urlPrefix = (SWBuf)"ftp://" + is->source;
+	SWBuf urlPrefix = (SWBuf)((is->type == "HTTP") ? "http://" : "ftp://") + is->source;
 
 	// let's be sure we can connect.  This seems to be necessary but sucks
 //	SWBuf url = urlPrefix + is->directory.c_str() + "/"; //dont forget the final slash
@@ -301,7 +319,7 @@
 			removeTrailingSlash(url);
 			url += (SWBuf)"/" + src; //dont forget the final slash
 			if (trans->getURL(dest, url.c_str())) {
-				SWLog::getSystemLog()->logDebug("FTPCopy: failed to get file %s", url.c_str());
+				SWLog::getSystemLog()->logDebug("netCopy: failed to get file %s", url.c_str());
 				retVal = -1;
 			}
 		}
@@ -365,7 +383,7 @@
 
 		if (fileBegin != fileEnd) {	// copy each file
 			if (is) {
-				while (fileBegin != fileEnd) {	// ftp each file first
+				while (fileBegin != fileEnd) {	// netCopy each file first
 					buffer = sourceDir + fileBegin->second.c_str();
 					if (ftpCopy(is, fileBegin->second.c_str(), buffer.c_str())) {
 						aborted = true;
@@ -394,7 +412,7 @@
 
 			if (is) {
 				fileBegin = module->second.lower_bound("File");
-				while (fileBegin != fileEnd) {	// delete each tmp ftp file
+				while (fileBegin != fileEnd) {	// delete each tmp netCopied file
 					buffer = sourceDir + fileBegin->second.c_str();
 					FileMgr::removeFile(buffer.c_str());
 					fileBegin++;
@@ -435,7 +453,7 @@
 					SWBuf destPath = (SWBuf)destMgr->prefixPath + relativePath;
 					FileMgr::copyDir(absolutePath.c_str(), destPath.c_str());
 				}
-				if (is) {		// delete tmp ftp files
+				if (is) {		// delete tmp netCopied files
 //					mgr->deleteModule(modName);
 					FileMgr::removeDir(absolutePath.c_str());
 				}




More information about the sword-cvs mailing list