summaryrefslogtreecommitdiff
path: root/src/lua_plugin_binding.c
diff options
context:
space:
mode:
authorniubinghui <[email protected]>2024-08-07 16:56:26 +0800
committerniubinghui <[email protected]>2024-08-07 16:56:26 +0800
commitfb9df743998c7eb20cd9803b2fcbb52d0c35dbb1 (patch)
treee446fbb35c19311f260e13980a1eab316d72ce92 /src/lua_plugin_binding.c
parent09c1a5488b0aae24e456880df81cdce22956bbe6 (diff)
【新增】增加一些和session相关的注册函数
Diffstat (limited to 'src/lua_plugin_binding.c')
-rw-r--r--src/lua_plugin_binding.c130
1 files changed, 118 insertions, 12 deletions
diff --git a/src/lua_plugin_binding.c b/src/lua_plugin_binding.c
index d8a51db..2444232 100644
--- a/src/lua_plugin_binding.c
+++ b/src/lua_plugin_binding.c
@@ -16,7 +16,7 @@
* int lua_cbinding_data_remove;
* int lua_cbinding_functions;
* int lua_cbinding_datas;
- * int lua_plugin_manage_session_regist;
+ * int lua_plugin_manage_regist;
* ** 注册函数lua_plugin_manage_session_regist还需要补充
************************************************************************/
#include "lua_plugin_manage_internal.h"
@@ -25,11 +25,19 @@
#include <string.h>
/* 需要注册至lua中供lua调用的所有函数原型 */
-int lua_plugin_manage_session_regist(lua_State * state);
+int lua_plugin_manage_regist(lua_State * state);
+int lua_session_get_id(lua_State * state);
+int lua_session_set_id(lua_State * state);
+int lua_session_get_type(lua_State * state);
+int lua_session_set_type(lua_State * state);
/* 需要注册至状态机中的函数定义在链表中, 会依次完成注册 */
struct lua_binding_function lua_bind_functions[] = {
- {lua_plugin_manage_session_regist, "register", "plugin_manage"},
+ {lua_plugin_manage_regist, "register", "plugin_manage"},
+ {lua_session_get_id, "getid", "session"},
+ {lua_session_set_id, "setid", "session"},
+ {lua_session_get_type, "gettype", "session"},
+ {lua_session_set_type, "settype", "session"},
{NULL, NULL, NULL},
};
@@ -465,14 +473,8 @@ int lua_cbinding_datas(lua_State *state)
return failed_count;
}
-/*
- * Function:
- * Input:
- * Output:
- * Return:
- * Description:
- */
-int lua_plugin_manage_session_regist(lua_State *state)
+/* ***** ***** ***** ***** ***** ***** */
+int lua_plugin_manage_regist(lua_State *state)
{
/* 参数个数检查 */
if (lua_gettop(state) != 4)
@@ -525,7 +527,7 @@ int lua_plugin_manage_session_regist(lua_State *state)
/* 在stellar中注册, 获取注册id */
int plugin_id = stellar_session_plugin_register(st, lpm_ctx_new_func, lpm_ctx_free_func, (void *)plugin_env);
#ifdef LUAPLUGIN_BASIC_UNITTEST
- printf("now regist new plugin, plugin id is %d\n", plugin_id);
+ LOGDEBUG("now regist new plugin, plugin id is %d\n", plugin_id);
#endif
/* 将注册完成的新插件插入到队列中 */
@@ -540,3 +542,107 @@ int lua_plugin_manage_session_regist(lua_State *state)
return 1;
}
+
+int lua_session_get_id(lua_State * state)
+{
+ /* 参数个数检查 */
+ if (lua_gettop(state) != 1)
+ {
+ lua_settop(state, 0);
+ return 0;
+ }
+
+ /* 参数类型检查 */
+ if (lua_type(state, -1) != LUA_TLIGHTUSERDATA )
+ {
+ lua_settop(state, 0);
+ return 0;
+ }
+
+ struct session * sess = (struct session *)lua_topointer(state, -1);
+ if ( !sess ) {
+ lua_settop(state, 0);
+ return 0;
+ }
+ lua_pop(state, 1);
+
+ lua_pushinteger(state, session_get_id(sess));
+ return 1;
+}
+
+int lua_session_set_id(lua_State * state)
+{
+ /* 参数个数检查 */
+ if (lua_gettop(state) != 2)
+ {
+ lua_settop(state, 0);
+ return 0;
+ }
+
+ /* 参数类型检查 */
+ if (lua_type(state, -1) != LUA_TNUMBER || lua_type(state, -2) != LUA_TLIGHTUSERDATA )
+ {
+ lua_settop(state, 0);
+ return 0;
+ }
+
+ int setid = lua_tointeger(state, -1);
+ lua_pop(state, 1);
+ struct session * sess = (struct session *)lua_topointer(state, -1);
+ lua_pop(state, 1);
+
+ session_set_id(sess, setid);
+ return 0;
+}
+
+int lua_session_get_type(lua_State * state)
+{
+ /* 参数个数检查 */
+ if (lua_gettop(state) != 1)
+ {
+ lua_settop(state, 0);
+ return 0;
+ }
+
+ /* 参数类型检查 */
+ if (lua_type(state, -1) != LUA_TLIGHTUSERDATA )
+ {
+ lua_settop(state, 0);
+ return 0;
+ }
+
+ struct session * sess = (struct session *)lua_topointer(state, -1);
+ if ( !sess ) {
+ lua_settop(state, 0);
+ return 0;
+ }
+ lua_pop(state, 1);
+
+ lua_pushinteger(state, session_get_type(sess));
+ return 1;
+}
+
+int lua_session_set_type(lua_State * state)
+{
+ /* 参数个数检查 */
+ if (lua_gettop(state) != 2)
+ {
+ lua_settop(state, 0);
+ return 0;
+ }
+
+ /* 参数类型检查 */
+ if (lua_type(state, -1) != LUA_TNUMBER || lua_type(state, -2) != LUA_TLIGHTUSERDATA )
+ {
+ lua_settop(state, 0);
+ return 0;
+ }
+
+ int settype = lua_tointeger(state, -1);
+ lua_pop(state, 1);
+ struct session * sess = (struct session *)lua_topointer(state, -1);
+ lua_pop(state, 1);
+
+ session_set_id(sess, settype);
+ return 0;
+} \ No newline at end of file