tufao  1.3.0
An asynchronous web framework for C++ built on top of Qt
sessionsettings.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_SESSIONSETTINGS_H
24 #define TUFAO_SESSIONSETTINGS_H
25 
26 #include <QtNetwork/QNetworkCookie>
27 #include <QtCore/QDateTime>
28 
29 namespace Tufao {
30 
56 {
60  QNetworkCookie cookie(const QByteArray &value = QByteArray()) const
61  {
62  return cookie(*this, value);
63  }
64 
69  static QNetworkCookie cookie(const SessionSettings &settings,
70  const QByteArray &value = QByteArray())
71  {
72  QNetworkCookie cookie;
73 
74  if (settings.timeout) {
75  cookie.setExpirationDate(QDateTime::currentDateTimeUtc()
76  .addSecs(settings.timeout * 60));
77  }
78  cookie.setHttpOnly(settings.httpOnly);
79  cookie.setSecure(settings.secure);
80  if (!settings.domain.isEmpty()) cookie.setDomain(settings.domain);
81  if (!settings.path.isEmpty()) cookie.setPath(settings.path);
82 
83  cookie.setName(settings.name);
84  cookie.setValue(value);
85 
86  return cookie;
87  }
88 
100  int timeout;
101 
111  bool httpOnly;
112 
117  QByteArray name;
118 
141  QByteArray path;
142 
160  bool secure;
161 
188  QByteArray domain;
189 };
190 
191 } // namespace Tufao
192 
193 #endif // TUFAO_SESSION_H
QByteArray name
The name to which cookies generated by this object are used.
Definition: sessionsettings.h:117
The SessionSettings class exposes details that sessions use to handle cookies.
Definition: sessionsettings.h:55
bool secure
Whether cookies generated by this object should only be used through secure connections.
Definition: sessionsettings.h:160
QNetworkCookie cookie(const QByteArray &value=QByteArray()) const
Creates a cookie, using value as the cookie's value.
Definition: sessionsettings.h:60
int timeout
Define the lifetime of cookies generated by this object (a timeout specified in minutes).
Definition: sessionsettings.h:100
This is the namespace where all Tufão facilities are grouped.
Definition: abstracthttpserverrequesthandler.h:30
QByteArray domain
The hosts to which cookies generated by this object are used.
Definition: sessionsettings.h:188
static QNetworkCookie cookie(const SessionSettings &settings, const QByteArray &value=QByteArray())
Creates a cookie, using value as the cookie's value and settings as cookie's settings.
Definition: sessionsettings.h:69
bool httpOnly
Whether cookies generated by this object should only be used in HTTP requests.
Definition: sessionsettings.h:111
QByteArray path
The set of paths to which cookies generated by this object are used.
Definition: sessionsettings.h:141