From 56879bf97876954f4ee62164441711ace1a837a1 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Sun, 21 Oct 2007 22:52:20 +0000 Subject: Merged revisions 85532 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r85532 | russell | 2007-10-13 00:24:33 -0500 (Sat, 13 Oct 2007) | 8 lines Properly handle the case where read() may return the text for more than one CLI command at once for a remote console. (closes issue #10888) Reported by: jamesgolovich Patches: asterisk-climultiple.diff.txt uploaded by jamesgolovich (license 176) ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@86585 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- include/asterisk/cli.h | 9 ++++++++- main/asterisk.c | 2 +- main/cli.c | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/asterisk/cli.h b/include/asterisk/cli.h index 59d91ab8c..ba0596d84 100644 --- a/include/asterisk/cli.h +++ b/include/asterisk/cli.h @@ -226,7 +226,14 @@ char *ast_cli_complete(const char *word, char *const choices[], int pos); int ast_cli_command(int fd, const char *s); /*! - * \brief Registers a command or an array of commands + * \brief Executes multiple CLI commands + * Interpret strings separated by '\0' and execute each one, sending output to fd + * \param size is the total size of the string + * \retval number of commands executed + */ +int ast_cli_command_multiple(int fd, size_t size, const char *s); + +/*! \brief Registers a command or an array of commands * \param e which cli entry to register * Register your own command * \retval 0 on success diff --git a/main/asterisk.c b/main/asterisk.c index 913859d56..1f7d91f55 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -963,7 +963,7 @@ static void *netconsole(void *vconsole) break; } tmp[res] = 0; - ast_cli_command(con->fd, tmp); + ast_cli_command_multiple(con->fd, res, tmp); } if (fds[1].revents) { res = read(con->p[0], tmp, sizeof(tmp)); diff --git a/main/cli.c b/main/cli.c index 432869c1a..06c1b9ca2 100644 --- a/main/cli.c +++ b/main/cli.c @@ -1850,3 +1850,20 @@ done: ast_free(dup); return 0; } + +int ast_cli_command_multiple(int fd, size_t size, const char *s) +{ + char cmd[512]; + int x, y = 0, count = 0; + + for (x = 0; x < size; x++) { + cmd[y] = s[x]; + y++; + if (s[x] == '\0') { + ast_cli_command(fd, cmd); + y = 0; + count++; + } + } + return count; +} -- cgit v1.2.3