mgcp_client: make domain part of endpoint configurable

So far, both osmo-msc and osmo-bsc always pass endpoint names of the form
'...@mgw' to osmo-mgw. Allow configuring the 'mgw' part.

Note that the actual way to pass a differing name is to pass a composed
'rtpbridge/*@foo' to mgcp_msg_gen() in the struct mgcp_msg. So this merely adds
a common VTY config for the domain name part, changes to clients are necessary.

- add mgcp_client_rtpbridge_wildcard() (useful for AoIP endpoints)
- add mgcp_client_endpoint_domain() (useful for SCCPlite endpoints)
- add mgcp client vty cfg 'mgw endpoint-domain NAME'

Rationale: reading pcaps becomes so much easier when each of osmo-bsc and
osmo-msc address their MGW with differing domain names. Otherwise, both will
have a '0@mgw' endpoint and it gets really confusing.

Also: our MGCP clients osmo-bsc and osmo-msc use code dup to compose the
initial 'rtpbridge/*@mgw' rtpbridge wildcard. It should be defined by this API
instead.

This will be used by:
* osmo-msc I87ac11847d1a6d165ee9a2b5d8a4978e7ac73433
* osmo-bsc I492023e9dca0233ec0a077032455d9f2e3880f78

After these, with according configuration, there can be a '0@bsc' and a '0@msc'
endpoint on two separate osmo-mgw instances:

osmo-mgw-for-bsc.cfg:
 mgcp
  domain bsc

osmo-bsc.cfg:
 msc 0
  mgw endpoint-domain bsc

osmo-mgw-for-msc.cfg:
 mgcp
  domain msc

osmo-msc.cfg:
 msc
  mgw endpoint-domain msc

There can also be '0@bsc' and '1@msc' endpoints on one single osmo-mgw instance with:

osmo-mgw.cfg:
 mgcp
  domain *

and same osmo-{bsc,msc}.cfg as above.

(By default, everything will still use '@mgw')

Change-Id: Ia662016f29dd8727d9c4626d726729641e21e1f8
diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c
index 8fa82cd..03e1da7 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -705,6 +705,16 @@
 	mgcp->actual.remote_port = conf->remote_port >= 0 ? (uint16_t)conf->remote_port :
 		MGCP_CLIENT_REMOTE_PORT_DEFAULT;
 
+	if (osmo_strlcpy(mgcp->actual.endpoint_domain_name, conf->endpoint_domain_name,
+			 sizeof(mgcp->actual.endpoint_domain_name))
+	    >= sizeof(mgcp->actual.endpoint_domain_name)) {
+		LOGP(DLMGCP, LOGL_ERROR, "MGCP client: endpoint domain name is too long, max length is %zu: '%s'\n",
+		     sizeof(mgcp->actual.endpoint_domain_name) - 1, conf->endpoint_domain_name);
+		talloc_free(mgcp);
+		return NULL;
+	}
+	LOGP(DLMGCP, LOGL_NOTICE, "MGCP client: using endpoint domain '@%s'\n", mgcp_client_endpoint_domain(mgcp));
+
 	return mgcp;
 }
 
@@ -811,6 +821,32 @@
 	return mgcp->remote_addr;
 }
 
+/* To compose endpoint names, usually for CRCX, use this as domain name.
+ * For example, snprintf("rtpbridge\*@%s", mgcp_client_endpoint_domain(mgcp)). */
+const char *mgcp_client_endpoint_domain(const struct mgcp_client *mgcp)
+{
+	return mgcp->actual.endpoint_domain_name[0] ? mgcp->actual.endpoint_domain_name : "mgw";
+}
+
+const char *mgcp_client_rtpbridge_wildcard(const struct mgcp_client *mgcp)
+{
+	static char endpoint[MGCP_ENDPOINT_MAXLEN];
+	int rc;
+
+#define RTPBRIDGE_WILDCARD_FMT "rtpbridge/*@%s"
+	rc = snprintf(endpoint, sizeof(endpoint), RTPBRIDGE_WILDCARD_FMT, mgcp_client_endpoint_domain(mgcp));
+	if (rc > sizeof(endpoint) - 1) {
+		LOGP(DLMGCP, LOGL_ERROR, "MGCP endpoint exceeds maximum length of %zu: '" RTPBRIDGE_WILDCARD_FMT "'\n",
+		     sizeof(endpoint) - 1, mgcp_client_endpoint_domain(mgcp));
+		return NULL;
+	}
+	if (rc < 1) {
+		LOGP(DLMGCP, LOGL_ERROR, "Cannot compose MGCP endpoint name\n");
+		return NULL;
+	}
+	return endpoint;
+}
+
 struct mgcp_response_pending * mgcp_client_pending_add(
 					struct mgcp_client *mgcp,
 					mgcp_trans_id_t trans_id,