2023-01-22 12:56:16 +00:00
|
|
|
#ifndef WEBFUSE_SERVER_HANDLER_HPP
|
|
|
|
#define WEBFUSE_SERVER_HANDLER_HPP
|
|
|
|
|
|
|
|
#include "webfuse/ws/messagereader.hpp"
|
|
|
|
#include "webfuse/ws/messagewriter.hpp"
|
|
|
|
|
|
|
|
#include <libwebsockets.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <queue>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <mutex>
|
|
|
|
#include <future>
|
2023-01-22 13:38:10 +00:00
|
|
|
#include <atomic>
|
2023-01-22 12:56:16 +00:00
|
|
|
|
|
|
|
namespace webfuse
|
|
|
|
{
|
|
|
|
|
|
|
|
class server_handler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
server_handler(std::string const & auth_app, std::string const & auth_hdr);
|
|
|
|
|
|
|
|
int filter_connection(lws * wsi);
|
|
|
|
|
|
|
|
int on_established(lws* wsi);
|
|
|
|
void on_receive(lws * wsi, void* in, int len);
|
2023-01-22 19:53:50 +00:00
|
|
|
int on_writable();
|
2023-01-22 12:56:16 +00:00
|
|
|
void on_closed(lws * wsi);
|
|
|
|
|
|
|
|
std::future<messagereader> perform(messagewriter writer);
|
|
|
|
void poll();
|
|
|
|
|
|
|
|
private:
|
|
|
|
int authenticate_via_header(lws * wsi);
|
|
|
|
std::string get_auth_token(lws * wsi) const;
|
|
|
|
uint32_t next_id();
|
2023-01-22 19:53:50 +00:00
|
|
|
void finish_authentication(lws * wsi, messagereader reader);
|
2023-01-22 12:56:16 +00:00
|
|
|
|
|
|
|
struct lws * connection;
|
|
|
|
uint32_t id;
|
2023-01-22 19:53:50 +00:00
|
|
|
bool shutdown_requested;
|
2023-01-22 12:56:16 +00:00
|
|
|
|
2023-01-22 13:38:10 +00:00
|
|
|
std::atomic<bool> is_authenticated;
|
2023-01-22 12:56:16 +00:00
|
|
|
std::string authenticator;
|
|
|
|
std::string auth_header;
|
|
|
|
|
|
|
|
std::string current_message;
|
|
|
|
|
|
|
|
std::mutex mut;
|
|
|
|
std::queue<webfuse::messagewriter> requests;
|
|
|
|
std::unordered_map<uint32_t, std::promise<webfuse::messagereader>> pending_responses;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|