summaryrefslogtreecommitdiffstats
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
parenta941e78cb66222af6016726aca9c9eba254e155d (diff)
downloadlibimobiledevice-bd72b013546ec8fe9f88916e98e34501b7ca38e7.tar.gz
libimobiledevice-bd72b013546ec8fe9f88916e98e34501b7ca38e7.tar.bz2
userpref: new internal function userpref_get_paired_uuids
-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)
186} 186}
187 187
188/** 188/**
189 * Fills a list with UUIDs of devices that have been connected to this
190 * system before, i.e. for which a public key file exists.
191 *
192 * @param list A pointer to a char** initially pointing to NULL that will
193 * hold a newly allocated list of UUIDs upon successful return.
194 * The caller is responsible for freeing the memory. Note that if
195 * no public key file was found the list has to be freed too as it
196 * points to a terminating NULL element.
197 * @param count The number of UUIDs found. This parameter can be NULL if it
198 * is not required.
199 *
200 * @return USERPREF_E_SUCCESS on success, or USERPREF_E_INVALID_ARG if the
201 * list parameter is not pointing to NULL.
202 */
203userpref_error_t userpref_get_paired_uuids(char ***list, unsigned int *count)
204{
205 GDir *config_dir;
206 gchar *config_path;
207 const gchar *dir_file;
208 GList *uuids = NULL;
209 unsigned int i;
210 unsigned int found = 0;
211
212 if (!list || (list && *list)) {
213 debug_info("ERROR: The list parameter needs to point to NULL!");
214 return USERPREF_E_INVALID_ARG;
215 }
216
217 if (count) {
218 *count = 0;
219 }
220
221 config_path = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, NULL);
222
223 config_dir = g_dir_open(config_path,0,NULL);
224 if (config_dir) {
225 while ((dir_file = g_dir_read_name(config_dir))) {
226 if (g_str_has_suffix(dir_file, ".pem") && (strlen(dir_file) == 44)) {
227 uuids = g_list_append(uuids, g_strndup(dir_file, strlen(dir_file)-4));
228 found++;
229 }
230 }
231 g_dir_close(config_dir);
232 }
233 *list = (char**)malloc(sizeof(char*) * (found+1));
234 for (i = 0; i < found; i++) {
235 (*list)[i] = g_list_nth_data(uuids, i);
236 }
237 (*list)[i] = NULL;
238
239 if (count) {
240 *count = found;
241 }
242 g_list_free(uuids);
243 g_free(config_path);
244
245 return USERPREF_E_SUCCESS;
246}
247
248/**
189 * Mark the device (as represented by the key) as having connected to this 249 * Mark the device (as represented by the key) as having connected to this
190 * configuration. 250 * configuration.
191 * 251 *
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
40G_GNUC_INTERNAL userpref_error_t userpref_set_device_public_key(const char *uuid, gnutls_datum_t public_key); 40G_GNUC_INTERNAL userpref_error_t userpref_set_device_public_key(const char *uuid, gnutls_datum_t public_key);
41G_GNUC_INTERNAL userpref_error_t userpref_remove_device_public_key(const char *uuid); 41G_GNUC_INTERNAL userpref_error_t userpref_remove_device_public_key(const char *uuid);
42G_GNUC_INTERNAL int userpref_has_device_public_key(const char *uuid); 42G_GNUC_INTERNAL int userpref_has_device_public_key(const char *uuid);
43userpref_error_t userpref_get_paired_uuids(char ***list, unsigned int *count);
43G_GNUC_INTERNAL void userpref_get_host_id(char **host_id); 44G_GNUC_INTERNAL void userpref_get_host_id(char **host_id);
44 45
45#endif 46#endif