diff options
Diffstat (limited to 'src/AFC.c')
| -rw-r--r-- | src/AFC.c | 28 |
1 files changed, 17 insertions, 11 deletions
| @@ -468,26 +468,32 @@ afc_error_t afc_get_device_info(afc_client_t client, char ***infos) | |||
| 468 | return ret; | 468 | return ret; |
| 469 | } | 469 | } |
| 470 | 470 | ||
| 471 | /** Get a specific field of the device info for a client connection to phone. | 471 | /** Get a specific key of the device info list for a client connection. |
| 472 | * Known values are: Model, FSTotalBytes, FSFreeBytes and FSBlockSize. This is | 472 | * Known key values are: Model, FSTotalBytes, FSFreeBytes and FSBlockSize. |
| 473 | * a helper function for afc_get_device_info(). | 473 | * This is a helper function for afc_get_device_info(). |
| 474 | * | 474 | * |
| 475 | * @param client The client to get device info for. | 475 | * @param client The client to get device info for. |
| 476 | * @param field The field to get the information for | 476 | * @param key The key to get the value of. |
| 477 | * @param value The value for the key if successful or NULL otherwise. | ||
| 477 | * | 478 | * |
| 478 | * @return A char * or NULL if there was an error. | 479 | * @return AFC_E_SUCCESS on success or an AFC_E_* error value. |
| 479 | */ | 480 | */ |
| 480 | char * afc_get_device_info_field(afc_client_t client, const char *field) | 481 | afc_error_t afc_get_device_info_key(afc_client_t client, const char *key, char **value) |
| 481 | { | 482 | { |
| 482 | char *ret = NULL; | 483 | afc_error_t ret = AFC_E_INTERNAL_ERROR; |
| 483 | char **kvps, **ptr; | 484 | char **kvps, **ptr; |
| 484 | 485 | ||
| 485 | if (field == NULL || afc_get_device_info(client, &kvps) != AFC_E_SUCCESS) | 486 | *value = NULL; |
| 486 | return NULL; | 487 | if (key == NULL) |
| 488 | return AFC_E_INVALID_ARGUMENT; | ||
| 489 | |||
| 490 | ret = afc_get_device_info(client, &kvps); | ||
| 491 | if (ret != AFC_E_SUCCESS) | ||
| 492 | return ret; | ||
| 487 | 493 | ||
| 488 | for (ptr = kvps; *ptr; ptr++) { | 494 | for (ptr = kvps; *ptr; ptr++) { |
| 489 | if (!strcmp(*ptr, field)) { | 495 | if (!strcmp(*ptr, key)) { |
| 490 | ret = strdup(*(ptr+1)); | 496 | *value = strdup(*(ptr+1)); |
| 491 | break; | 497 | break; |
| 492 | } | 498 | } |
| 493 | } | 499 | } |
