summaryrefslogtreecommitdiffstats
path: root/swig/plist.i
diff options
context:
space:
mode:
Diffstat (limited to 'swig/plist.i')
-rw-r--r--swig/plist.i61
1 files changed, 36 insertions, 25 deletions
diff --git a/swig/plist.i b/swig/plist.i
index 5987b77..79298e6 100644
--- a/swig/plist.i
+++ b/swig/plist.i
@@ -22,6 +22,7 @@ PListNode *allocate_wrapper(plist_t plist, char should_keep_plist) {
22 %} 22 %}
23 23
24%include "stdint.i" 24%include "stdint.i"
25%include "cstring.i"
25 26
26/* Parse the header file to generate wrappers */ 27/* Parse the header file to generate wrappers */
27typedef enum { 28typedef enum {
@@ -39,8 +40,6 @@ typedef enum {
39} plist_type; 40} plist_type;
40 41
41typedef struct { 42typedef struct {
42 plist_t node;
43 char should_keep_plist;
44} PListNode; 43} PListNode;
45 44
46%extend PListNode { // Attach these functions to struct Vector 45%extend PListNode { // Attach these functions to struct Vector
@@ -60,19 +59,19 @@ typedef struct {
60 return node; 59 return node;
61 } 60 }
62 61
63 PListNode(char* xml) { 62 %cstring_input_binary(char *data, uint64_t len);
64 plist_t plist = NULL; 63 PListNode(char *data, uint64_t len) {
65 plist_from_xml(xml, strlen(xml), &plist); 64 //first check input
66 if (plist) 65 if (len > 8) {
67 return allocate_wrapper( plist, 0 ); 66 plist_t plist = NULL;
68 return NULL; 67 if (memcmp(data, "bplist00", 8) == 0) {
69 } 68 plist_from_bin(data, len, &plist);
70 69 } else {
71 PListNode(char* bin, uint64_t len) { 70 plist_from_xml(data, len, &plist);
72 plist_t plist = NULL; 71 }
73 plist_from_bin(bin, len, &plist); 72 if (plist)
74 if (plist) 73 return allocate_wrapper( plist, 0 );
75 return allocate_wrapper( plist, 0 ); 74 }
76 return NULL; 75 return NULL;
77 } 76 }
78 77
@@ -114,8 +113,9 @@ typedef struct {
114 plist_add_sub_real_el($self->node, d); 113 plist_add_sub_real_el($self->node, d);
115 } 114 }
116 115
117 void add_sub_data(char* v, uint64_t l) { 116 %cstring_input_binary(char *data, uint64_t len);
118 plist_add_sub_data_el($self->node, v, l); 117 void add_sub_data(char *data, uint64_t len) {
118 plist_add_sub_data_el($self->node, data, len);
119 } 119 }
120 120
121 PListNode* get_first_child() { 121 PListNode* get_first_child() {
@@ -142,12 +142,14 @@ typedef struct {
142 return NULL; 142 return NULL;
143 } 143 }
144 144
145 %newobject as_key;
145 char* as_key() { 146 char* as_key() {
146 char* k = NULL; 147 char* k = NULL;
147 plist_get_key_val($self->node, &k); 148 plist_get_key_val($self->node, &k);
148 return k; 149 return k;
149 } 150 }
150 151
152 %newobject as_string;
151 char* as_string() { 153 char* as_string() {
152 char* s = NULL; 154 char* s = NULL;
153 plist_get_string_val($self->node, &s); 155 plist_get_string_val($self->node, &s);
@@ -172,11 +174,14 @@ typedef struct {
172 return d; 174 return d;
173 } 175 }
174 176
175 char* as_data() { 177 %cstring_output_allocate_size(char **STRING, uint64_t *LENGTH, free(*$1));
176 char* v; 178 void as_data(char **STRING, uint64_t *LENGTH) {
179 char* s = NULL;
177 uint64_t l; 180 uint64_t l;
178 plist_get_data_val($self->node, &v, &l); 181 plist_get_data_val($self->node, &s, &l);
179 return v; 182 *STRING = s;
183 *LENGTH = l;
184 return;
180 } 185 }
181 186
182 plist_type get_type() { 187 plist_type get_type() {
@@ -215,6 +220,7 @@ typedef struct {
215 return NULL; 220 return NULL;
216 } 221 }
217 222
223 %newobject to_xml;
218 char* to_xml () { 224 char* to_xml () {
219 char* s = NULL; 225 char* s = NULL;
220 uint32_t l; 226 uint32_t l;
@@ -222,22 +228,27 @@ typedef struct {
222 return s; 228 return s;
223 } 229 }
224 230
225 char* to_bin () { 231 %cstring_output_allocate_size(char **STRING, uint64_t *LENGTH, free(*$1));
232 void to_bin(char **STRING, uint64_t *LENGTH) {
226 char* s = NULL; 233 char* s = NULL;
227 uint32_t l; 234 uint32_t l;
228 plist_to_bin($self->node, &s, &l); 235 plist_to_bin($self->node, &s, &l);
229 return s; 236 *STRING = s;
237 *LENGTH = l;
238 return;
230 } 239 }
231 240
232 void from_xml (char* xml) { 241 %cstring_input_binary(char *data, uint64_t len);
242 void from_xml (char *data, uint64_t len) {
233 if (!$self->should_keep_plist) { 243 if (!$self->should_keep_plist) {
234 plist_free($self->node); 244 plist_free($self->node);
235 } 245 }
236 $self->node = NULL; 246 $self->node = NULL;
237 $self->should_keep_plist = 0; 247 $self->should_keep_plist = 0;
238 plist_from_xml(xml, strlen(xml), &$self->node); 248 plist_from_xml(data, len, &$self->node);
239 } 249 }
240 250
251 %cstring_input_binary(char *data, uint64_t len);
241 void from_bin (char* data, uint64_t len) { 252 void from_bin (char* data, uint64_t len) {
242 if (!$self->should_keep_plist) { 253 if (!$self->should_keep_plist) {
243 plist_free($self->node); 254 plist_free($self->node);