pandemonium_engine/modules/web/http/web_server_cookie.cpp

192 lines
6.3 KiB
C++
Raw Normal View History

#include "web_server_cookie.h"
String WebServerCookie::get_domain() {
2022-07-21 14:05:55 +02:00
return _domain;
}
void WebServerCookie::set_domain(const String &val) {
2022-07-21 14:05:55 +02:00
_domain = val;
}
String WebServerCookie::get_path() {
2022-07-21 14:05:55 +02:00
return _path;
}
void WebServerCookie::set_path(const String &val) {
2022-07-21 14:05:55 +02:00
_path = val;
}
String WebServerCookie::get_key() {
2022-07-21 14:05:55 +02:00
return _key;
}
void WebServerCookie::set_key(const String &val) {
2022-07-21 14:05:55 +02:00
_key = val;
}
String WebServerCookie::get_value() {
2022-07-21 14:05:55 +02:00
return _value;
}
void WebServerCookie::set_value(const String &val) {
2022-07-21 14:05:55 +02:00
_value = val;
}
bool WebServerCookie::get_http_only() {
2022-07-21 14:05:55 +02:00
return _http_only;
}
void WebServerCookie::set_http_only(const bool val) {
2022-07-21 14:05:55 +02:00
_http_only = val;
}
bool WebServerCookie::get_secure() {
2022-07-21 14:05:55 +02:00
return _secure;
}
void WebServerCookie::set_secure(const bool val) {
2022-07-21 14:05:55 +02:00
_secure = val;
}
bool WebServerCookie::get_delete() {
return _delete;
}
void WebServerCookie::set_delete(const bool val) {
_delete = val;
}
bool WebServerCookie::get_should_expire() {
return _should_expire;
}
void WebServerCookie::set_should_expire(const bool val) {
_should_expire = val;
}
uint64_t WebServerCookie::get_expiry_date_unix_time() {
return OS::get_singleton()->get_unix_time_from_datetime(_expiry_date);
}
void WebServerCookie::set_expiry_date_unix_time(const uint64_t unix_time) {
_expiry_date = OS::get_singleton()->get_datetime_from_unix_time(unix_time);
_should_expire = true;
}
OS::DateTime WebServerCookie::get_expiry_date() {
return _expiry_date;
}
void WebServerCookie::set_expiry_date(OS::DateTime date_time) {
_expiry_date = date_time;
_should_expire = true;
}
void WebServerCookie::set_expiry_date(OS::Date date, OS::Time time) {
_expiry_date.date = date;
_expiry_date.time = time;
_should_expire = true;
}
Dictionary WebServerCookie::get_expiry_date_dict() {
Dictionary date_time;
date_time["year"] = _expiry_date.date.year;
date_time["month"] = _expiry_date.date.month;
date_time["day"] = _expiry_date.date.day;
date_time["weekday"] = _expiry_date.date.weekday;
date_time["dst"] = _expiry_date.date.dst;
date_time["hour"] = _expiry_date.time.hour;
date_time["minute"] = _expiry_date.time.min;
date_time["second"] = _expiry_date.time.sec;
return date_time;
}
void WebServerCookie::set_expiry_date_dict(const Dictionary &date, const Dictionary &time) {
int month = date["month"];
int weekday = date["weekday"];
_expiry_date.date.year = date["year"];
_expiry_date.date.month = static_cast<OS::Month>(month);
_expiry_date.date.day = date["day"];
_expiry_date.date.weekday = static_cast<OS::Weekday>(weekday);
_expiry_date.date.dst = date["dst"];
_expiry_date.time.hour = time["hour"];
_expiry_date.time.min = time["minute"];
_expiry_date.time.sec = time["second"];
_should_expire = true;
}
void WebServerCookie::set_expiry_date_dt_dict(const Dictionary &date_time) {
int month = date_time["month"];
int weekday = date_time["weekday"];
_expiry_date.date.year = date_time["year"];
_expiry_date.date.month = static_cast<OS::Month>(month);
_expiry_date.date.day = date_time["day"];
_expiry_date.date.weekday = static_cast<OS::Weekday>(weekday);
_expiry_date.date.dst = date_time["dst"];
_expiry_date.time.hour = date_time["hour"];
_expiry_date.time.min = date_time["minute"];
_expiry_date.time.sec = date_time["second"];
_should_expire = true;
}
void WebServerCookie::set_data(const String &p_key, const String &p_value) {
2022-07-21 14:05:55 +02:00
_key = p_key;
_value = p_value;
}
String WebServerCookie::get_response_header_string() {
return "";
}
2022-06-26 15:00:25 +02:00
WebServerCookie::WebServerCookie() {
2022-07-21 14:05:55 +02:00
_should_expire = false;
_http_only = true;
_secure = false;
_delete = false;
}
2022-06-26 15:00:25 +02:00
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");
2022-07-21 14:05:55 +02:00
ClassDB::bind_method(D_METHOD("get_delete"), &WebServerCookie::get_delete);
ClassDB::bind_method(D_METHOD("set_delete", "val"), &WebServerCookie::set_delete);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "delete"), "set_delete", "get_delete");
ClassDB::bind_method(D_METHOD("get_should_expire"), &WebServerCookie::get_should_expire);
ClassDB::bind_method(D_METHOD("set_should_expire", "val"), &WebServerCookie::set_should_expire);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "should_expire"), "set_should_expire", "get_should_expire");
ClassDB::bind_method(D_METHOD("get_expiry_date_unix_time"), &WebServerCookie::get_expiry_date_unix_time);
ClassDB::bind_method(D_METHOD("set_expiry_date_unix_time", "unix_time"), &WebServerCookie::set_expiry_date_unix_time);
ClassDB::bind_method(D_METHOD("get_expiry_date"), &WebServerCookie::get_expiry_date_dict);
ClassDB::bind_method(D_METHOD("set_expiry_date", "date", "time"), &WebServerCookie::set_expiry_date_dict);
ClassDB::bind_method(D_METHOD("set_expiry_date_dt", "date_time"), &WebServerCookie::set_expiry_date_dt_dict);
ClassDB::bind_method(D_METHOD("set_data", "key", "value"), &WebServerCookie::set_data);
2022-07-21 14:05:55 +02:00
ClassDB::bind_method(D_METHOD("get_response_header_string"), &WebServerCookie::get_response_header_string);
}