Code

dbi utils: Use the new _r interface.
[sysdb.git] / src / backend / puppet / store-configs.c
index a9a0ff777e9d6f35bd364885832b485d1f88beef..c2f4d084048c71fbccb945b4f38dd753fda24d8d 100644 (file)
@@ -33,8 +33,6 @@
 
 #include "liboconfig/utils.h"
 
-#include <dbi/dbi.h>
-
 #include <assert.h>
 #include <errno.h>
 
@@ -87,7 +85,7 @@ sdb_puppet_stcfg_get_attrs(sdb_dbi_client_t __attribute__((unused)) *client,
 
        const char *hostname;
        const char *key;
-       const char *value;
+       sdb_data_t  value;
        sdb_time_t  last_update;
 
        assert(n == 4);
@@ -98,10 +96,11 @@ sdb_puppet_stcfg_get_attrs(sdb_dbi_client_t __attribute__((unused)) *client,
 
        hostname = data[0].data.string;
        key = data[1].data.string;
-       value = data[2].data.string;
+       value.type = SDB_TYPE_STRING;
+       value.data.string = data[2].data.string;
        last_update = data[3].data.datetime;
 
-       status = sdb_store_attribute(hostname, key, value, last_update);
+       status = sdb_store_attribute(hostname, key, &value, last_update);
 
        if (status < 0) {
                sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: Failed to "
@@ -137,6 +136,17 @@ sdb_puppet_stcfg_init(sdb_object_t *user_data)
        return 0;
 } /* sdb_puppet_stcfg_init */
 
+static int
+sdb_puppet_stcfg_shutdown(sdb_object_t *user_data)
+{
+       if (! user_data)
+               return -1;
+
+       sdb_dbi_client_destroy(SDB_OBJ_WRAPPER(user_data)->data);
+       SDB_OBJ_WRAPPER(user_data)->data = NULL;
+       return 0;
+} /* sdb_puppet_stcfg_shutdown */
+
 static int
 sdb_puppet_stcfg_collect(sdb_object_t *user_data)
 {
@@ -329,6 +339,8 @@ sdb_puppet_stcfg_config_conn(oconfig_item_t *ci)
        }
 
        sdb_plugin_register_init(cb_name, sdb_puppet_stcfg_init, user_data);
+       sdb_plugin_register_shutdown(cb_name, sdb_puppet_stcfg_shutdown,
+                       user_data);
        sdb_plugin_register_collector(cb_name, sdb_puppet_stcfg_collect,
                        /* interval */ NULL, user_data);
 
@@ -342,6 +354,9 @@ sdb_puppet_stcfg_config(oconfig_item_t *ci)
 {
        int i;
 
+       if (! ci) /* nothing to do to deconfigure this plugin */
+               return 0;
+
        for (i = 0; i < ci->children_num; ++i) {
                oconfig_item_t *child = ci->children + i;
 
@@ -366,13 +381,6 @@ sdb_module_init(sdb_plugin_info_t *info)
        sdb_plugin_set_info(info, SDB_PLUGIN_INFO_VERSION, SDB_VERSION);
        sdb_plugin_set_info(info, SDB_PLUGIN_INFO_PLUGIN_VERSION, SDB_VERSION);
 
-       if (dbi_initialize(/* driver dir = */ NULL) < 0) {
-               sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: failed to "
-                               "initialize DBI; possibly you don't have any drivers "
-                               "installed.");
-               return -1;
-       }
-
        sdb_plugin_register_config("puppet::store-configs",
                        sdb_puppet_stcfg_config);
        return 0;