diff options
Diffstat (limited to 'src/AFC.c')
| -rw-r--r-- | src/AFC.c | 130 |
1 files changed, 70 insertions, 60 deletions
| @@ -58,7 +58,7 @@ static void afc_unlock(iphone_afc_client_t client) { // just to be pretty | |||
| 58 | * | 58 | * |
| 59 | * @return A handle to the newly-connected client or NULL upon error. | 59 | * @return A handle to the newly-connected client or NULL upon error. |
| 60 | */ | 60 | */ |
| 61 | int iphone_afc_new_client ( iphone_device_t device, int src_port, int dst_port, iphone_afc_client_t *client ) { | 61 | iphone_error_t iphone_afc_new_client ( iphone_device_t device, int src_port, int dst_port, iphone_afc_client_t *client ) { |
| 62 | int ret = IPHONE_E_SUCCESS; | 62 | int ret = IPHONE_E_SUCCESS; |
| 63 | iphone_afc_client_t client_loc = (iphone_afc_client_t)malloc(sizeof(struct iphone_afc_client_int)); | 63 | iphone_afc_client_t client_loc = (iphone_afc_client_t)malloc(sizeof(struct iphone_afc_client_int)); |
| 64 | 64 | ||
| @@ -100,12 +100,14 @@ int iphone_afc_new_client ( iphone_device_t device, int src_port, int dst_port, | |||
| 100 | * | 100 | * |
| 101 | * @param client The client to disconnect. | 101 | * @param client The client to disconnect. |
| 102 | */ | 102 | */ |
| 103 | void iphone_afc_free_client ( iphone_afc_client_t client ) { | 103 | iphone_error_t iphone_afc_free_client ( iphone_afc_client_t client ) { |
| 104 | if (!client || !client->connection || !client->afc_packet) return; | 104 | if (!client || !client->connection || !client->afc_packet) |
| 105 | return IPHONE_E_INVALID_ARG; | ||
| 105 | 106 | ||
| 106 | iphone_mux_free_client(client->connection); | 107 | iphone_mux_free_client(client->connection); |
| 107 | free(client->afc_packet); | 108 | free(client->afc_packet); |
| 108 | free(client); | 109 | free(client); |
| 110 | return IPHONE_E_SUCCESS; | ||
| 109 | } | 111 | } |
| 110 | 112 | ||
| 111 | 113 | ||
| @@ -324,11 +326,12 @@ static char **make_strings_list(char *tokens, int true_length) { | |||
| 324 | * @return A char ** list of files in that directory, terminated by an empty | 326 | * @return A char ** list of files in that directory, terminated by an empty |
| 325 | * string for now or NULL if there was an error. | 327 | * string for now or NULL if there was an error. |
| 326 | */ | 328 | */ |
| 327 | char **iphone_afc_get_dir_list ( iphone_afc_client_t client, const char *dir) { | 329 | iphone_error_t iphone_afc_get_dir_list ( iphone_afc_client_t client, const char *dir, char ***list) { |
| 328 | int bytes = 0; | 330 | int bytes = 0; |
| 329 | char *data = NULL, **list = NULL; | 331 | char *data = NULL, **list_loc = NULL; |
| 332 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; | ||
| 330 | 333 | ||
| 331 | if (!client || !dir) return NULL; | 334 | if (!client || !dir || !list) return IPHONE_E_INVALID_ARG; |
| 332 | 335 | ||
| 333 | afc_lock(client); | 336 | afc_lock(client); |
| 334 | 337 | ||
| @@ -339,23 +342,25 @@ char **iphone_afc_get_dir_list ( iphone_afc_client_t client, const char *dir) { | |||
| 339 | bytes = dispatch_AFC_packet(client, dir, strlen(dir)); | 342 | bytes = dispatch_AFC_packet(client, dir, strlen(dir)); |
| 340 | if (bytes <= 0) { | 343 | if (bytes <= 0) { |
| 341 | afc_unlock(client); | 344 | afc_unlock(client); |
| 342 | return NULL; | 345 | return IPHONE_E_NOT_ENOUGH_DATA; |
| 343 | } | 346 | } |
| 344 | 347 | ||
| 345 | // Receive the data | 348 | // Receive the data |
| 346 | bytes = receive_AFC_data(client, &data); | 349 | bytes = receive_AFC_data(client, &data); |
| 347 | if (bytes < 0 && !data) { | 350 | if (bytes < 0 && !data) { |
| 348 | afc_unlock(client); | 351 | afc_unlock(client); |
| 349 | return NULL; | 352 | return IPHONE_E_NOT_ENOUGH_DATA; |
| 350 | } | 353 | } |
| 351 | 354 | ||
| 352 | // Parse the data | 355 | // Parse the data |
| 353 | list = make_strings_list(data, bytes); | 356 | list_loc = make_strings_list(data, bytes); |
| 357 | if (list_loc) ret = IPHONE_E_SUCCESS; | ||
| 354 | if (data) free(data); | 358 | if (data) free(data); |
| 355 | 359 | ||
| 356 | afc_unlock(client); | 360 | afc_unlock(client); |
| 361 | *list = list_loc; | ||
| 357 | 362 | ||
| 358 | return list; | 363 | return ret; |
| 359 | } | 364 | } |
| 360 | 365 | ||
| 361 | /** Get device info for a client connection to phone. (free space on disk, etc.) | 366 | /** Get device info for a client connection to phone. (free space on disk, etc.) |
| @@ -365,11 +370,11 @@ char **iphone_afc_get_dir_list ( iphone_afc_client_t client, const char *dir) { | |||
| 365 | * @return A char ** list of parameters as given by AFC or NULL if there was an | 370 | * @return A char ** list of parameters as given by AFC or NULL if there was an |
| 366 | * error. | 371 | * error. |
| 367 | */ | 372 | */ |
| 368 | char **iphone_afc_get_devinfo ( iphone_afc_client_t client ) { | 373 | iphone_error_t iphone_afc_get_devinfo ( iphone_afc_client_t client, char ***infos) { |
| 369 | int bytes = 0; | 374 | int bytes = 0; |
| 370 | char *data = NULL, **list = NULL; | 375 | char *data = NULL, **list = NULL; |
| 371 | 376 | ||
| 372 | if (!client) return NULL; | 377 | if (!client || !infos) return IPHONE_E_INVALID_ARG; |
| 373 | 378 | ||
| 374 | afc_lock(client); | 379 | afc_lock(client); |
| 375 | 380 | ||
| @@ -379,14 +384,14 @@ char **iphone_afc_get_devinfo ( iphone_afc_client_t client ) { | |||
| 379 | bytes = dispatch_AFC_packet(client, NULL, 0); | 384 | bytes = dispatch_AFC_packet(client, NULL, 0); |
| 380 | if (bytes < 0) { | 385 | if (bytes < 0) { |
| 381 | afc_unlock(client); | 386 | afc_unlock(client); |
| 382 | return NULL; | 387 | return IPHONE_E_NOT_ENOUGH_DATA; |
| 383 | } | 388 | } |
| 384 | 389 | ||
| 385 | // Receive the data | 390 | // Receive the data |
| 386 | bytes = receive_AFC_data(client, &data); | 391 | bytes = receive_AFC_data(client, &data); |
| 387 | if (bytes < 0 && !data) { | 392 | if (bytes < 0 && !data) { |
| 388 | afc_unlock(client); | 393 | afc_unlock(client); |
| 389 | return NULL; | 394 | return IPHONE_E_NOT_ENOUGH_DATA; |
| 390 | } | 395 | } |
| 391 | 396 | ||
| 392 | // Parse the data | 397 | // Parse the data |
| @@ -394,8 +399,8 @@ char **iphone_afc_get_devinfo ( iphone_afc_client_t client ) { | |||
| 394 | if (data) free(data); | 399 | if (data) free(data); |
| 395 | 400 | ||
| 396 | afc_unlock(client); | 401 | afc_unlock(client); |
| 397 | 402 | *infos = list; | |
| 398 | return list; | 403 | return IPHONE_E_SUCCESS; |
| 399 | } | 404 | } |
| 400 | 405 | ||
| 401 | /** Deletes a file. | 406 | /** Deletes a file. |
| @@ -406,7 +411,7 @@ char **iphone_afc_get_devinfo ( iphone_afc_client_t client ) { | |||
| 406 | * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG | 411 | * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG |
| 407 | * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. | 412 | * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. |
| 408 | */ | 413 | */ |
| 409 | int iphone_afc_delete_file ( iphone_afc_client_t client, const char *path) { | 414 | iphone_error_t iphone_afc_delete_file ( iphone_afc_client_t client, const char *path) { |
| 410 | char *response = NULL; | 415 | char *response = NULL; |
| 411 | int bytes; | 416 | int bytes; |
| 412 | 417 | ||
| @@ -445,7 +450,7 @@ int iphone_afc_delete_file ( iphone_afc_client_t client, const char *path) { | |||
| 445 | * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG | 450 | * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG |
| 446 | * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. | 451 | * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. |
| 447 | */ | 452 | */ |
| 448 | int iphone_afc_rename_file ( iphone_afc_client_t client, const char *from, const char *to) { | 453 | iphone_error_t iphone_afc_rename_file ( iphone_afc_client_t client, const char *from, const char *to) { |
| 449 | char *response = NULL; | 454 | char *response = NULL; |
| 450 | char *send = (char*)malloc(sizeof(char) * (strlen(from) + strlen(to) + 1 + sizeof(uint32))); | 455 | char *send = (char*)malloc(sizeof(char) * (strlen(from) + strlen(to) + 1 + sizeof(uint32))); |
| 451 | int bytes = 0; | 456 | int bytes = 0; |
| @@ -488,7 +493,7 @@ int iphone_afc_rename_file ( iphone_afc_client_t client, const char *from, const | |||
| 488 | * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG | 493 | * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG |
| 489 | * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. | 494 | * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. |
| 490 | */ | 495 | */ |
| 491 | int iphone_afc_mkdir ( iphone_afc_client_t client, const char *dir) { | 496 | iphone_error_t iphone_afc_mkdir ( iphone_afc_client_t client, const char *dir) { |
| 492 | int bytes = 0; | 497 | int bytes = 0; |
| 493 | char *response = NULL; | 498 | char *response = NULL; |
| 494 | 499 | ||
| @@ -586,7 +591,7 @@ iphone_afc_file_t afc_get_file_info(iphone_afc_client_t client, const char *path | |||
| 586 | * @return A pointer to an AFCFile struct containing the information received, | 591 | * @return A pointer to an AFCFile struct containing the information received, |
| 587 | * or NULL on failure. | 592 | * or NULL on failure. |
| 588 | */ | 593 | */ |
| 589 | int iphone_afc_get_file_attr ( iphone_afc_client_t client, const char *filename, struct stat *stbuf ) { | 594 | iphone_error_t iphone_afc_get_file_attr ( iphone_afc_client_t client, const char *filename, struct stat *stbuf ) { |
| 590 | 595 | ||
| 591 | int ret = IPHONE_E_SUCCESS; | 596 | int ret = IPHONE_E_SUCCESS; |
| 592 | if (!client ||!client->connection || !client->afc_packet || !stbuf) return IPHONE_E_INVALID_ARG; | 597 | if (!client ||!client->connection || !client->afc_packet || !stbuf) return IPHONE_E_INVALID_ARG; |
| @@ -620,7 +625,7 @@ int iphone_afc_get_file_attr ( iphone_afc_client_t client, const char *filename, | |||
| 620 | * received by afc_get_file_info) as well as the handle to the file or | 625 | * received by afc_get_file_info) as well as the handle to the file or |
| 621 | * NULL in the case of failure. | 626 | * NULL in the case of failure. |
| 622 | */ | 627 | */ |
| 623 | int iphone_afc_open_file ( iphone_afc_client_t client, const char *filename, uint32_t file_mode, iphone_afc_file_t *file ) { | 628 | iphone_error_t iphone_afc_open_file ( iphone_afc_client_t client, const char *filename, uint32_t file_mode, iphone_afc_file_t *file ) { |
| 624 | iphone_afc_file_t file_loc = NULL; | 629 | iphone_afc_file_t file_loc = NULL; |
| 625 | uint32 ag = 0; | 630 | uint32 ag = 0; |
| 626 | int bytes = 0, length = 0; | 631 | int bytes = 0, length = 0; |
| @@ -677,12 +682,12 @@ int iphone_afc_open_file ( iphone_afc_client_t client, const char *filename, uin | |||
| 677 | * | 682 | * |
| 678 | * @return The number of bytes read if successful. If there was an error -1. | 683 | * @return The number of bytes read if successful. If there was an error -1. |
| 679 | */ | 684 | */ |
| 680 | int iphone_afc_read_file ( iphone_afc_client_t client, iphone_afc_file_t file, char *data, int length) { | 685 | iphone_error_t iphone_afc_read_file ( iphone_afc_client_t client, iphone_afc_file_t file, char *data, int length, uint32_t *bytes) { |
| 681 | char *input = NULL; | 686 | char *input = NULL; |
| 682 | int current_count = 0, bytes = 0; | 687 | int current_count = 0, bytes_loc = 0; |
| 683 | const int MAXIMUM_READ_SIZE = 1 << 16; | 688 | const int MAXIMUM_READ_SIZE = 1 << 16; |
| 684 | 689 | ||
| 685 | if (!client || !client->afc_packet || !client->connection || !file) return -1; | 690 | if (!client || !client->afc_packet || !client->connection || !file) return IPHONE_E_INVALID_ARG; |
| 686 | if (debug) fprintf(stderr, "afc_read_file called for length %i\n", length); | 691 | if (debug) fprintf(stderr, "afc_read_file called for length %i\n", length); |
| 687 | 692 | ||
| 688 | afc_lock(client); | 693 | afc_lock(client); |
| @@ -698,40 +703,41 @@ int iphone_afc_read_file ( iphone_afc_client_t client, iphone_afc_file_t file, c | |||
| 698 | packet->size = ((length - current_count) < MAXIMUM_READ_SIZE) ? (length - current_count) : MAXIMUM_READ_SIZE; | 703 | packet->size = ((length - current_count) < MAXIMUM_READ_SIZE) ? (length - current_count) : MAXIMUM_READ_SIZE; |
| 699 | client->afc_packet->operation = AFC_READ; | 704 | client->afc_packet->operation = AFC_READ; |
| 700 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; | 705 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; |
| 701 | bytes = dispatch_AFC_packet(client, (char*)packet, sizeof(AFCFilePacket)); | 706 | bytes_loc = dispatch_AFC_packet(client, (char*)packet, sizeof(AFCFilePacket)); |
| 702 | free(packet); | 707 | free(packet); |
| 703 | 708 | ||
| 704 | if (bytes <= 0) { | 709 | if (bytes_loc <= 0) { |
| 705 | afc_unlock(client); | 710 | afc_unlock(client); |
| 706 | return -1; | 711 | return IPHONE_E_NOT_ENOUGH_DATA; |
| 707 | } | 712 | } |
| 708 | 713 | ||
| 709 | // Receive the data | 714 | // Receive the data |
| 710 | bytes = receive_AFC_data(client, &input); | 715 | bytes_loc = receive_AFC_data(client, &input); |
| 711 | if (debug) fprintf(stderr, "afc_read_file: bytes returned: %i\n", bytes); | 716 | if (debug) fprintf(stderr, "afc_read_file: bytes returned: %i\n", bytes_loc); |
| 712 | if (bytes < 0) { | 717 | if (bytes < 0) { |
| 713 | if (input) free(input); | 718 | if (input) free(input); |
| 714 | afc_unlock(client); | 719 | afc_unlock(client); |
| 715 | return -1; | 720 | return IPHONE_E_NOT_ENOUGH_DATA; |
| 716 | } else if (bytes == 0) { | 721 | } else if (bytes == 0) { |
| 717 | if (input) free(input); | 722 | if (input) free(input); |
| 718 | afc_unlock(client); | 723 | afc_unlock(client); |
| 719 | return current_count; | 724 | *bytes = current_count; |
| 725 | return IPHONE_E_SUCCESS; //FIXME check that's actually a success | ||
| 720 | } else { | 726 | } else { |
| 721 | if (input) { | 727 | if (input) { |
| 722 | if (debug) fprintf(stderr, "afc_read_file: %d\n", bytes); | 728 | if (debug) fprintf(stderr, "afc_read_file: %d\n", bytes_loc); |
| 723 | memcpy(data+current_count, input, (bytes > length) ? length : bytes); | 729 | memcpy(data+current_count, input, (bytes_loc > length) ? length : bytes_loc); |
| 724 | free(input); | 730 | free(input); |
| 725 | input = NULL; | 731 | input = NULL; |
| 726 | current_count += (bytes > length) ? length : bytes; | 732 | current_count += (bytes_loc > length) ? length : bytes_loc; |
| 727 | } | 733 | } |
| 728 | } | 734 | } |
| 729 | } | 735 | } |
| 730 | if (debug) fprintf(stderr, "afc_read_file: returning current_count as %i\n", current_count); | 736 | if (debug) fprintf(stderr, "afc_read_file: returning current_count as %i\n", current_count); |
| 731 | 737 | ||
| 732 | afc_unlock(client); | 738 | afc_unlock(client); |
| 733 | 739 | *bytes = current_count; | |
| 734 | return current_count; | 740 | return IPHONE_E_SUCCESS; |
| 735 | } | 741 | } |
| 736 | 742 | ||
| 737 | /** Writes a given number of bytes to a file. | 743 | /** Writes a given number of bytes to a file. |
| @@ -744,13 +750,13 @@ int iphone_afc_read_file ( iphone_afc_client_t client, iphone_afc_file_t file, c | |||
| 744 | * @return The number of bytes written to the file, or a value less than 0 if | 750 | * @return The number of bytes written to the file, or a value less than 0 if |
| 745 | * none were written... | 751 | * none were written... |
| 746 | */ | 752 | */ |
| 747 | int iphone_afc_write_file ( iphone_afc_client_t client, iphone_afc_file_t file, const char *data, int length) { | 753 | iphone_error_t iphone_afc_write_file ( iphone_afc_client_t client, iphone_afc_file_t file, const char *data, int length, uint32_t *bytes) { |
| 748 | char *acknowledgement = NULL; | 754 | char *acknowledgement = NULL; |
| 749 | const int MAXIMUM_WRITE_SIZE = 1 << 16; | 755 | const int MAXIMUM_WRITE_SIZE = 1 << 16; |
| 750 | uint32 zero = 0, bytes = 0, segments = (length / MAXIMUM_WRITE_SIZE), current_count = 0, i = 0; | 756 | uint32 zero = 0, bytes_loc = 0, segments = (length / MAXIMUM_WRITE_SIZE), current_count = 0, i = 0; |
| 751 | char *out_buffer = NULL; | 757 | char *out_buffer = NULL; |
| 752 | 758 | ||
| 753 | if (!client ||!client->afc_packet || !client->connection || !file) return -1; | 759 | if (!client ||!client->afc_packet || !client->connection || !file || !bytes_loc) return IPHONE_E_INVALID_ARG; |
| 754 | 760 | ||
| 755 | afc_lock(client); | 761 | afc_lock(client); |
| 756 | 762 | ||
| @@ -766,19 +772,19 @@ int iphone_afc_write_file ( iphone_afc_client_t client, iphone_afc_file_t file, | |||
| 766 | memcpy(out_buffer, (char*)&file->filehandle, sizeof(uint32)); | 772 | memcpy(out_buffer, (char*)&file->filehandle, sizeof(uint32)); |
| 767 | memcpy(out_buffer+4, (char*)&zero, sizeof(uint32)); | 773 | memcpy(out_buffer+4, (char*)&zero, sizeof(uint32)); |
| 768 | memcpy(out_buffer+8, data+current_count, MAXIMUM_WRITE_SIZE); | 774 | memcpy(out_buffer+8, data+current_count, MAXIMUM_WRITE_SIZE); |
| 769 | bytes = dispatch_AFC_packet(client, out_buffer, MAXIMUM_WRITE_SIZE + 8); | 775 | bytes_loc = dispatch_AFC_packet(client, out_buffer, MAXIMUM_WRITE_SIZE + 8); |
| 770 | if (bytes < 0) { | 776 | if (bytes_loc < 0) { |
| 771 | afc_unlock(client); | 777 | afc_unlock(client); |
| 772 | return bytes; | 778 | return IPHONE_E_NOT_ENOUGH_DATA; |
| 773 | } | 779 | } |
| 774 | free(out_buffer); | 780 | free(out_buffer); |
| 775 | out_buffer = NULL; | 781 | out_buffer = NULL; |
| 776 | 782 | ||
| 777 | current_count += bytes; | 783 | current_count += bytes_loc; |
| 778 | bytes = receive_AFC_data(client, &acknowledgement); | 784 | bytes_loc = receive_AFC_data(client, &acknowledgement); |
| 779 | if (bytes < 0) { | 785 | if (bytes_loc < 0) { |
| 780 | afc_unlock(client); | 786 | afc_unlock(client); |
| 781 | return current_count; | 787 | return IPHONE_E_NOT_ENOUGH_DATA; |
| 782 | } | 788 | } |
| 783 | } | 789 | } |
| 784 | 790 | ||
| @@ -786,7 +792,8 @@ int iphone_afc_write_file ( iphone_afc_client_t client, iphone_afc_file_t file, | |||
| 786 | // this length is fine because it's always sizeof(AFCPacket) + 8, but to be sure we do it again | 792 | // this length is fine because it's always sizeof(AFCPacket) + 8, but to be sure we do it again |
| 787 | if (current_count == length) { | 793 | if (current_count == length) { |
| 788 | afc_unlock(client); | 794 | afc_unlock(client); |
| 789 | return current_count; | 795 | *bytes = current_count; |
| 796 | return IPHONE_E_SUCCESS; | ||
| 790 | } | 797 | } |
| 791 | 798 | ||
| 792 | client->afc_packet->this_length = sizeof(AFCPacket) + 8; | 799 | client->afc_packet->this_length = sizeof(AFCPacket) + 8; |
| @@ -796,25 +803,26 @@ int iphone_afc_write_file ( iphone_afc_client_t client, iphone_afc_file_t file, | |||
| 796 | memcpy(out_buffer, (char*)&file->filehandle, sizeof(uint32)); | 803 | memcpy(out_buffer, (char*)&file->filehandle, sizeof(uint32)); |
| 797 | memcpy(out_buffer+4, (char*)&zero, sizeof(uint32)); | 804 | memcpy(out_buffer+4, (char*)&zero, sizeof(uint32)); |
| 798 | memcpy(out_buffer+8, data+current_count, (length - current_count)); | 805 | memcpy(out_buffer+8, data+current_count, (length - current_count)); |
| 799 | bytes = dispatch_AFC_packet(client, out_buffer, (length - current_count) + 8); | 806 | bytes_loc = dispatch_AFC_packet(client, out_buffer, (length - current_count) + 8); |
| 800 | free(out_buffer); | 807 | free(out_buffer); |
| 801 | out_buffer = NULL; | 808 | out_buffer = NULL; |
| 802 | 809 | ||
| 803 | current_count += bytes; | 810 | current_count += bytes_loc; |
| 804 | 811 | ||
| 805 | if (bytes <= 0) { | 812 | if (bytes_loc <= 0) { |
| 806 | afc_unlock(client); | 813 | afc_unlock(client); |
| 807 | return current_count; | 814 | *bytes = current_count; |
| 815 | return IPHONE_E_SUCCESS; | ||
| 808 | } | 816 | } |
| 809 | 817 | ||
| 810 | zero = bytes; | 818 | zero = bytes_loc; |
| 811 | bytes = receive_AFC_data(client, &acknowledgement); | 819 | bytes_loc = receive_AFC_data(client, &acknowledgement); |
| 812 | afc_unlock(client); | 820 | afc_unlock(client); |
| 813 | if (bytes < 0) { | 821 | if (bytes_loc < 0) { |
| 814 | if (debug) fprintf(stderr, "afc_write_file: uh oh?\n"); | 822 | if (debug) fprintf(stderr, "afc_write_file: uh oh?\n"); |
| 815 | } | 823 | } |
| 816 | 824 | ||
| 817 | return current_count; | 825 | return IPHONE_E_UNKNOWN_ERROR; |
| 818 | } | 826 | } |
| 819 | 827 | ||
| 820 | /** Closes a file on the phone. | 828 | /** Closes a file on the phone. |
| @@ -823,7 +831,8 @@ int iphone_afc_write_file ( iphone_afc_client_t client, iphone_afc_file_t file, | |||
| 823 | * @param file A pointer to an AFCFile struct containing the file handle of the | 831 | * @param file A pointer to an AFCFile struct containing the file handle of the |
| 824 | * file to close. | 832 | * file to close. |
| 825 | */ | 833 | */ |
| 826 | void iphone_afc_close_file ( iphone_afc_client_t client, iphone_afc_file_t file) { | 834 | iphone_error_t iphone_afc_close_file ( iphone_afc_client_t client, iphone_afc_file_t file) { |
| 835 | if (!client || !file) return IPHONE_E_INVALID_ARG; | ||
| 827 | char *buffer = malloc(sizeof(char) * 8); | 836 | char *buffer = malloc(sizeof(char) * 8); |
| 828 | uint32 zero = 0; | 837 | uint32 zero = 0; |
| 829 | int bytes = 0; | 838 | int bytes = 0; |
| @@ -846,7 +855,7 @@ void iphone_afc_close_file ( iphone_afc_client_t client, iphone_afc_file_t file) | |||
| 846 | 855 | ||
| 847 | if (bytes <= 0) { | 856 | if (bytes <= 0) { |
| 848 | afc_unlock(client); | 857 | afc_unlock(client); |
| 849 | return; | 858 | return IPHONE_E_UNKNOWN_ERROR; |
| 850 | } | 859 | } |
| 851 | 860 | ||
| 852 | // Receive the response | 861 | // Receive the response |
| @@ -854,6 +863,7 @@ void iphone_afc_close_file ( iphone_afc_client_t client, iphone_afc_file_t file) | |||
| 854 | if (buffer) free(buffer); | 863 | if (buffer) free(buffer); |
| 855 | free(file); | 864 | free(file); |
| 856 | afc_unlock(client); | 865 | afc_unlock(client); |
| 866 | return IPHONE_E_SUCCESS; | ||
| 857 | } | 867 | } |
| 858 | 868 | ||
| 859 | /** Seeks to a given position of a pre-opened file on the phone. | 869 | /** Seeks to a given position of a pre-opened file on the phone. |
| @@ -865,7 +875,7 @@ void iphone_afc_close_file ( iphone_afc_client_t client, iphone_afc_file_t file) | |||
| 865 | * | 875 | * |
| 866 | * @return IPHONE_E_SUCCESS on success, IPHONE_E_NOT_ENOUGH_DATA on failure. | 876 | * @return IPHONE_E_SUCCESS on success, IPHONE_E_NOT_ENOUGH_DATA on failure. |
| 867 | */ | 877 | */ |
| 868 | int iphone_afc_seek_file ( iphone_afc_client_t client, iphone_afc_file_t file, int seekpos) { | 878 | iphone_error_t iphone_afc_seek_file ( iphone_afc_client_t client, iphone_afc_file_t file, int seekpos) { |
| 869 | char *buffer = (char*)malloc(sizeof(char) * 24); | 879 | char *buffer = (char*)malloc(sizeof(char) * 24); |
| 870 | uint32 seekto = 0, bytes = 0, zero = 0; | 880 | uint32 seekto = 0, bytes = 0, zero = 0; |
| 871 | 881 | ||
| @@ -916,7 +926,7 @@ int iphone_afc_seek_file ( iphone_afc_client_t client, iphone_afc_file_t file, i | |||
| 916 | * @note This function is more akin to ftruncate than truncate, and truncate | 926 | * @note This function is more akin to ftruncate than truncate, and truncate |
| 917 | * calls would have to open the file before calling this, sadly. | 927 | * calls would have to open the file before calling this, sadly. |
| 918 | */ | 928 | */ |
| 919 | int iphone_afc_truncate_file ( iphone_afc_client_t client, iphone_afc_file_t file, uint32_t newsize) { | 929 | iphone_error_t iphone_afc_truncate_file ( iphone_afc_client_t client, iphone_afc_file_t file, uint32_t newsize) { |
| 920 | char *buffer = (char*)malloc(sizeof(char) * 16); | 930 | char *buffer = (char*)malloc(sizeof(char) * 16); |
| 921 | uint32 bytes = 0, zero = 0; | 931 | uint32 bytes = 0, zero = 0; |
| 922 | 932 | ||
