Move auth and bound handling to delegate.
This commit is contained in:
parent
b6314ccbc9
commit
4eb4d6bc9c
3 changed files with 40 additions and 13 deletions
|
@ -32,13 +32,16 @@
|
||||||
|
|
||||||
@protocol XMPPConnectionDelegate
|
@protocol XMPPConnectionDelegate
|
||||||
@optional
|
@optional
|
||||||
- (void)connectionWasClosed: (XMPPConnection*)conn;
|
- (void)connectionWasAuthenticated: (XMPPConnection*)conn;
|
||||||
|
- (void)connection: (XMPPConnection*)conn
|
||||||
|
wasBoundToJID: (XMPPJID*)jid;
|
||||||
- (void)connection: (XMPPConnection*)conn
|
- (void)connection: (XMPPConnection*)conn
|
||||||
didReceiveIQ: (XMPPIQ*)iq;
|
didReceiveIQ: (XMPPIQ*)iq;
|
||||||
- (void)connection: (XMPPConnection*)conn
|
- (void)connection: (XMPPConnection*)conn
|
||||||
didReceivePresence: (XMPPPresence*)pres;
|
didReceivePresence: (XMPPPresence*)pres;
|
||||||
- (void)connection: (XMPPConnection*)conn
|
- (void)connection: (XMPPConnection*)conn
|
||||||
didReceiveMessage: (XMPPMessage*)msg;
|
didReceiveMessage: (XMPPMessage*)msg;
|
||||||
|
- (void)connectionWasClosed: (XMPPConnection*)conn;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,7 +67,7 @@
|
||||||
short port;
|
short port;
|
||||||
/// Whether to use TLS
|
/// Whether to use TLS
|
||||||
BOOL useTLS;
|
BOOL useTLS;
|
||||||
id <XMPPConnectionDelegate> delegate;
|
id <XMPPConnectionDelegate, OFObject> delegate;
|
||||||
XMPPAuthenticator *authModule;
|
XMPPAuthenticator *authModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -191,7 +191,8 @@
|
||||||
size_t len = [sock readNBytes: 512
|
size_t len = [sock readNBytes: 512
|
||||||
intoBuffer: buf];
|
intoBuffer: buf];
|
||||||
|
|
||||||
if (len < 1)
|
if (len < 1 && [delegate respondsToSelector:
|
||||||
|
@selector(connectionWasClosed:)])
|
||||||
[delegate connectionWasClosed: self];
|
[delegate connectionWasClosed: self];
|
||||||
|
|
||||||
[of_stdout writeNBytes: len
|
[of_stdout writeNBytes: len
|
||||||
|
@ -266,7 +267,11 @@
|
||||||
OFXMLElement *jidElem = bindElem.children.firstObject;
|
OFXMLElement *jidElem = bindElem.children.firstObject;
|
||||||
JID = [[XMPPJID alloc] initWithString:
|
JID = [[XMPPJID alloc] initWithString:
|
||||||
[jidElem.children.firstObject stringValue]];
|
[jidElem.children.firstObject stringValue]];
|
||||||
of_log(@"Bound to JID: %@", [JID fullJID]);
|
|
||||||
|
if ([delegate respondsToSelector:
|
||||||
|
@selector(connection:wasBoundToJID:)])
|
||||||
|
[delegate connection: self
|
||||||
|
wasBoundToJID: JID];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,20 +318,25 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
[delegate connection: self
|
if ([delegate respondsToSelector: @selector(connection:didReceiveIQ:)])
|
||||||
didReceiveIQ: iq];
|
[delegate connection: self
|
||||||
|
didReceiveIQ: iq];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_handleMessage: (XMPPMessage*)msg
|
- (void)_handleMessage: (XMPPMessage*)msg
|
||||||
{
|
{
|
||||||
[delegate connection: self
|
if ([delegate respondsToSelector:
|
||||||
didReceiveMessage: msg];
|
@selector(connection:didReceiveMessage:)])
|
||||||
|
[delegate connection: self
|
||||||
|
didReceiveMessage: msg];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_handlePresence: (XMPPPresence*)pres
|
- (void)_handlePresence: (XMPPPresence*)pres
|
||||||
{
|
{
|
||||||
[delegate connection: self
|
if ([delegate respondsToSelector:
|
||||||
didReceivePresence: pres];
|
@selector(connection:didReceivePresence:)])
|
||||||
|
[delegate connection: self
|
||||||
|
didReceivePresence: pres];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)elementBuilder: (OFXMLElementBuilder*)b
|
- (void)elementBuilder: (OFXMLElementBuilder*)b
|
||||||
|
@ -408,7 +418,10 @@
|
||||||
[authModule parseServerFinalMessage:
|
[authModule parseServerFinalMessage:
|
||||||
[OFDataArray dataArrayWithBase64EncodedString:
|
[OFDataArray dataArrayWithBase64EncodedString:
|
||||||
[elem.children.firstObject stringValue]]];
|
[elem.children.firstObject stringValue]]];
|
||||||
of_log(@"Auth successful");
|
|
||||||
|
if ([delegate respondsToSelector:
|
||||||
|
@selector(connectionWasAuthenticated:)])
|
||||||
|
[delegate connectionWasAuthenticated: self];
|
||||||
|
|
||||||
/* Stream restart */
|
/* Stream restart */
|
||||||
parser.delegate = self;
|
parser.delegate = self;
|
||||||
|
|
15
tests/test.m
15
tests/test.m
|
@ -105,9 +105,15 @@ OF_APPLICATION_DELEGATE(AppDelegate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)connectionWasClosed: (XMPPConnection*)conn
|
- (void)connectionWasAuthenticated: (XMPPConnection*)conn
|
||||||
{
|
{
|
||||||
of_log(@"Connection was closed!");
|
of_log(@"Auth successful");
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)connection: (XMPPConnection*)conn
|
||||||
|
wasBoundToJID: (XMPPJID*)jid
|
||||||
|
{
|
||||||
|
of_log(@"Bound to JID: %@", [jid fullJID]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)connection: (XMPPConnection*)conn
|
- (void)connection: (XMPPConnection*)conn
|
||||||
|
@ -127,4 +133,9 @@ OF_APPLICATION_DELEGATE(AppDelegate)
|
||||||
{
|
{
|
||||||
of_log(@"Presence: %@", pres);
|
of_log(@"Presence: %@", pres);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)connectionWasClosed: (XMPPConnection*)conn
|
||||||
|
{
|
||||||
|
of_log(@"Connection was closed!");
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue