wip more refactoring
This commit is contained in:
71
ngc_ext_common.cpp
Normal file
71
ngc_ext_common.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "./ngc_ext_common.hpp"
|
||||
|
||||
//#include <cstdint>
|
||||
//#include <cassert>
|
||||
#include <new>
|
||||
//#include <map>
|
||||
//#include <list>
|
||||
//#include <set>
|
||||
//#include <optional>
|
||||
//#include <algorithm>
|
||||
|
||||
NGC_EXT_CTX* NGC_EXT_new(void) {
|
||||
auto* ctx = new NGC_EXT_CTX;
|
||||
// TODO: this is likely not necessary
|
||||
for (auto& it : ctx->callbacks) {
|
||||
it = nullptr;
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void NGC_EXT_kill(NGC_EXT_CTX* ngc_ext_ctx) {
|
||||
delete ngc_ext_ctx;
|
||||
}
|
||||
|
||||
//static void _handle_HS1_REQUEST_LAST_IDS(
|
||||
//Tox* tox,
|
||||
//NGC_HS1* ngc_hs1_ctx,
|
||||
|
||||
//uint32_t group_number,
|
||||
//uint32_t peer_number,
|
||||
|
||||
//const uint8_t *data,
|
||||
//size_t length
|
||||
//);
|
||||
|
||||
#define _EXT_HAVE(x, error) if ((length - curser) < (x)) { error; }
|
||||
void NGC_EXT_handle_group_custom_packet(
|
||||
Tox* tox,
|
||||
NGC_EXT_CTX* ngc_ext_ctx,
|
||||
|
||||
uint32_t group_number,
|
||||
uint32_t peer_number,
|
||||
|
||||
const uint8_t *data,
|
||||
size_t length
|
||||
//void *user_data
|
||||
) {
|
||||
size_t curser = 0;
|
||||
|
||||
_EXT_HAVE(1, return)
|
||||
|
||||
_PacketType pkg_type = static_cast<_PacketType>(*(data + curser));
|
||||
curser++;
|
||||
|
||||
fprintf(stderr, "custom_packet [%s] %lu\n", _pkgid2str(pkg_type), length);
|
||||
|
||||
if (pkg_type == INVALID) {
|
||||
fprintf(stderr, "(invalid)\n");
|
||||
return;
|
||||
}
|
||||
|
||||
auto handle_fn = ngc_ext_ctx->callbacks[pkg_type];
|
||||
if (handle_fn == nullptr) {
|
||||
fprintf(stderr, "!!! no handler for packet\n");
|
||||
return;
|
||||
}
|
||||
|
||||
handle_fn(tox, ngc_ext_ctx, group_number, peer_number, data+curser, length-curser);
|
||||
}
|
||||
#undef _EXT_HAVE
|
||||
|
||||
Reference in New Issue
Block a user