Bryan Forbes | 23954a2 | 2010-03-31 14:19:38 -0500 | [diff] [blame] | 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 | |
Martin Szulecki | 0cac547 | 2013-02-27 15:10:57 +0100 | [diff] [blame] | 13 | mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, lockdownd_service_descriptor_t descriptor, mobile_image_mounter_client_t *client) |
Bryan Forbes | 23954a2 | 2010-03-31 14:19:38 -0500 | [diff] [blame] | 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(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 | |
| 19 | cdef 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 Forbes | bea5efe | 2010-04-09 16:52:30 -0500 | [diff] [blame] | 30 | cdef class MobileImageMounterClient(PropertyListService): |
| 31 | __service_name__ = "com.apple.mobile.mobile_image_mounter" |
Bryan Forbes | 23954a2 | 2010-03-31 14:19:38 -0500 | [diff] [blame] | 32 | cdef mobile_image_mounter_client_t _c_client |
| 33 | |
Martin Szulecki | 0cac547 | 2013-02-27 15:10:57 +0100 | [diff] [blame] | 34 | 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 Forbes | 23954a2 | 2010-03-31 14:19:38 -0500 | [diff] [blame] | 36 | |
| 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 Forbes | 3877711 | 2010-04-30 13:35:57 -0500 | [diff] [blame] | 51 | |
| 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 Forbes | 23954a2 | 2010-03-31 14:19:38 -0500 | [diff] [blame] | 59 | |
| 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 Forbes | 3877711 | 2010-04-30 13:35:57 -0500 | [diff] [blame] | 66 | |
| 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 Forbes | 23954a2 | 2010-03-31 14:19:38 -0500 | [diff] [blame] | 74 | |
| 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) |