This repository has been archived on 2021-03-22. You can view files and clone it, but cannot push or open issues or pull requests.
backend/src/cgi.cpp

54 lines
948 B
C++
Raw Normal View History

2020-06-29 05:21:23 +02:00
#include "cgi.hpp"
#include <cgicc/Cgicc.h>
#include <exception>
#include <sstream>
#include <string>
#include <vector>
namespace FediBlock
{
using std::exception;
using std::getline;
using std::string;
using std::string_view;
using std::stringstream;
using std::vector;
entry_type parse_formdata()
{
entry_type answer;
try
{
cgicc::Cgicc cgi;
answer.instance = cgi("instance");
answer.tags = string_to_array(cgi("tags"));
answer.receipts = string_to_array(cgi("receipts"));
answer.description = cgi("description");
}
catch (exception &e)
{
// TODO: Error handling.
}
return answer;
}
vector<string> string_to_array(const string_view str)
{
stringstream input(str.data());
string element;
vector<string> output;
while (getline(input, element, ','))
{
output.push_back(element);
}
return output;
}
} // namespace FediBlock