diff options
Diffstat (limited to 'cython/mobilebackup.pxi')
| -rw-r--r-- | cython/mobilebackup.pxi | 65 |
1 files changed, 60 insertions, 5 deletions
diff --git a/cython/mobilebackup.pxi b/cython/mobilebackup.pxi index 4f07683..5a6fea6 100644 --- a/cython/mobilebackup.pxi +++ b/cython/mobilebackup.pxi | |||
| @@ -9,12 +9,25 @@ cdef extern from "libimobiledevice/mobilebackup.h": | |||
| 9 | MOBILEBACKUP_E_PLIST_ERROR = -2 | 9 | MOBILEBACKUP_E_PLIST_ERROR = -2 |
| 10 | MOBILEBACKUP_E_MUX_ERROR = -3 | 10 | MOBILEBACKUP_E_MUX_ERROR = -3 |
| 11 | MOBILEBACKUP_E_BAD_VERSION = -4 | 11 | MOBILEBACKUP_E_BAD_VERSION = -4 |
| 12 | MOBILEBACKUP_E_REPLY_NOT_OK = -5 | ||
| 12 | MOBILEBACKUP_E_UNKNOWN_ERROR = -256 | 13 | MOBILEBACKUP_E_UNKNOWN_ERROR = -256 |
| 13 | 14 | ||
| 14 | mobilebackup_error_t mobilebackup_client_new(idevice_t device, uint16_t port, mobilebackup_client_t * client) | 15 | ctypedef enum mobilebackup_flags_t: |
| 16 | MB_RESTORE_NOTIFY_SPRINGBOARD = (1 << 0) | ||
| 17 | MB_RESTORE_PRESERVE_SETTINGS = (1 << 1) | ||
| 18 | MB_RESTORE_PRESERVE_CAMERA_ROLL = (1 << 2) | ||
| 19 | |||
| 20 | mobilebackup_error_t mobilebackup_client_new(idevice_t device, lockdownd_service_descriptor_t descriptor, mobilebackup_client_t * client) | ||
| 15 | mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client) | 21 | mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client) |
| 16 | mobilebackup_error_t mobilebackup_receive(mobilebackup_client_t client, plist.plist_t *plist) | 22 | mobilebackup_error_t mobilebackup_receive(mobilebackup_client_t client, plist.plist_t *plist) |
| 17 | mobilebackup_error_t mobilebackup_send(mobilebackup_client_t client, plist.plist_t plist) | 23 | mobilebackup_error_t mobilebackup_send(mobilebackup_client_t client, plist.plist_t plist) |
| 24 | mobilebackup_error_t mobilebackup_request_backup(mobilebackup_client_t client, plist.plist_t backup_manifest, char *base_path, char *proto_version) | ||
| 25 | mobilebackup_error_t mobilebackup_send_backup_file_received(mobilebackup_client_t client) | ||
| 26 | mobilebackup_error_t mobilebackup_request_restore(mobilebackup_client_t client, plist.plist_t backup_manifest, mobilebackup_flags_t flags, char *proto_version) | ||
| 27 | mobilebackup_error_t mobilebackup_receive_restore_file_received(mobilebackup_client_t client, plist.plist_t *result) | ||
| 28 | mobilebackup_error_t mobilebackup_receive_restore_application_received(mobilebackup_client_t client, plist.plist_t *result) | ||
| 29 | mobilebackup_error_t mobilebackup_send_restore_complete(mobilebackup_client_t client) | ||
| 30 | mobilebackup_error_t mobilebackup_send_error(mobilebackup_client_t client, char *reason) | ||
| 18 | 31 | ||
| 19 | cdef class MobileBackupError(BaseError): | 32 | cdef class MobileBackupError(BaseError): |
| 20 | def __init__(self, *args, **kwargs): | 33 | def __init__(self, *args, **kwargs): |
| @@ -24,6 +37,7 @@ cdef class MobileBackupError(BaseError): | |||
| 24 | MOBILEBACKUP_E_PLIST_ERROR: "Property list error", | 37 | MOBILEBACKUP_E_PLIST_ERROR: "Property list error", |
| 25 | MOBILEBACKUP_E_MUX_ERROR: "MUX error", | 38 | MOBILEBACKUP_E_MUX_ERROR: "MUX error", |
| 26 | MOBILEBACKUP_E_BAD_VERSION: "Bad version", | 39 | MOBILEBACKUP_E_BAD_VERSION: "Bad version", |
| 40 | MOBILEBACKUP_E_REPLY_NOT_OK: "Reply not OK", | ||
| 27 | MOBILEBACKUP_E_UNKNOWN_ERROR: "Unknown error" | 41 | MOBILEBACKUP_E_UNKNOWN_ERROR: "Unknown error" |
| 28 | } | 42 | } |
| 29 | BaseError.__init__(self, *args, **kwargs) | 43 | BaseError.__init__(self, *args, **kwargs) |
| @@ -32,8 +46,8 @@ cdef class MobileBackupClient(PropertyListService): | |||
| 32 | __service_name__ = "com.apple.mobilebackup" | 46 | __service_name__ = "com.apple.mobilebackup" |
| 33 | cdef mobilebackup_client_t _c_client | 47 | cdef mobilebackup_client_t _c_client |
| 34 | 48 | ||
| 35 | def __cinit__(self, iDevice device not None, int port, *args, **kwargs): | 49 | def __cinit__(self, iDevice device not None, LockdownServiceDescriptor descriptor, *args, **kwargs): |
| 36 | self.handle_error(mobilebackup_client_new(device._c_dev, port, &self._c_client)) | 50 | self.handle_error(mobilebackup_client_new(device._c_dev, descriptor._c_service_descriptor, &self._c_client)) |
| 37 | 51 | ||
| 38 | def __dealloc__(self): | 52 | def __dealloc__(self): |
| 39 | cdef mobilebackup_error_t err | 53 | cdef mobilebackup_error_t err |
| @@ -41,11 +55,52 @@ cdef class MobileBackupClient(PropertyListService): | |||
| 41 | err = mobilebackup_client_free(self._c_client) | 55 | err = mobilebackup_client_free(self._c_client) |
| 42 | self.handle_error(err) | 56 | self.handle_error(err) |
| 43 | 57 | ||
| 58 | cdef inline BaseError _error(self, int16_t ret): | ||
| 59 | return MobileBackupError(ret) | ||
| 60 | |||
| 44 | cdef inline int16_t _send(self, plist.plist_t node): | 61 | cdef inline int16_t _send(self, plist.plist_t node): |
| 45 | return mobilebackup_send(self._c_client, node) | 62 | return mobilebackup_send(self._c_client, node) |
| 46 | 63 | ||
| 47 | cdef inline int16_t _receive(self, plist.plist_t* node): | 64 | cdef inline int16_t _receive(self, plist.plist_t* node): |
| 48 | return mobilebackup_receive(self._c_client, node) | 65 | return mobilebackup_receive(self._c_client, node) |
| 49 | 66 | ||
| 50 | cdef inline BaseError _error(self, int16_t ret): | 67 | cdef request_backup(self, plist.Node backup_manifest, bytes base_path, bytes proto_version): |
| 51 | return MobileBackupError(ret) | 68 | self.handle_error(mobilebackup_request_backup(self._c_client, backup_manifest._c_node, base_path, proto_version)) |
| 69 | |||
| 70 | cdef send_backup_file_received(self): | ||
| 71 | self.handle_error(mobilebackup_send_backup_file_received(self._c_client)) | ||
| 72 | |||
| 73 | cdef request_restore(self, plist.Node backup_manifest, int flags, proto_version): | ||
| 74 | self.handle_error(mobilebackup_request_restore(self._c_client, backup_manifest._c_node, <mobilebackup_flags_t>flags, proto_version)) | ||
| 75 | |||
| 76 | cpdef plist.Node receive_restore_file_received(self): | ||
| 77 | cdef: | ||
| 78 | plist.plist_t c_node = NULL | ||
| 79 | mobilebackup_error_t err | ||
| 80 | err = mobilebackup_receive_restore_file_received(self._c_client, &c_node) | ||
| 81 | try: | ||
| 82 | self.handle_error(err) | ||
| 83 | return plist.plist_t_to_node(c_node) | ||
| 84 | except BaseError, e: | ||
| 85 | if c_node != NULL: | ||
| 86 | plist.plist_free(c_node) | ||
| 87 | raise | ||
| 88 | |||
| 89 | cpdef plist.Node receive_restore_application_received(self): | ||
| 90 | cdef: | ||
| 91 | plist.plist_t c_node = NULL | ||
| 92 | mobilebackup_error_t err | ||
| 93 | err = mobilebackup_receive_restore_application_received(self._c_client, &c_node) | ||
| 94 | try: | ||
| 95 | self.handle_error(err) | ||
| 96 | return plist.plist_t_to_node(c_node) | ||
| 97 | except BaseError, e: | ||
| 98 | if c_node != NULL: | ||
| 99 | plist.plist_free(c_node) | ||
| 100 | raise | ||
| 101 | |||
| 102 | cdef send_restore_complete(self): | ||
| 103 | self.handle_error(mobilebackup_send_restore_complete(self._c_client)) | ||
| 104 | |||
| 105 | cdef send_error(self, bytes reason): | ||
| 106 | self.handle_error(mobilebackup_send_error(self._c_client, reason)) | ||
