【新增】实现数据管理能力
This commit is contained in:
115
src/lua_plugin_cfunc.c
Normal file
115
src/lua_plugin_cfunc.c
Normal file
@@ -0,0 +1,115 @@
|
||||
/*************************************************************************
|
||||
> File Name: lua_plugin_cfunc.c
|
||||
> Author:
|
||||
> Created Time: 2024-08
|
||||
> Encoding : UTF-8
|
||||
************************************************************************/
|
||||
|
||||
/*************************************************************************
|
||||
* version
|
||||
* [ v0.1 ]
|
||||
* 08-06
|
||||
* 1. 实现函数
|
||||
* void *lpm_ctx_new_func;
|
||||
* void lpm_ctx_free_func;
|
||||
************************************************************************/
|
||||
#include "lua_plugin_manage_internal.h"
|
||||
|
||||
/*
|
||||
* Function: lpm_ctx_new_func
|
||||
* Input: | struct session * | sess | 会话信息
|
||||
* | void * | plugin_env | 插件运行环境
|
||||
* Output:
|
||||
* Return: | NULL | 运行函数错误
|
||||
* | pointer | 运行插件上的ctx_new函数成功, 返回context
|
||||
* Description: 与C插件管理器保持一致的ctx_new_func
|
||||
*/
|
||||
void *lpm_ctx_new_func(
|
||||
struct session *sess,
|
||||
void *plugin_env)
|
||||
{
|
||||
if (__glibc_unlikely(!sess || !plugin_env))
|
||||
return NULL;
|
||||
struct lua_plugin_env *env = (struct lua_plugin_env *)plugin_env;
|
||||
|
||||
/* 获取插件ID并找到该插件 */
|
||||
// int plugin_id = session_get_pluginid(sess);
|
||||
int plugin_id = 1;
|
||||
struct lua_session_plugin *plugin = NULL;
|
||||
while ((plugin = utarray_next(env->plugin_env_plugin_array, plugin)))
|
||||
{
|
||||
if (plugin->plugin_id == plugin_id)
|
||||
break;
|
||||
}
|
||||
if (!plugin || plugin->plugin_id != plugin_id)
|
||||
/* 未找到该插件 */
|
||||
return NULL;
|
||||
|
||||
struct lua_context *new_context = lua_context_new(env->plugin_env_state);
|
||||
if (__glibc_unlikely(!new_context))
|
||||
/* 创建新的context失败 */
|
||||
return NULL;
|
||||
|
||||
struct lua_cdata param[3] = {0};
|
||||
param[0].cdata_type = DATATYPE_POINTER;
|
||||
param[0].cdata_pointer = sess;
|
||||
param[1].cdata_type = DATATYPE_TABLE;
|
||||
param[1].cdata_table = env->plugin_env_ref_id;
|
||||
param[2].cdata_type = DATATYPE_CONTEXT;
|
||||
param[2].cdata_context = new_context;
|
||||
|
||||
if (script_execute(&plugin->plugin_ctx_new_script, 3, param, 0, NULL))
|
||||
{
|
||||
/* 脚本执行失败 */
|
||||
free(new_context);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (void *)new_context;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function: lpm_ctx_free_func
|
||||
* Input: | struct session * | sess | 会话信息
|
||||
* | void * | sess_ctx | 会话中的私有数据
|
||||
* | void * | plugin_env | 插件运行环境
|
||||
* Output:
|
||||
* Return:
|
||||
* Description: 与C插件管理器保持一致的ctx_free_func
|
||||
*/
|
||||
void lpm_ctx_free_func(
|
||||
struct session *sess,
|
||||
void *sess_ctx,
|
||||
void *plugin_env)
|
||||
{
|
||||
if (__glibc_unlikely(!sess || !sess_ctx || !plugin_env))
|
||||
return;
|
||||
struct lua_context *context = (struct lua_context *)sess_ctx;
|
||||
struct lua_plugin_env *env = (struct lua_plugin_env *)plugin_env;
|
||||
|
||||
/* 获取插件ID并找到该插件 */
|
||||
// int plugin_id = session_get_pluginid(sess);
|
||||
int plugin_id = 1;
|
||||
struct lua_session_plugin *plugin = NULL;
|
||||
while ((plugin = utarray_next(env->plugin_env_plugin_array, plugin)))
|
||||
{
|
||||
if (plugin->plugin_id == plugin_id)
|
||||
break;
|
||||
}
|
||||
if (!plugin || plugin->plugin_id != plugin_id)
|
||||
/* 未找到该插件 */
|
||||
return;
|
||||
|
||||
struct lua_cdata param[3] = {0};
|
||||
param[0].cdata_type = DATATYPE_POINTER;
|
||||
param[0].cdata_pointer = sess;
|
||||
param[1].cdata_type = DATATYPE_CONTEXT;
|
||||
param[1].cdata_context = context;
|
||||
param[2].cdata_type = DATATYPE_TABLE;
|
||||
param[2].cdata_table = env->plugin_env_ref_id;
|
||||
|
||||
script_execute(&plugin->plugin_ctx_free_script, 3, param, 0, NULL);
|
||||
lua_context_free(context);
|
||||
|
||||
return;
|
||||
}
|
||||
Reference in New Issue
Block a user