Module: sip-router Branch: master Commit: 9505c4c249c1b39fb1b077fb5b6d72ddae638be3 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=9505c4c2...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Tue Jan 10 11:57:55 2012 +0100
app_lua: export sanity mod api to lua
- patch by noc [at] nelcom-voip.com
---
modules/app_lua/app_lua_exp.c | 63 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 63 insertions(+), 0 deletions(-)
diff --git a/modules/app_lua/app_lua_exp.c b/modules/app_lua/app_lua_exp.c index de676a5..5c4b412 100644 --- a/modules/app_lua/app_lua_exp.c +++ b/modules/app_lua/app_lua_exp.c @@ -51,6 +51,7 @@ #include "../../modules_k/alias_db/api.h" #include "../../modules_k/msilo/api.h" #include "../../modules_k/uac/api.h" +#include "../../modules/sanity/api.h"
#include "app_lua_api.h"
@@ -74,6 +75,7 @@ #define SR_LUA_EXP_MOD_ALIAS_DB (1<<17) #define SR_LUA_EXP_MOD_MSILO (1<<18) #define SR_LUA_EXP_MOD_UAC (1<<19) +#define SR_LUA_EXP_MOD_SANITY (1<<20)
/** * @@ -182,6 +184,12 @@ static msilo_api_t _lua_msilob; static uac_api_t _lua_uacb;
/** + * sanity + */ +static sanity_api_t _lua_sanityb; + + +/** * */ static int lua_sr_sl_send_reply (lua_State *L) @@ -2163,6 +2171,46 @@ static const luaL_reg _sr_uac_Map [] = { {NULL, NULL} };
+ +/** + * + */ +static int lua_sr_sanity_check(lua_State *L) +{ + int msg_checks, uri_checks; + int ret; + sr_lua_env_t *env_L; + + env_L = sr_lua_env_get(); + + if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SANITY)) + { + LM_WARN("weird: sanity function executed but module not registered\n"); + return app_lua_return_error(L); + } + + if(env_L->msg==NULL) + { + LM_WARN("invalid parameters from Lua env\n"); + return app_lua_return_error(L); + } + msg_checks = lua_tointeger(L, -1); + uri_checks = lua_tointeger(L, -2); + + ret = _lua_sanityb.check(env_L->msg, msg_checks, uri_checks); + return app_lua_return_int(L, ret); +} + + +/** + * + */ +static const luaL_reg _sr_sanity_Map [] = { + {"sanity_check", lua_sr_sanity_check}, + {NULL, NULL} +}; + + /** * */ @@ -2374,6 +2422,16 @@ int lua_sr_exp_init_mod(void) } LM_DBG("loaded uac api\n"); } + if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SANITY) + { + /* bind the SANITY API */ + if (sanity_load_api(&_lua_sanityb) < 0) + { + LM_ERR("cannot bind to SANITY API\n"); + return -1; + } + LM_DBG("loaded sanity api\n"); + } return 0; }
@@ -2447,6 +2505,9 @@ int lua_sr_exp_register_mod(char *mname) } else if(len==3 && strcmp(mname, "uac")==0) { _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_UAC; return 0; + } else if(len==6 && strcmp(mname, "sanity")==0) { + _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_SANITY; + return 0; }
return -1; @@ -2497,5 +2558,7 @@ void lua_sr_exp_openlibs(lua_State *L) luaL_openlib(L, "sr.msilo", _sr_msilo_Map, 0); if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_UAC) 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); }