diff options
Diffstat (limited to 'cython/file_relay.pxi')
-rw-r--r-- | cython/file_relay.pxi | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/cython/file_relay.pxi b/cython/file_relay.pxi new file mode 100644 index 0000000..5e9cbbe --- /dev/null +++ b/cython/file_relay.pxi | |||
@@ -0,0 +1,68 @@ | |||
1 | cdef extern from "libimobiledevice/file_relay.h": | ||
2 | cdef struct file_relay_client_private: | ||
3 | pass | ||
4 | ctypedef file_relay_client_private *file_relay_client_t | ||
5 | ctypedef char** const_sources_t "const char**" | ||
6 | |||
7 | ctypedef enum file_relay_error_t: | ||
8 | FILE_RELAY_E_SUCCESS = 0 | ||
9 | FILE_RELAY_E_INVALID_ARG = -1 | ||
10 | FILE_RELAY_E_PLIST_ERROR = -2 | ||
11 | FILE_RELAY_E_MUX_ERROR = -3 | ||
12 | FILE_RELAY_E_INVALID_SOURCE = -4 | ||
13 | FILE_RELAY_E_STAGING_EMPTY = -5 | ||
14 | FILE_RELAY_E_PERMISSION_DENIED = -6 | ||
15 | FILE_RELAY_E_UNKNOWN_ERROR = -256 | ||
16 | |||
17 | file_relay_error_t file_relay_client_new(idevice_t device, lockdownd_service_descriptor_t descriptor, file_relay_client_t *client) | ||
18 | file_relay_error_t file_relay_client_free(file_relay_client_t client) | ||
19 | |||
20 | file_relay_error_t file_relay_request_sources(file_relay_client_t client, const_sources_t sources, idevice_connection_t *connection) | ||
21 | |||
22 | cdef class FileRelayError(BaseError): | ||
23 | def __init__(self, *args, **kwargs): | ||
24 | self._lookup_table = { | ||
25 | FILE_RELAY_E_SUCCESS: "Success", | ||
26 | FILE_RELAY_E_INVALID_ARG: "Invalid argument", | ||
27 | FILE_RELAY_E_PLIST_ERROR: "Property list error", | ||
28 | FILE_RELAY_E_MUX_ERROR: "MUX error", | ||
29 | FILE_RELAY_E_INVALID_SOURCE: "Invalid source", | ||
30 | FILE_RELAY_E_STAGING_EMPTY: "Staging empty", | ||
31 | FILE_RELAY_E_PERMISSION_DENIED: "Permission denied", | ||
32 | FILE_RELAY_E_UNKNOWN_ERROR: "Unknown error" | ||
33 | } | ||
34 | BaseError.__init__(self, *args, **kwargs) | ||
35 | |||
36 | from libc.stdlib cimport * | ||
37 | |||
38 | cdef class FileRelayClient(PropertyListService): | ||
39 | __service_name__ = "com.apple.mobile.file_relay" | ||
40 | cdef file_relay_client_t _c_client | ||
41 | |||
42 | def __cinit__(self, iDevice device not None, LockdownServiceDescriptor descriptor, *args, **kwargs): | ||
43 | self.handle_error(file_relay_client_new(device._c_dev, descriptor._c_service_descriptor, &self._c_client)) | ||
44 | |||
45 | def __dealloc__(self): | ||
46 | cdef file_relay_error_t err | ||
47 | if self._c_client is not NULL: | ||
48 | err = file_relay_client_free(self._c_client) | ||
49 | self.handle_error(err) | ||
50 | |||
51 | cpdef iDeviceConnection request_sources(self, list sources): | ||
52 | cdef: | ||
53 | file_relay_error_t err | ||
54 | Py_ssize_t count = len(sources) | ||
55 | char** c_sources = <char**>malloc(sizeof(char*) * (count + 1)) | ||
56 | iDeviceConnection conn = iDeviceConnection.__new__(iDeviceConnection) | ||
57 | |||
58 | for i, value in enumerate(sources): | ||
59 | c_sources[i] = value | ||
60 | c_sources[count] = NULL | ||
61 | |||
62 | err = file_relay_request_sources(self._c_client, <const_sources_t>c_sources, &conn._c_connection) | ||
63 | free(c_sources) | ||
64 | self.handle_error(err) | ||
65 | return conn | ||
66 | |||
67 | cdef inline BaseError _error(self, int16_t ret): | ||
68 | return FileRelayError(ret) | ||