659fc8db58808a30be19c034caa5d59529e3c508
[platform/upstream/syncevolution.git] / src / synthesis / src / sysync / sysync_globs.h
1 /*
2  *  File:         sysync_globs.h
3  *
4  *  Author:       Lukas Zeller (luz@synthesis.ch)
5  *
6  *  Global definitions/macros/constants
7  *
8  *  Copyright (c) 2001-2009 by Synthesis AG (www.synthesis.ch)
9  *
10  *  2001-xx-xx : luz : created
11  *
12  */
13
14 #ifndef SYSYNC_GLOBS_H
15 #define SYSYNC_GLOBS_H
16
17 #include "generic_types.h"
18
19 // global error codes
20 #include "syerror.h"
21
22 // include sysync-independent part
23 #include "syncml_globs.h"
24
25 // include debug definitions
26 #include "sysync_debug.h"
27
28 // include global progress defs
29 #include "global_progress.h"
30
31 #ifdef __cplusplus
32 // we need some STL basics as we define types based on STL constructs
33 #include <string>
34 #include <list>
35 #include <map>
36
37 using namespace std;
38 namespace sysync {
39 #endif
40
41 // local status codes (normally generated from SyncML status + LOCAL_STATUS_CODE)
42 typedef TSyError localstatus;
43
44
45 // configuration switches (DEFAULT_xxx are defaults for corresponding globals)
46
47 // - time (in seconds) how long a session will be kept inactive before it times out
48 #define DEFAULT_SERVERSESSIONTIMEOUT (60*5) // 5 minutes
49 #define DEFAULT_CLIENTSESSIONTIMEOUT 20 // 20 seconds
50
51 // - log file format: datastore
52 //   - client
53 #define DEFAULT_LOG_LABELS_CLIENT "SyncEndTime\tUser\tSyncMLVers\tStatus\tSynctype\tSessionID\tRemote ID\tRemote Name\tRemote VersInfo\tDatastore\tLocAdded\tLocUpdated\tLocDeleted\tLocErrors\tRemAdded\tRemUpdated\tRemDeleted\tRemErrors\tBytesOut\tBytesIn\n\n"
54 #define DEFAULT_LOG_FORMAT_CLIENT "%seT\t%U\t%syV\t%sS\t%tS\t%iS\t%iR\t%nR\t%vR\t%nD\t%laI\t%luI\t%ldI\t%leI\t%raI\t%ruI\t%rdI\t%reI\t%doB\t%diB\n"
55 //   - server
56 #define DEFAULT_LOG_LABELS_SERVER "SyncEndTime\tUser\tSyncMLVers\tStatus\tSynctype\tSessionID\tRemote ID\tRemote Name\tRemote VersInfo\tDatastore\tLocAdded\tLocUpdated\tLocDeleted\tLocErrors\tRemAdded\tRemUpdated\tRemDeleted\tRemErrors\tSlowSyncMatches\tServerWon\tClientWon\tDuplicated\tBytesOut\tBytesIn\tSessionBytesOut\tSessionBytesIn\n\n"
57 #define DEFAULT_LOG_FORMAT_SERVER "%seT\t%U\t%syV\t%sS\t%tS\t%iS\t%iR\t%nR\t%vR\t%nD\t%laI\t%luI\t%ldI\t%leI\t%raI\t%ruI\t%rdI\t%reI\t%smI\t%scI\t%ccI\t%dcI\t%doB\t%diB\t%toB\t%tiB\n"
58
59 // - defines debug mask that is active by default
60 #define DEFAULT_DEBUG DBG_NORMAL
61 // - if 1, enables message dumps (if included)
62 #define DEFAULT_MSGDUMP 0
63 // - if 1, enables XML translation of messages (independent of MSGDUMP)
64 #define DEFAULT_XMLTRANSLATE 0
65 // - if 1, enables incoming message simulation (if included)
66 #define DEFAULT_SIMMSGREAD 0
67 // - if true, global log file is enabled
68 #define DEFAULT_GLOBALDEBUGLOGS false
69 // - if true, session-spcific log files are enabled by default
70 #define DEFAULT_SESSIONDEBUGLOGS true
71 // - hard-wired names for debug logs
72 #define CONFERRPREFIX "sysync_"
73 #define CONFERRSUFFIX "_cfgerr.log"
74 #define LOGNAMEPREFIX "sysync_"
75 #define LOGSUFFIX ".log"
76 #define MSGDUMPPREFIX "sysync_"
77 #define MSGDUMPINSUFFIX "_incoming.sml"
78 #define MSGDUMPOUTSUFFIX "_outgoing.sml"
79
80
81 // Expiry
82 #ifdef EXPIRES_AFTER_DATE
83   // gcc does not like line continuations in DOS text files
84   // scalar value representing date
85   #define SCRAMBLED_EXPIRY_VALUE  ((EXPIRY_DAY+7l) + (EXPIRY_MONTH-1)*42l + (EXPIRY_YEAR-1720l)*12l*42l)
86 #endif
87 // define at least the max difference above formula can have to
88 // a real difference because of non-smooth increment with time
89 #define MAX_EXPIRY_DIFF 15 // 42-28(Feb) = 14
90
91
92 #if defined(EXPIRES_AFTER_DATE) || defined(EXPIRES_AFTER_DAYS) || defined(SYSER_REGISTRATION)
93 #define APP_CAN_EXPIRE
94 #else
95 #undef APP_CAN_EXPIRE
96 #endif
97
98 // Hack switches for testing with difficult clients
99 // - if defined, strings will be encoded as SML_PCDATA_OPAQUE
100 //#define SML_STRINGS_AS_OPAQUE 1
101 // - if defined, status for <Sync> command will be issued after
102 //   statuses for contained SyncOp commands.
103 //#define SYNCSTATUS_AT_SYNC_CLOSE 1
104
105
106 // general constants
107 // - used by compare functions to signal compare incompatibility
108 //   (i.e. non-orderable not-equal)
109 #define SYSYNC_NOT_COMPARABLE -999
110
111 // - maximum auth retries attempted (client) before giving up
112 //   Note: since 2.0.4.6 this includes the attitional "retry" required to request auth chal from the server
113 #define MAX_NORMAL_AUTH_RETRIES 2 // Note: retry only once (plus once for chal request) to avoid strict servers (such as COA-S) to lock accounts
114 #define MAX_SMART_AUTH_RETRIES 4 // when fSmartAuthRetry option is set, some additional retries happen after MAX_NORMAL_AUTH_RETRIES are exhausted
115 // - maximum auth attempts allowed (server) before session gets aborted
116 #define MAX_AUTH_ATTEMPTS 3
117 // - number of message resend retries (client)
118 #define MAX_MESSAGE_RESENDS 3
119 // - number of message resend retries before trying older protocol
120 #define SAME_PROTOCOL_RESENDS 2
121
122
123 // - switch on multithread support if we need it
124 #if defined(MULTI_THREAD_DATASTORE) || defined(MULTITHREAD_PIPESERVER)
125   #define MULTI_THREAD_SUPPORT 1
126 #endif
127
128 // - buffer sizes
129 #define CONFIG_READ_BUFSIZ 3048 // size of buffer for XML config reading
130
131
132 // Max message size
133 #ifndef DEFAULT_MAXMSGSIZE
134   #ifndef SYSYNC_SERVER
135     // only client
136     #define DEFAULT_MAXMSGSIZE 20000 // 20k now for DS 1.2 (we had 10k before 3.x)
137   #else
138     // server (or server and client)
139     #define DEFAULT_MAXMSGSIZE 50000 // 50k should be enough
140   #endif
141 #endif
142
143 // Max object size
144 #ifndef DEFAULT_MAXOBJSIZE
145   #define DEFAULT_MAXOBJSIZE 4000000 // 4MB should be enough
146 #endif
147
148
149 // default identification strings
150 #define SYSYNC_OEM "Synthesis AG"
151 #define SYSYNC_SERVER_DEVID "SySync Server"
152 #define SYSYNC_CLIENT_DEVID "SySync Client"
153 #ifndef SYNCML_SERVER_DEVTYP
154   #define SYNCML_SERVER_DEVTYP "server" // could also be "workstation"
155 #endif
156 #ifndef SYNCML_CLIENT_DEVTYP
157   #define SYNCML_CLIENT_DEVTYP "workstation" // general case, could also be "handheld" or "pda"...
158 #endif
159
160 // SyncML SyncCap mask bits
161 #define SCAP_MASK_TWOWAY 0x0002         // Support of 'two-way sync' = 1
162 #define SCAP_MASK_TWOWAY_SLOW 0x0004    // Support of 'slow two-way sync' = 2
163 #define SCAP_MASK_ONEWAY_CLIENT 0x0008  // Support of 'one-way sync from client only' = 3
164 #define SCAP_MASK_REFRESH_CLIENT 0x0010 // Support of 'refresh sync from client only' = 4
165 #define SCAP_MASK_ONEWAY_SERVER 0x0020  // Support of 'one-way sync from server only' = 5
166 #define SCAP_MASK_REFRESH_SERVER 0x0040 // Support of 'refresh sync from server only' = 6
167 #define SCAP_MASK_SERVER_ALERTED 0x0080 // Support of 'server alerted sync' = 7
168 // - minimum needed for conformance
169 #define SCAP_MASK_MINIMAL (SCAP_MASK_TWOWAY | SCAP_MASK_TWOWAY_SLOW) // Support of 'server alerted sync' = 7
170 // - normal capabilities
171 #define SCAP_MASK_NORMAL (SCAP_MASK_MINIMAL | SCAP_MASK_ONEWAY_CLIENT | SCAP_MASK_REFRESH_CLIENT | SCAP_MASK_ONEWAY_SERVER | SCAP_MASK_REFRESH_SERVER)
172
173 // DMU / IPP locUris
174 #define IPP_PARAMS_LOCURI_BASE "./vendor/synthesis/ipp10/" // URI used to address DMU/IPP settings/subscription
175 #define IPP_PARAMS_LOCURI_CFG IPP_PARAMS_LOCURI_BASE "cfg" // IPP config data from server
176 #define IPP_PARAMS_LOCURI_REQ IPP_PARAMS_LOCURI_BASE "req" // IPP request from client
177 #define IPP_PARAMS_ITEM_METATYPE "text/plain" // meta type for IPP req and cfg PUT data items
178 #define IPP_REQ_ACTIVATE "activate" // activate-request
179 #define IPP_REQ_SUBSCRIBE "subscribe" // activate-request
180 #define IPP_REQ_CHECK "check" // check-request
181
182 // Remote provisioning
183 #define SETTINGS_LOCURI_BASE "./vendor/synthesis/settings10/" // URI used to address settings
184 #define SETTINGS_LOCURI_CFG SETTINGS_LOCURI_BASE "cfg" // settings config data from server
185 #define SETTINGS_ITEM_METATYPE "text/plain" // meta type for settings config data
186
187
188 // fatal errors
189 #ifdef __PALM_OS__
190   #ifndef PlatFormFatalErr
191     #define PlatFormFatalErr { ErrDisplay("PlatFormFatalErr called"); ErrThrow(999); }
192   #endif
193   #define PlatFormFatalThrow(x) { exception *eP=new x; ErrDisplay(eP->what()); ErrThrow(999); }
194   #define PlatFormFatalReThrow { ErrDisplay("C++ re-throw attempted"); ErrThrow(999); }
195 #elif defined(ANDROID)
196   #ifndef PlatFormFatalErr
197     #define PlatFormFatalErr { __android_log_write( ANDROID_LOG_DEBUG, "exc", "PlatFormFatalErr called"); exit(999); }
198   #endif
199   #define PlatFormFatalThrow(x) { exception *eP=new x; __android_log_print( ANDROID_LOG_DEBUG, "exc", "C++ exception thrown: %s",eP->what()); exit(999); }
200   #define PlatFormFatalReThrow { __android_log_write( ANDROID_LOG_DEBUG, "exc", "C++ re-throw attempted"); exit(999); }
201 #else
202   #ifndef PlatFormFatalErr
203     #define PlatFormFatalErr { printf("PlatFormFatalErr called"); exit(999); }
204   #endif
205   #define PlatFormFatalThrow(x) { exception *eP=new x; printf("C++ exception thrown: %s",eP->what()); exit(999); }
206   #define PlatFormFatalReThrow { printf("C++ re-throw attempted"); exit(999); }
207 #endif
208
209
210 #ifdef ANDROID
211   #define DYN_CAST static_cast
212 #else
213   #define DYN_CAST dynamic_cast
214 #endif
215
216
217 // exceptions
218
219 #ifndef TARGET_HAS_EXCEPTIONS
220         // define here depending on compiler
221   // if not defined e.g. in target options
222   #ifdef __EPOC_OS__
223     // no exceptions in EPOC
224     #define TARGET_HAS_EXCEPTIONS 0
225   #elif defined(__MWERKS__)
226     // in Coderwarrior it depends on compiler settings
227     #if __option (exceptions)
228       #define TARGET_HAS_EXCEPTIONS 1
229     #else
230       #define TARGET_HAS_EXCEPTIONS 0
231     #endif
232   #elif defined(WINCE) || defined(ANDROID)
233     // no exceptions in eVC
234     #define TARGET_HAS_EXCEPTIONS 0
235   #else
236     // otherwise generally assume yes
237     #define TARGET_HAS_EXCEPTIONS 1
238   #endif
239 #endif
240
241 #if TARGET_HAS_EXCEPTIONS
242   // really throw
243   #define SYSYNC_THROW(x) throw x
244   #define SYSYNC_RETHROW throw
245   #define SYSYNC_TRY try
246   #define SYSYNC_CATCH(x) catch(x) {
247   #define SYSYNC_ENDCATCH }
248 #else
249   // global fatal error
250   #define SYSYNC_THROW(x) PlatFormFatalThrow(x)
251   #define SYSYNC_RETHROW PlatFormFatalReThrow
252   #define SYSYNC_TRY
253   #define SYSYNC_CATCH(x) if(false) { TSmlException e("",SML_ERR_UNSPECIFIC);
254   #define SYSYNC_ENDCATCH }
255 #endif
256
257
258 // checked casts (non-checked when RTTI is not there)
259 #if defined(WINCE) || defined(__EPOC_OS__) || defined(ANDROID)
260   // eVC + symbian has no RTTI, so we rely on having the right type and
261   // do a static cast here
262   #define GET_CASTED_PTR(dst,ty,src,msg) dst=static_cast<ty *>(src)
263 #else
264   // use dynamic cast and check if pointer is not NULL
265   #define GET_CASTED_PTR(dst,ty,src,msg) { dst = dynamic_cast<ty *>(src); if (!dst) { SYSYNC_THROW(TSyncException(msg)); } }
266 #endif
267
268
269 // global types
270
271 // library calling interface
272 #ifndef SYSYLIBCI
273   #define SYSYLIBCI // default to compilers default calling interface
274 #endif
275
276 // extra1 values for pev_debug
277 #define PEV_DEBUG_FORCERETRY 1
278
279 #ifdef __cplusplus
280
281 // internal field types (item field types)
282 typedef enum {
283   fty_string,
284   fty_telephone,
285   fty_integer,
286   fty_timestamp,
287   fty_date,
288   fty_url,
289   fty_multiline,
290   fty_blob,
291   fty_none, // note: this one is mostly internal use
292   numFieldTypes
293 } TItemFieldTypes;
294
295
296 #ifdef SCRIPT_SUPPORT
297
298 // built-in function definition
299 class TItemField;
300 class TScriptContext;
301
302 typedef void (*TBuiltinFunc)(TItemField *&aTermP, TScriptContext *aFuncContextP);
303
304 typedef void* (*TTableChainFunc) (void *&aNextCallerContext);
305
306 typedef struct {
307   // name of function
308   cAppCharP fFuncName;
309   // implementation
310   TBuiltinFunc fFuncProc;
311   // return type of function
312   TItemFieldTypes fReturntype;
313   // parameters
314   sInt16 fNumParams;
315   // list of parameter definition bytes
316   const uInt8 *fParamTypes;
317 } TBuiltInFuncDef;
318
319 typedef struct {
320   // number of functions
321   uInt16 numFuncs;
322   // actual functions
323   const TBuiltInFuncDef *funcDefs;
324   // chain function
325   TTableChainFunc chainFunc;
326 } TFuncTable;
327
328
329 #endif // SCRIPT_SUPPORT
330
331 // progress event
332 class TLocalDSConfig; // forward
333
334 typedef struct {
335   TProgressEventType eventtype;
336   TLocalDSConfig *datastoreID; // config pointer is used as ID, NULL if global
337   sInt32 extra; // extra info, such as error code or count for progress or # of added items
338   sInt32 extra2; // extra info, such as total for progress or # of updated items
339   sInt32 extra3; // extra info, such as # of deleted items
340 } TProgressEvent;
341
342 // Callbacks
343
344 /* %%% from old ages, probably obsolete
345 // - XML config data reader func type
346 typedef int SYSYLIBCI (*TXMLTextReadFunc)(
347   appCharP aBuffer,
348   bufferIndex aMaxSize,
349   bufferIndex *aReadCharsP,
350   void *aContext
351 );
352 // - text message output
353 typedef void SYSYLIBCI (*TTextMsgProc)(cAppCharP aMessage, void *aContext);
354 */
355
356 // - progress event notification
357 typedef bool SYSYLIBCI (*TProgressEventFunc)(
358   const TProgressEvent &aEvent,
359   void *aContext
360 );
361
362 #endif // __cplusplus
363
364
365
366 // local status codes (normally generated from SyncML status + LOCAL_STATUS_CODE)
367 typedef uInt16 localstatus;
368
369 // SyncML encodings
370 // Note: SmlEncoding_t is defined in the RTK smldef.h
371 #define numSyncMLEncodings (SML_XML-SML_UNDEF+1)
372
373
374 // SyncML Versions
375 typedef enum {
376   syncml_vers_unknown,
377   syncml_vers_1_0,
378   syncml_vers_1_1,
379   syncml_vers_1_2,
380   // number of enums
381   numSyncMLVersions
382 } TSyncMLVersions;
383
384
385 // conflict resolution strategies
386 typedef enum {
387   cr_duplicate,    // add conflicting counterpart to both databases
388   cr_newer_wins,   // newer version wins (if date/version comparison is possible, like sst_duplicate otherwise)
389   cr_server_wins,  // server version wins (and is written to client, with merge if enabled)
390   cr_client_wins,  // client version wins (and is written to server, with merge if enabled)
391   // number of enums
392   numConflictStrategies
393 } TConflictResolution;
394
395
396 // package states
397 typedef enum {
398   psta_idle,            // not started yet, no package sent or received
399   psta_init,            // initialisation package
400   psta_sync,            // sync package
401   psta_initsync,        // combined initialisation and sync package
402   psta_map,             // data update status / map
403   psta_supplement,      // extra packages possibly needed at end of session
404   // number of enums
405   numPackageStates
406 } TPackageStates;
407
408
409 /// Sync operations
410 typedef enum {
411   sop_wants_add,      ///< like add, but is still available for slowsync match
412   sop_add,
413   sop_wants_replace,  ///< like replace, but not yet conflict-checked
414   sop_replace,
415   sop_reference_only, ///< slowsync resume only: like sop_wants_add/sop_wants_replace, but ONLY for comparing with incoming add/replace from client and avoiding add when matching - NEVER send these to client
416   sop_archive_delete,
417   sop_soft_delete,
418   sop_delete,
419   sop_copy,
420   sop_move, // new for DS 1.2
421   sop_none, // should be last
422   // number of enums
423   numSyncOperations
424 } TSyncOperation;
425
426
427 // Sync modes (note: slow/refresh is a separate flag)
428 typedef enum {
429   smo_twoway,
430   smo_fromserver,
431   smo_fromclient,
432   // number of enums
433   numSyncModes
434 } TSyncModes;
435
436
437 // filter identifiers
438 #define isFilterIdent(c) (isalnum(c) || c=='_' || c=='.')
439
440
441 #ifdef __cplusplus
442
443 // forwards
444 class TSmlCommand;
445
446 // container for TSmlCommand pointers
447 typedef std::list<TSmlCommand*> TSmlCommandPContainer; // contains sync commands
448
449 // string to string map
450 typedef std::map<string,string> TStringToStringMap; // string to string map
451
452 #endif
453
454 #ifdef __cplusplus
455 } // namespace sysync
456 #endif
457
458 #endif // SYSYNC_GLOBS_H
459
460 // eof
461