Browse Source

simple example to set the database file in auth (which is seen and remembered, but not passed on to the sqlite3datasource yet)
we should look for a decent way to do this without needing a global auth variable (jinmei has some ideas)


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1003 e5f2f494-b856-4b98-b285-d166d9295462

Jelte Jansen 15 years ago
parent
commit
29c5ffbd6c

+ 2 - 2
src/bin/auth/auth.spec

@@ -2,10 +2,10 @@
   "module_spec": {
     "module_name": "Auth",
     "config_data": [
-      { "item_name": "default_name",
+      { "item_name": "database_file",
         "item_type": "string",
         "item_optional": False,
-        "item_default": "Hello, world!"
+        "item_default": "b10-auth.db"
       },
       { "item_name": "zone_list",
         "item_type": "list",

+ 19 - 9
src/bin/auth/auth_srv.cc

@@ -125,16 +125,26 @@ AuthSrv::processMessage() {
     }
 }
 
+void
+AuthSrv::setDbFile(const std::string& db_file)
+{
+    if (_db_file != db_file) {
+        cout << "Change data source file, call our data source's function to now read " << db_file << endl;
+        _db_file = db_file;
+    }
+}
+
 ElementPtr
-AuthSrv::updateConfig(isc::data::ElementPtr config) {
-    //if (config->contains("port")) {
-        // todo: what to do with port change. restart automatically?
-        // ignore atm
-    //}
-    if (config) {
-        std::cout << "[XX] auth: new config " << config << std::endl;
-    } else {
-        std::cout << "[XX] auth: new config empty" << std::endl;
+AuthSrv::updateConfig(isc::data::ElementPtr new_config) {
+    if (new_config) {
+        // the ModuleCCSession has already checked if we have
+        // the correct ElementPtr type as specified in our .spec file
+        if (new_config->contains("database_file")) {
+            // Since we also get this value if it hasn't changed,
+            // but is non-default, setDbFile here should only really
+            // do anything if it has actually changed
+            setDbFile(new_config->get("database_file")->stringValue());
+        }
     }
     
     return isc::config::createAnswer(0);

+ 3 - 2
src/bin/auth/auth_srv.h

@@ -27,10 +27,11 @@ public:
     int getSocket() { return (sock); }
     void processMessage();
     void serve(std::string zone_name);
-
+    void setDbFile(const std::string& db_file);
     isc::data::ElementPtr updateConfig(isc::data::ElementPtr config);
 private:
-
+    std::string _db_file;
+    
     isc::auth::MetaDataSrc data_src;
     int sock;
 };

+ 4 - 3
src/bin/auth/main.cc

@@ -57,9 +57,10 @@ usage() {
 }
 
 isc::data::ElementPtr
-my_config_handler(isc::data::ElementPtr config)
+my_config_handler(isc::data::ElementPtr new_config)
 {
-    return auth.updateConfig(config);
+    auth.updateConfig(new_config);
+    return isc::config::createAnswer(0);
 }
 
 isc::data::ElementPtr
@@ -106,7 +107,7 @@ main(int argc, char* argv[]) {
         isc::config::ModuleCCSession cs = isc::config::ModuleCCSession(specfile,
                                                                        my_config_handler,
                                                                        my_command_handler);
-    
+
         // main server loop
         fd_set fds;
         int ps = auth.getSocket();

+ 1 - 1
src/lib/config/cpp/ccsession.h

@@ -75,7 +75,7 @@ public:
      * 100000 zones, where the whole list is passed every time a single
      * thing changes)
      */
-    void set_config_handler(isc::data::ElementPtr(*config_handler)(isc::data::ElementPtr new_config)) { config_handler_ = config_handler; };
+    void setConfigHandler(isc::data::ElementPtr(*config_handler)(isc::data::ElementPtr new_config)) { config_handler_ = config_handler; };
 
     /**
      * Set a command handler; the function that is passed takes an