Imported Upstream version 0.8~alpha1
[platform/upstream/syncevolution.git] / src / client-api / src / include / common / push / CTPConfig.h
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 #ifndef INCL_CTP_CONFIG
37 #define INCL_CTP_CONFIG
38 /** @cond DEV */
39
40 #include "base/fscapi.h"
41 #include "client/DMTClientConfig.h"
42 #include "spdm/ManagementNode.h"
43 #include "spdm/DMTreeFactory.h"
44 #include "spdm/DMTree.h"
45 #include "base/util/utils.h"
46 #include "base/util/StringBuffer.h"
47
48 /// This is the root for the configuration
49 #define APPLICATION_URI                 "Funambol/SyncClient"
50
51 /// This is the context for the CTP push parameters
52 #define CONTEXT_PUSH_CTP                "/push/ctp"    
53
54
55 class CTPConfig : public DMTClientConfig {
56
57 private:
58     
59     /**
60     * This key enables the push feature. It is a bitmask, 
61     * with bit 0 enabling the STP and bit 1 enabling the CTP.
62     * 0: None
63     * 1: STP
64     * 2: CTP
65     * 3: STP with fallback CTP
66     */
67     int32_t push;
68
69     /**
70     * This key enables the polling feature if the value is 
71     * greater than 0, otherwise the polling is disabled.
72     */
73     int32_t polling;
74     
75     /**
76     * Enable or disable the feature of storing the pending 
77     * push requests during a sync.
78     */
79     bool queuePush;
80
81     /**
82     * The time interval, in seconds, after which the 
83     * client will restore the connection.
84     */
85     int32_t ctpRetry;
86
87     /**
88     * The time interval, in seconds, for the maximum 
89     * retry timeout (see failure handling).
90     */
91     int32_t maxCtpRetry;
92     
93     /**
94     * The time, in seconds, for which the client 
95     * shall wait for the server response, after sending a command.        
96     */
97     int32_t ctpCmdTimeout;
98     
99     /**
100     * The time, in seconds, for which the connection with 
101     * the server shall be kept open once it has been established. 
102     * A value of zero indicates that the connection must be 
103     * kept open forever.
104     */
105     int32_t ctpConnTimeout;
106
107     /**
108     * TCP/IP port used by the server to listen for CTP requests. 
109     */
110     int32_t ctpPort;
111
112     ///
113     /// the nonce used for the MD5 auth. The nonce is sent by the server
114     /// in b64 encoding. It's the same nonce used for synchronization, so
115     /// the value is linked directly to 'accessConfig::serverNonce'.
116     //char* ctpNonce;
117
118     /**
119     * The interval of the heartbeat
120     */
121     int32_t ctpReady;
122
123     /**
124     * The url to contact. From DM
125     */
126     StringBuffer urlTo;
127     
128     /**
129     * The url populated after a JUMP server command.
130     * it is in format <(ipAddress|address):port>
131     */
132     StringBuffer urlFrom;
133
134     /**
135     * Timeout (seconds) for the address-change notification sync.
136     * CTP will wait until this sync ends, after this timeout the
137     * CTP is started.
138     */
139     int32_t notifyTimeout;
140     
141     /**
142     * The device id. From DM
143     */
144     StringBuffer devid;
145
146     /**
147     * The username. From DM
148     */
149     StringBuffer username;
150
151     
152     void setUsername(StringBuffer v) { username = v; }
153     void setDeviceId(StringBuffer v) { devid = v; }
154
155     StringBuffer checkPrefix(char* url);
156
157 public:        
158     
159     /**
160     * Constructor
161     */
162     CTPConfig(const char* application_uri);
163     
164     /**
165     * Destructor
166     */
167     ~CTPConfig();
168
169     /**
170     * Read the parameter configuration from the registry
171     */
172     void readCTPConfig();
173     
174     /**
175     * Save the parameter configuration to the registry.
176     * Actually the only needed parameter to be saved is the
177     * nonce sent by the server
178     */
179     void saveCTPConfig();
180     
181     /**
182     * set/get method for push parameter
183     */
184     void setPush(int32_t v) { push = v; }
185     int getPush()           { return push; }
186
187     /**
188     * set/get method for polling parameter
189     */
190     int32_t getPolling()       { return polling; }
191     void setPolling(int32_t v) { polling = v; }
192     
193     /**
194     * set/get method for queuePush parameter
195     */
196     bool getQueuePush()       { return queuePush; }
197     void setQueuePush(bool v) { queuePush = v; }
198     
199     /**
200     * set/get method for ctpRetry parameter
201     */
202     int32_t getCtpRetry()       { return ctpRetry; }
203     void setCtpRetry(int32_t v) { ctpRetry = v; }
204     
205     /**
206     * set/get method for maxCtpRetry parameter
207     */
208     int32_t getMaxCtpRetry()       { return maxCtpRetry; }
209     void setMaxCtpRetry(int32_t v) { maxCtpRetry = v; }
210     
211     /**
212     * set/get method for ctpCmdTimeout parameter
213     */
214     int32_t getCtpCmdTimeout()       { return ctpCmdTimeout; }
215     void setCtpCmdTimeout(int32_t v) { ctpCmdTimeout = v; }
216     
217     /**
218     * set/get method for ctpConnTimeout parameter
219     */
220     int32_t getCtpConnTimeout()       { return ctpConnTimeout; }
221     void setCtpConnTimeout(int32_t v) { ctpConnTimeout = v; }
222     
223     /**
224     * set/get method for ctpPort parameter
225     */
226     int32_t getCtpPort()       { return ctpPort; }
227     void setCtpPort(int32_t v) { ctpPort = v; }
228     
229     /**
230     * set/get method for ctpReady parameter
231     */
232     int32_t getCtpReady()       { return ctpReady; }
233     void setCtpReady(int32_t v) { ctpReady = v; }
234     
235
236     /**
237     * set/get method for nonce parameter: it's the 'accessConfig::clientNonce' so
238     * we ridirect to that property.
239     */
240     const char* getCtpNonce()       { return accessConfig.getClientNonce(); }
241     void setCtpNonce(const char* v) { accessConfig.setClientNonce(v); }
242
243     /**
244     * set/get method for urlTo parameter
245     */
246     StringBuffer& getUrlTo()      { return urlTo; }
247     void setUrlTo(StringBuffer v) { urlTo = v; }
248
249     /**
250     * set/get method for urlFrom parameter
251     */
252     StringBuffer& getUrlFrom()      { return urlFrom; }
253     void setUrlFrom(StringBuffer v) { urlFrom = v; }
254
255     /**
256     * set/get method for notifyTimeout parameter
257     */
258     int getNotifyTimeout()       { return notifyTimeout; }
259     void setNotifyTimeout(int v) { notifyTimeout = v; }
260
261     /**
262     * get method for username parameter
263     */
264     StringBuffer& getUsername() { return username; }
265     
266     /**
267     * get method for deviceId parameter
268     */
269     StringBuffer& getDeviceId() { return devid; }
270     
271
272     /**
273     * get the host name form the url
274     */
275     StringBuffer getHostName(StringBuffer syncUrl);
276     
277     /**
278     * get the host port form the url. If the port doesn't exist
279     * it return 0
280     */
281     int getHostPort(StringBuffer syncUrl);  
282 private:
283     char* decodePassword(const char* password);
284     StringBuffer encodePassword(const char* password);
285 };
286
287
288 /** @endcond */
289 #endif