diff options
| author | 2016-05-12 02:52:50 +0200 | |
|---|---|---|
| committer | 2016-05-12 02:52:50 +0200 | |
| commit | 449e27bf754f903f856a741e163a9e4a0c8037b0 (patch) | |
| tree | 209201532a9ba1c255c412a9f3257fd078d17091 | |
| parent | 19735fbd32ddbc9874f8aca12ac6e86239441dcd (diff) | |
| download | libplist-449e27bf754f903f856a741e163a9e4a0c8037b0.tar.gz libplist-449e27bf754f903f856a741e163a9e4a0c8037b0.tar.bz2 | |
Add plist_is_binary()
It can be useful if one needs to know what type of plist a memory buffer
contains.
| -rw-r--r-- | include/plist/plist.h | 13 | ||||
| -rw-r--r-- | src/plist.c | 9 |
2 files changed, 22 insertions, 0 deletions
diff --git a/include/plist/plist.h b/include/plist/plist.h index acd1c4d..2b7e1a1 100644 --- a/include/plist/plist.h +++ b/include/plist/plist.h | |||
| @@ -616,6 +616,19 @@ extern "C" | |||
| 616 | */ | 616 | */ |
| 617 | void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist); | 617 | void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist); |
| 618 | 618 | ||
| 619 | /** | ||
| 620 | * Test if in-memory plist data is binary or XML | ||
| 621 | * This method will look at the first bytes of plist_data | ||
| 622 | * to determine if plist_data contains a binary or XML plist. | ||
| 623 | * This method is not validating the whole memory buffer to check if the | ||
| 624 | * content is truly a plist, it's only using some heuristic on the first few | ||
| 625 | * bytes of plist_data. | ||
| 626 | * | ||
| 627 | * @param plist_data a pointer to the memory buffer containing plist data. | ||
| 628 | * @param length length of the buffer to read. | ||
| 629 | * @return 1 if the buffer is a binary plist, 0 otherwise. | ||
| 630 | */ | ||
| 631 | int plist_is_binary(const char *plist_data, uint32_t length); | ||
| 619 | 632 | ||
| 620 | /******************************************** | 633 | /******************************************** |
| 621 | * * | 634 | * * |
diff --git a/src/plist.c b/src/plist.c index 569251b..3e69e2a 100644 --- a/src/plist.c +++ b/src/plist.c | |||
| @@ -49,6 +49,15 @@ void plist_cleanup(void) | |||
| 49 | xmlCleanupMemory(); | 49 | xmlCleanupMemory(); |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | PLIST_API int plist_is_binary(const char *plist_data, uint32_t length) | ||
| 53 | { | ||
| 54 | if (length < 8) { | ||
| 55 | return 0; | ||
| 56 | } | ||
| 57 | |||
| 58 | return (memcmp(plist_data, "bplist00", 8) == 0); | ||
| 59 | } | ||
| 60 | |||
| 52 | plist_t plist_new_node(plist_data_t data) | 61 | plist_t plist_new_node(plist_data_t data) |
| 53 | { | 62 | { |
| 54 | return (plist_t) node_create(NULL, data); | 63 | return (plist_t) node_create(NULL, data); |
