END_TEST START_TEST(test_get_bare_jid) { assert_string_equal_free("foo@bar", jabber_get_bare_jid("foo@bar")); assert_string_equal_free("foo@bar", jabber_get_bare_jid("foo@bar/baz")); assert_string_equal_free("bar", jabber_get_bare_jid("bar")); assert_string_equal_free("bar", jabber_get_bare_jid("bar/baz")); }
static void jabber_vcard_parse_avatar(JabberStream *js, const char *from, JabberIqType type, const char *id, xmlnode *packet, gpointer blah) { JabberBuddy *jb = NULL; xmlnode *vcard, *photo, *binval, *fn, *nick; char *text; if(!from) return; jb = jabber_buddy_find(js, from, TRUE); js->pending_avatar_requests = g_slist_remove(js->pending_avatar_requests, jb); if((vcard = xmlnode_get_child(packet, "vCard")) || (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) { /* The logic here regarding the nickname and full name is copied from * buddy.c:jabber_vcard_parse. */ gchar *nickname = NULL; if ((fn = xmlnode_get_child(vcard, "FN"))) nickname = xmlnode_get_data(fn); if ((nick = xmlnode_get_child(vcard, "NICKNAME"))) { char *tmp = xmlnode_get_data(nick); char *bare_jid = jabber_get_bare_jid(from); if (tmp && strstr(bare_jid, tmp) == NULL) { g_free(nickname); nickname = tmp; } else if (tmp) g_free(tmp); g_free(bare_jid); } if (nickname) { serv_got_alias(js->gc, from, nickname); g_free(nickname); } if ((photo = xmlnode_get_child(vcard, "PHOTO")) && (binval = xmlnode_get_child(photo, "BINVAL")) && (text = xmlnode_get_data(binval))) { guchar *data; gsize size; data = purple_base64_decode(text, &size); if (data) { gchar *hash = jabber_calculate_data_hash(data, size, "sha1"); purple_buddy_icons_set_for_user(js->gc->account, from, data, size, hash); g_free(hash); } g_free(text); } } }
static gboolean find_by_jid_ghr(gpointer key, gpointer value, gpointer user_data) { JingleSession *session = (JingleSession *)value; const gchar *jid = user_data; gboolean use_bare = strchr(jid, '/') == NULL; gchar *remote_jid = jingle_session_get_remote_jid(session); gchar *cmp_jid = use_bare ? jabber_get_bare_jid(remote_jid) : g_strdup(remote_jid); g_free(remote_jid); if (g_str_equal(jid, cmp_jid)) { g_free(cmp_jid); return TRUE; } g_free(cmp_jid); return FALSE; }
void jabber_roster_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) { JabberStream *js = gc->proto_data; char *who; JabberBuddy *jb; JabberBuddyResource *jbr; char *my_bare_jid; if(!js->roster_parsed) return; if(!(who = jabber_get_bare_jid(buddy->name))) return; jb = jabber_buddy_find(js, buddy->name, FALSE); jabber_roster_update(js, who, NULL); my_bare_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain); if(!strcmp(who, my_bare_jid)) { PurplePresence *gpresence; PurpleStatus *status; gpresence = purple_account_get_presence(js->gc->account); status = purple_presence_get_active_status(gpresence); jabber_presence_fake_to_self(js, status); } else if(!jb || !(jb->subscription & JABBER_SUB_TO)) { jabber_presence_subscription_set(js, who, "subscribe"); } else if((jbr =jabber_buddy_find_resource(jb, NULL))) { purple_prpl_got_user_status(gc->account, who, jabber_buddy_state_get_status_id(jbr->state), "priority", jbr->priority, jbr->status ? "message" : NULL, jbr->status, NULL); } g_free(my_bare_jid); g_free(who); }
static void jabber_gmail_parse(JabberStream *js, const char *from, JabberIqType type, const char *id, PurpleXmlNode *packet, gpointer nul) { PurpleXmlNode *child; PurpleXmlNode *message; const char *to, *url; const char *in_str; char *to_name; int i, count = 1, returned_count; const char **tos, **froms, **urls; char **subjects; if (type == JABBER_IQ_ERROR) return; child = purple_xmlnode_get_child(packet, "mailbox"); if (!child) return; in_str = purple_xmlnode_get_attrib(child, "total-matched"); if (in_str && *in_str) count = atoi(in_str); /* If Gmail doesn't tell us who the mail is to, let's use our JID */ to = purple_xmlnode_get_attrib(packet, "to"); message = purple_xmlnode_get_child(child, "mail-thread-info"); if (count == 0 || !message) { if (count > 0) { char *bare_jid = jabber_get_bare_jid(to); const char *default_tos[2] = { bare_jid }; purple_notify_emails(js->gc, count, FALSE, NULL, NULL, default_tos, NULL, NULL, NULL); g_free(bare_jid); } else { purple_notify_emails(js->gc, count, FALSE, NULL, NULL, NULL, NULL, NULL, NULL); } return; } /* Loop once to see how many messages were returned so we can allocate arrays * accordingly */ for (returned_count = 0; message; returned_count++, message=purple_xmlnode_get_next_twin(message)); froms = g_new0(const char* , returned_count + 1); tos = g_new0(const char* , returned_count + 1); subjects = g_new0(char* , returned_count + 1); urls = g_new0(const char* , returned_count + 1); to = purple_xmlnode_get_attrib(packet, "to"); to_name = jabber_get_bare_jid(to); url = purple_xmlnode_get_attrib(child, "url"); if (!url || !*url) url = "http://www.gmail.com"; message= purple_xmlnode_get_child(child, "mail-thread-info"); for (i=0; message; message = purple_xmlnode_get_next_twin(message), i++) { PurpleXmlNode *sender_node, *subject_node; const char *from, *tid; char *subject; subject_node = purple_xmlnode_get_child(message, "subject"); sender_node = purple_xmlnode_get_child(message, "senders"); sender_node = purple_xmlnode_get_child(sender_node, "sender"); while (sender_node && (!purple_xmlnode_get_attrib(sender_node, "unread") || !strcmp(purple_xmlnode_get_attrib(sender_node, "unread"),"0"))) sender_node = purple_xmlnode_get_next_twin(sender_node); if (!sender_node) { i--; continue; } from = purple_xmlnode_get_attrib(sender_node, "name"); if (!from || !*from) from = purple_xmlnode_get_attrib(sender_node, "address"); subject = purple_xmlnode_get_data(subject_node); /* * url = purple_xmlnode_get_attrib(message, "url"); */ tos[i] = (to_name != NULL ? to_name : ""); froms[i] = (from != NULL ? from : ""); subjects[i] = (subject != NULL ? subject : g_strdup("")); urls[i] = url; tid = purple_xmlnode_get_attrib(message, "tid"); if (tid && (js->gmail_last_tid == NULL || strcmp(tid, js->gmail_last_tid) > 0)) { g_free(js->gmail_last_tid); js->gmail_last_tid = g_strdup(tid); } } if (i>0) purple_notify_emails(js->gc, count, count == i, (const char**) subjects, froms, tos, urls, NULL, NULL); g_free(to_name); g_free(tos); g_free(froms); for (i = 0; i < returned_count; i++) g_free(subjects[i]); g_free(subjects); g_free(urls); in_str = purple_xmlnode_get_attrib(child, "result-time"); if (in_str && *in_str) { g_free(js->gmail_last_time); js->gmail_last_time = g_strdup(in_str); } }