2023-12-18 00:25:33 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* http_session.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* PANDEMONIUM ENGINE */
|
|
|
|
/* https://github.com/Relintai/pandemonium_engine */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* Copyright (c) 2022-present Péter Magyar. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2022-06-25 01:55:54 +02:00
|
|
|
|
|
|
|
#include "http_session.h"
|
|
|
|
|
2022-06-26 20:53:39 +02:00
|
|
|
String HTTPSession::get_session_id() {
|
|
|
|
return session_id;
|
|
|
|
}
|
|
|
|
void HTTPSession::set_session_id(const String &val) {
|
|
|
|
session_id = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
int HTTPSession::get_id() {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
void HTTPSession::set_id(const int val) {
|
|
|
|
id = val;
|
|
|
|
}
|
|
|
|
|
2022-06-25 01:55:54 +02:00
|
|
|
void HTTPSession::add(const String &key, const Variant &value) {
|
|
|
|
_mutex.lock();
|
|
|
|
|
|
|
|
_data[key] = value;
|
|
|
|
|
|
|
|
_mutex.unlock();
|
|
|
|
}
|
|
|
|
void HTTPSession::remove(const String &key) {
|
|
|
|
_mutex.lock();
|
|
|
|
|
|
|
|
_data[key] = Variant();
|
|
|
|
|
|
|
|
_mutex.unlock();
|
|
|
|
}
|
|
|
|
bool HTTPSession::has(const String &key) {
|
|
|
|
return !_data[key].is_null();
|
|
|
|
}
|
|
|
|
|
2022-06-26 20:53:39 +02:00
|
|
|
Variant HTTPSession::get_value(const String &key) {
|
2022-06-25 01:55:54 +02:00
|
|
|
return _data[key];
|
|
|
|
}
|
|
|
|
const Variant &HTTPSession::get_const(const String &key) {
|
|
|
|
return _data[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
Object *HTTPSession::get_object(const String &key) {
|
|
|
|
// don't lock here
|
|
|
|
|
2022-06-26 20:53:39 +02:00
|
|
|
return _data[key];
|
2022-06-25 01:55:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Reference> HTTPSession::get_reference(const String &key) {
|
|
|
|
// don't lock here
|
|
|
|
|
2022-06-26 20:53:39 +02:00
|
|
|
return Ref<Reference>(_data[key]);
|
2022-06-25 01:55:54 +02:00
|
|
|
}
|
|
|
|
|
2022-07-21 23:55:33 +02:00
|
|
|
int HTTPSession::get_int(const String &key, const int def) {
|
2022-06-25 01:55:54 +02:00
|
|
|
// don't lock here
|
|
|
|
|
2022-07-21 23:55:33 +02:00
|
|
|
Variant *v = _data.getptr(key);
|
|
|
|
|
|
|
|
if (!v) {
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *v;
|
2022-06-25 01:55:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void HTTPSession::clear() {
|
|
|
|
_data.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTTPSession::reset() {
|
|
|
|
clear();
|
|
|
|
session_id = "";
|
|
|
|
}
|
|
|
|
|
2022-06-26 20:53:39 +02:00
|
|
|
HashMap<String, Variant> *HTTPSession::get_data() {
|
2022-06-25 01:55:54 +02:00
|
|
|
return &_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
HTTPSession::HTTPSession() {
|
|
|
|
id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
HTTPSession::~HTTPSession() {
|
|
|
|
clear();
|
2022-06-26 20:53:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void HTTPSession::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("get_session_id"), &HTTPSession::get_session_id);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_session_id", "val"), &HTTPSession::set_session_id);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "session_id"), "set_session_id", "get_session_id");
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_id"), &HTTPSession::get_id);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_id", "val"), &HTTPSession::set_id);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "id"), "set_id", "get_id");
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("add", "key", "value"), &HTTPSession::add);
|
|
|
|
ClassDB::bind_method(D_METHOD("remove", "key"), &HTTPSession::remove);
|
|
|
|
ClassDB::bind_method(D_METHOD("has", "key"), &HTTPSession::has);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_value", "key"), &HTTPSession::get_value);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("clear"), &HTTPSession::clear);
|
|
|
|
ClassDB::bind_method(D_METHOD("reset"), &HTTPSession::reset);
|
|
|
|
}
|