Migrated attr_sql_plugin_t to INIT/METHOD macros
authorAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 25 Nov 2010 21:49:44 +0000 (22:49 +0100)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 25 Nov 2010 21:49:44 +0000 (22:49 +0100)
src/libhydra/plugins/attr_sql/attr_sql_plugin.c

index 70e7a22..ac0304d 100644 (file)
@@ -43,10 +43,8 @@ struct private_attr_sql_plugin_t {
 
 };
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(private_attr_sql_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       private_attr_sql_plugin_t *this)
 {
        hydra->attributes->remove_provider(hydra->attributes, &this->attribute->provider);
        this->attribute->destroy(this->attribute);
@@ -59,21 +57,26 @@ static void destroy(private_attr_sql_plugin_t *this)
  */
 plugin_t *attr_sql_plugin_create()
 {
-       char *uri;
        private_attr_sql_plugin_t *this;
+       char *uri;
 
-       uri = lib->settings->get_str(lib->settings, "libhydra.plugins.attr-sql.database", NULL);
+       uri = lib->settings->get_str(lib->settings, "libhydra.plugins.attr-sql.database",
+                                                                                                NULL);
        if (!uri)
        {
                DBG1(DBG_CFG, "attr-sql plugin: database URI not set");
                return NULL;
        }
 
-       this = malloc_thing(private_attr_sql_plugin_t);
-
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy
+                       },
+               },
+               .db = lib->db->create(lib->db, uri)
+       );
 
-       this->db = lib->db->create(lib->db, uri);
        if (!this->db)
        {
                DBG1(DBG_CFG, "attr-sql plugin failed to connect to database");