Add multicast delegates.

This commit is contained in:
Jonathan Schleifer 2012-01-27 00:23:04 +01:00
parent 1c4befa4c4
commit 7fb28f25c8
9 changed files with 265 additions and 83 deletions

View file

@ -12,6 +12,7 @@ config.h.in
config.log config.log
config.status config.status
configure configure
DerivedData
docs docs
extra.mk extra.mk
ObjXMPP.xcodeproj/*.mode1v3 ObjXMPP.xcodeproj/*.mode1v3

View file

@ -16,6 +16,8 @@
4B19F57C14D17082005D52DC /* XMPPEXTERNALAuth.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B19F57814D17081005D52DC /* XMPPEXTERNALAuth.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B19F57C14D17082005D52DC /* XMPPEXTERNALAuth.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B19F57814D17081005D52DC /* XMPPEXTERNALAuth.h */; settings = {ATTRIBUTES = (Public, ); }; };
4B19F57D14D17082005D52DC /* XMPPEXTERNALAuth.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B19F57914D17081005D52DC /* XMPPEXTERNALAuth.m */; }; 4B19F57D14D17082005D52DC /* XMPPEXTERNALAuth.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B19F57914D17081005D52DC /* XMPPEXTERNALAuth.m */; };
4B19F5A314D1779E005D52DC /* ObjOpenSSL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B19F5A214D1779E005D52DC /* ObjOpenSSL.framework */; }; 4B19F5A314D1779E005D52DC /* ObjOpenSSL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B19F5A214D1779E005D52DC /* ObjOpenSSL.framework */; };
4B19F5D114D20B01005D52DC /* XMPPMulticastDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B19F5CF14D20B01005D52DC /* XMPPMulticastDelegate.h */; };
4B19F5D214D20B01005D52DC /* XMPPMulticastDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B19F5D014D20B01005D52DC /* XMPPMulticastDelegate.m */; };
4B4844F5138BBC7500EB48A5 /* XMPPSRVLookup.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B4844F3138BBC7400EB48A5 /* XMPPSRVLookup.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B4844F5138BBC7500EB48A5 /* XMPPSRVLookup.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B4844F3138BBC7400EB48A5 /* XMPPSRVLookup.h */; settings = {ATTRIBUTES = (Public, ); }; };
4B4844F6138BBC7500EB48A5 /* XMPPSRVLookup.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B4844F4138BBC7500EB48A5 /* XMPPSRVLookup.m */; }; 4B4844F6138BBC7500EB48A5 /* XMPPSRVLookup.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B4844F4138BBC7500EB48A5 /* XMPPSRVLookup.m */; };
4B484501138BBEEB00EB48A5 /* libresolv.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B484500138BBEEB00EB48A5 /* libresolv.dylib */; }; 4B484501138BBEEB00EB48A5 /* libresolv.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B484500138BBEEB00EB48A5 /* libresolv.dylib */; };
@ -68,6 +70,8 @@
4B19F57814D17081005D52DC /* XMPPEXTERNALAuth.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPEXTERNALAuth.h; path = src/XMPPEXTERNALAuth.h; sourceTree = SOURCE_ROOT; }; 4B19F57814D17081005D52DC /* XMPPEXTERNALAuth.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPEXTERNALAuth.h; path = src/XMPPEXTERNALAuth.h; sourceTree = SOURCE_ROOT; };
4B19F57914D17081005D52DC /* XMPPEXTERNALAuth.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPEXTERNALAuth.m; path = src/XMPPEXTERNALAuth.m; sourceTree = SOURCE_ROOT; }; 4B19F57914D17081005D52DC /* XMPPEXTERNALAuth.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPEXTERNALAuth.m; path = src/XMPPEXTERNALAuth.m; sourceTree = SOURCE_ROOT; };
4B19F5A214D1779E005D52DC /* ObjOpenSSL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjOpenSSL.framework; path = /Library/Frameworks/ObjOpenSSL.framework; sourceTree = "<group>"; }; 4B19F5A214D1779E005D52DC /* ObjOpenSSL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ObjOpenSSL.framework; path = /Library/Frameworks/ObjOpenSSL.framework; sourceTree = "<group>"; };
4B19F5CF14D20B01005D52DC /* XMPPMulticastDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPMulticastDelegate.h; path = src/XMPPMulticastDelegate.h; sourceTree = SOURCE_ROOT; };
4B19F5D014D20B01005D52DC /* XMPPMulticastDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPMulticastDelegate.m; path = src/XMPPMulticastDelegate.m; sourceTree = SOURCE_ROOT; };
4B4844F3138BBC7400EB48A5 /* XMPPSRVLookup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPSRVLookup.h; path = src/XMPPSRVLookup.h; sourceTree = SOURCE_ROOT; }; 4B4844F3138BBC7400EB48A5 /* XMPPSRVLookup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XMPPSRVLookup.h; path = src/XMPPSRVLookup.h; sourceTree = SOURCE_ROOT; };
4B4844F4138BBC7500EB48A5 /* XMPPSRVLookup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPSRVLookup.m; path = src/XMPPSRVLookup.m; sourceTree = SOURCE_ROOT; }; 4B4844F4138BBC7500EB48A5 /* XMPPSRVLookup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPSRVLookup.m; path = src/XMPPSRVLookup.m; sourceTree = SOURCE_ROOT; };
4B484500138BBEEB00EB48A5 /* libresolv.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libresolv.dylib; path = usr/lib/libresolv.dylib; sourceTree = SDKROOT; }; 4B484500138BBEEB00EB48A5 /* libresolv.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libresolv.dylib; path = usr/lib/libresolv.dylib; sourceTree = SDKROOT; };
@ -188,6 +192,8 @@
4BC559E31337AC0900E345C7 /* XMPPJID.m */, 4BC559E31337AC0900E345C7 /* XMPPJID.m */,
4BC559E41337AC0900E345C7 /* XMPPMessage.h */, 4BC559E41337AC0900E345C7 /* XMPPMessage.h */,
4BC559E51337AC0900E345C7 /* XMPPMessage.m */, 4BC559E51337AC0900E345C7 /* XMPPMessage.m */,
4B19F5CF14D20B01005D52DC /* XMPPMulticastDelegate.h */,
4B19F5D014D20B01005D52DC /* XMPPMulticastDelegate.m */,
4BC559E61337AC0900E345C7 /* XMPPPLAINAuth.h */, 4BC559E61337AC0900E345C7 /* XMPPPLAINAuth.h */,
4BC559E71337AC0900E345C7 /* XMPPPLAINAuth.m */, 4BC559E71337AC0900E345C7 /* XMPPPLAINAuth.m */,
4BC559E81337AC0900E345C7 /* XMPPPresence.h */, 4BC559E81337AC0900E345C7 /* XMPPPresence.h */,
@ -239,6 +245,7 @@
4B4844F5138BBC7500EB48A5 /* XMPPSRVLookup.h in Headers */, 4B4844F5138BBC7500EB48A5 /* XMPPSRVLookup.h in Headers */,
4BC55A011337AC1800E345C7 /* XMPPStanza.h in Headers */, 4BC55A011337AC1800E345C7 /* XMPPStanza.h in Headers */,
4B01D020137C7E7D005624EA /* namespaces.h in Headers */, 4B01D020137C7E7D005624EA /* namespaces.h in Headers */,
4B19F5D114D20B01005D52DC /* XMPPMulticastDelegate.h in Headers */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -344,6 +351,7 @@
4BD9BF5A134003F700DAB43A /* XMPPRosterItem.m in Sources */, 4BD9BF5A134003F700DAB43A /* XMPPRosterItem.m in Sources */,
4BDEF8081340B240000156D1 /* XMPPRoster.m in Sources */, 4BDEF8081340B240000156D1 /* XMPPRoster.m in Sources */,
4B4844F6138BBC7500EB48A5 /* XMPPSRVLookup.m in Sources */, 4B4844F6138BBC7500EB48A5 /* XMPPSRVLookup.m in Sources */,
4B19F5D214D20B01005D52DC /* XMPPMulticastDelegate.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

View file

@ -13,6 +13,7 @@ SRCS = XMPPAuthenticator.m \
XMPPIQ.m \ XMPPIQ.m \
XMPPJID.m \ XMPPJID.m \
XMPPMessage.m \ XMPPMessage.m \
XMPPMulticastDelegate.m \
XMPPPLAINAuth.m \ XMPPPLAINAuth.m \
XMPPPresence.m \ XMPPPresence.m \
XMPPRoster.m \ XMPPRoster.m \

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, 2011, Jonathan Schleifer <js@webkeks.org> * Copyright (c) 2010, 2011, 2012, Jonathan Schleifer <js@webkeks.org>
* Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de> * Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de>
* *
* https://webkeks.org/hg/objxmpp/ * https://webkeks.org/hg/objxmpp/
@ -32,6 +32,7 @@
@class XMPPRoster; @class XMPPRoster;
@class XMPPRosterItem; @class XMPPRosterItem;
@class SSLSocket; @class SSLSocket;
@class XMPPMulticastDelegate;
@protocol XMPPConnectionDelegate @protocol XMPPConnectionDelegate
#ifndef XMPP_CONNECTION_M #ifndef XMPP_CONNECTION_M
@ -77,7 +78,7 @@
OFString *domain, *domainToASCII; OFString *domain, *domainToASCII;
XMPPJID *JID; XMPPJID *JID;
uint16_t port; uint16_t port;
id <XMPPConnectionDelegate, OFObject> delegate; XMPPMulticastDelegate *delegates;
OFMutableDictionary *callbacks; OFMutableDictionary *callbacks;
XMPPAuthenticator *authModule; XMPPAuthenticator *authModule;
BOOL streamOpen; BOOL streamOpen;
@ -92,7 +93,6 @@
@property (copy) OFString *privateKeyFile, *certificateFile; @property (copy) OFString *privateKeyFile, *certificateFile;
@property (copy, readonly) XMPPJID *JID; @property (copy, readonly) XMPPJID *JID;
@property (assign) uint16_t port; @property (assign) uint16_t port;
@property (assign) id <XMPPConnectionDelegate> delegate;
@property (readonly, retain) XMPPRoster *roster; @property (readonly, retain) XMPPRoster *roster;
@property (readonly, retain, getter=socket) OFTCPSocket *sock; @property (readonly, retain, getter=socket) OFTCPSocket *sock;
@property (assign) BOOL encryptionRequired; @property (assign) BOOL encryptionRequired;
@ -105,6 +105,20 @@
*/ */
+ connection; + connection;
/**
* Adds the specified delegate.
*
* \param delegate The delegate to add
*/
- (void)addDelegate: (id <XMPPConnectionDelegate>)delegate;
/**
* Removes the specified delegate.
*
* \param delegate The delegate to remove
*/
- (void)removeDelegate: (id <XMPPConnectionDelegate>)delegate;
/** /**
* Connects to the XMPP service. * Connects to the XMPP service.
*/ */
@ -175,7 +189,7 @@
* must take exactly one parameter of type XMPPIQ* * must take exactly one parameter of type XMPPIQ*
*/ */
- (void)sendIQ: (XMPPIQ*)iq - (void)sendIQ: (XMPPIQ*)iq
withCallbackObject: (id)object withCallbackObject: (id)object
selector: (SEL)selector; selector: (SEL)selector;
#ifdef OF_HAVE_BLOCKS #ifdef OF_HAVE_BLOCKS
@ -185,7 +199,7 @@ withCallbackObject: (id)object
* \param callback The callback block * \param callback The callback block
*/ */
- (void)sendIQ: (XMPPIQ*)iq - (void)sendIQ: (XMPPIQ*)iq
withCallbackBlock: (void(^)(XMPPIQ*))callback; withCallbackBlock: (void(^)(XMPPIQ*))block;
#endif #endif
/** /**
@ -208,8 +222,6 @@ withCallbackBlock: (void(^)(XMPPIQ*))callback;
- (XMPPJID*)JID; - (XMPPJID*)JID;
- (void)setPort: (uint16_t)port; - (void)setPort: (uint16_t)port;
- (uint16_t)port; - (uint16_t)port;
- (void)setDelegate: (id <XMPPConnectionDelegate>)delegate;
- (id <XMPPConnectionDelegate>)delegate;
- (XMPPRoster*)roster; - (XMPPRoster*)roster;
- (void)XMPP_startStream; - (void)XMPP_startStream;
@ -229,6 +241,7 @@ withCallbackBlock: (void(^)(XMPPIQ*))callback;
- (void)XMPP_sendSession; - (void)XMPP_sendSession;
- (void)XMPP_handleSession: (XMPPIQ*)iq; - (void)XMPP_handleSession: (XMPPIQ*)iq;
- (OFString*)XMPP_IDNAToASCII: (OFString*)domain; - (OFString*)XMPP_IDNAToASCII: (OFString*)domain;
- (XMPPMulticastDelegate*)XMPP_delegates;
@end @end
@interface OFObject (XMPPConnectionDelegate) <XMPPConnectionDelegate> @interface OFObject (XMPPConnectionDelegate) <XMPPConnectionDelegate>

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2010, 2011, Jonathan Schleifer <js@webkeks.org> * Copyright (c) 2010, 2011, 2012, Jonathan Schleifer <js@webkeks.org>
* Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de> * Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de>
* *
* https://webkeks.org/hg/objxmpp/ * https://webkeks.org/hg/objxmpp/
@ -49,6 +49,7 @@
#import "XMPPPresence.h" #import "XMPPPresence.h"
#import "XMPPRoster.h" #import "XMPPRoster.h"
#import "XMPPRosterItem.h" #import "XMPPRosterItem.h"
#import "XMPPMulticastDelegate.h"
#import "XMPPExceptions.h" #import "XMPPExceptions.h"
#import "namespaces.h" #import "namespaces.h"
@ -67,6 +68,7 @@
port = 5222; port = 5222;
encrypted = NO; encrypted = NO;
streamOpen = NO; streamOpen = NO;
delegates = [[XMPPMulticastDelegate alloc] init];
callbacks = [[OFMutableDictionary alloc] init]; callbacks = [[OFMutableDictionary alloc] init];
} @catch (id e) { } @catch (id e) {
[self release]; [self release];
@ -89,6 +91,7 @@
[domain release]; [domain release];
[resource release]; [resource release];
[JID release]; [JID release];
[delegates release];
[callbacks release]; [callbacks release];
[authModule release]; [authModule release];
[roster release]; [roster release];
@ -304,9 +307,9 @@
- (void)parseBuffer: (const char*)buffer - (void)parseBuffer: (const char*)buffer
withLength: (size_t)length withLength: (size_t)length
{ {
if (length < 1 && [delegate respondsToSelector: if (length < 1) {
@selector(connectionWasClosed:)]) { [delegates broadcastSelector: @selector(connectionWasClosed:)
[delegate connectionWasClosed: self]; forConnection: self];
return; return;
} }
@ -375,10 +378,9 @@
- (void)sendStanza: (OFXMLElement*)element - (void)sendStanza: (OFXMLElement*)element
{ {
if ([delegate respondsToSelector: [delegates broadcastSelector: @selector(connection:didSendElement:)
@selector(connection:didSendElement:)]) forConnection: self
[delegate connection: self withObject: element];
didSendElement: element];
[sock writeString: [element XMLString]]; [sock writeString: [element XMLString]];
} }
@ -387,37 +389,37 @@
withCallbackObject: (id)object withCallbackObject: (id)object
selector: (SEL)selector selector: (SEL)selector
{ {
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFAutoreleasePool *pool;
@try { XMPPCallback *callback;
if (![iq ID]) if (![iq ID])
[iq setID: [self generateStanzaID]]; [iq setID: [self generateStanzaID]];
[callbacks setObject: [XMPPCallback pool = [[OFAutoreleasePool alloc] init];
callbackWithCallbackObject: object callback = [XMPPCallback callbackWithCallbackObject: object
selector: selector] selector: selector];
[callbacks setObject: callback
forKey: [iq ID]]; forKey: [iq ID]];
} @finally {
[pool release]; [pool release];
}
[self sendStanza: iq]; [self sendStanza: iq];
} }
#ifdef OF_HAVE_BLOCKS #ifdef OF_HAVE_BLOCKS
- (void)sendIQ: (XMPPIQ*)iq - (void)sendIQ: (XMPPIQ*)iq
withCallbackBlock: (xmpp_callback_block_t)callback; withCallbackBlock: (xmpp_callback_block_t)block;
{ {
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFAutoreleasePool *pool;
@try { XMPPCallback *callback;
if (![iq ID]) if (![iq ID])
[iq setID: [self generateStanzaID]]; [iq setID: [self generateStanzaID]];
[callbacks setObject: [XMPPCallback pool = [[OFAutoreleasePool alloc] init];
callbackWithCallbackBlock: callback] callback = [XMPPCallback callbackWithCallbackBlock: block];
[callbacks setObject: callback
forKey: [iq ID]]; forKey: [iq ID]];
} @finally {
[pool release]; [pool release];
}
[self sendStanza: iq]; [self sendStanza: iq];
} }
@ -486,10 +488,9 @@
[element setPrefix: @"stream" [element setPrefix: @"stream"
forNamespace: XMPP_NS_STREAM]; forNamespace: XMPP_NS_STREAM];
if ([delegate respondsToSelector: [delegates broadcastSelector: @selector(connection:didReceiveElement:)
@selector(connection:didReceiveElement:)]) forConnection: self
[delegate connection: self withObject: element];
didReceiveElement: element];
if ([[element namespace] isEqual: XMPP_NS_CLIENT]) if ([[element namespace] isEqual: XMPP_NS_CLIENT])
[self XMPP_handleStanza: element]; [self XMPP_handleStanza: element];
@ -692,9 +693,9 @@
/* FIXME: Catch errors here */ /* FIXME: Catch errors here */
SSLSocket *newSock; SSLSocket *newSock;
if ([delegate respondsToSelector: [delegates broadcastSelector: @selector(
@selector(connectionWillUpgradeToTLS:)]) connectionWillUpgradeToTLS:)
[delegate connectionWillUpgradeToTLS: self]; forConnection: self];
newSock = [[SSLSocket alloc] initWithSocket: sock newSock = [[SSLSocket alloc] initWithSocket: sock
privateKeyFile: privateKeyFile privateKeyFile: privateKeyFile
@ -704,9 +705,9 @@
encrypted = YES; encrypted = YES;
if ([delegate respondsToSelector: [delegates broadcastSelector: @selector(
@selector(connectionDidUpgradeToTLS:)]) connectionDidUpgradeToTLS:)
[delegate connectionDidUpgradeToTLS: self]; forConnection: self];
/* Stream restart */ /* Stream restart */
[self XMPP_startStream]; [self XMPP_startStream];
@ -748,9 +749,9 @@
[authModule continueWithData: [OFDataArray [authModule continueWithData: [OFDataArray
dataArrayWithBase64EncodedString: [element stringValue]]]; dataArrayWithBase64EncodedString: [element stringValue]]];
if ([delegate respondsToSelector: [delegates broadcastSelector: @selector(
@selector(connectionWasAuthenticated:)]) connectionWWasAuthenticated:)
[delegate connectionWasAuthenticated: self]; forConnection: self];
/* Stream restart */ /* Stream restart */
[self XMPP_startStream]; [self XMPP_startStream];
@ -786,9 +787,10 @@
if ([roster handleIQ: iq]) if ([roster handleIQ: iq])
return; return;
if ([delegate respondsToSelector: @selector(connection:didReceiveIQ:)]) handled = [delegates broadcastSelector: @selector(
handled = [delegate connection: self connection:didReceiveIQ:)
didReceiveIQ: iq]; forConnection: self
withObject: iq];
if (!handled && ![[iq type] isEqual: @"error"] && if (!handled && ![[iq type] isEqual: @"error"] &&
![[iq type] isEqual: @"result"]) { ![[iq type] isEqual: @"result"]) {
@ -799,18 +801,16 @@
- (void)XMPP_handleMessage: (XMPPMessage*)message - (void)XMPP_handleMessage: (XMPPMessage*)message
{ {
if ([delegate respondsToSelector: [delegates broadcastSelector: @selector(connection:didReceiveMessage:)
@selector(connection:didReceiveMessage:)]) forConnection: self
[delegate connection: self withObject: message];
didReceiveMessage: message];
} }
- (void)XMPP_handlePresence: (XMPPPresence*)presence - (void)XMPP_handlePresence: (XMPPPresence*)presence
{ {
if ([delegate respondsToSelector: [delegates broadcastSelector: @selector(connection:didReceivePresence:)
@selector(connection:didReceivePresence:)]) forConnection: self
[delegate connection: self withObject: presence];
didReceivePresence: presence];
} }
- (void)XMPP_handleFeatures: (OFXMLElement*)element - (void)XMPP_handleFeatures: (OFXMLElement*)element
@ -979,9 +979,9 @@
return; return;
} }
if ([delegate respondsToSelector: @selector(connection:wasBoundToJID:)]) [delegates broadcastSelector: @selector(connection:wasBoundToJID:)
[delegate connection: self forConnection: self
wasBoundToJID: JID]; withObject: JID];
} }
- (void)XMPP_sendSession - (void)XMPP_sendSession
@ -1002,9 +1002,9 @@
if (![[iq type] isEqual: @"result"]) if (![[iq type] isEqual: @"result"])
assert(0); assert(0);
if ([delegate respondsToSelector: @selector(connection:wasBoundToJID:)]) [delegates broadcastSelector: @selector(connection:wasBoundToJID:)
[delegate connection: self forConnection: self
wasBoundToJID: JID]; withObject: JID];
} }
- (OFString*)XMPP_IDNAToASCII: (OFString*)domain_ - (OFString*)XMPP_IDNAToASCII: (OFString*)domain_
@ -1045,14 +1045,19 @@
return port; return port;
} }
- (void)setDelegate: (id <XMPPConnectionDelegate>)delegate_ - (void)addDelegate: (id <XMPPConnectionDelegate>)delegate
{ {
delegate = (id <XMPPConnectionDelegate, OFObject>)delegate_; [delegates addDelegate: delegate];
} }
- (id <XMPPConnectionDelegate>)delegate - (void)removeDelegate: (id <XMPPConnectionDelegate>)delegate
{ {
return delegate; [delegates removeDelegate: delegate];
}
- (XMPPMulticastDelegate*)XMPP_delegates
{
return delegates;
} }
- (XMPPRoster*)roster - (XMPPRoster*)roster

View file

@ -0,0 +1,39 @@
/*
* Copyright (c) 2012, Jonathan Schleifer <js@webkeks.org>
*
* https://webkeks.org/hg/objxmpp/
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice is present in all copies.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#import "XMPPConnection.h"
@class OFDataArray;
@interface XMPPMulticastDelegate: OFObject
{
OFDataArray *delegates;
}
- (void)addDelegate: (id <XMPPConnectionDelegate>)delegate;
- (void)removeDelegate: (id <XMPPConnectionDelegate>)delegate;
- (BOOL)broadcastSelector: (SEL)selector
forConnection: (XMPPConnection*)connection;
- (BOOL)broadcastSelector: (SEL)selector
forConnection: (XMPPConnection*)connection
withObject: (id)object;
@end

111
src/XMPPMulticastDelegate.m Normal file
View file

@ -0,0 +1,111 @@
/*
* Copyright (c) 2012, Jonathan Schleifer <js@webkeks.org>
*
* https://webkeks.org/hg/objxmpp/
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice is present in all copies.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#import <ObjFW/OFDataArray.h>
#import "XMPPMulticastDelegate.h"
@implementation XMPPMulticastDelegate
- init
{
self = [super init];
@try {
delegates = [[OFDataArray alloc] initWithItemSize: sizeof(id)];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[delegates release];
[super dealloc];
}
- (void)addDelegate: (id <XMPPConnectionDelegate>)delegate
{
[delegates addItem: &delegate];
}
- (void)removeDelegate: (id<XMPPConnectionDelegate>)delegate
{
id *cArray = [delegates cArray];
size_t i, count = [delegates count];
for (i = 0; i < count; i++) {
if (cArray[i] == delegate) {
[delegates removeItemAtIndex: i];
return;
}
}
}
- (BOOL)broadcastSelector: (SEL)selector
forConnection: (XMPPConnection*)connection
{
id *cArray = [delegates cArray];
size_t i, count = [delegates count];
BOOL handled = NO;
for (i = 0; i < count; i++) {
if (![cArray[i] respondsToSelector: selector])
continue;
BOOL (*imp)(id, SEL, id) = (BOOL(*)(id, SEL, id))
[cArray[i] methodForSelector: selector];
handled |= imp(cArray[i], selector, connection);
}
return handled;
}
- (BOOL)broadcastSelector: (SEL)selector
forConnection: (XMPPConnection*)connection
withObject: (id)object
{
id *cArray = [delegates cArray];
size_t i, count = [delegates count];
BOOL handled = NO;
for (i = 0; i < count; i++) {
if (![cArray[i] respondsToSelector: selector])
continue;
BOOL (*imp)(id, SEL, id, id) = (BOOL(*)(id, SEL, id, id))
[cArray[i] methodForSelector: selector];
handled |= imp(cArray[i], selector, connection, object);
}
return handled;
}
@end

View file

@ -31,6 +31,7 @@
#import "XMPPConnection.h" #import "XMPPConnection.h"
#import "XMPPIQ.h" #import "XMPPIQ.h"
#import "XMPPJID.h" #import "XMPPJID.h"
#import "XMPPMulticastDelegate.h"
#import "namespaces.h" #import "namespaces.h"
@implementation XMPPRoster @implementation XMPPRoster
@ -157,19 +158,22 @@
else else
[self XMPP_addRosterItem: rosterItem]; [self XMPP_addRosterItem: rosterItem];
if (isPush && [[connection delegate] respondsToSelector: if (isPush) {
@selector(connection:didReceiveRosterItem:)]) SEL sel = @selector(connection:didReceiveRosterItem:);
[[connection delegate] connection: connection
didReceiveRosterItem: rosterItem]; [[connection XMPP_delegates]
broadcastSelector: sel
forConnection: connection
withObject: rosterItem];
}
} }
if (isPush) { if (isPush) {
[connection sendStanza: [iq resultIQ]]; [connection sendStanza: [iq resultIQ]];
} else { } else {
if ([[connection delegate] respondsToSelector: [[connection XMPP_delegates]
@selector(connectionDidReceiveRoster:)]) broadcastSelector: @selector(connectionDidReceiveRoster:)
[[connection delegate] forConnection: connection];
connectionDidReceiveRoster: connection];
[rosterID release]; [rosterID release];
rosterID = nil; rosterID = nil;

View file

@ -91,7 +91,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
[stanza ID]] isEqual: @"bob@localhost, alice@localhost, get, 42"])); [stanza ID]] isEqual: @"bob@localhost, alice@localhost, get, 42"]));
conn = [[XMPPConnection alloc] init]; conn = [[XMPPConnection alloc] init];
[conn setDelegate: self]; [conn addDelegate: self];
if ([arguments count] != 3) { if ([arguments count] != 3) {
of_log(@"Invalid count of command line arguments!"); of_log(@"Invalid count of command line arguments!");