[sword-svn] r2218 - in trunk: . include src/mgr utilities
scribe at crosswire.org
scribe at crosswire.org
Tue Dec 23 02:33:39 MST 2008
Author: scribe
Date: 2008-12-23 02:33:38 -0700 (Tue, 23 Dec 2008)
New Revision: 2218
Modified:
trunk/ChangeLog
trunk/include/installmgr.h
trunk/include/swbuf.h
trunk/src/mgr/installmgr.cpp
trunk/src/mgr/swconfig.cpp
trunk/utilities/installmgr.cpp
Log:
Added ignore of comment lines starting with '#'
in SWConfig processing
Added requirement to call setUserDisclaimerConfirmed
in InstallMgr before remote functions operate
Added refreshRemoteSourceConfiguration to sync a
local InstallMgr.conf with a master remote list
Added ability for InstallMgr to use username/passwd
supplied by either .conf or globally in c-tor
Added VerseMgr to abstract versification scheme
functionality
Included 1 versification scheme: KJV
Added param on SWBuf::stripPrefix to allow use more
like a safe string tokenizer to replace strtok
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2008-12-17 03:22:02 UTC (rev 2217)
+++ trunk/ChangeLog 2008-12-23 09:33:38 UTC (rev 2218)
@@ -1,11 +1,28 @@
API ChangeLog
+23-Dec-2008 Troy A. Griffitts <scribe at crosswire.org>
+ Added ignore of comment lines starting with '#'
+ in SWConfig processing
+ Added requirement to call setUserDisclaimerConfirmed
+ in InstallMgr before remote functions operate
+ Added refreshRemoteSourceConfiguration to sync a
+ local InstallMgr.conf with a master remote list
+ Added ability for InstallMgr to use username/passwd
+ supplied by either .conf or globally in c-tor
+ Added VerseMgr to abstract versification scheme
+ functionality
+ Included 1 versification scheme: KJV
+ Added param on SWBuf::stripPrefix to allow use more
+ like a safe string tokenizer to replace strtok
+
+
16-Dec-2008 Joachim A. <jansorg at crosswire.org>
- Added two Chinese bookname translations provided by F. Lee
+ Added two Chinese bookname translations provided by
+ F. Lee
03-Sep-2008 Troy A. Griffitts <scribe at crosswire.org>
- Added getOSISRefRangeText to SWKey. Not yetimplemented
- ideally or even correctly for all SWKey types.
+ Added getOSISRefRangeText to SWKey- not yetimplemented
+ ideally or even correctly for all SWKey types
* Release 1.5.11 *
Modified: trunk/include/installmgr.h
===================================================================
--- trunk/include/installmgr.h 2008-12-17 03:22:02 UTC (rev 2217)
+++ trunk/include/installmgr.h 2008-12-23 09:33:38 UTC (rev 2218)
@@ -22,13 +22,14 @@
InstallSource(const char *type, const char *confEnt = 0);
virtual ~InstallSource();
SWBuf getConfEnt() {
- return caption +"|" + source + "|" + directory + "|" + u + "|" + p;
+ return caption +"|" + source + "|" + directory + "|" + u + "|" + p + "|" + uid;
}
SWBuf caption;
SWBuf source;
SWBuf directory;
SWBuf u;
SWBuf p;
+ SWBuf uid;
SWBuf type;
SWBuf localShadow;
@@ -47,6 +48,7 @@
bool userDisclaimerConfirmed;
std::set<SWBuf> defaultMods;
char *privatePath;
+ SWBuf confPath;
StatusReporter *statusReporter;
bool passive;
SWBuf u, p;
@@ -71,9 +73,22 @@
InstallSourceMap sources;
bool term;
+ // Username and Password supplied here can be used to identify your frontend
+ // by supplying a valid anon password like installmgr at macsword.com
+ // This will get overridden if a password is required and provided in an indivual
+ // source configuration
InstallMgr(const char *privatePath = "./", StatusReporter *statusReporter = 0, SWBuf u="ftp", SWBuf p="installmgr at user.com");
virtual ~InstallMgr();
+ // Call to re-read InstallMgr.conf
+ void readInstallConf();
+
+ // Call to dump sources and other settings to InstallMgr.conf
+ void saveInstallConf();
+
+ // Removes all configured sources from memory. Call saveInstallConf() to persist
+ void clearSources();
+
virtual int removeModule(SWMgr *manager, const char *modName);
virtual int ftpCopy(InstallSource *is, const char *src, const char *dest, bool dirTransfer = false, const char *suffix = "");
virtual int installModule(SWMgr *destMgr, const char *fromLocation, const char *modName, InstallSource *is = 0);
@@ -107,6 +122,7 @@
void setUserDisclaimerConfirmed(bool val) { userDisclaimerConfirmed = val; }
virtual bool getCipherCode(const char *modName, SWConfig *config);
void setFTPPassive(bool passive) { this->passive = passive; }
+ bool isFTPPassive() { return passive; }
void terminate();
/************************************************************************
Modified: trunk/include/swbuf.h
===================================================================
--- trunk/include/swbuf.h 2008-12-17 03:22:02 UTC (rev 2217)
+++ trunk/include/swbuf.h 2008-12-23 09:33:38 UTC (rev 2218)
@@ -373,9 +373,14 @@
* Strip a prefix from this buffer up to a separator byte.
* Returns the prefix and modifies this buffer, shifting left to remove prefix
* @param separator to use (e.g. ':')
+ * @param endOfStringAsSeparator - also count end of string as separator.
+ * this is useful for tokenizing entire string like:
+ * x|y|z
+ * if true it will also include 'z'.
+ *
* @return prefix if separator character found; otherwise, null and leaves buffer unmodified
*/
- inline const char *stripPrefix(char separator) { const char *m = strchr(buf, separator); if (m) { int len = m-buf; char *hold = new char[len]; memcpy(hold, buf, len); *this << (len+1); memcpy(end+1, hold, len); delete [] hold; end[len+1] = 0; } return (m) ? end+1 : 0; } // safe. we know we don't actually realloc and shrink buffer when shifting, so we can place our return val at end.
+ inline const char *stripPrefix(char separator, bool endOfStringAsSeparator = false) { const char *m = strchr(buf, separator); if (!m && endOfStringAsSeparator) { if (*buf) { operator >>(1); *buf=0; end = buf; return buf + 1;} else return buf; } if (m) { int len = m-buf; char *hold = new char[len]; memcpy(hold, buf, len); *this << (len+1); memcpy(end+1, hold, len); delete [] hold; end[len+1] = 0; } return (m) ? end+1 : 0; } // safe. we know we don't actually realloc and shrink buffer when shifting, so we can place our return val at end.
// this could be nicer, like replacing a contiguous series of target bytes with single replacement; offering replacement const char *
/**
Modified: trunk/src/mgr/installmgr.cpp
===================================================================
--- trunk/src/mgr/installmgr.cpp 2008-12-17 03:22:02 UTC (rev 2217)
+++ trunk/src/mgr/installmgr.cpp 2008-12-23 09:33:38 UTC (rev 2218)
@@ -71,7 +71,6 @@
-
InstallMgr::InstallMgr(const char *privatePath, StatusReporter *sr, SWBuf u, SWBuf p) {
userDisclaimerConfirmed = false;
statusReporter = sr;
@@ -79,6 +78,7 @@
this->p = p;
this->privatePath = 0;
this->transport = 0;
+ installConf = 0;
stdstr(&(this->privatePath), privatePath);
if (this->privatePath) {
int len = strlen(this->privatePath);
@@ -86,24 +86,44 @@
|| (this->privatePath[len-1] == '\\'))
this->privatePath[len-1] = 0;
}
- SWBuf confPath = (SWBuf)privatePath + "/InstallMgr.conf";
+ confPath = (SWBuf)privatePath + "/InstallMgr.conf";
FileMgr::createParent(confPath.c_str());
+ readInstallConf();
+}
+
+
+InstallMgr::~InstallMgr() {
+ delete [] privatePath;
+ delete installConf;
+
+}
+
+void InstallMgr::clearSources() {
+ for (InstallSourceMap::iterator it = sources.begin(); it != sources.end(); ++it) {
+ delete it->second;
+ }
+ sources.clear();
+}
+
+void InstallMgr::readInstallConf() {
+
+ if (installConf) delete installConf;
+
installConf = new SWConfig(confPath.c_str());
- SectionMap::iterator sourcesSection;
+ clearSources();
+
+ setFTPPassive(stricmp((*installConf)["General"]["PassiveFTP"].c_str(), "false") != 0);
+
+ SectionMap::iterator confSection = installConf->Sections.find("Sources");
ConfigEntMap::iterator sourceBegin;
ConfigEntMap::iterator sourceEnd;
- sources.clear();
-
- setFTPPassive(stricmp((*installConf)["General"]["PassiveFTP"].c_str(), "false")!=0);
+ if (confSection != installConf->Sections.end()) {
+ sourceBegin = confSection->second.lower_bound("FTPSource");
+ sourceEnd = confSection->second.upper_bound("FTPSource");
- sourcesSection = installConf->Sections.find("Sources");
- if (sourcesSection != installConf->Sections.end()) {
- sourceBegin = sourcesSection->second.lower_bound("FTPSource");
- sourceEnd = sourcesSection->second.upper_bound("FTPSource");
-
while (sourceBegin != sourceEnd) {
InstallSource *is = new InstallSource("FTP", sourceBegin->second.c_str());
sources[is->caption] = is;
@@ -115,10 +135,10 @@
}
defaultMods.clear();
- sourcesSection = installConf->Sections.find("General");
- if (sourcesSection != installConf->Sections.end()) {
- sourceBegin = sourcesSection->second.lower_bound("DefaultMod");
- sourceEnd = sourcesSection->second.upper_bound("DefaultMod");
+ confSection = installConf->Sections.find("General");
+ if (confSection != installConf->Sections.end()) {
+ sourceBegin = confSection->second.lower_bound("DefaultMod");
+ sourceEnd = confSection->second.upper_bound("DefaultMod");
while (sourceBegin != sourceEnd) {
defaultMods.insert(sourceBegin->second.c_str());
@@ -128,18 +148,24 @@
}
-InstallMgr::~InstallMgr() {
- delete [] privatePath;
- delete installConf;
+void InstallMgr::saveInstallConf() {
+ installConf->Sections["Sources"].erase("FTPSource");
+
for (InstallSourceMap::iterator it = sources.begin(); it != sources.end(); ++it) {
- delete it->second;
+ if (it->second) {
+ installConf->Sections["Sources"].insert(ConfigEntMap::value_type("FTPSource", it->second->getConfEnt().c_str()));
+ }
}
+ (*installConf)["General"]["PassiveFTP"] = (isFTPPassive()) ? "true" : "false";
+
+ installConf->Save();
}
void InstallMgr::terminate() { if (transport) transport->terminate(); }
+
int InstallMgr::removeModule(SWMgr *manager, const char *moduleName) {
SectionMap::iterator module;
ConfigEntMap::iterator fileBegin;
@@ -207,6 +233,10 @@
int InstallMgr::ftpCopy(InstallSource *is, const char *src, const char *dest, bool dirTransfer, const char *suffix) {
+
+ // assert user disclaimer has been confirmed
+ if (!isUserDisclaimerConfirmed()) return -1;
+
int retVal = 0;
FTPTransport *trans = createFTPTransport(is->source, statusReporter);
transport = trans; // set classwide current transport for other thread terminate() call
@@ -465,6 +495,10 @@
int InstallMgr::refreshRemoteSource(InstallSource *is) {
+
+ // assert user disclaimer has been confirmed
+ if (!isUserDisclaimerConfirmed()) return -1;
+
SWBuf root = (SWBuf)privatePath + (SWBuf)"/" + is->source.c_str();
removeTrailingSlash(root);
SWBuf target = root + "/mods.d";
@@ -555,32 +589,71 @@
* sources and integrate it with our configurations.
*/
int InstallMgr::refreshRemoteSourceConfiguration() {
- // TODO: something
- // well a litte more specific:
- // add hash YYYYMMDDHHMMSSUU to each entry and use this
- // for dir name
- // master list should be commands like:
- // YYYYMMDDHHMMSSUU=delete
- // YYYYMMDDHHMMSSUU=FTPSource=...
- // YYYYMMDDHHMMSSUU=delete
- //
- SWBuf root = (SWBuf)privatePath+"/"+masterRepoList;
+
+ // assert user disclaimer has been confirmed
+ if (!isUserDisclaimerConfirmed()) return -1;
+
+ SWBuf root = (SWBuf)privatePath;
removeTrailingSlash(root);
+ SWBuf masterRepoListPath = root + "/" + masterRepoList;
InstallSource is("FTP");
is.source = "ftp.crosswire.org";
is.directory = "/pub/sword";
- int errorCode = ftpCopy(&is, masterRepoList, root.c_str(), false);
+ int errorCode = ftpCopy(&is, masterRepoList, masterRepoListPath.c_str(), false);
if (!errorCode) { //sucessfully downloaded the repo list
- SWConfig masterList(masterRepoList);
+ SWConfig masterList(masterRepoListPath);
SectionMap::iterator sections = masterList.Sections.find("Repos");
if (sections != masterList.Sections.end()) {
for (ConfigEntMap::iterator actions = sections->second.begin(); actions != sections->second.end(); actions++) {
- std::cout << "UID: " << actions->first << " ; data: " << actions->second << std::endl;
+ // Search through our current sources and see if we have a matching UID
+ InstallSourceMap::iterator it;
+ for (it = sources.begin(); it != sources.end(); ++it) {
+ // is this our UID?
+ if ((it->second) && (it->second->uid == actions->first)) {
+ if (actions->second == "REMOVE") {
+ // be sure to call save/reload after this
+ // or this could be dangerous
+ delete it->second;
+ it->second = 0;
+ }
+ else {
+ SWBuf key = actions->second.stripPrefix('=');
+ if (key == "FTPSource") {
+ // we might consider instantiating a temp IS
+ // from our config string and then copy only
+ // some entries. This would allow the use to
+ // change some fields and not have them overwritten
+ // but it seems like we might want to change any
+ // of the current fields so we don't do this now
+ // InstallSource i("FTP", actions->second);
+ delete it->second;
+ it->second = new InstallSource("FTP", actions->second.c_str());
+ it->second->uid = actions->first;
+ }
+ }
+ break;
+ }
+ }
+ // didn't find our UID, let's add it
+ if (it == sources.end()) {
+ SWBuf key = actions->second.stripPrefix('=');
+ if (key == "FTPSource") {
+ if (actions->second != "REMOVE") {
+ InstallSource *is = new InstallSource("FTP", actions->second.c_str());
+ is->uid = actions->first;
+ sources[is->caption] = is;
+ }
+ }
+ }
}
+
+ // persist and re-read
+ saveInstallConf();
+ readInstallConf();
+
return 0;
}
}
-
return -1;
}
@@ -590,16 +663,15 @@
mgr = 0;
userData = 0;
if (confEnt) {
- char *buf = 0;
- stdstr(&buf, confEnt);
+ SWBuf buf = confEnt;
+ caption = buf.stripPrefix('|', true);
+ source = buf.stripPrefix('|', true);
+ directory = buf.stripPrefix('|', true);
+ u = buf.stripPrefix('|', true);
+ p = buf.stripPrefix('|', true);
+ uid = buf.stripPrefix('|', true);
- caption = strtok(buf, "|");
- source = strtok(0, "|");
- directory = strtok(0, "|");
removeTrailingSlash(directory);
- u = strtok(0, "|");
- p = strtok(0, "|");
- delete [] buf;
}
}
Modified: trunk/src/mgr/swconfig.cpp
===================================================================
--- trunk/src/mgr/swconfig.cpp 2008-12-17 03:22:02 UTC (rev 2217)
+++ trunk/src/mgr/swconfig.cpp 2008-12-23 09:33:38 UTC (rev 2218)
@@ -66,27 +66,30 @@
}
while (goodLine) {
- buf = new char [ line.length() + 1 ];
- strcpy(buf, line.c_str());
- if (*strstrip(buf) == '[') {
- if (!first)
- Sections.insert(SectionMap::value_type(sectname, cursect));
- else first = false;
-
- cursect.erase(cursect.begin(), cursect.end());
+ // ignore commented lines
+ if (!line.startsWith("#")) {
+ buf = new char [ line.length() + 1 ];
+ strcpy(buf, line.c_str());
+ if (*strstrip(buf) == '[') {
+ if (!first)
+ Sections.insert(SectionMap::value_type(sectname, cursect));
+ else first = false;
+
+ cursect.erase(cursect.begin(), cursect.end());
- strtok(buf, "]");
- sectname = buf+1;
- }
- else {
- strtok(buf, "=");
- if ((*buf) && (*buf != '=')) {
- if ((data = strtok(NULL, "")))
- cursect.insert(ConfigEntMap::value_type(buf, strstrip(data)));
- else cursect.insert(ConfigEntMap::value_type(buf, ""));
+ strtok(buf, "]");
+ sectname = buf+1;
}
+ else {
+ strtok(buf, "=");
+ if ((*buf) && (*buf != '=')) {
+ if ((data = strtok(NULL, "")))
+ cursect.insert(ConfigEntMap::value_type(buf, strstrip(data)));
+ else cursect.insert(ConfigEntMap::value_type(buf, ""));
+ }
+ }
+ delete [] buf;
}
- delete [] buf;
goodLine = FileMgr::getLine(cfile, line);
}
if (!first)
Modified: trunk/utilities/installmgr.cpp
===================================================================
--- trunk/utilities/installmgr.cpp 2008-12-17 03:22:02 UTC (rev 2217)
+++ trunk/utilities/installmgr.cpp 2008-12-23 09:33:38 UTC (rev 2218)
@@ -30,7 +30,7 @@
}
-// clean up and exit is status is 0 or negative error code
+// clean up and exit if status is 0 or negative error code
void finish(int status) {
delete installMgr;
delete mgr;
@@ -84,7 +84,7 @@
}
-void createBasicConfig(bool enableRemote) {
+void createBasicConfig(bool enableRemote, bool addCrossWire) {
FileMgr::createParent(confPath.c_str());
remove(confPath.c_str());
@@ -106,7 +106,7 @@
bool enable = showDisclaimer();
- createBasicConfig(enable);
+ createBasicConfig(enable, true);
cout << "\n\nInitialized basic config file at [" << confPath << "]\n";
cout << "with remote source features " << ((enable) ? "ENABLED" : "DISABLED") << "\n";
@@ -121,7 +121,7 @@
}
if (!FileMgr::existsFile(confPath.c_str())) {
- createBasicConfig(true);
+ createBasicConfig(true, false);
finish(1); // cleanup and don't exit
init(); // re-init with InstallMgr which uses our new config
}
@@ -161,9 +161,9 @@
cout << "Remote Sources:\n\n";
for (InstallSourceMap::iterator it = installMgr->sources.begin(); it != installMgr->sources.end(); it++) {
cout << "[" << it->second->caption << "]\n";
- cout << "\tType ; " << it->second->type << "\n";
- cout << "\tSource ; " << it->second->source << "\n";
- cout << "\tDirectory; " << it->second->directory << "\n";
+ cout << "\tType : " << it->second->type << "\n";
+ cout << "\tSource : " << it->second->source << "\n";
+ cout << "\tDirectory: " << it->second->directory << "\n";
}
}
@@ -304,7 +304,7 @@
case 0: // -s list sources
listRemoteSources();
break;
- case 'c': // -rl remote list
+ case 'c': // -sc sync config with master
syncConfig();
break;
}
More information about the sword-cvs
mailing list