diff options
author | Martin Szulecki | 2009-09-12 11:39:06 +0200 |
---|---|---|
committer | Martin Szulecki | 2009-09-12 11:39:06 +0200 |
commit | fe6c846fa5d80824ee708393c4ea1a1fe4049a77 (patch) | |
tree | 89723aba73bd0121af1320b10ca6762bd21e1bc7 | |
parent | 51bd7976416ac5010f5edc5e70946cbe33646e93 (diff) | |
download | libimobiledevice-fe6c846fa5d80824ee708393c4ea1a1fe4049a77.tar.gz libimobiledevice-fe6c846fa5d80824ee708393c4ea1a1fe4049a77.tar.bz2 |
Update the afc_get_device_info helper to return an afc_error_t
We should return any underlying error afc_get_device_info returns
so one is able to act properly. Also renamed it to "key" instead
of "field" to be more generic.
-rw-r--r-- | include/libiphone/afc.h | 2 | ||||
-rw-r--r-- | src/AFC.c | 28 |
2 files changed, 18 insertions, 12 deletions
diff --git a/include/libiphone/afc.h b/include/libiphone/afc.h index 77b6f0e..e913f91 100644 --- a/include/libiphone/afc.h +++ b/include/libiphone/afc.h @@ -107,7 +107,7 @@ afc_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize); afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname); /* Helper functions */ -char * afc_get_device_info_field(afc_client_t client, const char *field); +afc_error_t afc_get_device_info_key(afc_client_t client, const char *key, char **value); #ifdef __cplusplus } @@ -468,26 +468,32 @@ afc_error_t afc_get_device_info(afc_client_t client, char ***infos) return ret; } -/** Get a specific field of the device info for a client connection to phone. - * Known values are: Model, FSTotalBytes, FSFreeBytes and FSBlockSize. This is - * a helper function for afc_get_device_info(). +/** Get a specific key of the device info list for a client connection. + * Known key values are: Model, FSTotalBytes, FSFreeBytes and FSBlockSize. + * This is a helper function for afc_get_device_info(). * * @param client The client to get device info for. - * @param field The field to get the information for + * @param key The key to get the value of. + * @param value The value for the key if successful or NULL otherwise. * - * @return A char * or NULL if there was an error. + * @return AFC_E_SUCCESS on success or an AFC_E_* error value. */ -char * afc_get_device_info_field(afc_client_t client, const char *field) +afc_error_t afc_get_device_info_key(afc_client_t client, const char *key, char **value) { - char *ret = NULL; + afc_error_t ret = AFC_E_INTERNAL_ERROR; char **kvps, **ptr; - if (field == NULL || afc_get_device_info(client, &kvps) != AFC_E_SUCCESS) - return NULL; + *value = NULL; + if (key == NULL) + return AFC_E_INVALID_ARGUMENT; + + ret = afc_get_device_info(client, &kvps); + if (ret != AFC_E_SUCCESS) + return ret; for (ptr = kvps; *ptr; ptr++) { - if (!strcmp(*ptr, field)) { - ret = strdup(*(ptr+1)); + if (!strcmp(*ptr, key)) { + *value = strdup(*(ptr+1)); break; } } |