Module: kamailio
Branch: master
Commit: 38bf1ef014ce39454a602a34045a3eb247c18201
URL:
https://github.com/kamailio/kamailio/commit/38bf1ef014ce39454a602a34045a3eb…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2015-04-18T11:32:33+02:00
app_lua: exported ndb_mongodb cmd to lua
---
Modified: modules/app_lua/app_lua_exp.c
---
Diff:
https://github.com/kamailio/kamailio/commit/38bf1ef014ce39454a602a34045a3eb…
Patch:
https://github.com/kamailio/kamailio/commit/38bf1ef014ce39454a602a34045a3eb…
---
diff --git a/modules/app_lua/app_lua_exp.c b/modules/app_lua/app_lua_exp.c
index d2d0188..540d5bf 100644
--- a/modules/app_lua/app_lua_exp.c
+++ b/modules/app_lua/app_lua_exp.c
@@ -55,6 +55,7 @@
#include "../../modules/cfgutils/api.h"
#include "../../modules/tmx/api.h"
#include "../../modules/mqueue/api.h"
+#include "../../modules/ndb_mongodb/api.h"
#include "app_lua_api.h"
@@ -82,6 +83,7 @@
#define SR_LUA_EXP_MOD_CFGUTILS (1<<21)
#define SR_LUA_EXP_MOD_TMX (1<<22)
#define SR_LUA_EXP_MOD_MQUEUE (1<<23)
+#define SR_LUA_EXP_MOD_NDB_MONGODB (1<<24)
/**
*
@@ -210,6 +212,12 @@ static tmx_api_t _lua_tmxb;
static mq_api_t _lua_mqb;
/**
+ * mqueue
+ */
+static ndb_mongodb_api_t _lua_ndb_mongodbb;
+
+
+/**
*
*/
static int lua_sr_sl_send_reply (lua_State *L)
@@ -2604,6 +2612,48 @@ static const luaL_Reg _sr_mqueue_Map [] = {
/**
*
*/
+static int lua_sr_ndb_mongodb_cmd(lua_State *L)
+{
+ int ret;
+ str param[6];
+
+ if(!(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_NDB_MONGODB))
+ {
+ LM_WARN("weird: ndb_mongodb function executed but module not registered\n");
+ return app_lua_return_error(L);
+ }
+ if(lua_gettop(L)!=5)
+ {
+ LM_WARN("invalid number of parameters from Lua\n");
+ return app_lua_return_error(L);
+ }
+
+ param[0].s = (char *) lua_tostring(L, -5);
+ param[0].len = strlen(param[0].s);
+ param[1].s = (char *) lua_tostring(L, -4);
+ param[1].len = strlen(param[1].s);
+ param[2].s = (char *) lua_tostring(L, -3);
+ param[2].len = strlen(param[2].s);
+ param[3].s = (char *) lua_tostring(L, -2);
+ param[3].len = strlen(param[3].s);
+ param[4].s = (char *) lua_tostring(L, -1);
+ param[4].len = strlen(param[4].s);
+
+ ret = _lua_ndb_mongodbb.cmd(¶m[0], ¶m[1], ¶m[2], ¶m[3],
¶m[4]);
+ return app_lua_return_int(L, ret);
+}
+
+/**
+ *
+ */
+static const luaL_Reg _sr_ndb_mongodb_Map [] = {
+ {"cmd", lua_sr_ndb_mongodb_cmd},
+ {NULL, NULL}
+};
+
+/**
+ *
+ */
int lua_sr_exp_init_mod(void)
{
if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SL)
@@ -2852,6 +2902,17 @@ int lua_sr_exp_init_mod(void)
}
LM_DBG("loaded mqueue api\n");
}
+ if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_NDB_MONGODB)
+ {
+ /* bind the NDB_MONGODB API */
+ if (ndb_mongodb_load_api(&_lua_ndb_mongodbb) < 0)
+ {
+ LM_ERR("cannot bind to NDB_MONGODB API\n");
+ return -1;
+ }
+ LM_DBG("loaded ndb_mongodb api\n");
+ }
+
return 0;
}
@@ -2937,6 +2998,9 @@ int lua_sr_exp_register_mod(char *mname)
} else if(len==6 && strcmp(mname, "mqueue")==0) {
_sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_MQUEUE;
return 0;
+ } else if(len==11 && strcmp(mname, "ndb_mongodb")==0) {
+ _sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_NDB_MONGODB;
+ return 0;
}
return -1;
@@ -2995,5 +3059,7 @@ void lua_sr_exp_openlibs(lua_State *L)
luaL_openlib(L, "sr.tmx", _sr_tmx_Map, 0);
if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_MQUEUE)
luaL_openlib(L, "sr.mq", _sr_mqueue_Map, 0);
+ if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_NDB_MONGODB)
+ luaL_openlib(L, "sr.ndb_mongodb", _sr_ndb_mongodb_Map, 0);
}