ObjXMPP  Check-in [f6c4d76bfa]

Overview
Comment:Handle roster pushs
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f6c4d76bfa14e6ac10c640a776acdcee4ffc8fbd74c77be7c40eb35f7dc9bc60
User & Date: florob@babelmonkeys.de on 2011-04-03 22:48:37
Other Links: manifest | tags
Context
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
11:48
Add two delegates for TLS upgrades.
This way, an OFStreamObserver can be used even with TLS.
check-in: 1faf025f1a user: js tags: trunk
Changes

Modified src/XMPPConnection.h from [6b484a50e7] to [a00f7ad7b1].

26
27
28
29
30
31
32

33
34
35
36
37
38
39
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40







+







@class XMPPConnection;
@class XMPPJID;
@class XMPPIQ;
@class XMPPMessage;
@class XMPPPresence;
@class XMPPAuthenticator;
@class XMPPRoster;
@class XMPPRosterItem;

#define XMPP_NS_BIND @"urn:ietf:params:xml:ns:xmpp-bind"
#define XMPP_NS_CLIENT @"jabber:client"
#define XMPP_NS_ROSTER @"jabber:iq:roster"
#define XMPP_NS_SASL @"urn:ietf:params:xml:ns:xmpp-sasl"
#define XMPP_NS_STARTTLS @"urn:ietf:params:xml:ns:xmpp-tls"
#define XMPP_NS_STANZAS @"urn:ietf:params:xml:ns:xmpp-stanzas"
47
48
49
50
51
52
53


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







+
+







#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)connectionWasClosed: (XMPPConnection*)conn;

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

433
434
435
436
437
438
439
440


441
442
443
444
445
446
447
433
434
435
436
437
438
439

440
441
442
443
444
445
446
447
448







-
+
+







	}

	if ([[iq ID] isEqual: sessionID]) {
		[self XMPP_handleSession: iq];
		return;
	}

	if ([[iq ID] isEqual: rosterID]) {
	if ([iq elementForName: @"query"
		     namespace: XMPP_NS_ROSTER]) {
		[self XMPP_handleRoster: iq];
		return;
	}

	if ([delegate respondsToSelector: @selector(connection:didReceiveIQ:)])
		handled = [delegate connection: self
				  didReceiveIQ: iq];
644
645
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
645
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







-

-
+
-




+
+
-
+
+

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




+

-
+
-
-

+





-
-
+
+
+
+
+
+
+
+
+










-
-
+
+
+
+
+
+

-
-
-
-
+
+
+
+
+
-
-







					  namespace: XMPP_NS_ROSTER]];
	[self sendStanza: iq];
}

- (void)XMPP_handleRoster: (XMPPIQ*)iq
{
	OFXMLElement *rosterElem;
	OFEnumerator *enumerator;
	OFXMLElement *elem;

	OFString *subscription;
	assert([[iq type] isEqual: @"result"]);

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

	if ([[iq ID] isEqual: rosterID]) {
		OFEnumerator *enumerator;
	assert(rosterElem != nil);

		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;

			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;

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

		elem = [[rosterElem children] firstObject];
		rosterItem = [XMPPRosterItem rosterItem];
		[rosterItem setJID: [XMPPJID JIDWithString:
		    [[elem attributeForName: @"jid"] stringValue]]];
		[rosterItem setName:
		    [[elem attributeForName: @"name"] stringValue]];
		[rosterItem setSubscription:
		    [[elem attributeForName: @"subscription"] 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];

		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];
	}
		[roster XMPP_updateRosterItem: rosterItem];

		response = [XMPPIQ IQWithType: @"result"
					   ID: [iq ID]];
		[response setTo: [iq from]];
		[self sendStanza: response];

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

		if ([delegate respondsToSelector:
		    @selector(connection:didReceiveRosterItem:)])
			[delegate connection:self
			didReceiveRosterItem: rosterItem];
	}
	[rosterID release];
	rosterID = nil;
}

- (XMPPJID*)JID
{
	return [[JID copy] autorelease];
}

Modified tests/test.m from [af27a5ba19] to [aed1a6726e].

131
132
133
134
135
136
137






138
139
140
141
142
143
144
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150







+
+
+
+
+
+








	pres = [XMPPPresence presence];
	[pres addPriority: 10];
	[pres addStatus: @"ObjXMPP test is working!"];

	[conn sendStanza: pres];
}

-     (void)connection: (XMPPConnection*)conn
  didReceiveRosterItem: (XMPPRosterItem*)rosterItem
{
	of_log(@"Got roster push: %@", rosterItem);
}

- (BOOL)connection: (XMPPConnection*)conn
      didReceiveIQ: (XMPPIQ*)iq
{
	of_log(@"IQ: %@", iq);

	return NO;