-
Notifications
You must be signed in to change notification settings - Fork 42
/
Connector.h
260 lines (222 loc) · 6.21 KB
/
Connector.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#ifndef CONNECTOR_H
#define CONNECTOR_H
#include <wx/wx.h>
#include <string>
#include <vector>
#include <wx/socket.h>
#include <wx/sharedptr.h>
#include "tcpstack.h"
typedef wxLongLong_t int64;
struct SBackupDir
{
wxString path;
wxString name;
int id;
int group;
wxString flags;
int server_default;
};
struct SStatus
{
SStatus()
: pause(false), capa(0), has_server(false),
needs_restore_restart(0), ask_restore_ok(0),
error(false), init(false), restore_file(false),
client(NULL)
{
}
bool isAvailable();
bool hasError();
wxString lastbackupdate;
wxString status;
wxString pcdone;
bool pause;
int capa;
std::string new_server;
bool has_server;
int ask_restore_ok;
bool restore_file;
wxString restore_path;
int needs_restore_restart;
bool init;
wxLongLong starttime;
size_t timeoutms;
wxSocketClient* client;
bool error;
CTCPStack tcpstack;
};
struct SLogEntry
{
int logid;
wxString logtime;
};
struct SLogLine
{
int loglevel;
wxString msg;
};
struct SRunningProcess
{
wxString action;
int percent_done;
wxLongLong_t eta_ms;
wxString details;
int detail_pc;
wxLongLong_t process_id;
bool operator==(const SRunningProcess& other) const
{
return action == other.action
&& percent_done == other.percent_done
&& eta_ms / 1000 / 60 == other.eta_ms / 1000 / 60
&& details == other.details
&& detail_pc == other.detail_pc
&& process_id == other.process_id;
}
};
struct SUrBackupServer
{
bool internet_connection;
wxString name;
bool operator==(const SUrBackupServer& other) const
{
return internet_connection == other.internet_connection
&& name == other.name;
}
};
struct SFinishedProcess
{
SFinishedProcess()
:id(0), success(false)
{
}
bool operator==(const SFinishedProcess& other) const
{
return id == other.id
&& success == other.success;
}
int64 id;
bool success;
};
struct SStatusDetails
{
bool ok;
wxLongLong_t last_backup_time;
std::vector<SRunningProcess> running_processes;
std::vector<SFinishedProcess> finished_processes;
std::vector<SUrBackupServer> servers;
int64 time_since_last_lan_connection;
bool internet_connected;
wxString internet_status;
int capability_bits;
bool operator==(const SStatusDetails& other) const
{
return ok == other.ok
&& last_backup_time == other.last_backup_time
&& running_processes == other.running_processes
&& servers == other.servers
&& time_since_last_lan_connection/1000/60 == other.time_since_last_lan_connection/1000/60
&& internet_connected == other.internet_connected
&& internet_status == other.internet_status
&& capability_bits == other.capability_bits;
}
};
struct SConnection
{
SConnection()
: client(NULL)
{}
wxSocketClient* client;
};
struct SPathMap
{
std::string source;
std::string target;
};
struct SBackupFile
{
int64 access;
int64 creat;
int64 mod;
int backupid;
int64 backuptime;
bool isdir;
std::string name;
std::string shahash;
int64 size;
};
struct SStartRestore
{
SStartRestore()
: ok(false), restore_id(0), status_id(0),
log_id(0), process_id(0) {}
bool ok;
int64 restore_id;
int64 status_id;
int64 log_id;
int64 process_id;
};
class Connector
{
public:
static std::vector<SBackupDir> getSharedPaths(void);
static bool saveSharedPaths(const std::vector<SBackupDir> &res);
static int startBackup(bool full);
static int startImage(bool full);
static bool updateSettings(const std::string &sdata, size_t timeoutms = 5000);
static std::vector<SLogEntry> getLogEntries(void);
static std::vector<SLogLine> getLogdata(int logid, int loglevel);
static bool setPause(bool b_pause);
static bool addNewServer(const std::string &ident);
static SStatusDetails getStatusDetails(SConnection* connection = NULL);
static int getCapabilities();
static bool restoreOk(bool ok, wxLongLong_t& process_id);
static SStatus initStatus(wxSocketClient* last_client, bool fast, size_t timeoutms=5000);
enum EAccessError
{
EAccessError_Ok,
EAccessError_NoServer,
EAccessError_NoTokens
};
static const int64 restore_flag_no_overwrite;
static const int64 restore_flag_no_reboot_overwrite;
static const int64 restore_flag_ignore_overwrite_failures;
static const int64 restore_flag_mapping_is_alternative;
static const int64 restore_flag_open_all_files_first;
static const int64 restore_flag_reboot_overwrite_all;
static std::string getFileBackupsList(EAccessError& access_error);
static std::string getFileList(const std::string& path, int* backupid, EAccessError& access_error);
static SStartRestore startRestore(const std::string& path, int backupid,
const std::vector<SPathMap>& map_paths, EAccessError& access_error, bool clean_other,
bool ignore_other_fs, bool follow_symlinks, int64 restore_flags);
static std::vector<SBackupFile> getFileList(const std::string& path, EAccessError& access_error);
static bool hasError(void);
static bool isBusy(void);
static std::string getPasswordData(bool change_command, bool set_busy);
static std::string getAccessParameters(const std::string& tokens);
private:
static std::string getResponse(const std::string &cmd, const std::string &args, bool change_command, SConnection* connection=NULL, size_t timeoutms=5000, bool set_busy=true);
static bool readTokens();
static std::string pw;
static std::string pw_change;
static bool error;
static bool busy;
static std::string tokens;
};
#endif //CONNECTOR_H