summaryrefslogtreecommitdiff
path: root/src/sysync/syncsession.cpp
AgeCommit message (Collapse)AuthorFilesLines
2014-09-10engine: fix use-after-free bug when delaying command executionPatrick Ohly1-2/+6
In one particular case, a pending command that needs more data, the engine crashed because delayed command execution code path deleted the command still needed for the next chunk (found in Client::Sync::eds_contact_eds_memo::testLargeObject).
2014-08-29syncsession: avoid unnecessary nonce updatePatrick Ohly1-2/+9
When the configure auth type needs no nonce, don't generate one and return NULL immediately, like newChallenge() would do. That avoids unnecessary disk writes for storing the new nonce, which is important for local syncs in IVI. It also avoids debug output about a challenge that would not get sent.
2014-01-08syncsession: track pointerPatrick Ohly1-1/+3
clang's scan-build reported a "use after free" error. Probably a false positive, caused by clang not knowing that a function call will always return the same value. Nevertheless it is safer to really track whether the pointer is still non-null, in particular because there are exception handlers which might do a double free.
2013-11-21engine: fix LOCERR_AGAIN handling with strict exec orderingPatrick Ohly1-3/+12
Using SyncEvolution as SyncML client was basically broken: when receiving a message with a few Adds and Final, the first Add returned LOCERR_AGAIN. This caused the engine to queue the command and all following ones, without invoking the storage for those additional queued Adds. So batching of writes was not working. Worse, the map phase was entered and thus the write phase ended despite the pending Adds. As a quick fix, force the storage to execute the operation immediately. A better solution would be to allow item operations to queue up and then flush them at the end of the message processing. This would at least allow batching inside the same message.
2013-07-10linux: fix multithreading under valgrindPatrick Ohly1-4/+43
TThreadObject::waitfor() gets called twice: once when the engine waits for completion of the thread, once when resetting the datastore. The second wait should be a NOP. However, although skipped the condwait (because fTerminated==true) it still ended up calling pthread_join() again (because fPosixThread!=0). This is problematic because a thread can only be joined once. It happened to work most of the time, except in some tests running under valgrind, where the second pthread_join() hangs. It is uncertain why it didn't happen all the time (Number of threads? Runtime of program?), but the fix is obvious - prevent entering pthread_join() more than once by resetting fPosixThread after the first call.
2013-07-10ensure ordering of status repliesPatrick Ohly1-8/+77
This commit ensures that Status commands are sent in the order of the corresponding command when out-of-order execution of commands is enabled. This is achieved by checking whether a Status command can really be issued. If there are already commands queued, then any Status command issued while processing another command gets attached to that command. Then the command itself is queued although it has finished. From then on the command merely acts as a container for the status commands. The next time delayed commands are processed, such commands are not executed again. Instead their statuses are issued. Add/Replace commands which contain incomplete items are special: they must trigger a Status 213 response in the same message, which cannot be done without processing the previously queued commands first. We could try to queue the incomplete command without processing it at all, but that would change the response in a way that might be unexpected by the peer (although legal). Better play it safe and finish all queued commands, then process the command. Out-of-order execution still needs to be enabled explicitly via <strictexecordering>off</strictexecordering> in a remote rule. This is a bit misleading, because the behavior should not be visible to the peer anymore, and thus not depend on who we are talking to.
2013-06-19asynchronous command executionPatrick Ohly1-3/+57
It can be useful to trigger add/update/delete requests and check for completion later. For example, combining multiple updates in one operation is more efficient in the Evolution Data Server (used by SyncEvolution). Another advantage is the execution of these changes in the background while already exchanging the next message with the peer. This patch implements asynchronous add/update/delete operations for client and server. The functionality can be requested by data stores by returning the new LOCERR_AGAIN status code. The <strictexecordering> flag must be set to 'false' before multiple pending operations are allowed. It is still 'true' by default, in which case once the first operation returns LOCERR_AGAIN, all further operations are queued immediately without submitting them to the store first. The flag used to allow processing further commands when the first Sync command was queued, primarily (exclusively?) because of a slow data store 'start data read' operation. Testing showed that allowing that breaks syncing with the Synthesis engine, so instead of allowing something of dubious value the code now always serializes commands when anything more than complex than add/delete/replace/copy is involved. In that sense the commit reduces the semantic of <strictexecordering> slightly from "allow broken SyncML behavior" to "enable asynchronous command execution". Together with the next commit, that hopefully can be done without violating the SyncML spec. Regarding the implementation, When getting the LOCERR_AGAIN status back, all levels involved in the processing of the change dump their local state into some kind of ausiliary data structure and attach that to the item. They check for that auxiliary data the next time they get called and if found, know that they need to resume operation where they left of before. For small functions, this is done with changes the if/else code branches. For large functions, the changes would have been too intrusive and hard to verify for correctness, because the control flow often depends on variables that may change as part of the execution. An approach based on goto was used in those cases (kind of like a reverse long jump). TSyncItem stores the auxiliary data in a hash indexed with hard-coded keys for each layer. Arbitrary string keys were considered, but discarded because of the (unnecessary) performance overhead. The SyncML toolkit's SmlItem has a new pointer that holds the additional state. The toolkit itself only sets it and knows how to free it via a callback. There is no explicit "flush pending changes" or "complete changes" operation on data stores, because that would require extending the plugin API. Instead the data stores are expected to finish the item change(s) when called a second time. Normally the second call happens at the beginning of the next message processing, thus achieving the goal of overlapping processing with network IO. The exception is the last message in a session. Testing showed that delaying item changes in the SyncML client's final message confused Synthesis client and/or server so that they no longer agree on the end of session. Now the pending commands are issued a second time at the end of processing that final message, which solved that issue. There is one caveat that needs to be addressed in the next commit: statuses must be issued in the order of their commands. At the moment, the engine in its default "strict exec ordering" mode will stop issuing more commands after the initial one was queued. A different way of ensuring correct order will be needed.
2013-06-10syncsession: move code into new tryDelayedExecutionCommands()Patrick Ohly1-41/+48
The code gets copied 1:1 without changes. This will be useful because some code in coming patches needs to call it.
2012-10-10SyncModeExtensions: added config flag <syncmodeextensions> that must be set ↵Lukas Zeller1-11/+15
in config to enable non-standard sync modes to be added into config. This is because some servers fail to work when non-standard modes are present, so by default they are off now. Projects that rely on the sync mode extensions (SyncEvolution) must enable them explicitly in config now
2012-06-06SyncCap: compatibility enhancement for Nokia phonesPatrick Ohly1-0/+35
It turns out that Nokia phones don't like SyncModes that they don't recognize. They abort a sync over Bluetooth/OBEX with a generic "Forbidden" error at the OBEX layer. This only occurs when the sync app requests the inclusion of non-standard SyncCaps ("can restart", custom flags). As a workaround, the extended SyncModes are sent less often now: - a client always sends them, based on the observation that servers handle that okay(ish - see Funambol workaround) - a server only sends them if the client has already sent some extensions itself This works as long as the Put with the client's DevInf is processed before the server's DevInf is generated in response to a Get; for libsynthesis<->libsynthesis syncs that is the case. A new dummy 390002 SyncMode is always sent, to trigger this behavior in the server also when the client has no other extensions. Perhaps this behavior should be made configurable and off by default, to avoid regressions in combinations which haven't been tested yet.
2012-03-02Merge remote branch 'origin/for-master/internal-sync' into nightlySyncEvolution Nightly Testing1-0/+13
2012-02-29restarting sync: support multiple datastoresPatrick Ohly1-6/+6
Removed the limitation to one active datastore. Testing showed that there was indeed a problem: when processing the Alert which triggers the restart, the "we are restarting" flag was local and thus only applied to the first datastore for which such an Alert was received. All further Alerts then are processed when the session state was already reset and thus the other datastores were not reset, causing undesired slow syncs (anchor not written). Fixed by remembering the "we are restarting" flag as part of the session. For good measure the flag is reset again when the restarted sync enters the "sync" phase.
2012-02-28logging: fixed CONSOLEPRINTF format conversion issuesPatrick Ohly1-1/+1
Compiling on 64 bit Linux with CONSOLEPRINTF mapped to printf() revealed some 32/64 bit mistmatches. Fixed by casting to long, as defined by the format string.
2012-02-07SyncML extensions: multiple cycles in the same sessionPatrick Ohly1-0/+13
SyncML limits the data exchange to "client sends changes, server sends changes back". If the client detects that it has further changes for the server while already in the second phase, it will have to wait for the next SyncML session before it can send these changes. This leads to a bad user experience, because the user expectation is that client and server are in sync after a sync session. Examples when this becomes a problem: - 409 conflict detected in binfile client (tested with SyncEvolution Client::Sync::eds_event::testAddBothSides[Refresh] and a SyncEvolution server with file backend which doesn't detect duplicates based on UID) - temporary error prevents applying a change, needs to be retried (untested at the moment) - PBAB use case: advanced client does a sync with a subset of the data (vCard without PHOTO, while retrieving PHOTO data in the background), then sends updates with more data (modified/new PHOTOs) later on (also untested) This commit introduces a new mode where SyncML client and server allow multiple read/write cycles inside the same session. This extends the SyncML 1.2 standard in the following way: - in refresh-from-client mode, client and server always enter the map phase although the standard says that it can and must be skipped; the Synthesis engine already supported that non-standard behavior via the fCompleteFromClientOnly flag (aka <completefromclientonly> in the config and remote rules) - the client, if it has more changes for the server and hasn't encountered problem, finishes the current cycle internally and then sends a new <Alert> in the next message to start the next cycle, instead of ending the map phase and package with a <Final/> tag - the server starts at the beginning of a new SyncML session when it gets that <Alert>, instead of rejecting it as a protocol violation - the first sync mode is done as set by the app; any following one falls back to incremental mode: - slow sync -> two-way sync or one-way if data direction was limited - refresh sync -> one-way sync in same direction - one-way sync -> do it again To simplify testing, this new functionality is currently limited to sync sessions with only a single active data store. The new mode has to be enabled *on both sides* with the <completefromclientonly> config option. When only enabled on the client side, the unexpected <Alert> will be rejected by the serer. When only enabled on the server side, the client might be surprised by the non-standard map phase behavior. SyncEvolution enables this new mode unconditionally with a remote rule when talking to itself. Ideally this should be replaced with a DevInf extension, both for "SyncML engine supports the mode" and "data store supports restarting". Data stores must be able to deal with repeated cycles in the same session. Typically this consists of reseting some state so that running another sync cycle doesn't reuse obsolete information. The binfile DS supports this now, but the underlying data store in the app might not be ready for it yet. Currently the engine does not check this. The binfile client automatically recognizes the 409 conflict case and enters a new sync cycle to get the server in sync with the client. In addition, any client can be told to restart the sync by setting the new "restartsync" session variable (PBAP use case). This has to happen before the client considers the session completed, i.e. before EndDataWrite() is called. It would be better to do this with a per-datastore flag, but it wasn't obvious how to expose such a flag via the engine API. While looking at the code it was noticed that issueCustomEndPut() is not called when running in standard-compliant refresh-from-client mode, because the code is only invoked at the end of the map phase, which is skipped in that mode. A bug?! Not fixed.
2011-08-15Merge remote-tracking branch 'meego/master' into luzLukas Zeller1-4/+99
2011-06-15remote rules + OverrideDevInf: parse DevInf as part of checking the configPatrick Ohly1-75/+83
Now the DevInf is parsed in TSessionConfig::localResolve(). The result is stored in the TRemoteRuleConfig instance. The advantage is that syntax errors are found earlier and for all remote rules, not just the one active during a sync. The downside is somewhat increased memory and CPU consumption. The DevInf in XML format is kept in memory although no longer needed after localResolve(). That might be useful for debugging.
2011-06-15remote rules: added OverrideDevInfPatrick Ohly1-2/+89
Many SyncML servers send DevInf without CtCap inside. For those servers, the engine (often incorrectly) has to assume that they support all fields. This patch adds a configuration element "OverrideDevInf" which helps to address this problem. It may occur in a "RemoteRule". Once that rule matches a DevInf sent by a peer, processing of CtCap continues with the CtCap element of the DevInf inside the remote rule. This allows adding and overriding the CtCap from a peer. "OverrideDevInf" must contain a complete DevInf, although right now only the CtCap inside it really matters. This approach has the advantage that it can reuse the existing and somewhat documented CtCap format for describing capabilities. The downside is that not everything can be encoded in that format, for example, how many components of the ORG field are supported. A possible solution for that is to extend the format in a way that only the Synthesis engine understand and/or standardize such extensions. Right now the "OverrideDevInf" content is only parsed when needed. Beware that syntax errors will only be found when using the rule!
2011-05-20whitespace cosmetics only: detabbed once againLukas Zeller1-47/+47
2011-01-21Updated copyright notice, year and author email address (comment only, no ↵Lukas Zeller1-1/+1
code changes) - luz no longer at Synthesis, but plan44.ch - Shared copyright for libsynthesis/sysync code pool - All files copyrighted until 2011
2010-12-06sync session: handle empty Target URIPatrick Ohly1-4/+17
As reported in the "[SyncEvolution] Sony Ericsson C510: No idea to get it working" mail thread, the C510 sends an empty Target URI. The Source URI contains the value we are looking for, so using that as fallback allows a sync to start.
2010-04-30engine 3.4.0.7: Progress events now session local and available for server ↵Lukas Zeller1-11/+50
sessions - new macros for generating progress events - in engine builds, progress events are strictly session local now and are directly delivered via SessionStep. - in monolithic builds, progress events are still passed down to the app level and delivered via a app level callback as in previous versions.
2010-03-18sysync_b64: added b64::free() that can be called to dispose blocks allocated ↵Lukas Zeller1-4/+4
by b64::decode/encode As sysync_b64 was made independent, it can't use sysync_malloc() any more, but uses normal malloc(). However, all blocks allocated and returned by b64::encode/decode were still returned with sysync_free(). This only did not hurt because sysync_free was mapped to free in most (all?) builds. Anyway, that was ugly so sysync_b64 now includes b64::free() to clean up the situation. This patch changes all occurrences of sysync_free() returning blocks allocated by b64:: routines with b64::free().
2010-03-18pluginapids: ReadNextItem can now return error without causing exceptions.Lukas Zeller1-0/+6
In particular, LOCERR_USERSUSPEND can be returned to signal that the plugin has detected a external condition that should suspend the session. All other errors abort the session.
2010-03-11Valgrind warning fixed: initialize the conditonal variablesmb10091Chen Congwu1-0/+5
2010-02-18engine: now shows engine-determined OS/version as well as configured hwv/fwv ↵Lukas Zeller1-0/+7
in log
2010-02-18engine: added configurable device ID (via "customdeviceid" config variable)Lukas Zeller1-3/+3
when "customdeviceid" is defined it will be used instead of the id determined by platform adapters. Notes: - "customdeviceid" is considered to be truly unique when defined. - The value used for the device ID on the SyncML level might be a MD5 hash of the real device ID and the user name when required. - the "device_uri" predefined config variable always returns the device ID as determined by platform adapters.
2010-02-05Engine 3.4.0.4: enhanced remote rules with subrules and multiple active ↵Lukas Zeller1-101/+142
rules per session - as before, unless a rule has the <finalrule> flag set, all remote rules will be checked for a match, and all matching rule's behaviour flags will be combined. - UNLIKE before (where the last matching rule was considered the one and only "active" rule), now all matching rules are kept in a list and all considered active. - Using <include rule="..."/> in a remote rule, a matching rule can activate other rules. - Using <subrule> (instead of <remoterule>), rules can be defined that never match by themselves, but can only be activated using <include name="..."/> - The REMOTERULENAME() script function still returns the name of the LAST activated rule (which, unless <include> is used, is the LAST matching rule, and is therefore backwards compatible with pre 3.4.0.4 configs. - A new ISACTIVERULE() script function allows to test if a certain rule is active (by name). This is meant to replace REMOTERULENAME()=="xxx" checks. - Rule-specific property definitions (<property rule="xxx") and rule-specific datatype usage (<use datatype="x" ... rulematch="rule"/>) now are activated by ANY of the active rules .
2010-01-27Merge remote branch 'moblin/master' into luz_tmpLukas Zeller1-2/+5
Conflicts: src/sysync/debuglogger.cpp (resolved as per discussion on os-libsynthesis 2010-01-27)
2010-01-27bugfix for unilib regression: there must be no requestmaxtime limit for clients!Lukas Zeller1-0/+1
joining client and server in syncagent caused RemainingRequestTime() to get active in clients as well, which could cause messing up sync sessions because incoming commands were "queued for later" after requestmaxtime (or, its default fallback, sessiontimeout) had passed. As sessiontimeout is set to 20secs in iphone client, this got active pretty quickly.
2009-12-09log file base name: configurable via "filename" config optionPatrick Ohly1-1/+4
Previously, the base part of the log file name was hard-coded inside libsynthesis at compile time via the TARGETID. Apps might have no control over how the library is compiled, so this patch adds a configuration option called "filename" (similar to "filesuffix/prefix") for this. SyncEvolution uses this option to ensure that the filename is "syncevolution-log.html", no matter how the library was compiled. It must know what the file is called because it prints the name in an error message on the command line.
2009-12-09Revert "TSyncSession::checkCredentials(): <requiredauth>none => accept ↵Patrick Ohly1-8/+0
invalid credentials" This reverts commit b76470a04038b601a2521a7e496ccde08efc5fa9. Lukas prefers to keep the old functionality and suggested to provide a <logininitscript> which returns TRUE in servers which need no credential checking. Will do that in SyncEvolution.
2009-12-09TSyncSession::checkCredentials(): <requiredauth>none => accept invalid ↵Patrick Ohly1-0/+8
credentials This changes the meaning of <requiredauth>none</requiredauth> from "all kinds of authentication methods allowed, including none" to "all kinds of credentials allowed, including invalid ones". Because a client with invalid credentials was already allowed to connect by not sending them, this doesn't make a server setup less secure. It has the advantage that the client setup becomes easier.
2009-12-09TSyncSession::initSync(): avoid #warning in gccPatrick Ohly1-1/+1
gcc -Wall -Werror aborts when running into #warning. As a workaround avoid the #warning when compiling with gcc.
2009-12-02english language cosmetics: there were still a lot of "eventual" uses that ↵Lukas Zeller1-8/+8
should have been "possible" See f78a532753 (comments: corrected wrong usage of english word "eventually" throughout all sources.) for more context.
2009-11-25Touch up to make compile again in client-only builds (and also WinMobile)Lukas Zeller1-5/+11
2009-11-04Some compilers don't not like #ifdefs within function argument listLukas Zeller1-10/+9
2009-11-04comments: corrected wrong usage of english word "eventually" throughout all ↵Lukas Zeller1-3/+3
sources. "eventually" was used all over the project to express "possibly". The reason why this happened is only apparent for German speakers - in German, "eventuell" in fact has the meaning of the English word "possibly". A classical case of a "false friend"... (http://en.wikipedia.org/wiki/False_friend)
2009-11-04MIME-DIR, remote rules: default charset interpretation now UTF-8 (no longer ↵Lukas Zeller1-1/+7
ANSI), added <inputcharset> to override For some now probably mostly irrelevant devices like T39m, T68 and V3i we had mimo_old interpret strings as ANSI when they had no CHARSET=xxx parameter. This conflicts with newer servers like DeskNow (they send UTF-8, but no CHARSET). So the new default is now UTF-8, but for the server side the new <inputcharset> remote rule option can change that on a per device basis.
2009-10-18Alert 222 loop detector improved: do not trigger as long as valid status is ↵Lukas Zeller1-0/+4
received Patrick observed permature session abort because the Alert 222 loop detector counted 5 Alert 222 messages in less than 20 seconds. There is a perfectly valid case where this could happen: - client sends a message to the server with a very compact list of deleted items - server responds with several (> 5) messages that contain the Status messages for the deletes, one by one (a bit strange, but valid). - soon the client has no changes left while the server is still sending status replies, so the client starts sending Alert 222. - After 5 alerts the session was aborted. The fix is now to reset the 222 alert counter fOutgoingAlert222Count whenever a essential (i.e. required) status response is received. So as long as the server sends status, the 222 loop detector will not trigger.
2009-10-14unilib: eliminated another bunch of printf argument warnings by casting all ↵Lukas Zeller1-1/+2
%ld arguments to (long) Note: this makes such args 64bit compatible, as long becomes 64bit automatically on 64bit arch.
2009-10-13unilib cleanup: fixed some build problems introduced through unilibLukas Zeller1-6/+6
2009-10-03Merge branch 'luz' into unilibLukas Zeller1-0/+1
2009-10-03TSyncSession: unitialized fEncodingPatrick Ohly1-0/+1
When an app using the server engine doesn't set the encoding, the TSyncSession::fEncoding member was used uninitialized. Setting it in the TSyncSession to SML_UNDEF fixes this and activates the "guess encoding based on message content" branch, as intended.
2009-10-03unilib: fixes needed to actually have both client&server enabled in the same ↵Lukas Zeller1-1/+11
build localengineds/superdatastore: client with superdatastore was old code that needed fixing to compile. (Generating maps from a superdatastore was never used so far as we didn't have any client side superdatastores). WARNING: client-side superdatastores are not tested at all. (but also have no real use case)
2009-10-03unilib: united former syncserver/syncclient into syncagent.h/.cppLukas Zeller1-3/+4
- Reason to do it was to allow deriving more specialized agents without having to decide about server/client when specializing and without introducing multiple inheritance hassles. - TAgentConfig class name re-used (was a useless intermediate class between TConfigElement and TSessionConfig). Now it became the replacement for TServerConfig/TClientConfig.
2009-10-03unilib started: engine version 3.3.0.0 to differentiate from normal 3.2.x.x ↵Lukas Zeller1-98/+110
non-unified builds - First walktrough to replace #if(n)def SYSYNC_CLIENT with new unilib macros IS_CLIENT, IS_SERVER which expand to constants in client-only or server-only builds, but query appBase for isServer() when both variants are included.
2009-09-24libsynthesis_srv: implementation complete - runs sync sessions ok with ↵Lukas Zeller1-0/+10
textDB backend. - first working version - beta quality only! - added comm config level <sessionidcgi> boolean flag to enable (default) or disable adding a RespURI with sessionID included as CGI variable. Can be set to false for transports that don't need it (OBEX for example). Note that there is also a session level variable (see below). - added <sendrespuri> and <respurionlywhendifferent> for RespURI control. - added "sendrespuri" session key field to allow turning on and off respuri on a per-session level, for example for multi-protocol servers (need RespURI for HTTP, must not have it for OBEX..)
2009-09-24cleanup: eliminated some compiler warnings about shadowing local declarationsLukas Zeller1-12/+12
2009-09-21engine 3.2.1.0: added "lenientMode" to ignore anchor mismatches in client, ↵Lukas Zeller1-0/+10
ignore missing status for get/alert 222 The new mode can be enabled by setting PROFILEFLAG_LENIENTMODE in the profileFlags of a client profile, or it can be enabled for servers using the new <lenientmode> option in <remoterule>s.
2009-09-21memory leak fixed: session script context was not deleted in session destructorLukas Zeller1-15/+15
This was a side effect of a change made earlier (May 2009), which was keeping the session script context at InternalResetSessionEx(). At that time, I forgot to add a delete in the destructor (via TerminateSession()) instead.