<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][14711] </title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=14711">14711</a></dd>
<dt>Author</dt> <dd>gled</dd>
<dt>Date</dt> <dd>2009-09-01 07:20:33 -0500 (Tue, 01 Sep 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>initial rev. ANSWER/HANGUP.</pre>

<h3>Added Paths</h3>
<ul>
<li><a href="#freeswitchtrunkcontribgledesl2agiMakefile">freeswitch/trunk/contrib/gled/esl2agi/Makefile</a></li>
<li><a href="#freeswitchtrunkcontribgledesl2agiREADME">freeswitch/trunk/contrib/gled/esl2agi/README</a></li>
<li><a href="#freeswitchtrunkcontribgledesl2agiesl2agic">freeswitch/trunk/contrib/gled/esl2agi/esl2agi.c</a></li>
<li><a href="#freeswitchtrunkcontribgledesl2agiesl2agih">freeswitch/trunk/contrib/gled/esl2agi/esl2agi.h</a></li>
</ul>

<h3>Property Changed</h3>
<ul>
<li><a href="#freeswitchtrunkcontribgledesl2agi">freeswitch/trunk/contrib/gled/esl2agi/</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunkcontribgledesl2agi"></a>
<div class="propset"><h4>Property changes: freeswitch/trunk/contrib/gled/esl2agi</h4>
<pre class="diff"><span>
<span class="cx">Name: svn:ignore
</span><span class="cx">   + esl2agi
</span></span></pre></div>
<a id="freeswitchtrunkcontribgledesl2agiMakefile"></a>
<div class="addfile"><h4>Added: freeswitch/trunk/contrib/gled/esl2agi/Makefile (0 => 14711)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/gled/esl2agi/Makefile                                (rev 0)
+++ freeswitch/trunk/contrib/gled/esl2agi/Makefile        2009-09-01 12:20:33 UTC (rev 14711)
</span><span class="lines">@@ -0,0 +1,13 @@
</span><ins>+CC=gcc
+ESL_PATH=../../../libs/esl
+INCLUDES=-I$(ESL_PATH)/../../libs/apr/include -I$(ESL_PATH)/src/include
+CFLAGS=-ggdb3 $(INCLUDES) -Wall -Werror
+LIBS=-L$(ESL_PATH) -L$(ESL_PATH)/../../.libs -L$(ESL_PATH)/../../libs/apr/.libs -lpthread -lesl -lapr-1
+
+all: esl2agi
+
+esl2agi: esl2agi.c
+        $(CC) -o esl2agi esl2agi.c $(CFLAGS) $(LIBS)
+
+clean:
+        rm -rf esl2agi esl2agi.dSYM
</ins></span></pre></div>
<a id="freeswitchtrunkcontribgledesl2agiREADME"></a>
<div class="addfile"><h4>Added: freeswitch/trunk/contrib/gled/esl2agi/README (0 => 14711)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/gled/esl2agi/README                                (rev 0)
+++ freeswitch/trunk/contrib/gled/esl2agi/README        2009-09-01 12:20:33 UTC (rev 14711)
</span><span class="lines">@@ -0,0 +1,8 @@
</span><ins>+ESL2AGI:
+        - listen for INCOMING socket connection.
+        - parse ESL received events, and traduce them to AGI events.
+
+Design:
+        - one thread calling esl_listen.
+        - one callback launching the translation thread.
+        - translation thread fork to execl the AGI script.
</ins></span></pre></div>
<a id="freeswitchtrunkcontribgledesl2agiesl2agic"></a>
<div class="addfile"><h4>Added: freeswitch/trunk/contrib/gled/esl2agi/esl2agi.c (0 => 14711)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/gled/esl2agi/esl2agi.c                                (rev 0)
+++ freeswitch/trunk/contrib/gled/esl2agi/esl2agi.c        2009-09-01 12:20:33 UTC (rev 14711)
</span><span class="lines">@@ -0,0 +1,451 @@
</span><ins>+/*
+ * Copyright (c) 2009, Tristan Mahe for TELEMAQUE
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 
+ * * Neither the name of the original author; nor the names of any contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ * 
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * Contrib:
+ *  main: Anthony Minessale II
+ *
+ */
+
+#define _DEBUG_STDERR
+
+#include &quot;esl2agi.h&quot;
+
+/* 
+ * Translator thread entry point
+ */
+static void *esl2agi_thread(void *data) {
+        esl_accept_t esl_req;
+        esl_accept_t *tmp;
+        esl2agi_pipes_t pipes;
+        esl_handle_t eslC = {{0}};
+
+        char script_path[1024] = &quot;\0&quot;;
+        const char *buf;
+        int pid;
+        int thread_running;
+
+        tmp = VOID_TO_ESL_A(data);
+        esl_req.client_sock = tmp-&gt;client_sock;
+        esl_req.addr = &amp;*tmp-&gt;addr;
+        free(tmp);
+
+        esl_attach_handle(&amp;eslC, esl_req.client_sock, esl_req.addr);
+        if (!(buf = esl_event_get_header(eslC.info_event, &quot;variable_ivr_path&quot;))) {
+                esl_disconnect(&amp;eslC);
+                esl_log(ESL_LOG_ERROR, &quot;No ivr_path variable set, check your dialplan!\n&quot;);
+                exit(0);
+        }
+
+        strncpy(script_path, buf, sizeof(script_path) - 1);
+
+        /* TODO: check for failure */
+        pipe(pipes.script);
+        pipe(pipes.socket);
+
+        thread_running = 1;
+        pid = fork();
+        if (pid &lt; 0) {
+                /* Close the pipes/socket and warn */
+                esl_log(ESL_LOG_ERROR, &quot;Fork failed, aie aie aie!\n&quot;);
+        }
+        else if (pid == 0) {
+                /* Child */
+                close(pipes.socket[1]);
+                close(pipes.script[0]);
+                close(esl_req.client_sock);
+
+                dup2(pipes.socket[0], STDIN_FILENO);
+                dup2(pipes.script[1], STDOUT_FILENO);
+
+                execl(script_path, script_path, NULL);
+                thread_running=0;
+#ifdef _DEBUG_STDERR
+                perror(&quot;Error running script&quot;);
+#endif
+                close(pipes.socket[0]);
+                close(pipes.script[1]);
+                exit(0);
+        }
+        else if (pid &gt; 0 ) { 
+                esl_event_t *event;
+                esl_status_t status;
+                char sbuf[2048];
+
+                close(pipes.socket[0]);
+                close(pipes.script[1]);
+
+                signal(SIGCHLD, SIG_IGN);
+                signal(SIGPIPE, SIG_IGN);
+
+                handle_setup_env(pipes.socket[1],&amp;eslC);
+
+                /* TODO: check status */
+                status = esl_send(&amp;eslC,&quot;myevents&quot;);
+
+                while ( eslC.connected &amp;&amp; thread_running) {
+                        int r , nfds = 0;
+                        fd_set rd;
+
+                        FD_ZERO(&amp;rd);
+                        FD_SET(esl_req.client_sock, &amp;rd);
+                        nfds = MAX(nfds,esl_req.client_sock);
+                        FD_SET(pipes.script[0], &amp;rd);
+                        nfds = MAX(nfds,pipes.script[0]);
+
+                        r = select(nfds + 1, &amp;rd, NULL, NULL, NULL);
+                        if (r == -1 )
+                                break;
+                        if (FD_ISSET(esl_req.client_sock, &amp;rd)) { /* ESL SIDE have something */
+                                status = esl_recv_event(&amp;eslC, 0, &amp;event);
+                                if (status == ESL_FAIL)
+                                        goto end;
+                                else if (status == ESL_SUCCESS) {
+                                        /* Translation ESL TO AGI
+                                         * - DTMF events.
+                                         * - Command results
+                                         * - 
+                                         */
+                                }
+                        }
+                        if (FD_ISSET(pipes.script[0],&amp;rd) ) { /* AGI has something to say */
+                                r = read(pipes.script[0],&amp;sbuf,2047);
+                                if (r&lt;0)
+                                        goto end;
+                                else {
+                                        if ( !strncasecmp(&quot;ANSWER&quot;,sbuf,6) ) {
+                                                if ( handle_answer(&amp;eslC,pipes.socket[1]) &lt; 0)
+                                                        goto end;
+                                        }
+                                        else if ( !strncasecmp(&quot;HANGUP&quot;,sbuf,6) ) {
+                                                if ( handle_hangup(&amp;eslC,pipes.socket[1]) &lt; 0)
+                                                        goto end;
+                                        }
+                                }
+                        }
+                }
+end:
+                kill(pid,SIGHUP);
+                close(pipes.socket[1]);
+                close(pipes.script[0]);
+                if (eslC.connected)
+                        esl_execute(&amp;eslC,&quot;hangup&quot;,NULL,NULL);
+                esl_disconnect(&amp;eslC);
+        }
+        return NULL;
+}
+
+/*
+ * Callback on accept, launch a detached thread then return.
+ */
+static void esl2agi(esl_socket_t server_sock, esl_socket_t client_sock, struct sockaddr_in *addr) {
+        esl_accept_t *esl_req;
+
+        /* Will be freed in the thread after read */
+        esl_req = malloc(sizeof(esl_accept_t) + 1);
+        esl_req-&gt;client_sock = client_sock;
+        esl_req-&gt;addr = addr;
+
+        pthread_t translator;
+
+        pthread_create(&amp;translator,NULL,esl2agi_thread,ESL_A_TO_VOID(esl_req));
+        pthread_detach(translator);
+
+        return;
+}
+
+/* Main entry
+ * Esl listen and that's all.
+ * Copyright (c) 2009, Anthony Minessale II
+ */
+int main(int argc, char *argv[])
+{
+        int i;
+        char *ip = NULL;
+        int port = 0;
+        
+        for (i = 1; i + 1 &lt; argc; ) {
+                if (!strcasecmp(argv[i], &quot;-h&quot;)) {
+                        ip = argv[++i];
+                } else if (!strcasecmp(argv[i], &quot;-p&quot;)) {
+                        port = atoi(argv[++i]);
+                } else {
+                        i++;
+                }
+        }
+
+        if (!(ip &amp;&amp; port)) {
+                fprintf(stderr, &quot;Usage %s -h &lt;host&gt; -p &lt;port&gt;\n&quot;, argv[0]);
+                return -1;
+        }
+
+        signal(SIGCHLD, SIG_IGN);
+
+        esl_listen(ip, port, esl2agi);
+        perror(&quot;We should never come here&quot;);        
+        return 0;
+}
+
+/* Setup env 
+ * TODO:        - should check write result.
+ *                - add missing informations and correct wrong ones.
+ */
+static int handle_setup_env(int fd,esl_handle_t *eslC) {
+        char buf[1024];
+        char *sbuf;
+
+        /* Setup Env for AGI scripts */
+        if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;variable_ivr_path&quot;)) ) {
+                sprintf(buf,&quot;agi_request: %s\n&quot;,sbuf);
+                write(fd, buf,strlen(buf) );
+        }
+        else
+                return -1;
+#ifdef _DEBUG_STDERR
+        perror(&quot;Setup ok on request&quot;);
+#endif
+
+        if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;variable_channel_name&quot;)) ) {
+                sprintf(buf,&quot;agi_channel: %s\n&quot;,sbuf);
+                write(fd, buf,strlen(buf) );
+        }
+        else
+                return -1;
+#ifdef _DEBUG_STDERR
+        perror(&quot;Setup ok on chan name&quot;);
+#endif
+
+        write(fd, &quot;agi_language: en\n&quot;,18);
+
+        if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Channel-Source&quot;)) ) {
+                sprintf(buf, &quot;agi_type: %s\n&quot;, sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else
+                return -1;
+#ifdef _DEBUG_STDERR
+        perror(&quot;Setup ok on source&quot;);
+#endif
+
+        if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Channel-Unique-ID&quot;)) ) {
+                sprintf(buf, &quot;agi_uniqueid: %s\n&quot;, sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else
+                return -1;
+#ifdef _DEBUG_STDERR
+        perror(&quot;Setup ok on uniqueid&quot;);
+#endif
+
+        /* ANI/DNIS */
+        if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Channel-Caller-ID-Number&quot;)) ) {
+                sprintf(buf, &quot;agi_callerid: %s\n&quot;, sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, &quot;agi_callerid: %s\n&quot;, &quot;unknown&quot;);
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror(&quot;Setup ok on callerid&quot;);
+#endif
+        if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Channel-Caller-ID-Name&quot;)) ) {
+                sprintf(buf, &quot;agi_calleridname: %s\n&quot;, sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, &quot;agi_calleridname: %s\n&quot;, &quot;unknown&quot;);
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror(&quot;Setup ok on calleridname&quot;);
+#endif
+
+        if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Channel-Screen-Bit&quot;)) ) {
+                sprintf(buf, &quot;agi_callingpres: %s\n&quot;, sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, &quot;agi_callingpres: %s\n&quot;, &quot;unknown&quot;);
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror(&quot;Setup ok on agi_callingpres&quot;);
+#endif
+        /* TODO */
+        if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Caller-Caller-ID-Number&quot;)) ) {
+                sprintf(buf, &quot;agi_callingani2: %s\n&quot;, sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, &quot;agi_callingani2: %s\n&quot;, &quot;unknown&quot;);
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror(&quot;Setup ok on agi_callingani2&quot;);
+#endif
+        /* TODO */
+        if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Caller-Caller-ID-Number&quot;)) ) {
+                sprintf(buf, &quot;agi_callington: %s\n&quot;, sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, &quot;agi_callington: %s\n&quot;, &quot;unknown&quot;);
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror(&quot;Setup ok on agi_callington&quot;);
+#endif
+        if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Caller-Destination-Number&quot;)) ) {
+                sprintf(buf, &quot;agi_dnid: %s\n&quot;, sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, &quot;agi_dnid: %s\n&quot;, &quot;unknown&quot;);
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror(&quot;Setup ok on agi_dnid&quot;);
+#endif
+        /* TODO */
+        if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Caller-Destination-Number&quot;)) ) {
+                sprintf(buf, &quot;agi_callingtns: %s\n&quot;, sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, &quot;agi_callingtns: %s\n&quot;, &quot;unknown&quot;);
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror(&quot;Setup ok on agi_callingtns&quot;);
+#endif
+
+        /* TODO: correct info */
+        if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Caller-Destination-Number&quot;)) ) {
+                sprintf(buf, &quot;agi_rdnis: %s\n&quot;, sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, &quot;agi_rdnis: %s\n&quot;, &quot;unknown&quot;);
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror(&quot;Setup ok on agi_callingtns&quot;);
+#endif
+        if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Channel-Context&quot;)) ) {
+                sprintf(buf, &quot;agi_context: %s\n&quot;, sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, &quot;agi_context: %s\n&quot;, &quot;unknown&quot;);
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror(&quot;Setup ok on agi_context&quot;);
+#endif
+
+        if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Channel-Destination-Number&quot;)) ) {
+                sprintf(buf, &quot;agi_extension: %s\n&quot;, sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, &quot;agi_extension: %s\n&quot;, &quot;unknown&quot;);
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror(&quot;Setup ok on agi_extension&quot;);
+#endif
+        /* TODO: correct info */
+        if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Channel-State-Number&quot;)) ) {
+                sprintf(buf, &quot;agi_priority: %s\n&quot;, sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, &quot;agi_priority: %s\n&quot;, &quot;unknown&quot;);
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror(&quot;Setup ok on agi_priority&quot;);
+#endif
+
+        write(fd, &quot;agi_enhanced: 0.0\n&quot;, 19);
+        write(fd, &quot;agi_accountcode: \n\n&quot;, 21);
+        return 0;
+}
+
+/*
+ * Hangup AGI cmd
+ * TODO:        - Add arg support to know which channel we want to hangup.
+ */
+static int handle_hangup(esl_handle_t *eslC,int fd) {
+        esl_status_t status;
+        int r;
+
+        status = esl_execute(eslC,&quot;hangup&quot;,NULL,NULL);
+        if (status == ESL_FAIL) {
+#ifdef _DEBUG_STDERR
+                perror(&quot;ESL FAILED TO HANGUP&quot;);
+#endif
+                r = write(fd,&quot;200 result=failure\n\n&quot;,128);
+                if (r&lt;0)
+                        return -1;
+                }
+        else if (status == ESL_SUCCESS) {
+                r = write(fd,&quot;200 result=success\n\n&quot;,128);
+                if (r&lt;0)
+                        return -1;
+        }
+        return 0;
+}
+
+/*
+ * Answer AGI cmd
+ */
+static int handle_answer(esl_handle_t *eslC,int fd) {
+        esl_status_t status;
+        int r;
+
+        status = esl_execute(eslC,&quot;answer&quot;,NULL,NULL);
+        if (status == ESL_FAIL) {
+#ifdef _DEBUG_STDERR
+                perror(&quot;ESL FAILED TO HANGUP&quot;);
+#endif
+                r = write(fd,&quot;200 result=failure\n\n&quot;,128);
+                if (r&lt;0)
+                        return -1;
+                }
+        else if (status == ESL_SUCCESS) {
+                r = write(fd,&quot;200 result=success\n\n&quot;,128);
+                if (r&lt;0)
+                        return -1;
+        }
+        return 0;
+}
</ins></span></pre></div>
<a id="freeswitchtrunkcontribgledesl2agiesl2agih"></a>
<div class="addfile"><h4>Added: freeswitch/trunk/contrib/gled/esl2agi/esl2agi.h (0 => 14711)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/gled/esl2agi/esl2agi.h                                (rev 0)
+++ freeswitch/trunk/contrib/gled/esl2agi/esl2agi.h        2009-09-01 12:20:33 UTC (rev 14711)
</span><span class="lines">@@ -0,0 +1,104 @@
</span><ins>+/*
+ * Copyright (c) 2009, Tristan Mahe for TELEMAQUE
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of the original author; nor the names of any contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* 
+ * Define Section
+ */
+
+#define _GNU_SOURCE
+
+/* 
+ * Inc Section
+ */
+
+#include &lt;stdio.h&gt;
+#include &lt;stdlib.h&gt;
+#include &lt;esl.h&gt;
+#include &lt;signal.h&gt;
+#include &lt;errno.h&gt;
+#include &lt;sys/time.h&gt;
+#include &lt;pthread.h&gt;
+/* 
+ * Macros Section
+ */
+
+#define PIPES_TO_VOID(v)        ((void*)(v))
+#define VOID_TO_PIPES(p)        ((esl2agi_pipes_t*)(p))
+
+#define ESL_A_TO_VOID(v)        ((void*)(v))
+#define VOID_TO_ESL_A(p)        ((esl_accept_t*)(p))
+
+#define MAX(x,y)                ((x) &gt; (y) ? (x) : (y))
+
+/* 
+ * Struct Section
+ */
+
+typedef struct {
+        esl_socket_t client_sock;
+        struct sockaddr_in *addr;
+} esl_accept_t;
+
+typedef struct {
+        int script[2];
+        int socket[2];
+} esl2agi_pipes_t;
+
+/* 
+ * Func Section
+ */
+
+static void esl2agi(esl_socket_t server_sock, esl_socket_t client_sock, struct sockaddr_in *addr);
+
+static void *esl2agi_thread(void *data);
+
+/*
+ * - EXEC application OPTIONS
+ * - GET DATA filetoplay timeout maxdigits
+ * - GET VARIABLE variablename
+ * - HANGUP 'channelname'
+ * - RECORD FILE filename format escapedigits timeout offsetsamples BEEP s=silence
+ * - SAY DIGITS
+ * - set autohangup time
+ * - set music  on|off class
+ * - set variable
+ * - stream file filename &lt;escape digits&gt; [sample offset]
+ * - wait for digit timeout
+ */
+
+
+static int handle_setup_env(int fd,esl_handle_t *eslC);
+
+static int handle_hangup(esl_handle_t *eslC,int fd);
+
+static int handle_answer(esl_handle_t *eslC,int fd);
</ins></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>