ObjXMPP  Check-in [e6237b123a]

Overview
Comment:Implement roster versioning.
Still needs some testing.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e6237b123a9113e3548bb970f53aa16439b89db2ee65f2eee450b2c76aba92cf
User & Date: js on 2012-02-06 15:17:37
Other Links: manifest | tags
Context
2012-02-06
15:33
Fix a few bugs in roster versioning. check-in: 15caf24f36 user: js tags: trunk
15:17
Implement roster versioning.
Still needs some testing.
check-in: e6237b123a user: js tags: trunk
14:23
Prevent changing the data storage after the roster has been requested. check-in: 5f55161423 user: js tags: trunk
Changes

Modified src/XMPPConnection.h from [d3e9061da5] to [e187223fa5].

153
154
155
156
157
158
159
160

161
162
163
164
165
166
167
153
154
155
156
157
158
159

160
161
162
163
164
165
166
167







-
+







	OFString *language;
	XMPPMulticastDelegate *delegates;
	OFMutableDictionary *callbacks;
	XMPPAuthenticator *authModule;
	BOOL streamOpen;
	BOOL needsSession;
	BOOL encryptionRequired, encrypted;
	BOOL rosterVersioningSupported;
	BOOL supportsRosterVersioning;
	unsigned int lastID;
/// \endcond
}

#ifdef OF_HAVE_PROPERTIES
/// \brief The username to use for authentication
@property (copy) OFString *username;
192
193
194
195
196
197
198
199

200
201
202
203
204
205
206
192
193
194
195
196
197
198

199
200
201
202
203
204
205
206







-
+







/// \brief The socket used for the connection
@property (readonly, retain, getter=socket) OFTCPSocket *sock;
/// \brief Whether encryption is required
@property BOOL encryptionRequired;
/// \brief Whether the connection is encrypted
@property (readonly) BOOL encrypted;
/// \brief Whether roster versioning is supported
@property (readonly) BOOL rosterVersioningSupported;
@property (readonly) BOOL supportsRosterVersioning;
#endif

/**
 * \brief Creates a new autoreleased XMPPConnection.
 *
 * \return A new autoreleased XMPPConnection
 */
334
335
336
337
338
339
340
341

342
343
344
345
346
347
348
334
335
336
337
338
339
340

341
342
343
344
345
346
347
348







-
+







- (XMPPJID*)JID;
- (void)setPort: (uint16_t)port;
- (uint16_t)port;
- (void)setDataStorage: (id <XMPPStorage>)dataStorage;
- (id <XMPPStorage>)dataStorage;
- (void)setLanguage: (OFString*)language;
- (OFString*)language;
- (BOOL)rosterVersioningSupported;
- (BOOL)supportsRosterVersioning;

/// \cond internal
- (void)XMPP_startStream;
- (void)XMPP_handleStream: (OFXMLElement*)element;
- (void)XMPP_handleTLS: (OFXMLElement*)element;
- (void)XMPP_handleSASL: (OFXMLElement*)element;
- (void)XMPP_handleStanza: (OFXMLElement*)element;

Modified src/XMPPConnection.m from [1283f67a38] to [8901a6e637].

346
347
348
349
350
351
352
353

354
355

356
357
358
359
360
361
362
346
347
348
349
350
351
352

353
354

355
356
357
358
359
360
361
362







-
+

-
+







}

- (BOOL)streamOpen
{
	return streamOpen;
}

- (BOOL)rosterVersioningSupported
- (BOOL)supportsRosterVersioning
{
	return rosterVersioningSupported;
	return supportsRosterVersioning;
}

- (BOOL)checkCertificateAndGetReason: (OFString**)reason
{
	X509Certificate *cert;
	OFDictionary *SANs;
	BOOL serviceSpecific = NO;
848
849
850
851
852
853
854
855

856
857
858
859
860
861
862
848
849
850
851
852
853
854

855
856
857
858
859
860
861
862







-
+








	if (encryptionRequired && !encrypted)
		/* TODO: Find/create an exception to throw here */
		@throw [OFException exceptionWithClass: isa];

	if ([element elementForName: @"ver"
			  namespace: XMPP_NS_ROSTERVER] != nil)
		rosterVersioningSupported = YES;
		supportsRosterVersioning = YES;

	if (mechs != nil) {
		OFEnumerator *enumerator;
		OFXMLElement *mech;

		enumerator = [[mechs children] objectEnumerator];
		while ((mech = [enumerator nextObject]) != nil)

Modified src/XMPPRoster.h from [c00194e1a0] to [de7818a9b5].

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
143
144
145
146
147
148
149

150

151
152
153
154
155
156
157







-

-







 */
- (void)removeDelegate: (id <XMPPRosterDelegate>)delegate;

- (void)setDataStorage: (id <XMPPStorage>)dataStorage;
- (id <XMPPStorage>)dataStorage;

/// \cond internal
- (void)XMPP_addRosterItem: (XMPPRosterItem*)rosterItem;
- (void)XMPP_updateRosterItem: (XMPPRosterItem*)rosterItem;
- (void)XMPP_deleteRosterItem: (XMPPRosterItem*)rosterItem;
- (void)XMPP_handleInitialRosterForConnection: (XMPPConnection*)connection
				       withIQ: (XMPPIQ*)iq;
- (XMPPRosterItem*)XMPP_rosterItemWithXMLElement: (OFXMLElement*)element;
/// \endcond
@end

@interface OFObject (XMPPRosterDelegate) <XMPPRosterDelegate>

Modified src/XMPPRoster.m from [ab74131ad5] to [ffdcace8e3].

71
72
73
74
75
76
77

78
79
80
81
82

83
84















85
86
87
88
89
90
91
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
97
98
99
100
101
102
103
104
105
106







+





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







{
	return [[rosterItems copy] autorelease];
}

- (void)requestRoster
{
	XMPPIQ *iq;
	OFXMLElement *query;

	rosterRequested = YES;

	iq = [XMPPIQ IQWithType: @"get"
			     ID: [connection generateStanzaID]];

	[iq addChild: [OFXMLElement elementWithName: @"query"
					  namespace: XMPP_NS_ROSTER]];
	query = [OFXMLElement elementWithName: @"query"
				    namespace: XMPP_NS_ROSTER];

	if ([connection supportsRosterVersioning]) {
		OFString *ver = [dataStorage stringValueForPath: @"roster.ver"];

		if (ver == nil)
			ver = @"";

		[query addAttributeWithName: @"ver"
				stringValue: ver];
	}

	[iq addChild: query];

	[connection     sendIQ: iq
	    withCallbackObject: self
		      selector: @selector(XMPP_handleInitialRosterForConnection:
			withIQ:)];
}

- (BOOL)connection: (XMPPConnection*)connection_
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121














122
123
124
125
126
127
128
129
121
122
123
124
125
126
127









128
129
130
131
132
133
134
135
136
137
138
139
140
141

142
143
144
145
146
147
148







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








	element = [rosterElement elementForName: @"item"
				      namespace: XMPP_NS_ROSTER];

	if (element != nil) {
		rosterItem = [self XMPP_rosterItemWithXMLElement: element];

		if ([[rosterItem subscription] isEqual: @"remove"])
			[self XMPP_deleteRosterItem: rosterItem];
		else
			[self XMPP_addRosterItem: rosterItem];

		[delegates broadcastSelector: @selector(
						  roster:didReceiveRosterItem:)
				  withObject: self
				  withObject: rosterItem];
		[self XMPP_updateRosterItem: rosterItem];
	}

	if ([connection supportsRosterVersioning]) {
		OFString *ver =
		    [[rosterElement attributeForName: @"ver"] stringValue];
		[dataStorage setStringValue: ver
				    forPath: @"roster.ver"];
	}

	[delegates broadcastSelector: @selector(
					  roster:didReceiveRosterItem:)
			  withObject: self
			  withObject: rosterItem];
	}

	[connection_ sendStanza: [iq resultIQ]];

	return YES;
}

- (void)addRosterItem: (XMPPRosterItem*)rosterItem
199
200
201
202
203
204
205
206

207



208
209











210
211
212
213
214
215
216












217
218
219






220
221
222
223
224
225
226
218
219
220
221
222
223
224

225
226
227
228
229


230
231
232
233
234
235
236
237
238
239
240
241






242
243
244
245
246
247
248
249
250
251
252
253



254
255
256
257
258
259
260
261
262
263
264
265
266







-
+

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

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







}

- (id <XMPPStorage>)dataStorage
{
	return dataStorage;
}

- (void)XMPP_addRosterItem: (XMPPRosterItem*)rosterItem
- (void)XMPP_updateRosterItem: (XMPPRosterItem*)rosterItem
{
	if ([connection supportsRosterVersioning]) {
		OFMutableDictionary *items = [[[dataStorage dictionaryForPath:
		    @"roster.items"] mutableCopy] autorelease];
	return [self XMPP_updateRosterItem: rosterItem];
}

		if (![[rosterItem subscription] isEqual: @"remove"]) {
			OFMutableDictionary *item = [OFMutableDictionary
			    dictionaryWithKeysAndObjects:
			    @"JID", [[rosterItem JID] bareJID],
			    @"subscription", [rosterItem subscription],
			    nil];

			if ([rosterItem name] != nil)
				[item setObject: [rosterItem name]
					 forKey: @"name"];

- (void)XMPP_updateRosterItem: (XMPPRosterItem*)rosterItem
{
	[rosterItems setObject: rosterItem
			forKey: [[rosterItem JID] bareJID]];
}

			if ([rosterItem groups] != nil)
				[item setObject: [rosterItem groups]
					 forKey: @"groups"];

			[items setObject: item
				  forKey: [[rosterItem JID] bareJID]];
		} else
			[items removeObjectForKey: [[rosterItem JID] bareJID]];

		[dataStorage setDictionary: items
				   forPath: @"roster.items"];
	}
- (void)XMPP_deleteRosterItem: (XMPPRosterItem*)rosterItem
{
	[rosterItems removeObjectForKey: [[rosterItem JID] bareJID]];

	if (![[rosterItem subscription] isEqual: @"remove"])
		[rosterItems setObject: rosterItem
				forKey: [[rosterItem JID] bareJID]];
	else
		[rosterItems removeObjectForKey: [[rosterItem JID] bareJID]];
}

- (XMPPRosterItem*)XMPP_rosterItemWithXMLElement: (OFXMLElement*)element
{
	OFString *subscription;
	OFEnumerator *groupEnumerator;
	OFXMLElement *groupElement;
251
252
253
254
255
256
257
258

259
260
261
262
263
264

265
266
267




















268
269
270
271
272
273
274
275
276
277
278
279
280








281
282
283
284
285
286
287
291
292
293
294
295
296
297

298
299
300
301
302
303

304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336




337
338
339
340
341
342
343
344
345
346
347
348
349
350
351







-
+





-
+



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









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








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

	return rosterItem;
}

- (void)XMPP_handleInitialRosterForConnection: (XMPPConnection*)connection
- (void)XMPP_handleInitialRosterForConnection: (XMPPConnection*)connection_
				       withIQ: (XMPPIQ*)iq
{
	OFXMLElement *rosterElement;
	OFEnumerator *enumerator;
	OFXMLElement *element;
	XMPPRosterItem *rosterItem = nil;
	XMPPRosterItem *rosterItem;

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

	if ([connection supportsRosterVersioning]) {
		OFDictionary *items = [dataStorage
		    dictionaryForPath: @"roster.items"];
		OFEnumerator *enumerator = [items objectEnumerator];
		OFDictionary *item;

		while ((item = [enumerator nextObject]) != nil) {
			rosterItem = [XMPPRosterItem rosterItem];
			[rosterItem setJID: [XMPPJID JIDWithString:
			    [item objectForKey: @"JID"]]];
			[rosterItem setName: [item objectForKey: @"name"]];
			[rosterItem setSubscription:
			    [item objectForKey: @"subscription"]];
			[rosterItem setGroups: [item objectForKey: @"groups"]];

			[rosterItems setObject: rosterItem
					forKey: [[rosterItem JID] bareJID]];
		}
	}

	enumerator = [[rosterElement children] objectEnumerator];
	while ((element = [enumerator nextObject]) != nil) {
		if (![[element name] isEqual: @"item"] ||
		    ![[element namespace] isEqual: XMPP_NS_ROSTER])
			continue;

		rosterItem = [self XMPP_rosterItemWithXMLElement: element];

		if ([[rosterItem subscription] isEqual: @"remove"])
			[self XMPP_deleteRosterItem: rosterItem];
		else
			[self XMPP_addRosterItem: rosterItem];
		[self XMPP_updateRosterItem: rosterItem];
	}

	if ([connection supportsRosterVersioning]) {
		OFString *ver =
		    [[rosterElement attributeForName: @"ver"] stringValue];
		[dataStorage setStringValue: ver
				    forPath: @"roster.ver"];
	}

	[delegates broadcastSelector: @selector(rosterWasReceived:)
			  withObject: self];
}
@end

Modified src/XMPPRosterItem.m from [5ea2368c27] to [212a56ecab].

21
22
23
24
25
26
27


28
29
30
31
32
33
34
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36







+
+







 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#import "XMPPRosterItem.h"

#import <ObjFW/macros.h>

@implementation XMPPRosterItem
+ rosterItem
{
	return [[[self alloc] init] autorelease];
}

100
101
102
103
104
105
106
107

108
109
110
111
112
113
114

115
116
102
103
104
105
106
107
108

109


110
111
112
113

114
115
116







-
+
-
-




-
+


- (OFString*)subscription
{
	return [[subscription copy] autorelease];
}

- (void)setGroups: (OFArray*)groups_
{
	OFArray *old = groups;
	OF_SETTER(groups, groups_, YES, YES)
	groups = [groups_ copy];
	[old release];
}

- (OFArray*)groups
{
	return [[groups copy] autorelease];
	OF_GETTER(groups, YES)
}
@end