2022-06-26 20:53:54 +02:00
|
|
|
#ifndef HTTP_SESSION_MANAGER_H
|
|
|
|
#define HTTP_SESSION_MANAGER_H
|
2022-06-25 01:55:54 +02:00
|
|
|
|
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-25 01:55:54 +02:00
|
|
|
|
2022-06-26 20:53:54 +02:00
|
|
|
#include "core/reference.h"
|
|
|
|
#include "scene/main/node.h"
|
2022-06-25 01:55:54 +02:00
|
|
|
|
2022-06-26 20:53:54 +02:00
|
|
|
#include "web_server_middleware.h"
|
2022-06-25 01:55:54 +02:00
|
|
|
|
|
|
|
class HTTPSession;
|
2022-06-26 20:53:54 +02:00
|
|
|
class WebServerRequest;
|
2022-06-25 01:55:54 +02:00
|
|
|
|
2022-06-27 13:56:34 +02:00
|
|
|
class HTTPSessionManager : public Node {
|
|
|
|
GDCLASS(HTTPSessionManager, Node);
|
2022-06-25 01:55:54 +02:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2022-06-27 13:56:34 +02:00
|
|
|
HTTPSessionManager();
|
|
|
|
~HTTPSessionManager();
|
2022-06-25 01:55:54 +02:00
|
|
|
|
2022-06-26 20:53:54 +02:00
|
|
|
HashMap<String, Ref<HTTPSession>> _sessions;
|
2022-06-25 01:55:54 +02:00
|
|
|
Vector<Ref<HTTPSession>> _sessions_vec;
|
|
|
|
Mutex _mutex;
|
2022-06-26 20:53:54 +02:00
|
|
|
String _table_name;
|
|
|
|
String _data_table_name;
|
2022-06-25 01:55:54 +02:00
|
|
|
|
|
|
|
protected:
|
2022-06-26 20:53:54 +02:00
|
|
|
static void _bind_methods();
|
2022-06-25 01:55:54 +02:00
|
|
|
};
|
|
|
|
|
2022-06-26 15:00:25 +02:00
|
|
|
class SessionSetupWebServerMiddleware : public WebServerMiddleware {
|
2022-06-26 20:53:54 +02:00
|
|
|
GDCLASS(SessionSetupWebServerMiddleware, WebServerMiddleware);
|
2022-06-25 01:55:54 +02:00
|
|
|
|
|
|
|
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-25 01:55:54 +02:00
|
|
|
|
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-25 01:55:54 +02:00
|
|
|
};
|
|
|
|
|
2022-06-26 15:00:25 +02:00
|
|
|
#endif
|