From 04b29acc66b27c26c51f1bb2ee44aeba9a22f89a Mon Sep 17 00:00:00 2001 From: russell Date: Sat, 13 Oct 2007 05:24:33 +0000 Subject: 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: http://svn.digium.com/svn/asterisk/branches/1.4@85532 f38db490-d61c-443f-a65b-d21fe96a405b --- include/asterisk/cli.h | 8 ++++++++ main/asterisk.c | 2 +- main/cli.c | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/asterisk/cli.h b/include/asterisk/cli.h index e2a6f818b..9a7b53a36 100644 --- a/include/asterisk/cli.h +++ b/include/asterisk/cli.h @@ -108,6 +108,14 @@ char *ast_cli_complete(const char *word, char *const choices[], int pos); */ int ast_cli_command(int fd, const char *s); +/*! + * \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 diff --git a/main/asterisk.c b/main/asterisk.c index 53e4d042b..9f0f049de 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -936,7 +936,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 1d3a7b94b..826ed6f2a 100644 --- a/main/cli.c +++ b/main/cli.c @@ -2005,3 +2005,20 @@ int ast_cli_command(int fd, const char *s) 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