Add -close method
This commit is contained in:
parent
4efd9d8881
commit
446490ebc5
2 changed files with 27 additions and 4 deletions
|
@ -79,6 +79,7 @@
|
||||||
id <XMPPConnectionDelegate, OFObject> delegate;
|
id <XMPPConnectionDelegate, OFObject> delegate;
|
||||||
OFMutableDictionary *callbacks;
|
OFMutableDictionary *callbacks;
|
||||||
XMPPAuthenticator *authModule;
|
XMPPAuthenticator *authModule;
|
||||||
|
BOOL streamOpen;
|
||||||
BOOL needsSession;
|
BOOL needsSession;
|
||||||
BOOL encryptionRequired, encrypted;
|
BOOL encryptionRequired, encrypted;
|
||||||
unsigned int lastID;
|
unsigned int lastID;
|
||||||
|
@ -94,6 +95,7 @@
|
||||||
@property (readonly, retain, getter=socket) OFTCPSocket *sock;
|
@property (readonly, retain, getter=socket) OFTCPSocket *sock;
|
||||||
@property (assign) BOOL encryptionRequired;
|
@property (assign) BOOL encryptionRequired;
|
||||||
@property (readonly) BOOL encrypted;
|
@property (readonly) BOOL encrypted;
|
||||||
|
@property (readonly) BOOL streamOpen;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -106,6 +108,11 @@
|
||||||
*/
|
*/
|
||||||
- (void)connect;
|
- (void)connect;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the stream to the XMPP service
|
||||||
|
*/
|
||||||
|
- (void)close;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the certificate presented by the server.
|
* Checks the certificate presented by the server.
|
||||||
* Throws SSLInvalidCertificateException on failure.
|
* Throws SSLInvalidCertificateException on failure.
|
||||||
|
|
|
@ -65,6 +65,7 @@
|
||||||
sock = [[OFTCPSocket alloc] init];
|
sock = [[OFTCPSocket alloc] init];
|
||||||
port = 5222;
|
port = 5222;
|
||||||
encrypted = NO;
|
encrypted = NO;
|
||||||
|
streamOpen = NO;
|
||||||
callbacks = [[OFMutableDictionary alloc] init];
|
callbacks = [[OFMutableDictionary alloc] init];
|
||||||
} @catch (id e) {
|
} @catch (id e) {
|
||||||
[self release];
|
[self release];
|
||||||
|
@ -316,6 +317,11 @@
|
||||||
return encrypted;
|
return encrypted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)streamOpen
|
||||||
|
{
|
||||||
|
return streamOpen;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)checkCertificate
|
- (void)checkCertificate
|
||||||
{
|
{
|
||||||
X509Certificate *cert;
|
X509Certificate *cert;
|
||||||
|
@ -461,10 +467,12 @@ withCallbackBlock: (xmpp_callback_block)callback;
|
||||||
namespace: (OFString *)ns
|
namespace: (OFString *)ns
|
||||||
{
|
{
|
||||||
if (![name isEqual: @"stream"] || ![prefix isEqual: @"stream"] ||
|
if (![name isEqual: @"stream"] || ![prefix isEqual: @"stream"] ||
|
||||||
![ns isEqual: XMPP_NS_STREAM]) {
|
![ns isEqual: XMPP_NS_STREAM])
|
||||||
@throw [OFMalformedXMLException
|
@throw [OFMalformedXMLException
|
||||||
exceptionWithClass: [builder class]
|
exceptionWithClass: [builder class]
|
||||||
parser: nil];
|
parser: nil];
|
||||||
|
else {
|
||||||
|
[self close];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,6 +504,15 @@ withCallbackBlock: (xmpp_callback_block)callback;
|
||||||
@"xmlns='" XMPP_NS_CLIENT @"' "
|
@"xmlns='" XMPP_NS_CLIENT @"' "
|
||||||
@"xmlns:stream='" XMPP_NS_STREAM @"' "
|
@"xmlns:stream='" XMPP_NS_STREAM @"' "
|
||||||
@"version='1.0'>", domain];
|
@"version='1.0'>", domain];
|
||||||
|
streamOpen = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)close
|
||||||
|
{
|
||||||
|
if (streamOpen) {
|
||||||
|
[sock writeString: @"</stream:stream>"];
|
||||||
|
streamOpen = NO;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)XMPP_handleStanza: (OFXMLElement*)element
|
- (void)XMPP_handleStanza: (OFXMLElement*)element
|
||||||
|
@ -530,9 +547,8 @@ withCallbackBlock: (xmpp_callback_block)callback;
|
||||||
|
|
||||||
if ([[element name] isEqual: @"error"]) {
|
if ([[element name] isEqual: @"error"]) {
|
||||||
OFString *condition, *reason;
|
OFString *condition, *reason;
|
||||||
[parser setDelegate: self];
|
[self close];
|
||||||
[sock writeString: @"</stream:stream>"];
|
[sock close]; // Remote has already closed his stream
|
||||||
[sock close];
|
|
||||||
|
|
||||||
if ([element elementForName: @"bad-format"
|
if ([element elementForName: @"bad-format"
|
||||||
namespace: XMPP_NS_XMPP_STREAM])
|
namespace: XMPP_NS_XMPP_STREAM])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue