diff options
| author | 2010-11-05 20:39:07 +0100 | |
|---|---|---|
| committer | 2010-11-05 20:39:07 +0100 | |
| commit | 139306caebdcc9e4383795227ca3662d484e04d5 (patch) | |
| tree | 90a0556d014fbd362b602e10ce285f85adc6fd7f /src | |
| parent | eac909b522bb405cd34a8fb48259ea3952d2360a (diff) | |
| download | libimobiledevice-139306caebdcc9e4383795227ca3662d484e04d5.tar.gz libimobiledevice-139306caebdcc9e4383795227ca3662d484e04d5.tar.bz2 | |
Add new house_arrest service including small test tool
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile.am | 1 | ||||
| -rw-r--r-- | src/house_arrest.c | 250 | ||||
| -rw-r--r-- | src/house_arrest.h | 39 |
3 files changed, 290 insertions, 0 deletions
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 | ||
