Statistics
| Branch: | Revision:

janus-gateway / config.h @ 5e9e29e0

History | View | Annotate | Download (4.55 KB)

1 be35facb meetecho
/*! \file    config.h
2
 * \author   Lorenzo Miniero <lorenzo@meetecho.com>
3 5e9e29e0 meetecho
 * \brief    Configuration files parsing (headers)
4 be35facb meetecho
 * \details  Implementation of a parser of INI configuration files (based on libini-config).
5
 * 
6
 * \ingroup core
7
 * \ref core
8
 */
9
10
#ifndef _JANUS_CONFIG_H
11
#define _JANUS_CONFIG_H
12
13
#include <ini_config.h>
14
15
16
/*! \brief Configuration item (name=value) */
17
typedef struct janus_config_item {
18
        /*! \brief Name of the item */
19
        const char *name;
20
        /*! \brief Value of the item */
21
        const char *value;
22
        /*! \brief Next element in the linked list of items in this category */
23
        struct janus_config_item *next;
24
} janus_config_item;
25
26
/*! \brief Configuration category ([category]) */
27
typedef struct janus_config_category {
28
        /*! \brief Name of the category */
29
        const char *name;
30
        /*! \brief Linked list of items */
31
        janus_config_item *items;
32
        /*! \brief Next element in the linked list of categories in this configuration */
33
        struct janus_config_category *next;
34
} janus_config_category;
35
36
/*! \brief Configuration container */
37
typedef struct janus_config {
38
        /*! \brief Name of the configuration */
39
        const char *name;
40
        /*! \brief Linked list of uncategorized items */
41
        janus_config_item *items;
42
        /*! \brief Linked list of categories category */
43
        janus_config_category *categories;
44
} janus_config;
45
46
47
/*! \brief Method to parse an INI configuration file
48
 * @param[in] config_file Path to the configuration file
49
 * @returns A pointer to a valid janus_config instance if successful, NULL otherwise */ 
50
janus_config *janus_config_parse(const char *config_file);
51
/*! \brief Method to create a new, empty, configuration
52
 * @param[in] name Name to give to the configuration
53
 * @returns A pointer to a valid janus_config instance if successful, NULL otherwise */ 
54
janus_config *janus_config_create(const char *name);
55
/*! \brief Get all categories from a parsed configuration
56
 * @param[in] config The configuration container
57
 * @returns A pointer to the first janus_config_category instance in the list if successful, NULL otherwise */ 
58
janus_config_category *janus_config_get_categories(janus_config *config);
59
/*! \brief Get the category with a specific name from a parsed configuration
60
 * @param[in] config The configuration container
61
 * @param[in] name The name of the category
62
 * @returns A pointer to the janus_config_category instance if successful, NULL otherwise */ 
63
janus_config_category *janus_config_get_category(janus_config *config, const char *name);
64
/*! \brief Get all items from a category of a parsed configuration
65
 * @param[in] category The configuration category
66
 * @returns A pointer to the first janus_config_item instance in the list if successful, NULL otherwise */ 
67
janus_config_item *janus_config_get_items(janus_config_category *category);
68
/*! \brief Get the item with a specific name from a category of a parsed configuration
69
 * @param[in] category The configuration category
70
 * @param[in] name The name of the item
71
 * @returns A pointer to the janus_config_item instance if successful, NULL otherwise */ 
72
janus_config_item *janus_config_get_item(janus_config_category *category, const char *name);
73
/*! \brief Get the item with a specific name from a category with a specific name from a parsed configuration
74
 * \note This is the same as janus_config_get_item, but it looks for the janus_config_category for you
75
 * @param[in] config The configuration container
76
 * @param[in] category The name of the configuration category
77
 * @param[in] name The name of the item
78
 * @returns A pointer to the janus_config_item instance if successful, NULL otherwise */ 
79
janus_config_item *janus_config_get_item_drilldown(janus_config *config, const char *category, const char *name);
80
/*! \brief Add a new item with the specific name and value to a category, and create the category if it doesn't exist
81
 * \note If the item already exists in the category, its value is overwritten
82
 * @param[in] config The configuration container
83
 * @param[in] category The category to add the item to, and to create if it doesn't exist
84
 * @param[in] name The name of the item
85
 * @param[in] value The value of the item
86
 * @returns A pointer to the janus_config_item instance if successful, NULL otherwise */ 
87
janus_config_item *janus_config_add_item(janus_config *config, const char *category, const char *name, const char *value);
88
/*! \brief Helper method to print a configuration on the standard output
89
 * @param[in] config The configuration to print */
90
void janus_config_print(janus_config *config);
91
/*! \brief Destroy a configuration container instance
92
 * @param[in] config The configuration to destroy */
93
void janus_config_destroy(janus_config *config);
94
95
96
#endif