diff options
| -rw-r--r-- | cython/Makefile.am | 14 | ||||
| -rw-r--r-- | cython/imobiledevice.pxd | 50 | ||||
| -rw-r--r-- | cython/imobiledevice.pyx | 203 | ||||
| -rw-r--r-- | cython/mobilebackup.pxi | 54 | ||||
| -rw-r--r-- | cython/mobilesync.pxi | 54 | ||||
| -rw-r--r-- | cython/notification_proxy.pxi | 52 | ||||
| -rw-r--r-- | cython/property_list_service.pxi | 15 | ||||
| -rw-r--r-- | cython/sbservices.pxi | 57 | ||||
| -rw-r--r-- | cython/stdint.pxi | 10 |
9 files changed, 311 insertions, 198 deletions
diff --git a/cython/Makefile.am b/cython/Makefile.am index 3cada6c..f5f01ef 100644 --- a/cython/Makefile.am +++ b/cython/Makefile.am | |||
| @@ -6,25 +6,27 @@ AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_L | |||
| 6 | if HAVE_CYTHON | 6 | if HAVE_CYTHON |
| 7 | 7 | ||
| 8 | BUILT_SOURCES = imobiledevice.c | 8 | BUILT_SOURCES = imobiledevice.c |
| 9 | PXDINCLUDES = imobiledevice.pxd stdint.pxi $(CYTHON_PLIST_INCLUDE_DIR)/plist.pxd | ||
| 10 | PXIINCLUDES = stdint.pxi mobilesync.pxi notification_proxy.pxi sbservices.pxi mobilebackup.pxi | ||
| 9 | 11 | ||
| 10 | CLEANFILES = \ | 12 | CLEANFILES = \ |
| 11 | *.pyc \ | 13 | *.pyc \ |
| 12 | *.pyo \ | 14 | *.pyo \ |
| 13 | imobiledevice.so \ | ||
| 14 | imobiledevice.c | 15 | imobiledevice.c |
| 15 | 16 | ||
| 16 | EXTRA_DIST = \ | 17 | EXTRA_DIST = imobiledevice.pyx imobiledevice.pxd $(PXIINCLUDES) |
| 17 | imobiledevice.pyx | ||
| 18 | 18 | ||
| 19 | imobiledevicedir = $(pyexecdir) | 19 | imobiledevicedir = $(pyexecdir) |
| 20 | imobiledevice_LTLIBRARIES = imobiledevice.la | 20 | imobiledevice_LTLIBRARIES = imobiledevice.la |
| 21 | nodist_imobiledevice_la_SOURCES = imobiledevice.c #imobiledevice_private.c | 21 | imobiledevice_la_SOURCES = imobiledevice.pyx |
| 22 | imobiledevice_la_CFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/src $(PYTHON_CPPFLAGS) | 22 | imobiledevice_la_CFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/src $(PYTHON_CPPFLAGS) |
| 23 | imobiledevice_la_LDFLAGS = -module -avoid-version $(PYTHON_LDFLAGS) | 23 | imobiledevice_la_LDFLAGS = -module -avoid-version $(PYTHON_LDFLAGS) |
| 24 | imobiledevice_la_LIBADD = $(top_builddir)/src/libimobiledevice.la | 24 | imobiledevice_la_LIBADD = $(top_builddir)/src/libimobiledevice.la |
| 25 | 25 | ||
| 26 | imobiledevice.c: imobiledevice.pyx $(CYTHON_PLIST_INCLUDE_DIR)/plist.pxd | 26 | imobiledevice.c: imobiledevice.pyx $(PXDINCLUDES) $(PXIINCLUDES) |
| 27 | $(CYTHON) --line-directives -I$(CYTHON_PLIST_INCLUDE_DIR) -I$(top_srcdir)/src -o $@ $< | 27 | |
| 28 | .pyx.c: | ||
| 29 | $(CYTHON) -I$(CYTHON_PLIST_INCLUDE_DIR) -I$(top_srcdir)/src -o $@ $< | ||
| 28 | 30 | ||
| 29 | # imobiledevice_private.c: $(IMOBILEDEVICE_PRIVATE_SOURCES) $(IMOBILEDEVICE_INCLUDES) $(PLIST_INCLUDES) | 31 | # imobiledevice_private.c: $(IMOBILEDEVICE_PRIVATE_SOURCES) $(IMOBILEDEVICE_INCLUDES) $(PLIST_INCLUDES) |
| 30 | # $(CYTHON) $(IMOBILEDEVICE_CPPFLAGS) -I$(top_srcdir)/src -o $@ $< | 32 | # $(CYTHON) $(IMOBILEDEVICE_CPPFLAGS) -I$(top_srcdir)/src -o $@ $< |
diff --git a/cython/imobiledevice.pxd b/cython/imobiledevice.pxd new file mode 100644 index 0000000..bdebe33 --- /dev/null +++ b/cython/imobiledevice.pxd | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | cimport plist | ||
| 2 | |||
| 3 | include "stdint.pxi" | ||
| 4 | |||
| 5 | cdef extern from "pyerrors.h": | ||
| 6 | ctypedef class __builtin__.Exception [object PyBaseExceptionObject]: | ||
| 7 | pass | ||
| 8 | |||
| 9 | cdef class BaseError(Exception): | ||
| 10 | cdef dict _lookup_table | ||
| 11 | cdef int16_t _c_errcode | ||
| 12 | |||
| 13 | cdef class iDeviceError(BaseError): pass | ||
| 14 | |||
| 15 | cdef extern from "libimobiledevice/libimobiledevice.h": | ||
| 16 | cdef struct idevice_int: | ||
| 17 | pass | ||
| 18 | ctypedef idevice_int* idevice_t | ||
| 19 | ctypedef int16_t idevice_error_t | ||
| 20 | cdef enum idevice_event_type: | ||
| 21 | IDEVICE_DEVICE_ADD = 1, | ||
| 22 | IDEVICE_DEVICE_REMOVE | ||
| 23 | ctypedef struct idevice_event_t: | ||
| 24 | idevice_event_type event | ||
| 25 | char *uuid | ||
| 26 | int conn_type | ||
| 27 | ctypedef idevice_event_t* const_idevice_event_t "const idevice_event_t*" | ||
| 28 | |||
| 29 | cdef class iDeviceEvent: | ||
| 30 | cdef const_idevice_event_t _c_event | ||
| 31 | |||
| 32 | cdef class iDevice: | ||
| 33 | cdef idevice_t _c_dev | ||
| 34 | |||
| 35 | cdef class LockdownError(BaseError): pass | ||
| 36 | |||
| 37 | cdef extern from "libimobiledevice/lockdown.h": | ||
| 38 | cdef struct lockdownd_client_int: | ||
| 39 | pass | ||
| 40 | ctypedef lockdownd_client_int *lockdownd_client_t | ||
| 41 | |||
| 42 | cdef class LockdownClient: | ||
| 43 | cdef lockdownd_client_t _c_client | ||
| 44 | cpdef int start_service(self, service) | ||
| 45 | cpdef goodbye(self) | ||
| 46 | |||
| 47 | cpdef set_debug_level(int level) | ||
| 48 | cpdef event_subscribe(object callback) | ||
| 49 | cpdef event_unsubscribe() | ||
| 50 | cpdef get_device_list() | ||
diff --git a/cython/imobiledevice.pyx b/cython/imobiledevice.pyx index befd586..bbec7b8 100644 --- a/cython/imobiledevice.pyx +++ b/cython/imobiledevice.pyx | |||
| @@ -1,24 +1,4 @@ | |||
| 1 | cdef extern from *: | ||
| 2 | ctypedef unsigned char uint8_t | ||
| 3 | ctypedef short int int16_t | ||
| 4 | ctypedef unsigned short int uint16_t | ||
| 5 | ctypedef unsigned int uint32_t | ||
| 6 | ctypedef int int32_t | ||
| 7 | IF UNAME_MACHINE == 'x86_64': | ||
| 8 | ctypedef unsigned long int uint64_t | ||
| 9 | ELSE: | ||
| 10 | ctypedef unsigned long long int uint64_t | ||
| 11 | |||
| 12 | cimport plist | ||
| 13 | |||
| 14 | cdef extern from "pyerrors.h": | ||
| 15 | ctypedef class __builtin__.Exception [object PyBaseExceptionObject]: | ||
| 16 | pass | ||
| 17 | |||
| 18 | cdef class BaseError(Exception): | 1 | cdef class BaseError(Exception): |
| 19 | cdef dict _lookup_table | ||
| 20 | cdef int16_t _c_errcode | ||
| 21 | |||
| 22 | def __cinit__(self, int16_t errcode): | 2 | def __cinit__(self, int16_t errcode): |
| 23 | self._c_errcode = errcode | 3 | self._c_errcode = errcode |
| 24 | 4 | ||
| @@ -40,10 +20,6 @@ cdef class BaseError(Exception): | |||
| 40 | return self.__str__() | 20 | return self.__str__() |
| 41 | 21 | ||
| 42 | cdef extern from "libimobiledevice/libimobiledevice.h": | 22 | cdef extern from "libimobiledevice/libimobiledevice.h": |
| 43 | cdef struct idevice_int: | ||
| 44 | pass | ||
| 45 | ctypedef idevice_int* idevice_t | ||
| 46 | ctypedef int16_t idevice_error_t | ||
| 47 | int16_t IDEVICE_E_SUCCESS | 23 | int16_t IDEVICE_E_SUCCESS |
| 48 | int16_t IDEVICE_E_INVALID_ARG | 24 | int16_t IDEVICE_E_INVALID_ARG |
| 49 | int16_t IDEVICE_E_UNKNOWN_ERROR | 25 | int16_t IDEVICE_E_UNKNOWN_ERROR |
| @@ -51,14 +27,6 @@ cdef extern from "libimobiledevice/libimobiledevice.h": | |||
| 51 | int16_t IDEVICE_E_NOT_ENOUGH_DATA | 27 | int16_t IDEVICE_E_NOT_ENOUGH_DATA |
| 52 | int16_t IDEVICE_E_BAD_HEADER | 28 | int16_t IDEVICE_E_BAD_HEADER |
| 53 | int16_t IDEVICE_E_SSL_ERROR | 29 | int16_t IDEVICE_E_SSL_ERROR |
| 54 | cdef enum idevice_event_type: | ||
| 55 | IDEVICE_DEVICE_ADD = 1, | ||
| 56 | IDEVICE_DEVICE_REMOVE | ||
| 57 | ctypedef struct idevice_event_t: | ||
| 58 | idevice_event_type event | ||
| 59 | char *uuid | ||
| 60 | int conn_type | ||
| 61 | ctypedef idevice_event_t* const_idevice_event_t "const idevice_event_t*" | ||
| 62 | ctypedef void (*idevice_event_cb_t) (const_idevice_event_t event, void *user_data) | 30 | ctypedef void (*idevice_event_cb_t) (const_idevice_event_t event, void *user_data) |
| 63 | cdef extern idevice_error_t idevice_event_subscribe(idevice_event_cb_t callback, void *user_data) | 31 | cdef extern idevice_error_t idevice_event_subscribe(idevice_event_cb_t callback, void *user_data) |
| 64 | cdef extern idevice_error_t idevice_event_unsubscribe() | 32 | cdef extern idevice_error_t idevice_event_unsubscribe() |
| @@ -83,26 +51,25 @@ cdef class iDeviceError(BaseError): | |||
| 83 | } | 51 | } |
| 84 | BaseError.__init__(self, *args, **kwargs) | 52 | BaseError.__init__(self, *args, **kwargs) |
| 85 | 53 | ||
| 86 | def set_debug_level(level): | 54 | cpdef set_debug_level(int level): |
| 87 | idevice_set_debug_level(level) | 55 | idevice_set_debug_level(level) |
| 88 | 56 | ||
| 89 | cdef class iDeviceEvent: | 57 | cdef class iDeviceEvent: pass |
| 90 | cdef const_idevice_event_t _c_event | ||
| 91 | 58 | ||
| 92 | cdef void idevice_event_cb(const_idevice_event_t c_event, void *user_data): | 59 | cdef void idevice_event_cb(const_idevice_event_t c_event, void *user_data): |
| 93 | cdef iDeviceEvent event = iDeviceEvent() | 60 | cdef iDeviceEvent event = iDeviceEvent() |
| 94 | event._c_event = c_event | 61 | event._c_event = c_event |
| 95 | (<object>user_data)(event) | 62 | (<object>user_data)(event) |
| 96 | 63 | ||
| 97 | def event_subscribe(callback): | 64 | cpdef event_subscribe(object callback): |
| 98 | cdef iDeviceError err = iDeviceError(idevice_event_subscribe(idevice_event_cb, <void*>callback)) | 65 | cdef iDeviceError err = iDeviceError(idevice_event_subscribe(idevice_event_cb, <void*>callback)) |
| 99 | if err: raise err | 66 | if err: raise err |
| 100 | 67 | ||
| 101 | def event_unsubscribe(): | 68 | cpdef event_unsubscribe(): |
| 102 | cdef iDeviceError err = iDeviceError(idevice_event_unsubscribe()) | 69 | cdef iDeviceError err = iDeviceError(idevice_event_unsubscribe()) |
| 103 | if err: raise err | 70 | if err: raise err |
| 104 | 71 | ||
| 105 | def get_device_list(): | 72 | cpdef get_device_list(): |
| 106 | cdef char** devices | 73 | cdef char** devices |
| 107 | cdef int count | 74 | cdef int count |
| 108 | cdef list result | 75 | cdef list result |
| @@ -118,8 +85,6 @@ def get_device_list(): | |||
| 118 | return result | 85 | return result |
| 119 | 86 | ||
| 120 | cdef class iDevice: | 87 | cdef class iDevice: |
| 121 | cdef idevice_t _c_dev | ||
| 122 | |||
| 123 | def __cinit__(self, uuid=None, *args, **kwargs): | 88 | def __cinit__(self, uuid=None, *args, **kwargs): |
| 124 | cdef char* c_uuid = NULL | 89 | cdef char* c_uuid = NULL |
| 125 | if uuid is not None: | 90 | if uuid is not None: |
| @@ -202,8 +167,6 @@ cdef class LockdownError(BaseError): | |||
| 202 | BaseError.__init__(self, *args, **kwargs) | 167 | BaseError.__init__(self, *args, **kwargs) |
| 203 | 168 | ||
| 204 | cdef class LockdownClient: | 169 | cdef class LockdownClient: |
| 205 | cdef lockdownd_client_t _c_client | ||
| 206 | |||
| 207 | def __cinit__(self, iDevice device not None, char *label=NULL, *args, **kwargs): | 170 | def __cinit__(self, iDevice device not None, char *label=NULL, *args, **kwargs): |
| 208 | cdef iDevice dev = device | 171 | cdef iDevice dev = device |
| 209 | err = LockdownError(lockdownd_client_new_with_handshake(dev._c_dev, &(self._c_client), label)) | 172 | err = LockdownError(lockdownd_client_new_with_handshake(dev._c_dev, &(self._c_client), label)) |
| @@ -220,155 +183,11 @@ cdef class LockdownClient: | |||
| 220 | if err: raise err | 183 | if err: raise err |
| 221 | return port | 184 | return port |
| 222 | 185 | ||
| 223 | def goodbye(self): | 186 | cpdef goodbye(self): |
| 224 | pass | 187 | pass |
| 225 | |||
| 226 | |||
| 227 | cdef extern from "libimobiledevice/mobilesync.h": | ||
| 228 | cdef struct mobilesync_client_int: | ||
| 229 | pass | ||
| 230 | ctypedef mobilesync_client_int *mobilesync_client_t | ||
| 231 | |||
| 232 | ctypedef int16_t mobilesync_error_t | ||
| 233 | int16_t MOBILESYNC_E_SUCCESS | ||
| 234 | int16_t MOBILESYNC_E_INVALID_ARG | ||
| 235 | int16_t MOBILESYNC_E_PLIST_ERROR | ||
| 236 | int16_t MOBILESYNC_E_MUX_ERROR | ||
| 237 | int16_t MOBILESYNC_E_BAD_VERSION | ||
| 238 | int16_t MOBILESYNC_E_UNKNOWN_ERROR | ||
| 239 | |||
| 240 | mobilesync_error_t mobilesync_client_new(idevice_t device, uint16_t port, mobilesync_client_t * client) | ||
| 241 | mobilesync_error_t mobilesync_client_free(mobilesync_client_t client) | ||
| 242 | mobilesync_error_t mobilesync_receive(mobilesync_client_t client, plist.plist_t *plist) | ||
| 243 | mobilesync_error_t mobilesync_send(mobilesync_client_t client, plist.plist_t plist) | ||
| 244 | |||
| 245 | cdef class MobileSyncError(BaseError): | ||
| 246 | def __init__(self, *args, **kwargs): | ||
| 247 | self._lookup_table = { | ||
| 248 | MOBILESYNC_E_SUCCESS: "Success", | ||
| 249 | MOBILESYNC_E_INVALID_ARG: "Invalid argument", | ||
| 250 | MOBILESYNC_E_PLIST_ERROR: "PList Error", | ||
| 251 | MOBILESYNC_E_MUX_ERROR: "MUX Error", | ||
| 252 | MOBILESYNC_E_BAD_VERSION: "Bad Version", | ||
| 253 | MOBILESYNC_E_UNKNOWN_ERROR: "Unknown error" | ||
| 254 | } | ||
| 255 | BaseError.__init__(self, *args, **kwargs) | ||
| 256 | |||
| 257 | cdef class MobileSyncClient: | ||
| 258 | cdef mobilesync_client_t _c_client | ||
| 259 | |||
| 260 | def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): | ||
| 261 | cdef iDevice dev = device | ||
| 262 | cdef LockdownClient lckd | ||
| 263 | if lockdown is None: | ||
| 264 | lckd = LockdownClient(dev) | ||
| 265 | else: | ||
| 266 | lcdk = lockdown | ||
| 267 | port = lckd.start_service("com.apple.mobilesync") | ||
| 268 | err = MobileSyncError(mobilesync_client_new(dev._c_dev, port, &(self._c_client))) | ||
| 269 | if err: raise err | ||
| 270 | |||
| 271 | def __dealloc__(self): | ||
| 272 | if self._c_client is not NULL: | ||
| 273 | err = MobileSyncError(mobilesync_client_free(self._c_client)) | ||
| 274 | if err: raise err | ||
| 275 | |||
| 276 | cpdef send(self, object obj): | ||
| 277 | cdef plist.Node node | ||
| 278 | cdef plist.plist_t c_node | ||
| 279 | if isinstance(obj, plist.Node): | ||
| 280 | node = obj | ||
| 281 | c_node = node._c_node | ||
| 282 | else: | ||
| 283 | c_node = plist.native_to_plist_t(obj) | ||
| 284 | err = MobileSyncError(mobilesync_send(self._c_client, c_node)) | ||
| 285 | if err: raise err | ||
| 286 | |||
| 287 | cpdef receive(self): | ||
| 288 | cdef plist.plist_t c_node = NULL | ||
| 289 | err = MobileSyncError(mobilesync_receive(self._c_client, &(c_node))) | ||
| 290 | if err: raise err | ||
| 291 | 188 | ||
| 292 | return plist.plist_t_to_node(c_node) | 189 | include "property_list_service.pxi" |
| 293 | 190 | include "mobilesync.pxi" | |
| 294 | cdef extern from *: | 191 | include "notification_proxy.pxi" |
| 295 | ctypedef char* const_char_ptr "const char*" | 192 | include "sbservices.pxi" |
| 296 | 193 | include "mobilebackup.pxi" | |
| 297 | cdef extern from "libimobiledevice/notification_proxy.h": | ||
| 298 | cdef struct np_client_int: | ||
| 299 | pass | ||
| 300 | ctypedef np_client_int *np_client_t | ||
| 301 | ctypedef int16_t np_error_t | ||
| 302 | ctypedef void (*np_notify_cb_t) (const_char_ptr notification, void *userdata) | ||
| 303 | np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client) | ||
| 304 | np_error_t np_client_free(np_client_t client) | ||
| 305 | np_error_t np_post_notification(np_client_t client, char *notification) | ||
| 306 | np_error_t np_observe_notification(np_client_t client, char *notification) | ||
| 307 | np_error_t np_observe_notifications(np_client_t client, char **notification_spec) | ||
| 308 | np_error_t np_set_notify_callback(np_client_t client, np_notify_cb_t notify_cb, void *userdata) | ||
| 309 | |||
| 310 | cdef void np_notify_cb(const_char_ptr notification, void *py_callback): | ||
| 311 | (<object>py_callback)(notification) | ||
| 312 | |||
| 313 | cdef class NotificationProxyError(BaseError): | ||
| 314 | pass | ||
| 315 | |||
| 316 | cdef class NotificationProxy: | ||
| 317 | cdef np_client_t _c_client | ||
| 318 | |||
| 319 | def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): | ||
| 320 | cdef iDevice dev = device | ||
| 321 | cdef LockdownClient lckd | ||
| 322 | if lockdown is None: | ||
| 323 | lckd = LockdownClient(dev) | ||
| 324 | else: | ||
| 325 | lckd = lockdown | ||
| 326 | port = lckd.start_service("com.apple.mobile.notification_proxy") | ||
| 327 | err = NotificationProxyError(np_client_new(dev._c_dev, port, &(self._c_client))) | ||
| 328 | if err: raise err | ||
| 329 | |||
| 330 | def __dealloc__(self): | ||
| 331 | if self._c_client is not NULL: | ||
| 332 | err = NotificationProxyError(np_client_free(self._c_client)) | ||
| 333 | if err: raise err | ||
| 334 | |||
| 335 | def set_notify_callback(self, callback): | ||
| 336 | err = NotificationProxyError(np_set_notify_callback(self._c_client, np_notify_cb, <void*>callback)) | ||
| 337 | if err: raise err | ||
| 338 | |||
| 339 | def observe_notification(self, notification): | ||
| 340 | err = NotificationProxyError(np_observe_notification(self._c_client, notification)) | ||
| 341 | if err: raise err | ||
| 342 | |||
| 343 | cdef extern from "libimobiledevice/sbservices.h": | ||
| 344 | cdef struct sbservices_client_int: | ||
| 345 | pass | ||
| 346 | ctypedef sbservices_client_int *sbservices_client_t | ||
| 347 | ctypedef int16_t sbservices_error_t | ||
| 348 | sbservices_error_t sbservices_client_new(idevice_t device, uint16_t port, sbservices_client_t *client) | ||
| 349 | sbservices_error_t sbservices_client_free(sbservices_client_t client) | ||
| 350 | sbservices_error_t sbservices_get_icon_state(sbservices_client_t client, plist.plist_t *state) | ||
| 351 | sbservices_error_t sbservices_set_icon_state(sbservices_client_t client, plist.plist_t newstate) | ||
| 352 | sbservices_error_t sbservices_get_icon_pngdata(sbservices_client_t client, char *bundleId, char **pngdata, uint64_t *pngsize) | ||
| 353 | |||
| 354 | cdef class SpringboardServicesError(BaseError): | ||
| 355 | pass | ||
| 356 | |||
| 357 | cdef class SpringboardServices: | ||
| 358 | cdef sbservices_client_t _c_client | ||
| 359 | |||
| 360 | def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): | ||
| 361 | cdef iDevice dev = device | ||
| 362 | cdef LockdownClient lckd | ||
| 363 | if lockdown is None: | ||
| 364 | lckd = LockdownClient(dev) | ||
| 365 | else: | ||
| 366 | lckd = lockdown | ||
| 367 | port = lockdown.start_service("com.apple.springboardservices") | ||
| 368 | err = SpringboardServicesError(sbservices_client_new(dev._c_dev, port, &(self._c_client))) | ||
| 369 | if err: raise err | ||
| 370 | |||
| 371 | def __dealloc__(self): | ||
| 372 | if self._c_client is not NULL: | ||
| 373 | err = SpringboardServicesError(sbservices_client_free(self._c_client)) | ||
| 374 | if err: raise err | ||
diff --git a/cython/mobilebackup.pxi b/cython/mobilebackup.pxi new file mode 100644 index 0000000..2bbaebe --- /dev/null +++ b/cython/mobilebackup.pxi | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | cdef extern from "libimobiledevice/mobilebackup.h": | ||
| 2 | cdef struct mobilebackup_client_int: | ||
| 3 | pass | ||
| 4 | ctypedef mobilebackup_client_int *mobilebackup_client_t | ||
| 5 | |||
| 6 | ctypedef int16_t mobilebackup_error_t | ||
| 7 | int16_t MOBILEBACKUP_E_SUCCESS | ||
| 8 | int16_t MOBILEBACKUP_E_INVALID_ARG | ||
| 9 | int16_t MOBILEBACKUP_E_PLIST_ERROR | ||
| 10 | int16_t MOBILEBACKUP_E_MUX_ERROR | ||
| 11 | int16_t MOBILEBACKUP_E_BAD_VERSION | ||
| 12 | int16_t MOBILEBACKUP_E_UNKNOWN_ERROR | ||
| 13 | |||
| 14 | mobilebackup_error_t mobilebackup_client_new(idevice_t device, uint16_t port, mobilebackup_client_t * client) | ||
| 15 | mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client) | ||
| 16 | mobilebackup_error_t mobilebackup_receive(mobilebackup_client_t client, plist.plist_t *plist) | ||
| 17 | mobilebackup_error_t mobilebackup_send(mobilebackup_client_t client, plist.plist_t plist) | ||
| 18 | |||
| 19 | cdef class MobileBackupError(BaseError): | ||
| 20 | def __init__(self, *args, **kwargs): | ||
| 21 | self._lookup_table = { | ||
| 22 | MOBILEBACKUP_E_SUCCESS: "Success", | ||
| 23 | MOBILEBACKUP_E_INVALID_ARG: "Invalid argument", | ||
| 24 | MOBILEBACKUP_E_PLIST_ERROR: "PList Error", | ||
| 25 | MOBILEBACKUP_E_MUX_ERROR: "MUX Error", | ||
| 26 | MOBILEBACKUP_E_BAD_VERSION: "Bad Version", | ||
| 27 | MOBILEBACKUP_E_UNKNOWN_ERROR: "Unknown error" | ||
| 28 | } | ||
| 29 | BaseError.__init__(self, *args, **kwargs) | ||
| 30 | |||
| 31 | cdef class MobileBackupClient(PropertyListService): | ||
| 32 | cdef mobilebackup_client_t _c_client | ||
| 33 | |||
| 34 | def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): | ||
| 35 | cdef iDevice dev = device | ||
| 36 | cdef LockdownClient lckd | ||
| 37 | if lockdown is None: | ||
| 38 | lckd = LockdownClient(dev) | ||
| 39 | else: | ||
| 40 | lckd = lockdown | ||
| 41 | port = lckd.start_service("com.apple.mobilebackup") | ||
| 42 | err = MobileBackupError(mobilebackup_client_new(dev._c_dev, port, &self._c_client)) | ||
| 43 | if err: raise err | ||
| 44 | |||
| 45 | def __dealloc__(self): | ||
| 46 | if self._c_client is not NULL: | ||
| 47 | err = MobileBackupError(mobilebackup_client_free(self._c_client)) | ||
| 48 | if err: raise err | ||
| 49 | |||
| 50 | cdef _send(self, plist.plist_t node): | ||
| 51 | return MobileBackupError(mobilebackup_send(self._c_client, node)) | ||
| 52 | |||
| 53 | cdef _receive(self, plist.plist_t* node): | ||
| 54 | return MobileBackupError(mobilebackup_receive(self._c_client, node)) | ||
diff --git a/cython/mobilesync.pxi b/cython/mobilesync.pxi new file mode 100644 index 0000000..b9cf951 --- /dev/null +++ b/cython/mobilesync.pxi | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | cdef extern from "libimobiledevice/mobilesync.h": | ||
| 2 | cdef struct mobilesync_client_int: | ||
| 3 | pass | ||
| 4 | ctypedef mobilesync_client_int *mobilesync_client_t | ||
| 5 | |||
| 6 | ctypedef int16_t mobilesync_error_t | ||
| 7 | int16_t MOBILESYNC_E_SUCCESS | ||
| 8 | int16_t MOBILESYNC_E_INVALID_ARG | ||
| 9 | int16_t MOBILESYNC_E_PLIST_ERROR | ||
| 10 | int16_t MOBILESYNC_E_MUX_ERROR | ||
| 11 | int16_t MOBILESYNC_E_BAD_VERSION | ||
| 12 | int16_t MOBILESYNC_E_UNKNOWN_ERROR | ||
| 13 | |||
| 14 | mobilesync_error_t mobilesync_client_new(idevice_t device, uint16_t port, mobilesync_client_t * client) | ||
| 15 | mobilesync_error_t mobilesync_client_free(mobilesync_client_t client) | ||
| 16 | mobilesync_error_t mobilesync_receive(mobilesync_client_t client, plist.plist_t *plist) | ||
| 17 | mobilesync_error_t mobilesync_send(mobilesync_client_t client, plist.plist_t plist) | ||
| 18 | |||
| 19 | cdef class MobileSyncError(BaseError): | ||
| 20 | def __init__(self, *args, **kwargs): | ||
| 21 | self._lookup_table = { | ||
| 22 | MOBILESYNC_E_SUCCESS: "Success", | ||
| 23 | MOBILESYNC_E_INVALID_ARG: "Invalid argument", | ||
| 24 | MOBILESYNC_E_PLIST_ERROR: "PList Error", | ||
| 25 | MOBILESYNC_E_MUX_ERROR: "MUX Error", | ||
| 26 | MOBILESYNC_E_BAD_VERSION: "Bad Version", | ||
| 27 | MOBILESYNC_E_UNKNOWN_ERROR: "Unknown error" | ||
| 28 | } | ||
| 29 | BaseError.__init__(self, *args, **kwargs) | ||
| 30 | |||
| 31 | cdef class MobileSyncClient(PropertyListService): | ||
| 32 | cdef mobilesync_client_t _c_client | ||
| 33 | |||
| 34 | def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): | ||
| 35 | cdef iDevice dev = device | ||
| 36 | cdef LockdownClient lckd | ||
| 37 | if lockdown is None: | ||
| 38 | lckd = LockdownClient(dev) | ||
| 39 | else: | ||
| 40 | lckd = lockdown | ||
| 41 | port = lckd.start_service("com.apple.mobilesync") | ||
| 42 | err = MobileSyncError(mobilesync_client_new(dev._c_dev, port, &(self._c_client))) | ||
| 43 | if err: raise err | ||
| 44 | |||
| 45 | def __dealloc__(self): | ||
| 46 | if self._c_client is not NULL: | ||
| 47 | err = MobileSyncError(mobilesync_client_free(self._c_client)) | ||
| 48 | if err: raise err | ||
| 49 | |||
| 50 | cdef _send(self, plist.plist_t node): | ||
| 51 | return MobileSyncError(mobilesync_send(self._c_client, node)) | ||
| 52 | |||
| 53 | cdef _receive(self, plist.plist_t* node): | ||
| 54 | return MobileSyncError(mobilesync_receive(self._c_client, node)) | ||
diff --git a/cython/notification_proxy.pxi b/cython/notification_proxy.pxi new file mode 100644 index 0000000..acccf7d --- /dev/null +++ b/cython/notification_proxy.pxi | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | cdef extern from *: | ||
| 2 | ctypedef char* const_char_ptr "const char*" | ||
| 3 | |||
| 4 | cdef extern from "libimobiledevice/notification_proxy.h": | ||
| 5 | cdef struct np_client_int: | ||
| 6 | pass | ||
| 7 | ctypedef np_client_int *np_client_t | ||
| 8 | ctypedef int16_t np_error_t | ||
| 9 | ctypedef void (*np_notify_cb_t) (const_char_ptr notification, void *userdata) | ||
| 10 | np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client) | ||
| 11 | np_error_t np_client_free(np_client_t client) | ||
| 12 | np_error_t np_post_notification(np_client_t client, char *notification) | ||
| 13 | np_error_t np_observe_notification(np_client_t client, char *notification) | ||
| 14 | np_error_t np_observe_notifications(np_client_t client, char **notification_spec) | ||
| 15 | np_error_t np_set_notify_callback(np_client_t client, np_notify_cb_t notify_cb, void *userdata) | ||
| 16 | |||
| 17 | cdef void np_notify_cb(const_char_ptr notification, void *py_callback): | ||
| 18 | (<object>py_callback)(notification) | ||
| 19 | |||
| 20 | cdef class NotificationProxyError(BaseError): | ||
| 21 | pass | ||
| 22 | |||
| 23 | cdef class NotificationProxy: | ||
| 24 | cdef np_client_t _c_client | ||
| 25 | |||
| 26 | def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): | ||
| 27 | cdef iDevice dev = device | ||
| 28 | cdef LockdownClient lckd | ||
| 29 | if lockdown is None: | ||
| 30 | lckd = LockdownClient(dev) | ||
| 31 | else: | ||
| 32 | lckd = lockdown | ||
| 33 | port = lckd.start_service("com.apple.mobile.notification_proxy") | ||
| 34 | err = NotificationProxyError(np_client_new(dev._c_dev, port, &(self._c_client))) | ||
| 35 | if err: raise err | ||
| 36 | |||
| 37 | def __dealloc__(self): | ||
| 38 | if self._c_client is not NULL: | ||
| 39 | err = NotificationProxyError(np_client_free(self._c_client)) | ||
| 40 | if err: raise err | ||
| 41 | |||
| 42 | cpdef set_notify_callback(self, object callback): | ||
| 43 | err = NotificationProxyError(np_set_notify_callback(self._c_client, np_notify_cb, <void*>callback)) | ||
| 44 | if err: raise err | ||
| 45 | |||
| 46 | cpdef observe_notification(self, bytes notification): | ||
| 47 | err = NotificationProxyError(np_observe_notification(self._c_client, notification)) | ||
| 48 | if err: raise err | ||
| 49 | |||
| 50 | cpdef post_notification(self, bytes notification): | ||
| 51 | err = NotificationProxyError(np_post_notification(self._c_client, notification)) | ||
| 52 | if err: raise err | ||
diff --git a/cython/property_list_service.pxi b/cython/property_list_service.pxi new file mode 100644 index 0000000..9b3f694 --- /dev/null +++ b/cython/property_list_service.pxi | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | cdef class PropertyListService: | ||
| 2 | cpdef send(self, plist.Node node): | ||
| 3 | cdef plist.Node n = node | ||
| 4 | cdef BaseError err = self._send(n._c_node) | ||
| 5 | if err: raise err | ||
| 6 | |||
| 7 | cpdef plist.Node receive(self): | ||
| 8 | cdef plist.plist_t c_node = NULL | ||
| 9 | cdef BaseError err = self._receive(&c_node) | ||
| 10 | if err: raise err | ||
| 11 | |||
| 12 | return plist.plist_t_to_node(c_node) | ||
| 13 | |||
| 14 | cdef _send(self, plist.plist_t node): pass | ||
| 15 | cdef _receive(self, plist.plist_t* c_node): pass | ||
diff --git a/cython/sbservices.pxi b/cython/sbservices.pxi new file mode 100644 index 0000000..cb9de59 --- /dev/null +++ b/cython/sbservices.pxi | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | cdef extern from "libimobiledevice/sbservices.h": | ||
| 2 | cdef struct sbservices_client_int: | ||
| 3 | pass | ||
| 4 | ctypedef sbservices_client_int *sbservices_client_t | ||
| 5 | ctypedef int16_t sbservices_error_t | ||
| 6 | sbservices_error_t sbservices_client_new(idevice_t device, uint16_t port, sbservices_client_t *client) | ||
| 7 | sbservices_error_t sbservices_client_free(sbservices_client_t client) | ||
| 8 | sbservices_error_t sbservices_get_icon_state(sbservices_client_t client, plist.plist_t *state) | ||
| 9 | sbservices_error_t sbservices_set_icon_state(sbservices_client_t client, plist.plist_t newstate) | ||
| 10 | sbservices_error_t sbservices_get_icon_pngdata(sbservices_client_t client, char *bundleId, char **pngdata, uint64_t *pngsize) | ||
| 11 | |||
| 12 | cdef class SpringboardServicesError(BaseError): | ||
| 13 | pass | ||
| 14 | |||
| 15 | cdef class SpringboardServices: | ||
| 16 | cdef sbservices_client_t _c_client | ||
| 17 | |||
| 18 | def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): | ||
| 19 | cdef iDevice dev = device | ||
| 20 | cdef LockdownClient lckd | ||
| 21 | if lockdown is None: | ||
| 22 | lckd = LockdownClient(dev) | ||
| 23 | else: | ||
| 24 | lckd = lockdown | ||
| 25 | port = lockdown.start_service("com.apple.springboardservices") | ||
| 26 | err = SpringboardServicesError(sbservices_client_new(dev._c_dev, port, &(self._c_client))) | ||
| 27 | if err: raise err | ||
| 28 | |||
| 29 | def __dealloc__(self): | ||
| 30 | if self._c_client is not NULL: | ||
| 31 | err = SpringboardServicesError(sbservices_client_free(self._c_client)) | ||
| 32 | if err: raise err | ||
| 33 | |||
| 34 | property icon_state: | ||
| 35 | def __get__(self): | ||
| 36 | cdef plist.plist_t c_node = NULL | ||
| 37 | cdef plist.Node node | ||
| 38 | cdef SpringboardServicesError err = \ | ||
| 39 | SpringboardServicesError(sbservices_get_icon_state(self._c_client, &c_node)) | ||
| 40 | if err: raise err | ||
| 41 | node = plist.plist_t_to_node(c_node) | ||
| 42 | return node | ||
| 43 | def __set__(self, plist.Node newstate not None): | ||
| 44 | cdef plist.Node node = newstate | ||
| 45 | cdef SpringboardServicesError err = \ | ||
| 46 | SpringboardServicesError(sbservices_set_icon_state(self._c_client, node._c_node)) | ||
| 47 | if err: raise err | ||
| 48 | |||
| 49 | cpdef bytes get_pngdata(self, bytes bundleId): | ||
| 50 | cdef bytes result | ||
| 51 | cdef char* pngdata = NULL | ||
| 52 | cdef uint64_t pngsize | ||
| 53 | cdef SpringboardServicesError err = \ | ||
| 54 | SpringboardServicesError(sbservices_get_icon_pngdata(self._c_client, bundleId, &pngdata, &pngsize)) | ||
| 55 | if err: raise err | ||
| 56 | result = pngdata[:pngsize] | ||
| 57 | return result | ||
diff --git a/cython/stdint.pxi b/cython/stdint.pxi new file mode 100644 index 0000000..e21103f --- /dev/null +++ b/cython/stdint.pxi | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | cdef extern from *: | ||
| 2 | ctypedef unsigned char uint8_t | ||
| 3 | ctypedef short int int16_t | ||
| 4 | ctypedef unsigned short int uint16_t | ||
| 5 | ctypedef unsigned int uint32_t | ||
| 6 | ctypedef int int32_t | ||
| 7 | IF UNAME_MACHINE == 'x86_64': | ||
| 8 | ctypedef unsigned long int uint64_t | ||
| 9 | ELSE: | ||
| 10 | ctypedef unsigned long long int uint64_t | ||
