Skip to content
This repository
Browse code

XMPPPrivacy ARC issues. Fixes issue #50

  • Loading branch information...
commit 931f72db88e5b683e8e77da844b42cbe444e891b 1 parent 2e9fa90
Robbie Hanson authored July 03, 2012

Showing 1 changed file with 42 additions and 51 deletions. Show diff stats Hide diff stats

  1. 93  Extensions/XEP-0016/XMPPPrivacy.m
93  Extensions/XEP-0016/XMPPPrivacy.m
... ...
@@ -1,6 +1,7 @@
1 1
 #import "XMPP.h"
2 2
 #import "XMPPLogging.h"
3 3
 #import "XMPPPrivacy.h"
  4
+#import "NSNumber+XMPP.h"
4 5
 
5 6
 // Log levels: off, error, warn, info, verbose
6 7
 // Log flags: trace
@@ -40,7 +41,9 @@ @interface XMPPPrivacyQueryInfo : NSObject
40 41
 @property (nonatomic, readonly) NSString *privacyListName;
41 42
 @property (nonatomic, readonly) NSArray *privacyListItems;
42 43
 
43  
-@property (nonatomic, readwrite, retain) dispatch_source_t timer;
  44
+@property (nonatomic, readwrite) dispatch_source_t timer;
  45
+
  46
+- (void)cancel;
44 47
 
45 48
 + (XMPPPrivacyQueryInfo *)queryInfoWithType:(XMPPPrivacyQueryInfoType)type;
46 49
 + (XMPPPrivacyQueryInfo *)queryInfoWithType:(XMPPPrivacyQueryInfoType)type name:(NSString *)name;
@@ -105,15 +108,6 @@ - (void)deactivate
105 108
 	[super deactivate];
106 109
 }
107 110
 
108  
-- (void)dealloc
109  
-{
110  
-	[privacyDict release];
111  
-	[activeListName release];
112  
-	[defaultListName release];
113  
-	[pendingQueries release];
114  
-	[super dealloc];
115  
-}
116  
-
117 111
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
118 112
 #pragma mark Properties
119 113
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -271,13 +265,10 @@ - (void)clearPrivacyListInfo
271 265
 	}
272 266
 	else
273 267
 	{
274  
-		dispatch_async(moduleQueue, ^{
275  
-			NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  268
+		dispatch_async(moduleQueue, ^{ @autoreleasepool {
276 269
 			
277 270
 			[privacyDict removeAllObjects];
278  
-			
279  
-			[pool drain];
280  
-		});
  271
+		}});
281 272
 	}
282 273
 }
283 274
 
@@ -291,15 +282,12 @@ - (NSArray *)listNames
291 282
 	{
292 283
 		__block NSArray *result;
293 284
 		
294  
-		dispatch_sync(moduleQueue, ^{
295  
-			NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  285
+		dispatch_sync(moduleQueue, ^{ @autoreleasepool {
296 286
 			
297 287
 			result = [[privacyDict allKeys] copy];
298  
-			
299  
-			[pool drain];
300  
-		});
  288
+		}});
301 289
 		
302  
-		return [result autorelease];
  290
+		return result;
303 291
 	}
304 292
 }
305 293
 
@@ -318,8 +306,6 @@ - (NSArray *)listWithName:(NSString *)privacyListName
318 306
 	// ExecuteVoidBlock(moduleQueue, block);
319 307
 	// ExecuteNonVoidBlock(moduleQueue, block, NSArray*)
320 308
 	
321  
-	int n = MIN(5, 6);
322  
-	
323 309
 	if (dispatch_get_current_queue() == moduleQueue)
324 310
 	{
325 311
 		return block();
@@ -328,15 +314,12 @@ - (NSArray *)listWithName:(NSString *)privacyListName
328 314
 	{
329 315
 		__block NSArray *result;
330 316
 		
331  
-		dispatch_sync(moduleQueue, ^{
332  
-			NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
333  
-			
334  
-			result = [block() retain];
  317
+		dispatch_sync(moduleQueue, ^{ @autoreleasepool {
335 318
 			
336  
-			[pool drain];
337  
-		});
  319
+			result = block();
  320
+		}});
338 321
 		
339  
-		return [result autorelease];
  322
+		return result;
340 323
 	}
341 324
 }
342 325
 
@@ -482,11 +465,19 @@ - (void)setListWithName:(NSString *)privacyListName items:(NSArray *)items
482 465
 - (void)addQueryInfo:(XMPPPrivacyQueryInfo *)queryInfo withKey:(NSString *)uuid
483 466
 {
484 467
 	// Setup timer
485  
-	NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:QUERY_TIMEOUT
486  
-	                                                  target:self
487  
-	                                                selector:@selector(queryTimeout:)
488  
-	                                                userInfo:uuid
489  
-	                                                 repeats:NO];
  468
+	
  469
+	dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, moduleQueue);
  470
+	
  471
+	dispatch_source_set_event_handler(timer, ^{ @autoreleasepool {
  472
+		
  473
+		[self queryTimeout:uuid];
  474
+	}});
  475
+	
  476
+	dispatch_time_t fireTime = dispatch_time(DISPATCH_TIME_NOW, (QUERY_TIMEOUT * NSEC_PER_SEC));
  477
+	
  478
+	dispatch_source_set_timer(timer, fireTime, DISPATCH_TIME_FOREVER, 1.0);
  479
+	dispatch_resume(timer);
  480
+	
490 481
 	queryInfo.timer = timer;
491 482
 	
492 483
 	// Add to dictionary
@@ -496,7 +487,7 @@ - (void)addQueryInfo:(XMPPPrivacyQueryInfo *)queryInfo withKey:(NSString *)uuid
496 487
 - (void)removeQueryInfo:(XMPPPrivacyQueryInfo *)queryInfo withKey:(NSString *)uuid
497 488
 {
498 489
 	// Invalidate timer
499  
-	[queryInfo.timer invalidate];
  490
+	[queryInfo cancel];
500 491
 	
501 492
 	// Remove from dictionary
502 493
 	[pendingQueries removeObjectForKey:uuid];
@@ -528,10 +519,8 @@ - (void)processQuery:(XMPPPrivacyQueryInfo *)queryInfo withFailureCode:(XMPPPriv
528 519
 	}
529 520
 }
530 521
 
531  
-- (void)queryTimeout:(NSTimer *)timer
  522
+- (void)queryTimeout:(NSString *)uuid
532 523
 {
533  
-	NSString *uuid = [timer userInfo];
534  
-	
535 524
 	XMPPPrivacyQueryInfo *queryInfo = [privacyDict objectForKey:uuid];
536 525
 	if (queryInfo)
537 526
 	{
@@ -610,9 +599,6 @@ - (void)processQueryResponse:(XMPPIQ *)iq withInfo:(XMPPPrivacyQueryInfo *)query
610 599
 		
611 600
 		if ([[iq type] isEqualToString:@"result"])
612 601
 		{
613  
-			[activeListName release];
614  
-			[defaultListName release];
615  
-			
616 602
 			NSXMLElement *query = [iq elementForName:@"query" xmlns:@"jabber:iq:privacy"];
617 603
 			if (query == nil) return;
618 604
 			
@@ -742,7 +728,6 @@ - (void)processQueryResponse:(XMPPIQ *)iq withInfo:(XMPPPrivacyQueryInfo *)query
742 728
 		
743 729
 		if ([[iq type] isEqualToString:@"result"])
744 730
 		{
745  
-			[activeListName release];
746 731
 			activeListName = [[queryInfo privacyListName] copy];
747 732
 			
748 733
 			[multicastDelegate xmppPrivacy:self didSetActiveListName:queryInfo.privacyListName];
@@ -776,7 +761,6 @@ - (void)processQueryResponse:(XMPPIQ *)iq withInfo:(XMPPPrivacyQueryInfo *)query
776 761
 		
777 762
 		if ([[iq type] isEqualToString:@"result"])
778 763
 		{
779  
-			[defaultListName release];
780 764
 			defaultListName = [[queryInfo privacyListName] copy];
781 765
 			
782 766
 			[multicastDelegate xmppPrivacy:self didSetDefaultListName:queryInfo.privacyListName];
@@ -933,7 +917,6 @@ + (NSXMLElement *)privacyItemWithType:(NSString *)type
933 917
 	[item addAttributeWithName:@"action" stringValue:action];
934 918
 	[item addAttributeWithName:@"order"  stringValue:order];
935 919
 	
936  
-	[order release];
937 920
 	return item;
938 921
 }
939 922
 
@@ -982,13 +965,21 @@ - (id)initWithType:(XMPPPrivacyQueryInfoType)aType name:(NSString *)name items:(
982 965
 	return self;
983 966
 }
984 967
 
  968
+- (void)cancel
  969
+{
  970
+	if (timer)
  971
+	{
  972
+		dispatch_source_cancel(timer);
  973
+		#if NEEDS_DISPATCH_RETAIN_RELEASE
  974
+		dispatch_release(timer);
  975
+		#endif
  976
+		timer = NULL;
  977
+	}
  978
+}
  979
+
985 980
 - (void)dealloc
986 981
 {
987  
-	[privacyListName release];
988  
-	[privacyListItems release];
989  
-	[timer invalidate];
990  
-	[timer release];
991  
-	[super dealloc];
  982
+	[self cancel];
992 983
 }
993 984
 
994 985
 + (XMPPPrivacyQueryInfo *)queryInfoWithType:(XMPPPrivacyQueryInfoType)type
@@ -1003,7 +994,7 @@ + (XMPPPrivacyQueryInfo *)queryInfoWithType:(XMPPPrivacyQueryInfoType)type name:
1003 994
 
1004 995
 + (XMPPPrivacyQueryInfo *)queryInfoWithType:(XMPPPrivacyQueryInfoType)type name:(NSString *)name items:(NSArray *)items
1005 996
 {
1006  
-	return [[[XMPPPrivacyQueryInfo alloc] initWithType:type name:name items:items] autorelease];
  997
+	return [[XMPPPrivacyQueryInfo alloc] initWithType:type name:name items:items];
1007 998
 }
1008 999
 
1009 1000
 @end

0 notes on commit 931f72d

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