Hobrasoft httpd server
Embedded HTTP server for Qt and C++
httpsessionstore.h
Go to the documentation of this file.
1 
8 #ifndef _HttpSessionStore_H_
9 #define _HttpSessionStore_H_
10 
11 #include <QObject>
12 #include <QHash>
13 #include <QTimer>
14 #include <QString>
15 #include "httpsession.h"
16 
17 namespace HobrasoftHttpd {
18 
19 class HttpSession;
20 class HttpServer;
21 class HttpRequest;
22 class HttpResponse;
23 class HttpSettings;
24 
25 
29 class HttpSessionStore : public QObject {
30  Q_OBJECT
31  public:
32 
36  HttpSessionStore(const HttpSettings *settings, QObject *parent);
37 
42 
46  QByteArray sessionId(HttpRequest *request, HttpResponse *response);
47 
51  HttpSession session(HttpRequest *request, HttpResponse *response);
52 
56  HttpSession session(const QByteArray& id);
57 
61  void remove(HttpSession session);
62 
68  void setSessionCookieName(const QString& x) { m_sessionCookieName = x; }
69 
73  const QString& sessionCookieName() const;
74 
75  bool contains(const QByteArray& id) const { return m_sessions.contains(id); }
76 
77  signals:
78 
82  void aboutToRemove(const HttpSession& session) const;
83 
84  private slots:
85 
89  void slotCleaner();
90 
91  private:
92  QTimer *m_cleaner;
93  QHash<QByteArray, HttpSession> m_sessions;
96  void init();
97 
98 };
99 
100 }
101 
102 #endif
QByteArray sessionId(HttpRequest *request, HttpResponse *response)
Returns session ID associated with the request or response.
HttpSessionStore(const HttpSettings *settings, QObject *parent)
Constructor.
Information about one session.
Definition: httpsession.h:33
QString m_sessionCookieName
The name of the session cookie.
General single-threaded, event-driven HTTP server.
Definition: httpserver.h:88
void aboutToRemove(const HttpSession &session) const
Signal is emited when a session is about to remove from storage.
HttpSession session(HttpRequest *request, HttpResponse *response)
Returns session associated with the request or response.
QHash< QByteArray, HttpSession > m_sessions
List of stored sessions.
Response to HTTP request - headers, cookies and body.
Definition: httpresponse.h:30
QTimer * m_cleaner
Timer for store cleaning from old sessions.
Configuration of the http server instance.
Definition: httpsettings.h:39
const HttpSettings * m_settings
Pointer to http server settings.
void setSessionCookieName(const QString &x)
Sets the name of the session cookie.
Processes HTTP request, parses headers, body and files sent by HTTP protocol.
Definition: httprequest.h:23
void slotCleaner()
Slot cleans the store from old sessions.
Namespace of HTTP server.
const QString & sessionCookieName() const
Returns the session cookie name.