diff options
Diffstat (limited to 'src/config')
-rw-r--r-- | src/config/preferences.c | 74 | ||||
-rw-r--r-- | src/config/preferences.h | 4 |
2 files changed, 78 insertions, 0 deletions
diff --git a/src/config/preferences.c b/src/config/preferences.c index 6d63d3e9..e11b4cf2 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -430,6 +430,80 @@ prefs_set_pgp_char(char ch) _save_prefs(); } +GList * +prefs_get_trusted_certs(void) +{ + gsize length; + GList *fp_list = NULL; + gchar **fps = g_key_file_get_string_list(prefs, PREF_GROUP_CONNECTION, "certs", &length, NULL); + if (fps) { + int i = 0; + for (i = 0; i < length; i++) { + fp_list = g_list_append(fp_list, strdup(fps[i])); + } + g_strfreev(fps); + return fp_list; + } else { + return NULL; + } +} + +void +prefs_free_trusted_certs(GList *certs) +{ + if (certs) { + g_list_free_full(certs, free); + } +} + +void +prefs_add_trusted_cert(const char * const fp) +{ + gsize length; + gchar **list = g_key_file_get_string_list(prefs, PREF_GROUP_CONNECTION, "certs", &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], fp) == 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(fp)); + + // 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(prefs, PREF_GROUP_CONNECTION, "certs", new_list, g_list_length(glist)); + + // list not found + } else { + const gchar* new_list[2]; + new_list[0] = strdup(fp); + new_list[1] = NULL; + g_key_file_set_string_list(prefs, PREF_GROUP_CONNECTION, "certs", new_list, 1); + } + + g_strfreev(list); + g_list_free_full(glist, g_free); + _save_prefs(); +} + gboolean prefs_add_alias(const char * const name, const char * const value) { diff --git a/src/config/preferences.h b/src/config/preferences.h index 2a7ab5bf..432137b3 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -162,4 +162,8 @@ char * prefs_get_string(preference_t pref); void prefs_free_string(char *pref); void prefs_set_string(preference_t pref, char *value); +GList* prefs_get_trusted_certs(void); +void prefs_free_trusted_certs(GList *certs); +void prefs_add_trusted_cert(const char * const fp); + #endif |