5#include "sessionstorefile.h"
7#include <Cutelyst/Application>
8#include <Cutelyst/Context>
10#include <QCoreApplication>
15#include <QLoggingCategory>
19Q_LOGGING_CATEGORY(C_SESSION_FILE,
"cutelyst.plugin.sessionfile", QtWarningMsg)
21#define SESSION_STORE_FILE_SAVE QStringLiteral("_c_session_store_file_save")
22#define SESSION_STORE_FILE_DATA QStringLiteral("_c_session_store_file_data")
49 const QVariantHash data = loadSessionData(c, sid);
51 return data.value(key, defaultValue);
59 QVariantHash data = loadSessionData(c, sid);
61 data.insert(key, value);
62 c->
setStash(SESSION_STORE_FILE_DATA, data);
63 c->
setStash(SESSION_STORE_FILE_SAVE,
true);
70 QVariantHash data = loadSessionData(c, sid);
73 c->
setStash(SESSION_STORE_FILE_DATA, data);
74 c->
setStash(SESSION_STORE_FILE_SAVE,
true);
93 const QVariant sessionVariant = c->
stash(SESSION_STORE_FILE_DATA);
94 if (!sessionVariant.
isNull()) {
95 data = sessionVariant.
toHash();
99 const QString root = rootPath();
103 if (!
QDir().mkpath(root)) {
104 qCWarning(C_SESSION_FILE) <<
"Failed to create path for session object" << root;
115 if (!c->stash(SESSION_STORE_FILE_SAVE).toBool()) {
119 const QVariantHash data = c->
stash(SESSION_STORE_FILE_DATA).toHash();
121 if (data.isEmpty()) {
134 if (file->pos() < file->size()) {
135 file->resize(file->pos());
152 c->
setStash(SESSION_STORE_FILE_DATA, data);
158#include "moc_sessionstorefile.cpp"
void afterDispatch(Cutelyst::Context *c)
void stash(const QVariantHash &unite)
void setStash(const QString &key, const QVariant &value)
Application * app() const noexcept
SessionStoreFile(QObject *parent=nullptr)
virtual bool storeSessionData(Context *c, const QByteArray &sid, const QString &key, const QVariant &value) final
virtual bool deleteSessionData(Context *c, const QByteArray &sid, const QString &key) final
virtual QVariant getSessionData(Context *c, const QByteArray &sid, const QString &key, const QVariant &defaultValue) final
virtual bool deleteExpiredSessions(Context *c, quint64 expires) final
Abstract class to create a session store.
The Cutelyst namespace holds all public Cutelyst API.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString fromLatin1(QByteArrayView str)
bool isNull() const const
QHash< QString, QVariant > toHash() const const