mgcp_protocol: refactor MGCP request handling

At the moment the MGCP request handling and message parsing is not
clearly separated. The function mgcp_parse_header() in mgcp_msg.c is
also responsible for resolving an endpoint. This leads to unclear layer
separation. We eventually end up in a situation where we can not execute
any request handler without beeing able to resolve an endpoint, however
this is necessary if we want to implement wildcarded DLCX resquests.

In the current situation a wildcarded DLCX is not possible to implement
as we always have to resolve a an to get to the trunk which we need to
iterate. However, we just can't resolve a free endpoint in a situation
where all endpoints on te trunk are in use.

We have to refactor the request handler so that the parsing in mgcp_msg
only extracts us the endpoint name. The resolving is then done in
mgcp_handle_message() in mgcp_protocol.c. Then we are able to decide
what to do if we are unable to resolve an endpoint but still be able to
resolve the trunk.

This patch does not change the behaviour of osmo-mgw yet, but it lays
the foundation for request handler implementations that can still
perform useful actions if no endpoint but a trunk has been resolved. A
wilcarded DLCX is such a case. It does not need an endpoint, just the
trunk.

Change-Id: I9f519d8a0ee8a513fa1e74acf3ee7dbc0991cdde
Related: SYS#5535
diff --git a/src/libosmo-mgcp/mgcp_msg.c b/src/libosmo-mgcp/mgcp_msg.c
index 8783e20..f8b486a 100644
--- a/src/libosmo-mgcp/mgcp_msg.c
+++ b/src/libosmo-mgcp/mgcp_msg.c
@@ -132,24 +132,19 @@
 }
 
 /*! Analyze and parse the the hader of an MGCP messeage string.
- *  \param[out] pdata caller provided memory to store the parsing results
- *  \param[in] data mgcp message string
- *  \returns when the status line was complete and transaction_id and
- *  endp out parameters are set, -1 on error */
+ *  \param[out] pdata caller provided memory to store the parsing results.
+ *  \param[in] data mgcp message string.
+ *  \returns 0 when the status line was complete and parseable, negative (MGCP
+ *  cause code) on error. */
 int mgcp_parse_header(struct mgcp_parse_data *pdata, char *data)
 {
 	int i = 0;
 	char *elem, *save = NULL;
-	int cause;
 
 	/*! This function will parse the header part of the received
-	 *  MGCP message. The parsing results are stored in pdata.
-	 *  The function will also automatically search the pool with
-	 *  available endpoints in order to find an endpoint that matches
-	 *  the endpoint string in in the header */
+	 *  MGCP message. The parsing results are stored in pdata. */
 
 	OSMO_ASSERT(data);
-	pdata->trans = "000000";
 
 	for (elem = strtok_r(data, " ", &save); elem;
 	     elem = strtok_r(NULL, " ", &save)) {
@@ -158,13 +153,7 @@
 			pdata->trans = elem;
 			break;
 		case 1:
-			pdata->endp = mgcp_endp_by_name(&cause, elem, pdata->cfg);
-			if (!pdata->endp) {
-				LOGP(DLMGCP, LOGL_ERROR,
-				     "Unable to find Endpoint `%s'\n", elem);
-				OSMO_ASSERT(cause < 0);
-				return cause;
-			}
+			pdata->epname = elem;
 			break;
 		case 2:
 			if (strcasecmp("MGCP", elem)) {
@@ -174,11 +163,8 @@
 			}
 			break;
 		case 3:
-			if (strcmp("1.0", elem)) {
-				LOGP(DLMGCP, LOGL_ERROR, "MGCP version `%s' "
-				     "not supported\n", elem);
+			if (strcmp("1.0", elem))
 				return -528;
-			}
 			break;
 		}
 		i++;
@@ -186,8 +172,6 @@
 
 	if (i != 4) {
 		LOGP(DLMGCP, LOGL_ERROR, "MGCP status line too short.\n");
-		pdata->trans = "000000";
-		pdata->endp = NULL;
 		return -510;
 	}