Module: kamailio Branch: master Commit: aaec01e0556bf6148ec50795f896af71f9680a70 URL: https://github.com/kamailio/kamailio/commit/aaec01e0556bf6148ec50795f896af71...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2024-01-18T09:29:21+01:00
kex: added is_myhost(uri) - check if host part only is local
- similar to is_myself() but ignores the port and protocol
---
Modified: src/modules/kex/kex_mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/aaec01e0556bf6148ec50795f896af71... Patch: https://github.com/kamailio/kamailio/commit/aaec01e0556bf6148ec50795f896af71...
---
diff --git a/src/modules/kex/kex_mod.c b/src/modules/kex/kex_mod.c index 452639c3cbd..4a1047acb2a 100644 --- a/src/modules/kex/kex_mod.c +++ b/src/modules/kex/kex_mod.c @@ -50,6 +50,7 @@ MODULE_VERSION
/** module functions */ int w_is_myself(struct sip_msg *msg, char *uri, str *s2); +int w_is_myhost(struct sip_msg *msg, char *uri, str *s2); int w_setdebug(struct sip_msg *msg, char *level, str *s2); int w_resetdebug(struct sip_msg *msg, char *uri, str *s2);
@@ -96,6 +97,8 @@ static cmd_export_t cmds[] = { ANY_ROUTE}, {"is_myself", (cmd_function)w_is_myself, 1, fixup_spve_null, fixup_free_spve_null, ANY_ROUTE}, + {"is_myhost", (cmd_function)w_is_myhost, 1, fixup_spve_null, + fixup_free_spve_null, ANY_ROUTE}, {"setdebug", (cmd_function)w_setdebug, 1, fixup_igp_null, fixup_free_igp_null, ANY_ROUTE}, {"resetdebug", (cmd_function)w_resetdebug, 0, 0, 0, ANY_ROUTE}, @@ -188,6 +191,35 @@ int w_is_myself(struct sip_msg *msg, char *uri, str *s2) return 1; }
+/** + * + */ +int w_is_myhost(struct sip_msg *msg, char *uri, str *s2) +{ + int ret; + str suri; + struct sip_uri puri; + + if(fixup_get_svalue(msg, (gparam_p)uri, &suri) != 0) { + LM_ERR("cannot get the URI parameter\n"); + return -1; + } + if(suri.len > 4 + && (strncmp(suri.s, "sip:", 4) == 0 + || strncmp(suri.s, "sips:", 5) == 0)) { + if(parse_uri(suri.s, suri.len, &puri) != 0) { + LM_ERR("failed to parse uri [%.*s]\n", suri.len, suri.s); + return -1; + } + ret = check_self(&puri.host, 0, 0); + } else { + ret = check_self(&suri, 0, 0); + } + if(ret != 1) + return -1; + return 1; +} + int w_setdebug(struct sip_msg *msg, char *level, str *s2) { int lval = 0;