diff options
Diffstat (limited to 'cython/mobile_image_mounter.pxi')
| -rw-r--r-- | cython/mobile_image_mounter.pxi | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/cython/mobile_image_mounter.pxi b/cython/mobile_image_mounter.pxi new file mode 100644 index 0000000..d9d40d5 --- /dev/null +++ b/cython/mobile_image_mounter.pxi | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | cdef 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 | |||
| 13 | mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, lockdownd_service_descriptor_t descriptor, mobile_image_mounter_client_t *client) | ||
| 14 | 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_with_options(mobile_image_mounter_client_t client, char *image_path, const unsigned char *signature, unsigned int signature_length, char *image_type, plist.plist_t options, plist.plist_t *result) | ||
| 17 | mobile_image_mounter_error_t mobile_image_mounter_mount_image(mobile_image_mounter_client_t client, char *image_path, const unsigned char *signature, unsigned int signature_length, char *image_type, plist.plist_t *result) | ||
| 18 | mobile_image_mounter_error_t mobile_image_mounter_unmount_image(mobile_image_mounter_client_t client, const char *mount_path); | ||
| 19 | mobile_image_mounter_error_t mobile_image_mounter_hangup(mobile_image_mounter_client_t client) | ||
| 20 | |||
| 21 | cdef class MobileImageMounterError(BaseError): | ||
| 22 | def __init__(self, *args, **kwargs): | ||
| 23 | self._lookup_table = { | ||
| 24 | MOBILE_IMAGE_MOUNTER_E_SUCCESS: "Success", | ||
| 25 | MOBILE_IMAGE_MOUNTER_E_INVALID_ARG: "Invalid argument", | ||
| 26 | MOBILE_IMAGE_MOUNTER_E_PLIST_ERROR: "Property list error", | ||
| 27 | MOBILE_IMAGE_MOUNTER_E_CONN_FAILED: "Connection failed", | ||
| 28 | MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR: "Unknown error" | ||
| 29 | } | ||
| 30 | BaseError.__init__(self, *args, **kwargs) | ||
| 31 | |||
| 32 | cdef class MobileImageMounterClient(PropertyListService): | ||
| 33 | __service_name__ = "com.apple.mobile.mobile_image_mounter" | ||
| 34 | cdef mobile_image_mounter_client_t _c_client | ||
| 35 | |||
| 36 | def __cinit__(self, iDevice device not None, LockdownServiceDescriptor descriptor, *args, **kwargs): | ||
| 37 | self.handle_error(mobile_image_mounter_new(device._c_dev, descriptor._c_service_descriptor, &self._c_client)) | ||
| 38 | |||
| 39 | def __dealloc__(self): | ||
| 40 | cdef mobile_image_mounter_error_t err | ||
| 41 | if self._c_client is not NULL: | ||
| 42 | err = mobile_image_mounter_free(self._c_client) | ||
| 43 | self.handle_error(err) | ||
| 44 | |||
| 45 | cdef inline BaseError _error(self, int16_t ret): | ||
| 46 | return MobileImageMounterError(ret) | ||
| 47 | |||
| 48 | cpdef plist.Node lookup_image(self, bytes image_type): | ||
| 49 | cdef: | ||
| 50 | plist.plist_t c_node = NULL | ||
| 51 | mobile_image_mounter_error_t err | ||
| 52 | err = mobile_image_mounter_lookup_image(self._c_client, image_type, &c_node) | ||
| 53 | |||
| 54 | try: | ||
| 55 | self.handle_error(err) | ||
| 56 | |||
| 57 | return plist.plist_t_to_node(c_node) | ||
| 58 | except Exception, e: | ||
| 59 | if c_node != NULL: | ||
| 60 | plist.plist_free(c_node) | ||
| 61 | |||
| 62 | cpdef plist.Node mount_image_with_options(self, bytes image_path, bytes signature, bytes image_type, object options): | ||
| 63 | cdef: | ||
| 64 | plist.Node n_options | ||
| 65 | plist.plist_t c_options | ||
| 66 | plist.plist_t c_result = NULL | ||
| 67 | bint free_options = False | ||
| 68 | plist.plist_t c_node = NULL | ||
| 69 | mobile_image_mounter_error_t err | ||
| 70 | if isinstance(options, plist.Dict): | ||
| 71 | n_options = options | ||
| 72 | c_options = n_options._c_node | ||
| 73 | elif isinstance(options, dict): | ||
| 74 | c_options = plist.native_to_plist_t(options) | ||
| 75 | free_options = True | ||
| 76 | else: | ||
| 77 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) | ||
| 78 | err = mobile_image_mounter_mount_image_with_options(self._c_client, image_path, signature, len(signature), | ||
| 79 | image_type, c_options, &c_node) | ||
| 80 | if free_options: | ||
| 81 | plist.plist_free(c_options) | ||
| 82 | try: | ||
| 83 | self.handle_error(err) | ||
| 84 | |||
| 85 | return plist.plist_t_to_node(c_node) | ||
| 86 | except Exception, e: | ||
| 87 | if c_node != NULL: | ||
| 88 | plist.plist_free(c_node) | ||
| 89 | |||
| 90 | cpdef plist.Node mount_image(self, bytes image_path, bytes signature, bytes image_type): | ||
| 91 | cdef: | ||
| 92 | plist.plist_t c_node = NULL | ||
| 93 | mobile_image_mounter_error_t err | ||
| 94 | err = mobile_image_mounter_mount_image(self._c_client, image_path, signature, len(signature), | ||
| 95 | image_type, &c_node) | ||
| 96 | |||
| 97 | try: | ||
| 98 | self.handle_error(err) | ||
| 99 | |||
| 100 | return plist.plist_t_to_node(c_node) | ||
| 101 | except Exception, e: | ||
| 102 | if c_node != NULL: | ||
| 103 | plist.plist_free(c_node) | ||
| 104 | |||
| 105 | cpdef unmount_image(self, bytes mount_path): | ||
| 106 | cdef: | ||
| 107 | mobile_image_mounter_error_t err | ||
| 108 | err = mobile_image_mounter_unmount_image(self._c_client, mount_path) | ||
| 109 | |||
| 110 | self.handle_error(err) | ||
| 111 | |||
| 112 | cpdef hangup(self): | ||
| 113 | cdef mobile_image_mounter_error_t err | ||
| 114 | err = mobile_image_mounter_hangup(self._c_client) | ||
| 115 | self.handle_error(err) | ||
