forked from meganz/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmegaapi_impl.h
More file actions
3656 lines (3122 loc) · 141 KB
/
megaapi_impl.h
File metadata and controls
3656 lines (3122 loc) · 141 KB
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file megaapi_impl.h
* @brief Private header file of the intermediate layer for the MEGA C++ SDK.
*
* (c) 2013-2014 by Mega Limited, Auckland, New Zealand
*
* This file is part of the MEGA SDK - Client Access Engine.
*
* Applications using the MEGA API must present a valid application key
* and comply with the the rules set forth in the Terms of Service.
*
* The MEGA SDK 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 MEGAAPI_IMPL_H
#define MEGAAPI_IMPL_H
#include <atomic>
#include <memory>
#include "mega.h"
#include "mega/gfx/external.h"
#include "megaapi.h"
#define CRON_USE_LOCAL_TIME 1
#include "mega/mega_ccronexpr.h"
#ifdef USE_PCRE
#include <pcre.h>
#endif
#ifdef HAVE_LIBUV
#include "uv.h"
#include "mega/mega_http_parser.h"
#include "mega/mega_evt_tls.h"
#endif
#ifndef _WIN32
#include <curl/curl.h>
#include <fcntl.h>
#endif
////////////////////////////// SETTINGS //////////////////////////////
////////// Support for threads and mutexes
//Choose one of these options.
//Otherwise, C++11 threads and mutexes will be used
//#define USE_PTHREAD
//#define USE_QT
////////// Support for thumbnails and previews.
//If you selected QT for threads and mutexes, it will be also used for thumbnails and previews
//You can create a subclass of MegaGfxProcessor and pass it to the constructor of MegaApi
//#define USE_FREEIMAGE
//Define WINDOWS_PHONE if you want to build the MEGA SDK for Windows Phone
//#define WINDOWS_PHONE
/////////////////////////// END OF SETTINGS ///////////////////////////
namespace mega
{
#ifdef USE_QT
class MegaThread : public QtThread {};
class MegaSemaphore : public QtSemaphore {};
#elif USE_PTHREAD
class MegaThread : public PosixThread {};
class MegaSemaphore : public PosixSemaphore {};
#elif defined(_WIN32) && !defined(USE_CPPTHREAD) && !defined(WINDOWS_PHONE)
class MegaThread : public Win32Thread {};
class MegaSemaphore : public Win32Semaphore {};
#else
class MegaThread : public CppThread {};
class MegaSemaphore : public CppSemaphore {};
#endif
#ifdef USE_QT
class MegaGfxProc : public GfxProcQT {};
#elif USE_FREEIMAGE
class MegaGfxProc : public GfxProcFreeImage {};
#elif TARGET_OS_IPHONE
class MegaGfxProc : public GfxProcCG {};
#else
class MegaGfxProc : public GfxProcExternal {};
#endif
#ifdef WIN32
#ifndef WINDOWS_PHONE
#ifdef USE_CURL
class MegaHttpIO : public CurlHttpIO {};
#else
class MegaHttpIO : public WinHttpIO {};
#endif
#else
class MegaHttpIO : public CurlHttpIO {};
#endif
class MegaFileSystemAccess : public WinFileSystemAccess {};
class MegaWaiter : public WinWaiter {};
#else
#ifdef __APPLE__
typedef CurlHttpIO MegaHttpIO;
typedef PosixFileSystemAccess MegaFileSystemAccess;
typedef PosixWaiter MegaWaiter;
#else
class MegaHttpIO : public CurlHttpIO {};
class MegaFileSystemAccess : public PosixFileSystemAccess {};
class MegaWaiter : public PosixWaiter {};
#endif
#endif
#ifdef HAVE_LIBUV
class MegaTCPServer;
class MegaHTTPServer;
class MegaFTPServer;
#endif
class MegaDbAccess : public SqliteDbAccess
{
public:
MegaDbAccess(string *basePath = NULL) : SqliteDbAccess(basePath){}
};
class MegaErrorPrivate : public MegaError
{
public:
MegaErrorPrivate(int errorCode = MegaError::API_OK);
MegaErrorPrivate(int errorCode, long long value);
MegaErrorPrivate(const Error &err);
MegaErrorPrivate(const MegaError &megaError);
~MegaErrorPrivate() override;
MegaError* copy() const override;
int getErrorCode() const override;
long long getValue() const override;
bool hasExtraInfo() const override;
long long getUserStatus() const override;
long long getLinkStatus() const override;
const char* getErrorString() const override;
const char* toString() const override;
const char* __str__() const override;
const char* __toString() const override;
private:
long long mValue = 0;
long long mUserStatus = MegaError::UserErrorCode::USER_ETD_UNKNOWN;
long long mLinkStatus = MegaError::LinkErrorCode::LINK_UNKNOWN;
};
class ExternalLogger : public Logger
{
public:
ExternalLogger();
~ExternalLogger();
void addMegaLogger(MegaLogger* logger);
void removeMegaLogger(MegaLogger *logger);
void setLogLevel(int logLevel);
void setLogToConsole(bool enable);
void postLog(int logLevel, const char *message, const char *filename, int line);
void log(const char *time, int loglevel, const char *source, const char *message
#ifdef ENABLE_LOG_PERFORMANCE
, const char **directMessages, size_t *directMessagesSizes, unsigned numberMessages
#endif
) override;
private:
std::recursive_mutex mutex;
set <MegaLogger *> megaLoggers;
bool logToConsole;
};
class MegaTransferPrivate;
class MegaTreeProcCopy : public MegaTreeProcessor
{
public:
NewNode* nn;
unsigned nc;
MegaTreeProcCopy(MegaClient *client);
bool processMegaNode(MegaNode* node) override;
void allocnodes(void);
protected:
MegaClient *client;
};
class MegaSizeProcessor : public MegaTreeProcessor
{
protected:
long long totalBytes;
public:
MegaSizeProcessor();
bool processMegaNode(MegaNode* node) override;
long long getTotalBytes();
};
class MegaRecursiveOperation
{
public:
virtual ~MegaRecursiveOperation() = default;
virtual void start(MegaNode* node) = 0;
virtual void cancel() = 0;
protected:
MegaApiImpl *megaApi;
MegaClient *client;
MegaTransferPrivate *transfer;
MegaTransferListener *listener;
int recursive;
int tag;
int pendingTransfers;
bool cancelled = false;
std::set<MegaTransferPrivate*> subTransfers;
int mIncompleteTransfers = { 0 };
MegaErrorPrivate mLastError = { API_OK };
};
class MegaFolderUploadController : public MegaRequestListener, public MegaTransferListener, public MegaRecursiveOperation
{
public:
MegaFolderUploadController(MegaApiImpl *megaApi, MegaTransferPrivate *transfer);
void start(MegaNode* node) override;
void cancel() override;
protected:
void onFolderAvailable(MegaHandle handle);
void checkCompletion();
std::list<LocalPath> pendingFolders;
public:
void onRequestFinish(MegaApi* api, MegaRequest *request, MegaError *e) override;
void onTransferStart(MegaApi *api, MegaTransfer *transfer) override;
void onTransferUpdate(MegaApi *api, MegaTransfer *transfer) override;
void onTransferFinish(MegaApi* api, MegaTransfer *transfer, MegaError *e) override;
~MegaFolderUploadController();
};
class MegaBackupController : public MegaBackup, public MegaRequestListener, public MegaTransferListener
{
public:
MegaBackupController(MegaApiImpl *megaApi, int tag, int folderTransferTag, handle parenthandle, const char *filename, bool attendPastBackups, const char *speriod, int64_t period=-1, int maxBackups = 10);
MegaBackupController(MegaBackupController *backup);
~MegaBackupController();
void update();
void start(bool skip = false);
void removeexceeding(bool currentoneOK);
void abortCurrent();
// MegaBackup interface
MegaBackup *copy() override;
const char *getLocalFolder() const override;
MegaHandle getMegaHandle() const override;
int getTag() const override;
int64_t getPeriod() const override;
const char *getPeriodString() const override;
int getMaxBackups() const override;
int getState() const override;
long long getNextStartTime(long long oldStartTimeAbsolute = -1) const override;
bool getAttendPastBackups() const override;
MegaTransferList *getFailedTransfers() override;
// MegaBackup setters
void setLocalFolder(const std::string &value);
void setMegaHandle(const MegaHandle &value);
void setTag(int value);
void setPeriod(const int64_t &value);
void setPeriodstring(const std::string &value);
void setMaxBackups(int value);
void setState(int value);
void setAttendPastBackups(bool value);
//getters&setters
int64_t getStartTime() const;
void setStartTime(const int64_t &value);
std::string getBackupName() const;
void setBackupName(const std::string &value);
int64_t getOffsetds() const;
void setOffsetds(const int64_t &value);
int64_t getLastbackuptime() const;
void setLastbackuptime(const int64_t &value);
int getFolderTransferTag() const;
void setFolderTransferTag(int value);
//convenience methods
bool isBackup(std::string localname, std::string backupname) const;
int64_t getTimeOfBackup(std::string localname) const;
protected:
// common variables
MegaApiImpl *megaApi;
MegaClient *client;
MegaBackupListener *backupListener;
int state;
int tag;
int64_t lastwakeuptime;
int64_t lastbackuptime; //ds absolute
int pendingremovals;
int folderTransferTag; //reused between backup instances
std::string basepath;
std::string backupName;
handle parenthandle;
int maxBackups;
int64_t period;
std::string periodstring;
cron_expr ccronexpr;
bool valid;
int64_t offsetds; //times offset with epoch time?
int64_t startTime; // when shall the next backup begin
bool attendPastBackups;
// backup instance related
handle currentHandle;
std::string currentName;
std::list<LocalPath> pendingFolders;
std::vector<MegaTransfer *> failedTransfers;
int recursive;
int pendingTransfers;
int pendingTags;
// backup instance stats
int64_t currentBKStartTime;
int64_t updateTime;
long long transferredBytes;
long long totalBytes;
long long speed;
long long meanSpeed;
long long numberFiles; //number of files successfully uploaded
long long totalFiles;
long long numberFolders;
// internal methods
void onFolderAvailable(MegaHandle handle);
bool checkCompletion();
bool isBusy() const;
int64_t getLastBackupTime();
long long getNextStartTimeDs(long long oldStartTimeds = -1) const;
std::string epochdsToString(int64_t rawtimeds) const;
int64_t stringTimeTods(string stime) const;
void clearCurrentBackupData();
public:
void onRequestFinish(MegaApi* api, MegaRequest *request, MegaError *e) override;
void onTransferStart(MegaApi *api, MegaTransfer *transfer) override;
void onTransferUpdate(MegaApi *api, MegaTransfer *transfer) override;
void onTransferTemporaryError(MegaApi *, MegaTransfer *t, MegaError* e) override;
void onTransferFinish(MegaApi* api, MegaTransfer *transfer, MegaError *e) override;
long long getNumberFolders() const override;
void setNumberFolders(long long value);
long long getNumberFiles() const override;
void setNumberFiles(long long value);
long long getMeanSpeed() const override;
void setMeanSpeed(long long value);
long long getSpeed() const override;
void setSpeed(long long value);
long long getTotalBytes() const override;
void setTotalBytes(long long value);
long long getTransferredBytes() const override;
void setTransferredBytes(long long value);
int64_t getUpdateTime() const override;
void setUpdateTime(const int64_t &value);
int64_t getCurrentBKStartTime() const override;
void setCurrentBKStartTime(const int64_t &value);
long long getTotalFiles() const override;
void setTotalFiles(long long value);
MegaBackupListener *getBackupListener() const;
void setBackupListener(MegaBackupListener *value);
cron_expr getCcronexpr() const;
void setCcronexpr(const cron_expr &value);
bool isValid() const;
void setValid(bool value);
};
class MegaFolderDownloadController : public MegaTransferListener, public MegaRecursiveOperation
{
public:
MegaFolderDownloadController(MegaApiImpl *megaApi, MegaTransferPrivate *transfer);
void start(MegaNode *node) override;
void cancel() override;
protected:
void downloadFolderNode(MegaNode *node, LocalPath& path, FileSystemType fsType);
void checkCompletion();
public:
void onTransferStart(MegaApi *, MegaTransfer *t) override;
void onTransferUpdate(MegaApi *, MegaTransfer *t) override;
void onTransferFinish(MegaApi*, MegaTransfer *t, MegaError *e) override;
};
class MegaNodePrivate : public MegaNode, public Cacheable
{
public:
MegaNodePrivate(const char *name, int type, int64_t size, int64_t ctime, int64_t mtime,
MegaHandle nodeMegaHandle, std::string *nodekey, std::string *attrstring, std::string *fileattrstring,
const char *fingerprint, const char *originalFingerprint, MegaHandle owner, MegaHandle parentHandle = INVALID_HANDLE,
const char *privateauth = NULL, const char *publicauth = NULL, bool isPublic = true,
bool isForeign = false, const char *chatauth = NULL);
MegaNodePrivate(MegaNode *node);
~MegaNodePrivate() override;
int getType() override;
const char* getName() override;
const char* getFingerprint() override;
const char* getOriginalFingerprint() override;
bool hasCustomAttrs() override;
MegaStringList *getCustomAttrNames() override;
const char *getCustomAttr(const char* attrName) override;
int getDuration() override;
int getWidth() override;
int getHeight() override;
int getShortformat() override;
int getVideocodecid() override;
double getLatitude() override;
double getLongitude() override;
char *getBase64Handle() override;
int64_t getSize() override;
int64_t getCreationTime() override;
int64_t getModificationTime() override;
MegaHandle getHandle() override;
MegaHandle getRestoreHandle() override;
MegaHandle getParentHandle() override;
std::string* getNodeKey() override;
char *getBase64Key() override;
std::string* getAttrString() override;
char* getFileAttrString() override;
int getTag() override;
int64_t getExpirationTime() override;
MegaHandle getPublicHandle() override;
MegaNode* getPublicNode() override;
char *getPublicLink(bool includeKey = true) override;
int64_t getPublicLinkCreationTime() override;
bool isNewLinkFormat();
bool isFile() override;
bool isFolder() override;
bool isRemoved() override;
bool hasChanged(int changeType) override;
int getChanges() override;
bool hasThumbnail() override;
bool hasPreview() override;
bool isPublic() override;
bool isExported() override;
bool isExpired() override;
bool isTakenDown() override;
bool isForeign() override;
std::string* getPrivateAuth() override;
MegaNodeList *getChildren() override;
void setPrivateAuth(const char *privateAuth) override;
void setPublicAuth(const char *publicAuth);
void setChatAuth(const char *chatAuth);
void setForeign(bool foreign);
void setChildren(MegaNodeList *children);
void setName(const char *newName);
std::string* getPublicAuth() override;
const char *getChatAuth() override;
bool isShared() override;
bool isOutShare() override;
bool isInShare() override;
std::string* getSharekey();
MegaHandle getOwner() const override;
#ifdef ENABLE_SYNC
bool isSyncDeleted() override;
std::string getLocalPath() override;
#endif
static MegaNode *fromNode(Node *node);
MegaNode *copy() override;
char *serialize() override;
bool serialize(string*) override;
static MegaNodePrivate* unserialize(string*);
protected:
MegaNodePrivate(Node *node);
int type;
const char *name;
const char *fingerprint;
const char *originalfingerprint;
attr_map *customAttrs;
int64_t size;
int64_t ctime;
int64_t mtime;
MegaHandle nodehandle;
MegaHandle parenthandle;
MegaHandle restorehandle;
std::string nodekey;
std::string attrstring;
std::string fileattrstring;
std::string privateAuth;
std::string publicAuth;
const char *chatAuth;
int tag;
int changed;
struct {
bool thumbnailAvailable : 1;
bool previewAvailable : 1;
bool isPublicNode : 1;
bool outShares : 1;
bool inShare : 1;
bool foreign : 1;
};
PublicLink *plink;
bool mNewLinkFormat;
std::string *sharekey; // for plinks of folders
int duration;
int width;
int height;
int shortformat;
int videocodecid;
double latitude;
double longitude;
MegaNodeList *children;
MegaHandle owner;
#ifdef ENABLE_SYNC
bool syncdeleted;
std::string localPath;
#endif
};
class MegaUserPrivate : public MegaUser
{
public:
MegaUserPrivate(User *user);
MegaUserPrivate(MegaUser *user);
static MegaUser *fromUser(User *user);
virtual MegaUser *copy();
~MegaUserPrivate();
virtual const char* getEmail();
virtual MegaHandle getHandle();
virtual int getVisibility();
virtual int64_t getTimestamp();
virtual bool hasChanged(int changeType);
virtual int getChanges();
virtual int isOwnChange();
protected:
const char *email;
MegaHandle handle;
int visibility;
int64_t ctime;
int changed;
int tag;
};
class MegaUserAlertPrivate : public MegaUserAlert
{
public:
MegaUserAlertPrivate(UserAlert::Base* user, MegaClient* mc);
//MegaUserAlertPrivate(const MegaUserAlertPrivate&); // default copy works for this type
virtual MegaUserAlert* copy() const;
virtual unsigned getId() const;
virtual bool getSeen() const;
virtual bool getRelevant() const;
virtual int getType() const;
virtual const char *getTypeString() const;
virtual MegaHandle getUserHandle() const;
virtual MegaHandle getNodeHandle() const;
virtual const char* getEmail() const;
virtual const char* getPath() const;
virtual const char* getName() const;
virtual const char* getHeading() const;
virtual const char* getTitle() const;
virtual int64_t getNumber(unsigned index) const;
virtual int64_t getTimestamp(unsigned index) const;
virtual const char* getString(unsigned index) const;
virtual bool isOwnChange() const;
protected:
unsigned id;
bool seen;
bool relevant;
int type;
int tag;
string heading;
string title;
handle userHandle;
string email;
handle nodeHandle;
string nodePath;
string nodeName;
vector<int64_t> numbers;
vector<int64_t> timestamps;
vector<string> extraStrings;
};
class MegaHandleListPrivate : public MegaHandleList
{
public:
MegaHandleListPrivate();
MegaHandleListPrivate(const MegaHandleListPrivate *hList);
virtual ~MegaHandleListPrivate();
virtual MegaHandleList *copy() const;
virtual MegaHandle get(unsigned int i) const;
virtual unsigned int size() const;
virtual void addMegaHandle(MegaHandle megaHandle);
private:
std::vector<MegaHandle> mList;
};
class MegaIntegerListPrivate : public MegaIntegerList
{
public:
MegaIntegerListPrivate(const vector<int64_t> &integers);
virtual ~MegaIntegerListPrivate();
MegaIntegerList *copy() const override;
int64_t get(int i) const override;
int size() const override;
private:
vector<int64_t> mIntegers;
};
class MegaSharePrivate : public MegaShare
{
public:
static MegaShare *fromShare(MegaHandle nodeMegaHandle, Share *share);
virtual MegaShare *copy();
virtual ~MegaSharePrivate();
virtual const char *getUser();
virtual MegaHandle getNodeHandle();
virtual int getAccess();
virtual int64_t getTimestamp();
virtual bool isPending();
protected:
MegaSharePrivate(MegaHandle nodehandle, Share *share);
MegaSharePrivate(MegaShare *share);
MegaHandle nodehandle;
const char *user;
int access;
int64_t ts;
bool pending;
};
class MegaTransferPrivate : public MegaTransfer, public Cacheable
{
public:
MegaTransferPrivate(int type, MegaTransferListener *listener = NULL);
MegaTransferPrivate(const MegaTransferPrivate *transfer);
virtual ~MegaTransferPrivate();
MegaTransfer *copy() override;
Transfer *getTransfer() const;
void setTransfer(Transfer *transfer);
void setStartTime(int64_t startTime);
void setTransferredBytes(long long transferredBytes);
void setTotalBytes(long long totalBytes);
void setPath(const char* path);
void setParentPath(const char* path);
void setNodeHandle(MegaHandle nodeHandle);
void setParentHandle(MegaHandle parentHandle);
void setNumConnections(int connections);
void setStartPos(long long startPos);
void setEndPos(long long endPos);
void setNumRetry(int retry);
void setMaxRetries(int retry);
void setTime(int64_t time);
void setFileName(const char* fileName);
void setSlot(int id);
void setTag(int tag);
void setSpeed(long long speed);
void setMeanSpeed(long long meanSpeed);
void setDeltaSize(long long deltaSize);
void setUpdateTime(int64_t updateTime);
void setPublicNode(MegaNode *publicNode, bool copyChildren = false);
void setSyncTransfer(bool syncTransfer);
void setSourceFileTemporary(bool temporary);
void setStartFirst(bool startFirst);
void setBackupTransfer(bool backupTransfer);
void setForeignOverquota(bool backupTransfer);
void setStreamingTransfer(bool streamingTransfer);
void setLastBytes(char *lastBytes);
void setLastError(const MegaError *e);
void setFolderTransferTag(int tag);
void setNotificationNumber(long long notificationNumber);
void setListener(MegaTransferListener *listener);
int getType() const override;
const char * getTransferString() const override;
const char* toString() const override;
const char* __str__() const override;
const char* __toString() const override;
virtual int64_t getStartTime() const override;
long long getTransferredBytes() const override;
long long getTotalBytes() const override;
const char* getPath() const override;
const char* getParentPath() const override;
MegaHandle getNodeHandle() const override;
MegaHandle getParentHandle() const override;
long long getStartPos() const override;
long long getEndPos() const override;
const char* getFileName() const override;
MegaTransferListener* getListener() const override;
int getNumRetry() const override;
int getMaxRetries() const override;
virtual int64_t getTime() const;
int getTag() const override;
long long getSpeed() const override;
long long getMeanSpeed() const override;
long long getDeltaSize() const override;
int64_t getUpdateTime() const override;
virtual MegaNode *getPublicNode() const;
MegaNode *getPublicMegaNode() const override;
bool isSyncTransfer() const override;
bool isStreamingTransfer() const override;
bool isFinished() const override;
virtual bool isSourceFileTemporary() const;
virtual bool shouldStartFirst() const;
bool isBackupTransfer() const override;
bool isForeignOverquota() const override;
char *getLastBytes() const override;
MegaError getLastError() const override;
const MegaError *getLastErrorExtended() const override;
bool isFolderTransfer() const override;
int getFolderTransferTag() const override;
virtual void setAppData(const char *data);
const char* getAppData() const override;
virtual void setState(int state);
int getState() const override;
virtual void setPriority(unsigned long long p);
unsigned long long getPriority() const override;
long long getNotificationNumber() const override;
bool serialize(string*) override;
static MegaTransferPrivate* unserialize(string*);
void startRecursiveOperation(unique_ptr<MegaRecursiveOperation>, MegaNode* node); // takes ownership of both
long long getPlaceInQueue() const;
void setPlaceInQueue(long long value);
protected:
int type;
int tag;
int state;
uint64_t priority;
struct
{
bool syncTransfer : 1;
bool streamingTransfer : 1;
bool temporarySourceFile : 1;
bool startFirst : 1;
bool backupTransfer : 1;
bool foreignOverquota : 1;
};
int64_t startTime;
int64_t updateTime;
int64_t time;
long long transferredBytes;
long long totalBytes;
long long speed;
long long meanSpeed;
long long deltaSize;
long long notificationNumber;
MegaHandle nodeHandle;
MegaHandle parentHandle;
const char* path;
const char* parentPath; //used as targetUser for uploads
const char* fileName;
char *lastBytes;
MegaNode *publicNode;
long long startPos;
long long endPos;
int retry;
int maxRetries;
long long placeInQueue = 0;
MegaTransferListener *listener;
Transfer *transfer = nullptr;
std::unique_ptr<MegaError> lastError;
int folderTransferTag;
const char* appData;
unique_ptr<MegaRecursiveOperation> recursiveOperation;
};
class MegaTransferDataPrivate : public MegaTransferData
{
public:
MegaTransferDataPrivate(TransferList *transferList, long long notificationNumber);
MegaTransferDataPrivate(const MegaTransferDataPrivate *transferData);
virtual ~MegaTransferDataPrivate();
virtual MegaTransferData *copy() const;
virtual int getNumDownloads() const;
virtual int getNumUploads() const;
virtual int getDownloadTag(int i) const;
virtual int getUploadTag(int i) const;
virtual unsigned long long getDownloadPriority(int i) const;
virtual unsigned long long getUploadPriority(int i) const;
virtual long long getNotificationNumber() const;
protected:
int numDownloads;
int numUploads;
long long notificationNumber;
vector<int> downloadTags;
vector<int> uploadTags;
vector<uint64_t> downloadPriorities;
vector<uint64_t> uploadPriorities;
};
class MegaFolderInfoPrivate : public MegaFolderInfo
{
public:
MegaFolderInfoPrivate(int numFiles, int numFolders, int numVersions, long long currentSize, long long versionsSize);
MegaFolderInfoPrivate(const MegaFolderInfoPrivate *folderData);
virtual ~MegaFolderInfoPrivate();
virtual MegaFolderInfo *copy() const;
virtual int getNumVersions() const;
virtual int getNumFiles() const;
virtual int getNumFolders() const;
virtual long long getCurrentSize() const;
virtual long long getVersionsSize() const;
protected:
int numFiles;
int numFolders;
int numVersions;
long long currentSize;
long long versionsSize;
};
class MegaTimeZoneDetailsPrivate : public MegaTimeZoneDetails
{
public:
MegaTimeZoneDetailsPrivate(vector<string>* timeZones, vector<int> *timeZoneOffsets, int defaultTimeZone);
MegaTimeZoneDetailsPrivate(const MegaTimeZoneDetailsPrivate *timeZoneDetails);
virtual ~MegaTimeZoneDetailsPrivate();
virtual MegaTimeZoneDetails *copy() const;
virtual int getNumTimeZones() const;
virtual const char *getTimeZone(int index) const;
virtual int getTimeOffset(int index) const;
virtual int getDefault() const;
protected:
int defaultTimeZone;
vector<string> timeZones;
vector<int> timeZoneOffsets;
};
class MegaPushNotificationSettingsPrivate : public MegaPushNotificationSettings
{
public:
MegaPushNotificationSettingsPrivate(const std::string &settingsJSON);
MegaPushNotificationSettingsPrivate();
MegaPushNotificationSettingsPrivate(const MegaPushNotificationSettingsPrivate *settings);
std::string generateJson() const;
bool isValid() const;
virtual ~MegaPushNotificationSettingsPrivate();
MegaPushNotificationSettings *copy() const override;
private:
m_time_t mGlobalDND = -1; // defaults to -1 if not defined
int mGlobalScheduleStart = -1; // defaults to -1 if not defined
int mGlobalScheduleEnd = -1; // defaults to -1 if not defined
std::string mGlobalScheduleTimezone;
std::map<MegaHandle, m_time_t> mChatDND;
std::map<MegaHandle, bool> mChatAlwaysNotify;
m_time_t mContactsDND = -1; // defaults to -1 if not defined
m_time_t mSharesDND = -1; // defaults to -1 if not defined
m_time_t mGlobalChatsDND = -1; // defaults to -1 if not defined
bool mJsonInvalid = false; // true if ctor from JSON find issues
public:
// getters
bool isGlobalEnabled() const override;
bool isGlobalDndEnabled() const override;
bool isGlobalChatsDndEnabled() const override;
int64_t getGlobalDnd() const override;
int64_t getGlobalChatsDnd() const override;
bool isGlobalScheduleEnabled() const override;
int getGlobalScheduleStart() const override;
int getGlobalScheduleEnd() const override;
const char *getGlobalScheduleTimezone() const override;
bool isChatEnabled(MegaHandle chatid) const override;
bool isChatDndEnabled(MegaHandle chatid) const override;
int64_t getChatDnd(MegaHandle chatid) const override;
bool isChatAlwaysNotifyEnabled(MegaHandle chatid) const override;
bool isContactsEnabled() const override;
bool isSharesEnabled() const override;
bool isChatsEnabled() const override;
// setters
void enableGlobal(bool enable) override;
void setGlobalDnd(int64_t timestamp) override;
void disableGlobalDnd() override;
void setGlobalSchedule(int start, int end, const char *timezone) override;
void disableGlobalSchedule() override;
void enableChat(MegaHandle chatid, bool enable) override;
void setChatDnd(MegaHandle chatid, int64_t timestamp) override;
void setGlobalChatsDnd(int64_t timestamp) override;
void enableChatAlwaysNotify(MegaHandle chatid, bool enable) override;
void enableContacts(bool enable) override;
void enableShares(bool enable) override;
void enableChats(bool enable) override;
};
class MegaContactRequestPrivate : public MegaContactRequest
{
public:
MegaContactRequestPrivate(PendingContactRequest *request);
MegaContactRequestPrivate(const MegaContactRequest *request);
virtual ~MegaContactRequestPrivate();
static MegaContactRequest *fromContactRequest(PendingContactRequest *request);
virtual MegaContactRequest *copy() const;
virtual MegaHandle getHandle() const;
virtual char* getSourceEmail() const;
virtual char* getSourceMessage() const;
virtual char* getTargetEmail() const;
virtual int64_t getCreationTime() const;
virtual int64_t getModificationTime() const;
virtual int getStatus() const;
virtual bool isOutgoing() const;
virtual bool isAutoAccepted() const;
protected:
MegaHandle handle;
char* sourceEmail;
char* sourceMessage;
char* targetEmail;
int64_t creationTime;
int64_t modificationTime;
int status;
bool outgoing;
bool autoaccepted;
};
#ifdef ENABLE_SYNC
class MegaSyncEventPrivate: public MegaSyncEvent
{
public:
explicit MegaSyncEventPrivate(int type);
MegaSyncEvent *copy() override;
int getType() const override;
const char *getPath() const override;
MegaHandle getNodeHandle() const override;
const char *getNewPath() const override;
const char* getPrevName() const override;
MegaHandle getPrevParent() const override;
void setPath(const char* path);
void setNodeHandle(MegaHandle nodeHandle);
void setNewPath(const char* newPath);
void setPrevName(const char* prevName);
void setPrevParent(MegaHandle prevParent);
protected:
int type;
std::unique_ptr<char[]> path;
std::unique_ptr<char[]> newPath;
std::unique_ptr<char[]> prevName;