summaryrefslogtreecommitdiff
path: root/protocols/WhatsApp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-09-19 19:09:07 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-09-19 19:09:07 +0000
commit41de1ce748d969a65bbefc6987c98d4e0a5010a3 (patch)
tree7568765f0ebf66fa54fa470f4eee22251301bc58 /protocols/WhatsApp
parent5148c6e14bc21f758810aafff715bc4121c80d57 (diff)
merge #2
git-svn-id: http://svn.miranda-ng.org/main/trunk@10527 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/WhatsApp')
-rw-r--r--protocols/WhatsApp/src/WASocketConnection.cpp49
-rw-r--r--protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp625
-rw-r--r--protocols/WhatsApp/src/connection.cpp17
-rw-r--r--protocols/WhatsApp/src/contacts.cpp35
-rw-r--r--protocols/WhatsApp/src/dialogs.cpp28
-rw-r--r--protocols/WhatsApp/src/messages.cpp10
-rw-r--r--protocols/WhatsApp/src/proto.cpp47
-rw-r--r--protocols/WhatsApp/src/proto.h3
-rw-r--r--protocols/WhatsApp/src/theme.cpp103
-rw-r--r--protocols/WhatsApp/src/utils.cpp38
-rw-r--r--protocols/WhatsApp/src/version.h2
11 files changed, 381 insertions, 576 deletions
diff --git a/protocols/WhatsApp/src/WASocketConnection.cpp b/protocols/WhatsApp/src/WASocketConnection.cpp
index 477f463291..b5d1b0235c 100644
--- a/protocols/WhatsApp/src/WASocketConnection.cpp
+++ b/protocols/WhatsApp/src/WASocketConnection.cpp
@@ -1,35 +1,36 @@
#include "common.h"
#include "WASocketConnection.h"
-
HANDLE WASocketConnection::hNetlibUser = NULL;
-void WASocketConnection::initNetwork(HANDLE hNetlibUser) throw (WAException) {
+void WASocketConnection::initNetwork(HANDLE hNetlibUser) throw (WAException)
+{
WASocketConnection::hNetlibUser = hNetlibUser;
}
-void WASocketConnection::quitNetwork() {
+void WASocketConnection::quitNetwork()
+{
}
WASocketConnection::WASocketConnection(const std::string& dir, int port) throw (WAException)
{
- NETLIBOPENCONNECTION noc = {sizeof(noc)};
+ NETLIBOPENCONNECTION noc = { sizeof(noc) };
noc.szHost = dir.c_str();
noc.wPort = port;
noc.flags = NLOCF_V2; // | NLOCF_SSL;
- this->hConn = (HANDLE) CallService(MS_NETLIB_OPENCONNECTION, reinterpret_cast<WPARAM>(this->hNetlibUser),
- reinterpret_cast<LPARAM>(&noc));
- if (this->hConn == NULL)
- {
+ this->hConn = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, reinterpret_cast<WPARAM>(this->hNetlibUser),
+ reinterpret_cast<LPARAM>(&noc));
+ if (this->hConn == NULL) {
throw WAException(getLastErrorMsg(), WAException::SOCKET_EX, WAException::SOCKET_EX_OPEN);
}
this->connected = true;
}
-void WASocketConnection::write(int i) {
+void WASocketConnection::write(int i)
+{
char buffer;
- buffer = (char) i;
+ buffer = (char)i;
NETLIBBUFFER nlb;
nlb.buf = &buffer;
@@ -42,12 +43,14 @@ void WASocketConnection::write(int i) {
}
}
-void WASocketConnection::makeNonBlock() {
+void WASocketConnection::makeNonBlock()
+{
//if (fcntl(socket->channel, F_SETFL, O_NONBLOCK) == -1) // #TODO !?
- throw WAException("Error setting socket nonblocking!", WAException::SOCKET_EX, WAException::SOCKET_EX_OPEN);
+ throw WAException("Error setting socket nonblocking!", WAException::SOCKET_EX, WAException::SOCKET_EX_OPEN);
}
-int WASocketConnection::waitForRead() {
+int WASocketConnection::waitForRead()
+{
// #TODO Is this called at all?
return 0;
@@ -79,13 +82,13 @@ void WASocketConnection::flush() {}
void WASocketConnection::write(const std::vector<unsigned char>& bytes, int offset, int length)
{
NETLIBBUFFER nlb;
- std::string tmpBuf = std::string(bytes.begin(), bytes.end());
- nlb.buf = (char*) &(tmpBuf.c_str()[offset]);
+ std::string tmpBuf = std::string(bytes.begin(), bytes.end());
+ nlb.buf = (char*)&(tmpBuf.c_str()[offset]);
nlb.len = length;
nlb.flags = 0; //MSG_NOHTTPGATEWAYWRAP | MSG_NODUMP;
int result = CallService(MS_NETLIB_SEND, reinterpret_cast<WPARAM>(this->hConn),
- reinterpret_cast<LPARAM>(&nlb));
+ reinterpret_cast<LPARAM>(&nlb));
if (result < length) {
throw WAException(getLastErrorMsg(), WAException::SOCKET_EX, WAException::SOCKET_EX_SEND);
}
@@ -96,13 +99,14 @@ void WASocketConnection::write(const std::vector<unsigned char>& bytes, int leng
this->write(bytes, 0, length);
}
-unsigned char WASocketConnection::read() {
+unsigned char WASocketConnection::read()
+{
char c;
SetLastError(0);
int result;
//do {
- result = Netlib_Recv(this->hConn, &c, 1, 0 /*MSG_NOHTTPGATEWAYWRAP | MSG_NODUMP*/);
+ result = Netlib_Recv(this->hConn, &c, 1, 0 /*MSG_NOHTTPGATEWAYWRAP | MSG_NODUMP*/);
//} while (WSAGetLastError() == EINTR);
if (result <= 0) {
throw WAException(getLastErrorMsg(), WAException::SOCKET_EX, WAException::SOCKET_EX_RECV);
@@ -110,7 +114,8 @@ unsigned char WASocketConnection::read() {
return c;
}
-int WASocketConnection::read(std::vector<unsigned char>& b, int off, int length) {
+int WASocketConnection::read(std::vector<unsigned char>& b, int off, int length)
+{
if (off < 0 || length < 0) {
throw new WAException("Out of bounds", WAException::SOCKET_EX, WAException::SOCKET_EX_RECV);
}
@@ -129,11 +134,13 @@ int WASocketConnection::read(std::vector<unsigned char>& b, int off, int length)
return result;
}
-void WASocketConnection::forceShutdown() {
+void WASocketConnection::forceShutdown()
+{
Netlib_Shutdown(this->hConn);
}
-WASocketConnection::~WASocketConnection() {
+WASocketConnection::~WASocketConnection()
+{
this->forceShutdown();
Netlib_CloseHandle(this->hConn);
}
diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp
index 9caf489f97..f819ff8737 100644
--- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp
+++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp
@@ -251,264 +251,25 @@ const char* WAConnection::dictionary[] = {
"WAUTH-1"
};
-
-//const char* WAConnection::dictionary[] = {
-// "",
-// "",
-// "",
-// "",
-// "",
-// "1",
-// "1.0",
-// "ack",
-// "action",
-// "active",
-// "add",
-// "all",
-// "allow",
-// "apple",
-// "audio",
-// "auth",
-// "author",
-// "available",
-// "bad-request",
-// "base64",
-// "Bell.caf",
-// "bind",
-// "body",
-// "Boing.caf",
-// "cancel",
-// "category",
-// "challenge",
-// "chat",
-// "clean",
-// "code",
-// "composing",
-// "config",
-// "conflict",
-// "contacts",
-// "create",
-// "creation",
-// "default",
-// "delay",
-// "delete",
-// "delivered",
-// "deny",
-// "DIGEST-MD5",
-// "DIGEST-MD5-1",
-// "dirty",
-// "en",
-// "enable",
-// "encoding",
-// "error",
-// "expiration",
-// "expired",
-// "failure",
-// "false",
-// "favorites",
-// "feature",
-// "field",
-// "free",
-// "from",
-// "g.us",
-// "get",
-// "Glass.caf",
-// "google",
-// "group",
-// "groups",
-// "g_sound",
-// "Harp.caf",
-// "http://etherx.jabber.org/streams",
-// "http://jabber.org/protocol/chatstates",
-// "id",
-// "image",
-// "img",
-// "inactive",
-// "internal-server-error",
-// "iq",
-// "item",
-// "item-not-found",
-// "jabber:client",
-// "jabber:iq:last",
-// "jabber:iq:privacy",
-// "jabber:x:delay",
-// "jabber:x:event",
-// "jid",
-// "jid-malformed",
-// "kind",
-// "leave",
-// "leave-all",
-// "list",
-// "location",
-// "max_groups",
-// "max_participants",
-// "max_subject",
-// "mechanism",
-// "mechanisms",
-// "media",
-// "message",
-// "message_acks",
-// "missing",
-// "modify",
-// "name",
-// "not-acceptable",
-// "not-allowed",
-// "not-authorized",
-// "notify",
-// "Offline Storage",
-// "order",
-// "owner",
-// "owning",
-// "paid",
-// "participant",
-// "participants",
-// "participating",
-// "particpants",
-// "paused",
-// "picture",
-// "ping",
-// "PLAIN",
-// "platform",
-// "presence",
-// "preview",
-// "probe",
-// "prop",
-// "props",
-// "p_o",
-// "p_t",
-// "query",
-// "raw",
-// "receipt",
-// "receipt_acks",
-// "received",
-// "relay",
-// "remove",
-// "Replaced by new connection",
-// "request",
-// "resource",
-// "resource-constraint",
-// "response",
-// "result",
-// "retry",
-// "rim",
-// "s.whatsapp.net",
-// "seconds",
-// "server",
-// "session",
-// "set",
-// "show",
-// "sid",
-// "sound",
-// "stamp",
-// "starttls",
-// "status",
-// "stream:error",
-// "stream:features",
-// "subject",
-// "subscribe",
-// "success",
-// "system-shutdown",
-// "s_o",
-// "s_t",
-// "t",
-// "TimePassing.caf",
-// "timestamp",
-// "to",
-// "Tri-tone.caf",
-// "type",
-// "unavailable",
-// "uri",
-// "url",
-// "urn:ietf:params:xml:ns:xmpp-bind",
-// "urn:ietf:params:xml:ns:xmpp-sasl",
-// "urn:ietf:params:xml:ns:xmpp-session",
-// "urn:ietf:params:xml:ns:xmpp-stanzas",
-// "urn:ietf:params:xml:ns:xmpp-streams",
-// "urn:xmpp:delay",
-// "urn:xmpp:ping",
-// "urn:xmpp:receipts",
-// "urn:xmpp:whatsapp",
-// "urn:xmpp:whatsapp:dirty",
-// "urn:xmpp:whatsapp:mms",
-// "urn:xmpp:whatsapp:push",
-// "value",
-// "vcard",
-// "version",
-// "video",
-// "w",
-// "w:g",
-// "w:p:r",
-// "wait",
-// "x",
-// "xml-not-well-formed",
-// "xml:lang",
-// "xmlns",
-// "xmlns:stream",
-// "Xylophone.caf",
-// "account",
-// "digest",
-// "g_notify",
-// "method",
-// "password",
-// "registration",
-// "stat",
-// "text",
-// "user",
-// "username",
-// "event",
-// "latitude",
-// "longitude",
-// "true",
-// "after",
-// "before",
-// "broadcast",
-// "count",
-// "features",
-// "first",
-// "index",
-// "invalid-mechanism",
-// "l$dict",
-// "max",
-// "offline",
-// "proceed",
-// "required",
-// "sync",
-// "elapsed",
-// "ip",
-// "microsoft",
-// "mute",
-// "nokia",
-// "off",
-// "pin",
-// "pop_mean_time",
-// "pop_plus_minus",
-// "port",
-// "reason",
-// "server-error",
-// "silent",
-// "timeout",
-// "lc",
-// "lg",
-// "bad-protocol",
-// "none",
-// "remote-server-timeout",
-// "service-unavailable",
-// "w:p",
-// "w:profile:picture",
-// "notification",
-// "",
-// "",
-// "",
-// "",
-// "",
-// "XXX"
-//};
-
-WAConnection::WAConnection(IMutex* mutex, WAListener* event_handler, WAGroupListener* group_event_handler) {
+WAConnection::WAConnection(IMutex* mutex, WAListener* event_handler, WAGroupListener* group_event_handler)
+{
this->init(event_handler, group_event_handler, mutex);
}
-void WAConnection::init(WAListener* event_handler, WAGroupListener* group_event_handler, IMutex* mutex) {
+WAConnection::~WAConnection()
+{
+ delete this->inputKey;
+ delete this->outputKey;
+ delete this->in;
+ delete this->out;
+ std::map<string, IqResultHandler*>::iterator it;
+ for (it = this->pending_server_requests.begin(); it != this->pending_server_requests.end(); it++) {
+ delete it->second;
+ }
+}
+
+void WAConnection::init(WAListener* event_handler, WAGroupListener* group_event_handler, IMutex* mutex)
+{
this->login = NULL;
this->event_handler = event_handler;
this->group_event_handler = group_event_handler;
@@ -529,7 +290,8 @@ void WAConnection::init(WAListener* event_handler, WAGroupListener* group_event_
this->mutex = mutex;
}
-void WAConnection::setLogin(WALogin* login) {
+void WAConnection::setLogin(WALogin* login)
+{
this->login = login;
if (login->expire_date != 0L) {
@@ -546,11 +308,13 @@ void WAConnection::setLogin(WALogin* login) {
this->out = login->getTreeNodeWriter();
}
-WALogin* WAConnection::getLogin() {
+WALogin* WAConnection::getLogin()
+{
return this->login;
}
-void WAConnection::sendMessageWithMedia(FMessage* message) throw (WAException) {
+void WAConnection::sendMessageWithMedia(FMessage* message) throw (WAException)
+{
_LOGDATA("Send message with media %s %d", message->media_name.c_str(), message->media_size);
_LOGDATA("media-url:%s", message->media_url.c_str());
if (message->media_wa_type == FMessage::WA_TYPE_SYSTEM)
@@ -562,12 +326,14 @@ void WAConnection::sendMessageWithMedia(FMessage* message) throw (WAException)
if (message->media_wa_type == FMessage::WA_TYPE_LOCATION) {
(*attribs)["latitude"] = Utilities::doubleToStr(message->latitude);
(*attribs)["longitude"] = Utilities::doubleToStr(message->longitude);
- } else {
+ }
+ else {
if (message->media_wa_type != FMessage::WA_TYPE_CONTACT && !message->media_name.empty() && !message->media_url.empty() && message->media_size > 0L) {
(*attribs)["file"] = message->media_name;
(*attribs)["size"] = Utilities::intToStr((int)message->media_size);
(*attribs)["url"] = message->media_url;
- } else {
+ }
+ else {
(*attribs)["file"] = message->media_name;
(*attribs)["size"] = Utilities::intToStr((int)message->media_size);
(*attribs)["url"] = message->media_url;
@@ -581,7 +347,8 @@ void WAConnection::sendMessageWithMedia(FMessage* message) throw (WAException)
(*attribs2)["name"] = message->media_name;
ProtocolTreeNode* vcardNode = new ProtocolTreeNode("vcard", attribs2, new std::vector<unsigned char>(message->data.begin(), message->data.end()));
mediaNode = new ProtocolTreeNode("media", attribs, vcardNode);
- } else {
+ }
+ else {
(*attribs)["encoding"] = "text";
mediaNode = new ProtocolTreeNode("media", attribs, new std::vector<unsigned char>(message->data.begin(), message->data.end()), NULL);
}
@@ -591,14 +358,16 @@ void WAConnection::sendMessageWithMedia(FMessage* message) throw (WAException)
delete root;
}
-void WAConnection::sendMessageWithBody(FMessage* message) throw (WAException) {
+void WAConnection::sendMessageWithBody(FMessage* message) throw (WAException)
+{
ProtocolTreeNode* bodyNode = new ProtocolTreeNode("body", NULL, new std::vector<unsigned char>(message->data.begin(), message->data.end()));
ProtocolTreeNode* root = WAConnection::getMessageNode(message, bodyNode);
this->out->write(root);
delete root;
}
-ProtocolTreeNode* WAConnection::getMessageNode(FMessage* message, ProtocolTreeNode* child) {
+ProtocolTreeNode* WAConnection::getMessageNode(FMessage* message, ProtocolTreeNode* child)
+{
ProtocolTreeNode* requestNode = NULL;
ProtocolTreeNode* serverNode = new ProtocolTreeNode("server", NULL);
std::map<string, string>* attrib = new std::map<string, string>();
@@ -606,7 +375,7 @@ ProtocolTreeNode* WAConnection::getMessageNode(FMessage* message, ProtocolTreeNo
std::vector<ProtocolTreeNode*>* children = new std::vector<ProtocolTreeNode*>(1);
(*children)[0] = serverNode;
ProtocolTreeNode* xNode = new ProtocolTreeNode("x", attrib, NULL, children);
- int childCount = (requestNode == NULL? 0 : 1) + 2;
+ int childCount = (requestNode == NULL ? 0 : 1) + 2;
std::vector<ProtocolTreeNode*>* messageChildren = new std::vector<ProtocolTreeNode*>(childCount);
int i = 0;
if (requestNode != NULL) {
@@ -626,31 +395,21 @@ ProtocolTreeNode* WAConnection::getMessageNode(FMessage* message, ProtocolTreeNo
return new ProtocolTreeNode("message", attrib2, NULL, messageChildren);
}
-void WAConnection::sendMessage(FMessage* message) throw(WAException) {
+void WAConnection::sendMessage(FMessage* message) throw(WAException)
+{
if (message->media_wa_type != 0)
sendMessageWithMedia(message);
else
sendMessageWithBody(message);
}
-
-WAConnection::~WAConnection() {
- delete this->inputKey;
- delete this->outputKey;
- delete this->in;
- delete this->out;
- std::map<string, IqResultHandler*>::iterator it;
- for (it = this->pending_server_requests.begin(); it != this->pending_server_requests.end(); it++) {
- delete it->second;
- }
-}
-
-
-void WAConnection::setVerboseId(bool b) {
+void WAConnection::setVerboseId(bool b)
+{
this->verbose = b;
}
-void WAConnection::sendAvailableForChat() throw(WAException) {
+void WAConnection::sendAvailableForChat() throw(WAException)
+{
std::map<string, string>* attribs = new std::map<string, string>();
(*attribs)["name"] = this->login->push_name;
ProtocolTreeNode *presenceNode = new ProtocolTreeNode("presence", attribs);
@@ -658,12 +417,14 @@ void WAConnection::sendAvailableForChat() throw(WAException) {
delete presenceNode;
}
-bool WAConnection::read() throw(WAException) {
+bool WAConnection::read() throw(WAException)
+{
ProtocolTreeNode* node;
try {
node = this->in->nextTree();
this->lastTreeRead = time(NULL);
- } catch (exception& ex) {
+ }
+ catch (exception& ex) {
throw WAException(ex.what(), WAException::CORRUPT_STREAM_EX, 0);
}
@@ -673,7 +434,7 @@ bool WAConnection::read() throw(WAException) {
if (ProtocolTreeNode::tagEquals(node, "iq")) {
std::string* type = node->getAttributeValue("type");
- std::string* id = node->getAttributeValue("id");
+ std::string* id = node->getAttributeValue("id");
std::string* from = node->getAttributeValue("from");
std::string f;
if (from == NULL)
@@ -689,19 +450,22 @@ bool WAConnection::read() throw(WAException) {
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);
- if (it!= this->pending_server_requests.end()) {
+ if (it != this->pending_server_requests.end()) {
it->second->parse(node, f);
delete it->second;
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)) {
this->account_kind = 1;
- } else if ((kind != NULL) && (kind->compare("free") == 0)) {
+ }
+ else if ((kind != NULL) && (kind->compare("free") == 0)) {
this->account_kind = 0;
- } else
+ }
+ else
this->account_kind = -1;
std::string* expiration = accountNode->getAttributeValue("expiration");
if (expiration == NULL) {
@@ -713,29 +477,33 @@ bool WAConnection::read() throw(WAException) {
if (this->event_handler != NULL)
this->event_handler->onAccountChange(this->account_kind, this->expire_date);
}
- } else if (type->compare("error") == 0) {
+ }
+ else if (type->compare("error") == 0) {
std::map<string, IqResultHandler*>::iterator it = this->pending_server_requests.find(*id);
- if (it!= this->pending_server_requests.end()) {
+ if (it != this->pending_server_requests.end()) {
it->second->error(node);
delete it->second;
this->pending_server_requests.erase(*id);
}
- } else if (type->compare("get") == 0) {
+ }
+ else if (type->compare("get") == 0) {
ProtocolTreeNode* childNode = node->getChild(0);
if (ProtocolTreeNode::tagEquals(childNode, "ping")) {
if (this->event_handler != NULL)
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)) {
+ }
+ 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());
+ 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 (type->compare("set") == 0) {
+ }
+ else if (type->compare("set") == 0) {
ProtocolTreeNode* childNode = node->getChild(0);
if (ProtocolTreeNode::tagEquals(childNode, "query")) {
std::string* xmlns = childNode->getAttributeValue("xmlns");
@@ -751,9 +519,11 @@ bool WAConnection::read() throw(WAException) {
delete itemNodes;
}
}
- } else
+ }
+ else
throw WAException("unknown iq type attribute: " + *type, WAException::CORRUPT_STREAM_EX, 0);
- } else if (ProtocolTreeNode::tagEquals(node, "presence")) {
+ }
+ 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)) {
@@ -761,28 +531,33 @@ bool WAConnection::read() throw(WAException) {
if ((type != NULL) && (type->compare("unavailable") == 0)) {
if (this->event_handler != NULL)
this->event_handler->onAvailable(*from, false);
- } else if ((type == NULL) || (type->compare("available") == 0)) {
+ }
+ else if ((type == NULL) || (type->compare("available") == 0)) {
if (this->event_handler != NULL)
this->event_handler->onAvailable(*from, true);
}
- } else if ((xmlns->compare("w") == 0) && (from != NULL)) {
+ }
+ 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) {
if (this->group_event_handler != NULL)
this->group_event_handler->onGroupAddUser(*from, *add);
- } else if (remove != NULL) {
+ }
+ else if (remove != NULL) {
if (this->group_event_handler != NULL)
this->group_event_handler->onGroupRemoveUser(*from, *remove);
- } else if ((status != NULL) && (status->compare("dirty") == 0)) {
+ }
+ else if ((status != NULL) && (status->compare("dirty") == 0)) {
std::map<string, string>* categories = parseCategories(node);
if (this->event_handler != NULL)
this->event_handler->onDirty(*categories);
delete categories;
}
}
- } else if (ProtocolTreeNode::tagEquals(node, "message")) {
+ }
+ else if (ProtocolTreeNode::tagEquals(node, "message")) {
parseMessageInitialTagAlreadyChecked(node);
}
@@ -790,11 +565,13 @@ bool WAConnection::read() throw(WAException) {
return true;
}
-void WAConnection::sendNop() throw(WAException) {
+void WAConnection::sendNop() throw(WAException)
+{
this->out->write(NULL);
}
-void WAConnection::sendPing() throw(WAException) {
+void WAConnection::sendPing() throw(WAException)
+{
std::string id = makeId("ping_");
this->pending_server_requests[id] = new IqResultPingHandler(this);
@@ -811,7 +588,8 @@ void WAConnection::sendPing() throw(WAException) {
delete iqNode;
}
-void WAConnection::sendPong(const std::string& id) throw(WAException) {
+void WAConnection::sendPong(const std::string& id) throw(WAException)
+{
std::map<string, string>* attribs = new std::map<string, string>();
(*attribs)["type"] = "result";
(*attribs)["to"] = this->login->domain;
@@ -821,7 +599,8 @@ void WAConnection::sendPong(const std::string& id) throw(WAException) {
delete iqNode;
}
-void WAConnection::sendComposing(const std::string& to) throw(WAException) {
+void WAConnection::sendComposing(const std::string& to) throw(WAException)
+{
std::map<string, string>* attribs1 = new std::map<string, string>();
(*attribs1)["xmlns"] = "http://jabber.org/protocol/chatstates";
ProtocolTreeNode* composingNode = new ProtocolTreeNode("composing", attribs1);
@@ -837,7 +616,8 @@ void WAConnection::sendComposing(const std::string& to) throw(WAException) {
}
-void WAConnection::sendActive() throw(WAException) {
+void WAConnection::sendActive() throw(WAException)
+{
std::map<string, string>* attribs = new std::map<string, string>();
(*attribs)["type"] = "active";
ProtocolTreeNode* presenceNode = new ProtocolTreeNode("presence", attribs);
@@ -847,7 +627,8 @@ void WAConnection::sendActive() throw(WAException) {
delete presenceNode;
}
-void WAConnection::sendInactive() throw(WAException) {
+void WAConnection::sendInactive() throw(WAException)
+{
std::map<string, string>* attribs = new std::map<string, string>();
(*attribs)["type"] = "inactive";
ProtocolTreeNode* presenceNode = new ProtocolTreeNode("presence", attribs);
@@ -857,7 +638,8 @@ void WAConnection::sendInactive() throw(WAException) {
delete presenceNode;
}
-void WAConnection::sendPaused(const std::string& to) throw(WAException) {
+void WAConnection::sendPaused(const std::string& to) throw(WAException)
+{
std::map<string, string>* attribs1 = new std::map<string, string>();
(*attribs1)["xmlns"] = "http://jabber.org/protocol/chatstates";
ProtocolTreeNode* pausedNode = new ProtocolTreeNode("paused", attribs1);
@@ -872,7 +654,8 @@ void WAConnection::sendPaused(const std::string& to) throw(WAException) {
delete messageNode;
}
-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)
+{
std::map<string, string>* attribs1 = new std::map<string, string>();
(*attribs1)["xmlns"] = "urn:xmpp:receipts";
ProtocolTreeNode* receivedNode = new ProtocolTreeNode("received", attribs1);
@@ -884,7 +667,8 @@ void WAConnection::sendSubjectReceived(const std::string& to, const std::string&
delete messageNode;
}
-ProtocolTreeNode* WAConnection::getSubjectMessage(const std::string& to, const std::string& id, ProtocolTreeNode* child) throw (WAException) {
+ProtocolTreeNode* WAConnection::getSubjectMessage(const std::string& to, const std::string& id, ProtocolTreeNode* child) throw (WAException)
+{
std::map<string, string>* attribs1 = new std::map<string, string>();
(*attribs1)["to"] = to;
(*attribs1)["type"] = "subject";
@@ -894,7 +678,8 @@ ProtocolTreeNode* WAConnection::getSubjectMessage(const std::string& to, const s
return messageNode;
}
-void WAConnection::sendMessageReceived(FMessage* message) throw(WAException) {
+void WAConnection::sendMessageReceived(FMessage* message) throw(WAException)
+{
std::map<string, string>* attribs1 = new std::map<string, string>();
(*attribs1)["xmlns"] = "urn:xmpp:receipts";
ProtocolTreeNode* receivedNode = new ProtocolTreeNode("received", attribs1);
@@ -911,19 +696,22 @@ void WAConnection::sendMessageReceived(FMessage* message) throw(WAException) {
}
void WAConnection::sendDeliveredReceiptAck(const std::string& to,
- const std::string& id) throw(WAException) {
+ const std::string& id) throw(WAException)
+{
ProtocolTreeNode *root = getReceiptAck(to, id, "delivered");
this->out->write(root);
delete root;
}
-void WAConnection::sendVisibleReceiptAck(const std::string& to, const std::string& id) throw (WAException) {
+void WAConnection::sendVisibleReceiptAck(const std::string& to, const std::string& id) throw (WAException)
+{
ProtocolTreeNode *root = getReceiptAck(to, id, "visible");
this->out->write(root);
delete root;
}
-void WAConnection::sendPresenceSubscriptionRequest(const std::string& to) throw(WAException) {
+void WAConnection::sendPresenceSubscriptionRequest(const std::string& to) throw(WAException)
+{
std::map<string, string>* attribs1 = new std::map<string, string>();
(*attribs1)["type"] = "subscribe";
(*attribs1)["to"] = to;
@@ -932,10 +720,11 @@ void WAConnection::sendPresenceSubscriptionRequest(const std::string& to) throw(
delete presenceNode;
}
-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)
+{
std::map<string, string>* attribs1 = new std::map<string, string>();
- (*attribs1)["xmlns"] ="urn:xmpp:whatsapp:push";
- (*attribs1)["sound"] =sound;
+ (*attribs1)["xmlns"] = "urn:xmpp:whatsapp:push";
+ (*attribs1)["sound"] = sound;
(*attribs1)["id"] = pushID;
(*attribs1)["preview"] = preview ? "1" : "0";
(*attribs1)["platform"] = platform;
@@ -957,17 +746,18 @@ void WAConnection::sendClientConfig(const std::string& sound, const std::string
}
-void WAConnection::sendClientConfig(const std::string& pushID, bool preview, const std::string& platform, bool defaultSettings, bool groupSettings, const std::vector<GroupSetting>& groups) throw(WAException) {
+void WAConnection::sendClientConfig(const std::string& pushID, bool preview, const std::string& platform, bool defaultSettings, bool groupSettings, const std::vector<GroupSetting>& groups) throw(WAException)
+{
std::map<string, string>* attribs1 = new std::map<string, string>();
- (*attribs1)["xmlns"] ="urn:xmpp:whatsapp:push";
+ (*attribs1)["xmlns"] = "urn:xmpp:whatsapp:push";
(*attribs1)["id"] = pushID;
(*attribs1)["lg"] = "en";
(*attribs1)["lc"] = "US";
(*attribs1)["clear"] = "0";
(*attribs1)["preview"] = preview ? "1" : "0";
(*attribs1)["platform"] = platform;
- (*attribs1)["default"] = defaultSettings? "1": "0";
- (*attribs1)["groups"] = groupSettings? "1" : "0";
+ (*attribs1)["default"] = defaultSettings ? "1" : "0";
+ (*attribs1)["groups"] = groupSettings ? "1" : "0";
ProtocolTreeNode* configNode = new ProtocolTreeNode("config", attribs1, NULL, this->processGroupSettings(groups));
std::string id = makeId("config_");
@@ -981,15 +771,16 @@ void WAConnection::sendClientConfig(const std::string& pushID, bool preview, con
delete iqNode;
}
-std::vector<ProtocolTreeNode*>* WAConnection::processGroupSettings(const std::vector<GroupSetting>& groups) {
+std::vector<ProtocolTreeNode*>* WAConnection::processGroupSettings(const std::vector<GroupSetting>& groups)
+{
std::vector<ProtocolTreeNode*>* result = new std::vector<ProtocolTreeNode*>(groups.size());
if (!groups.empty()) {
time_t now = time(NULL);
for (size_t i = 0; i < groups.size(); i++) {
std::map<string, string>* attribs = new std::map<string, string>();
(*attribs)["jid"] = groups[i].jid;
- (*attribs)["notify"] = (groups[i].enabled? "1": "0");
- (*attribs)["mute"] = Utilities::intToStr( int(groups[i].muteExpiry > now ? (groups[i].muteExpiry - now) : 0));
+ (*attribs)["notify"] = (groups[i].enabled ? "1" : "0");
+ (*attribs)["mute"] = Utilities::intToStr(int(groups[i].muteExpiry > now ? (groups[i].muteExpiry - now) : 0));
_LOGDATA("mute group %s, %s", (*attribs)["jid"].c_str(), (*attribs)["mute"].c_str());
(*result)[i] = new ProtocolTreeNode("item", attribs);
@@ -999,7 +790,8 @@ std::vector<ProtocolTreeNode*>* WAConnection::processGroupSettings(const std::ve
return result;
}
-std::string WAConnection::makeId(const std::string& prefix) {
+std::string WAConnection::makeId(const std::string& prefix)
+{
this->iqid++;
std::string id;
if (this->verbose)
@@ -1010,8 +802,8 @@ 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)
+{
std::map<string, string>* attribs1 = new std::map<string, string>();
(*attribs1)["xmlns"] = "urn:xmpp:receipts";
(*attribs1)["type"] = receiptType;
@@ -1026,8 +818,9 @@ ProtocolTreeNode* WAConnection::getReceiptAck(const std::string& to, const std::
return messageNode;
}
-std::map<string, string>* WAConnection::parseCategories(ProtocolTreeNode* dirtyNode) throw (WAException) {
- std::map<string, string>* categories = new std::map<string,string>();
+std::map<string, string>* WAConnection::parseCategories(ProtocolTreeNode* dirtyNode) throw (WAException)
+{
+ std::map<string, string>* categories = new std::map<string, string>();
if (dirtyNode->children != NULL) {
for (size_t i = 0; i < dirtyNode->children->size(); i++) {
ProtocolTreeNode* childNode = (*dirtyNode->children)[i];
@@ -1042,7 +835,8 @@ std::map<string, string>* WAConnection::parseCategories(ProtocolTreeNode* dirtyN
return categories;
}
-void WAConnection::parseMessageInitialTagAlreadyChecked(ProtocolTreeNode* messageNode) throw (WAException){
+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");
@@ -1071,7 +865,8 @@ void WAConnection::parseMessageInitialTagAlreadyChecked(ProtocolTreeNode* messag
this->event_handler->onMessageError(message, errorCode);
delete errorNodes;
delete message;
- } else if (typeAttribute->compare("subject") == 0) {
+ }
+ 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++) {
@@ -1082,28 +877,31 @@ void WAConnection::parseMessageInitialTagAlreadyChecked(ProtocolTreeNode* messag
delete requestNodes;
ProtocolTreeNode* bodyNode = messageNode->getChild("body");
- std::string* newSubject = bodyNode == NULL? NULL : bodyNode->getDataAsString();
+ 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) {
+ }
+ 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();
+ 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")) {
+ }
+ else if (ProtocolTreeNode::tagEquals(childNode, "paused")) {
if (this->event_handler != NULL)
this->event_handler->onIsTyping(*from, false);
- } else if (ProtocolTreeNode::tagEquals(childNode, "body")) {
+ }
+ else if (ProtocolTreeNode::tagEquals(childNode, "body")) {
std::string* message = childNode->getDataAsString();
Key* key = new Key(*from, false, *id);
fmessage->key = key;
@@ -1112,10 +910,11 @@ void WAConnection::parseMessageInitialTagAlreadyChecked(ProtocolTreeNode* messag
fmessage->status = FMessage::STATUS_UNSENT;
if (message != NULL)
delete message;
- } else if (ProtocolTreeNode::tagEquals(childNode, "media") && (id != NULL)) {
+ }
+ 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"));
+ 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"));
@@ -1142,22 +941,24 @@ void WAConnection::parseMessageInitialTagAlreadyChecked(ProtocolTreeNode* messag
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"));
+ fmessage->media_name = (contactChildNode->getAttributeValue("name") == NULL ? "" : *contactChildNode->getAttributeValue("name"));
std::string* data = contactChildNode->getDataAsString();
- fmessage->data = (data == NULL? "": *data);
+ fmessage->data = (data == NULL ? "" : *data);
if (data != NULL)
delete data;
}
- } else {
+ }
+ 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);
+ 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;
}
@@ -1165,12 +966,15 @@ void WAConnection::parseMessageInitialTagAlreadyChecked(ProtocolTreeNode* messag
Key* key = new Key(*from, false, *id);
fmessage->key = key;
fmessage->remote_resource = author;
- } else if (!ProtocolTreeNode::tagEquals(childNode, "active")) {
+ }
+ 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")) {
+ }
+ 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);
@@ -1180,17 +984,8 @@ void WAConnection::parseMessageInitialTagAlreadyChecked(ProtocolTreeNode* messag
this->event_handler->onMessageStatusUpdate(message);
delete message;
}
-// else if ((xmlns != NULL) && xmlns->compare("jabber:x:delay") == 0) {
-// std::string* stamp_str = childNode->getAttributeValue("stamp");
-// if (stamp_str != NULL) {
-// time_t stamp = Utilities::parseBBDate(*stamp_str);
-// if (stamp != 0) {
-// fmessage->timestamp = (long long) stamp;
-// fmessage->offline = true;
-// }
-// }
-// }
- } else if (ProtocolTreeNode::tagEquals(childNode, "received")) {
+ }
+ 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;
@@ -1204,7 +999,8 @@ void WAConnection::parseMessageInitialTagAlreadyChecked(ProtocolTreeNode* messag
else if (receipt_type->compare("visible") == 0)
sendVisibleReceiptAck(*from, *id);
}
- } else if (ProtocolTreeNode::tagEquals(childNode, "offline")) {
+ }
+ else if (ProtocolTreeNode::tagEquals(childNode, "offline")) {
if (attribute_t != NULL) {
fmessage->timestamp = atoi(attribute_t->c_str());
}
@@ -1222,33 +1018,36 @@ void WAConnection::parseMessageInitialTagAlreadyChecked(ProtocolTreeNode* messag
this->event_handler->onMessageForMe(fmessage, duplicate);
delete fmessage;
- } else if (typeAttribute->compare("notification") == 0) {
+ }
+ 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();
+ 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();
+ 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);
+ this->event_handler->onPictureChanged(*from, ((author == NULL) ? "" : *author), true);
}
- } else if (ProtocolTreeNode::tagEquals(child2, "delete")) {
+ }
+ else if (ProtocolTreeNode::tagEquals(child2, "delete")) {
std::string* author = child2->getAttributeValue("author");
- this->event_handler->onPictureChanged(*from, ((author == NULL)?"":*author), false);
+ this->event_handler->onPictureChanged(*from, ((author == NULL) ? "" : *author), false);
}
}
}
- } else if (ProtocolTreeNode::tagEquals(child, "request")) {
+ }
+ else if (ProtocolTreeNode::tagEquals(child, "request")) {
flag = true;
}
}
@@ -1259,11 +1058,13 @@ void WAConnection::parseMessageInitialTagAlreadyChecked(ProtocolTreeNode* messag
}
}
-bool WAConnection::supportsReceiptAcks() {
+bool WAConnection::supportsReceiptAcks()
+{
return (this->login != NULL) && (this->login->supports_receipt_acks);
}
-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)
+{
std::map<string, string>* attribs1 = new std::map<string, string>();
(*attribs1)["xmlns"] = "urn:xmpp:receipts";
ProtocolTreeNode* child = new ProtocolTreeNode("received", attribs1);
@@ -1278,7 +1079,8 @@ void WAConnection::sendNotificationReceived(const std::string& jid, const std::s
delete node;
}
-void WAConnection::sendClose() throw(WAException) {
+void WAConnection::sendClose() throw(WAException)
+{
std::map<string, string>* attribs1 = new std::map<string, string>();
(*attribs1)["type"] = "unavailable";
ProtocolTreeNode* presenceNode = new ProtocolTreeNode("presence", attribs1);
@@ -1287,7 +1089,8 @@ void WAConnection::sendClose() throw(WAException) {
this->out->streamEnd();
}
-void WAConnection::sendGetPrivacyList() throw (WAException) {
+void WAConnection::sendGetPrivacyList() throw (WAException)
+{
std::string id = makeId("privacylist_");
this->pending_server_requests[id] = new IqResultPrivayListHandler(this);
@@ -1308,7 +1111,8 @@ void WAConnection::sendGetPrivacyList() throw (WAException) {
delete iqNode;
}
-void WAConnection::sendGetServerProperties() throw (WAException) {
+void WAConnection::sendGetServerProperties() throw (WAException)
+{
std::string id = makeId("get_server_properties_");
this->pending_server_requests[id] = new IqResultServerPropertiesHandler(this);
@@ -1327,7 +1131,8 @@ void WAConnection::sendGetServerProperties() throw (WAException) {
delete iqNode;
}
-void WAConnection::sendGetGroups() throw (WAException) {
+void WAConnection::sendGetGroups() throw (WAException)
+{
this->mutex->lock();
std::string id = makeId("get_groups_");
this->pending_server_requests[id] = new IqResultGetGroupsHandler(this, "participating");
@@ -1336,7 +1141,8 @@ void WAConnection::sendGetGroups() throw (WAException) {
this->mutex->unlock();
}
-void WAConnection::sendGetOwningGroups() throw (WAException) {
+void WAConnection::sendGetOwningGroups() throw (WAException)
+{
this->mutex->lock();
std::string id = makeId("get_owning_groups_");
this->pending_server_requests[id] = new IqResultGetGroupsHandler(this, "owning");
@@ -1345,7 +1151,8 @@ void WAConnection::sendGetOwningGroups() throw (WAException) {
this->mutex->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)
+{
std::map<string, string>* attribs1 = new std::map<string, string>();
(*attribs1)["xmlns"] = "w:g";
(*attribs1)["type"] = type;
@@ -1361,7 +1168,8 @@ void WAConnection::sendGetGroups(const std::string& id, const std::string& type)
delete iqNode;
}
-void WAConnection::readGroupList(ProtocolTreeNode* node, std::vector<std::string>& groups) throw (WAException) {
+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];
@@ -1379,12 +1187,14 @@ void WAConnection::readGroupList(ProtocolTreeNode* node, std::vector<std::string
delete nodes;
}
-std::string WAConnection::gidToGjid(const std::string& gid) {
+std::string WAConnection::gidToGjid(const std::string& gid)
+{
return gid + "@g.us";
}
-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);
@@ -1402,7 +1212,8 @@ void WAConnection::sendQueryLastOnline(const std::string& jid) throw (WAExceptio
delete iqNode;
}
-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);
@@ -1420,7 +1231,8 @@ void WAConnection::sendGetGroupInfo(const std::string& gjid) throw (WAException)
delete iqNode;
}
-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);
@@ -1438,7 +1250,8 @@ void WAConnection::sendGetParticipants(const std::string& gjid) throw (WAExcepti
delete iqNode;
}
-void WAConnection::readAttributeList(ProtocolTreeNode* node, std::vector<std::string>& vector, const std::string& tag, const std::string& attribute) throw (WAException) {
+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];
@@ -1448,7 +1261,8 @@ void WAConnection::readAttributeList(ProtocolTreeNode* node, std::vector<std::st
delete nodes;
}
-void WAConnection::sendCreateGroupChat(const std::string& subject) throw (WAException){
+void WAConnection::sendCreateGroupChat(const std::string& subject) throw (WAException)
+{
_LOGDATA("sending create group: %s", subject.c_str());
std::string id = makeId("create_group_");
this->pending_server_requests[id] = new IqResultCreateGroupChatHandler(this);
@@ -1469,7 +1283,8 @@ void WAConnection::sendCreateGroupChat(const std::string& subject) throw (WAExce
delete iqNode;
}
-void WAConnection::sendEndGroupChat(const std::string& gjid) throw (WAException){
+void WAConnection::sendEndGroupChat(const std::string& gjid) throw (WAException)
+{
std::string id = makeId("remove_group_");
std::map<string, string>* attribs1 = new std::map<string, string>();
@@ -1480,14 +1295,15 @@ void WAConnection::sendEndGroupChat(const std::string& gjid) throw (WAException)
std::map<string, string>* attribs2 = new std::map<string, string>();
(*attribs2)["id"] = id;
(*attribs2)["type"] = "set";
- (*attribs2)["to"] = gjid ;
+ (*attribs2)["to"] = gjid;
ProtocolTreeNode* iqNode = new ProtocolTreeNode("iq", attribs2, groupNode);
this->out->write(iqNode);
delete iqNode;
}
-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);
@@ -1509,7 +1325,8 @@ void WAConnection::sendClearDirty(const std::string& category) throw (WAExceptio
delete iqNode;
}
-void WAConnection::sendLeaveGroup(const std::string& gjid) throw (WAException) {
+void WAConnection::sendLeaveGroup(const std::string& gjid) throw (WAException)
+{
std::string id = makeId("leave_group_");
std::map<string, string>* attribs1 = new std::map<string, string>();
@@ -1530,17 +1347,20 @@ void WAConnection::sendLeaveGroup(const std::string& gjid) throw (WAException) {
delete iqNode;
}
-void WAConnection::sendAddParticipants(const std::string& gjid, const std::vector<std::string>& participants) throw (WAException) {
+void WAConnection::sendAddParticipants(const std::string& gjid, const std::vector<std::string>& 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<std::string>& participants) throw (WAException) {
+void WAConnection::sendRemoveParticipants(const std::string& gjid, const std::vector<std::string>& 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<std::string>& participants, const std::string& id, const std::string& inner_tag) throw (WAException) {
+void WAConnection::sendVerbParticipants(const std::string& gjid, const std::vector<std::string>& participants, const std::string& id, const std::string& inner_tag) throw (WAException)
+{
size_t size = participants.size();
std::vector<ProtocolTreeNode*>* children = new std::vector<ProtocolTreeNode*>(size);
for (size_t i = 0; i < size; i++) {
@@ -1563,7 +1383,8 @@ void WAConnection::sendVerbParticipants(const std::string& gjid, const std::vect
delete iqNode;
}
-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_");
std::map<string, string>* attribs1 = new std::map<string, string>();
@@ -1581,7 +1402,8 @@ void WAConnection::sendSetNewSubject(const std::string& gjid, const std::string&
delete iqNode;
}
-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)
return jid;
@@ -1589,7 +1411,8 @@ std::string WAConnection::removeResourceFromJid(const std::string& jid) {
return jid.substr(0, slashidx + 1);
}
-void WAConnection::sendStatusUpdate(std::string& status) throw (WAException) {
+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", NULL, new std::vector<unsigned char>(status.begin(), status.end()), NULL);
@@ -1599,9 +1422,8 @@ void WAConnection::sendStatusUpdate(std::string& status) throw (WAException) {
delete message;
}
-
-
-void WAConnection::sendSetPicture(const std::string& jid, std::vector<unsigned char>* data) throw (WAException) {
+void WAConnection::sendSetPicture(const std::string& jid, std::vector<unsigned char>* data) throw (WAException)
+{
std::string id = this->makeId("set_photo_");
this->pending_server_requests[id] = new IqResultSetPhotoHandler(this, jid);
@@ -1620,7 +1442,8 @@ void WAConnection::sendSetPicture(const std::string& jid, std::vector<unsigned c
delete iqNode;
}
-void WAConnection::sendGetPicture(const std::string& jid, const std::string& type, const std::string& oldId, const std::string& newId) throw (WAException) {
+void WAConnection::sendGetPicture(const std::string& jid, const std::string& type, const std::string& oldId, const std::string& newId) throw (WAException)
+{
std::string id = makeId("get_picture_");
this->pending_server_requests[id] = new IqResultGetPhotoHandler(this, jid, oldId, newId);
@@ -1639,7 +1462,8 @@ void WAConnection::sendGetPicture(const std::string& jid, const std::string& typ
delete iqNode;
}
-void WAConnection::sendGetPictureIds(const std::vector<std::string>& jids) throw (WAException) {
+void WAConnection::sendGetPictureIds(const std::vector<std::string>& jids) throw (WAException)
+{
std::string id = makeId("get_picture_ids_");
this->pending_server_requests[id] = new IqResultGetPictureIdsHandler(this);
@@ -1664,7 +1488,8 @@ void WAConnection::sendGetPictureIds(const std::vector<std::string>& jids) throw
delete iqNode;
}
-void WAConnection::sendDeleteAccount() throw (WAException) {
+void WAConnection::sendDeleteAccount() throw (WAException)
+{
std::string id = makeId("del_acct_");
this->pending_server_requests[id] = new IqResultSendDeleteAccount(this);
diff --git a/protocols/WhatsApp/src/connection.cpp b/protocols/WhatsApp/src/connection.cpp
index a76ad89522..27af21cebb 100644
--- a/protocols/WhatsApp/src/connection.cpp
+++ b/protocols/WhatsApp/src/connection.cpp
@@ -33,51 +33,43 @@ void WhatsAppProto::ChangeStatus(void*)
void WhatsAppProto::stayConnectedLoop(void*)
{
- bool error = true;
std::string cc, in, pass;
DBVARIANT dbv = { 0 };
if (!getString(WHATSAPP_KEY_CC, &dbv)) {
cc = dbv.pszVal;
db_free(&dbv);
- error = cc.empty();
}
- if (error) {
+ if (cc.empty()) {
NotifyEvent(m_tszUserName, TranslateT("Please enter a country-code."), NULL, WHATSAPP_EVENT_CLIENT);
return;
}
- error = true;
if (!getString(WHATSAPP_KEY_LOGIN, &dbv)) {
in = dbv.pszVal;
db_free(&dbv);
- error = in.empty();
}
- if (error) {
+ if (in.empty()) {
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";
- error = true;
if (!getString(WHATSAPP_KEY_NICK, &dbv)) {
this->nick = dbv.pszVal;
db_free(&dbv);
- error = nick.empty();
}
- if (error) {
+ if (nick.empty()) {
NotifyEvent(m_tszUserName, TranslateT("Please enter a nickname."), NULL, WHATSAPP_EVENT_CLIENT);
return;
}
- error = true;
if (!getString(WHATSAPP_KEY_PASS, &dbv)) {
pass = dbv.pszVal;
db_free(&dbv);
- error = pass.empty();
}
- if (error) {
+ if (pass.empty()) {
NotifyEvent(m_tszUserName, TranslateT("Please enter a password."), NULL, WHATSAPP_EVENT_CLIENT);
return;
}
@@ -87,6 +79,7 @@ void WhatsAppProto::stayConnectedLoop(void*)
Mutex writerMutex;
WALogin* login = NULL;
int desiredStatus;
+ bool error = false;
this->conn = NULL;
diff --git a/protocols/WhatsApp/src/contacts.cpp b/protocols/WhatsApp/src/contacts.cpp
index 7bacb6c4a2..8eae2922a9 100644
--- a/protocols/WhatsApp/src/contacts.cpp
+++ b/protocols/WhatsApp/src/contacts.cpp
@@ -156,28 +156,26 @@ void WhatsAppProto::SetAllContactStatuses(int status, bool reset_client)
void WhatsAppProto::ProcessBuddyList(void*)
{
std::vector<std::string> jids;
- DBVARIANT dbv;
for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
if (isChatRoom(hContact))
continue;
- if (!getString(hContact, WHATSAPP_KEY_ID, &dbv)) {
- std::string id(dbv.pszVal);
- db_free(&dbv);
-
+ ptrA jid(getStringA(hContact, WHATSAPP_KEY_ID));
+ if (jid) {
try {
if (!db_get_b(hContact, "CList", "Hidden", 0)) {
// Do not request picture for inactive groups - this would make the group visible again
- jids.push_back(id);
+ jids.push_back(string(jid));
}
if (getByte(hContact, "SimpleChatRoom", 0) == 0) {
- this->connection->sendQueryLastOnline(id);
- this->connection->sendPresenceSubscriptionRequest(id);
+ this->connection->sendQueryLastOnline((char*)jid);
+ this->connection->sendPresenceSubscriptionRequest((char*)jid);
}
}
CODE_BLOCK_CATCH_ALL
}
}
+
if (jids.size() > 0) {
try {
this->connection->sendGetPictureIds(jids);
@@ -197,8 +195,8 @@ void WhatsAppProto::SearchAckThread(void *targ)
std::string jid(id);
jid.append("@s.whatsapp.net");
- this->connection->sendQueryLastOnline(jid);
- this->connection->sendPresenceSubscriptionRequest(jid);
+ this->connection->sendQueryLastOnline(jid.c_str());
+ this->connection->sendPresenceSubscriptionRequest(jid.c_str());
mir_free(targ);
mir_free(id);
@@ -596,11 +594,11 @@ void __cdecl WhatsAppProto::SendSetGroupNameWorker(void* data)
input_box_ret* ibr(static_cast<input_box_ret*>(data));
string groupName(ibr->value);
mir_free(ibr->value);
- DBVARIANT dbv;
- if (!getString(*((MCONTACT*)ibr->userData), WHATSAPP_KEY_ID, &dbv) && this->isOnline()) {
- this->connection->sendSetNewSubject(dbv.pszVal, groupName);
- db_free(&dbv);
- }
+
+ ptrA jid(getStringA(*((MCONTACT*)ibr->userData), WHATSAPP_KEY_ID));
+ if (jid && this->isOnline())
+ this->connection->sendSetNewSubject((char*)jid, groupName);
+
delete ibr->userData;
delete ibr;
}
@@ -640,11 +638,10 @@ INT_PTR __cdecl WhatsAppProto::OnChangeGroupSubject(WPARAM hContact, LPARAM lPar
INT_PTR __cdecl WhatsAppProto::OnLeaveGroup(WPARAM hContact, LPARAM)
{
- DBVARIANT dbv;
- if (this->isOnline() && !getString(hContact, WHATSAPP_KEY_ID, &dbv)) {
+ ptrA jid(getStringA(hContact, WHATSAPP_KEY_ID));
+ if (jid && this->isOnline()) {
setByte(hContact, "IsGroupMember", 0);
- this->connection->sendLeaveGroup(dbv.pszVal);
- db_free(&dbv);
+ this->connection->sendLeaveGroup((char*)jid);
}
return 0;
}
diff --git a/protocols/WhatsApp/src/dialogs.cpp b/protocols/WhatsApp/src/dialogs.cpp
index 95d0006eb6..a434493c04 100644
--- a/protocols/WhatsApp/src/dialogs.cpp
+++ b/protocols/WhatsApp/src/dialogs.cpp
@@ -1,5 +1,8 @@
#include "common.h"
+#define szAskSendSms LPGEN("An SMS with registration-code will be sent to your mobile phone.\nNotice that you are not able to use the real WhatsApp and this plugin simultaneously!\nContinue?")
+#define szPasswordSet LPGEN("Your password has been set automatically. You can proceed with login now")
+
INT_PTR CALLBACK WhatsAppAccountProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
WhatsAppProto *proto;
@@ -45,17 +48,21 @@ INT_PTR CALLBACK WhatsAppAccountProc(HWND hwnd, UINT message, WPARAM wparam, LPA
if (LOWORD(wparam) == IDC_BUTTON_REQUEST_CODE || LOWORD(wparam) == IDC_BUTTON_REGISTER) {
proto = reinterpret_cast<WhatsAppProto*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
+ string password;
char cc[5];
GetDlgItemTextA(hwnd, IDC_CC, cc, sizeof(cc));
char number[128];
GetDlgItemTextA(hwnd, IDC_LOGIN, number, sizeof(number));
if (LOWORD(wparam) == IDC_BUTTON_REQUEST_CODE) {
- if (MessageBox(NULL, TranslateT("An SMS with registration-code will be sent to your mobile phone.\nNotice that you are not able to use the real WhatsApp and this plugin simultaneously!\nContinue?"),
- PRODUCT_NAME, MB_YESNO) == IDYES) {
- string res = proto->Register(REG_STATE_REQ_CODE, string(cc), string(number), string());
- if (!res.empty())
- EnableWindow(GetDlgItem(hwnd, IDC_PW), TRUE);
+ if (IDYES == MessageBox(NULL, TranslateT(szAskSendSms), PRODUCT_NAME, MB_YESNO)) {
+ if (proto->Register(REG_STATE_REQ_CODE, string(cc), string(number), string(), password)) {
+ if (!password.empty()) {
+ MessageBox(NULL, TranslateT(szPasswordSet), PRODUCT_NAME, MB_ICONWARNING);
+ proto->setString(WHATSAPP_KEY_PASS, password.c_str());
+ }
+ else EnableWindow(GetDlgItem(hwnd, IDC_PW), TRUE); // unblock sms code entry field
+ }
}
}
else if (LOWORD(wparam) == IDC_BUTTON_REGISTER) {
@@ -63,14 +70,13 @@ INT_PTR CALLBACK WhatsAppAccountProc(HWND hwnd, UINT message, WPARAM wparam, LPA
GetDlgItemTextA(hwnd, IDC_PW, code, sizeof(code));
if (strlen(code) != 6) {
- MessageBox(NULL, TranslateT("Please correctly specify your registration code received by SMS"),
- PRODUCT_NAME, MB_ICONEXCLAMATION);
+ MessageBox(NULL, TranslateT("Please correctly specify your registration code received by SMS"), PRODUCT_NAME, MB_ICONEXCLAMATION);
return TRUE;
}
- string pw = proto->Register(REG_STATE_REG_CODE, string(cc), string(number), string(code));
- if (!pw.empty()) {
- proto->setString(WHATSAPP_KEY_PASS, pw.c_str());
- MessageBox(NULL, TranslateT("Your password has been set automatically.\nIf you change your password manually, you may lose it and need to request a new code!"), PRODUCT_NAME, MB_ICONWARNING);
+
+ if (proto->Register(REG_STATE_REG_CODE, string(cc), string(number), string(code), password)) {
+ proto->setString(WHATSAPP_KEY_PASS, password.c_str());
+ MessageBox(NULL, TranslateT(szPasswordSet), PRODUCT_NAME, MB_ICONWARNING);
}
}
}
diff --git a/protocols/WhatsApp/src/messages.cpp b/protocols/WhatsApp/src/messages.cpp
index f232d5f451..b9f2288164 100644
--- a/protocols/WhatsApp/src/messages.cpp
+++ b/protocols/WhatsApp/src/messages.cpp
@@ -119,7 +119,6 @@ void WhatsAppProto::onIsTyping(const std::string& paramString, bool paramBoolean
}
}
-
int WhatsAppProto::UserIsTyping(MCONTACT hContact, int type)
{
if (hContact && isOnline())
@@ -139,13 +138,12 @@ void WhatsAppProto::SendTypingWorker(void* p)
if (getWord(typing->hContact, "Status", 0) == ID_STATUS_OFFLINE)
return;
- DBVARIANT dbv;
- if (!getString(typing->hContact, WHATSAPP_KEY_ID, &dbv) &&
- this->isOnline()) {
+ ptrA jid(getStringA(typing->hContact, WHATSAPP_KEY_ID));
+ if (jid && this->isOnline()) {
if (typing->status == PROTOTYPE_SELFTYPING_ON)
- this->connection->sendComposing(dbv.pszVal);
+ this->connection->sendComposing((char*)jid);
else
- this->connection->sendPaused(dbv.pszVal);
+ this->connection->sendPaused((char*)jid);
}
delete typing;
diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp
index 634ac19c05..270a82a30b 100644
--- a/protocols/WhatsApp/src/proto.cpp
+++ b/protocols/WhatsApp/src/proto.cpp
@@ -155,15 +155,14 @@ static NETLIBHTTPHEADER s_registerHeaders[] =
{ "Content-Type", "application/x-www-form-urlencoded" }
};
-string WhatsAppProto::Register(int state, const string &cc, const string &number, const string &code)
+bool WhatsAppProto::Register(int state, const string &cc, const string &number, const string &code, string &ret)
{
string idx;
- string ret;
DBVARIANT dbv;
if (WASocketConnection::hNetlibUser == NULL) {
NotifyEvent(m_tszUserName, TranslateT("Network-connection error."), NULL, WHATSAPP_EVENT_CLIENT);
- return ret;
+ return false;
}
if (!getString(WHATSAPP_KEY_IDX, &dbv)) {
@@ -182,7 +181,7 @@ string WhatsAppProto::Register(int state, const string &cc, const string &number
CMStringA url = WARegister::RequestCodeUrl(cc + number, code);
if (url.IsEmpty())
- return ret;
+ return false;
NETLIBHTTPREQUEST nlhr = { sizeof(NETLIBHTTPREQUEST) };
nlhr.requestType = REQUEST_POST;
@@ -197,7 +196,7 @@ string WhatsAppProto::Register(int state, const string &cc, const string &number
const TCHAR *ptszTitle = TranslateT("Registration");
if (pnlhr == NULL) {
this->NotifyEvent(ptszTitle, TranslateT("Registration failed. Invalid server response."), NULL, WHATSAPP_EVENT_CLIENT);
- return ret;
+ return false;
}
debugLogA("Server response: %s", pnlhr->pData);
@@ -205,7 +204,7 @@ string WhatsAppProto::Register(int state, const string &cc, const string &number
JSONROOT resp(pnlhr->pData);
if (resp == NULL) {
this->NotifyEvent(ptszTitle, TranslateT("Registration failed. Invalid server response."), NULL, WHATSAPP_EVENT_CLIENT);
- return ret;
+ return false;
}
// Status = fail
@@ -222,26 +221,30 @@ string WhatsAppProto::Register(int state, const string &cc, const string &number
CMString tmp(FORMAT, TranslateT("Please try again in %i seconds"), json_as_int(tmpVal));
this->NotifyEvent(ptszTitle, tmp, NULL, WHATSAPP_EVENT_OTHER);
}
- return ret;
+ return false;
}
// Request code
if (state == REG_STATE_REQ_CODE) {
- if (!lstrcmp(ptrT(json_as_string(val)), _T("sent")))
+ val = json_get(resp, "pw");
+ if (val != NULL)
+ ret = _T2A(ptrT(json_as_string(val)));
+ else if (!lstrcmp(ptrT(json_as_string(val)), _T("sent")))
this->NotifyEvent(ptszTitle, TranslateT("Registration code has been sent to your phone."), NULL, WHATSAPP_EVENT_OTHER);
- return "ok";
+ return true;
}
// Register
if (state == REG_STATE_REG_CODE) {
val = json_get(resp, "pw");
- if (val == NULL)
- this->NotifyEvent(ptszTitle, TranslateT("Registration failed."), NULL, WHATSAPP_EVENT_CLIENT);
- else
+ if (val != NULL) {
ret = _T2A(ptrT(json_as_string(val)));
+ return true;
+ }
+ this->NotifyEvent(ptszTitle, TranslateT("Registration failed."), NULL, WHATSAPP_EVENT_CLIENT);
}
- return ret;
+ return false;
}
//////////////////////////////////////////////////////////////////////////////
@@ -270,25 +273,15 @@ int WhatsAppProto::OnOptionsInit(WPARAM wParam, LPARAM lParam)
return 0;
}
-int WhatsAppProto::RefreshBuddyList(WPARAM, LPARAM)
-{
- if (!isOffline()) {
- //ForkThread(
- }
- return 0;
-}
-
int WhatsAppProto::RequestFriendship(WPARAM hContact, LPARAM lParam)
{
if (hContact == NULL || isOffline())
return 0;
- DBVARIANT dbv;
- if (!getString(hContact, WHATSAPP_KEY_ID, &dbv)) {
- std::string id(dbv.pszVal);
- this->connection->sendQueryLastOnline(id);
- this->connection->sendPresenceSubscriptionRequest(id);
- db_free(&dbv);
+ ptrA jid(getStringA(hContact, WHATSAPP_KEY_ID));
+ if (jid) {
+ this->connection->sendQueryLastOnline((char*)jid);
+ this->connection->sendPresenceSubscriptionRequest((char*)jid);
}
return 0;
diff --git a/protocols/WhatsApp/src/proto.h b/protocols/WhatsApp/src/proto.h
index 8963735320..32ed69b72e 100644
--- a/protocols/WhatsApp/src/proto.h
+++ b/protocols/WhatsApp/src/proto.h
@@ -86,7 +86,6 @@ public:
int __cdecl OnOptionsInit(WPARAM, LPARAM);
int __cdecl OnModulesLoaded(WPARAM, LPARAM);
- int __cdecl RefreshBuddyList(WPARAM, LPARAM);
int __cdecl RequestFriendship(WPARAM, LPARAM);
// Events
@@ -134,7 +133,7 @@ public:
}
// Registration
- string Register(int state, const string &cc, const string &number, const string &code);
+ bool Register(int state, const string &cc, const string &number, const string &code, string &password);
// Helpers
std::tstring GetAvatarFolder();
diff --git a/protocols/WhatsApp/src/theme.cpp b/protocols/WhatsApp/src/theme.cpp
index 3376291af0..26a615e4db 100644
--- a/protocols/WhatsApp/src/theme.cpp
+++ b/protocols/WhatsApp/src/theme.cpp
@@ -20,17 +20,17 @@ void InitIcons(void)
HANDLE GetIconHandle(const char* name)
{
- for(size_t i=0; i<SIZEOF(icons); i++)
- if(strcmp(icons[i].szName, name) == 0)
+ for (size_t i = 0; i < SIZEOF(icons); i++)
+ if (strcmp(icons[i].szName, name) == 0)
return icons[i].hIcolib;
return 0;
}
-char *GetIconDescription(const char* name)
+char* GetIconDescription(const char* name)
{
- for(size_t i=0; i<SIZEOF(icons); i++)
- if(strcmp(icons[i].szName, name) == 0)
+ for (size_t i = 0; i < SIZEOF(icons); i++)
+ if (strcmp(icons[i].szName, name) == 0)
return icons[i].szDescr;
return "";
@@ -43,50 +43,50 @@ HGENMENU g_hContactMenuItems[CMITEMS_COUNT];
static WhatsAppProto* GetInstanceByHContact(MCONTACT hContact)
{
char *proto = GetContactProto(hContact);
- if( !proto )
+ if (!proto)
return 0;
- for(int i=0; i<g_Instances.getCount(); i++)
- if(!strcmp(proto,g_Instances[i].m_szModuleName))
+ for (int i = 0; i < g_Instances.getCount(); i++)
+ if (!strcmp(proto, g_Instances[i].m_szModuleName))
return &g_Instances[i];
return 0;
}
-template<INT_PTR (__cdecl WhatsAppProto::*Fcn)(WPARAM,LPARAM)>
-INT_PTR GlobalService(WPARAM wParam,LPARAM lParam)
+template<INT_PTR(__cdecl WhatsAppProto::*Fcn)(WPARAM, LPARAM)>
+INT_PTR GlobalService(WPARAM wParam, LPARAM lParam)
{
WhatsAppProto *proto = GetInstanceByHContact(MCONTACT(wParam));
- return proto ? (proto->*Fcn)(wParam,lParam) : 0;
+ return proto ? (proto->*Fcn)(wParam, lParam) : 0;
}
-template<INT_PTR (__cdecl WhatsAppProto::*Fcn)(WPARAM,LPARAM,LPARAM)>
-INT_PTR GlobalServiceParam(WPARAM wParam,LPARAM lParam, LPARAM lParam2)
+template<INT_PTR(__cdecl WhatsAppProto::*Fcn)(WPARAM, LPARAM, LPARAM)>
+INT_PTR GlobalServiceParam(WPARAM wParam, LPARAM lParam, LPARAM lParam2)
{
WhatsAppProto *proto = GetInstanceByHContact(MCONTACT(wParam));
- return proto ? (proto->*Fcn)(wParam,lParam,lParam2) : 0;
+ return proto ? (proto->*Fcn)(wParam, lParam, lParam2) : 0;
}
-static int PrebuildContactMenu(WPARAM wParam,LPARAM lParam)
+static int PrebuildContactMenu(WPARAM wParam, LPARAM lParam)
{
- for (size_t i=0; i<SIZEOF(g_hContactMenuItems); i++)
+ for (size_t i = 0; i < SIZEOF(g_hContactMenuItems); i++)
Menu_ShowItem(g_hContactMenuItems[i], false);
WhatsAppProto *proto = GetInstanceByHContact(MCONTACT(wParam));
- return proto ? proto->OnPrebuildContactMenu(wParam,lParam) : 0;
+ return proto ? proto->OnPrebuildContactMenu(wParam, lParam) : 0;
}
void WhatsAppProto::InitContactMenus()
{
::HookEvent(ME_CLIST_PREBUILDCONTACTMENU, PrebuildContactMenu);
- CLISTMENUITEM mi = {sizeof(mi)};
+ CLISTMENUITEM mi = { sizeof(mi) };
mi.position = -2000006100;
mi.icolibItem = GetIconHandle("leaveGroup");
mi.pszName = GetIconDescription("leaveGroup");
mi.pszService = "WhatsAppProto/LeaveGroup";
- CreateServiceFunction(mi.pszService,GlobalService<&WhatsAppProto::OnLeaveGroup>);
+ CreateServiceFunction(mi.pszService, GlobalService<&WhatsAppProto::OnLeaveGroup>);
g_hContactMenuItems[CMI_LEAVE_GROUP] = Menu_AddContactMenuItem(&mi);
mi.position = -2000006100;
@@ -98,12 +98,12 @@ void WhatsAppProto::InitContactMenus()
mi.icolibItem = GetIconHandle("changeGroupSubject");
mi.pszName = GetIconDescription("changeGroupSubject");
mi.pszService = "WhatsAppProto/ChangeGroupSubject";
- CreateServiceFunction(mi.pszService,GlobalService<&WhatsAppProto::OnChangeGroupSubject>);
+ CreateServiceFunction(mi.pszService, GlobalService<&WhatsAppProto::OnChangeGroupSubject>);
g_hContactMenuItems[CMI_CHANGE_GROUP_SUBJECT] = Menu_AddContactMenuItem(&mi);
}
-int WhatsAppProto::OnPrebuildContactMenu(WPARAM wParam,LPARAM lParam)
-{
+int WhatsAppProto::OnPrebuildContactMenu(WPARAM wParam, LPARAM lParam)
+{
MCONTACT hContact = MCONTACT(wParam);
if (hContact)
debugLog(pcli->pfnGetContactDisplayName(hContact, 0));
@@ -111,31 +111,29 @@ int WhatsAppProto::OnPrebuildContactMenu(WPARAM wParam,LPARAM lParam)
debugLogA("No contact found");
if (g_hContactMenuItems[CMI_ADD_CONTACT_TO_GROUP] != NULL)
- CallService("CList/RemoveContactMenuItem", (WPARAM) g_hContactMenuItems[CMI_ADD_CONTACT_TO_GROUP], (LPARAM) 0);
+ CallService("CList/RemoveContactMenuItem", (WPARAM)g_hContactMenuItems[CMI_ADD_CONTACT_TO_GROUP], (LPARAM)0);
if (g_hContactMenuItems[CMI_REMOVE_CONTACT_FROM_GROUP] != NULL)
- CallService("CList/RemoveContactMenuItem", (WPARAM) g_hContactMenuItems[CMI_REMOVE_CONTACT_FROM_GROUP], (LPARAM) 0);
-
+ CallService("CList/RemoveContactMenuItem", (WPARAM)g_hContactMenuItems[CMI_REMOVE_CONTACT_FROM_GROUP], (LPARAM)0);
+
int chatType = getByte(hContact, "SimpleChatRoom", 0);
- CLISTMENUITEM mi = {sizeof(mi)};
+ CLISTMENUITEM mi = { sizeof(mi) };
- if (chatType == 0)
- {
+ if (chatType == 0) {
mi.flags = CMIF_CHILDPOPUP;
- mi.position= -2000006102;
+ mi.position = -2000006102;
mi.icolibItem = GetIconHandle("addContactToGroup");
mi.pszName = GetIconDescription("addContactToGroup");
mi.pszService = NULL;
g_hContactMenuItems[CMI_ADD_CONTACT_TO_GROUP] = Menu_AddContactMenuItem(&mi);
- if (!isOnline())
- {
+ if (!isOnline()) {
Menu_ShowItem(g_hContactMenuItems[CMI_ADD_CONTACT_TO_GROUP], false);
return 0;
}
- mi.hParentMenu = (HGENMENU) g_hContactMenuItems[CMI_ADD_CONTACT_TO_GROUP];
+ mi.hParentMenu = (HGENMENU)g_hContactMenuItems[CMI_ADD_CONTACT_TO_GROUP];
mi.flags = CMIF_ROOTHANDLE | CMIF_TCHAR;
int iGrpCount = 0;
@@ -145,16 +143,14 @@ int WhatsAppProto::OnPrebuildContactMenu(WPARAM wParam,LPARAM lParam)
DBVARIANT dbv;
for (map<MCONTACT, map<MCONTACT, bool>>::iterator it = this->isMemberByGroupContact.begin();
- it != this->isMemberByGroupContact.end(); ++it)
- {
+ it != this->isMemberByGroupContact.end(); ++it) {
map<MCONTACT, bool>::iterator memberIt = it->second.find(hContact);
// Only, if current contact is not already member of this group
- if ((memberIt == it->second.end() || memberIt->second == false) && !getString(it->first, "ID", &dbv))
- {
+ if ((memberIt == it->second.end() || memberIt->second == false) && !getString(it->first, "ID", &dbv)) {
fullSvcName = svcName + dbv.pszVal;
- mi.pszService = (char*) fullSvcName.c_str();
+ mi.pszService = (char*)fullSvcName.c_str();
mi.ptszName = pcli->pfnGetContactDisplayName(it->first, 0);
- CreateServiceFunctionParam(mi.pszService, GlobalServiceParam<&WhatsAppProto::OnAddContactToGroup>, (LPARAM) it->first);
+ CreateServiceFunctionParam(mi.pszService, GlobalServiceParam<&WhatsAppProto::OnAddContactToGroup>, (LPARAM)it->first);
Menu_AddContactMenuItem(&mi);
db_free(&dbv);
iGrpCount++;
@@ -163,34 +159,28 @@ int WhatsAppProto::OnPrebuildContactMenu(WPARAM wParam,LPARAM lParam)
if (!iGrpCount)
Menu_ShowItem(g_hContactMenuItems[CMI_ADD_CONTACT_TO_GROUP], false);
}
- else if (chatType == 1)
- {
+ else if (chatType == 1) {
mi.flags = CMIM_FLAGS;
if (!isOnline() || getByte(hContact, "IsGroupMember", 0) == 0)
mi.flags |= CMIF_GRAYED;
- CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM) g_hContactMenuItems[CMI_LEAVE_GROUP], (LPARAM) &mi);
+ CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)g_hContactMenuItems[CMI_LEAVE_GROUP], (LPARAM)&mi);
}
- else if (chatType == 2)
- {
+ else if (chatType == 2) {
// owning chat/group
mi.flags = CMIF_CHILDPOPUP;
- mi.position= -2000006102;
+ mi.position = -2000006102;
mi.icolibItem = GetIconHandle("removeContactFromGroup");
mi.pszName = GetIconDescription("removeContactFromGroup");
mi.pszService = NULL;
g_hContactMenuItems[CMI_REMOVE_CONTACT_FROM_GROUP] = Menu_AddContactMenuItem(&mi);
bool bShow = false;
- if (isOnline() && getByte(hContact, "IsGroupMember", 0) == 1)
- {
+ if (isOnline() && getByte(hContact, "IsGroupMember", 0) == 1) {
map<MCONTACT, map<MCONTACT, bool>>::iterator groupsIt = this->isMemberByGroupContact.find(hContact);
if (groupsIt == this->isMemberByGroupContact.end())
- {
debugLogA("Group exists only on contact list");
- }
- else
- {
- mi.hParentMenu = (HGENMENU) g_hContactMenuItems[CMI_REMOVE_CONTACT_FROM_GROUP];
+ else {
+ mi.hParentMenu = (HGENMENU)g_hContactMenuItems[CMI_REMOVE_CONTACT_FROM_GROUP];
mi.flags = CMIF_ROOTHANDLE | CMIF_TCHAR;
string fullSvcName;
@@ -198,15 +188,13 @@ int WhatsAppProto::OnPrebuildContactMenu(WPARAM wParam,LPARAM lParam)
svcName += "/RemoveContactFromGroup_";
DBVARIANT dbv;
- for (map<MCONTACT, bool>::iterator it = groupsIt->second.begin(); it != groupsIt->second.end(); ++it)
- {
- if (!getString(it->first, "ID", &dbv))
- {
+ for (map<MCONTACT, bool>::iterator it = groupsIt->second.begin(); it != groupsIt->second.end(); ++it) {
+ if (!getString(it->first, "ID", &dbv)) {
fullSvcName = svcName + dbv.pszVal;
- mi.pszService = (char*) fullSvcName.c_str();
+ mi.pszService = (char*)fullSvcName.c_str();
mi.ptszName = pcli->pfnGetContactDisplayName(it->first, 0);
CreateServiceFunctionParam(mi.pszService,
- GlobalServiceParam<&WhatsAppProto::OnRemoveContactFromGroup>, (LPARAM) it->first);
+ GlobalServiceParam<&WhatsAppProto::OnRemoveContactFromGroup>, (LPARAM)it->first);
Menu_AddContactMenuItem(&mi);
db_free(&dbv);
bShow = true;
@@ -225,7 +213,6 @@ int WhatsAppProto::OnPrebuildContactMenu(WPARAM wParam,LPARAM lParam)
int WhatsAppProto::OnBuildStatusMenu(WPARAM wParam, LPARAM lParam)
{
-
char text[200];
strcpy(text, m_szModuleName);
char *tDest = text + strlen(text);
diff --git a/protocols/WhatsApp/src/utils.cpp b/protocols/WhatsApp/src/utils.cpp
index 35d3ceb3a6..0aa95f1a16 100644
--- a/protocols/WhatsApp/src/utils.cpp
+++ b/protocols/WhatsApp/src/utils.cpp
@@ -1,25 +1,25 @@
#include "common.h"
std::string getLastErrorMsg()
-{
- // Retrieve the system error message for the last-error code
-
- LPVOID lpMsgBuf;
- DWORD dw = WSAGetLastError();
-
- FormatMessageA(
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- dw,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPSTR) &lpMsgBuf,
- 0, NULL );
-
- std::string ret((LPSTR) lpMsgBuf);
- LocalFree(lpMsgBuf);
- return ret;
+{
+ // Retrieve the system error message for the last-error code
+
+ LPVOID lpMsgBuf;
+ DWORD dw = WSAGetLastError();
+
+ FormatMessageA(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ dw,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPSTR)&lpMsgBuf,
+ 0, NULL);
+
+ std::string ret((LPSTR)lpMsgBuf);
+ LocalFree(lpMsgBuf);
+ return ret;
}
BYTE* utils::md5string(const BYTE *data, int size, BYTE *digest)
diff --git a/protocols/WhatsApp/src/version.h b/protocols/WhatsApp/src/version.h
index 97ccdcfe90..46c9824af4 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 1
+#define __BUILD_NUM 2
#include <stdver.h>