Browse code

kemix: exported get_conid() function to retrieve tcp connection id

- returns -1 if not available

Daniel-Constantin Mierla authored on 24/02/2020 08:30:31
Showing 1 changed files
... ...
@@ -32,6 +32,7 @@
32 32
 #include "../../core/parser/parse_from.h"
33 33
 #include "../../core/parser/parse_to.h"
34 34
 #include "../../core/parser/digest/digest.h"
35
+#include "../../core/tcp_conn.h"
35 36
 
36 37
 MODULE_VERSION
37 38
 
... ...
@@ -822,6 +823,25 @@ static sr_kemi_xval_t* ki_kx_get_callid(sip_msg_t *msg)
822 823
 	return &_sr_kemi_kx_xval;
823 824
 }
824 825
 
826
+/**
827
+ *
828
+ */
829
+static int ki_kx_get_conid(sip_msg_t *msg)
830
+{
831
+	tcp_connection_t *con;
832
+	int conid;
833
+
834
+	if (msg == NULL)
835
+		return -1;
836
+
837
+	if ((con = tcpconn_get(msg->rcv.proto_reserved1, 0, 0, 0, 0)) == NULL)
838
+		return -1;
839
+
840
+	conid = con->id;
841
+	tcpconn_put(con);
842
+
843
+	return conid;
844
+}
825 845
 
826 846
 /**
827 847
  *
... ...
@@ -1058,6 +1078,11 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
1058 1078
 		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1059 1079
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1060 1080
 	},
1081
+	{ str_init("kx"), str_init("get_conid"),
1082
+		SR_KEMIP_INT, ki_kx_get_conid,
1083
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
1084
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
1085
+	},
1061 1086
 
1062 1087
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
1063 1088
 };