protocol: fix tagging of wildcarded requests

When a wildcarded CRCX is done flag "wildcarded_crcx" is set in the
endpoint struct. The flag tells other part of the code whether the
request was wildcarded or not since in some cases the behaviour
might be different for wildcarded requests. The implementation of
this mechanism is not entirely correct. The flag is set on wildcarded
requests but on non wildcarded requests it is not reset. Also the
name is misleading.

- rename wildcarded_crcx to wildcarded_req

- ensure the flag is refreshed with every new request

Change-Id: Ia5063ec65f5bc3a8a0943d1fd823aaeee20b8637
diff --git a/src/libosmo-mgcp/mgcp_endp.c b/src/libosmo-mgcp/mgcp_endp.c
index 77310c6..6d3a6d4 100644
--- a/src/libosmo-mgcp/mgcp_endp.c
+++ b/src/libosmo-mgcp/mgcp_endp.c
@@ -51,5 +51,5 @@
 	endp->local_options.string = NULL;
 	talloc_free(endp->local_options.codec);
 	endp->local_options.codec = NULL;
-	endp->wildcarded_crcx = false;
+	endp->wildcarded_req = false;
 }
diff --git a/src/libosmo-mgcp/mgcp_msg.c b/src/libosmo-mgcp/mgcp_msg.c
index 89046c0..8d22cc5 100644
--- a/src/libosmo-mgcp/mgcp_msg.c
+++ b/src/libosmo-mgcp/mgcp_msg.c
@@ -143,6 +143,7 @@
 	char *rest = NULL;
 	struct mgcp_trunk_config *tcfg;
 	int trunk, endp;
+	struct mgcp_endpoint *endp_ptr;
 
 	trunk = strtoul(mgcp + 6, &rest, 10);
 	if (rest == NULL || rest[0] != '/' || trunk < 1) {
@@ -179,7 +180,9 @@
 		return NULL;
 	}
 
-	return &tcfg->endpoints[endp];
+	endp_ptr = &tcfg->endpoints[endp];
+	endp_ptr->wildcarded_req = false;
+	return endp_ptr;
 }
 
 /* Find an endpoint that is not in use. Do this by going through the endpoint
@@ -197,7 +200,7 @@
 			LOGP(DLMGCP, LOGL_DEBUG,
 			     "endpoint:0x%x found free endpoint\n",
 			     ENDPOINT_NUMBER(endp));
-			endp->wildcarded_crcx = true;
+			endp->wildcarded_req = true;
 			return endp;
 		}
 	}
@@ -263,8 +266,11 @@
 			return endp;
 		}
 		gw = strtoul(endpoint_number_str, &endptr, 16);
-		if (gw < cfg->trunk.number_endpoints && endptr[0] == '@')
-			return &cfg->trunk.endpoints[gw];
+		if (gw < cfg->trunk.number_endpoints && endptr[0] == '@') {
+			endp = &cfg->trunk.endpoints[gw];
+			endp->wildcarded_req = false;
+			return endp;
+		}
 	}
 
 	/* Deprecated method without prefix */
@@ -272,8 +278,11 @@
 	     "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] == '@')
-		return &cfg->trunk.endpoints[gw];
+	if (gw < cfg->trunk.number_endpoints && endptr[0] == '@') {
+		endp = &cfg->trunk.endpoints[gw];
+		endp->wildcarded_req = false;
+		return endp;
+	}
 
 	LOGP(DLMGCP, LOGL_ERROR, "Not able to find the endpoint: '%s'\n", mgcp);
 	*cause = -500;
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index bfb8768..62487d1 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -199,7 +199,7 @@
 	int rc;
 
 	/* NOTE: Only in the virtual trunk we allow dynamic endpoint names */
-	if (endp->wildcarded_crcx
+	if (endp->wildcarded_req
 	    && endp->tcfg->trunk_type == MGCP_TRUNK_VIRTUAL) {
 		rc = msgb_printf(msg, "Z: %s%x@%s\r\n",
 				 MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK,