From 97ba0b94c5da04f0d03945baa21c338c77c9dc20 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 25 Jan 2015 22:07:28 +0000 Subject: - correct writing of tokens, especially extended - further code optimizations git-svn-id: http://svn.miranda-ng.org/main/trunk@11911 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp | 35 ++++++++------------------- 1 file changed, 10 insertions(+), 25 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 c833d30ffe..e009968b59 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp @@ -20,19 +20,17 @@ using namespace Utilities; const std::string WALogin::NONCE_KEY = "nonce=\""; -WALogin::WALogin(WAConnection* connection, BinTreeNodeReader *reader, BinTreeNodeWriter *writer, const std::string& password) +WALogin::WALogin(WAConnection* connection, const std::string& password) { this->connection = connection; this->password = password; - this->inn = reader; - this->out = writer; this->account_kind = -1; this->expire_date = 0L; } std::vector* WALogin::login(const std::vector& authBlob) { - this->out->streamStart(connection->domain, connection->resource); + connection->out->streamStart(connection->domain, connection->resource); _LOGDATA("sent stream start"); @@ -44,27 +42,17 @@ std::vector* WALogin::login(const std::vector& aut _LOGDATA("send auth, auth blob size %d", authBlob.size()); - this->inn->streamStart(); + connection->in->streamStart(); _LOGDATA("read stream start"); return this->readFeaturesUntilChallengeOrSuccess(); } -BinTreeNodeReader* WALogin::getTreeNodeReader() -{ - return this->inn; -} - -BinTreeNodeWriter* WALogin::getTreeNodeWriter() -{ - return this->out; -} - void WALogin::sendResponse(const std::vector& challengeData) { std::vector* authBlob = this->getAuthBlob(challengeData); - this->out->write(ProtocolTreeNode("response", authBlob)); + connection->out->write(ProtocolTreeNode("response", authBlob)); } void WALogin::sendFeatures() @@ -76,7 +64,7 @@ void WALogin::sendFeatures() ProtocolTreeNode* pictureChild = new ProtocolTreeNode("w:profile:picture") << XATTR("type", "all"); children->push_back(pictureChild); - this->out->write(ProtocolTreeNode("stream:features", NULL, children), true); + connection->out->write(ProtocolTreeNode("stream:features", NULL, children), true); } void WALogin::sendAuth(const std::vector& existingChallenge) @@ -85,7 +73,7 @@ void WALogin::sendAuth(const std::vector& existingChallenge) if (!existingChallenge.empty()) data = this->getAuthBlob(existingChallenge); - this->out->write(ProtocolTreeNode("auth", data) << + connection->out->write(ProtocolTreeNode("auth", data) << XATTR("mechanism", "WAUTH-2") << XATTR("user", connection->user), true); } @@ -110,15 +98,13 @@ std::vector* WALogin::getAuthBlob(const std::vector* WALogin::readFeaturesUntilChallengeOrSuccess() { - while (ProtocolTreeNode *root = this->inn->nextTree()) { + while (ProtocolTreeNode *root = connection->in->nextTree()) { if (ProtocolTreeNode::tagEquals(root, "stream:features")) { connection->supports_receipt_acks = root->getChild("receipt_acks") != NULL; delete root; continue; } if (ProtocolTreeNode::tagEquals(root, "challenge")) { - // base64_decode(*root->data); - // _LOGDATA("Challenge data %s (%d)", root->data->c_str(), root->data->length()); std::vector challengedata(root->data->begin(), root->data->end()); delete root; this->sendResponse(challengedata); @@ -128,7 +114,6 @@ std::vector* WALogin::readFeaturesUntilChallengeOrSuccess() return new std::vector(data.begin(), data.end()); } if (ProtocolTreeNode::tagEquals(root, "success")) { - // base64_decode(*root->data); std::vector* ret = new std::vector(root->data->begin(), root->data->end()); this->parseSuccessNode(root); delete root; @@ -140,6 +125,8 @@ std::vector* WALogin::readFeaturesUntilChallengeOrSuccess() void WALogin::parseSuccessNode(ProtocolTreeNode* node) { + connection->out->setLoggedIn(); + const string &expiration = node->getAttributeValue("expiration"); if (!expiration.empty()) { this->expire_date = atol(expiration.c_str()); @@ -158,7 +145,7 @@ void WALogin::parseSuccessNode(ProtocolTreeNode* node) std::vector WALogin::readSuccess() { - ProtocolTreeNode *node = this->inn->nextTree(); + ProtocolTreeNode *node = connection->in->nextTree(); if (ProtocolTreeNode::tagEquals(node, "failure")) { delete node; @@ -181,8 +168,6 @@ 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