version 3.0
This commit is contained in:
commit
d837490606
209 changed files with 19662 additions and 0 deletions
0
config/Makefile
Normal file
0
config/Makefile
Normal file
144
config/config.cc
Normal file
144
config/config.cc
Normal file
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <config/config.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: config.cc //
|
||||
// Description: main configuration parser //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-04-01 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool
|
||||
Config::activate(const std::string& oname)
|
||||
{
|
||||
if (object_map_.find(oname) == object_map_.end()) {
|
||||
ERROR(log_) << "Object (" << oname << ") can not be activated as it does not exist.";
|
||||
return (false);
|
||||
}
|
||||
|
||||
ConfigObject *co = object_map_[oname];
|
||||
return (co->activate());
|
||||
}
|
||||
|
||||
bool
|
||||
Config::create(const std::string& cname, const std::string& oname)
|
||||
{
|
||||
if (class_map_.find(cname) == class_map_.end()) {
|
||||
ERROR(log_) << "Class (" << cname << ") not present.";
|
||||
return (false);
|
||||
}
|
||||
if (object_map_.find(oname) != object_map_.end()) {
|
||||
ERROR(log_) << "Refusing to create object (" << oname << ") twice.";
|
||||
return (false);
|
||||
}
|
||||
|
||||
ConfigClass *cc = class_map_[cname];
|
||||
|
||||
object_map_[oname] = new ConfigObject(this, oname, cc, cc->allocate());
|
||||
|
||||
return (true);
|
||||
}
|
||||
|
||||
bool
|
||||
Config::set(const std::string& oname, const std::string& mname,
|
||||
const std::string& vstr)
|
||||
{
|
||||
if (object_map_.find(oname) == object_map_.end()) {
|
||||
ERROR(log_) << "Can not set member value on object (" << oname << ") that does not exist.";
|
||||
return (false);
|
||||
}
|
||||
|
||||
ConfigObject *co = object_map_[oname];
|
||||
|
||||
#if 0
|
||||
ConfigType *ct = cc->member(mname);
|
||||
if (ct == NULL) {
|
||||
ERROR(log_) << "No such member (" << mname << ") in object (" << oname << ")";
|
||||
return (false);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (vstr[0] == '$') {
|
||||
std::string::const_iterator dot;
|
||||
|
||||
dot = std::find(vstr.begin(), vstr.end(), '.');
|
||||
|
||||
std::string ooname(vstr.begin() + 1, dot);
|
||||
std::string omname(dot + 1, vstr.end());
|
||||
|
||||
if (ooname == "" || omname == "") {
|
||||
ERROR(log_) << "Refernece to invalid object (" << ooname << ") or member (" << omname << ") by name.";
|
||||
return (false);
|
||||
}
|
||||
|
||||
if (object_map_.find(ooname) == object_map_.end()) {
|
||||
ERROR(log_) << "Reference to non-existant object (" << ooname << ")";
|
||||
return (false);
|
||||
}
|
||||
|
||||
ConfigObject *oco = object_map_[ooname];
|
||||
|
||||
object_field_string_map_t::const_iterator fsit;
|
||||
fsit = field_strings_map_.find(object_field_string_map_t::key_type(oco, omname));
|
||||
if (fsit == field_strings_map_.end()) {
|
||||
ERROR(log_) << "Reference to unset member (" << omname << ") in object (" << ooname << ")";
|
||||
return (false);
|
||||
}
|
||||
|
||||
return (set(oname, mname, fsit->second));
|
||||
}
|
||||
|
||||
if (!co->set(mname, vstr)) {
|
||||
ERROR(log_) << "Member (" << mname << ") in object (" << oname << ") could not be set.";
|
||||
return (false);
|
||||
}
|
||||
|
||||
field_strings_map_[object_field_string_map_t::key_type(co, mname)] = vstr;
|
||||
|
||||
return (true);
|
||||
}
|
||||
|
||||
void
|
||||
Config::import(ConfigClass *cc)
|
||||
{
|
||||
if (class_map_.find(cc->name_) != class_map_.end())
|
||||
return;
|
||||
|
||||
class_map_[cc->name_] = cc;
|
||||
}
|
||||
|
||||
void
|
||||
Config::marshall(ConfigExporter *exp) const
|
||||
{
|
||||
std::map<std::string, ConfigObject *>::const_iterator it;
|
||||
|
||||
for (it = object_map_.begin(); it != object_map_.end(); ++it)
|
||||
exp->object(it->second, it->first);
|
||||
}
|
87
config/config.h
Normal file
87
config/config.h
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_CONFIG_H
|
||||
#define CONFIG_CONFIG_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <config/config_class.h>
|
||||
#include <config/config_exporter.h>
|
||||
#include <config/config_object.h>
|
||||
#include <config/config_type.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: config.h //
|
||||
// Description: main configuration parser //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-04-01 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Config {
|
||||
typedef std::map<std::pair<ConfigObject *, std::string>, std::string> object_field_string_map_t;
|
||||
|
||||
LogHandle log_;
|
||||
std::map<std::string, ConfigClass *> class_map_;
|
||||
std::map<std::string, ConfigObject *> object_map_;
|
||||
object_field_string_map_t field_strings_map_;
|
||||
|
||||
public:
|
||||
Config(void)
|
||||
: log_("/config"),
|
||||
class_map_(),
|
||||
object_map_()
|
||||
{ }
|
||||
|
||||
~Config()
|
||||
{
|
||||
std::map<std::string, ConfigObject *>::const_iterator it;
|
||||
for (it = object_map_.begin(); it != object_map_.end(); ++it)
|
||||
delete it->second;
|
||||
}
|
||||
|
||||
bool activate(const std::string&);
|
||||
bool create(const std::string&, const std::string&);
|
||||
bool set(const std::string&, const std::string&, const std::string&);
|
||||
|
||||
void import(ConfigClass *);
|
||||
|
||||
void marshall(ConfigExporter *) const;
|
||||
|
||||
ConfigObject *lookup(const std::string& oname) const
|
||||
{
|
||||
std::map<std::string, ConfigObject *>::const_iterator omit;
|
||||
|
||||
omit = object_map_.find(oname);
|
||||
if (omit == object_map_.end())
|
||||
return (NULL);
|
||||
return (omit->second);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* !CONFIG_CONFIG_H */
|
74
config/config_class.cc
Normal file
74
config/config_class.cc
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <config/config_class.h>
|
||||
#include <config/config_exporter.h>
|
||||
#include <config/config_type.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: config_class.cc //
|
||||
// Description: parser for configuration classes //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-04-01 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ConfigClass::~ConfigClass()
|
||||
{
|
||||
std::map<std::string, const ConfigClassMember *>::iterator it;
|
||||
|
||||
while ((it = members_.begin()) != members_.end()) {
|
||||
delete it->second;
|
||||
members_.erase(it);
|
||||
}
|
||||
|
||||
delete factory_;
|
||||
}
|
||||
|
||||
bool
|
||||
ConfigClass::set(ConfigObject *co, const std::string& mname, const std::string& vstr) const
|
||||
{
|
||||
#if 0
|
||||
ASSERT("/config/class", co->class_ == this);
|
||||
#endif
|
||||
|
||||
std::map<std::string, const ConfigClassMember *>::const_iterator it = members_.find(mname);
|
||||
if (it == members_.end()) {
|
||||
ERROR("/config/class") << "Object member (" << mname << ") does not exist.";
|
||||
return (false);
|
||||
}
|
||||
return (it->second->set(co, vstr));
|
||||
}
|
||||
|
||||
void
|
||||
ConfigClass::marshall(ConfigExporter *exp, const ConfigClassInstance *co) const
|
||||
{
|
||||
std::map<std::string, const ConfigClassMember *>::const_iterator it;
|
||||
for (it = members_.begin(); it != members_.end(); ++it) {
|
||||
exp->field(co, it->second, it->first);
|
||||
}
|
||||
}
|
111
config/config_class.h
Normal file
111
config/config_class.h
Normal file
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_CONFIG_CLASS_H
|
||||
#define CONFIG_CONFIG_CLASS_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <common/factory.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: config_class.h //
|
||||
// Description: parser for configuration classes //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-04-01 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Config;
|
||||
class ConfigExporter;
|
||||
class ConfigType;
|
||||
class ConfigObject;
|
||||
|
||||
/*
|
||||
* A base type for class instances.
|
||||
*/
|
||||
class ConfigClassInstance {
|
||||
protected:
|
||||
ConfigClassInstance(void)
|
||||
{ }
|
||||
public:
|
||||
virtual ~ConfigClassInstance()
|
||||
{ }
|
||||
|
||||
virtual bool activate(const ConfigObject *) = 0;
|
||||
};
|
||||
|
||||
class ConfigClassMember {
|
||||
protected:
|
||||
ConfigClassMember(void)
|
||||
{ }
|
||||
public:
|
||||
virtual ~ConfigClassMember()
|
||||
{ }
|
||||
|
||||
virtual void marshall(ConfigExporter *, const ConfigClassInstance *) const = 0;
|
||||
virtual bool set(ConfigObject *, const std::string&) const = 0;
|
||||
virtual ConfigType *type(void) const = 0;
|
||||
};
|
||||
|
||||
class ConfigClass {
|
||||
friend class Config;
|
||||
friend struct ConfigObject;
|
||||
|
||||
std::string name_;
|
||||
Factory<ConfigClassInstance> *factory_;
|
||||
std::map<std::string, const ConfigClassMember *> members_;
|
||||
protected:
|
||||
ConfigClass(const std::string& xname, Factory<ConfigClassInstance> *factory)
|
||||
: name_(xname),
|
||||
factory_(factory),
|
||||
members_()
|
||||
{ }
|
||||
|
||||
virtual ~ConfigClass();
|
||||
|
||||
template<typename Tc, typename Tf, typename Ti>
|
||||
void add_member(const std::string& mname, Tc type, Tf Ti::*fieldp);
|
||||
|
||||
private:
|
||||
ConfigClassInstance *allocate(void) const
|
||||
{
|
||||
return (factory_->create());
|
||||
}
|
||||
|
||||
bool set(ConfigObject *, const std::string&, const std::string&) const;
|
||||
|
||||
public:
|
||||
void marshall(ConfigExporter *, const ConfigClassInstance *) const;
|
||||
|
||||
std::string name(void) const
|
||||
{
|
||||
return (name_);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* !CONFIG_CONFIG_CLASS_H */
|
56
config/config_class_address.cc
Normal file
56
config/config_class_address.cc
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <config/config_class.h>
|
||||
#include <config/config_object.h>
|
||||
#include <config/config_class_address.h>
|
||||
|
||||
ConfigClassAddress config_class_address;
|
||||
|
||||
bool
|
||||
ConfigClassAddress::Instance::activate(const ConfigObject *)
|
||||
{
|
||||
switch (family_) {
|
||||
case SocketAddressFamilyIP:
|
||||
case SocketAddressFamilyIPv4:
|
||||
case SocketAddressFamilyIPv6:
|
||||
if (path_ != "") {
|
||||
ERROR("/config/class/address") << "IP socket has path field set, which is only valid for Unix domain sockets.";
|
||||
return (false);
|
||||
}
|
||||
return (true);
|
||||
|
||||
case SocketAddressFamilyUnix:
|
||||
if (host_ != "" || port_ != "") {
|
||||
ERROR("/config/class/address") << "Unix domain socket has host and/or port field set, which is only valid for IP sockets.";
|
||||
return (false);
|
||||
}
|
||||
return (true);
|
||||
|
||||
default:
|
||||
ERROR("/config/class/address") << "Unsupported address family.";
|
||||
return (false);
|
||||
}
|
||||
}
|
70
config/config_class_address.h
Normal file
70
config/config_class_address.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_CONFIG_CLASS_ADDRESS_H
|
||||
#define CONFIG_CONFIG_CLASS_ADDRESS_H
|
||||
|
||||
#include <config/config_type_address_family.h>
|
||||
#include <config/config_type_string.h>
|
||||
#include <config/config_type_proto.h>
|
||||
|
||||
class ConfigClassAddress : public ConfigClass {
|
||||
public:
|
||||
struct Instance : public ConfigClassInstance {
|
||||
SocketAddressFamily family_;
|
||||
std::string host_;
|
||||
std::string port_;
|
||||
std::string path_;
|
||||
ConfigProto proto_;
|
||||
|
||||
Instance(void)
|
||||
: family_(SocketAddressFamilyUnspecified),
|
||||
host_(""),
|
||||
port_(""),
|
||||
path_(""),
|
||||
proto_(ConfigProtoNone)
|
||||
{
|
||||
}
|
||||
|
||||
bool activate(const ConfigObject *);
|
||||
};
|
||||
|
||||
ConfigClassAddress(const std::string& xname = "address")
|
||||
: ConfigClass(xname, new ConstructorFactory<ConfigClassInstance, Instance>)
|
||||
{
|
||||
add_member("family", &config_type_address_family, &Instance::family_);
|
||||
add_member("host", &config_type_string, &Instance::host_);
|
||||
add_member("port", &config_type_string, &Instance::port_); /* XXX enum? */
|
||||
add_member("path", &config_type_string, &Instance::path_);
|
||||
add_member("proto", &config_type_proto, &Instance::proto_);
|
||||
}
|
||||
|
||||
~ConfigClassAddress()
|
||||
{ }
|
||||
};
|
||||
|
||||
extern ConfigClassAddress config_class_address;
|
||||
|
||||
#endif /* !CONFIG_CONFIG_CLASS_ADDRESS_H */
|
41
config/config_class_log_mask.cc
Normal file
41
config/config_class_log_mask.cc
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <config/config_class.h>
|
||||
#include <config/config_object.h>
|
||||
#include <config/config_class_log_mask.h>
|
||||
|
||||
ConfigClassLogMask config_class_log_mask;
|
||||
|
||||
bool
|
||||
ConfigClassLogMask::Instance::activate(const ConfigObject *)
|
||||
{
|
||||
if (!Log::mask(regex_, mask_)) {
|
||||
ERROR("/config/class/logmask") << "Could not set log mask.";
|
||||
return (false);
|
||||
}
|
||||
|
||||
return (true);
|
||||
}
|
53
config/config_class_log_mask.h
Normal file
53
config/config_class_log_mask.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_CONFIG_CLASS_LOG_MASK_H
|
||||
#define CONFIG_CONFIG_CLASS_LOG_MASK_H
|
||||
|
||||
#include <config/config_type_log_level.h>
|
||||
#include <config/config_type_string.h>
|
||||
|
||||
class ConfigClassLogMask : public ConfigClass {
|
||||
struct Instance : public ConfigClassInstance {
|
||||
std::string regex_;
|
||||
Log::Priority mask_;
|
||||
|
||||
bool activate(const ConfigObject *);
|
||||
};
|
||||
public:
|
||||
ConfigClassLogMask(void)
|
||||
: ConfigClass("log-mask", new ConstructorFactory<ConfigClassInstance, Instance>)
|
||||
{
|
||||
add_member("regex", &config_type_string, &Instance::regex_);
|
||||
add_member("mask", &config_type_log_level, &Instance::mask_);
|
||||
}
|
||||
|
||||
~ConfigClassLogMask()
|
||||
{ }
|
||||
};
|
||||
|
||||
extern ConfigClassLogMask config_class_log_mask;
|
||||
|
||||
#endif /* !CONFIG_CONFIG_CLASS_LOG_MASK_H */
|
49
config/config_exporter.h
Normal file
49
config/config_exporter.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2011-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_CONFIG_EXPORTER_H
|
||||
#define CONFIG_CONFIG_EXPORTER_H
|
||||
|
||||
class ConfigClass;
|
||||
class ConfigClassInstance;
|
||||
class ConfigClassMember;
|
||||
struct ConfigObject;
|
||||
class ConfigType;
|
||||
|
||||
class ConfigExporter {
|
||||
protected:
|
||||
ConfigExporter(void)
|
||||
{ }
|
||||
|
||||
virtual ~ConfigExporter()
|
||||
{ }
|
||||
|
||||
public:
|
||||
virtual void field(const ConfigClassInstance *, const ConfigClassMember *, const std::string&) = 0;
|
||||
virtual void object(const ConfigObject *, const std::string&) = 0;
|
||||
virtual void value(const ConfigType *, const std::string&) = 0;
|
||||
};
|
||||
|
||||
#endif /* !CONFIG_CONFIG_EXPORTER_H */
|
54
config/config_object.cc
Normal file
54
config/config_object.cc
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <config/config_object.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: config_object.cc //
|
||||
// Description: parser for configuration objects //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-04-01 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool
|
||||
ConfigObject::activate(void) const
|
||||
{
|
||||
return (instance_->activate(this));
|
||||
}
|
||||
|
||||
void
|
||||
ConfigObject::marshall(ConfigExporter *exp) const
|
||||
{
|
||||
class_->marshall(exp, instance_);
|
||||
}
|
||||
|
||||
bool
|
||||
ConfigObject::set(const std::string& mname, const std::string& vstr)
|
||||
{
|
||||
return (class_->set(this, mname, vstr));
|
||||
}
|
105
config/config_object.h
Normal file
105
config/config_object.h
Normal file
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_CONFIG_OBJECT_H
|
||||
#define CONFIG_CONFIG_OBJECT_H
|
||||
|
||||
#include <config/config_class.h>
|
||||
#include <config/config_exporter.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: config_object.h //
|
||||
// Description: parser for configuration objects //
|
||||
// Project: WANProxy XTech //
|
||||
// Adapted by: Andreu Vidal Bramfeld-Software //
|
||||
// Last modified: 2015-04-01 //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Config;
|
||||
|
||||
struct ConfigObject {
|
||||
Config *config_;
|
||||
std::string name_;
|
||||
const ConfigClass *class_;
|
||||
ConfigClassInstance *instance_;
|
||||
|
||||
ConfigObject(Config *config, const std::string& name, const ConfigClass *cc, ConfigClassInstance *inst)
|
||||
: config_(config),
|
||||
name_(name),
|
||||
class_(cc),
|
||||
instance_(inst)
|
||||
{ }
|
||||
|
||||
virtual ~ConfigObject()
|
||||
{
|
||||
delete instance_;
|
||||
}
|
||||
|
||||
bool activate(void) const;
|
||||
void marshall(ConfigExporter *) const;
|
||||
bool set(const std::string&, const std::string&);
|
||||
};
|
||||
|
||||
template<typename Tc, typename Tf, typename Ti>
|
||||
void ConfigClass::add_member(const std::string& mname, Tc type, Tf Ti::*fieldp)
|
||||
{
|
||||
struct TypedConfigClassMember : public ConfigClassMember {
|
||||
Tc config_type_;
|
||||
Tf Ti::*config_field_;
|
||||
|
||||
TypedConfigClassMember(Tc config_type, Tf Ti::*config_field)
|
||||
: config_type_(config_type),
|
||||
config_field_(config_field)
|
||||
{ }
|
||||
virtual ~TypedConfigClassMember()
|
||||
{ }
|
||||
|
||||
void marshall(ConfigExporter *exp, const ConfigClassInstance *instance) const
|
||||
{
|
||||
const Ti *inst = dynamic_cast<const Ti *>(instance);
|
||||
ASSERT("/config/class/field", inst != NULL);
|
||||
config_type_->marshall(exp, &(inst->*config_field_));
|
||||
}
|
||||
|
||||
bool set(ConfigObject *co, const std::string& vstr) const
|
||||
{
|
||||
Ti *inst = dynamic_cast<Ti *>(co->instance_);
|
||||
ASSERT("/config/class/field", inst != NULL);
|
||||
return (config_type_->set(co, vstr, &(inst->*config_field_)));
|
||||
}
|
||||
|
||||
ConfigType *type(void) const
|
||||
{
|
||||
return (config_type_);
|
||||
}
|
||||
};
|
||||
|
||||
ASSERT("/config/class/" + name_, members_.find(mname) == members_.end());
|
||||
members_[mname] = new TypedConfigClassMember(type, fieldp);
|
||||
}
|
||||
|
||||
#endif /* !CONFIG_CONFIG_OBJECT_H */
|
48
config/config_type.h
Normal file
48
config/config_type.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_CONFIG_TYPE_H
|
||||
#define CONFIG_CONFIG_TYPE_H
|
||||
|
||||
class Config;
|
||||
class ConfigExporter;
|
||||
|
||||
class ConfigType {
|
||||
std::string name_;
|
||||
protected:
|
||||
ConfigType(const std::string& xname)
|
||||
: name_(xname)
|
||||
{ }
|
||||
|
||||
virtual ~ConfigType()
|
||||
{ }
|
||||
public:
|
||||
std::string name(void) const
|
||||
{
|
||||
return (name_);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* !CONFIG_CONFIG_TYPE_H */
|
37
config/config_type_address_family.cc
Normal file
37
config/config_type_address_family.cc
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2009 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <config/config_type_address_family.h>
|
||||
|
||||
static struct ConfigTypeAddressFamily::Mapping config_type_address_family_map[] = {
|
||||
{ "IP", SocketAddressFamilyIP },
|
||||
{ "IPv4", SocketAddressFamilyIPv4 },
|
||||
{ "IPv6", SocketAddressFamilyIPv6 },
|
||||
{ "Unix", SocketAddressFamilyUnix },
|
||||
{ NULL, SocketAddressFamilyUnspecified }
|
||||
};
|
||||
|
||||
ConfigTypeAddressFamily
|
||||
config_type_address_family("address-family", config_type_address_family_map);
|
37
config/config_type_address_family.h
Normal file
37
config/config_type_address_family.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2011 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_CONFIG_TYPE_ADDRESS_FAMILY_H
|
||||
#define CONFIG_CONFIG_TYPE_ADDRESS_FAMILY_H
|
||||
|
||||
#include <config/config_type_enum.h>
|
||||
|
||||
#include <io/socket/socket_types.h>
|
||||
|
||||
typedef ConfigTypeEnum<SocketAddressFamily> ConfigTypeAddressFamily;
|
||||
|
||||
extern ConfigTypeAddressFamily config_type_address_family;
|
||||
|
||||
#endif /* !CONFIG_CONFIG_TYPE_ADDRESS_FAMILY_H */
|
85
config/config_type_enum.h
Normal file
85
config/config_type_enum.h
Normal file
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_CONFIG_TYPE_ENUM_H
|
||||
#define CONFIG_CONFIG_TYPE_ENUM_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <config/config_exporter.h>
|
||||
#include <config/config_type.h>
|
||||
|
||||
template<typename E>
|
||||
class ConfigTypeEnum : public ConfigType {
|
||||
public:
|
||||
struct Mapping {
|
||||
const char *string_;
|
||||
E enum_;
|
||||
};
|
||||
private:
|
||||
std::map<std::string, E> enum_map_;
|
||||
public:
|
||||
ConfigTypeEnum(const std::string& xname, struct Mapping *mappings)
|
||||
: ConfigType(xname),
|
||||
enum_map_()
|
||||
{
|
||||
ASSERT("/config/type/enum", mappings != NULL);
|
||||
while (mappings->string_ != NULL) {
|
||||
enum_map_[mappings->string_] = mappings->enum_;
|
||||
mappings++;
|
||||
}
|
||||
}
|
||||
|
||||
~ConfigTypeEnum()
|
||||
{ }
|
||||
|
||||
void marshall(ConfigExporter *exp, const E *enump) const
|
||||
{
|
||||
E xenum = *enump;
|
||||
|
||||
typename std::map<std::string, E>::const_iterator it;
|
||||
for (it = enum_map_.begin(); it != enum_map_.end(); ++it) {
|
||||
if (it->second != xenum)
|
||||
continue;
|
||||
exp->value(this, it->first);
|
||||
return;
|
||||
}
|
||||
HALT("/config/type/enum") << "Trying to marshall unknown enum.";
|
||||
}
|
||||
|
||||
bool set(ConfigObject *, const std::string& vstr, E *enump)
|
||||
{
|
||||
if (enum_map_.find(vstr) == enum_map_.end()) {
|
||||
ERROR("/config/type/enum") << "Invalid value (" << vstr << ")";
|
||||
return (false);
|
||||
}
|
||||
|
||||
*enump = enum_map_[vstr];
|
||||
|
||||
return (true);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* !CONFIG_CONFIG_TYPE_ENUM_H */
|
92
config/config_type_flags.h
Normal file
92
config/config_type_flags.h
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_CONFIG_TYPE_FLAGS_H
|
||||
#define CONFIG_CONFIG_TYPE_FLAGS_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <config/config_exporter.h>
|
||||
#include <config/config_type.h>
|
||||
|
||||
template<typename T>
|
||||
class ConfigTypeFlags : public ConfigType {
|
||||
public:
|
||||
struct Mapping {
|
||||
const char *string_;
|
||||
T flag_;
|
||||
};
|
||||
private:
|
||||
std::map<std::string, T> flag_map_;
|
||||
public:
|
||||
ConfigTypeFlags(const std::string& xname, struct Mapping *mappings)
|
||||
: ConfigType(xname),
|
||||
flag_map_()
|
||||
{
|
||||
ASSERT("/config/type/flags", mappings != NULL);
|
||||
while (mappings->string_ != NULL) {
|
||||
flag_map_[mappings->string_] = mappings->flag_;
|
||||
mappings++;
|
||||
}
|
||||
}
|
||||
|
||||
~ConfigTypeFlags()
|
||||
{ }
|
||||
|
||||
void marshall(ConfigExporter *exp, const T *flagsp) const
|
||||
{
|
||||
T flags = *flagsp;
|
||||
|
||||
std::string str;
|
||||
typename std::map<std::string, T>::const_iterator it;
|
||||
for (it = flag_map_.begin(); it != flag_map_.end(); ++it) {
|
||||
if ((it->second & flags) == 0)
|
||||
continue;
|
||||
flags &= ~it->second;
|
||||
if (!str.empty())
|
||||
str += "|";
|
||||
str += it->first;
|
||||
}
|
||||
if (flags != 0)
|
||||
HALT("/config/type/flags") << "Trying to marshall unknown flags.";
|
||||
if (flags == 0 && str.empty())
|
||||
str = "0";
|
||||
exp->value(this, str);
|
||||
}
|
||||
|
||||
bool set(ConfigObject *, const std::string& vstr, T *flagsp)
|
||||
{
|
||||
if (flag_map_.find(vstr) == flag_map_.end()) {
|
||||
ERROR("/config/type/flags") << "Invalid value (" << vstr << ")";
|
||||
return (false);
|
||||
}
|
||||
|
||||
*flagsp |= flag_map_[vstr];
|
||||
|
||||
return (true);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* !CONFIG_CONFIG_TYPE_FLAGS_H */
|
67
config/config_type_int.cc
Normal file
67
config/config_type_int.cc
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if !defined(__OPENNT)
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <config/config_exporter.h>
|
||||
#include <config/config_type_int.h>
|
||||
|
||||
ConfigTypeInt config_type_int;
|
||||
|
||||
void
|
||||
ConfigTypeInt::marshall(ConfigExporter *exp, const intmax_t *valp) const
|
||||
{
|
||||
intmax_t val = *valp;
|
||||
|
||||
char buf[sizeof val * 2 + 2 + 1];
|
||||
snprintf(buf, sizeof buf, "0x%016jx", val);
|
||||
exp->value(this, buf);
|
||||
}
|
||||
|
||||
bool
|
||||
ConfigTypeInt::set(ConfigObject *, const std::string& vstr, intmax_t *valp)
|
||||
{
|
||||
const char *str = vstr.c_str();
|
||||
char *endp;
|
||||
intmax_t imax;
|
||||
|
||||
#if !defined(__OPENNT)
|
||||
imax = strtoimax(str, &endp, 0);
|
||||
#else
|
||||
imax = strtoll(str, &endp, 0);
|
||||
#endif
|
||||
if (*endp != '\0') {
|
||||
ERROR("/config/type/int") << "Invalid numeric format.";
|
||||
return (false);
|
||||
}
|
||||
|
||||
*valp = imax;
|
||||
|
||||
return (true);
|
||||
}
|
49
config/config_type_int.h
Normal file
49
config/config_type_int.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_CONFIG_TYPE_INT_H
|
||||
#define CONFIG_CONFIG_TYPE_INT_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <config/config_type.h>
|
||||
|
||||
class ConfigTypeInt : public ConfigType {
|
||||
public:
|
||||
ConfigTypeInt(void)
|
||||
: ConfigType("int")
|
||||
{ }
|
||||
|
||||
~ConfigTypeInt()
|
||||
{ }
|
||||
|
||||
void marshall(ConfigExporter *, const intmax_t *) const;
|
||||
|
||||
bool set(ConfigObject *, const std::string&, intmax_t *);
|
||||
};
|
||||
|
||||
extern ConfigTypeInt config_type_int;
|
||||
|
||||
#endif /* !CONFIG_CONFIG_TYPE_INT_H */
|
41
config/config_type_log_level.cc
Normal file
41
config/config_type_log_level.cc
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2009 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <config/config_type_log_level.h>
|
||||
|
||||
struct ConfigTypeLogLevel::Mapping config_type_log_level_map[] = {
|
||||
{ "EMERG", Log::Emergency },
|
||||
{ "ALERT", Log::Alert },
|
||||
{ "CRIT", Log::Critical },
|
||||
{ "ERR", Log::Error },
|
||||
{ "WARNING", Log::Warning },
|
||||
{ "NOTICE", Log::Notice },
|
||||
{ "INFO", Log::Info },
|
||||
{ "DEBUG", Log::Debug },
|
||||
{ NULL, Log::Debug }
|
||||
};
|
||||
|
||||
ConfigTypeLogLevel
|
||||
config_type_log_level("log-level", config_type_log_level_map);
|
35
config/config_type_log_level.h
Normal file
35
config/config_type_log_level.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2011 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_CONFIG_TYPE_LOG_LEVEL_H
|
||||
#define CONFIG_CONFIG_TYPE_LOG_LEVEL_H
|
||||
|
||||
#include <config/config_type_enum.h>
|
||||
|
||||
typedef ConfigTypeEnum<Log::Priority> ConfigTypeLogLevel;
|
||||
|
||||
extern ConfigTypeLogLevel config_type_log_level;
|
||||
|
||||
#endif /* !CONFIG_CONFIG_TYPE_LOG_LEVEL_H */
|
64
config/config_type_pointer.cc
Normal file
64
config/config_type_pointer.cc
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <config/config.h>
|
||||
#include <config/config_class.h>
|
||||
#include <config/config_exporter.h>
|
||||
#include <config/config_object.h>
|
||||
#include <config/config_type_pointer.h>
|
||||
|
||||
ConfigTypePointer config_type_pointer;
|
||||
|
||||
void
|
||||
ConfigTypePointer::marshall(ConfigExporter *exp, ConfigObject *const *cop) const
|
||||
{
|
||||
const ConfigObject *co = *cop;
|
||||
|
||||
if (co == NULL)
|
||||
exp->value(this, "None");
|
||||
else
|
||||
exp->value(this, co->name_);
|
||||
}
|
||||
|
||||
bool
|
||||
ConfigTypePointer::set(ConfigObject *co, const std::string& vstr, ConfigObject **cop)
|
||||
{
|
||||
if (vstr == "None") {
|
||||
*cop = NULL;
|
||||
return (true);
|
||||
}
|
||||
|
||||
ConfigObject *target = co->config_->lookup(vstr);
|
||||
if (target == NULL) {
|
||||
ERROR("/config/type/pointer") << "Referenced object (" << vstr << ") does not exist.";
|
||||
return (false);
|
||||
}
|
||||
|
||||
*cop = target;
|
||||
|
||||
return (true);
|
||||
}
|
49
config/config_type_pointer.h
Normal file
49
config/config_type_pointer.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_CONFIG_TYPE_POINTER_H
|
||||
#define CONFIG_CONFIG_TYPE_POINTER_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <config/config_type.h>
|
||||
|
||||
class ConfigTypePointer : public ConfigType {
|
||||
public:
|
||||
ConfigTypePointer(void)
|
||||
: ConfigType("pointer")
|
||||
{ }
|
||||
|
||||
~ConfigTypePointer()
|
||||
{ }
|
||||
|
||||
void marshall(ConfigExporter *, ConfigObject *const *) const;
|
||||
|
||||
bool set(ConfigObject *, const std::string&, ConfigObject **);
|
||||
};
|
||||
|
||||
extern ConfigTypePointer config_type_pointer;
|
||||
|
||||
#endif /* !CONFIG_CONFIG_TYPE_POINTER_H */
|
10
config/config_type_proto.cc
Normal file
10
config/config_type_proto.cc
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include "config_type_proto.h"
|
||||
|
||||
static struct ConfigTypeProto::Mapping config_type_proto_map[] = {
|
||||
{ "TCP", ConfigProtoTCP },
|
||||
{ "TCP_POOL", ConfigProtoTCPPool },
|
||||
{ NULL, ConfigProtoNone }
|
||||
};
|
||||
|
||||
ConfigTypeProto
|
||||
config_type_proto("proto", config_type_proto_map);
|
16
config/config_type_proto.h
Normal file
16
config/config_type_proto.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef CONFIG_CONFIG_TYPE_PROTO_H
|
||||
#define CONFIG_CONFIG_TYPE_PROTO_H
|
||||
|
||||
#include <config/config_type_enum.h>
|
||||
|
||||
enum ConfigProto {
|
||||
ConfigProtoTCP,
|
||||
ConfigProtoTCPPool,
|
||||
ConfigProtoNone,
|
||||
};
|
||||
|
||||
typedef ConfigTypeEnum<ConfigProto> ConfigTypeProto;
|
||||
|
||||
extern ConfigTypeProto config_type_proto;
|
||||
|
||||
#endif /* !CONFIG_CONFIG_TYPE_PROTO_H */
|
28
config/config_type_string.cc
Normal file
28
config/config_type_string.cc
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) 2009 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <config/config_type_string.h>
|
||||
|
||||
ConfigTypeString config_type_string;
|
72
config/config_type_string.h
Normal file
72
config/config_type_string.h
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Juli Mallett. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_CONFIG_TYPE_STRING_H
|
||||
#define CONFIG_CONFIG_TYPE_STRING_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <config/config_exporter.h>
|
||||
#include <config/config_type.h>
|
||||
|
||||
class ConfigTypeString : public ConfigType {
|
||||
public:
|
||||
ConfigTypeString(void)
|
||||
: ConfigType("string")
|
||||
{ }
|
||||
|
||||
~ConfigTypeString()
|
||||
{ }
|
||||
|
||||
void marshall(ConfigExporter *exp, const std::string *stringp) const
|
||||
{
|
||||
exp->value(this, *stringp);
|
||||
}
|
||||
|
||||
bool set(ConfigObject *, const std::string& vstr, std::string *stringp)
|
||||
{
|
||||
if (*vstr.begin() != '"') {
|
||||
ERROR("/config/type/string") << "String does not begin with '\"'.";
|
||||
return (false);
|
||||
}
|
||||
if (*vstr.rbegin() != '"') {
|
||||
ERROR("/config/type/string") << "String does not end with '\"'.";
|
||||
return (false);
|
||||
}
|
||||
|
||||
std::string str(vstr.begin() + 1, vstr.end() - 1);
|
||||
if (std::find(str.begin(), str.end(), '"') != str.end()) {
|
||||
ERROR("/config/type/string") << "String has '\"' other than at beginning or end.";
|
||||
return (false);
|
||||
}
|
||||
|
||||
*stringp = str;
|
||||
return (true);
|
||||
}
|
||||
};
|
||||
|
||||
extern ConfigTypeString config_type_string;
|
||||
|
||||
#endif /* !CONFIG_CONFIG_TYPE_STRING_H */
|
14
config/lib.mk
Normal file
14
config/lib.mk
Normal file
|
@ -0,0 +1,14 @@
|
|||
VPATH+= ${TOPDIR}/config
|
||||
|
||||
SRCS+= config.cc
|
||||
SRCS+= config_class.cc
|
||||
SRCS+= config_class_log_mask.cc
|
||||
SRCS+= config_object.cc
|
||||
SRCS+= config_type_int.cc
|
||||
SRCS+= config_type_log_level.cc
|
||||
SRCS+= config_type_pointer.cc
|
||||
SRCS+= config_type_string.cc
|
||||
SRCS+= config_type_proto.cc
|
||||
|
||||
SRCS_io_socket+=config_class_address.cc
|
||||
SRCS_io_socket+=config_type_address_family.cc
|
Loading…
Add table
Add a link
Reference in a new issue