Remoto - VFS
|
A subclass of VFS_websocket_client that implements the remoto websocket protocol and handles requests and responses to a connected client. More...
#include <VFS_remotoserver.h>
Public Slots | |
virtual void | applyDiff (VFS_request *t) |
Apply a diff to this node. More... | |
virtual void | receiveResponse (VFS_request *t) |
Receive a response from an issueRequest(). More... | |
virtual void | removeSourcePathMap (VFS_node *n) |
Remove a VFS_remotoserver_client::_sourcePathMap entry for a VFS_node. More... | |
Public Slots inherited from VFS_node | |
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_remotoserver_client (QWebSocket *socket, VFS_websocket_server *server) | |
virtual | ~VFS_remotoserver_client () |
virtual VFS_request * | createRequest (VFS_request::requestType type, QString path, QString user="unknown", QJsonDocument data=QJsonDocument(), QJsonObject metadata=QJsonObject(), bool dontDelete=false) |
Create a VFS_remotoserver_request to service a request received from a client. More... | |
virtual VFS_node * | find (VFS_request *r) |
VFS_remotoserver_client cannot contain children, but instead points to a websocket client, if connected. More... | |
QJsonObject | parameters () const |
Return the parameters provided to this client when authentication was granted. More... | |
virtual QJsonDocument | receive (QByteArray data) |
Receive a message from a connected websocket client. More... | |
virtual QString | reportDetails () |
Report the _user and _type of a connected client. More... | |
bool | writeError (QString message, bool binary=false) |
Write an error state to a connected client. More... | |
bool | writeRequestError (QString command, QString path, QString reason, bool binary=false) |
Write a requesterror command to a connected client. More... | |
bool | writeRequestSuccess (QString command, QString path, QJsonDocument data=QJsonDocument(), QJsonObject metadata=QJsonObject(), bool binary=false) |
VFS_remotoserver_client::writeRequestSuccess. More... | |
bool | writeUICode (QString libname, QString code, QString error, bool binary=false) |
Write a VFS_request::code response to a connected client. More... | |
bool | writeUICodeDirectory (QJsonObject o, QString error, bool binary=false) |
Write a VFS_request::codeDirectory response to a connected client. More... | |
bool | writeUIDiff (QString path, QJsonDocument diff, QString user, bool binary=false) |
Send a diff command to a client when something interesting happens on a subscribed VFS_node. More... | |
bool | writeUILS (QString id, QString path, QJsonDocument data, QJsonObject metadata, bool binary=false) |
Write a VFS_request::ls response to a connected client. More... | |
bool | writeUIMetadata (QString path, QJsonObject metadata, bool binary=false) |
Write a VFS_request::metadata response to a connected client. More... | |
bool | writeUIRead (QString path, QJsonDocument data, QJsonObject metadata, bool binary=false) |
Send the results of a VFS_request::read command to a client. More... | |
bool | writeUIReleaseLock (QString path, QJsonDocument data, bool binary=false) |
Write the results of a VFS_request::releaselock to a connected client. More... | |
bool | writeUIRequestLock (QString path, QJsonDocument data, bool binary=false) |
Write the results of a VFS_request::requestlock to a connected client. More... | |
bool | writeUIRM (QString path, bool binary=false) |
Send an RM command to a connected client. More... | |
bool | writeUISubscribe (QString path, QJsonDocument data, QJsonObject metadata, bool binary=false) |
Write a VFS_request::subscribe response to a connected client. More... | |
bool | writeUIWrite (QString path, QJsonDocument data, QJsonObject metadata, bool binary=false) |
Write data to a connected client. More... | |
Public Member Functions inherited from VFS_websocket_client | |
VFS_websocket_client (QString wsurl, quint16 interval=3000) | |
VFS_websocket_client (QWebSocket *socket, VFS_websocket_server *server) | |
virtual | ~VFS_websocket_client () |
VFS_websocket_client destructor -. More... | |
virtual bool | isConnected () |
If the client will attempt to reconnect, return true. More... | |
virtual bool | isConnecting () |
If the client will attempt to reconnect, return true. More... | |
virtual bool | isContainer () |
A VFS_websocket_client cannot contain children. More... | |
virtual void | submit (VFS_request *r) |
Submit to the socket. More... | |
virtual bool | writeBinary (QByteArray data) |
Write binary data over the websocket. More... | |
virtual bool | writeText (QString data) |
Write text data over the websocket. More... | |
Public Member Functions inherited from VFS_node | |
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... | |
VFS_node * | find (QString path) |
Find a node by string path. More... | |
VFS_node * | findChildWithName (QString name) |
Check if a child with a given name exists. More... | |
virtual VFS_node * | mount () |
Mount this node. 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 Member Functions | |
void | addSourcePathMap (VFS_node *source, QString path) |
Add a VFS_remotoserver_client::_sourcePathMap entry for a path from a client's perspective to a VFS_node. More... | |
virtual void | authenticate (QJsonDocument d) |
Authenticate a user using VFS_websocket_server::authenticate(). More... | |
virtual void | rm (VFS_request *r) |
Send an RM command to a user. More... | |
virtual void | write (VFS_request *r) |
Write form or interface information back to a user. More... | |
Protected Member Functions inherited from VFS_websocket_client | |
virtual void | authorized () |
Notify the node that it has received authorization from some auth method. More... | |
virtual void | init () |
Initialize needed signal/slot connections. More... | |
Protected Member Functions inherited from VFS_node | |
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 | 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... | |
Protected Attributes | |
QJsonObject | _parameters |
Parameters provided during the auth process. More... | |
VFS_session * | _session |
The session associated with this client connection. More... | |
QMap< VFS_node *, QString > | _sourcePathMap |
A map relating path requests from a client to path requests on the VFS. More... | |
QString | _type |
The remote client type, which may be "browser" or "unity" or any other id string. More... | |
QString | _user |
The authenticated client's username. More... | |
Protected Attributes inherited from VFS_websocket_client | |
QHostAddress | _address |
The network address of the connected client. More... | |
bool | _authenticated |
if auth has taken place and succeeded More... | |
bool | _authorized |
if this connection has a session More... | |
int | _connectID |
For client connections, the reconnect timerID. More... | |
quint16 | _interval |
The reconnect interval if disconnected. More... | |
bool | _isClient |
A client connection may not be created by a listening server, thus the second constructor. More... | |
int | _pingID |
Connections can become stale; This is the ID of the ping timer. More... | |
VFS_websocket_server * | _server |
owning server More... | |
QWebSocket * | _socket |
client socket More... | |
QString | _wsurl |
For client connections, the WebSocket address to connect to. More... | |
Protected Attributes inherited from VFS_node | |
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_remotoserver_request |
Additional Inherited Members | |
Signals inherited from VFS_websocket_client | |
void | connected () |
Connection has been made. More... | |
void | disconnected () |
Connection has been lost. More... | |
void | error (QAbstractSocket::SocketError) |
There has been a socket error. More... | |
void | readyBinaryMessage (QByteArray message) |
A binary message has been received. More... | |
void | readyTextMessage (QString message) |
A text message has been received. More... | |
Signals inherited from VFS_node | |
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 Public Member Functions inherited from VFS_node | |
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... | |
Protected Slots inherited from VFS_websocket_client | |
virtual void | close () |
Close the socket if it is connected. More... | |
virtual void | socket_connected () |
Slot called when the client is connected. More... | |
virtual void | socket_disconnected () |
Slot called when the client is disconnected. More... | |
virtual void | socket_receive_binary (QByteArray message) |
VFS_websocket_client::socket_receive_binary. More... | |
virtual void | socket_receive_text (QString message) |
The socket has received a message in text mode. More... | |
virtual void | startPing () |
Start the ping timer. More... | |
virtual void | timerEvent (QTimerEvent *event) |
Send the ping command. More... | |
A subclass of VFS_websocket_client that implements the remoto websocket protocol and handles requests and responses to a connected client.
This node will do the heavy lifting work of parsing incoming messages, sending requests to other VFS_node paths on the VFS, and routing responses back to the end user. All websocket clients must be authenticated, which is automatically done with VFS_websocket_server::authenticate().
The connected client will usually be a web browser, but could also be a unity game engine, for instance, or another VFS.
Definition at line 33 of file VFS_remotoserver.h.
|
explicit |
socket | A newly created QWebSocket provided by the server |
server | The server instance that created the socket |
Definition at line 150 of file VFS_remotoserver.cpp.
|
virtual |
Definition at line 157 of file VFS_remotoserver.cpp.
|
protected |
Add a VFS_remotoserver_client::_sourcePathMap entry for a path from a client's perspective to a VFS_node.
source | The node that responded to a VFS_request::subscribe request |
path | The path to map |
Because a VFS_node doesn't know what its path is, the client must take note of the path used to subscribe to a node, and use that mapping to formulate a response to a request.
This map is maintained by connecting to the unmounted() signal of the VFS_node.
Definition at line 950 of file VFS_remotoserver.cpp.
|
virtualslot |
Apply a diff to this node.
t | The VFS_request object |
A diff occurs when a client subscribes to a VFS_node and a diff is emitted from it. Most frequently, a diff originates from a submit() operation, but could also come from a timer event or potentially any other thing a node wants to do.
The path
will always be cleaned using rutils::cleanPath() first.
If a mapping in _sourcePathMap does not exist, the applyDiff() will fail. Otherwise it will succeed.
Definition at line 196 of file VFS_remotoserver.cpp.
|
protectedvirtual |
Authenticate a user using VFS_websocket_server::authenticate().
d | The remoto command received. |
This method is called when VFS_websocket_client::_authenticated==false
. If the "command" field of the command is not "identify", the client will be dropped after sending a failed authorization response.
Definition at line 718 of file VFS_remotoserver.cpp.
|
virtual |
Create a VFS_remotoserver_request to service a request received from a client.
type | The request type |
path | The request path |
user | The user who is performing the request |
data | The request data |
metadata | The request metadata |
dontDelete | An unused parameter which is present only for polymorphism |
this
set as the _origin. Reimplemented from VFS_node.
Definition at line 173 of file VFS_remotoserver.cpp.
|
virtual |
VFS_remotoserver_client cannot contain children, but instead points to a websocket client, if connected.
r | The VFS_request object |
this
is always returned. This only comes into play when a client is being written to... let the path fragment flow to the client.
Reimplemented from VFS_node.
Definition at line 756 of file VFS_remotoserver.cpp.
QJsonObject VFS_remotoserver_client::parameters | ( | ) | const |
Return the parameters provided to this client when authentication was granted.
Definition at line 1478 of file VFS_remotoserver.cpp.
|
virtual |
Receive a message from a connected websocket client.
data | The message |
This is the meat of the protocol handler. First, the incoming message is parsed as JSON. If a non-parseable command is received, the socket is closed and the client is dropped. An error is logged.
Commands must follow the form:
The first command received from a client must be an "identify" command, or the connection will be dropped.
The following incoming commands are recognized:
Command | Action | Notify Exception | Object | Value |
---|---|---|---|---|
identify | call VFS_remotoserver_client::authenticate() | No | No | credentials |
ping | keep the connection alive. Send: { "command":"pong" }
| No | No | |
create | send a VFS_request::create request on a path. | No | Yes | |
rm | send a VFS_request::rm request on a path | No | Yes | boolean true |
subscribe | send a VFS_request::subscribe on a path | No | Yes | subscription count |
read | send a VFS_request::read on a path | No | Yes | |
submit | send a VFS_request::submit on a path | Yes | Yes | data |
write | send a VFS_request::write on a path | Yes | Yes | data |
unsubscribe | send a VFS_request::unsubscribe on a path | No | Yes | boolean true |
ls | send a VFS_request::ls on a path | No | Yes | { "path":"some/path", "metadata":{} }
|
metadata | send a VFS_request::metadata on a path | No | Yes | |
requestlock | send a VFS_request::requestlock on a path | No | Yes | key to lock on |
releaselock | send a VFS_request::releaselock on a path | No | Yes | key to release |
code | call VFS_creator::code() with the library:nodename | No | Yes | boolean true |
codeDirectory | call VFS_creator::codeDirectory() | No | No |
Some commands receive an object syntax, which is a way of batching requests. Some require require a boolean true
to be set, others just use the object as a list.
Reimplemented from VFS_websocket_client.
Definition at line 289 of file VFS_remotoserver.cpp.
|
virtualslot |
Receive a response from an issueRequest().
t | The VFS_request object |
If a client has _authenticated==false
, check the _success of the request, and populate an "authorization" command response with user information.
If the client has already been authenticated, call VFS_node::receiveResponse().
Definition at line 835 of file VFS_remotoserver.cpp.
|
virtualslot |
Remove a VFS_remotoserver_client::_sourcePathMap entry for a VFS_node.
s | The VFS_node |
This happens when the target VFS_node is unmounted().
Definition at line 974 of file VFS_remotoserver.cpp.
|
virtual |
Report the _user and _type of a connected client.
Reimplemented from VFS_node.
Definition at line 768 of file VFS_remotoserver.cpp.
|
protectedvirtual |
Send an RM command to a user.
r | The VFS_request object |
This happens when a node wants to write an rm directly to a client, probably from an event that was not initiated by the user.
For instance, the receiving side may also have a VFS or quasi-VFS that needs to execute an RM.
Calls writeUIRM() using the VFS_request object, and always sets r->_success=true
.
Reimplemented from VFS_node.
Definition at line 813 of file VFS_remotoserver.cpp.
|
protectedvirtual |
Write form or interface information back to a user.
r | The VFS_request object |
This happens when a node wants to write directly to a client, probably from an event that was not initiated by the user.
For instance, we may want to open a modal in the user's interface, or tell a client that it needs to reload.
Calls writeUIWrite() using the VFS_request object, and always sets r->_success=true
.
Reimplemented from VFS_websocket_client.
Definition at line 790 of file VFS_remotoserver.cpp.
bool VFS_remotoserver_client::writeError | ( | QString | message, |
bool | binary = false |
||
) |
Write an error state to a connected client.
message | The error message |
binary | Send using binary? |
Some operations may generate an error. This method will trigger an error modal on the client.
Definition at line 1396 of file VFS_remotoserver.cpp.
bool VFS_remotoserver_client::writeRequestError | ( | QString | command, |
QString | path, | ||
QString | reason, | ||
bool | binary = false |
||
) |
Write a requesterror command to a connected client.
command | The request command that has failed |
path | The request path that has failed |
reason | The reason for failure, if possible to know |
binary | Send using binary? |
Some operations may generate an error. This method will send a requesterror command to the client, which will give it an opportunity to deal with the problem, if possible.
Definition at line 1424 of file VFS_remotoserver.cpp.
bool VFS_remotoserver_client::writeRequestSuccess | ( | QString | command, |
QString | path, | ||
QJsonDocument | data = QJsonDocument() , |
||
QJsonObject | metadata = QJsonObject() , |
||
bool | binary = false |
||
) |
VFS_remotoserver_client::writeRequestSuccess.
command | The request command that has succeeded. |
path | The request path that has succeeded. |
data | The data to send back, which may be empty. |
metadata | The metadata to send back, which may be empty. |
binary | Send using binary? |
Some operations submitted by the client and not asking for a response. For instance, VFS_request::submit and VFS_request::create. However, we want to notify the client of success so it has an opportunity to trigger callbacks.
Definition at line 1454 of file VFS_remotoserver.cpp.
bool VFS_remotoserver_client::writeUICode | ( | QString | name, |
QString | code, | ||
QString | error, | ||
bool | binary = false |
||
) |
Write a VFS_request::code response to a connected client.
name | The nodename:libname of the request |
code | The code or raw data to return |
error | An error string, if it is set |
binary | Send using binary? |
Definition at line 1332 of file VFS_remotoserver.cpp.
bool VFS_remotoserver_client::writeUICodeDirectory | ( | QJsonObject | o, |
QString | error, | ||
bool | binary = false |
||
) |
Write a VFS_request::codeDirectory response to a connected client.
o | The code directory to send |
error | An error to write back to the client |
binary | Send using binary? |
Definition at line 1365 of file VFS_remotoserver.cpp.
bool VFS_remotoserver_client::writeUIDiff | ( | QString | path, |
QJsonDocument | diff, | ||
QString | user, | ||
bool | binary = false |
||
) |
Send a diff command to a client when something interesting happens on a subscribed VFS_node.
path | The path to report to the client |
diff | The diff |
user | The user originating the diff |
binary | Send using binary? |
Definition at line 1004 of file VFS_remotoserver.cpp.
bool VFS_remotoserver_client::writeUILS | ( | QString | id, |
QString | path, | ||
QJsonDocument | data, | ||
QJsonObject | metadata, | ||
bool | binary = false |
||
) |
Write a VFS_request::ls response to a connected client.
id | The ls id of the request. |
path | The path to write to the client |
data | The ls data |
metadata | The ls metadata |
binary | Send using binary? |
Because ls requests can be asynchronous and the requests need to be tracked by the client (for modals), an id is assigned.
Definition at line 1195 of file VFS_remotoserver.cpp.
bool VFS_remotoserver_client::writeUIMetadata | ( | QString | path, |
QJsonObject | metadata, | ||
bool | binary = false |
||
) |
Write a VFS_request::metadata response to a connected client.
path | The path to write to the client |
metadata | The metadata |
binary | Send using binary? |
Definition at line 1229 of file VFS_remotoserver.cpp.
bool VFS_remotoserver_client::writeUIRead | ( | QString | path, |
QJsonDocument | data, | ||
QJsonObject | metadata, | ||
bool | binary = false |
||
) |
Send the results of a VFS_request::read command to a client.
path | The path to report to the client |
data | The read data |
metadata | The read metadata |
binary | Send using binary? |
Definition at line 1045 of file VFS_remotoserver.cpp.
bool VFS_remotoserver_client::writeUIReleaseLock | ( | QString | path, |
QJsonDocument | data, | ||
bool | binary = false |
||
) |
Write the results of a VFS_request::releaselock to a connected client.
path | The path to write to the client |
data | The boolean status of eash requested key |
binary | Send using binary? |
Keys can always be released. The status of each released key will be true, and written back to the client:
Definition at line 1299 of file VFS_remotoserver.cpp.
bool VFS_remotoserver_client::writeUIRequestLock | ( | QString | path, |
QJsonDocument | data, | ||
bool | binary = false |
||
) |
Write the results of a VFS_request::requestlock to a connected client.
path | The path to write to the client |
data | The boolean status of eash requested key |
binary | Send using binary? |
The status of each requested key will be written back to the client:
Definition at line 1265 of file VFS_remotoserver.cpp.
bool VFS_remotoserver_client::writeUIRM | ( | QString | path, |
bool | binary = false |
||
) |
Send an RM command to a connected client.
path | The path to rm on the client |
binary | Send using binary? |
Definition at line 1121 of file VFS_remotoserver.cpp.
bool VFS_remotoserver_client::writeUISubscribe | ( | QString | path, |
QJsonDocument | data, | ||
QJsonObject | metadata, | ||
bool | binary = false |
||
) |
Write a VFS_request::subscribe response to a connected client.
path | The path to write to the client |
data | The subscribe data |
metadata | The subscribe metadata |
binary | Send using binary? |
Definition at line 1152 of file VFS_remotoserver.cpp.
bool VFS_remotoserver_client::writeUIWrite | ( | QString | path, |
QJsonDocument | data, | ||
QJsonObject | metadata, | ||
bool | binary = false |
||
) |
Write data to a connected client.
This will probably be a modal form.
path | The path to write to the client |
data | The write data |
metadata | The write metadata |
binary | Send using binary? |
Definition at line 1084 of file VFS_remotoserver.cpp.
|
friend |
Definition at line 37 of file VFS_remotoserver.h.
|
protected |
Parameters provided during the auth process.
Definition at line 84 of file VFS_remotoserver.h.
|
protected |
The session associated with this client connection.
Definition at line 78 of file VFS_remotoserver.h.
|
protected |
A map relating path requests from a client to path requests on the VFS.
We need to match VFS_request::_path with a response path, as the requesting client requests on a different path than the response may indicate.
Definition at line 85 of file VFS_remotoserver.h.
|
protected |
The remote client type, which may be "browser" or "unity" or any other id string.
This will be used in the future when/if there are many client types that need different treatment and initialization upon authentication.
Definition at line 83 of file VFS_remotoserver.h.
|
protected |
The authenticated client's username.
Definition at line 82 of file VFS_remotoserver.h.