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

74 lines
1.7 KiB
C++
Raw Normal View History

2020-06-29 06:10:40 +02:00
/* 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/>.
*/
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()
{
2020-06-29 07:05:04 +02:00
entry_type entry;
2020-06-29 05:21:23 +02:00
try
{
cgicc::Cgicc cgi;
2020-06-29 07:05:04 +02:00
entry.instance = cgi("instance");
entry.tags = string_to_vector(cgi("tags"));
entry.receipts = string_to_vector(cgi("receipts"));
entry.description = cgi("description");
2020-06-29 05:21:23 +02:00
}
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.
}
2020-06-29 07:05:04 +02:00
return entry;
2020-06-29 05:21:23 +02:00
}
2020-06-29 07:05:04 +02:00
vector<string> string_to_vector(const string_view str)
2020-06-29 05:21:23 +02:00
{
2020-06-29 07:05:04 +02:00
vector<string> vec;
2020-06-29 05:21:23 +02:00
stringstream input(str.data());
string element;
while (getline(input, element, ','))
2020-06-29 05:21:23 +02:00
{
vec.push_back(element);
2020-06-29 05:21:23 +02:00
}
2020-06-29 07:05:04 +02:00
return vec;
2020-06-29 05:21:23 +02:00
}
} // namespace FediBlock