2021-08-04 20:32:51 +02:00
|
|
|
|
|
|
|
#include "http_session.h"
|
|
|
|
|
2022-01-09 14:32:09 +01:00
|
|
|
void HTTPSession::add(const String &key, const Variant &value) {
|
|
|
|
_mutex.lock();
|
2021-08-04 20:32:51 +02:00
|
|
|
|
2022-01-09 14:32:09 +01:00
|
|
|
_data[key] = value;
|
|
|
|
|
|
|
|
_mutex.unlock();
|
2021-08-04 20:32:51 +02:00
|
|
|
}
|
2022-01-09 14:32:09 +01:00
|
|
|
void HTTPSession::remove(const String &key) {
|
|
|
|
_mutex.lock();
|
|
|
|
|
|
|
|
_data[key] = Variant();
|
2021-08-04 20:32:51 +02:00
|
|
|
|
2022-01-09 14:32:09 +01:00
|
|
|
_mutex.unlock();
|
|
|
|
}
|
|
|
|
bool HTTPSession::has(const String &key) {
|
2022-01-09 15:48:54 +01:00
|
|
|
return !_data[key].is_null();
|
2021-08-04 20:32:51 +02:00
|
|
|
}
|
|
|
|
|
2022-01-09 14:32:09 +01:00
|
|
|
Variant HTTPSession::get(const String &key) {
|
2021-08-04 20:32:51 +02:00
|
|
|
return _data[key];
|
|
|
|
}
|
2022-01-09 14:51:04 +01:00
|
|
|
const Variant &HTTPSession::get_const(const String &key) {
|
|
|
|
return _data[key];
|
|
|
|
}
|
2021-08-04 20:32:51 +02:00
|
|
|
|
2022-01-09 14:32:09 +01:00
|
|
|
Object *HTTPSession::get_object(const String &key) {
|
|
|
|
// don't lock here
|
2021-08-22 22:03:10 +02:00
|
|
|
|
2022-01-09 14:32:09 +01:00
|
|
|
return _data[key].to_object();
|
2021-08-22 22:03:10 +02:00
|
|
|
}
|
|
|
|
|
2021-11-01 19:11:27 +01:00
|
|
|
Ref<Reference> HTTPSession::get_reference(const String &key) {
|
2022-01-09 14:32:09 +01:00
|
|
|
// don't lock here
|
2021-08-22 22:03:10 +02:00
|
|
|
|
2022-01-09 14:32:09 +01:00
|
|
|
return _data[key].to_reference();
|
2021-08-22 22:03:10 +02:00
|
|
|
}
|
|
|
|
|
2021-11-01 19:11:27 +01:00
|
|
|
int HTTPSession::get_int(const String &key) {
|
2022-01-09 14:32:09 +01:00
|
|
|
// don't lock here
|
2021-08-04 20:32:51 +02:00
|
|
|
|
2022-01-09 14:32:09 +01:00
|
|
|
return _data[key].to_int();
|
2021-08-04 20:32:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void HTTPSession::clear() {
|
|
|
|
_data.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTTPSession::reset() {
|
|
|
|
clear();
|
|
|
|
session_id = "";
|
|
|
|
}
|
|
|
|
|
2022-01-09 14:32:09 +01:00
|
|
|
std::map<String, Variant> *HTTPSession::get_data() {
|
|
|
|
return &_data;
|
2021-08-22 23:53:26 +02:00
|
|
|
}
|
|
|
|
|
2021-08-04 20:32:51 +02:00
|
|
|
HTTPSession::HTTPSession() {
|
2021-08-22 23:53:26 +02:00
|
|
|
id = 0;
|
2021-08-04 20:32:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HTTPSession::~HTTPSession() {
|
|
|
|
clear();
|
|
|
|
}
|