diff options
| -rw-r--r-- | dev/Makefile.am | 7 | ||||
| -rw-r--r-- | dev/housearresttest.c | 214 | ||||
| -rw-r--r-- | include/Makefile.am | 1 | ||||
| -rw-r--r-- | include/libimobiledevice/house_arrest.h | 64 | ||||
| -rw-r--r-- | src/Makefile.am | 1 | ||||
| -rw-r--r-- | src/house_arrest.c | 250 | ||||
| -rw-r--r-- | src/house_arrest.h | 39 |
7 files changed, 575 insertions, 1 deletions
diff --git a/dev/Makefile.am b/dev/Makefile.am index 0790c80..6da20da 100644 --- a/dev/Makefile.am +++ b/dev/Makefile.am | |||
| @@ -4,7 +4,7 @@ AM_CFLAGS = $(GLOBAL_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_C | |||
| 4 | AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) | 4 | AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) |
| 5 | 5 | ||
| 6 | if ENABLE_DEVTOOLS | 6 | if ENABLE_DEVTOOLS |
| 7 | noinst_PROGRAMS = ideviceclient lckd-client afccheck msyncclient filerelaytest | 7 | noinst_PROGRAMS = ideviceclient lckd-client afccheck msyncclient filerelaytest housearresttest |
| 8 | 8 | ||
| 9 | ideviceclient_SOURCES = ideviceclient.c | 9 | ideviceclient_SOURCES = ideviceclient.c |
| 10 | ideviceclient_LDADD = ../src/libimobiledevice.la | 10 | ideviceclient_LDADD = ../src/libimobiledevice.la |
| @@ -29,6 +29,11 @@ filerelaytest_CFLAGS = $(AM_CFLAGS) | |||
| 29 | filerelaytest_LDFLAGS = $(AM_LDFLAGS) | 29 | filerelaytest_LDFLAGS = $(AM_LDFLAGS) |
| 30 | filerelaytest_LDADD = ../src/libimobiledevice.la | 30 | filerelaytest_LDADD = ../src/libimobiledevice.la |
| 31 | 31 | ||
| 32 | housearresttest_SOURCES = housearresttest.c | ||
| 33 | housearresttest_CFLAGS = $(AM_CFLAGS) | ||
| 34 | housearresttest_LDFLAGS = $(AM_LDFLAGS) | ||
| 35 | housearresttest_LDADD = ../src/libimobiledevice.la | ||
| 36 | |||
| 32 | endif # ENABLE_DEVTOOLS | 37 | endif # ENABLE_DEVTOOLS |
| 33 | 38 | ||
| 34 | EXTRA_DIST = ideviceclient.c lckdclient.c afccheck.c msyncclient.c | 39 | EXTRA_DIST = ideviceclient.c lckdclient.c afccheck.c msyncclient.c |
diff --git a/dev/housearresttest.c b/dev/housearresttest.c new file mode 100644 index 0000000..7282a8c --- /dev/null +++ b/dev/housearresttest.c | |||
| @@ -0,0 +1,214 @@ | |||
| 1 | /* | ||
| 2 | * housearresttest.c | ||
| 3 | * Simple Test program showing the usage of the house_arrest interface. | ||
| 4 | * | ||
| 5 | * Copyright (c) 2010 Nikias Bassen All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | #include <stdio.h> | ||
| 22 | #include <stdlib.h> | ||
| 23 | #include <string.h> | ||
| 24 | |||
| 25 | #include <libimobiledevice/libimobiledevice.h> | ||
| 26 | #include <libimobiledevice/lockdown.h> | ||
| 27 | #include <libimobiledevice/house_arrest.h> | ||
| 28 | #include <libimobiledevice/afc.h> | ||
| 29 | |||
| 30 | static void print_usage(int argc, char **argv) | ||
| 31 | { | ||
| 32 | char *name = NULL; | ||
| 33 | |||
| 34 | name = strrchr(argv[0], '/'); | ||
| 35 | printf("Usage: %s [OPTIONS] APPID\n", (name ? name + 1: argv[0])); | ||
| 36 | printf("Test the house_arrest service.\n\n"); | ||
| 37 | printf(" -d, --debug\t\tenable communication debugging\n"); | ||
| 38 | printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n"); | ||
| 39 | printf(" -t, --test\t\ttest creating, writing, and deleting a file\n"); | ||
| 40 | printf(" -h, --help\t\tprints usage information\n"); | ||
| 41 | printf("\n"); | ||
| 42 | } | ||
| 43 | |||
| 44 | int main(int argc, char **argv) | ||
| 45 | { | ||
| 46 | idevice_t dev = NULL; | ||
| 47 | lockdownd_client_t client = NULL; | ||
| 48 | house_arrest_client_t hac = NULL; | ||
| 49 | house_arrest_error_t res; | ||
| 50 | int i; | ||
| 51 | char *uuid = NULL; | ||
| 52 | const char *appid = NULL; | ||
| 53 | int test_file_io = 0; | ||
| 54 | |||
| 55 | /* parse cmdline args */ | ||
| 56 | for (i = 1; i < argc; i++) { | ||
| 57 | if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { | ||
| 58 | idevice_set_debug_level(1); | ||
| 59 | continue; | ||
| 60 | } | ||
| 61 | else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) { | ||
| 62 | i++; | ||
| 63 | if (!argv[i] || (strlen(argv[i]) != 40)) { | ||
| 64 | print_usage(argc, argv); | ||
| 65 | return 0; | ||
| 66 | } | ||
| 67 | uuid = strdup(argv[i]); | ||
| 68 | continue; | ||
| 69 | } | ||
| 70 | else if (!strcmp(argv[i], "-t") || !strcmp(argv[i], "--test")) { | ||
| 71 | test_file_io = 1; | ||
| 72 | continue; | ||
| 73 | } | ||
| 74 | else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { | ||
| 75 | print_usage(argc, argv); | ||
| 76 | return 0; | ||
| 77 | } | ||
| 78 | else { | ||
| 79 | appid = argv[i]; | ||
| 80 | break; | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | if (!appid) { | ||
| 85 | print_usage(argc, argv); | ||
| 86 | return 0; | ||
| 87 | } | ||
| 88 | |||
| 89 | if (idevice_new(&dev, uuid) != IDEVICE_E_SUCCESS) { | ||
| 90 | printf("no device connected?!\n"); | ||
| 91 | goto leave_cleanup; | ||
| 92 | } | ||
| 93 | |||
| 94 | if (lockdownd_client_new_with_handshake(dev, &client, NULL) != LOCKDOWN_E_SUCCESS) { | ||
| 95 | printf("could not connect to lockdownd!\n"); | ||
| 96 | goto leave_cleanup; | ||
| 97 | } | ||
| 98 | |||
| 99 | uint16_t port = 0; | ||
| 100 | if (lockdownd_start_service(client, "com.apple.mobile.house_arrest", &port) != LOCKDOWN_E_SUCCESS) { | ||
| 101 | printf("could not start house_arrest service!\n"); | ||
| 102 | goto leave_cleanup; | ||
| 103 | } | ||
| 104 | |||
| 105 | if (client) { | ||
| 106 | lockdownd_client_free(client); | ||
| 107 | client = NULL; | ||
| 108 | } | ||
| 109 | |||
| 110 | if (house_arrest_client_new(dev, port, &hac) != HOUSE_ARREST_E_SUCCESS) { | ||
| 111 | printf("could not connect to house_arrest service!\n"); | ||
| 112 | goto leave_cleanup; | ||
| 113 | } | ||
| 114 | |||
| 115 | res = house_arrest_send_command(hac, "VendDocuments", appid); | ||
| 116 | if (res != HOUSE_ARREST_E_SUCCESS) { | ||
| 117 | printf("error %d when trying to get VendDocuments\n", res); | ||
| 118 | goto leave_cleanup; | ||
| 119 | } | ||
| 120 | |||
| 121 | plist_t dict = NULL; | ||
| 122 | if (house_arrest_get_result(hac, &dict) != HOUSE_ARREST_E_SUCCESS) { | ||
| 123 | if (house_arrest_get_result(hac, &dict) != HOUSE_ARREST_E_SUCCESS) { | ||
| 124 | printf("hmmm....\n"); | ||
| 125 | goto leave_cleanup; | ||
| 126 | } | ||
| 127 | } | ||
| 128 | |||
| 129 | plist_t node = plist_dict_get_item(dict, "Error"); | ||
| 130 | if (node) { | ||
| 131 | char *str = NULL; | ||
| 132 | plist_get_string_val(node, &str); | ||
| 133 | printf("Error: %s\n", str); | ||
| 134 | if (str) free(str); | ||
| 135 | plist_free(dict); | ||
| 136 | dict = NULL; | ||
| 137 | goto leave_cleanup; | ||
| 138 | } | ||
| 139 | node = plist_dict_get_item(dict, "Status"); | ||
| 140 | if (node) { | ||
| 141 | char *str = NULL; | ||
| 142 | plist_get_string_val(node, &str); | ||
| 143 | if (str && (strcmp(str, "Complete") != 0)) { | ||
| 144 | printf("Warning: Status is not 'Complete' but '%s'\n", str); | ||
| 145 | } | ||
| 146 | if (str) free(str); | ||
| 147 | plist_free(dict); | ||
| 148 | dict = NULL; | ||
| 149 | } | ||
| 150 | if (dict) { | ||
| 151 | plist_free(dict); | ||
| 152 | } | ||
| 153 | |||
| 154 | afc_client_t afc = NULL; | ||
| 155 | afc_error_t ae = afc_client_new_from_house_arrest_client(hac, &afc); | ||
| 156 | if (ae != AFC_E_SUCCESS) { | ||
| 157 | printf("afc error %d\n", ae); | ||
| 158 | } | ||
| 159 | if (ae == AFC_E_SUCCESS) { | ||
| 160 | char **list = NULL; | ||
| 161 | afc_read_directory(afc, "/", &list); | ||
| 162 | printf("Directory contents:\n"); | ||
| 163 | if (list) { | ||
| 164 | while (list[0]) { | ||
| 165 | if (strcmp(list[0], ".") && strcmp(list[0], "..")) { | ||
| 166 | puts(list[0]); | ||
| 167 | } | ||
| 168 | list++; | ||
| 169 | } | ||
| 170 | } | ||
| 171 | |||
| 172 | if (test_file_io) { | ||
| 173 | uint64_t tf = 0; | ||
| 174 | printf("\n==== Performing file tests ====\n"); | ||
| 175 | printf("Opening file 'foobar' for writing: "); | ||
| 176 | if (afc_file_open(afc, "/foobar", AFC_FOPEN_RW, &tf) == AFC_E_SUCCESS) { | ||
| 177 | uint32_t wb = 0; | ||
| 178 | printf("OK\n"); | ||
| 179 | |||
| 180 | printf("Writing to file: "); | ||
| 181 | if (afc_file_write(afc, tf, "test\r\n", 6, &wb) != AFC_E_SUCCESS) { | ||
| 182 | printf("ERROR\n"); | ||
| 183 | } else { | ||
| 184 | printf("OK\n"); | ||
| 185 | } | ||
| 186 | afc_file_close(afc, tf); | ||
| 187 | printf("Deleting file 'foobar': "); | ||
| 188 | if (afc_remove_path(afc, "/foobar") == AFC_E_SUCCESS) { | ||
| 189 | printf("OK\n"); | ||
| 190 | } else { | ||
| 191 | printf("ERROR\n"); | ||
| 192 | } | ||
| 193 | } else { | ||
| 194 | printf("ERROR\n"); | ||
| 195 | } | ||
| 196 | } | ||
| 197 | afc_client_free(afc); | ||
| 198 | } else { | ||
| 199 | printf("failed to connect to afc service, error %d\n", ae); | ||
| 200 | } | ||
| 201 | |||
| 202 | leave_cleanup: | ||
| 203 | if (hac) { | ||
| 204 | house_arrest_client_free(hac); | ||
| 205 | } | ||
| 206 | if (client) { | ||
| 207 | lockdownd_client_free(client); | ||
| 208 | } | ||
| 209 | if (dev) { | ||
| 210 | idevice_free(dev); | ||
| 211 | } | ||
| 212 | |||
| 213 | return 0; | ||
| 214 | } | ||
diff --git a/include/Makefile.am b/include/Makefile.am index 12f3188..44794c6 100644 --- a/include/Makefile.am +++ b/include/Makefile.am | |||
| @@ -9,4 +9,5 @@ nobase_include_HEADERS = libimobiledevice/libimobiledevice.h \ | |||
| 9 | libimobiledevice/screenshotr.h \ | 9 | libimobiledevice/screenshotr.h \ |
| 10 | libimobiledevice/mobilesync.h \ | 10 | libimobiledevice/mobilesync.h \ |
| 11 | libimobiledevice/mobilebackup.h \ | 11 | libimobiledevice/mobilebackup.h \ |
| 12 | libimobiledevice/house_arrest.h \ | ||
| 12 | libimobiledevice/restore.h | 13 | libimobiledevice/restore.h |
diff --git a/include/libimobiledevice/house_arrest.h b/include/libimobiledevice/house_arrest.h new file mode 100644 index 0000000..04290f1 --- /dev/null +++ b/include/libimobiledevice/house_arrest.h | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | /** | ||
| 2 | * @file libimobiledevice/house_arrest.h | ||
| 3 | * @brief Access AppStore application folders and their contents. | ||
| 4 | * \internal | ||
| 5 | * | ||
| 6 | * Copyright (c) 2010 Nikias Bassen, All Rights Reserved. | ||
| 7 | * | ||
| 8 | * This library is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU Lesser General Public | ||
| 10 | * License as published by the Free Software Foundation; either | ||
| 11 | * version 2.1 of the License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * This library is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * Lesser General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU Lesser General Public | ||
| 19 | * License along with this library; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 21 | */ | ||
| 22 | |||
| 23 | #ifndef HOUSE_ARREST_H | ||
| 24 | #define HOUSE_ARREST_H | ||
| 25 | |||
| 26 | #ifdef __cplusplus | ||
| 27 | extern "C" { | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #include <libimobiledevice/libimobiledevice.h> | ||
| 31 | #include <libimobiledevice/afc.h> | ||
| 32 | |||
| 33 | /** @name Error Codes */ | ||
| 34 | /*@{*/ | ||
| 35 | #define HOUSE_ARREST_E_SUCCESS 0 | ||
| 36 | #define HOUSE_ARREST_E_INVALID_ARG -1 | ||
| 37 | #define HOUSE_ARREST_E_PLIST_ERROR -2 | ||
| 38 | #define HOUSE_ARREST_E_CONN_FAILED -3 | ||
| 39 | #define HOUSE_ARREST_E_INVALID_MODE -4 | ||
| 40 | |||
| 41 | #define HOUSE_ARREST_E_UNKNOWN_ERROR -256 | ||
| 42 | /*@}*/ | ||
| 43 | |||
| 44 | /** Represents an error code. */ | ||
| 45 | typedef int16_t house_arrest_error_t; | ||
| 46 | |||
| 47 | typedef struct house_arrest_client_private house_arrest_client_private; | ||
| 48 | typedef house_arrest_client_private *house_arrest_client_t; /**< The client handle. */ | ||
| 49 | |||
| 50 | /* Interface */ | ||
| 51 | house_arrest_error_t house_arrest_client_new(idevice_t device, uint16_t port, house_arrest_client_t *client); | ||
| 52 | house_arrest_error_t house_arrest_client_free(house_arrest_client_t client); | ||
| 53 | |||
| 54 | house_arrest_error_t house_arrest_send_request(house_arrest_client_t client, plist_t dict); | ||
| 55 | house_arrest_error_t house_arrest_send_command(house_arrest_client_t client, const char *command, const char *appid); | ||
| 56 | house_arrest_error_t house_arrest_get_result(house_arrest_client_t client, plist_t *dict); | ||
| 57 | |||
| 58 | afc_error_t afc_client_new_from_house_arrest_client(house_arrest_client_t client, afc_client_t *afc_client); | ||
| 59 | |||
| 60 | #ifdef __cplusplus | ||
| 61 | } | ||
| 62 | #endif | ||
| 63 | |||
| 64 | #endif | ||
diff --git a/src/Makefile.am b/src/Makefile.am index 338daf2..70dc895 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
| @@ -20,4 +20,5 @@ libimobiledevice_la_SOURCES = idevice.c idevice.h \ | |||
| 20 | screenshotr.c screenshotr.h\ | 20 | screenshotr.c screenshotr.h\ |
| 21 | mobilesync.c mobilesync.h\ | 21 | mobilesync.c mobilesync.h\ |
| 22 | mobilebackup.c mobilebackup.h\ | 22 | mobilebackup.c mobilebackup.h\ |
| 23 | house_arrest.c house_arrest.h\ | ||
| 23 | restore.c restore.h | 24 | restore.c restore.h |
diff --git a/src/house_arrest.c b/src/house_arrest.c new file mode 100644 index 0000000..5baa76e --- /dev/null +++ b/src/house_arrest.c | |||
| @@ -0,0 +1,250 @@ | |||
| 1 | /* | ||
| 2 | * house_arrest.c | ||
| 3 | * com.apple.mobile.house_arrest service implementation. | ||
| 4 | * | ||
| 5 | * Copyright (c) 2010 Nikias Bassen, All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <string.h> | ||
| 23 | #include <stdlib.h> | ||
| 24 | #include <unistd.h> | ||
| 25 | #include <plist/plist.h> | ||
| 26 | |||
| 27 | #include "house_arrest.h" | ||
| 28 | #include "property_list_service.h" | ||
| 29 | #include "afc.h" | ||
| 30 | #include "debug.h" | ||
| 31 | |||
| 32 | /** | ||
| 33 | * Convert a property_list_service_error_t value to a house_arrest_error_t | ||
| 34 | * value. Used internally to get correct error codes. | ||
| 35 | * | ||
| 36 | * @param err A property_list_service_error_t error code | ||
| 37 | * | ||
| 38 | * @return A matching house_arrest_error_t error code, | ||
| 39 | * HOUSE_ARREST_E_UNKNOWN_ERROR otherwise. | ||
| 40 | */ | ||
| 41 | static house_arrest_error_t house_arrest_error(property_list_service_error_t err) | ||
| 42 | { | ||
| 43 | switch (err) { | ||
| 44 | case PROPERTY_LIST_SERVICE_E_SUCCESS: | ||
| 45 | return HOUSE_ARREST_E_SUCCESS; | ||
| 46 | case PROPERTY_LIST_SERVICE_E_INVALID_ARG: | ||
| 47 | return HOUSE_ARREST_E_INVALID_ARG; | ||
| 48 | case PROPERTY_LIST_SERVICE_E_PLIST_ERROR: | ||
| 49 | return HOUSE_ARREST_E_PLIST_ERROR; | ||
| 50 | case PROPERTY_LIST_SERVICE_E_MUX_ERROR: | ||
| 51 | return HOUSE_ARREST_E_CONN_FAILED; | ||
| 52 | default: | ||
| 53 | break; | ||
| 54 | } | ||
| 55 | return HOUSE_ARREST_E_UNKNOWN_ERROR; | ||
| 56 | } | ||
| 57 | |||
| 58 | /** | ||
| 59 | * Connects to the house_arrest service on the specified device. | ||
| 60 | * | ||
| 61 | * @param device The device to connect to. | ||
| 62 | * @param port Destination port (usually given by lockdownd_start_service). | ||
| 63 | * @param client Pointer that will point to a newly allocated | ||
| 64 | * housearrest_client_t upon successful return. | ||
| 65 | * | ||
| 66 | * @return HOUSE_ARREST_E_SUCCESS on success, HOUSE_ARREST_E_INVALID_ARG when | ||
| 67 | * client is NULL, or an HOUSE_ARREST_E_* error code otherwise. | ||
| 68 | */ | ||
| 69 | house_arrest_error_t house_arrest_client_new(idevice_t device, uint16_t port, house_arrest_client_t *client) | ||
| 70 | { | ||
| 71 | if (!device) | ||
| 72 | return HOUSE_ARREST_E_INVALID_ARG; | ||
| 73 | |||
| 74 | property_list_service_client_t plistclient = NULL; | ||
| 75 | house_arrest_error_t err = house_arrest_error(property_list_service_client_new(device, port, &plistclient)); | ||
| 76 | if (err != HOUSE_ARREST_E_SUCCESS) { | ||
| 77 | return err; | ||
| 78 | } | ||
| 79 | |||
| 80 | house_arrest_client_t client_loc = (house_arrest_client_t) malloc(sizeof(struct house_arrest_client_private)); | ||
| 81 | client_loc->parent = plistclient; | ||
| 82 | client_loc->mode = HOUSE_ARREST_CLIENT_MODE_NORMAL; | ||
| 83 | |||
| 84 | *client = client_loc; | ||
| 85 | return HOUSE_ARREST_E_SUCCESS; | ||
| 86 | } | ||
| 87 | |||
| 88 | /** | ||
| 89 | * Disconnects an house_arrest client from the device and frees up the | ||
| 90 | * house_arrest client data. | ||
| 91 | * | ||
| 92 | * @note After using afc_client_new_from_house_arrest_client(), make sure | ||
| 93 | * you call afc_client_free() before calling this function to ensure | ||
| 94 | * a proper cleanup. Do not call this function if you still need to | ||
| 95 | * perform AFC operations since it will close the connection. | ||
| 96 | * | ||
| 97 | * @param client The house_arrest client to disconnect and free. | ||
| 98 | * | ||
| 99 | * @return HOUSE_ARREST_E_SUCCESS on success, HOUSE_ARREST_E_INVALID_ARG when | ||
| 100 | * client is NULL, or an HOUSE_ARREST_E_* error code otherwise. | ||
| 101 | */ | ||
| 102 | house_arrest_error_t house_arrest_client_free(house_arrest_client_t client) | ||
| 103 | { | ||
| 104 | if (!client) | ||
| 105 | return HOUSE_ARREST_E_INVALID_ARG; | ||
| 106 | |||
| 107 | house_arrest_error_t err = HOUSE_ARREST_E_SUCCESS; | ||
| 108 | if (client->parent && client->parent->connection) { | ||
| 109 | house_arrest_error(property_list_service_client_free(client->parent)); | ||
| 110 | } | ||
| 111 | client->parent = NULL; | ||
| 112 | free(client); | ||
| 113 | |||
| 114 | return err; | ||
| 115 | } | ||
| 116 | |||
| 117 | /** | ||
| 118 | * Sends a generic request to the connected house_arrest service. | ||
| 119 | * | ||
| 120 | * @param client The house_arrest client to use. | ||
| 121 | * @param dict The request to send as a plist of type PLIST_DICT. | ||
| 122 | * | ||
| 123 | * @note If this function returns HOUSE_ARREST_E_SUCCESS it does not mean | ||
| 124 | * that the request was successful. To check for success or failure you | ||
| 125 | * need to call house_arrest_get_result(). | ||
| 126 | * @see house_arrest_get_result | ||
| 127 | * | ||
| 128 | * @return HOUSE_ARREST_E_SUCCESS if the request was successfully sent, | ||
| 129 | * HOUSE_ARREST_E_INVALID_ARG if client or dict is invalid, | ||
| 130 | * HOUSE_ARREST_E_PLIST_ERROR if dict is not a plist of type PLIST_DICT, | ||
| 131 | * HOUSE_ARREST_E_INVALID_MODE if the client is not in the correct mode, | ||
| 132 | * or HOUSE_ARREST_E_CONN_FAILED if a connection error occured. | ||
| 133 | */ | ||
| 134 | house_arrest_error_t house_arrest_send_request(house_arrest_client_t client, plist_t dict) | ||
| 135 | { | ||
| 136 | if (!client || !client->parent || !dict) | ||
| 137 | return HOUSE_ARREST_E_INVALID_ARG; | ||
| 138 | if (plist_get_node_type(dict) != PLIST_DICT) | ||
| 139 | return HOUSE_ARREST_E_PLIST_ERROR; | ||
| 140 | if (client->mode != HOUSE_ARREST_CLIENT_MODE_NORMAL) | ||
| 141 | return HOUSE_ARREST_E_INVALID_MODE; | ||
| 142 | |||
| 143 | house_arrest_error_t res = house_arrest_error(property_list_service_send_xml_plist(client->parent, dict)); | ||
| 144 | if (res != HOUSE_ARREST_E_SUCCESS) { | ||
| 145 | debug_info("could not send plist, error %d", res); | ||
| 146 | } | ||
| 147 | return res; | ||
| 148 | } | ||
| 149 | |||
| 150 | /** | ||
| 151 | * Send a command to the connected house_arrest service. | ||
| 152 | * Calls house_arrest_send_request() internally. | ||
| 153 | * | ||
| 154 | * @param client The house_arrest client to use. | ||
| 155 | * @param command The command to send. Currently, only VendContainer and | ||
| 156 | * VendDocuments are known. | ||
| 157 | * @param appid The application identifier to pass along with the . | ||
| 158 | * | ||
| 159 | * @note If this function returns HOUSE_ARREST_E_SUCCESS it does not mean | ||
| 160 | * that the command was successful. To check for success or failure you | ||
| 161 | * need to call house_arrest_get_result(). | ||
| 162 | * @see house_arrest_get_result | ||
| 163 | * | ||
| 164 | * @return HOUSE_ARREST_E_SUCCESS if the command was successfully sent, | ||
| 165 | * HOUSE_ARREST_E_INVALID_ARG if client, command, or appid is invalid, | ||
| 166 | * HOUSE_ARREST_E_INVALID_MODE if the client is not in the correct mode, | ||
| 167 | * or HOUSE_ARREST_E_CONN_FAILED if a connection error occured. | ||
| 168 | */ | ||
| 169 | house_arrest_error_t house_arrest_send_command(house_arrest_client_t client, const char *command, const char *appid) | ||
| 170 | { | ||
| 171 | if (!client || !client->parent || !command || !appid) | ||
| 172 | return HOUSE_ARREST_E_INVALID_ARG; | ||
| 173 | if (client->mode != HOUSE_ARREST_CLIENT_MODE_NORMAL) | ||
| 174 | return HOUSE_ARREST_E_INVALID_MODE; | ||
| 175 | |||
| 176 | house_arrest_error_t res = HOUSE_ARREST_E_UNKNOWN_ERROR; | ||
| 177 | |||
| 178 | plist_t dict = plist_new_dict(); | ||
| 179 | plist_dict_insert_item(dict, "Command", plist_new_string(command)); | ||
| 180 | plist_dict_insert_item(dict, "Identifier", plist_new_string(appid)); | ||
| 181 | |||
| 182 | res = house_arrest_send_request(client, dict); | ||
| 183 | |||
| 184 | plist_free(dict); | ||
| 185 | |||
| 186 | return res; | ||
| 187 | } | ||
| 188 | |||
| 189 | /** | ||
| 190 | * Retrieves the result of a previously sent house_arrest_request_* request. | ||
| 191 | * | ||
| 192 | * @param client The house_arrest client to use | ||
| 193 | * @param dict Pointer that will be set to a plist containing the result to | ||
| 194 | * the last performed operation. It holds a key 'Status' with the value | ||
| 195 | * 'Complete' on success or a key 'Error' with an error description as | ||
| 196 | * value. The caller is responsible for freeing the returned plist. | ||
| 197 | * | ||
| 198 | * @return HOUSE_ARREST_E_SUCCESS if a result plist was retrieved, | ||
| 199 | * HOUSE_ARREST_E_INVALID_ARG if client is invalid, | ||
| 200 | * HOUSE_ARREST_E_INVALID_MODE if the client is not in the correct mode, | ||
| 201 | * or HOUSE_ARREST_E_CONN_FAILED if a connection error occured. | ||
| 202 | */ | ||
| 203 | house_arrest_error_t house_arrest_get_result(house_arrest_client_t client, plist_t *dict) | ||
| 204 | { | ||
| 205 | if (!client || !client->parent) | ||
| 206 | return HOUSE_ARREST_E_INVALID_ARG; | ||
| 207 | if (client->mode != HOUSE_ARREST_CLIENT_MODE_NORMAL) | ||
| 208 | return HOUSE_ARREST_E_INVALID_MODE; | ||
| 209 | |||
| 210 | house_arrest_error_t res = house_arrest_error(property_list_service_receive_plist(client->parent, dict)); | ||
| 211 | if (res != HOUSE_ARREST_E_SUCCESS) { | ||
| 212 | debug_info("could not get result, error %d", res); | ||
| 213 | if (*dict) { | ||
| 214 | plist_free(*dict); | ||
| 215 | *dict = NULL; | ||
| 216 | } | ||
| 217 | } | ||
| 218 | return res; | ||
| 219 | } | ||
| 220 | |||
| 221 | /** | ||
| 222 | * Creates an AFC client using the given house_arrest client's connection | ||
| 223 | * allowing file access to a specific application directory requested by | ||
| 224 | * functions like house_arrest_request_vendor_documents(). | ||
| 225 | * | ||
| 226 | * @param client The house_arrest client to use. | ||
| 227 | * @param afc_client Pointer that will be set to a newly allocated afc_client_t | ||
| 228 | * upon successful return. | ||
| 229 | * | ||
| 230 | * @note After calling this function the house_arrest client will go in an | ||
| 231 | * AFC mode that will only allow calling house_arrest_client_free(). | ||
| 232 | * Only call house_arrest_client_free() if all AFC operations have | ||
| 233 | * completed since it will close the connection. | ||
| 234 | * | ||
| 235 | * @return AFC_E_SUCCESS if the afc client was successfully created, | ||
| 236 | * AFC_E_INVALID_ARG if client is invalid or was already used to create | ||
| 237 | * an afc client, or an AFC_E_* error code returned by | ||
| 238 | * afc_client_new_from_connection(). | ||
| 239 | */ | ||
| 240 | afc_error_t afc_client_new_from_house_arrest_client(house_arrest_client_t client, afc_client_t *afc_client) | ||
| 241 | { | ||
| 242 | if (!client || !client->parent || (client->mode == HOUSE_ARREST_CLIENT_MODE_AFC)) { | ||
| 243 | return AFC_E_INVALID_ARG; | ||
| 244 | } | ||
| 245 | afc_error_t err = afc_client_new_from_connection(client->parent->connection, afc_client); | ||
| 246 | if (err == AFC_E_SUCCESS) { | ||
| 247 | client->mode = HOUSE_ARREST_CLIENT_MODE_AFC; | ||
| 248 | } | ||
| 249 | return err; | ||
| 250 | } | ||
diff --git a/src/house_arrest.h b/src/house_arrest.h new file mode 100644 index 0000000..6d13a88 --- /dev/null +++ b/src/house_arrest.h | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | /* | ||
| 2 | * house_arrest.h | ||
| 3 | * com.apple.mobile.house_arrest service header file. | ||
| 4 | * | ||
| 5 | * Copyright (c) 2010 Nikias Bassen, All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | #ifndef IHOUSE_ARREST_H | ||
| 22 | #define IHOUSE_ARREST_H | ||
| 23 | |||
| 24 | #include <glib.h> | ||
| 25 | |||
| 26 | #include "libimobiledevice/house_arrest.h" | ||
| 27 | #include "property_list_service.h" | ||
| 28 | |||
| 29 | enum house_arrest_client_mode { | ||
| 30 | HOUSE_ARREST_CLIENT_MODE_NORMAL = 0, | ||
| 31 | HOUSE_ARREST_CLIENT_MODE_AFC, | ||
| 32 | }; | ||
| 33 | |||
| 34 | struct house_arrest_client_private { | ||
| 35 | property_list_service_client_t parent; | ||
| 36 | enum house_arrest_client_mode mode; | ||
| 37 | }; | ||
| 38 | |||
| 39 | #endif | ||
