X-Osmo-IGN: rather parse items by token, not char
Adjust the X-Osmo-IGN parsing to use string tokens instead of parsing single
characters.
Reconsidering the first implementation as a poor choice, rather specify the
format of X-Osmo-IGN as any-length string tokens separated by spaces, which is
more flexible and more future proof.
See also osmo-gsm-manuals If15a88c3b5b40fd1d24ad0f94f3231f678669ab1 which
defines the X-Osmo-IGN format as string tokens, matching this patch.
In mgcp_test, add an unknown X-Osmo-IGN item. Though the output is not checked
by the testsuite.at, running manually shows the error log about the unkown
X-Osmo-IGN item.
Change-Id: Ia6fe5ead4b601931c1bf41b29fc1b237aac37d2c
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index cb2c965..7f4a7b8 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -674,6 +674,30 @@
return 534;
}
+static bool parse_x_osmo_ign(struct mgcp_endpoint *endp, char *line)
+{
+ char *saveptr = NULL;
+
+ if (strncmp(line, MGCP_X_OSMO_IGN_HEADER, strlen(MGCP_X_OSMO_IGN_HEADER)))
+ return false;
+ line += strlen(MGCP_X_OSMO_IGN_HEADER);
+
+ while (1) {
+ char *token = strtok_r(line, " ", &saveptr);
+ line = NULL;
+ if (!token)
+ break;
+
+ if (!strcmp(token, "C"))
+ endp->x_osmo_ign |= MGCP_X_OSMO_IGN_CALLID;
+ else
+ LOGP(DLMGCP, LOGL_ERROR, "endpoint %x: received unknown X-Osmo-IGN item '%s'\n",
+ ENDPOINT_NUMBER(endp), token);
+ }
+
+ return true;
+}
+
/* CRCX command handler, processes the received command */
static struct msgb *handle_create_con(struct mgcp_parse_data *p)
{
@@ -723,22 +747,9 @@
break;
}
- /* Parse X-Osmo-IGN header */
- if (!strncmp(line, MGCP_X_OSMO_IGN_HEADER,
- strlen(MGCP_X_OSMO_IGN_HEADER))) {
- int i;
- int line_len = strlen(line);
- for (i = strlen(MGCP_X_OSMO_IGN_HEADER); i < line_len; i++) {
- switch (line[i]) {
- case 'C':
- endp->x_osmo_ign |= MGCP_X_OSMO_IGN_CALLID;
- break;
- default:
- break;
- }
- }
+ if (parse_x_osmo_ign(endp, line))
break;
- }
+
/* Ignore unknown X-headers */
break;
case '\0':