Fork me on GitHub
Data Structures | Typedefs | Enumerations | Functions
config.h File Reference

Configuration files parsing (headers) More...

#include <glib.h>
Include dependency graph for config.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  janus_config_container
 Generic configuration container (can be an item, a category or an array) More...
 
struct  janus_config
 Configuration container. More...
 

Typedefs

typedef enum janus_config_type janus_config_type
 Configuration element type. More...
 
typedef struct janus_config_container janus_config_container
 Generic configuration container (can be an item, a category or an array) More...
 
typedef struct janus_config_container janus_config_item
 Configuration item (defined for backwards compatibility) More...
 
typedef struct janus_config_container janus_config_category
 Configuration category (defined for backwards compatibility) More...
 
typedef struct janus_config_container janus_config_array
 Configuration array. More...
 
typedef struct janus_config janus_config
 Configuration container. More...
 

Enumerations

enum  janus_config_type { janus_config_type_any = 1, janus_config_type_item, janus_config_type_category, janus_config_type_array }
 Configuration element type. More...
 

Functions

janus_configjanus_config_parse (const char *config_file)
 Method to parse an INI configuration file. More...
 
janus_configjanus_config_create (const char *name)
 Method to create a new, empty, configuration. More...
 
void janus_config_print (janus_config *config)
 Helper method to print a configuration on the standard output. More...
 
void janus_config_print_as (janus_config *config, int level)
 Helper method to print a configuration on the standard output using a different logging level than LOG_VERB. More...
 
int janus_config_save (janus_config *config, const char *folder, const char *filename)
 Helper method to save a configuration to a file. More...
 
void janus_config_destroy (janus_config *config)
 Destroy a configuration container instance. More...
 
janus_config_itemjanus_config_item_create (const char *name, const char *value)
 Method to create a new janus_config_item instance from name and value. More...
 
janus_config_categoryjanus_config_category_create (const char *name)
 Method to create a new janus_config_category instance. More...
 
janus_config_arrayjanus_config_array_create (const char *name)
 Method to create a new janus_config_array instance. More...
 
void janus_config_container_destroy (janus_config_container *container)
 Helper method to quickly destroy an item, category or array. More...
 
janus_config_containerjanus_config_get (janus_config *config, janus_config_container *parent, janus_config_type type, const char *name)
 Helper method to quickly get an item, category, or array. More...
 
janus_config_containerjanus_config_get_create (janus_config *config, janus_config_container *parent, janus_config_type type, const char *name)
 Same as janus_config_get, but creates the element if it doesn't exist. More...
 
janus_config_containerjanus_config_search (janus_config *config,...)
 Helper method to quickly lookup an item, category, or array. More...
 
int janus_config_add (janus_config *config, janus_config_container *parent, janus_config_container *item)
 Add an item/category/array instance to a category or array. More...
 
int janus_config_remove (janus_config *config, janus_config_container *parent, const char *name)
 Remove an existing item with the specific name from a category/array. More...
 
GList * janus_config_get_items (janus_config *config, janus_config_container *parent)
 Helper method to return the list of plain items, either in root or from a parent. More...
 
GList * janus_config_get_categories (janus_config *config, janus_config_container *parent)
 Helper method to return the list of categories, either in root or from a parent. More...
 
GList * janus_config_get_arrays (janus_config *config, janus_config_container *parent)
 Helper method to return the list of arrays, either in root or from a parent. More...
 

Detailed Description

Configuration files parsing (headers)

Author
Lorenzo Miniero loren.nosp@m.zo@m.nosp@m.eetec.nosp@m.ho.c.nosp@m.om

Implementation of a parser of INI and libconfig configuration files.

Core

Typedef Documentation

typedef struct janus_config janus_config

Configuration container.

Configuration array.

Configuration category (defined for backwards compatibility)

Generic configuration container (can be an item, a category or an array)

Configuration item (defined for backwards compatibility)

Configuration element type.

Enumeration Type Documentation

Configuration element type.

Enumerator
janus_config_type_any 

Anything (just for searches)

janus_config_type_item 

Plain item.

janus_config_type_category 

Category.

janus_config_type_array 

Array.

Function Documentation

int janus_config_add ( janus_config config,
janus_config_container parent,
janus_config_container item 
)

Add an item/category/array instance to a category or array.

Note
If adding to a category and the item/category/array already exists, it is replaced; it is appended if the target is an array instead, where duplicates are accepted.
Parameters
[in]configThe configuration instance
[in]parentThe category or array to add the item to, if any
[in]itemThe item/category/array to add
Returns
0 if successful, a negative integer otherwise
janus_config_array* janus_config_array_create ( const char *  name)

Method to create a new janus_config_array instance.

Parameters
[in]nameName to give to the array
Returns
A valid janus_config_array instance if successful, NULL otherwise
janus_config_category* janus_config_category_create ( const char *  name)

Method to create a new janus_config_category instance.

Parameters
[in]nameName to give to the category
Returns
A pointer to a valid janus_config_category instance if successful, NULL otherwise
void janus_config_container_destroy ( janus_config_container container)

Helper method to quickly destroy an item, category or array.

Note
This method also destroys anything it contains, if it's a category or array, but will not unlink the object from its parent: this is up to the caller
Parameters
[in]containerThe item/category/array to destroy
janus_config* janus_config_create ( const char *  name)

Method to create a new, empty, configuration.

Parameters
[in]nameName to give to the configuration
Returns
A pointer to a valid janus_config instance if successful, NULL otherwise
void janus_config_destroy ( janus_config config)

Destroy a configuration container instance.

Parameters
[in]configThe configuration to destroy
janus_config_container* janus_config_get ( janus_config config,
janus_config_container parent,
janus_config_type  type,
const char *  name 
)

Helper method to quickly get an item, category, or array.

Note
If the parent container is NULL, the lookup is done at the root. If something is found but type doesn't match (name is an array but we're looking for a category), NULL is returned.
Parameters
[in]configThe configuration instance
[in]parentThe parent container (category or array), if any
[in]typeThe type of container to look for
[in]nameThe name of the item/category/array to look for
Returns
A pointer to a valid janus_config_container instance if successful, NULL otherwise
GList* janus_config_get_arrays ( janus_config config,
janus_config_container parent 
)

Helper method to return the list of arrays, either in root or from a parent.

Note
The method returns a new GList: it's up to the caller to free it. The values of the list data must NOT be freed, though, as it's just linked from the configuration.
Parameters
[in]configThe configuration instance
[in]parentThe parent container (category or array), if any
Returns
A pointer to the categories GLib linked list of arrays if successful, NULL otherwise
GList* janus_config_get_categories ( janus_config config,
janus_config_container parent 
)

Helper method to return the list of categories, either in root or from a parent.

Note
The method returns a new GList: it's up to the caller to free it. The values of the list data must NOT be freed, though, as it's just linked from the configuration.
Parameters
[in]configThe configuration instance
[in]parentThe parent container (category or array), if any
Returns
A pointer to the categories GLib linked list of categories if successful, NULL otherwise
janus_config_container* janus_config_get_create ( janus_config config,
janus_config_container parent,
janus_config_type  type,
const char *  name 
)

Same as janus_config_get, but creates the element if it doesn't exist.

Note
Nothing is created if type is janus_config_type_any.
Parameters
[in]configThe configuration instance
[in]parentThe parent container (category or array), if any
[in]typeThe type of container to look for
[in]nameThe name of the item/category/array to look for
Returns
A pointer to a valid janus_config_container instance if successful, NULL otherwise
GList* janus_config_get_items ( janus_config config,
janus_config_container parent 
)

Helper method to return the list of plain items, either in root or from a parent.

Note
The method returns a new GList: it's up to the caller to free it. The values of the list data must NOT be freed, though, as it's just linked from the configuration.
Parameters
[in]configThe configuration instance
[in]parentThe parent container (category or array), if any
Returns
A pointer to the categories GLib linked list of items if successful, NULL otherwise
janus_config_item* janus_config_item_create ( const char *  name,
const char *  value 
)

Method to create a new janus_config_item instance from name and value.

Parameters
[in]nameName to give to the item
[in]valueValue of the item (optional)
Returns
A valid janus_config_item instance if successful, NULL otherwise
janus_config* janus_config_parse ( const char *  config_file)

Method to parse an INI configuration file.

Parameters
[in]config_filePath to the configuration file
Returns
A pointer to a valid janus_config instance if successful, NULL otherwise
void janus_config_print ( janus_config config)

Helper method to print a configuration on the standard output.

Note
This prints with LOG_VERB: if you need the configuration to be visible at a different debugging level, use janus_config_print_as instead
Parameters
[in]configThe configuration to print
void janus_config_print_as ( janus_config config,
int  level 
)

Helper method to print a configuration on the standard output using a different logging level than LOG_VERB.

Parameters
[in]configThe configuration to print
[in]levelThe debugging level to use
int janus_config_remove ( janus_config config,
janus_config_container parent,
const char *  name 
)

Remove an existing item with the specific name from a category/array.

Parameters
[in]configThe configuration instance
[in]parentThe category/array to remove the item from, if any
[in]nameThe name of the item/category/array to remove
Returns
0 if successful, a negative integer otherwise
int janus_config_save ( janus_config config,
const char *  folder,
const char *  filename 
)

Helper method to save a configuration to a file.

Parameters
[in]configThe configuration to sav
[in]folderThe folder the file should be saved to
[in]filenameThe file name, extension included (should be .cfg)
Returns
0 if successful, a negative integer otherwise
janus_config_container* janus_config_search ( janus_config config,
  ... 
)

Helper method to quickly lookup an item, category, or array.

Note
If something is found but type doesn't match (name is an array but we're looking for a category), NULL is returned.
Parameters
[in]configThe configuration instance
Returns
A pointer to a valid janus_config_container instance if successful, NULL otherwise