[asterisk-dev] [patch] manager.c and http interface

Luigi Rizzo rizzo at icir.org
Mon Oct 16 11:01:48 MST 2006


On Mon, Oct 16, 2006 at 07:50:38PM +0200, Johansson Olle E wrote:
> Isn't there a temporary directory you can set in asterisk.conf?
> 
> If not, it's definitely time to introduce it.

well, apart from that i was wondering if there is library
function/system call that can create a swap-backed file without
having to go to the filesystem.
Another option would be socketpair(), but i am not sure
how much it can buffer...

Anyways, this is not a performance-critical path.
There is already a lot of system calls involved in processing
these cli commands, 3-4 more won't harm too much.

	cheers
	luigi

> /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>&nbsp;&nbsp;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
> 
> 
> 
> _______________________________________________
> --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


More information about the asterisk-dev mailing list