1
0
Fork 0
mirror of https://github.com/KingDuckZ/kamokan.git synced 2024-12-27 21:35:41 +00:00

New free function to get POST values.

This commit is contained in:
King_DuckZ 2017-04-06 20:12:44 +01:00
parent e9d54c3ff5
commit 6a502df135
3 changed files with 60 additions and 0 deletions

View file

@ -14,6 +14,7 @@ add_executable(${PROJECT_NAME}
envy.cpp envy.cpp
cgi_env.cpp cgi_env.cpp
num_to_token.cpp num_to_token.cpp
cgi_post.cpp
) )
target_include_directories(${PROJECT_NAME} SYSTEM target_include_directories(${PROJECT_NAME} SYSTEM

45
src/cgi_post.cpp Normal file
View file

@ -0,0 +1,45 @@
#include "cgi_post.hpp"
#include "cgi_env.hpp"
#include "split_get_vars.hpp"
#include <iostream>
#include <iterator>
#include <algorithm>
#include <string>
#include <cassert>
#include <ciso646>
namespace tawashi {
namespace cgi {
namespace {
} //unnamed namespace
const PostMapType& read_post (const CGIEnv& parEnv) {
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)
);
for (auto& itm : split_env_vars(original_data)) {
map[itm.first] = itm.second;
}
}
already_read = true;
}
return map;
}
} //namespace cgi
} //namespace tawashi

14
src/cgi_post.hpp Normal file
View file

@ -0,0 +1,14 @@
#pragma once
#include <boost/container/flat_map.hpp>
#include <boost/utility/string_ref.hpp>
namespace tawashi {
class CGIEnv;
namespace cgi {
typedef boost::container::flat_map<boost::string_ref, boost::string_ref> PostMapType;
const PostMapType& read_post (const CGIEnv& parEnv);
} //namespace cgi
} //namespace tawashi