From b2f86045d3b3dc2a454f127f186429b60e493072 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 6 Feb 2015 23:36:02 +0000 Subject: merge from branch git-svn-id: http://svn.miranda-ng.org/main/trunk@12029 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- .../WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp | 8 +- .../WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.h | 4 +- protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp | 2 +- protocols/WhatsApp/src/WhatsAPI++/ByteArray.h | 2 +- protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp | 4 +- protocols/WhatsApp/src/WhatsAPI++/FMessage.h | 2 +- protocols/WhatsApp/src/WhatsAPI++/KeyStream.cpp | 2 +- .../WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h | 14 +- protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp | 435 +++++++++++---------- protocols/WhatsApp/src/WhatsAPI++/WAConnection.h | 173 ++++---- protocols/WhatsApp/src/WhatsAPI++/WAException.h | 6 +- protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp | 12 +- protocols/WhatsApp/src/WhatsAPI++/WALogin.h | 4 +- protocols/WhatsApp/src/WhatsAPI++/utilities.cpp | 18 +- protocols/WhatsApp/src/WhatsAPI++/utilities.h | 16 +- 15 files changed, 349 insertions(+), 353 deletions(-) (limited to 'protocols/WhatsApp/src/WhatsAPI++') diff --git a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp index 035a3c9d39..00909b6855 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp @@ -134,7 +134,7 @@ void BinTreeNodeWriter::writeAttributes(std::map* attributes) } } -void BinTreeNodeWriter::writeString(const std::string& tag) +void BinTreeNodeWriter::writeString(const std::string &tag) { int token = WAConnection::tokenLookup(tag); if (token != -1) @@ -151,7 +151,7 @@ void BinTreeNodeWriter::writeString(const std::string& tag) } } -void BinTreeNodeWriter::writeJid(std::string* user, const std::string& server) +void BinTreeNodeWriter::writeJid(std::string* user, const std::string &server) { out->write(250); if (user != NULL && !user->empty()) @@ -265,12 +265,12 @@ void BinTreeNodeWriter::write(const ProtocolTreeNode &node, bool needsFlush) this->mutex->lock(); try { this->writeDummyHeader(); - #ifdef _DEBUG + if (bSecure) { string tmp = node.toString(); this->realOut->log(tmp.c_str()); } - #endif + if (node.tag.empty()) out->write(0); else diff --git a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.h b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.h index 5a43d660b1..9b59f26f03 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.h +++ b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.h @@ -47,8 +47,8 @@ private: void writeInt16(int v, ByteArrayOutputStream* out); void writeInt16(int v); void writeAttributes(std::map* attributes); - void writeString(const std::string& tag); - void writeJid(std::string* user, const std::string& server); + void writeString(const std::string &tag); + void writeJid(std::string* user, const std::string &server); void writeToken(int intValue); void writeBytes(unsigned char* bytes, int length); void writeInt24(int v); diff --git a/protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp b/protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp index 7e98847cff..5df55f97ab 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp @@ -51,7 +51,7 @@ void ByteArrayOutputStream::write(unsigned char* b, size_t len) write(b[i]); } -void ByteArrayOutputStream::write(const std::string& s) +void ByteArrayOutputStream::write(const std::string &s) { for (size_t i = 0; i < s.size(); i++) write((unsigned char)s[i]); diff --git a/protocols/WhatsApp/src/WhatsAPI++/ByteArray.h b/protocols/WhatsApp/src/WhatsAPI++/ByteArray.h index 5a3f90d221..d3375d1f3b 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/ByteArray.h +++ b/protocols/WhatsApp/src/WhatsAPI++/ByteArray.h @@ -26,7 +26,7 @@ public: void setPosition(size_t count); void write(int i); void write(unsigned char* c, size_t length); - void write(const std::string& s); + void write(const std::string &s); void setLength(size_t length); __forceinline size_t getCapacity() const { return buf.capacity(); } diff --git a/protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp b/protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp index 23461b30fc..8f5fd2dcc9 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp @@ -57,7 +57,7 @@ FMessage::~FMessage() { } -Key::Key(const std::string& remote_jid, bool from_me, const std::string& id) +Key::Key(const std::string &remote_jid, bool from_me, const std::string &id) { this->remote_jid = remote_jid; this->from_me = from_me; @@ -70,7 +70,7 @@ std::string Key::toString() } -unsigned char FMessage::getMessage_WA_Type(const std::string& type) +unsigned char FMessage::getMessage_WA_Type(const std::string &type) { if (type.empty()) return WA_TYPE_UNDEFINED; diff --git a/protocols/WhatsApp/src/WhatsAPI++/FMessage.h b/protocols/WhatsApp/src/WhatsAPI++/FMessage.h index 9b6a29b038..0d55aa6804 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/FMessage.h +++ b/protocols/WhatsApp/src/WhatsAPI++/FMessage.h @@ -21,7 +21,7 @@ struct Key bool from_me; std::string id; - Key(const std::string& remote_jid, bool from_me, const std::string& id); + Key(const std::string &remote_jid, bool from_me, const std::string &id); std::string toString(); }; diff --git a/protocols/WhatsApp/src/WhatsAPI++/KeyStream.cpp b/protocols/WhatsApp/src/WhatsAPI++/KeyStream.cpp index d027cb9c86..c50e4cbbd1 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/KeyStream.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/KeyStream.cpp @@ -36,7 +36,7 @@ void KeyStream::init(unsigned char* _key, unsigned char* _keyMac) RC4(&this->rc4, sizeof(drop), drop, drop); } -void KeyStream::keyFromPasswordAndNonce(const std::string& pass, const std::vector& nonce, unsigned char *out) +void KeyStream::keyFromPasswordAndNonce(const std::string &pass, const std::vector& nonce, unsigned char *out) { size_t cbSize = nonce.size(); diff --git a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h index aeb1b6e18e..50e0f4033d 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h +++ b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h @@ -55,21 +55,21 @@ public: map *attributes; vector *children; - ProtocolTreeNode(const string& tag, ProtocolTreeNode* child); - ProtocolTreeNode(const string& tag, vector* data = NULL, vector *children = NULL); + ProtocolTreeNode(const string &tag, ProtocolTreeNode *child); + ProtocolTreeNode(const string &tag, vector *data = NULL, vector *children = NULL); ~ProtocolTreeNode(); string toString() const; - ProtocolTreeNode* getChild(const string& id); + ProtocolTreeNode* getChild(const string &id); ProtocolTreeNode* getChild(size_t id); - const string& getAttributeValue(const string& attribute); + const string& getAttributeValue(const string &attribute); vector getAllChildren(); - vector getAllChildren(const string& tag); + vector getAllChildren(const string &tag); std::string getDataAsString() const; - static bool tagEquals(ProtocolTreeNode *node, const string& tag); - static void require(ProtocolTreeNode *node, const string& tag); + static bool tagEquals(ProtocolTreeNode *node, const string &tag); + static void require(ProtocolTreeNode *node, const string &tag); }; ProtocolTreeNode& operator<<(ProtocolTreeNode&, const XATTR&); diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp index f1e671a4de..be44413c52 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp @@ -204,6 +204,8 @@ bool WAConnection::read() throw(WAException) parsePresense(node); else if (ProtocolTreeNode::tagEquals(node, "message")) parseMessage(node); + else if (ProtocolTreeNode::tagEquals(node, "notification")) + parseNotification(node); else if (ProtocolTreeNode::tagEquals(node, "ack")) parseAck(node); else if (ProtocolTreeNode::tagEquals(node, "receipt")) @@ -228,7 +230,7 @@ void WAConnection::readGroupList(ProtocolTreeNode *node, std::vectorgetAttributeValue("s_o"); const string &creation = groupNode->getAttributeValue("creation"); if (m_pGroupEventHandler != NULL) - m_pGroupEventHandler->onGroupInfoFromList(gjid, owner, subject, subject_owner, atoi(subject_t.c_str()), atoi(creation.c_str())); + m_pGroupEventHandler->onGroupInfo(gjid, owner, subject, subject_owner, atoi(subject_t.c_str()), atoi(creation.c_str())); groups.push_back(gjid); } } @@ -260,26 +262,10 @@ void WAConnection::parseAck(ProtocolTreeNode *node) throw(WAException) if (cls == "message" && m_pEventHandler != NULL) { FMessage msg(from, true, id); msg.status = FMessage::STATUS_RECEIVED_BY_SERVER; - m_pEventHandler->onMessageStatusUpdate(&msg); + m_pEventHandler->onMessageStatusUpdate(msg); } } -void WAConnection::parseReceipt(ProtocolTreeNode *node) throw(WAException) -{ - const string &from = node->getAttributeValue("from"); - const string &id = node->getAttributeValue("id"); - const string &ts = node->getAttributeValue("t"); - - if (m_pEventHandler != NULL) { - FMessage msg(from, false, id); - msg.status = FMessage::STATUS_RECEIVED_BY_TARGET; - m_pEventHandler->onMessageStatusUpdate(&msg); - } - - out.write(ProtocolTreeNode("ack") - << XATTR("to", from) << XATTR("id", id) << XATTR("type", "read") << XATTRI("t", time(0))); -} - void WAConnection::parseChatStates(ProtocolTreeNode *node) throw (WAException) { const string &from = node->getAttributeValue("from"); @@ -298,6 +284,99 @@ void WAConnection::parseChatStates(ProtocolTreeNode *node) throw (WAException) } } +void WAConnection::parseIq(ProtocolTreeNode *node) throw(WAException) +{ + const string &type = node->getAttributeValue("type"); + if (type.empty()) + throw WAException("missing 'type' attribute in iq stanza", WAException::CORRUPT_STREAM_EX, 0); + + const string &id = node->getAttributeValue("id"); + const string &from = node->getAttributeValue("from"); + + if (type == "result") { + if (id.empty()) + throw WAException("missing 'id' attribute in iq stanza", WAException::CORRUPT_STREAM_EX, 0); + + std::map::iterator it = this->pending_server_requests.find(id); + if (it != this->pending_server_requests.end()) { + it->second->parse(node, from); + delete it->second; + this->pending_server_requests.erase(id); + } + else if (id.compare(0, this->user.size(), this->user) == 0) { + ProtocolTreeNode *accountNode = node->getChild(0); + ProtocolTreeNode::require(accountNode, "account"); + const string &kind = accountNode->getAttributeValue("kind"); + if (kind == "paid") + this->account_kind = 1; + else if (kind == "free") + this->account_kind = 0; + else + this->account_kind = -1; + + const string &expiration = accountNode->getAttributeValue("expiration"); + if (expiration.empty()) + throw WAException("no expiration"); + + this->expire_date = atol(expiration.c_str()); + if (this->expire_date == 0) + throw WAException("invalid expire date: " + expiration); + if (m_pEventHandler != NULL) + m_pEventHandler->onAccountChange(this->account_kind, this->expire_date); + } + else { + ProtocolTreeNode *childNode = node->getChild(0); + if (ProtocolTreeNode::tagEquals(childNode, "leave")) { + std::vector nodes(childNode->getAllChildren("group")); + for (size_t i = 0; i < nodes.size(); i++) { + ProtocolTreeNode *groupNode = nodes[i]; + const string &gjid = groupNode->getAttributeValue("id"); + if (m_pGroupEventHandler != NULL) + m_pGroupEventHandler->onLeaveGroup(gjid); + } + } + } + } + else if (type == "error") { + std::map::iterator it = this->pending_server_requests.find(id); + if (it != this->pending_server_requests.end()) { + it->second->error(node); + delete it->second; + this->pending_server_requests.erase(id); + } + } + else if (type == "get") { + ProtocolTreeNode *childNode = node->getChild(0); + if (ProtocolTreeNode::tagEquals(childNode, "ping")) { + if (m_pEventHandler != NULL) + m_pEventHandler->onPing(id); + } + else if ((ProtocolTreeNode::tagEquals(childNode, "query") && !from.empty()) ? false : (ProtocolTreeNode::tagEquals(childNode, "relay")) && !from.empty()) { + const string &pin = childNode->getAttributeValue("pin"); + if (!pin.empty() && m_pEventHandler != NULL) { + int timeoutSeconds = atoi(childNode->getAttributeValue("timeout").c_str()); + m_pEventHandler->onRelayRequest(pin, timeoutSeconds, id); + } + } + } + else if (type == "set") { + ProtocolTreeNode *childNode = node->getChild(0); + if (ProtocolTreeNode::tagEquals(childNode, "query")) { + const string &xmlns = childNode->getAttributeValue("xmlns"); + if (xmlns == "jabber:iq:roster") { + std::vector itemNodes(childNode->getAllChildren("item")); + for (size_t i = 0; i < itemNodes.size(); i++) { + ProtocolTreeNode *itemNode = itemNodes[i]; + const string &jid = itemNode->getAttributeValue("jid"); + const string &subscription = itemNode->getAttributeValue("subscription"); + // ask = itemNode->getAttributeValue("ask"); + } + } + } + } + else throw WAException("unknown iq type attribute: " + type, WAException::CORRUPT_STREAM_EX, 0); +} + void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAException) { const string &id = messageNode->getAttributeValue("id"); @@ -321,23 +400,7 @@ void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAExceptio message.status = FMessage::STATUS_SERVER_BOUNCE; if (m_pEventHandler != NULL) - m_pEventHandler->onMessageError(&message, errorCode); - } - else if (typeAttribute == "subject") { - bool receiptRequested = false; - std::vector requestNodes(messageNode->getAllChildren("request")); - for (size_t i = 0; i < requestNodes.size(); i++) { - ProtocolTreeNode *requestNode = requestNodes[i]; - if (requestNode->getAttributeValue("xmlns") == "urn:xmpp:receipts") - receiptRequested = true; - } - - ProtocolTreeNode *bodyNode = messageNode->getChild("body"); - if (bodyNode != NULL&& m_pGroupEventHandler != NULL) - m_pGroupEventHandler->onGroupNewSubject(from, author, bodyNode->getDataAsString(), atoi(attribute_t.c_str())); - - if (receiptRequested) - sendSubjectReceived(from, id); + m_pEventHandler->onMessageError(message, errorCode); } else if (typeAttribute == "text") { ProtocolTreeNode *body = messageNode->getChild("body"); @@ -347,6 +410,7 @@ void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAExceptio FMessage fmessage(from, false, id); fmessage.wants_receipt = false; fmessage.timestamp = atoi(attribute_t.c_str()); + fmessage.remote_resource = messageNode->getAttributeValue("participant"); fmessage.notifyname = messageNode->getAttributeValue("notify"); fmessage.data = body->getDataAsString(); fmessage.status = FMessage::STATUS_UNSENT; @@ -354,8 +418,13 @@ void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAExceptio fmessage.timestamp = time(NULL); fmessage.offline = false; } - if (m_pEventHandler != NULL) - m_pEventHandler->onMessageForMe(&fmessage, false); + + if (fmessage.remote_resource.empty()) { + if (m_pEventHandler != NULL) + m_pEventHandler->onMessageForMe(fmessage); + } + else if (m_pGroupEventHandler != NULL) + m_pGroupEventHandler->onGroupMessage(fmessage); } else if (typeAttribute == "media") { if (from.empty() || id.empty()) @@ -421,120 +490,87 @@ void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAExceptio } if (m_pEventHandler != NULL) - m_pEventHandler->onMessageForMe(&fmessage, false); - } - else if (typeAttribute == "notification") { - logData("Notification node %s", messageNode->toString().c_str()); - bool flag = false; - std::vector children(messageNode->getAllChildren()); - for (size_t i = 0; i < children.size(); i++) { - ProtocolTreeNode *child = children[i]; - if (ProtocolTreeNode::tagEquals(child, "notification")) { - const string &type = child->getAttributeValue("type"); - if (type == "picture" && m_pEventHandler != NULL) { - std::vector children2(child->getAllChildren()); - for (unsigned j = 0; j < children2.size(); j++) { - ProtocolTreeNode *child2 = children2[j]; - if (ProtocolTreeNode::tagEquals(child2, "set")) { - const string &id = child2->getAttributeValue("id"); - const string &author = child2->getAttributeValue("author"); - if (!id.empty()) - m_pEventHandler->onPictureChanged(from, author, true); - } - else if (ProtocolTreeNode::tagEquals(child2, "delete")) { - const string &author = child2->getAttributeValue("author"); - m_pEventHandler->onPictureChanged(from, author, false); - } - } - } - } - else if (ProtocolTreeNode::tagEquals(child, "request")) - flag = true; - } - if (flag) - this->sendNotificationReceived(from, id); + m_pEventHandler->onMessageForMe(fmessage); } } -void WAConnection::parseIq(ProtocolTreeNode *node) throw(WAException) +void WAConnection::parseNotification(ProtocolTreeNode *node) throw(WAException) { - const string &type = node->getAttributeValue("type"); - if (type.empty()) - throw WAException("missing 'type' attribute in iq stanza", WAException::CORRUPT_STREAM_EX, 0); - const string &id = node->getAttributeValue("id"); const string &from = node->getAttributeValue("from"); + const string &type = node->getAttributeValue("type"); + if (type.empty() || from.empty() || m_pEventHandler == NULL) + return; - if (type == "result") { - if (id.empty()) - throw WAException("missing 'id' attribute in iq stanza", WAException::CORRUPT_STREAM_EX, 0); + const string &participant = node->getAttributeValue("participant"); + int ts = atoi(node->getAttributeValue("t").c_str()); - std::map::iterator it = this->pending_server_requests.find(id); - if (it != this->pending_server_requests.end()) { - it->second->parse(node, from); - delete it->second; - this->pending_server_requests.erase(id); - } - else if (id.compare(0, this->user.size(), this->user) == 0) { - ProtocolTreeNode *accountNode = node->getChild(0); - ProtocolTreeNode::require(accountNode, "account"); - const string &kind = accountNode->getAttributeValue("kind"); - if (kind == "paid") - this->account_kind = 1; - else if (kind == "free") - this->account_kind = 0; - else - this->account_kind = -1; + if (type == "contacts") { + std::vector children(node->getAllChildren()); + for (size_t i = 0; i < children.size(); i++) { + ProtocolTreeNode *child = children[i]; - const string &expiration = accountNode->getAttributeValue("expiration"); - if (expiration.empty()) - throw WAException("no expiration"); + const string &jid = node->getAttributeValue("jid"); + if (jid.empty()) continue; - this->expire_date = atol(expiration.c_str()); - if (this->expire_date == 0) - throw WAException("invalid expire date: " + expiration); - if (m_pEventHandler != NULL) - m_pEventHandler->onAccountChange(this->account_kind, this->expire_date); + bool bAdded; + if (ProtocolTreeNode::tagEquals(child, "add")) + bAdded = true; + else if (ProtocolTreeNode::tagEquals(child, "delete")) + bAdded = false; + else + continue; + + m_pEventHandler->onContactChanged(jid, bAdded); } } - else if (type == "error") { - std::map::iterator it = this->pending_server_requests.find(id); - if (it != this->pending_server_requests.end()) { - it->second->error(node); - delete it->second; - this->pending_server_requests.erase(id); + else if (type == "picture") { + std::vector children2(node->getAllChildren()); + for (unsigned j = 0; j < children2.size(); j++) { + ProtocolTreeNode *child2 = children2[j]; + if (ProtocolTreeNode::tagEquals(child2, "set")) { + const string &id = child2->getAttributeValue("id"); + const string &jid = child2->getAttributeValue("jid"); + if (!id.empty()) + m_pEventHandler->onPictureChanged(jid, id, true); + } + else if (ProtocolTreeNode::tagEquals(child2, "delete")) { + const string &jid = child2->getAttributeValue("jid"); + m_pEventHandler->onPictureChanged(jid, id, false); + } } } - else if (type == "get") { - ProtocolTreeNode *childNode = node->getChild(0); - if (ProtocolTreeNode::tagEquals(childNode, "ping")) { - if (m_pEventHandler != NULL) - m_pEventHandler->onPing(id); + // group chats + else if (type == "participant") { + ProtocolTreeNode *subNode = node->getChild("add"); + if (subNode != NULL) { + const string &jid = subNode->getAttributeValue("jid"); + if (m_pGroupEventHandler) + m_pGroupEventHandler->onGroupAddUser(from, jid, ts); } - else if ((ProtocolTreeNode::tagEquals(childNode, "query") && !from.empty()) ? false : (ProtocolTreeNode::tagEquals(childNode, "relay")) && !from.empty()) { - const string &pin = childNode->getAttributeValue("pin"); - if (!pin.empty() && m_pEventHandler != NULL) { - int timeoutSeconds = atoi(childNode->getAttributeValue("timeout").c_str()); - m_pEventHandler->onRelayRequest(pin, timeoutSeconds, id); - } + else if ((subNode = node->getChild("remove")) != NULL) { + const string &jid = subNode->getAttributeValue("jid"); + if (m_pGroupEventHandler) + m_pGroupEventHandler->onGroupRemoveUser(from, jid, ts); } + else return; + } - else if (type == "set") { - ProtocolTreeNode *childNode = node->getChild(0); - if (ProtocolTreeNode::tagEquals(childNode, "query")) { - const string &xmlns = childNode->getAttributeValue("xmlns"); - if (xmlns == "jabber:iq:roster") { - std::vector itemNodes(childNode->getAllChildren("item")); - for (size_t i = 0; i < itemNodes.size(); i++) { - ProtocolTreeNode *itemNode = itemNodes[i]; - const string &jid = itemNode->getAttributeValue("jid"); - const string &subscription = itemNode->getAttributeValue("subscription"); - // ask = itemNode->getAttributeValue("ask"); - } - } - } + else if (type == "subject") { + ProtocolTreeNode *bodyNode = node->getChild("body"); + if (bodyNode != NULL && m_pGroupEventHandler != NULL) + m_pGroupEventHandler->onGroupNewSubject(from, participant, bodyNode->getDataAsString(), ts); + return; // don't set ack } - else throw WAException("unknown iq type attribute: " + type, WAException::CORRUPT_STREAM_EX, 0); + + ProtocolTreeNode sendNode("ack"); + sendNode << XATTR("to", from) << XATTR("id", id) << XATTR("type", type) << XATTR("class", "notification"); + const string &to = node->getAttributeValue("to"); + if (!to.empty()) + sendNode << XATTR("from", to); + if (!participant.empty()) + sendNode << XATTR("participant", participant); + out.write(sendNode); } void WAConnection::parsePresense(ProtocolTreeNode *node) throw(WAException) @@ -544,17 +580,18 @@ void WAConnection::parsePresense(ProtocolTreeNode *node) throw(WAException) if (from.empty()) return; + int ts = atoi(node->getAttributeValue("t").c_str()); if (xmlns == "w" && !from.empty()) { const string &add = node->getAttributeValue("add"); const string &remove = node->getAttributeValue("remove"); const string &status = node->getAttributeValue("status"); if (!add.empty()) { if (m_pGroupEventHandler != NULL) - m_pGroupEventHandler->onGroupAddUser(from, add); + m_pGroupEventHandler->onGroupAddUser(from, add, ts); } else if (!remove.empty()) { if (m_pGroupEventHandler != NULL) - m_pGroupEventHandler->onGroupRemoveUser(from, remove); + m_pGroupEventHandler->onGroupRemoveUser(from, remove, ts); } else if (status == "dirty") { std::map categories = parseCategories(node); @@ -575,6 +612,22 @@ void WAConnection::parsePresense(ProtocolTreeNode *node) throw(WAException) } } +void WAConnection::parseReceipt(ProtocolTreeNode *node) throw(WAException) +{ + const string &from = node->getAttributeValue("from"); + const string &id = node->getAttributeValue("id"); + const string &ts = node->getAttributeValue("t"); + + if (m_pEventHandler != NULL) { + FMessage msg(from, false, id); + msg.status = FMessage::STATUS_RECEIVED_BY_TARGET; + m_pEventHandler->onMessageStatusUpdate(msg); + } + + out.write(ProtocolTreeNode("ack") + << XATTR("to", from) << XATTR("id", id) << XATTR("type", "read") << XATTRI("t", time(0))); +} + std::vector* WAConnection::processGroupSettings(const std::vector& groups) { std::vector* result = new std::vector(groups.size()); @@ -650,29 +703,11 @@ void WAConnection::sendDeleteAccount() throw (WAException) void WAConnection::sendGetGroups() throw (WAException) { m_pMutex->lock(); - std::string id = makeId("get_groups_"); + std::string id = makeId("iq_"); this->pending_server_requests[id] = new IqResultGetGroupsHandler(this, "participating"); - sendGetGroups(id, "participating"); - m_pMutex->unlock(); -} - -void WAConnection::sendGetGroups(const std::string &id, const std::string &type) throw (WAException) -{ - ProtocolTreeNode *listNode = new ProtocolTreeNode("list") - << XATTR("xmlns", "w:g") << XATTR("type", type); - - out.write(ProtocolTreeNode("iq", listNode) - << XATTR("id", id) << XATTR("type", "get") << XATTR("to", "g.us")); -} - -void WAConnection::sendGetOwningGroups() throw (WAException) -{ - m_pMutex->lock(); - std::string id = makeId("get_owning_groups_"); - this->pending_server_requests[id] = new IqResultGetGroupsHandler(this, "owning"); - - sendGetGroups(id, "owning"); + out.write(ProtocolTreeNode("iq", new ProtocolTreeNode("list") << XATTR("type", "participating")) + << XATTR("xmlns", "w:g") << XATTR("id", id) << XATTR("type", "get") << XATTR("to", "g.us")); m_pMutex->unlock(); } @@ -702,10 +737,9 @@ void WAConnection::sendGetServerProperties() throw (WAException) std::string id = makeId("get_server_properties_"); this->pending_server_requests[id] = new IqResultServerPropertiesHandler(this); - ProtocolTreeNode *listNode = new ProtocolTreeNode("list") - << XATTR("xmlns", "w:g") << XATTR("type", "props"); + ProtocolTreeNode *listNode = new ProtocolTreeNode("list") << XATTR("type", "props"); - out.write(ProtocolTreeNode("iq", listNode) + out.write(ProtocolTreeNode("iq", listNode) << XATTR("xmlns", "w:g2") << XATTR("id", id) << XATTR("type", "get") << XATTR("to", "g.us")); } @@ -775,22 +809,14 @@ void WAConnection::sendMessageWithBody(FMessage* message) throw (WAException) delete n; } -void WAConnection::sendMessageReceived(FMessage* message) throw(WAException) +void WAConnection::sendMessageReceived(const FMessage &message) throw(WAException) { out.write(ProtocolTreeNode("receipt") << XATTR("type", "read") - << XATTR("to", message->key.remote_jid) << XATTR("id", message->key.id) << XATTRI("t", (int)time(0))); + << XATTR("to", message.key.remote_jid) << XATTR("id", message.key.id) << XATTRI("t", (int)time(0))); } ///////////////////////////////////////////////////////////////////////////////////////// -void WAConnection::sendNotificationReceived(const std::string &jid, const std::string &id) throw(WAException) -{ - ProtocolTreeNode *child = new ProtocolTreeNode("received") << XATTR("xmlns", "urn:xmpp:receipts"); - - out.write(ProtocolTreeNode("message", child) - << XATTR("id", id) << XATTR("type", "notification") << XATTR("to", jid)); -} - void WAConnection::sendPaused(const std::string &to) throw(WAException) { out.write(ProtocolTreeNode("chatstate", new ProtocolTreeNode("paused")) << XATTR("to", to)); @@ -851,34 +877,26 @@ void WAConnection::sendStatusUpdate(std::string& status) throw (WAException) delete n; } -void WAConnection::sendSubjectReceived(const std::string &to, const std::string &id)throw(WAException) -{ - ProtocolTreeNode *receivedNode = new ProtocolTreeNode("received") << XATTR("xmlns", "urn:xmpp:receipts"); - - out.write(ProtocolTreeNode("message", receivedNode) - << XATTR("to", to) << XATTR("type", "subject") << XATTR("id", id)); -} - ///////////////////////////////////////////////////////////////////////////////////////// // Group chats void WAConnection::sendGetGroupInfo(const std::string &gjid) throw (WAException) { - std::string id = makeId("get_g_info_"); + std::string id = makeId("iq_"); this->pending_server_requests[id] = new IqResultGetGroupInfoHandler(this); - ProtocolTreeNode *queryNode = new ProtocolTreeNode("query") << XATTR("xmlns", "w:g"); - out.write(ProtocolTreeNode("iq", queryNode) + ProtocolTreeNode *queryNode = new ProtocolTreeNode("query") << XATTR("request", "interactive"); + out.write(ProtocolTreeNode("iq", queryNode) << XATTR("xmlns", "w:g2") << XATTR("id", id) << XATTR("type", "get") << XATTR("to", gjid)); } void WAConnection::sendGetParticipants(const std::string &gjid) throw (WAException) { - std::string id = makeId("get_participants_"); + std::string id = makeId("iq_"); this->pending_server_requests[id] = new IqResultGetGroupParticipantsHandler(this); - ProtocolTreeNode *listNode = new ProtocolTreeNode("list") << XATTR("xmlns", "w:g"); - out.write(ProtocolTreeNode("iq", listNode) + ProtocolTreeNode *listNode = new ProtocolTreeNode("list"); + out.write(ProtocolTreeNode("iq", listNode) << XATTR("xmlns", "w:g") << XATTR("id", id) << XATTR("type", "get") << XATTR("to", gjid)); } @@ -895,24 +913,14 @@ void WAConnection::sendCreateGroupChat(const std::string &subject) throw (WAExce { logData("sending create group: %s", subject.c_str()); std::string id = makeId("create_group_"); - this->pending_server_requests[id] = new IqResultCreateGroupChatHandler(this); + this->pending_server_requests[id] = new IqResultCreateGroupChatHandler(this, subject); - ProtocolTreeNode *groupNode = new ProtocolTreeNode("group") - << XATTR("xmlns", "w:g") << XATTR("action", "create") << XATTR("subject", subject); + ProtocolTreeNode *groupNode = new ProtocolTreeNode("group") << XATTR("action", "create") << XATTR("subject", subject); - out.write(ProtocolTreeNode("iq", groupNode) + out.write(ProtocolTreeNode("iq", groupNode) << XATTR("xmlns", "w:g") << XATTR("id", id) << XATTR("type", "set") << XATTR("to", "g.us")); } -void WAConnection::sendEndGroupChat(const std::string &gjid) throw (WAException) -{ - std::string id = makeId("remove_group_"); - - ProtocolTreeNode *groupNode = new ProtocolTreeNode("group") << XATTR("xmlns", "w:g") << XATTR("action", "delete"); - out.write(ProtocolTreeNode("iq", groupNode) - << XATTR("id", id) << XATTR("type", "set") << XATTR("to", gjid)); -} - void WAConnection::sendClearDirty(const std::string &category) throw (WAException) { std::string id = makeId("clean_dirty_"); @@ -924,49 +932,48 @@ void WAConnection::sendClearDirty(const std::string &category) throw (WAExceptio << XATTR("id", id) << XATTR("type", "set") << XATTR("to", "s.whatsapp.net")); } -void WAConnection::sendLeaveGroup(const std::string &gjid) throw (WAException) +void WAConnection::sendJoinLeaveGroup(const char *gjid, bool bJoin) throw (WAException) { - std::string id = makeId("leave_group_"); + std::string id = makeId("iq_"); ProtocolTreeNode *groupNode = new ProtocolTreeNode("group") << XATTR("id", gjid); - ProtocolTreeNode *leaveNode = new ProtocolTreeNode("leave", groupNode) << XATTR("xmlns", "w:g"); - out.write(ProtocolTreeNode("iq", leaveNode) + ProtocolTreeNode *leaveNode = new ProtocolTreeNode((bJoin) ? "join" : "leave", groupNode); + out.write(ProtocolTreeNode("iq", leaveNode) << XATTR("xmlns", "w:g2") << XATTR("id", id) << XATTR("type", "set") << XATTR("to", "g.us")); } -void WAConnection::sendAddParticipants(const std::string &gjid, const std::vector& participants) throw (WAException) +void WAConnection::sendAddParticipants(const std::string &gjid, const std::vector &participants) throw (WAException) { - std::string id = makeId("add_group_participants_"); - this->sendVerbParticipants(gjid, participants, id, "add"); + sendVerbParticipants(gjid, participants, "add"); } -void WAConnection::sendRemoveParticipants(const std::string &gjid, const std::vector& participants) throw (WAException) +void WAConnection::sendRemoveParticipants(const std::string &gjid, const std::vector &participants) throw (WAException) { - std::string id = makeId("remove_group_participants_"); - this->sendVerbParticipants(gjid, participants, id, "remove"); + sendVerbParticipants(gjid, participants, "remove"); } -void WAConnection::sendVerbParticipants(const std::string &gjid, const std::vector& participants, const std::string &id, const std::string &inner_tag) throw (WAException) +void WAConnection::sendVerbParticipants(const std::string &gjid, const std::vector &participants, const std::string &inner_tag) throw (WAException) { + std::string id = makeId("iq_"); + size_t size = participants.size(); std::vector* children = new std::vector(size); for (size_t i = 0; i < size; i++) (*children)[i] = new ProtocolTreeNode("participant") << XATTR("jid", participants[i]); - ProtocolTreeNode *innerNode = new ProtocolTreeNode(inner_tag, NULL, children) - << XATTR("xmlns", "w:g"); + ProtocolTreeNode *innerNode = new ProtocolTreeNode(inner_tag, NULL, children); - out.write(ProtocolTreeNode("iq", innerNode) + out.write(ProtocolTreeNode("iq", innerNode) << XATTR("xmlns", "w:g") << XATTR("id", id) << XATTR("type", "set") << XATTR("to", gjid)); } void WAConnection::sendSetNewSubject(const std::string &gjid, const std::string &subject) throw (WAException) { - std::string id = this->makeId("set_group_subject_"); + std::string id = this->makeId("iq_"); - ProtocolTreeNode *subjectNode = new ProtocolTreeNode("subject") - << XATTR("xmlns", "w:g") << XATTR("value", subject); + std::vector *data = new std::vector(subject.begin(), subject.end()); + ProtocolTreeNode *subjectNode = new ProtocolTreeNode("subject", data); - out.write(ProtocolTreeNode("iq", subjectNode) + out.write(ProtocolTreeNode("iq", subjectNode) << XATTR("xmlns", "w:g2") << XATTR("id", id) << XATTR("type", "set") << XATTR("to", gjid)); } diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h index 6f4fb2b4f2..bddfe1ccd7 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h +++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h @@ -30,42 +30,41 @@ class BinTreeNodeReader; class WAListener { public: - virtual void onMessageForMe(FMessage* paramFMessage, bool paramBoolean) throw (WAException)=0; - virtual void onMessageStatusUpdate(FMessage* paramFMessage)=0; - virtual void onMessageError(FMessage* message, int paramInt)=0; - virtual void onPing(const std::string& paramString) throw (WAException)=0; - virtual void onPingResponseReceived()=0; - virtual void onAvailable(const std::string& paramString, bool paramBoolean)=0; - virtual void onClientConfigReceived(const std::string& paramString)=0; - virtual void onLastSeen(const std::string& paramString1, int paramInt, const string ¶mString2) = 0; - virtual void onIsTyping(const std::string& paramString, bool paramBoolean)=0; - virtual void onAccountChange(int paramInt, time_t paramLong)=0; - virtual void onPrivacyBlockListAdd(const std::string& paramString)=0; - virtual void onPrivacyBlockListClear()=0; - virtual void onDirty(const std::map& paramHashtable)=0; - virtual void onDirtyResponse(int paramHashtable)=0; - virtual void onRelayRequest(const std::string& paramString1, int paramInt, const std::string& paramString2)=0; - virtual void onSendGetPicture(const std::string& jid, const std::vector& data, const std::string& id)=0; - virtual void onPictureChanged(const std::string& from, const std::string& author, bool set)=0; - virtual void onDeleteAccount(bool result)=0; + virtual void onMessageForMe(const FMessage ¶mFMessage) throw (WAException) = 0; + virtual void onMessageStatusUpdate(const FMessage ¶mFMessage) = 0; + virtual void onMessageError(const FMessage &message, int paramInt) = 0; + virtual void onPing(const std::string ¶mString) throw (WAException) = 0; + virtual void onPingResponseReceived() = 0; + virtual void onAvailable(const std::string ¶mString, bool paramBoolean) = 0; + virtual void onClientConfigReceived(const std::string ¶mString) = 0; + virtual void onLastSeen(const std::string ¶mString1, int paramInt, const string ¶mString2) = 0; + virtual void onIsTyping(const std::string ¶mString, bool paramBoolean) = 0; + virtual void onAccountChange(int paramInt, time_t paramLong) = 0; + virtual void onPrivacyBlockListAdd(const std::string ¶mString) = 0; + virtual void onPrivacyBlockListClear() = 0; + virtual void onDirty(const std::map& paramHashtable) = 0; + virtual void onDirtyResponse(int paramHashtable) = 0; + virtual void onRelayRequest(const std::string ¶mString1, int paramInt, const std::string ¶mString2) = 0; + virtual void onSendGetPicture(const std::string &jid, const std::vector& data, const std::string &id) = 0; + virtual void onContactChanged(const std::string &jid, bool added) = 0; + virtual void onPictureChanged(const std::string &jid, const std::string &id, bool set) = 0; + virtual void onDeleteAccount(bool result) = 0; }; class WAGroupListener { public: - virtual void onGroupAddUser(const std::string& paramString1, const std::string& paramString2)=0; - virtual void onGroupRemoveUser(const std::string& paramString1, const std::string& paramString2)=0; - virtual void onGroupNewSubject(const std::string& from, const std::string& author, const std::string& newSubject, int paramInt)=0; - virtual void onServerProperties(std::map* nameValueMap)=0; - virtual void onGroupCreated(const std::string& paramString1, const std::string& paramString2)=0; - virtual void onGroupInfo(const std::string& paramString1, const std::string& paramString2, const std::string& paramString3, const std::string& paramString4, int paramInt1, int paramInt2)=0; - virtual void onGroupInfoFromList(const std::string& paramString1, const std::string& paramString2, const std::string& paramString3, const std::string& paramString4, int paramInt1, int paramInt2)=0; - virtual void onOwningGroups(const std::vector& paramVector)=0; - virtual void onSetSubject(const std::string& paramString)=0; - virtual void onAddGroupParticipants(const std::string& paramString, const std::vector& paramVector, int paramHashtable)=0; - virtual void onRemoveGroupParticipants(const std::string& paramString, const std::vector& paramVector, int paramHashtable)=0; - virtual void onGetParticipants(const std::string& gjid, const std::vector& participants)=0; - virtual void onParticipatingGroups(const std::vector& paramVector)=0; - virtual void onLeaveGroup(const std::string& paramString)=0; + virtual void onGroupAddUser(const std::string &gjid, const std::string &ujid, int ts) = 0; + virtual void onGroupRemoveUser(const std::string &gjid, const std::string &ujid, int ts) = 0; + virtual void onGroupNewSubject(const std::string &from, const std::string &author, const std::string &newSubject, int paramInt) = 0; + virtual void onGroupMessage(const FMessage ¶mFMessage) = 0; + virtual void onServerProperties(std::map* nameValueMap) = 0; + virtual void onGroupCreated(const std::string &gjid, const std::string &nick) = 0; + virtual void onGroupInfo(const std::string &jid, const std::string &owner, const std::string &subject, const std::string &subject_owner, int time_subject, int time_created) = 0; + virtual void onSetSubject(const std::string ¶mString) = 0; + virtual void onAddGroupParticipants(const std::string ¶mString, const std::vector ¶mVector, int paramHashtable) = 0; + virtual void onRemoveGroupParticipants(const std::string ¶mString, const std::vector ¶mVector, int paramHashtable) = 0; + virtual void onGetParticipants(const std::string &gjid, const std::vector &participants) = 0; + virtual void onLeaveGroup(const std::string ¶mString) = 0; }; class GroupSetting { @@ -88,7 +87,7 @@ class WAConnection WAConnection* con; public: IqResultHandler(WAConnection* con) {this->con = con;} - virtual void parse(ProtocolTreeNode* paramProtocolTreeNode, const std::string& paramString) throw (WAException)=0; + virtual void parse(ProtocolTreeNode* paramProtocolTreeNode, const std::string ¶mString) throw (WAException)=0; void error(ProtocolTreeNode* node, int code) { con->logData("WAConnection: error node %s: code = %d", node->getAttributeValue("id").c_str(), code); } @@ -112,7 +111,7 @@ class WAConnection class IqResultPingHandler: public IqResultHandler { public: IqResultPingHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) { + virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { if (this->con->m_pEventHandler != NULL) this->con->m_pEventHandler->onPingResponseReceived(); } @@ -127,23 +126,17 @@ class WAConnection private: std::string type; public: - IqResultGetGroupsHandler(WAConnection* con, const std::string& type ):IqResultHandler(con) {this->type = type;} - virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) { + IqResultGetGroupsHandler(WAConnection* con, const std::string &type ):IqResultHandler(con) {this->type = type;} + virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { std::vector groups; this->con->readGroupList(node, groups); - if (this->con->m_pGroupEventHandler != NULL) { - if (this->type.compare("participating") == 0) - this->con->m_pGroupEventHandler->onParticipatingGroups(groups); - else if (this->type.compare("owning") == 0) - this->con->m_pGroupEventHandler->onOwningGroups(groups); - } } }; class IqResultServerPropertiesHandler: public IqResultHandler { public: IqResultServerPropertiesHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) { + virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { std::vector nodes(node->getAllChildren("prop")); std::map nameValueMap; for (size_t i = 0; i < nodes.size();i++) { @@ -161,7 +154,7 @@ class WAConnection class IqResultPrivayListHandler: public IqResultHandler { public: IqResultPrivayListHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) { + virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { ProtocolTreeNode* queryNode = node->getChild(0); ProtocolTreeNode::require(queryNode, "query"); ProtocolTreeNode* listNode = queryNode->getChild(0); @@ -185,7 +178,7 @@ class WAConnection class IqResultGetGroupInfoHandler: public IqResultHandler { public: IqResultGetGroupInfoHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) { + virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { ProtocolTreeNode* groupNode = node->getChild(0); ProtocolTreeNode::require(groupNode, "group"); const string &owner = groupNode->getAttributeValue("owner"); @@ -201,30 +194,34 @@ class WAConnection class IqResultGetGroupParticipantsHandler: public IqResultHandler { public: IqResultGetGroupParticipantsHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) { - std::vector participants; - this->con->readAttributeList(node, participants, "participant", "jid"); - if (this->con->m_pGroupEventHandler != NULL) + virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { + if (this->con->m_pGroupEventHandler != NULL) { + std::vector participants; + this->con->readAttributeList(node, participants, "participant", "jid"); this->con->m_pGroupEventHandler->onGetParticipants(from, participants); + } } }; class IqResultCreateGroupChatHandler: public IqResultHandler { + std::string subject; public: - IqResultCreateGroupChatHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) { + IqResultCreateGroupChatHandler(WAConnection* con, const std::string &_subject) : + IqResultHandler(con), + subject(_subject) {} + virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { ProtocolTreeNode* groupNode = node->getChild(0); ProtocolTreeNode::require(groupNode, "group"); const string &groupId = groupNode->getAttributeValue("id"); if (!groupId.empty() && con->m_pGroupEventHandler != NULL) - this->con->m_pGroupEventHandler->onGroupCreated(from, groupId); + this->con->m_pGroupEventHandler->onGroupCreated(groupId + "@" + from, subject); } }; class IqResultQueryLastOnlineHandler: public IqResultHandler { public: IqResultQueryLastOnlineHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) { + virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { ProtocolTreeNode* firstChild = node->getChild(0); ProtocolTreeNode::require(firstChild, "query"); const string &seconds = firstChild->getAttributeValue("seconds"); @@ -241,10 +238,10 @@ class WAConnection std::string oldId; std::string newId; public: - IqResultGetPhotoHandler(WAConnection* con, const std::string& jid):IqResultHandler(con) { + IqResultGetPhotoHandler(WAConnection* con, const std::string &jid):IqResultHandler(con) { this->jid = jid; } - virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) { + virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { const string &attributeValue = node->getAttributeValue("type"); if (!attributeValue.empty() && attributeValue == "result" && this->con->m_pEventHandler != NULL) { @@ -272,8 +269,8 @@ class WAConnection private: std::string jid; public: - IqResultSetPhotoHandler(WAConnection* con, const std::string& jid):IqResultHandler(con) {this->jid = jid;} - virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) { + IqResultSetPhotoHandler(WAConnection* con, const std::string &jid):IqResultHandler(con) {this->jid = jid;} + virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { if (this->con->m_pEventHandler != NULL) { ProtocolTreeNode* child = node->getChild("picture"); if (child != NULL) @@ -287,7 +284,7 @@ class WAConnection class IqResultSendDeleteAccount: public IqResultHandler { public: IqResultSendDeleteAccount(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) { + virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { if (this->con->m_pEventHandler != NULL) this->con->m_pEventHandler->onDeleteAccount(true); } @@ -301,14 +298,14 @@ class WAConnection class IqResultClearDirtyHandler: public IqResultHandler { public: IqResultClearDirtyHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) { + virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { } }; class IqSendClientConfigHandler: public IqResultHandler { public: IqSendClientConfigHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) { + virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { con->logData("Clientconfig response %s", node->toString().c_str()); } @@ -334,25 +331,25 @@ private: void parseChatStates(ProtocolTreeNode *node) throw (WAException); void parseIq(ProtocolTreeNode *node) throw(WAException); void parseMessage(ProtocolTreeNode* node) throw(WAException); + void parseNotification(ProtocolTreeNode *node) throw(WAException); void parsePresense(ProtocolTreeNode*) throw(WAException); void parseReceipt(ProtocolTreeNode *node) throw (WAException); std::map parseCategories(ProtocolTreeNode* node) throw(WAException); void sendMessageWithMedia(FMessage* message) throw(WAException); void sendMessageWithBody(FMessage* message) throw(WAException); - ProtocolTreeNode* getReceiptAck(const std::string& to, const std::string& id, const std::string& receiptType) throw(WAException); - std::string makeId(const std::string& prefix); - void sendGetGroups(const std::string& id, const std::string& type) throw (WAException); + ProtocolTreeNode* getReceiptAck(const std::string &to, const std::string &id, const std::string &receiptType) throw(WAException); + std::string makeId(const std::string &prefix); void readGroupList(ProtocolTreeNode* node, std::vector& groups) throw (WAException); - std::string gidToGjid(const std::string& gid); - void readAttributeList(ProtocolTreeNode* node, std::vector& vector, const std::string& tag, const std::string& attribute) throw (WAException); - void sendVerbParticipants(const std::string& gjid, const std::vector& participants, const std::string& id, const std::string& inner_tag) throw (WAException); + std::string gidToGjid(const std::string &gid); + void readAttributeList(ProtocolTreeNode* node, std::vector &vector, const std::string &tag, const std::string &attribute) throw (WAException); + void sendVerbParticipants(const std::string &gjid, const std::vector &participants, const std::string &inner_tag) throw (WAException); bool supportsReceiptAcks(); static ProtocolTreeNode* getMessageNode(FMessage* message, ProtocolTreeNode* node); std::vector* processGroupSettings(const std::vector& gruops); public: - WAConnection(const std::string& user, const std::string& resource, IMutex* mutex, IMutex *write_mutex, ISocketConnection *conn, WAListener* m_pEventHandler, WAGroupListener* m_pGroupEventHandler); + WAConnection(const std::string &user, const std::string &resource, IMutex* mutex, IMutex *write_mutex, ISocketConnection *conn, WAListener* m_pEventHandler, WAGroupListener* m_pGroupEventHandler); virtual ~WAConnection(); std::string user; @@ -374,7 +371,7 @@ public: void logData(const char *format, ...); - static std::string removeResourceFromJid(const std::string& jid); + static std::string removeResourceFromJid(const std::string &jid); void setLogin(WALogin *login); void setVerboseId(bool b); @@ -384,36 +381,32 @@ public: bool read() throw(WAException); void sendPing() throw(WAException); - void sendQueryLastOnline(const std::string& jid) throw (WAException); - void sendPong(const std::string& id) throw(WAException); - void sendComposing(const std::string& to) throw(WAException); + void sendQueryLastOnline(const std::string &jid) throw (WAException); + void sendPong(const std::string &id) throw(WAException); + void sendComposing(const std::string &to) throw(WAException); void sendActive() throw(WAException); void sendInactive() throw(WAException); - void sendPaused(const std::string& to) throw(WAException); - void sendSubjectReceived(const std::string& to, const std::string& id) throw(WAException); - void sendMessageReceived(FMessage* message) throw(WAException); - void sendPresenceSubscriptionRequest(const std::string& to) throw (WAException); - void sendClientConfig(const std::string& sound, const std::string& pushID, bool preview, const std::string& platform) throw(WAException); - void sendClientConfig(const std::string& pushID, bool preview, const std::string& platform, bool defaultSettings, bool groupSettings, const std::vector& groups) throw(WAException); + void sendPaused(const std::string &to) throw(WAException); + void sendMessageReceived(const FMessage &message) throw(WAException); + void sendPresenceSubscriptionRequest(const std::string &to) throw (WAException); + void sendClientConfig(const std::string &sound, const std::string &pushID, bool preview, const std::string &platform) throw(WAException); + void sendClientConfig(const std::string &pushID, bool preview, const std::string &platform, bool defaultSettings, bool groupSettings, const std::vector& groups) throw(WAException); void sendClose() throw (WAException); void sendAvailable() throw (WAException); // U.H. void sendGetPrivacyList() throw (WAException); void sendGetServerProperties() throw (WAException); void sendGetGroups() throw (WAException); - void sendGetOwningGroups() throw (WAException); - void sendCreateGroupChat(const std::string& subject) throw (WAException); - void sendEndGroupChat(const std::string& gjid) throw (WAException); - void sendGetGroupInfo(const std::string& gjid) throw (WAException); - void sendGetParticipants(const std::string& gjid) throw (WAException); - void sendClearDirty(const std::string& category) throw (WAException); - void sendLeaveGroup(const std::string& gjid) throw (WAException); - void sendAddParticipants(const std::string& gjid, const std::vector& participants) throw (WAException); - void sendRemoveParticipants(const std::string& gjid, const std::vector& participants) throw (WAException); - void sendSetNewSubject(const std::string& gjid, const std::string& subject) throw (WAException); + void sendCreateGroupChat(const std::string &subject) throw (WAException); + void sendGetGroupInfo(const std::string &gjid) throw (WAException); + void sendGetParticipants(const std::string &gjid) throw (WAException); + void sendClearDirty(const std::string &category) throw (WAException); + void sendJoinLeaveGroup(const char *gjid, bool bJoin) throw (WAException); + void sendAddParticipants(const std::string &gjid, const std::vector &participants) throw (WAException); + void sendRemoveParticipants(const std::string &gjid, const std::vector &participant) throw (WAException); + void sendSetNewSubject(const std::string &gjid, const std::string &subject) throw (WAException); void sendStatusUpdate(std::string& status) throw (WAException); - void sendGetPicture(const std::string& jid, const std::string& type) throw (WAException); - void sendSetPicture(const std::string& jid, std::vector* data, std::vector* preview) throw (WAException); - void sendNotificationReceived(const std::string& from, const std::string& id) throw(WAException); + void sendGetPicture(const std::string &jid, const std::string &type) throw (WAException); + void sendSetPicture(const std::string &jid, std::vector* data, std::vector* preview) throw (WAException); void sendDeleteAccount() throw(WAException); }; diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAException.h b/protocols/WhatsApp/src/WhatsAPI++/WAException.h index 47d5cdfaf7..4255850ffc 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WAException.h +++ b/protocols/WhatsApp/src/WhatsAPI++/WAException.h @@ -32,9 +32,9 @@ public: static const int SOCKET_EX_SEND = 3; static const int SOCKET_EX_RECV = 4; - WAException(const std::string& err): runtime_error(err) {this->type = 0; this->subtype = 0; this->expire_date = 0;}; - WAException(const std::string& err, int type, int subtype): runtime_error(err), type(type), subtype(subtype), expire_date(0) {}; - WAException(const std::string& err, int type, int subtype, time_t expireDate): runtime_error(err), type(type), subtype(subtype), expire_date(expireDate) {}; + WAException(const std::string &err): runtime_error(err) {this->type = 0; this->subtype = 0; this->expire_date = 0;}; + WAException(const std::string &err, int type, int subtype): runtime_error(err), type(type), subtype(subtype), expire_date(0) {}; + WAException(const std::string &err, int type, int subtype, time_t expireDate): runtime_error(err), type(type), subtype(subtype), expire_date(expireDate) {}; }; #endif /* WAEXCEPTION_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp b/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp index edec990dfa..80be5402ed 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp @@ -8,7 +8,6 @@ #include "WALogin.h" #include "ByteArray.h" #include "ProtocolTreeNode.h" -#include "WAException.h" #include #include #include @@ -18,7 +17,7 @@ using namespace Utilities; -WALogin::WALogin(WAConnection* connection, const std::string& password) +WALogin::WALogin(WAConnection* connection, const std::string &password) { m_pConnection = connection; m_szPassword = password; @@ -97,12 +96,9 @@ std::vector* WALogin::getAuthBlob(const std::vector WALogin::readFeaturesUntilChallengeOrSuccess() { while (ProtocolTreeNode *root = m_pConnection->in.nextTree()) { - #ifdef _DEBUG - { - string tmp = root->toString(); - m_pConnection->logData(tmp.c_str()); - } - #endif + string tmp = root->toString(); + m_pConnection->logData(tmp.c_str()); + if (ProtocolTreeNode::tagEquals(root, "stream:features")) { m_pConnection->supports_receipt_acks = root->getChild("receipt_acks") != NULL; delete root; diff --git a/protocols/WhatsApp/src/WhatsAPI++/WALogin.h b/protocols/WhatsApp/src/WhatsAPI++/WALogin.h index 30c5937810..0d4d30af5b 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WALogin.h +++ b/protocols/WhatsApp/src/WhatsAPI++/WALogin.h @@ -35,7 +35,7 @@ public: void init(unsigned char *_key, unsigned char *_keyMac); - static void keyFromPasswordAndNonce(const std::string& pass, const std::vector& nonce, unsigned char *out); + static void keyFromPasswordAndNonce(const std::string &pass, const std::vector& nonce, unsigned char *out); void decodeMessage(unsigned char* buffer, int macOffset, int offset, const int length); void encodeMessage(unsigned char* buffer, int macOffset, int offset, const int length); }; @@ -58,7 +58,7 @@ public: int m_iAccountKind; std::string m_szPassword; - WALogin(WAConnection* connection, const std::string& password); + WALogin(WAConnection* connection, const std::string &password); ~WALogin(); std::vector login(const std::vector &blob); diff --git a/protocols/WhatsApp/src/WhatsAPI++/utilities.cpp b/protocols/WhatsApp/src/WhatsAPI++/utilities.cpp index 0734c34210..1c6f28e009 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/utilities.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/utilities.cpp @@ -14,7 +14,7 @@ const static char digits[] = { 'u', 'v', 'w', 'x', 'y', 'z' }; -std::string reverseString(const std::string& str) +std::string reverseString(const std::string &str) { return std::string(str.rbegin(), str.rend()); } @@ -51,7 +51,7 @@ std::string itoa(int value, unsigned int base) } -std::string processIdentity(const std::string& id) +std::string processIdentity(const std::string &id) { std::string buffer_str = reverseString(id); @@ -69,7 +69,7 @@ std::string processIdentity(const std::string& id) return buffer_str; } -void debug(const std::string& msg) +void debug(const std::string &msg) { #ifdef _LOGWIN32 cout << "DEBUG: " << msg << endl; @@ -153,7 +153,7 @@ time_t parseBBDate(const string& s) return mktime(&timeinfo); } -long long parseLongLong(const std::string& str) +long long parseLongLong(const std::string &str) { std::stringstream sstr(str); long long val; @@ -235,7 +235,7 @@ vector* loadFileToBytes(const string& path) return bytes; } -bool fileExists(const std::string& path) +bool fileExists(const std::string &path) { return _access(path.c_str(), 0) == 0; } @@ -260,7 +260,7 @@ string removeWaDomainFromJid(const string& jid) return jid; } -string getNameFromPath(const std::string& path) +string getNameFromPath(const std::string &path) { size_t i = path.rfind('/'); if (i == string::npos) @@ -270,17 +270,17 @@ string getNameFromPath(const std::string& path) return path.substr(i); } -vector* getChallengeData(const std::string& challengeFile) +vector* getChallengeData(const std::string &challengeFile) { return loadFileToBytes(challengeFile); } -bool saveChallengeData(const std::vector& data, const std::string& challengeFile) +bool saveChallengeData(const std::vector& data, const std::string &challengeFile) { return saveBytesToFile(data, challengeFile); } -std::string utf8_to_utf16(const std::string& utf8) +std::string utf8_to_utf16(const std::string &utf8) { std::vector unicode; size_t i = 0; diff --git a/protocols/WhatsApp/src/WhatsAPI++/utilities.h b/protocols/WhatsApp/src/WhatsAPI++/utilities.h index 4df6fde13d..5f5dd5713a 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/utilities.h +++ b/protocols/WhatsApp/src/WhatsAPI++/utilities.h @@ -38,20 +38,20 @@ using namespace std; // these functions must be declared somewhere in the same linking module std::string base64_encode(void*, size_t); -void md5_string(const std::string& data, unsigned char digest[16]); +void md5_string(const std::string &data, unsigned char digest[16]); namespace Utilities{ string getMcc(); string getMnc(); string reverseString(const string& str); - string processIdentity(const std::string& password); + string processIdentity(const std::string &password); int64_t randLong(); int64_t absLong(int64_t num); string str(int64_t number, int radix); std::string itoa(int value, unsigned int base); std::string intToStr(int i); std::string doubleToStr(double d); - long long parseLongLong(const std::string& str); + long long parseLongLong(const std::string &str); time_t parseBBDate(const string& s); long long getCurrentTimeMillis(); std::string bytesToHex(unsigned char* bytes, int length); @@ -60,11 +60,11 @@ namespace Utilities{ bool saveBytesToFile(const string& data, const string& filePath); bool saveBytesToFile(const std::vector& data, const string& filePath); string removeWaDomainFromJid(const string& jid); - string getNameFromPath(const std::string& path); + string getNameFromPath(const std::string &path); vector* loadFileToBytes(const string& path); - bool fileExists(const std::string& path); - std::vector* getChallengeData(const std::string& file); - bool saveChallengeData(const std::vector& data, const std::string& file); - std::string utf8_to_utf16(const std::string& utf8); + bool fileExists(const std::string &path); + std::vector* getChallengeData(const std::string &file); + bool saveChallengeData(const std::vector& data, const std::string &file); + std::string utf8_to_utf16(const std::string &utf8); } #endif -- cgit v1.2.3