Overview
Comment: | Add capability to register callbacks when sending IQs |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
9815ad146d58ceb44c77000a76ffee90 |
User & Date: | florob@babelmonkeys.de on 2012-01-01 02:42:01 |
Other Links: | manifest | tags |
Context
2012-01-04
| ||
22:25 | Use OF_SETTER/OF_GETTER. check-in: 220daa147d user: js tags: trunk | |
2012-01-01
| ||
02:42 | Add capability to register callbacks when sending IQs check-in: 9815ad146d user: florob@babelmonkeys.de tags: trunk | |
2011-12-11
| ||
23:40 | Get rid of a warning. check-in: e85080a478 user: js tags: trunk | |
Changes
Modified src/Makefile from [9c79822df1] to [c7688681a6].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | include ../extra.mk LIB = ${OBJXMPP_SHARED_LIB} LIB_MAJOR = 0 LIB_MINOR = 0 STATIC_LIB = ${OBJXMPP_STATIC_LIB} SRCS = XMPPAuthenticator.m \ XMPPConnection.m \ XMPPExceptions.m \ XMPPIQ.m \ XMPPJID.m \ XMPPMessage.m \ XMPPPLAINAuth.m \ XMPPPresence.m \ | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | include ../extra.mk LIB = ${OBJXMPP_SHARED_LIB} LIB_MAJOR = 0 LIB_MINOR = 0 STATIC_LIB = ${OBJXMPP_STATIC_LIB} SRCS = XMPPAuthenticator.m \ XMPPCallback.m \ XMPPConnection.m \ XMPPExceptions.m \ XMPPIQ.m \ XMPPJID.m \ XMPPMessage.m \ XMPPPLAINAuth.m \ XMPPPresence.m \ |
︙ | ︙ |
Added src/XMPPCallback.h version [9b4ffbc375].
Added src/XMPPCallback.m version [2b6add7aa0].
Modified src/XMPPConnection.h from [75217b7182] to [bd5ddff49e].
︙ | ︙ | |||
73 74 75 76 77 78 79 80 81 82 83 | OFXMLParser *parser, *oldParser; OFXMLElementBuilder *elementBuilder, *oldElementBuilder; OFString *username, *password, *server, *resource; OFString *domain, *domainToASCII; XMPPJID *JID; uint16_t port; id <XMPPConnectionDelegate, OFObject> delegate; XMPPAuthenticator *authModule; BOOL needsSession; BOOL encryptionRequired, encrypted; unsigned int lastID; | > < | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | OFXMLParser *parser, *oldParser; OFXMLElementBuilder *elementBuilder, *oldElementBuilder; OFString *username, *password, *server, *resource; OFString *domain, *domainToASCII; XMPPJID *JID; uint16_t port; id <XMPPConnectionDelegate, OFObject> delegate; OFMutableDictionary *callbacks; XMPPAuthenticator *authModule; BOOL needsSession; BOOL encryptionRequired, encrypted; unsigned int lastID; XMPPRoster *roster; } #ifdef OF_HAVE_PROPERTIES @property (copy) OFString *username, *password, *server, *domain, *resource; @property (copy, readonly) XMPPJID *JID; @property (assign) uint16_t port; |
︙ | ︙ | |||
154 155 156 157 158 159 160 161 162 163 164 165 166 167 | /** * Sends an OFXMLElement, usually an XMPPStanza. * * \param element The element to send */ - (void)sendStanza: (OFXMLElement*)element; /** * Generates a new, unique stanza ID. * * \return A new, generated, unique stanza ID. */ - (OFString*)generateStanzaID; | > > > > > > > > > > > > > > > > > > > > > | 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | /** * Sends an OFXMLElement, usually an XMPPStanza. * * \param element The element to send */ - (void)sendStanza: (OFXMLElement*)element; /** * Sends an XMPPIQ, registering a callback method * * \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; #ifdef OF_HAVE_BLOCKS /** * Sends an XMPPIQ, registering a callback block * * \param callback The callback block */ - (void)sendIQ: (XMPPIQ*)iq withCallbackBlock: (void(^)(XMPPIQ*))callback; #endif /** * Generates a new, unique stanza ID. * * \return A new, generated, unique stanza ID. */ - (OFString*)generateStanzaID; |
︙ | ︙ |
Modified src/XMPPConnection.m from [7b09f7e693] to [e52bbff4d6].
︙ | ︙ | |||
33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #include <idna.h> #import <ObjOpenSSL/SSLSocket.h> #import <ObjOpenSSL/SSLInvalidCertificateException.h> #import <ObjOpenSSL/X509Certificate.h> #import "XMPPConnection.h" #import "XMPPSRVLookup.h" #import "XMPPSCRAMAuth.h" #import "XMPPPLAINAuth.h" #import "XMPPStanza.h" #import "XMPPJID.h" #import "XMPPIQ.h" #import "XMPPMessage.h" | > | 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include <idna.h> #import <ObjOpenSSL/SSLSocket.h> #import <ObjOpenSSL/SSLInvalidCertificateException.h> #import <ObjOpenSSL/X509Certificate.h> #import "XMPPConnection.h" #import "XMPPCallback.h" #import "XMPPSRVLookup.h" #import "XMPPSCRAMAuth.h" #import "XMPPPLAINAuth.h" #import "XMPPStanza.h" #import "XMPPJID.h" #import "XMPPIQ.h" #import "XMPPMessage.h" |
︙ | ︙ | |||
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | { self = [super init]; @try { sock = [[OFTCPSocket alloc] init]; port = 5222; encrypted = NO; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [sock release]; [parser release]; [elementBuilder release]; [username release]; [password release]; [server release]; [domain release]; [resource release]; [JID release]; | > < | | | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | { self = [super init]; @try { sock = [[OFTCPSocket alloc] init]; port = 5222; encrypted = NO; callbacks = [[OFMutableDictionary alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [sock release]; [parser release]; [elementBuilder release]; [username release]; [password release]; [server release]; [domain release]; [resource release]; [JID release]; [callbacks release]; [authModule release]; [roster release]; [super dealloc]; } - (void)setUsername: (OFString*)username_ { |
︙ | ︙ | |||
347 348 349 350 351 352 353 354 355 356 357 358 359 360 | if ([delegate respondsToSelector: @selector(connection:didSendElement:)]) [delegate connection: self didSendElement: element]; [sock writeString: [element XMLString]]; } - (OFString*)generateStanzaID { return [OFString stringWithFormat: @"objxmpp_%u", lastID++]; } - (void)parser: (OFXMLParser*)p | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | if ([delegate respondsToSelector: @selector(connection:didSendElement:)]) [delegate connection: self didSendElement: element]; [sock writeString: [element XMLString]]; } - (void)sendIQ: (XMPPIQ*)iq withCallbackObject: (id)object selector: (SEL)selector { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; @try { if (![iq ID]) [iq setID: [self generateStanzaID]]; [callbacks setObject: [XMPPObjectCallback callbackWithCallbackObject: object selector: selector] forKey: [iq ID]]; } @finally { [pool release]; } [self sendStanza: iq]; } #ifdef OF_HAVE_BLOCKS - (void)sendIQ: (XMPPIQ*)iq withCallbackBlock: (xmpp_callback_block)callback; { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; @try { if (![iq ID]) [iq setID: [self generateStanzaID]]; [callbacks setObject: [XMPPBlockCallback callbackWithCallbackBlock: callback] forKey: [iq ID]]; } @finally { [pool release]; } [self sendStanza: iq]; } #endif - (OFString*)generateStanzaID { return [OFString stringWithFormat: @"objxmpp_%u", lastID++]; } - (void)parser: (OFXMLParser*)p |
︙ | ︙ | |||
652 653 654 655 656 657 658 | assert(0); } - (void)XMPP_handleIQ: (XMPPIQ*)iq { BOOL handled = NO; | | < < < | | < | > | 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 | assert(0); } - (void)XMPP_handleIQ: (XMPPIQ*)iq { BOOL handled = NO; id <XMPPCallback> callback; if ((callback = [callbacks objectForKey: [iq ID]])) { [callback runWithIQ: iq]; [callbacks removeObjectForKey: [iq ID]]; return; } if ([iq elementForName: @"query" namespace: XMPP_NS_ROSTER]) if ([roster handleIQ: iq]) return; |
︙ | ︙ | |||
795 796 797 798 799 800 801 | } - (void)XMPP_sendResourceBind { XMPPIQ *iq; OFXMLElement *bind; | < | | > > < < < < | | > > < < < | 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 | } - (void)XMPP_sendResourceBind { XMPPIQ *iq; OFXMLElement *bind; iq = [XMPPIQ IQWithType: @"set" ID: [self generateStanzaID]]; bind = [OFXMLElement elementWithName: @"bind" namespace: XMPP_NS_BIND]; if (resource != nil) [bind addChild: [OFXMLElement elementWithName: @"resource" namespace: XMPP_NS_BIND stringValue: resource]]; [iq addChild: bind]; [self sendIQ: iq withCallbackObject: self selector: @selector(XMPP_handleResourceBind:)]; } - (void)XMPP_handleResourceBind: (XMPPIQ*)iq { OFXMLElement *bindElement; OFXMLElement *jidElement; assert([[iq type] isEqual: @"result"]); bindElement = [iq elementForName: @"bind" namespace: XMPP_NS_BIND]; assert(bindElement != nil); jidElement = [bindElement elementForName: @"jid" namespace: XMPP_NS_BIND]; JID = [[XMPPJID alloc] initWithString: [jidElement stringValue]]; if (needsSession) { [self XMPP_sendSession]; return; } if ([delegate respondsToSelector: @selector(connection:wasBoundToJID:)]) [delegate connection: self wasBoundToJID: JID]; } - (void)XMPP_sendSession { XMPPIQ *iq; iq = [XMPPIQ IQWithType: @"set" ID: [self generateStanzaID]]; [iq addChild: [OFXMLElement elementWithName: @"session" namespace: XMPP_NS_SESSION]]; [self sendIQ: iq withCallbackObject: self selector: @selector(XMPP_handleSession:)]; } - (void)XMPP_handleSession: (XMPPIQ*)iq { if (![[iq type] isEqual: @"result"]) assert(0); if ([delegate respondsToSelector: @selector(connection:wasBoundToJID:)]) [delegate connection: self wasBoundToJID: JID]; } - (OFString*)XMPP_IDNAToASCII: (OFString*)domain_ { OFString *ret; char *cDomain; Idna_rc rc; |
︙ | ︙ |