<!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
+ * "AS IS" 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 "esl2agi.h"
+
+/*
+ * 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] = "\0";
+ const char *buf;
+        int pid;
+        int thread_running;
+
+        tmp = VOID_TO_ESL_A(data);
+        esl_req.client_sock = tmp->client_sock;
+        esl_req.addr = &*tmp->addr;
+        free(tmp);
+
+ esl_attach_handle(&eslC, esl_req.client_sock, esl_req.addr);
+ if (!(buf = esl_event_get_header(eslC.info_event, "variable_ivr_path"))) {
+ esl_disconnect(&eslC);
+ esl_log(ESL_LOG_ERROR, "No ivr_path variable set, check your dialplan!\n");
+ 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 < 0) {
+                /* Close the pipes/socket and warn */
+ esl_log(ESL_LOG_ERROR, "Fork failed, aie aie aie!\n");
+        }
+        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("Error running script");
+#endif
+                close(pipes.socket[0]);
+                close(pipes.script[1]);
+                exit(0);
+        }
+        else if (pid > 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],&eslC);
+
+                /* TODO: check status */
+                status = esl_send(&eslC,"myevents");
+
+                while ( eslC.connected && thread_running) {
+                        int r , nfds = 0;
+                        fd_set rd;
+
+                        FD_ZERO(&rd);
+                        FD_SET(esl_req.client_sock, &rd);
+                        nfds = MAX(nfds,esl_req.client_sock);
+                        FD_SET(pipes.script[0], &rd);
+                        nfds = MAX(nfds,pipes.script[0]);
+
+                        r = select(nfds + 1, &rd, NULL, NULL, NULL);
+                        if (r == -1 )
+                                break;
+                        if (FD_ISSET(esl_req.client_sock, &rd)) { /* ESL SIDE have something */
+                                status = esl_recv_event(&eslC, 0, &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],&rd) ) { /* AGI has something to say */
+                                r = read(pipes.script[0],&sbuf,2047);
+                                if (r<0)
+                                        goto end;
+                                else {
+                                        if ( !strncasecmp("ANSWER",sbuf,6) ) {
+                                                if ( handle_answer(&eslC,pipes.socket[1]) < 0)
+                                                        goto end;
+                                        }
+                                        else if ( !strncasecmp("HANGUP",sbuf,6) ) {
+                                                if ( handle_hangup(&eslC,pipes.socket[1]) < 0)
+                                                        goto end;
+                                        }
+                                }
+                        }
+                }
+end:
+                kill(pid,SIGHUP);
+                close(pipes.socket[1]);
+                close(pipes.script[0]);
+                if (eslC.connected)
+                        esl_execute(&eslC,"hangup",NULL,NULL);
+         esl_disconnect(&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->client_sock = client_sock;
+        esl_req->addr = addr;
+
+        pthread_t translator;
+
+        pthread_create(&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 < argc; ) {
+                if (!strcasecmp(argv[i], "-h")) {
+                        ip = argv[++i];
+                } else if (!strcasecmp(argv[i], "-p")) {
+                        port = atoi(argv[++i]);
+                } else {
+                        i++;
+                }
+        }
+
+        if (!(ip && port)) {
+                fprintf(stderr, "Usage %s -h <host> -p <port>\n", argv[0]);
+                return -1;
+        }
+
+        signal(SIGCHLD, SIG_IGN);
+
+        esl_listen(ip, port, esl2agi);
+        perror("We should never come here");        
+        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->info_event, "variable_ivr_path")) ) {
+                sprintf(buf,"agi_request: %s\n",sbuf);
+                write(fd, buf,strlen(buf) );
+        }
+        else
+                return -1;
+#ifdef _DEBUG_STDERR
+        perror("Setup ok on request");
+#endif
+
+        if ( (sbuf = esl_event_get_header(eslC->info_event, "variable_channel_name")) ) {
+                sprintf(buf,"agi_channel: %s\n",sbuf);
+                write(fd, buf,strlen(buf) );
+        }
+        else
+                return -1;
+#ifdef _DEBUG_STDERR
+        perror("Setup ok on chan name");
+#endif
+
+        write(fd, "agi_language: en\n",18);
+
+        if ( (sbuf = esl_event_get_header(eslC->info_event, "Channel-Source")) ) {
+                sprintf(buf, "agi_type: %s\n", sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else
+                return -1;
+#ifdef _DEBUG_STDERR
+        perror("Setup ok on source");
+#endif
+
+        if ( (sbuf = esl_event_get_header(eslC->info_event, "Channel-Unique-ID")) ) {
+                sprintf(buf, "agi_uniqueid: %s\n", sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else
+                return -1;
+#ifdef _DEBUG_STDERR
+        perror("Setup ok on uniqueid");
+#endif
+
+        /* ANI/DNIS */
+        if ( (sbuf = esl_event_get_header(eslC->info_event, "Channel-Caller-ID-Number")) ) {
+                sprintf(buf, "agi_callerid: %s\n", sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, "agi_callerid: %s\n", "unknown");
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror("Setup ok on callerid");
+#endif
+        if ( (sbuf = esl_event_get_header(eslC->info_event, "Channel-Caller-ID-Name")) ) {
+                sprintf(buf, "agi_calleridname: %s\n", sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, "agi_calleridname: %s\n", "unknown");
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror("Setup ok on calleridname");
+#endif
+
+        if ( (sbuf = esl_event_get_header(eslC->info_event, "Channel-Screen-Bit")) ) {
+                sprintf(buf, "agi_callingpres: %s\n", sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, "agi_callingpres: %s\n", "unknown");
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror("Setup ok on agi_callingpres");
+#endif
+        /* TODO */
+        if ( (sbuf = esl_event_get_header(eslC->info_event, "Caller-Caller-ID-Number")) ) {
+                sprintf(buf, "agi_callingani2: %s\n", sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, "agi_callingani2: %s\n", "unknown");
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror("Setup ok on agi_callingani2");
+#endif
+        /* TODO */
+        if ( (sbuf = esl_event_get_header(eslC->info_event, "Caller-Caller-ID-Number")) ) {
+                sprintf(buf, "agi_callington: %s\n", sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, "agi_callington: %s\n", "unknown");
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror("Setup ok on agi_callington");
+#endif
+        if ( (sbuf = esl_event_get_header(eslC->info_event, "Caller-Destination-Number")) ) {
+                sprintf(buf, "agi_dnid: %s\n", sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, "agi_dnid: %s\n", "unknown");
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror("Setup ok on agi_dnid");
+#endif
+        /* TODO */
+        if ( (sbuf = esl_event_get_header(eslC->info_event, "Caller-Destination-Number")) ) {
+                sprintf(buf, "agi_callingtns: %s\n", sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, "agi_callingtns: %s\n", "unknown");
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror("Setup ok on agi_callingtns");
+#endif
+
+        /* TODO: correct info */
+        if ( (sbuf = esl_event_get_header(eslC->info_event, "Caller-Destination-Number")) ) {
+                sprintf(buf, "agi_rdnis: %s\n", sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, "agi_rdnis: %s\n", "unknown");
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror("Setup ok on agi_callingtns");
+#endif
+        if ( (sbuf = esl_event_get_header(eslC->info_event, "Channel-Context")) ) {
+                sprintf(buf, "agi_context: %s\n", sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, "agi_context: %s\n", "unknown");
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror("Setup ok on agi_context");
+#endif
+
+        if ( (sbuf = esl_event_get_header(eslC->info_event, "Channel-Destination-Number")) ) {
+                sprintf(buf, "agi_extension: %s\n", sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, "agi_extension: %s\n", "unknown");
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror("Setup ok on agi_extension");
+#endif
+        /* TODO: correct info */
+        if ( (sbuf = esl_event_get_header(eslC->info_event, "Channel-State-Number")) ) {
+                sprintf(buf, "agi_priority: %s\n", sbuf);
+                write(fd, buf, strlen(buf) );
+        }
+        else {
+                sprintf(buf, "agi_priority: %s\n", "unknown");
+                write(fd, buf, strlen(buf) );
+        }
+#ifdef _DEBUG_STDERR
+        perror("Setup ok on agi_priority");
+#endif
+
+        write(fd, "agi_enhanced: 0.0\n", 19);
+        write(fd, "agi_accountcode: \n\n", 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,"hangup",NULL,NULL);
+        if (status == ESL_FAIL) {
+#ifdef _DEBUG_STDERR
+                perror("ESL FAILED TO HANGUP");
+#endif
+                r = write(fd,"200 result=failure\n\n",128);
+                if (r<0)
+                        return -1;
+                }
+        else if (status == ESL_SUCCESS) {
+                r = write(fd,"200 result=success\n\n",128);
+                if (r<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,"answer",NULL,NULL);
+        if (status == ESL_FAIL) {
+#ifdef _DEBUG_STDERR
+                perror("ESL FAILED TO HANGUP");
+#endif
+                r = write(fd,"200 result=failure\n\n",128);
+                if (r<0)
+                        return -1;
+                }
+        else if (status == ESL_SUCCESS) {
+                r = write(fd,"200 result=success\n\n",128);
+                if (r<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
+ * "AS IS" 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 <stdio.h>
+#include <stdlib.h>
+#include <esl.h>
+#include <signal.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <pthread.h>
+/*
+ * 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) > (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 <escape digits> [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>