[AGI 1.4] C sample?

Hello

I’m pretty much a newbie when it comes to C, but I have to use this language to write a couple of AGI proggies because I need them to be statically compiled.

Strangely enough, Google didn’t return much when looking for the “Hello, world!” of AGI in C.

The following doesn’t work: The file never gets written:

//check_cid.c
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <string.h>

int main(int argc, char *argv[])
{
	char line[80];
	int i;

	setlinebuf(stdout);
	setlinebuf(stderr);

	FILE *file;
	file = fopen("file.txt","a+");
	while (1) {
		fgets(line,80,stdin);
		fprintf(file,"%s",line);
		if (strlen(line) <= 1) break;
	}
	fclose(file);

	return(EXIT_SUCCESS);
}

This is how it’s compiled:

gcc -Wall -Wstrict-prototypes -Wno-unknown-pragmas check_cid.c -o check_cid.exe -lsqlite3 -mtune=i386 -ldl -lpthread -static

This is how it’s called in extensions.conf:

[inside]
exten => 9999,1,Verbose(Yes!)
exten => 9999,n,AGI(check_cid.exe|123)

And this is the output of “agi debug” in CLI:

*CLI>     -- Executing [9999@inside:1] Verbose("SIP/2000-0904bee0", "Yes!") in new stack
Yes!
    -- Executing [9999@inside:2] AGI("SIP/2000-0904bee0", "check_cid.exe|123") in new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/check_cid.exe
AGI Tx >> agi_request: check_cid.exe
AGI Tx >> agi_channel: SIP/2000-0904bee0
AGI Tx >> agi_language: en
AGI Tx >> agi_type: SIP
AGI Tx >> agi_uniqueid: 1201412176.3
AGI Tx >> agi_callerid: 2000
AGI Tx >> agi_calleridname: Fred
AGI Tx >> agi_callingpres: 0
AGI Tx >> agi_callingani2: 0
AGI Tx >> agi_callington: 0
AGI Tx >> agi_callingtns: 0
AGI Tx >> agi_dnid: 9999
AGI Tx >> agi_rdnis: unknown
AGI Tx >> agi_context: inside
AGI Tx >> agi_extension: 9999
AGI Tx >> agi_priority: 2
AGI Tx >> agi_enhanced: 0.0
AGI Tx >> agi_accountcode: 
AGI Tx >> 
    -- AGI Script check_cid.exe completed, returning 0
  == Auto fallthrough, channel 'SIP/2000-0904bee0' status is 'UNKNOWN'

If someone has a very basic example in C that shows how to read the CID #, and rewrite the CID name, I’m interested.

Thank you.