diff options
| -rw-r--r-- | include/libimobiledevice/installation_proxy.h | 14 | ||||
| -rw-r--r-- | src/installation_proxy.c | 40 |
2 files changed, 28 insertions, 26 deletions
diff --git a/include/libimobiledevice/installation_proxy.h b/include/libimobiledevice/installation_proxy.h index 2bf738d..bee9a16 100644 --- a/include/libimobiledevice/installation_proxy.h +++ b/include/libimobiledevice/installation_proxy.h | |||
| @@ -49,21 +49,21 @@ typedef struct instproxy_client_private instproxy_client_private; | |||
| 49 | typedef instproxy_client_private *instproxy_client_t; /**< The client handle. */ | 49 | typedef instproxy_client_private *instproxy_client_t; /**< The client handle. */ |
| 50 | 50 | ||
| 51 | /** Reports the status of the given operation */ | 51 | /** Reports the status of the given operation */ |
| 52 | typedef void (*instproxy_status_cb_t) (const char *operation, plist_t status); | 52 | typedef void (*instproxy_status_cb_t) (const char *operation, plist_t status, void *user_data); |
| 53 | 53 | ||
| 54 | /* Interface */ | 54 | /* Interface */ |
| 55 | instproxy_error_t instproxy_client_new(idevice_t device, uint16_t port, instproxy_client_t *client); | 55 | instproxy_error_t instproxy_client_new(idevice_t device, uint16_t port, instproxy_client_t *client); |
| 56 | instproxy_error_t instproxy_client_free(instproxy_client_t client); | 56 | instproxy_error_t instproxy_client_free(instproxy_client_t client); |
| 57 | 57 | ||
| 58 | instproxy_error_t instproxy_browse(instproxy_client_t client, plist_t client_options, plist_t *result); | 58 | instproxy_error_t instproxy_browse(instproxy_client_t client, plist_t client_options, plist_t *result); |
| 59 | instproxy_error_t instproxy_install(instproxy_client_t client, const char *pkg_path, plist_t client_options, instproxy_status_cb_t status_cb); | 59 | instproxy_error_t instproxy_install(instproxy_client_t client, const char *pkg_path, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data); |
| 60 | instproxy_error_t instproxy_upgrade(instproxy_client_t client, const char *pkg_path, plist_t client_options, instproxy_status_cb_t status_cb); | 60 | instproxy_error_t instproxy_upgrade(instproxy_client_t client, const char *pkg_path, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data); |
| 61 | instproxy_error_t instproxy_uninstall(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb); | 61 | instproxy_error_t instproxy_uninstall(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data); |
| 62 | 62 | ||
| 63 | instproxy_error_t instproxy_lookup_archives(instproxy_client_t client, plist_t client_options, plist_t *result); | 63 | instproxy_error_t instproxy_lookup_archives(instproxy_client_t client, plist_t client_options, plist_t *result); |
| 64 | instproxy_error_t instproxy_archive(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb); | 64 | instproxy_error_t instproxy_archive(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data); |
| 65 | instproxy_error_t instproxy_restore(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb); | 65 | instproxy_error_t instproxy_restore(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data); |
| 66 | instproxy_error_t instproxy_remove_archive(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb); | 66 | instproxy_error_t instproxy_remove_archive(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data); |
| 67 | 67 | ||
| 68 | plist_t instproxy_client_options_new(); | 68 | plist_t instproxy_client_options_new(); |
| 69 | void instproxy_client_options_add(plist_t client_options, ...) G_GNUC_NULL_TERMINATED; | 69 | void instproxy_client_options_add(plist_t client_options, ...) G_GNUC_NULL_TERMINATED; |
diff --git a/src/installation_proxy.c b/src/installation_proxy.c index 3ffbb6a..b54ade7 100644 --- a/src/installation_proxy.c +++ b/src/installation_proxy.c | |||
| @@ -32,6 +32,7 @@ struct instproxy_status_data { | |||
| 32 | instproxy_client_t client; | 32 | instproxy_client_t client; |
| 33 | instproxy_status_cb_t cbfunc; | 33 | instproxy_status_cb_t cbfunc; |
| 34 | char *operation; | 34 | char *operation; |
| 35 | void *user_data; | ||
| 35 | }; | 36 | }; |
| 36 | 37 | ||
| 37 | /** | 38 | /** |
| @@ -271,7 +272,7 @@ leave_unlock: | |||
| 271 | * @param operation Operation name. Will be passed to the callback function | 272 | * @param operation Operation name. Will be passed to the callback function |
| 272 | * in async mode or shown in debug messages in sync mode. | 273 | * in async mode or shown in debug messages in sync mode. |
| 273 | */ | 274 | */ |
| 274 | static instproxy_error_t instproxy_perform_operation(instproxy_client_t client, instproxy_status_cb_t status_cb, const char *operation) | 275 | static instproxy_error_t instproxy_perform_operation(instproxy_client_t client, instproxy_status_cb_t status_cb, const char *operation, void *user_data) |
| 275 | { | 276 | { |
| 276 | instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR; | 277 | instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR; |
| 277 | int ok = 1; | 278 | int ok = 1; |
| @@ -288,7 +289,7 @@ static instproxy_error_t instproxy_perform_operation(instproxy_client_t client, | |||
| 288 | if (dict) { | 289 | if (dict) { |
| 289 | /* invoke callback function */ | 290 | /* invoke callback function */ |
| 290 | if (status_cb) { | 291 | if (status_cb) { |
| 291 | status_cb(operation, dict); | 292 | status_cb(operation, dict, user_data); |
| 292 | } | 293 | } |
| 293 | /* check for 'Error', so we can abort cleanly */ | 294 | /* check for 'Error', so we can abort cleanly */ |
| 294 | plist_t err = plist_dict_get_item(dict, "Error"); | 295 | plist_t err = plist_dict_get_item(dict, "Error"); |
| @@ -352,7 +353,7 @@ static gpointer instproxy_status_updater(gpointer arg) | |||
| 352 | struct instproxy_status_data *data = (struct instproxy_status_data*)arg; | 353 | struct instproxy_status_data *data = (struct instproxy_status_data*)arg; |
| 353 | 354 | ||
| 354 | /* run until the operation is complete or an error occurs */ | 355 | /* run until the operation is complete or an error occurs */ |
| 355 | (void)instproxy_perform_operation(data->client, data->cbfunc, data->operation); | 356 | (void)instproxy_perform_operation(data->client, data->cbfunc, data->operation, data->user_data); |
| 356 | 357 | ||
| 357 | /* cleanup */ | 358 | /* cleanup */ |
| 358 | instproxy_lock(data->client); | 359 | instproxy_lock(data->client); |
| @@ -382,7 +383,7 @@ static gpointer instproxy_status_updater(gpointer arg) | |||
| 382 | * when the operation completed successfully (sync). | 383 | * when the operation completed successfully (sync). |
| 383 | * An INSTPROXY_E_* error value is returned if an error occured. | 384 | * An INSTPROXY_E_* error value is returned if an error occured. |
| 384 | */ | 385 | */ |
| 385 | static instproxy_error_t instproxy_create_status_updater(instproxy_client_t client, instproxy_status_cb_t status_cb, const char *operation) | 386 | static instproxy_error_t instproxy_create_status_updater(instproxy_client_t client, instproxy_status_cb_t status_cb, const char *operation, void *user_data) |
| 386 | { | 387 | { |
| 387 | instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR; | 388 | instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR; |
| 388 | if (status_cb) { | 389 | if (status_cb) { |
| @@ -392,6 +393,7 @@ static instproxy_error_t instproxy_create_status_updater(instproxy_client_t clie | |||
| 392 | data->client = client; | 393 | data->client = client; |
| 393 | data->cbfunc = status_cb; | 394 | data->cbfunc = status_cb; |
| 394 | data->operation = strdup(operation); | 395 | data->operation = strdup(operation); |
| 396 | data->user_data = user_data; | ||
| 395 | 397 | ||
| 396 | client->status_updater = g_thread_create(instproxy_status_updater, data, TRUE, NULL); | 398 | client->status_updater = g_thread_create(instproxy_status_updater, data, TRUE, NULL); |
| 397 | if (client->status_updater) { | 399 | if (client->status_updater) { |
| @@ -400,7 +402,7 @@ static instproxy_error_t instproxy_create_status_updater(instproxy_client_t clie | |||
| 400 | } | 402 | } |
| 401 | } else { | 403 | } else { |
| 402 | /* sync mode */ | 404 | /* sync mode */ |
| 403 | res = instproxy_perform_operation(client, NULL, operation); | 405 | res = instproxy_perform_operation(client, NULL, operation, NULL); |
| 404 | } | 406 | } |
| 405 | return res; | 407 | return res; |
| 406 | } | 408 | } |
| @@ -419,7 +421,7 @@ static instproxy_error_t instproxy_create_status_updater(instproxy_client_t clie | |||
| 419 | * @return INSTPROXY_E_SUCCESS on success or an INSTPROXY_E_* error value if | 421 | * @return INSTPROXY_E_SUCCESS on success or an INSTPROXY_E_* error value if |
| 420 | * an error occured. | 422 | * an error occured. |
| 421 | */ | 423 | */ |
| 422 | static instproxy_error_t instproxy_install_or_upgrade(instproxy_client_t client, const char *pkg_path, plist_t client_options, instproxy_status_cb_t status_cb, const char *command) | 424 | static instproxy_error_t instproxy_install_or_upgrade(instproxy_client_t client, const char *pkg_path, plist_t client_options, instproxy_status_cb_t status_cb, const char *command, void *user_data) |
| 423 | { | 425 | { |
| 424 | if (!client || !client->parent || !pkg_path) { | 426 | if (!client || !client->parent || !pkg_path) { |
| 425 | return INSTPROXY_E_INVALID_ARG; | 427 | return INSTPROXY_E_INVALID_ARG; |
| @@ -437,7 +439,7 @@ static instproxy_error_t instproxy_install_or_upgrade(instproxy_client_t client, | |||
| 437 | return res; | 439 | return res; |
| 438 | } | 440 | } |
| 439 | 441 | ||
| 440 | return instproxy_create_status_updater(client, status_cb, command); | 442 | return instproxy_create_status_updater(client, status_cb, command, user_data); |
| 441 | } | 443 | } |
| 442 | 444 | ||
| 443 | /** | 445 | /** |
| @@ -463,9 +465,9 @@ static instproxy_error_t instproxy_install_or_upgrade(instproxy_client_t client, | |||
| 463 | * created successfully; any error occuring during the operation has to be | 465 | * created successfully; any error occuring during the operation has to be |
| 464 | * handled inside the specified callback function. | 466 | * handled inside the specified callback function. |
| 465 | */ | 467 | */ |
| 466 | instproxy_error_t instproxy_install(instproxy_client_t client, const char *pkg_path, plist_t client_options, instproxy_status_cb_t status_cb) | 468 | instproxy_error_t instproxy_install(instproxy_client_t client, const char *pkg_path, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) |
| 467 | { | 469 | { |
| 468 | return instproxy_install_or_upgrade(client, pkg_path, client_options, status_cb, "Install"); | 470 | return instproxy_install_or_upgrade(client, pkg_path, client_options, status_cb, "Install", user_data); |
| 469 | } | 471 | } |
| 470 | 472 | ||
| 471 | /** | 473 | /** |
| @@ -493,9 +495,9 @@ instproxy_error_t instproxy_install(instproxy_client_t client, const char *pkg_p | |||
| 493 | * created successfully; any error occuring during the operation has to be | 495 | * created successfully; any error occuring during the operation has to be |
| 494 | * handled inside the specified callback function. | 496 | * handled inside the specified callback function. |
| 495 | */ | 497 | */ |
| 496 | instproxy_error_t instproxy_upgrade(instproxy_client_t client, const char *pkg_path, plist_t client_options, instproxy_status_cb_t status_cb) | 498 | instproxy_error_t instproxy_upgrade(instproxy_client_t client, const char *pkg_path, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) |
| 497 | { | 499 | { |
| 498 | return instproxy_install_or_upgrade(client, pkg_path, client_options, status_cb, "Upgrade"); | 500 | return instproxy_install_or_upgrade(client, pkg_path, client_options, status_cb, "Upgrade", user_data); |
| 499 | } | 501 | } |
| 500 | 502 | ||
| 501 | /** | 503 | /** |
| @@ -516,7 +518,7 @@ instproxy_error_t instproxy_upgrade(instproxy_client_t client, const char *pkg_p | |||
| 516 | * created successfully; any error occuring during the operation has to be | 518 | * created successfully; any error occuring during the operation has to be |
| 517 | * handled inside the specified callback function. | 519 | * handled inside the specified callback function. |
| 518 | */ | 520 | */ |
| 519 | instproxy_error_t instproxy_uninstall(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb) | 521 | instproxy_error_t instproxy_uninstall(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) |
| 520 | { | 522 | { |
| 521 | if (!client || !client->parent || !appid) { | 523 | if (!client || !client->parent || !appid) { |
| 522 | return INSTPROXY_E_INVALID_ARG; | 524 | return INSTPROXY_E_INVALID_ARG; |
| @@ -542,7 +544,7 @@ instproxy_error_t instproxy_uninstall(instproxy_client_t client, const char *app | |||
| 542 | return res; | 544 | return res; |
| 543 | } | 545 | } |
| 544 | 546 | ||
| 545 | return instproxy_create_status_updater(client, status_cb, "Uninstall"); | 547 | return instproxy_create_status_updater(client, status_cb, "Uninstall", user_data); |
| 546 | } | 548 | } |
| 547 | 549 | ||
| 548 | /** | 550 | /** |
| @@ -608,7 +610,7 @@ leave_unlock: | |||
| 608 | * created successfully; any error occuring during the operation has to be | 610 | * created successfully; any error occuring during the operation has to be |
| 609 | * handled inside the specified callback function. | 611 | * handled inside the specified callback function. |
| 610 | */ | 612 | */ |
| 611 | instproxy_error_t instproxy_archive(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb) | 613 | instproxy_error_t instproxy_archive(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) |
| 612 | { | 614 | { |
| 613 | if (!client || !client->parent || !appid) | 615 | if (!client || !client->parent || !appid) |
| 614 | return INSTPROXY_E_INVALID_ARG; | 616 | return INSTPROXY_E_INVALID_ARG; |
| @@ -625,7 +627,7 @@ instproxy_error_t instproxy_archive(instproxy_client_t client, const char *appid | |||
| 625 | debug_info("could not send plist, error %d", res); | 627 | debug_info("could not send plist, error %d", res); |
| 626 | return res; | 628 | return res; |
| 627 | } | 629 | } |
| 628 | return instproxy_create_status_updater(client, status_cb, "Archive"); | 630 | return instproxy_create_status_updater(client, status_cb, "Archive", user_data); |
| 629 | } | 631 | } |
| 630 | 632 | ||
| 631 | /** | 633 | /** |
| @@ -648,7 +650,7 @@ instproxy_error_t instproxy_archive(instproxy_client_t client, const char *appid | |||
| 648 | * created successfully; any error occuring during the operation has to be | 650 | * created successfully; any error occuring during the operation has to be |
| 649 | * handled inside the specified callback function. | 651 | * handled inside the specified callback function. |
| 650 | */ | 652 | */ |
| 651 | instproxy_error_t instproxy_restore(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb) | 653 | instproxy_error_t instproxy_restore(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) |
| 652 | { | 654 | { |
| 653 | if (!client || !client->parent || !appid) | 655 | if (!client || !client->parent || !appid) |
| 654 | return INSTPROXY_E_INVALID_ARG; | 656 | return INSTPROXY_E_INVALID_ARG; |
| @@ -665,7 +667,7 @@ instproxy_error_t instproxy_restore(instproxy_client_t client, const char *appid | |||
| 665 | debug_info("could not send plist, error %d", res); | 667 | debug_info("could not send plist, error %d", res); |
| 666 | return res; | 668 | return res; |
| 667 | } | 669 | } |
| 668 | return instproxy_create_status_updater(client, status_cb, "Restore"); | 670 | return instproxy_create_status_updater(client, status_cb, "Restore", user_data); |
| 669 | } | 671 | } |
| 670 | 672 | ||
| 671 | /** | 673 | /** |
| @@ -688,7 +690,7 @@ instproxy_error_t instproxy_restore(instproxy_client_t client, const char *appid | |||
| 688 | * created successfully; any error occuring during the operation has to be | 690 | * created successfully; any error occuring during the operation has to be |
| 689 | * handled inside the specified callback function. | 691 | * handled inside the specified callback function. |
| 690 | */ | 692 | */ |
| 691 | instproxy_error_t instproxy_remove_archive(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb) | 693 | instproxy_error_t instproxy_remove_archive(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) |
| 692 | { | 694 | { |
| 693 | if (!client || !client->parent || !appid) | 695 | if (!client || !client->parent || !appid) |
| 694 | return INSTPROXY_E_INVALID_ARG; | 696 | return INSTPROXY_E_INVALID_ARG; |
| @@ -705,7 +707,7 @@ instproxy_error_t instproxy_remove_archive(instproxy_client_t client, const char | |||
| 705 | debug_info("could not send plist, error %d", res); | 707 | debug_info("could not send plist, error %d", res); |
| 706 | return res; | 708 | return res; |
| 707 | } | 709 | } |
| 708 | return instproxy_create_status_updater(client, status_cb, "RemoveArchive"); | 710 | return instproxy_create_status_updater(client, status_cb, "RemoveArchive", user_data); |
| 709 | } | 711 | } |
| 710 | 712 | ||
| 711 | /** | 713 | /** |
