ObjXMPP  Check-in [69621da29a]

Overview
Comment:Add autorelease pools.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 69621da29a13611205df7c0951a9a55f8c064051f180607a1f15473f2f5cc578
User & Date: js on 2011-03-27 23:55:02
Other Links: manifest | tags
Context
2011-03-28
13:14
Add XMPPRoster class. check-in: 010bd227d2 user: js tags: trunk
2011-03-27
23:55
Add autorelease pools. check-in: 69621da29a user: js tags: trunk
23:47
Add XMPPRosterItem class. check-in: c9c5afc2e7 user: js tags: trunk
Changes

Modified src/XMPPConnection.m from [3fbb4082fa] to [c3167bab5a].

46
47
48
49
50
51
52

53
54
55
56
57

58
59
60
61
62
63
64
46
47
48
49
50
51
52
53
54

55
56
57
58
59
60
61
62
63
64
65







+

-



+







#define NS_STARTTLS @"urn:ietf:params:xml:ns:xmpp-tls"
#define NS_STANZAS @"urn:ietf:params:xml:ns:xmpp-stanzas"
#define NS_SESSION @"urn:ietf:params:xml:ns:xmpp-session"
#define NS_STREAM @"http://etherx.jabber.org/streams"

@interface XMPPConnection ()
- (void)XMPP_startStream;
- (void)XMPP_handleStanza: (OFXMLElement*)elem;
- (void)XMPP_sendAuth: (OFString*)name;
- (void)XMPP_handleFeatures: (OFXMLElement*)elem;
- (void)XMPP_handleIQ: (XMPPIQ*)iq;
- (void)XMPP_handleMessage: (XMPPMessage*)msg;
- (void)XMPP_handlePresence: (XMPPPresence*)pres;
- (void)XMPP_handleFeatures: (OFXMLElement*)elem;
- (void)XMPP_sendResourceBind;
- (void)XMPP_handleResourceBind: (XMPPIQ*)iq;
- (void)XMPP_sendSession;
- (void)XMPP_handleSession: (XMPPIQ*)iq;
- (void)XMPP_handleRoster: (XMPPIQ*)iq;
@end

260
261
262
263
264
265
266


267
268
269
270
271
272
273
274
275
276
277
278
279
280
281


282
283
284
285
286


287
288
289
290
291
292















293
294
295
296
297
298
299
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321







+
+















+
+





+
+






+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








-    (void)parser: (OFXMLParser*)p
  didStartElement: (OFString*)name
       withPrefix: (OFString*)prefix
	namespace: (OFString*)ns
       attributes: (OFArray*)attrs
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

	if (![name isEqual: @"stream"] || ![prefix isEqual: @"stream"] ||
	    ![ns isEqual: NS_STREAM]) {
		of_log(@"Did not get expected stream start!");
		assert(0);
	}

	for (OFXMLAttribute *attr in attrs) {
		if ([attr.name isEqual: @"from"] &&
		    ![attr.stringValue isEqual: server]) {
			of_log(@"Got invalid from in stream start!");
			assert(0);
		}
	}

	parser.delegate = elementBuilder;

	[pool release];
}

- (void)elementBuilder: (OFXMLElementBuilder*)b
       didBuildElement: (OFXMLElement*)elem
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

	elem.defaultNamespace = NS_CLIENT;
	[elem setPrefix: @"stream"
	   forNamespace: NS_STREAM];

	of_log(@"In:  %@", elem);

	[self XMPP_handleStanza: elem];

	[pool release];
}

- (void)XMPP_startStream
{
	[sock writeFormat: @"<?xml version='1.0'?>\n"
			   @"<stream:stream to='%@' xmlns='" NS_CLIENT @"' "
			   @"xmlns:stream='" NS_STREAM @"' "
			   @"version='1.0'>", server];
}

- (void)XMPP_handleStanza: (OFXMLElement*)elem
{
	if ([elem.namespace isEqual: NS_CLIENT]) {
		if ([elem.name isEqual: @"iq"]) {
			[self XMPP_handleIQ: [XMPPIQ stanzaWithElement: elem]];
			return;
		}

		if ([elem.name isEqual: @"message"]) {
339
340
341
342
343
344
345
346
347


348
349

350
351
352
353
354
355



356
357
358
359
360
361
362
361
362
363
364
365
366
367


368
369


370
371
372
373



374
375
376
377
378
379
380
381
382
383







-
-
+
+
-
-
+



-
-
-
+
+
+







	}

	if ([elem.namespace isEqual: NS_SASL]) {
		if ([elem.name isEqual: @"challenge"]) {
			OFXMLElement *responseTag;
			OFDataArray *challenge =
			    [OFDataArray dataArrayWithBase64EncodedString:
				[elem.children.firstObject stringValue]];
			OFDataArray *response =
			    [elem.children.firstObject stringValue]];
			OFDataArray *response = [authModule
			    [authModule
			        calculateResponseWithChallenge: challenge];
			    calculateResponseWithChallenge: challenge];

			responseTag = [OFXMLElement elementWithName: @"response"
							  namespace: NS_SASL];
			[responseTag
			    addChild: [OFXMLElement elementWithCharacters:
				[response stringByBase64Encoding]]];
			[responseTag addChild:
			    [OFXMLElement elementWithCharacters:
			    [response stringByBase64Encoding]]];

			[self sendStanza: responseTag];
			return;
		}

		if ([elem.name isEqual: @"success"]) {
			[authModule parseServerFinalMessage:
375
376
377
378
379
380
381
382

383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
396
397
398
399
400
401
402

403
404
405
406
407
408
409
410
411








412
413
414
415
416
417
418







-
+








-
-
-
-
-
-
-
-








		if ([elem.name isEqual: @"failure"]) {
			of_log(@"Auth failed!");
			// FIXME: Do more parsing/handling
			@throw [XMPPAuthFailedException
			    newWithClass: isa
			      connection: self
				  reason: [elem stringValue]];
				  reason: elem.stringValue];
		}

		assert(0);
	}

	assert(0);
}

- (void)XMPP_startStream
{
	[sock writeFormat: @"<?xml version='1.0'?>\n"
			   @"<stream:stream to='%@' xmlns='" NS_CLIENT @"' "
			   @"xmlns:stream='" NS_STREAM @"' "
			   @"version='1.0'>", server];
}

- (void)XMPP_handleIQ: (XMPPIQ*)iq
{
	BOOL handled = NO;

	if ([iq.ID isEqual: bindID]) {
		[self XMPP_handleResourceBind: iq];
		return;