Commit 6710f4bf authored by Jonathan Beck's avatar Jonathan Beck

Format sources to ANSI style using AStyle (astyle --style=ansi).

parent fed25735
......@@ -30,7 +30,7 @@ namespace PList
class Array : public Structure
{
public :
public :
Array(Node* parent = NULL);
Array(plist_t node, Node* parent = NULL);
Array(Array& a);
......@@ -45,7 +45,7 @@ class Array : public Structure
void Remove(Node* node);
void Remove(unsigned int pos);
private :
private :
std::vector<Node*> _array;
};
......
......@@ -29,7 +29,7 @@ namespace PList
class Boolean : public Node
{
public :
public :
Boolean(Node* parent = NULL);
Boolean(plist_t node, Node* parent = NULL);
Boolean(Boolean& b);
......
......@@ -30,7 +30,7 @@ namespace PList
class Data : public Node
{
public :
public :
Data(Node* parent = NULL);
Data(plist_t node, Node* parent = NULL);
Data(Data& d);
......
......@@ -34,7 +34,7 @@ namespace PList
class Date : public Node
{
public :
public :
Date(Node* parent = NULL);
Date(plist_t node, Node* parent = NULL);
Date(Date& d);
......
......@@ -31,7 +31,7 @@ namespace PList
class Dictionary : public Structure
{
public :
public :
Dictionary(Node* parent = NULL);
Dictionary(plist_t node, Node* parent = NULL);
Dictionary(Dictionary& d);
......@@ -50,7 +50,7 @@ class Dictionary : public Structure
void Remove(Node* node);
void Remove(const std::string& key);
private :
private :
std::map<std::string,Node*> _map;
......
......@@ -29,7 +29,7 @@ namespace PList
class Integer : public Node
{
public :
public :
Integer(Node* parent = NULL);
Integer(plist_t node, Node* parent = NULL);
Integer(Integer& i);
......
......@@ -29,7 +29,7 @@ namespace PList
class Node
{
public :
public :
virtual ~Node();
virtual Node* Clone() = 0;
......@@ -39,7 +39,7 @@ class Node
plist_type GetType();
plist_t GetPlist();
protected:
protected:
Node(Node* parent = NULL);
Node(plist_t node, Node* parent = NULL);
Node(plist_type type, Node* parent = NULL);
......
......@@ -29,7 +29,7 @@ namespace PList
class Real : public Node
{
public :
public :
Real(Node* parent = NULL);
Real(plist_t node, Node* parent = NULL);
Real(Real& d);
......
......@@ -30,7 +30,7 @@ namespace PList
class String : public Node
{
public :
public :
String(Node* parent = NULL);
String(plist_t node, Node* parent = NULL);
String(String& s);
......
......@@ -31,7 +31,7 @@ namespace PList
class Structure : public Node
{
public :
public :
virtual ~Structure();
uint32_t GetSize();
......@@ -41,11 +41,11 @@ class Structure : public Node
virtual void Remove(Node* node) = 0;
protected:
protected:
Structure(Node* parent = NULL);
Structure(plist_type type, Node* parent = NULL);
private:
private:
Structure(Structure& s);
Structure& operator=(const Structure& s);
};
......
......@@ -27,17 +27,17 @@
namespace PList
{
class Utils
{
public:
class Utils
{
public:
static Node* FromPlist(plist_t node, Node* parent = NULL);
static Structure* FromXml(const std::string& xml);
static Structure* FromBin(const std::vector<char>& bin);
private:
private:
Utils();
~Utils();
};
};
};
#endif // PLIST__UTILS_H
......@@ -23,7 +23,8 @@
#define LIBPLIST_H
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
#ifdef _MSC_VER
......@@ -37,40 +38,41 @@ extern "C" {
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
#ifdef plist_EXPORTS
#define PLIST_API __declspec( dllexport )
#else
#define PLIST_API __declspec( dllimport )
#endif
#ifdef plist_EXPORTS
#define PLIST_API __declspec( dllexport )
#else
#include <stdint.h>
#define PLIST_API
#define PLIST_API __declspec( dllimport )
#endif
#else
#include <stdint.h>
#define PLIST_API
#endif
#include <sys/types.h>
#include <stdarg.h>
/**
/**
* \mainpage libplist : A library to handle Apple Property Lists
* \defgroup PublicAPI Public libplist API
*/
/*@{*/
/*@{*/
/**
/**
* The basic plist abstract data type.
*/
typedef void *plist_t;
/**
/**
* The plist dictionary iterator.
*/
typedef void *plist_dict_iter;
/**
/**
* The enumeration of plist node types.
*/
typedef enum {
typedef enum
{
PLIST_BOOLEAN, /**< Boolean, scalar type */
PLIST_UINT, /**< Unsigned integer, scalar type */
PLIST_REAL, /**< Real, scalar type */
......@@ -84,13 +86,13 @@ extern "C" {
} plist_type;
/********************************************
/********************************************
* *
* Creation & Destruction *
* *
********************************************/
/**
/**
* Create a new root plist_t type #PLIST_DICT
*
* @return the created plist
......@@ -98,7 +100,7 @@ extern "C" {
*/
PLIST_API plist_t plist_new_dict(void);
/**
/**
* Create a new root plist_t type #PLIST_ARRAY
*
* @return the created plist
......@@ -106,7 +108,7 @@ extern "C" {
*/
PLIST_API plist_t plist_new_array(void);
/**
/**
* Create a new plist_t type #PLIST_STRING
*
* @param val the sting value, encoded in UTF8.
......@@ -115,7 +117,7 @@ extern "C" {
*/
PLIST_API plist_t plist_new_string(const char *val);
/**
/**
* Create a new plist_t type #PLIST_BOOLEAN
*
* @param val the boolean value, 0 is false, other values are true.
......@@ -124,7 +126,7 @@ extern "C" {
*/
PLIST_API plist_t plist_new_bool(uint8_t val);
/**
/**
* Create a new plist_t type #PLIST_UINT
*
* @param val the unsigned integer value
......@@ -133,7 +135,7 @@ extern "C" {
*/
PLIST_API plist_t plist_new_uint(uint64_t val);
/**
/**
* Create a new plist_t type #PLIST_REAL
*
* @param val the real value
......@@ -142,7 +144,7 @@ extern "C" {
*/
PLIST_API plist_t plist_new_real(double val);
/**
/**
* Create a new plist_t type #PLIST_DATA
*
* @param val the binary buffer
......@@ -152,7 +154,7 @@ extern "C" {
*/
PLIST_API plist_t plist_new_data(const char *val, uint64_t length);
/**
/**
* Create a new plist_t type #PLIST_DATE
*
* @param sec the number of seconds since 01/01/2001
......@@ -162,14 +164,14 @@ extern "C" {
*/
PLIST_API plist_t plist_new_date(int32_t sec, int32_t usec);
/**
/**
* Destruct a plist_t node and all its children recursively
*
* @param plist the plist to free
*/
PLIST_API void plist_free(plist_t plist);
/**
/**
* Return a copy of passed node and it's children
*
* @param plist the plist to copy
......@@ -178,13 +180,13 @@ extern "C" {
PLIST_API plist_t plist_copy(plist_t node);
/********************************************
/********************************************
* *
* Array functions *
* *
********************************************/
/**
/**
* Get size of a #PLIST_ARRAY node.
*
* @param node the node of type #PLIST_ARRAY
......@@ -192,7 +194,7 @@ extern "C" {
*/
PLIST_API uint32_t plist_array_get_size(plist_t node);
/**
/**
* Get the nth item in a #PLIST_ARRAY node.
*
* @param node the node of type #PLIST_ARRAY
......@@ -201,7 +203,7 @@ 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
......@@ -209,7 +211,7 @@ extern "C" {
*/
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
*
......@@ -219,7 +221,7 @@ extern "C" {
*/
PLIST_API void plist_array_set_item(plist_t node, plist_t item, uint32_t n);
/**
/**
* Append a new item at the end of a #PLIST_ARRAY node.
*
* @param node the node of type #PLIST_ARRAY
......@@ -227,7 +229,7 @@ extern "C" {
*/
PLIST_API void plist_array_append_item(plist_t node, plist_t item);
/**
/**
* Insert a new item at position n in a #PLIST_ARRAY node.
*
* @param node the node of type #PLIST_ARRAY
......@@ -236,7 +238,7 @@ extern "C" {
*/
PLIST_API void plist_array_insert_item(plist_t node, plist_t item, uint32_t n);
/**
/**
* Remove an existing position in a #PLIST_ARRAY node.
* Removed position will be freed using #plist_free
*
......@@ -245,13 +247,13 @@ extern "C" {
*/
PLIST_API void plist_array_remove_item(plist_t node, uint32_t n);
/********************************************
/********************************************
* *
* Dictionary functions *
* *
********************************************/
/**
/**
* Get size of a #PLIST_DICT node.
*
* @param node the node of type #PLIST_DICT
......@@ -259,7 +261,7 @@ extern "C" {
*/
PLIST_API uint32_t plist_dict_get_size(plist_t node);
/**
/**
* Create iterator of a #PLIST_DICT node.
* The allocated iterator shoult be freed with tandard free function
*
......@@ -268,7 +270,7 @@ extern "C" {
*/
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
......@@ -278,7 +280,7 @@ extern "C" {
*/
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
......@@ -286,7 +288,7 @@ extern "C" {
*/
PLIST_API void plist_dict_get_item_key(plist_t node, char **key);
/**
/**
* Get the nth item in a #PLIST_DICT node.
*
* @param node the node of type #PLIST_DICT
......@@ -295,7 +297,7 @@ extern "C" {
*/
PLIST_API plist_t plist_dict_get_item(plist_t node, const char* key);
/**
/**
* Set item identified by key in a #PLIST_DICT node.
* The previous item at index n will be freed using #plist_free
*
......@@ -305,7 +307,7 @@ extern "C" {
*/
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.
*
* @param node the node of type #PLIST_DICT
......@@ -314,7 +316,7 @@ extern "C" {
*/
PLIST_API void plist_dict_insert_item(plist_t node, const char* key, plist_t item);
/**
/**
* Remove an existing position in a #PLIST_DICT node.
* Removed position will be freed using #plist_free
*
......@@ -324,20 +326,20 @@ extern "C" {
PLIST_API void plist_dict_remove_item(plist_t node, const char* key);
/********************************************
/********************************************
* *
* Getters *
* *
********************************************/
/**
/**
* Get the parent of a node
*
* @param node the parent (NULL if node is root)
*/
PLIST_API plist_t plist_get_parent(plist_t node);
/**
/**
* Get the #plist_type of a node.
*
* @param node the node
......@@ -345,7 +347,7 @@ extern "C" {
*/
PLIST_API plist_type plist_get_node_type(plist_t node);
/**
/**
* Get the value of a #PLIST_KEY node.
* This function does nothing if node is not of type #PLIST_KEY
*
......@@ -355,7 +357,7 @@ extern "C" {
*/
PLIST_API void plist_get_key_val(plist_t node, char **val);
/**
/**
* Get the value of a #PLIST_STRING node.
* This function does nothing if node is not of type #PLIST_STRING
*
......@@ -365,7 +367,7 @@ extern "C" {
*/
PLIST_API void plist_get_string_val(plist_t node, char **val);
/**
/**
* Get the value of a #PLIST_BOOLEAN node.
* This function does nothing if node is not of type #PLIST_BOOLEAN
*
......@@ -374,7 +376,7 @@ extern "C" {
*/
PLIST_API void plist_get_bool_val(plist_t node, uint8_t * val);
/**
/**
* Get the value of a #PLIST_UINT node.
* This function does nothing if node is not of type #PLIST_UINT
*
......@@ -383,7 +385,7 @@ extern "C" {
*/
PLIST_API void plist_get_uint_val(plist_t node, uint64_t * val);
/**
/**
* Get the value of a #PLIST_REAL node.
* This function does nothing if node is not of type #PLIST_REAL
*
......@@ -392,7 +394,7 @@ extern "C" {
*/
PLIST_API void plist_get_real_val(plist_t node, double *val);
/**
/**
* Get the value of a #PLIST_DATA node.
* This function does nothing if node is not of type #PLIST_DATA
*
......@@ -402,7 +404,7 @@ extern "C" {
*/
PLIST_API void plist_get_data_val(plist_t node, char **val, uint64_t * length);
/**
/**
* Get the value of a #PLIST_DATE node.
* This function does nothing if node is not of type #PLIST_DATE
*
......@@ -413,13 +415,13 @@ extern "C" {
PLIST_API void plist_get_date_val(plist_t node, int32_t * sec, int32_t * usec);
/********************************************
/********************************************
* *
* Setters *
* *
********************************************/
/**
/**
* Forces type of node. Changing type of structured nodes is only allowed if node is empty.
* Reset value of node;
* @param node the node
......@@ -427,7 +429,7 @@ extern "C" {
*/
PLIST_API void plist_set_type(plist_t node, plist_type type);
/**
/**
* Set the value of a node.
* Forces type of node to #PLIST_KEY
*
......@@ -436,7 +438,7 @@ extern "C" {
*/
PLIST_API void plist_set_key_val(plist_t node, const char *val);
/**
/**
* Set the value of a node.
* Forces type of node to #PLIST_STRING
*
......@@ -445,7 +447,7 @@ extern "C" {
*/
PLIST_API void plist_set_string_val(plist_t node, const char *val);
/**
/**
* Set the value of a node.
* Forces type of node to #PLIST_BOOLEAN
*
......@@ -454,7 +456,7 @@ extern "C" {
*/
PLIST_API void plist_set_bool_val(plist_t node, uint8_t val);
/**
/**
* Set the value of a node.
* Forces type of node to #PLIST_UINT
*
......@@ -463,7 +465,7 @@ extern "C" {
*/
PLIST_API void plist_set_uint_val(plist_t node, uint64_t val);
/**
/**
* Set the value of a node.
* Forces type of node to #PLIST_REAL
*
......@@ -472,7 +474,7 @@ extern "C" {
*/
PLIST_API void plist_set_real_val(plist_t node, double val);
/**
/**
* Set the value of a node.
* Forces type of node to #PLIST_DATA
*
......@@ -482,7 +484,7 @@ extern "C" {
*/
PLIST_API void plist_set_data_val(plist_t node, const char *val, uint64_t length);
/**
/**
* Set the value of a node.
* Forces type of node to #PLIST_DATE
*
......@@ -493,13 +495,13 @@ extern "C" {
PLIST_API void plist_set_date_val(plist_t node, int32_t sec, int32_t usec);
/********************************************
/********************************************
* *
* Import & Export *
* *
********************************************/
/**
/**
* Export the #plist_t structure to XML format.
*
* @param plist the root node to export
......@@ -509,7 +511,7 @@ extern "C" {
*/
PLIST_API void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length);
/**
/**
* Export the #plist_t structure to binary format.
*
* @param plist the root node to export
......@@ -519,7 +521,7 @@ extern "C" {
*/
PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length);
/**
/**
* Import the #plist_t structure from XML format.
*
* @param plist_xml a pointer to the xml buffer.
......@@ -528,7 +530,7 @@ extern "C" {
*/
PLIST_API void plist_from_xml(const char *plist_xml, uint32_t length, plist_t * plist);
/**
/**
* Import the #plist_t structure from binary format.
*
* @param plist_bin a pointer to the xml buffer.
......@@ -538,13 +540,13 @@ extern "C" {
PLIST_API void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist);
/********************************************
/********************************************
* *
* Utils *
* *
********************************************/
/**
/**
* Get a node from its path. Each path element depends on the associated father node type.
* For Dictionaries, var args are casted to const char*, for arrays, var args are caster to uint32_t
* Search is breath first order.
......@@ -555,7 +557,7 @@ extern "C" {
*/
PLIST_API plist_t plist_access_path(plist_t plist, uint32_t length, ...);
/**
/**
* Variadic version of #plist_access_path.
*
* @param plist the node to access result from.
......@@ -565,7 +567,7 @@ extern "C" {
*/
PLIST_API plist_t plist_access_pathv(plist_t plist, uint32_t length, va_list v);
/**
/**
* Compare two node values
*
* @param node_l left node to compare
......@@ -577,40 +579,40 @@ extern "C" {
//DEPRECATED API BELOW
/*@}*/
/**
/*@}*/
/**
* \defgroup DeprecatedAPI Deprecated libplist API
*/
/*@{*/
/*@{*/
/********************************************
/********************************************
* *
* Tree navigation *
* *
********************************************/
/**
/**
* Get the first child of a node
*
* @param node the first child
*/
PLIST_API plist_t plist_get_first_child(plist_t node);
/**
/**
* Get the next sibling of a node
*
* @param node the next sibling
*/
PLIST_API plist_t plist_get_next_sibling(plist_t node);
/**
/**
* Get the previous sibling of a node
*
* @param node the previous sibling
*/
PLIST_API plist_t plist_get_prev_sibling(plist_t node);
/**
/**
* Get the nth child of a #PLIST_ARRAY node.
*
* @param node the node of type #PLIST_ARRAY
......@@ -619,7 +621,7 @@ extern "C" {
*/
PLIST_API plist_t plist_get_array_nth_el(plist_t node, uint32_t n);
/**
/**
* Get the child of a #PLIST_DICT node from the associated key value.
*
* @param node the node of type #PLIST_DICT
......@@ -629,13 +631,13 @@ extern "C" {
PLIST_API plist_t plist_get_dict_el_from_key(plist_t node, const char *key);
/********************************************
/********************************************
* *
* Setters *
* *
********************************************/
/**
/**
* Add a subnode to a node. The node must be of a structured type
* (ie #PLIST_DICT or #PLIST_ARRAY). This function fails silently
* if subnode already has a father.
......@@ -645,7 +647,7 @@ extern "C" {
*/
PLIST_API void plist_add_sub_node(plist_t node, plist_t subnode);
/**
/**
* Add a subnode of type #PLIST_KEY to a node. The node must be of a structured type
* (ie #PLIST_DICT or #PLIST_ARRAY).
*
......@@ -654,7 +656,7 @@ extern "C" {
*/
PLIST_API void plist_add_sub_key_el(plist_t node, const char *val);
/**
/**
* Add a subnode of type #PLIST_STRING to a node. The node must be of a structured type
* (ie #PLIST_DICT or #PLIST_ARRAY).
*
......@@ -663,7 +665,7 @@ extern "C" {
*/
PLIST_API void plist_add_sub_string_el(plist_t node, const char *val);
/**
/**
* Add a subnode of type #PLIST_BOOLEAN to a node. The node must be of a structured type
* (ie #PLIST_DICT or #PLIST_ARRAY).
*
......@@ -672,7 +674,7 @@ extern "C" {
*/
PLIST_API void plist_add_sub_bool_el(plist_t node, uint8_t val);
/**
/**
* Add a subnode of type #PLIST_UINT to a node. The node must be of a structured type
* (ie #PLIST_DICT or #PLIST_ARRAY).
*
......@@ -681,7 +683,7 @@ extern "C" {
*/
PLIST_API void plist_add_sub_uint_el(plist_t node, uint64_t val);
/**
/**
* Add a subnode of type #PLIST_REAL to a node. The node must be of a structured type
* (ie #PLIST_DICT or #PLIST_ARRAY).
*
......@@ -690,7 +692,7 @@ extern "C" {
*/
PLIST_API void plist_add_sub_real_el(plist_t node, double val);
/**
/**
* Add a subnode of type #PLIST_DATA to a node. The node must be of a structured type
* (ie #PLIST_DICT or #PLIST_ARRAY).
*
......@@ -700,7 +702,7 @@ extern "C" {
*/
PLIST_API void plist_add_sub_data_el(plist_t node, const char *val, uint64_t length);
/**
/**
* Add a subnode of type #PLIST_DATE to a node. The node must be of a structured type
* (ie #PLIST_DICT or #PLIST_ARRAY).
*
......@@ -711,13 +713,13 @@ extern "C" {
PLIST_API void plist_add_sub_date_el(plist_t node, int32_t sec, int32_t usec);
/********************************************
/********************************************
* *
* Utils *
* *
********************************************/
/**
/**
* Find the first encountered #PLIST_KEY node mathing that key.
* Search is breath first order.
*
......@@ -726,7 +728,7 @@ extern "C" {
*/
PLIST_API plist_t plist_find_node_by_key(plist_t plist, const char *value);
/**
/**
* Find the first encountered #PLIST_STRING node mathing that string.
* Search is breath first order.
*
......@@ -735,7 +737,7 @@ extern "C" {
*/
PLIST_API plist_t plist_find_node_by_string(plist_t plist, const char *value);
/*@}*/
/*@}*/
#ifdef __cplusplus
......
......@@ -43,7 +43,8 @@ int main(int argc, char *argv[])
struct stat *filestats = (struct stat *) malloc(sizeof(struct stat));
Options *options = parse_arguments(argc, argv);
if (!options) {
if (!options)
{
print_usage();
free(filestats);
return 0;
......@@ -61,10 +62,13 @@ int main(int argc, char *argv[])
//convert one format to another
if (memcmp(plist_entire, "bplist00", 8) == 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 {
}
else
{
plist_from_xml(plist_entire, filestats->st_size, &root_node);
plist_to_bin(root_node, &plist_out, &size);
}
......@@ -72,8 +76,10 @@ int main(int argc, char *argv[])
free(plist_entire);
free(filestats);
if (plist_out) {
if (options->out_file != NULL) {
if (plist_out)
{
if (options->out_file != NULL)
{
FILE *oplist = fopen(options->out_file, "wb");
if (!oplist)
return 1;
......@@ -85,7 +91,8 @@ int main(int argc, char *argv[])
fwrite(plist_out, size, sizeof(char), stdout);
free(plist_out);
} else
}
else
printf("ERROR\n");
free(options);
......@@ -99,9 +106,12 @@ Options *parse_arguments(int argc, char *argv[])
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) {
for (i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "--infile") || !strcmp(argv[i], "-i"))
{
if ((i + 1) == argc)
{
free(options);
return NULL;
}
......@@ -110,8 +120,10 @@ Options *parse_arguments(int argc, char *argv[])
continue;
}
if (!strcmp(argv[i], "--outfile") || !strcmp(argv[i], "-o")) {
if ((i + 1) == argc) {
if (!strcmp(argv[i], "--outfile") || !strcmp(argv[i], "-o"))
{
if ((i + 1) == argc)
{
free(options);
return NULL;
}
......@@ -120,17 +132,20 @@ Options *parse_arguments(int argc, char *argv[])
continue;
}
if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d") || !strcmp(argv[i], "-v")) {
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")) {
if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h"))
{
free(options);
return NULL;
}
}
if (!options->in_file /*|| !options->out_file */ ) {
if (!options->in_file /*|| !options->out_file */ )
{
free(options);
return NULL;
}
......
......@@ -19,7 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
typedef struct _options {
typedef struct _options
{
char *in_file, *out_file;
uint8_t debug, in_fmt, out_fmt;
} Options;
......
......@@ -37,7 +37,8 @@ Node::Node(plist_type type, Node* parent) : _parent(parent)
{
_node = NULL;
switch(type) {
switch (type)
{
case PLIST_BOOLEAN:
_node = plist_new_bool(0);
break;
......
......@@ -38,7 +38,7 @@ Node* Utils::FromPlist(plist_t node, Node* parent)
if (node)
{
plist_type type = plist_get_node_type(node);
switch(type)
switch (type)
{
case PLIST_DICT:
ret = new Dictionary(node, parent);
......
......@@ -44,7 +44,8 @@
#define BPLIST_TRL_ROOTOBJ_IDX 10
#define BPLIST_TRL_OFFTAB_IDX 18
enum {
enum
{
BPLIST_NULL = 0x00,
BPLIST_FALSE = 0x08,
BPLIST_TRUE = 0x09,
......@@ -68,7 +69,8 @@ static void byte_convert(uint8_t * address, size_t size)
uint8_t i = 0, j = 0;
uint8_t tmp = 0;
for (i = 0; i < (size / 2); i++) {
for (i = 0; i < (size / 2); i++)
{
tmp = address[i];
j = ((size - 1) + 0) - i;
address[i] = address[j];
......@@ -109,7 +111,8 @@ static plist_t parse_uint_node(char *bnode, uint8_t size, char **next_object)
plist_data_t data = plist_new_plist_data();
size = 1 << size; // make length less misleading
switch (size) {
switch (size)
{
case sizeof(uint8_t):
case sizeof(uint16_t):
case sizeof(uint32_t):
......@@ -135,7 +138,8 @@ static plist_t parse_real_node(char *bnode, uint8_t size)
float floatval = 0.0;
size = 1 << size; // make length less misleading
switch (size) {
switch (size)
{
case sizeof(float):
floatval = *(float *) bnode;
byte_convert((uint8_t *) & floatval, sizeof(float));
......@@ -261,10 +265,12 @@ static plist_t parse_bin_node(char *object, uint8_t dict_size, char **next_objec
size = (*object) & 0x0F;
object++;
switch (type) {
switch (type)
{
case BPLIST_NULL:
switch (size) {
switch (size)
{
case BPLIST_TRUE:
{
......@@ -302,7 +308,8 @@ static plist_t parse_bin_node(char *object, uint8_t dict_size, char **next_objec
return parse_date_node(object, size);
case BPLIST_DATA:
if (0x0F == size) {
if (0x0F == size)
{
plist_t size_node = parse_bin_node(object, dict_size, &object);
if (plist_get_node_type(size_node) != PLIST_UINT)
return NULL;
......@@ -312,7 +319,8 @@ static plist_t parse_bin_node(char *object, uint8_t dict_size, char **next_objec
return parse_data_node(object, size);
case BPLIST_STRING:
if (0x0F == size) {
if (0x0F == size)
{
plist_t size_node = parse_bin_node(object, dict_size, &object);
if (plist_get_node_type(size_node) != PLIST_UINT)
return NULL;
......@@ -322,7 +330,8 @@ static plist_t parse_bin_node(char *object, uint8_t dict_size, char **next_objec
return parse_string_node(object, size);
case BPLIST_UNICODE:
if (0x0F == size) {
if (0x0F == size)
{
plist_t size_node = parse_bin_node(object, dict_size, &object);
if (plist_get_node_type(size_node) != PLIST_UINT)
return NULL;
......@@ -333,7 +342,8 @@ static plist_t parse_bin_node(char *object, uint8_t dict_size, char **next_objec
case BPLIST_UID:
case BPLIST_ARRAY:
if (0x0F == size) {
if (0x0F == size)
{
plist_t size_node = parse_bin_node(object, dict_size, &object);
if (plist_get_node_type(size_node) != PLIST_UINT)
return NULL;
......@@ -344,7 +354,8 @@ static plist_t parse_bin_node(char *object, uint8_t dict_size, char **next_objec
case BPLIST_SET:
case BPLIST_DICT:
if (0x0F == size) {
if (0x0F == size)
{
plist_t size_node = parse_bin_node(object, dict_size, &object);
if (plist_get_node_type(size_node) != PLIST_UINT)
return NULL;
......@@ -365,7 +376,8 @@ static gpointer copy_plist_data(gconstpointer src, gpointer data)
dstdata->type = srcdata->type;
dstdata->length = srcdata->length;
switch (dstdata->type) {
switch (dstdata->type)
{
case PLIST_BOOLEAN:
dstdata->boolval = srcdata->boolval;
break;
......@@ -447,7 +459,8 @@ void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist)
//parse serialized nodes
offset_table = (char *) (plist_bin + offset_table_index);
for (i = 0; i < num_objects; i++) {
for (i = 0; i < num_objects; i++)
{
char *obj = NULL;
current_offset = UINT_TO_HOST(offset_table + i * offset_size, offset_size);
......@@ -456,13 +469,16 @@ void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist)
}
//setup children for structured types
for (i = 0; i < num_objects; i++) {
for (i = 0; i < num_objects; i++)
{
plist_data_t data = plist_get_data(nodeslist[i]);
switch (data->type) {
switch (data->type)
{
case PLIST_DICT:
for (j = 0; j < data->length; j++) {
for (j = 0; j < data->length; j++)
{
str_i = j * dict_param_size;
str_j = (j + data->length) * dict_param_size;
......@@ -472,14 +488,16 @@ void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist)
//first one is actually a key
plist_get_data(nodeslist[index1])->type = PLIST_KEY;
if (index1 < num_objects) {
if (index1 < num_objects)
{
if (G_NODE_IS_ROOT(nodeslist[index1]))
g_node_append(nodeslist[i], nodeslist[index1]);
else
g_node_append(nodeslist[i], g_node_copy_deep(nodeslist[index1], copy_plist_data, NULL));
}
if (index2 < num_objects) {
if (index2 < num_objects)
{
if (G_NODE_IS_ROOT(nodeslist[index2]))
g_node_append(nodeslist[i], nodeslist[index2]);
else
......@@ -491,11 +509,13 @@ void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist)
break;
case PLIST_ARRAY:
for (j = 0; j < data->length; j++) {
for (j = 0; j < data->length; j++)
{
str_j = j * dict_param_size;
index1 = UINT_TO_HOST(data->buff + str_j, dict_param_size);
if (index1 < num_objects) {
if (index1 < num_objects)
{
if (G_NODE_IS_ROOT(nodeslist[index1]))
g_node_append(nodeslist[i], nodeslist[index1]);
else
......@@ -523,7 +543,8 @@ static guint plist_data_hash(gconstpointer key)
char *buff = NULL;
guint size = 0;
switch (data->type) {
switch (data->type)
{
case PLIST_BOOLEAN:
case PLIST_UINT:
case PLIST_REAL:
......@@ -559,7 +580,8 @@ static guint plist_data_hash(gconstpointer key)
struct serialize_s {
struct serialize_s
{
GPtrArray *objects;
GHashTable *ref_table;
};
......@@ -572,7 +594,8 @@ static void serialize_plist(GNode * node, gpointer data)
//first check that node is not yet in objects
gpointer val = g_hash_table_lookup(ser->ref_table, node);
if (val) {
if (val)
{
//data is already in table
return;
}
......@@ -617,9 +640,12 @@ static void write_real(GByteArray * bplist, double val)
uint64_t size = get_real_bytes(*((uint64_t *) & val)); //cheat to know used space
uint8_t *buff = (uint8_t *) malloc(sizeof(uint8_t) + size);
buff[0] = BPLIST_REAL | Log2(size);
if (size == sizeof(double)) {
if (size == sizeof(double))
{
memcpy(buff + 1, &val, size);
} else if (size == sizeof(float)) {
}
else if (size == sizeof(float))
{
float tmpval = (float) val;
memcpy(buff + 1, &tmpval, size);
}
......@@ -644,7 +670,8 @@ static void write_raw_data(GByteArray * bplist, uint8_t mark, uint8_t * val, uin
uint8_t *buff = NULL;
uint8_t marker = mark | (size < 15 ? size : 0xf);
g_byte_array_append(bplist, &marker, sizeof(uint8_t));
if (size >= 15) {
if (size >= 15)
{
GByteArray *int_buff = g_byte_array_new();
write_int(int_buff, size);
g_byte_array_append(bplist, int_buff->data, int_buff->len);
......@@ -689,7 +716,8 @@ static void write_array(GByteArray * bplist, GNode * node, GHashTable * ref_tabl
uint64_t size = g_node_n_children(node);
uint8_t marker = BPLIST_ARRAY | (size < 15 ? size : 0xf);
g_byte_array_append(bplist, &marker, sizeof(uint8_t));
if (size >= 15) {
if (size >= 15)
{
GByteArray *int_buff = g_byte_array_new();
write_int(int_buff, size);
g_byte_array_append(bplist, int_buff->data, int_buff->len);
......@@ -698,7 +726,8 @@ static void write_array(GByteArray * bplist, GNode * node, GHashTable * ref_tabl
buff = (uint8_t *) malloc(size * dict_param_size);
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 = *(uint64_t *) (g_hash_table_lookup(ref_table, cur));
memcpy(buff + i * dict_param_size, &idx, dict_param_size);
byte_convert(buff + i * dict_param_size, dict_param_size);
......@@ -722,7 +751,8 @@ static void write_dict(GByteArray * bplist, GNode * node, GHashTable * ref_table
uint64_t size = g_node_n_children(node) / 2;
uint8_t marker = BPLIST_DICT | (size < 15 ? size : 0xf);
g_byte_array_append(bplist, &marker, sizeof(uint8_t));
if (size >= 15) {
if (size >= 15)
{
GByteArray *int_buff = g_byte_array_new();
write_int(int_buff, size);
g_byte_array_append(bplist, int_buff->data, int_buff->len);
......@@ -731,7 +761,8 @@ static void write_dict(GByteArray * bplist, GNode * node, GHashTable * ref_table
buff = (uint8_t *) malloc(size * 2 * dict_param_size);
for (i = 0, cur = node->children; cur && i < size; cur = cur->next->next, i++) {
for (i = 0, cur = node->children; cur && i < size; cur = cur->next->next, i++)
{
idx1 = *(uint64_t *) (g_hash_table_lookup(ref_table, cur));
memcpy(buff + i * dict_param_size, &idx1, dict_param_size);
byte_convert(buff + i * dict_param_size, dict_param_size);
......@@ -801,12 +832,14 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
//write objects and table
offsets = (uint64_t *) malloc(num_objects * sizeof(uint64_t));
for (i = 0; i < num_objects; i++) {
for (i = 0; i < num_objects; i++)
{
plist_data_t data = plist_get_data(g_ptr_array_index(objects, i));
offsets[i] = bplist_buff->len;
switch (data->type) {
switch (data->type)
{
case PLIST_BOOLEAN:
buff = (uint8_t *) malloc(sizeof(uint8_t));
buff[0] = data->boolval ? BPLIST_TRUE : BPLIST_FALSE;
......@@ -826,11 +859,14 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
case PLIST_STRING:
len = strlen(data->strval);
type = xmlDetectCharEncoding(data->strval, len);
if (XML_CHAR_ENCODING_UTF8 == type) {
if (XML_CHAR_ENCODING_UTF8 == type)
{
unicodestr = g_utf8_to_utf16(data->strval, len, &items_read, &items_written, &error);
write_unicode(bplist_buff, unicodestr, items_written);
g_free(unicodestr);
} else if (XML_CHAR_ENCODING_ASCII == type || XML_CHAR_ENCODING_NONE == type) {
}
else if (XML_CHAR_ENCODING_ASCII == type || XML_CHAR_ENCODING_NONE == type)
{
write_string(bplist_buff, data->strval);
}
break;
......@@ -858,7 +894,8 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
//write offsets
offset_size = get_needed_bytes(bplist_buff->len);
offset_table_index = bplist_buff->len;
for (i = 0; i < num_objects; i++) {
for (i = 0; i < num_objects; i++)
{
uint8_t *offsetbuff = (uint8_t *) malloc(offset_size);
memcpy(offsetbuff, offsets + i, offset_size);
byte_convert(offsetbuff, offset_size);
......
......@@ -46,8 +46,10 @@ plist_data_t plist_new_plist_data(void)
static void plist_free_data(plist_data_t data)
{
if (data) {
switch (data->type) {
if (data)
{
switch (data->type)
{
case PLIST_KEY:
case PLIST_STRING:
free(data->strval);
......@@ -154,7 +156,8 @@ plist_t plist_new_date(int32_t sec, int32_t usec)
void plist_free(plist_t plist)
{
if (plist) {
if (plist)
{
plist_free_node(plist, NULL);
g_node_destroy(plist);
}
......@@ -172,8 +175,10 @@ static void plist_copy_node(GNode * node, gpointer parent_node_ptr)
memcpy(newdata, data, sizeof(struct plist_data_s));
node_type = plist_get_node_type(node);
if (node_type == PLIST_DATA || node_type == PLIST_STRING || node_type == PLIST_KEY) {
switch (node_type) {
if (node_type == PLIST_DATA || node_type == PLIST_STRING || node_type == PLIST_KEY)
{
switch (node_type)
{
case PLIST_DATA:
newdata->buff = (uint8_t *) malloc(data->length);
memcpy(newdata->buff, data->buff, data->length);
......@@ -186,10 +191,12 @@ static void plist_copy_node(GNode * node, gpointer parent_node_ptr)
}
newnode = plist_new_node(newdata);
if (*(plist_t*)parent_node_ptr) {
if (*(plist_t*)parent_node_ptr)
{
g_node_append(*(plist_t*)parent_node_ptr, newnode);
}
else {
else
{
*(plist_t*)parent_node_ptr = newnode;
}
......@@ -206,7 +213,8 @@ plist_t plist_copy(plist_t node)
uint32_t plist_array_get_size(plist_t node)
{
uint32_t ret = 0;
if (node && PLIST_ARRAY == plist_get_node_type(node)) {
if (node && PLIST_ARRAY == plist_get_node_type(node))
{
ret = g_node_n_children(node);
}
return ret;
......@@ -215,7 +223,8 @@ uint32_t plist_array_get_size(plist_t node)
plist_t plist_array_get_item(plist_t node, uint32_t n)
{
plist_t ret = NULL;
if (node && PLIST_ARRAY == plist_get_node_type(node)) {
if (node && PLIST_ARRAY == plist_get_node_type(node))
{
ret = (plist_t)g_node_nth_child(node, n);
}
return ret;
......@@ -224,7 +233,8 @@ plist_t plist_array_get_item(plist_t node, uint32_t n)
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)) {
if (PLIST_ARRAY == plist_get_node_type(father))
{
return g_node_child_position(father, node);
}
return 0;
......@@ -232,9 +242,11 @@ uint32_t plist_array_get_item_index(plist_t node)
void plist_array_set_item(plist_t node, plist_t item, uint32_t n)
{
if (node && PLIST_ARRAY == plist_get_node_type(node)) {
if (node && PLIST_ARRAY == plist_get_node_type(node))
{
plist_t old_item = plist_array_get_item(node, n);
if (old_item) {
if (old_item)
{
plist_free_node(old_item, NULL);
old_item = NULL;
plist_copy_node(item, &old_item);
......@@ -245,7 +257,8 @@ void plist_array_set_item(plist_t node, plist_t item, uint32_t n)
void plist_array_append_item(plist_t node, plist_t item)
{
if (node && PLIST_ARRAY == plist_get_node_type(node)) {
if (node && PLIST_ARRAY == plist_get_node_type(node))
{
g_node_append(node, item);
}
return;
......@@ -253,7 +266,8 @@ void plist_array_append_item(plist_t node, plist_t item)
void plist_array_insert_item(plist_t node, plist_t item, uint32_t n)
{
if (node && PLIST_ARRAY == plist_get_node_type(node)) {
if (node && PLIST_ARRAY == plist_get_node_type(node))
{
g_node_insert(node, n, item);
}
return;
......@@ -261,9 +275,11 @@ void plist_array_insert_item(plist_t node, plist_t item, uint32_t n)
void plist_array_remove_item(plist_t node, uint32_t n)
{
if (node && PLIST_ARRAY == plist_get_node_type(node)) {
if (node && PLIST_ARRAY == plist_get_node_type(node))
{
plist_t old_item = plist_array_get_item(node, n);
if (old_item) {
if (old_item)
{
plist_free(old_item);
}
}
......@@ -273,7 +289,8 @@ void plist_array_remove_item(plist_t node, uint32_t n)
uint32_t plist_dict_get_size(plist_t node)
{
uint32_t ret = 0;
if (node && PLIST_DICT == plist_get_node_type(node)) {
if (node && PLIST_DICT == plist_get_node_type(node))
{
ret = g_node_n_children(node) / 2;
}
return ret;
......@@ -281,7 +298,8 @@ uint32_t plist_dict_get_size(plist_t node)
void plist_dict_new_iter(plist_t node, plist_dict_iter *iter)
{
if (iter && *iter == NULL) {
if (iter && *iter == NULL)
{
*iter = malloc(sizeof(uint32_t));
*((uint32_t*)(*iter)) = 0;
}
......@@ -292,20 +310,25 @@ void plist_dict_next_item(plist_t node, plist_dict_iter iter, char **key, plist_
{
uint32_t* iter_int = (uint32_t*) iter;
if (key) {
if (key)
{
*key = NULL;
}
if (val) {
if (val)
{
*val = NULL;
}
if (node && PLIST_DICT == plist_get_node_type(node) && *iter_int < g_node_n_children(node)) {
if (node && PLIST_DICT == plist_get_node_type(node) && *iter_int < g_node_n_children(node))
{
if (key) {
if (key)
{
plist_get_key_val((plist_t)g_node_nth_child(node, *iter_int), key);
}
if (val) {
if (val)
{
*val = (plist_t) g_node_nth_child(node, *iter_int + 1);
}
......@@ -317,7 +340,8 @@ void plist_dict_next_item(plist_t node, plist_dict_iter iter, char **key, plist_
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)) {
if (PLIST_DICT == plist_get_node_type(father))
{
plist_get_key_val( (plist_t) g_node_prev_sibling(node), key);
}
}
......@@ -326,17 +350,20 @@ plist_t plist_dict_get_item(plist_t node, const char* key)
{
plist_t ret = NULL;
if (node && PLIST_DICT == plist_get_node_type(node)) {
if (node && PLIST_DICT == plist_get_node_type(node))
{
plist_t current = NULL;
for (current = (plist_t)g_node_first_child(node);
current;
current = (plist_t)g_node_next_sibling(g_node_next_sibling(current))) {
current = (plist_t)g_node_next_sibling(g_node_next_sibling(current)))
{
plist_data_t data = plist_get_data(current);
assert( PLIST_KEY == plist_get_node_type(current) );
if (data && !strcmp(key, data->strval)) {
if (data && !strcmp(key, data->strval))
{
ret = (plist_t)g_node_next_sibling(current);
break;
}
......@@ -347,9 +374,11 @@ 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)
{
if (node && PLIST_DICT == plist_get_node_type(node)) {
if (node && PLIST_DICT == plist_get_node_type(node))
{
plist_t old_item = plist_dict_get_item(node, key);
if (old_item) {
if (old_item)
{
plist_free_node(old_item, NULL);
old_item = NULL;
plist_copy_node(item, &old_item);
......@@ -360,7 +389,8 @@ void plist_dict_set_item(plist_t node, const char* key, plist_t item)
void plist_dict_insert_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))
{
g_node_append(node, plist_new_key(key));
g_node_append(node, item);
}
......@@ -369,9 +399,11 @@ void plist_dict_insert_item(plist_t node, const char* key, plist_t item)
void plist_dict_remove_item(plist_t node, const char* key)
{
if (node && PLIST_DICT == plist_get_node_type(node)) {
if (node && PLIST_DICT == plist_get_node_type(node))
{
plist_t old_item = plist_dict_get_item(node, key);
if (old_item) {
if (old_item)
{
plist_t key_node = g_node_prev_sibling(old_item);
plist_free(key_node);
plist_free(old_item);
......@@ -383,7 +415,8 @@ void plist_dict_remove_item(plist_t node, const char* key)
static char compare_node_value(plist_type type, plist_data_t data, const void *value, uint64_t length)
{
char res = FALSE;
switch (type) {
switch (type)
{
case PLIST_BOOLEAN:
res = data->boolval == *((char *) value) ? TRUE : FALSE;
break;
......@@ -417,14 +450,17 @@ plist_t plist_access_pathv(plist_t plist, uint32_t length, va_list v)
plist_type type = PLIST_NONE;
uint32_t i = 0;
for (i = 0; i < length && current; i++) {
for (i = 0; i < length && current; i++)
{
type = plist_get_node_type(current);
if (type == PLIST_ARRAY) {
if (type == PLIST_ARRAY)
{
uint32_t index = va_arg(v, uint32_t);
current = plist_array_get_item(current, index);
}
else if (type == PLIST_DICT) {
else if (type == PLIST_DICT)
{
const char* key = va_arg(v, const char*);
current = plist_dict_get_item(current, key);
}
......@@ -455,7 +491,8 @@ static void plist_get_type_and_value(plist_t node, plist_type * type, void *valu
*type = data->type;
*length = data->length;
switch (*type) {
switch (*type)
{
case PLIST_BOOLEAN:
*((char *) value) = data->boolval;
break;
......@@ -492,7 +529,8 @@ plist_t plist_get_parent(plist_t node)
plist_type plist_get_node_type(plist_t node)
{
if (node) {
if (node)
{
plist_data_t data = plist_get_data(node);
if (data)
return data->type;
......@@ -581,7 +619,8 @@ gboolean plist_data_compare(gconstpointer a, gconstpointer b)
if (val_a->type != val_b->type)
return FALSE;
switch (val_a->type) {
switch (val_a->type)
{
case PLIST_BOOLEAN:
case PLIST_UINT:
case PLIST_REAL:
......@@ -632,7 +671,8 @@ static void plist_set_element_val(plist_t node, plist_type type, const void *val
plist_data_t data = plist_get_data(node);
assert(data); // a node should always have data attached
switch (data->type) {
switch (data->type)
{
case PLIST_KEY:
case PLIST_STRING:
free(data->strval);
......@@ -651,7 +691,8 @@ static void plist_set_element_val(plist_t node, plist_type type, const void *val
data->type = type;
data->length = length;
switch (type) {
switch (type)
{
case PLIST_BOOLEAN:
data->boolval = *((char *) value);
break;
......@@ -682,12 +723,14 @@ static void plist_set_element_val(plist_t node, plist_type type, const void *val
void plist_set_type(plist_t node, plist_type type)
{
if ( g_node_n_children(node) == 0 ) {
if ( g_node_n_children(node) == 0 )
{
plist_data_t data = plist_get_data(node);
plist_free_data( data );
data = plist_new_plist_data();
data->type = type;
switch(type){
switch (type)
{
case PLIST_BOOLEAN:
data->length = sizeof(uint8_t);
break;
......@@ -750,9 +793,11 @@ static plist_t plist_add_sub_element(plist_t node, plist_type type, const void *
{
//only structured types can have children
plist_type node_type = plist_get_node_type(node);
if (node_type == PLIST_DICT || node_type == PLIST_ARRAY) {
if (node_type == PLIST_DICT || node_type == PLIST_ARRAY)
{
//only structured types are allowed to have nulll value
if (value || (!value && (type == PLIST_DICT || type == PLIST_ARRAY))) {
if (value || (!value && (type == PLIST_DICT || type == PLIST_ARRAY)))
{
plist_t subnode = NULL;
......@@ -761,7 +806,8 @@ static plist_t plist_add_sub_element(plist_t node, plist_type type, const void *
data->type = type;
data->length = length;
switch (type) {
switch (type)
{
case PLIST_BOOLEAN:
data->boolval = *((char *) value);
break;
......@@ -793,7 +839,8 @@ static plist_t plist_add_sub_element(plist_t node, plist_type type, const void *
if (node)
g_node_append(node, subnode);
return subnode;
} else
}
else
return NULL;
}
return NULL;
......@@ -818,11 +865,13 @@ plist_t plist_get_prev_sibling(plist_t node)
plist_t plist_get_array_nth_el(plist_t node, uint32_t n)
{
plist_t ret = NULL;
if (node && PLIST_ARRAY == plist_get_node_type(node)) {
if (node && PLIST_ARRAY == plist_get_node_type(node))
{
uint32_t i = 0;
plist_t temp = plist_get_first_child(node);
while (i <= n && temp) {
while (i <= n && temp)
{
if (i == n)
ret = temp;
temp = plist_get_next_sibling(temp);
......@@ -835,7 +884,8 @@ plist_t plist_get_array_nth_el(plist_t node, uint32_t n)
plist_t plist_get_dict_el_from_key(plist_t node, const char *key)
{
plist_t ret = NULL;
if (node && PLIST_DICT == plist_get_node_type(node)) {
if (node && PLIST_DICT == plist_get_node_type(node))
{
plist_t key_node = plist_find_node_by_key(node, key);
ret = plist_get_next_sibling(key_node);
......@@ -845,7 +895,8 @@ plist_t plist_get_dict_el_from_key(plist_t node, const char *key)
void plist_add_sub_node(plist_t node, plist_t subnode)
{
if (node && subnode) {
if (node && subnode)
{
plist_type type = plist_get_node_type(node);
if (type == PLIST_DICT || type == PLIST_ARRAY)
g_node_append(node, subnode);
......@@ -895,14 +946,17 @@ static plist_t plist_find_node(plist_t plist, plist_type type, const void *value
if (!plist)
return NULL;
for (current = (plist_t)g_node_first_child(plist); current; current = (plist_t)g_node_next_sibling(current)) {
for (current = (plist_t)g_node_first_child(plist); current; current = (plist_t)g_node_next_sibling(current))
{
plist_data_t data = plist_get_data(current);
if (data->type == type && data->length == length && compare_node_value(type, data, value, length)) {
if (data->type == type && data->length == length && compare_node_value(type, data, value, length))
{
return current;
}
if (data->type == PLIST_DICT || data->type == PLIST_ARRAY) {
if (data->type == PLIST_DICT || data->type == PLIST_ARRAY)
{
plist_t sub = plist_find_node(current, type, value, length);
if (sub)
return sub;
......
......@@ -35,8 +35,10 @@
#endif
struct plist_data_s {
union {
struct plist_data_s
{
union
{
char boolval;
uint64_t intval;
double realval;
......
......@@ -72,7 +72,8 @@ static gchar *format_string(const char *buf, int cols, int depth)
assert(depth >= 0);
// Inserts new lines and tabs at appropriate locations
for (i = 0; i < nlines; i++) {
for (i = 0; i < nlines; i++)
{
new_buf[i * colw] = '\n';
for (j = 0; j < depth; j++)
new_buf[i * colw + 1 + j] = '\t';
......@@ -90,7 +91,8 @@ static gchar *format_string(const char *buf, int cols, int depth)
struct xml_node {
struct xml_node
{
xmlNodePtr xml;
uint32_t depth;
};
......@@ -134,7 +136,8 @@ static void node_to_xml(GNode * node, gpointer xml_struct)
xstruct = (struct xml_node *) xml_struct;
node_data = plist_get_data(node);
switch (node_data->type) {
switch (node_data->type)
{
case PLIST_BOOLEAN:
{
if (node_data->boolval)
......@@ -166,7 +169,8 @@ static void node_to_xml(GNode * node, gpointer xml_struct)
case PLIST_DATA:
tag = XPLIST_DATA;
if (node_data->length) {
if (node_data->length)
{
valtmp = g_base64_encode(node_data->buff, node_data->length);
val = format_string(valtmp, 60, xstruct->depth);
g_free(valtmp);
......@@ -188,7 +192,8 @@ static void node_to_xml(GNode * node, gpointer xml_struct)
break;
}
for (i = 0; i < xstruct->depth; i++) {
for (i = 0; i < xstruct->depth; i++)
{
xmlNodeAddContent(xstruct->xml, BAD_CAST("\t"));
}
child_node = xmlNewChild(xstruct->xml, NULL, tag, BAD_CAST(val));
......@@ -199,14 +204,17 @@ static void node_to_xml(GNode * node, gpointer xml_struct)
if (node_data->type == PLIST_ARRAY || node_data->type == PLIST_DICT)
xmlNodeAddContent(child_node, BAD_CAST("\n"));
if (isStruct) {
if (isStruct)
{
struct xml_node child = { child_node, xstruct->depth + 1 };
g_node_children_foreach(node, G_TRAVERSE_ALL, node_to_xml, &child);
}
//fix indent 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)
{
for (i = 0; i < xstruct->depth; i++) {
for (i = 0; i < xstruct->depth; i++)
{
xmlNodeAddContent(child_node, BAD_CAST("\t"));
}
}
......@@ -227,7 +235,8 @@ static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node)
if (!xml_node)
return;
for (node = xml_node->children; node; node = node->next) {
for (node = xml_node->children; node; node = node->next)
{
while (node && !xmlStrcmp(node->name, XPLIST_TEXT))
node = node->next;
......@@ -241,21 +250,24 @@ static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node)
else
*plist_node = subnode;
if (!xmlStrcmp(node->name, XPLIST_TRUE)) {
if (!xmlStrcmp(node->name, XPLIST_TRUE))
{
data->boolval = TRUE;
data->type = PLIST_BOOLEAN;
data->length = 1;
continue;
}
if (!xmlStrcmp(node->name, XPLIST_FALSE)) {
if (!xmlStrcmp(node->name, XPLIST_FALSE))
{
data->boolval = FALSE;
data->type = PLIST_BOOLEAN;
data->length = 1;
continue;
}
if (!xmlStrcmp(node->name, XPLIST_INT)) {
if (!xmlStrcmp(node->name, XPLIST_INT))
{
xmlChar *strval = xmlNodeGetContent(node);
data->intval = g_ascii_strtoull((char *) strval, NULL, 0);
data->type = PLIST_UINT;
......@@ -264,7 +276,8 @@ static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node)
continue;
}
if (!xmlStrcmp(node->name, XPLIST_REAL)) {
if (!xmlStrcmp(node->name, XPLIST_REAL))
{
xmlChar *strval = xmlNodeGetContent(node);
data->realval = atof((char *) strval);
data->type = PLIST_REAL;
......@@ -273,7 +286,8 @@ static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node)
continue;
}
if (!xmlStrcmp(node->name, XPLIST_DATE)) {
if (!xmlStrcmp(node->name, XPLIST_DATE))
{
xmlChar *strval = xmlNodeGetContent(node);
g_time_val_from_iso8601((char *) strval, &data->timeval);
data->type = PLIST_DATE;
......@@ -282,12 +296,14 @@ static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node)
continue;
}
if (!xmlStrcmp(node->name, XPLIST_STRING)) {
if (!xmlStrcmp(node->name, XPLIST_STRING))
{
xmlChar *strval = xmlNodeGetContent(node);
len = strlen((char *) strval);
type = xmlDetectCharEncoding(strval, len);
if (XML_CHAR_ENCODING_UTF8 == type || XML_CHAR_ENCODING_ASCII == type || XML_CHAR_ENCODING_NONE == type) {
if (XML_CHAR_ENCODING_UTF8 == type || XML_CHAR_ENCODING_ASCII == type || XML_CHAR_ENCODING_NONE == type)
{
data->strval = strdup((char *) strval);
data->type = PLIST_STRING;
data->length = strlen(data->strval);
......@@ -296,7 +312,8 @@ static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node)
continue;
}
if (!xmlStrcmp(node->name, XPLIST_KEY)) {
if (!xmlStrcmp(node->name, XPLIST_KEY))
{
xmlChar *strval = xmlNodeGetContent(node);
data->strval = strdup((char *) strval);
data->type = PLIST_KEY;
......@@ -305,7 +322,8 @@ static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node)
continue;
}
if (!xmlStrcmp(node->name, XPLIST_DATA)) {
if (!xmlStrcmp(node->name, XPLIST_DATA))
{
xmlChar *strval = xmlNodeGetContent(node);
gsize size = 0;
guchar *dec = g_base64_decode((char *) strval, &size);
......@@ -318,13 +336,15 @@ static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node)
continue;
}
if (!xmlStrcmp(node->name, XPLIST_ARRAY)) {
if (!xmlStrcmp(node->name, XPLIST_ARRAY))
{
data->type = PLIST_ARRAY;
xml_to_node(node, &subnode);
continue;
}
if (!xmlStrcmp(node->name, XPLIST_DICT)) {
if (!xmlStrcmp(node->name, XPLIST_DICT))
{
data->type = PLIST_DICT;
xml_to_node(node, &subnode);
continue;
......
......@@ -46,7 +46,8 @@ char compare_plist(plist_t node_l, plist_t node_r)
if ( !cur_l && !cur_r )
return plist_compare_node_value( node_l, node_r );
while(cur_l && cur_r && res) {
while (cur_l && cur_r && res)
{
if (!(res = compare_plist(cur_l, cur_r)))
return res;
......@@ -77,7 +78,8 @@ int main(int argc, char *argv[])
struct stat *filestats1 = (struct stat *) malloc(sizeof(struct stat));
struct stat *filestats2 = (struct stat *) malloc(sizeof(struct stat));
if (argc!= 3) {
if (argc!= 3)
{
printf("Wrong input\n");
return 1;
}
......@@ -89,7 +91,8 @@ int main(int argc, char *argv[])
iplist1 = fopen(file_in1, "rb");
iplist2 = fopen(file_in2, "rb");
if (!iplist1 || !iplist2) {
if (!iplist1 || !iplist2)
{
printf("File does not exists\n");
return 2;
}
......@@ -119,7 +122,8 @@ int main(int argc, char *argv[])
else
plist_from_xml(plist_2, size_in2, &root_node2);
if (!root_node1 || !root_node2) {
if (!root_node1 || !root_node2)
{
printf("PList parsing failed\n");
return 3;
}
......
......@@ -46,7 +46,8 @@ int main(int argc, char *argv[])
int size_out2 = 0;
char *file_in = NULL;
struct stat *filestats = (struct stat *) malloc(sizeof(struct stat));
if (argc!= 2) {
if (argc!= 2)
{
printf("Wrong input\n");
return 1;
}
......@@ -55,7 +56,8 @@ int main(int argc, char *argv[])
//read input file
iplist = fopen(file_in, "rb");
if (!iplist) {
if (!iplist)
{
printf("File does not exists\n");
return 2;
}
......@@ -69,7 +71,8 @@ int main(int argc, char *argv[])
//convert one format to another
plist_from_xml(plist_xml, size_in, &root_node1);
if (!root_node1) {
if (!root_node1)
{
printf("PList XML parsing failed\n");
return 3;
}
......@@ -77,7 +80,8 @@ int main(int argc, char *argv[])
printf("PList XML parsing succeeded\n");
plist_to_bin(root_node1, &plist_bin, &size_out);
if (!plist_bin) {
if (!plist_bin)
{
printf("PList BIN writing failed\n");
return 4;
}
......@@ -85,7 +89,8 @@ int main(int argc, char *argv[])
printf("PList BIN writing succeeded\n");
plist_from_bin(plist_bin, size_out, &root_node2);
if (!root_node2) {
if (!root_node2)
{
printf("PList BIN parsing failed\n");
return 5;
}
......@@ -93,14 +98,16 @@ int main(int argc, char *argv[])
printf("PList BIN parsing succeeded\n");
plist_to_xml(root_node2, &plist_xml2, &size_out2);
if (!plist_xml2) {
if (!plist_xml2)
{
printf("PList XML writing failed\n");
return 8;
}
else
printf("PList XML writing succeeded\n");
if (plist_xml2) {
if (plist_xml2)
{
FILE *oplist = NULL;
char file_out[512];
sprintf(file_out, "%s.out", file_in);
......@@ -116,7 +123,8 @@ int main(int argc, char *argv[])
free(plist_xml2);
free(filestats);
if (size_in != size_out2) {
if (size_in != size_out2)
{
printf("Size of input and output is different\n");
printf("Input size : %i\n", size_in);
printf("Output size : %i\n", size_out2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment