Module: kamailio
Branch: master
Commit: 614852cfdc3f6a18549b8e20ef51af9e64a93eba
URL:
https://github.com/kamailio/kamailio/commit/614852cfdc3f6a18549b8e20ef51af9…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-02-25T16:49:46+01:00
corex: added is_socket_name(sockname) config function
- test if the parameter matches a local socket name
- function exported to kemi
---
Modified: src/modules/corex/corex_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/614852cfdc3f6a18549b8e20ef51af9…
Patch:
https://github.com/kamailio/kamailio/commit/614852cfdc3f6a18549b8e20ef51af9…
---
diff --git a/src/modules/corex/corex_mod.c b/src/modules/corex/corex_mod.c
index 194efcdb8e..ee1ddd37f4 100644
--- a/src/modules/corex/corex_mod.c
+++ b/src/modules/corex/corex_mod.c
@@ -68,6 +68,7 @@ static int w_via_add_srvid(sip_msg_t *msg, char *pflags, char *p2);
static int w_via_add_xavp_params(sip_msg_t *msg, char *pflags, char *p2);
static int w_via_use_xavp_fields(sip_msg_t *msg, char *pflags, char *p2);
static int w_is_faked_msg(sip_msg_t *msg, char *p1, char *p2);
+static int w_is_socket_name(sip_msg_t *msg, char *psockname, char *p2);
static int fixup_file_op(void** param, int param_no);
@@ -146,6 +147,8 @@ static cmd_export_t cmds[]={
0, ANY_ROUTE },
{"is_faked_msg", (cmd_function)w_is_faked_msg, 0, 0,
0, ANY_ROUTE },
+ {"is_socket_name", (cmd_function)w_is_socket_name, 1, fixup_spve_null,
+ 0, ANY_ROUTE },
{0, 0, 0, 0, 0, 0}
};
@@ -1109,6 +1112,46 @@ static int w_is_faked_msg(sip_msg_t *msg, char *p1, char *p2)
return -1;
}
+/**
+ *
+ */
+static int ki_is_socket_name(sip_msg_t *msg, str *sockname)
+{
+ socket_info_t *si = NULL;
+
+ if (sockname==NULL || sockname->len<=0) {
+ LM_ERR("invalid socket name value\n");
+ return -1;
+ }
+
+ si = ksr_get_socket_by_name(sockname);
+ if(si != NULL) {
+ return 1;
+ }
+ return -1;
+}
+
+/**
+ *
+ */
+static int w_is_socket_name(sip_msg_t *msg, char *psockname, char *p2)
+{
+ str sockname;
+ socket_info_t *si = NULL;
+
+ if (fixup_get_svalue(msg, (gparam_t*)psockname, &sockname)!=0
+ || sockname.len<=0) {
+ LM_ERR("cannot get socket name value\n");
+ return -1;
+ }
+
+ si = ksr_get_socket_by_name(&sockname);
+ if(si != NULL) {
+ return 1;
+ }
+ return -1;
+}
+
/**
*
*/
@@ -1238,6 +1281,11 @@ static sr_kemi_t sr_kemi_corex_exports[] = {
{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
+ { str_init("corex"), str_init("is_socket_name"),
+ SR_KEMIP_INT, ki_is_socket_name,
+ { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
};