Sophie

Sophie

distrib > Mandriva > 2008.1 > i586 > media > contrib-updates > by-pkgid > c7095aefea7b97fbd2a596dcbfb9d481 > files > 483

asterisk-docs-1.4.26.1-1mdv2008.1.i586.rpm

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Debugging in AGI</title><link rel="stylesheet" href="styles.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.69.1" /><link rel="start" href="index.html" title="Asterisk™: The Future of Telephony" /><link rel="up" href="asterisk-CHP-9.html" title="Chapter 9. The Asterisk Gateway Interface (AGI)" /><link rel="prev" href="asterisk-CHP-9-SECT-4.html" title="Writing AGI Scripts in Python" /><link rel="next" href="asterisk-CHP-9-SECT-6.html" title="Conclusion" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Debugging in AGI</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="asterisk-CHP-9-SECT-4.html">Prev</a> </td><th width="60%" align="center">Chapter 9. The Asterisk Gateway Interface (AGI)</th><td width="20%" align="right"> <a accesskey="n" href="asterisk-CHP-9-SECT-6.html">Next</a></td></tr></table><hr /></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="asterisk-CHP-9-SECT-5"></a>Debugging in AGI</h2></div></div></div><p>Debugging AGI programs, <a id="ch09_debugging" class="indexterm"></a>as <a id="ch09_agidebug" class="indexterm"></a>with any other type of program, can be frustrating. Luckily,
    there are two advantages to debugging AGI scripts. First, since all of the
    communications between Asterisk and the AGI program happen over <code class="literal">STDIN</code> and <code class="literal">STDOUT</code> (and, of course, <code class="literal">STDERR</code>), you should be able to run your AGI
    script directly from the operating system. Second, Asterisk has a handy
    command for showing all of the communications between itself and the AGI
    script: <code class="literal">agi debug</code>.</p><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="asterisk-CHP-9-SECT-5.1"></a>Debugging from the Operating System</h3></div></div></div><p>As mentioned above, you should be able to run your program
      <a id="I_indexterm9_tt1256" class="indexterm"></a>directly from the operating system to see how it behaves.
      The secret here is to act just like Asterisk does, providing your script
      with the following:</p><div class="itemizedlist"><ul type="disc"><li><p>A list of variables and their values, such as <code class="literal">agi_test:1</code>.</p></li><li><p>A blank line feed (<code class="literal">\n</code>) to
          indicate <a id="I_indexterm9_tt1257" class="indexterm"></a><a id="I_indexterm9_tt1258" class="indexterm"></a>that you’re done passing variables.</p></li><li><p>Responses to each of the AGI commands from your AGI script.
          Usually, typing <strong class="userinput"><code>200
          response=1</code></strong> is sufficient.</p></li></ul></div><p>Trying your program directly from the operating system may help
      you to more easily spot bugs in your program.</p></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="asterisk-CHP-9-SECT-5.2"></a>Using Asterisk’s agi debug Command</h3></div></div></div><p>The Asterisk command-line interface has a very useful command for
      debugging AGI scripts, which is called (appropriately enough) <code class="literal">agi debug</code>. If you type <strong class="userinput"><code>agi debug</code></strong> at an<a id="I_indexterm9_tt1259" class="indexterm"></a> Asterisk console and then run an AGI, you’ll see
      something like the following:</p><a id="I_programlisting9_tt1260"></a><pre class="programlisting">-- Executing AGI("Zap/1-1", "temperature.php") in new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/temperature.php
AGI Tx &gt;&gt; agi_request: temperature.php
AGI Tx &gt;&gt; agi_channel: Zap/1-1
AGI Tx &gt;&gt; agi_language: en
AGI Tx &gt;&gt; agi_type: Zap
AGI Tx &gt;&gt; agi_uniqueid: 1116732890.8
AGI Tx &gt;&gt; agi_callerid: 101
AGI Tx &gt;&gt; agi_calleridname: Tom Jones
AGI Tx &gt;&gt; agi_callingpres: 0
AGI Tx &gt;&gt; agi_callingani2: 0
AGI Tx &gt;&gt; agi_callington: 0
AGI Tx &gt;&gt; agi_callingtns: 0
AGI Tx &gt;&gt; agi_dnid: unknown
AGI Tx &gt;&gt; agi_rdnis: unknown
AGI Tx &gt;&gt; agi_context: incoming
AGI Tx &gt;&gt; agi_extension: 141
AGI Tx &gt;&gt; agi_priority: 2
AGI Tx &gt;&gt; agi_enhanced: 0.0
AGI Tx &gt;&gt; agi_accountcode:
AGI Tx &gt;&gt;
AGI Rx &lt;&lt; STREAM FILE temperature ""
AGI Tx &gt;&gt; 200 result=0 endpos=6400
AGI Rx &lt;&lt; STREAM FILE is ""
AGI Tx &gt;&gt; 200 result=0 endpos=5440
AGI Rx &lt;&lt; SAY NUMBER 67 ""
    -- Playing 'digits/60' (language 'en')
    -- Playing 'digits/7' (language 'en')
AGI Tx &gt;&gt; 200 result=0
AGI Rx &lt;&lt; STREAM FILE degrees ""
AGI Tx &gt;&gt; 200 result=0 endpos=6720
AGI Rx &lt;&lt; STREAM FILE fahrenheit ""
AGI Tx &gt;&gt; 200 result=0 endpos=8000
    -- AGI Script temperature.php completed, returning 0</pre><p>You’ll see three types of lines while your AGI script is running.
      The first type, prefaced with <code class="literal">AGI TX
      &gt;&gt;</code>, are the lines that Asterisk transmits to your
      program’s <code class="literal">STDIN</code>. The second type,
      prefaced with <code class="literal">AGI RX &lt;&lt;</code>, are
      the commands your AGI program writes back to Asterisk over <code class="literal">STDOUT</code>. The third type, prefaced by <code class="literal"><code class="literal">--</code></code>, are the standard
      Asterisk messages presented as it executes certain commands.</p><p>To disable AGI debugging after it has been started, simply type
      <strong class="userinput"><code>agi no debug</code></strong> at an Asterisk
      console.</p><p>Using the <code class="literal">agi debug</code> command
      will enable you to see the communication between Asterisk and your
      program, which can be very useful when debugging. Hopefully, these two
      tips will greatly improve your ability to write and debug powerful AGI
      programs.<a id="I_indexterm9_tt1261" class="indexterm"></a><a id="I_indexterm9_tt1262" class="indexterm"></a></p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="asterisk-CHP-9-SECT-4.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="asterisk-CHP-9.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="asterisk-CHP-9-SECT-6.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Writing AGI Scripts in Python </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Conclusion</td></tr></table></div><div xmlns="" id="svn-footer"><hr /><p>You are reading <em>Asterisk: The Future of Telephony</em> (2nd Edition for Asterisk 1.4), by Jim van Meggelen, Jared Smith, and Leif Madsen.<br />
       This work is licensed under the <a href="http://creativecommons.org/licenses/by-nc-nd/3.0/">Creative Commons Attribution-Noncommercial-No Derivative Works License v3.0</a>.<br />
       To submit comments, corrections, or other contributions to the text, please visit <a href="http://oreilly.com/catalog/9780596510480/">http://www.oreilly.com/</a>.</p></div></body></html>