1
0
Fork 0
mirror of https://github.com/KingDuckZ/kamokan.git synced 2024-11-27 00:43:47 +00:00

Don't crash when a pastie doesn't exist, redirect to error page instead.

This commit is contained in:
King_DuckZ 2017-05-23 20:15:41 +01:00
parent 8b94672b25
commit 7549c0e664
4 changed files with 16 additions and 3 deletions

View file

@ -26,6 +26,7 @@ namespace tawashi {
UserFlooding,
UnkownReason,
RedisDisconnected,
MissingPostVariable
MissingPostVariable,
PastieNotFound
)
} //namespace tawashi

View file

@ -49,7 +49,8 @@ namespace tawashi {
"The pastie was not saved because the client is submitting too many pasties too quickly. Please wait a bit longer and try again.",
"An unknown error was raised.",
"Unable to connect to Redis.",
"Request is missing a POST variable."
"Request is missing a POST variable.",
"Pastie not found."
};
constexpr const auto lengths = string_lengths(err_descs);
static_assert(err_descs.static_size == lengths.static_size, "Mismatching array sizes between strings and their lengths");

View file

@ -43,11 +43,16 @@ namespace tawashi {
Response(parSettings, parStreamOut, parCgiEnv, true),
m_langmap_dir(parSettings->as<std::string>("langmap_dir")),
m_plain_text(false),
m_syntax_highlight(true)
m_syntax_highlight(true),
m_pastie_not_found(false)
{
}
HttpHeader PastieResponse::on_process() {
if (m_pastie_not_found) {
return make_error_redirect(ErrorReasons::PastieNotFound);
}
auto get = cgi_env().query_string_split();
const std::string& query_str(cgi_env().query_string());
if (get["m"] == "plain" or query_str.empty()) {
@ -78,6 +83,11 @@ namespace tawashi {
opt_string_list pastie_reply = redis.hmget(token, "pastie");
opt_string pastie = (pastie_reply and not pastie_reply->empty() ? (*pastie_reply)[0] : opt_string());
if (not pastie) {
m_pastie_not_found = true;
return;
}
srchilite::SourceHighlight highlighter;
highlighter.setDataDir(settings().as<std::string>("langmap_dir"));
highlighter.setGenerateEntireDoc(false);

View file

@ -42,5 +42,6 @@ namespace tawashi {
std::string m_langmap_dir;
bool m_plain_text;
bool m_syntax_highlight;
bool m_pastie_not_found;
};
} //namespace tawashi