The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InstallMgr Class Reference

#include <installmgr.h>

+ Inheritance diagram for InstallMgr:
+ Collaboration diagram for InstallMgr:

Public Member Functions

void clearSources ()
 
virtual bool getCipherCode (const char *modName, SWConfig *config)
 
long getTimeoutMillis ()
 
 InstallMgr (const char *privatePath="./", StatusReporter *statusReporter=0, SWBuf u="ftp", SWBuf p="installmgr@user.com")
 
virtual int installModule (SWMgr *destMgr, const char *fromLocation, const char *modName, InstallSource *is=0)
 
bool isDefaultModule (const char *modName)
 
bool isFTPPassive ()
 
bool isUnverifiedPeerAllowed ()
 
virtual bool isUserDisclaimerConfirmed () const
 
void readInstallConf ()
 
virtual int refreshRemoteSource (InstallSource *is)
 
virtual int refreshRemoteSourceConfiguration ()
 
virtual int remoteCopy (InstallSource *is, const char *src, const char *dest, bool dirTransfer=false, const char *suffix="")
 
virtual int removeModule (SWMgr *manager, const char *modName)
 
void saveInstallConf ()
 
void setFTPPassive (bool passive)
 
void setTimeoutMillis (long timeoutMillis)
 
void setUnverifiedPeerAllowed (bool allowed)
 
void setUserDisclaimerConfirmed (bool val)
 
void terminate ()
 
virtual ~InstallMgr ()
 

Static Public Member Functions

static std::map< SWModule *, int > getModuleStatus (const SWMgr &base, const SWMgr &other, bool utilModules=false)
 

Public Attributes

SWConfiginstallConf
 
InstallSourceMap sources
 

Static Public Attributes

static const unsigned int MODSTAT_CIPHERED = 0x010
 
static const unsigned int MODSTAT_CIPHERKEYPRESENT = 0x020
 
static const unsigned int MODSTAT_NEW = 0x008
 
static const unsigned int MODSTAT_OLDER = 0x001
 
static const unsigned int MODSTAT_SAMEVERSION = 0x002
 
static const unsigned int MODSTAT_UPDATED = 0x004
 
static bool userDisclaimerConfirmed = false
 

Protected Member Functions

virtual RemoteTransportcreateFTPTransport (const char *host, StatusReporter *statusReporter)
 
virtual RemoteTransportcreateHTTPTransport (const char *host, StatusReporter *statusReporter)
 

Protected Attributes

SWBuf confPath
 
std::set< SWBufdefaultMods
 
SWBuf p
 
bool passive
 
char * privatePath
 
StatusReporterstatusReporter
 
long timeoutMillis
 
RemoteTransporttransport
 
SWBuf u
 
bool unverifiedPeerAllowed
 

Detailed Description

Class to handle installation and maintenance of a SWORD library of books.

Definition at line 70 of file installmgr.h.

Constructor & Destructor Documentation

InstallMgr::InstallMgr ( const char *  privatePath = "./",
StatusReporter statusReporter = 0,
SWBuf  u = "ftp",
SWBuf  p = "installmgr@user.com" 
)

Username and Password supplied here can be used to identify your frontend by supplying a valid anon password like insta.nosp@m.llmg.nosp@m.r@mac.nosp@m.swor.nosp@m.d.com This will get overridden if a password is required and provided in an indivual source configuration.

Definition at line 99 of file installmgr.cpp.

99  {
100  passive = true;
101  timeoutMillis = 10000;
102  unverifiedPeerAllowed = true;
103  statusReporter = sr;
104  this->u = u;
105  this->p = p;
106  this->privatePath = 0;
107  this->transport = 0;
108  installConf = 0;
109  stdstr(&(this->privatePath), privatePath);
110  if (this->privatePath) {
111  int len = (int)strlen(this->privatePath);
112  if ((this->privatePath[len-1] == '/')
113  || (this->privatePath[len-1] == '\\'))
114  this->privatePath[len-1] = 0;
115  }
116  confPath = (SWBuf)privatePath + "/InstallMgr.conf";
118 
119  readInstallConf();
120 }
bool unverifiedPeerAllowed
Definition: installmgr.h:80
Definition: swbuf.h:47
char * privatePath
Definition: installmgr.h:74
SWBuf p
Definition: installmgr.h:79
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
const char * c_str() const
Definition: swbuf.h:158
void readInstallConf()
Definition: installmgr.cpp:138
SWBuf u
Definition: installmgr.h:79
static int createParent(const char *pName)
Definition: filemgr.cpp:426
bool passive
Definition: installmgr.h:77
SWBuf confPath
Definition: installmgr.h:75
long timeoutMillis
Definition: installmgr.h:78
SWConfig * installConf
Definition: installmgr.h:106
RemoteTransport * transport
Definition: installmgr.h:94
InstallMgr::~InstallMgr ( )
virtual

Definition at line 123 of file installmgr.cpp.

123  {
124  delete [] privatePath;
125  delete installConf;
126  clearSources();
127 }
void clearSources()
Definition: installmgr.cpp:130
char * privatePath
Definition: installmgr.h:74
SWConfig * installConf
Definition: installmgr.h:106

Member Function Documentation

void InstallMgr::clearSources ( )

Removes all configured sources from memory. Call saveInstallConf() to persist

Definition at line 130 of file installmgr.cpp.

130  {
131  for (InstallSourceMap::iterator it = sources.begin(); it != sources.end(); ++it) {
132  delete it->second;
133  }
134  sources.clear();
135 }
InstallSourceMap sources
Definition: installmgr.h:111
RemoteTransport * InstallMgr::createFTPTransport ( const char *  host,
StatusReporter statusReporter 
)
protectedvirtual

override this method and provide your own custom RemoteTransport subclass

Definition at line 81 of file installmgr.cpp.

81  {
82 #ifdef CURLAVAILABLE
83  return new CURLFTPTransport(host, statusReporter);
84 #else
85  return new FTPLibFTPTransport(host, statusReporter);
86 #endif
87 }
RemoteTransport * InstallMgr::createHTTPTransport ( const char *  host,
StatusReporter statusReporter 
)
protectedvirtual

override this method and provide your own custom HTTP RemoteTransport

Definition at line 90 of file installmgr.cpp.

90  {
91 #ifdef CURLAVAILABLE
92  return new CURLHTTPTransport(host, statusReporter);
93 #else
94  return 0;
95 #endif
96 }
virtual bool InstallMgr::getCipherCode ( const char *  modName,
SWConfig config 
)
inlinevirtual

override this and provide an input mechanism to allow your users to enter the decipher code for a module. return true you added the cipher code to the config. default to return 'aborted'

Definition at line 222 of file installmgr.h.

222  {
223  (void) modName; (void) config; // to avoid "unused variable" warnings
224  return false;
225 
226  /*
227  A sample implementation, roughly taken from the windows installmgr:
228 
229  SectionMap::iterator section;
230  ConfigEntMap::iterator entry;
231  SWBuf tmpBuf;
232  section = config->Sections.find(modName);
233  if (section != config->Sections.end()) {
234  entry = section->second.find("CipherKey");
235  if (entry != section->second.end()) {
236  entry->second = ASK_USER_FOR_CIPHER_CODE();
237  config->Save();
238 
239  // LET'S SHOW THE USER SOME SAMPLE TEXT FROM THE MODULE
240  SWMgr *mgr = new SWMgr();
241  SWModule *mod = mgr->getModule(modName);
242  mod->setKey("Ipet 2:12");
243  tmpBuf = mod->StripText();
244  mod->setKey("gen 1:10");
245  tmpBuf += "\n\n";
246  tmpBuf += mod->StripText();
247  if (SOME_DIALOG_CONFIRMATION(SWBuf(
248  "Using your provided cipher code, \
249  here is the data from the module. \
250  Does this look good?\n\n") + tmpBuf.c_str())) {
251 
252  // if USER CLICKS OK means we should return true
253  return true;
254  }
255  delete mgr;
256  }
257  }
258  return false;
259  */
260  }
map< SWModule *, int > InstallMgr::getModuleStatus ( const SWMgr base,
const SWMgr other,
bool  utilModules = false 
)
static

Definition at line 592 of file installmgr.cpp.

592  {
593  map<SWModule *, int> retVal;
594  SWBuf targetVersion;
595  SWBuf sourceVersion;
596  SWBuf softwareVersion;
597  bool cipher;
598  bool keyPresent;
599  int modStat;
600 
601  for (ModMap::const_iterator mod = (!utilModules ? other.getModules().begin() : other.getUtilModules().begin()); mod != (!utilModules ? other.getModules().end() : other.getUtilModules().end()); ++mod) {
602 
603  modStat = 0;
604 
605  cipher = false;
606  keyPresent = false;
607 
608  const char *v = mod->second->getConfigEntry("CipherKey");
609  if (v) {
610  cipher = true;
611  keyPresent = *v;
612  }
613 
614  targetVersion = "0.0";
615  sourceVersion = "1.0";
616  softwareVersion = (const char *)SWVersion::currentVersion;
617 
618  v = mod->second->getConfigEntry("Version");
619  if (v) sourceVersion = v;
620 
621  v = mod->second->getConfigEntry("MinimumVersion");
622  if (v) softwareVersion = v;
623 
624  const SWModule *baseMod = base.getModule(mod->first);
625  if (baseMod) {
626  targetVersion = "1.0";
627  v = baseMod->getConfigEntry("Version");
628  if (v) targetVersion = v;
629  modStat |= (SWVersion(sourceVersion.c_str()) > SWVersion(targetVersion.c_str())) ? MODSTAT_UPDATED : (SWVersion(sourceVersion.c_str()) < SWVersion(targetVersion.c_str())) ? MODSTAT_OLDER : MODSTAT_SAMEVERSION;
630  }
631  else modStat |= MODSTAT_NEW;
632 
633  if (cipher) modStat |= MODSTAT_CIPHERED;
634  if (keyPresent) modStat |= MODSTAT_CIPHERKEYPRESENT;
635  retVal[mod->second] = modStat;
636  }
637  return retVal;
638 }
Definition: swbuf.h:47
static const unsigned int MODSTAT_OLDER
Definition: installmgr.h:99
static const unsigned int MODSTAT_CIPHERKEYPRESENT
Definition: installmgr.h:104
virtual const char * getConfigEntry(const char *key) const
Definition: swmodule.cpp:1159
ModMap & getModules()
Definition: swmgr.cpp:1574
ModMap & getUtilModules()
Definition: swmgr.cpp:1575
static const unsigned int MODSTAT_NEW
Definition: installmgr.h:102
SWModule * getModule(const char *modName)
Definition: swmgr.h:360
const char * c_str() const
Definition: swbuf.h:158
static const unsigned int MODSTAT_CIPHERED
Definition: installmgr.h:103
static SWVersion currentVersion
Definition: swversion.h:69
static const unsigned int MODSTAT_UPDATED
Definition: installmgr.h:101
static const unsigned int MODSTAT_SAMEVERSION
Definition: installmgr.h:100
long InstallMgr::getTimeoutMillis ( )
inline

Definition at line 270 of file installmgr.h.

270 { return timeoutMillis; }
long timeoutMillis
Definition: installmgr.h:78
int InstallMgr::installModule ( SWMgr destMgr,
const char *  fromLocation,
const char *  modName,
InstallSource is = 0 
)
virtual

call to install a module from a local path (fromLocation) or remote InstallSource (is) (leave the other 0)

Definition at line 394 of file installmgr.cpp.

394  {
395  int retVal = 0;
396  SectionMap::iterator module, section;
397  ConfigEntMap::iterator fileBegin;
398  ConfigEntMap::iterator fileEnd;
399  ConfigEntMap::iterator entry;
400  SWBuf sourceDir;
401  SWBuf buffer;
402  bool aborted = false;
403  bool cipher = false;
404  SWBuf modFile;
405 
406 SWLOGD("***** InstallMgr::installModule\n");
407  if (fromLocation) {
408 SWLOGD("***** fromLocation: %s \n", fromLocation);
409  }
410 SWLOGD("***** modName: %s \n", modName);
411 
412  if (is)
413  sourceDir = (SWBuf)privatePath + "/" + is->uid;
414  else sourceDir = fromLocation;
415 
416  removeTrailingSlash(sourceDir);
417  sourceDir += '/';
418 
419  SWMgr mgr(sourceDir.c_str());
420 
421  module = mgr.config->getSections().find(modName);
422 
423  if (module != mgr.config->getSections().end()) {
424 
425  entry = module->second.find("CipherKey");
426  if (entry != module->second.end())
427  cipher = true;
428 
429  //
430  // This first check is a method to allow a module to specify each
431  // file that needs to be copied
432  //
433  fileEnd = module->second.upper_bound("File");
434  fileBegin = module->second.lower_bound("File");
435 
436  if (fileBegin != fileEnd) { // copy each file
437  if (is) {
438  while (fileBegin != fileEnd) { // netCopy each file first
439  buffer = sourceDir + fileBegin->second.c_str();
440  if (remoteCopy(is, fileBegin->second.c_str(), buffer.c_str())) {
441  aborted = true;
442  break; // user aborted
443  }
444  fileBegin++;
445  }
446  fileBegin = module->second.lower_bound("File");
447  }
448 
449  if (!aborted) {
450  // DO THE INSTALL
451  while (fileBegin != fileEnd && !retVal) {
452  SWBuf sourcePath = sourceDir;
453  sourcePath += fileBegin->second.c_str();
454  SWBuf dest = destMgr->prefixPath;
455  removeTrailingSlash(dest);
456  dest += '/';
457  dest += fileBegin->second.c_str();
458  retVal = FileMgr::copyFile(sourcePath.c_str(), dest.c_str());
459 
460  fileBegin++;
461  }
462  }
463  //---------------
464 
465  if (is) {
466  fileBegin = module->second.lower_bound("File");
467  while (fileBegin != fileEnd) { // delete each tmp netCopied file
468  buffer = sourceDir + fileBegin->second.c_str();
469  FileMgr::removeFile(buffer.c_str());
470  fileBegin++;
471  }
472  }
473  }
474 
475  // This is the REAL install code, the above code I don't think has
476  // ever been used
477  //
478  // Copy all files in DataPath directory
479  //
480  else {
481  ConfigEntMap::iterator entry;
482 
483  entry = module->second.find("AbsoluteDataPath");
484  if (entry != module->second.end()) {
485  SWBuf absolutePath = entry->second.c_str();
486  SWBuf relativePath = absolutePath;
487  entry = module->second.find("PrefixPath");
488  if (entry != module->second.end()) {
489  relativePath << strlen(entry->second.c_str());
490  }
491  else {
492  relativePath << strlen(mgr.prefixPath);
493  }
494 SWLOGD("***** mgr.prefixPath: %s \n", mgr.prefixPath);
495 SWLOGD("***** destMgr->prefixPath: %s \n", destMgr->prefixPath);
496 SWLOGD("***** absolutePath: %s \n", absolutePath.c_str());
497 SWLOGD("***** relativePath: %s \n", relativePath.c_str());
498 
499  if (is) {
500  if (remoteCopy(is, relativePath.c_str(), absolutePath.c_str(), true)) {
501  aborted = true; // user aborted
502  }
503  }
504  if (!aborted) {
505  SWBuf destPath = (SWBuf)destMgr->prefixPath + relativePath;
506  retVal = FileMgr::copyDir(absolutePath.c_str(), destPath.c_str());
507  }
508  if (is) { // delete tmp netCopied files
509 // mgr->deleteModule(modName);
510  FileMgr::removeDir(absolutePath.c_str());
511  }
512  }
513  }
514  if (!aborted) {
515  SWBuf confDir = sourceDir + "mods.d/";
516  std::vector<DirEntry> dirList = FileMgr::getDirList(confDir);
517  for (unsigned int i = 0; i < dirList.size() && !retVal; ++i) {
518  if (dirList[i].name.endsWith(".conf")) {
519  modFile = confDir;
520  modFile += dirList[i].name;
521  SWConfig *config = new SWConfig(modFile);
522  if (config->getSections().find(modName) != config->getSections().end()) {
523  SWBuf targetFile = destMgr->configPath; //"./mods.d/";
524  removeTrailingSlash(targetFile);
525  targetFile += "/";
526  targetFile += dirList[i].name;
527  retVal = FileMgr::copyFile(modFile.c_str(), targetFile.c_str());
528  if (cipher) {
529  if (getCipherCode(modName, config)) {
530  SWMgr newDest(destMgr->prefixPath);
531  removeModule(&newDest, modName);
532  aborted = true;
533  }
534  else {
535  config->save();
536  retVal = FileMgr::copyFile(modFile.c_str(), targetFile.c_str());
537  }
538  }
539  }
540  delete config;
541  }
542  }
543  }
544  return (aborted) ? -9 : retVal;
545  }
546  return 1;
547 }
Definition: swmgr.h:93
static int removeDir(const char *targetDir)
Definition: filemgr.cpp:639
Definition: swbuf.h:47
virtual SectionMap & getSections()
Definition: swconfig.cpp:186
char * privatePath
Definition: installmgr.h:74
SWText * module
Definition: osis2mod.cpp:105
char * prefixPath
Definition: swmgr.h:312
preg buffer
Definition: regex.c:8089
SWConfig * config
Definition: swmgr.h:302
const char * c_str() const
Definition: swbuf.h:158
static int removeFile(const char *fName)
Definition: filemgr.cpp:517
static int copyFile(const char *srcFile, const char *destFile)
Definition: filemgr.cpp:496
static void removeTrailingSlash(SWBuf &buf)
Definition: installmgr.cpp:57
static std::vector< struct DirEntry > getDirList(const char *dirPath, bool includeSize=false, bool includeIsDirectory=true)
Definition: filemgr.cpp:379
virtual int remoteCopy(InstallSource *is, const char *src, const char *dest, bool dirTransfer=false, const char *suffix="")
Definition: installmgr.cpp:300
static int copyDir(const char *srcDir, const char *destDir)
Definition: filemgr.cpp:618
#define SWLOGD(...)
Definition: defs.h:187
virtual int removeModule(SWMgr *manager, const char *modName)
Definition: installmgr.cpp:241
virtual bool getCipherCode(const char *modName, SWConfig *config)
Definition: installmgr.h:222
char * configPath
Definition: swmgr.h:316
SWMgr * mgr
Definition: installmgr.cpp:46
virtual void save() const
Definition: swconfig.cpp:115
bool InstallMgr::isDefaultModule ( const char *  modName)

Definition at line 583 of file installmgr.cpp.

583  {
584  return defaultMods.count(modName);
585 }
std::set< SWBuf > defaultMods
Definition: installmgr.h:73
bool InstallMgr::isFTPPassive ( )
inline

Definition at line 267 of file installmgr.h.

267 { return passive; }
bool passive
Definition: installmgr.h:77
bool InstallMgr::isUnverifiedPeerAllowed ( )
inline

Definition at line 273 of file installmgr.h.

273 { return unverifiedPeerAllowed; }
bool unverifiedPeerAllowed
Definition: installmgr.h:80
bool InstallMgr::isUserDisclaimerConfirmed ( ) const
virtual

Override this and provide an input mechanism to allow your users to confirm that they understand this important disclaimer. This method will be called immediately before attempting to perform any network function. If you would like your confirmation to always show at a predefined time before attempting network operations, then you can call this method yourself at the desired time.

Return true if your user confirms.

User disclaimer should ask user for confirmation of 2 critical items: and the default answer should be NO (due to possibly the wrong language for the disclaimer)

1) detection OK (Not in persecuted country) 2) repos other than CrossWire may have questionable content

A sample default impl is provided below:

Reimplemented in MyInstallMgr.

Definition at line 777 of file installmgr.cpp.

777  {
778 
780  std::cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
781  std::cout << " -=+* WARNING *+=- -=+* WARNING *+=-\n\n\n";
782  std::cout << "Although Install Manager provides a convenient way for installing\n";
783  std::cout << "and upgrading SWORD components, it also uses a systematic method\n";
784  std::cout << "for accessing sites which gives packet sniffers a target to lock\n";
785  std::cout << "into for singling out users. \n\n\n";
786  std::cout << "IF YOU LIVE IN A PERSECUTED COUNTRY AND DO NOT WISH TO RISK DETECTION,\n";
787  std::cout << "YOU SHOULD *NOT* USE INSTALL MANAGER'S REMOTE SOURCE FEATURES.\n\n\n";
788  std::cout << "Also, Remote Sources other than CrossWire may contain less than\n";
789  std::cout << "quality modules, modules with unorthodox content, or even modules\n";
790  std::cout << "which are not legitimately distributable. Many repositories\n";
791  std::cout << "contain wonderfully useful content. These repositories simply\n";
792  std::cout << "are not reviewed or maintained by CrossWire and CrossWire\n";
793  std::cout << "cannot be held responsible for their content. CAVEAT EMPTOR.\n\n\n";
794  std::cout << "If you understand this and are willing to enable remote source features\n";
795  std::cout << "then type yes at the prompt\n\n";
796  std::cout << "enable? [no] ";
797 
798  char prompt[10];
799  fgets(prompt, 9, stdin);
800  userDisclaimerConfirmed = (!strcmp(prompt, "yes\n"));
801  std::cout << "\n";
802  }
804 }
static bool userDisclaimerConfirmed
Definition: installmgr.h:98
void InstallMgr::readInstallConf ( )

Call to re-read InstallMgr.conf

Definition at line 138 of file installmgr.cpp.

138  {
139 
140  if (installConf) delete installConf;
141 
143 
144  clearSources();
145 
146  setFTPPassive(stricmp((*installConf)["General"]["PassiveFTP"].c_str(), "false") != 0);
147  long t = atol((*installConf)["General"]["TimeoutMillis"].c_str());
148  if (t > 0) setTimeoutMillis(t);
149  setUnverifiedPeerAllowed(stricmp((*installConf)["General"]["UnverifiedPeerAllowed"].c_str(), "false") != 0);
150 
151  SectionMap::iterator confSection = installConf->getSections().find("Sources");
152  ConfigEntMap::iterator sourceBegin;
153  ConfigEntMap::iterator sourceEnd;
154 
155  if (confSection != installConf->getSections().end()) {
156 
157  sourceBegin = confSection->second.lower_bound("FTPSource");
158  sourceEnd = confSection->second.upper_bound("FTPSource");
159 
160  while (sourceBegin != sourceEnd) {
161  InstallSource *is = new InstallSource("FTP", sourceBegin->second.c_str());
162  sources[is->caption] = is;
163  SWBuf parent = (SWBuf)privatePath + "/" + is->uid + "/file";
164  FileMgr::createParent(parent.c_str());
165  is->localShadow = (SWBuf)privatePath + "/" + is->uid;
166  sourceBegin++;
167  }
168 
169 #ifdef CURLSFTPAVAILABLE
170  sourceBegin = confSection->second.lower_bound("SFTPSource");
171  sourceEnd = confSection->second.upper_bound("SFTPSource");
172 
173  while (sourceBegin != sourceEnd) {
174  InstallSource *is = new InstallSource("SFTP", sourceBegin->second.c_str());
175  sources[is->caption] = is;
176  SWBuf parent = (SWBuf)privatePath + "/" + is->uid + "/file";
177  FileMgr::createParent(parent.c_str());
178  is->localShadow = (SWBuf)privatePath + "/" + is->uid;
179  sourceBegin++;
180  }
181 #endif // CURLSFTPAVAILABLE
182 
183  sourceBegin = confSection->second.lower_bound("HTTPSource");
184  sourceEnd = confSection->second.upper_bound("HTTPSource");
185 
186  while (sourceBegin != sourceEnd) {
187  InstallSource *is = new InstallSource("HTTP", sourceBegin->second.c_str());
188  sources[is->caption] = is;
189  SWBuf parent = (SWBuf)privatePath + "/" + is->uid + "/file";
190  FileMgr::createParent(parent.c_str());
191  is->localShadow = (SWBuf)privatePath + "/" + is->uid;
192  sourceBegin++;
193  }
194 
195  sourceBegin = confSection->second.lower_bound("HTTPSSource");
196  sourceEnd = confSection->second.upper_bound("HTTPSSource");
197 
198  while (sourceBegin != sourceEnd) {
199  InstallSource *is = new InstallSource("HTTPS", sourceBegin->second.c_str());
200  sources[is->caption] = is;
201  SWBuf parent = (SWBuf)privatePath + "/" + is->uid + "/file";
202  FileMgr::createParent(parent.c_str());
203  is->localShadow = (SWBuf)privatePath + "/" + is->uid;
204  sourceBegin++;
205  }
206  }
207 
208  defaultMods.clear();
209  confSection = installConf->getSections().find("General");
210  if (confSection != installConf->getSections().end()) {
211  sourceBegin = confSection->second.lower_bound("DefaultMod");
212  sourceEnd = confSection->second.upper_bound("DefaultMod");
213 
214  while (sourceBegin != sourceEnd) {
215  defaultMods.insert(sourceBegin->second.c_str());
216  sourceBegin++;
217  }
218  }
219 }
void clearSources()
Definition: installmgr.cpp:130
Definition: swbuf.h:47
virtual SectionMap & getSections()
Definition: swconfig.cpp:186
char * privatePath
Definition: installmgr.h:74
SWBuf caption
Definition: installmgr.h:50
int stricmp(const char *s1, const char *s2)
Definition: utilstr.cpp:194
void setUnverifiedPeerAllowed(bool allowed)
Definition: installmgr.h:272
void setTimeoutMillis(long timeoutMillis)
Definition: installmgr.h:269
const char * c_str() const
Definition: swbuf.h:158
void setFTPPassive(bool passive)
Definition: installmgr.h:266
std::set< SWBuf > defaultMods
Definition: installmgr.h:73
InstallSourceMap sources
Definition: installmgr.h:111
static int createParent(const char *pName)
Definition: filemgr.cpp:426
SWBuf confPath
Definition: installmgr.h:75
SWBuf localShadow
Definition: installmgr.h:58
SWConfig * installConf
Definition: installmgr.h:106
int InstallMgr::refreshRemoteSource ( InstallSource is)
virtual

call to obtain and locally cache the available content list of the remote source

Definition at line 550 of file installmgr.cpp.

550  {
551 
552  // assert user disclaimer has been confirmed
553  if (!isUserDisclaimerConfirmed()) return -1;
554 
555  SWBuf root = (SWBuf)privatePath + (SWBuf)"/" + is->uid.c_str();
556  removeTrailingSlash(root);
557  SWBuf target = root + "/mods.d";
558  int errorCode = -1; //0 means successful
559 
560  FileMgr::removeDir(target.c_str());
561 
562  if (!FileMgr::existsDir(target))
563  FileMgr::createPathAndFile(target+"/globals.conf");
564 
565 #ifndef EXCLUDEZLIB
566  SWBuf archive = root + "/mods.d.tar.gz";
567 
568  errorCode = remoteCopy(is, "mods.d.tar.gz", archive.c_str(), false);
569  if (!errorCode) { //sucessfully downloaded the tar,gz of module configs
570  int fd = FileMgr::openFileReadOnly(archive.c_str());
571  ZipCompress::unTarGZ(fd, root.c_str());
572  FileMgr::closeFile(fd);
573  }
574  else if (errorCode > -2) // don't try the next attempt on connection error or user requested termination
575 #endif
576  errorCode = remoteCopy(is, "mods.d", target.c_str(), true, ".conf"); //copy the whole directory
577 
578  is->flush();
579  return errorCode;
580 }
static char unTarGZ(int fd, const char *destPath)
Definition: zipcomprs.cpp:373
static int removeDir(const char *targetDir)
Definition: filemgr.cpp:639
Definition: swbuf.h:47
char * privatePath
Definition: installmgr.h:74
static signed char existsDir(const char *ipath, const char *idirName=0)
Definition: filemgr.cpp:357
static int openFileReadOnly(const char *fName)
Definition: filemgr.cpp:474
static void closeFile(int fd)
Definition: filemgr.cpp:491
const char * c_str() const
Definition: swbuf.h:158
static void removeTrailingSlash(SWBuf &buf)
Definition: installmgr.cpp:57
static int createPathAndFile(const char *fName)
Definition: filemgr.cpp:479
virtual int remoteCopy(InstallSource *is, const char *src, const char *dest, bool dirTransfer=false, const char *suffix="")
Definition: installmgr.cpp:300
virtual bool isUserDisclaimerConfirmed() const
Definition: installmgr.cpp:777
int InstallMgr::refreshRemoteSourceConfiguration ( )
virtual

call to populate installmgr configuration with all known remote sources from the master list at CrossWire

Definition at line 645 of file installmgr.cpp.

645  {
646 
647  // assert user disclaimer has been confirmed
648  if (!isUserDisclaimerConfirmed()) return -1;
649 
650  SWBuf root = (SWBuf)privatePath;
651  removeTrailingSlash(root);
652  SWBuf masterRepoListPath = root + "/" + masterRepoList;
653  InstallSource is("FTP");
654  is.source = "ftp.crosswire.org";
655  is.directory = "/pub/sword";
656  int errorCode = remoteCopy(&is, masterRepoList, masterRepoListPath.c_str(), false);
657  if (!errorCode) { //sucessfully downloaded the repo list
658  SWConfig masterList(masterRepoListPath);
659  SectionMap::iterator sections = masterList.getSections().find("Repos");
660  if (sections != masterList.getSections().end()) {
661  for (ConfigEntMap::iterator actions = sections->second.begin(); actions != sections->second.end(); actions++) {
662  // Search through our current sources and see if we have a matching UID
663  InstallSourceMap::iterator it;
664  for (it = sources.begin(); it != sources.end(); ++it) {
665  // is this our UID?
666  if ((it->second) && (it->second->uid == actions->first)) {
667  if (actions->second == "REMOVE") {
668  // be sure to call save/reload after this
669  // or this could be dangerous
670  delete it->second;
671  it->second = 0;
672  }
673  else {
674  SWBuf key = actions->second.stripPrefix('=');
675  if (key == "FTPSource") {
676  // we might consider instantiating a temp IS
677  // from our config string and then copy only
678  // some entries. This would allow the use to
679  // change some fields and not have them overwritten
680  // but it seems like we might want to change any
681  // of the current fields so we don't do this now
682  // InstallSource i("FTP", actions->second);
683  delete it->second;
684  it->second = new InstallSource("FTP", actions->second.c_str());
685  it->second->uid = actions->first;
686  }
687  }
688  break;
689  }
690  }
691  // didn't find our UID, let's add it
692  if (it == sources.end()) {
693  SWBuf key = actions->second.stripPrefix('=');
694  if (key == "FTPSource") {
695  if (actions->second != "REMOVE") {
696  InstallSource *is = new InstallSource("FTP", actions->second.c_str());
697  is->uid = actions->first;
698  sources[is->caption] = is;
699  }
700  }
701  }
702  }
703 
704  // persist and re-read
705  saveInstallConf();
706  readInstallConf();
707 
708  return 0;
709  }
710  }
711  return -1;
712 }
static const char * masterRepoList
Definition: installmgr.cpp:64
Definition: swbuf.h:47
char * privatePath
Definition: installmgr.h:74
SWBuf caption
Definition: installmgr.h:50
void saveInstallConf()
Definition: installmgr.cpp:222
const char * c_str() const
Definition: swbuf.h:158
void readInstallConf()
Definition: installmgr.cpp:138
static void removeTrailingSlash(SWBuf &buf)
Definition: installmgr.cpp:57
InstallSourceMap sources
Definition: installmgr.h:111
const char * stripPrefix(char separator, bool endOfStringAsSeparator=false)
Definition: swbuf.h:457
virtual int remoteCopy(InstallSource *is, const char *src, const char *dest, bool dirTransfer=false, const char *suffix="")
Definition: installmgr.cpp:300
virtual bool isUserDisclaimerConfirmed() const
Definition: installmgr.cpp:777
int InstallMgr::remoteCopy ( InstallSource is,
const char *  src,
const char *  dest,
bool  dirTransfer = false,
const char *  suffix = "" 
)
virtual

mostly an internally used method to remote download from a remote source to a local destination

Definition at line 300 of file installmgr.cpp.

300  {
301 SWLOGD("remoteCopy: %s, %s, %s, %c, %s", (is?is->source.c_str():"null"), src, (dest?dest:"null"), (dirTransfer?'t':'f'), (suffix?suffix:"null"));
302 
303  // assert user disclaimer has been confirmed
304  if (!isUserDisclaimerConfirmed()) return -1;
305 
306  int retVal = 0;
307  RemoteTransport *trans = 0;
308  if (is->type == "FTP"
309 #ifdef CURLSFTPAVAILABLE
310  || is->type == "SFTP"
311 #endif
312  ) {
313 
315  trans->setPassive(passive);
317  }
318  else if (is->type == "HTTP" || is->type == "HTTPS") {
320  }
321  transport = trans; // set classwide current transport for other thread terminate() call
322  if (is->u.length()) {
323  trans->setUser(is->u);
324  trans->setPasswd(is->p);
325  }
326  else {
327  trans->setUser(u);
328  trans->setPasswd(p);
329  }
330 
332 
333  SWBuf urlPrefix;
334  if (is->type == "HTTP") {
335  urlPrefix = (SWBuf) "http://";
336  }
337  else if (is->type == "HTTPS") {
338  urlPrefix = (SWBuf) "https://";
339  }
340 #ifdef CURLSFTPAVAILABLE
341  else if (is->type == "SFTP") {
342  urlPrefix = (SWBuf) "sftp://";
343  }
344 #endif
345  else {
346  urlPrefix = (SWBuf) "ftp://";
347  }
348  urlPrefix.append(is->source);
349 
350  // let's be sure we can connect. This seems to be necessary but sucks
351 // SWBuf url = urlPrefix + is->directory.c_str() + "/"; //dont forget the final slash
352 // if (trans->getURL("swdirlist.tmp", url.c_str())) {
353 // SWLOGD("FTPCopy: failed to get dir %s\n", url.c_str());
354 // return -1;
355 // }
356 
357 
358  if (dirTransfer) {
359  SWBuf dir = (SWBuf)is->directory.c_str();
360  removeTrailingSlash(dir);
361  dir += (SWBuf)"/" + src; //dont forget the final slash
362 SWLOGD("remoteCopy: dirTransfer: %s", dir.c_str());
363 
364  retVal = trans->copyDirectory(urlPrefix, dir, dest, suffix);
365 
366 
367  }
368  else {
369  SWTRY {
370  SWBuf url = urlPrefix + is->directory.c_str();
371  removeTrailingSlash(url);
372  url += (SWBuf)"/" + src; //dont forget the final slash
373  retVal = trans->getURL(dest, url.c_str());
374  if (retVal) {
375 SWLOGD("netCopy: failed to get file %s", url.c_str());
376  }
377  }
378  SWCATCH (...) {
379  retVal = -1;
380  }
381  }
382  SWTRY {
383  RemoteTransport *deleteMe = trans;
384  // do this order for threadsafeness
385  // (see terminate())
386  trans = transport = 0;
387  delete deleteMe;
388  }
389  SWCATCH (...) {}
390  return retVal;
391 }
void setUnverifiedPeerAllowed(bool val)
Definition: remotetrans.h:98
bool unverifiedPeerAllowed
Definition: installmgr.h:80
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
virtual RemoteTransport * createFTPTransport(const char *host, StatusReporter *statusReporter)
Definition: installmgr.cpp:81
SWBuf source
Definition: installmgr.h:51
void setTimeoutMillis(long timeoutMillis)
Definition: remotetrans.h:93
virtual char getURL(const char *destPath, const char *sourceURL, SWBuf *destBuf=0)
Definition: remotetrans.cpp:78
void setPassive(bool passive)
Definition: remotetrans.h:92
#define SWTRY
Definition: defs.h:57
StatusReporter * statusReporter
Definition: installmgr.h:76
SWBuf p
Definition: installmgr.h:79
#define SWCATCH(x)
Definition: defs.h:58
const char * c_str() const
Definition: swbuf.h:158
SWBuf & append(const char *str, long max=-1)
Definition: swbuf.h:274
int copyDirectory(const char *urlPrefix, const char *dir, const char *dest, const char *suffix)
static void removeTrailingSlash(SWBuf &buf)
Definition: installmgr.cpp:57
SWBuf u
Definition: installmgr.h:79
void setUser(const char *user)
Definition: remotetrans.h:96
bool passive
Definition: installmgr.h:77
void setPasswd(const char *passwd)
Definition: remotetrans.h:97
long timeoutMillis
Definition: installmgr.h:78
virtual RemoteTransport * createHTTPTransport(const char *host, StatusReporter *statusReporter)
Definition: installmgr.cpp:90
#define SWLOGD(...)
Definition: defs.h:187
RemoteTransport * transport
Definition: installmgr.h:94
SWBuf directory
Definition: installmgr.h:52
virtual bool isUserDisclaimerConfirmed() const
Definition: installmgr.cpp:777
int InstallMgr::removeModule ( SWMgr manager,
const char *  modName 
)
virtual

call to delete all files of a locally installed module.

Definition at line 241 of file installmgr.cpp.

241  {
242  SectionMap::iterator module;
243  ConfigEntMap::iterator fileBegin;
244  ConfigEntMap::iterator fileEnd, entry;
245 
246  // save our own copy, cuz when we remove the module from the SWMgr
247  // it's likely we'll free the memory passed to us in moduleName
248  SWBuf modName = moduleName;
249  module = manager->config->getSections().find(modName);
250 
251  if (module != manager->config->getSections().end()) {
252  // to be sure all files are closed
253  // this does not remove the .conf information from SWMgr
254  manager->deleteModule(modName);
255 
256  fileBegin = module->second.lower_bound("File");
257  fileEnd = module->second.upper_bound("File");
258 
259  SWBuf modFile;
260  SWBuf modDir;
261  entry = module->second.find("AbsoluteDataPath");
262  modDir = entry->second.c_str();
263  removeTrailingSlash(modDir);
264  if (fileBegin != fileEnd) { // remove each file
265  while (fileBegin != fileEnd) {
266  modFile = modDir;
267  modFile += "/";
268  modFile += fileBegin->second.c_str();
269  //remove file
270  FileMgr::removeFile(modFile.c_str());
271  fileBegin++;
272  }
273  }
274  else { //remove all files in DataPath directory
275  ConfigEntMap::iterator entry;
276  FileMgr::removeDir(modDir.c_str());
277  std::vector<DirEntry> dirList = FileMgr::getDirList(manager->configPath);
278  for (unsigned int i = 0; i < dirList.size(); ++i) {
279  if (dirList[i].name.endsWith(".conf")) {
280  modFile = manager->configPath;
281  removeTrailingSlash(modFile);
282  modFile += "/";
283  modFile += dirList[i].name;
284  SWConfig *config = new SWConfig(modFile.c_str());
285  if (config->getSections().find(modName) != config->getSections().end()) {
286  delete config;
287  FileMgr::removeFile(modFile.c_str());
288  }
289  else delete config;
290  }
291  }
292  }
293  return 0;
294  }
295  return 1;
296 }
static int removeDir(const char *targetDir)
Definition: filemgr.cpp:639
Definition: swbuf.h:47
virtual SectionMap & getSections()
Definition: swconfig.cpp:186
SWText * module
Definition: osis2mod.cpp:105
SWConfig * config
Definition: swmgr.h:302
const char * c_str() const
Definition: swbuf.h:158
static int removeFile(const char *fName)
Definition: filemgr.cpp:517
static void removeTrailingSlash(SWBuf &buf)
Definition: installmgr.cpp:57
static std::vector< struct DirEntry > getDirList(const char *dirPath, bool includeSize=false, bool includeIsDirectory=true)
Definition: filemgr.cpp:379
void deleteModule(const char *)
Definition: swmgr.cpp:1535
char * configPath
Definition: swmgr.h:316
void InstallMgr::saveInstallConf ( )

Call to dump sources and other settings to InstallMgr.conf

Definition at line 222 of file installmgr.cpp.

222  {
223 
224  installConf->getSection("Sources").clear();
225 
226  for (InstallSourceMap::iterator it = sources.begin(); it != sources.end(); ++it) {
227  if (it->second) {
228  installConf->getSection("Sources").insert(ConfigEntMap::value_type(it->second->type + "Source", it->second->getConfEnt().c_str()));
229  }
230  }
231  (*installConf)["General"]["PassiveFTP"] = (isFTPPassive()) ? "true" : "false";
232  (*installConf)["General"]["UnverifiedPeerAllowed"] = (isUnverifiedPeerAllowed()) ? "true" : "false";
233 
234  installConf->save();
235 }
bool isFTPPassive()
Definition: installmgr.h:267
ConfigEntMap & getSection(const char *section)
Definition: swconfig.h:76
bool isUnverifiedPeerAllowed()
Definition: installmgr.h:273
InstallSourceMap sources
Definition: installmgr.h:111
SWConfig * installConf
Definition: installmgr.h:106
virtual void save() const
Definition: swconfig.cpp:115
void InstallMgr::setFTPPassive ( bool  passive)
inline

whether or not to use passive mode when doing ftp transfers

Definition at line 266 of file installmgr.h.

266 { this->passive = passive; }
bool passive
Definition: installmgr.h:77
void InstallMgr::setTimeoutMillis ( long  timeoutMillis)
inline

Definition at line 269 of file installmgr.h.

269 { this->timeoutMillis = timeoutMillis; }
long timeoutMillis
Definition: installmgr.h:78
void InstallMgr::setUnverifiedPeerAllowed ( bool  allowed)
inline

Definition at line 272 of file installmgr.h.

272 { this->unverifiedPeerAllowed = allowed; }
bool unverifiedPeerAllowed
Definition: installmgr.h:80
void InstallMgr::setUserDisclaimerConfirmed ( bool  val)
inline

Preferred method of reporting user disclaimer confirmation is to override the above method instead of using the setter below. This is provided for clients who don't wish to inherit InstallMgr and override method.

Definition at line 214 of file installmgr.h.

static bool userDisclaimerConfirmed
Definition: installmgr.h:98
void InstallMgr::terminate ( )

Request nicely to terminate an ongoing transfer. If threading is a concern, consider calling terminate() from your status reporters as they are typically the link between the transfer thread and your UI.

Definition at line 238 of file installmgr.cpp.

238 { if (transport) transport->terminate(); }
RemoteTransport * transport
Definition: installmgr.h:94

Member Data Documentation

SWBuf InstallMgr::confPath
protected

Definition at line 75 of file installmgr.h.

std::set<SWBuf> InstallMgr::defaultMods
protected

Definition at line 73 of file installmgr.h.

SWConfig* InstallMgr::installConf

Definition at line 106 of file installmgr.h.

const unsigned int InstallMgr::MODSTAT_CIPHERED = 0x010
static

Definition at line 103 of file installmgr.h.

const unsigned int InstallMgr::MODSTAT_CIPHERKEYPRESENT = 0x020
static

Definition at line 104 of file installmgr.h.

const unsigned int InstallMgr::MODSTAT_NEW = 0x008
static

Definition at line 102 of file installmgr.h.

const unsigned int InstallMgr::MODSTAT_OLDER = 0x001
static

Definition at line 99 of file installmgr.h.

const unsigned int InstallMgr::MODSTAT_SAMEVERSION = 0x002
static

Definition at line 100 of file installmgr.h.

const unsigned int InstallMgr::MODSTAT_UPDATED = 0x004
static

Definition at line 101 of file installmgr.h.

SWBuf InstallMgr::p
protected

Definition at line 79 of file installmgr.h.

bool InstallMgr::passive
protected

Definition at line 77 of file installmgr.h.

char* InstallMgr::privatePath
protected

Definition at line 74 of file installmgr.h.

InstallSourceMap InstallMgr::sources

all remote sources configured for this installmgr. Use this to gain access to individual remote sources.

Definition at line 111 of file installmgr.h.

StatusReporter* InstallMgr::statusReporter
protected

Definition at line 76 of file installmgr.h.

long InstallMgr::timeoutMillis
protected

Definition at line 78 of file installmgr.h.

RemoteTransport* InstallMgr::transport
protected

we have a transport member to set as current running transport so we can ask it to terminate below, if user requests

Definition at line 94 of file installmgr.h.

SWBuf InstallMgr::u
protected

Definition at line 79 of file installmgr.h.

bool InstallMgr::unverifiedPeerAllowed
protected

Definition at line 80 of file installmgr.h.

bool InstallMgr::userDisclaimerConfirmed = false
static

Definition at line 98 of file installmgr.h.


The documentation for this class was generated from the following files: