ObjXMPP  Check-in [ba3acce2ec]

Overview
Comment:Split up XMPP_handleStanza.
Non-Stanzas are now handled in separate functions
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ba3acce2ecb6d8472d39bdbd82f388ce32f684b0047fe5868eae8cfd95649ea7
User & Date: florob@babelmonkeys.de on 2011-04-07 21:13:19
Other Links: manifest | tags
Context
2011-04-15
00:41
Handle stream errors check-in: ccfc230e32 user: florob@babelmonkeys.de tags: trunk
2011-04-07
21:13
Split up XMPP_handleStanza.
Non-Stanzas are now handled in separate functions
check-in: ba3acce2ec user: florob@babelmonkeys.de tags: trunk
2011-04-03
23:53
Clean up roster handling check-in: 3e837ad25f user: florob@babelmonkeys.de tags: trunk
Changes

Modified src/XMPPConnection.h from [ec242ca1b0] to [de4a3311e8].

159
160
161
162
163
164
165



166
167
168
169
170
171
172
- (void)setPort: (uint16_t)port;
- (uint16_t)port;
- (void)setDelegate: (id <XMPPConnectionDelegate>)delegate;
- (id <XMPPConnectionDelegate>)delegate;
- (XMPPRoster*)roster;

- (void)XMPP_startStream;



- (void)XMPP_handleStanza: (OFXMLElement*)elem;
- (void)XMPP_sendAuth: (OFString*)name;
- (void)XMPP_handleIQ: (XMPPIQ*)iq;
- (void)XMPP_handleMessage: (XMPPMessage*)msg;
- (void)XMPP_handlePresence: (XMPPPresence*)pres;
- (void)XMPP_handleFeatures: (OFXMLElement*)elem;
- (void)XMPP_sendResourceBind;







>
>
>







159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
- (void)setPort: (uint16_t)port;
- (uint16_t)port;
- (void)setDelegate: (id <XMPPConnectionDelegate>)delegate;
- (id <XMPPConnectionDelegate>)delegate;
- (XMPPRoster*)roster;

- (void)XMPP_startStream;
- (void)XMPP_handleStream: (OFXMLElement*)elem;
- (void)XMPP_handleTLS: (OFXMLElement*)elem;
- (void)XMPP_handleSASL: (OFXMLElement*)elem;
- (void)XMPP_handleStanza: (OFXMLElement*)elem;
- (void)XMPP_sendAuth: (OFString*)name;
- (void)XMPP_handleIQ: (XMPPIQ*)iq;
- (void)XMPP_handleMessage: (XMPPMessage*)msg;
- (void)XMPP_handlePresence: (XMPPPresence*)pres;
- (void)XMPP_handleFeatures: (OFXMLElement*)elem;
- (void)XMPP_sendResourceBind;

Modified src/XMPPConnection.m from [e6d90230b9] to [330b6dadbb].

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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337


338
339
340
341
342
343
344
345
346

347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427

	[elem setDefaultNamespace: XMPP_NS_CLIENT];
	[elem setPrefix: @"stream"
	   forNamespace: XMPP_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='" XMPP_NS_CLIENT @"' "
			   @"xmlns:stream='" XMPP_NS_STREAM @"' "
			   @"version='1.0'>", server];
}

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

		if ([[elem name] isEqual: @"message"]) {
			[self XMPP_handleMessage:
			    [XMPPMessage stanzaWithElement: elem]];
			return;
		}

		if ([[elem name] isEqual: @"presence"]) {
			[self XMPP_handlePresence:
			    [XMPPPresence stanzaWithElement: elem]];
			return;
		}

		assert(0);
	}

	if ([[elem namespace] isEqual: XMPP_NS_STREAM]) {


		if ([[elem name] isEqual: @"features"]) {
			[self XMPP_handleFeatures: elem];
			return;
		}

		assert(0);
	}

	if ([[elem namespace] isEqual: XMPP_NS_STARTTLS]) {

		if ([[elem name] isEqual: @"proceed"]) {
			/* FIXME: Catch errors here */
			SSLSocket *newSock;

			if ([delegate respondsToSelector:
			    @selector(connectionWillUpgradeToTLS:)])
				[delegate connectionWillUpgradeToTLS: self];

			newSock = [[SSLSocket alloc] initWithSocket: sock];
			[sock release];
			sock = newSock;

			if ([delegate respondsToSelector:
			    @selector(connectionDidUpgradeToTLS:)])
				[delegate connectionDidUpgradeToTLS: self];

			/* Stream restart */
			[parser setDelegate: self];
			[self XMPP_startStream];
			return;
		}

		if ([[elem name] isEqual: @"failure"])
			/* TODO: Find/create an exception to throw here */
			@throw [OFException newWithClass: isa];

		assert(0);
	}

	if ([[elem namespace] isEqual: XMPP_NS_SASL]) {

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

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

			[self sendStanza: responseTag];
			return;
		}

		if ([[elem name] isEqual: @"success"]) {
			[authModule parseServerFinalMessage:
			    [OFDataArray dataArrayWithBase64EncodedString:
				[elem stringValue]]];

			if ([delegate respondsToSelector:
			    @selector(connectionWasAuthenticated:)])
				[delegate connectionWasAuthenticated: self];

			/* Stream restart */
			[parser setDelegate: self];
			[self XMPP_startStream];
			return;
		}

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

		assert(0);
	}

	assert(0);
}

- (void)XMPP_handleIQ: (XMPPIQ*)iq
{







>
|
>
>
>
>
>
>
>
>
>















<
|
|
|
|

|
|
|
|
|

|
|
|
|
|

|
|

|
>
>
|
|
|
|

|
|

|
>
|
|
|

|
|
|

|
|
|

|
|
|

|
|
|
|
|

|
|
|

|
|

|
>
|
|
|
|
|
|
|

|
|
|
|
|
|

|
|
|

|
|
|
|

|
|
|

|
|
|
|
|

|
|
|
|
|
|
|
<
<
<







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
322
323
324
325

326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430



431
432
433
434
435
436
437

	[elem setDefaultNamespace: XMPP_NS_CLIENT];
	[elem setPrefix: @"stream"
	   forNamespace: XMPP_NS_STREAM];

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

	if ([[elem namespace] isEqual: XMPP_NS_CLIENT])
		[self XMPP_handleStanza: elem];

	if ([[elem namespace] isEqual: XMPP_NS_STREAM])
		[self XMPP_handleStream: elem];

	if ([[elem namespace] isEqual: XMPP_NS_STARTTLS])
		[self XMPP_handleTLS: elem];

	if ([[elem namespace] isEqual: XMPP_NS_SASL])
		[self XMPP_handleSASL: elem];

	[pool release];
}

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

- (void)XMPP_handleStanza: (OFXMLElement*)elem
{

	if ([[elem name] isEqual: @"iq"]) {
		[self XMPP_handleIQ: [XMPPIQ stanzaWithElement: elem]];
		return;
	}

	if ([[elem name] isEqual: @"message"]) {
		[self XMPP_handleMessage:
		    [XMPPMessage stanzaWithElement: elem]];
		return;
	}

	if ([[elem name] isEqual: @"presence"]) {
		[self XMPP_handlePresence:
		    [XMPPPresence stanzaWithElement: elem]];
		return;
	}

	assert(0);
}


- (void)XMPP_handleStream: (OFXMLElement*)elem
{
	if ([[elem name] isEqual: @"features"]) {
		[self XMPP_handleFeatures: elem];
		return;
	}

	assert(0);
}

- (void)XMPP_handleTLS: (OFXMLElement*)elem
{
	if ([[elem name] isEqual: @"proceed"]) {
		/* FIXME: Catch errors here */
		SSLSocket *newSock;

		if ([delegate respondsToSelector:
		    @selector(connectionWillUpgradeToTLS:)])
			[delegate connectionWillUpgradeToTLS: self];

		newSock = [[SSLSocket alloc] initWithSocket: sock];
		[sock release];
		sock = newSock;

		if ([delegate respondsToSelector:
		    @selector(connectionDidUpgradeToTLS:)])
			[delegate connectionDidUpgradeToTLS: self];

		/* Stream restart */
		[parser setDelegate: self];
		[self XMPP_startStream];
		return;
	}

	if ([[elem name] isEqual: @"failure"])
		/* TODO: Find/create an exception to throw here */
		@throw [OFException newWithClass: isa];

	assert(0);
}

- (void)XMPP_handleSASL: (OFXMLElement*)elem
{
	if ([[elem name] isEqual: @"challenge"]) {
		OFXMLElement *responseTag;
		OFDataArray *challenge =
		    [OFDataArray dataArrayWithBase64EncodedString:
		    [elem stringValue]];
		OFDataArray *response = [authModule
		    calculateResponseWithChallenge: challenge];

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

		[self sendStanza: responseTag];
		return;
	}

	if ([[elem name] isEqual: @"success"]) {
		[authModule parseServerFinalMessage:
		    [OFDataArray dataArrayWithBase64EncodedString:
			[elem stringValue]]];

		if ([delegate respondsToSelector:
		    @selector(connectionWasAuthenticated:)])
			[delegate connectionWasAuthenticated: self];

		/* Stream restart */
		[parser setDelegate: self];
		[self XMPP_startStream];
		return;
	}

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



	}

	assert(0);
}

- (void)XMPP_handleIQ: (XMPPIQ*)iq
{