diff options
| author | 2010-03-18 20:50:26 -0500 | |
|---|---|---|
| committer | 2012-03-20 23:25:54 +0100 | |
| commit | 7b4cb7fb2f1b1ed29f3bc97a9bcae5fc2a89fe95 (patch) | |
| tree | 4268abec171becef6befdfc5bd0a1ffc46d1962a /cython | |
| parent | 68c63cc1382326e7f0cb4e6bd863427f9069ca05 (diff) | |
| download | libimobiledevice-7b4cb7fb2f1b1ed29f3bc97a9bcae5fc2a89fe95.tar.gz libimobiledevice-7b4cb7fb2f1b1ed29f3bc97a9bcae5fc2a89fe95.tar.bz2 | |
Added afc.pxi.
More errors handled.
Changed error codes to enums in cython defs.
Diffstat (limited to 'cython')
| -rw-r--r-- | cython/Makefile.am | 15 | ||||
| -rw-r--r-- | cython/afc.pxi | 165 | ||||
| -rw-r--r-- | cython/imobiledevice.pxd | 1 | ||||
| -rw-r--r-- | cython/imobiledevice.pyx | 60 | ||||
| -rw-r--r-- | cython/mobilebackup.pxi | 14 | ||||
| -rw-r--r-- | cython/mobilesync.pxi | 14 | ||||
| -rw-r--r-- | cython/notification_proxy.pxi | 50 | ||||
| -rw-r--r-- | cython/property_list_client.pxi | 2 | ||||
| -rw-r--r-- | cython/sbservices.pxi | 47 | ||||
| -rw-r--r-- | cython/stdint.pxi | 2 |
10 files changed, 283 insertions, 87 deletions
diff --git a/cython/Makefile.am b/cython/Makefile.am index 1a71fbe..c0ebff6 100644 --- a/cython/Makefile.am +++ b/cython/Makefile.am | |||
| @@ -7,13 +7,14 @@ 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 | 9 | PXDINCLUDES = imobiledevice.pxd stdint.pxi $(CYTHON_PLIST_INCLUDE_DIR)/plist.pxd |
| 10 | PXIINCLUDES = \ | 10 | PXIINCLUDES = \ |
| 11 | stdint.pxi \ | 11 | stdint.pxi \ |
| 12 | mobilesync.pxi \ | 12 | mobilesync.pxi \ |
| 13 | notification_proxy.pxi \ | 13 | notification_proxy.pxi \ |
| 14 | sbservices.pxi \ | 14 | sbservices.pxi \ |
| 15 | mobilebackup.pxi \ | 15 | mobilebackup.pxi \ |
| 16 | property_list_client.pxi | 16 | property_list_client.pxi \ |
| 17 | afc.pxi | ||
| 17 | 18 | ||
| 18 | CLEANFILES = \ | 19 | CLEANFILES = \ |
| 19 | *.pyc \ | 20 | *.pyc \ |
diff --git a/cython/afc.pxi b/cython/afc.pxi new file mode 100644 index 0000000..51251c8 --- /dev/null +++ b/cython/afc.pxi | |||
| @@ -0,0 +1,165 @@ | |||
| 1 | cdef extern from "libimobiledevice/afc.h": | ||
| 2 | cdef struct afc_client_int: | ||
| 3 | pass | ||
| 4 | ctypedef afc_client_int *afc_client_t | ||
| 5 | ctypedef enum afc_error_t: | ||
| 6 | AFC_E_SUCCESS = 0 | ||
| 7 | AFC_E_UNKNOWN_ERROR = 1 | ||
| 8 | AFC_E_OP_HEADER_INVALID = 2 | ||
| 9 | AFC_E_NO_RESOURCES = 3 | ||
| 10 | AFC_E_READ_ERROR = 4 | ||
| 11 | AFC_E_WRITE_ERROR = 5 | ||
| 12 | AFC_E_UNKNOWN_PACKET_TYPE = 6 | ||
| 13 | AFC_E_INVALID_ARGUMENT = 7 | ||
| 14 | AFC_E_OBJECT_NOT_FOUND = 8 | ||
| 15 | AFC_E_OBJECT_IS_DIR = 9 | ||
| 16 | AFC_E_PERM_DENIED = 10 | ||
| 17 | AFC_E_SERVICE_NOT_CONNECTED = 11 | ||
| 18 | AFC_E_OP_TIMEOUT = 12 | ||
| 19 | AFC_E_TOO_MUCH_DATA = 13 | ||
| 20 | AFC_E_END_OF_DATA = 14 | ||
| 21 | AFC_E_OP_NOT_SUPPORTED = 15 | ||
| 22 | AFC_E_OBJECT_EXISTS = 16 | ||
| 23 | AFC_E_OBJECT_BUSY = 17 | ||
| 24 | AFC_E_NO_SPACE_LEFT = 18 | ||
| 25 | AFC_E_OP_WOULD_BLOCK = 19 | ||
| 26 | AFC_E_IO_ERROR = 20 | ||
| 27 | AFC_E_OP_INTERRUPTED = 21 | ||
| 28 | AFC_E_OP_IN_PROGRESS = 22 | ||
| 29 | AFC_E_INTERNAL_ERROR = 23 | ||
| 30 | AFC_E_MUX_ERROR = 30 | ||
| 31 | AFC_E_NO_MEM = 31 | ||
| 32 | AFC_E_NOT_ENOUGH_DATA = 32 | ||
| 33 | AFC_E_DIR_NOT_EMPTY = 33 | ||
| 34 | ctypedef enum afc_file_mode_t: | ||
| 35 | AFC_FOPEN_RDONLY = 0x00000001 | ||
| 36 | AFC_FOPEN_RW = 0x00000002 | ||
| 37 | AFC_FOPEN_WRONLY = 0x00000003 | ||
| 38 | AFC_FOPEN_WR = 0x00000004 | ||
| 39 | AFC_FOPEN_APPEND = 0x00000005 | ||
| 40 | AFC_FOPEN_RDAPPEND = 0x00000006 | ||
| 41 | ctypedef enum afc_link_type_t: | ||
| 42 | AFC_HARDLINK = 1 | ||
| 43 | AFC_SYMLINK = 2 | ||
| 44 | ctypedef enum afc_lock_op_t: | ||
| 45 | AFC_LOCK_SH = 1 | 4 | ||
| 46 | AFC_LOCK_EX = 2 | 4 | ||
| 47 | AFC_LOCK_UN = 8 | 4 | ||
| 48 | |||
| 49 | afc_error_t afc_client_new(idevice_t device, uint16_t port, afc_client_t *client) | ||
| 50 | afc_error_t afc_client_free(afc_client_t client) | ||
| 51 | afc_error_t afc_get_device_info(afc_client_t client, char ***infos) | ||
| 52 | afc_error_t afc_read_directory(afc_client_t client, char *dir, char ***list) | ||
| 53 | afc_error_t afc_get_file_info(afc_client_t client, char *filename, char ***infolist) | ||
| 54 | afc_error_t afc_file_open(afc_client_t client, char *filename, afc_file_mode_t file_mode, uint64_t *handle) | ||
| 55 | afc_error_t afc_file_close(afc_client_t client, uint64_t handle) | ||
| 56 | afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t operation) | ||
| 57 | afc_error_t afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, uint32_t *bytes_read) | ||
| 58 | afc_error_t afc_file_write(afc_client_t client, uint64_t handle, char *data, uint32_t length, uint32_t *bytes_written) | ||
| 59 | afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence) | ||
| 60 | afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position) | ||
| 61 | afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize) | ||
| 62 | afc_error_t afc_remove_path(afc_client_t client, char *path) | ||
| 63 | afc_error_t afc_rename_path(afc_client_t client, char *f, char *to) | ||
| 64 | afc_error_t afc_make_directory(afc_client_t client, char *dir) | ||
| 65 | afc_error_t afc_truncate(afc_client_t client, char *path, uint64_t newsize) | ||
| 66 | afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, char *target, char *linkname) | ||
| 67 | afc_error_t afc_set_file_time(afc_client_t client, char *path, uint64_t mtime) | ||
| 68 | |||
| 69 | cdef extern from *: | ||
| 70 | void free(void *ptr) | ||
| 71 | |||
| 72 | cdef class AfcError(BaseError): | ||
| 73 | def __init__(self, *args, **kwargs): | ||
| 74 | self._lookup_table = { | ||
| 75 | AFC_E_SUCCESS: "Success", | ||
| 76 | AFC_E_UNKNOWN_ERROR: "Unknown error", | ||
| 77 | AFC_E_OP_HEADER_INVALID: "OP header invalid", | ||
| 78 | AFC_E_NO_RESOURCES: "No resources", | ||
| 79 | AFC_E_READ_ERROR: "Read error", | ||
| 80 | AFC_E_WRITE_ERROR: "Write error", | ||
| 81 | AFC_E_UNKNOWN_PACKET_TYPE: "Unknown packet type", | ||
| 82 | AFC_E_INVALID_ARGUMENT: "Invalid argument", | ||
| 83 | AFC_E_OBJECT_NOT_FOUND: "Object not found", | ||
| 84 | AFC_E_OBJECT_IS_DIR: "Object is directory", | ||
| 85 | AFC_E_PERM_DENIED: "Permission denied", | ||
| 86 | AFC_E_SERVICE_NOT_CONNECTED: "Service not connected", | ||
| 87 | AFC_E_OP_TIMEOUT: "OP timeout", | ||
| 88 | AFC_E_TOO_MUCH_DATA: "Too much data", | ||
| 89 | AFC_E_END_OF_DATA: "End of data", | ||
| 90 | AFC_E_OP_NOT_SUPPORTED: "OP not supported", | ||
| 91 | AFC_E_OBJECT_EXISTS: "Object exists", | ||
| 92 | AFC_E_OBJECT_BUSY: "Object busy", | ||
| 93 | AFC_E_NO_SPACE_LEFT: "No space left", | ||
| 94 | AFC_E_OP_WOULD_BLOCK: "OP would block", | ||
| 95 | AFC_E_IO_ERROR: "IO error", | ||
| 96 | AFC_E_OP_INTERRUPTED: "OP interrupted", | ||
| 97 | AFC_E_OP_IN_PROGRESS: "OP in progress", | ||
| 98 | AFC_E_INTERNAL_ERROR: "Internal error", | ||
| 99 | AFC_E_MUX_ERROR: "MUX error", | ||
| 100 | AFC_E_NO_MEM: "No memory", | ||
| 101 | AFC_E_NOT_ENOUGH_DATA: "Not enough data", | ||
| 102 | AFC_E_DIR_NOT_EMPTY: "Directory not empty" | ||
| 103 | } | ||
| 104 | BaseError.__init__(self, *args, **kwargs) | ||
| 105 | |||
| 106 | cdef class AfcClient(Base): | ||
| 107 | cdef afc_client_t _c_client | ||
| 108 | |||
| 109 | def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): | ||
| 110 | cdef: | ||
| 111 | iDevice dev = device | ||
| 112 | LockdownClient lckd | ||
| 113 | afc_error_t err | ||
| 114 | if lockdown is None: | ||
| 115 | lckd = LockdownClient(dev) | ||
| 116 | else: | ||
| 117 | lckd = lockdown | ||
| 118 | port = lckd.start_service("com.apple.afc") | ||
| 119 | err = afc_client_new(dev._c_dev, port, &(self._c_client)) | ||
| 120 | self.handle_error(err) | ||
| 121 | |||
| 122 | def __dealloc__(self): | ||
| 123 | cdef afc_error_t err | ||
| 124 | if self._c_client is not NULL: | ||
| 125 | err = afc_client_free(self._c_client) | ||
| 126 | self.handle_error(err) | ||
| 127 | |||
| 128 | cdef inline BaseError _error(self, int16_t ret): | ||
| 129 | return AfcError(ret) | ||
| 130 | |||
| 131 | cpdef list get_device_info(self): | ||
| 132 | cdef: | ||
| 133 | afc_error_t err | ||
| 134 | char** infos | ||
| 135 | bytes info | ||
| 136 | int i = 0 | ||
| 137 | list result = [] | ||
| 138 | err = afc_get_device_info(self._c_client, &infos) | ||
| 139 | self.handle_error(err) | ||
| 140 | while infos[i]: | ||
| 141 | info = infos[i] | ||
| 142 | result.append(info) | ||
| 143 | free(infos[i]) | ||
| 144 | i = i + 1 | ||
| 145 | free(infos) | ||
| 146 | |||
| 147 | return result | ||
| 148 | |||
| 149 | cpdef list read_directory(self, bytes directory): | ||
| 150 | cdef: | ||
| 151 | afc_error_t err | ||
| 152 | char** dir_list | ||
| 153 | bytes f | ||
| 154 | int i = 0 | ||
| 155 | list result = [] | ||
| 156 | err = afc_read_directory(self._c_client, directory, &dir_list) | ||
| 157 | self.handle_error(err) | ||
| 158 | while dir_list[i]: | ||
| 159 | f = dir_list[i] | ||
| 160 | result.append(f) | ||
| 161 | free(dir_list[i]) | ||
| 162 | i = i + 1 | ||
| 163 | free(dir_list) | ||
| 164 | |||
| 165 | return result | ||
diff --git a/cython/imobiledevice.pxd b/cython/imobiledevice.pxd index 0557d37..8a7d6b2 100644 --- a/cython/imobiledevice.pxd +++ b/cython/imobiledevice.pxd | |||
| @@ -20,7 +20,6 @@ cdef extern from "libimobiledevice/libimobiledevice.h": | |||
| 20 | cdef struct idevice_int: | 20 | cdef struct idevice_int: |
| 21 | pass | 21 | pass |
| 22 | ctypedef idevice_int* idevice_t | 22 | ctypedef idevice_int* idevice_t |
| 23 | ctypedef int16_t idevice_error_t | ||
| 24 | cdef enum idevice_event_type: | 23 | cdef enum idevice_event_type: |
| 25 | IDEVICE_DEVICE_ADD = 1, | 24 | IDEVICE_DEVICE_ADD = 1, |
| 26 | IDEVICE_DEVICE_REMOVE | 25 | IDEVICE_DEVICE_REMOVE |
diff --git a/cython/imobiledevice.pyx b/cython/imobiledevice.pyx index c6a96dd..ecf94e1 100644 --- a/cython/imobiledevice.pyx +++ b/cython/imobiledevice.pyx | |||
| @@ -30,13 +30,14 @@ cdef class Base: | |||
| 30 | cdef inline BaseError _error(self, int16_t ret): pass | 30 | cdef inline BaseError _error(self, int16_t ret): pass |
| 31 | 31 | ||
| 32 | cdef extern from "libimobiledevice/libimobiledevice.h": | 32 | cdef extern from "libimobiledevice/libimobiledevice.h": |
| 33 | int16_t IDEVICE_E_SUCCESS | 33 | ctypedef enum idevice_error_t: |
| 34 | int16_t IDEVICE_E_INVALID_ARG | 34 | IDEVICE_E_SUCCESS = 0 |
| 35 | int16_t IDEVICE_E_UNKNOWN_ERROR | 35 | IDEVICE_E_INVALID_ARG = -1 |
| 36 | int16_t IDEVICE_E_NO_DEVICE | 36 | IDEVICE_E_UNKNOWN_ERROR = -2 |
| 37 | int16_t IDEVICE_E_NOT_ENOUGH_DATA | 37 | IDEVICE_E_NO_DEVICE = -3 |
| 38 | int16_t IDEVICE_E_BAD_HEADER | 38 | IDEVICE_E_NOT_ENOUGH_DATA = -4 |
| 39 | int16_t IDEVICE_E_SSL_ERROR | 39 | IDEVICE_E_BAD_HEADER = -5 |
| 40 | IDEVICE_E_SSL_ERROR = -6 | ||
| 40 | ctypedef void (*idevice_event_cb_t) (const_idevice_event_t event, void *user_data) | 41 | ctypedef void (*idevice_event_cb_t) (const_idevice_event_t event, void *user_data) |
| 41 | cdef extern idevice_error_t idevice_event_subscribe(idevice_event_cb_t callback, void *user_data) | 42 | cdef extern idevice_error_t idevice_event_subscribe(idevice_event_cb_t callback, void *user_data) |
| 42 | cdef extern idevice_error_t idevice_event_unsubscribe() | 43 | cdef extern idevice_error_t idevice_event_unsubscribe() |
| @@ -49,7 +50,7 @@ cdef extern from "libimobiledevice/libimobiledevice.h": | |||
| 49 | idevice_error_t idevice_get_handle(idevice_t device, uint32_t *handle) | 50 | idevice_error_t idevice_get_handle(idevice_t device, uint32_t *handle) |
| 50 | 51 | ||
| 51 | cdef class iDeviceError(BaseError): | 52 | cdef class iDeviceError(BaseError): |
| 52 | def __cinit__(self, *args, **kwargs): | 53 | def __init__(self, *args, **kwargs): |
| 53 | self._lookup_table = { | 54 | self._lookup_table = { |
| 54 | IDEVICE_E_SUCCESS: 'Success', | 55 | IDEVICE_E_SUCCESS: 'Success', |
| 55 | IDEVICE_E_INVALID_ARG: 'Invalid argument', | 56 | IDEVICE_E_INVALID_ARG: 'Invalid argument', |
| @@ -133,27 +134,27 @@ cdef extern from "libimobiledevice/lockdown.h": | |||
| 133 | cdef struct lockdownd_client_int: | 134 | cdef struct lockdownd_client_int: |
| 134 | pass | 135 | pass |
| 135 | ctypedef lockdownd_client_int *lockdownd_client_t | 136 | ctypedef lockdownd_client_int *lockdownd_client_t |
| 136 | ctypedef int16_t lockdownd_error_t | 137 | ctypedef enum lockdownd_error_t: |
| 137 | int16_t LOCKDOWN_E_SUCCESS | 138 | LOCKDOWN_E_SUCCESS = 0 |
| 138 | int16_t LOCKDOWN_E_INVALID_ARG | 139 | LOCKDOWN_E_INVALID_ARG = -1 |
| 139 | int16_t LOCKDOWN_E_INVALID_CONF | 140 | LOCKDOWN_E_INVALID_CONF = -2 |
| 140 | int16_t LOCKDOWN_E_PLIST_ERROR | 141 | LOCKDOWN_E_PLIST_ERROR = -3 |
| 141 | int16_t LOCKDOWN_E_PAIRING_FAILED | 142 | LOCKDOWN_E_PAIRING_FAILED = -4 |
| 142 | int16_t LOCKDOWN_E_SSL_ERROR | 143 | LOCKDOWN_E_SSL_ERROR = -5 |
| 143 | int16_t LOCKDOWN_E_DICT_ERROR | 144 | LOCKDOWN_E_DICT_ERROR = -6 |
| 144 | int16_t LOCKDOWN_E_START_SERVICE_FAILED | 145 | LOCKDOWN_E_START_SERVICE_FAILED = -7 |
| 145 | int16_t LOCKDOWN_E_NOT_ENOUGH_DATA | 146 | LOCKDOWN_E_NOT_ENOUGH_DATA = -8 |
| 146 | int16_t LOCKDOWN_E_SET_VALUE_PROHIBITED | 147 | LOCKDOWN_E_SET_VALUE_PROHIBITED = -9 |
| 147 | int16_t LOCKDOWN_E_GET_VALUE_PROHIBITED | 148 | LOCKDOWN_E_GET_VALUE_PROHIBITED = -10 |
| 148 | int16_t LOCKDOWN_E_REMOVE_VALUE_PROHIBITED | 149 | LOCKDOWN_E_REMOVE_VALUE_PROHIBITED = -11 |
| 149 | int16_t LOCKDOWN_E_MUX_ERROR | 150 | LOCKDOWN_E_MUX_ERROR = -12 |
| 150 | int16_t LOCKDOWN_E_ACTIVATION_FAILED | 151 | LOCKDOWN_E_ACTIVATION_FAILED = -13 |
| 151 | int16_t LOCKDOWN_E_PASSWORD_PROTECTED | 152 | LOCKDOWN_E_PASSWORD_PROTECTED = -14 |
| 152 | int16_t LOCKDOWN_E_NO_RUNNING_SESSION | 153 | LOCKDOWN_E_NO_RUNNING_SESSION = -15 |
| 153 | int16_t LOCKDOWN_E_INVALID_HOST_ID | 154 | LOCKDOWN_E_INVALID_HOST_ID = -16 |
| 154 | int16_t LOCKDOWN_E_INVALID_SERVICE | 155 | LOCKDOWN_E_INVALID_SERVICE = -17 |
| 155 | int16_t LOCKDOWN_E_INVALID_ACTIVATION_RECORD | 156 | LOCKDOWN_E_INVALID_ACTIVATION_RECORD = -18 |
| 156 | int16_t LOCKDOWN_E_UNKNOWN_ERROR | 157 | LOCKDOWN_E_UNKNOWN_ERROR = -256 |
| 157 | 158 | ||
| 158 | lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdownd_client_t *client, char *label) | 159 | lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdownd_client_t *client, char *label) |
| 159 | lockdownd_error_t lockdownd_client_free(lockdownd_client_t client) | 160 | lockdownd_error_t lockdownd_client_free(lockdownd_client_t client) |
| @@ -217,3 +218,4 @@ include "mobilesync.pxi" | |||
| 217 | include "notification_proxy.pxi" | 218 | include "notification_proxy.pxi" |
| 218 | include "sbservices.pxi" | 219 | include "sbservices.pxi" |
| 219 | include "mobilebackup.pxi" | 220 | include "mobilebackup.pxi" |
| 221 | include "afc.pxi" | ||
diff --git a/cython/mobilebackup.pxi b/cython/mobilebackup.pxi index f6b13a9..53a4b6f 100644 --- a/cython/mobilebackup.pxi +++ b/cython/mobilebackup.pxi | |||
| @@ -3,13 +3,13 @@ cdef extern from "libimobiledevice/mobilebackup.h": | |||
| 3 | pass | 3 | pass |
| 4 | ctypedef mobilebackup_client_int *mobilebackup_client_t | 4 | ctypedef mobilebackup_client_int *mobilebackup_client_t |
| 5 | 5 | ||
| 6 | ctypedef int16_t mobilebackup_error_t | 6 | ctypedef enum mobilebackup_error_t: |
| 7 | int16_t MOBILEBACKUP_E_SUCCESS | 7 | MOBILEBACKUP_E_SUCCESS = 0 |
| 8 | int16_t MOBILEBACKUP_E_INVALID_ARG | 8 | MOBILEBACKUP_E_INVALID_ARG = -1 |
| 9 | int16_t MOBILEBACKUP_E_PLIST_ERROR | 9 | MOBILEBACKUP_E_PLIST_ERROR = -2 |
| 10 | int16_t MOBILEBACKUP_E_MUX_ERROR | 10 | MOBILEBACKUP_E_MUX_ERROR = -3 |
| 11 | int16_t MOBILEBACKUP_E_BAD_VERSION | 11 | MOBILEBACKUP_E_BAD_VERSION = -4 |
| 12 | int16_t MOBILEBACKUP_E_UNKNOWN_ERROR | 12 | MOBILEBACKUP_E_UNKNOWN_ERROR = -256 |
| 13 | 13 | ||
| 14 | mobilebackup_error_t mobilebackup_client_new(idevice_t device, uint16_t port, mobilebackup_client_t * client) | 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) | 15 | mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client) |
diff --git a/cython/mobilesync.pxi b/cython/mobilesync.pxi index abd56b4..87539d2 100644 --- a/cython/mobilesync.pxi +++ b/cython/mobilesync.pxi | |||
| @@ -3,13 +3,13 @@ cdef extern from "libimobiledevice/mobilesync.h": | |||
| 3 | pass | 3 | pass |
| 4 | ctypedef mobilesync_client_int *mobilesync_client_t | 4 | ctypedef mobilesync_client_int *mobilesync_client_t |
| 5 | 5 | ||
| 6 | ctypedef int16_t mobilesync_error_t | 6 | ctypedef enum mobilesync_error_t: |
| 7 | int16_t MOBILESYNC_E_SUCCESS | 7 | MOBILESYNC_E_SUCCESS = 0 |
| 8 | int16_t MOBILESYNC_E_INVALID_ARG | 8 | MOBILESYNC_E_INVALID_ARG = -1 |
| 9 | int16_t MOBILESYNC_E_PLIST_ERROR | 9 | MOBILESYNC_E_PLIST_ERROR = -2 |
| 10 | int16_t MOBILESYNC_E_MUX_ERROR | 10 | MOBILESYNC_E_MUX_ERROR = -3 |
| 11 | int16_t MOBILESYNC_E_BAD_VERSION | 11 | MOBILESYNC_E_BAD_VERSION = -4 |
| 12 | int16_t MOBILESYNC_E_UNKNOWN_ERROR | 12 | MOBILESYNC_E_UNKNOWN_ERROR = -256 |
| 13 | 13 | ||
| 14 | mobilesync_error_t mobilesync_client_new(idevice_t device, uint16_t port, mobilesync_client_t * client) | 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) | 15 | mobilesync_error_t mobilesync_client_free(mobilesync_client_t client) |
diff --git a/cython/notification_proxy.pxi b/cython/notification_proxy.pxi index acccf7d..2ca484a 100644 --- a/cython/notification_proxy.pxi +++ b/cython/notification_proxy.pxi | |||
| @@ -5,7 +5,12 @@ cdef extern from "libimobiledevice/notification_proxy.h": | |||
| 5 | cdef struct np_client_int: | 5 | cdef struct np_client_int: |
| 6 | pass | 6 | pass |
| 7 | ctypedef np_client_int *np_client_t | 7 | ctypedef np_client_int *np_client_t |
| 8 | ctypedef int16_t np_error_t | 8 | ctypedef enum np_error_t: |
| 9 | NP_E_SUCCESS = 0 | ||
| 10 | NP_E_INVALID_ARG = -1 | ||
| 11 | NP_E_PLIST_ERROR = -2 | ||
| 12 | NP_E_CONN_FAILED = -3 | ||
| 13 | NP_E_UNKNOWN_ERROR = -256 | ||
| 9 | ctypedef void (*np_notify_cb_t) (const_char_ptr notification, void *userdata) | 14 | 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) | 15 | 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) | 16 | np_error_t np_client_free(np_client_t client) |
| @@ -18,35 +23,46 @@ cdef void np_notify_cb(const_char_ptr notification, void *py_callback): | |||
| 18 | (<object>py_callback)(notification) | 23 | (<object>py_callback)(notification) |
| 19 | 24 | ||
| 20 | cdef class NotificationProxyError(BaseError): | 25 | cdef class NotificationProxyError(BaseError): |
| 21 | pass | 26 | def __init__(self, *args, **kwargs): |
| 27 | self._lookup_table = { | ||
| 28 | NP_E_SUCCESS: "Success", | ||
| 29 | NP_E_INVALID_ARG: "Invalid argument", | ||
| 30 | NP_E_PLIST_ERROR: "PList Error", | ||
| 31 | NP_E_CONN_FAILED: "Connection Failed", | ||
| 32 | NP_E_UNKNOWN_ERROR: "Unknown Error" | ||
| 33 | } | ||
| 34 | BaseError.__init__(self, *args, **kwargs) | ||
| 22 | 35 | ||
| 23 | cdef class NotificationProxy: | 36 | cdef class NotificationProxy(Base): |
| 24 | cdef np_client_t _c_client | 37 | cdef np_client_t _c_client |
| 25 | 38 | ||
| 26 | def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): | 39 | def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): |
| 27 | cdef iDevice dev = device | 40 | cdef: |
| 28 | cdef LockdownClient lckd | 41 | iDevice dev = device |
| 42 | LockdownClient lckd | ||
| 43 | np_error_t err | ||
| 29 | if lockdown is None: | 44 | if lockdown is None: |
| 30 | lckd = LockdownClient(dev) | 45 | lckd = LockdownClient(dev) |
| 31 | else: | 46 | else: |
| 32 | lckd = lockdown | 47 | lckd = lockdown |
| 33 | port = lckd.start_service("com.apple.mobile.notification_proxy") | 48 | port = lckd.start_service("com.apple.mobile.notification_proxy") |
| 34 | err = NotificationProxyError(np_client_new(dev._c_dev, port, &(self._c_client))) | 49 | err = np_client_new(dev._c_dev, port, &self._c_client) |
| 35 | if err: raise err | 50 | self.handle_error(err) |
| 36 | 51 | ||
| 37 | def __dealloc__(self): | 52 | def __dealloc__(self): |
| 53 | cdef np_error_t err | ||
| 38 | if self._c_client is not NULL: | 54 | if self._c_client is not NULL: |
| 39 | err = NotificationProxyError(np_client_free(self._c_client)) | 55 | err = np_client_free(self._c_client) |
| 40 | if err: raise err | 56 | self.handle_error(err) |
| 41 | 57 | ||
| 58 | cdef inline BaseError _error(self, int16_t ret): | ||
| 59 | return NotificationProxyError(ret) | ||
| 60 | |||
| 42 | cpdef set_notify_callback(self, object callback): | 61 | cpdef set_notify_callback(self, object callback): |
| 43 | err = NotificationProxyError(np_set_notify_callback(self._c_client, np_notify_cb, <void*>callback)) | 62 | self.handle_error(np_set_notify_callback(self._c_client, np_notify_cb, <void*>callback)) |
| 44 | if err: raise err | 63 | |
| 45 | |||
| 46 | cpdef observe_notification(self, bytes notification): | 64 | cpdef observe_notification(self, bytes notification): |
| 47 | err = NotificationProxyError(np_observe_notification(self._c_client, notification)) | 65 | self.handle_error(np_observe_notification(self._c_client, notification)) |
| 48 | if err: raise err | ||
| 49 | 66 | ||
| 50 | cpdef post_notification(self, bytes notification): | 67 | cpdef post_notification(self, bytes notification): |
| 51 | err = NotificationProxyError(np_post_notification(self._c_client, notification)) | 68 | self.handle_error(np_post_notification(self._c_client, notification)) |
| 52 | if err: raise err | ||
diff --git a/cython/property_list_client.pxi b/cython/property_list_client.pxi index 2689658..874f2b5 100644 --- a/cython/property_list_client.pxi +++ b/cython/property_list_client.pxi | |||
| @@ -3,7 +3,7 @@ cdef class PropertyListClient(Base): | |||
| 3 | cdef plist.Node n = node | 3 | cdef plist.Node n = node |
| 4 | self.handle_error(self._send(n._c_node)) | 4 | self.handle_error(self._send(n._c_node)) |
| 5 | 5 | ||
| 6 | cpdef plist.Node receive(self): | 6 | cpdef object receive(self): |
| 7 | cdef plist.plist_t c_node = NULL | 7 | cdef plist.plist_t c_node = NULL |
| 8 | self.handle_error(self._receive(&c_node)) | 8 | self.handle_error(self._receive(&c_node)) |
| 9 | 9 | ||
diff --git a/cython/sbservices.pxi b/cython/sbservices.pxi index cb9de59..384c92b 100644 --- a/cython/sbservices.pxi +++ b/cython/sbservices.pxi | |||
| @@ -2,7 +2,12 @@ cdef extern from "libimobiledevice/sbservices.h": | |||
| 2 | cdef struct sbservices_client_int: | 2 | cdef struct sbservices_client_int: |
| 3 | pass | 3 | pass |
| 4 | ctypedef sbservices_client_int *sbservices_client_t | 4 | ctypedef sbservices_client_int *sbservices_client_t |
| 5 | ctypedef int16_t sbservices_error_t | 5 | ctypedef enum sbservices_error_t: |
| 6 | SBSERVICES_E_SUCCESS = 0 | ||
| 7 | SBSERVICES_E_INVALID_ARG = -1 | ||
| 8 | SBSERVICES_E_PLIST_ERROR = -2 | ||
| 9 | SBSERVICES_E_CONN_FAILED = -3 | ||
| 10 | SBSERVICES_E_UNKNOWN_ERROR = -256 | ||
| 6 | sbservices_error_t sbservices_client_new(idevice_t device, uint16_t port, sbservices_client_t *client) | 11 | 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) | 12 | 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) | 13 | sbservices_error_t sbservices_get_icon_state(sbservices_client_t client, plist.plist_t *state) |
| @@ -10,7 +15,15 @@ cdef extern from "libimobiledevice/sbservices.h": | |||
| 10 | sbservices_error_t sbservices_get_icon_pngdata(sbservices_client_t client, char *bundleId, char **pngdata, uint64_t *pngsize) | 15 | sbservices_error_t sbservices_get_icon_pngdata(sbservices_client_t client, char *bundleId, char **pngdata, uint64_t *pngsize) |
| 11 | 16 | ||
| 12 | cdef class SpringboardServicesError(BaseError): | 17 | cdef class SpringboardServicesError(BaseError): |
| 13 | pass | 18 | def __init__(self, *args, **kwargs): |
| 19 | self._lookup_table = { | ||
| 20 | SBSERVICES_E_SUCCESS: "Success", | ||
| 21 | SBSERVICES_E_INVALID_ARG: "Invalid argument", | ||
| 22 | SBSERVICES_E_PLIST_ERROR: "PList Error", | ||
| 23 | SBSERVICES_E_CONN_FAILED: "Connection Failed", | ||
| 24 | SBSERVICES_E_UNKNOWN_ERROR: "Unknown Error" | ||
| 25 | } | ||
| 26 | BaseError.__init__(self, *args, **kwargs) | ||
| 14 | 27 | ||
| 15 | cdef class SpringboardServices: | 28 | cdef class SpringboardServices: |
| 16 | cdef sbservices_client_t _c_client | 29 | cdef sbservices_client_t _c_client |
| @@ -23,35 +36,33 @@ cdef class SpringboardServices: | |||
| 23 | else: | 36 | else: |
| 24 | lckd = lockdown | 37 | lckd = lockdown |
| 25 | port = lockdown.start_service("com.apple.springboardservices") | 38 | port = lockdown.start_service("com.apple.springboardservices") |
| 26 | err = SpringboardServicesError(sbservices_client_new(dev._c_dev, port, &(self._c_client))) | 39 | self.handle_error(sbservices_client_new(dev._c_dev, port, &(self._c_client))) |
| 27 | if err: raise err | ||
| 28 | 40 | ||
| 29 | def __dealloc__(self): | 41 | def __dealloc__(self): |
| 30 | if self._c_client is not NULL: | 42 | if self._c_client is not NULL: |
| 31 | err = SpringboardServicesError(sbservices_client_free(self._c_client)) | 43 | err = SpringboardServicesError(sbservices_client_free(self._c_client)) |
| 32 | if err: raise err | 44 | if err: raise err |
| 33 | 45 | ||
| 46 | cdef inline BaseError _error(self, int16_t ret): | ||
| 47 | return SpringboardServicesError(ret) | ||
| 48 | |||
| 34 | property icon_state: | 49 | property icon_state: |
| 35 | def __get__(self): | 50 | def __get__(self): |
| 36 | cdef plist.plist_t c_node = NULL | 51 | cdef: |
| 37 | cdef plist.Node node | 52 | plist.plist_t c_node = NULL |
| 38 | cdef SpringboardServicesError err = \ | 53 | plist.Node node |
| 39 | SpringboardServicesError(sbservices_get_icon_state(self._c_client, &c_node)) | 54 | self.handle_error(sbservices_get_icon_state(self._c_client, &c_node)) |
| 40 | if err: raise err | ||
| 41 | node = plist.plist_t_to_node(c_node) | 55 | node = plist.plist_t_to_node(c_node) |
| 42 | return node | 56 | return node |
| 43 | def __set__(self, plist.Node newstate not None): | 57 | def __set__(self, plist.Node newstate not None): |
| 44 | cdef plist.Node node = newstate | 58 | cdef plist.Node node = newstate |
| 45 | cdef SpringboardServicesError err = \ | 59 | self.handle_error(sbservices_set_icon_state(self._c_client, node._c_node)) |
| 46 | SpringboardServicesError(sbservices_set_icon_state(self._c_client, node._c_node)) | ||
| 47 | if err: raise err | ||
| 48 | 60 | ||
| 49 | cpdef bytes get_pngdata(self, bytes bundleId): | 61 | cpdef bytes get_pngdata(self, bytes bundleId): |
| 50 | cdef bytes result | 62 | cdef: |
| 51 | cdef char* pngdata = NULL | 63 | bytes result |
| 52 | cdef uint64_t pngsize | 64 | char* pngdata = NULL |
| 53 | cdef SpringboardServicesError err = \ | 65 | uint64_t pngsize |
| 54 | SpringboardServicesError(sbservices_get_icon_pngdata(self._c_client, bundleId, &pngdata, &pngsize)) | 66 | self.handle_error(sbservices_get_icon_pngdata(self._c_client, bundleId, &pngdata, &pngsize)) |
| 55 | if err: raise err | ||
| 56 | result = pngdata[:pngsize] | 67 | result = pngdata[:pngsize] |
| 57 | return result | 68 | return result |
diff --git a/cython/stdint.pxi b/cython/stdint.pxi index e21103f..2617dec 100644 --- a/cython/stdint.pxi +++ b/cython/stdint.pxi | |||
| @@ -5,6 +5,8 @@ cdef extern from *: | |||
| 5 | ctypedef unsigned int uint32_t | 5 | ctypedef unsigned int uint32_t |
| 6 | ctypedef int int32_t | 6 | ctypedef int int32_t |
| 7 | IF UNAME_MACHINE == 'x86_64': | 7 | IF UNAME_MACHINE == 'x86_64': |
| 8 | ctypedef long int int64_t | ||
| 8 | ctypedef unsigned long int uint64_t | 9 | ctypedef unsigned long int uint64_t |
| 9 | ELSE: | 10 | ELSE: |
| 11 | ctypedef long long int int64_t | ||
| 10 | ctypedef unsigned long long int uint64_t | 12 | ctypedef unsigned long long int uint64_t |
