summaryrefslogtreecommitdiffstats
path: root/src/userpref.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2010-05-28 16:50:53 +0200
committerGravatar Nikias Bassen2010-05-28 17:00:34 +0200
commitbd72b013546ec8fe9f88916e98e34501b7ca38e7 (patch)
tree7568553d521e8955715bb2393de031df2ea681dd /src/userpref.c
parenta941e78cb66222af6016726aca9c9eba254e155d (diff)
downloadlibimobiledevice-bd72b013546ec8fe9f88916e98e34501b7ca38e7.tar.gz
libimobiledevice-bd72b013546ec8fe9f88916e98e34501b7ca38e7.tar.bz2
userpref: new internal function userpref_get_paired_uuids
Diffstat (limited to 'src/userpref.c')
-rw-r--r--src/userpref.c60
1 files changed, 60 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.
*