From 58ac4567a402d383c3edb0749b9f2fb88b8422d6 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 25 Jan 2015 19:54:43 +0000 Subject: less pointers, less memory problems git-svn-id: http://svn.miranda-ng.org/main/trunk@11906 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp | 40 +++++++++------------------ 1 file changed, 13 insertions(+), 27 deletions(-) (limited to 'protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp') diff --git a/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp b/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp index 0e0ebc22d7..c833d30ffe 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp @@ -20,25 +20,19 @@ using namespace Utilities; const std::string WALogin::NONCE_KEY = "nonce=\""; -WALogin::WALogin(WAConnection* connection, BinTreeNodeReader *reader, BinTreeNodeWriter *writer, const std::string& domain, const std::string& user, const std::string& resource, const std::string& password, const std::string& push_name) +WALogin::WALogin(WAConnection* connection, BinTreeNodeReader *reader, BinTreeNodeWriter *writer, const std::string& password) { this->connection = connection; + this->password = password; this->inn = reader; this->out = writer; - this->domain = domain; - this->user = user; - this->resource = resource; - this->password = password; - this->push_name = push_name; - this->supports_receipt_acks = false; this->account_kind = -1; this->expire_date = 0L; - this->outputKey = NULL; } std::vector* WALogin::login(const std::vector& authBlob) { - this->out->streamStart(this->domain, this->resource); + this->out->streamStart(connection->domain, connection->resource); _LOGDATA("sent stream start"); @@ -92,7 +86,7 @@ void WALogin::sendAuth(const std::vector& existingChallenge) data = this->getAuthBlob(existingChallenge); this->out->write(ProtocolTreeNode("auth", data) << - XATTR("mechanism", "WAUTH-2") << XATTR("user", this->user), true); + XATTR("mechanism", "WAUTH-2") << XATTR("user", connection->user), true); } std::vector* WALogin::getAuthBlob(const std::vector& nonce) @@ -100,31 +94,25 @@ std::vector* WALogin::getAuthBlob(const std::vectorpassword, nonce, out); - if (this->connection->inputKey != NULL) - delete this->connection->inputKey; - this->connection->inputKey = new KeyStream(out + 40, out + 60); - - if (this->outputKey != NULL) - delete this->outputKey; - this->outputKey = new KeyStream(out, out + 20); + this->connection->inputKey.init(out + 40, out + 60); + this->connection->outputKey.init(out, out + 20); std::vector* list = new std::vector(0); for (int i = 0; i < 4; i++) list->push_back(0); - list->insert(list->end(), this->user.begin(), this->user.end()); + list->insert(list->end(), connection->user.begin(), connection->user.end()); list->insert(list->end(), nonce.begin(), nonce.end()); - this->outputKey->encodeMessage(&((*list)[0]), 0, 4, (int)list->size() - 4); + this->connection->outputKey.encodeMessage(&((*list)[0]), 0, 4, (int)list->size() - 4); return list; } std::vector* WALogin::readFeaturesUntilChallengeOrSuccess() { - ProtocolTreeNode* root; - while ((root = this->inn->nextTree()) != NULL) { + while (ProtocolTreeNode *root = this->inn->nextTree()) { if (ProtocolTreeNode::tagEquals(root, "stream:features")) { - this->supports_receipt_acks = root->getChild("receipt_acks") != NULL; + connection->supports_receipt_acks = root->getChild("receipt_acks") != NULL; delete root; continue; } @@ -166,15 +154,11 @@ void WALogin::parseSuccessNode(ProtocolTreeNode* node) this->account_kind = 0; else this->account_kind = -1; - - if (this->connection->outputKey != NULL) - delete this->connection->outputKey; - this->connection->outputKey = this->outputKey; } std::vector WALogin::readSuccess() { - ProtocolTreeNode* node = this->inn->nextTree(); + ProtocolTreeNode *node = this->inn->nextTree(); if (ProtocolTreeNode::tagEquals(node, "failure")) { delete node; @@ -197,6 +181,8 @@ std::vector WALogin::readSuccess() } else this->account_kind = -1; + this->out->setLoggedIn(); + std::vector data = *node->data; delete node; return data; -- cgit v1.2.3