attr-sql: Use namespace for attr-sql config, with fallback
authorTobias Brunner <tobias@strongswan.org>
Tue, 28 Jan 2014 15:58:34 +0000 (16:58 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 12 Feb 2014 13:34:32 +0000 (14:34 +0100)
src/libhydra/plugins/attr_sql/attr_sql_plugin.c
src/libhydra/plugins/attr_sql/sql_attribute.c
src/pool/pool.c

index 702872c..dde9005 100644 (file)
@@ -61,7 +61,7 @@ static bool open_database(private_attr_sql_plugin_t *this,
                char *uri;
 
                uri = lib->settings->get_str(lib->settings,
-                                                               "libhydra.plugins.attr-sql.database", NULL);
+                                                               "%s.plugins.attr-sql.database", NULL, lib->ns);
                if (!uri)
                {
                        DBG1(DBG_CFG, "attr-sql plugin: database URI not set");
@@ -122,6 +122,8 @@ plugin_t *attr_sql_plugin_create()
                        },
                },
        );
+       lib->settings->add_fallback(lib->settings, "%s.plugins.attr-sql",
+                                                               "libhydra.plugins.attr-sql", lib->ns);
 
        return &this->public.plugin;
 }
index 0a06c41..d527c3f 100644 (file)
@@ -457,7 +457,7 @@ sql_attribute_t *sql_attribute_create(database_t *db)
                },
                .db = db,
                .history = lib->settings->get_bool(lib->settings,
-                                                       "libhydra.plugins.attr-sql.lease_history", TRUE),
+                                                       "%s.plugins.attr-sql.lease_history", TRUE, lib->ns),
        );
 
        /* close any "online" leases in the case we crashed */
index cc58f78..2659748 100644 (file)
@@ -1227,11 +1227,16 @@ int main(int argc, char *argv[])
        {
                exit(SS_RC_INITIALIZATION_FAILED);
        }
-
-       uri = lib->settings->get_str(lib->settings, "libhydra.plugins.attr-sql.database", NULL);
+       /* TODO: make database URI or setting key configurable via command line */
+       uri = lib->settings->get_str(lib->settings,
+                       "pool.database",
+                       lib->settings->get_str(lib->settings,
+                               "charon.plugins.attr-sql.database",
+                               lib->settings->get_str(lib->settings,
+                                       "libhydra.plugins.attr-sql.database", NULL)));
        if (!uri)
        {
-               fprintf(stderr, "database URI libhydra.plugins.attr-sql.database not set.\n");
+               fprintf(stderr, "database URI pool.database not set.\n");
                exit(SS_RC_INITIALIZATION_FAILED);
        }
        db = lib->db->create(lib->db, uri);