summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_utils.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2014-08-11 18:47:10 +0000
committerAlexander Lantsev <aunsane@gmail.com>2014-08-11 18:47:10 +0000
commit9f7023fdefc4bbdc888c8bb208bc79bbaa8df225 (patch)
tree30a29895f906c96f62349e17adf17a58ae004ff4 /protocols/Tox/src/tox_utils.cpp
parentf1e6c9b63fc90e6fbbcfcef52912ad0fda768302 (diff)
Tox: added friend list loading
git-svn-id: http://svn.miranda-ng.org/main/trunk@10157 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox/src/tox_utils.cpp')
-rw-r--r--protocols/Tox/src/tox_utils.cpp47
1 files changed, 16 insertions, 31 deletions
diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp
index e6f1a037f8..456b1dd75a 100644
--- a/protocols/Tox/src/tox_utils.cpp
+++ b/protocols/Tox/src/tox_utils.cpp
@@ -21,47 +21,32 @@ TOX_USERSTATUS CToxProto::MirandaToToxStatus(int status)
return userstatus;
}
-uint8_t *HexStringToData(const char *hex_string)
+std::vector<uint8_t> HexStringToData(const std::string hex)
{
- size_t legth = strlen(hex_string) / 2;
- uint8_t *data = (uint8_t*)mir_alloc(legth);
+ std::stringstream ss;
+ std::vector<uint8_t> data;
- for (size_t i = 0; i < legth; i++)
+ size_t count = hex.length() / 2;
+ for (size_t i = 0; i < count; i++)
{
- unsigned int val;
- sscanf(&hex_string[i * 2], "%2hhx", &val);
- data[i] = val;
+ uint8_t temp;
+ ss << std::hex << hex.substr(i * 2, 2);
+ ss >> temp;
+ data.push_back(temp);
}
return data;
}
-char *CToxProto::DataToHexString(const uint8_t *bin_string)
+std::string CToxProto::DataToHexString(const std::vector<uint8_t> data)
{
- uint32_t delta = 0, pos_extra, sum_extra = 0;
- char *ret = (char*)mir_alloc(TOX_FRIEND_ADDRESS_SIZE + 1);
-
- for (uint32_t i = 0; i < TOX_FRIEND_ADDRESS_SIZE; i++) {
- sprintf(&ret[2 * i + delta], "%02X", bin_string[i]);
-
- if ((i + 1) == TOX_CLIENT_ID_SIZE)
- pos_extra = 2 * (i + 1) + delta;
-
- if (i >= TOX_CLIENT_ID_SIZE)
- sum_extra |= bin_string[i];
-
- /*if (!((i + 1) % FRADDR_TOSTR_CHUNK_LEN)) {
- id_str[2 * (i + 1) + delta] = ' ';
- delta++;
- }*/
+ std::stringstream ss;
+ ss << std::hex << std::uppercase;
+ for (uint32_t i = 0; i < data.size(); i++)
+ {
+ ss << (int)data[i];
}
-
- //ret[2 * i + delta] = 0;
-
- if (!sum_extra)
- ret[pos_extra] = 0;
-
- return ret;
+ return ss.str();
}
int CToxProto::LoadToxData(const char *path)