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-08-17 12:53:49 +02:00
|
|
|
#include "core/containers/hash_map.h"
|
2022-06-26 20:53:54 +02:00
|
|
|
#include "core/os/mutex.h"
|
2022-08-17 14:19:55 +02:00
|
|
|
#include "core/string/ustring.h"
|
2022-08-17 12:53:49 +02:00
|
|
|
#include "core/containers/vector.h"
|
2022-06-25 01:55:54 +02:00
|
|
|
|
2022-08-17 13:45:14 +02:00
|
|
|
#include "core/object/reference.h"
|
2022-06-26 20:53:54 +02:00
|
|
|
#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:
|
2022-06-27 14:59:09 +02:00
|
|
|
void add_session(Ref<HTTPSession> session);
|
|
|
|
void remove_session(Ref<HTTPSession> session);
|
2022-06-25 01:55:54 +02:00
|
|
|
void delete_session(const String &session_id);
|
2022-06-27 14:59:09 +02:00
|
|
|
void save_session(Ref<HTTPSession> session);
|
2022-06-25 01:55:54 +02:00
|
|
|
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
|