Revision 62ea6d49
b/Classes/AccountManager.m | ||
---|---|---|
43 | 43 |
} |
44 | 44 |
success(request); |
45 | 45 |
[request notify]; |
46 |
} else if (request.retryWithUpdatedURL && ((request.responseStatusCode == 401) || (request.responseStatusCode == 404))) { |
|
46 |
} else if (request.retryWithUpdatedURL && |
|
47 |
((request.responseStatusCode == 401) || (request.responseStatusCode == 404) || (request.responseStatusCode == 0))) { |
|
47 | 48 |
[self retryWithUpdatedURL:request success:success failure:failure]; |
48 | 49 |
} else { |
49 | 50 |
failure(request); |
... | ... | |
51 | 52 |
} |
52 | 53 |
}]; |
53 | 54 |
[request setFailedBlock:^{ |
54 |
if (request.retryWithUpdatedURL && ((request.responseStatusCode == 401) || (request.responseStatusCode == 404))) { |
|
55 |
if (request.retryWithUpdatedURL && |
|
56 |
((request.responseStatusCode == 401) || (request.responseStatusCode == 404) || (request.responseStatusCode == 0))) { |
|
55 | 57 |
[self retryWithUpdatedURL:request success:success failure:failure]; |
56 | 58 |
} else { |
57 | 59 |
failure(request); |
... | ... | |
64 | 66 |
- (void)retryWithUpdatedURL:(OpenStackRequest *)request success:(APIResponseBlock)success failure:(APIResponseBlock)failure { |
65 | 67 |
[[self serviceCatalog] success:^(OpenStackRequest *serviceRequest) { |
66 | 68 |
OpenStackRequest *newRequest = [[request copy] autorelease]; |
69 |
if (newRequest.retryType == OpenStackRequestTypeAuthEndpoint) { |
|
70 |
NSString *urlPrefix = [account.provider.authEndpointURL description]; |
|
71 |
if (![urlPrefix hasSuffix:@"/"]) |
|
72 |
urlPrefix = [urlPrefix stringByAppendingString:@"/"]; |
|
73 |
NSString *urlSuffix = [[newRequest.url description] substringFromIndex:[[newRequest.retryBaseURL description] length]]; |
|
74 |
while ([urlSuffix hasPrefix:@"/"]) |
|
75 |
urlSuffix = [urlSuffix substringFromIndex:1]; |
|
76 |
newRequest.url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", urlPrefix, urlSuffix]]; |
|
77 |
} else if (newRequest.retryType == OpenStackRequestTypeUserCatalog) { |
|
78 |
NSString *urlPrefix = [account.provider.userCatalogURL description]; |
|
79 |
if (![urlPrefix hasSuffix:@"/"]) |
|
80 |
urlPrefix = [urlPrefix stringByAppendingString:@"/"]; |
|
81 |
NSString *urlSuffix = [[newRequest.url description] substringFromIndex:[[newRequest.retryBaseURL description] length]]; |
|
82 |
while ([urlSuffix hasPrefix:@"/"]) |
|
83 |
urlSuffix = [urlSuffix substringFromIndex:1]; |
|
84 |
newRequest.url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", urlPrefix, urlSuffix]]; |
|
85 |
} |
|
67 | 86 |
newRequest.retryWithUpdatedURL = NO; |
68 | 87 |
[self start:newRequest success:success failure:failure]; |
69 | 88 |
} failure:^(OpenStackRequest *serviceRequest) { |
b/Classes/OpenStackAccount.h | ||
---|---|---|
18 | 18 |
@property (nonatomic, retain) NSString *username; |
19 | 19 |
@property (nonatomic, retain) NSString *apiKey; |
20 | 20 |
@property (nonatomic, retain) NSString *authToken; |
21 |
@property (nonatomic, readonly) NSURL *filesURL; |
|
22 | 21 |
@property (nonatomic, retain) AccountManager *manager; |
23 | 22 |
@property (nonatomic, retain) NSNumber *bytesUsed; |
24 | 23 |
@property (nonatomic, retain) NSNumber *policyQuota; |
b/Classes/OpenStackAccount.m | ||
---|---|---|
19 | 19 |
|
20 | 20 |
@implementation OpenStackAccount |
21 | 21 |
|
22 |
@synthesize uuid, provider, username, filesURL, manager,
|
|
22 |
@synthesize uuid, provider, username, manager, |
|
23 | 23 |
bytesUsed, policyQuota, containers, hasBeenRefreshed, flaggedForDelete, |
24 | 24 |
shared, sharingAccount, userCatalog, ignoreSSLErrors; |
25 | 25 |
|
... | ... | |
117 | 117 |
|
118 | 118 |
#pragma mark - Properties |
119 | 119 |
|
120 |
- (NSURL *)filesURL { |
|
121 |
return [self.provider.authEndpointURL URLByAppendingPathComponent:self.username]; |
|
122 |
} |
|
123 |
|
|
124 | 120 |
- (void)setShared:(BOOL)aShared { |
125 | 121 |
if (shared != aShared) { |
126 | 122 |
self.containers = nil; |
b/Classes/OpenStackRequest.h | ||
---|---|---|
10 | 10 |
|
11 | 11 |
@class OpenStackAccount, Container, StorageObject, APICallback, ErrorAlerter; |
12 | 12 |
|
13 |
enum { |
|
14 |
OpenStackRequestTypeUserCatalog = 0, |
|
15 |
OpenStackRequestTypeAuthEndpoint = 1 |
|
16 |
}; |
|
17 |
typedef NSInteger OpenStackRequestType; |
|
18 |
|
|
13 | 19 |
@interface OpenStackRequest : ASIHTTPRequest <NSCopying> { |
14 | 20 |
OpenStackAccount *account; |
15 | 21 |
ASIBasicBlock backupCompletionBlock; |
16 | 22 |
ASIBasicBlock backupFailureBlock; |
17 | 23 |
APICallback *callback; |
18 | 24 |
BOOL retryWithUpdatedURL; |
25 |
NSURL *retryBaseURL; |
|
26 |
OpenStackRequestType retryType; |
|
19 | 27 |
NSString *followUpSelectorString; |
20 | 28 |
NSURL *notificationURL; |
21 | 29 |
} |
... | ... | |
24 | 32 |
@property (nonatomic, retain) APICallback *callback; |
25 | 33 |
@property (nonatomic, retain) ErrorAlerter *errorAlerter; |
26 | 34 |
@property (nonatomic, assign) BOOL retryWithUpdatedURL; |
35 |
@property (nonatomic, retain) NSURL *retryBaseURL; |
|
36 |
@property (nonatomic, assign) OpenStackRequestType retryType; |
|
27 | 37 |
@property (nonatomic, retain) NSString *followUpSelectorString; |
28 | 38 |
@property (nonatomic, retain) NSURL *notificationURL; |
29 | 39 |
|
b/Classes/OpenStackRequest.m | ||
---|---|---|
20 | 20 |
|
21 | 21 |
@implementation OpenStackRequest |
22 | 22 |
|
23 |
@synthesize account, callback, errorAlerter, retryWithUpdatedURL, followUpSelectorString, notificationURL; |
|
23 |
@synthesize account, callback, errorAlerter, retryWithUpdatedURL, retryBaseURL, retryType, followUpSelectorString, notificationURL;
|
|
24 | 24 |
|
25 | 25 |
#pragma mark - Constructors |
26 | 26 |
#pragma mark Generic |
... | ... | |
33 | 33 |
request.timeOutSeconds = 60; |
34 | 34 |
request.numberOfTimesToRetryOnTimeout = 5; |
35 | 35 |
request.validatesSecureCertificate = !account.ignoreSSLErrors; |
36 |
request.retryWithUpdatedURL = (account.provider.manual ? NO : YES);
|
|
36 |
request.retryWithUpdatedURL = NO;
|
|
37 | 37 |
return request; |
38 | 38 |
} |
39 | 39 |
|
40 | 40 |
+ (id)request:(OpenStackAccount *)account method:(NSString *)method url:(NSURL *)url { |
41 | 41 |
OpenStackRequest *request = [self requestWithoutToken:account method:method url:url]; |
42 |
request.retryWithUpdatedURL = (account.provider.manual ? NO : YES); |
|
42 | 43 |
[request addRequestHeader:@"X-Auth-Token" value:account.authToken]; |
43 | 44 |
return request; |
44 | 45 |
} |
45 | 46 |
|
46 | 47 |
+ (id)filesRequest:(OpenStackAccount *)account method:(NSString *)method path:(NSString *)path { |
47 |
NSString *urlString = [account.filesURL description]; |
|
48 |
if (account.sharingAccount) { |
|
49 |
urlString = [NSString stringWithFormat:@"%@%@", |
|
50 |
[urlString substringToIndex:[urlString rangeOfString:account.username].location], |
|
51 |
account.sharingAccount]; |
|
52 |
} |
|
48 |
NSString *urlString = [[account.provider.authEndpointURL |
|
49 |
URLByAppendingPathComponent:(account.sharingAccount ? account.sharingAccount : account.username)] description]; |
|
53 | 50 |
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@?format=json%@", |
54 | 51 |
urlString, |
55 | 52 |
path, |
56 | 53 |
(account.shared ? @"&shared=" : @"")]]; |
57 |
return [self request:account method:method url:url]; |
|
54 |
OpenStackRequest *request = [self request:account method:method url:url]; |
|
55 |
request.retryBaseURL = account.provider.authEndpointURL; |
|
56 |
request.retryType = OpenStackRequestTypeAuthEndpoint; |
|
57 |
return request; |
|
58 | 58 |
} |
59 | 59 |
|
60 | 60 |
#pragma mark NSCopying |
... | ... | |
65 | 65 |
newRequest.callback = self.callback; |
66 | 66 |
newRequest.errorAlerter = self.errorAlerter; |
67 | 67 |
newRequest.retryWithUpdatedURL = self.retryWithUpdatedURL; |
68 |
newRequest.retryBaseURL = self.retryBaseURL; |
|
69 |
newRequest.retryType = self.retryType; |
|
68 | 70 |
newRequest.followUpSelectorString = self.followUpSelectorString; |
69 | 71 |
newRequest.notificationURL = self.notificationURL; |
70 | 72 |
return newRequest; |
... | ... | |
100 | 102 |
#pragma mark User Catalog |
101 | 103 |
+ (id)userCatalogRequest:(OpenStackAccount *)account displaynames:(NSArray *)displaynames UUIDs:(NSArray *)UUIDs { |
102 | 104 |
OpenStackRequest *request = [self request:account method:@"POST" url:account.provider.userCatalogURL]; |
105 |
request.retryBaseURL = account.provider.userCatalogURL; |
|
106 |
request.retryType = OpenStackRequestTypeUserCatalog; |
|
103 | 107 |
NSMutableString *dataString = [NSMutableString stringWithString:@"{\"displaynames\":["]; |
104 | 108 |
if (displaynames) { |
105 | 109 |
for (NSUInteger index = 0 ; index < displaynames.count ; index++) { |
... | ... | |
146 | 150 |
request.numberOfTimesToRetryOnTimeout = 5; |
147 | 151 |
request.validatesSecureCertificate = !account.ignoreSSLErrors; |
148 | 152 |
request.retryWithUpdatedURL = (account.provider.manual ? NO : YES); |
153 |
request.retryBaseURL = account.provider.authEndpointURL; |
|
154 |
request.retryType = OpenStackRequestTypeAuthEndpoint; |
|
149 | 155 |
return request; |
150 | 156 |
} |
151 | 157 |
|
... | ... | |
154 | 160 |
OpenStackRequest *request = [self request:account method:@"GET" |
155 | 161 |
url:[NSURL URLWithString:[NSString stringWithFormat:@"%@?format=json", |
156 | 162 |
account.provider.authEndpointURL]]]; |
163 |
request.retryBaseURL = account.provider.authEndpointURL; |
|
164 |
request.retryType = OpenStackRequestTypeAuthEndpoint; |
|
157 | 165 |
if (marker) |
158 | 166 |
request.url = [NSURL URLWithString:[NSString stringWithFormat:@"%@&marker=%@", request.url.description, [NSString encodeToPercentEscape:marker]]]; |
159 | 167 |
if (!sharingAccountsBuffer) |
... | ... | |
456 | 464 |
- (void)dealloc { |
457 | 465 |
[account release]; |
458 | 466 |
[errorAlerter release]; |
467 |
[retryBaseURL release]; |
|
459 | 468 |
[followUpSelectorString release]; |
460 | 469 |
[notificationURL release]; |
461 | 470 |
[self releaseBackupBlocksOnMainThread]; |
b/OpenStack-Info.plist | ||
---|---|---|
56 | 56 |
</dict> |
57 | 57 |
</array> |
58 | 58 |
<key>CFBundleVersion</key> |
59 |
<string>20130702.0</string>
|
|
59 |
<string>20130704.0</string>
|
|
60 | 60 |
<key>LSRequiresIPhoneOS</key> |
61 | 61 |
<true/> |
62 | 62 |
<key>NSMainNibFile</key> |
Also available in: Unified diff