0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 08:42:34 +01:00

ircd: Various minor cleanup.

This commit is contained in:
Jason Volk 2018-01-22 00:25:08 -08:00
parent b91fcefe45
commit e63f06ecc2
2 changed files with 108 additions and 44 deletions

View file

@ -76,8 +76,10 @@ ircd::init(boost::asio::io_context &ios,
try try
{ {
if(runlevel != runlevel::HALT) if(runlevel != runlevel::HALT)
throw error("Cannot init() IRCd from runlevel %s", throw error
reflect(runlevel)); {
"Cannot init() IRCd from runlevel %s", reflect(runlevel)
};
// Samples the thread this context was executed on which should be where // Samples the thread this context was executed on which should be where
// the user ran ios.run(). The user may have invoked ios.run() on multiple // the user ran ios.run(). The user may have invoked ios.run() on multiple
@ -253,7 +255,10 @@ try
} }
catch(const ctx::interrupted &e) catch(const ctx::interrupted &e)
{ {
log::warning("IRCd main interrupted..."); log::warning
{
"IRCd main interrupted..."
};
} }
#ifndef RB_DEBUG #ifndef RB_DEBUG
catch(const std::exception &e) catch(const std::exception &e)
@ -261,7 +266,10 @@ catch(const std::exception &e)
// When not in debug mode this is a clean return to not crash through // When not in debug mode this is a clean return to not crash through
// the embedder's ios.run() which would terminate the rest of their // the embedder's ios.run() which would terminate the rest of their
// program. Instead they have the right to handle the error and try again. // program. Instead they have the right to handle the error and try again.
log::critical("IRCd main exited: %s", e.what()); log::critical
{
"IRCd main exited: %s", e.what()
};
} }
#else #else
catch(...) catch(...)
@ -294,10 +302,13 @@ void
ircd::set_runlevel(const enum runlevel &new_runlevel) ircd::set_runlevel(const enum runlevel &new_runlevel)
try try
{ {
log::debug("IRCd runlevel transition from '%s' to '%s'%s", log::debug
reflect(ircd::runlevel), {
reflect(new_runlevel), "IRCd runlevel transition from '%s' to '%s'%s",
ircd::runlevel_changed? " (notifying user)" : ""); reflect(ircd::runlevel),
reflect(new_runlevel),
ircd::runlevel_changed? " (notifying user)" : ""
};
ircd::_runlevel = new_runlevel; ircd::_runlevel = new_runlevel;
@ -308,19 +319,26 @@ try
ios->post([new_runlevel] ios->post([new_runlevel]
{ {
if(new_runlevel == runlevel::HALT) if(new_runlevel == runlevel::HALT)
log::notice("IRCd %s", reflect(new_runlevel)); log::notice
{
"IRCd %s", reflect(new_runlevel)
};
ircd::runlevel_changed(new_runlevel); ircd::runlevel_changed(new_runlevel);
}); });
if(new_runlevel != runlevel::HALT) if(new_runlevel != runlevel::HALT)
log::notice("IRCd %s", reflect(new_runlevel)); log::notice
{
"IRCd %s", reflect(new_runlevel)
};
} }
catch(const std::exception &e) catch(const std::exception &e)
{ {
log::critical("IRCd runlevel change to '%s': %s", log::critical
reflect(new_runlevel), {
e.what()); "IRCd runlevel change to '%s': %s", reflect(new_runlevel), e.what()
};
ircd::terminate(); ircd::terminate();
} }
@ -346,7 +364,10 @@ ircd::read_conf(std::string filename)
try try
{ {
if(!filename.empty()) if(!filename.empty())
log::debug("User supplied a configuration file path: `%s'", filename); log::debug
{
"User supplied a configuration file path: `%s'", filename
};
if(filename.empty()) if(filename.empty())
filename = fs::CPATH; filename = fs::CPATH;
@ -371,17 +392,22 @@ try
const json::object object{read}; const json::object object{read};
const size_t key_count{object.count()}; const size_t key_count{object.count()};
log::info("Using configuration from: `%s': JSON object with %zu members in %zu bytes", log::info
filename, {
key_count, "Using configuration from: `%s': JSON object with %zu members in %zu bytes",
read.size()); filename,
key_count,
read.size()
};
return read; return read;
} }
catch(const std::exception &e) catch(const std::exception &e)
{ {
log::error("Configuration @ `%s': %s", log::error
filename, {
e.what()); "Configuration @ `%s': %s", filename, e.what()
};
throw; throw;
} }

View file

@ -38,7 +38,10 @@ ircd::resource::find(string_view path)
} }
catch(const std::out_of_range &e) catch(const std::out_of_range &e)
{ {
throw http::error(http::code::NOT_FOUND); throw http::error
{
http::code::NOT_FOUND
};
} }
// Exact file or directory match // Exact file or directory match
@ -50,17 +53,26 @@ ircd::resource::find(string_view path)
{ {
// Walk the iterator back to find if there is a directory prefixing this path. // Walk the iterator back to find if there is a directory prefixing this path.
if(it == begin(resources)) if(it == begin(resources))
throw http::error(http::code::NOT_FOUND); throw http::error
{
http::code::NOT_FOUND
};
--it; --it;
if(!startswith(path, rstrip(it->first, '/'))) if(!startswith(path, rstrip(it->first, '/')))
throw http::error(http::code::NOT_FOUND); throw http::error
{
http::code::NOT_FOUND
};
} }
// Check if the resource is a directory; if not, it can only // Check if the resource is a directory; if not, it can only
// handle exact path matches. // handle exact path matches.
if(~it->second->flags & it->second->DIRECTORY && path != rstrip(it->first, '/')) if(~it->second->flags & it->second->DIRECTORY && path != rstrip(it->first, '/'))
throw http::error(http::code::NOT_FOUND); throw http::error
{
http::code::NOT_FOUND
};
return *it->second; return *it->second;
} }
@ -84,9 +96,16 @@ ircd::resource::resource(const string_view &path,
,flags{opts.flags} ,flags{opts.flags}
,resources_it{[this, &path] ,resources_it{[this, &path]
{ {
const auto iit(resources.emplace(this->path, this)); const auto iit
{
resources.emplace(this->path, this)
};
if(!iit.second) if(!iit.second)
throw error("resource \"%s\" already registered", path); throw error
{
"resource \"%s\" already registered", path
};
return unique_const_iterator<decltype(resources)> return unique_const_iterator<decltype(resources)>
{ {
@ -94,13 +113,19 @@ ircd::resource::resource(const string_view &path,
}; };
}()} }()}
{ {
log::info("Registered resource \"%s\"", path.empty()? string_view{"/"} : path); log::info
{
"Registered resource \"%s\"", path.empty()? string_view{"/"} : path
};
} }
ircd::resource::~resource() ircd::resource::~resource()
noexcept noexcept
{ {
log::info("Unregistered resource \"%s\"", path.empty()? string_view{"/"} : path); log::info
{
"Unregistered resource \"%s\"", path.empty()? string_view{"/"} : path
};
} }
namespace ircd namespace ircd
@ -205,9 +230,12 @@ catch(const m::error &)
} }
catch(const std::exception &e) catch(const std::exception &e)
{ {
log::error("X-Matrix Authorization from %s: %s", log::error
string(remote(client)), {
e.what()); "X-Matrix Authorization from %s: %s",
string(remote(client)),
e.what()
};
throw m::error throw m::error
{ {
@ -379,9 +407,16 @@ ircd::resource::method::method(struct resource &resource,
,opts{opts} ,opts{opts}
,methods_it{[this, &name] ,methods_it{[this, &name]
{ {
const auto iit(this->resource->methods.emplace(this->name, this)); const auto iit
{
this->resource->methods.emplace(this->name, this)
};
if(!iit.second) if(!iit.second)
throw error("resource \"%s\" already registered", name); throw error
{
"resource \"%s\" already registered", name
};
return unique_const_iterator<decltype(resource::methods)> return unique_const_iterator<decltype(resource::methods)>
{ {
@ -660,14 +695,17 @@ ircd::resource::response::response(client &client,
write_closure(client)(vector); write_closure(client)(vector);
log::debug("socket(%p) local[%s] remote[%s] HTTP %d %s in %ld$us; response in %ld$us (%s) content-length:%zu", log::debug
client.sock.get(), {
string(local(client)), "socket(%p) local[%s] remote[%s] HTTP %d %s in %ld$us; response in %ld$us (%s) content-length:%zu",
string(remote(client)), client.sock.get(),
int(code), string(local(client)),
http::status(code), string(remote(client)),
request_time, int(code),
(client.request->timer.at<microseconds>().count() - request_time), http::status(code),
content_type, request_time,
content.size()); (client.request->timer.at<microseconds>().count() - request_time),
content_type,
content.size()
};
} }