summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plist.c69
1 files changed, 50 insertions, 19 deletions
diff --git a/src/plist.c b/src/plist.c
index 1b33ec3..70386bc 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -23,11 +23,11 @@
23 23
24 24
25#include <string.h> 25#include <string.h>
26#include <assert.h>
27#include "plist.h" 26#include "plist.h"
28#include <stdlib.h> 27#include <stdlib.h>
29#include <stdio.h> 28#include <stdio.h>
30#include <math.h> 29#include <math.h>
30#include <assert.h>
31 31
32#ifdef WIN32 32#ifdef WIN32
33#include <windows.h> 33#include <windows.h>
@@ -324,6 +324,7 @@ static void plist_copy_node(node_t *node, void *parent_node_ptr)
324 plist_data_t newdata = plist_new_plist_data(); 324 plist_data_t newdata = plist_new_plist_data();
325 325
326 assert(data); // plist should always have data 326 assert(data); // plist should always have data
327 assert(newdata);
327 328
328 memcpy(newdata, data, sizeof(struct plist_data_s)); 329 memcpy(newdata, data, sizeof(struct plist_data_s));
329 330
@@ -761,75 +762,105 @@ PLIST_API plist_type plist_get_node_type(plist_t node)
761 762
762PLIST_API void plist_get_key_val(plist_t node, char **val) 763PLIST_API void plist_get_key_val(plist_t node, char **val)
763{ 764{
765 if (!node || !val)
766 return;
764 plist_type type = plist_get_node_type(node); 767 plist_type type = plist_get_node_type(node);
765 uint64_t length = 0; 768 uint64_t length = 0;
766 if (PLIST_KEY == type) 769 if (PLIST_KEY != type)
767 plist_get_type_and_value(node, &type, (void *) val, &length); 770 return;
771 plist_get_type_and_value(node, &type, (void *) val, &length);
772 if (!*val)
773 return;
768 assert(length == strlen(*val)); 774 assert(length == strlen(*val));
769} 775}
770 776
771PLIST_API void plist_get_string_val(plist_t node, char **val) 777PLIST_API void plist_get_string_val(plist_t node, char **val)
772{ 778{
779 if (!node || !val)
780 return;
773 plist_type type = plist_get_node_type(node); 781 plist_type type = plist_get_node_type(node);
774 uint64_t length = 0; 782 uint64_t length = 0;
775 if (PLIST_STRING == type) 783 if (PLIST_STRING != type)
776 plist_get_type_and_value(node, &type, (void *) val, &length); 784 return;
785 plist_get_type_and_value(node, &type, (void *) val, &length);
786 if (!*val)
787 return;
777 assert(length == strlen(*val)); 788 assert(length == strlen(*val));
778} 789}
779 790
780PLIST_API void plist_get_bool_val(plist_t node, uint8_t * val) 791PLIST_API void plist_get_bool_val(plist_t node, uint8_t * val)
781{ 792{
793 if (!node || !val)
794 return;
782 plist_type type = plist_get_node_type(node); 795 plist_type type = plist_get_node_type(node);
783 uint64_t length = 0; 796 uint64_t length = 0;
784 if (PLIST_BOOLEAN == type) 797 if (PLIST_BOOLEAN != type)
785 plist_get_type_and_value(node, &type, (void *) val, &length); 798 return;
799 plist_get_type_and_value(node, &type, (void *) val, &length);
786 assert(length == sizeof(uint8_t)); 800 assert(length == sizeof(uint8_t));
787} 801}
788 802
789PLIST_API void plist_get_uint_val(plist_t node, uint64_t * val) 803PLIST_API void plist_get_uint_val(plist_t node, uint64_t * val)
790{ 804{
805 if (!node || !val)
806 return;
791 plist_type type = plist_get_node_type(node); 807 plist_type type = plist_get_node_type(node);
792 uint64_t length = 0; 808 uint64_t length = 0;
793 if (PLIST_UINT == type) 809 if (PLIST_UINT != type)
794 plist_get_type_and_value(node, &type, (void *) val, &length); 810 return;
811 plist_get_type_and_value(node, &type, (void *) val, &length);
795 assert(length == sizeof(uint64_t) || length == 16); 812 assert(length == sizeof(uint64_t) || length == 16);
796} 813}
797 814
798PLIST_API void plist_get_uid_val(plist_t node, uint64_t * val) 815PLIST_API void plist_get_uid_val(plist_t node, uint64_t * val)
799{ 816{
817 if (!node || !val)
818 return;
800 plist_type type = plist_get_node_type(node); 819 plist_type type = plist_get_node_type(node);
801 uint64_t length = 0; 820 uint64_t length = 0;
802 if (PLIST_UID == type) 821 if (PLIST_UID != type)
803 plist_get_type_and_value(node, &type, (void *) val, &length); 822 return;
823 plist_get_type_and_value(node, &type, (void *) val, &length);
804 assert(length == sizeof(uint64_t)); 824 assert(length == sizeof(uint64_t));
805} 825}
806 826
807PLIST_API void plist_get_real_val(plist_t node, double *val) 827PLIST_API void plist_get_real_val(plist_t node, double *val)
808{ 828{
829 if (!node || !val)
830 return;
809 plist_type type = plist_get_node_type(node); 831 plist_type type = plist_get_node_type(node);
810 uint64_t length = 0; 832 uint64_t length = 0;
811 if (PLIST_REAL == type) 833 if (PLIST_REAL != type)
812 plist_get_type_and_value(node, &type, (void *) val, &length); 834 return;
835 plist_get_type_and_value(node, &type, (void *) val, &length);
813 assert(length == sizeof(double)); 836 assert(length == sizeof(double));
814} 837}
815 838
816PLIST_API void plist_get_data_val(plist_t node, char **val, uint64_t * length) 839PLIST_API void plist_get_data_val(plist_t node, char **val, uint64_t * length)
817{ 840{
841 if (!node || !val || !length)
842 return;
818 plist_type type = plist_get_node_type(node); 843 plist_type type = plist_get_node_type(node);
819 if (PLIST_DATA == type) 844 if (PLIST_DATA != type)
820 plist_get_type_and_value(node, &type, (void *) val, length); 845 return;
846 plist_get_type_and_value(node, &type, (void *) val, length);
821} 847}
822 848
823PLIST_API void plist_get_date_val(plist_t node, int32_t * sec, int32_t * usec) 849PLIST_API void plist_get_date_val(plist_t node, int32_t * sec, int32_t * usec)
824{ 850{
851 if (!node)
852 return;
825 plist_type type = plist_get_node_type(node); 853 plist_type type = plist_get_node_type(node);
826 uint64_t length = 0; 854 uint64_t length = 0;
827 double val = 0; 855 double val = 0;
828 if (PLIST_DATE == type) 856 if (PLIST_DATE != type)
829 plist_get_type_and_value(node, &type, (void *) &val, &length); 857 return;
858 plist_get_type_and_value(node, &type, (void *) &val, &length);
830 assert(length == sizeof(double)); 859 assert(length == sizeof(double));
831 *sec = (int32_t)val; 860 if (sec)
832 *usec = (int32_t)fabs((val - (int64_t)val) * 1000000); 861 *sec = (int32_t)val;
862 if (usec)
863 *usec = (int32_t)fabs((val - (int64_t)val) * 1000000);
833} 864}
834 865
835int plist_data_compare(const void *a, const void *b) 866int plist_data_compare(const void *a, const void *b)