Mercurial > pidgin
comparison src/protocols/jabber/iq.c @ 8312:ba12d8b12ab0
[gaim-migrate @ 9036]
I think this is preliminary jabber file sending support. I can't test it
because the new network listening stuff is broken if you run both IPv4 and
IPv6. If someone with a more "normal" setup can let me know if this works,
I'd appreciate it. Note that it's not completely implemented yet, so sending
via a proxy server doesn't work, cancelling transfers doesn't work, error
handling isn't there, and it probably leaks memory. A sane person might even
wonder why I'm committing this. Oh well.
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Sat, 21 Feb 2004 23:59:49 +0000 |
parents | b5dbd1839716 |
children | db1123eb56b0 |
comparison
equal
deleted
inserted
replaced
8311:9e2b28acf1cd | 8312:ba12d8b12ab0 |
---|---|
21 #include "internal.h" | 21 #include "internal.h" |
22 #include "debug.h" | 22 #include "debug.h" |
23 #include "prefs.h" | 23 #include "prefs.h" |
24 | 24 |
25 #include "buddy.h" | 25 #include "buddy.h" |
26 #include "disco.h" | |
26 #include "iq.h" | 27 #include "iq.h" |
27 #include "oob.h" | 28 #include "oob.h" |
28 #include "roster.h" | 29 #include "roster.h" |
29 #include "si.h" | 30 #include "si.h" |
30 | 31 |
116 | 117 |
117 if(iq->id && iq->callback) { | 118 if(iq->id && iq->callback) { |
118 jcd = g_new0(JabberCallbackData, 1); | 119 jcd = g_new0(JabberCallbackData, 1); |
119 jcd->callback = iq->callback; | 120 jcd->callback = iq->callback; |
120 jcd->data = iq->callback_data; | 121 jcd->data = iq->callback_data; |
121 g_hash_table_insert(iq->js->callbacks, g_strdup(iq->id), jcd); | 122 g_hash_table_insert(iq->js->iq_callbacks, g_strdup(iq->id), jcd); |
122 } | 123 } |
123 | 124 |
124 jabber_iq_free(iq); | 125 jabber_iq_free(iq); |
125 } | 126 } |
126 | 127 |
131 g_free(iq->id); | 132 g_free(iq->id); |
132 xmlnode_free(iq->node); | 133 xmlnode_free(iq->node); |
133 g_free(iq); | 134 g_free(iq); |
134 } | 135 } |
135 | 136 |
136 static void jabber_iq_handle_last(JabberStream *js, xmlnode *packet) | 137 static void jabber_iq_last_parse(JabberStream *js, xmlnode *packet) |
137 { | 138 { |
138 JabberIq *iq; | 139 JabberIq *iq; |
139 const char *type; | 140 const char *type; |
140 const char *from; | 141 const char *from; |
141 const char *id; | 142 const char *id; |
159 | 160 |
160 jabber_iq_send(iq); | 161 jabber_iq_send(iq); |
161 } | 162 } |
162 } | 163 } |
163 | 164 |
164 static void jabber_iq_handle_time(JabberStream *js, xmlnode *packet) | 165 static void jabber_iq_time_parse(JabberStream *js, xmlnode *packet) |
165 { | 166 { |
166 const char *type, *from, *id; | 167 const char *type, *from, *id; |
167 JabberIq *iq; | 168 JabberIq *iq; |
168 char buf[1024]; | 169 char buf[1024]; |
169 xmlnode *query; | 170 xmlnode *query; |
193 | 194 |
194 jabber_iq_send(iq); | 195 jabber_iq_send(iq); |
195 } | 196 } |
196 } | 197 } |
197 | 198 |
198 static void jabber_iq_handle_version(JabberStream *js, xmlnode *packet) | 199 static void jabber_iq_version_parse(JabberStream *js, xmlnode *packet) |
199 { | 200 { |
200 JabberIq *iq; | 201 JabberIq *iq; |
201 const char *type, *from, *id; | 202 const char *type, *from, *id; |
202 xmlnode *query; | 203 xmlnode *query; |
203 char *os = NULL; | 204 char *os = NULL; |
232 | 233 |
233 jabber_iq_send(iq); | 234 jabber_iq_send(iq); |
234 } | 235 } |
235 } | 236 } |
236 | 237 |
237 #define SUPPORT_FEATURE(x) \ | |
238 feature = xmlnode_new_child(query, "feature"); \ | |
239 xmlnode_set_attrib(feature, "var", x); | |
240 | |
241 | |
242 void jabber_disco_info_parse(JabberStream *js, xmlnode *packet) { | |
243 const char *from = xmlnode_get_attrib(packet, "from"); | |
244 const char *type = xmlnode_get_attrib(packet, "type"); | |
245 | |
246 if(!from || !type) | |
247 return; | |
248 | |
249 if(!strcmp(type, "get")) { | |
250 xmlnode *query, *identity, *feature; | |
251 JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, | |
252 "http://jabber.org/protocol/disco#info"); | |
253 | |
254 jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id")); | |
255 | |
256 xmlnode_set_attrib(iq->node, "to", from); | |
257 query = xmlnode_get_child(iq->node, "query"); | |
258 | |
259 identity = xmlnode_new_child(query, "identity"); | |
260 xmlnode_set_attrib(identity, "category", "client"); | |
261 xmlnode_set_attrib(identity, "type", "pc"); /* XXX: bot, console, | |
262 * handheld, pc, phone, | |
263 * web */ | |
264 | |
265 SUPPORT_FEATURE("jabber:iq:last") | |
266 SUPPORT_FEATURE("jabber:iq:oob") | |
267 SUPPORT_FEATURE("jabber:iq:time") | |
268 SUPPORT_FEATURE("jabber:iq:version") | |
269 SUPPORT_FEATURE("jabber:x:conference") | |
270 SUPPORT_FEATURE("http://jabber.org/protocol/bytestreams") | |
271 SUPPORT_FEATURE("http://jabber.org/protocol/disco#info") | |
272 SUPPORT_FEATURE("http://jabber.org/protocol/disco#items") | |
273 #if 0 | |
274 SUPPORT_FEATURE("http://jabber.org/protocol/ibb") | |
275 #endif | |
276 SUPPORT_FEATURE("http://jabber.org/protocol/muc") | |
277 SUPPORT_FEATURE("http://jabber.org/protocol/muc#user") | |
278 SUPPORT_FEATURE("http://jabber.org/protocol/si") | |
279 SUPPORT_FEATURE("http://jabber.org/protocol/si/profile/file-transfer") | |
280 SUPPORT_FEATURE("http://jabber.org/protocol/xhtml-im") | |
281 | |
282 jabber_iq_send(iq); | |
283 } else if(!strcmp(type, "result")) { | |
284 xmlnode *query = xmlnode_get_child(packet, "query"); | |
285 xmlnode *child; | |
286 JabberID *jid; | |
287 JabberBuddy *jb; | |
288 JabberBuddyResource *jbr = NULL; | |
289 | |
290 if(!(jid = jabber_id_new(from))) | |
291 return; | |
292 | |
293 if(jid->resource && (jb = jabber_buddy_find(js, from, TRUE))) | |
294 jbr = jabber_buddy_find_resource(jb, jid->resource); | |
295 jabber_id_free(jid); | |
296 | |
297 for(child = query->child; child; child = child->next) { | |
298 if(child->type != XMLNODE_TYPE_TAG) | |
299 continue; | |
300 | |
301 if(!strcmp(child->name, "identity")) { | |
302 const char *category = xmlnode_get_attrib(child, "category"); | |
303 const char *type = xmlnode_get_attrib(child, "type"); | |
304 if(!category || !type) | |
305 continue; | |
306 | |
307 /* we found a groupchat or MUC server, add it to the list */ | |
308 /* XXX: actually check for protocol/muc or gc-1.0 support */ | |
309 if(!strcmp(category, "conference") && !strcmp(type, "text")) | |
310 js->chat_servers = g_list_append(js->chat_servers, g_strdup(from)); | |
311 | |
312 } else if(!strcmp(child->name, "feature")) { | |
313 const char *var = xmlnode_get_attrib(child, "var"); | |
314 if(!var) | |
315 continue; | |
316 | |
317 if(jbr && !strcmp(var, "http://jabber.org/protocol/si")) | |
318 jbr->capabilities |= JABBER_CAP_SI; | |
319 else if(jbr && !strcmp(var, | |
320 "http://jabber.org/protocol/si/profile/file-transfer")) | |
321 jbr->capabilities |= JABBER_CAP_SI_FILE_XFER; | |
322 else if(jbr && !strcmp(var, "http://jabber.org/protocol/bytestreams")) | |
323 jbr->capabilities |= JABBER_CAP_BYTESTREAMS; | |
324 } | |
325 } | |
326 } | |
327 } | |
328 | |
329 void jabber_disco_items_parse(JabberStream *js, xmlnode *packet) { | |
330 const char *from = xmlnode_get_attrib(packet, "from"); | |
331 const char *type = xmlnode_get_attrib(packet, "type"); | |
332 | |
333 if(!strcmp(type, "get")) { | |
334 JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_RESULT, | |
335 "http://jabber.org/protocol/disco#items"); | |
336 | |
337 jabber_iq_set_id(iq, xmlnode_get_attrib(packet, "id")); | |
338 | |
339 xmlnode_set_attrib(iq->node, "to", from); | |
340 jabber_iq_send(iq); | |
341 } | |
342 } | |
343 | |
344 static void | |
345 jabber_iq_disco_server_result_cb(JabberStream *js, xmlnode *packet, gpointer data) | |
346 { | |
347 xmlnode *query, *child; | |
348 const char *from = xmlnode_get_attrib(packet, "from"); | |
349 const char *type = xmlnode_get_attrib(packet, "type"); | |
350 | |
351 if(!from || !type) | |
352 return; | |
353 | |
354 if(strcmp(from, js->user->domain)) | |
355 return; | |
356 | |
357 if(strcmp(type, "result")) | |
358 return; | |
359 | |
360 while(js->chat_servers) { | |
361 g_free(js->chat_servers->data); | |
362 js->chat_servers = g_list_delete_link(js->chat_servers, js->chat_servers); | |
363 } | |
364 | |
365 query = xmlnode_get_child(packet, "query"); | |
366 | |
367 for(child = xmlnode_get_child(query, "item"); child; | |
368 child = xmlnode_get_next_twin(child)) { | |
369 JabberIq *iq; | |
370 const char *jid; | |
371 | |
372 if(!(jid = xmlnode_get_attrib(child, "jid"))) | |
373 continue; | |
374 | |
375 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#info"); | |
376 xmlnode_set_attrib(iq->node, "to", jid); | |
377 jabber_iq_send(iq); | |
378 } | |
379 } | |
380 | |
381 void jabber_iq_disco_server(JabberStream *js) | |
382 { | |
383 JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_GET, | |
384 "http://jabber.org/protocol/disco#items"); | |
385 | |
386 xmlnode_set_attrib(iq->node, "to", js->user->domain); | |
387 | |
388 jabber_iq_set_callback(iq, jabber_iq_disco_server_result_cb, NULL); | |
389 jabber_iq_send(iq); | |
390 } | |
391 | |
392 | |
393 void jabber_iq_parse(JabberStream *js, xmlnode *packet) | 238 void jabber_iq_parse(JabberStream *js, xmlnode *packet) |
394 { | 239 { |
395 JabberCallbackData *jcd; | 240 JabberCallbackData *jcd; |
396 xmlnode *query, *error, *x; | 241 xmlnode *query, *error, *x; |
397 const char *xmlns; | 242 const char *xmlns; |
399 JabberIq *iq; | 244 JabberIq *iq; |
400 | 245 |
401 query = xmlnode_get_child(packet, "query"); | 246 query = xmlnode_get_child(packet, "query"); |
402 type = xmlnode_get_attrib(packet, "type"); | 247 type = xmlnode_get_attrib(packet, "type"); |
403 from = xmlnode_get_attrib(packet, "from"); | 248 from = xmlnode_get_attrib(packet, "from"); |
249 id = xmlnode_get_attrib(packet, "id"); | |
250 | |
251 /* First, lets see if a special callback got registered */ | |
252 | |
253 if(type && (!strcmp(type, "result") || !strcmp(type, "error"))) { | |
254 if(id && *id && (jcd = g_hash_table_lookup(js->iq_callbacks, id))) { | |
255 jcd->callback(js, packet, jcd->data); | |
256 g_hash_table_remove(js->iq_callbacks, id); | |
257 } | |
258 return; | |
259 } | |
260 | |
261 /* Apparently not, so lets see if we have a pre-defined handler */ | |
404 | 262 |
405 if(type && query && (xmlns = xmlnode_get_attrib(query, "xmlns"))) { | 263 if(type && query && (xmlns = xmlnode_get_attrib(query, "xmlns"))) { |
406 if(!strcmp(type, "set")) { | 264 if(!strcmp(type, "set")) { |
407 if(!strcmp(xmlns, "jabber:iq:roster")) { | 265 if(!strcmp(xmlns, "jabber:iq:roster")) { |
408 jabber_roster_parse(js, packet); | 266 jabber_roster_parse(js, packet); |
414 jabber_bytestreams_parse(js, packet); | 272 jabber_bytestreams_parse(js, packet); |
415 return; | 273 return; |
416 } | 274 } |
417 } else if(!strcmp(type, "get")) { | 275 } else if(!strcmp(type, "get")) { |
418 if(!strcmp(xmlns, "jabber:iq:last")) { | 276 if(!strcmp(xmlns, "jabber:iq:last")) { |
419 jabber_iq_handle_last(js, packet); | 277 jabber_iq_last_parse(js, packet); |
420 return; | 278 return; |
421 } else if(!strcmp(xmlns, "jabber:iq:time")) { | 279 } else if(!strcmp(xmlns, "jabber:iq:time")) { |
422 jabber_iq_handle_time(js, packet); | 280 jabber_iq_time_parse(js, packet); |
423 return; | 281 return; |
424 } else if(!strcmp(xmlns, "jabber:iq:version")) { | 282 } else if(!strcmp(xmlns, "jabber:iq:version")) { |
425 jabber_iq_handle_version(js, packet); | 283 jabber_iq_version_parse(js, packet); |
426 return; | 284 return; |
427 } else if(!strcmp(xmlns, "http://jabber.org/protocol/disco#info")) { | 285 } else if(!strcmp(xmlns, "http://jabber.org/protocol/disco#info")) { |
428 jabber_disco_info_parse(js, packet); | 286 jabber_disco_info_parse(js, packet); |
429 return; | 287 return; |
430 } else if(!strcmp(xmlns, "http://jabber.org/protocol/disco#items")) { | 288 } else if(!strcmp(xmlns, "http://jabber.org/protocol/disco#items")) { |
442 jabber_disco_info_parse(js, packet); | 300 jabber_disco_info_parse(js, packet); |
443 return; | 301 return; |
444 } | 302 } |
445 } | 303 } |
446 } else { | 304 } else { |
447 xmlnode *si; | 305 if(xmlnode_get_child_with_namespace(packet, "si", "http://jabber.org/protocol/si")) { |
448 if((si = xmlnode_get_child(packet, "si")) && (xmlns = xmlnode_get_attrib(si, "xmlns")) && | |
449 !strcmp(xmlns, "http://jabber.org/protocol/si")) { | |
450 jabber_si_parse(js, packet); | 306 jabber_si_parse(js, packet); |
451 return; | 307 return; |
452 } | 308 } |
453 } | 309 } |
454 | 310 |
455 /* If we got here, no pre-defined handlers got it, lets see if a special | 311 |
456 * callback got registered */ | 312 /* If we get here, send the default error reply mandated by XMPP-CORE */ |
457 | |
458 id = xmlnode_get_attrib(packet, "id"); | |
459 | |
460 if(type && (!strcmp(type, "result") || !strcmp(type, "error"))) { | |
461 if(id && *id && (jcd = g_hash_table_lookup(js->callbacks, id))) { | |
462 jcd->callback(js, packet, jcd->data); | |
463 g_hash_table_remove(js->callbacks, id); | |
464 } | |
465 return; | |
466 } | |
467 | |
468 /* Default error reply mandated by XMPP-CORE */ | |
469 | 313 |
470 iq = jabber_iq_new(js, JABBER_IQ_ERROR); | 314 iq = jabber_iq_new(js, JABBER_IQ_ERROR); |
471 | 315 |
472 xmlnode_free(iq->node); | 316 xmlnode_free(iq->node); |
473 iq->node = xmlnode_copy(packet); | 317 iq->node = xmlnode_copy(packet); |