Ben Copsey

Added workaround for problem with type conversion on 2.2.1 for apps with a base sdk >= 3.0

Fiddle with header organisation / comments
... ... @@ -416,6 +416,11 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
- (void)attemptToApplyCredentialsAndResume;
- (void)attemptToApplyProxyCredentialsAndResume;
// Attempt to show the built-in authentication dialog, returns YES if credentials were supplied, NO if user cancelled dialog / dialog is disabled / running on main thread
// Currently only used on iPhone OS
- (BOOL)showProxyAuthenticationDialog;
- (BOOL)showAuthenticationDialog;
#pragma mark stream status handlers
// CFnetwork event handlers
... ... @@ -533,12 +538,12 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
+ (void)reachabilityChanged:(NSNotification *)note;
#endif
- (BOOL)showProxyAuthenticationDialog;
- (BOOL)showAuthenticationDialog;
// Returns the maximum amount of data we can read as part of the current measurement period, and sleeps this thread if our allowance is used up
+ (unsigned long)maxUploadReadLength;
// Determines whether we're on iPhone OS 2.0 at runtime, currently used to determine whether we should apply a workaround for an issue with converting longs to doubles on iPhone OS 2
+ (BOOL)isiPhoneOS2;
@property (retain) NSString *username;
@property (retain) NSString *password;
@property (retain) NSString *domain;
... ...
... ... @@ -95,6 +95,8 @@ static NSRecursiveLock *delegateAuthenticationLock = nil;
static NSOperationQueue *sharedRequestQueue = nil;
static BOOL isiPhoneOS2;
// Private stuff
@interface ASIHTTPRequest ()
... ... @@ -157,6 +159,12 @@ static NSOperationQueue *sharedRequestQueue = nil;
ASIRequestCancelledError = [[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIRequestCancelledErrorType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"The request was cancelled",NSLocalizedDescriptionKey,nil]] retain];
ASIUnableToCreateRequestError = [[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIUnableToCreateRequestErrorType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Unable to create request (bad url?)",NSLocalizedDescriptionKey,nil]] retain];
ASITooMuchRedirectionError = [[NSError errorWithDomain:NetworkRequestErrorDomain code:ASITooMuchRedirectionErrorType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"The request failed because it redirected too many times",NSLocalizedDescriptionKey,nil]] retain];
#if TARGET_OS_IPHONE
isiPhoneOS2 = ((floorf([[[UIDevice currentDevice] systemVersion] floatValue]) == 2.0) ? YES : NO);
#else
isiPhoneOS2 = NO;
#endif
}
[super initialize];
}
... ... @@ -698,7 +706,13 @@ static NSOperationQueue *sharedRequestQueue = nil;
if (shouldResetProgressIndicators) {
double amount = 1;
if (showAccurateProgress) {
amount = postLength;
//Workaround for an issue with converting a long to a double on iPhone OS 2.2.1 with a base SDK >= 3.0
if ([ASIHTTPRequest isiPhoneOS2]) {
amount = [[NSNumber numberWithUnsignedLongLong:postLength] doubleValue];
} else {
amount = (double)postLength;
}
}
[self resetUploadProgress:amount];
}
... ... @@ -983,7 +997,16 @@ static NSOperationQueue *sharedRequestQueue = nil;
// Update this request's own upload progress delegate
if (uploadProgressDelegate) {
[ASIHTTPRequest setProgress:(double)(1.0*(totalBytesSent-uploadBufferSize)/(postLength-uploadBufferSize)) forProgressIndicator:uploadProgressDelegate];
double progress;
//Workaround for an issue with converting a long to a double on iPhone OS 2.2.1 with a base SDK >= 3.0
if ([ASIHTTPRequest isiPhoneOS2]) {
progress = [[NSNumber numberWithUnsignedLongLong:(totalBytesSent-uploadBufferSize)/(postLength-uploadBufferSize)] doubleValue];
} else {
progress = (double)(1.0*(totalBytesSent-uploadBufferSize)/(postLength-uploadBufferSize));
}
[ASIHTTPRequest setProgress:progress forProgressIndicator:uploadProgressDelegate];
}
... ... @@ -1047,7 +1070,15 @@ static NSOperationQueue *sharedRequestQueue = nil;
}
if (downloadProgressDelegate && contentLength > 0) {
[ASIHTTPRequest setProgress:(double)(1.0*bytesReadSoFar/(contentLength+partialDownloadSize)) forProgressIndicator:downloadProgressDelegate];
double progress;
//Workaround for an issue with converting a long to a double on iPhone OS 2.2.1 with a base SDK >= 3.0
if ([ASIHTTPRequest isiPhoneOS2]) {
progress = [[NSNumber numberWithUnsignedLongLong:bytesReadSoFar/(contentLength+partialDownloadSize)] doubleValue];
} else {
progress = (double)(1.0*bytesReadSoFar/(contentLength+partialDownloadSize));
}
[ASIHTTPRequest setProgress:progress forProgressIndicator:downloadProgressDelegate];
}
[self setLastBytesRead:bytesReadSoFar];
... ... @@ -2862,6 +2893,11 @@ static NSOperationQueue *sharedRequestQueue = nil;
return toRead;
}
+ (BOOL)isiPhoneOS2
{
return isiPhoneOS2;
}
@synthesize username;
@synthesize password;
... ...
... ... @@ -231,6 +231,7 @@
}
[self setUploadProgressBytes:[self uploadProgressBytes] - bytes];
double progress = ([self uploadProgressBytes]*1.0)/([self uploadProgressTotalBytes]*1.0);
[ASIHTTPRequest setProgress:progress forProgressIndicator:[self uploadProgressDelegate]];
}
... ... @@ -243,7 +244,13 @@
}
[self setUploadProgressBytes:[self uploadProgressBytes] + bytes];
double progress = ([self uploadProgressBytes]*1.0)/([self uploadProgressTotalBytes]*1.0);
double progress;
//Workaround for an issue with converting a long to a double on iPhone OS 2.2.1 with a base SDK >= 3.0
if ([ASIHTTPRequest isiPhoneOS2]) {
progress = [[NSNumber numberWithUnsignedLongLong:[self uploadProgressBytes]] doubleValue]/[[NSNumber numberWithUnsignedLongLong:[self uploadProgressTotalBytes]] doubleValue];
} else {
progress = ([self uploadProgressBytes]*1.0)/([self uploadProgressTotalBytes]*1.0);
}
[ASIHTTPRequest setProgress:progress forProgressIndicator:[self uploadProgressDelegate]];
}
... ... @@ -263,7 +270,14 @@
return;
}
[self setDownloadProgressBytes:[self downloadProgressBytes] + bytes];
double progress = ([self downloadProgressBytes]*1.0)/([self downloadProgressTotalBytes]*1.0);
double progress;
//Workaround for an issue with converting a long to a double on iPhone OS 2.2.1 with a base SDK >= 3.0
if ([ASIHTTPRequest isiPhoneOS2]) {
progress = [[NSNumber numberWithUnsignedLongLong:[self downloadProgressBytes]] doubleValue]/[[NSNumber numberWithUnsignedLongLong:[self downloadProgressTotalBytes]] doubleValue];
} else {
progress = ([self downloadProgressBytes]*1.0)/([self downloadProgressTotalBytes]*1.0);
}
[ASIHTTPRequest setProgress:progress forProgressIndicator:[self downloadProgressDelegate]];
}
... ...