ObjXMPP  Check-in [3e837ad25f]

Overview
Comment:Clean up roster handling
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3e837ad25fec669d20ceaf70d852bb296b34496e77e4e6c09ed962a952d5a41d
User & Date: florob@babelmonkeys.de on 2011-04-03 23:53:00
Other Links: manifest | tags
Context
2011-04-07
21:13
Split up XMPP_handleStanza.
Non-Stanzas are now handled in separate functions
check-in: ba3acce2ec user: florob@babelmonkeys.de tags: trunk
2011-04-03
23:53
Clean up roster handling check-in: 3e837ad25f user: florob@babelmonkeys.de tags: trunk
22:48
Handle roster pushs check-in: f6c4d76bfa user: florob@babelmonkeys.de tags: trunk
Changes

Modified src/XMPPConnection.h from [a00f7ad7b1] to [ec242ca1b0].

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62


63
64
65
66
67
68
69
48
49
50
51
52
53
54


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69







-
-






+
+







#ifdef OF_HAVE_OPTIONAL_PROTOCOLS
@optional
#endif
- (void)connectionWasAuthenticated: (XMPPConnection*)conn;
- (void)connection: (XMPPConnection*)conn
     wasBoundToJID: (XMPPJID*)jid;
- (void)connectionDidReceiveRoster: (XMPPConnection*)conn;
-     (void)connection: (XMPPConnection*)conn
  didReceiveRosterItem: (XMPPRosterItem*)rosterItem;
- (BOOL)connection: (XMPPConnection*)conn
      didReceiveIQ: (XMPPIQ*)iq;
-   (void)connection: (XMPPConnection*)conn
  didReceivePresence: (XMPPPresence*)pres;
-  (void)connection: (XMPPConnection*)conn
  didReceiveMessage: (XMPPMessage*)msg;
-     (void)connection: (XMPPConnection*)conn
  didReceiveRosterItem: (XMPPRosterItem*)rosterItem;
- (void)connectionWasClosed: (XMPPConnection*)conn;
- (void)connectionWillUpgradeToTLS: (XMPPConnection*)conn;
- (void)connectionDidUpgradeToTLS: (XMPPConnection*)conn;
@end

/**
 * \brief A class which abstracts a connection to an XMPP service.

Modified src/XMPPConnection.m from [50d3cf8f73] to [e6d90230b9].

646
647
648
649
650
651
652

653


654
655
656
657

658

659
660

661
662
663
664


665
666
667
668



669
670
671
672



673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731







732
733
734
735
736




737
738
739
740
741

742
743
744



745
746
747
748
749

750
751
752
753














754
755
756
757
758
759
760
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661

662


663
664
665


666
667




668
669
670
671



672
673
674
675












































676
677
678
679
680
681
682
683






684
685
686
687
688
689
690
691
692
693


694
695
696
697
698
699
700
701
702
703



704
705
706



707

708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733







+

+
+




+
-
+
-
-
+


-
-
+
+
-
-
-
-
+
+
+

-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








-
-
-
-
-
-
+
+
+
+
+
+
+



-
-
+
+
+
+





+
-
-
-
+
+
+
-
-
-

-
+




+
+
+
+
+
+
+
+
+
+
+
+
+
+







	[self sendStanza: iq];
}

- (void)XMPP_handleRoster: (XMPPIQ*)iq
{
	OFXMLElement *rosterElem;
	OFXMLElement *elem;
	XMPPRosterItem *rosterItem = nil;
	OFString *subscription;
	OFEnumerator *enumerator;
	BOOL isPush = ![[iq ID] isEqual: rosterID];

	rosterElem = [iq elementForName: @"query"
			      namespace: XMPP_NS_ROSTER];

	if (isPush)
	if ([[iq ID] isEqual: rosterID]) {
		assert([[iq type] isEqual: @"set"]);
		OFEnumerator *enumerator;

	else
		assert([[iq type] isEqual: @"result"]);

		enumerator = [[rosterElem children] objectEnumerator];
		while ((elem = [enumerator nextObject]) != nil) {
	enumerator = [[rosterElem children] objectEnumerator];
	while ((elem = [enumerator nextObject]) != nil) {
			XMPPRosterItem *rosterItem;
			OFMutableArray *groups = [OFMutableArray array];
			OFEnumerator *groupEnumerator;
			OFXMLElement *groupElem;
		OFMutableArray *groups = [OFMutableArray array];
		OFEnumerator *groupEnumerator;
		OFXMLElement *groupElem;

			if (![[elem name] isEqual: @"item"] ||
			    ![[elem namespace] isEqual: XMPP_NS_ROSTER])
				continue;
		if (![[elem name] isEqual: @"item"] ||
		    ![[elem namespace] isEqual: XMPP_NS_ROSTER])
			continue;

			rosterItem = [XMPPRosterItem rosterItem];
			[rosterItem setJID: [XMPPJID JIDWithString:
			    [[elem attributeForName: @"jid"] stringValue]]];
			[rosterItem setName:
			    [[elem attributeForName: @"name"] stringValue]];

			subscription = [[elem attributeForName:
				@"subscription"] stringValue];
			if ([subscription isEqual: @"none"] ||
			    [subscription isEqual: @"to"] ||
			    [subscription isEqual: @"from"] ||
			    [subscription isEqual: @"both"])
				[rosterItem setSubscription: subscription];

			groupEnumerator =
			    [[elem elementsForName: @"group"
					 namespace: XMPP_NS_ROSTER]
				objectEnumerator];
			while ((groupElem = [groupEnumerator nextObject])
					!= nil)
				[groups addObject: [groupElem stringValue]];

			if ([groups count] > 0)
				[rosterItem setGroups: groups];

			[roster XMPP_addRosterItem: rosterItem];
		}

		if ([delegate respondsToSelector:
		    @selector(connectionDidReceiveRoster:)])
			[delegate connectionDidReceiveRoster: self];

		[rosterID release];
		rosterID = nil;
	} else {
		XMPPRosterItem *rosterItem;
		OFMutableArray *groups = [OFMutableArray array];
		OFEnumerator *groupEnumerator;
		OFXMLElement *groupElem;
		XMPPIQ *response;

		assert([[iq type] isEqual: @"set"]);

		elem = [[rosterElem children] firstObject];
		rosterItem = [XMPPRosterItem rosterItem];
		[rosterItem setJID: [XMPPJID JIDWithString:
		    [[elem attributeForName: @"jid"] stringValue]]];
		[rosterItem setName:
		    [[elem attributeForName: @"name"] stringValue]];

		subscription = [[elem attributeForName:
			@"subscription"] stringValue];
		if ([subscription isEqual: @"none"] ||
		    [subscription isEqual: @"to"] ||
		    [subscription isEqual: @"from"] ||
		    [subscription isEqual: @"both"] ||
		    [subscription isEqual: @"remove"])
			[rosterItem setSubscription: subscription];
		if (![subscription isEqual: @"none"] &&
		    ![subscription isEqual: @"to"] &&
		    ![subscription isEqual: @"from"] &&
		    ![subscription isEqual: @"both"] &&
		    (![subscription isEqual: @"remove"] || !isPush))
			subscription = @"none";
		[rosterItem setSubscription: subscription];

		groupEnumerator =
		    [[elem elementsForName: @"group"
				 namespace: XMPP_NS_ROSTER] objectEnumerator];
		while ((groupElem = [groupEnumerator nextObject]) != nil)
				 namespace: XMPP_NS_ROSTER]
			objectEnumerator];
		while ((groupElem = [groupEnumerator nextObject])
				!= nil)
			[groups addObject: [groupElem stringValue]];

		if ([groups count] > 0)
			[rosterItem setGroups: groups];

		if ([subscription isEqual: @"remove"])
		[roster XMPP_updateRosterItem: rosterItem];

		response = [XMPPIQ IQWithType: @"result"
			[roster XMPP_deleteRosterItem: rosterItem];
		else
			[roster XMPP_addRosterItem: rosterItem];
					   ID: [iq ID]];
		[response setTo: [iq from]];
		[self sendStanza: response];

		if ([delegate respondsToSelector:
		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];
}

811
812
813
814
815
816
817





818
819
820
821
822
823
824
825
826
827
828
829
830
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







+
+
+
+
+













{
}

-  (void)connection: (XMPPConnection*)conn
  didReceiveMessage: (XMPPMessage*)msg
{
}

-     (void)connection: (XMPPConnection*)conn
  didReceiveRosterItem: (XMPPRosterItem*)rosterItem
{
}

- (void)connectionWasClosed: (XMPPConnection*)conn
{
}

- (void)connectionWillUpgradeToTLS: (XMPPConnection*)conn
{
}

- (void)connectionDidUpgradeToTLS: (XMPPConnection*)conn
{
}
@end

Modified tests/test.m from [aed1a6726e] to [03eb4d2c68].

119
120
121
122
123
124
125
126

127
128
129
130
131
132
133
119
120
121
122
123
124
125

126
127
128
129
130
131
132
133







-
+







     wasBoundToJID: (XMPPJID*)jid
{
	of_log(@"Bound to JID: %@", [jid fullJID]);

	[conn requestRoster];
}

- (void)connectionDidReceiveRoster :(XMPPConnection*)conn
- (void)connectionDidReceiveRoster: (XMPPConnection*)conn
{
	XMPPPresence *pres;

	of_log(@"Got roster: %@", [[conn roster] rosterItems]);

	pres = [XMPPPresence presence];
	[pres addPriority: 10];