[PATCH] osmo-mgw[master]: drop code dup between libosmo-mgcp-client and libosmo-mgcp

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Thu Oct 5 17:33:19 UTC 2017


Hello Harald Welte, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/4055

to look at the new patch set (#2).

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
---
M include/Makefile.am
M include/osmocom/mgcp/mgcp.h
R include/osmocom/mgcp/mgcp_common.h
M include/osmocom/mgcp/mgcp_internal.h
M include/osmocom/mgcp_client/Makefile.am
M src/libosmo-mgcp-client/Makefile.am
M src/libosmo-mgcp/Makefile.am
D src/libosmo-mgcp/mgcp_common.c
M src/libosmo-mgcp/mgcp_conn.c
M src/libosmo-mgcp/mgcp_msg.c
M src/libosmo-mgcp/mgcp_network.c
M src/libosmo-mgcp/mgcp_protocol.c
M src/libosmo-mgcp/mgcp_vty.c
M tests/mgcp/mgcp_test.c
M tests/mgcp_client/Makefile.am
15 files changed, 19 insertions(+), 73 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/55/4055/2

diff --git a/include/Makefile.am b/include/Makefile.am
index 3cc4b1d..b52e5ea 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -9,6 +9,7 @@
 	osmocom/mgcp_client/mgcp_client.h \
 	osmocom/mgcp_client/mgcp_common.h \
 	osmocom/mgcp/mgcp.h \
+	osmocom/mgcp/mgcp_common.h \
 	osmocom/mgcp/mgcp_internal.h \
 	osmocom/mgcp/osmux.h \
 	$(NULL)
diff --git a/include/osmocom/mgcp/mgcp.h b/include/osmocom/mgcp/mgcp.h
index 67c499b..07d9516 100644
--- a/include/osmocom/mgcp/mgcp.h
+++ b/include/osmocom/mgcp/mgcp.h
@@ -28,6 +28,8 @@
 #include <osmocom/core/logging.h>
 #include <osmocom/mgcp/mgcp_ep.h>
 
+#include <osmocom/mgcp/mgcp_common.h>
+
 #include <arpa/inet.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -166,21 +168,6 @@
 	MGCP_BSC = 0,
 	MGCP_BSC_NAT,
 };
-
-enum mgcp_connection_mode {
-	MGCP_CONN_NONE = 0,
-	MGCP_CONN_RECV_ONLY = 1,
-	MGCP_CONN_SEND_ONLY = 2,
-	MGCP_CONN_RECV_SEND = MGCP_CONN_RECV_ONLY | MGCP_CONN_SEND_ONLY,
-	MGCP_CONN_LOOPBACK  = 4 | MGCP_CONN_RECV_SEND,
-};
-
-extern const struct value_string mgcp_connection_mode_strs[];
-
-static inline const char *mgcp_cmode_name(enum mgcp_connection_mode mode)
-{
-	return get_value_string(mgcp_connection_mode_strs, mode);
-}
 
 struct mgcp_config {
 	int source_port;
diff --git a/include/osmocom/mgcp_client/mgcp_common.h b/include/osmocom/mgcp/mgcp_common.h
similarity index 100%
rename from include/osmocom/mgcp_client/mgcp_common.h
rename to include/osmocom/mgcp/mgcp_common.h
diff --git a/include/osmocom/mgcp/mgcp_internal.h b/include/osmocom/mgcp/mgcp_internal.h
index 3a22d51..751aba5 100644
--- a/include/osmocom/mgcp/mgcp_internal.h
+++ b/include/osmocom/mgcp/mgcp_internal.h
@@ -330,5 +330,3 @@
 		return endp->cfg->net_ports.bind_addr;
 	return endp->cfg->source_addr;
 }
-
-int mgcp_msg_terminate_nul(struct msgb *msg);
diff --git a/include/osmocom/mgcp_client/Makefile.am b/include/osmocom/mgcp_client/Makefile.am
index 24401f1..0eaafcc 100644
--- a/include/osmocom/mgcp_client/Makefile.am
+++ b/include/osmocom/mgcp_client/Makefile.am
@@ -1,3 +1,11 @@
+BUILT_SOURCES = \
+	mgcp_common.h \
+	$(NULL)
+
 noinst_HEADERS = \
 	mgcp_client_internal.h \
 	$(NULL)
+
+mgcp_common.h: $(top_srcdir)/include/osmocom/mgcp/mgcp_common.h
+	echo -e "/*\n\n   DO NOT EDIT THIS FILE!\n   THIS IS OVERWRITTEN DURING BUILD\n   This is an automatic copy of <osmocom/mgcp/mgcp_common.h>\n\n */" > mgcp_common.h
+	cat $(top_srcdir)/include/osmocom/mgcp/mgcp_common.h >> mgcp_common.h
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 at 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>
diff --git a/tests/mgcp/mgcp_test.c b/tests/mgcp/mgcp_test.c
index c91de8f..e783dac 100644
--- a/tests/mgcp/mgcp_test.c
+++ b/tests/mgcp/mgcp_test.c
@@ -21,6 +21,7 @@
 
 #include <osmocom/mgcp/mgcp.h>
 #include <osmocom/mgcp/vty.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/tests/mgcp_client/Makefile.am b/tests/mgcp_client/Makefile.am
index e33f0e8..5cd0d8a 100644
--- a/tests/mgcp_client/Makefile.am
+++ b/tests/mgcp_client/Makefile.am
@@ -1,6 +1,7 @@
 AM_CPPFLAGS = \
 	$(all_includes) \
 	-I$(top_srcdir)/include \
+	-I$(top_builddir)/include \
 	-I$(top_srcdir) \
 	$(NULL)
 

-- 
To view, visit https://gerrit.osmocom.org/4055
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I7a5d3b9a2eb90be7e34b95efa529429f2e6c3ed8
Gerrit-PatchSet: 2
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder


More information about the gerrit-log mailing list