Property list tools

Property list tools — Tools for manipulating property lists

Stability Level

Unstable, unless otherwise indicated

Functions

Types and Values

Object Hierarchy

    GBoxed
    ╰── PlistObject

Includes

#include <osxcart/plist.h>

Description

Property lists are used in Mac OS X, NeXTSTEP, and GNUstep to store serialized objects. Mac OS X uses an XML format to store property lists in files with the extension .plist. This module reads and writes property lists in the XML format. For more information on the format, see the Apple developer documentation. Instead of deserializing the property list into Core Foundation types as in Mac OS X, the property list is represented using a hierarchical structure of PlistObjects, lightweight objects that can contain any type of data.

Each property list object type has a corresponding PlistObject structure. For completeness, the data types are listed here:

XML Element Core Foundation data type PlistObject struct
true, false CFBoolean PlistObjectBoolean
integer CFNumber PlistObjectInteger
real CFNumber PlistObjectReal
string CFString PlistObjectString
date CFDate PlistObjectDate
data CFData PlistObjectData
array CFArray PlistObjectArray
dict CFDictionary PlistObjectDict

Functions

plist_error_quark ()

GQuark
plist_error_quark (void);

The error domain for property list errors.

Returns

The string plist-error-quark as a

GQuark.

[transfer none]


plist_object_new ()

PlistObject *
plist_object_new (const PlistObjectType type);

Allocates a PlistObject, with its value initialized to zero in whatever way is appropriate for type .

Parameters

type

The type of PlistObject to create.

 

Returns

a newly-allocated PlistObject.

[transfer full]


plist_object_copy ()

PlistObject *
plist_object_copy (PlistObject *object);

Makes a copy of a PlistObject.

Parameters

object

The PlistObject to copy.

 

Returns

a newly-allocated PlistObject.

[transfer full]

Since 1.1


plist_object_free ()

void
plist_object_free (PlistObject *object);

Deallocates a PlistObject. If object is a container type, also deallocates all of the PlistObjects inside it.

Parameters

object

The PlistObject to free.

 

plist_object_get_boolean ()

gboolean
plist_object_get_boolean (PlistObject *object);

This function is intended for bindings to other programming languages; in C, you can simply use object->boolean.val.

Parameters

object

a PlistObject holding a boolean

 

Returns

the boolean value held by object .

Since 1.1


plist_object_get_real ()

double
plist_object_get_real (PlistObject *object);

This function is intended for bindings to other programming languages; in C, you can simply use object->real.val.

Parameters

object

a PlistObject holding a real value

 

Returns

the real value held by object .

Since 1.1


plist_object_get_integer ()

int
plist_object_get_integer (PlistObject *object);

This function is intended for bindings to other programming languages; in C, you can simply use object->integer.val.

Parameters

object

a PlistObject holding an integer

 

Returns

the integer value held by object .

Since 1.1


plist_object_get_string ()

const char *
plist_object_get_string (PlistObject *object);

This function is intended for bindings to other programming languages; in C, you can simply use object->string.val.

Parameters

object

a PlistObject holding a string

 

Returns

the string value held by object .

[transfer none]

Since 1.1


plist_object_get_date ()

const GTimeVal
plist_object_get_date (PlistObject *object);

This function is intended for bindings to other programming languages; in C, you can simply use object->date.val.

Parameters

object

a PlistObject holding a date

 

Returns

the date value held by object as a GTimeVal.

[transfer none]

Since 1.1


plist_object_get_array ()

GList *
plist_object_get_array (PlistObject *object);

This function is intended for bindings to other programming languages; in C, you can simply use object->array.val.

Parameters

object

a PlistObject holding an array

 

Returns

the GList held by object .

[transfer none][element-type PlistObject]

Since 1.1


plist_object_get_dict ()

GHashTable *
plist_object_get_dict (PlistObject *object);

This function is intended for bindings to other programming languages; in C, you can simply use object->dict.val.

Parameters

object

a PlistObject holding a dictionary

 

Returns

the GHashTable held by object .

[transfer none][element-type char* PlistObject]

Since 1.1


plist_object_get_data ()

unsigned char *
plist_object_get_data (PlistObject *object,
                       size_t *length);

This function is intended for bindings to other programming languages; in C, you can simply use object->data.val and

object->data.length.

Parameters

object

a PlistObject holding binary data

 

length

return location for the length of the data.

[out]

Returns

a pointer to the data held by object .

[transfer none][array length=length]

Since 1.1


plist_object_set_boolean ()

void
plist_object_set_boolean (PlistObject *object,
                          gboolean val);

This function is intended for bindings to other programming languages; in C, you can simply use object->boolean.val.

Parameters

object

a PlistObject holding a boolean

 

val

a new boolean value

 

Since 1.1


plist_object_set_real ()

void
plist_object_set_real (PlistObject *object,
                       double val);

This function is intended for bindings to other programming languages; in C, you can simply use object->real.val.

Parameters

object

a PlistObject holding a real value

 

val

a new real value

 

Since 1.1


plist_object_set_integer ()

void
plist_object_set_integer (PlistObject *object,
                          int val);

This function is intended for bindings to other programming languages; in C, you can simply use object->integer.val.

Parameters

object

a PlistObject holding an integer

 

val

a new integer value

 

Since 1.1


plist_object_set_string ()

void
plist_object_set_string (PlistObject *object,
                         const char *val);

This function is intended for bindings to other programming languages; in C, you can simply use object->string.val.

Parameters

object

a PlistObject holding a string

 

val

a new string value

 

Since 1.1


plist_object_set_date ()

void
plist_object_set_date (PlistObject *object,
                       GTimeVal val);

This function is intended for bindings to other programming languages; in C, you can simply use object->date.val.

Parameters

object

a PlistObject holding a date value

 

val

a new date value

 

Since 1.1


plist_object_set_array ()

void
plist_object_set_array (PlistObject *object,
                        GList *val);

This function is intended for bindings to other programming languages; in C, you can simply use object->array.val.

Parameters

object

a PlistObject holding an array

 

val

a new array.

[transfer none][element-type PlistObject]

Since 1.1


plist_object_set_dict ()

void
plist_object_set_dict (PlistObject *object,
                       GHashTable *val);

This function is intended for bindings to other programming languages; in C, you can simply use object->dict.val.

Parameters

object

a PlistObject holding a dictionary

 

val

a new dictionary.

[transfer none][element-type char* PlistObject]

Since 1.1


plist_object_set_data ()

void
plist_object_set_data (PlistObject *object,
                       unsigned char *val,
                       size_t length);

This function is intended for bindings to other programming languages; in C, you can simply use object->data.val and

object->data.length.

Parameters

object

a PlistObject holding binary data

 

val

new binary data.

[transfer none][array length=length]

length

length of val

 

Since 1.1


plist_object_lookup ()

PlistObject *
plist_object_lookup (PlistObject *tree,
                     ...);

Convenience function for looking up an object that exists at a certain path within the plist. The variable argument list can consist of either strings (dictionary keys, if the object at that point in the path is a dict) or integers (array indices, if the object at that point in the path is an array.)

The variable argument list must be terminated by -1.

For example, given the following plist:

<dict> 
  <key>Array</key> 
  <array> 
    <integer>1</integer>
    <string>2</string>
    <real>3.0</real> 
  </array> 
  <key>Dict</key>
  <dict>
    <key>Integer</key>
    <integer>1</integer>
    <key>Real</key>
    <real>2.0</real>
    <key>String</key>
    <string>3</string>
  </dict>
</plist>]| 
then the following code: 
|[PlistObject *obj1 = plist_object_lookup(plist, "Array", 0, -1); 
PlistObject *obj2 = plist_object_lookup(plist, "Dict", "Integer", -1);]| 
will place in @obj1 and @obj2 two identical #PlistObjects containing
the integer 1, although they will both point to two different spots in the
@plist tree.

Parameters

tree

The root object of the plist

 

...

A path consisting of dictionary keys and array indices, terminated by -1

 

Returns

The requested PlistObject, or NULL if the path did not exist. The returned object is a pointer to the object within the original tree , and is not copied. Therefore, it should not be freed separately from tree .

[transfer none]

Since 1.1


plist_read ()

PlistObject *
plist_read (const gchar *filename,
            GError **error);

Reads a property list in XML format from filename and returns a PlistObject representing the property list.

Parameters

filename

The path to a file containing a property list in XML format.

 

error

Return location for an error, or NULL.

 

Returns

the property list, or NULL if an error occurred, in which case error is set. The property list must be freed with plist_object_free() after use.


plist_read_file ()

PlistObject *
plist_read_file (GFile *file,
                 GCancellable *cancellable,
                 GError **error);

Reads a property list in XML format from file and returns a PlistObject representing the property list. The operation will be cancelled if cancellable is triggered from another thread.

Parameters

file

A GFile containing a property list in XML format.

 

cancellable

An optional GCancellable object, or NULL.

[allow-none]

error

Return location for an error, or NULL.

 

Returns

the property list, or NULL if an error occurred, in which case error is set. The property list must be freed with plist_object_free() after use.


plist_read_from_string ()

PlistObject *
plist_read_from_string (const gchar *string,
                        GError **error);

Reads a property list in XML format from string and returns a PlistObject representing the property list.

Parameters

string

A string containing a property list in XML format.

 

error

Return location for an error, or NULL.

 

Returns

the property list, or NULL if an error occurred, in which case error is set. The property list must be freed with plist_object_free() after use.


plist_write ()

gboolean
plist_write (PlistObject *plist,
             const gchar *filename,
             GError **error);

Writes the property list plist to a file in XML format. If filename exists, it will be overwritten.

Parameters

plist

A property list object.

 

filename

The filename to write to.

 

error

Return location for an error, or NULL.

 

Returns

TRUE if the operation succeeded, FALSE if not, in which case error is set.


plist_write_file ()

gboolean
plist_write_file (PlistObject *plist,
                  GFile *file,
                  GCancellable *cancellable,
                  GError **error);

Writes the property list plist to a file in XML format. If file exists, it will be overwritten. The operation will be cancelled if cancellable is triggered from another thread.

Parameters

plist

A property list object.

 

file

A GFile to write to.

 

cancellable

optional GCancellable object, or NULL.

[allow-none]

error

Return location for an error, or NULL.

 

Returns

TRUE if the operation succeeded, FALSE if not, in which case error is set.


plist_write_to_string ()

gchar *
plist_write_to_string (PlistObject *plist);

Writes the property list plist to a string in XML format.

Parameters

plist

A property list object.

 

Returns

a newly-allocated string containing an XML property list. The string must be freed with g_free() when you are done with it.

Types and Values

enum PlistObjectType

The type of value stored in a PlistObject.

Members

PLIST_OBJECT_BOOLEAN

A PlistObjectBoolean.

 

PLIST_OBJECT_REAL

A PlistObjectReal.

 

PLIST_OBJECT_INTEGER

A PlistObjectInteger.

 

PLIST_OBJECT_STRING

A PlistObjectString.

 

PLIST_OBJECT_DATE

A PlistObjectDate.

 

PLIST_OBJECT_ARRAY

A PlistObjectArray.

 

PLIST_OBJECT_DICT

A PlistObjectDict.

 

PLIST_OBJECT_DATA

A PlistObjectData.

 

PlistObjectBoolean

typedef struct {
	PlistObjectType type;
	gboolean val;
} PlistObjectBoolean;

A PlistObject which contains a boolean, similar to CFBoolean.

Members

PlistObjectType type;

Must be PLIST_OBJECT_BOOLEAN

 

gboolean val;

The value

 

PlistObjectReal

typedef struct {
	PlistObjectType type;
	gdouble val;
} PlistObjectReal;

A PlistObject which contains a double-precision floating point number.

CFNumber is used to represent these in CoreFoundation.

Members

PlistObjectType type;

Must be PLIST_OBJECT_REAL

 

gdouble val;

The value

 

PlistObjectInteger

typedef struct {
	PlistObjectType type;
	gint val;
} PlistObjectInteger;

A PlistObject which contains an integer. CFNumber is used to represent these in CoreFoundation.

Members

PlistObjectType type;

Must be PLIST_OBJECT_INTEGER

 

gint val;

The value

 

PlistObjectString

typedef struct {
	PlistObjectType type;
	gchar *val;
} PlistObjectString;

A PlistObject which contains a string, similar to CFString.

Members

PlistObjectType type;

Must be PLIST_OBJECT_STRING

 

gchar *val;

The string

 

PlistObjectDate

typedef struct {
	PlistObjectType type;
	GTimeVal val;
} PlistObjectDate;

A PlistObject which contains a date in GLib's timeval format, similar to

CFDate.

Members

PlistObjectType type;

Must be PLIST_OBJECT_DATE

 

GTimeVal val;

The date

 

PlistObjectArray

typedef struct {
	PlistObjectType type;
	GList *val;
} PlistObjectArray;

A PlistObject which contains any number of child PlistObjects, similar to CFArray.

Members

PlistObjectType type;

Must be PLIST_OBJECT_ARRAY

 

GList *val;

A list of PlistObjects

 

PlistObjectDict

typedef struct {
	PlistObjectType type;
	GHashTable *val;
} PlistObjectDict;

A PlistObject which contains a dictionary of child PlistObjects accessed by string keys, similar to CFDictionary.

Members

PlistObjectType type;

Must be PLIST_OBJECT_DICT

 

GHashTable *val;

A hash table of PlistObjects

 

PlistObjectData

typedef struct {
	PlistObjectType type;
	guchar *val;
	gsize length;
} PlistObjectData;

A PlistObject which contains arbitary binary data, similar to

CFData.

Members

PlistObjectType type;

Must be PLIST_OBJECT_DATA

 

guchar *val;

The data

 

gsize length;

The length of the data

 

PlistObject

The PlistObject type is a union of all the types that can be stored in a property list. It is similar to a NSValue or

CFValue, or an extremely lightweight GValue. In

this library, PlistObjects provide a lightweight interface for storing and manipulating property lists so that the library doesn't have to depend on CoreFoundation.

Similar to GdkEvent, the type field is always the first member of the structure, so that the type of value can always be determined.

Here is an example:

if(obj->type == PLIST_OBJECT_ARRAY)
    g_list_foreach(obj->array.val, some_function, NULL);]|

Members

PlistObjectType type;

The type of value stored in this object.

 

PlistObjectBoolean boolean;

The object as a PlistObjectBoolean.

 

PlistObjectReal real;

The object as a PlistObjectReal.

 

PlistObjectInteger integer;

The object as a PlistObjectInteger.

 

PlistObjectString string;

The object as a PlistObjectString.

 

PlistObjectDate date;

The object as a PlistObjectDate.

 

PlistObjectArray array;

The object as a PlistObjectArray.

 

PlistObjectDict dict;

The object as a PlistObjectDict.

 

PlistObjectData data;

The object as a PlistObjectData.

 

enum PlistError

The different error codes which can be thrown in the PLIST_ERROR domain.

Members

PLIST_ERROR_FAILED

A generic error.

 

PLIST_ERROR_BAD_VERSION

The plist was an incompatible version.

 

PLIST_ERROR_UNEXPECTED_OBJECT

An object was out of place in the plist.

 

PLIST_ERROR_EXTRANEOUS_KEY

A <key> element was encountered outside a <dict> object.

 

PLIST_ERROR_MISSING_KEY

A <dict> object was missing a

<key> element.
 

PLIST_ERROR_BAD_DATE

A <date> object contained incorrect formatting.

 

PLIST_ERROR_NO_ELEMENTS

The plist was empty.

 

PLIST_ERROR

#define PLIST_ERROR plist_error_quark()

The domain of errors raised by property list processing in Osxcart.