mirror of
https://github.com/matrix-construct/construct
synced 2024-11-15 14:31:11 +01:00
ircd: Various minor cleanup.
This commit is contained in:
parent
b91fcefe45
commit
e63f06ecc2
2 changed files with 108 additions and 44 deletions
60
ircd/ircd.cc
60
ircd/ircd.cc
|
@ -76,8 +76,10 @@ ircd::init(boost::asio::io_context &ios,
|
|||
try
|
||||
{
|
||||
if(runlevel != runlevel::HALT)
|
||||
throw error("Cannot init() IRCd from runlevel %s",
|
||||
reflect(runlevel));
|
||||
throw error
|
||||
{
|
||||
"Cannot init() IRCd from runlevel %s", reflect(runlevel)
|
||||
};
|
||||
|
||||
// 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
|
||||
|
@ -253,7 +255,10 @@ try
|
|||
}
|
||||
catch(const ctx::interrupted &e)
|
||||
{
|
||||
log::warning("IRCd main interrupted...");
|
||||
log::warning
|
||||
{
|
||||
"IRCd main interrupted..."
|
||||
};
|
||||
}
|
||||
#ifndef RB_DEBUG
|
||||
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
|
||||
// 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.
|
||||
log::critical("IRCd main exited: %s", e.what());
|
||||
log::critical
|
||||
{
|
||||
"IRCd main exited: %s", e.what()
|
||||
};
|
||||
}
|
||||
#else
|
||||
catch(...)
|
||||
|
@ -294,10 +302,13 @@ void
|
|||
ircd::set_runlevel(const enum runlevel &new_runlevel)
|
||||
try
|
||||
{
|
||||
log::debug("IRCd runlevel transition from '%s' to '%s'%s",
|
||||
log::debug
|
||||
{
|
||||
"IRCd runlevel transition from '%s' to '%s'%s",
|
||||
reflect(ircd::runlevel),
|
||||
reflect(new_runlevel),
|
||||
ircd::runlevel_changed? " (notifying user)" : "");
|
||||
ircd::runlevel_changed? " (notifying user)" : ""
|
||||
};
|
||||
|
||||
ircd::_runlevel = new_runlevel;
|
||||
|
||||
|
@ -308,19 +319,26 @@ try
|
|||
ios->post([new_runlevel]
|
||||
{
|
||||
if(new_runlevel == runlevel::HALT)
|
||||
log::notice("IRCd %s", reflect(new_runlevel));
|
||||
log::notice
|
||||
{
|
||||
"IRCd %s", reflect(new_runlevel)
|
||||
};
|
||||
|
||||
ircd::runlevel_changed(new_runlevel);
|
||||
});
|
||||
|
||||
if(new_runlevel != runlevel::HALT)
|
||||
log::notice("IRCd %s", reflect(new_runlevel));
|
||||
log::notice
|
||||
{
|
||||
"IRCd %s", reflect(new_runlevel)
|
||||
};
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
log::critical("IRCd runlevel change to '%s': %s",
|
||||
reflect(new_runlevel),
|
||||
e.what());
|
||||
log::critical
|
||||
{
|
||||
"IRCd runlevel change to '%s': %s", reflect(new_runlevel), e.what()
|
||||
};
|
||||
|
||||
ircd::terminate();
|
||||
}
|
||||
|
@ -346,7 +364,10 @@ ircd::read_conf(std::string filename)
|
|||
try
|
||||
{
|
||||
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())
|
||||
filename = fs::CPATH;
|
||||
|
@ -371,17 +392,22 @@ try
|
|||
|
||||
const json::object object{read};
|
||||
const size_t key_count{object.count()};
|
||||
log::info("Using configuration from: `%s': JSON object with %zu members in %zu bytes",
|
||||
log::info
|
||||
{
|
||||
"Using configuration from: `%s': JSON object with %zu members in %zu bytes",
|
||||
filename,
|
||||
key_count,
|
||||
read.size());
|
||||
read.size()
|
||||
};
|
||||
|
||||
return read;
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
log::error("Configuration @ `%s': %s",
|
||||
filename,
|
||||
e.what());
|
||||
log::error
|
||||
{
|
||||
"Configuration @ `%s': %s", filename, e.what()
|
||||
};
|
||||
|
||||
throw;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,10 @@ ircd::resource::find(string_view path)
|
|||
}
|
||||
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
|
||||
|
@ -50,17 +53,26 @@ ircd::resource::find(string_view path)
|
|||
{
|
||||
// Walk the iterator back to find if there is a directory prefixing this path.
|
||||
if(it == begin(resources))
|
||||
throw http::error(http::code::NOT_FOUND);
|
||||
throw http::error
|
||||
{
|
||||
http::code::NOT_FOUND
|
||||
};
|
||||
|
||||
--it;
|
||||
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
|
||||
// handle exact path matches.
|
||||
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;
|
||||
}
|
||||
|
@ -84,9 +96,16 @@ ircd::resource::resource(const string_view &path,
|
|||
,flags{opts.flags}
|
||||
,resources_it{[this, &path]
|
||||
{
|
||||
const auto iit(resources.emplace(this->path, this));
|
||||
const auto iit
|
||||
{
|
||||
resources.emplace(this->path, this)
|
||||
};
|
||||
|
||||
if(!iit.second)
|
||||
throw error("resource \"%s\" already registered", path);
|
||||
throw error
|
||||
{
|
||||
"resource \"%s\" already registered", path
|
||||
};
|
||||
|
||||
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()
|
||||
noexcept
|
||||
{
|
||||
log::info("Unregistered resource \"%s\"", path.empty()? string_view{"/"} : path);
|
||||
log::info
|
||||
{
|
||||
"Unregistered resource \"%s\"", path.empty()? string_view{"/"} : path
|
||||
};
|
||||
}
|
||||
|
||||
namespace ircd
|
||||
|
@ -205,9 +230,12 @@ catch(const m::error &)
|
|||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
log::error("X-Matrix Authorization from %s: %s",
|
||||
log::error
|
||||
{
|
||||
"X-Matrix Authorization from %s: %s",
|
||||
string(remote(client)),
|
||||
e.what());
|
||||
e.what()
|
||||
};
|
||||
|
||||
throw m::error
|
||||
{
|
||||
|
@ -379,9 +407,16 @@ ircd::resource::method::method(struct resource &resource,
|
|||
,opts{opts}
|
||||
,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)
|
||||
throw error("resource \"%s\" already registered", name);
|
||||
throw error
|
||||
{
|
||||
"resource \"%s\" already registered", name
|
||||
};
|
||||
|
||||
return unique_const_iterator<decltype(resource::methods)>
|
||||
{
|
||||
|
@ -660,7 +695,9 @@ ircd::resource::response::response(client &client,
|
|||
|
||||
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
|
||||
{
|
||||
"socket(%p) local[%s] remote[%s] HTTP %d %s in %ld$us; response in %ld$us (%s) content-length:%zu",
|
||||
client.sock.get(),
|
||||
string(local(client)),
|
||||
string(remote(client)),
|
||||
|
@ -669,5 +706,6 @@ ircd::resource::response::response(client &client,
|
|||
request_time,
|
||||
(client.request->timer.at<microseconds>().count() - request_time),
|
||||
content_type,
|
||||
content.size());
|
||||
content.size()
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue