more callbacks
This commit is contained in:
parent
4da9d3f81c
commit
490d892262
2
external/tox_ngc_ft1/tox_ngc_ft1
vendored
2
external/tox_ngc_ft1/tox_ngc_ft1
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 27f4dd7180be0309aa201cdf2453197ce7acea32
|
Subproject commit 4c37f0c32bd22f55756c5adacf37956a9b7dac1e
|
@ -5,6 +5,8 @@
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
// TODO: maybe a dispatch table is better?
|
||||||
|
|
||||||
// logging
|
// logging
|
||||||
void log_cb(Tox*, TOX_LOG_LEVEL level, const char *file, uint32_t line, const char *func, const char *message, void *user_data) {
|
void log_cb(Tox*, TOX_LOG_LEVEL level, const char *file, uint32_t line, const char *func, const char *message, void *user_data) {
|
||||||
//ToxClient* client = static_cast<ToxClient*>(user_data);
|
//ToxClient* client = static_cast<ToxClient*>(user_data);
|
||||||
@ -43,3 +45,39 @@ void group_self_join_cb(Tox*, uint32_t group_number, void *user_data) {
|
|||||||
static_cast<ToxClient*>(user_data)->onToxGroupSelfJoin(group_number);
|
static_cast<ToxClient*>(user_data)->onToxGroupSelfJoin(group_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ==================== sha1_info ====================
|
||||||
|
|
||||||
|
void ft1_recv_request_sha1_info_cb(Tox*, uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size, void* user_data) {
|
||||||
|
static_cast<ToxClient*>(user_data)->onFT1ReceiveRequestSHA1Info(group_number, peer_number, file_id, file_id_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ft1_recv_init_sha1_info_cb(Tox*, uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size, const uint8_t transfer_id, const size_t file_size, void* user_data) {
|
||||||
|
return static_cast<ToxClient*>(user_data)->onFT1ReceiveInitSHA1Info(group_number, peer_number, file_id, file_id_size, transfer_id, file_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft1_recv_data_sha1_info_cb(Tox*, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, const uint8_t* data, size_t data_size, void* user_data) {
|
||||||
|
static_cast<ToxClient*>(user_data)->onFT1ReceiveDataSHA1Info(group_number, peer_number, transfer_id, data_offset, data, data_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft1_send_data_sha1_info_cb(Tox*, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, uint8_t* data, size_t data_size, void* user_data) {
|
||||||
|
static_cast<ToxClient*>(user_data)->onFT1SendDataSHA1Info(group_number, peer_number, transfer_id, data_offset, data, data_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== sha1_chunk ====================
|
||||||
|
|
||||||
|
void ft1_recv_request_sha1_chunk_cb(Tox*, uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size, void* user_data) {
|
||||||
|
static_cast<ToxClient*>(user_data)->onFT1ReceiveRequestSHA1Chunk(group_number, peer_number, file_id, file_id_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ft1_recv_init_sha1_chunk_cb(Tox*, uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size, const uint8_t transfer_id, const size_t file_size, void* user_data) {
|
||||||
|
return static_cast<ToxClient*>(user_data)->onFT1ReceiveInitSHA1Chunk(group_number, peer_number, file_id, file_id_size, transfer_id, file_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft1_recv_data_sha1_chunk_cb(Tox*, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, const uint8_t* data, size_t data_size, void* user_data) {
|
||||||
|
static_cast<ToxClient*>(user_data)->onFT1ReceiveDataSHA1Chunk(group_number, peer_number, transfer_id, data_offset, data, data_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft1_send_data_sha1_chunk_cb(Tox*, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, uint8_t* data, size_t data_size, void* user_data) {
|
||||||
|
static_cast<ToxClient*>(user_data)->onFT1SendDataSHA1Chunk(group_number, peer_number, transfer_id, data_offset, data, data_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -38,3 +38,17 @@ void group_self_join_cb(Tox *tox, uint32_t group_number, void *user_data);
|
|||||||
//static void group_join_fail_cb(Tox *tox, uint32_t group_number, Tox_Group_Join_Fail fail_type, void *user_data);
|
//static void group_join_fail_cb(Tox *tox, uint32_t group_number, Tox_Group_Join_Fail fail_type, void *user_data);
|
||||||
//static void group_moderation_cb(Tox *tox, uint32_t group_number, uint32_t source_peer_id, uint32_t target_peer_id, Tox_Group_Mod_Event mod_type, void *user_data);
|
//static void group_moderation_cb(Tox *tox, uint32_t group_number, uint32_t source_peer_id, uint32_t target_peer_id, Tox_Group_Mod_Event mod_type, void *user_data);
|
||||||
|
|
||||||
|
// ft1
|
||||||
|
|
||||||
|
// sha1_info
|
||||||
|
void ft1_recv_request_sha1_info_cb(Tox *tox, uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size, void* user_data);
|
||||||
|
bool ft1_recv_init_sha1_info_cb(Tox *tox, uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size, const uint8_t transfer_id, const size_t file_size, void* user_data);
|
||||||
|
void ft1_recv_data_sha1_info_cb(Tox *tox, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, const uint8_t* data, size_t data_size, void* user_data);
|
||||||
|
void ft1_send_data_sha1_info_cb(Tox *tox, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, uint8_t* data, size_t data_size, void* user_data);
|
||||||
|
|
||||||
|
// sha1_chunk
|
||||||
|
void ft1_recv_request_sha1_chunk_cb(Tox *tox, uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size, void* user_data);
|
||||||
|
bool ft1_recv_init_sha1_chunk_cb(Tox *tox, uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size, const uint8_t transfer_id, const size_t file_size, void* user_data);
|
||||||
|
void ft1_recv_data_sha1_chunk_cb(Tox *tox, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, const uint8_t* data, size_t data_size, void* user_data);
|
||||||
|
void ft1_send_data_sha1_chunk_cb(Tox *tox, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, uint8_t* data, size_t data_size, void* user_data);
|
||||||
|
|
||||||
|
@ -65,8 +65,8 @@ ToxClient::ToxClient(const CommandLine& cl) :
|
|||||||
throw std::runtime_error{"tox failed"};
|
throw std::runtime_error{"tox failed"};
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CALLBACK_REG(x) tox_callback_##x(_tox, x##_cb)
|
#define TOX_CALLBACK_REG(x) tox_callback_##x(_tox, x##_cb)
|
||||||
CALLBACK_REG(self_connection_status);
|
TOX_CALLBACK_REG(self_connection_status);
|
||||||
|
|
||||||
//CALLBACK_REG(friend_name);
|
//CALLBACK_REG(friend_name);
|
||||||
//CALLBACK_REG(friend_status_message);
|
//CALLBACK_REG(friend_status_message);
|
||||||
@ -74,7 +74,7 @@ ToxClient::ToxClient(const CommandLine& cl) :
|
|||||||
//CALLBACK_REG(friend_connection_status);
|
//CALLBACK_REG(friend_connection_status);
|
||||||
//CALLBACK_REG(friend_typing);
|
//CALLBACK_REG(friend_typing);
|
||||||
//CALLBACK_REG(friend_read_receipt);
|
//CALLBACK_REG(friend_read_receipt);
|
||||||
CALLBACK_REG(friend_request);
|
TOX_CALLBACK_REG(friend_request);
|
||||||
//CALLBACK_REG(friend_message);
|
//CALLBACK_REG(friend_message);
|
||||||
|
|
||||||
//CALLBACK_REG(file_recv_control);
|
//CALLBACK_REG(file_recv_control);
|
||||||
@ -92,10 +92,13 @@ ToxClient::ToxClient(const CommandLine& cl) :
|
|||||||
//CALLBACK_REG(friend_lossy_packet);
|
//CALLBACK_REG(friend_lossy_packet);
|
||||||
//CALLBACK_REG(friend_lossless_packet);
|
//CALLBACK_REG(friend_lossless_packet);
|
||||||
|
|
||||||
CALLBACK_REG(group_custom_packet);
|
TOX_CALLBACK_REG(group_custom_packet);
|
||||||
CALLBACK_REG(group_custom_private_packet);
|
TOX_CALLBACK_REG(group_custom_private_packet);
|
||||||
CALLBACK_REG(group_invite);
|
TOX_CALLBACK_REG(group_invite);
|
||||||
#undef CALLBACK_REG
|
TOX_CALLBACK_REG(group_peer_join);
|
||||||
|
TOX_CALLBACK_REG(group_peer_exit);
|
||||||
|
TOX_CALLBACK_REG(group_self_join);
|
||||||
|
#undef TOX_CALLBACK_REG
|
||||||
|
|
||||||
if (_self_name.empty()) {
|
if (_self_name.empty()) {
|
||||||
_self_name = "tox_ngc_ft1_tool";
|
_self_name = "tox_ngc_ft1_tool";
|
||||||
@ -108,6 +111,18 @@ ToxClient::ToxClient(const CommandLine& cl) :
|
|||||||
_ft1_ctx = NGC_FT1_new(&ft1_options);
|
_ft1_ctx = NGC_FT1_new(&ft1_options);
|
||||||
NGC_FT1_register_ext(_ft1_ctx, _ext_ctx);
|
NGC_FT1_register_ext(_ft1_ctx, _ext_ctx);
|
||||||
|
|
||||||
|
// sha1_info
|
||||||
|
NGC_FT1_register_callback_recv_request(_ft1_ctx, NGC_FT1_file_kind::HASH_SHA1_INFO, ft1_recv_request_sha1_info_cb, this);
|
||||||
|
NGC_FT1_register_callback_recv_init(_ft1_ctx, NGC_FT1_file_kind::HASH_SHA1_INFO, ft1_recv_init_sha1_info_cb, this);
|
||||||
|
NGC_FT1_register_callback_recv_data(_ft1_ctx, NGC_FT1_file_kind::HASH_SHA1_INFO, ft1_recv_data_sha1_info_cb, this);
|
||||||
|
NGC_FT1_register_callback_send_data(_ft1_ctx, NGC_FT1_file_kind::HASH_SHA1_INFO, ft1_send_data_sha1_info_cb, this);
|
||||||
|
|
||||||
|
// sha1_chunk
|
||||||
|
NGC_FT1_register_callback_recv_request(_ft1_ctx, NGC_FT1_file_kind::HASH_SHA1_CHUNK, ft1_recv_request_sha1_chunk_cb, this);
|
||||||
|
NGC_FT1_register_callback_recv_init(_ft1_ctx, NGC_FT1_file_kind::HASH_SHA1_CHUNK, ft1_recv_init_sha1_chunk_cb, this);
|
||||||
|
NGC_FT1_register_callback_recv_data(_ft1_ctx, NGC_FT1_file_kind::HASH_SHA1_CHUNK, ft1_recv_data_sha1_chunk_cb, this);
|
||||||
|
NGC_FT1_register_callback_send_data(_ft1_ctx, NGC_FT1_file_kind::HASH_SHA1_CHUNK, ft1_send_data_sha1_chunk_cb, this);
|
||||||
|
|
||||||
// dht bootstrap
|
// dht bootstrap
|
||||||
{
|
{
|
||||||
struct DHT_node {
|
struct DHT_node {
|
||||||
@ -215,6 +230,34 @@ void ToxClient::onToxGroupSelfJoin(uint32_t group_number) {
|
|||||||
_tox_profile_dirty = true;
|
_tox_profile_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sha1_info
|
||||||
|
void ToxClient::onFT1ReceiveRequestSHA1Info(uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ToxClient::onFT1ReceiveInitSHA1Info(uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size, const uint8_t transfer_id, const size_t file_size) {
|
||||||
|
return false; // deny
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToxClient::onFT1ReceiveDataSHA1Info(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, const uint8_t* data, size_t data_size) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToxClient::onFT1SendDataSHA1Info(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, uint8_t* data, size_t data_size) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// sha1_chunk
|
||||||
|
void ToxClient::onFT1ReceiveRequestSHA1Chunk(uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ToxClient::onFT1ReceiveInitSHA1Chunk(uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size, const uint8_t transfer_id, const size_t file_size) {
|
||||||
|
return false; // deny
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToxClient::onFT1ReceiveDataSHA1Chunk(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, const uint8_t* data, size_t data_size) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToxClient::onFT1SendDataSHA1Chunk(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, uint8_t* data, size_t data_size) {
|
||||||
|
}
|
||||||
|
|
||||||
void ToxClient::saveToxProfile(void) {
|
void ToxClient::saveToxProfile(void) {
|
||||||
if (_tox_profile_path.empty()) {
|
if (_tox_profile_path.empty()) {
|
||||||
return;
|
return;
|
||||||
|
@ -30,6 +30,19 @@ struct ToxClient {
|
|||||||
void onToxGroupPeerExit(uint32_t group_number, uint32_t peer_id, Tox_Group_Exit_Type exit_type, std::string_view name, std::string_view part_message);
|
void onToxGroupPeerExit(uint32_t group_number, uint32_t peer_id, Tox_Group_Exit_Type exit_type, std::string_view name, std::string_view part_message);
|
||||||
void onToxGroupSelfJoin(uint32_t group_number);
|
void onToxGroupSelfJoin(uint32_t group_number);
|
||||||
|
|
||||||
|
public: // FT1 callbacks
|
||||||
|
// sha1_info
|
||||||
|
void onFT1ReceiveRequestSHA1Info(uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size);
|
||||||
|
bool onFT1ReceiveInitSHA1Info(uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size, const uint8_t transfer_id, const size_t file_size);
|
||||||
|
void onFT1ReceiveDataSHA1Info(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, const uint8_t* data, size_t data_size);
|
||||||
|
void onFT1SendDataSHA1Info(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, uint8_t* data, size_t data_size);
|
||||||
|
|
||||||
|
// sha1_chunk
|
||||||
|
void onFT1ReceiveRequestSHA1Chunk(uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size);
|
||||||
|
bool onFT1ReceiveInitSHA1Chunk(uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size, const uint8_t transfer_id, const size_t file_size);
|
||||||
|
void onFT1ReceiveDataSHA1Chunk(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, const uint8_t* data, size_t data_size);
|
||||||
|
void onFT1SendDataSHA1Chunk(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, uint8_t* data, size_t data_size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void saveToxProfile(void);
|
void saveToxProfile(void);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user