Index: src/XMPPCallback.h ================================================================== --- src/XMPPCallback.h +++ src/XMPPCallback.h @@ -29,22 +29,25 @@ typedef void(^xmpp_callback_block_t)(XMPPConnection*, XMPPIQ*); #endif @interface XMPPCallback: OFObject { - id object; + id target; SEL selector; +#ifdef OF_HAVE_BLOCKS + xmpp_callback_block_t block; +#endif } #ifdef OF_HAVE_BLOCKS -+ callbackWithCallbackBlock: (xmpp_callback_block_t)callback; -- initWithCallbackBlock: (xmpp_callback_block_t)callback; ++ callbackWithBlock: (xmpp_callback_block_t)callback; +- initWithBlock: (xmpp_callback_block_t)callback; #endif -+ callbackWithCallbackObject: (id)object - selector: (SEL)selector; -- initWithCallbackObject: (id)object - selector: (SEL)selector; ++ callbackWithTarget: (id)target + selector: (SEL)selector; +- initWithTarget: (id)target + selector: (SEL)selector; - (void)runWithIQ: (XMPPIQ*)iq connection: (XMPPConnection*)connection; @end Index: src/XMPPCallback.m ================================================================== --- src/XMPPCallback.m +++ src/XMPPCallback.m @@ -26,56 +26,66 @@ #import "XMPPCallback.h" @implementation XMPPCallback #ifdef OF_HAVE_BLOCKS -+ callbackWithCallbackBlock: (xmpp_callback_block_t)callback ++ callbackWithBlock: (xmpp_callback_block_t)block { - return [[[self alloc] initWithCallbackBlock: callback] autorelease]; + return [[(XMPPCallback*)[self alloc] initWithBlock: block] autorelease]; } -- initWithCallbackBlock: (xmpp_callback_block_t)callback +- initWithBlock: (xmpp_callback_block_t)block_ { self = [super init]; - object = [callback copy]; + @try { + block = [block_ copy]; + } @catch (id e) { + [self release]; + @throw e; + } return self; } #endif -+ callbackWithCallbackObject: (id)object_ - selector: (SEL)selector_ -{ - return [[[self alloc] initWithCallbackObject: object_ - selector: selector_] autorelease]; -} - -- initWithCallbackObject: (id)object_ - selector: (SEL)selector_ ++ callbackWithTarget: (id)target + selector: (SEL)selector +{ + return [[[self alloc] initWithTarget: target + selector: selector] autorelease]; +} + +- initWithTarget: (id)target_ + selector: (SEL)selector_ { self = [super init]; - object = object_; + target = [target_ retain]; selector = selector_; return self; } - (void)dealloc { + [target release]; +#ifdef OF_HAVE_BLOCKS + [block release]; +#endif + [super dealloc]; } - (void)runWithIQ: (XMPPIQ*)iq connection: (XMPPConnection*)connection { #ifdef OF_HAVE_BLOCKS - if ([object isKindOfClass: [OFBlock class]]) - ((xmpp_callback_block_t)object)(connection, iq); + if (block != NULL) + block(connection, iq); else #endif - [object performSelector: selector + [target performSelector: selector withObject: connection withObject: iq]; } @end Index: src/XMPPConnection.h ================================================================== --- src/XMPPConnection.h +++ src/XMPPConnection.h @@ -313,22 +313,22 @@ * * \param object The object that contains the callback method * \param selector The selector of the callback method, * must take exactly one parameter of type XMPPIQ* */ -- (void)sendIQ: (XMPPIQ*)iq - withCallbackObject: (id)object - selector: (SEL)selector; +- (void)sendIQ: (XMPPIQ*)iq + callbackTarget: (id)target + selector: (SEL)selector; #ifdef OF_HAVE_BLOCKS /** * \brief Sends an XMPPIQ, registering a callback block. * * \param callback The callback block */ -- (void)sendIQ: (XMPPIQ*)iq - withCallbackBlock: (xmpp_callback_block_t)block; +- (void)sendIQ: (XMPPIQ*)iq + callbackBlock: (xmpp_callback_block_t)block; #endif /** * \brief Generates a new, unique stanza ID. * @@ -368,13 +368,13 @@ - (void)XMPP_handleIQ: (XMPPIQ*)iq; - (void)XMPP_handleMessage: (XMPPMessage*)message; - (void)XMPP_handlePresence: (XMPPPresence*)presence; - (void)XMPP_handleFeatures: (OFXMLElement*)element; - (void)XMPP_handleResourceBindForConnection: (XMPPConnection*)connection - withIQ: (XMPPIQ*)iq; + IQ: (XMPPIQ*)iq; - (void)XMPP_sendSession; - (void)XMPP_handleSessionForConnection: (XMPPConnection*)connection - withIQ: (XMPPIQ*)iq; + IQ: (XMPPIQ*)iq; - (OFString*)XMPP_IDNAToASCII: (OFString*)domain; - (XMPPMulticastDelegate*)XMPP_delegates; /// \endcond @end Index: src/XMPPConnection.m ================================================================== --- src/XMPPConnection.m +++ src/XMPPConnection.m @@ -467,42 +467,42 @@ withObject: element]; [sock writeString: [element XMLString]]; } -- (void)sendIQ: (XMPPIQ*)iq - withCallbackObject: (id)object - selector: (SEL)selector +- (void)sendIQ: (XMPPIQ*)iq + callbackTarget: (id)target + selector: (SEL)selector { OFAutoreleasePool *pool; XMPPCallback *callback; if (![iq ID]) [iq setID: [self generateStanzaID]]; pool = [[OFAutoreleasePool alloc] init]; - callback = [XMPPCallback callbackWithCallbackObject: object - selector: selector]; + callback = [XMPPCallback callbackWithTarget: target + selector: selector]; [callbacks setObject: callback forKey: [iq ID]]; [pool release]; [self sendStanza: iq]; } #ifdef OF_HAVE_BLOCKS -- (void)sendIQ: (XMPPIQ*)iq - withCallbackBlock: (xmpp_callback_block_t)block; +- (void)sendIQ: (XMPPIQ*)iq + callbackBlock: (xmpp_callback_block_t)block { OFAutoreleasePool *pool; XMPPCallback *callback; if (![iq ID]) [iq setID: [self generateStanzaID]]; pool = [[OFAutoreleasePool alloc] init]; - callback = [XMPPCallback callbackWithCallbackBlock: block]; + callback = [XMPPCallback callbackWithBlock: block]; [callbacks setObject: callback forKey: [iq ID]]; [pool release]; [self sendStanza: iq]; @@ -1036,14 +1036,14 @@ namespace: XMPP_NS_BIND stringValue: resource]]; [iq addChild: bind]; - [self sendIQ: iq - withCallbackObject: self - selector: @selector(XMPP_handleResourceBindForConnection: - withIQ:)]; + [self sendIQ: iq + callbackTarget: self + selector: @selector(XMPP_handleResourceBindForConnection: + IQ:)]; } - (void)XMPP_sendStreamError: (OFString*)condition text: (OFString*)text { @@ -1063,11 +1063,11 @@ [self sendStanza: error]; [self close]; } - (void)XMPP_handleResourceBindForConnection: (XMPPConnection*)connection - withIQ: (XMPPIQ*)iq + IQ: (XMPPIQ*)iq { OFXMLElement *bindElement; OFXMLElement *jidElement; assert([[iq type] isEqual: @"result"]); @@ -1097,18 +1097,17 @@ iq = [XMPPIQ IQWithType: @"set" ID: [self generateStanzaID]]; [iq addChild: [OFXMLElement elementWithName: @"session" namespace: XMPP_NS_SESSION]]; - [self sendIQ: iq - withCallbackObject: self - selector: @selector( - XMPP_handleSessionForConnection:withIQ:)]; + [self sendIQ: iq + callbackTarget: self + selector: @selector(XMPP_handleSessionForConnection:IQ:)]; } - (void)XMPP_handleSessionForConnection: (XMPPConnection*)connection - withIQ: (XMPPIQ*)iq + IQ: (XMPPIQ*)iq { if (![[iq type] isEqual: @"result"]) assert(0); [delegates broadcastSelector: @selector(connection:wasBoundToJID:) Index: src/XMPPRoster.h ================================================================== --- src/XMPPRoster.h +++ src/XMPPRoster.h @@ -154,9 +154,9 @@ - (id )dataStorage; /// \cond internal - (void)XMPP_updateRosterItem: (XMPPRosterItem*)rosterItem; - (void)XMPP_handleInitialRosterForConnection: (XMPPConnection*)connection - withIQ: (XMPPIQ*)iq; + IQ: (XMPPIQ*)iq; - (XMPPRosterItem*)XMPP_rosterItemWithXMLElement: (OFXMLElement*)element; /// \endcond @end Index: src/XMPPRoster.m ================================================================== --- src/XMPPRoster.m +++ src/XMPPRoster.m @@ -95,14 +95,14 @@ stringValue: ver]; } [iq addChild: query]; - [connection sendIQ: iq - withCallbackObject: self - selector: @selector(XMPP_handleInitialRosterForConnection: - withIQ:)]; + [connection sendIQ: iq + callbackTarget: self + selector: @selector(XMPP_handleInitialRosterForConnection: + IQ:)]; } - (BOOL)connection: (XMPPConnection*)connection_ didReceiveIQ: (XMPPIQ*)iq { @@ -304,11 +304,11 @@ return rosterItem; } - (void)XMPP_handleInitialRosterForConnection: (XMPPConnection*)connection_ - withIQ: (XMPPIQ*)iq + IQ: (XMPPIQ*)iq { OFXMLElement *rosterElement; OFEnumerator *enumerator; OFXMLElement *element; XMPPRosterItem *rosterItem; Index: tests/test.m ================================================================== --- tests/test.m +++ tests/test.m @@ -167,12 +167,12 @@ #ifdef OF_HAVE_BLOCKS XMPPIQ *iq = [XMPPIQ IQWithType: @"get" ID: [conn generateStanzaID]]; [iq addChild: [OFXMLElement elementWithName: @"ping" namespace: @"urn:xmpp:ping"]]; - [conn sendIQ: iq - withCallbackBlock: ^ (XMPPConnection *c, XMPPIQ *resp) { + [conn sendIQ: iq + callbackBlock: ^ (XMPPConnection *c, XMPPIQ *resp) { of_log(@"Ping response: %@", resp); }]; #endif }