[svn] commit: r1536 - in /trunk: configure.ac src/bin/auth/Makefile.am src/bin/auth/auth.pre.in src/bin/auth/auth.spec src/bin/auth/auth_srv.cc src/bin/auth/auth_srv.h src/bin/auth/main.cc src/lib/auth/sqlite3_datasrc.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Mar 18 20:17:56 UTC 2010
Author: each
Date: Thu Mar 18 20:17:56 2010
New Revision: 1536
Log:
Make b10-auth use a default database path from auth.spec rather than
/tmp/zone.sqlite3.
Added:
trunk/src/bin/auth/auth.pre.in
- copied, changed from r1515, trunk/src/bin/auth/auth.spec
Removed:
trunk/src/bin/auth/auth.spec
Modified:
trunk/configure.ac
trunk/src/bin/auth/Makefile.am
trunk/src/bin/auth/auth_srv.cc
trunk/src/bin/auth/auth_srv.h
trunk/src/bin/auth/main.cc
trunk/src/lib/auth/sqlite3_datasrc.cc
Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Thu Mar 18 20:17:56 2010
@@ -306,6 +306,7 @@
src/bin/msgq/msgq.py
src/bin/msgq/msgq_test
src/bin/msgq/run_msgq.sh
+ src/bin/auth/auth.pre
src/bin/auth/spec_config.h
src/lib/config/tests/data_def_unittests_config.h
src/lib/python/isc/config/tests/config_test
Modified: trunk/src/bin/auth/Makefile.am
==============================================================================
--- trunk/src/bin/auth/Makefile.am (original)
+++ trunk/src/bin/auth/Makefile.am Thu Mar 18 20:17:56 2010
@@ -9,10 +9,10 @@
pkglibexecdir = $(libexecdir)/@PACKAGE@
-CLEANFILES = *.gcno *.gcda
+CLEANFILES = *.gcno *.gcda auth.pre auth.spec
man_MANS = b10-auth.8
-EXTRA_DIST = $(man_MANS) b10-auth.xml
+EXTRA_DIST = $(man_MANS) b10-auth.xml auth.spec
if ENABLE_MAN
@@ -20,6 +20,9 @@
xsltproc --novalid --xinclude --nonet -o $@ http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $(srcdir)/b10-auth.xml
endif
+
+auth.spec: auth.pre
+ $(SED) -e "s|@@LOCALSTATEDIR@@|$(localstatedir)|" auth.pre >$@
pkglibexec_PROGRAMS = b10-auth
b10_auth_SOURCES = auth_srv.cc auth_srv.h
Modified: trunk/src/bin/auth/auth_srv.cc
==============================================================================
--- trunk/src/bin/auth/auth_srv.cc (original)
+++ trunk/src/bin/auth/auth_srv.cc Thu Mar 18 20:17:56 2010
@@ -65,11 +65,12 @@
isc::data::ElementPtr setDbFile(const isc::data::ElementPtr config);
std::string db_file_;
- isc::auth::MetaDataSrc data_sources_;
+ ModuleCCSession* cs_;
+ MetaDataSrc data_sources_;
/// We keep a pointer to the currently running sqlite datasource
/// so that we can specifically remove that one should the database
/// file change
- isc::auth::ConstDataSrcPtr cur_datasrc_;
+ ConstDataSrcPtr cur_datasrc_;
bool verbose_mode_;
@@ -77,17 +78,18 @@
static const uint16_t DEFAULT_LOCAL_UDPSIZE = 4096;
};
-AuthSrvImpl::AuthSrvImpl() : verbose_mode_(false) {
+AuthSrvImpl::AuthSrvImpl() : cs_(NULL), verbose_mode_(false)
+{
// cur_datasrc_ is automatically initialized by the default constructor,
// effectively being an empty (sqlite) data source. once ccsession is up
// the datasource will be set by the configuration setting
- // (or the default one if none is set)
// add static data source
data_sources_.addDataSrc(ConstDataSrcPtr(new StaticDataSrc));
}
-AuthSrv::AuthSrv() : impl_(new AuthSrvImpl) {}
+AuthSrv::AuthSrv() : impl_(new AuthSrvImpl) {
+}
AuthSrv::~AuthSrv() {
delete impl_;
@@ -154,6 +156,16 @@
return (impl_->verbose_mode_);
}
+void
+AuthSrv::setConfigSession(ModuleCCSession* cs) {
+ impl_->cs_ = cs;
+}
+
+ModuleCCSession*
+AuthSrv::configSession() const {
+ return (impl_->cs_);
+}
+
bool
AuthSrv::processMessage(InputBuffer& request_buffer, Message& message,
MessageRenderer& response_renderer,
@@ -251,23 +263,34 @@
ElementPtr
AuthSrvImpl::setDbFile(const isc::data::ElementPtr config) {
- if (config) {
+ ElementPtr answer = isc::config::createAnswer();
+ ElementPtr final;
+
+ if (config && config->contains("database_file")) {
db_file_ = config->get("database_file")->stringValue();
- if (verbose_mode_) {
- cerr << "[AuthSrv] Data source database file: " << db_file_ << endl;
- }
+ final = config;
+ } else if (cs_ != NULL) {
+ bool is_default;
+ string item("database_file");
+ ElementPtr value = cs_->getValue(is_default, item);
+ db_file_ = value->stringValue();
+ final = Element::createFromString("{}");
+ final->set(item, value);
+ } else {
+ return (answer);
+ }
+
+ if (verbose_mode_) {
+ cerr << "[AuthSrv] Data source database file: " << db_file_ << endl;
}
// create SQL data source
- // config may be empty here; in that case it will load the default
- // database file
// Note: the following step is tricky to be exception-safe and to ensure
// exception guarantee: We first need to perform all operations that can
// fail, while acquiring resources in the RAII manner. We then perform
// delete and swap operations which should not fail.
DataSrcPtr datasrc_ptr(DataSrcPtr(new Sqlite3DataSrc));
- datasrc_ptr->init(config);
- ElementPtr answer = isc::config::createAnswer();
+ datasrc_ptr->init(final);
data_sources_.addDataSrc(datasrc_ptr);
// The following code should be exception free.
@@ -276,26 +299,17 @@
}
cur_datasrc_ = datasrc_ptr;
- return answer;
+ return (answer);
}
ElementPtr
AuthSrv::updateConfig(isc::data::ElementPtr new_config) {
try {
+ // the ModuleCCSession has already checked if we have
+ // the correct ElementPtr type as specified in our .spec file
ElementPtr answer = isc::config::createAnswer();
- if (new_config != NULL) {
- // the ModuleCCSession has already checked if we have
- // the correct ElementPtr type as specified in our .spec file
- if (new_config->contains("database_file")) {
- answer = impl_->setDbFile(new_config);
- }
- }
-
- // if we have no sqlite3 data source, use the default
- if (impl_->cur_datasrc_ == NULL) {
- impl_->setDbFile(ElementPtr());
- }
-
+ answer = impl_->setDbFile(new_config);
+
return answer;
} catch (const isc::Exception& error) {
if (impl_->verbose_mode_) {
Modified: trunk/src/bin/auth/auth_srv.h
==============================================================================
--- trunk/src/bin/auth/auth_srv.h (original)
+++ trunk/src/bin/auth/auth_srv.h Thu Mar 18 20:17:56 2010
@@ -20,6 +20,7 @@
#include <string>
#include <cc/data.h>
+#include <config/ccsession.h>
namespace isc {
namespace dns {
@@ -55,6 +56,8 @@
bool getVerbose() const;
void serve(std::string zone_name);
isc::data::ElementPtr updateConfig(isc::data::ElementPtr config);
+ isc::config::ModuleCCSession* configSession() const;
+ void setConfigSession(isc::config::ModuleCCSession* cs);
private:
AuthSrvImpl* impl_;
};
Modified: trunk/src/bin/auth/main.cc
==============================================================================
--- trunk/src/bin/auth/main.cc (original)
+++ trunk/src/bin/auth/main.cc Thu Mar 18 20:17:56 2010
@@ -332,13 +332,10 @@
void
run_server(const char* port, const bool use_ipv4, const bool use_ipv6,
- const string& specfile)
+ AuthSrv* srv)
{
ServerSet servers;
short portnum = atoi(port);
-
- ModuleCCSession cs(specfile, io_service_, my_config_handler,
- my_command_handler);
if (use_ipv4) {
servers.udp4_server = new UDPServer(io_service_, AF_INET, portnum);
@@ -554,7 +551,7 @@
void
run_server(const char* port, const bool use_ipv4, const bool use_ipv6,
- const string& specfile)
+ AuthSrv* srv)
{
SocketSet socket_set;
fd_set fds_base;
@@ -579,11 +576,13 @@
}
++nfds;
- ModuleCCSession cs(specfile, my_config_handler, my_command_handler);
-
cout << "Server started." << endl;
- int ss = cs.getSocket();
+ if (srv->configSession() == NULL) {
+ isc_throw(FatalError, "Config session not initalized");
+ }
+
+ int ss = srv->configSession()->getSocket();
Message dns_message(Message::PARSE);
OutputBuffer resonse_buffer(0);
MessageRenderer response_renderer(resonse_buffer);
@@ -615,7 +614,7 @@
processMessageTCP(socket_set.tps6, dns_message, response_renderer);
}
if (FD_ISSET(ss, &fds)) {
- cs.checkCommand();
+ srv->configSession()->checkCommand();
}
}
}
@@ -668,9 +667,6 @@
usage();
}
- auth_server = new AuthSrv;
- auth_server->setVerbose(verbose_mode);
-
// initialize command channel
int ret = 0;
try {
@@ -682,7 +678,20 @@
specfile = string(AUTH_SPECFILE_LOCATION);
}
- run_server(port, use_ipv4, use_ipv6, specfile);
+ auth_server = new AuthSrv;
+ auth_server->setVerbose(verbose_mode);
+
+#ifdef HAVE_BOOSTLIB
+ ModuleCCSession cs(specfile, io_service_, my_config_handler,
+ my_command_handler);
+#else
+ ModuleCCSession cs(specfile, my_config_handler, my_command_handler);
+#endif
+
+ auth_server->setConfigSession(&cs);
+ auth_server->updateConfig(ElementPtr());
+
+ run_server(port, use_ipv4, use_ipv6, auth_server);
} catch (const std::exception& ex) {
cerr << ex.what() << endl;
ret = 1;
Modified: trunk/src/lib/auth/sqlite3_datasrc.cc
==============================================================================
--- trunk/src/lib/auth/sqlite3_datasrc.cc (original)
+++ trunk/src/lib/auth/sqlite3_datasrc.cc Thu Mar 18 20:17:56 2010
@@ -54,10 +54,6 @@
};
namespace {
-// Note: this cannot be std::string to avoid
-// "static initialization order fiasco".
-const char* DEFAULT_DB_FILE = "/tmp/zone.sqlite3";
-
const char* const SCHEMA_LIST[] = {
"CREATE TABLE schema_version (version INTEGER NOT NULL)",
"INSERT INTO schema_version VALUES (1)",
@@ -567,7 +563,7 @@
if (config && config->contains("database_file")) {
open(config->get("database_file")->stringValue());
} else {
- open(DEFAULT_DB_FILE);
+ isc_throw(DataSourceError, "No sqlite3 database file specified");
}
return (SUCCESS);
}
More information about the bind10-changes
mailing list