Remoto - VFS: VFS_session.h Source File
Remoto - VFS
VFS_session.h
Go to the documentation of this file.
1 #ifndef VFS_SESSION_H
2 #define VFS_SESSION_H
3 
4 #include "VFS_base/VFS_node.h"
5 #include "VFS_sessionManager.h"
6 
7 #include <QDateTime>
8 #include <QMutex>
9 #include <QQueue>
10 
11 class VFS_sessionManager;
12 
13 class VFS_session : public VFS_node
14 {
15  Q_OBJECT
16 
17  friend class VFS_sessionManager;
18  friend class VFS_acl;
19 
20  public:
21  explicit VFS_session(VFS_node *client, VFS_sessionManager *manager, QString user, QString type, QString home, QString authpath, QDateTime expires=QDateTime(), QString address="", QJsonObject parameters=QJsonObject(), QString authtoken="");
22  explicit VFS_session(VFS_node *client, VFS_sessionManager *manager, QJsonObject data);
23  virtual ~VFS_session();
24 
25  virtual bool isContainer();
26  virtual QString reportDetails();
27 
28  static bool registerSessionType(QString type, QJsonObject definition, QJsonObject defaults=QJsonObject());
29 
30  bool isMemberOf(QString group);
31  bool isMemberOf(QStringList groups);
32 
33  QJsonValue fetchSessionValue(QString key);
34  static QJsonValue fetchDefaultSessionValue(QString type, QString key);
35 
36  static VFS_session *fetchSession(QString address);
37  QJsonObject toJson();
38 
39  qint64 secondsToExpire();
40  QString authtoken();
41 
42  protected:
43  virtual void timerEvent(QTimerEvent *event);
44  int timerID;
45 
46  virtual QByteArray icon();
47 
48  //virtual void subscribe(VFS_request *r);
49  //virtual void unsubscribe(VFS_request *r);
50 
51  //virtual void ls(VFS_request *r);
52  virtual void read(VFS_request *r);
53  //virtual void write(VFS_request *r);
54  //virtual void metadata(VFS_request *r);
55  //virtual void report(VFS_request *r);
56  //virtual void submit(VFS_request *r);
57  virtual void rm(VFS_request *r);
58  //virtual void requestLock(VFS_request *r);
59  //virtual void releaseLock(VFS_request *r);
60 
61  virtual void initializeUser(VFS_request *r);
62  QJsonObject resolveTokens(QJsonObject _data);
63 
64  private:
65  bool _initialized;
66  QQueue<VFS_request *> _initializers;
67  void dequeueInitializer();
68 
71  QDateTime _created;
72  QDateTime _expires;
73  QString _address;
74 
75  QString _user;
76  quint16 _uidnumber;
77  QString _realname;
78  QJsonArray _groups;
79  QString _type;
80  QString _home;
81  QString _authpath;
82  QString _authtoken;
83 
84  QJsonObject _tokens;
85  QJsonObject _sessionData;
86 
87  static void initializeTypes();
88  static bool _initializedTypes;
89  static QMutex _sessionTypesLock;
90  static QJsonObject _sessionTypes;
91  static QJsonObject _sessionDefaults;
92 
93  public slots:
94  virtual void applyDiff(VFS_request *r);
95  virtual void receiveResponse(VFS_request *t);
96 };
97 
98 #endif // VFS_SESSION_H
The ACL class for maintaining permission to nodes.
Definition: VFS_acl.h:7
VFS_node is the base class from which all other VFS_node classes derive.
Definition: VFS_node.h:143
friend class VFS_session
Definition: VFS_node.h:146
The base class for all requests between nodes.
Definition: VFS_node.h:54
The VFS_session object represents a single session.
Definition: VFS_session.h:14
QString _realname
The real name of the user associated with this session.
Definition: VFS_session.h:77
virtual void timerEvent(QTimerEvent *event)
The timer event used to check if the session is still valid.
bool _initialized
false until initialization is complete
Definition: VFS_session.h:65
static QMutex _sessionTypesLock
A mutex to protect thread safety during initialization.
Definition: VFS_session.h:89
QDateTime _expires
The Expiration date/time of this session.
Definition: VFS_session.h:72
virtual void rm(VFS_request *r)
Remove (delete) this node, and also the _client associated with it.
QJsonObject _tokens
The tokens available to resolve session values.
Definition: VFS_session.h:84
virtual ~VFS_session()
static bool _initializedTypes
Whether or not VFS_session static variables have been initialized.
Definition: VFS_session.h:88
virtual QByteArray icon()
Return the user icon from VFS_icons.
static QJsonObject _sessionTypes
The registered session types. The entries here will be de-tokenized on read()
Definition: VFS_session.h:90
QQueue< VFS_request * > _initializers
The list of initialization requests which must be empty for _initialized to become true.
Definition: VFS_session.h:66
virtual void applyDiff(VFS_request *r)
Receive diffs from our subscriptions.
virtual void receiveResponse(VFS_request *t)
VFS_sessionManager::receiveResponse.
VFS_sessionManager * _manager
The sessionManager tracking this session.
Definition: VFS_session.h:70
QJsonObject resolveTokens(QJsonObject _data)
Resolve the tokens for a session type based on variables gathered in the _tokens object.
virtual void initializeUser(VFS_request *r)
Check and create session files for a user.
static QJsonValue fetchDefaultSessionValue(QString type, QString key)
Fetch a session type's default value by key, as registered by registerSessionType()
qint64 secondsToExpire()
Given the current time, calculate the number of seconds until this session will expire.
QString _type
The session or client type.
Definition: VFS_session.h:79
static QJsonObject _sessionDefaults
The default values, per type, per entry.
Definition: VFS_session.h:91
bool isMemberOf(QString group)
Check if this session's group list includes the specified group.
QJsonObject toJson()
Return a json object with the salient data from this session.
quint16 _uidnumber
The uidnumber of the user associated with this session.
Definition: VFS_session.h:76
QString _user
The username associated with this session.
Definition: VFS_session.h:75
QJsonArray _groups
The list of groups this user is a member of.
Definition: VFS_session.h:78
QString _authpath
The VFS_auth path that authenticated this session.
Definition: VFS_session.h:81
QString _address
The remote address of the client.
Definition: VFS_session.h:73
VFS_node * _client
The client this session is for, which will usually be a subclass of VFS_websocket_client.
Definition: VFS_session.h:69
static VFS_session * fetchSession(QString address)
Try to resolve and cast a string address to a VFS_session.
virtual QString reportDetails()
Report data about a connected client.
QString _home
The VFS path to this user's home directory.
Definition: VFS_session.h:80
void dequeueInitializer()
Remove the first initializer item from _initializers and call issueRequest().
QString _authtoken
The authtoken VFS path associated with this session, which corresponds to an entry at VFS_sessionMana...
Definition: VFS_session.h:82
QJsonObject _sessionData
The resolved session data for this user type.
Definition: VFS_session.h:85
QDateTime _created
The creation date/time of this session.
Definition: VFS_session.h:71
QString authtoken()
Return the file component of the _authtoken path.
static bool registerSessionType(QString type, QJsonObject definition, QJsonObject defaults=QJsonObject())
Register a new session type by name.
static void initializeTypes()
Initialize the VFS_session::_sessionTypes member.
int timerID
The ID of the session timer.
Definition: VFS_session.h:44
virtual bool isContainer()
A VFS_session cannot have children.
virtual void read(VFS_request *r)
Read the session data.
QJsonValue fetchSessionValue(QString key)
Fetch a value from the _sessionData, by key.
VFS_sessionManager manages connected clients and their session data.