[sr-dev] git:master: modules/app_lua, modules/sdpops: Exported sdpops:sdp_with_media () to app_lua

Peter Dunkley peter.dunkley at crocodile-rcs.com
Tue Aug 16 15:41:52 CEST 2011


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

Author: pd <peter.dunkley at crocodile-rcs.com>
Committer: pd <peter.dunkley at crocodile-rcs.com>
Date:   Tue Aug 16 14:39:41 2011 +0100

modules/app_lua, modules/sdpops: Exported sdpops:sdp_with_media() to app_lua

- Also fixed a bug relating to logging levels within app_lua (sr.log())
- Feature added by Hugh Waite at Crocodile RCS

---

 modules/app_lua/Makefile      |    1 +
 modules/app_lua/app_lua_exp.c |   59 +++++++++++++++++++++++++++++++++++++---
 modules/app_lua/app_lua_sr.c  |    6 +++-
 modules/sdpops/api.h          |   26 ++++++++++++++++++
 modules/sdpops/sdpops_mod.c   |   16 +++++++++-
 5 files changed, 100 insertions(+), 8 deletions(-)

diff --git a/modules/app_lua/Makefile b/modules/app_lua/Makefile
index 47d6072..e4dbc69 100644
--- a/modules/app_lua/Makefile
+++ b/modules/app_lua/Makefile
@@ -46,5 +46,6 @@ DEFS+=-DOPENSER_MOD_INTERFACE
 
 SERLIBPATH=../../lib
 SER_LIBS+=$(SERLIBPATH)/kcore/kcore
+LIBS+=-lm
 
 include ../../Makefile.modules
diff --git a/modules/app_lua/app_lua_exp.c b/modules/app_lua/app_lua_exp.c
index c998b7e..0893089 100644
--- a/modules/app_lua/app_lua_exp.c
+++ b/modules/app_lua/app_lua_exp.c
@@ -41,6 +41,7 @@
 #include "../../modules_k/registrar/api.h"
 #include "../../modules_k/dispatcher/api.h"
 #include "../../modules/xhttp/api.h"
+#include "../../modules/sdpops/api.h"
 
 #include "app_lua_api.h"
 
@@ -54,6 +55,7 @@
 #define SR_LUA_EXP_MOD_REGISTRAR  (1<<7)
 #define SR_LUA_EXP_MOD_DISPATCHER (1<<8)
 #define SR_LUA_EXP_MOD_XHTTP      (1<<9)
+#define SR_LUA_EXP_MOD_SDPOPS     (1<<10)
 
 /**
  *
@@ -112,6 +114,11 @@ static tm_xapi_t _lua_xtmb;
 static xhttp_api_t _lua_xhttpb;
 
 /**
+ * sdpops
+ */
+static sdpops_api_t _lua_sdpopsb;
+
+/**
  *
  */
 static int lua_sr_sl_send_reply (lua_State *L)
@@ -1224,6 +1231,17 @@ static int lua_sr_dispatcher_is_from(lua_State *L)
 	return app_lua_return_int(L, ret);
 }
 
+/**
+ *
+ */
+static const luaL_reg _sr_dispatcher_Map [] = {
+	{"select",      lua_sr_dispatcher_select},
+	{"next",        lua_sr_dispatcher_next},
+	{"mark",        lua_sr_dispatcher_mark},
+	{"is_from",     lua_sr_dispatcher_is_from},
+	{NULL, NULL}
+};
+
 
 /**
  *
@@ -1276,18 +1294,34 @@ static const luaL_reg _sr_xhttp_Map [] = {
 	{NULL, NULL}
 };
 
+/**
+ *
+ */
+static int lua_sr_sdpops_with_media(lua_State *L)
+{
+	int ret;
+	str media;
+	sr_lua_env_t *env_L;
+
+	env_L = sr_lua_env_get();
+
+	media.s = (char*)lua_tostring(L, -1);
+	media.len = strlen(media.s);
+
+	ret = _lua_sdpopsb.sdp_with_media(env_L->msg, &media);
+
+	return app_lua_return_int(L, ret);
+}
 
 /**
  *
  */
-static const luaL_reg _sr_dispatcher_Map [] = {
-	{"select",      lua_sr_dispatcher_select},
-	{"next",        lua_sr_dispatcher_next},
-	{"mark",        lua_sr_dispatcher_mark},
-	{"is_from",     lua_sr_dispatcher_is_from},
+static const luaL_reg _sr_sdpops_Map [] = {
+	{"sdp_with_media",       lua_sr_sdpops_with_media},
 	{NULL, NULL}
 };
 
+
 /**
  *
  */
@@ -1399,6 +1433,16 @@ int lua_sr_exp_init_mod(void)
 		}
 		LM_DBG("loaded xhttp api\n");
 	}
+	if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SDPOPS)
+	{
+		/* bind the SDPOPS API */
+		if (sdpops_load_api(&_lua_sdpopsb) < 0)
+		{
+			LM_ERR("cannot bind to SDPOPS API\n");
+			return -1;
+		}
+		LM_DBG("loaded sdpops api\n");
+	}
 	return 0;
 }
 
@@ -1442,6 +1486,9 @@ int lua_sr_exp_register_mod(char *mname)
 	} else 	if(len==5 && strcmp(mname, "xhttp")==0) {
 		_sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_XHTTP;
 		return 0;
+	} else 	if(len==6 && strcmp(mname, "sdpops")==0) {
+		_sr_lua_exp_reg_mods |= SR_LUA_EXP_MOD_SDPOPS;
+		return 0;
 	}
 
 	return -1;
@@ -1472,5 +1519,7 @@ void lua_sr_exp_openlibs(lua_State *L)
 		luaL_openlib(L, "sr.dispatcher", _sr_dispatcher_Map,  0);
 	if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_XHTTP)
 		luaL_openlib(L, "sr.xhttp",      _sr_xhttp_Map,       0);
+	if(_sr_lua_exp_reg_mods&SR_LUA_EXP_MOD_SDPOPS)
+		luaL_openlib(L, "sr.sdpops",     _sr_sdpops_Map,      0);
 }
 
diff --git a/modules/app_lua/app_lua_sr.c b/modules/app_lua/app_lua_sr.c
index 7a8575a..c5f5bf8 100644
--- a/modules/app_lua/app_lua_sr.c
+++ b/modules/app_lua/app_lua_sr.c
@@ -91,7 +91,11 @@ static int lua_sr_log (lua_State *L)
 		{
 			LM_ERR("%s", txt);
 		} else {
-			if(strcasecmp(level, "warn")==0) {
+			if(strcasecmp(level, "dbg")==0) {
+				LM_DBG("%s", txt);
+			} else if(strcasecmp(level, "info")==0) {
+				LM_INFO("%s", txt);
+			} else if(strcasecmp(level, "warn")==0) {
 				LM_WARN("%s", txt);
 			} else if(strcasecmp(level, "crit")==0) {
 				LM_CRIT("%s", txt);
diff --git a/modules/sdpops/api.h b/modules/sdpops/api.h
new file mode 100644
index 0000000..215dcce
--- /dev/null
+++ b/modules/sdpops/api.h
@@ -0,0 +1,26 @@
+#ifndef SDPOPS_API_H
+#define SDPOPS_API_H
+#include "../../str.h"
+
+typedef int (*sdp_with_media_t)(struct sip_msg*, str*);
+
+typedef struct sdpops_binds {
+	sdp_with_media_t sdp_with_media;
+} sdpops_api_t;
+
+typedef int (*bind_sdpops_f)(sdpops_api_t*);
+
+int bind_sdpops(struct sdpops_binds*);
+
+inline static int sdpops_load_api(sdpops_api_t *sob)
+{
+	bind_sdpops_f bind_sdpops_exports;
+	if (!(bind_sdpops_exports = (bind_sdpops_f)find_export("bind_sdpops", 0, 0)))
+	{
+		LM_ERR("Failed to import bind_sdpops\n");
+		return -1;
+	}
+	return bind_sdpops_exports(sob);
+}
+
+#endif /*SDPOPS_API_H*/
diff --git a/modules/sdpops/sdpops_mod.c b/modules/sdpops/sdpops_mod.c
index 7b587e6..1212053 100644
--- a/modules/sdpops/sdpops_mod.c
+++ b/modules/sdpops/sdpops_mod.c
@@ -34,6 +34,7 @@
 #include "../../trim.h"
 #include "../../data_lump.h"
 
+#include "api.h"
 #include "sdpops_data.h"
 
 MODULE_VERSION
@@ -54,7 +55,9 @@ static cmd_export_t cmds[] = {
 		1, fixup_spve_null,  0, ANY_ROUTE},
 	{"sdp_print",                  (cmd_function)w_sdp_print,
 		1, fixup_igp_null,  0, ANY_ROUTE},
-	{0, 0, 0, 0, 0}
+	{"bind_sdpops",                (cmd_function)bind_sdpops,
+		0, 0, 0, 0},
+	{0, 0, 0, 0, 0, 0}
 };
 
 static pv_export_t mod_pvs[] = {
@@ -360,7 +363,7 @@ static int sdp_with_media(sip_msg_t *msg, str *media)
 		return -1;
 	}
 
-	LM_ERR("attempting to search for media type: [%.*s]\n",
+	LM_DBG("attempting to search for media type: [%.*s]\n",
 			media->len, media->s);
 
 	sdp = (sdp_info_t*)msg->body;
@@ -437,3 +440,12 @@ static int w_sdp_print(sip_msg_t* msg, char* level, char *bar)
 	print_sdp(sdp, llevel);
 	return 1;
 }
+
+int bind_sdpops(struct sdpops_binds *sob){
+	if (sob == NULL) {
+		LM_WARN("bind_sdpops: Cannot load sdpops API into a NULL pointer\n");
+		return -1;
+	}
+	sob->sdp_with_media = sdp_with_media;
+	return 0;
+}




More information about the sr-dev mailing list