Adding nonstandard function to the source code

Lets start by saying my knowledge of the C language sucks.

I’m looking at dial.c in the asterisk source, specifically the section that deals with a call being answered. I want to make the server send a udp packet out when the call is answered so I’ve tried this:

if (fr->frametype == AST_FRAME_CONTROL) { switch (fr->subclass) { case AST_CONTROL_ANSWER: if (option_verbose > 2) ast_verbose( VERBOSE_PREFIX_3 "%s answered %s\n", channel->owner->name, chan->name); AST_LIST_REMOVE(&dial->channels, channel, list); AST_LIST_INSERT_HEAD(&dial->channels, channel, list); set_state(dial, AST_DIAL_RESULT_ANSWERED); [b]system("echo inboundcall | /bin/nc -q 0 -w 1 testbox 7000");[/b] break;

The line in bold being my addition, but it does not seem to do anything.
This is a test line of code, the value ‘testbox’ is the dns name of a machine running a listener on port 7000, so it should show the text “inboundcall” when I pick up the handset.

When I get this working, the DNS name of testbox needs to be replaced with a text prefix like “PC” and then the xtn number of the phone that answered, so if xtn 101 picks up, then the string will be sent to a computer with a hostname of PC101.

When that works, the string will be changed to be the callerid and then you get to the end of the story, our custom CRM package will listen for packets on this port and pop the customer contact details when it recieved them.

I think I can bodge my way around inserting the relevent variables, but I could really do with a little help in just getting the first testing phase to function.

Thanks in advance.

An easier method would be to build a simple AMI listener in VB/Java/etc and use that, rather than mucking around in the Asterisk source code.

Basically, it’d be a simple application you’d run on everyone’s machine that would connect to the AMI and look for “Dial” AMI events. They look like this:

Event: Dial Privilege: call,all Source: Zap/4-1 Destination: SIP/xxxx-0824d580 CallerID: xxxxxxxxxx CallerIDName: <unknown> SrcUniqueID: 1186154122.2067 DestUniqueID: 1186154122.2068

Obviously, “Destination” is the SIP peer being dialed, and “CallerID” then is the callerid of the person doing the calling. Some simple parsing and you can get this all done.

I’d have this as either a service or a taskbar icon on the client machine which then initates a connection to localhost port 7000 which transmits the callerid information. That way, the only configuration needed would be the SIP extension of the phone at the same desk as that computer.