aboutsummaryrefslogtreecommitdiffstats
path: root/main/manager.c
diff options
context:
space:
mode:
authorrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-10-17 17:41:59 +0000
committerrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-10-17 17:41:59 +0000
commit2e31cdbf7e77b0809b38620a595819f78d6467eb (patch)
tree5e684e9d31176d7992f15b77ed200794fe24387f /main/manager.c
parentb6e0ce41a330535ea6d082427fba962a5bdd2f5b (diff)
open a temporary file to receive the output from cli commands
invoked through the http interface. It is not terribly efficient but better than no output at all. Todo: use a configurable /tmp directory instead of a hardwired one. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@45330 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/manager.c')
-rw-r--r--main/manager.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/main/manager.c b/main/manager.c
index 45cdd6e6b..85210cc76 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -1172,7 +1172,7 @@ static int action_waitevent(struct mansession *s, struct message *m)
ast_mutex_unlock(&s->__lock);
if (needexit)
break;
- if (s->fd > 0) {
+ if (!s->inuse && s->fd > 0) {
if (ast_wait_for_input(s->fd, 1000))
break;
} else {
@@ -2445,6 +2445,11 @@ static char *generic_http_callback(int format, struct sockaddr_in *requestor, co
ast_build_string(&c, &len, "<body bgcolor=\"#ffffff\"><table align=center bgcolor=\"#f1f1f1\" width=\"500\">\r\n");
ast_build_string(&c, &len, "<tr><td colspan=\"2\" bgcolor=\"#f1f1ff\"><h1>&nbsp;&nbsp;Manager Tester</h1></td></tr>\r\n");
}
+ {
+ char template[32];
+ ast_copy_string(template, "/tmp/ast-http-XXXXXX", sizeof(template));
+ s->fd = mkstemp(template);
+ }
if (process_message(s, &m)) {
if (s->authenticated) {
if (option_verbose > 1) {
@@ -2461,6 +2466,25 @@ static char *generic_http_callback(int format, struct sockaddr_in *requestor, co
}
s->needdestroy = 1;
}
+ if (s->fd > -1) { /* have temporary output */
+ char *buf;
+ off_t len = lseek(s->fd, 0, SEEK_END); /* how many chars available */
+
+ if (len > 0 && (buf = ast_calloc(1, len+1))) {
+ if (!s->outputstr)
+ s->outputstr = ast_calloc(1, sizeof(*s->outputstr));
+ if (s->outputstr) {
+ lseek(s->fd, 0, SEEK_SET);
+ read(s->fd, buf, len);
+ ast_verbose("--- fd %d has %d bytes ---\n%s\n---\n", s->fd, (int)len, buf);
+ ast_dynamic_str_append(&s->outputstr, 0, "%s", buf);
+ }
+ free(buf);
+ }
+ close(s->fd);
+ s->fd = -1;
+ }
+
if (s->outputstr) {
char *tmp;
if (format == FORMAT_XML)