2018-09-03 16:16:36 +08:00
|
|
|
#pragma once
|
2018-09-12 15:29:35 +08:00
|
|
|
|
2018-09-03 16:16:36 +08:00
|
|
|
#include <tfe_stream.h>
|
2018-09-12 15:29:35 +08:00
|
|
|
#include <tfe_http.h>
|
2018-09-03 16:16:36 +08:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/* PLUGIN INIT & DEINIT */
|
|
|
|
|
plugin_init_cb_t * on_init;
|
|
|
|
|
plugin_deinit_cb_t * on_deinit;
|
|
|
|
|
|
2018-09-12 15:29:35 +08:00
|
|
|
/* STREAM */
|
2018-09-03 16:16:36 +08:00
|
|
|
stream_open_cb_t * on_open;
|
|
|
|
|
stream_data_cb_t * on_data;
|
|
|
|
|
stream_close_cb_t * on_close;
|
2018-09-12 15:29:35 +08:00
|
|
|
|
|
|
|
|
/* HTTP */
|
|
|
|
|
http_session_begin_cb * on_session_begin;
|
|
|
|
|
http_session_data_cb * on_session_data;
|
|
|
|
|
http_session_end_cb * on_session_end;
|
2018-09-03 16:16:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Register plugin */
|
2018-09-07 17:27:23 +08:00
|
|
|
void tfe_plugin_register(struct tfe_plugin * plugin);
|
2018-09-03 16:16:36 +08:00
|
|
|
/* Unregister plugin */
|
|
|
|
|
void tfe_plugin_unregister(struct tfe_plugin * plugin);
|
|
|
|
|
|
2018-09-07 17:27:23 +08:00
|
|
|
/* Interate */
|
|
|
|
|
struct tfe_plugin * tfe_plugin_iterate(unsigned int * iterate);
|
|
|
|
|
unsigned int tfe_plugin_total_counts();
|
|
|
|
|
|
2018-09-03 16:16:36 +08:00
|
|
|
#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); \
|
|
|
|
|
}
|
2018-09-12 15:29:35 +08:00
|
|
|
|
|
|
|
|
#define TFE_PLUGIN_FOREACH(_p_info, _iterator) \
|
|
|
|
|
for((_p_info) = tfe_plugin_iterate((_iterator)); (_p_info) != NULL; \
|
|
|
|
|
(_p_info) = tfe_plugin_iterate((_iterator)))
|