summaryrefslogtreecommitdiffstats
path: root/src/AFC.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/AFC.c')
-rw-r--r--src/AFC.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/AFC.c b/src/AFC.c
index b27080a..ba436e7 100644
--- a/src/AFC.c
+++ b/src/AFC.c
@@ -68,18 +68,18 @@ afc_error_t afc_client_new(iphone_device_t device, int dst_port, afc_client_t *
68 return AFC_E_INVALID_ARGUMENT; 68 return AFC_E_INVALID_ARGUMENT;
69 69
70 /* attempt connection */ 70 /* attempt connection */
71 int sfd = usbmuxd_connect(device->handle, dst_port); 71 iphone_connection_t connection = NULL;
72 if (sfd < 0) { 72 if (iphone_device_connect(device, dst_port, &connection) != IPHONE_E_SUCCESS) {
73 return AFC_E_MUX_ERROR; 73 return AFC_E_MUX_ERROR;
74 } 74 }
75 75
76 afc_client_t client_loc = (afc_client_t) malloc(sizeof(struct afc_client_int)); 76 afc_client_t client_loc = (afc_client_t) malloc(sizeof(struct afc_client_int));
77 client_loc->sfd = sfd; 77 client_loc->connection = connection;
78 78
79 /* allocate a packet */ 79 /* allocate a packet */
80 client_loc->afc_packet = (AFCPacket *) malloc(sizeof(AFCPacket)); 80 client_loc->afc_packet = (AFCPacket *) malloc(sizeof(AFCPacket));
81 if (!client_loc->afc_packet) { 81 if (!client_loc->afc_packet) {
82 usbmuxd_disconnect(client_loc->sfd); 82 iphone_device_disconnect(client_loc->connection);
83 free(client_loc); 83 free(client_loc);
84 return AFC_E_NO_MEM; 84 return AFC_E_NO_MEM;
85 } 85 }
@@ -102,10 +102,10 @@ afc_error_t afc_client_new(iphone_device_t device, int dst_port, afc_client_t *
102 */ 102 */
103afc_error_t afc_client_free(afc_client_t client) 103afc_error_t afc_client_free(afc_client_t client)
104{ 104{
105 if (!client || client->sfd < 0 || !client->afc_packet) 105 if (!client || !client->connection || !client->afc_packet)
106 return AFC_E_INVALID_ARGUMENT; 106 return AFC_E_INVALID_ARGUMENT;
107 107
108 usbmuxd_disconnect(client->sfd); 108 iphone_device_disconnect(client->connection);
109 free(client->afc_packet); 109 free(client->afc_packet);
110 if (client->mutex) { 110 if (client->mutex) {
111 g_mutex_free(client->mutex); 111 g_mutex_free(client->mutex);
@@ -132,7 +132,7 @@ static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t l
132 int bytes = 0, offset = 0; 132 int bytes = 0, offset = 0;
133 char *buffer; 133 char *buffer;
134 134
135 if (!client || client->sfd < 0 || !client->afc_packet) 135 if (!client || !client->connection || !client->afc_packet)
136 return 0; 136 return 0;
137 137
138 if (!data || !length) 138 if (!data || !length)
@@ -164,7 +164,7 @@ static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t l
164 return -1; 164 return -1;
165 } 165 }
166 memcpy(buffer + sizeof(AFCPacket), data, offset); 166 memcpy(buffer + sizeof(AFCPacket), data, offset);
167 usbmuxd_send(client->sfd, buffer, client->afc_packet->this_length, (uint32_t*)&bytes); 167 iphone_device_send(client->connection, buffer, client->afc_packet->this_length, (uint32_t*)&bytes);
168 free(buffer); 168 free(buffer);
169 if (bytes <= 0) { 169 if (bytes <= 0) {
170 return bytes; 170 return bytes;
@@ -175,7 +175,7 @@ static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t l
175 log_debug_msg("%s: Buffer: \n", __func__); 175 log_debug_msg("%s: Buffer: \n", __func__);
176 log_debug_buffer(data + offset, length - offset); 176 log_debug_buffer(data + offset, length - offset);
177 177
178 usbmuxd_send(client->sfd, data + offset, length - offset, (uint32_t*)&bytes); 178 iphone_device_send(client->connection, data + offset, length - offset, (uint32_t*)&bytes);
179 return bytes; 179 return bytes;
180 } else { 180 } else {
181 log_debug_msg("%s: doin things the old way\n", __func__); 181 log_debug_msg("%s: doin things the old way\n", __func__);
@@ -188,7 +188,7 @@ static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t l
188 } 188 }
189 log_debug_buffer(buffer, client->afc_packet->this_length); 189 log_debug_buffer(buffer, client->afc_packet->this_length);
190 log_debug_msg("\n"); 190 log_debug_msg("\n");
191 usbmuxd_send(client->sfd, buffer, client->afc_packet->this_length, (uint32_t*)&bytes); 191 iphone_device_send(client->connection, buffer, client->afc_packet->this_length, (uint32_t*)&bytes);
192 192
193 if (buffer) { 193 if (buffer) {
194 free(buffer); 194 free(buffer);
@@ -220,7 +220,7 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int *
220 *bytes = 0; 220 *bytes = 0;
221 221
222 /* first, read the AFC header */ 222 /* first, read the AFC header */
223 usbmuxd_recv(client->sfd, (char*)&header, sizeof(AFCPacket), (uint32_t*)bytes); 223 iphone_device_recv(client->connection, (char*)&header, sizeof(AFCPacket), (uint32_t*)bytes);
224 if (*bytes <= 0) { 224 if (*bytes <= 0) {
225 log_debug_msg("%s: Just didn't get enough.\n", __func__); 225 log_debug_msg("%s: Just didn't get enough.\n", __func__);
226 *dump_here = NULL; 226 *dump_here = NULL;
@@ -273,7 +273,7 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int *
273 273
274 *dump_here = (char*)malloc(entire_len); 274 *dump_here = (char*)malloc(entire_len);
275 if (this_len > 0) { 275 if (this_len > 0) {
276 usbmuxd_recv(client->sfd, *dump_here, this_len, (uint32_t*)bytes); 276 iphone_device_recv(client->connection, *dump_here, this_len, (uint32_t*)bytes);
277 if (*bytes <= 0) { 277 if (*bytes <= 0) {
278 free(*dump_here); 278 free(*dump_here);
279 *dump_here = NULL; 279 *dump_here = NULL;
@@ -291,7 +291,7 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int *
291 291
292 if (entire_len > this_len) { 292 if (entire_len > this_len) {
293 while (current_count < entire_len) { 293 while (current_count < entire_len) {
294 usbmuxd_recv(client->sfd, (*dump_here)+current_count, entire_len - current_count, (uint32_t*)bytes); 294 iphone_device_recv(client->connection, (*dump_here)+current_count, entire_len - current_count, (uint32_t*)bytes);
295 if (*bytes <= 0) { 295 if (*bytes <= 0) {
296 log_debug_msg("%s: Error receiving data (recv returned %d)\n", __func__, *bytes); 296 log_debug_msg("%s: Error receiving data (recv returned %d)\n", __func__, *bytes);
297 break; 297 break;
@@ -517,7 +517,7 @@ afc_error_t afc_remove_path(afc_client_t client, const char *path)
517 int bytes; 517 int bytes;
518 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 518 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
519 519
520 if (!client || !path || !client->afc_packet || client->sfd < 0) 520 if (!client || !path || !client->afc_packet || !client->connection)
521 return AFC_E_INVALID_ARGUMENT; 521 return AFC_E_INVALID_ARGUMENT;
522 522
523 afc_lock(client); 523 afc_lock(client);
@@ -560,7 +560,7 @@ afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *t
560 int bytes = 0; 560 int bytes = 0;
561 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 561 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
562 562
563 if (!client || !from || !to || !client->afc_packet || client->sfd < 0) 563 if (!client || !from || !to || !client->afc_packet || !client->connection)
564 return AFC_E_INVALID_ARGUMENT; 564 return AFC_E_INVALID_ARGUMENT;
565 565
566 afc_lock(client); 566 afc_lock(client);
@@ -687,7 +687,7 @@ afc_file_open(afc_client_t client, const char *filename,
687 // set handle to 0 so in case an error occurs, the handle is invalid 687 // set handle to 0 so in case an error occurs, the handle is invalid
688 *handle = 0; 688 *handle = 0;
689 689
690 if (!client || client->sfd < 0|| !client->afc_packet) 690 if (!client || !client->connection || !client->afc_packet)
691 return AFC_E_INVALID_ARGUMENT; 691 return AFC_E_INVALID_ARGUMENT;
692 692
693 afc_lock(client); 693 afc_lock(client);
@@ -742,7 +742,7 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint
742 const int MAXIMUM_READ_SIZE = 1 << 16; 742 const int MAXIMUM_READ_SIZE = 1 << 16;
743 afc_error_t ret = AFC_E_SUCCESS; 743 afc_error_t ret = AFC_E_SUCCESS;
744 744
745 if (!client || !client->afc_packet || client->sfd < 0 || handle == 0) 745 if (!client || !client->afc_packet || !client->connection || handle == 0)
746 return AFC_E_INVALID_ARGUMENT; 746 return AFC_E_INVALID_ARGUMENT;
747 log_debug_msg("%s: called for length %i\n", __func__, length); 747 log_debug_msg("%s: called for length %i\n", __func__, length);
748 748
@@ -819,7 +819,7 @@ afc_file_write(afc_client_t client, uint64_t handle,
819 char *out_buffer = NULL; 819 char *out_buffer = NULL;
820 afc_error_t ret = AFC_E_SUCCESS; 820 afc_error_t ret = AFC_E_SUCCESS;
821 821
822 if (!client || !client->afc_packet || client->sfd < 0 || !bytes || (handle == 0)) 822 if (!client || !client->afc_packet || !client->connection || !bytes || (handle == 0))
823 return AFC_E_INVALID_ARGUMENT; 823 return AFC_E_INVALID_ARGUMENT;
824 824
825 afc_lock(client); 825 afc_lock(client);
@@ -1139,7 +1139,7 @@ afc_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize)
1139 uint64_t size_requested = newsize; 1139 uint64_t size_requested = newsize;
1140 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1140 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1141 1141
1142 if (!client || !path || !client->afc_packet || client->sfd < 0) 1142 if (!client || !path || !client->afc_packet || !client->connection)
1143 return AFC_E_INVALID_ARGUMENT; 1143 return AFC_E_INVALID_ARGUMENT;
1144 1144
1145 afc_lock(client); 1145 afc_lock(client);
@@ -1183,7 +1183,7 @@ afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const c
1183 uint64_t type = linktype; 1183 uint64_t type = linktype;
1184 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1184 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1185 1185
1186 if (!client || !target || !linkname || !client->afc_packet || client->sfd < 0) 1186 if (!client || !target || !linkname || !client->afc_packet || !client->connection)
1187 return AFC_E_INVALID_ARGUMENT; 1187 return AFC_E_INVALID_ARGUMENT;
1188 1188
1189 afc_lock(client); 1189 afc_lock(client);