diff options
Diffstat (limited to 'swig/imobiledevice.i')
| -rw-r--r-- | swig/imobiledevice.i | 220 |
1 files changed, 220 insertions, 0 deletions
diff --git a/swig/imobiledevice.i b/swig/imobiledevice.i new file mode 100644 index 0000000..f978c8e --- /dev/null +++ b/swig/imobiledevice.i | |||
| @@ -0,0 +1,220 @@ | |||
| 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 <plist/plist.h> | ||
| 10 | #include <plist/plist++.h> | ||
| 11 | #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 | |||
| 39 | typedef struct { | ||
| 40 | idevice_t dev; | ||
| 41 | } idevice; | ||
| 42 | |||
| 43 | typedef struct { | ||
| 44 | idevice* dev; | ||
| 45 | lockdownd_client_t client; | ||
| 46 | } Lockdownd; | ||
| 47 | |||
| 48 | typedef struct { | ||
| 49 | idevice* dev; | ||
| 50 | mobilesync_client_t client; | ||
| 51 | } MobileSync; | ||
| 52 | |||
| 53 | %inline %{ | ||
| 54 | //now define funtions to handle creation and deletion of objects | ||
| 55 | |||
| 56 | |||
| 57 | void my_delete_idevice(idevice* dev) { | ||
| 58 | if (dev) { | ||
| 59 | idevice_free(dev->dev); | ||
| 60 | free(dev); | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | Lockdownd* my_new_Lockdownd(idevice* device) { | ||
| 65 | if (!device) return NULL; | ||
| 66 | Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); | ||
| 67 | client->dev = device; | ||
| 68 | client->client = NULL; | ||
| 69 | if (LOCKDOWN_E_SUCCESS == lockdownd_client_new_with_handshake(device->dev , &(client->client), NULL)) { | ||
| 70 | return client; | ||
| 71 | } | ||
| 72 | else { | ||
| 73 | free(client); | ||
| 74 | return NULL; | ||
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 78 | void my_delete_Lockdownd(Lockdownd* lckd) { | ||
| 79 | if (lckd) { | ||
| 80 | lockdownd_client_free(lckd->client); | ||
| 81 | free(lckd); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | MobileSync* my_new_MobileSync(Lockdownd* lckd) { | ||
| 86 | if (!lckd || !lckd->dev) return NULL; | ||
| 87 | MobileSync* client = NULL; | ||
| 88 | uint16_t port = 0; | ||
| 89 | if (LOCKDOWN_E_SUCCESS == lockdownd_start_service(lckd->client, "com.apple.mobilesync", &port)) { | ||
| 90 | client = (MobileSync*) malloc(sizeof(MobileSync)); | ||
| 91 | client->dev = lckd->dev; | ||
| 92 | client->client = NULL; | ||
| 93 | mobilesync_client_new(lckd->dev->dev, port, &(client->client)); | ||
| 94 | } | ||
| 95 | return client; | ||
| 96 | } | ||
| 97 | |||
| 98 | PList::Node* new_node_from_plist(plist_t node) | ||
| 99 | { | ||
| 100 | PList::Node* ret = NULL; | ||
| 101 | plist_type subtype = plist_get_node_type(node); | ||
| 102 | switch(subtype) | ||
| 103 | { | ||
| 104 | case PLIST_DICT: | ||
| 105 | ret = new PList::Dictionary(node); | ||
| 106 | break; | ||
| 107 | case PLIST_ARRAY: | ||
| 108 | ret = new PList::Array(node); | ||
| 109 | break; | ||
| 110 | case PLIST_BOOLEAN: | ||
| 111 | ret = new PList::Boolean(node); | ||
| 112 | break; | ||
| 113 | case PLIST_UINT: | ||
| 114 | ret = new PList::Integer(node); | ||
| 115 | break; | ||
| 116 | case PLIST_REAL: | ||
| 117 | ret = new PList::Real(node); | ||
| 118 | break; | ||
| 119 | case PLIST_STRING: | ||
| 120 | ret = new PList::String(node); | ||
| 121 | break; | ||
| 122 | case PLIST_DATE: | ||
| 123 | ret = new PList::Date(node); | ||
| 124 | break; | ||
| 125 | case PLIST_DATA: | ||
| 126 | ret = new PList::Data(node); | ||
| 127 | break; | ||
| 128 | default: | ||
| 129 | break; | ||
| 130 | } | ||
| 131 | return ret; | ||
| 132 | } | ||
| 133 | %} | ||
| 134 | |||
| 135 | |||
| 136 | %extend idevice { // Attach these functions to struct idevice | ||
| 137 | idevice() { | ||
| 138 | idevice* device = (idevice*) malloc(sizeof(idevice)); | ||
| 139 | device->dev = NULL; | ||
| 140 | return device; | ||
| 141 | } | ||
| 142 | |||
| 143 | ~idevice() { | ||
| 144 | my_delete_idevice($self); | ||
| 145 | } | ||
| 146 | |||
| 147 | void set_debug_level(int level) { | ||
| 148 | idevice_set_debug_level(level); | ||
| 149 | } | ||
| 150 | |||
| 151 | int init_device_by_uuid(char* uuid) { | ||
| 152 | if (IDEVICE_E_SUCCESS == idevice_new(&($self->dev), uuid)) | ||
| 153 | return 1; | ||
| 154 | return 0; | ||
| 155 | } | ||
| 156 | |||
| 157 | int init_device() { | ||
| 158 | if (IDEVICE_E_SUCCESS == idevice_new(&($self->dev), NULL)) | ||
| 159 | return 1; | ||
| 160 | return 0; | ||
| 161 | } | ||
| 162 | |||
| 163 | %newobject get_uuid; | ||
| 164 | char* get_uuid(){ | ||
| 165 | char* uuid = NULL; | ||
| 166 | idevice_get_uuid($self->dev, &uuid); | ||
| 167 | return uuid; | ||
| 168 | } | ||
| 169 | |||
| 170 | Lockdownd* get_lockdown_client() { | ||
| 171 | return my_new_Lockdownd($self); | ||
| 172 | } | ||
| 173 | }; | ||
| 174 | |||
| 175 | |||
| 176 | %extend Lockdownd { // Attach these functions to struct Lockdownd | ||
| 177 | Lockdownd(idevice* device) { | ||
| 178 | return my_new_Lockdownd(device); | ||
| 179 | } | ||
| 180 | |||
| 181 | ~Lockdownd() { | ||
| 182 | my_delete_Lockdownd($self); | ||
| 183 | } | ||
| 184 | |||
| 185 | void send(PList::Node* node) { | ||
| 186 | lockdownd_send($self->client, node->GetPlist()); | ||
| 187 | } | ||
| 188 | |||
| 189 | PList::Node* receive() { | ||
| 190 | plist_t node = NULL; | ||
| 191 | lockdownd_receive($self->client, &node); | ||
| 192 | return new_node_from_plist(node); | ||
| 193 | } | ||
| 194 | |||
| 195 | MobileSync* get_mobilesync_client() { | ||
| 196 | return my_new_MobileSync($self); | ||
| 197 | } | ||
| 198 | }; | ||
| 199 | |||
| 200 | %extend MobileSync { // Attach these functions to struct MobileSync | ||
| 201 | MobileSync(Lockdownd* lckd) { | ||
| 202 | return my_new_MobileSync(lckd); | ||
| 203 | } | ||
| 204 | |||
| 205 | ~MobileSync() { | ||
| 206 | mobilesync_client_free($self->client); | ||
| 207 | free($self); | ||
| 208 | } | ||
| 209 | |||
| 210 | void send(PList::Node* node) { | ||
| 211 | mobilesync_send($self->client, node->GetPlist()); | ||
| 212 | } | ||
| 213 | |||
| 214 | PList::Node* receive() { | ||
| 215 | plist_t node = NULL; | ||
| 216 | mobilesync_receive($self->client, &node); | ||
| 217 | return new_node_from_plist(node); | ||
| 218 | } | ||
| 219 | }; | ||
| 220 | |||
