drop/replace very weird logging in mgcp_client.c

mgcp_do_write() is the final stage of writing data towards the MGCP server
(MGW). In that function, drop an unconditional iteration and copy of the MGCP
message to a static string buffer for no apparent reason besides debug logging.

Instead, use osmo_escape_str() with a limited length, which can just be an
inline format argument in the LOGP() statement. This way, the string mangling
is simpler and only gets run when DMGCP is actually on debug log level.

Change-Id: Id6877ed7fd7dbe009b2ece8792d5160d040c1aaa
diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c
index 2a8cc15..fc9c5d3 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -735,26 +735,15 @@
 static int mgcp_do_write(struct osmo_fd *fd, struct msgb *msg)
 {
 	int ret;
-	static char strbuf[4096];
-	unsigned int l = msg->len < sizeof(strbuf) ? msg->len : sizeof(strbuf);
-	unsigned int i;
 
-	osmo_strlcpy(strbuf, (const char*)msg->data, l);
-	for (i = 0; i < sizeof(strbuf); i++) {
-		if (strbuf[i] == '\n' || strbuf[i] == '\r') {
-			strbuf[i] = '\0';
-			break;
-		}
-	}
-	DEBUGP(DLMGCP, "Tx MGCP msg to MGCP GW: '%s'\n", strbuf);
-
-	LOGP(DLMGCP, LOGL_DEBUG, "Sending msg to MGCP GW size: %u\n", msg->len);
+	LOGP(DLMGCP, LOGL_DEBUG, "Sending msg to MGCP GW size: len=%u '%s'...\n",
+	     msg->len, osmo_escape_str((const char*)msg->data, OSMO_MIN(42, msg->len)));
 
 	ret = write(fd->fd, msg->data, msg->len);
 	if (ret != msg->len)
-		LOGP(DLMGCP, LOGL_ERROR, "Failed to forward message to MGCP"
-		     " GW: %s\n", strerror(errno));
-
+		LOGP(DLMGCP, LOGL_ERROR, "Failed to Tx MGCP: %d='%s'; msg: len=%u '%s'...\n",
+		     errno, strerror(errno),
+		     msg->len, osmo_escape_str((const char*)msg->data, OSMO_MIN(42, msg->len)));
 	return ret;
 }