Remoto - VFS: VFS_websocket_server.h Source File
Remoto - VFS
VFS_websocket_server.h
Go to the documentation of this file.
1 #ifndef VFS_WEBSOCKET_SERVER_H
2 #define VFS_WEBSOCKET_SERVER_H
3 
4 #include <QWebSocketServer>
5 //#include <QTimer>
6 
7 #include "VFS_websocket_client.h"
8 
10 {
11  Q_OBJECT
12 
13  friend class VFS_websocket_client;
14 
15  public:
16  explicit VFS_websocket_server(quint16 port, QString authPaths, QString sessions, QHostAddress addr=QHostAddress::Any, QWebSocketServer::SslMode ssl=QWebSocketServer::NonSecureMode, QString sslCertPath="", QString sslKeyPath="");
17  virtual ~VFS_websocket_server();
18 
19  virtual bool isContainer();
20 
21  virtual bool authenticate(VFS_websocket_client *client, QJsonObject credentials);
22  virtual void authorize(VFS_websocket_client *client, QJsonObject authdata);
23 
24  protected:
25  QHostAddress _listenAddress;
26  quint16 _port;
27  QWebSocketServer::SslMode _ssl;
28  QString _sslCertPath;
29  QString _sslKeyPath;
30  QWebSocketServer _socket;
31 
32  QStringList _authPaths;
33  QString _sessionsPath;
34 
35  virtual VFS_websocket_client *createWebsocketClient(QWebSocket *s);
36 
37  private:
38  //QTimer _listenTimer; //!< A timer used to delay the listen... we want to make sure the VFS is fully built before connections are attempted
39 
40  public slots:
41  virtual bool listen();
42  virtual void clientBinaryMessage(QByteArray message);
43  virtual void clientTextMessage(QString message);
44  virtual void clientError(QAbstractSocket::SocketError error);
45  virtual void serverError(QWebSocketProtocol::CloseCode closeCode);
46 
47  protected slots:
48  virtual void newConnection();
49  virtual void closeConnection();
50  virtual void sslErrors(const QList<QSslError> &errors);
51 };
52 
53 #endif // VFS_WEBSOCKET_SERVER_H
VFS_node is the base class from which all other VFS_node classes derive.
Definition: VFS_node.h:143
A VFS_node that manages a QWebSocket connection.
void error(QAbstractSocket::SocketError)
There has been a socket error.
A VFS_websocket server will listen for incoming websocket connections, optionally using ssl.
virtual ~VFS_websocket_server()
VFS_websocket_server destructor.
virtual bool authenticate(VFS_websocket_client *client, QJsonObject credentials)
Authenticate a client based on received credentials.
QHostAddress _listenAddress
Address to listen on, or 0.0.0.0 for all.
QStringList _authPaths
The list of auth paths to query when a user request authentication.
quint16 _port
Port to listen on.
virtual void sslErrors(const QList< QSslError > &errors)
One or more ssl errors have occurred.
QString _sslCertPath
ssl cert file path
QString _sessionsPath
The path to the sessionManager node.
QWebSocketServer _socket
The QWebSocket server object that will be listening.
virtual void clientTextMessage(QString message)
A client has received a text websocket message.
virtual void serverError(QWebSocketProtocol::CloseCode closeCode)
A server socket error has occurred.
virtual void clientBinaryMessage(QByteArray message)
The client has received a binary websocket message.
virtual void newConnection()
A new connection has been requested, and is pending.
virtual void clientError(QAbstractSocket::SocketError error)
A socket error has occurred.
VFS_websocket_server(quint16 port, QString authPaths, QString sessions, QHostAddress addr=QHostAddress::Any, QWebSocketServer::SslMode ssl=QWebSocketServer::NonSecureMode, QString sslCertPath="", QString sslKeyPath="")
VFS_websocket_server constructor.
QString _sslKeyPath
ssl key file path
virtual void authorize(VFS_websocket_client *client, QJsonObject authdata)
Authorize a client and create a session based on type and username.
virtual bool isContainer()
A VFS_websocket_server is always a container; it's children will be the connected clients.
QWebSocketServer::SslMode _ssl
Use ssl?
virtual bool listen()
Start listening on the _socket for incoming connections.
virtual void closeConnection()
Close a child client connection, and remove() it from this node's child list.
virtual VFS_websocket_client * createWebsocketClient(QWebSocket *s)
Create a VFS_websocket_client to host a new connection.