XMPPConnection: Verify origin of IQ responses
This commit is contained in:
parent
358334a778
commit
3e150f18d6
1 changed files with 43 additions and 16 deletions
|
@ -563,15 +563,25 @@
|
||||||
{
|
{
|
||||||
OFAutoreleasePool *pool;
|
OFAutoreleasePool *pool;
|
||||||
XMPPCallback *callback;
|
XMPPCallback *callback;
|
||||||
|
OFString *ID, *key;
|
||||||
if (![IQ ID])
|
|
||||||
[IQ setID: [self generateStanzaID]];
|
|
||||||
|
|
||||||
pool = [[OFAutoreleasePool alloc] init];
|
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
|
callback = [XMPPCallback callbackWithTarget: target
|
||||||
selector: selector];
|
selector: selector];
|
||||||
[_callbacks setObject: callback
|
[_callbacks setObject: callback
|
||||||
forKey: [IQ ID]];
|
forKey: key];
|
||||||
[pool release];
|
[pool release];
|
||||||
|
|
||||||
[self sendStanza: IQ];
|
[self sendStanza: IQ];
|
||||||
|
@ -583,14 +593,24 @@
|
||||||
{
|
{
|
||||||
OFAutoreleasePool *pool;
|
OFAutoreleasePool *pool;
|
||||||
XMPPCallback *callback;
|
XMPPCallback *callback;
|
||||||
|
OFString *ID, *key;
|
||||||
if (![IQ ID])
|
|
||||||
[IQ setID: [self generateStanzaID]];
|
|
||||||
|
|
||||||
pool = [[OFAutoreleasePool alloc] init];
|
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];
|
callback = [XMPPCallback callbackWithBlock: block];
|
||||||
[_callbacks setObject: callback
|
[_callbacks setObject: callback
|
||||||
forKey: [IQ ID]];
|
forKey: key];
|
||||||
[pool release];
|
[pool release];
|
||||||
|
|
||||||
[self sendStanza: IQ];
|
[self sendStanza: IQ];
|
||||||
|
@ -958,26 +978,33 @@
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)XMPP_handleIQ: (XMPPIQ*)iq
|
- (void)XMPP_handleIQ: (XMPPIQ*)IQ
|
||||||
{
|
{
|
||||||
bool handled = false;
|
bool handled = false;
|
||||||
XMPPCallback *callback;
|
XMPPCallback *callback;
|
||||||
|
OFString *key;
|
||||||
|
|
||||||
if ((callback = [_callbacks objectForKey: [iq ID]])) {
|
if ((key = [[IQ from] fullJID]) == nil)
|
||||||
[callback runWithIQ: iq
|
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];
|
connection: self];
|
||||||
[_callbacks removeObjectForKey: [iq ID]];
|
[_callbacks removeObjectForKey: key];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
handled = [_delegates broadcastSelector: @selector(
|
handled = [_delegates broadcastSelector: @selector(
|
||||||
connection:didReceiveIQ:)
|
connection:didReceiveIQ:)
|
||||||
withObject: self
|
withObject: self
|
||||||
withObject: iq];
|
withObject: IQ];
|
||||||
|
|
||||||
if (!handled && ![[iq type] isEqual: @"error"] &&
|
if (!handled && ![[IQ type] isEqual: @"error"] &&
|
||||||
![[iq type] isEqual: @"result"]) {
|
![[IQ type] isEqual: @"result"]) {
|
||||||
[self sendStanza: [iq errorIQWithType: @"cancel"
|
[self sendStanza: [IQ errorIQWithType: @"cancel"
|
||||||
condition: @"service-unavailable"]];
|
condition: @"service-unavailable"]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue