-
Notifications
You must be signed in to change notification settings - Fork 407
/
megacmd.h
205 lines (162 loc) · 5.62 KB
/
megacmd.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
/**
* @file src/megacmd.h
* @brief MEGAcmd: Interactive CLI and service application
*
* (c) 2013 by Mega Limited, Auckland, New Zealand
*
* This file is part of the MEGAcmd.
*
* MEGAcmd 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.
*
* @copyright Simplified (2-clause) BSD License.
*
* You should have received a copy of the license along with this
* program.
*/
#ifndef MEGACMD_H
#define MEGACMD_H
#include <iostream>
#include <iomanip>
#ifdef _WIN32
#include <algorithm>
#endif
using std::cout;
using std::endl;
using std::max;
using std::min;
using std::flush;
using std::left;
using std::cerr;
using std::istringstream;
using std::locale;
using std::stringstream;
using std::exception;
#include "megaapi_impl.h"
#include "megacmd_events.h"
#define PROGRESS_COMPLETE -2
namespace megacmd {
typedef struct sync_struct
{
mega::MegaHandle handle;
bool active;
std::string localpath;
long long fingerprint;
bool loadedok; //ephimeral data
} sync_struct;
typedef struct backup_struct
{
mega::MegaHandle handle;
bool active;
std::string localpath; //TODO: review wether this is local or utf-8 representation and be consistent
int64_t period;
std::string speriod;
int numBackups;
bool failed; //This should mark the failure upon resuming. It shall not be persisted
int tag; //This is depends on execution. should not be persisted
int id; //Internal id for megacmd. Depends on execution should not be persisted
} backup_istruct;
enum prompttype
{
COMMAND, LOGINPASSWORD, NEWPASSWORD, PASSWORDCONFIRM, AREYOUSURETODELETE
};
static const char* const prompts[] =
{
"MEGA CMD> ", "Password:", "New Password:", "Retype New Password:", "Are you sure to delete? "
};
enum
{
MCMD_OK = 0, ///< Everything OK
MCMD_EARGS = -51, ///< Wrong arguments
MCMD_INVALIDEMAIL = -52, ///< Invalid email
MCMD_NOTFOUND = -53, ///< Resource not found
MCMD_INVALIDSTATE = -54, ///< Invalid state
MCMD_INVALIDTYPE = -55, ///< Invalid type
MCMD_NOTPERMITTED = -56, ///< Operation not allowed
MCMD_NOTLOGGEDIN = -57, ///< Needs loging in
MCMD_NOFETCH = -58, ///< Nodes not fetched
MCMD_EUNEXPECTED = -59, ///< Unexpected failure
MCMD_REQCONFIRM = -60, ///< Confirmation required
MCMD_REQSTRING = -61, ///< String required
MCMD_PARTIALOUT = -62, ///< Partial output provided
MCMD_EXISTS = -63, ///< Resource already exists
MCMD_REQRESTART = -71, ///< Restart required
};
enum confirmresponse
{
MCMDCONFIRM_NO=0,
MCMDCONFIRM_YES,
MCMDCONFIRM_ALL,
MCMDCONFIRM_NONE
};
void changeprompt(const char *newprompt);
void informStateListener(std::string message, int clientID);
void broadcastMessage(std::string message, bool keepIfNoListeners = false);
void informStateListeners(std::string s);
void removeDelayedBroadcastMatching(const std::string &toMatch);
void broadcastDelayedMessage(std::string message, bool keepIfNoListeners);
void appendGreetingStatusFirstListener(const std::string &msj);
void removeGreetingStatusFirstListener(const std::string &msj);
void appendGreetingStatusAllListener(const std::string &msj);
void clearGreetingStatusAllListener();
void clearGreetingStatusFirstListener();
void removeGreetingStatusAllListener(const std::string &msj);
void removeGreetingMatching(const std::string &toMatch);
void removeDelayedBroadcastMatching(const std::string &toMatch);
void setloginInAtStartup(bool value);
void setBlocked(int value);
int getBlocked();
void unblock();
bool getloginInAtStartup();
void updatevalidCommands();
void reset();
/**
* @brief A class to ensure clients are properly informed of login in situations
*/
class LoginGuard {
public:
LoginGuard()
{
appendGreetingStatusAllListener(std::string("login:"));
setloginInAtStartup(true);
}
~LoginGuard()
{
removeGreetingStatusAllListener(std::string("login:"));
informStateListeners("loged:"); //send this even when failed!
setloginInAtStartup(false);
}
};
mega::MegaApi* getFreeApiFolder();
void freeApiFolder(mega::MegaApi *apiFolder);
const char * getUsageStr(const char *command);
void unescapeifRequired(std::string &what);
void setprompt(prompttype p, std::string arg = "");
prompttype getprompt();
void printHistory();
int askforConfirmation(std::string message);
bool booleanAskForConfirmation(std::string messageHeading);
std::string askforUserResponse(std::string message);
void* checkForUpdates(void *param);
void stopcheckingForUpdates();
void startcheckingForUpdates();
void informTransferUpdate(mega::MegaTransfer *transfer, int clientID);
void informStateListenerByClientId(int clientID, std::string s);
void informProgressUpdate(long long transferred, long long total, int clientID, std::string title = "");
void sendEvent(StatsManager::MegacmdEvent event, mega::MegaApi *megaApi, bool wait = true);
void sendEvent(StatsManager::MegacmdEvent event, const char *msg, mega::MegaApi *megaApi, bool wait = true);
#ifdef _WIN32
void uninstall();
#endif
class LoggedStream; // forward delaration
int executeServer(int argc, char* argv[],
std::unique_ptr<megacmd::LoggedStream> logStream = nullptr,
int sdkLogLevel = mega::MegaApi::LOG_LEVEL_DEBUG,
int cmdLogLevel = mega::MegaApi::LOG_LEVEL_DEBUG,
bool skiplockcheck = false,
std::string debug_api_url = {},
bool disablepkp/*only for debugging*/ = false);
void stopServer();
}//end namespace
#endif