summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am2
-rwxr-xr-xautogen.sh2
-rw-r--r--configure.ac4
-rw-r--r--m4/as-compiler-flag.m462
-rw-r--r--src/Makefile.am2
-rw-r--r--src/bplist.c42
-rw-r--r--src/plist.c2
-rw-r--r--src/plist.h2
8 files changed, 93 insertions, 25 deletions
diff --git a/Makefile.am b/Makefile.am
index 7a67ab6..e88e9be 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,5 @@
1AUTOMAKE_OPTIONS = foreign 1AUTOMAKE_OPTIONS = foreign
2 2ACLOCAL_AMFLAGS = -I m4
3SUBDIRS = src include plutil 3SUBDIRS = src include plutil
4 4
5pkgconfigdir = $(libdir)/pkgconfig 5pkgconfigdir = $(libdir)/pkgconfig
diff --git a/autogen.sh b/autogen.sh
index c17ea96..9aa7170 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -1,5 +1,5 @@
1#!/bin/sh 1#!/bin/sh
2aclocal 2aclocal -I m4
3libtoolize 3libtoolize
4autoheader 4autoheader
5automake --add-missing 5automake --add-missing
diff --git a/configure.ac b/configure.ac
index aa3a2e2..4af0e49 100644
--- a/configure.ac
+++ b/configure.ac
@@ -6,6 +6,7 @@ AC_INIT(libplist, 0.1.0, nospam@nowhere.com)
6AM_INIT_AUTOMAKE(libplist, 0.1.0) 6AM_INIT_AUTOMAKE(libplist, 0.1.0)
7AC_CONFIG_SRCDIR([src/]) 7AC_CONFIG_SRCDIR([src/])
8AC_CONFIG_HEADER([config.h]) 8AC_CONFIG_HEADER([config.h])
9AC_CONFIG_MACRO_DIR([m4])
9 10
10AC_PROG_LIBTOOL 11AC_PROG_LIBTOOL
11 12
@@ -44,4 +45,7 @@ if test "$no_debug_code" = true; then
44 AC_DEFINE(STRIP_DEBUG_CODE,1,[Strip debug reporting code]) 45 AC_DEFINE(STRIP_DEBUG_CODE,1,[Strip debug reporting code])
45fi 46fi
46 47
48AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Wall -Wextra -Wmissing-declarations -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default")
49AC_SUBST(GLOBAL_CFLAGS)
50
47AC_OUTPUT(Makefile src/Makefile include/Makefile plutil/Makefile libplist-1.0.pc) 51AC_OUTPUT(Makefile src/Makefile include/Makefile plutil/Makefile libplist-1.0.pc)
diff --git a/m4/as-compiler-flag.m4 b/m4/as-compiler-flag.m4
new file mode 100644
index 0000000..0f660cf
--- /dev/null
+++ b/m4/as-compiler-flag.m4
@@ -0,0 +1,62 @@
1dnl as-compiler-flag.m4 0.1.0
2
3dnl autostars m4 macro for detection of compiler flags
4
5dnl David Schleef <ds@schleef.org>
6
7dnl $Id: as-compiler-flag.m4,v 1.1 2005/12/15 23:35:19 ds Exp $
8
9dnl AS_COMPILER_FLAG(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
10dnl Tries to compile with the given CFLAGS.
11dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
12dnl and ACTION-IF-NOT-ACCEPTED otherwise.
13
14AC_DEFUN([AS_COMPILER_FLAG],
15[
16 AC_MSG_CHECKING([to see if compiler understands $1])
17
18 save_CFLAGS="$CFLAGS"
19 CFLAGS="$CFLAGS $1"
20
21 AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
22 CFLAGS="$save_CFLAGS"
23
24 if test "X$flag_ok" = Xyes ; then
25 m4_ifvaln([$2],[$2])
26 true
27 else
28 m4_ifvaln([$3],[$3])
29 true
30 fi
31 AC_MSG_RESULT([$flag_ok])
32])
33
34dnl AS_COMPILER_FLAGS(VAR, FLAGS)
35dnl Tries to compile with the given CFLAGS.
36
37AC_DEFUN([AS_COMPILER_FLAGS],
38[
39 list=$2
40 flags_supported=""
41 flags_unsupported=""
42 AC_MSG_CHECKING([for supported compiler flags])
43 for each in $list
44 do
45 save_CFLAGS="$CFLAGS"
46 CFLAGS="$CFLAGS $each"
47 AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
48 CFLAGS="$save_CFLAGS"
49
50 if test "X$flag_ok" = Xyes ; then
51 flags_supported="$flags_supported $each"
52 else
53 flags_unsupported="$flags_unsupported $each"
54 fi
55 done
56 AC_MSG_RESULT([$flags_supported])
57 if test "X$flags_unsupported" != X ; then
58 AC_MSG_WARN([unsupported compiler flags: $flags_unsupported])
59 fi
60 $1="$$1 $flags_supported"
61])
62
diff --git a/src/Makefile.am b/src/Makefile.am
index 07143b6..3178d8a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,6 @@
1INCLUDES = -I$(top_srcdir)/include 1INCLUDES = -I$(top_srcdir)/include
2 2
3AM_CFLAGS = $(libxml2_CFLAGS) $(libglib2_CFLAGS) -D_GNU_SOURCE 3AM_CFLAGS = $(GLOBAL_CFLAGS) $(libxml2_CFLAGS) $(libglib2_CFLAGS) -D_GNU_SOURCE
4AM_LDFLAGS = $(libxml2_LIBS) $(libglib2_LIBS) 4AM_LDFLAGS = $(libxml2_LIBS) $(libglib2_LIBS)
5 5
6lib_LTLIBRARIES = libplist.la 6lib_LTLIBRARIES = libplist.la
diff --git a/src/bplist.c b/src/bplist.c
index 54a4bb2..94d7458 100644
--- a/src/bplist.c
+++ b/src/bplist.c
@@ -59,9 +59,9 @@ enum {
59 BPLIST_MASK = 0xF0 59 BPLIST_MASK = 0xF0
60}; 60};
61 61
62void byte_convert(char *address, size_t size) 62static void byte_convert(char *address, size_t size)
63{ 63{
64 int i = 0, j = 0; 64 uint8_t i = 0, j = 0;
65 char tmp = '\0'; 65 char tmp = '\0';
66 66
67 for (i = 0; i < (size / 2); i++) { 67 for (i = 0; i < (size / 2); i++) {
@@ -83,7 +83,7 @@ void byte_convert(char *address, size_t size)
83#define get_needed_bytes(x) (x <= 1<<8 ? 1 : ( x <= 1<<16 ? 2 : ( x <= (uint64_t)1<<32 ? 4 : 8))) 83#define get_needed_bytes(x) (x <= 1<<8 ? 1 : ( x <= 1<<16 ? 2 : ( x <= (uint64_t)1<<32 ? 4 : 8)))
84#define get_real_bytes(x) (x >> 32 ? 4 : 8) 84#define get_real_bytes(x) (x >> 32 ? 4 : 8)
85 85
86plist_t parse_uint_node(char *bnode, uint8_t size, char **next_object) 86static plist_t parse_uint_node(char *bnode, uint8_t size, char **next_object)
87{ 87{
88 plist_data_t data = plist_new_plist_data(); 88 plist_data_t data = plist_new_plist_data();
89 89
@@ -114,7 +114,7 @@ plist_t parse_uint_node(char *bnode, uint8_t size, char **next_object)
114 return g_node_new(data); 114 return g_node_new(data);
115} 115}
116 116
117plist_t parse_real_node(char *bnode, uint8_t size) 117static plist_t parse_real_node(char *bnode, uint8_t size)
118{ 118{
119 plist_data_t data = plist_new_plist_data(); 119 plist_data_t data = plist_new_plist_data();
120 120
@@ -136,7 +136,7 @@ plist_t parse_real_node(char *bnode, uint8_t size)
136 return g_node_new(data); 136 return g_node_new(data);
137} 137}
138 138
139plist_t parse_string_node(char *bnode, uint8_t size) 139static plist_t parse_string_node(char *bnode, uint8_t size)
140{ 140{
141 plist_data_t data = plist_new_plist_data(); 141 plist_data_t data = plist_new_plist_data();
142 142
@@ -148,7 +148,7 @@ plist_t parse_string_node(char *bnode, uint8_t size)
148 return g_node_new(data); 148 return g_node_new(data);
149} 149}
150 150
151plist_t parse_unicode_node(char *bnode, uint8_t size) 151static plist_t parse_unicode_node(char *bnode, uint8_t size)
152{ 152{
153 plist_data_t data = plist_new_plist_data(); 153 plist_data_t data = plist_new_plist_data();
154 154
@@ -160,7 +160,7 @@ plist_t parse_unicode_node(char *bnode, uint8_t size)
160 return g_node_new(data); 160 return g_node_new(data);
161} 161}
162 162
163plist_t parse_data_node(char *bnode, uint64_t size, uint32_t ref_size) 163static plist_t parse_data_node(char *bnode, uint64_t size, uint32_t ref_size)
164{ 164{
165 plist_data_t data = plist_new_plist_data(); 165 plist_data_t data = plist_new_plist_data();
166 166
@@ -172,7 +172,7 @@ plist_t parse_data_node(char *bnode, uint64_t size, uint32_t ref_size)
172 return g_node_new(data); 172 return g_node_new(data);
173} 173}
174 174
175plist_t parse_dict_node(char *bnode, uint64_t size, uint32_t ref_size) 175static plist_t parse_dict_node(char *bnode, uint64_t size, uint32_t ref_size)
176{ 176{
177 plist_data_t data = plist_new_plist_data(); 177 plist_data_t data = plist_new_plist_data();
178 178
@@ -184,7 +184,7 @@ plist_t parse_dict_node(char *bnode, uint64_t size, uint32_t ref_size)
184 return g_node_new(data); 184 return g_node_new(data);
185} 185}
186 186
187plist_t parse_array_node(char *bnode, uint64_t size, uint32_t ref_size) 187static plist_t parse_array_node(char *bnode, uint64_t size, uint32_t ref_size)
188{ 188{
189 plist_data_t data = plist_new_plist_data(); 189 plist_data_t data = plist_new_plist_data();
190 190
@@ -198,7 +198,7 @@ plist_t parse_array_node(char *bnode, uint64_t size, uint32_t ref_size)
198 198
199 199
200 200
201plist_t parse_bin_node(char *object, uint8_t dict_size, char **next_object) 201static plist_t parse_bin_node(char *object, uint8_t dict_size, char **next_object)
202{ 202{
203 if (!object) 203 if (!object)
204 return NULL; 204 return NULL;
@@ -297,7 +297,7 @@ plist_t parse_bin_node(char *object, uint8_t dict_size, char **next_object)
297 return NULL; 297 return NULL;
298} 298}
299 299
300gpointer copy_plist_data(gconstpointer src, gpointer data) 300static gpointer copy_plist_data(gconstpointer src, gpointer data)
301{ 301{
302 plist_data_t srcdata = (plist_data_t) src; 302 plist_data_t srcdata = (plist_data_t) src;
303 plist_data_t dstdata = plist_new_plist_data(); 303 plist_data_t dstdata = plist_new_plist_data();
@@ -387,7 +387,7 @@ void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist)
387 } 387 }
388 388
389 //setup children for structured types 389 //setup children for structured types
390 int j = 0, str_i = 0, str_j = 0; 390 uint32_t j = 0, str_i = 0, str_j = 0;
391 uint32_t index1 = 0, index2 = 0; 391 uint32_t index1 = 0, index2 = 0;
392 392
393 for (i = 0; i < num_objects; i++) { 393 for (i = 0; i < num_objects; i++) {
@@ -449,7 +449,7 @@ void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist)
449 *plist = nodeslist[root_object]; 449 *plist = nodeslist[root_object];
450} 450}
451 451
452guint plist_data_hash(gconstpointer key) 452static guint plist_data_hash(gconstpointer key)
453{ 453{
454 plist_data_t data = plist_get_data((plist_t) key); 454 plist_data_t data = plist_get_data((plist_t) key);
455 455
@@ -494,7 +494,7 @@ guint plist_data_hash(gconstpointer key)
494 return hash; 494 return hash;
495} 495}
496 496
497gboolean plist_data_compare(gconstpointer a, gconstpointer b) 497static gboolean plist_data_compare(gconstpointer a, gconstpointer b)
498{ 498{
499 if (!a || !b) 499 if (!a || !b)
500 return FALSE; 500 return FALSE;
@@ -550,7 +550,7 @@ struct serialize_s {
550 GHashTable *ref_table; 550 GHashTable *ref_table;
551}; 551};
552 552
553void serialize_plist(GNode * node, gpointer data) 553static void serialize_plist(GNode * node, gpointer data)
554{ 554{
555 struct serialize_s *ser = (struct serialize_s *) data; 555 struct serialize_s *ser = (struct serialize_s *) data;
556 uint64_t current_index = ser->objects->len; 556 uint64_t current_index = ser->objects->len;
@@ -585,7 +585,7 @@ void write_int(GByteArray * bplist, uint64_t val)
585 free(buff); 585 free(buff);
586} 586}
587 587
588void write_real(GByteArray * bplist, double val) 588static void write_real(GByteArray * bplist, double val)
589{ 589{
590 uint64_t size = get_real_bytes(*((uint64_t *) & val)); //cheat to know used space 590 uint64_t size = get_real_bytes(*((uint64_t *) & val)); //cheat to know used space
591 uint8_t *buff = (uint8_t *) malloc(sizeof(uint8_t) + size); 591 uint8_t *buff = (uint8_t *) malloc(sizeof(uint8_t) + size);
@@ -596,7 +596,7 @@ void write_real(GByteArray * bplist, double val)
596 free(buff); 596 free(buff);
597} 597}
598 598
599void write_raw_data(GByteArray * bplist, uint8_t mark, uint8_t * val, uint64_t size) 599static void write_raw_data(GByteArray * bplist, uint8_t mark, uint8_t * val, uint64_t size)
600{ 600{
601 uint8_t marker = mark | (size < 15 ? size : 0xf); 601 uint8_t marker = mark | (size < 15 ? size : 0xf);
602 g_byte_array_append(bplist, &marker, sizeof(uint8_t)); 602 g_byte_array_append(bplist, &marker, sizeof(uint8_t));
@@ -612,18 +612,18 @@ void write_raw_data(GByteArray * bplist, uint8_t mark, uint8_t * val, uint64_t s
612 free(buff); 612 free(buff);
613} 613}
614 614
615void write_data(GByteArray * bplist, uint8_t * val, uint64_t size) 615static void write_data(GByteArray * bplist, uint8_t * val, uint64_t size)
616{ 616{
617 write_raw_data(bplist, BPLIST_DATA, val, size); 617 write_raw_data(bplist, BPLIST_DATA, val, size);
618} 618}
619 619
620void write_string(GByteArray * bplist, char *val) 620static void write_string(GByteArray * bplist, char *val)
621{ 621{
622 uint64_t size = strlen(val); 622 uint64_t size = strlen(val);
623 write_raw_data(bplist, BPLIST_STRING, val, size); 623 write_raw_data(bplist, BPLIST_STRING, val, size);
624} 624}
625 625
626void write_array(GByteArray * bplist, GNode * node, GHashTable * ref_table, uint8_t dict_param_size) 626static void write_array(GByteArray * bplist, GNode * node, GHashTable * ref_table, uint8_t dict_param_size)
627{ 627{
628 uint64_t size = g_node_n_children(node); 628 uint64_t size = g_node_n_children(node);
629 uint8_t marker = BPLIST_ARRAY | (size < 15 ? size : 0xf); 629 uint8_t marker = BPLIST_ARRAY | (size < 15 ? size : 0xf);
@@ -652,7 +652,7 @@ void write_array(GByteArray * bplist, GNode * node, GHashTable * ref_table, uint
652 652
653} 653}
654 654
655void write_dict(GByteArray * bplist, GNode * node, GHashTable * ref_table, uint8_t dict_param_size) 655static void write_dict(GByteArray * bplist, GNode * node, GHashTable * ref_table, uint8_t dict_param_size)
656{ 656{
657 uint64_t size = g_node_n_children(node) / 2; 657 uint64_t size = g_node_n_children(node) / 2;
658 uint8_t marker = BPLIST_DICT | (size < 15 ? size : 0xf); 658 uint8_t marker = BPLIST_DICT | (size < 15 ? size : 0xf);
diff --git a/src/plist.c b/src/plist.c
index a3d3cb2..d737ab8 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -136,7 +136,7 @@ plist_t plist_get_prev_sibling(plist_t node)
136 return (plist_t) g_node_prev_sibling((GNode *) node); 136 return (plist_t) g_node_prev_sibling((GNode *) node);
137} 137}
138 138
139char compare_node_value(plist_type type, plist_data_t data, void *value, uint64_t length) 139static char compare_node_value(plist_type type, plist_data_t data, void *value, uint64_t length)
140{ 140{
141 char res = FALSE; 141 char res = FALSE;
142 switch (type) { 142 switch (type) {
diff --git a/src/plist.h b/src/plist.h
index b7c74d9..3f4036f 100644
--- a/src/plist.h
+++ b/src/plist.h
@@ -55,6 +55,8 @@ plist_t plist_new_node(plist_data_t data);
55plist_data_t plist_get_data(const plist_t node); 55plist_data_t plist_get_data(const plist_t node);
56plist_data_t plist_new_plist_data(); 56plist_data_t plist_new_plist_data();
57void plist_free_plist_data(plist_data_t node); 57void plist_free_plist_data(plist_data_t node);
58plist_type plist_get_node_type(plist_t node);
59uint64_t plist_get_node_uint_val(plist_t node);
58 60
59 61
60#endif 62#endif