From d64c041cdb7345a319d5b0725064ac5e345e69d1 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Wed, 14 Jul 2021 11:53:49 +0200 Subject: [PATCH] mgcp_endp: make wildcarded detection separate osmo-mgw currently does only a very simple detection method for wildcarded requests, but it makes sense to split this detection off into a separate function so that it can be used from different code locations and we still have it at one place only. Change-Id: I27018c01afb8acabfcf5d435c996cc9806e52d6b Related: SYS#5535 --- include/osmocom/mgcp/mgcp_endp.h | 1 + src/libosmo-mgcp/mgcp_endp.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/osmocom/mgcp/mgcp_endp.h b/include/osmocom/mgcp/mgcp_endp.h index 8d19b443d..db1a8976b 100644 --- a/include/osmocom/mgcp/mgcp_endp.h +++ b/include/osmocom/mgcp/mgcp_endp.h @@ -134,6 +134,7 @@ struct mgcp_endpoint *mgcp_endp_alloc(struct mgcp_trunk *trunk, unsigned int ind void mgcp_endp_release(struct mgcp_endpoint *endp); int mgcp_endp_claim(struct mgcp_endpoint *endp, const char *callid); void mgcp_endp_update(struct mgcp_endpoint *endp); +bool mgcp_endp_is_wildcarded(const char *epname); struct mgcp_endpoint *mgcp_endp_by_name_trunk(int *cause, const char *epname, const struct mgcp_trunk *trunk); struct mgcp_endpoint *mgcp_endp_by_name(int *cause, const char *epname, diff --git a/src/libosmo-mgcp/mgcp_endp.c b/src/libosmo-mgcp/mgcp_endp.c index 9ebdd8e94..ddfd6cf31 100644 --- a/src/libosmo-mgcp/mgcp_endp.c +++ b/src/libosmo-mgcp/mgcp_endp.c @@ -237,6 +237,18 @@ static struct mgcp_endpoint *find_specific_endpoint(const char *epname, return NULL; } +/*! Check if the given epname refers to a wildcarded request or to a specific + * endpoint. + * \param[in] epname endpoint name to check + * \returns true if epname refers to wildcarded request, else false. */ +bool mgcp_endp_is_wildcarded(const char *epname) +{ + if (strstr(epname, "*")) + return true; + + return false; +} + /*! Find an endpoint by its name on a specified trunk. * \param[out] cause pointer to store cause code, can be NULL. * \param[in] epname endpoint name to lookup. @@ -253,7 +265,7 @@ struct mgcp_endpoint *mgcp_endp_by_name_trunk(int *cause, const char *epname, /* At the moment we only support a primitive ('*'-only) method of * wildcarded endpoint searches that picks the next free endpoint on * a trunk. */ - if (strstr(epname, "*")) { + if (mgcp_endp_is_wildcarded(epname)) { endp = find_free_endpoint(trunk); if (endp) { LOGPENDP(endp, DLMGCP, LOGL_DEBUG,