Imported Upstream version 0.8~alpha1
[platform/upstream/syncevolution.git] / src / client-api / src / c++ / common / spds / AccessConfig.cpp
1 /*
2  * Funambol is a mobile platform developed by Funambol, Inc. 
3  * Copyright (C) 2003 - 2007 Funambol, Inc.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Affero General Public License version 3 as published by
7  * the Free Software Foundation with the addition of the following permission 
8  * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
9  * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 
10  * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
11  * 
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15  * details.
16  * 
17  * You should have received a copy of the GNU Affero General Public License 
18  * along with this program; if not, see http://www.gnu.org/licenses or write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20  * MA 02110-1301 USA.
21  * 
22  * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite 
23  * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
24  * 
25  * The interactive user interfaces in modified source and object code versions
26  * of this program must display Appropriate Legal Notices, as required under
27  * Section 5 of the GNU Affero General Public License version 3.
28  * 
29  * In accordance with Section 7(b) of the GNU Affero General Public License
30  * version 3, these Appropriate Legal Notices must retain the display of the
31  * "Powered by Funambol" logo. If the display of the logo is not reasonably 
32  * feasible for technical reasons, the Appropriate Legal Notices must display
33  * the words "Powered by Funambol".
34  */
35
36
37 #include "base/fscapi.h"
38 #include "base/util/utils.h"
39 #include "spds/AccessConfig.h"
40 #include "spdm/constants.h"
41 #include "base/globalsdef.h"
42
43 USE_NAMESPACE
44
45
46 AccessConfig::AccessConfig() {
47
48     useProxy = false;
49     proxyPort = 8080;
50     firstTimeSyncMode = SYNC_SLOW;
51     dirty = false;
52
53     username   = NULL;
54     password   = NULL;
55     proxyHost  = NULL;
56     syncURL    = NULL;
57
58     endTimestamp = beginTimestamp = 0;
59
60     serverNonce           = NULL;
61     clientNonce           = NULL;
62     serverID              = NULL;
63     serverPWD             = NULL;
64     clientAuthType        = NULL;
65     serverAuthType        = NULL;
66     isServerAuthRequired  = false;
67     maxMsgSize            = 0;
68     readBufferSize        = 0;
69     userAgent             = NULL;
70     proxyUsername         = NULL;
71     proxyPassword         = NULL;
72     checkConn             = false;
73     responseTimeout       = 0;
74     compression           = false;
75 }
76
77 AccessConfig::AccessConfig(AccessConfig& s) {
78     assign(s);
79 }
80
81 AccessConfig::~AccessConfig() {
82     safeDelete(&username );
83     safeDelete(&password );
84     safeDelete(&proxyHost);
85     safeDelete(&syncURL  );
86
87     safeDelete(&serverNonce         );
88     safeDelete(&clientNonce         );
89     safeDelete(&serverID            );
90     safeDelete(&serverPWD           );
91     safeDelete(&clientAuthType      );
92     safeDelete(&serverAuthType      );
93     safeDelete(&userAgent           );
94     safeDelete(&proxyUsername       );
95     safeDelete(&proxyPassword       );
96 }
97
98 bool AccessConfig::getServerAuthRequired() const {
99     return isServerAuthRequired;
100 }
101
102 void AccessConfig::setServerAuthRequired(bool v) {
103     isServerAuthRequired = v;
104
105     dirty |= DIRTY_SERVERAUTH_REQUIRED;
106 }
107
108 const char* AccessConfig::getServerAuthType() const {
109     return serverAuthType;
110 }
111
112
113 void AccessConfig::setServerAuthType(const char* v){
114     set(&serverAuthType, v);
115 }
116
117
118 const char* AccessConfig::getClientAuthType() const {
119     return clientAuthType;
120 }
121
122
123 void AccessConfig::setClientAuthType(const char* v){
124     set(&clientAuthType, v);
125
126     dirty |= DIRTY_CLIENTAUTHTYPE;
127 }
128
129 const char* AccessConfig::getServerPWD() const {
130     return serverPWD;
131 }
132
133
134 void AccessConfig::setServerPWD(const char* v){
135     set(&serverPWD, v);
136
137     dirty |= DIRTY_SERVERPWD;
138 }
139
140 const char* AccessConfig::getServerID() const {
141     return serverID;
142 }
143
144
145 void AccessConfig::setServerID(const char* v){
146     set(&serverID, v);
147
148     dirty |= DIRTY_SERVERID;
149 }
150
151 const char* AccessConfig::getServerNonce() const {
152     return serverNonce;
153 }
154
155
156 void AccessConfig::setServerNonce(const char* v){
157     set(&serverNonce, v);
158
159     dirty |= DIRTY_SERVER_NONCE;
160 }
161
162 const char* AccessConfig::getClientNonce() const {
163     return clientNonce;
164 }
165
166
167 void AccessConfig::setClientNonce(const char* v){
168     set(&clientNonce, v);
169
170     dirty |= DIRTY_CLIENT_NONCE;
171 }
172
173 const char* AccessConfig::getUsername() const {
174     return username;
175 }
176
177
178 void AccessConfig::setUsername(const char* v){
179     set(&username, v);
180
181     dirty |= DIRTY_USERNAME;
182 }
183
184
185 const char* AccessConfig::getPassword() const {
186     return password;
187 }
188
189 void AccessConfig::setPassword(const char* v) {
190     set(&password, v);
191
192     dirty |= DIRTY_PASSWORD;
193 }
194
195 SyncMode AccessConfig::getFirstTimeSyncMode() const {
196     return firstTimeSyncMode;
197 }
198
199 void AccessConfig::setFirstTimeSyncMode(SyncMode v) {
200     firstTimeSyncMode = v;
201
202     dirty |= DIRTY_FIRST_TIME_SYNC_MODE;
203 }
204
205 bool AccessConfig::getUseProxy() const {
206     return useProxy;
207 }
208
209 void AccessConfig::setUseProxy(bool v) {
210     useProxy = v;
211
212     dirty |= DIRTY_USE_PROXY;
213 }
214
215 const char* AccessConfig::getProxyHost() const {
216     return proxyHost;
217 }
218
219 void AccessConfig::setProxyHost(const char* v) {
220     set(&proxyHost, v);
221
222     dirty |= DIRTY_PROXY_HOST;
223 }
224
225 int AccessConfig::getProxyPort() const {
226     return proxyPort;
227 }
228
229 void AccessConfig::setProxyPort(int v) {
230     proxyPort = v;
231
232     dirty |= DIRTY_PROXY_PORT;
233 }
234
235 const char* AccessConfig::getProxyUsername() const {
236     return proxyUsername;
237 }
238
239 void AccessConfig::setProxyUsername(const char* v) {
240     set(&proxyUsername, v);
241 }
242
243 const char* AccessConfig::getProxyPassword() const {
244     return proxyPassword;
245 }
246
247 void AccessConfig::setProxyPassword(const char* v) {
248     set(&proxyPassword, v);
249 }
250
251 const char* AccessConfig::getUserAgent() const {
252     return userAgent;
253 }
254
255 void AccessConfig::setUserAgent(const char* v) {
256     set(&userAgent, v);
257 }
258
259
260 unsigned int AccessConfig::getResponseTimeout() const {
261     return responseTimeout;
262 }
263 void AccessConfig::setResponseTimeout(unsigned int v) {
264     responseTimeout = v;
265 }
266
267 bool AccessConfig::getCheckConn() const {
268     return checkConn;
269 }
270 void AccessConfig::setCheckConn(bool v) {
271     checkConn = v;
272 }
273
274
275 const char* AccessConfig::getSyncURL() const {
276     return syncURL;
277 }
278
279 void AccessConfig::setSyncURL(const char* v) {
280     //
281     // Checks if the url starts with http(s)://; if not, http:// is prepended
282     //
283     set(&syncURL, v);
284
285     // Adds default protocol if not set AND the string is not empty
286     if (*syncURL                                                        &&
287         strncmp(syncURL, "http://", 7)  &&
288         strncmp(syncURL, "HTTP://", 7)  &&
289         strncmp(syncURL, "https://", 8) &&
290         strncmp(syncURL, "HTTPS://", 8) ) {
291
292             char* dest = new char[strlen(syncURL)+8];
293             sprintf(dest, "http://%s", syncURL );
294
295             set(&syncURL, dest);
296
297             delete dest;
298     }
299
300     dirty |= DIRTY_SYNC_URL;
301 }
302
303 void AccessConfig::setBeginSync(unsigned long timestamp) {
304     beginTimestamp = timestamp;
305     dirty |= DIRTY_SYNC_BEGIN;
306 }
307
308 unsigned long AccessConfig::getBeginSync() const {
309     return beginTimestamp;
310 }
311
312 void AccessConfig::setMaxMsgSize(unsigned long msgSize) {
313     maxMsgSize = msgSize;
314 }
315
316 unsigned long AccessConfig::getMaxMsgSize() const {
317     return maxMsgSize;
318 }
319
320 void AccessConfig::setReadBufferSize(unsigned long bufferSize) {
321     readBufferSize = bufferSize;
322 }
323
324 unsigned long AccessConfig::getReadBufferSize() const {
325     return readBufferSize;
326 }
327
328 void AccessConfig::setEndSync(unsigned long timestamp) {
329     endTimestamp = timestamp;
330     dirty |= DIRTY_SYNC_END;
331 }
332
333 unsigned long AccessConfig::getEndSync() const {
334     return endTimestamp;
335 }
336
337
338 unsigned int AccessConfig::getDirty() const {
339     return dirty;
340 }
341
342 void AccessConfig::set(char** buf, const char* v) {
343     safeDelete(buf);
344
345     if (v == NULL) {
346         v = "";
347     }
348     int len = strlen(v);
349     *buf = new char[len+2];
350
351     strcpy(*buf, v);
352 }
353
354 void AccessConfig::assign(const AccessConfig& s) {
355     setUsername (s.getUsername() );
356     setPassword (s.getPassword() );
357     setSyncURL  (s.getSyncURL()  );
358     setProxyHost(s.getProxyHost());
359     setProxyPort(s.getProxyPort());
360     setUserAgent(s.getUserAgent());
361
362     setProxyUsername(s.getProxyUsername());
363     setProxyPassword(s.getProxyPassword());
364     setBeginSync(s.getBeginSync());
365     setEndSync(s.getEndSync());
366     setFirstTimeSyncMode(s.getFirstTimeSyncMode());
367
368     setServerAuthRequired(s.getServerAuthRequired());
369     setClientAuthType(s.getClientAuthType());
370     setServerAuthType(s.getServerAuthType());
371     setServerPWD(s.getServerPWD());
372     setServerID(s.getServerID());
373     setServerNonce(s.getServerNonce());
374     setClientNonce(s.getClientNonce());
375     setMaxMsgSize(s.getMaxMsgSize());
376     setReadBufferSize(s.getReadBufferSize());
377     setCheckConn(s.getCheckConn());
378     setResponseTimeout(s.getResponseTimeout());
379     setCompression(s.getCompression());
380
381     dirty = s.getDirty();
382 }
383
384 void AccessConfig::setCompression(bool v){
385         compression= v;
386 }
387
388
389 /*void AccessConfig::setCompression(const char *v){
390     if(strcmp(v,"1") == 0){
391         compression = true;
392     }else{
393         compression = false;
394     }
395 }*/
396
397
398
399 bool AccessConfig::getCompression() const{
400     return compression;
401 }
402