Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Mac OS X
*.DS_Store
.DS_Store

# Xcode
*.pbxuser
Expand Down
Binary file modified src/.DS_Store
Binary file not shown.
Binary file modified src/ACWebDAV/.DS_Store
Binary file not shown.
6 changes: 5 additions & 1 deletion src/ACWebDAV/ACWebDAVClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,15 @@
@protocol ACWebDAVClientDelegate <NSObject>

@optional
- (BOOL)needToCancelDownload;
- (void)resetCancelDownload:(BOOL)cancel;
- (BOOL)needToCancelUpload;
- (void)resetCancelUpload:(BOOL)cancel;

- (void)client:(ACWebDAVClient*)client failedWithError:(NSError*)error;
- (void)client:(ACWebDAVClient*)client failedWithErrorCode:(int)errorCode;

- (void)client:(ACWebDAVClient*)client loadedMetadata:(ACWebDAVItem*)item;
- (void)client:(ACWebDAVClient*)client loadedMetadata:(NSArray *)items;
- (void)client:(ACWebDAVClient*)client loadMetadataFailedWithError:(NSError*)error;
- (void)client:(ACWebDAVClient*)client loadMetadataFailedWithErrorCode:(int)errorCode;

Expand Down
71 changes: 60 additions & 11 deletions src/ACWebDAV/ACWebDAVClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ +(ACWebDAVClient*)clientForMobileMeWithUsername:(NSString *)_username password:(
return [self clientWithHost:[@"http://idisk.mac.com/" stringByAppendingString:_username] username:_username password:_password];
}





#pragma mark -
#pragma mark Properties

Expand All @@ -57,6 +61,11 @@ -(void)setHost:(NSString*)value {
}
}






#pragma mark -
#pragma mark Client Methods

Expand Down Expand Up @@ -112,7 +121,7 @@ -(void)copyFrom:(NSString*)fromHref toPath:(NSString*)toHref {
-(void)copyFrom:(NSString*)fromHref toPath:(NSString*)toHref overwrite:(BOOL)overwrite {
ACWebDAVLocation* location = [ACWebDAVLocation locationWithHost:self.host href:fromHref username:self.username password:self.password];
ACWebDAVLocation* destination = [ACWebDAVLocation locationWithHost:self.host href:toHref username:self.username password:self.password];
ACWebDAVCopyRequest* request = [ACWebDAVCopyRequest requestToCopyItem:[ACWebDAVItem itemWithLocation:location] toLocation:destination delegate:self];
ACWebDAVCopyRequest* request = [ACWebDAVCopyRequest requestToCopyItem:[ACWebDAVItem itemWithLocation:location] toLocation:destination overWrite:NO delegate:self];
[request start];
}

Expand All @@ -123,7 +132,7 @@ -(void)moveFrom:(NSString*)fromHref toPath:(NSString*)toHref {
-(void)moveFrom:(NSString*)fromHref toPath:(NSString*)toHref overwrite:(BOOL)overwrite {
ACWebDAVLocation* location = [ACWebDAVLocation locationWithHost:self.host href:fromHref username:self.username password:self.password];
ACWebDAVLocation* destination = [ACWebDAVLocation locationWithHost:self.host href:toHref username:self.username password:self.password];
ACWebDAVMoveRequest* request = [ACWebDAVMoveRequest requestToMoveItem:[ACWebDAVItem itemWithLocation:location] toLocation:destination delegate:self];
ACWebDAVMoveRequest* request = [ACWebDAVMoveRequest requestToMoveItem:[ACWebDAVItem itemWithLocation:location] toLocation:destination overWrite:NO delegate:self];
[request start];
}

Expand All @@ -142,23 +151,56 @@ -(void)unlockPath:(NSString *)href token:(NSString*)token {
[request start];
}







#pragma mark -
#pragma mark Delegate Handlers

-(void)request:(ACWebDAVPropertyRequest*)request didReturnItems:(NSArray*)items {
if([self.delegate respondsToSelector:@selector(client:loadedMetadata:)]) {

#pragma mark - List Request Methods
-(void)request:(ACWebDAVPropertyRequest*)request didReturnItems:(NSArray*)items
{
NSLog(@"============= didReturnItems ===============");
if([self.delegate respondsToSelector:@selector(client:loadedMetadata:)])
{
if(items == nil || items.count < 1) {
[self.delegate client:self loadedMetadata:nil];
} else {
[self.delegate client:self loadedMetadata:[items objectAtIndex:0]];
}
else
{
[self.delegate client:self loadedMetadata:items];
}
}
}

-(void)request:(ACWebDAVDownloadRequest*)request didUpdateDownloadProgress:(float)percent {
if([self.delegate respondsToSelector:@selector(client:downloadProgress:forFile:)]) {
[self.delegate client:self downloadProgress:percent forFile:[request.userInfo objectForKey:@"destinationPath"]];
}
-(void)request:(ACWebDAVDownloadRequest*)request didUpdateDownloadProgress:(float)percent
{
if([self.delegate respondsToSelector:@selector(needToCancelDownload)])
{
BOOL cancel = [self.delegate needToCancelDownload];
if (cancel==NO)
{
if([self.delegate respondsToSelector:@selector(client:downloadProgress:forFile:)])
{
[self.delegate client:self downloadProgress:percent
forFile:[request.userInfo objectForKey:@"destinationPath"]];
}
}
else
{
[request cancel];
if ([self.delegate respondsToSelector:@selector(resetCancelDownload:)])
{
[self.delegate resetCancelDownload:NO];
}
}
}


}

-(void)request:(ACWebDAVDownloadRequest*)request didCompleteDownload:(NSData*)data {
Expand All @@ -168,7 +210,14 @@ -(void)request:(ACWebDAVDownloadRequest*)request didCompleteDownload:(NSData*)da
[self.delegate client:self downloadedFileData:data];
}
} else {
[data writeToFile:path atomically:YES];
if ([data writeToFile:path atomically:YES])
{
NSLog(@"write to file:%@ Success",path);
}
else
{
NSLog(@"write to file:%@ Failed",path);
}
if([self.delegate respondsToSelector:@selector(client:downloadedFile:)]) {
[self.delegate client:self downloadedFile:path];
}
Expand Down
17 changes: 17 additions & 0 deletions src/ACWebDAV/Classes/ACWebDAVFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ -(id)initWithDictionary:(NSDictionary *)d {
return self;
}

-(NSString *)description
{
NSString *typeStr = (self.type==ACWebDAVItemTypeCollection)?@"Collection":@"File";
return [NSString stringWithFormat:@"\n=====item=====\n{\ttype:%@\n\tdisplayName:%@\n\thref:%@\n\tabsoluteHref:%@\n\tparentHref:%@\n\tabsoluteParentHref:%@\n\tcreationDate:%@\n\tlastModifiedDate:%@\n\turl:%@\n\tcontentType:%@\n\tcontentLength:%lld\n}",
typeStr,
self.displayName,
self.href,
self.absoluteHref,
self.parentHref,
self.absoluteParentHref,
self.creationDate,
self.lastModifiedDate,
self.url,
self.contentType,
self.contentLength];
}

-(void)dealloc {
[contentType release];
[super dealloc];
Expand Down
70 changes: 52 additions & 18 deletions src/ACWebDAV/Classes/ACWebDAVItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@

#import "ACWebDAVItem.h"
#import "ACWebDAV.h"
#import "ISO8601DateFormatter.h"
#import "NSDateRFC1123.h"




@implementation ACWebDAVItem

@synthesize type, href, displayName, creationDate, lastModifiedDate, location, delegate, lock;

-(id)initWithDictionary:(NSDictionary*)d {
if((self = [super init])) {

-(id)initWithDictionary:(NSDictionary*)d
{
if((self = [super init]))
{
// Set the type
if([[d objectForKey:@"resourcetype"] isEqualToString:@"collection"]) {
type = ACWebDAVItemTypeCollection;
Expand All @@ -26,25 +32,39 @@ -(id)initWithDictionary:(NSDictionary*)d {
// Set the href
href = [[d objectForKey:@"href"] retain];

static NSDateFormatter* dateFormatter;
if(dateFormatter == nil) {
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss Z"];
}

// Set the display name
displayName = [[d objectForKey:@"displayname"] retain];



//===============================
// Date Setting
//===============================
// Set the creation date
if([d objectForKey:@"creationdate"] != nil) {
creationDate = [[dateFormatter dateFromString:[d objectForKey:@"creationdate"]] retain];
NSString *createDateStr = [d objectForKey:@"creationdate"];
NSString *modifyDateStr = [d objectForKey:@"getlastmodified"];

if(createDateStr != nil)
{
ISO8601DateFormatter *formatter = [[ISO8601DateFormatter alloc] init];
creationDate = [formatter dateFromString:createDateStr];
[formatter release];

//change the GMT Date to localDate
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger timeInterval = [zone secondsFromGMTForDate:creationDate];
creationDate = [[creationDate dateByAddingTimeInterval: timeInterval] retain];
}

// Set the last modified date
if([d objectForKey:@"getlastmodified"] != nil) {
lastModifiedDate = [[dateFormatter dateFromString:[d objectForKey:@"getlastmodified"]] retain];
if(modifyDateStr != nil)
{
lastModifiedDate = [NSDate dateFromRFC1123:modifyDateStr];

//change the GMT Date to localDate
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger timeInterval = [zone secondsFromGMTForDate:lastModifiedDate];
lastModifiedDate = [[lastModifiedDate dateByAddingTimeInterval: timeInterval] retain];
}

// Set the display name
displayName = [[d objectForKey:@"displayname"] retain];

}
return self;
}
Expand Down Expand Up @@ -126,6 +146,20 @@ -(void)request:(ACWebDAVPropertyRequest *)request didReceiveProperties:(NSArray*
[self.delegate ACWebDAVItem:self didReceiveProperties:[properties objectAtIndex:0]];
}
}
-(NSString *)description
{
NSString *typeStr = (self.type==ACWebDAVItemTypeCollection)?@"Collection":@"File";
return [NSString stringWithFormat:@"=====item=====\n{\ttype:%@\n\tdisplayName:%@\n\thref:%@\n\tabsoluteHref:%@\n\tparentHref:%@\n\tabsoluteParentHref:%@\n\tcreationDate:%@\n\tlastModifiedDate:%@\n\turl:%@\n}",
typeStr,
self.displayName,
self.href,
self.absoluteHref,
self.parentHref,
self.absoluteParentHref,
self.creationDate,
self.lastModifiedDate,
self.url];
}

-(void)dealloc {
[href release];
Expand Down
79 changes: 79 additions & 0 deletions src/ACWebDAV/ISO8601/ISO8601DateFormatter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*ISO8601DateFormatter.h
*
*Created by Peter Hosey on 2009-04-11.
*Copyright 2009 Peter Hosey. All rights reserved.
*/

#import <Foundation/Foundation.h>

/*This class converts dates to and from ISO 8601 strings. A good introduction to ISO 8601: <http://www.cl.cam.ac.uk/~mgk25/iso-time.html>
*
*Parsing can be done strictly, or not. When you parse loosely, leading whitespace is ignored, as is anything after the date.
*The loose parser will return an NSDate for this string: @" \t\r\n\f\t 2006-03-02!!!"
*Leading non-whitespace will not be ignored; the string will be rejected, and nil returned. See the README that came with this addition.
*
*The strict parser will only accept a string if the date is the entire string. The above string would be rejected immediately, solely on these grounds.
*Also, the loose parser provides some extensions that the strict parser doesn't.
*For example, the standard says for "-DDD" (an ordinal date in the implied year) that the logical representation (meaning, hierarchically) would be "--DDD", but because that extra hyphen is "superfluous", it was omitted.
*The loose parser will accept the extra hyphen; the strict parser will not.
*A full list of these extensions is in the README file.
*/

/*The format to either expect or produce.
*Calendar format is YYYY-MM-DD.
*Ordinal format is YYYY-DDD, where DDD ranges from 1 to 366; for example, 2009-32 is 2009-02-01.
*Week format is YYYY-Www-D, where ww ranges from 1 to 53 (the 'W' is literal) and D ranges from 1 to 7; for example, 2009-W05-07.
*/
enum {
ISO8601DateFormatCalendar,
ISO8601DateFormatOrdinal,
ISO8601DateFormatWeek,
};
typedef NSUInteger ISO8601DateFormat;

//The default separator for time values. Currently, this is ':'.
extern unichar ISO8601DefaultTimeSeparatorCharacter;

@interface ISO8601DateFormatter: NSFormatter
{
NSString *lastUsedFormatString;
NSDateFormatter *unparsingFormatter;

NSCalendar *parsingCalendar, *unparsingCalendar;

NSTimeZone *defaultTimeZone;
ISO8601DateFormat format;
unichar timeSeparator;
BOOL includeTime;
BOOL parsesStrictly;
}

//Call this if you get a memory warning.
+ (void) purgeGlobalCaches;

@property(nonatomic, retain) NSTimeZone *defaultTimeZone;

#pragma mark Parsing

//As a formatter, this object converts strings to dates.

@property BOOL parsesStrictly;

- (NSDateComponents *) dateComponentsFromString:(NSString *)string;
- (NSDateComponents *) dateComponentsFromString:(NSString *)string timeZone:(out NSTimeZone **)outTimeZone;
- (NSDateComponents *) dateComponentsFromString:(NSString *)string timeZone:(out NSTimeZone **)outTimeZone range:(out NSRange *)outRange;

- (NSDate *) dateFromString:(NSString *)string;
- (NSDate *) dateFromString:(NSString *)string timeZone:(out NSTimeZone **)outTimeZone;
- (NSDate *) dateFromString:(NSString *)string timeZone:(out NSTimeZone **)outTimeZone range:(out NSRange *)outRange;

#pragma mark Unparsing

@property ISO8601DateFormat format;
@property BOOL includeTime;
@property unichar timeSeparator;

- (NSString *) stringFromDate:(NSDate *)date;
- (NSString *) stringFromDate:(NSDate *)date timeZone:(NSTimeZone *)timeZone;

@end
Loading