From c19978863878a014b5aa2538989b41b864708866 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Wed, 27 Feb 2013 15:14:01 +0100 Subject: cython: Add all service protocols which brings Python bindings to 100% coverage --- cython/Makefile.am | 7 +++ cython/diagnostics_relay.pxi | 128 ++++++++++++++++++++++++++++++++++++++++ cython/heartbeat.pxi | 56 ++++++++++++++++++ cython/house_arrest.pxi | 84 +++++++++++++++++++++++++++ cython/imobiledevice.pyx | 7 +++ cython/misagent.pxi | 74 ++++++++++++++++++++++++ cython/mobilebackup2.pxi | 114 ++++++++++++++++++++++++++++++++++++ cython/restore.pxi | 135 +++++++++++++++++++++++++++++++++++++++++++ cython/webinspector.pxi | 56 ++++++++++++++++++ 9 files changed, 661 insertions(+) create mode 100644 cython/diagnostics_relay.pxi create mode 100644 cython/heartbeat.pxi create mode 100644 cython/house_arrest.pxi create mode 100644 cython/misagent.pxi create mode 100644 cython/mobilebackup2.pxi create mode 100644 cython/restore.pxi create mode 100644 cython/webinspector.pxi diff --git a/cython/Makefile.am b/cython/Makefile.am index 64c5c1c..b5090b1 100644 --- a/cython/Makefile.am +++ b/cython/Makefile.am @@ -13,10 +13,17 @@ PXIINCLUDES = \ notification_proxy.pxi \ sbservices.pxi \ mobilebackup.pxi \ + mobilebackup2.pxi \ afc.pxi \ file_relay.pxi \ screenshotr.pxi \ installation_proxy.pxi \ + webinspector.pxi \ + heartbeat.pxi \ + diagnostics_relay.pxi \ + misagent.pxi \ + house_arrest.pxi \ + restore.pxi \ mobile_image_mounter.pxi CLEANFILES = \ diff --git a/cython/diagnostics_relay.pxi b/cython/diagnostics_relay.pxi new file mode 100644 index 0000000..155e5b7 --- /dev/null +++ b/cython/diagnostics_relay.pxi @@ -0,0 +1,128 @@ +REQUEST_TYPE_ALL = "All" +REQUEST_TYPE_WIFI = "WiFi" +REQUEST_TYPE_GAS_GAUGE = "GasGauge" +REQUEST_TYPE_NAND = "NAND" + +cdef extern from "libimobiledevice/diagnostics_relay.h": + cdef struct diagnostics_relay_client_private: + pass + ctypedef diagnostics_relay_client_private *diagnostics_relay_client_t + + ctypedef enum diagnostics_relay_error_t: + DIAGNOSTICS_RELAY_E_SUCCESS = 0 + DIAGNOSTICS_RELAY_E_INVALID_ARG = -1 + DIAGNOSTICS_RELAY_E_PLIST_ERROR = -2 + DIAGNOSTICS_RELAY_E_MUX_ERROR = -3 + DIAGNOSTICS_RELAY_E_UNKNOWN_REQUEST = -4 + DIAGNOSTICS_RELAY_E_UNKNOWN_ERROR = -256 + cdef enum: + DIAGNOSTICS_RELAY_ACTION_FLAG_WAIT_FOR_DISCONNECT = (1 << 1) + DIAGNOSTICS_RELAY_ACTION_FLAG_DISPLAY_PASS = (1 << 2) + DIAGNOSTICS_RELAY_ACTION_FLAG_DISPLAY_FAIL = (1 << 3) + + diagnostics_relay_error_t diagnostics_relay_client_new(idevice_t device, lockdownd_service_descriptor_t descriptor, diagnostics_relay_client_t * client) + diagnostics_relay_error_t diagnostics_relay_client_free(diagnostics_relay_client_t client) + + diagnostics_relay_error_t diagnostics_relay_goodbye(diagnostics_relay_client_t client) + diagnostics_relay_error_t diagnostics_relay_sleep(diagnostics_relay_client_t client) + diagnostics_relay_error_t diagnostics_relay_restart(diagnostics_relay_client_t client, int flags) + diagnostics_relay_error_t diagnostics_relay_shutdown(diagnostics_relay_client_t client, int flags) + diagnostics_relay_error_t diagnostics_relay_request_diagnostics(diagnostics_relay_client_t client, char* type, plist.plist_t* diagnostics) + diagnostics_relay_error_t diagnostics_relay_query_mobilegestalt(diagnostics_relay_client_t client, plist.plist_t keys, plist.plist_t* result) + diagnostics_relay_error_t diagnostics_relay_query_ioregistry_entry(diagnostics_relay_client_t client, char* name, char* class_name, plist.plist_t* result) + diagnostics_relay_error_t diagnostics_relay_query_ioregistry_plane(diagnostics_relay_client_t client, char* plane, plist.plist_t* result) + +cdef class DiagnosticsRelayError(BaseError): + def __init__(self, *args, **kwargs): + self._lookup_table = { + DIAGNOSTICS_RELAY_E_SUCCESS: "Success", + DIAGNOSTICS_RELAY_E_INVALID_ARG: "Invalid argument", + DIAGNOSTICS_RELAY_E_PLIST_ERROR: "Property list error", + DIAGNOSTICS_RELAY_E_MUX_ERROR: "MUX error", + DIAGNOSTICS_RELAY_E_UNKNOWN_REQUEST: "Unknown request", + DIAGNOSTICS_RELAY_E_UNKNOWN_ERROR: "Unknown error" + } + BaseError.__init__(self, *args, **kwargs) + +cdef class DiagnosticsRelayClient(PropertyListService): + __service_name__ = "com.apple.mobile.diagnostics_relay" + cdef diagnostics_relay_client_t _c_client + + def __cinit__(self, iDevice device not None, LockdownServiceDescriptor descriptor, *args, **kwargs): + self.handle_error(diagnostics_relay_client_new(device._c_dev, descriptor._c_service_descriptor, &self._c_client)) + + def __dealloc__(self): + cdef diagnostics_relay_error_t err + if self._c_client is not NULL: + err = diagnostics_relay_client_free(self._c_client) + self.handle_error(err) + + cdef inline BaseError _error(self, int16_t ret): + return DiagnosticsRelayError(ret) + + cpdef goodbye(self): + self.handle_error(diagnostics_relay_goodbye(self._c_client)) + + cpdef sleep(self): + self.handle_error(diagnostics_relay_sleep(self._c_client)) + + cpdef restart(self, int flags): + self.handle_error(diagnostics_relay_restart(self._c_client, flags)) + + cpdef shutdown(self, int flags): + self.handle_error(diagnostics_relay_shutdown(self._c_client, flags)) + + cpdef plist.Node request_diagnostics(self, bytes type): + cdef: + plist.plist_t c_node = NULL + diagnostics_relay_error_t err + err = diagnostics_relay_request_diagnostics(self._c_client, type, &c_node) + try: + self.handle_error(err) + return plist.plist_t_to_node(c_node) + except BaseError, e: + if c_node != NULL: + plist.plist_free(c_node) + raise + + cpdef plist.Node query_mobilegestalt(self, plist.Node keys = None): + cdef: + plist.plist_t c_node = NULL + diagnostics_relay_error_t err + plist.plist_t keys_c_node = NULL + if keys is not None: + keys_c_node = keys._c_node + err = diagnostics_relay_query_mobilegestalt(self._c_client, keys_c_node, &c_node) + try: + self.handle_error(err) + return plist.plist_t_to_node(c_node) + except BaseError, e: + if c_node != NULL: + plist.plist_free(c_node) + raise + + cpdef plist.Node query_ioregistry_entry(self, bytes name, bytes class_name): + cdef: + plist.plist_t c_node = NULL + diagnostics_relay_error_t err + err = diagnostics_relay_query_ioregistry_entry(self._c_client, name, class_name, &c_node) + try: + self.handle_error(err) + return plist.plist_t_to_node(c_node) + except BaseError, e: + if c_node != NULL: + plist.plist_free(c_node) + raise + + cpdef plist.Node query_ioregistry_plane(self, bytes plane = None): + cdef: + plist.plist_t c_node = NULL + diagnostics_relay_error_t err + err = diagnostics_relay_query_ioregistry_plane(self._c_client, plane, &c_node) + try: + self.handle_error(err) + return plist.plist_t_to_node(c_node) + except BaseError, e: + if c_node != NULL: + plist.plist_free(c_node) + raise diff --git a/cython/heartbeat.pxi b/cython/heartbeat.pxi new file mode 100644 index 0000000..b48fb59 --- /dev/null +++ b/cython/heartbeat.pxi @@ -0,0 +1,56 @@ +cdef extern from "libimobiledevice/heartbeat.h": + cdef struct heartbeat_client_private: + pass + ctypedef heartbeat_client_private *heartbeat_client_t + + ctypedef enum heartbeat_error_t: + HEARTBEAT_E_SUCCESS = 0 + HEARTBEAT_E_INVALID_ARG = -1 + HEARTBEAT_E_PLIST_ERROR = -2 + HEARTBEAT_E_MUX_ERROR = -3 + HEARTBEAT_E_SSL_ERROR = -4 + HEARTBEAT_E_UNKNOWN_ERROR = -256 + + heartbeat_error_t heartbeat_client_new(idevice_t device, lockdownd_service_descriptor_t descriptor, heartbeat_client_t * client) + heartbeat_error_t heartbeat_client_free(heartbeat_client_t client) + + heartbeat_error_t heartbeat_send(heartbeat_client_t client, plist.plist_t plist) + heartbeat_error_t heartbeat_receive(heartbeat_client_t client, plist.plist_t * plist) + heartbeat_error_t heartbeat_receive_with_timeout(heartbeat_client_t client, plist.plist_t * plist, uint32_t timeout_ms) + +cdef class HeartbeatError(BaseError): + def __init__(self, *args, **kwargs): + self._lookup_table = { + HEARTBEAT_E_SUCCESS: "Success", + HEARTBEAT_E_INVALID_ARG: "Invalid argument", + HEARTBEAT_E_PLIST_ERROR: "Property list error", + HEARTBEAT_E_MUX_ERROR: "MUX error", + HEARTBEAT_E_SSL_ERROR: "SSL Error", + HEARTBEAT_E_UNKNOWN_ERROR: "Unknown error" + } + BaseError.__init__(self, *args, **kwargs) + +cdef class HeartbeatClient(PropertyListService): + __service_name__ = "com.apple.heartbeat" + cdef heartbeat_client_t _c_client + + def __cinit__(self, iDevice device not None, LockdownServiceDescriptor descriptor, *args, **kwargs): + self.handle_error(heartbeat_client_new(device._c_dev, descriptor._c_service_descriptor, &self._c_client)) + + def __dealloc__(self): + cdef heartbeat_error_t err + if self._c_client is not NULL: + err = heartbeat_client_free(self._c_client) + self.handle_error(err) + + cdef inline int16_t _send(self, plist.plist_t node): + return heartbeat_send(self._c_client, node) + + cdef inline int16_t _receive(self, plist.plist_t* node): + return heartbeat_receive(self._c_client, node) + + cdef inline int16_t _receive_with_timeout(self, plist.plist_t* node, int timeout_ms): + return heartbeat_receive_with_timeout(self._c_client, node, timeout_ms) + + cdef inline BaseError _error(self, int16_t ret): + return HeartbeatError(ret) diff --git a/cython/house_arrest.pxi b/cython/house_arrest.pxi new file mode 100644 index 0000000..2a81213 --- /dev/null +++ b/cython/house_arrest.pxi @@ -0,0 +1,84 @@ +cdef extern from "libimobiledevice/house_arrest.h": + cdef struct house_arrest_client_private: + pass + ctypedef house_arrest_client_private *house_arrest_client_t + + ctypedef enum house_arrest_error_t: + HOUSE_ARREST_E_SUCCESS = 0 + HOUSE_ARREST_E_INVALID_ARG = -1 + HOUSE_ARREST_E_PLIST_ERROR = -2 + HOUSE_ARREST_E_CONN_FAILED = -3 + HOUSE_ARREST_E_INVALID_MODE = -4 + HOUSE_ARREST_E_UNKNOWN_ERROR = -256 + + house_arrest_error_t house_arrest_client_new(idevice_t device, lockdownd_service_descriptor_t descriptor, house_arrest_client_t * client) + house_arrest_error_t house_arrest_client_free(house_arrest_client_t client) + + house_arrest_error_t house_arrest_send_request(house_arrest_client_t client, plist.plist_t dict) + house_arrest_error_t house_arrest_send_command(house_arrest_client_t client, char *command, char *appid) + house_arrest_error_t house_arrest_get_result(house_arrest_client_t client, plist.plist_t *dict) + + afc_error_t afc_client_new_from_house_arrest_client(house_arrest_client_t client, afc_client_t *afc_client) + +cdef class HouseArrestError(BaseError): + def __init__(self, *args, **kwargs): + self._lookup_table = { + HOUSE_ARREST_E_SUCCESS: "Success", + HOUSE_ARREST_E_INVALID_ARG: "Invalid argument", + HOUSE_ARREST_E_PLIST_ERROR: "Property list error", + HOUSE_ARREST_E_CONN_FAILED: "Connection failed", + HOUSE_ARREST_E_INVALID_MODE: "Invalid mode", + HOUSE_ARREST_E_UNKNOWN_ERROR: "Unknown error" + } + BaseError.__init__(self, *args, **kwargs) + +cdef class HouseArrestClient(PropertyListService): + __service_name__ = "com.apple.mobile.house_arrest" + cdef house_arrest_client_t _c_client + + def __cinit__(self, iDevice device not None, LockdownServiceDescriptor descriptor, *args, **kwargs): + self.handle_error(house_arrest_client_new(device._c_dev, descriptor._c_service_descriptor, &self._c_client)) + + def __dealloc__(self): + cdef house_arrest_error_t err + if self._c_client is not NULL: + err = house_arrest_client_free(self._c_client) + self.handle_error(err) + + cdef inline BaseError _error(self, int16_t ret): + return HouseArrestError(ret) + + cdef send_request(self, plist.Node message): + self.handle_error(house_arrest_send_request(self._c_client, message._c_node)) + + cdef send_command(self, bytes command, bytes appid): + self.handle_error(house_arrest_send_command(self._c_client, command, appid)) + + cpdef plist.Node get_result(self): + cdef: + plist.plist_t c_node = NULL + house_arrest_error_t err + err = house_arrest_get_result(self._c_client, &c_node) + try: + self.handle_error(err) + return plist.plist_t_to_node(c_node) + except BaseError, e: + if c_node != NULL: + plist.plist_free(c_node) + raise + + cpdef AfcClient to_afc_client(self): + cdef: + afc_client_t c_afc_client = NULL + AfcClient result + afc_error_t err + err = afc_client_new_from_house_arrest_client(self._c_client, &c_afc_client) + try: + result = AfcClient.__new__(AfcClient) + result._c_client = c_afc_client + result.handle_error(err) + return result + except BaseError, e: + if c_afc_client != NULL: + afc_client_free(c_afc_client); + raise diff --git a/cython/imobiledevice.pyx b/cython/imobiledevice.pyx index de59456..fa5e7ae 100644 --- a/cython/imobiledevice.pyx +++ b/cython/imobiledevice.pyx @@ -241,8 +241,15 @@ include "mobilesync.pxi" include "notification_proxy.pxi" include "sbservices.pxi" include "mobilebackup.pxi" +include "mobilebackup2.pxi" include "afc.pxi" include "file_relay.pxi" include "screenshotr.pxi" include "installation_proxy.pxi" include "mobile_image_mounter.pxi" +include "webinspector.pxi" +include "heartbeat.pxi" +include "diagnostics_relay.pxi" +include "misagent.pxi" +include "house_arrest.pxi" +include "restore.pxi" diff --git a/cython/misagent.pxi b/cython/misagent.pxi new file mode 100644 index 0000000..1fee4b9 --- /dev/null +++ b/cython/misagent.pxi @@ -0,0 +1,74 @@ +cdef extern from "libimobiledevice/misagent.h": + cdef struct misagent_client_private: + pass + ctypedef misagent_client_private *misagent_client_t + + ctypedef enum misagent_error_t: + MISAGENT_E_SUCCESS = 0 + MISAGENT_E_INVALID_ARG = -1 + MISAGENT_E_PLIST_ERROR = -2 + MISAGENT_E_CONN_FAILED = -3 + MISAGENT_E_REQUEST_FAILED = -4 + MISAGENT_E_UNKNOWN_ERROR = -256 + + misagent_error_t misagent_client_new(idevice_t device, lockdownd_service_descriptor_t descriptor, misagent_client_t * client) + misagent_error_t misagent_client_free(misagent_client_t client) + + misagent_error_t misagent_install(misagent_client_t client, plist.plist_t profile) + misagent_error_t misagent_copy(misagent_client_t client, plist.plist_t* profiles) + misagent_error_t misagent_remove(misagent_client_t client, char* profileID) + int misagent_get_status_code(misagent_client_t client) + +cdef class MisagentError(BaseError): + def __init__(self, *args, **kwargs): + self._lookup_table = { + MISAGENT_E_SUCCESS: "Success", + MISAGENT_E_INVALID_ARG: "Invalid argument", + MISAGENT_E_PLIST_ERROR: "Property list error", + MISAGENT_E_CONN_FAILED: "Connection failed", + MISAGENT_E_REQUEST_FAILED: "Request failed", + MISAGENT_E_UNKNOWN_ERROR: "Unknown error" + } + BaseError.__init__(self, *args, **kwargs) + +cdef class MisagentClient(PropertyListService): + __service_name__ = "com.apple.misagent" + cdef misagent_client_t _c_client + + def __cinit__(self, iDevice device not None, LockdownServiceDescriptor descriptor, *args, **kwargs): + self.handle_error(misagent_client_new(device._c_dev, descriptor._c_service_descriptor, &self._c_client)) + + def __dealloc__(self): + cdef misagent_error_t err + if self._c_client is not NULL: + err = misagent_client_free(self._c_client) + self.handle_error(err) + + cdef inline BaseError _error(self, int16_t ret): + return MisagentError(ret) + + cpdef install(self, plist.Node profile): + cdef misagent_error_t err + err = misagent_install(self._c_client, profile._c_node) + self.handle_error(err) + + cpdef plist.Node copy(self): + cdef: + plist.plist_t c_node = NULL + misagent_error_t err + err = misagent_copy(self._c_client, &c_node) + try: + self.handle_error(err) + return plist.plist_t_to_node(c_node) + except BaseError, e: + if c_node != NULL: + plist.plist_free(c_node) + raise + + cpdef remove(self, bytes profile_id): + cdef misagent_error_t err + err = misagent_remove(self._c_client, profile_id) + self.handle_error(err) + + cpdef int get_status_code(self): + return misagent_get_status_code(self._c_client) 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 @@ +cdef extern from "libimobiledevice/mobilebackup2.h": + cdef struct mobilebackup2_client_private: + pass + ctypedef mobilebackup2_client_private *mobilebackup2_client_t + + ctypedef enum mobilebackup2_error_t: + MOBILEBACKUP2_E_SUCCESS = 0 + MOBILEBACKUP2_E_INVALID_ARG = -1 + MOBILEBACKUP2_E_PLIST_ERROR = -2 + MOBILEBACKUP2_E_MUX_ERROR = -3 + MOBILEBACKUP2_E_BAD_VERSION = -4 + MOBILEBACKUP2_E_REPLY_NOT_OK = -5 + MOBILEBACKUP2_E_NO_COMMON_VERSION = -6 + MOBILEBACKUP2_E_UNKNOWN_ERROR = -256 + + mobilebackup2_error_t mobilebackup2_client_new(idevice_t device, lockdownd_service_descriptor_t descriptor, mobilebackup2_client_t * client) + mobilebackup2_error_t mobilebackup2_client_free(mobilebackup2_client_t client) + + mobilebackup2_error_t mobilebackup2_send_message(mobilebackup2_client_t client, char *message, plist.plist_t options) + mobilebackup2_error_t mobilebackup2_receive_message(mobilebackup2_client_t client, plist.plist_t *msg_plist, char **dlmessage) + mobilebackup2_error_t mobilebackup2_send_raw(mobilebackup2_client_t client, char *data, uint32_t length, uint32_t *bytes) + mobilebackup2_error_t mobilebackup2_receive_raw(mobilebackup2_client_t client, char *data, uint32_t length, uint32_t *bytes) + mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t client, double local_versions[], char count, double *remote_version) + mobilebackup2_error_t mobilebackup2_send_request(mobilebackup2_client_t client, char *request, char *target_identifier, char *source_identifier, plist.plist_t options) + mobilebackup2_error_t mobilebackup2_send_status_response(mobilebackup2_client_t client, int status_code, char *status1, plist.plist_t status2) + +cdef class MobileBackup2Error(BaseError): + def __init__(self, *args, **kwargs): + self._lookup_table = { + MOBILEBACKUP2_E_SUCCESS: "Success", + MOBILEBACKUP2_E_INVALID_ARG: "Invalid argument", + MOBILEBACKUP2_E_PLIST_ERROR: "Property list error", + MOBILEBACKUP2_E_MUX_ERROR: "MUX error", + MOBILEBACKUP2_E_BAD_VERSION: "Bad version", + MOBILEBACKUP2_E_REPLY_NOT_OK: "Reply not OK", + MOBILEBACKUP2_E_NO_COMMON_VERSION: "No common version", + MOBILEBACKUP2_E_UNKNOWN_ERROR: "Unknown error" + } + BaseError.__init__(self, *args, **kwargs) + +cdef class MobileBackup2Client(PropertyListService): + __service_name__ = "com.apple.mobilebackup2" + cdef mobilebackup2_client_t _c_client + + def __cinit__(self, iDevice device not None, LockdownServiceDescriptor descriptor, *args, **kwargs): + self.handle_error(mobilebackup2_client_new(device._c_dev, descriptor._c_service_descriptor, &self._c_client)) + + def __dealloc__(self): + cdef mobilebackup2_error_t err + if self._c_client is not NULL: + err = mobilebackup2_client_free(self._c_client) + self.handle_error(err) + + cdef inline BaseError _error(self, int16_t ret): + return MobileBackup2Error(ret) + + cdef send_message(self, bytes message, plist.Node options): + self.handle_error(mobilebackup2_send_message(self._c_client, message, options._c_node)) + + cdef tuple receive_message(self): + cdef: + char* dlmessage = NULL + plist.plist_t c_node = NULL + mobilebackup2_error_t err + err = mobilebackup2_receive_message(self._c_client, &c_node, &dlmessage) + try: + self.handle_error(err) + return (plist.plist_t_to_node(c_node), dlmessage) + except BaseError, e: + if c_node != NULL: + plist.plist_free(c_node) + if dlmessage != NULL: + free(dlmessage) + raise + + cdef int send_raw(self, bytes data, int length): + cdef: + uint32_t bytes = 0 + mobilebackup2_error_t err + err = mobilebackup2_send_raw(self._c_client, data, length, &bytes) + try: + self.handle_error(err) + return bytes + except BaseError, e: + raise + + cdef int receive_raw(self, bytes data, int length): + cdef: + uint32_t bytes = 0 + mobilebackup2_error_t err + err = mobilebackup2_receive_raw(self._c_client, data, length, &bytes) + try: + self.handle_error(err) + return bytes + except BaseError, e: + raise + + cdef float version_exchange(self, double[::1] local_versions): + cdef: + double[::1] temp = None + double remote_version = 0.0 + mobilebackup2_error_t err + err = mobilebackup2_version_exchange(self._c_client, &local_versions[0], len(local_versions), &remote_version) + try: + self.handle_error(err) + return remote_version + except BaseError, e: + raise + + cdef send_request(self, bytes request, bytes target_identifier, bytes source_identifier, plist.Node options): + self.handle_error(mobilebackup2_send_request(self._c_client, request, target_identifier, source_identifier, options._c_node)) + + cdef send_status_response(self, int status_code, bytes status1, plist.Node status2): + self.handle_error(mobilebackup2_send_status_response(self._c_client, status_code, status1, status2._c_node)) diff --git a/cython/restore.pxi b/cython/restore.pxi new file mode 100644 index 0000000..7d3d80e --- /dev/null +++ b/cython/restore.pxi @@ -0,0 +1,135 @@ +cdef extern from "libimobiledevice/restore.h": + cdef struct restored_client_private: + pass + ctypedef restored_client_private *restored_client_t + + ctypedef enum restored_error_t: + RESTORE_E_SUCCESS = 0 + RESTORE_E_INVALID_ARG = -1 + RESTORE_E_INVALID_CONF = -2 + RESTORE_E_PLIST_ERROR = -3 + RESTORE_E_DICT_ERROR = -4 + RESTORE_E_NOT_ENOUGH_DATA = -5 + RESTORE_E_MUX_ERROR = -6 + RESTORE_E_START_RESTORE_FAILED = -7 + RESTORE_E_UNKNOWN_ERROR = -256 + + restored_error_t restored_client_new(idevice_t device, restored_client_t *client, char *label) + restored_error_t restored_client_free(restored_client_t client) + + restored_error_t restored_query_type(restored_client_t client, char **tp, uint64_t *version) + restored_error_t restored_query_value(restored_client_t client, char *key, plist.plist_t *value) + restored_error_t restored_get_value(restored_client_t client, char *key, plist.plist_t *value) + restored_error_t restored_send(restored_client_t client, plist.plist_t plist) + restored_error_t restored_receive(restored_client_t client, plist.plist_t *plist) + restored_error_t restored_goodbye(restored_client_t client) + + restored_error_t restored_start_restore(restored_client_t client, plist.plist_t options, uint64_t version) + restored_error_t restored_reboot(restored_client_t client) + + void restored_client_set_label(restored_client_t client, char *label) + +cdef class RestoreError(BaseError): + def __init__(self, *args, **kwargs): + self._lookup_table = { + RESTORE_E_SUCCESS: "Success", + RESTORE_E_INVALID_ARG: "Invalid argument", + RESTORE_E_INVALID_CONF: "Invalid configuration", + RESTORE_E_PLIST_ERROR: "Property list error", + RESTORE_E_DICT_ERROR: "Dict error", + RESTORE_E_NOT_ENOUGH_DATA: "Not enough data", + RESTORE_E_MUX_ERROR: "MUX Error", + RESTORE_E_START_RESTORE_FAILED: "Starting restore failed", + RESTORE_E_UNKNOWN_ERROR: "Unknown error" + } + BaseError.__init__(self, *args, **kwargs) + +cdef class RestoreClient(PropertyListService): + cdef restored_client_t _c_client + + def __cinit__(self, iDevice device not None, bytes label=b'', *args, **kwargs): + cdef: + restored_error_t err + char* c_label = NULL + if label: + c_label = label + err = restored_client_new(device._c_dev, &self._c_client, c_label) + self.handle_error(err) + + self.device = device + + def __dealloc__(self): + cdef restored_error_t err + if self._c_client is not NULL: + err = restored_client_free(self._c_client) + self.handle_error(err) + + cdef inline BaseError _error(self, int16_t ret): + return RestoreError(ret) + + cdef inline int16_t _send(self, plist.plist_t node): + return restored_send(self._c_client, node) + + cdef inline int16_t _receive(self, plist.plist_t* node): + return restored_receive(self._c_client, node) + + cpdef tuple query_type(self): + cdef: + restored_error_t err + char* c_type = NULL + uint64_t c_version = 0 + tuple result + err = restored_query_type(self._c_client, &c_type, &c_version) + try: + self.handle_error(err) + result = (c_type, c_version) + return result + except BaseError, e: + raise + finally: + if c_type != NULL: + free(c_type) + + cpdef plist.Node query_value(self, bytes key=None): + cdef: + restored_error_t err + plist.plist_t c_node = NULL + char* c_key = NULL + if key is not None: + c_key = key + err = restored_query_value(self._c_client, c_key, &c_node) + try: + self.handle_error(err) + return plist.plist_t_to_node(c_node) + except BaseError, e: + if c_node != NULL: + plist.plist_free(c_node) + raise + + cpdef plist.Node get_value(self, bytes key=None): + cdef: + restored_error_t err + plist.plist_t c_node = NULL + char* c_key = NULL + if key is not None: + c_key = key + err = restored_get_value(self._c_client, c_key, &c_node) + try: + self.handle_error(err) + return plist.plist_t_to_node(c_node) + except BaseError, e: + if c_node != NULL: + plist.plist_free(c_node) + raise + + cpdef goodbye(self): + self.handle_error(restored_goodbye(self._c_client)) + + cpdef start_restore(self, plist.Node options, uint64_t version): + self.handle_error(restored_start_restore(self._c_client, options._c_node, version)) + + cpdef reboot(self): + self.handle_error(restored_reboot(self._c_client)) + + cpdef set_label(self, bytes label): + restored_client_set_label(self._c_client, label) 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 @@ +cdef extern from "libimobiledevice/webinspector.h": + cdef struct webinspector_client_private: + pass + ctypedef webinspector_client_private *webinspector_client_t + + ctypedef enum webinspector_error_t: + WEBINSPECTOR_E_SUCCESS = 0 + WEBINSPECTOR_E_INVALID_ARG = -1 + WEBINSPECTOR_E_PLIST_ERROR = -2 + WEBINSPECTOR_E_MUX_ERROR = -3 + WEBINSPECTOR_E_SSL_ERROR = -4 + WEBINSPECTOR_E_UNKNOWN_ERROR = -256 + + webinspector_error_t webinspector_client_new(idevice_t device, lockdownd_service_descriptor_t descriptor, webinspector_client_t * client) + webinspector_error_t webinspector_client_free(webinspector_client_t client) + + webinspector_error_t webinspector_send(webinspector_client_t client, plist.plist_t plist) + webinspector_error_t webinspector_receive(webinspector_client_t client, plist.plist_t * plist) + webinspector_error_t webinspector_receive_with_timeout(webinspector_client_t client, plist.plist_t * plist, uint32_t timeout_ms) + +cdef class WebinspectorError(BaseError): + def __init__(self, *args, **kwargs): + self._lookup_table = { + WEBINSPECTOR_E_SUCCESS: "Success", + WEBINSPECTOR_E_INVALID_ARG: "Invalid argument", + WEBINSPECTOR_E_PLIST_ERROR: "Property list error", + WEBINSPECTOR_E_MUX_ERROR: "MUX error", + WEBINSPECTOR_E_SSL_ERROR: "SSL Error", + WEBINSPECTOR_E_UNKNOWN_ERROR: "Unknown error" + } + BaseError.__init__(self, *args, **kwargs) + +cdef class WebinspectorClient(PropertyListService): + __service_name__ = "com.apple.webinspector" + cdef webinspector_client_t _c_client + + def __cinit__(self, iDevice device not None, LockdownServiceDescriptor descriptor, *args, **kwargs): + self.handle_error(webinspector_client_new(device._c_dev, descriptor._c_service_descriptor, &self._c_client)) + + def __dealloc__(self): + cdef webinspector_error_t err + if self._c_client is not NULL: + err = webinspector_client_free(self._c_client) + self.handle_error(err) + + cdef inline int16_t _send(self, plist.plist_t node): + return webinspector_send(self._c_client, node) + + cdef inline int16_t _receive(self, plist.plist_t* node): + return webinspector_receive(self._c_client, node) + + cdef inline int16_t _receive_with_timeout(self, plist.plist_t* node, int timeout_ms): + return webinspector_receive_with_timeout(self._c_client, node, timeout_ms) + + cdef inline BaseError _error(self, int16_t ret): + return WebinspectorError(ret) -- cgit v1.1-32-gdbae