Fork me on GitHub
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 dependency graph for config.c:

Functions

char * get_filename (const char *path)
char * ltrim (char *s)
char * rtrim (char *s)
char * trim (char *s)
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.
janus_config_categoryjanus_config_get_categories (janus_config *config)
 Get all categories from a parsed configuration.
janus_config_categoryjanus_config_get_category (janus_config *config, const char *name)
 Get the category with a specific name from a parsed configuration.
janus_config_itemjanus_config_get_items (janus_config_category *category)
 Get all items from a category of a parsed configuration.
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.
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.
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.
void janus_config_print (janus_config *config)
 Helper method to print a configuration on the standard output.
void janus_config_destroy (janus_config *config)
 Destroy a configuration container instance.

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 (based on libini-config).

Core

Function Documentation

char * get_filename ( const char *  path)
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
janus_config_category* janus_config_get_categories ( janus_config config)

Get all categories from a parsed configuration.

Parameters
[in]configThe configuration container
Returns
A pointer to the first janus_config_category instance in the 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
janus_config_item* janus_config_get_items ( janus_config_category category)

Get all items from a category of a parsed configuration.

Parameters
[in]categoryThe configuration category
Returns
A pointer to the first janus_config_item instance in the 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
char * ltrim ( char *  s)
char * rtrim ( char *  s)
char * trim ( char *  s)