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++
Raw Normal View History

2020-06-29 05:21:23 +02:00
#include "cgi.hpp"
#include <cgicc/Cgicc.h>
#include <exception>
#include <iostream>
2020-06-29 05:21:23 +02:00
#include <sstream>
#include <string>
#include <vector>
namespace FediBlock
{
using std::cerr;
2020-06-29 05:21:23 +02:00
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)
2020-06-29 05:21:23 +02:00
{
cerr << e.what() << '\n';
2020-06-29 05:21:23 +02:00
// 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)
2020-06-29 05:21:23 +02:00
{
cerr << e.what() << '\n';
2020-06-29 05:21:23 +02:00
}
return output;
}
} // namespace FediBlock