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
a3c6acf8
Commit
a3c6acf8
authored
Jan 04, 2009
by
Jonathan Beck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more warning fixes.
parent
5d9e97d4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
67 deletions
+94
-67
configure.ac
configure.ac
+1
-1
bplist.c
src/bplist.c
+39
-27
plist.h
src/plist.h
+1
-1
xplist.c
src/xplist.c
+53
-38
No files found.
configure.ac
View file @
a3c6acf8
...
@@ -45,7 +45,7 @@ if test "$no_debug_code" = true; then
...
@@ -45,7 +45,7 @@ if test "$no_debug_code" = true; then
AC_DEFINE(STRIP_DEBUG_CODE,1,[Strip debug reporting code])
AC_DEFINE(STRIP_DEBUG_CODE,1,[Strip debug reporting code])
fi
fi
AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Wall -Wextra -Wmissing-declarations -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default")
AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Wall -Wextra -Wmissing-declarations -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default
-Wno-unused-parameter
")
AC_SUBST(GLOBAL_CFLAGS)
AC_SUBST(GLOBAL_CFLAGS)
AC_OUTPUT(Makefile src/Makefile include/Makefile plutil/Makefile libplist-1.0.pc)
AC_OUTPUT(Makefile src/Makefile include/Makefile plutil/Makefile libplist-1.0.pc)
src/bplist.c
View file @
a3c6acf8
...
@@ -27,10 +27,10 @@
...
@@ -27,10 +27,10 @@
#include <string.h>
#include <string.h>
/* Magic marker and size. */
/* Magic marker and size. */
#define BPLIST_MAGIC
"bplist"
#define BPLIST_MAGIC
((uint8_t*)"bplist")
#define BPLIST_MAGIC_SIZE 6
#define BPLIST_MAGIC_SIZE 6
#define BPLIST_VERSION
"00"
#define BPLIST_VERSION
((uint8_t*)"00")
#define BPLIST_VERSION_SIZE 2
#define BPLIST_VERSION_SIZE 2
...
@@ -59,11 +59,11 @@ enum {
...
@@ -59,11 +59,11 @@ enum {
BPLIST_MASK
=
0xF0
BPLIST_MASK
=
0xF0
};
};
static
void
byte_convert
(
char
*
address
,
size_t
size
)
static
void
byte_convert
(
uint8_t
*
address
,
size_t
size
)
{
{
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
uint8_t
i
=
0
,
j
=
0
;
uint8_t
i
=
0
,
j
=
0
;
char
tmp
=
'\0'
;
uint8_t
tmp
=
0
;
for
(
i
=
0
;
i
<
(
size
/
2
);
i
++
)
{
for
(
i
=
0
;
i
<
(
size
/
2
);
i
++
)
{
tmp
=
address
[
i
];
tmp
=
address
[
i
];
...
@@ -75,13 +75,18 @@ static void byte_convert(char *address, size_t size)
...
@@ -75,13 +75,18 @@ static void byte_convert(char *address, size_t size)
}
}
#define swap_n_bytes(x, n) \
#define swap_n_bytes(x, n) \
n == 8 ? GUINT64_FROM_BE( *(uint64_t *)(x) ) : \
(
n == 8 ? GUINT64_FROM_BE( *(uint64_t *)(x) ) : \
(n == 4 ? GUINT32_FROM_BE( *(uint32_t *)(x) ) : \
(n == 4 ? GUINT32_FROM_BE( *(uint32_t *)(x) ) : \
(n == 2 ? GUINT16_FROM_BE( *(uint16_t *)(x) ) : *(uint8_t *)(x) ))
(n == 2 ? GUINT16_FROM_BE( *(uint16_t *)(x) ) : \
*(uint8_t *)(x) )))
#define be64dec(x) GUINT64_FROM_BE( *(uint64_t*)(x) )
#define be64dec(x) GUINT64_FROM_BE( *(uint64_t*)(x) )
#define get_needed_bytes(x) (x <= 1<<8 ? 1 : ( x <= 1<<16 ? 2 : ( x <= (uint64_t)1<<32 ? 4 : 8)))
#define get_needed_bytes(x) \
( ((uint64_t)x) < (1ULL << 8) ? 1 : \
( ((uint64_t)x) < (1ULL << 16) ? 2 : \
( ((uint64_t)x) < (1ULL << 32) ? 4 : 8)))
#define get_real_bytes(x) (x >> 32 ? 4 : 8)
#define get_real_bytes(x) (x >> 32 ? 4 : 8)
...
@@ -118,12 +123,8 @@ static plist_t parse_real_node(char *bnode, uint8_t size)
...
@@ -118,12 +123,8 @@ static plist_t parse_real_node(char *bnode, uint8_t size)
size
=
1
<<
size
;
// make length less misleading
size
=
1
<<
size
;
// make length less misleading
switch
(
size
)
{
switch
(
size
)
{
case
sizeof
(
float
):
case
sizeof
(
float
):
memcpy
(
&
data
->
realval
,
bnode
,
size
);
byte_convert
((
char
*
)
&
data
->
realval
,
size
);
break
;
case
sizeof
(
double
):
case
sizeof
(
double
):
memcpy
(
&
data
->
realval
,
bnode
,
size
);
data
->
realval
=
swap_n_bytes
(
bnode
,
size
);
byte_convert
((
char
*
)
&
data
->
realval
,
size
);
break
;
break
;
default:
default:
free
(
data
);
free
(
data
);
...
@@ -163,8 +164,8 @@ static plist_t parse_data_node(char *bnode, uint64_t size)
...
@@ -163,8 +164,8 @@ static plist_t parse_data_node(char *bnode, uint64_t size)
data
->
type
=
PLIST_DATA
;
data
->
type
=
PLIST_DATA
;
data
->
length
=
size
;
data
->
length
=
size
;
data
->
buff
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
size
);
data
->
buff
=
(
uint8_t
*
)
malloc
(
sizeof
(
uint8_t
)
*
size
);
memcpy
(
data
->
buff
,
bnode
,
sizeof
(
char
)
*
size
);
memcpy
(
data
->
buff
,
bnode
,
sizeof
(
uint8_t
)
*
size
);
return
g_node_new
(
data
);
return
g_node_new
(
data
);
}
}
...
@@ -175,8 +176,8 @@ static plist_t parse_dict_node(char *bnode, uint64_t size, uint32_t ref_size)
...
@@ -175,8 +176,8 @@ static plist_t parse_dict_node(char *bnode, uint64_t size, uint32_t ref_size)
data
->
type
=
PLIST_DICT
;
data
->
type
=
PLIST_DICT
;
data
->
length
=
size
;
data
->
length
=
size
;
data
->
buff
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
size
*
ref_size
*
2
);
data
->
buff
=
(
uint8_t
*
)
malloc
(
sizeof
(
uint8_t
)
*
size
*
ref_size
*
2
);
memcpy
(
data
->
buff
,
bnode
,
sizeof
(
char
)
*
size
*
ref_size
*
2
);
memcpy
(
data
->
buff
,
bnode
,
sizeof
(
uint8_t
)
*
size
*
ref_size
*
2
);
return
g_node_new
(
data
);
return
g_node_new
(
data
);
}
}
...
@@ -187,8 +188,8 @@ static plist_t parse_array_node(char *bnode, uint64_t size, uint32_t ref_size)
...
@@ -187,8 +188,8 @@ static plist_t parse_array_node(char *bnode, uint64_t size, uint32_t ref_size)
data
->
type
=
PLIST_ARRAY
;
data
->
type
=
PLIST_ARRAY
;
data
->
length
=
size
;
data
->
length
=
size
;
data
->
buff
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
size
*
ref_size
);
data
->
buff
=
(
uint8_t
*
)
malloc
(
sizeof
(
uint8_t
)
*
size
*
ref_size
);
memcpy
(
data
->
buff
,
bnode
,
sizeof
(
char
)
*
size
*
ref_size
);
memcpy
(
data
->
buff
,
bnode
,
sizeof
(
uint8_t
)
*
size
*
ref_size
);
return
g_node_new
(
data
);
return
g_node_new
(
data
);
}
}
...
@@ -321,12 +322,12 @@ static gpointer copy_plist_data(gconstpointer src, gpointer data)
...
@@ -321,12 +322,12 @@ static gpointer copy_plist_data(gconstpointer src, gpointer data)
break
;
break
;
case
PLIST_DATA
:
case
PLIST_DATA
:
case
PLIST_ARRAY
:
case
PLIST_ARRAY
:
dstdata
->
buff
=
(
char
*
)
malloc
(
sizeof
(
char
*
)
*
srcdata
->
length
);
dstdata
->
buff
=
(
uint8_t
*
)
malloc
(
sizeof
(
uint8_t
*
)
*
srcdata
->
length
);
memcpy
(
dstdata
->
buff
,
srcdata
->
buff
,
sizeof
(
char
*
)
*
srcdata
->
length
);
memcpy
(
dstdata
->
buff
,
srcdata
->
buff
,
sizeof
(
uint8_t
*
)
*
srcdata
->
length
);
break
;
break
;
case
PLIST_DICT
:
case
PLIST_DICT
:
dstdata
->
buff
=
(
char
*
)
malloc
(
sizeof
(
char
*
)
*
srcdata
->
length
*
2
);
dstdata
->
buff
=
(
uint8_t
*
)
malloc
(
sizeof
(
uint8_t
*
)
*
srcdata
->
length
*
2
);
memcpy
(
dstdata
->
buff
,
srcdata
->
buff
,
sizeof
(
char
*
)
*
srcdata
->
length
*
2
);
memcpy
(
dstdata
->
buff
,
srcdata
->
buff
,
sizeof
(
uint8_t
*
)
*
srcdata
->
length
*
2
);
break
;
break
;
default:
default:
break
;
break
;
...
@@ -561,7 +562,9 @@ static void serialize_plist(GNode * node, gpointer data)
...
@@ -561,7 +562,9 @@ static void serialize_plist(GNode * node, gpointer data)
return
;
return
;
}
}
//insert new ref
//insert new ref
g_hash_table_insert
(
ser
->
ref_table
,
node
,
GUINT_TO_POINTER
(
current_index
));
uint64_t
*
index_val
=
(
uint64_t
*
)
malloc
(
sizeof
(
uint64_t
));
*
index_val
=
current_index
;
g_hash_table_insert
(
ser
->
ref_table
,
node
,
index_val
);
//now append current node to object array
//now append current node to object array
g_ptr_array_add
(
ser
->
objects
,
node
);
g_ptr_array_add
(
ser
->
objects
,
node
);
...
@@ -571,6 +574,12 @@ static void serialize_plist(GNode * node, gpointer data)
...
@@ -571,6 +574,12 @@ static void serialize_plist(GNode * node, gpointer data)
return
;
return
;
}
}
static
gboolean
free_index
(
gpointer
key
,
gpointer
value
,
gpointer
user_data
)
{
free
((
uint64_t
*
)
value
);
return
TRUE
;
}
#define Log2(x) (x == 8 ? 3 : (x == 4 ? 2 : (x == 2 ? 1 : 0)))
#define Log2(x) (x == 8 ? 3 : (x == 4 ? 2 : (x == 2 ? 1 : 0)))
static
void
write_int
(
GByteArray
*
bplist
,
uint64_t
val
)
static
void
write_int
(
GByteArray
*
bplist
,
uint64_t
val
)
...
@@ -619,7 +628,7 @@ static void write_data(GByteArray * bplist, uint8_t * val, uint64_t size)
...
@@ -619,7 +628,7 @@ static void write_data(GByteArray * bplist, uint8_t * val, uint64_t size)
static
void
write_string
(
GByteArray
*
bplist
,
char
*
val
)
static
void
write_string
(
GByteArray
*
bplist
,
char
*
val
)
{
{
uint64_t
size
=
strlen
(
val
);
uint64_t
size
=
strlen
(
val
);
write_raw_data
(
bplist
,
BPLIST_STRING
,
val
,
size
);
write_raw_data
(
bplist
,
BPLIST_STRING
,
(
uint8_t
*
)
val
,
size
);
}
}
static
void
write_array
(
GByteArray
*
bplist
,
GNode
*
node
,
GHashTable
*
ref_table
,
uint8_t
dict_param_size
)
static
void
write_array
(
GByteArray
*
bplist
,
GNode
*
node
,
GHashTable
*
ref_table
,
uint8_t
dict_param_size
)
...
@@ -640,7 +649,7 @@ static void write_array(GByteArray * bplist, GNode * node, GHashTable * ref_tabl
...
@@ -640,7 +649,7 @@ static void write_array(GByteArray * bplist, GNode * node, GHashTable * ref_tabl
GNode
*
cur
=
NULL
;
GNode
*
cur
=
NULL
;
uint64_t
i
=
0
;
uint64_t
i
=
0
;
for
(
i
=
0
,
cur
=
node
->
children
;
cur
&&
i
<
size
;
cur
=
cur
->
next
,
i
++
)
{
for
(
i
=
0
,
cur
=
node
->
children
;
cur
&&
i
<
size
;
cur
=
cur
->
next
,
i
++
)
{
idx
=
GPOINTER_TO_UINT
(
g_hash_table_lookup
(
ref_table
,
cur
));
idx
=
*
(
uint64_t
*
)
(
g_hash_table_lookup
(
ref_table
,
cur
));
memcpy
(
buff
+
i
*
dict_param_size
,
&
idx
,
dict_param_size
);
memcpy
(
buff
+
i
*
dict_param_size
,
&
idx
,
dict_param_size
);
byte_convert
(
buff
+
i
*
dict_param_size
,
dict_param_size
);
byte_convert
(
buff
+
i
*
dict_param_size
,
dict_param_size
);
}
}
...
@@ -747,7 +756,7 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
...
@@ -747,7 +756,7 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
//TODO
//TODO
break
;
break
;
case
PLIST_DATA
:
case
PLIST_DATA
:
write_data
(
bplist_buff
,
data
->
strval
,
data
->
length
);
write_data
(
bplist_buff
,
data
->
buff
,
data
->
length
);
case
PLIST_ARRAY
:
case
PLIST_ARRAY
:
write_array
(
bplist_buff
,
g_ptr_array_index
(
objects
,
i
),
ref_table
,
dict_param_size
);
write_array
(
bplist_buff
,
g_ptr_array_index
(
objects
,
i
),
ref_table
,
dict_param_size
);
break
;
break
;
...
@@ -762,6 +771,9 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
...
@@ -762,6 +771,9 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
}
}
}
}
//free intermediate objects
g_hash_table_foreach_remove
(
ref_table
,
free_index
,
NULL
);
//write offsets
//write offsets
offset_size
=
get_needed_bytes
(
bplist_buff
->
len
);
offset_size
=
get_needed_bytes
(
bplist_buff
->
len
);
offset_table_index
=
bplist_buff
->
len
;
offset_table_index
=
bplist_buff
->
len
;
...
@@ -778,7 +790,7 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
...
@@ -778,7 +790,7 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
root_object
=
GUINT64_FROM_BE
(
root_object
);
root_object
=
GUINT64_FROM_BE
(
root_object
);
offset_table_index
=
GUINT64_FROM_BE
(
offset_table_index
);
offset_table_index
=
GUINT64_FROM_BE
(
offset_table_index
);
char
trailer
[
BPLIST_TRL_SIZE
];
uint8_t
trailer
[
BPLIST_TRL_SIZE
];
memcpy
(
trailer
+
BPLIST_TRL_OFFSIZE_IDX
,
&
offset_size
,
sizeof
(
uint8_t
));
memcpy
(
trailer
+
BPLIST_TRL_OFFSIZE_IDX
,
&
offset_size
,
sizeof
(
uint8_t
));
memcpy
(
trailer
+
BPLIST_TRL_PARMSIZE_IDX
,
&
dict_param_size
,
sizeof
(
uint8_t
));
memcpy
(
trailer
+
BPLIST_TRL_PARMSIZE_IDX
,
&
dict_param_size
,
sizeof
(
uint8_t
));
memcpy
(
trailer
+
BPLIST_TRL_NUMOBJ_IDX
,
&
num_objects
,
sizeof
(
uint64_t
));
memcpy
(
trailer
+
BPLIST_TRL_NUMOBJ_IDX
,
&
num_objects
,
sizeof
(
uint64_t
));
...
...
src/plist.h
View file @
a3c6acf8
...
@@ -43,7 +43,7 @@ struct plist_data_s {
...
@@ -43,7 +43,7 @@ struct plist_data_s {
double
realval
;
double
realval
;
char
*
strval
;
char
*
strval
;
wchar_t
*
unicodeval
;
wchar_t
*
unicodeval
;
char
*
buff
;
uint8_t
*
buff
;
};
};
uint64_t
length
;
uint64_t
length
;
plist_type
type
;
plist_type
type
;
...
...
src/xplist.c
View file @
a3c6acf8
...
@@ -32,6 +32,17 @@
...
@@ -32,6 +32,17 @@
#include <libxml/parser.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/tree.h>
#define XPLIST_TEXT BAD_CAST("text")
#define XPLIST_KEY BAD_CAST("key")
#define XPLIST_FALSE BAD_CAST("false")
#define XPLIST_TRUE BAD_CAST("true")
#define XPLIST_INT BAD_CAST("integer")
#define XPLIST_REAL BAD_CAST("real")
#define XPLIST_DATE BAD_CAST("date")
#define XPLIST_DATA BAD_CAST("data")
#define XPLIST_STRING BAD_CAST("string")
#define XPLIST_ARRAY BAD_CAST("array")
#define XPLIST_DICT BAD_CAST("dict")
const
char
*
plist_base
=
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?>
\n
\
const
char
*
plist_base
=
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?>
\n
\
<!DOCTYPE plist PUBLIC
\"
-//Apple Computer//DTD PLIST 1.0//EN
\"
\"
http://www.apple.com/DTDs/PropertyList-1.0.dtd
\"
>
\n
\
<!DOCTYPE plist PUBLIC
\"
-//Apple Computer//DTD PLIST 1.0//EN
\"
\"
http://www.apple.com/DTDs/PropertyList-1.0.dtd
\"
>
\n
\
...
@@ -125,56 +136,56 @@ static void node_to_xml(GNode * node, gpointer xml_struct)
...
@@ -125,56 +136,56 @@ static void node_to_xml(GNode * node, gpointer xml_struct)
xmlNodePtr
child_node
=
NULL
;
xmlNodePtr
child_node
=
NULL
;
char
isStruct
=
FALSE
;
char
isStruct
=
FALSE
;
const
gc
har
*
tag
=
NULL
;
const
xmlC
har
*
tag
=
NULL
;
const
gchar
*
val
=
NULL
;
gchar
*
val
=
NULL
;
switch
(
node_data
->
type
)
{
switch
(
node_data
->
type
)
{
case
PLIST_BOOLEAN
:
case
PLIST_BOOLEAN
:
{
{
if
(
node_data
->
boolval
)
if
(
node_data
->
boolval
)
tag
=
"true"
;
tag
=
XPLIST_TRUE
;
else
else
tag
=
"false"
;
tag
=
XPLIST_FALSE
;
}
}
break
;
break
;
case
PLIST_UINT
:
case
PLIST_UINT
:
tag
=
"integer"
;
tag
=
XPLIST_INT
;
val
=
g_strdup_printf
(
"%lu"
,
(
long
unsigned
int
)
node_data
->
intval
);
val
=
g_strdup_printf
(
"%lu"
,
(
long
unsigned
int
)
node_data
->
intval
);
break
;
break
;
case
PLIST_REAL
:
case
PLIST_REAL
:
tag
=
"real"
;
tag
=
XPLIST_REAL
;
val
=
g_strdup_printf
(
"%Lf"
,
(
long
double
)
node_data
->
realval
);
val
=
g_strdup_printf
(
"%Lf"
,
(
long
double
)
node_data
->
realval
);
break
;
break
;
case
PLIST_STRING
:
case
PLIST_STRING
:
tag
=
"string"
;
tag
=
XPLIST_STRING
;
val
=
g_strdup
(
node_data
->
strval
);
val
=
g_strdup
(
node_data
->
strval
);
break
;
break
;
case
PLIST_UNICODE
:
case
PLIST_UNICODE
:
tag
=
"string"
;
tag
=
XPLIST_STRING
;
val
=
g_strdup
((
gchar
*
)
node_data
->
unicodeval
);
val
=
g_strdup
((
gchar
*
)
node_data
->
unicodeval
);
break
;
break
;
case
PLIST_KEY
:
case
PLIST_KEY
:
tag
=
"key"
;
tag
=
XPLIST_KEY
;
val
=
g_strdup
((
gchar
*
)
node_data
->
strval
);
val
=
g_strdup
((
gchar
*
)
node_data
->
strval
);
break
;
break
;
case
PLIST_DATA
:
case
PLIST_DATA
:
tag
=
"data"
;
tag
=
XPLIST_DATA
;
gchar
*
valtmp
=
g_base64_encode
(
node_data
->
buff
,
node_data
->
length
);
gchar
*
valtmp
=
g_base64_encode
(
node_data
->
buff
,
node_data
->
length
);
val
=
format_string
(
valtmp
,
68
,
xstruct
->
depth
);
val
=
format_string
(
valtmp
,
68
,
xstruct
->
depth
);
g_free
(
valtmp
);
g_free
(
valtmp
);
break
;
break
;
case
PLIST_ARRAY
:
case
PLIST_ARRAY
:
tag
=
"array"
;
tag
=
XPLIST_ARRAY
;
isStruct
=
TRUE
;
isStruct
=
TRUE
;
break
;
break
;
case
PLIST_DICT
:
case
PLIST_DICT
:
tag
=
"dict"
;
tag
=
XPLIST_DICT
;
isStruct
=
TRUE
;
isStruct
=
TRUE
;
break
;
break
;
case
PLIST_DATE
:
//TODO : handle date tag
case
PLIST_DATE
:
//TODO : handle date tag
...
@@ -182,17 +193,17 @@ static void node_to_xml(GNode * node, gpointer xml_struct)
...
@@ -182,17 +193,17 @@ static void node_to_xml(GNode * node, gpointer xml_struct)
break
;
break
;
}
}
in
t
i
=
0
;
uint32_
t
i
=
0
;
for
(
i
=
0
;
i
<
xstruct
->
depth
;
i
++
)
{
for
(
i
=
0
;
i
<
xstruct
->
depth
;
i
++
)
{
xmlNodeAddContent
(
xstruct
->
xml
,
"
\t
"
);
xmlNodeAddContent
(
xstruct
->
xml
,
BAD_CAST
(
"
\t
"
)
);
}
}
child_node
=
xmlNewChild
(
xstruct
->
xml
,
NULL
,
tag
,
val
);
child_node
=
xmlNewChild
(
xstruct
->
xml
,
NULL
,
tag
,
BAD_CAST
(
val
)
);
xmlNodeAddContent
(
xstruct
->
xml
,
"
\n
"
);
xmlNodeAddContent
(
xstruct
->
xml
,
BAD_CAST
(
"
\n
"
)
);
g_free
(
val
);
g_free
(
val
);
//add return for structured types
//add return for structured types
if
(
node_data
->
type
==
PLIST_ARRAY
||
node_data
->
type
==
PLIST_DICT
)
if
(
node_data
->
type
==
PLIST_ARRAY
||
node_data
->
type
==
PLIST_DICT
)
xmlNodeAddContent
(
child_node
,
"
\n
"
);
xmlNodeAddContent
(
child_node
,
BAD_CAST
(
"
\n
"
)
);
if
(
isStruct
)
{
if
(
isStruct
)
{
struct
xml_node
child
=
{
child_node
,
xstruct
->
depth
+
1
};
struct
xml_node
child
=
{
child_node
,
xstruct
->
depth
+
1
};
...
@@ -202,20 +213,20 @@ static void node_to_xml(GNode * node, gpointer xml_struct)
...
@@ -202,20 +213,20 @@ static void node_to_xml(GNode * node, gpointer xml_struct)
if
(
node_data
->
type
==
PLIST_ARRAY
||
node_data
->
type
==
PLIST_DICT
)
{
if
(
node_data
->
type
==
PLIST_ARRAY
||
node_data
->
type
==
PLIST_DICT
)
{
for
(
i
=
0
;
i
<
xstruct
->
depth
;
i
++
)
{
for
(
i
=
0
;
i
<
xstruct
->
depth
;
i
++
)
{
xmlNodeAddContent
(
child_node
,
"
\t
"
);
xmlNodeAddContent
(
child_node
,
BAD_CAST
(
"
\t
"
)
);
}
}
}
}
return
;
return
;
}
}
void
xml_to_node
(
xmlNodePtr
xml_node
,
plist_t
*
plist_node
)
static
void
xml_to_node
(
xmlNodePtr
xml_node
,
plist_t
*
plist_node
)
{
{
xmlNodePtr
node
=
NULL
;
xmlNodePtr
node
=
NULL
;
for
(
node
=
xml_node
->
children
;
node
;
node
=
node
->
next
)
{
for
(
node
=
xml_node
->
children
;
node
;
node
=
node
->
next
)
{
while
(
node
&&
!
xmlStrcmp
(
node
->
name
,
"text"
))
while
(
node
&&
!
xmlStrcmp
(
node
->
name
,
XPLIST_TEXT
))
node
=
node
->
next
;
node
=
node
->
next
;
if
(
!
node
)
if
(
!
node
)
break
;
break
;
...
@@ -227,68 +238,68 @@ void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node)
...
@@ -227,68 +238,68 @@ void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node)
else
else
*
plist_node
=
subnode
;
*
plist_node
=
subnode
;
if
(
!
xmlStrcmp
(
node
->
name
,
"true"
))
{
if
(
!
xmlStrcmp
(
node
->
name
,
XPLIST_TRUE
))
{
data
->
boolval
=
1
;
data
->
boolval
=
TRUE
;
data
->
type
=
PLIST_BOOLEAN
;
data
->
type
=
PLIST_BOOLEAN
;
data
->
length
=
1
;
data
->
length
=
1
;
continue
;
continue
;
}
}
if
(
!
xmlStrcmp
(
node
->
name
,
"false"
))
{
if
(
!
xmlStrcmp
(
node
->
name
,
XPLIST_FALSE
))
{
data
->
boolval
=
0
;
data
->
boolval
=
FALSE
;
data
->
type
=
PLIST_BOOLEAN
;
data
->
type
=
PLIST_BOOLEAN
;
data
->
length
=
1
;
data
->
length
=
1
;
continue
;
continue
;
}
}
if
(
!
xmlStrcmp
(
node
->
name
,
"integer"
))
{
if
(
!
xmlStrcmp
(
node
->
name
,
XPLIST_INT
))
{
char
*
strval
=
xmlNodeGetContent
(
node
);
char
*
strval
=
(
char
*
)
xmlNodeGetContent
(
node
);
data
->
intval
=
g_ascii_strtoull
(
strval
,
NULL
,
0
);
data
->
intval
=
g_ascii_strtoull
(
strval
,
NULL
,
0
);
data
->
type
=
PLIST_UINT
;
data
->
type
=
PLIST_UINT
;
data
->
length
=
8
;
data
->
length
=
8
;
continue
;
continue
;
}
}
if
(
!
xmlStrcmp
(
node
->
name
,
"real"
))
{
if
(
!
xmlStrcmp
(
node
->
name
,
XPLIST_REAL
))
{
char
*
strval
=
xmlNodeGetContent
(
node
);
char
*
strval
=
(
char
*
)
xmlNodeGetContent
(
node
);
data
->
realval
=
atof
(
strval
);
data
->
realval
=
atof
(
strval
);
data
->
type
=
PLIST_REAL
;
data
->
type
=
PLIST_REAL
;
data
->
length
=
8
;
data
->
length
=
8
;
continue
;
continue
;
}
}
if
(
!
xmlStrcmp
(
node
->
name
,
"date"
))
if
(
!
xmlStrcmp
(
node
->
name
,
XPLIST_DATE
))
continue
;
//TODO : handle date tag
continue
;
//TODO : handle date tag
if
(
!
xmlStrcmp
(
node
->
name
,
"string"
))
{
if
(
!
xmlStrcmp
(
node
->
name
,
XPLIST_STRING
))
{
data
->
strval
=
strdup
(
xmlNodeGetContent
(
node
));
data
->
strval
=
strdup
(
(
char
*
)
xmlNodeGetContent
(
node
));
data
->
type
=
PLIST_STRING
;
data
->
type
=
PLIST_STRING
;
data
->
length
=
strlen
(
data
->
strval
);
data
->
length
=
strlen
(
data
->
strval
);
continue
;
continue
;
}
}
if
(
!
xmlStrcmp
(
node
->
name
,
"key"
))
{
if
(
!
xmlStrcmp
(
node
->
name
,
XPLIST_KEY
))
{
data
->
strval
=
strdup
(
xmlNodeGetContent
(
node
));
data
->
strval
=
strdup
(
(
char
*
)
xmlNodeGetContent
(
node
));
data
->
type
=
PLIST_KEY
;
data
->
type
=
PLIST_KEY
;
data
->
length
=
strlen
(
data
->
strval
);
data
->
length
=
strlen
(
data
->
strval
);
continue
;
continue
;
}
}
if
(
!
xmlStrcmp
(
node
->
name
,
"data"
))
{
if
(
!
xmlStrcmp
(
node
->
name
,
XPLIST_DATA
))
{
gsize
size
=
0
;
gsize
size
=
0
;
data
->
buff
=
g_base64_decode
(
xmlNodeGetContent
(
node
),
&
size
);
data
->
buff
=
g_base64_decode
(
(
char
*
)
xmlNodeGetContent
(
node
),
&
size
);
data
->
length
=
size
;
data
->
length
=
size
;
data
->
type
=
PLIST_DATA
;
data
->
type
=
PLIST_DATA
;
continue
;
continue
;
}
}
if
(
!
xmlStrcmp
(
node
->
name
,
"array"
))
{
if
(
!
xmlStrcmp
(
node
->
name
,
XPLIST_ARRAY
))
{
data
->
type
=
PLIST_ARRAY
;
data
->
type
=
PLIST_ARRAY
;
xml_to_node
(
node
,
&
subnode
);
xml_to_node
(
node
,
&
subnode
);
continue
;
continue
;
}
}
if
(
!
xmlStrcmp
(
node
->
name
,
"dict"
))
{
if
(
!
xmlStrcmp
(
node
->
name
,
XPLIST_DICT
))
{
data
->
type
=
PLIST_DICT
;
data
->
type
=
PLIST_DICT
;
xml_to_node
(
node
,
&
subnode
);
xml_to_node
(
node
,
&
subnode
);
continue
;
continue
;
...
@@ -306,7 +317,11 @@ void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length)
...
@@ -306,7 +317,11 @@ void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length)
node_to_xml
(
plist
,
&
root
);
node_to_xml
(
plist
,
&
root
);
xmlDocDumpMemory
(
plist_doc
,
(
xmlChar
**
)
plist_xml
,
length
);
int
size
=
0
;
xmlDocDumpMemory
(
plist_doc
,
(
xmlChar
**
)
plist_xml
,
&
size
);
if
(
size
>=
0
)
*
length
=
size
;
free_plist
(
plist_doc
);
}
}
void
plist_from_xml
(
const
char
*
plist_xml
,
uint32_t
length
,
plist_t
*
plist
)
void
plist_from_xml
(
const
char
*
plist_xml
,
uint32_t
length
,
plist_t
*
plist
)
...
...
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