Generate unique IDs and free all instance variables on dealloc.
This commit is contained in:
parent
34966a35b5
commit
456cc295bc
2 changed files with 60 additions and 40 deletions
|
@ -53,31 +53,21 @@
|
||||||
OFTCPSocket *sock;
|
OFTCPSocket *sock;
|
||||||
OFXMLParser *parser;
|
OFXMLParser *parser;
|
||||||
OFXMLElementBuilder *elementBuilder;
|
OFXMLElementBuilder *elementBuilder;
|
||||||
/// The username to connect with
|
OFString *username, *password, *server, *resource;
|
||||||
OFString *username;
|
|
||||||
/// The password to connect with
|
|
||||||
OFString *password;
|
|
||||||
/// The server to connect to
|
|
||||||
OFString *server;
|
|
||||||
/// The resource to connect with
|
|
||||||
OFString *resource;
|
|
||||||
/// The JID bound to this connection (this is determined by the server)
|
|
||||||
XMPPJID *JID;
|
XMPPJID *JID;
|
||||||
/// The port to connect to
|
uint16_t port;
|
||||||
short port;
|
|
||||||
/// Whether to use TLS
|
/// Whether to use TLS
|
||||||
BOOL useTLS;
|
BOOL useTLS;
|
||||||
id <XMPPConnectionDelegate, OFObject> delegate;
|
id <XMPPConnectionDelegate, OFObject> delegate;
|
||||||
XMPPAuthenticator *authModule;
|
XMPPAuthenticator *authModule;
|
||||||
BOOL needsSession;
|
BOOL needsSession;
|
||||||
|
unsigned int lastID;
|
||||||
|
OFString *bindID, *sessionID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property (copy) OFString *username;
|
@property (copy) OFString *username, *password, *server, *resource;
|
||||||
@property (copy) OFString *password;
|
|
||||||
@property (copy) OFString *server;
|
|
||||||
@property (copy) OFString *resource;
|
|
||||||
@property (copy, readonly) XMPPJID *JID;
|
@property (copy, readonly) XMPPJID *JID;
|
||||||
@property (assign) short port;
|
@property (assign) uint16_t port;
|
||||||
@property (assign) BOOL useTLS;
|
@property (assign) BOOL useTLS;
|
||||||
@property (retain) id <XMPPConnectionDelegate> delegate;
|
@property (retain) id <XMPPConnectionDelegate> delegate;
|
||||||
|
|
||||||
|
@ -97,4 +87,11 @@
|
||||||
* \param elem The element to send
|
* \param elem The element to send
|
||||||
*/
|
*/
|
||||||
- (void)sendStanza: (OFXMLElement*)elem;
|
- (void)sendStanza: (OFXMLElement*)elem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a new, unique stanza ID.
|
||||||
|
*
|
||||||
|
* \return A new, generated, unique stanza ID.
|
||||||
|
*/
|
||||||
|
- (OFString*)generateStanzaID;
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -48,14 +48,14 @@
|
||||||
@interface XMPPConnection ()
|
@interface XMPPConnection ()
|
||||||
- (void)XMPP_startStream;
|
- (void)XMPP_startStream;
|
||||||
- (void)XMPP_sendAuth: (OFString*)name;
|
- (void)XMPP_sendAuth: (OFString*)name;
|
||||||
- (void)XMPP_sendResourceBind;
|
|
||||||
- (void)XMPP_sendSession;
|
|
||||||
- (void)XMPP_handleResourceBind: (XMPPIQ*)iq;
|
|
||||||
- (void)XMPP_handleSession;
|
|
||||||
- (void)XMPP_handleFeatures: (OFXMLElement*)elem;
|
- (void)XMPP_handleFeatures: (OFXMLElement*)elem;
|
||||||
- (void)XMPP_handleIQ: (XMPPIQ*)iq;
|
- (void)XMPP_handleIQ: (XMPPIQ*)iq;
|
||||||
- (void)XMPP_handleMessage: (XMPPMessage*)msg;
|
- (void)XMPP_handleMessage: (XMPPMessage*)msg;
|
||||||
- (void)XMPP_handlePresence: (XMPPPresence*)pres;
|
- (void)XMPP_handlePresence: (XMPPPresence*)pres;
|
||||||
|
- (void)XMPP_sendResourceBind;
|
||||||
|
- (void)XMPP_handleResourceBind: (XMPPIQ*)iq;
|
||||||
|
- (void)XMPP_sendSession;
|
||||||
|
- (void)XMPP_handleSession: (XMPPIQ*)iq;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation XMPPConnection
|
@implementation XMPPConnection
|
||||||
|
@ -83,7 +83,15 @@
|
||||||
[sock release];
|
[sock release];
|
||||||
[parser release];
|
[parser release];
|
||||||
[elementBuilder release];
|
[elementBuilder release];
|
||||||
|
[username release];
|
||||||
|
[password release];
|
||||||
|
[server release];
|
||||||
|
[resource release];
|
||||||
|
[JID release];
|
||||||
|
[delegate release];
|
||||||
[authModule release];
|
[authModule release];
|
||||||
|
[bindID release];
|
||||||
|
[sessionID release];
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
@ -232,6 +240,11 @@
|
||||||
[sock writeString: [elem stringValue]];
|
[sock writeString: [elem stringValue]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (OFString*)generateStanzaID
|
||||||
|
{
|
||||||
|
return [OFString stringWithFormat: @"objxmpp_%u", lastID++];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)parser: (OFXMLParser*)p
|
- (void)parser: (OFXMLParser*)p
|
||||||
didStartElement: (OFString*)name
|
didStartElement: (OFString*)name
|
||||||
withPrefix: (OFString*)prefix
|
withPrefix: (OFString*)prefix
|
||||||
|
@ -362,14 +375,6 @@
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)elementBuilder: (OFXMLElementBuilder*)b
|
|
||||||
didNotExpectCloseTag: (OFString*)name
|
|
||||||
withPrefix: (OFString*)prefix
|
|
||||||
namespace: (OFString*)ns
|
|
||||||
{
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)XMPP_startStream
|
- (void)XMPP_startStream
|
||||||
{
|
{
|
||||||
[sock writeFormat: @"<?xml version='1.0'?>\n"
|
[sock writeFormat: @"<?xml version='1.0'?>\n"
|
||||||
|
@ -380,14 +385,13 @@
|
||||||
|
|
||||||
- (void)XMPP_handleIQ: (XMPPIQ*)iq
|
- (void)XMPP_handleIQ: (XMPPIQ*)iq
|
||||||
{
|
{
|
||||||
// FIXME: More checking!
|
if ([iq.ID isEqual: bindID] && [iq.type isEqual: @"result"]) {
|
||||||
if ([iq.ID isEqual: @"bind0"] && [iq.type isEqual: @"result"]) {
|
|
||||||
[self XMPP_handleResourceBind: iq];
|
[self XMPP_handleResourceBind: iq];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([iq.ID isEqual: @"session0"] && [iq.type isEqual: @"result"]) {
|
if ([iq.ID isEqual: sessionID] && [iq.type isEqual: @"result"]) {
|
||||||
[self XMPP_handleSession];
|
[self XMPP_handleSession: iq];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -483,13 +487,20 @@
|
||||||
|
|
||||||
- (void)XMPP_sendResourceBind
|
- (void)XMPP_sendResourceBind
|
||||||
{
|
{
|
||||||
XMPPIQ *iq = [XMPPIQ IQWithType: @"set"
|
XMPPIQ *iq;
|
||||||
ID: @"bind0"];
|
OFXMLElement *bind;
|
||||||
OFXMLElement *bind = [OFXMLElement elementWithName: @"bind"
|
|
||||||
namespace: NS_BIND];
|
bindID = [[self generateStanzaID] retain];
|
||||||
if (resource)
|
iq = [XMPPIQ IQWithType: @"set"
|
||||||
|
ID: bindID];
|
||||||
|
|
||||||
|
bind = [OFXMLElement elementWithName: @"bind"
|
||||||
|
namespace: NS_BIND];
|
||||||
|
|
||||||
|
if (resource != nil)
|
||||||
[bind addChild: [OFXMLElement elementWithName: @"resource"
|
[bind addChild: [OFXMLElement elementWithName: @"resource"
|
||||||
stringValue: resource]];
|
stringValue: resource]];
|
||||||
|
|
||||||
[iq addChild: bind];
|
[iq addChild: bind];
|
||||||
|
|
||||||
[self sendStanza: iq];
|
[self sendStanza: iq];
|
||||||
|
@ -508,6 +519,9 @@
|
||||||
JID = [[XMPPJID alloc] initWithString:
|
JID = [[XMPPJID alloc] initWithString:
|
||||||
[jidElem.children.firstObject stringValue]];
|
[jidElem.children.firstObject stringValue]];
|
||||||
|
|
||||||
|
[bindID release];
|
||||||
|
bindID = nil;
|
||||||
|
|
||||||
if (needsSession) {
|
if (needsSession) {
|
||||||
[self XMPP_sendSession];
|
[self XMPP_sendSession];
|
||||||
return;
|
return;
|
||||||
|
@ -520,17 +534,26 @@
|
||||||
|
|
||||||
- (void)XMPP_sendSession
|
- (void)XMPP_sendSession
|
||||||
{
|
{
|
||||||
XMPPIQ *iq = [XMPPIQ IQWithType: @"set"
|
XMPPIQ *iq;
|
||||||
ID: @"session0"];
|
|
||||||
|
sessionID = [[self generateStanzaID] retain];
|
||||||
|
iq = [XMPPIQ IQWithType: @"set"
|
||||||
|
ID: sessionID];
|
||||||
[iq addChild: [OFXMLElement elementWithName: @"session"
|
[iq addChild: [OFXMLElement elementWithName: @"session"
|
||||||
namespace: NS_SESSION]];
|
namespace: NS_SESSION]];
|
||||||
[self sendStanza: iq];
|
[self sendStanza: iq];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)XMPP_handleSession
|
- (void)XMPP_handleSession: (XMPPIQ*)iq
|
||||||
{
|
{
|
||||||
|
if (![iq.type isEqual: @"result"])
|
||||||
|
assert(0);
|
||||||
|
|
||||||
if ([delegate respondsToSelector: @selector(connection:wasBoundToJID:)])
|
if ([delegate respondsToSelector: @selector(connection:wasBoundToJID:)])
|
||||||
[delegate connection: self
|
[delegate connection: self
|
||||||
wasBoundToJID: JID];
|
wasBoundToJID: JID];
|
||||||
|
|
||||||
|
[sessionID release];
|
||||||
|
sessionID = nil;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue