Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

AMI hangs waiting for response

#74

require 'rubygems'
require 'adhearsion'
require 'adhearsion/voip/asterisk/manager_interface'
ami = Adhearsion::VoIP::Asterisk::Manager::ManagerInterface.new :host => "localhost", ..., :events => false
ami.connect!

resp = ami.send_action "Command", :Command => "sip show channels"

This code does not return. I modified manager_interface/ami_lexer.rb in order to call view_buffer at the very end of << operation (right after the call to resume!) hope that helps:

shell$ ruby t.rb

DEBUG ami: Sending AMI action:

Action: login ActionID: T4A02kpR-g1hq-kHAr-GvBN-U0Jk7QZ1tpKO Username: pbxui Secret: XXXXXXXX Events: Off

VVVVVVVVVVVVVVVVVVVVVVVVVVVVV

Viewing the buffer

############################# Asterisk Call Manager/1.0\r\n
^ ############################# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ VVVVVVVVVVVVVVVVVVVVVVVVVVVVV

Viewing the buffer

############################# Asterisk Call Manager/1.0\r\n
Response: Success\r\n
ActionID: T4A02kpR-g1hq-kHAr-GvBN-U0Jk7QZ1tpKO\r\n
Message: Authentication accepted\r\n
\r\n ^ ############################# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ INFO ami: Successful AMI actions-only connection into pbxui@localhost DEBUG ami: Sending AMI action:
Action: command ActionID: OPZFbpxz-huMN-qhZn-UEVg-tHCWuYsWvJRU Command: sip show channels

VVVVVVVVVVVVVVVVVVVVVVVVVVVVV

Viewing the buffer

############################# Asterisk Call Manager/1.0\r\n
Response: Success\r\n
ActionID: T4A02kpR-g1hq-kHAr-GvBN-U0Jk7QZ1tpKO\r\n
Message: Authentication accepted\r\n
\r\n Response: Follows\r\n
Privilege: Command\r\n
^ ############################# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ VVVVVVVVVVVVVVVVVVVVVVVVVVVVV

Viewing the buffer

############################# Asterisk Call Manager/1.0\r\n
Response: Success\r\n
ActionID: T4A02kpR-g1hq-kHAr-GvBN-U0Jk7QZ1tpKO\r\n
Message: Authentication accepted\r\n
\r\n Response: Follows\r\n
Privilege: Command\r\n
ActionID: OPZFbpxz-huMN-qhZn-UEVg-tHCWuYsWvJRU\r\n
^ ############################# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ VVVVVVVVVVVVVVVVVVVVVVVVVVVVV

Viewing the buffer

############################# Asterisk Call Manager/1.0\r\n
Response: Success\r\n
ActionID: T4A02kpR-g1hq-kHAr-GvBN-U0Jk7QZ1tpKO\r\n
Message: Authentication accepted\r\n
\r\n Response: Follows\r\n
Privilege: Command\r\n
ActionID: OPZFbpxz-huMN-qhZn-UEVg-tHCWuYsWvJRU\r\n
Peer User/ANR Call ID Seq (Tx/Rx) Format Hold Last Message \n
0 active SIP channels\n
^ ############################# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ VVVVVVVVVVVVVVVVVVVVVVVVVVVVV

Viewing the buffer

############################# Asterisk Call Manager/1.0\r\n
Response: Success\r\n
ActionID: T4A02kpR-g1hq-kHAr-GvBN-U0Jk7QZ1tpKO\r\n
Message: Authentication accepted\r\n
\r\n Response: Follows\r\n
Privilege: Command\r\n
ActionID: OPZFbpxz-huMN-qhZn-UEVg-tHCWuYsWvJRU\r\n
Peer User/ANR Call ID Seq (Tx/Rx) Format Hold Last Message \n
0 active SIP channels\n
--END COMMAND--\r\n \r\n ^ ############################# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

here i have to break the application because it hangs (waiting for more data I guess).

LOCAL GEMS

activesupport (2.3.2)
adhearsion (0.8.2)
cgi_multipart_eof_fix (2.5.0)
daemons (1.0.10)
fastthread (1.0.7, 1.0.1)
gem_plugin (0.2.3)
log4r (1.0.5)
mailfactory (1.4.0)
mime-types (1.16, 1.15)
mongrel (1.1.5)
mysql (2.7)
passenger (2.2.2, 2.0.3)
rack (1.0.0, 0.9.1, 0.4.0)
rake (0.8.7, 0.8.3)
rdoc (2.4.3, 2.2.1)
rubigen (1.5.2)
ruby-net-ldap (0.0.4)
sequel (3.0.0, 2.7.0)

Reported by dimas · May 28th, 2009 @ 09:09 AM

State: resolved
Milestone: none
Assigned to: Jay Phillips Jay Phillips

Activity

  1. dimas
    dimas

    OMG how the plaintext was formatted... Will try repeating the last buffer dump in PRE tags:

    #############################
    Asterisk Call Manager/1.0\r\n
    Response: Success\r\n
    ActionID: T4A02kpR-g1hq-kHAr-GvBN-U0Jk7QZ1tpKO\r\n
    Message: Authentication accepted\r\n
    \r\n
    Response: Follows\r\n
    Privilege: Command\r\n
    ActionID: OPZFbpxz-huMN-qhZn-UEVg-tHCWuYsWvJRU\r\n
    Peer             User/ANR    Call ID      Seq (Tx/Rx)  Format           Hold     Last Message   \n
    0 active SIP channels\n
    --END COMMAND--\r\n
    \r\n
    ^
    #############################
    

    May 28th, 2009 @ 09:12 AM

  2. bodhi
    bodhi
    • Tag set to ami, ragel

    I think this is due to a bug in the ami protocol lexer definition. The definition states that before --END COMMAND--\r\n there is \r\n, but in reality only the \n is transmitted.

    Try applying the patch in the attached file, it might fix it for you. But then you'll probably run into problem #72 AMI lexer buffer offset ;)

    May 31st, 2009 @ 09:41 PM

  3. dimas
    dimas

    The patch seems to fix the problem thanks.

    I had to install lots of other gems and Ragel in order to rebuild the lexer though... I wish this fix would be brought by "gem install adhearsion" when it will be time to install it on other boxes :)

    I'm not hitting #72 AMI lexer buffer offset yet because responses are short (i'm just trying out ruby/adhearsion, not doing anything serious in production).

    Thanks again.

    June 1st, 2009 @ 05:36 AM

  4. Jay Phillips
    Jay Phillips
    • State changed from new to open

    Hey bodhi,

    Thanks for submitting a patch! Do you have a Github account? I'd love your patch to be credited in the public timeline by you doing a fork, patching, and sending a pull request.

    Also, as a note:

    -            text = @data[@last_seen_value_end..(@current_pointer - "\r\n--END COMMAND--".size)]
    +            text = @data[@last_seen_value_end..@current_pointer]
    +            text.sub! /\r?\n--END COMMAND--/, ""
    

    I think there is a way to get around the ending issue without doing String#sub!(). I tried to avoid modifications like that because it places logic outside of the Ragel realm and, if this is ported to other languages (Java or C) for use with Adhearsion as interpreter extensions, that code will have to replicate all the little hacks like that too.

    June 4th, 2009 @ 03:28 AM

  5. Ben Klang
    Ben Klang
    • State changed from open to resolved
    • Milestone order changed from 0 to 0

    This appears to have been fixed in commit 573348a9957547ad8a12f7e394b4cad1e6693f3a. My testing confirms that the example command works successfully (even with the missing \r from Asterisk).

    August 2nd, 2010 @ 12:27 PM

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.