summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christophe Fergeau2016-05-12 02:55:01 +0200
committerGravatar Nikias Bassen2016-05-12 02:55:01 +0200
commit11d639f92f2c7067a0e7cc949f147abd506514ec (patch)
treefef75bcb253462541982c678d0b7260fc5141811
parent449e27bf754f903f856a741e163a9e4a0c8037b0 (diff)
downloadlibplist-11d639f92f2c7067a0e7cc949f147abd506514ec.tar.gz
libplist-11d639f92f2c7067a0e7cc949f147abd506514ec.tar.bz2
Implement plist_from_memory()
Rather than having everyone reimplement binary/XML plist detection by looking at the first bytes of the plist content, it's better to do this detection in libplist and hide that internal detail from library users.
-rw-r--r--include/plist/plist.h11
-rw-r--r--src/plist.c15
2 files changed, 26 insertions, 0 deletions
diff --git a/include/plist/plist.h b/include/plist/plist.h
index 2b7e1a1..7e59acb 100644
--- a/include/plist/plist.h
+++ b/include/plist/plist.h
@@ -617,6 +617,17 @@ extern "C"
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 /** 619 /**
620 * Import the #plist_t structure from memory data.
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 *
624 * @param plist_data a pointer to the memory buffer containing plist data.
625 * @param length length of the buffer to read.
626 * @param plist a pointer to the imported plist.
627 */
628 void plist_from_memory(const char *plist_data, uint32_t length, plist_t * plist);
629
630 /**
620 * Test if in-memory plist data is binary or XML 631 * Test if in-memory plist data is binary or XML
621 * This method will look at the first bytes of plist_data 632 * This method will look at the first bytes of plist_data
622 * to determine if plist_data contains a binary or XML plist. 633 * to determine if plist_data contains a binary or XML plist.
diff --git a/src/plist.c b/src/plist.c
index 3e69e2a..1ff17fc 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -58,6 +58,21 @@ PLIST_API int plist_is_binary(const char *plist_data, uint32_t length)
58 return (memcmp(plist_data, "bplist00", 8) == 0); 58 return (memcmp(plist_data, "bplist00", 8) == 0);
59} 59}
60 60
61
62PLIST_API void plist_from_memory(const char *plist_data, uint32_t length, plist_t * plist)
63{
64 if (length < 8) {
65 *plist = NULL;
66 return;
67 }
68
69 if (plist_is_binary(plist_data, length)) {
70 plist_from_bin(plist_data, length, plist);
71 } else {
72 plist_from_xml(plist_data, length, plist);
73 }
74}
75
61plist_t plist_new_node(plist_data_t data) 76plist_t plist_new_node(plist_data_t data)
62{ 77{
63 return (plist_t) node_create(NULL, data); 78 return (plist_t) node_create(NULL, data);