1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
/**
*
* @file configuration.h
* @brief Configuration management routines
*
*/
#ifndef _CONFIGURATION_H_
#define _CONFIGURATION_H_
/* This is roughly based on the APT configuration class */
struct configitem {
char *tag;
char *value;
struct configitem *parent, *child, *next;
};
/**
* @brief Configuration management class
*/
struct configuration {
/**
* @brief configuration data
*/
struct configitem *root;
/**
* @brief Get a configuration item with a given tag (string)
* @param cfg configuration object
* @param tag Tag of configuration item
* @param defaultvalue Default value
* @return Value of configuration item
*/
const char *(*get)(struct configuration *cfg, const char *tag,
const char *defaultvalue);
/**
* @brief Get a configuration item with a given tag (integer)
* @param cfg configuration object
* @param tag Tag of configuration item
* @param defaultvalue Default value
* @return Value of configuration item
*/
int (*geti)(struct configuration *cfg, const char *tag,
int defaultvalue);
/**
* @brief Set the value of a configuration item (string)
* @param cfg Configuration object
* @param tag Tag of configuration item
* @param value New value
*/
void (*set)(struct configuration *cfg, const char *tag,
const char *value);
/**
* @brief Set the value of a configuration item (integer)
* @param cfg Configuration object
* @param tag Tag of configuration item
* @param value New value
*/
void (*seti)(struct configuration *cfg, const char *tag,
int value);
/**
* @brief Checks to see if a given configuration item exists
* @param cfg Configuration object
* @param tag Tag of configuration item
* @return 1 if item exists
*/
int (*exists)(struct configuration *cfg, const char *tag);
/**
* @brief Populate configuration object with data from file
* @param cfg Configuration object
* @param filename Configuration file to read
* @return 1 on success, 0 on error
*/
int (*read)(struct configuration *cfg, const char *filename);
/**
* @brief Dump the contents of a configuration object to stdout
* @param cfg Configuration object
*/
void (*dump)(struct configuration *cfg);
/**
* @brief returns an internal pointer to a tree structure
* representing a node with the given tag
* @param cfg Configuration object
* @param tag Tag of configuration item
* @warning external callers should not change the structure of
* the tree returned
*/
struct configitem *(*tree)(struct configuration *cfg,
const char *tag);
};
/**
* @brief Creates a configuration object
*/
struct configuration *config_new(void);
/**
* @brief Deletes a configuration object
*/
void config_delete(struct configuration *);
#endif
|