Code

plugin: Made plugin context a dynamic object.
[sysdb.git] / src / daemon / config.c
index 2975e06fa7d218393907bbcd770809d6689353ff..76955050837b2714011252e74e6dda78e7b660bc 100644 (file)
@@ -27,8 +27,8 @@
 
 #include "sysdb.h"
 #include "core/plugin.h"
-#include "utils/error.h"
-#include "utils/time.h"
+#include "core/error.h"
+#include "core/time.h"
 
 #include "daemon/config.h"
 
@@ -58,13 +58,13 @@ config_get_interval(oconfig_item_t *ci, sdb_time_t *interval)
        if (oconfig_get_number(ci, &interval_dbl)) {
                sdb_log(SDB_LOG_ERR, "config: Interval requires "
                                "a single numeric argument\n"
-                               "\tUsage: Interval SECONDS\n");
+                               "\tUsage: Interval SECONDS");
                return -1;
        }
 
        if (interval_dbl <= 0.0) {
                sdb_log(SDB_LOG_ERR, "config: Invalid interval: %f\n"
-                               "\tInterval may not be less than or equal to zero.\n",
+                               "\tInterval may not be less than or equal to zero.",
                                interval_dbl);
                return -1;
        }
@@ -88,6 +88,39 @@ daemon_set_interval(oconfig_item_t *ci)
        return config_get_interval(ci, &default_interval);
 } /* daemon_set_interval */
 
+static int
+daemon_load_plugin(oconfig_item_t *ci)
+{
+       char *name;
+
+       sdb_plugin_ctx_t ctx = SDB_PLUGIN_CTX_INIT;
+       sdb_plugin_ctx_t old_ctx;
+
+       int status, i;
+
+       if (oconfig_get_string(ci, &name)) {
+               sdb_log(SDB_LOG_ERR, "config: LoadPlugin requires a single "
+                               "string argument\n"
+                               "\tUsage: LoadPlugin PLUGIN");
+               return -1;
+       }
+
+       for (i = 0; i < ci->children_num; ++i) {
+               oconfig_item_t *child = ci->children + i;
+
+               /* we don't currently support any options */
+               sdb_log(SDB_LOG_WARNING, "config: Unknown option '%s' "
+                               "inside 'LoadPlugin' -- see the documentation for "
+                               "details.", child->key);
+               continue;
+       }
+
+       old_ctx = sdb_plugin_set_ctx(ctx);
+       status = sdb_plugin_load(name);
+       sdb_plugin_set_ctx(old_ctx);
+       return status;
+} /* daemon_load_plugin */
+
 static int
 daemon_load_backend(oconfig_item_t *ci)
 {
@@ -104,11 +137,11 @@ daemon_load_backend(oconfig_item_t *ci)
        if (oconfig_get_string(ci, &name)) {
                sdb_log(SDB_LOG_ERR, "config: LoadBackend requires a single "
                                "string argument\n"
-                               "\tUsage: LoadBackend BACKEND\n");
+                               "\tUsage: LoadBackend BACKEND");
                return -1;
        }
 
-       snprintf(plugin_name, sizeof(plugin_name), "backend/%s", name);
+       snprintf(plugin_name, sizeof(plugin_name), "backend::%s", name);
 
        for (i = 0; i < ci->children_num; ++i) {
                oconfig_item_t *child = ci->children + i;
@@ -120,7 +153,7 @@ daemon_load_backend(oconfig_item_t *ci)
                else {
                        sdb_log(SDB_LOG_WARNING, "config: Unknown option '%s' "
                                        "inside 'LoadBackend' -- see the documentation for "
-                                       "details.\n", child->key);
+                                       "details.", child->key);
                        continue;
                }
        }
@@ -141,7 +174,7 @@ daemon_configure_plugin(oconfig_item_t *ci)
        if (oconfig_get_string(ci, &name)) {
                sdb_log(SDB_LOG_ERR, "config: %s requires a single "
                                "string argument\n"
-                               "\tUsage: LoadBackend BACKEND\n",
+                               "\tUsage: LoadBackend BACKEND",
                                ci->key);
                return -1;
        }
@@ -151,6 +184,7 @@ daemon_configure_plugin(oconfig_item_t *ci)
 
 static token_parser_t token_parser_list[] = {
        { "Interval", daemon_set_interval },
+       { "LoadPlugin", daemon_load_plugin },
        { "LoadBackend", daemon_load_backend },
        { "Backend", daemon_configure_plugin },
        { "Plugin", daemon_configure_plugin },
@@ -187,6 +221,7 @@ daemon_parse_config(const char *filename)
                                sdb_error_append("\tUnknown option '%s' -- "
                                                "see the documentation for details\n",
                                                child->key);
+                       sdb_error_chomp();
                        sdb_error_log(SDB_LOG_ERR);
                        retval = -1;
                }