ObjXMPP  Check-in [4aae7b6dd1]

Overview
Comment:XMPPConnection: Verify origin of IQ responses
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4aae7b6dd1d5f1b84daa88af850b6bf192b3dd97d4baf591443cae6db470b818
User & Date: florob@babelmonkeys.de on 2014-02-03 22:36:13
Other Links: manifest | tags
Context
2014-02-03
22:50
XMPPRoster: Ensure roster pushes were sent by the server check-in: 6f1b17c116 user: florob@babelmonkeys.de tags: trunk
22:36
XMPPConnection: Verify origin of IQ responses check-in: 4aae7b6dd1 user: florob@babelmonkeys.de tags: trunk
22:34
Adapt to ObjFW changes check-in: 0668df366c user: florob@babelmonkeys.de tags: trunk
Changes

Modified src/XMPPConnection.m from [150ec0f157] to [15582e8207].

559
560
561
562
563
564
565

566


567
568

569
570






571
572
573
574
575
576
577
578
579
580
581
582
583
584
585

586


587
588

589
590






591
592
593
594
595
596
597
598
599
600

-   (void)sendIQ: (XMPPIQ*)IQ
  callbackTarget: (id)target
	selector: (SEL)selector
{
	OFAutoreleasePool *pool;
	XMPPCallback *callback;




	if (![IQ ID])
		[IQ setID: [self generateStanzaID]];


	pool = [[OFAutoreleasePool alloc] init];






	callback = [XMPPCallback callbackWithTarget: target
					   selector: selector];
	[_callbacks setObject: callback
		       forKey: [IQ ID]];
	[pool release];

	[self sendStanza: IQ];
}

#ifdef OF_HAVE_BLOCKS
-  (void)sendIQ: (XMPPIQ*)IQ
  callbackBlock: (xmpp_callback_block_t)block
{
	OFAutoreleasePool *pool;
	XMPPCallback *callback;




	if (![IQ ID])
		[IQ setID: [self generateStanzaID]];


	pool = [[OFAutoreleasePool alloc] init];






	callback = [XMPPCallback callbackWithBlock: block];
	[_callbacks setObject: callback
		       forKey: [IQ ID]];
	[pool release];

	[self sendStanza: IQ];
}
#endif

- (OFString*)generateStanzaID







>

>
>
|
|
>
|
|
>
>
>
>
>
>



|











>

>
>
|
|
>
|
|
>
>
>
>
>
>


|







559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620

-   (void)sendIQ: (XMPPIQ*)IQ
  callbackTarget: (id)target
	selector: (SEL)selector
{
	OFAutoreleasePool *pool;
	XMPPCallback *callback;
	OFString *ID, *key;

	pool = [[OFAutoreleasePool alloc] init];

	if ((ID = [IQ ID]) == nil) {
		ID = [self generateStanzaID];
		[IQ setID: ID];
	}

	if ((key = [[IQ to] fullJID]) == nil)
		key = [_JID bareJID];
	if (key == nil) // Only happens for resource bind
		key = @"bind";
	key = [key stringByAppendingString: ID];

	callback = [XMPPCallback callbackWithTarget: target
					   selector: selector];
	[_callbacks setObject: callback
		       forKey: key];
	[pool release];

	[self sendStanza: IQ];
}

#ifdef OF_HAVE_BLOCKS
-  (void)sendIQ: (XMPPIQ*)IQ
  callbackBlock: (xmpp_callback_block_t)block
{
	OFAutoreleasePool *pool;
	XMPPCallback *callback;
	OFString *ID, *key;

	pool = [[OFAutoreleasePool alloc] init];

	if ((ID = [IQ ID]) == nil) {
		ID = [self generateStanzaID];
		[IQ setID: ID];
	}

	if ((key = [[IQ to] fullJID]) == nil)
		key = [_JID bareJID];
	if (key == nil) // Connection not yet bound, can't send stanzas
		@throw [OFInvalidArgumentException exception];
	key = [key stringByAppendingString: ID];

	callback = [XMPPCallback callbackWithBlock: block];
	[_callbacks setObject: callback
		       forKey: key];
	[pool release];

	[self sendStanza: IQ];
}
#endif

- (OFString*)generateStanzaID
954
955
956
957
958
959
960
961
962
963
964

965






966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
		    exceptionWithConnection: self
				     reason: [element XMLString]];
	}

	assert(0);
}

- (void)XMPP_handleIQ: (XMPPIQ*)iq
{
	bool handled = false;
	XMPPCallback *callback;








	if ((callback = [_callbacks objectForKey: [iq ID]])) {
		[callback runWithIQ: iq
			 connection: self];
		[_callbacks removeObjectForKey: [iq ID]];
		return;
	}

	handled = [_delegates broadcastSelector: @selector(
						     connection:didReceiveIQ:)
				     withObject: self
				     withObject: iq];

	if (!handled && ![[iq type] isEqual: @"error"] &&
	    ![[iq type] isEqual: @"result"]) {
		[self sendStanza: [iq errorIQWithType: @"cancel"
					    condition: @"service-unavailable"]];
	}
}

- (void)XMPP_handleMessage: (XMPPMessage*)message
{
	[_delegates broadcastSelector: @selector(connection:didReceiveMessage:)







|



>

>
>
>
>
>
>
|
|

|






|

|
|
|







974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
		    exceptionWithConnection: self
				     reason: [element XMLString]];
	}

	assert(0);
}

- (void)XMPP_handleIQ: (XMPPIQ*)IQ
{
	bool handled = false;
	XMPPCallback *callback;
	OFString *key;

	if ((key = [[IQ from] fullJID]) == nil)
		key = [_JID bareJID];
	if (key == nil) // Only happens for resource bind
		key = @"bind";
	key = [key stringByAppendingString: [IQ ID]];

	if ((callback = [_callbacks objectForKey: key])) {
		[callback runWithIQ: IQ
			 connection: self];
		[_callbacks removeObjectForKey: key];
		return;
	}

	handled = [_delegates broadcastSelector: @selector(
						     connection:didReceiveIQ:)
				     withObject: self
				     withObject: IQ];

	if (!handled && ![[IQ type] isEqual: @"error"] &&
	    ![[IQ type] isEqual: @"result"]) {
		[self sendStanza: [IQ errorIQWithType: @"cancel"
					    condition: @"service-unavailable"]];
	}
}

- (void)XMPP_handleMessage: (XMPPMessage*)message
{
	[_delegates broadcastSelector: @selector(connection:didReceiveMessage:)