summaryrefslogtreecommitdiff
path: root/protocols/WhatsApp/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-11-10 17:19:12 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-11-10 17:19:12 +0000
commitb43b7abf33f5b2ab480a85584df0e3ce8c76a8ca (patch)
tree98a2b9c9038974e76d40ffe7114bd7ea2df8290f /protocols/WhatsApp/src
parent7ec4cc63fa1b31af0496ac934d001323519c838f (diff)
much less crazy imlementaion of xml reader
git-svn-id: http://svn.miranda-ng.org/main/trunk@10945 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/WhatsApp/src')
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp7
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/FMessage.h2
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp54
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h8
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp514
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/WAConnection.h120
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp27
-rw-r--r--protocols/WhatsApp/src/contacts.cpp5
-rw-r--r--protocols/WhatsApp/src/dialogs.cpp4
-rw-r--r--protocols/WhatsApp/src/messages.cpp4
-rw-r--r--protocols/WhatsApp/src/proto.h2
-rw-r--r--protocols/WhatsApp/src/version.h2
12 files changed, 341 insertions, 408 deletions
diff --git a/protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp b/protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp
index 0eca3aeef7..c80e44c657 100644
--- a/protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp
+++ b/protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp
@@ -105,10 +105,11 @@ std::string Key::toString() {
}
-unsigned char FMessage::getMessage_WA_Type(std::string* type) {
- if ((type == NULL) || (type->length() == 0))
+unsigned char FMessage::getMessage_WA_Type(const std::string& type) {
+ if (type.empty())
return WA_TYPE_UNDEFINED;
- std::string typeLower = *type;
+
+ std::string typeLower = type;
std::transform(typeLower.begin(), typeLower.end(), typeLower.begin(), ::tolower);
if (typeLower.compare("system") == 0)
return WA_TYPE_SYSTEM;
diff --git a/protocols/WhatsApp/src/WhatsAPI++/FMessage.h b/protocols/WhatsApp/src/WhatsAPI++/FMessage.h
index 63ae64451a..3d9c8438f5 100644
--- a/protocols/WhatsApp/src/WhatsAPI++/FMessage.h
+++ b/protocols/WhatsApp/src/WhatsAPI++/FMessage.h
@@ -77,7 +77,7 @@ public:
static std::string getMessage_WA_Type_StrValue(unsigned char type);
static std::string nextKeyIdNumber();
- static unsigned char getMessage_WA_Type(std::string* typeString);
+ static unsigned char getMessage_WA_Type(const std::string& typeString);
FMessage();
FMessage(const std::string& remote_jid, bool from_me = true, const std::string& data = "");
diff --git a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp
index a44fa27812..5ca7bd7f0e 100644
--- a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp
+++ b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp
@@ -8,6 +8,8 @@
#include "WAException.h"
#include "ProtocolTreeNode.h"
+static std::string nilstr;
+
ProtocolTreeNode::ProtocolTreeNode(const string& tag, map<string, string> *attributes, vector<unsigned char>* data, vector<ProtocolTreeNode*> *children) {
this->tag = tag;
this->data = data;
@@ -46,13 +48,10 @@ string ProtocolTreeNode::toString() {
out += "" + ii->first + "=\"" + ii->second + "\"";
}
out += ">\n";
- std::string* data = getDataAsString();
- out += (this->data != NULL? *data:"");
- delete data;
+ out += getDataAsString();
if (this->children != NULL) {
vector<ProtocolTreeNode*>::iterator ii;
-
for (ii = children->begin(); ii != children->end(); ii++)
out += (*ii)->toString();
}
@@ -83,51 +82,52 @@ ProtocolTreeNode* ProtocolTreeNode::getChild(size_t id) {
return NULL;
}
-string* ProtocolTreeNode::getAttributeValue(const string& attribute) {
+const string& ProtocolTreeNode::getAttributeValue(const string& attribute)
+{
if (this->attributes == NULL)
- return NULL;
+ return nilstr;
map<string,string>::iterator it = attributes->find(attribute);
if (it == attributes->end())
- return NULL;
+ return nilstr;
- return &it->second;
+ return it->second;
}
-vector<ProtocolTreeNode*>* ProtocolTreeNode::getAllChildren() {
- vector<ProtocolTreeNode*>* ret = new vector<ProtocolTreeNode*>();
-
+vector<ProtocolTreeNode*> ProtocolTreeNode::getAllChildren()
+{
if (this->children == NULL)
- return ret;
+ return vector<ProtocolTreeNode*>();
- return this->children;
+ return *this->children;
}
-std::string* ProtocolTreeNode::getDataAsString() {
+std::string ProtocolTreeNode::getDataAsString()
+{
if (this->data == NULL)
- return NULL;
- return new std::string(this->data->begin(), this->data->end());
+ return nilstr;
+ return std::string(this->data->begin(), this->data->end());
}
-vector<ProtocolTreeNode*>* ProtocolTreeNode::getAllChildren(const string& tag) {
- vector<ProtocolTreeNode*>* ret = new vector<ProtocolTreeNode*>();
-
- if (this->children == NULL)
- return ret;
+vector<ProtocolTreeNode*> ProtocolTreeNode::getAllChildren(const string &tag)
+{
+ vector<ProtocolTreeNode*> ret;
- for (size_t i = 0; i < this->children->size(); i++)
- if (tag.compare((*children)[i]->tag) == 0)
- ret->push_back((*children)[i]);
+ if (this->children != NULL)
+ for (size_t i = 0; i < this->children->size(); i++)
+ if (tag.compare((*children)[i]->tag) == 0)
+ ret.push_back((*children)[i]);
return ret;
}
-
-bool ProtocolTreeNode::tagEquals(ProtocolTreeNode *node, const string& tag) {
+bool ProtocolTreeNode::tagEquals(ProtocolTreeNode *node, const string& tag)
+{
return (node != NULL && node->tag.compare(tag) == 0);
}
-void ProtocolTreeNode::require(ProtocolTreeNode *node, const string& tag) {
+void ProtocolTreeNode::require(ProtocolTreeNode *node, const string& tag)
+{
if (!tagEquals(node, tag))
throw WAException("failed require. node:" + node->toString() + "tag: " + tag, WAException::CORRUPT_STREAM_EX, 0);
}
diff --git a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h
index 3156c8b7e7..d810852314 100644
--- a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h
+++ b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h
@@ -26,11 +26,11 @@ public:
string toString();
ProtocolTreeNode* getChild(const string& id);
ProtocolTreeNode* getChild(size_t id);
- string* getAttributeValue(const string& attribute);
+ const string& getAttributeValue(const string& attribute);
- vector<ProtocolTreeNode*>* getAllChildren();
- vector<ProtocolTreeNode*>* getAllChildren(const string& tag);
- std::string* getDataAsString();
+ vector<ProtocolTreeNode*> getAllChildren();
+ vector<ProtocolTreeNode*> getAllChildren(const string& tag);
+ std::string getDataAsString();
static bool tagEquals(ProtocolTreeNode *node, const string& tag);
static void require(ProtocolTreeNode *node, const string& tag);
diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp
index d8e57c5882..8fb24b443b 100644
--- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp
+++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp
@@ -433,123 +433,111 @@ bool WAConnection::read() throw(WAException)
}
if (ProtocolTreeNode::tagEquals(node, "iq")) {
- std::string* type = node->getAttributeValue("type");
- std::string* id = node->getAttributeValue("id");
- std::string* from = node->getAttributeValue("from");
- std::string f;
- if (from == NULL)
- f = "";
- else
- f = *from;
-
- if (type == NULL)
+ const string &type = node->getAttributeValue("type");
+ if (type.empty())
throw WAException("missing 'type' attribute in iq stanza", WAException::CORRUPT_STREAM_EX, 0);
- if (type->compare("result") == 0) {
- if (id == NULL)
+ 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<string, IqResultHandler*>::iterator it = this->pending_server_requests.find(*id);
+ std::map<string, IqResultHandler*>::iterator it = this->pending_server_requests.find(id);
if (it != this->pending_server_requests.end()) {
- it->second->parse(node, f);
+ it->second->parse(node, from);
delete it->second;
- this->pending_server_requests.erase(*id);
+ this->pending_server_requests.erase(id);
}
- else if (id->compare(0, this->login->user.size(), this->login->user) == 0) {
+ else if (id.compare(0, this->login->user.size(), this->login->user) == 0) {
ProtocolTreeNode* accountNode = node->getChild(0);
ProtocolTreeNode::require(accountNode, "account");
- std::string* kind = accountNode->getAttributeValue("kind");
- if ((kind != NULL) && (kind->compare("paid") == 0)) {
+ const string &kind = accountNode->getAttributeValue("kind");
+ if (kind == "paid")
this->account_kind = 1;
- }
- else if ((kind != NULL) && (kind->compare("free") == 0)) {
+ else if (kind == "free")
this->account_kind = 0;
- }
else
this->account_kind = -1;
- std::string* expiration = accountNode->getAttributeValue("expiration");
- if (expiration == NULL) {
+
+ const string &expiration = accountNode->getAttributeValue("expiration");
+ if (expiration.empty())
throw WAException("no expiration");
- }
- this->expire_date = atol(expiration->c_str());
+
+ this->expire_date = atol(expiration.c_str());
if (this->expire_date == 0)
- throw WAException("invalid expire date: " + *expiration);
+ throw WAException("invalid expire date: " + expiration);
if (this->event_handler != NULL)
this->event_handler->onAccountChange(this->account_kind, this->expire_date);
}
}
- else if (type->compare("error") == 0) {
- std::map<string, IqResultHandler*>::iterator it = this->pending_server_requests.find(*id);
+ else if (type == "error") {
+ std::map<string, IqResultHandler*>::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);
+ this->pending_server_requests.erase(id);
}
}
- else if (type->compare("get") == 0) {
+ else if (type == "get") {
ProtocolTreeNode* childNode = node->getChild(0);
if (ProtocolTreeNode::tagEquals(childNode, "ping")) {
if (this->event_handler != NULL)
- this->event_handler->onPing(*id);
+ this->event_handler->onPing(id);
}
- else if (ProtocolTreeNode::tagEquals(childNode, "query") && (from != NULL) ? false : // (childNode->getAttributeValue("xmlns") != NULL) && ((*childNode->getAttributeValue("xmlns")).compare("http://jabber.org/protocol/disco#info") == 0) :
- (ProtocolTreeNode::tagEquals(childNode, "relay")) && (from != NULL)) {
- std::string* pin = childNode->getAttributeValue("pin");
- std::string* timeoutString = childNode->getAttributeValue("timeout");
- int timeoutSeconds;
- timeoutSeconds = timeoutString == NULL ? 0 : atoi(timeoutString->c_str());
- if (pin != NULL)
- if (this->event_handler != NULL)
- this->event_handler->onRelayRequest(*pin, timeoutSeconds, *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) {
+ int timeoutSeconds = atoi(childNode->getAttributeValue("timeout").c_str());
+ this->event_handler->onRelayRequest(pin, timeoutSeconds, id);
+ }
}
}
- else if (type->compare("set") == 0) {
+ else if (type == "set") {
ProtocolTreeNode* childNode = node->getChild(0);
if (ProtocolTreeNode::tagEquals(childNode, "query")) {
- std::string* xmlns = childNode->getAttributeValue("xmlns");
- if ((xmlns != NULL) && (xmlns->compare("jabber:iq:roster") == 0)) {
- std::vector<ProtocolTreeNode*>* itemNodes = childNode->getAllChildren("item");
- std::string ask = "";
- for (size_t i = 0; i < itemNodes->size(); i++) {
- ProtocolTreeNode* itemNode = (*itemNodes)[i];
- std::string* jid = itemNode->getAttributeValue("jid");
- std::string* subscription = itemNode->getAttributeValue("subscription");
- ask = *itemNode->getAttributeValue("ask");
+ const string &xmlns = childNode->getAttributeValue("xmlns");
+ if (xmlns == "jabber:iq:roster") {
+ std::vector<ProtocolTreeNode*> 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");
}
- delete itemNodes;
}
}
}
- else
- throw WAException("unknown iq type attribute: " + *type, WAException::CORRUPT_STREAM_EX, 0);
+ else throw WAException("unknown iq type attribute: " + type, WAException::CORRUPT_STREAM_EX, 0);
}
else if (ProtocolTreeNode::tagEquals(node, "presence")) {
- std::string* xmlns = node->getAttributeValue("xmlns");
- std::string* from = node->getAttributeValue("from");
- if (((xmlns == NULL) || (xmlns->compare("urn:xmpp") == 0)) && (from != NULL)) {
- std::string* type = node->getAttributeValue("type");
- if ((type != NULL) && (type->compare("unavailable") == 0)) {
+ const string &xmlns = node->getAttributeValue("xmlns");
+ const string &from = node->getAttributeValue("from");
+ if (xmlns == "urn:xmpp" && !from.empty()) {
+ const string &type = node->getAttributeValue("type");
+ if (type == "unavailable") {
if (this->event_handler != NULL)
- this->event_handler->onAvailable(*from, false);
+ this->event_handler->onAvailable(from, false);
}
- else if ((type == NULL) || (type->compare("available") == 0)) {
+ else if (type == "available") {
if (this->event_handler != NULL)
- this->event_handler->onAvailable(*from, true);
+ this->event_handler->onAvailable(from, true);
}
}
- else if ((xmlns->compare("w") == 0) && (from != NULL)) {
- std::string* add = node->getAttributeValue("add");
- std::string* remove = node->getAttributeValue("remove");
- std::string* status = node->getAttributeValue("status");
- if (add != NULL) {
+ else 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 (this->group_event_handler != NULL)
- this->group_event_handler->onGroupAddUser(*from, *add);
+ this->group_event_handler->onGroupAddUser(from, add);
}
- else if (remove != NULL) {
+ else if (!remove.empty()) {
if (this->group_event_handler != NULL)
- this->group_event_handler->onGroupRemoveUser(*from, *remove);
+ this->group_event_handler->onGroupRemoveUser(from, remove);
}
- else if ((status != NULL) && (status->compare("dirty") == 0)) {
+ else if (status == "dirty") {
std::map<string, string>* categories = parseCategories(node);
if (this->event_handler != NULL)
this->event_handler->onDirty(*categories);
@@ -825,9 +813,9 @@ std::map<string, string>* WAConnection::parseCategories(ProtocolTreeNode* dirtyN
for (size_t i = 0; i < dirtyNode->children->size(); i++) {
ProtocolTreeNode* childNode = (*dirtyNode->children)[i];
if (ProtocolTreeNode::tagEquals(childNode, "category")) {
- std::string* categoryName = childNode->getAttributeValue("name");
- std::string* timestamp = childNode->getAttributeValue("timestamp");
- (*categories)[*categoryName] = *timestamp;
+ const string &categoryName = childNode->getAttributeValue("name");
+ const string &timestamp = childNode->getAttributeValue("timestamp");
+ (*categories)[categoryName] = timestamp;
}
}
}
@@ -837,221 +825,191 @@ std::map<string, string>* WAConnection::parseCategories(ProtocolTreeNode* dirtyN
void WAConnection::parseMessageInitialTagAlreadyChecked(ProtocolTreeNode* messageNode) throw (WAException)
{
- std::string* id = messageNode->getAttributeValue("id");
- std::string* attribute_t = messageNode->getAttributeValue("t");
- std::string* from = messageNode->getAttributeValue("from");
- std::string* authoraux = messageNode->getAttributeValue("author");
- std::string author = "";
-
- if (authoraux != NULL)
- author = *authoraux;
-
- std::string* typeAttribute = messageNode->getAttributeValue("type");
- if (typeAttribute != NULL) {
- if (typeAttribute->compare("error") == 0) {
- int errorCode = 0;
- std::vector<ProtocolTreeNode*>* errorNodes = messageNode->getAllChildren("error");
- for (size_t i = 0; i < errorNodes->size(); i++) {
- ProtocolTreeNode *errorNode = (*errorNodes)[i];
- std::string* codeString = errorNode->getAttributeValue("code");
- errorCode = atoi(codeString->c_str());
- }
+ const string &id = messageNode->getAttributeValue("id");
+ const string &attribute_t = messageNode->getAttributeValue("t");
+ const string &from = messageNode->getAttributeValue("from");
+ const string &author = messageNode->getAttributeValue("author");
+
+ const string &typeAttribute = messageNode->getAttributeValue("type");
+ if (typeAttribute.empty())
+ return;
+
+ if (typeAttribute == "error") {
+ int errorCode = 0;
+ std::vector<ProtocolTreeNode*> errorNodes(messageNode->getAllChildren("error"));
+ for (size_t i = 0; i < errorNodes.size(); i++) {
+ ProtocolTreeNode *errorNode = errorNodes[i];
+ errorCode = atoi(errorNode->getAttributeValue("code").c_str());
+ }
- Key* key = new Key(*from, true, *id);
- FMessage* message = new FMessage(key);
- message->status = FMessage::STATUS_SERVER_BOUNCE;
+ Key* key = new Key(from, true, id);
+ FMessage* message = new FMessage(key);
+ message->status = FMessage::STATUS_SERVER_BOUNCE;
- if (this->event_handler != NULL)
- this->event_handler->onMessageError(message, errorCode);
- delete errorNodes;
- delete message;
+ if (this->event_handler != NULL)
+ this->event_handler->onMessageError(message, errorCode);
+ delete message;
+ }
+ else if (typeAttribute == "subject") {
+ bool receiptRequested = false;
+ std::vector<ProtocolTreeNode*> 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;
}
- else if (typeAttribute->compare("subject") == 0) {
- bool receiptRequested = false;
- std::vector<ProtocolTreeNode*>* requestNodes = messageNode->getAllChildren("request");
- for (size_t i = 0; i < requestNodes->size(); i++) {
- ProtocolTreeNode *requestNode = (*requestNodes)[i];
- if ((requestNode->getAttributeValue("xmlns") != NULL) && (*requestNode->getAttributeValue("xmlns")).compare("urn:xmpp:receipts") == 0)
- receiptRequested = true;
+
+ 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 (receiptRequested)
+ sendSubjectReceived(from, id);
+ }
+ else if (typeAttribute == "chat") {
+ FMessage* fmessage = new FMessage();
+ fmessage->wants_receipt = false;
+ bool duplicate = false;
+
+ std::vector<ProtocolTreeNode*> messageChildren(messageNode->getAllChildren());
+ 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);
}
- delete requestNodes;
-
- ProtocolTreeNode* bodyNode = messageNode->getChild("body");
- std::string* newSubject = bodyNode == NULL ? NULL : bodyNode->getDataAsString();
- if ((newSubject != NULL) && (this->group_event_handler != NULL))
- this->group_event_handler->onGroupNewSubject(*from, author, *newSubject, atoi(attribute_t->c_str()));
- if (newSubject != NULL)
- delete newSubject;
- if (receiptRequested)
- sendSubjectReceived(*from, *id);
- }
- else if (typeAttribute->compare("chat") == 0) {
- FMessage* fmessage = new FMessage();
- fmessage->wants_receipt = false;
- bool duplicate = false;
- std::vector<ProtocolTreeNode*> myVector(0);
- std::vector<ProtocolTreeNode*>* messageChildren = messageNode->children == NULL ? &myVector : messageNode->getAllChildren();
- 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);
- }
- else if (ProtocolTreeNode::tagEquals(childNode, "paused")) {
- if (this->event_handler != NULL)
- this->event_handler->onIsTyping(*from, false);
- }
- else if (ProtocolTreeNode::tagEquals(childNode, "body")) {
- std::string* message = childNode->getDataAsString();
- Key* key = new Key(*from, false, *id);
- fmessage->key = key;
- fmessage->remote_resource = author;
- fmessage->data = *message;
- fmessage->status = FMessage::STATUS_UNSENT;
- if (message != NULL)
- delete message;
+ else if (ProtocolTreeNode::tagEquals(childNode, "paused")) {
+ if (this->event_handler != NULL)
+ this->event_handler->onIsTyping(from, false);
+ }
+ else if (ProtocolTreeNode::tagEquals(childNode, "body")) {
+ Key* key = new Key(from, false, id);
+ fmessage->key = key;
+ fmessage->remote_resource = author;
+ fmessage->data = childNode->getDataAsString();
+ fmessage->status = FMessage::STATUS_UNSENT;
+ }
+ else if (ProtocolTreeNode::tagEquals(childNode, "media") && !id.empty()) {
+ fmessage->media_wa_type = FMessage::getMessage_WA_Type(childNode->getAttributeValue("type"));
+ fmessage->media_url = childNode->getAttributeValue("url");
+ fmessage->media_name = childNode->getAttributeValue("file");
+ fmessage->media_size = Utilities::parseLongLong(childNode->getAttributeValue("size"));
+ fmessage->media_duration_seconds = atoi(childNode->getAttributeValue("seconds").c_str());
+
+ if (fmessage->media_wa_type == FMessage::WA_TYPE_LOCATION) {
+ const string &latitudeString = childNode->getAttributeValue("latitude");
+ const string &longitudeString = childNode->getAttributeValue("longitude");
+ if (latitudeString.empty() || longitudeString.empty())
+ throw WAException("location message missing lat or long attribute", WAException::CORRUPT_STREAM_EX, 0);
+
+ double latitude = atof(latitudeString.c_str());
+ double longitude = atof(longitudeString.c_str());
+ fmessage->latitude = latitude;
+ fmessage->longitude = longitude;
}
- else if (ProtocolTreeNode::tagEquals(childNode, "media") && (id != NULL)) {
- fmessage->media_wa_type = FMessage::getMessage_WA_Type(childNode->getAttributeValue("type"));
- fmessage->media_url = (childNode->getAttributeValue("url") == NULL ? "" : *childNode->getAttributeValue("url"));
- fmessage->media_name = (childNode->getAttributeValue("file") == NULL ? "" : *childNode->getAttributeValue("file"));
-
- if (childNode->getAttributeValue("size") != NULL)
- fmessage->media_size = Utilities::parseLongLong(*childNode->getAttributeValue("size"));
- else
- fmessage->media_size = 0;
-
- if (childNode->getAttributeValue("seconds") != NULL)
- fmessage->media_duration_seconds = atoi(childNode->getAttributeValue("seconds")->c_str());
- else
- fmessage->media_duration_seconds = 0;
-
- if (fmessage->media_wa_type == FMessage::WA_TYPE_LOCATION) {
- std::string* latitudeString = childNode->getAttributeValue("latitude");
- std::string* longitudeString = childNode->getAttributeValue("longitude");
- if (latitudeString == NULL || longitudeString == NULL)
- throw WAException("location message missing lat or long attribute", WAException::CORRUPT_STREAM_EX, 0);
-
- double latitude = atof(latitudeString->c_str());
- double longitude = atof(longitudeString->c_str());
- fmessage->latitude = latitude;
- fmessage->longitude = longitude;
- }
- if (fmessage->media_wa_type == FMessage::WA_TYPE_CONTACT) {
- ProtocolTreeNode* contactChildNode = childNode->getChild(0);
- if (contactChildNode != NULL) {
- fmessage->media_name = (contactChildNode->getAttributeValue("name") == NULL ? "" : *contactChildNode->getAttributeValue("name"));
- std::string* data = contactChildNode->getDataAsString();
- fmessage->data = (data == NULL ? "" : *data);
- if (data != NULL)
- delete data;
- }
+ if (fmessage->media_wa_type == FMessage::WA_TYPE_CONTACT) {
+ ProtocolTreeNode* contactChildNode = childNode->getChild(0);
+ if (contactChildNode != NULL) {
+ fmessage->media_name = contactChildNode->getAttributeValue("name");
+ fmessage->data = contactChildNode->getDataAsString();
}
+ }
+ else {
+ const string &encoding = childNode->getAttributeValue("encoding");
+ if (encoding.empty() || encoding == "text")
+ fmessage->data = childNode->getDataAsString();
else {
- std::string* encoding = childNode->getAttributeValue("encoding");
- std::string* data;
- if ((encoding == NULL) || ((encoding != NULL) && (encoding->compare("text") == 0))) {
- data = childNode->getDataAsString();
- }
- else {
- _LOGDATA("Media data encoding type '%s'", (encoding == NULL ? "text" : encoding->c_str()));
- data = (childNode->data == NULL ? NULL : new std::string(base64_encode(childNode->data->data(), childNode->data->size())));
- }
- fmessage->data = (data == NULL ? "" : *data);
- if (data != NULL)
- delete data;
+ _LOGDATA("Media data encoding type '%s'", encoding.empty() ? "text" : encoding.c_str());
+ fmessage->data = (childNode->data == NULL ? "" : std::string(base64_encode(childNode->data->data(), childNode->data->size())));
}
+ }
- Key* key = new Key(*from, false, *id);
- fmessage->key = key;
- fmessage->remote_resource = author;
+ Key* key = new Key(from, false, id);
+ fmessage->key = key;
+ fmessage->remote_resource = author;
+ }
+ else if (!ProtocolTreeNode::tagEquals(childNode, "active")) {
+ if (ProtocolTreeNode::tagEquals(childNode, "request")) {
+ fmessage->wants_receipt = true;
}
- else if (!ProtocolTreeNode::tagEquals(childNode, "active")) {
- if (ProtocolTreeNode::tagEquals(childNode, "request")) {
- fmessage->wants_receipt = true;
- }
- else if (ProtocolTreeNode::tagEquals(childNode, "notify")) {
- fmessage->notifyname = (childNode->getAttributeValue("name") == NULL) ? "" : *childNode->getAttributeValue("name");
- }
- else if (ProtocolTreeNode::tagEquals(childNode, "x")) {
- std::string* xmlns = childNode->getAttributeValue("xmlns");
- if ((xmlns != NULL) && (xmlns->compare("jabber:x:event") == 0) && (id != NULL)) {
- Key* key = new Key(*from, true, *id);
- FMessage* message = new FMessage(key);
- message->status = FMessage::STATUS_RECEIVED_BY_SERVER;
- if (this->event_handler != NULL)
- this->event_handler->onMessageStatusUpdate(message);
- delete message;
- }
- }
- else if (ProtocolTreeNode::tagEquals(childNode, "received")) {
- Key* key = new Key(*from, true, *id);
+ else if (ProtocolTreeNode::tagEquals(childNode, "notify")) {
+ fmessage->notifyname = childNode->getAttributeValue("name");
+ }
+ else if (ProtocolTreeNode::tagEquals(childNode, "x")) {
+ const string &xmlns = childNode->getAttributeValue("xmlns");
+ if (xmlns == "jabber:x:event" && !id.empty()) {
+ Key* key = new Key(from, true, id);
FMessage* message = new FMessage(key);
- message->status = FMessage::STATUS_RECEIVED_BY_TARGET;
+ message->status = FMessage::STATUS_RECEIVED_BY_SERVER;
if (this->event_handler != NULL)
this->event_handler->onMessageStatusUpdate(message);
delete message;
- if (this->supportsReceiptAcks()) {
- std::string* receipt_type = childNode->getAttributeValue("type");
- if ((receipt_type == NULL) || (receipt_type->compare("delivered") == 0))
- sendDeliveredReceiptAck(*from, *id);
- else if (receipt_type->compare("visible") == 0)
- sendVisibleReceiptAck(*from, *id);
- }
}
- else if (ProtocolTreeNode::tagEquals(childNode, "offline")) {
- if (attribute_t != NULL) {
- fmessage->timestamp = atoi(attribute_t->c_str());
- }
- fmessage->offline = true;
+ }
+ else if (ProtocolTreeNode::tagEquals(childNode, "received")) {
+ Key* key = new Key(from, true, id);
+ FMessage* message = new FMessage(key);
+ message->status = FMessage::STATUS_RECEIVED_BY_TARGET;
+ if (this->event_handler != NULL)
+ this->event_handler->onMessageStatusUpdate(message);
+ delete message;
+ if (this->supportsReceiptAcks()) {
+ const string &receipt_type = childNode->getAttributeValue("type");
+ if (receipt_type == "delivered")
+ sendDeliveredReceiptAck(from, id);
+ else if (receipt_type == "visible")
+ sendVisibleReceiptAck(from, id);
}
}
+ else if (ProtocolTreeNode::tagEquals(childNode, "offline")) {
+ if (!attribute_t.empty())
+ fmessage->timestamp = atoi(attribute_t.c_str());
+ fmessage->offline = true;
+ }
}
+ }
- if (fmessage->timestamp == 0) {
- fmessage->timestamp = time(NULL);
- fmessage->offline = false;
- }
+ if (fmessage->timestamp == 0) {
+ fmessage->timestamp = time(NULL);
+ fmessage->offline = false;
+ }
- if (fmessage->key != NULL && this->event_handler != NULL)
- this->event_handler->onMessageForMe(fmessage, duplicate);
+ if (fmessage->key != NULL && this->event_handler != NULL)
+ this->event_handler->onMessageForMe(fmessage, duplicate);
- delete fmessage;
- }
- else if (typeAttribute->compare("notification") == 0) {
- _LOGDATA("Notification node %s", messageNode->toString().c_str());
- bool flag = false;
- std::vector<ProtocolTreeNode*> myVector(0);
- std::vector<ProtocolTreeNode*>* children = messageNode->children == NULL ? &myVector : messageNode->getAllChildren();
- for (size_t i = 0; i < children->size(); i++) {
- ProtocolTreeNode* child = (*children)[i];
- if (ProtocolTreeNode::tagEquals(child, "notification")) {
- std::string* type = child->getAttributeValue("type");
- if ((type != NULL) && (type->compare("picture") == 0) && (this->event_handler != NULL)) {
- std::vector<ProtocolTreeNode*> myVector2(0);
- std::vector<ProtocolTreeNode*>* children2 = child->children == NULL ? &myVector2 : child->getAllChildren();
- for (unsigned j = 0; j < children2->size(); j++) {
- ProtocolTreeNode* child2 = (*children2)[j];
- if (ProtocolTreeNode::tagEquals(child2, "set")) {
- std::string* id = child2->getAttributeValue("id");
- std::string* author = child2->getAttributeValue("author");
- if (id != NULL)
- this->event_handler->onPictureChanged(*from, ((author == NULL) ? "" : *author), true);
- }
- else if (ProtocolTreeNode::tagEquals(child2, "delete")) {
- std::string* author = child2->getAttributeValue("author");
- this->event_handler->onPictureChanged(*from, ((author == NULL) ? "" : *author), false);
- }
+ delete fmessage;
+ }
+ else if (typeAttribute == "notification") {
+ _LOGDATA("Notification node %s", messageNode->toString().c_str());
+ bool flag = false;
+ std::vector<ProtocolTreeNode*> 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" && this->event_handler != NULL) {
+ std::vector<ProtocolTreeNode*> 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())
+ this->event_handler->onPictureChanged(from, author, true);
+ }
+ else if (ProtocolTreeNode::tagEquals(child2, "delete")) {
+ const string &author = child2->getAttributeValue("author");
+ this->event_handler->onPictureChanged(from, author, false);
}
}
}
- else if (ProtocolTreeNode::tagEquals(child, "request"))
- flag = true;
}
- if (flag)
- this->sendNotificationReceived(*from, *id);
+ else if (ProtocolTreeNode::tagEquals(child, "request"))
+ flag = true;
}
+ if (flag)
+ this->sendNotificationReceived(from, id);
}
}
@@ -1167,21 +1125,20 @@ void WAConnection::sendGetGroups(const std::string& id, const std::string& type)
void WAConnection::readGroupList(ProtocolTreeNode* node, std::vector<std::string>& groups) throw (WAException)
{
- std::vector<ProtocolTreeNode*>* nodes = node->getAllChildren("group");
- for (size_t i = 0; i < nodes->size(); i++) {
- ProtocolTreeNode* groupNode = (*nodes)[i];
- std::string* gid = groupNode->getAttributeValue("id");
- std::string gjid = gidToGjid(*gid);
- std::string* owner = groupNode->getAttributeValue("owner");
- std::string* subject = groupNode->getAttributeValue("subject");
- std::string* subject_t = groupNode->getAttributeValue("s_t");
- std::string* subject_owner = groupNode->getAttributeValue("s_o");
- std::string* creation = groupNode->getAttributeValue("creation");
+ std::vector<ProtocolTreeNode*> nodes(node->getAllChildren("group"));
+ for (size_t i = 0; i < nodes.size(); i++) {
+ ProtocolTreeNode* groupNode = nodes[i];
+ const string &gid = groupNode->getAttributeValue("id");
+ string gjid = gidToGjid(gid);
+ const string &owner = groupNode->getAttributeValue("owner");
+ const string &subject = groupNode->getAttributeValue("subject");
+ const string &subject_t = groupNode->getAttributeValue("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()));
+ this->group_event_handler->onGroupInfoFromList(gjid, owner, subject, subject_owner, atoi(subject_t.c_str()), atoi(creation.c_str()));
groups.push_back(gjid);
}
- delete nodes;
}
std::string WAConnection::gidToGjid(const std::string& gid)
@@ -1189,7 +1146,6 @@ std::string WAConnection::gidToGjid(const std::string& gid)
return gid + "@g.us";
}
-
void WAConnection::sendQueryLastOnline(const std::string& jid) throw (WAException)
{
std::string id = makeId("last_");
@@ -1249,13 +1205,11 @@ void WAConnection::sendGetParticipants(const std::string& gjid) throw (WAExcepti
void WAConnection::readAttributeList(ProtocolTreeNode* node, std::vector<std::string>& vector, const std::string& tag, const std::string& attribute) throw (WAException)
{
- std::vector<ProtocolTreeNode*>* nodes = node->getAllChildren(tag);
- for (size_t i = 0; i < nodes->size(); i++) {
- ProtocolTreeNode* tagNode = (*nodes)[i];
- std::string* value = tagNode->getAttributeValue(attribute);
- vector.push_back(*value);
+ std::vector<ProtocolTreeNode*> nodes(node->getAllChildren(tag));
+ for (size_t i = 0; i < nodes.size(); i++) {
+ ProtocolTreeNode* tagNode = nodes[i];
+ vector.push_back(tagNode->getAttributeValue(attribute));
}
- delete nodes;
}
void WAConnection::sendCreateGroupChat(const std::string& subject) throw (WAException)
diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h
index 96a813ecd0..9fbfde8484 100644
--- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h
+++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h
@@ -36,7 +36,7 @@ public:
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, std::string* paramString2)=0;
+ virtual void onLastSeen(const std::string& paramString1, int paramInt, const string &paramString2) = 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;
@@ -102,25 +102,23 @@ class WAConnection {
IqResultHandler(WAConnection* con) {this->con = con;}
virtual void parse(ProtocolTreeNode* paramProtocolTreeNode, const std::string& paramString) throw (WAException)=0;
void error(ProtocolTreeNode* node, int code) {
- _LOGDATA("WAConnection: error node %s: code = %d", node->getAttributeValue("id")->c_str(), code);
+ _LOGDATA("WAConnection: error node %s: code = %d", node->getAttributeValue("id").c_str(), code);
}
void error(ProtocolTreeNode* node) throw (WAException) {
- std::vector<ProtocolTreeNode*>* nodes = node->getAllChildren("error");
- for (size_t i = 0; i < nodes->size(); i++) {
- ProtocolTreeNode* errorNode = (*nodes)[i];
+ std::vector<ProtocolTreeNode*> nodes(node->getAllChildren("error"));
+ for (size_t i = 0; i < nodes.size(); i++) {
+ ProtocolTreeNode* errorNode = nodes[i];
if (errorNode != NULL) {
- std::string* errorCodeString = errorNode->getAttributeValue("code");
- if (errorCodeString != NULL) {
- int errorCode = atoi(errorCodeString->c_str());
+ const string &errorCodeString = errorNode->getAttributeValue("code");
+ if (!errorCodeString.empty()) {
+ int errorCode = atoi(errorCodeString.c_str());
error(node, errorCode);
}
}
}
- delete nodes;
}
virtual ~IqResultHandler() {}
-
};
class IqResultPingHandler: public IqResultHandler {
@@ -158,15 +156,15 @@ class WAConnection {
public:
IqResultServerPropertiesHandler(WAConnection* con):IqResultHandler(con) {}
virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) {
- std::vector<ProtocolTreeNode*>* nodes = node->getAllChildren("prop");
+ std::vector<ProtocolTreeNode*> nodes(node->getAllChildren("prop"));
std::map<std::string,std::string> nameValueMap;
- for (size_t i = 0; i < nodes->size();i++) {
- ProtocolTreeNode* propNode = (*nodes)[i];
- std::string* nameAttr = propNode->getAttributeValue("name");
- std::string* valueAttr = propNode->getAttributeValue("value");
- nameValueMap[*nameAttr] = *valueAttr;
+ for (size_t i = 0; i < nodes.size();i++) {
+ ProtocolTreeNode* propNode = nodes[i];
+ const string &nameAttr = propNode->getAttributeValue("name");
+ const string &valueAttr = propNode->getAttributeValue("value");
+ nameValueMap[nameAttr] = valueAttr;
}
- delete nodes;
+
if (this->con->group_event_handler != NULL)
this->con->group_event_handler->onServerProperties(&nameValueMap);
}
@@ -186,10 +184,10 @@ class WAConnection {
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) {
- std::string* jid = itemNode->getAttributeValue("value");
- if (jid != NULL && this->con->event_handler != NULL)
- this->con->event_handler->onPrivacyBlockListAdd(*jid);
+ 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);
}
}
}
@@ -202,14 +200,13 @@ class WAConnection {
virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) {
ProtocolTreeNode* groupNode = node->getChild(0);
ProtocolTreeNode::require(groupNode, "group");
- // std::string* gid = groupNode->getAttributeValue("id");
- std::string* owner = groupNode->getAttributeValue("owner");
- std::string* subject = groupNode->getAttributeValue("subject");
- std::string* subject_t = groupNode->getAttributeValue("s_t");
- std::string* subject_owner = groupNode->getAttributeValue("s_o");
- std::string* creation = groupNode->getAttributeValue("creation");
+ const string &owner = groupNode->getAttributeValue("owner");
+ const string &subject = groupNode->getAttributeValue("subject");
+ 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()));
+ this->con->group_event_handler->onGroupInfo(from, owner, subject, subject_owner, atoi(subject_t.c_str()), atoi(creation.c_str()));
}
};
@@ -230,9 +227,9 @@ class WAConnection {
virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) {
ProtocolTreeNode* groupNode = node->getChild(0);
ProtocolTreeNode::require(groupNode, "group");
- std::string* groupId = groupNode->getAttributeValue("id");
- if (groupId != NULL && con->group_event_handler != NULL)
- this->con->group_event_handler->onGroupCreated(from, *groupId);
+ const string &groupId = groupNode->getAttributeValue("id");
+ if (!groupId.empty() && con->group_event_handler != NULL)
+ this->con->group_event_handler->onGroupCreated(from, groupId);
}
};
@@ -242,14 +239,11 @@ class WAConnection {
virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) {
ProtocolTreeNode* firstChild = node->getChild(0);
ProtocolTreeNode::require(firstChild, "query");
- std::string* seconds = firstChild->getAttributeValue("seconds");
- std::string* status = NULL;
- status = firstChild->getDataAsString();
- if (seconds != NULL && !from.empty()) {
+ 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);
- }
- delete status;
+ this->con->event_handler->onLastSeen(from, atoi(seconds.c_str()), status);
}
};
@@ -265,21 +259,19 @@ class WAConnection {
this->newId = newId;
}
virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) {
- std::string* attributeValue = node->getAttributeValue("type");
-
- if ((attributeValue != NULL) && (attributeValue->compare("result") == 0) && (this->con->event_handler != NULL)) {
- std::vector<ProtocolTreeNode*>* children = node->getAllChildren("picture");
- for (size_t i = 0; i < children->size(); i++) {
- ProtocolTreeNode* current = (*children)[i];
- std::string* id = current->getAttributeValue("id");
- if ((id != NULL) && (current->data != NULL) && (current->data->size() > 0)) {
- if (current->data != NULL) {
+ const string &attributeValue = node->getAttributeValue("type");
+
+ if (!attributeValue.empty() && attributeValue == "result" && this->con->event_handler != NULL) {
+ std::vector<ProtocolTreeNode*> 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, this->oldId, this->newId);
- }
break;
}
}
- delete children;
}
}
void error(ProtocolTreeNode* node) throw (WAException) {
@@ -297,38 +289,32 @@ class WAConnection {
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) {
- std::string* photoId = NULL;
ProtocolTreeNode* child = node->getChild("picture");
- if (child != NULL) {
+ if (child != NULL)
this->con->event_handler->onPictureChanged(this->jid, "", true);
- } else {
+ else
this->con->event_handler->onPictureChanged(this->jid, "", false);
- }
}
}
};
-
class IqResultGetPictureIdsHandler: public IqResultHandler {
public:
IqResultGetPictureIdsHandler(WAConnection* con):IqResultHandler(con) {}
virtual void parse(ProtocolTreeNode* node, const std::string& from) throw (WAException) {
// _LOGDATA("onGetPhotoIds %s", node->toString().c_str());
ProtocolTreeNode* groupNode = node->getChild("list");
- std::vector<ProtocolTreeNode*>* children = groupNode->getAllChildren("user");
+ std::vector<ProtocolTreeNode*> children(groupNode->getAllChildren("user"));
std::map<std::string, std::string> ids;
- for (size_t i = 0; i < children->size(); i++) {
- std::string* jid = (*children)[i]->getAttributeValue("jid");
- std::string* id = (*children)[i]->getAttributeValue("id");
- if (jid != NULL) {
- ids[*jid] = (id == NULL? "": *id);
- }
+ for (size_t i = 0; i < children.size(); i++) {
+ const string &jid = children[i]->getAttributeValue("jid");
+ const string &id = children[i]->getAttributeValue("id");
+ if (!jid.empty())
+ ids[jid] = id;
}
- delete children;
- if (this->con->event_handler != NULL) {
+ if (this->con->event_handler != NULL)
this->con->event_handler->onSendGetPictureIds(&ids);
- }
}
};
@@ -336,15 +322,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) {
+ if (this->con->event_handler != NULL)
this->con->event_handler->onDeleteAccount(true);
- }
}
void error(ProtocolTreeNode* node) throw (WAException) {
- if (this->con->event_handler != NULL) {
+ if (this->con->event_handler != NULL)
this->con->event_handler->onDeleteAccount(false);
- }
}
};
diff --git a/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp b/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp
index f8bf6dc993..311edc70a5 100644
--- a/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp
+++ b/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp
@@ -222,18 +222,17 @@ std::vector<unsigned char>* WALogin::readFeaturesUntilChallengeOrSuccess() {
}
void WALogin::parseSuccessNode(ProtocolTreeNode* node) {
- std::string* expiration = node->getAttributeValue("expiration");
- if (expiration != NULL) {
- this->expire_date = atol(expiration->c_str());
+ const string &expiration = node->getAttributeValue("expiration");
+ if (!expiration.empty()) {
+ this->expire_date = atol(expiration.c_str());
if (this->expire_date == 0)
- throw WAException("invalid expire date: " + *expiration);
+ throw WAException("invalid expire date: " + expiration);
}
-
- std::string* kind = node->getAttributeValue("kind");
- if (kind != NULL && kind->compare("paid") == 0)
+ const string &kind = node->getAttributeValue("kind");
+ if (kind == "paid")
this->account_kind = 1;
- else if (kind != NULL && kind->compare("free") == 0)
+ else if (kind == "free")
this->account_kind = 0;
else
this->account_kind = -1;
@@ -254,18 +253,18 @@ std::vector<unsigned char> WALogin::readSuccess() {
ProtocolTreeNode::require(node, "success");
this->parseSuccessNode(node);
- std::string* status = node->getAttributeValue("status");
- if (status != NULL && status->compare("expired") == 0) {
+ const string &status = node->getAttributeValue("status");
+ if (status == "expired") {
delete node;
throw WAException("Account expired on" + std::string(ctime(&this->expire_date)), WAException::LOGIN_FAILURE_EX, WAException::LOGIN_FAILURE_EX_TYPE_EXPIRED, this->expire_date);
}
- if (status != NULL && status->compare("active") == 0) {
- if (node->getAttributeValue("expiration") == NULL) {
+ if (status == "active") {
+ if (node->getAttributeValue("expiration").empty()) {
delete node;
throw WAException("active account with no expiration");
}
- } else
- this->account_kind = -1;
+ }
+ else this->account_kind = -1;
std::vector<unsigned char> data = *node->data;
delete node;
diff --git a/protocols/WhatsApp/src/contacts.cpp b/protocols/WhatsApp/src/contacts.cpp
index ce4258799c..bdef80ad8d 100644
--- a/protocols/WhatsApp/src/contacts.cpp
+++ b/protocols/WhatsApp/src/contacts.cpp
@@ -13,8 +13,7 @@ bool WhatsAppProto::IsMyContact(MCONTACT hContact, bool include_chat)
return false;
}
-MCONTACT WhatsAppProto::AddToContactList(const std::string& jid, BYTE type, bool dont_check, const char *new_name,
- bool isChatRoom, bool isHidden)
+MCONTACT WhatsAppProto::AddToContactList(const std::string& jid, BYTE type, bool dont_check, const char *new_name, bool isChatRoom, bool isHidden)
{
if (!dont_check) {
// First, check if this contact exists
@@ -184,7 +183,7 @@ void WhatsAppProto::onAvailable(const std::string& paramString, bool paramBoolea
this->UpdateStatusMsg(hContact);
}
-void WhatsAppProto::onLastSeen(const std::string& paramString1, int paramInt, std::string* paramString2)
+void WhatsAppProto::onLastSeen(const std::string& paramString1, int paramInt, const string &paramString2)
{
MCONTACT hContact = this->AddToContactList(paramString1, 0, false);
setDword(hContact, WHATSAPP_KEY_LAST_SEEN, paramInt);
diff --git a/protocols/WhatsApp/src/dialogs.cpp b/protocols/WhatsApp/src/dialogs.cpp
index 6973973578..9392737ecf 100644
--- a/protocols/WhatsApp/src/dialogs.cpp
+++ b/protocols/WhatsApp/src/dialogs.cpp
@@ -156,7 +156,7 @@ INT_PTR CALLBACK WhatsAppInputBoxProc(HWND hwndDlg, UINT message, WPARAM wparam,
EnableWindow(GetDlgItem(hwndDlg, IDC_OK), len > 0);
return TRUE;
}
-
+
if (LOWORD(wparam) == IDC_OK) {
ib = reinterpret_cast<input_box*>(GetWindowLongPtr(hwndDlg, GWLP_USERDATA));
TCHAR* value = new TCHAR[ib->limit + 1];
@@ -173,7 +173,7 @@ INT_PTR CALLBACK WhatsAppInputBoxProc(HWND hwndDlg, UINT message, WPARAM wparam,
delete ib;
return TRUE;
}
-
+
if (LOWORD(wparam) == IDC_CANCEL) {
EndDialog(hwndDlg, wparam);
ib = reinterpret_cast<input_box*>(GetWindowLongPtr(hwndDlg, GWLP_USERDATA));
diff --git a/protocols/WhatsApp/src/messages.cpp b/protocols/WhatsApp/src/messages.cpp
index b9f2288164..3526daafe9 100644
--- a/protocols/WhatsApp/src/messages.cpp
+++ b/protocols/WhatsApp/src/messages.cpp
@@ -40,7 +40,6 @@ void WhatsAppProto::onMessageForMe(FMessage* paramFMessage, bool paramBoolean)
int WhatsAppProto::SendMsg(MCONTACT hContact, int flags, const char *msg)
{
-
int msgId = ++(this->msgId);
ForkThread(&WhatsAppProto::SendMsgWorker, new send_direct(hContact, msg, (HANDLE)msgId, flags & IS_CHAT));
@@ -49,7 +48,6 @@ int WhatsAppProto::SendMsg(MCONTACT hContact, int flags, const char *msg)
void WhatsAppProto::SendMsgWorker(void* p)
{
-
if (p == NULL)
return;
@@ -151,8 +149,6 @@ void WhatsAppProto::SendTypingWorker(void* p)
void WhatsAppProto::onMessageStatusUpdate(FMessage* fmsg)
{
-
-
MCONTACT hContact = this->ContactIDToHContact(fmsg->key->remote_jid);
if (hContact == 0)
return;
diff --git a/protocols/WhatsApp/src/proto.h b/protocols/WhatsApp/src/proto.h
index c598d1baff..d3ba55b576 100644
--- a/protocols/WhatsApp/src/proto.h
+++ b/protocols/WhatsApp/src/proto.h
@@ -171,7 +171,7 @@ public:
virtual void onPingResponseReceived() { }
virtual void onAvailable(const std::string& paramString, bool paramBoolean);
virtual void onClientConfigReceived(const std::string& paramString) { }
- virtual void onLastSeen(const std::string& paramString1, int paramInt, std::string* paramString2);
+ virtual void onLastSeen(const std::string& paramString1, int paramInt, const std::string& paramString2);
virtual void onIsTyping(const std::string& paramString, bool paramBoolean);
virtual void onAccountChange(int paramInt, time_t expire_date) { }
virtual void onPrivacyBlockListAdd(const std::string& paramString) { }
diff --git a/protocols/WhatsApp/src/version.h b/protocols/WhatsApp/src/version.h
index c4e377bccc..684deffc8a 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 0
-#define __BUILD_NUM 4
+#define __BUILD_NUM 5
#include <stdver.h>