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, 30 insertions, 27 deletions
diff --git a/src/AFC.c b/src/AFC.c
index 960d640..e666c45 100644
--- a/src/AFC.c
+++ b/src/AFC.c
@@ -24,8 +24,11 @@
24#include <errno.h> 24#include <errno.h>
25#include <unistd.h> 25#include <unistd.h>
26#include "AFC.h" 26#include "AFC.h"
27#include "iphone.h"
27#include "utils.h" 28#include "utils.h"
28 29
30#include <libiphone/afc.h>
31
29 32
30// This is the maximum size an AFC data packet can be 33// This is the maximum size an AFC data packet can be
31const int MAXIMUM_PACKET_SIZE = (2 << 15); 34const int MAXIMUM_PACKET_SIZE = (2 << 15);
@@ -34,7 +37,7 @@ const int MAXIMUM_PACKET_SIZE = (2 << 15);
34 * 37 *
35 * @param client The AFC client connection to lock 38 * @param client The AFC client connection to lock
36 */ 39 */
37static void afc_lock(iphone_afc_client_t client) 40static void afc_lock(afc_client_t client)
38{ 41{
39 log_debug_msg("Locked\n"); 42 log_debug_msg("Locked\n");
40 /*while (client->lock) { 43 /*while (client->lock) {
@@ -48,7 +51,7 @@ static void afc_lock(iphone_afc_client_t client)
48 * 51 *
49 * @param client The AFC 52 * @param client The AFC
50 */ 53 */
51static void afc_unlock(iphone_afc_client_t client) 54static void afc_unlock(afc_client_t client)
52{ // just to be pretty 55{ // just to be pretty
53 log_debug_msg("Unlocked\n"); 56 log_debug_msg("Unlocked\n");
54 //client->lock = 0; 57 //client->lock = 0;
@@ -63,7 +66,7 @@ static void afc_unlock(iphone_afc_client_t client)
63 * 66 *
64 * @return A handle to the newly-connected client or NULL upon error. 67 * @return A handle to the newly-connected client or NULL upon error.
65 */ 68 */
66iphone_error_t iphone_afc_new_client(iphone_device_t device, int dst_port, iphone_afc_client_t * client) 69iphone_error_t afc_new_client(iphone_device_t device, int dst_port, afc_client_t * client)
67{ 70{
68 //makes sure thread environment is available 71 //makes sure thread environment is available
69 if (!g_thread_supported()) 72 if (!g_thread_supported())
@@ -78,7 +81,7 @@ iphone_error_t iphone_afc_new_client(iphone_device_t device, int dst_port, iphon
78 return IPHONE_E_UNKNOWN_ERROR; // ret; 81 return IPHONE_E_UNKNOWN_ERROR; // ret;
79 } 82 }
80 83
81 iphone_afc_client_t client_loc = (iphone_afc_client_t) malloc(sizeof(struct iphone_afc_client_int)); 84 afc_client_t client_loc = (afc_client_t) malloc(sizeof(struct afc_client_int));
82 client_loc->sfd = sfd; 85 client_loc->sfd = sfd;
83 86
84 // Allocate a packet 87 // Allocate a packet
@@ -105,7 +108,7 @@ iphone_error_t iphone_afc_new_client(iphone_device_t device, int dst_port, iphon
105 * 108 *
106 * @param client The client to disconnect. 109 * @param client The client to disconnect.
107 */ 110 */
108iphone_error_t iphone_afc_free_client(iphone_afc_client_t client) 111iphone_error_t afc_free_client(afc_client_t client)
109{ 112{
110 if (!client || client->sfd < 0 || !client->afc_packet) 113 if (!client || client->sfd < 0 || !client->afc_packet)
111 return IPHONE_E_INVALID_ARG; 114 return IPHONE_E_INVALID_ARG;
@@ -127,7 +130,7 @@ iphone_error_t iphone_afc_free_client(iphone_afc_client_t client)
127 * 130 *
128 * @return AFC error code or -1 on error. 131 * @return AFC error code or -1 on error.
129 */ 132 */
130int iphone_afc_get_afcerror(iphone_afc_client_t client) 133int afc_get_afcerror(afc_client_t client)
131{ 134{
132 int res = -1; 135 int res = -1;
133 if (client) { 136 if (client) {
@@ -140,13 +143,13 @@ int iphone_afc_get_afcerror(iphone_afc_client_t client)
140 143
141/** 144/**
142 * Tries to convert the AFC error value into a meaningful errno value. 145 * Tries to convert the AFC error value into a meaningful errno value.
143 * Internally used by iphone_afc_get_errno. 146 * Internally used by afc_get_errno.
144 * 147 *
145 * @param afcerror AFC error value to convert 148 * @param afcerror AFC error value to convert
146 * 149 *
147 * @return errno value or -1 if the errno could not be determined. 150 * @return errno value or -1 if the errno could not be determined.
148 * 151 *
149 * @see iphone_afc_get_errno 152 * @see afc_get_errno
150 */ 153 */
151static int afcerror_to_errno(int afcerror) 154static int afcerror_to_errno(int afcerror)
152{ 155{
@@ -189,7 +192,7 @@ static int afcerror_to_errno(int afcerror)
189 * 192 *
190 * @return errno value or -1 on error. 193 * @return errno value or -1 on error.
191 */ 194 */
192int iphone_afc_get_errno(iphone_afc_client_t client) 195int afc_get_errno(afc_client_t client)
193{ 196{
194 int res = -1; 197 int res = -1;
195 if (client) { 198 if (client) {
@@ -213,7 +216,7 @@ int iphone_afc_get_errno(iphone_afc_client_t client)
213 * reason is that if you set them to different values, it indicates 216 * reason is that if you set them to different values, it indicates
214 * you want to send the data as two packets. 217 * you want to send the data as two packets.
215 */ 218 */
216static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, uint64_t length) 219static int dispatch_AFC_packet(afc_client_t client, const char *data, uint64_t length)
217{ 220{
218 int bytes = 0, offset = 0; 221 int bytes = 0, offset = 0;
219 char *buffer; 222 char *buffer;
@@ -294,7 +297,7 @@ static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, uin
294 * received raised a non-trivial error condition (i.e. non-zero with 297 * received raised a non-trivial error condition (i.e. non-zero with
295 * AFC_ERROR operation) 298 * AFC_ERROR operation)
296 */ 299 */
297static int receive_AFC_data(iphone_afc_client_t client, char **dump_here) 300static int receive_AFC_data(afc_client_t client, char **dump_here)
298{ 301{
299 AFCPacket header; 302 AFCPacket header;
300 int bytes = 0; 303 int bytes = 0;
@@ -468,7 +471,7 @@ static char **make_strings_list(char *tokens, int true_length)
468 * @return A char ** list of files in that directory, terminated by an empty 471 * @return A char ** list of files in that directory, terminated by an empty
469 * string for now or NULL if there was an error. 472 * string for now or NULL if there was an error.
470 */ 473 */
471iphone_error_t iphone_afc_get_dir_list(iphone_afc_client_t client, const char *dir, char ***list) 474iphone_error_t afc_get_dir_list(afc_client_t client, const char *dir, char ***list)
472{ 475{
473 int bytes = 0; 476 int bytes = 0;
474 char *data = NULL, **list_loc = NULL; 477 char *data = NULL, **list_loc = NULL;
@@ -514,7 +517,7 @@ iphone_error_t iphone_afc_get_dir_list(iphone_afc_client_t client, const char *d
514 * @return A char ** list of parameters as given by AFC or NULL if there was an 517 * @return A char ** list of parameters as given by AFC or NULL if there was an
515 * error. 518 * error.
516 */ 519 */
517iphone_error_t iphone_afc_get_devinfo(iphone_afc_client_t client, char ***infos) 520iphone_error_t afc_get_devinfo(afc_client_t client, char ***infos)
518{ 521{
519 int bytes = 0; 522 int bytes = 0;
520 char *data = NULL, **list = NULL; 523 char *data = NULL, **list = NULL;
@@ -556,7 +559,7 @@ iphone_error_t iphone_afc_get_devinfo(iphone_afc_client_t client, char ***infos)
556 * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG 559 * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG
557 * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. 560 * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise.
558 */ 561 */
559iphone_error_t iphone_afc_delete_file(iphone_afc_client_t client, const char *path) 562iphone_error_t afc_delete_file(afc_client_t client, const char *path)
560{ 563{
561 char *response = NULL; 564 char *response = NULL;
562 int bytes; 565 int bytes;
@@ -596,7 +599,7 @@ iphone_error_t iphone_afc_delete_file(iphone_afc_client_t client, const char *pa
596 * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG 599 * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG
597 * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. 600 * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise.
598 */ 601 */
599iphone_error_t iphone_afc_rename_file(iphone_afc_client_t client, const char *from, const char *to) 602iphone_error_t afc_rename_file(afc_client_t client, const char *from, const char *to)
600{ 603{
601 char *response = NULL; 604 char *response = NULL;
602 char *send = (char *) malloc(sizeof(char) * (strlen(from) + strlen(to) + 1 + sizeof(uint32_t))); 605 char *send = (char *) malloc(sizeof(char) * (strlen(from) + strlen(to) + 1 + sizeof(uint32_t)));
@@ -640,7 +643,7 @@ iphone_error_t iphone_afc_rename_file(iphone_afc_client_t client, const char *fr
640 * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG 643 * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG
641 * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. 644 * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise.
642 */ 645 */
643iphone_error_t iphone_afc_mkdir(iphone_afc_client_t client, const char *dir) 646iphone_error_t afc_mkdir(afc_client_t client, const char *dir)
644{ 647{
645 int bytes = 0; 648 int bytes = 0;
646 char *response = NULL; 649 char *response = NULL;
@@ -682,7 +685,7 @@ iphone_error_t iphone_afc_mkdir(iphone_afc_client_t client, const char *dir)
682 * @return IPHONE_E_SUCCESS on success or an IPHONE_E_* error value 685 * @return IPHONE_E_SUCCESS on success or an IPHONE_E_* error value
683 * when something went wrong. 686 * when something went wrong.
684 */ 687 */
685iphone_error_t iphone_afc_get_file_info(iphone_afc_client_t client, const char *path, char ***infolist) 688iphone_error_t afc_get_file_info(afc_client_t client, const char *path, char ***infolist)
686{ 689{
687 char *received = NULL; 690 char *received = NULL;
688 int length; 691 int length;
@@ -726,8 +729,8 @@ iphone_error_t iphone_afc_get_file_info(iphone_afc_client_t client, const char *
726 * @return IPHONE_E_SUCCESS on success or an IPHONE_E_* error on failure. 729 * @return IPHONE_E_SUCCESS on success or an IPHONE_E_* error on failure.
727 */ 730 */
728iphone_error_t 731iphone_error_t
729iphone_afc_open_file(iphone_afc_client_t client, const char *filename, 732afc_open_file(afc_client_t client, const char *filename,
730 iphone_afc_file_mode_t file_mode, uint64_t *handle) 733 afc_file_mode_t file_mode, uint64_t *handle)
731{ 734{
732 uint32_t ag = 0; 735 uint32_t ag = 0;
733 int bytes = 0, length = 0; 736 int bytes = 0, length = 0;
@@ -786,7 +789,7 @@ iphone_afc_open_file(iphone_afc_client_t client, const char *filename,
786 * @return The number of bytes read if successful. If there was an error -1. 789 * @return The number of bytes read if successful. If there was an error -1.
787 */ 790 */
788iphone_error_t 791iphone_error_t
789iphone_afc_read_file(iphone_afc_client_t client, uint64_t handle, char *data, int length, uint32_t * bytes) 792afc_read_file(afc_client_t client, uint64_t handle, char *data, int length, uint32_t * bytes)
790{ 793{
791 char *input = NULL; 794 char *input = NULL;
792 int current_count = 0, bytes_loc = 0; 795 int current_count = 0, bytes_loc = 0;
@@ -857,7 +860,7 @@ iphone_afc_read_file(iphone_afc_client_t client, uint64_t handle, char *data, in
857 * none were written... 860 * none were written...
858 */ 861 */
859iphone_error_t 862iphone_error_t
860iphone_afc_write_file(iphone_afc_client_t client, uint64_t handle, 863afc_write_file(afc_client_t client, uint64_t handle,
861 const char *data, int length, uint32_t * bytes) 864 const char *data, int length, uint32_t * bytes)
862{ 865{
863 char *acknowledgement = NULL; 866 char *acknowledgement = NULL;
@@ -946,7 +949,7 @@ iphone_afc_write_file(iphone_afc_client_t client, uint64_t handle,
946 * @param client The client to close the file with. 949 * @param client The client to close the file with.
947 * @param handle File handle of a previously opened file. 950 * @param handle File handle of a previously opened file.
948 */ 951 */
949iphone_error_t iphone_afc_close_file(iphone_afc_client_t client, uint64_t handle) 952iphone_error_t afc_close_file(afc_client_t client, uint64_t handle)
950{ 953{
951 if (!client || (handle == 0)) 954 if (!client || (handle == 0))
952 return IPHONE_E_INVALID_ARG; 955 return IPHONE_E_INVALID_ARG;
@@ -997,7 +1000,7 @@ iphone_error_t iphone_afc_close_file(iphone_afc_client_t client, uint64_t handle
997 * @param handle File handle of a previously opened file. 1000 * @param handle File handle of a previously opened file.
998 * @operation the lock or unlock operation to perform. 1001 * @operation the lock or unlock operation to perform.
999 */ 1002 */
1000iphone_error_t iphone_afc_lock_file(iphone_afc_client_t client, uint64_t handle, int operation) 1003iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, int operation)
1001{ 1004{
1002 if (!client || (handle == 0)) 1005 if (!client || (handle == 0))
1003 return IPHONE_E_INVALID_ARG; 1006 return IPHONE_E_INVALID_ARG;
@@ -1046,7 +1049,7 @@ iphone_error_t iphone_afc_lock_file(iphone_afc_client_t client, uint64_t handle,
1046 * 1049 *
1047 * @return IPHONE_E_SUCCESS on success, IPHONE_E_NOT_ENOUGH_DATA on failure. 1050 * @return IPHONE_E_SUCCESS on success, IPHONE_E_NOT_ENOUGH_DATA on failure.
1048 */ 1051 */
1049iphone_error_t iphone_afc_seek_file(iphone_afc_client_t client, uint64_t handle, int64_t offset, int whence) 1052iphone_error_t afc_seek_file(afc_client_t client, uint64_t handle, int64_t offset, int whence)
1050{ 1053{
1051 char *buffer = (char *) malloc(sizeof(char) * 24); 1054 char *buffer = (char *) malloc(sizeof(char) * 24);
1052 uint32_t zero = 0; 1055 uint32_t zero = 0;
@@ -1093,7 +1096,7 @@ iphone_error_t iphone_afc_seek_file(iphone_afc_client_t client, uint64_t handle,
1093 * @note This function is more akin to ftruncate than truncate, and truncate 1096 * @note This function is more akin to ftruncate than truncate, and truncate
1094 * calls would have to open the file before calling this, sadly. 1097 * calls would have to open the file before calling this, sadly.
1095 */ 1098 */
1096iphone_error_t iphone_afc_truncate_file(iphone_afc_client_t client, uint64_t handle, uint64_t newsize) 1099iphone_error_t afc_truncate_file(afc_client_t client, uint64_t handle, uint64_t newsize)
1097{ 1100{
1098 char *buffer = (char *) malloc(sizeof(char) * 16); 1101 char *buffer = (char *) malloc(sizeof(char) * 16);
1099 int bytes = 0; 1102 int bytes = 0;
@@ -1135,7 +1138,7 @@ iphone_error_t iphone_afc_truncate_file(iphone_afc_client_t client, uint64_t han
1135 * @return IPHONE_E_SUCCESS if everything went well, IPHONE_E_INVALID_ARG 1138 * @return IPHONE_E_SUCCESS if everything went well, IPHONE_E_INVALID_ARG
1136 * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. 1139 * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise.
1137 */ 1140 */
1138iphone_error_t iphone_afc_truncate(iphone_afc_client_t client, const char *path, off_t newsize) 1141iphone_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize)
1139{ 1142{
1140 char *response = NULL; 1143 char *response = NULL;
1141 char *send = (char *) malloc(sizeof(char) * (strlen(path) + 1 + 8)); 1144 char *send = (char *) malloc(sizeof(char) * (strlen(path) + 1 + 8));
@@ -1181,7 +1184,7 @@ iphone_error_t iphone_afc_truncate(iphone_afc_client_t client, const char *path,
1181 * @return IPHONE_E_SUCCESS if everything went well, IPHONE_E_INVALID_ARG 1184 * @return IPHONE_E_SUCCESS if everything went well, IPHONE_E_INVALID_ARG
1182 * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. 1185 * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise.
1183 */ 1186 */
1184iphone_error_t iphone_afc_make_link(iphone_afc_client_t client, iphone_afc_link_type_t linktype, const char *target, const char *linkname) 1187iphone_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname)
1185{ 1188{
1186 char *response = NULL; 1189 char *response = NULL;
1187 char *send = (char *) malloc(sizeof(char) * (strlen(target)+1 + strlen(linkname)+1 + 8)); 1190 char *send = (char *) malloc(sizeof(char) * (strlen(target)+1 + strlen(linkname)+1 + 8));