mcgp_client: mgcp_msg_gen(): add checks to verify params

mgcp_msg_gen() does not check the contents of the prameters that
are handed over with the struct. This may lead to invalid mgcp
messages sent to the MGW, which can be difficult to debug.

Add some additional checks to make a possible problem
noticeable in an early stage.

- verify that the endpoint is not a nullstring
- verify that the connection id is not a nullstring
- verify that the ip-address is not a nullstring
- verify that the port number is a value greater 0

Change-Id: I15c464c4bcdf6e524f68acc62f44186dd7ad19a7
diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c
index 2f3d0d1..1c35aa9 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -789,8 +789,15 @@
 	}
 
 	/* Add endpoint name */
-	if (mgcp_msg->presence & MGCP_MSG_PRESENCE_ENDPOINT)
+	if (mgcp_msg->presence & MGCP_MSG_PRESENCE_ENDPOINT) {
+		if (strlen(mgcp_msg->endpoint) <= 0) {
+			LOGP(DLMGCP, LOGL_ERROR,
+			     "Empty endpoint name, can not generate MGCP message\n");
+			msgb_free(msg);
+			return NULL;
+		}
 		rc += msgb_printf(msg, " %s", mgcp_msg->endpoint);
+	}
 
 	/* Add protocol version */
 	rc += msgb_printf(msg, " MGCP 1.0\r\n");
@@ -800,8 +807,15 @@
 		rc += msgb_printf(msg, "C: %x\r\n", mgcp_msg->call_id);
 
 	/* Add connection id */
-	if (mgcp_msg->presence & MGCP_MSG_PRESENCE_CONN_ID)
+	if (mgcp_msg->presence & MGCP_MSG_PRESENCE_CONN_ID) {
+		if (strlen(mgcp_msg->conn_id) <= 0) {
+			LOGP(DLMGCP, LOGL_ERROR,
+			     "Empty connection id, can not generate MGCP message\n");
+			msgb_free(msg);
+			return NULL;
+		}
 		rc += msgb_printf(msg, "I: %s\r\n", mgcp_msg->conn_id);
+	}
 
 	/* Add local connection options */
 	if (mgcp_msg->verb == MGCP_VERB_CRCX)
@@ -816,6 +830,18 @@
 	/* Add RTP address and port (SDP) */
 	if (mgcp_msg->presence & MGCP_MSG_PRESENCE_AUDIO_IP
 	    && mgcp_msg->presence & MGCP_MSG_PRESENCE_AUDIO_PORT) {
+		if (mgcp_msg->audio_port == 0) {
+			LOGP(DLMGCP, LOGL_ERROR,
+			     "Invalid port number, can not generate MGCP message\n");
+			msgb_free(msg);
+			return NULL;
+		}
+		if (strlen(mgcp_msg->audio_ip) <= 0) {
+			LOGP(DLMGCP, LOGL_ERROR,
+			     "Empty ip address, can not generate MGCP message\n");
+			msgb_free(msg);
+			return NULL;
+		}
 		rc += msgb_printf(msg, "\r\n");
 		rc += msgb_printf(msg, "c=IN IP4 %s\r\n", mgcp_msg->audio_ip);
 		rc +=