PACK Qt Binding  $VERSION$
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
server.h
Go to the documentation of this file.
1 // Copyright (C) 2010-2011 by Konrad Rosenbaum <konrad@silmor.de>
2 // protected under the GNU LGPL version 3 or at your option any newer.
3 // See COPYING.LGPL file that comes with this distribution.
4 //
5 
6 #ifndef WOB_SERVER_H
7 #define WOB_SERVER_H
8 
9 #include <QObject>
10 #include <QHostAddress>
11 #include <QMap>
12 #include <QMetaType>
13 
14 class QTcpServer;
15 class QLocalServer;
16 class WInterface;
17 
18 #ifndef WOLF_BASE_EXPORT
19 #define WOLF_BASE_EXPORT Q_DECL_IMPORT
20 #endif
21 
24 {
25  public:
30 
32  WServerRequest& operator=(const WServerRequest&);
33 
35  bool hasHeader(const QString&)const;
37  bool hasCgiHeader(const QString&)const;
39  QByteArray header(const QString&)const;
41  QByteArray cgiHeader(const QString&)const;
43  QByteArray bodyData()const;
44 
46  bool isValid()const;
47 
49  QByteArray dump()const;
50 
52  QString pathInfo()const;
54  QString hostInfo()const;
55 
56  protected:
58  WServerRequest(const QByteArray&);
59  void setBody(const QByteArray&);
60  friend class WServer;
61  friend class WServerReceiver;
62 
63  private:
64  QMap<QByteArray,QByteArray>mhead;
65  QByteArray mbody;
66 };
68 
71 {
72  public:
74  WServerReply();
76  WServerReply(const WServerReply&)=default;
78  WServerReply& operator=(const WServerReply&)=default;
79 
81  bool setStatus(short code,QString str);
83  bool setHeader(const QString&,const QString&);
85  void setBody(const QString&);
87  void setBody(const QByteArray&);
88 
89  protected:
90  friend class WServer;
92  QByteArray toWireFormat()const;
93  private:
94  short mStatCode;
95  QByteArray mStatStr,mBody;
96  QMap<QString,QPair<QString,QString> >mHead;
97 };
98 
103 class WOLF_BASE_EXPORT WServer:public QObject
104 {
105  Q_OBJECT
106  public:
112  WServer(const QString&path,bool removeIfExist=true,QObject*parent=0);
118  WServer(const QHostAddress&addr,unsigned short port,QObject*parent=0);
120  virtual ~WServer()=default;
121 
123  bool isActive()const{return tcpserv!=0 || locserv!=0;}
124 
127  int receiveTimeout()const{return mrecvtimeout;}
128 
130  quint16 tcpPort()const;
131 
132  public slots:
137  void registerInterface(const QString&path,WInterface*ifc);
142  void registerStatic(const QString&path,const QString&content);
144  void unregisterPath(const QString&);
146  void register404(const QString&);
148  void register400(const QString&);
150  void setReceiveTimeout(int);
152  void restrictSourceHosts(const QPair<QHostAddress,int>&);
154  void enableDebugUrl(bool enable=true);
155 
156  private slots:
158  void newConnection();
160  void handleConnection(QIODevice*);
162  void handleRequest(WServerRequest,QIODevice*);
163  private:
164  void handleRequestHelper(WServerRequest,QIODevice*);
165  QTcpServer*tcpserv;
166  QLocalServer*locserv;
167  QMap<QString,WInterface*>iface;
168  QMap<QString,QString>statcontent;
169  QString err404,err400;
170  int mrecvtimeout;
171  QPair<QHostAddress,int>sourcehost;
172  bool mdebugenabled;
173 };
174 
175 #endif
#define WOLF_BASE_EXPORT
Definition: server.h:19
Definition: server_p.h:12
Definition: server.h:103
int receiveTimeout() const
Definition: server.h:127
reply object for the server side: contains the data sent back to the client
Definition: server.h:70
Encapsulates the request as it comes in via (S)CGI.
Definition: server.h:23
bool isActive() const
returns true if this is a working server (i.e. the constructor did not have errors) ...
Definition: server.h:123
base class of all interfaces
Definition: interface.h:28
Q_DECLARE_METATYPE(WServerRequest)