diff options
Diffstat (limited to 'cython/webinspector.pxi')
| -rw-r--r-- | cython/webinspector.pxi | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/cython/webinspector.pxi b/cython/webinspector.pxi new file mode 100644 index 0000000..4622ef5 --- /dev/null +++ b/cython/webinspector.pxi | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | cdef extern from "libimobiledevice/webinspector.h": | ||
| 2 | cdef struct webinspector_client_private: | ||
| 3 | pass | ||
| 4 | ctypedef webinspector_client_private *webinspector_client_t | ||
| 5 | |||
| 6 | ctypedef enum webinspector_error_t: | ||
| 7 | WEBINSPECTOR_E_SUCCESS = 0 | ||
| 8 | WEBINSPECTOR_E_INVALID_ARG = -1 | ||
| 9 | WEBINSPECTOR_E_PLIST_ERROR = -2 | ||
| 10 | WEBINSPECTOR_E_MUX_ERROR = -3 | ||
| 11 | WEBINSPECTOR_E_SSL_ERROR = -4 | ||
| 12 | WEBINSPECTOR_E_UNKNOWN_ERROR = -256 | ||
| 13 | |||
| 14 | webinspector_error_t webinspector_client_new(idevice_t device, lockdownd_service_descriptor_t descriptor, webinspector_client_t * client) | ||
| 15 | webinspector_error_t webinspector_client_free(webinspector_client_t client) | ||
| 16 | |||
| 17 | webinspector_error_t webinspector_send(webinspector_client_t client, plist.plist_t plist) | ||
| 18 | webinspector_error_t webinspector_receive(webinspector_client_t client, plist.plist_t * plist) | ||
| 19 | webinspector_error_t webinspector_receive_with_timeout(webinspector_client_t client, plist.plist_t * plist, uint32_t timeout_ms) | ||
| 20 | |||
| 21 | cdef class WebinspectorError(BaseError): | ||
| 22 | def __init__(self, *args, **kwargs): | ||
| 23 | self._lookup_table = { | ||
| 24 | WEBINSPECTOR_E_SUCCESS: "Success", | ||
| 25 | WEBINSPECTOR_E_INVALID_ARG: "Invalid argument", | ||
| 26 | WEBINSPECTOR_E_PLIST_ERROR: "Property list error", | ||
| 27 | WEBINSPECTOR_E_MUX_ERROR: "MUX error", | ||
| 28 | WEBINSPECTOR_E_SSL_ERROR: "SSL Error", | ||
| 29 | WEBINSPECTOR_E_UNKNOWN_ERROR: "Unknown error" | ||
| 30 | } | ||
| 31 | BaseError.__init__(self, *args, **kwargs) | ||
| 32 | |||
| 33 | cdef class WebinspectorClient(PropertyListService): | ||
| 34 | __service_name__ = "com.apple.webinspector" | ||
| 35 | cdef webinspector_client_t _c_client | ||
| 36 | |||
| 37 | def __cinit__(self, iDevice device not None, LockdownServiceDescriptor descriptor, *args, **kwargs): | ||
| 38 | self.handle_error(webinspector_client_new(device._c_dev, descriptor._c_service_descriptor, &self._c_client)) | ||
| 39 | |||
| 40 | def __dealloc__(self): | ||
| 41 | cdef webinspector_error_t err | ||
| 42 | if self._c_client is not NULL: | ||
| 43 | err = webinspector_client_free(self._c_client) | ||
| 44 | self.handle_error(err) | ||
| 45 | |||
| 46 | cdef inline int16_t _send(self, plist.plist_t node): | ||
| 47 | return webinspector_send(self._c_client, node) | ||
| 48 | |||
| 49 | cdef inline int16_t _receive(self, plist.plist_t* node): | ||
| 50 | return webinspector_receive(self._c_client, node) | ||
| 51 | |||
| 52 | cdef inline int16_t _receive_with_timeout(self, plist.plist_t* node, int timeout_ms): | ||
| 53 | return webinspector_receive_with_timeout(self._c_client, node, timeout_ms) | ||
| 54 | |||
| 55 | cdef inline BaseError _error(self, int16_t ret): | ||
| 56 | return WebinspectorError(ret) | ||
