From 21e7268a503be780b35e367564d711e79a61dffc Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sat, 28 Feb 2015 06:48:33 +0000 Subject: Tox: - added support of tox1 dns resolving - added request/grant items in contact menu - added copy id item in statum menu - code reordering - fixed minor bugs git-svn-id: http://svn.miranda-ng.org/main/trunk@12281 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_address.h | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'protocols/Tox/src/tox_address.h') diff --git a/protocols/Tox/src/tox_address.h b/protocols/Tox/src/tox_address.h index 6eada63300..4270e23ee2 100644 --- a/protocols/Tox/src/tox_address.h +++ b/protocols/Tox/src/tox_address.h @@ -9,12 +9,11 @@ class ToxHexAddress private: std::string hexData; public: - ToxHexAddress(const char *hex) : hexData(hex) { } - ToxHexAddress(const std::string &hex) : hexData(hex) { } ToxHexAddress(const ToxHexAddress &address) : hexData(address.hexData) { } - ToxHexAddress(const std::vector &bin) + ToxHexAddress(const char *hex, size_t size = TOX_FRIEND_ADDRESS_SIZE * 2) : hexData(hex, hex + size) { } + ToxHexAddress(const std::string &hex) { - this->ToxHexAddress::ToxHexAddress(bin.data(), bin.size()); + this->ToxHexAddress::ToxHexAddress(hex.c_str(), hex.size()); } ToxHexAddress(const uint8_t *bin, size_t size = TOX_FRIEND_ADDRESS_SIZE) { @@ -23,10 +22,18 @@ public: std::transform(hexData.begin(), hexData.end(), hexData.begin(), ::toupper); mir_free(hex); } + ToxHexAddress(const std::vector &bin) + { + this->ToxHexAddress::ToxHexAddress(bin.data(), bin.size()); + } const size_t GetLength() const { return hexData.length(); } + const bool IsEmpty() const + { + return hexData.length() == 0; + } const ToxHexAddress GetPubKey() const { ToxHexAddress pubKey = hexData.substr(0, TOX_PUBLIC_KEY_SIZE * 2).c_str(); @@ -36,6 +43,10 @@ public: { return hexData.c_str(); } + static ToxHexAddress Empty() + { + return ToxHexAddress(""); + } ToxBinAddress ToBin() const; }; @@ -45,24 +56,23 @@ private: std::vector binData; public: ToxBinAddress(const ToxBinAddress &address) : binData(address.binData) { } - ToxBinAddress(const std::vector &bin) : binData(bin) { } ToxBinAddress(const uint8_t *bin, size_t size = TOX_FRIEND_ADDRESS_SIZE) : binData(bin, bin + size) { } - ToxBinAddress(const std::string &hex) - { - this->ToxBinAddress::ToxBinAddress(hex.c_str()); - } - ToxBinAddress(const char *hex) + ToxBinAddress(const std::vector &bin, size_t size = TOX_FRIEND_ADDRESS_SIZE) : binData(bin.begin(), bin.begin() + size) { } + ToxBinAddress(const char *hex, size_t size = TOX_FRIEND_ADDRESS_SIZE * 2) { char *endptr; const char *pos = hex; - size_t size = mir_strlen(hex) / 2; - for (size_t i = 0; i < size; i++) + for (size_t i = 0; i < size / 2; i++) { char buf[5] = { '0', 'x', pos[0], pos[1], 0 }; binData.push_back((uint8_t)strtol(buf, &endptr, 0)); pos += 2; } } + ToxBinAddress(const std::string &hex) + { + this->ToxBinAddress::ToxBinAddress(hex.c_str(), hex.size()); + } const ToxBinAddress GetPubKey() const { ToxBinAddress pubKey(binData.data(), TOX_PUBLIC_KEY_SIZE); -- cgit v1.2.3