summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/plist/plist.h19
-rw-r--r--src/plist.c28
-rw-r--r--swig/plist.i54
3 files changed, 91 insertions, 10 deletions
diff --git a/include/plist/plist.h b/include/plist/plist.h
index 7bdd00a..b7b0fa4 100644
--- a/include/plist/plist.h
+++ b/include/plist/plist.h
@@ -140,6 +140,25 @@ extern "C" {
140 */ 140 */
141 PLIST_API plist_t plist_get_prev_sibling(plist_t node); 141 PLIST_API plist_t plist_get_prev_sibling(plist_t node);
142 142
143/**
144 * Get the nth child of a #PLIST_ARRAY node.
145 *
146 * @param node the node of type #PLIST_ARRAY
147 * @param n the index of the child to get. Range is [0, array_size[
148 * @return the nth children or NULL if node is not of type #PLIST_ARRAY
149 */
150 PLIST_API plist_t plist_get_array_nth_el(plist_t node, uint32_t n);
151
152/**
153 * Get the child of a #PLIST_DICT node from the associated key value.
154 *
155 * @param node the node of type #PLIST_DICT
156 * @param key the key associated to the requested value
157 * @return the key associated value or NULL if node is not of type #PLIST_DICT
158 */
159 PLIST_API plist_t plist_get_dict_el_from_key(plist_t node, const char *key);
160
161
143/******************************************** 162/********************************************
144 * * 163 * *
145 * Setters * 164 * Setters *
diff --git a/src/plist.c b/src/plist.c
index 2a70a09..c3c9e7b 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -165,6 +165,34 @@ plist_t plist_get_prev_sibling(plist_t node)
165 return (plist_t) g_node_prev_sibling((GNode *) node); 165 return (plist_t) g_node_prev_sibling((GNode *) node);
166} 166}
167 167
168plist_t plist_get_array_nth_el(plist_t node, uint32_t n)
169{
170 plist_t ret = NULL;
171 if (node && PLIST_ARRAY == plist_get_node_type(node)) {
172 uint32_t i = 0;
173 plist_t temp = plist_get_first_child(node);
174
175 while ( i <= n && temp) {
176 if (i == n)
177 ret = temp;
178 temp = plist_get_next_sibling(temp);
179 i++;
180 }
181 }
182 return ret;
183}
184
185plist_t plist_get_dict_el_from_key(plist_t node, const char *key)
186{
187 plist_t ret = NULL;
188 if (node && PLIST_DICT == plist_get_node_type(node)) {
189
190 plist_t key_node = plist_find_node_by_key(node, key);
191 ret = plist_get_next_sibling(key_node);
192 }
193 return ret;
194}
195
168static char compare_node_value(plist_type type, plist_data_t data, const void *value, uint64_t length) 196static char compare_node_value(plist_type type, plist_data_t data, const void *value, uint64_t length)
169{ 197{
170 char res = FALSE; 198 char res = FALSE;
diff --git a/swig/plist.i b/swig/plist.i
index 41ff7cc..a56592e 100644
--- a/swig/plist.i
+++ b/swig/plist.i
@@ -180,21 +180,55 @@ typedef struct {
180 } 180 }
181 181
182 PListNode* find_node_by_key(char *s) { 182 PListNode* find_node_by_key(char *s) {
183 PListNode* plist = allocate_wrapper(); 183 plist_t node = plist_find_node_by_key($self->node, s);
184 if (plist) { 184 if (node) {
185 plist->node = plist_find_node_by_key($self->node, s); 185 PListNode* plist = allocate_wrapper();
186 plist->should_keep_plist = 1; 186 if (plist) {
187 plist->node = node;
188 plist->should_keep_plist = 1;
189 }
190 return plist;
187 } 191 }
188 return plist; 192 return NULL;
189 } 193 }
190 194
191 PListNode* find_node_by_string(char* s) { 195 PListNode* find_node_by_string(char* s) {
192 PListNode* plist = allocate_wrapper(); 196 plist_t node = plist_find_node_by_string($self->node, s);
193 if (plist) { 197 if (node) {
194 plist->node = plist_find_node_by_string($self->node, s); 198 PListNode* plist = allocate_wrapper();
195 plist->should_keep_plist = 1; 199 if (plist) {
200 plist->node = node;
201 plist->should_keep_plist = 1;
202 }
203 return plist;
204 }
205 return NULL;
206 }
207
208 PListNode* get_array_nth_el(unsigned int n) {
209 plist_t node = plist_get_array_nth_el($self->node, n);
210 if (node) {
211 PListNode* plist = allocate_wrapper();
212 if (plist) {
213 plist->node = node;
214 plist->should_keep_plist = 1;
215 }
216 return plist;
196 } 217 }
197 return plist; 218 return NULL;
219 }
220
221 PListNode* get_dict_el_from_key(char *key) {
222 plist_t node = plist_get_dict_el_from_key($self->node, key);
223 if (node) {
224 PListNode* plist = allocate_wrapper();
225 if (plist) {
226 plist->node = node;
227 plist->should_keep_plist = 1;
228 }
229 return plist;
230 }
231 return NULL;
198 } 232 }
199 233
200 char* to_xml () { 234 char* to_xml () {