︙ | | | ︙ | |
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
86
87
88
89
90
91
92
93
94
95
|
{
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];
[authModule release];
[bindID release];
[sessionID release];
[roster release];
[super dealloc];
}
- (void)setUsername: (OFString*)username_
{
|
>
<
|
|
|
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
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
|
assert(0);
}
- (void)XMPP_handleIQ: (XMPPIQ*)iq
{
BOOL handled = NO;
if ([[iq ID] isEqual: bindID]) {
[self XMPP_handleResourceBind: iq];
return;
}
if ([[iq ID] isEqual: sessionID]) {
[self XMPP_handleSession: iq];
return;
}
if ([iq elementForName: @"query"
namespace: XMPP_NS_ROSTER])
if ([roster handleIQ: iq])
return;
|
|
<
<
<
|
|
<
|
>
|
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
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
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
|
}
- (void)XMPP_sendResourceBind
{
XMPPIQ *iq;
OFXMLElement *bind;
bindID = [[self generateStanzaID] retain];
iq = [XMPPIQ IQWithType: @"set"
ID: bindID];
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 sendStanza: iq];
}
- (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]];
[bindID release];
bindID = nil;
if (needsSession) {
[self XMPP_sendSession];
return;
}
if ([delegate respondsToSelector: @selector(connection:wasBoundToJID:)])
[delegate connection: self
wasBoundToJID: JID];
}
- (void)XMPP_sendSession
{
XMPPIQ *iq;
sessionID = [[self generateStanzaID] retain];
iq = [XMPPIQ IQWithType: @"set"
ID: sessionID];
[iq addChild: [OFXMLElement elementWithName: @"session"
namespace: XMPP_NS_SESSION]];
[self sendStanza: iq];
}
- (void)XMPP_handleSession: (XMPPIQ*)iq
{
if (![[iq type] isEqual: @"result"])
assert(0);
if ([delegate respondsToSelector: @selector(connection:wasBoundToJID:)])
[delegate connection: self
wasBoundToJID: JID];
[sessionID release];
sessionID = nil;
}
- (OFString*)XMPP_IDNAToASCII: (OFString*)domain_
{
OFString *ret;
char *cDomain;
Idna_rc rc;
|
<
|
|
>
>
<
<
<
<
|
|
>
>
<
<
<
|
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;
|
︙ | | | ︙ | |