diff options
Diffstat (limited to 'cython/installation_proxy.pxi')
| -rw-r--r-- | cython/installation_proxy.pxi | 210 |
1 files changed, 210 insertions, 0 deletions
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 @@ | |||
| 1 | cdef extern from "libimobiledevice/installation_proxy.h": | ||
| 2 | cdef struct instproxy_client_private: | ||
| 3 | pass | ||
| 4 | ctypedef instproxy_client_private *instproxy_client_t | ||
| 5 | ctypedef void (*instproxy_status_cb_t) (const_char_ptr operation, plist.plist_t status, void *user_data) | ||
| 6 | |||
| 7 | ctypedef enum instproxy_error_t: | ||
| 8 | INSTPROXY_E_SUCCESS = 0 | ||
| 9 | INSTPROXY_E_INVALID_ARG = -1 | ||
| 10 | INSTPROXY_E_PLIST_ERROR = -2 | ||
| 11 | INSTPROXY_E_CONN_FAILED = -3 | ||
| 12 | INSTPROXY_E_OP_IN_PROGRESS = -4 | ||
| 13 | INSTPROXY_E_OP_FAILED = -5 | ||
| 14 | INSTPROXY_E_UNKNOWN_ERROR = -256 | ||
| 15 | |||
| 16 | instproxy_error_t instproxy_client_new(idevice_t device, uint16_t port, instproxy_client_t *client) | ||
| 17 | instproxy_error_t instproxy_client_free(instproxy_client_t client) | ||
| 18 | |||
| 19 | instproxy_error_t instproxy_browse(instproxy_client_t client, plist.plist_t client_options, plist.plist_t *result) | ||
| 20 | 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) | ||
| 21 | 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) | ||
| 22 | 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) | ||
| 23 | |||
| 24 | instproxy_error_t instproxy_lookup_archives(instproxy_client_t client, plist.plist_t client_options, plist.plist_t *result) | ||
| 25 | 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) | ||
| 26 | 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) | ||
| 27 | 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) | ||
| 28 | |||
| 29 | cdef void instproxy_notify_cb(const_char_ptr operation, plist.plist_t status, void *py_callback): | ||
| 30 | (<object>py_callback)(operation, plist.plist_t_to_node(status, False)) | ||
| 31 | |||
| 32 | cdef class InstallationProxyError(BaseError): | ||
| 33 | def __init__(self, *args, **kwargs): | ||
| 34 | self._lookup_table = { | ||
| 35 | INSTPROXY_E_SUCCESS: "Success", | ||
| 36 | INSTPROXY_E_INVALID_ARG: "Invalid argument", | ||
| 37 | INSTPROXY_E_PLIST_ERROR: "Property list error", | ||
| 38 | INSTPROXY_E_CONN_FAILED: "Connection failed", | ||
| 39 | INSTPROXY_E_OP_IN_PROGRESS: "Operation in progress", | ||
| 40 | INSTPROXY_E_OP_FAILED: "Operation failed", | ||
| 41 | INSTPROXY_E_UNKNOWN_ERROR: "Unknown error" | ||
| 42 | } | ||
| 43 | BaseError.__init__(self, *args, **kwargs) | ||
| 44 | |||
| 45 | cdef class InstallationProxyClient(Base): | ||
| 46 | cdef instproxy_client_t _c_client | ||
| 47 | |||
| 48 | def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): | ||
| 49 | cdef: | ||
| 50 | iDevice dev = device | ||
| 51 | LockdownClient lckd | ||
| 52 | instproxy_error_t err | ||
| 53 | if lockdown is None: | ||
| 54 | lckd = LockdownClient(dev) | ||
| 55 | else: | ||
| 56 | lckd = lockdown | ||
| 57 | port = lckd.start_service("com.apple.mobile.installation_proxy") | ||
| 58 | err = instproxy_client_new(dev._c_dev, port, &self._c_client) | ||
| 59 | self.handle_error(err) | ||
| 60 | |||
| 61 | def __dealloc__(self): | ||
| 62 | cdef instproxy_error_t err | ||
| 63 | if self._c_client is not NULL: | ||
| 64 | err = instproxy_client_free(self._c_client) | ||
| 65 | self.handle_error(err) | ||
| 66 | |||
| 67 | cpdef plist.Node browse(self, object client_options): | ||
| 68 | cdef: | ||
| 69 | plist.Node options | ||
| 70 | plist.plist_t c_options | ||
| 71 | plist.plist_t c_result = NULL | ||
| 72 | instproxy_error_t err | ||
| 73 | if isinstance(client_options, plist.Dict): | ||
| 74 | options = client_options | ||
| 75 | c_options = options._c_node | ||
| 76 | elif isinstance(client_options, dict): | ||
| 77 | c_options = plist.native_to_plist_t(client_options) | ||
| 78 | else: | ||
| 79 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) | ||
| 80 | err = instproxy_browse(self._c_client, c_options, &c_result) | ||
| 81 | self.handle_error(err) | ||
| 82 | return plist.plist_t_to_node(c_result) | ||
| 83 | |||
| 84 | cpdef install(self, bytes pkg_path, object client_options, object callback=None): | ||
| 85 | cdef: | ||
| 86 | plist.Node options | ||
| 87 | plist.plist_t c_options | ||
| 88 | instproxy_error_t err | ||
| 89 | if isinstance(client_options, plist.Dict): | ||
| 90 | options = client_options | ||
| 91 | c_options = options._c_node | ||
| 92 | elif isinstance(client_options, dict): | ||
| 93 | c_options = plist.native_to_plist_t(client_options) | ||
| 94 | else: | ||
| 95 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) | ||
| 96 | if callback is None: | ||
| 97 | err = instproxy_install(self._c_client, pkg_path, options._c_node, NULL, NULL) | ||
| 98 | else: | ||
| 99 | err = instproxy_install(self._c_client, pkg_path, options._c_node, instproxy_notify_cb, <void*>callback) | ||
| 100 | self.handle_error(err) | ||
| 101 | |||
| 102 | cpdef upgrade(self, bytes pkg_path, object client_options, object callback=None): | ||
| 103 | cdef: | ||
| 104 | plist.Node options | ||
| 105 | plist.plist_t c_options | ||
| 106 | instproxy_error_t err | ||
| 107 | if isinstance(client_options, plist.Dict): | ||
| 108 | options = client_options | ||
| 109 | c_options = options._c_node | ||
| 110 | elif isinstance(client_options, dict): | ||
| 111 | c_options = plist.native_to_plist_t(client_options) | ||
| 112 | else: | ||
| 113 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) | ||
| 114 | if callback is None: | ||
| 115 | err = instproxy_upgrade(self._c_client, pkg_path, options._c_node, NULL, NULL) | ||
| 116 | else: | ||
| 117 | err = instproxy_upgrade(self._c_client, pkg_path, options._c_node, instproxy_notify_cb, <void*>callback) | ||
| 118 | self.handle_error(err) | ||
| 119 | |||
| 120 | cpdef uninstall(self, bytes appid, object client_options, object callback=None): | ||
| 121 | cdef: | ||
| 122 | plist.Node options | ||
| 123 | plist.plist_t c_options | ||
| 124 | instproxy_error_t err | ||
| 125 | if isinstance(client_options, plist.Dict): | ||
| 126 | options = client_options | ||
| 127 | c_options = options._c_node | ||
| 128 | elif isinstance(client_options, dict): | ||
| 129 | c_options = plist.native_to_plist_t(client_options) | ||
| 130 | else: | ||
| 131 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) | ||
| 132 | if callback is None: | ||
| 133 | err = instproxy_uninstall(self._c_client, appid, options._c_node, NULL, NULL) | ||
| 134 | else: | ||
| 135 | err = instproxy_uninstall(self._c_client, appid, options._c_node, instproxy_notify_cb, <void*>callback) | ||
| 136 | self.handle_error(err) | ||
| 137 | |||
| 138 | cpdef plist.Node lookup_archives(self, object client_options): | ||
| 139 | cdef: | ||
| 140 | plist.Node options | ||
| 141 | plist.plist_t c_options | ||
| 142 | plist.plist_t c_node = NULL | ||
| 143 | instproxy_error_t err | ||
| 144 | if isinstance(client_options, plist.Dict): | ||
| 145 | options = client_options | ||
| 146 | c_options = options._c_node | ||
| 147 | elif isinstance(client_options, dict): | ||
| 148 | c_options = plist.native_to_plist_t(client_options) | ||
| 149 | else: | ||
| 150 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) | ||
| 151 | err = instproxy_lookup_archives(self._c_client, options._c_node, &c_node) | ||
| 152 | self.handle_error(err) | ||
| 153 | return plist.plist_t_to_node(c_node) | ||
| 154 | |||
| 155 | cpdef archive(self, bytes appid, object client_options, object callback=None): | ||
| 156 | cdef: | ||
| 157 | plist.Node options | ||
| 158 | plist.plist_t c_options | ||
| 159 | instproxy_error_t err | ||
| 160 | if isinstance(client_options, plist.Dict): | ||
| 161 | options = client_options | ||
| 162 | c_options = options._c_node | ||
| 163 | elif isinstance(client_options, dict): | ||
| 164 | c_options = plist.native_to_plist_t(client_options) | ||
| 165 | else: | ||
| 166 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) | ||
| 167 | if callback is None: | ||
| 168 | err = instproxy_archive(self._c_client, appid, options._c_node, NULL, NULL) | ||
| 169 | else: | ||
| 170 | err = instproxy_archive(self._c_client, appid, options._c_node, instproxy_notify_cb, <void*>callback) | ||
| 171 | self.handle_error(err) | ||
| 172 | |||
| 173 | cpdef restore(self, bytes appid, object client_options, object callback=None): | ||
| 174 | cdef: | ||
| 175 | plist.Node options | ||
| 176 | plist.plist_t c_options | ||
| 177 | instproxy_error_t err | ||
| 178 | if isinstance(client_options, plist.Dict): | ||
| 179 | options = client_options | ||
| 180 | c_options = options._c_node | ||
| 181 | elif isinstance(client_options, dict): | ||
| 182 | c_options = plist.native_to_plist_t(client_options) | ||
| 183 | else: | ||
| 184 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) | ||
| 185 | if callback is None: | ||
| 186 | err = instproxy_restore(self._c_client, appid, options._c_node, NULL, NULL) | ||
| 187 | else: | ||
| 188 | err = instproxy_restore(self._c_client, appid, options._c_node, instproxy_notify_cb, <void*>callback) | ||
| 189 | self.handle_error(err) | ||
| 190 | |||
| 191 | cpdef remove_archive(self, bytes appid, object client_options, object callback=None): | ||
| 192 | cdef: | ||
| 193 | plist.Node options | ||
| 194 | plist.plist_t c_options | ||
| 195 | instproxy_error_t err | ||
| 196 | if isinstance(client_options, plist.Dict): | ||
| 197 | options = client_options | ||
| 198 | c_options = options._c_node | ||
| 199 | elif isinstance(client_options, dict): | ||
| 200 | c_options = plist.native_to_plist_t(client_options) | ||
| 201 | else: | ||
| 202 | raise InstallationProxyError(INSTPROXY_E_INVALID_ARG) | ||
| 203 | if callback is None: | ||
| 204 | err = instproxy_remove_archive(self._c_client, appid, options._c_node, NULL, NULL) | ||
| 205 | else: | ||
| 206 | err = instproxy_remove_archive(self._c_client, appid, options._c_node, instproxy_notify_cb, <void*>callback) | ||
| 207 | self.handle_error(err) | ||
| 208 | |||
| 209 | cdef inline BaseError _error(self, int16_t ret): | ||
| 210 | return InstallationProxyError(ret) | ||
