summaryrefslogtreecommitdiffstats
path: root/src/AFC.c
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2009-07-25 00:19:47 +0200
committerGravatar Martin Szulecki2009-07-25 00:19:47 +0200
commitc3d9e80985ef52eebb25bb07512cabc52786c130 (patch)
tree12e7b989b4beba1ca32c5629e215edf98a8ae1d0 /src/AFC.c
parent19a28b0ed18c8ca2f855e7d129ddcdb8c939a707 (diff)
downloadlibimobiledevice-c3d9e80985ef52eebb25bb07512cabc52786c130.tar.gz
libimobiledevice-c3d9e80985ef52eebb25bb07512cabc52786c130.tar.bz2
Define remaining unknown AFC operations; SUCCESS is actually a DATA operation
Diffstat (limited to 'src/AFC.c')
-rw-r--r--src/AFC.c43
1 files changed, 22 insertions, 21 deletions
diff --git a/src/AFC.c b/src/AFC.c
index 8cc88f1..1151f23 100644
--- a/src/AFC.c
+++ b/src/AFC.c
@@ -341,7 +341,7 @@ static int receive_AFC_data(afc_client_t client, char **dump_here)
341 && header.entire_length == sizeof(AFCPacket)) { 341 && header.entire_length == sizeof(AFCPacket)) {
342 log_debug_msg("%s: Empty AFCPacket received!\n", __func__); 342 log_debug_msg("%s: Empty AFCPacket received!\n", __func__);
343 *dump_here = NULL; 343 *dump_here = NULL;
344 if (header.operation == AFC_SUCCESS_RESPONSE) { 344 if (header.operation == AFC_OP_DATA) {
345 return 0; 345 return 0;
346 } else { 346 } else {
347 client->afcerror = EIO; 347 client->afcerror = EIO;
@@ -396,13 +396,13 @@ static int receive_AFC_data(afc_client_t client, char **dump_here)
396 } 396 }
397 397
398 // check for errors 398 // check for errors
399 if (header.operation == AFC_SUCCESS_RESPONSE) { 399 if (header.operation == AFC_OP_DATA) {
400 // we got a positive response! 400 // we got a positive response!
401 log_debug_msg("%s: got a success response\n", __func__); 401 log_debug_msg("%s: got a success response\n", __func__);
402 } else if (header.operation == AFC_FILE_HANDLE) { 402 } else if (header.operation == AFC_OP_FILE_OPEN_RES) {
403 // we got a file handle response 403 // we got a file handle response
404 log_debug_msg("%s: got a file handle response, handle=%lld\n", __func__, param1); 404 log_debug_msg("%s: got a file handle response, handle=%lld\n", __func__, param1);
405 } else if (header.operation == AFC_ERROR) { 405 } else if (header.operation == AFC_OP_STATUS) {
406 // error message received 406 // error message received
407 if (param1 == 0) { 407 if (param1 == 0) {
408 // ERROR_SUCCESS, this is not an error! 408 // ERROR_SUCCESS, this is not an error!
@@ -418,7 +418,7 @@ static int receive_AFC_data(afc_client_t client, char **dump_here)
418 return -1; 418 return -1;
419 } 419 }
420 } else { 420 } else {
421 // unknown operation code received! 421 /* unknown operation code received */
422 free(*dump_here); 422 free(*dump_here);
423 *dump_here = NULL; 423 *dump_here = NULL;
424 424
@@ -481,7 +481,7 @@ iphone_error_t afc_get_dir_list(afc_client_t client, const char *dir, char ***li
481 afc_lock(client); 481 afc_lock(client);
482 482
483 // Send the command 483 // Send the command
484 client->afc_packet->operation = AFC_LIST_DIR; 484 client->afc_packet->operation = AFC_OP_READ_DIR;
485 client->afc_packet->entire_length = 0; 485 client->afc_packet->entire_length = 0;
486 client->afc_packet->this_length = 0; 486 client->afc_packet->this_length = 0;
487 bytes = dispatch_AFC_packet(client, dir, strlen(dir)+1); 487 bytes = dispatch_AFC_packet(client, dir, strlen(dir)+1);
@@ -526,7 +526,7 @@ iphone_error_t afc_get_devinfo(afc_client_t client, char ***infos)
526 afc_lock(client); 526 afc_lock(client);
527 527
528 // Send the command 528 // Send the command
529 client->afc_packet->operation = AFC_GET_DEVINFO; 529 client->afc_packet->operation = AFC_OP_GET_DEVINFO;
530 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 530 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
531 bytes = dispatch_AFC_packet(client, NULL, 0); 531 bytes = dispatch_AFC_packet(client, NULL, 0);
532 if (bytes < 0) { 532 if (bytes < 0) {
@@ -545,6 +545,7 @@ iphone_error_t afc_get_devinfo(afc_client_t client, char ***infos)
545 free(data); 545 free(data);
546 546
547 afc_unlock(client); 547 afc_unlock(client);
548
548 *infos = list; 549 *infos = list;
549 return IPHONE_E_SUCCESS; 550 return IPHONE_E_SUCCESS;
550} 551}
@@ -569,7 +570,7 @@ iphone_error_t afc_delete_file(afc_client_t client, const char *path)
569 570
570 // Send command 571 // Send command
571 client->afc_packet->this_length = client->afc_packet->entire_length = 0; 572 client->afc_packet->this_length = client->afc_packet->entire_length = 0;
572 client->afc_packet->operation = AFC_DELETE; 573 client->afc_packet->operation = AFC_OP_REMOVE_PATH;
573 bytes = dispatch_AFC_packet(client, path, strlen(path)+1); 574 bytes = dispatch_AFC_packet(client, path, strlen(path)+1);
574 if (bytes <= 0) { 575 if (bytes <= 0) {
575 afc_unlock(client); 576 afc_unlock(client);
@@ -612,7 +613,7 @@ iphone_error_t afc_rename_file(afc_client_t client, const char *from, const char
612 memcpy(send, from, strlen(from) + 1); 613 memcpy(send, from, strlen(from) + 1);
613 memcpy(send + strlen(from) + 1, to, strlen(to) + 1); 614 memcpy(send + strlen(from) + 1, to, strlen(to) + 1);
614 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 615 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
615 client->afc_packet->operation = AFC_RENAME; 616 client->afc_packet->operation = AFC_OP_RENAME_PATH;
616 bytes = dispatch_AFC_packet(client, send, strlen(to)+1 + strlen(from)+1); 617 bytes = dispatch_AFC_packet(client, send, strlen(to)+1 + strlen(from)+1);
617 free(send); 618 free(send);
618 if (bytes <= 0) { 619 if (bytes <= 0) {
@@ -652,7 +653,7 @@ iphone_error_t afc_mkdir(afc_client_t client, const char *dir)
652 afc_lock(client); 653 afc_lock(client);
653 654
654 // Send command 655 // Send command
655 client->afc_packet->operation = AFC_MAKE_DIR; 656 client->afc_packet->operation = AFC_OP_MAKE_DIR;
656 client->afc_packet->this_length = client->afc_packet->entire_length = 0; 657 client->afc_packet->this_length = client->afc_packet->entire_length = 0;
657 bytes = dispatch_AFC_packet(client, dir, strlen(dir)+1); 658 bytes = dispatch_AFC_packet(client, dir, strlen(dir)+1);
658 if (bytes <= 0) { 659 if (bytes <= 0) {
@@ -695,7 +696,7 @@ iphone_error_t afc_get_file_info(afc_client_t client, const char *path, char ***
695 afc_lock(client); 696 afc_lock(client);
696 697
697 // Send command 698 // Send command
698 client->afc_packet->operation = AFC_GET_INFO; 699 client->afc_packet->operation = AFC_OP_GET_FILE_INFO;
699 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 700 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
700 dispatch_AFC_packet(client, path, strlen(path)+1); 701 dispatch_AFC_packet(client, path, strlen(path)+1);
701 702
@@ -747,7 +748,7 @@ afc_open_file(afc_client_t client, const char *filename,
747 memcpy(data + 4, &ag, 4); 748 memcpy(data + 4, &ag, 4);
748 memcpy(data + 8, filename, strlen(filename)); 749 memcpy(data + 8, filename, strlen(filename));
749 data[8 + strlen(filename)] = '\0'; 750 data[8 + strlen(filename)] = '\0';
750 client->afc_packet->operation = AFC_FILE_OPEN; 751 client->afc_packet->operation = AFC_OP_FILE_OPEN;
751 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 752 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
752 bytes = dispatch_AFC_packet(client, data, 8 + strlen(filename) + 1); 753 bytes = dispatch_AFC_packet(client, data, 8 + strlen(filename) + 1);
753 free(data); 754 free(data);
@@ -808,7 +809,7 @@ afc_read_file(afc_client_t client, uint64_t handle, char *data, int length, uint
808 AFCFilePacket *packet = (AFCFilePacket *) malloc(sizeof(AFCFilePacket)); 809 AFCFilePacket *packet = (AFCFilePacket *) malloc(sizeof(AFCFilePacket));
809 packet->filehandle = handle; 810 packet->filehandle = handle;
810 packet->size = ((length - current_count) < MAXIMUM_READ_SIZE) ? (length - current_count) : MAXIMUM_READ_SIZE; 811 packet->size = ((length - current_count) < MAXIMUM_READ_SIZE) ? (length - current_count) : MAXIMUM_READ_SIZE;
811 client->afc_packet->operation = AFC_READ; 812 client->afc_packet->operation = AFC_OP_READ;
812 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 813 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
813 bytes_loc = dispatch_AFC_packet(client, (char *) packet, sizeof(AFCFilePacket)); 814 bytes_loc = dispatch_AFC_packet(client, (char *) packet, sizeof(AFCFilePacket));
814 free(packet); 815 free(packet);
@@ -880,7 +881,7 @@ afc_write_file(afc_client_t client, uint64_t handle,
880 // Send the segment 881 // Send the segment
881 client->afc_packet->this_length = sizeof(AFCPacket) + 8; 882 client->afc_packet->this_length = sizeof(AFCPacket) + 8;
882 client->afc_packet->entire_length = client->afc_packet->this_length + MAXIMUM_WRITE_SIZE; 883 client->afc_packet->entire_length = client->afc_packet->this_length + MAXIMUM_WRITE_SIZE;
883 client->afc_packet->operation = AFC_WRITE; 884 client->afc_packet->operation = AFC_OP_WRITE;
884 out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket)); 885 out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket));
885 memcpy(out_buffer, (char *)&handle, sizeof(uint64_t)); 886 memcpy(out_buffer, (char *)&handle, sizeof(uint64_t));
886 memcpy(out_buffer + 8, data + current_count, MAXIMUM_WRITE_SIZE); 887 memcpy(out_buffer + 8, data + current_count, MAXIMUM_WRITE_SIZE);
@@ -914,7 +915,7 @@ afc_write_file(afc_client_t client, uint64_t handle,
914 915
915 client->afc_packet->this_length = sizeof(AFCPacket) + 8; 916 client->afc_packet->this_length = sizeof(AFCPacket) + 8;
916 client->afc_packet->entire_length = client->afc_packet->this_length + (length - current_count); 917 client->afc_packet->entire_length = client->afc_packet->this_length + (length - current_count);
917 client->afc_packet->operation = AFC_WRITE; 918 client->afc_packet->operation = AFC_OP_WRITE;
918 out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket)); 919 out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket));
919 memcpy(out_buffer, (char *) &handle, sizeof(uint64_t)); 920 memcpy(out_buffer, (char *) &handle, sizeof(uint64_t));
920 memcpy(out_buffer + 8, data + current_count, (length - current_count)); 921 memcpy(out_buffer + 8, data + current_count, (length - current_count));
@@ -960,7 +961,7 @@ iphone_error_t afc_close_file(afc_client_t client, uint64_t handle)
960 961
961 // Send command 962 // Send command
962 memcpy(buffer, &handle, sizeof(uint64_t)); 963 memcpy(buffer, &handle, sizeof(uint64_t));
963 client->afc_packet->operation = AFC_FILE_CLOSE; 964 client->afc_packet->operation = AFC_OP_FILE_CLOSE;
964 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 965 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
965 bytes = dispatch_AFC_packet(client, buffer, 8); 966 bytes = dispatch_AFC_packet(client, buffer, 8);
966 free(buffer); 967 free(buffer);
@@ -1007,7 +1008,7 @@ iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, afc_lock_op_t
1007 memcpy(buffer, &handle, sizeof(uint64_t)); 1008 memcpy(buffer, &handle, sizeof(uint64_t));
1008 memcpy(buffer + 8, &op, 8); 1009 memcpy(buffer + 8, &op, 8);
1009 1010
1010 client->afc_packet->operation = AFC_FILE_LOCK; 1011 client->afc_packet->operation = AFC_OP_FILE_LOCK;
1011 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 1012 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
1012 bytes = dispatch_AFC_packet(client, buffer, 16); 1013 bytes = dispatch_AFC_packet(client, buffer, 16);
1013 free(buffer); 1014 free(buffer);
@@ -1053,7 +1054,7 @@ iphone_error_t afc_seek_file(afc_client_t client, uint64_t handle, int64_t offse
1053 memcpy(buffer + 8, &whence, sizeof(int32_t)); // fromwhere 1054 memcpy(buffer + 8, &whence, sizeof(int32_t)); // fromwhere
1054 memcpy(buffer + 12, &zero, sizeof(uint32_t)); // pad 1055 memcpy(buffer + 12, &zero, sizeof(uint32_t)); // pad
1055 memcpy(buffer + 16, &offset, sizeof(uint64_t)); // offset 1056 memcpy(buffer + 16, &offset, sizeof(uint64_t)); // offset
1056 client->afc_packet->operation = AFC_FILE_SEEK; 1057 client->afc_packet->operation = AFC_OP_FILE_SEEK;
1057 client->afc_packet->this_length = client->afc_packet->entire_length = 0; 1058 client->afc_packet->this_length = client->afc_packet->entire_length = 0;
1058 bytes = dispatch_AFC_packet(client, buffer, 24); 1059 bytes = dispatch_AFC_packet(client, buffer, 24);
1059 free(buffer); 1060 free(buffer);
@@ -1097,7 +1098,7 @@ iphone_error_t afc_truncate_file(afc_client_t client, uint64_t handle, uint64_t
1097 // Send command 1098 // Send command
1098 memcpy(buffer, &handle, sizeof(uint64_t)); // handle 1099 memcpy(buffer, &handle, sizeof(uint64_t)); // handle
1099 memcpy(buffer + 8, &newsize, sizeof(uint64_t)); // newsize 1100 memcpy(buffer + 8, &newsize, sizeof(uint64_t)); // newsize
1100 client->afc_packet->operation = AFC_FILE_TRUNCATE; 1101 client->afc_packet->operation = AFC_OP_FILE_SET_SIZE;
1101 client->afc_packet->this_length = client->afc_packet->entire_length = 0; 1102 client->afc_packet->this_length = client->afc_packet->entire_length = 0;
1102 bytes = dispatch_AFC_packet(client, buffer, 16); 1103 bytes = dispatch_AFC_packet(client, buffer, 16);
1103 free(buffer); 1104 free(buffer);
@@ -1145,7 +1146,7 @@ iphone_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize
1145 memcpy(send, &size_requested, 8); 1146 memcpy(send, &size_requested, 8);
1146 memcpy(send + 8, path, strlen(path) + 1); 1147 memcpy(send + 8, path, strlen(path) + 1);
1147 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 1148 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
1148 client->afc_packet->operation = AFC_TRUNCATE; 1149 client->afc_packet->operation = AFC_OP_TRUNCATE;
1149 bytes = dispatch_AFC_packet(client, send, 8 + strlen(path) + 1); 1150 bytes = dispatch_AFC_packet(client, send, 8 + strlen(path) + 1);
1150 free(send); 1151 free(send);
1151 if (bytes <= 0) { 1152 if (bytes <= 0) {
@@ -1196,7 +1197,7 @@ iphone_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, cons
1196 memcpy(send + 8, target, strlen(target) + 1); 1197 memcpy(send + 8, target, strlen(target) + 1);
1197 memcpy(send + 8 + strlen(target) + 1, linkname, strlen(linkname) + 1); 1198 memcpy(send + 8 + strlen(target) + 1, linkname, strlen(linkname) + 1);
1198 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 1199 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
1199 client->afc_packet->operation = AFC_MAKE_LINK; 1200 client->afc_packet->operation = AFC_OP_MAKE_LINK;
1200 bytes = dispatch_AFC_packet(client, send, 8 + strlen(linkname) + 1 + strlen(target) + 1); 1201 bytes = dispatch_AFC_packet(client, send, 8 + strlen(linkname) + 1 + strlen(target) + 1);
1201 free(send); 1202 free(send);
1202 if (bytes <= 0) { 1203 if (bytes <= 0) {