73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
-
|
[server release];
[resource release];
[JID release];
[delegate release];
[authModule release];
[bindID release];
[sessionID release];
[rosterID release];
[roster release];
[super dealloc];
}
- (void)setUsername: (OFString*)username_
{
|
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
-
-
-
-
-
+
+
+
+
-
-
-
+
-
|
if (length < 1 && [delegate respondsToSelector:
@selector(connectionWasClosed:)])
[delegate connectionWasClosed: self];
[parser parseBuffer: buffer
withLength: length];
if (oldParser != nil) {
[oldParser release];
oldParser = nil;
}
[oldParser release];
[oldElementBuilder release];
oldParser = nil;
if (oldElementBuilder != nil) {
[oldElementBuilder release];
oldElementBuilder = nil;
oldElementBuilder = nil;
}
}
- (OFTCPSocket*)socket
{
return [[sock retain] autorelease];
}
|
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
|
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
|
-
-
-
+
+
+
-
|
if ([[iq ID] isEqual: sessionID]) {
[self XMPP_handleSession: iq];
return;
}
if ([iq elementForName: @"query"
namespace: XMPP_NS_ROSTER]) {
[self XMPP_handleRoster: iq];
return;
namespace: XMPP_NS_ROSTER])
if ([roster handleIQ: iq])
return;
}
if ([delegate respondsToSelector: @selector(connection:didReceiveIQ:)])
handled = [delegate connection: self
didReceiveIQ: iq];
if (!handled && ![[iq type] isEqual: @"error"]
&& ![[iq type] isEqual: @"result"]) {
|
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
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
|
752
753
754
755
756
757
758
759
760
761
762
763
764
765
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
[delegate connection: self
wasBoundToJID: JID];
[sessionID release];
sessionID = nil;
}
- (void)requestRoster
{
XMPPIQ *iq;
if (rosterID != nil)
assert(0);
rosterID = [[self generateStanzaID] retain];
iq = [XMPPIQ IQWithType: @"get"
ID: rosterID];
[iq addChild: [OFXMLElement elementWithName: @"query"
namespace: XMPP_NS_ROSTER]];
[self sendStanza: iq];
}
- (void)XMPP_handleRoster: (XMPPIQ*)iq
{
OFXMLElement *rosterElement;
OFXMLElement *element;
XMPPRosterItem *rosterItem = nil;
OFString *subscription;
OFEnumerator *enumerator;
BOOL isPush = ![[iq ID] isEqual: rosterID];
rosterElement = [iq elementForName: @"query"
namespace: XMPP_NS_ROSTER];
if (isPush)
assert([[iq type] isEqual: @"set"]);
else
assert([[iq type] isEqual: @"result"]);
enumerator = [[rosterElement children] objectEnumerator];
while ((element = [enumerator nextObject]) != nil) {
OFMutableArray *groups = [OFMutableArray array];
OFEnumerator *groupEnumerator;
OFXMLElement *groupElement;
if (![[element name] isEqual: @"item"] ||
![[element namespace] isEqual: XMPP_NS_ROSTER])
continue;
rosterItem = [XMPPRosterItem rosterItem];
[rosterItem setJID: [XMPPJID JIDWithString:
[[element attributeForName: @"jid"] stringValue]]];
[rosterItem setName:
[[element attributeForName: @"name"] stringValue]];
subscription = [[element attributeForName:
@"subscription"] stringValue];
if (![subscription isEqual: @"none"] &&
![subscription isEqual: @"to"] &&
![subscription isEqual: @"from"] &&
![subscription isEqual: @"both"] &&
(![subscription isEqual: @"remove"] || !isPush))
subscription = @"none";
[rosterItem setSubscription: subscription];
groupEnumerator = [[element
elementsForName: @"group"
namespace: XMPP_NS_ROSTER] objectEnumerator];
while ((groupElement = [groupEnumerator nextObject]) != nil)
[groups addObject: [groupElement stringValue]];
if ([groups count] > 0)
[rosterItem setGroups: groups];
if ([subscription isEqual: @"remove"])
[roster XMPP_deleteRosterItem: rosterItem];
else
[roster XMPP_addRosterItem: rosterItem];
if (isPush && [delegate respondsToSelector:
@selector(connection:didReceiveRosterItem:)])
[delegate connection:self
didReceiveRosterItem: rosterItem];
}
if (isPush) {
XMPPIQ *response = [XMPPIQ IQWithType: @"result"
ID: [iq ID]];
[response setTo: [iq from]];
[self sendStanza: response];
} else {
if ([delegate respondsToSelector:
@selector(connectionDidReceiveRoster:)])
[delegate connectionDidReceiveRoster: self];
[rosterID release];
rosterID = nil;
}
}
- (XMPPJID*)JID
{
return [[JID copy] autorelease];
}
- (void)setPort: (uint16_t)port_
{
|