Merge branch 'collectd-5.5'
[collectd.git] / src / daemon / configfile.h
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 "utils_time.h"
33 #include "liboconfig/oconfig.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,
71                 int (*callback) (const char *, const char *),
72                 const char **keys, int keys_num);
73
74 int cf_register_complex (const char *type, int (*callback) (oconfig_item_t *));
75
76 /*
77  * DESCRIPTION
78  *  `cf_read' reads the config file `filename' and dispatches the read
79  *  information to functions/variables. Most important: Is calls `plugin_load'
80  *  to load specific plugins, depending on the current mode of operation.
81  *
82  * PARAMETERS
83  *  `filename'  An additional filename to look for. This function calls
84  *              `lc_process' which already searches many standard locations..
85  *              If set to NULL will use the `CONFIGFILE' define.
86  *
87  * RETURN VALUE
88  *  Returns zero upon success and non-zero otherwise. A error-message will have
89  *  been printed in this case.
90  */
91 int cf_read (const char *filename);
92
93 int global_option_set (const char *option, const char *value, _Bool from_cli);
94 const char *global_option_get (const char *option);
95 long global_option_get_long (const char *option, long default_value);
96 long global_option_get_long_in_range (const char *option, long default_value, long min, long max);
97
98 cdtime_t global_option_get_time (char const *option, cdtime_t default_value);
99
100 cdtime_t cf_get_default_interval (void);
101
102 /* Assures the config option is a string, duplicates it and returns the copy in
103  * "ret_string". If necessary "*ret_string" is freed first. Returns zero upon
104  * success. */
105 int cf_util_get_string (const oconfig_item_t *ci, char **ret_string);
106
107 /* Assures the config option is a string and copies it to the provided buffer.
108  * Assures null-termination. */
109 int cf_util_get_string_buffer (const oconfig_item_t *ci, char *buffer,
110                 size_t buffer_size);
111
112 /* Assures the config option is a number and returns it as an int. */
113 int cf_util_get_int (const oconfig_item_t *ci, int *ret_value);
114
115 /* Assures the config option is a number and returns it as a double. */
116 int cf_util_get_double (const oconfig_item_t *ci, double *ret_value);
117
118 /* Assures the config option is a boolean and assignes it to `ret_bool'.
119  * Otherwise, `ret_bool' is not changed and non-zero is returned. */
120 int cf_util_get_boolean (const oconfig_item_t *ci, _Bool *ret_bool);
121
122 /* Assures the config option is a boolean and set or unset the given flag in
123  * `ret_value' as appropriate. Returns non-zero on error. */
124 int cf_util_get_flag (const oconfig_item_t *ci,
125                 unsigned int *ret_value, unsigned int flag);
126
127 /* Assures that the config option is a string or a number if the correct range
128  * of 1-65535. The string is then converted to a port number using
129  * `service_name_to_port_number' and returned.
130  * Returns the port number in the range [1-65535] or less than zero upon
131  * failure. */
132 int cf_util_get_port_number (const oconfig_item_t *ci);
133
134 /* Assures that the config option is either a service name (a string) or a port
135  * number (an integer in the appropriate range) and returns a newly allocated
136  * string. If ret_string points to a non-NULL pointer, it is freed before
137  * assigning a new value. */
138 int cf_util_get_service (const oconfig_item_t *ci, char **ret_string);
139
140 int cf_util_get_cdtime (const oconfig_item_t *ci, cdtime_t *ret_value);
141
142 #endif /* defined(CONFIGFILE_H) */