QtWebApp
httpsessionstore.h
Go to the documentation of this file.
1 
6 #ifndef HTTPSESSIONSTORE_H
7 #define HTTPSESSIONSTORE_H
8 
9 #include <QObject>
10 #include <QMap>
11 #include <QTimer>
12 #include <QMutex>
13 #include "httpglobal.h"
14 #include "httpsession.h"
15 #include "httpresponse.h"
16 #include "httprequest.h"
17 
18 namespace stefanfrings {
19 
35 class DECLSPEC HttpSessionStore : public QObject {
36  Q_OBJECT
37  Q_DISABLE_COPY(HttpSessionStore)
38 public:
39 
50  HttpSessionStore(const QSettings* settings, QObject* parent=nullptr);
51 
53  virtual ~HttpSessionStore();
54 
64  QByteArray getSessionId(HttpRequest& request, HttpResponse& response);
65 
76  HttpSession getSession(HttpRequest& request, HttpResponse& response, const bool allowCreate=true);
77 
85  HttpSession getSession(const QByteArray id);
86 
88  void removeSession(const HttpSession session);
89 
90 protected:
92  QMap<QByteArray,HttpSession> sessions;
93 
94 private:
95 
97  const QSettings* settings;
98 
100  QTimer cleanupTimer;
101 
103  QByteArray cookieName;
104 
106  int expirationTime;
107 
109  QMutex mutex;
110 
111 private slots:
112 
114  void sessionTimerEvent();
115 
116 signals:
117 
122  void sessionDeleted(const QByteArray& sessionId);
123 };
124 
125 } // end of namespace
126 
127 #endif // HTTPSESSIONSTORE_H
This object represents a single HTTP request.
Definition: httprequest.h:37
This object represents a HTTP response, used to return something to the web client.
Definition: httpresponse.h:36
Stores HTTP sessions and deletes them when they have expired.
QMap< QByteArray, HttpSession > sessions
Storage for the sessions.
void sessionDeleted(const QByteArray &sessionId)
Emitted when the session is deleted.
This class stores data for a single HTTP session.
Definition: httpsession.h:23