summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'protocols')
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h11
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp60
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/WAConnection.h4
-rw-r--r--protocols/WhatsApp/src/version.h2
4 files changed, 38 insertions, 39 deletions
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<unsigned char>* data;
+ vector<unsigned char>* data;
string tag;
map<string, string> *attributes;
vector<ProtocolTreeNode*> *children;
ProtocolTreeNode(const string& tag, ProtocolTreeNode* child);
ProtocolTreeNode(const string& tag, vector<unsigned char>* data = NULL, vector<ProtocolTreeNode*> *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<unsigned char>(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<ProtocolTreeNode*>* children = new std::vector<ProtocolTreeNode*>(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<ProtocolTreeNode*>* messageChildren = new std::vector<ProtocolTreeNode*>(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<ProtocolTreeNode*>* messageChildren = new std::vector<ProtocolTreeNode*>();
+ 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<string, string>* 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<unsigned char>(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<unsigned char>(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<string, string>* 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<std::string>& groups) throw (WAException);
@@ -377,7 +377,7 @@ private:
void readAttributeList(ProtocolTreeNode* node, std::vector<std::string>& vector, const std::string& tag, const std::string& attribute) throw (WAException);
void sendVerbParticipants(const std::string& gjid, const std::vector<std::string>& 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<ProtocolTreeNode*>* processGroupSettings(const std::vector<GroupSetting>& 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 <stdver.h>