Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1 | /* A Media Gateway Control Protocol Media Gateway: RFC 3435 */ |
| 2 | /* Message parser/generator utilities */ |
| 3 | |
| 4 | /* |
| 5 | * (C) 2009-2012 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 6 | * (C) 2009-2012 by On-Waves |
| 7 | * (C) 2017 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
| 8 | * All Rights Reserved |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU Affero General Public License as published by |
| 12 | * the Free Software Foundation; either version 3 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU Affero General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Affero General Public License |
| 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <limits.h> |
| 26 | |
Philipp Maier | 993ea6b | 2020-08-04 18:26:50 +0200 | [diff] [blame] | 27 | #include <osmocom/mgcp/mgcp.h> |
| 28 | #include <osmocom/mgcp/osmux.h> |
| 29 | #include <osmocom/mgcp/mgcp_protocol.h> |
Neels Hofmeyr | 6779354 | 2017-09-08 04:25:16 +0200 | [diff] [blame] | 30 | #include <osmocom/mgcp/mgcp_common.h> |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 31 | #include <osmocom/mgcp/mgcp_msg.h> |
| 32 | #include <osmocom/mgcp/mgcp_conn.h> |
Philipp Maier | 37d11c8 | 2018-02-01 14:38:12 +0100 | [diff] [blame] | 33 | #include <osmocom/mgcp/mgcp_endp.h> |
Philipp Maier | 036612b | 2021-07-19 17:47:49 +0200 | [diff] [blame] | 34 | #include <osmocom/mgcp/mgcp_trunk.h> |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 35 | |
| 36 | /*! Display an mgcp message on the log output. |
| 37 | * \param[in] message mgcp message string |
| 38 | * \param[in] len message mgcp message string length |
| 39 | * \param[in] preamble string to display in logtext in front of each line */ |
| 40 | void mgcp_disp_msg(unsigned char *message, unsigned int len, char *preamble) |
| 41 | { |
| 42 | unsigned char line[80]; |
| 43 | unsigned char *ptr; |
| 44 | unsigned int consumed = 0; |
| 45 | unsigned int consumed_line = 0; |
| 46 | unsigned int line_count = 0; |
| 47 | |
| 48 | if (!log_check_level(DLMGCP, LOGL_DEBUG)) |
| 49 | return; |
| 50 | |
| 51 | while (1) { |
| 52 | memset(line, 0, sizeof(line)); |
| 53 | ptr = line; |
| 54 | consumed_line = 0; |
| 55 | do { |
| 56 | if (*message != '\n' && *message != '\r') { |
| 57 | *ptr = *message; |
| 58 | ptr++; |
| 59 | } |
| 60 | message++; |
| 61 | consumed++; |
| 62 | consumed_line++; |
| 63 | } while (*message != '\n' && consumed < len |
| 64 | && consumed_line < sizeof(line)); |
| 65 | |
| 66 | if (strlen((const char *)line)) { |
| 67 | LOGP(DLMGCP, LOGL_DEBUG, "%s: line #%02u: %s\n", |
| 68 | preamble, line_count, line); |
| 69 | line_count++; |
| 70 | } |
| 71 | |
| 72 | if (consumed >= len) |
| 73 | return; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /*! Parse connection mode. |
Andreas Eversberg | dc7dfd0 | 2023-07-05 12:36:49 +0200 | [diff] [blame] | 78 | * \param[in] mode as string (recvonly, sendrecv, sendonly confecho or loopback) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 79 | * \param[in] endp pointer to endpoint (only used for log output) |
| 80 | * \param[out] associated connection to be modified accordingly |
| 81 | * \returns 0 on success, -1 on error */ |
| 82 | int mgcp_parse_conn_mode(const char *mode, struct mgcp_endpoint *endp, |
| 83 | struct mgcp_conn *conn) |
| 84 | { |
| 85 | int ret = 0; |
| 86 | |
| 87 | if (!mode) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 88 | LOGPCONN(conn, DLMGCP, LOGL_ERROR, |
| 89 | "missing connection mode\n"); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 90 | return -1; |
| 91 | } |
| 92 | if (!conn) |
| 93 | return -1; |
| 94 | if (!endp) |
| 95 | return -1; |
| 96 | |
Pau Espin Pedrol | 1705848 | 2019-06-26 12:23:02 +0200 | [diff] [blame] | 97 | if (strcasecmp(mode, "recvonly") == 0) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 98 | conn->mode = MGCP_CONN_RECV_ONLY; |
Pau Espin Pedrol | 1705848 | 2019-06-26 12:23:02 +0200 | [diff] [blame] | 99 | else if (strcasecmp(mode, "sendrecv") == 0) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 100 | conn->mode = MGCP_CONN_RECV_SEND; |
Pau Espin Pedrol | 1705848 | 2019-06-26 12:23:02 +0200 | [diff] [blame] | 101 | else if (strcasecmp(mode, "sendonly") == 0) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 102 | conn->mode = MGCP_CONN_SEND_ONLY; |
Andreas Eversberg | dc7dfd0 | 2023-07-05 12:36:49 +0200 | [diff] [blame] | 103 | else if (strcasecmp(mode, "confecho") == 0) |
| 104 | conn->mode = MGCP_CONN_CONFECHO; |
Pau Espin Pedrol | 1705848 | 2019-06-26 12:23:02 +0200 | [diff] [blame] | 105 | else if (strcasecmp(mode, "loopback") == 0) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 106 | conn->mode = MGCP_CONN_LOOPBACK; |
| 107 | else { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 108 | LOGPCONN(conn, DLMGCP, LOGL_ERROR, |
| 109 | "unknown connection mode: '%s'\n", mode); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 110 | ret = -1; |
| 111 | } |
| 112 | |
Pau Espin Pedrol | 30e0135 | 2020-09-21 12:29:41 +0200 | [diff] [blame] | 113 | /* Special handling for RTP connections */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 114 | if (conn->type == MGCP_CONN_TYPE_RTP) { |
Pau Espin Pedrol | 2c40164 | 2021-12-24 14:48:26 +0100 | [diff] [blame] | 115 | conn->u.rtp.end.output_enabled = !!(conn->mode & MGCP_CONN_SEND_ONLY); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 116 | } |
| 117 | |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 118 | LOGPENDP(endp, DLMGCP, LOGL_DEBUG, "conn:%s\n", mgcp_conn_dump(conn)); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 119 | |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 120 | LOGPCONN(conn, DLMGCP, LOGL_DEBUG, "connection mode '%s' %d\n", |
| 121 | mode, conn->mode); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 122 | |
| 123 | /* Special handling für RTP connections */ |
| 124 | if (conn->type == MGCP_CONN_TYPE_RTP) { |
Pau Espin Pedrol | 2c40164 | 2021-12-24 14:48:26 +0100 | [diff] [blame] | 125 | LOGPCONN(conn, DLMGCP, LOGL_DEBUG, "output_enabled %u\n", |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 126 | conn->u.rtp.end.output_enabled); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /* The VTY might change the connection mode at any time, so we have |
| 130 | * to hold a copy of the original connection mode */ |
| 131 | conn->mode_orig = conn->mode; |
| 132 | |
| 133 | return ret; |
| 134 | } |
| 135 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 136 | /*! Analyze and parse the the hader of an MGCP messeage string. |
Philipp Maier | 8dc3597 | 2021-07-14 11:20:16 +0200 | [diff] [blame] | 137 | * \param[out] pdata caller provided memory to store the parsing results. |
| 138 | * \param[in] data mgcp message string. |
| 139 | * \returns 0 when the status line was complete and parseable, negative (MGCP |
| 140 | * cause code) on error. */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 141 | int mgcp_parse_header(struct mgcp_parse_data *pdata, char *data) |
| 142 | { |
| 143 | int i = 0; |
| 144 | char *elem, *save = NULL; |
| 145 | |
| 146 | /*! This function will parse the header part of the received |
Philipp Maier | 8dc3597 | 2021-07-14 11:20:16 +0200 | [diff] [blame] | 147 | * MGCP message. The parsing results are stored in pdata. */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 148 | |
| 149 | OSMO_ASSERT(data); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 150 | |
| 151 | for (elem = strtok_r(data, " ", &save); elem; |
| 152 | elem = strtok_r(NULL, " ", &save)) { |
| 153 | switch (i) { |
| 154 | case 0: |
| 155 | pdata->trans = elem; |
| 156 | break; |
| 157 | case 1: |
Philipp Maier | 8dc3597 | 2021-07-14 11:20:16 +0200 | [diff] [blame] | 158 | pdata->epname = elem; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 159 | break; |
| 160 | case 2: |
Pau Espin Pedrol | 9a34592 | 2019-06-26 13:06:30 +0200 | [diff] [blame] | 161 | if (strcasecmp("MGCP", elem)) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 162 | LOGP(DLMGCP, LOGL_ERROR, |
| 163 | "MGCP header parsing error\n"); |
Harald Welte | abbb6b9 | 2017-12-28 13:13:50 +0100 | [diff] [blame] | 164 | return -510; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 165 | } |
| 166 | break; |
| 167 | case 3: |
Philipp Maier | 8dc3597 | 2021-07-14 11:20:16 +0200 | [diff] [blame] | 168 | if (strcmp("1.0", elem)) |
Harald Welte | abbb6b9 | 2017-12-28 13:13:50 +0100 | [diff] [blame] | 169 | return -528; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 170 | break; |
| 171 | } |
| 172 | i++; |
| 173 | } |
| 174 | |
| 175 | if (i != 4) { |
| 176 | LOGP(DLMGCP, LOGL_ERROR, "MGCP status line too short.\n"); |
Harald Welte | abbb6b9 | 2017-12-28 13:13:50 +0100 | [diff] [blame] | 177 | return -510; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | return 0; |
| 181 | } |
| 182 | |
| 183 | /*! Extract OSMUX CID from an MGCP parameter line (string). |
| 184 | * \param[in] line single parameter line from the MGCP message |
Pau Espin Pedrol | 2b89617 | 2019-04-24 13:47:23 +0200 | [diff] [blame] | 185 | * \returns OSMUX CID, -1 wildcard, -2 on error */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 186 | int mgcp_parse_osmux_cid(const char *line) |
| 187 | { |
| 188 | int osmux_cid; |
| 189 | |
Pau Espin Pedrol | 2b89617 | 2019-04-24 13:47:23 +0200 | [diff] [blame] | 190 | |
Pau Espin Pedrol | c1bf469 | 2019-05-14 16:23:24 +0200 | [diff] [blame] | 191 | if (strcasecmp(line + 2, "Osmux: *") == 0) { |
Pau Espin Pedrol | 2b89617 | 2019-04-24 13:47:23 +0200 | [diff] [blame] | 192 | LOGP(DLMGCP, LOGL_DEBUG, "Parsed wilcard Osmux CID\n"); |
| 193 | return -1; |
| 194 | } |
| 195 | |
Pau Espin Pedrol | c1bf469 | 2019-05-14 16:23:24 +0200 | [diff] [blame] | 196 | if (sscanf(line + 2 + 7, "%u", &osmux_cid) != 1) { |
Pau Espin Pedrol | ef6304e | 2019-04-23 13:24:37 +0200 | [diff] [blame] | 197 | LOGP(DLMGCP, LOGL_ERROR, "Failed parsing Osmux in MGCP msg line: %s\n", |
| 198 | line); |
Pau Espin Pedrol | 2b89617 | 2019-04-24 13:47:23 +0200 | [diff] [blame] | 199 | return -2; |
Pau Espin Pedrol | ef6304e | 2019-04-23 13:24:37 +0200 | [diff] [blame] | 200 | } |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 201 | |
| 202 | if (osmux_cid > OSMUX_CID_MAX) { |
| 203 | LOGP(DLMGCP, LOGL_ERROR, "Osmux ID too large: %u > %u\n", |
| 204 | osmux_cid, OSMUX_CID_MAX); |
Pau Espin Pedrol | 2b89617 | 2019-04-24 13:47:23 +0200 | [diff] [blame] | 205 | return -2; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 206 | } |
Pau Espin Pedrol | c7c8e64 | 2022-10-06 18:24:21 +0200 | [diff] [blame] | 207 | LOGP(DLMGCP, LOGL_DEBUG, "MGCP client offered Osmux CID %u\n", osmux_cid); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 208 | |
| 209 | return osmux_cid; |
| 210 | } |
| 211 | |
| 212 | /*! Check MGCP parameter line (string) for plausibility. |
Philipp Maier | 036612b | 2021-07-19 17:47:49 +0200 | [diff] [blame] | 213 | * \param[in] endp pointer to endpoint (only used for log output, may be NULL) |
| 214 | * \param[in] trunk pointer to trunk (only used for log output, may be NULL if endp is not NULL) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 215 | * \param[in] line single parameter line from the MGCP message |
Philipp Maier | 036612b | 2021-07-19 17:47:49 +0200 | [diff] [blame] | 216 | * \returns true when line seems plausible, false on error */ |
| 217 | bool mgcp_check_param(const struct mgcp_endpoint *endp, struct mgcp_trunk *trunk, const char *line) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 218 | { |
| 219 | const size_t line_len = strlen(line); |
| 220 | if (line[0] != '\0' && line_len < 2) { |
Philipp Maier | 036612b | 2021-07-19 17:47:49 +0200 | [diff] [blame] | 221 | if (endp) |
| 222 | LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "wrong MGCP option format: '%s'\n", line); |
| 223 | else |
| 224 | LOGPTRUNK(trunk, DLMGCP, LOGL_NOTICE, "wrong MGCP option format: '%s'\n", line); |
| 225 | return false; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /* FIXME: A couple more checks wouldn't hurt... */ |
| 229 | |
Philipp Maier | 036612b | 2021-07-19 17:47:49 +0200 | [diff] [blame] | 230 | return true; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | /*! Check if the specified callid seems plausible. |
| 234 | * \param[in] endp pointer to endpoint |
| 235 | * \param{in] callid to verify |
Pau Espin Pedrol | 06624e1 | 2020-09-21 12:18:52 +0200 | [diff] [blame] | 236 | * \returns 0 when callid seems plausible, -1 on error */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 237 | int mgcp_verify_call_id(struct mgcp_endpoint *endp, const char *callid) |
| 238 | { |
| 239 | /*! This function compares the supplied callid with the called that is |
| 240 | * stored in the endpoint structure. */ |
| 241 | |
| 242 | if (!endp) |
| 243 | return -1; |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 244 | |
| 245 | /* Accept any CallID for "X-Osmo-IGN: C" */ |
| 246 | if (endp->x_osmo_ign & MGCP_X_OSMO_IGN_CALLID) |
| 247 | return 0; |
| 248 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 249 | if (!callid) |
| 250 | return -1; |
| 251 | if (!endp->callid) |
| 252 | return -1; |
| 253 | |
| 254 | if (strcmp(endp->callid, callid) != 0) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 255 | LOGPENDP(endp, DLMGCP, LOGL_ERROR, |
| 256 | "CallIDs mismatch: '%s' != '%s'\n", |
| 257 | endp->callid, callid); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 258 | return -1; |
| 259 | } |
| 260 | |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | /*! Check if the specified connection id seems plausible. |
| 265 | * \param[in] endp pointer to endpoint |
| 266 | * \param{in] connection id to verify |
Neels Hofmeyr | eb72ff0 | 2018-09-03 23:00:07 +0200 | [diff] [blame] | 267 | * \returns 0 when connection id is valid and exists, an RFC3435 error code on error. |
Neels Hofmeyr | 8a91d2c | 2018-09-03 22:51:30 +0200 | [diff] [blame] | 268 | */ |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 269 | int mgcp_verify_ci(struct mgcp_endpoint *endp, const char *conn_id) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 270 | { |
Neels Hofmeyr | eb72ff0 | 2018-09-03 23:00:07 +0200 | [diff] [blame] | 271 | /* For invalid conn_ids, return 510 "The transaction could not be executed, because some |
| 272 | * unspecified protocol error was detected." */ |
| 273 | |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 274 | /* Check for null identifiers */ |
| 275 | if (!conn_id) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 276 | LOGPENDP(endp, DLMGCP, LOGL_ERROR, |
| 277 | "invalid ConnectionIdentifier (missing)\n"); |
Neels Hofmeyr | eb72ff0 | 2018-09-03 23:00:07 +0200 | [diff] [blame] | 278 | return 510; |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 279 | } |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 280 | |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 281 | /* Check for empty connection identifiers */ |
| 282 | if (strlen(conn_id) == 0) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 283 | LOGPENDP(endp, DLMGCP, LOGL_ERROR, |
| 284 | "invalid ConnectionIdentifier (empty)\n"); |
Neels Hofmeyr | eb72ff0 | 2018-09-03 23:00:07 +0200 | [diff] [blame] | 285 | return 510; |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 286 | } |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 287 | |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 288 | /* Check for over long connection identifiers */ |
Neels Hofmeyr | 5336f57 | 2018-09-03 22:05:48 +0200 | [diff] [blame] | 289 | if (strlen(conn_id) > (MGCP_CONN_ID_MAXLEN-1)) { |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 290 | LOGPENDP(endp, DLMGCP, LOGL_ERROR, |
| 291 | "invalid ConnectionIdentifier (too long: %zu > %d) 0x%s\n", |
| 292 | strlen(conn_id), MGCP_CONN_ID_MAXLEN-1, conn_id); |
Neels Hofmeyr | eb72ff0 | 2018-09-03 23:00:07 +0200 | [diff] [blame] | 293 | return 510; |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | /* Check if connection exists */ |
| 297 | if (mgcp_conn_get(endp, conn_id)) |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 298 | return 0; |
| 299 | |
Pau Espin Pedrol | 3239f62 | 2019-04-24 18:47:46 +0200 | [diff] [blame] | 300 | LOGPENDP(endp, DLMGCP, LOGL_ERROR, |
| 301 | "no connection found under ConnectionIdentifier 0x%s\n", conn_id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 302 | |
Neels Hofmeyr | eb72ff0 | 2018-09-03 23:00:07 +0200 | [diff] [blame] | 303 | /* When the conn_id was not found, return error code 515 "The transaction refers to an incorrect |
| 304 | * connection-id (may have been already deleted)." */ |
| 305 | return 515; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | /*! Extract individual lines from MCGP message. |
| 309 | * \param[in] str MGCP message string, consisting of multiple lines |
| 310 | * \param{in] saveptr pointer to next line in str |
| 311 | * \returns line, NULL when done */ |
| 312 | char *mgcp_strline(char *str, char **saveptr) |
| 313 | { |
| 314 | char *result; |
| 315 | |
| 316 | /*! The function must be called with *str set to the input string |
| 317 | * for the first line. After that saveptr will be initalized. |
| 318 | * all consecutive lines are extracted by calling the function |
| 319 | * with str set to NULL. When done, the function will return NULL |
| 320 | * to indicate that all lines have been parsed. */ |
| 321 | |
| 322 | if (str) |
| 323 | *saveptr = str; |
| 324 | |
| 325 | result = *saveptr; |
| 326 | |
| 327 | if (*saveptr != NULL) { |
| 328 | *saveptr = strpbrk(*saveptr, "\r\n"); |
| 329 | |
| 330 | if (*saveptr != NULL) { |
| 331 | char *eos = *saveptr; |
| 332 | |
| 333 | if ((*saveptr)[0] == '\r' && (*saveptr)[1] == '\n') |
| 334 | (*saveptr)++; |
| 335 | (*saveptr)++; |
| 336 | if ((*saveptr)[0] == '\0') |
| 337 | *saveptr = NULL; |
| 338 | |
| 339 | *eos = '\0'; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | return result; |
| 344 | } |