-
Notifications
You must be signed in to change notification settings - Fork 0
/
safeapi.h
186 lines (166 loc) · 7.11 KB
/
safeapi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#ifndef SAFEAPI_H
#define SAFEAPI_H
#include <QObject>
#include <QtMath>
#include <QMutex>
#include "safeworker.h"
#include "safecalls.h"
#include "safeerrors.h"
#include "safetypes.h"
class SafeApi : public QObject
{
Q_OBJECT
public:
SafeApi(QString host, QObject *parent = 0);
~SafeApi();
void setState(SafeApiState state) { this->apiState = state; }
SafeApiState state() { return this->apiState; }
signals:
void errorRaised(ulong id, quint16 code, QString text);
/* USER */
void getCaptchaComplete(ulong id, SafeCaptcha captcha);
void checkEmailComplete(ulong id, bool available);
void checkLoginComplete(ulong id, bool available);
void registerUserComplete(ulong id);
void unregisterUserComplete(ulong id, QString login, QString user_id);
void authUserComplete(ulong id, QString user_id);
void logoutUserComplete(ulong id);
void getDiskQuotaComplete(ulong id, ulong used_bytes, ulong total_bytes);
void getPersonalComplete(ulong id, QJsonObject personal, QJsonObject props);
void setPersonalComplete(ulong id);
void changePasswordComplete(ulong id);
void activatePromoComplete(ulong id, ulong used_bytes, ulong total_bytes, ulong added);
/* FILESYSTEM */
void pullFileProgress(ulong id, ulong bytes, ulong total_bytes);
void pullFileComplete(ulong id);
void pushFileProgress(ulong id, ulong bytes, ulong total_bytes);
void pushFileComplete(ulong id, SafeFile file_info);
void copyFileComplete(ulong id, ulong file_id);
void moveFileComplete(ulong id, ulong file_id);
void removeFileComplete(ulong id);
void makeDirComplete(ulong id, ulong dir_id);
void copyDirComplete(ulong id);
void moveDirComplete(ulong id);
void listDirComplete(ulong id, QList<SafeDir> dirs,
QList<SafeFile> files,
QJsonObject root_info);
void removeDirComplete(ulong id);
void getPropsComplete(ulong id, QJsonObject props);
void setPropsComplete(ulong id);
void getParentTreeComplete(ulong id, QJsonArray tree);
void getEventsComplete(ulong id, QJsonArray events);
void purgeTrashComplete(ulong id);
/* LOCKS */
void lockObjectComplete(ulong id, QString lock_token);
void unlockObjectComplete(ulong id);
void listLocksComplete(ulong id, QJsonArray locks);
void refreshLockComplete(ulong id, QJsonObject userdata, bool exclusive);
/* SHARES */
void shareObjectComplete(ulong id);
void unshareObjectComplete(ulong id);
void unshareAllComplete(ulong id);
void listSharesComplete(ulong id, QJsonArray shares);
void publicObjectComplete(ulong id, QString link);
void unpublicObjectComplete(ulong id);
/* VERSIONS */
void listVersionsComplete(ulong id, QJsonArray versions,
QString current,
QString file_id);
void getVersionComplete(ulong id, QString current);
void setVersionComplete(ulong id);
void removeVersionComplete(ulong id);
void setVersionControlComplete(ulong id);
public slots:
void freeWorker(ulong worker_id);
void freeFileWorker(ulong worker_id);
void clearState();
/* USER */
ulong getCaptcha();
ulong checkEmail(QString email);
ulong checkLogin(QString login);
ulong registerUser(QString login, QString password, QString user_captcha, SafeCaptcha captcha);
ulong unregisterUser(QString login, QString password);
ulong authUser(QString login, QString password);
ulong authUserCaptcha(QString login, QString password, QString user_captcha, SafeCaptcha captcha);
ulong logoutUser();
ulong getDiskQuota();
ulong getPersonal();
ulong setPersonal(QJsonDocument personal, QJsonDocument props);
ulong setPersonalEmail(QJsonDocument personal, QJsonDocument props, QString password);
ulong changePassword(QString login, QString password, QString new_password);
ulong activatePromo(QString code);
/* FILESYSTEM */
ulong pullFile(QString file_id, QString path, ulong size = 0, ulong offset = 0);
ulong pushFile(QString dst_dir_id, QString path, QString file_name,
bool overwrite = false, bool versioned = false,
QJsonDocument props = QJsonDocument(),
ulong ctime = 0, ulong mtime = 0);
ulong copyFile(QString file_id, QString dst_dir_id,
QString file_name = QString(),
bool overwrite = false, bool versioned = false);
ulong moveFile(QString file_id, QString dst_dir_id,
QString file_name = QString(),
bool overwrite = false, bool versioned = false);
ulong removeFile(QString file_id, bool now = false);
ulong makeDir(QString parent_dir_id, QString dir_name,
QJsonDocument props = QJsonDocument(),
ulong ctime = 0, ulong mtime = 0);
ulong copyDir(QString src_dir_id, QString dst_dir_id,
QString dir_name = QString(),
bool overwrite = false, bool versioned = false);
ulong moveDir(QString src_dir_id, QString dst_dir_id,
QString dir_name = QString(),
bool overwrite = false, bool versioned = false);
ulong removeDir(QString dir_id, bool recursive = false, bool now = false);
ulong listDir(QString dir_id = QString());
ulong getProps(QString id_or_url, bool is_url = false);
ulong setProps(QString object_id, QJsonDocument props);
ulong getParentTree(QString dir_id);
ulong getEvents(ulong after, bool last = false);
ulong purgeTrash();
/* LOCKS */
ulong lockObject(QString id, ulong timeout = 0,
bool exclusive = false,
QJsonObject userdata = QJsonObject());
ulong unlockObject(QString lock_token);
ulong listLocks(QString id);
ulong refreshLock(QString lock_token, ulong timeout);
/* SHARES */
ulong shareObject(QString id, QString login,
bool writable = false, ulong expires = 0);
ulong unshareObject(QString id, QString login);
ulong unshareAll(QString id);
ulong listShares(QString id);
ulong publicObject(QString id, ulong expires = 0);
ulong unpublicObject(QString id);
/* VERSIONS */
ulong listVersions(QString id);
ulong getVersion(QString id);
ulong setVersion(QString id, QString version_id);
ulong removeVersion(QString id);
ulong setVersionControl(QString id, bool enabled);
private slots:
void networkError(const QString& text);
private:
ulong ticker;
QString host;
int maxThreads;
int maxFileThreads;
QMutex mutex;
QHash<ulong, SafeWorker*> workersPool;
QQueue<SafeWorker*> workersQueue;
QHash<ulong, SafeWorker*> fileWorkersPool;
QQueue<SafeWorker*> fileWorkersQueue;
/* shared state */
SafeApiState apiState;
/* methods */
SafeWorker *createWorker(QString cmd);
SafeWorker *createFileWorker(QString cmd);
void routeWorker(SafeWorker *worker);
void routeFileWorker(SafeWorker *worker);
void processWorkersQueue();
void processFileWorkersQueue();
bool reportError(ulong id, const QJsonDocument& response);
ulong getId();
};
#endif // SAFEAPI_H