root / src / libstrongswan / settings.h @ 3797b8e767a247f64a706b0a4dc8656e8377fbab
History | View | Annotate | Download (3.4 KB)
| 1 | /*
|
|---|---|
| 2 | * Copyright (C) 2008 Martin Willi |
| 3 | * Hochschule fuer Technik Rapperswil |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License as published by the |
| 7 | * Free Software Foundation; either version 2 of the License, or (at your |
| 8 | * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 12 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | * for more details. |
| 14 | */ |
| 15 | |
| 16 | /**
|
| 17 | * @defgroup settings settings |
| 18 | * @{ @ingroup libstrongswan
|
| 19 | */ |
| 20 | |
| 21 | #ifndef SETTINGS_H_
|
| 22 | #define SETTINGS_H_
|
| 23 | |
| 24 | typedef struct settings_t settings_t; |
| 25 | |
| 26 | #include <utils.h> |
| 27 | #include <utils/enumerator.h> |
| 28 | |
| 29 | /**
|
| 30 | * Generic configuration options read from a config file. |
| 31 | * |
| 32 | * The syntax is quite simple: |
| 33 | * |
| 34 | * settings := (section|keyvalue)* |
| 35 | * section := name { settings }
|
| 36 | * keyvalue := key = value\n |
| 37 | * |
| 38 | * E.g.: |
| 39 | * @code |
| 40 | a = b |
| 41 | section-one {
|
| 42 | somevalue = asdf |
| 43 | subsection {
|
| 44 | othervalue = xxx |
| 45 | } |
| 46 | yetanother = zz |
| 47 | } |
| 48 | section-two {
|
| 49 | } |
| 50 | @endcode |
| 51 | * |
| 52 | * The values are accesses using the get() functions using dotted keys, e.g. |
| 53 | * section-one.subsection.othervalue |
| 54 | */ |
| 55 | struct settings_t {
|
| 56 | |
| 57 | /**
|
| 58 | * Get a settings value as a string. |
| 59 | * |
| 60 | * @param key key including sections, printf style format |
| 61 | * @param def value returned if key not found |
| 62 | * @param ... argument list for key |
| 63 | * @return value pointing to internal string |
| 64 | */ |
| 65 | char* (*get_str)(settings_t *this, char *key, char *def, ...); |
| 66 | |
| 67 | /**
|
| 68 | * Get a boolean yes|no, true|false value. |
| 69 | * |
| 70 | * @param key key including sections, printf style format |
| 71 | * @param def value returned if key not found |
| 72 | * @param ... argument list for key |
| 73 | * @return value of the key |
| 74 | */ |
| 75 | bool (*get_bool)(settings_t *this, char *key, bool def, ...); |
| 76 | |
| 77 | /**
|
| 78 | * Get an integer value. |
| 79 | * |
| 80 | * @param key key including sections, printf style format |
| 81 | * @param def value returned if key not found |
| 82 | * @param ... argument list for key |
| 83 | * @return value of the key |
| 84 | */ |
| 85 | int (*get_int)(settings_t *this, char *key, int def, ...); |
| 86 | |
| 87 | /**
|
| 88 | * Get a time value. |
| 89 | * |
| 90 | * @param key key including sections, printf style format |
| 91 | * @param def value returned if key not found |
| 92 | * @param ... argument list for key |
| 93 | * @return value of the key |
| 94 | */ |
| 95 | u_int32_t (*get_time)(settings_t *this, char *key, u_int32_t def, ...);
|
| 96 | |
| 97 | /**
|
| 98 | * Create an enumerator over subsection names of a section. |
| 99 | * |
| 100 | * @param section section including parents, printf style format |
| 101 | * @param ... argument list for key |
| 102 | * @return enumerator over subsection names |
| 103 | */ |
| 104 | enumerator_t* (*create_section_enumerator)(settings_t *this, |
| 105 | char *section, ...);
|
| 106 | |
| 107 | /**
|
| 108 | * Create an enumerator over key/value pairs in a section. |
| 109 | * |
| 110 | * @param section section name to list key/value pairs of, printf style |
| 111 | * @param ... argmuent list for section |
| 112 | * @return enumerator over (char *key, char *value) |
| 113 | */ |
| 114 | enumerator_t* (*create_key_value_enumerator)(settings_t *this, |
| 115 | char *section, ...);
|
| 116 | |
| 117 | /**
|
| 118 | * Destroy a settings instance. |
| 119 | */ |
| 120 | void (*destroy)(settings_t *this);
|
| 121 | }; |
| 122 | |
| 123 | /**
|
| 124 | * Load settings from a file. |
| 125 | * |
| 126 | * @param file file to read settings from, NULL for default |
| 127 | * @return settings object |
| 128 | */ |
| 129 | settings_t *settings_create(char *file);
|
| 130 | |
| 131 | #endif /** SETTINGS_H_ @}*/ |