The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
installmgr.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * installmgr.h - class InstallMgr: primary class to access all
4  * module installation functionality
5  *
6  * $Id: installmgr.h 3805 2020-09-19 12:19:28Z scribe $
7  *
8  * Copyright 2002-2013 CrossWire Bible Society (http://www.crosswire.org)
9  * CrossWire Bible Society
10  * P. O. Box 2528
11  * Tempe, AZ 85280-2528
12  *
13  * This program is free software; you can redistribute it and/or modify it
14  * under the terms of the GNU General Public License as published by the
15  * Free Software Foundation version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * General Public License for more details.
21  *
22  */
23 
24 #ifndef INSTALLMGR_H
25 #define INSTALLMGR_H
26 
27 #include <defs.h>
28 #include <swbuf.h>
29 #include <map>
30 #include <set>
31 
33 
34 class SWMgr;
35 class SWModule;
36 class SWConfig;
37 class RemoteTransport;
38 class StatusReporter;
39 
44 public:
45  InstallSource(const char *type, const char *confEnt = 0);
46  virtual ~InstallSource();
48  return caption +"|" + source + "|" + directory + "|" + u + "|" + p + "|" + uid;
49  }
56 
59  void *userData;
60  SWMgr *getMgr();
61  void flush();
62 };
63 
66 typedef std::map<SWBuf, InstallSource *> InstallSourceMap;
67 
71 
72 protected:
73  std::set<SWBuf> defaultMods;
74  char *privatePath;
77  bool passive;
79  SWBuf u, p;
81 
84  virtual RemoteTransport *createFTPTransport(const char *host, StatusReporter *statusReporter);
85 
88  virtual RemoteTransport *createHTTPTransport(const char *host, StatusReporter *statusReporter);
89 
90 
95 
96 public:
97 
99  static const unsigned int MODSTAT_OLDER;
100  static const unsigned int MODSTAT_SAMEVERSION;
101  static const unsigned int MODSTAT_UPDATED;
102  static const unsigned int MODSTAT_NEW;
103  static const unsigned int MODSTAT_CIPHERED;
104  static const unsigned int MODSTAT_CIPHERKEYPRESENT;
105 
107 
112 
118  InstallMgr(const char *privatePath = "./", StatusReporter *statusReporter = 0, SWBuf u="ftp", SWBuf p="installmgr@user.com");
119  virtual ~InstallMgr();
120 
123  void readInstallConf();
124 
127  void saveInstallConf();
128 
131  void clearSources();
132 
135  virtual int removeModule(SWMgr *manager, const char *modName);
136 
140  virtual int remoteCopy(InstallSource *is, const char *src, const char *dest, bool dirTransfer = false, const char *suffix = "");
141 
144  virtual int installModule(SWMgr *destMgr, const char *fromLocation, const char *modName, InstallSource *is = 0);
145 
146 
149  virtual int refreshRemoteSource(InstallSource *is);
150 
151 
155  virtual int refreshRemoteSourceConfiguration();
156 
157 
178  virtual bool isUserDisclaimerConfirmed() const; /* {
179 
180  bool confirmed = userDisclaimerConfirmed;
181 
182  if (!confirmed) {
183  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";
184  cout << " -=+* WARNING *+=- -=+* WARNING *+=-\n\n\n";
185  cout << "Although Install Manager provides a convenient way for installing\n";
186  cout << "and upgrading SWORD components, it also uses a systematic method\n";
187  cout << "for accessing sites which gives packet sniffers a target to lock\n";
188  cout << "into for singling out users. \n\n\n";
189  cout << "IF YOU LIVE IN A PERSECUTED COUNTRY AND DO NOT WISH TO RISK DETECTION,\n";
190  cout << "YOU SHOULD *NOT* USE INSTALL MANAGER'S REMOTE SOURCE FEATURES.\n\n\n";
191  cout << "Also, Remote Sources other than CrossWire may contain less than\n";
192  cout << "quality modules, modules with unorthodox content, or even modules\n";
193  cout << "which are not legitimately distributable. Many repositories\n";
194  cout << "contain wonderfully useful content. These repositories simply\n";
195  cout << "are not reviewed or maintained by CrossWire and CrossWire\n";
196  cout << "cannot be held responsible for their content. CAVEAT EMPTOR.\n\n\n";
197  cout << "If you understand this and are willing to enable remote source features\n";
198  cout << "then type yes at the prompt\n\n";
199  cout << "enable? [no] ";
200 
201  char prompt[10];
202  fgets(prompt, 9, stdin);
203  confirmed = (!strcmp(prompt, "yes\n"));
204  cout << "\n";
205  }
206  return confirmed;
207  } */
208 
209 
215 
216 
222  virtual bool getCipherCode(const char *modName, SWConfig *config) {
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  }
261 
262 
263 
266  void setFTPPassive(bool passive) { this->passive = passive; }
267  bool isFTPPassive() { return passive; }
268 
269  void setTimeoutMillis(long timeoutMillis) { this->timeoutMillis = timeoutMillis; }
270  long getTimeoutMillis() { return timeoutMillis; }
271 
272  void setUnverifiedPeerAllowed(bool allowed) { this->unverifiedPeerAllowed = allowed; }
273  bool isUnverifiedPeerAllowed() { return unverifiedPeerAllowed; }
274 
279  void terminate();
280 
281  /************************************************************************
282  * getModuleStatus - compare the modules of two SWMgrs and return a
283  * vector describing the status of each. See MODSTAT_*
284  * @param base The base SWMgr to compare-- usually represents what is currently installed
285  * @param other The other SWMgr to compare to base-- usually represents an install source's SWMgr
286  * @param utilModules whether to show user modules or utility modules; user modules is the default
287  */
288  static std::map<SWModule *, int> getModuleStatus(const SWMgr &base, const SWMgr &other, bool utilModules = false);
289 
290  /************************************************************************
291  * isDefaultModule - allows an installation to provide a set of modules
292  * in installMgr.conf like:
293  * [General]
294  * DefaultMod=KJV
295  * DefaultMod=StrongsGreek
296  * DefaultMod=Personal
297  * This method allows a user interface to ask if a module is specified
298  * as a default in the above way. The logic is, if no modules are
299  * installed then all default modules should be automatically selected for install
300  * to help the user select a basic foundation of useful modules
301  */
302  bool isDefaultModule(const char *modName);
303 };
304 
305 
307 
308 #endif
#define SWORD_NAMESPACE_START
Definition: defs.h:39
Definition: swmgr.h:93
bool unverifiedPeerAllowed
Definition: installmgr.h:80
Definition: swbuf.h:47
bool isFTPPassive()
Definition: installmgr.h:267
static const unsigned int MODSTAT_OLDER
Definition: installmgr.h:99
static const unsigned int MODSTAT_CIPHERKEYPRESENT
Definition: installmgr.h:104
SWBuf source
Definition: installmgr.h:51
#define SWDLLEXPORT
Definition: defs.h:171
char * privatePath
Definition: installmgr.h:74
long getTimeoutMillis()
Definition: installmgr.h:270
StatusReporter * statusReporter
Definition: installmgr.cpp:48
SWBuf caption
Definition: installmgr.h:50
StatusReporter * statusReporter
Definition: installmgr.h:76
SWBuf getConfEnt()
Definition: installmgr.h:47
void setUnverifiedPeerAllowed(bool allowed)
Definition: installmgr.h:272
void setTimeoutMillis(long timeoutMillis)
Definition: installmgr.h:269
static const unsigned int MODSTAT_NEW
Definition: installmgr.h:102
void * userData
Definition: installmgr.h:59
bool isUnverifiedPeerAllowed()
Definition: installmgr.h:273
void refreshRemoteSource(const char *sourceName)
Definition: installmgr.cpp:280
void setFTPPassive(bool passive)
Definition: installmgr.h:266
SWBuf u
Definition: installmgr.h:79
std::set< SWBuf > defaultMods
Definition: installmgr.h:73
static const unsigned int MODSTAT_CIPHERED
Definition: installmgr.h:103
InstallSourceMap sources
Definition: installmgr.h:111
bool passive
Definition: installmgr.h:77
static bool userDisclaimerConfirmed
Definition: installmgr.h:98
void setUserDisclaimerConfirmed(bool val)
Definition: installmgr.h:214
SWBuf confPath
Definition: installmgr.h:75
long timeoutMillis
Definition: installmgr.h:78
SWBuf localShadow
Definition: installmgr.h:58
SWConfig * installConf
Definition: installmgr.h:106
static const unsigned int MODSTAT_UPDATED
Definition: installmgr.h:101
#define SWORD_NAMESPACE_END
Definition: defs.h:40
SWMgr * mgr
Definition: installmgr.h:43
RemoteTransport * transport
Definition: installmgr.h:94
SWBuf directory
Definition: installmgr.h:52
virtual bool getCipherCode(const char *modName, SWConfig *config)
Definition: installmgr.h:222
std::map< SWBuf, InstallSource * > InstallSourceMap
Definition: installmgr.h:66
static const unsigned int MODSTAT_SAMEVERSION
Definition: installmgr.h:100
static time_t base
Definition: ftpparse.c:47