pandemonium_engine/modules/web/http/http_session_manager.h

66 lines
1.5 KiB
C++
Raw Normal View History

2022-06-26 20:53:54 +02:00
#ifndef HTTP_SESSION_MANAGER_H
#define HTTP_SESSION_MANAGER_H
2022-06-26 20:53:54 +02:00
#include "core/hash_map.h"
#include "core/os/mutex.h"
#include "core/ustring.h"
#include "core/vector.h"
2022-06-26 20:53:54 +02:00
#include "core/reference.h"
#include "scene/main/node.h"
2022-06-26 20:53:54 +02:00
#include "web_server_middleware.h"
class HTTPSession;
2022-06-26 20:53:54 +02:00
class WebServerRequest;
class HTTPSessionManager : public Node {
GDCLASS(HTTPSessionManager, Node);
public:
void add_session(Ref<HTTPSession> &session);
void remove_session(Ref<HTTPSession> &session);
void delete_session(const String &session_id);
void save_session(Ref<HTTPSession> &session);
Ref<HTTPSession> get_session(const String &session_id);
Ref<HTTPSession> create_session();
void load_sessions();
void clear();
virtual String generate_session_id(const String &base = "");
virtual void migrate();
virtual void create_table();
virtual void drop_table();
HTTPSessionManager();
~HTTPSessionManager();
2022-06-26 20:53:54 +02:00
HashMap<String, Ref<HTTPSession>> _sessions;
Vector<Ref<HTTPSession>> _sessions_vec;
Mutex _mutex;
2022-06-26 20:53:54 +02:00
String _table_name;
String _data_table_name;
protected:
2022-06-26 20:53:54 +02:00
static void _bind_methods();
};
2022-06-26 15:00:25 +02:00
class SessionSetupWebServerMiddleware : public WebServerMiddleware {
2022-06-26 20:53:54 +02:00
GDCLASS(SessionSetupWebServerMiddleware, WebServerMiddleware);
public:
//returnring true means handled, false means continue
2022-06-26 20:53:54 +02:00
bool _on_before_handle_request_main(Ref<WebServerRequest> request);
2022-06-26 15:00:25 +02:00
SessionSetupWebServerMiddleware();
~SessionSetupWebServerMiddleware();
2022-06-26 20:53:54 +02:00
protected:
static void _bind_methods();
};
2022-06-26 15:00:25 +02:00
#endif