[sword-svn] r2326 - in trunk: include lib/bcppmake src/mgr tests/testsuite

scribe at crosswire.org scribe at crosswire.org
Wed Apr 22 01:53:05 MST 2009


Author: scribe
Date: 2009-04-22 01:53:04 -0700 (Wed, 22 Apr 2009)
New Revision: 2326

Added:
   trunk/include/curlhttpt.h
   trunk/src/mgr/curlhttpt.cpp
   trunk/tests/testsuite/tmp/
Modified:
   trunk/include/canon_abbrevs.h
   trunk/include/ftptrans.h
   trunk/include/installmgr.h
   trunk/lib/bcppmake/libsword.bpf
   trunk/lib/bcppmake/libsword.bpr
   trunk/src/mgr/ftptrans.cpp
   trunk/src/mgr/installmgr.cpp
   trunk/src/mgr/swmgr.cpp
Log:
Added abbrevs which prefer traditional canon books
Changed installmgr to encourage a best practices way to enable remote features
Commented installmgr.h
Updated Windows lookup logic to use APPDATA
Added stub for CURLHTTPTransport (don't get excited, this isn't close to working yet, but wanted to have it in the API so we can work on it in the 1.6.x branch
Added some missing header files

Modified: trunk/include/canon_abbrevs.h
===================================================================
--- trunk/include/canon_abbrevs.h	2009-04-20 19:09:25 UTC (rev 2325)
+++ trunk/include/canon_abbrevs.h	2009-04-22 08:53:04 UTC (rev 2326)
@@ -222,6 +222,7 @@
   {"EPJ", "EpJer"},		// Epistle of Jeremiah
   {"EPJER", "EpJer"},		// Epistle of Jeremiah
   {"EPLAO", "EpLao"},		// Laodiceans
+  {"ES", "Esth"},               // Esther
   {"ESDRAS A", "1Esd"},		// I Esdras
   {"ESDRAS B", "2Esd"},		// II Esdras
   {"ESDRASA", "1Esd"},		// I Esdras
@@ -384,6 +385,7 @@
   {"J", "Josh"},		// Joshua
   {"JAMES", "Jas"},		// James
   {"JAS", "Jas"},		// James
+  {"JD", "Judg"},		// Judges
   {"JDA", "JudgA"},		// Judges (Codex Alexandrinus)
   {"JDB", "JudgB"},		// Judges (Codex Vaticanus)
   {"JDGS", "Judg"},		// Judges
@@ -406,6 +408,7 @@
   {"JOSHUA (CODEX VATICANUS)", "JoshB"},		// Joshua (Codex Vaticanus)
   {"JSA", "JoshA"},		// Joshua (Codex Alexandrinus)
   {"JSB", "JoshB"},		// Joshua (Codex Vaticanus)
+  {"JU", "Jude"},		// Jude
   {"JUB", "Jub"},		// Jubilees
   {"JUBILEES", "Jub"},		// Jubilees
   {"JUDE", "Jude"},		// Jude
@@ -421,6 +424,7 @@
   {"LAMENTATIONS", "Lam"},		// Lamentations
   {"LAO", "EpLao"},		// Laodiceans
   {"LAODICEANS", "EpLao"},		// Laodiceans
+  {"LE", "Lev"},		// Leviticus
   {"LESSER GENESIS", "Jub"},		// Jubilees
   {"LETJER", "EpJer"},		// Epistle of Jeremiah
   {"LETTER OF JEREMIAH", "EpJer"},		// Epistle of Jeremiah
@@ -462,6 +466,7 @@
   {"PHLM", "Phlm"},		// Philemon
   {"PHM", "Phlm"},		// Philemon
   {"PHP", "Phil"},		// Philippians
+  {"PR", "Prov"},		// Proverbs
   {"PRA", "PrAzar"},		// Prayer of Azariah
   {"PRAYER OF AZARIAH", "PrAzar"},		// Prayer of Azariah
   {"PRAYER OF MANASSEH", "PrMan"},		// Prayer of Manasses

Added: trunk/include/curlhttpt.h
===================================================================
--- trunk/include/curlhttpt.h	                        (rev 0)
+++ trunk/include/curlhttpt.h	2009-04-22 08:53:04 UTC (rev 2326)
@@ -0,0 +1,52 @@
+/******************************************************************************
+*  curlhttpt.h  - code for CURL impl of HTTP Transport
+*
+* $Id: swbuf.h 2218 2008-12-23 09:33:38Z scribe $
+*
+* Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
+*	CrossWire Bible Society
+*	P. O. Box 2528
+*	Tempe, AZ  85280-2528
+*
+* This program is free software; you can redistribute it and/or modify it
+* under the terms of the GNU General Public License as published by the
+* Free Software Foundation version 2.
+*
+* This program is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+* General Public License for more details.
+*
+*/
+#ifndef CURLHTTPT_H
+#define CURLHTTPT_H
+
+#include <defs.h>
+#include <ftptrans.h>
+
+SWORD_NAMESPACE_START
+
+class CURL;
+
+// initialize/cleanup SYSTEMWIDE library with life of this static.
+class CURLHTTPTransport_init {
+public:
+	CURLHTTPTransport_init();
+	~CURLHTTPTransport_init();
+};
+
+
+class SWDLLEXPORT CURLHTTPTransport : public FTPTransport {
+	CURL *session;
+
+public:
+	CURLHTTPTransport(const char *host, StatusReporter *statusReporter = 0);
+	~CURLHTTPTransport();
+
+	virtual char getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf = 0);
+};
+
+
+SWORD_NAMESPACE_END
+
+#endif

Modified: trunk/include/ftptrans.h
===================================================================
--- trunk/include/ftptrans.h	2009-04-20 19:09:25 UTC (rev 2325)
+++ trunk/include/ftptrans.h	2009-04-22 08:53:04 UTC (rev 2326)
@@ -1,3 +1,26 @@
+/******************************************************************************
+*  ftptrans.h  - code for FTP Transport
+*
+* $Id: swbuf.h 2218 2008-12-23 09:33:38Z scribe $
+*
+* Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
+*	CrossWire Bible Society
+*	P. O. Box 2528
+*	Tempe, AZ  85280-2528
+*
+* This program is free software; you can redistribute it and/or modify it
+* under the terms of the GNU General Public License as published by the
+* Free Software Foundation version 2.
+*
+* This program is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+* General Public License for more details.
+*
+*/
+
+// TODO: Rename this to RemoteTransport in 1.7.x
+
 #ifndef FTPTRANS_H
 #define FTPTRANS_H
 
@@ -5,14 +28,7 @@
 #include <defs.h>
 #include <swbuf.h>
 
-//SWORD_NAMESPACE_START
 
-
-// move this include to cpp once struct ftpparse isn't exposed anymore
-extern "C" {
-#include <ftpparse.h>
-}
-
 SWORD_NAMESPACE_START
 
 /** Class for reporting status
@@ -22,7 +38,7 @@
 	virtual ~StatusReporter() {};
 	/** Messages before stages of a batch download */
 	virtual void preStatus(long totalBytes, long completedBytes, const char *message);
-	
+
 	/** frequently called throughout a download, to report status */
 	virtual void statusUpdate(double dtTotal, double dlNow);
 };
@@ -31,7 +47,7 @@
 /** TODO: document
 * A base class to be used for reimplementation of network services.
 */
-class SWDLLEXPORT FTPTransport {
+class SWDLLEXPORT FTPTransport {	// TODO: rename to more generic RemoteTransport
 
 protected:
 	StatusReporter *statusReporter;
@@ -40,14 +56,14 @@
 	SWBuf host;
 	SWBuf u;
 	SWBuf p;
-	
+
 public:
 	FTPTransport(const char *host, StatusReporter *statusReporter = 0);
 	virtual ~FTPTransport();
 
 	/***********
 	 * override this method in your real impl
-	 * 
+	 *
 	 * if destBuf then write to buffer instead of file
 	 */
 	virtual char getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf = 0);

Modified: trunk/include/installmgr.h
===================================================================
--- trunk/include/installmgr.h	2009-04-20 19:09:25 UTC (rev 2325)
+++ trunk/include/installmgr.h	2009-04-22 08:53:04 UTC (rev 2326)
@@ -14,7 +14,7 @@
 class FTPTransport;
 class StatusReporter;
 
-/** TODO: document
+/** A remote installation source configuration
 */
 class SWDLLEXPORT InstallSource {
 	SWMgr *mgr;
@@ -38,10 +38,12 @@
 	void flush();
 };
 
+/** A standard map of remote install sources.
+ */
 typedef std::map<SWBuf, InstallSource *> InstallSourceMap;
 
-/** TODO: document
-*/
+/** Class to handle installation and maintenance of a SWORD library of books.
+ */
 class SWDLLEXPORT InstallMgr {
 
 protected:
@@ -52,14 +54,21 @@
 	StatusReporter *statusReporter;
 	bool passive;
 	SWBuf u, p;
-	
-	// override this method and provide your own custom FTPTransport subclass
+
+	/** override this method and provide your own custom FTPTransport subclass
+         */
 	virtual FTPTransport *createFTPTransport(const char *host, StatusReporter *statusReporter);
 
-	// we have a transport member to set as current running transport so we
-	// can ask it to terminate below, if user requests
-	FTPTransport *transport;	
-	
+	/** override this method and provide your own custom HTTP RemoteTransport (still called FTPTransport in pre 1.7.x) subclass
+         */
+	virtual FTPTransport *createHTTPTransport(const char *host, StatusReporter *statusReporter);
+
+
+	/** we have a transport member to set as current running transport so we
+	 *  can ask it to terminate below, if user requests
+         */
+	FTPTransport *transport;
+
 public:
 
 	static const int MODSTAT_OLDER;
@@ -70,35 +79,66 @@
 	static const int MODSTAT_CIPHERKEYPRESENT;
 
 	SWConfig *installConf;
+
+        /** all remote sources configured for this installmgr.  Use this to gain access
+         *  to individual remote sources.
+         */
 	InstallSourceMap sources;
-	bool term;
 
-	// Username and Password supplied here can be used to identify your frontend
-	// by supplying a valid anon password like installmgr at macsword.com
-	// This will get overridden if a password is required and provided in an indivual
-	// source configuration
+	/** Username and Password supplied here can be used to identify your frontend
+	 *  by supplying a valid anon password like installmgr at macsword.com
+	 *  This will get overridden if a password is required and provided in an indivual
+	 *  source configuration.
+         */
 	InstallMgr(const char *privatePath = "./", StatusReporter *statusReporter = 0, SWBuf u="ftp", SWBuf p="installmgr at user.com");
 	virtual ~InstallMgr();
 
-	// Call to re-read InstallMgr.conf
+	/** Call to re-read InstallMgr.conf
+         */
 	void readInstallConf();
 
-	// Call to dump sources and other settings to InstallMgr.conf
+	/** Call to dump sources and other settings to InstallMgr.conf
+         */
 	void saveInstallConf();
 
-	// Removes all configured sources from memory.  Call saveInstallConf() to persist
+	/** Removes all configured sources from memory.  Call saveInstallConf() to persist
+         */
 	void clearSources();
 
+        /** call to delete all files of a locally installed module.
+         */
 	virtual int removeModule(SWMgr *manager, const char *modName);
+
+        /** mostly an internally used method to ftp download from an remote source to a local destination
+         */
 	virtual int ftpCopy(InstallSource *is, const char *src, const char *dest, bool dirTransfer = false, const char *suffix = "");
+
+        /** call to install a module from a local path (fromLocation) or remote InstallSource (is) (leave the other 0)
+         */
 	virtual int installModule(SWMgr *destMgr, const char *fromLocation, const char *modName, InstallSource *is = 0);
-	
+
+        /** call to obtain and locally cache the available content list of the remote source
+         */
 	virtual int refreshRemoteSource(InstallSource *is);
+
+        /** call to populate installmgr configuration with all known
+         *  remote sources from the master list at CrossWire
+         */
 	virtual int refreshRemoteSourceConfiguration();
-	/* user disclaimer should ask user for confirmation of 2 critical items:
-	 * and the default answer should be NO
-	 * (possible wrong language of disclaimer)
+
+	/** override this and provide an input mechanism to allow your users
+	 *  to confirm that they understand this important disclaimer.
+	 *  return true your user confirms.
+         *
+	 *  user disclaimer should ask user for confirmation of 2 critical items:
+	 *  and the default answer should be NO
+	 *  (possible wrong language of disclaimer)
 	 *
+
+A sample impl:
+
+	static bool confirmed = false;
+        if (!confirmed) {
 		cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
 		cout << "                -=+* WARNING *+=- -=+* WARNING *+=-\n\n\n";
 		cout << "Although Install Manager provides a convenient way for installing\n";
@@ -108,7 +148,7 @@
 		cout << "IF YOU LIVE IN A PERSECUTED COUNTRY AND DO NOT WISH TO RISK DETECTION,\n";
 		cout << "YOU SHOULD *NOT* USE INSTALL MANAGER'S REMOTE SOURCE FEATURES.\n\n\n";
 		cout << "Also, Remote Sources other than CrossWire may contain less than\n";
-		cout << "quality modules, module with unorthodox content, or even modules\n";
+		cout << "quality modules, modules with unorthodox content, or even modules\n";
 		cout << "which are not legitimately distributable.  Many repositories\n";
 		cout << "contain wonderfully useful content.  These repositories simply\n";
 		cout << "are not reviewed or maintained by CrossWire and CrossWire\n";
@@ -116,17 +156,67 @@
 		cout << "If you understand this and are willing to enable remote source features\n";
 		cout << "then type yes at the prompt\n\n";
 		cout << "enable? [no] ";
+
+		char prompt[10];
+		fgets(prompt, 9, stdin);
+		confirmed = (!strcmp(prompt, "yes\n"));
+        }
+        return confirmed;
+
+         */
+	virtual bool isUserDisclaimerConfirmed() const { return false; }
+
+
+	/** override this and provide an input mechanism to allow your users
+	 * to enter the decipher code for a module.
+	 * return true you added the cipher code to the config.
+	 * default to return 'aborted'
+
+A sample implementation, roughly taken from the windows installmgr:
+
+	SectionMap::iterator section;
+	ConfigEntMap::iterator entry;
+	SWBuf tmpBuf;
+	section = config->Sections.find(modName);
+	if (section != config->Sections.end()) {
+		entry = section->second.find("CipherKey");
+		if (entry != section->second.end()) {
+			entry->second = GET_USER_INPUT();
+			config->Save();
+
+			// LET'S SHOW THE USER SOME SAMPLE TEXT FROM THE MODULE
+			SWMgr *mgr = new SWMgr();
+			SWModule *mod = mgr->getModule(modName);
+			mod->setKey("Ipet 2:12");
+			tmpBuf = mod->StripText();
+			mod->setKey("gen 1:10");
+			tmpBuf += "\n\n";
+			tmpBuf += mod->StripText();
+			SOME_DIALOG_CONTROL->SETTEXT(tmpBuf.c_str());
+			delete mgr;
+
+			// if USER CLICKS OK means we should return true
+			return true;
+		}
+	}
+	return false;
+}
 	*/
+       	virtual bool getCipherCode(const char *modName, SWConfig *config) { return false; }
 
-	bool isUserDisclaimerConfirmed() const { return userDisclaimerConfirmed; }
-	void setUserDisclaimerConfirmed(bool val) { userDisclaimerConfirmed = val; }
-	virtual bool getCipherCode(const char *modName, SWConfig *config);
+
+
+	/** whether or not to use passive mode when doing ftp transfers
+         */
 	void setFTPPassive(bool passive) { this->passive = passive; }
 	bool isFTPPassive() { return passive; }
+
+        /** call from another thread to terminate the installation process
+         */
 	void terminate();
 
 	/************************************************************************
-	 * getModuleStatus - compare the modules of two SWMgrs and return a 
+	 * getModuleStatus - compare the modules of two SWMgrs and return a
 	 * 	vector describing the status of each.  See MODSTAT_*
 	 */
 	static std::map<SWModule *, int> getModuleStatus(const SWMgr &base, const SWMgr &other);

Modified: trunk/lib/bcppmake/libsword.bpf
===================================================================
--- trunk/lib/bcppmake/libsword.bpf	2009-04-20 19:09:25 UTC (rev 2325)
+++ trunk/lib/bcppmake/libsword.bpf	2009-04-22 08:53:04 UTC (rev 2326)
@@ -150,6 +150,7 @@
 USEUNIT("..\..\src\modules\filters\teihtmlhref.cpp");
 USEUNIT("..\..\src\mgr\versemgr.cpp");
 USEUNIT("..\..\src\modules\filters\osisruby.cpp");
+USEUNIT("..\..\src\mgr\curlhttpt.cpp");
 //---------------------------------------------------------------------------
 #define Library
 

Modified: trunk/lib/bcppmake/libsword.bpr
===================================================================
--- trunk/lib/bcppmake/libsword.bpr	2009-04-20 19:09:25 UTC (rev 2325)
+++ trunk/lib/bcppmake/libsword.bpr	2009-04-22 08:53:04 UTC (rev 2326)
@@ -118,7 +118,7 @@
       ..\..\src\modules\comments\rawcom4\rawcom4.obj 
       ..\..\src\modules\common\rawverse4.obj 
       ..\..\src\modules\filters\teihtmlhref.obj ..\..\src\mgr\versemgr.obj 
-      ..\..\src\modules\filters\osisruby.obj"/>
+      ..\..\src\modules\filters\osisruby.obj ..\..\src\mgr\curlhttpt.obj"/>
     <RESFILES value=""/>
     <IDLFILES value=""/>
     <IDLGENFILES value=""/>
@@ -132,7 +132,7 @@
     <PATHRC value=".;"/>
     <PATHASM value=".;"/>
     <LINKER value="TLib"/>
-    <USERDEFINES value="UNICODE;_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;USELUCENE;_WIN32;_CL_DISABLE_MULTITHREADING;CURLAVAILABLE;LUCENE_ENABLE_REFCOUNT;_DEBUG"/>
+    <USERDEFINES value="UNICODE;_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;USELUCENE;_WIN32;_CL_DISABLE_MULTITHREADING;CURLAVAILABLE;LUCENE_ENABLE_REFCOUNT"/>
     <SYSDEFINES value="NO_STRICT"/>
     <MAINSOURCE value="libsword.bpf"/>
     <INCLUDEPATH value="..\..\src\modules\comments\rawcom4;..\..\src\modules\texts\rawtext4;..\..\src\modules\tests;..\..\src\utilfuns\zlib;..\..\src\modules\lexdict\zld;..\..\src\modules\lexdict\rawld4;..\..\src\modules\comments\zcom;..\..\src\modules\genbook\rawgenbook;..\..\src\modules\genbook;..\..\src\modules\texts\ztext;..\..\src\modules\texts\rawtext;..\..\src\modules\texts;..\..\src\modules\lexdict\rawld;..\..\src\modules\lexdict;..\..\src\modules\filters;..\..\src\modules\common;..\..\src\modules\comments\rawfiles;..\..\src\modules\comments\rawcom;..\..\src\modules\comments\hrefcom;..\..\src\modules\comments;..\..\src\modules;..\..\src\frontend;..\..\src\utilfuns;..\..\src\mgr;..\..\src\keys;..\..\..\icu-sword\source\common;..\..\apps\windoze\CBuilder5\InstallMgr\curl\include;..\..\include;$(BCB)\include;$(BCB)\include\vcl;..\..\..\icu-sword\source\i18n;..\..\..\biblecs\clucene\src;..\..\..\biblecs\apps\InstallMgr\curl\include"/>
@@ -160,9 +160,9 @@
       -D_ICU_ -D_ICUSWORD_ -DUSBINARY -DU_HAVE_PLACEMENT_NEW=0 -DUSELUCENE 
       -D_WIN32 -D_CL_DISABLE_MULTITHREADING -DCURLAVAILABLE 
       -DLUCENE_ENABLE_REFCOUNT -no_tie -boa"/>
-    <CFLAG1 value="-Od -Vx -X- -r- -a8 -4 -b- -k -y -v -vi- -c -tW -tWM"/>
-    <PFLAGS value="-$Y+ -$W -$O- -v -JPHNE -M"/>
-    <AFLAGS value="/mx /w2 /zi"/>
+    <CFLAG1 value="-O2 -Vx -X- -a8 -4 -b- -k- -vi -c -tW -tWM"/>
+    <PFLAGS value="-$Y- -$L- -$D- -v -JPHNE -M"/>
+    <AFLAGS value="/mx /w2 /zn"/>
     <LFLAGS value="/P512"/>
   </OPTIONS>
   <LINKER>
@@ -238,8 +238,8 @@
 
 [HistoryLists\hlConditionals]
 Count=25
-Item0=UNICODE;_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;USELUCENE;_WIN32;_CL_DISABLE_MULTITHREADING;CURLAVAILABLE;LUCENE_ENABLE_REFCOUNT;_DEBUG
-Item1=UNICODE;_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;USELUCENE;_WIN32;_CL_DISABLE_MULTITHREADING;CURLAVAILABLE;LUCENE_ENABLE_REFCOUNT
+Item0=UNICODE;_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;USELUCENE;_WIN32;_CL_DISABLE_MULTITHREADING;CURLAVAILABLE;LUCENE_ENABLE_REFCOUNT
+Item1=UNICODE;_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;USELUCENE;_WIN32;_CL_DISABLE_MULTITHREADING;CURLAVAILABLE;LUCENE_ENABLE_REFCOUNT;_DEBUG
 Item2=UNICODE;_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;USELUCENE;_WIN32;_CL_DISABLE_MULTITHREADING;CURLAVAILABLE
 Item3=UNICODE;_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;USELUCENE;_WIN32;_CL_DISABLE_MULTITHREADING
 Item4=UNICODE;_ICU_;_ICUSWORD_;USBINARY;U_HAVE_PLACEMENT_NEW=0;USELUCENE;_WIN32;_CL_DISABLE_MULTITHREADING;_DEBUG

Added: trunk/src/mgr/curlhttpt.cpp
===================================================================
--- trunk/src/mgr/curlhttpt.cpp	                        (rev 0)
+++ trunk/src/mgr/curlhttpt.cpp	2009-04-22 08:53:04 UTC (rev 2326)
@@ -0,0 +1,178 @@
+ /*****************************************************************************
+ * CURLHTTPTransport functions
+ *
+ *
+ *
+ * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
+ *	CrossWire Bible Society
+ *	P. O. Box 2528
+ *	Tempe, AZ  85280-2528
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ */
+
+
+
+#include <curlhttpt.h>
+
+#include <fcntl.h>
+
+#include <curl/curl.h>
+#include <curl/types.h>
+#include <curl/easy.h>
+
+#include <swlog.h>
+
+SWORD_NAMESPACE_START
+
+
+struct FtpFile {
+  const char *filename;
+  FILE *stream;
+  SWBuf *destBuf;
+};
+
+
+int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream);
+int my_fprogress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
+
+static CURLHTTPTransport_init _CURLHTTPTransport_init;
+
+CURLHTTPTransport_init::CURLHTTPTransport_init() {
+	//curl_global_init(CURL_GLOBAL_DEFAULT);  // curl_easy_init automatically calls it if needed
+}
+
+CURLHTTPTransport_init::~CURLHTTPTransport_init() {
+// CURLFTPT d-tor cleans this up
+//	curl_global_cleanup();
+}
+
+int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
+	struct FtpFile *out=(struct FtpFile *)stream;
+	if (out && !out->stream && !out->destBuf) {
+		/* open file for writing */
+		out->stream=fopen(out->filename, "wb");
+		if (!out->stream)
+			return -1; /* failure, can't open file to write */
+	}
+	if (out->destBuf) {
+		int s = out->destBuf->size();
+		out->destBuf->size(s+(size*nmemb));
+		memcpy(out->destBuf->getRawData()+s, buffer, size*nmemb);
+		return nmemb;
+	}
+	return fwrite(buffer, size, nmemb, out->stream);
+}
+
+
+int my_fprogress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) {
+	if (clientp) {
+		((StatusReporter *)clientp)->statusUpdate(dltotal, dlnow);
+	}
+	return 0;
+}
+
+
+static int my_trace(CURL *handle, curl_infotype type, unsigned char *data, size_t size, void *userp) {
+	SWBuf header;
+	(void)userp; /* prevent compiler warning */
+	(void)handle; /* prevent compiler warning */
+
+	switch (type) {
+	case CURLINFO_TEXT: header = "TEXT"; break;
+	case CURLINFO_HEADER_OUT: header = "=> Send header"; break;
+	case CURLINFO_HEADER_IN: header = "<= Recv header"; break;
+
+	// these we don't want to log (HUGE)
+	case CURLINFO_DATA_OUT: header = "=> Send data";
+	case CURLINFO_SSL_DATA_OUT: header = "=> Send SSL data";
+	case CURLINFO_DATA_IN: header = "<= Recv data";
+	case CURLINFO_SSL_DATA_IN: header = "<= Recv SSL data";
+	default: /* in case a new one is introduced to shock us */
+		return 0;
+	}
+
+	if (size > 120) size = 120;
+	SWBuf text;
+	text.size(size);
+	memcpy(text.getRawData(), data, size);
+	SWLog::getSystemLog()->logDebug("CURLHTTPTransport: %s: %s", header.c_str(), text.c_str());
+	return 0;
+}
+
+CURLHTTPTransport::CURLHTTPTransport(const char *host, StatusReporter *sr) : FTPTransport(host, sr) {
+	session = (CURL *)curl_easy_init();
+}
+
+
+CURLHTTPTransport::~CURLHTTPTransport() {
+	curl_easy_cleanup(session);
+}
+
+
+char CURLHTTPTransport::getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf) {
+	signed char retVal = 0;
+	struct FtpFile ftpfile = {destPath, 0, destBuf};
+
+	CURLcode res;
+
+	if (session) {
+		curl_easy_setopt(session, CURLOPT_URL, sourceURL);
+
+		SWBuf credentials = u + ":" + p;
+		curl_easy_setopt(session, CURLOPT_USERPWD, credentials.c_str());
+		curl_easy_setopt(session, CURLOPT_WRITEFUNCTION, my_fwrite);
+		if (!passive)
+			curl_easy_setopt(session, CURLOPT_FTPPORT, "-");
+		curl_easy_setopt(session, CURLOPT_NOPROGRESS, 0);
+		curl_easy_setopt(session, CURLOPT_PROGRESSDATA, statusReporter);
+		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);
+		
+		/* FTP connection settings */
+
+#if (LIBCURL_VERSION_MAJOR > 7) || \
+   ((LIBCURL_VERSION_MAJOR == 7) && (LIBCURL_VERSION_MINOR > 10)) || \
+   ((LIBCURL_VERSION_MAJOR == 7) && (LIBCURL_VERSION_MINOR == 10) && (LIBCURL_VERSION_PATCH >= 5))
+#      define EPRT_AVAILABLE 1
+#endif
+
+#ifdef EPRT_AVAILABLE
+		curl_easy_setopt(session, CURLOPT_FTP_USE_EPRT, 0);
+		SWLog::getSystemLog()->logDebug("***** using CURLOPT_FTP_USE_EPRT\n");
+#endif
+
+
+		SWLog::getSystemLog()->logDebug("***** About to perform curl easy action. \n");
+		SWLog::getSystemLog()->logDebug("***** destPath: %s \n", destPath);
+		SWLog::getSystemLog()->logDebug("***** sourceURL: %s \n", sourceURL);
+		res = curl_easy_perform(session);
+		SWLog::getSystemLog()->logDebug("***** Finished performing curl easy action. \n");
+
+		if(CURLE_OK != res) {
+			retVal = -1;
+		}
+	}
+
+	if (ftpfile.stream)
+		fclose(ftpfile.stream); /* close the local file */
+
+	return retVal;
+}
+
+
+SWORD_NAMESPACE_END
+

Modified: trunk/src/mgr/ftptrans.cpp
===================================================================
--- trunk/src/mgr/ftptrans.cpp	2009-04-20 19:09:25 UTC (rev 2325)
+++ trunk/src/mgr/ftptrans.cpp	2009-04-22 08:53:04 UTC (rev 2326)
@@ -29,6 +29,9 @@
 #include <dirent.h>
 #include <swlog.h>
 
+extern "C" {
+#include <ftpparse.h>
+}
 
 using std::vector;
 

Modified: trunk/src/mgr/installmgr.cpp
===================================================================
--- trunk/src/mgr/installmgr.cpp	2009-04-20 19:09:25 UTC (rev 2325)
+++ trunk/src/mgr/installmgr.cpp	2009-04-22 08:53:04 UTC (rev 2326)
@@ -45,6 +45,7 @@
 
 #ifdef CURLAVAILABLE
 #include <curlftpt.h>
+#include <curlhttpt.h>
 #else
 #include <ftplibftpt.h>
 #endif
@@ -86,8 +87,16 @@
 #endif
 }
 
+FTPTransport *InstallMgr::createHTTPTransport(const char *host, StatusReporter *statusReporter) {
+#ifdef CURLAVAILABLE
+	return new CURLHTTPTransport(host, statusReporter);
+#else
+	return 0;
+#endif
+}
 
 
+
 InstallMgr::InstallMgr(const char *privatePath, StatusReporter *sr, SWBuf u, SWBuf p) {
 	userDisclaimerConfirmed = false;
 	statusReporter = sr;
@@ -197,7 +206,7 @@
 		// to be sure all files are closed
 		// this does not remove the .conf information from SWMgr
 		manager->deleteModule(modName);
-			
+
 		fileBegin = module->second.lower_bound("File");
 		fileEnd = module->second.upper_bound("File");
 
@@ -266,7 +275,7 @@
 		trans->setPasswd(p);
 	}
 	trans->setPassive(passive);
-	
+
 	SWBuf urlPrefix = (SWBuf)"ftp://" + is->source;
 
 	// let's be sure we can connect.  This seems to be necessary but sucks
@@ -276,7 +285,7 @@
 //		 return -1;
 //	}
 
-	   
+
 	if (dirTransfer) {
 		SWBuf dir = (SWBuf)is->directory.c_str();
 		removeTrailingSlash(dir);
@@ -470,47 +479,6 @@
 	return 1;
 }
 
-
-// override this and provide an input mechanism to allow your users
-// to enter the decipher code for a module.
-// return true you added the cipher code to the config.
-// default to return 'aborted'
-bool InstallMgr::getCipherCode(const char *modName, SWConfig *config) {
-	return false;
-
-/* a sample implementation, roughly taken from the windows installmgr
-
-	SectionMap::iterator section;
-	ConfigEntMap::iterator entry;
-	SWBuf tmpBuf;
-	section = config->Sections.find(modName);
-	if (section != config->Sections.end()) {
-		entry = section->second.find("CipherKey");
-		if (entry != section->second.end()) {
-			entry->second = GET_USER_INPUT();
-			config->Save();
-
-			// LET'S SHOW THE USER SOME SAMPLE TEXT FROM THE MODULE
-			SWMgr *mgr = new SWMgr();
-			SWModule *mod = mgr->Modules[modName];
-			mod->setKey("Ipet 2:12");
-			tmpBuf = mod->StripText();
-			mod->setKey("gen 1:10");
-			tmpBuf += "\n\n";
-			tmpBuf += mod->StripText();
-			SOME_DIALOG_CONTROL->SETTEXT(tmpBuf.c_str());
-			delete mgr;
-
-			// if USER CLICKS OK means we should return true
-			return true;
-		}
-	}
-	return false;
-*/
-
-}
-
-
 int InstallMgr::refreshRemoteSource(InstallSource *is) {
 
 	// assert user disclaimer has been confirmed
@@ -520,7 +488,7 @@
 	removeTrailingSlash(root);
 	SWBuf target = root + "/mods.d";
 	int errorCode = -1; //0 means successful
-	
+
 	FileMgr::removeDir(target.c_str());
 
 	if (!FileMgr::existsDir(target))
@@ -528,17 +496,17 @@
 
 #ifndef EXCLUDEZLIB
 	SWBuf archive = root + "/mods.d.tar.gz";
-	
+
 	errorCode = ftpCopy(is, "mods.d.tar.gz", archive.c_str(), false);
 	if (!errorCode) { //sucessfully downloaded the tar,gz of module configs
 		FileDesc *fd = FileMgr::getSystemFileMgr()->open(archive.c_str(), FileMgr::RDONLY);
 		untargz(fd->getFd(), root.c_str());
 		FileMgr::getSystemFileMgr()->close(fd);
 	}
-	else if (!term) //if the tar.gz download was canceled don't continue with another download
+	else
 #endif
 	errorCode = ftpCopy(is, "mods.d", target.c_str(), true, ".conf"); //copy the whole directory
-	
+
 	is->flush();
 	return errorCode;
 }

Modified: trunk/src/mgr/swmgr.cpp
===================================================================
--- trunk/src/mgr/swmgr.cpp	2009-04-20 19:09:25 UTC (rev 2325)
+++ trunk/src/mgr/swmgr.cpp	2009-04-22 08:53:04 UTC (rev 2326)
@@ -254,11 +254,7 @@
 	SWBuf homeDir = getenv("HOME");
 	if (!homeDir.length()) {
 		// silly windows
-		homeDir = getenv("HOMEDRIVE");
-		if (homeDir.length()) {
-			homeDir += getenv("HOMEPATH");
-			homeDir += "/Application Data";
-		}
+		homeDir = getenv("APPDATA");
 	}
 	if (homeDir.length()) {
 		if ((homeDir[homeDir.length()-1] != '\\') && (homeDir[homeDir.length()-1] != '/')) {




More information about the sword-cvs mailing list