summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/Tox/src/stdafx.h1
-rw-r--r--protocols/Tox/src/tox_address.h118
-rw-r--r--protocols/Tox/src/tox_contacts.cpp4
-rw-r--r--protocols/Tox/src/tox_core.cpp2
-rw-r--r--protocols/Tox/src/tox_options.cpp2
-rw-r--r--protocols/Tox/src/tox_profile.cpp2
-rw-r--r--protocols/Tox/src/tox_proto.h2
-rw-r--r--protocols/Tox/src/tox_search.cpp2
8 files changed, 44 insertions, 89 deletions
diff --git a/protocols/Tox/src/stdafx.h b/protocols/Tox/src/stdafx.h
index 275262c787..9433293742 100644
--- a/protocols/Tox/src/stdafx.h
+++ b/protocols/Tox/src/stdafx.h
@@ -17,7 +17,6 @@ DEFINE_PROPERTYKEY(PKEY_Device_FriendlyName, 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0
#include <vector>
#include <regex>
#include <map>
-#include <algorithm>
#include <newpluginapi.h>
diff --git a/protocols/Tox/src/tox_address.h b/protocols/Tox/src/tox_address.h
index 2688118fe2..9ef57caba2 100644
--- a/protocols/Tox/src/tox_address.h
+++ b/protocols/Tox/src/tox_address.h
@@ -7,115 +7,73 @@ class ToxBinAddress;
class ToxHexAddress
{
private:
- std::string hexData;
+ size_t hexSize;
+ char *hexData;
void Init(const char *hex, size_t size)
{
- hexData = std::string(hex, size);
+ hexSize = size;
+ hexData = (char*)mir_calloc(hexSize + 1);
+ memcpy(hexData, hex, hexSize);
}
void Init(const uint8_t *bin, size_t size)
{
- char *hex = (char*)mir_alloc(size * 2 + 1);
- hexData = bin2hex(bin, size, hex);
- std::transform(hexData.begin(), hexData.end(), hexData.begin(), ::toupper);
- mir_free(hex);
+ hexSize = size * 2;
+ hexData = (char*)mir_calloc(hexSize + 1);
+ char *p = bin2hex(bin, size, hexData);
+ while (*p++ = toupper(*p));
}
public:
- ToxHexAddress(const ToxHexAddress &address) : hexData(address.hexData) { }
- ToxHexAddress(const char *hex, size_t size = TOX_ADDRESS_SIZE * 2) : hexData(hex, hex + size) { }
- ToxHexAddress(const std::string &hex)
- {
- Init(hex.c_str(), hex.size());
- }
- ToxHexAddress(const uint8_t *bin, size_t size = TOX_ADDRESS_SIZE)
- {
- Init(bin, size);
- }
- ToxHexAddress(const std::vector<uint8_t> &bin)
- {
- Init(bin.data(), bin.size());
- }
+ ToxHexAddress(const char *hex, size_t size = TOX_ADDRESS_SIZE * 2) { Init(hex, size); }
+ ToxHexAddress(const std::string &hex) { Init(hex.c_str(), hex.size()); }
+ ToxHexAddress(const uint8_t *bin, size_t size = TOX_ADDRESS_SIZE) { Init(bin, size); }
+ ToxHexAddress(const ToxHexAddress &address) : hexData(address.hexData) { Init(address.hexData, address.hexSize); }
+ ~ToxHexAddress() { if (hexData) mir_free(hexData); }
ToxHexAddress& operator=(const char *hex)
{
Init(hex, mir_strlen(hex));
return *this;
}
- const size_t GetLength() const
- {
- return hexData.length();
- }
- const bool IsEmpty() const
- {
- return hexData.empty();
- }
- const ToxHexAddress GetPubKey() const
- {
- ToxHexAddress pubKey = hexData.substr(0, TOX_PUBLIC_KEY_SIZE * 2).c_str();
- return pubKey;
- }
- operator const char*() const
- {
- return hexData.c_str();
- }
- static ToxHexAddress Empty()
- {
- return ToxHexAddress("", 0);
- }
+ const size_t GetLength() const { return hexSize; }
+ const bool IsEmpty() const { return hexData[0] == 0; }
+ const ToxHexAddress GetPubKey() const { return ToxHexAddress(hexData, TOX_PUBLIC_KEY_SIZE * 2); }
+ operator const char*() const { return hexData; }
+ static ToxHexAddress Empty() { return ToxHexAddress("", 0); }
ToxBinAddress ToBin() const;
};
class ToxBinAddress
{
private:
- std::vector<uint8_t> binData;
+ size_t binSize;
+ uint8_t *binData;
void Init(const char *hex, size_t size)
{
- char *endptr;
- const char *pos = hex;
- size /= 2; binData.resize(size);
- for (size_t i = 0; i < size; i++)
- {
- char buf[5] = { '0', 'x', pos[0], pos[1], 0 };
- binData[i] = (uint8_t)strtol(buf, &endptr, 0);
- pos += 2;
- }
+ binSize = size / 2;
+ binData = (uint8_t*)mir_alloc(binSize);
+ hex2bin(hex, binData, binSize);
}
-public:
- ToxBinAddress(const ToxBinAddress &address) : binData(address.binData) { }
- ToxBinAddress(const uint8_t *bin, size_t size = TOX_ADDRESS_SIZE) : binData(bin, bin + size) { }
- ToxBinAddress(const std::vector<uint8_t> &bin, size_t size = TOX_ADDRESS_SIZE) : binData(bin.begin(), bin.begin() + size) { }
- ToxBinAddress(const char *hex, size_t size = TOX_ADDRESS_SIZE * 2)
- {
- Init(hex, size);
- }
- ToxBinAddress(const std::string &hex)
+ void Init(const uint8_t *bin, size_t size)
{
- Init(hex.c_str(), hex.size());
+ binSize = size;
+ binData = (uint8_t*)mir_alloc(binSize);
+ memcpy(binData, bin, binSize);
}
+public:
+ ToxBinAddress(const uint8_t *bin, size_t size = TOX_ADDRESS_SIZE) { Init(bin, size); }
+ ToxBinAddress(const char *hex, size_t size = TOX_ADDRESS_SIZE * 2) { Init(hex, size); }
+ ToxBinAddress(const std::string &hex) { Init(hex.c_str(), hex.size()); }
+ ToxBinAddress(const ToxBinAddress &address) { Init(address.binData, address.binSize); }
+ ~ToxBinAddress() { if (binData) mir_free(binData); }
ToxBinAddress& operator=(const char *hex)
{
Init(hex, mir_strlen(hex));
return *this;
}
- const ToxBinAddress GetPubKey() const
- {
- ToxBinAddress pubKey(binData.data(), TOX_PUBLIC_KEY_SIZE);
- return pubKey;
- }
- operator const uint8_t*() const
- {
- return binData.data();
- }
- ToxHexAddress ToHex() const
- {
- ToxHexAddress hex(binData.data(), binData.size());
- return hex;
- }
+ const ToxBinAddress GetPubKey() const { return ToxBinAddress(binData, TOX_PUBLIC_KEY_SIZE); }
+ operator const uint8_t*() const { return binData; }
+ ToxHexAddress ToHex() const { return ToxHexAddress(binData, binSize); }
};
-ToxBinAddress ToxHexAddress::ToBin() const
-{
- ToxBinAddress bin(hexData.c_str());
- return bin;
-}
+ToxBinAddress ToxHexAddress::ToBin() const { return ToxBinAddress(hexData, hexSize); }
#endif //_TOX_ADDRESS_H_ \ No newline at end of file
diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp
index bee4f7a126..fb0cf283a4 100644
--- a/protocols/Tox/src/tox_contacts.cpp
+++ b/protocols/Tox/src/tox_contacts.cpp
@@ -196,7 +196,7 @@ INT_PTR CToxProto::OnGrantAuth(WPARAM hContact, LPARAM)
db_unset(hContact, "CList", "NotOnList");
delSetting(hContact, "Grant");
- SaveToxProfile();
+ SaveToxProfile(toxThread);
return 0;
}
@@ -215,7 +215,7 @@ int CToxProto::OnContactDeleted(MCONTACT hContact, LPARAM)
logger->Log(__FUNCTION__": failed to delete friend (%d)", error);
return error;
}
- SaveToxProfile();
+ SaveToxProfile(toxThread);
}
/*else
{
diff --git a/protocols/Tox/src/tox_core.cpp b/protocols/Tox/src/tox_core.cpp
index bcc75eb436..5ab131ea6e 100644
--- a/protocols/Tox/src/tox_core.cpp
+++ b/protocols/Tox/src/tox_core.cpp
@@ -126,7 +126,7 @@ void CToxProto::UninitToxCore(CToxThread *toxThread)
{
CancelAllTransfers();
- SaveToxProfile();
+ SaveToxProfile(toxThread);
if (toxThread->tox != NULL)
{
diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp
index 007a3d6f74..a5f63da6ee 100644
--- a/protocols/Tox/src/tox_options.cpp
+++ b/protocols/Tox/src/tox_options.cpp
@@ -167,7 +167,7 @@ void CToxOptionsMain::OnApply()
// todo: add checkbox
m_proto->setTString("Password", pass_ptrT(m_password.GetText()));
- m_proto->SaveToxProfile();
+ m_proto->SaveToxProfile(m_proto->toxThread);
}
}
diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp
index 68539952b4..c8d93c4a26 100644
--- a/protocols/Tox/src/tox_profile.cpp
+++ b/protocols/Tox/src/tox_profile.cpp
@@ -97,7 +97,7 @@ bool CToxProto::LoadToxProfile(Tox_Options *options)
return false;
}
-void CToxProto::SaveToxProfile()
+void CToxProto::SaveToxProfile(CToxThread *toxThread)
{
mir_cslock locker(profileLock);
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h
index b12488e2b3..9179931cb1 100644
--- a/protocols/Tox/src/tox_proto.h
+++ b/protocols/Tox/src/tox_proto.h
@@ -81,7 +81,7 @@ private:
static TCHAR* GetToxProfilePath(const TCHAR *accountName);
bool LoadToxProfile(Tox_Options *options);
- void SaveToxProfile();
+ void SaveToxProfile(CToxThread *toxThread);
INT_PTR __cdecl OnCopyToxID(WPARAM, LPARAM);
diff --git a/protocols/Tox/src/tox_search.cpp b/protocols/Tox/src/tox_search.cpp
index 33479ba034..df15a4ab78 100644
--- a/protocols/Tox/src/tox_search.cpp
+++ b/protocols/Tox/src/tox_search.cpp
@@ -5,9 +5,7 @@ ToxHexAddress ResolveToxAddressFromDnsRecordV1(const std::string &dnsRecord)
std::smatch match;
std::regex regex("^v=tox1;id=([A-Fa-f0-9]{76})(;sign=(\\S+))?$");
if (std::regex_search(dnsRecord, match, regex))
- {
return ToxHexAddress(match[1]);
- }
return ToxHexAddress::Empty();
}