Tuesday, November 6, 2007

Re: [asterisk-users] use dial plan passed arg value in C agi code

Hi,

thanks for the replies although i am still confused.

my agi script is

exten => _.,1,AGI(simple_c_prgm|999);
exten => _.,2,NoOp(${MYAGIVAR});

Now i want to set the value of MYAGIVAR to 999 in my c program called simple_c_prgm. This is what I am doing:

#include <stdio.h>
int main(int argc, char *argv[])
{

  char        line[80];
  int i;
  /* use line buffering */

  setlinebuf(stdout);
  setlinebuf(stderr);

  while (1) {
    /*gives me all the agi env var*/
    fgets(line,80,stdin);
 
  //prints the variables
    printf("--> %s",line);
    if (strlen(line) <= 1) break;

  }


//according to me the passed variable should be available here but i am not getting anything here
//nothing gets printed on the agi debug command

  for(i=0 ;i<=argc ;i++)
    {
         printf("%s", argv[i]);
    }

  /* Send asterisk a command */
  printf("SET VARIABLE AGIVAR %s",argv[1] );

  /* Read response from Asterisk and show on console */
  fgets(line,80,stdin);
  fputs(line,stderr);


}


It would be great if someone could tell me what the problem is

Thanks

Arpit


On Nov 2, 2007 5:24 PM, Steve Edwards <asterisk.org@sedwards.com> wrote:
On Fri, 2 Nov 2007, James FitzGibbon wrote:

> I handle this (in Perl) using Getopt::Long, which knows nothing of AGI's
> stdin/stdout mechanics:

The AGI variables are passed via stdin (similar to an HTTP GET request)
and can be observed using "agi debug" at the Asterisk prompt. It's a fixed
list you get whether you want them or not. It's a common mistake for the
beginning AGI programmer to not read them (thus emptying stdin) and then
wonder why their AGI's don't work correctly.

Arguments are passed to the AGI as elements of argv[] (for C, my native
"tongue"). Thus, "Getopt:Long" (for Perl) or "getopt_long()" (for C) work
as expected. Using a comma to separate the arguments is an "asteriskism."

Passing multiple arguments this way has worked for as long as I've been
using Asterisk -- several years.

Thanks in advance,
------------------------------------------------------------------------
Steve Edwards      sedwards@sedwards.com      Voice: +1-760-468-3867 PST
Newline                                             Fax: +1-760-731-3000

_______________________________________________
--Bandwidth and Colocation Provided by http://www.api-digital.com--

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
  http://lists.digium.com/mailman/listinfo/asterisk-users



--
Arpit Mehta
Graduate Student
Department of Computer Science
Columbia University

Tel: 1-646-387-5998

No comments: