summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/userpref.c60
-rw-r--r--src/userpref.h1
2 files changed, 61 insertions, 0 deletions
diff --git a/src/userpref.c b/src/userpref.c
index 59c61b6..6e62000 100644
--- a/src/userpref.c
+++ b/src/userpref.c
@@ -186,6 +186,66 @@ int userpref_has_device_public_key(const char *uuid)
}
/**
+ * Fills a list with UUIDs of devices that have been connected to this
+ * system before, i.e. for which a public key file exists.
+ *
+ * @param list A pointer to a char** initially pointing to NULL that will
+ * hold a newly allocated list of UUIDs upon successful return.
+ * The caller is responsible for freeing the memory. Note that if
+ * no public key file was found the list has to be freed too as it
+ * points to a terminating NULL element.
+ * @param count The number of UUIDs found. This parameter can be NULL if it
+ * is not required.
+ *
+ * @return USERPREF_E_SUCCESS on success, or USERPREF_E_INVALID_ARG if the
+ * list parameter is not pointing to NULL.
+ */
+userpref_error_t userpref_get_paired_uuids(char ***list, unsigned int *count)
+{
+ GDir *config_dir;
+ gchar *config_path;
+ const gchar *dir_file;
+ GList *uuids = NULL;
+ unsigned int i;
+ unsigned int found = 0;
+
+ if (!list || (list && *list)) {
+ debug_info("ERROR: The list parameter needs to point to NULL!");
+ return USERPREF_E_INVALID_ARG;
+ }
+
+ if (count) {
+ *count = 0;
+ }
+
+ config_path = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, NULL);
+
+ config_dir = g_dir_open(config_path,0,NULL);
+ if (config_dir) {
+ while ((dir_file = g_dir_read_name(config_dir))) {
+ if (g_str_has_suffix(dir_file, ".pem") && (strlen(dir_file) == 44)) {
+ uuids = g_list_append(uuids, g_strndup(dir_file, strlen(dir_file)-4));
+ found++;
+ }
+ }
+ g_dir_close(config_dir);
+ }
+ *list = (char**)malloc(sizeof(char*) * (found+1));
+ for (i = 0; i < found; i++) {
+ (*list)[i] = g_list_nth_data(uuids, i);
+ }
+ (*list)[i] = NULL;
+
+ if (count) {
+ *count = found;
+ }
+ g_list_free(uuids);
+ g_free(config_path);
+
+ return USERPREF_E_SUCCESS;
+}
+
+/**
* Mark the device (as represented by the key) as having connected to this
* configuration.
*
diff --git a/src/userpref.h b/src/userpref.h
index 48b8969..d6952d3 100644
--- a/src/userpref.h
+++ b/src/userpref.h
@@ -40,6 +40,7 @@ G_GNUC_INTERNAL userpref_error_t userpref_get_certs_as_pem(gnutls_datum_t *pem_r
G_GNUC_INTERNAL userpref_error_t userpref_set_device_public_key(const char *uuid, gnutls_datum_t public_key);
G_GNUC_INTERNAL userpref_error_t userpref_remove_device_public_key(const char *uuid);
G_GNUC_INTERNAL int userpref_has_device_public_key(const char *uuid);
+userpref_error_t userpref_get_paired_uuids(char ***list, unsigned int *count);
G_GNUC_INTERNAL void userpref_get_host_id(char **host_id);
#endif