Skip to content

Commit 7514ac9

Browse files
committed
Merge branch 'master' into xep-0136
2 parents 2b30e76 + b28b3b1 commit 7514ac9

File tree

117 files changed

+15643
-3450
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+15643
-3450
lines changed

Authentication/Anonymous/XMPPAnonymousAuthentication.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ - (BOOL)authenticateAnonymously:(NSError **)errPtr
117117
}
118118
}};
119119

120-
if (dispatch_get_current_queue() == xmppQueue)
120+
if (dispatch_get_current_queue() == self.xmppQueue)
121121
block();
122122
else
123-
dispatch_sync(xmppQueue, block);
123+
dispatch_sync(self.xmppQueue, block);
124124

125125
if (errPtr)
126126
*errPtr = err;

Authentication/Deprecated-Digest/XMPPDeprecatedDigestAuthentication.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,18 @@ - (BOOL)supportsDeprecatedDigestAuthentication
122122

123123
// The root element can be properly queried for authentication mechanisms anytime after the
124124
// stream:features are received, and TLS has been setup (if required)
125-
if (state >= STATE_XMPP_POST_NEGOTIATION)
125+
if (self.state >= STATE_XMPP_POST_NEGOTIATION)
126126
{
127127
// Search for an iq element within the rootElement.
128128
// Recall that some servers might stupidly add a "jabber:client" namespace which might cause problems
129129
// if we simply used the elementForName method.
130130

131131
NSXMLElement *iq = nil;
132132

133-
NSUInteger i, count = [rootElement childCount];
133+
NSUInteger i, count = [self.rootElement childCount];
134134
for (i = 0; i < count; i++)
135135
{
136-
NSXMLNode *childNode = [rootElement childAtIndex:i];
136+
NSXMLNode *childNode = [self.rootElement childAtIndex:i];
137137

138138
if ([childNode kind] == NSXMLElementKind)
139139
{
@@ -151,10 +151,10 @@ - (BOOL)supportsDeprecatedDigestAuthentication
151151
}
152152
}};
153153

154-
if (dispatch_get_current_queue() == xmppQueue)
154+
if (dispatch_get_current_queue() == self.xmppQueue)
155155
block();
156156
else
157-
dispatch_sync(xmppQueue, block);
157+
dispatch_sync(self.xmppQueue, block);
158158

159159
return result;
160160
}

Authentication/Deprecated-Plain/XMPPDeprecatedPlainAuthentication.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,18 @@ - (BOOL)supportsDeprecatedPlainAuthentication
116116

117117
// The root element can be properly queried for authentication mechanisms anytime after the
118118
// stream:features are received, and TLS has been setup (if required)
119-
if (state >= STATE_XMPP_POST_NEGOTIATION)
119+
if (self.state >= STATE_XMPP_POST_NEGOTIATION)
120120
{
121121
// Search for an iq element within the rootElement.
122122
// Recall that some servers might stupidly add a "jabber:client" namespace which might cause problems
123123
// if we simply used the elementForName method.
124124

125125
NSXMLElement *iq = nil;
126126

127-
NSUInteger i, count = [rootElement childCount];
127+
NSUInteger i, count = [self.rootElement childCount];
128128
for (i = 0; i < count; i++)
129129
{
130-
NSXMLNode *childNode = [rootElement childAtIndex:i];
130+
NSXMLNode *childNode = [self.rootElement childAtIndex:i];
131131

132132
if ([childNode kind] == NSXMLElementKind)
133133
{
@@ -145,10 +145,10 @@ - (BOOL)supportsDeprecatedPlainAuthentication
145145
}
146146
}};
147147

148-
if (dispatch_get_current_queue() == xmppQueue)
148+
if (dispatch_get_current_queue() == self.xmppQueue)
149149
block();
150150
else
151-
dispatch_sync(xmppQueue, block);
151+
dispatch_sync(self.xmppQueue, block);
152152

153153
return result;
154154
}

Authentication/Digest-MD5/XMPPDigestMD5Authentication.m

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ @interface XMPPDigestMD5Authentication ()
3535
NSString *password;
3636
}
3737

38+
// The properties are hooks (primarily for testing)
39+
40+
@property (nonatomic, strong) NSString *realm;
41+
@property (nonatomic, strong) NSString *nonce;
42+
@property (nonatomic, strong) NSString *qop;
43+
@property (nonatomic, strong) NSString *cnonce;
44+
@property (nonatomic, strong) NSString *digestURI;
45+
@property (nonatomic, strong) NSString *username;
46+
@property (nonatomic, strong) NSString *password;
47+
3848
- (NSDictionary *)dictionaryFromChallenge:(NSXMLElement *)challenge;
3949
- (NSString *)base64EncodedFullResponse;
4050

@@ -51,6 +61,14 @@ + (NSString *)mechanismName
5161
return @"DIGEST-MD5";
5262
}
5363

64+
@synthesize realm;
65+
@synthesize nonce;
66+
@synthesize qop;
67+
@synthesize cnonce;
68+
@synthesize digestURI;
69+
@synthesize username;
70+
@synthesize password;
71+
5472
- (id)initWithStream:(XMPPStream *)stream password:(NSString *)inPassword
5573
{
5674
if ((self = [super init]))
@@ -119,7 +137,9 @@ - (XMPPHandleAuthResponse)handleAuth1:(NSXMLElement *)authResponse
119137
else
120138
digestURI = [NSString stringWithFormat:@"xmpp/%@", serverHostName];
121139

122-
cnonce = [XMPPStream generateUUID];
140+
if (cnonce == nil)
141+
cnonce = [XMPPStream generateUUID];
142+
123143
username = [myJID user];
124144

125145
// Create and send challenge response element
@@ -234,22 +254,37 @@ - (NSString *)response
234254
NSString *HA1str = [NSString stringWithFormat:@"%@:%@:%@", username, realm, password];
235255
NSString *HA2str = [NSString stringWithFormat:@"AUTHENTICATE:%@", digestURI];
236256

257+
XMPPLogVerbose(@"HA1str: %@", HA1str);
258+
XMPPLogVerbose(@"HA2str: %@", HA2str);
259+
237260
NSData *HA1dataA = [[HA1str dataUsingEncoding:NSUTF8StringEncoding] md5Digest];
238261
NSData *HA1dataB = [[NSString stringWithFormat:@":%@:%@", nonce, cnonce] dataUsingEncoding:NSUTF8StringEncoding];
239262

263+
XMPPLogVerbose(@"HA1dataA: %@", HA1dataA);
264+
XMPPLogVerbose(@"HA1dataB: %@", HA1dataB);
265+
240266
NSMutableData *HA1data = [NSMutableData dataWithCapacity:([HA1dataA length] + [HA1dataB length])];
241267
[HA1data appendData:HA1dataA];
242268
[HA1data appendData:HA1dataB];
243269

270+
XMPPLogVerbose(@"HA1data: %@", HA1data);
271+
244272
NSString *HA1 = [[HA1data md5Digest] hexStringValue];
245273

246274
NSString *HA2 = [[[HA2str dataUsingEncoding:NSUTF8StringEncoding] md5Digest] hexStringValue];
247275

276+
XMPPLogVerbose(@"HA1: %@", HA1);
277+
XMPPLogVerbose(@"HA2: %@", HA2);
278+
248279
NSString *responseStr = [NSString stringWithFormat:@"%@:%@:00000001:%@:auth:%@",
249280
HA1, nonce, cnonce, HA2];
250281

282+
XMPPLogVerbose(@"responseStr: %@", responseStr);
283+
251284
NSString *response = [[[responseStr dataUsingEncoding:NSUTF8StringEncoding] md5Digest] hexStringValue];
252285

286+
XMPPLogVerbose(@"response: %@", response);
287+
253288
return response;
254289
}
255290

@@ -266,7 +301,7 @@ - (NSString *)base64EncodedFullResponse
266301
[buffer appendFormat:@"response=%@,", [self response]];
267302
[buffer appendFormat:@"charset=utf-8"];
268303

269-
XMPPLogSend(@"decoded response: %@", buffer);
304+
XMPPLogVerbose(@"%@: Decoded response: %@", THIS_FILE, buffer);
270305

271306
NSData *utf8data = [buffer dataUsingEncoding:NSUTF8StringEncoding];
272307

Authentication/Plain/XMPPPlainAuthentication.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919

2020
@implementation XMPPPlainAuthentication
2121
{
22-
#if __has_feature(objc_arc_weak)
22+
#if __has_feature(objc_arc_weak)
2323
__weak XMPPStream *xmppStream;
24-
#else
24+
#else
2525
__unsafe_unretained XMPPStream *xmppStream;
26-
#endif
26+
#endif
2727

2828
NSString *password;
2929
}
@@ -56,7 +56,7 @@ - (BOOL)start:(NSError **)errPtr
5656

5757
NSString *username = [xmppStream.myJID user];
5858

59-
NSString *payload = [NSString stringWithFormat:@"%C%@%C%@", 0, username, 0, password];
59+
NSString *payload = [NSString stringWithFormat:@"\0%@\0%@", username, password];
6060
NSString *base64 = [[payload dataUsingEncoding:NSUTF8StringEncoding] base64Encoded];
6161

6262
// <auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">Base-64-Info</auth>

Authentication/X-Facebook-Platform/XMPPXFacebookPlatformAuthentication.m

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@
2121

2222
static char facebookAppIdKey;
2323

24-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
25-
#pragma mark -
26-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27-
28-
@implementation XMPPXFacebookPlatformAuthentication
24+
@interface XMPPXFacebookPlatformAuthentication ()
2925
{
3026
#if __has_feature(objc_arc_weak)
3127
__weak XMPPStream *xmppStream;
@@ -41,6 +37,17 @@ @implementation XMPPXFacebookPlatformAuthentication
4137
NSString *method;
4238
}
4339

40+
- (NSDictionary *)dictionaryFromChallenge:(NSXMLElement *)challenge;
41+
- (NSString *)base64EncodedFullResponse;
42+
43+
@end
44+
45+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
46+
#pragma mark -
47+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
48+
49+
@implementation XMPPXFacebookPlatformAuthentication
50+
4451
+ (NSString *)mechanismName
4552
{
4653
return @"X-FACEBOOK-PLATFORM";
@@ -225,15 +232,15 @@ - (id)initWithFacebookAppId:(NSString *)fbAppId
225232
if ((self = [self init])) // Note: Using [self init], NOT [super init]
226233
{
227234
self.facebookAppId = fbAppId;
228-
myJID_setByClient = [XMPPJID jidWithString:XMPPFacebookChatHostName];
235+
self.myJID = [XMPPJID jidWithString:XMPPFacebookChatHostName];
229236

230237
// As of October 8, 2011, Facebook doesn't have their XMPP SRV records set.
231238
// And, as per the XMPP specification, we MUST check the XMPP SRV records for an IP address,
232239
// before falling back to a traditional A record lookup.
233240
//
234241
// So we're setting the hostname as a minor optimization to avoid the SRV timeout delay.
235242

236-
hostName = XMPPFacebookChatHostName;
243+
self.hostName = XMPPFacebookChatHostName;
237244
}
238245
return self;
239246
}
@@ -246,10 +253,10 @@ - (NSString *)facebookAppId
246253
result = objc_getAssociatedObject(self, &facebookAppIdKey);
247254
};
248255

249-
if (dispatch_get_current_queue() == xmppQueue)
256+
if (dispatch_get_current_queue() == self.xmppQueue)
250257
block();
251258
else
252-
dispatch_sync(xmppQueue, block);
259+
dispatch_sync(self.xmppQueue, block);
253260

254261
return result;
255262
}
@@ -262,10 +269,10 @@ - (void)setFacebookAppId:(NSString *)inFacebookAppId
262269
objc_setAssociatedObject(self, &facebookAppIdKey, newFacebookAppId, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
263270
};
264271

265-
if (dispatch_get_current_queue() == xmppQueue)
272+
if (dispatch_get_current_queue() == self.xmppQueue)
266273
block();
267274
else
268-
dispatch_async(xmppQueue, block);
275+
dispatch_async(self.xmppQueue, block);
269276
}
270277

271278
- (BOOL)supportsXFacebookPlatformAuthentication
@@ -307,10 +314,10 @@ - (BOOL)authenticateWithFacebookAccessToken:(NSString *)accessToken error:(NSErr
307314
}};
308315

309316

310-
if (dispatch_get_current_queue() == xmppQueue)
317+
if (dispatch_get_current_queue() == self.xmppQueue)
311318
block();
312319
else
313-
dispatch_sync(xmppQueue, block);
320+
dispatch_sync(self.xmppQueue, block);
314321

315322
if (errPtr)
316323
*errPtr = err;

Categories/NSData+XMPP.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ - (NSString *)hexStringValue
4040

4141
for (i = 0; i < [self length]; ++i)
4242
{
43-
[stringBuffer appendFormat:@"%02x", (unsigned long)dataBuffer[i]];
43+
[stringBuffer appendFormat:@"%02x", (unsigned int)dataBuffer[i]];
4444
}
4545

4646
return [stringBuffer copy];
@@ -106,11 +106,12 @@ - (NSData *)base64Decoded
106106
unsigned long ixtext = 0;
107107
unsigned long lentext = [self length];
108108
unsigned char ch = 0;
109-
unsigned char inbuf[4], outbuf[3];
109+
unsigned char inbuf[4] = {0, 0, 0, 0};
110+
unsigned char outbuf[3] = {0, 0, 0};
110111
short i = 0, ixinbuf = 0;
111112
BOOL flignore = NO;
112113
BOOL flendtext = NO;
113-
114+
114115
while( YES )
115116
{
116117
if( ixtext >= lentext ) break;

Core/XMPPIQ.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
+ (XMPPIQ *)iqWithType:(NSString *)type to:(XMPPJID *)jid;
2828
+ (XMPPIQ *)iqWithType:(NSString *)type to:(XMPPJID *)jid elementID:(NSString *)eid;
2929
+ (XMPPIQ *)iqWithType:(NSString *)type to:(XMPPJID *)jid elementID:(NSString *)eid child:(NSXMLElement *)childElement;
30+
+ (XMPPIQ *)iqWithType:(NSString *)type elementID:(NSString *)eid;
31+
+ (XMPPIQ *)iqWithType:(NSString *)type elementID:(NSString *)eid child:(NSXMLElement *)childElement;
32+
+ (XMPPIQ *)iqWithType:(NSString *)type child:(NSXMLElement *)childElement;
3033

3134
/**
3235
* Creates and returns a new XMPPIQ element.
@@ -37,6 +40,9 @@
3740
- (id)initWithType:(NSString *)type to:(XMPPJID *)jid;
3841
- (id)initWithType:(NSString *)type to:(XMPPJID *)jid elementID:(NSString *)eid;
3942
- (id)initWithType:(NSString *)type to:(XMPPJID *)jid elementID:(NSString *)eid child:(NSXMLElement *)childElement;
43+
- (id)initWithType:(NSString *)type elementID:(NSString *)eid;
44+
- (id)initWithType:(NSString *)type elementID:(NSString *)eid child:(NSXMLElement *)childElement;
45+
- (id)initWithType:(NSString *)type child:(NSXMLElement *)childElement;
4046

4147
/**
4248
* Returns the type attribute of the IQ.

Core/XMPPIQ.m

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ + (XMPPIQ *)iqWithType:(NSString *)type to:(XMPPJID *)jid elementID:(NSString *)
6565
return [[XMPPIQ alloc] initWithType:type to:jid elementID:eid child:childElement];
6666
}
6767

68+
+ (XMPPIQ *)iqWithType:(NSString *)type elementID:(NSString *)eid
69+
{
70+
return [[XMPPIQ alloc] initWithType:type to:nil elementID:eid child:nil];
71+
}
72+
73+
+ (XMPPIQ *)iqWithType:(NSString *)type elementID:(NSString *)eid child:(NSXMLElement *)childElement
74+
{
75+
return [[XMPPIQ alloc] initWithType:type to:nil elementID:eid child:childElement];
76+
}
77+
78+
+ (XMPPIQ *)iqWithType:(NSString *)type child:(NSXMLElement *)childElement
79+
{
80+
return [[XMPPIQ alloc] initWithType:type to:nil elementID:nil child:childElement];
81+
}
82+
6883
- (id)init
6984
{
7085
return [self initWithType:nil to:nil elementID:nil child:nil];
@@ -104,6 +119,21 @@ - (id)initWithType:(NSString *)type to:(XMPPJID *)jid elementID:(NSString *)eid
104119
return self;
105120
}
106121

122+
- (id)initWithType:(NSString *)type elementID:(NSString *)eid
123+
{
124+
return [self initWithType:type to:nil elementID:eid child:nil];
125+
}
126+
127+
- (id)initWithType:(NSString *)type elementID:(NSString *)eid child:(NSXMLElement *)childElement
128+
{
129+
return [self initWithType:type to:nil elementID:eid child:childElement];
130+
}
131+
132+
- (id)initWithType:(NSString *)type child:(NSXMLElement *)childElement
133+
{
134+
return [self initWithType:type to:nil elementID:nil child:childElement];
135+
}
136+
107137
- (NSString *)type
108138
{
109139
return [[self attributeStringValueForName:@"type"] lowercaseString];

0 commit comments

Comments
 (0)