tropo / tropo-agitate

Script for Tropo that emulates the Asterisk AGI
http://tropo.com
MIT License
20 stars 15 forks source link

Generate Asterisk specific 5XX protocol errors #6

Closed jsgoecke closed 13 years ago

jsgoecke commented 13 years ago

"200 result=-1" the best way to signal a protocol error is a 5XX. For example, if you send a command to a hung-up channel you'll get back "511 Command Not Permitted on a dead channel." - bklang

jsgoecke commented 13 years ago

http://www.voip-info.org/wiki/view/Asterisk+AGI#Returnvalue

bklang commented 13 years ago

In case this is helpful: Asterisk (as of 1.6.2) only ever generates 3 5XX errors (though according to the spec 500-599 are protocol errors):

          # 520 Invalid command syntax.
          # 511 Command Not Permitted on a dead channel
          # 510 Invalid or unknown command
jsgoecke commented 13 years ago

Implemented the 510 code:

DEBUG agi: >>> EXEC foobar "blahblah" DEBUG agi: <<< 510 result=Invalid or unknown Command

http://github.com/tropo/tropo-agitate/commit/d0defd5b7031086a1f3c384c2c2a6abc16586ba2

Will work to implement the others as well.

jsgoecke commented 13 years ago

I implemented 511, but of course anytime there is a hangup I am going to fire an event and get this in Adhearsion:

DEBUG agi: >>> EXEC foobar "blahblah" INFO agi: HANGUP event for call with uniqueid "c48dd66fe615cbc6289e5865e257f481" and channel "TROPO/c48dd66fe615cbc6289e5865e257f481" [Sun Oct 10 10:55:49 2010] Adhearsion::VoIP::Asterisk::AGI::Server::RubyServer 0.0.0.0:4573 client:15106 disconnect

At which point could Adhearsion actually get a 511 over AGI?

Also, I notice if I throw a 510 error Adhearsion says it might be a bug, when in this case it is clearly not:

DEBUG agi: >>> EXEC foobar "blahblah" DEBUG agi: <<< 510 result=Invalid or unknown Command

WARN agi: AGI 500 error encountered. This may be a bug in Adhearsion. Please report it at http://adhearsion.lighthouseapp.com

bklang commented 13 years ago

Yeah, at this point it's a lot more likely to be a user calling "execute" with a invalid app than a bug in our AGI. I'll update that error message.

The HANGUP event you're seeing is (or should be) Adhearsion's reaction to either a "511" response or a bare "HANGUP" written to the socket. It is possible to catch the Hangup exception and do things to the channel; this was what used to be called DeadAGI. Most commands don't work on dead channels, hence the 511.

jsgoecke commented 13 years ago

511 is now in there. http://github.com/tropo/tropo-agitate/commit/edcfbf44d6099acc09807e8663ba380741620890

jsgoecke commented 13 years ago

DRY'd up the 511 implementation, now returns:

DEBUG agi: >>> EXEC playback "Hello world!" DEBUG agi: <<< 511 result=Command Not Permitted on a dead channel

DEBUG agi: AGI 500 error. Raising hangup INFO agi: HANGUP event for call with uniqueid "bfa02bc0afea96361a4cf83db0ff8b0c" and channel "TROPO/bfa02bc0afea96361a4cf83db0ff8b0c"

bklang commented 13 years ago

Looks good to me