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
f9299fa8
Commit
f9299fa8
authored
Mar 19, 2014
by
Nikias Bassen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plist_dict_set_item: insert key/value pair if key not already present
parent
6dcc8c48
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
14 deletions
+16
-14
plist.h
include/plist/plist.h
+5
-4
plist.c
src/plist.c
+11
-10
No files found.
include/plist/plist.h
View file @
f9299fa8
...
@@ -310,20 +310,21 @@ extern "C"
...
@@ -310,20 +310,21 @@ extern "C"
/**
/**
* Set item identified by key in a #PLIST_DICT node.
* Set item identified by key in a #PLIST_DICT node.
* The previous item at index n will be freed using #plist_free
* The previous item identified by key will be freed using #plist_free.
* If there is no item for the given key a new item will be inserted.
*
*
* @param node the node of type #PLIST_DICT
* @param node the node of type #PLIST_DICT
* @param item the new item associated to key
* @param item the new item associated to key
* @param key the identifier of the item to
get. Assert if identifier is not presen
t.
* @param key the identifier of the item to
se
t.
*/
*/
PLIST_API
void
plist_dict_set_item
(
plist_t
node
,
const
char
*
key
,
plist_t
item
);
PLIST_API
void
plist_dict_set_item
(
plist_t
node
,
const
char
*
key
,
plist_t
item
);
/**
/**
* Insert a new item
at position n in
a #PLIST_DICT node.
* Insert a new item
into
a #PLIST_DICT node.
*
*
* @param node the node of type #PLIST_DICT
* @param node the node of type #PLIST_DICT
* @param item the new item to insert
* @param item the new item to insert
* @param key The identifier of the item to insert.
Assert if identifier already present.
* @param key The identifier of the item to insert.
*/
*/
PLIST_API
void
plist_dict_insert_item
(
plist_t
node
,
const
char
*
key
,
plist_t
item
);
PLIST_API
void
plist_dict_insert_item
(
plist_t
node
,
const
char
*
key
,
plist_t
item
);
...
...
src/plist.c
View file @
f9299fa8
...
@@ -405,17 +405,18 @@ plist_t plist_dict_get_item(plist_t node, const char* key)
...
@@ -405,17 +405,18 @@ plist_t plist_dict_get_item(plist_t node, const char* key)
void
plist_dict_set_item
(
plist_t
node
,
const
char
*
key
,
plist_t
item
)
void
plist_dict_set_item
(
plist_t
node
,
const
char
*
key
,
plist_t
item
)
{
{
if
(
node
&&
PLIST_DICT
==
plist_get_node_type
(
node
))
if
(
node
&&
PLIST_DICT
==
plist_get_node_type
(
node
))
{
{
node_t
*
old_item
=
plist_dict_get_item
(
node
,
key
);
node_t
*
old_item
=
plist_dict_get_item
(
node
,
key
);
if
(
old_item
)
if
(
old_item
)
{
{
int
idx
=
plist_free_node
(
old_item
);
int
idx
=
plist_free_node
(
old_item
);
if
(
idx
<
0
)
{
if
(
idx
<
0
)
{
node_attach
(
node
,
item
);
node_attach
(
node
,
item
);
}
else
{
}
else
{
node_insert
(
node
,
idx
,
item
);
node_insert
(
node
,
idx
,
item
);
}
}
}
else
{
node_attach
(
node
,
plist_new_key
(
key
));
node_attach
(
node
,
item
);
}
}
}
}
return
;
return
;
...
@@ -466,7 +467,7 @@ void plist_dict_merge(plist_t *target, plist_t source)
...
@@ -466,7 +467,7 @@ void plist_dict_merge(plist_t *target, plist_t source)
if
(
plist_dict_get_item
(
*
target
,
key
)
!=
NULL
)
if
(
plist_dict_get_item
(
*
target
,
key
)
!=
NULL
)
plist_dict_remove_item
(
*
target
,
key
);
plist_dict_remove_item
(
*
target
,
key
);
plist_dict_
inser
t_item
(
*
target
,
key
,
plist_copy
(
subnode
));
plist_dict_
se
t_item
(
*
target
,
key
,
plist_copy
(
subnode
));
free
(
key
);
free
(
key
);
key
=
NULL
;
key
=
NULL
;
}
while
(
1
);
}
while
(
1
);
...
...
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