Move auth and bound handling to delegate.

This commit is contained in:
Jonathan Schleifer 2011-03-21 15:44:42 +01:00
parent b6314ccbc9
commit 4eb4d6bc9c
3 changed files with 40 additions and 13 deletions

View file

@ -32,13 +32,16 @@
@protocol XMPPConnectionDelegate
@optional
- (void)connectionWasClosed: (XMPPConnection*)conn;
- (void)connectionWasAuthenticated: (XMPPConnection*)conn;
- (void)connection: (XMPPConnection*)conn
wasBoundToJID: (XMPPJID*)jid;
- (void)connection: (XMPPConnection*)conn
didReceiveIQ: (XMPPIQ*)iq;
- (void)connection: (XMPPConnection*)conn
didReceivePresence: (XMPPPresence*)pres;
- (void)connection: (XMPPConnection*)conn
didReceiveMessage: (XMPPMessage*)msg;
- (void)connectionWasClosed: (XMPPConnection*)conn;
@end
/**
@ -64,7 +67,7 @@
short port;
/// Whether to use TLS
BOOL useTLS;
id <XMPPConnectionDelegate> delegate;
id <XMPPConnectionDelegate, OFObject> delegate;
XMPPAuthenticator *authModule;
}

View file

@ -191,7 +191,8 @@
size_t len = [sock readNBytes: 512
intoBuffer: buf];
if (len < 1)
if (len < 1 && [delegate respondsToSelector:
@selector(connectionWasClosed:)])
[delegate connectionWasClosed: self];
[of_stdout writeNBytes: len
@ -266,7 +267,11 @@
OFXMLElement *jidElem = bindElem.children.firstObject;
JID = [[XMPPJID alloc] initWithString:
[jidElem.children.firstObject stringValue]];
of_log(@"Bound to JID: %@", [JID fullJID]);
if ([delegate respondsToSelector:
@selector(connection:wasBoundToJID:)])
[delegate connection: self
wasBoundToJID: JID];
}
}
@ -313,18 +318,23 @@
return;
}
if ([delegate respondsToSelector: @selector(connection:didReceiveIQ:)])
[delegate connection: self
didReceiveIQ: iq];
}
- (void)_handleMessage: (XMPPMessage*)msg
{
if ([delegate respondsToSelector:
@selector(connection:didReceiveMessage:)])
[delegate connection: self
didReceiveMessage: msg];
}
- (void)_handlePresence: (XMPPPresence*)pres
{
if ([delegate respondsToSelector:
@selector(connection:didReceivePresence:)])
[delegate connection: self
didReceivePresence: pres];
}
@ -408,7 +418,10 @@
[authModule parseServerFinalMessage:
[OFDataArray dataArrayWithBase64EncodedString:
[elem.children.firstObject stringValue]]];
of_log(@"Auth successful");
if ([delegate respondsToSelector:
@selector(connectionWasAuthenticated:)])
[delegate connectionWasAuthenticated: self];
/* Stream restart */
parser.delegate = self;

View file

@ -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
@ -127,4 +133,9 @@ OF_APPLICATION_DELEGATE(AppDelegate)
{
of_log(@"Presence: %@", pres);
}
- (void)connectionWasClosed: (XMPPConnection*)conn
{
of_log(@"Connection was closed!");
}
@end