[MERGED] libosmocore[master]: ctrl: make response easier to parse

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
Mon Nov 27 16:44:28 UTC 2017


Harald Welte has submitted this change and it was merged.

Change subject: ctrl: make response easier to parse
......................................................................


ctrl: make response easier to parse

Previously ctrl request for all counters in
group (e. g. 'rate_ctr.abs.msc.0') will result in human-readable
description which is not regular enough and is hard to both parse and
generate. The ctrl interface is intended for m2m, not for human
interaction. Let's simplify things by making response similar to counter
group request ('rate_ctr.*').

Reply now looks as follows:
GET_REPLY 9084354783926137287 rate_ctr.abs.msc.0 loc_update_type:attach 0;loc_update_type:normal 0;

Previously it was:
GET_REPLY 9084354783926137287 rate_ctr.abs.msc.0 All counters in msc.0
loc_update_type:attach 0
loc_update_type:normal 0

Change-Id: I7a24cc307450efdcd28168fffe477320c59fcd36
Related: OS#2550
---
M src/ctrl/control_if.c
1 file changed, 9 insertions(+), 32 deletions(-)

Approvals:
  Neels Hofmeyr: Looks good to me, but someone else must approve
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/ctrl/control_if.c b/src/ctrl/control_if.c
index 38e7aef..015c55e 100644
--- a/src/ctrl/control_if.c
+++ b/src/ctrl/control_if.c
@@ -499,42 +499,19 @@
 	}
 }
 
-static char *get_all_rate_ctr_in_group(void *ctx, const struct rate_ctr_group *ctrg, int intv)
-{
-	int i;
-	char *counters = talloc_strdup(ctx, "");
-	if (!counters)
-		return NULL;
-
-	for (i=0;i<ctrg->desc->num_ctr;i++) {
-		counters = talloc_asprintf_append(counters, "\n%s.%u.%s %"PRIu64,
-			ctrg->desc->group_name_prefix, ctrg->idx,
-			ctrg->desc->ctr_desc[i].name,
-			get_rate_ctr_value(&ctrg->ctr[i], intv, ctrg->desc->group_name_prefix));
-		if (!counters)
-			return NULL;
-	}
-	return counters;
-}
-
 static int get_rate_ctr_group_idx(const struct rate_ctr_group *ctrg, int intv, struct ctrl_cmd *cmd)
 {
-	char *counters;
-
-	counters = get_all_rate_ctr_in_group(cmd, ctrg, intv);
-	if (!counters)
-		goto oom;
-
-	cmd->reply = talloc_asprintf(cmd, "All counters in %s.%u%s",
-			ctrg->desc->group_name_prefix, ctrg->idx, counters);
-	talloc_free(counters);
-	if (!cmd->reply)
-		goto oom;
+	unsigned int i;
+	for (i = 0; i < ctrg->desc->num_ctr; i++) {
+		ctrl_cmd_reply_printf(cmd, "%s %"PRIu64";", ctrg->desc->ctr_desc[i].name,
+				      get_rate_ctr_value(&ctrg->ctr[i], intv, ctrg->desc->group_name_prefix));
+		if (!cmd->reply) {
+			cmd->reply = "OOM";
+			return CTRL_CMD_ERROR;
+		}
+	}
 
 	return CTRL_CMD_REPLY;
-oom:
-	cmd->reply = "OOM.";
-	return CTRL_CMD_ERROR;
 }
 
 static int ctrl_rate_ctr_group_handler(struct rate_ctr_group *ctrg, void *data)

-- 
To view, visit https://gerrit.osmocom.org/5023
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I7a24cc307450efdcd28168fffe477320c59fcd36
Gerrit-PatchSet: 4
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>



More information about the gerrit-log mailing list