1
0
forked from blue/pica
pica/server/server.h

60 lines
1.5 KiB
C
Raw Normal View History

2023-12-30 22:42:11 +00:00
//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
//SPDX-License-Identifier: GPL-3.0-or-later
2023-11-21 22:19:08 +00:00
#pragma once
#include <iostream>
#include <string>
#include <sstream>
#include <optional>
#include <string_view>
#include <vector>
#include <memory>
2023-12-23 20:23:38 +00:00
#include <map>
2023-11-21 22:19:08 +00:00
#include <fcgiapp.h>
#include <fcgio.h>
#include <stdint.h>
2023-12-20 22:42:13 +00:00
#include <argon2.h>
2023-11-23 19:57:32 +00:00
2023-11-21 22:19:08 +00:00
#include "request/request.h"
#include "response/response.h"
2023-11-23 19:57:32 +00:00
#include "router.h"
2023-12-23 20:23:38 +00:00
#include "session.h"
2023-12-29 17:40:00 +00:00
#include "database/pool.h"
2023-12-11 23:29:55 +00:00
#include "utils/helpers.h"
#include "config.h"
2023-12-30 22:42:11 +00:00
#include "taskmanager/manager.h"
2023-12-31 17:10:04 +00:00
#include "taskmanager/scheduler.h"
2023-11-21 22:19:08 +00:00
2023-12-30 22:42:11 +00:00
class Server : public std::enable_shared_from_this<Server> {
2023-11-21 22:19:08 +00:00
public:
Server();
~Server();
void run(int socketDescriptor);
2023-12-20 22:42:13 +00:00
unsigned int registerAccount(const std::string& login, const std::string& password);
2023-12-22 23:25:20 +00:00
bool validatePassword(const std::string& login, const std::string& password);
2023-12-23 20:23:38 +00:00
Session& openSession(const std::string& login);
2023-12-28 20:26:08 +00:00
Session& getSession(const std::string& accessToken);
DB::Resource getDatabase();
2023-12-20 22:42:13 +00:00
2023-11-21 22:19:08 +00:00
private:
void handleRequest(std::unique_ptr<Request> request);
2023-12-20 22:42:13 +00:00
static std::string generateRandomString(std::size_t length);
2023-11-23 19:57:32 +00:00
2023-11-21 22:19:08 +00:00
private:
2023-12-23 20:23:38 +00:00
using Sessions = std::map<std::string, std::unique_ptr<Session>>;
2023-11-21 22:19:08 +00:00
bool terminating;
uint64_t requestCount;
std::optional<std::string> serverName;
2023-12-30 22:42:11 +00:00
std::shared_ptr<Router> router;
2023-12-29 17:40:00 +00:00
std::shared_ptr<DB::Pool> pool;
2023-12-30 22:42:11 +00:00
std::shared_ptr<TM::Manager> taskManager;
2023-12-31 17:10:04 +00:00
std::shared_ptr<TM::Scheduler> scheduler;
2023-12-23 20:23:38 +00:00
Sessions sessions;
2023-11-21 22:19:08 +00:00
};