summaryrefslogtreecommitdiffstats
path: root/cython/imobiledevice.pyx
diff options
context:
space:
mode:
authorGravatar Bryan Forbes2010-04-09 16:52:30 -0500
committerGravatar Martin Szulecki2012-03-20 23:25:55 +0100
commitbea5efe442daeab05d5d7a2e9d9e7b934ba6e684 (patch)
tree0346eebd799517c0976e640db7241d0c72cf7d95 /cython/imobiledevice.pyx
parentacac4f819ccafa6f6bb945626f2e21ec2b75074b (diff)
downloadlibimobiledevice-bea5efe442daeab05d5d7a2e9d9e7b934ba6e684.tar.gz
libimobiledevice-bea5efe442daeab05d5d7a2e9d9e7b934ba6e684.tar.bz2
Implemented hierarchy suggested by Martin S.
Implemented new BaseService constructors. Moved LockdownClient to lockdown.pxi. Implemented more of the afc interface.
Diffstat (limited to 'cython/imobiledevice.pyx')
-rw-r--r--cython/imobiledevice.pyx117
1 files changed, 30 insertions, 87 deletions
diff --git a/cython/imobiledevice.pyx b/cython/imobiledevice.pyx
index b57db04..77a7a3a 100644
--- a/cython/imobiledevice.pyx
+++ b/cython/imobiledevice.pyx
@@ -170,99 +170,42 @@ cdef class iDevice(Base):
170 self.handle_error(idevice_get_handle(self._c_dev, &handle)) 170 self.handle_error(idevice_get_handle(self._c_dev, &handle))
171 return handle 171 return handle
172 172
173cdef extern from "libimobiledevice/lockdown.h": 173cdef extern from *:
174 cdef struct lockdownd_client_private: 174 ctypedef char* const_char_ptr "const char*"
175 pass 175 void free(void *ptr)
176 ctypedef lockdownd_client_private *lockdownd_client_t 176 void plist_free(plist.plist_t node)
177 ctypedef enum lockdownd_error_t: 177
178 LOCKDOWN_E_SUCCESS = 0 178cdef class BaseService(Base):
179 LOCKDOWN_E_INVALID_ARG = -1 179 __service_name__ = None
180 LOCKDOWN_E_INVALID_CONF = -2
181 LOCKDOWN_E_PLIST_ERROR = -3
182 LOCKDOWN_E_PAIRING_FAILED = -4
183 LOCKDOWN_E_SSL_ERROR = -5
184 LOCKDOWN_E_DICT_ERROR = -6
185 LOCKDOWN_E_START_SERVICE_FAILED = -7
186 LOCKDOWN_E_NOT_ENOUGH_DATA = -8
187 LOCKDOWN_E_SET_VALUE_PROHIBITED = -9
188 LOCKDOWN_E_GET_VALUE_PROHIBITED = -10
189 LOCKDOWN_E_REMOVE_VALUE_PROHIBITED = -11
190 LOCKDOWN_E_MUX_ERROR = -12
191 LOCKDOWN_E_ACTIVATION_FAILED = -13
192 LOCKDOWN_E_PASSWORD_PROTECTED = -14
193 LOCKDOWN_E_NO_RUNNING_SESSION = -15
194 LOCKDOWN_E_INVALID_HOST_ID = -16
195 LOCKDOWN_E_INVALID_SERVICE = -17
196 LOCKDOWN_E_INVALID_ACTIVATION_RECORD = -18
197 LOCKDOWN_E_UNKNOWN_ERROR = -256
198
199 lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdownd_client_t *client, char *label)
200 lockdownd_error_t lockdownd_client_free(lockdownd_client_t client)
201 lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, char *service, uint16_t *port)
202
203cdef class LockdownError(BaseError):
204 def __init__(self, *args, **kwargs):
205 self._lookup_table = {
206 LOCKDOWN_E_SUCCESS: "Success",
207 LOCKDOWN_E_INVALID_ARG: "Invalid argument",
208 LOCKDOWN_E_INVALID_CONF: "Invalid configuration",
209 LOCKDOWN_E_PLIST_ERROR: "Property list error",
210 LOCKDOWN_E_PAIRING_FAILED: "Pairing failed",
211 LOCKDOWN_E_SSL_ERROR: "SSL error",
212 LOCKDOWN_E_DICT_ERROR: "Dict error",
213 LOCKDOWN_E_START_SERVICE_FAILED: "Start service failed",
214 LOCKDOWN_E_NOT_ENOUGH_DATA: "Not enough data",
215 LOCKDOWN_E_SET_VALUE_PROHIBITED: "Set value prohibited",
216 LOCKDOWN_E_GET_VALUE_PROHIBITED: "Get value prohibited",
217 LOCKDOWN_E_REMOVE_VALUE_PROHIBITED: "Remove value prohibited",
218 LOCKDOWN_E_MUX_ERROR: "MUX Error",
219 LOCKDOWN_E_ACTIVATION_FAILED: "Activation failed",
220 LOCKDOWN_E_PASSWORD_PROTECTED: "Password protected",
221 LOCKDOWN_E_NO_RUNNING_SESSION: "No running session",
222 LOCKDOWN_E_INVALID_HOST_ID: "Invalid host ID",
223 LOCKDOWN_E_INVALID_SERVICE: "Invalid service",
224 LOCKDOWN_E_INVALID_ACTIVATION_RECORD: "Invalid activation record",
225 LOCKDOWN_E_UNKNOWN_ERROR: "Unknown error"
226 }
227 BaseError.__init__(self, *args, **kwargs)
228 180
229cdef class LockdownClient(Base): 181cdef class PropertyListService(BaseService):
230 def __cinit__(self, iDevice device not None, bytes label="", *args, **kwargs): 182 cpdef send(self, plist.Node node):
183 self.handle_error(self._send(node._c_node))
184
185 cpdef object receive(self):
231 cdef: 186 cdef:
232 iDevice dev = device 187 plist.plist_t c_node = NULL
233 lockdownd_error_t err 188 int16_t err
234 char* c_label = NULL 189 err = self._receive(&c_node)
235 if label: 190 try:
236 c_label = label
237 err = lockdownd_client_new_with_handshake(dev._c_dev, &(self._c_client), c_label)
238 self.handle_error(err)
239
240 def __dealloc__(self):
241 cdef lockdownd_error_t err
242 if self._c_client is not NULL:
243 err = lockdownd_client_free(self._c_client)
244 self.handle_error(err) 191 self.handle_error(err)
192 except BaseError, e:
193 if c_node != NULL:
194 plist_free(c_node)
195 raise
245 196
246 cdef inline BaseError _error(self, int16_t ret): 197 return plist.plist_t_to_node(c_node)
247 return LockdownError(ret)
248
249 cpdef int start_service(self, bytes service):
250 cdef:
251 uint16_t port
252 lockdownd_error_t err
253 err = lockdownd_start_service(self._c_client, service, &port)
254 self.handle_error(err)
255 return port
256
257 cpdef goodbye(self):
258 pass
259 198
260cdef extern from *: 199 cdef inline int16_t _send(self, plist.plist_t node):
261 ctypedef char* const_char_ptr "const char*" 200 raise NotImplementedError("send is not implemented")
262 void free(void *ptr) 201
263 void plist_free(plist.plist_t node) 202 cdef inline int16_t _receive(self, plist.plist_t* c_node):
203 raise NotImplementedError("receive is not implemented")
204
205cdef class DeviceLinkService(PropertyListService):
206 pass
264 207
265include "property_list_client.pxi" 208include "lockdown.pxi"
266include "mobilesync.pxi" 209include "mobilesync.pxi"
267include "notification_proxy.pxi" 210include "notification_proxy.pxi"
268include "sbservices.pxi" 211include "sbservices.pxi"