From 89f3cf8bbb9dc1fa0fe72f6af6638ac086c7e011 Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Wed, 29 Nov 2017 09:33:41 +0300 Subject: libevent, telegram, whatsapp moved to deprecated coz doesn't work --- .../WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp | 347 ------ .../WhatsApp/src/WhatsAPI++/BinTreeNodeReader.h | 73 -- .../WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp | 276 ----- .../WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.h | 71 -- protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp | 113 -- protocols/WhatsApp/src/WhatsAPI++/ByteArray.h | 53 - protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp | 94 -- protocols/WhatsApp/src/WhatsAPI++/FMessage.h | 83 -- protocols/WhatsApp/src/WhatsAPI++/IMutex.h | 14 - .../WhatsApp/src/WhatsAPI++/ISocketConnection.h | 24 - protocols/WhatsApp/src/WhatsAPI++/KeyStream.cpp | 92 -- protocols/WhatsApp/src/WhatsAPI++/LICENSE | 340 ------ .../WhatsApp/src/WhatsAPI++/MediaUploader.cpp | 134 --- protocols/WhatsApp/src/WhatsAPI++/MediaUploader.h | 18 - protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.cpp | 298 ------ protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.h | 23 - .../WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp | 183 ---- .../WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h | 81 -- protocols/WhatsApp/src/WhatsAPI++/README.md | 30 - protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp | 1125 -------------------- protocols/WhatsApp/src/WhatsAPI++/WAConnection.h | 415 -------- protocols/WhatsApp/src/WhatsAPI++/WAException.h | 40 - protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp | 182 ---- protocols/WhatsApp/src/WhatsAPI++/WALogin.h | 67 -- protocols/WhatsApp/src/WhatsAPI++/WARegister.cpp | 71 -- protocols/WhatsApp/src/WhatsAPI++/WARegister.h | 23 - protocols/WhatsApp/src/WhatsAPI++/targetver.h | 8 - protocols/WhatsApp/src/WhatsAPI++/utilities.cpp | 386 ------- protocols/WhatsApp/src/WhatsAPI++/utilities.h | 70 -- 29 files changed, 4734 deletions(-) delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/ByteArray.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/FMessage.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/IMutex.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/ISocketConnection.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/KeyStream.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/LICENSE delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/MediaUploader.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/MediaUploader.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/README.md delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/WAConnection.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/WAException.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/WALogin.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/WARegister.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/WARegister.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/targetver.h delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/utilities.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/utilities.h (limited to 'protocols/WhatsApp/src/WhatsAPI++') diff --git a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp deleted file mode 100644 index b3ed6aa3f5..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp +++ /dev/null @@ -1,347 +0,0 @@ -/* - * BinTreeNodeReader.cpp - * - * Created on: 26/06/2012 - * Author: Antonio - */ - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "BinTreeNodeReader.h" -#include "WAException.h" -#include "ProtocolTreeNode.h" -#include "utilities.h" - -extern const char *dictionary[], *extended_dict[]; - -BinTreeNodeReader::BinTreeNodeReader(WAConnection *conn, ISocketConnection *connection) : - buf(BUFFER_SIZE) -{ - this->conn = conn; - this->rawIn = connection; - this->readSize = 1; - this->in = NULL; -} - -BinTreeNodeReader::~BinTreeNodeReader() -{ - delete this->in; -} - -ProtocolTreeNode* BinTreeNodeReader::nextTreeInternal() -{ - int b = this->in->read(); - int size = readListSize(b); - b = this->in->read(); - if (b == 2) - return NULL; - - std::string* tag = this->readStringAsString(b); - - if ((size == 0) || (tag == NULL)) - throw WAException("nextTree sees 0 list or null tag", WAException::CORRUPT_STREAM_EX, -1); - int attribCount = (size - 2 + size % 2) / 2; - std::map* attribs = readAttributes(attribCount); - if (size % 2 == 1) { - ProtocolTreeNode* ret = new ProtocolTreeNode(*tag); ret->attributes = attribs; - delete tag; - return ret; - } - b = this->in->read(); - if (isListTag(b)) { - ProtocolTreeNode* ret = new ProtocolTreeNode(*tag, NULL, readList(b)); ret->attributes = attribs; - delete tag; - return ret; - } - - ReadData* obj = this->readString(b); - std::vector* data; - if (obj->type == STRING) { - std::string* s = (std::string*) obj->data; - data = new std::vector(s->begin(), s->end()); - delete s; - } - else data = (std::vector*) obj->data; - - ProtocolTreeNode* ret = new ProtocolTreeNode(*tag, data); ret->attributes = attribs; - delete obj; - delete tag; - return ret; -} - -bool BinTreeNodeReader::isListTag(int b) -{ - return (b == 248) || (b == 0) || (b == 249); -} - -void BinTreeNodeReader::decodeStream(int flags, int offset, int length) -{ - unsigned char *pData = (unsigned char*)&buf[0]; - - if ((flags & 8) != 0) { - if (length < 4) - throw WAException("invalid length" + length, WAException::CORRUPT_STREAM_EX, 0); - - length -= 4; - - this->conn->inputKey.decodeMessage(pData, offset + length, 0, length); - } - - if (this->in != NULL) - delete this->in; - this->in = new ByteArrayInputStream(&this->buf, offset, length); -} - -std::map* BinTreeNodeReader::readAttributes(int attribCount) -{ - std::map* attribs = new std::map(); - for (int i = 0; i < attribCount; i++) { - std::string* key = readStringAsString(); - std::string* value = readStringAsString(); - (*attribs)[*key] = *value; - delete key; - delete value; - } - return attribs; -} - -std::vector* BinTreeNodeReader::readList(int token) -{ - int size = readListSize(token); - std::vector* list = new std::vector(size); - for (int i = 0; i < size; i++) - (*list)[i] = nextTreeInternal(); - - return list; -} - -int BinTreeNodeReader::readListSize(int token) -{ - switch (token) { - case 0: return 0; - case 248: return readInt8(this->in); - case 249: return readInt16(this->in); - default: - throw new WAException("invalid list size in readListSize: token " + token, WAException::CORRUPT_STREAM_EX, 0); - } - return 0; -} - -std::vector* BinTreeNodeReader::readList() -{ - return readList(this->in->read()); -} - -ReadData* BinTreeNodeReader::readString() -{ - return readString(this->in->read()); -} - -ReadData* BinTreeNodeReader::readString(int token) -{ - if (token == -1) - throw WAException("-1 token in readString", WAException::CORRUPT_STREAM_EX, -1); - - int bSize; - ReadData *ret = new ReadData(); - - if (token > 2 && token <= 236) { - if (token != 236) - ret->data = new std::string(dictionary[token]); - else { - token = readInt8(this->in); - ret->data = new std::string(extended_dict[token]); - } - - ret->type = STRING; - return ret; - } - - switch (token) { - case 0: - delete ret; - return NULL; - - case 252: - bSize = readInt8(this->in); - { - std::vector* buf8 = new std::vector(bSize); - fillArray(*buf8, bSize, this->in); - ret->type = ARRAY; - ret->data = buf8; - } - return ret; - - case 253: - bSize = readInt24(this->in); - { - std::vector* buf24 = new std::vector(bSize); - fillArray(*buf24, bSize, this->in); - ret->type = ARRAY; - ret->data = buf24; - } - return ret; - - case 255: - bSize = readInt8(this->in); - { - int size = bSize & 0x7f; - int numnibbles = size * 2 - ((bSize & 0x80) ? 1 : 0); - - std::vector tmp(size); - fillArray(tmp, size, this->in); - std::string s; - for (int i = 0; i < numnibbles; i++) { - char c = (tmp[i / 2] >> (4 - ((i & 1) << 2))) & 0xF; - if (c < 10) s += (c + '0'); - else s += (c - 10 + '-'); - } - - ret->type = STRING; - ret->data = new std::string(s); - } - return ret; - - case 250: - std::string* user = readStringAsString(); - std::string* server = readStringAsString(); - if ((user != NULL) && (server != NULL)) { - std::string* result = new std::string(*user + "@" + *server); - delete user; - delete server; - ret->type = STRING; - ret->data = result; - return ret; - } - if (server != NULL) { - ret->type = STRING; - ret->data = server; - return ret; - } - throw WAException("readString couldn't reconstruct jid", WAException::CORRUPT_STREAM_EX, -1); - } - throw WAException("readString couldn't match token" + (int)token, WAException::CORRUPT_STREAM_EX, -1); -} - -std::string* BinTreeNodeReader::objectAsString(ReadData* o) -{ - if (o->type == STRING) - return (std::string*) o->data; - - if (o->type == ARRAY) { - std::vector* v = (std::vector*) o->data; - std::string* ret = new std::string(v->begin(), v->end()); - delete v; - return ret; - } - - return NULL; -} - -std::string* BinTreeNodeReader::readStringAsString() -{ - ReadData* o = this->readString(); - std::string* ret = this->objectAsString(o); - delete o; - return ret; -} - -std::string* BinTreeNodeReader::readStringAsString(int token) -{ - ReadData* o = this->readString(token); - std::string* ret = this->objectAsString(o); - delete o; - return ret; -} - -void BinTreeNodeReader::fillArray(std::vector& buff, int len, ByteArrayInputStream* in) -{ - int count = 0; - while (count < len) - count += in->read(buff, count, len - count); -} - -void BinTreeNodeReader::fillArray(std::vector& buff, int len, ISocketConnection *in) -{ - int count = 0; - while (count < len) - count += in->read(buff, count, len - count); -} - -void BinTreeNodeReader::getTopLevelStream() -{ - int stanzaSize = readInt24(this->rawIn); - int flags = (stanzaSize >> 20); - stanzaSize &= 0x0FFFFF; - - if (this->buf.size() < (size_t)stanzaSize) { - int newsize = max((int)(this->buf.size() * 3 / 2), stanzaSize); - this->buf.resize(newsize); - } - fillArray(this->buf, stanzaSize, this->rawIn); - - this->decodeStream(flags, 0, stanzaSize); -} - -int BinTreeNodeReader::readInt8(ByteArrayInputStream* in) -{ - return in->read(); -} - -int BinTreeNodeReader::readInt16(ByteArrayInputStream* in) -{ - int intTop = in->read(); - int intBot = in->read(); - int value = (intTop << 8) + intBot; - return value; -} - -int BinTreeNodeReader::readInt24(ByteArrayInputStream* in) -{ - int int1 = in->read(); - int int2 = in->read(); - int int3 = in->read(); - int value = (int1 << 16) + (int2 << 8) + int3; - - return value; -} - -ProtocolTreeNode* BinTreeNodeReader::nextTree() -{ - this->getTopLevelStream(); - return nextTreeInternal(); -} - -void BinTreeNodeReader::streamStart() -{ - this->getTopLevelStream(); - - int tag = this->in->read(); - int size = readListSize(tag); - tag = this->in->read(); - if (tag != 1) - throw WAException("expecting STREAM_START in streamStart", WAException::CORRUPT_STREAM_EX, 0); - - int attribCount = (size - 2 + size % 2) / 2; - std::map* attributes = readAttributes(attribCount); - delete attributes; -} - -int BinTreeNodeReader::readInt8(ISocketConnection *in) -{ - return in->read(); -} - -int BinTreeNodeReader::readInt16(ISocketConnection *in) -{ - unsigned char data[2]; - in->read(data, 2); - return (int(data[0]) << 8) + int(data[1]); -} - -int BinTreeNodeReader::readInt24(ISocketConnection *in) -{ - unsigned char data[3]; - in->read(data, 3); - return (int(data[0]) << 16) + (int(data[1]) << 8) + int(data[2]); -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.h b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.h deleted file mode 100644 index 7a2d43454d..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * BinTreeNodeReader.h - * - * Created on: 26/06/2012 - * Author: Antonio - */ -#ifndef BINTREENODEREADER_H_ -#define BINTREENODEREADER_H_ - -#include "ProtocolTreeNode.h" -#include "ISocketConnection.h" -#include "ByteArray.h" -#include "WAConnection.h" -#include -#include -#include - -#define BUFFER_SIZE 512 - -class WAConnection; - -enum ReadType {STRING, ARRAY}; - -class ReadData { -public: - ReadData() {}; - virtual ~ReadData() {}; - - ReadType type; - void * data; -}; - -class BinTreeNodeReader { -private: - ISocketConnection *rawIn; - ByteArrayInputStream* in; - std::vector buf; - int readSize; - WAConnection *conn; - - ProtocolTreeNode* nextTreeInternal(); - bool isListTag(int b); - void decodeStream(int flags, int offset, int length); - std::map* readAttributes(int attribCount); - std::vector* readList(int token); - int readListSize(int token); - std::vector* readList(); - ReadData* readString(); - ReadData* readString(int token); - static void fillArray(std::vector& buff, int len, ByteArrayInputStream* in); - static void fillArray(std::vector& buff, int len, ISocketConnection *in); - std::string* objectAsString(ReadData* o); - std::string* readStringAsString(); - std::string* readStringAsString(int token); - void getTopLevelStream(); - static int readInt8(ByteArrayInputStream* in); - static int readInt8(ISocketConnection *in); - static int readInt16(ByteArrayInputStream* in); - static int readInt16(ISocketConnection *in); - static int readInt24(ByteArrayInputStream* in); - static int readInt24(ISocketConnection *in); - - -public: - BinTreeNodeReader(WAConnection* conn, ISocketConnection* connection); - ~BinTreeNodeReader(); - ProtocolTreeNode* nextTree(); - void streamStart(); - -}; - -#endif /* BINTREENODEREADER_H_ */ - diff --git a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp deleted file mode 100644 index 19bf6a466f..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp +++ /dev/null @@ -1,276 +0,0 @@ -/* - * BinTreeNodeWriter.cpp - * - * Created on: 26/06/2012 - * Author: Antonio - */ - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "BinTreeNodeWriter.h" -#include "utilities.h" - -BinTreeNodeWriter::BinTreeNodeWriter(WAConnection *_conn, ISocketConnection *_connection, IMutex *_mutex) -{ - bSecure = false; - bFlush = true; - mutex = _mutex; - conn = _conn; - out = new ByteArrayOutputStream(4096); - realOut = _connection; - dataBegin = 0; -} - -BinTreeNodeWriter::~BinTreeNodeWriter() -{ - delete out; -} - -void BinTreeNodeWriter::writeDummyHeader() -{ - dataBegin = (int)out->getPosition(); // save node start offset - - unsigned char zero3[3] = { 0, 0, 0 }; - out->write(zero3, 3); -} - -void BinTreeNodeWriter::processBuffer() -{ - unsigned char num = 0; - if (bSecure) { - unsigned char zero4[4] = { 0, 0, 0, 0 }; - out->write(zero4, 4); // reserve place for hmac - num = 0x80; - } - int num3 = (int)out->getLength() - 3 - dataBegin; - if (num3 >= 1048576L) - throw WAException("Buffer too large: " + num3, WAException::CORRUPT_STREAM_EX, 0); - - std::vector &buffer = out->getBuffer(); - if (bSecure) { - int num4 = num3 - 4; - conn->outputKey.encodeMessage(buffer.data(), dataBegin + 3 + num4, dataBegin + 3, num4); - } - - buffer[dataBegin + 2] = (unsigned char)(num3 & 0xFF); num3 >>= 8; - buffer[dataBegin + 1] = (unsigned char)(num3 & 0xFF); num3 >>= 8; - buffer[dataBegin] = (unsigned char)(num3 & 0xFF) | num; -} - -void BinTreeNodeWriter::streamStart(std::string domain, std::string resource) -{ - this->mutex->lock(); - try { - out->setPosition(0); - out->setLength(0); - out->write('W'); - out->write('A'); - out->write(1); - out->write(5); - - std::map attributes; - attributes["to"] = domain; - attributes["resource"] = resource; - this->writeDummyHeader(); - this->writeListStart((int)attributes.size() * 2 + 1); - out->write(1); - this->writeAttributes(&attributes); - this->processBuffer(); - this->flushBuffer(true); - } - catch (exception& ex) { - this->mutex->unlock(); - throw ex; - } - this->mutex->unlock(); -} - -void BinTreeNodeWriter::writeListStart(int i) -{ - if (i == 0) { - out->write(0); - } - else if (i < 256) { - out->write(248); - writeInt8(i); - } - else { - out->write(249); - writeInt16(i); - } -} - -void BinTreeNodeWriter::writeInt8(int v) -{ - out->write(v & 0xFF); -} - -void BinTreeNodeWriter::writeInt16(int v, ISocketConnection* o) -{ - o->write((v & 0xFF00) >> 8); - o->write((v & 0xFF) >> 0); -} - -void BinTreeNodeWriter::writeInt16(int v) -{ - writeInt16(v, this->out); -} - -void BinTreeNodeWriter::writeInt16(int v, ByteArrayOutputStream* o) -{ - o->write((v & 0xFF00) >> 8); - o->write((v & 0xFF) >> 0); -} - -void BinTreeNodeWriter::writeAttributes(std::map* attributes) -{ - if (attributes != NULL) { - std::map::iterator ii; - for (ii = attributes->begin(); ii != attributes->end(); ii++) { - writeString(ii->first); - writeString(ii->second); - } - } -} - -void BinTreeNodeWriter::writeString(const std::string &tag) -{ - int token = WAConnection::tokenLookup(tag); - if (token != -1) - writeToken(token); - else { - size_t atIndex = tag.find('@'); - if (atIndex == 0 || atIndex == string::npos) - writeBytes((unsigned char*)tag.data(), (int)tag.length()); - else { - std::string server = tag.substr(atIndex + 1); - std::string user = tag.substr(0, atIndex); - writeJid(&user, server); - } - } -} - -void BinTreeNodeWriter::writeJid(std::string* user, const std::string &server) -{ - out->write(250); - if (user != NULL && !user->empty()) - writeString(*user); - else - writeToken(0); - - writeString(server); - -} - -void BinTreeNodeWriter::writeToken(int intValue) -{ - if (intValue & 0x100) { - out->write(236); - out->write(intValue & 0xFF); - } - else out->write(intValue); -} - -void BinTreeNodeWriter::writeBytes(unsigned char* bytes, int length) -{ - if (length >= 256) { - out->write(253); - writeInt24(length); - } - else { - out->write(252); - writeInt8(length); - } - out->write(bytes, length); -} - -void BinTreeNodeWriter::writeInt24(int v) -{ - out->write((v & 0xFF0000) >> 16); - out->write((v & 0xFF00) >> 8); - out->write(v & 0xFF); -} - -void BinTreeNodeWriter::writeInternal(const ProtocolTreeNode &node) -{ - writeListStart( - 1 + (node.attributes == NULL ? 0 : (int)node.attributes->size() * 2) - + (node.children == NULL ? 0 : 1) - + (node.data == NULL ? 0 : 1)); - writeString(node.tag); - writeAttributes(node.attributes); - if (node.data != NULL) - writeBytes((unsigned char*)node.data->data(), (int)node.data->size()); - - if (node.children != NULL && !node.children->empty()) { - writeListStart((int)node.children->size()); - for (size_t a = 0; a < node.children->size(); a++) - writeInternal(*(*node.children)[a]); - } -} - -void BinTreeNodeWriter::flushBuffer(bool flushNetwork) -{ - try { - this->processBuffer(); - } - catch (WAException& ex) { - out->setPosition(0); - out->setLength(0); - throw ex; - } - - if (!flushNetwork) - return; - - std::vector &buffer = out->getBuffer(); - this->realOut->write(buffer, (int)buffer.size()); - if (out->getCapacity() - out->getLength() < 3L || out->getLength() > 4096L) { - delete out; - out = new ByteArrayOutputStream(4096); - } - else { - out->setPosition(0); - out->setLength(0); - } - dataBegin = 0; -} - -void BinTreeNodeWriter::streamEnd() -{ - this->mutex->lock(); - try { - writeListStart(1); - out->write(2); - flushBuffer(true); - } - catch (exception& ex) { - this->mutex->unlock(); - throw ex; - } - this->mutex->unlock(); -} - -void BinTreeNodeWriter::write(const ProtocolTreeNode& node) -{ - this->mutex->lock(); - try { - this->writeDummyHeader(); - - if (bSecure) { - string tmp = node.toString(); - this->realOut->log("XML written:\n", tmp.c_str()); - } - - if (node.tag.empty()) - out->write(0); - else - writeInternal(node); - flushBuffer(bFlush); - } - catch (exception& ex) { - this->mutex->unlock(); - throw WAException(ex.what()); - } - this->mutex->unlock(); -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.h b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.h deleted file mode 100644 index f7ed6a6bc8..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * BinTreeNodeWriter.h - * - * Created on: 26/06/2012 - * Author: Antonio - */ - - -#ifndef BINTREENODEWRITER_H_ -#define BINTREENODEWRITER_H_ - -#include -#include "ProtocolTreeNode.h" -#include "ISocketConnection.h" -#include "ByteArray.h" -#include "IMutex.h" -#include "WAConnection.h" - -using namespace std; - -#define STREAM_START 1 -#define STREAM_END 2 -#define LIST_EMPTY 0 -#define LIST_8 248 -#define LIST_16 249 -#define JID_PAIR 250 -#define BINARY_8 252 -#define BINARY_24 253 -#define TOKEN_8 254 - -#include - -class BinTreeNodeWriter -{ - friend class WAConnection; - - WAConnection *conn; - ISocketConnection *realOut; - ByteArrayOutputStream *out; - IMutex *mutex; - int dataBegin; - bool bSecure, bFlush; - - void writeListStart(int i); - void writeInt8(int v); - void writeInt16(int v, ISocketConnection* out); - void writeInt16(int v, ByteArrayOutputStream* out); - void writeInt16(int v); - void writeAttributes(std::map* attributes); - void writeString(const std::string &tag); - void writeJid(std::string* user, const std::string &server); - void writeToken(int intValue); - void writeBytes(unsigned char* bytes, int length); - void writeInt24(int v); - void writeInternal(const ProtocolTreeNode &node); - void writeDummyHeader(); - void processBuffer(); - -public: - BinTreeNodeWriter(WAConnection* conn, ISocketConnection* connection, IMutex* mutex); - ~BinTreeNodeWriter(); - - void streamStart(std::string domain, std::string resource); - void flushBuffer(bool flushNetwork); - void streamEnd(); - void write(const ProtocolTreeNode &node); - - void setSecure() { bSecure = true; } -}; - -#endif /* BINTREENODEWRITER_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp b/protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp deleted file mode 100644 index 8dbc044e67..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * ByteArray.cpp - * - * Created on: 26/06/2012 - * Author: Antonio - */ - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "ByteArray.h" -#include "WAException.h" -#include "utilities.h" - -ByteArrayOutputStream::ByteArrayOutputStream(int size) -{ - buf.reserve(size); - position = 0; -} - -void ByteArrayOutputStream::setLength(size_t length) -{ - buf.resize(length); -} - -void ByteArrayOutputStream::setPosition(size_t count) -{ - position = count; -} - - -std::vector& ByteArrayOutputStream::getBuffer() -{ - return buf; -} - -void ByteArrayOutputStream::write(int i) -{ - if (this->position == this->buf.size()) - buf.push_back((unsigned char)i); - else - buf[position] = (unsigned char)i; - position++; -} - -void ByteArrayOutputStream::write(unsigned char* b, size_t len) -{ - if (len == 0) - return; - - for (size_t i = 0; i < len; i++) - write(b[i]); -} - -void ByteArrayOutputStream::write(const std::string &s) -{ - for (size_t i = 0; i < s.size(); i++) - write((unsigned char)s[i]); -} - -ByteArrayOutputStream::~ByteArrayOutputStream() -{ -} - -ByteArrayInputStream::ByteArrayInputStream(std::vector* buf, size_t off, size_t length) -{ - this->buf = buf; - this->pos = off; - this->count = min(off + length, buf->size()); -} - -ByteArrayInputStream::ByteArrayInputStream(std::vector* buf) -{ - this->buf = buf; - this->pos = 0; - this->count = buf->size(); -} - -int ByteArrayInputStream::read() -{ - return (pos < count) ? ((*this->buf)[pos++]) : -1; -} - -int ByteArrayInputStream::read(std::vector& b, size_t off, size_t len) -{ - if (len > (b.size() - off)) - throw new WAException("Index out of bounds"); - - if (len == 0) - return 0; - - int c = read(); - if (c == -1) - return -1; - - b[off] = (unsigned char)c; - - size_t i = 1; - try { - for (; i < len; i++) { - c = read(); - if (c == -1) - break; - - b[off + i] = (unsigned char)c; - } - } - catch (std::exception&) { - } - return (int)i; -} - -ByteArrayInputStream::~ByteArrayInputStream() -{} diff --git a/protocols/WhatsApp/src/WhatsAPI++/ByteArray.h b/protocols/WhatsApp/src/WhatsAPI++/ByteArray.h deleted file mode 100644 index d3375d1f3b..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/ByteArray.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * ByteArray.h - * - * Created on: 26/06/2012 - * Author: Antonio - */ - - - -#ifndef BYTEARRAY_H_ -#define BYTEARRAY_H_ - -#include -#include - -class ByteArrayOutputStream { -protected: - std::vector buf; - size_t position; - -public: - ByteArrayOutputStream(int size = 32); - virtual ~ByteArrayOutputStream(); - - std::vector& getBuffer(); - void setPosition(size_t count); - void write(int i); - void write(unsigned char* c, size_t length); - void write(const std::string &s); - void setLength(size_t length); - - __forceinline size_t getCapacity() const { return buf.capacity(); } - __forceinline size_t getLength() const { return buf.size(); } - __forceinline size_t getPosition() const { return position; } -}; - -class ByteArrayInputStream { -protected: - std::vector* buf; - size_t pos; - size_t mark; - size_t count; - -public: - ByteArrayInputStream(std::vector* buf, size_t off, size_t length ); - ByteArrayInputStream(std::vector* buf); - int read(); - int read(std::vector& b, size_t off, size_t length); - - virtual ~ByteArrayInputStream(); -}; - -#endif /* BYTEARRAY_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp b/protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp deleted file mode 100644 index 8358560f99..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * FMessage.cpp - * - * Created on: 02/07/2012 - * Author: Antonio - */ - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "utilities.h" - -FMessage::FMessage() : - key("", false, "") -{ - this->timestamp = 0; - this->media_wa_type = 0; - this->longitude = 0; - this->latitude = 0; - this->media_duration_seconds = 0; - this->media_size = 0; -} - -FMessage::FMessage(const std::string &remote_jid, bool from_me, const std::string &id) : - key(remote_jid, from_me, id) -{ - this->timestamp = time(NULL); - this->media_wa_type = 0; - this->longitude = 0; - this->latitude = 0; - this->media_duration_seconds = 0; - this->media_size = 0; -} - -std::string FMessage::getMessage_WA_Type_StrValue(unsigned char type) -{ - switch (type) { - case FMessage::WA_TYPE_UNDEFINED: - return ""; - case FMessage::WA_TYPE_SYSTEM: - return "system"; - case FMessage::WA_TYPE_AUDIO: - return "audio"; - case FMessage::WA_TYPE_CONTACT: - return "vcard"; - case FMessage::WA_TYPE_IMAGE: - return "image"; - case FMessage::WA_TYPE_LOCATION: - return "location"; - case FMessage::WA_TYPE_VIDEO: - return "video"; - } - - return ""; -} - -FMessage::~FMessage() -{ -} - -Key::Key(const std::string &remote_jid, bool from_me, const std::string &id) -{ - this->remote_jid = remote_jid; - this->from_me = from_me; - this->id = id; -} - -std::string Key::toString() -{ - return "Key[id=" + id + ", from_me=" + (from_me ? "true" : "false") + ", remote_jid=" + remote_jid + "]"; -} - - -unsigned char FMessage::getMessage_WA_Type(const std::string &type) -{ - if (type.empty()) - return WA_TYPE_UNDEFINED; - - std::string typeLower = type; - std::transform(typeLower.begin(), typeLower.end(), typeLower.begin(), ::tolower); - if (typeLower.compare("system") == 0) - return WA_TYPE_SYSTEM; - if (typeLower.compare("image") == 0) - return WA_TYPE_IMAGE; - if (typeLower.compare("audio") == 0) - return WA_TYPE_AUDIO; - if (typeLower.compare("video") == 0) - return WA_TYPE_VIDEO; - if (typeLower.compare("vcard") == 0) - return WA_TYPE_CONTACT; - if (typeLower.compare("location") == 0) - return WA_TYPE_LOCATION; - - return WA_TYPE_UNDEFINED; -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/FMessage.h b/protocols/WhatsApp/src/WhatsAPI++/FMessage.h deleted file mode 100644 index 0d55aa6804..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/FMessage.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * FMessage.h - * - * Created on: 02/07/2012 - * Author: Antonio - */ - - - -#ifndef FMESSAGE_H_ -#define FMESSAGE_H_ - -#include -//#include -#include -#include "IMutex.h" - -struct Key -{ - std::string remote_jid; - bool from_me; - std::string id; - - Key(const std::string &remote_jid, bool from_me, const std::string &id); - std::string toString(); - -}; - -struct FMessage -{ - Key key; - unsigned char media_wa_type; - std::string data; - long long timestamp; - std::string remote_resource; - bool wants_receipt; - unsigned char status; - std::string notifyname; - bool offline; - std::string media_url; - std::string media_name; - - long long media_size; - int media_duration_seconds; - double latitude; - double longitude; - - enum { - WA_TYPE_UNDEFINED = 0, - WA_TYPE_IMAGE = 1, - WA_TYPE_AUDIO = 2, - WA_TYPE_VIDEO = 3, - WA_TYPE_CONTACT = 4, - WA_TYPE_LOCATION = 5, - WA_TYPE_SYSTEM = 7 - }; - - enum { - STATUS_UNSENT = 0, - STATUS_UPLOADING = 1, - STATUS_UPLOADED = 2, - STATUS_SENT_BY_CLIENT = 3, - STATUS_RECEIVED_BY_SERVER = 4, - STATUS_RECEIVED_BY_TARGET = 5, - STATUS_NEVER_SEND = 6, - STATUS_SERVER_BOUNCE = 7, - - STATUS_USER_ADDED = 191, - STATUS_USER_REMOVED = 192, - STATUS_SUBJECT_CHANGED = 193, - STATUS_PICTURE_CHANGED_SET = 194, - STATUS_PICTURE_CHANGED_DELETE = 195 - }; - - static std::string getMessage_WA_Type_StrValue(unsigned char type); - static unsigned char getMessage_WA_Type(const std::string &typeString); - - FMessage(); - FMessage(const std::string &remote_jid, bool from_me, const std::string &id); - virtual ~FMessage(); -}; - -#endif /* FMESSAGE_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/IMutex.h b/protocols/WhatsApp/src/WhatsAPI++/IMutex.h deleted file mode 100644 index 56a5492ac9..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/IMutex.h +++ /dev/null @@ -1,14 +0,0 @@ -#if !defined(IMUTEX_H) -#define IMUTEX_H - -class IMutex -{ -public: - IMutex() {} - virtual ~IMutex() {} - - virtual void lock() = 0; - virtual void unlock() = 0; -}; - -#endif \ No newline at end of file diff --git a/protocols/WhatsApp/src/WhatsAPI++/ISocketConnection.h b/protocols/WhatsApp/src/WhatsAPI++/ISocketConnection.h deleted file mode 100644 index b017df8cdc..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/ISocketConnection.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef ISOCKETCONNECTION_H_ -#define ISOCKETCONNECTION_H_ - -#include - -class ISocketConnection { - -public: - ISocketConnection() {} - virtual ~ISocketConnection() {} - - virtual void write(int i) = 0; - virtual unsigned char read() = 0; - virtual void flush() = 0; - virtual void write(const std::vector& b, int length) = 0; - virtual int read(unsigned char*, int length) = 0; - virtual int read(std::vector& b, int off, int length) = 0; - virtual void makeNonBlock() = 0; - virtual void forceShutdown() = 0; - - virtual void log(const char *prefix, const char *str) = 0; -}; - -#endif /* ISOCKETCONNECTION_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/KeyStream.cpp b/protocols/WhatsApp/src/WhatsAPI++/KeyStream.cpp deleted file mode 100644 index 563e5ac7f1..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/KeyStream.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * WALogin.cpp - * - * Created on: 26/06/2012 - * Author: Antonio - */ - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "WALogin.h" -#include "ByteArray.h" -#include "ProtocolTreeNode.h" -#include "WAException.h" - -using namespace Utilities; - -KeyStream::KeyStream() : - seq(0) -{ - HMAC_CTX_init(&hmac); -} - -KeyStream::~KeyStream() -{ - HMAC_CTX_cleanup(&hmac); -} - -void KeyStream::init(unsigned char* _key, unsigned char* _keyMac) -{ - memcpy(key, _key, 20); - memcpy(keyMac, _keyMac, 20); - - RC4_set_key(&this->rc4, 20, this->key); - - unsigned char drop[768]; - RC4(&this->rc4, sizeof(drop), drop, drop); -} - -void KeyStream::keyFromPasswordAndNonce(const std::string &pass, const std::vector& nonce, unsigned char *out) -{ - size_t cbSize = nonce.size(); - - uint8_t *pNonce = (uint8_t*)_alloca(cbSize + 1); - memcpy(pNonce, nonce.data(), cbSize); - - for (int i = 0; i < 4; i++) { - pNonce[cbSize] = i + 1; - PKCS5_PBKDF2_HMAC_SHA1(pass.data(), (int)pass.size(), pNonce, (int)cbSize+1, 2, 20, out + i*20); - } -} - -void KeyStream::decodeMessage(unsigned char* buffer, int macOffset, int offset, const int length) -{ - unsigned char digest[20]; - this->hmacsha1(buffer + offset, length, digest); - - if (memcmp(&buffer[macOffset], digest, 4)) - throw WAException("invalid MAC", WAException::CORRUPT_STREAM_EX, 0); - - unsigned char* out = (unsigned char*)_alloca(length); - RC4(&this->rc4, length, buffer + offset, out); - memcpy(buffer + offset, out, length); -} - -void KeyStream::encodeMessage(unsigned char* buffer, int macOffset, int offset, const int length) -{ - unsigned char* out = (unsigned char*)_alloca(length); - RC4(&this->rc4, length, buffer + offset, out); - memcpy(buffer + offset, out, length); - - unsigned char digest[20]; - this->hmacsha1(buffer + offset, length, digest); - memcpy(buffer + macOffset, digest, 4); -} - -void KeyStream::hmacsha1(unsigned char* text, int textLength, unsigned char *out) -{ - HMAC_Init(&hmac, this->keyMac, 20, EVP_sha1()); - HMAC_Update(&hmac, text, textLength); - - unsigned char hmacInt[4]; - hmacInt[0] = (this->seq >> 24); - hmacInt[1] = (this->seq >> 16); - hmacInt[2] = (this->seq >> 8); - hmacInt[3] = (this->seq); - HMAC_Update(&hmac, hmacInt, sizeof(hmacInt)); - - unsigned int mdLength; - HMAC_Final(&hmac, out, &mdLength); - - this->seq++; -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/LICENSE b/protocols/WhatsApp/src/WhatsAPI++/LICENSE deleted file mode 100644 index cccee9ef01..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/LICENSE +++ /dev/null @@ -1,340 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/protocols/WhatsApp/src/WhatsAPI++/MediaUploader.cpp b/protocols/WhatsApp/src/WhatsAPI++/MediaUploader.cpp deleted file mode 100644 index 34a99a9de4..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/MediaUploader.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include "../stdafx.h" -#include "MediaUploader.h" - -// TODO get rid of unneeded headers added by NETLIBHTTPREQUEST. it sould look like this: -//POST https://mmiXYZ.whatsapp.net/u/gOzeKj6U64LABC -//Content-Type: multipart/form-data; boundary=zzXXzzYYzzXXzzQQ -//Host: mmiXYZ.whatsapp.net -//User-Agent: WhatsApp/2.12.96 S40Version/14.26 Device/Nokia302 -//Content-Length: 9999999999 -// -//So remove these somehow: -//Accept-Encoding: deflate, gzip -//Connection: Keep-Alive -//Proxy-Connection: Keep-Alive - -static NETLIBHTTPHEADER s_imageHeaders[] = -{ - { "User-Agent", ACCOUNT_USER_AGENT }, - { "Content-Type", "multipart/form-data; boundary=zzXXzzYYzzXXzzQQ" } -}; - -static std::vector* sttFileToMem(const wchar_t *ptszFileName) -{ - HANDLE hFile = CreateFile(ptszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (hFile == INVALID_HANDLE_VALUE) - return NULL; - - DWORD upperSize, lowerSize = GetFileSize(hFile, &upperSize); - std::vector *result = new std::vector(lowerSize); - ReadFile(hFile, (void*)result->data(), lowerSize, &upperSize, NULL); - CloseHandle(hFile); - return result; -} - -namespace MediaUploader -{ - std::string sendData(std::string host, std::string head, std::string filePath, std::string tail) - { - // TODO string crap: can this be done more nicely? - std::wstring stemp = std::wstring(filePath.begin(), filePath.end()); - LPCWSTR sw = stemp.c_str(); - - vector *dataVector = sttFileToMem(sw); - - vector allVector(head.begin(), head.end()); - allVector.insert(allVector.end(), dataVector->begin(), dataVector->end()); - allVector.insert(allVector.end(), tail.begin(), tail.end()); - - NETLIBHTTPREQUEST nlhr = { sizeof(NETLIBHTTPREQUEST) }; - nlhr.requestType = REQUEST_POST; - nlhr.szUrl = (char*)host.c_str(); - nlhr.headers = s_imageHeaders; - nlhr.headersCount = _countof(s_imageHeaders); - nlhr.flags = NLHRF_HTTP11 | NLHRF_SSL; - nlhr.pData = (char*)allVector.data(); - nlhr.dataLength = (int)allVector.size(); - - NETLIBHTTPREQUEST *pnlhr = Netlib_HttpTransaction(g_hNetlibUser, &nlhr); - - string data = pnlhr->pData; - - if (!data.empty()) - return data; - else return 0; - } - - std::string pushfile(std::string url, FMessage * message, std::string from) - { - return getPostString(url, message, from); - } - - std::string getPostString(std::string url, FMessage * message, std::string from) - { - string filePath = message->media_url; - string to = message->key.remote_jid; - string extension = split(filePath, '.')[1]; - - uint8_t digest[16]; - md5_string(filePath, digest); - char dest[33]; - bin2hex(digest, sizeof(digest), dest); - - string cryptoname = dest; - cryptoname += "." + extension; - string boundary = "zzXXzzYYzzXXzzQQ"; - - string hBAOS = "--" + boundary + "\r\n"; - hBAOS += "Content-Disposition: form-data; name=\"to\"\r\n\r\n"; - hBAOS += to + "\r\n"; - hBAOS += "--" + boundary + "\r\n"; - hBAOS += "Content-Disposition: form-data; name=\"from\"\r\n\r\n"; - hBAOS += from + "\r\n"; - hBAOS += "--" + boundary + "\r\n"; - hBAOS += "Content-Disposition: form-data; name=\"file\"; filename=\"" + cryptoname + "\"\r\n"; - hBAOS += "Content-Type: " + getMimeFromExtension(extension) + "\r\n\r\n"; - - string fBAOS = "\r\n--" + boundary + "--\r\n"; - return sendData(url, hBAOS, filePath, fBAOS); - } - - static map extensions; - - std::string getMimeFromExtension(const string &extension) - { - if (extensions.empty()) { - extensions["audio/3gpp"] = "3gp"; - extensions["audio/x-caf"] = "caf"; - extensions["audio/wav"] = "wav"; - extensions["audio/mpeg"] = "mp3"; - extensions["audio/mpeg3"] = "mp3"; - extensions["audio/x-mpeg-32"] = "mp3"; - extensions["audio/x-ms-wma"] = "wma"; - extensions["audio/ogg"] = "ogg"; - extensions["audio/aiff"] = "aif"; - extensions["audio/x-aiff"] = "aif"; - extensions["audio/mp4"] = "m4a"; - extensions["image/jpeg"] = "jpg"; - extensions["image/gif"] = "gif"; - extensions["image/png"] = "png"; - extensions["video/3gpp"] = "3gp"; - extensions["video/mp4"] = "mp4"; - extensions["video/quicktime"] = "mov"; - extensions["video/avi"] = "avi"; - extensions["video/msvideo"] = "avi"; - extensions["video/x-msvideo"] = "avi"; - } - - for (auto it = extensions.begin(); it != extensions.end(); ++it) - if ((*it).second == extension) - return (*it).first; - - return ""; - } -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/MediaUploader.h b/protocols/WhatsApp/src/WhatsAPI++/MediaUploader.h deleted file mode 100644 index 7fb6612095..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/MediaUploader.h +++ /dev/null @@ -1,18 +0,0 @@ -/* -* -*/ -#ifndef MEDIAUPLOADER_H_ -#define MEDIAUPLOADER_H_ - -using namespace std; - -namespace MediaUploader -{ - std::string pushfile(std::string url, FMessage * message, std::string from); - std::string getPostString(std::string url, FMessage * message, std::string from); - std::string sendData(std::string host, std::string head, std::string filePath, std::string tail); - std::string getExtensionFromMime(string mime); - std::string getMimeFromExtension(const string &extension); -}; - -#endif /* MEDIAUPLOADER_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.cpp b/protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.cpp deleted file mode 100644 index dc5466321d..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.cpp +++ /dev/null @@ -1,298 +0,0 @@ -/* - * PhoneNumber.cpp - * - */ - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "PhoneNumber.h" - -struct CountryDescr -{ - char *name; - int countryCode, mcc, mnc; - char *ISO3166, *ISO639; -} -static countries[] = -{ - { "Russia", 7, 250, 20, "RU", "ru" }, - { "Kazakhstan", 7, 401, 77, "KZ", "kk" }, - { "Afghanistan", 93, 412, 1, "AF", "ps" }, - { "Albania", 355, 276, 1, "AL", "sq" }, - { "Alberta", 1403, 302, 720, "CA", "en" }, - { "Alberta", 1780, 302, 720, "CA", "en" }, - { "Algeria", 213, 603, 1, "DZ", "ar" }, - { "Andorra", 376, 213, 3, "AD", "ca" }, - { "Angola", 244, 631, 2, "AO", "pt" }, - { "Anguilla", 1264, 365, 10, "AI", "en" }, - { "Antarctica (Australian bases)", 6721, 232, 1, "AQ", "en" }, - { "Antigua and Barbuda", 1268, 344, 50, "AG", "en" }, - { "Argentina", 54, 722, 10, "AR", "es" }, - { "Armenia", 374, 283, 10, "AM", "hy" }, - { "Aruba", 297, 363, 1, "AW", "nl" }, - { "Ascension", 247, 658, 1, "AC", "en" }, - { "Australia", 61, 505, 1, "AU", "en" }, - { "Austria", 43, 232, 3, "AT", "de" }, - { "Azerbaijan", 994, 400, 1, "AZ", "az" }, - { "Bahamas", 1242, 364, 39, "BS", "en" }, - { "Bahrain", 973, 426, 1, "BH", "ar" }, - { "Bangladesh", 880, 470, 1, "BD", "bn" }, - { "Barbados", 1246, 342, 750, "BB", "en" }, - { "Belarus", 375, 257, 1, "BY", "be" }, - { "Belgium", 32, 206, 1, "BE", "nl" }, - { "Belize", 501, 702, 67, "BZ", "es" }, - { "Benin", 229, 616, 1, "BJ", "fr" }, - { "Bermuda", 1441, 350, 1, "BM", "en" }, - { "Bhutan", 975, 402, 11, "BT", "dz" }, - { "Bolivia", 591, 736, 1, "BO", "es" }, - { "Bosnia and Herzegovina", 387, 218, 3, "BA", "bs" }, - { "Botswana", 267, 652, 4, "BW", "en" }, - { "Brazil", 55, 724, 2, "BR", "pt" }, - { "British Columbia", 1250, 302, 720, "CA", "en" }, - { "British Columbia", 1604, 302, 720, "CA", "en" }, - { "British Columbia", 1778, 302, 720, "CA", "en" }, - { "British Indian Ocean Territory", 246, 348, 1, "IO", "en" }, - { "British Virgin Islands", 1284, 348, 170, "GB", "en" }, - { "Brunei", 673, 528, 11, "BN", "ms" }, - { "Bulgaria", 359, 284, 3, "BG", "bg" }, - { "Burkina Faso", 226, 613, 1, "BF", "fr" }, - { "Burundi", 257, 642, 82, "BI", "rn" }, - { "Cambodia", 855, 456, 2, "KH", "km" }, - { "Cameroon", 237, 624, 1, "CM", "fr" }, - { "Cape Verde", 238, 625, 1, "CV", "pt" }, - { "Cayman Islands", 1345, 346, 50, "GB", "en" }, - { "Central African Republic", 236, 623, 3, "CF", "sg" }, - { "Chad", 235, 622, 4, "TD", "fr" }, - { "Chile", 56, 730, 2, "CL", "es" }, - { "China", 86, 460, 3, "CN", "en" }, - { "Colombia", 57, 732, 102, "CO", "es" }, - { "Comoros", 269, 654, 1, "KM", "fr" }, - { "Democratic Republic of the Congo", 243, 630, 1, "CD", "fr" }, - { "Republic of the Congo", 242, 629, 1, "CG", "fr" }, - { "Cook Islands", 682, 548, 1, "CK", "en" }, - { "Costa Rica", 506, 658, 4, "CR", "es" }, - { "Cote d'Ivoire", 712, 612, 1, "CI", "fr" }, - { "Croatia", 385, 219, 1, "HR", "hr" }, - { "Cuba", 53, 368, 1, "CU", "es" }, - { "Cyprus", 357, 280, 1, "CY", "el" }, - { "Czech Republic", 420, 230, 2, "CZ", "cs" }, - { "Denmark", 45, 238, 1, "DK", "da" }, - { "Djibouti", 253, 638, 1, "DJ", "fr" }, - { "Dominica", 1767, 366, 20, "DM", "en" }, - { "Dominican Republic", 1809, 370, 1, "DO", "es" }, - { "Dominican Republic", 1829, 370, 1, "DO", "en" }, - { "East Timor", 670, 514, 1, "TL", "pt" }, - { "Ecuador", 593, 740, 0, "EC", "es" }, - { "Egypt", 20, 602, 2, "EG", "ar" }, - { "El Salvador", 503, 706, 1, "SV", "es" }, - { "Equatorial Guinea", 240, 627, 3, "GQ", "es" }, - { "Eritrea", 291, 657, 1, "ER", "ti" }, - { "Estonia", 372, 248, 3, "EE", "et" }, - { "Ethiopia", 251, 636, 11, "ET", "am" }, - { "Falkland Islands", 500, 750, 1, "FK", "en" }, - { "Faroe Islands", 298, 288, 2, "FO", "fo" }, - { "Fiji", 679, 542, 1, "FJ", "en" }, - { "Finland", 358, 244, 5, "FI", "fi" }, - { "France", 33, 208, 9, "FR", "fr" }, - { "French Guiana", 594, 742, 1, "GF", "fr" }, - { "French Polynesia", 689, 547, 15, "PF", "fr" }, - { "Gabon", 241, 628, 1, "GA", "fr" }, - { "Gambia", 220, 607, 1, "GM", "en" }, - { "Gaza Strip", 970, 0, 0, "PS", "ar" }, - { "Georgia", 995, 282, 1, "GE", "ka" }, - { "Germany", 49, 262, 1, "DE", "de" }, - { "Ghana", 233, 620, 2, "GH", "ak" }, - { "Gibraltar", 350, 266, 9, "GI", "en" }, - { "Greece", 30, 202, 5, "GR", "el" }, - { "Greenland", 299, 290, 1, "GL", "kl" }, - { "Grenada", 1473, 352, 30, "GD", "en" }, - { "Guadeloupe", 590, 340, 1, "GP", "fr" }, - { "Guam", 1671, 535, 32, "GU", "en" }, - { "Guatemala", 502, 704, 1, "GT", "es" }, - { "Guinea", 224, 611, 1, "GN", "fr" }, - { "Guinea-Bissau", 245, 632, 3, "GW", "pt" }, - { "Guyana", 592, 738, 1, "GY", "pt" }, - { "Haiti", 509, 372, 2, "HT", "fr" }, - { "Honduras", 504, 708, 2, "HN", "es" }, - { "Hong Kong", 852, 454, 0, "HK", "zh" }, - { "Hungary", 36, 216, 70, "HU", "hu" }, - { "Iceland", 354, 274, 2, "IS", "is" }, - { "India", 91, 404, 30, "IN", "hi" }, - { "Indonesia", 62, 510, 10, "ID", "id" }, - { "Iraq", 964, 418, 20, "IQ", "ar" }, - { "Iran", 98, 432, 35, "IR", "fa" }, - { "Ireland (Eire)", 353, 272, 1, "IE", "en" }, - { "Israel", 972, 425, 1, "IL", "he" }, - { "Italy", 39, 222, 10, "IT", "it" }, - { "Jamaica", 1876, 338, 50, "JM", "en" }, - { "Japan", 81, 440, 1, "JP", "ja" }, - { "Jordan", 962, 416, 77, "JO", "ar" }, - { "Kenya", 254, 639, 7, "KE", "sw" }, - { "Kiribati", 686, 545, 1, "KI", "en" }, - { "Kuwait", 965, 419, 4, "KW", "ar" }, - { "Kyrgyzstan", 996, 437, 1, "KG", "ky" }, - { "Laos", 856, 457, 1, "LA", "lo" }, - { "Latvia", 371, 247, 2, "LV", "lv" }, - { "Lebanon", 961, 415, 1, "LB", "ar" }, - { "Lesotho", 266, 651, 1, "LS", "st" }, - { "Liberia", 231, 618, 7, "LR", "en" }, - { "Libya", 218, 606, 0, "LY", "ar" }, - { "Liechtenstein", 423, 295, 2, "LI", "de" }, - { "Lithuania", 370, 246, 3, "LT", "lt" }, - { "Luxembourg", 352, 270, 99, "LU", "fr" }, - { "Macau", 853, 455, 2, "MO", "pt" }, - { "Republic of Macedonia", 389, 294, 1, "MK", "mk" }, - { "Madagascar", 261, 646, 2, "MG", "mg" }, - { "Malawi", 265, 650, 1, "MW", "ny" }, - { "Malaysia", 60, 502, 16, "MY", "en" }, - { "Maldives", 960, 472, 1, "MV", "dv" }, - { "Mali", 223, 610, 2, "ML", "fr" }, - { "Malta", 356, 278, 1, "MT", "mt" }, - { "Manitoba", 1204, 302, 720, "CA", "en" }, - { "Marshall Islands", 692, 551, 1, "MH", "mh" }, - { "Martinique", 596, 340, 1, "MQ", "fr" }, - { "Mauritania", 222, 609, 2, "MR", "ar" }, - { "Mauritius", 230, 617, 1, "MU", "en" }, - { "Mayotte", 262, 654, 1, "YT", "fr" }, - { "Mexico", 52, 334, 3, "MX", "es" }, - { "Federated States of Micronesia", 691, 550, 1, "FM", "en" }, - { "Moldova", 373, 259, 1, "MD", "ru" }, - { "Monaco", 377, 212, 1, "MC", "fr" }, - { "Mongolia", 976, 428, 91, "MN", "mn" }, - { "Montenegro", 382, 297, 2, "ME", "sr" }, - { "Montserrat", 1664, 354, 860, "MS", "en" }, - { "Morocco", 212, 604, 0, "MA", "ar" }, - { "Mozambique", 258, 643, 4, "MZ", "pt" }, - { "Myanmar", 95, 414, 1, "MM", "my" }, - { "Namibia", 264, 649, 3, "NA", "en" }, - { "Nauru", 674, 536, 2, "NR", "na" }, - { "Netherlands", 31, 204, 4, "NL", "nl" }, - { "Netherlands Antilles", 599, 362, 51, "AN", "nl" }, - { "Nepal", 977, 429, 1, "NP", "ne" }, - { "New Brunswick", 1506, 302, 720, "CA", "en" }, - { "New Caledonia", 687, 546, 1, "NC", "fr" }, - { "New Zealand", 64, 530, 1, "NZ", "en" }, - { "Newfoundland", 1709, 302, 720, "CA", "en" }, - { "Nicaragua", 505, 710, 30, "NI", "es" }, - { "Niger", 227, 614, 4, "NE", "fr" }, - { "Nigeria", 234, 621, 20, "NG", "ha" }, - { "Niue", 683, 555, 1, "NU", "en" }, - { "Norfolk Island", 6723, 505, 10, "NF", "en" }, - { "North Korea", 850, 467, 193, "KP", "ko" }, - { "Northern Mariana Islands", 1670, 534, 1, "MP", "en" }, - { "Northwest Territories", 1867, 302, 720, "CA", "en" }, - { "Norway", 47, 242, 4, "NO", "nb" }, - { "Nova Scotia", 1902, 302, 720, "CA", "en" }, - { "Oman", 968, 422, 2, "OM", "ar" }, - { "Ontario", 1416, 302, 720, "CA", "en" }, - { "Ontario", 1519, 302, 720, "CA", "en" }, - { "Ontario", 1613, 302, 720, "CA", "en" }, - { "Ontario", 1647, 302, 720, "CA", "en" }, - { "Ontario", 1705, 302, 720, "CA", "en" }, - { "Ontario", 1807, 302, 720, "CA", "en" }, - { "Ontario", 1905, 302, 720, "CA", "en" }, - { "Pakistan", 92, 410, 1, "PK", "en" }, - { "Palau", 680, 552, 80, "PW", "en" }, - { "Palestine", 970, 425, 6, "PS", "ar" }, - { "Panama", 507, 714, 2, "PA", "es" }, - { "Papua New Guinea", 675, 537, 3, "PG", "ho" }, - { "Paraguay", 595, 744, 6, "PY", "es" }, - { "Peru", 51, 716, 6, "PE", "es" }, - { "Philippines", 63, 515, 2, "PH", "fil" }, - { "Poland", 48, 260, 3, "PL", "pl" }, - { "Portugal", 351, 268, 1, "PT", "pt" }, - { "Qatar", 974, 427, 2, "QA", "ar" }, - { "Quebec", 1418, 302, 720, "CA", "en" }, - { "Quebec", 1450, 302, 720, "CA", "en" }, - { "Quebec", 1514, 302, 720, "CA", "en" }, - { "Quebec", 1819, 302, 720, "CA", "en" }, - { "Reunion", 262, 647, 0, "RE", "fr" }, - { "Romania", 40, 226, 1, "RO", "ro" }, - { "Rwanda", 250, 635, 10, "RW", "rw" }, - { "Saint-Barthelemy", 590, 340, 1, "BL", "fr" }, - { "Saint Helena", 290, 658, 1, "SH", "en" }, - { "Saint Kitts and Nevis", 1869, 356, 50, "KN", "en" }, - { "Saint Lucia", 1758, 358, 50, "LC", "en" }, - { "Saint Martin (French side)", 590, 340, 1, "MF", "fr" }, - { "Saint Pierre and Miquelon", 508, 308, 2, "PM", "fr" }, - { "Saint Vincent and the Grenadines", 1670, 360, 70, "VC", "en" }, - { "Samoa", 685, 549, 1, "WS", "sm" }, - { "Sao Tome and Principe", 239, 626, 1, "ST", "pt" }, - { "Saskatchewan", 1306, 302, 720, "CA", "en" }, - { "Saudi Arabia", 966, 420, 4, "SA", "ar" }, - { "Senegal", 221, 608, 1, "SN", "wo" }, - { "Serbia", 381, 220, 1, "RS", "sr" }, - { "Seychelles", 248, 633, 10, "SC", "fr" }, - { "Sierra Leone", 232, 619, 4, "SL", "en" }, - { "Singapore", 65, 525, 1, "SG", "en" }, - { "Slovakia", 421, 231, 4, "SK", "sk" }, - { "Slovenia", 386, 293, 31, "SI", "sl" }, - { "Solomon Islands", 677, 540, 2, "SB", "en" }, - { "Somalia", 252, 637, 82, "SO", "so" }, - { "South Africa", 27, 655, 1, "ZA", "xh" }, - { "South Korea", 82, 450, 5, "KR", "ko" }, - { "South Sudan", 211, 659, 2, "SS", "en" }, - { "Spain", 34, 214, 1, "ES", "es" }, - { "Sri Lanka", 94, 413, 1, "LK", "si" }, - { "Sudan", 249, 634, 7, "SD", "ar" }, - { "Suriname", 597, 746, 3, "SR", "nl" }, - { "Swaziland", 268, 653, 10, "SZ", "ss" }, - { "Sweden", 46, 240, 7, "SE", "sv" }, - { "Switzerland", 41, 228, 3, "CH", "de" }, - { "Syria", 963, 417, 1, "SY", "ar" }, - { "Taiwan", 886, 466, 1, "TW", "cmn" }, - { "Tajikistan", 992, 436, 1, "TJ", "tg" }, - { "Tanzania", 255, 640, 4, "TZ", "sw" }, - { "Thailand", 66, 520, 0, "TH", "th" }, - { "Togo", 228, 615, 1, "TG", "fr" }, - { "Tokelau", 690, 690, 1, "TK", "tkl" }, - { "Tonga", 676, 539, 1, "TO", "to" }, - { "Trinidad and Tobago", 1868, 374, 12, "TT", "en" }, - { "Tunisia", 216, 605, 1, "TN", "ar" }, - { "Turkey", 90, 286, 2, "TR", "tr" }, - { "Turkmenistan", 993, 438, 1, "TM", "tk" }, - { "Turks and Caicos Islands", 1649, 376, 50, "TC", "en" }, - { "Tuvalu", 688, 553, 1, "TV", "tvl" }, - { "Uganda", 256, 641, 14, "UG", "sw" }, - { "Ukraine", 380, 255, 1, "UA", "uk" }, - { "United Arab Emirates", 971, 424, 2, "AE", "ar" }, - { "United Kingdom", 44, 234, 10, "GB", "en" }, - { "United States of America", 1, 310, 4, "US", "en" }, - { "Uruguay", 598, 748, 7, "UY", "es" }, - { "Uzbekistan", 998, 434, 7, "UZ", "uz" }, - { "Vanuatu", 678, 541, 5, "VU", "bi" }, - { "Venezuela", 58, 734, 4, "VE", "es" }, - { "Vietnam", 84, 452, 1, "VN", "vi" }, - { "U.S. Virgin Islands", 1340, 332, 4, "VI", "en" }, - { "Wallis and Futuna", 681, 543, 1, "WF", "fr" }, - { "West Bank", 970, 0, 1, "PS", "ar" }, - { "Yemen", 967, 421, 2, "YE", "ar" }, - { "Zambia", 260, 645, 2, "ZM", "en" }, - { "Zimbabwe", 263, 648, 2, "ZW", "en" } -}; - -PhoneNumber::PhoneNumber(const std::string &szNumber) -{ - int cc1 = atoi(szNumber.substr(0, 1).c_str()), cc2 = atoi(szNumber.substr(0, 2).c_str()), cc3 = atoi(szNumber.substr(0, 3).c_str()); - - for (int i = 0; i < _countof(countries); i++) { - CountryDescr &p = countries[i]; - if (p.countryCode != cc1 && p.countryCode != cc2 && p.countryCode != cc3) - continue; - - if (p.countryCode == 7) - if (i == 0 && (cc2 == '77' || cc2 == '76')) - continue; - - this->Country = p.name; - this->countryCode = p.countryCode; - this->Number = szNumber.substr(1 + (size_t)floor(log10(double(p.countryCode)))); - this->ISO3166 = p.ISO3166; - this->ISO639 = p.ISO639; - this->mcc = p.mcc; - this->mnc = p.mnc; - return; - } - - throw new WAException("Could not dissect phone number " + szNumber); -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.h b/protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.h deleted file mode 100644 index aa3dd16ef9..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/PhoneNumber.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * PhoneNumber.h - * - */ - -#ifndef PHONENUMBER_H_ -#define PHONENUMBER_H_ - -#include - -struct PhoneNumber -{ - PhoneNumber(const std::string &number); - - std::string Country; - std::string Number; - - const char *ISO3166, *ISO639; - int countryCode; - int mcc, mnc; -}; - -#endif /* PHONENUMBER_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp deleted file mode 100644 index 2e04563fda..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* - * ProtocolTreeNode.cpp - * - * Created on: 26/06/2012 - * Author: Antonio - */ - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "WAException.h" -#include "ProtocolTreeNode.h" - -static std::string nilstr; - -ProtocolTreeNode::ProtocolTreeNode(const string &_tag, vector* _data, vector *_children) : - tag(_tag) -{ - data = _data; - attributes = NULL; - children = _children; -} - -ProtocolTreeNode::ProtocolTreeNode(const string &_tag, ProtocolTreeNode *_child) : - tag(_tag) -{ - this->data = NULL; - this->attributes = NULL; - this->children = new std::vector(); - children->push_back(_child); -} - -ProtocolTreeNode::~ProtocolTreeNode() -{ - delete this->attributes; - - if (this->children != NULL) { - for (size_t i = 0; i < this->children->size(); i++) - if (this->children->at(i) != NULL) - delete this->children->at(i); - delete this->children; - } - - delete data; -} - - -string ProtocolTreeNode::toString() const -{ - string out; - out += "<" + this->tag; - if (this->attributes != NULL) { - map::iterator ii; - for (ii = attributes->begin(); ii != attributes->end(); ii++) - out += " " + ii->first + "=\"" + ii->second + "\""; - } - out += ">\n"; - out += getDataAsString(); - - if (this->children != NULL) { - vector::iterator ii; - for (ii = children->begin(); ii != children->end(); ii++) - out += (*ii)->toString(); - } - - out += "tag + ">\n"; - - return out; -} - -ProtocolTreeNode* ProtocolTreeNode::getChild(const string& id) -{ - if (this->children == NULL || this->children->size() == 0) - return NULL; - - for (std::size_t i = 0; i < this->children->size(); i++) - if (id.compare((*children)[i]->tag) == 0) - return (*children)[i]; - - return NULL; -} - -ProtocolTreeNode* ProtocolTreeNode::getChild(size_t id) -{ - if (this->children == NULL || this->children->size() == 0) - return NULL; - - if (children->size() > id) - return (*children)[id]; - - return NULL; -} - -const string& ProtocolTreeNode::getAttributeValue(const string& attribute) -{ - if (this->attributes == NULL) - return nilstr; - - map::iterator it = attributes->find(attribute); - if (it == attributes->end()) - return nilstr; - - return it->second; -} - -vector ProtocolTreeNode::getAllChildren() -{ - if (this->children == NULL) - return vector(); - - return *this->children; -} - -std::string ProtocolTreeNode::getDataAsString() const -{ - if (this->data == NULL) - return nilstr; - return std::string(this->data->begin(), this->data->end()); -} - -vector ProtocolTreeNode::getAllChildren(const string &tag) -{ - vector ret; - - 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) -{ - return (node != NULL && node->tag.compare(tag) == 0); -} - -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); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -ProtocolTreeNode& operator<<(ProtocolTreeNode &node, const XATTR &attr) -{ - if (node.attributes == NULL) - node.attributes = new map; - - (*node.attributes)[attr.name] = attr.value; - return node; -} - -ProtocolTreeNode* operator<<(ProtocolTreeNode *node, const XATTR &attr) -{ - if (node->attributes == NULL) - node->attributes = new map; - - (*node->attributes)[attr.name] = attr.value; - return node; -} - -ProtocolTreeNode& operator<<(ProtocolTreeNode &node, const XATTRI &attr) -{ - if (node.attributes == NULL) - node.attributes = new map; - - char szValue[100]; - _itoa_s(attr.value, szValue, 10); - (*node.attributes)[attr.name] = szValue; - return node; -} - -ProtocolTreeNode* operator<<(ProtocolTreeNode *node, const XATTRI &attr) -{ - if (node->attributes == NULL) - node->attributes = new map; - - char szValue[100]; - _itoa_s(attr.value, szValue, 10); - (*node->attributes)[attr.name] = szValue; - return node; -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h deleted file mode 100644 index 50e0f4033d..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -* ProtocolTreeNode.h -* -* Created on: 26/06/2012 -* Author: Antonio -*/ - -#if !defined(PROTOCOLNODE_H) -#define PROTOCOLNODE_H - -#include -#include -#include - -using namespace std; - -struct XATTR -{ - __forceinline XATTR(const char *_name, const char *_value) : - name(_name), value(_value) - {} - - __forceinline XATTR(const char *_name, const std::string &_value) : - name(_name), value(_value.c_str()) - {} - - __forceinline XATTR(const std::string &_name, const std::string &_value) : - name(_name.c_str()), value(_value.c_str()) - {} - - const char *name, *value; -}; - -struct XATTRI -{ - __forceinline XATTRI(const char *_name, int _value) : - name(_name), value(_value) - {} - - __forceinline XATTRI(const std::string &_name, int _value) : - name(_name.c_str()), value(_value) - {} - - const char *name; - int value; -}; - -class ProtocolTreeNode -{ - ProtocolTreeNode(const ProtocolTreeNode&); // to prevent copying - -public: - vector* data; - string tag; - map *attributes; - vector *children; - - ProtocolTreeNode(const string &tag, ProtocolTreeNode *child); - ProtocolTreeNode(const string &tag, vector *data = NULL, vector *children = NULL); - ~ProtocolTreeNode(); - - string toString() const; - ProtocolTreeNode* getChild(const string &id); - ProtocolTreeNode* getChild(size_t id); - const string& getAttributeValue(const string &attribute); - - vector getAllChildren(); - vector getAllChildren(const string &tag); - std::string getDataAsString() const; - - static bool tagEquals(ProtocolTreeNode *node, const string &tag); - static void require(ProtocolTreeNode *node, const string &tag); -}; - -ProtocolTreeNode& operator<<(ProtocolTreeNode&, const XATTR&); -ProtocolTreeNode* operator<<(ProtocolTreeNode*, const XATTR&); - -ProtocolTreeNode& operator<<(ProtocolTreeNode&, const XATTRI&); -ProtocolTreeNode* operator<<(ProtocolTreeNode*, const XATTRI&); - -#endif /* PROTOCOLNODE_H_ */ \ No newline at end of file diff --git a/protocols/WhatsApp/src/WhatsAPI++/README.md b/protocols/WhatsApp/src/WhatsAPI++/README.md deleted file mode 100644 index 69e374a6ef..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/README.md +++ /dev/null @@ -1,30 +0,0 @@ -This library can be used for creating WhatsApp-clients and is based on the MojoWhatsup-project written by Antonio Morales. The original source code has been modified by Uli Hecht. - -------------------------------------------------------------------------------------------------- -ORIGINAL "README.MD" BELOW -------------------------------------------------------------------------------------------------- - -MojoWhatsup -=========== - -MojoWhatsup is an IM application for Webos that allows you to chat with your Whatsapp friends - -MojoWhatsup has been developed as a Webos hybrid app, i.e. a javascript webos app (based in Mojo framework) -and a plugin (mojowhatsup_service_plugin) in C++. The plugin supports all Whatsapp communication API. - -Contact: Antonio Morales - -License: - - Copyright (c) 2012, Antonio Morales - - MojoWhatsup is free software: you can redistribute it and/or modify it under the terms - of the GNU General Public License as published by the Free Software Foundation, - either version 2 of the License, or (at your option) any later version. - - MojoWhatsup is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with MojoWhatsup. - If not, see http://www.gnu.org/licenses/. diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp deleted file mode 100644 index b760c58da4..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp +++ /dev/null @@ -1,1125 +0,0 @@ -/* - * WAConnection.cpp - * - * Created on: 26/06/2012 - * Author: Antonio - */ - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "ProtocolTreeNode.h" -#include "utilities.h" - -const char* dictionary[] = { - "", "", "", "account", "ack", "action", "active", "add", "after", "all", "allow", "apple", "auth", "author", "available", - "bad-protocol", "bad-request", "before", "body", "broadcast", "cancel", "category", "challenge", "chat", "clean", "code", - "composing", "config", "contacts", "count", "create", "creation", "debug", "default", "delete", "delivery", "delta", "deny", - "digest", "dirty", "duplicate", "elapsed", "enable", "encoding", "error", "event", "expiration", "expired", "fail", "failure", - "false", "favorites", "feature", "features", "feature-not-implemented", "field", "first", "free", "from", "g.us", "get", "google", - "group", "groups", "groups_v2", "http://etherx.jabber.org/streams", "http://jabber.org/protocol/chatstates", "ib", "id", "image", - "img", "index", "internal-server-error", "ip", "iq", "item-not-found", "item", "jabber:iq:last", "jabber:iq:privacy", "jabber:x:event", - "jid", "kind", "last", "leave", "list", "max", "mechanism", "media", "message_acks", "message", "method", "microsoft", "missing", - "modify", "mute", "name", "nokia", "none", "not-acceptable", "not-allowed", "not-authorized", "notification", "notify", "off", - "offline", "order", "owner", "owning", "p_o", "p_t", "paid", "participant", "participants", "participating", "paused", "picture", - "pin", "ping", "platform", "port", "presence", "preview", "probe", "prop", "props", "query", "raw", "read", "readreceipts", "reason", - "receipt", "relay", "remote-server-timeout", "remove", "request", "required", "resource-constraint", "resource", "response", "result", - "retry", "rim", "s_o", "s_t", "s.us", "s.whatsapp.net", "seconds", "server-error", "server", "service-unavailable", "set", "show", "silent", - "stat", "status", "stream:error", "stream:features", "subject", "subscribe", "success", "sync", "t", "text", "timeout", "timestamp", "to", - "true", "type", "unavailable", "unsubscribe", "uri", "url", "urn:ietf:params:xml:ns:xmpp-sasl", "urn:ietf:params:xml:ns:xmpp-stanzas", - "urn:ietf:params:xml:ns:xmpp-streams", "urn:xmpp:ping", "urn:xmpp:whatsapp:account", "urn:xmpp:whatsapp:dirty", "urn:xmpp:whatsapp:mms", - "urn:xmpp:whatsapp:push", "urn:xmpp:whatsapp", "user", "user-not-found", "value", "version", "w:g", "w:p:r", "w:p", "w:profile:picture", - "w", "wait", "WAUTH-2", "xmlns:stream", "xmlns", "1", "chatstate", "crypto", "phash", "enc", "class", "off_cnt", "w:g2", "promote", - "demote", "creator", "Bell.caf", "Boing.caf", "Glass.caf", "Harp.caf", "TimePassing.caf", "Tri-tone.caf", "Xylophone.caf", "background", - "backoff", "chunked", "context", "full", "in", "interactive", "out", "registration", "sid", "urn:xmpp:whatsapp:sync", "flt", "s16", "u8", - "adpcm", "amrnb", "amrwb", "mp3", "pcm", "qcelp", "wma", "h263", "h264", "jpeg" -}; - -const char* extended_dict[] = { - "mpeg4", "wmv", "audio/3gpp", "audio/aac", "audio/amr", "audio/mp4", "audio/mpeg", "audio/ogg", "audio/qcelp", "audio/wav", - "audio/webm", "audio/x-caf", "audio/x-ms-wma", "image/gif", "image/jpeg", "image/png", "video/3gpp", "video/avi", "video/mp4", - "video/mpeg", "video/quicktime", "video/x-flv", "video/x-ms-asf", "302", "400", "401", "402", "403", "404", "405", "406", "407", - "409", "410", "500", "501", "503", "504", "abitrate", "acodec", "app_uptime", "asampfmt", "asampfreq", "audio", "clear", "conflict", - "conn_no_nna", "cost", "currency", "duration", "extend", "file", "fps", "g_notify", "g_sound", "gcm", "gone", "google_play", "hash", - "height", "invalid", "jid-malformed", "latitude", "lc", "lg", "live", "location", "log", "longitude", "max_groups", "max_participants", - "max_subject", "mimetype", "mode", "napi_version", "normalize", "orighash", "origin", "passive", "password", "played", - "policy-violation", "pop_mean_time", "pop_plus_minus", "price", "pricing", "redeem", "Replaced by new connection", "resume", - "signature", "size", "sound", "source", "system-shutdown", "username", "vbitrate", "vcard", "vcodec", "video", "width", - "xml-not-well-formed", "checkmarks", "image_max_edge", "image_max_kbytes", "image_quality", "ka", "ka_grow", "ka_shrink", "newmedia", - "library", "caption", "forward", "c0", "c1", "c2", "c3", "clock_skew", "cts", "k0", "k1", "login_rtt", "m_id", "nna_msg_rtt", - "nna_no_off_count", "nna_offline_ratio", "nna_push_rtt", "no_nna_con_count", "off_msg_rtt", "on_msg_rtt", "stat_name", "sts", - "suspect_conn", "lists", "self", "qr", "web", "w:b", "recipient", "w:stats", "forbidden", "aurora.m4r", "bamboo.m4r", "chord.m4r", - "circles.m4r", "complete.m4r", "hello.m4r", "input.m4r", "keys.m4r", "note.m4r", "popcorn.m4r", "pulse.m4r", "synth.m4r", "filehash", - "max_list_recipients", "en-AU", "en-GB", "es-MX", "pt-PT", "zh-Hans", "zh-Hant", "relayelection", "relaylatency", "interruption", - "Apex.m4r", "Beacon.m4r", "Bulletin.m4r", "By The Seaside.m4r", "Chimes.m4r", "Circuit.m4r", "Constellation.m4r", "Cosmic.m4r", - "Crystals.m4r", "Hillside.m4r", "Illuminate.m4r", "Night Owl.m4r", "Opening.m4r", "Playtime.m4r", "Presto.m4r", "Radar.m4r", - "Radiate.m4r", "Ripples.m4r", "Sencha.m4r", "Signal.m4r", "Silk.m4r", "Slow Rise.m4r", "Stargaze.m4r", "Summit.m4r", "Twinkle.m4r", - "Uplift.m4r", "Waves.m4r", "voip", "eligible", "upgrade", "planned", "current", "future", "disable", "expire", "start", "stop", - "accuracy", "speed", "bearing", "recording", "encrypt", "key", "identity", "w:gp2", "admin", "locked", "unlocked", "new", "battery", - "archive", "adm", "plaintext_size", "compressed_size", "delivered", "msg", "pkmsg", "everyone", "v", "transport", "call-id" -}; - -static map tokenMap1, tokenMap2; - -void WAConnection::globalInit() -{ - for (int i = 0; i < _countof(dictionary); i++) - if (*dictionary[i] != 0) - tokenMap1[dictionary[i]] = i; - - for (int i = 0; i < _countof(extended_dict); i++) - tokenMap2[extended_dict[i]] = i; -} - -int WAConnection::tokenLookup(const std::string &str) -{ - std::map::iterator it = tokenMap1.find(str); - if (it != tokenMap1.end()) - return it->second; - - it = tokenMap2.find(str); - if (it != tokenMap2.end()) - return it->second + 0x100; - - return -1; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -void WAConnection::logData(const char *format, ...) -{ - va_list args; - va_start(args, format); - char tmp[4000]; - vsprintf_s(tmp, format, args); - rawConn->log(">> ", tmp); - va_end(args); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -WAConnection::WAConnection(const std::string &user, const std::string &resource, IMutex *mutex, IMutex *write_mutex, ISocketConnection *conn, WAListener *pEventHandler, WAGroupListener *pGroupEventHandler) : - in(this, conn), - out(this, conn, write_mutex) -{ - m_pMutex = mutex; - m_pEventHandler = pEventHandler; - m_pGroupEventHandler = pGroupEventHandler; - - rawConn = conn; - - this->retry = true; - - this->user = user; - this->resource = resource; - this->domain = "s.whatsapp.net"; - this->jid = user + "@" + domain; - - this->supports_receipt_acks = false; - this->iqid = 0; - this->lastTreeRead = 0; - this->expire_date = 0L; - this->account_kind = -1; -} - -WAConnection::~WAConnection() -{ - m_pMutex->lock(); - for (auto it = pending_server_requests.begin(); it != pending_server_requests.end(); ++it) - delete it->second; - m_pMutex->unlock(); -} - -std::string WAConnection::gidToGjid(const std::string &gid) -{ - return gid + "@g.us"; -} - -std::string WAConnection::makeId(const std::string &prefix) -{ - return prefix + Utilities::itoa(++this->iqid, 16); -} - -ProtocolTreeNode* WAConnection::getReceiptAck(const std::string &to, const std::string &id, const std::string &receiptType) throw(WAException) -{ - ProtocolTreeNode *ackNode = new ProtocolTreeNode("ack") - << XATTR("xmlns", "urn:xmpp:receipts") << XATTR("type", receiptType); - - return new ProtocolTreeNode("message", ackNode) << XATTR("to", to) << XATTR("type", "chat") << XATTR("id", id); -} - -bool WAConnection::supportsReceiptAcks() -{ - return supports_receipt_acks; -} - -std::string WAConnection::removeResourceFromJid(const std::string &jid) -{ - size_t slashidx = jid.find('/'); - if (slashidx == std::string::npos) - return jid; - - return jid.substr(0, slashidx + 1); -} - -void WAConnection::setLogin(WALogin* login) -{ - if (login->m_tExpireDate != 0L) - this->expire_date = login->m_tExpireDate; - - if (login->m_iAccountKind != -1) - this->account_kind = login->m_iAccountKind; -} - -bool WAConnection::read() throw(WAException) -{ - ProtocolTreeNode *node; - try { - node = in.nextTree(); - this->lastTreeRead = time(NULL); - } - catch (exception& ex) { - throw WAException(ex.what(), WAException::CORRUPT_STREAM_EX, 0); - } - - if (node == NULL) - return false; - - string tmp = node->toString(); - rawConn->log("XML received\n", tmp.c_str()); - - if (ProtocolTreeNode::tagEquals(node, "iq")) - parseIq(node); - else if (ProtocolTreeNode::tagEquals(node, "presence")) - parsePresense(node); - else if (ProtocolTreeNode::tagEquals(node, "message")) - parseMessage(node); - else if (ProtocolTreeNode::tagEquals(node, "notification")) - parseNotification(node); - else if (ProtocolTreeNode::tagEquals(node, "ack")) - parseAck(node); - else if (ProtocolTreeNode::tagEquals(node, "receipt")) - parseReceipt(node); - else if (ProtocolTreeNode::tagEquals(node, "chatstate")) - parseChatStates(node); - else { - rawConn->log("Warning: Node parsing not handled:\n", tmp.c_str()); - } - - delete node; - return true; -} - -void WAConnection::readGroupList(ProtocolTreeNode *node, std::vector& groups) throw (WAException) -{ - std::vector 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 (m_pGroupEventHandler != NULL) - m_pGroupEventHandler->onGroupInfo(gjid, owner, subject, subject_owner, atoi(subject_t.c_str()), atoi(creation.c_str())); - groups.push_back(gjid); - } -} - -std::map WAConnection::parseCategories(ProtocolTreeNode *dirtyNode) throw (WAException) -{ - std::map categories; - if (dirtyNode->children != NULL) { - for (size_t i = 0; i < dirtyNode->children->size(); i++) { - ProtocolTreeNode *childNode = (*dirtyNode->children)[i]; - if (ProtocolTreeNode::tagEquals(childNode, "category")) { - const string &categoryName = childNode->getAttributeValue("name"); - const string ×tamp = childNode->getAttributeValue("timestamp"); - categories[categoryName] = timestamp; - } - } - } - - return categories; -} - -void WAConnection::parseAck(ProtocolTreeNode *node) throw(WAException) -{ - const string &from = node->getAttributeValue("from"); - const string &cls = node->getAttributeValue("class"); - const string &id = node->getAttributeValue("id"); - // const string &ts = node->getAttributeValue("t"); - - if (cls == "message" && m_pEventHandler != NULL) { - FMessage msg(from, true, id); - msg.status = FMessage::STATUS_RECEIVED_BY_SERVER; - m_pEventHandler->onMessageStatusUpdate(msg); - } -} - -void WAConnection::parseChatStates(ProtocolTreeNode *node) throw (WAException) -{ - const string &from = node->getAttributeValue("from"); - - std::vector messageChildren(node->getAllChildren()); - for (size_t i = 0; i < messageChildren.size(); i++) { - ProtocolTreeNode *childNode = messageChildren[i]; - if (ProtocolTreeNode::tagEquals(childNode, "composing")) { - if (m_pEventHandler != NULL) - m_pEventHandler->onIsTyping(from, true); - } - else if (ProtocolTreeNode::tagEquals(childNode, "paused")) { - if (m_pEventHandler != NULL) - m_pEventHandler->onIsTyping(from, false); - } - } -} - -void WAConnection::parseIq(ProtocolTreeNode *node) throw(WAException) -{ - const string &type = node->getAttributeValue("type"); - if (type.empty()) - throw WAException("missing 'type' attribute in iq stanza", WAException::CORRUPT_STREAM_EX, 0); - - 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); - - m_pMutex->lock(); - std::map::iterator it = this->pending_server_requests.find(id); - if (it != this->pending_server_requests.end()) { - it->second->parse(node, from); - delete it->second; - this->pending_server_requests.erase(id); - m_pMutex->unlock(); - return; - } - - m_pMutex->unlock(); - if (id.compare(0, this->user.size(), this->user) == 0) { - ProtocolTreeNode *accountNode = node->getChild(0); - ProtocolTreeNode::require(accountNode, "account"); - const string &kind = accountNode->getAttributeValue("kind"); - if (kind == "paid") - this->account_kind = 1; - else if (kind == "free") - this->account_kind = 0; - else - this->account_kind = -1; - - const string &expiration = accountNode->getAttributeValue("expiration"); - if (expiration.empty()) - throw WAException("no expiration"); - - this->expire_date = atol(expiration.c_str()); - if (this->expire_date == 0) - throw WAException("invalid expire date: " + expiration); - if (m_pEventHandler != NULL) - m_pEventHandler->onAccountChange(this->account_kind, this->expire_date); - } - else { - ProtocolTreeNode *childNode = node->getChild(0); - if (ProtocolTreeNode::tagEquals(childNode, "leave")) { - std::vector nodes(childNode->getAllChildren("group")); - for (size_t i = 0; i < nodes.size(); i++) { - ProtocolTreeNode *groupNode = nodes[i]; - const string &gjid = groupNode->getAttributeValue("id"); - if (m_pGroupEventHandler != NULL) - m_pGroupEventHandler->onLeaveGroup(gjid); - } - } - } - } - else if (type == "error") { - m_pMutex->lock(); - std::map::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); - } - m_pMutex->unlock(); - } - else if (type == "get") { - ProtocolTreeNode *childNode = node->getChild(0); - if (ProtocolTreeNode::tagEquals(childNode, "ping")) { - if (m_pEventHandler != NULL) - m_pEventHandler->onPing(id); - } - else if ((ProtocolTreeNode::tagEquals(childNode, "query") && !from.empty()) ? false : (ProtocolTreeNode::tagEquals(childNode, "relay")) && !from.empty()) { - const string &pin = childNode->getAttributeValue("pin"); - if (!pin.empty() && m_pEventHandler != NULL) { - int timeoutSeconds = atoi(childNode->getAttributeValue("timeout").c_str()); - m_pEventHandler->onRelayRequest(pin, timeoutSeconds, id); - } - } - } - else if (type == "set") { - ProtocolTreeNode *childNode = node->getChild(0); - if (ProtocolTreeNode::tagEquals(childNode, "query")) { - const string &xmlns = childNode->getAttributeValue("xmlns"); - if (xmlns == "jabber:iq:roster") { - std::vector 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"); - } - } - } - } - else throw WAException("unknown iq type attribute: " + type, WAException::CORRUPT_STREAM_EX, 0); -} - -void WAConnection::parseMessage(ProtocolTreeNode *messageNode) throw (WAException) -{ - const string &id = messageNode->getAttributeValue("id"); - const string &attribute_t = messageNode->getAttributeValue("t"); - const string &from = messageNode->getAttributeValue("from"); - - const string &typeAttribute = messageNode->getAttributeValue("type"); - if (typeAttribute.empty()) - return; - - const string &participant = messageNode->getAttributeValue("participant"); - if (typeAttribute == "error") { - int errorCode = 0; - std::vector errorNodes(messageNode->getAllChildren("error")); - for (size_t i = 0; i < errorNodes.size(); i++) { - ProtocolTreeNode *errorNode = errorNodes[i]; - errorCode = atoi(errorNode->getAttributeValue("code").c_str()); - } - - FMessage message(from, true, id); - message.status = FMessage::STATUS_SERVER_BOUNCE; - - if (m_pEventHandler != NULL) - m_pEventHandler->onMessageError(message, errorCode); - return; - } - - if (from.empty() || id.empty()) - return; - FMessage fmessage(from, false, id); - - if (typeAttribute == "text") { - ProtocolTreeNode *body = messageNode->getChild("body"); - if (body == NULL || body->data == NULL || body->data->empty()) - return; - - fmessage.wants_receipt = false; - fmessage.timestamp = atoi(attribute_t.c_str()); - fmessage.remote_resource = participant; - fmessage.notifyname = messageNode->getAttributeValue("notify"); - fmessage.data = body->getDataAsString(); - fmessage.status = FMessage::STATUS_UNSENT; - if (fmessage.timestamp == 0) { - fmessage.timestamp = time(NULL); - fmessage.offline = false; - } - } - else if (typeAttribute == "media") { - ProtocolTreeNode *media = messageNode->getChild("media"); - if (media == NULL) - return; - - fmessage.wants_receipt = false; - fmessage.timestamp = atoi(attribute_t.c_str()); - fmessage.notifyname = messageNode->getAttributeValue("notify"); - fmessage.remote_resource = messageNode->getAttributeValue("participant"); - fmessage.media_wa_type = FMessage::getMessage_WA_Type(media->getAttributeValue("type")); - fmessage.media_url = media->getAttributeValue("url"); - fmessage.media_name = media->getAttributeValue("file"); - fmessage.media_size = Utilities::parseLongLong(media->getAttributeValue("size")); - fmessage.media_duration_seconds = atoi(media->getAttributeValue("seconds").c_str()); - - if (fmessage.media_wa_type == FMessage::WA_TYPE_LOCATION) { - const string &name = media->getAttributeValue("name"); - const string &latitudeString = media->getAttributeValue("latitude"); - const string &longitudeString = media->getAttributeValue("longitude"); - if (latitudeString.empty() || longitudeString.empty()) - throw WAException("location message missing lat or long attribute", WAException::CORRUPT_STREAM_EX, 0); - - fmessage.latitude = atof(latitudeString.c_str()); - fmessage.longitude = atof(longitudeString.c_str()); - if (!name.empty()) - fmessage.data = name; - } - else if (fmessage.media_wa_type == FMessage::WA_TYPE_CONTACT) { - ProtocolTreeNode *contactChildNode = media->getChild(0); - if (contactChildNode != NULL) { - fmessage.media_name = contactChildNode->getAttributeValue("name"); - fmessage.data = contactChildNode->getDataAsString(); - size_t off = fmessage.data.find("TEL;"); - if (off != string::npos) { - if ((off = fmessage.data.find(":", off)) != string::npos) { - std::string number; - for (off++;; off++) { - char c = fmessage.data[off]; - if (isdigit(c)) - number += c; - else if (c == '+' || c == ' ') - continue; - else - break; - } - if (!number.empty()) - fmessage.media_url = number; - } - } - } - } - else { - const string &encoding = media->getAttributeValue("encoding"); - if (encoding.empty() || encoding == "text") - fmessage.data = media->getDataAsString(); - else - fmessage.data = media->getAttributeValue("caption"); - } - } - else return; - - if (fmessage.remote_resource.empty()) { - if (m_pEventHandler != NULL) - m_pEventHandler->onMessageForMe(fmessage); - } - else if (m_pGroupEventHandler != NULL) - m_pGroupEventHandler->onGroupMessage(fmessage); -} - -void WAConnection::parseNotification(ProtocolTreeNode *node) throw(WAException) -{ - const string &id = node->getAttributeValue("id"); - const string &from = node->getAttributeValue("from"); - const string &type = node->getAttributeValue("type"); - if (type.empty() || from.empty() || m_pEventHandler == NULL) - return; - - const string &participant = node->getAttributeValue("participant"); - int ts = atoi(node->getAttributeValue("t").c_str()); - - if (type == "contacts") { - std::vector children(node->getAllChildren()); - for (size_t i = 0; i < children.size(); i++) { - ProtocolTreeNode *child = children[i]; - - const string &jid = node->getAttributeValue("jid"); - if (jid.empty()) continue; - - bool bAdded; - if (ProtocolTreeNode::tagEquals(child, "add")) - bAdded = true; - else if (ProtocolTreeNode::tagEquals(child, "delete")) - bAdded = false; - else - continue; - - m_pEventHandler->onContactChanged(jid, bAdded); - } - } - else if (type == "picture") { - std::vector children2(node->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 &jid = child2->getAttributeValue("jid"); - if (!id.empty()) - m_pEventHandler->onPictureChanged(jid, id, true); - } - else if (ProtocolTreeNode::tagEquals(child2, "delete")) { - const string &jid = child2->getAttributeValue("jid"); - m_pEventHandler->onPictureChanged(jid, id, false); - } - } - } - // group chats - else if (type == "participant") { - ProtocolTreeNode *subNode = node->getChild("add"); - if (subNode != NULL) { - const string &jid = subNode->getAttributeValue("jid"); - if (m_pGroupEventHandler) - m_pGroupEventHandler->onGroupAddUser(from, jid, ts); - } - else if ((subNode = node->getChild("remove")) != NULL) { - const string &jid = subNode->getAttributeValue("jid"); - if (m_pGroupEventHandler) - m_pGroupEventHandler->onGroupRemoveUser(from, jid, ts); - } - else return; - - } - else if (type == "subject") { - ProtocolTreeNode *bodyNode = node->getChild("body"); - if (bodyNode != NULL && m_pGroupEventHandler != NULL) - m_pGroupEventHandler->onGroupNewSubject(from, participant, bodyNode->getDataAsString(), ts); - } - else { - rawConn->log("Warning: Unknown Notification received:\n", node->toString().c_str()); - } - - sendAck(node, "notification"); -} - -void WAConnection::parsePresense(ProtocolTreeNode *node) throw(WAException) -{ - const string &xmlns = node->getAttributeValue("xmlns"); - const string &from = node->getAttributeValue("from"); - if (from.empty()) - return; - - int ts = atoi(node->getAttributeValue("t").c_str()); - 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 (m_pGroupEventHandler != NULL) - m_pGroupEventHandler->onGroupAddUser(from, add, ts); - } - else if (!remove.empty()) { - if (m_pGroupEventHandler != NULL) - m_pGroupEventHandler->onGroupRemoveUser(from, remove, ts); - } - else if (status == "dirty") { - std::map categories = parseCategories(node); - if (m_pEventHandler != NULL) - m_pEventHandler->onDirty(categories); - } - return; - } - - if (m_pEventHandler != NULL) { - const string &type = node->getAttributeValue("type"); - if (type == "unavailable") { - const string &lastSeen = node->getAttributeValue("last"); - m_pEventHandler->onAvailable(from, false, (lastSeen == "deny") ? 0 : stoul(lastSeen)); - } - else if (type == "available" || type == "") - m_pEventHandler->onAvailable(from, true); - } -} - -void WAConnection::parseReceipt(ProtocolTreeNode *node) throw(WAException) -{ - const string &from = node->getAttributeValue("from"); - const string &id = node->getAttributeValue("id"); - - if (m_pEventHandler != NULL) { - FMessage msg(from, false, id); - msg.status = FMessage::STATUS_RECEIVED_BY_TARGET; - m_pEventHandler->onMessageStatusUpdate(msg); - } - - sendAck(node,"receipt"); -} - -std::vector* WAConnection::processGroupSettings(const std::vector& groups) -{ - std::vector* result = new std::vector(groups.size()); - if (!groups.empty()) { - time_t now = time(NULL); - for (size_t i = 0; i < groups.size(); i++) { - (*result)[i] = new ProtocolTreeNode("item") - << XATTR("jid", groups[i].jid) << XATTR("notify", (groups[i].enabled ? "1" : "0")) - << XATTRI("mute", (groups[i].muteExpiry > now) ? groups[i].muteExpiry - now : 0); - } - } - - return result; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Send* functions - -void WAConnection::sendActive() throw(WAException) -{ - ProtocolTreeNode n("presence"); - out.write(n << XATTR("type", "active")); -} - -void WAConnection::sendAvailableForChat() throw(WAException) -{ - ProtocolTreeNode n("presence"); - out.write(n << XATTR("name", this->nick)); -} - -void WAConnection::sendClientConfig(const std::string &sound, const std::string &pushID, bool preview, const std::string &platform) throw(WAException) -{ - m_pMutex->lock(); - std::string id = makeId("config_"); - this->pending_server_requests[id] = new IqSendClientConfigHandler(this); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("config") - << XATTR("xmlns", "urn:xmpp:whatsapp:push") << XATTR("sound", sound) << XATTR("id", pushID) << XATTR("preview", preview ? "1" : "0") << XATTR("platform", platform)); - out.write(iq << XATTR("id", id) << XATTR("type", "set") << XATTR("to", this->domain)); -} - -void WAConnection::sendClientConfig(const std::string &pushID, bool preview, const std::string &platform, bool defaultSettings, bool groupSettings, const std::vector& groups) throw(WAException) -{ - ProtocolTreeNode *configNode = new ProtocolTreeNode("config", NULL, this->processGroupSettings(groups)) - << XATTR("xmlns", "urn:xmpp:whatsapp:push") << XATTR("id", pushID) << XATTR("lg", "en") << XATTR("lc", "US") << XATTR("clear", "0") - << XATTR("preview", preview ? "1" : "0") << XATTR("platform", platform) - << XATTR("default", defaultSettings ? "1" : "0") << XATTR("groups", groupSettings ? "1" : "0"); - - std::string id = makeId("config_"); - ProtocolTreeNode iq("iq", configNode); - out.write(iq << XATTR("id", id) << XATTR("type", "set") << XATTR("to", this->domain)); -} - -void WAConnection::sendClose() throw(WAException) -{ - ProtocolTreeNode n("presence"); - out.write(n << XATTR("type", "unavailable")); - out.streamEnd(); -} - -void WAConnection::sendComposing(const std::string &to) throw(WAException) -{ - ProtocolTreeNode n("chatstate", new ProtocolTreeNode("composing")); - out.write(n << XATTR("to", to)); -} - -void WAConnection::sendDeleteAccount() throw (WAException) -{ - m_pMutex->lock(); - std::string id = makeId("del_acct_"); - this->pending_server_requests[id] = new IqResultSendDeleteAccount(this); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("remove") << XATTR("xmlns", "urn:xmpp:whatsapp:account")); - out.write(iq << XATTR("id", id) << XATTR("type", "get") << XATTR("to", "s.whatsapp.net")); -} - -void WAConnection::sendGetGroups() throw (WAException) -{ - m_pMutex->lock(); - std::string id = makeId("iq_"); - this->pending_server_requests[id] = new IqResultGetGroupsHandler(this, "participating"); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("list") << XATTR("type", "participating")); - out.write(iq << XATTR("xmlns", "w:g") << XATTR("id", id) << XATTR("type", "get") << XATTR("to", "g.us")); -} - -void WAConnection::sendGetPicture(const char *jid, const char *type) throw (WAException) -{ - m_pMutex->lock(); - std::string id = makeId("iq_"); - this->pending_server_requests[id] = new IqResultGetPhotoHandler(this, jid); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("picture") << XATTR("type", type)); - out.write(iq << XATTR("id", id) << XATTR("to", jid) << XATTR("xmlns", "w:profile:picture") << XATTR("type", "get")); -} - -void WAConnection::sendGetPrivacyList() throw (WAException) -{ - m_pMutex->lock(); - std::string id = makeId("privacylist_"); - this->pending_server_requests[id] = new IqResultPrivayListHandler(this); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("query", - new ProtocolTreeNode("list") << XATTR("name", "default")) << XATTR("xmlns", "jabber:iq:privacy")); - out.write(iq << XATTR("id", id) << XATTR("type", "get")); -} - -void WAConnection::sendGetServerProperties() throw (WAException) -{ - m_pMutex->lock(); - std::string id = makeId("get_server_properties_"); - this->pending_server_requests[id] = new IqResultServerPropertiesHandler(this); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("list") << XATTR("type", "props")); - out.write(iq << XATTR("xmlns", "w:g2") << XATTR("id", id) << XATTR("type", "get") << XATTR("to", "g.us")); -} - -void WAConnection::sendInactive() throw(WAException) -{ - ProtocolTreeNode n("presence"); - out.write(n << XATTR("type", "inactive")); -} - -void WAConnection::sendAck(ProtocolTreeNode *node, const char *classType) -{ - const string &from = node->getAttributeValue("from"); - const string &to = node->getAttributeValue("to"); - const string &participant = node->getAttributeValue("participant"); - const string &id = node->getAttributeValue("id"); - const string &type = node->getAttributeValue("type"); - - ProtocolTreeNode sendNode("ack"); - sendNode << XATTR("to", from) << XATTR("id", id) << XATTR("class", classType); - if (!to.empty()) - sendNode << XATTR("from", to); - if (!participant.empty()) - sendNode << XATTR("participant", participant); - if (!type.empty()) - sendNode << XATTR("type", type); - - out.write(sendNode); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -ProtocolTreeNode* WAConnection::getMessageNode(FMessage* message, ProtocolTreeNode *child) -{ - std::vector* messageChildren = new std::vector(); - messageChildren->push_back(new ProtocolTreeNode("x", new ProtocolTreeNode("server")) << XATTR("xmlns", "jabber:x:event")); - messageChildren->push_back(child); - - return new ProtocolTreeNode("message", NULL, messageChildren) << - XATTR("to", message->key.remote_jid) << XATTR("type", "text") << XATTR("id", message->key.id) << XATTRI("t", message->timestamp); -} - -void WAConnection::sendMessage(FMessage* message) throw(WAException) -{ - if (message->media_wa_type != 0) - sendMessageWithMedia(message); - else - sendMessageWithBody(message); -} - -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) - throw new WAException("Cannot send system message over the network"); - - // request node for image, audio or video upload - if (message->media_wa_type == FMessage::WA_TYPE_IMAGE || message->media_wa_type == FMessage::WA_TYPE_AUDIO || message->media_wa_type == FMessage::WA_TYPE_VIDEO) { - m_pMutex->lock(); - std::string id = makeId("iq_"); - this->pending_server_requests[id] = new MediaUploadResponseHandler(this, *message); - m_pMutex->unlock(); - - ProtocolTreeNode *mediaNode = new ProtocolTreeNode("media"); - mediaNode << XATTR("hash", message->media_name) << XATTR("type", FMessage::getMessage_WA_Type_StrValue(message->media_wa_type)) << XATTR("size", std::to_string(message->media_size)); - - ProtocolTreeNode *n = new ProtocolTreeNode("iq", mediaNode); - n << XATTR("id", id) << XATTR("to", this->domain) << XATTR("type", "set") << XATTR("xmlns", "w:m"); - out.write(*n); - delete n; - return; - } - - ProtocolTreeNode *mediaNode; - if (message->media_wa_type == FMessage::WA_TYPE_CONTACT && !message->media_name.empty()) { - ProtocolTreeNode *vcardNode = new ProtocolTreeNode("vcard", new std::vector(message->data.begin(), message->data.end())) - << XATTR("name", message->media_name); - mediaNode = new ProtocolTreeNode("media", vcardNode); - } - else { - mediaNode = new ProtocolTreeNode("media", new std::vector(message->data.begin(), message->data.end()), NULL) - << XATTR("encoding", "text"); - } - - mediaNode << XATTR("xmlns", "urn:xmpp:whatsapp:mms") << XATTR("type", FMessage::getMessage_WA_Type_StrValue(message->media_wa_type)); - - if (message->media_wa_type == FMessage::WA_TYPE_LOCATION) - mediaNode << XATTR("latitude", Utilities::doubleToStr(message->latitude)) << XATTR("longitude", Utilities::doubleToStr(message->longitude)); - else { - mediaNode << XATTR("file", message->media_name) << XATTRI("size", message->media_size) << XATTR("url", message->media_url); - if (message->media_wa_type == FMessage::WA_TYPE_CONTACT || message->media_name.empty() || message->media_url.empty() || message->media_size <= 0) - mediaNode << XATTRI("seconds", message->media_duration_seconds); - } - - ProtocolTreeNode *n = WAConnection::getMessageNode(message, mediaNode); - out.write(*n); - delete n; - -} - -// TODO remove this code from WA purple -static std::string query_field(std::string work, std::string lo, bool integer = false) -{ - size_t p = work.find("\"" + lo + "\""); - if (p == std::string::npos) - return ""; - - work = work.substr(p + ("\"" + lo + "\"").size()); - - p = work.find("\""); - if (integer) - p = work.find(":"); - if (p == std::string::npos) - return ""; - - work = work.substr(p + 1); - - p = 0; - while (p < work.size()) { - if (work[p] == '"' && (p == 0 || work[p - 1] != '\\')) - break; - p++; - } - if (integer) { - p = 0; - while (p < work.size() && work[p] >= '0' && work[p] <= '9') - p++; - } - if (p == std::string::npos) - return ""; - - work = work.substr(0, p); - - return work; -} - -void WAConnection::processUploadResponse(ProtocolTreeNode * node, FMessage * message) -{ - ProtocolTreeNode* duplicate = node->getChild("duplicate"); - - // setup vars for media message - string fileType; - string caption, url, fileName, fileSize, filePath, fileHash; - caption = message->data; - - // parse node - if (duplicate != NULL) { - url = duplicate->getAttributeValue("url"); - fileSize = duplicate->getAttributeValue("size"); - fileHash = duplicate->getAttributeValue("filehash"); - fileType = duplicate->getAttributeValue("type"); - string tempfileName = duplicate->getAttributeValue("url"); - size_t index = tempfileName.find_last_of('/')+1; - fileName = tempfileName.substr(index); - } - else { - ProtocolTreeNode *media = node->getChild("media"); - if (media == NULL) - return; - - string url = media->getAttributeValue("url"); - if(url.empty()) - return; - - string json = MediaUploader::pushfile(url,message, this->user); - if (json.empty()) - return; - - //TODO why does the JSONNode not work? -> Throws some exception when trying to access elements after parsing. - - /*JSONNode resp = JSONNode::parse(json.c_str()); - fileName = resp["name"].as_string(); - url = resp["url"].as_string(); - fileSize = resp["size"].as_string(); - fileHash = resp["filehash"].as_string(); - fileType = resp["type"].as_string(); - */ - - // TODO remove this code from WA purple - size_t offset = json.find("{"); - if (offset == std::string::npos) - return; - json = json.substr(offset + 1); - - /* Look for closure */ - size_t cl = json.find("{"); - if (cl == std::string::npos) - cl = json.size(); - std::string work = json.substr(0, cl); - - fileName = query_field(work, "name"); - url = query_field(work, "url"); - fileSize = query_field(work, "size"); - fileHash = query_field(work, "filehash"); - fileType = query_field(work, "type"); - - } - - // TODO show caption and(?) link to media file in message window and history - ProtocolTreeNode *mediaNode = new ProtocolTreeNode("media"); - mediaNode << XATTR("type", fileType) - << XATTR("url", url) << XATTR("encoding", "raw") << XATTR("file", fileName) - << XATTR("size", fileSize)<< XATTR("caption", caption); - - ProtocolTreeNode * messageNode = new ProtocolTreeNode("message", mediaNode); - messageNode << XATTR("to", message->key.remote_jid) << XATTR("type", "media") - << XATTR("id", message->key.id) << XATTRI("t", (int)time(0)); - out.write(*messageNode); - delete messageNode; -} - -void WAConnection::sendMessageWithBody(FMessage* message) throw (WAException) -{ - ProtocolTreeNode *bodyNode = new ProtocolTreeNode("body", new std::vector(message->data.begin(), message->data.end())); - ProtocolTreeNode *n = WAConnection::getMessageNode(message, bodyNode); - out.write(*n); - delete n; -} - -void WAConnection::sendMessageReceived(const FMessage &message) throw(WAException) -{ - ProtocolTreeNode n("receipt"); - out.write(n << XATTR("type", "read") << XATTR("to", message.key.remote_jid) << XATTR("id", message.key.id)); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -void WAConnection::sendPaused(const std::string &to) throw(WAException) -{ - ProtocolTreeNode n("chatstate", new ProtocolTreeNode("paused")); - out.write(n << XATTR("to", to)); -} - -void WAConnection::sendPing() throw(WAException) -{ - m_pMutex->lock(); - std::string id = makeId("ping_"); - this->pending_server_requests[id] = new IqResultPingHandler(this); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("ping")); - out.write(iq << XATTR("id", id) << XATTR("xmlns", "w:p") << XATTR("type", "get") << XATTR("to", "s.whatsapp.net")); -} - -void WAConnection::sendPong(const std::string &id) throw(WAException) -{ - ProtocolTreeNode iq("iq"); - out.write(iq << XATTR("type", "result") << XATTR("to", this->domain) << XATTR("id", id)); -} - -void WAConnection::sendPresenceSubscriptionRequest(const std::string &to) throw(WAException) -{ - ProtocolTreeNode n("presence"); - out.write(n << XATTR("type", "subscribe") << XATTR("to", to)); -} - -void WAConnection::sendSetPicture(const char *jid, std::vector* data, std::vector* preview) throw (WAException) -{ - m_pMutex->lock(); - std::string id = this->makeId("set_photo_"); - this->pending_server_requests[id] = new IqResultSetPhotoHandler(this, jid); - m_pMutex->unlock(); - - std::vector* messageChildren = new std::vector(); - if (preview) - messageChildren->push_back(new ProtocolTreeNode("picture", preview, NULL) << XATTR("type", "preview")); - if (data) - messageChildren->push_back(new ProtocolTreeNode("picture", data, NULL) << XATTR("type", "image")); - - ProtocolTreeNode iq("iq", NULL, messageChildren); - out.write(iq << XATTR("id", id) << XATTR("type", "set") << XATTR("to", jid) << XATTR("xmlns", "w:profile:picture")); -} - -void WAConnection::sendStatusUpdate(std::string& status) throw (WAException) -{ - std::string id = this->makeId(Utilities::intToStr((int)time(NULL))); - FMessage message("s.us", true, id); - ProtocolTreeNode *body = new ProtocolTreeNode("body", new std::vector(status.begin(), status.end()), NULL); - ProtocolTreeNode *n = getMessageNode(&message, body); - out.write(*n); - delete n; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Group chats - -void WAConnection::sendGetGroupInfo(const std::string &gjid) throw (WAException) -{ - m_pMutex->lock(); - std::string id = makeId("iq_"); - this->pending_server_requests[id] = new IqResultGetGroupInfoHandler(this); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("query") << XATTR("request", "interactive")); - out.write(iq << XATTR("xmlns", "w:g2") << XATTR("id", id) << XATTR("type", "get") << XATTR("to", gjid)); -} - -void WAConnection::sendGetParticipants(const std::string &gjid) throw (WAException) -{ - m_pMutex->lock(); - std::string id = makeId("iq_"); - this->pending_server_requests[id] = new IqResultGetGroupParticipantsHandler(this); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("list")); - out.write(iq << XATTR("xmlns", "w:g") << XATTR("id", id) << XATTR("type", "get") << XATTR("to", gjid)); -} - -void WAConnection::readAttributeList(ProtocolTreeNode *node, std::vector& vector, const std::string &tag, const std::string &attribute) throw (WAException) -{ - std::vector nodes(node->getAllChildren(tag)); - for (size_t i = 0; i < nodes.size(); i++) { - ProtocolTreeNode *tagNode = nodes[i]; - vector.push_back(tagNode->getAttributeValue(attribute)); - } -} - -void WAConnection::sendCreateGroupChat(const std::string &subject) throw (WAException) -{ - logData("sending create group: %s", subject.c_str()); - - m_pMutex->lock(); - std::string id = makeId("create_group_"); - this->pending_server_requests[id] = new IqResultCreateGroupChatHandler(this, subject); - m_pMutex->unlock(); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode("group") << XATTR("action", "create") << XATTR("subject", subject)); - out.write(iq << XATTR("xmlns", "w:g") << XATTR("id", id) << XATTR("type", "set") << XATTR("to", "g.us")); -} - -void WAConnection::sendClearDirty(const std::string &category) throw (WAException) -{ - m_pMutex->lock(); - std::string id = makeId("clean_dirty_"); - this->pending_server_requests[id] = new IqResultClearDirtyHandler(this); - m_pMutex->unlock(); - - ProtocolTreeNode *categoryNode = new ProtocolTreeNode("category") << XATTR("name", category); - ProtocolTreeNode *cleanNode = new ProtocolTreeNode("clean", categoryNode) << XATTR("xmlns", "urn:xmpp:whatsapp:dirty"); - ProtocolTreeNode iq("iq", cleanNode); - out.write(iq << XATTR("id", id) << XATTR("type", "set") << XATTR("to", "s.whatsapp.net")); -} - -void WAConnection::sendJoinLeaveGroup(const char *gjid, bool bJoin) throw (WAException) -{ - std::string id = makeId("iq_"); - - ProtocolTreeNode *groupNode = new ProtocolTreeNode("group") << XATTR("id", gjid); - ProtocolTreeNode *leaveNode = new ProtocolTreeNode((bJoin) ? "join" : "leave", groupNode); - ProtocolTreeNode iq("iq", leaveNode); - out.write(iq << XATTR("xmlns", "w:g2") << XATTR("id", id) << XATTR("type", "set") << XATTR("to", "g.us")); -} - -void WAConnection::sendAddParticipants(const std::string &gjid, const std::vector &participants) throw (WAException) -{ - sendVerbParticipants(gjid, participants, "add"); -} - -void WAConnection::sendRemoveParticipants(const std::string &gjid, const std::vector &participants) throw (WAException) -{ - sendVerbParticipants(gjid, participants, "remove"); -} - -void WAConnection::sendVerbParticipants(const std::string &gjid, const std::vector &participants, const std::string &inner_tag) throw (WAException) -{ - std::string id = makeId("iq_"); - - size_t size = participants.size(); - std::vector* children = new std::vector(size); - for (size_t i = 0; i < size; i++) - (*children)[i] = new ProtocolTreeNode("participant") << XATTR("jid", participants[i]); - - ProtocolTreeNode iq("iq", new ProtocolTreeNode(inner_tag, NULL, children)); - out.write(iq << XATTR("xmlns", "w:g") << XATTR("id", id) << XATTR("type", "set") << XATTR("to", gjid)); -} - -void WAConnection::sendSetNewSubject(const std::string &gjid, const std::string &subject) throw (WAException) -{ - std::string id = this->makeId("iq_"); - - std::vector *data = new std::vector(subject.begin(), subject.end()); - ProtocolTreeNode iq("iq", new ProtocolTreeNode("subject", data)); - out.write(iq << XATTR("xmlns", "w:g2") << XATTR("id", id) << XATTR("type", "set") << XATTR("to", gjid)); -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h deleted file mode 100644 index 0756a77abe..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.h +++ /dev/null @@ -1,415 +0,0 @@ -/* - * WAConnection.h - * - * Created on: 26/06/2012 - * Author: Antonio - */ - - - - -#ifndef WACONNECTION_H_ -#define WACONNECTION_H_ - -#include -#include -#include -#include "WAException.h" -#include "FMessage.h" -#include "WALogin.h" -#include "utilities.h" -#include "BinTreeNodeReader.h" -#include "BinTreeNodeWriter.h" -#include "MediaUploader.h" - -#pragma warning(disable : 4290) - -class WALogin; -class WASocketConnection; -class KeyStream; -class BinTreeNodeReader; - -class WAListener { -public: - virtual void onMessageForMe(const FMessage ¶mFMessage) throw (WAException) = 0; - virtual void onMessageStatusUpdate(const FMessage ¶mFMessage) = 0; - virtual void onMessageError(const FMessage &message, int paramInt) = 0; - virtual void onPing(const std::string ¶mString) throw (WAException) = 0; - virtual void onPingResponseReceived() = 0; - virtual void onAvailable(const std::string ¶mString, bool paramBoolean, DWORD lastSeenTime = 0) = 0; - virtual void onClientConfigReceived(const std::string ¶mString) = 0; - virtual void onIsTyping(const std::string ¶mString, bool paramBoolean) = 0; - virtual void onAccountChange(int paramInt, time_t paramLong) = 0; - virtual void onPrivacyBlockListAdd(const std::string ¶mString) = 0; - virtual void onPrivacyBlockListClear() = 0; - virtual void onDirty(const std::map& paramHashtable) = 0; - virtual void onDirtyResponse(int paramHashtable) = 0; - virtual void onRelayRequest(const std::string ¶mString1, int paramInt, const std::string ¶mString2) = 0; - virtual void onSendGetPicture(const std::string &jid, const std::vector& data, const std::string &id) = 0; - virtual void onContactChanged(const std::string &jid, bool added) = 0; - virtual void onPictureChanged(const std::string &jid, const std::string &id, bool set) = 0; - virtual void onDeleteAccount(bool result) = 0; -}; - -class WAGroupListener { -public: - virtual void onGroupAddUser(const std::string &gjid, const std::string &ujid, int ts) = 0; - virtual void onGroupRemoveUser(const std::string &gjid, const std::string &ujid, int ts) = 0; - virtual void onGroupNewSubject(const std::string &from, const std::string &author, const std::string &newSubject, int paramInt) = 0; - virtual void onGroupMessage(const FMessage ¶mFMessage) = 0; - virtual void onServerProperties(std::map* nameValueMap) = 0; - virtual void onGroupCreated(const std::string &gjid, const std::string &nick) = 0; - virtual void onGroupInfo(const std::string &jid, const std::string &owner, const std::string &subject, const std::string &subject_owner, int time_subject, int time_created) = 0; - virtual void onSetSubject(const std::string ¶mString) = 0; - virtual void onAddGroupParticipants(const std::string ¶mString, const std::vector ¶mVector, int paramHashtable) = 0; - virtual void onRemoveGroupParticipants(const std::string ¶mString, const std::vector ¶mVector, int paramHashtable) = 0; - virtual void onGetParticipants(const std::string &gjid, const std::vector &participants) = 0; - virtual void onLeaveGroup(const std::string ¶mString) = 0; -}; - -class GroupSetting { -public: - std::string jid; - bool enabled; - time_t muteExpiry; - - GroupSetting() { - enabled = true; - jid = ""; - muteExpiry = 0; - } -}; - -class WAConnection -{ - class IqResultHandler { - protected: - WAConnection* con; - public: - IqResultHandler(WAConnection* con) {this->con = con;} - virtual void parse(ProtocolTreeNode* paramProtocolTreeNode, const std::string ¶mString) throw (WAException)=0; - void error(ProtocolTreeNode* node, int code) { - con->logData("WAConnection: error node %s: code = %d", node->getAttributeValue("id").c_str(), code); - } - void error(ProtocolTreeNode* node) throw (WAException) { - std::vector nodes(node->getAllChildren("error")); - for (size_t i = 0; i < nodes.size(); i++) { - ProtocolTreeNode* errorNode = nodes[i]; - if (errorNode != NULL) { - const string &errorCodeString = errorNode->getAttributeValue("code"); - if (!errorCodeString.empty()) { - int errorCode = atoi(errorCodeString.c_str()); - error(node, errorCode); - } - } - } - } - - virtual ~IqResultHandler() {} - }; - - class IqResultPingHandler: public IqResultHandler { - public: - IqResultPingHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode*, const std::string&) throw (WAException) { - if (this->con->m_pEventHandler != NULL) - this->con->m_pEventHandler->onPingResponseReceived(); - } - - void error(ProtocolTreeNode*) throw (WAException) { - if (this->con->m_pEventHandler != NULL) - this->con->m_pEventHandler->onPingResponseReceived(); - } - }; - - class IqResultGetGroupsHandler: public IqResultHandler { - private: - std::string type; - public: - IqResultGetGroupsHandler(WAConnection* con, const std::string &type ):IqResultHandler(con) {this->type = type;} - virtual void parse(ProtocolTreeNode* node, const std::string&) throw (WAException) { - std::vector groups; - this->con->readGroupList(node, groups); - } - }; - - class IqResultServerPropertiesHandler: public IqResultHandler { - public: - IqResultServerPropertiesHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string&) throw (WAException) { - std::vector nodes(node->getAllChildren("prop")); - std::map nameValueMap; - 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; - } - - if (this->con->m_pGroupEventHandler != NULL) - this->con->m_pGroupEventHandler->onServerProperties(&nameValueMap); - } - }; - - class IqResultPrivayListHandler: public IqResultHandler { - public: - IqResultPrivayListHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string&) throw (WAException) { - ProtocolTreeNode* queryNode = node->getChild(0); - ProtocolTreeNode::require(queryNode, "query"); - ProtocolTreeNode* listNode = queryNode->getChild(0); - ProtocolTreeNode::require(listNode, "list"); - if (this->con->m_pEventHandler != NULL) - this->con->m_pEventHandler->onPrivacyBlockListClear(); - if (listNode->children != NULL) { - for (size_t i = 0; i < listNode->children->size(); i++) { - ProtocolTreeNode* itemNode = (*listNode->children)[i]; - ProtocolTreeNode::require(itemNode, "item"); - if (itemNode->getAttributeValue("type").compare("jid") == 0) { - const string &jid = itemNode->getAttributeValue("value"); - if (!jid.empty() && this->con->m_pEventHandler != NULL) - this->con->m_pEventHandler->onPrivacyBlockListAdd(jid); - } - } - } - } - }; - - class IqResultGetGroupInfoHandler: public IqResultHandler { - public: - IqResultGetGroupInfoHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { - ProtocolTreeNode* groupNode = node->getChild(0); - ProtocolTreeNode::require(groupNode, "group"); - 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->m_pGroupEventHandler != NULL) - this->con->m_pGroupEventHandler->onGroupInfo(from, owner, subject, subject_owner, atoi(subject_t.c_str()), atoi(creation.c_str())); - } - }; - - class IqResultGetGroupParticipantsHandler: public IqResultHandler { - public: - IqResultGetGroupParticipantsHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { - if (this->con->m_pGroupEventHandler != NULL) { - std::vector participants; - this->con->readAttributeList(node, participants, "participant", "jid"); - this->con->m_pGroupEventHandler->onGetParticipants(from, participants); - } - } - }; - - class IqResultCreateGroupChatHandler: public IqResultHandler { - std::string subject; - public: - IqResultCreateGroupChatHandler(WAConnection* con, const std::string &_subject) : - IqResultHandler(con), - subject(_subject) {} - virtual void parse(ProtocolTreeNode* node, const std::string &from) throw (WAException) { - ProtocolTreeNode* groupNode = node->getChild(0); - ProtocolTreeNode::require(groupNode, "group"); - const string &groupId = groupNode->getAttributeValue("id"); - if (!groupId.empty() && con->m_pGroupEventHandler != NULL) - this->con->m_pGroupEventHandler->onGroupCreated(groupId + "@" + from, subject); - } - }; - - class IqResultGetPhotoHandler: public IqResultHandler { - private: - std::string jid; - std::string oldId; - std::string newId; - public: - IqResultGetPhotoHandler(WAConnection* con, const std::string &jid):IqResultHandler(con) { - this->jid = jid; - } - virtual void parse(ProtocolTreeNode* node, const std::string&) throw (WAException) { - const string &attributeValue = node->getAttributeValue("type"); - - if (!attributeValue.empty() && attributeValue == "result" && this->con->m_pEventHandler != NULL) { - std::vector children(node->getAllChildren("picture")); - for (size_t i = 0; i < children.size(); i++) { - ProtocolTreeNode* current = children[i]; - const string &id = current->getAttributeValue("id"); - if (!id.empty() && current->data != NULL && current->data->size() > 0) { - if (current->data != NULL) - this->con->m_pEventHandler->onSendGetPicture(this->jid, *current->data, id); - break; - } - } - } - } - void error(ProtocolTreeNode*) throw (WAException) { - if (this->con->m_pEventHandler != NULL) { - std::vector v; - this->con->m_pEventHandler->onSendGetPicture("error", v, ""); - } - } - }; - - class IqResultSetPhotoHandler: public IqResultHandler { - private: - std::string jid; - public: - IqResultSetPhotoHandler(WAConnection* con, const std::string &jid):IqResultHandler(con) {this->jid = jid;} - virtual void parse(ProtocolTreeNode* node, const std::string&) throw (WAException) { - if (this->con->m_pEventHandler != NULL) { - ProtocolTreeNode* child = node->getChild("picture"); - if (child != NULL) - this->con->m_pEventHandler->onPictureChanged(this->jid, "", true); - else - this->con->m_pEventHandler->onPictureChanged(this->jid, "", false); - } - } - }; - - class IqResultSendDeleteAccount: public IqResultHandler { - public: - IqResultSendDeleteAccount(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode*, const std::string&) throw (WAException) { - if (this->con->m_pEventHandler != NULL) - this->con->m_pEventHandler->onDeleteAccount(true); - } - - void error(ProtocolTreeNode*) throw (WAException) { - if (this->con->m_pEventHandler != NULL) - this->con->m_pEventHandler->onDeleteAccount(false); - } - }; - - class IqResultClearDirtyHandler: public IqResultHandler { - public: - IqResultClearDirtyHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode*, const std::string&) throw (WAException) { - } - }; - - class IqSendClientConfigHandler: public IqResultHandler { - public: - IqSendClientConfigHandler(WAConnection* con):IqResultHandler(con) {} - virtual void parse(ProtocolTreeNode* node, const std::string&) throw (WAException) { - con->logData("Clientconfig response %s", node->toString().c_str()); - } - - void error(ProtocolTreeNode* node) throw (WAException) { - con->logData("Clientconfig response error %s", node->toString().c_str()); - } - }; - - class MediaUploadResponseHandler : public IqResultHandler { - private: - FMessage message; - public: - MediaUploadResponseHandler(WAConnection* con, const FMessage &message) :IqResultHandler(con) { this->message = message; } - virtual void parse(ProtocolTreeNode* node, const std::string&) throw (WAException) { - this->con->processUploadResponse(node, &message); - } - void error(ProtocolTreeNode* node) throw (WAException) { - con->logData("Error on Media Upload Request: %s", node->toString().c_str()); - } - }; - - friend class WALogin; - -private: - ISocketConnection *rawConn; - BinTreeNodeReader in; - BinTreeNodeWriter out; - WAListener *m_pEventHandler; - WAGroupListener *m_pGroupEventHandler; - int iqid; - std::map pending_server_requests; - IMutex *m_pMutex; - - void parseAck(ProtocolTreeNode *node) throw (WAException); - void parseChatStates(ProtocolTreeNode *node) throw (WAException); - void parseIq(ProtocolTreeNode *node) throw(WAException); - void parseMessage(ProtocolTreeNode* node) throw(WAException); - void parseNotification(ProtocolTreeNode *node) throw(WAException); - void parsePresense(ProtocolTreeNode*) throw(WAException); - void parseReceipt(ProtocolTreeNode *node) throw (WAException); - std::map parseCategories(ProtocolTreeNode* node) throw(WAException); - - void processUploadResponse(ProtocolTreeNode *node, FMessage *message); - - void sendMessageWithMedia(FMessage* message) throw(WAException); - void sendMessageWithBody(FMessage* message) throw(WAException); - ProtocolTreeNode* getReceiptAck(const std::string &to, const std::string &id, const std::string &receiptType) throw(WAException); - std::string makeId(const std::string &prefix); - void readGroupList(ProtocolTreeNode* node, std::vector& groups) throw (WAException); - std::string gidToGjid(const std::string &gid); - void readAttributeList(ProtocolTreeNode* node, std::vector &vector, const std::string &tag, const std::string &attribute) throw (WAException); - void sendVerbParticipants(const std::string &gjid, const std::vector &participants, const std::string &inner_tag) throw (WAException); - bool supportsReceiptAcks(); - static ProtocolTreeNode* getMessageNode(FMessage* message, ProtocolTreeNode* node); - std::vector* processGroupSettings(const std::vector& gruops); - -public: - WAConnection(const std::string &user, const std::string &resource, IMutex* mutex, IMutex *write_mutex, ISocketConnection *conn, WAListener* m_pEventHandler, WAGroupListener* m_pGroupEventHandler); - virtual ~WAConnection(); - - std::string user; - std::string domain; - std::string resource; - std::string jid; - std::string nick; - - KeyStream inputKey, outputKey; - - bool retry; - bool supports_receipt_acks; - time_t expire_date; - int account_kind; - time_t lastTreeRead; - - static void globalInit(void); - static int tokenLookup(const std::string&); - - void logData(const char *format, ...); - void flush() { out.flushBuffer(true); } - - static std::string removeResourceFromJid(const std::string &jid); - - void setFlush(bool _flush) { if (out.bFlush = _flush) out.flushBuffer(true); } - - void setLogin(WALogin *login); - void sendMessage(FMessage* message) throw(WAException); - void sendAvailableForChat() throw(WAException); - - bool read() throw(WAException); - - void sendAck(ProtocolTreeNode * node, const char *classType); - void sendPing() throw(WAException); - void sendPong(const std::string &id) throw(WAException); - void sendComposing(const std::string &to) throw(WAException); - void sendActive() throw(WAException); - void sendInactive() throw(WAException); - void sendPaused(const std::string &to) throw(WAException); - void sendMessageReceived(const FMessage &message) throw(WAException); - void sendPresenceSubscriptionRequest(const std::string &to) throw (WAException); - void sendClientConfig(const std::string &sound, const std::string &pushID, bool preview, const std::string &platform) throw(WAException); - void sendClientConfig(const std::string &pushID, bool preview, const std::string &platform, bool defaultSettings, bool groupSettings, const std::vector& groups) throw(WAException); - void sendClose() throw (WAException); - void sendAvailable() throw (WAException); // U.H. - void sendGetPrivacyList() throw (WAException); - void sendGetServerProperties() throw (WAException); - void sendGetGroups() throw (WAException); - void sendCreateGroupChat(const std::string &subject) throw (WAException); - void sendGetGroupInfo(const std::string &gjid) throw (WAException); - void sendGetParticipants(const std::string &gjid) throw (WAException); - void sendClearDirty(const std::string &category) throw (WAException); - void sendJoinLeaveGroup(const char *gjid, bool bJoin) throw (WAException); - void sendAddParticipants(const std::string &gjid, const std::vector &participants) throw (WAException); - void sendRemoveParticipants(const std::string &gjid, const std::vector &participant) throw (WAException); - void sendSetNewSubject(const std::string &gjid, const std::string &subject) throw (WAException); - void sendStatusUpdate(std::string& status) throw (WAException); - void sendGetPicture(const char *jid, const char *type) throw (WAException); - void sendSetPicture(const char *jid, std::vector* data, std::vector* preview) throw (WAException); - void sendDeleteAccount() throw(WAException); -}; - -#endif /* WACONNECTION_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAException.h b/protocols/WhatsApp/src/WhatsAPI++/WAException.h deleted file mode 100644 index 4255850ffc..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/WAException.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * WAException.h - * - * Created on: 27/06/2012 - * Author: Antonio - */ - - - -#ifndef WAEXCEPTION_H_ -#define WAEXCEPTION_H_ - -#include -#include - -class WAException: public std::runtime_error { -public: - int type; - int subtype; - time_t expire_date; // in seconds - - static const int LOGIN_FAILURE_EX = 1; - static const int LOGIN_FAILURE_EX_TYPE_PASSWORD = 0; - static const int LOGIN_FAILURE_EX_TYPE_EXPIRED = 1; - - static const int CORRUPT_STREAM_EX = 2; - - static const int SOCKET_EX = 3; - static const int SOCKET_EX_RESOLVE_HOST = 0; - static const int SOCKET_EX_OPEN = 1; - static const int SOCKET_EX_INIT = 2; - static const int SOCKET_EX_SEND = 3; - static const int SOCKET_EX_RECV = 4; - - WAException(const std::string &err): runtime_error(err) {this->type = 0; this->subtype = 0; this->expire_date = 0;}; - WAException(const std::string &err, int type, int subtype): runtime_error(err), type(type), subtype(subtype), expire_date(0) {}; - WAException(const std::string &err, int type, int subtype, time_t expireDate): runtime_error(err), type(type), subtype(subtype), expire_date(expireDate) {}; -}; - -#endif /* WAEXCEPTION_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp b/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp deleted file mode 100644 index 12f7c7a863..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* - * WALogin.cpp - * - * Created on: 26/06/2012 - * Author: Antonio - */ - -#include "WALogin.h" -#include "ByteArray.h" -#include "ProtocolTreeNode.h" -#include -#include -#include -#include - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -using namespace Utilities; - -WALogin::WALogin(WAConnection* connection, const std::string &password) -{ - m_pConnection = connection; - m_szPassword = password; - m_iAccountKind = -1; - m_tExpireDate = 0L; -} - -std::vector WALogin::login(const std::vector& authBlob) -{ - m_pConnection->out.streamStart(m_pConnection->domain, m_pConnection->resource); - - m_pConnection->logData("sent stream start"); - - sendFeatures(); - - m_pConnection->logData("sent features"); - - sendAuth(authBlob); - - m_pConnection->logData("send auth, auth blob size %d", authBlob.size()); - - m_pConnection->in.streamStart(); - - m_pConnection->logData("read stream start"); - - return this->readFeaturesUntilChallengeOrSuccess(); -} - -void WALogin::sendResponse(const std::vector& challengeData) -{ - std::vector* authBlob = this->getAuthBlob(challengeData); - m_pConnection->out.write(ProtocolTreeNode("response", authBlob)); -} - -void WALogin::sendFeatures() -{ - std::vector* children = new std::vector(); - ProtocolTreeNode* receiptsChild = new ProtocolTreeNode("readreceipts"); - children->push_back(receiptsChild); - - ProtocolTreeNode* groupsChild = new ProtocolTreeNode("groups_v2"); - children->push_back(groupsChild); - - ProtocolTreeNode* privacyChild = new ProtocolTreeNode("privacy"); - children->push_back(privacyChild); - - ProtocolTreeNode* presenceChild = new ProtocolTreeNode("presence"); - children->push_back(presenceChild); - - m_pConnection->out.write(ProtocolTreeNode("stream:features", NULL, children)); -} - -void WALogin::sendAuth(const std::vector& existingChallenge) -{ - std::vector* data = NULL; - if (!existingChallenge.empty()) - data = getAuthBlob(existingChallenge); - - ProtocolTreeNode n("auth", data); - m_pConnection->out.write(n << XATTR("mechanism", "WAUTH-2") << XATTR("user", m_pConnection->user)); -} - -std::vector* WALogin::getAuthBlob(const std::vector& nonce) -{ - unsigned char out[4*20]; - KeyStream::keyFromPasswordAndNonce(m_szPassword, nonce, out); - - m_pConnection->inputKey.init(out + 40, out + 60); - m_pConnection->outputKey.init(out, out + 20); - - std::vector* list = new std::vector(0); - for (int i = 0; i < 4; i++) - list->push_back(0); - - list->insert(list->end(), m_pConnection->user.begin(), m_pConnection->user.end()); - list->insert(list->end(), nonce.begin(), nonce.end()); - - m_pConnection->outputKey.encodeMessage(&((*list)[0]), 0, 4, (int)list->size() - 4); - return list; -} - -std::vector WALogin::readFeaturesUntilChallengeOrSuccess() -{ - while (ProtocolTreeNode *root = m_pConnection->in.nextTree()) { - if (ProtocolTreeNode::tagEquals(root, "challenge")) { - std::vector challengedata(root->data->begin(), root->data->end()); - delete root; - - this->sendResponse(challengedata); - m_pConnection->logData("Send response"); - std::vector data = this->readSuccess(); - m_pConnection->logData("Read success"); - return std::vector(data.begin(), data.end()); - } - - if (ProtocolTreeNode::tagEquals(root, "success")) { - std::vector ret(root->data->begin(), root->data->end()); - this->parseSuccessNode(root); - delete root; - return ret; - } - - if (ProtocolTreeNode::tagEquals(root, "stream:features")) - m_pConnection->supports_receipt_acks = root->getChild("receipt_acks") != NULL; - - delete root; - } - throw WAException("fell out of loop in readFeaturesAndChallenge", WAException::CORRUPT_STREAM_EX, 0); -} - -void WALogin::parseSuccessNode(ProtocolTreeNode* node) -{ - m_pConnection->out.setSecure(); - - const string &expiration = node->getAttributeValue("expiration"); - if (!expiration.empty()) { - m_tExpireDate = atol(expiration.c_str()); - if (m_tExpireDate == 0) - throw WAException("invalid expire date: " + expiration); - } - - const string &kind = node->getAttributeValue("kind"); - if (kind == "paid") - m_iAccountKind = 1; - else if (kind == "free") - m_iAccountKind = 0; - else - m_iAccountKind = -1; -} - -std::vector WALogin::readSuccess() -{ - ProtocolTreeNode *node = m_pConnection->in.nextTree(); - - if (ProtocolTreeNode::tagEquals(node, "failure")) { - delete node; - throw WAException("Login failure", WAException::LOGIN_FAILURE_EX, WAException::LOGIN_FAILURE_EX_TYPE_PASSWORD); - } - - ProtocolTreeNode::require(node, "success"); - this->parseSuccessNode(node); - - const string &status = node->getAttributeValue("status"); - if (status == "expired") { - delete node; - throw WAException("Account expired on" + std::string(ctime(&m_tExpireDate)), WAException::LOGIN_FAILURE_EX, WAException::LOGIN_FAILURE_EX_TYPE_EXPIRED, m_tExpireDate); - } - if (status == "active") { - if (node->getAttributeValue("expiration").empty()) { - delete node; - throw WAException("active account with no expiration"); - } - } - else m_iAccountKind = -1; - - std::vector data = *node->data; - delete node; - return data; -} - -WALogin::~WALogin() -{} diff --git a/protocols/WhatsApp/src/WhatsAPI++/WALogin.h b/protocols/WhatsApp/src/WhatsAPI++/WALogin.h deleted file mode 100644 index 0d4d30af5b..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/WALogin.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * WALogin.h - * - * Created on: 26/06/2012 - * Author: Antonio - */ - -#ifndef WALOGIN_H_ -#define WALOGIN_H_ - -#include "BinTreeNodeReader.h" -#include "BinTreeNodeWriter.h" -#include "WAConnection.h" -#include - -#include "../OpenSSL/rc4.h" -#include "../OpenSSL/hmac.h" - -class WAConnection; -class BinTreeNodeReader; -class BinTreeNodeWriter; - -class KeyStream { -private: - RC4_KEY rc4; - unsigned char key[20], keyMac[20]; - int seq; - HMAC_CTX hmac; - - void hmacsha1(unsigned char* text, int textLength, unsigned char *out); - -public: - KeyStream(); - ~KeyStream(); - - void init(unsigned char *_key, unsigned char *_keyMac); - - static void keyFromPasswordAndNonce(const std::string &pass, const std::vector& nonce, unsigned char *out); - void decodeMessage(unsigned char* buffer, int macOffset, int offset, const int length); - void encodeMessage(unsigned char* buffer, int macOffset, int offset, const int length); -}; - - -class WALogin { -private: - WAConnection *m_pConnection; - - std::vector* getAuthBlob(const std::vector& nonce); - void sendResponse(const std::vector& challengeData); - void sendFeatures(); - void sendAuth(const std::vector& nonce); - std::vector readFeaturesUntilChallengeOrSuccess(); - void parseSuccessNode(ProtocolTreeNode *node); - std::vector readSuccess(); - -public: - time_t m_tExpireDate; - int m_iAccountKind; - std::string m_szPassword; - - WALogin(WAConnection* connection, const std::string &password); - ~WALogin(); - - std::vector login(const std::vector &blob); -}; - -#endif /* WALOGIN_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/WARegister.cpp b/protocols/WhatsApp/src/WhatsAPI++/WARegister.cpp deleted file mode 100644 index f7371c7fc8..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/WARegister.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * WARegister.cpp - * - */ - -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "WARegister.h" -#include "PhoneNumber.h" - -using namespace Utilities; - -static char WaToken[] = WHATSAPP_TOKEN; - - -///////////////////////////////////////////////////////////////////////////////////////// -// Token generation -// -std::string WAToken::GenerateToken(const string &number) -{ - uint8_t digest[16]; - md5_string(WaToken + number, digest); - - char dest[33]; - bin2hex(digest, sizeof(digest), dest); - return dest; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Account registration -// -CMStringA WARegister::RequestCodeUrl(const std::string &phoneNumber, const std::string &code) -{ - try { - std::string id = GenerateIdentity(phoneNumber); - - PhoneNumber pn(phoneNumber); - std::string token = WAToken::GenerateToken(pn.Number); - - const char *n = pn.Number.c_str(); - - if (!code.empty() && code != "voice" && code != "sms") - return CMStringA(FORMAT, "https://v.whatsapp.net/v2/register?cc=%d&in=%s&id=%s&code=%s", pn.countryCode, n, id.c_str(), code.c_str()); - - return CMStringA(FORMAT, "https://v.whatsapp.net/v2/code?cc=%d&in=%s&to=%d%s&method=%s&mcc=%03d&mnc=%03d&token=%s&id=%s&lg=%s&lc=%s", - pn.countryCode, n, pn.countryCode, n, code.c_str(), pn.mcc, pn.mnc, token.c_str(), id.c_str(), pn.ISO639, pn.ISO3166); - } - catch (...) - {} - - return CMStringA(); -} - - -std::string WARegister::GenerateIdentity(const std::string &phone) -{ - std::string id = phone; - std::reverse(id.begin(), id.end()); - - BYTE hash[MIR_SHA1_HASH_SIZE]; - mir_sha1_hash((PBYTE)id.c_str(), (int)id.length(), hash); - - id.clear(); - for (int i = 0; i < sizeof(hash); i++) { - char buf[10]; - sprintf_s(buf, "%%%02x", hash[i]); - id += buf; - } - - return id; -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/WARegister.h b/protocols/WhatsApp/src/WhatsAPI++/WARegister.h deleted file mode 100644 index f2fe0e230b..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/WARegister.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * WARegister.h - */ - -#ifndef WAREGISTER_H_ -#define WAREGISTER_H_ - -#include - -struct WAToken -{ - static std::string GenerateToken(const std::string &number); -}; - -class WARegister -{ - static std::string GenerateIdentity(const std::string &phone); - -public: - static CMStringA RequestCodeUrl(const std::string &phone, const std::string &code); -}; - -#endif /* WAREGISTER_H_ */ diff --git a/protocols/WhatsApp/src/WhatsAPI++/targetver.h b/protocols/WhatsApp/src/WhatsAPI++/targetver.h deleted file mode 100644 index 343ce14c2f..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/targetver.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -// Durch Einbeziehen von"SDKDDKVer.h" wird die hцchste verfьgbare Windows-Plattform definiert. - -// Wenn Sie die Anwendung fьr eine frьhere Windows-Plattform erstellen mцchten, schlieЯen Sie "WinSDKVer.h" ein, und -// legen Sie das _WIN32_WINNT-Makro auf die zu unterstьtzende Plattform fest, bevor Sie "SDKDDKVer.h" einschlieЯen. - -#include diff --git a/protocols/WhatsApp/src/WhatsAPI++/utilities.cpp b/protocols/WhatsApp/src/WhatsAPI++/utilities.cpp deleted file mode 100644 index 9c56a0c7dd..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/utilities.cpp +++ /dev/null @@ -1,386 +0,0 @@ -#include "../stdafx.h" // #TODO Remove Miranda-dependency - -#include "utilities.h" -#include "WAException.h" - -namespace Utilities { - -const static char digits[] = { - '0', '1', '2', '3', '4', '5', - '6', '7', '8', '9', 'a', 'b', - 'c', 'd', 'e', 'f', 'g', 'h', - 'i', 'j', 'k', 'l', 'm', 'n', - 'o', 'p', 'q', 'r', 's', 't', - 'u', 'v', 'w', 'x', 'y', 'z' -}; - -std::string reverseString(const std::string &str) -{ - return std::string(str.rbegin(), str.rend()); -} - -std::string itoa(int value, unsigned int base) -{ - const char digitMap[] = "0123456789abcdef"; - - std::string buf; - // Guard: - if (base == 0 || base > 16) { - - // Error: may add more trace/log output here - return buf; - } - // Take care of negative int: - std::string sign; - int _value = value; - // Check for case when input is zero: - if (_value == 0) return "0"; - if (value < 0) { - _value = -value; - sign = "-"; - } - - // Translating number to string with base: - - for (int i = 30; _value && i; --i) { - buf = digitMap[_value % base] + buf; - _value /= base; - } - - return sign.append(buf); -} - - -std::string processIdentity(const std::string &id) -{ - std::string buffer_str = reverseString(id); - - unsigned char digest[16]; - md5_string(buffer_str, digest); - buffer_str.clear(); - - for (int i = 0; i < 16; i++) { - int tmp = digest[i] + 128; - int f = tmp & 0xff; - - buffer_str = buffer_str.append(itoa(f, 16)); - } - - return buffer_str; -} - -void debug(const std::string &msg) -{ -#ifdef _LOGWIN32 - cout << "DEBUG: " << msg << endl; -#else - syslog(LOG_ERR, msg.c_str()); -#endif -} - -std::string str(int64_t i, int radix) -{ - if (radix < 2 || radix > 36) - throw WAException("radix must be in 2..36"); - char buf[65]; - int charPos = 64; - bool negative = (i < 0); - - if (!negative) { - i = -i; - } - - while (i <= -radix) { - buf[charPos--] = digits[(int)(-(i % radix))]; - i = i / radix; - } - buf[charPos] = digits[(int)(-i)]; - - if (negative) { - buf[--charPos] = '-'; - } - - std::string aux(buf, 65); - - return std::string(aux, charPos, (65 - charPos)); -} - -int64_t randLong() -{ - std::srand((unsigned)time(NULL)); - int64_t r = (int64_t)((char)(std::rand() % 256)); - - for (int i = 0; i < 7; i++) - r = (r << 8) + ((char)(std::rand() % 256)); - - return r; -} - -int64_t absLong(int64_t num) -{ - return (num >= 0 ? num : -num); -} - - -std::string intToStr(int i) -{ - std::stringstream convert; - convert << i; - return convert.str(); -} - -std::string doubleToStr(double d) -{ - std::stringstream convert; - convert << d; - return convert.str(); -} - -time_t parseBBDate(const string& s) -{ - if (s.length() < 17) - return time(NULL); - - struct tm timeinfo; - timeinfo.tm_year = atoi(s.substr(0, 4).c_str()) - 1900; - timeinfo.tm_mon = atoi(s.substr(4, 2).c_str()) - 1; - timeinfo.tm_mday = atoi(s.substr(6, 2).c_str()); - timeinfo.tm_hour = atoi(s.substr(9, 2).c_str()); - timeinfo.tm_min = atoi(s.substr(12, 2).c_str()); - timeinfo.tm_sec = atoi(s.substr(15, 2).c_str()); - - //return timegm(&timeinfo); - return mktime(&timeinfo); -} - -long long parseLongLong(const std::string &str) -{ - std::stringstream sstr(str); - long long val; - sstr >> val; - - return val; -} - -string bytesToHex(unsigned char* bytes, int length) -{ - string ret(length * 2, ' '); - string::iterator p = ret.begin(); - for (int c = 0; c < length; c++) { - int ub = bytes[c]; - *p++ = forDigit(ub >> 4); - *p++ = forDigit(ub % 16); - } - - return ret; -} - -unsigned char forDigit(int b) -{ - if (b < 10) - return (unsigned char)(48 + b); - return (unsigned char)(97 + b - 10); -} - -bool saveStringToFile(const string& data, const string& filePath) -{ - std::ofstream out(filePath.c_str()); - if (out.fail()) return false; - out << data; - if (out.fail()) return false; - out.close(); - if (out.fail()) return false; - return true; -} - -bool saveBytesToFile(const std::vector& data, const string& filePath) -{ - std::fstream out(filePath.c_str(), ios::out | ios::binary); - if (out.fail()) return false; - out.write((const char*)&data[0], data.size()); - if (out.fail()) return false; - out.close(); - if (out.fail()) return false; - return true; -} - - -bool saveBytesToFile(const string& data, const string& filePath) -{ - std::fstream out(filePath.c_str(), ios::out | ios::binary); - if (out.fail()) return false; - out.write(data.c_str(), data.length()); - if (out.fail()) return false; - out.close(); - if (out.fail()) return false; - return true; -} - -vector* loadFileToBytes(const string& path) -{ - vector* bytes = NULL; - std::ifstream in(path.c_str(), ios::in | ios::binary | ios::ate); - size_t size = in.tellg(); - if (in.fail()) return NULL; - - in.seekg(0, ios::beg); - char *buffer = new char[size]; - in.read(buffer, size); - bytes = new vector(buffer, buffer + size); - delete[] buffer; - in.close(); - if (in.fail()) return NULL; - - return bytes; -} - -bool fileExists(const std::string &path) -{ - return _access(path.c_str(), 0) == 0; -} - - -string removeWaDomainFromJid(const string& jid) -{ - string result = jid; - - size_t index = jid.find("@s.whatsapp.net"); - if (index != string::npos) { - result.replace(index, 15, ""); - return result; - } - - index = jid.find("@g.us"); - if (index != string::npos) { - result.replace(index, 5, ""); - return result; - } - - return jid; -} - -string getNameFromPath(const std::string &path) -{ - size_t i = path.rfind('/'); - if (i == string::npos) - i = 0; - else - i = i + 1; - return path.substr(i); -} - -vector* getChallengeData(const std::string &challengeFile) -{ - return loadFileToBytes(challengeFile); -} - -bool saveChallengeData(const std::vector& data, const std::string &challengeFile) -{ - return saveBytesToFile(data, challengeFile); -} - -std::string utf8_to_utf16(const std::string &utf8) -{ - std::vector unicode; - for (size_t i = 0; i < utf8.size();) { - unsigned long uni; - size_t todo; - unsigned char ch = utf8[i++]; - if (ch <= 0x7F) { - uni = ch; - todo = 0; - } - else if (ch <= 0xBF) { - throw std::logic_error("not a UTF-8 string"); - } - else if (ch <= 0xDF) { - uni = ch & 0x1F; - todo = 1; - } - else if (ch <= 0xEF) { - uni = ch & 0x0F; - todo = 2; - } - else if (ch <= 0xF7) { - uni = ch & 0x07; - todo = 3; - } - else { - throw std::logic_error("not a UTF-8 string"); - } - for (size_t j = 0; j < todo; ++j) { - if (i == utf8.size()) - throw std::logic_error("not a UTF-8 string"); - ch = utf8[i++]; - if (ch < 0x80 || ch > 0xBF) - throw std::logic_error("not a UTF-8 string"); - uni <<= 6; - uni += ch & 0x3F; - } - if (uni >= 0xD800 && uni <= 0xDFFF) - throw std::logic_error("not a UTF-8 string"); - if (uni > 0x10FFFF) - throw std::logic_error("not a UTF-8 string"); - unicode.push_back(uni); - } - std::string utf16; - for (size_t i = 0; i < unicode.size(); ++i) { - unsigned long uni = unicode[i]; - if (uni <= 0x7F) { - utf16 += (char)uni; - } - else - if (uni <= 0xFFFF) { - stringstream value; - value << std::setw(4) << std::setfill('0') << Utilities::itoa(uni, 16).c_str(); - utf16 += "\\u" + value.str(); - } - else { - stringstream value1, value2; - uni -= 0x10000; - value1 << std::setw(4) << std::setfill('0') << Utilities::itoa(((uni >> 10) + 0xD800), 16); - utf16 += "\\u" + value1.str(); - - value2 << std::setw(4) << std::setfill('0') << Utilities::itoa(((uni & 0x3FF) + 0xDC00), 16); - utf16 += "\\u" + value2.str(); - } - } - return utf16; -} - -std::string string_format(const char* fmt, va_list ap) -{ - int size = 100; - std::string str; - while (true) { - str.resize(size); - //va_start(ap, fmt); - int n = vsnprintf((char *)str.c_str(), size, fmt, ap); - //va_end(ap); - if (n > -1 && n < size) { - str.resize(n); - return str; - } - if (n > -1) - size = n + 1; - else - size *= 2; - } - return str; -} - -std::string string_format(const std::string fmt, va_list ap) -{ - return string_format(fmt.c_str(), ap); -} - -std::string string_format(const std::string fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - std::string ret = string_format(fmt, ap); - va_end(ap); - return ret; -} - -} diff --git a/protocols/WhatsApp/src/WhatsAPI++/utilities.h b/protocols/WhatsApp/src/WhatsAPI++/utilities.h deleted file mode 100644 index 5f5dd5713a..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/utilities.h +++ /dev/null @@ -1,70 +0,0 @@ -/*************************************************************************** -** -** Copyright (c) 2012, Tarek Galal -** -** This file is part of Wazapp, an IM application for Meego Harmattan -** platform that allows communication with Whatsapp users. -** -** Wazapp is free software: you can redistribute it and/or modify it under -** the terms of the GNU General Public License as published by the -** Free Software Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** Wazapp is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -** See the GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Wazapp. If not, see http://www.gnu.org/licenses/. -** -****************************************************************************/ - -#ifndef WA_UTILITIES -#define WA_UTILITIES - -#include -#include -#include -#include -#include - -#define _LOGWIN32 // #TODO -#ifndef _LOGWIN32 -#include -#endif - -using namespace std; - -// these functions must be declared somewhere in the same linking module -std::string base64_encode(void*, size_t); -void md5_string(const std::string &data, unsigned char digest[16]); - -namespace Utilities{ - string getMcc(); - string getMnc(); - string reverseString(const string& str); - string processIdentity(const std::string &password); - int64_t randLong(); - int64_t absLong(int64_t num); - string str(int64_t number, int radix); - std::string itoa(int value, unsigned int base); - std::string intToStr(int i); - std::string doubleToStr(double d); - long long parseLongLong(const std::string &str); - time_t parseBBDate(const string& s); - long long getCurrentTimeMillis(); - std::string bytesToHex(unsigned char* bytes, int length); - unsigned char forDigit(int b); - bool saveStringToFile(const string& data, const string& filePath); - bool saveBytesToFile(const string& data, const string& filePath); - bool saveBytesToFile(const std::vector& data, const string& filePath); - string removeWaDomainFromJid(const string& jid); - string getNameFromPath(const std::string &path); - vector* loadFileToBytes(const string& path); - bool fileExists(const std::string &path); - std::vector* getChallengeData(const std::string &file); - bool saveChallengeData(const std::vector& data, const std::string &file); - std::string utf8_to_utf16(const std::string &utf8); -} -#endif -- cgit v1.2.3