summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2009-07-25 03:46:54 +0200
committerGravatar Martin Szulecki2009-07-25 03:46:54 +0200
commit0e255cfe381caedf0375e6834021333d971f8050 (patch)
treea9c5bcffb2a7cea2e037dad1513a502ffab7df28 /src
parent8415e1f13dfc8c31fe4d1ff695af26189297795b (diff)
downloadlibimobiledevice-0e255cfe381caedf0375e6834021333d971f8050.tar.gz
libimobiledevice-0e255cfe381caedf0375e6834021333d971f8050.tar.bz2
Implement afc_file_tell() and adjust afc_receive_data() to handle it
Diffstat (limited to 'src')
-rw-r--r--src/AFC.c45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/AFC.c b/src/AFC.c
index 87ce78e..6a6d3f2 100644
--- a/src/AFC.c
+++ b/src/AFC.c
@@ -329,6 +329,9 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int *
329 } else if (header.operation == AFC_OP_FILE_OPEN_RES) { 329 } else if (header.operation == AFC_OP_FILE_OPEN_RES) {
330 /* file handle response */ 330 /* file handle response */
331 log_debug_msg("%s: got a file handle response, handle=%lld\n", __func__, param1); 331 log_debug_msg("%s: got a file handle response, handle=%lld\n", __func__, param1);
332 } else if (header.operation == AFC_OP_FILE_TELL_RES) {
333 /* tell response */
334 log_debug_msg("%s: got a tell response, position=%lld\n", __func__, param1);
332 } else { 335 } else {
333 /* unknown operation code received */ 336 /* unknown operation code received */
334 free(*dump_here); 337 free(*dump_here);
@@ -986,8 +989,46 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset,
986 989
987 afc_unlock(client); 990 afc_unlock(client);
988 991
989 if (bytes < 0) { 992 return ret;
990 return IPHONE_E_AFC_ERROR; 993}
994
995/** Returns current position in a pre-opened file on the phone.
996 *
997 * @param client The client to use.
998 * @param handle File handle of a previously opened file.
999 * @param position Position in bytes of indicator
1000 *
1001 * @return AFC_E_SUCCESS on success, AFC_E_NOT_ENOUGH_DATA on failure.
1002 */
1003afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position)
1004{
1005 char *buffer = (char *) malloc(sizeof(char) * 8);
1006 int bytes = 0;
1007 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1008
1009 if (!client || (handle == 0))
1010 return AFC_E_INVALID_ARGUMENT;
1011
1012 afc_lock(client);
1013
1014 // Send the command
1015 memcpy(buffer, &handle, sizeof(uint64_t)); // handle
1016 client->afc_packet->operation = AFC_OP_FILE_TELL;
1017 client->afc_packet->this_length = client->afc_packet->entire_length = 0;
1018 bytes = afc_dispatch_packet(client, buffer, 8);
1019 free(buffer);
1020 buffer = NULL;
1021
1022 if (bytes <= 0) {
1023 afc_unlock(client);
1024 return AFC_E_NOT_ENOUGH_DATA;
1025 }
1026
1027 // Receive the data
1028 ret = afc_receive_data(client, &buffer, &bytes);
1029 if (bytes > 0 && buffer) {
1030 /* Get the position */
1031 memcpy(position, buffer, sizeof(uint64_t));
991 } 1032 }
992 if (buffer) 1033 if (buffer)
993 free(buffer); 1034 free(buffer);