Hobrasoft httpd server
Embedded HTTP server for Qt and C++
httpsettings.h
Go to the documentation of this file.
1 
7 #ifndef _HTTP_SETTINGS_H_
8 #define _HTTP_SETTINGS_H_
9 
10 #include <QHostAddress>
11 #include <QSettings>
12 #include <QSslError>
13 #include <QSet>
14 
15 int qHash(const QSslError error);
16 
17 namespace HobrasoftHttpd {
18 
39 class HttpSettings : public QObject {
40  Q_OBJECT
41  public:
42 
46  HttpSettings(QObject *parent);
47 
51  HttpSettings(const QSettings *, QObject *parent);
52 
58  HttpSettings(const QSettings *, const QString& section, QObject *parent);
59 
60  const QHostAddress& address() const { return m_address; }
61  void setAddress(const QHostAddress& x) { m_address = x; }
62  void setDefaultAddress(const QHostAddress& x) { m_default_address = x; }
63 
64  int port() const { return m_port; }
65  void setPort(int x) { m_port = x; }
66  void setDefaultPort(int x) { m_default_port = x; }
67 
68  int timeout() const { return m_timeout; }
69  void setTimeout(int x) { m_timeout = x; }
70  void setDefaultTimeout(int x) { m_default_timeout = x; }
71 
72  int maxAge() const { return m_maxAge; }
73  void setMaxAge(int x) { m_maxAge = x; }
74  void setDefaultMaxAge(int x) { m_default_maxAge = x; }
75 
76  const QString& encoding() const { return m_encoding; }
77  void setEncoding(const QString& x) { m_encoding = x; }
78  void setDefaultEncoding(const QString& x) { m_default_encoding = x; }
79 
80  const QString& docroot() const { return m_docroot; }
81  void setDocroot(const QString& x) { m_docroot = x; }
82  void setDefaultDocroot(const QString& x) { m_default_docroot = x; }
83 
84  const QString& indexFile() const { return m_indexFile; }
85  void setIndexFile(const QString& x) { m_indexFile = x; }
86  void setDefaultIndexFile(const QString& x) { m_default_indexFile = x; }
87 
88  int sessionExpirationTime() const { return m_sessionExpirationTime; }
89  void setExpirationTime(int x) { m_sessionExpirationTime = x; }
90  void setDefaultExpirationTime(int x) { m_default_sessionExpirationTime = x;}
91 
92  const QString& sessionCookieName() const { return m_sessionCookieName; }
93  void setSessionCookieName(const QString& x) { m_sessionCookieName = x; }
94  void setDefaultSessionCookieName(const QString& x) { m_default_sessionCookieName = x; }
95 
96  int maxRequestSize() const { return m_maxRequestSize; }
97  void setMaxRequestSize(int x) { m_maxRequestSize = x; }
98  void setDefaultMaxRequestSize(int x) { m_default_maxRequestSize = x; }
99 
100  int maxMultiPartSize() const { return m_maxMultiPartSize; }
101  void setMaxMultiPartSize(int x) { m_maxMultiPartSize = x; }
102  void setDefaultMaxMultiPartSize(int x) { m_default_maxMultiPartSize = x; }
103 
104  const QString& tempDir() const { return m_tempDir; }
105  void setTempDir(const QString& x) { m_tempDir = x; }
106  void setDefaultTempDir(const QString& x) { m_default_tempDir = x; }
107 
108  bool useSSL() const { return m_useSSL; }
109  void setUseSSL(bool x) { m_useSSL = x; }
110  void setDefaultUseSSL(bool x) { m_default_useSSL = x; }
111 
112  bool threads() const { return m_threads; }
113  void setThreads(bool x) { m_threads = x; }
114  void setDefaultThreads(bool x) { m_default_threads = x; }
115 
116  bool gzip() const { return m_gzip; }
117  void setGzip(bool x) { m_gzip = x; }
118  void setDefaultGzip(bool x) { m_default_gzip = x; }
119 
120  const QString& sslKey() const { return m_sslKey; }
121  void setSslKey(const QString& x) { m_sslKey = x; }
122  void setDefaultSslKey(const QString& x) { m_default_sslKey = x; }
123 
124  const QString& sslCrt() const { return m_sslCrt; }
125  void setSslCrt(const QString& x) { m_sslCrt = x; }
126  void setDefaultSslCrt(const QString& x) { m_default_sslCrt = x; }
127 
128  const QString& sslCaCrt() const { return m_sslCaCrt; }
129  void setSslCaCrt(const QString& x) { m_sslCaCrt = x; }
130  void setDefaultSslCaCrt(const QString& x) { m_default_sslCaCrt = x; }
131 
132 
133  bool ignoreSslError(QSslError error) const;
134 
158  void readSettings(const QSettings* settings, const QString& section, const QString& section2);
159 
160 
164  void readSettings(const QSettings* settings, const QString& section);
165 
171  void setSection2(const QString& section) { m_section2 = section; }
172 
173  protected:
174  #ifndef DOXYGEN_SHOULD_SKIP_THIS
175  QString m_section2;
176  int m_port;
177  QHostAddress m_address;
178  int m_timeout;
179  int m_maxAge;
180  QString m_encoding;
181  QString m_docroot;
182  QString m_indexFile;
183  QString m_sessionCookieName;
184  int m_sessionExpirationTime;
185  int m_maxRequestSize;
186  int m_maxMultiPartSize;
187  QString m_tempDir;
188  bool m_useSSL;
189  QString m_sslKey;
190  QString m_sslCrt;
191  QString m_sslCaCrt;
192  QSet<QSslError> m_sslErrors;
193  bool m_ignoreAllSslErrors;
194  bool m_threads;
195  bool m_gzip;
196 
197  // Default values
198  QString m_default_section2;
199  int m_default_port;
200  QHostAddress m_default_address;
201  int m_default_timeout;
202  int m_default_maxAge;
203  QString m_default_encoding;
204  QString m_default_docroot;
205  QString m_default_indexFile;
206  QString m_default_sessionCookieName;
207  int m_default_sessionExpirationTime;
208  int m_default_maxRequestSize;
209  int m_default_maxMultiPartSize;
210  QString m_default_tempDir;
211  bool m_default_useSSL;
212  QString m_default_sslKey;
213  QString m_default_sslCrt;
214  QString m_default_sslCaCrt;
215  bool m_default_ignoreAllSslErrors;
216  bool m_default_threads;
217  bool m_default_gzip;
218  #endif
219 
220  private:
221  void setDefaultValues();
222 
223 };
224 
225 }
226 
227 #endif
void readSettings(const QSettings *settings, const QString &section, const QString &section2)
Read settings from configuration file.
void setDefaultMaxAge(int x)
Sets the default max age cacheing proxy objects.
Definition: httpsettings.h:74
bool ignoreSslError(QSslError error) const
Returns true if the error should be ignored, default true.
void setMaxAge(int x)
Sets the max age cacheing proxy objects.
Definition: httpsettings.h:73
void setDefaultMaxMultiPartSize(int x)
Sets default maximum request size in multipart requests.
Definition: httpsettings.h:102
void setDefaultSessionCookieName(const QString &x)
Sets session cookie name.
Definition: httpsettings.h:94
int maxMultiPartSize() const
Returns maximum request size in multipart requests.
Definition: httpsettings.h:100
void setDefaultGzip(bool x)
Set default value for gzip compression.
Definition: httpsettings.h:118
const QString & encoding() const
Returns the encoding in COntent-type header.
Definition: httpsettings.h:76
const QString & sessionCookieName() const
Returns session cookie name.
Definition: httpsettings.h:92
void setThreads(bool x)
Set starting new thread for each connection.
Definition: httpsettings.h:113
void setDefaultSslCrt(const QString &x)
Set default SSL certificate.
Definition: httpsettings.h:126
void setDefaultPort(int x)
Sets the default port number.
Definition: httpsettings.h:66
void setDocroot(const QString &x)
Sets path to document root.
Definition: httpsettings.h:81
void setDefaultSslKey(const QString &x)
Set default SSL key.
Definition: httpsettings.h:122
void setDefaultMaxRequestSize(int x)
Sets default maximum request size.
Definition: httpsettings.h:98
void setDefaultTimeout(int x)
Sets default timeout for opened connection from clients.
Definition: httpsettings.h:70
const QString & sslCaCrt() const
Returns SSL CA certificate.
Definition: httpsettings.h:128
void setUseSSL(bool x)
Set status of SSL connections.
Definition: httpsettings.h:109
void setSslCaCrt(const QString &x)
Set SSL CA certificate.
Definition: httpsettings.h:129
bool threads() const
Returns true if server starts new thread for each connection.
Definition: httpsettings.h:112
const QString & tempDir() const
Returns path to temporary directory.
Definition: httpsettings.h:104
void setPort(int x)
Sets the port number.
Definition: httpsettings.h:65
void setSessionCookieName(const QString &x)
Sets default session cookie name.
Definition: httpsettings.h:93
HttpSettings(QObject *parent)
Constructor reads default QSettings file section [httpd].
void setIndexFile(const QString &x)
Sets name of index file in directory (index.html)
Definition: httpsettings.h:85
void setDefaultTempDir(const QString &x)
Sets default path to temporary directory.
Definition: httpsettings.h:106
int timeout() const
Returns timeout for opened connection from clients.
Definition: httpsettings.h:68
void setDefaultThreads(bool x)
Set default value for starting new thread for each connection.
Definition: httpsettings.h:114
void setEncoding(const QString &x)
Sets the encoding in COntent-type header.
Definition: httpsettings.h:77
void setSection2(const QString &section)
Sets the name for the second section.
Definition: httpsettings.h:171
void setDefaultIndexFile(const QString &x)
Sets default name of index file in directory (index.html)
Definition: httpsettings.h:86
int maxAge() const
Returns the max age for cacheing proxy objects.
Definition: httpsettings.h:72
void setDefaultAddress(const QHostAddress &x)
Sets the defailt bind address.
Definition: httpsettings.h:62
Configuration of the http server instance.
Definition: httpsettings.h:39
const QString & sslKey() const
Returns SSL key.
Definition: httpsettings.h:120
const QHostAddress & address() const
Returns the bind address.
Definition: httpsettings.h:60
void setMaxMultiPartSize(int x)
Sets maximum request size in multipart requests.
Definition: httpsettings.h:101
bool useSSL() const
Returns status of SSL connections.
Definition: httpsettings.h:108
void setDefaultUseSSL(bool x)
Set default status of SSL connections.
Definition: httpsettings.h:110
int sessionExpirationTime() const
Returns maximum expiration time for the session.
Definition: httpsettings.h:88
const QString & indexFile() const
Returns name of index file in directory (index.html)
Definition: httpsettings.h:84
void setDefaultEncoding(const QString &x)
Sets the default encoding in COntent-type header.
Definition: httpsettings.h:78
int maxRequestSize() const
Returns maximum request size.
Definition: httpsettings.h:96
void setMaxRequestSize(int x)
Sets maximum request size.
Definition: httpsettings.h:97
void setTempDir(const QString &x)
Sets path to temporary directory.
Definition: httpsettings.h:105
void setTimeout(int x)
Sets timeout for opened connection from clients.
Definition: httpsettings.h:69
void setDefaultSslCaCrt(const QString &x)
Set default SSL CA certificate.
Definition: httpsettings.h:130
void setSslCrt(const QString &x)
Set SSL certificate.
Definition: httpsettings.h:125
void setDefaultDocroot(const QString &x)
Sets default path to document root.
Definition: httpsettings.h:82
const QString & sslCrt() const
Returns SSL certificate.
Definition: httpsettings.h:124
void setSslKey(const QString &x)
Set SSL key.
Definition: httpsettings.h:121
void setExpirationTime(int x)
Sets maximum expiration time for the session.
Definition: httpsettings.h:89
int port() const
Returns the port number.
Definition: httpsettings.h:64
void setAddress(const QHostAddress &x)
Sets the bind address.
Definition: httpsettings.h:61
void setDefaultExpirationTime(int x)
Sets default maximum expiration time for the session.
Definition: httpsettings.h:90
Namespace of HTTP server.
const QString & docroot() const
Returns path to document root.
Definition: httpsettings.h:80
bool gzip() const
Returns true if server can use gzip compression.
Definition: httpsettings.h:116
void setGzip(bool x)
Enable gzip compression.
Definition: httpsettings.h:117