2022-07-27 14:11:29 +08:00
|
|
|
#include "deps/uthash/uthash.h"
|
2022-07-20 20:20:31 +08:00
|
|
|
#include "sdk/include/session.h"
|
2022-07-27 15:51:07 +08:00
|
|
|
#include "sdk/include/plugin.h"
|
2022-07-20 20:20:31 +08:00
|
|
|
#include "session_manager.h"
|
2022-07-27 15:51:07 +08:00
|
|
|
#include "plugin_manager.h"
|
|
|
|
|
|
|
|
|
|
#include <sys/queue.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
|
* CallBack Static Hash Table (For Global)
|
|
|
|
|
******************************************************************************/
|
2022-07-20 20:20:31 +08:00
|
|
|
|
2022-07-27 15:51:07 +08:00
|
|
|
struct session_event_callback_static
|
2022-07-06 23:18:13 +08:00
|
|
|
{
|
2022-07-27 15:51:07 +08:00
|
|
|
enum session_event_type event;
|
|
|
|
|
fn_session_event_callback *callback;
|
2022-07-06 23:18:13 +08:00
|
|
|
};
|
|
|
|
|
|
2022-07-27 15:51:07 +08:00
|
|
|
/*
|
|
|
|
|
* Hast table
|
|
|
|
|
*
|
|
|
|
|
* key: string -> session_type
|
|
|
|
|
* val: array -> event_cbs
|
|
|
|
|
*/
|
|
|
|
|
struct managed_session_event_callback
|
|
|
|
|
{
|
|
|
|
|
char session_type[16];
|
|
|
|
|
struct session_event_callback_static event_cbs[0]; // dynamic array
|
|
|
|
|
// Record the number of callback functions that want to process the current session
|
|
|
|
|
int event_cbs_num;
|
|
|
|
|
UT_hash_handle hh;
|
|
|
|
|
};
|
2022-07-06 23:18:13 +08:00
|
|
|
|
2022-07-27 15:51:07 +08:00
|
|
|
/******************************************************************************
|
|
|
|
|
* CallBack Runtime Array (For Per Session)
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
struct session_event_callback_runtime
|
2022-07-06 23:18:13 +08:00
|
|
|
{
|
2022-07-27 15:51:07 +08:00
|
|
|
int skip; // for skip this plugin callback
|
|
|
|
|
void *callback_args;
|
|
|
|
|
|
|
|
|
|
enum session_event_type event;
|
|
|
|
|
fn_session_event_callback *callback;
|
2022-07-06 23:18:13 +08:00
|
|
|
};
|
|
|
|
|
|
2022-07-27 15:51:07 +08:00
|
|
|
struct session_plugin_ctx
|
2022-07-06 23:18:13 +08:00
|
|
|
{
|
2022-07-27 15:51:07 +08:00
|
|
|
int event_cbs_num;
|
|
|
|
|
struct session_event_callback_runtime event_cbs[0]; // dynamic array
|
2022-07-06 23:18:13 +08:00
|
|
|
};
|
|
|
|
|
|
2022-07-27 15:51:07 +08:00
|
|
|
/******************************************************************************
|
|
|
|
|
* struct plugin_manager
|
|
|
|
|
******************************************************************************/
|
2022-07-06 23:18:13 +08:00
|
|
|
|
2022-07-27 15:51:07 +08:00
|
|
|
/*
|
|
|
|
|
* Each plugin has an init_cb and an exit_cb, but may have multiple entry_cb.
|
|
|
|
|
* entry_cb is stored in the global_session_callback_ctx.
|
|
|
|
|
*/
|
|
|
|
|
struct plugin_ctx
|
2022-07-27 14:11:29 +08:00
|
|
|
{
|
2022-07-27 15:51:07 +08:00
|
|
|
char *name;
|
|
|
|
|
char *library;
|
|
|
|
|
/*
|
|
|
|
|
* Stores the context generated by the plugin initialization,
|
|
|
|
|
* which is used to release resources when the plugin ends.
|
|
|
|
|
*/
|
|
|
|
|
void *pme;
|
|
|
|
|
plugin_init_callback *init_cb;
|
|
|
|
|
plugin_exit_callback *exit_cb;
|
2022-07-27 14:11:29 +08:00
|
|
|
};
|
|
|
|
|
|
2022-07-27 15:51:07 +08:00
|
|
|
struct plugin_manager
|
2022-07-27 14:11:29 +08:00
|
|
|
{
|
2022-07-27 15:51:07 +08:00
|
|
|
struct managed_session_event_callback *cb_table;
|
|
|
|
|
struct plugin_ctx plugins[MAX_PLUGIN_NUM];
|
2022-07-27 14:11:29 +08:00
|
|
|
};
|
|
|
|
|
|
2022-07-27 15:51:07 +08:00
|
|
|
/******************************************************************************
|
|
|
|
|
* Private API
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void plugin_manager_handle_opening_event(struct plugin_manager *plug_mgr, struct stellar_event *event)
|
2022-07-24 23:59:00 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-27 15:51:07 +08:00
|
|
|
static void plugin_manager_handle_data_event(struct plugin_manager *plug_mgr, struct stellar_event *event)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void plugin_manager_handle_closing_event(struct plugin_manager *plug_mgr, struct stellar_event *event)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
|
* Public API
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
struct plugin_manager *plugin_manager_create()
|
|
|
|
|
{
|
|
|
|
|
struct plugin_manager *plug_mgr = NULL;
|
|
|
|
|
|
|
|
|
|
return plug_mgr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void plugin_manager_destory(struct plugin_manager *plug_mgr)
|
|
|
|
|
{
|
|
|
|
|
if (plug_mgr)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int plugin_manager_load(struct plugin_manager *plug_mgr, const char *plugin_file)
|
2022-07-24 23:59:00 +08:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-27 15:51:07 +08:00
|
|
|
void plugin_manager_unload(struct plugin_manager *plug_mgr)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int plugin_manager_register(struct plugin_manager *plug_mgr, const char *session_type, fn_session_event_callback *callback)
|
2022-07-06 23:18:13 +08:00
|
|
|
{
|
2022-07-20 20:20:31 +08:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-27 15:51:07 +08:00
|
|
|
void plugin_manager_dispatch(struct plugin_manager *plug_mgr, struct stellar_event *event)
|
2022-07-20 20:20:31 +08:00
|
|
|
{
|
2022-07-27 15:51:07 +08:00
|
|
|
assert(event);
|
|
|
|
|
struct stellar_session_event_data *event_data = event->session_event_data;
|
|
|
|
|
assert(event_data);
|
|
|
|
|
session_event_type type = event_data->type;
|
|
|
|
|
|
|
|
|
|
switch (type)
|
2022-07-06 23:18:13 +08:00
|
|
|
{
|
|
|
|
|
case SESSION_EVENT_OPENING:
|
2022-07-27 15:51:07 +08:00
|
|
|
plugin_manager_handle_opening_event(plug_mgr, event);
|
|
|
|
|
break;
|
|
|
|
|
case SESSION_EVENT_RAWPKT: /* fall through */
|
|
|
|
|
case SESSION_EVENT_ORDPKT: /* fall through */
|
|
|
|
|
case SESSION_EVENT_META: /* fall through */
|
|
|
|
|
plugin_manager_handle_data_event(plug_mgr, event);
|
|
|
|
|
break;
|
|
|
|
|
case SESSION_EVENT_CLOSING:
|
|
|
|
|
plugin_manager_handle_closing_event(plug_mgr, event);
|
2022-07-06 23:18:13 +08:00
|
|
|
break;
|
|
|
|
|
default:
|
2022-07-27 15:51:07 +08:00
|
|
|
// TODO log error
|
2022-07-06 23:18:13 +08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|