diff options
| author | 2023-01-16 04:25:52 +0100 | |
|---|---|---|
| committer | 2023-01-16 04:25:52 +0100 | |
| commit | d886885b0ec2506fa2caf0986a3d0e496fea91c2 (patch) | |
| tree | 58bc4bcd1963ea885abd60a65bf87a2685526714 /src/bplist.c | |
| parent | 47a7fbe438ee7350a2b151e007f07043ef596775 (diff) | |
| download | libplist-d886885b0ec2506fa2caf0986a3d0e496fea91c2.tar.gz libplist-d886885b0ec2506fa2caf0986a3d0e496fea91c2.tar.bz2 | |
Rename PLIST_UINT to PLIST_INT and add plist_new_int() and plist_get_int_val()
This properly supports getting and setting signed or unsigned integer values.
Also, a new helper function plist_int_val_is_negative() was added to determine if
a given #PLIST_INT node has a negative value or not.
The old type PLIST_UINT is defined as a macro with the value of PLIST_INT for
backwards compatibility.
This commit also adds int vs. uint support to the C++ interface, and the python
bindings in a hopefully useful way.
Diffstat (limited to 'src/bplist.c')
| -rw-r--r-- | src/bplist.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/bplist.c b/src/bplist.c index 851ecd6..8927de6 100644 --- a/src/bplist.c +++ b/src/bplist.c | |||
| @@ -62,7 +62,7 @@ enum | |||
| 62 | BPLIST_FALSE = 0x08, | 62 | BPLIST_FALSE = 0x08, |
| 63 | BPLIST_TRUE = 0x09, | 63 | BPLIST_TRUE = 0x09, |
| 64 | BPLIST_FILL = 0x0F, /* will be used for length grabbing */ | 64 | BPLIST_FILL = 0x0F, /* will be used for length grabbing */ |
| 65 | BPLIST_UINT = 0x10, | 65 | BPLIST_INT = 0x10, |
| 66 | BPLIST_REAL = 0x20, | 66 | BPLIST_REAL = 0x20, |
| 67 | BPLIST_DATE = 0x30, | 67 | BPLIST_DATE = 0x30, |
| 68 | BPLIST_DATA = 0x40, | 68 | BPLIST_DATA = 0x40, |
| @@ -229,7 +229,7 @@ void plist_bin_deinit(void) | |||
| 229 | 229 | ||
| 230 | static plist_t parse_bin_node_at_index(struct bplist_data *bplist, uint32_t node_index); | 230 | static plist_t parse_bin_node_at_index(struct bplist_data *bplist, uint32_t node_index); |
| 231 | 231 | ||
| 232 | static plist_t parse_uint_node(const char **bnode, uint8_t size) | 232 | static plist_t parse_int_node(const char **bnode, uint8_t size) |
| 233 | { | 233 | { |
| 234 | plist_data_t data = plist_new_plist_data(); | 234 | plist_data_t data = plist_new_plist_data(); |
| 235 | 235 | ||
| @@ -254,7 +254,7 @@ static plist_t parse_uint_node(const char **bnode, uint8_t size) | |||
| 254 | data->intval = UINT_TO_HOST(*bnode, size); | 254 | data->intval = UINT_TO_HOST(*bnode, size); |
| 255 | 255 | ||
| 256 | (*bnode) += size; | 256 | (*bnode) += size; |
| 257 | data->type = PLIST_UINT; | 257 | data->type = PLIST_INT; |
| 258 | 258 | ||
| 259 | return node_create(NULL, data); | 259 | return node_create(NULL, data); |
| 260 | } | 260 | } |
| @@ -583,8 +583,8 @@ static plist_t parse_bin_node(struct bplist_data *bplist, const char** object) | |||
| 583 | case BPLIST_DICT: | 583 | case BPLIST_DICT: |
| 584 | { | 584 | { |
| 585 | uint16_t next_size = **object & BPLIST_FILL; | 585 | uint16_t next_size = **object & BPLIST_FILL; |
| 586 | if ((**object & BPLIST_MASK) != BPLIST_UINT) { | 586 | if ((**object & BPLIST_MASK) != BPLIST_INT) { |
| 587 | PLIST_BIN_ERR("%s: invalid size node type for node type 0x%02x: found 0x%02x, expected 0x%02x\n", __func__, type, **object & BPLIST_MASK, BPLIST_UINT); | 587 | PLIST_BIN_ERR("%s: invalid size node type for node type 0x%02x: found 0x%02x, expected 0x%02x\n", __func__, type, **object & BPLIST_MASK, BPLIST_INT); |
| 588 | return NULL; | 588 | return NULL; |
| 589 | } | 589 | } |
| 590 | (*object)++; | 590 | (*object)++; |
| @@ -641,12 +641,12 @@ static plist_t parse_bin_node(struct bplist_data *bplist, const char** object) | |||
| 641 | return NULL; | 641 | return NULL; |
| 642 | } | 642 | } |
| 643 | 643 | ||
| 644 | case BPLIST_UINT: | 644 | case BPLIST_INT: |
| 645 | if (pobject + (uint64_t)(1 << size) > poffset_table) { | 645 | if (pobject + (uint64_t)(1 << size) > poffset_table) { |
| 646 | PLIST_BIN_ERR("%s: BPLIST_UINT data bytes point outside of valid range\n", __func__); | 646 | PLIST_BIN_ERR("%s: BPLIST_INT data bytes point outside of valid range\n", __func__); |
| 647 | return NULL; | 647 | return NULL; |
| 648 | } | 648 | } |
| 649 | return parse_uint_node(object, size); | 649 | return parse_int_node(object, size); |
| 650 | 650 | ||
| 651 | case BPLIST_REAL: | 651 | case BPLIST_REAL: |
| 652 | if (pobject + (uint64_t)(1 << size) > poffset_table) { | 652 | if (pobject + (uint64_t)(1 << size) > poffset_table) { |
| @@ -896,7 +896,7 @@ static unsigned int plist_data_hash(const void* key) | |||
| 896 | switch (data->type) | 896 | switch (data->type) |
| 897 | { | 897 | { |
| 898 | case PLIST_BOOLEAN: | 898 | case PLIST_BOOLEAN: |
| 899 | case PLIST_UINT: | 899 | case PLIST_INT: |
| 900 | case PLIST_REAL: | 900 | case PLIST_REAL: |
| 901 | case PLIST_DATE: | 901 | case PLIST_DATE: |
| 902 | case PLIST_UID: | 902 | case PLIST_UID: |
| @@ -973,7 +973,7 @@ static void write_int(bytearray_t * bplist, uint64_t val) | |||
| 973 | //do not write 3bytes int node | 973 | //do not write 3bytes int node |
| 974 | if (size == 3) | 974 | if (size == 3) |
| 975 | size++; | 975 | size++; |
| 976 | sz = BPLIST_UINT | Log2(size); | 976 | sz = BPLIST_INT | Log2(size); |
| 977 | 977 | ||
| 978 | val = be64toh(val); | 978 | val = be64toh(val); |
| 979 | byte_array_append(bplist, &sz, 1); | 979 | byte_array_append(bplist, &sz, 1); |
| @@ -982,7 +982,7 @@ static void write_int(bytearray_t * bplist, uint64_t val) | |||
| 982 | 982 | ||
| 983 | static void write_uint(bytearray_t * bplist, uint64_t val) | 983 | static void write_uint(bytearray_t * bplist, uint64_t val) |
| 984 | { | 984 | { |
| 985 | uint8_t sz = BPLIST_UINT | 4; | 985 | uint8_t sz = BPLIST_INT | 4; |
| 986 | uint64_t zero = 0; | 986 | uint64_t zero = 0; |
| 987 | 987 | ||
| 988 | val = be64toh(val); | 988 | val = be64toh(val); |
| @@ -1346,7 +1346,7 @@ PLIST_API plist_err_t plist_to_bin(plist_t plist, char **plist_bin, uint32_t * l | |||
| 1346 | byte_array_append(bplist_buff, &b, 1); | 1346 | byte_array_append(bplist_buff, &b, 1); |
| 1347 | break; | 1347 | break; |
| 1348 | } | 1348 | } |
| 1349 | case PLIST_UINT: | 1349 | case PLIST_INT: |
| 1350 | if (data->length == 16) { | 1350 | if (data->length == 16) { |
| 1351 | write_uint(bplist_buff, data->intval); | 1351 | write_uint(bplist_buff, data->intval); |
| 1352 | } else { | 1352 | } else { |
