1
0
Fork 0
mirror of https://github.com/KingDuckZ/kamokan.git synced 2025-02-09 09:23:56 +00:00
kamokan/src/main.cpp

85 lines
2.4 KiB
C++
Raw Normal View History

2017-04-06 23:35:06 +01:00
/* Copyright 2017, Michele Santullo
* This file is part of "tawashi".
*
* "tawashi" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "tawashi" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "tawashi". If not, see <http://www.gnu.org/licenses/>.
*/
2017-04-04 20:58:40 +01:00
#include "incredis/incredis.hpp"
#include "tawashiConfig.h"
2017-04-06 22:45:44 +01:00
#include "submit_paste_response.hpp"
2017-04-06 23:28:57 +01:00
#include "pastie_response.hpp"
2017-04-06 21:27:38 +01:00
#include "index_response.hpp"
2017-04-05 08:41:49 +01:00
#include "cgi_env.hpp"
#include "ini_file.hpp"
#include "pathname/pathname.hpp"
#include "duckhandy/compatibility.h"
#include "duckhandy/lexical_cast.hpp"
2017-04-04 20:58:40 +01:00
#include <iostream>
#include <string>
#include <fstream>
#include <iterator>
#include <ciso646>
2017-04-04 20:58:40 +01:00
//www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4150.pdf
namespace {
std::string config_file_path() a_pure;
std::string config_file_path() {
mchlib::PathName config_path(TAWASHI_CONFIG_PATH);
mchlib::PathName full_path("");
if (config_path.is_absolute()) {
full_path = std::move(config_path);
}
else {
full_path = mchlib::PathName(TAWASHI_PATH_PREFIX);
full_path.join(config_path);
}
full_path.join(TAWASHI_CONFIG_FILE);
return full_path.path();
}
2017-04-04 20:58:40 +01:00
} //unnamed namespace
int main() {
//std::cout << "Content-type:text/plain\n\n";
#if !defined(NDEBUG)
std::cerr << "Loading config: \"" << config_file_path() << "\"\n";
#endif
std::ifstream conf(config_file_path());
conf >> std::noskipws;
tawashi::IniFile ini = tawashi::IniFile(std::istream_iterator<char>(conf), std::istream_iterator<char>());
conf.close();
const auto& settings = ini.parsed().at("tawashi");
redis::IncRedis incredis(std::string(settings.at("redis_server")), dhandy::lexical_cast<uint16_t>(settings.at("redis_port")));
incredis.connect();
2017-04-04 20:58:40 +01:00
2017-04-06 23:02:17 +01:00
tawashi::cgi::Env cgi_env;
2017-04-06 21:27:38 +01:00
if (cgi_env.path_info() == "/index.cgi") {
tawashi::IndexResponse resp;
resp.send();
2017-04-04 20:58:40 +01:00
}
2017-04-06 21:27:38 +01:00
else if (cgi_env.path_info() == "/paste.cgi") {
2017-04-06 22:45:44 +01:00
tawashi::SubmitPasteResponse resp(incredis);
2017-04-06 21:27:38 +01:00
resp.send();
}
else {
2017-04-06 23:28:57 +01:00
tawashi::PastieResponse resp(incredis);
resp.send();
}
2017-04-04 20:58:40 +01:00
return 0;
}