From 6a7d14cf50fecd8fc3887eefa689f3b51666542d Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Sat, 18 Jun 2016 02:02:34 +0200 Subject: [PATCH 001/103] Set the max number of connections per transfer --- include/mega/megaclient.h | 3 +++ include/megaapi.h | 20 +++++++++++++++++++- include/megaapi_impl.h | 1 + src/megaapi.cpp | 5 +++++ src/megaapi_impl.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/megaclient.cpp | 18 ++++++++++++++++++ src/transferslot.cpp | 1 + 7 files changed, 86 insertions(+), 1 deletion(-) diff --git a/include/mega/megaclient.h b/include/mega/megaclient.h index 0a370ac5e8..eb79e5b7af 100644 --- a/include/mega/megaclient.h +++ b/include/mega/megaclient.h @@ -161,6 +161,9 @@ class MEGA_API MegaClient void stopxfer(File* f); void pausexfers(direction_t, bool, bool = false); + // set max connections per transfer + void setmaxconnections(direction_t, int); + // enqueue/abort direct read void pread(Node*, m_off_t, m_off_t, void*); void pread(handle, SymmCipher* key, int64_t, m_off_t, m_off_t, void*); diff --git a/include/megaapi.h b/include/megaapi.h index 7c0cd44f14..c04f780b03 100644 --- a/include/megaapi.h +++ b/include/megaapi.h @@ -1614,7 +1614,7 @@ class MegaRequest TYPE_SUBMIT_FEEDBACK, TYPE_SEND_EVENT, TYPE_CLEAN_RUBBISH_BIN, TYPE_SET_ATTR_NODE, TYPE_CHAT_CREATE, TYPE_CHAT_FETCH, TYPE_CHAT_INVITE, TYPE_CHAT_REMOVE, TYPE_CHAT_URL, TYPE_CHAT_GRANT_ACCESS, TYPE_CHAT_REMOVE_ACCESS, - TYPE_USE_HTTPS_ONLY, TYPE_SET_PROXY + TYPE_USE_HTTPS_ONLY, TYPE_SET_PROXY, TYPE_SET_MAX_CONNECTIONS }; virtual ~MegaRequest(); @@ -1970,6 +1970,7 @@ class MegaRequest * - MegaApi::cancelTransfers - Returns MegaTransfer::TYPE_DOWNLOAD if downloads are cancelled or MegaTransfer::TYPE_UPLOAD if uploads are cancelled * - MegaApi::setUserAttribute - Returns the attribute type * - MegaApi::getUserAttribute - Returns the attribute type + * - MegaApi::setMaxConnections - Returns the direction of transfers * * @return Type of parameter related to the request */ @@ -2010,6 +2011,7 @@ class MegaRequest * - MegaApi::replyContactRequest - Returns the action to do with the contact request * - MegaApi::inviteContact - Returns the action to do with the contact request * - MegaApi::sendEvent - Returns the event type + * - MegaApi::setMaxConnections - Returns the number of connections * * This value is valid for these request in onRequestFinish when the * error code is MegaError::API_OK: @@ -5653,6 +5655,22 @@ class MegaApi */ void setUploadLimit(int bpslimit); + /** + * @brief Set the maximum number of connections per transfer + * + * The associated request type with this request is MegaRequest::TYPE_SET_MAX_CONNECTIONS + * Valid data in the MegaRequest object received on callbacks: + * - MegaRequest::getParamType - Returns the first parameter + * - MegaRequest::getNumber - Returns the second parameter + * + * @param direction Direction of transfers + * Valid values for this parameter are: + * - MegaTransfer::TYPE_DOWNLOAD = 0 + * - MegaTransfer::TYPE_UPLOAD = 1 + * @param connections Maximum number of connection (it should be at least 1) + */ + void setMaxConnections(int direction, int connections, MegaRequestListener* listener = NULL); + /** * @brief Set the transfer method for downloads * diff --git a/include/megaapi_impl.h b/include/megaapi_impl.h index f780548330..4292f52421 100644 --- a/include/megaapi_impl.h +++ b/include/megaapi_impl.h @@ -1282,6 +1282,7 @@ class MegaApiImpl : public MegaApp void disableTransferResumption(const char* loggedOutId); bool areTransfersPaused(int direction); void setUploadLimit(int bpslimit); + void setMaxConnections(int direction, int connections, MegaRequestListener* listener = NULL); void setDownloadMethod(int method); void setUploadMethod(int method); int getDownloadMethod(); diff --git a/src/megaapi.cpp b/src/megaapi.cpp index d88bb52fc6..3f6a714a85 100644 --- a/src/megaapi.cpp +++ b/src/megaapi.cpp @@ -1578,6 +1578,11 @@ void MegaApi::setUploadLimit(int bpslimit) pImpl->setUploadLimit(bpslimit); } +void MegaApi::setMaxConnections(int direction, int connections, MegaRequestListener *listener) +{ + pImpl->setMaxConnections(direction, connections, listener); +} + void MegaApi::setDownloadMethod(int method) { pImpl->setDownloadMethod(method); diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 407869b75e..12bb2806c5 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -2282,6 +2282,7 @@ const char *MegaRequestPrivate::getRequestString() const case TYPE_CHAT_REMOVE_ACCESS: return "CHAT_REMOVE_ACCESS"; case TYPE_USE_HTTPS_ONLY: return "USE_HTTPS_ONLY"; case TYPE_SET_PROXY: return "SET_PROXY"; + case TYPE_SET_MAX_CONNECTIONS: return "SET_MAX_CONNECTIONS"; } return "UNKNOWN"; } @@ -4393,6 +4394,15 @@ void MegaApiImpl::setUploadLimit(int bpslimit) client->putmbpscap = bpslimit; } +void MegaApiImpl::setMaxConnections(int direction, int connections, MegaRequestListener *listener) +{ + MegaRequestPrivate *request = new MegaRequestPrivate(MegaRequest::TYPE_SET_MAX_CONNECTIONS, listener); + request->setParamType(direction); + request->setNumber(connections); + requestQueue.push(request); + waiter->notify(); +} + void MegaApiImpl::setDownloadMethod(int method) { switch(method) @@ -11196,6 +11206,35 @@ void MegaApiImpl::sendPendingRequests() fireOnRequestFinish(request, MegaError(API_OK)); break; } + case MegaRequest::TYPE_SET_MAX_CONNECTIONS: + { + int direction = request->getParamType(); + int connections = request->getNumber(); + + if (connections <= 0 || (direction != -1 + && direction != MegaTransfer::TYPE_DOWNLOAD + && direction != MegaTransfer::TYPE_UPLOAD)) + { + e = API_EARGS; + break; + } + + if (direction == -1) + { + client->setmaxconnections(GET, connections); + client->setmaxconnections(PUT, connections); + } + else if (direction == MegaTransfer::TYPE_DOWNLOAD) + { + client->setmaxconnections(GET, connections); + } + else + { + client->setmaxconnections(PUT, connections); + } + + break; + } case MegaRequest::TYPE_CANCEL_TRANSFER: { int transferTag = request->getTransferTag(); diff --git a/src/megaclient.cpp b/src/megaclient.cpp index 70f45cd386..dc54f58257 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -9426,6 +9426,24 @@ void MegaClient::pausexfers(direction_t d, bool pause, bool hard) } } +void MegaClient::setmaxconnections(direction_t d, int num) +{ + if (num > 0) + { + connections[d] = num; + for (transferslot_list::iterator it = tslots.begin(); it != tslots.end(); ) + { + TransferSlot *slot = *it++; + if (slot->transfer->type == d) + { + slot->transfer->bt.arm(); + slot->transfer->cachedtempurl = slot->tempurl; + delete slot; + } + } + } +} + Node* MegaClient::nodebyfingerprint(FileFingerprint* fingerprint) { fingerprint_set::iterator it; diff --git a/src/transferslot.cpp b/src/transferslot.cpp index 667abbca27..478dfc8105 100644 --- a/src/transferslot.cpp +++ b/src/transferslot.cpp @@ -49,6 +49,7 @@ TransferSlot::TransferSlot(Transfer* ctransfer) transfer->slot = this; connections = transfer->size > 131072 ? transfer->client->connections[transfer->type] : 1; + LOG_debug << "Creating transfer slot with " << connections << " connections"; reqs = new HttpReqXfer*[connections](); From 848a2d885fa22299cfba2378831b7fa64b981eaa Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Mon, 4 Jul 2016 14:41:22 +0200 Subject: [PATCH 002/103] First approach to authorize and download public folders (incomplete) --- include/megaapi.h | 13 ++++ include/megaapi_impl.h | 8 ++- src/megaapi.cpp | 5 ++ src/megaapi_impl.cpp | 156 +++++++++++++++++++++++++---------------- 4 files changed, 120 insertions(+), 62 deletions(-) diff --git a/include/megaapi.h b/include/megaapi.h index 7d623ebf8e..e46018c267 100644 --- a/include/megaapi.h +++ b/include/megaapi.h @@ -883,6 +883,19 @@ class MegaNode */ virtual std::string* getPublicAuth(); + /** + * @brief Returns the child nodes of an authorized folder node + * + * This function always returns NULL, except for authorized folder nodes. + * Authorized folder nodes are the ones returned by MegaApi::authorizeNode. + * + * The MegaNode object retains the ownership of the returned pointer. It will be valid until the deletion + * of the MegaNode object. + * + * @return Child nodes of an authorized folder node, otherwise NULL + */ + virtual MegaNodeList *getChildren(); + #ifdef ENABLE_SYNC /** * @brief Returns true if this node was deleted from the MEGA account by the diff --git a/include/megaapi_impl.h b/include/megaapi_impl.h index 9a8824558a..4dd86481e6 100644 --- a/include/megaapi_impl.h +++ b/include/megaapi_impl.h @@ -177,10 +177,10 @@ class MegaFolderDownloadController : public MegaTransferListener { public: MegaFolderDownloadController(MegaApiImpl *megaApi, MegaTransferPrivate *transfer); - void start(); + void start(MegaNode *node); protected: - void downloadFolderNode(Node *node, string *path); + void downloadFolderNode(MegaNode *node, string *path); void checkCompletion(); MegaApiImpl *megaApi; @@ -241,9 +241,11 @@ class MegaNodePrivate : public MegaNode, public Cachable virtual bool isTakenDown(); virtual bool isForeign(); virtual std::string* getPrivateAuth(); + virtual MegaNodeList *getChildren(); virtual void setPrivateAuth(const char *privateAuth); void setPublicAuth(const char *publicAuth); void setForeign(bool foreign); + void setChildren(MegaNodeList *children); virtual std::string* getPublicAuth(); virtual bool isShared(); virtual bool isOutShare(); @@ -286,6 +288,7 @@ class MegaNodePrivate : public MegaNode, public Cachable bool foreign : 1; }; PublicLink *plink; + MegaNodeList *children; #ifdef ENABLE_SYNC bool syncdeleted; @@ -1437,6 +1440,7 @@ class MegaApiImpl : public MegaApp const char *privateauth, const char *publicauth); MegaNode *authorizeNode(MegaNode *node); + void authorizeMegaNodePrivate(MegaNodePrivate *node); void loadBalancing(const char* service, MegaRequestListener *listener = NULL); diff --git a/src/megaapi.cpp b/src/megaapi.cpp index e86f3f7d56..2df5947480 100644 --- a/src/megaapi.cpp +++ b/src/megaapi.cpp @@ -382,6 +382,11 @@ string *MegaNode::getPublicAuth() return NULL; } +MegaNodeList *MegaNode::getChildren() +{ + return NULL; +} + #ifdef ENABLE_SYNC bool MegaNode::isSyncDeleted() { diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 34836d6da4..d5ff54f04e 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -92,6 +92,7 @@ MegaNodePrivate::MegaNodePrivate(const char *name, int type, int64_t size, int64 this->inShare = false; this->plink = NULL; this->foreign = isForeign; + this->children = NULL; if (privateauth) { @@ -114,6 +115,7 @@ MegaNodePrivate::MegaNodePrivate(MegaNode *node) this->name = MegaApi::strdup(node->getName()); this->fingerprint = MegaApi::strdup(node->getFingerprint()); this->customAttrs = NULL; + this->children = NULL; this->type = node->getType(); this->size = node->getSize(); this->ctime = node->getCreationTime(); @@ -164,6 +166,7 @@ MegaNodePrivate::MegaNodePrivate(Node *node) { this->name = MegaApi::strdup(node->displayname()); this->fingerprint = NULL; + this->children = NULL; if (node->isvalid) { @@ -881,6 +884,11 @@ string *MegaNodePrivate::getPrivateAuth() return &privateAuth; } +MegaNodeList *MegaNodePrivate::getChildren() +{ + return children; +} + void MegaNodePrivate::setPrivateAuth(const char *privateAuth) { if (!privateAuth || !privateAuth[0]) @@ -910,6 +918,11 @@ void MegaNodePrivate::setForeign(bool foreign) this->foreign = foreign; } +void MegaNodePrivate::setChildren(MegaNodeList *children) +{ + this->children = children; +} + string *MegaNodePrivate::getPublicAuth() { return &publicAuth; @@ -921,6 +934,7 @@ MegaNodePrivate::~MegaNodePrivate() delete [] fingerprint; delete customAttrs; delete plink; + delete children; } MegaUserPrivate::MegaUserPrivate(User *user) : MegaUser() @@ -6416,38 +6430,52 @@ MegaNode *MegaApiImpl::createForeignFolderNode(MegaHandle handle, const char *na MegaNode *MegaApiImpl::authorizeNode(MegaNode *node) { - if (!node || node->getType() != MegaNode::TYPE_FILE) + if (!node || node->isPublic() || node->isForeign()) { return NULL; } - if (node->isPublic() || node->isForeign()) - { - return node->copy(); - } - MegaNodePrivate *result = NULL; sdkMutex.lock(); Node *n = client->nodebyhandle(node->getHandle()); - if (n && n->type == FILENODE) + if (n) { - char *h = NULL; result = new MegaNodePrivate(node); - result->setForeign(true); + authorizeMegaNodePrivate(result); + } + + sdkMutex.unlock(); + return result; +} + +void MegaApiImpl::authorizeMegaNodePrivate(MegaNodePrivate *node) +{ + node->setForeign(true); + if (node->getType() == MegaNode::TYPE_FILE) + { + char *h = NULL; if (client->sid.size()) { h = getAccountAuth(); - result->setPrivateAuth(h); + node->setPrivateAuth(h); } else { h = MegaApi::handleToBase64(client->getrootpublicfolder()); - result->setPublicAuth(h); + node->setPublicAuth(h); } delete [] h; } - sdkMutex.unlock(); - return result; + else + { + MegaNodeList *children = getChildren(node); + node->setChildren(children); + for (int i = 0; i < children->size(); i++) + { + MegaNodePrivate *privNode = (MegaNodePrivate *)children->get(i); + authorizeMegaNodePrivate(privNode); + } + } } void MegaApiImpl::loadBalancing(const char* service, MegaRequestListener *listener) @@ -10759,7 +10787,7 @@ void MegaApiImpl::sendPendingTransfers() transferMap[nextTag] = transfer; transfer->setTag(nextTag); MegaFolderDownloadController *downloader = new MegaFolderDownloadController(this, transfer); - downloader->start(); + downloader->start(publicNode); break; } @@ -14033,10 +14061,10 @@ MegaFolderDownloadController::MegaFolderDownloadController(MegaApiImpl *megaApi, this->listener = transfer->getListener(); this->recursive = 0; this->pendingTransfers = 0; - this->tag = transfer->getTag(); + this->tag = transfer->getTag(); } -void MegaFolderDownloadController::start() +void MegaFolderDownloadController::start(MegaNode *node) { transfer->setFolderTransferTag(-1); transfer->setStartTime(Waiter::ds); @@ -14044,7 +14072,18 @@ void MegaFolderDownloadController::start() const char *parentPath = transfer->getParentPath(); const char *fileName = transfer->getFileName(); - Node *node = client->nodebyhandle(transfer->getNodeHandle()); + + if (!node) + { + megaApi->getNodeByHandle(transfer->getNodeHandle()); + if (!node) + { + LOG_debug << "Folder download failed. Node not found"; + megaApi->fireOnTransferFinish(transfer, MegaError(API_ENOENT)); + delete this; + return; + } + } string name; string securename; @@ -14064,19 +14103,7 @@ void MegaFolderDownloadController::start() if (!fileName) { - attr_map::iterator ait = node->attrs.map.find('n'); - if (ait == node->attrs.map.end()) - { - name = "CRYPTO_ERROR"; - } - else if (!ait->second.size()) - { - name = "BLANK"; - } - else - { - name = ait->second; - } + name = node->getName(); } else { @@ -14096,7 +14123,7 @@ void MegaFolderDownloadController::start() downloadFolderNode(node, &path); } -void MegaFolderDownloadController::downloadFolderNode(Node *node, string *path) +void MegaFolderDownloadController::downloadFolderNode(MegaNode *node, string *path) { recursive++; @@ -14124,58 +14151,69 @@ void MegaFolderDownloadController::downloadFolderNode(Node *node, string *path) delete da; localpath.append(client->fsaccess->localseparator); - for (node_list::iterator it = node->children.begin(); it != node->children.end(); it++) + MegaNodeList *children = NULL; + if (node->isForeign()) { - Node *child = (*it); - int l = localpath.size(); + children = node->getChildren(); + } + else + { + children = megaApi->getChildren(node); + } - string name; - attr_map::iterator ait = child->attrs.map.find('n'); - if (ait == child->attrs.map.end()) - { - name = "CRYPTO_ERROR"; - } - else if (!ait->second.size()) - { - name = "BLANK"; - } - else - { - name = ait->second; - } + if (!children) + { + LOG_err << "Child nodes not found: " << *path; + recursive--; + checkCompletion(); + return; + } + + for (int i = 0; i < children->size(); i++) + { + MegaNode *child = children->get(i); + int l = localpath.size(); + string name = child->getName(); client->fsaccess->name2local(&name); localpath.append(name); string utf8path; client->fsaccess->local2path(&localpath, &utf8path); - if (child->type == FILENODE) + if (child->getType() == MegaNode::TYPE_FILE) { pendingTransfers++; - FileAccess *fa = client->fsaccess->newfileaccess(); - if (fa->fopen(&localpath, true, false) && fa->type == FILENODE) + FileAccess *fa = NULL; + Node *childNode = NULL; + if (!child->isForeign()) + { + childNode = client->nodebyhandle(child->getHandle()); + fa = client->fsaccess->newfileaccess(); + } + + if (childNode && fa->fopen(&localpath, true, false) && fa->type == FILENODE) { FileFingerprint fp; fp.genfingerprint(fa); - if ((fp.isvalid && child->isvalid && fp == *(FileFingerprint *)child) - || (!child->isvalid && fa->size == child->size && fa->mtime == child->mtime)) + if ((fp.isvalid && childNode->isvalid && fp == *(FileFingerprint *)childNode) + || (!childNode->isvalid && fa->size == childNode->size && fa->mtime == childNode->mtime)) { LOG_debug << "Already downloaded file detected: " << utf8path; int nextTag = client->nextreqtag(); MegaTransferPrivate* t = new MegaTransferPrivate(MegaTransfer::TYPE_DOWNLOAD, this); t->setPath(utf8path.data()); - t->setNodeHandle(child->nodehandle); + t->setNodeHandle(childNode->nodehandle); t->setTag(nextTag); t->setFolderTransferTag(tag); - t->setTotalBytes(child->size); + t->setTotalBytes(childNode->size); megaApi->transferMap[nextTag] = t; megaApi->fireOnTransferStart(t); - t->setTransferredBytes(child->size); - t->setDeltaSize(child->size); + t->setTransferredBytes(childNode->size); + t->setDeltaSize(childNode->size); megaApi->fireOnTransferFinish(t, MegaError(API_OK)); localpath.resize(l); delete fa; @@ -14184,9 +14222,7 @@ void MegaFolderDownloadController::downloadFolderNode(Node *node, string *path) } delete fa; - MegaNode *megaChild = MegaNodePrivate::fromNode(child); - megaApi->startDownload(megaChild, utf8path.c_str(), 0, 0, tag, NULL, this); - delete megaChild; + megaApi->startDownload(child, utf8path.c_str(), 0, 0, tag, NULL, this); } else { From 1abce39951c6ecbb3ea7f91ac17ef139b7f2bb07 Mon Sep 17 00:00:00 2001 From: Victor Teniente Mateos Date: Tue, 26 Jul 2016 19:37:47 +0200 Subject: [PATCH 003/103] Support to download public folder nodes --- src/megaapi_impl.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index d5ff54f04e..7c2ceecac2 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -115,7 +115,7 @@ MegaNodePrivate::MegaNodePrivate(MegaNode *node) this->name = MegaApi::strdup(node->getName()); this->fingerprint = MegaApi::strdup(node->getFingerprint()); this->customAttrs = NULL; - this->children = NULL; + this->children = node->getChildren(); this->type = node->getType(); this->size = node->getSize(); this->ctime = node->getCreationTime(); @@ -934,7 +934,6 @@ MegaNodePrivate::~MegaNodePrivate() delete [] fingerprint; delete customAttrs; delete plink; - delete children; } MegaUserPrivate::MegaUserPrivate(User *user) : MegaUser() @@ -10781,7 +10780,7 @@ void MegaApiImpl::sendPendingTransfers() break; } - if (!transfer->isStreamingTransfer() && node && node->type != FILENODE) + if (!transfer->isStreamingTransfer() && ((node && node->type != FILENODE) || publicNode->getType() == FOLDERNODE)) { // Folder download transferMap[nextTag] = transfer; From 431e37fc72f00cda09fe3518b0a7ba3845707bbc Mon Sep 17 00:00:00 2001 From: Victor Teniente Mateos Date: Tue, 26 Jul 2016 19:54:04 +0200 Subject: [PATCH 004/103] Improve download of folder nodes --- src/megaapi_impl.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 7c2ceecac2..d0ca949bb7 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -14184,35 +14184,35 @@ void MegaFolderDownloadController::downloadFolderNode(MegaNode *node, string *pa { pendingTransfers++; FileAccess *fa = NULL; - Node *childNode = NULL; - if (!child->isForeign()) - { - childNode = client->nodebyhandle(child->getHandle()); - fa = client->fsaccess->newfileaccess(); - } + fa = client->fsaccess->newfileaccess(); - if (childNode && fa->fopen(&localpath, true, false) && fa->type == FILENODE) + if (child && fa->fopen(&localpath, true, false) && fa->type == FILENODE) { - FileFingerprint fp; - fp.genfingerprint(fa); - if ((fp.isvalid && childNode->isvalid && fp == *(FileFingerprint *)childNode) - || (!childNode->isvalid && fa->size == childNode->size && fa->mtime == childNode->mtime)) + const char *fpLocal = megaApi->getFingerprint(localpath.c_str()); + const char *fpRemote = megaApi->getFingerprint(child); + + if ((fpLocal && fpRemote && !strcmp(fpLocal,fpRemote)) + || (!fpRemote && child->getSize() == fa->size + && child->getModificationTime() == fa->mtime)) { + delete [] fpLocal; + delete [] fpRemote; + LOG_debug << "Already downloaded file detected: " << utf8path; int nextTag = client->nextreqtag(); MegaTransferPrivate* t = new MegaTransferPrivate(MegaTransfer::TYPE_DOWNLOAD, this); t->setPath(utf8path.data()); - t->setNodeHandle(childNode->nodehandle); + t->setNodeHandle(child->getHandle()); t->setTag(nextTag); t->setFolderTransferTag(tag); - t->setTotalBytes(childNode->size); + t->setTotalBytes(child->getSize()); megaApi->transferMap[nextTag] = t; megaApi->fireOnTransferStart(t); - t->setTransferredBytes(childNode->size); - t->setDeltaSize(childNode->size); + t->setTransferredBytes(child->getSize()); + t->setDeltaSize(child->getSize()); megaApi->fireOnTransferFinish(t, MegaError(API_OK)); localpath.resize(l); delete fa; From a53485b4327ff821cf60b079bc79c0ef6c6bbcb5 Mon Sep 17 00:00:00 2001 From: Victor Teniente Mateos Date: Tue, 26 Jul 2016 20:07:01 +0200 Subject: [PATCH 005/103] Tree processor to manage COPY requests for public folders --- include/megaapi_impl.h | 14 +++ src/megaapi_impl.cpp | 204 ++++++++++++++++++++++++++++++++--------- 2 files changed, 175 insertions(+), 43 deletions(-) diff --git a/include/megaapi_impl.h b/include/megaapi_impl.h index 4dd86481e6..cb18d2cc02 100644 --- a/include/megaapi_impl.h +++ b/include/megaapi_impl.h @@ -145,6 +145,20 @@ class ExternalLogger : public Logger }; class MegaTransferPrivate; +class MegaFolderProcTree : public MegaTreeProcessor +{ +public: + NewNode* nn; + unsigned nc; + + MegaFolderProcTree(MegaClient *client); + virtual bool processMegaNode(MegaNode* node); + void allocnodes(void); + +protected: + MegaClient *client; +}; + class MegaFolderUploadController : public MegaRequestListener, public MegaTransferListener { public: diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index d0ca949bb7..fa0a09cf2a 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -6327,8 +6327,18 @@ bool MegaApiImpl::processMegaTree(MegaNode* n, MegaTreeProcessor* processor, boo Node *node = client->nodebyhandle(n->getHandle()); if(!node) { + if (n->getType() != FILENODE) + { + MegaNodeList *nList = n->getChildren(); + for (int i = 0; i < nList->size(); i++) + { + MegaNode *child = nList->get(i); + processMegaTree(child, processor); + } + } + bool result = processor->processMegaNode(n); sdkMutex.unlock(); - return true; + return result; } if (node->type != FILENODE) @@ -11172,63 +11182,93 @@ void MegaApiImpl::sendPendingRequests() if (!node) { - NewNode *newnode = new NewNode[1]; - newnode->nodekey.assign(publicNode->getNodeKey()->data(), publicNode->getNodeKey()->size()); - newnode->attrstring = new string; - - if (publicNode->isPublic()) + if (publicNode->getType() != FILENODE) { - newnode->attrstring->assign(publicNode->getAttrString()->data(), publicNode->getAttrString()->size()); - newnode->source = NEW_PUBLIC; + unsigned nc; + MegaFolderProcTree *ptree = new MegaFolderProcTree(client); + this->processMegaTree(publicNode, ptree); + ptree->allocnodes(); + nc = ptree->nc; + // build new nodes array + this->processMegaTree(publicNode, ptree); + if (!nc) + { + e = API_EARGS; + break; + } + + if (target) + { + client->putnodes(target->nodehandle, ptree->nn, nc); + } + else + { + client->putnodes(email, ptree->nn, nc); + } + delete ptree; } else { - SymmCipher key; - AttrMap attrs; - - key.setkey((const byte*)publicNode->getNodeKey()->data(), FILENODE); - string sname = publicNode->getName(); - fsAccess->normalize(&sname); - attrs.map['n'] = sname; + NewNode *newnode = new NewNode[1]; + newnode->nodekey.assign(publicNode->getNodeKey()->data(), publicNode->getNodeKey()->size()); + newnode->attrstring = new string; - const char *fingerprint = publicNode->getFingerprint(); - if (fingerprint && fingerprint[0]) + if (publicNode->isPublic()) { - m_off_t size = 0; - unsigned int fsize = strlen(fingerprint); - unsigned int ssize = fingerprint[0] - 'A'; - if (!(ssize > (sizeof(size) * 4 / 3 + 4) || fsize <= (ssize + 1))) + newnode->attrstring->assign(publicNode->getAttrString()->data(), publicNode->getAttrString()->size()); + newnode->source = NEW_PUBLIC; + } + else + { + SymmCipher key; + AttrMap attrs; + + key.setkey((const byte*)publicNode->getNodeKey()->data(), publicNode->getType()); + string sname = publicNode->getName(); + fsAccess->normalize(&sname); + attrs.map['n'] = sname; + + const char *fingerprint = publicNode->getFingerprint(); + if (fingerprint && fingerprint[0]) { - int len = sizeof(size) + 1; - byte *buf = new byte[len]; - Base64::atob(fingerprint + 1, buf, len); - int l = Serialize64::unserialize(buf, len, (uint64_t *)&size); - delete [] buf; - if (l > 0) + m_off_t size = 0; + unsigned int fsize = strlen(fingerprint); + unsigned int ssize = fingerprint[0] - 'A'; + if (!(ssize > (sizeof(size) * 4 / 3 + 4) || fsize <= (ssize + 1))) { - attrs.map['c'] = fingerprint + ssize + 1; + int len = sizeof(size) + 1; + byte *buf = new byte[len]; + Base64::atob(fingerprint + 1, buf, len); + int l = Serialize64::unserialize(buf, len, (uint64_t *)&size); + delete [] buf; + if (l > 0) + { + attrs.map['c'] = fingerprint + ssize + 1; + } } } + + string attrstring; + attrs.getjson(&attrstring); + client->makeattr(&key,newnode->attrstring, attrstring.c_str()); + newnode->source = NEW_NODE; } - string attrstring; - attrs.getjson(&attrstring); - client->makeattr(&key,newnode->attrstring, attrstring.c_str()); - newnode->source = NEW_NODE; - } + newnode->nodehandle = publicNode->getHandle(); + newnode->type = (nodetype_t)publicNode->getType(); + newnode->parenthandle = UNDEF; - newnode->nodehandle = publicNode->getHandle(); - newnode->type = FILENODE; - newnode->parenthandle = UNDEF; + if(target) + { + client->putnodes(target->nodehandle, newnode, 1); + } + else + { + client->putnodes(email, newnode, 1); + } - if(target) - { - client->putnodes(target->nodehandle, newnode, 1); - } - else - { - client->putnodes(email, newnode, 1); } + } else { @@ -13808,6 +13848,84 @@ FileInputStream::~FileInputStream() } +MegaFolderProcTree::MegaFolderProcTree(MegaClient *client) +{ + nn = NULL; + nc = 0; + this->client = client; +} + +void MegaFolderProcTree::allocnodes() +{ + if (nc) + { + nn = new NewNode[nc]; + } +} +bool MegaFolderProcTree::processMegaNode(MegaNode *n) +{ + if (nn) + { + string attrstring; + SymmCipher key; + AttrMap attrs; + NewNode* t = nn+--nc; + + // copy node + t->source = NEW_NODE; + t->type = (nodetype_t)n->getType(); + t->nodehandle = n->getHandle(); + t->parenthandle = n->getParentHandle() ? n->getParentHandle() : UNDEF; + + // copy key (if file) or generate new key (if folder) + if (n->getType() == FILENODE) + { + t->nodekey = *(n->getNodeKey()); + } + else + { + byte buf[FOLDERNODEKEYLENGTH]; + PrnGen::genblock(buf,sizeof buf); + t->nodekey.assign((char*)buf,FOLDERNODEKEYLENGTH); + } + + // attach attributes + string sname = n->getName(); + client->fsaccess->normalize(&sname); + attrs.map['n'] = sname; + + const char *fingerprint = n->getFingerprint(); + if (fingerprint && fingerprint[0]) + { + m_off_t size = 0; + unsigned int fsize = strlen(fingerprint); + unsigned int ssize = fingerprint[0] - 'A'; + if (!(ssize > (sizeof(size) * 4 / 3 + 4) || fsize <= (ssize + 1))) + { + int len = sizeof(size) + 1; + byte *buf = new byte[len]; + Base64::atob(fingerprint + 1, buf, len); + int l = Serialize64::unserialize(buf, len, (uint64_t *)&size); + delete [] buf; + if (l > 0) + { + attrs.map['c'] = fingerprint + ssize + 1; + } + } + } + + key.setkey((const byte*)t->nodekey.data(),n->getType()); + + t->attrstring = new string; + attrs.getjson(&attrstring); + client->makeattr(&key,t->attrstring, attrstring.c_str()); + } + else + { + nc++; + } + +} MegaFolderUploadController::MegaFolderUploadController(MegaApiImpl *megaApi, MegaTransferPrivate *transfer) { From 8833411799099bcfb3f5ee5efb33808f988c3763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Hern=C3=A1ndez?= Date: Wed, 27 Jul 2016 13:51:30 +0200 Subject: [PATCH 006/103] Add a new flag `okd` for `s` & `s2` packets The new flag indicates that the API has deleted the ownerkey of the share. If the flag is not received, the sharekey is preserved for nodekey rewriting. --- include/mega/share.h | 4 ++-- src/megaclient.cpp | 12 +++++++++--- src/share.cpp | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/include/mega/share.h b/include/mega/share.h index 53563b4ab6..c6fe3e508e 100644 --- a/include/mega/share.h +++ b/include/mega/share.h @@ -56,12 +56,12 @@ struct MEGA_API NewShare handle pending; bool upgrade_pending_to_full; - bool have_key, have_auth; + bool have_key, have_auth, remove_key; byte key[SymmCipher::BLOCKSIZE]; byte auth[SymmCipher::BLOCKSIZE]; - NewShare(handle, int, handle, accesslevel_t, m_time_t, const byte*, const byte* = NULL, handle = UNDEF, bool = false); + NewShare(handle, int, handle, accesslevel_t, m_time_t, const byte*, const byte* = NULL, handle = UNDEF, bool = false, bool = false); }; } // namespace diff --git a/src/megaclient.cpp b/src/megaclient.cpp index e76a39ef78..b04f7bb1c8 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -220,7 +220,7 @@ void MegaClient::mergenewshare(NewShare *s, bool notify) } // Erase sharekey if no outgoing shares (incl pending) exist - if (!n->outshares && !n->pendingshares) + if (!n->outshares && !n->pendingshares && s->remove_key) { rewriteforeignkeys(n); @@ -3494,7 +3494,7 @@ void MegaClient::sc_newnodes() // share requests come in the following flavours: // - n/k (set share key) (always symmetric) -// - n/o/u (share deletion) +// - n/o/u[/okd] (share deletion) // - n/o/u/k/r/ts[/ok][/ha] (share addition) (k can be asymmetric) // returns 0 in case of a share addition or error, 1 otherwise bool MegaClient::sc_shares() @@ -3506,6 +3506,7 @@ bool MegaClient::sc_shares() bool upgrade_pending_to_full = false; const char* k = NULL; const char* ok = NULL; + bool okremoved = false; byte ha[SymmCipher::BLOCKSIZE]; byte sharekey[SymmCipher::BLOCKSIZE]; int have_ha = 0; @@ -3541,6 +3542,10 @@ bool MegaClient::sc_shares() ok = jsonsc.getvalue(); break; + case MAKENAMEID3('o', 'k', 'd'): + okremoved = (jsonsc.getint() == 1); // owner key removed + break; + case MAKENAMEID2('h', 'a'): // outgoing share signature have_ha = Base64::atob(jsonsc.getvalue(), ha, sizeof ha) == sizeof ha; break; @@ -3616,7 +3621,8 @@ bool MegaClient::sc_shares() if (!ISUNDEF(oh) && (!ISUNDEF(uh) || !ISUNDEF(p))) { // share revocation or share without key - newshares.push_back(new NewShare(h, outbound, outbound ? uh : oh, r, 0, NULL, NULL, p, false)); + newshares.push_back(new NewShare(h, outbound, + outbound ? uh : oh, r, 0, NULL, NULL, p, false, okremoved)); return r == ACCESS_UNKNOWN; } } diff --git a/src/share.cpp b/src/share.cpp index b6bdef4d72..d19277bacd 100644 --- a/src/share.cpp +++ b/src/share.cpp @@ -81,7 +81,7 @@ void Share::update(accesslevel_t a, m_time_t t, PendingContactRequest* pending) // coutgoing: < 0 - don't authenticate, > 0 - authenticate using handle auth NewShare::NewShare(handle ch, int coutgoing, handle cpeer, accesslevel_t caccess, - m_time_t cts, const byte* ckey, const byte* cauth, handle cpending,bool cupgrade_pending_to_full) + m_time_t cts, const byte* ckey, const byte* cauth, handle cpending,bool cupgrade_pending_to_full, bool okremoved) { h = ch; outgoing = coutgoing; @@ -90,6 +90,7 @@ NewShare::NewShare(handle ch, int coutgoing, handle cpeer, accesslevel_t caccess ts = cts; pending = cpending; upgrade_pending_to_full = cupgrade_pending_to_full; + remove_key = okremoved; if (ckey) { From da81dfd4bbcd4ea8cab143fce4981842b510ee14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Hern=C3=A1ndez?= Date: Thu, 28 Jul 2016 13:08:55 +0200 Subject: [PATCH 007/103] Rearrange conditions to remove ownerkey --- src/megaclient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/megaclient.cpp b/src/megaclient.cpp index b04f7bb1c8..31c2076858 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -220,7 +220,7 @@ void MegaClient::mergenewshare(NewShare *s, bool notify) } // Erase sharekey if no outgoing shares (incl pending) exist - if (!n->outshares && !n->pendingshares && s->remove_key) + if (s->remove_key && !n->outshares && !n->pendingshares) { rewriteforeignkeys(n); From af4392f1e043b89359a0b849f94b6aff5cf92b4c Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Wed, 24 Aug 2016 19:08:48 +0200 Subject: [PATCH 008/103] Don't allow to set more than 6 connections per transfer --- include/megaapi.h | 5 ++++- src/megaapi_impl.cpp | 6 ++++++ src/megaclient.cpp | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/megaapi.h b/include/megaapi.h index 1253a075ca..37b59727ef 100644 --- a/include/megaapi.h +++ b/include/megaapi.h @@ -6180,6 +6180,9 @@ class MegaApi /** * @brief Set the maximum number of connections per transfer * + * The maximum number of allowed connections is 6. If a higher number of connections is + * passed to this function, it will fail with the error code API_ETOOMANY. + * * The associated request type with this request is MegaRequest::TYPE_SET_MAX_CONNECTIONS * Valid data in the MegaRequest object received on callbacks: * - MegaRequest::getParamType - Returns the first parameter @@ -6189,7 +6192,7 @@ class MegaApi * Valid values for this parameter are: * - MegaTransfer::TYPE_DOWNLOAD = 0 * - MegaTransfer::TYPE_UPLOAD = 1 - * @param connections Maximum number of connection (it should be at least 1) + * @param connections Maximum number of connection (it should between 1 and 6) */ void setMaxConnections(int direction, int connections, MegaRequestListener* listener = NULL); diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 1b3faac334..af27e22aac 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -12416,6 +12416,12 @@ void MegaApiImpl::sendPendingRequests() break; } + if (connections > 6) + { + e = API_ETOOMANY; + break; + } + if (direction == -1) { client->setmaxconnections(GET, connections); diff --git a/src/megaclient.cpp b/src/megaclient.cpp index bf8151efd1..49286daa06 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -10019,6 +10019,11 @@ void MegaClient::setmaxconnections(direction_t d, int num) { if (num > 0) { + if (num > 6) + { + num = 6; + } + connections[d] = num; for (transferslot_list::iterator it = tslots.begin(); it != tslots.end(); ) { From 8adacda5f6414789ed25aaf327c422971466d110 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Wed, 24 Aug 2016 19:09:45 +0200 Subject: [PATCH 009/103] Send the onRequestFinish callback when the request finishes correctly --- src/megaapi_impl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index af27e22aac..9805ead98c 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -12436,6 +12436,7 @@ void MegaApiImpl::sendPendingRequests() client->setmaxconnections(PUT, connections); } + fireOnRequestFinish(request, MegaError(API_OK)); break; } case MegaRequest::TYPE_CANCEL_TRANSFER: From eb3901f486827517eafbb2189be92586f50b121a Mon Sep 17 00:00:00 2001 From: polmr Date: Thu, 1 Sep 2016 10:21:28 +0200 Subject: [PATCH 010/103] fixed memory leak --- src/megaapi_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 7cf2421d8f..fd402f09d5 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -1050,6 +1050,7 @@ MegaNodePrivate::~MegaNodePrivate() delete customAttrs; delete plink; delete sharekey; + delete children; } MegaUserPrivate::MegaUserPrivate(User *user) : MegaUser() @@ -6641,7 +6642,6 @@ void MegaApiImpl::authorizeMegaNodePrivate(MegaNodePrivate *node) MegaNodePrivate *privNode = (MegaNodePrivate *)children->get(i); authorizeMegaNodePrivate(privNode); } - } } void MegaApiImpl::loadBalancing(const char* service, MegaRequestListener *listener) From c07f711ba7cd64fbf6c73155350b19805d07d95d Mon Sep 17 00:00:00 2001 From: polmr Date: Thu, 1 Sep 2016 18:23:33 +0200 Subject: [PATCH 011/103] fixed memory leaks & segfaults fixed mem leak at downloadFolderNode fixed segfault due to wrong copy() for MegaNode fixed segfault at sendPendingTransfers when downloading folder with non loged megaapi --- src/megaapi_impl.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index fd402f09d5..52450e4c34 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -120,6 +120,7 @@ MegaNodePrivate::MegaNodePrivate(MegaNode *node) this->fingerprint = MegaApi::strdup(node->getFingerprint()); this->customAttrs = NULL; this->children = node->getChildren(); + if (this->children) this->children = this->children->copy() this->duration = node->getDuration(); this->latitude = node->getLatitude(); this->longitude = node->getLongitude(); @@ -10975,7 +10976,7 @@ void MegaApiImpl::sendPendingTransfers() break; } - if (!transfer->isStreamingTransfer() && ((node && node->type != FILENODE) || publicNode->getType() == FOLDERNODE)) + if (!transfer->isStreamingTransfer() && ((node && node->type != FILENODE) || (publicNode && publicNode->getType() == FOLDERNODE)) ) { // Folder download transferMap[nextTag] = transfer; @@ -14625,6 +14626,9 @@ void MegaFolderDownloadController::downloadFolderNode(MegaNode *node, string *pa recursive--; checkCompletion(); + if (!node->isForeign()){ + delete children; + } } void MegaFolderDownloadController::checkCompletion() From c83b893d9dcdd60b16422647dd393c90e1b670be Mon Sep 17 00:00:00 2001 From: polmr Date: Thu, 1 Sep 2016 18:28:43 +0200 Subject: [PATCH 012/103] fixed problem that prevents folder download --- src/megaapi_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 52450e4c34..3bd503d677 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -14467,7 +14467,7 @@ void MegaFolderDownloadController::start(MegaNode *node) if (!node) { - megaApi->getNodeByHandle(transfer->getNodeHandle()); + node = megaApi->getNodeByHandle(transfer->getNodeHandle()); if (!node) { LOG_debug << "Folder download failed. Node not found"; From 1b6d78727ace298ab53457959256bec7a8a03c96 Mon Sep 17 00:00:00 2001 From: polmr Date: Thu, 1 Sep 2016 19:41:17 +0200 Subject: [PATCH 013/103] fixed use of node that may have bene delete before --- src/megaapi_impl.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 3bd503d677..af7f0c11de 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -14544,6 +14544,7 @@ void MegaFolderDownloadController::downloadFolderNode(MegaNode *node, string *pa localpath.append(client->fsaccess->localseparator); MegaNodeList *children = NULL; + bool childrenneedsdelete = false; if (node->isForeign()) { children = node->getChildren(); @@ -14551,6 +14552,7 @@ void MegaFolderDownloadController::downloadFolderNode(MegaNode *node, string *pa else { children = megaApi->getChildren(node); + childrenneedsdelete=true; } if (!children) @@ -14626,7 +14628,7 @@ void MegaFolderDownloadController::downloadFolderNode(MegaNode *node, string *pa recursive--; checkCompletion(); - if (!node->isForeign()){ + if (childrenneedsdelete){ delete children; } } From 040b33022b6a24138e9411d98a19cac09962940a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Hern=C3=A1ndez?= Date: Wed, 7 Sep 2016 13:00:43 +0200 Subject: [PATCH 014/103] Avoid duplicated chat notifications --- examples/megacli.cpp | 7 ++++--- examples/megacli.h | 2 +- include/mega/megaapp.h | 2 +- include/mega/megaclient.h | 2 +- include/mega/types.h | 1 + include/megaapi_impl.h | 4 ++-- src/megaapi_impl.cpp | 13 +++++++------ src/megaclient.cpp | 2 +- 8 files changed, 18 insertions(+), 15 deletions(-) diff --git a/examples/megacli.cpp b/examples/megacli.cpp index 5b4ac768f7..c23a42d24e 100644 --- a/examples/megacli.cpp +++ b/examples/megacli.cpp @@ -620,7 +620,7 @@ void DemoApp::chatsettitle_result(error e) } } -void DemoApp::chats_updated(textchat_vector *chats) +void DemoApp::chats_updated(textchat_map *chats) { if (chats) { @@ -633,9 +633,10 @@ void DemoApp::chats_updated(textchat_vector *chats) cout << chats->size() << " chats updated or created" << endl; } - for (int i = 0; i < chats->size(); i++) + textchat_map::iterator it; + for (it = chats->begin(); it != chats->end(); it++) { - printChatInformation(chats->at(i)); + printChatInformation(it->second); } } } diff --git a/examples/megacli.h b/examples/megacli.h index 85c2f762de..f4ab635bd8 100644 --- a/examples/megacli.h +++ b/examples/megacli.h @@ -127,7 +127,7 @@ struct DemoApp : public MegaApp virtual void chattruncate_result(error); virtual void chatsettitle_result(error); - void chats_updated(textchat_vector *); + void chats_updated(textchat_map*); void printChatInformation(TextChat *); string getPrivilegeString(privilege_t priv); diff --git a/include/mega/megaapp.h b/include/mega/megaapp.h index 9b3f927e5b..e35c0da7ce 100644 --- a/include/mega/megaapp.h +++ b/include/mega/megaapp.h @@ -205,7 +205,7 @@ struct MEGA_API MegaApp virtual void chattruncate_result(error) { } virtual void chatsettitle_result(error) { } - virtual void chats_updated(textchat_vector *) { } + virtual void chats_updated(textchat_map *) { } #endif // global transfer queue updates (separate signaling towards the queued objects) diff --git a/include/mega/megaclient.h b/include/mega/megaclient.h index ef068dcbaf..0d36a0a733 100644 --- a/include/mega/megaclient.h +++ b/include/mega/megaclient.h @@ -674,7 +674,7 @@ class MEGA_API MegaClient void filecachedel(File*); #ifdef ENABLE_CHAT - textchat_vector chatnotify; + textchat_map chatnotify; void notifychat(TextChat *); #endif diff --git a/include/mega/types.h b/include/mega/types.h index 3c45c33edc..4165455cc6 100644 --- a/include/mega/types.h +++ b/include/mega/types.h @@ -435,6 +435,7 @@ struct TextChat } }; typedef vector textchat_vector; +typedef map textchat_map; #endif typedef enum { RECOVER_WITH_MASTERKEY = 9, RECOVER_WITHOUT_MASTERKEY = 10, CANCEL_ACCOUNT = 21, CHANGE_EMAIL = 12 } recovery_t; diff --git a/include/megaapi_impl.h b/include/megaapi_impl.h index c31ac75ae9..ff18f89397 100644 --- a/include/megaapi_impl.h +++ b/include/megaapi_impl.h @@ -882,7 +882,7 @@ class MegaTextChatListPrivate : public MegaTextChatList { public: MegaTextChatListPrivate(); - MegaTextChatListPrivate(textchat_vector *list); + MegaTextChatListPrivate(textchat_map *list); virtual ~MegaTextChatListPrivate(); virtual MegaTextChatList *copy() const; @@ -1772,7 +1772,7 @@ class MegaApiImpl : public MegaApp virtual void chattruncate_result(error); virtual void chatsettitle_result(error); - virtual void chats_updated(textchat_vector *); + virtual void chats_updated(textchat_map *); #endif #ifdef ENABLE_SYNC diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 193b44fc00..03ad63b059 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -7781,8 +7781,8 @@ void MegaApiImpl::chatcreate_result(TextChat *chat, error e) if (!e) { // encapsulate the chat in a list for the request - textchat_vector chatList; - chatList.push_back(chat); + textchat_map chatList; + chatList[chat->id] = chat; MegaTextChatListPrivate *megaChatList = new MegaTextChatListPrivate(&chatList); request->setMegaTextChatList(megaChatList); @@ -7903,7 +7903,7 @@ void MegaApiImpl::chatsettitle_result(error e) -void MegaApiImpl::chats_updated(textchat_vector *chats) +void MegaApiImpl::chats_updated(textchat_map *chats) { if (!chats || !chats->size()) { @@ -16143,15 +16143,16 @@ MegaTextChatListPrivate::MegaTextChatListPrivate() } -MegaTextChatListPrivate::MegaTextChatListPrivate(textchat_vector *list) +MegaTextChatListPrivate::MegaTextChatListPrivate(textchat_map *list) { MegaTextChatPrivate *megaChat; MegaTextChatPeerListPrivate *chatPeers; TextChat *chat; - for (unsigned i = 0; i < list->size(); i++) + textchat_map::iterator it; + for (it = list->begin(); it != list->end(); it++) { - chat = list->at(i); + chat = it->second; chatPeers = chat->userpriv ? new MegaTextChatPeerListPrivate(chat->userpriv) : NULL; megaChat = new MegaTextChatPrivate(chat->id, chat->priv, chat->url, chat->shard, chatPeers, chat->group, chat->ou, chat->title); diff --git a/src/megaclient.cpp b/src/megaclient.cpp index 324aab2e5d..5dee320f48 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -6960,7 +6960,7 @@ void MegaClient::notifypcr(PendingContactRequest* pcr) #ifdef ENABLE_CHAT void MegaClient::notifychat(TextChat *chat) { - chatnotify.push_back(chat); + chatnotify[chat->id] = chat; } #endif From 6b8f9916aed81bd5dcc2df254947038032ad241f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Hern=C3=A1ndez?= Date: Wed, 7 Sep 2016 13:01:01 +0200 Subject: [PATCH 015/103] Fix some warnings --- examples/megacli.cpp | 6 +++--- src/megaapi_impl.cpp | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/megacli.cpp b/examples/megacli.cpp index c23a42d24e..c06a3cd420 100644 --- a/examples/megacli.cpp +++ b/examples/megacli.cpp @@ -4064,7 +4064,7 @@ static void process_line(char* l) os << setw(34) << it->second->targetemail; char buffer[12]; - int size = Base64::btoa((byte*)&(it->second->id), sizeof(it->second->id), buffer); + Base64::btoa((byte*)&(it->second->id), sizeof(it->second->id), buffer); os << "\t(id: "; os << buffer; @@ -4081,7 +4081,7 @@ static void process_line(char* l) os << setw(34) << it->second->originatoremail; char buffer[12]; - int size = Base64::btoa((byte*)&(it->second->id), sizeof(it->second->id), buffer); + Base64::btoa((byte*)&(it->second->id), sizeof(it->second->id), buffer); os << "\t(id: "; os << buffer; @@ -4860,7 +4860,7 @@ void DemoApp::sessions_killed(handle sessionid, error e) else { char id[12]; - int size = Base64::btoa((byte*)&(sessionid), sizeof(sessionid), id); + Base64::btoa((byte*)&(sessionid), sizeof(sessionid), id); cout << "Session with id " << id << " has been killed" << endl; } } diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 03ad63b059..872903d544 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -16082,7 +16082,7 @@ const char *MegaTextChatPrivate::getTitle() const MegaTextChatListPrivate::~MegaTextChatListPrivate() { - for (unsigned int i = 0; i < size(); i++) + for (unsigned int i = 0; i < (unsigned int) size(); i++) { delete list.at(i); } @@ -16095,7 +16095,7 @@ MegaTextChatList *MegaTextChatListPrivate::copy() const const MegaTextChat *MegaTextChatListPrivate::get(unsigned int i) const { - if (i >= size()) + if (i >= (unsigned int) size()) { return NULL; } @@ -16107,7 +16107,7 @@ const MegaTextChat *MegaTextChatListPrivate::get(unsigned int i) const MegaTextChat *MegaTextChatListPrivate::get(unsigned int i) { - if (i >= size()) + if (i >= (unsigned int) size()) { return NULL; } @@ -16131,7 +16131,7 @@ MegaTextChatListPrivate::MegaTextChatListPrivate(const MegaTextChatListPrivate * { MegaTextChatPrivate *chat; - for (unsigned int i = 0; i < list->size(); i++) + for (unsigned int i = 0; i < (unsigned) list->size(); i++) { chat = new MegaTextChatPrivate(list->get(i)); this->list.push_back(chat); From cde590f4bdda305195d16cb3a16c601c80370a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Hern=C3=A1ndez?= Date: Wed, 7 Sep 2016 13:40:59 +0200 Subject: [PATCH 016/103] Add MegaTextChat::copy() --- include/megaapi.h | 13 +++++++++++++ include/megaapi_impl.h | 2 ++ src/megaapi.cpp | 5 +++++ src/megaapi_impl.cpp | 5 +++++ 4 files changed, 25 insertions(+) diff --git a/include/megaapi.h b/include/megaapi.h index e1f3e87cab..a5574e39f2 100644 --- a/include/megaapi.h +++ b/include/megaapi.h @@ -1338,6 +1338,19 @@ class MegaTextChat virtual ~MegaTextChat(); + /** + * @brief Creates a copy of this MegaTextChat object + * + * The resulting object is fully independent of the source MegaTextChat, + * it contains a copy of all internal attributes, so it will be valid after + * the original object is deleted. + * + * You are the owner of the returned object + * + * @return Copy of the MegaTextChat object + */ + virtual MegaTextChat *copy() const; + /** * @brief getHandle Returns the MegaHandle of the chat. * @return MegaHandle of the chat. diff --git a/include/megaapi_impl.h b/include/megaapi_impl.h index ff18f89397..fe1d6a7a21 100644 --- a/include/megaapi_impl.h +++ b/include/megaapi_impl.h @@ -856,6 +856,8 @@ class MegaTextChatPrivate : public MegaTextChat MegaTextChatPrivate(const MegaTextChat *); MegaTextChatPrivate(handle id, int priv, string url, int shard, const MegaTextChatPeerList *peers, bool group, handle ou, string title); + virtual MegaTextChat *copy() const; + virtual ~MegaTextChatPrivate(); virtual MegaHandle getHandle() const; virtual int getOwnPrivilege() const; diff --git a/src/megaapi.cpp b/src/megaapi.cpp index 1237a52d91..3588548207 100644 --- a/src/megaapi.cpp +++ b/src/megaapi.cpp @@ -3715,6 +3715,11 @@ MegaTextChat::~MegaTextChat() } +MegaTextChat *MegaTextChat::copy() const +{ + return NULL; +} + MegaHandle MegaTextChat::getHandle() const { return INVALID_HANDLE; diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 872903d544..811c05fb6b 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -16023,6 +16023,11 @@ MegaTextChatPrivate::MegaTextChatPrivate(handle id, int priv, string url, int sh this->title = title; } +MegaTextChat *MegaTextChatPrivate::copy() const +{ + return new MegaTextChatPrivate(this); +} + MegaTextChatPrivate::~MegaTextChatPrivate() { delete peers; From 8a223c55dac1b6ba253d90e0d8bcca459d1f3a0d Mon Sep 17 00:00:00 2001 From: Victor Teniente Mateos Date: Tue, 27 Sep 2016 10:31:40 +0200 Subject: [PATCH 017/103] Reset system mask to use custom permissions --- src/posix/fs.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/posix/fs.cpp b/src/posix/fs.cpp index ec11104f0a..2b273043d3 100644 --- a/src/posix/fs.cpp +++ b/src/posix/fs.cpp @@ -288,6 +288,7 @@ PosixFileSystemAccess::PosixFileSystemAccess(int fseventsfd) defaultfilepermissions = 0600; defaultfolderpermissions = 0700; + umask(000); localseparator = "/"; From 218593d7f367dabadc870bdbf220e5693183ecc7 Mon Sep 17 00:00:00 2001 From: polmr Date: Wed, 28 Sep 2016 16:57:45 +0200 Subject: [PATCH 018/103] added missing ";" --- src/megaapi_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index af7f0c11de..534bb2e936 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -120,7 +120,7 @@ MegaNodePrivate::MegaNodePrivate(MegaNode *node) this->fingerprint = MegaApi::strdup(node->getFingerprint()); this->customAttrs = NULL; this->children = node->getChildren(); - if (this->children) this->children = this->children->copy() + if (this->children) this->children = this->children->copy(); this->duration = node->getDuration(); this->latitude = node->getLatitude(); this->longitude = node->getLongitude(); From 5d0477582a66d7baab9b80cb44c3e2603d4f44b7 Mon Sep 17 00:00:00 2001 From: polmr Date: Wed, 28 Sep 2016 17:10:43 +0200 Subject: [PATCH 019/103] added missing "}" --- src/megaapi_impl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 534bb2e936..0b063d524f 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -6643,6 +6643,7 @@ void MegaApiImpl::authorizeMegaNodePrivate(MegaNodePrivate *node) MegaNodePrivate *privNode = (MegaNodePrivate *)children->get(i); authorizeMegaNodePrivate(privNode); } + } } void MegaApiImpl::loadBalancing(const char* service, MegaRequestListener *listener) From ac2d3c7b6347e258ed0cfcd7399e10a8d4328f38 Mon Sep 17 00:00:00 2001 From: Javier Navarro Date: Mon, 3 Oct 2016 12:31:02 +0200 Subject: [PATCH 020/103] Initial build scripts supporting MEGAchat on iOS (incomplete) --- bindings/ios/3rdparty/build-all.sh | 9 + bindings/ios/3rdparty/build-cares.sh | 8 +- bindings/ios/3rdparty/build-curl.sh | 2 +- bindings/ios/3rdparty/build-expat.sh | 94 ++++++++++ bindings/ios/3rdparty/build-libevent2.sh | 107 ++++++++++++ bindings/ios/3rdparty/build-libsodium.sh | 2 +- bindings/ios/3rdparty/build-libuv.sh | 6 +- bindings/ios/3rdparty/build-libws.sh | 126 ++++++++++++++ bindings/ios/3rdparty/build-megachat.sh | 148 ++++++++++++++++ bindings/ios/3rdparty/build-openssl.sh | 2 +- bindings/ios/3rdparty/iOS.cmake | 211 +++++++++++++++++++++++ 11 files changed, 705 insertions(+), 10 deletions(-) create mode 100644 bindings/ios/3rdparty/build-expat.sh create mode 100644 bindings/ios/3rdparty/build-libevent2.sh create mode 100644 bindings/ios/3rdparty/build-libws.sh create mode 100644 bindings/ios/3rdparty/build-megachat.sh create mode 100644 bindings/ios/3rdparty/iOS.cmake diff --git a/bindings/ios/3rdparty/build-all.sh b/bindings/ios/3rdparty/build-all.sh index 8e9ebe50ae..379cfc22d8 100644 --- a/bindings/ios/3rdparty/build-all.sh +++ b/bindings/ios/3rdparty/build-all.sh @@ -9,4 +9,13 @@ sh build-curl.sh sh build-libuv.sh sh build-libsodium.sh +if [ "$1" == "--enable-chat"]; then + sh build-expat.sh + sh build-libevent2.sh + sh build-libws.sh + sh build-megachat.sh +fi + + echo "Done." + diff --git a/bindings/ios/3rdparty/build-cares.sh b/bindings/ios/3rdparty/build-cares.sh index e60e38ef34..4527811b87 100644 --- a/bindings/ios/3rdparty/build-cares.sh +++ b/bindings/ios/3rdparty/build-cares.sh @@ -36,7 +36,7 @@ set -e if [ ! -e "c-ares-${CARES_VERSION}.tar.gz" ] then - curl -O "http://c-ares.haxx.se/download/c-ares-${CARES_VERSION}.tar.gz" + wget "http://c-ares.haxx.se/download/c-ares-${CARES_VERSION}.tar.gz" fi tar zxf c-ares-${CARES_VERSION}.tar.gz @@ -79,9 +79,9 @@ done popd mkdir lib || true lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libcares.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libcares.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libcares.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libcares.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libcares.a -output ${CURRENTPATH}/lib/libcares.a -mkdir -p include/cares || true -cp -f c-ares-${CARES_VERSION}/ares.h c-ares-${CARES_VERSION}/ares_build.h c-ares-${CARES_VERSION}/ares_dns.h c-ares-${CARES_VERSION}/ares_rules.h c-ares-${CARES_VERSION}/ares_version.h include/cares/ -sed -i '' $'s/\#define CARES_SIZEOF_LONG 8/\#ifdef __LP64__\\\n\#define CARES_SIZEOF_LONG 8\\\n#else\\\n\#define CARES_SIZEOF_LONG 4\\\n\#endif/' include/cares/ares_build.h +mkdir -p include || true +cp -f c-ares-${CARES_VERSION}/ares.h c-ares-${CARES_VERSION}/ares_build.h c-ares-${CARES_VERSION}/ares_dns.h c-ares-${CARES_VERSION}/ares_rules.h c-ares-${CARES_VERSION}/ares_version.h include/ +sed -i '' $'s/\#define CARES_SIZEOF_LONG 8/\#ifdef __LP64__\\\n\#define CARES_SIZEOF_LONG 8\\\n#else\\\n\#define CARES_SIZEOF_LONG 4\\\n\#endif/' include/ares_build.h rm -rf c-ares-${CARES_VERSION} diff --git a/bindings/ios/3rdparty/build-curl.sh b/bindings/ios/3rdparty/build-curl.sh index 6073a9f9ef..d85eca65c2 100644 --- a/bindings/ios/3rdparty/build-curl.sh +++ b/bindings/ios/3rdparty/build-curl.sh @@ -36,7 +36,7 @@ set -e if [ ! -e "curl-${CURL_VERSION}.tar.gz" ] then -curl -O "https://curl.haxx.se/download/curl-${CURL_VERSION}.tar.gz" +wget "https://curl.haxx.se/download/curl-${CURL_VERSION}.tar.gz" fi for ARCH in ${ARCHS} diff --git a/bindings/ios/3rdparty/build-expat.sh b/bindings/ios/3rdparty/build-expat.sh new file mode 100644 index 0000000000..2f9054fa16 --- /dev/null +++ b/bindings/ios/3rdparty/build-expat.sh @@ -0,0 +1,94 @@ +#!/bin/sh + +EXPAT_VERSION="2.1.1" +SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version` + +############################################## +CURRENTPATH=`pwd` +OPENSSL_PREFIX="${CURRENTPATH}" +ARCHS="i386 x86_64 armv7 armv7s arm64" +DEVELOPER=`xcode-select -print-path` + +if [ ! -d "$DEVELOPER" ]; then + echo "xcode path is not set correctly $DEVELOPER does not exist (most likely because of xcode > 4.3)" + echo "run" + echo "sudo xcode-select -switch " + echo "for default installation:" + echo "sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer" + exit 1 +fi + +case $DEVELOPER in + *\ * ) + echo "Your Xcode path contains whitespaces, which is not supported." + exit 1 + ;; +esac + +case $CURRENTPATH in + *\ * ) + echo "Your path contains whitespaces, which is not supported by 'make install'." + exit 1 + ;; +esac + +set -e + +if [ ! -e "expat-${EXPAT_VERSION}.tar.bz2" ] +then +wget "http://downloads.sourceforge.net/project/expat/expat/2.1.1/expat-${EXPAT_VERSION}.tar.bz2" +fi + +for ARCH in ${ARCHS} +do +if [[ "${ARCH}" == "i386" || "${ARCH}" == "x86_64" ]]; +then +PLATFORM="iPhoneSimulator" +else +PLATFORM="iPhoneOS" +fi + +rm -rf expat-${EXPAT_VERSION} +tar zxf expat-${EXPAT_VERSION}.tar.bz2 +pushd "expat-${EXPAT_VERSION}" + +export BUILD_TOOLS="${DEVELOPER}" +export BUILD_DEVROOT="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer" +export BUILD_SDKROOT="${BUILD_DEVROOT}/SDKs/${PLATFORM}${SDKVERSION}.sdk" + +export CC="${BUILD_TOOLS}/usr/bin/gcc -arch ${ARCH}" +mkdir -p "${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" + +# Build +export LDFLAGS="-Os -arch ${ARCH} -Wl,-dead_strip -miphoneos-version-min=7.0 -L${BUILD_SDKROOT}/usr/lib" +export CFLAGS="-Os -arch ${ARCH} -pipe -no-cpp-precomp -isysroot ${BUILD_SDKROOT} -miphoneos-version-min=7.0 -Wno-implicit-function-declaration" +export CPPFLAGS="${CFLAGS} -I${BUILD_SDKROOT}/usr/include" +export CXXFLAGS="${CPPFLAGS}" + +if [ "${ARCH}" == "arm64" ]; then +./configure --host=aarch64-apple-darwin --enable-static --disable-shared +else +./configure --host=${ARCH}-apple-darwin --enable-static --disable-shared +fi + +make +cp -f .libs/libexpat.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/ +#make clean + +popd + +done + + +mkdir lib || true +lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libexpat.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libexpat.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libexpat.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libexpat.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libexpat.a -output ${CURRENTPATH}/lib/libexpat.a + +mkdir -p include/expat || true +cp -f expat-${EXPAT_VERSION}/lib/*.h include/expat/ + +rm -rf bin +rm -rf expat-${EXPAT_VERSION} +rm -rf expat-${EXPAT_VERSION}.tar.bz2 + + +echo "Done." diff --git a/bindings/ios/3rdparty/build-libevent2.sh b/bindings/ios/3rdparty/build-libevent2.sh new file mode 100644 index 0000000000..4d5bae9d56 --- /dev/null +++ b/bindings/ios/3rdparty/build-libevent2.sh @@ -0,0 +1,107 @@ +#!/bin/sh + +MEGACHAT_VERSION="GIT" +SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version` + +############################################## +CURRENTPATH=`pwd` +OPENSSL_PREFIX="${CURRENTPATH}" +ARCHS="i386 x86_64 armv7 armv7s arm64" +DEVELOPER=`xcode-select -print-path` + +if [ ! -d "$DEVELOPER" ]; then + echo "xcode path is not set correctly $DEVELOPER does not exist (most likely because of xcode > 4.3)" + echo "run" + echo "sudo xcode-select -switch " + echo "for default installation:" + echo "sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer" + exit 1 +fi + +case $DEVELOPER in + *\ * ) + echo "Your Xcode path contains whitespaces, which is not supported." + exit 1 + ;; +esac + +case $CURRENTPATH in + *\ * ) + echo "Your path contains whitespaces, which is not supported by 'make install'." + exit 1 + ;; +esac + +set -e + +if [ ! -d "karere-native" ] +then +git clone --recursive https://code.developers.mega.co.nz/messenger/karere-native +fi + +for ARCH in ${ARCHS} +do +if [[ "${ARCH}" == "i386" || "${ARCH}" == "x86_64" ]]; +then +PLATFORM="iPhoneSimulator" +else +PLATFORM="iPhoneOS" +fi + +pushd karere-native/third-party/libevent +git reset --hard && git clean -dfx + +export BUILD_TOOLS="${DEVELOPER}" +export BUILD_DEVROOT="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer" +export BUILD_SDKROOT="${BUILD_DEVROOT}/SDKs/${PLATFORM}${SDKVERSION}.sdk" + +export CC="${BUILD_TOOLS}/usr/bin/gcc -arch ${ARCH}" +mkdir -p "${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" + +# Build +export LDFLAGS="-Os -arch ${ARCH} -Wl,-dead_strip -miphoneos-version-min=7.0 -L${BUILD_SDKROOT}/usr/lib -L${OPENSSL_PREFIX}/lib" +export CFLAGS="-Os -arch ${ARCH} -pipe -no-cpp-precomp -isysroot ${BUILD_SDKROOT} -miphoneos-version-min=7.0 -I${OPENSSL_PREFIX}/include" +export CPPFLAGS="${CFLAGS} -I${BUILD_SDKROOT}/usr/include" +export CXXFLAGS="${CPPFLAGS}" + +./autogen.sh + +if [ "${ARCH}" == "arm64" ]; then +./configure --host=aarch64-apple-darwin --enable-static --disable-shared --disable-libevent-regress --disable-tests --disable-samples +else +./configure --host=${ARCH}-apple-darwin --enable-static --disable-shared --disable-libevent-regress --disable-tests --disable-samples +fi + +make +cp -f .libs/libevent.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/ +cp -f .libs/libevent_core.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/ +cp -f .libs/libevent_extra.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/ +cp -f .libs/libevent_pthreads.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/ +cp -f .libs/libevent_openssl.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/ + +#make clean + +popd + +done + + +mkdir lib || true +lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libevent.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libevent.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libevent.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libevent.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libevent.a -output ${CURRENTPATH}/lib/libevent.a + +lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libevent_core.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libevent_core.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libevent_core.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libevent_core.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libevent_core.a -output ${CURRENTPATH}/lib/libevent_core.a + +lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libevent_extra.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libevent_extra.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libevent_extra.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libevent_extra.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libevent_extra.a -output ${CURRENTPATH}/lib/libevent_extra.a + +lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libevent_pthreads.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libevent_pthreads.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libevent_pthreads.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libevent_pthreads.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libevent_pthreads.a -output ${CURRENTPATH}/lib/libevent_pthreads.a + +lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libevent_openssl.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libevent_openssl.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libevent_openssl.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libevent_openssl.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libevent_openssl.a -output ${CURRENTPATH}/lib/libevent_openssl.a + +mkdir -p include/libevent || true +cp -f -R karere-native/third-party/libevent/include/* include/libevent/ + +#rm -rf bin +#rm -rf expat-${EXPAT_VERSION} +#rm -rf expat-${EXPAT_VERSION}.tar.bz2 + +echo "Done." diff --git a/bindings/ios/3rdparty/build-libsodium.sh b/bindings/ios/3rdparty/build-libsodium.sh index af487e8199..a968821ce6 100644 --- a/bindings/ios/3rdparty/build-libsodium.sh +++ b/bindings/ios/3rdparty/build-libsodium.sh @@ -6,7 +6,7 @@ set -e if [ ! -e "libsodium-${LIBSODIUM_VERSION}.tar.gz" ] then -curl -LO "https://github.com/jedisct1/libsodium/releases/download/${LIBSODIUM_VERSION}/libsodium-${LIBSODIUM_VERSION}.tar.gz" +wget "https://github.com/jedisct1/libsodium/releases/download/${LIBSODIUM_VERSION}/libsodium-${LIBSODIUM_VERSION}.tar.gz" fi rm -rf libsodium-${LIBSODIUM_VERSION} diff --git a/bindings/ios/3rdparty/build-libuv.sh b/bindings/ios/3rdparty/build-libuv.sh index ee475427f5..b8cec09ece 100644 --- a/bindings/ios/3rdparty/build-libuv.sh +++ b/bindings/ios/3rdparty/build-libuv.sh @@ -36,7 +36,7 @@ set -e if [ ! -e "libuv-v${UV_VERSION}.tar.gz" ] then -curl -O "http://dist.libuv.org/dist/v${UV_VERSION}/libuv-v${UV_VERSION}.tar.gz" +wget "http://dist.libuv.org/dist/v${UV_VERSION}/libuv-v${UV_VERSION}.tar.gz" fi for ARCH in ${ARCHS} @@ -85,8 +85,8 @@ done mkdir lib || true lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libuv.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libuv.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libuv.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libuv.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libuv.a -output ${CURRENTPATH}/lib/libuv.a -mkdir -p include/uv || true -cp -f libuv-v${UV_VERSION}/include/*.h include/uv/ +mkdir -p include || true +cp -f libuv-v${UV_VERSION}/include/*.h include/ rm -rf bin rm -rf libuv-v${UV_VERSION} diff --git a/bindings/ios/3rdparty/build-libws.sh b/bindings/ios/3rdparty/build-libws.sh new file mode 100644 index 0000000000..97e5a3ff78 --- /dev/null +++ b/bindings/ios/3rdparty/build-libws.sh @@ -0,0 +1,126 @@ +#!/bin/sh + +MEGACHAT_VERSION="GIT" +SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version` + +############################################## +CURRENTPATH=`pwd` +OPENSSL_PREFIX="${CURRENTPATH}" +ARCHS="i386 x86_64 armv7 armv7s arm64" +DEVELOPER=`xcode-select -print-path` + +if [ ! -d "$DEVELOPER" ]; then + echo "xcode path is not set correctly $DEVELOPER does not exist (most likely because of xcode > 4.3)" + echo "run" + echo "sudo xcode-select -switch " + echo "for default installation:" + echo "sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer" + exit 1 +fi + +case $DEVELOPER in + *\ * ) + echo "Your Xcode path contains whitespaces, which is not supported." + exit 1 + ;; +esac + +case $CURRENTPATH in + *\ * ) + echo "Your path contains whitespaces, which is not supported by 'make install'." + exit 1 + ;; +esac + +set -e + +if [ ! -d "karere-native" ] +then +git clone --recursive https://code.developers.mega.co.nz/messenger/karere-native +fi + +for ARCH in ${ARCHS} +do + +if [[ "${ARCH}" == "i386" || "${ARCH}" == "x86_64" ]]; +then +PLATFORM="iPhoneSimulator" +else +PLATFORM="iPhoneOS" +fi + +echo "BUILDING FOR ${ARCH}" + +IOSC_TARGET=iphoneos +IOSC_OS_VERSION=-mios-version-min=7.0 +IOSC_ARCH=${ARCH} +IOSC_PLATFORM_SDKNAME=${PLATFORM} +IOSC_CMAKE_TOOLCHAIN="../ios.toolchain.cmake" +IOSC_SYSROOT=`xcrun -sdk $IOSC_TARGET -show-sdk-path` +# the same as SDKROOT + +pushd karere-native/third-party/libws +git reset --hard && git clean -dfx + +export BUILD_TOOLS="${DEVELOPER}" +export BUILD_DEVROOT="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer" +export BUILD_SDKROOT="${BUILD_DEVROOT}/SDKs/${PLATFORM}${SDKVERSION}.sdk" + +export CC="${BUILD_TOOLS}/usr/bin/gcc -arch ${ARCH}" +mkdir -p "${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" + +# Build +export LDFLAGS="-Os -arch ${ARCH} -Wl,-dead_strip -miphoneos-version-min=7.0 -L${BUILD_SDKROOT}/usr/lib" +export CFLAGS="-Os -arch ${ARCH} -pipe -no-cpp-precomp -isysroot ${BUILD_SDKROOT} -miphoneos-version-min=7.0" +export CPPFLAGS="${CFLAGS} -I${BUILD_SDKROOT}/usr/include" +export CXXFLAGS="${CPPFLAGS}" + +if [ "${ARCH}" == "arm64" ]; then + +IOSC_HOST_TRIPLET=aarch64-apple-darwin + +/Applications/CMake.app/Contents/bin/cmake . -DCMAKE_TOOLCHAIN_FILE=${CURRENTPATH}/iOS.cmake -DIOS_PLATFORM=OS -DIOS_PLATFORM_TYPE=${ARCH} -DBUILD_ARM64=1 -DCMAKE_LIBRARY_PATH=${CURRENTPATH}/lib -DCMAKE_INCLUDE_PATH=${CURRENTPATH}/include -DLIBEVENT_INCLUDE_DIRS=${CURRENTPATH}/include/libevent -DLIBEVENT_LIB_CORE=${CURRENTPATH}/lib -DLIBEVENT_LIB_EXTRA=${CURRENTPATH}/lib -DLIBEVENT_LIB_OPENSSL=${CURRENTPATH}/lib -DLIBEVENT_LIB_PTHREADS=${CURRENTPATH}/lib -DOPENSSL_INCLUDE_DIR=${CURRENTPATH}/include -DOPENSSL_SSL_LIBRARY=${CURRENTPATH}/lib/libssl.a -DOPENSSL_CRYPTO_LIBRARY=${CURRENTPATH}/lib/libcrypto.a -DOPENSSL_ROOT_DIR=${CURRENTPATH} -DLIBEVENT_LIB=${CURRENTPATH}/lib/libevent.a + +elif [ "${ARCH}" == "i386" ]; then + +IOSC_HOST_TRIPLET=${ARCH}-apple-darwin + +/Applications/CMake.app/Contents/bin/cmake . -DCMAKE_TOOLCHAIN_FILE=${CURRENTPATH}/iOS.cmake -DIOS_PLATFORM=SIMULATOR -DCMAKE_LIBRARY_PATH=${CURRENTPATH}/lib -DCMAKE_INCLUDE_PATH=${CURRENTPATH}/include -DLIBEVENT_INCLUDE_DIRS=${CURRENTPATH}/include/libevent -DLIBEVENT_LIB_CORE=${CURRENTPATH}/lib -DLIBEVENT_LIB_EXTRA=${CURRENTPATH}/lib -DLIBEVENT_LIB_OPENSSL=${CURRENTPATH}/lib -DLIBEVENT_LIB_PTHREADS=${CURRENTPATH}/lib -DOPENSSL_INCLUDE_DIR=${CURRENTPATH}/include -DOPENSSL_SSL_LIBRARY=${CURRENTPATH}/lib/libssl.a -DOPENSSL_CRYPTO_LIBRARY=${CURRENTPATH}/lib/libcrypto.a -DOPENSSL_ROOT_DIR=${CURRENTPATH} -DLIBEVENT_LIB=${CURRENTPATH}/lib/libevent.a + +elif [ "${ARCH}" == "x86_64" ]; then + +IOSC_HOST_TRIPLET=${ARCH}-apple-darwin + +/Applications/CMake.app/Contents/bin/cmake . -DCMAKE_TOOLCHAIN_FILE=${CURRENTPATH}/iOS.cmake -DIOS_PLATFORM=SIMULATOR64 -DCMAKE_LIBRARY_PATH=${CURRENTPATH}/lib -DCMAKE_INCLUDE_PATH=${CURRENTPATH}/include -DLIBEVENT_INCLUDE_DIRS=${CURRENTPATH}/include/libevent -DLIBEVENT_LIB_CORE=${CURRENTPATH}/lib -DLIBEVENT_LIB_EXTRA=${CURRENTPATH}/lib -DLIBEVENT_LIB_OPENSSL=${CURRENTPATH}/lib -DLIBEVENT_LIB_PTHREADS=${CURRENTPATH}/lib -DOPENSSL_INCLUDE_DIR=${CURRENTPATH}/include -DOPENSSL_SSL_LIBRARY=${CURRENTPATH}/lib/libssl.a -DOPENSSL_CRYPTO_LIBRARY=${CURRENTPATH}/lib/libcrypto.a -DOPENSSL_ROOT_DIR=${CURRENTPATH} -DLIBEVENT_LIB=${CURRENTPATH}/lib/libevent.a + +else + +IOSC_HOST_TRIPLET=${ARCH}-apple-darwin + +/Applications/CMake.app/Contents/bin/cmake . -DCMAKE_TOOLCHAIN_FILE=${CURRENTPATH}/iOS.cmake -DIOS_PLATFORM=OS -DIOS_PLATFORM_TYPE=${ARCH} -DCMAKE_LIBRARY_PATH=${CURRENTPATH}/lib -DCMAKE_INCLUDE_PATH=${CURRENTPATH}/include -DLIBEVENT_INCLUDE_DIRS=${CURRENTPATH}/include/libevent -DLIBEVENT_LIB_CORE=${CURRENTPATH}/lib -DLIBEVENT_LIB_EXTRA=${CURRENTPATH}/lib -DLIBEVENT_LIB_OPENSSL=${CURRENTPATH}/lib -DLIBEVENT_LIB_PTHREADS=${CURRENTPATH}/lib -DOPENSSL_INCLUDE_DIR=${CURRENTPATH}/include -DOPENSSL_SSL_LIBRARY=${CURRENTPATH}/lib/libssl.a -DOPENSSL_CRYPTO_LIBRARY=${CURRENTPATH}/lib/libcrypto.a -DOPENSSL_ROOT_DIR=${CURRENTPATH} -DLIBEVENT_LIB=${CURRENTPATH}/lib/libevent.a +fi + +CMAKE_XCOMPILE_ARGS="-DCMAKE_TOOLCHAIN_FILE=$IOSC_CMAKE_TOOLCHAIN -DCMAKE_INSTALL_PREFIX=$IOSC_BUILDROOT" +CONFIGURE_XCOMPILE_ARGS="--prefix=$IOSC_BUILDROOT --host=$IOSC_HOST_TRIPLET" + +make + +cp -f lib/libws.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/ + +popd + +done + + +mkdir lib || true +lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libws.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libws.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libws.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libws.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libws.a -output ${CURRENTPATH}/lib/libws.a + +#mkdir -p include/libws || true +#cp -f expat-${EXPAT_VERSION}/lib/*.h include/expat/ + +#rm -rf bin +#rm -rf expat-${EXPAT_VERSION} +#rm -rf expat-${EXPAT_VERSION}.tar.bz2 + + +echo "Done." diff --git a/bindings/ios/3rdparty/build-megachat.sh b/bindings/ios/3rdparty/build-megachat.sh new file mode 100644 index 0000000000..c80959923a --- /dev/null +++ b/bindings/ios/3rdparty/build-megachat.sh @@ -0,0 +1,148 @@ +#!/bin/sh + +MEGACHAT_VERSION="GIT" +SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version` + +############################################## +CURRENTPATH=`pwd` +OPENSSL_PREFIX="${CURRENTPATH}" +ARCHS="i386 x86_64 armv7 armv7s arm64" +DEVELOPER=`xcode-select -print-path` + +if [ ! -d "$DEVELOPER" ]; then + echo "xcode path is not set correctly $DEVELOPER does not exist (most likely because of xcode > 4.3)" + echo "run" + echo "sudo xcode-select -switch " + echo "for default installation:" + echo "sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer" + exit 1 +fi + +case $DEVELOPER in + *\ * ) + echo "Your Xcode path contains whitespaces, which is not supported." + exit 1 + ;; +esac + +case $CURRENTPATH in + *\ * ) + echo "Your path contains whitespaces, which is not supported by 'make install'." + exit 1 + ;; +esac + +set -e + +if [ ! -d "karere-native" ] +then +git clone --recursive https://code.developers.mega.co.nz/messenger/karere-native +git branch feature/mega-chat-api +fi + +if [ ! -d "include/webrtc" ] +then + WEBRTC_REVISION=9ac4df1ba66d39c3621cfb2e8ed08ae39658b793 + mkdir -p webrtc + pushd webrtc + git init + git remote add origin https://chromium.googlesource.com/external/webrtc.git + git fetch --depth=1 origin ${WEBRTC_REVISION} + git checkout ${WEBRTC_REVISION} + popd + ln -s ../webrtc/webrtc include/webrtc + ln -s ../../mega include/mega +fi + +for ARCH in ${ARCHS} +do + +if [[ "${ARCH}" == "i386" || "${ARCH}" == "x86_64" ]]; +then +PLATFORM="iPhoneSimulator" +else +PLATFORM="iPhoneOS" +fi + +echo "BUILDING FOR ${ARCH}" + +IOSC_TARGET=iphoneos +IOSC_OS_VERSION=-mios-version-min=7.0 +IOSC_ARCH=${ARCH} +IOSC_PLATFORM_SDKNAME=${PLATFORM} +IOSC_CMAKE_TOOLCHAIN="../ios.toolchain.cmake" +IOSC_SYSROOT=`xcrun -sdk $IOSC_TARGET -show-sdk-path` +# the same as SDKROOT + +pushd karere-native/src +git reset --hard && git clean -dfx + +export BUILD_TOOLS="${DEVELOPER}" +export BUILD_DEVROOT="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer" +export BUILD_SDKROOT="${BUILD_DEVROOT}/SDKs/${PLATFORM}${SDKVERSION}.sdk" + +export CC="${BUILD_TOOLS}/usr/bin/gcc -arch ${ARCH}" +mkdir -p "${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" + +# Build +export LDFLAGS="-Os -arch ${ARCH} -Wl,-dead_strip -miphoneos-version-min=7.0 -L${BUILD_SDKROOT}/usr/lib" +export CFLAGS="-Os -arch ${ARCH} -pipe -no-cpp-precomp -isysroot ${BUILD_SDKROOT} -miphoneos-version-min=7.0" +export CPPFLAGS="${CFLAGS} -I${BUILD_SDKROOT}/usr/include" +export CXXFLAGS="${CPPFLAGS}" + +if [ "${ARCH}" == "arm64" ]; then + +IOSC_HOST_TRIPLET=aarch64-apple-darwin + +/Applications/CMake.app/Contents/bin/cmake . -D_LIBMEGA_LIBRARIES= -DLIBMEGA_PUBLIC_INCLUDE_DIR=../../../../../include -DCMAKE_SYSROOT=${CURRENTPATH} -DCMAKE_TOOLCHAIN_FILE=${CURRENTPATH}/iOS.cmake -DIOS_PLATFORM=OS -DIOS_PLATFORM_TYPE=${ARCH} -DBUILD_ARM64=1 -DCMAKE_LIBRARY_PATH=${CURRENTPATH}/lib -DCMAKE_INCLUDE_PATH=${CURRENTPATH}/include -DLIBEVENT_INCLUDE_DIRS=${CURRENTPATH}/include/libevent -DLIBEVENT_LIB_CORE=${CURRENTPATH}/lib -DLIBEVENT_LIB_EXTRA=${CURRENTPATH}/lib -DLIBEVENT_LIB_OPENSSL=${CURRENTPATH}/lib -DLIBEVENT_LIB_PTHREADS=${CURRENTPATH}/lib -DOPENSSL_INCLUDE_DIR=${CURRENTPATH}/include -DOPENSSL_SSL_LIBRARY=${CURRENTPATH}/lib/libssl.a -DOPENSSL_CRYPTO_LIBRARY=${CURRENTPATH}/lib/libcrypto.a -DOPENSSL_ROOT_DIR=${CURRENTPATH} -DLIBEVENT_LIB=${CURRENTPATH}/lib/libevent.a + +elif [ "${ARCH}" == "i386" ]; then + +IOSC_HOST_TRIPLET=${ARCH}-apple-darwin + +/Applications/CMake.app/Contents/bin/cmake . -D_LIBMEGA_LIBRARIES= -DLIBMEGA_PUBLIC_INCLUDE_DIR=../../../../../include -DCMAKE_SYSROOT=${CURRENTPATH} -DCMAKE_TOOLCHAIN_FILE=${CURRENTPATH}/iOS.cmake -DIOS_PLATFORM=SIMULATOR -DCMAKE_LIBRARY_PATH=${CURRENTPATH}/lib -DCMAKE_INCLUDE_PATH=${CURRENTPATH}/include -DLIBEVENT_INCLUDE_DIRS=${CURRENTPATH}/include/libevent -DLIBEVENT_LIB_CORE=${CURRENTPATH}/lib -DLIBEVENT_LIB_EXTRA=${CURRENTPATH}/lib -DLIBEVENT_LIB_OPENSSL=${CURRENTPATH}/lib -DLIBEVENT_LIB_PTHREADS=${CURRENTPATH}/lib -DOPENSSL_INCLUDE_DIR=${CURRENTPATH}/include -DOPENSSL_SSL_LIBRARY=${CURRENTPATH}/lib/libssl.a -DOPENSSL_CRYPTO_LIBRARY=${CURRENTPATH}/lib/libcrypto.a -DOPENSSL_ROOT_DIR=${CURRENTPATH} -DLIBEVENT_LIB=${CURRENTPATH}/lib/libevent.a + +elif [ "${ARCH}" == "x86_64" ]; then + +IOSC_HOST_TRIPLET=${ARCH}-apple-darwin + +/Applications/CMake.app/Contents/bin/cmake . -D_LIBMEGA_LIBRARIES= -DLIBMEGA_PUBLIC_INCLUDE_DIR=../../../../../include -DCMAKE_SYSROOT=${CURRENTPATH} -DCMAKE_TOOLCHAIN_FILE=${CURRENTPATH}/iOS.cmake -DIOS_PLATFORM=SIMULATOR64 -DCMAKE_LIBRARY_PATH=${CURRENTPATH}/lib -DCMAKE_INCLUDE_PATH=${CURRENTPATH}/include -DLIBEVENT_INCLUDE_DIRS=${CURRENTPATH}/include/libevent -DLIBEVENT_LIB_CORE=${CURRENTPATH}/lib -DLIBEVENT_LIB_EXTRA=${CURRENTPATH}/lib -DLIBEVENT_LIB_OPENSSL=${CURRENTPATH}/lib -DLIBEVENT_LIB_PTHREADS=${CURRENTPATH}/lib -DOPENSSL_INCLUDE_DIR=${CURRENTPATH}/include -DOPENSSL_SSL_LIBRARY=${CURRENTPATH}/lib/libssl.a -DOPENSSL_CRYPTO_LIBRARY=${CURRENTPATH}/lib/libcrypto.a -DOPENSSL_ROOT_DIR=${CURRENTPATH} -DLIBEVENT_LIB=${CURRENTPATH}/lib/libevent.a + +else + +IOSC_HOST_TRIPLET=${ARCH}-apple-darwin + +/Applications/CMake.app/Contents/bin/cmake . -D_LIBMEGA_LIBRARIES= -DLIBMEGA_PUBLIC_INCLUDE_DIR=../../../../../include -DCMAKE_SYSROOT=${CURRENTPATH} -DCMAKE_TOOLCHAIN_FILE=${CURRENTPATH}/iOS.cmake -DIOS_PLATFORM=OS -DIOS_PLATFORM_TYPE=${ARCH} -DCMAKE_LIBRARY_PATH=${CURRENTPATH}/lib -DCMAKE_INCLUDE_PATH=${CURRENTPATH}/include -DLIBEVENT_INCLUDE_DIRS=${CURRENTPATH}/include/libevent -DLIBEVENT_LIB_CORE=${CURRENTPATH}/lib -DLIBEVENT_LIB_EXTRA=${CURRENTPATH}/lib -DLIBEVENT_LIB_OPENSSL=${CURRENTPATH}/lib -DLIBEVENT_LIB_PTHREADS=${CURRENTPATH}/lib -DOPENSSL_INCLUDE_DIR=${CURRENTPATH}/include -DOPENSSL_SSL_LIBRARY=${CURRENTPATH}/lib/libssl.a -DOPENSSL_CRYPTO_LIBRARY=${CURRENTPATH}/lib/libcrypto.a -DOPENSSL_ROOT_DIR=${CURRENTPATH} -DLIBEVENT_LIB=${CURRENTPATH}/lib/libevent.a +fi + +CMAKE_XCOMPILE_ARGS="-DCMAKE_TOOLCHAIN_FILE=$IOSC_CMAKE_TOOLCHAIN -DCMAKE_INSTALL_PREFIX=$IOSC_BUILDROOT" +CONFIGURE_XCOMPILE_ARGS="--prefix=$IOSC_BUILDROOT --host=$IOSC_HOST_TRIPLET" + +make + +cp -f libkarere.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/libkarere.a +cp -f rtcModule/base/libservices.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/libservices.a +cp -f rtcModule/base/strophe/libstrophe.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/libstrophe.a +cp -f rtcModule/librtcmodule.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/librtcmodule.a +cp -f rtcModule/webrtc/libwebrtc_my.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/libwebrtc_my.a + +popd + +done + + +mkdir lib || true +lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libkarere.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libkarere.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libkarere.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libkarere.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libkarere.a -output ${CURRENTPATH}/lib/libkarere.a +lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libservices.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libservices.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libservices.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libservices.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libservices.a -output ${CURRENTPATH}/lib/libservices.a +lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libstrophe.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libstrophe.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libstrophe.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libstrophe.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libstrophe.a -output ${CURRENTPATH}/lib/libws.a +lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/librtcmodule.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/librtcmodule.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/librtcmodule.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/librtcmodule.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/librtcmodule.a -output ${CURRENTPATH}/lib/librtcmodule.a +lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libwebrtc_my.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libwebrtc_my.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libwebrtc_my.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libwebrtc_my.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libwebrtc_my.a -output ${CURRENTPATH}/lib/libwebrtc_my.a + +mkdir -p include || true +cp -f karere-native/src/megachatapi.h include/ + +#rm -rf bin +#rm -rf expat-${EXPAT_VERSION} +#rm -rf expat-${EXPAT_VERSION}.tar.bz2 + +echo "Done." diff --git a/bindings/ios/3rdparty/build-openssl.sh b/bindings/ios/3rdparty/build-openssl.sh index 60a7eea4fb..751f57a439 100644 --- a/bindings/ios/3rdparty/build-openssl.sh +++ b/bindings/ios/3rdparty/build-openssl.sh @@ -36,7 +36,7 @@ set -e if [ ! -e openssl-${VERSION}.tar.gz ]; then - curl -O http://www.openssl.org/source/openssl-${VERSION}.tar.gz + wget http://www.openssl.org/source/openssl-${VERSION}.tar.gz fi mkdir -p "${CURRENTPATH}/src" diff --git a/bindings/ios/3rdparty/iOS.cmake b/bindings/ios/3rdparty/iOS.cmake new file mode 100644 index 0000000000..7237c03b06 --- /dev/null +++ b/bindings/ios/3rdparty/iOS.cmake @@ -0,0 +1,211 @@ +# This file is based off of the Platform/Darwin.cmake and Platform/UnixPaths.cmake +# files which are included with CMake 2.8.4 +# It has been altered for iOS development + +# Options: +# +# IOS_PLATFORM = OS (default) or SIMULATOR or SIMULATOR64 +# This decides if SDKS will be selected from the iPhoneOS.platform or iPhoneSimulator.platform folders +# OS - the default, used to build for iPhone and iPad physical devices, which have an arm arch. +# SIMULATOR - used to build for the Simulator platforms, which have an x86 arch. +# +# CMAKE_IOS_DEVELOPER_ROOT = automatic(default) or /path/to/platform/Developer folder +# By default this location is automatcially chosen based on the IOS_PLATFORM value above. +# If set manually, it will override the default location and force the user of a particular Developer Platform +# +# CMAKE_IOS_SDK_ROOT = automatic(default) or /path/to/platform/Developer/SDKs/SDK folder +# By default this location is automatcially chosen based on the CMAKE_IOS_DEVELOPER_ROOT value. +# In this case it will always be the most up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path. +# If set manually, this will force the use of a specific SDK version + +# Macros: +# +# set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE) +# A convenience macro for setting xcode specific properties on targets +# example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1") +# +# find_host_package (PROGRAM ARGS) +# A macro used to find executable programs on the host system, not within the iOS environment. +# Thanks to the android-cmake project for providing the command + +# Standard settings +set (CMAKE_SYSTEM_NAME Darwin) +set (CMAKE_SYSTEM_VERSION 1) +set (UNIX True) +set (APPLE True) +set (IOS True) + +set(APPLE_IOS ON) +set(TARGET_OS_IPHONE ON) + +# Required as of cmake 2.8.10 +set (CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE) + +# Determine the cmake host system version so we know where to find the iOS SDKs +find_program (CMAKE_UNAME uname /bin /usr/bin /usr/local/bin) +if (CMAKE_UNAME) + exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION) + string (REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}") +endif (CMAKE_UNAME) + +# Force the compilers to gcc for iOS +include (CMakeForceCompiler) +CMAKE_FORCE_C_COMPILER (/usr/bin/gcc Apple) +CMAKE_FORCE_CXX_COMPILER (/usr/bin/g++ Apple) +set(CMAKE_AR ar CACHE FILEPATH "" FORCE) + +# Skip the platform compiler checks for cross compiling +set (CMAKE_CXX_COMPILER_WORKS TRUE) +set (CMAKE_C_COMPILER_WORKS TRUE) + +# All iOS/Darwin specific settings - some may be redundant +set (CMAKE_SHARED_LIBRARY_PREFIX "lib") +set (CMAKE_SHARED_LIBRARY_SUFFIX ".dylib") +set (CMAKE_SHARED_MODULE_PREFIX "lib") +set (CMAKE_SHARED_MODULE_SUFFIX ".so") +set (CMAKE_MODULE_EXISTS 1) +set (CMAKE_DL_LIBS "") + +set (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ") +set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ") +set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}") +set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}") + +# Hidden visibilty is required for cxx on iOS +set (CMAKE_C_FLAGS_INIT "") +set (CMAKE_CXX_FLAGS_INIT "-fvisibility=hidden -fvisibility-inlines-hidden -stdlib=libc++ -std=c++11") + +set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") +set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}") + +set (CMAKE_PLATFORM_HAS_INSTALLNAME 1) +set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names") +set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names") +set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,") +set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,") +set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a") + +# hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree +# (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache +# and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun) +# hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex +if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL) + find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool) +endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL) + +# Setup iOS platform unless specified manually with IOS_PLATFORM +if (NOT DEFINED IOS_PLATFORM) + set (IOS_PLATFORM "OS") +endif (NOT DEFINED IOS_PLATFORM) +set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform") + +# Setup building for arm64 or not +if (NOT DEFINED BUILD_ARM64) + set (BUILD_ARM64 true) +endif (NOT DEFINED BUILD_ARM64) +set (BUILD_ARM64 ${BUILD_ARM64} CACHE STRING "Build arm64 arch or not") + +# Check the platform selection and setup for developer root +if (${IOS_PLATFORM} STREQUAL "OS") + set (IOS_PLATFORM_LOCATION "iPhoneOS.platform") + + # This causes the installers to properly locate the output libraries + set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos") +elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR") + set (SIMULATOR true) + set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform") + + # This causes the installers to properly locate the output libraries + set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator") +elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR64") + set (SIMULATOR true) + set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform") + + # This causes the installers to properly locate the output libraries + set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator") +else (${IOS_PLATFORM} STREQUAL "OS") + message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR") +endif (${IOS_PLATFORM} STREQUAL "OS") + +# Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT +# Note Xcode 4.3 changed the installation location, choose the most recent one available +exec_program(/usr/bin/xcode-select ARGS -print-path OUTPUT_VARIABLE CMAKE_XCODE_DEVELOPER_DIR) +set (XCODE_POST_43_ROOT "${CMAKE_XCODE_DEVELOPER_DIR}/Platforms/${IOS_PLATFORM_LOCATION}/Developer") +set (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer") +if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) + if (EXISTS ${XCODE_POST_43_ROOT}) + set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT}) + elseif(EXISTS ${XCODE_PRE_43_ROOT}) + set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT}) + endif (EXISTS ${XCODE_POST_43_ROOT}) +endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) +set (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform") + +# Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT +if (NOT DEFINED CMAKE_IOS_SDK_ROOT) + file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*") + if (_CMAKE_IOS_SDKS) + list (SORT _CMAKE_IOS_SDKS) + list (REVERSE _CMAKE_IOS_SDKS) + list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT) + else (_CMAKE_IOS_SDKS) + message (FATAL_ERROR "No iOS SDK's found in default search path ${CMAKE_IOS_DEVELOPER_ROOT}. Manually set CMAKE_IOS_SDK_ROOT or install the iOS SDK.") + endif (_CMAKE_IOS_SDKS) + message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}") +endif (NOT DEFINED CMAKE_IOS_SDK_ROOT) +set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK") + +# Set the sysroot default to the most recent SDK +set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support") + +# set the architecture for iOS +if (${IOS_PLATFORM} STREQUAL "OS") + set (IOS_ARCH ${IOS_PLATFORM_TYPE}) +elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR") + set (IOS_ARCH i386) +elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR64") + set (IOS_ARCH x86_64) +endif (${IOS_PLATFORM} STREQUAL "OS") + +set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS") + +# Set the find root to the iOS developer roots and to user defined paths +set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string "iOS find search path root") + +# default to searching for frameworks first +set (CMAKE_FIND_FRAMEWORK FIRST) + +# set up the default search directories for frameworks +set (CMAKE_SYSTEM_FRAMEWORK_PATH + ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks + ${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks + ${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks +) + +# only search the iOS sdks, not the remainder of the host filesystem +set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) +set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + + +# This little macro lets you set any XCode specific property +macro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE) + set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE}) +endmacro (set_xcode_property) + + +# This macro lets you find executable programs on the host system +macro (find_host_package) + set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) + set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) + set (IOS FALSE) + + find_package(${ARGN}) + + set (IOS TRUE) + set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) + set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +endmacro (find_host_package) + From b15f60db143fb9741c02f33c5772c032440b1d39 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Mon, 3 Oct 2016 20:07:22 +0200 Subject: [PATCH 021/103] New build script for libsodium. Fixes compilation on macOS Sierra --- bindings/ios/3rdparty/build-libsodium.sh | 75 ++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/bindings/ios/3rdparty/build-libsodium.sh b/bindings/ios/3rdparty/build-libsodium.sh index a968821ce6..83bec7b891 100644 --- a/bindings/ios/3rdparty/build-libsodium.sh +++ b/bindings/ios/3rdparty/build-libsodium.sh @@ -1,6 +1,35 @@ #!/bin/sh LIBSODIUM_VERSION="1.0.11" +SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version` + +############################################## +CURRENTPATH=`pwd` +ARCHS="i386 x86_64 armv7 armv7s arm64" +DEVELOPER=`xcode-select -print-path` + +if [ ! -d "$DEVELOPER" ]; then + echo "xcode path is not set correctly $DEVELOPER does not exist (most likely because of xcode > 4.3)" + echo "run" + echo "sudo xcode-select -switch " + echo "for default installation:" + echo "sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer" + exit 1 +fi + +case $DEVELOPER in + *\ * ) + echo "Your Xcode path contains whitespaces, which is not supported." + exit 1 + ;; +esac + +case $CURRENTPATH in + *\ * ) + echo "Your path contains whitespaces, which is not supported by 'make install'." + exit 1 + ;; +esac set -e @@ -9,20 +38,54 @@ then wget "https://github.com/jedisct1/libsodium/releases/download/${LIBSODIUM_VERSION}/libsodium-${LIBSODIUM_VERSION}.tar.gz" fi +for ARCH in ${ARCHS} +do +if [[ "${ARCH}" == "i386" || "${ARCH}" == "x86_64" ]]; +then +PLATFORM="iPhoneSimulator" +else +PLATFORM="iPhoneOS" +fi + rm -rf libsodium-${LIBSODIUM_VERSION} tar zxf libsodium-${LIBSODIUM_VERSION}.tar.gz pushd "libsodium-${LIBSODIUM_VERSION}" -sh dist-build/ios.sh +export BUILD_TOOLS="${DEVELOPER}" +export BUILD_DEVROOT="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer" +export BUILD_SDKROOT="${BUILD_DEVROOT}/SDKs/${PLATFORM}${SDKVERSION}.sdk" -cp -f libsodium-ios/lib/libsodium.a ../lib -cp -fR libsodium-ios/include/sodium* ../include -#make clean +export CC="${BUILD_TOOLS}/usr/bin/gcc -arch ${ARCH}" +mkdir -p "${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" + +# Build +export LDFLAGS="-Os -arch ${ARCH} -Wl,-dead_strip -miphoneos-version-min=7.0 -L${BUILD_SDKROOT}/usr/lib" +export CFLAGS="-Os -arch ${ARCH} -pipe -no-cpp-precomp -isysroot ${BUILD_SDKROOT} -miphoneos-version-min=7.0" +export CPPFLAGS="${CFLAGS} -I${BUILD_SDKROOT}/usr/include" +export CXXFLAGS="${CPPFLAGS}" + +if [ "${ARCH}" == "arm64" ]; then +./configure --host=aarch64-apple-darwin --disable-shared --enable-minimal +else +./configure --host=${ARCH}-apple-darwin --disable-shared --enable-minimal +fi + +make -j8 + +cp -f src/libsodium/.libs/libsodium.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/ popd -rm -rf libsodium-${LIBSODIUM_VERSION} -rm -rf libsodium-${LIBSODIUM_VERSION}.tar.gz +done + +mkdir lib || true +lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libsodium.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libsodium.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libsodium.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libsodium.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libsodium.a -output ${CURRENTPATH}/lib/libsodium.a + +cp -fR libsodium-${LIBSODIUM_VERSION}/src/libsodium/include/sodium* include + +rm -rf bin +rm -rf libsodium-${LIBSODIUM_VERSION} echo "Done." + From be8e1ba7a13e2ba4846f929e3ad627315d39b6ec Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Mon, 3 Oct 2016 20:09:18 +0200 Subject: [PATCH 022/103] Fixes to build scripts related to MEGAchat --- bindings/ios/3rdparty/.gitignore | 3 +++ bindings/ios/3rdparty/build-cares.sh | 2 +- bindings/ios/3rdparty/build-cryptopp.sh | 4 ++-- bindings/ios/3rdparty/build-curl.sh | 2 +- bindings/ios/3rdparty/build-expat.sh | 2 +- bindings/ios/3rdparty/build-libevent2.sh | 4 ++-- bindings/ios/3rdparty/build-libuv.sh | 2 +- bindings/ios/3rdparty/build-libws.sh | 4 ++-- bindings/ios/3rdparty/build-megachat.sh | 7 +++---- bindings/ios/3rdparty/build-openssl.sh | 4 ++-- 10 files changed, 18 insertions(+), 16 deletions(-) diff --git a/bindings/ios/3rdparty/.gitignore b/bindings/ios/3rdparty/.gitignore index 5c7ebcafc6..df8228e00b 100644 --- a/bindings/ios/3rdparty/.gitignore +++ b/bindings/ios/3rdparty/.gitignore @@ -2,6 +2,9 @@ /cryptopp*.zip /curl* /openssl* +/libsodium* /include /lib +/karere-native +/webrtc diff --git a/bindings/ios/3rdparty/build-cares.sh b/bindings/ios/3rdparty/build-cares.sh index 4527811b87..4c76356fdf 100644 --- a/bindings/ios/3rdparty/build-cares.sh +++ b/bindings/ios/3rdparty/build-cares.sh @@ -70,7 +70,7 @@ else ./configure --host=${ARCH}-apple-darwin --enable-static --disable-shared fi -make +make -j8 cp -f .libs/libcares.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/ make clean diff --git a/bindings/ios/3rdparty/build-cryptopp.sh b/bindings/ios/3rdparty/build-cryptopp.sh index 2d75d02c9f..72f0280da1 100644 --- a/bindings/ios/3rdparty/build-cryptopp.sh +++ b/bindings/ios/3rdparty/build-cryptopp.sh @@ -20,8 +20,8 @@ fi unzip cryptopp${CRYPTOPP_VERSION}.zip -d cryptopp # Step 1. Build versions for devices and simulator -xcodebuild -target cryptopp ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" -xcodebuild -target cryptopp ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphonesimulator BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" +xcodebuild -jobs 8 -target cryptopp ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" +xcodebuild -jobs 8 -target cryptopp ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphonesimulator BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" # Make sure the output directory exists mkdir -p "${UNIVERSAL_OUTPUTFOLDER}" diff --git a/bindings/ios/3rdparty/build-curl.sh b/bindings/ios/3rdparty/build-curl.sh index d85eca65c2..c1a78bb4df 100644 --- a/bindings/ios/3rdparty/build-curl.sh +++ b/bindings/ios/3rdparty/build-curl.sh @@ -71,7 +71,7 @@ else ./configure --host=${ARCH}-apple-darwin --enable-static --disable-shared --with-ssl=${OPENSSL_PREFIX} --with-zlib --disable-manual --disable-ftp --disable-file --disable-ldap --disable-ldaps --disable-rtsp --disable-proxy --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smtp --disable-gopher --disable-sspi --enable-ipv6 --disable-smb fi -make +make -j8 cp -f lib/.libs/libcurl.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/ #make clean diff --git a/bindings/ios/3rdparty/build-expat.sh b/bindings/ios/3rdparty/build-expat.sh index 2f9054fa16..b1fee782fe 100644 --- a/bindings/ios/3rdparty/build-expat.sh +++ b/bindings/ios/3rdparty/build-expat.sh @@ -71,7 +71,7 @@ else ./configure --host=${ARCH}-apple-darwin --enable-static --disable-shared fi -make +make -j8 cp -f .libs/libexpat.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/ #make clean diff --git a/bindings/ios/3rdparty/build-libevent2.sh b/bindings/ios/3rdparty/build-libevent2.sh index 4d5bae9d56..fdc75be9e4 100644 --- a/bindings/ios/3rdparty/build-libevent2.sh +++ b/bindings/ios/3rdparty/build-libevent2.sh @@ -36,7 +36,7 @@ set -e if [ ! -d "karere-native" ] then -git clone --recursive https://code.developers.mega.co.nz/messenger/karere-native +git clone --recursive -b feature/mega-chat-api https://code.developers.mega.co.nz/messenger/karere-native fi for ARCH in ${ARCHS} @@ -72,7 +72,7 @@ else ./configure --host=${ARCH}-apple-darwin --enable-static --disable-shared --disable-libevent-regress --disable-tests --disable-samples fi -make +make -j8 cp -f .libs/libevent.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/ cp -f .libs/libevent_core.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/ cp -f .libs/libevent_extra.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/ diff --git a/bindings/ios/3rdparty/build-libuv.sh b/bindings/ios/3rdparty/build-libuv.sh index b8cec09ece..c5212dd2e3 100644 --- a/bindings/ios/3rdparty/build-libuv.sh +++ b/bindings/ios/3rdparty/build-libuv.sh @@ -73,7 +73,7 @@ else ./configure --host=${ARCH}-apple-darwin --enable-static --disable-shared fi -make +make -j8 cp -f .libs/libuv.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/ #make clean diff --git a/bindings/ios/3rdparty/build-libws.sh b/bindings/ios/3rdparty/build-libws.sh index 97e5a3ff78..5feba8a0eb 100644 --- a/bindings/ios/3rdparty/build-libws.sh +++ b/bindings/ios/3rdparty/build-libws.sh @@ -36,7 +36,7 @@ set -e if [ ! -d "karere-native" ] then -git clone --recursive https://code.developers.mega.co.nz/messenger/karere-native +git clone --recursive -b feature/mega-chat-api https://code.developers.mega.co.nz/messenger/karere-native fi for ARCH in ${ARCHS} @@ -103,7 +103,7 @@ fi CMAKE_XCOMPILE_ARGS="-DCMAKE_TOOLCHAIN_FILE=$IOSC_CMAKE_TOOLCHAIN -DCMAKE_INSTALL_PREFIX=$IOSC_BUILDROOT" CONFIGURE_XCOMPILE_ARGS="--prefix=$IOSC_BUILDROOT --host=$IOSC_HOST_TRIPLET" -make +make -j8 cp -f lib/libws.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/ diff --git a/bindings/ios/3rdparty/build-megachat.sh b/bindings/ios/3rdparty/build-megachat.sh index c80959923a..a9e7cadb47 100644 --- a/bindings/ios/3rdparty/build-megachat.sh +++ b/bindings/ios/3rdparty/build-megachat.sh @@ -36,8 +36,7 @@ set -e if [ ! -d "karere-native" ] then -git clone --recursive https://code.developers.mega.co.nz/messenger/karere-native -git branch feature/mega-chat-api +git clone --recursive -b feature/mega-chat-api https://code.developers.mega.co.nz/messenger/karere-native fi if [ ! -d "include/webrtc" ] @@ -86,7 +85,7 @@ mkdir -p "${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" # Build export LDFLAGS="-Os -arch ${ARCH} -Wl,-dead_strip -miphoneos-version-min=7.0 -L${BUILD_SDKROOT}/usr/lib" -export CFLAGS="-Os -arch ${ARCH} -pipe -no-cpp-precomp -isysroot ${BUILD_SDKROOT} -miphoneos-version-min=7.0" +export CFLAGS="-Os -arch ${ARCH} -pipe -no-cpp-precomp -isysroot ${BUILD_SDKROOT} -miphoneos-version-min=7.0 -D_DARWIN_C_SOURCE" export CPPFLAGS="${CFLAGS} -I${BUILD_SDKROOT}/usr/include" export CXXFLAGS="${CPPFLAGS}" @@ -118,7 +117,7 @@ fi CMAKE_XCOMPILE_ARGS="-DCMAKE_TOOLCHAIN_FILE=$IOSC_CMAKE_TOOLCHAIN -DCMAKE_INSTALL_PREFIX=$IOSC_BUILDROOT" CONFIGURE_XCOMPILE_ARGS="--prefix=$IOSC_BUILDROOT --host=$IOSC_HOST_TRIPLET" -make +make -j8 cp -f libkarere.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/libkarere.a cp -f rtcModule/base/libservices.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/libservices.a diff --git a/bindings/ios/3rdparty/build-openssl.sh b/bindings/ios/3rdparty/build-openssl.sh index 751f57a439..6b309b8938 100644 --- a/bindings/ios/3rdparty/build-openssl.sh +++ b/bindings/ios/3rdparty/build-openssl.sh @@ -88,9 +88,9 @@ do if [ "$1" == "verbose" ]; then - make + make -j8 else - make >> "${LOG}" 2>&1 + make -j8 >> "${LOG}" 2>&1 fi if [ $? != 0 ]; From 4f29770ee1d0bf4bc60aad3ce11c803ef2198201 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Mon, 3 Oct 2016 20:34:14 +0200 Subject: [PATCH 023/103] Ignore an useless library --- bindings/ios/3rdparty/build-megachat.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/bindings/ios/3rdparty/build-megachat.sh b/bindings/ios/3rdparty/build-megachat.sh index a9e7cadb47..ab6d255098 100644 --- a/bindings/ios/3rdparty/build-megachat.sh +++ b/bindings/ios/3rdparty/build-megachat.sh @@ -123,7 +123,6 @@ cp -f libkarere.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/libkar cp -f rtcModule/base/libservices.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/libservices.a cp -f rtcModule/base/strophe/libstrophe.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/libstrophe.a cp -f rtcModule/librtcmodule.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/librtcmodule.a -cp -f rtcModule/webrtc/libwebrtc_my.a ${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/libwebrtc_my.a popd @@ -135,7 +134,6 @@ lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libkarere. lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libservices.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libservices.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libservices.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libservices.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libservices.a -output ${CURRENTPATH}/lib/libservices.a lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libstrophe.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libstrophe.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libstrophe.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libstrophe.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libstrophe.a -output ${CURRENTPATH}/lib/libws.a lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/librtcmodule.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/librtcmodule.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/librtcmodule.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/librtcmodule.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/librtcmodule.a -output ${CURRENTPATH}/lib/librtcmodule.a -lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libwebrtc_my.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libwebrtc_my.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libwebrtc_my.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libwebrtc_my.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libwebrtc_my.a -output ${CURRENTPATH}/lib/libwebrtc_my.a mkdir -p include || true cp -f karere-native/src/megachatapi.h include/ From 206ff61edb25658a96fb8b9cc3053c8726c8d07a Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 4 Oct 2016 18:06:18 +0200 Subject: [PATCH 024/103] first attempt to ask for lock status and disconnect if timeout --- include/mega/http.h | 2 +- include/mega/megaclient.h | 7 ++++ src/megaclient.cpp | 79 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 84 insertions(+), 4 deletions(-) diff --git a/include/mega/http.h b/include/mega/http.h index 3a2bc2212a..f0270d5468 100644 --- a/include/mega/http.h +++ b/include/mega/http.h @@ -118,7 +118,7 @@ struct MEGA_API HttpIO : public EventTrigger dstime lastdata; // data receive timeout - static const int NETWORKTIMEOUT = 6000; + static const int NETWORKTIMEOUT = 1200; // set useragent (must be called exactly once) virtual void setuseragent(string*) = 0; diff --git a/include/mega/megaclient.h b/include/mega/megaclient.h index 306cbcb3a9..83a90e91a0 100644 --- a/include/mega/megaclient.h +++ b/include/mega/megaclient.h @@ -383,6 +383,7 @@ class MEGA_API MegaClient private: BackoffTimer btcs; BackoffTimer btbadhost; + BackoffTimer btworkinglock; // server-client command trigger connection HttpReq* pendingsc; @@ -391,6 +392,9 @@ class MEGA_API MegaClient // badhost report HttpReq* badhostcs; + // Working lock + HttpReq* workinglockcs; + // notify URL for new server-client commands string scnotifyurl; @@ -817,6 +821,9 @@ class MEGA_API MegaClient void setchunkfailed(string*); string badhosts; + string workinglockResponse; + bool doAskForWorkingLock = false; + // process object arrays by the API server int readnodes(JSON*, int, putsource_t = PUTNODES_APP, NewNode* = NULL, int = 0, int = 0); diff --git a/src/megaclient.cpp b/src/megaclient.cpp index ce92bad53a..be9a159394 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -717,6 +717,7 @@ void MegaClient::init() btsc.reset(); btpfa.reset(); btbadhost.reset(); + btworkinglock.reset(); jsonsc.pos = NULL; insca = false; @@ -815,6 +816,7 @@ MegaClient::MegaClient(MegaApp* a, Waiter* w, HttpIO* h, FileSystemAccess* f, Db reqtag = 0; badhostcs = NULL; + workinglockcs = NULL; scsn[sizeof scsn - 1] = 0; cachedscsn = UNDEF; @@ -842,6 +844,7 @@ MegaClient::~MegaClient() delete pendingcs; delete pendingsc; delete badhostcs; + delete workinglockcs; delete sctable; delete tctable; delete dbaccess; @@ -863,9 +866,34 @@ void MegaClient::exec() abortbackoff(overquotauntil <= Waiter::ds); } - if (EVER(httpio->lastdata) && !pendingcs && Waiter::ds >= httpio->lastdata + HttpIO::NETWORKTIMEOUT) + if (EVER(httpio->lastdata) && pendingcs && !fetchingnodes && Waiter::ds >= httpio->lastdata + HttpIO::NETWORKTIMEOUT) { - disconnect(); + if (!workinglockcs && !doAskForWorkingLock && workinglockResponse.empty() && btworkinglock.armed()) + { + LOG_err << "Timeout passed. Triggering petition for working lock ... "; + doAskForWorkingLock = true; + } + + if (workinglockResponse == "0") //not locked + { + LOG_fatal << "Disconnecting due to timeout (server idle)"; + disconnect(); + //TODO: send report + } + else if (workinglockResponse == "1") + { + LOG_warn << "Timeout not causing disconnect. The server reports writting lock (server is doing something for us. It's ok to wait') "; + //TODO: send report + } + else if (!workinglockResponse.empty()) + { + LOG_err << "Unexpected working lock response: " << workinglockResponse; + } + } + + if (!workinglockResponse.empty()) + { + workinglockResponse.clear(); } // successful network operation with a failed transfer chunk: increment error count @@ -1366,6 +1394,27 @@ void MegaClient::exec() } } + if (workinglockcs) + { + if (workinglockcs->status == REQ_SUCCESS) + { + LOG_debug << "Successful requested working lock. Result=" << workinglockcs->in; + btworkinglock.reset(); + btworkinglock.backoff(600); //leave the api be for a while + workinglockResponse = workinglockcs->in; + delete workinglockcs; + workinglockcs = NULL; + } + else if(workinglockcs->status == REQ_FAILURE) + { + LOG_warn << "Failed requested working lock. Retrying..."; + btworkinglock.backoff(600); //leave the api be for a while + doAskForWorkingLock = true; + delete workinglockcs; + workinglockcs = NULL; + } + } + // fill transfer slots from the queue dispatchmore(PUT); dispatchmore(GET); @@ -1879,6 +1928,20 @@ void MegaClient::exec() badhostcs->post(this); badhosts.clear(); } + + if (!workinglockcs && doAskForWorkingLock && btworkinglock.armed()) + { + LOG_debug << "Sending workinglock petition: " << workinglockResponse; + workinglockcs = new HttpReq(); + workinglockcs->posturl = APIURL; + workinglockcs->posturl.append("cs?"); + workinglockcs->posturl.append(auth); + workinglockcs->posturl.append("&wlt=1"); + workinglockcs->type = REQ_JSON; + workinglockcs->post(this); + workinglockResponse.clear(); + doAskForWorkingLock = false; + } } while (httpio->doio() || execdirectreads() || (!pendingcs && reqs.cmdspending() && btcs.armed()) || looprequested); } @@ -1947,9 +2010,14 @@ int MegaClient::preparewait() // retry failed badhost requests if (!badhostcs) { - btbadhost.update(&nds); + btbadhost.update(&nds); //TODO: this can produce segfault if ocurred after reset() } +// if (!workinglockcs) +// { +// btworkinglock.update(&nds); +// } + // retry failed file attribute puts if (curfa == newfa.end()) { @@ -2104,6 +2172,11 @@ bool MegaClient::abortbackoff(bool includexfers) r = true; } + if (btworkinglock.arm()) + { + r = true; + } + if (!pendingsc && btsc.arm()) { r = true; From 6a675051ce3da33759540de6a4e40f92ccb4c7fd Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Wed, 5 Oct 2016 18:40:39 +0200 Subject: [PATCH 025/103] Add the build of WebRTC to iOS build scripts --- bindings/ios/3rdparty/build-all.sh | 13 ++--- bindings/ios/3rdparty/build-webrtc.sh | 70 +++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 bindings/ios/3rdparty/build-webrtc.sh diff --git a/bindings/ios/3rdparty/build-all.sh b/bindings/ios/3rdparty/build-all.sh index 379cfc22d8..3dea514e9f 100644 --- a/bindings/ios/3rdparty/build-all.sh +++ b/bindings/ios/3rdparty/build-all.sh @@ -2,6 +2,7 @@ set -e +# MEGA SDK deps sh build-cryptopp.sh sh build-openssl.sh sh build-cares.sh @@ -9,13 +10,13 @@ sh build-curl.sh sh build-libuv.sh sh build-libsodium.sh -if [ "$1" == "--enable-chat"]; then - sh build-expat.sh - sh build-libevent2.sh - sh build-libws.sh - sh build-megachat.sh -fi +# MEGAchat deps +sh build-expat.sh +sh build-libevent2.sh +sh build-libws.sh +sh build-webrtc.sh +sh build-megachat.sh echo "Done." diff --git a/bindings/ios/3rdparty/build-webrtc.sh b/bindings/ios/3rdparty/build-webrtc.sh new file mode 100644 index 0000000000..465a789869 --- /dev/null +++ b/bindings/ios/3rdparty/build-webrtc.sh @@ -0,0 +1,70 @@ +#!/bin/sh + +MEGACHAT_VERSION="GIT" +SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version` + +############################################## +CURRENTPATH=`pwd` +OPENSSL_PREFIX="${CURRENTPATH}" +ARCHS="ia32 x64 arm arm64" +DEVELOPER=`xcode-select -print-path` + +if [ ! -d "$DEVELOPER" ]; then + echo "xcode path is not set correctly $DEVELOPER does not exist (most likely because of xcode > 4.3)" + echo "run" + echo "sudo xcode-select -switch " + echo "for default installation:" + echo "sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer" + exit 1 +fi + +case $DEVELOPER in + *\ * ) + echo "Your Xcode path contains whitespaces, which is not supported." + exit 1 + ;; +esac + +case $CURRENTPATH in + *\ * ) + echo "Your path contains whitespaces, which is not supported by 'make install'." + exit 1 + ;; +esac + +set -e + +if [ ! -d "karere-native" ] +then +git clone --recursive -b feature/mega-chat-api https://code.developers.mega.co.nz/messenger/karere-native +fi + +export WEBRTC_DEPS_INCLUDE=${CURRENTPATH}/include +export WEBRTC_DEPS_LIB=${CURRENTPATH}/lib + +for ARCH in ${ARCHS} +do + +echo "BUILDING FOR ${ARCH}" +rm -rf karere-native/webrtc-build/ios/src karere-native/webrtc-build/ios/depot_tools karere-native/webrtc-build/ios/.gclient + +karere-native/webrtc-build/build-webrtc.sh ${CURRENTPATH}/karere-native/webrtc-build/ios --platform ios --arch ${ARCH} --batch + +mkdir -p "${CURRENTPATH}/bin/${ARCH}" +if [[ ${ARCH} == arm* ]]; then + libtool -static -o ${CURRENTPATH}/bin/${ARCH}/libWebRTC.a ${CURRENTPATH}/karere-native/webrtc-build/ios/src/out/Release-iphoneos/*.a +else + libtool -static -o ${CURRENTPATH}/bin/${ARCH}/libWebRTC.a ${CURRENTPATH}/karere-native/webrtc-build/ios/src/out/Release-iphonesimulator/*.a +fi + +done + + +mkdir lib || true +lipo -create ${CURRENTPATH}/bin/ia32/libWebRTC.a ${CURRENTPATH}/bin/x64/libWebRTC.a ${CURRENTPATH}/bin/arm/libWebRTC.a ${CURRENTPATH}/bin/arm64/libWebRTC.a -output ${CURRENTPATH}/lib/libWebRTC.a + +mkdir -p include || true +ln -s ../karere-native/webrtc-build/ios/src/ include/webrtc +rm -rf bin +echo "Done." + From addd05a3a82338519e20f4f33c836c5bed0b0ca0 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Wed, 5 Oct 2016 18:44:01 +0200 Subject: [PATCH 026/103] Fix the link to WebRTC headers --- bindings/ios/3rdparty/build-webrtc.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/ios/3rdparty/build-webrtc.sh b/bindings/ios/3rdparty/build-webrtc.sh index 465a789869..23115749a5 100644 --- a/bindings/ios/3rdparty/build-webrtc.sh +++ b/bindings/ios/3rdparty/build-webrtc.sh @@ -64,7 +64,7 @@ mkdir lib || true lipo -create ${CURRENTPATH}/bin/ia32/libWebRTC.a ${CURRENTPATH}/bin/x64/libWebRTC.a ${CURRENTPATH}/bin/arm/libWebRTC.a ${CURRENTPATH}/bin/arm64/libWebRTC.a -output ${CURRENTPATH}/lib/libWebRTC.a mkdir -p include || true -ln -s ../karere-native/webrtc-build/ios/src/ include/webrtc +ln -sf ../karere-native/webrtc-build/ios/src/webrtc include/webrtc rm -rf bin echo "Done." From 01e7c9352da6a2eeb6e8be3ccf103be3fa8df949 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Thu, 6 Oct 2016 18:11:20 +0200 Subject: [PATCH 027/103] Fix bugs in the build script for MEGAchat --- bindings/ios/3rdparty/build-megachat.sh | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/bindings/ios/3rdparty/build-megachat.sh b/bindings/ios/3rdparty/build-megachat.sh index ab6d255098..e38f2199d9 100644 --- a/bindings/ios/3rdparty/build-megachat.sh +++ b/bindings/ios/3rdparty/build-megachat.sh @@ -39,19 +39,7 @@ then git clone --recursive -b feature/mega-chat-api https://code.developers.mega.co.nz/messenger/karere-native fi -if [ ! -d "include/webrtc" ] -then - WEBRTC_REVISION=9ac4df1ba66d39c3621cfb2e8ed08ae39658b793 - mkdir -p webrtc - pushd webrtc - git init - git remote add origin https://chromium.googlesource.com/external/webrtc.git - git fetch --depth=1 origin ${WEBRTC_REVISION} - git checkout ${WEBRTC_REVISION} - popd - ln -s ../webrtc/webrtc include/webrtc - ln -s ../../mega include/mega -fi +ln -sf ../../mega include/mega for ARCH in ${ARCHS} do @@ -132,7 +120,7 @@ done mkdir lib || true lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libkarere.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libkarere.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libkarere.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libkarere.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libkarere.a -output ${CURRENTPATH}/lib/libkarere.a lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libservices.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libservices.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libservices.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libservices.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libservices.a -output ${CURRENTPATH}/lib/libservices.a -lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libstrophe.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libstrophe.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libstrophe.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libstrophe.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libstrophe.a -output ${CURRENTPATH}/lib/libws.a +lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/libstrophe.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/libstrophe.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/libstrophe.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/libstrophe.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/libstrophe.a -output ${CURRENTPATH}/lib/libstrophe.a lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/librtcmodule.a ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/librtcmodule.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/librtcmodule.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/librtcmodule.a ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/librtcmodule.a -output ${CURRENTPATH}/lib/librtcmodule.a mkdir -p include || true From 5bae1a4ceb20015a30ad9d5f22d0dd5c06ca4da7 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Thu, 6 Oct 2016 18:13:11 +0200 Subject: [PATCH 028/103] Allow the intermediate layer of MEGAchat to access the internal MegaApi pointer --- bindings/ios/MEGASdk.mm | 1 - bindings/ios/Private/MegaSDK+init.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/ios/MEGASdk.mm b/bindings/ios/MEGASdk.mm index bda4df4208..b095f9d0bf 100644 --- a/bindings/ios/MEGASdk.mm +++ b/bindings/ios/MEGASdk.mm @@ -58,7 +58,6 @@ - (MegaGlobalListener *)createDelegateMEGAGlobalListener:(id - (MegaListener *)createDelegateMEGAListener:(id)delegate; @property MegaApi *megaApi; -- (MegaApi *)getCPtr; @end diff --git a/bindings/ios/Private/MegaSDK+init.h b/bindings/ios/Private/MegaSDK+init.h index e719fe615c..db6ce1c65d 100644 --- a/bindings/ios/Private/MegaSDK+init.h +++ b/bindings/ios/Private/MegaSDK+init.h @@ -26,5 +26,6 @@ - (void)freeRequestListener:(DelegateMEGARequestListener *)delegate; - (void)freeTransferListener:(DelegateMEGATransferListener *)delegate; +- (mega::MegaApi *)getCPtr; @end From d15aaff9b02af97a4a71f450eb9333e2c4e96ba0 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Thu, 6 Oct 2016 18:16:25 +0200 Subject: [PATCH 029/103] Ignore XCode files --- bindings/ios/.gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 bindings/ios/.gitignore diff --git a/bindings/ios/.gitignore b/bindings/ios/.gitignore new file mode 100644 index 0000000000..a0c72a51a7 --- /dev/null +++ b/bindings/ios/.gitignore @@ -0,0 +1,2 @@ +/MEGASDK.xcodeproj/xcuserdata/MEGA.xcuserdatad/xcschemes/MEGASDK.xcscheme +/MEGASDK.xcodeproj/xcuserdata/MEGA.xcuserdatad/xcschemes/xcschememanagement.plist From 6f651f6d0462aa14bae663f707d682d0d21f86b3 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Fri, 7 Oct 2016 00:37:04 +0200 Subject: [PATCH 030/103] Add debug info for MEGAchat libraries --- bindings/ios/3rdparty/build-megachat.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/ios/3rdparty/build-megachat.sh b/bindings/ios/3rdparty/build-megachat.sh index e38f2199d9..352d0be9ad 100644 --- a/bindings/ios/3rdparty/build-megachat.sh +++ b/bindings/ios/3rdparty/build-megachat.sh @@ -73,7 +73,7 @@ mkdir -p "${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" # Build export LDFLAGS="-Os -arch ${ARCH} -Wl,-dead_strip -miphoneos-version-min=7.0 -L${BUILD_SDKROOT}/usr/lib" -export CFLAGS="-Os -arch ${ARCH} -pipe -no-cpp-precomp -isysroot ${BUILD_SDKROOT} -miphoneos-version-min=7.0 -D_DARWIN_C_SOURCE" +export CFLAGS="-Os -arch ${ARCH} -pipe -no-cpp-precomp -isysroot ${BUILD_SDKROOT} -miphoneos-version-min=7.0 -D_DARWIN_C_SOURCE -g3" export CPPFLAGS="${CFLAGS} -I${BUILD_SDKROOT}/usr/include" export CXXFLAGS="${CPPFLAGS}" From e785a6cda3d7878d6873d8a7d9895de698446c37 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Fri, 7 Oct 2016 02:11:29 +0200 Subject: [PATCH 031/103] Copy WebRTC headers instead of linking them to prevent problems with XCode --- bindings/ios/3rdparty/build-webrtc.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bindings/ios/3rdparty/build-webrtc.sh b/bindings/ios/3rdparty/build-webrtc.sh index 23115749a5..47678c5e7f 100644 --- a/bindings/ios/3rdparty/build-webrtc.sh +++ b/bindings/ios/3rdparty/build-webrtc.sh @@ -64,7 +64,14 @@ mkdir lib || true lipo -create ${CURRENTPATH}/bin/ia32/libWebRTC.a ${CURRENTPATH}/bin/x64/libWebRTC.a ${CURRENTPATH}/bin/arm/libWebRTC.a ${CURRENTPATH}/bin/arm64/libWebRTC.a -output ${CURRENTPATH}/lib/libWebRTC.a mkdir -p include || true -ln -sf ../karere-native/webrtc-build/ios/src/webrtc include/webrtc +cp -R karere-native/webrtc-build/ios/src/webrtc include/ +find include/webrtc -iname "*.c*" -exec rm {} \; +find include/webrtc -iname "*.gyp*" -exec rm {} \; +find include/webrtc -iname "*.gn" -exec rm {} \; +find include/webrtc -iname "*.py" -exec rm {} \; +find include/webrtc -iname "*.mm" -exec rm {} \; + +rm -rf karere-native/webrtc-build/ios/src karere-native/webrtc-build/ios/depot_tools karere-native/webrtc-build/ios/.gclient rm -rf bin echo "Done." From a0249d2b6c53d526cad31b918741e2ad660b6f00 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Tue, 11 Oct 2016 13:38:20 +0200 Subject: [PATCH 032/103] Allow to replace a share key --- src/megaclient.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/megaclient.cpp b/src/megaclient.cpp index 31c2076858..61dba2172d 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -146,7 +146,7 @@ void MegaClient::mergenewshare(NewShare *s, bool notify) if ((n = nodebyhandle(s->h))) { - if (!n->sharekey && s->have_key) + if (s->have_key && (!n->sharekey || memcmp(s->key, n->sharekey->key, SymmCipher::KEYLENGTH))) { // setting an outbound sharekey requires node authentication // unless coming from a trusted source (the local cache) @@ -175,6 +175,14 @@ void MegaClient::mergenewshare(NewShare *s, bool notify) if (auth) { + if (n->sharekey) + { + int creqtag = reqtag; + reqtag = 0; + sendevent(99424,"Replacing share key"); + reqtag = creqtag; + delete n->sharekey; + } n->sharekey = new SymmCipher(s->key); skreceived = true; } From 6966d2e174cba8c49df55f7c62fbd8ddde2c6e90 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Tue, 11 Oct 2016 14:29:59 +0200 Subject: [PATCH 033/103] Fix compilation on Windows --- src/megaapi_impl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 0b063d524f..8fa7372b1e 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -14201,6 +14201,7 @@ bool MegaFolderProcTree::processMegaNode(MegaNode *n) nc++; } + return true; } MegaFolderUploadController::MegaFolderUploadController(MegaApiImpl *megaApi, MegaTransferPrivate *transfer) From 673fe06eceb160fb0d1c703dae151029c73ff9f2 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Tue, 11 Oct 2016 14:30:40 +0200 Subject: [PATCH 034/103] Refactoring, formatting, minor fixes --- include/megaapi_impl.h | 4 +- src/megaapi_impl.cpp | 111 +++++++++++++++++++++++------------------ 2 files changed, 65 insertions(+), 50 deletions(-) diff --git a/include/megaapi_impl.h b/include/megaapi_impl.h index 9e245fc511..6620786978 100644 --- a/include/megaapi_impl.h +++ b/include/megaapi_impl.h @@ -145,13 +145,13 @@ class ExternalLogger : public Logger }; class MegaTransferPrivate; -class MegaFolderProcTree : public MegaTreeProcessor +class MegaTreeProcCopy : public MegaTreeProcessor { public: NewNode* nn; unsigned nc; - MegaFolderProcTree(MegaClient *client); + MegaTreeProcCopy(MegaClient *client); virtual bool processMegaNode(MegaNode* node); void allocnodes(void); diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 8fa7372b1e..0b6acd52ac 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -119,8 +119,6 @@ MegaNodePrivate::MegaNodePrivate(MegaNode *node) this->name = MegaApi::strdup(node->getName()); this->fingerprint = MegaApi::strdup(node->getFingerprint()); this->customAttrs = NULL; - this->children = node->getChildren(); - if (this->children) this->children = this->children->copy(); this->duration = node->getDuration(); this->latitude = node->getLatitude(); this->longitude = node->getLongitude(); @@ -146,6 +144,12 @@ MegaNodePrivate::MegaNodePrivate(MegaNode *node) this->foreign = node->isForeign(); this->sharekey = NULL; + this->children = node->getChildren(); + if (this->children) + { + this->children = this->children->copy(); + } + if (node->isExported()) { this->plink = new PublicLink(node->getPublicHandle(), node->getExpirationTime(), node->isTakenDown()); @@ -6479,13 +6483,20 @@ int MegaApiImpl::getAccess(MegaNode* megaNode) bool MegaApiImpl::processMegaTree(MegaNode* n, MegaTreeProcessor* processor, bool recursive) { - if(!n) return true; - if(!processor) return false; + if (!n) + { + return true; + } + + if (!processor) + { + return false; + } sdkMutex.lock(); - Node *node = client->nodebyhandle(n->getHandle()); - if(!node) - { + Node *node = client->nodebyhandle(n->getHandle()); + if (!node) + { if (n->getType() != FILENODE) { MegaNodeList *nList = n->getChildren(); @@ -6498,35 +6509,35 @@ bool MegaApiImpl::processMegaTree(MegaNode* n, MegaTreeProcessor* processor, boo bool result = processor->processMegaNode(n); sdkMutex.unlock(); return result; - } + } - if (node->type != FILENODE) - { - for (node_list::iterator it = node->children.begin(); it != node->children.end(); ) - { - MegaNode *megaNode = MegaNodePrivate::fromNode(*it++); - if(recursive) - { - if(!processMegaTree(megaNode,processor)) - { - delete megaNode; + if (node->type != FILENODE) + { + for (node_list::iterator it = node->children.begin(); it != node->children.end(); ) + { + MegaNode *megaNode = MegaNodePrivate::fromNode(*it++); + if(recursive) + { + if(!processMegaTree(megaNode,processor)) + { + delete megaNode; sdkMutex.unlock(); - return 0; - } - } - else - { - if(!processor->processMegaNode(megaNode)) - { - delete megaNode; + return 0; + } + } + else + { + if(!processor->processMegaNode(megaNode)) + { + delete megaNode; sdkMutex.unlock(); - return 0; - } - } - delete megaNode; - } - } - bool result = processor->processMegaNode(n); + return 0; + } + } + delete megaNode; + } + } + bool result = processor->processMegaNode(n); sdkMutex.unlock(); return result; @@ -11372,27 +11383,30 @@ void MegaApiImpl::sendPendingRequests() if (publicNode->getType() != FILENODE) { unsigned nc; - MegaFolderProcTree *ptree = new MegaFolderProcTree(client); - this->processMegaTree(publicNode, ptree); - ptree->allocnodes(); - nc = ptree->nc; + MegaTreeProcCopy tc(client); + + processMegaTree(publicNode, &tc); + tc.allocnodes(); + nc = tc.nc; + // build new nodes array - this->processMegaTree(publicNode, ptree); + processMegaTree(publicNode, &tc); if (!nc) { e = API_EARGS; break; } + tc.nn->parenthandle = UNDEF; + if (target) { - client->putnodes(target->nodehandle, ptree->nn, nc); + client->putnodes(target->nodehandle, tc.nn, nc); } else { - client->putnodes(email, ptree->nn, nc); + client->putnodes(email, tc.nn, nc); } - delete ptree; } else { @@ -14124,21 +14138,21 @@ FileInputStream::~FileInputStream() } -MegaFolderProcTree::MegaFolderProcTree(MegaClient *client) +MegaTreeProcCopy::MegaTreeProcCopy(MegaClient *client) { nn = NULL; nc = 0; this->client = client; } -void MegaFolderProcTree::allocnodes() +void MegaTreeProcCopy::allocnodes() { if (nc) { nn = new NewNode[nc]; } } -bool MegaFolderProcTree::processMegaNode(MegaNode *n) +bool MegaTreeProcCopy::processMegaNode(MegaNode *n) { if (nn) { @@ -14455,7 +14469,7 @@ MegaFolderDownloadController::MegaFolderDownloadController(MegaApiImpl *megaApi, this->listener = transfer->getListener(); this->recursive = 0; this->pendingTransfers = 0; - this->tag = transfer->getTag(); + this->tag = transfer->getTag(); } void MegaFolderDownloadController::start(MegaNode *node) @@ -14546,7 +14560,7 @@ void MegaFolderDownloadController::downloadFolderNode(MegaNode *node, string *pa localpath.append(client->fsaccess->localseparator); MegaNodeList *children = NULL; - bool childrenneedsdelete = false; + bool deleteChildren = false; if (node->isForeign()) { children = node->getChildren(); @@ -14554,7 +14568,7 @@ void MegaFolderDownloadController::downloadFolderNode(MegaNode *node, string *pa else { children = megaApi->getChildren(node); - childrenneedsdelete=true; + deleteChildren = true; } if (!children) @@ -14630,7 +14644,8 @@ void MegaFolderDownloadController::downloadFolderNode(MegaNode *node, string *pa recursive--; checkCompletion(); - if (childrenneedsdelete){ + if (deleteChildren) + { delete children; } } From 178ab678745d42d63a4a72b5d86249f7b49fc46c Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Thu, 13 Oct 2016 18:10:22 +0200 Subject: [PATCH 035/103] Allow to iterate authorized nodes non recursively Allow to cancel the processing of authorized nodes --- include/megaapi_impl.h | 1 - src/megaapi_impl.cpp | 22 +++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/megaapi_impl.h b/include/megaapi_impl.h index 6620786978..821e947eb7 100644 --- a/include/megaapi_impl.h +++ b/include/megaapi_impl.h @@ -311,7 +311,6 @@ class MegaNodePrivate : public MegaNode, public Cachable int duration; double latitude; double longitude; - MegaNodeList *children; #ifdef ENABLE_SYNC diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 0b6acd52ac..77c8fb9018 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -6503,7 +6503,20 @@ bool MegaApiImpl::processMegaTree(MegaNode* n, MegaTreeProcessor* processor, boo for (int i = 0; i < nList->size(); i++) { MegaNode *child = nList->get(i); - processMegaTree(child, processor); + if (recursive) + { + processMegaTree(child, processor); + sdkMutex.unlock(); + return 0; + } + else + { + if (!processor->processMegaNode(child)) + { + sdkMutex.unlock(); + return 0; + } + } } } bool result = processor->processMegaNode(n); @@ -6516,9 +6529,9 @@ bool MegaApiImpl::processMegaTree(MegaNode* n, MegaTreeProcessor* processor, boo for (node_list::iterator it = node->children.begin(); it != node->children.end(); ) { MegaNode *megaNode = MegaNodePrivate::fromNode(*it++); - if(recursive) + if (recursive) { - if(!processMegaTree(megaNode,processor)) + if (!processMegaTree(megaNode,processor)) { delete megaNode; sdkMutex.unlock(); @@ -6527,7 +6540,7 @@ bool MegaApiImpl::processMegaTree(MegaNode* n, MegaTreeProcessor* processor, boo } else { - if(!processor->processMegaNode(megaNode)) + if (!processor->processMegaNode(megaNode)) { delete megaNode; sdkMutex.unlock(); @@ -6538,7 +6551,6 @@ bool MegaApiImpl::processMegaTree(MegaNode* n, MegaTreeProcessor* processor, boo } } bool result = processor->processMegaNode(n); - sdkMutex.unlock(); return result; } From ae14497fc874aa0d6a9b3ea5afe2c5840dfff81e Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Thu, 13 Oct 2016 18:12:31 +0200 Subject: [PATCH 036/103] Fixed a crash iterating authorized nodes without children --- src/megaapi_impl.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 77c8fb9018..120c36fdda 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -6500,22 +6500,25 @@ bool MegaApiImpl::processMegaTree(MegaNode* n, MegaTreeProcessor* processor, boo if (n->getType() != FILENODE) { MegaNodeList *nList = n->getChildren(); - for (int i = 0; i < nList->size(); i++) + if (nList) { - MegaNode *child = nList->get(i); - if (recursive) + for (int i = 0; i < nList->size(); i++) { - processMegaTree(child, processor); - sdkMutex.unlock(); - return 0; - } - else - { - if (!processor->processMegaNode(child)) + MegaNode *child = nList->get(i); + if (recursive) { + processMegaTree(child, processor); sdkMutex.unlock(); return 0; } + else + { + if (!processor->processMegaNode(child)) + { + sdkMutex.unlock(); + return 0; + } + } } } } From ae28f41c5f3e91008b5e10d381b3b57d665c7e33 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Thu, 13 Oct 2016 18:24:32 +0200 Subject: [PATCH 037/103] Force the iteration of public or foreign MegaNodes --- src/megaapi_impl.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 120c36fdda..9b0f5f6660 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -6494,7 +6494,13 @@ bool MegaApiImpl::processMegaTree(MegaNode* n, MegaTreeProcessor* processor, boo } sdkMutex.lock(); - Node *node = client->nodebyhandle(n->getHandle()); + Node *node = NULL; + + if (!n->isForeign() && !n->isPublic()) + { + node = client->nodebyhandle(n->getHandle()); + } + if (!node) { if (n->getType() != FILENODE) From 67c8ce4b6a205626f9d5cfea39315e73f5247d6b Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Fri, 14 Oct 2016 12:29:55 +0200 Subject: [PATCH 038/103] Update docs and make authorizeNode work according to it --- include/megaapi.h | 4 +--- src/megaapi_impl.cpp | 9 +++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/megaapi.h b/include/megaapi.h index 27fffce919..a5c7b73126 100644 --- a/include/megaapi.h +++ b/include/megaapi.h @@ -7507,8 +7507,6 @@ class MegaApi /** * @brief Returns a MegaNode that can be downloaded with any instance of MegaApi * - * This function only allows to authorize file nodes. - * * You can use MegaApi::startDownload with the resulting node with any instance * of MegaApi, even if it's logged into another account, a public folder, or not * logged in. @@ -7528,7 +7526,7 @@ class MegaApi * You take the ownership of the returned value. * * @param node MegaNode to authorize - * @return Authorized node, or NULL if the node can't be authorized or is not a file + * @return Authorized node, or NULL if the node can't be authorized */ MegaNode *authorizeNode(MegaNode *node); diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 9b0f5f6660..1252a1bc96 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -6630,11 +6630,16 @@ MegaNode *MegaApiImpl::createForeignFolderNode(MegaHandle handle, const char *na MegaNode *MegaApiImpl::authorizeNode(MegaNode *node) { - if (!node || node->isPublic() || node->isForeign()) + if (!node) { return NULL; } + if (node->isPublic() || node->isForeign()) + { + return node->copy(); + } + MegaNodePrivate *result = NULL; sdkMutex.lock(); Node *n = client->nodebyhandle(node->getHandle()); @@ -6661,7 +6666,7 @@ void MegaApiImpl::authorizeMegaNodePrivate(MegaNodePrivate *node) } else { - h = MegaApi::handleToBase64(client->getrootpublicfolder()); + h = MegaApiImpl::handleToBase64(client->getrootpublicfolder()); node->setPublicAuth(h); } delete [] h; From eae971e15c2f568a15b0520730a3cba958a3ee3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Hern=C3=A1ndez?= Date: Fri, 14 Oct 2016 12:46:06 +0200 Subject: [PATCH 039/103] Add initialization to mutex constructor --- contrib/QtCreator/megacli.files | 2 ++ include/mega/thread/cppthread.h | 1 + include/mega/thread/libuvthread.h | 1 + include/mega/thread/posixthread.h | 1 + include/mega/thread/qtthread.h | 1 + include/mega/thread/win32thread.h | 1 + src/thread/cppthread.cpp | 8 ++++++++ src/thread/libuvthread.cpp | 8 ++++++++ src/thread/posixthread.cpp | 8 ++++++++ src/thread/qtthread.cpp | 8 ++++++++ src/thread/win32thread.cpp | 7 +++++++ 11 files changed, 46 insertions(+) diff --git a/contrib/QtCreator/megacli.files b/contrib/QtCreator/megacli.files index 75b74c7dc8..d0911b7e4b 100644 --- a/contrib/QtCreator/megacli.files +++ b/contrib/QtCreator/megacli.files @@ -139,3 +139,5 @@ ../../tests/sdktests.cpp ../../tests/sdk_test.h ../../tests/crypto_test.cpp +../../src/thread/libuvthread.cpp +../../include/mega/thread/libuvthread.h diff --git a/include/mega/thread/cppthread.h b/include/mega/thread/cppthread.h index 1fbda684fc..6e43eaaebc 100644 --- a/include/mega/thread/cppthread.h +++ b/include/mega/thread/cppthread.h @@ -51,6 +51,7 @@ class CppMutex : public Mutex { public: CppMutex(); + CppMutex(bool recursive); virtual void init(bool recursive); virtual void lock(); virtual void unlock(); diff --git a/include/mega/thread/libuvthread.h b/include/mega/thread/libuvthread.h index 77030d59f2..b2be9e003a 100644 --- a/include/mega/thread/libuvthread.h +++ b/include/mega/thread/libuvthread.h @@ -50,6 +50,7 @@ class LibUVMutex : public Mutex { public: LibUVMutex(); + LibUVMutex(bool recursive); virtual void init(bool recursive); virtual void lock(); virtual void unlock(); diff --git a/include/mega/thread/posixthread.h b/include/mega/thread/posixthread.h index 1bc84f9b14..9b8bdead71 100644 --- a/include/mega/thread/posixthread.h +++ b/include/mega/thread/posixthread.h @@ -47,6 +47,7 @@ class PosixMutex : public Mutex { public: PosixMutex(); + PosixMutex(bool recursive); virtual void init(bool recursive); virtual void lock(); virtual void unlock(); diff --git a/include/mega/thread/qtthread.h b/include/mega/thread/qtthread.h index 13c782ae4d..7f4bf0ebff 100644 --- a/include/mega/thread/qtthread.h +++ b/include/mega/thread/qtthread.h @@ -51,6 +51,7 @@ class QtMutex : public Mutex { public: QtMutex(); + QtMutex(bool recursive); virtual void init(bool recursive); virtual void lock(); virtual void unlock(); diff --git a/include/mega/thread/win32thread.h b/include/mega/thread/win32thread.h index 0abf8823fc..76fc34cf38 100644 --- a/include/mega/thread/win32thread.h +++ b/include/mega/thread/win32thread.h @@ -49,6 +49,7 @@ class Win32Mutex : public Mutex { public: Win32Mutex(); + Win32Mutex(bool recursive); virtual void init(bool recursive); virtual void lock(); virtual void unlock(); diff --git a/src/thread/cppthread.cpp b/src/thread/cppthread.cpp index db64508f33..cac56600af 100644 --- a/src/thread/cppthread.cpp +++ b/src/thread/cppthread.cpp @@ -57,6 +57,14 @@ CppMutex::CppMutex() rmutex = NULL; } +CppMutex::CppMutex(bool recursive) +{ + mutex = NULL; + rmutex = NULL; + + init(recursive); +} + void CppMutex::init(bool recursive = true) { if (mutex || rmutex) diff --git a/src/thread/libuvthread.cpp b/src/thread/libuvthread.cpp index 4369b7074a..5813b43a71 100644 --- a/src/thread/libuvthread.cpp +++ b/src/thread/libuvthread.cpp @@ -64,6 +64,14 @@ LibUVMutex::LibUVMutex() count = NULL; } +LibUVMutex::LibUVMutex(bool recursive) +{ + mutex = NULL; + count = NULL; + + init(recursive); +} + void LibUVMutex::init(bool recursive) { mutex = new uv_mutex_t; diff --git a/src/thread/posixthread.cpp b/src/thread/posixthread.cpp index ae2b7ab3ca..45a887523d 100644 --- a/src/thread/posixthread.cpp +++ b/src/thread/posixthread.cpp @@ -53,6 +53,14 @@ PosixMutex::PosixMutex() attr = NULL; } +PosixMutex::PosixMutex(bool recursive) +{ + mutex = NULL; + attr = NULL; + + init(recursive); +} + void PosixMutex::init(bool recursive) { if (recursive) diff --git a/src/thread/qtthread.cpp b/src/thread/qtthread.cpp index 4422544dad..7e130104df 100644 --- a/src/thread/qtthread.cpp +++ b/src/thread/qtthread.cpp @@ -62,6 +62,14 @@ QtMutex::QtMutex() mutex = NULL; } +QtMutex::QtMutex(bool recursive) +{ + mutex = NULL; + + init(recursive); +} + + void QtMutex::init(bool recursive) { if(recursive) diff --git a/src/thread/win32thread.cpp b/src/thread/win32thread.cpp index 24d716f95d..49a1dee90f 100644 --- a/src/thread/win32thread.cpp +++ b/src/thread/win32thread.cpp @@ -60,6 +60,13 @@ Win32Mutex::Win32Mutex() InitializeCriticalSection(&mutex); } +Win32Mutex::Win32Mutex(bool recursive) +{ + InitializeCriticalSection(&mutex); + + init(recursive); // just for correctness +} + void Win32Mutex::init(bool recursive) { From 64750c8828f509ef2eaa51e27de85baafad6a7ca Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Fri, 14 Oct 2016 18:11:46 +0200 Subject: [PATCH 040/103] Unify the management of own and foreign nodes --- include/megaapi.h | 3 - src/megaapi_impl.cpp | 186 +++++++++++++++++-------------------------- 2 files changed, 72 insertions(+), 117 deletions(-) diff --git a/include/megaapi.h b/include/megaapi.h index a5c7b73126..6fea0bba47 100644 --- a/include/megaapi.h +++ b/include/megaapi.h @@ -4891,9 +4891,6 @@ class MegaApi * @param newParent Parent for the new node * @param newName Name for the new node * - * This parameter is only used if the original node is a file and it isn't a public node, - * otherwise, it's ignored. - * * @param listener MegaRequestListener to track this request */ void copyNode(MegaNode* node, MegaNode *newParent, const char* newName, MegaRequestListener *listener = NULL); diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 1252a1bc96..39aeedc4c6 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -11014,7 +11014,7 @@ void MegaApiImpl::sendPendingTransfers() break; } - if (!transfer->isStreamingTransfer() && ((node && node->type != FILENODE) || (publicNode && publicNode->getType() == FOLDERNODE)) ) + if (!transfer->isStreamingTransfer() && ((node && node->type != FILENODE) || (publicNode && publicNode->getType() != FILENODE)) ) { // Folder download transferMap[nextTag] = transfer; @@ -11406,96 +11406,48 @@ void MegaApiImpl::sendPendingRequests() if (!node) { - if (publicNode->getType() != FILENODE) - { - unsigned nc; - MegaTreeProcCopy tc(client); - - processMegaTree(publicNode, &tc); - tc.allocnodes(); - nc = tc.nc; - - // build new nodes array - processMegaTree(publicNode, &tc); - if (!nc) - { - e = API_EARGS; - break; - } + unsigned nc; + MegaTreeProcCopy tc(client); - tc.nn->parenthandle = UNDEF; + processMegaTree(publicNode, &tc); + tc.allocnodes(); + nc = tc.nc; - if (target) - { - client->putnodes(target->nodehandle, tc.nn, nc); - } - else - { - client->putnodes(email, tc.nn, nc); - } - } - else + // build new nodes array + processMegaTree(publicNode, &tc); + if (!nc) { - NewNode *newnode = new NewNode[1]; - newnode->nodekey.assign(publicNode->getNodeKey()->data(), publicNode->getNodeKey()->size()); - newnode->attrstring = new string; - - if (publicNode->isPublic()) - { - newnode->attrstring->assign(publicNode->getAttrString()->data(), publicNode->getAttrString()->size()); - newnode->source = NEW_PUBLIC; - } - else - { - SymmCipher key; - AttrMap attrs; - - key.setkey((const byte*)publicNode->getNodeKey()->data(), publicNode->getType()); - string sname = publicNode->getName(); - fsAccess->normalize(&sname); - attrs.map['n'] = sname; + e = API_EARGS; + break; + } - const char *fingerprint = publicNode->getFingerprint(); - if (fingerprint && fingerprint[0]) - { - m_off_t size = 0; - unsigned int fsize = strlen(fingerprint); - unsigned int ssize = fingerprint[0] - 'A'; - if (!(ssize > (sizeof(size) * 4 / 3 + 4) || fsize <= (ssize + 1))) - { - int len = sizeof(size) + 1; - byte *buf = new byte[len]; - Base64::atob(fingerprint + 1, buf, len); - int l = Serialize64::unserialize(buf, len, (uint64_t *)&size); - delete [] buf; - if (l > 0) - { - attrs.map['c'] = fingerprint + ssize + 1; - } - } - } + tc.nn->parenthandle = UNDEF; - string attrstring; - attrs.getjson(&attrstring); - client->makeattr(&key,newnode->attrstring, attrstring.c_str()); - newnode->source = NEW_NODE; - } + if (newName && tc.nn[0].nodekey.size()) + { + SymmCipher key; + AttrMap attrs; + string attrstring; - newnode->nodehandle = publicNode->getHandle(); - newnode->type = (nodetype_t)publicNode->getType(); - newnode->parenthandle = UNDEF; + key.setkey((const byte*)tc.nn[0].nodekey.data(), node->type); + attrs = node->attrs; - if(target) - { - client->putnodes(target->nodehandle, newnode, 1); - } - else - { - client->putnodes(email, newnode, 1); - } + string sname = newName; + fsAccess->normalize(&sname); + attrs.map['n'] = sname; + attrs.getjson(&attrstring); + client->makeattr(&key,tc.nn[0].attrstring, attrstring.c_str()); } + if (target) + { + client->putnodes(target->nodehandle, tc.nn, nc); + } + else + { + client->putnodes(email, tc.nn, nc); + } } else { @@ -11517,7 +11469,7 @@ void MegaApiImpl::sendPendingRequests() tc.nn->parenthandle = UNDEF; - if(nc == 1 && newName && tc.nn[0].nodekey.size()) + if (newName && tc.nn[0].nodekey.size()) { SymmCipher key; AttrMap attrs; @@ -14182,17 +14134,8 @@ bool MegaTreeProcCopy::processMegaNode(MegaNode *n) { if (nn) { - string attrstring; - SymmCipher key; - AttrMap attrs; NewNode* t = nn+--nc; - // copy node - t->source = NEW_NODE; - t->type = (nodetype_t)n->getType(); - t->nodehandle = n->getHandle(); - t->parenthandle = n->getParentHandle() ? n->getParentHandle() : UNDEF; - // copy key (if file) or generate new key (if folder) if (n->getType() == FILENODE) { @@ -14202,39 +14145,54 @@ bool MegaTreeProcCopy::processMegaNode(MegaNode *n) { byte buf[FOLDERNODEKEYLENGTH]; PrnGen::genblock(buf,sizeof buf); - t->nodekey.assign((char*)buf,FOLDERNODEKEYLENGTH); + t->nodekey.assign((char*)buf, FOLDERNODEKEYLENGTH); } - // attach attributes - string sname = n->getName(); - client->fsaccess->normalize(&sname); - attrs.map['n'] = sname; + t->attrstring = new string; - const char *fingerprint = n->getFingerprint(); - if (fingerprint && fingerprint[0]) + if (n->isPublic()) { - m_off_t size = 0; - unsigned int fsize = strlen(fingerprint); - unsigned int ssize = fingerprint[0] - 'A'; - if (!(ssize > (sizeof(size) * 4 / 3 + 4) || fsize <= (ssize + 1))) + t->attrstring->assign(n->getAttrString()->data(), n->getAttrString()->size()); + t->source = NEW_PUBLIC; + } + else + { + SymmCipher key; + AttrMap attrs; + + key.setkey((const byte*)t->nodekey.data(),n->getType()); + string sname = n->getName(); + client->fsaccess->normalize(&sname); + attrs.map['n'] = sname; + + const char *fingerprint = n->getFingerprint(); + if (fingerprint && fingerprint[0]) { - int len = sizeof(size) + 1; - byte *buf = new byte[len]; - Base64::atob(fingerprint + 1, buf, len); - int l = Serialize64::unserialize(buf, len, (uint64_t *)&size); - delete [] buf; - if (l > 0) + m_off_t size = 0; + unsigned int fsize = strlen(fingerprint); + unsigned int ssize = fingerprint[0] - 'A'; + if (!(ssize > (sizeof(size) * 4 / 3 + 4) || fsize <= (ssize + 1))) { - attrs.map['c'] = fingerprint + ssize + 1; + int len = sizeof(size) + 1; + byte *buf = new byte[len]; + Base64::atob(fingerprint + 1, buf, len); + int l = Serialize64::unserialize(buf, len, (uint64_t *)&size); + delete [] buf; + if (l > 0) + { + attrs.map['c'] = fingerprint + ssize + 1; + } } } - } - key.setkey((const byte*)t->nodekey.data(),n->getType()); + string attrstring; + attrs.getjson(&attrstring); + client->makeattr(&key,t->attrstring, attrstring.c_str()); + } - t->attrstring = new string; - attrs.getjson(&attrstring); - client->makeattr(&key,t->attrstring, attrstring.c_str()); + t->nodehandle = n->getHandle(); + t->type = (nodetype_t)n->getType(); + t->parenthandle = n->getParentHandle() ? n->getParentHandle() : UNDEF; } else { From c83a1d2bd9354fe88fca78f46241e0bca94c69e2 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Fri, 14 Oct 2016 18:12:41 +0200 Subject: [PATCH 041/103] Fixed a memory leak --- src/megaapi_impl.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 39aeedc4c6..e9a481e0ab 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -14464,6 +14464,7 @@ void MegaFolderDownloadController::start(MegaNode *node) const char *parentPath = transfer->getParentPath(); const char *fileName = transfer->getFileName(); + bool deleteNode = false; if (!node) { @@ -14475,6 +14476,7 @@ void MegaFolderDownloadController::start(MegaNode *node) delete this; return; } + deleteNode = true; } string name; @@ -14513,6 +14515,11 @@ void MegaFolderDownloadController::start(MegaNode *node) transfer->setPath(path.c_str()); downloadFolderNode(node, &path); + + if (deleteNode) + { + delete node; + } } void MegaFolderDownloadController::downloadFolderNode(MegaNode *node, string *path) From 8ff682a41947f4f94b3d391c9073a41b18a74cb5 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Fri, 14 Oct 2016 18:13:10 +0200 Subject: [PATCH 042/103] Cleanup --- src/megaapi_impl.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index e9a481e0ab..ca717a1718 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -14576,6 +14576,7 @@ void MegaFolderDownloadController::downloadFolderNode(MegaNode *node, string *pa int l = localpath.size(); string name = child->getName(); + int64_t size = child->getSize(); client->fsaccess->name2local(&name); localpath.append(name); @@ -14588,13 +14589,13 @@ void MegaFolderDownloadController::downloadFolderNode(MegaNode *node, string *pa FileAccess *fa = NULL; fa = client->fsaccess->newfileaccess(); - if (child && fa->fopen(&localpath, true, false) && fa->type == FILENODE) + if (fa->fopen(&localpath, true, false) && fa->type == FILENODE) { const char *fpLocal = megaApi->getFingerprint(localpath.c_str()); const char *fpRemote = megaApi->getFingerprint(child); if ((fpLocal && fpRemote && !strcmp(fpLocal,fpRemote)) - || (!fpRemote && child->getSize() == fa->size + || (!fpRemote && size == fa->size && child->getModificationTime() == fa->mtime)) { delete [] fpLocal; @@ -14609,12 +14610,12 @@ void MegaFolderDownloadController::downloadFolderNode(MegaNode *node, string *pa t->setTag(nextTag); t->setFolderTransferTag(tag); - t->setTotalBytes(child->getSize()); + t->setTotalBytes(size); megaApi->transferMap[nextTag] = t; megaApi->fireOnTransferStart(t); - t->setTransferredBytes(child->getSize()); - t->setDeltaSize(child->getSize()); + t->setTransferredBytes(size); + t->setDeltaSize(size); megaApi->fireOnTransferFinish(t, MegaError(API_OK)); localpath.resize(l); delete fa; From 56f84bb7f928e1be737df6091b465e6d0661429e Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Fri, 14 Oct 2016 18:26:54 +0200 Subject: [PATCH 043/103] Manage errors creating folders in folder downloads Finish folder downloads with the last error received --- include/megaapi_impl.h | 1 + src/megaapi_impl.cpp | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/megaapi_impl.h b/include/megaapi_impl.h index 821e947eb7..f44ff47da5 100644 --- a/include/megaapi_impl.h +++ b/include/megaapi_impl.h @@ -204,6 +204,7 @@ class MegaFolderDownloadController : public MegaTransferListener int recursive; int tag; int pendingTransfers; + error e; public: virtual void onTransferStart(MegaApi *, MegaTransfer *t); diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index ca717a1718..345632e288 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -14454,6 +14454,7 @@ MegaFolderDownloadController::MegaFolderDownloadController(MegaApiImpl *megaApi, this->recursive = 0; this->pendingTransfers = 0; this->tag = transfer->getTag(); + this->e = API_OK; } void MegaFolderDownloadController::start(MegaNode *node) @@ -14531,7 +14532,16 @@ void MegaFolderDownloadController::downloadFolderNode(MegaNode *node, string *pa FileAccess *da = client->fsaccess->newfileaccess(); if (!da->fopen(&localpath, true, false)) { - client->fsaccess->mkdirlocal(&localpath); + if (!client->fsaccess->mkdirlocal(&localpath)) + { + delete da; + LOG_err << "Unable to create folder: " << *path; + + recursive--; + e = API_EWRITE; + checkCompletion(); + return; + } } else if (da->type != FILENODE) { @@ -14543,8 +14553,8 @@ void MegaFolderDownloadController::downloadFolderNode(MegaNode *node, string *pa LOG_err << "Local file detected where there should be a folder: " << *path; recursive--; + e = API_EEXIST; checkCompletion(); - return; } delete da; @@ -14566,6 +14576,7 @@ void MegaFolderDownloadController::downloadFolderNode(MegaNode *node, string *pa { LOG_err << "Child nodes not found: " << *path; recursive--; + e = API_ENOENT; checkCompletion(); return; } @@ -14647,7 +14658,7 @@ void MegaFolderDownloadController::checkCompletion() if (!recursive && !pendingTransfers) { LOG_debug << "Folder download finished - " << transfer->getTransferredBytes() << " of " << transfer->getTotalBytes(); - megaApi->fireOnTransferFinish(transfer, MegaError(API_OK)); + megaApi->fireOnTransferFinish(transfer, MegaError(e)); delete this; } } @@ -14679,6 +14690,10 @@ void MegaFolderDownloadController::onTransferFinish(MegaApi *, MegaTransfer *t, } megaApi->fireOnTransferUpdate(transfer); + if (e->getErrorCode()) + { + this->e = (error)e->getErrorCode(); + } checkCompletion(); } From 855b5b5282d18a3127e0c95c650534b80695725d Mon Sep 17 00:00:00 2001 From: Javier Navarro Date: Fri, 14 Oct 2016 18:40:45 +0200 Subject: [PATCH 044/103] Change the branch of karere repository from feature/mega-chat-api to develop --- bindings/ios/3rdparty/build-libevent2.sh | 2 +- bindings/ios/3rdparty/build-libws.sh | 2 +- bindings/ios/3rdparty/build-megachat.sh | 2 +- bindings/ios/3rdparty/build-webrtc.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bindings/ios/3rdparty/build-libevent2.sh b/bindings/ios/3rdparty/build-libevent2.sh index fdc75be9e4..a198661f52 100644 --- a/bindings/ios/3rdparty/build-libevent2.sh +++ b/bindings/ios/3rdparty/build-libevent2.sh @@ -36,7 +36,7 @@ set -e if [ ! -d "karere-native" ] then -git clone --recursive -b feature/mega-chat-api https://code.developers.mega.co.nz/messenger/karere-native +git clone --recursive -b develop https://code.developers.mega.co.nz/messenger/karere-native fi for ARCH in ${ARCHS} diff --git a/bindings/ios/3rdparty/build-libws.sh b/bindings/ios/3rdparty/build-libws.sh index 5feba8a0eb..030f812ce0 100644 --- a/bindings/ios/3rdparty/build-libws.sh +++ b/bindings/ios/3rdparty/build-libws.sh @@ -36,7 +36,7 @@ set -e if [ ! -d "karere-native" ] then -git clone --recursive -b feature/mega-chat-api https://code.developers.mega.co.nz/messenger/karere-native +git clone --recursive -b develop https://code.developers.mega.co.nz/messenger/karere-native fi for ARCH in ${ARCHS} diff --git a/bindings/ios/3rdparty/build-megachat.sh b/bindings/ios/3rdparty/build-megachat.sh index 352d0be9ad..bbc99a79cd 100644 --- a/bindings/ios/3rdparty/build-megachat.sh +++ b/bindings/ios/3rdparty/build-megachat.sh @@ -36,7 +36,7 @@ set -e if [ ! -d "karere-native" ] then -git clone --recursive -b feature/mega-chat-api https://code.developers.mega.co.nz/messenger/karere-native +git clone --recursive -b develop https://code.developers.mega.co.nz/messenger/karere-native fi ln -sf ../../mega include/mega diff --git a/bindings/ios/3rdparty/build-webrtc.sh b/bindings/ios/3rdparty/build-webrtc.sh index 47678c5e7f..0d394459ea 100644 --- a/bindings/ios/3rdparty/build-webrtc.sh +++ b/bindings/ios/3rdparty/build-webrtc.sh @@ -36,7 +36,7 @@ set -e if [ ! -d "karere-native" ] then -git clone --recursive -b feature/mega-chat-api https://code.developers.mega.co.nz/messenger/karere-native +git clone --recursive -b develop https://code.developers.mega.co.nz/messenger/karere-native fi export WEBRTC_DEPS_INCLUDE=${CURRENTPATH}/include From ca2bd683738276a0b97c659343d029918da30d06 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Fri, 14 Oct 2016 18:49:54 +0200 Subject: [PATCH 045/103] Fixed a bug in processMegaTree --- src/megaapi_impl.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 345632e288..1c9d2d289a 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -6513,9 +6513,11 @@ bool MegaApiImpl::processMegaTree(MegaNode* n, MegaTreeProcessor* processor, boo MegaNode *child = nList->get(i); if (recursive) { - processMegaTree(child, processor); - sdkMutex.unlock(); - return 0; + if (!processMegaTree(child, processor)) + { + sdkMutex.unlock(); + return 0; + } } else { @@ -6765,7 +6767,6 @@ bool MegaApiImpl::processTree(Node* node, TreeProcessor* processor, bool recursi } } bool result = processor->processNode(node); - sdkMutex.unlock(); return result; } From 9ebc8c30d830006ee1ab2daff3997c6327aa2bb9 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Fri, 14 Oct 2016 19:00:10 +0200 Subject: [PATCH 046/103] Fixed a possible memory leak --- src/megaapi_impl.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 1c9d2d289a..f8c7a8d46a 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -14128,7 +14128,7 @@ void MegaTreeProcCopy::allocnodes() { if (nc) { - nn = new NewNode[nc]; + nn = new NewNode[nc]; } } bool MegaTreeProcCopy::processMegaNode(MegaNode *n) @@ -14633,6 +14633,8 @@ void MegaFolderDownloadController::downloadFolderNode(MegaNode *node, string *pa delete fa; continue; } + delete [] fpLocal; + delete [] fpRemote; } delete fa; From af17a853de5d7a12cb02da2dd8f474580c2802c5 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Fri, 14 Oct 2016 21:38:39 +0200 Subject: [PATCH 047/103] Fixed bugs detected durig tests related to node copies --- include/megaapi_impl.h | 1 + src/megaapi_impl.cpp | 106 +++++++++++++++++++++++------------------ 2 files changed, 61 insertions(+), 46 deletions(-) diff --git a/include/megaapi_impl.h b/include/megaapi_impl.h index f44ff47da5..6f53f45b74 100644 --- a/include/megaapi_impl.h +++ b/include/megaapi_impl.h @@ -264,6 +264,7 @@ class MegaNodePrivate : public MegaNode, public Cachable void setPublicAuth(const char *publicAuth); void setForeign(bool foreign); void setChildren(MegaNodeList *children); + void setName(const char *newName); virtual std::string* getPublicAuth(); virtual bool isShared(); virtual bool isOutShare(); diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index f8c7a8d46a..48debd0010 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -1043,6 +1043,14 @@ void MegaNodePrivate::setChildren(MegaNodeList *children) this->children = children; } +void MegaNodePrivate::setName(const char *newName) +{ + if (name) + delete [] name; + + name = MegaApi::strdup(newName); +} + string *MegaNodePrivate::getPublicAuth() { return &publicAuth; @@ -11397,12 +11405,22 @@ void MegaApiImpl::sendPendingRequests() } case MegaRequest::TYPE_COPY: { - Node *node = client->nodebyhandle(request->getNodeHandle()); + Node *node = NULL; Node *target = client->nodebyhandle(request->getParentHandle()); const char* email = request->getEmail(); MegaNode *publicNode = request->getPublicNode(); const char *newName = request->getName(); + if (!publicNode->isForeign() && !publicNode->isPublic()) + { + node = client->nodebyhandle(request->getNodeHandle()); + if (!node) + { + e = API_ENOENT; + break; + } + } + if (!publicNode || (!target && !email) || (newName && !(*newName))) { e = API_EARGS; break; } if (!node) @@ -11413,33 +11431,29 @@ void MegaApiImpl::sendPendingRequests() processMegaTree(publicNode, &tc); tc.allocnodes(); nc = tc.nc; - - // build new nodes array - processMegaTree(publicNode, &tc); if (!nc) { e = API_EARGS; break; } - tc.nn->parenthandle = UNDEF; - - if (newName && tc.nn[0].nodekey.size()) + if (newName) { - SymmCipher key; - AttrMap attrs; - string attrstring; - - key.setkey((const byte*)tc.nn[0].nodekey.data(), node->type); - attrs = node->attrs; + MegaNodePrivate *privateNode = dynamic_cast(publicNode); + if (privateNode) + { + privateNode->setName(newName); + } + else + { + LOG_err << "Unknown node type"; + } + } - string sname = newName; - fsAccess->normalize(&sname); - attrs.map['n'] = sname; + // build new nodes array + processMegaTree(publicNode, &tc); - attrs.getjson(&attrstring); - client->makeattr(&key,tc.nn[0].attrstring, attrstring.c_str()); - } + tc.nn->parenthandle = UNDEF; if (target) { @@ -14150,47 +14164,47 @@ bool MegaTreeProcCopy::processMegaNode(MegaNode *n) } t->attrstring = new string; - if (n->isPublic()) { - t->attrstring->assign(n->getAttrString()->data(), n->getAttrString()->size()); t->source = NEW_PUBLIC; } else { - SymmCipher key; - AttrMap attrs; + t->source = NEW_NODE; + } - key.setkey((const byte*)t->nodekey.data(),n->getType()); - string sname = n->getName(); - client->fsaccess->normalize(&sname); - attrs.map['n'] = sname; + SymmCipher key; + AttrMap attrs; + + key.setkey((const byte*)t->nodekey.data(),n->getType()); + string sname = n->getName(); + client->fsaccess->normalize(&sname); + attrs.map['n'] = sname; - const char *fingerprint = n->getFingerprint(); - if (fingerprint && fingerprint[0]) + const char *fingerprint = n->getFingerprint(); + if (fingerprint && fingerprint[0]) + { + m_off_t size = 0; + unsigned int fsize = strlen(fingerprint); + unsigned int ssize = fingerprint[0] - 'A'; + if (!(ssize > (sizeof(size) * 4 / 3 + 4) || fsize <= (ssize + 1))) { - m_off_t size = 0; - unsigned int fsize = strlen(fingerprint); - unsigned int ssize = fingerprint[0] - 'A'; - if (!(ssize > (sizeof(size) * 4 / 3 + 4) || fsize <= (ssize + 1))) + int len = sizeof(size) + 1; + byte *buf = new byte[len]; + Base64::atob(fingerprint + 1, buf, len); + int l = Serialize64::unserialize(buf, len, (uint64_t *)&size); + delete [] buf; + if (l > 0) { - int len = sizeof(size) + 1; - byte *buf = new byte[len]; - Base64::atob(fingerprint + 1, buf, len); - int l = Serialize64::unserialize(buf, len, (uint64_t *)&size); - delete [] buf; - if (l > 0) - { - attrs.map['c'] = fingerprint + ssize + 1; - } + attrs.map['c'] = fingerprint + ssize + 1; } } - - string attrstring; - attrs.getjson(&attrstring); - client->makeattr(&key,t->attrstring, attrstring.c_str()); } + string attrstring; + attrs.getjson(&attrstring); + client->makeattr(&key,t->attrstring, attrstring.c_str()); + t->nodehandle = n->getHandle(); t->type = (nodetype_t)n->getType(); t->parenthandle = n->getParentHandle() ? n->getParentHandle() : UNDEF; From 5e2e7e982ca887e7fb0d8e3b26babfce50df4786 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Fri, 14 Oct 2016 22:06:50 +0200 Subject: [PATCH 048/103] Don't allow to upload or copy inside file nodes --- src/megaapi_impl.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 48debd0010..db9263c7e6 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -10924,7 +10924,7 @@ void MegaApiImpl::sendPendingTransfers() int64_t mtime = transfer->getTime(); Node *parent = client->nodebyhandle(transfer->getParentHandle()); - if(!localPath || !parent || !fileName || !(*fileName)) + if (!localPath || !parent || parent->type == FILENODE || !fileName || !(*fileName)) { e = API_EARGS; break; @@ -11421,7 +11421,13 @@ void MegaApiImpl::sendPendingRequests() } } - if (!publicNode || (!target && !email) || (newName && !(*newName))) { e = API_EARGS; break; } + if (!publicNode || (!target && !email) + || (newName && !(*newName)) + || (target && target->type == FILENODE)) + { + e = API_EARGS; + break; + } if (!node) { From 8d59648e6654b58bdf9fd2ad94a15c1900533a5a Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Mon, 17 Oct 2016 13:08:38 +0200 Subject: [PATCH 049/103] Formatting --- src/megaapi_impl.cpp | 118 ++++++++++++++++++++++++------------------- 1 file changed, 67 insertions(+), 51 deletions(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index db9263c7e6..7272404c6a 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -11041,26 +11041,25 @@ void MegaApiImpl::sendPendingTransfers() string securename; string path; - if(parentPath) - { - path = parentPath; - } - else - { - string separator; - client->fsaccess->local2path(&client->fsaccess->localseparator, &separator); - path = "."; - path.append(separator); - } - - MegaFileGet *f; + if (parentPath) + { + path = parentPath; + } + else + { + string separator; + client->fsaccess->local2path(&client->fsaccess->localseparator, &separator); + path = "."; + path.append(separator); + } - if(node) - { - if(!fileName) + MegaFileGet *f; + if (node) + { + if (!fileName) { attr_map::iterator ait = node->attrs.map.find('n'); - if(ait == node->attrs.map.end()) + if (ait == node->attrs.map.end()) { name = "CRYPTO_ERROR"; } @@ -11081,35 +11080,39 @@ void MegaApiImpl::sendPendingTransfers() client->fsaccess->name2local(&name); client->fsaccess->local2path(&name, &securename); path += securename; - f = new MegaFileGet(client, node, path); - } - else - { - if(!transfer->getFileName()) + f = new MegaFileGet(client, node, path); + } + else + { + if (!transfer->getFileName()) + { name = publicNode->getName(); + } else + { name = transfer->getFileName(); + } client->fsaccess->name2local(&name); client->fsaccess->local2path(&name, &securename); path += securename; - f = new MegaFileGet(client, publicNode, path); - } + f = new MegaFileGet(client, publicNode, path); + } - transfer->setPath(path.c_str()); + transfer->setPath(path.c_str()); f->setTransfer(transfer); bool ok = client->startxfer(GET, f, true); - if(transfer->getTag() == -1) + if (transfer->getTag() == -1) { //Already existing transfer if (ok) { //Set the transfer as regular transfer_map::iterator it = client->transfers[GET].find(f); - if(it != client->transfers[GET].end()) + if (it != client->transfers[GET].end()) { int previousTag = it->second->tag; - if(transferMap.find(previousTag) != transferMap.end()) + if (transferMap.find(previousTag) != transferMap.end()) { MegaTransferPrivate* previousTransfer = transferMap.at(previousTag); previousTransfer->setSyncTransfer(false); @@ -11135,28 +11138,39 @@ void MegaApiImpl::sendPendingTransfers() } else { - m_off_t startPos = transfer->getStartPos(); - m_off_t endPos = transfer->getEndPos(); - if(startPos < 0 || endPos < 0 || startPos > endPos) { e = API_EARGS; break; } - if(node) + m_off_t startPos = transfer->getStartPos(); + m_off_t endPos = transfer->getEndPos(); + if (startPos < 0 || endPos < 0 || startPos > endPos) + { + e = API_EARGS; + break; + } + + if (node) { transfer->setFileName(node->displayname()); - if(startPos >= node->size || endPos >= node->size) - { e = API_EARGS; break; } + if (startPos >= node->size || endPos >= node->size) + { + e = API_EARGS; + break; + } - m_off_t totalBytes = endPos - startPos + 1; - transferMap[nextTag]=transfer; - transfer->setTotalBytes(totalBytes); - transfer->setTag(nextTag); + m_off_t totalBytes = endPos - startPos + 1; + transferMap[nextTag]=transfer; + transfer->setTotalBytes(totalBytes); + transfer->setTag(nextTag); fireOnTransferStart(transfer); - client->pread(node, startPos, totalBytes, transfer); - waiter->notify(); - } - else - { + client->pread(node, startPos, totalBytes, transfer); + waiter->notify(); + } + else + { transfer->setFileName(publicNode->getName()); - if(startPos >= publicNode->getSize() || endPos >= publicNode->getSize()) - { e = API_EARGS; break; } + if (startPos >= publicNode->getSize() || endPos >= publicNode->getSize()) + { + e = API_EARGS; + break; + } m_off_t totalBytes = endPos - startPos + 1; transferMap[nextTag]=transfer; @@ -11169,16 +11183,18 @@ void MegaApiImpl::sendPendingTransfers() MemAccess::get((const char*)publicNode->getNodeKey()->data() + SymmCipher::KEYLENGTH), startPos, totalBytes, transfer); waiter->notify(); - } + } } - currentTransfer=NULL; - break; - } - } + currentTransfer = NULL; + break; + } + } - if(e) + if (e) + { fireOnTransferFinish(transfer, MegaError(e)); + } sdkMutex.unlock(); } From 183b6c1af47a3bbe4957f81650c942b05dc921a4 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Mon, 17 Oct 2016 18:33:01 +0200 Subject: [PATCH 050/103] Changed the name of a variable --- src/megaapi_impl.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 7272404c6a..08ecd39bc9 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -11424,10 +11424,10 @@ void MegaApiImpl::sendPendingRequests() Node *node = NULL; Node *target = client->nodebyhandle(request->getParentHandle()); const char* email = request->getEmail(); - MegaNode *publicNode = request->getPublicNode(); + MegaNode *megaNode = request->getPublicNode(); const char *newName = request->getName(); - if (!publicNode->isForeign() && !publicNode->isPublic()) + if (!megaNode->isForeign() && !megaNode->isPublic()) { node = client->nodebyhandle(request->getNodeHandle()); if (!node) @@ -11437,7 +11437,7 @@ void MegaApiImpl::sendPendingRequests() } } - if (!publicNode || (!target && !email) + if (!megaNode || (!target && !email) || (newName && !(*newName)) || (target && target->type == FILENODE)) { @@ -11450,7 +11450,7 @@ void MegaApiImpl::sendPendingRequests() unsigned nc; MegaTreeProcCopy tc(client); - processMegaTree(publicNode, &tc); + processMegaTree(megaNode, &tc); tc.allocnodes(); nc = tc.nc; if (!nc) @@ -11461,7 +11461,7 @@ void MegaApiImpl::sendPendingRequests() if (newName) { - MegaNodePrivate *privateNode = dynamic_cast(publicNode); + MegaNodePrivate *privateNode = dynamic_cast(megaNode); if (privateNode) { privateNode->setName(newName); @@ -11473,7 +11473,7 @@ void MegaApiImpl::sendPendingRequests() } // build new nodes array - processMegaTree(publicNode, &tc); + processMegaTree(megaNode, &tc); tc.nn->parenthandle = UNDEF; From 7df13acfe966f9f855928aa82f88e7d42c1cc82c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Hern=C3=A1ndez?= Date: Mon, 17 Oct 2016 19:40:23 +0200 Subject: [PATCH 051/103] Define the maximum number of connections per transfer --- include/mega/types.h | 2 ++ include/megaapi.h | 10 +++++----- src/megaapi_impl.cpp | 2 +- src/megaclient.cpp | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/mega/types.h b/include/mega/types.h index dce1b00cf7..078ee0cbcf 100644 --- a/include/mega/types.h +++ b/include/mega/types.h @@ -448,6 +448,8 @@ typedef enum { RECOVER_WITH_MASTERKEY = 9, RECOVER_WITHOUT_MASTERKEY = 10, CANCE typedef enum { EMAIL_REMOVED = 0, EMAIL_PENDING_REMOVED = 1, EMAIL_PENDING_ADDED = 2, EMAIL_FULLY_ACCEPTED = 3 } emailstatus_t; +#define MAX_NUM_CONNECTIONS 6 + } // namespace #endif diff --git a/include/megaapi.h b/include/megaapi.h index 3c1c6aa7f7..ab121cca49 100644 --- a/include/megaapi.h +++ b/include/megaapi.h @@ -6242,19 +6242,19 @@ class MegaApi /** * @brief Set the maximum number of connections per transfer * - * The maximum number of allowed connections is 6. If a higher number of connections is - * passed to this function, it will fail with the error code API_ETOOMANY. + * The maximum number of allowed connections is MAX_NUM_CONNECTIONS. If a higher number + * of connections is passed to this function, it will fail with the error code API_ETOOMANY. * * The associated request type with this request is MegaRequest::TYPE_SET_MAX_CONNECTIONS * Valid data in the MegaRequest object received on callbacks: - * - MegaRequest::getParamType - Returns the first parameter - * - MegaRequest::getNumber - Returns the second parameter + * - MegaRequest::getParamType - Returns the value for \c direction parameter + * - MegaRequest::getNumber - Returns the number of \c connections * * @param direction Direction of transfers * Valid values for this parameter are: * - MegaTransfer::TYPE_DOWNLOAD = 0 * - MegaTransfer::TYPE_UPLOAD = 1 - * @param connections Maximum number of connection (it should between 1 and 6) + * @param connections Maximum number of connection (it should between 1 and MAX_NUM_CONNECTIONS) */ void setMaxConnections(int direction, int connections, MegaRequestListener* listener = NULL); diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 6612ffb01c..c052731832 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -12576,7 +12576,7 @@ void MegaApiImpl::sendPendingRequests() break; } - if (connections > 6) + if (connections > MAX_NUM_CONNECTIONS) { e = API_ETOOMANY; break; diff --git a/src/megaclient.cpp b/src/megaclient.cpp index da22a69f3e..cb5ddf2b02 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -10048,9 +10048,9 @@ void MegaClient::setmaxconnections(direction_t d, int num) { if (num > 0) { - if (num > 6) + if (num > MAX_NUM_CONNECTIONS) { - num = 6; + num = MAX_NUM_CONNECTIONS; } connections[d] = num; From c6fe3abc59fa971ff344cfaa3f79ef02e9d89fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Hern=C3=A1ndez?= Date: Mon, 17 Oct 2016 19:41:00 +0200 Subject: [PATCH 052/103] Add new method to set max. connections for both download & upload --- include/megaapi.h | 14 ++++++++++++++ src/megaapi.cpp | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/include/megaapi.h b/include/megaapi.h index ab121cca49..1fd5384f46 100644 --- a/include/megaapi.h +++ b/include/megaapi.h @@ -6258,6 +6258,20 @@ class MegaApi */ void setMaxConnections(int direction, int connections, MegaRequestListener* listener = NULL); + /** + * @brief Set the maximum number of connections per transfer for downloads and uploads + * + * The maximum number of allowed connections is MAX_NUM_CONNECTIONS. If a higher number + * of connections is passed to this function, it will fail with the error code API_ETOOMANY. + * + * The associated request type with this request is MegaRequest::TYPE_SET_MAX_CONNECTIONS + * Valid data in the MegaRequest object received on callbacks: + * - MegaRequest::getNumber - Returns the number of connections + * + * @param connections Maximum number of connection (it should between 1 and MAX_NUM_CONNECTIONS) + */ + void setMaxConnections(int connections, MegaRequestListener* listener = NULL); + /** * @brief Set the transfer method for downloads * diff --git a/src/megaapi.cpp b/src/megaapi.cpp index 20be4ced58..7f19a5be68 100644 --- a/src/megaapi.cpp +++ b/src/megaapi.cpp @@ -1697,6 +1697,11 @@ void MegaApi::setMaxConnections(int direction, int connections, MegaRequestListe pImpl->setMaxConnections(direction, connections, listener); } +void MegaApi::setMaxConnections(int connections, MegaRequestListener *listener) +{ + pImpl->setMaxConnections(-1, connections, listener); +} + void MegaApi::setDownloadMethod(int method) { pImpl->setDownloadMethod(method); From 2b9370b039b99fdc22589e50adcee47a34979dcc Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Mon, 17 Oct 2016 19:56:02 +0200 Subject: [PATCH 053/103] Pause / resume the processing of action packets --- include/mega/megaclient.h | 3 +++ include/megaapi.h | 24 ++++++++++++++++++++++++ include/megaapi_impl.h | 2 ++ src/megaapi.cpp | 10 ++++++++++ src/megaapi_impl.cpp | 14 ++++++++++++++ src/megaclient.cpp | 6 ++++-- 6 files changed, 57 insertions(+), 2 deletions(-) diff --git a/include/mega/megaclient.h b/include/mega/megaclient.h index 306cbcb3a9..8aa8096bc5 100644 --- a/include/mega/megaclient.h +++ b/include/mega/megaclient.h @@ -550,6 +550,9 @@ class MEGA_API MegaClient void updatesc(); void finalizesc(bool); + // flag to pause / resume the processing of action packets + bool scpaused; + // MegaClient-Server response JSON JSON json; diff --git a/include/megaapi.h b/include/megaapi.h index 71dfe41579..b2def54206 100644 --- a/include/megaapi.h +++ b/include/megaapi.h @@ -7658,6 +7658,30 @@ class MegaApi */ void setPublicKeyPinning(bool enable); + /** + * @brief Pause the reception of action packets + * + * This function is intended to help apps to initialize themselves + * after the reception of nodes (MegaApi::fetchNodes) but before the reception + * of action packets. + * + * For that purpose, this function can be called synchronously in the callback + * onRequestFinish related to the fetchNodes request. + * + * After your initialization is finished, you can call MegaApi::resumeActionPackets + * to start receiving external updates. + * + * If you forget to call MegaApi::resumeActionPackets after the usage of this function + * the SDK won't work properly. Do not use this function for other purposes. + */ + void pauseActionPackets(); + + /** + * @brief Resume the reception of action packets + * @see MegaApi::pauseActionPackets + */ + void resumeActionPackets(); + #ifdef _WIN32 /** * @brief Convert an UTF16 string to UTF8 (Windows only) diff --git a/include/megaapi_impl.h b/include/megaapi_impl.h index ed14947ff2..6016c9ee61 100644 --- a/include/megaapi_impl.h +++ b/include/megaapi_impl.h @@ -1487,6 +1487,8 @@ class MegaApiImpl : public MegaApp void changeApiUrl(const char *apiURL, bool disablepkp = false); void retrySSLerrors(bool enable); void setPublicKeyPinning(bool enable); + void pauseActionPackets(); + void resumeActionPackets(); static bool nodeComparatorDefaultASC (Node *i, Node *j); static bool nodeComparatorDefaultDESC (Node *i, Node *j); diff --git a/src/megaapi.cpp b/src/megaapi.cpp index 9d67eda220..8f31aac101 100644 --- a/src/megaapi.cpp +++ b/src/megaapi.cpp @@ -2119,6 +2119,16 @@ void MegaApi::setPublicKeyPinning(bool enable) pImpl->setPublicKeyPinning(enable); } +void MegaApi::pauseActionPackets() +{ + pImpl->pauseActionPackets(); +} + +void MegaApi::resumeActionPackets() +{ + pImpl->resumeActionPackets(); +} + char *MegaApi::base64ToBase32(const char *base64) { if(!base64) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 37a1c1f787..60391ea6de 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -6786,6 +6786,20 @@ void MegaApiImpl::setPublicKeyPinning(bool enable) sdkMutex.unlock(); } +void MegaApiImpl::pauseActionPackets() +{ + sdkMutex.lock(); + client->scpaused = true; + sdkMutex.unlock(); +} + +void MegaApiImpl::resumeActionPackets() +{ + sdkMutex.lock(); + client->scpaused = false; + sdkMutex.unlock(); +} + bool MegaApiImpl::processTree(Node* node, TreeProcessor* processor, bool recursive) { if(!node) return 1; diff --git a/src/megaclient.cpp b/src/megaclient.cpp index f547c1130c..8fd47f025e 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -742,6 +742,7 @@ MegaClient::MegaClient(MegaApp* a, Waiter* w, HttpIO* h, FileSystemAccess* f, Db usealtdownport = false; usealtupport = false; retryessl = false; + scpaused = false; #ifndef EMSCRIPTEN autodownport = true; @@ -1303,9 +1304,9 @@ void MegaClient::exec() // do not process the SC result until all preconfigured syncs are up and running // except if SC packets are required to complete a fetchnodes - if (jsonsc.pos && (syncsup || !statecurrent) && !syncdownrequired && !syncdownretry) + if (!scpaused && jsonsc.pos && (syncsup || !statecurrent) && !syncdownrequired && !syncdownretry) #else - if (jsonsc.pos) + if (!scpaused && jsonsc.pos) #endif { // FIXME: reload in case of bad JSON @@ -2598,6 +2599,7 @@ void MegaClient::locallogout() putmbpscap = 0; fetchingnodes = false; overquotauntil = 0; + scpaused = false; for (fafc_map::iterator cit = fafcs.begin(); cit != fafcs.end(); cit++) { From 284428b9794f4afb21e581fde01cb39683d06834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Hern=C3=A1ndez?= Date: Mon, 17 Oct 2016 20:09:37 +0200 Subject: [PATCH 054/103] Move the definition of NUM_MAX_CONNECTIONS to the private side --- include/mega/megaclient.h | 3 +++ include/mega/types.h | 2 -- include/megaapi.h | 12 ++++++------ src/megaapi_impl.cpp | 2 +- src/megaclient.cpp | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/mega/megaclient.h b/include/mega/megaclient.h index 9a5f320ac6..29d2d16e9e 100644 --- a/include/mega/megaclient.h +++ b/include/mega/megaclient.h @@ -161,6 +161,9 @@ class MEGA_API MegaClient void stopxfer(File* f); void pausexfers(direction_t, bool, bool = false); + // maximum number of connections per transfer + static const unsigned MAX_NUM_CONNECTIONS = 6; + // set max connections per transfer void setmaxconnections(direction_t, int); diff --git a/include/mega/types.h b/include/mega/types.h index 078ee0cbcf..dce1b00cf7 100644 --- a/include/mega/types.h +++ b/include/mega/types.h @@ -448,8 +448,6 @@ typedef enum { RECOVER_WITH_MASTERKEY = 9, RECOVER_WITHOUT_MASTERKEY = 10, CANCE typedef enum { EMAIL_REMOVED = 0, EMAIL_PENDING_REMOVED = 1, EMAIL_PENDING_ADDED = 2, EMAIL_FULLY_ACCEPTED = 3 } emailstatus_t; -#define MAX_NUM_CONNECTIONS 6 - } // namespace #endif diff --git a/include/megaapi.h b/include/megaapi.h index 1fd5384f46..b50f887209 100644 --- a/include/megaapi.h +++ b/include/megaapi.h @@ -6242,8 +6242,8 @@ class MegaApi /** * @brief Set the maximum number of connections per transfer * - * The maximum number of allowed connections is MAX_NUM_CONNECTIONS. If a higher number - * of connections is passed to this function, it will fail with the error code API_ETOOMANY. + * The maximum number of allowed connections is 6. If a higher number of connections is passed + * to this function, it will fail with the error code API_ETOOMANY. * * The associated request type with this request is MegaRequest::TYPE_SET_MAX_CONNECTIONS * Valid data in the MegaRequest object received on callbacks: @@ -6254,21 +6254,21 @@ class MegaApi * Valid values for this parameter are: * - MegaTransfer::TYPE_DOWNLOAD = 0 * - MegaTransfer::TYPE_UPLOAD = 1 - * @param connections Maximum number of connection (it should between 1 and MAX_NUM_CONNECTIONS) + * @param connections Maximum number of connection (it should between 1 and 6) */ void setMaxConnections(int direction, int connections, MegaRequestListener* listener = NULL); /** * @brief Set the maximum number of connections per transfer for downloads and uploads * - * The maximum number of allowed connections is MAX_NUM_CONNECTIONS. If a higher number - * of connections is passed to this function, it will fail with the error code API_ETOOMANY. + * The maximum number of allowed connections is 6. If a higher number of connections is passed + * to this function, it will fail with the error code API_ETOOMANY. * * The associated request type with this request is MegaRequest::TYPE_SET_MAX_CONNECTIONS * Valid data in the MegaRequest object received on callbacks: * - MegaRequest::getNumber - Returns the number of connections * - * @param connections Maximum number of connection (it should between 1 and MAX_NUM_CONNECTIONS) + * @param connections Maximum number of connection (it should between 1 and 6) */ void setMaxConnections(int connections, MegaRequestListener* listener = NULL); diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index c052731832..1b80087dd1 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -12576,7 +12576,7 @@ void MegaApiImpl::sendPendingRequests() break; } - if (connections > MAX_NUM_CONNECTIONS) + if (connections > MegaClient::MAX_NUM_CONNECTIONS) { e = API_ETOOMANY; break; diff --git a/src/megaclient.cpp b/src/megaclient.cpp index cb5ddf2b02..5f5c4490dd 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -10048,9 +10048,9 @@ void MegaClient::setmaxconnections(direction_t d, int num) { if (num > 0) { - if (num > MAX_NUM_CONNECTIONS) + if (num > MegaClient::MAX_NUM_CONNECTIONS) { - num = MAX_NUM_CONNECTIONS; + num = MegaClient::MAX_NUM_CONNECTIONS; } connections[d] = num; From 494e52294a7cb78d8ad80851aa2e0287bb4ad8bb Mon Sep 17 00:00:00 2001 From: Javier Navarro Date: Tue, 18 Oct 2016 12:06:00 +0200 Subject: [PATCH 055/103] Build MEGAChat dependencies only when using the argument --enable-chat --- bindings/ios/3rdparty/build-all.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bindings/ios/3rdparty/build-all.sh b/bindings/ios/3rdparty/build-all.sh index 3dea514e9f..930aee6d3e 100644 --- a/bindings/ios/3rdparty/build-all.sh +++ b/bindings/ios/3rdparty/build-all.sh @@ -11,12 +11,14 @@ sh build-libuv.sh sh build-libsodium.sh # MEGAchat deps +if [ "$1" == "--enable-chat"]; then sh build-expat.sh sh build-libevent2.sh sh build-libws.sh sh build-webrtc.sh sh build-megachat.sh +fi echo "Done." From 58a2960787604561f36c11493dda92b57af02297 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Tue, 18 Oct 2016 12:51:56 +0200 Subject: [PATCH 056/103] Calculate the size of foreign folders --- include/megaapi_impl.h | 12 ++++++++++++ src/megaapi_impl.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/megaapi_impl.h b/include/megaapi_impl.h index 0d9f1f94c3..474cff4514 100644 --- a/include/megaapi_impl.h +++ b/include/megaapi_impl.h @@ -159,6 +159,18 @@ class MegaTreeProcCopy : public MegaTreeProcessor MegaClient *client; }; + +class MegaSizeProcessor : public MegaTreeProcessor +{ + protected: + long long totalBytes; + + public: + MegaSizeProcessor(); + virtual bool processMegaNode(MegaNode* node); + long long getTotalBytes(); +}; + class MegaFolderUploadController : public MegaRequestListener, public MegaTransferListener { public: diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index b118cedcdb..13ec869d49 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -6889,6 +6889,13 @@ long long MegaApiImpl::getSize(MegaNode *n) return n->getSize(); } + if (n->isForeign()) + { + MegaSizeProcessor megaSizeProcessor; + processMegaTree(n, &megaSizeProcessor); + return megaSizeProcessor.getTotalBytes(); + } + sdkMutex.lock(); Node *node = client->nodebyhandle(n->getHandle()); if(!node) @@ -16520,3 +16527,22 @@ vector &PublicLinkProcessor::getNodes() { return nodes; } + +MegaSizeProcessor::MegaSizeProcessor() +{ + totalBytes = 0; +} + +bool MegaSizeProcessor::processMegaNode(MegaNode *node) +{ + if (node->getType() == MegaNode::TYPE_FILE) + { + totalBytes += node->getSize(); + } + return true; +} + +long long MegaSizeProcessor::getTotalBytes() +{ + return totalBytes; +} From 9e068a21adab2ea3de8cf32d196f411d0feba80e Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Wed, 19 Oct 2016 13:09:26 +0200 Subject: [PATCH 057/103] Don't block the SDK during the cancellation of many transfers --- src/megaapi_impl.cpp | 47 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 13ec869d49..35b0c4863f 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -11341,12 +11341,20 @@ void MegaApiImpl::sendPendingRequests() } sdkMutex.lock(); - nextTag = client->nextreqtag(); - request->setTag(nextTag); - requestMap[nextTag]=request; - e = API_OK; - fireOnRequestStart(request); + if (!request->getTag()) + { + nextTag = client->nextreqtag(); + request->setTag(nextTag); + requestMap[nextTag]=request; + fireOnRequestStart(request); + } + else + { + nextTag = request->getTag(); + } + + e = API_OK; switch(request->getType()) { case MegaRequest::TYPE_LOGIN: @@ -12686,31 +12694,24 @@ void MegaApiImpl::sendPendingRequests() case MegaRequest::TYPE_CANCEL_TRANSFERS: { int direction = request->getParamType(); + bool flag = request->getFlag(); + if((direction != MegaTransfer::TYPE_DOWNLOAD) && (direction != MegaTransfer::TYPE_UPLOAD)) { e = API_EARGS; break; } - for (transfer_map::iterator it = client->transfers[direction].begin() ; it != client->transfers[direction].end() ; ) + if (!flag) { - Transfer *transfer = it->second; - if(transferMap.find(transfer->tag) != transferMap.end()) + for (transfer_map::iterator it = client->transfers[direction].begin() ; it != client->transfers[direction].end() ; it++) { - MegaTransferPrivate* megaTransfer = transferMap.at(transfer->tag); - megaTransfer->setSyncTransfer(true); - megaTransfer->setLastError(MegaError(API_EINCOMPLETE)); + cancelTransferByTag(it->second->tag); } - - it++; - - file_list files = transfer->files; - file_list::iterator iterator = files.begin(); - while (iterator != files.end()) - { - File *file = *iterator; - iterator++; - if(!file->syncxfer) client->stopxfer(file); - } + request->setFlag(true); + requestQueue.push(request); + } + else + { + fireOnRequestFinish(request, MegaError(API_OK)); } - fireOnRequestFinish(request, MegaError(API_OK)); break; } #ifdef ENABLE_SYNC From a7b2a3f36b35de15cc0ad21d7d85de151d1d0c7c Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Wed, 19 Oct 2016 13:15:33 +0200 Subject: [PATCH 058/103] Formatting --- src/megaapi_impl.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 35b0c4863f..fb6993767f 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -11329,19 +11329,18 @@ void MegaApiImpl::removeRecursively(const char *path) void MegaApiImpl::sendPendingRequests() { - MegaRequestPrivate *request; - error e; + MegaRequestPrivate *request; + error e; int nextTag = 0; - while((request = requestQueue.pop())) - { + while((request = requestQueue.pop())) + { if (!nextTag && request->getType() != MegaRequest::TYPE_LOGOUT) { client->abortbackoff(false); } - sdkMutex.lock(); - + sdkMutex.lock(); if (!request->getTag()) { nextTag = client->nextreqtag(); @@ -11355,17 +11354,17 @@ void MegaApiImpl::sendPendingRequests() } e = API_OK; - switch(request->getType()) - { - case MegaRequest::TYPE_LOGIN: - { - const char *login = request->getEmail(); - const char *password = request->getPassword(); + switch (request->getType()) + { + case MegaRequest::TYPE_LOGIN: + { + const char *login = request->getEmail(); + const char *password = request->getPassword(); const char* megaFolderLink = request->getLink(); const char* base64pwkey = request->getPrivateKey(); const char* sessionKey = request->getSessionKey(); - if(!megaFolderLink && (!(login && password)) && !sessionKey && (!(login && base64pwkey))) + if (!megaFolderLink && (!(login && password)) && !sessionKey && (!(login && base64pwkey))) { e = API_EARGS; break; From e083ab2505c13b418fca77662016c6651e77917e Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Wed, 19 Oct 2016 13:32:33 +0200 Subject: [PATCH 059/103] Added a comment --- src/megaapi_impl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index fb6993767f..3e271abc88 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -11350,6 +11350,7 @@ void MegaApiImpl::sendPendingRequests() } else { + // this case happens when we queue requests already started nextTag = request->getTag(); } From aef4fb7189ce92bcfbe6d3ac1b7aa0ff57c9aadc Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Wed, 19 Oct 2016 20:46:02 +0200 Subject: [PATCH 060/103] included version.h to define SDK version configure modified to load values from this file --- configure.ac | 46 +++++++++++++++++++++++++++++----------------- include/mega.h | 3 +++ include/version.h | 3 +++ 3 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 include/version.h diff --git a/configure.ac b/configure.ac index 619dde8a34..ae9c6ac271 100644 --- a/configure.ac +++ b/configure.ac @@ -31,18 +31,30 @@ AC_PREREQ([2.61]) # The Mega SDK version number is generated into config.h. # The version in Git should reflect the *next* version planned. -m4_define([mega_major_version], [2]) -m4_define([mega_minor_version], [6]) -m4_define([mega_micro_version], [0]) +#~ m4_define([mega_major_version], [m4_esyscmd([cat include/version.h | grep MAJOR | cut -d" " -f 3])]) +#~ m4_define([mega_minor_version], m4_esyscmd([cat include/version.h | grep MINOR | cut -d" " -f 3])) +#~ m4_define([mega_micro_version], [m4_esyscmd(cat include/version.h | grep MICRO | cut -d" " -f 3)]) +m4_define([mega_major_version], [$(cat include/version.h | grep MAJOR | cut -d" " -f 3)]) +m4_define([mega_minor_version], [$(cat include/version.h | grep MINOR | cut -d" " -f 3)]) +m4_define([mega_micro_version], [$(cat include/version.h | grep MICRO | cut -d" " -f 3)]) +#~ m4_define([mega_major_version], [2]) +#~ m4_define([mega_minor_version], [3]) +#~ m4_define([mega_micro_version], [4]) m4_define([mega_version], [mega_major_version.mega_minor_version.mega_micro_version]) # libtool interface versioning m4_define([mega_lt_revision], [0]) -m4_define([mega_lt_current], [m4_eval(100 * mega_minor_version + mega_micro_version)]) +#~ m4_define([mega_lt_current], [$(echo $(( $( cat include/version.h | grep MINOR | cut -d" " -f 3 ) * 100 + $(cat include/version.h | grep MICRO | cut -d" " -f 3))))]) +m4_define([mega_lt_current], [$(echo -n $(( $( cat include/version.h | grep MINOR | cut -d" " -f 3 ) * 100 + $(cat include/version.h | grep MICRO | cut -d" " -f 3))))]) +#~ m4_define([mega_lt_current], [m4_eval(100 * mega_minor_version + mega_micro_version)]) m4_define([mega_lt_age], [0]) -AC_INIT([libmega], [mega_version], [https://github.com/meganz/sdk]) +#~ AC_INIT([libmega], $(echo $(( $( cat include/version.h | grep MAJOR | cut -d" " -f 3 )"."$( cat include/version.h | grep MINOR | cut -d" " -f 3 )"."$(cat include/version.h | grep MICRO | cut -d" " -f 3)))), [https://github.com/meganz/sdk]) +AC_INIT([libmega], m4_esyscmd([ cut -d ' ' -f3 < include/version.h | tr -st '\n' '.' | cut -d '.' -f1,2,3 --output-delimiter='.' | tr -d '\n']), [https://github.com/meganz/sdk]) +#~ AC_INIT([libmega], m4_esyscmd(echo -n 2.5.8), [https://github.com/meganz/sdk]) +#~ AC_INIT([libmega], [mega_version], [https://github.com/meganz/sdk]) +#~ AC_INIT([libmega], [-], [https://github.com/meganz/sdk]) # Define _GNU_SOURCE # AC_GNU_SOURCE @@ -56,20 +68,20 @@ AC_CONFIG_MACRO_DIR([m4]) m4_ifndef([AM_SILENT_RULES], [m4_define([AM_SILENT_RULES],[])]) AM_SILENT_RULES([yes]) -MEGA_MAJOR_VERSION=mega_major_version -MEGA_MINOR_VERSION=mega_minor_version -MEGA_MICRO_VERSION=mega_micro_version +#MEGA_MAJOR_VERSION=mega_major_version +#MEGA_MINOR_VERSION=mega_minor_version +#MEGA_MICRO_VERSION=mega_micro_version -AC_SUBST(MEGA_MAJOR_VERSION) -AC_SUBST(MEGA_MINOR_VERSION) -AC_SUBST(MEGA_MICRO_VERSION) +#AC_SUBST(MEGA_MAJOR_VERSION) +#AC_SUBST(MEGA_MINOR_VERSION) +#AC_SUBST(MEGA_MICRO_VERSION) -AC_DEFINE(MEGA_MAJOR_VERSION, [mega_major_version], - [MEGA SDK major version.]) -AC_DEFINE(MEGA_MINOR_VERSION, [mega_minor_version], - [MEGA SDK minor version.]) -AC_DEFINE(MEGA_MICRO_VERSION, [mega_micro_version], - [MEGA SDK micro version.]) +#AC_DEFINE(MEGA_MAJOR_VERSION, [mega_major_version], +# [MEGA SDK major version.]) +#AC_DEFINE(MEGA_MINOR_VERSION, [mega_minor_version], +# [MEGA SDK minor version.]) +#AC_DEFINE(MEGA_MICRO_VERSION, [mega_micro_version], +# [MEGA SDK micro version.]) LT_CURRENT=mega_lt_current LT_REVISION=mega_lt_revision diff --git a/include/mega.h b/include/mega.h index 79a9c51d8a..49045066f5 100644 --- a/include/mega.h +++ b/include/mega.h @@ -26,6 +26,9 @@ #define MEGA_SDK #endif +// version +#include "version.h" + // project types #include "mega/types.h" diff --git a/include/version.h b/include/version.h new file mode 100644 index 0000000000..de7e8a08d7 --- /dev/null +++ b/include/version.h @@ -0,0 +1,3 @@ +#define MEGA_MAJOR_VERSION 2 +#define MEGA_MINOR_VERSION 7 +#define MEGA_MICRO_VERSION 5 From c0e69d98d805a051276660b3c09e45c1736a4d1f Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Wed, 19 Oct 2016 20:49:15 +0200 Subject: [PATCH 061/103] code cleaned --- configure.ac | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/configure.ac b/configure.ac index ae9c6ac271..3c6b1236ea 100644 --- a/configure.ac +++ b/configure.ac @@ -31,30 +31,20 @@ AC_PREREQ([2.61]) # The Mega SDK version number is generated into config.h. # The version in Git should reflect the *next* version planned. -#~ m4_define([mega_major_version], [m4_esyscmd([cat include/version.h | grep MAJOR | cut -d" " -f 3])]) -#~ m4_define([mega_minor_version], m4_esyscmd([cat include/version.h | grep MINOR | cut -d" " -f 3])) -#~ m4_define([mega_micro_version], [m4_esyscmd(cat include/version.h | grep MICRO | cut -d" " -f 3)]) m4_define([mega_major_version], [$(cat include/version.h | grep MAJOR | cut -d" " -f 3)]) m4_define([mega_minor_version], [$(cat include/version.h | grep MINOR | cut -d" " -f 3)]) m4_define([mega_micro_version], [$(cat include/version.h | grep MICRO | cut -d" " -f 3)]) -#~ m4_define([mega_major_version], [2]) -#~ m4_define([mega_minor_version], [3]) -#~ m4_define([mega_micro_version], [4]) + m4_define([mega_version], [mega_major_version.mega_minor_version.mega_micro_version]) # libtool interface versioning m4_define([mega_lt_revision], [0]) -#~ m4_define([mega_lt_current], [$(echo $(( $( cat include/version.h | grep MINOR | cut -d" " -f 3 ) * 100 + $(cat include/version.h | grep MICRO | cut -d" " -f 3))))]) m4_define([mega_lt_current], [$(echo -n $(( $( cat include/version.h | grep MINOR | cut -d" " -f 3 ) * 100 + $(cat include/version.h | grep MICRO | cut -d" " -f 3))))]) -#~ m4_define([mega_lt_current], [m4_eval(100 * mega_minor_version + mega_micro_version)]) m4_define([mega_lt_age], [0]) -#~ AC_INIT([libmega], $(echo $(( $( cat include/version.h | grep MAJOR | cut -d" " -f 3 )"."$( cat include/version.h | grep MINOR | cut -d" " -f 3 )"."$(cat include/version.h | grep MICRO | cut -d" " -f 3)))), [https://github.com/meganz/sdk]) AC_INIT([libmega], m4_esyscmd([ cut -d ' ' -f3 < include/version.h | tr -st '\n' '.' | cut -d '.' -f1,2,3 --output-delimiter='.' | tr -d '\n']), [https://github.com/meganz/sdk]) -#~ AC_INIT([libmega], m4_esyscmd(echo -n 2.5.8), [https://github.com/meganz/sdk]) -#~ AC_INIT([libmega], [mega_version], [https://github.com/meganz/sdk]) -#~ AC_INIT([libmega], [-], [https://github.com/meganz/sdk]) + # Define _GNU_SOURCE # AC_GNU_SOURCE @@ -68,21 +58,6 @@ AC_CONFIG_MACRO_DIR([m4]) m4_ifndef([AM_SILENT_RULES], [m4_define([AM_SILENT_RULES],[])]) AM_SILENT_RULES([yes]) -#MEGA_MAJOR_VERSION=mega_major_version -#MEGA_MINOR_VERSION=mega_minor_version -#MEGA_MICRO_VERSION=mega_micro_version - -#AC_SUBST(MEGA_MAJOR_VERSION) -#AC_SUBST(MEGA_MINOR_VERSION) -#AC_SUBST(MEGA_MICRO_VERSION) - -#AC_DEFINE(MEGA_MAJOR_VERSION, [mega_major_version], -# [MEGA SDK major version.]) -#AC_DEFINE(MEGA_MINOR_VERSION, [mega_minor_version], -# [MEGA SDK minor version.]) -#AC_DEFINE(MEGA_MICRO_VERSION, [mega_micro_version], -# [MEGA SDK micro version.]) - LT_CURRENT=mega_lt_current LT_REVISION=mega_lt_revision LT_AGE=mega_lt_age From d467c9225975beb423c0f78d9dc5e7490a28cb69 Mon Sep 17 00:00:00 2001 From: polmr Date: Wed, 19 Oct 2016 20:50:03 +0200 Subject: [PATCH 062/103] sdk version set to 2.9.9 --- include/version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/version.h b/include/version.h index de7e8a08d7..677535e78c 100644 --- a/include/version.h +++ b/include/version.h @@ -1,3 +1,3 @@ #define MEGA_MAJOR_VERSION 2 -#define MEGA_MINOR_VERSION 7 -#define MEGA_MICRO_VERSION 5 +#define MEGA_MINOR_VERSION 9 +#define MEGA_MICRO_VERSION 9 From 7e6ec7a0a57193bf88f00bfd36cb78f794d8f260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Hern=C3=A1ndez?= Date: Fri, 21 Oct 2016 11:50:57 +0200 Subject: [PATCH 063/103] Allow no-URL in `mcf` from gettree response API won't return the `url` anymore as part of the `mcf` element in the fetchnodes response. --- src/megaclient.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/megaclient.cpp b/src/megaclient.cpp index f547c1130c..3cba692a8e 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -7186,8 +7186,7 @@ void MegaClient::procmcf(JSON *j) break; case EOO: - if (chatid != UNDEF && priv != PRIV_UNKNOWN && !url.empty() - && shard != -1) + if (chatid != UNDEF && priv != PRIV_UNKNOWN && shard != -1) { TextChat *chat = new TextChat(); chat->id = chatid; From 7f6e8250f8bc9e242814022cc553a93e8e2a52f1 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 21 Oct 2016 12:56:08 +0200 Subject: [PATCH 064/103] moved version.h to mega/version.h updated python scripts to get version from version.h (instead of configure.ac) deleted redundant definitions of versions in config-android.h & win32/megasys.h --- bindings/python/setup.py | 14 +++++++------- configure.ac | 10 +++++----- doc/source/conf.py | 14 +++++++------- include/mega.h | 2 +- include/mega/config-android.h | 9 --------- include/mega/version.h | 9 +++++++++ include/mega/win32/megasys.h | 13 ------------- include/version.h | 3 --- 8 files changed, 29 insertions(+), 45 deletions(-) create mode 100644 include/mega/version.h delete mode 100644 include/version.h diff --git a/bindings/python/setup.py b/bindings/python/setup.py index 8ae6192e4c..40a4d61076 100644 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -23,13 +23,13 @@ def get_version(): """ Grabs and returns the version and release numbers from autotools. """ - configure_ac = open(os.path.join('..', '..', 'configure.ac')).read() - major = re.search('m4_define\(\[mega_major_version\], \[([0-9]+)\]', - configure_ac) - minor = re.search('m4_define\(\[mega_minor_version\], \[([0-9]+)\]', - configure_ac) - micro = re.search('m4_define\(\[mega_micro_version\], \[(.+?)\]', - configure_ac) + version_h = open(os.path.join('..', '..', 'include', 'mega', 'version.h')).read() + major = re.search('define MEGA_MAJOR_VERSION ([0-9]+)', + version_h) + minor = re.search('define MEGA_MINOR_VERSION ([0-9]+)', + version_h) + micro = re.search('define MEGA_MICRO_VERSION (.+?)', + version_h) if major: major, minor, micro = major.group(1), minor.group(1), micro.group(1) version = '.'.join([major, minor]) diff --git a/configure.ac b/configure.ac index 3c6b1236ea..91abc02d9e 100644 --- a/configure.ac +++ b/configure.ac @@ -31,19 +31,19 @@ AC_PREREQ([2.61]) # The Mega SDK version number is generated into config.h. # The version in Git should reflect the *next* version planned. -m4_define([mega_major_version], [$(cat include/version.h | grep MAJOR | cut -d" " -f 3)]) -m4_define([mega_minor_version], [$(cat include/version.h | grep MINOR | cut -d" " -f 3)]) -m4_define([mega_micro_version], [$(cat include/version.h | grep MICRO | cut -d" " -f 3)]) +m4_define([mega_major_version], [$(cat include/mega/version.h | grep "define MEGA_MAJOR" | cut -d" " -f 3)]) +m4_define([mega_minor_version], [$(cat include/mega/version.h | grep "define MEGA_MINOR" | cut -d" " -f 3)]) +m4_define([mega_micro_version], [$(cat include/mega/version.h | grep "define MEGA_MICRO" | cut -d" " -f 3)]) m4_define([mega_version], [mega_major_version.mega_minor_version.mega_micro_version]) # libtool interface versioning m4_define([mega_lt_revision], [0]) -m4_define([mega_lt_current], [$(echo -n $(( $( cat include/version.h | grep MINOR | cut -d" " -f 3 ) * 100 + $(cat include/version.h | grep MICRO | cut -d" " -f 3))))]) +m4_define([mega_lt_current], [$(echo -n $(( $( cat include/mega/version.h | grep "define MEGA_MAJOR" | cut -d" " -f 3 ) * 10000 + $( cat include/mega/version.h | grep "define MEGA_MINOR" | cut -d" " -f 3 ) * 100 + $(cat include/mega/version.h | grep "define MEGA_MICRO" | cut -d" " -f 3))))]) m4_define([mega_lt_age], [0]) -AC_INIT([libmega], m4_esyscmd([ cut -d ' ' -f3 < include/version.h | tr -st '\n' '.' | cut -d '.' -f1,2,3 --output-delimiter='.' | tr -d '\n']), [https://github.com/meganz/sdk]) +AC_INIT([libmega], m4_esyscmd([ grep define < include/mega/version.h | cut -d ' ' -f3 | tr -st '\n' '.' | cut -d '.' -f1,2,3 --output-delimiter='.' | tr -d '\n']), [https://github.com/meganz/sdk]) # Define _GNU_SOURCE diff --git a/doc/source/conf.py b/doc/source/conf.py index 7e97bc2362..af2cb575be 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -52,13 +52,13 @@ def get_versions(): Grabs and returns the version and release numbers from autotools. """ import re - configure_ac = open(os.path.join('..', '..', 'configure.ac')).read() - major = re.search('m4_define\(\[mega_major_version\], \[([0-9]+)\]', - configure_ac) - minor = re.search('m4_define\(\[mega_minor_version\], \[([0-9]+)\]', - configure_ac) - micro = re.search('m4_define\(\[mega_micro_version\], \[(.+?)\]', - configure_ac) + version_h = open(os.path.join('..', '..', 'include', 'mega', 'version.h')).read() + major = re.search('define MEGA_MAJOR_VERSION ([0-9]+)', + version_h) + minor = re.search('define MEGA_MINOR_VERSION ([0-9]+)', + version_h) + micro = re.search('define MEGA_MICRO_VERSION (.+?)', + version_h) if major: major, minor, micro = major.group(1), minor.group(1), micro.group(1) version = '.'.join([major, minor]) diff --git a/include/mega.h b/include/mega.h index 49045066f5..e9f4c2bb84 100644 --- a/include/mega.h +++ b/include/mega.h @@ -27,7 +27,7 @@ #endif // version -#include "version.h" +#include "mega/version.h" // project types #include "mega/types.h" diff --git a/include/mega/config-android.h b/include/mega/config-android.h index 79d5276f47..cc213e822c 100644 --- a/include/mega/config-android.h +++ b/include/mega/config-android.h @@ -111,15 +111,6 @@ */ #define LT_OBJDIR ".libs/" -/* MEGA SDK major version. */ -#define MEGA_MAJOR_VERSION 2 - -/* MEGA SDK micro version. */ -#define MEGA_MICRO_VERSION 0 - -/* MEGA SDK minor version. */ -#define MEGA_MINOR_VERSION 6 - /* Name of package */ #define PACKAGE "libmega" diff --git a/include/mega/version.h b/include/mega/version.h new file mode 100644 index 0000000000..4aad975fce --- /dev/null +++ b/include/mega/version.h @@ -0,0 +1,9 @@ +#ifndef MEGA_MAJOR_VERSION + #define MEGA_MAJOR_VERSION 2 +#endif +#ifndef MEGA_MINOR_VERSION + #define MEGA_MINOR_VERSION 6 +#endif +#ifndef MEGA_MICRO_VERSION + #define MEGA_MICRO_VERSION 0 +#endif diff --git a/include/mega/win32/megasys.h b/include/mega/win32/megasys.h index cf2b077f41..436fcb6fbc 100644 --- a/include/mega/win32/megasys.h +++ b/include/mega/win32/megasys.h @@ -86,19 +86,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -// FIXME: move to auto-generated file -#ifndef MEGA_MAJOR_VERSION - #define MEGA_MAJOR_VERSION 2 -#endif - -#ifndef MEGA_MINOR_VERSION - #define MEGA_MINOR_VERSION 6 -#endif - -#ifndef MEGA_MICRO_VERSION - #define MEGA_MICRO_VERSION 0 -#endif - #include #endif diff --git a/include/version.h b/include/version.h deleted file mode 100644 index 677535e78c..0000000000 --- a/include/version.h +++ /dev/null @@ -1,3 +0,0 @@ -#define MEGA_MAJOR_VERSION 2 -#define MEGA_MINOR_VERSION 9 -#define MEGA_MICRO_VERSION 9 From 92d55afd93035995c55354038209c06a55b18061 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Fri, 21 Oct 2016 13:09:06 +0200 Subject: [PATCH 065/103] Update version.h --- include/mega/version.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/mega/version.h b/include/mega/version.h index 4aad975fce..ed3528f181 100644 --- a/include/mega/version.h +++ b/include/mega/version.h @@ -1,9 +1,9 @@ #ifndef MEGA_MAJOR_VERSION - #define MEGA_MAJOR_VERSION 2 +#define MEGA_MAJOR_VERSION 2 #endif #ifndef MEGA_MINOR_VERSION - #define MEGA_MINOR_VERSION 6 +#define MEGA_MINOR_VERSION 6 #endif #ifndef MEGA_MICRO_VERSION - #define MEGA_MICRO_VERSION 0 +#define MEGA_MICRO_VERSION 0 #endif From c1f41909bc8949ec1d8f37ca3006faf271c864f4 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Fri, 21 Oct 2016 13:37:04 +0200 Subject: [PATCH 066/103] Copy child nodes only when needed --- include/megaapi_impl.h | 6 ++-- src/megaapi_impl.cpp | 68 +++++++++++++++++++++++++++++------------- 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/include/megaapi_impl.h b/include/megaapi_impl.h index 474cff4514..145e55f85a 100644 --- a/include/megaapi_impl.h +++ b/include/megaapi_impl.h @@ -410,7 +410,7 @@ class MegaTransferPrivate : public MegaTransfer, public Cachable void setSpeed(long long speed); void setDeltaSize(long long deltaSize); void setUpdateTime(int64_t updateTime); - void setPublicNode(MegaNode *publicNode); + void setPublicNode(MegaNode *publicNode, bool copyChildren = false); void setSyncTransfer(bool syncTransfer); void setSourceFileTemporary(bool temporary); void setStreamingTransfer(bool streamingTransfer); @@ -611,7 +611,7 @@ class MegaRequestPrivate : public MegaRequest void setAccess(int access); void setNumRetry(int ds); void setNextRetryDelay(int delay); - void setPublicNode(MegaNode* publicNode); + void setPublicNode(MegaNode* publicNode, bool copyChildren = false); void setNumDetails(int numDetails); void setFile(const char* file); void setParamType(int type); @@ -976,13 +976,13 @@ class MegaNodeListPrivate : public MegaNodeList public: MegaNodeListPrivate(); MegaNodeListPrivate(Node** newlist, int size); + MegaNodeListPrivate(MegaNodeListPrivate *nodeList, bool copyChildren = false); virtual ~MegaNodeListPrivate(); virtual MegaNodeList *copy(); virtual MegaNode* get(int i); virtual int size(); protected: - MegaNodeListPrivate(MegaNodeListPrivate *nodeList); MegaNode** list; int s; }; diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 3e271abc88..01f3ca4529 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -143,12 +143,7 @@ MegaNodePrivate::MegaNodePrivate(MegaNode *node) this->inShare = node->isInShare(); this->foreign = node->isForeign(); this->sharekey = NULL; - - this->children = node->getChildren(); - if (this->children) - { - this->children = this->children->copy(); - } + this->children = NULL; if (node->isExported()) { @@ -1705,15 +1700,27 @@ void MegaTransferPrivate::setUpdateTime(int64_t updateTime) { this->updateTime = updateTime; } -void MegaTransferPrivate::setPublicNode(MegaNode *publicNode) +void MegaTransferPrivate::setPublicNode(MegaNode *publicNode, bool copyChildren) { - if(this->publicNode) + if (this->publicNode) + { delete this->publicNode; + } - if(!publicNode) + if (!publicNode) + { this->publicNode = NULL; + } else - this->publicNode = publicNode->copy(); + { + MegaNodePrivate *nodePrivate = new MegaNodePrivate(publicNode); + MegaNodeListPrivate *children = dynamic_cast(publicNode->getChildren()); + if (children && copyChildren) + { + nodePrivate->setChildren(new MegaNodeListPrivate(children, true)); + } + this->publicNode = nodePrivate; + } } void MegaTransferPrivate::setSyncTransfer(bool syncTransfer) @@ -2493,15 +2500,27 @@ Proxy *MegaRequestPrivate::getProxy() return proxy; } -void MegaRequestPrivate::setPublicNode(MegaNode *publicNode) +void MegaRequestPrivate::setPublicNode(MegaNode *publicNode, bool copyChildren) { - if(this->publicNode) + if (this->publicNode) + { delete this->publicNode; + } - if(!publicNode) + if (!publicNode) + { this->publicNode = NULL; + } else - this->publicNode = publicNode->copy(); + { + MegaNodePrivate *nodePrivate = new MegaNodePrivate(publicNode); + MegaNodeListPrivate *children = dynamic_cast(publicNode->getChildren()); + if (children && copyChildren) + { + nodePrivate->setChildren(new MegaNodeListPrivate(children, true)); + } + this->publicNode = nodePrivate; + } } const char *MegaRequestPrivate::getRequestString() const @@ -2773,7 +2792,7 @@ MegaNodeListPrivate::MegaNodeListPrivate(Node** newlist, int size) list[i] = MegaNodePrivate::fromNode(newlist[i]); } -MegaNodeListPrivate::MegaNodeListPrivate(MegaNodeListPrivate *nodeList) +MegaNodeListPrivate::MegaNodeListPrivate(MegaNodeListPrivate *nodeList, bool copyChildren) { s = nodeList->size(); if (!s) @@ -2784,7 +2803,16 @@ MegaNodeListPrivate::MegaNodeListPrivate(MegaNodeListPrivate *nodeList) list = new MegaNode*[s]; for (int i = 0; iget(i)); + { + MegaNode *node = nodeList->get(i); + MegaNodePrivate *nodePrivate = new MegaNodePrivate(node); + MegaNodeListPrivate *children = dynamic_cast(node->getChildren()); + if (children && copyChildren) + { + nodePrivate->setChildren(new MegaNodeListPrivate(children, true)); + } + list[i] = nodePrivate; + } } MegaNodeListPrivate::~MegaNodeListPrivate() @@ -4297,7 +4325,7 @@ void MegaApiImpl::copyNode(MegaNode *node, MegaNode* target, MegaRequestListener MegaRequestPrivate *request = new MegaRequestPrivate(MegaRequest::TYPE_COPY, listener); if (node) { - request->setPublicNode(node); + request->setPublicNode(node, true); request->setNodeHandle(node->getHandle()); } if(target) request->setParentHandle(target->getHandle()); @@ -4310,7 +4338,7 @@ void MegaApiImpl::copyNode(MegaNode *node, MegaNode *target, const char *newName MegaRequestPrivate *request = new MegaRequestPrivate(MegaRequest::TYPE_COPY, listener); if (node) { - request->setPublicNode(node); + request->setPublicNode(node, true); request->setNodeHandle(node->getHandle()); } if(target) request->setParentHandle(target->getHandle()); @@ -4353,7 +4381,7 @@ void MegaApiImpl::sendFileToUser(MegaNode *node, const char* email, MegaRequestL MegaRequestPrivate *request = new MegaRequestPrivate(MegaRequest::TYPE_COPY, listener); if (node) { - request->setPublicNode(node); + request->setPublicNode(node, true); request->setNodeHandle(node->getHandle()); } request->setEmail(email); @@ -5334,7 +5362,7 @@ void MegaApiImpl::startDownload(MegaNode *node, const char* localPath, long /*st transfer->setNodeHandle(node->getHandle()); if (node->isPublic() || node->isForeign()) { - transfer->setPublicNode(node); + transfer->setPublicNode(node, true); } } From ea367dc0b927f63d7b858543544496754f03bdf3 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Fri, 21 Oct 2016 13:39:05 +0200 Subject: [PATCH 067/103] Formatting --- src/megaapi_impl.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 01f3ca4529..86d287cf77 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -2795,14 +2795,14 @@ MegaNodeListPrivate::MegaNodeListPrivate(Node** newlist, int size) MegaNodeListPrivate::MegaNodeListPrivate(MegaNodeListPrivate *nodeList, bool copyChildren) { s = nodeList->size(); - if (!s) - { - list = NULL; - return; - } + if (!s) + { + list = NULL; + return; + } - list = new MegaNode*[s]; - for (int i = 0; iget(i); MegaNodePrivate *nodePrivate = new MegaNodePrivate(node); From b43cad5dc30b13f3e52ad091fc5df86e69244157 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Sat, 22 Oct 2016 16:36:33 +0200 Subject: [PATCH 068/103] Skip transfers of already downloaded files --- src/megaapi_impl.cpp | 116 +++++++++++++++++++++++++++---------------- 1 file changed, 73 insertions(+), 43 deletions(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 86d287cf77..2da0ddf385 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -11172,7 +11172,6 @@ void MegaApiImpl::sendPendingTransfers() } // File download - currentTransfer=transfer; if (!transfer->isStreamingTransfer()) { string name; @@ -11218,7 +11217,6 @@ void MegaApiImpl::sendPendingTransfers() client->fsaccess->name2local(&name); client->fsaccess->local2path(&name, &securename); path += securename; - f = new MegaFileGet(client, node, path); } else { @@ -11234,6 +11232,78 @@ void MegaApiImpl::sendPendingTransfers() client->fsaccess->name2local(&name); client->fsaccess->local2path(&name, &securename); path += securename; + } + + string wLocalPath; + FileFingerprint *prevFp = NULL; + m_off_t size = 0; + fsAccess->path2local(&path, &wLocalPath); + FileAccess *fa = fsAccess->newfileaccess(); + if (fa->fopen(&wLocalPath, true, false)) + { + if (node) + { + prevFp = node; + size = node->size; + } + else + { + const char *fpstring = publicNode->getFingerprint(); + prevFp = getFileFingerprintInternal(fpstring); + size = publicNode->getSize(); + } + + bool duplicate = false; + if (prevFp && prevFp->isvalid) + { + FileFingerprint fp; + fp.genfingerprint(fa); + if (fp == *prevFp) + { + duplicate = true; + } + } + else if (fa->size == size) + { + duplicate = true; + } + + if (duplicate) + { + transferMap[nextTag] = transfer; + transfer->setTag(nextTag); + transfer->setTotalBytes(fa->size); + transfer->setTransferredBytes(fa->size); + transfer->setPath(path.c_str()); + fireOnTransferStart(transfer); + if (node) + { + transfer->setNodeHandle(node->nodehandle); + } + else + { + transfer->setNodeHandle(publicNode->getHandle()); + delete prevFp; + } + transfer->setDeltaSize(fa->size); + transfer->setSpeed(0); + transfer->setStartTime(Waiter::ds); + transfer->setUpdateTime(Waiter::ds); + fireOnTransferFinish(transfer, MegaError(API_OK)); + delete fa; + break; + } + } + delete fa; + + currentTransfer = transfer; + if (node) + { + f = new MegaFileGet(client, node, path); + } + else + { + delete prevFp; f = new MegaFileGet(client, publicNode, path); } @@ -11276,6 +11346,7 @@ void MegaApiImpl::sendPendingTransfers() } else { + currentTransfer = transfer; m_off_t startPos = transfer->getStartPos(); m_off_t endPos = transfer->getEndPos(); if (startPos < 0 || endPos < 0 || startPos > endPos) @@ -14844,7 +14915,6 @@ void MegaFolderDownloadController::downloadFolderNode(MegaNode *node, string *pa int l = localpath.size(); string name = child->getName(); - int64_t size = child->getSize(); client->fsaccess->name2local(&name); localpath.append(name); @@ -14854,46 +14924,6 @@ void MegaFolderDownloadController::downloadFolderNode(MegaNode *node, string *pa if (child->getType() == MegaNode::TYPE_FILE) { pendingTransfers++; - FileAccess *fa = NULL; - fa = client->fsaccess->newfileaccess(); - - if (fa->fopen(&localpath, true, false) && fa->type == FILENODE) - { - const char *fpLocal = megaApi->getFingerprint(localpath.c_str()); - const char *fpRemote = megaApi->getFingerprint(child); - - if ((fpLocal && fpRemote && !strcmp(fpLocal,fpRemote)) - || (!fpRemote && size == fa->size - && child->getModificationTime() == fa->mtime)) - { - delete [] fpLocal; - delete [] fpRemote; - - LOG_debug << "Already downloaded file detected: " << utf8path; - int nextTag = client->nextreqtag(); - MegaTransferPrivate* t = new MegaTransferPrivate(MegaTransfer::TYPE_DOWNLOAD, this); - - t->setPath(utf8path.data()); - t->setNodeHandle(child->getHandle()); - - t->setTag(nextTag); - t->setFolderTransferTag(tag); - t->setTotalBytes(size); - megaApi->transferMap[nextTag] = t; - megaApi->fireOnTransferStart(t); - - t->setTransferredBytes(size); - t->setDeltaSize(size); - megaApi->fireOnTransferFinish(t, MegaError(API_OK)); - localpath.resize(l); - delete fa; - continue; - } - delete [] fpLocal; - delete [] fpRemote; - } - delete fa; - megaApi->startDownload(child, utf8path.c_str(), 0, 0, tag, NULL, this); } else From ba9194b6349a1db635036305a46be036c1c30df0 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Sat, 22 Oct 2016 22:15:41 +0200 Subject: [PATCH 069/103] Simplified the implementation of the lock request --- include/mega/http.h | 5 ++- include/mega/megaclient.h | 3 +- src/http.cpp | 6 ++++ src/megaclient.cpp | 74 ++++++++++++++++++--------------------- 4 files changed, 46 insertions(+), 42 deletions(-) diff --git a/include/mega/http.h b/include/mega/http.h index f0270d5468..e4ca38d63d 100644 --- a/include/mega/http.h +++ b/include/mega/http.h @@ -118,7 +118,10 @@ struct MEGA_API HttpIO : public EventTrigger dstime lastdata; // data receive timeout - static const int NETWORKTIMEOUT = 1200; + static const int NETWORKTIMEOUT; + + // request timeout + static const int REQUESTTIMEOUT; // set useragent (must be called exactly once) virtual void setuseragent(string*) = 0; diff --git a/include/mega/megaclient.h b/include/mega/megaclient.h index 83a90e91a0..b69e2de962 100644 --- a/include/mega/megaclient.h +++ b/include/mega/megaclient.h @@ -821,8 +821,7 @@ class MEGA_API MegaClient void setchunkfailed(string*); string badhosts; - string workinglockResponse; - bool doAskForWorkingLock = false; + bool requestLock; // process object arrays by the API server int readnodes(JSON*, int, putsource_t = PUTNODES_APP, NewNode* = NULL, int = 0, int = 0); diff --git a/src/http.cpp b/src/http.cpp index 33b8cb6475..567a599f31 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -25,6 +25,12 @@ namespace mega { +// data receive timeout +const int HttpIO::NETWORKTIMEOUT = 6000; + +// request timeout +const int HttpIO::REQUESTTIMEOUT = 1200; + #ifdef _WIN32 const char* mega_inet_ntop(int af, const void* src, char* dst, int cnt) { diff --git a/src/megaclient.cpp b/src/megaclient.cpp index be9a159394..d9a885f9d3 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -683,6 +683,7 @@ void MegaClient::init() csretrying = false; chunkfailed = false; statecurrent = false; + requestLock = false; totalNodes = 0; #ifdef ENABLE_SYNC @@ -866,34 +867,18 @@ void MegaClient::exec() abortbackoff(overquotauntil <= Waiter::ds); } - if (EVER(httpio->lastdata) && pendingcs && !fetchingnodes && Waiter::ds >= httpio->lastdata + HttpIO::NETWORKTIMEOUT) + if (EVER(httpio->lastdata) && Waiter::ds >= httpio->lastdata + HttpIO::NETWORKTIMEOUT + && !pendingcs) { - if (!workinglockcs && !doAskForWorkingLock && workinglockResponse.empty() && btworkinglock.armed()) - { - LOG_err << "Timeout passed. Triggering petition for working lock ... "; - doAskForWorkingLock = true; - } - - if (workinglockResponse == "0") //not locked - { - LOG_fatal << "Disconnecting due to timeout (server idle)"; - disconnect(); - //TODO: send report - } - else if (workinglockResponse == "1") - { - LOG_warn << "Timeout not causing disconnect. The server reports writting lock (server is doing something for us. It's ok to wait') "; - //TODO: send report - } - else if (!workinglockResponse.empty()) - { - LOG_err << "Unexpected working lock response: " << workinglockResponse; - } + LOG_debug << "Network timeout. Reconnecting"; + disconnect(); } - if (!workinglockResponse.empty()) + if (EVER(httpio->lastdata) && Waiter::ds >= httpio->lastdata + HttpIO::REQUESTTIMEOUT + && pendingcs && !fetchingnodes && !workinglockcs) { - workinglockResponse.clear(); + LOG_debug << "Request timeout. Triggering a lock request"; + requestLock = true; } // successful network operation with a failed transfer chunk: increment error count @@ -1398,18 +1383,31 @@ void MegaClient::exec() { if (workinglockcs->status == REQ_SUCCESS) { - LOG_debug << "Successful requested working lock. Result=" << workinglockcs->in; + LOG_debug << "Successful lock request"; btworkinglock.reset(); - btworkinglock.backoff(600); //leave the api be for a while - workinglockResponse = workinglockcs->in; + + if (workinglockcs->in == "1") + { + LOG_warn << "Disconnecting due to timeout (server idle)"; + disconnect(); + } + else if (workinglockcs->in == "0") + { + LOG_debug << "Timeout not causing disconnect (server busy)"; + } + else + { + LOG_err << "Error in lock request: " << workinglockcs->in; + } + delete workinglockcs; workinglockcs = NULL; + requestLock = false; } else if(workinglockcs->status == REQ_FAILURE) { - LOG_warn << "Failed requested working lock. Retrying..."; - btworkinglock.backoff(600); //leave the api be for a while - doAskForWorkingLock = true; + LOG_warn << "Failed lock request. Retrying..."; + btworkinglock.backoff(); delete workinglockcs; workinglockcs = NULL; } @@ -1929,9 +1927,9 @@ void MegaClient::exec() badhosts.clear(); } - if (!workinglockcs && doAskForWorkingLock && btworkinglock.armed()) + if (!workinglockcs && requestLock && btworkinglock.armed()) { - LOG_debug << "Sending workinglock petition: " << workinglockResponse; + LOG_debug << "Sending lock request"; workinglockcs = new HttpReq(); workinglockcs->posturl = APIURL; workinglockcs->posturl.append("cs?"); @@ -1939,8 +1937,6 @@ void MegaClient::exec() workinglockcs->posturl.append("&wlt=1"); workinglockcs->type = REQ_JSON; workinglockcs->post(this); - workinglockResponse.clear(); - doAskForWorkingLock = false; } } while (httpio->doio() || execdirectreads() || (!pendingcs && reqs.cmdspending() && btcs.armed()) || looprequested); } @@ -2010,13 +2006,13 @@ int MegaClient::preparewait() // retry failed badhost requests if (!badhostcs) { - btbadhost.update(&nds); //TODO: this can produce segfault if ocurred after reset() + btbadhost.update(&nds); } -// if (!workinglockcs) -// { -// btworkinglock.update(&nds); -// } + if (!workinglockcs) + { + btworkinglock.update(&nds); + } // retry failed file attribute puts if (curfa == newfa.end()) From f0f2305f4d3c0f60dba32f0eeb560e06e55d58f3 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Sat, 22 Oct 2016 22:22:24 +0200 Subject: [PATCH 070/103] Minor fix --- src/megaclient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/megaclient.cpp b/src/megaclient.cpp index d9a885f9d3..95db754543 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -875,7 +875,7 @@ void MegaClient::exec() } if (EVER(httpio->lastdata) && Waiter::ds >= httpio->lastdata + HttpIO::REQUESTTIMEOUT - && pendingcs && !fetchingnodes && !workinglockcs) + && pendingcs && !fetchingnodes && !requestLock) { LOG_debug << "Request timeout. Triggering a lock request"; requestLock = true; From 6e19e3ce9829a20b5565115a3c94163c988d6197 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Sat, 22 Oct 2016 23:47:08 +0200 Subject: [PATCH 071/103] Restore default permissions --- src/posix/fs.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/posix/fs.cpp b/src/posix/fs.cpp index 2b273043d3..f1e6b33ad3 100644 --- a/src/posix/fs.cpp +++ b/src/posix/fs.cpp @@ -247,8 +247,19 @@ bool PosixFileAccess::fopen(string* f, bool read, bool write) } #endif + mode_t mode; + if (write) + { + mode = umask(0); + } + if ((fd = open(f->c_str(), write ? (read ? O_RDWR : O_WRONLY | O_CREAT) : O_RDONLY, defaultfilepermissions)) >= 0) { + if (write) + { + umask(mode); + } + if (!fstat(fd, &statbuf)) { #ifdef __MACH__ @@ -274,6 +285,10 @@ bool PosixFileAccess::fopen(string* f, bool read, bool write) close(fd); } + else if (write) + { + umask(mode); + } return false; } @@ -288,7 +303,6 @@ PosixFileSystemAccess::PosixFileSystemAccess(int fseventsfd) defaultfilepermissions = 0600; defaultfolderpermissions = 0700; - umask(000); localseparator = "/"; @@ -778,8 +792,10 @@ bool PosixFileSystemAccess::copylocal(string* oldname, string* newname, m_time_t if ((sfd = open(oldname->c_str(), O_RDONLY | O_DIRECT)) >= 0) { LOG_verbose << "Copying via sendfile"; + mode_t mode = umask(0); if ((tfd = open(newname->c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_DIRECT, defaultfilepermissions)) >= 0) { + umask(mode); while ((t = sendfile(tfd, sfd, NULL, 1024 * 1024 * 1024)) > 0); #else char buf[16384]; @@ -787,14 +803,17 @@ bool PosixFileSystemAccess::copylocal(string* oldname, string* newname, m_time_t if ((sfd = open(oldname->c_str(), O_RDONLY)) >= 0) { LOG_verbose << "Copying via read/write"; + mode_t mode = umask(0); if ((tfd = open(newname->c_str(), O_WRONLY | O_CREAT | O_TRUNC, defaultfilepermissions)) >= 0) { + umask(mode); while (((t = read(sfd, buf, sizeof buf)) > 0) && write(tfd, buf, t) == t); #endif close(tfd); } else { + umask(mode); target_exists = errno == EEXIST; transient_error = errno == ETXTBSY || errno == EBUSY; @@ -984,7 +1003,9 @@ bool PosixFileSystemAccess::mkdirlocal(string* name, bool) } #endif + mode_t mode = umask(0); bool r = !mkdir(name->c_str(), defaultfolderpermissions); + umask(mode); if (!r) { From 84a0bad4bae52f464ab428eeecc052ca3673263d Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Mon, 24 Oct 2016 10:46:03 +0200 Subject: [PATCH 072/103] Added a timeout for the lock request --- include/mega/megaclient.h | 2 ++ src/megaclient.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/mega/megaclient.h b/include/mega/megaclient.h index b69e2de962..dd8b9ee268 100644 --- a/include/mega/megaclient.h +++ b/include/mega/megaclient.h @@ -823,6 +823,8 @@ class MEGA_API MegaClient bool requestLock; + m_time_t requestLockTimestamp; + // process object arrays by the API server int readnodes(JSON*, int, putsource_t = PUTNODES_APP, NewNode* = NULL, int = 0, int = 0); diff --git a/src/megaclient.cpp b/src/megaclient.cpp index 95db754543..5105749aaa 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -684,6 +684,7 @@ void MegaClient::init() chunkfailed = false; statecurrent = false; requestLock = false; + requestLockTimestamp = 0; totalNodes = 0; #ifdef ENABLE_SYNC @@ -1403,13 +1404,16 @@ void MegaClient::exec() delete workinglockcs; workinglockcs = NULL; requestLock = false; + requestLockTimestamp = 0; } - else if(workinglockcs->status == REQ_FAILURE) + else if (workinglockcs->status == REQ_FAILURE + || (workinglockcs->status == REQ_INFLIGHT && Waiter::ds >= requestLockTimestamp + HttpIO::REQUESTTIMEOUT)) { LOG_warn << "Failed lock request. Retrying..."; btworkinglock.backoff(); delete workinglockcs; workinglockcs = NULL; + requestLockTimestamp = 0; } } @@ -1937,6 +1941,7 @@ void MegaClient::exec() workinglockcs->posturl.append("&wlt=1"); workinglockcs->type = REQ_JSON; workinglockcs->post(this); + requestLockTimestamp = Waiter::ds; } } while (httpio->doio() || execdirectreads() || (!pendingcs && reqs.cmdspending() && btcs.armed()) || looprequested); } From 7a760ccb3db4f75ee66dfd0608824873d191717c Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Mon, 24 Oct 2016 10:46:31 +0200 Subject: [PATCH 073/103] Stop the lock request ondisconnect() --- src/megaclient.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/megaclient.cpp b/src/megaclient.cpp index 5105749aaa..84a61c8c67 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -2584,6 +2584,15 @@ void MegaClient::disconnect() pendingsc->disconnect(); } + if (workinglockcs) + { + btworkinglock.reset(); + delete workinglockcs; + workinglockcs = NULL; + requestLock = false; + requestLockTimestamp = 0; + } + for (transferslot_list::iterator it = tslots.begin(); it != tslots.end(); it++) { (*it)->disconnect(); From 82995c49315e99d60e0504c67a930b74e3fac2da Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Mon, 24 Oct 2016 10:46:58 +0200 Subject: [PATCH 074/103] Send events related to the lock request --- src/megaclient.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/megaclient.cpp b/src/megaclient.cpp index 84a61c8c67..39c479e530 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -1389,12 +1389,19 @@ void MegaClient::exec() if (workinglockcs->in == "1") { - LOG_warn << "Disconnecting due to timeout (server idle)"; + int creqtag = reqtag; + reqtag = 0; + sendevent(99424, "Timeout (server idle)"); + reqtag = creqtag; + disconnect(); } else if (workinglockcs->in == "0") { - LOG_debug << "Timeout not causing disconnect (server busy)"; + int creqtag = reqtag; + reqtag = 0; + sendevent(99425, "Timeout (server busy)"); + reqtag = creqtag; } else { From b58e026c9f163c82cae0443373d0be0e221300b8 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Mon, 24 Oct 2016 10:47:22 +0200 Subject: [PATCH 075/103] Fixed backoffs --- src/megaclient.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/megaclient.cpp b/src/megaclient.cpp index 39c479e530..b6f695a1d6 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -2016,12 +2016,12 @@ int MegaClient::preparewait() } // retry failed badhost requests - if (!badhostcs) + if (!badhostcs && badhosts.size()) { btbadhost.update(&nds); } - if (!workinglockcs) + if (!workinglockcs && requestLock) { btworkinglock.update(&nds); } From 6f567dbaddbcace0dd3a1322fb59f4877b50f9f3 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Mon, 24 Oct 2016 12:17:18 +0200 Subject: [PATCH 076/103] Abort the lock request when the ongoing request continues --- include/mega/http.h | 2 +- include/mega/megaclient.h | 3 +++ src/http.cpp | 2 ++ src/megaapi_impl.cpp | 15 ++++++--------- src/megaclient.cpp | 30 +++++++++++++++++++++--------- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/include/mega/http.h b/include/mega/http.h index e4ca38d63d..0d208531bc 100644 --- a/include/mega/http.h +++ b/include/mega/http.h @@ -161,7 +161,7 @@ struct MEGA_API HttpReq string chunkedout; byte* buf; - m_off_t buflen, bufpos; + m_off_t buflen, bufpos, notifiedbufpos; // we assume that API responses are smaller than 4 GB m_off_t contentlength; diff --git a/include/mega/megaclient.h b/include/mega/megaclient.h index dd8b9ee268..5a7692d540 100644 --- a/include/mega/megaclient.h +++ b/include/mega/megaclient.h @@ -243,6 +243,9 @@ class MEGA_API MegaClient // close all open HTTP connections void disconnect(); + // abort lock request + void abortlockrequest(); + // abort session and free all state information void logout(); diff --git a/src/http.cpp b/src/http.cpp index 567a599f31..d85b845ff4 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -289,6 +289,7 @@ void HttpReq::post(MegaClient* client, const char* data, unsigned len) httpio = client->httpio; bufpos = 0; + notifiedbufpos = 0; inpurge = 0; contentlength = -1; @@ -356,6 +357,7 @@ void HttpReq::init() inpurge = 0; sslcheckfailed = false; bufpos = 0; + notifiedbufpos = 0; contentlength = 0; timeleft = -1; lastdata = 0; diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 81d7c0fa2f..2cfa5c78b6 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -8889,20 +8889,17 @@ void MegaApiImpl::request_error(error e) void MegaApiImpl::request_response_progress(m_off_t currentProgress, m_off_t totalProgress) { - if(requestMap.size() == 1) + if (requestMap.size() == 1) { MegaRequestPrivate *request = requestMap.begin()->second; - if(request && request->getType() == MegaRequest::TYPE_FETCH_NODES) + if (request && request->getType() == MegaRequest::TYPE_FETCH_NODES) { - if(request->getTransferredBytes() != currentProgress) + request->setTransferredBytes(currentProgress); + if (totalProgress != -1) { - request->setTransferredBytes(currentProgress); - if(totalProgress != -1) - { - request->setTotalBytes(totalProgress); - } - fireOnRequestUpdate(request); + request->setTotalBytes(totalProgress); } + fireOnRequestUpdate(request); } } } diff --git a/src/megaclient.cpp b/src/megaclient.cpp index b6f695a1d6..fbe5c1b501 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -1101,11 +1101,17 @@ void MegaClient::exec() case REQ_INFLIGHT: if (pendingcs->contentlength > 0) { - app->request_response_progress(pendingcs->bufpos, pendingcs->contentlength); + if (pendingcs->bufpos > pendingcs->notifiedbufpos) + { + abortlockrequest(); + app->request_response_progress(pendingcs->bufpos, pendingcs->contentlength); + pendingcs->notifiedbufpos = pendingcs->bufpos; + } } break; case REQ_SUCCESS: + abortlockrequest(); app->request_response_progress(pendingcs->bufpos, -1); if (pendingcs->in != "-3" && pendingcs->in != "-4") @@ -1160,6 +1166,7 @@ void MegaClient::exec() // fall through case REQ_FAILURE: + abortlockrequest(); if (pendingcs->sslcheckfailed) { sslfakeissuer = pendingcs->sslfakeissuer; @@ -2591,14 +2598,7 @@ void MegaClient::disconnect() pendingsc->disconnect(); } - if (workinglockcs) - { - btworkinglock.reset(); - delete workinglockcs; - workinglockcs = NULL; - requestLock = false; - requestLockTimestamp = 0; - } + abortlockrequest(); for (transferslot_list::iterator it = tslots.begin(); it != tslots.end(); it++) { @@ -2629,6 +2629,18 @@ void MegaClient::disconnect() httpio->disconnect(); } +void MegaClient::abortlockrequest() +{ + if (workinglockcs) + { + btworkinglock.reset(); + delete workinglockcs; + workinglockcs = NULL; + requestLock = false; + requestLockTimestamp = 0; + } +} + void MegaClient::logout() { if (loggedin() != FULLACCOUNT) From fcccd016a1bc38b6094cd10b8ac152280bfe5f22 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Mon, 24 Oct 2016 13:23:23 +0200 Subject: [PATCH 077/103] Wake up the SDK to process lock requests --- src/megaclient.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/megaclient.cpp b/src/megaclient.cpp index fbe5c1b501..bcd791ad16 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -2104,6 +2104,15 @@ int MegaClient::preparewait() { nds = timeout; } + + if (pendingcs && !fetchingnodes) + { + timeout = httpio->lastdata + HttpIO::REQUESTTIMEOUT; + if (timeout >= Waiter::ds && timeout < nds) + { + nds = timeout; + } + } } } From 7edb911cadda1799c1f6845fadc6dd593e83da35 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Mon, 24 Oct 2016 22:53:56 +0200 Subject: [PATCH 078/103] Use the timestamp of the request queue instead of the one of the network layer Wake up the SDK even if the even should have been processed in the past Update the timestamp of the request queue after having checked that the server is busy Other fixes --- include/mega/http.h | 2 +- include/mega/megaclient.h | 2 -- src/http.cpp | 3 +- src/megaclient.cpp | 60 ++++++++++++++++++++++++++------------- src/posix/net.cpp | 31 +++++++++++--------- src/transfer.cpp | 1 + src/win32/net.cpp | 3 ++ 7 files changed, 65 insertions(+), 37 deletions(-) diff --git a/include/mega/http.h b/include/mega/http.h index 0d208531bc..d2b6788ffe 100644 --- a/include/mega/http.h +++ b/include/mega/http.h @@ -205,7 +205,7 @@ struct MEGA_API HttpReq // progress information virtual m_off_t transferred(MegaClient*); - // timestamp of last data received + // timestamp of last data sent or received dstime lastdata; // prevent raw data from being dumped in debug mode diff --git a/include/mega/megaclient.h b/include/mega/megaclient.h index 5a7692d540..3bf711511f 100644 --- a/include/mega/megaclient.h +++ b/include/mega/megaclient.h @@ -826,8 +826,6 @@ class MEGA_API MegaClient bool requestLock; - m_time_t requestLockTimestamp; - // process object arrays by the API server int readnodes(JSON*, int, putsource_t = PUTNODES_APP, NewNode* = NULL, int = 0, int = 0); diff --git a/src/http.cpp b/src/http.cpp index d85b845ff4..564ad8b83d 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -292,6 +292,7 @@ void HttpReq::post(MegaClient* client, const char* data, unsigned len) notifiedbufpos = 0; inpurge = 0; contentlength = -1; + lastdata = Waiter::ds; httpio->post(this, data, len); } @@ -360,7 +361,7 @@ void HttpReq::init() notifiedbufpos = 0; contentlength = 0; timeleft = -1; - lastdata = 0; + lastdata = NEVER; } void HttpReq::setreq(const char* u, contenttype_t t) diff --git a/src/megaclient.cpp b/src/megaclient.cpp index bcd791ad16..cda27ee31b 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -684,7 +684,6 @@ void MegaClient::init() chunkfailed = false; statecurrent = false; requestLock = false; - requestLockTimestamp = 0; totalNodes = 0; #ifdef ENABLE_SYNC @@ -875,8 +874,8 @@ void MegaClient::exec() disconnect(); } - if (EVER(httpio->lastdata) && Waiter::ds >= httpio->lastdata + HttpIO::REQUESTTIMEOUT - && pendingcs && !fetchingnodes && !requestLock) + if (pendingcs && EVER(pendingcs->lastdata) && !requestLock && !fetchingnodes + && Waiter::ds >= pendingcs->lastdata + HttpIO::REQUESTTIMEOUT) { LOG_debug << "Request timeout. Triggering a lock request"; requestLock = true; @@ -1128,6 +1127,8 @@ void MegaClient::exec() json.begin(pendingcs->in.c_str()); reqs.procresult(this); + WAIT_CLASS::bumpds(); + delete pendingcs; pendingcs = NULL; @@ -1409,6 +1410,8 @@ void MegaClient::exec() reqtag = 0; sendevent(99425, "Timeout (server busy)"); reqtag = creqtag; + + pendingcs->lastdata = Waiter::ds; } else { @@ -1418,16 +1421,14 @@ void MegaClient::exec() delete workinglockcs; workinglockcs = NULL; requestLock = false; - requestLockTimestamp = 0; } else if (workinglockcs->status == REQ_FAILURE - || (workinglockcs->status == REQ_INFLIGHT && Waiter::ds >= requestLockTimestamp + HttpIO::REQUESTTIMEOUT)) + || (workinglockcs->status == REQ_INFLIGHT && Waiter::ds >= workinglockcs->lastdata + HttpIO::REQUESTTIMEOUT)) { LOG_warn << "Failed lock request. Retrying..."; btworkinglock.backoff(); delete workinglockcs; workinglockcs = NULL; - requestLockTimestamp = 0; } } @@ -1955,7 +1956,6 @@ void MegaClient::exec() workinglockcs->posturl.append("&wlt=1"); workinglockcs->type = REQ_JSON; workinglockcs->post(this); - requestLockTimestamp = Waiter::ds; } } while (httpio->doio() || execdirectreads() || (!pendingcs && reqs.cmdspending() && btcs.armed()) || looprequested); } @@ -2096,22 +2096,46 @@ int MegaClient::preparewait() #endif // detect stuck network - if (EVER(httpio->lastdata)) + if (EVER(httpio->lastdata) && !pendingcs) { dstime timeout = httpio->lastdata + HttpIO::NETWORKTIMEOUT; - if (timeout >= Waiter::ds && timeout < nds) + if (timeout > Waiter::ds && timeout < nds) { nds = timeout; } + else if (timeout <= Waiter::ds) + { + nds = 0; + } + } - if (pendingcs && !fetchingnodes) + if (pendingcs && EVER(pendingcs->lastdata)) + { + if (!requestLock && !fetchingnodes) { - timeout = httpio->lastdata + HttpIO::REQUESTTIMEOUT; - if (timeout >= Waiter::ds && timeout < nds) + dstime timeout = pendingcs->lastdata + HttpIO::REQUESTTIMEOUT; + if (timeout > Waiter::ds && timeout < nds) { nds = timeout; } + else if (timeout <= Waiter::ds) + { + nds = 0; + } + } + else if (workinglockcs && EVER(workinglockcs->lastdata) + && workinglockcs->status == REQ_INFLIGHT) + { + dstime timeout = workinglockcs->lastdata + HttpIO::REQUESTTIMEOUT; + if (timeout > Waiter::ds && timeout < nds) + { + nds = timeout; + } + else if (timeout <= Waiter::ds) + { + nds = 0; + } } } } @@ -2640,14 +2664,10 @@ void MegaClient::disconnect() void MegaClient::abortlockrequest() { - if (workinglockcs) - { - btworkinglock.reset(); - delete workinglockcs; - workinglockcs = NULL; - requestLock = false; - requestLockTimestamp = 0; - } + delete workinglockcs; + workinglockcs = NULL; + btworkinglock.reset(); + requestLock = false; } void MegaClient::logout() diff --git a/src/posix/net.cpp b/src/posix/net.cpp index 7f1054bf16..3e9a64e339 100644 --- a/src/posix/net.cpp +++ b/src/posix/net.cpp @@ -1491,6 +1491,7 @@ bool CurlHttpIO::doio() { dnsok = true; lastdata = Waiter::ds; + req->lastdata = Waiter::ds; } else { @@ -1690,19 +1691,21 @@ size_t CurlHttpIO::read_data(void* ptr, size_t size, size_t nmemb, void* source) size_t CurlHttpIO::write_data(void* ptr, size_t size, size_t nmemb, void* target) { - if(((HttpReq*)target)->httpio) + HttpReq *req = (HttpReq*)target; + if (req->httpio) { - if (((HttpReq*)target)->chunked) + if (req->chunked) { - ((CurlHttpIO*)((HttpReq*)target)->httpio)->statechange = true; + ((CurlHttpIO*)req->httpio)->statechange = true; } if (size * nmemb) { - ((HttpReq*)target)->put(ptr, size * nmemb, true); + req->put(ptr, size * nmemb, true); } - ((HttpReq*)target)->httpio->lastdata = Waiter::ds; + req->httpio->lastdata = Waiter::ds; + req->lastdata = Waiter::ds; } return size * nmemb; @@ -1711,6 +1714,7 @@ size_t CurlHttpIO::write_data(void* ptr, size_t size, size_t nmemb, void* target // set contentlength according to Original-Content-Length header size_t CurlHttpIO::check_header(void* ptr, size_t size, size_t nmemb, void* target) { + HttpReq *req = (HttpReq*)target; if (size * nmemb > 2) { LOG_verbose << "Header: " << string((const char *)ptr, size * nmemb - 2); @@ -1718,40 +1722,41 @@ size_t CurlHttpIO::check_header(void* ptr, size_t size, size_t nmemb, void* targ if (!memcmp(ptr, "HTTP/", 5)) { - if (((HttpReq*)target)->contentlength >= 0) + if (req->contentlength >= 0) { // For authentication with some proxies, cURL sends two requests in the context of a single one // Content-Length is reset here to not take into account the header from the first response LOG_warn << "Receiving a second response. Resetting Content-Length"; - ((HttpReq*)target)->contentlength = -1; + req->contentlength = -1; } return size * nmemb; } else if (!memcmp(ptr, "Content-Length:", 15)) { - if (((HttpReq*)target)->contentlength < 0) + if (req->contentlength < 0) { - ((HttpReq*)target)->setcontentlength(atol((char*)ptr + 15)); + req->setcontentlength(atol((char*)ptr + 15)); } } else if (!memcmp(ptr, "Original-Content-Length:", 24)) { - ((HttpReq*)target)->setcontentlength(atol((char*)ptr + 24)); + req->setcontentlength(atol((char*)ptr + 24)); } else if (!memcmp(ptr, "X-MEGA-Time-Left:", 17)) { - ((HttpReq*)target)->timeleft = atol((char*)ptr + 17); + req->timeleft = atol((char*)ptr + 17); } else { return size * nmemb; } - if (((HttpReq*)target)->httpio) + if (req->httpio) { - ((HttpReq*)target)->httpio->lastdata = Waiter::ds; + req->httpio->lastdata = Waiter::ds; + req->lastdata = Waiter::ds; } return size * nmemb; diff --git a/src/transfer.cpp b/src/transfer.cpp index e60ce08a55..9cf52e41ff 100644 --- a/src/transfer.cpp +++ b/src/transfer.cpp @@ -1001,6 +1001,7 @@ bool DirectReadSlot::doio() if (req->httpio) { req->httpio->lastdata = Waiter::ds; + req->lastdata = Waiter::ds; } if (dr->drn->client->app->pread_data((byte*)req->in.data(), t, pos, dr->appdata)) diff --git a/src/win32/net.cpp b/src/win32/net.cpp index 518cabba1f..dfc42550e1 100644 --- a/src/win32/net.cpp +++ b/src/win32/net.cpp @@ -226,6 +226,7 @@ VOID CALLBACK WinHttpIO::asynccallback(HINTERNET hInternet, DWORD_PTR dwContext, if (req->status == REQ_SUCCESS) { httpio->lastdata = Waiter::ds; + req->lastdata = Waiter::ds; } httpio->success = true; } @@ -267,6 +268,7 @@ VOID CALLBACK WinHttpIO::asynccallback(HINTERNET hInternet, DWORD_PTR dwContext, if (req->httpio) { req->httpio->lastdata = Waiter::ds; + req->lastdata = Waiter::ds; } if (httpctx->gzip) @@ -325,6 +327,7 @@ VOID CALLBACK WinHttpIO::asynccallback(HINTERNET hInternet, DWORD_PTR dwContext, if (req->httpio) { req->httpio->lastdata = Waiter::ds; + req->lastdata = Waiter::ds; } if (!req->buf) From 0b4d7e3d0b25767860eb8705c3fe669db736eeb1 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Tue, 25 Oct 2016 10:33:55 +0200 Subject: [PATCH 079/103] Delay the disconnection due to a hang in the request queue --- include/mega/http.h | 7 +++++-- include/mega/megaclient.h | 1 + src/http.cpp | 7 +++++-- src/megaclient.cpp | 20 +++++++++++++++++--- src/posix/net.cpp | 2 +- 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/include/mega/http.h b/include/mega/http.h index d2b6788ffe..0a754b71d5 100644 --- a/include/mega/http.h +++ b/include/mega/http.h @@ -117,11 +117,14 @@ struct MEGA_API HttpIO : public EventTrigger // timestamp of last data received (across all connections) dstime lastdata; - // data receive timeout + // data receive timeout (ds) static const int NETWORKTIMEOUT; - // request timeout + // request timeout (ds) static const int REQUESTTIMEOUT; + + // connection timeout (ds) + static const int CONNECTTIMEOUT; // set useragent (must be called exactly once) virtual void setuseragent(string*) = 0; diff --git a/include/mega/megaclient.h b/include/mega/megaclient.h index 3bf711511f..89a96341c0 100644 --- a/include/mega/megaclient.h +++ b/include/mega/megaclient.h @@ -825,6 +825,7 @@ class MEGA_API MegaClient string badhosts; bool requestLock; + dstime disconnecttimestamp; // process object arrays by the API server int readnodes(JSON*, int, putsource_t = PUTNODES_APP, NewNode* = NULL, int = 0, int = 0); diff --git a/src/http.cpp b/src/http.cpp index 564ad8b83d..552e477443 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -25,12 +25,15 @@ namespace mega { -// data receive timeout +// data receive timeout (ds) const int HttpIO::NETWORKTIMEOUT = 6000; -// request timeout +// request timeout (ds) const int HttpIO::REQUESTTIMEOUT = 1200; +// connect timeout (ds) +const int HttpIO::CONNECTTIMEOUT = 100; + #ifdef _WIN32 const char* mega_inet_ntop(int af, const void* src, char* dst, int cnt) { diff --git a/src/megaclient.cpp b/src/megaclient.cpp index cda27ee31b..669cc0cde4 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -684,6 +684,7 @@ void MegaClient::init() chunkfailed = false; statecurrent = false; requestLock = false; + disconnecttimestamp = NEVER; totalNodes = 0; #ifdef ENABLE_SYNC @@ -867,8 +868,8 @@ void MegaClient::exec() abortbackoff(overquotauntil <= Waiter::ds); } - if (EVER(httpio->lastdata) && Waiter::ds >= httpio->lastdata + HttpIO::NETWORKTIMEOUT - && !pendingcs) + if ((EVER(httpio->lastdata) && Waiter::ds >= httpio->lastdata + HttpIO::NETWORKTIMEOUT + && !pendingcs) || (EVER(disconnecttimestamp) && disconnecttimestamp <= Waiter::ds)) { LOG_debug << "Network timeout. Reconnecting"; disconnect(); @@ -1402,7 +1403,7 @@ void MegaClient::exec() sendevent(99424, "Timeout (server idle)"); reqtag = creqtag; - disconnect(); + disconnecttimestamp = Waiter::ds + HttpIO::CONNECTTIMEOUT; } else if (workinglockcs->in == "0") { @@ -2138,6 +2139,18 @@ int MegaClient::preparewait() } } } + + if (EVER(disconnecttimestamp)) + { + if (disconnecttimestamp > Waiter::ds && disconnecttimestamp < nds) + { + nds = disconnecttimestamp; + } + else if (disconnecttimestamp <= Waiter::ds) + { + nds = 0; + } + } } // immediate action required? @@ -2668,6 +2681,7 @@ void MegaClient::abortlockrequest() workinglockcs = NULL; btworkinglock.reset(); requestLock = false; + disconnecttimestamp = NEVER; } void MegaClient::logout() diff --git a/src/posix/net.cpp b/src/posix/net.cpp index 3e9a64e339..7a4d8ff5d6 100644 --- a/src/posix/net.cpp +++ b/src/posix/net.cpp @@ -867,7 +867,7 @@ void CurlHttpIO::send_request(CurlHttpContext* httpctx) curl_easy_setopt(curl, CURLOPT_PRIVATE, (void*)req); curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); curl_easy_setopt(curl, CURLOPT_NOSIGNAL, true); - curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L); + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, HttpIO::CONNECTTIMEOUT / 10); curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L); curl_easy_setopt(curl, CURLOPT_TCP_KEEPIDLE, 90L); curl_easy_setopt(curl, CURLOPT_TCP_KEEPINTVL, 60L); From 4c1c2beb76e2989daacdc9a1e9a643a79392a806 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Tue, 25 Oct 2016 10:48:46 +0200 Subject: [PATCH 080/103] Properly initialize the lock request --- src/megaclient.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/megaclient.cpp b/src/megaclient.cpp index 669cc0cde4..b25632d6ef 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -683,8 +683,6 @@ void MegaClient::init() csretrying = false; chunkfailed = false; statecurrent = false; - requestLock = false; - disconnecttimestamp = NEVER; totalNodes = 0; #ifdef ENABLE_SYNC @@ -719,7 +717,8 @@ void MegaClient::init() btsc.reset(); btpfa.reset(); btbadhost.reset(); - btworkinglock.reset(); + + abortlockrequest(); jsonsc.pos = NULL; insca = false; From 49ddb23502c41d3670af65f0fbfecd756f2e9f77 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Tue, 25 Oct 2016 10:53:30 +0200 Subject: [PATCH 081/103] Initialize the request before init() --- src/megaclient.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/megaclient.cpp b/src/megaclient.cpp index b25632d6ef..7e081eb20b 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -736,6 +736,7 @@ MegaClient::MegaClient(MegaApp* a, Waiter* w, HttpIO* h, FileSystemAccess* f, Db usealtdownport = false; usealtupport = false; retryessl = false; + workinglockcs = NULL; #ifndef EMSCRIPTEN autodownport = true; From 5c7e5cb39daa7f63bed5ccbd1bd81498ba890828 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Tue, 25 Oct 2016 11:10:12 +0200 Subject: [PATCH 082/103] Move the event to the right place --- src/megaclient.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/megaclient.cpp b/src/megaclient.cpp index 7e081eb20b..14f6af30c9 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -818,7 +818,6 @@ MegaClient::MegaClient(MegaApp* a, Waiter* w, HttpIO* h, FileSystemAccess* f, Db reqtag = 0; badhostcs = NULL; - workinglockcs = NULL; scsn[sizeof scsn - 1] = 0; cachedscsn = UNDEF; @@ -868,12 +867,21 @@ void MegaClient::exec() abortbackoff(overquotauntil <= Waiter::ds); } - if ((EVER(httpio->lastdata) && Waiter::ds >= httpio->lastdata + HttpIO::NETWORKTIMEOUT - && !pendingcs) || (EVER(disconnecttimestamp) && disconnecttimestamp <= Waiter::ds)) + if (EVER(httpio->lastdata) && Waiter::ds >= httpio->lastdata + HttpIO::NETWORKTIMEOUT + && !pendingcs) { LOG_debug << "Network timeout. Reconnecting"; disconnect(); } + else if (EVER(disconnecttimestamp) && disconnecttimestamp <= Waiter::ds) + { + int creqtag = reqtag; + reqtag = 0; + sendevent(99424, "Timeout (server idle)"); + reqtag = creqtag; + + disconnect(); + } if (pendingcs && EVER(pendingcs->lastdata) && !requestLock && !fetchingnodes && Waiter::ds >= pendingcs->lastdata + HttpIO::REQUESTTIMEOUT) @@ -1398,11 +1406,7 @@ void MegaClient::exec() if (workinglockcs->in == "1") { - int creqtag = reqtag; - reqtag = 0; - sendevent(99424, "Timeout (server idle)"); - reqtag = creqtag; - + LOG_warn << "Timeout (server idle)"; disconnecttimestamp = Waiter::ds + HttpIO::CONNECTTIMEOUT; } else if (workinglockcs->in == "0") From 528b110fb8d86f25939735a379c8b22e8327c9cd Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Tue, 25 Oct 2016 12:00:48 +0200 Subject: [PATCH 083/103] Disable the processing of the timeout for request while waiting for a disconnection --- src/megaclient.cpp | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/megaclient.cpp b/src/megaclient.cpp index 14f6af30c9..7ad47eb466 100644 --- a/src/megaclient.cpp +++ b/src/megaclient.cpp @@ -873,17 +873,19 @@ void MegaClient::exec() LOG_debug << "Network timeout. Reconnecting"; disconnect(); } - else if (EVER(disconnecttimestamp) && disconnecttimestamp <= Waiter::ds) + else if (EVER(disconnecttimestamp)) { - int creqtag = reqtag; - reqtag = 0; - sendevent(99424, "Timeout (server idle)"); - reqtag = creqtag; + if (disconnecttimestamp <= Waiter::ds) + { + int creqtag = reqtag; + reqtag = 0; + sendevent(99424, "Timeout (server idle)"); + reqtag = creqtag; - disconnect(); + disconnect(); + } } - - if (pendingcs && EVER(pendingcs->lastdata) && !requestLock && !fetchingnodes + else if (pendingcs && EVER(pendingcs->lastdata) && !requestLock && !fetchingnodes && Waiter::ds >= pendingcs->lastdata + HttpIO::REQUESTTIMEOUT) { LOG_debug << "Request timeout. Triggering a lock request"; @@ -2117,7 +2119,18 @@ int MegaClient::preparewait() if (pendingcs && EVER(pendingcs->lastdata)) { - if (!requestLock && !fetchingnodes) + if (EVER(disconnecttimestamp)) + { + if (disconnecttimestamp > Waiter::ds && disconnecttimestamp < nds) + { + nds = disconnecttimestamp; + } + else if (disconnecttimestamp <= Waiter::ds) + { + nds = 0; + } + } + else if (!requestLock && !fetchingnodes) { dstime timeout = pendingcs->lastdata + HttpIO::REQUESTTIMEOUT; if (timeout > Waiter::ds && timeout < nds) @@ -2143,18 +2156,6 @@ int MegaClient::preparewait() } } } - - if (EVER(disconnecttimestamp)) - { - if (disconnecttimestamp > Waiter::ds && disconnecttimestamp < nds) - { - nds = disconnecttimestamp; - } - else if (disconnecttimestamp <= Waiter::ds) - { - nds = 0; - } - } } // immediate action required? From 31fd28be12169f3b531e6a076ba9017111e1f18e Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Tue, 25 Oct 2016 12:35:11 +0200 Subject: [PATCH 084/103] Increase the time before a connection timeout --- src/http.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/http.cpp b/src/http.cpp index 552e477443..73f68bd518 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -32,7 +32,7 @@ const int HttpIO::NETWORKTIMEOUT = 6000; const int HttpIO::REQUESTTIMEOUT = 1200; // connect timeout (ds) -const int HttpIO::CONNECTTIMEOUT = 100; +const int HttpIO::CONNECTTIMEOUT = 120; #ifdef _WIN32 const char* mega_inet_ntop(int af, const void* src, char* dst, int cnt) From d8949926973b141639421ed47dce51b4b6790e49 Mon Sep 17 00:00:00 2001 From: Victor Teniente Mateos Date: Tue, 25 Oct 2016 13:58:25 +0200 Subject: [PATCH 085/103] New function to create local folders --- include/megaapi.h | 8 ++++++++ include/megaapi_impl.h | 1 + src/megaapi.cpp | 5 +++++ src/megaapi_impl.cpp | 12 ++++++++++++ src/posix/fs.cpp | 1 + 5 files changed, 27 insertions(+) diff --git a/include/megaapi.h b/include/megaapi.h index d5b23515aa..c0bf5c8188 100644 --- a/include/megaapi.h +++ b/include/megaapi.h @@ -4833,6 +4833,14 @@ class MegaApi */ void createFolder(const char* name, MegaNode *parent, MegaRequestListener *listener = NULL); + /** + * @brief Create a new empty folder in your local file system + * + * @param localPath Path of the new folder + * @return True if the local folder was successfully created, otherwise false. + */ + bool createLocalFolder(const char* localPath); + /** * @brief Move a node in the MEGA account * diff --git a/include/megaapi_impl.h b/include/megaapi_impl.h index 7d5f842863..c30e800101 100644 --- a/include/megaapi_impl.h +++ b/include/megaapi_impl.h @@ -1256,6 +1256,7 @@ class MegaApiImpl : public MegaApp static void log(int logLevel, const char* message, const char *filename = NULL, int line = -1); void createFolder(const char* name, MegaNode *parent, MegaRequestListener *listener = NULL); + bool createLocalFolder(const char *path); void moveNode(MegaNode* node, MegaNode* newParent, MegaRequestListener *listener = NULL); void copyNode(MegaNode* node, MegaNode *newParent, MegaRequestListener *listener = NULL); void copyNode(MegaNode* node, MegaNode *newParent, const char* newName, MegaRequestListener *listener = NULL); diff --git a/src/megaapi.cpp b/src/megaapi.cpp index deff749456..2c9f041211 100644 --- a/src/megaapi.cpp +++ b/src/megaapi.cpp @@ -1346,6 +1346,11 @@ void MegaApi::createFolder(const char *name, MegaNode *parent, MegaRequestListen pImpl->createFolder(name, parent, listener); } +bool MegaApi::createLocalFolder(const char *localPath) +{ + return pImpl->createLocalFolder(localPath); +} + void MegaApi::moveNode(MegaNode *node, MegaNode *newParent, MegaRequestListener *listener) { pImpl->moveNode(node, newParent, listener); diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index bfcbce2a1e..2d9b9f410d 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -4255,6 +4255,18 @@ void MegaApiImpl::createFolder(const char *name, MegaNode *parent, MegaRequestLi waiter->notify(); } +bool MegaApiImpl::createLocalFolder(const char *path) +{ + string localpath; + string sPath(path); + client->fsaccess->path2local(&sPath, &localpath); + sdkMutex.lock(); + bool success = client->fsaccess->mkdirlocal(&localpath); + sdkMutex.unlock(); + + return success; +} + void MegaApiImpl::moveNode(MegaNode *node, MegaNode *newParent, MegaRequestListener *listener) { MegaRequestPrivate *request = new MegaRequestPrivate(MegaRequest::TYPE_MOVE, listener); diff --git a/src/posix/fs.cpp b/src/posix/fs.cpp index f1e6b33ad3..449ae8bf25 100644 --- a/src/posix/fs.cpp +++ b/src/posix/fs.cpp @@ -1009,6 +1009,7 @@ bool PosixFileSystemAccess::mkdirlocal(string* name, bool) if (!r) { + LOG_err << "Error creating local directory: " << name->c_str() << " errno: " << errno; target_exists = errno == EEXIST; transient_error = errno == ETXTBSY || errno == EBUSY; } From c88520c0cf2f9e5f8c8d0eba91fe367cdab3ef09 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Tue, 25 Oct 2016 14:05:48 +0200 Subject: [PATCH 086/103] Safety checks and compatibility with long paths --- src/megaapi_impl.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 2d9b9f410d..100d58a63c 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -4257,9 +4257,21 @@ void MegaApiImpl::createFolder(const char *name, MegaNode *parent, MegaRequestLi bool MegaApiImpl::createLocalFolder(const char *path) { + if (!path) + { + return false; + } + string localpath; string sPath(path); + +#if defined(_WIN32) && !defined(WINDOWS_PHONE) + if(!PathIsRelativeA(sPath.c_str()) && ((sPath.size()<2) || sPath.compare(0, 2, "\\\\"))) + sPath.insert(0, "\\\\?\\"); +#endif + client->fsaccess->path2local(&sPath, &localpath); + sdkMutex.lock(); bool success = client->fsaccess->mkdirlocal(&localpath); sdkMutex.unlock(); From 9ac0fe51d06d7edda5c88f0ddcd3d78cac197fb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20G=C3=B3mez?= Date: Tue, 13 Sep 2016 12:21:17 +0200 Subject: [PATCH 087/103] Add start upload with modification time and temporary source (WP binding) --- bindings/wp8/MegaSDK.cpp | 21 +++++++++++++++++++++ bindings/wp8/MegaSDK.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/bindings/wp8/MegaSDK.cpp b/bindings/wp8/MegaSDK.cpp index 08ec646bd7..42dfb1988f 100644 --- a/bindings/wp8/MegaSDK.cpp +++ b/bindings/wp8/MegaSDK.cpp @@ -2027,6 +2027,27 @@ void MegaSDK::startUploadWithMtime(String^ localPath, MNode^ parent, uint64 mtim (parent != nullptr) ? parent->getCPtr() : NULL, mtime); } +void MegaSDK::startUploadWithMtimeTempSource(String^ localPath, MNode^ parent, uint64 mtime, bool isSourceTemporary, MTransferListenerInterface^ listener) +{ + std::string utf8localPath; + if (localPath != nullptr) + MegaApi::utf16ToUtf8(localPath->Data(), localPath->Length(), &utf8localPath); + + megaApi->startUpload((localPath != nullptr) ? utf8localPath.c_str() : NULL, + (parent != nullptr) ? parent->getCPtr() : NULL, mtime, isSourceTemporary, + createDelegateMTransferListener(listener)); +} + +void MegaSDK::startUploadWithMtimeTempSource(String^ localPath, MNode^ parent, uint64 mtime, bool isSourceTemporary) +{ + std::string utf8localPath; + if (localPath != nullptr) + MegaApi::utf16ToUtf8(localPath->Data(), localPath->Length(), &utf8localPath); + + megaApi->startUpload((localPath != nullptr) ? utf8localPath.c_str() : NULL, + (parent != nullptr) ? parent->getCPtr() : NULL, mtime, isSourceTemporary); +} + void MegaSDK::startUploadToFileWithMtime(String^ localPath, MNode^ parent, String^ fileName, uint64 mtime, MTransferListenerInterface^ listener) { std::string utf8localPath; diff --git a/bindings/wp8/MegaSDK.h b/bindings/wp8/MegaSDK.h index c943782eb6..36392b3479 100644 --- a/bindings/wp8/MegaSDK.h +++ b/bindings/wp8/MegaSDK.h @@ -325,6 +325,8 @@ namespace mega void startUploadToFile(String^ localPath, MNode^ parent, String^ fileName); void startUploadWithMtime(String^ localPath, MNode^ parent, uint64 mtime, MTransferListenerInterface^ listener); void startUploadWithMtime(String^ localPath, MNode^ parent, uint64 mtime); + void startUploadWithMtimeTempSource(String^ localPath, MNode^ parent, uint64 mtime, bool isSourceTemporary, MTransferListenerInterface^ listener); + void startUploadWithMtimeTempSource(String^ localPath, MNode^ parent, uint64 mtime, bool isSourceTemporary); void startUploadToFileWithMtime(String^ localPath, MNode^ parent, String^ fileName, uint64 mtime, MTransferListenerInterface^ listener); void startUploadToFileWithMtime(String^ localPath, MNode^ parent, String^ fileName, uint64 mtime); void startUploadWithData(String^ localPath, MNode^ parent, String^ appData, MTransferListenerInterface^ listener); From eefc8a804c521c446e8cc9a7dd21c5c663b295d3 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Tue, 13 Sep 2016 11:21:51 +0200 Subject: [PATCH 088/103] New function to upload temporary files with a custom modification time --- include/megaapi.h | 11 +++++++++++ src/megaapi.cpp | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/include/megaapi.h b/include/megaapi.h index 6e36d86df7..aaeb817177 100644 --- a/include/megaapi.h +++ b/include/megaapi.h @@ -6022,6 +6022,17 @@ class MegaApi */ void startUpload(const char* localPath, MegaNode *parent, int64_t mtime, MegaTransferListener *listener=NULL); + /** + * @brief Upload a file or a folder with a custom modification time + * @param localPath Local path of the file + * @param parent Parent node for the file in the MEGA account + * @param mtime Custom modification time for the file in MEGA (in seconds since the epoch) + * @param isSourceTemporary Pass the ownership of the file to the SDK, that will DELETE it when the upload finishes. + * This parameter is intended to automatically delete temporary files that are only created to be uploaded. + * @param listener MegaTransferListener to track this transfer + */ + void startUpload(const char* localPath, MegaNode *parent, int64_t mtime, bool isSourceTemporary, MegaTransferListener *listener=NULL); + /** * @brief Upload a file or folder with a custom name * @param localPath Local path of the file or folder diff --git a/src/megaapi.cpp b/src/megaapi.cpp index 9b877b6cb7..0183bea73e 100644 --- a/src/megaapi.cpp +++ b/src/megaapi.cpp @@ -1767,6 +1767,11 @@ void MegaApi::startUpload(const char *localPath, MegaNode *parent, int64_t mtime pImpl->startUpload(localPath, parent, mtime, listener); } +void MegaApi::startUpload(const char *localPath, MegaNode *parent, int64_t mtime, bool isSourceTemporary, MegaTransferListener *listener) +{ + pImpl->startUpload(localPath, parent, (const char *)NULL, mtime, 0, NULL, isSourceTemporary, listener); +} + void MegaApi::startUpload(const char* localPath, MegaNode* parent, const char* fileName, MegaTransferListener *listener) { pImpl->startUpload(localPath, parent, fileName, listener); From fa320ca83a86546d02bf16841a83728720a965a6 Mon Sep 17 00:00:00 2001 From: Victor Teniente Mateos Date: Wed, 26 Oct 2016 17:11:42 +0200 Subject: [PATCH 089/103] Initial commit for auto-detect proxy support on OSX --- bindings/qt/sdk.pri | 8 ++++ include/mega/osx/osxutils.h | 8 ++++ src/http.cpp | 10 ++++- src/osx/osxutils.mm | 89 +++++++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 include/mega/osx/osxutils.h create mode 100644 src/osx/osxutils.mm diff --git a/bindings/qt/sdk.pri b/bindings/qt/sdk.pri index 616071412d..41dbe43edd 100644 --- a/bindings/qt/sdk.pri +++ b/bindings/qt/sdk.pri @@ -286,9 +286,17 @@ unix:!macx { macx { INCLUDEPATH += $$MEGASDK_BASE_PATH/include/mega/posix + INCLUDEPATH += $$MEGASDK_BASE_PATH/include/mega/osx + + OBJECTIVE_SOURCES += $$MEGASDK_BASE_PATH/src/osx/osxutils.mm + SOURCES += $$MEGASDK_BASE_PATH/bindings/qt/3rdparty/sqlite3.c + INCLUDEPATH += $$MEGASDK_BASE_PATH/bindings/qt/3rdparty/include/curl INCLUDEPATH += $$MEGASDK_BASE_PATH/bindings/qt/3rdparty/include/libsodium + DEFINES += PCRE_STATIC _DARWIN_FEATURE_64_BIT_INODE + LIBS += -L$$MEGASDK_BASE_PATH/bindings/qt/3rdparty/libs/ $$MEGASDK_BASE_PATH/bindings/qt/3rdparty/libs/libcares.a $$MEGASDK_BASE_PATH/bindings/qt/3rdparty/libs/libcurl.a $$MEGASDK_BASE_PATH/bindings/qt/3rdparty/libs/libsodium.a -lz -lssl -lcrypto -lcryptopp + LIBS += -framework SystemConfiguration } diff --git a/include/mega/osx/osxutils.h b/include/mega/osx/osxutils.h new file mode 100644 index 0000000000..76851251fe --- /dev/null +++ b/include/mega/osx/osxutils.h @@ -0,0 +1,8 @@ +#ifndef OSXUTILS_H +#define OSXUTILS_H + +#include "mega/proxy.h" + +void getOSXproxy(mega::Proxy* proxy); + +#endif // OSXUTILS_H diff --git a/src/http.cpp b/src/http.cpp index 73f68bd518..f4c7840b7b 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -23,6 +23,10 @@ #include "mega/megaclient.h" #include "mega/logging.h" +#ifdef __APPLE__ +#include "mega/osx/osxutils.h" +#endif + namespace mega { // data receive timeout (ds) @@ -210,7 +214,11 @@ Proxy *HttpIO::getautoproxy() if (ieProxyConfig.lpszAutoConfigUrl) { GlobalFree(ieProxyConfig.lpszAutoConfigUrl); - } + } +#endif + +#ifdef __APPLE__ + getOSXproxy(proxy); #endif return proxy; diff --git a/src/osx/osxutils.mm b/src/osx/osxutils.mm new file mode 100644 index 0000000000..19fc314821 --- /dev/null +++ b/src/osx/osxutils.mm @@ -0,0 +1,89 @@ +#include "osxutils.h" +#include +#include + +using namespace mega; + +enum {HTTP_PROXY = 0, HTTPS_PROXY}; + +CFTypeRef getValueFromKey(CFDictionaryRef dict, const void *key, CFTypeID type) +{ + CFTypeRef value = CFDictionaryGetValue(dict, key); + if (!value) + { + return NULL; + } + + if ((CFGetTypeID(value) == type)) + { + return value; + } + + return NULL; +} + +bool getProxyConfiguration(CFDictionaryRef dict, int proxyType, Proxy* proxy) +{ + int isEnabled = 0; + int port; + + if (proxyType != HTTPS_PROXY && proxyType != HTTP_PROXY) + { + return false; + } + + CFStringRef proxyEnableKey = proxyType == HTTP_PROXY ? kSCPropNetProxiesHTTPEnable : kSCPropNetProxiesHTTPSEnable; + CFStringRef proxyHostKey = proxyType == HTTP_PROXY ? kSCPropNetProxiesHTTPProxy : kSCPropNetProxiesHTTPSProxy; + CFStringRef portKey = proxyType == HTTP_PROXY ? kSCPropNetProxiesHTTPPort : kSCPropNetProxiesHTTPSPort; + + CFNumberRef proxyEnabledRef = (CFNumberRef)getValueFromKey(dict, proxyEnableKey, CFNumberGetTypeID()); + if (proxyEnabledRef && CFNumberGetValue(proxyEnabledRef, kCFNumberIntType, &isEnabled) && (isEnabled != 0)) + { + if ([(NSDictionary*)dict valueForKey: proxyType == HTTPS_PROXY ? @"HTTPSUser": @"HTTPUser"] != nil) + { + //Username set, skip proxy configuration. We only allow proxies withouth user/pw credentials + return false; + } + + CFStringRef hostRef = (CFStringRef)getValueFromKey(dict, proxyHostKey, CFStringGetTypeID()); + if (hostRef) + { + CFIndex length = CFStringGetLength(hostRef); + CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1; + char *buffer = (char *) malloc (maxSize); + if (CFStringGetCString(hostRef, buffer, maxSize, kCFStringEncodingUTF8)) + { + CFNumberRef portRef = (CFNumberRef)getValueFromKey(dict, portKey, CFNumberGetTypeID()); + if (portRef && CFNumberGetValue(portRef, kCFNumberIntType, &port)) + { + ostringstream oss; + oss << (proxyType == HTTPS_PROXY ? "https://" : "http://") << buffer << ":" << port; + string link = oss.str(); + proxy->setProxyType(Proxy::CUSTOM); + proxy->setProxyURL(&link); + free(buffer); + return true; + } + + } + free(buffer); + } + } + return false; +} + +void getOSXproxy(Proxy* proxy) +{ + CFDictionaryRef proxySettings = NULL; + proxySettings = SCDynamicStoreCopyProxies(NULL); + if (!proxySettings) + { + return; + } + + if (!getProxyConfiguration(proxySettings, HTTP_PROXY, proxy)) + { + getProxyConfiguration(proxySettings, HTTPS_PROXY, proxy); + } + CFRelease(proxySettings); +} From 98bd09f0c375b632cc4b60e632081a5f0e859baa Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Thu, 27 Oct 2016 09:51:33 +0200 Subject: [PATCH 090/103] fixed getting version in configure in some macOS --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 91abc02d9e..698eb3d718 100644 --- a/configure.ac +++ b/configure.ac @@ -43,7 +43,7 @@ m4_define([mega_lt_revision], [0]) m4_define([mega_lt_current], [$(echo -n $(( $( cat include/mega/version.h | grep "define MEGA_MAJOR" | cut -d" " -f 3 ) * 10000 + $( cat include/mega/version.h | grep "define MEGA_MINOR" | cut -d" " -f 3 ) * 100 + $(cat include/mega/version.h | grep "define MEGA_MICRO" | cut -d" " -f 3))))]) m4_define([mega_lt_age], [0]) -AC_INIT([libmega], m4_esyscmd([ grep define < include/mega/version.h | cut -d ' ' -f3 | tr -st '\n' '.' | cut -d '.' -f1,2,3 --output-delimiter='.' | tr -d '\n']), [https://github.com/meganz/sdk]) +AC_INIT([libmega], m4_esyscmd([ grep define < include/mega/version.h | awk '{print $3}' | awk 'BEGIN { RS = "" ; FS = "\n" } {printf $1"."$2"."$3}']), [https://github.com/meganz/sdk]) # Define _GNU_SOURCE From 3949e65353fb8cdc0708420eb215f7265de18a10 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Thu, 27 Oct 2016 12:00:04 +0200 Subject: [PATCH 091/103] fixed configure.ac mega_lt_current calculation for macos --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 698eb3d718..9279e2968a 100644 --- a/configure.ac +++ b/configure.ac @@ -40,7 +40,7 @@ m4_define([mega_version], # libtool interface versioning m4_define([mega_lt_revision], [0]) -m4_define([mega_lt_current], [$(echo -n $(( $( cat include/mega/version.h | grep "define MEGA_MAJOR" | cut -d" " -f 3 ) * 10000 + $( cat include/mega/version.h | grep "define MEGA_MINOR" | cut -d" " -f 3 ) * 100 + $(cat include/mega/version.h | grep "define MEGA_MICRO" | cut -d" " -f 3))))]) +m4_define([mega_lt_current], [$(grep define Date: Thu, 27 Oct 2016 12:00:37 +0200 Subject: [PATCH 092/103] included osxutils compilation in macos --- include/Makefile.am | 6 ++++++ src/include.am | 8 ++++++++ src/osx/osxutils.mm | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/Makefile.am b/include/Makefile.am index 75ee5e5cd6..fe2dbbfe49 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -79,4 +79,10 @@ nobase_libmegainclude_HEADERS += \ mega/posix/megaconsolewaiter.h endif +if DARWIN +if !USE_IOS +nobase_libmegainclude_HEADERS += mega/osx/osxutils.h +endif +endif + #noinst_HEADERS = config.h diff --git a/src/include.am b/src/include.am index 10da4a88bf..934e898fdd 100644 --- a/src/include.am +++ b/src/include.am @@ -76,7 +76,15 @@ endif # IOS specific if USE_IOS src_libmega_la_SOURCES += src/gfx/GfxProcCG.mm +else +if DARWIN +# MacOS specific +src_libmega_la_SOURCES += src/osx/osxutils.mm +src_libmega_la_LDFLAGS += -framework SystemConfiguration endif +endif + + # win32 sources if WIN32 diff --git a/src/osx/osxutils.mm b/src/osx/osxutils.mm index 19fc314821..bf9c833e7b 100644 --- a/src/osx/osxutils.mm +++ b/src/osx/osxutils.mm @@ -1,4 +1,4 @@ -#include "osxutils.h" +#include "mega/osx/osxutils.h" #include #include From 60e32b54d3270c6f90714f8fbf1efa9cb3992465 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Thu, 27 Oct 2016 17:28:55 +0200 Subject: [PATCH 093/103] Removed obsolete files --- contrib/vsprojects/Mega.sln | 29 --- contrib/vsprojects/Mega.vcxproj | 175 -------------- contrib/vsprojects/Mega.vcxproj.filters | 255 -------------------- contrib/vsprojects/Mega.vcxproj.user | 3 - contrib/vsprojects/megasync.vcxproj | 129 ---------- contrib/vsprojects/megasync.vcxproj.filters | 141 ----------- contrib/vsprojects/megasync.vcxproj.user | 3 - 7 files changed, 735 deletions(-) delete mode 100644 contrib/vsprojects/Mega.sln delete mode 100644 contrib/vsprojects/Mega.vcxproj delete mode 100644 contrib/vsprojects/Mega.vcxproj.filters delete mode 100644 contrib/vsprojects/Mega.vcxproj.user delete mode 100644 contrib/vsprojects/megasync.vcxproj delete mode 100644 contrib/vsprojects/megasync.vcxproj.filters delete mode 100644 contrib/vsprojects/megasync.vcxproj.user diff --git a/contrib/vsprojects/Mega.sln b/contrib/vsprojects/Mega.sln deleted file mode 100644 index f4e3022066..0000000000 --- a/contrib/vsprojects/Mega.sln +++ /dev/null @@ -1,29 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Mega", "Mega.vcxproj", "{93FED8CC-E7A0-4EC7-BC79-3589F469A75B}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "megasync", "megasync.vcxproj", "{1F18FD59-A6AE-4689-9431-2D0288FF7763}" - ProjectSection(ProjectDependencies) = postProject - {93FED8CC-E7A0-4EC7-BC79-3589F469A75B} = {93FED8CC-E7A0-4EC7-BC79-3589F469A75B} - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {93FED8CC-E7A0-4EC7-BC79-3589F469A75B}.Debug|Win32.ActiveCfg = Debug|Win32 - {93FED8CC-E7A0-4EC7-BC79-3589F469A75B}.Debug|Win32.Build.0 = Debug|Win32 - {93FED8CC-E7A0-4EC7-BC79-3589F469A75B}.Release|Win32.ActiveCfg = Release|Win32 - {93FED8CC-E7A0-4EC7-BC79-3589F469A75B}.Release|Win32.Build.0 = Release|Win32 - {1F18FD59-A6AE-4689-9431-2D0288FF7763}.Debug|Win32.ActiveCfg = Debug|Win32 - {1F18FD59-A6AE-4689-9431-2D0288FF7763}.Debug|Win32.Build.0 = Debug|Win32 - {1F18FD59-A6AE-4689-9431-2D0288FF7763}.Release|Win32.ActiveCfg = Release|Win32 - {1F18FD59-A6AE-4689-9431-2D0288FF7763}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/contrib/vsprojects/Mega.vcxproj b/contrib/vsprojects/Mega.vcxproj deleted file mode 100644 index fb1102d9ce..0000000000 --- a/contrib/vsprojects/Mega.vcxproj +++ /dev/null @@ -1,175 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {93FED8CC-E7A0-4EC7-BC79-3589F469A75B} - Win32Proj - Mega - - - - DynamicLibrary - true - Unicode - - - DynamicLibrary - false - true - Unicode - - - - - - - - - - - - - true - AllRules.ruleset - - - - - false - AllRules.ruleset - - - - - - - - Level3 - Disabled - MEGA_CREATE_SHARED_LIBRARY;WIN32;_DEBUG;_WINDOWS;_USRDLL;MEGA_EXPORTS;USE_CRYPTOPP;USE_SQLITE - ..\..\;..\..\sqlite3;..\..\include\mega\win32;..\..\include;%(AdditionalIncludeDirectories) - $(IntDir)/%(RelativeDir)/ - - - Windows - true - winhttp.lib;ws2_32.lib;%(AdditionalDependencies) - ../../;%(AdditionalLibraryDirectories) - - - - - Level3 - - - MaxSpeed - true - true - MEGA_CREATE_SHARED_LIBRARY;WIN32;_DEBUG;_WINDOWS;_USRDLL;MEGA_EXPORTS;USE_CRYPTOPP;USE_SQLITE - ..\..\sqlite3;..\..\include\mega\win32;..\..\include;%(AdditionalIncludeDirectories) - $(IntDir)/%(RelativeDir)/ - - - Windows - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/contrib/vsprojects/Mega.vcxproj.filters b/contrib/vsprojects/Mega.vcxproj.filters deleted file mode 100644 index 5b081895bc..0000000000 --- a/contrib/vsprojects/Mega.vcxproj.filters +++ /dev/null @@ -1,255 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - - \ No newline at end of file diff --git a/contrib/vsprojects/Mega.vcxproj.user b/contrib/vsprojects/Mega.vcxproj.user deleted file mode 100644 index ace9a86acb..0000000000 --- a/contrib/vsprojects/Mega.vcxproj.user +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/contrib/vsprojects/megasync.vcxproj b/contrib/vsprojects/megasync.vcxproj deleted file mode 100644 index b7646bad5d..0000000000 --- a/contrib/vsprojects/megasync.vcxproj +++ /dev/null @@ -1,129 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {1F18FD59-A6AE-4689-9431-2D0288FF7763} - Win32Proj - megasync - - - - Application - true - Unicode - - - Application - false - true - Unicode - - - - - - - - - - - - - true - - - false - - - - - - Level3 - Disabled - MEGA_LINKED_AS_SHARED_LIBRARY;WIN32;_DEBUG;_CONSOLE;USE_SQLITE;USE_CRYPTOPP;%(PreprocessorDefinitions) - ..\..\;..\..\sqlite3;..\..\include\mega\win32;..\..\include;%(AdditionalIncludeDirectories) - - - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - - - Console - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {93fed8cc-e7a0-4ec7-bc79-3589f469a75b} - - - - - - \ No newline at end of file diff --git a/contrib/vsprojects/megasync.vcxproj.filters b/contrib/vsprojects/megasync.vcxproj.filters deleted file mode 100644 index d1ffbe61a8..0000000000 --- a/contrib/vsprojects/megasync.vcxproj.filters +++ /dev/null @@ -1,141 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - \ No newline at end of file diff --git a/contrib/vsprojects/megasync.vcxproj.user b/contrib/vsprojects/megasync.vcxproj.user deleted file mode 100644 index ace9a86acb..0000000000 --- a/contrib/vsprojects/megasync.vcxproj.user +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file From a4919554724aecfbf538876180c03f114997b11d Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Thu, 27 Oct 2016 17:32:30 +0200 Subject: [PATCH 094/103] Update the build of Java bindings to Visual Studio 2015 --- bindings/java/contrib/vs2010/.gitignore | 1 - bindings/java/contrib/vs2015/.gitignore | 4 ++++ .../contrib/{vs2010 => vs2015}/MEGAdll.sln | 0 .../{vs2010 => vs2015}/MEGAdll.vcxproj | 22 +++++++++++-------- .../MEGAdll.vcxproj.filters | 0 .../java/contrib/{vs2010 => vs2015}/README.md | 10 ++++----- 6 files changed, 22 insertions(+), 15 deletions(-) delete mode 100644 bindings/java/contrib/vs2010/.gitignore create mode 100644 bindings/java/contrib/vs2015/.gitignore rename bindings/java/contrib/{vs2010 => vs2015}/MEGAdll.sln (100%) rename bindings/java/contrib/{vs2010 => vs2015}/MEGAdll.vcxproj (94%) rename bindings/java/contrib/{vs2010 => vs2015}/MEGAdll.vcxproj.filters (100%) rename bindings/java/contrib/{vs2010 => vs2015}/README.md (77%) diff --git a/bindings/java/contrib/vs2010/.gitignore b/bindings/java/contrib/vs2010/.gitignore deleted file mode 100644 index e09b8fbbe2..0000000000 --- a/bindings/java/contrib/vs2010/.gitignore +++ /dev/null @@ -1 +0,0 @@ -3rdparty \ No newline at end of file diff --git a/bindings/java/contrib/vs2015/.gitignore b/bindings/java/contrib/vs2015/.gitignore new file mode 100644 index 0000000000..9d7c7e6f04 --- /dev/null +++ b/bindings/java/contrib/vs2015/.gitignore @@ -0,0 +1,4 @@ +3rdparty +*.suo +*.sdf +*.vcxproj.user \ No newline at end of file diff --git a/bindings/java/contrib/vs2010/MEGAdll.sln b/bindings/java/contrib/vs2015/MEGAdll.sln similarity index 100% rename from bindings/java/contrib/vs2010/MEGAdll.sln rename to bindings/java/contrib/vs2015/MEGAdll.sln diff --git a/bindings/java/contrib/vs2010/MEGAdll.vcxproj b/bindings/java/contrib/vs2015/MEGAdll.vcxproj similarity index 94% rename from bindings/java/contrib/vs2010/MEGAdll.vcxproj rename to bindings/java/contrib/vs2015/MEGAdll.vcxproj index c46a2c758b..643827d3ca 100644 --- a/bindings/java/contrib/vs2010/MEGAdll.vcxproj +++ b/bindings/java/contrib/vs2015/MEGAdll.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -124,23 +124,27 @@ DynamicLibrary true Unicode + v140 DynamicLibrary true Unicode + v140 DynamicLibrary false true Unicode + v140 DynamicLibrary false true Unicode + v140 @@ -193,14 +197,14 @@ ..\..\..\..\include;..\..\..\..\third_party\utf8proc;.;3rdparty\include\curl;3rdparty\include\cares;3rdparty\include\zlib;3rdparty\include;..\..\..\..\include\mega\wincurl;3rdparty\include\cryptopp;3rdparty\include\libsodium;C:\Program Files (x86)\Java\jdk1.8.0_77\include;C:\Program Files (x86)\Java\jdk1.8.0_77\include\win32;debug;%(AdditionalIncludeDirectories) false true - _ITERATOR_DEBUG_LEVEL=0;WIN32_LEAN_AND_MEAN;ZLIB_WINAPI;_WINDOWS;UNICODE;WIN32;USE_FREEIMAGE;USE_SQLITE;USE_CRYPTOPP;ENABLE_SYNC;SODIUM_STATIC;PCRE_STATIC;USE_CURL;%(PreprocessorDefinitions) + _ITERATOR_DEBUG_LEVEL=0;WIN32_LEAN_AND_MEAN;ZLIB_WINAPI;_WINDOWS;UNICODE;WIN32;USE_FREEIMAGE;USE_SQLITE;USE_CRYPTOPP;ENABLE_SYNC;SODIUM_STATIC;PCRE_STATIC;USE_CURL;ENABLE_CHAT;%(PreprocessorDefinitions) false MultiThreadedDLL true 3rdparty\libs\x32;%(AdditionalLibraryDirectories) - cryptopp.lib;FreeImage.lib;crypt32.lib;shlwapi.lib;libcurl.lib;cares.lib;libeay32.lib;ssleay32.lib;winhttp.lib;Ws2_32.lib;%(AdditionalDependencies) + cryptopp.lib;FreeImage.lib;crypt32.lib;shlwapi.lib;libcurl.lib;cares.lib;libeay32.lib;ssleay32.lib;winhttp.lib;Ws2_32.lib;sodium.lib;%(AdditionalDependencies) true @@ -213,14 +217,14 @@ ..\..\..\..\include;..\..\..\..\third_party\utf8proc;.;3rdparty\include\curl;3rdparty\include\cares;3rdparty\include\zlib;3rdparty\include;..\..\..\..\include\mega\wincurl;3rdparty\include\cryptopp;3rdparty\include\libsodium;C:\Program Files (x86)\Java\jdk1.8.0_77\include;C:\Program Files (x86)\Java\jdk1.8.0_77\include\win32;debug;%(AdditionalIncludeDirectories) false true - _ITERATOR_DEBUG_LEVEL=0;WIN32_LEAN_AND_MEAN;ZLIB_WINAPI;_WINDOWS;UNICODE;WIN32;USE_FREEIMAGE;USE_SQLITE;USE_CRYPTOPP;ENABLE_SYNC;SODIUM_STATIC;PCRE_STATIC;USE_CURL;%(PreprocessorDefinitions) + _ITERATOR_DEBUG_LEVEL=0;WIN32_LEAN_AND_MEAN;ZLIB_WINAPI;_WINDOWS;UNICODE;WIN32;USE_FREEIMAGE;USE_SQLITE;USE_CRYPTOPP;ENABLE_SYNC;SODIUM_STATIC;PCRE_STATIC;USE_CURL;ENABLE_CHAT;%(PreprocessorDefinitions) false MultiThreadedDLL true 3rdparty\libs\x64;%(AdditionalLibraryDirectories) - cryptopp.lib;FreeImage.lib;crypt32.lib;shlwapi.lib;libcurl.lib;cares.lib;libeay32.lib;ssleay32.lib;winhttp.lib;Ws2_32.lib;%(AdditionalDependencies) + cryptopp.lib;FreeImage.lib;crypt32.lib;shlwapi.lib;libcurl.lib;cares.lib;libeay32.lib;ssleay32.lib;winhttp.lib;Ws2_32.lib;sodium.lib;%(AdditionalDependencies) true @@ -232,7 +236,7 @@ MaxSpeed true true - WIN32_LEAN_AND_MEAN;ZLIB_WINAPI;_WINDOWS;UNICODE;WIN32;USE_FREEIMAGE;USE_SQLITE;USE_CRYPTOPP;ENABLE_SYNC;SODIUM_STATIC;PCRE_STATIC;USE_CURL;%(PreprocessorDefinitions) + WIN32_LEAN_AND_MEAN;ZLIB_WINAPI;_WINDOWS;UNICODE;WIN32;USE_FREEIMAGE;USE_SQLITE;USE_CRYPTOPP;ENABLE_SYNC;SODIUM_STATIC;PCRE_STATIC;USE_CURL;ENABLE_CHAT;%(PreprocessorDefinitions) ..\..\..\..\include;..\..\..\..\third_party\utf8proc;.;3rdparty\include\curl;3rdparty\include\cares;3rdparty\include\zlib;3rdparty\include;..\..\..\..\include\mega\wincurl;3rdparty\include\cryptopp;3rdparty\include\libsodium;C:\Program Files (x86)\Java\jdk1.8.0_77\include;C:\Program Files (x86)\Java\jdk1.8.0_77\include\\win32;release;%(AdditionalIncludeDirectories) @@ -240,7 +244,7 @@ true true 3rdparty\libs\x32;%(AdditionalLibraryDirectories) - cryptopp.lib;FreeImage.lib;crypt32.lib;shlwapi.lib;libcurl.lib;cares.lib;libeay32.lib;ssleay32.lib;winhttp.lib;Ws2_32.lib;%(AdditionalDependencies) + cryptopp.lib;FreeImage.lib;crypt32.lib;shlwapi.lib;libcurl.lib;cares.lib;libeay32.lib;ssleay32.lib;winhttp.lib;Ws2_32.lib;sodium.lib;%(AdditionalDependencies) @@ -249,7 +253,7 @@ MaxSpeed true true - WIN32_LEAN_AND_MEAN;ZLIB_WINAPI;_WINDOWS;UNICODE;WIN32;USE_FREEIMAGE;USE_SQLITE;USE_CRYPTOPP;ENABLE_SYNC;SODIUM_STATIC;PCRE_STATIC;USE_CURL;%(PreprocessorDefinitions) + WIN32_LEAN_AND_MEAN;ZLIB_WINAPI;_WINDOWS;UNICODE;WIN32;USE_FREEIMAGE;USE_SQLITE;USE_CRYPTOPP;ENABLE_SYNC;SODIUM_STATIC;PCRE_STATIC;USE_CURL;ENABLE_CHAT;%(PreprocessorDefinitions) ..\..\..\..\include;..\..\..\..\third_party\utf8proc;.;3rdparty\include\curl;3rdparty\include\cares;3rdparty\include\zlib;3rdparty\include;..\..\..\..\include\mega\wincurl;3rdparty\include\cryptopp;3rdparty\include\libsodium;C:\Program Files (x86)\Java\jdk1.8.0_77\include;C:\Program Files (x86)\Java\jdk1.8.0_77\include\\win32;release;%(AdditionalIncludeDirectories) @@ -257,7 +261,7 @@ true true 3rdparty\libs\x64;%(AdditionalLibraryDirectories) - cryptopp.lib;FreeImage.lib;crypt32.lib;shlwapi.lib;libcurl.lib;cares.lib;libeay32.lib;ssleay32.lib;winhttp.lib;Ws2_32.lib;%(AdditionalDependencies) + cryptopp.lib;FreeImage.lib;crypt32.lib;shlwapi.lib;libcurl.lib;cares.lib;libeay32.lib;ssleay32.lib;winhttp.lib;Ws2_32.lib;sodium.lib;%(AdditionalDependencies) diff --git a/bindings/java/contrib/vs2010/MEGAdll.vcxproj.filters b/bindings/java/contrib/vs2015/MEGAdll.vcxproj.filters similarity index 100% rename from bindings/java/contrib/vs2010/MEGAdll.vcxproj.filters rename to bindings/java/contrib/vs2015/MEGAdll.vcxproj.filters diff --git a/bindings/java/contrib/vs2010/README.md b/bindings/java/contrib/vs2015/README.md similarity index 77% rename from bindings/java/contrib/vs2010/README.md rename to bindings/java/contrib/vs2015/README.md index 9dc7ab40ef..07e912807a 100644 --- a/bindings/java/contrib/vs2010/README.md +++ b/bindings/java/contrib/vs2015/README.md @@ -2,24 +2,24 @@ Visual Studio solution for compiling the SDK library. -This solution, created with Visual Studio 2010 SP1 C++ Express edition, allows to compile `mega.dll` for Windows +This solution, created with Visual Studio 2015 Express edition, allows to compile `mega.dll` for Windows Such library is required to run Java applications using the MEGA SDK and must be provided with its corresponding Java clases. ## How to run the project: -1. Download the 3rd-party libraries from this [link](https://mega.nz/#!osthWZxb!eZmgAXlD80yPcc-W3RGPYo0MTfllTYKGQ-dLVQbMumI). +1. Download the 3rd-party libraries from this [link](https://mega.nz/#!IwMkyYzK!0tW9hv6m0qZ7ysjwPOTPPktVI0lDQfXaCIa8Pj3DtBA). -2. Extract the content to `sdk/bindings/java/contrib/vs2010/`. +2. Extract the content to `sdk/bindings/java/contrib/vs2015/`. -3. Download the Java bindings files created by SWIG from this [link](https://mega.nz/#!alcg3YZJ!BouxSESJClRTE8ReW6i3nBUp6ZrcQAbHYw6FkSaL9qY). +3. Download the Java bindings files created by SWIG from this [link](https://mega.nz/#!g4kHgZ6C!Gn9GFnEUSZwNiW-9j--Ojp7vdUjusTyAtsJuSzITxfQ). 4. Extract the content to `sdk/bindings/java/` 5. Open the solution `MEGAdll.sln` and hit "Build". -6. If success, you should find a `mega.dll` library in `sdk/bindings/java/contrib/vs2010/Release/`. +6. If success, you should find a `mega.dll` library in `sdk/bindings/java/contrib/vs2015/Release/`. ## Notes From 92cb2b896cfe5ee9d3520cc05641ef248963f3de Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Thu, 27 Oct 2016 17:34:24 +0200 Subject: [PATCH 095/103] Update the prebuilt libraries of the Java example for Windows --- examples/java/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/java/README.md b/examples/java/README.md index 2ef1736fbb..62665337b5 100644 --- a/examples/java/README.md +++ b/examples/java/README.md @@ -48,7 +48,7 @@ You have two options, using a prebuilt native library or building it by yourself ### To use a prebuilt library (the easy way), follow these steps: 1. Download and extract the SDK to a folder in your computer ([link](https://github.com/meganz/sdk/archive/master.zip)). -2. Download the prebuilt library (`mega.dll`) along with its corresponding Java classes from [here](https://mega.nz/#!zws2WBjR!NKvG-k_5UeW0R6oo2XWHrThUwQ9YlRXOmKDAi7I7nHg). +2. Download the prebuilt library (`mega.dll`) along with its corresponding Java classes from [here](https://mega.nz/#!N0VmQRDD!HJc5-kUu_EDMwnAFUYueePuhW6pI0ytEff88ZWxHPxc). 3. Extract the content into `sdk/examples/java/`, keeping the folder structure. ### To build the library by yourself @@ -56,9 +56,9 @@ You have two options, using a prebuilt native library or building it by yourself Instead of downloading the prebuilt library, you can build it directly from the sources. 1. Download and extract the SDK to a folder in your computer ([link](https://github.com/meganz/sdk/archive/master.zip)). -2. Follow the instructions in [this guide](https://github.com/meganz/sdk/blob/master/bindings/java/contrib/vs2010/README.md). -3. Copy the new file `mega.dll` from `sdk/bindings/java/contrib/vs2010/Debug` and its dependencies into `sdk/examples/java/libs`. -4. Copy the Java classes from `sdk/bindings/java/nz/mega/sdk` into `sdk/bindings/java/src/nz/mega/sdk`. +2. Follow the instructions in [this guide](https://github.com/meganz/sdk/blob/master/bindings/java/contrib/vs2015/README.md). +3. Copy the new file `mega.dll` from `sdk/bindings/java/contrib/vs2015/Release` and its dependencies into `sdk/examples/java/libs`. +4. Copy the Java classes from `sdk/bindings/java/nz/mega/sdk` into `sdk/examples/java/src/nz/mega/sdk`. ## How to run the application @@ -85,7 +85,7 @@ set PATH=%PATH%;\examples\java\libs - If setting the `PATH` environment variable doesn't solve the solve the problem loading the library, you may try moving `mega.dll` and all its dependencies to the working directory. - A 64 bit version of all required libraries is provided in the `x64` folder inside the `libs` folder of our package with prebuilt libraries. -You can replace the 32-bit DLLs with the 64-bit ones to run the example app in a 64 bit environment. +You can replace the 32-bit DLLs with the 64-bit ones to run the example app in a 64 bit environment. Since all prebuilt libraries are built with Visual Studio 2015, you will need to install the Microsoft Visual Studio 2015 Redistributable Package (32 bit or 64 bit) to use them. - The console example will not work from some IDEs (like Eclipse) as it requires the hidden password entry using the console directly. From 3338088b893104e1fcf732a6787a3e04e46aebb6 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Thu, 27 Oct 2016 18:21:48 +0200 Subject: [PATCH 096/103] Don't use OSX stuff on iOS --- src/http.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/http.cpp b/src/http.cpp index f4c7840b7b..850464829c 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -23,7 +23,7 @@ #include "mega/megaclient.h" #include "mega/logging.h" -#ifdef __APPLE__ +#if defined(__APPLE__) && !(TARGET_OS_IPHONE) #include "mega/osx/osxutils.h" #endif @@ -217,7 +217,7 @@ Proxy *HttpIO::getautoproxy() } #endif -#ifdef __APPLE__ +#if defined(__APPLE__) && !(TARGET_OS_IPHONE) getOSXproxy(proxy); #endif From 5f56b4b6c9cec547aa455c9979e194c89f8636b9 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Fri, 28 Oct 2016 12:47:03 +0200 Subject: [PATCH 097/103] Minor fixes --- src/osx/osxutils.mm | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/osx/osxutils.mm b/src/osx/osxutils.mm index bf9c833e7b..2b556c5f5e 100644 --- a/src/osx/osxutils.mm +++ b/src/osx/osxutils.mm @@ -4,7 +4,7 @@ using namespace mega; -enum {HTTP_PROXY = 0, HTTPS_PROXY}; +enum { HTTP_PROXY = 0, HTTPS_PROXY }; CFTypeRef getValueFromKey(CFDictionaryRef dict, const void *key, CFTypeID type) { @@ -39,9 +39,10 @@ bool getProxyConfiguration(CFDictionaryRef dict, int proxyType, Proxy* proxy) CFNumberRef proxyEnabledRef = (CFNumberRef)getValueFromKey(dict, proxyEnableKey, CFNumberGetTypeID()); if (proxyEnabledRef && CFNumberGetValue(proxyEnabledRef, kCFNumberIntType, &isEnabled) && (isEnabled != 0)) { - if ([(NSDictionary*)dict valueForKey: proxyType == HTTPS_PROXY ? @"HTTPSUser": @"HTTPUser"] != nil) + if ([(NSDictionary*)dict valueForKey: proxyType == HTTP_PROXY ? @"HTTPUser" : @"HTTPSUser"] != nil) { - //Username set, skip proxy configuration. We only allow proxies withouth user/pw credentials + // Username set, skip proxy configuration. We only allow proxies withouth user/pw credentials + // to not have to request the password to the user to read the keychain return false; } @@ -50,23 +51,22 @@ bool getProxyConfiguration(CFDictionaryRef dict, int proxyType, Proxy* proxy) { CFIndex length = CFStringGetLength(hostRef); CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1; - char *buffer = (char *) malloc (maxSize); + char *buffer = new char[maxSize]; if (CFStringGetCString(hostRef, buffer, maxSize, kCFStringEncodingUTF8)) { CFNumberRef portRef = (CFNumberRef)getValueFromKey(dict, portKey, CFNumberGetTypeID()); if (portRef && CFNumberGetValue(portRef, kCFNumberIntType, &port)) { ostringstream oss; - oss << (proxyType == HTTPS_PROXY ? "https://" : "http://") << buffer << ":" << port; + oss << (proxyType == HTTP_PROXY ? "http://" : "https://") << buffer << ":" << port; string link = oss.str(); proxy->setProxyType(Proxy::CUSTOM); proxy->setProxyURL(&link); - free(buffer); + delete [] buffer; return true; } - } - free(buffer); + delete [] buffer; } } return false; @@ -81,9 +81,9 @@ void getOSXproxy(Proxy* proxy) return; } - if (!getProxyConfiguration(proxySettings, HTTP_PROXY, proxy)) + if (!getProxyConfiguration(proxySettings, HTTPS_PROXY, proxy)) { - getProxyConfiguration(proxySettings, HTTPS_PROXY, proxy); + getProxyConfiguration(proxySettings, HTTP_PROXY, proxy); } CFRelease(proxySettings); } From 5653a58e109ae395026fc2810210ffabc68666c5 Mon Sep 17 00:00:00 2001 From: Javier Serrano Date: Fri, 28 Oct 2016 12:53:28 +0200 Subject: [PATCH 098/103] Update version.h --- include/mega/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mega/version.h b/include/mega/version.h index ed3528f181..9c057e09f8 100644 --- a/include/mega/version.h +++ b/include/mega/version.h @@ -2,7 +2,7 @@ #define MEGA_MAJOR_VERSION 2 #endif #ifndef MEGA_MINOR_VERSION -#define MEGA_MINOR_VERSION 6 +#define MEGA_MINOR_VERSION 8 #endif #ifndef MEGA_MICRO_VERSION #define MEGA_MICRO_VERSION 0 From 37f098aa967bfde41b1aa47621d3b9fef8a07167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Hern=C3=A1ndez?= Date: Fri, 28 Oct 2016 13:12:54 +0200 Subject: [PATCH 099/103] Update README.md --- examples/java/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/java/README.md b/examples/java/README.md index 62665337b5..68a093e1e9 100644 --- a/examples/java/README.md +++ b/examples/java/README.md @@ -48,7 +48,7 @@ You have two options, using a prebuilt native library or building it by yourself ### To use a prebuilt library (the easy way), follow these steps: 1. Download and extract the SDK to a folder in your computer ([link](https://github.com/meganz/sdk/archive/master.zip)). -2. Download the prebuilt library (`mega.dll`) along with its corresponding Java classes from [here](https://mega.nz/#!N0VmQRDD!HJc5-kUu_EDMwnAFUYueePuhW6pI0ytEff88ZWxHPxc). +2. Download the prebuilt library (`mega.dll`) along with its corresponding Java classes from [here](https://mega.nz/#!N0VmQRDD!HJc5-kUu_EDMwnAFUYueePuhW6pI0ytEff88ZWxHPxc). Commit: 92cb2b896cfe5ee9d3520cc05641ef248963f3de 3. Extract the content into `sdk/examples/java/`, keeping the folder structure. ### To build the library by yourself From db7baa720a526e6dcc47c8a67c187a041f7348bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Hern=C3=A1ndez?= Date: Mon, 31 Oct 2016 12:03:07 +0100 Subject: [PATCH 100/103] Fix out-of-range access at createChat() --- src/megaapi_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/megaapi_impl.cpp b/src/megaapi_impl.cpp index 3e271abc88..a8360c6da8 100644 --- a/src/megaapi_impl.cpp +++ b/src/megaapi_impl.cpp @@ -13045,7 +13045,7 @@ void MegaApiImpl::sendPendingRequests() } // if 1:1 chat, peer is enforced to be moderator too - if (!group && userpriv->at(1).second != PRIV_MODERATOR) + if (!group && userpriv->at(0).second != PRIV_MODERATOR) { ((MegaTextChatPeerListPrivate*)chatPeers)->setPeerPrivilege(userpriv->at(1).first, PRIV_MODERATOR); } From 565fb4f574e3e9c77cad585ceb9ad7da4a902581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Hern=C3=A1ndez?= Date: Mon, 31 Oct 2016 12:55:37 +0100 Subject: [PATCH 101/103] Add missing file to the list of installed files --- include/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/include/Makefile.am b/include/Makefile.am index fe2dbbfe49..ca23060885 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -36,6 +36,7 @@ nobase_libmegainclude_HEADERS = \ mega/waiter.h \ mega/proxy.h \ mega/pendingcontactrequest.h \ + mega/version.h \ mega/crypto/cryptopp.h \ mega/crypto/sodium.h \ mega/db/sqlite.h \ From b1b2c29b3965ff260359b20e30e47ee082d758a2 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 8 Nov 2016 17:25:07 +0100 Subject: [PATCH 102/103] modified autotools to require sodium to configure --- configure.ac | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index 9279e2968a..1fc9481c46 100644 --- a/configure.ac +++ b/configure.ac @@ -363,8 +363,8 @@ AC_ARG_WITH(sodium, sodium=false ;; yes) - AC_CHECK_HEADERS([sodium/core.h],, [ - AC_MSG_ERROR([sodium/core.h header not found or not usable]) + AC_CHECK_HEADERS([sodium.h],, [ + AC_MSG_ERROR([sodium.h header not found or not usable]) ]) AC_CHECK_LIB(sodium, [sodium_init], [SODIUM_LIBS="-lsodium"],[ AC_MSG_ERROR([Could not find libsodium]) @@ -379,7 +379,7 @@ AC_ARG_WITH(sodium, CXXFLAGS="-I$with_sodium/include $CXXFLAGS" CPPFLAGS="-I$with_sodium/include $CPPFLAGS" - AC_CHECK_HEADERS(sodium/core.h, + AC_CHECK_HEADERS(sodium.h, SODIUM_CXXFLAGS="-I$with_sodium/include" SODIUM_CPPFLAGS="-I$with_sodium/include" SODIUM_LDFLAGS="-L$with_sodium/lib", @@ -391,11 +391,11 @@ AC_ARG_WITH(sodium, CXXFLAGS="-I$with_sodium/src/libsodium/include $CXXFLAGS" CPPFLAGS="-I$with_sodium/src/libsodium/include $CPPFLAGS" - AC_CHECK_HEADERS(sodium/core.h, + AC_CHECK_HEADERS(sodium.h, SODIUM_CXXFLAGS="-I$with_sodium/src/libsodium/include" SODIUM_CPPFLAGS="-I$with_sodium/src/libsodium/include" SODIUM_LDFLAGS="-L$with_sodium/src/libsodium/.libs", - AC_MSG_ERROR([sodium/core.h header not found or not usable]) + AC_MSG_ERROR([sodium.h header not found or not usable]) ) fi @@ -413,8 +413,12 @@ AC_ARG_WITH(sodium, esac ], [AC_MSG_RESULT([--with-sodium not specified]) - AC_CHECK_HEADERS([sodium/core.h], [sodium=true], []) - AC_CHECK_LIB(sodium, [sodium_init], [SODIUM_LIBS="-lsodium"],[]) + AC_CHECK_HEADERS([sodium.h], [sodium=true], [ + AC_MSG_ERROR([sodium.h header not found or not usable]) + ]) + AC_CHECK_LIB(sodium, [sodium_init], [SODIUM_LIBS="-lsodium"],[ + AC_MSG_ERROR([Could not find libsodium]) + ]) ] ) AC_SUBST(SODIUM_CXXFLAGS) From e32d9760c61d50bc3e84ca02c4ca57e3d05682eb Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 8 Nov 2016 18:19:32 +0100 Subject: [PATCH 103/103] sodium required only when enable_chat --- configure.ac | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 1fc9481c46..7ee04adf4c 100644 --- a/configure.ac +++ b/configure.ac @@ -414,10 +414,14 @@ AC_ARG_WITH(sodium, ], [AC_MSG_RESULT([--with-sodium not specified]) AC_CHECK_HEADERS([sodium.h], [sodium=true], [ - AC_MSG_ERROR([sodium.h header not found or not usable]) + if test "x$enable_chat" = "xyes" ; then + AC_MSG_ERROR([sodium.h header not found or not usable]) + fi ]) AC_CHECK_LIB(sodium, [sodium_init], [SODIUM_LIBS="-lsodium"],[ - AC_MSG_ERROR([Could not find libsodium]) + if test "x$enable_chat" = "xyes" ; then + AC_MSG_ERROR([Could not find libsodium]) + fi ]) ] )