summaryrefslogtreecommitdiff
path: root/include/installmgr.h
blob: b3972b62c4794de67da02bcecd450e27c13b8718 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#ifndef INSTALLMGR_H
#define INSTALLMGR_H

#include <defs.h>
#include <swbuf.h>
#include <map>
#include <set>

SWORD_NAMESPACE_START

class SWMgr;
class SWModule;
class SWConfig;
class FTPTransport;
class StatusReporter;

/** A remote installation source configuration
*/
class SWDLLEXPORT InstallSource {
	SWMgr *mgr;
public:
	InstallSource(const char *type, const char *confEnt = 0);
	virtual ~InstallSource();
	SWBuf getConfEnt() {
		return caption +"|" + source + "|" + directory + "|" + u + "|" + p + "|" + uid;
	}
	SWBuf caption;
	SWBuf source;
	SWBuf directory;
	SWBuf u;
	SWBuf p;
	SWBuf uid;

	SWBuf type;
	SWBuf localShadow;
	void *userData;
	SWMgr *getMgr();
	void flush();
};

/** A standard map of remote install sources.
 */
typedef std::map<SWBuf, InstallSource *> InstallSourceMap;

/** Class to handle installation and maintenance of a SWORD library of books.
 */
class SWDLLEXPORT InstallMgr {

protected:
	bool userDisclaimerConfirmed;
	std::set<SWBuf> defaultMods;
	char *privatePath;
	SWBuf confPath;
	StatusReporter *statusReporter;
	bool passive;
	SWBuf u, p;

	/** override this method and provide your own custom FTPTransport subclass
         */
	virtual FTPTransport *createFTPTransport(const char *host, StatusReporter *statusReporter);

	/** override this method and provide your own custom HTTP RemoteTransport (still called FTPTransport in pre 1.7.x) subclass
         */
	virtual FTPTransport *createHTTPTransport(const char *host, StatusReporter *statusReporter);


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

public:

	static const int MODSTAT_OLDER;
	static const int MODSTAT_SAMEVERSION;
	static const int MODSTAT_UPDATED;
	static const int MODSTAT_NEW;
	static const int MODSTAT_CIPHERED;
	static const int MODSTAT_CIPHERKEYPRESENT;

	SWConfig *installConf;

        /** all remote sources configured for this installmgr.  Use this to gain access
         *  to individual remote sources.
         */
	InstallSourceMap sources;

	/** Username and Password supplied here can be used to identify your frontend
	 *  by supplying a valid anon password like installmgr@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@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();

        /** call to delete all files of a locally installed module.
         */
	virtual int removeModule(SWMgr *manager, const char *modName);

        /** mostly an internally used method to ftp download from an remote source to a local destination
         */
	virtual int ftpCopy(InstallSource *is, const char *src, const char *dest, bool dirTransfer = false, const char *suffix = "");

        /** call to install a module from a local path (fromLocation) or remote InstallSource (is) (leave the other 0)
         */
	virtual int installModule(SWMgr *destMgr, const char *fromLocation, const char *modName, InstallSource *is = 0);

        /** call to obtain and locally cache the available content list of the remote source
         */
	virtual int refreshRemoteSource(InstallSource *is);

        /** call to populate installmgr configuration with all known
         *  remote sources from the master list at CrossWire
         */
	virtual int refreshRemoteSourceConfiguration();

	/** 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
	 *  (possibly the wrong language for the disclaimer)
	 *

A sample impl:

	static bool confirmed = false;
        if (!confirmed) {
		cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
		cout << "                -=+* WARNING *+=- -=+* WARNING *+=-\n\n\n";
		cout << "Although Install Manager provides a convenient way for installing\n";
		cout << "and upgrading SWORD components, it also uses a systematic method\n";
		cout << "for accessing sites which gives packet sniffers a target to lock\n";
		cout << "into for singling out users. \n\n\n";
		cout << "IF YOU LIVE IN A PERSECUTED COUNTRY AND DO NOT WISH TO RISK DETECTION,\n";
		cout << "YOU SHOULD *NOT* USE INSTALL MANAGER'S REMOTE SOURCE FEATURES.\n\n\n";
		cout << "Also, Remote Sources other than CrossWire may contain less than\n";
		cout << "quality modules, modules with unorthodox content, or even modules\n";
		cout << "which are not legitimately distributable.  Many repositories\n";
		cout << "contain wonderfully useful content.  These repositories simply\n";
		cout << "are not reviewed or maintained by CrossWire and CrossWire\n";
		cout << "cannot be held responsible for their content. CAVEAT EMPTOR.\n\n\n";
		cout << "If you understand this and are willing to enable remote source features\n";
		cout << "then type yes at the prompt\n\n";
		cout << "enable? [no] ";

		char prompt[10];
		fgets(prompt, 9, stdin);
		confirmed = (!strcmp(prompt, "yes\n"));
        }
        return confirmed;

         */
	virtual bool isUserDisclaimerConfirmed() const { return userDisclaimerConfirmed; }

	/** 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.
	 */
	void setUserDisclaimerConfirmed(bool val) { userDisclaimerConfirmed = val; }


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

A sample implementation, roughly taken from the windows installmgr:

	SectionMap::iterator section;
	ConfigEntMap::iterator entry;
	SWBuf tmpBuf;
	section = config->Sections.find(modName);
	if (section != config->Sections.end()) {
		entry = section->second.find("CipherKey");
		if (entry != section->second.end()) {
			entry->second = GET_USER_INPUT();
			config->Save();

			// LET'S SHOW THE USER SOME SAMPLE TEXT FROM THE MODULE
			SWMgr *mgr = new SWMgr();
			SWModule *mod = mgr->getModule(modName);
			mod->setKey("Ipet 2:12");
			tmpBuf = mod->StripText();
			mod->setKey("gen 1:10");
			tmpBuf += "\n\n";
			tmpBuf += mod->StripText();
			SOME_DIALOG_CONTROL->SETTEXT(tmpBuf.c_str());
			delete mgr;

			// if USER CLICKS OK means we should return true
			return true;
		}
	}
	return false;
}
	*/
       	virtual bool getCipherCode(const char *modName, SWConfig *config) { return false; }



	/** whether or not to use passive mode when doing ftp transfers
         */
	void setFTPPassive(bool passive) { this->passive = passive; }
	bool isFTPPassive() { return passive; }

        /** call from another thread to terminate the installation process
         */
	void terminate();

	/************************************************************************
	 * getModuleStatus - compare the modules of two SWMgrs and return a
	 * 	vector describing the status of each.  See MODSTAT_*
	 */
	static std::map<SWModule *, int> getModuleStatus(const SWMgr &base, const SWMgr &other);

	/************************************************************************
	 * isDefaultModule - allows an installation to provide a set of modules
	 *   in installMgr.conf like:
	 *     [General]
	 *     DefaultMod=KJV
	 *     DefaultMod=StrongsGreek
	 *     DefaultMod=Personal
	 *   This method allows a user interface to ask if a module is specified
	 *   as a default in the above way.  The logic is, if no modules are
	 *   installed then all default modules should be automatically selected for install
	 *   to help the user select a basic foundation of useful modules
	 */
	bool isDefaultModule(const char *modName);
};


SWORD_NAMESPACE_END

#endif