forked from mattrajca/DAVKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b5d992c
Showing
39 changed files
with
2,823 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// | ||
// Prefix header for all source files of the 'DAVKit' target in the 'DAVKit' project. | ||
// | ||
|
||
#ifdef __OBJC__ | ||
#import <Foundation/Foundation.h> | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>English</string> | ||
<key>CFBundleExecutable</key> | ||
<string>${EXECUTABLE_NAME}</string> | ||
<key>CFBundleIconFile</key> | ||
<string></string> | ||
<key>CFBundleIdentifier</key> | ||
<string>com.MattRajca.${PRODUCT_NAME:rfc1034Identifier}</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>${PRODUCT_NAME}</string> | ||
<key>CFBundlePackageType</key> | ||
<string>FMWK</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
<key>NSPrincipalClass</key> | ||
<string></string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2010 Matt Rajca | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
DAVKit | ||
====== | ||
|
||
DAVKit is a simple Cocoa framework for communicating with WebDAV servers. It supports downloading, uploading, copying, moving, and deleting files and folders, all completely asynchronously. By subclassing `DAVRequest`, you can extend the existing support for WebDAV requests to suit your own needs. Unit test are also included for all of the supported requests. If DAVKit is missing something, or you would like to submit a patch, please file an issue in the issue tracker. | ||
|
||
Basic Usage | ||
----------- | ||
|
||
To get started, include the DAVKit framework in your Mac OS X application target per usual. To use DAVKit on iPhone, copy the contents of the Sources directory into your own project. | ||
|
||
All of the WebDAV requests are sent using the `DAVSession` class. Initialize `DAVSession` like so: | ||
|
||
DAVCredentials *creds = [DAVCredentials credentialsWithUsername:@"USER" | ||
password:@"PASS"]; | ||
|
||
NSString *root = @"http://idisk.me.com/matt.rajca"; // don't include the trailing / (slash) | ||
|
||
DAVSession *session = [[DAVSession alloc] initWithRootURL:root | ||
credentials:creds]; | ||
|
||
|
||
`DAVSession` itself acts like a queue, limiting the number of requests it can make at any single time. The default is `2`. To enqueue a new WebDAV request, instantiate one of the subclasses of `DAVRequest`, and pass it to `DAVSession` as shown below: | ||
|
||
[session enqueueRequest:subclassOfDAVRequest]; | ||
|
||
To receive callbacks when the state of the request changes, register yourself as the delegate of the instance of `DAVRequest` before enqueueing it. | ||
|
||
|
||
Credits | ||
------- | ||
|
||
Thanks to Peter Hosey for the ISO8601DateFormatter class! | ||
|
||
License | ||
------- | ||
|
||
Copyright (c) 2010 Matt Rajca | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// DAVCredentials.h | ||
// DAVKit | ||
// | ||
// Copyright Matt Rajca 2010. All rights reserved. | ||
// | ||
|
||
/* Only Basic authentication is supported */ | ||
|
||
@interface DAVCredentials : NSObject { | ||
@private | ||
NSString *_username; | ||
NSString *_password; | ||
} | ||
|
||
@property (readonly) NSString *username; | ||
@property (readonly) NSString *password; | ||
|
||
+ (id)credentialsWithUsername:(NSString *)username password:(NSString *)password; | ||
- (id)initWithUsername:(NSString *)username password:(NSString *)password; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// DAVCredentials.m | ||
// DAVKit | ||
// | ||
// Copyright Matt Rajca 2010. All rights reserved. | ||
// | ||
|
||
#import "DAVCredentials.h" | ||
|
||
@implementation DAVCredentials | ||
|
||
@synthesize username = _username; | ||
@synthesize password = _password; | ||
|
||
+ (id)credentialsWithUsername:(NSString *)username password:(NSString *)password { | ||
return [[[[self class] alloc] initWithUsername:username password:password] autorelease]; | ||
} | ||
|
||
- (id)initWithUsername:(NSString *)username password:(NSString *)password { | ||
NSParameterAssert(username != nil); | ||
NSParameterAssert(password != nil); | ||
|
||
self = [super init]; | ||
if (self) { | ||
_username = [username copy]; | ||
_password = [password copy]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc { | ||
[_username release]; | ||
[_password release]; | ||
|
||
[super dealloc]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// DAVKit.h | ||
// DAVKit | ||
// | ||
// Copyright Matt Rajca 2010. All rights reserved. | ||
// | ||
|
||
#import <DAVKit/DAVCredentials.h> | ||
#import <DAVKit/DAVRequest.h> | ||
#import <DAVKit/DAVRequests.h> | ||
#import <DAVKit/DAVResponseItem.h> | ||
#import <DAVKit/DAVSession.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// DAVListingParser.h | ||
// DAVKit | ||
// | ||
// Copyright Matt Rajca 2010. All rights reserved. | ||
// | ||
|
||
@class DAVResponseItem; | ||
|
||
@interface DAVListingParser : NSObject < NSXMLParserDelegate > { | ||
@private | ||
NSXMLParser *_parser; | ||
NSMutableString *_currentString; | ||
NSMutableArray *_items; | ||
DAVResponseItem *_currentItem; | ||
} | ||
|
||
- (id)initWithData:(NSData *)data; | ||
|
||
- (NSArray *)parse:(NSError **)error; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// | ||
// DAVListingParser.m | ||
// DAVKit | ||
// | ||
// Copyright Matt Rajca 2010. All rights reserved. | ||
// | ||
|
||
#import "DAVListingParser.h" | ||
|
||
#import "DAVResponseItem.h" | ||
#import "ISO8601DateFormatter.h" | ||
|
||
@interface DAVListingParser () | ||
|
||
- (NSDate *)_ISO8601DateWithString:(NSString *)aString; | ||
|
||
@end | ||
|
||
|
||
@implementation DAVListingParser | ||
|
||
- (id)initWithData:(NSData *)data { | ||
NSParameterAssert(data != nil); | ||
|
||
self = [super init]; | ||
if (self) { | ||
_items = [[NSMutableArray alloc] init]; | ||
|
||
_parser = [[NSXMLParser alloc] initWithData:data]; | ||
[_parser setDelegate:self]; | ||
} | ||
return self; | ||
} | ||
|
||
- (NSArray *)parse:(NSError **)error { | ||
if (![_parser parse]) { | ||
if (error) { | ||
*error = [_parser parserError]; | ||
} | ||
|
||
return nil; | ||
} | ||
|
||
return [[_items copy] autorelease]; | ||
} | ||
|
||
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { | ||
[_currentString appendString:string]; | ||
} | ||
|
||
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName | ||
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName | ||
attributes:(NSDictionary *)attributeDict { | ||
|
||
_currentString = [[NSMutableString alloc] init]; | ||
|
||
if ([elementName isEqualToString:@"D:response"]) { | ||
_currentItem = [[DAVResponseItem alloc] init]; | ||
} | ||
} | ||
|
||
- (NSDate *)_ISO8601DateWithString:(NSString *)aString { | ||
ISO8601DateFormatter *formatter = [[ISO8601DateFormatter alloc] init]; | ||
|
||
NSDate *date = [formatter dateFromString:aString]; | ||
[formatter release]; | ||
|
||
return date; | ||
} | ||
|
||
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName | ||
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { | ||
|
||
if ([elementName isEqualToString:@"D:href"]) { | ||
_currentItem.href = _currentString; | ||
} | ||
else if ([elementName isEqualToString:@"D:getcontentlength"]) { | ||
_currentItem.contentLength = [_currentString integerValue]; | ||
} | ||
else if ([elementName isEqualToString:@"D:getcontenttype"]) { | ||
_currentItem.contentType = _currentString; | ||
} | ||
else if ([elementName isEqualToString:@"D:modificationdate"]) { | ||
_currentItem.modificationDate = [self _ISO8601DateWithString:_currentString]; | ||
} | ||
else if ([elementName isEqualToString:@"D:creationdate"]) { | ||
_currentItem.creationDate = [self _ISO8601DateWithString:_currentString]; | ||
} | ||
else if ([elementName isEqualToString:@"D:response"]) { | ||
[_items addObject:_currentItem]; | ||
|
||
[_currentItem release]; | ||
_currentItem = nil; | ||
} | ||
|
||
[_currentString release]; | ||
_currentString = nil; | ||
} | ||
|
||
- (void)dealloc { | ||
[_parser release]; | ||
[_currentString release]; | ||
[_items release]; | ||
[_currentItem release]; | ||
|
||
[super dealloc]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// DAVRequest+Private.h | ||
// DAVKit | ||
// | ||
// Copyright Matt Rajca 2010. All rights reserved. | ||
// | ||
|
||
@class DAVSession; | ||
|
||
@interface DAVRequest (Private) | ||
|
||
- (void)setParentSession:(DAVSession *)parentSession; | ||
- (NSMutableURLRequest *)newRequestWithPath:(NSString *)path method:(NSString *)method; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// DAVRequest.h | ||
// DAVKit | ||
// | ||
// Copyright Matt Rajca 2010. All rights reserved. | ||
// | ||
|
||
@class DAVSession; | ||
@protocol DAVRequestDelegate; | ||
|
||
/* codes returned are HTTP status codes */ | ||
extern NSString *const DAVClientErrorDomain; | ||
|
||
@interface DAVRequest : NSOperation { | ||
@private | ||
NSString *_path; | ||
NSURLConnection *_connection; | ||
NSMutableData *_data; | ||
BOOL _done; | ||
BOOL _executing; | ||
|
||
__weak DAVSession *_parentSession; | ||
__weak id < DAVRequestDelegate > _delegate; | ||
} | ||
|
||
@property (readonly) NSString *path; | ||
|
||
@property (assign) __weak id < DAVRequestDelegate > delegate; | ||
|
||
- (id)initWithPath:(NSString *)aPath; | ||
|
||
- (NSString *)concatenatedURLWithPath:(NSString *)aPath; | ||
|
||
/* must be overriden by subclasses */ | ||
- (NSURLRequest *)request; | ||
|
||
/* optional override */ | ||
- (id)resultForData:(NSData *)data; | ||
|
||
@end | ||
|
||
|
||
@protocol DAVRequestDelegate < NSObject > | ||
|
||
@optional | ||
|
||
// The error can be a NSURLConnection error or a WebDAV error | ||
- (void)request:(DAVRequest *)aRequest didFailWithError:(NSError *)error; | ||
|
||
// The resulting object varies depending on the request type | ||
- (void)request:(DAVRequest *)aRequest didSucceedWithResult:(id)result; | ||
|
||
@end |
Oops, something went wrong.