浏览代码

modules_k/tmx: Added C API to enable other modules to bind to tmx

- Exported t_suspend() for use in app_lua
Peter Dunkley 13 年之前
父节点
当前提交
242bbdd184
共有 2 个文件被更改,包括 42 次插入0 次删除
  1. 28 0
      modules_k/tmx/api.h
  2. 14 0
      modules_k/tmx/tmx_mod.c

+ 28 - 0
modules_k/tmx/api.h

@@ -0,0 +1,28 @@
+#ifndef _TMX_API_H_
+#define _TMX_API_H_
+
+typedef int (*tmx_t_suspend_f)(struct sip_msg*, char*, char*);
+typedef struct tmx_api {
+	tmx_t_suspend_f t_suspend;
+} tmx_api_t;
+
+typedef int (*bind_tmx_f)(tmx_api_t* api);
+
+static inline int load_tmx_api(tmx_api_t *api)
+{
+	bind_tmx_f bindtmx;
+
+	bindtmx = (bind_tmx_f)find_export("bind_tmx", 1, 0);
+	if(bindtmx == 0) {
+		LM_ERR("cannot find bind_tmx\n");
+		return -1;
+	}
+	if(bindtmx(api)<0)
+	{
+		LM_ERR("cannot bind tmx api\n");
+		return -1;
+	}
+	return 0;
+}
+
+#endif

+ 14 - 0
modules_k/tmx/tmx_mod.c

@@ -33,6 +33,7 @@
 
 #include "t_var.h"
 #include "t_mi.h"
+#include "api.h"
 
 MODULE_VERSION
 
@@ -63,6 +64,8 @@ static int w_t_suspend(struct sip_msg* msg, char*, char*);
 static int w_t_continue(struct sip_msg* msg, char *idx, char *lbl, char *rtn);
 static int fixup_t_continue(void** param, int param_no);
 
+static int bind_tmx(tmx_api_t* api);
+
 /* statistic variables */
 stat_var *tm_rcv_rpls;
 stat_var *tm_rld_rpls;
@@ -158,6 +161,8 @@ static cmd_export_t cmds[]={
 			0, ANY_ROUTE  },
 	{"t_continue", (cmd_function)w_t_continue,     3,
 		fixup_t_continue, 0, ANY_ROUTE },
+	{"bind_tmx", (cmd_function)bind_tmx, 1,
+		0, 0, ANY_ROUTE },
 	{0,0,0,0,0,0}
 };
 
@@ -559,6 +564,15 @@ static int fixup_t_continue(void** param, int param_no)
 	return 0;
 }
 
+static int bind_tmx(tmx_api_t* api)
+{
+	if (!api)
+		return -1;
+
+	api->t_suspend = w_t_suspend;
+	return 0;
+}
+
 #ifdef STATISTICS
 
 /*** tm stats ***/