74 lines
1.7 KiB
C++
74 lines
1.7 KiB
C++
/* This file is part of FediBlock-backend.
|
|
* Copyright © 2020 tastytea <tastytea@tastytea.de>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
* the Free Software Foundation, version 3.
|
|
*
|
|
* This program 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 Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#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 entry;
|
|
try
|
|
{
|
|
cgicc::Cgicc cgi;
|
|
entry.instance = cgi("instance");
|
|
entry.tags = string_to_vector(cgi("tags"));
|
|
entry.receipts = string_to_vector(cgi("receipts"));
|
|
entry.description = cgi("description");
|
|
}
|
|
catch (const exception &e)
|
|
{
|
|
cerr << e.what() << '\n';
|
|
// TODO: Error handling.
|
|
}
|
|
|
|
return entry;
|
|
}
|
|
|
|
vector<string> string_to_vector(const string_view str)
|
|
{
|
|
vector<string> vec;
|
|
|
|
stringstream input(str.data());
|
|
string element;
|
|
|
|
while (getline(input, element, ','))
|
|
{
|
|
vec.push_back(element);
|
|
}
|
|
|
|
return vec;
|
|
}
|
|
|
|
} // namespace FediBlock
|