This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
libosmo-mgcp-client: make independent of other mgcp libs
Remove the shared mgcp_common.c file and hence erase all conflicts in case both
libosmo-mgcp-client and libosmo-mgcp were linked.
Move the few remaining common definitions to new header
<osmocom/mgcp/mgcp_common.h>. The content of this header is now the only bit
shared between mgcp and mgcp-client.
However, keep separate copies of the file for each of the library to not
require debian dependencies between the two libraries. The file is copied from
mgcp to mgcp_client during 'make', as a BUILT_SOURCE.
Move enum mgcp_connection_mode to mgcp_common.h.
Move for_each_non_empty_line() macro to mgcp_common.h.
Replace for_each_line() use in mgcp_client with for_each_non_empty_line()
(according to comment; for_each_non_empty_line() replaces for_each_line() and
uses strtok_r() instead of an own reinvention).
Make mgcp_msg_terminate_nul() a static inline and place in mgcp_common.h. The
complexity is just above your average static inline, but it's a way to not dup
code and use it in both mgcp and mgcp_client without linking problems.
Move mgcp_connection_mode_strs to mgcp_client.c, rename to mgcp_client_ prefix.
(It would make sense to have something similar in mgcp, but since it is only
used in mgcp_client, we can avoid the dup altogether.)
Change-Id: Ifd3a2c7cdabb31bc50cb7f671758ffb7cdd10221
---
M include/Makefile.am
M include/osmocom/mgcp/mgcp.h
A include/osmocom/mgcp/mgcp_common.h
M include/osmocom/mgcp/mgcp_internal.h
M include/osmocom/mgcp_client/Makefile.am
M include/osmocom/mgcp_client/mgcp_client.h
M include/osmocom/mgcp_client/mgcp_client_internal.h
M src/libosmo-mgcp-client/Makefile.am
M src/libosmo-mgcp-client/mgcp_client.c
M src/libosmo-mgcp-client/mgcp_client_vty.c
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/mgcp_client_test.c
19 files changed, 103 insertions(+), 80 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/05/4005/2
diff --git a/include/Makefile.am b/include/Makefile.am
index 2e354ae..b52e5ea 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -7,7 +7,9 @@
osmocom/legacy_mgcp/mgcp_internal.h \
osmocom/legacy_mgcp/osmux.h \
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 3424684..3e387eb 100644
--- a/include/osmocom/mgcp/mgcp.h
+++ b/include/osmocom/mgcp/mgcp.h
@@ -167,21 +167,6 @@
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/mgcp_common.h b/include/osmocom/mgcp/mgcp_common.h
new file mode 100644
index 0000000..bdff555
--- /dev/null
+++ b/include/osmocom/mgcp/mgcp_common.h
@@ -0,0 +1,64 @@
+/* MGCP common implementations.
+ * These are used in libosmo-mgcp as well as libosmo-mgcp-client.
+ * To avoid interdependency, these are implemented in .h file only. */
+
+/*
+ * (C) 2017 by sysmocom s.f.m.c. GmbH <info at sysmocom.de>
+ * (C) 2009-2012 by Holger Hans Peter Freyther <zecke at selfish.org>
+ * (C) 2009-2012 by On-Waves
+ * 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/>.
+ *
+ */
+
+#pragma once
+
+#include <string.h>
+#include <errno.h>
+
+#include <osmocom/core/msgb.h>
+#include <osmocom/core/logging.h>
+
+#define for_each_non_empty_line(line, save) \
+ for (line = strtok_r(NULL, "\r\n", &save); line; \
+ line = strtok_r(NULL, "\r\n", &save))
+
+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,
+};
+
+/* Ensure that the msg->l2h is NUL terminated. */
+static inline 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/include/osmocom/mgcp/mgcp_internal.h b/include/osmocom/mgcp/mgcp_internal.h
index fe54e22..b8fc530 100644
--- a/include/osmocom/mgcp/mgcp_internal.h
+++ b/include/osmocom/mgcp/mgcp_internal.h
@@ -316,5 +316,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/include/osmocom/mgcp_client/mgcp_client.h b/include/osmocom/mgcp_client/mgcp_client.h
index df73811..b560442 100644
--- a/include/osmocom/mgcp_client/mgcp_client.h
+++ b/include/osmocom/mgcp_client/mgcp_client.h
@@ -2,6 +2,8 @@
#include <stdint.h>
+#include <osmocom/mgcp/mgcp_common.h>
+
#define MGCP_CLIENT_LOCAL_ADDR_DEFAULT "0.0.0.0"
#define MGCP_CLIENT_LOCAL_PORT_DEFAULT 0
#define MGCP_CLIENT_REMOTE_ADDR_DEFAULT "127.0.0.1"
@@ -71,3 +73,9 @@
struct msgb *mgcp_msg_dlcx(struct mgcp_client *mgcp, uint16_t rtp_endpoint,
unsigned int call_id);
+
+extern const struct value_string mgcp_client_connection_mode_strs[];
+static inline const char *mgcp_client_cmode_name(enum mgcp_connection_mode mode)
+{
+ return get_value_string(mgcp_client_connection_mode_strs, mode);
+}
diff --git a/include/osmocom/mgcp_client/mgcp_client_internal.h b/include/osmocom/mgcp_client/mgcp_client_internal.h
index 1b149e2..690a4af 100644
--- a/include/osmocom/mgcp_client/mgcp_client_internal.h
+++ b/include/osmocom/mgcp_client/mgcp_client_internal.h
@@ -1,5 +1,7 @@
#pragma once
+#include <osmocom/core/write_queue.h>
+
#define MSGB_CB_MGCP_TRANS_ID 0
struct mgcp_client {
diff --git a/src/libosmo-mgcp-client/Makefile.am b/src/libosmo-mgcp-client/Makefile.am
index b17477a..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)
@@ -30,7 +31,6 @@
libosmo_mgcp_client_la_SOURCES = \
mgcp_client.c \
mgcp_client_vty.c \
- ../libosmo-legacy-mgcp/mgcp_common.c \
$(NULL)
libosmo_mgcp_client_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(MGCP_CLIENT_LIBVERSION)
diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c
index b72fc50..1cd37be 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -24,8 +24,6 @@
#include <osmocom/core/msgb.h>
#include <osmocom/core/logging.h>
-#include <osmocom/legacy_mgcp/mgcp.h>
-#include <osmocom/legacy_mgcp/mgcp_internal.h>
#include <osmocom/mgcp_client/mgcp_client.h>
#include <osmocom/mgcp_client/mgcp_client_internal.h>
@@ -208,7 +206,7 @@
*data = '\0';
data ++;
- for_each_line(line, data) {
+ for_each_non_empty_line(line, data) {
if (!mgcp_line_is_valid(line))
return -EINVAL;
@@ -584,7 +582,7 @@
trans_id,
rtp_endpoint,
call_id,
- mgcp_cmode_name(mode));
+ mgcp_client_cmode_name(mode));
}
struct msgb *mgcp_msg_mdcx(struct mgcp_client *mgcp,
@@ -602,7 +600,7 @@
,
trans_id,
rtp_endpoint,
- mgcp_cmode_name(mode),
+ mgcp_client_cmode_name(mode),
rtp_conn_addr,
rtp_port);
}
@@ -620,3 +618,12 @@
{
return &mgcp->actual;
}
+
+const struct value_string mgcp_client_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 }
+};
diff --git a/src/libosmo-mgcp-client/mgcp_client_vty.c b/src/libosmo-mgcp-client/mgcp_client_vty.c
index 1e8bba6..c52803f 100644
--- a/src/libosmo-mgcp-client/mgcp_client_vty.c
+++ b/src/libosmo-mgcp-client/mgcp_client_vty.c
@@ -27,7 +27,6 @@
#include <osmocom/vty/command.h>
#include <osmocom/core/utils.h>
-#include <osmocom/legacy_mgcp/vty.h>
#include <osmocom/mgcp_client/mgcp_client.h>
#define MGCPGW_STR "MGCP gateway configuration for RTP streams\n"
diff --git a/src/libosmo-mgcp/Makefile.am b/src/libosmo-mgcp/Makefile.am
index a9c7602..b003f57 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 38f6961..0c21365 100644
--- a/src/libosmo-mgcp/mgcp_conn.c
+++ b/src/libosmo-mgcp/mgcp_conn.c
@@ -22,6 +22,7 @@
*/
#include <osmocom/mgcp/mgcp_conn.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 d809447..c9dc887 100644
--- a/src/libosmo-mgcp/mgcp_msg.c
+++ b/src/libosmo-mgcp/mgcp_msg.c
@@ -24,6 +24,7 @@
#include <limits.h>
#include <osmocom/mgcp/mgcp_internal.h>
+#include <osmocom/mgcp/mgcp_common.h>
#include <osmocom/mgcp/mgcp_msg.h>
/*! \brief Display an mgcp message on the log output.
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index caed189..ac5fd1a 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 d019602..36ec683 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 4f73cee..5c50419 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>
diff --git a/tests/mgcp/mgcp_test.c b/tests/mgcp/mgcp_test.c
index 240116a..6a43b7b 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/mgcp_client_test.c b/tests/mgcp_client/mgcp_client_test.c
index 6045297..f2f0e0f 100644
--- a/tests/mgcp_client/mgcp_client_test.c
+++ b/tests/mgcp_client/mgcp_client_test.c
@@ -22,7 +22,6 @@
#include <osmocom/core/msgb.h>
#include <osmocom/core/application.h>
-#include <osmocom/legacy_mgcp/mgcp.h>
#include <osmocom/mgcp_client/mgcp_client.h>
#include <osmocom/mgcp_client/mgcp_client_internal.h>
--
To view, visit https://gerrit.osmocom.org/4005
To unsubscribe, visit https://gerrit.osmocom.org/settings
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Ifd3a2c7cdabb31bc50cb7f671758ffb7cdd10221
Gerrit-PatchSet: 2
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder