1
0
Fork 0
mirror of https://github.com/KingDuckZ/kamokan.git synced 2025-05-10 09:13:30 +00:00

Change namespace of kamokan-specific stuff.

This commit is contained in:
King_DuckZ 2017-06-12 22:57:40 +01:00
parent a912b1e3d4
commit e5f7f60e8b
32 changed files with 268 additions and 246 deletions

View file

@ -57,16 +57,16 @@ namespace {
} }
template <typename T> template <typename T>
std::unique_ptr<tawashi::Response> make_response ( std::unique_ptr<kamokan::Response> make_response (
const Kakoune::SafePtr<tawashi::SettingsBag>& parSettings, const Kakoune::SafePtr<kamokan::SettingsBag>& parSettings,
const Kakoune::SafePtr<tawashi::cgi::Env>& parCgiEnv const Kakoune::SafePtr<kamokan::cgi::Env>& parCgiEnv
) { ) {
return static_cast<std::unique_ptr<tawashi::Response>>( return static_cast<std::unique_ptr<kamokan::Response>>(
std::make_unique<T>(parSettings, &std::cout, parCgiEnv) std::make_unique<T>(parSettings, &std::cout, parCgiEnv)
); );
} }
void fill_defaults (tawashi::SettingsBag& parSettings) { void fill_defaults (kamokan::SettingsBag& parSettings) {
parSettings.add_default("redis_server", "127.0.0.1"); parSettings.add_default("redis_server", "127.0.0.1");
parSettings.add_default("redis_port", "6379"); parSettings.add_default("redis_port", "6379");
parSettings.add_default("redis_mode", "sock"); parSettings.add_default("redis_mode", "sock");
@ -105,9 +105,9 @@ namespace {
std::cout << "config_file_path(): \"" << config_file_path() << "\"\n"; std::cout << "config_file_path(): \"" << config_file_path() << "\"\n";
} }
curry::SafeStackObject<tawashi::IniFile> load_ini() { curry::SafeStackObject<kamokan::IniFile> load_ini() {
using curry::SafeStackObject; using curry::SafeStackObject;
using tawashi::IniFile; using kamokan::IniFile;
using std::istream_iterator; using std::istream_iterator;
std::ifstream conf(config_file_path()); std::ifstream conf(config_file_path());
@ -115,7 +115,7 @@ namespace {
return SafeStackObject<IniFile>(istream_iterator<char>(conf), istream_iterator<char>()); return SafeStackObject<IniFile>(istream_iterator<char>(conf), istream_iterator<char>());
} }
std::shared_ptr<spdlog::logger> setup_logging (const tawashi::SettingsBag& parSettings) { std::shared_ptr<spdlog::logger> setup_logging (const kamokan::SettingsBag& parSettings) {
//Prepare the logger //Prepare the logger
spdlog::set_pattern("[%Y-%m-%d %T %z] - %v"); spdlog::set_pattern("[%Y-%m-%d %T %z] - %v");
spdlog::set_level(spdlog::level::trace); //set to maximum possible here spdlog::set_level(spdlog::level::trace); //set to maximum possible here
@ -134,12 +134,12 @@ namespace {
int main (int parArgc, char* parArgv[], char* parEnvp[]) { int main (int parArgc, char* parArgv[], char* parEnvp[]) {
using curry::SafeStackObject; using curry::SafeStackObject;
using tawashi::IndexResponse; using kamokan::IndexResponse;
using tawashi::SubmitPasteResponse; using kamokan::SubmitPasteResponse;
using tawashi::QuickSubmitPasteResponse; using kamokan::QuickSubmitPasteResponse;
using tawashi::PastieResponse; using kamokan::PastieResponse;
using tawashi::ErrorResponse; using kamokan::ErrorResponse;
using tawashi::Response; using kamokan::Response;
using tawashi::RequestMethodType; using tawashi::RequestMethodType;
if (2 == parArgc and boost::string_view(parArgv[1]) == "--show-paths") { if (2 == parArgc and boost::string_view(parArgv[1]) == "--show-paths") {
@ -147,8 +147,8 @@ int main (int parArgc, char* parArgv[], char* parEnvp[]) {
return 0; return 0;
} }
SafeStackObject<tawashi::IniFile> ini = load_ini(); SafeStackObject<kamokan::IniFile> ini = load_ini();
auto settings = SafeStackObject<tawashi::SettingsBag>(ini, "kamokan"); auto settings = SafeStackObject<kamokan::SettingsBag>(ini, "kamokan");
fill_defaults(*settings); fill_defaults(*settings);
auto statuslog = setup_logging(*settings); auto statuslog = setup_logging(*settings);
@ -158,7 +158,7 @@ int main (int parArgc, char* parArgv[], char* parEnvp[]) {
statuslog->info("Loaded config: \"{}\"", config_file_path()); 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); kamokan::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", RequestMethodType::GET, &make_response<IndexResponse>); resp_factory.register_maker("index.cgi", RequestMethodType::GET, &make_response<IndexResponse>);
resp_factory.register_maker("", RequestMethodType::GET, &make_response<IndexResponse>); resp_factory.register_maker("", RequestMethodType::GET, &make_response<IndexResponse>);

View file

@ -47,8 +47,8 @@ target_compile_definitions(${PROJECT_NAME}
PRIVATE BOOST_SPIRIT_USE_PHOENIX_V3=1 PRIVATE BOOST_SPIRIT_USE_PHOENIX_V3=1
PUBLIC $<$<CONFIG:Debug>:SPDLOG_DEBUG_ON> PUBLIC $<$<CONFIG:Debug>:SPDLOG_DEBUG_ON>
PUBLIC $<$<CONFIG:Debug>:SPDLOG_TRACE_ON> PUBLIC $<$<CONFIG:Debug>:SPDLOG_TRACE_ON>
PUBLIC $<$<BOOL:${BUILD_TESTING}>:tawashi_virtual_testing=virtual> PUBLIC $<$<BOOL:${BUILD_TESTING}>:kamokan_virtual_testing=virtual>
PUBLIC $<$<NOT:$<BOOL:${BUILD_TESTING}>>:tawashi_virtual_testing=> PUBLIC $<$<NOT:$<BOOL:${BUILD_TESTING}>>:kamokan_virtual_testing=>
PUBLIC $<$<BOOL:${BUILD_TESTING}>:KAMOKAN_WITH_TESTING> PUBLIC $<$<BOOL:${BUILD_TESTING}>:KAMOKAN_WITH_TESTING>
) )
target_compile_options(${PROJECT_NAME} target_compile_options(${PROJECT_NAME}

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "error_response.hpp" #include "error_response.hpp"
@ -26,7 +26,7 @@
#include <string> #include <string>
#include <cassert> #include <cassert>
namespace tawashi { namespace kamokan {
ErrorResponse::ErrorResponse ( ErrorResponse::ErrorResponse (
const Kakoune::SafePtr<SettingsBag>& parSettings, const Kakoune::SafePtr<SettingsBag>& parSettings,
std::ostream* parStreamOut, std::ostream* parStreamOut,
@ -37,6 +37,8 @@ namespace tawashi {
} }
void ErrorResponse::on_mustache_prepare (mstch::map& parContext) { void ErrorResponse::on_mustache_prepare (mstch::map& parContext) {
using tawashi::ErrorReasons;
auto get = cgi_env().query_string_split(); auto get = cgi_env().query_string_split();
const int reason_int = boost::lexical_cast<int>(get["reason"]); const int reason_int = boost::lexical_cast<int>(get["reason"]);
ErrorReasons reason_code(ErrorReasons::UnkownReason); ErrorReasons reason_code(ErrorReasons::UnkownReason);
@ -55,7 +57,7 @@ namespace tawashi {
"Unsupported CONTENT_TYPE.", "Unsupported CONTENT_TYPE.",
"Invalid pastie token." "Invalid pastie token."
}; };
constexpr const auto lengths = string_lengths(err_descs); constexpr const auto lengths = tawashi::string_lengths(err_descs);
static_assert(err_descs.static_size == lengths.static_size, "Mismatching array sizes between strings and their lengths"); static_assert(err_descs.static_size == lengths.static_size, "Mismatching array sizes between strings and their lengths");
#if !defined(NDEBUG) #if !defined(NDEBUG)
@ -67,4 +69,4 @@ namespace tawashi {
parContext["error_message"] = std::string(err_descs[reason_code], lengths[reason_code]); parContext["error_message"] = std::string(err_descs[reason_code], lengths[reason_code]);
parContext["error_id"] = std::to_string(reason_code); parContext["error_id"] = std::to_string(reason_code);
} }
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
@ -20,7 +20,7 @@
#include "response.hpp" #include "response.hpp"
#include <boost/utility/string_view.hpp> #include <boost/utility/string_view.hpp>
namespace tawashi { namespace kamokan {
class ErrorResponse : public Response { class ErrorResponse : public Response {
public: public:
ErrorResponse ( ErrorResponse (
@ -35,5 +35,5 @@ namespace tawashi {
private: private:
virtual void on_mustache_prepare (mstch::map& parContext) override; virtual void on_mustache_prepare (mstch::map& parContext) override;
}; };
} //namespace tawashi } //namespace kamokan

View file

@ -1,24 +1,24 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "index_response.hpp" #include "index_response.hpp"
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
namespace tawashi { namespace kamokan {
IndexResponse::IndexResponse ( IndexResponse::IndexResponse (
const Kakoune::SafePtr<SettingsBag>& parSettings, const Kakoune::SafePtr<SettingsBag>& parSettings,
std::ostream* parStreamOut, std::ostream* parStreamOut,
@ -27,5 +27,5 @@ namespace tawashi {
Response(parSettings, parStreamOut, parCgiEnv, false) Response(parSettings, parStreamOut, parCgiEnv, false)
{ {
} }
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
@ -20,7 +20,7 @@
#include "response.hpp" #include "response.hpp"
#include <boost/utility/string_view.hpp> #include <boost/utility/string_view.hpp>
namespace tawashi { namespace kamokan {
class IndexResponse : public Response { class IndexResponse : public Response {
public: public:
IndexResponse ( IndexResponse (
@ -34,4 +34,4 @@ namespace tawashi {
private: private:
}; };
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "ini_file.hpp" #include "ini_file.hpp"
@ -41,7 +41,7 @@
#include <type_traits> #include <type_traits>
#include <iterator> #include <iterator>
namespace tawashi { namespace kamokan {
namespace { namespace {
typedef boost::string_view string_type; typedef boost::string_view string_type;
@ -144,4 +144,4 @@ namespace tawashi {
} }
IniFile::~IniFile() noexcept = default; IniFile::~IniFile() noexcept = default;
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
@ -24,7 +24,7 @@
#include <string> #include <string>
#include <cassert> #include <cassert>
namespace tawashi { namespace kamokan {
class IniFile : public Kakoune::SafeCountable { class IniFile : public Kakoune::SafeCountable {
public: public:
typedef boost::container::flat_map<boost::string_view, boost::string_view> KeyValueMapType; typedef boost::container::flat_map<boost::string_view, boost::string_view> KeyValueMapType;
@ -55,4 +55,4 @@ namespace tawashi {
assert(parse_success()); assert(parse_success());
return m_map; return m_map;
} }
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "list_highlight_langs.hpp" #include "list_highlight_langs.hpp"
@ -22,7 +22,7 @@
#include <boost/range/algorithm/copy.hpp> #include <boost/range/algorithm/copy.hpp>
#include <boost/range/iterator_range_core.hpp> #include <boost/range/iterator_range_core.hpp>
namespace tawashi { namespace kamokan {
HighlightLangList list_highlight_langs (const SettingsBag& parSettings) { HighlightLangList list_highlight_langs (const SettingsBag& parSettings) {
srchilite::LangMap lang_map(parSettings.as<std::string>("langmap_dir"), "lang.map"); srchilite::LangMap lang_map(parSettings.as<std::string>("langmap_dir"), "lang.map");
lang_map.open(); lang_map.open();
@ -30,5 +30,5 @@ namespace tawashi {
const auto lang_range = boost::make_iterator_range(lang_map.begin(), lang_map.end()); const auto lang_range = boost::make_iterator_range(lang_map.begin(), lang_map.end());
return boost::copy_range<HighlightLangList>(lang_range | boost::adaptors::map_keys); return boost::copy_range<HighlightLangList>(lang_range | boost::adaptors::map_keys);
} }
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
@ -20,9 +20,9 @@
#include <vector> #include <vector>
#include <string> #include <string>
namespace tawashi { namespace kamokan {
class SettingsBag; class SettingsBag;
typedef std::vector<std::string> HighlightLangList; typedef std::vector<std::string> HighlightLangList;
HighlightLangList list_highlight_langs (const SettingsBag& parSettings); HighlightLangList list_highlight_langs (const SettingsBag& parSettings);
} //namespace tawashi } //namespace kamokan

View file

@ -1,24 +1,24 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "num_to_token.hpp" #include "num_to_token.hpp"
#include <cassert> #include <cassert>
namespace tawashi { namespace kamokan {
namespace { namespace {
//const int g_any_min = 0; //const int g_any_min = 0;
//const int g_any_max = g_any_min + 'z' - 'a' - 1; //const int g_any_max = g_any_min + 'z' - 'a' - 1;
@ -61,4 +61,4 @@ namespace tawashi {
return retval; return retval;
} }
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
@ -21,6 +21,6 @@
#include <string> #include <string>
#include <cstdint> #include <cstdint>
namespace tawashi { namespace kamokan {
std::string num_to_token (int64_t parNum) a_pure; std::string num_to_token (int64_t parNum) a_pure;
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "pastie_response.hpp" #include "pastie_response.hpp"
@ -32,7 +32,7 @@
#include <boost/algorithm/string/finder.hpp> #include <boost/algorithm/string/finder.hpp>
#include <boost/range/adaptor/transformed.hpp> #include <boost/range/adaptor/transformed.hpp>
namespace tawashi { namespace kamokan {
namespace { namespace {
const char g_nolang_token[] = "colourless"; const char g_nolang_token[] = "colourless";
@ -101,7 +101,9 @@ namespace tawashi {
{ {
} }
HttpHeader PastieResponse::on_process() { tawashi::HttpHeader PastieResponse::on_process() {
using tawashi::ErrorReasons;
if (m_pastie_not_found) if (m_pastie_not_found)
return make_error_redirect(ErrorReasons::PastieNotFound); return make_error_redirect(ErrorReasons::PastieNotFound);
if (m_token_invalid) if (m_token_invalid)
@ -111,7 +113,7 @@ namespace tawashi {
const std::string& query_str(cgi_env().query_string()); const std::string& query_str(cgi_env().query_string());
if (get["m"] == "plain" or query_str.empty()) { if (get["m"] == "plain" or query_str.empty()) {
m_plain_text = true; m_plain_text = true;
return make_header_type_text_utf8(); return tawashi::make_header_type_text_utf8();
} }
else if (query_str == g_nolang_token) { else if (query_str == g_nolang_token) {
m_syntax_highlight = false; m_syntax_highlight = false;
@ -125,7 +127,7 @@ namespace tawashi {
if (m_lang_file.empty()) if (m_lang_file.empty())
m_lang_file = "default.lang"; m_lang_file = "default.lang";
} }
return make_header_type_html(); return tawashi::make_header_type_html();
} }
void PastieResponse::on_mustache_prepare (mstch::map& parContext) { void PastieResponse::on_mustache_prepare (mstch::map& parContext) {
@ -161,7 +163,7 @@ namespace tawashi {
processed_pastie = std::move(*pastie); processed_pastie = std::move(*pastie);
} }
else { else {
Escapist houdini; tawashi::Escapist houdini;
std::ostringstream oss; std::ostringstream oss;
oss << R"(<pre><tt><font color="#EDEDED">)"; oss << R"(<pre><tt><font color="#EDEDED">)";
oss << houdini.escape_html(*pastie) << "</font></tt></pre>\n"; oss << houdini.escape_html(*pastie) << "</font></tt></pre>\n";
@ -187,4 +189,4 @@ namespace tawashi {
else else
return load_mustache(); return load_mustache();
} }
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
@ -21,7 +21,7 @@
#include <string> #include <string>
#include <boost/utility/string_view.hpp> #include <boost/utility/string_view.hpp>
namespace tawashi { namespace kamokan {
class PastieResponse : public Response { class PastieResponse : public Response {
public: public:
PastieResponse ( PastieResponse (
@ -34,7 +34,7 @@ namespace tawashi {
virtual boost::string_view page_basename() const override { return boost::string_view("pastie"); } virtual boost::string_view page_basename() const override { return boost::string_view("pastie"); }
private: private:
virtual HttpHeader on_process() override; virtual tawashi::HttpHeader on_process() override;
virtual void on_mustache_prepare (mstch::map& parContext) override; virtual void on_mustache_prepare (mstch::map& parContext) override;
virtual std::string on_mustache_retrieve() override; virtual std::string on_mustache_retrieve() override;
@ -45,4 +45,4 @@ namespace tawashi {
bool m_pastie_not_found; bool m_pastie_not_found;
bool m_token_invalid; bool m_token_invalid;
}; };
} //namespace tawashi } //namespace kamokan

View file

@ -1,23 +1,23 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "quick_submit_paste_response.hpp" #include "quick_submit_paste_response.hpp"
namespace tawashi { namespace kamokan {
QuickSubmitPasteResponse::QuickSubmitPasteResponse ( QuickSubmitPasteResponse::QuickSubmitPasteResponse (
const Kakoune::SafePtr<SettingsBag>& parSettings, const Kakoune::SafePtr<SettingsBag>& parSettings,
std::ostream* parStreamOut, std::ostream* parStreamOut,
@ -35,8 +35,8 @@ namespace tawashi {
return "{{base_uri}}/{{redirect_to_address}}\n"; return "{{base_uri}}/{{redirect_to_address}}\n";
} }
HttpHeader QuickSubmitPasteResponse::make_success_response (std::string&& parPastieParam) { tawashi::HttpHeader QuickSubmitPasteResponse::make_success_response (std::string&& parPastieParam) {
m_redirect_to = std::move(parPastieParam); m_redirect_to = std::move(parPastieParam);
return HttpHeader(); return tawashi::HttpHeader();
} }
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
@ -22,7 +22,7 @@
#include <boost/utility/string_view.hpp> #include <boost/utility/string_view.hpp>
#include <cassert> #include <cassert>
namespace tawashi { namespace kamokan {
class QuickSubmitPasteResponse : public SubmitPasteResponse { class QuickSubmitPasteResponse : public SubmitPasteResponse {
public: public:
QuickSubmitPasteResponse ( QuickSubmitPasteResponse (
@ -33,7 +33,7 @@ namespace tawashi {
protected: protected:
virtual boost::string_view page_basename() const override { assert(false); return boost::string_view(""); } virtual boost::string_view page_basename() const override { assert(false); return boost::string_view(""); }
virtual HttpHeader make_success_response (std::string&& parPastieParam) override; virtual tawashi::HttpHeader make_success_response (std::string&& parPastieParam) override;
private: private:
virtual void on_mustache_prepare (mstch::map& parContext) override; virtual void on_mustache_prepare (mstch::map& parContext) override;
@ -41,4 +41,4 @@ namespace tawashi {
std::string m_redirect_to; std::string m_redirect_to;
}; };
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "response.hpp" #include "response.hpp"
@ -34,7 +34,7 @@
#include <cstdint> #include <cstdint>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
namespace tawashi { namespace kamokan {
namespace { namespace {
//boost::string_ref fetch_page_basename (const cgi::Env& parEnv) { //boost::string_ref fetch_page_basename (const cgi::Env& parEnv) {
// const boost::string_ref& path = parEnv.path_info(); // const boost::string_ref& path = parEnv.path_info();
@ -115,7 +115,7 @@ namespace tawashi {
oss << ':' << port; oss << ':' << port;
} }
} }
else if (not host_port.empty() and seems_valid_number<uint16_t>(host_port)) { else if (not host_port.empty() and tawashi::seems_valid_number<uint16_t>(host_port)) {
oss << ':' << host_port; oss << ':' << host_port;
} }
} }
@ -159,8 +159,8 @@ namespace tawashi {
Response::~Response() noexcept = default; Response::~Response() noexcept = default;
HttpHeader Response::on_process() { tawashi::HttpHeader Response::on_process() {
return HttpHeader(); return tawashi::HttpHeader();
} }
void Response::on_mustache_prepare (mstch::map&) { void Response::on_mustache_prepare (mstch::map&) {
@ -183,7 +183,7 @@ namespace tawashi {
m_storage.finalize_connection(); m_storage.finalize_connection();
SPDLOG_TRACE(statuslog, "Raising event on_process"); SPDLOG_TRACE(statuslog, "Raising event on_process");
HttpHeader http_header = this->on_process(); tawashi::HttpHeader http_header = this->on_process();
*m_stream_out << http_header; *m_stream_out << http_header;
if (http_header.body_required()) { if (http_header.body_required()) {
@ -239,17 +239,19 @@ namespace tawashi {
return *m_settings; return *m_settings;
} }
HttpHeader Response::make_redirect (HttpStatusCodes parCode, const std::string& parLocation) { tawashi::HttpHeader Response::make_redirect (tawashi::HttpStatusCodes parCode, const std::string& parLocation) {
std::ostringstream oss; std::ostringstream oss;
oss << base_uri() << '/' << parLocation; oss << base_uri() << '/' << parLocation;
auto statuslog = spdlog::get("statuslog"); auto statuslog = spdlog::get("statuslog");
assert(statuslog); assert(statuslog);
statuslog->info("Redirecting to page \"{}\"", oss.str()); statuslog->info("Redirecting to page \"{}\"", oss.str());
return HttpHeader(parCode, oss.str()); return tawashi::HttpHeader(parCode, oss.str());
} }
HttpHeader Response::make_error_redirect (ErrorReasons parReason) { tawashi::HttpHeader Response::make_error_redirect (tawashi::ErrorReasons parReason) {
using tawashi::HttpStatusCodes;
auto statuslog = spdlog::get("statuslog"); auto statuslog = spdlog::get("statuslog");
assert(statuslog); assert(statuslog);
const HttpStatusCodes redir_code = HttpStatusCodes::Code302_Found; const HttpStatusCodes redir_code = HttpStatusCodes::Code302_Found;
@ -259,4 +261,4 @@ namespace tawashi {
oss << "error.cgi?reason=" << parReason._to_integral(); oss << "error.cgi?reason=" << parReason._to_integral();
return make_redirect(redir_code, oss.str()); return make_redirect(redir_code, oss.str());
} }
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
@ -29,11 +29,14 @@
#include <memory> #include <memory>
namespace tawashi { namespace tawashi {
class SettingsBag;
namespace cgi { namespace cgi {
class Env; class Env;
} //namespace cgi } //namespace cgi
} //namespace tawashi
namespace kamokan {
class SettingsBag;
namespace cgi = tawashi::cgi;
class Response { class Response {
public: public:
@ -50,18 +53,18 @@ namespace tawashi {
); );
const cgi::Env& cgi_env() const; const cgi::Env& cgi_env() const;
tawashi_virtual_testing const cgi::PostMapType& cgi_post() const; kamokan_virtual_testing const cgi::PostMapType& cgi_post() const;
const std::string& base_uri() const; const std::string& base_uri() const;
virtual boost::string_view page_basename() const = 0; virtual boost::string_view page_basename() const = 0;
tawashi_virtual_testing const Storage& storage() const; kamokan_virtual_testing const Storage& storage() const;
const SettingsBag& settings() const; const SettingsBag& settings() const;
virtual std::string load_mustache() const; virtual std::string load_mustache() const;
HttpHeader make_redirect (HttpStatusCodes parCode, const std::string& parLocation); tawashi::HttpHeader make_redirect (tawashi::HttpStatusCodes parCode, const std::string& parLocation);
HttpHeader make_error_redirect (ErrorReasons parReason); tawashi::HttpHeader make_error_redirect (tawashi::ErrorReasons parReason);
private: private:
virtual HttpHeader on_process(); virtual tawashi::HttpHeader on_process();
virtual void on_mustache_prepare (mstch::map& parContext); virtual void on_mustache_prepare (mstch::map& parContext);
virtual std::string on_mustache_retrieve(); virtual std::string on_mustache_retrieve();
@ -72,4 +75,4 @@ namespace tawashi {
std::string m_base_uri; std::string m_base_uri;
std::ostream* m_stream_out; std::ostream* m_stream_out;
}; };
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "response_factory.hpp" #include "response_factory.hpp"
@ -24,7 +24,7 @@
#include <algorithm> #include <algorithm>
#include <array> #include <array>
namespace tawashi { namespace kamokan {
namespace { namespace {
} //unnamed namespace } //unnamed namespace
@ -32,11 +32,11 @@ namespace tawashi {
Kakoune::SafePtr<SettingsBag> settings; Kakoune::SafePtr<SettingsBag> settings;
boost::container::flat_map<std::string, ResponseMakerFunc> makers_get; boost::container::flat_map<std::string, ResponseMakerFunc> makers_get;
boost::container::flat_map<std::string, ResponseMakerFunc> makers_post; boost::container::flat_map<std::string, ResponseMakerFunc> makers_post;
std::array<ResponseMakerFunc, RequestMethodType::_size()> jolly_makers; std::array<ResponseMakerFunc, tawashi::RequestMethodType::_size()> jolly_makers;
Kakoune::SafePtr<cgi::Env> cgi_env; Kakoune::SafePtr<tawashi::cgi::Env> cgi_env;
}; };
ResponseFactory::ResponseFactory (const Kakoune::SafePtr<SettingsBag>& parSettings, const Kakoune::SafePtr<cgi::Env>& parCgiEnv) : ResponseFactory::ResponseFactory (const Kakoune::SafePtr<SettingsBag>& parSettings, const Kakoune::SafePtr<tawashi::cgi::Env>& parCgiEnv) :
m_local_data(std::make_unique<LocalData>()) m_local_data(std::make_unique<LocalData>())
{ {
m_local_data->settings = parSettings; m_local_data->settings = parSettings;
@ -46,7 +46,7 @@ namespace tawashi {
ResponseFactory::~ResponseFactory() noexcept = default; ResponseFactory::~ResponseFactory() noexcept = default;
std::unique_ptr<Response> ResponseFactory::make_response (const boost::string_view& parName, RequestMethodType parReqType) { std::unique_ptr<Response> ResponseFactory::make_response (const boost::string_view& parName, tawashi::RequestMethodType parReqType) {
std::string name(parName.data(), parName.size()); std::string name(parName.data(), parName.size());
spdlog::get("statuslog")->info( spdlog::get("statuslog")->info(
"making response object for \"{}\" method {}", "making response object for \"{}\" method {}",
@ -54,7 +54,11 @@ namespace tawashi {
parReqType._to_string() parReqType._to_string()
); );
const auto& makers = (static_cast<RequestMethodType>(RequestMethodType::POST) == parReqType ? m_local_data->makers_post : m_local_data->makers_get); const auto& makers = (
static_cast<tawashi::RequestMethodType>(tawashi::RequestMethodType::POST) == parReqType ?
m_local_data->makers_post : m_local_data->makers_get
);
auto maker_it = makers.find(name); auto maker_it = makers.find(name);
if (makers.end() != maker_it) { if (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);
@ -74,18 +78,18 @@ namespace tawashi {
m_local_data->makers_post[std::move(parName)] = parMaker; m_local_data->makers_post[std::move(parName)] = parMaker;
} }
void ResponseFactory::register_maker (std::string&& parName, RequestMethodType parReqType, ResponseMakerFunc parMaker) { void ResponseFactory::register_maker (std::string&& parName, tawashi::RequestMethodType parReqType, ResponseMakerFunc parMaker) {
switch (parReqType) { switch (parReqType) {
case RequestMethodType::GET: case tawashi::RequestMethodType::GET:
m_local_data->makers_get[std::move(parName)] = parMaker; m_local_data->makers_get[std::move(parName)] = parMaker;
break; break;
case RequestMethodType::POST: case tawashi::RequestMethodType::POST:
m_local_data->makers_post[std::move(parName)] = parMaker; m_local_data->makers_post[std::move(parName)] = parMaker;
break; break;
}; };
} }
void ResponseFactory::register_jolly_maker (ResponseMakerFunc parMaker, RequestMethodType parReqType) { void ResponseFactory::register_jolly_maker (ResponseMakerFunc parMaker, tawashi::RequestMethodType parReqType) {
m_local_data->jolly_makers[parReqType] = parMaker; m_local_data->jolly_makers[parReqType] = parMaker;
} }
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
@ -23,27 +23,30 @@
#include <memory> #include <memory>
namespace tawashi { namespace tawashi {
class SettingsBag;
namespace cgi { namespace cgi {
class Env; class Env;
} //namespace cgi } //namespace cgi
} //namespace tawashi
namespace kamokan {
class SettingsBag;
namespace cgi = tawashi::cgi;
class ResponseFactory { class ResponseFactory {
public: public:
typedef std::function<std::unique_ptr<Response>(const Kakoune::SafePtr<SettingsBag>&, const Kakoune::SafePtr<cgi::Env>& parCgiEnv)> ResponseMakerFunc; typedef std::function<std::unique_ptr<Response>(const Kakoune::SafePtr<SettingsBag>&, const Kakoune::SafePtr<tawashi::cgi::Env>& parCgiEnv)> ResponseMakerFunc;
explicit ResponseFactory (const Kakoune::SafePtr<SettingsBag>& parSettings, const Kakoune::SafePtr<cgi::Env>& parCgiEnv); explicit ResponseFactory (const Kakoune::SafePtr<SettingsBag>& parSettings, const Kakoune::SafePtr<tawashi::cgi::Env>& parCgiEnv);
~ResponseFactory() noexcept; ~ResponseFactory() noexcept;
std::unique_ptr<Response> make_response(const boost::string_view& parName, RequestMethodType parReqType); std::unique_ptr<Response> make_response(const boost::string_view& parName, tawashi::RequestMethodType parReqType);
void register_maker (std::string&& parName, ResponseMakerFunc parMaker); void register_maker (std::string&& parName, ResponseMakerFunc parMaker);
void register_maker (std::string&& parName, RequestMethodType parReqType, ResponseMakerFunc parMaker); void register_maker (std::string&& parName, tawashi::RequestMethodType parReqType, ResponseMakerFunc parMaker);
void register_jolly_maker (ResponseMakerFunc parMaker, RequestMethodType parReqType); void register_jolly_maker (ResponseMakerFunc parMaker, tawashi::RequestMethodType parReqType);
private: private:
struct LocalData; struct LocalData;
std::unique_ptr<LocalData> m_local_data; std::unique_ptr<LocalData> m_local_data;
}; };
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "settings_bag.hpp" #include "settings_bag.hpp"
@ -24,9 +24,9 @@
#include <sstream> #include <sstream>
#include <iostream> #include <iostream>
namespace tawashi { namespace kamokan {
namespace { namespace {
const IniFile::KeyValueMapType* get_tawashi_node (const IniFile& parIni, boost::string_view parSectionName) { const IniFile::KeyValueMapType* get_kamokan_node (const IniFile& parIni, boost::string_view parSectionName) {
auto it_found = parIni.parsed().find(parSectionName); auto it_found = parIni.parsed().find(parSectionName);
if (parIni.parsed().end() != it_found) { if (parIni.parsed().end() != it_found) {
return &it_found->second; return &it_found->second;
@ -41,7 +41,7 @@ namespace tawashi {
SettingsBag::SettingsBag (const Kakoune::SafePtr<IniFile>& parIni, boost::string_view parSectionName) : SettingsBag::SettingsBag (const Kakoune::SafePtr<IniFile>& parIni, boost::string_view parSectionName) :
m_ini(parIni), m_ini(parIni),
m_values(get_tawashi_node(*parIni, parSectionName)) m_values(get_kamokan_node(*parIni, parSectionName))
{ {
assert(m_values); assert(m_values);
} }
@ -97,4 +97,4 @@ namespace tawashi {
template bool SettingsBag::as<bool> (boost::string_view parIndex) const; template bool SettingsBag::as<bool> (boost::string_view parIndex) const;
template uint16_t SettingsBag::as<uint16_t> (boost::string_view parIndex) const; template uint16_t SettingsBag::as<uint16_t> (boost::string_view parIndex) const;
template uint32_t SettingsBag::as<uint32_t> (boost::string_view parIndex) const; template uint32_t SettingsBag::as<uint32_t> (boost::string_view parIndex) const;
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
@ -27,7 +27,7 @@
#include <functional> #include <functional>
#include <string> #include <string>
namespace tawashi { namespace kamokan {
class SettingsBag : public Kakoune::SafeCountable { class SettingsBag : public Kakoune::SafeCountable {
typedef std::map<boost::string_view, boost::string_view> MapType; typedef std::map<boost::string_view, boost::string_view> MapType;
public: public:
@ -56,4 +56,4 @@ namespace tawashi {
#endif #endif
return (*this)[parIndex]; return (*this)[parIndex];
} }
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "storage.hpp" #include "storage.hpp"
@ -28,7 +28,7 @@
#include <utility> #include <utility>
#include <algorithm> #include <algorithm>
namespace tawashi { namespace kamokan {
namespace { namespace {
redis::IncRedis make_incredis (const SettingsBag& parSettings) { redis::IncRedis make_incredis (const SettingsBag& parSettings) {
using redis::IncRedis; using redis::IncRedis;
@ -48,10 +48,11 @@ namespace tawashi {
} }
Storage::SubmissionResult make_submission_result (std::string&& parToken) { Storage::SubmissionResult make_submission_result (std::string&& parToken) {
using tawashi::ErrorReasons;
return Storage::SubmissionResult { std::move(parToken), boost::optional<ErrorReasons>() }; return Storage::SubmissionResult { std::move(parToken), boost::optional<ErrorReasons>() };
} }
Storage::SubmissionResult make_submission_result (ErrorReasons parError) { Storage::SubmissionResult make_submission_result (tawashi::ErrorReasons parError) {
return Storage::SubmissionResult { std::string(), boost::make_optional(parError) }; return Storage::SubmissionResult { std::string(), boost::make_optional(parError) };
} }
} //unnamed namespace } //unnamed namespace
@ -84,7 +85,7 @@ namespace tawashi {
m_redis->wait_for_connect(); m_redis->wait_for_connect();
auto batch = m_redis->make_batch(); auto batch = m_redis->make_batch();
batch.select(m_settings->as<uint32_t>("redis_db")); batch.select(m_settings->as<uint32_t>("redis_db"));
batch.client_setname("tawashi_v" STRINGIZE(VERSION_MAJOR) "." STRINGIZE(VERSION_MINOR) "." STRINGIZE(VERSION_PATCH)); batch.client_setname("kamokan_v" STRINGIZE(VERSION_MAJOR) "." STRINGIZE(VERSION_MINOR) "." STRINGIZE(VERSION_PATCH));
batch.throw_if_failed(); batch.throw_if_failed();
} }
} }
@ -95,6 +96,8 @@ namespace tawashi {
const boost::string_view& parLang, const boost::string_view& parLang,
const std::string& parRemoteIP const std::string& parRemoteIP
) const { ) const {
using tawashi::ErrorReasons;
if (not is_connected()) if (not is_connected())
return make_submission_result(ErrorReasons::RedisDisconnected); return make_submission_result(ErrorReasons::RedisDisconnected);
@ -110,7 +113,7 @@ namespace tawashi {
statuslog->info( statuslog->info(
"Submitting pastie of size {} to redis -> \"{}\"", "Submitting pastie of size {} to redis -> \"{}\"",
parText.size(), parText.size(),
truncated_string(parText, 30) tawashi::truncated_string(parText, 30)
); );
} }
@ -155,4 +158,4 @@ namespace tawashi {
return *m_settings; return *m_settings;
} }
#endif #endif
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
@ -29,30 +29,30 @@ namespace redis {
class IncRedis; class IncRedis;
} //namespace redis } //namespace redis
namespace tawashi { namespace kamokan {
class SettingsBag; class SettingsBag;
class Storage { class Storage {
public: public:
struct SubmissionResult { struct SubmissionResult {
std::string token; std::string token;
boost::optional<ErrorReasons> error; boost::optional<tawashi::ErrorReasons> error;
}; };
explicit Storage (const Kakoune::SafePtr<SettingsBag>& parSettings); explicit Storage (const Kakoune::SafePtr<SettingsBag>& parSettings);
tawashi_virtual_testing ~Storage(); kamokan_virtual_testing ~Storage();
tawashi_virtual_testing void connect_async(); kamokan_virtual_testing void connect_async();
tawashi_virtual_testing bool is_connected() const; kamokan_virtual_testing bool is_connected() const;
tawashi_virtual_testing void finalize_connection(); kamokan_virtual_testing void finalize_connection();
tawashi_virtual_testing SubmissionResult submit_pastie ( kamokan_virtual_testing SubmissionResult submit_pastie (
const boost::string_view& parText, const boost::string_view& parText,
uint32_t parExpiry, uint32_t parExpiry,
const boost::string_view& parLang, const boost::string_view& parLang,
const std::string& parRemoteIP const std::string& parRemoteIP
) const; ) const;
tawashi_virtual_testing boost::optional<std::string> retrieve_pastie (const boost::string_view& parToken) const; kamokan_virtual_testing boost::optional<std::string> retrieve_pastie (const boost::string_view& parToken) const;
#if defined(KAMOKAN_WITH_TESTING) #if defined(KAMOKAN_WITH_TESTING)
const SettingsBag& settings() const; const SettingsBag& settings() const;
@ -62,4 +62,4 @@ namespace tawashi {
std::unique_ptr<redis::IncRedis> m_redis; std::unique_ptr<redis::IncRedis> m_redis;
Kakoune::SafePtr<SettingsBag> m_settings; Kakoune::SafePtr<SettingsBag> m_settings;
}; };
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "submit_paste_response.hpp" #include "submit_paste_response.hpp"
@ -29,17 +29,17 @@
#include <cstdint> #include <cstdint>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
namespace tawashi { namespace kamokan {
namespace { namespace {
const char g_post_key[] = "pastie"; const char g_post_key[] = "pastie";
const char g_language_key[] = "lang"; const char g_language_key[] = "lang";
const char g_duration_key[] = "ttl"; const char g_duration_key[] = "ttl";
class MissingPostVarError : public TawashiException { class MissingPostVarError : public tawashi::TawashiException {
public: public:
explicit MissingPostVarError(const boost::string_view& parKey) : explicit MissingPostVarError(const boost::string_view& parKey) :
TawashiException( TawashiException(
ErrorReasons::MissingPostVariable, tawashi::ErrorReasons::MissingPostVariable,
"Error retrieving POST variable \"" + std::string(parKey.begin(), parKey.end()) + "\"" "Error retrieving POST variable \"" + std::string(parKey.begin(), parKey.end()) + "\""
) )
{} {}
@ -94,7 +94,9 @@ namespace tawashi {
{ {
} }
HttpHeader SubmitPasteResponse::on_process() { tawashi::HttpHeader SubmitPasteResponse::on_process() {
using tawashi::ErrorReasons;
boost::string_view pastie; boost::string_view pastie;
boost::string_view lang; boost::string_view lang;
boost::string_view duration; boost::string_view duration;
@ -109,14 +111,14 @@ namespace tawashi {
lang = get_value_from_post_log_failure(post, make_string_view(g_language_key)); lang = get_value_from_post_log_failure(post, make_string_view(g_language_key));
duration = get_value_from_post_log_failure(post, make_string_view(g_duration_key)); duration = get_value_from_post_log_failure(post, make_string_view(g_duration_key));
} }
catch (const UnsupportedContentTypeException& err) { catch (const tawashi::UnsupportedContentTypeException& err) {
statuslog->info( statuslog->info(
"Unsupported content type exception: \"{}\"", "Unsupported content type exception: \"{}\"",
err.what() err.what()
); );
return make_error_redirect(ErrorReasons::UnsupportedContentType); return make_error_redirect(ErrorReasons::UnsupportedContentType);
} }
catch (const TawashiException& e) { catch (const tawashi::TawashiException& e) {
statuslog->error(e.what()); statuslog->error(e.what());
return make_error_redirect(e.reason()); return make_error_redirect(e.reason());
} }
@ -163,15 +165,16 @@ namespace tawashi {
const boost::string_view& parLang const boost::string_view& parLang
) -> StringOrHeader { ) -> StringOrHeader {
auto& storage = this->storage(); auto& storage = this->storage();
std::string remote_ip = guess_real_remote_ip(cgi_env()); std::string remote_ip = tawashi::guess_real_remote_ip(cgi_env());
Storage::SubmissionResult submission_res = storage.submit_pastie(parText, parExpiry, parLang, remote_ip); Storage::SubmissionResult submission_res = storage.submit_pastie(parText, parExpiry, parLang, remote_ip);
if (not submission_res.error) if (not submission_res.error)
return std::make_pair(boost::make_optional(std::move(submission_res.token)), HttpHeader()); return std::make_pair(boost::make_optional(std::move(submission_res.token)), tawashi::HttpHeader());
else else
return std::make_pair(boost::optional<std::string>(), make_error_redirect(*submission_res.error)); return std::make_pair(boost::optional<std::string>(), make_error_redirect(*submission_res.error));
} }
HttpHeader SubmitPasteResponse::make_success_response (std::string&& parPastieParam) { tawashi::HttpHeader SubmitPasteResponse::make_success_response (std::string&& parPastieParam) {
using tawashi::HttpStatusCodes;
return this->make_redirect(HttpStatusCodes::Code303_SeeOther, std::move(parPastieParam)); return this->make_redirect(HttpStatusCodes::Code303_SeeOther, std::move(parPastieParam));
} }
} //namespace tawashi } //namespace kamokan

View file

@ -1,18 +1,18 @@
/* Copyright 2017, Michele Santullo /* Copyright 2017, Michele Santullo
* This file is part of "tawashi". * This file is part of "kamokan".
* *
* "tawashi" is free software: you can redistribute it and/or modify * "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* "tawashi" is distributed in the hope that it will be useful, * "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>. * along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
@ -24,7 +24,7 @@
#include <cassert> #include <cassert>
#include <utility> #include <utility>
namespace tawashi { namespace kamokan {
class SubmitPasteResponse : public Response { class SubmitPasteResponse : public Response {
public: public:
#if defined(KAMOKAN_WITH_TESTING) #if defined(KAMOKAN_WITH_TESTING)
@ -44,12 +44,12 @@ namespace tawashi {
protected: protected:
virtual boost::string_view page_basename() const override { assert(false); return boost::string_view(""); } virtual boost::string_view page_basename() const override { assert(false); return boost::string_view(""); }
virtual HttpHeader make_success_response (std::string&& parPastieParam); virtual tawashi::HttpHeader make_success_response (std::string&& parPastieParam);
private: private:
typedef std::pair<boost::optional<std::string>, HttpHeader> StringOrHeader; typedef std::pair<boost::optional<std::string>, tawashi::HttpHeader> StringOrHeader;
virtual HttpHeader on_process() override; virtual tawashi::HttpHeader on_process() override;
StringOrHeader submit_to_storage (const boost::string_view& parText, uint32_t parExpiry, const boost::string_view& parLang); StringOrHeader submit_to_storage (const boost::string_view& parText, uint32_t parExpiry, const boost::string_view& parLang);
}; };
} //namespace tawashi } //namespace kamokan

View file

@ -20,7 +20,7 @@
#include <utility> #include <utility>
#include <algorithm> #include <algorithm>
namespace tawashi { namespace kamokan {
FakeStorage::FakeStorage (const Kakoune::SafePtr<SettingsBag>& parSettings, bool parItsConnected) : FakeStorage::FakeStorage (const Kakoune::SafePtr<SettingsBag>& parSettings, bool parItsConnected) :
Storage(parSettings), Storage(parSettings),
m_submission_num(1), m_submission_num(1),
@ -77,4 +77,4 @@ namespace tawashi {
const std::vector<FakeStorage::SubmittedPastie>& FakeStorage::submitted_pasties() const { const std::vector<FakeStorage::SubmittedPastie>& FakeStorage::submitted_pasties() const {
return m_submitted_pasties; return m_submitted_pasties;
} }
} //namespace tawashi } //namespace kamokan

View file

@ -26,7 +26,7 @@
# error "Can't compile this class if test mode is disabled" # error "Can't compile this class if test mode is disabled"
#endif #endif
namespace tawashi { namespace kamokan {
class FakeStorage : public Storage { class FakeStorage : public Storage {
public: public:
struct SubmittedPastie { struct SubmittedPastie {
@ -38,19 +38,19 @@ namespace tawashi {
}; };
FakeStorage (const Kakoune::SafePtr<SettingsBag>& parSettings, bool parItsConnected); FakeStorage (const Kakoune::SafePtr<SettingsBag>& parSettings, bool parItsConnected);
tawashi_virtual_testing ~FakeStorage(); kamokan_virtual_testing ~FakeStorage();
tawashi_virtual_testing void connect_async(); kamokan_virtual_testing void connect_async();
tawashi_virtual_testing bool is_connected() const; kamokan_virtual_testing bool is_connected() const;
tawashi_virtual_testing void finalize_connection(); kamokan_virtual_testing void finalize_connection();
tawashi_virtual_testing SubmissionResult submit_pastie ( kamokan_virtual_testing SubmissionResult submit_pastie (
const boost::string_view& parText, const boost::string_view& parText,
uint32_t parExpiry, uint32_t parExpiry,
const boost::string_view& parLang, const boost::string_view& parLang,
const std::string& parRemoteIP const std::string& parRemoteIP
) const; ) const;
tawashi_virtual_testing boost::optional<std::string> retrieve_pastie (const boost::string_view& parToken) const; kamokan_virtual_testing boost::optional<std::string> retrieve_pastie (const boost::string_view& parToken) const;
const std::vector<SubmittedPastie>& submitted_pasties() const; const std::vector<SubmittedPastie>& submitted_pasties() const;
@ -59,4 +59,4 @@ namespace tawashi {
mutable int64_t m_submission_num; mutable int64_t m_submission_num;
bool m_its_connected; bool m_its_connected;
}; };
} //namespace tawashi } //namespace kamokan

View file

@ -55,7 +55,7 @@ R"(Content-type: text/html
)"; )";
} //unnamed namespace } //unnamed namespace
namespace tawashi { namespace kamokan {
class IndexResponseCustomMustache : public IndexResponse { class IndexResponseCustomMustache : public IndexResponse {
public: public:
IndexResponseCustomMustache ( IndexResponseCustomMustache (
@ -71,7 +71,7 @@ namespace tawashi {
return g_mustache_html; return g_mustache_html;
} }
}; };
} //namespace tawashi } //namespace kamokan
TEST_CASE ("Index response", "[index][response]") { TEST_CASE ("Index response", "[index][response]") {
using curry::SafeStackObject; using curry::SafeStackObject;
@ -109,12 +109,12 @@ TEST_CASE ("Index response", "[index][response]") {
" host_path = /\n" " host_path = /\n"
" host_port =\n" " host_port =\n"
); );
SafeStackObject<tawashi::IniFile> ini(std::move(kamokan_settings)); SafeStackObject<kamokan::IniFile> ini(std::move(kamokan_settings));
SafeStackObject<tawashi::SettingsBag> settings(ini, "kamokan"); SafeStackObject<kamokan::SettingsBag> settings(ini, "kamokan");
std::stringstream response_stream; std::stringstream response_stream;
tawashi::IndexResponseCustomMustache response(settings, &response_stream, fake_env); kamokan::IndexResponseCustomMustache response(settings, &response_stream, fake_env);
response.send(); response.send();
response_stream.seekg(0); response_stream.seekg(0);

View file

@ -29,7 +29,7 @@
#include <sstream> #include <sstream>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
namespace tawashi { namespace kamokan {
class SubmitPasteResponseWithFakeStorage : public SubmitPasteResponse { class SubmitPasteResponseWithFakeStorage : public SubmitPasteResponse {
public: public:
SubmitPasteResponseWithFakeStorage ( SubmitPasteResponseWithFakeStorage (
@ -62,7 +62,7 @@ namespace tawashi {
FakeStorage m_fake_storage; FakeStorage m_fake_storage;
std::string m_post_data; std::string m_post_data;
}; };
} //namespace tawashi } //namespace kamokan
TEST_CASE ("Submit paste response", "[submitpaste][response]") { TEST_CASE ("Submit paste response", "[submitpaste][response]") {
using curry::SafeStackObject; using curry::SafeStackObject;
@ -121,11 +121,11 @@ TEST_CASE ("Submit paste response", "[submitpaste][response]") {
" min_pastie_size = 1\n" " min_pastie_size = 1\n"
" truncate_long_pasties = no\n" " truncate_long_pasties = no\n"
); );
SafeStackObject<tawashi::IniFile> ini(std::move(kamokan_settings)); SafeStackObject<kamokan::IniFile> ini(std::move(kamokan_settings));
SafeStackObject<tawashi::SettingsBag> settings(ini, "kamokan"); SafeStackObject<kamokan::SettingsBag> settings(ini, "kamokan");
std::ostringstream oss; std::ostringstream oss;
tawashi::SubmitPasteResponseWithFakeStorage submit_response( kamokan::SubmitPasteResponseWithFakeStorage submit_response(
settings, settings,
&oss, &oss,
fake_env, fake_env,

View file

@ -22,7 +22,7 @@
#include <ciso646> #include <ciso646>
TEST_CASE ("Test parsing an ini text", "[ini][parser]") { TEST_CASE ("Test parsing an ini text", "[ini][parser]") {
using tawashi::IniFile; using kamokan::IniFile;
//empty data //empty data
{ {

View file

@ -26,8 +26,8 @@
#include <stdexcept> #include <stdexcept>
TEST_CASE ("Add and retrieve values from SettingsBag", "[settings][ini]") { TEST_CASE ("Add and retrieve values from SettingsBag", "[settings][ini]") {
using tawashi::SettingsBag; using kamokan::SettingsBag;
using tawashi::IniFile; using kamokan::IniFile;
using curry::SafeStackObject; using curry::SafeStackObject;
auto statuslog = spdlog::stdout_logger_st("statuslog"); auto statuslog = spdlog::stdout_logger_st("statuslog");