Mercurial > pidgin
comparison libpurple/protocols/jabber/jabber.c @ 25175:b1b1b75a922e
Sprinkle jabber_resource_has_capability in places
Plug a small leak
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Wed, 26 Nov 2008 22:06:46 +0000 |
parents | 860ebaf275ae |
children | e1f363f8fd6b |
comparison
equal
deleted
inserted
replaced
25174:68bfc99884ea | 25175:b1b1b75a922e |
---|---|
2388 | 2388 |
2389 static gboolean _jabber_send_buzz(JabberStream *js, const char *username, char **error) { | 2389 static gboolean _jabber_send_buzz(JabberStream *js, const char *username, char **error) { |
2390 | 2390 |
2391 JabberBuddy *jb; | 2391 JabberBuddy *jb; |
2392 JabberBuddyResource *jbr; | 2392 JabberBuddyResource *jbr; |
2393 GList *iter; | |
2394 | 2393 |
2395 if(!username) | 2394 if(!username) |
2396 return FALSE; | 2395 return FALSE; |
2397 | 2396 |
2398 jb = jabber_buddy_find(js, username, FALSE); | 2397 jb = jabber_buddy_find(js, username, FALSE); |
2405 if(!jbr) { | 2404 if(!jbr) { |
2406 *error = g_strdup_printf(_("Unable to buzz, because user %s might be offline."), username); | 2405 *error = g_strdup_printf(_("Unable to buzz, because user %s might be offline."), username); |
2407 return FALSE; | 2406 return FALSE; |
2408 } | 2407 } |
2409 | 2408 |
2409 /* Is this message sufficiently useful to not just fold it in with the tail error condition below? */ | |
2410 if(!jbr->caps) { | 2410 if(!jbr->caps) { |
2411 *error = g_strdup_printf(_("Unable to buzz, because there is nothing known about user %s."), username); | 2411 *error = g_strdup_printf(_("Unable to buzz, because there is nothing known about user %s."), username); |
2412 return FALSE; | 2412 return FALSE; |
2413 } | 2413 } |
2414 | 2414 |
2415 for(iter = jbr->caps->features; iter; iter = g_list_next(iter)) { | 2415 if (jabber_resource_has_capability(jbr, "http://www.xmpp.org/extensions/xep-0224.html#ns")) { |
2416 if(!strcmp(iter->data, "http://www.xmpp.org/extensions/xep-0224.html#ns")) { | 2416 xmlnode *buzz, *msg = xmlnode_new("message"); |
2417 xmlnode *buzz, *msg = xmlnode_new("message"); | 2417 gchar *to; |
2418 gchar *to; | 2418 |
2419 | 2419 to = g_strdup_printf("%s/%s", username, jbr->name); |
2420 to = g_strdup_printf("%s/%s", username, jbr->name); | 2420 xmlnode_set_attrib(msg, "to", to); |
2421 xmlnode_set_attrib(msg, "to", to); | 2421 g_free(to); |
2422 g_free(to); | 2422 |
2423 | 2423 /* avoid offline storage */ |
2424 /* avoid offline storage */ | 2424 xmlnode_set_attrib(msg, "type", "headline"); |
2425 xmlnode_set_attrib(msg, "type", "headline"); | 2425 |
2426 | 2426 buzz = xmlnode_new_child(msg, "attention"); |
2427 buzz = xmlnode_new_child(msg, "attention"); | 2427 xmlnode_set_namespace(buzz, "http://www.xmpp.org/extensions/xep-0224.html#ns"); |
2428 xmlnode_set_namespace(buzz, "http://www.xmpp.org/extensions/xep-0224.html#ns"); | 2428 |
2429 | 2429 jabber_send(js, msg); |
2430 jabber_send(js, msg); | 2430 xmlnode_free(msg); |
2431 xmlnode_free(msg); | 2431 |
2432 | 2432 return TRUE; |
2433 return TRUE; | |
2434 } | |
2435 } | 2433 } |
2436 | 2434 |
2437 *error = g_strdup_printf(_("Unable to buzz, because the user %s does not support it."), username); | 2435 *error = g_strdup_printf(_("Unable to buzz, because the user %s does not support it."), username); |
2438 return FALSE; | 2436 return FALSE; |
2439 } | 2437 } |
2588 | 2586 |
2589 if (!purple_account_is_connected(account)) | 2587 if (!purple_account_is_connected(account)) |
2590 return FALSE; | 2588 return FALSE; |
2591 js = gc->proto_data; | 2589 js = gc->proto_data; |
2592 | 2590 |
2593 resource = jabber_get_resource(jid); | |
2594 if (!(resource = jabber_get_resource(jid)) || | 2591 if (!(resource = jabber_get_resource(jid)) || |
2595 !(jb = jabber_buddy_find(js, jid, FALSE)) || | 2592 !(jb = jabber_buddy_find(js, jid, FALSE)) || |
2596 !(jbr = jabber_buddy_find_resource(jb, resource))) { | 2593 !(jbr = jabber_buddy_find_resource(jb, resource))) { |
2597 g_free(resource); | 2594 g_free(resource); |
2598 return FALSE; | 2595 return FALSE; |
2599 } | 2596 } |
2600 | 2597 |
2601 g_free(resource); | 2598 g_free(resource); |
2602 | 2599 |
2603 if (!jbr->caps) { | 2600 return jabber_resource_has_capability(jbr, feature); |
2604 /* TODO: fetch them? */ | |
2605 return FALSE; | |
2606 } | |
2607 | |
2608 return NULL != g_list_find_custom(jbr->caps->features, feature, (GCompareFunc)strcmp); | |
2609 } | 2601 } |
2610 | 2602 |
2611 static void | 2603 static void |
2612 jabber_ipc_add_feature(const gchar *feature) | 2604 jabber_ipc_add_feature(const gchar *feature) |
2613 { | 2605 { |