iberbox  2.1.2
action.h
Go to the documentation of this file.
1 
10 #ifndef ACTION_H
11 #define ACTION_H
12 
13 #include "iberbox/config.h"
14 #include "iberbox/ownership.h"
15 #include "iberbox/error.h"
16 #include "iberbox/node.h"
17 #include "iberbox/transfer.h"
18 #include "iberbox/payments.h"
19 #include "iberbox/account.h"
20 #include "iberbox/user.h"
21 
22 #include <memory>
23 #include <functional>
24 #include <mutex>
25 #include <condition_variable>
26 
27 #ifdef USE_SCAPIX
28 #include <scapix/bridge/object.h>
29 #endif
30 
31 namespace iberbox {
32 
33 class ActionData;
34 typedef std::shared_ptr<ActionData> Action;
35 typedef std::vector<Action> ActionDataList;
36 typedef std::shared_ptr<ActionDataList> ActionList;
37 
42 #ifdef USE_SCAPIX
43  : public scapix::bridge::object<ActionData>
44 #endif
45 {
46 public:
51  {
52  TEST,
164  };
165 
171  {
175  };
176 
183  static const char *getTypeName(unsigned type)
184  {
185  static const char *sActionNames[] =
186  {
187  "TEST",
188  "ADD_CONTACT",
189  "VERIFY_EMAIL",
190  "FORGOT_PASSWORD",
191  "CREATE_ACCOUNT",
192  "CHANGE_PASSWORD",
193  "RECOVERY_KEY",
194  "MANAGE_2FA",
195  "LOGIN",
196  "GET_NODES",
197  "GET_ROOT",
198  "GET_CHILDREN",
199  "GET_NODE",
200  "GET_PATH",
201  "ADD_NODES",
202  "DELETE_NODE",
203  "RENAME_NODE",
204  "MOVE_NODE",
205  "COPY_NODE",
206  "CREATE_LINK",
207  "GET_LINK_INFO",
208  "USER_INFO",
209  "ACCOUNT_INFO",
210  "LOG_EVENT",
211  "TEST_PROXY",
212  "SET_PROXY",
213  "UPLOAD",
214  "DOWNLOAD",
215  "DOWNLOAD_ZIP",
216  "STREAM",
217  "BACKUP",
218  "UPLOAD_METADATA",
219  "DOWNLOAD_METADATA",
220  "GET_TRANSFERS",
221  "CLEAR_FINISHED_TRANSFERS",
222  "CANCEL_TRANSFERS",
223  "SET_TRANSFER_SPEED_LIMIT",
224  "GET_TRANSFER_SPEED_LIMIT",
225  "REGISTER_DEVICE",
226  "SELECT_DEVICE",
227  "GET_CURRENT_DEVICE",
228  "GET_DEVICE",
229  "GET_DEVICES",
230  "RENAME_DEVICE",
231  "DELETE_DEVICE",
232  "GET_BACKUP",
233  "GET_BACKUPS",
234  "CREATE_BACKUP",
235  "MODIFY_BACKUP",
236  "RENAME_BACKUP",
237  "CHANGE_BACKUP_SCHEDULE",
238  "CHANGE_BACKUP_PATH",
239  "CHANGE_BACKUP_STATUS",
240  "DELETE_BACKUP",
241  "AUTHORIZE_BACKUP",
242  "GET_SNAPSHOTS",
243  "GET_NEXT_SNAPSHOTS",
244  "GET_NEXT_SNAPSHOTS_BY_DEVICE",
245  "GET_NEXT_SNAPSHOTS_BY_BACKUP",
246  "GET_NEXT_SNAPSHOTS_BY_ACCOUNT",
247  "GET_NEXT_SNAPSHOTS_BY_SCHEDULE",
248  "GET_LAST_SNAPSHOTS",
249  "GET_LAST_SNAPSHOTS_BY_DEVICE",
250  "GET_LAST_SNAPSHOTS_BY_BACKUP",
251  "GET_LAST_SNAPSHOTS_BY_ACCOUNT",
252  "CREATE_INBOX",
253  "SET_INBOX_INFO",
254  "GET_INBOX_INFO",
255  "LOGIN_LINK",
256  "SET_RECORD_INFO",
257  "UPLOAD_TO_RECORD",
258  "REMOVE_FROM_RECORD",
259  "GET_RECORD_INFO",
260  "SET_RECORD_STATUS",
261  "SUBSCRIPTION_OPTIONS",
262  "PAYMENT_INFO",
263  "REMOVE_PAYMENT_METHOD",
264  "SET_INVOICING_ADDRESS",
265  "INVOICING_INFO",
266  "GET_INVOICE",
267  "SESSION_INFO",
268  "LOGOUT_LINK",
269  "CRASH_REPORT",
270  "UPDATE",
271  "LOGOUT",
272  "CURRENT_EMAIL",
273  "NEW_SESSION",
274  "DESTROY",
275  "REFERRALS_INFO",
276  "BALANCES_INFO",
277  "COUPONS",
278  "ADD_PAYMENT_METHOD",
279  "JOIN_LINK",
280  "DEFAULT_ACCOUNT",
281  "REVOKE_ACCOUNT_ACCESS",
282  "MANAGE_SECRETS",
283  "MANAGE_CONTACTS",
284  "MANAGE_OUTBOXES",
285  "MANAGE_SENT_RECORDS",
286  "GET_NODE_TREE",
287  "SET_ACCOUNT_VALUE",
288  "DELETE_ACCOUNT",
289  "SET_ACCESS_LEVEL",
290  "MANAGE_SHARED_DRIVES",
291  "DELETE_LINK",
292  "MANAGE_MEETINGS",
293  "MANAGE_NODE_TAG",
294  "GET_COMMANDS_LOG",
295  "VERIFY_HASH",
296  "NOTICE_CREDENTIALS",
297  "MANAGE_FOLDER_SYNC",
298  };
299  static_assert((sizeof(sActionNames) / sizeof(sActionNames[0]) == ActionData::LAST), "Invalid number of action names");
300  return type < ActionData::LAST ? sActionNames[type] : "INVALID";
301  }
302 
309  static const std::string getTypeNameString(unsigned type)
310  {
311  return getTypeName(type);
312  }
313 
314  virtual ~ActionData();
315 
321  int getLocalTag() const;
327  int getType() const;
332  int getTag() const;
337  const char *getActionName() const;
342  const std::string getActionNameString() const;
347  const char *getEmail() const;
352  const std::string getEmailString() const;
357  const char *getPassword() const;
362  const std::string getPasswordString() const;
367  const char *getText() const;
372  const std::string getTextString() const;
377  const char *getSession() const;
382  const std::string getSessionString() const;
387  const char *getName() const;
392  const std::string getNameString() const;
397  const char *getLastName() const;
402  const std::string getLastNameString() const;
407  const char *getLink() const;
412  const std::string getLinkString() const;
418  bool isProcessed() const;
424  bool isFinished() const;
425 
430  int getIntValue() const;
435  int getStatus() const;
440  long getLongValue() const;
445  uint64_t getTotalSize() const;
450  uint64_t getCompletedSize() const;
455  uint64_t getAccountId() const;
465  const std::string getAccountStringHandle() const;
470  uint64_t getUserId() const;
475  Node getNode() const;
480  NodeList getNodeList() const;
485  Transfer getTransfer() const;
490  uint64_t getNodeId() const;
495  NodeHandle getNodeHandle() const;
500  uint64_t getParentId() const;
505  NumberList getNumberList() const;
510  StringList getStringList() const;
520  ActionList getActionList() const;
530  PaymentInfo getPaymentInfo() const;
535  AccountInfo getAccountInfo() const;
540  UserInfo getUserInfo() const;
565  CouponInfoList getCoupons() const;
570  CouponInfo getCoupon() const;
585  CommandLogList getLog() const;
590  std::vector<uint8_t> *getData();
595  int getErrorType() const;
600  const char *getErrorName() const;
605  const std::string getErrorNameString() const;
606 
611  const std::string getCustomData() const;
612 
613 #ifndef USE_SCAPIX
614 
618  Error getError() const;
619 #endif
620 
621 #ifndef EMSCRIPTEN
622 protected:
623 #endif
624 
625  ActionData(int type);
626 
627  int mLocalTag;
628  int mType;
629  int mTag;
630  char *mEmail;
631  char *mPassword;
632  char *mText;
633  char *mSession;
634  char *mName;
635  char *mLastName;
636  char *mLink;
637  bool mFinished;
638  bool mProcessed;
639  Error mError;
640 
641  int mIntValue;
642  int mStatus;
643  long mLongValue;
644  uint64_t mTotalSize;
645  uint64_t mCompletedSize;
646  uint64_t mAccountId;
647  std::string mAccountHandle;
648  uint64_t mUserId;
649  std::string mUserHandle;
650 
651  Node mNode;
652  NodeList mNodeList;
653  uint64_t mNodeId;
654  uint64_t mParentId;
655  std::string mNodeHandle;
656  std::string mParentHandle;
657  Transfer mTransfer;
658  std::vector<uint8_t> mData;
659 
660  NumberList mNumberList;
661  StringList mStringList;
662  TransferList mTransferList;
663  ActionList mActionList;
664  SubscriptionInfoList mSubscriptionInfoList;
665  PaymentInfo mPaymentInfo;
666  AccountInfo mAccountInfo;
667  UserInfo mUserInfo;
668  InvoicingInfo mInvoicingInfo;
669  SessionInfoList mActiveSessionInfoList;
670  SessionInfoList mInactiveSessionInfoList;
671  BalancesInfo mBalancesInfo;
672  CouponInfo mCouponInfo;
673  CouponInfoList mCouponInfoList;
674  PermissionInfoList mAccountPermissionInfoList;
675  PermissionInfoList mUserPermissionInfoList;
676  CommandLogList mCommandLogList;
677  std::string mCustomData;
678 };
679 
683 class ActionListener : public SharedOwnership
684 #ifdef USE_SCAPIX
685  , public scapix::bridge::object<ActionListener>
686 #endif
687 {
688 public:
692  ActionListener();
697  ActionListener(std::function<void(Action)> finishCallback);
698  ActionListener(std::function<void(Action)> progressCallback, std::function<void(Action)> finishCallback);
699  ActionListener(std::function<void(Action)> errorCallback, std::function<void(Action)> progressCallback, std::function<void(Action)> finishCallback);
700  ActionListener(std::function<void(Action)> startCallback, std::function<void(Action)> errorCallback, std::function<void(Action)> progressCallback, std::function<void(Action)> finishCallback);
701 
702  virtual ~ActionListener();
703 
704  void setStartCallback(std::function<void(Action)> startCallback);
705  void setErrorCallback(std::function<void(Action)> errorCallback);
706  void setProgressCallback(std::function<void(Action)> progressCallback);
707  void setFinishCallback(std::function<void(Action)> finishCallback);
708 
713  virtual void onActionStart(Action action);
718  virtual void onActionProcessed(Action action);
723  virtual void onActionProgress(Action action);
728  virtual void onActionError(Action action);
733  virtual void onActionFinish(Action action);
734 
735 protected:
736  std::function<void(Action)> mStartCallback;
737  std::function<void(Action)> mProgressCallback;
738  std::function<void(Action)> mFinishCallback;
739  std::function<void(Action)> mErrorCallback;
740 };
741 
746 {
747 public:
757  virtual ~BlockingActionListener() override;
758 
763  virtual void onActionFinish(Action action) override;
768  virtual void onActionProgress(Action action) override;
774  virtual void setOwnership(bool external_or_cpp) override;
779  Action getResult();
780 
781 protected:
782  Action mAction;
783  bool mOwnMemory;
784 
785 #ifndef EMSCRIPTEN
786  std::condition_variable mConditionVariable;
787  std::mutex mMutex;
788 #endif
789 };
790 
791 #ifdef USE_SCAPIX
792 typedef std::shared_ptr<ActionListener> ActionListenerType;
793 #else
795 #endif
796 
797 }
798 
799 #define MODIFY_ATTRIBUTES(NodeVarName) \
800  mApiManager->mCloudCache->encryptNode(NodeVarName, [this, action, NodeVarName](EncryptedNode encryptedNode) \
801  { \
802  action->setEncryptedAttributes(new std::vector<uint8_t>(*encryptedNode->getEncryptedAttributes())); \
803  action->setNode(NodeVarName); \
804  action->setIntValue(NodeVarName->getExtraNumber()); \
805  notifyProcessed(action); \
806  mApiManager->processApiRequest(std::make_shared<RenameNodeRequest>(action, mApiManager->getClientId()), this); \
807  }); \
808 
809 #endif // ACTION_H
810 
std::shared_ptr< CouponInfoDataList > CouponInfoList
Definition: account.h:340
uint64_t getNodeId() const
Gets the node identifier.
StringList getStringList() const
Gets the string list.
Definition: action.h:85
Definition: action.h:101
Definition: action.h:79
Definition: action.h:136
std::shared_ptr< BalancesInfoData > BalancesInfo
Definition: account.h:305
Transfer getTransfer() const
Gets the transfer.
Change password action.
Definition: action.h:57
The Blocking Action Listener class.
Definition: action.h:745
Copy node action.
Definition: action.h:70
SessionInfoList getActiveSessions() const
Gets the active sessions.
Definition: action.h:96
Get node action.
Definition: action.h:64
const char * getActionName() const
Gets the name of the action.
Error getError() const
Gets the error.
Definition: action.h:117
uint64_t getParentId() const
Gets the parent node identifier.
Definition: action.h:153
const std::string getTextString() const
Gets the text.
std::shared_ptr< CommandLogDataList > CommandLogList
Definition: account.h:400
The iberbox namespace.
Definition: task.h:21
Definition: action.h:99
Definition: action.h:133
Get nodes action.
Definition: action.h:61
Get the tree of descendants of a node.
Definition: action.h:151
Definition: action.h:121
int getIntValue() const
Gets the int value.
Definition: action.h:118
Definition: action.h:141
uint64_t getAccountId() const
Gets the account identifier.
std::shared_ptr< InvoicingInfoData > InvoicingInfo
Definition: payments.h:300
uint64_t getUserId() const
Gets the user identifier.
const char * getSession() const
Gets the session.
Get children action.
Definition: action.h:63
Account info actions.
Definition: action.h:74
CommandLogList getLog() const
Gets the commands log for the current account.
Test action.
Definition: action.h:52
const char * getLink() const
Gets the link.
ActionListener * ActionListenerType
Definition: action.h:794
uint64_t NodeHandle
Definition: node.h:26
const char * getPassword() const
Gets the password.
Definition: action.h:131
CouponInfoList getCoupons() const
Gets the coupons.
bool isFinished() const
Gets whether the action is finished or not.
NodeList getNodeList() const
Gets the node list.
const std::string getCustomData() const
Get custom data set by the app.
Add contact action.
Definition: action.h:53
Definition: action.h:124
const std::string getAccountStringHandle() const
Gets the account string handle.
PermissionInfoList getAccountPermissions() const
Gets the permissions a user has in every joined account.
const char * getLastName() const
Gets the last name.
NodeHandle getNodeHandle() const
Gets the node identifier.
long getLongValue() const
Gets the long value.
std::shared_ptr< AccountInfoData > AccountInfo
Definition: account.h:221
std::shared_ptr< NodeData > Node
Definition: node.h:666
Definition: action.h:163
Move node action.
Definition: action.h:69
Definition: action.h:134
SubscriptionInfoList getSubscriptionInfoList() const
Gets the subscription info list.
std::vector< Action > ActionDataList
Definition: action.h:35
Definition: action.h:138
Manager folder sync flag.
Definition: action.h:162
Delete node action.
Definition: action.h:67
const std::string getActionNameString() const
Gets the name of the action.
Definition: action.h:80
const std::string getPasswordString() const
Gets the password.
Manage secret spaces.
Definition: action.h:147
AccountInfo getAccountInfo() const
Gets the account info.
Definition: action.h:119
The Action Data class.
Definition: action.h:41
TransferList getTransferList() const
Gets the transfer list.
Manage contacts.
Definition: action.h:148
BalancesInfo getBalancesInfo() const
Gets the balances info.
std::shared_ptr< PermissionInfoDataList > PermissionInfoList
Definition: account.h:366
ActionType
The action type enum.
Definition: action.h:50
Forgot password action.
Definition: action.h:55
Definition: action.h:91
const std::string getLinkString() const
Gets the link.
std::vector< uint8_t > * getData()
Gets the data.
Definition: action.h:120
Get path aciton.
Definition: action.h:65
Create and check join links as well as joining an account.
Definition: action.h:144
ActionList getActionList() const
Gets the action list.
std::shared_ptr< PaymentInfoData > PaymentInfo
Definition: payments.h:215
uint64_t getTotalSize() const
Gets the total size.
Definition: action.h:78
Revoke account access.
Definition: action.h:146
std::shared_ptr< NodeDataList > NodeList
Definition: node.h:668
PermissionInfoList getUserPermissions() const
Gets the permissions every joined user has for the current account.
Definition: action.h:81
const std::string getNameString() const
Gets the name.
const std::string getLastNameString() const
Gets the last name.
Manage shared drives.
Definition: action.h:155
const char * getName() const
Gets the name.
std::shared_ptr< TransferData > Transfer
Definition: transfer.h:245
Create link action.
Definition: action.h:71
Definition: action.h:76
InvoicingInfo getInvoicingInfo() const
Gets the invoicing info.
Definition: action.h:82
const char * getText() const
Gets the text.
Definition: action.h:58
Definition: action.h:139
Definition: action.h:135
std::shared_ptr< UserInfoData > UserInfo
The user info type.
Definition: user.h:105
std::shared_ptr< ActionData > Action
Definition: action.h:33
std::shared_ptr< StringVector > StringList
Definition: node.h:674
Definition: action.h:75
bool isProcessed() const
Gets whether the action is processed or not.
Add nodea action.
Definition: action.h:66
Definition: action.h:105
Definition: action.h:127
std::shared_ptr< TransferDataList > TransferList
Definition: transfer.h:247
Definition: action.h:97
Definition: action.h:93
int getTag() const
Gets the Tag object.
int getErrorType() const
Gets the error type.
Get root nodes action.
Definition: action.h:62
Rename node action.
Definition: action.h:68
Node getNode() const
Gets the node.
Manage outboxes.
Definition: action.h:149
const char * getEmail() const
Gets the email.
const char * getErrorName() const
Gets the error name.
Verify email action.
Definition: action.h:54
Definition: action.h:173
const std::string getSessionString() const
Gets the session.
Definition: action.h:137
The error class.
Definition: error.h:25
int getLocalTag() const
Gets the local tag of an action.
Definition: action.h:107
Get link info action.
Definition: action.h:72
Definition: action.h:172
std::shared_ptr< CouponInfoData > CouponInfo
Definition: account.h:338
std::shared_ptr< SessionInfoDataList > SessionInfoList
Definition: account.h:227
Manage sent records.
Definition: action.h:150
CouponInfo getCoupon() const
Gets the coupon.
const std::string getErrorNameString() const
Gets the error name.
Definition: action.h:140
std::shared_ptr< ActionDataList > ActionList
Definition: action.h:36
NumberList getNumberList() const
Gets the number list.
Definition: action.h:60
Definition: action.h:132
Definition: action.h:59
Get notice email credentials.
Definition: action.h:161
PaymentInfo getPaymentInfo() const
Gets the payment info.
Definition: action.h:98
Definition: action.h:94
uint64_t getCompletedSize() const
Gets the completed size.
Definition: action.h:142
static const std::string getTypeNameString(unsigned type)
Gets the event type name.
Definition: action.h:309
Replace default account.
Definition: action.h:145
std::shared_ptr< SubscriptionInfoDataList > SubscriptionInfoList
Definition: payments.h:28
Definition: action.h:100
Manage2faOperation
The manage 2-Factor Authentication operation enum.
Definition: action.h:170
Definition: action.h:157
User info actions.
Definition: action.h:73
int getStatus() const
Gets the status.
static const char * getTypeName(unsigned type)
Gets the event type name.
Definition: action.h:183
The Action Listener class.
Definition: action.h:683
Verify file hash.
Definition: action.h:160
int getType() const
Gets the type of the action.
Create account action.
Definition: action.h:56
NodeHandle getAccountHandle() const
Gets the account handle.
SessionInfoList getInactiveSessions() const
Gets the inactive sessions.
Definition: action.h:130
std::shared_ptr< NumberVector > NumberList
Definition: node.h:671
Get commands log.
Definition: action.h:159
Definition: action.h:158
Definition: action.h:77
const std::string getEmailString() const
Gets the email.
Definition: action.h:95
Definition: action.h:174
UserInfo getUserInfo() const
Gets the user info.
Set a configuration value of the account.
Definition: action.h:152
Definition: action.h:156