summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_address.h
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-02-28 06:48:33 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-02-28 06:48:33 +0000
commit21e7268a503be780b35e367564d711e79a61dffc (patch)
tree87b408e722116a6faea0d029d090e6278cda0f28 /protocols/Tox/src/tox_address.h
parent4410284da77786594d7009b6c515176de0d5a51e (diff)
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
Diffstat (limited to 'protocols/Tox/src/tox_address.h')
-rw-r--r--protocols/Tox/src/tox_address.h34
1 files changed, 22 insertions, 12 deletions
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<uint8_t> &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<uint8_t> &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<uint8_t> binData;
public:
ToxBinAddress(const ToxBinAddress &address) : binData(address.binData) { }
- ToxBinAddress(const std::vector<uint8_t> &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<uint8_t> &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);