Remoto - VFS
|
A VFS_websocket server will listen for incoming websocket connections, optionally using ssl. More...
#include <VFS_websocket_server.h>
Public Slots | |
virtual void | clientBinaryMessage (QByteArray message) |
The client has received a binary websocket message. More... | |
virtual void | clientError (QAbstractSocket::SocketError error) |
A socket error has occurred. More... | |
virtual void | clientTextMessage (QString message) |
A client has received a text websocket message. More... | |
virtual bool | listen () |
Start listening on the _socket for incoming connections. More... | |
virtual void | serverError (QWebSocketProtocol::CloseCode closeCode) |
A server socket error has occurred. More... | |
![]() | |
virtual void | applyDiff (VFS_request *r) |
Apply a diff received via subscription. More... | |
virtual void | executeRequest (VFS_request *t) |
Based on the VFS_request::requestType, execute the function associated with an operation. More... | |
void | notifySubscribers (VFS_node *origin, VFS_request *t) |
Propagate a diff to subscribers. More... | |
virtual void | receiveResponse (VFS_request *t) |
Once a VFS_request has been completed, a response will be issued back to its _origin. More... | |
void | remove (bool andDelete) |
Remove a child node. More... | |
virtual void | remove (VFS_node *node=nullptr, QString *name=nullptr, QString user="server") |
Remove a child node from this node. More... | |
virtual void | subtreeRequest (VFS_request *t) |
find() the target of a VFS_request, and execute the request More... | |
virtual void | unsubscribeAll (VFS_node *n) |
Remove all references to a subscriber from this node. More... | |
Public Member Functions | |
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. More... | |
virtual | ~VFS_websocket_server () |
VFS_websocket_server destructor. More... | |
virtual bool | authenticate (VFS_websocket_client *client, QJsonObject credentials) |
Authenticate a client based on received credentials. More... | |
virtual void | authorize (VFS_websocket_client *client, QJsonObject authdata) |
Authorize a client and create a session based on type and username. More... | |
virtual bool | isContainer () |
A VFS_websocket_server is always a container; it's children will be the connected clients. More... | |
![]() | |
Q_INVOKABLE | VFS_node () |
The VFS_node constructor will add its instance to the VFS_node::__allNodes global node registry, observing thread safety rules. More... | |
virtual | ~VFS_node () |
VFS_node destructor. More... | |
virtual VFS_node * | append (QString name, VFS_node *node, bool containerCheck=true, QString user="server") |
Append a VFS_node as a child of this node. More... | |
QString | className () |
Return the class name of a node. More... | |
virtual VFS_request * | createRequest (VFS_request::requestType type, QString path, QString user="unknown", QJsonDocument data=QJsonDocument(), QJsonObject metadata=QJsonObject(), bool dontDelete=false) |
Create a new VFS_request with this object as _origin. More... | |
VFS_node * | find (QString path) |
Find a node by string path. More... | |
virtual VFS_node * | find (VFS_request *r) |
Find a node using a VFS_request. More... | |
VFS_node * | findChildWithName (QString name) |
Check if a child with a given name exists. More... | |
virtual VFS_node * | mount () |
Mount this node. More... | |
virtual QString | reportDetails () |
Additional details for a generated report. More... | |
QString | uniqueChildName (QString name) |
Generate a unique child name. More... | |
virtual VFS_node * | unmount () |
Unmount this node. More... | |
virtual bool | validChildName (QString name) |
Check if a node name is valid. More... | |
Protected Slots | |
virtual void | closeConnection () |
Close a child client connection, and remove() it from this node's child list. More... | |
virtual void | newConnection () |
A new connection has been requested, and is pending. More... | |
virtual void | sslErrors (const QList< QSslError > &errors) |
One or more ssl errors have occurred. More... | |
Protected Member Functions | |
virtual VFS_websocket_client * | createWebsocketClient (QWebSocket *s) |
Create a VFS_websocket_client to host a new connection. More... | |
![]() | |
virtual void | aclDefaults (VFS_request *r) |
Return default values and features associated wth this node. More... | |
void | addACLDefault (QJsonObject &acl, bool value, QString description="") |
Add a default value to the acl object. More... | |
void | addACLFeature (QJsonObject &acl, QString feature, bool value, QString description="") |
Add a feature to the acl object. More... | |
void | addACLFeatureGroup (QJsonObject &acl, QString feature, QString group, bool value) |
Add a feature group to the acl object. More... | |
void | addACLFeatureUser (QJsonObject &acl, QString feature, QString user, bool value) |
Add a feature user to the acl object. More... | |
void | addACLGroup (QJsonObject &acl, QString group, bool value) |
Add a group to the acl object. More... | |
void | addACLUser (QJsonObject &acl, QString user, bool value) |
Add a user to the acl object. More... | |
virtual QByteArray | icon () |
Fetch the icon for a node. More... | |
virtual void | issueRequest (VFS_node *target, VFS_request *t) |
Issue a VFS_request to its target. More... | |
virtual void | issueRequest (VFS_request *t) |
A convenience function. More... | |
virtual void | issueResponse (VFS_request *t) |
Once a request has been completed, issue a response. More... | |
virtual void | ls (VFS_request *r) |
List the contents of this node. More... | |
virtual void | metadata (VFS_request *r) |
Fetch the metadata of this node. More... | |
virtual void | read (VFS_request *r) |
Return the data contents of this node, or if it's a container call ls() More... | |
virtual void | releaseLock (VFS_request *r) |
Release a lock on this node. More... | |
virtual void | report (VFS_request *r) |
Report debugging information about the current state of this node. More... | |
virtual void | requestLock (VFS_request *r) |
Request a lock on this node. More... | |
virtual void | rm (VFS_request *r) |
Remove a child entry from a node, or the node itself. More... | |
virtual void | submit (VFS_request *r) |
Submit a diff to a node. More... | |
virtual void | subscribe (VFS_request *r) |
Add an entry to this node's _subscription list. More... | |
virtual void | unsubscribe (VFS_request *r) |
Remove an entry from this node's _subscription list. More... | |
virtual void | unsubscribePath (QString path) |
Unsubscribe all references to a subpath. More... | |
virtual void | write (VFS_request *r) |
Write data to this node. More... | |
Protected Attributes | |
QStringList | _authPaths |
The list of auth paths to query when a user request authentication. More... | |
QHostAddress | _listenAddress |
Address to listen on, or 0.0.0.0 for all. More... | |
quint16 | _port |
Port to listen on. More... | |
QString | _sessionsPath |
The path to the sessionManager node. More... | |
QWebSocketServer | _socket |
The QWebSocket server object that will be listening. More... | |
QWebSocketServer::SslMode | _ssl |
Use ssl? More... | |
QString | _sslCertPath |
ssl cert file path More... | |
QString | _sslKeyPath |
ssl key file path More... | |
![]() | |
VFS_children | _children |
This node's children. More... | |
QMutex | _lock |
A recursive mutex that is local to this node. More... | |
VFS_subscriptionType | _subscribers |
This node's subscribers. These subscribers will receive diff notifications. More... | |
Friends | |
class | VFS_websocket_client |
Additional Inherited Members | |
![]() | |
void | diff (VFS_node *origin, VFS_request *t) |
Emit a diff, which will trigger notifySubscribers() for a mounted node. More... | |
void | finished (bool andDelete=false) |
Emitted if a thread fails to create its node, or a node is rm()'d, or any other reason a node has completed its lifecycle. It is deleted if andDelete==true . More... | |
void | mounted () |
Emitted when a node is mount()ed. More... | |
void | unmounted (VFS_node *self) |
Emitted when a node is unmount()ed. More... | |
![]() | |
static bool | __isNode (VFS_node *) |
Check to see if a node is in the global registry. More... | |
static QString | code (QString nodename, QString libname, QString &error) |
Fetch code or any other resource from a node. More... | |
A VFS_websocket server will listen for incoming websocket connections, optionally using ssl.
The base class implementation will do nothing useful. It must be subclassed, as well as VFS_websocket_client.
Definition at line 9 of file VFS_websocket_server.h.
|
explicit |
VFS_websocket_server constructor.
port | Port to listen on. |
authPaths | List of sequential VFS auth paths to authenticate a user. |
sessions | The path to the sessionManager, which will be a "sessions" node |
addr | Address to listen on, or 0.0.0.0 for any. |
ssl | Use ssl? |
sslCertPath | ssl cert file path |
sslKeyPath | ssl key file path |
This server will listen() when the root VFS emits VFS::initialized().
Definition at line 33 of file VFS_websocket_server.cpp.
|
virtual |
VFS_websocket_server destructor.
Closes the socket during destruction.
Definition at line 63 of file VFS_websocket_server.cpp.
|
virtual |
Authenticate a client based on received credentials.
client | The client requesting authentication. |
credentials | The authentication credentials, probably from the _metadata field of a VFS_request. |
This method uses an authindex to sequentially send a VFS_request subclass to query an auth path. The success or failure of the request will need to be captured in the subclassed VFS_websocket_client::receiveResponse() function. If it's a failure, a second call to authenticate() with the same _metadata will query the next auth path. If the auth path list has been exhausted, this function will return false, and the user connection should be closed.
This virtual method could be subclassed if needed to change the default functionality.
Definition at line 230 of file VFS_websocket_server.cpp.
|
virtual |
Authorize a client and create a session based on type and username.
client | The client requesting authorization. |
authdata | The data returned from a VFS_auth subclass node. |
This method will issue a request to a VFS_sessionHandler to create a new VFS_session for a connected user based on the type of the session.
Definition at line 298 of file VFS_websocket_server.cpp.
|
virtualslot |
The client has received a binary websocket message.
message | The message |
This is an interception point for a VFS_websocket_server. If a server wishes to parse or filter or sanitize incoming socket data, a subclass of this function could do this.
Generally, a VFS_websocket_client should be doing the work on the messages it receives, but in some security contexts, a server may want to supervise communication.
The base implementation does not pass data to the client, and the message dies here.
This must be called as the result of a slot, because sender() is dynamically cast to the VFS_websocket_client.
Definition at line 356 of file VFS_websocket_server.cpp.
|
virtualslot |
A socket error has occurred.
Log it as an error/warning, but do nothing.
error | The error |
Definition at line 410 of file VFS_websocket_server.cpp.
|
virtualslot |
A client has received a text websocket message.
message | The message |
This is an interception point for a VFS_websocket_server. If a server wishes to parse or filter or sanitize incoming socket data, a subclass of this function could do this.
Generally, a VFS_websocket_client should be doing the work on the messages it receives, but in some security contexts, a server may want to supervise communication.
The base implementation does not pass data to the client, and the message dies here.
Definition at line 388 of file VFS_websocket_server.cpp.
|
protectedvirtualslot |
Close a child client connection, and remove() it from this node's child list.
This will also call deleteLater() on the VFS_websocket_client. This is not meant to be called directly, but instead connected as a slot to any other mechanism which may cause a close.
Definition at line 316 of file VFS_websocket_server.cpp.
|
protectedvirtual |
Create a VFS_websocket_client to host a new connection.
socket | The socket returned by _socket.nextPendingConnection(). |
This method is meant to be subclassed to return the type (subclass) of VFS_websocket_client needed by a subclassed server.
Reimplemented in VFS_remotoserver.
Definition at line 207 of file VFS_websocket_server.cpp.
|
virtual |
A VFS_websocket_server is always a container; it's children will be the connected clients.
Reimplemented from VFS_node.
Definition at line 73 of file VFS_websocket_server.cpp.
|
virtualslot |
Start listening on the _socket for incoming connections.
If the socket is already listening, this will return false.
The socket will be set to allow a maximum of 100 pending connections. After that it will emit an error, and new clients will not be allowed to connect until some of the pending connections are serviced.
If ssl is requested, the ssl cert and key files will be validated. Any problem here will prevent the socket from opening.
A message is either logged or warned, depending on listen() status.
Definition at line 92 of file VFS_websocket_server.cpp.
|
protectedvirtualslot |
A new connection has been requested, and is pending.
Accept the new connection and create a VFS_websocket_client to host it. Connect the necessary signals and slots to manage the lifespan of the connection.
The child will be append()ed once authenticated and authorized by VFS_websocket_client::authorized().
Definition at line 172 of file VFS_websocket_server.cpp.
|
virtualslot |
A server socket error has occurred.
Log it as an error, but do nothing.
closeCode | The websocket close state received by the underlying driver |
Definition at line 425 of file VFS_websocket_server.cpp.
|
protectedvirtualslot |
One or more ssl errors have occurred.
Log them as errors, and do nothing.
errors | The list of QSslErrors to log |
Definition at line 435 of file VFS_websocket_server.cpp.
|
friend |
Definition at line 13 of file VFS_websocket_server.h.
|
protected |
The list of auth paths to query when a user request authentication.
Definition at line 32 of file VFS_websocket_server.h.
|
protected |
Address to listen on, or 0.0.0.0 for all.
Definition at line 25 of file VFS_websocket_server.h.
|
protected |
Port to listen on.
Definition at line 26 of file VFS_websocket_server.h.
|
protected |
The path to the sessionManager node.
Definition at line 33 of file VFS_websocket_server.h.
|
protected |
The QWebSocket server object that will be listening.
Definition at line 30 of file VFS_websocket_server.h.
|
protected |
Use ssl?
Definition at line 27 of file VFS_websocket_server.h.
|
protected |
ssl cert file path
Definition at line 28 of file VFS_websocket_server.h.
|
protected |
ssl key file path
Definition at line 29 of file VFS_websocket_server.h.