This patch allows the CALLCLI directive to call the ast_cli_command
function.  The implementation is a bit of a hack, but it was done this
way in order to have minimal impact on the overall code.  Note the pipe
default buffer size for your operating system and version vs the amount
of data that you want from the pipe.  Modifications might need to be
made to increase pipe buffer size.

This patch was originally against app_agi.c, but that no longer exists
in the codebase.  I've applied it to res_agi.c as they look extremely
similar and it compiles without warning, but little testing has been
done on this.  All of my testing in depth testing has been done on
app_agi.c

The diff is against the current res_agi in CVS.  The diff against
app_agi.c is also available if anyone wants it.

-- 
Mike Nugent <[EMAIL PROTECTED]>
Index: res_agi.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_agi.c,v
retrieving revision 1.3
diff -r1.3 res_agi.c
894a895,932
> static int handle_callcli(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
> {
>   /* mike nugent - Sat Sep 18 15:18:18 PDT 2004 - [EMAIL PROTECTED] */
>   int p[2];
>   int index, n, total;
>   char buf[129];   // /usr/include/linux/limits.h:#define PIPE_BUF 4096
>                    // # bytes in atomic write to a pipe
>   char *str = NULL;
> 
>   if ( (pipe(p)) == -1 ) {
>     return RESULT_FAILURE;
>   }
> 
>   ast_cli_command(p[1], argv[1]);
> 
>   str=(char *)malloc(129);
>   memset(str,0,129);
>   memset(buf,0,129);
>   index = 1;
>   total = 0;
>   do {
>     n = read(p[0], buf, 128);
>     total += n;
>     buf[n] = '\0';
>     strcat(str,buf);
>     index++;
>     str = (char *)realloc(str,(index*128)+1);
>   } while ( n == 128 );
> 
>   write(agi->fd, str, total);
>   fdprintf(agi->fd, "200 result=0\n");
>   fdprintf(agi->fd, "\n"); // we may need to call this in a loop to get all
>                            // the lines so return a newline at the end
> 
>   return RESULT_SUCCESS;
> }
> 
> 
1088a1127,1130
> static char usage_callcli[] =
> " Usage: CALLCLI \"<command>\"\n"
> "    Calls the CLI with the command and returns the result\n";
> 
1119c1161,1162
< 	{ { "set", "music", NULL }, handle_setmusic, "Enable/Disable Music on hold generator", usage_setmusic }
---
> 	{ { "set", "music", NULL }, handle_setmusic, "Enable/Disable Music on hold generator", usage_setmusic },
>   { { "callcli", NULL }, handle_callcli, "Calls a command from the CLI and returns the response", usage_callcli }
_______________________________________________
Asterisk-Dev mailing list
[EMAIL PROTECTED]
http://lists.digium.com/mailman/listinfo/asterisk-dev
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-dev

Reply via email to