[asterisk-dev] [patch] manager.c and http interface
Johansson Olle E
olle at voop.com
Mon Oct 16 10:50:38 MST 2006
Isn't there a temporary directory you can set in asterisk.conf?
If not, it's definitely time to introduce it.
/O
16 okt 2006 kl. 17.21 skrev Luigi Rizzo:
> it appears that as it is now, manager.c cannot handle generic CLI
> commands through the web interface.
> This is because CLI commands expect to produce their output to a
> file descriptor (s->fd), but for http connections the
> file descriptor is not there
>
> I am attaching below a quick and dirty patch that opens a temporary
> file to buffer the output, and then dumps it to the output buffer
> from where it can be reformatted in the various supported formats.
>
> It is not terribly efficient, but it adds a lot of functionality
> and lilely it can be simplified a lot, and also used to simplify
> external code e.g. the case s->fd == -1 in astman_append.
>
> Any objection to have it committed ?
> Of course the XML and HTTP formatting code should be improved
> a bit to handle the (currently unformatted) response from most CLI
> commands, but that poses no backward compatibility issues as
> the functionality is not there now...
>
> cheers
> luigi
>
> Index: main/manager.c
> ===================================================================
> --- main/manager.c (revision 45219)
> +++ main/manager.c (working copy)
> @@ -2435,6 +2435,11 @@
> 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> Manager Tester</h1></td></tr>\r\n");
> }
> + if (1) {
> + 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) {
> @@ -2451,6 +2456,25 @@
> }
> 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)
> _______________________________________________
> --Bandwidth and Colocation provided by Easynews.com --
>
> asterisk-dev mailing list
> To UNSUBSCRIBE or update options visit:
> http://lists.digium.com/mailman/listinfo/asterisk-dev
---
Olle E. Johansson * Asterisk Evangelist, developer * VOOP A/S
olle at voop.com
More information about the asterisk-dev
mailing list