diff options
author | Bryan Forbes | 2010-03-31 14:19:38 -0500 |
---|---|---|
committer | Martin Szulecki | 2012-03-20 23:25:55 +0100 |
commit | 23954a2b28e6f763a83524a85ead4716620ee7cc (patch) | |
tree | 33a4a940c26d7b7a228400ffcf6abbc0435958ae | |
parent | 7b4cb7fb2f1b1ed29f3bc97a9bcae5fc2a89fe95 (diff) | |
download | libimobiledevice-23954a2b28e6f763a83524a85ead4716620ee7cc.tar.gz libimobiledevice-23954a2b28e6f763a83524a85ead4716620ee7cc.tar.bz2 |
Added all remaining classes from libimobiledevice.
-rw-r--r-- | cython/Makefile.am | 10 | ||||
-rw-r--r-- | cython/afc.pxi | 8 | ||||
-rw-r--r-- | cython/file_relay.pxi | 75 | ||||
-rw-r--r-- | cython/imobiledevice.pxd | 18 | ||||
-rw-r--r-- | cython/imobiledevice.pyx | 38 | ||||
-rw-r--r-- | cython/installation_proxy.pxi | 210 | ||||
-rw-r--r-- | cython/mobile_image_mounter.pxi | 75 | ||||
-rw-r--r-- | cython/mobilebackup.pxi | 10 | ||||
-rw-r--r-- | cython/mobilesync.pxi | 10 | ||||
-rw-r--r-- | cython/notification_proxy.pxi | 13 | ||||
-rw-r--r-- | cython/sbservices.pxi | 10 | ||||
-rw-r--r-- | cython/screenshotr.pxi | 65 |
12 files changed, 505 insertions, 37 deletions
diff --git a/cython/Makefile.am b/cython/Makefile.am index c0ebff6..228ec0c 100644 --- a/cython/Makefile.am +++ b/cython/Makefile.am @@ -14,7 +14,11 @@ PXIINCLUDES = \ sbservices.pxi \ mobilebackup.pxi \ property_list_client.pxi \ - afc.pxi + afc.pxi \ + file_relay.pxi \ + screenshotr.pxi \ + installation_proxy.pxi \ + mobile_image_mounter.pxi CLEANFILES = \ *.pyc \ @@ -26,8 +30,8 @@ EXTRA_DIST = imobiledevice.pyx imobiledevice.pxd $(PXIINCLUDES) imobiledevicedir = $(pyexecdir) imobiledevice_LTLIBRARIES = imobiledevice.la imobiledevice_la_SOURCES = imobiledevice.pyx -imobiledevice_la_CFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/src $(PYTHON_CPPFLAGS) -imobiledevice_la_LDFLAGS = -module -avoid-version $(PYTHON_LDFLAGS) +imobiledevice_la_CFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/src $(PYTHON_CPPFLAGS) $(libglib2_CFLAGS) $(libgthread2_CFLAGS) +imobiledevice_la_LDFLAGS = -module -avoid-version $(PYTHON_LDFLAGS) $(libglib2_LIBS) $(libgthread2_LIBS) imobiledevice_la_LIBADD = $(top_builddir)/src/libimobiledevice.la imobiledevice.c: imobiledevice.pyx $(PXDINCLUDES) $(PXIINCLUDES) diff --git a/cython/afc.pxi b/cython/afc.pxi index 51251c8..ac9c927 100644 --- a/cython/afc.pxi +++ b/cython/afc.pxi @@ -1,7 +1,7 @@ cdef extern from "libimobiledevice/afc.h": - cdef struct afc_client_int: + cdef struct afc_client_private: pass - ctypedef afc_client_int *afc_client_t + ctypedef afc_client_private *afc_client_t ctypedef enum afc_error_t: AFC_E_SUCCESS = 0 AFC_E_UNKNOWN_ERROR = 1 @@ -10,7 +10,7 @@ cdef extern from "libimobiledevice/afc.h": AFC_E_READ_ERROR = 4 AFC_E_WRITE_ERROR = 5 AFC_E_UNKNOWN_PACKET_TYPE = 6 - AFC_E_INVALID_ARGUMENT = 7 + AFC_E_INVALID_ARG = 7 AFC_E_OBJECT_NOT_FOUND = 8 AFC_E_OBJECT_IS_DIR = 9 AFC_E_PERM_DENIED = 10 @@ -79,7 +79,7 @@ cdef class AfcError(BaseError): AFC_E_READ_ERROR: "Read error", AFC_E_WRITE_ERROR: "Write error", AFC_E_UNKNOWN_PACKET_TYPE: "Unknown packet type", - AFC_E_INVALID_ARGUMENT: "Invalid argument", + AFC_E_INVALID_ARG: "Invalid argument", AFC_E_OBJECT_NOT_FOUND: "Object not found", AFC_E_OBJECT_IS_DIR: "Object is directory", AFC_E_PERM_DENIED: "Permission denied", 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 @@ +cdef extern from "libimobiledevice/file_relay.h": + cdef struct file_relay_client_private: + pass + ctypedef file_relay_client_private *file_relay_client_t + ctypedef char** const_sources_t "const char**" + + ctypedef enum file_relay_error_t: + FILE_RELAY_E_SUCCESS = 0 + FILE_RELAY_E_INVALID_ARG = -1 + FILE_RELAY_E_PLIST_ERROR = -2 + FILE_RELAY_E_MUX_ERROR = -3 + FILE_RELAY_E_INVALID_SOURCE = -4 + FILE_RELAY_E_STAGING_EMPTY = -5 + FILE_RELAY_E_UNKNOWN_ERROR = -256 + + file_relay_error_t file_relay_client_new(idevice_t device, uint16_t port, file_relay_client_t *client) + file_relay_error_t file_relay_client_free(file_relay_client_t client) + + file_relay_error_t file_relay_request_sources(file_relay_client_t client, const_sources_t sources, idevice_connection_t *connection) + +cdef class FileRelayError(BaseError): + def __init__(self, *args, **kwargs): + self._lookup_table = { + FILE_RELAY_E_SUCCESS: "Success", + FILE_RELAY_E_INVALID_ARG: "Invalid argument", + FILE_RELAY_E_PLIST_ERROR: "Property list error", + FILE_RELAY_E_MUX_ERROR: "MUX error", + FILE_RELAY_E_INVALID_SOURCE: "Invalid source", + FILE_RELAY_E_STAGING_EMPTY: "Staging empty", + FILE_RELAY_E_UNKNOWN_ERROR: "Unknown error" + } + BaseError.__init__(self, *args, **kwargs) + +cimport stdlib + +cdef class FileRelayClient(Base): + cdef file_relay_client_t _c_client + + def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): + cdef: + iDevice dev = device + LockdownClient lckd + file_relay_error_t err + if lockdown is None: + lckd = LockdownClient(dev) + else: + lckd = lockdown + port = lckd.start_service("com.apple.mobile.file_relay") + err = file_relay_client_new(dev._c_dev, port, &self._c_client) + self.handle_error(err) + + def __dealloc__(self): + cdef file_relay_error_t err + if self._c_client is not NULL: + err = file_relay_client_free(self._c_client) + self.handle_error(err) + + cpdef iDeviceConnection request_sources(self, list sources): + cdef: + file_relay_error_t err + Py_ssize_t count = len(sources) + char** c_sources = <char**>stdlib.malloc(sizeof(char*) * (count + 1)) + iDeviceConnection conn = iDeviceConnection.__new__(iDeviceConnection) + + for i, value in enumerate(sources): + c_sources[i] = value + c_sources[count] = NULL + + err = file_relay_request_sources(self._c_client, <const_sources_t>c_sources, &conn._c_connection) + free(c_sources) + self.handle_error(err) + return conn + + cdef inline BaseError _error(self, int16_t ret): + return FileRelayError(ret) diff --git a/cython/imobiledevice.pxd b/cython/imobiledevice.pxd index 8a7d6b2..8efd669 100644 --- a/cython/imobiledevice.pxd +++ b/cython/imobiledevice.pxd @@ -17,9 +17,12 @@ cdef class Base: cdef class iDeviceError(BaseError): pass cdef extern from "libimobiledevice/libimobiledevice.h": - cdef struct idevice_int: + cdef struct idevice_private: pass - ctypedef idevice_int* idevice_t + ctypedef idevice_private* idevice_t + cdef struct idevice_connection_private: + pass + ctypedef idevice_connection_private* idevice_connection_t cdef enum idevice_event_type: IDEVICE_DEVICE_ADD = 1, IDEVICE_DEVICE_REMOVE @@ -32,15 +35,22 @@ cdef extern from "libimobiledevice/libimobiledevice.h": cdef class iDeviceEvent: cdef const_idevice_event_t _c_event +cdef class iDeviceConnection(Base): + cdef idevice_connection_t _c_connection + + cpdef disconnect(self) + cdef class iDevice(Base): cdef idevice_t _c_dev + cpdef iDeviceConnection connect(self, uint16_t port) + cdef class LockdownError(BaseError): pass cdef extern from "libimobiledevice/lockdown.h": - cdef struct lockdownd_client_int: + cdef struct lockdownd_client_private: pass - ctypedef lockdownd_client_int *lockdownd_client_t + ctypedef lockdownd_client_private *lockdownd_client_t cdef class LockdownClient(Base): cdef lockdownd_client_t _c_client diff --git a/cython/imobiledevice.pyx b/cython/imobiledevice.pyx index ecf94e1..b7ec87b 100644 --- a/cython/imobiledevice.pyx +++ b/cython/imobiledevice.pyx @@ -48,6 +48,11 @@ cdef extern from "libimobiledevice/libimobiledevice.h": idevice_error_t idevice_free(idevice_t device) idevice_error_t idevice_get_uuid(idevice_t device, char** uuid) idevice_error_t idevice_get_handle(idevice_t device, uint32_t *handle) + idevice_error_t idevice_connect(idevice_t device, uint16_t port, idevice_connection_t *connection) + idevice_error_t idevice_disconnect(idevice_connection_t connection) + idevice_error_t idevice_connection_send(idevice_connection_t connection, char *data, uint32_t len, uint32_t *sent_bytes) + idevice_error_t idevice_connection_receive_timeout(idevice_connection_t connection, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout) + idevice_error_t idevice_connection_receive(idevice_connection_t connection, char *data, uint32_t len, uint32_t *recv_bytes) cdef class iDeviceError(BaseError): def __init__(self, *args, **kwargs): @@ -99,6 +104,18 @@ cpdef get_device_list(): if err: raise err return result +cdef class iDeviceConnection(Base): + def __init__(self, *args, **kwargs): + raise TypeError("iDeviceConnection cannot be instantiated. Please use iDevice.connect()") + + cpdef disconnect(self): + cdef idevice_error_t err + err = idevice_disconnect(self._c_connection) + self.handle_error(err) + + cdef inline BaseError _error(self, int16_t ret): + return iDeviceError(ret) + cdef class iDevice(Base): def __cinit__(self, uuid=None, *args, **kwargs): cdef: @@ -116,6 +133,14 @@ cdef class iDevice(Base): cdef inline BaseError _error(self, int16_t ret): return iDeviceError(ret) + cpdef iDeviceConnection connect(self, uint16_t port): + cdef: + idevice_error_t err + iDeviceConnection conn = iDeviceConnection.__new__(iDeviceConnection) + err = idevice_connect(self._c_dev, port, &conn._c_connection) + self.handle_error(err) + return conn + property uuid: def __get__(self): cdef: @@ -131,9 +156,9 @@ cdef class iDevice(Base): return handle cdef extern from "libimobiledevice/lockdown.h": - cdef struct lockdownd_client_int: + cdef struct lockdownd_client_private: pass - ctypedef lockdownd_client_int *lockdownd_client_t + ctypedef lockdownd_client_private *lockdownd_client_t ctypedef enum lockdownd_error_t: LOCKDOWN_E_SUCCESS = 0 LOCKDOWN_E_INVALID_ARG = -1 @@ -166,7 +191,7 @@ cdef class LockdownError(BaseError): LOCKDOWN_E_SUCCESS: "Success", LOCKDOWN_E_INVALID_ARG: "Invalid argument", LOCKDOWN_E_INVALID_CONF: "Invalid configuration", - LOCKDOWN_E_PLIST_ERROR: "PList error", + LOCKDOWN_E_PLIST_ERROR: "Property list error", LOCKDOWN_E_PAIRING_FAILED: "Pairing failed", LOCKDOWN_E_SSL_ERROR: "SSL error", LOCKDOWN_E_DICT_ERROR: "Dict error", @@ -213,9 +238,16 @@ cdef class LockdownClient(Base): cpdef goodbye(self): pass +cdef extern from *: + ctypedef char* const_char_ptr "const char*" + include "property_list_client.pxi" include "mobilesync.pxi" include "notification_proxy.pxi" include "sbservices.pxi" include "mobilebackup.pxi" include "afc.pxi" +include "file_relay.pxi" +include "screenshotr.pxi" +include "installation_proxy.pxi" +include "mobile_image_mounter.pxi" diff --git a/cython/installation_proxy.pxi b/cython/installation_proxy.pxi new file mode 100644 index 0000000..0424a81 --- /dev/null +++ b/cython/installation_proxy.pxi @@ -0,0 +1,210 @@ +cdef extern from "libimobiledevice/installation_proxy.h": + cdef struct instproxy_client_private: + pass + ctypedef instproxy_client_private *instproxy_client_t + ctypedef void (*instproxy_status_cb_t) (const_char_ptr operation, plist.plist_t status, void *user_data) + + ctypedef enum instproxy_error_t: + INSTPROXY_E_SUCCESS = 0 + INSTPROXY_E_INVALID_ARG = -1 + INSTPROXY_E_PLIST_ERROR = -2 + INSTPROXY_E_CONN_FAILED = -3 + INSTPROXY_E_OP_IN_PROGRESS = -4 + INSTPROXY_E_OP_FAILED = -5 + INSTPROXY_E_UNKNOWN_ERROR = -256 + + instproxy_error_t instproxy_client_new(idevice_t device, uint16_t port, instproxy_client_t *client) + instproxy_error_t instproxy_client_free(instproxy_client_t client) + + instproxy_error_t instproxy_browse(instproxy_client_t client, plist.plist_t client_options, plist.plist_t *result) + instproxy_error_t instproxy_install(instproxy_client_t client, char *pkg_path, plist.plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) + instproxy_error_t instproxy_upgrade(instproxy_client_t client, char *pkg_path, plist.plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) + instproxy_error_t instproxy_uninstall(instproxy_client_t client, char *appid, plist.plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) + + instproxy_error_t instproxy_lookup_archives(instproxy_client_t client, plist.plist_t client_options, plist.plist_t *result) + instproxy_error_t instproxy_archive(instproxy_client_t client, char *appid, plist.plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) + instproxy_error_t instproxy_restore(instproxy_client_t client, char *appid, plist.plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) + instproxy_error_t instproxy_remove_archive(instproxy_client_t client, char *appid, plist.plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) + +cdef void instproxy_notify_cb(const_char_ptr operation, plist.plist_t status, void *py_callback): + (<object>py_callback)(operation, plist.plist_t_to_node(status, False)) + +cdef class InstallationProxyError(BaseError): + def __init__(self, *args, **kwargs): + self._lookup_table = { + INSTPROXY_E_SUCCESS: "Success", + INSTPROXY_E_INVALID_ARG: "Invalid argument", + INSTPROXY_E_PLIST_ERROR: "Property list error", + INSTPROXY_E_CONN_FAILED: "Connection failed", + INSTPROXY_E_OP_IN_PROGRESS: "Operation in progress", + INSTPROXY_E_OP_FAILED: "Operation failed", + INSTPROXY_E_UNKNOWN_ERROR: "Unknown error" + } + BaseError.__init__(self, *args, **kwargs) + +cdef class InstallationProxyClient(Base): + cdef instproxy_client_t _c_client + + def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): + cdef: + iDevice dev = device + LockdownClient lckd + instproxy_error_t err + if lockdown is None: + lckd = LockdownClient(dev) + else: + lckd = lockdown + port = lckd.start_service("com.apple.mobile.installation_proxy") + err = instproxy_client_new(dev._c_dev, port, &self._c_client) + self.handle_error(err) + + def __dealloc__(self): + cdef instproxy_error_t err + if self._c_client is not NULL: + err = instproxy_client_free(self._c_client) + self.handle_error(err) + + cpdef plist.Node browse(self, object client_options): + cdef: + plist.Node options + plist.plist_t c_options + plist.plist_t c_result = NULL + instproxy_error_t err + if isinstance(client_options, plist.Dict): + options = client_options + c_options = options._c_node + elif isinstance(client_options, dict): + c_options = plist.native_to_plist_t(client_options) + else: + raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) + err = instproxy_browse(self._c_client, c_options, &c_result) + self.handle_error(err) + return plist.plist_t_to_node(c_result) + + cpdef install(self, bytes pkg_path, object client_options, object callback=None): + cdef: + plist.Node options + plist.plist_t c_options + instproxy_error_t err + if isinstance(client_options, plist.Dict): + options = client_options + c_options = options._c_node + elif isinstance(client_options, dict): + c_options = plist.native_to_plist_t(client_options) + else: + raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) + if callback is None: + err = instproxy_install(self._c_client, pkg_path, options._c_node, NULL, NULL) + else: + err = instproxy_install(self._c_client, pkg_path, options._c_node, instproxy_notify_cb, <void*>callback) + self.handle_error(err) + + cpdef upgrade(self, bytes pkg_path, object client_options, object callback=None): + cdef: + plist.Node options + plist.plist_t c_options + instproxy_error_t err + if isinstance(client_options, plist.Dict): + options = client_options + c_options = options._c_node + elif isinstance(client_options, dict): + c_options = plist.native_to_plist_t(client_options) + else: + raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) + if callback is None: + err = instproxy_upgrade(self._c_client, pkg_path, options._c_node, NULL, NULL) + else: + err = instproxy_upgrade(self._c_client, pkg_path, options._c_node, instproxy_notify_cb, <void*>callback) + self.handle_error(err) + + cpdef uninstall(self, bytes appid, object client_options, object callback=None): + cdef: + plist.Node options + plist.plist_t c_options + instproxy_error_t err + if isinstance(client_options, plist.Dict): + options = client_options + c_options = options._c_node + elif isinstance(client_options, dict): + c_options = plist.native_to_plist_t(client_options) + else: + raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) + if callback is None: + err = instproxy_uninstall(self._c_client, appid, options._c_node, NULL, NULL) + else: + err = instproxy_uninstall(self._c_client, appid, options._c_node, instproxy_notify_cb, <void*>callback) + self.handle_error(err) + + cpdef plist.Node lookup_archives(self, object client_options): + cdef: + plist.Node options + plist.plist_t c_options + plist.plist_t c_node = NULL + instproxy_error_t err + if isinstance(client_options, plist.Dict): + options = client_options + c_options = options._c_node + elif isinstance(client_options, dict): + c_options = plist.native_to_plist_t(client_options) + else: + raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) + err = instproxy_lookup_archives(self._c_client, options._c_node, &c_node) + self.handle_error(err) + return plist.plist_t_to_node(c_node) + + cpdef archive(self, bytes appid, object client_options, object callback=None): + cdef: + plist.Node options + plist.plist_t c_options + instproxy_error_t err + if isinstance(client_options, plist.Dict): + options = client_options + c_options = options._c_node + elif isinstance(client_options, dict): + c_options = plist.native_to_plist_t(client_options) + else: + raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) + if callback is None: + err = instproxy_archive(self._c_client, appid, options._c_node, NULL, NULL) + else: + err = instproxy_archive(self._c_client, appid, options._c_node, instproxy_notify_cb, <void*>callback) + self.handle_error(err) + + cpdef restore(self, bytes appid, object client_options, object callback=None): + cdef: + plist.Node options + plist.plist_t c_options + instproxy_error_t err + if isinstance(client_options, plist.Dict): + options = client_options + c_options = options._c_node + elif isinstance(client_options, dict): + c_options = plist.native_to_plist_t(client_options) + else: + raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) + if callback is None: + err = instproxy_restore(self._c_client, appid, options._c_node, NULL, NULL) + else: + err = instproxy_restore(self._c_client, appid, options._c_node, instproxy_notify_cb, <void*>callback) + self.handle_error(err) + + cpdef remove_archive(self, bytes appid, object client_options, object callback=None): + cdef: + plist.Node options + plist.plist_t c_options + instproxy_error_t err + if isinstance(client_options, plist.Dict): + options = client_options + c_options = options._c_node + elif isinstance(client_options, dict): + c_options = plist.native_to_plist_t(client_options) + else: + raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) + if callback is None: + err = instproxy_remove_archive(self._c_client, appid, options._c_node, NULL, NULL) + else: + err = instproxy_remove_archive(self._c_client, appid, options._c_node, instproxy_notify_cb, <void*>callback) + self.handle_error(err) + + cdef inline BaseError _error(self, int16_t ret): + return InstallationProxyError(ret) diff --git a/cython/mobile_image_mounter.pxi b/cython/mobile_image_mounter.pxi new file mode 100644 index 0000000..8ec30d1 --- /dev/null +++ b/cython/mobile_image_mounter.pxi @@ -0,0 +1,75 @@ +cdef extern from "libimobiledevice/mobile_image_mounter.h": + cdef struct mobile_image_mounter_client_private: + pass + ctypedef mobile_image_mounter_client_private *mobile_image_mounter_client_t + + ctypedef enum mobile_image_mounter_error_t: + MOBILE_IMAGE_MOUNTER_E_SUCCESS = 0 + MOBILE_IMAGE_MOUNTER_E_INVALID_ARG = -1 + MOBILE_IMAGE_MOUNTER_E_PLIST_ERROR = -2 + MOBILE_IMAGE_MOUNTER_E_CONN_FAILED = -3 + MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR = -256 + + mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, uint16_t port, mobile_image_mounter_client_t *client) + mobile_image_mounter_error_t mobile_image_mounter_free(mobile_image_mounter_client_t client) + mobile_image_mounter_error_t mobile_image_mounter_lookup_image(mobile_image_mounter_client_t client, char *image_type, plist.plist_t *result) + mobile_image_mounter_error_t mobile_image_mounter_mount_image(mobile_image_mounter_client_t client, char *image_path, char *image_signature, uint16_t signature_length, char *image_type, plist.plist_t *result) + mobile_image_mounter_error_t mobile_image_mounter_hangup(mobile_image_mounter_client_t client) + +cdef class MobileImageMounterError(BaseError): + def __init__(self, *args, **kwargs): + self._lookup_table = { + MOBILE_IMAGE_MOUNTER_E_SUCCESS: "Success", + MOBILE_IMAGE_MOUNTER_E_INVALID_ARG: "Invalid argument", + MOBILE_IMAGE_MOUNTER_E_PLIST_ERROR: "Property list error", + MOBILE_IMAGE_MOUNTER_E_CONN_FAILED: "Connection failed", + MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR: "Unknown error" + } + BaseError.__init__(self, *args, **kwargs) + +cdef class MobileImageMounterClient(PropertyListClient): + cdef mobile_image_mounter_client_t _c_client + + def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): + cdef: + iDevice dev = device + LockdownClient lckd + mobile_image_mounter_error_t err + if lockdown is None: + lckd = LockdownClient(dev) + else: + lckd = lockdown + port = lckd.start_service("com.apple.mobile.mobile_image_mounter") + err = mobile_image_mounter_new(dev._c_dev, port, &self._c_client) + self.handle_error(err) + + def __dealloc__(self): + cdef mobile_image_mounter_error_t err + if self._c_client is not NULL: + err = mobile_image_mounter_free(self._c_client) + self.handle_error(err) + + cdef inline BaseError _error(self, int16_t ret): + return MobileImageMounterError(ret) + + cpdef plist.Node lookup_image(self, bytes image_type): + cdef: + plist.plist_t c_node = NULL + mobile_image_mounter_error_t err + err = mobile_image_mounter_lookup_image(self._c_client, image_type, &c_node) + self.handle_error(err) + return plist.plist_t_to_node(c_node) + + cpdef plist.Node mount_image(self, bytes image_path, bytes image_signature, bytes image_type): + cdef: + plist.plist_t c_node = NULL + mobile_image_mounter_error_t err + err = mobile_image_mounter_mount_image(self._c_client, image_path, image_signature, len(image_signature), + image_type, &c_node) + self.handle_error(err) + return plist.plist_t_to_node(c_node) + + cpdef hangup(self): + cdef mobile_image_mounter_error_t err + err = mobile_image_mounter_hangup(self._c_client) + self.handle_error(err) diff --git a/cython/mobilebackup.pxi b/cython/mobilebackup.pxi index 53a4b6f..330a99d 100644 --- a/cython/mobilebackup.pxi +++ b/cython/mobilebackup.pxi @@ -1,7 +1,7 @@ cdef extern from "libimobiledevice/mobilebackup.h": - cdef struct mobilebackup_client_int: + cdef struct mobilebackup_client_private: pass - ctypedef mobilebackup_client_int *mobilebackup_client_t + ctypedef mobilebackup_client_private *mobilebackup_client_t ctypedef enum mobilebackup_error_t: MOBILEBACKUP_E_SUCCESS = 0 @@ -21,9 +21,9 @@ cdef class MobileBackupError(BaseError): self._lookup_table = { MOBILEBACKUP_E_SUCCESS: "Success", MOBILEBACKUP_E_INVALID_ARG: "Invalid argument", - MOBILEBACKUP_E_PLIST_ERROR: "PList Error", - MOBILEBACKUP_E_MUX_ERROR: "MUX Error", - MOBILEBACKUP_E_BAD_VERSION: "Bad Version", + MOBILEBACKUP_E_PLIST_ERROR: "Property list error", + MOBILEBACKUP_E_MUX_ERROR: "MUX error", + MOBILEBACKUP_E_BAD_VERSION: "Bad version", MOBILEBACKUP_E_UNKNOWN_ERROR: "Unknown error" } BaseError.__init__(self, *args, **kwargs) diff --git a/cython/mobilesync.pxi b/cython/mobilesync.pxi index 87539d2..d5dacb1 100644 --- a/cython/mobilesync.pxi +++ b/cython/mobilesync.pxi @@ -1,7 +1,7 @@ cdef extern from "libimobiledevice/mobilesync.h": - cdef struct mobilesync_client_int: + cdef struct mobilesync_client_private: pass - ctypedef mobilesync_client_int *mobilesync_client_t + ctypedef mobilesync_client_private *mobilesync_client_t ctypedef enum mobilesync_error_t: MOBILESYNC_E_SUCCESS = 0 @@ -21,9 +21,9 @@ cdef class MobileSyncError(BaseError): self._lookup_table = { MOBILESYNC_E_SUCCESS: "Success", MOBILESYNC_E_INVALID_ARG: "Invalid argument", - MOBILESYNC_E_PLIST_ERROR: "PList Error", - MOBILESYNC_E_MUX_ERROR: "MUX Error", - MOBILESYNC_E_BAD_VERSION: "Bad Version", + MOBILESYNC_E_PLIST_ERROR: "Property list error", + MOBILESYNC_E_MUX_ERROR: "MUX error", + MOBILESYNC_E_BAD_VERSION: "Bad version", MOBILESYNC_E_UNKNOWN_ERROR: "Unknown error" } BaseError.__init__(self, *args, **kwargs) diff --git a/cython/notification_proxy.pxi b/cython/notification_proxy.pxi index 2ca484a..d5f2d25 100644 --- a/cython/notification_proxy.pxi +++ b/cython/notification_proxy.pxi @@ -1,10 +1,7 @@ -cdef extern from *: - ctypedef char* const_char_ptr "const char*" - cdef extern from "libimobiledevice/notification_proxy.h": - cdef struct np_client_int: + cdef struct np_client_private: pass - ctypedef np_client_int *np_client_t + ctypedef np_client_private *np_client_t ctypedef enum np_error_t: NP_E_SUCCESS = 0 NP_E_INVALID_ARG = -1 @@ -27,9 +24,9 @@ cdef class NotificationProxyError(BaseError): self._lookup_table = { NP_E_SUCCESS: "Success", NP_E_INVALID_ARG: "Invalid argument", - NP_E_PLIST_ERROR: "PList Error", - NP_E_CONN_FAILED: "Connection Failed", - NP_E_UNKNOWN_ERROR: "Unknown Error" + NP_E_PLIST_ERROR: "Property list error", + NP_E_CONN_FAILED: "Connection failed", + NP_E_UNKNOWN_ERROR: "Unknown error" } BaseError.__init__(self, *args, **kwargs) diff --git a/cython/sbservices.pxi b/cython/sbservices.pxi index 384c92b..0ad67c7 100644 --- a/cython/sbservices.pxi +++ b/cython/sbservices.pxi @@ -1,7 +1,7 @@ cdef extern from "libimobiledevice/sbservices.h": - cdef struct sbservices_client_int: + cdef struct sbservices_client_private: pass - ctypedef sbservices_client_int *sbservices_client_t + ctypedef sbservices_client_private *sbservices_client_t ctypedef enum sbservices_error_t: SBSERVICES_E_SUCCESS = 0 SBSERVICES_E_INVALID_ARG = -1 @@ -19,9 +19,9 @@ cdef class SpringboardServicesError(BaseError): self._lookup_table = { SBSERVICES_E_SUCCESS: "Success", SBSERVICES_E_INVALID_ARG: "Invalid argument", - SBSERVICES_E_PLIST_ERROR: "PList Error", - SBSERVICES_E_CONN_FAILED: "Connection Failed", - SBSERVICES_E_UNKNOWN_ERROR: "Unknown Error" + SBSERVICES_E_PLIST_ERROR: "Property list error", + SBSERVICES_E_CONN_FAILED: "Connection failed", + SBSERVICES_E_UNKNOWN_ERROR: "Unknown error" } BaseError.__init__(self, *args, **kwargs) diff --git a/cython/screenshotr.pxi b/cython/screenshotr.pxi new file mode 100644 index 0000000..92d95b9 --- /dev/null +++ b/cython/screenshotr.pxi @@ -0,0 +1,65 @@ +cdef extern from "libimobiledevice/screenshotr.h": + cdef struct screenshotr_client_private: + pass + ctypedef screenshotr_client_private *screenshotr_client_t + + ctypedef enum screenshotr_error_t: + SCREENSHOTR_E_SUCCESS = 0 + SCREENSHOTR_E_INVALID_ARG = -1 + SCREENSHOTR_E_PLIST_ERROR = -2 + SCREENSHOTR_E_MUX_ERROR = -3 + SCREENSHOTR_E_BAD_VERSION = -4 + SCREENSHOTR_E_UNKNOWN_ERROR = -256 + + screenshotr_error_t screenshotr_client_new(idevice_t device, uint16_t port, screenshotr_client_t * client) + screenshotr_error_t screenshotr_client_free(screenshotr_client_t client) + screenshotr_error_t screenshotr_take_screenshot(screenshotr_client_t client, char **imgdata, uint64_t *imgsize) + +cdef class ScreenshotrError(BaseError): + def __init__(self, *args, **kwargs): + self._lookup_table = { + SCREENSHOTR_E_SUCCESS: "Success", + SCREENSHOTR_E_INVALID_ARG: "Invalid argument", + SCREENSHOTR_E_PLIST_ERROR: "Property list error", + SCREENSHOTR_E_MUX_ERROR: "MUX error", + SCREENSHOTR_E_BAD_VERSION: "Bad version", + SCREENSHOTR_E_UNKNOWN_ERROR: "Unknown error" + } + BaseError.__init__(self, *args, **kwargs) + +cdef class ScreenshotrClient(Base): + cdef screenshotr_client_t _c_client + + def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): + cdef: + iDevice dev = device + LockdownClient lckd + screenshotr_error_t err + if lockdown is None: + lckd = LockdownClient(dev) + else: + lckd = lockdown + port = lckd.start_service("com.apple.mobile.screenshotr") + err = screenshotr_client_new(dev._c_dev, port, &self._c_client) + self.handle_error(err) + + def __dealloc__(self): + cdef screenshotr_error_t err + if self._c_client is not NULL: + err = screenshotr_client_free(self._c_client) + self.handle_error(err) + + cpdef bytes take_screenshot(self): + cdef: + char* c_data + uint64_t data_size + bytes result + screenshotr_error_t err + + err = screenshotr_take_screenshot(self._c_client, &c_data, &data_size) + self.handle_error(err) + result = c_data[:data_size] + return result + + cdef inline BaseError _error(self, int16_t ret): + return ScreenshotrError(ret) |