-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared_state.hpp
More file actions
executable file
·103 lines (88 loc) · 4.4 KB
/
Copy pathshared_state.hpp
File metadata and controls
executable file
·103 lines (88 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/vinniefalco/CppCon2018
//
#ifndef BOOST_BEAST_EXAMPLE_WEBSOCKET_CHAT_MULTI_SHARED_STATE_HPP
#define BOOST_BEAST_EXAMPLE_WEBSOCKET_CHAT_MULTI_SHARED_STATE_HPP
#include "beast.hpp"
#include "Board.hpp"
#include "FuzeDBI.hpp"
#include "FuzeHttpState.hpp"
#include "PermissionObject.hpp"
#include <boost/smart_ptr.hpp>
#include <mutex>
#include <string>
#include <unordered_set>
// Forward declaration
class WebsocketSession;
namespace FuzeHttp{
// class State;
class Server;
};
struct StateConfig {
std::string thumbnail_file_extension;
unsigned int thumbnail_size = 150;
unsigned int file_size_limit_mb;
bool convert_heic_to_jpg;
bool avif_thumbnails;
bool heic_thumbnails;
bool svg_thumbnails;
bool webp_thumbnails;
bool mp4_thumbnails;
bool webm_thumbnails;
bool strip_metadata;
};
// Represents the shared server state
class shared_state : public FuzeHttp::State {
public:
shared_state(FuzeHttp::Server* server, StateConfig config, bool create_owner_account);
// shared_state(FuzeDBI::Connection* fuze_database_interface, std::filesystem::path document_root, std::filesystem::path media_location_relative, StateConfig config, std::unordered_map<std::string, std::string>&& busted_target_to_target, std::unordered_set<std::string>&& files_generated_from_templates);
const StateConfig config;
void start();
void setAdditionalImageFormatsFromConfig(const StateConfig& config);
bool canCreateThumbnailForImageFormat(const std::string_view mime_type) const;
bool canCreateThumbnailForVideoFormat(const std::string_view mime_type) const;
// FuzeDBI::Connection* fuze_dbi;
const int client_pwhash_opslimit = 2; // CPU cost for client-side password hashing.
const int client_pwhash_memlimit = 128 << 20; // Likewise, memory cost.
// Board main_board;
Board* main_board() { return &(this->boards.at(0)); }
int createThread(int board_id, boost::json::object thread_json, int author_client_id);
int createMessage(int board_id, boost::json::object message_json, int author_client_id);
std::string dumpAllGroups(const std::optional<FuzeHttp::Client>& client) const;
// BasicResponse setGroupHeirarchy(const FuzeHttp::Client& client, std::vector<int> ordered_groups);
// BasicResponse createAccount(nlohmann::json user_json);
// std::string dumpMembersInGroup(int group_id) const;
// std::string dumpMembersInGroupAsArray(int group_id) const;
std::string dumpAllUsers(const std::optional<FuzeHttp::Client>& client) const;
// std::string dumpPermissions(int client_id) const { return this->getPermissionCollectionsAsJson(client_id).dump(); }
const Thread* getThread(int board_id, int thread_id) const { return this->boards.at(board_id).getThread(thread_id); }
std::string getIntermediateSaltFromAccount(int account_id);
const FuzeHttp::Client& getClientFromAccountId(int account_id) const;
// bool usernameExists(std::string username) const { std::unordered_map<std::string, int>::const_iterator it = username_to_id_map.find(username); return it != username_to_id_map.end(); };
// BasicResponse addUserToGroups(const FuzeHttp::Client& client, int user_id, std::vector<int> groups_by_id);
void sendToThread (std::string message, int thread_id);
void sendToWebRTC(std::string message);
void clearWebsockets();
const std::filesystem::path& getMediaLocation() const { return media_location; }
// const std::filesystem::path& getProgramLocation() const { return program_location; }
const char* getSecret() const { return this->secret_base64; }
private:
const std::filesystem::path media_location;
// const std::filesystem::path program_location;
char secret_base64[sodium_base64_ENCODED_LEN(crypto_pwhash_SALTBYTES, sodium_base64_VARIANT_URLSAFE)];
// FuzeDBI::Connection* fuze_dbi;
std::unordered_set<std::string> image_formats_to_create_thumbnails_for = {"image/bmp", "image/gif", "image/vnd.microsoft.icon", "image/jpeg", "image/jxl", "image/png"};
std::unordered_set<std::string> video_formats_to_create_thumbnails_for;
// This mutex synchronizes all access to sessions_
// std::mutex mutex_;
// std::unordered_map<int, Board> boards;
std::unordered_map<int, Board> boards;
// std::vector<int> ordered_boards;
// HTTP sessions. Client validates using a cookie
};
#endif