diff options
Diffstat (limited to 'swig/imobiledevice.i')
-rw-r--r-- | swig/imobiledevice.i | 341 |
1 files changed, 0 insertions, 341 deletions
diff --git a/swig/imobiledevice.i b/swig/imobiledevice.i deleted file mode 100644 index 2de69e7..0000000 --- a/swig/imobiledevice.i +++ /dev/null | |||
@@ -1,341 +0,0 @@ | |||
1 | /* swig.i */ | ||
2 | %module imobiledevice | ||
3 | %feature("autodoc", "1"); | ||
4 | %{ | ||
5 | /* Includes the header in the wrapper code */ | ||
6 | #include <libimobiledevice/libimobiledevice.h> | ||
7 | #include <libimobiledevice/lockdown.h> | ||
8 | #include <libimobiledevice/mobilesync.h> | ||
9 | #include <libimobiledevice/notification_proxy.h> | ||
10 | #include <plist/plist.h> | ||
11 | #include <plist/plist++.h> | ||
12 | #include "../src/debug.h" | ||
13 | |||
14 | typedef struct { | ||
15 | idevice_t dev; | ||
16 | } idevice; | ||
17 | |||
18 | typedef struct { | ||
19 | idevice* dev; | ||
20 | lockdownd_client_t client; | ||
21 | } Lockdownd; | ||
22 | |||
23 | typedef struct { | ||
24 | idevice* dev; | ||
25 | mobilesync_client_t client; | ||
26 | } MobileSync; | ||
27 | |||
28 | typedef struct { | ||
29 | idevice* dev; | ||
30 | np_client_t client; | ||
31 | } NotificationProxy; | ||
32 | |||
33 | //now declare funtions to handle creation and deletion of objects | ||
34 | static void my_delete_idevice(idevice* dev) { | ||
35 | if (dev) { | ||
36 | idevice_free(dev->dev); | ||
37 | free(dev); | ||
38 | } | ||
39 | } | ||
40 | |||
41 | static Lockdownd* my_new_Lockdownd(idevice* device) { | ||
42 | if (!device) return NULL; | ||
43 | Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); | ||
44 | client->dev = device; | ||
45 | client->client = NULL; | ||
46 | if (LOCKDOWN_E_SUCCESS == lockdownd_client_new_with_handshake(device->dev , &(client->client), NULL)) { | ||
47 | return client; | ||
48 | } | ||
49 | else { | ||
50 | free(client); | ||
51 | return NULL; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | static void my_delete_Lockdownd(Lockdownd* lckd) { | ||
56 | if (lckd) { | ||
57 | lockdownd_client_free(lckd->client); | ||
58 | free(lckd); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | static MobileSync* my_new_MobileSync(Lockdownd* lckd) { | ||
63 | if (!lckd || !lckd->dev) return NULL; | ||
64 | MobileSync* client = NULL; | ||
65 | uint16_t port = 0; | ||
66 | if (LOCKDOWN_E_SUCCESS == lockdownd_start_service(lckd->client, "com.apple.mobilesync", &port)) { | ||
67 | client = (MobileSync*) malloc(sizeof(MobileSync)); | ||
68 | client->dev = lckd->dev; | ||
69 | client->client = NULL; | ||
70 | mobilesync_client_new(lckd->dev->dev, port, &(client->client)); | ||
71 | } | ||
72 | return client; | ||
73 | } | ||
74 | |||
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) | ||
89 | { | ||
90 | PList::Node* ret = NULL; | ||
91 | plist_type subtype = plist_get_node_type(node); | ||
92 | switch(subtype) | ||
93 | { | ||
94 | case PLIST_DICT: | ||
95 | ret = new PList::Dictionary(node); | ||
96 | break; | ||
97 | case PLIST_ARRAY: | ||
98 | ret = new PList::Array(node); | ||
99 | break; | ||
100 | case PLIST_BOOLEAN: | ||
101 | ret = new PList::Boolean(node); | ||
102 | break; | ||
103 | case PLIST_UINT: | ||
104 | ret = new PList::Integer(node); | ||
105 | break; | ||
106 | case PLIST_REAL: | ||
107 | ret = new PList::Real(node); | ||
108 | break; | ||
109 | case PLIST_STRING: | ||
110 | ret = new PList::String(node); | ||
111 | break; | ||
112 | case PLIST_DATE: | ||
113 | ret = new PList::Date(node); | ||
114 | break; | ||
115 | case PLIST_DATA: | ||
116 | ret = new PList::Data(node); | ||
117 | break; | ||
118 | default: | ||
119 | break; | ||
120 | } | ||
121 | return ret; | ||
122 | } | ||
123 | |||
124 | #ifdef SWIGPYTHON | ||
125 | static void NotificationProxyPythonCallback(const char *notification, void* user_data) { | ||
126 | PyObject *func, *arglist; | ||
127 | |||
128 | func = (PyObject *) user_data; | ||
129 | arglist = Py_BuildValue("(s)",notification); | ||
130 | |||
131 | PyEval_CallObject(func, arglist); | ||
132 | |||
133 | Py_DECREF(arglist); | ||
134 | } | ||
135 | #endif | ||
136 | %} | ||
137 | |||
138 | /* Parse the header file to generate wrappers */ | ||
139 | %include "stdint.i" | ||
140 | %include "cstring.i" | ||
141 | %include "plist/swig/plist.i" | ||
142 | |||
143 | /* This needs to be here since if it's after | ||
144 | * the structs, SWIG won't pick it up for %extend | ||
145 | */ | ||
146 | #ifdef SWIGPYTHON | ||
147 | %typemap(in) (PyObject *pyfunc) { | ||
148 | if (!PyCallable_Check($input)) { | ||
149 | PyErr_SetString(PyExc_TypeError, "Need a callable object!"); | ||
150 | return NULL; | ||
151 | } | ||
152 | $1 = $input; | ||
153 | } | ||
154 | %typemap(in) (const char **string_list) { | ||
155 | /* Check if it's a list */ | ||
156 | if (PyList_Check($input)) { | ||
157 | int size = PyList_Size($input); | ||
158 | int i = 0; | ||
159 | $1 = (char **) malloc((size+1)*sizeof(char *)); | ||
160 | for (i = 0; i < size; i++) { | ||
161 | PyObject *o = PyList_GetItem($input,i); | ||
162 | if (PyString_Check(o)) { | ||
163 | $1[i] = PyString_AsString(PyList_GetItem($input,i)); | ||
164 | } else { | ||
165 | PyErr_SetString(PyExc_TypeError,"List must contain strings"); | ||
166 | free($1); | ||
167 | return NULL; | ||
168 | } | ||
169 | } | ||
170 | $1[i] = 0; | ||
171 | } else if (PyTuple_Check($input)) { | ||
172 | int size = PyTuple_Size($input); | ||
173 | int i = 0; | ||
174 | $1 = (char **) malloc((size+1)*sizeof(char *)); | ||
175 | for (i = 0; i < size; i++) { | ||
176 | PyObject *o = PyTuple_GetItem($input,i); | ||
177 | if (PyString_Check(o)) { | ||
178 | $1[i] = PyString_AsString(PyTuple_GetItem($input,i)); | ||
179 | } else { | ||
180 | PyErr_SetString(PyExc_TypeError,"List must contain strings"); | ||
181 | free($1); | ||
182 | return NULL; | ||
183 | } | ||
184 | } | ||
185 | $1[i] = 0; | ||
186 | } else { | ||
187 | PyErr_SetString(PyExc_TypeError, "not a list or tuple"); | ||
188 | return NULL; | ||
189 | } | ||
190 | } | ||
191 | %typemap(freearg) (const char **string_list) { | ||
192 | free((char *) $1); | ||
193 | } | ||
194 | #endif | ||
195 | |||
196 | typedef struct { | ||
197 | idevice_t dev; | ||
198 | } idevice; | ||
199 | |||
200 | typedef struct { | ||
201 | idevice* dev; | ||
202 | lockdownd_client_t client; | ||
203 | } Lockdownd; | ||
204 | |||
205 | typedef struct { | ||
206 | idevice* dev; | ||
207 | mobilesync_client_t client; | ||
208 | } MobileSync; | ||
209 | |||
210 | typedef struct { | ||
211 | idevice* dev; | ||
212 | np_client_t client; | ||
213 | } NotificationProxy; | ||
214 | |||
215 | |||
216 | %extend idevice { // Attach these functions to struct idevice | ||
217 | idevice() { | ||
218 | idevice* device = (idevice*) malloc(sizeof(idevice)); | ||
219 | device->dev = NULL; | ||
220 | return device; | ||
221 | } | ||
222 | |||
223 | ~idevice() { | ||
224 | my_delete_idevice($self); | ||
225 | } | ||
226 | |||
227 | void set_debug_level(int level) { | ||
228 | idevice_set_debug_level(level); | ||
229 | } | ||
230 | |||
231 | int init_device_by_uuid(char* uuid) { | ||
232 | if (IDEVICE_E_SUCCESS == idevice_new(&($self->dev), uuid)) | ||
233 | return 1; | ||
234 | return 0; | ||
235 | } | ||
236 | |||
237 | int init_device() { | ||
238 | if (IDEVICE_E_SUCCESS == idevice_new(&($self->dev), NULL)) | ||
239 | return 1; | ||
240 | return 0; | ||
241 | } | ||
242 | |||
243 | %newobject get_uuid; | ||
244 | char* get_uuid(){ | ||
245 | char* uuid = NULL; | ||
246 | idevice_get_uuid($self->dev, &uuid); | ||
247 | return uuid; | ||
248 | } | ||
249 | |||
250 | Lockdownd* get_lockdown_client() { | ||
251 | return my_new_Lockdownd($self); | ||
252 | } | ||
253 | }; | ||
254 | |||
255 | %extend Lockdownd { // Attach these functions to struct Lockdownd | ||
256 | Lockdownd(idevice* device) { | ||
257 | return my_new_Lockdownd(device); | ||
258 | } | ||
259 | |||
260 | ~Lockdownd() { | ||
261 | my_delete_Lockdownd($self); | ||
262 | } | ||
263 | |||
264 | void send(PList::Node* node) { | ||
265 | lockdownd_send($self->client, node->GetPlist()); | ||
266 | } | ||
267 | |||
268 | PList::Node* receive() { | ||
269 | plist_t node = NULL; | ||
270 | lockdownd_receive($self->client, &node); | ||
271 | return new_node_from_plist(node); | ||
272 | } | ||
273 | |||
274 | MobileSync* get_mobilesync_client() { | ||
275 | return my_new_MobileSync($self); | ||
276 | } | ||
277 | |||
278 | NotificationProxy* get_notification_proxy_client() { | ||
279 | return my_new_NotificationProxy($self); | ||
280 | } | ||
281 | }; | ||
282 | |||
283 | %extend MobileSync { // Attach these functions to struct MobileSync | ||
284 | MobileSync(Lockdownd* lckd) { | ||
285 | return my_new_MobileSync(lckd); | ||
286 | } | ||
287 | |||
288 | ~MobileSync() { | ||
289 | mobilesync_client_free($self->client); | ||
290 | free($self); | ||
291 | } | ||
292 | |||
293 | void send(PList::Node* node) { | ||
294 | mobilesync_send($self->client, node->GetPlist()); | ||
295 | } | ||
296 | |||
297 | PList::Node* receive() { | ||
298 | plist_t node = NULL; | ||
299 | mobilesync_receive($self->client, &node); | ||
300 | return new_node_from_plist(node); | ||
301 | } | ||
302 | }; | ||
303 | |||
304 | #define NP_SYNC_WILL_START "com.apple.itunes-mobdev.syncWillStart" | ||
305 | #define NP_SYNC_DID_START "com.apple.itunes-mobdev.syncDidStart" | ||
306 | #define NP_SYNC_DID_FINISH "com.apple.itunes-mobdev.syncDidFinish" | ||
307 | #define NP_SYNC_LOCK_REQUEST "com.apple.itunes-mobdev.syncLockRequest" | ||
308 | |||
309 | %extend NotificationProxy { | ||
310 | NotificationProxy(Lockdownd* lckd) { | ||
311 | return my_new_NotificationProxy(lckd); | ||
312 | } | ||
313 | |||
314 | ~NotificationProxy() { | ||
315 | np_client_free($self->client); | ||
316 | free($self); | ||
317 | } | ||
318 | |||
319 | int16_t post_notification(const char* notification) { | ||
320 | return np_post_notification($self->client, notification); | ||
321 | } | ||
322 | |||
323 | int16_t observe_notification(const char* notification) { | ||
324 | return np_observe_notification($self->client, notification); | ||
325 | } | ||
326 | |||
327 | int16_t observe_notifications(const char** string_list) { | ||
328 | return np_observe_notifications($self->client, string_list); | ||
329 | } | ||
330 | }; | ||
331 | |||
332 | #ifdef SWIGPYTHON | ||
333 | %extend NotificationProxy { | ||
334 | int16_t set_callback(PyObject *pyfunc) { | ||
335 | int16_t res; | ||
336 | res = np_set_notify_callback($self->client, NotificationProxyPythonCallback, (void *) pyfunc); | ||
337 | Py_INCREF(pyfunc); | ||
338 | return res; | ||
339 | } | ||
340 | }; | ||
341 | #endif | ||