X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fconfigfile.c;h=a5cdb1a6fdac84a09894be37e7f493ee72cc5237;hb=57d32cdea9ed71a34cfdf62e8b0050749486319e;hp=311ebb385f0c7602af02b5102f1cd0ce8126e17e;hpb=2f0dfdda8bc499fdb161c6a5850ec176e75bd4fa;p=collectd.git diff --git a/src/configfile.c b/src/configfile.c index 311ebb38..a5cdb1a6 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -1,6 +1,6 @@ /** * collectd - src/configfile.c - * Copyright (C) 2005,2006 Florian octo Forster + * Copyright (C) 2005-2008 Florian octo Forster * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -27,7 +27,6 @@ #include "common.h" #include "plugin.h" #include "configfile.h" -#include "network.h" #define ESCAPE_NULL(str) ((str) == NULL ? "(null)" : (str)) @@ -43,6 +42,13 @@ typedef struct cf_callback struct cf_callback *next; } cf_callback_t; +typedef struct cf_complex_callback_s +{ + char *type; + int (*callback) (oconfig_item_t *); + struct cf_complex_callback_s *next; +} cf_complex_callback_t; + typedef struct cf_value_map_s { char *key; @@ -60,19 +66,18 @@ typedef struct cf_global_option_s * Prototypes of callback functions */ static int dispatch_value_plugindir (const oconfig_item_t *ci); -static int dispatch_value_loadds (const oconfig_item_t *ci); static int dispatch_value_loadplugin (const oconfig_item_t *ci); /* * Private variables */ static cf_callback_t *first_callback = NULL; +static cf_complex_callback_t *complex_callback_head = NULL; static cf_value_map_t cf_value_map[] = { {"PluginDir", dispatch_value_plugindir}, - {"LoadPlugin", dispatch_value_loadplugin}, - {"LoadDS", dispatch_value_loadds} + {"LoadPlugin", dispatch_value_loadplugin} }; static int cf_value_map_num = STATIC_ARRAY_LEN (cf_value_map); @@ -82,7 +87,8 @@ static cf_global_option_t cf_global_options[] = {"PIDFile", NULL, PIDFILE}, {"Hostname", NULL, NULL}, {"Interval", NULL, "10"}, - {"ReadThreads", NULL, "5"} + {"ReadThreads", NULL, "5"}, + {"TypesDB", NULL, PLUGINDIR"/types.db"} /* FIXME: Configure path */ }; static int cf_global_options_num = STATIC_ARRAY_LEN (cf_global_options); @@ -120,7 +126,9 @@ static int cf_dispatch (const char *type, const char *orig_key, if ((cf_cb = cf_search (type)) == NULL) { - WARNING ("Plugin `%s' did not register a callback.", type); + WARNING ("Found a configuration for the `%s' plugin, but " + "the plugin isn't loaded or didn't register " + "a configuration callback.", type); return (-1); } @@ -184,18 +192,6 @@ static int dispatch_value_plugindir (const oconfig_item_t *ci) return (0); } -static int dispatch_value_loadds (const oconfig_item_t *ci) -{ - assert (strcasecmp (ci->key, "LoadDS") == 0); - - if (ci->values_num != 1) - return (-1); - if (ci->values[0].type != OCONFIG_TYPE_STRING) - return (-1); - - return (plugin_load (ci->values[0].value.string, MR_DATASETS)); -} /* int dispatch_value_loadds */ - static int dispatch_value_loadplugin (const oconfig_item_t *ci) { assert (strcasecmp (ci->key, "LoadPlugin") == 0); @@ -205,7 +201,7 @@ static int dispatch_value_loadplugin (const oconfig_item_t *ci) if (ci->values[0].type != OCONFIG_TYPE_STRING) return (-1); - return (plugin_load (ci->values[0].value.string, MR_EVERYTHING)); + return (plugin_load (ci->values[0].value.string)); } /* int dispatch_value_loadplugin */ static int dispatch_value_plugin (const char *plugin, oconfig_item_t *ci) @@ -271,21 +267,29 @@ static int dispatch_block_plugin (oconfig_item_t *ci) int i; char *name; + cf_complex_callback_t *cb; + if (strcasecmp (ci->key, "Plugin") != 0) return (-1); - if (ci->values_num != 1) + if (ci->values_num < 1) return (-1); if (ci->values[0].type != OCONFIG_TYPE_STRING) return (-1); name = ci->values[0].value.string; + /* Check for a complex callback first */ + for (cb = complex_callback_head; cb != NULL; cb = cb->next) + if (strcasecmp (name, cb->type) == 0) + return (cb->callback (ci)); + + /* Hm, no complex plugin found. Dispatch the values one by one */ for (i = 0; i < ci->children_num; i++) { if (ci->children[i].children == NULL) dispatch_value_plugin (name, ci->children + i); else - {DEBUG ("No nested config blocks allow for plugins. Yet.");} + {DEBUG ("No nested config blocks allow for this plugin.");} } return (0); @@ -361,6 +365,26 @@ void cf_unregister (const char *type) } } /* void cf_unregister */ +void cf_unregister_complex (const char *type) +{ + cf_complex_callback_t *this, *prev; + + for (prev = NULL, this = complex_callback_head; + this != NULL; + prev = this, this = this->next) + if (strcasecmp (this->type, type) == 0) + { + if (prev == NULL) + complex_callback_head = this->next; + else + prev->next = this->next; + + sfree (this->type); + sfree (this); + break; + } +} /* void cf_unregister */ + void cf_register (const char *type, int (*callback) (const char *, const char *), const char **keys, int keys_num) @@ -383,6 +407,39 @@ void cf_register (const char *type, first_callback = cf_cb; } /* void cf_register */ +int cf_register_complex (const char *type, int (*callback) (oconfig_item_t *)) +{ + cf_complex_callback_t *new; + + new = (cf_complex_callback_t *) malloc (sizeof (cf_complex_callback_t)); + if (new == NULL) + return (-1); + + new->type = strdup (type); + if (new->type == NULL) + { + sfree (new); + return (-1); + } + + new->callback = callback; + new->next = NULL; + + if (complex_callback_head == NULL) + { + complex_callback_head = new; + } + else + { + cf_complex_callback_t *last = complex_callback_head; + while (last->next != NULL) + last = last->next; + last->next = new; + } + + return (0); +} /* int cf_register_complex */ + int cf_read (char *filename) { oconfig_item_t *conf;