diff options
Diffstat (limited to 'swig')
| -rw-r--r-- | swig/__init__.py | 2 | ||||
| -rw-r--r-- | swig/imobiledevice.i | 239 |
2 files changed, 184 insertions, 57 deletions
diff --git a/swig/__init__.py b/swig/__init__.py index e70dcce..e0c053b 100644 --- a/swig/__init__.py +++ b/swig/__init__.py | |||
| @@ -1,2 +1,2 @@ | |||
| 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
| 2 | from iphone import * | 2 | from imobiledevice import * |
diff --git a/swig/imobiledevice.i b/swig/imobiledevice.i index f978c8e..3c9fd3c 100644 --- a/swig/imobiledevice.i +++ b/swig/imobiledevice.i | |||
| @@ -6,83 +6,60 @@ | |||
| 6 | #include <libimobiledevice/libimobiledevice.h> | 6 | #include <libimobiledevice/libimobiledevice.h> |
| 7 | #include <libimobiledevice/lockdown.h> | 7 | #include <libimobiledevice/lockdown.h> |
| 8 | #include <libimobiledevice/mobilesync.h> | 8 | #include <libimobiledevice/mobilesync.h> |
| 9 | #include <libimobiledevice/notification_proxy.h> | ||
| 9 | #include <plist/plist.h> | 10 | #include <plist/plist.h> |
| 10 | #include <plist/plist++.h> | 11 | #include <plist/plist++.h> |
| 11 | #include "../src/debug.h" | 12 | #include "../src/debug.h" |
| 12 | typedef struct { | ||
| 13 | idevice_t dev; | ||
| 14 | } idevice; | ||
| 15 | |||
| 16 | typedef struct { | ||
| 17 | idevice* dev; | ||
| 18 | lockdownd_client_t client; | ||
| 19 | } Lockdownd; | ||
| 20 | |||
| 21 | typedef struct { | ||
| 22 | idevice* dev; | ||
| 23 | mobilesync_client_t client; | ||
| 24 | } MobileSync; | ||
| 25 | |||
| 26 | //now declare funtions to handle creation and deletion of objects | ||
| 27 | void my_delete_idevice(idevice* dev); | ||
| 28 | Lockdownd* my_new_Lockdownd(idevice* device); | ||
| 29 | void my_delete_Lockdownd(Lockdownd* lckd); | ||
| 30 | MobileSync* my_new_MobileSync(Lockdownd* lckd); | ||
| 31 | PList::Node* new_node_from_plist(plist_t node); | ||
| 32 | |||
| 33 | %} | ||
| 34 | /* Parse the header file to generate wrappers */ | ||
| 35 | %include "stdint.i" | ||
| 36 | %include "cstring.i" | ||
| 37 | %include "plist/swig/plist.i" | ||
| 38 | 13 | ||
| 39 | typedef struct { | 14 | typedef struct { |
| 40 | idevice_t dev; | 15 | idevice_t dev; |
| 41 | } idevice; | 16 | } idevice; |
| 42 | 17 | ||
| 43 | typedef struct { | 18 | typedef struct { |
| 44 | idevice* dev; | 19 | idevice* dev; |
| 45 | lockdownd_client_t client; | 20 | lockdownd_client_t client; |
| 46 | } Lockdownd; | 21 | } Lockdownd; |
| 47 | 22 | ||
| 48 | typedef struct { | 23 | typedef struct { |
| 49 | idevice* dev; | 24 | idevice* dev; |
| 50 | mobilesync_client_t client; | 25 | mobilesync_client_t client; |
| 51 | } MobileSync; | 26 | } MobileSync; |
| 52 | 27 | ||
| 53 | %inline %{ | 28 | typedef struct { |
| 54 | //now define funtions to handle creation and deletion of objects | 29 | idevice* dev; |
| 55 | 30 | np_client_t client; | |
| 31 | } NotificationProxy; | ||
| 56 | 32 | ||
| 57 | void my_delete_idevice(idevice* dev) { | 33 | //now declare funtions to handle creation and deletion of objects |
| 34 | static void my_delete_idevice(idevice* dev) { | ||
| 58 | if (dev) { | 35 | if (dev) { |
| 59 | idevice_free(dev->dev); | 36 | idevice_free(dev->dev); |
| 60 | free(dev); | 37 | free(dev); |
| 61 | } | 38 | } |
| 62 | } | 39 | } |
| 63 | 40 | ||
| 64 | Lockdownd* my_new_Lockdownd(idevice* device) { | 41 | static Lockdownd* my_new_Lockdownd(idevice* device) { |
| 65 | if (!device) return NULL; | 42 | if (!device) return NULL; |
| 66 | Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); | 43 | Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); |
| 67 | client->dev = device; | 44 | client->dev = device; |
| 68 | client->client = NULL; | 45 | client->client = NULL; |
| 69 | if (LOCKDOWN_E_SUCCESS == lockdownd_client_new_with_handshake(device->dev , &(client->client), NULL)) { | 46 | if (LOCKDOWN_E_SUCCESS == lockdownd_client_new_with_handshake(device->dev , &(client->client), NULL)) { |
| 70 | return client; | 47 | return client; |
| 71 | } | 48 | } |
| 72 | else { | 49 | else { |
| 73 | free(client); | 50 | free(client); |
| 74 | return NULL; | 51 | return NULL; |
| 75 | } | 52 | } |
| 76 | } | 53 | } |
| 77 | 54 | ||
| 78 | void my_delete_Lockdownd(Lockdownd* lckd) { | 55 | static void my_delete_Lockdownd(Lockdownd* lckd) { |
| 79 | if (lckd) { | 56 | if (lckd) { |
| 80 | lockdownd_client_free(lckd->client); | 57 | lockdownd_client_free(lckd->client); |
| 81 | free(lckd); | 58 | free(lckd); |
| 82 | } | 59 | } |
| 83 | } | 60 | } |
| 84 | 61 | ||
| 85 | MobileSync* my_new_MobileSync(Lockdownd* lckd) { | 62 | static MobileSync* my_new_MobileSync(Lockdownd* lckd) { |
| 86 | if (!lckd || !lckd->dev) return NULL; | 63 | if (!lckd || !lckd->dev) return NULL; |
| 87 | MobileSync* client = NULL; | 64 | MobileSync* client = NULL; |
| 88 | uint16_t port = 0; | 65 | uint16_t port = 0; |
| @@ -95,7 +72,20 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { | |||
| 95 | return client; | 72 | return client; |
| 96 | } | 73 | } |
| 97 | 74 | ||
| 98 | PList::Node* new_node_from_plist(plist_t node) | 75 | static NotificationProxy* my_new_NotificationProxy(Lockdownd* lckd) { |
| 76 | if (!lckd || !lckd->dev) return NULL; | ||
| 77 | NotificationProxy* client = NULL; | ||
| 78 | uint16_t port = 0; | ||
| 79 | if (LOCKDOWN_E_SUCCESS == lockdownd_start_service(lckd->client, "com.apple.mobile.notification_proxy", &port)) { | ||
| 80 | client = (NotificationProxy*) malloc(sizeof(NotificationProxy)); | ||
| 81 | client->dev = lckd->dev; | ||
| 82 | client->client = NULL; | ||
| 83 | np_client_new(lckd->dev->dev, port, &(client->client)); | ||
| 84 | } | ||
| 85 | return client; | ||
| 86 | } | ||
| 87 | |||
| 88 | static PList::Node* new_node_from_plist(plist_t node) | ||
| 99 | { | 89 | { |
| 100 | PList::Node* ret = NULL; | 90 | PList::Node* ret = NULL; |
| 101 | plist_type subtype = plist_get_node_type(node); | 91 | plist_type subtype = plist_get_node_type(node); |
| @@ -130,7 +120,102 @@ PList::Node* new_node_from_plist(plist_t node) | |||
| 130 | } | 120 | } |
| 131 | return ret; | 121 | return ret; |
| 132 | } | 122 | } |
| 133 | %} | 123 | |
| 124 | #ifdef SWIGPYTHON | ||
| 125 | PyObject* python_callback = NULL; | ||
| 126 | |||
| 127 | static void NotificationProxyPythonCallback(const char *notification) { | ||
| 128 | PyObject *arglist; | ||
| 129 | PyGILState_STATE gstate; | ||
| 130 | |||
| 131 | arglist = Py_BuildValue("(s)",notification); | ||
| 132 | |||
| 133 | gstate = PyGILState_Ensure(); | ||
| 134 | |||
| 135 | PyEval_CallObject(python_callback, arglist); | ||
| 136 | |||
| 137 | Py_XDECREF(arglist); | ||
| 138 | PyGILState_Release(gstate); | ||
| 139 | } | ||
| 140 | #endif | ||
| 141 | %} | ||
| 142 | |||
| 143 | /* Parse the header file to generate wrappers */ | ||
| 144 | %include "stdint.i" | ||
| 145 | %include "cstring.i" | ||
| 146 | %include "plist/swig/plist.i" | ||
| 147 | |||
| 148 | /* This needs to be here since if it's after | ||
| 149 | * the structs, SWIG won't pick it up for %extend | ||
| 150 | */ | ||
| 151 | #ifdef SWIGPYTHON | ||
| 152 | %typemap(in) (PyObject *pyfunc) { | ||
| 153 | if (!PyCallable_Check($input)) { | ||
| 154 | PyErr_SetString(PyExc_TypeError, "Need a callable object!"); | ||
| 155 | return NULL; | ||
| 156 | } | ||
| 157 | $1 = $input; | ||
| 158 | } | ||
| 159 | %typemap(in) (const char **string_list) { | ||
| 160 | /* Check if it's a list */ | ||
| 161 | if (PyList_Check($input)) { | ||
| 162 | int size = PyList_Size($input); | ||
| 163 | int i = 0; | ||
| 164 | $1 = (char **) malloc((size+1)*sizeof(char *)); | ||
| 165 | for (i = 0; i < size; i++) { | ||
| 166 | PyObject *o = PyList_GetItem($input,i); | ||
| 167 | if (PyString_Check(o)) { | ||
| 168 | $1[i] = PyString_AsString(PyList_GetItem($input,i)); | ||
| 169 | } else { | ||
| 170 | PyErr_SetString(PyExc_TypeError,"List must contain strings"); | ||
| 171 | free($1); | ||
| 172 | return NULL; | ||
| 173 | } | ||
| 174 | } | ||
| 175 | $1[i] = 0; | ||
| 176 | } else if (PyTuple_Check($input)) { | ||
| 177 | int size = PyTuple_Size($input); | ||
| 178 | int i = 0; | ||
| 179 | $1 = (char **) malloc((size+1)*sizeof(char *)); | ||
| 180 | for (i = 0; i < size; i++) { | ||
| 181 | PyObject *o = PyTuple_GetItem($input,i); | ||
| 182 | if (PyString_Check(o)) { | ||
| 183 | $1[i] = PyString_AsString(PyTuple_GetItem($input,i)); | ||
| 184 | } else { | ||
| 185 | PyErr_SetString(PyExc_TypeError,"List must contain strings"); | ||
| 186 | free($1); | ||
| 187 | return NULL; | ||
| 188 | } | ||
| 189 | } | ||
| 190 | $1[i] = 0; | ||
| 191 | } else { | ||
| 192 | PyErr_SetString(PyExc_TypeError, "not a list or tuple"); | ||
| 193 | return NULL; | ||
| 194 | } | ||
| 195 | } | ||
| 196 | %typemap(freearg) (const char **string_list) { | ||
| 197 | free((char *) $1); | ||
| 198 | } | ||
| 199 | #endif | ||
| 200 | |||
| 201 | typedef struct { | ||
| 202 | idevice_t dev; | ||
| 203 | } idevice; | ||
| 204 | |||
| 205 | typedef struct { | ||
| 206 | idevice* dev; | ||
| 207 | lockdownd_client_t client; | ||
| 208 | } Lockdownd; | ||
| 209 | |||
| 210 | typedef struct { | ||
| 211 | idevice* dev; | ||
| 212 | mobilesync_client_t client; | ||
| 213 | } MobileSync; | ||
| 214 | |||
| 215 | typedef struct { | ||
| 216 | idevice* dev; | ||
| 217 | np_client_t client; | ||
| 218 | } NotificationProxy; | ||
| 134 | 219 | ||
| 135 | 220 | ||
| 136 | %extend idevice { // Attach these functions to struct idevice | 221 | %extend idevice { // Attach these functions to struct idevice |
| @@ -172,7 +257,6 @@ PList::Node* new_node_from_plist(plist_t node) | |||
| 172 | } | 257 | } |
| 173 | }; | 258 | }; |
| 174 | 259 | ||
| 175 | |||
| 176 | %extend Lockdownd { // Attach these functions to struct Lockdownd | 260 | %extend Lockdownd { // Attach these functions to struct Lockdownd |
| 177 | Lockdownd(idevice* device) { | 261 | Lockdownd(idevice* device) { |
| 178 | return my_new_Lockdownd(device); | 262 | return my_new_Lockdownd(device); |
| @@ -195,6 +279,10 @@ PList::Node* new_node_from_plist(plist_t node) | |||
| 195 | MobileSync* get_mobilesync_client() { | 279 | MobileSync* get_mobilesync_client() { |
| 196 | return my_new_MobileSync($self); | 280 | return my_new_MobileSync($self); |
| 197 | } | 281 | } |
| 282 | |||
| 283 | NotificationProxy* get_notification_proxy_client() { | ||
| 284 | return my_new_NotificationProxy($self); | ||
| 285 | } | ||
| 198 | }; | 286 | }; |
| 199 | 287 | ||
| 200 | %extend MobileSync { // Attach these functions to struct MobileSync | 288 | %extend MobileSync { // Attach these functions to struct MobileSync |
| @@ -218,3 +306,42 @@ PList::Node* new_node_from_plist(plist_t node) | |||
| 218 | } | 306 | } |
| 219 | }; | 307 | }; |
| 220 | 308 | ||
| 309 | #define NP_SYNC_WILL_START "com.apple.itunes-mobdev.syncWillStart" | ||
| 310 | #define NP_SYNC_DID_START "com.apple.itunes-mobdev.syncDidStart" | ||
| 311 | #define NP_SYNC_DID_FINISH "com.apple.itunes-mobdev.syncDidFinish" | ||
| 312 | #define NP_SYNC_LOCK_REQUEST "com.apple.itunes-mobdev.syncLockRequest" | ||
| 313 | |||
| 314 | %extend NotificationProxy { | ||
| 315 | NotificationProxy(Lockdownd* lckd) { | ||
| 316 | return my_new_NotificationProxy(lckd); | ||
| 317 | } | ||
| 318 | |||
| 319 | ~NotificationProxy() { | ||
| 320 | np_client_free($self->client); | ||
| 321 | free($self); | ||
| 322 | } | ||
| 323 | |||
| 324 | int16_t post_notification(const char* notification) { | ||
| 325 | return np_post_notification($self->client, notification); | ||
| 326 | } | ||
| 327 | |||
| 328 | int16_t observe_notification(const char* notification) { | ||
| 329 | return np_observe_notification($self->client, notification); | ||
| 330 | } | ||
| 331 | |||
| 332 | int16_t observe_notifications(const char** string_list) { | ||
| 333 | return np_observe_notifications($self->client, string_list); | ||
| 334 | } | ||
| 335 | }; | ||
| 336 | |||
| 337 | #ifdef SWIGPYTHON | ||
| 338 | %extend NotificationProxy { | ||
| 339 | int16_t set_callback(PyObject *pyfunc) { | ||
| 340 | int16_t res; | ||
| 341 | python_callback = pyfunc; | ||
| 342 | res = np_set_notify_callback($self->client, NotificationProxyPythonCallback); | ||
| 343 | Py_INCREF(pyfunc); | ||
| 344 | return res; | ||
| 345 | } | ||
| 346 | }; | ||
| 347 | #endif | ||
