Fork me on GitHub
Functions
config.c File Reference

Configuration files parsing. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include "config.h"
#include "debug.h"
#include "utils.h"
Include dependency graph for config.c:

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...
 
GList * janus_config_get_categories (janus_config *config)
 Get the list of all categories from a parsed configuration as a GLib linked list. More...
 
janus_config_categoryjanus_config_get_category (janus_config *config, const char *name)
 Get the category with a specific name from a parsed configuration. More...
 
GList * janus_config_get_items (janus_config_category *category)
 Get the list of all items in a category as a GLib linked list. More...
 
janus_config_itemjanus_config_get_item (janus_config_category *category, const char *name)
 Get the item with a specific name from a category of a parsed configuration. More...
 
janus_config_itemjanus_config_get_item_drilldown (janus_config *config, const char *category, const char *name)
 Get the item with a specific name from a category with a specific name from a parsed configuration. More...
 
janus_config_categoryjanus_config_add_category (janus_config *config, const char *category)
 Add a new category with the specific name. More...
 
int janus_config_remove_category (janus_config *config, const char *category)
 Remove an existing category with the specific name. More...
 
janus_config_itemjanus_config_add_item (janus_config *config, const char *category, const char *name, const char *value)
 Add a new item with the specific name and value to a category, and create the category if it doesn't exist. More...
 
int janus_config_remove_item (janus_config *config, const char *category, const char *name)
 Remove an existing item with the specific name from a category. More...
 
void janus_config_print (janus_config *config)
 Helper method to print a configuration on the standard output. More...
 
gboolean 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...
 

Detailed Description

Configuration files parsing.

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

Implementation of a parser of INI configuration files.

Core

Function Documentation

janus_config_category* janus_config_add_category ( janus_config config,
const char *  category 
)

Add a new category with the specific name.

Note
If the item already exists in the category, it is NOT overwritten, and the existing instance is returned
Parameters
[in]configThe configuration container
[in]categoryThe category to create
Returns
A pointer to the janus_config_category instance if successful, NULL otherwise
janus_config_item* janus_config_add_item ( janus_config config,
const char *  category,
const char *  name,
const char *  value 
)

Add a new item with the specific name and value to a category, and create the category if it doesn't exist.

Note
If the item already exists in the category, its value is overwritten
Parameters
[in]configThe configuration container
[in]categoryThe category to add the item to, and to create if it doesn't exist
[in]nameThe name of the item
[in]valueThe value of the item
Returns
A pointer to the janus_config_item instance if successful, NULL otherwise
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
GList* janus_config_get_categories ( janus_config config)

Get the list of all categories from a parsed configuration as a GLib linked list.

Parameters
[in]configThe configuration container
Returns
A pointer to the categories GLib linked list if successful, NULL otherwise
janus_config_category* janus_config_get_category ( janus_config config,
const char *  name 
)

Get the category with a specific name from a parsed configuration.

Parameters
[in]configThe configuration container
[in]nameThe name of the category
Returns
A pointer to the janus_config_category instance if successful, NULL otherwise
janus_config_item* janus_config_get_item ( janus_config_category category,
const char *  name 
)

Get the item with a specific name from a category of a parsed configuration.

Parameters
[in]categoryThe configuration category
[in]nameThe name of the item
Returns
A pointer to the janus_config_item instance if successful, NULL otherwise
janus_config_item* janus_config_get_item_drilldown ( janus_config config,
const char *  category,
const char *  name 
)

Get the item with a specific name from a category with a specific name from a parsed configuration.

Note
This is the same as janus_config_get_item, but it looks for the janus_config_category for you
Parameters
[in]configThe configuration container
[in]categoryThe name of the configuration category
[in]nameThe name of the item
Returns
A pointer to the janus_config_item instance if successful, NULL otherwise
GList* janus_config_get_items ( janus_config_category category)

Get the list of all items in a category as a GLib linked list.

Parameters
[in]categoryThe configuration category
Returns
A pointer to the items GLib linked list 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.

Parameters
[in]configThe configuration to print
int janus_config_remove_category ( janus_config config,
const char *  category 
)

Remove an existing category with the specific name.

Note
This will also remove all items from that category
Parameters
[in]configThe configuration container
[in]categoryThe category to remove
Returns
0 if successful, a negative integer otherwise
int janus_config_remove_item ( janus_config config,
const char *  category,
const char *  name 
)

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

Parameters
[in]configThe configuration container
[in]categoryThe category to remove the item from
[in]nameThe name of the item
Returns
0 if successful, a negative integer otherwise
gboolean 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