From 53867c8c7ca7a578d8f36b619f352700ba34c9ad Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 26 Jan 2015 14:20:08 +0000 Subject: fix for a crash on message sending git-svn-id: http://svn.miranda-ng.org/main/trunk@11917 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- .../WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h | 11 ++-- protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp | 60 ++++++++++------------ protocols/WhatsApp/src/WhatsAPI++/WAConnection.h | 4 +- protocols/WhatsApp/src/version.h | 2 +- 4 files changed, 38 insertions(+), 39 deletions(-) (limited to 'protocols') diff --git a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h index 6be09cef8d..aeb1b6e18e 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h +++ b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h @@ -45,15 +45,20 @@ struct XATTRI int value; }; -class ProtocolTreeNode { +class ProtocolTreeNode +{ + ProtocolTreeNode(const ProtocolTreeNode&); // to prevent copying + public: - vector* data; + vector* data; string tag; map *attributes; vector *children; 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(size_t id); @@ -65,8 +70,6 @@ public: static bool tagEquals(ProtocolTreeNode *node, const string& tag); static void require(ProtocolTreeNode *node, const string& tag); - - virtual ~ProtocolTreeNode(); }; ProtocolTreeNode& operator<<(ProtocolTreeNode&, const XATTR&); diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp index ceb308763d..d5533577bb 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp @@ -174,35 +174,26 @@ void WAConnection::sendMessageWithMedia(FMessage* message) throw (WAException) mediaNode << XATTRI("seconds", message->media_duration_seconds); } - this->out->write(WAConnection::getMessageNode(message, mediaNode)); + ProtocolTreeNode *n = WAConnection::getMessageNode(message, mediaNode); + this->out->write(*n); + delete n; } void WAConnection::sendMessageWithBody(FMessage* message) throw (WAException) { ProtocolTreeNode* bodyNode = new ProtocolTreeNode("body", new std::vector(message->data.begin(), message->data.end())); - this->out->write(WAConnection::getMessageNode(message, bodyNode)); -} - -ProtocolTreeNode WAConnection::getMessageNode(FMessage* message, ProtocolTreeNode* child) -{ - ProtocolTreeNode* requestNode = NULL; - ProtocolTreeNode* serverNode = new ProtocolTreeNode("server"); - std::vector* children = new std::vector(1); - (*children)[0] = serverNode; - ProtocolTreeNode* xNode = new ProtocolTreeNode("x", NULL, children) << XATTR("xmlns", "jabber:x:event"); - int childCount = (requestNode == NULL ? 0 : 1) + 2; - std::vector* messageChildren = new std::vector(childCount); - int i = 0; - if (requestNode != NULL) { - (*messageChildren)[i] = requestNode; - i++; - } - (*messageChildren)[i] = xNode; - i++; - (*messageChildren)[i] = child; - i++; + ProtocolTreeNode *n = WAConnection::getMessageNode(message, bodyNode); + this->out->write(*n); + delete n; +} + +ProtocolTreeNode* WAConnection::getMessageNode(FMessage* message, ProtocolTreeNode* child) +{ + std::vector* messageChildren = new std::vector(); + messageChildren->push_back(new ProtocolTreeNode("x", new ProtocolTreeNode("server")) << XATTR("xmlns", "jabber:x:event")); + messageChildren->push_back(child); - return ProtocolTreeNode("message", NULL, messageChildren) << + return new ProtocolTreeNode("message", NULL, messageChildren) << XATTR("to", message->key->remote_jid) << XATTR("type", "chat") << XATTR("id", message->key->id); } @@ -425,15 +416,18 @@ void WAConnection::sendMessageReceived(FMessage* message) throw(WAException) << XATTR("to", message->key->remote_jid) << XATTR("type", "chat") << XATTR("id", message->key->id)); } -void WAConnection::sendDeliveredReceiptAck(const std::string& to, - const std::string& id) throw(WAException) +void WAConnection::sendDeliveredReceiptAck(const std::string& to, const std::string& id) throw(WAException) { - this->out->write(getReceiptAck(to, id, "delivered")); + ProtocolTreeNode *n = getReceiptAck(to, id, "delivered"); + this->out->write(*n); + delete n; } void WAConnection::sendVisibleReceiptAck(const std::string& to, const std::string& id) throw (WAException) { - this->out->write(getReceiptAck(to, id, "visible")); + ProtocolTreeNode *n = getReceiptAck(to, id, "visible"); + this->out->write(*n); + delete n; } void WAConnection::sendPresenceSubscriptionRequest(const std::string& to) throw(WAException) @@ -491,12 +485,12 @@ 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); - return ProtocolTreeNode("message", ackNode) << XATTR("to", to) << XATTR("type", "chat") << XATTR("id", id); + return new ProtocolTreeNode("message", ackNode) << XATTR("to", to) << XATTR("type", "chat") << XATTR("id", id); } std::map* WAConnection::parseCategories(ProtocolTreeNode* dirtyNode) throw (WAException) @@ -930,9 +924,11 @@ std::string WAConnection::removeResourceFromJid(const std::string& jid) void WAConnection::sendStatusUpdate(std::string& status) throw (WAException) { std::string id = this->makeId(Utilities::intToStr((int)time(NULL))); - FMessage* message = new FMessage(new Key("s.us", true, id)); - ProtocolTreeNode* body = new ProtocolTreeNode("body", new std::vector(status.begin(), status.end()), NULL); - this->out->write(getMessageNode(message, body)); + FMessage *message = new FMessage(new Key("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); + delete n; delete message; } diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h index 365c1e2d3d..91164a824f 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h +++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h @@ -369,7 +369,7 @@ private: void sendMessageWithBody(FMessage* message) throw(WAException); std::map* parseCategories(ProtocolTreeNode* node) throw(WAException); void parseMessageInitialTagAlreadyChecked(ProtocolTreeNode* node) throw(WAException); - ProtocolTreeNode getReceiptAck(const std::string& to, const std::string& id, const std::string& receiptType) 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); void readGroupList(ProtocolTreeNode* node, std::vector& groups) throw (WAException); @@ -377,7 +377,7 @@ private: 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); bool supportsReceiptAcks(); - static ProtocolTreeNode getMessageNode(FMessage* message, ProtocolTreeNode* node); + static ProtocolTreeNode* getMessageNode(FMessage* message, ProtocolTreeNode* node); std::vector* processGroupSettings(const std::vector& gruops); public: diff --git a/protocols/WhatsApp/src/version.h b/protocols/WhatsApp/src/version.h index 3f05a927e9..ca808c5877 100644 --- a/protocols/WhatsApp/src/version.h +++ b/protocols/WhatsApp/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 1 #define __RELEASE_NUM 2 -#define __BUILD_NUM 0 +#define __BUILD_NUM 1 #include -- cgit v1.2.3