From a92f8dd5c0be08c8de472135dcbbb3d63ed91b79 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 26 Jun 2022 17:03:06 +0200 Subject: [PATCH] Added bindings for WebServerCookie and adde dit to the build. --- modules/web/SCsub | 1 + modules/web/config.py | 1 + modules/web/http/web_server_cookie.cpp | 75 ++++++++++++++++++++++++-- modules/web/http/web_server_cookie.h | 40 +++++++++++--- modules/web/register_types.cpp | 3 ++ 5 files changed, 109 insertions(+), 11 deletions(-) diff --git a/modules/web/SCsub b/modules/web/SCsub index db78f32dc..656624b80 100644 --- a/modules/web/SCsub +++ b/modules/web/SCsub @@ -9,6 +9,7 @@ sources = [ "register_types.cpp", "http/http_server_enums.cpp", + "http/web_server_cookie.cpp", "html/html_builder_bind.cpp", ] diff --git a/modules/web/config.py b/modules/web/config.py index 34eb72b26..4bca6254f 100644 --- a/modules/web/config.py +++ b/modules/web/config.py @@ -14,6 +14,7 @@ def get_doc_classes(): #"WorldArea", "HTTPServerEnums", + "WebServerCookie", "HTMLBuilder", "HTMLTag", ] diff --git a/modules/web/http/web_server_cookie.cpp b/modules/web/http/web_server_cookie.cpp index 7e2efe3f3..524d7fc7d 100644 --- a/modules/web/http/web_server_cookie.cpp +++ b/modules/web/http/web_server_cookie.cpp @@ -1,10 +1,49 @@ -#include "cookie.h" +#include "web_server_cookie.h" -WebServerCookie::WebServerCookie(const String &p_key, const String &p_value) { - http_only = true; - secure = false; +String WebServerCookie::get_domain() { + return domain; +} +void WebServerCookie::set_domain(const String &val) { + domain = val; +} +String WebServerCookie::get_path() { + return path; +} +void WebServerCookie::set_path(const String &val) { + path = val; +} + +String WebServerCookie::get_key() { + return key; +} +void WebServerCookie::set_key(const String &val) { + key = val; +} + +String WebServerCookie::get_value() { + return value; +} +void WebServerCookie::set_value(const String &val) { + value = val; +} + +bool WebServerCookie::get_http_only() { + return http_only; +} +void WebServerCookie::set_http_only(const bool val) { + http_only = val; +} + +bool WebServerCookie::get_secure() { + return secure; +} +void WebServerCookie::set_secure(const bool val) { + secure = val; +} + +void WebServerCookie::set_data(const String &p_key, const String &p_value) { key = p_key; value = p_value; } @@ -16,3 +55,31 @@ WebServerCookie::WebServerCookie() { WebServerCookie::~WebServerCookie() { } + +void WebServerCookie::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_domain"), &WebServerCookie::get_domain); + ClassDB::bind_method(D_METHOD("set_domain", "val"), &WebServerCookie::set_domain); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "domain"), "set_domain", "get_domain"); + + ClassDB::bind_method(D_METHOD("get_path"), &WebServerCookie::get_path); + ClassDB::bind_method(D_METHOD("set_path", "val"), &WebServerCookie::set_path); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "path"), "set_path", "get_path"); + + ClassDB::bind_method(D_METHOD("get_key"), &WebServerCookie::get_key); + ClassDB::bind_method(D_METHOD("set_key", "val"), &WebServerCookie::set_key); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "key"), "set_key", "get_key"); + + ClassDB::bind_method(D_METHOD("get_value"), &WebServerCookie::get_value); + ClassDB::bind_method(D_METHOD("set_value", "val"), &WebServerCookie::set_value); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "value"), "set_value", "get_value"); + + ClassDB::bind_method(D_METHOD("get_http_only"), &WebServerCookie::get_http_only); + ClassDB::bind_method(D_METHOD("set_http_only", "val"), &WebServerCookie::set_http_only); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "http_only"), "set_http_only", "get_http_only"); + + ClassDB::bind_method(D_METHOD("get_secure"), &WebServerCookie::get_secure); + ClassDB::bind_method(D_METHOD("set_secure", "val"), &WebServerCookie::set_secure); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "secure"), "set_secure", "get_secure"); + + ClassDB::bind_method(D_METHOD("set_data", "key", "value"), &WebServerCookie::set_data); +} diff --git a/modules/web/http/web_server_cookie.h b/modules/web/http/web_server_cookie.h index 2d12060c8..ee12e2890 100644 --- a/modules/web/http/web_server_cookie.h +++ b/modules/web/http/web_server_cookie.h @@ -1,10 +1,37 @@ -#ifndef COOKIE_H -#define COOKIE_H +#ifndef WEB_SERVER_COOKIE_H +#define WEB_SERVER_COOKIE_H -#include "core/string.h" +#include "core/ustring.h" + +#include "core/reference.h" + +class WebServerCookie : public Reference { + GDCLASS(WebServerCookie, Reference); -class WebServerCookie { public: + String get_domain(); + void set_domain(const String &val); + + String get_path(); + void set_path(const String &val); + + String get_key(); + void set_key(const String &val); + + String get_value(); + void set_value(const String &val); + + bool get_http_only(); + void set_http_only(const bool val); + + bool get_secure(); + void set_secure(const bool val); + + void set_data(const String &p_key, const String &p_value); + + WebServerCookie(); + ~WebServerCookie(); + //todo date String domain; String path; @@ -13,9 +40,8 @@ public: bool http_only; bool secure; - WebServerCookie(); - WebServerCookie(const String &p_key, const String &p_value); - ~WebServerCookie(); +protected: + static void _bind_methods(); }; #endif diff --git a/modules/web/register_types.cpp b/modules/web/register_types.cpp index eb7b8df7b..9ec14acf9 100644 --- a/modules/web/register_types.cpp +++ b/modules/web/register_types.cpp @@ -26,10 +26,13 @@ SOFTWARE. #include "html/html_builder_bind.h" #include "http/http_server_enums.h" +#include "http/web_server_cookie.h" void register_web_types() { ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class<_HTMLBuilder>(); ClassDB::register_class<_HTMLTag>(); }