summaryrefslogtreecommitdiffstats
path: root/cython/mobilebackup2.pxi
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2013-02-27 15:14:01 +0100
committerGravatar Martin Szulecki2013-02-27 15:14:01 +0100
commitc19978863878a014b5aa2538989b41b864708866 (patch)
tree73d40d6cbda5250972239c96b418edeb6fbbbf52 /cython/mobilebackup2.pxi
parent0cac547eb79492e04176ad541fe6fb1d1f576824 (diff)
downloadlibimobiledevice-c19978863878a014b5aa2538989b41b864708866.tar.gz
libimobiledevice-c19978863878a014b5aa2538989b41b864708866.tar.bz2
cython: Add all service protocols which brings Python bindings to 100% coverage
Diffstat (limited to 'cython/mobilebackup2.pxi')
-rw-r--r--cython/mobilebackup2.pxi114
1 files changed, 114 insertions, 0 deletions
diff --git a/cython/mobilebackup2.pxi b/cython/mobilebackup2.pxi
new file mode 100644
index 0000000..aac5358
--- /dev/null
+++ b/cython/mobilebackup2.pxi
@@ -0,0 +1,114 @@
1cdef extern from "libimobiledevice/mobilebackup2.h":
2 cdef struct mobilebackup2_client_private:
3 pass
4 ctypedef mobilebackup2_client_private *mobilebackup2_client_t
5
6 ctypedef enum mobilebackup2_error_t:
7 MOBILEBACKUP2_E_SUCCESS = 0
8 MOBILEBACKUP2_E_INVALID_ARG = -1
9 MOBILEBACKUP2_E_PLIST_ERROR = -2
10 MOBILEBACKUP2_E_MUX_ERROR = -3
11 MOBILEBACKUP2_E_BAD_VERSION = -4
12 MOBILEBACKUP2_E_REPLY_NOT_OK = -5
13 MOBILEBACKUP2_E_NO_COMMON_VERSION = -6
14 MOBILEBACKUP2_E_UNKNOWN_ERROR = -256
15
16 mobilebackup2_error_t mobilebackup2_client_new(idevice_t device, lockdownd_service_descriptor_t descriptor, mobilebackup2_client_t * client)
17 mobilebackup2_error_t mobilebackup2_client_free(mobilebackup2_client_t client)
18
19 mobilebackup2_error_t mobilebackup2_send_message(mobilebackup2_client_t client, char *message, plist.plist_t options)
20 mobilebackup2_error_t mobilebackup2_receive_message(mobilebackup2_client_t client, plist.plist_t *msg_plist, char **dlmessage)
21 mobilebackup2_error_t mobilebackup2_send_raw(mobilebackup2_client_t client, char *data, uint32_t length, uint32_t *bytes)
22 mobilebackup2_error_t mobilebackup2_receive_raw(mobilebackup2_client_t client, char *data, uint32_t length, uint32_t *bytes)
23 mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t client, double local_versions[], char count, double *remote_version)
24 mobilebackup2_error_t mobilebackup2_send_request(mobilebackup2_client_t client, char *request, char *target_identifier, char *source_identifier, plist.plist_t options)
25 mobilebackup2_error_t mobilebackup2_send_status_response(mobilebackup2_client_t client, int status_code, char *status1, plist.plist_t status2)
26
27cdef class MobileBackup2Error(BaseError):
28 def __init__(self, *args, **kwargs):
29 self._lookup_table = {
30 MOBILEBACKUP2_E_SUCCESS: "Success",
31 MOBILEBACKUP2_E_INVALID_ARG: "Invalid argument",
32 MOBILEBACKUP2_E_PLIST_ERROR: "Property list error",
33 MOBILEBACKUP2_E_MUX_ERROR: "MUX error",
34 MOBILEBACKUP2_E_BAD_VERSION: "Bad version",
35 MOBILEBACKUP2_E_REPLY_NOT_OK: "Reply not OK",
36 MOBILEBACKUP2_E_NO_COMMON_VERSION: "No common version",
37 MOBILEBACKUP2_E_UNKNOWN_ERROR: "Unknown error"
38 }
39 BaseError.__init__(self, *args, **kwargs)
40
41cdef class MobileBackup2Client(PropertyListService):
42 __service_name__ = "com.apple.mobilebackup2"
43 cdef mobilebackup2_client_t _c_client
44
45 def __cinit__(self, iDevice device not None, LockdownServiceDescriptor descriptor, *args, **kwargs):
46 self.handle_error(mobilebackup2_client_new(device._c_dev, descriptor._c_service_descriptor, &self._c_client))
47
48 def __dealloc__(self):
49 cdef mobilebackup2_error_t err
50 if self._c_client is not NULL:
51 err = mobilebackup2_client_free(self._c_client)
52 self.handle_error(err)
53
54 cdef inline BaseError _error(self, int16_t ret):
55 return MobileBackup2Error(ret)
56
57 cdef send_message(self, bytes message, plist.Node options):
58 self.handle_error(mobilebackup2_send_message(self._c_client, message, options._c_node))
59
60 cdef tuple receive_message(self):
61 cdef:
62 char* dlmessage = NULL
63 plist.plist_t c_node = NULL
64 mobilebackup2_error_t err
65 err = mobilebackup2_receive_message(self._c_client, &c_node, &dlmessage)
66 try:
67 self.handle_error(err)
68 return (plist.plist_t_to_node(c_node), <bytes>dlmessage)
69 except BaseError, e:
70 if c_node != NULL:
71 plist.plist_free(c_node)
72 if dlmessage != NULL:
73 free(dlmessage)
74 raise
75
76 cdef int send_raw(self, bytes data, int length):
77 cdef:
78 uint32_t bytes = 0
79 mobilebackup2_error_t err
80 err = mobilebackup2_send_raw(self._c_client, data, length, &bytes)
81 try:
82 self.handle_error(err)
83 return <bint>bytes
84 except BaseError, e:
85 raise
86
87 cdef int receive_raw(self, bytes data, int length):
88 cdef:
89 uint32_t bytes = 0
90 mobilebackup2_error_t err
91 err = mobilebackup2_receive_raw(self._c_client, data, length, &bytes)
92 try:
93 self.handle_error(err)
94 return <bint>bytes
95 except BaseError, e:
96 raise
97
98 cdef float version_exchange(self, double[::1] local_versions):
99 cdef:
100 double[::1] temp = None
101 double remote_version = 0.0
102 mobilebackup2_error_t err
103 err = mobilebackup2_version_exchange(self._c_client, &local_versions[0], len(local_versions), &remote_version)
104 try:
105 self.handle_error(err)
106 return <float>remote_version
107 except BaseError, e:
108 raise
109
110 cdef send_request(self, bytes request, bytes target_identifier, bytes source_identifier, plist.Node options):
111 self.handle_error(mobilebackup2_send_request(self._c_client, request, target_identifier, source_identifier, options._c_node))
112
113 cdef send_status_response(self, int status_code, bytes status1, plist.Node status2):
114 self.handle_error(mobilebackup2_send_status_response(self._c_client, status_code, status1, status2._c_node))