diff options
author | Kirill Volinsky <mataes2007@gmail.com> | 2014-08-09 16:01:49 +0000 |
---|---|---|
committer | Kirill Volinsky <mataes2007@gmail.com> | 2014-08-09 16:01:49 +0000 |
commit | 681ba8556e859f38a0d7c910e9d40a9a917b3280 (patch) | |
tree | 9d4bf58947cbf5c2734e6d3f874182620d5bace1 /protocols/Tox/src/tox_utils.cpp | |
parent | 4156a5c95e9ac029bfd6c08dbebba3ff216c8b1d (diff) |
in debug you can see that it connects to network
git-svn-id: http://svn.miranda-ng.org/main/trunk@10137 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox/src/tox_utils.cpp')
-rw-r--r-- | protocols/Tox/src/tox_utils.cpp | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp index 3888da24bd..38cb154ce5 100644 --- a/protocols/Tox/src/tox_utils.cpp +++ b/protocols/Tox/src/tox_utils.cpp @@ -1,25 +1,16 @@ #include "common.h"
-uint8_t *CToxProto::HexToBinString(char *hex_string)
+char *CToxProto::HexToBinString(const char *hex_string)
{
- // byte is represented by exactly 2 hex digits, so lenth of binary string
- // is half of that of the hex one. only hex string with even length valid.
- // the more proper implementation would be to check if strlen(hex_string)
- // is odd and return error code if it is. we assume strlen is even.
- // if it's not then the last byte just won't be written in 'ret'.
- int length = strlen(hex_string) / 2;
- uint8_t *ret = (uint8_t*)mir_alloc(length);
- char *pos = hex_string;
-
- for (int i = 0; i < length; i++, pos += 2)
- {
- //sscanf(pos, "%2hhx", &ret[i]);
- uint8_t byteval;
- sscanf(pos, "%2hhx", &byteval);
- ret[i] = byteval;
- }
-
- return ret;
+ size_t len = strlen(hex_string); + char *val = (char*)mir_alloc(len); + + size_t i; + + for (i = 0; i < len; ++i, hex_string += 2) + sscanf(hex_string, "%2hhx", &val[i]); + + return val;
}
char *CToxProto::BinToHexString(uint8_t *bin_string)
|