Things
This commit is contained in:
@@ -3,6 +3,10 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <tox/tox.h>
|
||||
|
||||
#include "tox-weechat.h"
|
||||
|
||||
#include "tox-weechat-utils.h"
|
||||
|
||||
uint8_t *
|
||||
@@ -22,7 +26,7 @@ tox_weechat_hex2bin(const char *hex)
|
||||
}
|
||||
|
||||
char *
|
||||
weechat_tox_bin2hex(const uint8_t *bin, size_t size)
|
||||
tox_weechat_bin2hex(const uint8_t *bin, size_t size)
|
||||
{
|
||||
char *hex = malloc(size * 2 + 1);
|
||||
char *position = hex;
|
||||
@@ -37,3 +41,42 @@ weechat_tox_bin2hex(const uint8_t *bin, size_t size)
|
||||
return hex;
|
||||
}
|
||||
|
||||
char *
|
||||
tox_weechat_null_terminate(const uint8_t *str, size_t length)
|
||||
{
|
||||
char *str_null = malloc(length + 1);
|
||||
memcpy(str_null, str, length);
|
||||
str_null[length] = 0;
|
||||
|
||||
return str_null;
|
||||
}
|
||||
|
||||
char *
|
||||
tox_weechat_get_name_nt(int32_t friend_number)
|
||||
{
|
||||
size_t length = tox_get_name_size(tox, friend_number);
|
||||
uint8_t name[length];
|
||||
tox_get_name(tox, friend_number, name);
|
||||
|
||||
return tox_weechat_null_terminate(name, length);
|
||||
}
|
||||
|
||||
char *
|
||||
tox_weechat_get_status_message_nt(int32_t friend_number)
|
||||
{
|
||||
size_t length = tox_get_status_message_size(tox, friend_number);
|
||||
uint8_t message[length];
|
||||
tox_get_status_message(tox, friend_number, message, length);
|
||||
|
||||
return tox_weechat_null_terminate(message, length);
|
||||
}
|
||||
|
||||
char *
|
||||
tox_weechat_get_self_name_nt()
|
||||
{
|
||||
size_t length = tox_get_self_name_size(tox);
|
||||
uint8_t name[length];
|
||||
tox_get_self_name(tox, name);
|
||||
|
||||
return tox_weechat_null_terminate(name, length);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user