2017-04-06 22:35:06 +00: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-06 19:12:44 +00:00
|
|
|
#include "cgi_post.hpp"
|
|
|
|
#include "cgi_env.hpp"
|
|
|
|
#include "split_get_vars.hpp"
|
2017-04-06 19:15:44 +00:00
|
|
|
#include "curl_wrapper.hpp"
|
2017-04-06 19:12:44 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <iterator>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <string>
|
|
|
|
#include <cassert>
|
|
|
|
#include <ciso646>
|
|
|
|
|
|
|
|
namespace tawashi {
|
|
|
|
namespace cgi {
|
|
|
|
namespace {
|
|
|
|
} //unnamed namespace
|
|
|
|
|
2017-04-06 22:02:17 +00:00
|
|
|
const PostMapType& read_post (const Env& parEnv) {
|
2017-04-06 19:12:44 +00:00
|
|
|
static bool already_read = false;
|
|
|
|
static PostMapType map;
|
|
|
|
static std::string original_data;
|
|
|
|
|
|
|
|
if (not already_read) {
|
|
|
|
assert(original_data.empty());
|
|
|
|
assert(map.empty());
|
|
|
|
|
|
|
|
const auto input_len = parEnv.content_length();
|
|
|
|
if (input_len > 0) {
|
|
|
|
original_data.reserve(input_len);
|
|
|
|
std::copy_n(
|
|
|
|
std::istream_iterator<char>(std::cin),
|
|
|
|
input_len,
|
|
|
|
std::back_inserter(original_data)
|
|
|
|
);
|
|
|
|
|
2017-04-06 19:15:44 +00:00
|
|
|
CurlWrapper curl;
|
2017-04-06 19:12:44 +00:00
|
|
|
for (auto& itm : split_env_vars(original_data)) {
|
2017-04-06 21:57:44 +00:00
|
|
|
map[unescape_string(curl, itm.first)] = unescape_string(curl, itm.second);
|
2017-04-06 19:12:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
already_read = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
} //namespace cgi
|
|
|
|
} //namespace tawashi
|