Index: cli.c =================================================================== RCS file: /usr/cvsroot/asterisk/cli.c,v retrieving revision 1.30 diff -u -r1.30 cli.c --- cli.c 16 Jan 2004 01:24:00 -0000 1.30 +++ cli.c 3 Feb 2004 00:16:26 -0000 @@ -34,14 +34,77 @@ #define VERSION_INFO "Asterisk " ASTERISK_VERSION " built by " BUILD_USER "@" BUILD_HOSTNAME \ " on a " BUILD_MACHINE " running " BUILD_OS + +static char *cliprefix[16384]; +static short int clinl[16384]; + +void ast_cli_set_prefix(int fd, char *pref) { + if (cliprefix[0] != '\0') { + memset(cliprefix,0,sizeof(cliprefix)); + }; + if (clinl[0] != 0x1) { + memset(clinl,0x1,sizeof(clinl)); + }; + + if (fd >= 0 && fd < 16384) { + cliprefix[fd] = pref; + clinl[fd] = pref ? 0x1 : 0x0; + if (pref) + ast_log(LOG_DEBUG,"Set fd %d prefix to %c",fd,*pref); + else + ast_log(LOG_DEBUG,"Unset fd %d prefix",fd); + } else { + ast_log(LOG_WARNING, "Attempted to assign prefix to fd that was too large\n"); + }; +}; void ast_cli(int fd, char *fmt, ...) { char *stuff; va_list ap; + + if (cliprefix[0] != '\0') { + memset(cliprefix,0,sizeof(cliprefix)); + }; + if (clinl[0] != 0x1) { + memset(clinl,0x1,sizeof(clinl)); + }; + va_start(ap, fmt); vasprintf(&stuff, fmt, ap); va_end(ap); - write(fd, stuff, strlen(stuff)); + if (cliprefix[fd]) { + char *cur; + char *next = stuff; + char delim = '\n'; + int nl = 0x0; + int len; + int first = 1; + if (clinl[fd]) { + clinl[fd] = 0x0; + nl = 0x1; + }; + + while ((cur = next)) { + next = strchr(next,delim); + if (next) { + next++; + len = next - cur; + nl = 1; + } else { + len = strlen(cur); + if (!first) nl = 0; + }; + if (len && nl) { + char *cp = cliprefix[fd]; + write(fd, cp, strlen(cp)); + }; + write(fd, cur, len); + first = 1; + }; + clinl[fd] = nl; + } else { + write(fd, stuff, strlen(stuff)); + }; free(stuff); } Index: manager.c =================================================================== RCS file: /usr/cvsroot/asterisk/manager.c,v retrieving revision 1.37 diff -u -r1.37 manager.c --- manager.c 29 Jan 2004 00:28:51 -0000 1.37 +++ manager.c 3 Feb 2004 00:16:26 -0000 @@ -403,13 +403,15 @@ static int action_command(struct mansession *s, struct message *m) { char *cmd = astman_get_header(m, "Command"); + char *prefix = ": "; ast_mutex_lock(&s->lock); s->blocking = 1; ast_mutex_unlock(&s->lock); ast_cli(s->fd, "Response: Follows\r\n"); - /* FIXME: Wedge a ActionID response in here, waiting for later changes */ + ast_cli_set_prefix(s->fd,prefix); ast_cli_command(s->fd, cmd); - ast_cli(s->fd, "--END COMMAND--\r\n\r\n"); + ast_cli_set_prefix(s->fd,NULL); + ast_cli(s->fd, "\r\n\r\n"); ast_mutex_lock(&s->lock); s->blocking = 0; ast_mutex_unlock(&s->lock); Index: doc/manager.txt =================================================================== RCS file: /usr/cvsroot/asterisk/doc/manager.txt,v retrieving revision 1.2 diff -u -r1.2 manager.txt --- doc/manager.txt 22 Jan 2004 21:41:19 -0000 1.2 +++ doc/manager.txt 3 Feb 2004 00:16:27 -0000 @@ -12,9 +12,12 @@ Command Syntax -------------- -Mangement communication consists of tags of the form "header: value", -terminated with an empty newline (\r\n) in the style of SMTP, HTTP, and -other headers. +Management communication consists of tags of the form "header: value", +terminated with an empty newline (\r\n) in the style of SMTP, HTTP, and other +headers. Headers need not be unique, but handling of duplicate headers is not +defined. Actions may provide multi-line, text responses by specifying each +line with a blank header. Bulk input can be provided this same way for actions +that support it (not currently implemented). The first tag MUST be one of the following: Index: include/asterisk/cli.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/cli.h,v retrieving revision 1.5 diff -u -r1.5 cli.h --- include/asterisk/cli.h 10 Sep 2003 05:24:49 -0000 1.5 +++ include/asterisk/cli.h 3 Feb 2004 00:16:27 -0000 @@ -20,6 +20,7 @@ #include +extern void ast_cli_set_prefix(int fd, char *pref); extern void ast_cli(int fd, char *fmt, ...) __attribute__ ((format (printf, 2, 3)));