Esempio n. 1
0
void remove_contact_with_remaining_in_group(void **state)
{
    roster_create();

    GSList *groups1 = NULL;
    groups1 = g_slist_append(groups1, strdup("friends"));
    groups1 = g_slist_append(groups1, strdup("work"));
    groups1 = g_slist_append(groups1, strdup("stuff"));
    roster_add("*****@*****.**", NULL, groups1, NULL, FALSE);

    GSList *groups2 = NULL;
    groups2 = g_slist_append(groups2, strdup("friends"));
    groups2 = g_slist_append(groups2, strdup("work"));
    groups2 = g_slist_append(groups2, strdup("different"));
    roster_add("*****@*****.**", NULL, groups2, NULL, FALSE);

    roster_remove("*****@*****.**", "*****@*****.**");

    GSList *groups_res = roster_get_groups();
    assert_int_equal(g_slist_length(groups_res), 3);

    GSList *found = g_slist_find_custom(groups_res, "friends", g_strcmp0);
    assert_true(found != NULL);
    found = g_slist_find_custom(groups_res, "work", g_strcmp0);
    assert_true(found != NULL);
    found = g_slist_find_custom(groups_res, "stuff", g_strcmp0);
    assert_true(found != NULL);

    g_slist_free_full(groups_res, g_free);
    roster_destroy();
}
Esempio n. 2
0
void add_remove_contact_groups(void **state)
{
    roster_create();

    GSList *groups1 = NULL;
    groups1 = g_slist_append(groups1, strdup("friends"));
    groups1 = g_slist_append(groups1, strdup("work"));
    groups1 = g_slist_append(groups1, strdup("stuff"));
    roster_add("*****@*****.**", NULL, groups1, NULL, FALSE);

    roster_remove("*****@*****.**", "*****@*****.**");

    GSList *groups_res = roster_get_groups();
    assert_int_equal(g_slist_length(groups_res), 0);

    g_slist_free_full(groups_res, g_free);
    roster_destroy();
}
Esempio n. 3
0
static int
_roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
    void * const userdata)
{
    xmpp_stanza_t *query =
        xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
    xmpp_stanza_t *item =
        xmpp_stanza_get_child_by_name(query, STANZA_NAME_ITEM);

    if (item == NULL) {
        return 1;
    }

    // if from attribute exists and it is not current users barejid, ignore push
    Jid *my_jid = jid_create(jabber_get_fulljid());
    const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
    if (from && (strcmp(from, my_jid->barejid) != 0)) {
        jid_destroy(my_jid);
        return 1;
    }
    jid_destroy(my_jid);

    const char *barejid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID);
    gchar *barejid_lower = g_utf8_strdown(barejid, -1);
    const char *name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME);
    const char *sub = xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION);
    const char *ask = xmpp_stanza_get_attribute(item, STANZA_ATTR_ASK);

    // do not set nickname to empty string, set to NULL instead
    if (name && (strlen(name) == 0)) {
        name = NULL;
    }

    // remove from roster
    if (g_strcmp0(sub, "remove") == 0) {
        // remove barejid and name
        if (name == NULL) {
            name = barejid_lower;
        }
        roster_remove(name, barejid_lower);
        ui_roster_remove(barejid_lower);

    // otherwise update local roster
    } else {

        // check for pending out subscriptions
        gboolean pending_out = FALSE;
        if (ask && (strcmp(ask, "subscribe") == 0)) {
            pending_out = TRUE;
        }

        GSList *groups = _get_groups_from_item(item);

        // update the local roster
        PContact contact = roster_get_contact(barejid_lower);
        if (contact == NULL) {
            gboolean added = roster_add(barejid_lower, name, groups, sub, pending_out);
            if (added) {
                ui_roster_add(barejid_lower, name);
            }
        } else {
            sv_ev_roster_update(barejid_lower, name, groups, sub, pending_out);
        }
    }

    g_free(barejid_lower);

    return 1;
}