summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5005598)
raw | patch | inline | side by side (parent: 5005598)
author | octo <octo> | |
Tue, 20 Dec 2005 08:03:34 +0000 (08:03 +0000) | ||
committer | octo <octo> | |
Tue, 20 Dec 2005 08:03:34 +0000 (08:03 +0000) |
Reorganized the `configfile.c' file. Changed callback names, their order and added comments.
Added `cf_callback_mode_plugindir' to allow the config file to change the plugin directory.
Added `cf_callback_mode_plugindir' to allow the config file to change the plugin directory.
src/configfile.c | patch | blob | history | |
src/plugin.c | patch | blob | history | |
src/plugin.h | patch | blob | history |
diff --git a/src/configfile.c b/src/configfile.c
index a0610041257525ba50e6013c473dbb357866262b..76e542178ab5e4b7a43e1bb6c59049294f8c5852 100644 (file)
--- a/src/configfile.c
+++ b/src/configfile.c
{"Server", NULL, MODE_CLIENT },
{"Port", NULL, MODE_CLIENT | MODE_SERVER },
{"PIDFile", NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL},
- {"DataDir", NULL, MODE_SERVER | MODE_LOCAL},
- {"PluginDir", NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL}
+ {"DataDir", NULL, MODE_SERVER | MODE_LOCAL}
};
-static int cf_mode_num = 5;
+static int cf_mode_num = 4;
static int nesting_depth = 0;
static char *current_module = NULL;
-/* cf_register needs this prototype */
-int cf_callback_dispatch (const char *, const char *, const char *,
+/* `cf_register' needs this prototype */
+int cf_callback_plugin_dispatch (const char *, const char *, const char *,
const char *, lc_flags_t, void *);
/*
* `key', but apparently `lc_register_*' can handle
* it.. */
lc_register_callback (buf, SHORTOPT_NONE,
- LC_VAR_STRING, cf_callback_dispatch,
+ LC_VAR_STRING, cf_callback_plugin_dispatch,
NULL);
}
else
return (NULL);
}
-/*
- * Functions for the actual parsing
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Functions for the actual parsing *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*
+ * `cf_callback_mode'
+ * Start/end the `mode' section
+ *
+ * <Mode `arguments'>
+ * ...
+ * </Mode>
*/
-int cf_callback_dispatch (const char *shortvar, const char *var,
+int cf_callback_mode (const char *shortvar, const char *var,
const char *arguments, const char *value, lc_flags_t flags,
void *extra)
{
DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
shortvar, var, arguments, value);
- if ((nesting_depth == 0) || (current_module == NULL))
+ if (flags == LC_FLAGS_SECTIONSTART)
{
- fprintf (stderr, ERR_NEEDS_SECTION, shortvar);
- return (LC_CBRET_ERROR);
+ if (nesting_depth != 0)
+ {
+ fprintf (stderr, ERR_NOT_NESTED);
+ return (LC_CBRET_ERROR);
+ }
+
+ if (arguments == NULL)
+ {
+ fprintf (stderr, ERR_NEEDS_ARG, shortvar);
+ return (LC_CBRET_ERROR);
+ }
+
+ nesting_depth++;
+
+ if (((operating_mode == MODE_CLIENT)
+ && (strcasecmp (arguments, "Client") == 0))
+ || ((operating_mode == MODE_SERVER)
+ && (strcasecmp (arguments, "Server") == 0))
+ || ((operating_mode == MODE_LOCAL)
+ && (strcasecmp (arguments, "Local") == 0)))
+ {
+ return (LC_CBRET_OKAY);
+ }
+ else
+ {
+ return (LC_CBRET_IGNORESECTION);
+ }
}
+ else if (flags == LC_FLAGS_SECTIONEND)
+ {
+ nesting_depth--;
- /* Send the data to the plugin */
- if (cf_dispatch (current_module, shortvar, value) < 0)
+ return (LC_CBRET_OKAY);
+ }
+ else
+ {
+ fprintf (stderr, ERR_SECTION_ONLY, shortvar);
return (LC_CBRET_ERROR);
+ }
+
+}
+
+/*
+ * `cf_callback_mode_plugindir'
+ * Change the plugin directory
+ *
+ * <Mode xxx>
+ * PluginDir `value'
+ * </Mode>
+ */
+int cf_callback_mode_plugindir (const char *shortvar, const char *var,
+ const char *arguments, const char *value, lc_flags_t flags,
+ void *extra)
+{
+ DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
+ shortvar, var, arguments, value);
+
+ plugin_set_dir (value);
return (LC_CBRET_OKAY);
}
-int cf_callback_options_mode (const char *shortvar, const char *var,
+int cf_callback_mode_option (const char *shortvar, const char *var,
const char *arguments, const char *value, lc_flags_t flags,
void *extra)
{
cf_mode_item_t *item;
+ DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
+ shortvar, var, arguments, value);
+
if (extra == NULL)
{
fprintf (stderr, "No extra..?\n");
return (LC_CBRET_OKAY);
}
-int cf_callback_section_mode (const char *shortvar, const char *var,
+/*
+ * `cf_callback_mode_loadmodule':
+ * Load a plugin.
+ *
+ * <Mode xxx>
+ * LoadPlugin `value'
+ * </Mode>
+ */
+int cf_callback_mode_loadmodule (const char *shortvar, const char *var,
const char *arguments, const char *value, lc_flags_t flags,
void *extra)
{
DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
shortvar, var, arguments, value);
- if (flags == LC_FLAGS_SECTIONSTART)
+ if (nesting_depth == 0)
{
- if (nesting_depth != 0)
- {
- fprintf (stderr, ERR_NOT_NESTED);
- return (LC_CBRET_ERROR);
- }
+ fprintf (stderr, ERR_NEEDS_SECTION, shortvar);
+ return (LC_CBRET_ERROR);
+ }
- if (arguments == NULL)
- {
- fprintf (stderr, ERR_NEEDS_ARG, shortvar);
- return (LC_CBRET_ERROR);
- }
+ if (plugin_load (value))
+ syslog (LOG_ERR, "plugin_load (%s): failed to load plugin", value);
- nesting_depth++;
+ /* Return `okay' even if there was an error, because it's not a syntax
+ * problem.. */
+ return (LC_CBRET_OKAY);
+}
- if (((operating_mode == MODE_CLIENT)
- && (strcasecmp (arguments, "Client") == 0))
- || ((operating_mode == MODE_SERVER)
- && (strcasecmp (arguments, "Server") == 0))
- || ((operating_mode == MODE_LOCAL)
- && (strcasecmp (arguments, "Local") == 0)))
- {
- return (LC_CBRET_OKAY);
- }
- else
- {
- return (LC_CBRET_IGNORESECTION);
- }
- }
- else if (flags == LC_FLAGS_SECTIONEND)
- {
- nesting_depth--;
+/* XXX think about how to do the command line stuff */
+int cf_callback_mode_switch (const char *shortvar, const char *var,
+ const char *arguments, const char *value, lc_flags_t flags,
+ void *extra)
+{
+ DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
+ shortvar, var, arguments, value);
- return (LC_CBRET_OKAY);
- }
+ if (strcasecmp (shortvar, "Client") == 0)
+ operating_mode = MODE_CLIENT;
+ else if (strcasecmp (shortvar, "Local") == 0)
+ operating_mode = MODE_LOCAL;
+ else if (strcasecmp (shortvar, "Server") == 0)
+ operating_mode = MODE_SERVER;
else
{
- fprintf (stderr, ERR_SECTION_ONLY, shortvar);
+ fprintf (stderr, "cf_callback_mode_switch: Wrong mode!\n");
return (LC_CBRET_ERROR);
}
+ return (LC_CBRET_OKAY);
}
-int cf_callback_section_module (const char *shortvar, const char *var,
+/*
+ * `cf_callback_plugin'
+ * Start/end section `plugin'
+ *
+ * <Plugin `arguments'>
+ * ...
+ * </Plugin>
+ */
+int cf_callback_plugin (const char *shortvar, const char *var,
const char *arguments, const char *value, lc_flags_t flags,
void *extra)
{
}
}
-int cf_callback_loadmodule (const char *shortvar, const char *var,
+/*
+ * `cf_callback_plugin_dispatch'
+ * Send options within `plugin' sections to the plugin that requests it.
+ *
+ * <Plugin `current_module'>
+ * `var' `value'
+ * </Plugin>
+ */
+int cf_callback_plugin_dispatch (const char *shortvar, const char *var,
const char *arguments, const char *value, lc_flags_t flags,
void *extra)
{
DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
shortvar, var, arguments, value);
- if (nesting_depth == 0)
+ if ((nesting_depth == 0) || (current_module == NULL))
{
fprintf (stderr, ERR_NEEDS_SECTION, shortvar);
return (LC_CBRET_ERROR);
}
- if (plugin_load (value))
- syslog (LOG_ERR, "plugin_load (%s): failed to load plugin", shortvar);
+ /* Send the data to the plugin */
+ if (cf_dispatch (current_module, shortvar, value) < 0)
+ return (LC_CBRET_ERROR);
- /* Return `okay' even if there was an error, because it's not a syntax
- * problem.. */
return (LC_CBRET_OKAY);
}
if (filename == NULL)
filename = CONFIGFILE;
+ lc_register_callback ("Client", 'c', LC_VAR_NONE,
+ cf_callback_mode_switch, NULL);
+ lc_register_callback ("Local", 'l', LC_VAR_NONE,
+ cf_callback_mode_switch, NULL);
+ lc_register_callback ("Server", 's', LC_VAR_NONE,
+ cf_callback_mode_switch, NULL);
+
lc_register_callback ("Mode", SHORTOPT_NONE, LC_VAR_SECTION,
- cf_callback_section_mode, NULL);
+ cf_callback_mode, NULL);
lc_register_callback ("Plugin", SHORTOPT_NONE, LC_VAR_SECTION,
- cf_callback_section_module, NULL);
+ cf_callback_plugin, NULL);
+ lc_register_callback ("Mode.PluginDir", 'P',
+ LC_VAR_STRING, cf_callback_mode_plugindir, NULL);
lc_register_callback ("Mode.LoadPlugin", SHORTOPT_NONE,
- LC_VAR_STRING, cf_callback_loadmodule,
- NULL);
+ LC_VAR_STRING, cf_callback_mode_loadmodule, NULL);
for (i = 0; i < cf_mode_num; i++)
{
continue;
lc_register_callback (longvar, SHORTOPT_NONE, LC_VAR_STRING,
- cf_callback_options_mode, (void *) item);
+ cf_callback_mode_option, (void *) item);
}
if (lc_process_file ("collectd", filename, LC_CONF_APACHE))
diff --git a/src/plugin.c b/src/plugin.c
index ce4c943753526eff1889bb1600ac1d036cac3733..abc08e579688e179889ca14d88f32a2fd812a9b2 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
return (plugindir);
}
-void plugin_set_dir (char *dir)
+void plugin_set_dir (const char *dir)
{
if (plugindir != NULL)
free (plugindir);
diff --git a/src/plugin.h b/src/plugin.h
index 8749327ab8cc900b9c6030c4a64c5d213e922d7f..a07c205a66c47bc67fd445ea49767a01c9a89993 100644 (file)
--- a/src/plugin.h
+++ b/src/plugin.h
* NOTES
* If `dir' is NULL the compiled in default `PLUGINDIR' is used.
*/
-void plugin_set_dir (char *dir);
+void plugin_set_dir (const char *dir);
/*
* NAME