diff options
-rw-r--r-- | include/libiphone/afc.h | 3 | ||||
-rw-r--r-- | src/AFC.c | 29 |
2 files changed, 32 insertions, 0 deletions
diff --git a/include/libiphone/afc.h b/include/libiphone/afc.h index 651621e..77b6f0e 100644 --- a/include/libiphone/afc.h +++ b/include/libiphone/afc.h @@ -106,6 +106,9 @@ afc_error_t afc_make_directory(afc_client_t client, const char *dir); 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); + #ifdef __cplusplus } #endif @@ -468,6 +468,35 @@ 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(). + * + * @param client The client to get device info for. + * @param field The field to get the information for + * + * @return A char * or NULL if there was an error. + */ +char * afc_get_device_info_field(afc_client_t client, const char *field) +{ + char *ret = NULL; + char **kvps, **ptr; + + if (field == NULL || afc_get_device_info(client, &kvps) != AFC_E_SUCCESS) + return NULL; + + for (ptr = kvps; *ptr; ptr++) { + if (!strcmp(*ptr, field)) { + ret = strdup(*(ptr+1)); + break; + } + } + + g_strfreev(kvps); + + return ret; +} + /** Deletes a file or directory. * * @param client The client to use. |