diff options
Diffstat (limited to 'cython/file_relay.pxi')
| -rw-r--r-- | cython/file_relay.pxi | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/cython/file_relay.pxi b/cython/file_relay.pxi new file mode 100644 index 0000000..05c99f5 --- /dev/null +++ b/cython/file_relay.pxi | |||
| @@ -0,0 +1,75 @@ | |||
| 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_UNKNOWN_ERROR = -256 | ||
| 15 | |||
| 16 | file_relay_error_t file_relay_client_new(idevice_t device, uint16_t port, file_relay_client_t *client) | ||
| 17 | file_relay_error_t file_relay_client_free(file_relay_client_t client) | ||
| 18 | |||
| 19 | file_relay_error_t file_relay_request_sources(file_relay_client_t client, const_sources_t sources, idevice_connection_t *connection) | ||
| 20 | |||
| 21 | cdef class FileRelayError(BaseError): | ||
| 22 | def __init__(self, *args, **kwargs): | ||
| 23 | self._lookup_table = { | ||
| 24 | FILE_RELAY_E_SUCCESS: "Success", | ||
| 25 | FILE_RELAY_E_INVALID_ARG: "Invalid argument", | ||
| 26 | FILE_RELAY_E_PLIST_ERROR: "Property list error", | ||
| 27 | FILE_RELAY_E_MUX_ERROR: "MUX error", | ||
| 28 | FILE_RELAY_E_INVALID_SOURCE: "Invalid source", | ||
| 29 | FILE_RELAY_E_STAGING_EMPTY: "Staging empty", | ||
| 30 | FILE_RELAY_E_UNKNOWN_ERROR: "Unknown error" | ||
| 31 | } | ||
| 32 | BaseError.__init__(self, *args, **kwargs) | ||
| 33 | |||
| 34 | cimport stdlib | ||
| 35 | |||
| 36 | cdef class FileRelayClient(Base): | ||
| 37 | cdef file_relay_client_t _c_client | ||
| 38 | |||
| 39 | def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): | ||
| 40 | cdef: | ||
| 41 | iDevice dev = device | ||
| 42 | LockdownClient lckd | ||
| 43 | file_relay_error_t err | ||
| 44 | if lockdown is None: | ||
| 45 | lckd = LockdownClient(dev) | ||
| 46 | else: | ||
| 47 | lckd = lockdown | ||
| 48 | port = lckd.start_service("com.apple.mobile.file_relay") | ||
| 49 | err = file_relay_client_new(dev._c_dev, port, &self._c_client) | ||
| 50 | self.handle_error(err) | ||
| 51 | |||
| 52 | def __dealloc__(self): | ||
| 53 | cdef file_relay_error_t err | ||
| 54 | if self._c_client is not NULL: | ||
| 55 | err = file_relay_client_free(self._c_client) | ||
| 56 | self.handle_error(err) | ||
| 57 | |||
| 58 | cpdef iDeviceConnection request_sources(self, list sources): | ||
| 59 | cdef: | ||
| 60 | file_relay_error_t err | ||
| 61 | Py_ssize_t count = len(sources) | ||
| 62 | char** c_sources = <char**>stdlib.malloc(sizeof(char*) * (count + 1)) | ||
| 63 | iDeviceConnection conn = iDeviceConnection.__new__(iDeviceConnection) | ||
| 64 | |||
| 65 | for i, value in enumerate(sources): | ||
| 66 | c_sources[i] = value | ||
| 67 | c_sources[count] = NULL | ||
| 68 | |||
| 69 | err = file_relay_request_sources(self._c_client, <const_sources_t>c_sources, &conn._c_connection) | ||
| 70 | free(c_sources) | ||
| 71 | self.handle_error(err) | ||
| 72 | return conn | ||
| 73 | |||
| 74 | cdef inline BaseError _error(self, int16_t ret): | ||
| 75 | return FileRelayError(ret) | ||
