[MERGED] osmo-mgw[master]: mgcp_client: cosmetic: clean up SDP params parsing

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Thu Feb 22 07:56:01 UTC 2018


Harald Welte has submitted this change and it was merged.

Change subject: mgcp_client: cosmetic: clean up SDP params parsing
......................................................................


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(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



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: merged
Gerrit-Change-Id: Icf1df761270777a142bc8ace75f2a10918314f73
Gerrit-PatchSet: 2
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list