Mercurial > pidgin
comparison libgaim/protocols/jabber/iq.c @ 14294:8a6154a52b84
[gaim-migrate @ 16984]
get rid of some hardcoding of jabber IQ callbacks
this should let plugins add their own callbacks, I think
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Tue, 22 Aug 2006 18:28:00 +0000 |
parents | 60b1bc8dbf37 |
children | 8a2b571f9990 |
comparison
equal
deleted
inserted
replaced
14293:82373bb6a47a | 14294:8a6154a52b84 |
---|---|
32 | 32 |
33 #ifdef _WIN32 | 33 #ifdef _WIN32 |
34 #include "utsname.h" | 34 #include "utsname.h" |
35 #endif | 35 #endif |
36 | 36 |
37 GHashTable *iq_handlers = NULL; | |
38 | |
39 | |
37 JabberIq *jabber_iq_new(JabberStream *js, JabberIqType type) | 40 JabberIq *jabber_iq_new(JabberStream *js, JabberIqType type) |
38 { | 41 { |
39 JabberIq *iq; | 42 JabberIq *iq; |
40 | 43 |
41 iq = g_new0(JabberIq, 1); | 44 iq = g_new0(JabberIq, 1); |
248 { | 251 { |
249 JabberCallbackData *jcd; | 252 JabberCallbackData *jcd; |
250 xmlnode *query, *error, *x; | 253 xmlnode *query, *error, *x; |
251 const char *xmlns; | 254 const char *xmlns; |
252 const char *type, *id, *from; | 255 const char *type, *id, *from; |
256 JabberIqHandler *jih; | |
253 | 257 |
254 query = xmlnode_get_child(packet, "query"); | 258 query = xmlnode_get_child(packet, "query"); |
255 type = xmlnode_get_attrib(packet, "type"); | 259 type = xmlnode_get_attrib(packet, "type"); |
256 from = xmlnode_get_attrib(packet, "from"); | 260 from = xmlnode_get_attrib(packet, "from"); |
257 id = xmlnode_get_attrib(packet, "id"); | 261 id = xmlnode_get_attrib(packet, "id"); |
267 } | 271 } |
268 | 272 |
269 /* Apparently not, so lets see if we have a pre-defined handler */ | 273 /* Apparently not, so lets see if we have a pre-defined handler */ |
270 | 274 |
271 if(type && query && (xmlns = xmlnode_get_namespace(query))) { | 275 if(type && query && (xmlns = xmlnode_get_namespace(query))) { |
272 if(!strcmp(type, "set")) { | 276 if((jih = g_hash_table_lookup(iq_handlers, xmlns))) { |
273 if(!strcmp(xmlns, "jabber:iq:roster")) { | 277 jih(js, packet); |
274 jabber_roster_parse(js, packet); | |
275 return; | |
276 } else if(!strcmp(xmlns, "jabber:iq:oob")) { | |
277 jabber_oob_parse(js, packet); | |
278 return; | |
279 } else if(!strcmp(xmlns, "http://jabber.org/protocol/bytestreams")) { | |
280 jabber_bytestreams_parse(js, packet); | |
281 return; | |
282 } | |
283 } else if(!strcmp(type, "get")) { | |
284 if(!strcmp(xmlns, "jabber:iq:last")) { | |
285 jabber_iq_last_parse(js, packet); | |
286 return; | |
287 } else if(!strcmp(xmlns, "jabber:iq:time")) { | |
288 jabber_iq_time_parse(js, packet); | |
289 return; | |
290 } else if(!strcmp(xmlns, "jabber:iq:version")) { | |
291 jabber_iq_version_parse(js, packet); | |
292 return; | |
293 } else if(!strcmp(xmlns, "http://jabber.org/protocol/disco#info")) { | |
294 jabber_disco_info_parse(js, packet); | |
295 return; | |
296 } else if(!strcmp(xmlns, "http://jabber.org/protocol/disco#items")) { | |
297 jabber_disco_items_parse(js, packet); | |
298 return; | |
299 } | |
300 } else if(!strcmp(type, "result")) { | |
301 if(!strcmp(xmlns, "jabber:iq:roster")) { | |
302 jabber_roster_parse(js, packet); | |
303 return; | |
304 } else if(!strcmp(xmlns, "jabber:iq:register")) { | |
305 jabber_register_parse(js, packet); | |
306 return; | |
307 } else if(!strcmp(xmlns, "http://jabber.org/protocol/disco#info")) { | |
308 jabber_disco_info_parse(js, packet); | |
309 return; | |
310 } | |
311 } | |
312 } else { | |
313 if(xmlnode_get_child_with_namespace(packet, "si", "http://jabber.org/protocol/si")) { | |
314 jabber_si_parse(js, packet); | |
315 return; | 278 return; |
316 } | 279 } |
280 } | |
281 | |
282 | |
283 if(xmlnode_get_child_with_namespace(packet, "si", "http://jabber.org/protocol/si")) { | |
284 jabber_si_parse(js, packet); | |
285 return; | |
317 } | 286 } |
318 | 287 |
319 /* If we get here, send the default error reply mandated by XMPP-CORE */ | 288 /* If we get here, send the default error reply mandated by XMPP-CORE */ |
320 if(type && (!strcmp(type, "set") || !strcmp(type, "get"))) { | 289 if(type && (!strcmp(type, "set") || !strcmp(type, "get"))) { |
321 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_ERROR); | 290 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_ERROR); |
333 | 302 |
334 jabber_iq_send(iq); | 303 jabber_iq_send(iq); |
335 } | 304 } |
336 } | 305 } |
337 | 306 |
307 void jabber_iq_register_handler(const char *xmlns, JabberIqHandler handlerfunc) | |
308 { | |
309 g_hash_table_replace(iq_handlers, g_strdup(xmlns), handlerfunc); | |
310 } | |
311 | |
312 void jabber_iq_init(void) | |
313 { | |
314 iq_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); | |
315 | |
316 jabber_iq_register_handler("jabber:iq:roster", jabber_roster_parse); | |
317 jabber_iq_register_handler("jabber:iq:oob", jabber_oob_parse); | |
318 jabber_iq_register_handler("http://jabber.org/protocol/bytestreams", jabber_bytestreams_parse); | |
319 jabber_iq_register_handler("jabber:iq:last", jabber_iq_last_parse); | |
320 jabber_iq_register_handler("jabber:iq:time", jabber_iq_time_parse); | |
321 jabber_iq_register_handler("jabber:iq:version", jabber_iq_version_parse); | |
322 jabber_iq_register_handler("http://jabber.org/protocol/disco#info", jabber_disco_info_parse); | |
323 jabber_iq_register_handler("http://jabber.org/protocol/disco#items", jabber_disco_items_parse); | |
324 jabber_iq_register_handler("jabber:iq:register", jabber_register_parse); | |
325 } | |
326 | |
327 void jabber_iq_uninit(void) | |
328 { | |
329 g_hash_table_destroy(iq_handlers); | |
330 } | |
331 |