1 #ifndef CONFIGFILE_H
2 #define CONFIGFILE_H
3 /**
4 * collectd - src/configfile.h
5 * Copyright (C) 2005-2011 Florian octo Forster
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 * Authors:
22 * Florian octo Forster <octo at collectd.org>
23 **/
25 #include "collectd.h"
26 #include "utils_time.h"
27 #include "liboconfig/oconfig.h"
29 /*
30 * DESCRIPTION
31 * Remove a registered plugin from the internal data structures.
32 *
33 * PARAMETERS
34 * `type' Name of the plugin (must be the same as passed to
35 * `plugin_register'
36 */
37 void cf_unregister (const char *type);
38 void cf_unregister_complex (const char *type);
40 /*
41 * DESCRIPTION
42 * `cf_register' is called by plugins that wish to receive config keys. The
43 * plugin will then receive all keys it registered for if they're found in a
44 * `<Plugin $type>' section.
45 *
46 * PARAMETERS
47 * `type' Name of the plugin (must be the same as passed to
48 * `plugin_register'
49 * `callback' Pointer to the callback function. The callback must return zero
50 * upon success, a value smaller than zero if it doesn't know how
51 * to handle the `key' passed to it (the first argument) or a
52 * value greater than zero if it knows how to handle the key but
53 * failed.
54 * `keys' Array of key values this plugin wished to receive. The last
55 * element must be a NULL-pointer.
56 * `keys_num' Number of elements in the array (not counting the last NULL-
57 * pointer.
58 *
59 * NOTES
60 * `cf_unregister' will be called for `type' to make sure only one record
61 * exists for each `type' at any time. This means that `cf_register' may be
62 * called multiple times, but only the last call will have an effect.
63 */
64 void cf_register (const char *type,
65 int (*callback) (const char *, const char *),
66 const char **keys, int keys_num);
68 int cf_register_complex (const char *type, int (*callback) (oconfig_item_t *));
70 /*
71 * DESCRIPTION
72 * `cf_read' reads the config file `filename' and dispatches the read
73 * information to functions/variables. Most important: Is calls `plugin_load'
74 * to load specific plugins, depending on the current mode of operation.
75 *
76 * PARAMETERS
77 * `filename' An additional filename to look for. This function calls
78 * `lc_process' which already searches many standard locations..
79 * If set to NULL will use the `CONFIGFILE' define.
80 *
81 * RETURN VALUE
82 * Returns zero upon success and non-zero otherwise. A error-message will have
83 * been printed in this case.
84 */
85 int cf_read (char *filename);
87 int global_option_set (const char *option, const char *value);
88 const char *global_option_get (const char *option);
90 /* Assures the config option is a string, duplicates it and returns the copy in
91 * "ret_string". If necessary "*ret_string" is freed first. Returns zero upon
92 * success. */
93 int cf_util_get_string (const oconfig_item_t *ci, char **ret_string);
95 /* Assures the config option is a string and copies it to the provided buffer.
96 * Assures null-termination. */
97 int cf_util_get_string_buffer (const oconfig_item_t *ci, char *buffer,
98 size_t buffer_size);
100 /* Assures the config option is a number and returns it as an int. */
101 int cf_util_get_int (const oconfig_item_t *ci, int *ret_value);
103 /* Assures the config option is a boolean and assignes it to `ret_bool'.
104 * Otherwise, `ret_bool' is not changed and non-zero is returned. */
105 int cf_util_get_boolean (const oconfig_item_t *ci, _Bool *ret_bool);
107 /* Assures the config option is a boolean and set or unset the given flag in
108 * `ret_value' as appropriate. Returns non-zero on error. */
109 int cf_util_get_flag (const oconfig_item_t *ci,
110 unsigned int *ret_value, unsigned int flag);
112 /* Assures that the config option is a string or a number if the correct range
113 * of 1-65535. The string is then converted to a port number using
114 * `service_name_to_port_number' and returned.
115 * Returns the port number in the range [1-65535] or less than zero upon
116 * failure. */
117 int cf_util_get_port_number (const oconfig_item_t *ci);
119 /* Assures that the config option is either a service name (a string) or a port
120 * number (an integer in the appropriate range) and returns a newly allocated
121 * string. If ret_string points to a non-NULL pointer, it is freed before
122 * assigning a new value. */
123 int cf_util_get_service (const oconfig_item_t *ci, char **ret_string);
125 int cf_util_get_cdtime (const oconfig_item_t *ci, cdtime_t *ret_value);
127 #endif /* defined(CONFIGFILE_H) */