From ddaf28fc24e72b79176ec8b909efa223c4184d9f Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Wed, 23 Jun 2010 14:47:20 +0000 Subject: [PATCH] Monotone-Parent: 60c0036b3723ee42d8b8cbed474b6c6eac6c5e9a Monotone-Revision: 432bfd0df53df4464e70c8b82989b3fcc7aa849e Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-06-23T14:47:20 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 10 +++++ SoObjects/SOGo/SOGoGCSFolder.m | 77 ++++++++++++++++++++++++++-------- 2 files changed, 70 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 463210821..a68afa263 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-06-23 Wolfgang Sourdeau + + * SoObjects/SOGo/SOGoGCSFolder.m (-_lastModified): new method that + returns the last modified timestamp of the folder. Taken from + previous implementation of davCollectionTag. + (-davCollectionTag): make use of the new method above. + (_isValidSyncToken:): new method that perform a real validation of + the sync token passed as parameter. + (-davSyncCollection): make use of the new method above. + 2010-06-22 Wolfgang Sourdeau * SoObjects/SOGo/SOGoDAVAuthenticator.m (-checkLogin:andPassword:) diff --git a/SoObjects/SOGo/SOGoGCSFolder.m b/SoObjects/SOGo/SOGoGCSFolder.m index 5cbfccb53..3c9022339 100644 --- a/SoObjects/SOGo/SOGoGCSFolder.m +++ b/SoObjects/SOGo/SOGoGCSFolder.m @@ -776,14 +776,14 @@ static NSArray *childRecordFields = nil; } } -- (NSString *) davCollectionTag +- (int) _lastModified { NSArray *records; GCSFolder *folder; EOFetchSpecification *cTagSpec; EOSortOrdering *ordering; NSNumber *lastModified; - NSString *cTag; + int value; folder = [self ocsFolder]; ordering = [EOSortOrdering sortOrderingWithKey: @"c_lastmodified" @@ -800,12 +800,17 @@ static NSArray *childRecordFields = nil; { lastModified = [[records objectAtIndex: 0] objectForKey: @"c_lastmodified"]; - cTag = [lastModified stringValue]; + value = [lastModified intValue]; } else - cTag = @"-1"; + value = -1; - return cTag; + return value; +} + +- (NSString *) davCollectionTag +{ + return [NSString stringWithFormat: @"%d", [self _lastModified]]; } - (BOOL) userIsSubscriber: (NSString *) subscribingUser @@ -1207,7 +1212,7 @@ static NSArray *childRecordFields = nil; SEL *selectors; max = [properties count]; - selectors = NSZoneMalloc (NULL, sizeof (max * sizeof (SEL))); + selectors = NSZoneMalloc (NULL, max * sizeof (SEL)); for (count = 0; count < max; count++) selectors[count] = SOGoSelectorForPropertyGetter ([properties objectAtIndex: count]); @@ -1254,6 +1259,43 @@ static NSArray *childRecordFields = nil; appendContentString: [multistatus asWebDavStringWithNamespaces: nil]]; } +- (BOOL) _isValidSyncToken: (NSString *) syncToken +{ + unichar *characters; + int count, max, value; + BOOL valid; + + max = [syncToken length]; + if (max > 0) + { + characters = NSZoneMalloc (NULL, max * sizeof (unichar)); + [syncToken getCharacters: characters]; + if (max == 2 + && characters[0] == '-' + && characters[1] == '1') + valid = YES; + else + { + valid = YES; + value = 0; + for (count = 0; valid && count < max; count++) + { + if (characters[count] < '0' + || characters[count] > '9') + valid = NO; + else + value = value * 10 + characters[count] - '0'; + } + valid |= (value <= [self _lastModified]); + } + NSZoneFree (NULL, characters); + } + else + valid = YES; + + return valid; +} + - (WOResponse *) davSyncCollection: (WOContext *) localContext { WOResponse *r; @@ -1270,17 +1312,18 @@ static NSArray *childRecordFields = nil; documentElement = (DOMElement *) [document documentElement]; syncToken = [[documentElement firstElementWithTag: @"sync-token" inNamespace: XMLNS_WEBDAV] textValue]; - - propElement = [documentElement firstElementWithTag: @"prop" - inNamespace: XMLNS_WEBDAV]; - properties = [self parseDAVRequestedProperties: propElement]; - records = [self _fetchSyncTokenFields: properties - matchingSyncToken: syncToken]; - if (![syncToken length] || [records count]) - [self _appendComponentProperties: [properties allKeys] - fromRecords: records - matchingSyncToken: [syncToken intValue] - toResponse: r]; + if ([self _isValidSyncToken: syncToken]) + { + propElement = [documentElement firstElementWithTag: @"prop" + inNamespace: XMLNS_WEBDAV]; + properties = [self parseDAVRequestedProperties: propElement]; + records = [self _fetchSyncTokenFields: properties + matchingSyncToken: syncToken]; + [self _appendComponentProperties: [properties allKeys] + fromRecords: records + matchingSyncToken: [syncToken intValue] + toResponse: r]; + } else [r appendDAVError: davElement (@"valid-sync-token", XMLNS_WEBDAV)];