summaryrefslogtreecommitdiff
path: root/src/mgr
diff options
context:
space:
mode:
Diffstat (limited to 'src/mgr')
-rw-r--r--src/mgr/Makefile.am4
-rw-r--r--src/mgr/curlftpt.cpp150
-rw-r--r--src/mgr/curlhttpt.cpp142
-rw-r--r--src/mgr/encfiltmgr.cpp150
-rw-r--r--src/mgr/filemgr.cpp19
-rw-r--r--src/mgr/ftplibftpt.cpp126
-rw-r--r--src/mgr/installmgr.cpp118
-rw-r--r--src/mgr/localemgr.cpp17
-rw-r--r--src/mgr/markupfiltmgr.cpp442
-rw-r--r--src/mgr/remotetrans.cpp (renamed from src/mgr/ftptrans.cpp)65
-rw-r--r--src/mgr/stringmgr.cpp125
-rw-r--r--src/mgr/swcacher.cpp13
-rw-r--r--src/mgr/swconfig.cpp14
-rw-r--r--src/mgr/swfiltermgr.cpp12
-rw-r--r--src/mgr/swlocale.cpp24
-rw-r--r--src/mgr/swmgr.cpp179
-rw-r--r--src/mgr/swsearchable.cpp17
-rw-r--r--src/mgr/versificationmgr.cpp (renamed from src/mgr/versemgr.cpp)145
18 files changed, 1000 insertions, 762 deletions
diff --git a/src/mgr/Makefile.am b/src/mgr/Makefile.am
index 10d7158..6acec3a 100644
--- a/src/mgr/Makefile.am
+++ b/src/mgr/Makefile.am
@@ -23,8 +23,8 @@ libsword_la_SOURCES += $(mgrdir)/swfiltermgr.cpp
libsword_la_SOURCES += $(mgrdir)/encfiltmgr.cpp
libsword_la_SOURCES += $(mgrdir)/markupfiltmgr.cpp
libsword_la_SOURCES += $(mgrdir)/filemgr.cpp
-libsword_la_SOURCES += $(mgrdir)/versemgr.cpp
-libsword_la_SOURCES += $(mgrdir)/ftptrans.cpp
+libsword_la_SOURCES += $(mgrdir)/versificationmgr.cpp
+libsword_la_SOURCES += $(mgrdir)/remotetrans.cpp
libsword_la_SOURCES += $(mgrdir)/swlocale.cpp
libsword_la_SOURCES += $(mgrdir)/localemgr.cpp
libsword_la_SOURCES += $(mgrdir)/swcacher.cpp
diff --git a/src/mgr/curlftpt.cpp b/src/mgr/curlftpt.cpp
index 7d2fd3c..63eacb1 100644
--- a/src/mgr/curlftpt.cpp
+++ b/src/mgr/curlftpt.cpp
@@ -1,9 +1,10 @@
- /*****************************************************************************
- * CURLFTPTransport functions
+/*****************************************************************************
*
+ * curlftpt.cpp - CURLFTPTransport
*
+ * $Id: curlftpt.cpp 2980 2013-09-14 21:51:47Z scribe $
*
- * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
+ * Copyright 2004-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -19,106 +20,110 @@
*
*/
-
-
#include <curlftpt.h>
#include <fcntl.h>
#include <curl/curl.h>
-#include <curl/types.h>
#include <curl/easy.h>
#include <swlog.h>
-SWORD_NAMESPACE_START
+SWORD_NAMESPACE_START
-struct FtpFile {
- const char *filename;
- FILE *stream;
- SWBuf *destBuf;
-};
+namespace {
+ 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 CURLFTPTransport_init _CURLFTPTransport_init;
+ // initialize/cleanup SYSTEMWIDE library with life of this static.
+ static class CURLFTPTransport_init {
+ public:
+ CURLFTPTransport_init() {
+ curl_global_init(CURL_GLOBAL_DEFAULT); // curl_easy_init automatically calls it if needed
+ }
-CURLFTPTransport_init::CURLFTPTransport_init() {
- curl_global_init(CURL_GLOBAL_DEFAULT); // curl_easy_init automatically calls it if needed
-}
+ ~CURLFTPTransport_init() {
+ curl_global_cleanup();
+ }
+ } _curlFTPTransport_init;
-CURLFTPTransport_init::~CURLFTPTransport_init() {
- 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;
+ static 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);
}
- return fwrite(buffer, size, nmemb, out->stream);
-}
-struct MyProgressData {
- StatusReporter *sr;
- bool *term;
-};
+ struct MyProgressData {
+ StatusReporter *sr;
+ bool *term;
+ };
-int my_fprogress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) {
- if (clientp) {
- MyProgressData *pd = (MyProgressData *)clientp;
-SWLog::getSystemLog()->logDebug("CURLFTPTransport report progress: totalSize: %ld; xfered: %ld\n", (long)dltotal, (long)dlnow);
- if (pd->sr) {
- pd->sr->statusUpdate(dltotal, dlnow);
+ static int my_fprogress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) {
+ if (clientp) {
+ MyProgressData *pd = (MyProgressData *)clientp;
+ SWLog::getSystemLog()->logDebug("CURLFTPTransport report progress: totalSize: %ld; xfered: %ld\n", (long)dltotal, (long)dlnow);
+ if (pd->sr) {
+ if (dltotal < 0) dltotal = 0;
+ if (dlnow < 0) dlnow = 0;
+ if (dlnow > dltotal) dlnow = dltotal;
+ pd->sr->update(dltotal, dlnow);
+ }
+ if (*(pd->term)) return 1;
}
- if (*(pd->term)) return 1;
+ return 0;
}
- 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 */
+ 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 */
+ 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("CURLFTPTransport: %s: %s", header.c_str(), text.c_str());
return 0;
}
-
- if (size > 120) size = 120;
- SWBuf text;
- text.size(size);
- memcpy(text.getRawData(), data, size);
- SWLog::getSystemLog()->logDebug("CURLFTPTransport: %s: %s", header.c_str(), text.c_str());
- return 0;
}
-CURLFTPTransport::CURLFTPTransport(const char *host, StatusReporter *sr) : FTPTransport(host, sr) {
+
+CURLFTPTransport::CURLFTPTransport(const char *host, StatusReporter *sr) : RemoteTransport(host, sr) {
session = (CURL *)curl_easy_init();
}
@@ -156,6 +161,7 @@ char CURLFTPTransport::getURL(const char *destPath, const char *sourceURL, SWBuf
/* Switch on full protocol/debug output */
curl_easy_setopt(session, CURLOPT_VERBOSE, true);
+ curl_easy_setopt(session, CURLOPT_CONNECTTIMEOUT, 45);
/* FTP connection settings */
diff --git a/src/mgr/curlhttpt.cpp b/src/mgr/curlhttpt.cpp
index b736050..5db0ee7 100644
--- a/src/mgr/curlhttpt.cpp
+++ b/src/mgr/curlhttpt.cpp
@@ -1,9 +1,10 @@
- /*****************************************************************************
- * CURLHTTPTransport functions
+/*****************************************************************************
*
+ * curlhttpt.cpp - CURLHTTPTransport
*
+ * $Id: curlhttpt.cpp 2980 2013-09-14 21:51:47Z scribe $
*
- * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
+ * Copyright 2004-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -25,7 +26,6 @@
#include <cctype>
#include <curl/curl.h>
-#include <curl/types.h>
#include <curl/easy.h>
#include <swlog.h>
@@ -34,84 +34,77 @@
using std::vector;
-SWORD_NAMESPACE_START
-
-
-struct FtpFile {
- const char *filename;
- FILE *stream;
- SWBuf *destBuf;
-};
+SWORD_NAMESPACE_START
-int my_httpfwrite(void *buffer, size_t size, size_t nmemb, void *stream);
-int my_httpfprogress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
+namespace {
-static CURLHTTPTransport_init _CURLHTTPTransport_init;
+ struct FtpFile {
+ const char *filename;
+ FILE *stream;
+ SWBuf *destBuf;
+ };
-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_httpfwrite(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;
+ static int my_httpfwrite(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);
}
- return fwrite(buffer, size, nmemb, out->stream);
-}
-int my_httpfprogress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) {
- if (clientp) {
- ((StatusReporter *)clientp)->statusUpdate(dltotal, dlnow);
+ static int my_httpfprogress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) {
+ if (clientp) {
+ if (dltotal < 0) dltotal = 0;
+ if (dlnow < 0) dlnow = 0;
+ if (dlnow > dltotal) dlnow = dltotal;
+ ((StatusReporter *)clientp)->update(dltotal, dlnow);
+ }
+ return 0;
}
- return 0;
-}
-static int myhttp_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 */
+ static int myhttp_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;
+ 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;
+ }
- // 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 */
+ 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;
}
-
- 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) {
+
+CURLHTTPTransport::CURLHTTPTransport(const char *host, StatusReporter *sr) : RemoteTransport(host, sr) {
session = (CURL *)curl_easy_init();
}
@@ -136,6 +129,7 @@ char CURLHTTPTransport::getURL(const char *destPath, const char *sourceURL, SWBu
if (!passive)
curl_easy_setopt(session, CURLOPT_FTPPORT, "-");
curl_easy_setopt(session, CURLOPT_NOPROGRESS, 0);
+ curl_easy_setopt(session, CURLOPT_FAILONERROR, 1);
curl_easy_setopt(session, CURLOPT_PROGRESSDATA, statusReporter);
curl_easy_setopt(session, CURLOPT_PROGRESSFUNCTION, my_httpfprogress);
curl_easy_setopt(session, CURLOPT_DEBUGFUNCTION, myhttp_trace);
@@ -144,7 +138,11 @@ char CURLHTTPTransport::getURL(const char *destPath, const char *sourceURL, SWBu
/* Switch on full protocol/debug output */
curl_easy_setopt(session, CURLOPT_VERBOSE, true);
+ curl_easy_setopt(session, CURLOPT_CONNECTTIMEOUT, 45);
+ /* Disable checking host certificate */
+ curl_easy_setopt(session, CURLOPT_SSL_VERIFYPEER, false);
+
/* FTP connection settings */
#if (LIBCURL_VERSION_MAJOR > 7) || \
@@ -206,7 +204,7 @@ vector<struct DirEntry> CURLHTTPTransport::getDirList(const char *dirURL) {
SWBuf dirBuf;
const char *pBuf;
char *pBufRes;
- char possibleName[400];
+ SWBuf possibleName;
double fSize;
int possibleNameLength = 0;
@@ -215,10 +213,12 @@ vector<struct DirEntry> CURLHTTPTransport::getDirList(const char *dirURL) {
while (pBuf != NULL) {
pBuf += 9;//move to the start of the actual name.
pBufRes = (char *)strchr(pBuf, '\"');//Find the end of the possible file name
+ if (!pBufRes)
+ break;
possibleNameLength = pBufRes - pBuf;
- sprintf(possibleName, "%.*s", possibleNameLength, pBuf);
+ possibleName.setFormatted("%.*s", possibleNameLength, pBuf);
if (isalnum(possibleName[0])) {
- SWLog::getSystemLog()->logDebug("getDirListHTTP: Found a file: %s", possibleName);
+ SWLog::getSystemLog()->logDebug("getDirListHTTP: Found a file: %s", possibleName.c_str());
pBuf = pBufRes;
pBufRes = (char *)findSizeStart(pBuf);
fSize = 0;
@@ -229,13 +229,13 @@ vector<struct DirEntry> CURLHTTPTransport::getDirList(const char *dirURL) {
fSize *= 1024;
else if (pBufRes[0] == 'M')
fSize *= 1048576;
+ pBuf = pBufRes;
}
struct DirEntry i;
i.name = possibleName;
- i.size = fSize;
- i.isDirectory = (possibleName[possibleNameLength-1] == '/');
+ i.size = (long unsigned int)fSize;
+ i.isDirectory = possibleName.endsWith("/");
dirList.push_back(i);
- pBuf = pBufRes;
} else {
pBuf += possibleNameLength;
}
diff --git a/src/mgr/encfiltmgr.cpp b/src/mgr/encfiltmgr.cpp
index cb6dab4..24938bc 100644
--- a/src/mgr/encfiltmgr.cpp
+++ b/src/mgr/encfiltmgr.cpp
@@ -1,9 +1,12 @@
/******************************************************************************
- * swencodingmgr.cpp - implementaion of class EncodingFilterMgr, subclass of
- * used to transcode all module text to a requested
- * encoding.
*
- * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
+ * encfiltmgr.cpp - implementaion of class EncodingFilterMgr, subclass of
+ * SWFilterMgr, used to transcode all module text to a
+ * requested encoding
+ *
+ * $Id: encfiltmgr.cpp 2980 2013-09-14 21:51:47Z scribe $
+ *
+ * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -22,6 +25,7 @@
#include <encfiltmgr.h>
#include <utilstr.h>
+#include <scsuutf8.h>
#include <latin1utf8.h>
#include <unicodertf.h>
@@ -32,65 +36,65 @@
#include <swmgr.h>
+
SWORD_NAMESPACE_START
+
/******************************************************************************
* EncodingFilterMgr Constructor - initializes instance of EncodingFilterMgr
*
* ENT:
* enc - Encoding format to emit
*/
+EncodingFilterMgr::EncodingFilterMgr(char enc)
+ : SWFilterMgr() {
-EncodingFilterMgr::EncodingFilterMgr (char enc)
- : SWFilterMgr() {
-
- latin1utf8 = new Latin1UTF8();
-
- encoding = enc;
-
- switch (encoding) {
- case ENC_LATIN1:
- targetenc = new UTF8Latin1();
- break;
- case ENC_UTF16:
- targetenc = new UTF8UTF16();
- break;
- case ENC_RTF:
- targetenc = new UnicodeRTF();
- break;
- case ENC_HTML:
- targetenc = new UTF8HTML();
- break;
- default: // i.e. case ENC_UTF8
- targetenc = NULL;
- }
+ scsuutf8 = new SCSUUTF8();
+ latin1utf8 = new Latin1UTF8();
+
+ encoding = enc;
+
+ switch (encoding) {
+ case ENC_LATIN1: targetenc = new UTF8Latin1(); break;
+ case ENC_UTF16: targetenc = new UTF8UTF16(); break;
+ case ENC_RTF: targetenc = new UnicodeRTF(); break;
+ case ENC_HTML: targetenc = new UTF8HTML(); break;
+ default: // i.e. case ENC_UTF8
+ targetenc = NULL;
+ }
}
+
/******************************************************************************
* EncodingFilterMgr Destructor - Cleans up instance of EncodingFilterMgr
*/
EncodingFilterMgr::~EncodingFilterMgr() {
- if (latin1utf8)
- delete latin1utf8;
- if (targetenc)
- delete targetenc;
+ delete scsuutf8;
+ delete latin1utf8;
+ delete targetenc;
}
+
void EncodingFilterMgr::AddRawFilters(SWModule *module, ConfigEntMap &section) {
ConfigEntMap::iterator entry;
SWBuf encoding = ((entry = section.find("Encoding")) != section.end()) ? (*entry).second : (SWBuf)"";
if (!encoding.length() || !stricmp(encoding.c_str(), "Latin-1")) {
- module->AddRawFilter(latin1utf8);
+ module->addRawFilter(latin1utf8);
+ }
+ else if (!stricmp(encoding.c_str(), "SCSU")) {
+ module->addRawFilter(scsuutf8);
}
}
+
void EncodingFilterMgr::AddEncodingFilters(SWModule *module, ConfigEntMap &section) {
- if (targetenc)
- module->AddEncodingFilter(targetenc);
+ if (targetenc)
+ module->addEncodingFilter(targetenc);
}
+
/******************************************************************************
* EncodingFilterMgr::Encoding - sets/gets encoding
*
@@ -99,49 +103,41 @@ void EncodingFilterMgr::AddEncodingFilters(SWModule *module, ConfigEntMap &secti
* RET: encoding
*/
char EncodingFilterMgr::Encoding(char enc) {
- if (enc && enc != encoding) {
- encoding = enc;
- SWFilter * oldfilter = targetenc;
-
- switch (encoding) {
- case ENC_LATIN1:
- targetenc = new UTF8Latin1();
- break;
- case ENC_UTF16:
- targetenc = new UTF8UTF16();
- break;
- case ENC_RTF:
- targetenc = new UnicodeRTF();
- break;
- case ENC_HTML:
- targetenc = new UTF8HTML();
- break;
- default: // i.e. case ENC_UTF8
- targetenc = NULL;
- }
-
- ModMap::const_iterator module;
-
- if (oldfilter != targetenc) {
- if (oldfilter) {
- if (!targetenc) {
- for (module = getParentMgr()->Modules.begin(); module != getParentMgr()->Modules.end(); module++)
- module->second->RemoveRenderFilter(oldfilter);
- }
- else {
- for (module = getParentMgr()->Modules.begin(); module != getParentMgr()->Modules.end(); module++)
- module->second->ReplaceRenderFilter(oldfilter, targetenc);
- }
- delete oldfilter;
- }
- else if (targetenc) {
- for (module = getParentMgr()->Modules.begin(); module != getParentMgr()->Modules.end(); module++)
- module->second->AddRenderFilter(targetenc);
- }
- }
-
- }
- return encoding;
+ if (enc && enc != encoding) {
+ encoding = enc;
+ SWFilter *oldfilter = targetenc;
+
+ switch (encoding) {
+ case ENC_LATIN1: targetenc = new UTF8Latin1(); break;
+ case ENC_UTF16: targetenc = new UTF8UTF16(); break;
+ case ENC_RTF: targetenc = new UnicodeRTF(); break;
+ case ENC_HTML: targetenc = new UTF8HTML(); break;
+ default: // i.e. case ENC_UTF8
+ targetenc = NULL;
+ }
+
+ ModMap::const_iterator module;
+
+ if (oldfilter != targetenc) {
+ if (oldfilter) {
+ if (!targetenc) {
+ for (module = getParentMgr()->Modules.begin(); module != getParentMgr()->Modules.end(); module++)
+ module->second->removeRenderFilter(oldfilter);
+ }
+ else {
+ for (module = getParentMgr()->Modules.begin(); module != getParentMgr()->Modules.end(); module++)
+ module->second->replaceRenderFilter(oldfilter, targetenc);
+ }
+ delete oldfilter;
+ }
+ else if (targetenc) {
+ for (module = getParentMgr()->Modules.begin(); module != getParentMgr()->Modules.end(); module++)
+ module->second->addRenderFilter(targetenc);
+ }
+ }
+ }
+ return encoding;
}
+
SWORD_NAMESPACE_END
diff --git a/src/mgr/filemgr.cpp b/src/mgr/filemgr.cpp
index 820440b..d801aaa 100644
--- a/src/mgr/filemgr.cpp
+++ b/src/mgr/filemgr.cpp
@@ -1,10 +1,11 @@
/******************************************************************************
- * filemgr.cpp - implementation of class FileMgr used for pooling file
- * handles
*
- * $Id: filemgr.cpp 2495 2009-12-24 22:22:16Z scribe $
+ * filemgr.cpp - implementation of class FileMgr used for pooling file
+ * handles
*
- * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
+ * $Id: filemgr.cpp 2833 2013-06-29 06:40:28Z chrislit $
+ *
+ * Copyright 1998-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -540,12 +541,18 @@ int FileMgr::removeDir(const char *targetDir) {
FileMgr::removeFile(targetPath.c_str());
}
else {
- removeDir(targetPath.c_str());
+ FileMgr::removeDir(targetPath.c_str());
}
}
}
closedir(dir);
- removeFile(targetDir);
+ FileMgr::removeFile(targetDir);
+/*
+ int status = FileMgr::removeFile(targetDir);
+ int stuff = errno;
+ char *err = strerror(errno);
+ int x = stuff;
+*/
}
return 0;
}
diff --git a/src/mgr/ftplibftpt.cpp b/src/mgr/ftplibftpt.cpp
index fe23048..f1d1655 100644
--- a/src/mgr/ftplibftpt.cpp
+++ b/src/mgr/ftplibftpt.cpp
@@ -1,9 +1,10 @@
- /*****************************************************************************
- * FTPLibFTPTransport functions
+/*****************************************************************************
*
+ * ftplibftpt.cpp - FTPLibFTPTransport
*
+ * $Id: ftplibftpt.cpp 2983 2013-09-15 16:22:32Z scribe $
*
- * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
+ * Copyright 2004-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -18,7 +19,6 @@
* General Public License for more details.
*
*/
-
#include <stdio.h>
#include <fcntl.h>
@@ -34,41 +34,58 @@ SWORD_NAMESPACE_START
namespace {
-struct MyProgressData {
- StatusReporter *sr;
- long totalSize;
- bool *term;
-};
-
-int my_fprogress(netbuf *nControl, int xfered, void *arg) {
- if (arg) {
- MyProgressData *pd = (MyProgressData *)arg;
-SWLog::getSystemLog()->logDebug("FTPLibFTPTransport report progress: totalSize: %ld; xfered: %d\n", pd->totalSize, xfered);
- if (pd->sr) {
- pd->sr->statusUpdate(pd->totalSize, xfered);
- }
- if (*(pd->term)) return 0;
+ struct MyProgressData {
+ StatusReporter *sr;
+ long totalSize;
+ bool *term;
+ };
+
+ static int my_swbufwriter(netbuf *nControl, void *buffer, size_t size, void *swbuf) {
+ SWBuf &output = *(SWBuf *)swbuf;
+ int s = output.size();
+ output.size(s+size);
+ memcpy(output.getRawData()+s, buffer, size);
+ return size;
}
- return 1;
-}
-}
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+ static int my_fprogress(netbuf *nControl, int xfered, void *arg) {
+ if (arg) {
+ MyProgressData *pd = (MyProgressData *)arg;
+ SWLog::getSystemLog()->logDebug("FTPLibFTPTransport report progress: totalSize: %ld; xfered: %d\n", pd->totalSize, xfered);
+ if (pd->sr) {
+ pd->sr->statusUpdate(pd->totalSize, xfered);
+ }
+ if (*(pd->term)) return 0;
+ }
+ return 1;
+ }
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
-static FTPLibFTPTransport_init _FTPLibFTPTransport_init;
+ // initialize/cleanup SYSTEMWIDE library with life of this static.
+ static class FTPLibFTPTransport_init {
+ public:
+ FTPLibFTPTransport_init() {
+ FtpInit();
+ }
+ ~FTPLibFTPTransport_init() {
+ }
-FTPLibFTPTransport_init::FTPLibFTPTransport_init() {
- FtpInit();
-}
+ } _ftpLibFTPTransport_init;
-FTPLibFTPTransport_init::~FTPLibFTPTransport_init() {
}
-FTPLibFTPTransport::FTPLibFTPTransport(const char *host, StatusReporter *sr) : FTPTransport(host, sr) {
+FTPLibFTPTransport::FTPLibFTPTransport(const char *host, StatusReporter *sr) : RemoteTransport(host, sr) {
ftpConnection = 0;
}
@@ -85,6 +102,8 @@ char FTPLibFTPTransport::assureLoggedIn() {
if (ftpConnection == 0) {
SWLog::getSystemLog()->logDebug("connecting to host: %s...\n", host.c_str());
if (FtpConnect(host, &ftpConnection)) {
+ FtpOptions(FTPLIB_CONNMODE, (passive) ? FTPLIB_PASSIVE : FTPLIB_PORT, ftpConnection);
+
SWLog::getSystemLog()->logDebug("connected. logging in...\n");
if (FtpLogin(u.c_str(), p.c_str(), ftpConnection)) {
SWLog::getSystemLog()->logDebug("logged in.\n");
@@ -103,14 +122,6 @@ char FTPLibFTPTransport::assureLoggedIn() {
return retVal;
}
-// yeah yeah, I know I know. Compile with curl support if you don't like it
-#pragma GCC diagnostic ignored "-Wall"
-void my_tmpnam(char *tmpName) {
- tmpName = tmpnam(tmpName);
-}
-#pragma GCC diagnostic warning "-Wall"
-
-
char FTPLibFTPTransport::getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf) {
@@ -128,29 +139,22 @@ char FTPLibFTPTransport::getURL(const char *destPath, const char *sourceURL, SWB
if (!destBuf) {
outFile = destPath;
}
- else {
-#ifdef ANDROID
- outFile = "/sdcard/sword/InstallMgr/swtmpbuf.out";
-#else
- char tmpName[128];
- my_tmpnam(tmpName);
- outFile = tmpName;
-#endif
- }
sourcePath << (6 + host.length()); // shift << "ftp://hostname";
- SWLog::getSystemLog()->logDebug("getting file %s to %s\n", sourcePath.c_str(), outFile.c_str());
- if (passive)
- FtpOptions(FTPLIB_CONNMODE, FTPLIB_PASSIVE, ftpConnection);
- else
- FtpOptions(FTPLIB_CONNMODE, FTPLIB_PORT, ftpConnection);
-
+ SWLog::getSystemLog()->logDebug("getting file %s to %s\n", sourcePath.c_str(), destBuf ? "*internal buffer*" : outFile.c_str());
struct MyProgressData pd;
pd.sr = statusReporter;
pd.term = &term;
pd.totalSize = 0;
- // !!!WDG also want to set callback options
+ if (destBuf) {
+ FtpOptions(FTPLIB_CALLBACK_WRITER, (long)&my_swbufwriter, ftpConnection);
+ FtpOptions(FTPLIB_CALLBACK_WRITERARG, (long)destBuf, ftpConnection);
+ }
+ else {
+ FtpOptions(FTPLIB_CALLBACK_WRITER, 0L, ftpConnection);
+ }
+
FtpOptions(FTPLIB_CALLBACK, (long)&my_fprogress, ftpConnection);
FtpOptions(FTPLIB_CALLBACKARG, (long)&pd, ftpConnection);
FtpOptions(FTPLIB_CALLBACKBYTES, (long)2048, ftpConnection);
@@ -159,29 +163,15 @@ char FTPLibFTPTransport::getURL(const char *destPath, const char *sourceURL, SWB
// SWLog::getSystemLog()->logDebug("getting test directory %s\n", sourcePath.c_str());
// FtpDir(NULL, sourcePath, ftpConnection);
SWLog::getSystemLog()->logDebug("getting real directory %s\n", sourcePath.c_str());
- retVal = FtpDir(outFile.c_str(), sourcePath, ftpConnection) - 1;
- SWLog::getSystemLog()->logDebug("got real directory %s to %s\n", sourcePath.c_str(), outFile.c_str());
+ retVal = FtpDir(destBuf ? 0 : outFile.c_str(), sourcePath, ftpConnection) - 1;
+ SWLog::getSystemLog()->logDebug("got real directory %s to %s\n", sourcePath.c_str(), destBuf ? "*internal buffer*" : outFile.c_str());
}
else {
SWLog::getSystemLog()->logDebug("getting file %s\n", sourcePath.c_str());
int size;
FtpSize(sourcePath, &size, FTPLIB_IMAGE, ftpConnection);
pd.totalSize = size;
- retVal = FtpGet(outFile.c_str(), sourcePath, FTPLIB_IMAGE, ftpConnection) - 1;
- }
-
- // Is there a way to FTPGet directly to a buffer?
- // If not, we probably want to add x-platform way to open a tmp file with FileMgr
- // Currently outFile is set to tmpFile above sortof unsafe
- if (destBuf) {
- SWLog::getSystemLog()->logDebug("filling destBuf\n");
- FileDesc *fd = FileMgr::getSystemFileMgr()->open(outFile.c_str(), FileMgr::RDONLY);
- long size = fd->seek(0, SEEK_END);
- fd->seek(0, SEEK_SET);
- destBuf->size(size);
- fd->read(destBuf->getRawData(), size);
- FileMgr::getSystemFileMgr()->close(fd);
- FileMgr::removeFile(outFile.c_str());
+ retVal = FtpGet(destBuf ? 0 : outFile.c_str(), sourcePath, FTPLIB_IMAGE, ftpConnection) - 1;
}
SWLog::getSystemLog()->logDebug("FTPLibFTPTransport - returning: %d\n", retVal);
diff --git a/src/mgr/installmgr.cpp b/src/mgr/installmgr.cpp
index b75df6f..1e83db5 100644
--- a/src/mgr/installmgr.cpp
+++ b/src/mgr/installmgr.cpp
@@ -1,10 +1,10 @@
- /*****************************************************************************
- * InstallMgr functions to be made into something usefully exposed by
- * master Glassey
+/*****************************************************************************
*
+ * installmgr.cpp - InstallMgr functions
*
+ * $Id: installmgr.cpp 2980 2013-09-14 21:51:47Z scribe $
*
- * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
+ * Copyright 2002-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -20,8 +20,6 @@
*
*/
-
-
#ifndef EXCLUDEZLIB
extern "C" {
#include <untgz.h>
@@ -51,23 +49,26 @@ extern "C" {
#endif
#include <iostream>
+
+
+using std::map;
+
+
SWORD_NAMESPACE_START
namespace {
-void removeTrailingSlash(SWBuf &buf) {
- int len = buf.size();
- if ((buf[len-1] == '/')
- || (buf[len-1] == '\\'))
- buf.size(len-1);
-}
-
-const char *masterRepoList = "masterRepoList.conf";
+ static void removeTrailingSlash(SWBuf &buf) {
+ int len = buf.size();
+ if ((buf[len-1] == '/')
+ || (buf[len-1] == '\\'))
+ buf.size(len-1);
+ }
-};
+ static const char *masterRepoList = "masterRepoList.conf";
+}
-using std::map;
const int InstallMgr::MODSTAT_OLDER = 0x001;
const int InstallMgr::MODSTAT_SAMEVERSION = 0x002;
@@ -76,10 +77,11 @@ const int InstallMgr::MODSTAT_NEW = 0x008;
const int InstallMgr::MODSTAT_CIPHERED = 0x010;
const int InstallMgr::MODSTAT_CIPHERKEYPRESENT = 0x020;
-// override this method and provide your own custom FTPTransport subclass
+
+// override this method and provide your own custom RemoteTransport subclass
// here we try a couple defaults if sword was compiled with support for them.
// see these classes for examples of how to make your own
-FTPTransport *InstallMgr::createFTPTransport(const char *host, StatusReporter *statusReporter) {
+RemoteTransport *InstallMgr::createFTPTransport(const char *host, StatusReporter *statusReporter) {
#ifdef CURLAVAILABLE
return new CURLFTPTransport(host, statusReporter);
#else
@@ -87,7 +89,8 @@ FTPTransport *InstallMgr::createFTPTransport(const char *host, StatusReporter *s
#endif
}
-FTPTransport *InstallMgr::createHTTPTransport(const char *host, StatusReporter *statusReporter) {
+
+RemoteTransport *InstallMgr::createHTTPTransport(const char *host, StatusReporter *statusReporter) {
#ifdef CURLAVAILABLE
return new CURLHTTPTransport(host, statusReporter);
#else
@@ -96,7 +99,6 @@ FTPTransport *InstallMgr::createHTTPTransport(const char *host, StatusReporter *
}
-
InstallMgr::InstallMgr(const char *privatePath, StatusReporter *sr, SWBuf u, SWBuf p) {
userDisclaimerConfirmed = false;
statusReporter = sr;
@@ -125,6 +127,7 @@ InstallMgr::~InstallMgr() {
clearSources();
}
+
void InstallMgr::clearSources() {
for (InstallSourceMap::iterator it = sources.begin(); it != sources.end(); ++it) {
delete it->second;
@@ -132,6 +135,7 @@ void InstallMgr::clearSources() {
sources.clear();
}
+
void InstallMgr::readInstallConf() {
if (installConf) delete installConf;
@@ -147,6 +151,7 @@ void InstallMgr::readInstallConf() {
ConfigEntMap::iterator sourceEnd;
if (confSection != installConf->Sections.end()) {
+
sourceBegin = confSection->second.lower_bound("FTPSource");
sourceEnd = confSection->second.upper_bound("FTPSource");
@@ -158,6 +163,21 @@ void InstallMgr::readInstallConf() {
is->localShadow = (SWBuf)privatePath + "/" + is->uid;
sourceBegin++;
}
+
+#ifdef CURLSFTPAVAILABLE
+ sourceBegin = confSection->second.lower_bound("SFTPSource");
+ sourceEnd = confSection->second.upper_bound("SFTPSource");
+
+ while (sourceBegin != sourceEnd) {
+ InstallSource *is = new InstallSource("SFTP", 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++;
+ }
+#endif // CURLSFTPAVAILABLE
+
sourceBegin = confSection->second.lower_bound("HTTPSource");
sourceEnd = confSection->second.upper_bound("HTTPSource");
@@ -169,6 +189,18 @@ void InstallMgr::readInstallConf() {
is->localShadow = (SWBuf)privatePath + "/" + is->uid;
sourceBegin++;
}
+
+ sourceBegin = confSection->second.lower_bound("HTTPSSource");
+ sourceEnd = confSection->second.upper_bound("HTTPSSource");
+
+ while (sourceBegin != sourceEnd) {
+ InstallSource *is = new InstallSource("HTTPS", 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();
@@ -270,19 +302,24 @@ int InstallMgr::removeModule(SWMgr *manager, const char *moduleName) {
// TODO: rename to netCopy
-int InstallMgr::ftpCopy(InstallSource *is, const char *src, const char *dest, bool dirTransfer, const char *suffix) {
-SWLog::getSystemLog()->logDebug("netCopy: %s, %s, %s, %c, %s", (is?is->source.c_str():"null"), src, (dest?dest:"null"), (dirTransfer?'t':'f'), (suffix?suffix:"null"));
+int InstallMgr::remoteCopy(InstallSource *is, const char *src, const char *dest, bool dirTransfer, const char *suffix) {
+SWLog::getSystemLog()->logDebug("remoteCopy: %s, %s, %s, %c, %s", (is?is->source.c_str():"null"), src, (dest?dest:"null"), (dirTransfer?'t':'f'), (suffix?suffix:"null"));
// assert user disclaimer has been confirmed
if (!isUserDisclaimerConfirmed()) return -1;
int retVal = 0;
- FTPTransport *trans = 0;
- if (is->type == "FTP") {
+ RemoteTransport *trans = 0;
+ if (is->type == "FTP"
+#ifdef CURLSFTPAVAILABLE
+ || is->type == "SFTP"
+#endif
+ ) {
+
trans = createFTPTransport(is->source, statusReporter);
trans->setPassive(passive);
}
- else if (is->type == "HTTP") {
+ else if (is->type == "HTTP" || is->type == "HTTPS") {
trans = createHTTPTransport(is->source, statusReporter);
}
transport = trans; // set classwide current transport for other thread terminate() call
@@ -295,7 +332,22 @@ SWLog::getSystemLog()->logDebug("netCopy: %s, %s, %s, %c, %s", (is?is->source.c_
trans->setPasswd(p);
}
- SWBuf urlPrefix = (SWBuf)((is->type == "HTTP") ? "http://" : "ftp://") + is->source;
+ SWBuf urlPrefix;
+ if (is->type == "HTTP") {
+ urlPrefix = (SWBuf) "http://";
+ }
+ else if (is->type == "HTTPS") {
+ urlPrefix = (SWBuf) "https://";
+ }
+#ifdef CURLSFTPAVAILABLE
+ else if (is->type == "SFTP") {
+ urlPrefix = (SWBuf) "sftp://";
+ }
+#endif
+ else {
+ urlPrefix = (SWBuf) "ftp://";
+ }
+ urlPrefix.append(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
@@ -329,7 +381,7 @@ SWLog::getSystemLog()->logDebug("netCopy: %s, %s, %s, %c, %s", (is?is->source.c_
}
}
SWTRY {
- FTPTransport *deleteMe = trans;
+ RemoteTransport *deleteMe = trans;
// do this order for threadsafeness
// (see terminate())
trans = transport = 0;
@@ -386,7 +438,7 @@ int InstallMgr::installModule(SWMgr *destMgr, const char *fromLocation, const ch
if (is) {
while (fileBegin != fileEnd) { // netCopy each file first
buffer = sourceDir + fileBegin->second.c_str();
- if (ftpCopy(is, fileBegin->second.c_str(), buffer.c_str())) {
+ if (remoteCopy(is, fileBegin->second.c_str(), buffer.c_str())) {
aborted = true;
break; // user aborted
}
@@ -446,7 +498,7 @@ int InstallMgr::installModule(SWMgr *destMgr, const char *fromLocation, const ch
SWLog::getSystemLog()->logDebug("***** relativePath: %s \n", relativePath.c_str());
if (is) {
- if (ftpCopy(is, relativePath.c_str(), absolutePath.c_str(), true)) {
+ if (remoteCopy(is, relativePath.c_str(), absolutePath.c_str(), true)) {
aborted = true; // user aborted
}
}
@@ -498,6 +550,7 @@ int InstallMgr::installModule(SWMgr *destMgr, const char *fromLocation, const ch
return 1;
}
+
int InstallMgr::refreshRemoteSource(InstallSource *is) {
// assert user disclaimer has been confirmed
@@ -516,7 +569,7 @@ int InstallMgr::refreshRemoteSource(InstallSource *is) {
#ifndef EXCLUDEZLIB
SWBuf archive = root + "/mods.d.tar.gz";
- errorCode = ftpCopy(is, "mods.d.tar.gz", archive.c_str(), false);
+ errorCode = remoteCopy(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());
@@ -524,7 +577,7 @@ int InstallMgr::refreshRemoteSource(InstallSource *is) {
}
else
#endif
- errorCode = ftpCopy(is, "mods.d", target.c_str(), true, ".conf"); //copy the whole directory
+ errorCode = remoteCopy(is, "mods.d", target.c_str(), true, ".conf"); //copy the whole directory
is->flush();
return errorCode;
@@ -535,6 +588,7 @@ bool InstallMgr::isDefaultModule(const char *modName) {
return defaultMods.count(modName);
}
+
/************************************************************************
* getModuleStatus - compare the modules of two SWMgrs and return a
* vector describing the status of each. See MODSTAT_*
@@ -603,7 +657,7 @@ int InstallMgr::refreshRemoteSourceConfiguration() {
InstallSource is("FTP");
is.source = "ftp.crosswire.org";
is.directory = "/pub/sword";
- int errorCode = ftpCopy(&is, masterRepoList, masterRepoListPath.c_str(), false);
+ int errorCode = remoteCopy(&is, masterRepoList, masterRepoListPath.c_str(), false);
if (!errorCode) { //sucessfully downloaded the repo list
SWConfig masterList(masterRepoListPath);
SectionMap::iterator sections = masterList.Sections.find("Repos");
diff --git a/src/mgr/localemgr.cpp b/src/mgr/localemgr.cpp
index 628d271..90d4716 100644
--- a/src/mgr/localemgr.cpp
+++ b/src/mgr/localemgr.cpp
@@ -1,10 +1,11 @@
/******************************************************************************
- * localemgr.cpp - implementation of class LocaleMgr used to interact with
- * registered locales for a sword installation
*
- * $Id: localemgr.cpp 2499 2010-01-02 04:51:05Z scribe $
+ * localemgr.cpp - implementation of class LocaleMgr used to interact with
+ * registered locales for a SWORD installation
*
- * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
+ * $Id: localemgr.cpp 3005 2014-01-09 04:06:11Z greg.hellings $
+ *
+ * Copyright 2000-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -39,8 +40,10 @@
SWORD_NAMESPACE_START
+
LocaleMgr *LocaleMgr::systemLocaleMgr = 0;
+
class __staticsystemLocaleMgr {
public:
__staticsystemLocaleMgr() { }
@@ -261,12 +264,12 @@ void LocaleMgr::setDefaultLocaleName(const char *name) {
stdstr(&defaultLocaleName, tmplang);
// First check for what we ask for
- if (!getLocale(tmplang)) {
+ if (locales->find(tmplang) == locales->end()) {
// check for locale without country
char *nocntry=0;
stdstr(&nocntry, tmplang);
strtok(nocntry, "_");
- if (getLocale(nocntry)) {
+ if (locales->find(nocntry) != locales->end()) {
stdstr(&defaultLocaleName, nocntry);
}
delete [] nocntry;
@@ -274,4 +277,6 @@ void LocaleMgr::setDefaultLocaleName(const char *name) {
delete [] tmplang;
}
+
SWORD_NAMESPACE_END
+
diff --git a/src/mgr/markupfiltmgr.cpp b/src/mgr/markupfiltmgr.cpp
index 5dca845..fb12583 100644
--- a/src/mgr/markupfiltmgr.cpp
+++ b/src/mgr/markupfiltmgr.cpp
@@ -1,9 +1,12 @@
/******************************************************************************
- * swmarkupmgr.cpp - implementaion of class MarkupFilterMgr, subclass of
- * used to transcode all module text to a requested
- * markup.
*
- * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
+ * markupfiltmgr.cpp - implementaion of class MarkupFilterMgr, subclass of
+ * used to transcode all module text to a requested
+ * markup
+ *
+ * $Id: markupfiltmgr.cpp 2980 2013-09-14 21:51:47Z scribe $
+ *
+ * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -27,7 +30,6 @@
#include <gbfthml.h>
#include <thmlhtml.h>
#include <gbfhtml.h>
-#include <plainhtml.h>
#include <thmlhtmlhref.h>
#include <gbfhtmlhref.h>
#include <teihtmlhref.h>
@@ -43,13 +45,19 @@
#include <thmlwebif.h>
#include <osiswebif.h>
#include <swmodule.h>
+#include <thmlxhtml.h>
+#include <gbfxhtml.h>
+#include <osisxhtml.h>
+#include <teixhtml.h>
#include <markupfiltmgr.h>
#include <swmgr.h>
+
SWORD_NAMESPACE_START
+
/******************************************************************************
* MarkupFilterMgr Constructor - initializes instance of MarkupFilterMgr
*
@@ -58,12 +66,12 @@ SWORD_NAMESPACE_START
* mark - Markup format to emit
*/
-MarkupFilterMgr::MarkupFilterMgr (char mark, char enc)
- : EncodingFilterMgr(enc) {
+MarkupFilterMgr::MarkupFilterMgr(char mark, char enc)
+ : EncodingFilterMgr(enc) {
- markup = mark;
+ markup = mark;
- CreateFilters(markup);
+ CreateFilters(markup);
}
@@ -72,18 +80,14 @@ MarkupFilterMgr::MarkupFilterMgr (char mark, char enc)
*/
MarkupFilterMgr::~MarkupFilterMgr() {
- if (fromthml)
- delete (fromthml);
- if (fromgbf)
- delete (fromgbf);
- if (fromplain)
- delete (fromplain);
- if (fromosis)
- delete (fromosis);
- if (fromtei)
- delete (fromtei);
+ delete fromthml;
+ delete fromgbf;
+ delete fromplain;
+ delete fromosis;
+ delete fromtei;
}
+
/******************************************************************************
* MarkupFilterMgr::Markup - sets/gets markup
*
@@ -92,204 +96,224 @@ MarkupFilterMgr::~MarkupFilterMgr() {
* RET: markup
*/
char MarkupFilterMgr::Markup(char mark) {
- if (mark && mark != markup) {
- markup = mark;
- ModMap::const_iterator module;
-
- SWFilter * oldplain = fromplain;
- SWFilter * oldthml = fromthml;
- SWFilter * oldgbf = fromgbf;
- SWFilter * oldosis = fromosis;
- SWFilter * oldtei = fromtei;
-
- CreateFilters(markup);
-
- for (module = getParentMgr()->Modules.begin(); module != getParentMgr()->Modules.end(); module++)
- switch (module->second->Markup()) {
- case FMT_THML:
- if (oldthml != fromthml) {
- if (oldthml) {
- if (!fromthml) {
- module->second->RemoveRenderFilter(oldthml);
- }
- else {
- module->second->ReplaceRenderFilter(oldthml, fromthml);
- }
- }
- else if (fromthml) {
- module->second->AddRenderFilter(fromthml);
- }
- }
- break;
- case FMT_GBF:
- if (oldgbf != fromgbf) {
- if (oldgbf) {
- if (!fromgbf) {
- module->second->RemoveRenderFilter(oldgbf);
- }
- else {
- module->second->ReplaceRenderFilter(oldgbf, fromgbf);
- }
- }
- else if (fromgbf) {
- module->second->AddRenderFilter(fromgbf);
- }
- break;
- }
- case FMT_PLAIN:
- if (oldplain != fromplain) {
- if (oldplain) {
- if (!fromplain) {
- module->second->RemoveRenderFilter(oldplain);
- }
- else {
- module->second->ReplaceRenderFilter(oldplain, fromplain);
- }
- }
- else if (fromplain) {
- module->second->AddRenderFilter(fromplain);
- }
- break;
- }
- case FMT_OSIS:
- if (oldosis != fromosis) {
- if (oldosis) {
- if (!fromosis) {
- module->second->RemoveRenderFilter(oldosis);
- }
- else {
- module->second->ReplaceRenderFilter(oldosis, fromosis);
- }
- }
- else if (fromosis) {
- module->second->AddRenderFilter(fromosis);
- }
- break;
- }
- case FMT_TEI:
- if (oldtei != fromtei) {
- if (oldtei) {
- if (!fromtei) {
- module->second->RemoveRenderFilter(oldtei);
- }
- else {
- module->second->ReplaceRenderFilter(oldtei, fromtei);
- }
- }
- else if (fromtei) {
- module->second->AddRenderFilter(fromtei);
- }
- break;
- }
- }
-
- if (oldthml)
- delete oldthml;
- if (oldgbf)
- delete oldgbf;
- if (oldplain)
- delete oldplain;
- if (oldosis)
- delete oldosis;
- if (oldtei)
- delete oldtei;
- }
- return markup;
+ if (mark && mark != markup) {
+ markup = mark;
+ ModMap::const_iterator module;
+
+ SWFilter *oldplain = fromplain;
+ SWFilter *oldthml = fromthml;
+ SWFilter *oldgbf = fromgbf;
+ SWFilter *oldosis = fromosis;
+ SWFilter *oldtei = fromtei;
+
+ CreateFilters(markup);
+
+ for (module = getParentMgr()->Modules.begin(); module != getParentMgr()->Modules.end(); ++module) {
+ switch (module->second->getMarkup()) {
+ case FMT_THML:
+ if (oldthml != fromthml) {
+ if (oldthml) {
+ if (!fromthml) {
+ module->second->removeRenderFilter(oldthml);
+ }
+ else {
+ module->second->replaceRenderFilter(oldthml, fromthml);
+ }
+ }
+ else if (fromthml) {
+ module->second->addRenderFilter(fromthml);
+ }
+ }
+ break;
+
+ case FMT_GBF:
+ if (oldgbf != fromgbf) {
+ if (oldgbf) {
+ if (!fromgbf) {
+ module->second->removeRenderFilter(oldgbf);
+ }
+ else {
+ module->second->replaceRenderFilter(oldgbf, fromgbf);
+ }
+ }
+ else if (fromgbf) {
+ module->second->addRenderFilter(fromgbf);
+ }
+ }
+ break;
+
+ case FMT_PLAIN:
+ if (oldplain != fromplain) {
+ if (oldplain) {
+ if (!fromplain) {
+ module->second->removeRenderFilter(oldplain);
+ }
+ else {
+ module->second->replaceRenderFilter(oldplain, fromplain);
+ }
+ }
+ else if (fromplain) {
+ module->second->addRenderFilter(fromplain);
+ }
+ }
+ break;
+
+ case FMT_OSIS:
+ if (oldosis != fromosis) {
+ if (oldosis) {
+ if (!fromosis) {
+ module->second->removeRenderFilter(oldosis);
+ }
+ else {
+ module->second->replaceRenderFilter(oldosis, fromosis);
+ }
+ }
+ else if (fromosis) {
+ module->second->addRenderFilter(fromosis);
+ }
+ }
+ break;
+
+ case FMT_TEI:
+ if (oldtei != fromtei) {
+ if (oldtei) {
+ if (!fromtei) {
+ module->second->removeRenderFilter(oldtei);
+ }
+ else {
+ module->second->replaceRenderFilter(oldtei, fromtei);
+ }
+ }
+ else if (fromtei) {
+ module->second->addRenderFilter(fromtei);
+ }
+ }
+ break;
+ }
+ }
+
+ delete oldthml;
+ delete oldgbf;
+ delete oldplain;
+ delete oldosis;
+ delete oldtei;
+ }
+ return markup;
}
+
void MarkupFilterMgr::AddRenderFilters(SWModule *module, ConfigEntMap &section) {
- switch (module->Markup()) {
- case FMT_THML:
- if (fromthml)
- module->AddRenderFilter(fromthml);
- break;
- case FMT_GBF:
- if (fromgbf)
- module->AddRenderFilter(fromgbf);
- break;
- case FMT_PLAIN:
- if (fromplain)
- module->AddRenderFilter(fromplain);
- break;
- case FMT_OSIS:
- if (fromosis)
- module->AddRenderFilter(fromosis);
- break;
- case FMT_TEI:
- if (fromtei)
- module->AddRenderFilter(fromtei);
- break;
- }
+ switch (module->getMarkup()) {
+ case FMT_THML:
+ if (fromthml)
+ module->addRenderFilter(fromthml);
+ break;
+ case FMT_GBF:
+ if (fromgbf)
+ module->addRenderFilter(fromgbf);
+ break;
+ case FMT_PLAIN:
+ if (fromplain)
+ module->addRenderFilter(fromplain);
+ break;
+ case FMT_OSIS:
+ if (fromosis)
+ module->addRenderFilter(fromosis);
+ break;
+ case FMT_TEI:
+ if (fromtei)
+ module->addRenderFilter(fromtei);
+ break;
+ }
}
+
void MarkupFilterMgr::CreateFilters(char markup) {
- switch (markup) {
- case FMT_PLAIN:
- fromplain = NULL;
- fromthml = new ThMLPlain();
- fromgbf = new GBFPlain();
- fromosis = new OSISPlain();
- fromtei = new TEIPlain();
- break;
- case FMT_THML:
- fromplain = NULL;
- fromthml = NULL;
- fromgbf = new GBFThML();
- fromosis = NULL;
- fromtei = NULL;
- break;
- case FMT_GBF:
- fromplain = NULL;
- fromthml = new ThMLGBF();
- fromgbf = NULL;
- fromosis = NULL;
- fromtei = NULL;
- break;
- case FMT_HTML:
- fromplain = new PLAINHTML();
- fromthml = new ThMLHTML();
- fromgbf = new GBFHTML();
- fromosis = NULL;
- fromtei = NULL;
- break;
- case FMT_HTMLHREF:
- fromplain = new PLAINHTML();
- fromthml = new ThMLHTMLHREF();
- fromgbf = new GBFHTMLHREF();
- fromosis = new OSISHTMLHREF();
- fromtei = new TEIHTMLHREF();
- break;
- case FMT_RTF:
- fromplain = NULL;
- fromthml = new ThMLRTF();
- fromgbf = new GBFRTF();
- fromosis = new OSISRTF();
- fromtei = new TEIRTF();
- break;
- case FMT_OSIS:
- fromplain = NULL;
- fromthml = new ThMLOSIS();
- fromgbf = new GBFOSIS();
- fromosis = new OSISOSIS();
- fromtei = NULL;
- break;
- case FMT_WEBIF:
- fromplain = NULL;
- fromthml = new ThMLWEBIF();
- fromgbf = new GBFWEBIF();
- fromosis = new OSISWEBIF();
- fromtei = NULL;
- break;
- case FMT_TEI:
- fromplain = NULL;
- fromthml = NULL;
- fromgbf = NULL;
- fromosis = NULL;
- fromtei = NULL;
- break;
- }
+ switch (markup) {
+ case FMT_PLAIN:
+ fromplain = NULL;
+ fromthml = new ThMLPlain();
+ fromgbf = new GBFPlain();
+ fromosis = new OSISPlain();
+ fromtei = new TEIPlain();
+ break;
+
+ case FMT_THML:
+ fromplain = NULL;
+ fromthml = NULL;
+ fromgbf = new GBFThML();
+ fromosis = NULL;
+ fromtei = NULL;
+ break;
+
+ case FMT_GBF:
+ fromplain = NULL;
+ fromthml = new ThMLGBF();
+ fromgbf = NULL;
+ fromosis = NULL;
+ fromtei = NULL;
+ break;
+
+ case FMT_HTML:
+ fromplain = NULL;
+ fromthml = new ThMLHTML();
+ fromgbf = new GBFHTML();
+ fromosis = NULL;
+ fromtei = NULL;
+ break;
+
+ case FMT_HTMLHREF:
+ fromplain = NULL;
+ fromthml = new ThMLHTMLHREF();
+ fromgbf = new GBFHTMLHREF();
+ fromosis = new OSISHTMLHREF();
+ fromtei = new TEIHTMLHREF();
+ break;
+
+ case FMT_RTF:
+ fromplain = NULL;
+ fromthml = new ThMLRTF();
+ fromgbf = new GBFRTF();
+ fromosis = new OSISRTF();
+ fromtei = new TEIRTF();
+ break;
+
+ case FMT_OSIS:
+ fromplain = NULL;
+ fromthml = new ThMLOSIS();
+ fromgbf = new GBFOSIS();
+ fromosis = new OSISOSIS();
+ fromtei = NULL;
+ break;
+
+ case FMT_WEBIF:
+ fromplain = NULL;
+ fromthml = new ThMLWEBIF();
+ fromgbf = new GBFWEBIF();
+ fromosis = new OSISWEBIF();
+ fromtei = NULL;
+ break;
+
+ case FMT_TEI:
+ fromplain = NULL;
+ fromthml = NULL;
+ fromgbf = NULL;
+ fromosis = NULL;
+ fromtei = NULL;
+ break;
+
+ case FMT_XHTML:
+ fromplain = NULL;
+ fromthml = new ThMLXHTML();
+ fromgbf = new GBFXHTML();
+ fromosis = new OSISXHTML();
+ fromtei = new TEIXHTML();
+ break;
+ }
}
+
SWORD_NAMESPACE_END
+
diff --git a/src/mgr/ftptrans.cpp b/src/mgr/remotetrans.cpp
index 6e17661..03ad3e4 100644
--- a/src/mgr/ftptrans.cpp
+++ b/src/mgr/remotetrans.cpp
@@ -1,9 +1,10 @@
- /*****************************************************************************
- * FTPTransport functions
+/*****************************************************************************
*
+ * remotetrans.cpp -
*
+ * $Id: remotetrans.cpp 2980 2013-09-14 21:51:47Z scribe $
*
- * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
+ * Copyright 2004-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -19,20 +20,19 @@
*
*/
-
-
-
-#include <ftptrans.h>
+#include <remotetrans.h>
#include <filemgr.h>
#include <fcntl.h>
#include <dirent.h>
#include <swlog.h>
+
extern "C" {
#include <ftpparse.h>
}
+
using std::vector;
@@ -41,12 +41,12 @@ SWORD_NAMESPACE_START
namespace {
-void removeTrailingSlash(SWBuf &buf) {
- int len = buf.size();
- if ((buf[len-1] == '/')
- || (buf[len-1] == '\\'))
- buf.size(len-1);
-}
+ void removeTrailingSlash(SWBuf &buf) {
+ int len = buf.size();
+ if ((buf[len-1] == '/')
+ || (buf[len-1] == '\\'))
+ buf.size(len-1);
+ }
};
@@ -54,11 +54,12 @@ void removeTrailingSlash(SWBuf &buf) {
void StatusReporter::preStatus(long totalBytes, long completedBytes, const char *message) {
}
+
void StatusReporter::statusUpdate(double dtTotal, double dlNow) {
}
-FTPTransport::FTPTransport(const char *host, StatusReporter *statusReporter) {
+RemoteTransport::RemoteTransport(const char *host, StatusReporter *statusReporter) {
this->statusReporter = statusReporter;
this->host = host;
u = "ftp";
@@ -67,18 +68,18 @@ FTPTransport::FTPTransport(const char *host, StatusReporter *statusReporter) {
}
-FTPTransport::~FTPTransport() {
+RemoteTransport::~RemoteTransport() {
}
// override this method in your real transport class
-char FTPTransport::getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf) {
+char RemoteTransport::getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf) {
char retVal = 0;
return retVal;
}
-vector<struct DirEntry> FTPTransport::getDirList(const char *dirURL) {
+vector<struct DirEntry> RemoteTransport::getDirList(const char *dirURL) {
vector<struct DirEntry> dirList;
@@ -99,12 +100,15 @@ vector<struct DirEntry> FTPTransport::getDirList(const char *dirURL) {
else if ((*end != 10) && (*end != 13))
break;
}
- SWLog::getSystemLog()->logWarning("FTPURLGetDir: parsing item %s(%d)\n", start, end-start);
+ SWLog::getSystemLog()->logWarning("getDirList: parsing item %s(%d)\n", start, end-start);
int status = ftpparse(&item, start, end - start);
- SWLog::getSystemLog()->logWarning("FTPURLGetDir: got item %s\n", item.name);
- if (status) {
+ // in ftpparse.h, there is a warning that name is not necessarily null terminated
+ SWBuf name;
+ name.append(item.name, item.namelen);
+ SWLog::getSystemLog()->logWarning("getDirList: got item %s\n", name.c_str());
+ if (status && name != "." && name != "..") {
struct DirEntry i;
- i.name = item.name;
+ i.name = name;
i.size = item.size;
i.isDirectory = (item.flagtrycwd == 1);
dirList.push_back(i);
@@ -112,15 +116,14 @@ vector<struct DirEntry> FTPTransport::getDirList(const char *dirURL) {
start = end;
}
}
- else
- {
- SWLog::getSystemLog()->logWarning("FTPURLGetDir: failed to get dir %s\n", dirURL);
+ else {
+ SWLog::getSystemLog()->logWarning("getDirList: failed to get dir %s\n", dirURL);
}
return dirList;
}
-int FTPTransport::copyDirectory(const char *urlPrefix, const char *dir, const char *dest, const char *suffix) {
+int RemoteTransport::copyDirectory(const char *urlPrefix, const char *dir, const char *dest, const char *suffix) {
unsigned int i;
int retVal = 0;
@@ -163,7 +166,7 @@ int FTPTransport::copyDirectory(const char *urlPrefix, const char *dir, const ch
url += dirEntry.name; //dont forget the final slash
if (!dirEntry.isDirectory) {
if (getURL(buffer.c_str(), url.c_str())) {
- SWLog::getSystemLog()->logWarning("FTPCopy: failed to get file %s\n", url.c_str());
+ SWLog::getSystemLog()->logWarning("copyDirectory: failed to get file %s\n", url.c_str());
return -2;
}
completedBytes += dirEntry.size;
@@ -173,7 +176,7 @@ int FTPTransport::copyDirectory(const char *urlPrefix, const char *dir, const ch
removeTrailingSlash(subdir);
subdir += (SWBuf)"/" + dirEntry.name;
if (copyDirectory(urlPrefix, subdir, buffer.c_str(), suffix)) {
- SWLog::getSystemLog()->logWarning("FTPCopy: failed to get file %s\n", subdir.c_str());
+ SWLog::getSystemLog()->logWarning("copyDirectory: failed to get file %s\n", subdir.c_str());
return -2;
}
}
@@ -189,5 +192,13 @@ int FTPTransport::copyDirectory(const char *urlPrefix, const char *dir, const ch
}
+#if defined(__GNUC__)
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+void StatusReporter::update(unsigned long totalBytes, unsigned long completedBytes) {
+ statusUpdate(totalBytes, completedBytes);
+}
+
+
SWORD_NAMESPACE_END
diff --git a/src/mgr/stringmgr.cpp b/src/mgr/stringmgr.cpp
index c4a994e..0390905 100644
--- a/src/mgr/stringmgr.cpp
+++ b/src/mgr/stringmgr.cpp
@@ -1,9 +1,10 @@
/******************************************************************************
- * stringmgr.cpp - implementation of class StringMgr
*
- * $Id: stringmgr.cpp 2115 2007-10-16 18:29:00Z scribe $
+ * stringmgr.cpp - implementation of class StringMgr
*
- * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
+ * $Id: stringmgr.cpp 2980 2013-09-14 21:51:47Z scribe $
+ *
+ * Copyright 2004-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -38,8 +39,10 @@
#endif
+
SWORD_NAMESPACE_START
+
StringMgr *StringMgr::systemStringMgr = 0;
class __staticsystemStringMgr {
@@ -48,70 +51,74 @@ public:
~__staticsystemStringMgr() { if (StringMgr::systemStringMgr) delete StringMgr::systemStringMgr; StringMgr::systemStringMgr = 0; }
} _staticsystemStringMgr;
-/**
- * Determine whether the string contains a valid unicode sequence. The following table give the pattern of a valid UTF-8 character.
- * Unicode Range 1st 2nd 3rd 4th 5th 6th
- * U-00000000 - U-0000007F 0nnnnnnn
- * U-00000080 - U-000007FF 110nnnnn 10nnnnnn
- * U-00000800 - U-0000FFFF 1110nnnn 10nnnnnn 10nnnnnn
- * U-00010000 - U-001FFFFF 11110nnn 10nnnnnn 10nnnnnn 10nnnnnn
- * U-00200000 - U-03FFFFFF 111110nn 10nnnnnn 10nnnnnn 10nnnnnn 10nnnnnn
- * U-04000000 - U-7FFFFFFF 1111110n 10nnnnnn 10nnnnnn 10nnnnnn 10nnnnnn 10nnnnnn
- * Note:
- * The latest UTF-8 RFC allows for a max of 4 bytes. Earlier allowed 6.
- * The number of bits of the leading byte before the first 0 is the total number of bytes
- * The "n" are the bits of the unicode codepoint.
- *
- * This routine does not check to see if the code point is in the range. It could.
- *
- * @param txt the text to check
- * @return 1 if all high order characters form a valid unicode sequence
- * -1 if there are no high order characters
- * 0 if there are high order characters that do not form a valid unicode sequence
- * @author DM Smith [dmsmith555 at yahoo dot com]
- */
-int isValidUTF8(unsigned char *txt) {
- unsigned int countUTF8 = 0;
-#if 0
- unsigned char parts = 0;
-
-
- unsigned char *p = txt;
- while (*p) {
- // Is the high order bit set?
- if (*p & 0x80) {
- // then count the number of high order bits that are set
- // this determines the number of following bytes need to have high order bits set
- unsigned char i = *p;
- for (parts = 0; i & 0x80; parts++) {
- i <<= 1;
- }
-
- // The pattern 10nnnnnn is not a unicode character
- if (parts == 1) {
- return 0;
- }
- else {
- while (--parts && ++*p) {
- // The pattern of each following character must be: 10nnnnnn
- if (0xc0 & *p != 0x80) {
- return 0;
- }
+namespace {
+
+ /**
+ * Determine whether the string contains a valid unicode sequence. The following table give the pattern of a valid UTF-8 character.
+ * Unicode Range 1st 2nd 3rd 4th 5th 6th
+ * U-00000000 - U-0000007F 0nnnnnnn
+ * U-00000080 - U-000007FF 110nnnnn 10nnnnnn
+ * U-00000800 - U-0000FFFF 1110nnnn 10nnnnnn 10nnnnnn
+ * U-00010000 - U-001FFFFF 11110nnn 10nnnnnn 10nnnnnn 10nnnnnn
+ * U-00200000 - U-03FFFFFF 111110nn 10nnnnnn 10nnnnnn 10nnnnnn 10nnnnnn
+ * U-04000000 - U-7FFFFFFF 1111110n 10nnnnnn 10nnnnnn 10nnnnnn 10nnnnnn 10nnnnnn
+ * Note:
+ * The latest UTF-8 RFC allows for a max of 4 bytes. Earlier allowed 6.
+ * The number of bits of the leading byte before the first 0 is the total number of bytes
+ * The "n" are the bits of the unicode codepoint.
+ *
+ * This routine does not check to see if the code point is in the range. It could.
+ *
+ * @param txt the text to check
+ * @return 1 if all high order characters form a valid unicode sequence
+ * -1 if there are no high order characters
+ * 0 if there are high order characters that do not form a valid unicode sequence
+ * @author DM Smith [dmsmith555 at yahoo dot com]
+ */
+ int isValidUTF8(unsigned char *txt) {
+ unsigned int countUTF8 = 0;
+ #if 0
+ unsigned char parts = 0;
+
+
+ unsigned char *p = txt;
+ while (*p) {
+ // Is the high order bit set?
+ if (*p & 0x80) {
+ // then count the number of high order bits that are set
+ // this determines the number of following bytes need to have high order bits set
+ unsigned char i = *p;
+ for (parts = 0; i & 0x80; parts++) {
+ i <<= 1;
}
- // Oops, we've run out of bytes too soon: Cannot be UTF-8
- if (parts) {
+
+ // The pattern 10nnnnnn is not a unicode character
+ if (parts == 1) {
return 0;
}
+ else {
+ while (--parts && ++*p) {
+ // The pattern of each following character must be: 10nnnnnn
+ if (0xc0 & *p != 0x80) {
+ return 0;
+ }
+ }
+
+ // Oops, we've run out of bytes too soon: Cannot be UTF-8
+ if (parts) {
+ return 0;
+ }
+ }
+ countUTF8++;
}
- countUTF8++;
}
- }
- // At this point it is either UTF-8 or ascii
-#endif
- return countUTF8 ? 1 : -1;
+ // At this point it is either UTF-8 or ascii
+ #endif
+ return countUTF8 ? 1 : -1;
+ }
}
diff --git a/src/mgr/swcacher.cpp b/src/mgr/swcacher.cpp
index 57d0817..e12bdcb 100644
--- a/src/mgr/swcacher.cpp
+++ b/src/mgr/swcacher.cpp
@@ -1,10 +1,12 @@
/******************************************************************************
- * swcacher.h - definition of class SWCacher used to provide an interface for
- * objects that cache and want a standard interface for cleaning up.
*
- * $Id: swcacher.cpp 1688 2005-01-01 04:42:26Z scribe $
+ * swcacher.cpp - definition of class SWCacher used to provide an
+ * interface for objects that cache and want a standard
+ * interface for cleaning up
*
- * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
+ * $Id: swcacher.cpp 2980 2013-09-14 21:51:47Z scribe $
+ *
+ * Copyright 2002-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -22,6 +24,7 @@
#include <swcacher.h>
+
SWORD_NAMESPACE_START
@@ -44,4 +47,6 @@ long SWCacher::lastAccess() {
return 0;
}
+
SWORD_NAMESPACE_END
+
diff --git a/src/mgr/swconfig.cpp b/src/mgr/swconfig.cpp
index 309f686..748071c 100644
--- a/src/mgr/swconfig.cpp
+++ b/src/mgr/swconfig.cpp
@@ -1,10 +1,11 @@
/******************************************************************************
- * swconfig.cpp - implementation of Class SWConfig used for saving and
- * retrieval of configuration information
*
- * $Id: swconfig.cpp 2218 2008-12-23 09:33:38Z scribe $
+ * swconfig.cpp - used for saving and retrieval of configuration
+ * information
*
- * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
+ * $Id: swconfig.cpp 2980 2013-09-14 21:51:47Z scribe $
+ *
+ * Copyright 1998-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -28,9 +29,11 @@
SWORD_NAMESPACE_START
+
SWConfig::SWConfig() {
}
+
SWConfig::SWConfig(const char * ifilename) {
filename = ifilename;
Load();
@@ -40,6 +43,7 @@ SWConfig::SWConfig(const char * ifilename) {
SWConfig::~SWConfig() {
}
+
void SWConfig::Load() {
if (!filename.size()) return; // assert we have a filename
@@ -164,4 +168,6 @@ ConfigEntMap & SWConfig::operator [] (const char *section) {
return Sections[section];
}
+
SWORD_NAMESPACE_END
+
diff --git a/src/mgr/swfiltermgr.cpp b/src/mgr/swfiltermgr.cpp
index 434f2e0..5240014 100644
--- a/src/mgr/swfiltermgr.cpp
+++ b/src/mgr/swfiltermgr.cpp
@@ -1,10 +1,11 @@
/******************************************************************************
- * swfiltermgr.cpp - definition of class SWFilterMgr used as an interface to
- * manage filters on a module
*
- * $Id: swfiltermgr.cpp 1688 2005-01-01 04:42:26Z scribe $
+ * swfiltermgr.cpp - Implementation of SWFilterMgr, used as an interface
+ * to manage filters on a module
*
- * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
+ * $Id: swfiltermgr.cpp 2980 2013-09-14 21:51:47Z scribe $
+ *
+ * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -22,6 +23,7 @@
#include <swfiltermgr.h>
+
SWORD_NAMESPACE_START
@@ -90,4 +92,6 @@ void SWFilterMgr::AddStripFilters(SWModule * module, ConfigEntMap & section) {
void SWFilterMgr::AddRawFilters(SWModule * module, ConfigEntMap & section) {
}
+
SWORD_NAMESPACE_END
+
diff --git a/src/mgr/swlocale.cpp b/src/mgr/swlocale.cpp
index fff35d5..a007238 100644
--- a/src/mgr/swlocale.cpp
+++ b/src/mgr/swlocale.cpp
@@ -1,10 +1,11 @@
/******************************************************************************
- * swlocale.cpp - implementation of Class SWLocale used for retrieval
- * of locale lookups
*
- * $Id: swlocale.cpp 2463 2009-10-14 22:14:55Z chrislit $
+ * swlocale.cpp - implementation of Class SWLocale used for retrieval
+ * of locale lookups
*
- * Copyright 2000 CrossWire Bible Society (http://www.crosswire.org)
+ * $Id: swlocale.cpp 2980 2013-09-14 21:51:47Z scribe $
+ *
+ * Copyright 2000-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -25,15 +26,21 @@
#include <map>
#include <swconfig.h>
#include <versekey.h>
-#include <versemgr.h>
+#include <versificationmgr.h>
+
SWORD_NAMESPACE_START
-typedef std::map < SWBuf, SWBuf, std::less < SWBuf > >LookupMap;
+
+namespace {
+ typedef std::map < SWBuf, SWBuf, std::less < SWBuf > >LookupMap;
+}
+
const char *SWLocale::DEFAULT_LOCALE_NAME="en";
-// I have bridge patterns, but this hides swconfig and map from lots o stuff
+
+// I hate bridge patterns, but this hides swconfig and map from lots o stuff
class SWLocale::Private {
public:
LookupMap lookupTable;
@@ -144,10 +151,12 @@ const char *SWLocale::getDescription() {
return description;
}
+
const char *SWLocale::getEncoding() {
return encoding;
}
+
void SWLocale::augment(SWLocale &addFrom) {
*localeSource += *addFrom.localeSource;
}
@@ -184,3 +193,4 @@ const struct abbrev *SWLocale::getBookAbbrevs(int *retSize) {
SWORD_NAMESPACE_END
+
diff --git a/src/mgr/swmgr.cpp b/src/mgr/swmgr.cpp
index 3ee253f..0a2d583 100644
--- a/src/mgr/swmgr.cpp
+++ b/src/mgr/swmgr.cpp
@@ -1,10 +1,10 @@
/******************************************************************************
- * swmgr.cpp - implementaion of class SWMgr used to interact with an install
- * base of sword modules.
*
- * $Id: swmgr.cpp 2374 2009-05-04 03:48:01Z scribe $
+ * swmgr.cpp - used to interact with an install base of sword modules
*
- * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
+ * $Id: swmgr.cpp 2985 2013-10-04 14:38:14Z scribe $
+ *
+ * Copyright 1998-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -51,6 +51,8 @@
#include <gbfheadings.h>
#include <gbfredletterwords.h>
#include <gbfmorph.h>
+#include <osisenum.h>
+#include <osisglosses.h>
#include <osisheadings.h>
#include <osisfootnotes.h>
#include <osisstrongs.h>
@@ -58,8 +60,10 @@
#include <osislemma.h>
#include <osisredletterwords.h>
#include <osismorphsegmentation.h>
-#include <osisruby.h>
#include <osisscripref.h>
+#include <osisvariants.h>
+#include <osisxlit.h>
+#include <osisreferencelinks.h>
#include <thmlstrongs.h>
#include <thmlfootnotes.h>
#include <thmlheadings.h>
@@ -81,6 +85,7 @@
#include <swfiltermgr.h>
#include <swcipher.h>
#include <swoptfilter.h>
+#include <rtfhtml.h>
#include <swlog.h>
@@ -88,6 +93,8 @@
#ifndef EXCLUDEZLIB
#include "zipcomprs.h"
+#include "bz2comprs.h"
+#include "xzcomprs.h"
#endif
@@ -95,8 +102,10 @@
#include <utf8transliterator.h>
#endif
+
SWORD_NAMESPACE_START
+
#ifdef _ICU_
bool SWMgr::isICU = true;
#else
@@ -110,6 +119,14 @@ const char *SWMgr::globalConfPath = GLOBCONFPATH;
const char *SWMgr::globalConfPath = "/etc/sword.conf:/usr/local/etc/sword.conf";
#endif
+
+const char *SWMgr::MODTYPE_BIBLES = "Biblical Texts";
+const char *SWMgr::MODTYPE_COMMENTARIES = "Commentaries";
+const char *SWMgr::MODTYPE_LEXDICTS = "Lexicons / Dictionaries";
+const char *SWMgr::MODTYPE_GENBOOKS = "Generic Books";
+const char *SWMgr::MODTYPE_DAILYDEVOS = "Daily Devotional";
+
+
void SWMgr::init() {
SWOptionFilter *tmpFilter = 0;
configPath = 0;
@@ -123,6 +140,7 @@ void SWMgr::init() {
cipherFilters.clear();
optionFilters.clear();
cleanupFilters.clear();
+ extraFilters.clear();
tmpFilter = new ThMLVariants();
optionFilters.insert(OptionFilterMap::value_type("ThMLVariants", tmpFilter));
cleanupFilters.push_back(tmpFilter);
@@ -179,10 +197,23 @@ void SWMgr::init() {
optionFilters.insert(OptionFilterMap::value_type("OSISMorphSegmentation", tmpFilter));
cleanupFilters.push_back(tmpFilter);
- tmpFilter = new OSISRuby();
+ tmpFilter = new OSISGlosses();
+ optionFilters.insert(OptionFilterMap::value_type("OSISGlosses", tmpFilter));
optionFilters.insert(OptionFilterMap::value_type("OSISRuby", tmpFilter));
cleanupFilters.push_back(tmpFilter);
+ tmpFilter = new OSISXlit();
+ optionFilters.insert(OptionFilterMap::value_type("OSISXlit", tmpFilter));
+ cleanupFilters.push_back(tmpFilter);
+
+ tmpFilter = new OSISEnum();
+ optionFilters.insert(OptionFilterMap::value_type("OSISEnum", tmpFilter));
+ cleanupFilters.push_back(tmpFilter);
+
+ tmpFilter = new OSISVariants();
+ optionFilters.insert(OptionFilterMap::value_type("OSISVariants", tmpFilter));
+ cleanupFilters.push_back(tmpFilter);
+
tmpFilter = new ThMLStrongs();
optionFilters.insert(OptionFilterMap::value_type("ThMLStrongs", tmpFilter));
cleanupFilters.push_back(tmpFilter);
@@ -241,15 +272,25 @@ void SWMgr::init() {
gbfplain = new GBFPlain();
cleanupFilters.push_back(gbfplain);
+ extraFilters.insert(FilterMap::value_type("GBFPlain", gbfplain));
thmlplain = new ThMLPlain();
cleanupFilters.push_back(thmlplain);
+ extraFilters.insert(FilterMap::value_type("ThMLPlain", thmlplain));
osisplain = new OSISPlain();
cleanupFilters.push_back(osisplain);
+ extraFilters.insert(FilterMap::value_type("OSISPlain", osisplain));
teiplain = new TEIPlain();
cleanupFilters.push_back(teiplain);
+ extraFilters.insert(FilterMap::value_type("TEIPlain", teiplain));
+
+ // filters which aren't really used anywhere but which we want available for a "FilterName" -> filter mapping (e.g., filterText)
+ SWFilter *f = new RTFHTML();
+ extraFilters.insert(FilterMap::value_type("RTFHTML", f));
+ cleanupFilters.push_back(f);
+
}
@@ -715,7 +756,7 @@ void SWMgr::augmentModules(const char *ipath, bool multiMod) {
// fix config's Section names to rename modules which are available more than once
// find out which sections are in both config objects
// inserting all configs first is not good because that overwrites old keys and new modules would share the same config
- for (SectionMap::iterator it = config->Sections.begin(); it != config->Sections.end(); ++it) {
+ for (SectionMap::iterator it = config->Sections.begin(); it != config->Sections.end();) {
if (saveConfig->Sections.find( (*it).first ) != saveConfig->Sections.end()) { //if the new section is already present rename it
ConfigEntMap entMap((*it).second);
@@ -727,8 +768,10 @@ void SWMgr::augmentModules(const char *ipath, bool multiMod) {
} while (config->Sections.find(name) != config->Sections.end());
config->Sections.insert(SectionMap::value_type(name, entMap) );
- config->Sections.erase(it);
+ SectionMap::iterator toErase = it++;
+ config->Sections.erase(toErase);
}
+ else ++it;
}
}
@@ -819,7 +862,8 @@ signed char SWMgr::Load() {
return ret;
}
-SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap &section)
+
+SWModule *SWMgr::createModule(const char *name, const char *driver, ConfigEntMap &section)
{
SWBuf description, datapath, misc1;
ConfigEntMap::iterator entry;
@@ -868,7 +912,9 @@ SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap &s
else
markup = FMT_GBF;
- if (!stricmp(encoding.c_str(), "UTF-8")) {
+ if (!stricmp(encoding.c_str(), "SCSU"))
+ enc = ENC_SCSU;
+ else if (!stricmp(encoding.c_str(), "UTF-8")) {
enc = ENC_UTF8;
}
else enc = ENC_LATIN1;
@@ -889,7 +935,6 @@ SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap &s
if ((!stricmp(driver, "zText")) || (!stricmp(driver, "zCom"))) {
SWCompress *compress = 0;
int blockType = CHAPTERBLOCKS;
- int blockNum = 1;
misc1 = ((entry = section.find("BlockType")) != section.end()) ? (*entry).second : (SWBuf)"CHAPTER";
if (!stricmp(misc1.c_str(), "VERSE"))
blockType = VERSEBLOCKS;
@@ -898,14 +943,17 @@ SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap &s
else if (!stricmp(misc1.c_str(), "BOOK"))
blockType = BOOKBLOCKS;
- misc1 = ((entry = section.find("BlockNumber")) != section.end()) ? (*entry).second : (SWBuf)"1";
- blockNum = atoi(misc1.c_str());
-
misc1 = ((entry = section.find("CompressType")) != section.end()) ? (*entry).second : (SWBuf)"LZSS";
#ifndef EXCLUDEZLIB
if (!stricmp(misc1.c_str(), "ZIP"))
compress = new ZipCompress();
else
+ if (!stricmp(misc1.c_str(), "BZIP2_UNSUPPORTED"))
+ compress = new Bzip2Compress();
+ else
+ if (!stricmp(misc1.c_str(), "XZ_UNSUPPORTED"))
+ compress = new XzCompress();
+ else
#endif
if (!stricmp(misc1.c_str(), "LZSS"))
compress = new LZSSCompress();
@@ -949,18 +997,24 @@ SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap &s
int pos = 0; //used for position of final / in AbsoluteDataPath, but also set to 1 for modules types that need to strip module name
if (!stricmp(driver, "RawLD")) {
- newmod = new RawLD(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
+ bool caseSensitive = ((entry = section.find("CaseSensitiveKeys")) != section.end()) ? (*entry).second == "true": false;
+ bool strongsPadding = ((entry = section.find("StrongsPadding")) != section.end()) ? (*entry).second == "true": true;
+ newmod = new RawLD(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), caseSensitive, strongsPadding);
pos = 1;
}
if (!stricmp(driver, "RawLD4")) {
- newmod = new RawLD4(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
+ bool caseSensitive = ((entry = section.find("CaseSensitiveKeys")) != section.end()) ? (*entry).second == "true": false;
+ bool strongsPadding = ((entry = section.find("StrongsPadding")) != section.end()) ? (*entry).second == "true": true;
+ newmod = new RawLD4(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), caseSensitive, strongsPadding);
pos = 1;
}
if (!stricmp(driver, "zLD")) {
SWCompress *compress = 0;
int blockCount;
+ bool caseSensitive = ((entry = section.find("CaseSensitiveKeys")) != section.end()) ? (*entry).second == "true": false;
+ bool strongsPadding = ((entry = section.find("StrongsPadding")) != section.end()) ? (*entry).second == "true": true;
misc1 = ((entry = section.find("BlockCount")) != section.end()) ? (*entry).second : (SWBuf)"200";
blockCount = atoi(misc1.c_str());
blockCount = (blockCount) ? blockCount : 200;
@@ -975,7 +1029,7 @@ SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap &s
compress = new LZSSCompress();
if (compress) {
- newmod = new zLD(datapath.c_str(), name, description.c_str(), blockCount, compress, 0, enc, direction, markup, lang.c_str());
+ newmod = new zLD(datapath.c_str(), name, description.c_str(), blockCount, compress, 0, enc, direction, markup, lang.c_str(), caseSensitive, strongsPadding);
}
pos = 1;
}
@@ -1008,7 +1062,7 @@ SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap &s
if (newmod) {
// if a specific module type is set in the config, use this
if ((entry = section.find("Type")) != section.end())
- newmod->Type(entry->second.c_str());
+ newmod->setType(entry->second.c_str());
newmod->setConfig(&section);
}
@@ -1018,11 +1072,37 @@ SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap &s
void SWMgr::AddGlobalOptions(SWModule *module, ConfigEntMap &section, ConfigEntMap::iterator start, ConfigEntMap::iterator end) {
- for (;start != end; start++) {
+
+ for (;start != end; ++start) {
OptionFilterMap::iterator it;
- it = optionFilters.find((*start).second);
+ SWBuf filterName = start->second;
+
+
+ // special cases for filters with parameters
+
+ if (filterName.startsWith("OSISReferenceLinks")) {
+ SWBuf params = filterName;
+ filterName = params.stripPrefix('|', true);
+ SWBuf optionName = params.stripPrefix('|', true);
+ SWBuf optionTip = params.stripPrefix('|', true);
+ SWBuf optionType = params.stripPrefix('|', true);
+ SWBuf optionSubType = params.stripPrefix('|', true);
+ SWBuf optionDefaultValue = params.stripPrefix('|', true);
+ // we'll key off of type and subtype.
+ filterName = filterName + "." + optionType + "." + optionSubType;
+
+ it = optionFilters.find(filterName);
+ if (it == optionFilters.end()) {
+ SWOptionFilter *tmpFilter = new OSISReferenceLinks(optionName, optionTip, optionType, optionSubType, optionDefaultValue);
+ optionFilters.insert(OptionFilterMap::value_type(filterName, tmpFilter));
+ cleanupFilters.push_back(tmpFilter);
+ }
+ }
+
+
+ it = optionFilters.find(filterName);
if (it != optionFilters.end()) {
- module->AddOptionFilter((*it).second); // add filter to module and option as a valid option
+ module->addOptionFilter((*it).second); // add filter to module and option as a valid option
StringList::iterator loop;
for (loop = options.begin(); loop != options.end(); loop++) {
if (!strcmp((*loop).c_str(), (*it).second->getOptionName()))
@@ -1035,20 +1115,31 @@ void SWMgr::AddGlobalOptions(SWModule *module, ConfigEntMap &section, ConfigEntM
if (filterMgr)
filterMgr->AddGlobalOptions(module, section, start, end);
#ifdef _ICU_
- module->AddOptionFilter(transliterator);
+ module->addOptionFilter(transliterator);
#endif
}
char SWMgr::filterText(const char *filterName, SWBuf &text, const SWKey *key, const SWModule *module)
- {
+{
char retVal = -1;
+ // why didn't we use find here?
for (OptionFilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) {
if ((*it).second->getOptionName()) {
- if (!stricmp(filterName, (*it).second->getOptionName()))
- retVal = it->second->processText(text, key, module); // add filter to module
+ if (!stricmp(filterName, (*it).second->getOptionName())) {
+ retVal = it->second->processText(text, key, module);
+ break;
+ }
+ }
+ }
+
+ if (retVal == -1) {
+ FilterMap::iterator it = extraFilters.find(filterName);
+ if (it != extraFilters.end()) {
+ retVal = it->second->processText(text, key, module);
}
}
+
return retVal;
}
@@ -1059,7 +1150,7 @@ void SWMgr::AddLocalOptions(SWModule *module, ConfigEntMap &section, ConfigEntMa
OptionFilterMap::iterator it;
it = optionFilters.find((*start).second);
if (it != optionFilters.end()) {
- module->AddOptionFilter((*it).second); // add filter to module
+ module->addOptionFilter((*it).second); // add filter to module
}
}
@@ -1075,7 +1166,7 @@ void SWMgr::AddStripFilters(SWModule *module, ConfigEntMap &section, ConfigEntMa
OptionFilterMap::iterator it;
it = optionFilters.find((*start).second);
if (it != optionFilters.end()) {
- module->AddStripFilter((*it).second); // add filter to module
+ module->addStripFilter((*it).second); // add filter to module
}
}
}
@@ -1088,9 +1179,9 @@ void SWMgr::AddRawFilters(SWModule *module, ConfigEntMap &section) {
cipherKey = ((entry = section.find("CipherKey")) != section.end()) ? (*entry).second : (SWBuf)"";
if (cipherKey.length()) {
SWFilter *cipherFilter = new CipherFilter(cipherKey.c_str());
- cipherFilters.insert(FilterMap::value_type(module->Name(), cipherFilter));
+ cipherFilters.insert(FilterMap::value_type(module->getName(), cipherFilter));
cleanupFilters.push_back(cipherFilter);
- module->AddRawFilter(cipherFilter);
+ module->addRawFilter(cipherFilter);
}
if (filterMgr)
@@ -1145,16 +1236,16 @@ void SWMgr::AddStripFilters(SWModule *module, ConfigEntMap &section)
}
if (!stricmp(sourceformat.c_str(), "GBF")) {
- module->AddStripFilter(gbfplain);
+ module->addStripFilter(gbfplain);
}
else if (!stricmp(sourceformat.c_str(), "ThML")) {
- module->AddStripFilter(thmlplain);
+ module->addStripFilter(thmlplain);
}
else if (!stricmp(sourceformat.c_str(), "OSIS")) {
- module->AddStripFilter(osisplain);
+ module->addStripFilter(osisplain);
}
else if (!stricmp(sourceformat.c_str(), "TEI")) {
- module->AddStripFilter(teiplain);
+ module->addStripFilter(teiplain);
}
if (filterMgr)
@@ -1176,19 +1267,19 @@ void SWMgr::CreateMods(bool multiMod) {
driver = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)"";
if (driver.length()) {
- newmod = CreateMod((*it).first, driver, section);
+ newmod = createModule((*it).first, driver, section);
if (newmod) {
// Filters to add for this module and globally announce as an option to the user
// e.g. translit, strongs, redletterwords, etc, so users can turn these on and off globally
- start = (*it).second.lower_bound("GlobalOptionFilter");
- end = (*it).second.upper_bound("GlobalOptionFilter");
+ start = section.lower_bound("GlobalOptionFilter");
+ end = section.upper_bound("GlobalOptionFilter");
AddGlobalOptions(newmod, section, start, end);
// Only add the option to the module, don't announce it's availability
// These are useful for like: filters that parse special entryAttribs in a text
// or whatever you might want to happen on entry lookup
- start = (*it).second.lower_bound("LocalOptionFilter");
- end = (*it).second.upper_bound("LocalOptionFilter");
+ start = section.lower_bound("LocalOptionFilter");
+ end = section.upper_bound("LocalOptionFilter");
AddLocalOptions(newmod, section, start, end);
//STRIP FILTERS
@@ -1198,20 +1289,20 @@ void SWMgr::CreateMods(bool multiMod) {
// Any special processing for this module when searching:
// e.g. for papyri, removed all [](). notation
- start = (*it).second.lower_bound("LocalStripFilter");
- end = (*it).second.upper_bound("LocalStripFilter");
+ start = section.lower_bound("LocalStripFilter");
+ end = section.upper_bound("LocalStripFilter");
AddStripFilters(newmod, section, start, end);
AddRawFilters(newmod, section);
AddRenderFilters(newmod, section);
AddEncodingFilters(newmod, section);
- SWModule *oldmod = Modules[newmod->Name()];
+ SWModule *oldmod = Modules[newmod->getName()];
if (oldmod) {
delete oldmod;
}
- Modules[newmod->Name()] = newmod;
+ Modules[newmod->getName()] = newmod;
}
}
}
@@ -1382,11 +1473,13 @@ signed char SWMgr::setCipherKey(const char *modName, const char *key) {
SWFilter *cipherFilter = new CipherFilter(key);
cipherFilters.insert(FilterMap::value_type(modName, cipherFilter));
cleanupFilters.push_back(cipherFilter);
- (*it2).second->AddRawFilter(cipherFilter);
+ (*it2).second->addRawFilter(cipherFilter);
return 0;
}
}
return -1;
}
+
SWORD_NAMESPACE_END
+
diff --git a/src/mgr/swsearchable.cpp b/src/mgr/swsearchable.cpp
index 48ae556..5837c9c 100644
--- a/src/mgr/swsearchable.cpp
+++ b/src/mgr/swsearchable.cpp
@@ -1,10 +1,11 @@
/******************************************************************************
- * swsearchable.h - definition of class SWSearchable used to provide an
- * interface for objects that be searched.
*
- * $Id: swsearchable.cpp 1959 2006-08-28 00:39:56Z scribe $
+ * swsearchable.cpp - used to provide an interface for objects that
+ * can be searched
*
- * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
+ * $Id: swsearchable.cpp 2980 2013-09-14 21:51:47Z scribe $
+ *
+ * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -23,10 +24,13 @@
#include <swsearchable.h>
#include <listkey.h>
+
SWORD_NAMESPACE_START
+
void SWSearchable::nullPercent(char percent, void *percentUserData) {}
+
SWSearchable::SWSearchable() {
}
@@ -34,7 +38,8 @@ SWSearchable::SWSearchable() {
SWSearchable::~SWSearchable() {
}
- // special search framework
+
+// special search framework
signed char SWSearchable::createSearchFramework(void (*percent)(char, void *), void *percentUserData) {
return 0;
}
@@ -50,4 +55,6 @@ bool SWSearchable::isSearchOptimallySupported(const char *istr, int searchType,
return retVal;
}
+
SWORD_NAMESPACE_END
+
diff --git a/src/mgr/versemgr.cpp b/src/mgr/versificationmgr.cpp
index 354c0df..7972488 100644
--- a/src/mgr/versemgr.cpp
+++ b/src/mgr/versificationmgr.cpp
@@ -1,10 +1,11 @@
/******************************************************************************
- * versemgr.cpp - implementation of class VerseMgr used for managing
- * versification systems
*
- * $Id: versemgr.cpp 2108 2007-10-13 20:35:02Z scribe $
+ * versificationmgr.cpp - implementation of class VersificationMgr used
+ * for managing versification systems
*
- * Copyright 2010 CrossWire Bible Society (http://www.crosswire.org)
+ * $Id: versificationmgr.cpp 2980 2013-09-14 21:51:47Z scribe $
+ *
+ * Copyright 2008-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -20,7 +21,7 @@
*
*/
-#include <versemgr.h>
+#include <versificationmgr.h>
#include <vector>
#include <map>
#include <treekey.h>
@@ -36,43 +37,48 @@
#include <canon_nrsv.h> // NRSV v11n system
#include <canon_nrsva.h> // NRSV + Apocrypha v11n system
#include <canon_synodal.h> // Russian Synodal v11n system
+#include <canon_synodalprot.h> // Russian Synodal v11n system
#include <canon_vulg.h> // Vulgate v11n system
#include <canon_german.h> // German v11n system
#include <canon_luther.h> // Luther v11n system
#include <canon_catholic.h> // Catholic v11n system (10 chapter Esther)
#include <canon_catholic2.h> // Catholic2 v11n system (16 chapter Esther)
-#include <canon_synodalp.h> // SynodalP v11n system (KJV with Synodal-like verse counts)
+#include <canon_lxx.h> // General LXX v11n system (includes GNT, as used in Orthodox Bibles)
+#include <canon_orthodox.h> // Orthodox v11n system as used in Orthodox Bibles
using std::vector;
using std::map;
using std::distance;
using std::lower_bound;
+
SWORD_NAMESPACE_START
-VerseMgr *VerseMgr::getSystemVerseMgr() {
- if (!systemVerseMgr) {
- systemVerseMgr = new VerseMgr();
- systemVerseMgr->registerVersificationSystem("KJV", otbooks, ntbooks, vm);
- systemVerseMgr->registerVersificationSystem("Leningrad", otbooks_leningrad, ntbooks_null, vm_leningrad);
- systemVerseMgr->registerVersificationSystem("MT", otbooks_mt, ntbooks_null, vm_mt);
- systemVerseMgr->registerVersificationSystem("KJVA", otbooks_kjva, ntbooks, vm_kjva);
- systemVerseMgr->registerVersificationSystem("NRSV", otbooks, ntbooks, vm_nrsv);
- systemVerseMgr->registerVersificationSystem("NRSVA", otbooks_nrsva, ntbooks, vm_nrsva);
- systemVerseMgr->registerVersificationSystem("Synodal", otbooks_synodal, ntbooks_synodal, vm_synodal);
- systemVerseMgr->registerVersificationSystem("Vulg", otbooks_vulg, ntbooks_vulg, vm_vulg);
- systemVerseMgr->registerVersificationSystem("German", otbooks_german, ntbooks, vm_german);
- systemVerseMgr->registerVersificationSystem("Luther", otbooks_luther, ntbooks_luther, vm_luther);
- systemVerseMgr->registerVersificationSystem("Catholic", otbooks_catholic, ntbooks, vm_catholic);
- systemVerseMgr->registerVersificationSystem("Catholic2", otbooks_catholic2, ntbooks, vm_catholic2);
- systemVerseMgr->registerVersificationSystem("SynodalP", otbooks, ntbooks, vm_synodalp);
+VersificationMgr *VersificationMgr::getSystemVersificationMgr() {
+ if (!systemVersificationMgr) {
+ systemVersificationMgr = new VersificationMgr();
+ systemVersificationMgr->registerVersificationSystem("KJV", otbooks, ntbooks, vm);
+ systemVersificationMgr->registerVersificationSystem("Leningrad", otbooks_leningrad, ntbooks_null, vm_leningrad);
+ systemVersificationMgr->registerVersificationSystem("MT", otbooks_mt, ntbooks_null, vm_mt);
+ systemVersificationMgr->registerVersificationSystem("KJVA", otbooks_kjva, ntbooks, vm_kjva);
+ systemVersificationMgr->registerVersificationSystem("NRSV", otbooks, ntbooks, vm_nrsv);
+ systemVersificationMgr->registerVersificationSystem("NRSVA", otbooks_nrsva, ntbooks, vm_nrsva);
+ systemVersificationMgr->registerVersificationSystem("Synodal", otbooks_synodal, ntbooks_synodal, vm_synodal);
+ systemVersificationMgr->registerVersificationSystem("SynodalProt", otbooks_synodalProt, ntbooks_synodal, vm_synodalProt);
+ systemVersificationMgr->registerVersificationSystem("Vulg", otbooks_vulg, ntbooks_vulg, vm_vulg);
+ systemVersificationMgr->registerVersificationSystem("German", otbooks_german, ntbooks, vm_german);
+ systemVersificationMgr->registerVersificationSystem("Luther", otbooks_luther, ntbooks_luther, vm_luther);
+ systemVersificationMgr->registerVersificationSystem("Catholic", otbooks_catholic, ntbooks, vm_catholic);
+ systemVersificationMgr->registerVersificationSystem("Catholic2", otbooks_catholic2, ntbooks, vm_catholic2);
+ systemVersificationMgr->registerVersificationSystem("LXX", otbooks_lxx, ntbooks, vm_lxx);
+ systemVersificationMgr->registerVersificationSystem("Orthodox", otbooks_orthodox, ntbooks, vm_orthodox);
}
- return systemVerseMgr;
+ return systemVersificationMgr;
}
-class VerseMgr::System::Private {
+class VersificationMgr::System::Private {
public:
/** Array[chapmax] of maximum verses in chapters */
vector<Book> books;
@@ -80,11 +86,11 @@ public:
Private() {
}
- Private(const VerseMgr::System::Private &other) {
+ Private(const VersificationMgr::System::Private &other) {
books = other.books;
osisLookup = other.osisLookup;
}
- VerseMgr::System::Private &operator =(const VerseMgr::System::Private &other) {
+ VersificationMgr::System::Private &operator =(const VersificationMgr::System::Private &other) {
books = other.books;
osisLookup = other.osisLookup;
return *this;
@@ -92,7 +98,7 @@ public:
};
-class VerseMgr::Book::Private {
+class VersificationMgr::Book::Private {
friend struct BookOffsetLess;
public:
/** Array[chapmax] of maximum verses in chapters */
@@ -102,12 +108,12 @@ public:
Private() {
verseMax.clear();
}
- Private(const VerseMgr::Book::Private &other) {
+ Private(const VersificationMgr::Book::Private &other) {
verseMax.clear();
verseMax = other.verseMax;
offsetPrecomputed = other.offsetPrecomputed;
}
- VerseMgr::Book::Private &operator =(const VerseMgr::Book::Private &other) {
+ VersificationMgr::Book::Private &operator =(const VersificationMgr::Book::Private &other) {
verseMax.clear();
verseMax = other.verseMax;
offsetPrecomputed = other.offsetPrecomputed;
@@ -115,18 +121,21 @@ public:
}
};
+
struct BookOffsetLess {
- bool operator() (const VerseMgr::Book &o1, const VerseMgr::Book &o2) const { return o1.p->offsetPrecomputed[0] < o2.p->offsetPrecomputed[0]; }
- bool operator() (const long &o1, const VerseMgr::Book &o2) const { return o1 < o2.p->offsetPrecomputed[0]; }
- bool operator() (const VerseMgr::Book &o1, const long &o2) const { return o1.p->offsetPrecomputed[0] < o2; }
+ bool operator() (const VersificationMgr::Book &o1, const VersificationMgr::Book &o2) const { return o1.p->offsetPrecomputed[0] < o2.p->offsetPrecomputed[0]; }
+ bool operator() (const long &o1, const VersificationMgr::Book &o2) const { return o1 < o2.p->offsetPrecomputed[0]; }
+ bool operator() (const VersificationMgr::Book &o1, const long &o2) const { return o1.p->offsetPrecomputed[0] < o2; }
bool operator() (const long &o1, const long &o2) const { return o1 < o2; }
};
-void VerseMgr::Book::init() {
+
+void VersificationMgr::Book::init() {
p = new Private();
}
-void VerseMgr::System::init() {
+
+void VersificationMgr::System::init() {
p = new Private();
BMAX[0] = 0;
BMAX[1] = 0;
@@ -134,7 +143,7 @@ void VerseMgr::System::init() {
}
-VerseMgr::System::System(const System &other) {
+VersificationMgr::System::System(const System &other) {
init();
name = other.name;
BMAX[0] = other.BMAX[0];
@@ -143,7 +152,8 @@ VerseMgr::System::System(const System &other) {
ntStartOffset = other.ntStartOffset;
}
-VerseMgr::System &VerseMgr::System::operator =(const System &other) {
+
+VersificationMgr::System &VersificationMgr::System::operator =(const System &other) {
name = other.name;
BMAX[0] = other.BMAX[0];
BMAX[1] = other.BMAX[1];
@@ -153,22 +163,23 @@ VerseMgr::System &VerseMgr::System::operator =(const System &other) {
}
-VerseMgr::System::~System() {
+VersificationMgr::System::~System() {
delete p;
}
-const VerseMgr::Book *VerseMgr::System::getBook(int number) const {
+
+const VersificationMgr::Book *VersificationMgr::System::getBook(int number) const {
return (number < (signed int)p->books.size()) ? &(p->books[number]) : 0;
}
-int VerseMgr::System::getBookNumberByOSISName(const char *bookName) const {
+int VersificationMgr::System::getBookNumberByOSISName(const char *bookName) const {
map<SWBuf, int>::const_iterator it = p->osisLookup.find(bookName);
return (it != p->osisLookup.end()) ? it->second : -1;
}
-void VerseMgr::System::loadFromSBook(const sbook *ot, const sbook *nt, int *chMax) {
+void VersificationMgr::System::loadFromSBook(const sbook *ot, const sbook *nt, int *chMax) {
int chap = 0;
int book = 0;
long offset = 0; // module heading
@@ -211,7 +222,7 @@ void VerseMgr::System::loadFromSBook(const sbook *ot, const sbook *nt, int *chMa
}
-VerseMgr::Book::Book(const Book &other) {
+VersificationMgr::Book::Book(const Book &other) {
longName = other.longName;
osisName = other.osisName;
prefAbbrev = other.prefAbbrev;
@@ -220,7 +231,8 @@ VerseMgr::Book::Book(const Book &other) {
(*p) = *(other.p);
}
-VerseMgr::Book& VerseMgr::Book::operator =(const Book &other) {
+
+VersificationMgr::Book& VersificationMgr::Book::operator =(const Book &other) {
longName = other.longName;
osisName = other.osisName;
prefAbbrev = other.prefAbbrev;
@@ -231,23 +243,23 @@ VerseMgr::Book& VerseMgr::Book::operator =(const Book &other) {
}
-VerseMgr::Book::~Book() {
+VersificationMgr::Book::~Book() {
delete p;
}
-int VerseMgr::Book::getVerseMax(int chapter) const {
+int VersificationMgr::Book::getVerseMax(int chapter) const {
chapter--;
return (p && (chapter < (signed int)p->verseMax.size()) && (chapter > -1)) ? p->verseMax[chapter] : -1;
}
-int VerseMgr::System::getBookCount() const {
+int VersificationMgr::System::getBookCount() const {
return (p ? p->books.size() : 0);
}
-long VerseMgr::System::getOffsetFromVerse(int book, int chapter, int verse) const {
+long VersificationMgr::System::getOffsetFromVerse(int book, int chapter, int verse) const {
long offset = -1;
chapter--;
@@ -272,7 +284,7 @@ long VerseMgr::System::getOffsetFromVerse(int book, int chapter, int verse) cons
}
-char VerseMgr::System::getVerseFromOffset(long offset, int *book, int *chapter, int *verse) const {
+char VersificationMgr::System::getVerseFromOffset(long offset, int *book, int *chapter, int *verse) const {
if (offset < 1) { // just handle the module heading corner case up front (and error case)
(*book) = -1;
@@ -311,67 +323,67 @@ char VerseMgr::System::getVerseFromOffset(long offset, int *book, int *chapter,
/***************************************************
- * VerseMgr
+ * VersificationMgr
*/
-class VerseMgr::Private {
+class VersificationMgr::Private {
public:
Private() {
}
- Private(const VerseMgr::Private &other) {
+ Private(const VersificationMgr::Private &other) {
systems = other.systems;
}
- VerseMgr::Private &operator =(const VerseMgr::Private &other) {
+ VersificationMgr::Private &operator =(const VersificationMgr::Private &other) {
systems = other.systems;
return *this;
}
map<SWBuf, System> systems;
};
// ---------------- statics -----------------
-VerseMgr *VerseMgr::systemVerseMgr = 0;
+VersificationMgr *VersificationMgr::systemVersificationMgr = 0;
-class __staticsystemVerseMgr {
+class __staticsystemVersificationMgr {
public:
- __staticsystemVerseMgr() { }
- ~__staticsystemVerseMgr() { delete VerseMgr::systemVerseMgr; }
-} _staticsystemVerseMgr;
+ __staticsystemVersificationMgr() { }
+ ~__staticsystemVersificationMgr() { delete VersificationMgr::systemVersificationMgr; }
+} _staticsystemVersificationMgr;
-void VerseMgr::init() {
+void VersificationMgr::init() {
p = new Private();
}
-VerseMgr::~VerseMgr() {
+VersificationMgr::~VersificationMgr() {
delete p;
}
-void VerseMgr::setSystemVerseMgr(VerseMgr *newVerseMgr) {
- if (systemVerseMgr)
- delete systemVerseMgr;
- systemVerseMgr = newVerseMgr;
+void VersificationMgr::setSystemVersificationMgr(VersificationMgr *newVersificationMgr) {
+ if (systemVersificationMgr)
+ delete systemVersificationMgr;
+ systemVersificationMgr = newVersificationMgr;
}
-const VerseMgr::System *VerseMgr::getVersificationSystem(const char *name) const {
+const VersificationMgr::System *VersificationMgr::getVersificationSystem(const char *name) const {
map<SWBuf, System>::const_iterator it = p->systems.find(name);
return (it != p->systems.end()) ? &(it->second) : 0;
}
-void VerseMgr::registerVersificationSystem(const char *name, const sbook *ot, const sbook *nt, int *chMax) {
+void VersificationMgr::registerVersificationSystem(const char *name, const sbook *ot, const sbook *nt, int *chMax) {
p->systems[name] = name;
System &s = p->systems[name];
s.loadFromSBook(ot, nt, chMax);
}
-void VerseMgr::registerVersificationSystem(const char *name, const TreeKey *tk) {
+void VersificationMgr::registerVersificationSystem(const char *name, const TreeKey *tk) {
}
-const StringList VerseMgr::getVersificationSystems() const {
+const StringList VersificationMgr::getVersificationSystems() const {
StringList retVal;
for (map<SWBuf, System>::const_iterator it = p->systems.begin(); it != p->systems.end(); it++) {
retVal.push_back(it->first);
@@ -381,3 +393,4 @@ const StringList VerseMgr::getVersificationSystems() const {
SWORD_NAMESPACE_END
+