summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mobile_image_mounter.c77
1 files changed, 41 insertions, 36 deletions
diff --git a/src/mobile_image_mounter.c b/src/mobile_image_mounter.c
index c8c4c6f..bbebbb4 100644
--- a/src/mobile_image_mounter.c
+++ b/src/mobile_image_mounter.c
@@ -2,7 +2,7 @@
2 * mobile_image_mounter.c 2 * mobile_image_mounter.c
3 * com.apple.mobile.mobile_image_mounter service implementation. 3 * com.apple.mobile.mobile_image_mounter service implementation.
4 * 4 *
5 * Copyright (c) 2010 Nikias Bassen, All Rights Reserved. 5 * Copyright (c) 2010-2019 Nikias Bassen, All Rights Reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public 8 * modify it under the terms of the GNU Lesser General Public
@@ -141,6 +141,43 @@ leave_unlock:
141 return res; 141 return res;
142} 142}
143 143
144static mobile_image_mounter_error_t process_result(plist_t result, const char *expected_status)
145{
146 mobile_image_mounter_error_t res = MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED;
147 char* strval = NULL;
148 plist_t node;
149
150 node = plist_dict_get_item(result, "Error");
151 if (node && plist_get_node_type(node) == PLIST_STRING) {
152 plist_get_string_val(node, &strval);
153 }
154 if (strval) {
155 if (!strcmp(strval, "DeviceLocked")) {
156 debug_info("Device is locked, can't mount");
157 res = MOBILE_IMAGE_MOUNTER_E_DEVICE_LOCKED;
158 } else {
159 debug_info("Unhandled error '%s' received", strval);
160 }
161 free(strval);
162 return res;
163 }
164
165 node = plist_dict_get_item(result, "Status");
166 if (node && plist_get_node_type(node) == PLIST_STRING) {
167 plist_get_string_val(node, &strval);
168 }
169 if (!strval) {
170 debug_info("Error: Unexpected response received!");
171 } else if (strcmp(strval, expected_status) == 0) {
172 res = MOBILE_IMAGE_MOUNTER_E_SUCCESS;
173 } else {
174 debug_info("Error: didn't get %s but %s", expected_status, strval);
175 }
176 free(strval);
177
178 return res;
179}
180
144LIBIMOBILEDEVICE_API mobile_image_mounter_error_t mobile_image_mounter_upload_image(mobile_image_mounter_client_t client, const char *image_type, size_t image_size, const char *signature, uint16_t signature_size, mobile_image_mounter_upload_cb_t upload_cb, void* userdata) 181LIBIMOBILEDEVICE_API mobile_image_mounter_error_t mobile_image_mounter_upload_image(mobile_image_mounter_client_t client, const char *image_type, size_t image_size, const char *signature, uint16_t signature_size, mobile_image_mounter_upload_cb_t upload_cb, void* userdata)
145{ 182{
146 if (!client || !image_type || (image_size == 0) || !upload_cb) { 183 if (!client || !image_type || (image_size == 0) || !upload_cb) {
@@ -169,23 +206,10 @@ LIBIMOBILEDEVICE_API mobile_image_mounter_error_t mobile_image_mounter_upload_im
169 debug_info("Error receiving response from device!"); 206 debug_info("Error receiving response from device!");
170 goto leave_unlock; 207 goto leave_unlock;
171 } 208 }
172 res = MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED; 209 res = process_result(result, "ReceiveBytesAck");
173 210 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
174 char* strval = NULL;
175 plist_t node = plist_dict_get_item(result, "Status");
176 if (node && plist_get_node_type(node) == PLIST_STRING) {
177 plist_get_string_val(node, &strval);
178 }
179 if (!strval) {
180 debug_info("Error: Unexpected response received!");
181 goto leave_unlock;
182 }
183 if (strcmp(strval, "ReceiveBytesAck") != 0) {
184 debug_info("Error: didn't get ReceiveBytesAck but %s", strval);
185 free(strval);
186 goto leave_unlock; 211 goto leave_unlock;
187 } 212 }
188 free(strval);
189 213
190 size_t tx = 0; 214 size_t tx = 0;
191 size_t bufsize = 65536; 215 size_t bufsize = 65536;
@@ -223,26 +247,7 @@ LIBIMOBILEDEVICE_API mobile_image_mounter_error_t mobile_image_mounter_upload_im
223 debug_info("Error receiving response from device!"); 247 debug_info("Error receiving response from device!");
224 goto leave_unlock; 248 goto leave_unlock;
225 } 249 }
226 res = MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED; 250 res = process_result(result, "Complete");
227
228 strval = NULL;
229 node = plist_dict_get_item(result, "Status");
230 if (node && plist_get_node_type(node) == PLIST_STRING) {
231 plist_get_string_val(node, &strval);
232 }
233 if (!strval) {
234 debug_info("Error: Unexpected response received!");
235 goto leave_unlock;
236 }
237 if (strcmp(strval, "Complete") != 0) {
238 debug_info("Error: didn't get Complete but %s", strval);
239 free(strval);
240 goto leave_unlock;
241 } else {
242 res = MOBILE_IMAGE_MOUNTER_E_SUCCESS;
243 }
244 free(strval);
245
246 251
247leave_unlock: 252leave_unlock:
248 mobile_image_mounter_unlock(client); 253 mobile_image_mounter_unlock(client);