From 3e2a2bfd7e04efcda0bf76d37edfa2dbeae490c5 Mon Sep 17 00:00:00 2001
From: Luigi Rizzo <rizzo@icir.org>
Date: Tue, 17 Oct 2006 18:08:51 +0000
Subject: [PATCH] simplify authority_to_str() using ast_build_string()

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@45351 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 main/manager.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/main/manager.c b/main/manager.c
index 5e50d09b2f..606dafc325 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -199,24 +199,21 @@ static AST_LIST_HEAD_STATIC(users, ast_manager_user);
 static struct manager_action *first_action = NULL;
 AST_MUTEX_DEFINE_STATIC(actionlock);
 
-/*! \brief Convert authority code to string with serveral options */
+/*! \brief Convert authority code to a list of options */
 static char *authority_to_str(int authority, char *res, int reslen)
 {
-	int running_total = 0, i;
+	int i, len = reslen;
+	char *dst = res, *sep = "";
 
-	memset(res, 0, reslen);
+	res[0] = '\0';
 	for (i = 0; i < (sizeof(perms) / sizeof(perms[0])) - 1; i++) {
 		if (authority & perms[i].num) {
-			if (*res) {
-				strncat(res, ",", (reslen > running_total) ? reslen - running_total : 0);
-				running_total++;
-			}
-			strncat(res, perms[i].label, (reslen > running_total) ? reslen - running_total : 0);
-			running_total += strlen(perms[i].label);
+			ast_build_string(&dst, &len, "%s%s", sep, perms[i].label);
+			sep = ",";
 		}
 	}
 
-	if (ast_strlen_zero(res))
+	if (ast_strlen_zero(res))	/* replace empty string with something sensible */
 		ast_copy_string(res, "<none>", reslen);
 	
 	return res;
@@ -554,8 +551,7 @@ static int handle_showmanagers(int fd, int argc, char *argv[])
 }
 
 
-/*! \brief  CLI command 
-	Should change to "manager show commands" */
+/*! \brief  CLI command  manager list commands */
 static int handle_showmancmds(int fd, int argc, char *argv[])
 {
 	struct manager_action *cur;
@@ -573,8 +569,7 @@ static int handle_showmancmds(int fd, int argc, char *argv[])
 	return RESULT_SUCCESS;
 }
 
-/*! \brief CLI command show manager connected */
-/* Should change to "manager show connected" */
+/*! \brief CLI command manager list connected */
 static int handle_showmanconn(int fd, int argc, char *argv[])
 {
 	struct mansession *s;
-- 
GitLab