diff options
| author | 2010-05-28 16:50:53 +0200 | |
|---|---|---|
| committer | 2010-05-28 17:00:34 +0200 | |
| commit | bd72b013546ec8fe9f88916e98e34501b7ca38e7 (patch) | |
| tree | 7568553d521e8955715bb2393de031df2ea681dd /src/userpref.c | |
| parent | a941e78cb66222af6016726aca9c9eba254e155d (diff) | |
| download | libimobiledevice-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.c | 60 |
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) | |||
| 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 | */ | ||
| 203 | userpref_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 | * |
