Remoto - VFS: VFS_remotoserver.h Source File
Remoto - VFS
VFS_remotoserver.h
Go to the documentation of this file.
1 #ifndef VFS_REMOTOSERVER_H
2 #define VFS_REMOTOSERVER_H
3 
4 #include <QJsonDocument>
5 #include <QJsonObject>
6 //#include <QDomDocument>
7 
9 
11 {
12  Q_OBJECT
13 
14  public:
15  Q_INVOKABLE explicit VFS_remotoserver(quint16 port, QString auth, QString sessions, QHostAddress addr=QHostAddress::Any, QWebSocketServer::SslMode ssl=QWebSocketServer::NonSecureMode, QString sslCertPath="", QString sslKeyPath="");
16  virtual ~VFS_remotoserver();
17 
18  virtual QString reportDetails();
19 
20  signals:
21 
22  public slots:
23  virtual void clientBinaryMessage(QByteArray message);
24  virtual void clientTextMessage(QString message);
25 
26  protected:
27  virtual VFS_websocket_client *createWebsocketClient(QWebSocket *s);
28 
29  private:
30  static int count;
31 };
32 
34 {
35  Q_OBJECT
36 
38 
39  public:
40  explicit VFS_remotoserver_client(QWebSocket *socket, VFS_websocket_server *server );
41  virtual ~VFS_remotoserver_client();
42 
43  virtual QJsonDocument receive(QByteArray data);
44  virtual VFS_node *find(VFS_request *r);
45 
46  virtual QString reportDetails();
47 
48  bool writeUIDiff(QString path, QJsonDocument diff, QString user, bool binary=false);
49  bool writeUIRead(QString path, QJsonDocument data, QJsonObject metadata, bool binary=false);
50  bool writeUIWrite(QString path, QJsonDocument data, QJsonObject metadata, bool binary=false);
51  bool writeUIRM(QString path, bool binary=false);
52  bool writeUISubscribe(QString path, QJsonDocument data, QJsonObject metadata, bool binary=false);
53  bool writeUILS(QString id, QString path, QJsonDocument data, QJsonObject metadata, bool binary=false);
54  bool writeUIMetadata(QString path, QJsonObject metadata, bool binary=false);
55  bool writeUIRequestLock(QString path, QJsonDocument data, bool binary=false);
56  bool writeUIReleaseLock(QString path, QJsonDocument data, bool binary=false);
57  bool writeUICode(QString libname, QString code, QString error, bool binary=false);
58  bool writeUICodeDirectory(QJsonObject o, QString error, bool binary=false);
59  bool writeError(QString message, bool binary=false);
60  bool writeRequestSuccess(QString command, QString path, QJsonDocument data=QJsonDocument(), QJsonObject metadata=QJsonObject(), bool binary=false);
61  bool writeRequestError(QString command, QString path, QString reason, bool binary=false);
62 
63  virtual VFS_request *createRequest(VFS_request::requestType type, QString path, QString user="unknown", QJsonDocument data=QJsonDocument(), QJsonObject metadata=QJsonObject(), bool dontDelete=false);
64 
65  QJsonObject parameters() const;
66 
67  protected:
68  virtual void authenticate(QJsonDocument d);
69 
70  //virtual void ls(VFS_request *r);
71  //virtual void read(VFS_request *r);
72  virtual void write(VFS_request *r);
73  //virtual void metadata(VFS_request *r);
74  //virtual void report(VFS_request *r);
75  //virtual void submit(VFS_request *r);
76  virtual void rm(VFS_request *r);
77 
79 
80  void addSourcePathMap(VFS_node *source, QString path);
81 
82  QString _user;
83  QString _type;
84  QJsonObject _parameters;
85  QMap<VFS_node *, QString> _sourcePathMap;
86 
87  private:
88 
89  public slots:
90  virtual void receiveResponse(VFS_request *t);
91  virtual void applyDiff(VFS_request *t);
92  virtual void removeSourcePathMap(VFS_node *n);
93 };
94 
96 {
97  public:
98  VFS_remotoserver_request(VFS_request::requestType type, VFS_remotoserver_client *origin, QString path="", QString user="unknown", QJsonDocument data=QJsonDocument(), QJsonObject metadata=QJsonObject(), bool binary=false);
99  virtual ~VFS_remotoserver_request();
100 
101  virtual void execute();
102 
103  bool _binary;
104 };
105 
106 #endif // VFS_REMOTOSERVER_H
VFS_node is the base class from which all other VFS_node classes derive.
Definition: VFS_node.h:143
virtual void metadata(VFS_request *r)
Fetch the metadata of this node.
Definition: VFS_node.cpp:797
static QString code(QString nodename, QString libname, QString &error)
Fetch code or any other resource from a node.
Definition: VFS_node.cpp:1038
void diff(VFS_node *origin, VFS_request *t)
Emit a diff, which will trigger notifySubscribers() for a mounted node.
A subclass of VFS_websocket_client that implements the remoto websocket protocol and handles requests...
virtual QJsonDocument receive(QByteArray data)
Receive a message from a connected websocket client.
QString _type
The remote client type, which may be "browser" or "unity" or any other id string.
virtual void authenticate(QJsonDocument d)
Authenticate a user using VFS_websocket_server::authenticate().
bool writeUICode(QString libname, QString code, QString error, bool binary=false)
Write a VFS_request::code response to a connected client.
bool writeRequestError(QString command, QString path, QString reason, bool binary=false)
Write a requesterror command to a connected client.
QMap< VFS_node *, QString > _sourcePathMap
A map relating path requests from a client to path requests on the VFS.
bool writeUIRequestLock(QString path, QJsonDocument data, bool binary=false)
Write the results of a VFS_request::requestlock to a connected client.
bool writeError(QString message, bool binary=false)
Write an error state to a connected client.
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_n...
bool writeUIWrite(QString path, QJsonDocument data, QJsonObject metadata, bool binary=false)
Write data to a connected client.
virtual void applyDiff(VFS_request *t)
Apply a diff to this node.
bool writeUIReleaseLock(QString path, QJsonDocument data, bool binary=false)
Write the results of a VFS_request::releaselock to a connected client.
bool writeUIMetadata(QString path, QJsonObject metadata, bool binary=false)
Write a VFS_request::metadata response to a connected client.
QJsonObject _parameters
Parameters provided during the auth process.
virtual void receiveResponse(VFS_request *t)
Receive a response from an issueRequest().
bool writeUIRead(QString path, QJsonDocument data, QJsonObject metadata, bool binary=false)
Send the results of a VFS_request::read command to a client.
QJsonObject parameters() const
Return the parameters provided to this client when authentication was granted.
VFS_session * _session
The session associated with this client connection.
virtual void write(VFS_request *r)
Write form or interface information back to a user.
QString _user
The authenticated client's username.
bool writeUICodeDirectory(QJsonObject o, QString error, bool binary=false)
Write a VFS_request::codeDirectory response to a connected client.
virtual void removeSourcePathMap(VFS_node *n)
Remove a VFS_remotoserver_client::_sourcePathMap entry for a VFS_node.
virtual VFS_node * find(VFS_request *r)
VFS_remotoserver_client cannot contain children, but instead points to a websocket client,...
virtual QString reportDetails()
Report the _user and _type of a connected 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.
bool writeRequestSuccess(QString command, QString path, QJsonDocument data=QJsonDocument(), QJsonObject metadata=QJsonObject(), bool binary=false)
VFS_remotoserver_client::writeRequestSuccess.
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.
bool writeUIRM(QString path, bool binary=false)
Send an RM command to a connected client.
virtual void rm(VFS_request *r)
Send an RM command to a user.
bool writeUISubscribe(QString path, QJsonDocument data, QJsonObject metadata, bool binary=false)
Write a VFS_request::subscribe response to a connected client.
VFS_remotoserver_client(QWebSocket *socket, VFS_websocket_server *server)
bool writeUILS(QString id, QString path, QJsonDocument data, QJsonObject metadata, bool binary=false)
Write a VFS_request::ls response to a connected client.
A subclass of VFS_request used for websocket (VFS_remotoserver) communication.
bool _binary
Binary mode flag for websocket messages.
virtual void execute()
Dynamically cast the _origin node to a VFS_remotoserver_client and write the results of a request to ...
VFS_remotoserver_request(VFS_request::requestType type, VFS_remotoserver_client *origin, QString path="", QString user="unknown", QJsonDocument data=QJsonDocument(), QJsonObject metadata=QJsonObject(), bool binary=false)
VFS_remotoserver is a subclass of VFS_websocket_server.
virtual void clientTextMessage(QString message)
The client has received as text websocket message.
Q_INVOKABLE VFS_remotoserver(quint16 port, QString auth, QString sessions, QHostAddress addr=QHostAddress::Any, QWebSocketServer::SslMode ssl=QWebSocketServer::NonSecureMode, QString sslCertPath="", QString sslKeyPath="")
virtual QString reportDetails()
Report the _port number.
virtual VFS_websocket_client * createWebsocketClient(QWebSocket *s)
Create a VFS_remotoserver_client to host a new connection.
static int count
The global count of VFS_remotoserver instances, used to create a config.json file if needed.
virtual void clientBinaryMessage(QByteArray message)
The client has received as binary websocket message.
virtual ~VFS_remotoserver()
The base class for all requests between nodes.
Definition: VFS_node.h:54
requestType
Requests perform one of these actions.
Definition: VFS_node.h:63
@ metadata
read metadata (6)
Definition: VFS_node.h:70
The VFS_session object represents a single session.
Definition: VFS_session.h:14
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.