ObjXMPP  Diff

Differences From Artifact [ab74131ad5]:

To Artifact [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