From 6779354245c719580ea3c48ca752cf8cddc2d14f Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Fri, 8 Sep 2017 04:25:16 +0200 Subject: [PATCH] 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 --- include/Makefile.am | 1 + include/osmocom/mgcp/mgcp.h | 17 +----- .../{mgcp_client => mgcp}/mgcp_common.h | 0 include/osmocom/mgcp/mgcp_internal.h | 2 - include/osmocom/mgcp_client/Makefile.am | 8 +++ src/libosmo-mgcp-client/Makefile.am | 1 + src/libosmo-mgcp/Makefile.am | 1 - src/libosmo-mgcp/mgcp_common.c | 54 ------------------- src/libosmo-mgcp/mgcp_conn.c | 2 +- src/libosmo-mgcp/mgcp_msg.c | 1 + src/libosmo-mgcp/mgcp_network.c | 1 + src/libosmo-mgcp/mgcp_protocol.c | 1 + src/libosmo-mgcp/mgcp_vty.c | 1 + tests/mgcp/mgcp_test.c | 1 + tests/mgcp_client/Makefile.am | 1 + 15 files changed, 19 insertions(+), 73 deletions(-) rename include/osmocom/{mgcp_client => mgcp}/mgcp_common.h (100%) delete mode 100644 src/libosmo-mgcp/mgcp_common.c diff --git a/include/Makefile.am b/include/Makefile.am index 3cc4b1dcd..b52e5eaa4 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -9,6 +9,7 @@ nobase_include_HEADERS = \ 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 67c499bb0..07d95166e 100644 --- a/include/osmocom/mgcp/mgcp.h +++ b/include/osmocom/mgcp/mgcp.h @@ -28,6 +28,8 @@ #include #include +#include + #include #include #include @@ -167,21 +169,6 @@ enum mgcp_role { 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; char *local_ip; 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 3a22d51f2..751aba50a 100644 --- a/include/osmocom/mgcp/mgcp_internal.h +++ b/include/osmocom/mgcp/mgcp_internal.h @@ -330,5 +330,3 @@ static inline const char *mgcp_net_src_addr(struct mgcp_endpoint *endp) 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 24401f1ba..0eaafcc53 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 \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 a2eb2bec4..3dd21db1a 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 20959b876..e121fea04 100644 --- a/src/libosmo-mgcp/Makefile.am +++ b/src/libosmo-mgcp/Makefile.am @@ -32,7 +32,6 @@ noinst_HEADERS = \ $(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 c246742f0..000000000 --- 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 - * 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 . - * - */ - -#include - -#include -#include - -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 1a295e7d9..0da62bc5e 100644 --- a/src/libosmo-mgcp/mgcp_conn.c +++ b/src/libosmo-mgcp/mgcp_conn.c @@ -23,7 +23,7 @@ #include #include -#include +#include /* 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 f4ecb037a..d686bcac5 100644 --- a/src/libosmo-mgcp/mgcp_msg.c +++ b/src/libosmo-mgcp/mgcp_msg.c @@ -25,6 +25,7 @@ #include #include +#include #include #include diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c index 4a1eb74fd..dac16988e 100644 --- a/src/libosmo-mgcp/mgcp_network.c +++ b/src/libosmo-mgcp/mgcp_network.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c index ac25894f8..c00cdc6dc 100644 --- a/src/libosmo-mgcp/mgcp_protocol.c +++ b/src/libosmo-mgcp/mgcp_protocol.c @@ -34,6 +34,7 @@ #include #include +#include #include #include #include diff --git a/src/libosmo-mgcp/mgcp_vty.c b/src/libosmo-mgcp/mgcp_vty.c index aaa0429b5..a1299b2d6 100644 --- a/src/libosmo-mgcp/mgcp_vty.c +++ b/src/libosmo-mgcp/mgcp_vty.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include diff --git a/tests/mgcp/mgcp_test.c b/tests/mgcp/mgcp_test.c index c91de8f9b..e783dac0e 100644 --- a/tests/mgcp/mgcp_test.c +++ b/tests/mgcp/mgcp_test.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include diff --git a/tests/mgcp_client/Makefile.am b/tests/mgcp_client/Makefile.am index e33f0e8a7..5cd0d8a1b 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)