mgcp_client: cosmetic: clean up SDP params parsing The mgcp_response_parse_params() is in a jumble. Straighten out these cosmetic issues:
- Move assertion of r->body close to its first use. - Instead of a talloc_zero and osmo_strlcpy dance, simply use talloc_strdup(). - Drop the first unused invocation of mgcp_find_section_end(). - Drop unused assignment of data_ptr = data. - In the log, mention "SDP" to clarify. - Add a comment clarifying how we skip the section marker. Change-Id: Icf1df761270777a142bc8ace75f2a10918314f73 --- M src/libosmo-mgcp-client/mgcp_client.c 1 file changed, 7 insertions(+), 6 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/39/6639/2 diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c index c340303..de940c0 100644 --- a/src/libosmo-mgcp-client/mgcp_client.c +++ b/src/libosmo-mgcp-client/mgcp_client.c @@ -251,26 +251,27 @@ { char *line; int rc; - OSMO_ASSERT(r->body); - char *data = mgcp_find_section_end(r->body); + char *data; char *data_ptr; /* Since this functions performs a destructive parsing, we create a * local copy of the body data */ - data = talloc_zero_size(r, strlen(r->body)+1); + OSMO_ASSERT(r->body); + data = talloc_strdup(r, r->body); OSMO_ASSERT(data); - data_ptr = data; - osmo_strlcpy(data, r->body, strlen(r->body)); /* Find beginning of the parameter (SDP) section */ data_ptr = mgcp_find_section_end(data); if (!data) { LOGP(DLMGCP, LOGL_ERROR, - "MGCP response: cannot find start of parameters\n"); + "MGCP response: cannot find start of SDP parameters\n"); rc = -EINVAL; goto exit; } + /* data_ptr now points to the beginning of the section-end-marker; for_each_non_empty_line() + * skips any \r and \n characters for free, so we don't need to skip the marker. */ + for_each_non_empty_line(line, data_ptr) { if (!mgcp_line_is_valid(line)) return -EINVAL; -- To view, visit https://gerrit.osmocom.org/6639 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newpatchset Gerrit-Change-Id: Icf1df761270777a142bc8ace75f2a10918314f73 Gerrit-PatchSet: 2 Gerrit-Project: osmo-mgw Gerrit-Branch: master Gerrit-Owner: Neels Hofmeyr <nhofm...@sysmocom.de> Gerrit-Reviewer: Jenkins Builder