Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrajca committed Aug 19, 2010
0 parents commit b5d992c
Show file tree
Hide file tree
Showing 39 changed files with 2,823 additions and 0 deletions.
566 changes: 566 additions & 0 deletions DAVKit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions DAVKit_Prefix.pch
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
28 changes: 28 additions & 0 deletions Info.plist
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>
19 changes: 19 additions & 0 deletions LICENSE.txt
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.
55 changes: 55 additions & 0 deletions README.markdown
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.
22 changes: 22 additions & 0 deletions Sources/Core/DAVCredentials.h
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
38 changes: 38 additions & 0 deletions Sources/Core/DAVCredentials.m
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
12 changes: 12 additions & 0 deletions Sources/Core/DAVKit.h
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>
22 changes: 22 additions & 0 deletions Sources/Core/DAVListingParser.h
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
109 changes: 109 additions & 0 deletions Sources/Core/DAVListingParser.m
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
15 changes: 15 additions & 0 deletions Sources/Core/DAVRequest+Private.h
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
53 changes: 53 additions & 0 deletions Sources/Core/DAVRequest.h
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
Loading

0 comments on commit b5d992c

Please sign in to comment.