From a96380a0dc6dbf8c3443560eec458ac0d22d7820 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Tue, 28 Jan 2014 13:51:21 -0500 Subject: [PATCH] Fixed SyncKey issue not being updated during the sync operation --- ActiveSync/SOGoActiveSyncDispatcher+Sync.m | 56 +++++++++++++--------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/ActiveSync/SOGoActiveSyncDispatcher+Sync.m b/ActiveSync/SOGoActiveSyncDispatcher+Sync.m index 90b510abd..442589bd4 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher+Sync.m +++ b/ActiveSync/SOGoActiveSyncDispatcher+Sync.m @@ -680,15 +680,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NSString *collectionId, *realCollectionId, *syncKey, *davCollectionTag, *bodyPreferenceType; SOGoMicrosoftActiveSyncFolderType folderType; id collection, value; - + + NSMutableString *changeBuffer, *commandsBuffer; BOOL getChanges, first_sync; - + + changeBuffer = [NSMutableString string]; + commandsBuffer = [NSMutableString string]; + collectionId = [[(id)[theDocumentElement getElementsByTagName: @"CollectionId"] lastObject] textValue]; realCollectionId = [collectionId realCollectionIdWithFolderType: &folderType]; collection = [self collectionFromId: realCollectionId type: folderType]; - syncKey = [[(id)[theDocumentElement getElementsByTagName: @"SyncKey"] lastObject] textValue]; - davCollectionTag = [collection davCollectionTag]; + syncKey = davCollectionTag = [[(id)[theDocumentElement getElementsByTagName: @"SyncKey"] lastObject] textValue]; // From the documention, if GetChanges is missing, we must assume it's a YES. // See http://msdn.microsoft.com/en-us/library/gg675447(v=exchg.80).aspx for all details. @@ -715,21 +718,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [context setObject: bodyPreferenceType forKey: @"BodyPreferenceType"]; - [theBuffer appendString: @""]; - - if (folderType == ActiveSyncMailFolder) - [theBuffer appendString: @"Email"]; - else if (folderType == ActiveSyncContactFolder) - [theBuffer appendString: @"Contacts"]; - else if (folderType == ActiveSyncEventFolder) - [theBuffer appendString: @"Calendar"]; - else if (folderType == ActiveSyncTaskFolder) - [theBuffer appendString: @"Tasks"]; - - [theBuffer appendFormat: @"%@", davCollectionTag]; - [theBuffer appendFormat: @"%@", collectionId]; - [theBuffer appendFormat: @"%d", 1]; - // We generate the commands, if any, for the response. We might also have // generated some in processSyncCommand:inResponse: as we could have // received a Fetch command @@ -740,7 +728,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. withSyncKey: syncKey withFolderType: folderType withFilterType: [NSCalendarDate dateFromFilterType: [[(id)[theDocumentElement getElementsByTagName: @"FilterType"] lastObject] textValue]] - inBuffer: theBuffer]; + inBuffer: changeBuffer]; } // @@ -761,11 +749,35 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. processed: &processed]; if (processed) - [theBuffer appendFormat: @"%@", s]; + [commandsBuffer appendFormat: @"%@", s]; else - [theBuffer appendString: s]; + [commandsBuffer appendString: s]; } + // If we got any changes or if we have applied any commands + // let's regenerate our SyncKey based on the collection tag. + if ([changeBuffer length] || [commandsBuffer length]) + davCollectionTag = [collection davCollectionTag]; + + // Generate the response buffer + [theBuffer appendString: @""]; + + if (folderType == ActiveSyncMailFolder) + [theBuffer appendString: @"Email"]; + else if (folderType == ActiveSyncContactFolder) + [theBuffer appendString: @"Contacts"]; + else if (folderType == ActiveSyncEventFolder) + [theBuffer appendString: @"Calendar"]; + else if (folderType == ActiveSyncTaskFolder) + [theBuffer appendString: @"Tasks"]; + + [theBuffer appendFormat: @"%@", davCollectionTag]; + [theBuffer appendFormat: @"%@", collectionId]; + [theBuffer appendFormat: @"%d", 1]; + + [theBuffer appendString: changeBuffer]; + [theBuffer appendString: commandsBuffer]; + [theBuffer appendString: @""]; }