summaryrefslogtreecommitdiffstats
path: root/src/AFC.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/AFC.c')
-rw-r--r--src/AFC.c57
1 files changed, 28 insertions, 29 deletions
diff --git a/src/AFC.c b/src/AFC.c
index af07b56..dfe8af7 100644
--- a/src/AFC.c
+++ b/src/AFC.c
@@ -21,8 +21,7 @@
21 21
22#include <stdio.h> 22#include <stdio.h>
23#include "AFC.h" 23#include "AFC.h"
24#include "plist.h" 24
25#include "utils.h"
26 25
27 26
28// This is the maximum size an AFC data packet can be 27// This is the maximum size an AFC data packet can be
@@ -246,7 +245,7 @@ static int receive_AFC_data(iphone_afc_client_t client, char **dump_here)
246 return retval; 245 return retval;
247 } 246 }
248 247
249 uint32 param1 = buffer[sizeof(AFCPacket)]; 248 uint32_t param1 = buffer[sizeof(AFCPacket)];
250 free(buffer); 249 free(buffer);
251 250
252 if (r_packet->operation == AFC_ERROR && !(client->afc_packet->operation == AFC_DELETE && param1 == 7)) { 251 if (r_packet->operation == AFC_ERROR && !(client->afc_packet->operation == AFC_DELETE && param1 == 7)) {
@@ -475,7 +474,7 @@ iphone_error_t iphone_afc_delete_file(iphone_afc_client_t client, const char *pa
475iphone_error_t iphone_afc_rename_file(iphone_afc_client_t client, const char *from, const char *to) 474iphone_error_t iphone_afc_rename_file(iphone_afc_client_t client, const char *from, const char *to)
476{ 475{
477 char *response = NULL; 476 char *response = NULL;
478 char *send = (char *) malloc(sizeof(char) * (strlen(from) + strlen(to) + 1 + sizeof(uint32))); 477 char *send = (char *) malloc(sizeof(char) * (strlen(from) + strlen(to) + 1 + sizeof(uint32_t)));
479 int bytes = 0; 478 int bytes = 0;
480 479
481 if (!client || !from || !to || !client->afc_packet || !client->connection) 480 if (!client || !from || !to || !client->afc_packet || !client->connection)
@@ -661,7 +660,7 @@ iphone_afc_open_file(iphone_afc_client_t client, const char *filename,
661 iphone_afc_file_mode_t file_mode, iphone_afc_file_t * file) 660 iphone_afc_file_mode_t file_mode, iphone_afc_file_t * file)
662{ 661{
663 iphone_afc_file_t file_loc = NULL; 662 iphone_afc_file_t file_loc = NULL;
664 uint32 ag = 0; 663 uint32_t ag = 0;
665 int bytes = 0, length = 0; 664 int bytes = 0, length = 0;
666 char *data = (char *) malloc(sizeof(char) * (8 + strlen(filename) + 1)); 665 char *data = (char *) malloc(sizeof(char) * (8 + strlen(filename) + 1));
667 666
@@ -796,8 +795,8 @@ iphone_afc_write_file(iphone_afc_client_t client, iphone_afc_file_t file,
796{ 795{
797 char *acknowledgement = NULL; 796 char *acknowledgement = NULL;
798 const int MAXIMUM_WRITE_SIZE = 1 << 15; 797 const int MAXIMUM_WRITE_SIZE = 1 << 15;
799 uint32 zero = 0, current_count = 0, i = 0; 798 uint32_t zero = 0, current_count = 0, i = 0;
800 uint32 segments = (length / MAXIMUM_WRITE_SIZE); 799 uint32_t segments = (length / MAXIMUM_WRITE_SIZE);
801 int bytes_loc = 0; 800 int bytes_loc = 0;
802 char *out_buffer = NULL; 801 char *out_buffer = NULL;
803 802
@@ -815,8 +814,8 @@ iphone_afc_write_file(iphone_afc_client_t client, iphone_afc_file_t file,
815 client->afc_packet->entire_length = client->afc_packet->this_length + MAXIMUM_WRITE_SIZE; 814 client->afc_packet->entire_length = client->afc_packet->this_length + MAXIMUM_WRITE_SIZE;
816 client->afc_packet->operation = AFC_WRITE; 815 client->afc_packet->operation = AFC_WRITE;
817 out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket)); 816 out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket));
818 memcpy(out_buffer, (char *) &file->filehandle, sizeof(uint32)); 817 memcpy(out_buffer, (char *) &file->filehandle, sizeof(uint32_t));
819 memcpy(out_buffer + 4, (char *) &zero, sizeof(uint32)); 818 memcpy(out_buffer + 4, (char *) &zero, sizeof(uint32_t));
820 memcpy(out_buffer + 8, data + current_count, MAXIMUM_WRITE_SIZE); 819 memcpy(out_buffer + 8, data + current_count, MAXIMUM_WRITE_SIZE);
821 bytes_loc = dispatch_AFC_packet(client, out_buffer, MAXIMUM_WRITE_SIZE + 8); 820 bytes_loc = dispatch_AFC_packet(client, out_buffer, MAXIMUM_WRITE_SIZE + 8);
822 if (bytes_loc < 0) { 821 if (bytes_loc < 0) {
@@ -848,8 +847,8 @@ iphone_afc_write_file(iphone_afc_client_t client, iphone_afc_file_t file,
848 client->afc_packet->entire_length = client->afc_packet->this_length + (length - current_count); 847 client->afc_packet->entire_length = client->afc_packet->this_length + (length - current_count);
849 client->afc_packet->operation = AFC_WRITE; 848 client->afc_packet->operation = AFC_WRITE;
850 out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket)); 849 out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket));
851 memcpy(out_buffer, (char *) &file->filehandle, sizeof(uint32)); 850 memcpy(out_buffer, (char *) &file->filehandle, sizeof(uint32_t));
852 memcpy(out_buffer + 4, (char *) &zero, sizeof(uint32)); 851 memcpy(out_buffer + 4, (char *) &zero, sizeof(uint32_t));
853 memcpy(out_buffer + 8, data + current_count, (length - current_count)); 852 memcpy(out_buffer + 8, data + current_count, (length - current_count));
854 bytes_loc = dispatch_AFC_packet(client, out_buffer, (length - current_count) + 8); 853 bytes_loc = dispatch_AFC_packet(client, out_buffer, (length - current_count) + 8);
855 free(out_buffer); 854 free(out_buffer);
@@ -884,7 +883,7 @@ iphone_error_t iphone_afc_close_file(iphone_afc_client_t client, iphone_afc_file
884 if (!client || !file) 883 if (!client || !file)
885 return IPHONE_E_INVALID_ARG; 884 return IPHONE_E_INVALID_ARG;
886 char *buffer = malloc(sizeof(char) * 8); 885 char *buffer = malloc(sizeof(char) * 8);
887 uint32 zero = 0; 886 uint32_t zero = 0;
888 int bytes = 0; 887 int bytes = 0;
889 888
890 afc_lock(client); 889 afc_lock(client);
@@ -892,8 +891,8 @@ iphone_error_t iphone_afc_close_file(iphone_afc_client_t client, iphone_afc_file
892 log_debug_msg("afc_close_file: File handle %i\n", file->filehandle); 891 log_debug_msg("afc_close_file: File handle %i\n", file->filehandle);
893 892
894 // Send command 893 // Send command
895 memcpy(buffer, &file->filehandle, sizeof(uint32)); 894 memcpy(buffer, &file->filehandle, sizeof(uint32_t));
896 memcpy(buffer + sizeof(uint32), &zero, sizeof(zero)); 895 memcpy(buffer + sizeof(uint32_t), &zero, sizeof(zero));
897 client->afc_packet->operation = AFC_FILE_CLOSE; 896 client->afc_packet->operation = AFC_FILE_CLOSE;
898 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 897 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
899 bytes = dispatch_AFC_packet(client, buffer, sizeof(char) * 8); 898 bytes = dispatch_AFC_packet(client, buffer, sizeof(char) * 8);
@@ -939,7 +938,7 @@ iphone_error_t iphone_afc_lock_file(iphone_afc_client_t client, iphone_afc_file_
939 if (!client || !file) 938 if (!client || !file)
940 return IPHONE_E_INVALID_ARG; 939 return IPHONE_E_INVALID_ARG;
941 char *buffer = malloc(16); 940 char *buffer = malloc(16);
942 uint32 zero = 0; 941 uint32_t zero = 0;
943 int bytes = 0; 942 int bytes = 0;
944 uint64_t op = operation; 943 uint64_t op = operation;
945 944
@@ -948,8 +947,8 @@ iphone_error_t iphone_afc_lock_file(iphone_afc_client_t client, iphone_afc_file_
948 log_debug_msg("afc_lock_file: File handle %i\n", file->filehandle); 947 log_debug_msg("afc_lock_file: File handle %i\n", file->filehandle);
949 948
950 // Send command 949 // Send command
951 memcpy(buffer, &file->filehandle, sizeof(uint32)); 950 memcpy(buffer, &file->filehandle, sizeof(uint32_t));
952 memcpy(buffer + sizeof(uint32), &zero, sizeof(zero)); 951 memcpy(buffer + sizeof(uint32_t), &zero, sizeof(zero));
953 memcpy(buffer + 8, &op, 8); 952 memcpy(buffer + 8, &op, 8);
954 953
955 client->afc_packet->operation = AFC_FILE_LOCK; 954 client->afc_packet->operation = AFC_FILE_LOCK;
@@ -986,7 +985,7 @@ iphone_error_t iphone_afc_lock_file(iphone_afc_client_t client, iphone_afc_file_
986iphone_error_t iphone_afc_seek_file(iphone_afc_client_t client, iphone_afc_file_t file, int seekpos) 985iphone_error_t iphone_afc_seek_file(iphone_afc_client_t client, iphone_afc_file_t file, int seekpos)
987{ 986{
988 char *buffer = (char *) malloc(sizeof(char) * 24); 987 char *buffer = (char *) malloc(sizeof(char) * 24);
989 uint32 seekto = 0, zero = 0; 988 uint32_t seekto = 0, zero = 0;
990 int bytes = 0; 989 int bytes = 0;
991 990
992 if (seekpos < 0) 991 if (seekpos < 0)
@@ -996,12 +995,12 @@ iphone_error_t iphone_afc_seek_file(iphone_afc_client_t client, iphone_afc_file_
996 995
997 // Send the command 996 // Send the command
998 seekto = seekpos; 997 seekto = seekpos;
999 memcpy(buffer, &file->filehandle, sizeof(uint32)); // handle 998 memcpy(buffer, &file->filehandle, sizeof(uint32_t)); // handle
1000 memcpy(buffer + 4, &zero, sizeof(uint32)); // pad 999 memcpy(buffer + 4, &zero, sizeof(uint32_t)); // pad
1001 memcpy(buffer + 8, &zero, sizeof(uint32)); // fromwhere 1000 memcpy(buffer + 8, &zero, sizeof(uint32_t)); // fromwhere
1002 memcpy(buffer + 12, &zero, sizeof(uint32)); // pad 1001 memcpy(buffer + 12, &zero, sizeof(uint32_t)); // pad
1003 memcpy(buffer + 16, &seekto, sizeof(uint32)); // offset 1002 memcpy(buffer + 16, &seekto, sizeof(uint32_t)); // offset
1004 memcpy(buffer + 20, &zero, sizeof(uint32)); // pad 1003 memcpy(buffer + 20, &zero, sizeof(uint32_t)); // pad
1005 client->afc_packet->operation = AFC_FILE_SEEK; 1004 client->afc_packet->operation = AFC_FILE_SEEK;
1006 client->afc_packet->this_length = client->afc_packet->entire_length = 0; 1005 client->afc_packet->this_length = client->afc_packet->entire_length = 0;
1007 bytes = dispatch_AFC_packet(client, buffer, 23); 1006 bytes = dispatch_AFC_packet(client, buffer, 23);
@@ -1041,14 +1040,14 @@ iphone_error_t iphone_afc_truncate_file(iphone_afc_client_t client, iphone_afc_f
1041{ 1040{
1042 char *buffer = (char *) malloc(sizeof(char) * 16); 1041 char *buffer = (char *) malloc(sizeof(char) * 16);
1043 int bytes = 0; 1042 int bytes = 0;
1044 uint32 zero = 0; 1043 uint32_t zero = 0;
1045 1044
1046 afc_lock(client); 1045 afc_lock(client);
1047 1046
1048 // Send command 1047 // Send command
1049 memcpy(buffer, &file->filehandle, sizeof(uint32)); // handle 1048 memcpy(buffer, &file->filehandle, sizeof(uint32_t)); // handle
1050 memcpy(buffer + 4, &zero, sizeof(uint32)); // pad 1049 memcpy(buffer + 4, &zero, sizeof(uint32_t)); // pad
1051 memcpy(buffer + 8, &newsize, sizeof(uint32)); // newsize 1050 memcpy(buffer + 8, &newsize, sizeof(uint32_t)); // newsize
1052 memcpy(buffer + 12, &zero, 3); // pad 1051 memcpy(buffer + 12, &zero, 3); // pad
1053 client->afc_packet->operation = AFC_FILE_TRUNCATE; 1052 client->afc_packet->operation = AFC_FILE_TRUNCATE;
1054 client->afc_packet->this_length = client->afc_packet->entire_length = 0; 1053 client->afc_packet->this_length = client->afc_packet->entire_length = 0;
@@ -1121,7 +1120,7 @@ iphone_error_t iphone_afc_truncate(iphone_afc_client_t client, const char *path,
1121} 1120}
1122 1121
1123 1122
1124uint32 iphone_afc_get_file_handle(iphone_afc_file_t file) 1123uint32_t iphone_afc_get_file_handle(iphone_afc_file_t file)
1125{ 1124{
1126 return file->filehandle; 1125 return file->filehandle;
1127} 1126}