summaryrefslogtreecommitdiffstats
path: root/src/lockdown.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2009-09-10 13:28:13 +0200
committerGravatar Martin Szulecki2009-09-12 11:41:38 +0200
commit1f6282ffddec7012df82fa929dfe72cfc74b063a (patch)
tree452c927c07806855f360ee9803111a1f72e05d3c /src/lockdown.c
parent26ce10634d277df51c4e9c2bd61b409df3f5b060 (diff)
downloadlibimobiledevice-1f6282ffddec7012df82fa929dfe72cfc74b063a.tar.gz
libimobiledevice-1f6282ffddec7012df82fa929dfe72cfc74b063a.tar.bz2
Public API rework, extension and adaption to latest libusbmuxd-1.0 API.
Diffstat (limited to 'src/lockdown.c')
-rw-r--r--src/lockdown.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/lockdown.c b/src/lockdown.c
index 7a2aa7d..a05b5db 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -213,12 +213,14 @@ lockdownd_error_t lockdownd_client_free(lockdownd_client_t client)
213 213
214 lockdownd_stop_ssl_session(client); 214 lockdownd_stop_ssl_session(client);
215 215
216 if (client->sfd > 0) { 216 if (client->connection) {
217 lockdownd_goodbye(client); 217 lockdownd_goodbye(client);
218 218
219 // IMO, read of final "sessionUpcall connection closed" packet 219 // IMO, read of final "sessionUpcall connection closed" packet
220 // should come here instead of in iphone_free_device 220 // should come here instead of in iphone_free_device
221 ret = usbmuxd_disconnect(client->sfd); 221 if ((ret = iphone_device_disconnect(client->connection)) != IPHONE_E_SUCCESS) {
222 ret = LOCKDOWN_E_UNKNOWN_ERROR;
223 }
222 } 224 }
223 225
224 free(client); 226 free(client);
@@ -241,7 +243,7 @@ lockdownd_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist)
241 uint32_t datalen = 0, bytes = 0, received_bytes = 0; 243 uint32_t datalen = 0, bytes = 0, received_bytes = 0;
242 244
243 if (!client->in_SSL) 245 if (!client->in_SSL)
244 ret = usbmuxd_recv(client->sfd, (char *) &datalen, sizeof(datalen), &bytes); 246 ret = iphone_device_recv(client->connection, (char *) &datalen, sizeof(datalen), &bytes);
245 else { 247 else {
246 ssize_t res = gnutls_record_recv(*client->ssl_session, &datalen, sizeof(datalen)); 248 ssize_t res = gnutls_record_recv(*client->ssl_session, &datalen, sizeof(datalen));
247 if (res < 0) { 249 if (res < 0) {
@@ -260,7 +262,7 @@ lockdownd_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist)
260 /* fill buffer and request more packets if needed */ 262 /* fill buffer and request more packets if needed */
261 if (!client->in_SSL) { 263 if (!client->in_SSL) {
262 while ((received_bytes < datalen) && (ret == LOCKDOWN_E_SUCCESS)) { 264 while ((received_bytes < datalen) && (ret == LOCKDOWN_E_SUCCESS)) {
263 ret = usbmuxd_recv(client->sfd, receive + received_bytes, datalen - received_bytes, &bytes); 265 ret = iphone_device_recv(client->connection, receive + received_bytes, datalen - received_bytes, &bytes);
264 received_bytes += bytes; 266 received_bytes += bytes;
265 } 267 }
266 } else { 268 } else {
@@ -328,7 +330,7 @@ lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist)
328 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: made the query, sending it along\n", __func__); 330 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: made the query, sending it along\n", __func__);
329 331
330 if (!client->in_SSL) 332 if (!client->in_SSL)
331 ret = usbmuxd_send(client->sfd, real_query, ntohl(length) + sizeof(length), (uint32_t*)&bytes); 333 ret = iphone_device_send(client->connection, real_query, ntohl(length) + sizeof(length), (uint32_t*)&bytes);
332 else { 334 else {
333 ssize_t res = gnutls_record_send(*client->ssl_session, real_query, ntohl(length) + sizeof(length)); 335 ssize_t res = gnutls_record_send(*client->ssl_session, real_query, ntohl(length) + sizeof(length));
334 if (res < 0) { 336 if (res < 0) {
@@ -659,19 +661,19 @@ lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **de
659 */ 661 */
660lockdownd_error_t lockdownd_client_new(iphone_device_t device, lockdownd_client_t *client) 662lockdownd_error_t lockdownd_client_new(iphone_device_t device, lockdownd_client_t *client)
661{ 663{
662 if (!device || !client) 664 if (!client)
663 return LOCKDOWN_E_INVALID_ARG; 665 return LOCKDOWN_E_INVALID_ARG;
664 lockdownd_error_t ret = LOCKDOWN_E_SUCCESS; 666 lockdownd_error_t ret = LOCKDOWN_E_SUCCESS;
665 char *host_id = NULL; 667 char *host_id = NULL;
666 668
667 int sfd = usbmuxd_connect(device->handle, 0xf27e); 669 iphone_connection_t connection;
668 if (sfd < 0) { 670 if (iphone_device_connect(device, 0xf27e, &connection) != IPHONE_E_SUCCESS) {
669 log_debug_msg("%s: could not connect to lockdownd (device handle %d)\n", __func__, device->handle); 671 log_debug_msg("%s: could not connect to lockdownd (device %s)\n", __func__, device->uuid);
670 return LOCKDOWN_E_MUX_ERROR; 672 return LOCKDOWN_E_MUX_ERROR;
671 } 673 }
672 674
673 lockdownd_client_t client_loc = (lockdownd_client_t) malloc(sizeof(struct lockdownd_client_int)); 675 lockdownd_client_t client_loc = (lockdownd_client_t) malloc(sizeof(struct lockdownd_client_int));
674 client_loc->sfd = sfd; 676 client_loc->connection = connection;
675 client_loc->ssl_session = (gnutls_session_t *) malloc(sizeof(gnutls_session_t)); 677 client_loc->ssl_session = (gnutls_session_t *) malloc(sizeof(gnutls_session_t));
676 client_loc->in_SSL = 0; 678 client_loc->in_SSL = 0;
677 679
@@ -1176,7 +1178,7 @@ ssize_t lockdownd_secuwrite(gnutls_transport_ptr_t transport, char *buffer, size
1176 client = (lockdownd_client_t) transport; 1178 client = (lockdownd_client_t) transport;
1177 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: called\n", __func__); 1179 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: called\n", __func__);
1178 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pre-send length = %zi\n", __func__, length); 1180 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pre-send length = %zi\n", __func__, length);
1179 usbmuxd_send(client->sfd, buffer, length, &bytes); 1181 iphone_device_send(client->connection, buffer, length, &bytes);
1180 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: post-send sent %i bytes\n", __func__, bytes); 1182 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: post-send sent %i bytes\n", __func__, bytes);
1181 return bytes; 1183 return bytes;
1182} 1184}
@@ -1205,7 +1207,7 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_
1205 1207
1206 // repeat until we have the full data or an error occurs. 1208 // repeat until we have the full data or an error occurs.
1207 do { 1209 do {
1208 if ((res = usbmuxd_recv(client->sfd, recv_buffer, this_len, (uint32_t*)&bytes)) != LOCKDOWN_E_SUCCESS) { 1210 if ((res = iphone_device_recv(client->connection, recv_buffer, this_len, (uint32_t*)&bytes)) != LOCKDOWN_E_SUCCESS) {
1209 log_debug_msg("%s: ERROR: usbmux_recv returned %d\n", __func__, res); 1211 log_debug_msg("%s: ERROR: usbmux_recv returned %d\n", __func__, res);
1210 return res; 1212 return res;
1211 } 1213 }