Remoto - VFS
|
The VFS_session object represents a single session. More...
#include <VFS_session.h>
Public Slots | |
virtual void | applyDiff (VFS_request *r) |
Receive diffs from our subscriptions. More... | |
virtual void | receiveResponse (VFS_request *t) |
VFS_sessionManager::receiveResponse. 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_session (VFS_node *client, VFS_sessionManager *manager, QJsonObject data) | |
Construct a new VFS_session from a QJSonObject. More... | |
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="") | |
Construct a new VFS_session. More... | |
virtual | ~VFS_session () |
QString | authtoken () |
Return the file component of the _authtoken path. More... | |
QJsonValue | fetchSessionValue (QString key) |
Fetch a value from the _sessionData, by key. More... | |
virtual bool | isContainer () |
A VFS_session cannot have children. More... | |
bool | isMemberOf (QString group) |
Check if this session's group list includes the specified group. More... | |
bool | isMemberOf (QStringList groups) |
Check if this session's group list includes a member of the groups argument. More... | |
virtual QString | reportDetails () |
Report data about a connected client. More... | |
qint64 | secondsToExpire () |
Given the current time, calculate the number of seconds until this session will expire. More... | |
QJsonObject | toJson () |
Return a json object with the salient data from this session. 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... | |
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... | |
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... | |
Static Public Member Functions | |
static QJsonValue | fetchDefaultSessionValue (QString type, QString key) |
Fetch a session type's default value by key, as registered by registerSessionType() More... | |
static VFS_session * | fetchSession (QString address) |
Try to resolve and cast a string address to a VFS_session. More... | |
static bool | registerSessionType (QString type, QJsonObject definition, QJsonObject defaults=QJsonObject()) |
Register a new session type by name. 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 Member Functions | |
virtual QByteArray | icon () |
Return the user icon from VFS_icons. More... | |
virtual void | initializeUser (VFS_request *r) |
Check and create session files for a user. More... | |
virtual void | read (VFS_request *r) |
Read the session data. More... | |
QJsonObject | resolveTokens (QJsonObject _data) |
Resolve the tokens for a session type based on variables gathered in the _tokens object. More... | |
virtual void | rm (VFS_request *r) |
Remove (delete) this node, and also the _client associated with it. More... | |
virtual void | timerEvent (QTimerEvent *event) |
The timer event used to check if the session is still valid. 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 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 | 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 | 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 | |
int | timerID |
The ID of the session timer. 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... | |
Private Member Functions | |
void | dequeueInitializer () |
Remove the first initializer item from _initializers and call issueRequest(). More... | |
Static Private Member Functions | |
static void | initializeTypes () |
Initialize the VFS_session::_sessionTypes member. More... | |
Private Attributes | |
QString | _address |
The remote address of the client. More... | |
QString | _authpath |
The VFS_auth path that authenticated this session. More... | |
QString | _authtoken |
The authtoken VFS path associated with this session, which corresponds to an entry at VFS_sessionManager::_tokendata. More... | |
VFS_node * | _client |
The client this session is for, which will usually be a subclass of VFS_websocket_client. More... | |
QDateTime | _created |
The creation date/time of this session. More... | |
QDateTime | _expires |
The Expiration date/time of this session. More... | |
QJsonArray | _groups |
The list of groups this user is a member of. More... | |
QString | _home |
The VFS path to this user's home directory. More... | |
bool | _initialized |
false until initialization is complete More... | |
QQueue< VFS_request * > | _initializers |
The list of initialization requests which must be empty for _initialized to become true. More... | |
VFS_sessionManager * | _manager |
The sessionManager tracking this session. More... | |
QString | _realname |
The real name of the user associated with this session. More... | |
QJsonObject | _sessionData |
The resolved session data for this user type. More... | |
QJsonObject | _tokens |
The tokens available to resolve session values. More... | |
QString | _type |
The session or client type. More... | |
quint16 | _uidnumber |
The uidnumber of the user associated with this session. More... | |
QString | _user |
The username associated with this session. More... | |
Static Private Attributes | |
static bool | _initializedTypes = false |
Whether or not VFS_session static variables have been initialized. More... | |
static QJsonObject | _sessionDefaults = QJsonObject() |
The default values, per type, per entry. More... | |
static QJsonObject | _sessionTypes = QJsonObject() |
The registered session types. The entries here will be de-tokenized on read() More... | |
static QMutex | _sessionTypesLock |
A mutex to protect thread safety during initialization. More... | |
Friends | |
class | VFS_acl |
class | VFS_sessionManager |
Additional Inherited Members | |
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... | |
The VFS_session object represents a single session.
A session may represent an actual user or some other logged-in thing, which may be another VFS, as defined by the _type.
Depending on the session type, it may report session data like user preferences, interface state, or per-application settings. Plugins will need to register themselves to a VFS_sessionManager for this to be complete.
Definition at line 13 of file VFS_session.h.
|
explicit |
Construct a new VFS_session.
client | The VFS_node that represents the client connection. |
manager | The VFS_sessionManager that is tracking this session. |
user | The username associated with this session. |
type | The client/session type. |
home | The VFS path to the user's home directory. |
authpath | The path to the VFS_auth node that authenticated this session |
expires | A time in the future for expiration, or a null time which will never expire. |
address | The address of the remote client, used only for reporting |
parameters | Parameters passed from the client during authentication |
authtoken | The authtoken to create or update, if present. |
A created session should only exist for a fixed amount of time, and then expire. New activity does not reset the expiration... A user will need to need to re-login at some interval.
The constructor will start a timer at an interval of one minute. That timer will check if the current system time is greater than the expiration time, and emit finished() if so.
If an authtoken exists the token data will be deleted later by the VFS_sessionManager::_pruner.
Definition at line 51 of file VFS_session.cpp.
|
explicit |
Construct a new VFS_session from a QJSonObject.
client | The VFS_node that represents the client connection. |
manager | The VFS_sessionManager that is tracking this session. |
data | The data used to construct this session |
This contstructor is used to create sessions transmitted to sub-VFS instances, and is later used for ACLs. Generally a VFS_tcp_export_client will request a session if its VFS_tcp_export_sessionManager doesn't have one registered with a provided ID.
The data
parameter should contain:
If an expiration is provided it will be ignored, and instead an expiration of approximately 10 minutes will be set.
The constructor will start a timer at an interval of one minute. That timer will check if the current system time is greater than the expiration time, and emit finished() if so.
Definition at line 121 of file VFS_session.cpp.
|
virtual |
Definition at line 160 of file VFS_session.cpp.
|
virtualslot |
Receive diffs from our subscriptions.
r | The VFS_request object |
We have subscribed to the nodes/paths registered for the profile type. Here we receive their diffs.
If a diff's data is null, we consider that the deletion of an important session file, and we will kill this session.
Definition at line 824 of file VFS_session.cpp.
QString VFS_session::authtoken | ( | ) |
Return the file component of the _authtoken path.
Definition at line 400 of file VFS_session.cpp.
|
private |
Remove the first initializer item from _initializers and call issueRequest().
If this is the last item in the queue, we assume it's the original request from a sessionManager and populate the response data with type-dependent paths for a user session.
For instance, for a session of type "browser":
Tokens will have already been replaced with corresponding values from _sessionData
.
The VFS_sessionManager (_manager) will add authtoken data to this.
This method will check/create all the paths resolved by the type template.
Definition at line 654 of file VFS_session.cpp.
|
static |
Fetch a session type's default value by key, as registered by registerSessionType()
type | The session type. |
key | The key of the default value being fetched. |
Definition at line 304 of file VFS_session.cpp.
|
static |
Try to resolve and cast a string address to a VFS_session.
address | The string representation of a pointer |
Definition at line 324 of file VFS_session.cpp.
QJsonValue VFS_session::fetchSessionValue | ( | QString | key | ) |
Fetch a value from the _sessionData, by key.
key | The key to fetch |
If the key does not exist in _sessionData, QJsonValue::Undefined will be returned.
Definition at line 268 of file VFS_session.cpp.
|
protectedvirtual |
Return the user icon from VFS_icons.
Reimplemented from VFS_node.
Definition at line 742 of file VFS_session.cpp.
|
staticprivate |
Initialize the VFS_session::_sessionTypes member.
Additional types can be registered later with VFS_session::registerType()
Definition at line 174 of file VFS_session.cpp.
|
protectedvirtual |
Check and create session files for a user.
r | The VFS_request from the sessionManager, which will be the callback for when initialization is complete |
This method will initialize the _sessionData object and ensure that folders are created and files are copied from skeleton entries as needed.
Definition at line 509 of file VFS_session.cpp.
|
virtual |
A VFS_session cannot have children.
Reimplemented from VFS_node.
Definition at line 453 of file VFS_session.cpp.
bool VFS_session::isMemberOf | ( | QString | group | ) |
Check if this session's group list includes the specified group.
group | The group name to search for in this session's group list |
Definition at line 415 of file VFS_session.cpp.
bool VFS_session::isMemberOf | ( | QStringList | groups | ) |
Check if this session's group list includes a member of the groups argument.
groups | The group names to search for in this session's group list |
Definition at line 435 of file VFS_session.cpp.
|
protectedvirtual |
Read the session data.
r | The VFS_request object |
Reimplemented from VFS_node.
Definition at line 769 of file VFS_session.cpp.
|
virtualslot |
VFS_sessionManager::receiveResponse.
r | The VFS_request response object |
Definition at line 839 of file VFS_session.cpp.
|
static |
Register a new session type by name.
type | The session type. |
definition | The tokenized session definition. |
defaults | The json objects representing the default values for a session definition field. |
When a client connects to the system via websocket, a session is created for that user. The client should identify itself by type during the authentication/authorization process. New session types can be added using this method.
A series of tokens are recognized by default:
In addition, any parameters
passed during the authorization request are added to the token list.
Any path referenced here will be checked by VFS_session::initializeUser() to validate the existence of directories and files. Any entry ending with a slash '/' be considered a directory, and those without are considered a file.
For those that are files, you will probably want to provide default values in the defaults
object.
Definition at line 241 of file VFS_session.cpp.
|
virtual |
Report data about a connected client.
Reimplemented from VFS_node.
Definition at line 464 of file VFS_session.cpp.
|
protected |
Resolve the tokens for a session type based on variables gathered in the _tokens object.
data | The data to resolve |
Definition at line 701 of file VFS_session.cpp.
|
protectedvirtual |
Remove (delete) this node, and also the _client associated with it.
r | The VFS_request object |
Reimplemented from VFS_node.
Definition at line 795 of file VFS_session.cpp.
qint64 VFS_session::secondsToExpire | ( | ) |
Given the current time, calculate the number of seconds until this session will expire.
This is to be used for browser cookie expiration, which receives a "max-age" field when setting a cookie.
Definition at line 386 of file VFS_session.cpp.
|
protectedvirtual |
The timer event used to check if the session is still valid.
event | The QTimerEvent |
If the currentDateTimeUtc is greater than _expires, this node will emit a finished() signal, which will kill the session and cause the connection to drop.
Definition at line 488 of file VFS_session.cpp.
QJsonObject VFS_session::toJson | ( | ) |
Return a json object with the salient data from this session.
This is used to transmit data to sub-vfs instances. It does not (cannot) transmit meaningful object pointers (like _client or _manager), and therefore will not be constructable in that way on a receiving side.
Definition at line 354 of file VFS_session.cpp.
|
friend |
Definition at line 18 of file VFS_session.h.
|
friend |
Definition at line 17 of file VFS_session.h.
|
private |
The remote address of the client.
Definition at line 73 of file VFS_session.h.
|
private |
The VFS_auth path that authenticated this session.
Definition at line 81 of file VFS_session.h.
|
private |
The authtoken VFS path associated with this session, which corresponds to an entry at VFS_sessionManager::_tokendata.
Definition at line 82 of file VFS_session.h.
|
private |
The client this session is for, which will usually be a subclass of VFS_websocket_client.
Definition at line 69 of file VFS_session.h.
|
private |
The creation date/time of this session.
Definition at line 71 of file VFS_session.h.
|
private |
The Expiration date/time of this session.
Definition at line 72 of file VFS_session.h.
|
private |
The list of groups this user is a member of.
Definition at line 78 of file VFS_session.h.
|
private |
The VFS path to this user's home directory.
Definition at line 80 of file VFS_session.h.
|
private |
false until initialization is complete
Definition at line 65 of file VFS_session.h.
|
staticprivate |
Whether or not VFS_session static variables have been initialized.
Definition at line 88 of file VFS_session.h.
|
private |
The list of initialization requests which must be empty for _initialized to become true.
Definition at line 66 of file VFS_session.h.
|
private |
The sessionManager tracking this session.
Definition at line 70 of file VFS_session.h.
|
private |
The real name of the user associated with this session.
Definition at line 77 of file VFS_session.h.
|
private |
The resolved session data for this user type.
Definition at line 85 of file VFS_session.h.
|
staticprivate |
The default values, per type, per entry.
Definition at line 91 of file VFS_session.h.
|
staticprivate |
The registered session types. The entries here will be de-tokenized on read()
Definition at line 90 of file VFS_session.h.
|
staticprivate |
A mutex to protect thread safety during initialization.
Definition at line 89 of file VFS_session.h.
|
private |
The tokens available to resolve session values.
Definition at line 84 of file VFS_session.h.
|
private |
The session or client type.
Definition at line 79 of file VFS_session.h.
|
private |
The uidnumber of the user associated with this session.
Definition at line 76 of file VFS_session.h.
|
private |
The username associated with this session.
Definition at line 75 of file VFS_session.h.
|
protected |
The ID of the session timer.
Definition at line 44 of file VFS_session.h.