diff --git a/ChangeLog b/ChangeLog index dde14dd2a..f901159d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2009-08-05 Wolfgang Sourdeau + * SoObjects/SOGo/SOGoGCSFolder.m (-davSyncCollection): enhanced to + return a DAV error with the "valid-sync-token" condition tag when + a token is provided while the collection is empty. + * SoObjects/SOGo/WOResponse+SOGo.m: new class module. (-appendDAVError:): utility method that adds and formats the XML body of a DAV error, with the error condition passed as argument. diff --git a/SoObjects/SOGo/SOGoGCSFolder.m b/SoObjects/SOGo/SOGoGCSFolder.m index a9d3e8d15..edcc5c0fd 100644 --- a/SoObjects/SOGo/SOGoGCSFolder.m +++ b/SoObjects/SOGo/SOGoGCSFolder.m @@ -69,6 +69,7 @@ #import "SOGoUser.h" #import "SOGoWebDAVAclManager.h" #import "WORequest+SOGo.h" +#import "WOResponse+SOGo.h" #import "SOGoGCSFolder.h" @@ -896,7 +897,7 @@ static NSArray *childRecordFields = nil; } - (NSArray *) _fetchSyncTokenFields: (NSDictionary *) properties - matchingSyncToken: (int) syncToken + matchingSyncToken: (NSString *) syncToken { /* TODO: - validation: @@ -908,6 +909,7 @@ static NSArray *childRecordFields = nil; EOQualifier *qualifier; NSEnumerator *addFields; NSString *currentField, *filter; + int syncTokenInt; fields = [NSMutableArray arrayWithObjects: @"c_name", @"c_component", @"c_creationdate", @"c_lastmodified", nil]; @@ -916,16 +918,17 @@ static NSArray *childRecordFields = nil; if ([currentField length]) [fields addObjectUniquely: currentField]; - if (syncToken) + if ([syncToken length]) { + syncTokenInt = [syncToken intValue]; qualifier = [EOQualifier qualifierWithQualifierFormat: - @"c_lastmodified > %d", syncToken]; + @"c_lastmodified > %d", syncTokenInt]; mRecords = [NSMutableArray arrayWithArray: [self _fetchFields: fields - withQualifier: qualifier - ignoreDeleted: YES]]; + withQualifier: qualifier + ignoreDeleted: YES]]; qualifier = [EOQualifier qualifierWithQualifierFormat: @"c_lastmodified > %d and c_deleted == 1", - syncToken]; + syncTokenInt]; fields = [NSMutableArray arrayWithObjects: @"c_name", @"c_deleted", nil]; [mRecords addObjectsFromArray: [self _fetchFields: fields withQualifier: qualifier @@ -1090,10 +1093,10 @@ static NSArray *childRecordFields = nil; if (newToken < currentLM) newToken = currentLM; [syncResponses addObject: [self _syncResponseWithProperties: properties - andMethodSelectors: selectors - fromRecord: record - withToken: syncToken - andBaseURL: baseURL]]; + andMethodSelectors: selectors + fromRecord: record + withToken: syncToken + andBaseURL: baseURL]]; } NSZoneFree (NULL, selectors); @@ -1122,15 +1125,12 @@ static NSArray *childRecordFields = nil; NSString *syncToken; NSDictionary *properties; NSArray *records; - int syncTokenInt; r = [context response]; - [r setStatus: 207]; [r setContentEncoding: NSUTF8StringEncoding]; [r setHeader: @"text/xml; charset=\"utf-8\"" forKey: @"content-type"]; [r setHeader: @"no-cache" forKey: @"pragma"]; [r setHeader: @"no-cache" forKey: @"cache-control"]; - [r appendContentString:@"\r\n"]; document = [[context request] contentAsDOMDocument]; documentElement = (DOMElement *) [document documentElement]; @@ -1139,15 +1139,21 @@ static NSArray *childRecordFields = nil; propElement = [documentElement firstElementWithTag: @"prop" inNamespace: XMLNS_WEBDAV]; - - syncTokenInt = [syncToken intValue]; properties = [self parseDAVRequestedProperties: propElement]; records = [self _fetchSyncTokenFields: properties - matchingSyncToken: syncTokenInt]; - [self _appendComponentProperties: [properties allKeys] - fromRecords: records - matchingSyncToken: syncTokenInt - toResponse: r]; + matchingSyncToken: syncToken]; + if (![syncToken length] || [records count]) + { + [r setStatus: 207]; + [r appendContentString: @"\r\n"]; + [self _appendComponentProperties: [properties allKeys] + fromRecords: records + matchingSyncToken: [syncToken intValue] + toResponse: r]; + } + else + [r appendDAVError: davElement (@"valid-sync-token", XMLNS_WEBDAV)]; return r; } diff --git a/Tests/README b/Tests/README index 1dc8e0de9..f409218ff 100644 --- a/Tests/README +++ b/Tests/README @@ -7,6 +7,11 @@ setup 2) edit testconfig.py to suit your environment 3) run the test scripts +runnable scripts +---------------- + +webdav-sync.py + other -----