1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
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) with gil:
(<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(PropertyListService):
__service_name__ = "com.apple.mobile.installation_proxy"
cdef instproxy_client_t _c_client
def __cinit__(self, iDevice device not None, int port, *args, **kwargs):
cdef:
iDevice dev = device
instproxy_error_t err
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)
|