Renamed qwebsocket.pri to qwebsockets.pri
[contrib/qtwebsockets.git] / src / qwebsocketserver.h
1 /*
2 QWebSockets implements the WebSocket protocol as defined in RFC 6455.
3 Copyright (C) 2013 Kurt Pattyn (pattyn.kurt@gmail.com)
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19
20 #ifndef QWEBSOCKETSERVER_H
21 #define QWEBSOCKETSERVER_H
22
23 #include <QObject>
24 #include <QString>
25 #include <QHostAddress>
26 #include "qwebsocketsglobal.h"
27 #include "qwebsocketprotocol.h"
28
29 QT_BEGIN_NAMESPACE
30
31 class QWebSocketServerPrivate;
32 class QWebSocket;
33
34 class Q_WEBSOCKETS_EXPORT QWebSocketServer : public QObject
35 {
36         Q_OBJECT
37
38 public:
39         explicit QWebSocketServer(const QString &serverName, QObject *parent = 0);
40         virtual ~QWebSocketServer();
41
42         bool listen(const QHostAddress &address = QHostAddress::Any, quint16 port = 0);
43         void close();
44
45         bool isListening() const;
46
47         void setMaxPendingConnections(int numConnections);
48         int maxPendingConnections() const;
49
50         quint16 serverPort() const;
51         QHostAddress serverAddress() const;
52
53         bool setSocketDescriptor(int socketDescriptor);
54         int socketDescriptor() const;
55
56         bool waitForNewConnection(int msec = 0, bool *timedOut = 0);
57         bool hasPendingConnections() const;
58         virtual QWebSocket *nextPendingConnection();
59
60         QAbstractSocket::SocketError serverError() const;
61         QString errorString() const;
62
63         void pauseAccepting();
64         void resumeAccepting();
65
66 #ifndef QT_NO_NETWORKPROXY
67         void setProxy(const QNetworkProxy &networkProxy);
68         QNetworkProxy proxy() const;
69 #endif
70
71         QList<QWebSocketProtocol::Version> supportedVersions() const;
72         QList<QString> supportedProtocols() const;
73         QList<QString> supportedExtensions() const;
74
75 protected:
76         virtual bool isOriginAllowed(const QString &origin) const;
77
78 Q_SIGNALS:
79         void acceptError(QAbstractSocket::SocketError socketError);
80         void newConnection();
81
82 private:
83         Q_DISABLE_COPY(QWebSocketServer)
84         QWebSocketServerPrivate * const d_ptr;
85         friend class QWebSocketServerPrivate;
86 };
87
88 QT_END_NAMESPACE
89
90 #endif // QWEBSOCKETSERVER_H