diff options
Diffstat (limited to 'cython/misagent.pxi')
| -rw-r--r-- | cython/misagent.pxi | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/cython/misagent.pxi b/cython/misagent.pxi new file mode 100644 index 0000000..1fee4b9 --- /dev/null +++ b/cython/misagent.pxi | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | cdef extern from "libimobiledevice/misagent.h": | ||
| 2 | cdef struct misagent_client_private: | ||
| 3 | pass | ||
| 4 | ctypedef misagent_client_private *misagent_client_t | ||
| 5 | |||
| 6 | ctypedef enum misagent_error_t: | ||
| 7 | MISAGENT_E_SUCCESS = 0 | ||
| 8 | MISAGENT_E_INVALID_ARG = -1 | ||
| 9 | MISAGENT_E_PLIST_ERROR = -2 | ||
| 10 | MISAGENT_E_CONN_FAILED = -3 | ||
| 11 | MISAGENT_E_REQUEST_FAILED = -4 | ||
| 12 | MISAGENT_E_UNKNOWN_ERROR = -256 | ||
| 13 | |||
| 14 | misagent_error_t misagent_client_new(idevice_t device, lockdownd_service_descriptor_t descriptor, misagent_client_t * client) | ||
| 15 | misagent_error_t misagent_client_free(misagent_client_t client) | ||
| 16 | |||
| 17 | misagent_error_t misagent_install(misagent_client_t client, plist.plist_t profile) | ||
| 18 | misagent_error_t misagent_copy(misagent_client_t client, plist.plist_t* profiles) | ||
| 19 | misagent_error_t misagent_remove(misagent_client_t client, char* profileID) | ||
| 20 | int misagent_get_status_code(misagent_client_t client) | ||
| 21 | |||
| 22 | cdef class MisagentError(BaseError): | ||
| 23 | def __init__(self, *args, **kwargs): | ||
| 24 | self._lookup_table = { | ||
| 25 | MISAGENT_E_SUCCESS: "Success", | ||
| 26 | MISAGENT_E_INVALID_ARG: "Invalid argument", | ||
| 27 | MISAGENT_E_PLIST_ERROR: "Property list error", | ||
| 28 | MISAGENT_E_CONN_FAILED: "Connection failed", | ||
| 29 | MISAGENT_E_REQUEST_FAILED: "Request failed", | ||
| 30 | MISAGENT_E_UNKNOWN_ERROR: "Unknown error" | ||
| 31 | } | ||
| 32 | BaseError.__init__(self, *args, **kwargs) | ||
| 33 | |||
| 34 | cdef class MisagentClient(PropertyListService): | ||
| 35 | __service_name__ = "com.apple.misagent" | ||
| 36 | cdef misagent_client_t _c_client | ||
| 37 | |||
| 38 | def __cinit__(self, iDevice device not None, LockdownServiceDescriptor descriptor, *args, **kwargs): | ||
| 39 | self.handle_error(misagent_client_new(device._c_dev, descriptor._c_service_descriptor, &self._c_client)) | ||
| 40 | |||
| 41 | def __dealloc__(self): | ||
| 42 | cdef misagent_error_t err | ||
| 43 | if self._c_client is not NULL: | ||
| 44 | err = misagent_client_free(self._c_client) | ||
| 45 | self.handle_error(err) | ||
| 46 | |||
| 47 | cdef inline BaseError _error(self, int16_t ret): | ||
| 48 | return MisagentError(ret) | ||
| 49 | |||
| 50 | cpdef install(self, plist.Node profile): | ||
| 51 | cdef misagent_error_t err | ||
| 52 | err = misagent_install(self._c_client, profile._c_node) | ||
| 53 | self.handle_error(err) | ||
| 54 | |||
| 55 | cpdef plist.Node copy(self): | ||
| 56 | cdef: | ||
| 57 | plist.plist_t c_node = NULL | ||
| 58 | misagent_error_t err | ||
| 59 | err = misagent_copy(self._c_client, &c_node) | ||
| 60 | try: | ||
| 61 | self.handle_error(err) | ||
| 62 | return plist.plist_t_to_node(c_node) | ||
| 63 | except BaseError, e: | ||
| 64 | if c_node != NULL: | ||
| 65 | plist.plist_free(c_node) | ||
| 66 | raise | ||
| 67 | |||
| 68 | cpdef remove(self, bytes profile_id): | ||
| 69 | cdef misagent_error_t err | ||
| 70 | err = misagent_remove(self._c_client, profile_id) | ||
| 71 | self.handle_error(err) | ||
| 72 | |||
| 73 | cpdef int get_status_code(self): | ||
| 74 | return misagent_get_status_code(self._c_client) | ||
