2 * collectd - src/configfile.h
3 * Copyright (C) 2005-2011 Florian octo Forster
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
24 * Florian octo Forster <octo at collectd.org>
31 #include "utils_time.h"
32 #include "liboconfig/oconfig.h"
36 * Remove a registered plugin from the internal data structures.
39 * `type' Name of the plugin (must be the same as passed to
42 void cf_unregister (const char *type);
43 void cf_unregister_complex (const char *type);
47 * `cf_register' is called by plugins that wish to receive config keys. The
48 * plugin will then receive all keys it registered for if they're found in a
49 * `<Plugin $type>' section.
52 * `type' Name of the plugin (must be the same as passed to
54 * `callback' Pointer to the callback function. The callback must return zero
55 * upon success, a value smaller than zero if it doesn't know how
56 * to handle the `key' passed to it (the first argument) or a
57 * value greater than zero if it knows how to handle the key but
59 * `keys' Array of key values this plugin wished to receive. The last
60 * element must be a NULL-pointer.
61 * `keys_num' Number of elements in the array (not counting the last NULL-
65 * `cf_unregister' will be called for `type' to make sure only one record
66 * exists for each `type' at any time. This means that `cf_register' may be
67 * called multiple times, but only the last call will have an effect.
69 void cf_register (const char *type,
70 int (*callback) (const char *, const char *),
71 const char **keys, int keys_num);
73 int cf_register_complex (const char *type, int (*callback) (oconfig_item_t *));
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.
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.
87 * Returns zero upon success and non-zero otherwise. A error-message will have
88 * been printed in this case.
90 int cf_read (char *filename);
92 int global_option_set (const char *option, const char *value);
93 const char *global_option_get (const char *option);
94 long global_option_get_long (const char *option, long default_value);
95 long global_option_get_long_in_range (const char *option, long default_value, long min, long max);
97 cdtime_t global_option_get_time (char const *option, cdtime_t default_value);
99 cdtime_t cf_get_default_interval (void);
101 /* Assures the config option is a string, duplicates it and returns the copy in
102 * "ret_string". If necessary "*ret_string" is freed first. Returns zero upon
104 int cf_util_get_string (const oconfig_item_t *ci, char **ret_string);
106 /* Assures the config option is a string and copies it to the provided buffer.
107 * Assures null-termination. */
108 int cf_util_get_string_buffer (const oconfig_item_t *ci, char *buffer,
111 /* Assures the config option is a number and returns it as an int. */
112 int cf_util_get_int (const oconfig_item_t *ci, int *ret_value);
114 /* Assures the config option is a number and returns it as a double. */
115 int cf_util_get_double (const oconfig_item_t *ci, double *ret_value);
117 /* Assures the config option is a boolean and assignes it to `ret_bool'.
118 * Otherwise, `ret_bool' is not changed and non-zero is returned. */
119 int cf_util_get_boolean (const oconfig_item_t *ci, _Bool *ret_bool);
121 /* Assures the config option is a boolean and set or unset the given flag in
122 * `ret_value' as appropriate. Returns non-zero on error. */
123 int cf_util_get_flag (const oconfig_item_t *ci,
124 unsigned int *ret_value, unsigned int flag);
126 /* Assures that the config option is a string or a number if the correct range
127 * of 1-65535. The string is then converted to a port number using
128 * `service_name_to_port_number' and returned.
129 * Returns the port number in the range [1-65535] or less than zero upon
131 int cf_util_get_port_number (const oconfig_item_t *ci);
133 /* Assures that the config option is either a service name (a string) or a port
134 * number (an integer in the appropriate range) and returns a newly allocated
135 * string. If ret_string points to a non-NULL pointer, it is freed before
136 * assigning a new value. */
137 int cf_util_get_service (const oconfig_item_t *ci, char **ret_string);
139 int cf_util_get_cdtime (const oconfig_item_t *ci, cdtime_t *ret_value);
141 #endif /* defined(CONFIGFILE_H) */