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