drop code dup between libosmo-mgcp-client and libosmo-mgcp

Remove mgcp_common.c and replace with mgcp_common.h.

Move mgcp_common.h from mgcp_client/ to mgcp/;
Place a compile-time copy of it back in mgcp_client/.

Add builddir/include to compiler -I paths to find generated header.

Rationale:
- Keep separate copies of the file for each of the library to not require
  debian dependencies between the two libraries.
- Avoid code dup by copying during 'make' (think: a generated header, BUILT_SOURCE).
- The copy does not have implications for linking (like mgcp_common.c did) nor
  is it a source for build confusion or fallout in other projects, because it
  does not reach across several git source trees (like gsm_data_shared.h did).

mgcp_connection_mode_strs are not actually used in libosmo-mgcp, so drop them.
(It would make semantic sense to have then in mgcp, but we can add it when it
is needed. A similar value string array remains in libosmo-mgcp-client.)

Change-Id: I7a5d3b9a2eb90be7e34b95efa529429f2e6c3ed8
diff --git a/src/libosmo-mgcp-client/Makefile.am b/src/libosmo-mgcp-client/Makefile.am
index a2eb2be..3dd21db 100644
--- a/src/libosmo-mgcp-client/Makefile.am
+++ b/src/libosmo-mgcp-client/Makefile.am
@@ -1,6 +1,7 @@
 AM_CPPFLAGS = \
 	$(all_includes) \
 	-I$(top_srcdir)/include \
+	-I$(top_builddir)/include \
 	-I$(top_builddir) \
 	$(NULL)
 
diff --git a/src/libosmo-mgcp/Makefile.am b/src/libosmo-mgcp/Makefile.am
index 20959b8..e121fea 100644
--- a/src/libosmo-mgcp/Makefile.am
+++ b/src/libosmo-mgcp/Makefile.am
@@ -32,7 +32,6 @@
 	$(NULL)
 
 libosmo_mgcp_la_SOURCES = \
-	mgcp_common.c \
 	mgcp_protocol.c \
 	mgcp_network.c \
 	mgcp_vty.c \
diff --git a/src/libosmo-mgcp/mgcp_common.c b/src/libosmo-mgcp/mgcp_common.c
deleted file mode 100644
index c246742..0000000
--- a/src/libosmo-mgcp/mgcp_common.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/* Media Gateway Control Protocol Media Gateway: RFC 3435 */
-/* Implementations useful both for the MGCP GW as well as MGCP GW clients */
-
-/*
- * (C) 2016 by sysmocom s.m.f.c. GmbH <info@sysmocom.de>
- * All Rights Reserved
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include <errno.h>
-
-#include <osmocom/core/utils.h>
-#include <osmocom/mgcp/mgcp.h>
-
-const struct value_string mgcp_connection_mode_strs[] = {
-	{ MGCP_CONN_NONE, "none" },
-	{ MGCP_CONN_RECV_SEND, "sendrecv" },
-	{ MGCP_CONN_SEND_ONLY, "sendonly" },
-	{ MGCP_CONN_RECV_ONLY, "recvonly" },
-	{ MGCP_CONN_LOOPBACK, "loopback" },
-	{ 0, NULL }
-};
-
-/* Ensure that the msg->l2h is NUL terminated. */
-int mgcp_msg_terminate_nul(struct msgb *msg)
-{
-	unsigned char *tail = msg->l2h + msgb_l2len(msg); /* char after l2 data */
-	if (tail[-1] == '\0')
-		/* nothing to do */;
-	else if (msgb_tailroom(msg) > 0)
-		tail[0] = '\0';
-	else if (tail[-1] == '\r' || tail[-1] == '\n')
-		tail[-1] = '\0';
-	else {
-		LOGP(DLMGCP, LOGL_ERROR, "Cannot NUL terminate MGCP message: "
-		     "Length: %d, Buffer size: %d\n",
-		     msgb_l2len(msg), msg->data_len);
-		return -ENOTSUP;
-	}
-	return 0;
-}
diff --git a/src/libosmo-mgcp/mgcp_conn.c b/src/libosmo-mgcp/mgcp_conn.c
index 1a295e7..0da62bc 100644
--- a/src/libosmo-mgcp/mgcp_conn.c
+++ b/src/libosmo-mgcp/mgcp_conn.c
@@ -23,7 +23,7 @@
 
 #include <osmocom/mgcp/mgcp_conn.h>
 #include <osmocom/mgcp/mgcp_internal.h>
-#include <osmocom/mgcp/mgcp_ep.h>
+#include <osmocom/mgcp/mgcp_common.h>
 
 /* Reset codec state and free memory */
 static void mgcp_rtp_codec_reset(struct mgcp_rtp_codec *codec)
diff --git a/src/libosmo-mgcp/mgcp_msg.c b/src/libosmo-mgcp/mgcp_msg.c
index f4ecb03..d686bca 100644
--- a/src/libosmo-mgcp/mgcp_msg.c
+++ b/src/libosmo-mgcp/mgcp_msg.c
@@ -25,6 +25,7 @@
 #include <limits.h>
 
 #include <osmocom/mgcp/mgcp_internal.h>
+#include <osmocom/mgcp/mgcp_common.h>
 #include <osmocom/mgcp/mgcp_msg.h>
 #include <osmocom/mgcp/mgcp_conn.h>
 
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index 4a1eb74..dac1698 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -34,6 +34,7 @@
 #include <osmocom/core/select.h>
 #include <osmocom/netif/rtp.h>
 #include <osmocom/mgcp/mgcp.h>
+#include <osmocom/mgcp/mgcp_common.h>
 #include <osmocom/mgcp/mgcp_internal.h>
 #include <osmocom/mgcp/mgcp_stat.h>
 #include <osmocom/mgcp/osmux.h>
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index ac25894..c00cdc6 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -34,6 +34,7 @@
 #include <osmocom/core/select.h>
 
 #include <osmocom/mgcp/mgcp.h>
+#include <osmocom/mgcp/mgcp_common.h>
 #include <osmocom/mgcp/mgcp_internal.h>
 #include <osmocom/mgcp/mgcp_stat.h>
 #include <osmocom/mgcp/mgcp_msg.h>
diff --git a/src/libosmo-mgcp/mgcp_vty.c b/src/libosmo-mgcp/mgcp_vty.c
index aaa0429..a1299b2 100644
--- a/src/libosmo-mgcp/mgcp_vty.c
+++ b/src/libosmo-mgcp/mgcp_vty.c
@@ -23,6 +23,7 @@
 
 #include <osmocom/core/talloc.h>
 #include <osmocom/mgcp/mgcp.h>
+#include <osmocom/mgcp/mgcp_common.h>
 #include <osmocom/mgcp/mgcp_internal.h>
 #include <osmocom/mgcp/vty.h>
 #include <osmocom/mgcp/mgcp_conn.h>