Commit 11d639f9 authored by Christophe Fergeau's avatar Christophe Fergeau Committed by Nikias Bassen

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.
parent 449e27bf
...@@ -616,6 +616,17 @@ extern "C" ...@@ -616,6 +616,17 @@ extern "C"
*/ */
void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist); void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist);
/**
* Import the #plist_t structure from memory data.
* This method will look at the first bytes of plist_data
* to determine if plist_data contains a binary or XML plist.
*
* @param plist_data a pointer to the memory buffer containing plist data.
* @param length length of the buffer to read.
* @param plist a pointer to the imported plist.
*/
void plist_from_memory(const char *plist_data, uint32_t length, plist_t * plist);
/** /**
* Test if in-memory plist data is binary or XML * Test if in-memory plist data is binary or XML
* This method will look at the first bytes of plist_data * This method will look at the first bytes of plist_data
......
...@@ -58,6 +58,21 @@ PLIST_API int plist_is_binary(const char *plist_data, uint32_t length) ...@@ -58,6 +58,21 @@ PLIST_API int plist_is_binary(const char *plist_data, uint32_t length)
return (memcmp(plist_data, "bplist00", 8) == 0); return (memcmp(plist_data, "bplist00", 8) == 0);
} }
PLIST_API void plist_from_memory(const char *plist_data, uint32_t length, plist_t * plist)
{
if (length < 8) {
*plist = NULL;
return;
}
if (plist_is_binary(plist_data, length)) {
plist_from_bin(plist_data, length, plist);
} else {
plist_from_xml(plist_data, length, plist);
}
}
plist_t plist_new_node(plist_data_t data) plist_t plist_new_node(plist_data_t data)
{ {
return (plist_t) node_create(NULL, data); return (plist_t) node_create(NULL, data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment