Skip to content
Browse files

Fake out lock refreshes.

1 parent 1b7b8e1 commit 2eaaaeadc698a05c31bf4d612afca87d0ef09828 Cameron Esfahani committed Apr 7, 2012
Showing with 20 additions and 7 deletions.
  1. +20 −7 Extensions/WebDAV/DAVResponse.m
View
27 Extensions/WebDAV/DAVResponse.m
@@ -244,6 +244,7 @@ - (id) initWithMethod:(NSString*)method headers:(NSDictionary*)headers bodyData:
NSString* scope = nil;
NSString* type = nil;
NSString* owner = nil;
+ NSString* token = nil;
xmlDocPtr document = xmlReadMemory(body.bytes, (int)body.length, NULL, NULL, kXMLParseOptions);
if (document) {
xmlNodePtr node = _XMLChildWithName(document->children, (const xmlChar*)"lockinfo");
@@ -267,15 +268,26 @@ - (id) initWithMethod:(NSString*)method headers:(NSDictionary*)headers bodyData:
HTTPLogWarn(@"HTTP Server: Invalid DAV properties\n%@", [[NSString alloc] initWithData:body encoding:NSUTF8StringEncoding]);
}
xmlFreeDoc(document);
- }
+ } else {
+ // No body, see if they're trying to refresh an existing lock. If so, then just fake up the scope, type and depth so we fall
+ // into the lock create case.
+ NSString* lockToken;
+ if ((lockToken = [headers objectForKey:@"If"]) != nil) {
+ scope = @"exclusive";
+ type = @"write";
+ depth = @"0";
+ token = [lockToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"(<>)"]];
+ }
+ }
if ([scope isEqualToString:@"exclusive"] && [type isEqualToString:@"write"] && [depth isEqualToString:@"0"] &&
([[NSFileManager defaultManager] fileExistsAtPath:path] || [[NSData data] writeToFile:path atomically:YES])) {
NSString* timeout = [headers objectForKey:@"Timeout"];
-
- CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
- NSString *uuidStr = (__bridge_transfer NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid);
- NSString* token = [NSString stringWithFormat:@"urn:uuid:%@", uuidStr];
- CFRelease(uuid);
+ if (!token) {
+ CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
+ NSString *uuidStr = (__bridge_transfer NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid);
+ token = [NSString stringWithFormat:@"urn:uuid:%@", uuidStr];
+ CFRelease(uuid);
+ }
NSMutableString* xmlString = [NSMutableString stringWithString:@"<?xml version=\"1.0\" encoding=\"utf-8\" ?>"];
[xmlString appendString:@"<D:prop xmlns:D=\"DAV:\">\n"];
@@ -290,7 +302,8 @@ - (id) initWithMethod:(NSString*)method headers:(NSDictionary*)headers bodyData:
[xmlString appendFormat:@"<D:timeout>%@</D:timeout>\n", timeout];
}
[xmlString appendFormat:@"<D:locktoken><D:href>%@</D:href></D:locktoken>\n", token];
- // [xmlString appendFormat:@"<D:lockroot><D:href>%@</D:href></D:lockroot>\n", root];
+ NSString* lockroot = [@"http://" stringByAppendingString:[[headers objectForKey:@"Host"] stringByAppendingString:[@"/" stringByAppendingString:resourcePath]]];
+ [xmlString appendFormat:@"<D:lockroot><D:href>%@</D:href></D:lockroot>\n", lockroot];
[xmlString appendString:@"</D:activelock>\n</D:lockdiscovery>\n"];
[xmlString appendString:@"</D:prop>"];

0 comments on commit 2eaaaea

Please sign in to comment.
Something went wrong with that request. Please try again.