mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-11 13:21:10 +01:00
More fixes, and added all of the cleanued up classes to the build.
This commit is contained in:
parent
5d3954bceb
commit
844dc44f24
@ -10,6 +10,18 @@ sources = [
|
||||
|
||||
"file_cache.cpp",
|
||||
|
||||
"http/csrf_token.cpp",
|
||||
"http/http_server_enums.cpp",
|
||||
"http/http_session.cpp",
|
||||
"http/http_session_manager.cpp",
|
||||
"http/web_node.cpp",
|
||||
"http/web_permission.cpp",
|
||||
"http/web_root.cpp",
|
||||
"http/web_server.cpp",
|
||||
"http/web_server_cookie.cpp",
|
||||
"http/web_server_middleware.cpp",
|
||||
"http/web_server_request.cpp",
|
||||
|
||||
"http/http_server_enums.cpp",
|
||||
"http/web_server_cookie.cpp",
|
||||
|
||||
|
@ -11,11 +11,22 @@ def configure(env):
|
||||
|
||||
def get_doc_classes():
|
||||
return [
|
||||
#"WorldArea",
|
||||
|
||||
"FileCache",
|
||||
|
||||
"HTTPServerEnums",
|
||||
"WebServerCookie",
|
||||
"CSRFTokenWebServerMiddleware",
|
||||
"HTTPSession",
|
||||
"HTTPSessionManager",
|
||||
"SessionSetupWebServerMiddleware",
|
||||
"WebNode",
|
||||
"WebPermission",
|
||||
"WebRoot",
|
||||
"WebServer",
|
||||
"WebServerCookie",
|
||||
"WebServerMiddleware",
|
||||
"WebServerRequest",
|
||||
|
||||
"HTMLBuilder",
|
||||
"HTMLTag",
|
||||
]
|
||||
|
@ -1,8 +1,6 @@
|
||||
#include "http_session_manager.h"
|
||||
|
||||
#include "http_session.h"
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#if DATABASES_ENABLED
|
||||
#include "database/database_manager.h"
|
||||
@ -11,11 +9,11 @@
|
||||
#include "database/table_builder.h"
|
||||
#endif
|
||||
|
||||
#include "web_server.h"
|
||||
#include "web_server_cookie.h"
|
||||
#include "web_server_request.h"
|
||||
|
||||
#include "web_server_cookie.h"
|
||||
|
||||
void HTTPSessionManager::add_session(Ref<HTTPSession> &session) {
|
||||
void HTTPSessionManager::add_session(Ref<HTTPSession> session) {
|
||||
if (!session.is_valid()) {
|
||||
printf("HTTPSessionManager::add_session: ERROR, session is null!\n");
|
||||
return;
|
||||
@ -29,7 +27,7 @@ void HTTPSessionManager::add_session(Ref<HTTPSession> &session) {
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
void HTTPSessionManager::remove_session(Ref<HTTPSession> &session) {
|
||||
void HTTPSessionManager::remove_session(Ref<HTTPSession> session) {
|
||||
if (!session.is_valid()) {
|
||||
printf("HTTPSessionManager::remove_session: ERROR, session is null!\n");
|
||||
return;
|
||||
@ -88,7 +86,7 @@ void HTTPSessionManager::delete_session(const String &session_id) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void HTTPSessionManager::save_session(Ref<HTTPSession> &session) {
|
||||
void HTTPSessionManager::save_session(Ref<HTTPSession> session) {
|
||||
#if DATABASES_ENABLED
|
||||
Ref<QueryBuilder> b = DatabaseManager::get_singleton()->ddb->get_query_builder();
|
||||
|
||||
@ -276,6 +274,16 @@ HTTPSessionManager::~HTTPSessionManager() {
|
||||
}
|
||||
|
||||
void HTTPSessionManager::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("add_session", "session"), &HTTPSessionManager::add_session);
|
||||
ClassDB::bind_method(D_METHOD("remove_session", "session"), &HTTPSessionManager::remove_session);
|
||||
ClassDB::bind_method(D_METHOD("delete_session", "session_id"), &HTTPSessionManager::delete_session);
|
||||
ClassDB::bind_method(D_METHOD("save_session", "session"), &HTTPSessionManager::save_session);
|
||||
ClassDB::bind_method(D_METHOD("get_session", "session_id"), &HTTPSessionManager::get_session);
|
||||
ClassDB::bind_method(D_METHOD("create_session"), &HTTPSessionManager::create_session);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("load_sessions"), &HTTPSessionManager::load_sessions);
|
||||
ClassDB::bind_method(D_METHOD("clear"), &HTTPSessionManager::clear);
|
||||
ClassDB::bind_method(D_METHOD("generate_session_id", "base"), &HTTPSessionManager::generate_session_id, "");
|
||||
}
|
||||
|
||||
bool SessionSetupWebServerMiddleware::_on_before_handle_request_main(Ref<WebServerRequest> request) {
|
||||
@ -284,25 +292,18 @@ bool SessionSetupWebServerMiddleware::_on_before_handle_request_main(Ref<WebServ
|
||||
if (sid == "") {
|
||||
// You could create a session here if you want to always assign sessions to visitors.
|
||||
// Example code:
|
||||
// HTTPSession *session = HTTPSessionManager::get_singleton()->create_session();
|
||||
// HTTPSessionManager *sm = request->server->get_session_manager();
|
||||
// ERR_FAIL_COND_V(!sm, false);
|
||||
// Ref<HTTPSession> session = sm->create_session();
|
||||
// request->session = session;
|
||||
// request->add_cookie(::Cookie("session_id", session->session_id));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO WebServer nodes should have a get_sess-manager() method
|
||||
|
||||
//Probably:
|
||||
//WebServer (Impl) -> maybe webroot node should not be auto discovered, it should have a nodepath for safety
|
||||
// I - WebRoot
|
||||
// I - WebNodes ... (site)
|
||||
// I - HTTPSessionManager (finds parent websercver, registers itself in enter tree)
|
||||
// I - Other helper nodes, maybe a DatabaseManager (convert to node) etc These will not be accessible
|
||||
|
||||
//request->server->get_session_manager()->get_session(sid);
|
||||
|
||||
//request->session = HTTPSessionManager::get_singleton()->get_session(sid);
|
||||
HTTPSessionManager *sm = request->server->get_session_manager();
|
||||
ERR_FAIL_COND_V(!sm, false);
|
||||
request->session = sm->get_session(sid);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -18,10 +18,10 @@ class HTTPSessionManager : public Node {
|
||||
GDCLASS(HTTPSessionManager, Node);
|
||||
|
||||
public:
|
||||
void add_session(Ref<HTTPSession> &session);
|
||||
void remove_session(Ref<HTTPSession> &session);
|
||||
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);
|
||||
void save_session(Ref<HTTPSession> session);
|
||||
Ref<HTTPSession> get_session(const String &session_id);
|
||||
Ref<HTTPSession> create_session();
|
||||
|
||||
|
@ -329,6 +329,10 @@ void WebNode::clear_handlers() {
|
||||
_node_route_map.clear();
|
||||
}
|
||||
|
||||
void WebNode::request_write_lock() {
|
||||
_write_lock_requested = true;
|
||||
}
|
||||
|
||||
WebServer *WebNode::get_server() {
|
||||
// todo this shoult probably be cached
|
||||
return Object::cast_to<WebServer>(get_tree());
|
||||
@ -404,11 +408,8 @@ void WebNode::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_uri_segment", "val"), &WebNode::set_uri_segment);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "uri_segment"), "set_uri_segment", "get_uri_segment");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_uri_segment"), &WebNode::get_uri_segment);
|
||||
ClassDB::bind_method(D_METHOD("get_uri_segment"), &WebNode::get_uri_segment);
|
||||
|
||||
String get_full_uri(const bool slash_at_the_end = true);
|
||||
String get_full_uri_parent(const bool slash_at_the_end = true);
|
||||
ClassDB::bind_method(D_METHOD("get_full_uri", "slash_at_the_end "), &WebNode::get_full_uri, true);
|
||||
ClassDB::bind_method(D_METHOD("get_full_uri_parent", "slash_at_the_end "), &WebNode::get_full_uri_parent, true);
|
||||
|
||||
//#if WEB_SETTINGS_ENABLED
|
||||
// Settings *get_settings();
|
||||
|
@ -124,6 +124,7 @@ protected:
|
||||
|
||||
Ref<WebPermission> _web_permission;
|
||||
|
||||
//TODO this should be atomic
|
||||
bool _write_lock_requested;
|
||||
RWLock _rw_lock;
|
||||
};
|
||||
|
@ -54,6 +54,10 @@ void WebServer::server_handle_request(Ref<WebServerRequest> request) {
|
||||
_rw_lock.read_unlock();
|
||||
}
|
||||
|
||||
void WebServer::request_write_lock() {
|
||||
_write_lock_requested = true;
|
||||
}
|
||||
|
||||
void WebServer::start() {
|
||||
call("_start");
|
||||
}
|
||||
@ -87,7 +91,6 @@ void WebServer::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_session_manager"), &WebServer::get_session_manager_bind);
|
||||
ClassDB::bind_method(D_METHOD("set_session_manager", "val"), &WebServer::set_session_manager_bind);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "session_manager", PROPERTY_HINT_RESOURCE_TYPE, "HTTPSessionManager"), "set_session_manager", "get_session_manager");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("server_handle_request", "request"), &WebServer::server_handle_request);
|
||||
ClassDB::bind_method(D_METHOD("request_write_lock"), &WebServer::request_write_lock);
|
||||
|
@ -49,6 +49,7 @@ protected:
|
||||
|
||||
HTTPSessionManager *_session_manager;
|
||||
|
||||
//TODO this should be atomic
|
||||
bool _write_lock_requested;
|
||||
RWLock _rw_lock;
|
||||
};
|
||||
|
@ -25,19 +25,40 @@ SOFTWARE.
|
||||
//#include "core/engine.h"
|
||||
|
||||
#include "file_cache.h"
|
||||
|
||||
#include "html/html_builder_bind.h"
|
||||
|
||||
#include "http/csrf_token.h"
|
||||
#include "http/http_server_enums.h"
|
||||
#include "http/http_session.h"
|
||||
#include "http/http_session_manager.h"
|
||||
#include "http/web_node.h"
|
||||
#include "http/web_permission.h"
|
||||
#include "http/web_root.h"
|
||||
#include "http/web_server.h"
|
||||
#include "http/web_server_cookie.h"
|
||||
#include "http/web_server_middleware.h"
|
||||
#include "http/web_server_request.h"
|
||||
|
||||
void register_web_types() {
|
||||
ClassDB::register_class<HTTPServerEnums>();
|
||||
ClassDB::register_class<_HTMLBuilder>();
|
||||
ClassDB::register_class<_HTMLTag>();
|
||||
|
||||
ClassDB::register_class<FileCache>();
|
||||
|
||||
ClassDB::register_class<WebServerCookie>();
|
||||
ClassDB::register_class<HTTPServerEnums>();
|
||||
|
||||
ClassDB::register_class<_HTMLBuilder>();
|
||||
ClassDB::register_class<_HTMLTag>();
|
||||
ClassDB::register_class<CSRFTokenWebServerMiddleware>();
|
||||
ClassDB::register_class<HTTPSession>();
|
||||
ClassDB::register_class<HTTPSessionManager>();
|
||||
ClassDB::register_class<SessionSetupWebServerMiddleware>();
|
||||
ClassDB::register_class<WebNode>();
|
||||
ClassDB::register_class<WebPermission>();
|
||||
ClassDB::register_class<WebRoot>();
|
||||
ClassDB::register_class<WebServer>();
|
||||
ClassDB::register_class<WebServerCookie>();
|
||||
ClassDB::register_class<WebServerMiddleware>();
|
||||
ClassDB::register_class<WebServerRequest>();
|
||||
}
|
||||
|
||||
void unregister_web_types() {
|
||||
|
Loading…
Reference in New Issue
Block a user