This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
tango-tfe/common/include/tfe_plugin.h

58 lines
1.6 KiB
C
Raw Normal View History

#pragma once
#include <tfe_stream.h>
struct tfe_proxy;
struct tfe_thread_ctx;
typedef int plugin_init_cb_t(struct tfe_proxy * proxy);
typedef void plugin_deinit_cb_t(struct tfe_proxy * proxy);
//Return 1 for identify as its traffic;
//Return 0 for unknown traffic;
typedef int stream_open_cb_t(const struct tfe_stream * stream, unsigned int thread_id,
enum tfe_conn_dir dir, void ** pme);
typedef tfe_stream_action stream_data_cb_t(const struct tfe_stream * stream, unsigned int thread_id,
enum tfe_conn_dir dir, const unsigned char * data, size_t len, void ** pme);
typedef void stream_close_cb_t(const struct tfe_stream * stream, unsigned int thread_id,
enum tfe_stream_close_reason reason, void ** pme);
enum tfe_plugin_type
{
TFE_PLUGIN_TYPE_PLATFORM,
TFE_PLUGIN_TYPE_PROTOCOL,
TFE_PLUGIN_TYPE_BUSINESS
};
struct tfe_plugin
{
/* SYMBOL & PROTOCOL */
const char * symbol;
enum tfe_plugin_type type;
enum tfe_app_proto proto;
/* PLUGIN INIT & DEINIT */
plugin_init_cb_t * on_init;
plugin_deinit_cb_t * on_deinit;
/* PLUGIN STREAM ENTRIES */
stream_open_cb_t * on_open;
stream_data_cb_t * on_data;
stream_close_cb_t * on_close;
};
/* Register plugin */
int tfe_plugin_register(struct tfe_plugin * plugin);
/* Unregister plugin */
void tfe_plugin_unregister(struct tfe_plugin * plugin);
#define TFE_PLUGIN_REGISTER(_symbol, _plugin) \
static void __attribute__((constructor, used)) __plugin_loader_##_symbol(); \
static void __plugin_loader_##_symbol() \
{ \
_plugin.symbol = #_symbol; \
tfe_plugin_register(&_plugin); \
}