summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2019-11-07 04:54:45 +0100
committerGravatar Nikias Bassen2019-11-07 04:54:45 +0100
commit49cbc8df7672c4dd5fa0c73e9046ee91924ae4b8 (patch)
treebc339ae6a11d149538d0a82af105bb73a86b6e17
parent4d4586903b4cbab8b307a406e894e34b4b19a723 (diff)
downloadlibplist-49cbc8df7672c4dd5fa0c73e9046ee91924ae4b8.tar.gz
libplist-49cbc8df7672c4dd5fa0c73e9046ee91924ae4b8.tar.bz2
Add plist_get_data_ptr() and plist_get_string_ptr() to the interface
-rw-r--r--include/plist/plist.h26
-rw-r--r--src/plist.c25
2 files changed, 51 insertions, 0 deletions
diff --git a/include/plist/plist.h b/include/plist/plist.h
index 824ba43..29b1fce 100644
--- a/include/plist/plist.h
+++ b/include/plist/plist.h
@@ -463,6 +463,19 @@ extern "C"
463 void plist_get_string_val(plist_t node, char **val); 463 void plist_get_string_val(plist_t node, char **val);
464 464
465 /** 465 /**
466 * Get a pointer to the buffer of a #PLIST_STRING node.
467 *
468 * @note DO NOT MODIFY the buffer. Mind that the buffer is only available
469 * until the plist node gets freed. Make a copy if needed.
470 *
471 * @param node The node
472 * @param length If non-NULL, will be set to the length of the string
473 *
474 * @return Pointer to the NULL-terminated buffer.
475 */
476 const char* plist_get_string_ptr(plist_t node, uint64_t* length);
477
478 /**
466 * Get the value of a #PLIST_BOOLEAN node. 479 * Get the value of a #PLIST_BOOLEAN node.
467 * This function does nothing if node is not of type #PLIST_BOOLEAN 480 * This function does nothing if node is not of type #PLIST_BOOLEAN
468 * 481 *
@@ -501,6 +514,19 @@ extern "C"
501 void plist_get_data_val(plist_t node, char **val, uint64_t * length); 514 void plist_get_data_val(plist_t node, char **val, uint64_t * length);
502 515
503 /** 516 /**
517 * Get a pointer to the data buffer of a #PLIST_DATA node.
518 *
519 * @note DO NOT MODIFY the buffer. Mind that the buffer is only available
520 * until the plist node gets freed. Make a copy if needed.
521 *
522 * @param node The node
523 * @param length Pointer to a uint64_t that will be set to the length of the buffer
524 *
525 * @return Pointer to the buffer
526 */
527 const char* plist_get_data_ptr(plist_t node, uint64_t* length);
528
529 /**
504 * Get the value of a #PLIST_DATE node. 530 * Get the value of a #PLIST_DATE node.
505 * This function does nothing if node is not of type #PLIST_DATE 531 * This function does nothing if node is not of type #PLIST_DATE
506 * 532 *
diff --git a/src/plist.c b/src/plist.c
index eb0160c..87be488 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -868,6 +868,19 @@ PLIST_API void plist_get_string_val(plist_t node, char **val)
868 assert(length == strlen(*val)); 868 assert(length == strlen(*val));
869} 869}
870 870
871PLIST_API const char* plist_get_string_ptr(plist_t node, uint64_t* length)
872{
873 if (!node)
874 return NULL;
875 plist_type type = plist_get_node_type(node);
876 if (PLIST_STRING != type)
877 return NULL;
878 plist_data_t data = plist_get_data(node);
879 if (length)
880 *length = data->length;
881 return (const char*)data->strval;
882}
883
871PLIST_API void plist_get_bool_val(plist_t node, uint8_t * val) 884PLIST_API void plist_get_bool_val(plist_t node, uint8_t * val)
872{ 885{
873 if (!node || !val) 886 if (!node || !val)
@@ -926,6 +939,18 @@ PLIST_API void plist_get_data_val(plist_t node, char **val, uint64_t * length)
926 plist_get_type_and_value(node, &type, (void *) val, length); 939 plist_get_type_and_value(node, &type, (void *) val, length);
927} 940}
928 941
942PLIST_API const char* plist_get_data_ptr(plist_t node, uint64_t* length)
943{
944 if (!node || !length)
945 return NULL;
946 plist_type type = plist_get_node_type(node);
947 if (PLIST_DATA != type)
948 return NULL;
949 plist_data_t data = plist_get_data(node);
950 *length = data->length;
951 return (const char*)data->buff;
952}
953
929PLIST_API void plist_get_date_val(plist_t node, int32_t * sec, int32_t * usec) 954PLIST_API void plist_get_date_val(plist_t node, int32_t * sec, int32_t * usec)
930{ 955{
931 if (!node) 956 if (!node)