mirror of
https://github.com/matrix-construct/construct
synced 2024-06-02 18:18:56 +02:00
ircd::conf: Add newconf to oldconf translation.
This commit is contained in:
parent
3e1bf93a22
commit
2c854124af
|
@ -27,6 +27,39 @@
|
|||
namespace ircd {
|
||||
namespace conf {
|
||||
|
||||
IRCD_EXCEPTION(ircd::error, error)
|
||||
|
||||
extern struct log::log log;
|
||||
|
||||
namespace newconf
|
||||
{
|
||||
IRCD_EXCEPTION(conf::error, error)
|
||||
IRCD_EXCEPTION(error, unknown_block)
|
||||
|
||||
using letters = std::array<std::string, 256>;
|
||||
|
||||
extern topconf current; // The latest newconf parse map after startup or rehash
|
||||
extern topconf last; // The current is moved to last for differentiation
|
||||
extern letters registry; // Translates newconf block names into characters
|
||||
|
||||
uint8_t find_letter(const std::string &name);
|
||||
std::forward_list<std::string> translate(const topconf &);
|
||||
}
|
||||
|
||||
void init(const std::string &path);
|
||||
|
||||
} // namespace conf
|
||||
} // namespace ircd
|
||||
#endif // __cplusplus
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace ircd {
|
||||
namespace conf {
|
||||
|
||||
|
||||
|
||||
#define NOT_AUTHORISED (-1)
|
||||
#define I_SOCKET_ERROR (-2)
|
||||
#define I_LINE_FULL (-3)
|
||||
|
|
|
@ -89,6 +89,7 @@ namespace ircd
|
|||
#include "chmode.h"
|
||||
#include "channel.h"
|
||||
|
||||
#include "logger.h"
|
||||
#include "newconf.h"
|
||||
#include "conf.h"
|
||||
|
||||
|
@ -102,7 +103,6 @@ namespace ircd
|
|||
#include "hook.h"
|
||||
#include "ircd_getopt.h"
|
||||
#include "listener.h"
|
||||
#include "logger.h"
|
||||
#include "info.h"
|
||||
#include "modules.h"
|
||||
#include "monitor.h"
|
||||
|
|
94
ircd/conf.cc
94
ircd/conf.cc
|
@ -20,8 +20,102 @@
|
|||
*
|
||||
*/
|
||||
|
||||
namespace ircd {
|
||||
namespace conf {
|
||||
|
||||
struct log::log log
|
||||
{
|
||||
"conf", 'w' // both C's unavailable :/
|
||||
};
|
||||
|
||||
newconf::topconf newconf::current;
|
||||
newconf::topconf newconf::last;
|
||||
newconf::letters newconf::registry;
|
||||
|
||||
void parse_newconf(const std::string &path);
|
||||
|
||||
} // namespace conf
|
||||
} // namespace ircd
|
||||
|
||||
using namespace ircd;
|
||||
|
||||
void conf::init(const std::string &path)
|
||||
{
|
||||
newconf::registry['A'] = "admin";
|
||||
newconf::registry['B'] = "blacklist";
|
||||
newconf::registry['C'] = "connect";
|
||||
newconf::registry['I'] = "auth";
|
||||
newconf::registry['M'] = "serverinfo";
|
||||
newconf::registry['O'] = "operator";
|
||||
newconf::registry['P'] = "listen";
|
||||
newconf::registry['U'] = "service";
|
||||
newconf::registry['Y'] = "class";
|
||||
newconf::registry['a'] = "alias";
|
||||
newconf::registry['d'] = "exempt";
|
||||
newconf::registry['g'] = "general";
|
||||
newconf::registry['l'] = "log";
|
||||
newconf::registry['m'] = "loadmodule";
|
||||
|
||||
parse_newconf(path);
|
||||
const auto oldconf(newconf::translate(newconf::current));
|
||||
}
|
||||
|
||||
void
|
||||
conf::parse_newconf(const std::string &path)
|
||||
{
|
||||
newconf::last = std::move(newconf::current);
|
||||
newconf::current = newconf::parse_file(path);
|
||||
}
|
||||
|
||||
std::forward_list<std::string>
|
||||
conf::newconf::translate(const newconf::topconf &top)
|
||||
{
|
||||
std::forward_list<std::string> ret;
|
||||
for(const auto &pair : top) try
|
||||
{
|
||||
const auto &type(pair.first);
|
||||
const auto &block(pair.second);
|
||||
const auto &label(block.first);
|
||||
const auto &items(block.second);
|
||||
const auto &letter(find_letter(type));
|
||||
for(const auto &item : items)
|
||||
{
|
||||
const auto &key(item.first);
|
||||
const auto &vals(item.second);
|
||||
std::stringstream buf;
|
||||
buf << letter << " "
|
||||
<< label << " "
|
||||
<< key << " :";
|
||||
|
||||
for(auto i(0); i < int(vals.size()) - 1; ++i)
|
||||
buf << vals.at(i) << " ";
|
||||
|
||||
if(!vals.empty())
|
||||
buf << vals.back();
|
||||
|
||||
ret.emplace_front(buf.str());
|
||||
}
|
||||
}
|
||||
catch(const error &e)
|
||||
{
|
||||
log.warning("%s", e.what());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
conf::newconf::find_letter(const std::string &name)
|
||||
{
|
||||
const auto ®istry(newconf::registry);
|
||||
const auto it(std::find(begin(registry), end(registry), name));
|
||||
if(it == end(registry))
|
||||
throw unknown_block("%s is not registered to a letter", name.c_str());
|
||||
|
||||
return std::distance(begin(registry), it);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
#define CF_TYPE(x) ((x) & CF_MTYPE)
|
||||
|
||||
|
|
|
@ -174,7 +174,7 @@ ircd::init(boost::asio::io_service &io_service,
|
|||
log::init();
|
||||
log::mark("log started");
|
||||
|
||||
conf::newconf::parse_file(configfile);
|
||||
conf::init(configfile);
|
||||
|
||||
// initialise operhash fairly early.
|
||||
//init_operhash();
|
||||
|
|
Loading…
Reference in a new issue