| 1 |
/** |
| 2 |
* collectd - src/configfile.h |
| 3 |
* Copyright (C) 2005-2011 Florian octo Forster |
| 4 |
* |
| 5 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 6 |
* copy of this software and associated documentation files (the "Software"), |
| 7 |
* to deal in the Software without restriction, including without limitation |
| 8 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 10 |
* Software is furnished to do so, subject to the following conditions: |
| 11 |
* |
| 12 |
* The above copyright notice and this permission notice shall be included in |
| 13 |
* all copies or substantial portions of the Software. |
| 14 |
* |
| 15 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 |
* DEALINGS IN THE SOFTWARE. |
| 22 |
* |
| 23 |
* Authors: |
| 24 |
* Florian octo Forster <octo at collectd.org> |
| 25 |
**/ |
| 26 |
|
| 27 |
#ifndef CONFIGFILE_H |
| 28 |
#define CONFIGFILE_H |
| 29 |
|
| 30 |
#include "collectd.h" |
| 31 |
|
| 32 |
#include "liboconfig/oconfig.h" |
| 33 |
#include "utils_time.h" |
| 34 |
|
| 35 |
/* |
| 36 |
* DESCRIPTION |
| 37 |
* Remove a registered plugin from the internal data structures. |
| 38 |
* |
| 39 |
* PARAMETERS |
| 40 |
* `type' Name of the plugin (must be the same as passed to |
| 41 |
* `plugin_register' |
| 42 |
*/ |
| 43 |
void cf_unregister(const char *type); |
| 44 |
void cf_unregister_complex(const char *type); |
| 45 |
|
| 46 |
/* |
| 47 |
* DESCRIPTION |
| 48 |
* `cf_register' is called by plugins that wish to receive config keys. The |
| 49 |
* plugin will then receive all keys it registered for if they're found in a |
| 50 |
* `<Plugin $type>' section. |
| 51 |
* |
| 52 |
* PARAMETERS |
| 53 |
* `type' Name of the plugin (must be the same as passed to |
| 54 |
* `plugin_register' |
| 55 |
* `callback' Pointer to the callback function. The callback must return zero |
| 56 |
* upon success, a value smaller than zero if it doesn't know how |
| 57 |
* to handle the `key' passed to it (the first argument) or a |
| 58 |
* value greater than zero if it knows how to handle the key but |
| 59 |
* failed. |
| 60 |
* `keys' Array of key values this plugin wished to receive. The last |
| 61 |
* element must be a NULL-pointer. |
| 62 |
* `keys_num' Number of elements in the array (not counting the last NULL- |
| 63 |
* pointer. |
| 64 |
* |
| 65 |
* NOTES |
| 66 |
* `cf_unregister' will be called for `type' to make sure only one record |
| 67 |
* exists for each `type' at any time. This means that `cf_register' may be |
| 68 |
* called multiple times, but only the last call will have an effect. |
| 69 |
*/ |
| 70 |
void cf_register(const char *type, int (*callback)(const char *, const char *), |
| 71 |
const char **keys, int keys_num); |
| 72 |
|
| 73 |
int cf_register_complex(const char *type, int (*callback)(oconfig_item_t *)); |
| 74 |
|
| 75 |
/* |
| 76 |
* DESCRIPTION |
| 77 |
* `cf_read' reads the config file `filename' and dispatches the read |
| 78 |
* information to functions/variables. Most important: Is calls `plugin_load' |
| 79 |
* to load specific plugins, depending on the current mode of operation. |
| 80 |
* |
| 81 |
* PARAMETERS |
| 82 |
* `filename' An additional filename to look for. This function calls |
| 83 |
* `lc_process' which already searches many standard locations.. |
| 84 |
* If set to NULL will use the `CONFIGFILE' define. |
| 85 |
* |
| 86 |
* RETURN VALUE |
| 87 |
* Returns zero upon success and non-zero otherwise. A error-message will have |
| 88 |
* been printed in this case. |
| 89 |
*/ |
| 90 |
int cf_read(const char *filename); |
| 91 |
|
| 92 |
int global_option_set(const char *option, const char *value, bool from_cli); |
| 93 |
const char *global_option_get(const char *option); |
| 94 |
long global_option_get_long(const char *option, long default_value); |
| 95 |
|
| 96 |
cdtime_t global_option_get_time(char const *option, cdtime_t default_value); |
| 97 |
|
| 98 |
cdtime_t cf_get_default_interval(void); |
| 99 |
|
| 100 |
/* Assures the config option is a string, duplicates it and returns the copy in |
| 101 |
* "ret_string". If necessary "*ret_string" is freed first. Returns zero upon |
| 102 |
* success. */ |
| 103 |
int cf_util_get_string(const oconfig_item_t *ci, char **ret_string); |
| 104 |
|
| 105 |
/* Assures the config option is a string and copies it to the provided buffer. |
| 106 |
* Assures null-termination. */ |
| 107 |
int cf_util_get_string_buffer(const oconfig_item_t *ci, char *buffer, |
| 108 |
size_t buffer_size); |
| 109 |
|
| 110 |
/* Assures the config option is a number and returns it as an int. */ |
| 111 |
int cf_util_get_int(const oconfig_item_t *ci, int *ret_value); |
| 112 |
|
| 113 |
/* Assures the config option is a number and returns it as a double. */ |
| 114 |
int cf_util_get_double(const oconfig_item_t *ci, double *ret_value); |
| 115 |
|
| 116 |
/* Assures the config option is a boolean and assignes it to `ret_bool'. |
| 117 |
* Otherwise, `ret_bool' is not changed and non-zero is returned. */ |
| 118 |
int cf_util_get_boolean(const oconfig_item_t *ci, bool *ret_bool); |
| 119 |
|
| 120 |
/* Assures the config option is a boolean and set or unset the given flag in |
| 121 |
* `ret_value' as appropriate. Returns non-zero on error. */ |
| 122 |
int cf_util_get_flag(const oconfig_item_t *ci, unsigned int *ret_value, |
| 123 |
unsigned int flag); |
| 124 |
|
| 125 |
/* Assures that the config option is a string or a number if the correct range |
| 126 |
* of 1-65535. The string is then converted to a port number using |
| 127 |
* `service_name_to_port_number' and returned. |
| 128 |
* Returns the port number in the range [1-65535] or less than zero upon |
| 129 |
* failure. */ |
| 130 |
int cf_util_get_port_number(const oconfig_item_t *ci); |
| 131 |
|
| 132 |
/* Assures that the config option is either a service name (a string) or a port |
| 133 |
* number (an integer in the appropriate range) and returns a newly allocated |
| 134 |
* string. If ret_string points to a non-NULL pointer, it is freed before |
| 135 |
* assigning a new value. */ |
| 136 |
int cf_util_get_service(const oconfig_item_t *ci, char **ret_string); |
| 137 |
|
| 138 |
int cf_util_get_cdtime(const oconfig_item_t *ci, cdtime_t *ret_value); |
| 139 |
|
| 140 |
#endif /* defined(CONFIGFILE_H) */ |