Browse files

Merge branch 'arc'

  • Loading branch information...
2 parents 921537f + da21938 commit 51d2d6f5046896a3359ed423d76e0c7e0d44b64b @robbiehanson committed Dec 26, 2011
Showing with 7,447 additions and 4,201 deletions.
  1. +1 −0 .gitmodules
  2. +5 −1 Categories/NSData+XMPP.m
  3. +5 −2 Categories/NSNumber+XMPP.h
  4. +100 −27 Categories/NSNumber+XMPP.m
  5. +67 −0 Categories/NSXMLElement+XMPP.h
  6. +145 −3 Categories/NSXMLElement+XMPP.m
  7. +1 −1 Core/XMPPElement.h
  8. +27 −1 Core/XMPPElement.m
  9. +17 −7 Core/XMPPIQ.m
  10. +6 −6 Core/XMPPJID.h
  11. +40 −39 Core/XMPPJID.m
  12. +4 −0 Core/XMPPMessage.h
  13. +38 −5 Core/XMPPMessage.m
  14. +2 −2 Core/XMPPModule.h
  15. +7 −6 Core/XMPPModule.m
  16. +27 −30 Core/XMPPParser.m
  17. +8 −3 Core/XMPPPresence.m
  18. +7 −7 Core/XMPPStream.h
  19. +241 −463 Core/XMPPStream.m
  20. +2 −2 Extensions/CoreDataStorage/XMPPCoreDataStorage.h
  21. +25 −48 Extensions/CoreDataStorage/XMPPCoreDataStorage.m
  22. +11 −3 Extensions/CoreDataStorage/XMPPCoreDataStorageProtected.h
  23. +28 −41 Extensions/Reconnect/XMPPReconnect.m
  24. +2 −2 Extensions/Roster/CoreDataStorage/XMPPGroupCoreDataStorageObject.h
  25. +4 −4 Extensions/Roster/CoreDataStorage/XMPPGroupCoreDataStorageObject.m
  26. +12 −12 Extensions/Roster/CoreDataStorage/XMPPResourceCoreDataStorageObject.h
  27. +4 −1 Extensions/Roster/CoreDataStorage/XMPPResourceCoreDataStorageObject.m
  28. +2 −1 Extensions/Roster/CoreDataStorage/XMPPRosterCoreDataStorage.h
  29. +25 −34 Extensions/Roster/CoreDataStorage/XMPPRosterCoreDataStorage.m
  30. +15 −15 Extensions/Roster/CoreDataStorage/XMPPUserCoreDataStorageObject.h
  31. +10 −5 Extensions/Roster/CoreDataStorage/XMPPUserCoreDataStorageObject.m
  32. +17 −22 Extensions/Roster/MemoryStorage/XMPPResourceMemoryStorage.m
  33. +2 −2 Extensions/Roster/MemoryStorage/XMPPRosterMemoryStorage.h
  34. +61 −91 Extensions/Roster/MemoryStorage/XMPPRosterMemoryStorage.m
  35. +2 −2 Extensions/Roster/MemoryStorage/XMPPRosterMemoryStoragePrivate.h
  36. +2 −2 Extensions/Roster/MemoryStorage/XMPPUserMemoryStorage.h
  37. +13 −22 Extensions/Roster/MemoryStorage/XMPPUserMemoryStorage.m
  38. +2 −2 Extensions/Roster/XMPPRoster.h
  39. +8 −14 Extensions/Roster/XMPPRoster.m
  40. +8 −4 Extensions/XEP-0009/XMPPIQ+JabberRPC.m
  41. +5 −4 Extensions/XEP-0009/XMPPIQ+JabberRPCResonse.m
  42. +12 −22 Extensions/XEP-0009/XMPPJabberRPCModule.m
  43. +8 −0 Extensions/XEP-0045/CoreDataStorage/XMPPRoom.xcdatamodeld/.xccurrentversion
  44. +35 −0 Extensions/XEP-0045/CoreDataStorage/XMPPRoom.xcdatamodeld/XMPPRoom.xcdatamodel/contents
  45. +84 −0 Extensions/XEP-0045/CoreDataStorage/XMPPRoomCoreDataStorage.h
  46. +475 −0 Extensions/XEP-0045/CoreDataStorage/XMPPRoomCoreDataStorage.m
  47. +38 −0 Extensions/XEP-0045/CoreDataStorage/XMPPRoomMessageCoreDataStorageObject.h
  48. +148 −0 Extensions/XEP-0045/CoreDataStorage/XMPPRoomMessageCoreDataStorageObject.m
  49. +37 −0 Extensions/XEP-0045/CoreDataStorage/XMPPRoomOccupantCoreDataStorageObject.h
  50. +233 −0 Extensions/XEP-0045/CoreDataStorage/XMPPRoomOccupantCoreDataStorageObject.m
  51. +129 −0 Extensions/XEP-0045/MemoryStorage/XMPPRoomMemoryStorage.h
  52. +653 −0 Extensions/XEP-0045/MemoryStorage/XMPPRoomMemoryStorage.m
  53. +34 −0 Extensions/XEP-0045/MemoryStorage/XMPPRoomMessageMemoryStorage.h
  54. +157 −0 Extensions/XEP-0045/MemoryStorage/XMPPRoomMessageMemoryStorage.m
  55. +33 −0 Extensions/XEP-0045/MemoryStorage/XMPPRoomOccupantMemoryStorage.h
  56. +182 −0 Extensions/XEP-0045/MemoryStorage/XMPPRoomOccupantMemoryStorage.m
  57. +49 −0 Extensions/XEP-0045/XMPPMUC.h
  58. +121 −0 Extensions/XEP-0045/XMPPMUC.m
  59. +239 −29 Extensions/XEP-0045/XMPPRoom.h
  60. +778 −364 Extensions/XEP-0045/XMPPRoom.m
  61. +58 −0 Extensions/XEP-0045/XMPPRoomMessage.h
  62. +48 −16 Extensions/XEP-0045/XMPPRoomOccupant.h
  63. +0 −58 Extensions/XEP-0045/XMPPRoomOccupant.m
  64. +16 −0 Extensions/XEP-0045/XMPPRoomPrivate.h
  65. +2 −2 Extensions/XEP-0054/CoreDataStorage/XMPPvCardAvatarCoreDataStorageObject.h
  66. +10 −6 Extensions/XEP-0054/CoreDataStorage/XMPPvCardCoreDataStorage.m
  67. +8 −8 Extensions/XEP-0054/CoreDataStorage/XMPPvCardCoreDataStorageObject.h
  68. +4 −1 Extensions/XEP-0054/CoreDataStorage/XMPPvCardCoreDataStorageObject.m
  69. +2 −2 Extensions/XEP-0054/CoreDataStorage/XMPPvCardTempCoreDataStorageObject.h
  70. +41 −41 Extensions/XEP-0054/XMPPvCardTemp.h
  71. +8 −7 Extensions/XEP-0054/XMPPvCardTemp.m
  72. +7 −10 Extensions/XEP-0054/XMPPvCardTempAdr.h
  73. +4 −0 Extensions/XEP-0054/XMPPvCardTempAdr.m
  74. +4 −0 Extensions/XEP-0054/XMPPvCardTempAdrTypes.m
  75. +3 −1 Extensions/XEP-0054/XMPPvCardTempBase.m
  76. +6 −7 Extensions/XEP-0054/XMPPvCardTempEmail.h
  77. +4 −0 Extensions/XEP-0054/XMPPvCardTempEmail.m
  78. +1 −1 Extensions/XEP-0054/XMPPvCardTempLabel.h
  79. +4 −1 Extensions/XEP-0054/XMPPvCardTempLabel.m
  80. +3 −3 Extensions/XEP-0054/XMPPvCardTempModule.h
  81. +16 −17 Extensions/XEP-0054/XMPPvCardTempModule.m
  82. +14 −15 Extensions/XEP-0054/XMPPvCardTempTel.h
  83. +4 −0 Extensions/XEP-0054/XMPPvCardTempTel.m
  84. +5 −6 Extensions/XEP-0060/XMPPPubSub.m
  85. +33 −66 Extensions/XEP-0065/TURNSocket.m
  86. +4 −4 Extensions/XEP-0082/NSDate+XMPPDateTimeProfiles.m
  87. +3 −3 Extensions/XEP-0082/XMPPDateTimeProfiles.m
  88. +1 −1 Extensions/XEP-0100/XMPPTransports.h
  89. +5 −6 Extensions/XEP-0100/XMPPTransports.m
  90. +28 −32 Extensions/XEP-0115/CoreDataStorage/XMPPCapabilitiesCoreDataStorage.m
  91. +5 −5 Extensions/XEP-0115/CoreDataStorage/XMPPCapsCoreDataStorageObject.h
  92. +5 −1 Extensions/XEP-0115/CoreDataStorage/XMPPCapsCoreDataStorageObject.m
  93. +9 −9 Extensions/XEP-0115/CoreDataStorage/XMPPCapsResourceCoreDataStorageObject.h
  94. +4 −0 Extensions/XEP-0115/CoreDataStorage/XMPPCapsResourceCoreDataStorageObject.m
  95. +2 −2 Extensions/XEP-0115/XMPPCapabilities.h
  96. +25 −52 Extensions/XEP-0115/XMPPCapabilities.m
  97. +3 −3 Extensions/XEP-0153/XMPPvCardAvatarModule.h
  98. +11 −16 Extensions/XEP-0153/XMPPvCardAvatarModule.m
  99. +1 −1 Extensions/XEP-0199/XMPPAutoPing.h
  100. +13 −19 Extensions/XEP-0199/XMPPAutoPing.m
  101. +16 −32 Extensions/XEP-0199/XMPPPing.m
  102. +1 −1 Extensions/XEP-0202/XMPPAutoTime.h
  103. +15 −23 Extensions/XEP-0202/XMPPAutoTime.m
  104. +16 −33 Extensions/XEP-0202/XMPPTime.m
  105. +4 −1 Extensions/XEP-0203/XMPPElement+Delay.m
  106. +6 −4 Utilities/DDList.m
  107. +4 −20 Utilities/GCDMulticastDelegate.h
  108. +117 −247 Utilities/GCDMulticastDelegate.m
  109. +2 −2 Utilities/RFImageToDataTransformer.m
  110. +13 −35 Utilities/XMPPDigestAuthentication.m
  111. +1 −1 Utilities/XMPPIDTracker.h
  112. +11 −21 Utilities/XMPPIDTracker.m
  113. +3 −3 Utilities/XMPPSRVResolver.h
  114. +39 −64 Utilities/XMPPSRVResolver.m
  115. +7 −10 Utilities/XMPPXFacebookPlatformAuthentication.m
  116. +77 −25 Vendor/CocoaAsyncSocket/GCDAsyncSocket.h
  117. +58 −35 Vendor/CocoaAsyncSocket/GCDAsyncSocket.m
  118. +4 −4 Vendor/CocoaLumberjack/DDASLLogger.h
  119. +14 −1 Vendor/CocoaLumberjack/DDASLLogger.m
  120. +4 −4 Vendor/CocoaLumberjack/DDAbstractDatabaseLogger.h
  121. +76 −76 Vendor/CocoaLumberjack/DDAbstractDatabaseLogger.m
  122. +16 −16 Vendor/CocoaLumberjack/DDFileLogger.h
  123. +69 −318 Vendor/CocoaLumberjack/DDFileLogger.m
  124. +10 −127 Vendor/CocoaLumberjack/DDLog.h
  125. +290 −839 Vendor/CocoaLumberjack/DDLog.m
  126. +4 −4 Vendor/CocoaLumberjack/DDTTYLogger.h
  127. +14 −1 Vendor/CocoaLumberjack/DDTTYLogger.m
  128. +65 −0 Vendor/CocoaLumberjack/Extensions/ContextFilterLogFormatter.h
  129. +191 −0 Vendor/CocoaLumberjack/Extensions/ContextFilterLogFormatter.m
  130. +105 −0 Vendor/CocoaLumberjack/Extensions/DispatchQueueLogFormatter.h
  131. +189 −0 Vendor/CocoaLumberjack/Extensions/DispatchQueueLogFormatter.m
  132. +7 −0 Vendor/CocoaLumberjack/Extensions/README.txt
  133. +5 −3 Vendor/KissXML/Categories/NSString+DDXML.m
  134. +37 −6 Vendor/KissXML/DDXML.h
  135. +17 −0 Vendor/KissXML/DDXMLDocument.h
  136. +22 −4 Vendor/KissXML/DDXMLDocument.m
  137. +17 −0 Vendor/KissXML/DDXMLElement.h
  138. +181 −163 Vendor/KissXML/DDXMLElement.m
  139. +17 −0 Vendor/KissXML/DDXMLNode.h
  140. +739 −150 Vendor/KissXML/DDXMLNode.m
  141. +37 −8 Vendor/KissXML/Private/DDXMLPrivate.h
  142. +1 −1 Vendor/facebook-ios-sdk
  143. +8 −8 Xcode/DesktopXMPP/AppDelegate.h
  144. +0 −2 Xcode/DesktopXMPP/AppDelegate.m
  145. +5 −5 Xcode/DesktopXMPP/ChatController.h
  146. +20 −24 Xcode/DesktopXMPP/ChatController.m
  147. +0 −14 Xcode/DesktopXMPP/ChatWindowManager.h
  148. +0 −84 Xcode/DesktopXMPP/ChatWindowManager.m
  149. +16 −9 Xcode/DesktopXMPP/English.lproj/ChatWindow.nib/designable.nib
  150. BIN Xcode/DesktopXMPP/English.lproj/ChatWindow.nib/keyedobjects.nib
Sorry, we could not display the entire diff because it was too big.
View
1 .gitmodules
@@ -1,3 +1,4 @@
[submodule "Vendor/facebook-ios-sdk"]
path = Vendor/facebook-ios-sdk
url = git://github.com/facebook/facebook-ios-sdk.git
+ ignore = dirty
View
6 Categories/NSData+XMPP.m
@@ -1,6 +1,10 @@
#import "NSData+XMPP.h"
#import <CommonCrypto/CommonDigest.h>
+#if ! __has_feature(objc_arc)
+#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
+#endif
+
@implementation NSData (XMPP)
@@ -39,7 +43,7 @@ - (NSString *)hexStringValue
[stringBuffer appendFormat:@"%02x", (unsigned long)dataBuffer[i]];
}
- return [[stringBuffer copy] autorelease];
+ return [stringBuffer copy];
}
- (NSString *)base64Encoded
View
7 Categories/NSNumber+XMPP.h
@@ -6,8 +6,11 @@
+ (NSNumber *)numberWithPtr:(const void *)ptr;
- (id)initWithPtr:(const void *)ptr;
-+ (BOOL)parseString:(NSString *)str intoSInt64:(SInt64 *)pNum;
-+ (BOOL)parseString:(NSString *)str intoUInt64:(UInt64 *)pNum;
++ (BOOL)parseString:(NSString *)str intoInt32:(int32_t *)pNum;
++ (BOOL)parseString:(NSString *)str intoUInt32:(uint32_t *)pNum;
+
++ (BOOL)parseString:(NSString *)str intoInt64:(int64_t *)pNum;
++ (BOOL)parseString:(NSString *)str intoUInt64:(uint64_t *)pNum;
+ (BOOL)parseString:(NSString *)str intoNSInteger:(NSInteger *)pNum;
+ (BOOL)parseString:(NSString *)str intoNSUInteger:(NSUInteger *)pNum;
View
127 Categories/NSNumber+XMPP.m
@@ -1,100 +1,173 @@
#import "NSNumber+XMPP.h"
+#if ! __has_feature(objc_arc)
+#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
+#endif
+
@implementation NSNumber (XMPP)
+ (NSNumber *)numberWithPtr:(const void *)ptr
{
- return [[[NSNumber alloc] initWithPtr:ptr] autorelease];
+ return [[NSNumber alloc] initWithPtr:ptr];
}
- (id)initWithPtr:(const void *)ptr
{
return [self initWithLong:(long)ptr];
}
-+ (BOOL)parseString:(NSString *)str intoSInt64:(SInt64 *)pNum
++ (BOOL)parseString:(NSString *)str intoInt32:(int32_t *)pNum
{
- if(str == nil)
+ if (str == nil)
{
- *pNum = 0;
+ *pNum = (int32_t)0;
return NO;
}
errno = 0;
- // On both 32-bit and 64-bit machines, long long = 64 bit
+ long result = strtol([str UTF8String], NULL, 10);
- *pNum = strtoll([str UTF8String], NULL, 10);
+ if (LONG_BIT != 32)
+ {
+ if (result > INT32_MAX)
+ {
+ *pNum = INT32_MAX;
+ return NO;
+ }
+ if (result < INT32_MIN)
+ {
+ *pNum = INT32_MIN;
+ return NO;
+ }
+ }
+
+ // From the manpage:
+ //
+ // If no conversion could be performed, 0 is returned and the global variable errno is set to EINVAL.
+ // If an overflow or underflow occurs, errno is set to ERANGE and the function return value is clamped.
+ //
+ // Clamped means it will be TYPE_MAX or TYPE_MIN.
+ // If overflow/underflow occurs, returning a clamped value is more accurate then returning zero.
- if(errno != 0)
+ *pNum = (int32_t)result;
+
+ if (errno != 0)
return NO;
else
return YES;
}
-+ (BOOL)parseString:(NSString *)str intoUInt64:(UInt64 *)pNum
++ (BOOL)parseString:(NSString *)str intoUInt32:(uint32_t *)pNum
{
- if(str == nil)
+ if (str == nil)
{
- *pNum = 0;
+ *pNum = (uint32_t)0;
return NO;
}
errno = 0;
- // On both 32-bit and 64-bit machines, unsigned long long = 64 bit
+ unsigned long result = strtoul([str UTF8String], NULL, 10);
- *pNum = strtoull([str UTF8String], NULL, 10);
+ if (LONG_BIT != 32)
+ {
+ if (result > UINT32_MAX)
+ {
+ *pNum = UINT32_MAX;
+ return NO;
+ }
+ }
+
+ // From the manpage:
+ //
+ // If no conversion could be performed, 0 is returned and the global variable errno is set to EINVAL.
+ // If an overflow or underflow occurs, errno is set to ERANGE and the function return value is clamped.
+ //
+ // Clamped means it will be TYPE_MAX or TYPE_MIN.
+ // If overflow/underflow occurs, returning a clamped value is more accurate then returning zero.
- if(errno != 0)
+ *pNum = (uint32_t)result;
+
+ if (errno != 0)
return NO;
else
return YES;
}
-+ (BOOL)parseString:(NSString *)str intoNSInteger:(NSInteger *)pNum
++ (BOOL)parseString:(NSString *)str intoInt64:(int64_t *)pNum
{
- if(str == nil)
+ if (str == nil)
{
- *pNum = 0;
+ *pNum = (int64_t)0;
return NO;
}
errno = 0;
- // On LP64, NSInteger = long = 64 bit
- // Otherwise, NSInteger = int = long = 32 bit
+ // On both 32-bit and 64-bit machines, long long = 64 bit
- *pNum = strtol([str UTF8String], NULL, 10);
+ *pNum = strtoll([str UTF8String], NULL, 10);
- if(errno != 0)
+ // From the manpage:
+ //
+ // If no conversion could be performed, 0 is returned and the global variable errno is set to EINVAL.
+ // If an overflow or underflow occurs, errno is set to ERANGE and the function return value is clamped.
+ //
+ // Clamped means it will be TYPE_MAX or TYPE_MIN.
+ // If overflow/underflow occurs, returning a clamped value is more accurate then returning zero.
+
+ if (errno != 0)
return NO;
else
return YES;
}
-+ (BOOL)parseString:(NSString *)str intoNSUInteger:(NSUInteger *)pNum
++ (BOOL)parseString:(NSString *)str intoUInt64:(uint64_t *)pNum
{
- if(str == nil)
+ if (str == nil)
{
- *pNum = 0;
+ *pNum = (uint64_t)0;
return NO;
}
errno = 0;
- // On LP64, NSUInteger = unsigned long = 64 bit
- // Otherwise, NSUInteger = unsigned int = unsigned long = 32 bit
+ // On both 32-bit and 64-bit machines, unsigned long long = 64 bit
+
+ *pNum = strtoull([str UTF8String], NULL, 10);
- *pNum = strtoul([str UTF8String], NULL, 10);
+ // From the manpage:
+ //
+ // If no conversion could be performed, 0 is returned and the global variable errno is set to EINVAL.
+ // If an overflow or underflow occurs, errno is set to ERANGE and the function return value is clamped.
+ //
+ // Clamped means it will be TYPE_MAX or TYPE_MIN.
+ // If overflow/underflow occurs, returning a clamped value is more accurate then returning zero.
- if(errno != 0)
+ if (errno != 0)
return NO;
else
return YES;
}
++ (BOOL)parseString:(NSString *)str intoNSInteger:(NSInteger *)pNum
+{
+ if (NSIntegerMax == INT32_MAX)
+ return [self parseString:str intoInt32:(int32_t *)pNum];
+ else
+ return [self parseString:str intoInt64:(int64_t *)pNum];
+}
+
++ (BOOL)parseString:(NSString *)str intoNSUInteger:(NSUInteger *)pNum
+{
+ if (NSUIntegerMax == UINT32_MAX)
+ return [self parseString:str intoUInt32:(uint32_t *)pNum];
+ else
+ return [self parseString:str intoUInt64:(uint64_t *)pNum];
+}
+
+ (UInt8)extractUInt8FromData:(NSData *)data atOffset:(unsigned int)offset
{
// 8 bits = 1 byte
View
67 Categories/NSXMLElement+XMPP.h
@@ -7,27 +7,73 @@
@interface NSXMLElement (XMPP)
+/**
+ * Creating elements with explicit xmlns values.
+ *
+ * Use these instead of [NSXMLElement initWithName:URI:].
+ * The category methods below are more readable, and they actually work.
+**/
+
+ (NSXMLElement *)elementWithName:(NSString *)name xmlns:(NSString *)ns;
- (id)initWithName:(NSString *)name xmlns:(NSString *)ns;
+/**
+ * Extracting a single element.
+**/
+
- (NSXMLElement *)elementForName:(NSString *)name;
- (NSXMLElement *)elementForName:(NSString *)name xmlns:(NSString *)xmlns;
+/**
+ * Working with the common xmpp xmlns value.
+ *
+ * Use these instead of getting/setting the URI.
+ * The category methods below are more readable, and they actually work.
+**/
+
- (NSString *)xmlns;
- (void)setXmlns:(NSString *)ns;
+/**
+ * Convenience methods for printing xml elements with different styles.
+**/
+
- (NSString *)prettyXMLString;
- (NSString *)compactXMLString;
+/**
+ * Convenience methods for adding attributes.
+**/
+
- (void)addAttributeWithName:(NSString *)name stringValue:(NSString *)string;
+/**
+ * Convenience methods for extracting attribute values in different formats.
+ *
+ * E.g. <beer name="guinness" price="4.50"/> // float price = [beer attributeFloatValueForName:@"price"];
+**/
+
- (int)attributeIntValueForName:(NSString *)name;
- (BOOL)attributeBoolValueForName:(NSString *)name;
- (float)attributeFloatValueForName:(NSString *)name;
- (double)attributeDoubleValueForName:(NSString *)name;
+- (int32_t)attributeInt32ValueForName:(NSString *)name;
+- (uint32_t)attributeUInt32ValueForName:(NSString *)name;
+- (int64_t)attributeInt64ValueForName:(NSString *)name;
+- (uint64_t)attributeUInt64ValueForName:(NSString *)name;
+- (NSInteger)attributeIntegerValueForName:(NSString *)name;
+- (NSUInteger)attributeUnsignedIntegerValueForName:(NSString *)name;
- (NSString *)attributeStringValueForName:(NSString *)name;
- (NSNumber *)attributeNumberIntValueForName:(NSString *)name;
- (NSNumber *)attributeNumberBoolValueForName:(NSString *)name;
+- (NSNumber *)attributeNumberFloatValueForName:(NSString *)name;
+- (NSNumber *)attributeNumberDoubleValueForName:(NSString *)name;
+- (NSNumber *)attributeNumberInt32ValueForName:(NSString *)name;
+- (NSNumber *)attributeNumberUInt32ValueForName:(NSString *)name;
+- (NSNumber *)attributeNumberInt64ValueForName:(NSString *)name;
+- (NSNumber *)attributeNumberUInt64ValueForName:(NSString *)name;
+- (NSNumber *)attributeNumberIntegerValueForName:(NSString *)name;
+- (NSNumber *)attributeNumberUnsignedIntegerValueForName:(NSString *)name;
- (int)attributeIntValueForName:(NSString *)name withDefaultValue:(int)defaultValue;
- (BOOL)attributeBoolValueForName:(NSString *)name withDefaultValue:(BOOL)defaultValue;
@@ -39,6 +85,27 @@
- (NSMutableDictionary *)attributesAsDictionary;
+/**
+ * Convenience methods for extracting element values in different formats.
+ *
+ * E.g. <price>9.99</price> // float price = [priceElement stringValueAsFloat];
+**/
+
+- (int)stringValueAsInt;
+- (BOOL)stringValueAsBool;
+- (float)stringValueAsFloat;
+- (double)stringValueAsDouble;
+- (int32_t)stringValueAsInt32;
+- (uint32_t)stringValueAsUInt32;
+- (int64_t)stringValueAsInt64;
+- (uint64_t)stringValueAsUInt64;
+- (NSInteger)stringValueAsNSInteger;
+- (NSUInteger)stringValueAsNSUInteger;
+
+/**
+ * Working with namespaces.
+**/
+
- (void)addNamespaceWithPrefix:(NSString *)prefix stringValue:(NSString *)string;
- (NSString *)namespaceStringValueForPrefix:(NSString *)prefix;
View
148 Categories/NSXMLElement+XMPP.m
@@ -1,4 +1,9 @@
#import "NSXMLElement+XMPP.h"
+#import "NSNumber+XMPP.h"
+
+#if ! __has_feature(objc_arc)
+#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
+#endif
@implementation NSXMLElement (XMPP)
@@ -14,7 +19,7 @@ + (NSXMLElement *)elementWithName:(NSString *)name xmlns:(NSString *)ns
- (id)initWithName:(NSString *)name xmlns:(NSString *)ns
{
- if ([self initWithName:name])
+ if ((self = [self initWithName:name]))
{
[self setXmlns:ns];
}
@@ -28,7 +33,7 @@ - (id)initWithName:(NSString *)name xmlns:(NSString *)ns
- (NSXMLElement *)elementForName:(NSString *)name
{
NSArray *elements = [self elementsForName:name];
- if([elements count] > 0)
+ if ([elements count] > 0)
{
return [elements objectAtIndex:0];
}
@@ -64,7 +69,7 @@ - (NSXMLElement *)elementForName:(NSString *)name
- (NSXMLElement *)elementForName:(NSString *)name xmlns:(NSString *)xmlns
{
NSArray *elements = [self elementsForLocalName:name URI:xmlns];
- if([elements count] > 0)
+ if ([elements count] > 0)
{
return [elements objectAtIndex:0];
}
@@ -135,6 +140,42 @@ - (double)attributeDoubleValueForName:(NSString *)name
{
return [[self attributeStringValueForName:name] doubleValue];
}
+- (int32_t)attributeInt32ValueForName:(NSString *)name
+{
+ int32_t result = 0;
+ [NSNumber parseString:[self attributeStringValueForName:name] intoInt32:&result];
+ return result;
+}
+- (uint32_t)attributeUInt32ValueForName:(NSString *)name
+{
+ uint32_t result = 0;
+ [NSNumber parseString:[self attributeStringValueForName:name] intoUInt32:&result];
+ return result;
+}
+- (int64_t)attributeInt64ValueForName:(NSString *)name
+{
+ int64_t result;
+ [NSNumber parseString:[self attributeStringValueForName:name] intoInt64:&result];
+ return result;
+}
+- (uint64_t)attributeUInt64ValueForName:(NSString *)name
+{
+ uint64_t result;
+ [NSNumber parseString:[self attributeStringValueForName:name] intoUInt64:&result];
+ return result;
+}
+- (NSInteger)attributeIntegerValueForName:(NSString *)name
+{
+ NSInteger result;
+ [NSNumber parseString:[self attributeStringValueForName:name] intoNSInteger:&result];
+ return result;
+}
+- (NSUInteger)attributeUnsignedIntegerValueForName:(NSString *)name
+{
+ NSUInteger result = 0;
+ [NSNumber parseString:[self attributeStringValueForName:name] intoNSUInteger:&result];
+ return result;
+}
- (NSString *)attributeStringValueForName:(NSString *)name
{
return [[self attributeForName:name] stringValue];
@@ -147,6 +188,38 @@ - (NSNumber *)attributeNumberBoolValueForName:(NSString *)name
{
return [NSNumber numberWithBool:[self attributeBoolValueForName:name]];
}
+- (NSNumber *)attributeNumberFloatValueForName:(NSString *)name
+{
+ return [NSNumber numberWithFloat:[self attributeFloatValueForName:name]];
+}
+- (NSNumber *)attributeNumberDoubleValueForName:(NSString *)name
+{
+ return [NSNumber numberWithDouble:[self attributeDoubleValueForName:name]];
+}
+- (NSNumber *)attributeNumberInt32ValueForName:(NSString *)name
+{
+ return [NSNumber numberWithInt:[self attributeInt32ValueForName:name]];
+}
+- (NSNumber *)attributeNumberUInt32ValueForName:(NSString *)name
+{
+ return [NSNumber numberWithUnsignedInt:[self attributeUInt32ValueForName:name]];
+}
+- (NSNumber *)attributeNumberInt64ValueForName:(NSString *)name
+{
+ return [NSNumber numberWithLongLong:[self attributeInt64ValueForName:name]];
+}
+- (NSNumber *)attributeNumberUInt64ValueForName:(NSString *)name
+{
+ return [NSNumber numberWithUnsignedLongLong:[self attributeUInt64ValueForName:name]];
+}
+- (NSNumber *)attributeNumberIntegerValueForName:(NSString *)name
+{
+ return [NSNumber numberWithInteger:[self attributeIntegerValueForName:name]];
+}
+- (NSNumber *)attributeNumberUnsignedIntegerValueForName:(NSString *)name
+{
+ return [NSNumber numberWithUnsignedInteger:[self attributeUnsignedIntegerValueForName:name]];
+}
/**
* The following methods return the corresponding value of the attribute with the given name.
@@ -206,6 +279,75 @@ - (NSMutableDictionary *)attributesAsDictionary
}
/**
+ * The following methods return the corresponding value of the node.
+**/
+
+- (int)stringValueAsInt
+{
+ return [[self stringValue] intValue];
+}
+- (BOOL)stringValueAsBool
+{
+ return [[self stringValue] boolValue];
+}
+- (float)stringValueAsFloat
+{
+ return [[self stringValue] floatValue];
+}
+- (double)stringValueAsDouble
+{
+ return [[self stringValue] doubleValue];
+}
+- (int32_t)stringValueAsInt32
+{
+ int32_t result;
+ if ([NSNumber parseString:[self stringValue] intoInt32:&result])
+ return result;
+ else
+ return 0;
+}
+- (uint32_t)stringValueAsUInt32
+{
+ uint32_t result;
+ if ([NSNumber parseString:[self stringValue] intoUInt32:&result])
+ return result;
+ else
+ return 0;
+}
+- (int64_t)stringValueAsInt64
+{
+ int64_t result = 0;
+ if ([NSNumber parseString:[self stringValue] intoInt64:&result])
+ return result;
+ else
+ return 0;
+}
+- (uint64_t)stringValueAsUInt64
+{
+ uint64_t result = 0;
+ if ([NSNumber parseString:[self stringValue] intoUInt64:&result])
+ return result;
+ else
+ return 0;
+}
+- (NSInteger)stringValueAsNSInteger
+{
+ NSInteger result = 0;
+ if ([NSNumber parseString:[self stringValue] intoNSInteger:&result])
+ return result;
+ else
+ return 0;
+}
+- (NSUInteger)stringValueAsNSUInteger
+{
+ NSUInteger result = 0;
+ if ([NSNumber parseString:[self stringValue] intoNSUInteger:&result])
+ return result;
+ else
+ return 0;
+}
+
+/**
* Shortcut to avoid having to use NSXMLNode everytime
**/
- (void)addNamespaceWithPrefix:(NSString *)prefix stringValue:(NSString *)string
View
2 Core/XMPPElement.h
@@ -15,7 +15,7 @@
* On the iPhone, the KissXML library provides a drop-in replacement for Apple's NSXML classes.
**/
-@interface XMPPElement : NSXMLElement <NSCoding>
+@interface XMPPElement : NSXMLElement <NSCoding, NSCopying>
- (NSString *)elementID;
View
28 Core/XMPPElement.m
@@ -2,6 +2,8 @@
#import "XMPPJID.h"
#import "NSXMLElement+XMPP.h"
+#import <objc/runtime.h>
+
@implementation XMPPElement
@@ -32,7 +34,19 @@ - (id)initWithCoder:(NSCoder *)coder
xmlString = [coder decodeObject];
}
- return [super initWithXMLString:xmlString error:nil];
+ // The method [super initWithXMLString:error:] may return a different self.
+ // In other words, it may [self release], and alloc/init/return a new self.
+ //
+ // So to maintain the proper class (XMPPIQ, XMPPMessage, XMPPPresence, etc)
+ // we need to get a reference to the class before invoking super.
+
+ Class selfClass = [self class];
+
+ if ((self = [super initWithXMLString:xmlString error:nil]))
+ {
+ object_setClass(self, selfClass);
+ }
+ return self;
}
- (void)encodeWithCoder:(NSCoder *)coder
@@ -50,6 +64,18 @@ - (void)encodeWithCoder:(NSCoder *)coder
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+#pragma mark Copying
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (id)copyWithZone:(NSZone *)zone
+{
+ NSXMLElement *elementCopy = [super copyWithZone:zone];
+ object_setClass(elementCopy, [self class]);
+
+ return elementCopy;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark Common Jabber Methods
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
View
24 Core/XMPPIQ.m
@@ -4,6 +4,10 @@
#import <objc/runtime.h>
+#if ! __has_feature(objc_arc)
+#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
+#endif
+
@implementation XMPPIQ
@@ -38,27 +42,27 @@ + (XMPPIQ *)iqFromElement:(NSXMLElement *)element
+ (XMPPIQ *)iq
{
- return [[[XMPPIQ alloc] initWithType:nil to:nil elementID:nil child:nil] autorelease];
+ return [[XMPPIQ alloc] initWithType:nil to:nil elementID:nil child:nil];
}
+ (XMPPIQ *)iqWithType:(NSString *)type
{
- return [[[XMPPIQ alloc] initWithType:type to:nil elementID:nil child:nil] autorelease];
+ return [[XMPPIQ alloc] initWithType:type to:nil elementID:nil child:nil];
}
+ (XMPPIQ *)iqWithType:(NSString *)type to:(XMPPJID *)jid
{
- return [[[XMPPIQ alloc] initWithType:type to:jid elementID:nil child:nil] autorelease];
+ return [[XMPPIQ alloc] initWithType:type to:jid elementID:nil child:nil];
}
+ (XMPPIQ *)iqWithType:(NSString *)type to:(XMPPJID *)jid elementID:(NSString *)eid
{
- return [[[XMPPIQ alloc] initWithType:type to:jid elementID:eid child:nil] autorelease];
+ return [[XMPPIQ alloc] initWithType:type to:jid elementID:eid child:nil];
}
+ (XMPPIQ *)iqWithType:(NSString *)type to:(XMPPJID *)jid elementID:(NSString *)eid child:(NSXMLElement *)childElement
{
- return [[[XMPPIQ alloc] initWithType:type to:jid elementID:eid child:childElement] autorelease];
+ return [[XMPPIQ alloc] initWithType:type to:jid elementID:eid child:childElement];
}
- (id)init
@@ -138,7 +142,10 @@ - (NSXMLElement *)childElement
NSArray *children = [self children];
for (NSXMLElement *child in children)
{
- if ([[child name] caseInsensitiveCompare:@"error"] != NSOrderedSame)
+ // Careful: NSOrderedSame == 0
+
+ NSString *childName = [child name];
+ if (childName && ([childName caseInsensitiveCompare:@"error"] != NSOrderedSame))
{
return child;
}
@@ -152,7 +159,10 @@ - (NSXMLElement *)childErrorElement
NSArray *children = [self children];
for (NSXMLElement *child in children)
{
- if ([[child name] caseInsensitiveCompare:@"error"] == NSOrderedSame)
+ // Careful: NSOrderedSame == 0
+
+ NSString *childName = [child name];
+ if (childName && ([childName caseInsensitiveCompare:@"error"] == NSOrderedSame))
{
return child;
}
View
12 Core/XMPPJID.h
@@ -14,18 +14,18 @@ typedef enum XMPPJIDCompareOptions XMPPJIDCompareOptions;
@interface XMPPJID : NSObject <NSCoding, NSCopying>
{
- NSString *user;
- NSString *domain;
- NSString *resource;
+ __strong NSString *user;
+ __strong NSString *domain;
+ __strong NSString *resource;
}
+ (XMPPJID *)jidWithString:(NSString *)jidStr;
+ (XMPPJID *)jidWithString:(NSString *)jidStr resource:(NSString *)resource;
+ (XMPPJID *)jidWithUser:(NSString *)user domain:(NSString *)domain resource:(NSString *)resource;
-@property (readonly) NSString *user;
-@property (readonly) NSString *domain;
-@property (readonly) NSString *resource;
+@property (strong, readonly) NSString *user;
+@property (strong, readonly) NSString *domain;
+@property (strong, readonly) NSString *resource;
- (XMPPJID *)bareJID;
- (XMPPJID *)domainJID;
View
79 Core/XMPPJID.m
@@ -1,6 +1,11 @@
#import "XMPPJID.h"
#import "LibIDN.h"
+#if ! __has_feature(objc_arc)
+#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
+#endif
+
+
@implementation XMPPJID
+ (BOOL)validateDomain:(NSString *)domain
@@ -54,15 +59,15 @@ + (BOOL)parse:(NSString *)jidStr
NSRange atRange = [jidStr rangeOfString:@"@"];
- if(atRange.location != NSNotFound)
+ if (atRange.location != NSNotFound)
{
rawUser = [jidStr substringToIndex:atRange.location];
NSString *minusUser = [jidStr substringFromIndex:atRange.location+1];
NSRange slashRange = [minusUser rangeOfString:@"/"];
- if(slashRange.location != NSNotFound)
+ if (slashRange.location != NSNotFound)
{
rawDomain = [minusUser substringToIndex:slashRange.location];
rawResource = [minusUser substringFromIndex:slashRange.location+1];
@@ -76,7 +81,7 @@ + (BOOL)parse:(NSString *)jidStr
{
NSRange slashRange = [jidStr rangeOfString:@"/"];
- if(slashRange.location != NSNotFound)
+ if (slashRange.location != NSNotFound)
{
rawDomain = [jidStr substringToIndex:slashRange.location];
rawResource = [jidStr substringFromIndex:slashRange.location+1];
@@ -91,7 +96,7 @@ + (BOOL)parse:(NSString *)jidStr
NSString *prepDomain = [LibIDN prepDomain:rawDomain];
NSString *prepResource = [LibIDN prepResource:rawResource];
- if([XMPPJID validateUser:prepUser domain:prepDomain resource:prepResource])
+ if ([XMPPJID validateUser:prepUser domain:prepDomain resource:prepResource])
{
if(user) *user = prepUser;
if(domain) *domain = prepDomain;
@@ -109,34 +114,34 @@ + (XMPPJID *)jidWithString:(NSString *)jidStr
NSString *domain;
NSString *resource;
- if([XMPPJID parse:jidStr outUser:&user outDomain:&domain outResource:&resource])
+ if ([XMPPJID parse:jidStr outUser:&user outDomain:&domain outResource:&resource])
{
XMPPJID *jid = [[XMPPJID alloc] init];
jid->user = [user copy];
jid->domain = [domain copy];
jid->resource = [resource copy];
- return [jid autorelease];
+ return jid;
}
return nil;
}
+ (XMPPJID *)jidWithString:(NSString *)jidStr resource:(NSString *)resource
{
- if(![self validateResource:resource]) return nil;
+ if (![self validateResource:resource]) return nil;
NSString *user;
NSString *domain;
- if([XMPPJID parse:jidStr outUser:&user outDomain:&domain outResource:nil])
+ if ([XMPPJID parse:jidStr outUser:&user outDomain:&domain outResource:nil])
{
XMPPJID *jid = [[XMPPJID alloc] init];
jid->user = [user copy];
jid->domain = [domain copy];
jid->resource = [resource copy];
- return [jid autorelease];
+ return jid;
}
return nil;
@@ -148,19 +153,29 @@ + (XMPPJID *)jidWithUser:(NSString *)user domain:(NSString *)domain resource:(NS
NSString *prepDomain = [LibIDN prepDomain:domain];
NSString *prepResource = [LibIDN prepResource:resource];
- if([XMPPJID validateUser:prepUser domain:prepDomain resource:prepResource])
+ if ([XMPPJID validateUser:prepUser domain:prepDomain resource:prepResource])
{
XMPPJID *jid = [[XMPPJID alloc] init];
jid->user = [prepUser copy];
jid->domain = [prepDomain copy];
jid->resource = [prepResource copy];
- return [jid autorelease];
+ return jid;
}
return nil;
}
++ (XMPPJID *)jidWithPrevalidatedUser:(NSString *)user domain:(NSString *)domain resource:(NSString *)resource
+{
+ XMPPJID *jid = [[XMPPJID alloc] init];
+ jid->user = [user copy];
+ jid->domain = [domain copy];
+ jid->resource = [resource copy];
+
+ return jid;
+}
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark Encoding, Decoding:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -178,9 +193,9 @@ - (id)replacementObjectForPortCoder:(NSPortCoder *)encoder
- (id)initWithCoder:(NSCoder *)coder
{
- if((self = [super init]))
+ if ((self = [super init]))
{
- if([coder allowsKeyedCoding])
+ if ([coder allowsKeyedCoding])
{
user = [[coder decodeObjectForKey:@"user"] copy];
domain = [[coder decodeObjectForKey:@"domain"] copy];
@@ -198,7 +213,7 @@ - (id)initWithCoder:(NSCoder *)coder
- (void)encodeWithCoder:(NSCoder *)coder
{
- if([coder allowsKeyedCoding])
+ if ([coder allowsKeyedCoding])
{
[coder encodeObject:user forKey:@"user"];
[coder encodeObject:domain forKey:@"domain"];
@@ -219,7 +234,7 @@ - (void)encodeWithCoder:(NSCoder *)coder
- (id)copyWithZone:(NSZone *)zone
{
// This class is immutable
- return [self retain];
+ return self;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -251,48 +266,48 @@ - (NSString *)resource
- (XMPPJID *)bareJID
{
- if(resource == nil)
+ if (resource == nil)
{
- return [[self retain] autorelease];
+ return self;
}
else
{
- return [XMPPJID jidWithUser:user domain:domain resource:nil];
+ return [XMPPJID jidWithPrevalidatedUser:user domain:domain resource:nil];
}
}
- (XMPPJID *)domainJID
{
- if(user == nil && resource == nil)
+ if (user == nil && resource == nil)
{
- return [[self retain] autorelease];
+ return self;
}
else
{
- return [XMPPJID jidWithUser:nil domain:domain resource:nil];
+ return [XMPPJID jidWithPrevalidatedUser:nil domain:domain resource:nil];
}
}
- (NSString *)bare
{
- if(user)
+ if (user)
return [NSString stringWithFormat:@"%@@%@", user, domain];
else
return domain;
}
- (NSString *)full
{
- if(user)
+ if (user)
{
- if(resource)
+ if (resource)
return [NSString stringWithFormat:@"%@@%@/%@", user, domain, resource];
else
return [NSString stringWithFormat:@"%@@%@", user, domain];
}
else
{
- if(resource)
+ if (resource)
return [NSString stringWithFormat:@"%@/%@", domain, resource];
else
return domain;
@@ -339,17 +354,10 @@ - (BOOL)isServer
#pragma mark NSObject Methods:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
-- (unsigned)hash
-{
- return [[self full] hash];
-}
-#else
- (NSUInteger)hash
{
return [[self full] hash];
}
-#endif
- (BOOL)isEqual:(id)anObject
{
@@ -407,12 +415,5 @@ - (NSString *)description
return [self full];
}
-- (void)dealloc
-{
- [user release];
- [domain release];
- [resource release];
- [super dealloc];
-}
@end
View
4 Core/XMPPMessage.h
@@ -17,8 +17,12 @@
+ (XMPPMessage *)messageFromElement:(NSXMLElement *)element;
+ (XMPPMessage *)message;
++ (XMPPMessage *)messageWithType:(NSString *)type;
++ (XMPPMessage *)messageWithType:(NSString *)type to:(XMPPJID *)to;
- (id)init;
+- (id)initWithType:(NSString *)type;
+- (id)initWithType:(NSString *)type to:(XMPPJID *)to;
- (BOOL)isChatMessage;
- (BOOL)isChatMessageWithBody;
View
43 Core/XMPPMessage.m
@@ -4,6 +4,10 @@
#import <objc/runtime.h>
+#if ! __has_feature(objc_arc)
+#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
+#endif
+
@implementation XMPPMessage
@@ -38,7 +42,17 @@ + (XMPPMessage *)messageFromElement:(NSXMLElement *)element
+ (XMPPMessage *)message
{
- return [[[XMPPMessage alloc] init] autorelease];
+ return [[XMPPMessage alloc] init];
+}
+
++ (XMPPMessage *)messageWithType:(NSString *)type
+{
+ return [[XMPPMessage alloc] initWithType:type to:nil];
+}
+
++ (XMPPMessage *)messageWithType:(NSString *)type to:(XMPPJID *)to
+{
+ return [[XMPPMessage alloc] initWithType:type to:to];
}
- (id)init
@@ -47,6 +61,24 @@ - (id)init
return self;
}
+- (id)initWithType:(NSString *)type
+{
+ return [self initWithType:type to:nil];
+}
+
+- (id)initWithType:(NSString *)type to:(XMPPJID *)to
+{
+ if ((self = [super initWithName:@"message"]))
+ {
+ if (type)
+ [self addAttributeWithName:@"type" stringValue:type];
+
+ if (to)
+ [self addAttributeWithName:@"to" stringValue:[to description]];
+ }
+ return self;
+}
+
- (BOOL)isChatMessage
{
return [[[self attributeForName:@"type"] stringValue] isEqualToString:@"chat"];
@@ -78,10 +110,11 @@ - (NSError *)errorMessage {
}
-- (BOOL)isMessageWithBody {
- NSString *body = [[self elementForName:@"body"] stringValue];
-
- return ((body != nil) && ([body length] > 0));
+- (BOOL)isMessageWithBody
+{
+ NSString *body = [[self elementForName:@"body"] stringValue];
+
+ return ([body length] > 0);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
View
4 Core/XMPPModule.h
@@ -15,14 +15,14 @@
**/
@interface XMPPModule : NSObject
{
- XMPPStream *xmppStream;
+ __strong XMPPStream *xmppStream;
dispatch_queue_t moduleQueue;
id multicastDelegate;
}
@property (readonly) dispatch_queue_t moduleQueue;
-@property (readonly) XMPPStream *xmppStream;
+@property (strong, readonly) XMPPStream *xmppStream;
- (id)init;
- (id)initWithDispatchQueue:(dispatch_queue_t)queue;
View
13 Core/XMPPModule.m
@@ -2,6 +2,10 @@
#import "XMPPStream.h"
#import "XMPPLogging.h"
+#if ! __has_feature(objc_arc)
+#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
+#endif
+
// Log levels: off, error, warn, info, verbose
#if DEBUG
static const int xmppLogLevel = XMPP_LOG_LEVEL_WARN;
@@ -78,11 +82,9 @@ - (void)dealloc
[self deactivate];
}
- [multicastDelegate release];
dispatch_release(moduleQueue);
- [super dealloc];
}
/**
@@ -102,7 +104,7 @@ - (BOOL)activate:(XMPPStream *)aXmppStream
}
else
{
- xmppStream = [aXmppStream retain];
+ xmppStream = aXmppStream;
[xmppStream addDelegate:self delegateQueue:moduleQueue];
[xmppStream registerModule:self];
@@ -134,7 +136,6 @@ - (void)deactivate
[xmppStream removeDelegate:self delegateQueue:moduleQueue];
[xmppStream unregisterModule:self];
- [xmppStream release];
xmppStream = nil;
}
};
@@ -174,10 +175,10 @@ - (XMPPStream *)xmppStream
__block XMPPStream *result;
dispatch_sync(moduleQueue, ^{
- result = [xmppStream retain];
+ result = xmppStream;
});
- return [result autorelease];
+ return result;
}
}
View
57 Core/XMPPParser.m
@@ -6,6 +6,10 @@
#import "DDXMLPrivate.h"
#endif
+#if ! __has_feature(objc_arc)
+#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
+#endif
+
// Log levels: off, error, warn, info, verbose
#if DEBUG
static const int xmppLogLevel = XMPP_LOG_LEVEL_VERBOSE;
@@ -90,7 +94,16 @@ static void xmpp_onDidReadRoot(XMPPParser *parser, xmlNodePtr root)
static void xmpp_onDidReadElement(XMPPParser *parser, xmlNodePtr child)
{
- [DDXMLNode detachChild:child fromNode:child->parent];
+ // Detach the child from the xml tree.
+ //
+ // clean: Nullify next, prev, parent and doc pointers of child.
+ // fixNamespaces: Recurse through subtree, and ensure no namespaces are pointing to xmlNs nodes outside the tree.
+ // E.G. in a parent node that will no longer be available after the child is detached.
+ //
+ // We don't need to fix namespaces since we used xmpp_xmlSearchNs() to ensure we never created any
+ // namespaces outside the subtree of the child in the first place.
+
+ [DDXMLNode detachChild:child andClean:YES andFixNamespaces:NO];
DDXMLElement *childWrapper = [DDXMLElement nodeWithElementPrimitive:child owner:nil];
@@ -145,16 +158,12 @@ static void xmpp_setName(NSXMLElement *element, xmlNodePtr node)
NSString *elementName = [[NSString alloc] initWithFormat:@"%@:%@", prefix, name];
[element setName:elementName];
- [elementName release];
- [name release];
- [prefix release];
}
else
{
NSString *elementName = [[NSString alloc] initWithUTF8String:(const char *)node->name];
[element setName:elementName];
- [elementName release];
}
}
@@ -177,7 +186,6 @@ static void xmpp_addNamespaces(NSXMLElement *element, xmlNodePtr node)
{
NSString *nsName = [[NSString alloc] initWithUTF8String:(const char *)nsNode->prefix];
[ns setName:nsName];
- [nsName release];
}
else
{
@@ -189,10 +197,8 @@ static void xmpp_addNamespaces(NSXMLElement *element, xmlNodePtr node)
NSString *nsValue = [[NSString alloc] initWithUTF8String:(const char *)nsNode->href];
[ns setStringValue:nsValue];
- [nsValue release];
[element addNamespace:ns];
- [ns release];
}
nsNode = nsNode->next;
@@ -216,7 +222,6 @@ static void xmpp_addChildren(NSXMLElement *element, xmlNodePtr node)
{
NSString *value = [[NSString alloc] initWithUTF8String:(const char *)childNode->content];
[element setStringValue:value];
- [value release];
}
}
@@ -256,24 +261,18 @@ static void xmpp_addAttributes(NSXMLElement *element, xmlNodePtr node)
NSString *attrName = [[NSString alloc] initWithFormat:@"%@:%@", prefix, name];
[attr setName:attrName];
- [attrName release];
- [name release];
- [prefix release];
}
else
{
NSString *attrName = [[NSString alloc] initWithUTF8String:(const char *)attrNode->name];
[attr setName:attrName];
- [attrName release];
}
NSString *attrValue = [[NSString alloc] initWithUTF8String:(const char *)attrNode->children->content];
[attr setStringValue:attrValue];
- [attrValue release];
[element addAttribute:attr];
- [attr release];
}
attrNode = attrNode->next;
@@ -284,7 +283,7 @@ static void xmpp_addAttributes(NSXMLElement *element, xmlNodePtr node)
* Recursively adds all the child elements to the given parent.
*
* Note: This method is almost the same as xmpp_nsxmlFromLibxml, with one important difference.
- * It doen't add any objects to the autorelease pool.
+ * It doen't add any objects to the autorelease pool (xmpp_nsxmlFromLibXml has return value).
**/
static void xmpp_recursiveAddChild(NSXMLElement *parent, xmlNodePtr childNode)
{
@@ -300,7 +299,6 @@ static void xmpp_recursiveAddChild(NSXMLElement *parent, xmlNodePtr childNode)
xmpp_addAttributes(child, childNode);
[parent addChild:child];
- [child release];
}
/**
@@ -320,7 +318,7 @@ static void xmpp_recursiveAddChild(NSXMLElement *parent, xmlNodePtr childNode)
xmpp_addChildren(root, rootNode);
xmpp_addAttributes(root, rootNode);
- return [root autorelease];
+ return root;
}
static void xmpp_onDidReadRoot(XMPPParser *parser, xmlNodePtr root)
@@ -392,7 +390,7 @@ static void xmpp_onDidReadElement(XMPPParser *parser, xmlNodePtr child)
**/
static void xmpp_postStartElement(xmlParserCtxt *ctxt)
{
- XMPPParser *parser = (XMPPParser *)ctxt->_private;
+ XMPPParser *parser = (__bridge XMPPParser *)ctxt->_private;
parser->depth++;
if(!(parser->hasReportedRoot) && (parser->depth == 1))
@@ -418,7 +416,7 @@ static void xmpp_postStartElement(xmlParserCtxt *ctxt)
**/
static void xmpp_postEndElement(xmlParserCtxt *ctxt)
{
- XMPPParser *parser = (XMPPParser *)ctxt->_private;
+ XMPPParser *parser = (__bridge XMPPParser *)ctxt->_private;
parser->depth--;
if(parser->depth == 1)
@@ -460,7 +458,7 @@ static void xmpp_postEndElement(xmlParserCtxt *ctxt)
**/
static void xmpp_xmlAbortDueToMemoryShortage(xmlParserCtxt *ctxt)
{
- XMPPParser *parser = (XMPPParser *)ctxt->_private;
+ XMPPParser *parser = (__bridge XMPPParser *)ctxt->_private;
xmlStopParser(ctxt);
@@ -686,7 +684,7 @@ static void xmpp_xmlCharacters(void *ctx, const xmlChar *ch, int len)
{
xmlParserCtxt *ctxt = (xmlParserCtxt *)ctx;
- if(ctxt->node != NULL)
+ if (ctxt->node != NULL)
{
xmlNodePtr textNode = xmlNewTextLen(ch, len);
@@ -710,7 +708,7 @@ static void xmpp_xmlEndElement(void *ctx, const xmlChar *localname,
xmlParserCtxt *ctxt = (xmlParserCtxt *)ctx;
// Update our parent node pointer
- if(ctxt->node != NULL)
+ if (ctxt->node != NULL)
ctxt->node = ctxt->node->parent;
// Invoke delegate methods if needed
@@ -719,7 +717,7 @@ static void xmpp_xmlEndElement(void *ctx, const xmlChar *localname,
- (id)initWithDelegate:(id)aDelegate
{
- if((self = [super init]))
+ if ((self = [super init]))
{
delegate = aDelegate;
@@ -744,7 +742,7 @@ - (id)initWithDelegate:(id)aDelegate
parserCtxt->myDoc = xmlNewDoc(parserCtxt->version);
// Store reference to ourself
- parserCtxt->_private = self;
+ parserCtxt->_private = (__bridge void *)(self);
// Note: The parserCtxt also has a userData variable, but it is used by the DOM building functions.
// If we put a value there, it actually causes a crash!
@@ -755,11 +753,11 @@ - (id)initWithDelegate:(id)aDelegate
- (void)dealloc
{
- if(parserCtxt)
+ if (parserCtxt)
{
// The xmlFreeParserCtxt method will not free the created document in parserCtxt->myDoc.
- if(parserCtxt->myDoc)
+ if (parserCtxt->myDoc)
{
// Free the created xmlDoc
xmlFreeDoc(parserCtxt->myDoc);
@@ -768,7 +766,6 @@ - (void)dealloc
xmlFreeParserCtxt(parserCtxt);
}
- [super dealloc];
}
- (id)delegate {
@@ -785,7 +782,7 @@ - (void)parseData:(NSData *)data
// gets invoked, then the parserCtxt will be freed in the middle of the xmlParseChunk method.
// This often has the effect of crashing the application.
// To get around this problem we simply retain/release within the method.
- [self retain];
+ XMPPParser *selfRetain = self;
int result = xmlParseChunk(parserCtxt, (const char *)[data bytes], (int)[data length], 0);
@@ -813,7 +810,7 @@ - (void)parseData:(NSData *)data
}
}
- [self release];
+ selfRetain = nil;
}
@end
View
11 Core/XMPPPresence.m
@@ -1,8 +1,13 @@
#import "XMPPPresence.h"
+#import "XMPPJID.h"
#import "NSXMLElement+XMPP.h"
#import <objc/runtime.h>
+#if ! __has_feature(objc_arc)
+#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
+#endif
+
@implementation XMPPPresence
@@ -37,17 +42,17 @@ + (XMPPPresence *)presenceFromElement:(NSXMLElement *)element
+ (XMPPPresence *)presence
{
- return [[[XMPPPresence alloc] init] autorelease];
+ return [[XMPPPresence alloc] init];
}
+ (XMPPPresence *)presenceWithType:(NSString *)type
{
- return [[[XMPPPresence alloc] initWithType:type to:nil] autorelease];
+ return [[XMPPPresence alloc] initWithType:type to:nil];
}
+ (XMPPPresence *)presenceWithType:(NSString *)type to:(XMPPJID *)to
{
- return [[[XMPPPresence alloc] initWithType:type to:to] autorelease];
+ return [[XMPPPresence alloc] initWithType:type to:to];
}
- (id)init
View
14 Core/XMPPStream.h
@@ -30,7 +30,7 @@ enum XMPPStreamErrorCode
{
XMPPStreamInvalidType, // Attempting to access P2P methods in a non-P2P stream, or vice-versa
XMPPStreamInvalidState, // Invalid state for requested action, such as connect when already connected
- XMPPStreamInvalidProperty, // Missing a required property, such as hostName or myJID
+ XMPPStreamInvalidProperty, // Missing a required property, such as myJID
XMPPStreamInvalidParameter, // Invalid parameter, such as a nil JID
XMPPStreamUnsupportedAction, // The server doesn't support the requested action
};
@@ -62,9 +62,9 @@ typedef enum XMPPStreamErrorCode XMPPStreamErrorCode;
UInt16 hostPort;
NSString *tempPassword;
- BOOL isAccessToken;
-
- NSString *appId;
+ BOOL isAccessToken;
+
+ NSString *appId;
XMPPJID *myJID;
XMPPJID *remoteJID;
@@ -202,7 +202,7 @@ typedef enum XMPPStreamErrorCode XMPPStreamErrorCode;
/**
* Only used in P2P streams.
**/
-@property (readonly) XMPPJID *remoteJID;
+@property (strong, readonly) XMPPJID *remoteJID;
/**
* Many routers will teardown a socket mapping if there is no activity on the socket.
@@ -229,7 +229,7 @@ typedef enum XMPPStreamErrorCode XMPPStreamErrorCode;
*
* This excludes presence elements sent concerning subscriptions, MUC rooms, etc.
**/
-@property (readonly) XMPPPresence *myPresence;
+@property (strong, readonly) XMPPPresence *myPresence;
/**
* Returns the total number of bytes bytes sent/received by the xmpp stream.
@@ -257,7 +257,7 @@ typedef enum XMPPStreamErrorCode XMPPStreamErrorCode;
* The tag property allows you to associate user defined information with the stream.
* Tag values are not used internally, and should not be used by xmpp modules.
**/
-@property (readwrite, retain) id tag;
+@property (readwrite, strong) id tag;
#if TARGET_OS_IPHONE
View
704 Core/XMPPStream.m
@@ -21,6 +21,10 @@
#import <CFNetwork/CFNetwork.h>
#endif
+#if ! __has_feature(objc_arc)
+#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
+#endif
+
#if TARGET_OS_IPHONE
#define SOCKET_BUFFER_SIZE 512 // bytes
#else
@@ -163,7 +167,7 @@ - (id)initP2PFrom:(XMPPJID *)jid
[self commonInit];
// Store JID
- myJID = [jid retain];
+ myJID = jid;
// We do not initialize the socket, since the connectP2PWithSocket: method might be used.
@@ -198,52 +202,34 @@ - (void)dealloc
dispatch_release(xmppQueue);
dispatch_release(parserQueue);
- [multicastDelegate release];
[asyncSocket setDelegate:nil delegateQueue:NULL];
[asyncSocket disconnect];
- [asyncSocket release];
- [socketBuffer release];
[parser setDelegate:nil];
- [parser release];
- [parserError release];
- [hostName release];
- [tempPassword release];
- [myJID release];
- [remoteJID release];
- [myPresence release];
- [rootElement release];
if (keepAliveTimer)
{
dispatch_source_cancel(keepAliveTimer);
}
- [registeredModules release];
- [autoDelegateDict release];
- [srvResolver release];
- [srvResults release];
for (XMPPElementReceipt *receipt in receipts)
{
[receipt signalFailure];
}
- [receipts release];
[[self class] performSelector:@selector(xmppThreadStop)
onThread:xmppUtilityThread
withObject:nil
waitUntilDone:NO];
- [userTag release];
- [super dealloc];
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -261,10 +247,10 @@ - (NSString *)appId
__block NSString *result;
dispatch_sync(xmppQueue, ^{
- result = [appId retain];
+ result = appId;
});
- return [result autorelease];
+ return result;
}
}
@@ -274,7 +260,6 @@ - (void)setAppId:(NSString *)newAppId
{
if (appId != newAppId)
{
- [appId release];
appId = [newAppId copy];
}
}
@@ -283,11 +268,9 @@ - (void)setAppId:(NSString *)newAppId
NSString *newAppIdCopy = [newAppId copy];
dispatch_async(xmppQueue, ^{
- [appId release];
- appId = [newAppIdCopy retain];
+ appId = newAppIdCopy;
});
- [newAppIdCopy release];
}
}
@@ -302,10 +285,10 @@ - (NSString *)hostName
__block NSString *result;
dispatch_sync(xmppQueue, ^{
- result = [hostName retain];
+ result = hostName;
});
- return [result autorelease];
+ return result;
}
}
@@ -315,7 +298,6 @@ - (void)setHostName:(NSString *)newHostName
{
if (hostName != newHostName)
{
- [hostName release];
hostName = [newHostName copy];
}
}
@@ -324,11 +306,9 @@ - (void)setHostName:(NSString *)newHostName
NSString *newHostNameCopy = [newHostName copy];
dispatch_async(xmppQueue, ^{
- [hostName release];
- hostName = [newHostNameCopy retain];
+ hostName = newHostNameCopy;
});
- [newHostNameCopy release];
}
}
@@ -373,10 +353,10 @@ - (XMPPJID *)myJID
__block XMPPJID *result;
dispatch_sync(xmppQueue, ^{
- result = [myJID retain];
+ result = myJID;
});
- return [result autorelease];
+ return result;
}
}
@@ -388,8 +368,7 @@ - (void)setMyJID:(XMPPJID *)newMyJID
if (myJID != newMyJID)
{
- [myJID release];
- myJID = [newMyJID retain];
+ myJID = newMyJID;
}
[[NSNotificationCenter defaultCenter] postNotificationName:XMPPStreamDidChangeMyJIDNotification object:self];
@@ -412,10 +391,10 @@ - (XMPPJID *)remoteJID
__block XMPPJID *result;
dispatch_sync(xmppQueue, ^{
- result = [remoteJID retain];
+ result = remoteJID;
});
- return [result autorelease];
+ return result;
}
}
@@ -430,10 +409,10 @@ - (XMPPPresence *)myPresence
__block XMPPPresence *result;
dispatch_sync(xmppQueue, ^{
- result = [myPresence retain];
+ result = myPresence;
});
- return [result autorelease];
+ return result;
}
}
@@ -771,8 +750,7 @@ - (BOOL)connect:(NSError **)errPtr
__block BOOL result = NO;
__block NSError *err = nil;
- dispatch_block_t block = ^{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ dispatch_block_t block = ^{ @autoreleasepool {
if (state != STATE_XMPP_DISCONNECTED)
{
@@ -781,9 +759,6 @@ - (BOOL)connect:(NSError **)errPtr
err = [NSError errorWithDomain:XMPPStreamErrorDomain code:XMPPStreamInvalidState userInfo:info];
- [err retain];
- [pool drain];
-
result = NO;
return_from_block;
}
@@ -795,9 +770,6 @@ - (BOOL)connect:(NSError **)errPtr
err = [NSError errorWithDomain:XMPPStreamErrorDomain code:XMPPStreamInvalidType userInfo:info];
- [err retain];
- [pool drain];
-
result = NO;
return_from_block;
}
@@ -823,9 +795,6 @@ - (BOOL)connect:(NSError **)errPtr
err = [NSError errorWithDomain:XMPPStreamErrorDomain code:XMPPStreamInvalidProperty userInfo:info];
- [err retain];
- [pool drain];
-
result = NO;
return_from_block;
}
@@ -847,10 +816,8 @@ - (BOOL)connect:(NSError **)errPtr
state = STATE_XMPP_RESOLVING_SRV;
- [srvResolver release];
srvResolver = [[XMPPSRVResolver alloc] initWithdDelegate:self delegateQueue:xmppQueue resolverQueue:NULL];
- [srvResults release];
srvResults = nil;
srvResultsIndex = 0;
@@ -866,27 +833,24 @@ - (BOOL)connect:(NSError **)errPtr
state = STATE_XMPP_CONNECTING;
- result = [self connectToHost:hostName onPort:hostPort error:&err];
+ NSError *connectErr = nil;
+ result = [self connectToHost:hostName onPort:hostPort error:&connectErr];
if (!result)
{
+ err = connectErr;
state = STATE_XMPP_DISCONNECTED;
}
}
-
- [err retain];
- [pool drain];
- };
+ }};
if (dispatch_get_current_queue() == xmppQueue)
block();
else
dispatch_sync(xmppQueue, block);
if (errPtr)
- *errPtr = [err autorelease];
- else
- [err release];
+ *errPtr = err;
return result;
}
@@ -898,11 +862,11 @@ - (BOOL)oldSchoolSecureConnect:(NSError **)errPtr
__block BOOL result = NO;
__block NSError *err = nil;
- dispatch_block_t block = ^{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ dispatch_block_t block = ^{ @autoreleasepool {
// Go through the regular connect routine
- result = [self connect:&err];
+ NSError *connectErr = nil;
+ result = [self connect:&connectErr];
if (result)
{
@@ -911,20 +875,19 @@ - (BOOL)oldSchoolSecureConnect:(NSError **)errPtr
[self setIsSecure:YES];
}
-
- [err retain];
- [pool drain];
- };
+ else
+ {
+ err = connectErr;
+ }
+ }};
if (dispatch_get_current_queue() == xmppQueue)
block();
else
dispatch_sync(xmppQueue, block);
if (errPtr)
- *errPtr = [err autorelease];
- else
- [err release];
+ *errPtr = err;
return result;
}
@@ -947,8 +910,7 @@ - (BOOL)connectTo:(XMPPJID *)jid withAddress:(NSData *)remoteAddr error:(NSError
__block BOOL result = YES;
__block NSError *err = nil;
- dispatch_block_t block = ^{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ dispatch_block_t block = ^{ @autoreleasepool {
if (state != STATE_XMPP_DISCONNECTED)
{
@@ -957,9 +919,6 @@ - (BOOL)connectTo:(XMPPJID *)jid withAddress:(NSData *)remoteAddr error:(NSError
err = [NSError errorWithDomain:XMPPStreamErrorDomain code:XMPPStreamInvalidState userInfo:info];
- [err retain];
- [pool drain];
-
result = NO;
return_from_block;
}
@@ -971,9 +930,6 @@ - (BOOL)connectTo:(XMPPJID *)jid withAddress:(NSData *)remoteAddr error:(NSError
err = [NSError errorWithDomain:XMPPStreamErrorDomain code:XMPPStreamInvalidType userInfo:info];
- [err retain];
- [pool drain];
-
result = NO;
return_from_block;
}