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.hpp

90 lines
2.4 KiB
C++

/* This file is part of FediBlock-backend.
* Copyright © 2020, 2021 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/>.
*/
#ifndef FEDIBLOCK_BACKEND_CGI_HPP
#define FEDIBLOCK_BACKEND_CGI_HPP
#include "types.hpp"
#include <cgicc/Cgicc.h>
#include <cstdint>
#include <exception>
#include <string>
#include <string_view>
#include <vector>
namespace FediBlock::cgi
{
using std::string;
using std::string_view;
using std::vector;
// Read form data from QUERY_STRING or stdin and return it as an object.
[[nodiscard]] entry_type parse_formdata();
// Split a string at commas, return a vector.
[[nodiscard]] vector<string> string_to_vector(string_view str);
/*!
* @brief Read array from QUERY_STRING or stdin and return it as a vector.
*
* @param name name of the argument to read.
* @param cgi Reference to a cgicc:Cgicc object.
*
* @since 0.1.0
*/
[[nodiscard]] vector<string> get_array(const string &name, cgicc::Cgicc &cgi);
// Return str in lowercase.
[[nodiscard]] string tolower(string_view str);
// Replace certain characters with HTML tags or entities.
string text2html(string text);
// Check if the answer matches the solution we have for the id.
bool captcha_valid(std::uint8_t id, string_view answer);
bool is_spam(const entry_type &entry);
/*!
* @brief Add automatic tags.
*
* Example: If tag “nazism” is present, add “fascism”.
*
* @since 0.1.0
*/
void add_tags(entry_type &entry);
} // namespace FediBlock::cgi
class SpamException : public std::exception
{
public:
// NOLINTNEXTLINE(modernize-use-nodiscard)
const char *what() const noexcept override;
};
class CaptchaException : public std::exception
{
public:
// NOLINTNEXTLINE(modernize-use-nodiscard)
const char *what() const noexcept override;
};
#endif // FEDIBLOCK_BACKEND_CGI_HPP