2 * Funambol is a mobile platform developed by Funambol, Inc.
3 * Copyright (C) 2003 - 2007 Funambol, Inc.
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.
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
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,
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.
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.
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".
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"
46 AccessConfig::AccessConfig() {
50 firstTimeSyncMode = SYNC_SLOW;
58 endTimestamp = beginTimestamp = 0;
64 clientAuthType = NULL;
65 serverAuthType = NULL;
66 isServerAuthRequired = false;
77 AccessConfig::AccessConfig(AccessConfig& s) {
81 AccessConfig::~AccessConfig() {
82 safeDelete(&username );
83 safeDelete(&password );
84 safeDelete(&proxyHost);
85 safeDelete(&syncURL );
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 );
98 bool AccessConfig::getServerAuthRequired() const {
99 return isServerAuthRequired;
102 void AccessConfig::setServerAuthRequired(bool v) {
103 isServerAuthRequired = v;
105 dirty |= DIRTY_SERVERAUTH_REQUIRED;
108 const char* AccessConfig::getServerAuthType() const {
109 return serverAuthType;
113 void AccessConfig::setServerAuthType(const char* v){
114 set(&serverAuthType, v);
118 const char* AccessConfig::getClientAuthType() const {
119 return clientAuthType;
123 void AccessConfig::setClientAuthType(const char* v){
124 set(&clientAuthType, v);
126 dirty |= DIRTY_CLIENTAUTHTYPE;
129 const char* AccessConfig::getServerPWD() const {
134 void AccessConfig::setServerPWD(const char* v){
137 dirty |= DIRTY_SERVERPWD;
140 const char* AccessConfig::getServerID() const {
145 void AccessConfig::setServerID(const char* v){
148 dirty |= DIRTY_SERVERID;
151 const char* AccessConfig::getServerNonce() const {
156 void AccessConfig::setServerNonce(const char* v){
157 set(&serverNonce, v);
159 dirty |= DIRTY_SERVER_NONCE;
162 const char* AccessConfig::getClientNonce() const {
167 void AccessConfig::setClientNonce(const char* v){
168 set(&clientNonce, v);
170 dirty |= DIRTY_CLIENT_NONCE;
173 const char* AccessConfig::getUsername() const {
178 void AccessConfig::setUsername(const char* v){
181 dirty |= DIRTY_USERNAME;
185 const char* AccessConfig::getPassword() const {
189 void AccessConfig::setPassword(const char* v) {
192 dirty |= DIRTY_PASSWORD;
195 SyncMode AccessConfig::getFirstTimeSyncMode() const {
196 return firstTimeSyncMode;
199 void AccessConfig::setFirstTimeSyncMode(SyncMode v) {
200 firstTimeSyncMode = v;
202 dirty |= DIRTY_FIRST_TIME_SYNC_MODE;
205 bool AccessConfig::getUseProxy() const {
209 void AccessConfig::setUseProxy(bool v) {
212 dirty |= DIRTY_USE_PROXY;
215 const char* AccessConfig::getProxyHost() const {
219 void AccessConfig::setProxyHost(const char* v) {
222 dirty |= DIRTY_PROXY_HOST;
225 int AccessConfig::getProxyPort() const {
229 void AccessConfig::setProxyPort(int v) {
232 dirty |= DIRTY_PROXY_PORT;
235 const char* AccessConfig::getProxyUsername() const {
236 return proxyUsername;
239 void AccessConfig::setProxyUsername(const char* v) {
240 set(&proxyUsername, v);
243 const char* AccessConfig::getProxyPassword() const {
244 return proxyPassword;
247 void AccessConfig::setProxyPassword(const char* v) {
248 set(&proxyPassword, v);
251 const char* AccessConfig::getUserAgent() const {
255 void AccessConfig::setUserAgent(const char* v) {
260 unsigned int AccessConfig::getResponseTimeout() const {
261 return responseTimeout;
263 void AccessConfig::setResponseTimeout(unsigned int v) {
267 bool AccessConfig::getCheckConn() const {
270 void AccessConfig::setCheckConn(bool v) {
275 const char* AccessConfig::getSyncURL() const {
279 void AccessConfig::setSyncURL(const char* v) {
281 // Checks if the url starts with http(s)://; if not, http:// is prepended
285 // Adds default protocol if not set AND the string is not empty
287 strncmp(syncURL, "http://", 7) &&
288 strncmp(syncURL, "HTTP://", 7) &&
289 strncmp(syncURL, "https://", 8) &&
290 strncmp(syncURL, "HTTPS://", 8) ) {
292 char* dest = new char[strlen(syncURL)+8];
293 sprintf(dest, "http://%s", syncURL );
300 dirty |= DIRTY_SYNC_URL;
303 void AccessConfig::setBeginSync(unsigned long timestamp) {
304 beginTimestamp = timestamp;
305 dirty |= DIRTY_SYNC_BEGIN;
308 unsigned long AccessConfig::getBeginSync() const {
309 return beginTimestamp;
312 void AccessConfig::setMaxMsgSize(unsigned long msgSize) {
313 maxMsgSize = msgSize;
316 unsigned long AccessConfig::getMaxMsgSize() const {
320 void AccessConfig::setReadBufferSize(unsigned long bufferSize) {
321 readBufferSize = bufferSize;
324 unsigned long AccessConfig::getReadBufferSize() const {
325 return readBufferSize;
328 void AccessConfig::setEndSync(unsigned long timestamp) {
329 endTimestamp = timestamp;
330 dirty |= DIRTY_SYNC_END;
333 unsigned long AccessConfig::getEndSync() const {
338 unsigned int AccessConfig::getDirty() const {
342 void AccessConfig::set(char** buf, const char* v) {
349 *buf = new char[len+2];
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());
362 setProxyUsername(s.getProxyUsername());
363 setProxyPassword(s.getProxyPassword());
364 setBeginSync(s.getBeginSync());
365 setEndSync(s.getEndSync());
366 setFirstTimeSyncMode(s.getFirstTimeSyncMode());
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());
381 dirty = s.getDirty();
384 void AccessConfig::setCompression(bool v){
389 /*void AccessConfig::setCompression(const char *v){
390 if(strcmp(v,"1") == 0){
399 bool AccessConfig::getCompression() const{