Showing
6 changed files
with
75 additions
and
110 deletions
| @@ -8,14 +8,18 @@ | @@ -8,14 +8,18 @@ | ||
| 8 | 8 | ||
| 9 | #import "ASICloudFilesRequest.h" | 9 | #import "ASICloudFilesRequest.h" |
| 10 | 10 | ||
| 11 | +@class ASICloudFilesContainerXMLParserDelegate; | ||
| 11 | 12 | ||
| 12 | @interface ASICloudFilesCDNRequest : ASICloudFilesRequest { | 13 | @interface ASICloudFilesCDNRequest : ASICloudFilesRequest { |
| 13 | NSString *accountName; | 14 | NSString *accountName; |
| 14 | NSString *containerName; | 15 | NSString *containerName; |
| 16 | + ASICloudFilesContainerXMLParserDelegate *xmlParserDelegate; | ||
| 17 | + | ||
| 15 | } | 18 | } |
| 16 | 19 | ||
| 17 | @property (nonatomic, retain) NSString *accountName; | 20 | @property (nonatomic, retain) NSString *accountName; |
| 18 | @property (nonatomic, retain) NSString *containerName; | 21 | @property (nonatomic, retain) NSString *containerName; |
| 22 | +@property (nonatomic, retain) ASICloudFilesContainerXMLParserDelegate *xmlParserDelegate; | ||
| 19 | 23 | ||
| 20 | 24 | ||
| 21 | // HEAD /<api version>/<account>/<container> | 25 | // HEAD /<api version>/<account>/<container> |
| @@ -39,12 +43,18 @@ | @@ -39,12 +43,18 @@ | ||
| 39 | // PUT /<api version>/<account>/<container> | 43 | // PUT /<api version>/<account>/<container> |
| 40 | // PUT operations against a Container are used to CDN-enable that Container. | 44 | // PUT operations against a Container are used to CDN-enable that Container. |
| 41 | // Include an HTTP header of X-TTL to specify a custom TTL. | 45 | // Include an HTTP header of X-TTL to specify a custom TTL. |
| 46 | ++ (id)putRequestWithContainer:(NSString *)containerName; | ||
| 47 | ++ (id)putRequestWithContainer:(NSString *)containerName ttl:(NSUInteger)ttl; | ||
| 48 | +// returns: - (NSString *)cdnURI; | ||
| 42 | 49 | ||
| 43 | // POST /<api version>/<account>/<container> | 50 | // POST /<api version>/<account>/<container> |
| 44 | // POST operations against a CDN-enabled Container are used to adjust CDN attributes. | 51 | // POST operations against a CDN-enabled Container are used to adjust CDN attributes. |
| 45 | // The POST operation can be used to set a new TTL cache expiration or to enable/disable public sharing over the CDN. | 52 | // The POST operation can be used to set a new TTL cache expiration or to enable/disable public sharing over the CDN. |
| 46 | // X-TTL: 86400 | 53 | // X-TTL: 86400 |
| 47 | // X-CDN-Enabled: True | 54 | // X-CDN-Enabled: True |
| 55 | ++ (id)postRequestWithContainer:(NSString *)containerName; | ||
| 56 | ++ (id)postRequestWithContainer:(NSString *)containerName cdnEnabled:(BOOL)cdnEnabled ttl:(NSUInteger)ttl; | ||
| 57 | +// returns: - (NSString *)cdnURI; | ||
| 48 | 58 | ||
| 49 | 59 | ||
| 50 | @end | 60 | @end |
| @@ -7,11 +7,12 @@ | @@ -7,11 +7,12 @@ | ||
| 7 | // | 7 | // |
| 8 | 8 | ||
| 9 | #import "ASICloudFilesCDNRequest.h" | 9 | #import "ASICloudFilesCDNRequest.h" |
| 10 | +#import "ASICloudFilesContainerXMLParserDelegate.h" | ||
| 10 | 11 | ||
| 11 | 12 | ||
| 12 | @implementation ASICloudFilesCDNRequest | 13 | @implementation ASICloudFilesCDNRequest |
| 13 | 14 | ||
| 14 | -@synthesize accountName, containerName; | 15 | +@synthesize accountName, containerName, xmlParserDelegate; |
| 15 | 16 | ||
| 16 | + (id)cdnRequestWithMethod:(NSString *)method query:(NSString *)query { | 17 | + (id)cdnRequestWithMethod:(NSString *)method query:(NSString *)query { |
| 17 | NSString *urlString = [NSString stringWithFormat:@"%@%@", [ASICloudFilesRequest cdnManagementURL], query]; | 18 | NSString *urlString = [NSString stringWithFormat:@"%@%@", [ASICloudFilesRequest cdnManagementURL], query]; |
| @@ -55,7 +56,7 @@ | @@ -55,7 +56,7 @@ | ||
| 55 | #pragma mark GET - CDN Container Lists | 56 | #pragma mark GET - CDN Container Lists |
| 56 | 57 | ||
| 57 | + (id)listRequest { | 58 | + (id)listRequest { |
| 58 | - ASICloudFilesCDNRequest *request = [ASICloudFilesCDNRequest cdnRequestWithMethod:@"GET" query:nil]; | 59 | + ASICloudFilesCDNRequest *request = [ASICloudFilesCDNRequest cdnRequestWithMethod:@"GET" query:@"?format=xml"]; |
| 59 | return request; | 60 | return request; |
| 60 | } | 61 | } |
| 61 | 62 | ||
| @@ -79,24 +80,64 @@ | @@ -79,24 +80,64 @@ | ||
| 79 | } | 80 | } |
| 80 | 81 | ||
| 81 | - (NSArray *)containers { | 82 | - (NSArray *)containers { |
| 82 | - return nil; | 83 | + if (xmlParserDelegate.containerObjects) { |
| 83 | -} | 84 | + return xmlParserDelegate.containerObjects; |
| 85 | + } | ||
| 86 | + | ||
| 87 | + NSLog(@"list response data: %@", [self responseString]); | ||
| 88 | + | ||
| 89 | + NSXMLParser *parser = [[[NSXMLParser alloc] initWithData:[self responseData]] autorelease]; | ||
| 90 | + if (xmlParserDelegate == nil) { | ||
| 91 | + xmlParserDelegate = [[ASICloudFilesContainerXMLParserDelegate alloc] init]; | ||
| 92 | + } | ||
| 84 | 93 | ||
| 85 | -// GET /<api version>/<account> | 94 | + [parser setDelegate:xmlParserDelegate]; |
| 86 | -// limit, marker, format, enabled_only=true | 95 | + [parser setShouldProcessNamespaces:NO]; |
| 87 | -// + (id)getObjectRequestWithContainer:(NSString *)containerName objectPath:(NSString *)objectPath; | 96 | + [parser setShouldReportNamespacePrefixes:NO]; |
| 97 | + [parser setShouldResolveExternalEntities:NO]; | ||
| 98 | + [parser parse]; | ||
| 88 | 99 | ||
| 100 | + return xmlParserDelegate.containerObjects; | ||
| 101 | +} | ||
| 102 | + | ||
| 103 | +#pragma mark - | ||
| 104 | +#pragma mark PUT - CDN Enable Container | ||
| 89 | 105 | ||
| 90 | // PUT /<api version>/<account>/<container> | 106 | // PUT /<api version>/<account>/<container> |
| 91 | // PUT operations against a Container are used to CDN-enable that Container. | 107 | // PUT operations against a Container are used to CDN-enable that Container. |
| 92 | // Include an HTTP header of X-TTL to specify a custom TTL. | 108 | // Include an HTTP header of X-TTL to specify a custom TTL. |
| 109 | ++ (id)putRequestWithContainer:(NSString *)containerName { | ||
| 110 | + ASICloudFilesCDNRequest *request = [ASICloudFilesCDNRequest cdnRequestWithMethod:@"PUT" containerName:containerName]; | ||
| 111 | + return request; | ||
| 112 | +} | ||
| 113 | + | ||
| 114 | ++ (id)putRequestWithContainer:(NSString *)containerName ttl:(NSUInteger)ttl { | ||
| 115 | + ASICloudFilesCDNRequest *request = [ASICloudFilesCDNRequest cdnRequestWithMethod:@"PUT" containerName:containerName]; | ||
| 116 | + [request addRequestHeader:@"X-Ttl" value:[NSString stringWithFormat:@"%i", ttl]]; | ||
| 117 | + return request; | ||
| 118 | +} | ||
| 119 | + | ||
| 120 | +#pragma mark - | ||
| 121 | +#pragma mark POST - Adjust CDN Attributes | ||
| 93 | 122 | ||
| 94 | // POST /<api version>/<account>/<container> | 123 | // POST /<api version>/<account>/<container> |
| 95 | // POST operations against a CDN-enabled Container are used to adjust CDN attributes. | 124 | // POST operations against a CDN-enabled Container are used to adjust CDN attributes. |
| 96 | // The POST operation can be used to set a new TTL cache expiration or to enable/disable public sharing over the CDN. | 125 | // The POST operation can be used to set a new TTL cache expiration or to enable/disable public sharing over the CDN. |
| 97 | // X-TTL: 86400 | 126 | // X-TTL: 86400 |
| 98 | // X-CDN-Enabled: True | 127 | // X-CDN-Enabled: True |
| 128 | ++ (id)postRequestWithContainer:(NSString *)containerName { | ||
| 129 | + ASICloudFilesCDNRequest *request = [ASICloudFilesCDNRequest cdnRequestWithMethod:@"POST" containerName:containerName]; | ||
| 130 | + return request; | ||
| 131 | +} | ||
| 99 | 132 | ||
| 133 | ++ (id)postRequestWithContainer:(NSString *)containerName cdnEnabled:(BOOL)cdnEnabled ttl:(NSUInteger)ttl { | ||
| 134 | + ASICloudFilesCDNRequest *request = [ASICloudFilesCDNRequest cdnRequestWithMethod:@"POST" containerName:containerName]; | ||
| 135 | + if (ttl > 0) { | ||
| 136 | + [request addRequestHeader:@"X-Ttl" value:[NSString stringWithFormat:@"%i", ttl]]; | ||
| 137 | + } | ||
| 138 | + [request addRequestHeader:@"X-Ttl" value:cdnEnabled ? @"True" : @"False"]; | ||
| 139 | + return request; | ||
| 140 | +} | ||
| 100 | 141 | ||
| 101 | #pragma mark - | 142 | #pragma mark - |
| 102 | #pragma mark Memory Management | 143 | #pragma mark Memory Management |
| @@ -104,6 +145,7 @@ | @@ -104,6 +145,7 @@ | ||
| 104 | -(void)dealloc { | 145 | -(void)dealloc { |
| 105 | [accountName release]; | 146 | [accountName release]; |
| 106 | [containerName release]; | 147 | [containerName release]; |
| 148 | + [xmlParserDelegate release]; | ||
| 107 | [super dealloc]; | 149 | [super dealloc]; |
| 108 | } | 150 | } |
| 109 | 151 |
| @@ -11,9 +11,6 @@ | @@ -11,9 +11,6 @@ | ||
| 11 | @class ASICloudFilesContainer, ASICloudFilesContainerXMLParserDelegate; | 11 | @class ASICloudFilesContainer, ASICloudFilesContainerXMLParserDelegate; |
| 12 | 12 | ||
| 13 | @interface ASICloudFilesContainerRequest : ASICloudFilesRequest { | 13 | @interface ASICloudFilesContainerRequest : ASICloudFilesRequest { |
| 14 | - NSMutableArray *containerObjects; | ||
| 15 | - //NSUInteger containerCount; | ||
| 16 | - //NSUInteger bytesUsed; | ||
| 17 | 14 | ||
| 18 | // Internally used while parsing the response | 15 | // Internally used while parsing the response |
| 19 | NSString *currentContent; | 16 | NSString *currentContent; |
| @@ -111,10 +111,9 @@ | @@ -111,10 +111,9 @@ | ||
| 111 | #pragma mark Container List | 111 | #pragma mark Container List |
| 112 | 112 | ||
| 113 | - (NSArray *)containers { | 113 | - (NSArray *)containers { |
| 114 | - if (containerObjects) { | 114 | + if (xmlParserDelegate.containerObjects) { |
| 115 | - return containerObjects; | 115 | + return xmlParserDelegate.containerObjects; |
| 116 | } | 116 | } |
| 117 | - containerObjects = [[[NSMutableArray alloc] init] autorelease]; | ||
| 118 | 117 | ||
| 119 | //NSLog(@"list response data: %@", [self responseString]); | 118 | //NSLog(@"list response data: %@", [self responseString]); |
| 120 | 119 | ||
| @@ -133,68 +132,7 @@ | @@ -133,68 +132,7 @@ | ||
| 133 | } | 132 | } |
| 134 | 133 | ||
| 135 | #pragma mark - | 134 | #pragma mark - |
| 136 | -#pragma mark XML Parser Delegate | 135 | +#pragma mark Memory Management |
| 137 | - | ||
| 138 | -/* | ||
| 139 | - | ||
| 140 | - <container> | ||
| 141 | - <name>playground</name> | ||
| 142 | - <cdn_enabled>True</cdn_enabled> | ||
| 143 | - <ttl>259200</ttl> | ||
| 144 | - <cdn_url>http://c0023891.cdn.cloudfiles.rackspacecloud.com</cdn_url> | ||
| 145 | - <log_retention>True</log_retention> | ||
| 146 | - <referrer_acl></referrer_acl> | ||
| 147 | - <useragent_acl></useragent_acl> | ||
| 148 | - </container> | ||
| 149 | - | ||
| 150 | - | ||
| 151 | -<account name="MossoCloudFS_56ad0327-43d6-4ac4-9883-797f5690238e"> | ||
| 152 | - <container><name>bigdir</name><count>1536</count><bytes>10752</bytes></container> | ||
| 153 | - <container><name>cf_service</name><count>35</count><bytes>66151933</bytes></container> | ||
| 154 | - <container><name>elcamino</name><count>15</count><bytes>162457114</bytes></container> | ||
| 155 | - <container><name>laptop migration</name><count>15</count><bytes>225656510</bytes></container> | ||
| 156 | - <container><name>mike mayo</name><count>2</count><bytes>499581</bytes></container> | ||
| 157 | - <container><name>overhrd.com</name><count>12</count><bytes>205775052</bytes></container> | ||
| 158 | - <container><name>personal</name><count>2</count><bytes>14158285</bytes></container> | ||
| 159 | - <container><name>playground</name><count>4</count><bytes>2040999</bytes></container> | ||
| 160 | - <container><name>pubcamino</name><count>1</count><bytes>219946</bytes></container> | ||
| 161 | - <container><name>pubtest2</name><count>0</count><bytes>0</bytes></container> | ||
| 162 | - <container><name>refreshtest</name><count>0</count><bytes>0</bytes></container> | ||
| 163 | - <container><name>testfromapp</name><count>1</count><bytes>234288</bytes></container> | ||
| 164 | - <container><name>wadecrash</name><count>5</count><bytes>19839804</bytes></container> | ||
| 165 | -</account> | ||
| 166 | -*/ | ||
| 167 | - | ||
| 168 | -/* | ||
| 169 | -- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { | ||
| 170 | - [self setCurrentElement:elementName]; | ||
| 171 | - | ||
| 172 | - if ([elementName isEqualToString:@"container"]) { | ||
| 173 | - [self setCurrentObject:[ASICloudFilesContainer container]]; | ||
| 174 | - } | ||
| 175 | - [self setCurrentContent:@""]; | ||
| 176 | -} | ||
| 177 | - | ||
| 178 | -- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { | ||
| 179 | - if ([elementName isEqualToString:@"name"]) { | ||
| 180 | - [self currentObject].name = [self currentContent]; | ||
| 181 | - } else if ([elementName isEqualToString:@"count"]) { | ||
| 182 | - //[[self currentObject] setKey:[self currentContent]]; | ||
| 183 | - [self currentObject].count = [[self currentContent] intValue]; | ||
| 184 | - } else if ([elementName isEqualToString:@"bytes"]) { | ||
| 185 | - [self currentObject].bytes = [[self currentContent] intValue]; | ||
| 186 | - } else if ([elementName isEqualToString:@"container"]) { | ||
| 187 | - // we're done with this container. time to move on to the next | ||
| 188 | - [containerObjects addObject:currentObject]; | ||
| 189 | - [self setCurrentObject:nil]; | ||
| 190 | - } | ||
| 191 | -} | ||
| 192 | - | ||
| 193 | -- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { | ||
| 194 | - [self setCurrentContent:[[self currentContent] stringByAppendingString:string]]; | ||
| 195 | -} | ||
| 196 | -*/ | ||
| 197 | - | ||
| 198 | 136 | ||
| 199 | - (void)dealloc { | 137 | - (void)dealloc { |
| 200 | [currentElement release]; | 138 | [currentElement release]; |
| @@ -17,40 +17,9 @@ | @@ -17,40 +17,9 @@ | ||
| 17 | #pragma mark - | 17 | #pragma mark - |
| 18 | #pragma mark XML Parser Delegate | 18 | #pragma mark XML Parser Delegate |
| 19 | 19 | ||
| 20 | -/* | ||
| 21 | - | ||
| 22 | - <container> | ||
| 23 | - <name>playground</name> | ||
| 24 | - <cdn_enabled>True</cdn_enabled> | ||
| 25 | - <ttl>259200</ttl> | ||
| 26 | - <cdn_url>http://c0023891.cdn.cloudfiles.rackspacecloud.com</cdn_url> | ||
| 27 | - <log_retention>True</log_retention> | ||
| 28 | - <referrer_acl></referrer_acl> | ||
| 29 | - <useragent_acl></useragent_acl> | ||
| 30 | - </container> | ||
| 31 | - | ||
| 32 | - | ||
| 33 | - <account name="MossoCloudFS_56ad0327-43d6-4ac4-9883-797f5690238e"> | ||
| 34 | - <container><name>bigdir</name><count>1536</count><bytes>10752</bytes></container> | ||
| 35 | - <container><name>cf_service</name><count>35</count><bytes>66151933</bytes></container> | ||
| 36 | - <container><name>elcamino</name><count>15</count><bytes>162457114</bytes></container> | ||
| 37 | - <container><name>laptop migration</name><count>15</count><bytes>225656510</bytes></container> | ||
| 38 | - <container><name>mike mayo</name><count>2</count><bytes>499581</bytes></container> | ||
| 39 | - <container><name>overhrd.com</name><count>12</count><bytes>205775052</bytes></container> | ||
| 40 | - <container><name>personal</name><count>2</count><bytes>14158285</bytes></container> | ||
| 41 | - <container><name>playground</name><count>4</count><bytes>2040999</bytes></container> | ||
| 42 | - <container><name>pubcamino</name><count>1</count><bytes>219946</bytes></container> | ||
| 43 | - <container><name>pubtest2</name><count>0</count><bytes>0</bytes></container> | ||
| 44 | - <container><name>refreshtest</name><count>0</count><bytes>0</bytes></container> | ||
| 45 | - <container><name>testfromapp</name><count>1</count><bytes>234288</bytes></container> | ||
| 46 | - <container><name>wadecrash</name><count>5</count><bytes>19839804</bytes></container> | ||
| 47 | - </account> | ||
| 48 | - */ | ||
| 49 | - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { | 20 | - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { |
| 50 | [self setCurrentElement:elementName]; | 21 | [self setCurrentElement:elementName]; |
| 51 | 22 | ||
| 52 | - NSLog(@"start %@", elementName); | ||
| 53 | - | ||
| 54 | if ([elementName isEqualToString:@"container"]) { | 23 | if ([elementName isEqualToString:@"container"]) { |
| 55 | [self setCurrentObject:[ASICloudFilesContainer container]]; | 24 | [self setCurrentObject:[ASICloudFilesContainer container]]; |
| 56 | } | 25 | } |
| @@ -59,15 +28,24 @@ | @@ -59,15 +28,24 @@ | ||
| 59 | 28 | ||
| 60 | - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { | 29 | - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { |
| 61 | 30 | ||
| 62 | - NSLog(@"end %@", elementName); | ||
| 63 | - | ||
| 64 | if ([elementName isEqualToString:@"name"]) { | 31 | if ([elementName isEqualToString:@"name"]) { |
| 65 | [self currentObject].name = [self currentContent]; | 32 | [self currentObject].name = [self currentContent]; |
| 66 | } else if ([elementName isEqualToString:@"count"]) { | 33 | } else if ([elementName isEqualToString:@"count"]) { |
| 67 | - //[[self currentObject] setKey:[self currentContent]]; | ||
| 68 | [self currentObject].count = [[self currentContent] intValue]; | 34 | [self currentObject].count = [[self currentContent] intValue]; |
| 69 | } else if ([elementName isEqualToString:@"bytes"]) { | 35 | } else if ([elementName isEqualToString:@"bytes"]) { |
| 70 | [self currentObject].bytes = [[self currentContent] intValue]; | 36 | [self currentObject].bytes = [[self currentContent] intValue]; |
| 37 | + } else if ([elementName isEqualToString:@"cdn_enabled"]) { | ||
| 38 | + [self currentObject].cdnEnabled = [[self currentObject] isEqual:@"True"]; | ||
| 39 | + } else if ([elementName isEqualToString:@"ttl"]) { | ||
| 40 | + [self currentObject].ttl = [[self currentContent] intValue]; | ||
| 41 | + } else if ([elementName isEqualToString:@"cdn_url"]) { | ||
| 42 | + [self currentObject].cdnURL = [self currentContent]; | ||
| 43 | + } else if ([elementName isEqualToString:@"log_retention"]) { | ||
| 44 | + [self currentObject].logRetention = [[self currentObject] isEqual:@"True"]; | ||
| 45 | + } else if ([elementName isEqualToString:@"referrer_acl"]) { | ||
| 46 | + [self currentObject].referrerACL = [self currentContent]; | ||
| 47 | + } else if ([elementName isEqualToString:@"useragent_acl"]) { | ||
| 48 | + [self currentObject].useragentACL = [self currentContent]; | ||
| 71 | } else if ([elementName isEqualToString:@"container"]) { | 49 | } else if ([elementName isEqualToString:@"container"]) { |
| 72 | // we're done with this container. time to move on to the next | 50 | // we're done with this container. time to move on to the next |
| 73 | if (containerObjects == nil) { | 51 | if (containerObjects == nil) { |
| @@ -21,7 +21,7 @@ | @@ -21,7 +21,7 @@ | ||
| 21 | #import "ASIInputStream.h" | 21 | #import "ASIInputStream.h" |
| 22 | 22 | ||
| 23 | // Automatically set on build | 23 | // Automatically set on build |
| 24 | -NSString *ASIHTTPRequestVersion = @"v1.2-29 2010-01-10"; | 24 | +NSString *ASIHTTPRequestVersion = @"v1.2-30 2010-01-10"; |
| 25 | 25 | ||
| 26 | // We use our own custom run loop mode as CoreAnimation seems to want to hijack our threads otherwise | 26 | // We use our own custom run loop mode as CoreAnimation seems to want to hijack our threads otherwise |
| 27 | static CFStringRef ASIHTTPRequestRunMode = CFSTR("ASIHTTPRequest"); | 27 | static CFStringRef ASIHTTPRequestRunMode = CFSTR("ASIHTTPRequest"); |
-
Please register or login to post a comment