summaryrefslogtreecommitdiffstats
path: root/src/MobileSync.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/MobileSync.c')
-rw-r--r--src/MobileSync.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/MobileSync.c b/src/MobileSync.c
index 58d0beb..7d6e947 100644
--- a/src/MobileSync.c
+++ b/src/MobileSync.c
@@ -22,29 +22,30 @@
22#include "MobileSync.h" 22#include "MobileSync.h"
23#include <plist/plist.h> 23#include <plist/plist.h>
24#include <string.h> 24#include <string.h>
25#include <stdlib.h>
25#include <arpa/inet.h> 26#include <arpa/inet.h>
26 27
27 28
28#define MSYNC_VERSION_INT1 100 29#define MSYNC_VERSION_INT1 100
29#define MSYNC_VERSION_INT2 100 30#define MSYNC_VERSION_INT2 100
30 31
31iphone_error_t iphone_msync_new_client(iphone_device_t device, int src_port, int dst_port, 32iphone_error_t iphone_msync_new_client(iphone_device_t device, int dst_port,
32 iphone_msync_client_t * client) 33 iphone_msync_client_t * client)
33{ 34{
34 if (!device || src_port == 0 || dst_port == 0 || !client || *client) 35 if (!device || dst_port == 0 || !client || *client)
35 return IPHONE_E_INVALID_ARG; 36 return IPHONE_E_INVALID_ARG;
36 37
37 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 38 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
38 39
39 iphone_msync_client_t client_loc = (iphone_msync_client_t) malloc(sizeof(struct iphone_msync_client_int));
40
41 // Attempt connection 40 // Attempt connection
42 client_loc->connection = NULL; 41 int sfd = usbmuxd_connect(device->handle, dst_port);
43 ret = iphone_mux_new_client(device, src_port, dst_port, &client_loc->connection); 42 if (sfd < 0) {
44 if (IPHONE_E_SUCCESS != ret || !client_loc->connection) {
45 free(client_loc);
46 return ret; 43 return ret;
47 } 44 }
45
46 iphone_msync_client_t client_loc = (iphone_msync_client_t) malloc(sizeof(struct iphone_msync_client_int));
47 client_loc->sfd = sfd;
48
48 //perform handshake 49 //perform handshake
49 plist_t array = NULL; 50 plist_t array = NULL;
50 51
@@ -120,7 +121,7 @@ iphone_error_t iphone_msync_free_client(iphone_msync_client_t client)
120 return IPHONE_E_INVALID_ARG; 121 return IPHONE_E_INVALID_ARG;
121 122
122 iphone_msync_stop_session(client); 123 iphone_msync_stop_session(client);
123 return iphone_mux_free_client(client->connection); 124 return usbmuxd_disconnect(client->sfd);
124} 125}
125 126
126/** Polls the iPhone for MobileSync data. 127/** Polls the iPhone for MobileSync data.
@@ -138,14 +139,14 @@ iphone_error_t iphone_msync_recv(iphone_msync_client_t client, plist_t * plist)
138 char *receive = NULL; 139 char *receive = NULL;
139 uint32_t datalen = 0, bytes = 0, received_bytes = 0; 140 uint32_t datalen = 0, bytes = 0, received_bytes = 0;
140 141
141 ret = iphone_mux_recv(client->connection, (char *) &datalen, sizeof(datalen), &bytes); 142 ret = usbmuxd_recv(client->sfd, (char *) &datalen, sizeof(datalen), &bytes);
142 datalen = ntohl(datalen); 143 datalen = ntohl(datalen);
143 144
144 receive = (char *) malloc(sizeof(char) * datalen); 145 receive = (char *) malloc(sizeof(char) * datalen);
145 146
146 /* fill buffer and request more packets if needed */ 147 /* fill buffer and request more packets if needed */
147 while ((received_bytes < datalen) && (ret == IPHONE_E_SUCCESS)) { 148 while ((received_bytes < datalen) && (ret == IPHONE_E_SUCCESS)) {
148 ret = iphone_mux_recv(client->connection, receive + received_bytes, datalen - received_bytes, &bytes); 149 ret = usbmuxd_recv(client->sfd, receive + received_bytes, datalen - received_bytes, &bytes);
149 received_bytes += bytes; 150 received_bytes += bytes;
150 } 151 }
151 152
@@ -201,7 +202,7 @@ iphone_error_t iphone_msync_send(iphone_msync_client_t client, plist_t plist)
201 memcpy(real_query, &length, sizeof(length)); 202 memcpy(real_query, &length, sizeof(length));
202 memcpy(real_query + 4, content, ntohl(length)); 203 memcpy(real_query + 4, content, ntohl(length));
203 204
204 ret = iphone_mux_send(client->connection, real_query, ntohl(length) + sizeof(length), &bytes); 205 ret = usbmuxd_send(client->sfd, real_query, ntohl(length) + sizeof(length), (uint32_t*)&bytes);
205 free(real_query); 206 free(real_query);
206 return ret; 207 return ret;
207} 208}