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
e220e2cf
Commit
e220e2cf
authored
Dec 13, 2008
by
Jonathan Beck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add plutil and do some cleaning.
parent
3fdd24ae
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
322 additions
and
95 deletions
+322
-95
Makefile.am
Makefile.am
+1
-1
configure.ac
configure.ac
+1
-1
doxygen.cfg
doxygen.cfg
+1
-1
plist.h
include/plist/plist.h
+40
-0
Makefile.am
plutil/Makefile.am
+6
-0
plutil.c
plutil/plutil.c
+135
-0
plutil.h
plutil/plutil.h
+28
-0
bplist.c
src/bplist.c
+26
-26
plist.c
src/plist.c
+72
-31
plist.h
src/plist.h
+9
-32
xplist.c
src/xplist.c
+3
-3
No files found.
Makefile.am
View file @
e220e2cf
AUTOMAKE_OPTIONS
=
foreign
SUBDIRS
=
src include
SUBDIRS
=
src include
plutil
pkgconfigdir
=
$(libdir)
/pkgconfig
pkgconfig_DATA
=
libplist-1.0.pc
...
...
configure.ac
View file @
e220e2cf
...
...
@@ -44,4 +44,4 @@ if test "$no_debug_code" = true; then
AC_DEFINE(STRIP_DEBUG_CODE,1,[Strip debug reporting code])
fi
AC_OUTPUT(Makefile src/Makefile include/Makefile libplist-1.0.pc)
AC_OUTPUT(Makefile src/Makefile include/Makefile
plutil/Makefile
libplist-1.0.pc)
doxygen.cfg
View file @
e220e2cf
...
...
@@ -25,7 +25,7 @@ DOXYFILE_ENCODING = UTF-8
# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
# by quotes) that should identify the project.
PROJECT_NAME = lib
iphone
PROJECT_NAME = lib
plist
# The PROJECT_NUMBER tag can be used to enter a project or revision number.
# This could be handy for archiving the generated documentation or
...
...
include/plist/plist.h
View file @
e220e2cf
...
...
@@ -29,6 +29,46 @@ extern "C" {
#include <stdint.h>
#include <sys/types.h>
typedef
void
*
plist_t
;
typedef
enum
{
PLIST_BOOLEAN
,
PLIST_UINT
,
PLIST_REAL
,
PLIST_STRING
,
PLIST_UNICODE
,
PLIST_ARRAY
,
PLIST_DICT
,
PLIST_DATE
,
PLIST_DATA
,
PLIST_KEY
,
PLIST_NONE
}
plist_type
;
//Plist edition
void
plist_new_dict
(
plist_t
*
plist
);
void
plist_new_array
(
plist_t
*
plist
);
void
plist_new_dict_in_plist
(
plist_t
plist
,
plist_t
*
dict
);
void
plist_add_dict_element
(
plist_t
dict
,
char
*
key
,
plist_type
type
,
void
*
value
,
uint64_t
length
);
void
plist_free
(
plist_t
plist
);
//plist navigation
plist_t
plist_get_first_child
(
plist_t
node
);
plist_t
plist_get_next_sibling
(
plist_t
node
);
plist_t
plist_get_prev_sibling
(
plist_t
node
);
void
plist_to_xml
(
plist_t
plist
,
char
**
plist_xml
,
uint32_t
*
length
);
void
plist_to_bin
(
plist_t
plist
,
char
**
plist_bin
,
uint32_t
*
length
);
void
plist_from_xml
(
const
char
*
plist_xml
,
uint32_t
length
,
plist_t
*
plist
);
void
plist_from_bin
(
const
char
*
plist_bin
,
uint32_t
length
,
plist_t
*
plist
);
plist_t
plist_find_query_node
(
plist_t
plist
,
char
*
key
,
char
*
request
);
plist_t
plist_find_node
(
plist_t
plist
,
plist_type
type
,
void
*
value
);
void
plist_get_type_and_value
(
plist_t
node
,
plist_type
*
type
,
void
*
value
,
uint64_t
*
length
);
#ifdef __cplusplus
...
...
plutil/Makefile.am
0 → 100644
View file @
e220e2cf
INCLUDES
=
-I
$(top_srcdir)
/include
bin_PROGRAMS
=
plutil
plutil_SOURCES
=
plutil.c
plutil_LDADD
=
../src/libplist.la
plutil/plutil.c
0 → 100644
View file @
e220e2cf
/*
* plutil.C
* source for plist convertion tool
*
* Copyright (c) 2008 Zach C. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "plist/plist.h"
#include "plutil.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
int
main
(
int
argc
,
char
*
argv
[])
{
struct
stat
*
filestats
=
(
struct
stat
*
)
malloc
(
sizeof
(
struct
stat
));
Options
*
options
=
parse_arguments
(
argc
,
argv
);
if
(
!
options
)
{
print_usage
();
return
0
;
}
iphone_set_debug
(
options
->
debug
);
//read input file
FILE
*
iplist
=
fopen
(
options
->
in_file
,
"r"
);
if
(
!
iplist
)
return
1
;
stat
(
options
->
in_file
,
filestats
);
char
*
plist_entire
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
(
filestats
->
st_size
+
1
));
fread
(
plist_entire
,
sizeof
(
char
),
filestats
->
st_size
,
iplist
);
fclose
(
iplist
);
//convert one format to another
plist_t
root_node
=
NULL
;
char
*
plist_out
=
NULL
;
int
size
=
0
;
if
(
memcmp
(
plist_entire
,
"bplist00"
,
8
)
==
0
)
{
plist_from_bin
(
plist_entire
,
filestats
->
st_size
,
&
root_node
);
plist_to_xml
(
root_node
,
&
plist_out
,
&
size
);
}
else
{
plist_from_xml
(
plist_entire
,
filestats
->
st_size
,
&
root_node
);
plist_to_bin
(
root_node
,
&
plist_out
,
&
size
);
}
if
(
plist_out
)
{
if
(
options
->
out_file
!=
NULL
)
{
FILE
*
oplist
=
fopen
(
options
->
out_file
,
"wb"
);
if
(
!
oplist
)
return
1
;
fwrite
(
plist_out
,
size
,
sizeof
(
char
),
oplist
);
fclose
(
oplist
);
}
//if no output file specified, write to stdout
else
fwrite
(
plist_out
,
size
,
sizeof
(
char
),
stdout
);
}
else
printf
(
"ERROR
\n
"
);
return
0
;
}
Options
*
parse_arguments
(
int
argc
,
char
*
argv
[])
{
int
i
=
0
;
Options
*
options
=
(
Options
*
)
malloc
(
sizeof
(
Options
));
memset
(
options
,
0
,
sizeof
(
Options
));
for
(
i
=
1
;
i
<
argc
;
i
++
)
{
if
(
!
strcmp
(
argv
[
i
],
"--infile"
)
||
!
strcmp
(
argv
[
i
],
"-i"
))
{
if
((
i
+
1
)
==
argc
)
{
free
(
options
);
return
NULL
;
}
options
->
in_file
=
argv
[
i
+
1
];
i
++
;
continue
;
}
if
(
!
strcmp
(
argv
[
i
],
"--outfile"
)
||
!
strcmp
(
argv
[
i
],
"-o"
))
{
if
((
i
+
1
)
==
argc
)
{
free
(
options
);
return
NULL
;
}
options
->
out_file
=
argv
[
i
+
1
];
i
++
;
continue
;
}
if
(
!
strcmp
(
argv
[
i
],
"--debug"
)
||
!
strcmp
(
argv
[
i
],
"-d"
)
||
!
strcmp
(
argv
[
i
],
"-v"
))
{
options
->
debug
=
1
;
}
if
(
!
strcmp
(
argv
[
i
],
"--help"
)
||
!
strcmp
(
argv
[
i
],
"-h"
))
{
free
(
options
);
return
NULL
;
}
}
if
(
!
options
->
in_file
/*|| !options->out_file */
)
{
free
(
options
);
return
NULL
;
}
return
options
;
}
void
print_usage
()
{
printf
(
"Usage: plistutil -i|--infile in_file.plist -o|--outfile out_file.plist [--debug]
\n
"
);
printf
(
"
\n
"
);
printf
(
"
\t
-i or --infile: The file to read in.
\n
"
);
printf
(
"
\t
-o or --outfile: The file to convert to.
\n
"
);
printf
(
"
\t
-d, -v or --debug: Provide extended debug information.
\n\n
"
);
}
plutil/plutil.h
0 → 100644
View file @
e220e2cf
/*
* plutil.h
* header for plist convertion tool
*
* Copyright (c) 2008 Zach C. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
typedef
struct
_options
{
char
*
in_file
,
*
out_file
;
uint8_t
debug
,
in_fmt
,
out_fmt
;
}
Options
;
Options
*
parse_arguments
(
int
argc
,
char
*
argv
[]);
void
print_usage
();
src/bplist.c
View file @
e220e2cf
...
...
@@ -83,9 +83,9 @@ void byte_convert(char *address, size_t size)
#define get_needed_bytes(x) (x <= 1<<8 ? 1 : ( x <= 1<<16 ? 2 : ( x <= 1<<32 ? 4 : 8)))
#define get_real_bytes(x) (x >> 32 ? 4 : 8)
GNode
*
parse_uint_node
(
char
*
bnode
,
uint8_t
size
,
char
**
next_object
)
plist_t
parse_uint_node
(
char
*
bnode
,
uint8_t
size
,
char
**
next_object
)
{
struct
plist_data
*
data
=
(
struct
plist_data
*
)
calloc
(
sizeof
(
struct
plist_data
),
1
);
plist_data_t
data
=
plist_new_plist_data
(
);
size
=
1
<<
size
;
// make length less misleading
switch
(
size
)
{
...
...
@@ -114,9 +114,9 @@ GNode *parse_uint_node(char *bnode, uint8_t size, char **next_object)
return
g_node_new
(
data
);
}
GNode
*
parse_real_node
(
char
*
bnode
,
uint8_t
size
)
plist_t
parse_real_node
(
char
*
bnode
,
uint8_t
size
)
{
struct
plist_data
*
data
=
(
struct
plist_data
*
)
calloc
(
sizeof
(
struct
plist_data
),
1
);
plist_data_t
data
=
plist_new_plist_data
(
);
size
=
1
<<
size
;
// make length less misleading
switch
(
size
)
{
...
...
@@ -136,9 +136,9 @@ GNode *parse_real_node(char *bnode, uint8_t size)
return
g_node_new
(
data
);
}
GNode
*
parse_string_node
(
char
*
bnode
,
uint8_t
size
)
plist_t
parse_string_node
(
char
*
bnode
,
uint8_t
size
)
{
struct
plist_data
*
data
=
(
struct
plist_data
*
)
calloc
(
sizeof
(
struct
plist_data
),
1
);
plist_data_t
data
=
plist_new_plist_data
(
);
data
->
type
=
PLIST_STRING
;
data
->
strval
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
(
size
+
1
));
...
...
@@ -148,9 +148,9 @@ GNode *parse_string_node(char *bnode, uint8_t size)
return
g_node_new
(
data
);
}
GNode
*
parse_unicode_node
(
char
*
bnode
,
uint8_t
size
)
plist_t
parse_unicode_node
(
char
*
bnode
,
uint8_t
size
)
{
struct
plist_data
*
data
=
(
struct
plist_data
*
)
calloc
(
sizeof
(
struct
plist_data
),
1
);
plist_data_t
data
=
plist_new_plist_data
(
);
data
->
type
=
PLIST_UNICODE
;
data
->
unicodeval
=
(
wchar_t
*
)
malloc
(
sizeof
(
wchar_t
)
*
(
size
+
1
));
...
...
@@ -160,9 +160,9 @@ GNode *parse_unicode_node(char *bnode, uint8_t size)
return
g_node_new
(
data
);
}
GNode
*
parse_data_node
(
char
*
bnode
,
uint64_t
size
,
uint32_t
ref_size
)
plist_t
parse_data_node
(
char
*
bnode
,
uint64_t
size
,
uint32_t
ref_size
)
{
struct
plist_data
*
data
=
(
struct
plist_data
*
)
calloc
(
sizeof
(
struct
plist_data
),
1
);
plist_data_t
data
=
plist_new_plist_data
(
);
data
->
type
=
PLIST_DATA
;
data
->
length
=
size
;
...
...
@@ -172,9 +172,9 @@ GNode *parse_data_node(char *bnode, uint64_t size, uint32_t ref_size)
return
g_node_new
(
data
);
}
GNode
*
parse_dict_node
(
char
*
bnode
,
uint64_t
size
,
uint32_t
ref_size
)
plist_t
parse_dict_node
(
char
*
bnode
,
uint64_t
size
,
uint32_t
ref_size
)
{
struct
plist_data
*
data
=
(
struct
plist_data
*
)
calloc
(
sizeof
(
struct
plist_data
),
1
);
plist_data_t
data
=
plist_new_plist_data
(
);
data
->
type
=
PLIST_DICT
;
data
->
length
=
size
;
...
...
@@ -184,9 +184,9 @@ GNode *parse_dict_node(char *bnode, uint64_t size, uint32_t ref_size)
return
g_node_new
(
data
);
}
GNode
*
parse_array_node
(
char
*
bnode
,
uint64_t
size
,
uint32_t
ref_size
)
plist_t
parse_array_node
(
char
*
bnode
,
uint64_t
size
,
uint32_t
ref_size
)
{
struct
plist_data
*
data
=
(
struct
plist_data
*
)
calloc
(
sizeof
(
struct
plist_data
),
1
);
plist_data_t
data
=
plist_new_plist_data
(
);
data
->
type
=
PLIST_ARRAY
;
data
->
length
=
size
;
...
...
@@ -198,7 +198,7 @@ GNode *parse_array_node(char *bnode, uint64_t size, uint32_t ref_size)
GNode
*
parse_bin_node
(
char
*
object
,
uint8_t
dict_size
,
char
**
next_object
)
plist_t
parse_bin_node
(
char
*
object
,
uint8_t
dict_size
,
char
**
next_object
)
{
if
(
!
object
)
return
NULL
;
...
...
@@ -214,7 +214,7 @@ GNode *parse_bin_node(char *object, uint8_t dict_size, char **next_object)
case
BPLIST_TRUE
:
{
struct
plist_data
*
data
=
(
struct
plist_data
*
)
calloc
(
sizeof
(
struct
plist_data
),
1
);
plist_data_t
data
=
plist_new_plist_data
(
);
data
->
type
=
PLIST_BOOLEAN
;
data
->
boolval
=
TRUE
;
return
g_node_new
(
data
);
...
...
@@ -222,7 +222,7 @@ GNode *parse_bin_node(char *object, uint8_t dict_size, char **next_object)
case
BPLIST_FALSE
:
{
struct
plist_data
*
data
=
(
struct
plist_data
*
)
calloc
(
sizeof
(
struct
plist_data
),
1
);
plist_data_t
data
=
plist_new_plist_data
(
);
data
->
type
=
PLIST_BOOLEAN
;
data
->
boolval
=
FALSE
;
return
g_node_new
(
data
);
...
...
@@ -299,8 +299,8 @@ GNode *parse_bin_node(char *object, uint8_t dict_size, char **next_object)
gpointer
copy_plist_data
(
gconstpointer
src
,
gpointer
data
)
{
struct
plist_data
*
srcdata
=
(
struct
plist_data
*
)
src
;
struct
plist_data
*
dstdata
=
(
struct
plist_data
*
)
calloc
(
sizeof
(
struct
plist_data
),
1
);
plist_data_t
srcdata
=
(
plist_data_t
)
src
;
plist_data_t
dstdata
=
plist_new_plist_data
(
);
dstdata
->
type
=
srcdata
->
type
;
dstdata
->
length
=
srcdata
->
length
;
...
...
@@ -336,7 +336,7 @@ gpointer copy_plist_data(gconstpointer src, gpointer data)
return
dstdata
;
}
void
bin_to_plist
(
const
char
*
plist_bin
,
uint32_t
length
,
plist_t
*
plist
)
void
plist_from_bin
(
const
char
*
plist_bin
,
uint32_t
length
,
plist_t
*
plist
)
{
//first check we have enough data
if
(
!
(
length
>=
BPLIST_MAGIC_SIZE
+
BPLIST_VERSION_SIZE
+
BPLIST_TRL_SIZE
))
...
...
@@ -393,7 +393,7 @@ void bin_to_plist(const char *plist_bin, uint32_t length, plist_t * plist)
for
(
i
=
0
;
i
<
num_objects
;
i
++
)
{
log_debug_msg
(
"parse_nodes: on node %i
\n
"
,
i
);
struct
plist_data
*
data
=
(
struct
plist_data
*
)
nodeslist
[
i
]
->
data
;
plist_data_t
data
=
plist_get_data
(
nodeslist
[
i
])
;
switch
(
data
->
type
)
{
case
PLIST_DICT
:
...
...
@@ -406,7 +406,7 @@ void bin_to_plist(const char *plist_bin, uint32_t length, plist_t * plist)
index2
=
swap_n_bytes
(
data
->
buff
+
str_j
,
dict_param_size
);
//first one is actually a key
((
struct
plist_data
*
)
nodeslist
[
index1
]
->
data
)
->
type
=
PLIST_KEY
;
plist_get_data
(
nodeslist
[
index1
]
)
->
type
=
PLIST_KEY
;
if
(
G_NODE_IS_ROOT
(
nodeslist
[
index1
]))
g_node_append
(
nodeslist
[
i
],
nodeslist
[
index1
]);
...
...
@@ -446,7 +446,7 @@ void bin_to_plist(const char *plist_bin, uint32_t length, plist_t * plist)
guint
plist_data_hash
(
gconstpointer
key
)
{
struct
plist_data
*
data
=
(
struct
plist_data
*
)
((
GNode
*
)
key
)
->
data
;
plist_data_t
data
=
plist_get_data
(
key
)
;
guint
hash
=
data
->
type
;
guint
i
=
0
;
...
...
@@ -497,8 +497,8 @@ gboolean plist_data_compare(gconstpointer a, gconstpointer b)
if
(
!
((
GNode
*
)
a
)
->
data
||
!
((
GNode
*
)
b
)
->
data
)
return
FALSE
;
struct
plist_data
*
val_a
=
(
struct
plist_data
*
)
((
GNode
*
)
a
)
->
data
;
struct
plist_data
*
val_b
=
(
struct
plist_data
*
)
((
GNode
*
)
b
)
->
data
;
plist_data_t
val_a
=
plist_get_data
(
a
)
;
plist_data_t
val_b
=
plist_get_data
(
b
)
;
if
(
val_a
->
type
!=
val_b
->
type
)
return
FALSE
;
...
...
@@ -718,7 +718,7 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
for
(
i
=
0
;
i
<
num_objects
;
i
++
)
{
offsets
[
i
]
=
bplist_buff
->
len
;
struct
plist_data
*
data
=
(
struct
plist_data
*
)
((
GNode
*
)
g_ptr_array_index
(
objects
,
i
))
->
data
;
plist_data_t
data
=
plist_get_data
(
g_ptr_array_index
(
objects
,
i
))
;
switch
(
data
->
type
)
{
case
PLIST_BOOLEAN
:
...
...
src/plist.c
View file @
e220e2cf
...
...
@@ -28,23 +28,45 @@
#include <stdlib.h>
#include <stdio.h>
plist_t
plist_new_node
(
plist_data_t
data
)
{
return
(
plist_t
)
g_node_new
(
data
);
}
plist_data_t
plist_get_data
(
plist_t
node
)
{
if
(
!
node
)
return
NULL
;
return
((
GNode
*
)
node
)
->
data
;
}
plist_data_t
plist_new_plist_data
()
{
plist_data_t
data
=
(
plist_data_t
)
calloc
(
sizeof
(
struct
plist_data_s
),
1
);
return
data
;
}
void
plist_free_plist_data
(
plist_data_t
data
)
{
free
(
data
);
}
void
plist_new_dict
(
plist_t
*
plist
)
{
if
(
*
plist
!=
NULL
)
return
;
struct
plist_data
*
data
=
(
struct
plist_data
*
)
calloc
(
sizeof
(
struct
plist_data
),
1
);
plist_data_t
data
=
plist_new_plist_data
(
);
data
->
type
=
PLIST_DICT
;
*
plist
=
g_node_new
(
data
);
*
plist
=
plist_new_node
(
data
);
}
void
plist_new_array
(
plist_t
*
plist
)
{
if
(
*
plist
!=
NULL
)
return
;
struct
plist_data
*
data
=
(
struct
plist_data
*
)
calloc
(
sizeof
(
struct
plist_data
),
1
);
plist_data_t
data
=
plist_new_plist_data
(
);
data
->
type
=
PLIST_ARRAY
;
*
plist
=
g_node_new
(
data
);
*
plist
=
plist_new_node
(
data
);
}
void
plist_new_dict_in_plist
(
plist_t
plist
,
plist_t
*
dict
)
...
...
@@ -52,9 +74,9 @@ void plist_new_dict_in_plist(plist_t plist, plist_t * dict)
if
(
!
plist
||
*
dict
)
return
;
struct
plist_data
*
data
=
(
struct
plist_data
*
)
calloc
(
sizeof
(
struct
plist_data
),
1
);
plist_data_t
data
=
plist_new_plist_data
(
);
data
->
type
=
PLIST_DICT
;
*
dict
=
g_node_new
(
data
);
*
dict
=
plist_new_node
(
data
);
g_node_append
(
plist
,
*
dict
);
}
...
...
@@ -72,14 +94,14 @@ void plist_add_dict_element(plist_t dict, char *key, plist_type type, void *valu
if
(
!
dict
||
!
key
||
!
value
)
return
;
struct
plist_data
*
data
=
(
struct
plist_data
*
)
calloc
(
sizeof
(
struct
plist_data
),
1
);
plist_data_t
data
=
plist_new_plist_data
(
);
data
->
type
=
PLIST_KEY
;
data
->
strval
=
strdup
(
key
);
GNode
*
keynode
=
g_node_new
(
data
);
plist_t
keynode
=
plist_new_node
(
data
);
g_node_append
(
dict
,
keynode
);
//now handle value
struct
plist_data
*
val
=
(
struct
plist_data
*
)
calloc
(
sizeof
(
struct
plist_data
),
1
);
plist_data_t
val
=
plist_new_plist_data
(
);
val
->
type
=
type
;
val
->
length
=
length
;
...
...
@@ -108,7 +130,7 @@ void plist_add_dict_element(plist_t dict, char *key, plist_type type, void *valu
default:
break
;
}
GNode
*
valnode
=
g_node_new
(
val
);
plist_t
valnode
=
plist_new_node
(
val
);
g_node_append
(
dict
,
valnode
);
}
...
...
@@ -117,24 +139,41 @@ void plist_free(plist_t plist)
g_node_destroy
(
plist
);
}
plist_t
find_query_node
(
plist_t
plist
,
char
*
key
,
char
*
request
)
plist_t
plist_get_first_child
(
plist_t
node
)
{
return
(
plist_t
)
g_node_first_child
(
(
GNode
*
)
node
);
}
plist_t
plist_get_next_sibling
(
plist_t
node
)
{
return
(
plist_t
)
g_node_next_sibling
(
(
GNode
*
)
node
);
}
plist_t
plist_get_prev_sibling
(
plist_t
node
)
{
return
(
plist_t
)
g_node_prev_sibling
(
(
GNode
*
)
node
);
}
plist_t
plist_find_query_node
(
plist_t
plist
,
char
*
key
,
char
*
request
)
{
if
(
!
plist
)
return
NULL
;
GNode
*
current
=
NULL
;
for
(
current
=
plist
->
children
;
current
;
current
=
current
->
next
)
{
plist_t
current
=
NULL
;
plist_t
next
=
NULL
;
for
(
current
=
plist_get_first_child
(
plist
);
current
;
current
=
next
)
{
struct
plist_data
*
data
=
(
struct
plist_data
*
)
current
->
data
;
next
=
plist_get_next_sibling
(
current
);
plist_data_t
data
=
plist_get_data
(
current
);
if
(
data
->
type
==
PLIST_KEY
&&
!
strcmp
(
data
->
strval
,
key
)
&&
current
->
next
)
{
if
(
data
->
type
==
PLIST_KEY
&&
!
strcmp
(
data
->
strval
,
key
)
&&
next
)
{
data
=
(
struct
plist_data
*
)
current
->
next
->
data
;
data
=
plist_get_data
(
next
)
;
if
(
data
->
type
==
PLIST_STRING
&&
!
strcmp
(
data
->
strval
,
request
))
return
current
->
next
;
return
next
;
}
if
(
data
->
type
==
PLIST_DICT
||
data
->
type
==
PLIST_ARRAY
)
{
GNode
*
sub
=
find_query_node
(
current
,
key
,
request
);
plist_t
sub
=
plist_
find_query_node
(
current
,
key
,
request
);
if
(
sub
)
return
sub
;
}
...
...
@@ -142,7 +181,7 @@ plist_t find_query_node(plist_t plist, char *key, char *request)
return
NULL
;
}
char
compare_node_value
(
plist_type
type
,
struct
plist_data
*
data
,
void
*
value
)
char
compare_node_value
(
plist_type
type
,
plist_data_t
data
,
void
*
value
)
{
char
res
=
FALSE
;
switch
(
type
)
{
...
...
@@ -174,21 +213,21 @@ char compare_node_value(plist_type type, struct plist_data *data, void *value)
return
res
;
}
plist_t
find_node
(
plist_t
plist
,
plist_type
type
,
void
*
value
)
plist_t
plist_
find_node
(
plist_t
plist
,
plist_type
type
,
void
*
value
)
{
if
(
!
plist
)
return
NULL
;
GNode
*
current
=
NULL
;
for
(
current
=
plist
->
children
;
current
;
current
=
current
->
next
)
{
plist_t
current
=
NULL
;
for
(
current
=
plist
_get_first_child
(
plist
);
current
;
current
=
plist_get_next_sibling
(
current
)
)
{
struct
plist_data
*
data
=
(
struct
plist_data
*
)
current
->
data
;
plist_data_t
data
=
plist_get_data
(
current
)
;
if
(
data
->
type
==
type
&&
compare_node_value
(
type
,
data
,
value
))
{
return
current
;
}
if
(
data
->
type
==
PLIST_DICT
||
data
->
type
==
PLIST_ARRAY
)
{
GNode
*
sub
=
find_node
(
current
,
type
,
value
);
plist_t
sub
=
plist_
find_node
(
current
,
type
,
value
);
if
(
sub
)
return
sub
;
}
...
...
@@ -196,12 +235,12 @@ plist_t find_node(plist_t plist, plist_type type, void *value)
return
NULL
;
}
void
get_type_and_value
(
GNode
*
node
,
plist_type
*
type
,
void
*
value
,
uint64_t
*
length
)
void
plist_get_type_and_value
(
plist_t
node
,
plist_type
*
type
,
void
*
value
,
uint64_t
*
length
)
{
if
(
!
node
)
return
;
struct
plist_data
*
data
=
(
struct
plist_data
*
)
node
->
data
;
plist_data_t
data
=
plist_get_data
(
node
)
;
*
type
=
data
->
type
;
*
length
=
data
->
length
;
...
...
@@ -236,16 +275,18 @@ void get_type_and_value(GNode * node, plist_type * type, void *value, uint64_t *
plist_type
plist_get_node_type
(
plist_t
node
)
{
if
(
node
&&
node
->
data
)
return
((
struct
plist_data
*
)
node
->
data
)
->
type
;
else
return
PLIST_NONE
;
if
(
node
)
{
plist_data_t
data
=
plist_get_data
(
node
);
if
(
data
)
return
data
->
type
;
}
return
PLIST_NONE
;
}
uint64_t
plist_get_node_uint_val
(
plist_t
node
)
{
if
(
PLIST_UINT
==
plist_get_node_type
(
node
))
return
((
struct
plist_data
*
)
node
->
data
)
->
intval
;
return
plist_get_data
(
node
)
->
intval
;
else
return
0
;
}
src/plist.h
View file @
e220e2cf
...
...
@@ -22,6 +22,8 @@
#ifndef PLIST_H
#define PLIST_H
#include "plist/plist.h"
#include <stdint.h>
#include <wchar.h>
...
...
@@ -31,22 +33,10 @@
#include <glib.h>
typedef
enum
{
PLIST_BOOLEAN
,
PLIST_UINT
,
PLIST_REAL
,
PLIST_STRING
,
PLIST_UNICODE
,
PLIST_ARRAY
,
PLIST_DICT
,
PLIST_DATE
,
PLIST_DATA
,
PLIST_KEY
,
PLIST_NONE
}
plist_type
;
struct
plist_data
{
struct
plist_data_s
{
union
{
char
boolval
;
uint64_t
intval
;
...
...
@@ -59,25 +49,12 @@ struct plist_data {
plist_type
type
;
};
typedef
struct
plist_data_s
*
plist_data_t
;
plist_t
plist_new_node
(
plist_data_t
data
);
plist_data_t
plist_get_data
(
plist_t
node
);
plist_data_t
plist_new_plist_data
();
void
plist_free_plist_data
(
plist_data_t
node
);
typedef
GNode
*
plist_t
;
void
plist_new_dict
(
plist_t
*
plist
);
void
plist_new_array
(
plist_t
*
plist
);
void
plist_new_dict_in_plist
(
plist_t
plist
,
plist_t
*
dict
);
void
plist_add_dict_element
(
plist_t
dict
,
char
*
key
,
plist_type
type
,
void
*
value
,
uint64_t
length
);
void
plist_free
(
plist_t
plist
);
void
plist_to_xml
(
plist_t
plist
,
char
**
plist_xml
,
uint32_t
*
length
);
void
plist_to_bin
(
plist_t
plist
,
char
**
plist_bin
,
uint32_t
*
length
);
void
xml_to_plist
(
const
char
*
plist_xml
,
uint32_t
length
,
plist_t
*
plist
);
void
bin_to_plist
(
const
char
*
plist_bin
,
uint32_t
length
,
plist_t
*
plist
);
plist_t
find_query_node
(
plist_t
plist
,
char
*
key
,
char
*
request
);
plist_t
find_node
(
plist_t
plist
,
plist_type
type
,
void
*
value
);
void
get_type_and_value
(
plist_t
node
,
plist_type
*
type
,
void
*
value
,
uint64_t
*
length
);
#endif
src/xplist.c
View file @
e220e2cf
...
...
@@ -120,7 +120,7 @@ void node_to_xml(GNode * node, gpointer xml_struct)
return
;
struct
xml_node
*
xstruct
=
(
struct
xml_node
*
)
xml_struct
;
struct
plist_data
*
node_data
=
(
struct
plist_data
*
)
node
->
data
;
plist_data_t
node_data
=
plist_get_data
(
node
)
;
xmlNodePtr
child_node
=
NULL
;
char
isStruct
=
FALSE
;
...
...
@@ -220,7 +220,7 @@ void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node)
if
(
!
node
)
break
;
struct
plist_data
*
data
=
(
struct
plist_data
*
)
calloc
(
sizeof
(
struct
plist_data
),
1
);
plist_data_t
data
=
plist_new_plist_data
(
);
GNode
*
subnode
=
g_node_new
(
data
);
if
(
*
plist_node
)
g_node_append
(
*
plist_node
,
subnode
);
...
...
@@ -303,7 +303,7 @@ void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length)
xmlDocDumpMemory
(
plist_doc
,
(
xmlChar
**
)
plist_xml
,
length
);
}
void
xml_to_plist
(
const
char
*
plist_xml
,
uint32_t
length
,
plist_t
*
plist
)
void
plist_from_xml
(
const
char
*
plist_xml
,
uint32_t
length
,
plist_t
*
plist
)
{
xmlDocPtr
plist_doc
=
xmlReadMemory
(
plist_xml
,
length
,
NULL
,
NULL
,
0
);
xmlNodePtr
root_node
=
xmlDocGetRootElement
(
plist_doc
);
...
...
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