tufao  1.3.0
An asynchronous web framework for C++ built on top of Qt
sessionstore.h
1 /*
2  Copyright (c) 2012 Vinícius dos Santos Oliveira
3 
4  Permission is hereby granted, free of charge, to any person obtaining a copy
5  of this software and associated documentation files (the "Software"), to deal
6  in the Software without restriction, including without limitation the rights
7  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  copies of the Software, and to permit persons to whom the Software is
9  furnished to do so, subject to the following conditions:
10 
11  The above copyright notice and this permission notice shall be included in all
12  copies or substantial portions of the Software.
13 
14  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  SOFTWARE.
21  */
22 
23 #ifndef TUFAO_SESSIONSTORE_H
24 #define TUFAO_SESSIONSTORE_H
25 
26 #include "httpserverrequest.h"
27 #include "sessionsettings.h"
28 
29 namespace Tufao {
30 
220 class TUFAO_EXPORT SessionStore : public QObject
221 {
222  Q_OBJECT
223 public:
230  explicit SessionStore(const SessionSettings &settings = defaultSettings(),
231  QObject *parent = 0);
232 
236  ~SessionStore();
237 
241  virtual bool hasSession(const HttpServerRequest &request) const = 0;
242 
248  virtual void removeSession(const HttpServerRequest &request,
249  HttpServerResponse &response) = 0;
250 
260  void resetSession(HttpServerRequest &request) const;
261 
267  virtual QList<QByteArray> properties(const HttpServerRequest &request,
268  const HttpServerResponse &response)
269  const = 0;
270 
276  virtual bool hasProperty(const HttpServerRequest &request,
277  const HttpServerResponse &response,
278  const QByteArray &key) const = 0;
279 
286  virtual QVariant property(const HttpServerRequest &request,
287  HttpServerResponse &response,
288  const QByteArray &key) const = 0;
289 
295  virtual void setProperty(const HttpServerRequest &request,
296  HttpServerResponse &response,
297  const QByteArray &key, const QVariant &value) = 0;
298 
304  virtual void removeProperty(const HttpServerRequest &request,
305  HttpServerResponse &response,
306  const QByteArray &key) = 0;
307 
317  void setMacSecret(const QByteArray &secret);
318 
333  static SessionSettings defaultSettings();
334 
335 protected:
345  QByteArray session(const HttpServerRequest &request) const;
346 
360  QByteArray session(const HttpServerRequest &request,
361  const HttpServerResponse &response) const;
362 
381  void setSession(HttpServerResponse &response, const QByteArray &session)
382  const;
383 
390  void unsetSession(HttpServerResponse &response) const;
391 
398 
399  private:
400  QByteArray signSession(const QByteArray &message) const;
401  QByteArray unsignSession(const QByteArray &message) const;
402 
403  struct Priv;
404  Priv *priv;
405 };
406 
407 } // Namespace Tufao
408 
409 #endif // TUFAO_SESSIONSTORE_H
The SessionSettings class exposes details that sessions use to handle cookies.
Definition: sessionsettings.h:55
The Tufao::HttpServerResponse is used to respond to a Tufao::HttpServerRequest.
Definition: httpserverresponse.h:142
SessionSettings settings
This attribute represents the session's settings.
Definition: sessionstore.h:397
The Tufao::HttpServer represents a HTTP request received by Tufao::HttpServer.
Definition: httpserverrequest.h:54
This is the namespace where all Tufão facilities are grouped.
Definition: abstracthttpserverrequesthandler.h:30
SessionStore class can be used to store data that must persist among different requests.
Definition: sessionstore.h:220