Summary:ASTERISK-09909: Agi in live & dead channels? Don't drop DeadAGI from live.
Reporter:P. Christeas (xrg)Labels:
Date Opened:2007-07-20 03:14:49Date Closed:2007-07-23 16:47:05
Versions:Frequency of
Environment:Attachments:( 0) 20070720__bug10245.diff.txt
Description:According to ASTERISK-9884, the DeadAGI will be phased out from working on live channels. In the a2billing project (www.asterisk2billing.org), DeadAGI is the core element which calculates destination, dials and after the call records the call charges, all in one AGI call.

Is there some other AGI method that can manipulate a call both at Dial and after that?
If no, could you reconsider banning DeadAGI on live channels?
Comments:By: Tilghman Lesher (tilghman) 2007-07-20 07:53:49

1) Using DeadAGI for live calls has always been the wrong choice.  We're just enforcing it.  Likewise, using AGI for hungup calls has always been the wrong choice, but that was enforced from the get-go.
2) Your script can still live past hangup when using AGI; it simply won't be able to interact with Asterisk anymore:  just set a signal handler for the SIGHUP signal.
3) If you wish to interact with an AGI script past hangup, you can call DeadAGI on a separate script at that point.

By: Donny Kavanagh (donnyk) 2007-07-20 08:37:36

I'm working on a seriously large update of res_agi (which it badly needs), however, it will not change the fact that a call to DeadAGI should not keep running after the channel dies.  What was actually happening was DeadAGI would never exit on a live channel until the script terminated.  Hence, your AGI had the ability to block asterisk from entering the h extension to handle a hangup, clearly this is not the behavior we want.

As Corydon76 stated, AGI() will still tell you about the hangup, it wont terminate until it does, and then you can either ignore the SIGHUP and not exit and clean up, or rerun your script again in DeadAGI on the h extension.  Obviously all the channel variables will still be available, so it is only a matter of launching your script again.

By: P. Christeas (xrg) 2007-07-20 15:12:32

What you are saying in fact is that there is no way that a script could replace the dialplan logic. For example, the a2billing script would redial (using a different trunk) if the first dial failed.
Being able to write advanced dialplan scripts on procedural languages was such a nice feature. I recognize that dialplan is sometimes not a procedural matter that other langs could handle, but this barrier (of no script effectively crossing the live/dead channel transition) will limit things.

By: Tilghman Lesher (tilghman) 2007-07-20 17:26:39

Okay, so we might could actually fix that, instead of having users use DeadAGI improperly.  Prospective patch attached (needs testing).

By: Donny Kavanagh (donnyk) 2007-07-21 02:59:17

1) of course agi can replace dialplan logic, nothing functionality wise has been changed.

2) if you want to try to dial more then once then to AGI you would send
--> EXEC DIAL Zap/g1/mynumber|30|g
<-- after dial exits (30 seconds, or the end of call you get a response)
--- when you get a return, check your dialstatus and if necessary send the
--- call again
--> EXEC DIAL Zap/g2/mynumber|30|g

3) your agi is fine, the channel is *NOT* dead, so long as the originating channel does not hang up if you use the g option.  Asterisk automatically terminates the calling channel after a successful dial UNLESS you request it not to which is what the g option i've mentioned does.

4) i just tested this w/ agi on my own system and i am able to dial twice in a row w/ agi without ANY issues.

5) i don't think i can be more clear, but as far as i am concerned there are no code changes required to achieve the functionality you require.  But if you have any further questions let me know.  Please be descriptive if you feel this does not suit your needs.

By: P. Christeas (xrg) 2007-07-21 04:07:04

Ack! Thanks for your help on this. I will test as soon as I have a little time and let you know.

By: Donny Kavanagh (donnyk) 2007-07-22 11:24:46

Looking forward to your feedback.

By: P. Christeas (xrg) 2007-07-22 12:40:34

I performed a first test already:
I 'dialed' some extension from the AGI script, using 'EXEC Dial num,30,g ' and hung up the remote side. The script behaved as supposed, returning to the script.

So far so good.

By: Donny Kavanagh (donnyk) 2007-07-22 14:03:29

After a discussion w/ corydon on irc it seems this may be something we might want to do.  (and him fixing a misunderstanding i had about some stuff when an agi exits)

However that still wont change how you should setup the behaviour you wanted, you should still follow the examples i gave.  What this does mean however is your agi ignores the SIGHUP you will still be able to talk to asterisk in a limited functionality 'dead' mode.  So you'll be able to find out what happened to last call etc, but not place any others.. if you wish to place any others you need to follow the example i gave below and of course make sure your originating channel does not hang up.

By: Tilghman Lesher (tilghman) 2007-07-23 16:47:05

This is fixed in trunk in revision 76707.  DeadAGI will continue to work in 1.4, albeit with a warning.