mgcp_protocol: Avoid code duplication between virtual + other trunks
There were two code paths that were supposed to do exactly the same,
but then in Change-Id I3994af016fb96427263edbba05f560743f85fdd4 only
one of the two was modified, resulting in OS#4034
Let's
* dynamically allocate the virtual trunk
* rename mgcp_config.trunk to mgcp_config.virt_trunk to clarify
* as a result, abolish copy+pasted code for trunk initialization
Change-Id: I54762af6d417b849a24b6e71b6c5c996a5cb3fa6
Related: OS#4034
diff --git a/src/libosmo-mgcp/mgcp_msg.c b/src/libosmo-mgcp/mgcp_msg.c
index 3e95ed1..b0d1a9f 100644
--- a/src/libosmo-mgcp/mgcp_msg.c
+++ b/src/libosmo-mgcp/mgcp_msg.c
@@ -235,6 +235,7 @@
unsigned int gw = INT_MAX;
const char *endpoint_number_str;
struct mgcp_endpoint *endp;
+ struct mgcp_trunk_config *virt_trunk = cfg->virt_trunk;
*cause = 0;
@@ -259,15 +260,15 @@
endpoint_number_str =
mgcp + strlen(MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK);
if (endpoint_number_str[0] == '*') {
- endp = find_free_endpoint(cfg->trunk.endpoints,
- cfg->trunk.number_endpoints);
+ endp = find_free_endpoint(virt_trunk->endpoints,
+ virt_trunk->number_endpoints);
if (!endp)
*cause = -403;
return endp;
}
gw = strtoul(endpoint_number_str, &endptr, 16);
- if (gw < cfg->trunk.number_endpoints && endptr[0] == '@') {
- endp = &cfg->trunk.endpoints[gw];
+ if (gw < virt_trunk->number_endpoints && endptr[0] == '@') {
+ endp = &virt_trunk->endpoints[gw];
endp->wildcarded_req = false;
return endp;
}
@@ -278,8 +279,8 @@
"Addressing virtual trunk without prefix (deprecated), please use %s: '%s'\n",
MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK, mgcp);
gw = strtoul(mgcp, &endptr, 16);
- if (gw < cfg->trunk.number_endpoints && endptr[0] == '@') {
- endp = &cfg->trunk.endpoints[gw];
+ if (gw < virt_trunk->number_endpoints && endptr[0] == '@') {
+ endp = &virt_trunk->endpoints[gw];
endp->wildcarded_req = false;
return endp;
}