Remoto - VFS: VFS_application.cpp Source File
Remoto - VFS
VFS_application.cpp
Go to the documentation of this file.
1 
2 #include "VFS.h"
3 #include "VFS_icons.h"
4 #include "VFS_application.h"
5 #include "VFS_acl.h"
6 
38 VFS_application::VFS_application(QString settingsRoot)
39 : VFS_node()
40 , _settingsRoot(settingsRoot)
41 {
42  //printf("settings root: %s\n",qUtf8Printable(settingsRoot));
43 
44  //connect(this,SIGNAL(mounted()),this,SLOT(listen()));
45  connect(VFS::root(),SIGNAL(initialized()),this,SLOT(initialize()));
46 }
47 
49 {
50 }
51 
59 {
60  //if (_settingsRoot != "")
61  // VFS::WARN( QString("would initialize from: %1").arg(_settingsRoot) );
62 }
63 
75 {
76  return VFS_icons::get("application");
77 }
78 
88 {
90  {
91  if (r->_session && __isNode(r->_session))
92  r->_reason = QString("Access was denied for user '%1' on '%2'").arg(r->_user).arg(r->_initialPath);
93  else
94  r->_reason = QString("Missing or invalid session. Access was denied for user '%1' on path '%2' ('%3')").arg(r->_user).arg(r->_path).arg(r->_initialPath);
95 
96  return nullptr;
97  }
98 
99  if (r->_path == "")
100  return this;
101 
102  return VFS_node::find(r);
103 }
104 
105 
116 {
117  QMutexLocker _l(&_lock);
118 
120  QJsonObject a;
121 
122  for (it=_children.begin();it!=_children.end();it++)
123  {
124  //bool b = VFS_acl::checkAllowAccess(r->_session,r->_initialPath+"/"+it.key());
125  bool b = VFS_acl::checkAllowAccess(r->_session,r->_prefixPath.join("/")+"/"+it.key());
126  //printf(" VFS_application ACL ls: %s : %d\n",qUtf8Printable(r->_initialPath+"/"+it.key()),b);
127  if (b)
128  a[it.key()] = it.value()->isContainer(); //bool means whether it's a container.
129  }
130 
131  r->_data = QJsonDocument(a);
132  r->_success = true;
133 }
134 
135 
136 /*
137  \brief Dummy entry, will generate an error
138  \param r The VFS_request object
139 
140  VFS_application instances are meant to be subclassed, so this is always an error for now.
141  */
142 
143 /*
144 void VFS_application::read(VFS_request *r)
145 {
146  r->_reason = QString("%1 bad read path: %2").arg(className()).arg(r->_path);
147  r->_success = false;
148 }
149 */
150 
QMap< QString, VFS_node * >::iterator VFS_childrenIterator
Definition: VFS_node.h:39
static bool checkAllowAccess(VFS_session *s, QString path, QString feature="")
Check if a session has access to a resource.
Definition: VFS_acl.cpp:407
virtual ~VFS_application()
Q_INVOKABLE VFS_application(QString settingsRoot="")
Construct a VFS_application object.
virtual void ls(VFS_request *r)
List the contents of this node.
virtual VFS_node * find(VFS_request *r)
Check if a resource (path) is available for this application.
virtual QByteArray icon()
Fetch the application icon.
virtual void initialize()
The default implementation does nothing.
static char * get(QString which="")
Fetch an icon from the library.
Definition: VFS_icons.cpp:34
VFS_node is the base class from which all other VFS_node classes derive.
Definition: VFS_node.h:143
VFS_children _children
This node's children.
Definition: VFS_node.h:179
static bool __isNode(VFS_node *)
Check to see if a node is in the global registry.
Definition: VFS_node.cpp:588
VFS_node * find(QString path)
Find a node by string path.
Definition: VFS_node.cpp:1100
QMutex _lock
A recursive mutex that is local to this node.
Definition: VFS_node.h:178
The base class for all requests between nodes.
Definition: VFS_node.h:54
QString _initialPath
the target path when the request was made (relative to the responder)
Definition: VFS_node.h:93
QStringList _prefixPath
the prefix elements found while searching for the target
Definition: VFS_node.h:94
QString _user
who initiated this request, mostly for logging
Definition: VFS_node.h:106
VFS_session * _session
The session associated with this request. This is an optional value, and care should be taken to chec...
Definition: VFS_node.h:105
QString _reason
if something (probably bad) happened, this is the reason
Definition: VFS_node.h:108
QString _path
the target path remnant... the remaining path element once the request has found its target
Definition: VFS_node.h:95
bool _success
if the request was successfully completed
Definition: VFS_node.h:107
QJsonDocument _data
the request payload
Definition: VFS_node.h:102
static VFS * root()
Return the root node of the VFS filesystem.
Definition: VFS.cpp:399