ObjXMPP  Diff

Differences From Artifact [e6d90230b9]:

To Artifact [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
{