diff options
author | Gareth Palmer <gareth@acsdata.co.nz> | 2015-04-17 15:34:59 +1200 |
---|---|---|
committer | George Joseph <george.joseph@fairview5.com> | 2015-04-20 23:02:06 -0500 |
commit | 2f418c052eceea421ddbc2ca28e1139a471e6da6 (patch) | |
tree | fcf3286a3bc3206e33004b2d9a23bc16b90ebebb /main/cli.c | |
parent | f89481e39c0dc0682b6720108a9cda843d2e596c (diff) |
New AMI Command Output Format
This change modifies how the the output from a CLI command is sent
to a client over AMI.
Output from the CLI command is now sent as a series of zero-or-more
Output: headers.
Additionally, commands that fail to execute (eg: no such command,
invalid syntax etc.) now cause an Error response instead of Success.
If the command executed successfully, but the manager unable to
provide the output the reason will be included in the Message:
header. Otherwise it will contain 'Command output follows'.
Depends on a new version of starpy (> 1.0.2) that supports the new
output format.
See pull-request https://github.com/asterisk/starpy/pull/34
ASTERISK-24730
Change-Id: I6718d95490f0a6b3f171c1a5cdad9207f9a44888
Diffstat (limited to 'main/cli.c')
-rw-r--r-- | main/cli.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/main/cli.c b/main/cli.c index 9d3cdf3f4..a230c20ac 100644 --- a/main/cli.c +++ b/main/cli.c @@ -2681,12 +2681,12 @@ int ast_cli_command_full(int uid, int gid, int fd, const char *s) int x; char *duplicate = parse_args(s, &x, args + 1, AST_MAX_ARGS, NULL); char tmp[AST_MAX_ARGS + 1]; - char *retval = NULL; + char *retval = CLI_FAILURE; struct ast_cli_args a = { .fd = fd, .argc = x, .argv = args+1 }; if (duplicate == NULL) - return -1; + return RESULT_FAILURE; if (x < 1) /* We need at least one entry, otherwise ignore */ goto done; @@ -2705,8 +2705,7 @@ int ast_cli_command_full(int uid, int gid, int fd, const char *s) /* Check if the user has rights to run this command. */ if (!cli_has_permissions(uid, gid, tmp)) { ast_cli(fd, "You don't have permissions to run '%s' command\n", tmp); - ast_free(duplicate); - return 0; + goto done; } /* @@ -2719,14 +2718,13 @@ int ast_cli_command_full(int uid, int gid, int fd, const char *s) if (retval == CLI_SHOWUSAGE) { ast_cli(fd, "%s", S_OR(e->usage, "Invalid usage, but no usage information available.\n")); - } else { - if (retval == CLI_FAILURE) - ast_cli(fd, "Command '%s' failed.\n", s); + } else if (retval == CLI_FAILURE) { + ast_cli(fd, "Command '%s' failed.\n", s); } ast_atomic_fetchadd_int(&e->inuse, -1); done: ast_free(duplicate); - return 0; + return retval == CLI_SUCCESS ? RESULT_SUCCESS : RESULT_FAILURE; } int ast_cli_command_multiple_full(int uid, int gid, int fd, size_t size, const char *s) |