1 #ifndef CONFIGFILE_H
2 #define CONFIGFILE_H
3 /**
4 * collectd - src/configfile.h
5 * Copyright (C) 2005,2006 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 verplant.org>
23 **/
25 #include "collectd.h"
26 #include "liboconfig/oconfig.h"
28 /*
29 * DESCRIPTION
30 * Remove a registered plugin from the internal data structures.
31 *
32 * PARAMETERS
33 * `type' Name of the plugin (must be the same as passed to
34 * `plugin_register'
35 */
36 void cf_unregister (const char *type);
37 void cf_unregister_complex (const char *type);
39 /*
40 * DESCRIPTION
41 * `cf_register' is called by plugins that wish to receive config keys. The
42 * plugin will then receive all keys it registered for if they're found in a
43 * `<Plugin $type>' section.
44 *
45 * PARAMETERS
46 * `type' Name of the plugin (must be the same as passed to
47 * `plugin_register'
48 * `callback' Pointer to the callback function. The callback must return zero
49 * upon success, a value smaller than zero if it doesn't know how
50 * to handle the `key' passed to it (the first argument) or a
51 * value greater than zero if it knows how to handle the key but
52 * failed.
53 * `keys' Array of key values this plugin wished to receive. The last
54 * element must be a NULL-pointer.
55 * `keys_num' Number of elements in the array (not counting the last NULL-
56 * pointer.
57 *
58 * NOTES
59 * `cf_unregister' will be called for `type' to make sure only one record
60 * exists for each `type' at any time. This means that `cf_register' may be
61 * called multiple times, but only the last call will have an effect.
62 */
63 void cf_register (const char *type,
64 int (*callback) (const char *, const char *),
65 const char **keys, int keys_num);
67 int cf_register_complex (const char *type, int (*callback) (oconfig_item_t *));
69 /*
70 * DESCRIPTION
71 * `cf_read' reads the config file `filename' and dispatches the read
72 * information to functions/variables. Most important: Is calls `plugin_load'
73 * to load specific plugins, depending on the current mode of operation.
74 *
75 * PARAMETERS
76 * `filename' An additional filename to look for. This function calls
77 * `lc_process' which already searches many standard locations..
78 * If set to NULL will use the `CONFIGFILE' define.
79 *
80 * RETURN VALUE
81 * Returns zero upon success and non-zero otherwise. A error-message will have
82 * been printed in this case.
83 */
84 int cf_read (char *filename);
86 int global_option_set (const char *option, const char *value);
87 const char *global_option_get (const char *option);
89 /* Assures the config option is a string, duplicates it and returns the copy in
90 * "ret_string". If necessary "*ret_string" is freed first. Returns zero upon
91 * success. */
92 int cf_util_get_string (const oconfig_item_t *ci, char **ret_string);
94 /* Assures the config option is a string and copies it to the provided buffer.
95 * Assures null-termination. */
96 int cf_util_get_string_buffer (const oconfig_item_t *ci, char *buffer,
97 size_t buffer_size);
99 /* Assures the config option is a number and returns it as an int. */
100 int cf_util_get_int (const oconfig_item_t *ci, int *ret_value);
102 /* Assures the config option is a boolean and assignes it to `ret_bool'.
103 * Otherwise, `ret_bool' is not changed and non-zero is returned. */
104 int cf_util_get_boolean (const oconfig_item_t *ci, _Bool *ret_bool);
106 /* Assures that the config option is a string. The string is then converted to
107 * a port number using `service_name_to_port_number' and returned. Returns the
108 * port number in the range [1-65535] or less than zero upon failure. */
109 int cf_util_get_port_number (const oconfig_item_t *ci);
111 #endif /* defined(CONFIGFILE_H) */