blob: c246742f05084dedf736120eedd358432f1bcb6d [file] [log] [blame]
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001/* Media Gateway Control Protocol Media Gateway: RFC 3435 */
2/* Implementations useful both for the MGCP GW as well as MGCP GW clients */
3
4/*
5 * (C) 2016 by sysmocom s.m.f.c. GmbH <info@sysmocom.de>
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#include <errno.h>
24
25#include <osmocom/core/utils.h>
Philipp Maier87bd9be2017-08-22 16:35:41 +020026#include <osmocom/mgcp/mgcp.h>
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020027
28const struct value_string mgcp_connection_mode_strs[] = {
29 { MGCP_CONN_NONE, "none" },
30 { MGCP_CONN_RECV_SEND, "sendrecv" },
31 { MGCP_CONN_SEND_ONLY, "sendonly" },
32 { MGCP_CONN_RECV_ONLY, "recvonly" },
33 { MGCP_CONN_LOOPBACK, "loopback" },
34 { 0, NULL }
35};
36
37/* Ensure that the msg->l2h is NUL terminated. */
38int mgcp_msg_terminate_nul(struct msgb *msg)
39{
40 unsigned char *tail = msg->l2h + msgb_l2len(msg); /* char after l2 data */
41 if (tail[-1] == '\0')
42 /* nothing to do */;
43 else if (msgb_tailroom(msg) > 0)
44 tail[0] = '\0';
45 else if (tail[-1] == '\r' || tail[-1] == '\n')
46 tail[-1] = '\0';
47 else {
48 LOGP(DLMGCP, LOGL_ERROR, "Cannot NUL terminate MGCP message: "
49 "Length: %d, Buffer size: %d\n",
50 msgb_l2len(msg), msg->data_len);
51 return -ENOTSUP;
52 }
53 return 0;
54}