Fork me on GitHub
Loading...
Searching...
No Matches
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.
 
typedef struct janus_config_container janus_config_container
 Generic configuration container (can be an item, a category or an array)
 
typedef struct janus_config_container janus_config_item
 Configuration item (defined for backwards compatibility)
 
typedef struct janus_config_container janus_config_category
 Configuration category (defined for backwards compatibility)
 
typedef struct janus_config_container janus_config_array
 Configuration array.
 
typedef struct janus_config janus_config
 Configuration container.
 

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.
 
janus_configjanus_config_create (const char *name)
 Method to create a new, empty, configuration.
 
void janus_config_print (janus_config *config)
 Helper method to print a configuration on the standard output.
 
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.
 
int janus_config_save (janus_config *config, const char *folder, const char *filename)
 Helper method to save a configuration to a file.
 
void janus_config_destroy (janus_config *config)
 Destroy a configuration container instance.
 
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.
 
janus_config_categoryjanus_config_category_create (const char *name)
 Method to create a new janus_config_category instance.
 
janus_config_arrayjanus_config_array_create (const char *name)
 Method to create a new janus_config_array instance.
 
void janus_config_container_destroy (janus_config_container *container)
 Helper method to quickly destroy an item, category or array.
 
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.
 
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.
 
janus_config_containerjanus_config_search (janus_config *config,...)
 Helper method to quickly lookup an item, category, or array.
 
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.
 
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.
 
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.
 
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.
 
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.
 

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

◆ janus_config

typedef struct janus_config janus_config

Configuration container.

◆ janus_config_array

Configuration array.

◆ janus_config_category

Configuration category (defined for backwards compatibility)

◆ janus_config_container

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

◆ janus_config_item

Configuration item (defined for backwards compatibility)

◆ janus_config_type

Configuration element type.

Enumeration Type Documentation

◆ janus_config_type

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

◆ janus_config_add()

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_create()

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_create()

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

◆ janus_config_container_destroy()

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_create()

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

◆ janus_config_destroy()

void janus_config_destroy ( janus_config config)

Destroy a configuration container instance.

Parameters
[in]configThe configuration to destroy

◆ janus_config_get()

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

◆ janus_config_get_arrays()

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

◆ janus_config_get_categories()

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_get_create()

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

◆ janus_config_get_items()

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_create()

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_parse()

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

◆ janus_config_print()

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

◆ janus_config_print_as()

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

◆ janus_config_remove()

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

◆ janus_config_save()

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 .jcfg, or .cfg for legacy INI files)
Returns
0 if successful, a negative integer otherwise

◆ janus_config_search()

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