[sr-dev] git:master: app_lua: exported cfgutils api to lua

Daniel-Constantin Mierla miconda at gmail.com
Mon Feb 27 21:38:33 CET 2012


Module: sip-router
Branch: master
Commit: 3fd1b776a6e15d49f595d3b2a8eaffc97a963f12
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=3fd1b776a6e15d49f595d3b2a8eaffc97a963f12

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Sun Feb 26 12:25:12 2012 +0100

app_lua: exported cfgutils api to lua

---

 modules/app_lua/app_lua_exp.c |   84 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/modules/app_lua/app_lua_exp.c b/modules/app_lua/app_lua_exp.c
index 70dc11d..74d4f66 100644
--- a/modules/app_lua/app_lua_exp.c
+++ b/modules/app_lua/app_lua_exp.c
@@ -52,6 +52,7 @@
 #include "../../modules_k/msilo/api.h"
 #include "../../modules_k/uac/api.h"
 #include "../../modules/sanity/api.h"
+#include "../../modules_k/cfgutils/api.h"
 
 #include "app_lua_api.h"
 
@@ -76,6 +77,7 @@
 #define SR_LUA_EXP_MOD_MSILO      (1<<18)
 #define SR_LUA_EXP_MOD_UAC        (1<<19)
 #define SR_LUA_EXP_MOD_SANITY     (1<<20)
+#define SR_LUA_EXP_MOD_CFGUTILS   (1<<21)
 
 /**
  *
@@ -188,6 +190,11 @@ static uac_api_t _lua_uacb;
  */
 static sanity_api_t _lua_sanityb;
 
+/**
+ * cfgutils
+ */
+static cfgutils_api_t _lua_cfgutilsb;
+
 
 /**
  *
@@ -2256,6 +2263,68 @@ static const luaL_reg _sr_sanity_Map [] = {
 /**
  *
  */
+static int lua_sr_cfgutils_lock(lua_State *L)
+{
+	int ret;
+	str lkey;
+
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_CFGUTILS))
+	{
+		LM_WARN("weird: cfgutils function executed but module not registered\n");
+		return app_lua_return_error(L);
+	}
+	if(lua_gettop(L)!=1)
+	{
+		LM_WARN("invalid number of parameters from Lua\n");
+		return app_lua_return_error(L);
+	}
+	lkey.s = (char*)lua_tostring(L, -1);
+	lkey.len = strlen(lkey.s);
+	ret = _lua_cfgutilsb.mlock(&lkey);
+
+	return app_lua_return_int(L, ret);
+}
+
+
+/**
+ *
+ */
+static int lua_sr_cfgutils_unlock(lua_State *L)
+{
+	int ret;
+	str lkey;
+
+	if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_CFGUTILS))
+	{
+		LM_WARN("weird: cfgutils function executed but module not registered\n");
+		return app_lua_return_error(L);
+	}
+	if(lua_gettop(L)!=1)
+	{
+		LM_WARN("invalid number of parameters from Lua\n");
+		return app_lua_return_error(L);
+	}
+	lkey.s = (char*)lua_tostring(L, -1);
+	lkey.len = strlen(lkey.s);
+	ret = _lua_cfgutilsb.munlock(&lkey);
+
+	return app_lua_return_int(L, ret);
+}
+
+
+/**
+ *
+ */
+static const luaL_reg _sr_cfgutils_Map [] = {
+	{"lock",      lua_sr_cfgutils_lock},
+	{"unlock",    lua_sr_cfgutils_unlock},
+	{NULL, NULL}
+};
+
+
+/**
+ *
+ */
 int lua_sr_exp_init_mod(void)
 {
 	if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SL)
@@ -2474,6 +2543,16 @@ int lua_sr_exp_init_mod(void)
 		}
 		LM_DBG("loaded sanity api\n");
 	}
+	if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_CFGUTILS)
+	{
+		/* bind the CFGUTILS API */
+		if (cfgutils_load_api(&_lua_cfgutilsb) < 0)
+		{
+			LM_ERR("cannot bind to CFGUTILS API\n");
+			return -1;
+		}
+		LM_DBG("loaded cfgutils api\n");
+	}
 	return 0;
 }
 
@@ -2550,6 +2629,9 @@ int lua_sr_exp_register_mod(char *mname)
 	} else 	if(len==6 && strcmp(mname, "sanity")==0) {
 		_sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_SANITY;
 		return 0;
+	} else 	if(len==8 && strcmp(mname, "cfgutils")==0) {
+		_sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_CFGUTILS;
+		return 0;
 	}
 
 	return -1;
@@ -2602,5 +2684,7 @@ void lua_sr_exp_openlibs(lua_State *L)
 		luaL_openlib(L, "sr.uac", _sr_uac_Map,                0);
 	if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SANITY)
 		luaL_openlib(L, "sr.sanity", _sr_sanity_Map,          0);
+	if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_CFGUTILS)
+		luaL_openlib(L, "sr.cfgutils", _sr_cfgutils_Map,      0);
 }
 




More information about the sr-dev mailing list