[Asterisk-Users] Script AGI on C

cleviton.araujo at caixa.gov.br cleviton.araujo at caixa.gov.br
Mon May 22 08:21:56 MST 2006


Hi Folks:

I used that one example for AGI script on C web, only to fill the working with the Asterisk. I compiled and it worked great. I executed accidentally the ls -l command in directory where was the source and executable, I noted and was surprised that because the executable size was to further 20 times more than source.

I executed the gcc -Os source.c -o executable.agi command several times, with otimization flags different. Maximum i can affort to reduce the executable size was 17 times.

The source size full comment is 448 Bytes;
The size executable was about 7615 Bytes. (the maximum i got to reduce)

I was hope the executable size was in the order of magnitude of the proper source size, since the comments are long.

Do one get to explain because of this?
Is this overhead consequence of linking with the operational system?
The script use only four functions of stdio.h library. It was seem that the compiler include all stdio.h functions and compile all them.

I would like somebody of list to clear my doubt.

Regards,
Cleviton.


Here below small script used I grasp on site: http://home.cogeco.ca/~camstuff/agi.html

/* C works just fine with Asterisk but you should use 'setlinebuf' on stdout and stderr. This causes buffering one line at a time 
(rather than using a larger buffer). If you *don't* do this on stdout then your script will hang up while Asterisk waits for a 
command but the (long) buffer isn't full yet. A minimal AGI script in C looks like this: */
//
   #include <stdio.h>
   main() {
       char        line[80];
       /* use line buffering */
       setlinebuf(stdout);
       setlinebuf(stderr);
       /* read and ignore AGI environment */
       while (1) {
           fgets(line,80,stdin);
           if (strlen(line) <= 1) break;
       }
       /* Send asterisk a command */
       printf("SAY NUMBER 123 \"\"\n");
       /* Read response from Asterisk and show on console */
       fgets(line,80,stdin);
       fputs(line,stderr);
   }




More information about the asterisk-users mailing list