4 * Author: Lukas Zeller (luz@synthesis.ch)
6 * Global definitions/macros/constants
8 * Copyright (c) 2001-2009 by Synthesis AG (www.synthesis.ch)
10 * 2001-xx-xx : luz : created
14 #ifndef SYSYNC_GLOBS_H
15 #define SYSYNC_GLOBS_H
17 #include "generic_types.h"
22 // include sysync-independent part
23 #include "syncml_globs.h"
25 // include debug definitions
26 #include "sysync_debug.h"
28 // include global progress defs
29 #include "global_progress.h"
32 // we need some STL basics as we define types based on STL constructs
41 // local status codes (normally generated from SyncML status + LOCAL_STATUS_CODE)
42 typedef TSyError localstatus;
45 // configuration switches (DEFAULT_xxx are defaults for corresponding globals)
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
51 // - log file format: datastore
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"
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"
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"
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)
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
92 #if defined(EXPIRES_AFTER_DATE) || defined(EXPIRES_AFTER_DAYS) || defined(SYSER_REGISTRATION)
93 #define APP_CAN_EXPIRE
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
107 // - used by compare functions to signal compare incompatibility
108 // (i.e. non-orderable not-equal)
109 #define SYSYNC_NOT_COMPARABLE -999
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
123 // - switch on multithread support if we need it
124 #if defined(MULTI_THREAD_DATASTORE) || defined(MULTITHREAD_PIPESERVER)
125 #define MULTI_THREAD_SUPPORT 1
129 #define CONFIG_READ_BUFSIZ 3048 // size of buffer for XML config reading
133 #ifndef DEFAULT_MAXMSGSIZE
134 #ifndef SYSYNC_SERVER
136 #define DEFAULT_MAXMSGSIZE 20000 // 20k now for DS 1.2 (we had 10k before 3.x)
138 // server (or server and client)
139 #define DEFAULT_MAXMSGSIZE 50000 // 50k should be enough
144 #ifndef DEFAULT_MAXOBJSIZE
145 #define DEFAULT_MAXOBJSIZE 4000000 // 4MB should be enough
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"
156 #ifndef SYNCML_CLIENT_DEVTYP
157 #define SYNCML_CLIENT_DEVTYP "workstation" // general case, could also be "handheld" or "pda"...
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)
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
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
190 #ifndef PlatFormFatalErr
191 #define PlatFormFatalErr { ErrDisplay("PlatFormFatalErr called"); ErrThrow(999); }
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); }
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); }
202 #ifndef PlatFormFatalErr
203 #define PlatFormFatalErr { printf("PlatFormFatalErr called"); exit(999); }
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); }
211 #define DYN_CAST static_cast
213 #define DYN_CAST dynamic_cast
219 #ifndef TARGET_HAS_EXCEPTIONS
220 // define here depending on compiler
221 // if not defined e.g. in target options
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
230 #define TARGET_HAS_EXCEPTIONS 0
232 #elif defined(WINCE) || defined(ANDROID)
233 // no exceptions in eVC
234 #define TARGET_HAS_EXCEPTIONS 0
236 // otherwise generally assume yes
237 #define TARGET_HAS_EXCEPTIONS 1
241 #if TARGET_HAS_EXCEPTIONS
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 }
249 // global fatal error
250 #define SYSYNC_THROW(x) PlatFormFatalThrow(x)
251 #define SYSYNC_RETHROW PlatFormFatalReThrow
253 #define SYSYNC_CATCH(x) if(false) { TSmlException e("",SML_ERR_UNSPECIFIC);
254 #define SYSYNC_ENDCATCH }
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)
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)); } }
271 // library calling interface
273 #define SYSYLIBCI // default to compilers default calling interface
276 // extra1 values for pev_debug
277 #define PEV_DEBUG_FORCERETRY 1
281 // internal field types (item field types)
291 fty_none, // note: this one is mostly internal use
296 #ifdef SCRIPT_SUPPORT
298 // built-in function definition
300 class TScriptContext;
302 typedef void (*TBuiltinFunc)(TItemField *&aTermP, TScriptContext *aFuncContextP);
304 typedef void* (*TTableChainFunc) (void *&aNextCallerContext);
310 TBuiltinFunc fFuncProc;
311 // return type of function
312 TItemFieldTypes fReturntype;
315 // list of parameter definition bytes
316 const uInt8 *fParamTypes;
320 // number of functions
323 const TBuiltInFuncDef *funcDefs;
325 TTableChainFunc chainFunc;
329 #endif // SCRIPT_SUPPORT
332 class TLocalDSConfig; // forward
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
344 /* %%% from old ages, probably obsolete
345 // - XML config data reader func type
346 typedef int SYSYLIBCI (*TXMLTextReadFunc)(
348 bufferIndex aMaxSize,
349 bufferIndex *aReadCharsP,
352 // - text message output
353 typedef void SYSYLIBCI (*TTextMsgProc)(cAppCharP aMessage, void *aContext);
356 // - progress event notification
357 typedef bool SYSYLIBCI (*TProgressEventFunc)(
358 const TProgressEvent &aEvent,
362 #endif // __cplusplus
366 // local status codes (normally generated from SyncML status + LOCAL_STATUS_CODE)
367 typedef uInt16 localstatus;
370 // Note: SmlEncoding_t is defined in the RTK smldef.h
371 #define numSyncMLEncodings (SML_XML-SML_UNDEF+1)
385 // conflict resolution strategies
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)
392 numConflictStrategies
393 } TConflictResolution;
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
411 sop_wants_add, ///< like add, but is still available for slowsync match
413 sop_wants_replace, ///< like replace, but not yet conflict-checked
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
420 sop_move, // new for DS 1.2
421 sop_none, // should be last
427 // Sync modes (note: slow/refresh is a separate flag)
437 // filter identifiers
438 #define isFilterIdent(c) (isalnum(c) || c=='_' || c=='.')
446 // container for TSmlCommand pointers
447 typedef std::list<TSmlCommand*> TSmlCommandPContainer; // contains sync commands
449 // string to string map
450 typedef std::map<string,string> TStringToStringMap; // string to string map
455 } // namespace sysync
458 #endif // SYSYNC_GLOBS_H