summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2009-11-10 23:37:43 +0100
committerGravatar Jonathan Beck2009-11-10 23:37:43 +0100
commitff536344bc04ab9ec3763968b82997d07312acd6 (patch)
tree48aa02beef8c8a0dc686683f7a1294871149646f
parent51c24ae543bda324e4f16e17d189c8d8cd545fc1 (diff)
downloadlibplist-ff536344bc04ab9ec3763968b82997d07312acd6.tar.gz
libplist-ff536344bc04ab9ec3763968b82997d07312acd6.tar.bz2
Remove deprecated functions from API.
-rw-r--r--include/plist/plist.h162
-rw-r--r--src/plist.c189
-rw-r--r--test/CMakeLists.txt1
-rw-r--r--test/plist_cmp.c17
4 files changed, 18 insertions, 351 deletions
diff --git a/include/plist/plist.h b/include/plist/plist.h
index 47e5df3..1b1ac52 100644
--- a/include/plist/plist.h
+++ b/include/plist/plist.h
@@ -578,169 +578,7 @@ extern "C"
578 */ 578 */
579 PLIST_API char plist_compare_node_value(plist_t node_l, plist_t node_r); 579 PLIST_API char plist_compare_node_value(plist_t node_l, plist_t node_r);
580 580
581
582//DEPRECATED API BELOW
583
584 /*@}*/ 581 /*@}*/
585 /**
586 * \defgroup DeprecatedAPI Deprecated libplist API
587 */
588 /*@{*/
589
590 /********************************************
591 * *
592 * Tree navigation *
593 * *
594 ********************************************/
595
596 /**
597 * Get the first child of a node
598 *
599 * @param node the first child
600 */
601 PLIST_API plist_t plist_get_first_child(plist_t node);
602
603 /**
604 * Get the next sibling of a node
605 *
606 * @param node the next sibling
607 */
608 PLIST_API plist_t plist_get_next_sibling(plist_t node);
609
610 /**
611 * Get the previous sibling of a node
612 *
613 * @param node the previous sibling
614 */
615 PLIST_API plist_t plist_get_prev_sibling(plist_t node);
616
617 /**
618 * Get the nth child of a #PLIST_ARRAY node.
619 *
620 * @param node the node of type #PLIST_ARRAY
621 * @param n the index of the child to get. Range is [0, array_size[
622 * @return the nth children or NULL if node is not of type #PLIST_ARRAY
623 */
624 PLIST_API plist_t plist_get_array_nth_el(plist_t node, uint32_t n);
625
626 /**
627 * Get the child of a #PLIST_DICT node from the associated key value.
628 *
629 * @param node the node of type #PLIST_DICT
630 * @param key the key associated to the requested value
631 * @return the key associated value or NULL if node is not of type #PLIST_DICT
632 */
633 PLIST_API plist_t plist_get_dict_el_from_key(plist_t node, const char *key);
634
635
636 /********************************************
637 * *
638 * Setters *
639 * *
640 ********************************************/
641
642 /**
643 * Add a subnode to a node. The node must be of a structured type
644 * (ie #PLIST_DICT or #PLIST_ARRAY). This function fails silently
645 * if subnode already has a father.
646 *
647 * @param node the node to add a children to
648 * @param subnode the children node
649 */
650 PLIST_API void plist_add_sub_node(plist_t node, plist_t subnode);
651
652 /**
653 * Add a subnode of type #PLIST_KEY to a node. The node must be of a structured type
654 * (ie #PLIST_DICT or #PLIST_ARRAY).
655 *
656 * @param node the node to add a children to
657 * @param val the key value encoded as an ASCII string (must be null terminated)
658 */
659 PLIST_API void plist_add_sub_key_el(plist_t node, const char *val);
660
661 /**
662 * Add a subnode of type #PLIST_STRING to a node. The node must be of a structured type
663 * (ie #PLIST_DICT or #PLIST_ARRAY).
664 *
665 * @param node the node to add a children to
666 * @param val the string value encoded as an ASCII or UTF-8 string (must be null terminated)
667 */
668 PLIST_API void plist_add_sub_string_el(plist_t node, const char *val);
669
670 /**
671 * Add a subnode of type #PLIST_BOOLEAN to a node. The node must be of a structured type
672 * (ie #PLIST_DICT or #PLIST_ARRAY).
673 *
674 * @param node the node to add a children to
675 * @param val the boolean value (TRUE or FALSE)
676 */
677 PLIST_API void plist_add_sub_bool_el(plist_t node, uint8_t val);
678
679 /**
680 * Add a subnode of type #PLIST_UINT to a node. The node must be of a structured type
681 * (ie #PLIST_DICT or #PLIST_ARRAY).
682 *
683 * @param node the node to add a children to
684 * @param val the unsigned integer value
685 */
686 PLIST_API void plist_add_sub_uint_el(plist_t node, uint64_t val);
687
688 /**
689 * Add a subnode of type #PLIST_REAL to a node. The node must be of a structured type
690 * (ie #PLIST_DICT or #PLIST_ARRAY).
691 *
692 * @param node the node to add a children to
693 * @param val the real value
694 */
695 PLIST_API void plist_add_sub_real_el(plist_t node, double val);
696
697 /**
698 * Add a subnode of type #PLIST_DATA to a node. The node must be of a structured type
699 * (ie #PLIST_DICT or #PLIST_ARRAY).
700 *
701 * @param node the node to add a children to
702 * @param val the binary buffer
703 * @param length the length of the buffer
704 */
705 PLIST_API void plist_add_sub_data_el(plist_t node, const char *val, uint64_t length);
706
707 /**
708 * Add a subnode of type #PLIST_DATE to a node. The node must be of a structured type
709 * (ie #PLIST_DICT or #PLIST_ARRAY).
710 *
711 * @param node the node to add a children to
712 * @param sec the number of seconds since 01/01/2001
713 * @param usec the number of microseconds
714 */
715 PLIST_API void plist_add_sub_date_el(plist_t node, int32_t sec, int32_t usec);
716
717
718 /********************************************
719 * *
720 * Utils *
721 * *
722 ********************************************/
723
724 /**
725 * Find the first encountered #PLIST_KEY node mathing that key.
726 * Search is breath first order.
727 *
728 * @param plist the root node of the plist structure.
729 * @param value the ASCII Key to match.
730 */
731 PLIST_API plist_t plist_find_node_by_key(plist_t plist, const char *value);
732
733 /**
734 * Find the first encountered #PLIST_STRING node mathing that string.
735 * Search is breath first order.
736 *
737 * @param plist the root node of the plist structure.
738 * @param value the ASCII String to match.
739 */
740 PLIST_API plist_t plist_find_node_by_string(plist_t plist, const char *value);
741
742 /*@}*/
743
744 582
745#ifdef __cplusplus 583#ifdef __cplusplus
746} 584}
diff --git a/src/plist.c b/src/plist.c
index 9628e38..eac7cc0 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -786,192 +786,3 @@ void plist_set_date_val(plist_t node, int32_t sec, int32_t usec)
786 plist_set_element_val(node, PLIST_DATE, &val, sizeof(GTimeVal)); 786 plist_set_element_val(node, PLIST_DATE, &val, sizeof(GTimeVal));
787} 787}
788 788
789//DEPRECATED API BELOW
790
791
792static plist_t plist_add_sub_element(plist_t node, plist_type type, const void *value, uint64_t length)
793{
794 //only structured types can have children
795 plist_type node_type = plist_get_node_type(node);
796 if (node_type == PLIST_DICT || node_type == PLIST_ARRAY)
797 {
798 //only structured types are allowed to have nulll value
799 if (value || (!value && (type == PLIST_DICT || type == PLIST_ARRAY)))
800 {
801
802 plist_t subnode = NULL;
803
804 //now handle value
805 plist_data_t data = plist_new_plist_data();
806 data->type = type;
807 data->length = length;
808
809 switch (type)
810 {
811 case PLIST_BOOLEAN:
812 data->boolval = *((char *) value);
813 break;
814 case PLIST_UINT:
815 data->intval = *((uint64_t *) value);
816 break;
817 case PLIST_REAL:
818 data->realval = *((double *) value);
819 break;
820 case PLIST_KEY:
821 case PLIST_STRING:
822 data->strval = strdup((char *) value);
823 break;
824 case PLIST_DATA:
825 data->buff = (uint8_t *) malloc(length);
826 memcpy(data->buff, value, length);
827 break;
828 case PLIST_DATE:
829 data->timeval.tv_sec = ((GTimeVal *) value)->tv_sec;
830 data->timeval.tv_usec = ((GTimeVal *) value)->tv_usec;
831 break;
832 case PLIST_ARRAY:
833 case PLIST_DICT:
834 default:
835 break;
836 }
837
838 subnode = plist_new_node(data);
839 if (node)
840 g_node_append(node, subnode);
841 return subnode;
842 }
843 else
844 return NULL;
845 }
846 return NULL;
847}
848
849
850plist_t plist_get_first_child(plist_t node)
851{
852 return (plist_t) g_node_first_child((GNode *) node);
853}
854
855plist_t plist_get_next_sibling(plist_t node)
856{
857 return (plist_t) g_node_next_sibling((GNode *) node);
858}
859
860plist_t plist_get_prev_sibling(plist_t node)
861{
862 return (plist_t) g_node_prev_sibling((GNode *) node);
863}
864
865plist_t plist_get_array_nth_el(plist_t node, uint32_t n)
866{
867 plist_t ret = NULL;
868 if (node && PLIST_ARRAY == plist_get_node_type(node))
869 {
870 uint32_t i = 0;
871 plist_t temp = plist_get_first_child(node);
872
873 while (i <= n && temp)
874 {
875 if (i == n)
876 ret = temp;
877 temp = plist_get_next_sibling(temp);
878 i++;
879 }
880 }
881 return ret;
882}
883
884plist_t plist_get_dict_el_from_key(plist_t node, const char *key)
885{
886 plist_t ret = NULL;
887 if (node && PLIST_DICT == plist_get_node_type(node))
888 {
889
890 plist_t key_node = plist_find_node_by_key(node, key);
891 ret = plist_get_next_sibling(key_node);
892 }
893 return ret;
894}
895
896void plist_add_sub_node(plist_t node, plist_t subnode)
897{
898 if (node && subnode)
899 {
900 plist_type type = plist_get_node_type(node);
901 if (type == PLIST_DICT || type == PLIST_ARRAY)
902 g_node_append(node, subnode);
903 }
904}
905
906void plist_add_sub_key_el(plist_t node, const char *val)
907{
908 plist_add_sub_element(node, PLIST_KEY, val, strlen(val));
909}
910
911void plist_add_sub_string_el(plist_t node, const char *val)
912{
913 plist_add_sub_element(node, PLIST_STRING, val, strlen(val));
914}
915
916void plist_add_sub_bool_el(plist_t node, uint8_t val)
917{
918 plist_add_sub_element(node, PLIST_BOOLEAN, &val, sizeof(uint8_t));
919}
920
921void plist_add_sub_uint_el(plist_t node, uint64_t val)
922{
923 plist_add_sub_element(node, PLIST_UINT, &val, sizeof(uint64_t));
924}
925
926void plist_add_sub_real_el(plist_t node, double val)
927{
928 plist_add_sub_element(node, PLIST_REAL, &val, sizeof(double));
929}
930
931void plist_add_sub_data_el(plist_t node, const char *val, uint64_t length)
932{
933 plist_add_sub_element(node, PLIST_DATA, val, length);
934}
935
936void plist_add_sub_date_el(plist_t node, int32_t sec, int32_t usec)
937{
938 GTimeVal val = { sec, usec };
939 plist_add_sub_element(node, PLIST_DATE, &val, sizeof(GTimeVal));
940}
941
942static plist_t plist_find_node(plist_t plist, plist_type type, const void *value, uint64_t length)
943{
944 plist_t current = NULL;
945
946 if (!plist)
947 return NULL;
948
949 for (current = (plist_t)g_node_first_child(plist); current; current = (plist_t)g_node_next_sibling(current))
950 {
951
952 plist_data_t data = plist_get_data(current);
953
954 if (data->type == type && data->length == length && compare_node_value(type, data, value, length))
955 {
956 return current;
957 }
958 if (data->type == PLIST_DICT || data->type == PLIST_ARRAY)
959 {
960 plist_t sub = plist_find_node(current, type, value, length);
961 if (sub)
962 return sub;
963 }
964 }
965 return NULL;
966}
967
968plist_t plist_find_node_by_key(plist_t plist, const char *value)
969{
970 return plist_find_node(plist, PLIST_KEY, value, strlen(value));
971}
972
973plist_t plist_find_node_by_string(plist_t plist, const char *value)
974{
975 return plist_find_node(plist, PLIST_STRING, value, strlen(value));
976}
977
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 40dc640..415d076 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -1,5 +1,6 @@
1 1
2#build the test executable 2#build the test executable
3INCLUDE_DIRECTORIES( ${GLIB2_INCLUDE_DIR} )
3 4
4SET(plist_test_SRC 5SET(plist_test_SRC
5 plist_test.c) 6 plist_test.c)
diff --git a/test/plist_cmp.c b/test/plist_cmp.c
index 709e8d0..dcf961f 100644
--- a/test/plist_cmp.c
+++ b/test/plist_cmp.c
@@ -27,10 +27,27 @@
27#include <string.h> 27#include <string.h>
28#include <sys/stat.h> 28#include <sys/stat.h>
29 29
30#include <glib.h>
31
30#ifdef _MSC_VER 32#ifdef _MSC_VER
31#pragma warning(disable:4996) 33#pragma warning(disable:4996)
32#endif 34#endif
33 35
36static plist_t plist_get_first_child(plist_t node)
37{
38 return (plist_t) g_node_first_child((GNode *) node);
39}
40
41static plist_t plist_get_next_sibling(plist_t node)
42{
43 return (plist_t) g_node_next_sibling((GNode *) node);
44}
45
46static plist_t plist_get_prev_sibling(plist_t node)
47{
48 return (plist_t) g_node_prev_sibling((GNode *) node);
49}
50
34char compare_plist(plist_t node_l, plist_t node_r) 51char compare_plist(plist_t node_l, plist_t node_r)
35{ 52{
36 plist_t cur_l = NULL; 53 plist_t cur_l = NULL;