mirror of
https://github.com/KingDuckZ/kamokan.git
synced 2025-10-02 15:00:02 +00:00
Add more logging and error checking.
This commit is contained in:
parent
60d9641538
commit
e2437a6b12
4 changed files with 50 additions and 19 deletions
|
@ -146,20 +146,27 @@ int main (int parArgc, char* parArgv[], char* parEnvp[]) {
|
||||||
|
|
||||||
auto statuslog = setup_logging(*settings);
|
auto statuslog = setup_logging(*settings);
|
||||||
SPDLOG_DEBUG(statuslog, "tawashi started");
|
SPDLOG_DEBUG(statuslog, "tawashi started");
|
||||||
statuslog->info("Loaded config: \"{}\"", config_file_path());
|
int retval = 0;
|
||||||
|
try {
|
||||||
|
statuslog->info("Loaded config: \"{}\"", config_file_path());
|
||||||
|
|
||||||
auto cgi_env = SafeStackObject<tawashi::cgi::Env>(parEnvp, settings->at("host_path"));
|
auto cgi_env = SafeStackObject<tawashi::cgi::Env>(parEnvp, settings->at("host_path"));
|
||||||
tawashi::ResponseFactory resp_factory(settings, cgi_env);
|
tawashi::ResponseFactory resp_factory(settings, cgi_env);
|
||||||
SPDLOG_TRACE(statuslog, "Registering makers in the response factory");
|
SPDLOG_TRACE(statuslog, "Registering makers in the response factory");
|
||||||
resp_factory.register_maker("index.cgi", &make_response<IndexResponse>);
|
resp_factory.register_maker("index.cgi", &make_response<IndexResponse>);
|
||||||
resp_factory.register_maker("", &make_response<IndexResponse>);
|
resp_factory.register_maker("", &make_response<IndexResponse>);
|
||||||
resp_factory.register_maker("paste.cgi", &make_response<SubmitPasteResponse>);
|
resp_factory.register_maker("paste.cgi", &make_response<SubmitPasteResponse>);
|
||||||
resp_factory.register_maker("error.cgi", &make_response<ErrorResponse>);
|
resp_factory.register_maker("error.cgi", &make_response<ErrorResponse>);
|
||||||
resp_factory.register_jolly_maker(&make_response<PastieResponse>);
|
resp_factory.register_jolly_maker(&make_response<PastieResponse>);
|
||||||
|
|
||||||
std::unique_ptr<Response> response = resp_factory.make_response(cgi_env->path_info());
|
std::unique_ptr<Response> response = resp_factory.make_response(cgi_env->path_info());
|
||||||
response->send();
|
response->send();
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
statuslog->critical("Uncaught exception in main(): \"{}\"", e.what());
|
||||||
|
retval = 1;
|
||||||
|
}
|
||||||
|
|
||||||
SPDLOG_DEBUG(statuslog, "tawashi done, quitting");
|
SPDLOG_DEBUG(statuslog, "tawashi done, quitting with {}", retval);
|
||||||
return 0;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,17 +88,36 @@ namespace cgi {
|
||||||
m_skip_path_info(0)
|
m_skip_path_info(0)
|
||||||
{
|
{
|
||||||
const std::string& path = m_cgi_env[CGIVars::PATH_INFO];
|
const std::string& path = m_cgi_env[CGIVars::PATH_INFO];
|
||||||
assert(parBasePath.size() <= path.size());
|
if (parBasePath.empty()) {
|
||||||
|
spdlog::get("statuslog")->error("Received base path is empty - this will likely cause Tawashi to malfunction");
|
||||||
|
}
|
||||||
|
else if (parBasePath.size() > path.size()) {
|
||||||
|
spdlog::get("statuslog")->error(
|
||||||
|
"Received base path \"{}\" has size {}, which is longer than PATH_INFO \"{}\" size {}",
|
||||||
|
std::string(parBasePath.begin(), parBasePath.end()),
|
||||||
|
parBasePath.size(),
|
||||||
|
path,
|
||||||
|
path.size()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else if (parBasePath[parBasePath.size() - 1] != '/') {
|
||||||
|
spdlog::get("statuslog")->warn(
|
||||||
|
"Received base path \"{}\" doesn't end with a '/' character",
|
||||||
|
std::string(parBasePath.begin(), parBasePath.end())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (boost::starts_with(path, parBasePath)) {
|
if (boost::starts_with(path, parBasePath)) {
|
||||||
m_skip_path_info = parBasePath.size();
|
m_skip_path_info = parBasePath.size();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
auto statuslog = spdlog::get("statuslog");
|
|
||||||
assert(statuslog);
|
|
||||||
std::string str_base_path(parBasePath.begin(), parBasePath.end());
|
std::string str_base_path(parBasePath.begin(), parBasePath.end());
|
||||||
std::string str_path(path.begin(), path.end());
|
std::string str_path(path.begin(), path.end());
|
||||||
statuslog->error("base path is not a prefix of PATH_INFO: base path={}, PATH_INFO={}, tawashi will most likely malfunction", str_base_path, str_path);
|
spdlog::get("statuslog")->error(
|
||||||
|
"base path is not a prefix of PATH_INFO: base path={}, PATH_INFO={}, tawashi will most likely malfunction",
|
||||||
|
str_base_path,
|
||||||
|
str_path
|
||||||
|
);
|
||||||
m_skip_path_info = 1; //try with the default, maybe the user is lucky and it will work (ie base path = /)
|
m_skip_path_info = 1; //try with the default, maybe the user is lucky and it will work (ie base path = /)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,7 @@ namespace tawashi {
|
||||||
|
|
||||||
std::string processed_pastie;
|
std::string processed_pastie;
|
||||||
if (m_syntax_highlight) {
|
if (m_syntax_highlight) {
|
||||||
|
//TODO: redirect to "pastie not found" if !pastie
|
||||||
processed_pastie = std::move(*pastie);
|
processed_pastie = std::move(*pastie);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "cgi_env.hpp"
|
#include "cgi_env.hpp"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <boost/container/flat_map.hpp>
|
#include <boost/container/flat_map.hpp>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
namespace tawashi {
|
namespace tawashi {
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -42,17 +43,20 @@ namespace tawashi {
|
||||||
ResponseFactory::~ResponseFactory() noexcept = default;
|
ResponseFactory::~ResponseFactory() noexcept = default;
|
||||||
|
|
||||||
std::unique_ptr<Response> ResponseFactory::make_response (const boost::string_ref& parName) {
|
std::unique_ptr<Response> ResponseFactory::make_response (const boost::string_ref& parName) {
|
||||||
//spdlog::get("statuslog")->info("making response object for \"{}\"", parName);
|
std::string name(parName.data(), parName.size());
|
||||||
|
spdlog::get("statuslog")->info("making response object for \"{}\"", name);
|
||||||
|
|
||||||
auto maker_it = m_local_data->makers.find(std::string(parName.data(), parName.size()));
|
auto maker_it = m_local_data->makers.find(name);
|
||||||
if (m_local_data->makers.end() != maker_it) {
|
if (m_local_data->makers.end() != maker_it) {
|
||||||
return maker_it->second(m_local_data->settings, m_local_data->cgi_env);
|
return maker_it->second(m_local_data->settings, m_local_data->cgi_env);
|
||||||
}
|
}
|
||||||
else if (m_local_data->jolly_maker) {
|
else if (m_local_data->jolly_maker) {
|
||||||
|
spdlog::get("statuslog")->info("no exact match found for \"{}\", assuming it's a pastie's token", name);
|
||||||
return m_local_data->jolly_maker(m_local_data->settings, m_local_data->cgi_env);
|
return m_local_data->jolly_maker(m_local_data->settings, m_local_data->cgi_env);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert(false);
|
assert(false);
|
||||||
|
spdlog::get("statuslog")->critical("no exact match found for \"{}\" and no jolly maker given, this should not happen", name);
|
||||||
return std::unique_ptr<Response>();
|
return std::unique_ptr<Response>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue