2018-11-24 11:00:07 +01:00
|
|
|
/* This file is part of libravatarserv.
|
|
|
|
* Copyright © 2018 tastytea <tastytea@tastytea.de>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LIBRAVATARSERV_HPP
|
|
|
|
#define LIBRAVATARSERV_HPP
|
|
|
|
|
2018-11-25 06:00:45 +01:00
|
|
|
#if __cplusplus >= 201703L
|
|
|
|
#include <filesystem>
|
|
|
|
#else
|
|
|
|
#include <experimental/filesystem>
|
|
|
|
#endif
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
2018-12-01 11:30:05 +01:00
|
|
|
#include <Magick++/Image.h>
|
2018-11-24 11:00:07 +01:00
|
|
|
|
2018-11-25 06:00:45 +01:00
|
|
|
#if __cplusplus >= 201703L
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
#else
|
|
|
|
namespace fs = std::experimental::filesystem;
|
|
|
|
#endif
|
|
|
|
using std::string;
|
|
|
|
using std::uint16_t;
|
|
|
|
using std::uint8_t;
|
|
|
|
|
|
|
|
int main();
|
|
|
|
|
2018-11-30 07:00:37 +01:00
|
|
|
namespace settings
|
|
|
|
{ // settings.cpp
|
2018-11-25 06:00:45 +01:00
|
|
|
extern fs::path avatar_dir;
|
2018-11-27 15:42:43 +01:00
|
|
|
extern struct Settings
|
|
|
|
{
|
2018-11-28 14:56:15 +01:00
|
|
|
string default_fallback = "404";
|
2018-11-27 16:45:36 +01:00
|
|
|
bool redirect_nofallback = false;
|
|
|
|
bool redirect_nouser = false;
|
2018-11-27 15:42:43 +01:00
|
|
|
} settings;
|
2018-11-30 07:00:37 +01:00
|
|
|
|
|
|
|
bool find_avatar_dir();
|
|
|
|
void read_settings();
|
2018-11-25 06:00:45 +01:00
|
|
|
}
|
|
|
|
|
2018-11-26 04:07:43 +01:00
|
|
|
namespace http // http.cpp
|
|
|
|
{
|
|
|
|
struct Request
|
|
|
|
{
|
|
|
|
const string digest;
|
2018-11-26 05:22:49 +01:00
|
|
|
const uint16_t size;
|
2018-11-27 15:42:43 +01:00
|
|
|
string fallback;
|
2018-11-26 04:07:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const Request parse_request(const string &request);
|
2018-11-26 04:17:34 +01:00
|
|
|
const string get_parameter(const string &request, const string ¶meter);
|
2018-11-27 16:45:36 +01:00
|
|
|
void send_redirect(const Request &request);
|
2018-11-26 04:07:43 +01:00
|
|
|
}
|
|
|
|
|
2018-11-25 06:00:45 +01:00
|
|
|
namespace hash // hash.cpp
|
|
|
|
{
|
|
|
|
extern std::map<const string, const string> table;
|
|
|
|
|
|
|
|
const string md5(const string &text);
|
|
|
|
const string sha256(const string &text);
|
|
|
|
bool fill_table();
|
2018-11-30 06:48:45 +01:00
|
|
|
bool is_valid(const string &digest);
|
|
|
|
bool not_hex(const char &c);
|
2018-11-25 06:00:45 +01:00
|
|
|
}
|
|
|
|
|
2018-11-26 04:07:43 +01:00
|
|
|
namespace image // image.cpp
|
2018-11-25 06:00:45 +01:00
|
|
|
{
|
|
|
|
struct Image
|
|
|
|
{
|
2018-11-27 04:35:14 +01:00
|
|
|
uint8_t error;
|
2018-11-25 06:00:45 +01:00
|
|
|
Magick::Image image;
|
|
|
|
};
|
|
|
|
|
|
|
|
const Image get(const string &digest, const uint16_t size);
|
2018-11-27 04:35:14 +01:00
|
|
|
void write(Image &image);
|
2018-11-27 09:59:02 +01:00
|
|
|
Image identicon(const string &digest);
|
2018-11-25 06:00:45 +01:00
|
|
|
}
|
2018-11-24 11:00:07 +01:00
|
|
|
|
|
|
|
#endif // LIBRAVATARSERV_HPP
|