Example #1
0
ProfAccount*
account_new(const gchar * const name, const gchar * const jid,
    const gchar * const password, const gchar * eval_password, gboolean enabled, const gchar * const server,
    int port, const gchar * const resource, const gchar * const last_presence,
    const gchar * const login_presence, int priority_online, int priority_chat,
    int priority_away, int priority_xa, int priority_dnd,
    const gchar * const muc_service, const gchar * const muc_nick,
    const gchar * const otr_policy, GList *otr_manual, GList *otr_opportunistic,
    GList *otr_always)
{
    ProfAccount *new_account = malloc(sizeof(ProfAccount));

    new_account->name = strdup(name);

    if (jid) {
        new_account->jid = strdup(jid);
    } else {
        new_account->jid = strdup(name);
    }

    if (password) {
        new_account->password = strdup(password);
    } else {
        new_account->password = NULL;
    }

    if (eval_password) {
        new_account->eval_password = strdup(eval_password);
    } else {
        new_account->eval_password = NULL;
    }

    new_account->enabled = enabled;

    if (server) {
        new_account->server = strdup(server);
    } else {
        new_account->server = NULL;
    }

    if (resource) {
        new_account->resource = strdup(resource);
    } else {
        new_account->resource = NULL;
    }

    new_account->port = port;

    if (last_presence == NULL || !valid_resource_presence_string(last_presence)) {
        new_account->last_presence = strdup("online");
    } else {
        new_account->last_presence = strdup(last_presence);
    }

    if (login_presence == NULL) {
        new_account->login_presence = strdup("online");
    } else if (strcmp(login_presence, "last") == 0) {
        new_account->login_presence = strdup(login_presence);
    } else if (!valid_resource_presence_string(login_presence)) {
        new_account->login_presence = strdup("online");
    } else {
        new_account->login_presence = strdup(login_presence);
    }

    new_account->priority_online = priority_online;
    new_account->priority_chat = priority_chat;
    new_account->priority_away = priority_away;
    new_account->priority_xa = priority_xa;
    new_account->priority_dnd = priority_dnd;

    if (muc_service == NULL) {
        GString *g_muc_service = g_string_new("conference.");
        Jid *jidp = jid_create(new_account->jid);
        g_string_append(g_muc_service, jidp->domainpart);

        new_account->muc_service = g_muc_service->str;

        g_string_free(g_muc_service, FALSE);
        jid_destroy(jidp);
    } else {
        new_account->muc_service = strdup(muc_service);
    }

    if (muc_nick == NULL) {
        Jid *jidp = jid_create(new_account->jid);
        new_account->muc_nick = strdup(jidp->domainpart);
        jid_destroy(jidp);
    } else {
        new_account->muc_nick = strdup(muc_nick);
    }

    if (otr_policy) {
        new_account->otr_policy = strdup(otr_policy);
    } else {
        new_account->otr_policy = NULL;
    }

    new_account->otr_manual = otr_manual;
    new_account->otr_opportunistic = otr_opportunistic;
    new_account->otr_always = otr_always;

    return new_account;
}
Example #2
0
void test_unavailable_is_not_valid_resource_presence_string(void **state)
{
    assert_false(valid_resource_presence_string("unavailable"));
}
Example #3
0
void test_blah_is_not_valid_resource_presence_string(void **state)
{
    assert_false(valid_resource_presence_string("blah"));
}
Example #4
0
void test_dnd_is_valid_resource_presence_string(void **state)
{
    assert_true(valid_resource_presence_string("dnd"));
}
Example #5
0
void test_xa_is_valid_resource_presence_string(void **state)
{
    assert_true(valid_resource_presence_string("xa"));
}
Example #6
0
void test_away_is_valid_resource_presence_string(void **state)
{
    assert_true(valid_resource_presence_string("away"));
}
Example #7
0
void test_chat_is_valid_resource_presence_string(void **state)
{
    assert_true(valid_resource_presence_string("chat"));
}
Example #8
0
void test_online_is_valid_resource_presence_string(void **state)
{
    assert_true(valid_resource_presence_string("online"));
}