2
0
Эх сурвалжийг харах

sl(k): implement ser-like SL api

- SER modules dependent of sl module can work now with k-sl
- exported sl_send_reply() ser function takes the reason as charz while k version is str
- conflict was resolved since SER does the export via sl_api_t structure
  and bind_sl() function, kamailio does via sl_binds structure and
  load_sl() function - both are now included in k-sl module
Daniel-Constantin Mierla 16 жил өмнө
parent
commit
91c1f6c8b9

+ 22 - 2
modules_k/sl/sl.c

@@ -62,6 +62,7 @@
 
 #include "sl_funcs.h"
 #include "sl_api.h"
+#include "sl.h"
 #include "sl_cb.h"
 
 MODULE_VERSION
@@ -70,6 +71,7 @@ MODULE_VERSION
 static int w_sl_send_reply(struct sip_msg* msg, char* str1, char* str2);
 static int w_send_reply(struct sip_msg* msg, char* str1, char* str2);
 static int w_sl_reply_error(struct sip_msg* msg, char* str1, char* str2);
+static int bind_sl(sl_api_t* api);
 static int fixup_sl_send_reply(void** param, int param_no);
 static int mod_init(void);
 static void mod_destroy(void);
@@ -105,6 +107,8 @@ static cmd_export_t cmds[]={
 	{"load_sl",        (cmd_function)load_sl,
 		0,  0, 0,
 		0},
+	{"bind_sl",        (cmd_function)bind_sl,          0, 0, 0, 0},
+	{"api_sl_reply",   (cmd_function)sl_send_reply_sz, 2, 0, 0, 0},
 	{0,0,0,0,0,0}
 };
 
@@ -378,9 +382,25 @@ int load_sl( struct sl_binds *slb)
 	slb->reply      = sl_send_reply;
 	slb->reply_dlg  = sl_send_reply_dlg;
 	slb->sl_get_reply_totag = sl_get_reply_totag;
-	slb->send_reply = send_reply;
-	slb->get_reply_totag = get_reply_totag;
+	slb->send_reply         = send_reply;
+	slb->get_reply_totag    = get_reply_totag;
 
 
 	return 1;
 }
+
+static int bind_sl(sl_api_t* api)
+{
+	if (!api) {
+		ERR("Invalid parameter value\n");
+		return -1;
+	}
+
+	api->reply = (sl_send_reply_f)find_export("api_sl_reply", 2, 0);
+	if (api->reply == 0) {
+		ERR("Can't bind sl_reply functionn");
+		return -1;
+	}
+
+	return 0;
+}

+ 3 - 18
modules_k/sl/sl.h

@@ -31,24 +31,9 @@
  * - Module: \ref sl
  */
 
-#ifndef _SL_H_
-#define _SL_H_
-
-#include "../../lib/kcore/statistics.h"
-
-/* module parameter */
-extern int sl_enable_stats;
-
-/* statistic variables */
-extern stat_var *tx_1xx_rpls;
-extern stat_var *tx_2xx_rpls;
-extern stat_var *tx_3xx_rpls;
-extern stat_var *tx_4xx_rpls;
-extern stat_var *tx_5xx_rpls;
-extern stat_var *tx_6xx_rpls;
-extern stat_var *sent_rpls;
-extern stat_var *sent_err_rpls;
-extern stat_var *rcv_acks;
+#ifndef _SL_K_H_
+#define _SL_K_H_
 
+#include "../../modules_s/sl/sl.h"
 
 #endif

+ 2 - 2
modules_k/sl/sl_api.h

@@ -36,13 +36,13 @@
 typedef int (*get_reply_totag_f)(struct sip_msg *msg, str *tag);
 typedef int (*send_reply_f)(struct sip_msg *msg, int code, str *reason);
 typedef int (*sl_get_reply_totag_f)(struct sip_msg *msg, str *tag);
-typedef int (*sl_send_reply_f)(struct sip_msg *msg, int code, str *reason);
+typedef int (*sl_send_reply_str_f)(struct sip_msg *msg, int code, str *reason);
 typedef int (*sl_send_reply_dlg_f)(struct sip_msg *msg, int code, str *reason,
 		str *tag);
 
 /*! SL API bindings */
 struct sl_binds {
-	sl_send_reply_f reply;
+	sl_send_reply_str_f reply;
 	sl_send_reply_dlg_f reply_dlg;
 	sl_get_reply_totag_f sl_get_reply_totag;
 	send_reply_f send_reply;

+ 26 - 0
modules_k/sl/sl_funcs.c

@@ -67,6 +67,23 @@
 #include "sl_cb.h"
 #include "../../usr_avp.h"
 #include <string.h>
+#include "../../lib/kcore/statistics.h"
+
+/* module parameter */
+extern int sl_enable_stats;
+
+/* statistic variables */
+extern stat_var *tx_1xx_rpls;
+extern stat_var *tx_2xx_rpls;
+extern stat_var *tx_3xx_rpls;
+extern stat_var *tx_4xx_rpls;
+extern stat_var *tx_5xx_rpls;
+extern stat_var *tx_6xx_rpls;
+extern stat_var *sent_rpls;
+extern stat_var *sent_err_rpls;
+extern stat_var *rcv_acks;
+
+
 /* to-tag including pre-calculated and fixed part */
 static char           sl_tag_buf[TOTAG_VALUE_LEN];
 static str            sl_tag = {sl_tag_buf,TOTAG_VALUE_LEN};
@@ -256,6 +273,15 @@ int sl_send_reply(struct sip_msg *msg ,int code, str *text)
 	return sl_send_reply_helper(msg, code, text, 0);
 }
 
+/*! small wrapper around sl_send_reply_helper */
+int sl_send_reply_sz(struct sip_msg *msg ,int code, char *text)
+{
+	str r;
+	r.s = text;
+	r.len = strlen(text);
+	return sl_send_reply_helper(msg, code, &r, 0);
+}
+
 
 /*! small wrapper around sl_send_reply_helper */
 int sl_send_reply_dlg(struct sip_msg *msg ,int code, str *text, str *tag)

+ 1 - 0
modules_k/sl/sl_funcs.h

@@ -39,6 +39,7 @@
 int sl_startup(void);
 int sl_shutdown(void);
 int sl_send_reply( struct sip_msg *msg, int code, str *reason);
+int sl_send_reply_sz( struct sip_msg *msg, int code, char *reason);
 int sl_send_reply_dlg( struct sip_msg *msg, int code, str *reason, str *tag);
 int sl_filter_ACK( struct sip_msg *msg, unsigned int flags, void *foo );
 int sl_reply_error( struct sip_msg *msg );