summaryrefslogtreecommitdiff
path: root/protocols/WhatsApp/src/WhatsAPI++
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/WhatsApp/src/WhatsAPI++')
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp30
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp26
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp44
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/WALogin.h4
4 files changed, 52 insertions, 52 deletions
diff --git a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp
index 99c186f126..0cb12b2e93 100644
--- a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp
+++ b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp
@@ -183,25 +183,25 @@ ReadData* BinTreeNodeReader::readString(int token)
}
return ret;
- case 255:
- bSize = readInt8(this->in);
- {
- int size = bSize & 0x7f;
- int numnibbles = size * 2 - ((bSize & 0x80) ? 1 : 0);
-
+ case 255:
+ bSize = readInt8(this->in);
+ {
+ int size = bSize & 0x7f;
+ int numnibbles = size * 2 - ((bSize & 0x80) ? 1 : 0);
+
std::vector<unsigned char> tmp(size);
fillArray(tmp, size, this->in);
- std::string s;
- for (int i = 0; i < numnibbles; i++) {
- char c = (tmp[i / 2] >> (4 - ((i & 1) << 2))) & 0xF;
- if (c < 10) s += (c + '0');
- else s += (c - 10 + '-');
- }
-
+ std::string s;
+ for (int i = 0; i < numnibbles; i++) {
+ char c = (tmp[i / 2] >> (4 - ((i & 1) << 2))) & 0xF;
+ if (c < 10) s += (c + '0');
+ else s += (c - 10 + '-');
+ }
+
ret->type = STRING;
ret->data = new std::string(s);
- }
- return ret;
+ }
+ return ret;
case 250:
std::string* user = readStringAsString();
diff --git a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp
index cb3bc19258..7ef362ef4b 100644
--- a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp
+++ b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp
@@ -12,35 +12,35 @@
static std::string nilstr;
-ProtocolTreeNode::ProtocolTreeNode(const string& tag, vector<unsigned char>* data, vector<ProtocolTreeNode*> *children)
+ProtocolTreeNode::ProtocolTreeNode(const string &_tag, vector<unsigned char>* _data, vector<ProtocolTreeNode*> *_children) :
+ tag(_tag)
{
- this->tag = tag;
- this->data = data;
- this->attributes = NULL;
- this->children = children;
+ data = _data;
+ attributes = NULL;
+ children = _children;
}
-ProtocolTreeNode::ProtocolTreeNode(const string& tag, ProtocolTreeNode* child)
+ProtocolTreeNode::ProtocolTreeNode(const string &_tag, ProtocolTreeNode *_child) :
+ tag(_tag)
{
- this->tag = tag;
this->data = NULL;
this->attributes = NULL;
- this->children = new std::vector<ProtocolTreeNode*>(1);
- (*this->children)[0] = child;
+ this->children = new std::vector<ProtocolTreeNode*>();
+ children->push_back(_child);
}
ProtocolTreeNode::~ProtocolTreeNode()
{
- if (this->attributes != NULL)
- delete this->attributes;
+ delete this->attributes;
+
if (this->children != NULL) {
for (size_t i = 0; i < this->children->size(); i++)
if (this->children->at(i) != NULL)
delete this->children->at(i);
delete this->children;
}
- if (this->data != NULL)
- delete data;
+
+ delete data;
}
diff --git a/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp b/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp
index 40471ae559..dd29850885 100644
--- a/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp
+++ b/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp
@@ -22,7 +22,7 @@ const std::string WALogin::NONCE_KEY = "nonce=\"";
WALogin::WALogin(WAConnection* connection, const std::string& password)
{
- this->connection = connection;
+ m_pConnection = connection;
this->password = password;
this->account_kind = -1;
this->expire_date = 0L;
@@ -30,21 +30,21 @@ WALogin::WALogin(WAConnection* connection, const std::string& password)
std::vector<unsigned char>* WALogin::login(const std::vector<unsigned char>& authBlob)
{
- connection->out->streamStart(connection->domain, connection->resource);
+ m_pConnection->out->streamStart(m_pConnection->domain, m_pConnection->resource);
- connection->logData("sent stream start");
+ m_pConnection->logData("sent stream start");
sendFeatures();
- connection->logData("sent features");
+ m_pConnection->logData("sent features");
sendAuth(authBlob);
- connection->logData("send auth, auth blob size %d", authBlob.size());
+ m_pConnection->logData("send auth, auth blob size %d", authBlob.size());
- connection->in->streamStart();
+ m_pConnection->in->streamStart();
- connection->logData("read stream start");
+ m_pConnection->logData("read stream start");
return this->readFeaturesUntilChallengeOrSuccess();
}
@@ -52,7 +52,7 @@ std::vector<unsigned char>* WALogin::login(const std::vector<unsigned char>& aut
void WALogin::sendResponse(const std::vector<unsigned char>& challengeData)
{
std::vector<unsigned char>* authBlob = this->getAuthBlob(challengeData);
- connection->out->write(ProtocolTreeNode("response", authBlob));
+ m_pConnection->out->write(ProtocolTreeNode("response", authBlob));
}
void WALogin::sendFeatures()
@@ -64,7 +64,7 @@ void WALogin::sendFeatures()
ProtocolTreeNode* pictureChild = new ProtocolTreeNode("w:profile:picture") << XATTR("type", "all");
children->push_back(pictureChild);
- connection->out->write(ProtocolTreeNode("stream:features", NULL, children), true);
+ m_pConnection->out->write(ProtocolTreeNode("stream:features", NULL, children), true);
}
void WALogin::sendAuth(const std::vector<unsigned char>& existingChallenge)
@@ -73,8 +73,8 @@ void WALogin::sendAuth(const std::vector<unsigned char>& existingChallenge)
if (!existingChallenge.empty())
data = this->getAuthBlob(existingChallenge);
- connection->out->write(ProtocolTreeNode("auth", data) <<
- XATTR("mechanism", "WAUTH-2") << XATTR("user", connection->user), true);
+ m_pConnection->out->write(ProtocolTreeNode("auth", data) <<
+ XATTR("mechanism", "WAUTH-2") << XATTR("user", m_pConnection->user), true);
}
std::vector<unsigned char>* WALogin::getAuthBlob(const std::vector<unsigned char>& nonce)
@@ -82,31 +82,31 @@ std::vector<unsigned char>* WALogin::getAuthBlob(const std::vector<unsigned char
unsigned char out[4*20];
KeyStream::keyFromPasswordAndNonce(this->password, nonce, out);
- this->connection->inputKey.init(out + 40, out + 60);
- this->connection->outputKey.init(out, out + 20);
+ m_pConnection->inputKey.init(out + 40, out + 60);
+ m_pConnection->outputKey.init(out, out + 20);
std::vector<unsigned char>* list = new std::vector<unsigned char>(0);
for (int i = 0; i < 4; i++)
list->push_back(0);
- list->insert(list->end(), connection->user.begin(), connection->user.end());
+ list->insert(list->end(), m_pConnection->user.begin(), m_pConnection->user.end());
list->insert(list->end(), nonce.begin(), nonce.end());
- this->connection->outputKey.encodeMessage(&((*list)[0]), 0, 4, (int)list->size() - 4);
+ m_pConnection->outputKey.encodeMessage(&((*list)[0]), 0, 4, (int)list->size() - 4);
return list;
}
std::vector<unsigned char>* WALogin::readFeaturesUntilChallengeOrSuccess()
{
- while (ProtocolTreeNode *root = connection->in->nextTree()) {
+ while (ProtocolTreeNode *root = m_pConnection->in->nextTree()) {
#ifdef _DEBUG
{
string tmp = root->toString();
- connection->logData(tmp.c_str());
+ m_pConnection->logData(tmp.c_str());
}
#endif
if (ProtocolTreeNode::tagEquals(root, "stream:features")) {
- connection->supports_receipt_acks = root->getChild("receipt_acks") != NULL;
+ m_pConnection->supports_receipt_acks = root->getChild("receipt_acks") != NULL;
delete root;
continue;
}
@@ -114,9 +114,9 @@ std::vector<unsigned char>* WALogin::readFeaturesUntilChallengeOrSuccess()
std::vector<unsigned char> challengedata(root->data->begin(), root->data->end());
delete root;
this->sendResponse(challengedata);
- connection->logData("Send response");
+ m_pConnection->logData("Send response");
std::vector<unsigned char> data = this->readSuccess();
- connection->logData("Read success");
+ m_pConnection->logData("Read success");
return new std::vector<unsigned char>(data.begin(), data.end());
}
if (ProtocolTreeNode::tagEquals(root, "success")) {
@@ -131,7 +131,7 @@ std::vector<unsigned char>* WALogin::readFeaturesUntilChallengeOrSuccess()
void WALogin::parseSuccessNode(ProtocolTreeNode* node)
{
- connection->out->setSecure();
+ m_pConnection->out->setSecure();
const string &expiration = node->getAttributeValue("expiration");
if (!expiration.empty()) {
@@ -151,7 +151,7 @@ void WALogin::parseSuccessNode(ProtocolTreeNode* node)
std::vector<unsigned char> WALogin::readSuccess()
{
- ProtocolTreeNode *node = connection->in->nextTree();
+ ProtocolTreeNode *node = m_pConnection->in->nextTree();
if (ProtocolTreeNode::tagEquals(node, "failure")) {
delete node;
diff --git a/protocols/WhatsApp/src/WhatsAPI++/WALogin.h b/protocols/WhatsApp/src/WhatsAPI++/WALogin.h
index 440f34f71b..05e654549e 100644
--- a/protocols/WhatsApp/src/WhatsAPI++/WALogin.h
+++ b/protocols/WhatsApp/src/WhatsAPI++/WALogin.h
@@ -25,7 +25,7 @@ private:
RC4_KEY rc4;
unsigned char key[20], keyMac[20];
int seq;
- HMAC_CTX hmac;
+ HMAC_CTX hmac;
void hmacsha1(unsigned char* text, int textLength, unsigned char *out);
@@ -44,7 +44,7 @@ public:
class WALogin {
private:
static const std::string NONCE_KEY;
- WAConnection *connection;
+ WAConnection *m_pConnection;
std::vector<unsigned char>* getAuthBlob(const std::vector<unsigned char>& nonce);
void sendResponse(const std::vector<unsigned char>& challengeData);