Nuria Framework - Network
Network module of the NuriaProject Framework
 All Classes Functions Typedefs Enumerations Enumerator
httpnode.hpp
1 /* Copyright (c) 2014, The Nuria Project
2  * This software is provided 'as-is', without any express or implied
3  * warranty. In no event will the authors be held liable for any damages
4  * arising from the use of this software.
5  * Permission is granted to anyone to use this software for any purpose,
6  * including commercial applications, and to alter it and redistribute it
7  * freely, subject to the following restrictions:
8  * 1. The origin of this software must not be misrepresented; you must not
9  * claim that you wrote the original software. If you use this software
10  * in a product, an acknowledgment in the product documentation would be
11  * appreciated but is not required.
12  * 2. Altered source versions must be plainly marked as such, and must not be
13  * misrepresented as being the original software.
14  * 3. This notice may not be removed or altered from any source
15  * distribution.
16  */
17 
18 #ifndef NURIA_HTTPNODE_HPP
19 #define NURIA_HTTPNODE_HPP
20 
21 #include "network_global.hpp"
22 #include "httpclient.hpp"
23 #include "callback.hpp"
24 #include <QSharedData>
25 #include <QObject>
26 #include <QDir>
27 
28 namespace Nuria {
29 
30 class HttpNodePrivate;
31 class SlotInfoPrivate;
32 class HttpServer;
33 class HttpNode;
34 
39 class NURIA_NETWORK_EXPORT SlotInfo {
40 public:
41 
43  SlotInfo (const Callback &callback = Callback ());
44 
46  SlotInfo (const SlotInfo &other);
47 
49  SlotInfo &operator= (const SlotInfo &other);
50 
52  ~SlotInfo ();
53 
55  bool isValid () const;
56 
58  Callback callback () const;
59 
70  bool streamPostBody () const;
71 
73  void setStreamPostBody (bool value);
74 
79  HttpClient::HttpVerbs allowedVerbs () const;
80 
82  void setAllowedVerbs (HttpClient::HttpVerbs verbs);
83 
88  qint64 maxBodyLength () const;
89 
91  void setMaxBodyLength (qint64 length);
92 
98  bool forceEncrypted () const;
99 
101  void setForceEncrypted (bool force);
102 
103 private:
104  friend class HttpNode;
105 
106  //
107  QSharedDataPointer< SlotInfoPrivate > d;
108 
109 };
110 
112 typedef QList< HttpNode * > HttpNodeList;
113 
140 class NURIA_NETWORK_EXPORT HttpNode : public QObject {
141  Q_OBJECT
142 public:
143 
149 
151  NoStaticResources = 0,
152 
158  UseStaticResources = 1,
159 
164  UseNestedStaticResources = 2
165 
166  };
167 
173  HttpNode (const QString &resourceName, HttpNode *parent = 0);
174 
178  HttpNode (QObject *parent = 0);
179 
181  ~HttpNode ();
182 
186  bool isChild () const;
187 
192  HttpNode *parentNode () const;
193 
212  SlotInfo connectSlot (const QString &name, const Callback &callback);
213 
232  SlotInfo connectSlot (const QString &name, QObject *receiver, const char *slot);
233 
238  bool disconnectSlot (const QString &name);
239 
247  bool addNode (HttpNode *node);
248 
252  const QString &resourceName () const;
253 
257  const QDir &staticResourceDir () const;
258 
262  StaticResourcesMode staticResourceMode () const;
263 
269  bool setResourceName (const QString &name);
270 
280  void setStaticResourceDir (QDir path);
281 
286  void setStaticResourceMode (StaticResourcesMode mode);
287 
291  bool hasNode (const QString &name);
292 
296  bool hasSlot (const QString &name);
297 
302  HttpNode *findNode (const QString &name) const;
303 
304 protected:
305 
340  virtual bool invokePath (const QString &path, const QStringList &parts,
341  int index, HttpClient *client);
342 
368  virtual bool allowAccessToClient (const QString &path, const QStringList &parts,
369  int index, HttpClient *client);
370 
379  virtual bool callSlotByName (const QString &name, HttpClient *client);
380 
389  bool sendStaticResource (const QString &name, HttpClient *client);
390 
392  bool sendStaticResource (const QStringList &path, int indexInPath,
393  HttpClient *client);
394 
395 private:
396  friend class HttpServer;
397  friend class HttpClient;
398 
403  static bool callSlot (const SlotInfo &info, HttpClient *client);
404 
405  //
406  HttpNodePrivate *d_ptr;
407 
408 };
409 }
410 
411 #endif // NURIA_HTTPNODE_HPP
The HttpServer class provides a simple HTTP server. This server is directed at providing interactive ...
Definition: httpserver.hpp:40
The HttpClient class represents a connection to a client.
Definition: httpclient.hpp:92
Definition: httpnode.hpp:39
The HttpNode class represents a virtual directory (or a virtual file) HttpServer uses these nodes to ...
Definition: httpnode.hpp:140
StaticResourcesMode
Definition: httpnode.hpp:148