blob: a23a59be9705d3175efbf73955955b675c0a3906 [file] [log] [blame]
Bryan Forbes23954a22010-03-31 14:19:38 -05001cdef extern from "libimobiledevice/mobile_image_mounter.h":
2 cdef struct mobile_image_mounter_client_private:
3 pass
4 ctypedef mobile_image_mounter_client_private *mobile_image_mounter_client_t
5
6 ctypedef enum mobile_image_mounter_error_t:
7 MOBILE_IMAGE_MOUNTER_E_SUCCESS = 0
8 MOBILE_IMAGE_MOUNTER_E_INVALID_ARG = -1
9 MOBILE_IMAGE_MOUNTER_E_PLIST_ERROR = -2
10 MOBILE_IMAGE_MOUNTER_E_CONN_FAILED = -3
11 MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR = -256
12
Martin Szulecki0cac5472013-02-27 15:10:57 +010013 mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, lockdownd_service_descriptor_t descriptor, mobile_image_mounter_client_t *client)
Bryan Forbes23954a22010-03-31 14:19:38 -050014 mobile_image_mounter_error_t mobile_image_mounter_free(mobile_image_mounter_client_t client)
15 mobile_image_mounter_error_t mobile_image_mounter_lookup_image(mobile_image_mounter_client_t client, char *image_type, plist.plist_t *result)
16 mobile_image_mounter_error_t mobile_image_mounter_mount_image(mobile_image_mounter_client_t client, char *image_path, char *image_signature, uint16_t signature_length, char *image_type, plist.plist_t *result)
17 mobile_image_mounter_error_t mobile_image_mounter_hangup(mobile_image_mounter_client_t client)
18
19cdef class MobileImageMounterError(BaseError):
20 def __init__(self, *args, **kwargs):
21 self._lookup_table = {
22 MOBILE_IMAGE_MOUNTER_E_SUCCESS: "Success",
23 MOBILE_IMAGE_MOUNTER_E_INVALID_ARG: "Invalid argument",
24 MOBILE_IMAGE_MOUNTER_E_PLIST_ERROR: "Property list error",
25 MOBILE_IMAGE_MOUNTER_E_CONN_FAILED: "Connection failed",
26 MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR: "Unknown error"
27 }
28 BaseError.__init__(self, *args, **kwargs)
29
Bryan Forbesbea5efe2010-04-09 16:52:30 -050030cdef class MobileImageMounterClient(PropertyListService):
31 __service_name__ = "com.apple.mobile.mobile_image_mounter"
Bryan Forbes23954a22010-03-31 14:19:38 -050032 cdef mobile_image_mounter_client_t _c_client
33
Martin Szulecki0cac5472013-02-27 15:10:57 +010034 def __cinit__(self, iDevice device not None, LockdownServiceDescriptor descriptor, *args, **kwargs):
35 self.handle_error(mobile_image_mounter_new(device._c_dev, descriptor._c_service_descriptor, &self._c_client))
Bryan Forbes23954a22010-03-31 14:19:38 -050036
37 def __dealloc__(self):
38 cdef mobile_image_mounter_error_t err
39 if self._c_client is not NULL:
40 err = mobile_image_mounter_free(self._c_client)
41 self.handle_error(err)
42
43 cdef inline BaseError _error(self, int16_t ret):
44 return MobileImageMounterError(ret)
45
46 cpdef plist.Node lookup_image(self, bytes image_type):
47 cdef:
48 plist.plist_t c_node = NULL
49 mobile_image_mounter_error_t err
50 err = mobile_image_mounter_lookup_image(self._c_client, image_type, &c_node)
Bryan Forbes38777112010-04-30 13:35:57 -050051
52 try:
53 self.handle_error(err)
54
55 return plist.plist_t_to_node(c_node)
56 except Exception, e:
57 if c_node != NULL:
58 plist.plist_free(c_node)
Bryan Forbes23954a22010-03-31 14:19:38 -050059
60 cpdef plist.Node mount_image(self, bytes image_path, bytes image_signature, bytes image_type):
61 cdef:
62 plist.plist_t c_node = NULL
63 mobile_image_mounter_error_t err
64 err = mobile_image_mounter_mount_image(self._c_client, image_path, image_signature, len(image_signature),
65 image_type, &c_node)
Bryan Forbes38777112010-04-30 13:35:57 -050066
67 try:
68 self.handle_error(err)
69
70 return plist.plist_t_to_node(c_node)
71 except Exception, e:
72 if c_node != NULL:
73 plist.plist_free(c_node)
Bryan Forbes23954a22010-03-31 14:19:38 -050074
75 cpdef hangup(self):
76 cdef mobile_image_mounter_error_t err
77 err = mobile_image_mounter_hangup(self._c_client)
78 self.handle_error(err)