From c4562ac53bba7b587af2fcb5eebd6051b11d1f04 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 29 Jan 2015 13:41:23 +0000 Subject: - two new's replaced with aggregates - member's name unification git-svn-id: http://svn.miranda-ng.org/main/trunk@11948 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- .../WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp | 76 +++---- protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp | 219 ++++++++++----------- protocols/WhatsApp/src/WhatsAPI++/WAConnection.h | 93 ++++----- protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp | 16 +- protocols/WhatsApp/src/chat.cpp | 4 +- protocols/WhatsApp/src/connection.cpp | 13 +- protocols/WhatsApp/src/contacts.cpp | 8 +- protocols/WhatsApp/src/proto.cpp | 2 +- protocols/WhatsApp/src/proto.h | 4 +- 9 files changed, 206 insertions(+), 229 deletions(-) (limited to 'protocols/WhatsApp/src') diff --git a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp index 0dea74a6ac..cdd39a6509 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp @@ -23,26 +23,26 @@ BinTreeNodeWriter::BinTreeNodeWriter(WAConnection* conn, ISocketConnection* conn void BinTreeNodeWriter::writeDummyHeader() { int num = 3; - this->dataBegin = (int)this->out->getPosition(); + this->dataBegin = (int)out->getPosition(); int num2 = this->dataBegin + num; - this->out->setLength(num2); - this->out->setPosition(num2); + out->setLength(num2); + out->setPosition(num2); } void BinTreeNodeWriter::processBuffer() { unsigned char num = 0; if (bSecure) { - long num2 = (long)this->out->getLength() + 4L; - this->out->setLength(num2); - this->out->setPosition(num2); + long num2 = (long)out->getLength() + 4L; + out->setLength(num2); + out->setPosition(num2); num = 8; } - long num3 = (long)this->out->getLength() - 3L - (long) this->dataBegin; + long num3 = (long)out->getLength() - 3L - (long) this->dataBegin; if (num3 >= 1048576L) throw WAException("Buffer too large: " + num3, WAException::CORRUPT_STREAM_EX, 0); - std::vector& buffer = this->out->getBuffer(); + std::vector& buffer = out->getBuffer(); this->realOut->dump(buffer.data(), (int)buffer.size()); if (bSecure) { int num4 = (int)num3 - 4; @@ -57,19 +57,19 @@ void BinTreeNodeWriter::streamStart(std::string domain, std::string resource) { this->mutex->lock(); try { - this->out->setPosition(0); - this->out->setLength(0); - this->out->write('W'); - this->out->write('A'); - this->out->write(1); - this->out->write(5); + out->setPosition(0); + out->setLength(0); + out->write('W'); + out->write('A'); + out->write(1); + out->write(5); std::map attributes; attributes["to"] = domain; attributes["resource"] = resource; this->writeDummyHeader(); this->writeListStart((int)attributes.size() * 2 + 1); - this->out->write(1); + out->write(1); this->writeAttributes(&attributes); this->processBuffer(); this->flushBuffer(true, 0); @@ -84,21 +84,21 @@ void BinTreeNodeWriter::streamStart(std::string domain, std::string resource) void BinTreeNodeWriter::writeListStart(int i) { if (i == 0) { - this->out->write(0); + out->write(0); } else if (i < 256) { - this->out->write(248); + out->write(248); writeInt8(i); } else { - this->out->write(249); + out->write(249); writeInt16(i); } } void BinTreeNodeWriter::writeInt8(int v) { - this->out->write(v & 0xFF); + out->write(v & 0xFF); } void BinTreeNodeWriter::writeInt16(int v, ISocketConnection* o) @@ -148,7 +148,7 @@ void BinTreeNodeWriter::writeString(const std::string& tag) void BinTreeNodeWriter::writeJid(std::string* user, const std::string& server) { - this->out->write(250); + out->write(250); if (user != NULL && !user->empty()) writeString(*user); else @@ -161,30 +161,30 @@ void BinTreeNodeWriter::writeJid(std::string* user, const std::string& server) void BinTreeNodeWriter::writeToken(int intValue) { if (intValue & 0x100) { - this->out->write(236); - this->out->write(intValue & 0xFF); + out->write(236); + out->write(intValue & 0xFF); } - else this->out->write(intValue); + else out->write(intValue); } void BinTreeNodeWriter::writeBytes(unsigned char* bytes, int length) { if (length >= 256) { - this->out->write(253); + out->write(253); writeInt24(length); } else { - this->out->write(252); + out->write(252); writeInt8(length); } - this->out->write(bytes, length); + out->write(bytes, length); } void BinTreeNodeWriter::writeInt24(int v) { - this->out->write((v & 0xFF0000) >> 16); - this->out->write((v & 0xFF00) >> 8); - this->out->write(v & 0xFF); + out->write((v & 0xFF0000) >> 16); + out->write((v & 0xFF00) >> 8); + out->write(v & 0xFF); } void BinTreeNodeWriter::writeInternal(const ProtocolTreeNode &node) @@ -216,22 +216,22 @@ void BinTreeNodeWriter::flushBuffer(bool flushNetwork, int startingOffset) this->processBuffer(); } catch (WAException& ex) { - this->out->setPosition(0); - this->out->setLength(0); + out->setPosition(0); + out->setLength(0); throw ex; } - std::vector buffer(this->out->getBuffer().begin(), this->out->getBuffer().end()); - int num = (int)(this->out->getLength() - (long)startingOffset); - if (flushNetwork && ((long)this->out->getCapacity() - this->out->getLength() < 3L || this->out->getLength() > 4096L)) { + std::vector buffer(out->getBuffer().begin(), out->getBuffer().end()); + int num = (int)(out->getLength() - (long)startingOffset); + if (flushNetwork && ((long)out->getCapacity() - out->getLength() < 3L || out->getLength() > 4096L)) { delete this->out; this->out = new ByteArrayOutputStream(4096); } if (flushNetwork) { this->realOut->write(buffer, startingOffset, num); - this->out->setPosition(0); - this->out->setLength(0); + out->setPosition(0); + out->setLength(0); } } @@ -240,7 +240,7 @@ void BinTreeNodeWriter::streamEnd() this->mutex->lock(); try { writeListStart(1); - this->out->write(2); + out->write(2); flushBuffer(true); } catch (exception& ex) { @@ -267,7 +267,7 @@ void BinTreeNodeWriter::write(const ProtocolTreeNode &node, bool needsFlush) } #endif if (node.tag.empty()) - this->out->write(0); + out->write(0); else writeInternal(node); flushBuffer(needsFlush); diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp index 27dd4aff3a..e1175d26a6 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp @@ -96,14 +96,15 @@ void WAConnection::logData(const char *format, ...) ///////////////////////////////////////////////////////////////////////////////////////// -WAConnection::WAConnection(const std::string &user, const std::string &resource, IMutex *mutex, WAListener *event_handler, WAGroupListener *group_event_handler) +WAConnection::WAConnection(const std::string &user, const std::string &resource, IMutex *mutex, IMutex *write_mutex, ISocketConnection *conn, WAListener *pEventHandler, WAGroupListener *pGroupEventHandler) : + in(this, conn), + out(this, conn, write_mutex) { - this->mutex = mutex; - this->event_handler = event_handler; - this->group_event_handler = group_event_handler; + m_pMutex = mutex; + m_pEventHandler = pEventHandler; + m_pGroupEventHandler = pGroupEventHandler; - this->in = NULL; - this->out = NULL; + rawConn = conn; this->retry = true; @@ -122,26 +123,17 @@ WAConnection::WAConnection(const std::string &user, const std::string &resource, WAConnection::~WAConnection() { - delete this->in; - delete this->out; std::map::iterator it; for (it = this->pending_server_requests.begin(); it != this->pending_server_requests.end(); it++) delete it->second; } -void WAConnection::init(IMutex *mutex, ISocketConnection *conn) -{ - rawConn = conn; - in = new BinTreeNodeReader(this, conn); - out = new BinTreeNodeWriter(this, conn, mutex); -} - -std::string WAConnection::gidToGjid(const std::string& gid) +std::string WAConnection::gidToGjid(const std::string &gid) { return gid + "@g.us"; } -std::string WAConnection::makeId(const std::string& prefix) +std::string WAConnection::makeId(const std::string &prefix) { this->iqid++; std::string id; @@ -153,7 +145,7 @@ std::string WAConnection::makeId(const std::string& prefix) return id; } -ProtocolTreeNode* WAConnection::getReceiptAck(const std::string& to, const std::string& id, const std::string& receiptType) throw(WAException) +ProtocolTreeNode* WAConnection::getReceiptAck(const std::string &to, const std::string &id, const std::string &receiptType) throw(WAException) { ProtocolTreeNode *ackNode = new ProtocolTreeNode("ack") << XATTR("xmlns", "urn:xmpp:receipts") << XATTR("type", receiptType); @@ -166,7 +158,7 @@ bool WAConnection::supportsReceiptAcks() return supports_receipt_acks; } -std::string WAConnection::removeResourceFromJid(const std::string& jid) +std::string WAConnection::removeResourceFromJid(const std::string &jid) { size_t slashidx = jid.find('/'); if (slashidx == std::string::npos) @@ -193,7 +185,7 @@ bool WAConnection::read() throw(WAException) { ProtocolTreeNode *node; try { - node = this->in->nextTree(); + node = in.nextTree(); this->lastTreeRead = time(NULL); } catch (exception& ex) { @@ -237,8 +229,8 @@ void WAConnection::readGroupList(ProtocolTreeNode *node, std::vectorgetAttributeValue("s_t"); const string &subject_owner = groupNode->getAttributeValue("s_o"); const string &creation = groupNode->getAttributeValue("creation"); - if (this->group_event_handler != NULL) - this->group_event_handler->onGroupInfoFromList(gjid, owner, subject, subject_owner, atoi(subject_t.c_str()), atoi(creation.c_str())); + if (m_pGroupEventHandler != NULL) + m_pGroupEventHandler->onGroupInfoFromList(gjid, owner, subject, subject_owner, atoi(subject_t.c_str()), atoi(creation.c_str())); groups.push_back(gjid); } } @@ -267,10 +259,10 @@ void WAConnection::parseAck(ProtocolTreeNode *node) throw(WAException) const string &id = node->getAttributeValue("id"); const string &ts = node->getAttributeValue("t"); - if (cls == "message" && this->event_handler != NULL) { + if (cls == "message" && m_pEventHandler != NULL) { FMessage msg(from, true, id); msg.status = FMessage::STATUS_RECEIVED_BY_SERVER; - this->event_handler->onMessageStatusUpdate(&msg); + m_pEventHandler->onMessageStatusUpdate(&msg); } } @@ -282,12 +274,12 @@ void WAConnection::parseChatStates(ProtocolTreeNode *node) throw (WAException) for (size_t i = 0; i < messageChildren.size(); i++) { ProtocolTreeNode *childNode = messageChildren[i]; if (ProtocolTreeNode::tagEquals(childNode, "composing")) { - if (this->event_handler != NULL) - this->event_handler->onIsTyping(from, true); + if (m_pEventHandler != NULL) + m_pEventHandler->onIsTyping(from, true); } else if (ProtocolTreeNode::tagEquals(childNode, "paused")) { - if (this->event_handler != NULL) - this->event_handler->onIsTyping(from, false); + if (m_pEventHandler != NULL) + m_pEventHandler->onIsTyping(from, false); } } } @@ -314,8 +306,8 @@ void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAExceptio FMessage message(from, true, id); message.status = FMessage::STATUS_SERVER_BOUNCE; - if (this->event_handler != NULL) - this->event_handler->onMessageError(&message, errorCode); + if (m_pEventHandler != NULL) + m_pEventHandler->onMessageError(&message, errorCode); } else if (typeAttribute == "subject") { bool receiptRequested = false; @@ -327,8 +319,8 @@ void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAExceptio } ProtocolTreeNode *bodyNode = messageNode->getChild("body"); - if (bodyNode != NULL&& this->group_event_handler != NULL) - this->group_event_handler->onGroupNewSubject(from, author, bodyNode->getDataAsString(), atoi(attribute_t.c_str())); + if (bodyNode != NULL&& m_pGroupEventHandler != NULL) + m_pGroupEventHandler->onGroupNewSubject(from, author, bodyNode->getDataAsString(), atoi(attribute_t.c_str())); if (receiptRequested) sendSubjectReceived(from, id); @@ -394,8 +386,8 @@ void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAExceptio fmessage.offline = false; } - if (!fmessage.key.remote_jid.empty() && this->event_handler != NULL) - this->event_handler->onMessageForMe(&fmessage, duplicate); + if (!fmessage.key.remote_jid.empty() && m_pEventHandler != NULL) + m_pEventHandler->onMessageForMe(&fmessage, duplicate); } else if (typeAttribute == "notification") { logData("Notification node %s", messageNode->toString().c_str()); @@ -405,7 +397,7 @@ void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAExceptio ProtocolTreeNode *child = children[i]; if (ProtocolTreeNode::tagEquals(child, "notification")) { const string &type = child->getAttributeValue("type"); - if (type == "picture" && this->event_handler != NULL) { + if (type == "picture" && m_pEventHandler != NULL) { std::vector children2(child->getAllChildren()); for (unsigned j = 0; j < children2.size(); j++) { ProtocolTreeNode *child2 = children2[j]; @@ -413,11 +405,11 @@ void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAExceptio const string &id = child2->getAttributeValue("id"); const string &author = child2->getAttributeValue("author"); if (!id.empty()) - this->event_handler->onPictureChanged(from, author, true); + m_pEventHandler->onPictureChanged(from, author, true); } else if (ProtocolTreeNode::tagEquals(child2, "delete")) { const string &author = child2->getAttributeValue("author"); - this->event_handler->onPictureChanged(from, author, false); + m_pEventHandler->onPictureChanged(from, author, false); } } } @@ -467,8 +459,8 @@ void WAConnection::parseIq(ProtocolTreeNode *node) throw(WAException) this->expire_date = atol(expiration.c_str()); if (this->expire_date == 0) throw WAException("invalid expire date: " + expiration); - if (this->event_handler != NULL) - this->event_handler->onAccountChange(this->account_kind, this->expire_date); + if (m_pEventHandler != NULL) + m_pEventHandler->onAccountChange(this->account_kind, this->expire_date); } } else if (type == "error") { @@ -482,14 +474,14 @@ void WAConnection::parseIq(ProtocolTreeNode *node) throw(WAException) else if (type == "get") { ProtocolTreeNode *childNode = node->getChild(0); if (ProtocolTreeNode::tagEquals(childNode, "ping")) { - if (this->event_handler != NULL) - this->event_handler->onPing(id); + 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() && this->event_handler != NULL) { + if (!pin.empty() && m_pEventHandler != NULL) { int timeoutSeconds = atoi(childNode->getAttributeValue("timeout").c_str()); - this->event_handler->onRelayRequest(pin, timeoutSeconds, id); + m_pEventHandler->onRelayRequest(pin, timeoutSeconds, id); } } } @@ -523,29 +515,29 @@ void WAConnection::parsePresense(ProtocolTreeNode *node) throw(WAException) const string &remove = node->getAttributeValue("remove"); const string &status = node->getAttributeValue("status"); if (!add.empty()) { - if (this->group_event_handler != NULL) - this->group_event_handler->onGroupAddUser(from, add); + if (m_pGroupEventHandler != NULL) + m_pGroupEventHandler->onGroupAddUser(from, add); } else if (!remove.empty()) { - if (this->group_event_handler != NULL) - this->group_event_handler->onGroupRemoveUser(from, remove); + if (m_pGroupEventHandler != NULL) + m_pGroupEventHandler->onGroupRemoveUser(from, remove); } else if (status == "dirty") { std::map categories = parseCategories(node); - if (this->event_handler != NULL) - this->event_handler->onDirty(categories); + if (m_pEventHandler != NULL) + m_pEventHandler->onDirty(categories); } return; } const string &type = node->getAttributeValue("type"); if (type == "unavailable") { - if (this->event_handler != NULL) - this->event_handler->onAvailable(from, false); + if (m_pEventHandler != NULL) + m_pEventHandler->onAvailable(from, false); } else if (type == "available" || type == "") { - if (this->event_handler != NULL) - this->event_handler->onAvailable(from, true); + if (m_pEventHandler != NULL) + m_pEventHandler->onAvailable(from, true); } } @@ -569,15 +561,15 @@ std::vector* WAConnection::processGroupSettings(const std::ve void WAConnection::sendActive() throw(WAException) { - this->out->write(ProtocolTreeNode("presence") << XATTR("type", "active")); + out.write(ProtocolTreeNode("presence") << XATTR("type", "active")); } void WAConnection::sendAvailableForChat() throw(WAException) { - this->out->write(ProtocolTreeNode("presence") << XATTR("name", this->nick)); + out.write(ProtocolTreeNode("presence") << XATTR("name", this->nick)); } -void WAConnection::sendClientConfig(const std::string& sound, const std::string& pushID, bool preview, const std::string& platform) throw(WAException) +void WAConnection::sendClientConfig(const std::string &sound, const std::string &pushID, bool preview, const std::string &platform) throw(WAException) { ProtocolTreeNode *configNode = new ProtocolTreeNode("config") << XATTR("xmlns", "urn:xmpp:whatsapp:push") << XATTR("sound", sound) << XATTR("id", pushID) << XATTR("preview", preview ? "1" : "0") << XATTR("platform", platform); @@ -585,11 +577,11 @@ void WAConnection::sendClientConfig(const std::string& sound, const std::string& std::string id = makeId("config_"); this->pending_server_requests[id] = new IqSendClientConfigHandler(this); - this->out->write(ProtocolTreeNode("iq", configNode) + out.write(ProtocolTreeNode("iq", configNode) << XATTR("id", id) << XATTR("type", "set") << XATTR("to", this->domain)); } -void WAConnection::sendClientConfig(const std::string& pushID, bool preview, const std::string& platform, bool defaultSettings, bool groupSettings, const std::vector& groups) throw(WAException) +void WAConnection::sendClientConfig(const std::string &pushID, bool preview, const std::string &platform, bool defaultSettings, bool groupSettings, const std::vector& groups) throw(WAException) { ProtocolTreeNode *configNode = new ProtocolTreeNode("config", NULL, this->processGroupSettings(groups)) << XATTR("xmlns", "urn:xmpp:whatsapp:push") << XATTR("id", pushID) << XATTR("lg", "en") << XATTR("lc", "US") << XATTR("clear", "0") @@ -597,18 +589,18 @@ void WAConnection::sendClientConfig(const std::string& pushID, bool preview, con << XATTR("default", defaultSettings ? "1" : "0") << XATTR("groups", groupSettings ? "1" : "0"); std::string id = makeId("config_"); - this->out->write(ProtocolTreeNode("iq", configNode) << XATTR("id", id) << XATTR("type", "set") << XATTR("to", this->domain)); + out.write(ProtocolTreeNode("iq", configNode) << XATTR("id", id) << XATTR("type", "set") << XATTR("to", this->domain)); } void WAConnection::sendClose() throw(WAException) { - this->out->write(ProtocolTreeNode("presence") << XATTR("type", "unavailable")); - this->out->streamEnd(); + out.write(ProtocolTreeNode("presence") << XATTR("type", "unavailable")); + out.streamEnd(); } -void WAConnection::sendComposing(const std::string& to) throw(WAException) +void WAConnection::sendComposing(const std::string &to) throw(WAException) { - this->out->write(ProtocolTreeNode("chatstate", new ProtocolTreeNode("composing")) << XATTR("to", to)); + out.write(ProtocolTreeNode("chatstate", new ProtocolTreeNode("composing")) << XATTR("to", to)); } void WAConnection::sendDeleteAccount() throw (WAException) @@ -617,47 +609,47 @@ void WAConnection::sendDeleteAccount() throw (WAException) this->pending_server_requests[id] = new IqResultSendDeleteAccount(this); ProtocolTreeNode *node1 = new ProtocolTreeNode("remove") << XATTR("xmlns", "urn:xmpp:whatsapp:account"); - this->out->write(ProtocolTreeNode("iq", node1) + out.write(ProtocolTreeNode("iq", node1) << XATTR("id", id) << XATTR("type", "get") << XATTR("to", "s.whatsapp.net")); } void WAConnection::sendGetGroups() throw (WAException) { - this->mutex->lock(); + m_pMutex->lock(); std::string id = makeId("get_groups_"); this->pending_server_requests[id] = new IqResultGetGroupsHandler(this, "participating"); sendGetGroups(id, "participating"); - this->mutex->unlock(); + m_pMutex->unlock(); } -void WAConnection::sendGetGroups(const std::string& id, const std::string& type) throw (WAException) +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); - this->out->write(ProtocolTreeNode("iq", listNode) + out.write(ProtocolTreeNode("iq", listNode) << XATTR("id", id) << XATTR("type", "get") << XATTR("to", "g.us")); } void WAConnection::sendGetOwningGroups() throw (WAException) { - this->mutex->lock(); + m_pMutex->lock(); std::string id = makeId("get_owning_groups_"); this->pending_server_requests[id] = new IqResultGetGroupsHandler(this, "owning"); sendGetGroups(id, "owning"); - this->mutex->unlock(); + m_pMutex->unlock(); } -void WAConnection::sendGetPicture(const std::string& jid, const std::string& type) throw (WAException) +void WAConnection::sendGetPicture(const std::string &jid, const std::string &type) throw (WAException) { std::string id = makeId("iq_"); this->pending_server_requests[id] = new IqResultGetPhotoHandler(this, jid); ProtocolTreeNode *listNode = new ProtocolTreeNode("picture") << XATTR("type", type); - this->out->write(ProtocolTreeNode("iq", listNode) + out.write(ProtocolTreeNode("iq", listNode) << XATTR("id", id) << XATTR("to", jid) << XATTR("xmlns", "w:profile:picture") << XATTR("type", "get")); } @@ -668,7 +660,7 @@ void WAConnection::sendGetPrivacyList() throw (WAException) ProtocolTreeNode *listNode = new ProtocolTreeNode("list") << XATTR("name", "default"); ProtocolTreeNode *queryNode = new ProtocolTreeNode("query", listNode) << XATTR("xmlns", "jabber:iq:privacy"); - this->out->write(ProtocolTreeNode("iq", queryNode) << XATTR("id", id) << XATTR("type", "get")); + out.write(ProtocolTreeNode("iq", queryNode) << XATTR("id", id) << XATTR("type", "get")); } void WAConnection::sendGetServerProperties() throw (WAException) @@ -679,13 +671,13 @@ void WAConnection::sendGetServerProperties() throw (WAException) ProtocolTreeNode *listNode = new ProtocolTreeNode("list") << XATTR("xmlns", "w:g") << XATTR("type", "props"); - this->out->write(ProtocolTreeNode("iq", listNode) + out.write(ProtocolTreeNode("iq", listNode) << XATTR("id", id) << XATTR("type", "get") << XATTR("to", "g.us")); } void WAConnection::sendInactive() throw(WAException) { - this->out->write(ProtocolTreeNode("presence") << XATTR("type", "inactive")); + out.write(ProtocolTreeNode("presence") << XATTR("type", "inactive")); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -737,7 +729,7 @@ void WAConnection::sendMessageWithMedia(FMessage* message) throw (WAException) } ProtocolTreeNode *n = WAConnection::getMessageNode(message, mediaNode); - this->out->write(*n); + out.write(*n); delete n; } @@ -745,29 +737,29 @@ void WAConnection::sendMessageWithBody(FMessage* message) throw (WAException) { ProtocolTreeNode *bodyNode = new ProtocolTreeNode("body", new std::vector(message->data.begin(), message->data.end())); ProtocolTreeNode *n = WAConnection::getMessageNode(message, bodyNode); - this->out->write(*n); + out.write(*n); delete n; } void WAConnection::sendMessageReceived(FMessage* message) throw(WAException) { - this->out->write(ProtocolTreeNode("receipt") << XATTR("type", "read") + out.write(ProtocolTreeNode("receipt") << XATTR("type", "read") << 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) +void WAConnection::sendNotificationReceived(const std::string &jid, const std::string &id) throw(WAException) { ProtocolTreeNode *child = new ProtocolTreeNode("received") << XATTR("xmlns", "urn:xmpp:receipts"); - this->out->write(ProtocolTreeNode("message", child) + out.write(ProtocolTreeNode("message", child) << XATTR("id", id) << XATTR("type", "notification") << XATTR("to", jid)); } -void WAConnection::sendPaused(const std::string& to) throw(WAException) +void WAConnection::sendPaused(const std::string &to) throw(WAException) { - this->out->write(ProtocolTreeNode("chatstate", new ProtocolTreeNode("paused")) << XATTR("to", to)); + out.write(ProtocolTreeNode("chatstate", new ProtocolTreeNode("paused")) << XATTR("to", to)); } void WAConnection::sendPing() throw(WAException) @@ -776,38 +768,38 @@ void WAConnection::sendPing() throw(WAException) this->pending_server_requests[id] = new IqResultPingHandler(this); ProtocolTreeNode *pingNode = new ProtocolTreeNode("ping"); - this->out->write(ProtocolTreeNode("iq", pingNode) + out.write(ProtocolTreeNode("iq", pingNode) << XATTR("id", id) << XATTR("xmlns", "w:p") << XATTR("type", "get") << XATTR("to", "s.whatsapp.net")); } -void WAConnection::sendPong(const std::string& id) throw(WAException) +void WAConnection::sendPong(const std::string &id) throw(WAException) { - this->out->write(ProtocolTreeNode("iq") + out.write(ProtocolTreeNode("iq") << XATTR("type", "result") << XATTR("to", this->domain) << XATTR("id", id)); } -void WAConnection::sendPresenceSubscriptionRequest(const std::string& to) throw(WAException) +void WAConnection::sendPresenceSubscriptionRequest(const std::string &to) throw(WAException) { - this->out->write(ProtocolTreeNode("presence") << XATTR("type", "subscribe") << XATTR("to", to)); + out.write(ProtocolTreeNode("presence") << XATTR("type", "subscribe") << XATTR("to", to)); } -void WAConnection::sendQueryLastOnline(const std::string& jid) throw (WAException) +void WAConnection::sendQueryLastOnline(const std::string &jid) throw (WAException) { std::string id = makeId("last_"); this->pending_server_requests[id] = new IqResultQueryLastOnlineHandler(this); ProtocolTreeNode *queryNode = new ProtocolTreeNode("query") << XATTR("xmlns", "jabber:iq:last"); - this->out->write(ProtocolTreeNode("iq", queryNode) + out.write(ProtocolTreeNode("iq", queryNode) << XATTR("id", id) << XATTR("type", "get") << XATTR("to", jid)); } -void WAConnection::sendSetPicture(const std::string& jid, std::vector* data) throw (WAException) +void WAConnection::sendSetPicture(const std::string &jid, std::vector* data) throw (WAException) { std::string id = this->makeId("set_photo_"); this->pending_server_requests[id] = new IqResultSetPhotoHandler(this, jid); ProtocolTreeNode *listNode = new ProtocolTreeNode("picture", data, NULL) << XATTR("xmlns", "w:profile:picture"); - this->out->write(ProtocolTreeNode("iq", listNode) + out.write(ProtocolTreeNode("iq", listNode) << XATTR("id", id) << XATTR("type", "set") << XATTR("to", jid)); } @@ -817,42 +809,42 @@ void WAConnection::sendStatusUpdate(std::string& status) throw (WAException) FMessage message("s.us", true, id); ProtocolTreeNode *body = new ProtocolTreeNode("body", new std::vector(status.begin(), status.end()), NULL); ProtocolTreeNode *n = getMessageNode(&message, body); - this->out->write(*n); + out.write(*n); delete n; } -void WAConnection::sendSubjectReceived(const std::string& to, const std::string& id)throw(WAException) +void WAConnection::sendSubjectReceived(const std::string &to, const std::string &id)throw(WAException) { ProtocolTreeNode *receivedNode = new ProtocolTreeNode("received") << XATTR("xmlns", "urn:xmpp:receipts"); - this->out->write(ProtocolTreeNode("message", receivedNode) + 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) +void WAConnection::sendGetGroupInfo(const std::string &gjid) throw (WAException) { std::string id = makeId("get_g_info_"); this->pending_server_requests[id] = new IqResultGetGroupInfoHandler(this); ProtocolTreeNode *queryNode = new ProtocolTreeNode("query") << XATTR("xmlns", "w:g"); - this->out->write(ProtocolTreeNode("iq", queryNode) + out.write(ProtocolTreeNode("iq", queryNode) << XATTR("id", id) << XATTR("type", "get") << XATTR("to", gjid)); } -void WAConnection::sendGetParticipants(const std::string& gjid) throw (WAException) +void WAConnection::sendGetParticipants(const std::string &gjid) throw (WAException) { std::string id = makeId("get_participants_"); this->pending_server_requests[id] = new IqResultGetGroupParticipantsHandler(this); ProtocolTreeNode *listNode = new ProtocolTreeNode("list") << XATTR("xmlns", "w:g"); - this->out->write(ProtocolTreeNode("iq", listNode) + out.write(ProtocolTreeNode("iq", listNode) << XATTR("id", id) << XATTR("type", "get") << XATTR("to", gjid)); } -void WAConnection::readAttributeList(ProtocolTreeNode *node, std::vector& vector, const std::string& tag, const std::string& attribute) throw (WAException) +void WAConnection::readAttributeList(ProtocolTreeNode *node, std::vector& vector, const std::string &tag, const std::string &attribute) throw (WAException) { std::vector nodes(node->getAllChildren(tag)); for (size_t i = 0; i < nodes.size(); i++) { @@ -861,7 +853,7 @@ void WAConnection::readAttributeList(ProtocolTreeNode *node, std::vectorout->write(ProtocolTreeNode("iq", groupNode) + out.write(ProtocolTreeNode("iq", groupNode) << XATTR("id", id) << XATTR("type", "set") << XATTR("to", "g.us")); } -void WAConnection::sendEndGroupChat(const std::string& gjid) throw (WAException) +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"); - this->out->write(ProtocolTreeNode("iq", groupNode) + out.write(ProtocolTreeNode("iq", groupNode) << XATTR("id", id) << XATTR("type", "set") << XATTR("to", gjid)); } -void WAConnection::sendClearDirty(const std::string& category) throw (WAException) +void WAConnection::sendClearDirty(const std::string &category) throw (WAException) { std::string id = makeId("clean_dirty_"); this->pending_server_requests[id] = new IqResultClearDirtyHandler(this); ProtocolTreeNode *categoryNode = new ProtocolTreeNode("category") << XATTR("name", category); ProtocolTreeNode *cleanNode = new ProtocolTreeNode("clean", categoryNode) << XATTR("xmlns", "urn:xmpp:whatsapp:dirty"); - this->out->write(ProtocolTreeNode("iq", cleanNode) + out.write(ProtocolTreeNode("iq", cleanNode) << XATTR("id", id) << XATTR("type", "set") << XATTR("to", "s.whatsapp.net")); } -void WAConnection::sendLeaveGroup(const std::string& gjid) throw (WAException) +void WAConnection::sendLeaveGroup(const std::string &gjid) throw (WAException) { std::string id = makeId("leave_group_"); ProtocolTreeNode *groupNode = new ProtocolTreeNode("group") << XATTR("id", gjid); ProtocolTreeNode *leaveNode = new ProtocolTreeNode("leave", groupNode) << XATTR("xmlns", "w:g"); - this->out->write(ProtocolTreeNode("iq", leaveNode) + out.write(ProtocolTreeNode("iq", leaveNode) << 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"); } -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"); } -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 &id, const std::string &inner_tag) throw (WAException) { size_t size = participants.size(); std::vector* children = new std::vector(size); @@ -926,18 +918,17 @@ void WAConnection::sendVerbParticipants(const std::string& gjid, const std::vect ProtocolTreeNode *innerNode = new ProtocolTreeNode(inner_tag, NULL, children) << XATTR("xmlns", "w:g"); - this->out->write(ProtocolTreeNode("iq", innerNode) + out.write(ProtocolTreeNode("iq", innerNode) << XATTR("id", id) << XATTR("type", "set") << XATTR("to", gjid)); } -void WAConnection::sendSetNewSubject(const std::string& gjid, const std::string& subject) throw (WAException) +void WAConnection::sendSetNewSubject(const std::string &gjid, const std::string &subject) throw (WAException) { std::string id = this->makeId("set_group_subject_"); ProtocolTreeNode *subjectNode = new ProtocolTreeNode("subject") << XATTR("xmlns", "w:g") << XATTR("value", subject); - this->out->write(ProtocolTreeNode("iq", subjectNode) + out.write(ProtocolTreeNode("iq", subjectNode) << 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 5a5dfc5b83..6bc53e4c86 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h +++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h @@ -68,18 +68,6 @@ public: virtual void onLeaveGroup(const std::string& paramString)=0; }; - - -class MessageStore { -public: - MessageStore(); - - virtual FMessage* get(Key* key); - - virtual ~MessageStore(); -}; - - class GroupSetting { public: std::string jid; @@ -93,8 +81,8 @@ public: } }; -class WAConnection { - +class WAConnection +{ class IqResultHandler { protected: WAConnection* con; @@ -125,13 +113,13 @@ class WAConnection { public: IqResultPingHandler(WAConnection* con):IqResultHandler(con) {} virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) { - if (this->con->event_handler != NULL) - this->con->event_handler->onPingResponseReceived(); + if (this->con->m_pEventHandler != NULL) + this->con->m_pEventHandler->onPingResponseReceived(); } void error(ProtocolTreeNode* node) throw (WAException) { - if (this->con->event_handler != NULL) - this->con->event_handler->onPingResponseReceived(); + if (this->con->m_pEventHandler != NULL) + this->con->m_pEventHandler->onPingResponseReceived(); } }; @@ -143,11 +131,11 @@ class WAConnection { virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) { std::vector groups; this->con->readGroupList(node, groups); - if (this->con->group_event_handler != NULL) { + if (this->con->m_pGroupEventHandler != NULL) { if (this->type.compare("participating") == 0) - this->con->group_event_handler->onParticipatingGroups(groups); + this->con->m_pGroupEventHandler->onParticipatingGroups(groups); else if (this->type.compare("owning") == 0) - this->con->group_event_handler->onOwningGroups(groups); + this->con->m_pGroupEventHandler->onOwningGroups(groups); } } }; @@ -165,8 +153,8 @@ class WAConnection { nameValueMap[nameAttr] = valueAttr; } - if (this->con->group_event_handler != NULL) - this->con->group_event_handler->onServerProperties(&nameValueMap); + if (this->con->m_pGroupEventHandler != NULL) + this->con->m_pGroupEventHandler->onServerProperties(&nameValueMap); } }; @@ -178,16 +166,16 @@ class WAConnection { ProtocolTreeNode::require(queryNode, "query"); ProtocolTreeNode* listNode = queryNode->getChild(0); ProtocolTreeNode::require(listNode, "list"); - if (this->con->event_handler != NULL) - this->con->event_handler->onPrivacyBlockListClear(); + if (this->con->m_pEventHandler != NULL) + this->con->m_pEventHandler->onPrivacyBlockListClear(); if (listNode->children != NULL) { for (size_t i = 0; i < listNode->children->size(); i++) { ProtocolTreeNode* itemNode = (*listNode->children)[i]; ProtocolTreeNode::require(itemNode, "item"); if (itemNode->getAttributeValue("type").compare("jid") == 0) { const string &jid = itemNode->getAttributeValue("value"); - if (!jid.empty() && this->con->event_handler != NULL) - this->con->event_handler->onPrivacyBlockListAdd(jid); + if (!jid.empty() && this->con->m_pEventHandler != NULL) + this->con->m_pEventHandler->onPrivacyBlockListAdd(jid); } } } @@ -205,8 +193,8 @@ class WAConnection { const string &subject_t = groupNode->getAttributeValue("s_t"); const string &subject_owner = groupNode->getAttributeValue("s_o"); const string &creation = groupNode->getAttributeValue("creation"); - if (this->con->group_event_handler != NULL) - this->con->group_event_handler->onGroupInfo(from, owner, subject, subject_owner, atoi(subject_t.c_str()), atoi(creation.c_str())); + if (this->con->m_pGroupEventHandler != NULL) + this->con->m_pGroupEventHandler->onGroupInfo(from, owner, subject, subject_owner, atoi(subject_t.c_str()), atoi(creation.c_str())); } }; @@ -216,8 +204,8 @@ class WAConnection { virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) { std::vector participants; this->con->readAttributeList(node, participants, "participant", "jid"); - if (this->con->group_event_handler != NULL) - this->con->group_event_handler->onGetParticipants(from, participants); + if (this->con->m_pGroupEventHandler != NULL) + this->con->m_pGroupEventHandler->onGetParticipants(from, participants); } }; @@ -228,8 +216,8 @@ class WAConnection { ProtocolTreeNode* groupNode = node->getChild(0); ProtocolTreeNode::require(groupNode, "group"); const string &groupId = groupNode->getAttributeValue("id"); - if (!groupId.empty() && con->group_event_handler != NULL) - this->con->group_event_handler->onGroupCreated(from, groupId); + if (!groupId.empty() && con->m_pGroupEventHandler != NULL) + this->con->m_pGroupEventHandler->onGroupCreated(from, groupId); } }; @@ -242,8 +230,8 @@ class WAConnection { const string &seconds = firstChild->getAttributeValue("seconds"); const string &status = firstChild->getDataAsString(); if (!seconds.empty() && !from.empty()) - if (this->con->event_handler != NULL) - this->con->event_handler->onLastSeen(from, atoi(seconds.c_str()), status); + if (this->con->m_pEventHandler != NULL) + this->con->m_pEventHandler->onLastSeen(from, atoi(seconds.c_str()), status); } }; @@ -259,23 +247,23 @@ class WAConnection { virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) { const string &attributeValue = node->getAttributeValue("type"); - if (!attributeValue.empty() && attributeValue == "result" && this->con->event_handler != NULL) { + if (!attributeValue.empty() && attributeValue == "result" && this->con->m_pEventHandler != NULL) { std::vector children(node->getAllChildren("picture")); for (size_t i = 0; i < children.size(); i++) { ProtocolTreeNode* current = children[i]; const string &id = current->getAttributeValue("id"); if (!id.empty() && current->data != NULL && current->data->size() > 0) { if (current->data != NULL) - this->con->event_handler->onSendGetPicture(this->jid, *current->data, id); + this->con->m_pEventHandler->onSendGetPicture(this->jid, *current->data, id); break; } } } } void error(ProtocolTreeNode* node) throw (WAException) { - if (this->con->event_handler != NULL) { + if (this->con->m_pEventHandler != NULL) { std::vector v; - this->con->event_handler->onSendGetPicture("error", v, ""); + this->con->m_pEventHandler->onSendGetPicture("error", v, ""); } } }; @@ -286,12 +274,12 @@ class WAConnection { public: 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->event_handler != NULL) { + if (this->con->m_pEventHandler != NULL) { ProtocolTreeNode* child = node->getChild("picture"); if (child != NULL) - this->con->event_handler->onPictureChanged(this->jid, "", true); + this->con->m_pEventHandler->onPictureChanged(this->jid, "", true); else - this->con->event_handler->onPictureChanged(this->jid, "", false); + this->con->m_pEventHandler->onPictureChanged(this->jid, "", false); } } }; @@ -300,13 +288,13 @@ class WAConnection { public: IqResultSendDeleteAccount(WAConnection* con):IqResultHandler(con) {} virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) { - if (this->con->event_handler != NULL) - this->con->event_handler->onDeleteAccount(true); + if (this->con->m_pEventHandler != NULL) + this->con->m_pEventHandler->onDeleteAccount(true); } void error(ProtocolTreeNode* node) throw (WAException) { - if (this->con->event_handler != NULL) - this->con->event_handler->onDeleteAccount(false); + if (this->con->m_pEventHandler != NULL) + this->con->m_pEventHandler->onDeleteAccount(false); } }; @@ -333,14 +321,14 @@ class WAConnection { private: ISocketConnection *rawConn; - BinTreeNodeReader *in; - BinTreeNodeWriter *out; - WAListener *event_handler; - WAGroupListener *group_event_handler; + BinTreeNodeReader in; + BinTreeNodeWriter out; + WAListener *m_pEventHandler; + WAGroupListener *m_pGroupEventHandler; bool verbose; int iqid; std::map pending_server_requests; - IMutex *mutex; + IMutex *m_pMutex; void parseAck(ProtocolTreeNode *node) throw (WAException); void parseChatStates(ProtocolTreeNode *node) throw (WAException); @@ -363,9 +351,8 @@ private: std::vector* processGroupSettings(const std::vector& gruops); public: - WAConnection(const std::string& user, const std::string& resource, IMutex* mutex, WAListener* event_handler, WAGroupListener* group_event_handler); + WAConnection(const std::string& user, const std::string& resource, IMutex* mutex, IMutex *write_mutex, ISocketConnection *conn, WAListener* m_pEventHandler, WAGroupListener* m_pGroupEventHandler); virtual ~WAConnection(); - void init(IMutex* mutex, ISocketConnection*); std::string user; std::string domain; diff --git a/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp b/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp index c788fd3124..1f8c46faf2 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp @@ -30,7 +30,7 @@ WALogin::WALogin(WAConnection* connection, const std::string& password) std::vector WALogin::login(const std::vector& authBlob) { - m_pConnection->out->streamStart(m_pConnection->domain, m_pConnection->resource); + m_pConnection->out.streamStart(m_pConnection->domain, m_pConnection->resource); m_pConnection->logData("sent stream start"); @@ -42,7 +42,7 @@ std::vector WALogin::login(const std::vector& auth m_pConnection->logData("send auth, auth blob size %d", authBlob.size()); - m_pConnection->in->streamStart(); + m_pConnection->in.streamStart(); m_pConnection->logData("read stream start"); @@ -52,7 +52,7 @@ std::vector WALogin::login(const std::vector& auth void WALogin::sendResponse(const std::vector& challengeData) { std::vector* authBlob = this->getAuthBlob(challengeData); - m_pConnection->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); - m_pConnection->out->write(ProtocolTreeNode("stream:features", NULL, children), true); + m_pConnection->out.write(ProtocolTreeNode("stream:features", NULL, children), true); } void WALogin::sendAuth(const std::vector& existingChallenge) @@ -73,7 +73,7 @@ void WALogin::sendAuth(const std::vector& existingChallenge) if (!existingChallenge.empty()) data = this->getAuthBlob(existingChallenge); - m_pConnection->out->write(ProtocolTreeNode("auth", data) << + m_pConnection->out.write(ProtocolTreeNode("auth", data) << XATTR("mechanism", "WAUTH-2") << XATTR("user", m_pConnection->user), true); } @@ -98,7 +98,7 @@ std::vector* WALogin::getAuthBlob(const std::vector WALogin::readFeaturesUntilChallengeOrSuccess() { - while (ProtocolTreeNode *root = m_pConnection->in->nextTree()) { + while (ProtocolTreeNode *root = m_pConnection->in.nextTree()) { #ifdef _DEBUG { string tmp = root->toString(); @@ -131,7 +131,7 @@ std::vector WALogin::readFeaturesUntilChallengeOrSuccess() void WALogin::parseSuccessNode(ProtocolTreeNode* node) { - m_pConnection->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 WALogin::readSuccess() { - ProtocolTreeNode *node = m_pConnection->in->nextTree(); + ProtocolTreeNode *node = m_pConnection->in.nextTree(); if (ProtocolTreeNode::tagEquals(node, "failure")) { delete node; diff --git a/protocols/WhatsApp/src/chat.cpp b/protocols/WhatsApp/src/chat.cpp index 790906cb8f..4c3d3afeeb 100644 --- a/protocols/WhatsApp/src/chat.cpp +++ b/protocols/WhatsApp/src/chat.cpp @@ -43,8 +43,8 @@ int WhatsAppProto::OnChatOutgoing(WPARAM wParam, LPARAM lParam) GCDEST gcd = { m_szModuleName, hook->pDest->ptszID, GC_EVENT_MESSAGE }; GCEVENT gce = { sizeof(gce), &gcd }; gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszNick = mir_a2t(this->nick.c_str()); - gce.ptszUID = mir_a2t(this->jid.c_str()); + gce.ptszNick = mir_a2t(m_szNick.c_str()); + gce.ptszUID = mir_a2t(m_szJid.c_str()); gce.time = time(NULL); gce.ptszText = hook->ptszText; gce.bIsMe = TRUE; diff --git a/protocols/WhatsApp/src/connection.cpp b/protocols/WhatsApp/src/connection.cpp index e53d7848e8..1ff049ae6d 100644 --- a/protocols/WhatsApp/src/connection.cpp +++ b/protocols/WhatsApp/src/connection.cpp @@ -22,14 +22,14 @@ void WhatsAppProto::stayConnectedLoop(void*) NotifyEvent(m_tszUserName, TranslateT("Please enter a phone number without country code."), NULL, WHATSAPP_EVENT_CLIENT); return; } - this->phoneNumber = cc + in; - this->jid = this->phoneNumber + "@s.whatsapp.net"; + m_szPhoneNumber = cc + in; + m_szJid = m_szPhoneNumber + "@s.whatsapp.net"; if (!getString(WHATSAPP_KEY_NICK, &dbv)) { - this->nick = dbv.pszVal; + m_szNick = dbv.pszVal; db_free(&dbv); } - if (this->nick.empty()) { + if (m_szNick.empty()) { NotifyEvent(m_tszUserName, TranslateT("Please enter a nickname."), NULL, WHATSAPP_EVENT_CLIENT); return; } @@ -83,15 +83,14 @@ void WhatsAppProto::stayConnectedLoop(void*) portNumber = 5222, resource += "-5222"; this->conn = new WASocketConnection("c.whatsapp.net", portNumber); - m_pConnection = new WAConnection(this->phoneNumber, resource, &this->connMutex, this, this); - m_pConnection->init(&writerMutex, this->conn); + m_pConnection = new WAConnection(m_szPhoneNumber, resource, &this->connMutex, &writerMutex, this->conn, this, this); { WALogin login(m_pConnection, password); m_Challenge = login.login(m_Challenge); m_pConnection->setLogin(&login); } - m_pConnection->nick = this->nick; + m_pConnection->nick = m_szNick; m_pConnection->setVerboseId(true); if (m_iDesiredStatus != ID_STATUS_INVISIBLE) m_pConnection->sendAvailableForChat(); diff --git a/protocols/WhatsApp/src/contacts.cpp b/protocols/WhatsApp/src/contacts.cpp index 1efadd1876..33b289c098 100644 --- a/protocols/WhatsApp/src/contacts.cpp +++ b/protocols/WhatsApp/src/contacts.cpp @@ -243,7 +243,7 @@ void WhatsAppProto::onGroupInfo(const std::string& gjid, const std::string& owne debugLogA("Group info requested for non existing contact '%s'", gjid.c_str()); return; } - setByte(hContact, "SimpleChatRoom", ownerJid.compare(this->jid) == 0 ? 2 : 1); + setByte(hContact, "SimpleChatRoom", ownerJid.compare(m_szJid) == 0 ? 2 : 1); if (this->isOnline()) m_pConnection->sendGetParticipants(gjid); } @@ -265,7 +265,7 @@ void WhatsAppProto::onGroupAddUser(const std::string& paramString1, const std::s MCONTACT hContact = this->AddToContactList(paramString1); TCHAR *ptszGroupName = pcli->pfnGetContactDisplayName(hContact, 0); - if (paramString2.compare(this->jid) == 0) { + if (paramString2.compare(m_szJid) == 0) { this->NotifyEvent(ptszGroupName, TranslateT("You have been added to the group"), hContact, WHATSAPP_EVENT_OTHER); setByte(hContact, "IsGroupMember", 1); } @@ -287,7 +287,7 @@ void WhatsAppProto::onGroupRemoveUser(const std::string ¶mString1, const std TCHAR *ptszGroupName = pcli->pfnGetContactDisplayName(hContact, 0); - if (paramString2.compare(this->jid) == 0) { + if (paramString2.compare(m_szJid) == 0) { //db_set_b(hContact, "CList", "Hidden", 1); setByte(hContact, "IsGroupMember", 0); @@ -331,7 +331,7 @@ void WhatsAppProto::onGetParticipants(const std::string& gjid, const std::vector // Hide, if we are not member of the group // Sometimes the group is shown shortly after hiding it again, due to other threads which stored the contact // in a cache before it has been removed (E.g. picture-id list in processBuddyList) - if (isHidden && this->jid.compare(*it) == 0) { + if (isHidden && m_szJid.compare(*it) == 0) { isHidden = false; if (!isOwningGroup) { // Break, as we don't need to collect group-members diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp index eaf6b3d358..0d7285bb60 100644 --- a/protocols/WhatsApp/src/proto.cpp +++ b/protocols/WhatsApp/src/proto.cpp @@ -410,7 +410,7 @@ std::tstring WhatsAppProto::GetAvatarFileName(MCONTACT hContact) jid = szId; } - else jid = this->jid; + else jid = m_szJid; return result + std::tstring(_A2T(jid.c_str())) + _T(".jpg"); } diff --git a/protocols/WhatsApp/src/proto.h b/protocols/WhatsApp/src/proto.h index 25f145be59..33cc9bcad0 100644 --- a/protocols/WhatsApp/src/proto.h +++ b/protocols/WhatsApp/src/proto.h @@ -170,8 +170,8 @@ private: int lastPongTime; std::vector m_Challenge; - string phoneNumber; - string jid, nick; + string m_szPhoneNumber; + string m_szJid, m_szNick; std::map hContactByJid; map> isMemberByGroupContact; -- cgit v1.2.3