5 #include "sessionstorefile.h"
7 #include <Cutelyst/Application>
8 #include <Cutelyst/Context>
10 #include <QCoreApplication>
11 #include <QDataStream>
15 #include <QLoggingCategory>
19 Q_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")
40 const QVariantHash data = loadSessionData(c, sid);
42 return data.value(key, defaultValue);
50 QVariantHash data = loadSessionData(c, sid);
52 data.insert(key, value);
53 c->
setStash(SESSION_STORE_FILE_DATA, data);
54 c->
setStash(SESSION_STORE_FILE_SAVE,
true);
61 QVariantHash data = loadSessionData(c, sid);
64 c->
setStash(SESSION_STORE_FILE_DATA, data);
65 c->
setStash(SESSION_STORE_FILE_SAVE,
true);
90 const QVariant sessionVariant = c->
stash(SESSION_STORE_FILE_DATA);
91 if (!sessionVariant.
isNull()) {
92 data = sessionVariant.
toHash();
96 const QString root = rootPath();
100 if (!
QDir().mkpath(root)) {
101 qCWarning(C_SESSION_FILE) <<
"Failed to create path for session object" << root;
112 if (!c->stash(SESSION_STORE_FILE_SAVE).toBool()) {
116 const QVariantHash data = c->
stash(SESSION_STORE_FILE_DATA).toHash();
118 if (data.isEmpty()) {
119 QFile::remove(file->fileName());
121 QLockFile lock(file->fileName() + QLatin1String(
".lock"));
123 QDataStream in(file);
131 if (file->pos() < file->size()) {
132 file->resize(file->pos());
149 c->
setStash(SESSION_STORE_FILE_DATA, data);
154 #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