summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ideviceinstaller.c107
1 files changed, 35 insertions, 72 deletions
diff --git a/src/ideviceinstaller.c b/src/ideviceinstaller.c
index 5ff9dad..cf424d9 100644
--- a/src/ideviceinstaller.c
+++ b/src/ideviceinstaller.c
@@ -198,26 +198,14 @@ static void status_cb(plist_t command, plist_t status, void *unused)
198 } 198 }
199 199
200 /* clean up */ 200 /* clean up */
201 if (error_name) 201 free(error_name);
202 free(error_name); 202 free(error_description);
203 203
204 if (error_description) 204 free(last_status);
205 free(error_description); 205 last_status = status_name;
206
207 if (last_status) {
208 free(last_status);
209 last_status = NULL;
210 }
211
212 if (status_name) {
213 last_status = strdup(status_name);
214 free(status_name);
215 }
216 206
217 if (command_name) { 207 free(command_name);
218 free(command_name); 208 command_name = NULL;
219 command_name = NULL;
220 }
221 } else { 209 } else {
222 fprintf(stderr, "ERROR: %s was called with invalid arguments!\n", __func__); 210 fprintf(stderr, "ERROR: %s was called with invalid arguments!\n", __func__);
223 } 211 }
@@ -300,7 +288,7 @@ static int zip_get_app_directory(struct zip* zf, char** path)
300 288
301 len = p - name + 1; 289 len = p - name + 1;
302 290
303 if (*path != NULL) { 291 if (path != NULL) {
304 free(*path); 292 free(*path);
305 *path = NULL; 293 *path = NULL;
306 } 294 }
@@ -640,7 +628,7 @@ static void afc_upload_dir(afc_client_t afc, const char* path, const char* afcpa
640 628
641int main(int argc, char **argv) 629int main(int argc, char **argv)
642{ 630{
643 idevice_t phone = NULL; 631 idevice_t device = NULL;
644 lockdownd_client_t client = NULL; 632 lockdownd_client_t client = NULL;
645 instproxy_client_t ipc = NULL; 633 instproxy_client_t ipc = NULL;
646 instproxy_error_t err; 634 instproxy_error_t err;
@@ -655,16 +643,16 @@ int main(int argc, char **argv)
655 argc -= optind; 643 argc -= optind;
656 argv += optind; 644 argv += optind;
657 645
658 if (IDEVICE_E_SUCCESS != idevice_new(&phone, udid)) { 646 if (IDEVICE_E_SUCCESS != idevice_new(&device, udid)) {
659 fprintf(stderr, "No iOS device found, is it plugged in?\n"); 647 fprintf(stderr, "No iOS device found, is it plugged in?\n");
660 return -1; 648 return -1;
661 } 649 }
662 650
663 if (!udid) { 651 if (!udid) {
664 idevice_get_udid(phone, &udid); 652 idevice_get_udid(device, &udid);
665 } 653 }
666 654
667 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(phone, &client, "ideviceinstaller")) { 655 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &client, "ideviceinstaller")) {
668 fprintf(stderr, "Could not connect to lockdownd. Exiting.\n"); 656 fprintf(stderr, "Could not connect to lockdownd. Exiting.\n");
669 goto leave_cleanup; 657 goto leave_cleanup;
670 } 658 }
@@ -677,7 +665,7 @@ int main(int argc, char **argv)
677 goto leave_cleanup; 665 goto leave_cleanup;
678 } 666 }
679 667
680 np_error_t nperr = np_client_new(phone, service, &np); 668 np_error_t nperr = np_client_new(device, service, &np);
681 669
682 if (service) { 670 if (service) {
683 lockdownd_service_descriptor_free(service); 671 lockdownd_service_descriptor_free(service);
@@ -708,7 +696,7 @@ run_again:
708 goto leave_cleanup; 696 goto leave_cleanup;
709 } 697 }
710 698
711 err = instproxy_client_new(phone, service, &ipc); 699 err = instproxy_client_new(device, service, &ipc);
712 700
713 if (service) { 701 if (service) {
714 lockdownd_service_descriptor_free(service); 702 lockdownd_service_descriptor_free(service);
@@ -722,10 +710,9 @@ run_again:
722 710
723 setbuf(stdout, NULL); 711 setbuf(stdout, NULL);
724 712
725 if (last_status) { 713 free(last_status);
726 free(last_status); 714 last_status = NULL;
727 last_status = NULL; 715
728 }
729 notification_expected = 0; 716 notification_expected = 0;
730 717
731 if (cmd == CMD_LIST_APPS) { 718 if (cmd == CMD_LIST_APPS) {
@@ -808,9 +795,7 @@ run_again:
808 uint64_t af = 0; 795 uint64_t af = 0;
809 char buf[8192]; 796 char buf[8192];
810 797
811 if (service) { 798 lockdownd_service_descriptor_free(service);
812 lockdownd_service_descriptor_free(service);
813 }
814 service = NULL; 799 service = NULL;
815 800
816 if ((lockdownd_start_service(client, "com.apple.afc", &service) != 801 if ((lockdownd_start_service(client, "com.apple.afc", &service) !=
@@ -822,7 +807,7 @@ run_again:
822 lockdownd_client_free(client); 807 lockdownd_client_free(client);
823 client = NULL; 808 client = NULL;
824 809
825 if (afc_client_new(phone, service, &afc) != AFC_E_SUCCESS) { 810 if (afc_client_new(device, service, &afc) != AFC_E_SUCCESS) {
826 fprintf(stderr, "Could not connect to AFC!\n"); 811 fprintf(stderr, "Could not connect to AFC!\n");
827 goto leave_cleanup; 812 goto leave_cleanup;
828 } 813 }
@@ -1025,9 +1010,7 @@ run_again:
1025 } else { 1010 } else {
1026 fprintf(stderr, "WARNING: could not locate %s in archive!\n", ITUNES_METADATA_PLIST_FILENAME); 1011 fprintf(stderr, "WARNING: could not locate %s in archive!\n", ITUNES_METADATA_PLIST_FILENAME);
1027 } 1012 }
1028 if (zbuf) { 1013 free(zbuf);
1029 free(zbuf);
1030 }
1031 1014
1032 /* determine .app directory in archive */ 1015 /* determine .app directory in archive */
1033 zbuf = NULL; 1016 zbuf = NULL;
@@ -1107,9 +1090,7 @@ run_again:
1107 fprintf(stderr, "WARNING: could not locate %s in archive!\n", sinfname); 1090 fprintf(stderr, "WARNING: could not locate %s in archive!\n", sinfname);
1108 } 1091 }
1109 free(sinfname); 1092 free(sinfname);
1110 if (zbuf) { 1093 free(zbuf);
1111 free(zbuf);
1112 }
1113 1094
1114 /* copy archive to device */ 1095 /* copy archive to device */
1115 pkgname = NULL; 1096 pkgname = NULL;
@@ -1312,7 +1293,7 @@ run_again:
1312 lockdownd_client_free(client); 1293 lockdownd_client_free(client);
1313 client = NULL; 1294 client = NULL;
1314 1295
1315 if (afc_client_new(phone, service, &afc) != AFC_E_SUCCESS) { 1296 if (afc_client_new(device, service, &afc) != AFC_E_SUCCESS) {
1316 fprintf(stderr, "Could not connect to AFC!\n"); 1297 fprintf(stderr, "Could not connect to AFC!\n");
1317 goto leave_cleanup; 1298 goto leave_cleanup;
1318 } 1299 }
@@ -1444,7 +1425,7 @@ run_again:
1444 cmd = CMD_REMOVE_ARCHIVE; 1425 cmd = CMD_REMOVE_ARCHIVE;
1445 free(options); 1426 free(options);
1446 options = NULL; 1427 options = NULL;
1447 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(phone, &client, "ideviceinstaller")) { 1428 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &client, "ideviceinstaller")) {
1448 fprintf(stderr, "Could not connect to lockdownd. Exiting.\n"); 1429 fprintf(stderr, "Could not connect to lockdownd. Exiting.\n");
1449 goto leave_cleanup; 1430 goto leave_cleanup;
1450 } 1431 }
@@ -1466,41 +1447,23 @@ run_again:
1466 goto leave_cleanup; 1447 goto leave_cleanup;
1467 } 1448 }
1468 1449
1469 if (client) { 1450 /* not needed anymore */
1470 /* not needed anymore */ 1451 lockdownd_client_free(client);
1471 lockdownd_client_free(client); 1452 client = NULL;
1472 client = NULL;
1473 }
1474 1453
1475 idevice_wait_for_command_to_complete(); 1454 idevice_wait_for_command_to_complete();
1476 1455
1477leave_cleanup: 1456leave_cleanup:
1478 if (bundleidentifier) { 1457 np_client_free(np);
1479 free(bundleidentifier); 1458 instproxy_client_free(ipc);
1480 } 1459 afc_client_free(afc);
1481 if (np) { 1460 lockdownd_client_free(client);
1482 np_client_free(np); 1461 idevice_free(device);
1483 } 1462
1484 if (ipc) { 1463 free(udid);
1485 instproxy_client_free(ipc); 1464 free(appid);
1486 } 1465 free(options);
1487 if (afc) { 1466 free(bundleidentifier);
1488 afc_client_free(afc);
1489 }
1490 if (client) {
1491 lockdownd_client_free(client);
1492 }
1493 idevice_free(phone);
1494
1495 if (udid) {
1496 free(udid);
1497 }
1498 if (appid) {
1499 free(appid);
1500 }
1501 if (options) {
1502 free(options);
1503 }
1504 1467
1505 if (err_occurred && !res) { 1468 if (err_occurred && !res) {
1506 res = 128; 1469 res = 128;