Skip to content
Browse files

Fixes leak with string url encode method

  • Loading branch information...
1 parent bfbba04 commit bdd906980051ce28b90dbd35b7db6497350d4820 @devinross committed Feb 14, 2012
View
BIN ...roj/project.xcworkspace/xcuserdata/devinross14.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
View
5 src/TapkuLibrary/NSString+TKCategory.h
@@ -38,5 +38,10 @@
- (NSString *) escapeHTML;
- (NSString *) unescapeHTML;
- (NSString*) stringByRemovingHTML;
+- (NSString *) md5sum;
+
+
+- (BOOL) hasString:(NSString*)substring;
+
@end
View
30 src/TapkuLibrary/NSString+TKCategory.m
@@ -30,6 +30,7 @@
*/
#import "NSString+TKCategory.h"
+#import <CommonCrypto/CommonDigest.h>
@implementation NSString (TKCategory)
@@ -50,11 +51,20 @@ - (BOOL) isEmail{
}
- (NSString*) URLEncode{
- return [self stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
+
+ NSString *encodedString = (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(
+ NULL,
+ (__bridge CFStringRef)self,
+ NULL,
+ (CFStringRef)@"!*'();:@&=+$,/?%#[]",
+ kCFStringEncodingUTF8 );
+
+ return encodedString;
+
+ //return [self stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
}
-
- (NSString *) escapeHTML{
NSMutableString *s = [NSMutableString string];
@@ -155,5 +165,21 @@ - (NSString*) stringByRemovingHTML{
return html;
}
+- (NSString *) md5sum{
+ unsigned char digest[CC_MD5_DIGEST_LENGTH], i;
+ CC_MD5([self UTF8String], [self lengthOfBytesUsingEncoding:NSUTF8StringEncoding], digest);
+ NSMutableString *ms = [NSMutableString string];
+ for (i=0;i<CC_MD5_DIGEST_LENGTH;i++) {
+ [ms appendFormat: @"%02x", (int)(digest[i])];
+ }
+ return [ms copy];
+}
+
+- (BOOL) hasString:(NSString*)substring{
+
+ return !([self rangeOfString:substring].location == NSNotFound);
+
+}
+
@end
View
3 src/TapkuLibrary/TKHTTPRequest.h
@@ -122,9 +122,6 @@ typedef enum _TKNetworkErrorType {
#pragma mark network activity
+ (BOOL) isNetworkInUse;
+ (void) setShouldUpdateNetworkActivityIndicator:(BOOL)shouldUpdate;
-+ (void) showNetworkActivityIndicator; // Shows the network activity spinner thing on iOS. You may wish to override this to do something else in Mac projects
-+ (void) hideNetworkActivityIndicator; // Hides the network activity spinner thing on iOS
-
View
51 src/TapkuLibrary/TKHTTPRequest.m
@@ -487,36 +487,47 @@ + (void) showNetworkActivityIndicator{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
#endif
}
-+ (void) hideNetworkActivityIndicator{
+
+
+
++ (void) hideNetworkActivityIndicatorIfNeeeded{
+
+ if (runningRequestCount == 0) {
#if TARGET_OS_IPHONE
- [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
+ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
#endif
+ }
}
-+ (void) hideNetworkActivityIndicatorAfterDelay{
- [self performSelector:@selector(hideNetworkActivityIndicatorIfNeeeded) withObject:nil afterDelay:0.5];
+
++ (void) increaseNetworkMain{
+
+
+ runningRequestCount++;
+
+
+#if TARGET_OS_IPHONE
+ if (shouldUpdateNetworkActivityIndicator) [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
+#endif
+
}
-+ (void) hideNetworkActivityIndicatorIfNeeeded{
- if (runningRequestCount == 0) {
- [self hideNetworkActivityIndicator];
- }
++ (void) decreaseNetworkMain{
+ runningRequestCount--;
+#if TARGET_OS_IPHONE
+ [self performSelector:@selector(hideNetworkActivityIndicatorIfNeeeded) withObject:nil afterDelay:0.5];
+#endif
+
}
-- (void) _decreaseNetworkActivity{
- if(self.showNetworkActivity){
- runningRequestCount--;
- if (shouldUpdateNetworkActivityIndicator && runningRequestCount == 0)
- [[self class] performSelectorOnMainThread:@selector(hideNetworkActivityIndicatorAfterDelay) withObject:nil waitUntilDone:[NSThread isMainThread]];
-
+- (void) _decreaseNetworkActivity{
+
+ if(self.showNetworkActivity && shouldUpdateNetworkActivityIndicator){
+ [[self class] performSelectorOnMainThread:@selector(decreaseNetworkMain) withObject:nil waitUntilDone:[NSThread isMainThread]];
}
}
- (void) _increaseNetworkActivity{
-
-
- if(self.showNetworkActivity){
- runningRequestCount++;
- if (shouldUpdateNetworkActivityIndicator)
- [[self class] performSelectorOnMainThread:@selector(showNetworkActivityIndicator) withObject:nil waitUntilDone:[NSThread isMainThread]];
+ if(self.showNetworkActivity && shouldUpdateNetworkActivityIndicator){
+ [[self class] performSelectorOnMainThread:@selector(increaseNetworkMain) withObject:nil waitUntilDone:[NSThread isMainThread]];
}
}
View
28 src/TapkuLibrary/TKImageCache.m
@@ -80,8 +80,12 @@ - (id) initWithCacheDirectoryName:(NSString*)dirName{
cache_queue = dispatch_queue_create("com.tapku",NULL);
+
+
+
self.notificationName = @"NewCachedImageFile";
- self.timeTillRefreshCache = 60 * 60 * 24 * 7.0f;
+ self.timeTillRefreshCache = -1;
+ //self.timeTillRefreshCache = 60 * 60 * 24 * 7.0f;
return self;
}
@@ -98,21 +102,27 @@ - (UIImage*) imageForKey:(NSString*)key url:(NSURL*)url queueIfNeeded:(BOOL)queu
return [self imageForKey:key url:url queueIfNeeded:queueIfNeeded tag:0];
}
- (UIImage*) imageForKey:(NSString*)key url:(NSURL*)url queueIfNeeded:(BOOL)queueIfNeeded tag:(NSUInteger)tag{
+
+ if(key==nil) return nil;
if([self objectForKey:key]!=nil) return [self objectForKey:key];
if([self _imageExistsOnDiskWithKey:key]){
[self _readImageFromDiskWithKey:key tag:tag];
- NSString *path = [[self cacheDirectoryPath] stringByAppendingPathComponent:key];
- NSDate *created = [[[NSFileManager defaultManager] attributesOfItemAtPath:path error:NULL] fileCreationDate];
- NSTimeInterval timeSince = fabs([created timeIntervalSinceNow]);
+ if(self.timeTillRefreshCache > 0){
+ NSString *path = [[self cacheDirectoryPath] stringByAppendingPathComponent:key];
+ NSDate *created = [[[NSFileManager defaultManager] attributesOfItemAtPath:path error:NULL] fileCreationDate];
+ NSTimeInterval timeSince = fabs([created timeIntervalSinceNow]);
+
+ if(_timeTillRefreshCache > timeSince) queueIfNeeded = NO;
+
+ }else
+ queueIfNeeded = NO;
- if(_timeTillRefreshCache > timeSince) return nil; // if the disk cache image file is old, get network image anyway
}
- if(queueIfNeeded && url)
- [self _sendRequestForURL:url key:key tag:tag];
+ if(queueIfNeeded && url) [self _sendRequestForURL:url key:key tag:tag];
return nil;
}
@@ -123,7 +133,7 @@ - (void) _sendRequestForURL:(NSURL*)url key:(NSString*)key tag:(NSUInteger)tag{
- if([_requestKeys objectForKey:key]!=nil) return;
+ if(key == nil || [_requestKeys objectForKey:key]!=nil) return;
[_requestKeys setObject:[NSNull null] forKey:key];
@@ -305,6 +315,8 @@ - (void) _readImageFromDiskWithKey:(NSString*)key tag:(NSUInteger)tag{
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:key,@"key",cacheImage,@"image",[NSNumber numberWithUnsignedInt:tag],@"tag",nil];
[[NSNotificationCenter defaultCenter] postNotificationName:self.notificationName object:dict];
});
+ usleep(10000);
+
}
});
View
1 src/TapkuLibrary/TKViewController.h
@@ -40,6 +40,7 @@
@property (strong,nonatomic) UIView *loadingView;
- (void) addActiveRequest:(TKHTTPRequest*)request;
+- (NSInteger) activeRequestCount;
- (void) removeActiveRequest:(TKHTTPRequest*)request;
- (void) cancelActiveRequests;
View
4 src/TapkuLibrary/TKViewController.m
@@ -65,7 +65,9 @@ - (void) cancelActiveRequests{
}
}
-
+- (NSInteger) activeRequestCount{
+ return _activeRequests.count;
+}
#pragma mark - PROPERTIES
View
2 src/TapkuLibrary/TapkuLibrary.h
@@ -33,9 +33,11 @@
#import "NSArray+TKCategory.h"
#import "UIView+TKCategory.h"
#import "UIImage+TKCategory.h"
+#import "UIColor+TKCategory.h"
#import "UIImageView+TKCategory.h"
#import "UIScrollview+TKCategory.h"
#import "UIButton+TKCategory.h"
+#import "UIViewController+TKCategory.h"
#import "TKWindow.h"

0 comments on commit bdd9069

Please sign in to comment.
Something went wrong with that request. Please try again.