mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Cleanup g_strfreev()
to auto_gcharv
Include some additional minor cleanups
This commit is contained in:
parent
029f1caa52
commit
865a056315
@ -3210,14 +3210,14 @@ _form_field_autocomplete(ProfWin* window, const char* const input, gboolean prev
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gchar** split = g_strsplit(input, " ", 0);
|
||||
auto_gcharv gchar** split = g_strsplit(input, " ", 0);
|
||||
|
||||
if (g_strv_length(split) == 3) {
|
||||
char* field_tag = split[0] + 1;
|
||||
if (form_tag_exists(form, field_tag)) {
|
||||
form_field_type_t field_type = form_get_field_type(form, field_tag);
|
||||
Autocomplete value_ac = form_get_value_ac(form, field_tag);
|
||||
;
|
||||
|
||||
GString* beginning = g_string_new(split[0]);
|
||||
g_string_append(beginning, " ");
|
||||
g_string_append(beginning, split[1]);
|
||||
@ -3225,10 +3225,8 @@ _form_field_autocomplete(ProfWin* window, const char* const input, gboolean prev
|
||||
if (((g_strcmp0(split[1], "add") == 0) || (g_strcmp0(split[1], "remove") == 0))
|
||||
&& field_type == FIELD_LIST_MULTI) {
|
||||
found = autocomplete_param_with_ac(input, beginning->str, value_ac, TRUE, previous);
|
||||
|
||||
} else if ((g_strcmp0(split[1], "remove") == 0) && field_type == FIELD_TEXT_MULTI) {
|
||||
found = autocomplete_param_with_ac(input, beginning->str, value_ac, TRUE, previous);
|
||||
|
||||
} else if ((g_strcmp0(split[1], "remove") == 0) && field_type == FIELD_JID_MULTI) {
|
||||
found = autocomplete_param_with_ac(input, beginning->str, value_ac, TRUE, previous);
|
||||
}
|
||||
@ -3241,7 +3239,6 @@ _form_field_autocomplete(ProfWin* window, const char* const input, gboolean prev
|
||||
if (form_tag_exists(form, field_tag)) {
|
||||
form_field_type_t field_type = form_get_field_type(form, field_tag);
|
||||
Autocomplete value_ac = form_get_value_ac(form, field_tag);
|
||||
;
|
||||
|
||||
switch (field_type) {
|
||||
case FIELD_BOOLEAN:
|
||||
@ -3261,8 +3258,6 @@ _form_field_autocomplete(ProfWin* window, const char* const input, gboolean prev
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev(split);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
|
@ -2768,7 +2768,7 @@ _cmd_index(const Command* cmd)
|
||||
index_source = g_string_append(index_source, " ");
|
||||
}
|
||||
|
||||
gchar** tokens = g_str_tokenize_and_fold(index_source->str, NULL, NULL);
|
||||
auto_gcharv gchar** tokens = g_str_tokenize_and_fold(index_source->str, NULL, NULL);
|
||||
g_string_free(index_source, TRUE);
|
||||
|
||||
GString* index = g_string_new("");
|
||||
@ -2776,7 +2776,6 @@ _cmd_index(const Command* cmd)
|
||||
index = g_string_append(index, tokens[i]);
|
||||
index = g_string_append(index, " ");
|
||||
}
|
||||
g_strfreev(tokens);
|
||||
|
||||
return g_string_free(index, FALSE);
|
||||
}
|
||||
@ -2786,7 +2785,7 @@ cmd_search_index_any(char* term)
|
||||
{
|
||||
GList* results = NULL;
|
||||
|
||||
gchar** processed_terms = g_str_tokenize_and_fold(term, NULL, NULL);
|
||||
auto_gcharv gchar** processed_terms = g_str_tokenize_and_fold(term, NULL, NULL);
|
||||
int terms_len = g_strv_length(processed_terms);
|
||||
|
||||
for (int i = 0; i < terms_len; i++) {
|
||||
@ -2802,8 +2801,6 @@ cmd_search_index_any(char* term)
|
||||
g_list_free(index_keys);
|
||||
}
|
||||
|
||||
g_strfreev(processed_terms);
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@ -2812,7 +2809,7 @@ cmd_search_index_all(char* term)
|
||||
{
|
||||
GList* results = NULL;
|
||||
|
||||
gchar** terms = g_str_tokenize_and_fold(term, NULL, NULL);
|
||||
auto_gcharv gchar** terms = g_str_tokenize_and_fold(term, NULL, NULL);
|
||||
int terms_len = g_strv_length(terms);
|
||||
|
||||
GList* commands = g_hash_table_get_keys(search_index);
|
||||
@ -2833,7 +2830,6 @@ cmd_search_index_all(char* term)
|
||||
}
|
||||
|
||||
g_list_free(commands);
|
||||
g_strfreev(terms);
|
||||
|
||||
return results;
|
||||
}
|
||||
|
@ -505,9 +505,8 @@ cmd_connect(ProfWin* window, const char* const command, gchar** args)
|
||||
gboolean
|
||||
cmd_account_list(ProfWin* window, const char* const command, gchar** args)
|
||||
{
|
||||
gchar** accounts = accounts_get_list();
|
||||
auto_gcharv gchar** accounts = accounts_get_list();
|
||||
cons_show_account_list(accounts);
|
||||
g_strfreev(accounts);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -4839,9 +4838,8 @@ cmd_bookmark_ignore(ProfWin* window, const char* const command, gchar** args)
|
||||
// `/bookmark ignore` lists them
|
||||
if (args[1] == NULL) {
|
||||
gsize len = 0;
|
||||
gchar** list = bookmark_ignore_list(&len);
|
||||
auto_gcharv gchar** list = bookmark_ignore_list(&len);
|
||||
cons_show_bookmarks_ignore(list, len);
|
||||
g_strfreev(list);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -8479,18 +8477,16 @@ _cmd_execute(ProfWin* window, const char* const command, const char* const inp)
|
||||
{
|
||||
if (g_str_has_prefix(command, "/field") && window->type == WIN_CONFIG) {
|
||||
gboolean result = FALSE;
|
||||
gchar** args = parse_args_with_freetext(inp, 1, 2, &result);
|
||||
auto_gcharv gchar** args = parse_args_with_freetext(inp, 1, 2, &result);
|
||||
if (!result) {
|
||||
win_println(window, THEME_DEFAULT, "!", "Invalid command, see /form help");
|
||||
result = TRUE;
|
||||
} else {
|
||||
gchar** tokens = g_strsplit(inp, " ", 2);
|
||||
auto_gcharv gchar** tokens = g_strsplit(inp, " ", 2);
|
||||
char* field = tokens[0] + 1;
|
||||
result = cmd_form_field(window, field, args);
|
||||
g_strfreev(tokens);
|
||||
}
|
||||
|
||||
g_strfreev(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -8498,7 +8494,7 @@ _cmd_execute(ProfWin* window, const char* const command, const char* const inp)
|
||||
gboolean result = FALSE;
|
||||
|
||||
if (cmd) {
|
||||
gchar** args = cmd->parser(inp, cmd->min_args, cmd->max_args, &result);
|
||||
auto_gcharv gchar** args = cmd->parser(inp, cmd->min_args, cmd->max_args, &result);
|
||||
if (result == FALSE) {
|
||||
ui_invalid_command_usage(cmd->cmd, cmd->setting_func);
|
||||
return TRUE;
|
||||
@ -8507,20 +8503,17 @@ _cmd_execute(ProfWin* window, const char* const command, const char* const inp)
|
||||
int i = 0;
|
||||
while (cmd->sub_funcs[i].cmd) {
|
||||
if (g_strcmp0(args[0], (char*)cmd->sub_funcs[i].cmd) == 0) {
|
||||
result = cmd->sub_funcs[i].func(window, command, args);
|
||||
goto out;
|
||||
return cmd->sub_funcs[i].func(window, command, args);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (!cmd->func) {
|
||||
ui_invalid_command_usage(cmd->cmd, cmd->setting_func);
|
||||
result = TRUE;
|
||||
goto out;
|
||||
return TRUE;
|
||||
}
|
||||
result = cmd->func(window, command, args);
|
||||
out:
|
||||
g_strfreev(args);
|
||||
|
||||
return result;
|
||||
} else if (plugins_run_command(inp)) {
|
||||
return TRUE;
|
||||
@ -9543,15 +9536,13 @@ _url_http_method(ProfWin* window, const char* cmd_template, gchar* url, gchar* p
|
||||
void
|
||||
_url_external_method(const char* cmd_template, const char* url, gchar* filename)
|
||||
{
|
||||
gchar** argv = format_call_external_argv(cmd_template, url, filename);
|
||||
auto_gcharv gchar** argv = format_call_external_argv(cmd_template, url, filename);
|
||||
|
||||
if (!call_external(argv)) {
|
||||
cons_show_error("Unable to call external executable for url: check the logs for more information.");
|
||||
} else {
|
||||
cons_show("URL '%s' has been called with '%s'.", url, cmd_template);
|
||||
}
|
||||
|
||||
g_strfreev(argv);
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
@ -78,7 +78,7 @@ accounts_load(void)
|
||||
|
||||
// create the logins searchable list for autocompletion
|
||||
gsize naccounts;
|
||||
gchar** account_names = g_key_file_get_groups(accounts, &naccounts);
|
||||
auto_gcharv gchar** account_names = g_key_file_get_groups(accounts, &naccounts);
|
||||
|
||||
for (gsize i = 0; i < naccounts; i++) {
|
||||
autocomplete_add(all_ac, account_names[i]);
|
||||
@ -86,8 +86,6 @@ accounts_load(void)
|
||||
autocomplete_add(enabled_ac, account_names[i]);
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev(account_names);
|
||||
}
|
||||
|
||||
void
|
||||
@ -245,30 +243,27 @@ accounts_get_account(const char* const name)
|
||||
|
||||
gsize length;
|
||||
GList* otr_manual = NULL;
|
||||
gchar** manual = g_key_file_get_string_list(accounts, name, "otr.manual", &length, NULL);
|
||||
auto_gcharv gchar** manual = g_key_file_get_string_list(accounts, name, "otr.manual", &length, NULL);
|
||||
if (manual) {
|
||||
for (int 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);
|
||||
auto_gcharv gchar** opportunistic = g_key_file_get_string_list(accounts, name, "otr.opportunistic", &length, NULL);
|
||||
if (opportunistic) {
|
||||
for (int 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);
|
||||
auto_gcharv gchar** always = g_key_file_get_string_list(accounts, name, "otr.always", &length, NULL);
|
||||
if (always) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
otr_always = g_list_append(otr_always, strdup(always[i]));
|
||||
}
|
||||
g_strfreev(always);
|
||||
}
|
||||
|
||||
gchar* omemo_policy = NULL;
|
||||
@ -277,39 +272,35 @@ accounts_get_account(const char* const name)
|
||||
}
|
||||
|
||||
GList* omemo_enabled = NULL;
|
||||
gchar** omemo_enabled_list = g_key_file_get_string_list(accounts, name, "omemo.enabled", &length, NULL);
|
||||
auto_gcharv gchar** omemo_enabled_list = g_key_file_get_string_list(accounts, name, "omemo.enabled", &length, NULL);
|
||||
if (omemo_enabled_list) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
omemo_enabled = g_list_append(omemo_enabled, strdup(omemo_enabled_list[i]));
|
||||
}
|
||||
g_strfreev(omemo_enabled_list);
|
||||
}
|
||||
|
||||
GList* omemo_disabled = NULL;
|
||||
gchar** omemo_disabled_list = g_key_file_get_string_list(accounts, name, "omemo.disabled", &length, NULL);
|
||||
auto_gcharv gchar** omemo_disabled_list = g_key_file_get_string_list(accounts, name, "omemo.disabled", &length, NULL);
|
||||
if (omemo_disabled_list) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
omemo_disabled = g_list_append(omemo_disabled, strdup(omemo_disabled_list[i]));
|
||||
}
|
||||
g_strfreev(omemo_disabled_list);
|
||||
}
|
||||
|
||||
GList* ox_enabled = NULL;
|
||||
gchar** ox_enabled_list = g_key_file_get_string_list(accounts, name, "ox.enabled", &length, NULL);
|
||||
auto_gcharv gchar** ox_enabled_list = g_key_file_get_string_list(accounts, name, "ox.enabled", &length, NULL);
|
||||
if (ox_enabled_list) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
ox_enabled = g_list_append(ox_enabled, strdup(ox_enabled_list[i]));
|
||||
}
|
||||
g_strfreev(ox_enabled_list);
|
||||
}
|
||||
|
||||
GList* pgp_enabled = NULL;
|
||||
gchar** pgp_enabled_list = g_key_file_get_string_list(accounts, name, "pgp.enabled", &length, NULL);
|
||||
auto_gcharv gchar** pgp_enabled_list = g_key_file_get_string_list(accounts, name, "pgp.enabled", &length, NULL);
|
||||
if (pgp_enabled_list) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
pgp_enabled = g_list_append(pgp_enabled, strdup(pgp_enabled_list[i]));
|
||||
}
|
||||
g_strfreev(pgp_enabled_list);
|
||||
}
|
||||
|
||||
gchar* pgp_keyid = NULL;
|
||||
|
@ -34,6 +34,7 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "common.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <glib.h>
|
||||
@ -42,7 +43,7 @@ gboolean
|
||||
conf_string_list_add(GKeyFile* keyfile, const char* const group, const char* const key, const char* const item)
|
||||
{
|
||||
gsize length;
|
||||
gchar** list = g_key_file_get_string_list(keyfile, group, key, &length, NULL);
|
||||
auto_gcharv gchar** list = g_key_file_get_string_list(keyfile, group, key, &length, NULL);
|
||||
GList* glist = NULL;
|
||||
|
||||
// list found
|
||||
@ -81,7 +82,6 @@ conf_string_list_add(GKeyFile* keyfile, const char* const group, const char* con
|
||||
g_key_file_set_string_list(keyfile, group, key, new_list, 1);
|
||||
}
|
||||
|
||||
g_strfreev(list);
|
||||
g_list_free_full(glist, g_free);
|
||||
|
||||
return TRUE;
|
||||
@ -91,44 +91,43 @@ gboolean
|
||||
conf_string_list_remove(GKeyFile* keyfile, const char* const group, const char* const key, const char* const item)
|
||||
{
|
||||
gsize length;
|
||||
gchar** list = g_key_file_get_string_list(keyfile, group, key, &length, NULL);
|
||||
auto_gcharv gchar** list = g_key_file_get_string_list(keyfile, group, key, &length, NULL);
|
||||
|
||||
gboolean deleted = FALSE;
|
||||
if (list) {
|
||||
int i = 0;
|
||||
GList* glist = NULL;
|
||||
if (!list) {
|
||||
return FALSE;
|
||||
}
|
||||
int i = 0;
|
||||
GList* glist = NULL;
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
// item found, mark as deleted
|
||||
if (strcmp(list[i], item) == 0) {
|
||||
deleted = TRUE;
|
||||
} else {
|
||||
// add item to our g_list
|
||||
glist = g_list_append(glist, strdup(list[i]));
|
||||
}
|
||||
for (i = 0; i < length; i++) {
|
||||
// item found, mark as deleted
|
||||
if (strcmp(list[i], item) == 0) {
|
||||
deleted = TRUE;
|
||||
} else {
|
||||
// add item to our g_list
|
||||
glist = g_list_append(glist, strdup(list[i]));
|
||||
}
|
||||
|
||||
if (deleted) {
|
||||
if (g_list_length(glist) == 0) {
|
||||
g_key_file_remove_key(keyfile, group, key, NULL);
|
||||
} else {
|
||||
// create the new list entry
|
||||
const gchar* new_list[g_list_length(glist) + 1];
|
||||
GList* curr = glist;
|
||||
i = 0;
|
||||
while (curr) {
|
||||
new_list[i++] = curr->data;
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
new_list[i] = NULL;
|
||||
g_key_file_set_string_list(keyfile, group, key, new_list, g_list_length(glist));
|
||||
}
|
||||
}
|
||||
|
||||
g_list_free_full(glist, g_free);
|
||||
}
|
||||
|
||||
g_strfreev(list);
|
||||
if (deleted) {
|
||||
if (g_list_length(glist) == 0) {
|
||||
g_key_file_remove_key(keyfile, group, key, NULL);
|
||||
} else {
|
||||
// create the new list entry
|
||||
const gchar* new_list[g_list_length(glist) + 1];
|
||||
GList* curr = glist;
|
||||
i = 0;
|
||||
while (curr) {
|
||||
new_list[i++] = curr->data;
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
new_list[i] = NULL;
|
||||
g_key_file_set_string_list(keyfile, group, key, new_list, g_list_length(glist));
|
||||
}
|
||||
}
|
||||
|
||||
g_list_free_full(glist, g_free);
|
||||
|
||||
return deleted;
|
||||
}
|
||||
|
@ -216,12 +216,11 @@ _prefs_load(void)
|
||||
|
||||
room_trigger_ac = autocomplete_new();
|
||||
gsize len = 0;
|
||||
gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL);
|
||||
auto_gcharv gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL);
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
autocomplete_add(room_trigger_ac, triggers[i]);
|
||||
}
|
||||
g_strfreev(triggers);
|
||||
}
|
||||
|
||||
/* Clean up after _prefs_load() */
|
||||
@ -333,7 +332,7 @@ prefs_message_get_triggers(const char* const message)
|
||||
|
||||
auto_gchar gchar* message_lower = g_utf8_strdown(message, -1);
|
||||
gsize len = 0;
|
||||
gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL);
|
||||
auto_gcharv gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL);
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
auto_gchar gchar* trigger_lower = g_utf8_strdown(triggers[i], -1);
|
||||
@ -342,8 +341,6 @@ prefs_message_get_triggers(const char* const message)
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev(triggers);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -862,12 +859,6 @@ prefs_remove_plugin(const char* const name)
|
||||
_save_prefs();
|
||||
}
|
||||
|
||||
void
|
||||
prefs_free_plugins(gchar** plugins)
|
||||
{
|
||||
g_strfreev(plugins);
|
||||
}
|
||||
|
||||
void
|
||||
prefs_set_occupants_size(gint value)
|
||||
{
|
||||
@ -1316,14 +1307,12 @@ prefs_get_room_notify_triggers(void)
|
||||
{
|
||||
GList* result = NULL;
|
||||
gsize len = 0;
|
||||
gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL);
|
||||
auto_gcharv gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL);
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
result = g_list_append(result, strdup(triggers[i]));
|
||||
}
|
||||
|
||||
g_strfreev(triggers);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -1665,7 +1654,7 @@ prefs_get_aliases(void)
|
||||
} else {
|
||||
GList* result = NULL;
|
||||
gsize len;
|
||||
gchar** keys = g_key_file_get_keys(prefs, PREF_GROUP_ALIAS, &len, NULL);
|
||||
auto_gcharv gchar** keys = g_key_file_get_keys(prefs, PREF_GROUP_ALIAS, &len, NULL);
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
char* name = keys[i];
|
||||
@ -1680,8 +1669,6 @@ prefs_get_aliases(void)
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev(keys);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -253,7 +253,6 @@ gint prefs_get_autoxa_time(void);
|
||||
void prefs_set_autoxa_time(gint value);
|
||||
|
||||
gchar** prefs_get_plugins(void);
|
||||
void prefs_free_plugins(gchar** plugins);
|
||||
void prefs_add_plugin(const char* const name);
|
||||
void prefs_remove_plugin(const char* const name);
|
||||
|
||||
|
@ -71,12 +71,11 @@ tlscerts_init(void)
|
||||
|
||||
certs_ac = autocomplete_new();
|
||||
gsize len = 0;
|
||||
gchar** groups = g_key_file_get_groups(tlscerts, &len);
|
||||
auto_gcharv gchar** groups = g_key_file_get_groups(tlscerts, &len);
|
||||
|
||||
for (int i = 0; i < g_strv_length(groups); i++) {
|
||||
autocomplete_add(certs_ac, groups[i]);
|
||||
}
|
||||
g_strfreev(groups);
|
||||
|
||||
current_fp = NULL;
|
||||
}
|
||||
@ -116,7 +115,7 @@ tlscerts_list(void)
|
||||
{
|
||||
GList* res = NULL;
|
||||
gsize len = 0;
|
||||
gchar** groups = g_key_file_get_groups(tlscerts, &len);
|
||||
auto_gcharv gchar** groups = g_key_file_get_groups(tlscerts, &len);
|
||||
|
||||
for (int i = 0; i < g_strv_length(groups); i++) {
|
||||
char* fingerprint = strdup(groups[i]);
|
||||
@ -135,10 +134,6 @@ tlscerts_list(void)
|
||||
res = g_list_append(res, cert);
|
||||
}
|
||||
|
||||
if (groups) {
|
||||
g_strfreev(groups);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -178,9 +173,9 @@ tlscerts_new(const char* const fingerprint, int version, const char* const seria
|
||||
cert->pem = strdup(pem);
|
||||
}
|
||||
|
||||
gchar** fields = g_strsplit(subjectname, "/", 0);
|
||||
auto_gcharv gchar** fields = g_strsplit(subjectname, "/", 0);
|
||||
for (int i = 0; i < g_strv_length(fields); i++) {
|
||||
gchar** keyval = g_strsplit(fields[i], "=", 2);
|
||||
auto_gcharv gchar** keyval = g_strsplit(fields[i], "=", 2);
|
||||
if (g_strv_length(keyval) == 2) {
|
||||
if ((g_strcmp0(keyval[0], "C") == 0) || (g_strcmp0(keyval[0], "countryName") == 0)) {
|
||||
cert->subject_country = strdup(keyval[1]);
|
||||
@ -207,13 +202,11 @@ tlscerts_new(const char* const fingerprint, int version, const char* const seria
|
||||
cert->subject_email = strdup(keyval[1]);
|
||||
}
|
||||
}
|
||||
g_strfreev(keyval);
|
||||
}
|
||||
g_strfreev(fields);
|
||||
|
||||
fields = g_strsplit(issuername, "/", 0);
|
||||
for (int i = 0; i < g_strv_length(fields); i++) {
|
||||
gchar** keyval = g_strsplit(fields[i], "=", 2);
|
||||
auto_gcharv gchar** fields2 = g_strsplit(issuername, "/", 0);
|
||||
for (int i = 0; i < g_strv_length(fields2); i++) {
|
||||
auto_gcharv gchar** keyval = g_strsplit(fields2[i], "=", 2);
|
||||
if (g_strv_length(keyval) == 2) {
|
||||
if ((g_strcmp0(keyval[0], "C") == 0) || (g_strcmp0(keyval[0], "countryName") == 0)) {
|
||||
cert->issuer_country = strdup(keyval[1]);
|
||||
@ -240,9 +233,7 @@ tlscerts_new(const char* const fingerprint, int version, const char* const seria
|
||||
cert->issuer_email = strdup(keyval[1]);
|
||||
}
|
||||
}
|
||||
g_strfreev(keyval);
|
||||
}
|
||||
g_strfreev(fields);
|
||||
|
||||
return cert;
|
||||
}
|
||||
|
@ -1319,10 +1319,9 @@ static void
|
||||
_cut(ProfMessage* message, const char* cut)
|
||||
{
|
||||
if (strstr(message->plain, cut)) {
|
||||
gchar** split = g_strsplit(message->plain, cut, -1);
|
||||
auto_gcharv gchar** split = g_strsplit(message->plain, cut, -1);
|
||||
free(message->plain);
|
||||
message->plain = g_strjoinv("", split);
|
||||
g_strfreev(split);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1597,60 +1597,59 @@ _load_identity(void)
|
||||
static void
|
||||
_load_trust(void)
|
||||
{
|
||||
char** keys = NULL;
|
||||
gchar** groups = g_key_file_get_groups(omemo_ctx.trust_keyfile, NULL);
|
||||
if (groups) {
|
||||
int i;
|
||||
for (i = 0; groups[i] != NULL; i++) {
|
||||
GHashTable* trusted;
|
||||
auto_gcharv gchar** groups = g_key_file_get_groups(omemo_ctx.trust_keyfile, NULL);
|
||||
|
||||
trusted = g_hash_table_lookup(omemo_ctx.identity_key_store.trusted, groups[i]);
|
||||
if (!trusted) {
|
||||
trusted = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
|
||||
g_hash_table_insert(omemo_ctx.identity_key_store.trusted, strdup(groups[i]), trusted);
|
||||
}
|
||||
if (!groups) {
|
||||
return;
|
||||
}
|
||||
|
||||
keys = g_key_file_get_keys(omemo_ctx.trust_keyfile, groups[i], NULL, NULL);
|
||||
int j;
|
||||
for (j = 0; keys[j] != NULL; j++) {
|
||||
auto_gchar gchar* key_b64 = g_key_file_get_string(omemo_ctx.trust_keyfile, groups[i], keys[j], NULL);
|
||||
size_t key_len;
|
||||
auto_guchar guchar* key = g_base64_decode(key_b64, &key_len);
|
||||
signal_buffer* buffer = signal_buffer_create(key, key_len);
|
||||
uint32_t device_id = strtoul(keys[j], NULL, 10);
|
||||
g_hash_table_insert(trusted, GINT_TO_POINTER(device_id), buffer);
|
||||
}
|
||||
g_strfreev(keys);
|
||||
for (int i = 0; groups[i] != NULL; i++) {
|
||||
GHashTable* trusted;
|
||||
|
||||
trusted = g_hash_table_lookup(omemo_ctx.identity_key_store.trusted, groups[i]);
|
||||
if (!trusted) {
|
||||
trusted = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
|
||||
g_hash_table_insert(omemo_ctx.identity_key_store.trusted, strdup(groups[i]), trusted);
|
||||
}
|
||||
|
||||
auto_gcharv gchar** keys = g_key_file_get_keys(omemo_ctx.trust_keyfile, groups[i], NULL, NULL);
|
||||
for (int j = 0; keys[j] != NULL; j++) {
|
||||
auto_gchar gchar* key_b64 = g_key_file_get_string(omemo_ctx.trust_keyfile, groups[i], keys[j], NULL);
|
||||
size_t key_len;
|
||||
auto_guchar guchar* key = g_base64_decode(key_b64, &key_len);
|
||||
signal_buffer* buffer = signal_buffer_create(key, key_len);
|
||||
uint32_t device_id = strtoul(keys[j], NULL, 10);
|
||||
g_hash_table_insert(trusted, GINT_TO_POINTER(device_id), buffer);
|
||||
}
|
||||
g_strfreev(groups);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_load_sessions(void)
|
||||
{
|
||||
int i;
|
||||
auto_gcharv gchar** groups = g_key_file_get_groups(omemo_ctx.sessions_keyfile, NULL);
|
||||
if (groups) {
|
||||
for (i = 0; groups[i] != NULL; i++) {
|
||||
int j;
|
||||
GHashTable* device_store = NULL;
|
||||
|
||||
device_store = g_hash_table_lookup(omemo_ctx.session_store, groups[i]);
|
||||
if (!device_store) {
|
||||
device_store = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
|
||||
g_hash_table_insert(omemo_ctx.session_store, strdup(groups[i]), device_store);
|
||||
}
|
||||
if (!groups) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto_gcharv gchar** keys = g_key_file_get_keys(omemo_ctx.sessions_keyfile, groups[i], NULL, NULL);
|
||||
for (j = 0; keys[j] != NULL; j++) {
|
||||
uint32_t id = strtoul(keys[j], NULL, 10);
|
||||
auto_gchar gchar* record_b64 = g_key_file_get_string(omemo_ctx.sessions_keyfile, groups[i], keys[j], NULL);
|
||||
size_t record_len;
|
||||
auto_guchar guchar* record = g_base64_decode(record_b64, &record_len);
|
||||
signal_buffer* buffer = signal_buffer_create(record, record_len);
|
||||
g_hash_table_insert(device_store, GINT_TO_POINTER(id), buffer);
|
||||
}
|
||||
for (int i = 0; groups[i] != NULL; i++) {
|
||||
GHashTable* device_store = NULL;
|
||||
|
||||
device_store = g_hash_table_lookup(omemo_ctx.session_store, groups[i]);
|
||||
if (!device_store) {
|
||||
device_store = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
|
||||
g_hash_table_insert(omemo_ctx.session_store, strdup(groups[i]), device_store);
|
||||
}
|
||||
|
||||
auto_gcharv gchar** keys = g_key_file_get_keys(omemo_ctx.sessions_keyfile, groups[i], NULL, NULL);
|
||||
for (int j = 0; keys[j] != NULL; j++) {
|
||||
uint32_t id = strtoul(keys[j], NULL, 10);
|
||||
auto_gchar gchar* record_b64 = g_key_file_get_string(omemo_ctx.sessions_keyfile, groups[i], keys[j], NULL);
|
||||
size_t record_len;
|
||||
auto_guchar guchar* record = g_base64_decode(record_b64, &record_len);
|
||||
signal_buffer* buffer = signal_buffer_create(record, record_len);
|
||||
g_hash_table_insert(device_store, GINT_TO_POINTER(id), buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1658,25 +1657,26 @@ _load_sessions(void)
|
||||
static void
|
||||
_load_known_devices(void)
|
||||
{
|
||||
int i;
|
||||
auto_gcharv gchar** groups = g_key_file_get_groups(omemo_ctx.known_devices_keyfile, NULL);
|
||||
if (groups) {
|
||||
for (i = 0; groups[i] != NULL; i++) {
|
||||
int j;
|
||||
GHashTable* known_identities = NULL;
|
||||
|
||||
known_identities = g_hash_table_lookup(omemo_ctx.known_devices, groups[i]);
|
||||
if (!known_identities) {
|
||||
known_identities = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
|
||||
g_hash_table_insert(omemo_ctx.known_devices, strdup(groups[i]), known_identities);
|
||||
}
|
||||
if (!groups) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto_gcharv gchar** keys = g_key_file_get_keys(omemo_ctx.known_devices_keyfile, groups[i], NULL, NULL);
|
||||
for (j = 0; keys[j] != NULL; j++) {
|
||||
uint32_t device_id = strtoul(keys[j], NULL, 10);
|
||||
auto_gchar gchar* fingerprint = g_key_file_get_string(omemo_ctx.known_devices_keyfile, groups[i], keys[j], NULL);
|
||||
g_hash_table_insert(known_identities, strdup(fingerprint), GINT_TO_POINTER(device_id));
|
||||
}
|
||||
for (int i = 0; groups[i] != NULL; i++) {
|
||||
GHashTable* known_identities = NULL;
|
||||
|
||||
known_identities = g_hash_table_lookup(omemo_ctx.known_devices, groups[i]);
|
||||
if (!known_identities) {
|
||||
known_identities = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
|
||||
g_hash_table_insert(omemo_ctx.known_devices, strdup(groups[i]), known_identities);
|
||||
}
|
||||
|
||||
auto_gcharv gchar** keys = g_key_file_get_keys(omemo_ctx.known_devices_keyfile, groups[i], NULL, NULL);
|
||||
for (int j = 0; keys[j] != NULL; j++) {
|
||||
uint32_t device_id = strtoul(keys[j], NULL, 10);
|
||||
auto_gchar gchar* fingerprint = g_key_file_get_string(omemo_ctx.known_devices_keyfile, groups[i], keys[j], NULL);
|
||||
g_hash_table_insert(known_identities, strdup(fingerprint), GINT_TO_POINTER(device_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -177,14 +177,13 @@ p_gpg_on_connect(const char* const barejid)
|
||||
|
||||
// load each keyid
|
||||
gsize len = 0;
|
||||
gchar** jids = g_key_file_get_groups(pubkeyfile, &len);
|
||||
auto_gcharv gchar** jids = g_key_file_get_groups(pubkeyfile, &len);
|
||||
|
||||
gpgme_ctx_t ctx;
|
||||
gpgme_error_t error = gpgme_new(&ctx);
|
||||
|
||||
if (error) {
|
||||
log_error("GPG: Failed to create gpgme context. %s %s", gpgme_strsource(error), gpgme_strerror(error));
|
||||
g_strfreev(jids);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -212,7 +211,6 @@ p_gpg_on_connect(const char* const barejid)
|
||||
}
|
||||
|
||||
gpgme_release(ctx);
|
||||
g_strfreev(jids);
|
||||
|
||||
_save_pubkeys();
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ callbacks_get_window_handler(const char* tag)
|
||||
gboolean
|
||||
plugins_run_command(const char* const input)
|
||||
{
|
||||
gchar** split = g_strsplit(input, " ", -1);
|
||||
auto_gcharv gchar** split = g_strsplit(input, " ", -1);
|
||||
|
||||
GList* command_hashes = g_hash_table_get_values(p_commands);
|
||||
GList* curr_hash = command_hashes;
|
||||
@ -283,26 +283,20 @@ plugins_run_command(const char* const input)
|
||||
PluginCommand* command = g_hash_table_lookup(command_hash, split[0]);
|
||||
if (command) {
|
||||
gboolean result;
|
||||
gchar** args = parse_args_with_freetext(input, command->min_args, command->max_args, &result);
|
||||
auto_gcharv gchar** args = parse_args_with_freetext(input, command->min_args, command->max_args, &result);
|
||||
if (result == FALSE) {
|
||||
ui_invalid_command_usage(command->command_name, NULL);
|
||||
g_strfreev(split);
|
||||
g_list_free(command_hashes);
|
||||
return TRUE;
|
||||
} else {
|
||||
command->callback_exec(command, args);
|
||||
g_strfreev(split);
|
||||
g_strfreev(args);
|
||||
g_list_free(command_hashes);
|
||||
return TRUE;
|
||||
}
|
||||
g_list_free(command_hashes);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
curr_hash = g_list_next(curr_hash);
|
||||
}
|
||||
|
||||
g_list_free(command_hashes);
|
||||
g_strfreev(split);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -82,50 +82,47 @@ plugins_init(void)
|
||||
#endif
|
||||
|
||||
// load plugins
|
||||
gchar** plugins_pref = prefs_get_plugins();
|
||||
if (plugins_pref) {
|
||||
for (int i = 0; i < g_strv_length(plugins_pref); i++) {
|
||||
gboolean loaded = FALSE;
|
||||
gchar* filename = plugins_pref[i];
|
||||
auto_gcharv gchar** plugins_pref = prefs_get_plugins();
|
||||
if (!plugins_pref) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < g_strv_length(plugins_pref); i++) {
|
||||
gboolean loaded = FALSE;
|
||||
gchar* filename = plugins_pref[i];
|
||||
#ifdef HAVE_PYTHON
|
||||
if (g_str_has_suffix(filename, ".py")) {
|
||||
ProfPlugin* plugin = python_plugin_create(filename);
|
||||
if (plugin) {
|
||||
g_hash_table_insert(plugins, strdup(filename), plugin);
|
||||
loaded = TRUE;
|
||||
}
|
||||
if (g_str_has_suffix(filename, ".py")) {
|
||||
ProfPlugin* plugin = python_plugin_create(filename);
|
||||
if (plugin) {
|
||||
g_hash_table_insert(plugins, strdup(filename), plugin);
|
||||
loaded = TRUE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_C
|
||||
if (g_str_has_suffix(filename, ".so")) {
|
||||
ProfPlugin* plugin = c_plugin_create(filename);
|
||||
if (plugin) {
|
||||
g_hash_table_insert(plugins, strdup(filename), plugin);
|
||||
loaded = TRUE;
|
||||
}
|
||||
if (g_str_has_suffix(filename, ".so")) {
|
||||
ProfPlugin* plugin = c_plugin_create(filename);
|
||||
if (plugin) {
|
||||
g_hash_table_insert(plugins, strdup(filename), plugin);
|
||||
loaded = TRUE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (loaded) {
|
||||
log_info("Loaded plugin: %s", filename);
|
||||
} else {
|
||||
log_info("Failed to load plugin: %s", filename);
|
||||
}
|
||||
if (loaded) {
|
||||
log_info("Loaded plugin: %s", filename);
|
||||
} else {
|
||||
log_info("Failed to load plugin: %s", filename);
|
||||
}
|
||||
|
||||
// initialise plugins
|
||||
GList* values = g_hash_table_get_values(plugins);
|
||||
GList* curr = values;
|
||||
while (curr) {
|
||||
ProfPlugin* plugin = curr->data;
|
||||
plugin->init_func(plugin, PACKAGE_VERSION, PACKAGE_STATUS, NULL, NULL);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
g_list_free(values);
|
||||
}
|
||||
|
||||
prefs_free_plugins(plugins_pref);
|
||||
|
||||
return;
|
||||
// initialise plugins
|
||||
GList* values = g_hash_table_get_values(plugins);
|
||||
GList* curr = values;
|
||||
while (curr) {
|
||||
ProfPlugin* plugin = curr->data;
|
||||
plugin->init_func(plugin, PACKAGE_VERSION, PACKAGE_STATUS, NULL, NULL);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
g_list_free(values);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -378,7 +378,7 @@ _caps_by_ver(const char* const ver)
|
||||
auto_gchar gchar* os_version = g_key_file_get_string(cache, ver, "os_version", NULL);
|
||||
|
||||
gsize features_len = 0;
|
||||
gchar** features_list = g_key_file_get_string_list(cache, ver, "features", &features_len, NULL);
|
||||
auto_gcharv gchar** features_list = g_key_file_get_string_list(cache, ver, "features", &features_len, NULL);
|
||||
GSList* features = NULL;
|
||||
if (features_list && features_len > 0) {
|
||||
for (int i = 0; i < features_len; i++) {
|
||||
@ -391,9 +391,6 @@ _caps_by_ver(const char* const ver)
|
||||
software, software_version, os, os_version,
|
||||
features);
|
||||
|
||||
if (features_list) {
|
||||
g_strfreev(features_list);
|
||||
}
|
||||
g_slist_free(features);
|
||||
|
||||
return result;
|
||||
|
@ -877,7 +877,7 @@ _caps_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
}
|
||||
|
||||
// validate sha1
|
||||
gchar** split = g_strsplit(node, "#", -1);
|
||||
auto_gcharv gchar** split = g_strsplit(node, "#", -1);
|
||||
char* given_sha1 = split[1];
|
||||
auto_gchar gchar* generated_sha1 = stanza_create_caps_sha1_from_query(query);
|
||||
|
||||
@ -901,8 +901,6 @@ _caps_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
caps_map_jid_to_ver(from, given_sha1);
|
||||
}
|
||||
|
||||
g_strfreev(split);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1350,7 +1350,7 @@ _vcard_photo_result(xmpp_stanza_t* const stanza, void* userdata)
|
||||
}
|
||||
|
||||
if (data->open) {
|
||||
gchar** argv;
|
||||
auto_gcharv gchar** argv;
|
||||
gint argc;
|
||||
|
||||
auto_gchar gchar* cmdtemplate = prefs_get_string(PREF_VCARD_PHOTO_CMD);
|
||||
@ -1366,7 +1366,6 @@ _vcard_photo_result(xmpp_stanza_t* const stanza, void* userdata)
|
||||
if (!call_external(argv)) {
|
||||
cons_show_error("Unable to execute command");
|
||||
}
|
||||
g_strfreev(argv);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user