Wittyshare  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WsFsDaemon.cpp
Go to the documentation of this file.
1 
14 #include "WsFsDaemon.h"
15 
16 #include <Include/WsGlobalConfig.h>
17 #include <Tree/WsAccessTree.h>
20 #include <Logger/WsLogger.h>
21 #include <Search/WsSearch.h>
22 #include <Include/WsRequestType.h>
23 
24 using namespace boost;
25 using namespace zmq;
26 using namespace Json;
27 
29  m_listening(true),
30  m_conf(props)
31 {
32  if (m_conf->get("global", "enable_compression", "true") == "true") {
33  m_compress = true;
34  m_compressor = new WsCompressor();
36  LOG(INFO) << "WsFsDaemon::WsFsDaemon() : Compression is enabled";
37  } else m_compress = false;
38 }
39 
41 {
42  /* Stop listenning */
43  m_listening = false;
44  delete m_operation;
45  delete WsLogWriter::instance();
46 }
47 
48 WsFsDaemon::WsFsDaemon::DaemonStatus WsFsDaemon::workerRoutine()
49 {
50  LOG(DEBUG) << "WsFsDaemon::workerRoutine : starting new worker";
51  zmq::socket_t sock (*m_context, ZMQ_REP);
52  sock.connect ("inproc://workers");
53  Value root;
54  while (m_listening) {
55  try {
56  string data;
57  /* Receive data from socket */
58  if (receive(sock, data) == Failure)
59  return Failure;
60  /* Parse data (Json) */
61  if (parse(data, root) == Failure) {
63  continue;
64  }
65  /* handle the request depending on type */
66  int ret = handleRequest(sock, root);
67  /* If return code is error or not logged send a message */
68  switch (ret) {
69  case Failure:
71  break;
72  case NotLogged:
73  send(sock, "notlogged");
74  break;
75  }
76  } catch (zmq::error_t err) {
77  LOG(ERROR) << "WsFsDaemon::bind() : Error listening " << err.what();
78  }
79  }
80 }
81 
82 
83 WsFsDaemon::WsFsDaemon::DaemonStatus WsFsDaemon::bind(unsigned int numWorkers)
84 {
85  /* Instanciate object used for operations on tree */
88  LOG(ERROR) << "WsFsDaemon::bind() : Could not update WsFileSystemTree";
89  return Failure;
90  }
91  /* Retrieve values from configuration */
92  string protocol = m_conf->get("global", "protocol", "tcp");
93  string host = m_conf->get("global", "host", "127.0.0.1");
94  string port = m_conf->get("global", "port", "5555");
95  /* Init socket related data and socket */
96  m_context = new context_t(1);
97  socket_t clients(*m_context, ZMQ_ROUTER);
98  try {
99  LOG(INFO) << "WsFsDaemon::bind() : Binding server using " << protocol << " on " << host << ":" << port;
100  clients.bind((protocol + "://" + host + ":" + port).c_str());
101  } catch (zmq::error_t err) {
102  LOG(ERROR) << "WsFsDaemon::bind() : Cannot bind socket : " << err.what();
103  return Failure;
104  }
105  socket_t workers(*m_context, ZMQ_DEALER);
106  workers.bind("inproc://workers");
107  /* Load All groups */
108  WsAuthenticator auth;
109  m_allGroups = auth.getAllGroups();
110  /* Launch workers in separate threads */
111  for (int thread_nbr = 0; thread_nbr != numWorkers; thread_nbr++) {
112  new boost::thread(boost::bind(&WsFsDaemon::workerRoutine, this));
113  }
114  // Connect work threads to client threads via a queue
115  zmq::proxy (clients, workers, NULL);
116  LOG(INFO) << "WsFsDaemon::bind() : Binding server Success !";
117  return Success;
118 }
119 
120 WsFsDaemon::DaemonStatus WsFsDaemon::send(socket_t& sock, const string& s)
121 {
122  try {
123  /* Compress data ? */
124  if (m_compress) {
125  char* data = 0;
126  long r = m_compressor->compress(s, &data);
127  if (r == ErrorCode::Failure)
128  return Failure;
129  /* Create message */
130  message_t reply(r);
131  if (memcpy ((void*) reply.data (), data, r) == NULL) {
132  LOG(ERROR) << "WsFsDaemon::send() : Could not memcpy in Server";
133  return Failure;
134  }
135  delete[] data;
136  /* Send message */
137  if (sock.send (reply) < 0) {
138  LOG(ERROR) << "WsFsDaemon::send() : Could not send on socket ";
139  return Failure;
140  }
141  } else {
142  /* No compression, create and send message */
143  message_t reply(s.length());
144  if (memcpy ((void*) reply.data (), s.c_str(), s.length()) == NULL) {
145  LOG(ERROR) << "WsFsDaemon::send() : Could not memcpy in Server";
146  return Failure;
147  }
148  if (sock.send (reply) < 0) {
149  LOG(ERROR) << "WsFsDaemon::send() : Could not send on socket ";
150  return Failure;
151  }
152  }
153  } catch (zmq::error_t err) {
154  LOG(ERROR) << "WsFsDaemon::send() : Error sending " << err.what();
155  return Failure;
156  }
157  return Success;
158 }
159 
160 WsFsDaemon::DaemonStatus WsFsDaemon::receive(socket_t& sock, string& receivedData)
161 {
162  try {
163  message_t request;
164  if (sock.recv (&request) < 0) {
165  LOG(ERROR) << "WsFsDaemon::receive() : Could not receive on socket";
166  return Failure;
167  }
168  receivedData = rawDataToString(request);
169  } catch (zmq::error_t err) {
170  LOG(ERROR) << "WsFsDaemon::send() : Error sending " << err.what();
171  return Failure;
172  }
173  /* Parse the received request */
174  return Success;
175 }
176 
178 {
179  //Clear old Json tree
180  Reader reader;
181  root.clear();
182  if (!reader.parse(s, root, false)) {
183  LOG(ERROR) << "WsFsDaemon::parse() : Could not parse received input";
184  return Failure;
185  }
186  return Success;
187 }
188 
190 {
191  Value v = root[RequestField::Type];
192  if (v == Value::null) {
193  LOG(ERROR) << "WsFsDaemon::handleRequest() : Could not find request type";
194  return Failure;
195  }
196  /* get credentials */
197  string uid = root[RequestField::Uid].asString();
198  string pass = root[RequestField::Pass].asString();
199  string ip = root[RequestField::Ip].asString();
200  int requestType = v.asInt();
201  LOG(INFO) << "WsFsDaemon::handleRequest() : Received request : " << requestType << " from user " << uid << " ip " << ip;
202  /* Authenticate request */
203  if (requestType == Auth)
204  return handleAuthRequest(sock, root);
205  /* Check if user is logged because all other requests needs authenticated user*/
206  if (!isActiveSession(uid, pass, ip)) {
207  LOG(ERROR) << "WsFsDaemon::handleRequest() : User is not logged " << uid << " ip " << ip << " request : " << requestType;
208  return NotLogged;
209  }
210  switch (requestType) {
211  /* Permission request */
212  case Perm:
213  return handlePermRequest(sock, root);
214  /* Get all groups request */
215  case AllGroups:
216  return handleAllGroupsRequest(sock, root);
217  /* Get properties of a node request */
218  case Properties:
219  return handlePropsRequest(sock, root);
220  /* Get a property of a node request */
221  case Property:
222  return handlePropRequest(sock, root);
223  /* Search request */
224  case Search:
225  return handleSearchRequest(sock, root);
226  /* Clear cache request */
227  case ClearCache:
228  return handleClearCache(sock, root);
229  /* Get access tree item request */
230  case AccessItems:
231  return handleAccessTreeRequest(sock, root);
232  /* Get isEditor request */
233  case IsEditor:
234  return handleIsEditorRequest(sock, root);
235  /* Get isAdmin request */
236  case IsAdmin:
237  return handleIsAdminRequest(sock, root);
238  /* get RootPath request */
239  case RootPath:
240  return handleRootPathRequest(sock, root);
241  /* Get tree version request */
242  case TreeVersion:
243  return handleGetTreeVersion(sock, root);
244  /* Save properties of a node request */
245  case SaveProps:
246  return handleSavePropertiesRequest(sock, root);
247  /* Save a property of a node request */
248  case SaveProp:
249  return handleSavePropertyRequest(sock, root);
250  /* Create a node request */
251  case CreateNode:
252  return handleCreateNodeRequest(sock, root);
253  /* Delete a node request */
254  case DeleteNode:
255  return handleDeleteNodeRequest(sock, root);
256  /* Rename a node request */
257  case RenameNode:
258  return handleRenameNodeRequest(sock, root);
259  /* Lock a node request */
260  case GetLock:
261  return handleGetLockRequest(sock, root);
262  /* Unlock a node request */
263  case PutLock:
264  return handlePutLockRequest(sock, root);
265  /* Check lock */
266  case IsLocked:
267  return handleIsLockedRequest(sock, root);
268  default:
269  LOG(ERROR) << "WsFsDaemon::handleRequest() : Undefined request type " << requestType;
270  return Failure;
271  }
272 }
273 
275 {
276  /* get credentials */
277  string uid = root[RequestField::Uid].asString();
278  string pass = root[RequestField::Pass].asString();
279  string ip = root[RequestField::Ip].asString();
280  /* Check if there's already an active session for the user */
281  if (isActiveSession(uid, pass, ip)) {
282  /* If yes retrieve it from the cache */
283  WsUserSession* usess = m_userMap[uid];
284  LOG(DEBUG) << "WsFsDaemon::handleAuthRequest() : Session active for " << uid;
285  Value answer;
286  answer[RequestField::Uid] = uid;
287  answer[RequestField::Name] = usess->getName();
288  answer[RequestField::Surname] = usess->getSurname();
289  answer[RequestField::Email] = usess->getEmail();
290  return send(sock, answer.toStyledString());
291  }
292  LOG(INFO) << "WsFsDaemon::handleAuthRequest() : Received authentification request from user " << uid;
293  /* No active session, we need to authenticate the user */
294  WsAuthenticator c;
295  if (c.authentify(uid, pass, ip) == ErrorCode::Failure)
296  return Failure;
297  /* Create message */
298  Value answer;
299  answer[RequestField::Uid] = c.getUid();
300  answer[RequestField::Name] = c.getFirstName();
301  answer[RequestField::Surname] = c.getSurname();
302  answer[RequestField::Email] = c.getEmail();
303  set<string> groups = c.getUserGroups();
304  /* Insert uid in groups User is part of his group*/
305  groups.insert(c.getUid());
306  WsUserSession* sess = new WsUserSession(c.getUid(), pass, ip);
307  sess->setName(c.getFirstName());
308  sess->setSurname(c.getSurname());
309  sess->setEmail(c.getEmail());
310  sess->setGroups(c.getUserGroups());
311  m_userMap[c.getUid()] = sess;
312  LOG(INFO) << "WsFsDaemon::handleAuthRequest() : new uid is " << c.getUid();
313  return send(sock, answer.toStyledString());
314 }
315 
317 {
318  /* get credentials */
319  string uid = root[RequestField::Uid].asString();
320  /* Get the groups of the user */
321  set<string> groups = m_userMap[uid]->getGroups();
322  /* Create AccessTree */
323  WsAccessTree* tree = m_operation->getAccessTree(groups);
324  if (tree == 0)
325  return Failure;
326  /* Transform menuTree to json */
327  WsTreeSerializer serializer(tree);
328  serializer.serialize();
329  delete tree;
330  return send(sock, serializer.getSerializedForm());
331 }
332 
334 {
335  /* get credentials */
336  string uid = root[RequestField::Uid].asString();
337  string path = root[RequestField::Path].asString();
338  /* get users groups */
339  set<string> groups = m_userMap[uid]->getGroups();
340  /* Get permissions on node for user */
341  int perms = m_operation->getPermissions(groups, path);
342  if ( perms != ErrorCode::Failure)
343  return send(sock, boost::lexical_cast<string>(perms));
344  return Failure;
345 }
346 
348 {
349  /* Get credentials */
350  string uid = root[RequestField::Uid].asString();
351  /* Serialize the groups */
353  if (send(sock, s.getSerializedForm()) == ErrorCode::Failure)
354  return Failure;
355  return Success;
356 }
357 
359 {
360  /* Get credentials */
361  string uid = root[RequestField::Uid].asString();
362  string path = root[RequestField::Path].asString();
363  int i;
364  WsNodeProperties* answer;
365  /* Get groups of user */
366  set<string> groups = m_userMap[uid]->getGroups();
367  /* Get properties of node */
368  answer = m_operation->getProperties(groups, path);
369  if (answer == 0)
370  return Failure;
371  return send(sock, answer->getRoot().toStyledString());
372 }
373 
375 {
376  /* Get credentials */
377  string uid = root[RequestField::Uid].asString();
378  string p = root[RequestField::Path].asString();
379  string section = root[RequestField::Section].asString();
380  string prop = root[RequestField::Property].asString();
381  int i;
382  string answer;
383  set<string> groups = m_userMap[uid]->getGroups();
384  /* Get the node */
385  answer = m_operation->getProperty(groups, section, p, prop);
386  return send(sock, answer);
387 }
388 
390 {
391  /* Get credentials */
392  Value answer;
393  string uid = root[RequestField::Uid].asString();
394  string terms = root[RequestField::Terms].asString();
395  /* Get the groups of user */
396  set<string> groups = m_userMap[uid]->getGroups();
397  /* Get the search results */
398  vector<WsResultItem> l = m_operation->getSearchResults(groups, terms);
399  vector<WsResultItem>::iterator it;
400  int i = 0;
401  /* Build the Json answer */
402  for (it = l.begin(); it != l.end(); ++it, ++i) {
403  answer[i][RequestField::Path] = (*it).getPath().string();
404  answer[i][RequestField::Body] = (*it).getBody();
405  answer[i][RequestField::Type] = (*it).getType();
406  answer[i][RequestField::Size] = (double)(*it).getSize();
407  answer[i][RequestField::ModifyDate] = (double)(*it).getModifyDate();
408  }
409  return send(sock, answer.toStyledString());
410 }
411 
413 {
414  /* Get credentials */
415  string uid = root[RequestField::Uid].asString();
416  if (m_userMap.count(uid) > 0)
417  delete m_userMap[uid];
418  m_userMap.erase(uid);
419  return send(sock, RequestField::Success);
420 }
421 
423 {
424  /* Get credentials */
425  string uid = root[RequestField::Uid].asString();
426  /* Get user groups */
427  set<string> groups = m_userMap[uid]->getGroups();
428  /* Check if he is editor and send result */
429  if (m_operation->isEditor(groups))
430  return send(sock, "true");
431  else
432  return send(sock, "false");
433 }
434 
436 {
437  /* Get credentials */
438  string uid = root[RequestField::Uid].asString();
439  /* Get the groups of the user */
440  set<string> groups = m_userMap[uid]->getGroups();
441  /* Check if he is an admin and send result */
442  if (m_operation->isAdministrator(groups))
443  return send(sock, "true");
444  else
445  return send(sock, "false");
446 }
447 
449 {
450  /* Get credentials */
451  string uid = root[RequestField::Uid].asString();
452  string path = root[RequestField::Path].asString();
453  /* Get groups */
454  set<string> groups = m_userMap[uid]->getGroups();
455  /* Save */
456  if (m_operation->saveProperties(groups, root[RequestField::Property].toStyledString(), path) != ErrorCode::Failure)
457  return send(sock, RequestField::Success);
458  return Failure;
459 }
460 
462 {
463  /* Get credentials */
464  string uid = root[RequestField::Uid].asString();
465  string path = root[RequestField::Path].asString();
466  string section = root[RequestField::Section].asString();
467  string key = root[RequestField::Key].asString();
468  string value = root[RequestField::Value].asString();
469  /* get groups */
470  set<string> groups = m_userMap[uid]->getGroups();
471  /* Save */
472  if (m_operation->saveProperty(groups, path, section, key, value) != ErrorCode::Failure)
473  return send(sock, RequestField::Success);
474  return Failure;
475 }
476 
477 
479 {
480  /* Get credentials */
481  string uid = root[RequestField::Uid].asString();
482  string path = root[RequestField::Path].asString();
483  int type = root[RequestField::NodeType].asInt();
484  /* Get groups */
485  set<string> groups = m_userMap[uid]->getGroups();
486  /* Create node */
487  if (m_operation->createNode(groups, uid, path, type) == ErrorCode::Failure)
488  return Failure;
489  return send(sock, RequestField::Success);
490 }
491 
493 {
494  /* Get credentials */
495  string uid = root[RequestField::Uid].asString();
496  string path = root[RequestField::Path].asString();
497  /* Get groups */
498  set<string> groups = m_userMap[uid]->getGroups();
499  /* delete node */
500  if (m_operation->deleteNode(groups, uid, path) == ErrorCode::Failure)
501  return Failure;
502  return send(sock, RequestField::Success);
503 }
504 
506 {
507  /* Get credentials */
508  string uid = root[RequestField::Uid].asString();
509  string path = root[RequestField::Path].asString();
510  string newPath = root[RequestField::NewPath].asString();
511  /* Get groups */
512  set<string> groups = m_userMap[uid]->getGroups();
513  /* rename node */
514  if (m_operation->renameNode(groups, uid, path, newPath) == ErrorCode::Failure)
515  return Failure;
516  return send(sock, RequestField::Success);
517 }
518 
520 {
521  /* Get credentials */
522  string uid = root[RequestField::Uid].asString();
523  string path = root[RequestField::Path].asString();
524  /* Get groups */
525  set<string> groups = m_userMap[uid]->getGroups();
526  int ret = m_operation->getLock(groups, uid, path);
527  string rs = boost::lexical_cast<string>(ret);
528  return send(sock, rs);
529 }
530 
532 {
533  /* Get credentials */
534  string uid = root[RequestField::Uid].asString();
535  string path = root[RequestField::Path].asString();
536  /* Get groups */
537  set<string> groups = m_userMap[uid]->getGroups();
538  int ret = m_operation->putLock(groups, uid, path);
539  string rs = boost::lexical_cast<string>(ret);
540  return send(sock, rs);
541 }
542 
544 {
545  string uid = root[RequestField::Uid].asString();
546  string path = root[RequestField::Path].asString();
547  /* Get groups */
548  set<string> groups = m_userMap[uid]->getGroups();
549  std::string id = "";
550  int ret = m_operation->isLocked(groups, uid, path, id);
551  Value answer;
552  answer[RequestField::Value] = ret;
553  answer[RequestField::Uid] = id;
554  return send(sock, answer.toStyledString());
555 }
556 
558 {
559  /* Get credentials */
560  string uid = root[RequestField::Uid].asString();
561  /* get rootPath */
562  string rootPath = m_operation->getRootPath();
563  return send(sock, rootPath);
564 }
565 
567 {
568  /* Get credentials */
569  string uid = root[RequestField::Uid].asString();
570  string version = m_operation->getFsTreeStamp();
571  return send(sock, version);
572 }
573 
574 string WsFsDaemon::rawDataToString(zmq::message_t& msg)
575 {
576  string ret;
577  if (m_compress) {
578  m_decompressor->decompress(static_cast<char*>(msg.data()), msg.size(), ret);
579  } else ret = string(static_cast<char*>(msg.data()), msg.size());
580  return ret;
581 }
582 
583 bool WsFsDaemon::isActiveSession(const std::string& uid, const std::string& pass, const std::string& ip)
584 {
585  if ( m_userMap.count(uid) > 0)
586  return m_userMap[uid]->isValidSession(uid, pass, ip);
587  return false;
588 }
Reprensents a User session.
Definition: WsUserSession.h:27
Serializes an array.
DaemonStatus handlePermRequest(zmq::socket_t &sock, Json::Value &root)
sends the permissions of a path to the client
Definition: WsFsDaemon.cpp:333
void setSurname(const std::string &surname)
set the surname of the user
Reprensents the menu tree of a group. If a group does not have access to a Node, this Node will not s...
int putLock(const std::set< std::string > groups, const std::string &uid, const std::string &path)
unlocks the file by deleting the .config/locks/filename.lock file Only the owner of the lock can unlo...
RequestType enum variables.
DaemonStatus bind(unsigned int numWorkers=1)
start listening on the port
Definition: WsFsDaemon.cpp:83
const std::string Surname
Definition: WsRequestType.h:24
WsGlobalProperties * m_conf
Definition: WsFsDaemon.h:261
const std::string Path
Definition: WsRequestType.h:28
std::string getProperty(const std::set< std::string > &groups, const std::string &section, const std::string &p, const std::string &prop)
get a property for a node corresponding to the path
std::string getUid()
return the user uid WsAuthenticator::authentify must be called before
map< string, WsUserSession * > m_userMap
Definition: WsFsDaemon.h:276
#define DEBUG
Definition: WsLogger.h:27
void setName(const std::string &name)
set the name of the user
std::string getSurname()
return the user surname WsAuthenticator::authentify must be called before
DaemonStatus handleRenameNodeRequest(zmq::socket_t &sock, Json::Value &root)
rename a node
Definition: WsFsDaemon.cpp:505
Global properties class.
string rawDataToString(zmq::message_t &msg)
converts raw data received on the socket to string
Definition: WsFsDaemon.cpp:574
int saveProperty(const std::set< std::string > &groups, const std::string &path, const std::string &section, const std::string &attr, const std::string &val)
save a property of the node. The user must have access and edit rights for the node.
DaemonStatus parse(const std::string &s, Json::Value &root)
Parses the received data (json)
Definition: WsFsDaemon.cpp:177
int saveProperties(const std::set< std::string > &groups, const std::string &json, const std::string &path)
save the properties of the node. The user must have access and edit rights for the node...
DaemonStatus handleCreateNodeRequest(zmq::socket_t &sock, Json::Value &root)
create a node requested by the client
Definition: WsFsDaemon.cpp:478
Serializes the array.
const int Failure
bool isActiveSession(const std::string &uid, const std::string &pass, const std::string &ip)
returns true or false whether the section of a user is still active or not
Definition: WsFsDaemon.cpp:583
std::string getEmail()
return the user email WsAuthenticator::authentify must be called before
const std::string NodeType
Definition: WsRequestType.h:40
WsDecompressor * m_decompressor
Definition: WsFsDaemon.h:296
~WsFsDaemon()
destructor
Definition: WsFsDaemon.cpp:40
Redirect operations to adequate class.
Reprensents an access tree.
Definition: WsAccessTree.h:24
DaemonStatus handleSavePropertiesRequest(zmq::socket_t &sock, Json::Value &root)
saves the properties received by the client for a node
Definition: WsFsDaemon.cpp:448
Loads Authentification module and acts as an interface.
Serializes a tree (WsAccessTree, WsMenuTree).
Properties of a WsNode.
Used to compress data.
Definition: WsCompressor.h:24
DaemonStatus receive(zmq::socket_t &sock, std::string &receivedData)
read data from the socket
Definition: WsFsDaemon.cpp:160
const std::string Pass
Definition: WsRequestType.h:22
WsAccessTree * getAccessTree(const std::set< std::string > &groups)
Get the access tree starting from rootPath.
WsFsTreeOperations * m_operation
Definition: WsFsDaemon.h:271
const std::string & getName()
bool m_listening
Definition: WsFsDaemon.h:266
DaemonStatus handleIsLockedRequest(zmq::socket_t &sock, Json::Value &root)
checks the lock for the path
Definition: WsFsDaemon.cpp:543
void setGroups(const std::set< std::string > &groups)
sets the groups of a user
const std::string ModifyDate
Definition: WsRequestType.h:37
Used to decompress data.
std::vector< WsResultItem > getSearchResults(const std::set< std::string > &groups, const std::string &terms)
Get the results for searching for "terms".
const std::string Email
Definition: WsRequestType.h:25
zmq::context_t * m_context
Definition: WsFsDaemon.h:298
int renameNode(const std::set< std::string > &groups, const std::string &uid, const string &path, const string &newPath)
renames a node
const std::string NewPath
Definition: WsRequestType.h:31
DaemonStatus send(zmq::socket_t &sock, const std::string &s)
Sends data on the socket.
Definition: WsFsDaemon.cpp:120
int getLock(const std::set< std::string > groups, const std::string &uid, const std::string &path)
tries to acquire the lock for the path. @ return ErrorCode::Locked if the lock cannot be aquired beca...
const std::string Section
Definition: WsRequestType.h:29
WsNodeProperties * getProperties(const std::set< std::string > &groups, const std::string &p)
get properties of a node corresponding to the path
const std::string & getEmail()
const std::string getSerializedForm()
returns the serailized form of the directory
#define LOG
Definition: WsLogger.h:22
DaemonStatus handleSavePropertyRequest(zmq::socket_t &sock, Json::Value &root)
saves one property received by a client for a node
Definition: WsFsDaemon.cpp:461
Json::Value getRoot()
Return the root of the Json tree.
int getPermissions(const std::set< std::string > &groups, const std::string &p)
Get the permissions for a path for a set of groups.
int serialize()
serialize the given data structur
void setEmail(const std::string &email)
set the email of the user
DaemonStatus handlePropsRequest(zmq::socket_t &sock, Json::Value &root)
sends all the properties of a node
Definition: WsFsDaemon.cpp:358
const std::string Size
Definition: WsRequestType.h:36
#define INFO
Definition: WsLogger.h:32
DaemonStatus handleGetTreeVersion(zmq::socket_t &sock, Json::Value &root)
sends the last tree version to the client
Definition: WsFsDaemon.cpp:566
DaemonStatus handlePutLockRequest(zmq::socket_t &sock, Json::Value &root)
releases the lock for the path
Definition: WsFsDaemon.cpp:531
Serialize the menuTree to send it over network.
int deleteNode(const std::set< std::string > &groups, const std::string &uid, const string &path)
delete a node. The user must be an Admin on editor to remove the node
long decompress(const char *data, size_t size, std::string &uncompressedData)
decompress the input data and store result in uncompressedData
WsFsDaemon(WsGlobalProperties *props)
constructor for the server
Definition: WsFsDaemon.cpp:28
int isLocked(const std::set< std::string > groups, const std::string &uid, const std::string &path, std::string &id)
check is the path is already locked
const std::string Type
Definition: WsRequestType.h:19
const std::string Uid
Definition: WsRequestType.h:20
std::set< std::string > getUserGroups()
return the user groups WsAuthenticator::authentify must be called before
long compress(const std::string &data, char **compressedData)
compress the input string (data) and puts it in compressedData.
std::set< std::string > getAllGroups()
return all the possible groups WsAuthenticator::authentify must be called before
bool isAdministrator(const std::set< std::string > &groups)
const std::string & getFsTreeStamp()
Get the stamp of the last WsFileSystemTree.
std::string get(const std::string &section, const std::string &id, const std::string &def)
const std::string Value
Definition: WsRequestType.h:39
DaemonStatus handleGetLockRequest(zmq::socket_t &sock, Json::Value &root)
Acquires the lock for the path.
Definition: WsFsDaemon.cpp:519
DaemonStatus handlePropRequest(zmq::socket_t &sock, Json::Value &root)
sends a property of a node to the client
Definition: WsFsDaemon.cpp:374
const std::string getRootPath()
WsCompressor * m_compressor
Definition: WsFsDaemon.h:291
const std::string Ip
Definition: WsRequestType.h:21
DaemonStatus handleAuthRequest(zmq::socket_t &sock, Json::Value &root)
Authenticate user on server Loads the groups which the user belongs to, uid, email, etc..
Definition: WsFsDaemon.cpp:274
const std::string & getSurname()
const std::string getSerializedForm()
returns the Json text representing the given structure
const std::string Body
Definition: WsRequestType.h:35
set< string > m_allGroups
Definition: WsFsDaemon.h:281
DaemonStatus handleAccessTreeRequest(zmq::socket_t &sock, Json::Value &root)
Sends the accesstree to the client.
Definition: WsFsDaemon.cpp:316
static WsLogWriter * instance()
returns the instance of the WsLogWriter class. If no instance is existing, a new instance will be ret...
Definition: WsLogWriter.cpp:26
bool isEditor(const std::set< std::string > &groups)
const std::string Name
Definition: WsRequestType.h:23
int authentify(const std::string &uid, const std::string &pass="", const std::string &ip="")
authentify the user.
DaemonStatus handleRootPathRequest(zmq::socket_t &sock, Json::Value &root)
send the rootPath to the client
Definition: WsFsDaemon.cpp:557
const std::string Success
Definition: WsRequestType.h:32
const std::string Key
Definition: WsRequestType.h:38
Take charge of FS operations.
DaemonStatus workerRoutine()
Definition: WsFsDaemon.cpp:48
const std::string Failure
Definition: WsRequestType.h:33
const std::string Property
Definition: WsRequestType.h:30
std::string getFirstName()
return the user name WsAuthenticator::authentify must be called before
int createNode(const std::set< std::string > &groups, const std::string &uid, const string &path, int type)
create a directory or File. If the node is a WsDirNode than it will be only accessible to the Admin a...
DaemonStatus handleIsAdminRequest(zmq::socket_t &sock, Json::Value &root)
sends the result of an admin request so that the client can know if he is an admin or not ...
Definition: WsFsDaemon.cpp:435
#define ERROR
Definition: WsLogger.h:42
DaemonStatus handleClearCache(zmq::socket_t &sock, Json::Value &root)
clears the user from the cache
Definition: WsFsDaemon.cpp:412
bool m_compress
Definition: WsFsDaemon.h:286
DaemonStatus handleSearchRequest(zmq::socket_t &sock, Json::Value &root)
sends the result of a search request to the client. Only nodes where the user has access are returned...
Definition: WsFsDaemon.cpp:389
DaemonStatus handleAllGroupsRequest(zmq::socket_t &sock, Json::Value &root)
sends all the groups available to the client
Definition: WsFsDaemon.cpp:347
DaemonStatus handleRequest(zmq::socket_t &sock, Json::Value &root)
Handle received request and redirect to correct method.
Definition: WsFsDaemon.cpp:189
DaemonStatus handleIsEditorRequest(zmq::socket_t &sock, Json::Value &root)
sends the result of an editor request so that the client can know if he is an editor or not ...
Definition: WsFsDaemon.cpp:422
int update()
Update the WsFileSystemTree.
DaemonStatus handleDeleteNodeRequest(zmq::socket_t &sock, Json::Value &root)
delete a node requested by the client
Definition: WsFsDaemon.cpp:492
const std::string Terms
Definition: WsRequestType.h:34