예제 #1
0
void
accounts_set_login_presence(const char *const account_name, const char *const value)
{
    if (accounts_account_exists(account_name)) {
        g_key_file_set_string(accounts, account_name, "presence.login", value);
        _save_accounts();
    }
}
예제 #2
0
void
accounts_set_tls_policy(const char *const account_name, const char *const value)
{
    if (accounts_account_exists(account_name)) {
        g_key_file_set_string(accounts, account_name, "tls.policy", value);
        _save_accounts();
    }
}
예제 #3
0
void
accounts_set_pgp_keyid(const char *const account_name, const char *const value)
{
    if (accounts_account_exists(account_name)) {
        g_key_file_set_string(accounts, account_name, "pgp.keyid", value);
        _save_accounts();
    }
}
예제 #4
0
void
accounts_clear_otr(const char *const account_name)
{
    if (accounts_account_exists(account_name)) {
        g_key_file_remove_key(accounts, account_name, "otr.policy", NULL);
        _save_accounts();
    }
}
예제 #5
0
void
accounts_set_muc_nick(const char *const account_name, const char *const value)
{
    if (accounts_account_exists(account_name)) {
        g_key_file_set_string(accounts, account_name, "muc.nick", value);
        _save_accounts();
    }
}
예제 #6
0
void
accounts_clear_muc(const char *const account_name)
{
    if (accounts_account_exists(account_name)) {
        g_key_file_remove_key(accounts, account_name, "muc.service", NULL);
        _save_accounts();
    }
}
예제 #7
0
void
accounts_clear_resource(const char *const account_name)
{
    if (accounts_account_exists(account_name)) {
        g_key_file_remove_key(accounts, account_name, "resource", NULL);
        _save_accounts();
    }
}
예제 #8
0
void
accounts_clear_eval_password(const char *const account_name)
{
    if (accounts_account_exists(account_name)) {
        g_key_file_remove_key(accounts, account_name, "eval_password", NULL);
        _save_accounts();
    }
}
예제 #9
0
static void
_accounts_set_priority_online(const char * const account_name, const gint value)
{
    if (accounts_account_exists(account_name)) {
        g_key_file_set_integer(accounts, account_name, "priority.online", value);
        _save_accounts();
    }
}
예제 #10
0
static void
_accounts_set_otr_policy(const char * const account_name, const char * const value)
{
    if (accounts_account_exists(account_name)) {
        g_key_file_set_string(accounts, account_name, "otr.policy", value);
        _save_accounts();
    }
}
예제 #11
0
void
accounts_clear_pgp_keyid(const char *const account_name)
{
    if (accounts_account_exists(account_name)) {
        g_key_file_remove_key(accounts, account_name, "pgp.keyid", NULL);
        _save_accounts();
    }
}
예제 #12
0
void
accounts_set_priority_dnd(const char *const account_name, const gint value)
{
    if (accounts_account_exists(account_name)) {
        g_key_file_set_integer(accounts, account_name, "priority.dnd", value);
        _save_accounts();
    }
}
예제 #13
0
void
accounts_set_eval_password(const char *const account_name, const char *const value)
{
    if (accounts_account_exists(account_name)) {
        g_key_file_set_string(accounts, account_name, "eval_password", value);
        _save_accounts();
    }
}
예제 #14
0
void
accounts_set_resource(const char *const account_name, const char *const value)
{
    if (accounts_account_exists(account_name)) {
        g_key_file_set_string(accounts, account_name, "resource", value);
        _save_accounts();
    }
}
예제 #15
0
void
accounts_clear_server(const char *const account_name)
{
    if (accounts_account_exists(account_name)) {
        g_key_file_remove_key(accounts, account_name, "server", NULL);
        _save_accounts();
    }
}
예제 #16
0
void
accounts_set_port(const char *const account_name, const int value)
{
    if (value != 0) {
        g_key_file_set_integer(accounts, account_name, "port", value);
        _save_accounts();
    }
}
예제 #17
0
void
accounts_clear_script_start(const char *const account_name)
{
    if (accounts_account_exists(account_name)) {
        g_key_file_remove_key(accounts, account_name, "script.start", NULL);
        _save_accounts();
    }
}
예제 #18
0
static void
_accounts_set_muc_service(const char * const account_name, const char * const value)
{
    if (accounts_account_exists(account_name)) {
        g_key_file_set_string(accounts, account_name, "muc.service", value);
        _save_accounts();
    }
}
예제 #19
0
void
accounts_set_script_start(const char *const account_name, const char *const value)
{
    if (accounts_account_exists(account_name)) {
        g_key_file_set_string(accounts, account_name, "script.start", value);
        _save_accounts();
    }
}
예제 #20
0
int
accounts_remove(const char *account_name)
{
    int r = g_key_file_remove_group(accounts, account_name, NULL);
    _save_accounts();
    autocomplete_remove(all_ac, account_name);
    autocomplete_remove(enabled_ac, account_name);
    return r;
}
예제 #21
0
void
accounts_add(const char *account_name, const char *altdomain, const int port, const char *const tls_policy)
{
    // set account name and resource
    const char *barejid = account_name;
    const char *resource = "profanity";
    Jid *jid = jid_create(account_name);
    if (jid) {
        barejid = jid->barejid;
        if (jid->resourcepart) {
            resource = jid->resourcepart;
        }
    }

    // doesn't yet exist
    if (!g_key_file_has_group(accounts, account_name)) {
        g_key_file_set_boolean(accounts, account_name, "enabled", TRUE);
        g_key_file_set_string(accounts, account_name, "jid", barejid);
        g_key_file_set_string(accounts, account_name, "resource", resource);
        if (altdomain) {
            g_key_file_set_string(accounts, account_name, "server", altdomain);
        }
        if (port != 0) {
            g_key_file_set_integer(accounts, account_name, "port", port);
        }
        if (tls_policy) {
            g_key_file_set_string(accounts, account_name, "tls.policy", tls_policy);
        }

        Jid *jidp = jid_create(barejid);
        GString *muc_service = g_string_new("conference.");
        g_string_append(muc_service, jidp->domainpart);
        g_key_file_set_string(accounts, account_name, "muc.service", muc_service->str);
        g_string_free(muc_service, TRUE);
        if (jidp->localpart == NULL) {
            g_key_file_set_string(accounts, account_name, "muc.nick", jidp->domainpart);
        } else {
            g_key_file_set_string(accounts, account_name, "muc.nick", jidp->localpart);
        }
        jid_destroy(jidp);

        g_key_file_set_string(accounts, account_name, "presence.last", "online");
        g_key_file_set_string(accounts, account_name, "presence.login", "online");
        g_key_file_set_integer(accounts, account_name, "priority.online", 0);
        g_key_file_set_integer(accounts, account_name, "priority.chat", 0);
        g_key_file_set_integer(accounts, account_name, "priority.away", 0);
        g_key_file_set_integer(accounts, account_name, "priority.xa", 0);
        g_key_file_set_integer(accounts, account_name, "priority.dnd", 0);

        _save_accounts();
        autocomplete_add(all_ac, account_name);
        autocomplete_add(enabled_ac, account_name);
    }

    jid_destroy(jid);
}
예제 #22
0
void
accounts_set_last_status(const char *const account_name, const char *const value)
{
    if (accounts_account_exists(account_name)) {
        if (value) {
            g_key_file_set_string(accounts, account_name, "presence.laststatus", value);
        } else {
            g_key_file_remove_key(accounts, account_name, "presence.laststatus", NULL);
        }
        _save_accounts();
    }
}
예제 #23
0
gboolean
accounts_disable(const char *const name)
{
    if (g_key_file_has_group(accounts, name)) {
        g_key_file_set_boolean(accounts, name, "enabled", FALSE);
        _save_accounts();
        autocomplete_remove(enabled_ac, name);
        return TRUE;
    } else {
        return FALSE;
    }
}
예제 #24
0
void
accounts_set_priority_all(const char *const account_name, const gint value)
{
    if (accounts_account_exists(account_name)) {
        accounts_set_priority_online(account_name, value);
        accounts_set_priority_chat(account_name, value);
        accounts_set_priority_away(account_name, value);
        accounts_set_priority_xa(account_name, value);
        accounts_set_priority_dnd(account_name, value);
        _save_accounts();
    }
}
예제 #25
0
static gboolean
_accounts_rename(const char * const account_name, const char * const new_name)
{
    if (g_key_file_has_group(accounts, new_name)) {
        return FALSE;
    }

    if (!g_key_file_has_group(accounts, account_name)) {
        return FALSE;
    }

    g_key_file_set_boolean(accounts, new_name, "enabled",
        g_key_file_get_boolean(accounts, account_name, "enabled", NULL));

    g_key_file_set_integer(accounts, new_name, "priority.online",
        g_key_file_get_integer(accounts, account_name, "priority.online", NULL));
    g_key_file_set_integer(accounts, new_name, "priority.chat",
        g_key_file_get_integer(accounts, account_name, "priority.chat", NULL));
    g_key_file_set_integer(accounts, new_name, "priority.away",
        g_key_file_get_integer(accounts, account_name, "priority.away", NULL));
    g_key_file_set_integer(accounts, new_name, "priority.xa",
        g_key_file_get_integer(accounts, account_name, "priority.xa", NULL));
    g_key_file_set_integer(accounts, new_name, "priority.dnd",
        g_key_file_get_integer(accounts, account_name, "priority.dnd", NULL));

    // copy other string properties
    int i;
    for (i = 0; i < ARRAY_SIZE(string_keys); i++) {
        char *value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL);
        if (value != NULL) {
            g_key_file_set_string(accounts, new_name, string_keys[i], value);
            g_free(value);
        }
    }

    g_key_file_remove_group(accounts, account_name, NULL);
    _save_accounts();

    autocomplete_remove(all_ac, account_name);
    autocomplete_add(all_ac, new_name);
    if (g_key_file_get_boolean(accounts, new_name, "enabled", NULL)) {
        autocomplete_remove(enabled_ac, account_name);
        autocomplete_add(enabled_ac, new_name);
    }

    return TRUE;
}
예제 #26
0
void
accounts_set_last_activity(const char *const account_name)
{
    if (accounts_account_exists(account_name)) {
        GDateTime *nowdt = g_date_time_new_now_utc();
        GTimeVal nowtv;
        gboolean res = g_date_time_to_timeval(nowdt, &nowtv);
        g_date_time_unref(nowdt);

        if (res) {
            char *timestr = g_time_val_to_iso8601(&nowtv);
            g_key_file_set_string(accounts, account_name, "last.activity", timestr);
            free(timestr);
            _save_accounts();
        }
    }
}
예제 #27
0
void
accounts_set_jid(const char *const account_name, const char *const value)
{
    Jid *jid = jid_create(value);
    if (jid) {
        if (accounts_account_exists(account_name)) {
            g_key_file_set_string(accounts, account_name, "jid", jid->barejid);
            if (jid->resourcepart) {
                g_key_file_set_string(accounts, account_name, "resource", jid->resourcepart);
            }

            if (jid->localpart == NULL) {
                g_key_file_set_string(accounts, account_name, "muc.nick", jid->domainpart);
            } else {
                g_key_file_set_string(accounts, account_name, "muc.nick", jid->localpart);
            }

            _save_accounts();
        }

        jid_destroy(jid);
    }
}
예제 #28
0
void
accounts_add_otr_policy(const char *const account_name, const char *const contact_jid, const char *const policy)
{
    if (accounts_account_exists(account_name)) {
        GString *key = g_string_new("otr.");
        g_string_append(key, policy);
        gsize length;
        gchar **list = g_key_file_get_string_list(accounts, account_name, key->str, &length, NULL);
        GList *glist = NULL;

        // list found
        if (list) {
            int i = 0;
            for (i = 0; i < length; i++) {
                // item already in list, exit function
                if (strcmp(list[i], contact_jid) == 0) {
                    g_list_free_full(glist, g_free);
                    g_strfreev(list);
                    return;
                }
                // add item to our g_list
                glist = g_list_append(glist, strdup(list[i]));
            }

            // item not found, add to our g_list
            glist = g_list_append(glist, strdup(contact_jid));

            // create the new list entry
            const gchar* new_list[g_list_length(glist)+1];
            GList *curr = glist;
            i = 0;
            while (curr) {
                new_list[i++] = strdup(curr->data);
                curr = g_list_next(curr);
            }
            new_list[i] = NULL;
            g_key_file_set_string_list(accounts, account_name, key->str, new_list, g_list_length(glist));

        // list not found
        } else {
            const gchar* new_list[2];
            new_list[0] = strdup(contact_jid);
            new_list[1] = NULL;
            g_key_file_set_string_list(accounts, account_name, key->str, new_list, 1);
        }

        g_strfreev(list);
        g_list_free_full(glist, g_free);
        g_string_free(key, TRUE);

        // check for and remove from other lists
        if (strcmp(policy, "manual") == 0) {
            _remove_from_list(accounts, account_name, "otr.opportunistic", contact_jid);
            _remove_from_list(accounts, account_name, "otr.always", contact_jid);
        }
        if (strcmp(policy, "opportunistic") == 0) {
            _remove_from_list(accounts, account_name, "otr.manual", contact_jid);
            _remove_from_list(accounts, account_name, "otr.always", contact_jid);
        }
        if (strcmp(policy, "always") == 0) {
            _remove_from_list(accounts, account_name, "otr.opportunistic", contact_jid);
            _remove_from_list(accounts, account_name, "otr.manual", contact_jid);
        }

        _save_accounts();
    }
}
예제 #29
0
ProfAccount*
accounts_get_account(const char *const name)
{
    if (!g_key_file_has_group(accounts, name)) {
        return NULL;
    } else {
        gchar *jid = g_key_file_get_string(accounts, name, "jid", NULL);

        // fix accounts that have no jid property by setting to name
        if (jid == NULL) {
            g_key_file_set_string(accounts, name, "jid", name);
            _save_accounts();
        }

        gchar *password = g_key_file_get_string(accounts, name, "password", NULL);
        gchar *eval_password = g_key_file_get_string(accounts, name, "eval_password", NULL);
        gboolean enabled = g_key_file_get_boolean(accounts, name, "enabled", NULL);

        gchar *server = g_key_file_get_string(accounts, name, "server", NULL);
        gchar *resource = g_key_file_get_string(accounts, name, "resource", NULL);
        int port = g_key_file_get_integer(accounts, name, "port", NULL);

        gchar *last_presence = g_key_file_get_string(accounts, name, "presence.last", NULL);
        gchar *login_presence = g_key_file_get_string(accounts, name, "presence.login", NULL);

        int priority_online = g_key_file_get_integer(accounts, name, "priority.online", NULL);
        int priority_chat = g_key_file_get_integer(accounts, name, "priority.chat", NULL);
        int priority_away = g_key_file_get_integer(accounts, name, "priority.away", NULL);
        int priority_xa = g_key_file_get_integer(accounts, name, "priority.xa", NULL);
        int priority_dnd = g_key_file_get_integer(accounts, name, "priority.dnd", NULL);

        gchar *muc_service = g_key_file_get_string(accounts, name, "muc.service", NULL);
        gchar *muc_nick = g_key_file_get_string(accounts, name, "muc.nick", NULL);

        gchar *otr_policy = NULL;
        if (g_key_file_has_key(accounts, name, "otr.policy", NULL)) {
            otr_policy = g_key_file_get_string(accounts, name, "otr.policy", NULL);
        }

        gsize length;
        GList *otr_manual = NULL;
        gchar **manual = g_key_file_get_string_list(accounts, name, "otr.manual", &length, NULL);
        if (manual) {
            int i = 0;
            for (i = 0; i < length; i++) {
                otr_manual = g_list_append(otr_manual, strdup(manual[i]));
            }
            g_strfreev(manual);
        }

        GList *otr_opportunistic = NULL;
        gchar **opportunistic = g_key_file_get_string_list(accounts, name, "otr.opportunistic", &length, NULL);
        if (opportunistic) {
            int i = 0;
            for (i = 0; i < length; i++) {
                otr_opportunistic = g_list_append(otr_opportunistic, strdup(opportunistic[i]));
            }
            g_strfreev(opportunistic);
        }

        GList *otr_always = NULL;
        gchar **always = g_key_file_get_string_list(accounts, name, "otr.always", &length, NULL);
        if (always) {
            int i = 0;
            for (i = 0; i < length; i++) {
                otr_always = g_list_append(otr_always, strdup(always[i]));
            }
            g_strfreev(always);
        }

        gchar *pgp_keyid = NULL;
        if (g_key_file_has_key(accounts, name, "pgp.keyid", NULL)) {
            pgp_keyid = g_key_file_get_string(accounts, name, "pgp.keyid", NULL);
        }

        gchar *startscript = NULL;
        if (g_key_file_has_key(accounts, name, "script.start", NULL)) {
            startscript = g_key_file_get_string(accounts, name, "script.start", NULL);
        }

        gchar *tls_policy = g_key_file_get_string(accounts, name, "tls.policy", NULL);
        if (tls_policy && ((g_strcmp0(tls_policy, "force") != 0) &&
                (g_strcmp0(tls_policy, "allow") != 0) &&
                (g_strcmp0(tls_policy, "disable") != 0))) {
            g_free(tls_policy);
            tls_policy = NULL;
        }

        ProfAccount *new_account = account_new(name, jid, password, eval_password, enabled,
            server, port, resource, last_presence, login_presence,
            priority_online, priority_chat, priority_away, priority_xa,
            priority_dnd, muc_service, muc_nick, otr_policy, otr_manual,
            otr_opportunistic, otr_always, pgp_keyid, startscript, tls_policy);

        g_free(jid);
        g_free(password);
        g_free(eval_password);
        g_free(server);
        g_free(resource);
        g_free(last_presence);
        g_free(login_presence);
        g_free(muc_service);
        g_free(muc_nick);
        g_free(otr_policy);
        g_free(pgp_keyid);
        g_free(startscript);
        g_free(tls_policy);

        return new_account;
    }
}
예제 #30
0
gboolean
accounts_rename(const char *const account_name, const char *const new_name)
{
    if (g_key_file_has_group(accounts, new_name)) {
        return FALSE;
    }

    if (!g_key_file_has_group(accounts, account_name)) {
        return FALSE;
    }

    // treat all properties as strings for copy
    gchar *string_keys[] = {
        "enabled",
        "jid",
        "server",
        "port",
        "resource",
        "password",
        "eval_password",
        "presence.last",
        "presence.laststatus",
        "presence.login",
        "priority.online",
        "priority.chat",
        "priority.away",
        "priority.xa",
        "priority.dnd",
        "muc.service",
        "muc.nick",
        "otr.policy",
        "otr.manual",
        "otr.opportunistic",
        "otr.always",
        "pgp.keyid",
        "last.activity",
        "script.start",
        "tls.policy"
    };

    int i;
    for (i = 0; i < ARRAY_SIZE(string_keys); i++) {
        char *value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL);
        if (value) {
            g_key_file_set_string(accounts, new_name, string_keys[i], value);
            g_free(value);
        }
    }

    g_key_file_remove_group(accounts, account_name, NULL);
    _save_accounts();

    autocomplete_remove(all_ac, account_name);
    autocomplete_add(all_ac, new_name);
    if (g_key_file_get_boolean(accounts, new_name, "enabled", NULL)) {
        autocomplete_remove(enabled_ac, account_name);
        autocomplete_add(enabled_ac, new_name);
    }

    return TRUE;
}