client: do not insist on \n\n when parsing MGCP messages

The current implementation of mgcp_client.c requires MGCP
paragraphs to be separated wit a \n\n sequence. However,
when the client is used with servers other than osmo-mgcp,
the parapgraph may be formatted differently.

Also allow \n\r\n\r and \r\n\r\n as separator

Change-Id: Ie209fb71499e011e52f58575c6af118de2fdee88
This commit is contained in:
Philipp Maier 2018-01-18 15:16:13 +01:00 committed by dexter
parent 2138779559
commit 3b12e1b011
1 changed files with 23 additions and 2 deletions

View File

@ -219,12 +219,33 @@ response_parse_failure:
return -EINVAL;
}
/* A new section is marked by a double line break, check a few more
* patterns as there may be variants */
static char *mgcp_find_section_end(char *string)
{
char *rc;
rc = strstr(string, "\n\n");
if (rc)
return rc;
rc = strstr(string, "\n\r\n\r");
if (rc)
return rc;
rc = strstr(string, "\r\n\r\n");
if (rc)
return rc;
return NULL;
}
int mgcp_response_parse_params(struct mgcp_response *r)
{
char *line;
int rc;
OSMO_ASSERT(r->body);
char *data = strstr(r->body, "\n\n");
char *data = mgcp_find_section_end(r->body);
if (!data) {
LOGP(DLMGCP, LOGL_ERROR,
@ -286,7 +307,7 @@ static int parse_head_params(struct mgcp_response *r)
int rc = 0;
OSMO_ASSERT(r->body);
char *data = r->body;
char *data_end = strstr(r->body, "\n\n");
char *data_end = mgcp_find_section_end(r->body);
/* Protect SDP body, for_each_non_empty_line() will
* only parse until it hits \0 mark. */