[svn] commit: r88 - in /experiments/jelte-configuration: Makefile.in config_manager.cc config_module.cc config_module.hh config_obj.cc config_obj.hh example_module.cc example_module.hh myconf.conf
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Oct 15 13:57:49 UTC 2009
Author: jelte
Date: Thu Oct 15 13:57:49 2009
New Revision: 88
Log:
some small additions to config_obj
added a prototype idea for the module side of the configuration manager;
there is a base class config_module, which modules can extend in their specific config handling code, which will handle all actual communication and update-checking. example_module is an example of how this could work (though neither do much at this point)
Added:
experiments/jelte-configuration/config_module.cc
experiments/jelte-configuration/config_module.hh
experiments/jelte-configuration/example_module.cc
experiments/jelte-configuration/example_module.hh
Modified:
experiments/jelte-configuration/Makefile.in
experiments/jelte-configuration/config_manager.cc
experiments/jelte-configuration/config_obj.cc
experiments/jelte-configuration/config_obj.hh
experiments/jelte-configuration/myconf.conf
Modified: experiments/jelte-configuration/Makefile.in
==============================================================================
--- experiments/jelte-configuration/Makefile.in (original)
+++ experiments/jelte-configuration/Makefile.in Thu Oct 15 13:57:49 2009
@@ -14,17 +14,23 @@
# $Id$
-CFLAGS = @CFLAGS@
+CFLAGS = @CFLAGS@ -Wall -Werror
LDFLAGS = @LDFLAGS@
-all: config_manager
+all: config_manager config_module.o example_module
config_manager: config_manager.cc config_obj.o
- $(CXX) -g $(CFLAGS) $(LDFLAGS) -lxerces-c -o config_manager \
+ $(CXX) $(CFLAGS) $(LDFLAGS) -lxerces-c -o config_manager \
config_obj.o config_manager.cc
config_obj.o: config_obj.cc config_obj.hh
- $(CXX) -g $(CFLAGS) -c -o config_obj.o config_obj.cc
+ $(CXX) $(CFLAGS) -c -o config_obj.o config_obj.cc
+
+config_module.o: config_obj.o config_module.cc config_module.hh
+ $(CXX) $(CFLAGS) -c -o config_module.o config_module.cc
+
+example_module: config_module.o example_module.hh example_module.cc
+ $(CXX) $(CFLAGS) -o example_module -l xerces-c config_module.o config_obj.o example_module.cc
clean:
rm -f config_manager *.o myconf_new.conf
Modified: experiments/jelte-configuration/config_manager.cc
==============================================================================
--- experiments/jelte-configuration/config_manager.cc (original)
+++ experiments/jelte-configuration/config_manager.cc Thu Oct 15 13:57:49 2009
@@ -125,8 +125,8 @@
Config *config_part;
config_part = config->get_config_part("/module[@name=recursive]/zones/zone[@name=theo.com]");
- cout << "Selected zone configuration: " << endl;
- config_part->write_stream(std::cout);
+ //cout << "Selected zone configuration: " << endl;
+ //config_part->write_stream(std::cout);
cout << "Changing file to /tmp/myfile" << endl;
config_part->set_value("/file", "/tmp/myfile");
@@ -152,8 +152,8 @@
cout << "Remove the 'foo' element" << endl;
config_part2->remove_element("/foo");
- cout << "Selected zone configuration now: " << endl;
- config_part2->write_stream(std::cout);
+ //cout << "Selected zone configuration now: " << endl;
+ //config_part2->write_stream(std::cout);
cout << endl;
Modified: experiments/jelte-configuration/config_obj.cc
==============================================================================
--- experiments/jelte-configuration/config_obj.cc (original)
+++ experiments/jelte-configuration/config_obj.cc Thu Oct 15 13:57:49 2009
@@ -8,6 +8,8 @@
#include <xercesc/util/XMLString.hpp>
#include <xercesc/sax/HandlerBase.hpp>
#include <xercesc/framework/MemBufInputSource.hpp>
+
+#include <boost/algorithm/string.hpp>
using namespace xercesc;
@@ -35,7 +37,8 @@
XMLSize_t size;
/* code to read stream into the source goes here */
-
+ bytes = NULL;
+ size = 0;
MemBufInputSource *in_source = new MemBufInputSource(bytes, size, buf_id);
return in_source;
}
@@ -70,7 +73,7 @@
return false;
}
if (identifier.at(0) == '/') {
- int end_pos = identifier.find_first_of("/@[", 1);
+ size_t end_pos = identifier.find_first_of("/@[", 1);
if (end_pos == std::string::npos) {
new_identifier = identifier.substr(1);
} else {
@@ -78,8 +81,8 @@
if (identifier.length() > end_pos) {
if (identifier.at(end_pos) == '[') {
- int sel_eq_pos = identifier.find_first_of('=', end_pos);
- int sel_end_pos = identifier.find_first_of(']', end_pos);
+ size_t sel_eq_pos = identifier.find_first_of('=', end_pos);
+ size_t sel_end_pos = identifier.find_first_of(']', end_pos);
// selector is name=value pair, name can be another identifier
// or an attribute of the current.
if (sel_eq_pos == std::string::npos || sel_end_pos == std::string::npos) {
@@ -96,9 +99,22 @@
} else if (identifier.at(0) == '@') {
attribute = identifier.substr(1);
}
+ return true;
}
namespace ISC { namespace Config {
+
+ void
+ MyErrorHandler::error(const SAXParseException &exc) {
+ // for now this is just a placeholder
+ std::cout << "error on line " << exc.getLineNumber() << ": "
+ << xmlstring_to_string(exc.getMessage()) << std::endl;
+ }
+ void
+ MyErrorHandler::warning(const SAXParseException &exc) {
+ // for now this is just a placeholder
+ std::cout << "warning!" << std::endl;
+ }
Config::Config(std::string filename)
{
@@ -133,6 +149,28 @@
return get_node_value(n);
}
+ int
+ Config::get_int_value() {
+ return get_node_int_value(node);
+ }
+
+ int
+ Config::get_int_value(std::string identifier) {
+ DOMNode *n = find_sub_node(node, identifier);
+ return get_node_int_value(n);
+ }
+
+ bool
+ Config::get_bool_value() {
+ return get_node_bool_value(node);
+ }
+
+ bool
+ Config::get_bool_value(std::string identifier) {
+ DOMNode *n = find_sub_node(node, identifier);
+ return get_node_bool_value(n);
+ }
+
void
Config::set_value(std::string const &value) {
set_node_value(node, value);
@@ -176,10 +214,10 @@
/* we could set validation scheme and/or namespaces here */
parser->setValidationScheme(XercesDOMParser::Val_Always);
- ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
+ ErrorHandler* errHandler = (ErrorHandler*) new MyErrorHandler();
parser->setErrorHandler(errHandler);
/* this will probably not work until we have a dtd */
- parser->setIncludeIgnorableWhitespace(false);
+ parser->setIncludeIgnorableWhitespace(true);
try {
parser->parse(filename.c_str());
@@ -393,10 +431,21 @@
}
}
+ int
+ Config::get_node_int_value(const DOMNode *n)
+ {
+ return atoi(get_node_value(n).c_str());
+ }
+
+ bool
+ Config::get_node_bool_value(const DOMNode *n)
+ {
+ return (boost::iequals(get_node_value(n), "true"));
+ }
+
void
Config::set_node_value(DOMNode *n, std::string const &value)
{
- DOMNode *c;
XMLCh *xml_str;
if (!n) {
@@ -406,9 +455,10 @@
* element, or one with only one text child */
if (n->getNodeType() == n->ATTRIBUTE_NODE ||
(n->getNodeType() == n->ELEMENT_NODE &&
- !n->hasChildNodes() ||
- (n->getFirstChild() == n->getLastChild() &&
- n->getFirstChild()->getNodeType() == n->TEXT_NODE
+ (!n->hasChildNodes() ||
+ (n->getFirstChild() == n->getLastChild() &&
+ n->getFirstChild()->getNodeType() == n->TEXT_NODE
+ )
)
)
) {
Modified: experiments/jelte-configuration/config_obj.hh
==============================================================================
--- experiments/jelte-configuration/config_obj.hh (original)
+++ experiments/jelte-configuration/config_obj.hh Thu Oct 15 13:57:49 2009
@@ -60,6 +60,7 @@
#include <xercesc/dom/DOM.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
+#include <xercesc/sax/HandlerBase.hpp>
namespace ISC { namespace Config {
@@ -78,6 +79,14 @@
std::string msg;
};
+ class MyErrorHandler : public xercesc::HandlerBase {
+ public:
+ void error(const xercesc::SAXParseException& exc);
+ void warning(const xercesc::SAXParseException& exc);
+ };
+
+
+
class Config {
/* base node for this configuration of configuration part */;
xercesc::DOMNode *node;
@@ -109,6 +118,7 @@
/* returns the name of the base node */
std::string get_name();
+
/* returns the value of the base node.
* If the base node is not an attribute node or an
* element node with only one text node child, a
@@ -120,6 +130,15 @@
* a ConfigError exception is thrown
*/
std::string get_value(std::string identifier);
+
+ /* returns the int value of the base node.
+ * If the value cannot be converted to an int, 0 is returned
+ */
+ int get_int_value();
+ int get_int_value(std::string identifier);
+
+ bool get_bool_value();
+ bool get_bool_value(std::string identifier);
/* sets the value of the base node.
* If the base node is not an attribute node or an
@@ -214,6 +233,9 @@
std::string get_node_name(const xercesc::DOMNode *n);
/* Returns the value of a specific DOMNode */
std::string get_node_value(const xercesc::DOMNode *n);
+ int get_node_int_value(const xercesc::DOMNode *n);
+ bool get_node_bool_value(const xercesc::DOMNode *n);
+
/* Sets the value of a specific DOMNode */
void set_node_value(xercesc::DOMNode *n, std::string const &value);
Modified: experiments/jelte-configuration/myconf.conf
==============================================================================
--- experiments/jelte-configuration/myconf.conf (original)
+++ experiments/jelte-configuration/myconf.conf Thu Oct 15 13:57:49 2009
@@ -1,6 +1,9 @@
<?xml version="1.0"?>
-<config>
+<config xmlns="http://www.isc.org/BIND10/config"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+xsi:schemaLocation="http://www.isc.org/BIND10/config config_schema.xsd">
<module name="authoritative">
+<!--
<listen-port>53</listen-port>
<zones>
<zone name="tjeb.nl">
@@ -10,8 +13,9 @@
<zone name="theo.com">
<type>master</type>
<file>/var/zones/theo.com</file>
- <foo>bar</foo>
+ <foo>bar</foo>
</zone>
</zones>
+-->
</module>
</config>
More information about the bind10-changes
mailing list