Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libplist
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pwn
libplist
Commits
bc08d5f5
Commit
bc08d5f5
authored
Oct 10, 2009
by
Jonathan Beck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add dict iteration. Add functions to retrieve index and key from node.
parent
009274f4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
8 deletions
+73
-8
plist.h
include/plist/plist.h
+35
-3
plist.c
src/plist.c
+38
-5
No files found.
include/plist/plist.h
View file @
bc08d5f5
...
...
@@ -61,6 +61,11 @@ extern "C" {
*/
typedef
void
*
plist_t
;
/**
* The plist dictionary iterator.
*/
typedef
uint32_t
*
plist_dict_iter
;
/**
* The enumeration of plist node types.
*/
...
...
@@ -195,6 +200,14 @@ extern "C" {
*/
PLIST_API
plist_t
plist_array_get_item
(
plist_t
node
,
uint32_t
n
);
/**
* Get the index of an item. item must be a member of a #PLIST_ARRAY node.
*
* @param node the node
* @return the node index
*/
PLIST_API
uint32_t
plist_array_get_item_index
(
plist_t
node
);
/**
* Set the nth item in a #PLIST_ARRAY node.
* The previous item at index n will be freed using #plist_free
...
...
@@ -238,12 +251,31 @@ extern "C" {
********************************************/
/**
* Get size of a #PLIST_DICT node.
* Create iterator of a #PLIST_DICT node.
* The allocated iterator shoult be freed with tandard free function
*
* @param node the node of type #PLIST_DICT
* @param iter iterator of the #PLIST_DICT node
*/
PLIST_API
void
plist_dict_new_iter
(
plist_t
node
,
plist_dict_iter
*
iter
);
/**
* Increment iterator of a #PLIST_DICT node.
*
* @param node the node of type #PLIST_DICT
* @return size of the #PLIST_DICT node
* @param iter iterator of the dictionary
* @param key a location to store the key, or NULL.
* @param val a location to store the value, or NULL.
*/
PLIST_API
void
plist_dict_next_item
(
plist_t
node
,
plist_dict_iter
iter
,
char
**
key
,
plist_t
*
val
);
/**
* Get key associated to an item. Item must be member of a dictionary
*
* @param node the node
* @param key a location to store the key.
*/
PLIST_API
uint32_t
plist_dict_get_size
(
plist_t
node
);
PLIST_API
void
plist_dict_get_item_key
(
plist_t
node
,
char
**
key
);
/**
* Get the nth item in a #PLIST_DICT node.
...
...
src/plist.c
View file @
bc08d5f5
...
...
@@ -212,6 +212,14 @@ plist_t plist_array_get_item(plist_t node, uint32_t n)
return
ret
;
}
uint32_t
plist_array_get_item_index
(
plist_t
node
)
{
plist_t
father
=
plist_get_parent
(
node
);
if
(
PLIST_ARRAY
==
plist_get_node_type
(
father
))
{
return
g_node_child_position
(
father
,
node
);
}
}
void
plist_array_set_item
(
plist_t
node
,
plist_t
item
,
uint32_t
n
)
{
if
(
node
&&
PLIST_ARRAY
==
plist_get_node_type
(
node
))
{
...
...
@@ -252,13 +260,38 @@ void plist_array_remove_item(plist_t node, uint32_t n)
return
;
}
uint32_t
plist_dict_get_size
(
plist_t
node
)
void
plist_dict_new_iter
(
plist_t
node
,
plist_dict_iter
*
iter
)
{
uint32_t
ret
=
0
;
if
(
node
&&
PLIST_DICT
==
plist_get_node_type
(
node
))
{
ret
=
g_node_n_children
(
node
)
/
2
;
if
(
iter
&&
*
iter
==
NULL
)
{
*
iter
=
malloc
(
sizeof
(
uint32_t
));
**
iter
=
0
;
}
return
;
}
void
plist_dict_next_item
(
plist_t
node
,
plist_dict_iter
iter
,
char
**
key
,
plist_t
*
val
)
{
if
(
node
&&
PLIST_DICT
==
plist_get_node_type
(
node
)
&&
*
iter
<
g_node_n_children
(
node
)
/
2
)
{
if
(
key
)
{
plist_get_key_val
((
plist_t
)
g_node_nth_child
(
node
,
2
*
(
*
iter
)),
key
);
}
if
(
val
)
{
val
=
(
plist_t
)
g_node_nth_child
(
node
,
2
*
(
*
iter
)
+
1
);
}
*
iter
+=
2
;
}
return
;
}
void
plist_dict_get_item_key
(
plist_t
node
,
char
**
key
)
{
plist_t
father
=
plist_get_parent
(
node
);
if
(
PLIST_DICT
==
plist_get_node_type
(
father
))
{
plist_get_key_val
(
(
plist_t
)
g_node_prev_sibling
(
node
),
key
);
}
return
ret
;
}
plist_t
plist_dict_get_item
(
plist_t
node
,
const
char
*
key
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment