static void ssl_manager_load_certs (void) { GDir *dir; const gchar *d; GError *error = NULL; gchar *path; int row = 0; GtkListStore *store; store = GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW(manager.certlist))); gtk_list_store_clear(store); path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "certs", G_DIR_SEPARATOR_S, NULL); if((dir = g_dir_open(path, 0, &error)) == NULL) { debug_print("couldn't open dir '%s': %s (%d)\n", path, error->message, error->code); g_error_free(error); return; } while ((d = g_dir_read_name(dir)) != NULL) { gchar *server = NULL, *port = NULL, *fp = NULL; SSLCertificate *cert; if(strstr(d, ".cert") != d + (strlen(d) - strlen(".cert"))) continue; get_serverport(d, &server, &port); fp = get_fingerprint(d); if (server != NULL && port != NULL) { gint portnum = atoi(port); if (portnum > 0 && portnum <= 65535) { cert = ssl_certificate_find(server, portnum, fp); ssl_manager_list_view_insert_cert(manager.certlist, NULL, server, port, cert); } } g_free(server); g_free(port); g_free(fp); row++; } g_dir_close(dir); g_free(path); }
static void ssl_manager_load_certs (void) { DIR *dir; struct dirent *d; gchar *path; int row = 0; GtkListStore *store; store = GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW(manager.certlist))); gtk_list_store_clear(store); path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "certs", G_DIR_SEPARATOR_S, NULL); if((dir = opendir(path)) == NULL) { perror("opendir"); return; } while ((d = readdir(dir)) != NULL) { gchar *server, *port, *fp; SSLCertificate *cert; if(!strstr(d->d_name, ".cert")) continue; server = get_server(d->d_name); port = get_port(d->d_name); fp = get_fingerprint(d->d_name); cert = ssl_certificate_find(server, atoi(port), fp); ssl_manager_list_view_insert_cert(manager.certlist, NULL, server, port, cert); g_free(server); g_free(port); g_free(fp); row++; } closedir(dir); g_free(path); }