summaryrefslogtreecommitdiffstats
path: root/swig
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2009-04-19 22:00:21 +0200
committerGravatar Jonathan Beck2009-04-19 22:00:21 +0200
commit0a050c5c74fda302d563d4138f83ec17fc6d393c (patch)
tree9fc0033e0fd6d0e5bc7f4ad5c54c508555659024 /swig
parent33ca54263ea530d438e54733c8d495952c0b6cdd (diff)
downloadlibplist-0a050c5c74fda302d563d4138f83ec17fc6d393c.tar.gz
libplist-0a050c5c74fda302d563d4138f83ec17fc6d393c.tar.bz2
Use CString SWIG library to handle binary buffers.
Diffstat (limited to 'swig')
-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) {
%}
%include "stdint.i"
+%include "cstring.i"
/* Parse the header file to generate wrappers */
typedef enum {
@@ -39,8 +40,6 @@ typedef enum {
} plist_type;
typedef struct {
- plist_t node;
- char should_keep_plist;
} PListNode;
%extend PListNode { // Attach these functions to struct Vector
@@ -60,19 +59,19 @@ typedef struct {
return node;
}
- PListNode(char* xml) {
- plist_t plist = NULL;
- plist_from_xml(xml, strlen(xml), &plist);
- if (plist)
- return allocate_wrapper( plist, 0 );
- return NULL;
- }
-
- PListNode(char* bin, uint64_t len) {
- plist_t plist = NULL;
- plist_from_bin(bin, len, &plist);
- if (plist)
- return allocate_wrapper( plist, 0 );
+ %cstring_input_binary(char *data, uint64_t len);
+ PListNode(char *data, uint64_t len) {
+ //first check input
+ if (len > 8) {
+ plist_t plist = NULL;
+ if (memcmp(data, "bplist00", 8) == 0) {
+ plist_from_bin(data, len, &plist);
+ } else {
+ plist_from_xml(data, len, &plist);
+ }
+ if (plist)
+ return allocate_wrapper( plist, 0 );
+ }
return NULL;
}
@@ -114,8 +113,9 @@ typedef struct {
plist_add_sub_real_el($self->node, d);
}
- void add_sub_data(char* v, uint64_t l) {
- plist_add_sub_data_el($self->node, v, l);
+ %cstring_input_binary(char *data, uint64_t len);
+ void add_sub_data(char *data, uint64_t len) {
+ plist_add_sub_data_el($self->node, data, len);
}
PListNode* get_first_child() {
@@ -142,12 +142,14 @@ typedef struct {
return NULL;
}
+ %newobject as_key;
char* as_key() {
char* k = NULL;
plist_get_key_val($self->node, &k);
return k;
}
+ %newobject as_string;
char* as_string() {
char* s = NULL;
plist_get_string_val($self->node, &s);
@@ -172,11 +174,14 @@ typedef struct {
return d;
}
- char* as_data() {
- char* v;
+ %cstring_output_allocate_size(char **STRING, uint64_t *LENGTH, free(*$1));
+ void as_data(char **STRING, uint64_t *LENGTH) {
+ char* s = NULL;
uint64_t l;
- plist_get_data_val($self->node, &v, &l);
- return v;
+ plist_get_data_val($self->node, &s, &l);
+ *STRING = s;
+ *LENGTH = l;
+ return;
}
plist_type get_type() {
@@ -215,6 +220,7 @@ typedef struct {
return NULL;
}
+ %newobject to_xml;
char* to_xml () {
char* s = NULL;
uint32_t l;
@@ -222,22 +228,27 @@ typedef struct {
return s;
}
- char* to_bin () {
+ %cstring_output_allocate_size(char **STRING, uint64_t *LENGTH, free(*$1));
+ void to_bin(char **STRING, uint64_t *LENGTH) {
char* s = NULL;
uint32_t l;
plist_to_bin($self->node, &s, &l);
- return s;
+ *STRING = s;
+ *LENGTH = l;
+ return;
}
- void from_xml (char* xml) {
+ %cstring_input_binary(char *data, uint64_t len);
+ void from_xml (char *data, uint64_t len) {
if (!$self->should_keep_plist) {
plist_free($self->node);
}
$self->node = NULL;
$self->should_keep_plist = 0;
- plist_from_xml(xml, strlen(xml), &$self->node);
+ plist_from_xml(data, len, &$self->node);
}
+ %cstring_input_binary(char *data, uint64_t len);
void from_bin (char* data, uint64_t len) {
if (!$self->should_keep_plist) {
plist_free($self->node);