Cutelyst  2.13.0
session.h
1 /*
2  * Copyright (C) 2013-2017 Daniel Nicoletti <dantti12@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 #ifndef CSESSION_H
19 #define CSESSION_H
20 
21 #include <QVariant>
22 
23 #include <Cutelyst/plugin.h>
24 #include <Cutelyst/cutelyst_global.h>
25 
26 namespace Cutelyst {
27 
28 class Context;
29 class CUTELYST_PLUGIN_SESSION_EXPORT SessionStore : public QObject {
30  Q_OBJECT
31 public:
35  explicit SessionStore(QObject *parent = nullptr);
36 
40  virtual QVariant getSessionData(Context *c, const QString &sid, const QString &key, const QVariant &defaultValue = QVariant()) = 0;
41 
45  virtual bool storeSessionData(Context *c, const QString &sid, const QString &key, const QVariant &value) = 0;
46 
50  virtual bool deleteSessionData(Context *c, const QString &sid, const QString &key) = 0;
51 
55  virtual bool deleteExpiredSessions(Context *c, quint64 expires) = 0;
56 };
57 
58 class SessionPrivate;
105 class CUTELYST_PLUGIN_SESSION_EXPORT Session : public Plugin
106 {
107  Q_OBJECT
108  Q_DECLARE_PRIVATE(Session)
109 public:
113  Session(Application *parent);
114  virtual ~Session();
115 
119  virtual bool setup(Application *app) final;
120 
124  void setStorage(SessionStore *store);
125 
129  SessionStore *storage() const;
130 
135  static QString id(Context *c);
136 
141  static quint64 expires(Context *c);
142 
148  static void changeExpires(Context *c, quint64 expires);
149 
156  static void deleteSession(Context *c, const QString &reason = QString());
157 
164  static QString deleteReason(Context *c);
165 
169  static QVariant value(Context *c, const QString &key, const QVariant &defaultValue = QVariant());
170 
174  static void setValue(Context *c, const QString &key, const QVariant &value);
175 
179  static void deleteValue(Context *c, const QString &key);
180 
184  static void deleteValues(Context *c, const QStringList &keys);
185 
189  static bool isValid(Context *c);
190 
191 protected:
192  SessionPrivate *d_ptr;
193 
194 private:
195  Q_PRIVATE_SLOT(d_func(), void _q_saveSession(Context*))
196 };
197 
198 }
199 
200 #endif // CSESSION_H
Cutelyst::Plugin
Definition: plugin.h:30
Cutelyst::Session
Definition: session.h:105
Cutelyst::Application
The Cutelyst Application.
Definition: application.h:55
Cutelyst::Context
The Cutelyst Context.
Definition: context.h:50
Cutelyst::SessionStore
Definition: session.h:29
Cutelyst
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7