/** * Return a friend's Tox ID in short form. Return value must be freed. */ char * twc_get_friend_id_short(Tox *tox, int32_t friend_number) { uint8_t client_id[TOX_PUBLIC_KEY_SIZE]; TOX_ERR_FRIEND_GET_PUBLIC_KEY err; size_t short_id_length = weechat_config_integer(twc_config_short_id_size); char *hex_address = malloc(short_id_length + 1); tox_friend_get_public_key(tox, friend_number, client_id, &err); /* return a zero public key on failure */ if (err != TOX_ERR_FRIEND_GET_PUBLIC_KEY_OK) memset(client_id, 0, TOX_PUBLIC_KEY_SIZE); twc_bin2hex(client_id, short_id_length / 2, hex_address); return hex_address; }
void twc_friend_request_callback(Tox *tox, const uint8_t *public_key, const uint8_t *message, uint16_t length, void *data) { struct t_twc_profile *profile = data; char *message_nt = twc_null_terminate(message, length); int rc = twc_friend_request_add(profile, public_key, message_nt); if (rc == -1) { weechat_printf(profile->buffer, "%sReceived a friend request, but your friend request list is full!", weechat_prefix("warning")); } else { char hex_address[TOX_CLIENT_ID_SIZE * 2 + 1]; twc_bin2hex(public_key, TOX_CLIENT_ID_SIZE, hex_address); weechat_printf(profile->buffer, "%sReceived a friend request from %s with message \"%s\"; " "accept it with \"/friend accept %d\"", weechat_prefix("network"), hex_address, message_nt, rc); if (rc == -2) { weechat_printf(profile->buffer, "%sFailed to save friend request, try manually " "accepting with /friend add", weechat_prefix("error")); } } free(message_nt); }