Module: kamailio
Branch: master
Commit: a993f1538918c6c31c5da031e1d903250c4a9048
URL:
https://github.com/kamailio/kamailio/commit/a993f1538918c6c31c5da031e1d9032…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-12-17T08:45:11+01:00
kemix: added KSR.kx.get_rcvaddr_sock() - return local received address in socket format
---
Modified: src/modules/kemix/kemix_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/a993f1538918c6c31c5da031e1d9032…
Patch:
https://github.com/kamailio/kamailio/commit/a993f1538918c6c31c5da031e1d9032…
---
diff --git a/src/modules/kemix/kemix_mod.c b/src/modules/kemix/kemix_mod.c
index 3fb079349a..80d7807740 100644
--- a/src/modules/kemix/kemix_mod.c
+++ b/src/modules/kemix/kemix_mod.c
@@ -585,6 +585,38 @@ static sr_kemi_xval_t* ki_kx_get_rcv_sock_name(sip_msg_t *msg)
return &_sr_kemi_kx_xval;
}
+/**
+ *
+ */
+static sr_kemi_xval_t* ki_kx_get_rcvaddr_sock(sip_msg_t *msg)
+{
+ if(msg==NULL) {
+ sr_kemi_xval_null(&_sr_kemi_kx_xval, SR_KEMI_XVAL_NULL_EMPTY);
+ return &_sr_kemi_kx_xval;
+
+ }
+
+ if(msg->rcv.bind_address==NULL || msg->rcv.bind_address->sock_str.s==NULL) {
+ sr_kemi_xval_null(&_sr_kemi_kx_xval, SR_KEMI_XVAL_NULL_EMPTY);
+ return &_sr_kemi_kx_xval;
+ }
+
+ if (msg->rcv.bind_address->sock_str.len + 1 >= pv_get_buffer_size()) {
+ LM_ERR("local buffer size exceeded\n");
+ sr_kemi_xval_null(&_sr_kemi_kx_xval, SR_KEMI_XVAL_NULL_EMPTY);
+ return &_sr_kemi_kx_xval;
+ }
+
+ _sr_kemi_kx_xval.v.s.s = pv_get_buffer();
+ strncpy(_sr_kemi_kx_xval.v.s.s, msg->rcv.bind_address->sock_str.s,
+ msg->rcv.bind_address->sock_str.len);
+ _sr_kemi_kx_xval.v.s.len = msg->rcv.bind_address->sock_str.len;
+ _sr_kemi_kx_xval.v.s.s[_sr_kemi_kx_xval.v.s.len] = '\0';
+
+ _sr_kemi_kx_xval.vtype = SR_KEMIP_STR;
+ return &_sr_kemi_kx_xval;
+}
+
/**
*
*/
@@ -1473,6 +1505,11 @@ static sr_kemi_t sr_kemi_kx_exports[] = {
{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
+ { str_init("kx"), str_init("get_rcvaddr_sock"),
+ SR_KEMIP_XVAL, ki_kx_get_rcvaddr_sock,
+ { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
{ str_init("kx"), str_init("get_proto"),
SR_KEMIP_XVAL, ki_kx_get_proto,
{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,