Permalink
Browse files

XMPPPrivacy ARC issues. Fixes issue #50

  • Loading branch information...
robbiehanson committed Jul 3, 2012
1 parent 2e9fa90 commit 931f72db88e5b683e8e77da844b42cbe444e891b
Showing with 42 additions and 51 deletions.
  1. +42 −51 Extensions/XEP-0016/XMPPPrivacy.m
@@ -1,6 +1,7 @@
#import "XMPP.h"
#import "XMPPLogging.h"
#import "XMPPPrivacy.h"
+#import "NSNumber+XMPP.h"
// Log levels: off, error, warn, info, verbose
// Log flags: trace
@@ -40,7 +41,9 @@ @interface XMPPPrivacyQueryInfo : NSObject
@property (nonatomic, readonly) NSString *privacyListName;
@property (nonatomic, readonly) NSArray *privacyListItems;
-@property (nonatomic, readwrite, retain) dispatch_source_t timer;
+@property (nonatomic, readwrite) dispatch_source_t timer;
+
+- (void)cancel;
+ (XMPPPrivacyQueryInfo *)queryInfoWithType:(XMPPPrivacyQueryInfoType)type;
+ (XMPPPrivacyQueryInfo *)queryInfoWithType:(XMPPPrivacyQueryInfoType)type name:(NSString *)name;
@@ -105,15 +108,6 @@ - (void)deactivate
[super deactivate];
}
-- (void)dealloc
-{
- [privacyDict release];
- [activeListName release];
- [defaultListName release];
- [pendingQueries release];
- [super dealloc];
-}
-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark Properties
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -271,13 +265,10 @@ - (void)clearPrivacyListInfo
}
else
{
- dispatch_async(moduleQueue, ^{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ dispatch_async(moduleQueue, ^{ @autoreleasepool {
[privacyDict removeAllObjects];
-
- [pool drain];
- });
+ }});
}
}
@@ -291,15 +282,12 @@ - (NSArray *)listNames
{
__block NSArray *result;
- dispatch_sync(moduleQueue, ^{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ dispatch_sync(moduleQueue, ^{ @autoreleasepool {
result = [[privacyDict allKeys] copy];
-
- [pool drain];
- });
+ }});
- return [result autorelease];
+ return result;
}
}
@@ -318,8 +306,6 @@ - (NSArray *)listWithName:(NSString *)privacyListName
// ExecuteVoidBlock(moduleQueue, block);
// ExecuteNonVoidBlock(moduleQueue, block, NSArray*)
- int n = MIN(5, 6);
-
if (dispatch_get_current_queue() == moduleQueue)
{
return block();
@@ -328,15 +314,12 @@ - (NSArray *)listWithName:(NSString *)privacyListName
{
__block NSArray *result;
- dispatch_sync(moduleQueue, ^{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
- result = [block() retain];
+ dispatch_sync(moduleQueue, ^{ @autoreleasepool {
- [pool drain];
- });
+ result = block();
+ }});
- return [result autorelease];
+ return result;
}
}
@@ -482,11 +465,19 @@ - (void)setListWithName:(NSString *)privacyListName items:(NSArray *)items
- (void)addQueryInfo:(XMPPPrivacyQueryInfo *)queryInfo withKey:(NSString *)uuid
{
// Setup timer
- NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:QUERY_TIMEOUT
- target:self
- selector:@selector(queryTimeout:)
- userInfo:uuid
- repeats:NO];
+
+ dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, moduleQueue);
+
+ dispatch_source_set_event_handler(timer, ^{ @autoreleasepool {
+
+ [self queryTimeout:uuid];
+ }});
+
+ dispatch_time_t fireTime = dispatch_time(DISPATCH_TIME_NOW, (QUERY_TIMEOUT * NSEC_PER_SEC));
+
+ dispatch_source_set_timer(timer, fireTime, DISPATCH_TIME_FOREVER, 1.0);
+ dispatch_resume(timer);
+
queryInfo.timer = timer;
// Add to dictionary
@@ -496,7 +487,7 @@ - (void)addQueryInfo:(XMPPPrivacyQueryInfo *)queryInfo withKey:(NSString *)uuid
- (void)removeQueryInfo:(XMPPPrivacyQueryInfo *)queryInfo withKey:(NSString *)uuid
{
// Invalidate timer
- [queryInfo.timer invalidate];
+ [queryInfo cancel];
// Remove from dictionary
[pendingQueries removeObjectForKey:uuid];
@@ -528,10 +519,8 @@ - (void)processQuery:(XMPPPrivacyQueryInfo *)queryInfo withFailureCode:(XMPPPriv
}
}
-- (void)queryTimeout:(NSTimer *)timer
+- (void)queryTimeout:(NSString *)uuid
{
- NSString *uuid = [timer userInfo];
-
XMPPPrivacyQueryInfo *queryInfo = [privacyDict objectForKey:uuid];
if (queryInfo)
{
@@ -610,9 +599,6 @@ - (void)processQueryResponse:(XMPPIQ *)iq withInfo:(XMPPPrivacyQueryInfo *)query
if ([[iq type] isEqualToString:@"result"])
{
- [activeListName release];
- [defaultListName release];
-
NSXMLElement *query = [iq elementForName:@"query" xmlns:@"jabber:iq:privacy"];
if (query == nil) return;
@@ -742,7 +728,6 @@ - (void)processQueryResponse:(XMPPIQ *)iq withInfo:(XMPPPrivacyQueryInfo *)query
if ([[iq type] isEqualToString:@"result"])
{
- [activeListName release];
activeListName = [[queryInfo privacyListName] copy];
[multicastDelegate xmppPrivacy:self didSetActiveListName:queryInfo.privacyListName];
@@ -776,7 +761,6 @@ - (void)processQueryResponse:(XMPPIQ *)iq withInfo:(XMPPPrivacyQueryInfo *)query
if ([[iq type] isEqualToString:@"result"])
{
- [defaultListName release];
defaultListName = [[queryInfo privacyListName] copy];
[multicastDelegate xmppPrivacy:self didSetDefaultListName:queryInfo.privacyListName];
@@ -933,7 +917,6 @@ + (NSXMLElement *)privacyItemWithType:(NSString *)type
[item addAttributeWithName:@"action" stringValue:action];
[item addAttributeWithName:@"order" stringValue:order];
- [order release];
return item;
}
@@ -982,13 +965,21 @@ - (id)initWithType:(XMPPPrivacyQueryInfoType)aType name:(NSString *)name items:(
return self;
}
+- (void)cancel
+{
+ if (timer)
+ {
+ dispatch_source_cancel(timer);
+ #if NEEDS_DISPATCH_RETAIN_RELEASE
+ dispatch_release(timer);
+ #endif
+ timer = NULL;
+ }
+}
+
- (void)dealloc
{
- [privacyListName release];
- [privacyListItems release];
- [timer invalidate];
- [timer release];
- [super dealloc];
+ [self cancel];
}
+ (XMPPPrivacyQueryInfo *)queryInfoWithType:(XMPPPrivacyQueryInfoType)type
@@ -1003,7 +994,7 @@ + (XMPPPrivacyQueryInfo *)queryInfoWithType:(XMPPPrivacyQueryInfoType)type name:
+ (XMPPPrivacyQueryInfo *)queryInfoWithType:(XMPPPrivacyQueryInfoType)type name:(NSString *)name items:(NSArray *)items
{
- return [[[XMPPPrivacyQueryInfo alloc] initWithType:type name:name items:items] autorelease];
+ return [[XMPPPrivacyQueryInfo alloc] initWithType:type name:name items:items];
}
@end

0 comments on commit 931f72d

Please sign in to comment.