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

65 lines
1.1 KiB
C++

#include "cgi.hpp"
#include <cgicc/Cgicc.h>
#include <exception>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
namespace FediBlock
{
using std::cerr;
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 (const exception &e)
{
cerr << e.what() << '\n';
// TODO: Error handling.
}
return answer;
}
vector<string> string_to_array(const string_view str)
{
vector<string> output;
try
{
stringstream input(str.data());
string element;
while (getline(input, element, ','))
{
output.push_back(element);
}
}
catch (const exception &e)
{
cerr << e.what() << '\n';
}
return output;
}
} // namespace FediBlock