1 /** 2 * @file megaapi_impl.h 3 * @brief Private header file of the intermediate layer for the MEGA C++ SDK. 4 * 5 * (c) 2013-2014 by Mega Limited, Auckland, New Zealand 6 * 7 * This file is part of the MEGA SDK - Client Access Engine. 8 * 9 * Applications using the MEGA API must present a valid application key 10 * and comply with the the rules set forth in the Terms of Service. 11 * 12 * The MEGA SDK is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 * 16 * @copyright Simplified (2-clause) BSD License. 17 * 18 * You should have received a copy of the license along with this 19 * program. 20 */ 21 22 #ifndef MEGAAPI_IMPL_H 23 #define MEGAAPI_IMPL_H 24 25 #include <atomic> 26 #include <memory> 27 28 #include "mega.h" 29 #include "mega/gfx/external.h" 30 #include "megaapi.h" 31 32 #define CRON_USE_LOCAL_TIME 1 33 #include "mega/mega_ccronexpr.h" 34 35 #ifdef USE_PCRE 36 #include <pcre.h> 37 #endif 38 39 #ifdef HAVE_LIBUV 40 #include "uv.h" 41 #include "mega/mega_http_parser.h" 42 #include "mega/mega_evt_tls.h" 43 44 #endif 45 46 #ifndef _WIN32 47 #include <curl/curl.h> 48 #include <fcntl.h> 49 #endif 50 51 ////////////////////////////// SETTINGS ////////////////////////////// 52 ////////// Support for threads and mutexes 53 //Choose one of these options. 54 //Otherwise, C++11 threads and mutexes will be used 55 //#define USE_PTHREAD 56 //#define USE_QT 57 58 ////////// Support for thumbnails and previews. 59 //If you selected QT for threads and mutexes, it will be also used for thumbnails and previews 60 //You can create a subclass of MegaGfxProcessor and pass it to the constructor of MegaApi 61 //#define USE_FREEIMAGE 62 63 //Define WINDOWS_PHONE if you want to build the MEGA SDK for Windows Phone 64 //#define WINDOWS_PHONE 65 /////////////////////////// END OF SETTINGS /////////////////////////// 66 67 namespace mega 68 { 69 70 #ifdef USE_QT 71 class MegaThread : public QtThread {}; 72 class MegaSemaphore : public QtSemaphore {}; 73 #elif USE_PTHREAD 74 class MegaThread : public PosixThread {}; 75 class MegaSemaphore : public PosixSemaphore {}; 76 #elif defined(_WIN32) && !defined(USE_CPPTHREAD) && !defined(WINDOWS_PHONE) 77 class MegaThread : public Win32Thread {}; 78 class MegaSemaphore : public Win32Semaphore {}; 79 #else 80 class MegaThread : public CppThread {}; 81 class MegaSemaphore : public CppSemaphore {}; 82 #endif 83 84 #ifdef USE_QT 85 class MegaGfxProc : public GfxProcQT {}; 86 #elif USE_FREEIMAGE 87 class MegaGfxProc : public GfxProcFreeImage {}; 88 #elif TARGET_OS_IPHONE 89 class MegaGfxProc : public GfxProcCG {}; 90 #else 91 class MegaGfxProc : public GfxProcExternal {}; 92 #endif 93 94 #ifdef WIN32 95 #ifndef WINDOWS_PHONE 96 #ifdef USE_CURL 97 class MegaHttpIO : public CurlHttpIO {}; 98 #else 99 class MegaHttpIO : public WinHttpIO {}; 100 #endif 101 #else 102 class MegaHttpIO : public CurlHttpIO {}; 103 #endif 104 class MegaFileSystemAccess : public WinFileSystemAccess {}; 105 class MegaWaiter : public WinWaiter {}; 106 #else 107 #ifdef __APPLE__ 108 typedef CurlHttpIO MegaHttpIO; 109 typedef PosixFileSystemAccess MegaFileSystemAccess; 110 typedef PosixWaiter MegaWaiter; 111 #else 112 class MegaHttpIO : public CurlHttpIO {}; 113 class MegaFileSystemAccess : public PosixFileSystemAccess {}; 114 class MegaWaiter : public PosixWaiter {}; 115 #endif 116 #endif 117 118 #ifdef HAVE_LIBUV 119 class MegaTCPServer; 120 class MegaHTTPServer; 121 class MegaFTPServer; 122 #endif 123 124 class MegaDbAccess : public SqliteDbAccess 125 { 126 public: SqliteDbAccess(basePath)127 MegaDbAccess(string *basePath = NULL) : SqliteDbAccess(basePath){} 128 }; 129 130 class MegaErrorPrivate : public MegaError 131 { 132 public: 133 MegaErrorPrivate(int errorCode = MegaError::API_OK); 134 MegaErrorPrivate(int errorCode, long long value); 135 MegaErrorPrivate(const Error &err); 136 MegaErrorPrivate(const MegaError &megaError); 137 ~MegaErrorPrivate() override; 138 MegaError* copy() const override; 139 int getErrorCode() const override; 140 long long getValue() const override; 141 bool hasExtraInfo() const override; 142 long long getUserStatus() const override; 143 long long getLinkStatus() const override; 144 const char* getErrorString() const override; 145 const char* toString() const override; 146 const char* __str__() const override; 147 const char* __toString() const override; 148 149 private: 150 long long mValue = 0; 151 long long mUserStatus = MegaError::UserErrorCode::USER_ETD_UNKNOWN; 152 long long mLinkStatus = MegaError::LinkErrorCode::LINK_UNKNOWN; 153 }; 154 155 class ExternalLogger : public Logger 156 { 157 public: 158 ExternalLogger(); 159 ~ExternalLogger(); 160 void addMegaLogger(MegaLogger* logger); 161 void removeMegaLogger(MegaLogger *logger); 162 void setLogLevel(int logLevel); 163 void setLogToConsole(bool enable); 164 void postLog(int logLevel, const char *message, const char *filename, int line); 165 void log(const char *time, int loglevel, const char *source, const char *message 166 #ifdef ENABLE_LOG_PERFORMANCE 167 , const char **directMessages, size_t *directMessagesSizes, unsigned numberMessages 168 #endif 169 ) override; 170 171 private: 172 std::recursive_mutex mutex; 173 set <MegaLogger *> megaLoggers; 174 bool logToConsole; 175 }; 176 177 class MegaTransferPrivate; 178 class MegaTreeProcCopy : public MegaTreeProcessor 179 { 180 public: 181 NewNode* nn; 182 unsigned nc; 183 184 MegaTreeProcCopy(MegaClient *client); 185 bool processMegaNode(MegaNode* node) override; 186 void allocnodes(void); 187 188 protected: 189 MegaClient *client; 190 }; 191 192 193 class MegaSizeProcessor : public MegaTreeProcessor 194 { 195 protected: 196 long long totalBytes; 197 198 public: 199 MegaSizeProcessor(); 200 bool processMegaNode(MegaNode* node) override; 201 long long getTotalBytes(); 202 }; 203 204 class MegaRecursiveOperation 205 { 206 public: 207 virtual ~MegaRecursiveOperation() = default; 208 virtual void start(MegaNode* node) = 0; 209 virtual void cancel() = 0; 210 211 protected: 212 MegaApiImpl *megaApi; 213 MegaClient *client; 214 MegaTransferPrivate *transfer; 215 MegaTransferListener *listener; 216 int recursive; 217 int tag; 218 int pendingTransfers; 219 bool cancelled = false; 220 std::set<MegaTransferPrivate*> subTransfers; 221 int mIncompleteTransfers = { 0 }; 222 MegaErrorPrivate mLastError = { API_OK }; 223 }; 224 225 class MegaFolderUploadController : public MegaRequestListener, public MegaTransferListener, public MegaRecursiveOperation 226 { 227 public: 228 MegaFolderUploadController(MegaApiImpl *megaApi, MegaTransferPrivate *transfer); 229 void start(MegaNode* node) override; 230 void cancel() override; 231 232 protected: 233 void onFolderAvailable(MegaHandle handle); 234 void checkCompletion(); 235 236 std::list<LocalPath> pendingFolders; 237 238 public: 239 void onRequestFinish(MegaApi* api, MegaRequest *request, MegaError *e) override; 240 void onTransferStart(MegaApi *api, MegaTransfer *transfer) override; 241 void onTransferUpdate(MegaApi *api, MegaTransfer *transfer) override; 242 void onTransferFinish(MegaApi* api, MegaTransfer *transfer, MegaError *e) override; 243 ~MegaFolderUploadController(); 244 }; 245 246 247 class MegaBackupController : public MegaBackup, public MegaRequestListener, public MegaTransferListener 248 { 249 public: 250 MegaBackupController(MegaApiImpl *megaApi, int tag, int folderTransferTag, handle parenthandle, const char *filename, bool attendPastBackups, const char *speriod, int64_t period=-1, int maxBackups = 10); 251 MegaBackupController(MegaBackupController *backup); 252 ~MegaBackupController(); 253 254 void update(); 255 void start(bool skip = false); 256 void removeexceeding(bool currentoneOK); 257 void abortCurrent(); 258 259 // MegaBackup interface 260 MegaBackup *copy() override; 261 const char *getLocalFolder() const override; 262 MegaHandle getMegaHandle() const override; 263 int getTag() const override; 264 int64_t getPeriod() const override; 265 const char *getPeriodString() const override; 266 int getMaxBackups() const override; 267 int getState() const override; 268 long long getNextStartTime(long long oldStartTimeAbsolute = -1) const override; 269 bool getAttendPastBackups() const override; 270 MegaTransferList *getFailedTransfers() override; 271 272 273 // MegaBackup setters 274 void setLocalFolder(const std::string &value); 275 void setMegaHandle(const MegaHandle &value); 276 void setTag(int value); 277 void setPeriod(const int64_t &value); 278 void setPeriodstring(const std::string &value); 279 void setMaxBackups(int value); 280 void setState(int value); 281 void setAttendPastBackups(bool value); 282 283 //getters&setters 284 int64_t getStartTime() const; 285 void setStartTime(const int64_t &value); 286 std::string getBackupName() const; 287 void setBackupName(const std::string &value); 288 int64_t getOffsetds() const; 289 void setOffsetds(const int64_t &value); 290 int64_t getLastbackuptime() const; 291 void setLastbackuptime(const int64_t &value); 292 int getFolderTransferTag() const; 293 void setFolderTransferTag(int value); 294 295 //convenience methods 296 bool isBackup(std::string localname, std::string backupname) const; 297 int64_t getTimeOfBackup(std::string localname) const; 298 299 protected: 300 301 // common variables 302 MegaApiImpl *megaApi; 303 MegaClient *client; 304 MegaBackupListener *backupListener; 305 306 int state; 307 int tag; 308 int64_t lastwakeuptime; 309 int64_t lastbackuptime; //ds absolute 310 int pendingremovals; 311 int folderTransferTag; //reused between backup instances 312 std::string basepath; 313 std::string backupName; 314 handle parenthandle; 315 int maxBackups; 316 int64_t period; 317 std::string periodstring; 318 cron_expr ccronexpr; 319 bool valid; 320 int64_t offsetds; //times offset with epoch time? 321 int64_t startTime; // when shall the next backup begin 322 bool attendPastBackups; 323 324 // backup instance related 325 handle currentHandle; 326 std::string currentName; 327 std::list<LocalPath> pendingFolders; 328 std::vector<MegaTransfer *> failedTransfers; 329 int recursive; 330 int pendingTransfers; 331 int pendingTags; 332 // backup instance stats 333 int64_t currentBKStartTime; 334 int64_t updateTime; 335 long long transferredBytes; 336 long long totalBytes; 337 long long speed; 338 long long meanSpeed; 339 long long numberFiles; //number of files successfully uploaded 340 long long totalFiles; 341 long long numberFolders; 342 343 344 // internal methods 345 void onFolderAvailable(MegaHandle handle); 346 bool checkCompletion(); 347 bool isBusy() const; 348 int64_t getLastBackupTime(); 349 long long getNextStartTimeDs(long long oldStartTimeds = -1) const; 350 351 std::string epochdsToString(int64_t rawtimeds) const; 352 int64_t stringTimeTods(string stime) const; 353 354 void clearCurrentBackupData(); 355 356 public: 357 void onRequestFinish(MegaApi* api, MegaRequest *request, MegaError *e) override; 358 void onTransferStart(MegaApi *api, MegaTransfer *transfer) override; 359 void onTransferUpdate(MegaApi *api, MegaTransfer *transfer) override; 360 void onTransferTemporaryError(MegaApi *, MegaTransfer *t, MegaError* e) override; 361 void onTransferFinish(MegaApi* api, MegaTransfer *transfer, MegaError *e) override; 362 363 long long getNumberFolders() const override; 364 void setNumberFolders(long long value); 365 long long getNumberFiles() const override; 366 void setNumberFiles(long long value); 367 long long getMeanSpeed() const override; 368 void setMeanSpeed(long long value); 369 long long getSpeed() const override; 370 void setSpeed(long long value); 371 long long getTotalBytes() const override; 372 void setTotalBytes(long long value); 373 long long getTransferredBytes() const override; 374 void setTransferredBytes(long long value); 375 int64_t getUpdateTime() const override; 376 void setUpdateTime(const int64_t &value); 377 int64_t getCurrentBKStartTime() const override; 378 void setCurrentBKStartTime(const int64_t &value); 379 long long getTotalFiles() const override; 380 void setTotalFiles(long long value); 381 MegaBackupListener *getBackupListener() const; 382 void setBackupListener(MegaBackupListener *value); 383 cron_expr getCcronexpr() const; 384 void setCcronexpr(const cron_expr &value); 385 bool isValid() const; 386 void setValid(bool value); 387 }; 388 389 class MegaFolderDownloadController : public MegaTransferListener, public MegaRecursiveOperation 390 { 391 public: 392 MegaFolderDownloadController(MegaApiImpl *megaApi, MegaTransferPrivate *transfer); 393 void start(MegaNode *node) override; 394 void cancel() override; 395 396 protected: 397 void downloadFolderNode(MegaNode *node, LocalPath& path, FileSystemType fsType); 398 void checkCompletion(); 399 400 public: 401 void onTransferStart(MegaApi *, MegaTransfer *t) override; 402 void onTransferUpdate(MegaApi *, MegaTransfer *t) override; 403 void onTransferFinish(MegaApi*, MegaTransfer *t, MegaError *e) override; 404 }; 405 406 class MegaNodePrivate : public MegaNode, public Cacheable 407 { 408 public: 409 MegaNodePrivate(const char *name, int type, int64_t size, int64_t ctime, int64_t mtime, 410 MegaHandle nodeMegaHandle, std::string *nodekey, std::string *attrstring, std::string *fileattrstring, 411 const char *fingerprint, const char *originalFingerprint, MegaHandle owner, MegaHandle parentHandle = INVALID_HANDLE, 412 const char *privateauth = NULL, const char *publicauth = NULL, bool isPublic = true, 413 bool isForeign = false, const char *chatauth = NULL); 414 415 MegaNodePrivate(MegaNode *node); 416 ~MegaNodePrivate() override; 417 int getType() override; 418 const char* getName() override; 419 const char* getFingerprint() override; 420 const char* getOriginalFingerprint() override; 421 bool hasCustomAttrs() override; 422 MegaStringList *getCustomAttrNames() override; 423 const char *getCustomAttr(const char* attrName) override; 424 int getDuration() override; 425 int getWidth() override; 426 int getHeight() override; 427 int getShortformat() override; 428 int getVideocodecid() override; 429 double getLatitude() override; 430 double getLongitude() override; 431 char *getBase64Handle() override; 432 int64_t getSize() override; 433 int64_t getCreationTime() override; 434 int64_t getModificationTime() override; 435 MegaHandle getHandle() override; 436 MegaHandle getRestoreHandle() override; 437 MegaHandle getParentHandle() override; 438 std::string* getNodeKey() override; 439 char *getBase64Key() override; 440 std::string* getAttrString() override; 441 char* getFileAttrString() override; 442 int getTag() override; 443 int64_t getExpirationTime() override; 444 MegaHandle getPublicHandle() override; 445 MegaNode* getPublicNode() override; 446 char *getPublicLink(bool includeKey = true) override; 447 int64_t getPublicLinkCreationTime() override; 448 bool isNewLinkFormat(); 449 bool isFile() override; 450 bool isFolder() override; 451 bool isRemoved() override; 452 bool hasChanged(int changeType) override; 453 int getChanges() override; 454 bool hasThumbnail() override; 455 bool hasPreview() override; 456 bool isPublic() override; 457 bool isExported() override; 458 bool isExpired() override; 459 bool isTakenDown() override; 460 bool isForeign() override; 461 std::string* getPrivateAuth() override; 462 MegaNodeList *getChildren() override; 463 void setPrivateAuth(const char *privateAuth) override; 464 void setPublicAuth(const char *publicAuth); 465 void setChatAuth(const char *chatAuth); 466 void setForeign(bool foreign); 467 void setChildren(MegaNodeList *children); 468 void setName(const char *newName); 469 std::string* getPublicAuth() override; 470 const char *getChatAuth() override; 471 bool isShared() override; 472 bool isOutShare() override; 473 bool isInShare() override; 474 std::string* getSharekey(); 475 MegaHandle getOwner() const override; 476 477 #ifdef ENABLE_SYNC 478 bool isSyncDeleted() override; 479 std::string getLocalPath() override; 480 #endif 481 482 static MegaNode *fromNode(Node *node); 483 MegaNode *copy() override; 484 485 char *serialize() override; 486 bool serialize(string*) override; 487 static MegaNodePrivate* unserialize(string*); 488 489 protected: 490 MegaNodePrivate(Node *node); 491 int type; 492 const char *name; 493 const char *fingerprint; 494 const char *originalfingerprint; 495 attr_map *customAttrs; 496 int64_t size; 497 int64_t ctime; 498 int64_t mtime; 499 MegaHandle nodehandle; 500 MegaHandle parenthandle; 501 MegaHandle restorehandle; 502 std::string nodekey; 503 std::string attrstring; 504 std::string fileattrstring; 505 std::string privateAuth; 506 std::string publicAuth; 507 const char *chatAuth; 508 int tag; 509 int changed; 510 struct { 511 bool thumbnailAvailable : 1; 512 bool previewAvailable : 1; 513 bool isPublicNode : 1; 514 bool outShares : 1; 515 bool inShare : 1; 516 bool foreign : 1; 517 }; 518 PublicLink *plink; 519 bool mNewLinkFormat; 520 std::string *sharekey; // for plinks of folders 521 int duration; 522 int width; 523 int height; 524 int shortformat; 525 int videocodecid; 526 double latitude; 527 double longitude; 528 MegaNodeList *children; 529 MegaHandle owner; 530 531 #ifdef ENABLE_SYNC 532 bool syncdeleted; 533 std::string localPath; 534 #endif 535 }; 536 537 538 class MegaUserPrivate : public MegaUser 539 { 540 public: 541 MegaUserPrivate(User *user); 542 MegaUserPrivate(MegaUser *user); 543 static MegaUser *fromUser(User *user); 544 virtual MegaUser *copy(); 545 546 ~MegaUserPrivate(); 547 virtual const char* getEmail(); 548 virtual MegaHandle getHandle(); 549 virtual int getVisibility(); 550 virtual int64_t getTimestamp(); 551 virtual bool hasChanged(int changeType); 552 virtual int getChanges(); 553 virtual int isOwnChange(); 554 555 protected: 556 const char *email; 557 MegaHandle handle; 558 int visibility; 559 int64_t ctime; 560 int changed; 561 int tag; 562 }; 563 564 class MegaUserAlertPrivate : public MegaUserAlert 565 { 566 public: 567 MegaUserAlertPrivate(UserAlert::Base* user, MegaClient* mc); 568 //MegaUserAlertPrivate(const MegaUserAlertPrivate&); // default copy works for this type 569 virtual MegaUserAlert* copy() const; 570 571 virtual unsigned getId() const; 572 virtual bool getSeen() const; 573 virtual bool getRelevant() const; 574 virtual int getType() const; 575 virtual const char *getTypeString() const; 576 virtual MegaHandle getUserHandle() const; 577 virtual MegaHandle getNodeHandle() const; 578 virtual const char* getEmail() const; 579 virtual const char* getPath() const; 580 virtual const char* getName() const; 581 virtual const char* getHeading() const; 582 virtual const char* getTitle() const; 583 virtual int64_t getNumber(unsigned index) const; 584 virtual int64_t getTimestamp(unsigned index) const; 585 virtual const char* getString(unsigned index) const; 586 virtual bool isOwnChange() const; 587 588 protected: 589 unsigned id; 590 bool seen; 591 bool relevant; 592 int type; 593 int tag; 594 string heading; 595 string title; 596 handle userHandle; 597 string email; 598 handle nodeHandle; 599 string nodePath; 600 string nodeName; 601 vector<int64_t> numbers; 602 vector<int64_t> timestamps; 603 vector<string> extraStrings; 604 }; 605 606 class MegaHandleListPrivate : public MegaHandleList 607 { 608 public: 609 MegaHandleListPrivate(); 610 MegaHandleListPrivate(const MegaHandleListPrivate *hList); 611 virtual ~MegaHandleListPrivate(); 612 613 virtual MegaHandleList *copy() const; 614 virtual MegaHandle get(unsigned int i) const; 615 virtual unsigned int size() const; 616 virtual void addMegaHandle(MegaHandle megaHandle); 617 618 private: 619 std::vector<MegaHandle> mList; 620 }; 621 622 class MegaIntegerListPrivate : public MegaIntegerList 623 { 624 public: 625 MegaIntegerListPrivate(const vector<int64_t> &integers); 626 virtual ~MegaIntegerListPrivate(); 627 628 MegaIntegerList *copy() const override; 629 int64_t get(int i) const override; 630 int size() const override; 631 632 private: 633 vector<int64_t> mIntegers; 634 }; 635 636 class MegaSharePrivate : public MegaShare 637 { 638 public: 639 static MegaShare *fromShare(MegaHandle nodeMegaHandle, Share *share); 640 virtual MegaShare *copy(); 641 virtual ~MegaSharePrivate(); 642 virtual const char *getUser(); 643 virtual MegaHandle getNodeHandle(); 644 virtual int getAccess(); 645 virtual int64_t getTimestamp(); 646 virtual bool isPending(); 647 648 protected: 649 MegaSharePrivate(MegaHandle nodehandle, Share *share); 650 MegaSharePrivate(MegaShare *share); 651 652 MegaHandle nodehandle; 653 const char *user; 654 int access; 655 int64_t ts; 656 bool pending; 657 }; 658 659 class MegaTransferPrivate : public MegaTransfer, public Cacheable 660 { 661 public: 662 MegaTransferPrivate(int type, MegaTransferListener *listener = NULL); 663 MegaTransferPrivate(const MegaTransferPrivate *transfer); 664 virtual ~MegaTransferPrivate(); 665 666 MegaTransfer *copy() override; 667 Transfer *getTransfer() const; 668 void setTransfer(Transfer *transfer); 669 void setStartTime(int64_t startTime); 670 void setTransferredBytes(long long transferredBytes); 671 void setTotalBytes(long long totalBytes); 672 void setPath(const char* path); 673 void setParentPath(const char* path); 674 void setNodeHandle(MegaHandle nodeHandle); 675 void setParentHandle(MegaHandle parentHandle); 676 void setNumConnections(int connections); 677 void setStartPos(long long startPos); 678 void setEndPos(long long endPos); 679 void setNumRetry(int retry); 680 void setMaxRetries(int retry); 681 void setTime(int64_t time); 682 void setFileName(const char* fileName); 683 void setSlot(int id); 684 void setTag(int tag); 685 void setSpeed(long long speed); 686 void setMeanSpeed(long long meanSpeed); 687 void setDeltaSize(long long deltaSize); 688 void setUpdateTime(int64_t updateTime); 689 void setPublicNode(MegaNode *publicNode, bool copyChildren = false); 690 void setSyncTransfer(bool syncTransfer); 691 void setSourceFileTemporary(bool temporary); 692 void setStartFirst(bool startFirst); 693 void setBackupTransfer(bool backupTransfer); 694 void setForeignOverquota(bool backupTransfer); 695 void setStreamingTransfer(bool streamingTransfer); 696 void setLastBytes(char *lastBytes); 697 void setLastError(const MegaError *e); 698 void setFolderTransferTag(int tag); 699 void setNotificationNumber(long long notificationNumber); 700 void setListener(MegaTransferListener *listener); 701 702 int getType() const override; 703 const char * getTransferString() const override; 704 const char* toString() const override; 705 const char* __str__() const override; 706 const char* __toString() const override; 707 virtual int64_t getStartTime() const override; 708 long long getTransferredBytes() const override; 709 long long getTotalBytes() const override; 710 const char* getPath() const override; 711 const char* getParentPath() const override; 712 MegaHandle getNodeHandle() const override; 713 MegaHandle getParentHandle() const override; 714 long long getStartPos() const override; 715 long long getEndPos() const override; 716 const char* getFileName() const override; 717 MegaTransferListener* getListener() const override; 718 int getNumRetry() const override; 719 int getMaxRetries() const override; 720 virtual int64_t getTime() const; 721 int getTag() const override; 722 long long getSpeed() const override; 723 long long getMeanSpeed() const override; 724 long long getDeltaSize() const override; 725 int64_t getUpdateTime() const override; 726 virtual MegaNode *getPublicNode() const; 727 MegaNode *getPublicMegaNode() const override; 728 bool isSyncTransfer() const override; 729 bool isStreamingTransfer() const override; 730 bool isFinished() const override; 731 virtual bool isSourceFileTemporary() const; 732 virtual bool shouldStartFirst() const; 733 bool isBackupTransfer() const override; 734 bool isForeignOverquota() const override; 735 char *getLastBytes() const override; 736 MegaError getLastError() const override; 737 const MegaError *getLastErrorExtended() const override; 738 bool isFolderTransfer() const override; 739 int getFolderTransferTag() const override; 740 virtual void setAppData(const char *data); 741 const char* getAppData() const override; 742 virtual void setState(int state); 743 int getState() const override; 744 virtual void setPriority(unsigned long long p); 745 unsigned long long getPriority() const override; 746 long long getNotificationNumber() const override; 747 748 bool serialize(string*) override; 749 static MegaTransferPrivate* unserialize(string*); 750 751 void startRecursiveOperation(unique_ptr<MegaRecursiveOperation>, MegaNode* node); // takes ownership of both 752 753 long long getPlaceInQueue() const; 754 void setPlaceInQueue(long long value); 755 756 protected: 757 int type; 758 int tag; 759 int state; 760 uint64_t priority; 761 762 struct 763 { 764 bool syncTransfer : 1; 765 bool streamingTransfer : 1; 766 bool temporarySourceFile : 1; 767 bool startFirst : 1; 768 bool backupTransfer : 1; 769 bool foreignOverquota : 1; 770 }; 771 772 int64_t startTime; 773 int64_t updateTime; 774 int64_t time; 775 long long transferredBytes; 776 long long totalBytes; 777 long long speed; 778 long long meanSpeed; 779 long long deltaSize; 780 long long notificationNumber; 781 MegaHandle nodeHandle; 782 MegaHandle parentHandle; 783 const char* path; 784 const char* parentPath; //used as targetUser for uploads 785 const char* fileName; 786 char *lastBytes; 787 MegaNode *publicNode; 788 long long startPos; 789 long long endPos; 790 int retry; 791 int maxRetries; 792 793 long long placeInQueue = 0; 794 795 MegaTransferListener *listener; 796 Transfer *transfer = nullptr; 797 std::unique_ptr<MegaError> lastError; 798 int folderTransferTag; 799 const char* appData; 800 unique_ptr<MegaRecursiveOperation> recursiveOperation; 801 }; 802 803 class MegaTransferDataPrivate : public MegaTransferData 804 { 805 public: 806 MegaTransferDataPrivate(TransferList *transferList, long long notificationNumber); 807 MegaTransferDataPrivate(const MegaTransferDataPrivate *transferData); 808 809 virtual ~MegaTransferDataPrivate(); 810 virtual MegaTransferData *copy() const; 811 virtual int getNumDownloads() const; 812 virtual int getNumUploads() const; 813 virtual int getDownloadTag(int i) const; 814 virtual int getUploadTag(int i) const; 815 virtual unsigned long long getDownloadPriority(int i) const; 816 virtual unsigned long long getUploadPriority(int i) const; 817 virtual long long getNotificationNumber() const; 818 819 protected: 820 int numDownloads; 821 int numUploads; 822 long long notificationNumber; 823 vector<int> downloadTags; 824 vector<int> uploadTags; 825 vector<uint64_t> downloadPriorities; 826 vector<uint64_t> uploadPriorities; 827 }; 828 829 class MegaFolderInfoPrivate : public MegaFolderInfo 830 { 831 public: 832 MegaFolderInfoPrivate(int numFiles, int numFolders, int numVersions, long long currentSize, long long versionsSize); 833 MegaFolderInfoPrivate(const MegaFolderInfoPrivate *folderData); 834 835 virtual ~MegaFolderInfoPrivate(); 836 837 virtual MegaFolderInfo *copy() const; 838 839 virtual int getNumVersions() const; 840 virtual int getNumFiles() const; 841 virtual int getNumFolders() const; 842 virtual long long getCurrentSize() const; 843 virtual long long getVersionsSize() const; 844 845 protected: 846 int numFiles; 847 int numFolders; 848 int numVersions; 849 long long currentSize; 850 long long versionsSize; 851 }; 852 853 class MegaTimeZoneDetailsPrivate : public MegaTimeZoneDetails 854 { 855 public: 856 MegaTimeZoneDetailsPrivate(vector<string>* timeZones, vector<int> *timeZoneOffsets, int defaultTimeZone); 857 MegaTimeZoneDetailsPrivate(const MegaTimeZoneDetailsPrivate *timeZoneDetails); 858 859 virtual ~MegaTimeZoneDetailsPrivate(); 860 virtual MegaTimeZoneDetails *copy() const; 861 862 virtual int getNumTimeZones() const; 863 virtual const char *getTimeZone(int index) const; 864 virtual int getTimeOffset(int index) const; 865 virtual int getDefault() const; 866 867 protected: 868 int defaultTimeZone; 869 vector<string> timeZones; 870 vector<int> timeZoneOffsets; 871 }; 872 873 class MegaPushNotificationSettingsPrivate : public MegaPushNotificationSettings 874 { 875 public: 876 MegaPushNotificationSettingsPrivate(const std::string &settingsJSON); 877 MegaPushNotificationSettingsPrivate(); 878 MegaPushNotificationSettingsPrivate(const MegaPushNotificationSettingsPrivate *settings); 879 880 std::string generateJson() const; 881 bool isValid() const; 882 883 virtual ~MegaPushNotificationSettingsPrivate(); 884 MegaPushNotificationSettings *copy() const override; 885 886 private: 887 m_time_t mGlobalDND = -1; // defaults to -1 if not defined 888 int mGlobalScheduleStart = -1; // defaults to -1 if not defined 889 int mGlobalScheduleEnd = -1; // defaults to -1 if not defined 890 std::string mGlobalScheduleTimezone; 891 892 std::map<MegaHandle, m_time_t> mChatDND; 893 std::map<MegaHandle, bool> mChatAlwaysNotify; 894 895 m_time_t mContactsDND = -1; // defaults to -1 if not defined 896 m_time_t mSharesDND = -1; // defaults to -1 if not defined 897 m_time_t mGlobalChatsDND = -1; // defaults to -1 if not defined 898 899 bool mJsonInvalid = false; // true if ctor from JSON find issues 900 901 public: 902 903 // getters 904 905 bool isGlobalEnabled() const override; 906 bool isGlobalDndEnabled() const override; 907 bool isGlobalChatsDndEnabled() const override; 908 int64_t getGlobalDnd() const override; 909 int64_t getGlobalChatsDnd() const override; 910 bool isGlobalScheduleEnabled() const override; 911 int getGlobalScheduleStart() const override; 912 int getGlobalScheduleEnd() const override; 913 const char *getGlobalScheduleTimezone() const override; 914 915 bool isChatEnabled(MegaHandle chatid) const override; 916 bool isChatDndEnabled(MegaHandle chatid) const override; 917 int64_t getChatDnd(MegaHandle chatid) const override; 918 bool isChatAlwaysNotifyEnabled(MegaHandle chatid) const override; 919 920 bool isContactsEnabled() const override; 921 bool isSharesEnabled() const override; 922 bool isChatsEnabled() const override; 923 924 // setters 925 926 void enableGlobal(bool enable) override; 927 void setGlobalDnd(int64_t timestamp) override; 928 void disableGlobalDnd() override; 929 void setGlobalSchedule(int start, int end, const char *timezone) override; 930 void disableGlobalSchedule() override; 931 932 void enableChat(MegaHandle chatid, bool enable) override; 933 void setChatDnd(MegaHandle chatid, int64_t timestamp) override; 934 void setGlobalChatsDnd(int64_t timestamp) override; 935 void enableChatAlwaysNotify(MegaHandle chatid, bool enable) override; 936 937 void enableContacts(bool enable) override; 938 void enableShares(bool enable) override; 939 void enableChats(bool enable) override; 940 }; 941 942 class MegaContactRequestPrivate : public MegaContactRequest 943 { 944 public: 945 MegaContactRequestPrivate(PendingContactRequest *request); 946 MegaContactRequestPrivate(const MegaContactRequest *request); 947 virtual ~MegaContactRequestPrivate(); 948 949 static MegaContactRequest *fromContactRequest(PendingContactRequest *request); 950 virtual MegaContactRequest *copy() const; 951 952 virtual MegaHandle getHandle() const; 953 virtual char* getSourceEmail() const; 954 virtual char* getSourceMessage() const; 955 virtual char* getTargetEmail() const; 956 virtual int64_t getCreationTime() const; 957 virtual int64_t getModificationTime() const; 958 virtual int getStatus() const; 959 virtual bool isOutgoing() const; 960 virtual bool isAutoAccepted() const; 961 962 protected: 963 MegaHandle handle; 964 char* sourceEmail; 965 char* sourceMessage; 966 char* targetEmail; 967 int64_t creationTime; 968 int64_t modificationTime; 969 int status; 970 bool outgoing; 971 bool autoaccepted; 972 }; 973 974 #ifdef ENABLE_SYNC 975 976 class MegaSyncEventPrivate: public MegaSyncEvent 977 { 978 public: 979 explicit MegaSyncEventPrivate(int type); 980 981 MegaSyncEvent *copy() override; 982 983 int getType() const override; 984 const char *getPath() const override; 985 MegaHandle getNodeHandle() const override; 986 const char *getNewPath() const override; 987 const char* getPrevName() const override; 988 MegaHandle getPrevParent() const override; 989 990 void setPath(const char* path); 991 void setNodeHandle(MegaHandle nodeHandle); 992 void setNewPath(const char* newPath); 993 void setPrevName(const char* prevName); 994 void setPrevParent(MegaHandle prevParent); 995 996 protected: 997 int type; 998 std::unique_ptr<char[]> path; 999 std::unique_ptr<char[]> newPath; 1000 std::unique_ptr<char[]> prevName; 1001 MegaHandle nodeHandle = INVALID_HANDLE; 1002 MegaHandle prevParent = INVALID_HANDLE; 1003 }; 1004 1005 class MegaRegExpPrivate 1006 { 1007 public: 1008 MegaRegExpPrivate(); 1009 ~MegaRegExpPrivate(); 1010 1011 MegaRegExpPrivate *copy(); 1012 1013 bool addRegExp(const char *regExp); 1014 int getNumRegExp(); 1015 const char *getRegExp(int index); 1016 bool match(const char *s); 1017 const char *getFullPattern(); 1018 1019 private: 1020 enum{ 1021 REGEXP_NO_ERROR = 0, 1022 REGEXP_COMPILATION_ERROR, 1023 REGEXP_OPTIMIZATION_ERROR, 1024 REGEXP_EMPTY 1025 }; 1026 int compile(); 1027 bool updatePattern(); 1028 bool checkRegExp(const char *regExp); 1029 bool isPatternUpdated(); 1030 1031 private: 1032 std::vector<std::string> regExps; 1033 std::string pattern; 1034 bool patternUpdated; 1035 1036 #ifdef USE_PCRE 1037 int options; 1038 pcre* reCompiled; 1039 pcre_extra* reOptimization; 1040 #endif 1041 }; 1042 1043 class MegaSyncPrivate : public MegaSync 1044 { 1045 public: 1046 MegaSyncPrivate(const char *path, handle nodehandle, int tag); 1047 MegaSyncPrivate(MegaSyncPrivate *sync); 1048 1049 virtual ~MegaSyncPrivate(); 1050 1051 virtual MegaSync *copy(); 1052 1053 virtual MegaHandle getMegaHandle() const; 1054 void setMegaHandle(MegaHandle handle); 1055 virtual const char* getLocalFolder() const; 1056 void setLocalFolder(const char*path); 1057 virtual long long getLocalFingerprint() const; 1058 void setLocalFingerprint(long long fingerprint); 1059 virtual int getTag() const; 1060 void setTag(int tag); 1061 void setListener(MegaSyncListener *listener); 1062 MegaSyncListener *getListener(); 1063 virtual int getState() const; 1064 void setState(int state); 1065 virtual MegaRegExp* getRegExp() const; 1066 void setRegExp(MegaRegExp *regExp); 1067 1068 protected: 1069 MegaHandle megaHandle; 1070 char *localFolder; 1071 MegaRegExp *regExp; 1072 int tag; 1073 long long fingerprint; 1074 MegaSyncListener *listener; 1075 int state; 1076 }; 1077 1078 #endif 1079 1080 1081 class MegaPricingPrivate; 1082 class MegaRequestPrivate : public MegaRequest 1083 { 1084 public: 1085 MegaRequestPrivate(int type, MegaRequestListener *listener = NULL); 1086 MegaRequestPrivate(MegaRequestPrivate *request); 1087 1088 virtual ~MegaRequestPrivate(); 1089 MegaRequest *copy() override; 1090 void setNodeHandle(MegaHandle nodeHandle); 1091 void setLink(const char* link); 1092 void setParentHandle(MegaHandle parentHandle); 1093 void setSessionKey(const char* sessionKey); 1094 void setName(const char* name); 1095 void setEmail(const char* email); 1096 void setPassword(const char* email); 1097 void setNewPassword(const char* email); 1098 void setPrivateKey(const char* privateKey); 1099 void setAccess(int access); 1100 void setNumRetry(int ds); 1101 void setNextRetryDelay(int delay); 1102 void setPublicNode(MegaNode* publicNode, bool copyChildren = false); 1103 void setNumDetails(int numDetails); 1104 void setFile(const char* file); 1105 void setParamType(int type); 1106 void setText(const char* text); 1107 void setNumber(long long number); 1108 void setFlag(bool flag); 1109 void setTransferTag(int transfer); 1110 void setListener(MegaRequestListener *listener); 1111 void setTotalBytes(long long totalBytes); 1112 void setTransferredBytes(long long transferredBytes); 1113 void setTag(int tag); 1114 void addProduct(unsigned int type, handle product, int proLevel, int gbStorage, int gbTransfer, 1115 int months, int amount, int amountMonth, const char *currency, const char *description, const char *iosid, const char *androidid); 1116 void setProxy(Proxy *proxy); 1117 Proxy *getProxy(); 1118 void setTimeZoneDetails(MegaTimeZoneDetails *timeZoneDetails); 1119 1120 int getType() const override; 1121 const char *getRequestString() const override; 1122 const char* toString() const override; 1123 const char* __str__() const override; 1124 const char* __toString() const override; 1125 MegaHandle getNodeHandle() const override; 1126 const char* getLink() const override; 1127 MegaHandle getParentHandle() const override; 1128 const char* getSessionKey() const override; 1129 const char* getName() const override; 1130 const char* getEmail() const override; 1131 const char* getPassword() const override; 1132 const char* getNewPassword() const override; 1133 const char* getPrivateKey() const override; 1134 int getAccess() const override; 1135 const char* getFile() const override; 1136 int getNumRetry() const override; 1137 MegaNode *getPublicNode() const override; 1138 MegaNode *getPublicMegaNode() const override; 1139 int getParamType() const override; 1140 const char *getText() const override; 1141 long long getNumber() const override; 1142 bool getFlag() const override; 1143 long long getTransferredBytes() const override; 1144 long long getTotalBytes() const override; 1145 MegaRequestListener *getListener() const override; 1146 MegaAccountDetails *getMegaAccountDetails() const override; 1147 int getTransferTag() const override; 1148 int getNumDetails() const override; 1149 int getTag() const override; 1150 MegaPricing *getPricing() const override; 1151 AccountDetails * getAccountDetails() const; 1152 MegaAchievementsDetails *getMegaAchievementsDetails() const override; 1153 AchievementsDetails *getAchievementsDetails() const; 1154 MegaTimeZoneDetails *getMegaTimeZoneDetails () const override; 1155 1156 #ifdef ENABLE_CHAT 1157 MegaTextChatPeerList *getMegaTextChatPeerList() const override; 1158 void setMegaTextChatPeerList(MegaTextChatPeerList *chatPeers); 1159 MegaTextChatList *getMegaTextChatList() const override; 1160 void setMegaTextChatList(MegaTextChatList *chatList); 1161 #endif 1162 MegaStringMap *getMegaStringMap() const override; 1163 void setMegaStringMap(const MegaStringMap *); 1164 MegaStringListMap *getMegaStringListMap() const override; 1165 void setMegaStringListMap(const MegaStringListMap *stringListMap); 1166 MegaStringTable *getMegaStringTable() const override; 1167 void setMegaStringTable(const MegaStringTable *stringTable); 1168 MegaFolderInfo *getMegaFolderInfo() const override; 1169 void setMegaFolderInfo(const MegaFolderInfo *); 1170 const MegaPushNotificationSettings *getMegaPushNotificationSettings() const override; 1171 void setMegaPushNotificationSettings(const MegaPushNotificationSettings *settings); 1172 MegaBackgroundMediaUpload *getMegaBackgroundMediaUploadPtr() const override; 1173 void setMegaBackgroundMediaUploadPtr(MegaBackgroundMediaUpload *); // non-owned pointer 1174 1175 #ifdef ENABLE_SYNC 1176 void setSyncListener(MegaSyncListener *syncListener); 1177 MegaSyncListener *getSyncListener() const; 1178 void setRegExp(MegaRegExp *regExp); 1179 virtual MegaRegExp *getRegExp() const; 1180 #endif 1181 1182 MegaBackupListener *getBackupListener() const; 1183 void setBackupListener(MegaBackupListener *value); 1184 1185 protected: 1186 AccountDetails *accountDetails; 1187 MegaPricingPrivate *megaPricing; 1188 AchievementsDetails *achievementsDetails; 1189 MegaTimeZoneDetails *timeZoneDetails; 1190 int type; 1191 MegaHandle nodeHandle; 1192 const char* link; 1193 const char* name; 1194 MegaHandle parentHandle; 1195 const char* sessionKey; 1196 const char* email; 1197 const char* password; 1198 const char* newPassword; 1199 const char* privateKey; 1200 const char* text; 1201 long long number; 1202 int access; 1203 const char* file; 1204 int attrType; 1205 bool flag; 1206 long long totalBytes; 1207 long long transferredBytes; 1208 MegaRequestListener *listener; 1209 #ifdef ENABLE_SYNC 1210 MegaSyncListener *syncListener; 1211 MegaRegExp *regExp; 1212 #endif 1213 MegaBackupListener *backupListener; 1214 1215 int transfer; 1216 int numDetails; 1217 MegaNode* publicNode; 1218 int numRetry; 1219 int tag; 1220 Proxy *proxy; 1221 1222 #ifdef ENABLE_CHAT 1223 MegaTextChatPeerList *chatPeerList; 1224 MegaTextChatList *chatList; 1225 #endif 1226 MegaStringMap *stringMap; 1227 MegaStringListMap *mStringListMap; 1228 MegaStringTable *mStringTable; 1229 MegaFolderInfo *folderInfo; 1230 MegaPushNotificationSettings *settings; 1231 MegaBackgroundMediaUpload* backgroundMediaUpload; // non-owned pointer 1232 }; 1233 1234 class MegaEventPrivate : public MegaEvent 1235 { 1236 public: 1237 MegaEventPrivate(int type); 1238 MegaEventPrivate(MegaEventPrivate *event); 1239 virtual ~MegaEventPrivate(); 1240 MegaEvent *copy() override; 1241 1242 int getType() const override; 1243 const char *getText() const override; 1244 int64_t getNumber() const override; 1245 MegaHandle getHandle() const override; 1246 const char *getEventString() const override; 1247 1248 static const char* getEventString(int type); 1249 1250 void setText(const char* text); 1251 void setNumber(int64_t number); 1252 void setHandle(const MegaHandle &handle); 1253 1254 protected: 1255 int type; 1256 const char* text; 1257 int64_t number; 1258 MegaHandle mHandle; 1259 }; 1260 1261 class MegaAccountBalancePrivate : public MegaAccountBalance 1262 { 1263 public: 1264 static MegaAccountBalance *fromAccountBalance(const AccountBalance *balance); 1265 virtual ~MegaAccountBalancePrivate() ; 1266 virtual MegaAccountBalance* copy(); 1267 1268 virtual double getAmount() const; 1269 virtual char* getCurrency() const; 1270 1271 protected: 1272 MegaAccountBalancePrivate(const AccountBalance *balance); 1273 AccountBalance balance; 1274 }; 1275 1276 class MegaAccountSessionPrivate : public MegaAccountSession 1277 { 1278 public: 1279 static MegaAccountSession *fromAccountSession(const AccountSession *session); 1280 virtual ~MegaAccountSessionPrivate() ; 1281 virtual MegaAccountSession* copy(); 1282 1283 virtual int64_t getCreationTimestamp() const; 1284 virtual int64_t getMostRecentUsage() const; 1285 virtual char *getUserAgent() const; 1286 virtual char *getIP() const; 1287 virtual char *getCountry() const; 1288 virtual bool isCurrent() const; 1289 virtual bool isAlive() const; 1290 virtual MegaHandle getHandle() const; 1291 1292 private: 1293 MegaAccountSessionPrivate(const AccountSession *session); 1294 AccountSession session; 1295 }; 1296 1297 class MegaAccountPurchasePrivate : public MegaAccountPurchase 1298 { 1299 public: 1300 static MegaAccountPurchase *fromAccountPurchase(const AccountPurchase *purchase); 1301 virtual ~MegaAccountPurchasePrivate() ; 1302 virtual MegaAccountPurchase* copy(); 1303 1304 virtual int64_t getTimestamp() const; 1305 virtual char *getHandle() const; 1306 virtual char *getCurrency() const; 1307 virtual double getAmount() const; 1308 virtual int getMethod() const; 1309 1310 private: 1311 MegaAccountPurchasePrivate(const AccountPurchase *purchase); 1312 AccountPurchase purchase; 1313 }; 1314 1315 class MegaAccountTransactionPrivate : public MegaAccountTransaction 1316 { 1317 public: 1318 static MegaAccountTransaction *fromAccountTransaction(const AccountTransaction *transaction); 1319 virtual ~MegaAccountTransactionPrivate() ; 1320 virtual MegaAccountTransaction* copy(); 1321 1322 virtual int64_t getTimestamp() const; 1323 virtual char *getHandle() const; 1324 virtual char *getCurrency() const; 1325 virtual double getAmount() const; 1326 1327 private: 1328 MegaAccountTransactionPrivate(const AccountTransaction *transaction); 1329 AccountTransaction transaction; 1330 }; 1331 1332 class MegaAccountDetailsPrivate : public MegaAccountDetails 1333 { 1334 public: 1335 static MegaAccountDetails *fromAccountDetails(AccountDetails *details); 1336 virtual ~MegaAccountDetailsPrivate(); 1337 1338 virtual int getProLevel(); 1339 virtual int64_t getProExpiration(); 1340 virtual int getSubscriptionStatus(); 1341 virtual int64_t getSubscriptionRenewTime(); 1342 virtual char* getSubscriptionMethod(); 1343 virtual char* getSubscriptionCycle(); 1344 1345 virtual long long getStorageMax(); 1346 virtual long long getStorageUsed(); 1347 virtual long long getVersionStorageUsed(); 1348 virtual long long getTransferMax(); 1349 virtual long long getTransferOwnUsed(); 1350 virtual long long getTransferSrvUsed(); 1351 virtual long long getTransferUsed(); 1352 1353 virtual int getNumUsageItems(); 1354 virtual long long getStorageUsed(MegaHandle handle); 1355 virtual long long getNumFiles(MegaHandle handle); 1356 virtual long long getNumFolders(MegaHandle handle); 1357 virtual long long getVersionStorageUsed(MegaHandle handle); 1358 virtual long long getNumVersionFiles(MegaHandle handle); 1359 1360 virtual MegaAccountDetails* copy(); 1361 1362 virtual int getNumBalances() const; 1363 virtual MegaAccountBalance* getBalance(int i) const; 1364 1365 virtual int getNumSessions() const; 1366 virtual MegaAccountSession* getSession(int i) const; 1367 1368 virtual int getNumPurchases() const; 1369 virtual MegaAccountPurchase* getPurchase(int i) const; 1370 1371 virtual int getNumTransactions() const; 1372 virtual MegaAccountTransaction* getTransaction(int i) const; 1373 1374 virtual int getTemporalBandwidthInterval(); 1375 virtual long long getTemporalBandwidth(); 1376 virtual bool isTemporalBandwidthValid(); 1377 1378 private: 1379 MegaAccountDetailsPrivate(AccountDetails *details); 1380 AccountDetails details; 1381 }; 1382 1383 class MegaPricingPrivate : public MegaPricing 1384 { 1385 public: 1386 virtual ~MegaPricingPrivate(); 1387 virtual int getNumProducts(); 1388 virtual MegaHandle getHandle(int productIndex); 1389 virtual int getProLevel(int productIndex); 1390 virtual int getGBStorage(int productIndex); 1391 virtual int getGBTransfer(int productIndex); 1392 virtual int getMonths(int productIndex); 1393 virtual int getAmount(int productIndex); 1394 virtual const char* getCurrency(int productIndex); 1395 virtual const char* getDescription(int productIndex); 1396 virtual const char* getIosID(int productIndex); 1397 virtual const char* getAndroidID(int productIndex); 1398 virtual bool isBusinessType(int productIndex); 1399 virtual int getAmountMonth(int productIndex); 1400 virtual MegaPricing *copy(); 1401 1402 void addProduct(unsigned int type, handle product, int proLevel, int gbStorage, int gbTransfer, 1403 int months, int amount, int amountMonth, const char *currency, const char *description, const char *iosid, const char *androidid); 1404 private: 1405 vector<unsigned int> type; 1406 vector<handle> handles; 1407 vector<int> proLevel; 1408 vector<int> gbStorage; 1409 vector<int> gbTransfer; 1410 vector<int> months; 1411 vector<int> amount; 1412 vector<int> amountMonth; 1413 vector<const char *> currency; 1414 vector<const char *> description; 1415 vector<const char *> iosId; 1416 vector<const char *> androidId; 1417 }; 1418 1419 class MegaAchievementsDetailsPrivate : public MegaAchievementsDetails 1420 { 1421 public: 1422 static MegaAchievementsDetails *fromAchievementsDetails(AchievementsDetails *details); 1423 virtual ~MegaAchievementsDetailsPrivate(); 1424 1425 virtual MegaAchievementsDetails* copy(); 1426 1427 virtual long long getBaseStorage(); 1428 virtual long long getClassStorage(int class_id); 1429 virtual long long getClassTransfer(int class_id); 1430 virtual int getClassExpire(int class_id); 1431 virtual unsigned int getAwardsCount(); 1432 virtual int getAwardClass(unsigned int index); 1433 virtual int getAwardId(unsigned int index); 1434 virtual int64_t getAwardTimestamp(unsigned int index); 1435 virtual int64_t getAwardExpirationTs(unsigned int index); 1436 virtual MegaStringList* getAwardEmails(unsigned int index); 1437 virtual int getRewardsCount(); 1438 virtual int getRewardAwardId(unsigned int index); 1439 virtual long long getRewardStorage(unsigned int index); 1440 virtual long long getRewardTransfer(unsigned int index); 1441 virtual long long getRewardStorageByAwardId(int award_id); 1442 virtual long long getRewardTransferByAwardId(int award_id); 1443 virtual int getRewardExpire(unsigned int index); 1444 1445 virtual long long currentStorage(); 1446 virtual long long currentTransfer(); 1447 virtual long long currentStorageReferrals(); 1448 virtual long long currentTransferReferrals(); 1449 1450 private: 1451 MegaAchievementsDetailsPrivate(AchievementsDetails *details); 1452 AchievementsDetails details; 1453 }; 1454 1455 class MegaCancelTokenPrivate : public MegaCancelToken 1456 { 1457 public: 1458 ~MegaCancelTokenPrivate() override; 1459 1460 void cancel(bool newValue = true) override; 1461 bool isCancelled() const override; 1462 1463 private: 1464 std::atomic_bool cancelFlag { false }; 1465 }; 1466 1467 #ifdef ENABLE_CHAT 1468 class MegaTextChatPeerListPrivate : public MegaTextChatPeerList 1469 { 1470 public: 1471 MegaTextChatPeerListPrivate(); 1472 MegaTextChatPeerListPrivate(userpriv_vector *); 1473 1474 virtual ~MegaTextChatPeerListPrivate(); 1475 virtual MegaTextChatPeerList *copy() const; 1476 virtual void addPeer(MegaHandle h, int priv); 1477 virtual MegaHandle getPeerHandle(int i) const; 1478 virtual int getPeerPrivilege(int i) const; 1479 virtual int size() const; 1480 1481 // returns the list of user-privilege (this object keeps the ownership) 1482 const userpriv_vector * getList() const; 1483 1484 void setPeerPrivilege(handle uh, privilege_t priv); 1485 1486 private: 1487 userpriv_vector list; 1488 }; 1489 1490 class MegaTextChatPrivate : public MegaTextChat 1491 { 1492 public: 1493 MegaTextChatPrivate(const MegaTextChat *); 1494 MegaTextChatPrivate(const TextChat *); 1495 1496 virtual ~MegaTextChatPrivate(); 1497 virtual MegaTextChat *copy() const; 1498 1499 virtual MegaHandle getHandle() const; 1500 virtual int getOwnPrivilege() const; 1501 virtual int getShard() const; 1502 virtual const MegaTextChatPeerList *getPeerList() const; 1503 virtual void setPeerList(const MegaTextChatPeerList *peers); 1504 virtual bool isGroup() const; 1505 virtual MegaHandle getOriginatingUser() const; 1506 virtual const char *getTitle() const; 1507 virtual const char *getUnifiedKey() const; 1508 virtual int64_t getCreationTime() const; 1509 virtual bool isArchived() const; 1510 virtual bool isPublicChat() const; 1511 1512 virtual bool hasChanged(int changeType) const; 1513 virtual int getChanges() const; 1514 virtual int isOwnChange() const; 1515 1516 private: 1517 handle id; 1518 int priv; 1519 string url; 1520 int shard; 1521 MegaTextChatPeerList *peers; 1522 bool group; 1523 handle ou; 1524 string title; 1525 string unifiedKey; 1526 int changed; 1527 int tag; 1528 bool archived; 1529 bool publicchat; 1530 int64_t ts; 1531 }; 1532 1533 class MegaTextChatListPrivate : public MegaTextChatList 1534 { 1535 public: 1536 MegaTextChatListPrivate(); 1537 MegaTextChatListPrivate(textchat_map *list); 1538 1539 virtual ~MegaTextChatListPrivate(); 1540 virtual MegaTextChatList *copy() const; 1541 virtual const MegaTextChat *get(unsigned int i) const; 1542 virtual int size() const; 1543 1544 void addChat(MegaTextChatPrivate*); 1545 1546 private: 1547 MegaTextChatListPrivate(const MegaTextChatListPrivate*); 1548 vector<MegaTextChat*> list; 1549 }; 1550 1551 #endif 1552 1553 class MegaStringMapPrivate : public MegaStringMap 1554 { 1555 public: 1556 MegaStringMapPrivate(); 1557 MegaStringMapPrivate(const string_map *map, bool toBase64 = false); 1558 virtual ~MegaStringMapPrivate(); 1559 virtual MegaStringMap *copy() const; 1560 virtual const char *get(const char* key) const; 1561 virtual MegaStringList *getKeys() const; 1562 virtual void set(const char *key, const char *value); 1563 virtual int size() const; 1564 const string_map *getMap() const; 1565 1566 protected: 1567 MegaStringMapPrivate(const MegaStringMapPrivate *megaStringMap); 1568 string_map strMap; 1569 }; 1570 1571 1572 class MegaStringListPrivate : public MegaStringList 1573 { 1574 public: 1575 MegaStringListPrivate(); 1576 MegaStringListPrivate(char **newlist, int size); // takes ownership 1577 virtual ~MegaStringListPrivate(); 1578 MEGA_DISABLE_COPY_MOVE(MegaStringListPrivate) 1579 MegaStringList *copy() const override; 1580 const char* get(int i) const override; 1581 int size() const override; 1582 protected: 1583 MegaStringListPrivate(const MegaStringListPrivate *stringList); 1584 const char** list; 1585 int s; 1586 }; 1587 1588 bool operator==(const MegaStringList& lhs, const MegaStringList& rhs); 1589 1590 class MegaStringListMapPrivate : public MegaStringListMap 1591 { 1592 public: 1593 MegaStringListMapPrivate() = default; 1594 MEGA_DISABLE_COPY_MOVE(MegaStringListMapPrivate) 1595 MegaStringListMap* copy() const override; 1596 const MegaStringList* get(const char* key) const override; 1597 MegaStringList *getKeys() const override; 1598 void set(const char* key, const MegaStringList* value) override; // takes ownership of value 1599 int size() const override; 1600 protected: 1601 struct Compare 1602 { 1603 bool operator()(const std::unique_ptr<const char[]>& rhs, 1604 const std::unique_ptr<const char[]>& lhs) const; 1605 }; 1606 1607 map<std::unique_ptr<const char[]>, std::unique_ptr<const MegaStringList>, Compare> mMap; 1608 }; 1609 1610 class MegaStringTablePrivate : public MegaStringTable 1611 { 1612 public: 1613 MegaStringTablePrivate() = default; 1614 MEGA_DISABLE_COPY_MOVE(MegaStringTablePrivate) 1615 MegaStringTable* copy() const override; 1616 void append(const MegaStringList* value) override; // takes ownership of value 1617 const MegaStringList* get(int i) const override; 1618 int size() const override; 1619 protected: 1620 vector<std::unique_ptr<const MegaStringList>> mTable; 1621 }; 1622 1623 class MegaNodeListPrivate : public MegaNodeList 1624 { 1625 public: 1626 MegaNodeListPrivate(); 1627 MegaNodeListPrivate(node_vector& v); 1628 MegaNodeListPrivate(Node** newlist, int size); 1629 MegaNodeListPrivate(const MegaNodeListPrivate *nodeList, bool copyChildren = false); 1630 virtual ~MegaNodeListPrivate(); 1631 MegaNodeList *copy() const override; 1632 MegaNode* get(int i) const override; 1633 int size() const override; 1634 1635 void addNode(MegaNode* node) override; 1636 1637 protected: 1638 MegaNode** list; 1639 int s; 1640 }; 1641 1642 class MegaChildrenListsPrivate : public MegaChildrenLists 1643 { 1644 public: 1645 MegaChildrenListsPrivate(); 1646 MegaChildrenListsPrivate(MegaChildrenLists*); 1647 MegaChildrenListsPrivate(unique_ptr<MegaNodeListPrivate> folderList, unique_ptr<MegaNodeListPrivate> fileList); 1648 virtual MegaChildrenLists *copy(); 1649 virtual MegaNodeList* getFolderList(); 1650 virtual MegaNodeList* getFileList(); 1651 1652 protected: 1653 unique_ptr<MegaNodeList> folders; 1654 unique_ptr<MegaNodeList> files; 1655 }; 1656 1657 class MegaUserListPrivate : public MegaUserList 1658 { 1659 public: 1660 MegaUserListPrivate(); 1661 MegaUserListPrivate(User** newlist, int size); 1662 virtual ~MegaUserListPrivate(); 1663 virtual MegaUserList *copy(); 1664 virtual MegaUser* get(int i); 1665 virtual int size(); 1666 1667 protected: 1668 MegaUserListPrivate(MegaUserListPrivate *userList); 1669 MegaUser** list; 1670 int s; 1671 }; 1672 1673 class MegaShareListPrivate : public MegaShareList 1674 { 1675 public: 1676 MegaShareListPrivate(); 1677 MegaShareListPrivate(Share** newlist, MegaHandle *MegaHandlelist, int size); 1678 virtual ~MegaShareListPrivate(); 1679 virtual MegaShare* get(int i); 1680 virtual int size(); 1681 1682 protected: 1683 MegaShare** list; 1684 int s; 1685 }; 1686 1687 class MegaTransferListPrivate : public MegaTransferList 1688 { 1689 public: 1690 MegaTransferListPrivate(); 1691 MegaTransferListPrivate(MegaTransfer** newlist, int size); 1692 virtual ~MegaTransferListPrivate(); 1693 virtual MegaTransfer* get(int i); 1694 virtual int size(); 1695 1696 protected: 1697 MegaTransfer** list; 1698 int s; 1699 }; 1700 1701 class MegaContactRequestListPrivate : public MegaContactRequestList 1702 { 1703 public: 1704 MegaContactRequestListPrivate(); 1705 MegaContactRequestListPrivate(PendingContactRequest ** newlist, int size); 1706 virtual ~MegaContactRequestListPrivate(); 1707 virtual MegaContactRequestList *copy(); 1708 virtual MegaContactRequest* get(int i); 1709 virtual int size(); 1710 1711 protected: 1712 MegaContactRequestListPrivate(MegaContactRequestListPrivate *requestList); 1713 MegaContactRequest** list; 1714 int s; 1715 }; 1716 1717 class MegaUserAlertListPrivate : public MegaUserAlertList 1718 { 1719 public: 1720 MegaUserAlertListPrivate(); 1721 MegaUserAlertListPrivate(UserAlert::Base** newlist, int size, MegaClient* mc); 1722 MegaUserAlertListPrivate(const MegaUserAlertListPrivate &userList); 1723 virtual ~MegaUserAlertListPrivate(); 1724 virtual MegaUserAlertList *copy() const; 1725 virtual MegaUserAlert* get(int i) const; 1726 virtual int size() const; 1727 virtual void clear(); 1728 1729 protected: 1730 MegaUserAlertListPrivate(MegaUserAlertListPrivate *userList); 1731 MegaUserAlert** list; 1732 int s; 1733 }; 1734 1735 class MegaRecentActionBucketPrivate : public MegaRecentActionBucket 1736 { 1737 public: 1738 MegaRecentActionBucketPrivate(recentaction& ra, MegaClient* mc); 1739 MegaRecentActionBucketPrivate(int64_t timestamp, const string& user, handle parent, bool update, bool media, MegaNodeList*); 1740 virtual ~MegaRecentActionBucketPrivate(); 1741 virtual MegaRecentActionBucket *copy() const; 1742 virtual int64_t getTimestamp() const; 1743 virtual const char* getUserEmail() const; 1744 virtual MegaHandle getParentHandle() const; 1745 virtual bool isUpdate() const; 1746 virtual bool isMedia() const; 1747 virtual const MegaNodeList* getNodes() const; 1748 1749 private: 1750 int64_t timestamp; 1751 string user; 1752 handle parent; 1753 bool update, media; 1754 MegaNodeList* nodes; 1755 }; 1756 1757 class MegaRecentActionBucketListPrivate : public MegaRecentActionBucketList 1758 { 1759 public: 1760 MegaRecentActionBucketListPrivate(); 1761 MegaRecentActionBucketListPrivate(recentactions_vector& v, MegaClient* mc); 1762 MegaRecentActionBucketListPrivate(const MegaRecentActionBucketListPrivate &userList); 1763 virtual ~MegaRecentActionBucketListPrivate(); 1764 virtual MegaRecentActionBucketList *copy() const; 1765 virtual MegaRecentActionBucket* get(int i) const; 1766 virtual int size() const; 1767 1768 protected: 1769 MegaRecentActionBucketPrivate** list; 1770 int s; 1771 }; 1772 1773 class EncryptFilePieceByChunks : public EncryptByChunks 1774 { 1775 // specialisation for encrypting a piece of a file without using too much RAM 1776 FileAccess* fain; 1777 FileAccess* faout; 1778 m_off_t inpos, outpos; 1779 string buffer; 1780 unsigned lastsize; 1781 1782 public: 1783 1784 EncryptFilePieceByChunks(FileAccess* cFain, m_off_t cInPos, FileAccess* cFaout, m_off_t cOutPos, 1785 SymmCipher* cipher, chunkmac_map* chunkmacs, uint64_t ctriv); 1786 1787 byte* nextbuffer(unsigned bufsize) override; 1788 }; 1789 1790 class MegaBackgroundMediaUploadPrivate : public MegaBackgroundMediaUpload 1791 { 1792 public: 1793 MegaBackgroundMediaUploadPrivate(MegaApi* api); 1794 MegaBackgroundMediaUploadPrivate(const string& serialised, MegaApi* api); 1795 ~MegaBackgroundMediaUploadPrivate(); 1796 1797 bool analyseMediaInfo(const char* inputFilepath) override; 1798 char *encryptFile(const char* inputFilepath, int64_t startPos, m_off_t* length, const char *outputFilepath, 1799 bool adjustsizeonly) override; 1800 1801 char *getUploadURL() override; 1802 1803 bool serialize(string* s); 1804 char *serialize() override; 1805 1806 void setThumbnail(MegaHandle h) override; 1807 void setPreview(MegaHandle h) override; 1808 void setCoordinates(double lat, double lon, bool unshareable) override; 1809 1810 SymmCipher* nodecipher(MegaClient*); 1811 1812 MegaApiImpl* api; 1813 string url; 1814 chunkmac_map chunkmacs; 1815 byte filekey[FILENODEKEYLENGTH]; 1816 MediaProperties mediaproperties; 1817 1818 double latitude = MegaNode::INVALID_COORDINATE; 1819 double longitude = MegaNode::INVALID_COORDINATE; 1820 bool unshareableGPS = false; 1821 handle thumbnailFA = INVALID_HANDLE; 1822 handle previewFA = INVALID_HANDLE; 1823 }; 1824 1825 struct MegaFile : public File 1826 { 1827 MegaFile(); 1828 1829 void setTransfer(MegaTransferPrivate *transfer); 1830 MegaTransferPrivate *getTransfer(); 1831 bool serialize(string*) override; 1832 1833 static MegaFile* unserialize(string*); 1834 1835 protected: 1836 MegaTransferPrivate *megaTransfer; 1837 }; 1838 1839 struct MegaFileGet : public MegaFile 1840 { 1841 void prepare() override; 1842 void updatelocalname() override; 1843 void progress() override; 1844 void completed(Transfer*, LocalNode*) override; 1845 void terminated() override; 1846 MegaFileGet(MegaClient *client, Node* n, const LocalPath& dstPath, FileSystemType fsType); 1847 MegaFileGet(MegaClient *client, MegaNode* n, const LocalPath& dstPath); ~MegaFileGetMegaFileGet1848 ~MegaFileGet() {} 1849 1850 bool serialize(string*) override; 1851 static MegaFileGet* unserialize(string*); 1852 1853 private: MegaFileGetMegaFileGet1854 MegaFileGet() {} 1855 }; 1856 1857 struct MegaFilePut : public MegaFile 1858 { 1859 void completed(Transfer* t, LocalNode*) override; 1860 void terminated() override; 1861 MegaFilePut(MegaClient *client, LocalPath clocalname, string *filename, handle ch, const char* ctargetuser, int64_t mtime = -1, bool isSourceTemporary = false); ~MegaFilePutMegaFilePut1862 ~MegaFilePut() {} 1863 1864 bool serialize(string*) override; 1865 static MegaFilePut* unserialize(string*); 1866 1867 protected: 1868 int64_t customMtime; 1869 1870 private: MegaFilePutMegaFilePut1871 MegaFilePut() {} 1872 }; 1873 1874 class TreeProcessor 1875 { 1876 public: 1877 virtual bool processNode(Node* node); 1878 virtual ~TreeProcessor(); 1879 }; 1880 1881 class SearchTreeProcessor : public TreeProcessor 1882 { 1883 public: 1884 SearchTreeProcessor(const char *search); 1885 virtual bool processNode(Node* node); ~SearchTreeProcessor()1886 virtual ~SearchTreeProcessor() {} 1887 vector<Node *> &getResults(); 1888 1889 protected: 1890 const char *search; 1891 vector<Node *> results; 1892 }; 1893 1894 class OutShareProcessor : public TreeProcessor 1895 { 1896 public: 1897 OutShareProcessor(MegaClient&); 1898 virtual bool processNode(Node* node); ~OutShareProcessor()1899 virtual ~OutShareProcessor() {} 1900 vector<Share *> getShares(); 1901 vector<handle> getHandles(); 1902 void sortShares(int order); 1903 protected: 1904 vector<Share *> mShares; 1905 node_vector mNodes; 1906 MegaClient& mClient; 1907 }; 1908 1909 class PendingOutShareProcessor : public TreeProcessor 1910 { 1911 public: 1912 PendingOutShareProcessor(); 1913 virtual bool processNode(Node* node); ~PendingOutShareProcessor()1914 virtual ~PendingOutShareProcessor() {} 1915 vector<Share *> &getShares(); 1916 vector<handle> &getHandles(); 1917 1918 protected: 1919 vector<Share *> shares; 1920 vector<handle> handles; 1921 }; 1922 1923 class SizeProcessor : public TreeProcessor 1924 { 1925 protected: 1926 long long totalBytes; 1927 1928 public: 1929 SizeProcessor(); 1930 virtual bool processNode(Node* node); 1931 long long getTotalBytes(); 1932 }; 1933 1934 class TreeProcFolderInfo : public TreeProc 1935 { 1936 public: 1937 TreeProcFolderInfo(); 1938 virtual void proc(MegaClient*, Node*); ~TreeProcFolderInfo()1939 virtual ~TreeProcFolderInfo() {} 1940 MegaFolderInfo *getResult(); 1941 1942 protected: 1943 int numFiles; 1944 int numFolders; 1945 int numVersions; 1946 long long currentSize; 1947 long long versionsSize; 1948 }; 1949 1950 //Thread safe request queue 1951 class RequestQueue 1952 { 1953 protected: 1954 std::deque<MegaRequestPrivate *> requests; 1955 std::mutex mutex; 1956 1957 public: 1958 RequestQueue(); 1959 void push(MegaRequestPrivate *request); 1960 void push_front(MegaRequestPrivate *request); 1961 MegaRequestPrivate * pop(); 1962 MegaRequestPrivate * front(); 1963 void removeListener(MegaRequestListener *listener); 1964 #ifdef ENABLE_SYNC 1965 void removeListener(MegaSyncListener *listener); 1966 #endif 1967 void removeListener(MegaBackupListener *listener); 1968 }; 1969 1970 1971 //Thread safe transfer queue 1972 class TransferQueue 1973 { 1974 protected: 1975 std::deque<MegaTransferPrivate *> transfers; 1976 std::mutex mutex; 1977 long long lastPushedTransfer = 0; 1978 1979 public: 1980 TransferQueue(); 1981 void push(MegaTransferPrivate *transfer); 1982 void push_front(MegaTransferPrivate *transfer); 1983 MegaTransferPrivate * pop(); 1984 1985 /** 1986 * @brief pops and returns transfer up to the designated one 1987 * @param lastQueuedTransfer position of the last transfer to pop 1988 * @param direction directio of transfers to pop 1989 * @return 1990 */ 1991 std::vector<MegaTransferPrivate *> popUpTo(int lastQueuedTransfer, int direction); 1992 1993 void removeWithFolderTag(int folderTag, std::function<void(MegaTransferPrivate *)> callback); 1994 void removeListener(MegaTransferListener *listener); 1995 long long getLastPushedTag() const; 1996 }; 1997 1998 class MegaApiImpl : public MegaApp 1999 { 2000 public: 2001 MegaApiImpl(MegaApi *api, const char *appKey, MegaGfxProcessor* processor, const char *basePath = NULL, const char *userAgent = NULL, unsigned workerThreadCount = 1); 2002 MegaApiImpl(MegaApi *api, const char *appKey, const char *basePath = NULL, const char *userAgent = NULL, unsigned workerThreadCount = 1); 2003 MegaApiImpl(MegaApi *api, const char *appKey, const char *basePath, const char *userAgent, int fseventsfd, unsigned workerThreadCount = 1); 2004 virtual ~MegaApiImpl(); 2005 2006 static MegaApiImpl* ImplOf(MegaApi*); 2007 2008 enum { TARGET_INSHARE = 0, TARGET_OUTSHARE, TARGET_PUBLICLINK, }; 2009 2010 //Multiple listener management. 2011 void addListener(MegaListener* listener); 2012 void addRequestListener(MegaRequestListener* listener); 2013 void addTransferListener(MegaTransferListener* listener); 2014 void addBackupListener(MegaBackupListener* listener); 2015 void addGlobalListener(MegaGlobalListener* listener); 2016 #ifdef ENABLE_SYNC 2017 void addSyncListener(MegaSyncListener *listener); 2018 void removeSyncListener(MegaSyncListener *listener); 2019 #endif 2020 void removeListener(MegaListener* listener); 2021 void removeRequestListener(MegaRequestListener* listener); 2022 void removeTransferListener(MegaTransferListener* listener); 2023 void removeBackupListener(MegaBackupListener* listener); 2024 void removeGlobalListener(MegaGlobalListener* listener); 2025 2026 void cancelPendingTransfersByFolderTag(int folderTag); 2027 2028 2029 MegaRequest *getCurrentRequest(); 2030 MegaTransfer *getCurrentTransfer(); 2031 MegaError *getCurrentError(); 2032 MegaNodeList *getCurrentNodes(); 2033 MegaUserList *getCurrentUsers(); 2034 2035 //Utils 2036 long long getSDKtime(); 2037 char *getStringHash(const char* base64pwkey, const char* inBuf); 2038 void getSessionTransferURL(const char *path, MegaRequestListener *listener); 2039 static MegaHandle base32ToHandle(const char* base32Handle); 2040 static handle base64ToHandle(const char* base64Handle); 2041 static handle base64ToUserHandle(const char* base64Handle); 2042 static char *handleToBase64(MegaHandle handle); 2043 static char *userHandleToBase64(MegaHandle handle); 2044 static char *binaryToBase64(const char* binaryData, size_t length); 2045 static void base64ToBinary(const char *base64string, unsigned char **binary, size_t* binarysize); 2046 static const char* ebcEncryptKey(const char* encryptionKey, const char* plainKey); 2047 void retryPendingConnections(bool disconnect = false, bool includexfers = false, MegaRequestListener* listener = NULL); 2048 void setDnsServers(const char *dnsServers, MegaRequestListener* listener = NULL); 2049 void addEntropy(char* data, unsigned int size); 2050 static string userAttributeToString(int); 2051 static string userAttributeToLongName(int); 2052 static int userAttributeFromString(const char *name); 2053 static char userAttributeToScope(int); 2054 static void setStatsID(const char *id); 2055 2056 bool serverSideRubbishBinAutopurgeEnabled(); 2057 bool appleVoipPushEnabled(); 2058 bool newLinkFormatEnabled(); 2059 int smsAllowedState(); 2060 char* smsVerifiedPhoneNumber(); 2061 void resetSmsVerifiedPhoneNumber(MegaRequestListener *listener); 2062 2063 bool multiFactorAuthAvailable(); 2064 void multiFactorAuthCheck(const char *email, MegaRequestListener *listener = NULL); 2065 void multiFactorAuthGetCode(MegaRequestListener *listener = NULL); 2066 void multiFactorAuthEnable(const char *pin, MegaRequestListener *listener = NULL); 2067 void multiFactorAuthDisable(const char *pin, MegaRequestListener *listener = NULL); 2068 void multiFactorAuthLogin(const char* email, const char* password, const char* pin, MegaRequestListener *listener = NULL); 2069 void multiFactorAuthChangePassword(const char *oldPassword, const char *newPassword, const char* pin, MegaRequestListener *listener = NULL); 2070 void multiFactorAuthChangeEmail(const char *email, const char* pin, MegaRequestListener *listener = NULL); 2071 void multiFactorAuthCancelAccount(const char* pin, MegaRequestListener *listener = NULL); 2072 2073 void fetchTimeZone(MegaRequestListener *listener = NULL); 2074 2075 //API requests 2076 void login(const char* email, const char* password, MegaRequestListener *listener = NULL); 2077 char *dumpSession(); 2078 char *getSequenceNumber(); 2079 char *getAccountAuth(); 2080 void setAccountAuth(const char* auth); 2081 2082 void fastLogin(const char* email, const char *stringHash, const char *base64pwkey, MegaRequestListener *listener = NULL); 2083 void fastLogin(const char* session, MegaRequestListener *listener = NULL); 2084 void killSession(MegaHandle sessionHandle, MegaRequestListener *listener = NULL); 2085 void getUserData(MegaRequestListener *listener = NULL); 2086 void getUserData(MegaUser *user, MegaRequestListener *listener = NULL); 2087 void getUserData(const char *user, MegaRequestListener *listener = NULL); 2088 void getMiscFlags(MegaRequestListener *listener = NULL); 2089 void sendDevCommand(const char *command, const char *email, MegaRequestListener *listener = NULL); 2090 void getCloudStorageUsed(MegaRequestListener *listener = NULL); 2091 void getAccountDetails(bool storage, bool transfer, bool pro, bool sessions, bool purchases, bool transactions, int source = -1, MegaRequestListener *listener = NULL); 2092 void queryTransferQuota(long long size, MegaRequestListener *listener = NULL); 2093 void createAccount(const char* email, const char* password, const char* firstname, const char* lastname, MegaHandle lastPublicHandle, int lastPublicHandleType, int64_t lastAccessTimestamp, MegaRequestListener *listener = NULL); 2094 void resumeCreateAccount(const char* sid, MegaRequestListener *listener = NULL); 2095 void cancelCreateAccount(MegaRequestListener *listener = NULL); 2096 void sendSignupLink(const char* email, const char *name, const char *password, MegaRequestListener *listener = NULL); 2097 void fastSendSignupLink(const char *email, const char *base64pwkey, const char *name, MegaRequestListener *listener = NULL); 2098 void querySignupLink(const char* link, MegaRequestListener *listener = NULL); 2099 void confirmAccount(const char* link, const char *password, MegaRequestListener *listener = NULL); 2100 void fastConfirmAccount(const char* link, const char *base64pwkey, MegaRequestListener *listener = NULL); 2101 void resetPassword(const char *email, bool hasMasterKey, MegaRequestListener *listener = NULL); 2102 void queryRecoveryLink(const char *link, MegaRequestListener *listener = NULL); 2103 void confirmResetPasswordLink(const char *link, const char *newPwd, const char *masterKey = NULL, MegaRequestListener *listener = NULL); 2104 void cancelAccount(MegaRequestListener *listener = NULL); 2105 void confirmCancelAccount(const char *link, const char *pwd, MegaRequestListener *listener = NULL); 2106 void resendVerificationEmail(MegaRequestListener *listener = NULL); 2107 void changeEmail(const char *email, MegaRequestListener *listener = NULL); 2108 void confirmChangeEmail(const char *link, const char *pwd, MegaRequestListener *listener = NULL); 2109 void setProxySettings(MegaProxy *proxySettings, MegaRequestListener *listener = NULL); 2110 MegaProxy *getAutoProxySettings(); 2111 int isLoggedIn(); 2112 void whyAmIBlocked(bool logout, MegaRequestListener *listener = NULL); 2113 char* getMyEmail(); 2114 char* getMyUserHandle(); 2115 MegaHandle getMyUserHandleBinary(); 2116 MegaUser *getMyUser(); 2117 bool isAchievementsEnabled(); 2118 bool isBusinessAccount(); 2119 bool isMasterBusinessAccount(); 2120 bool isBusinessAccountActive(); 2121 int getBusinessStatus(); 2122 int64_t getOverquotaDeadlineTs(); 2123 MegaIntegerList *getOverquotaWarningsTs(); 2124 bool checkPassword(const char *password); 2125 char* getMyCredentials(); 2126 void getUserCredentials(MegaUser *user, MegaRequestListener *listener = NULL); 2127 bool areCredentialsVerified(MegaUser *user); 2128 void verifyCredentials(MegaUser *user, MegaRequestListener *listener = NULL); 2129 void resetCredentials(MegaUser *user, MegaRequestListener *listener = NULL); 2130 char* getMyRSAPrivateKey(); 2131 static void setLogLevel(int logLevel); 2132 static void setMaxPayloadLogSize(long long maxSize); 2133 static void addLoggerClass(MegaLogger *megaLogger); 2134 static void removeLoggerClass(MegaLogger *megaLogger); 2135 static void setLogToConsole(bool enable); 2136 static void log(int logLevel, const char* message, const char *filename = NULL, int line = -1); 2137 2138 void setLoggingName(const char* loggingName); 2139 2140 void createFolder(const char* name, MegaNode *parent, MegaRequestListener *listener = NULL); 2141 bool createLocalFolder(const char *path); 2142 void moveNode(MegaNode* node, MegaNode* newParent, MegaRequestListener *listener = NULL); 2143 void moveNode(MegaNode* node, MegaNode* newParent, const char *newName, MegaRequestListener *listener = NULL); 2144 void copyNode(MegaNode* node, MegaNode *newParent, MegaRequestListener *listener = NULL); 2145 void copyNode(MegaNode* node, MegaNode *newParent, const char* newName, MegaRequestListener *listener = NULL); 2146 void renameNode(MegaNode* node, const char* newName, MegaRequestListener *listener = NULL); 2147 void remove(MegaNode* node, bool keepversions = false, MegaRequestListener *listener = NULL); 2148 void removeVersions(MegaRequestListener *listener = NULL); 2149 void restoreVersion(MegaNode *version, MegaRequestListener *listener = NULL); 2150 void cleanRubbishBin(MegaRequestListener *listener = NULL); 2151 void sendFileToUser(MegaNode *node, MegaUser *user, MegaRequestListener *listener = NULL); 2152 void sendFileToUser(MegaNode *node, const char* email, MegaRequestListener *listener = NULL); 2153 void share(MegaNode *node, MegaUser* user, int level, MegaRequestListener *listener = NULL); 2154 void share(MegaNode* node, const char* email, int level, MegaRequestListener *listener = NULL); 2155 void loginToFolder(const char* megaFolderLink, MegaRequestListener *listener = NULL); 2156 void importFileLink(const char* megaFileLink, MegaNode* parent, MegaRequestListener *listener = NULL); 2157 void decryptPasswordProtectedLink(const char* link, const char* password, MegaRequestListener *listener = NULL); 2158 void encryptLinkWithPassword(const char* link, const char* password, MegaRequestListener *listener = NULL); 2159 void getPublicNode(const char* megaFileLink, MegaRequestListener *listener = NULL); 2160 const char *buildPublicLink(const char *publicHandle, const char *key, bool isFolder); 2161 void getThumbnail(MegaNode* node, const char *dstFilePath, MegaRequestListener *listener = NULL); 2162 void cancelGetThumbnail(MegaNode* node, MegaRequestListener *listener = NULL); 2163 void setThumbnail(MegaNode* node, const char *srcFilePath, MegaRequestListener *listener = NULL); 2164 void putThumbnail(MegaBackgroundMediaUpload* node, const char *srcFilePath, MegaRequestListener *listener = NULL); 2165 void setThumbnailByHandle(MegaNode* node, MegaHandle attributehandle, MegaRequestListener *listener = NULL); 2166 void getPreview(MegaNode* node, const char *dstFilePath, MegaRequestListener *listener = NULL); 2167 void cancelGetPreview(MegaNode* node, MegaRequestListener *listener = NULL); 2168 void setPreview(MegaNode* node, const char *srcFilePath, MegaRequestListener *listener = NULL); 2169 void putPreview(MegaBackgroundMediaUpload* node, const char *srcFilePath, MegaRequestListener *listener = NULL); 2170 void setPreviewByHandle(MegaNode* node, MegaHandle attributehandle, MegaRequestListener *listener = NULL); 2171 void getUserAvatar(MegaUser* user, const char *dstFilePath, MegaRequestListener *listener = NULL); 2172 void setAvatar(const char *dstFilePath, MegaRequestListener *listener = NULL); 2173 void getUserAvatar(const char *email_or_handle, const char *dstFilePath, MegaRequestListener *listener = NULL); 2174 static char* getUserAvatarColor(MegaUser *user); 2175 static char *getUserAvatarColor(const char *userhandle); 2176 static char* getUserAvatarSecondaryColor(MegaUser *user); 2177 static char *getUserAvatarSecondaryColor(const char *userhandle); 2178 bool testAllocation(unsigned allocCount, size_t allocSize); 2179 void getUserAttribute(MegaUser* user, int type, MegaRequestListener *listener = NULL); 2180 void getUserAttribute(const char* email_or_handle, int type, MegaRequestListener *listener = NULL); 2181 void getChatUserAttribute(const char* email_or_handle, int type, const char* ph, MegaRequestListener *listener = NULL); 2182 void getUserAttr(const char* email_or_handle, int type, const char *dstFilePath, int number = 0, MegaRequestListener *listener = NULL); 2183 void getChatUserAttr(const char* email_or_handle, int type, const char *dstFilePath, const char *ph = NULL, int number = 0, MegaRequestListener *listener = NULL); 2184 void setUserAttribute(int type, const char* value, MegaRequestListener *listener = NULL); 2185 void setUserAttribute(int type, const MegaStringMap* value, MegaRequestListener *listener = NULL); 2186 void getRubbishBinAutopurgePeriod(MegaRequestListener *listener = NULL); 2187 void setRubbishBinAutopurgePeriod(int days, MegaRequestListener *listener = NULL); 2188 void getDeviceName(MegaRequestListener *listener = NULL); 2189 void setDeviceName(const char* deviceName, MegaRequestListener *listener = NULL); 2190 void getUserEmail(MegaHandle handle, MegaRequestListener *listener = NULL); 2191 void setCustomNodeAttribute(MegaNode *node, const char *attrName, const char *value, MegaRequestListener *listener = NULL); 2192 void setNodeDuration(MegaNode *node, int secs, MegaRequestListener *listener = NULL); 2193 void setNodeCoordinates(MegaNode *node, bool unshareable, double latitude, double longitude, MegaRequestListener *listener = NULL); 2194 void exportNode(MegaNode *node, int64_t expireTime, MegaRequestListener *listener = NULL); 2195 void disableExport(MegaNode *node, MegaRequestListener *listener = NULL); 2196 void fetchNodes(bool resumeSyncs, MegaRequestListener *listener = NULL); 2197 void getPricing(MegaRequestListener *listener = NULL); 2198 void getPaymentId(handle productHandle, handle lastPublicHandle, int lastPublicHandleType, int64_t lastAccessTimestamp, MegaRequestListener *listener = NULL); 2199 void upgradeAccount(MegaHandle productHandle, int paymentMethod, MegaRequestListener *listener = NULL); 2200 void submitPurchaseReceipt(int gateway, const char *receipt, MegaHandle lastPublicHandle, int lastPublicHandleType, int64_t lastAccessTimestamp, MegaRequestListener *listener = NULL); 2201 void creditCardStore(const char* address1, const char* address2, const char* city, 2202 const char* province, const char* country, const char *postalcode, 2203 const char* firstname, const char* lastname, const char* creditcard, 2204 const char* expire_month, const char* expire_year, const char* cv2, 2205 MegaRequestListener *listener = NULL); 2206 2207 void creditCardQuerySubscriptions(MegaRequestListener *listener = NULL); 2208 void creditCardCancelSubscriptions(const char* reason, MegaRequestListener *listener = NULL); 2209 void getPaymentMethods(MegaRequestListener *listener = NULL); 2210 2211 char *exportMasterKey(); 2212 void updatePwdReminderData(bool lastSuccess, bool lastSkipped, bool mkExported, bool dontShowAgain, bool lastLogin, MegaRequestListener *listener = NULL); 2213 2214 void changePassword(const char *oldPassword, const char *newPassword, MegaRequestListener *listener = NULL); 2215 void inviteContact(const char* email, const char* message, int action, MegaHandle contactLink, MegaRequestListener* listener = NULL); 2216 void replyContactRequest(MegaContactRequest *request, int action, MegaRequestListener* listener = NULL); 2217 void respondContactRequest(); 2218 2219 void removeContact(MegaUser *user, MegaRequestListener* listener=NULL); 2220 void logout(MegaRequestListener *listener = NULL); 2221 void localLogout(MegaRequestListener *listener = NULL); 2222 void invalidateCache(); 2223 int getPasswordStrength(const char *password); 2224 void submitFeedback(int rating, const char *comment, MegaRequestListener *listener = NULL); 2225 void reportEvent(const char *details = NULL, MegaRequestListener *listener = NULL); 2226 void sendEvent(int eventType, const char* message, MegaRequestListener *listener = NULL); 2227 void createSupportTicket(const char* message, int type = 1, MegaRequestListener *listener = NULL); 2228 2229 void useHttpsOnly(bool httpsOnly, MegaRequestListener *listener = NULL); 2230 bool usingHttpsOnly(); 2231 2232 //Backups 2233 MegaStringList *getBackupFolders(int backuptag); 2234 void setBackup(const char* localPath, MegaNode *parent, bool attendPastBackups, int64_t period, string periodstring, int numBackups, MegaRequestListener *listener=NULL); 2235 void removeBackup(int tag, MegaRequestListener *listener=NULL); 2236 void abortCurrentBackup(int tag, MegaRequestListener *listener=NULL); 2237 2238 //Timer 2239 void startTimer( int64_t period, MegaRequestListener *listener=NULL); 2240 2241 //Transfers 2242 void startUpload(const char* localPath, MegaNode *parent, FileSystemType fsType, MegaTransferListener *listener=NULL); 2243 void startUpload(const char* localPath, MegaNode *parent, int64_t mtime, FileSystemType fsType, MegaTransferListener *listener=NULL); 2244 void startUpload(const char* localPath, MegaNode* parent, const char* fileName, FileSystemType fsType, MegaTransferListener *listener = NULL); 2245 void startUpload(bool startFirst, const char* localPath, MegaNode* parent, const char* fileName, int64_t mtime, int folderTransferTag, bool isBackup, const char *appData, bool isSourceFileTemporary, bool forceNewUpload, FileSystemType fsType, MegaTransferListener *listener); 2246 void startUpload(bool startFirst, const char* localPath, MegaNode* parent, const char* fileName, const char* targetUser, int64_t mtime, int folderTransferTag, bool isBackup, const char *appData, bool isSourceFileTemporary, bool forceNewUpload, FileSystemType fsType, MegaTransferListener *listener); 2247 void startUploadForSupport(const char *localPath, bool isSourceTemporary, FileSystemType fsType, MegaTransferListener *listener=NULL); 2248 void startDownload(MegaNode* node, const char* localPath, MegaTransferListener *listener = NULL); 2249 void startDownload(bool startFirst, MegaNode *node, const char* target, int folderTransferTag, const char *appData, MegaTransferListener *listener); 2250 void startStreaming(MegaNode* node, m_off_t startPos, m_off_t size, MegaTransferListener *listener); 2251 void setStreamingMinimumRate(int bytesPerSecond); 2252 void retryTransfer(MegaTransfer *transfer, MegaTransferListener *listener = NULL); 2253 void cancelTransfer(MegaTransfer *transfer, MegaRequestListener *listener=NULL); 2254 void cancelTransferByTag(int transferTag, MegaRequestListener *listener = NULL); 2255 void cancelTransfers(int direction, MegaRequestListener *listener=NULL); 2256 void pauseTransfers(bool pause, int direction, MegaRequestListener* listener=NULL); 2257 void pauseTransfer(int transferTag, bool pause, MegaRequestListener* listener = NULL); 2258 void moveTransferUp(int transferTag, MegaRequestListener *listener = NULL); 2259 void moveTransferDown(int transferTag, MegaRequestListener *listener = NULL); 2260 void moveTransferToFirst(int transferTag, MegaRequestListener *listener = NULL); 2261 void moveTransferToLast(int transferTag, MegaRequestListener *listener = NULL); 2262 void moveTransferBefore(int transferTag, int prevTransferTag, MegaRequestListener *listener = NULL); 2263 void enableTransferResumption(const char* loggedOutId); 2264 void disableTransferResumption(const char* loggedOutId); 2265 bool areTransfersPaused(int direction); 2266 void setUploadLimit(int bpslimit); 2267 void setMaxConnections(int direction, int connections, MegaRequestListener* listener = NULL); 2268 void setDownloadMethod(int method); 2269 void setUploadMethod(int method); 2270 bool setMaxDownloadSpeed(m_off_t bpslimit); 2271 bool setMaxUploadSpeed(m_off_t bpslimit); 2272 int getMaxDownloadSpeed(); 2273 int getMaxUploadSpeed(); 2274 int getCurrentDownloadSpeed(); 2275 int getCurrentUploadSpeed(); 2276 int getCurrentSpeed(int type); 2277 int getDownloadMethod(); 2278 int getUploadMethod(); 2279 MegaTransferData *getTransferData(MegaTransferListener *listener = NULL); 2280 MegaTransfer *getFirstTransfer(int type); 2281 void notifyTransfer(int transferTag, MegaTransferListener *listener = NULL); 2282 MegaTransferList *getTransfers(); 2283 MegaTransferList *getStreamingTransfers(); 2284 MegaTransfer* getTransferByTag(int transferTag); 2285 MegaTransferList *getTransfers(int type); 2286 MegaTransferList *getChildTransfers(int transferTag); 2287 MegaTransferList *getTansfersByFolderTag(int folderTransferTag); 2288 2289 2290 #ifdef ENABLE_SYNC 2291 //Sync 2292 int syncPathState(string *path); 2293 MegaNode *getSyncedNode(const LocalPath& path); 2294 void syncFolder(const char *localFolder, MegaNode *megaFolder, MegaRegExp *regExp = NULL, long long localfp = 0, MegaRequestListener* listener = NULL); 2295 void removeSync(handle nodehandle, MegaRequestListener *listener=NULL); 2296 void disableSync(handle nodehandle, MegaRequestListener *listener=NULL); 2297 int getNumActiveSyncs(); 2298 void stopSyncs(MegaRequestListener *listener=NULL); 2299 bool isSynced(MegaNode *n); 2300 void setExcludedNames(vector<string> *excludedNames); 2301 void setExcludedPaths(vector<string> *excludedPaths); 2302 void setExclusionLowerSizeLimit(long long limit); 2303 void setExclusionUpperSizeLimit(long long limit); 2304 bool moveToLocalDebris(const char *path); 2305 string getLocalPath(MegaNode *node); 2306 long long getNumLocalNodes(); 2307 bool isSyncable(const char *path, long long size); 2308 bool isInsideSync(MegaNode *node); 2309 bool is_syncable(Sync*, const char*, const LocalPath&); 2310 bool is_syncable(long long size); 2311 int isNodeSyncable(MegaNode *megaNode); 2312 bool isIndexing(); 2313 bool isSyncing(); 2314 2315 MegaSync *getSyncByTag(int tag); 2316 MegaSync *getSyncByNode(MegaNode *node); 2317 MegaSync *getSyncByPath(const char * localPath); 2318 char *getBlockedPath(); 2319 void setExcludedRegularExpressions(MegaSync *sync, MegaRegExp *regExp); 2320 #endif 2321 2322 MegaBackup *getBackupByTag(int tag); 2323 MegaBackup *getBackupByNode(MegaNode *node); 2324 MegaBackup *getBackupByPath(const char * localPath); 2325 2326 void update(); 2327 int isWaiting(); 2328 int areServersBusy(); 2329 2330 //Statistics 2331 int getNumPendingUploads(); 2332 int getNumPendingDownloads(); 2333 int getTotalUploads(); 2334 int getTotalDownloads(); 2335 void resetTotalDownloads(); 2336 void resetTotalUploads(); 2337 void updateStats(); 2338 long long getNumNodes(); 2339 long long getTotalDownloadedBytes(); 2340 long long getTotalUploadedBytes(); 2341 long long getTotalDownloadBytes(); 2342 long long getTotalUploadBytes(); 2343 2344 //Filesystem 2345 int getNumChildren(MegaNode* parent); 2346 int getNumChildFiles(MegaNode* parent); 2347 int getNumChildFolders(MegaNode* parent); 2348 MegaNodeList* getChildren(MegaNode *parent, int order); 2349 MegaNodeList* getVersions(MegaNode *node); 2350 int getNumVersions(MegaNode *node); 2351 bool hasVersions(MegaNode *node); 2352 void getFolderInfo(MegaNode *node, MegaRequestListener *listener); 2353 MegaChildrenLists* getFileFolderChildren(MegaNode *parent, int order=1); 2354 bool hasChildren(MegaNode *parent); 2355 MegaNode *getChildNode(MegaNode *parent, const char* name); 2356 MegaNode *getParentNode(MegaNode *node); 2357 char *getNodePath(MegaNode *node); 2358 MegaNode *getNodeByPath(const char *path, MegaNode *n = NULL); 2359 MegaNode *getNodeByHandle(handle handler); 2360 MegaContactRequest *getContactRequestByHandle(MegaHandle handle); 2361 MegaUserList* getContacts(); 2362 MegaUser* getContact(const char* uid); 2363 MegaUserAlertList* getUserAlerts(); 2364 int getNumUnreadUserAlerts(); 2365 MegaNodeList *getInShares(MegaUser* user, int order); 2366 MegaNodeList *getInShares(int order); 2367 MegaShareList *getInSharesList(int order); 2368 MegaUser *getUserFromInShare(MegaNode *node, bool recurse = false); 2369 bool isPendingShare(MegaNode *node); 2370 MegaShareList *getOutShares(int order); 2371 MegaShareList *getOutShares(MegaNode *node); 2372 MegaShareList *getPendingOutShares(); 2373 MegaShareList *getPendingOutShares(MegaNode *megaNode); 2374 MegaNodeList *getPublicLinks(int order); 2375 MegaContactRequestList *getIncomingContactRequests(); 2376 MegaContactRequestList *getOutgoingContactRequests(); 2377 2378 int getAccess(MegaNode* node); 2379 long long getSize(MegaNode *node); 2380 static void removeRecursively(const char *path); 2381 2382 //Fingerprint 2383 char *getFingerprint(const char *filePath); 2384 char *getFingerprint(MegaNode *node); 2385 char *getFingerprint(MegaInputStream *inputStream, int64_t mtime); 2386 MegaNode *getNodeByFingerprint(const char* fingerprint); 2387 MegaNodeList *getNodesByFingerprint(const char* fingerprint); 2388 MegaNodeList *getNodesByOriginalFingerprint(const char* originalfingerprint, MegaNode* parent); 2389 MegaNode *getExportableNodeByFingerprint(const char *fingerprint, const char *name = NULL); 2390 MegaNode *getNodeByFingerprint(const char *fingerprint, MegaNode* parent); 2391 bool hasFingerprint(const char* fingerprint); 2392 2393 //CRC 2394 char *getCRC(const char *filePath); 2395 char *getCRCFromFingerprint(const char *fingerprint); 2396 char *getCRC(MegaNode *node); 2397 MegaNode* getNodeByCRC(const char *crc, MegaNode* parent); 2398 2399 //Permissions 2400 MegaError checkAccess(MegaNode* node, int level); 2401 MegaError* checkAccessErrorExtended(MegaNode* node, int level); 2402 MegaError checkMove(MegaNode* node, MegaNode* target); 2403 MegaError* checkMoveErrorExtended(MegaNode* node, MegaNode* target); 2404 2405 bool isFilesystemAvailable(); 2406 MegaNode *getRootNode(); 2407 MegaNode* getInboxNode(); 2408 MegaNode *getRubbishNode(); 2409 MegaNode *getRootNode(MegaNode *node); 2410 bool isInRootnode(MegaNode *node, int index); 2411 2412 void setDefaultFilePermissions(int permissions); 2413 int getDefaultFilePermissions(); 2414 void setDefaultFolderPermissions(int permissions); 2415 int getDefaultFolderPermissions(); 2416 2417 long long getBandwidthOverquotaDelay(); 2418 2419 MegaRecentActionBucketList* getRecentActions(unsigned days = 90, unsigned maxnodes = 10000); 2420 2421 MegaNodeList* search(MegaNode* node, const char* searchString, MegaCancelToken *cancelToken, bool recursive = 1, int order = MegaApi::ORDER_NONE); 2422 bool processMegaTree(MegaNode* node, MegaTreeProcessor* processor, bool recursive = 1); 2423 MegaNodeList* search(const char* searchString, MegaCancelToken *cancelToken, int order = MegaApi::ORDER_NONE); 2424 2425 MegaNodeList* searchInAllShares(const char *searchString, MegaCancelToken *cancelToken, int order, int target); 2426 2427 MegaNode *createForeignFileNode(MegaHandle handle, const char *key, const char *name, m_off_t size, m_off_t mtime, 2428 MegaHandle parentHandle, const char *privateauth, const char *publicauth, const char *chatauth); 2429 MegaNode *createForeignFolderNode(MegaHandle handle, const char *name, MegaHandle parentHandle, 2430 const char *privateauth, const char *publicauth); 2431 2432 MegaNode *authorizeNode(MegaNode *node); 2433 void authorizeMegaNodePrivate(MegaNodePrivate *node); 2434 MegaNode *authorizeChatNode(MegaNode *node, const char *cauth); 2435 2436 const char *getVersion(); 2437 char *getOperatingSystemVersion(); 2438 void getLastAvailableVersion(const char *appKey, MegaRequestListener *listener = NULL); 2439 void getLocalSSLCertificate(MegaRequestListener *listener = NULL); 2440 void queryDNS(const char *hostname, MegaRequestListener *listener = NULL); 2441 void queryGeLB(const char *service, int timeoutds, int maxretries, MegaRequestListener *listener = NULL); 2442 void downloadFile(const char *url, const char *dstpath, MegaRequestListener *listener = NULL); 2443 const char *getUserAgent(); 2444 const char *getBasePath(); 2445 2446 void contactLinkCreate(bool renew = false, MegaRequestListener *listener = NULL); 2447 void contactLinkQuery(MegaHandle handle, MegaRequestListener *listener = NULL); 2448 void contactLinkDelete(MegaHandle handle, MegaRequestListener *listener = NULL); 2449 2450 void keepMeAlive(int type, bool enable, MegaRequestListener *listener = NULL); 2451 void acknowledgeUserAlerts(MegaRequestListener *listener = NULL); 2452 2453 void getPSA(MegaRequestListener *listener = NULL); 2454 void setPSA(int id, MegaRequestListener *listener = NULL); 2455 2456 void disableGfxFeatures(bool disable); 2457 bool areGfxFeaturesDisabled(); 2458 2459 void changeApiUrl(const char *apiURL, bool disablepkp = false); 2460 2461 bool setLanguage(const char* languageCode); 2462 void setLanguagePreference(const char* languageCode, MegaRequestListener *listener = NULL); 2463 void getLanguagePreference(MegaRequestListener *listener = NULL); 2464 bool getLanguageCode(const char* languageCode, std::string* code); 2465 2466 void setFileVersionsOption(bool disable, MegaRequestListener *listener = NULL); 2467 void getFileVersionsOption(MegaRequestListener *listener = NULL); 2468 2469 void setContactLinksOption(bool disable, MegaRequestListener *listener = NULL); 2470 void getContactLinksOption(MegaRequestListener *listener = NULL); 2471 2472 void retrySSLerrors(bool enable); 2473 void setPublicKeyPinning(bool enable); 2474 void pauseActionPackets(); 2475 void resumeActionPackets(); 2476 2477 static std::function<bool (Node*, Node*)>getComparatorFunction(int order, MegaClient& mc); 2478 static void sortByComparatorFunction(node_vector&, int order, MegaClient& mc); 2479 static bool nodeNaturalComparatorASC(Node *i, Node *j); 2480 static bool nodeNaturalComparatorDESC(Node *i, Node *j); 2481 static bool nodeComparatorDefaultASC (Node *i, Node *j); 2482 static bool nodeComparatorDefaultDESC (Node *i, Node *j); 2483 static bool nodeComparatorSizeASC (Node *i, Node *j); 2484 static bool nodeComparatorSizeDESC (Node *i, Node *j); 2485 static bool nodeComparatorCreationASC (Node *i, Node *j); 2486 static bool nodeComparatorCreationDESC (Node *i, Node *j); 2487 static bool nodeComparatorModificationASC (Node *i, Node *j); 2488 static bool nodeComparatorModificationDESC (Node *i, Node *j); 2489 static bool nodeComparatorPhotoASC(Node *i, Node *j, MegaClient& mc); 2490 static bool nodeComparatorPhotoDESC(Node *i, Node *j, MegaClient& mc); 2491 static bool nodeComparatorVideoASC(Node *i, Node *j, MegaClient& mc); 2492 static bool nodeComparatorVideoDESC(Node *i, Node *j, MegaClient& mc); 2493 static bool nodeComparatorPublicLinkCreationASC(Node *i, Node *j); 2494 static bool nodeComparatorPublicLinkCreationDESC(Node *i, Node *j); 2495 static int typeComparator(Node *i, Node *j); 2496 static bool userComparatorDefaultASC (User *i, User *j); 2497 2498 char* escapeFsIncompatible(const char *filename, const char *dstPath); 2499 char* unescapeFsIncompatible(const char* name, const char *path); 2500 2501 bool createThumbnail(const char* imagePath, const char *dstPath); 2502 bool createPreview(const char* imagePath, const char *dstPath); 2503 bool createAvatar(const char* imagePath, const char *dstPath); 2504 2505 void backgroundMediaUploadRequestUploadURL(int64_t fullFileSize, MegaBackgroundMediaUpload* state, MegaRequestListener *listener); 2506 void backgroundMediaUploadComplete(MegaBackgroundMediaUpload* state, const char* utf8Name, MegaNode *parent, const char* fingerprint, const char* fingerprintoriginal, 2507 const char *string64UploadToken, MegaRequestListener *listener); 2508 2509 bool ensureMediaInfo(); 2510 void setOriginalFingerprint(MegaNode* node, const char* originalFingerprint, MegaRequestListener *listener); 2511 2512 bool isOnline(); 2513 2514 #ifdef HAVE_LIBUV 2515 // start/stop 2516 bool httpServerStart(bool localOnly = true, int port = 4443, bool useTLS = false, const char *certificatepath = NULL, const char *keypath = NULL, bool useIPv6 = false); 2517 void httpServerStop(); 2518 int httpServerIsRunning(); 2519 2520 // management 2521 char *httpServerGetLocalLink(MegaNode *node); 2522 char *httpServerGetLocalWebDavLink(MegaNode *node); 2523 MegaStringList *httpServerGetWebDavLinks(); 2524 MegaNodeList *httpServerGetWebDavAllowedNodes(); 2525 void httpServerRemoveWebDavAllowedNode(MegaHandle handle); 2526 void httpServerRemoveWebDavAllowedNodes(); 2527 void httpServerSetMaxBufferSize(int bufferSize); 2528 int httpServerGetMaxBufferSize(); 2529 void httpServerSetMaxOutputSize(int outputSize); 2530 int httpServerGetMaxOutputSize(); 2531 2532 // permissions 2533 void httpServerEnableFileServer(bool enable); 2534 bool httpServerIsFileServerEnabled(); 2535 void httpServerEnableFolderServer(bool enable); 2536 bool httpServerIsFolderServerEnabled(); 2537 bool httpServerIsOfflineAttributeEnabled(); 2538 void httpServerSetRestrictedMode(int mode); 2539 int httpServerGetRestrictedMode(); 2540 bool httpServerIsLocalOnly(); 2541 void httpServerEnableOfflineAttribute(bool enable); 2542 void httpServerEnableSubtitlesSupport(bool enable); 2543 bool httpServerIsSubtitlesSupportEnabled(); 2544 2545 void httpServerAddListener(MegaTransferListener *listener); 2546 void httpServerRemoveListener(MegaTransferListener *listener); 2547 2548 void fireOnStreamingStart(MegaTransferPrivate *transfer); 2549 void fireOnStreamingTemporaryError(MegaTransferPrivate *transfer, unique_ptr<MegaErrorPrivate> e); 2550 void fireOnStreamingFinish(MegaTransferPrivate *transfer, unique_ptr<MegaErrorPrivate> e); 2551 2552 //FTP 2553 bool ftpServerStart(bool localOnly = true, int port = 4990, int dataportBegin = 1500, int dataPortEnd = 1600, bool useTLS = false, const char *certificatepath = NULL, const char *keypath = NULL); 2554 void ftpServerStop(); 2555 int ftpServerIsRunning(); 2556 2557 // management 2558 char *ftpServerGetLocalLink(MegaNode *node); 2559 MegaStringList *ftpServerGetLinks(); 2560 MegaNodeList *ftpServerGetAllowedNodes(); 2561 void ftpServerRemoveAllowedNode(MegaHandle handle); 2562 void ftpServerRemoveAllowedNodes(); 2563 void ftpServerSetMaxBufferSize(int bufferSize); 2564 int ftpServerGetMaxBufferSize(); 2565 void ftpServerSetMaxOutputSize(int outputSize); 2566 int ftpServerGetMaxOutputSize(); 2567 2568 // permissions 2569 void ftpServerSetRestrictedMode(int mode); 2570 int ftpServerGetRestrictedMode(); 2571 bool ftpServerIsLocalOnly(); 2572 2573 void ftpServerAddListener(MegaTransferListener *listener); 2574 void ftpServerRemoveListener(MegaTransferListener *listener); 2575 2576 void fireOnFtpStreamingStart(MegaTransferPrivate *transfer); 2577 void fireOnFtpStreamingTemporaryError(MegaTransferPrivate *transfer, unique_ptr<MegaErrorPrivate> e); 2578 void fireOnFtpStreamingFinish(MegaTransferPrivate *transfer, unique_ptr<MegaErrorPrivate> e); 2579 2580 #endif 2581 2582 #ifdef ENABLE_CHAT 2583 void createChat(bool group, bool publicchat, MegaTextChatPeerList *peers, const MegaStringMap *userKeyMap = NULL, const char *title = NULL, MegaRequestListener *listener = NULL); 2584 void inviteToChat(MegaHandle chatid, MegaHandle uh, int privilege, bool openMode, const char *unifiedKey = NULL, const char *title = NULL, MegaRequestListener *listener = NULL); 2585 void removeFromChat(MegaHandle chatid, MegaHandle uh = INVALID_HANDLE, MegaRequestListener *listener = NULL); 2586 void getUrlChat(MegaHandle chatid, MegaRequestListener *listener = NULL); 2587 void grantAccessInChat(MegaHandle chatid, MegaNode *n, MegaHandle uh, MegaRequestListener *listener = NULL); 2588 void removeAccessInChat(MegaHandle chatid, MegaNode *n, MegaHandle uh, MegaRequestListener *listener = NULL); 2589 void updateChatPermissions(MegaHandle chatid, MegaHandle uh, int privilege, MegaRequestListener *listener = NULL); 2590 void truncateChat(MegaHandle chatid, MegaHandle messageid, MegaRequestListener *listener = NULL); 2591 void setChatTitle(MegaHandle chatid, const char *title, MegaRequestListener *listener = NULL); 2592 void setChatUnifiedKey(MegaHandle chatid, const char *unifiedKey, MegaRequestListener *listener = NULL); 2593 void getChatPresenceURL(MegaRequestListener *listener = NULL); 2594 void registerPushNotification(int deviceType, const char *token, MegaRequestListener *listener = NULL); 2595 void sendChatStats(const char *data, int port, MegaRequestListener *listener = NULL); 2596 void sendChatLogs(const char *data, const char *aid, int port, MegaRequestListener *listener = NULL); 2597 MegaTextChatList *getChatList(); 2598 MegaHandleList *getAttachmentAccess(MegaHandle chatid, MegaHandle h); 2599 bool hasAccessToAttachment(MegaHandle chatid, MegaHandle h, MegaHandle uh); 2600 const char* getFileAttribute(MegaHandle h); 2601 void archiveChat(MegaHandle chatid, int archive, MegaRequestListener *listener = NULL); 2602 void setChatRetentionTime(MegaHandle chatid, int period, MegaRequestListener *listener = NULL); 2603 void requestRichPreview(const char *url, MegaRequestListener *listener = NULL); 2604 void chatLinkHandle(MegaHandle chatid, bool del, bool createifmissing, MegaRequestListener *listener = NULL); 2605 void getChatLinkURL(MegaHandle publichandle, MegaRequestListener *listener = NULL); 2606 void chatLinkClose(MegaHandle chatid, const char *title, MegaRequestListener *listener = NULL); 2607 void chatLinkJoin(MegaHandle publichandle, const char *unifiedkey, MegaRequestListener *listener = NULL); 2608 void enableRichPreviews(bool enable, MegaRequestListener *listener = NULL); 2609 void isRichPreviewsEnabled(MegaRequestListener *listener = NULL); 2610 void shouldShowRichLinkWarning(MegaRequestListener *listener = NULL); 2611 void setRichLinkWarningCounterValue(int value, MegaRequestListener *listener = NULL); 2612 void enableGeolocation(MegaRequestListener *listener = NULL); 2613 void isGeolocationEnabled(MegaRequestListener *listener = NULL); 2614 bool isChatNotifiable(MegaHandle chatid); 2615 #endif 2616 2617 void setMyChatFilesFolder(MegaHandle nodehandle, MegaRequestListener *listener = NULL); 2618 void getMyChatFilesFolder(MegaRequestListener *listener = NULL); 2619 void setCameraUploadsFolder(MegaHandle nodehandle, bool secondary, MegaRequestListener *listener = NULL); 2620 void setCameraUploadsFolders(MegaHandle primaryFolder, MegaHandle secondaryFolder, MegaRequestListener *listener); 2621 void getCameraUploadsFolder(bool secondary, MegaRequestListener *listener = NULL); 2622 void getUserAlias(MegaHandle uh, MegaRequestListener *listener = NULL); 2623 void setUserAlias(MegaHandle uh, const char *alias, MegaRequestListener *listener = NULL); 2624 2625 void getPushNotificationSettings(MegaRequestListener *listener = NULL); 2626 void setPushNotificationSettings(MegaPushNotificationSettings *settings, MegaRequestListener *listener = NULL); 2627 2628 bool isSharesNotifiable(); 2629 bool isContactsNotifiable(); 2630 2631 void getAccountAchievements(MegaRequestListener *listener = NULL); 2632 void getMegaAchievements(MegaRequestListener *listener = NULL); 2633 2634 void catchup(MegaRequestListener *listener = NULL); 2635 void getPublicLinkInformation(const char *megaFolderLink, MegaRequestListener *listener); 2636 2637 void sendSMSVerificationCode(const char* phoneNumber, MegaRequestListener *listener = NULL, bool reverifying_whitelisted = false); 2638 void checkSMSVerificationCode(const char* verificationCode, MegaRequestListener *listener = NULL); 2639 2640 void getRegisteredContacts(const MegaStringMap* contacts, MegaRequestListener *listener = NULL); 2641 2642 void getCountryCallingCodes(MegaRequestListener *listener = NULL); 2643 2644 void fireOnTransferStart(MegaTransferPrivate *transfer); 2645 void fireOnTransferFinish(MegaTransferPrivate *transfer, unique_ptr<MegaErrorPrivate> e, DBTableTransactionCommitter& committer); 2646 void fireOnTransferUpdate(MegaTransferPrivate *transfer); 2647 void fireOnTransferTemporaryError(MegaTransferPrivate *transfer, unique_ptr<MegaErrorPrivate> e); 2648 map<int, MegaTransferPrivate *> transferMap; 2649 map<int, MegaTransferPrivate *> folderTransferMap; //transferMap includes these, added for speedup 2650 2651 2652 MegaClient *getMegaClient(); 2653 static FileFingerprint *getFileFingerprintInternal(const char *fingerprint); 2654 2655 // You take the ownership of the returned value of both functiions 2656 // It can be NULL if the input parameters are invalid 2657 static char* getMegaFingerprintFromSdkFingerprint(const char* sdkFingerprint); 2658 static char* getSdkFingerprintFromMegaFingerprint(const char *megaFingerprint, m_off_t size); 2659 2660 error processAbortBackupRequest(MegaRequestPrivate *request, error e); 2661 void fireOnBackupStateChanged(MegaBackupController *backup); 2662 void fireOnBackupStart(MegaBackupController *backup); 2663 void fireOnBackupFinish(MegaBackupController *backup, unique_ptr<MegaErrorPrivate> e); 2664 void fireOnBackupUpdate(MegaBackupController *backup); 2665 void fireOnBackupTemporaryError(MegaBackupController *backup, unique_ptr<MegaErrorPrivate> e); 2666 2667 void yield(); 2668 void lockMutex(); 2669 void unlockMutex(); 2670 bool tryLockMutexFor(long long time); 2671 2672 protected: 2673 static const unsigned int MAX_SESSION_LENGTH; 2674 2675 void init(MegaApi *api, const char *appKey, MegaGfxProcessor* processor, const char *basePath /*= NULL*/, const char *userAgent /*= NULL*/, int fseventsfd /*= -1*/, unsigned clientWorkerThreadCount /*= 1*/); 2676 2677 static void *threadEntryPoint(void *param); 2678 static ExternalLogger externalLogger; 2679 2680 MegaTransferPrivate* getMegaTransferPrivate(int tag); 2681 2682 void fireOnRequestStart(MegaRequestPrivate *request); 2683 void fireOnRequestFinish(MegaRequestPrivate *request, unique_ptr<MegaErrorPrivate> e); 2684 void fireOnRequestUpdate(MegaRequestPrivate *request); 2685 void fireOnRequestTemporaryError(MegaRequestPrivate *request, unique_ptr<MegaErrorPrivate> e); 2686 bool fireOnTransferData(MegaTransferPrivate *transfer); 2687 void fireOnUsersUpdate(MegaUserList *users); 2688 void fireOnUserAlertsUpdate(MegaUserAlertList *alerts); 2689 void fireOnNodesUpdate(MegaNodeList *nodes); 2690 void fireOnAccountUpdate(); 2691 void fireOnContactRequestsUpdate(MegaContactRequestList *requests); 2692 void fireOnReloadNeeded(); 2693 void fireOnEvent(MegaEventPrivate *event); 2694 2695 #ifdef ENABLE_SYNC 2696 void fireOnGlobalSyncStateChanged(); 2697 void fireOnSyncStateChanged(MegaSyncPrivate *sync); 2698 void fireOnSyncEvent(MegaSyncPrivate *sync, MegaSyncEvent *event); 2699 void fireOnFileSyncStateChanged(MegaSyncPrivate *sync, string *localPath, int newState); 2700 #endif 2701 2702 #ifdef ENABLE_CHAT 2703 void fireOnChatsUpdate(MegaTextChatList *chats); 2704 #endif 2705 2706 void processTransferPrepare(Transfer *t, MegaTransferPrivate *transfer); 2707 void processTransferUpdate(Transfer *tr, MegaTransferPrivate *transfer); 2708 void processTransferComplete(Transfer *tr, MegaTransferPrivate *transfer); 2709 void processTransferFailed(Transfer *tr, MegaTransferPrivate *transfer, const Error &e, dstime timeleft); 2710 void processTransferRemoved(Transfer *tr, MegaTransferPrivate *transfer, const Error &e); 2711 2712 MegaApi *api; 2713 MegaThread thread; 2714 MegaClient *client; 2715 MegaHttpIO *httpio; 2716 MegaWaiter *waiter; 2717 MegaFileSystemAccess *fsAccess; 2718 MegaDbAccess *dbAccess; 2719 GfxProc *gfxAccess; 2720 string basePath; 2721 bool nocache; 2722 2723 #ifdef HAVE_LIBUV 2724 MegaHTTPServer *httpServer; 2725 int httpServerMaxBufferSize; 2726 int httpServerMaxOutputSize; 2727 bool httpServerEnableFiles; 2728 bool httpServerEnableFolders; 2729 bool httpServerOfflineAttributeEnabled; 2730 int httpServerRestrictedMode; 2731 bool httpServerSubtitlesSupportEnabled; 2732 set<MegaTransferListener *> httpServerListeners; 2733 2734 MegaFTPServer *ftpServer; 2735 int ftpServerMaxBufferSize; 2736 int ftpServerMaxOutputSize; 2737 int ftpServerRestrictedMode; 2738 set<MegaTransferListener *> ftpServerListeners; 2739 #endif 2740 2741 map<int, MegaBackupController *> backupsMap; 2742 2743 RequestQueue requestQueue; 2744 TransferQueue transferQueue; 2745 map<int, MegaRequestPrivate *> requestMap; 2746 2747 // sc requests to close existing wsc and immediately retrieve pending actionpackets 2748 RequestQueue scRequestQueue; 2749 2750 #ifdef ENABLE_SYNC 2751 map<int, MegaSyncPrivate *> syncMap; 2752 #endif 2753 2754 int pendingUploads; 2755 int pendingDownloads; 2756 int totalUploads; 2757 int totalDownloads; 2758 long long totalDownloadedBytes; 2759 long long totalUploadedBytes; 2760 long long totalDownloadBytes; 2761 long long totalUploadBytes; 2762 long long notificationNumber; 2763 set<MegaRequestListener *> requestListeners; 2764 set<MegaTransferListener *> transferListeners; 2765 set<MegaBackupListener *> backupListeners; 2766 2767 #ifdef ENABLE_SYNC 2768 set<MegaSyncListener *> syncListeners; 2769 #endif 2770 2771 set<MegaGlobalListener *> globalListeners; 2772 set<MegaListener *> listeners; 2773 retryreason_t waitingRequest; 2774 vector<string> excludedNames; 2775 vector<string> excludedPaths; 2776 long long syncLowerSizeLimit; 2777 long long syncUpperSizeLimit; 2778 std::recursive_timed_mutex sdkMutex; 2779 using SdkMutexGuard = std::unique_lock<std::recursive_timed_mutex>; // (equivalent to typedef) 2780 std::atomic<bool> syncPathStateLockTimeout{ false }; 2781 MegaTransferPrivate *currentTransfer; 2782 MegaRequestPrivate *activeRequest; 2783 MegaTransferPrivate *activeTransfer; 2784 MegaError *activeError; 2785 MegaNodeList *activeNodes; 2786 MegaUserList *activeUsers; 2787 MegaUserAlertList *activeUserAlerts; 2788 MegaContactRequestList *activeContactRequests; 2789 string appKey; 2790 2791 MegaPushNotificationSettings *mPushSettings; // stores lastest-seen settings (to be able to filter notifications) 2792 MegaTimeZoneDetails *mTimezones; 2793 2794 int threadExit; 2795 void loop(); 2796 2797 int maxRetries; 2798 2799 // a request-level error occurred 2800 void request_error(error) override; 2801 void request_response_progress(m_off_t, m_off_t) override; 2802 2803 // login result 2804 void prelogin_result(int, string*, string*, error) override; 2805 void login_result(error) override; 2806 void logout_result(error) override; 2807 void userdata_result(string*, string*, string*, error) override; 2808 void pubkey_result(User *) override; 2809 2810 // ephemeral session creation/resumption result 2811 2812 // check the reason of being blocked 2813 void ephemeral_result(error) override; 2814 void ephemeral_result(handle, const byte*) override; 2815 void cancelsignup_result(error) override; 2816 2817 // check the reason of being blocked 2818 void whyamiblocked_result(int) override; 2819 2820 // contact link management 2821 void contactlinkcreate_result(error, handle) override; 2822 void contactlinkquery_result(error, handle, string*, string*, string*, string*) override; 2823 void contactlinkdelete_result(error) override; 2824 2825 // multi-factor authentication 2826 void multifactorauthsetup_result(string*, error) override; 2827 void multifactorauthcheck_result(int) override; 2828 void multifactorauthdisable_result(error) override; 2829 2830 // fetch time zone 2831 void fetchtimezone_result(error, vector<string>*, vector<int>*, int) override; 2832 2833 // keep me alive feature 2834 void keepmealive_result(error) override; 2835 void acknowledgeuseralerts_result(error) override; 2836 2837 // account validation by txted verification code 2838 void smsverificationsend_result(error) override; 2839 void smsverificationcheck_result(error, std::string *phoneNumber) override; 2840 2841 // get registered contacts 2842 void getregisteredcontacts_result(error, vector<tuple<string, string, string>>*) override; 2843 2844 // get country calling codes 2845 void getcountrycallingcodes_result(error, map<string, vector<string>>*) override; 2846 2847 // get the current PSA 2848 void getpsa_result (error, int, string*, string*, string*, string*, string*) override; 2849 2850 // account creation 2851 void sendsignuplink_result(error) override; 2852 void querysignuplink_result(error) override; 2853 void querysignuplink_result(handle, const char*, const char*, const byte*, const byte*, const byte*, size_t) override; 2854 void confirmsignuplink_result(error) override; 2855 void confirmsignuplink2_result(handle, const char*, const char*, error) override; 2856 void setkeypair_result(error) override; 2857 2858 // account credentials, properties and history 2859 void account_details(AccountDetails*, bool, bool, bool, bool, bool, bool) override; 2860 void account_details(AccountDetails*, error) override; 2861 void querytransferquota_result(int) override; 2862 2863 void setattr_result(handle, error) override; 2864 void rename_result(handle, error) override; 2865 void unlink_result(handle, error) override; 2866 void unlinkversions_result(error) override; 2867 void nodes_updated(Node**, int) override; 2868 void users_updated(User**, int) override; 2869 void useralerts_updated(UserAlert::Base**, int) override; 2870 void account_updated() override; 2871 void pcrs_updated(PendingContactRequest**, int) override; 2872 2873 // password change result 2874 void changepw_result(error) override; 2875 2876 // user attribute update notification 2877 void userattr_update(User*, int, const char*) override; 2878 2879 void nodes_current() override; 2880 void catchup_result() override; 2881 void key_modified(handle, attr_t) override; 2882 2883 void fetchnodes_result(const Error&) override; 2884 void putnodes_result(error, targettype_t, NewNode*) override; 2885 2886 // share update result 2887 void share_result(error) override; 2888 void share_result(int, error) override; 2889 2890 // contact request results 2891 void setpcr_result(handle, error, opcactions_t) override; 2892 void updatepcr_result(error, ipcactions_t) override; 2893 2894 // file attribute fetch result 2895 void fa_complete(handle, fatype, const char*, uint32_t) override; 2896 int fa_failed(handle, fatype, int, error) override; 2897 2898 // file attribute modification result 2899 void putfa_result(handle, fatype, error) override; 2900 void putfa_result(handle, fatype, const char*) override; 2901 2902 // purchase transactions 2903 void enumeratequotaitems_result(unsigned type, handle product, unsigned prolevel, int gbstorage, int gbtransfer, 2904 unsigned months, unsigned amount, unsigned amountMonth, const char* currency, const char* description, const char* iosid, const char* androidid) override; 2905 void enumeratequotaitems_result(error e) override; 2906 void additem_result(error) override; 2907 void checkout_result(const char*, error) override; 2908 void submitpurchasereceipt_result(error) override; 2909 void creditcardstore_result(error) override; 2910 void creditcardquerysubscriptions_result(int, error) override; 2911 void creditcardcancelsubscriptions_result(error) override; 2912 void getpaymentmethods_result(int, error) override; 2913 void copysession_result(string*, error) override; 2914 2915 void userfeedbackstore_result(error) override; 2916 void sendevent_result(error) override; 2917 void supportticket_result(error) override; 2918 2919 void checkfile_result(handle h, const Error& e) override; 2920 void checkfile_result(handle h, error e, byte* filekey, m_off_t size, m_time_t ts, m_time_t tm, string* filename, string* fingerprint, string* fileattrstring) override; 2921 2922 // user invites/attributes 2923 void removecontact_result(error) override; 2924 void putua_result(error) override; 2925 void getua_result(error) override; 2926 void getua_result(byte*, unsigned, attr_t) override; 2927 void getua_result(TLVstore *, attr_t) override; 2928 #ifdef DEBUG 2929 void delua_result(error) override; 2930 void senddevcommand_result(int) override; 2931 #endif 2932 2933 void getuseremail_result(string *, error) override; 2934 2935 // file node export result 2936 void exportnode_result(error) override; 2937 void exportnode_result(handle, handle) override; 2938 2939 // exported link access result 2940 void openfilelink_result(const Error&) override; 2941 void openfilelink_result(handle, const byte*, m_off_t, string*, string*, int) override; 2942 2943 // retrieval of public link information 2944 void folderlinkinfo_result(error, handle, handle, string *, string*, m_off_t, uint32_t, uint32_t, m_off_t, uint32_t) override; 2945 2946 // global transfer queue updates (separate signaling towards the queued objects) 2947 void file_added(File*) override; 2948 void file_removed(File*, const Error& e) override; 2949 void file_complete(File*) override; 2950 2951 void transfer_complete(Transfer *) override; 2952 void transfer_removed(Transfer *) override; 2953 2954 File* file_resume(string*, direction_t *type) override; 2955 2956 void transfer_prepare(Transfer*) override; 2957 void transfer_failed(Transfer*, const Error& error, dstime timeleft) override; 2958 void transfer_update(Transfer*) override; 2959 2960 dstime pread_failure(const Error&, int, void*, dstime) override; 2961 bool pread_data(byte*, m_off_t, m_off_t, m_off_t, m_off_t, void*) override; 2962 2963 void reportevent_result(error) override; 2964 void sessions_killed(handle sessionid, error e) override; 2965 2966 void cleanrubbishbin_result(error) override; 2967 2968 void getrecoverylink_result(error) override; 2969 void queryrecoverylink_result(error) override; 2970 void queryrecoverylink_result(int type, const char *email, const char *ip, time_t ts, handle uh, const vector<string> *emails) override; 2971 void getprivatekey_result(error, const byte *privk = NULL, const size_t len_privk = 0) override; 2972 void confirmrecoverylink_result(error) override; 2973 void confirmcancellink_result(error) override; 2974 void getemaillink_result(error) override; 2975 void resendverificationemail_result(error) override; 2976 void resetSmsVerifiedPhoneNumber_result(error) override; 2977 void confirmemaillink_result(error) override; 2978 void getversion_result(int, const char*, error) override; 2979 void getlocalsslcertificate_result(m_time_t, string *certdata, error) override; 2980 void getmegaachievements_result(AchievementsDetails*, error) override; 2981 void getwelcomepdf_result(handle, string*, error) override; 2982 void backgrounduploadurl_result(error, string*) override; 2983 void mediadetection_ready() override; 2984 void storagesum_changed(int64_t newsum) override; 2985 void getmiscflags_result(error) override; 2986 2987 #ifdef ENABLE_CHAT 2988 // chat-related commandsresult 2989 void chatcreate_result(TextChat *, error) override; 2990 void chatinvite_result(error) override; 2991 void chatremove_result(error) override; 2992 void chaturl_result(string*, error) override; 2993 void chatgrantaccess_result(error) override; 2994 void chatremoveaccess_result(error) override; 2995 void chatupdatepermissions_result(error) override; 2996 void chattruncate_result(error) override; 2997 void chatsettitle_result(error) override; 2998 void chatpresenceurl_result(string*, error) override; 2999 void registerpushnotification_result(error) override; 3000 void archivechat_result(error) override; 3001 void setchatretentiontime_result(error) override; 3002 3003 void chats_updated(textchat_map *, int) override; 3004 void richlinkrequest_result(string*, error) override; 3005 void chatlink_result(handle, error) override; 3006 void chatlinkurl_result(handle, int, string*, string*, int, m_time_t, error) override; 3007 void chatlinkclose_result(error) override; 3008 void chatlinkjoin_result(error) override; 3009 #endif 3010 3011 #ifdef ENABLE_SYNC 3012 // sync status updates and events 3013 void syncupdate_state(Sync*, syncstate_t) override; 3014 void syncupdate_scanning(bool scanning) override; 3015 void syncupdate_local_folder_addition(Sync* sync, LocalNode *localNode, const char *path) override; 3016 void syncupdate_local_folder_deletion(Sync* sync, LocalNode *localNode) override; 3017 void syncupdate_local_file_addition(Sync* sync, LocalNode* localNode, const char *path) override; 3018 void syncupdate_local_file_deletion(Sync* sync, LocalNode* localNode) override; 3019 void syncupdate_local_file_change(Sync* sync, LocalNode* localNode, const char *path) override; 3020 void syncupdate_local_move(Sync* sync, LocalNode* localNode, const char* path) override; 3021 void syncupdate_get(Sync* sync, Node *node, const char* path) override; 3022 void syncupdate_put(Sync* sync, LocalNode *localNode, const char*) override; 3023 void syncupdate_remote_file_addition(Sync *sync, Node* n) override; 3024 void syncupdate_remote_file_deletion(Sync *sync, Node* n) override; 3025 void syncupdate_remote_folder_addition(Sync *sync, Node* n) override; 3026 void syncupdate_remote_folder_deletion(Sync* sync, Node* n) override; 3027 void syncupdate_remote_copy(Sync*, const char*) override; 3028 void syncupdate_remote_move(Sync *sync, Node *n, Node* prevparent) override; 3029 void syncupdate_remote_rename(Sync*sync, Node* n, const char* prevname) override; 3030 void syncupdate_treestate(LocalNode*) override; 3031 bool sync_syncable(Sync *, const char*, LocalPath&, Node *) override; 3032 bool sync_syncable(Sync *, const char*, LocalPath&) override; 3033 void sync_auto_resumed(const string& localPath, handle remoteNode, long long localFp, const vector<string>& regExp) override; 3034 void syncupdate_local_lockretry(bool) override; 3035 3036 // for the exclusive use of sync_syncable 3037 unique_ptr<FileAccess> mSyncable_fa; 3038 std::mutex mSyncable_fa_mutex; 3039 #endif 3040 3041 void backupput_result(const Error&, handle) override; 3042 void backupupdate_result(const Error&, handle) override; 3043 void backupputheartbeat_result(const Error&) override; 3044 void backupremove_result(const Error&, handle) override; 3045 3046 protected: 3047 // suggest reload due to possible race condition with other clients 3048 void reload(const char*) override; 3049 3050 // wipe all users, nodes and shares 3051 void clearing() override; 3052 3053 // failed request retry notification 3054 void notify_retry(dstime, retryreason_t) override; 3055 3056 // notify about db commit 3057 void notify_dbcommit() override; 3058 3059 // notify about a storage event 3060 void notify_storage(int) override; 3061 3062 // notify about an automatic change to HTTPS 3063 void notify_change_to_https() override; 3064 3065 // notify about account confirmation 3066 void notify_confirmation(const char*) override; 3067 3068 // network layer disconnected 3069 void notify_disconnect() override; 3070 3071 // notify about a finished HTTP request 3072 void http_result(error, int, byte *, int) override; 3073 3074 // notify about a business account status change 3075 void notify_business_status(BizStatus status) override; 3076 3077 // notify about a finished timer 3078 void timer_result(error) override; 3079 3080 void sendPendingScRequest(); 3081 void sendPendingRequests(); 3082 unsigned sendPendingTransfers(); 3083 void updateBackups(); 3084 char *stringToArray(string &buffer); 3085 3086 //Internal 3087 Node* getNodeByFingerprintInternal(const char *fingerprint); 3088 Node *getNodeByFingerprintInternal(const char *fingerprint, Node *parent); 3089 3090 bool processTree(Node* node, TreeProcessor* processor, bool recursive = 1, MegaCancelToken* cancelToken = nullptr); 3091 void getNodeAttribute(MegaNode* node, int type, const char *dstFilePath, MegaRequestListener *listener = NULL); 3092 void cancelGetNodeAttribute(MegaNode *node, int type, MegaRequestListener *listener = NULL); 3093 void setNodeAttribute(MegaNode* node, int type, const char *srcFilePath, MegaHandle attributehandle, MegaRequestListener *listener = NULL); 3094 void putNodeAttribute(MegaBackgroundMediaUpload* bu, int type, const char *srcFilePath, MegaRequestListener *listener = NULL); 3095 void setUserAttr(int type, const char *value, MegaRequestListener *listener = NULL); 3096 static char *getAvatarColor(handle userhandle); 3097 static char *getAvatarSecondaryColor(handle userhandle); 3098 bool isGlobalNotifiable(); 3099 3100 // return false if there's a schedule and it currently does not apply. Otherwise, true 3101 bool isScheduleNotifiable(); 3102 3103 // deletes backups, requests and transfers. Reset total stats for down/uploads 3104 void abortPendingActions(error preverror = API_OK); 3105 3106 bool hasToForceUpload(const Node &node, const MegaTransferPrivate &transfer) const; 3107 3108 friend class MegaBackgroundMediaUploadPrivate; 3109 }; 3110 3111 class MegaHashSignatureImpl 3112 { 3113 public: 3114 MegaHashSignatureImpl(const char *base64Key); 3115 ~MegaHashSignatureImpl(); 3116 void init(); 3117 void add(const char *data, unsigned size); 3118 bool checkSignature(const char *base64Signature); 3119 3120 protected: 3121 HashSignature *hashSignature; 3122 AsymmCipher* asymmCypher; 3123 }; 3124 3125 class ExternalInputStream : public InputStreamAccess 3126 { 3127 MegaInputStream *inputStream; 3128 3129 public: 3130 ExternalInputStream(MegaInputStream *inputStream); 3131 virtual m_off_t size(); 3132 virtual bool read(byte *buffer, unsigned size); 3133 }; 3134 3135 #ifdef HAVE_LIBUV 3136 class StreamingBuffer 3137 { 3138 public: 3139 StreamingBuffer(); 3140 ~StreamingBuffer(); 3141 void init(m_off_t capacity); 3142 unsigned int append(const char *buf, unsigned int len); 3143 unsigned int availableData(); 3144 unsigned int availableSpace(); 3145 unsigned int availableCapacity(); 3146 uv_buf_t nextBuffer(); 3147 void freeData(unsigned int len); 3148 void setMaxBufferSize(unsigned int bufferSize); 3149 void setMaxOutputSize(unsigned int outputSize); 3150 3151 static const unsigned int MAX_BUFFER_SIZE = 2097152; 3152 static const unsigned int MAX_OUTPUT_SIZE = 16384; 3153 3154 protected: 3155 char *buffer; 3156 unsigned int capacity; 3157 unsigned int size; 3158 unsigned int free; 3159 unsigned int inpos; 3160 unsigned int outpos; 3161 unsigned int maxBufferSize; 3162 unsigned int maxOutputSize; 3163 }; 3164 3165 class MegaTCPServer; 3166 class MegaTCPContext : public MegaTransferListener, public MegaRequestListener 3167 { 3168 public: 3169 MegaTCPContext(); 3170 virtual ~MegaTCPContext(); 3171 3172 // Connection management 3173 MegaTCPServer *server; 3174 uv_tcp_t tcphandle; 3175 uv_async_t asynchandle; 3176 uv_mutex_t mutex; 3177 MegaApiImpl *megaApi; 3178 m_off_t bytesWritten; 3179 m_off_t size; 3180 char *lastBuffer; 3181 int lastBufferLen; 3182 bool nodereceived; 3183 bool finished; 3184 bool failed; 3185 bool pause; 3186 3187 #ifdef ENABLE_EVT_TLS 3188 //tls stuff: 3189 evt_tls_t *evt_tls; 3190 bool invalid; 3191 #endif 3192 std::list<char*> writePointers; 3193 3194 // Request information 3195 bool range; 3196 m_off_t rangeStart; 3197 m_off_t rangeEnd; 3198 m_off_t rangeWritten; 3199 MegaNode *node; 3200 std::string path; 3201 std::string nodehandle; 3202 std::string nodekey; 3203 std::string nodename; 3204 m_off_t nodesize; 3205 int resultCode; 3206 3207 }; 3208 3209 class MegaTCPServer 3210 { 3211 protected: 3212 static void *threadEntryPoint(void *param); 3213 static http_parser_settings parsercfg; 3214 3215 uv_loop_t uv_loop; 3216 3217 set<handle> allowedHandles; 3218 handle lastHandle; 3219 list<MegaTCPContext*> connections; 3220 uv_async_t exit_handle; 3221 MegaApiImpl *megaApi; 3222 bool semaphoresdestroyed; 3223 uv_sem_t semaphoreStartup; 3224 uv_sem_t semaphoreEnd; 3225 MegaThread *thread; 3226 uv_tcp_t server; 3227 int maxBufferSize; 3228 int maxOutputSize; 3229 int restrictedMode; 3230 bool localOnly; 3231 bool started; 3232 int port; 3233 bool closing; 3234 int remainingcloseevents; 3235 3236 #ifdef ENABLE_EVT_TLS 3237 // TLS 3238 bool evtrequirescleaning; 3239 evt_ctx_t evtctx; 3240 std::string certificatepath; 3241 std::string keypath; 3242 #endif 3243 3244 // libuv callbacks 3245 static void onNewClient(uv_stream_t* server_handle, int status); 3246 static void onDataReceived(uv_stream_t* tcp, ssize_t nread, const uv_buf_t * buf); 3247 static void allocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t* buf); 3248 static void onClose(uv_handle_t* handle); 3249 3250 #ifdef ENABLE_EVT_TLS 3251 //libuv tls 3252 static void onNewClient_tls(uv_stream_t* server_handle, int status); 3253 static void onWriteFinished_tls_async(uv_write_t* req, int status); 3254 static void on_tcp_read(uv_stream_t *stream, ssize_t nrd, const uv_buf_t *data); 3255 static int uv_tls_writer(evt_tls_t *evt_tls, void *bfr, int sz); 3256 static void on_evt_tls_close(evt_tls_t *evt_tls, int status); 3257 static void on_hd_complete( evt_tls_t *evt_tls, int status); 3258 static void evt_on_rd(evt_tls_t *evt_tls, char *bfr, int sz); 3259 #endif 3260 3261 3262 static void onAsyncEventClose(uv_handle_t* handle); 3263 static void onAsyncEvent(uv_async_t* handle); 3264 static void onExitHandleClose(uv_handle_t* handle); 3265 3266 static void onCloseRequested(uv_async_t* handle); 3267 3268 static void onWriteFinished(uv_write_t* req, int status); //This might need to go to HTTPServer 3269 #ifdef ENABLE_EVT_TLS 3270 static void onWriteFinished_tls(evt_tls_t *evt_tls, int status); 3271 #endif 3272 static void closeConnection(MegaTCPContext *tcpctx); 3273 static void closeTCPConnection(MegaTCPContext *tcpctx); 3274 3275 void run(); 3276 void initializeAndStartListening(); 3277 3278 void answer(MegaTCPContext* tcpctx, const char *rsp, size_t rlen); 3279 3280 3281 //virtual methods: 3282 virtual void processReceivedData(MegaTCPContext *tcpctx, ssize_t nread, const uv_buf_t * buf); 3283 virtual void processAsyncEvent(MegaTCPContext *tcpctx); 3284 virtual MegaTCPContext * initializeContext(uv_stream_t *server_handle) = 0; 3285 virtual void processWriteFinished(MegaTCPContext* tcpctx, int status) = 0; 3286 virtual void processOnAsyncEventClose(MegaTCPContext* tcpctx); 3287 virtual bool respondNewConnection(MegaTCPContext* tcpctx) = 0; //returns true if server needs to start by reading 3288 virtual void processOnExitHandleClose(MegaTCPServer* tcpServer); 3289 3290 public: 3291 const bool useIPv6; 3292 const bool useTLS; 3293 MegaFileSystemAccess *fsAccess; 3294 3295 std::string basePath; 3296 3297 MegaTCPServer(MegaApiImpl *megaApi, std::string basePath, bool useTLS = false, std::string certificatepath = std::string(), std::string keypath = std::string(), bool useIPv6 = false); 3298 virtual ~MegaTCPServer(); 3299 bool start(int port, bool localOnly = true); 3300 void stop(bool doNotWait = false); 3301 int getPort(); 3302 bool isLocalOnly(); 3303 void setMaxBufferSize(int bufferSize); 3304 void setMaxOutputSize(int outputSize); 3305 int getMaxBufferSize(); 3306 int getMaxOutputSize(); 3307 void setRestrictedMode(int mode); 3308 int getRestrictedMode(); 3309 bool isHandleAllowed(handle h); 3310 void clearAllowedHandles(); 3311 char* getLink(MegaNode *node, std::string protocol = "http"); 3312 3313 set<handle> getAllowedHandles(); 3314 void removeAllowedHandle(MegaHandle handle); 3315 3316 void readData(MegaTCPContext* tcpctx); 3317 }; 3318 3319 3320 class MegaTCServer; 3321 class MegaHTTPServer; 3322 class MegaHTTPContext : public MegaTCPContext 3323 { 3324 3325 public: 3326 MegaHTTPContext(); 3327 ~MegaHTTPContext(); 3328 3329 // Connection management 3330 StreamingBuffer streamingBuffer; 3331 std::unique_ptr<MegaTransferPrivate> transfer; 3332 http_parser parser; 3333 char *lastBuffer; 3334 int lastBufferLen; 3335 bool nodereceived; 3336 bool failed; 3337 bool pause; 3338 3339 // Request information 3340 bool range; 3341 m_off_t rangeStart; 3342 m_off_t rangeEnd; 3343 m_off_t rangeWritten; 3344 MegaNode *node; 3345 std::string path; 3346 std::string nodehandle; 3347 std::string nodekey; 3348 std::string nodename; 3349 m_off_t nodesize; 3350 std::string nodepubauth; 3351 std::string nodeprivauth; 3352 std::string nodechatauth; 3353 int resultCode; 3354 3355 3356 // WEBDAV related 3357 int depth; 3358 std::string lastheader; 3359 std::string subpathrelative; 3360 const char *messageBody; 3361 size_t messageBodySize; 3362 std::string host; 3363 std::string destination; 3364 bool overwrite; 3365 std::unique_ptr<FileAccess> tmpFileAccess; 3366 std::string tmpFileName; 3367 std::string newname; //newname for moved node 3368 MegaHandle nodeToMove; //node to be moved after delete 3369 MegaHandle newParentNode; //parent node for moved after delete 3370 3371 uv_mutex_t mutex_responses; 3372 std::list<std::string> responses; 3373 3374 virtual void onTransferStart(MegaApi *, MegaTransfer *transfer); 3375 virtual bool onTransferData(MegaApi *, MegaTransfer *transfer, char *buffer, size_t size); 3376 virtual void onTransferFinish(MegaApi* api, MegaTransfer *transfer, MegaError *e); 3377 virtual void onRequestFinish(MegaApi* api, MegaRequest *request, MegaError *e); 3378 }; 3379 3380 class MegaHTTPServer: public MegaTCPServer 3381 { 3382 protected: 3383 set<handle> allowedWebDavHandles; 3384 3385 bool fileServerEnabled; 3386 bool folderServerEnabled; 3387 bool offlineAttribute; 3388 bool subtitlesSupportEnabled; 3389 3390 //virtual methods: 3391 virtual void processReceivedData(MegaTCPContext *ftpctx, ssize_t nread, const uv_buf_t * buf); 3392 virtual void processAsyncEvent(MegaTCPContext *ftpctx); 3393 virtual MegaTCPContext * initializeContext(uv_stream_t *server_handle); 3394 virtual void processWriteFinished(MegaTCPContext* tcpctx, int status); 3395 virtual void processOnAsyncEventClose(MegaTCPContext* tcpctx); 3396 virtual bool respondNewConnection(MegaTCPContext* tcpctx); 3397 virtual void processOnExitHandleClose(MegaTCPServer* tcpServer); 3398 3399 3400 // HTTP parser callback 3401 static int onMessageBegin(http_parser* parser); 3402 static int onHeadersComplete(http_parser* parser); 3403 static int onUrlReceived(http_parser* parser, const char* url, size_t length); 3404 static int onHeaderField(http_parser* parser, const char* at, size_t length); 3405 static int onHeaderValue(http_parser* parser, const char* at, size_t length); 3406 static int onBody(http_parser* parser, const char* at, size_t length); 3407 static int onMessageComplete(http_parser* parser); 3408 3409 static void sendHeaders(MegaHTTPContext *httpctx, string *headers); 3410 static void sendNextBytes(MegaHTTPContext *httpctx); 3411 static int streamNode(MegaHTTPContext *httpctx); 3412 3413 //Utility funcitons 3414 static std::string getHTTPMethodName(int httpmethod); 3415 static std::string getHTTPErrorString(int errorcode); 3416 static std::string getResponseForNode(MegaNode *node, MegaHTTPContext* httpctx); 3417 3418 // WEBDAV related 3419 static std::string getWebDavPropFindResponseForNode(std::string baseURL, std::string subnodepath, MegaNode *node, MegaHTTPContext* httpctx); 3420 static std::string getWebDavProfFindNodeContents(MegaNode *node, std::string baseURL, bool offlineAttribute); 3421 3422 static void returnHttpCodeBasedOnRequestError(MegaHTTPContext* httpctx, MegaError *e, bool synchronous = true); 3423 static void returnHttpCode(MegaHTTPContext* httpctx, int errorCode, std::string errorMessage = string(), bool synchronous = true); 3424 3425 public: 3426 3427 static void returnHttpCodeAsyncBasedOnRequestError(MegaHTTPContext* httpctx, MegaError *e); 3428 static void returnHttpCodeAsync(MegaHTTPContext* httpctx, int errorCode, std::string errorMessage = string()); 3429 3430 MegaHTTPServer(MegaApiImpl *megaApi, string basePath, bool useTLS = false, std::string certificatepath = std::string(), std::string keypath = std::string(), bool useIPv6 = false); 3431 virtual ~MegaHTTPServer(); 3432 char *getWebDavLink(MegaNode *node); 3433 3434 void clearAllowedHandles(); 3435 bool isHandleWebDavAllowed(handle h); 3436 set<handle> getAllowedWebDavHandles(); 3437 void removeAllowedWebDavHandle(MegaHandle handle); 3438 void enableFileServer(bool enable); 3439 void enableFolderServer(bool enable); 3440 bool isFileServerEnabled(); 3441 bool isFolderServerEnabled(); 3442 void enableOfflineAttribute(bool enable); 3443 bool isOfflineAttributeEnabled(); 3444 bool isSubtitlesSupportEnabled(); 3445 void enableSubtitlesSupport(bool enable); 3446 3447 }; 3448 3449 class MegaFTPServer; 3450 class MegaFTPDataServer; 3451 class MegaFTPContext : public MegaTCPContext 3452 { 3453 public: 3454 3455 int command; 3456 std::string arg1; 3457 std::string arg2; 3458 int resultcode; 3459 int pasiveport; 3460 MegaFTPDataServer * ftpDataServer; 3461 3462 std::string tmpFileName; 3463 3464 MegaNode *nodeToDeleteAfterMove; 3465 3466 uv_mutex_t mutex_responses; 3467 std::list<std::string> responses; 3468 3469 uv_mutex_t mutex_nodeToDownload; 3470 3471 //status 3472 MegaHandle cwd; 3473 bool atroot; 3474 bool athandle; 3475 MegaHandle parentcwd; 3476 3477 std::string cwdpath; 3478 3479 MegaFTPContext(); 3480 ~MegaFTPContext(); 3481 3482 virtual void onTransferStart(MegaApi *, MegaTransfer *transfer); 3483 virtual bool onTransferData(MegaApi *, MegaTransfer *transfer, char *buffer, size_t size); 3484 virtual void onTransferFinish(MegaApi* api, MegaTransfer *transfer, MegaError *e); 3485 virtual void onRequestFinish(MegaApi* api, MegaRequest *request, MegaError *e); 3486 }; 3487 3488 class MegaFTPDataServer; 3489 class MegaFTPServer: public MegaTCPServer 3490 { 3491 protected: 3492 enum{ 3493 FTP_CMD_INVALID = -1, 3494 FTP_CMD_USER = 1, 3495 FTP_CMD_PASS, 3496 FTP_CMD_ACCT, 3497 FTP_CMD_CWD, 3498 FTP_CMD_CDUP, 3499 FTP_CMD_SMNT, 3500 FTP_CMD_QUIT, 3501 FTP_CMD_REIN, 3502 FTP_CMD_PORT, 3503 FTP_CMD_PASV, 3504 FTP_CMD_TYPE, 3505 FTP_CMD_STRU, 3506 FTP_CMD_MODE, 3507 FTP_CMD_RETR, 3508 FTP_CMD_STOR, 3509 FTP_CMD_STOU, 3510 FTP_CMD_APPE, 3511 FTP_CMD_ALLO, 3512 FTP_CMD_REST, 3513 FTP_CMD_RNFR, 3514 FTP_CMD_RNTO, 3515 FTP_CMD_ABOR, 3516 FTP_CMD_DELE, 3517 FTP_CMD_RMD, 3518 FTP_CMD_MKD, 3519 FTP_CMD_PWD, 3520 FTP_CMD_LIST, 3521 FTP_CMD_NLST, 3522 FTP_CMD_SITE, 3523 FTP_CMD_SYST, 3524 FTP_CMD_STAT, 3525 FTP_CMD_HELP, 3526 FTP_CMD_FEAT, //rfc2389 3527 FTP_CMD_SIZE, 3528 FTP_CMD_PROT, 3529 FTP_CMD_EPSV, //rfc2428 3530 FTP_CMD_PBSZ, //rfc2228 3531 FTP_CMD_OPTS, //rfc2389 3532 FTP_CMD_NOOP 3533 }; 3534 3535 std::string crlfout; 3536 3537 MegaHandle nodeHandleToRename; 3538 3539 int pport; 3540 int dataportBegin; 3541 int dataPortEnd; 3542 3543 std::string getListingLineFromNode(MegaNode *child, std::string nameToShow = string()); 3544 3545 MegaNode *getBaseFolderNode(std::string path); 3546 MegaNode *getNodeByFullFtpPath(std::string path); 3547 void getPermissionsString(int permissions, char *permsString); 3548 3549 3550 //virtual methods: 3551 virtual void processReceivedData(MegaTCPContext *tcpctx, ssize_t nread, const uv_buf_t * buf); 3552 virtual void processAsyncEvent(MegaTCPContext *tcpctx); 3553 virtual MegaTCPContext * initializeContext(uv_stream_t *server_handle); 3554 virtual void processWriteFinished(MegaTCPContext* tcpctx, int status); 3555 virtual void processOnAsyncEventClose(MegaTCPContext* tcpctx); 3556 virtual bool respondNewConnection(MegaTCPContext* tcpctx); 3557 virtual void processOnExitHandleClose(MegaTCPServer* tcpServer); 3558 3559 public: 3560 3561 std::string newNameAfterMove; 3562 3563 MegaFTPServer(MegaApiImpl *megaApi, string basePath, int dataportBegin, int dataPortEnd, bool useTLS = false, std::string certificatepath = std::string(), std::string keypath = std::string()); 3564 virtual ~MegaFTPServer(); 3565 3566 static std::string getFTPErrorString(int errorcode, std::string argument = string()); 3567 3568 static void returnFtpCodeBasedOnRequestError(MegaFTPContext* ftpctx, MegaError *e); 3569 static void returnFtpCode(MegaFTPContext* ftpctx, int errorCode, std::string errorMessage = string()); 3570 3571 static void returnFtpCodeAsyncBasedOnRequestError(MegaFTPContext* ftpctx, MegaError *e); 3572 static void returnFtpCodeAsync(MegaFTPContext* ftpctx, int errorCode, std::string errorMessage = string()); 3573 MegaNode * getNodeByFtpPath(MegaFTPContext* ftpctx, std::string path); 3574 std::string cdup(handle parentHandle, MegaFTPContext* ftpctx); 3575 std::string cd(string newpath, MegaFTPContext* ftpctx); 3576 std::string shortenpath(std::string path); 3577 }; 3578 3579 class MegaFTPDataContext; 3580 class MegaFTPDataServer: public MegaTCPServer 3581 { 3582 protected: 3583 3584 //virtual methods: 3585 virtual void processReceivedData(MegaTCPContext *tcpctx, ssize_t nread, const uv_buf_t * buf); 3586 virtual void processAsyncEvent(MegaTCPContext *tcpctx); 3587 virtual MegaTCPContext * initializeContext(uv_stream_t *server_handle); 3588 virtual void processWriteFinished(MegaTCPContext* tcpctx, int status); 3589 virtual void processOnAsyncEventClose(MegaTCPContext* tcpctx); 3590 virtual bool respondNewConnection(MegaTCPContext* tcpctx); 3591 virtual void processOnExitHandleClose(MegaTCPServer* tcpServer); 3592 3593 void sendNextBytes(MegaFTPDataContext *ftpdatactx); 3594 3595 3596 public: 3597 MegaFTPContext *controlftpctx; 3598 3599 std::string resultmsj; 3600 MegaNode *nodeToDownload; 3601 std::string remotePathToUpload; 3602 std::string newNameToUpload; 3603 MegaHandle newParentNodeHandle; 3604 m_off_t rangeStartREST; 3605 void sendData(); 3606 bool notifyNewConnectionRequired; 3607 3608 MegaFTPDataServer(MegaApiImpl *megaApi, string basePath, MegaFTPContext * controlftpctx, bool useTLS = false, std::string certificatepath = std::string(), std::string keypath = std::string()); 3609 virtual ~MegaFTPDataServer(); 3610 string getListingLineFromNode(MegaNode *child); 3611 }; 3612 3613 class MegaFTPDataServer; 3614 class MegaFTPDataContext : public MegaTCPContext 3615 { 3616 public: 3617 3618 MegaFTPDataContext(); 3619 ~MegaFTPDataContext(); 3620 3621 void setControlCodeUponDataClose(int code, std::string msg = string()); 3622 3623 // Connection management 3624 StreamingBuffer streamingBuffer; 3625 MegaTransferPrivate *transfer; 3626 char *lastBuffer; 3627 int lastBufferLen; 3628 bool failed; 3629 int ecode; 3630 bool pause; 3631 MegaNode *node; 3632 3633 m_off_t rangeStart; 3634 m_off_t rangeWritten; 3635 3636 std::string tmpFileName; 3637 std::unique_ptr<FileAccess> tmpFileAccess; 3638 size_t tmpFileSize; 3639 3640 bool controlRespondedElsewhere; 3641 string controlResponseMessage; 3642 int controlResponseCode; 3643 3644 virtual void onTransferStart(MegaApi *, MegaTransfer *transfer); 3645 virtual bool onTransferData(MegaApi *, MegaTransfer *transfer, char *buffer, size_t size); 3646 virtual void onTransferFinish(MegaApi* api, MegaTransfer *transfer, MegaError *e); 3647 virtual void onRequestFinish(MegaApi* api, MegaRequest *request, MegaError *e); 3648 }; 3649 3650 3651 3652 #endif 3653 3654 } 3655 3656 #endif //MEGAAPI_IMPL_H 3657