<!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][14713] </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=14713">14713</a></dd>
<dt>Author</dt> <dd>gled</dd>
<dt>Date</dt> <dd>2009-09-01 11:24:34 -0500 (Tue, 01 Sep 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>some clean and error checks</pre>

<h3>Modified Paths</h3>
<ul>
<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 class="cx">   + esl2agi
</span><span class="cx">events.txt
</span></span></pre></div>
<a id="freeswitchtrunkcontribgledesl2agiREADME"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/contrib/gled/esl2agi/README (14712 => 14713)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/gled/esl2agi/README        2009-09-01 13:57:14 UTC (rev 14712)
+++ freeswitch/trunk/contrib/gled/esl2agi/README        2009-09-01 16:24:34 UTC (rev 14713)
</span><span class="lines">@@ -3,6 +3,6 @@
</span><span class="cx">         - parse ESL received events, and traduce them to AGI events.
</span><span class="cx"> 
</span><span class="cx"> Design:
</span><del>-        - one thread calling esl_listen.
-        - one callback launching the translation thread.
-        - translation thread fork to execl the AGI script.
</del><ins>+        - main process calls esl_listen.
+        - one callback launching a translation thread.
+        - translation thread fork to execl the AGI script, and kill that script on exit with SIGHUP.
</ins></span></pre></div>
<a id="freeswitchtrunkcontribgledesl2agiesl2agic"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/contrib/gled/esl2agi/esl2agi.c (14712 => 14713)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/gled/esl2agi/esl2agi.c        2009-09-01 13:57:14 UTC (rev 14712)
+++ freeswitch/trunk/contrib/gled/esl2agi/esl2agi.c        2009-09-01 16:24:34 UTC (rev 14713)
</span><span class="lines">@@ -35,8 +35,6 @@
</span><span class="cx">  *
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-#define _DEBUG_STDERR
-
</del><span class="cx"> #include &quot;esl2agi.h&quot;
</span><span class="cx"> 
</span><span class="cx"> /* 
</span><span class="lines">@@ -55,27 +53,41 @@
</span><span class="cx"> 
</span><span class="cx">         tmp = VOID_TO_ESL_A(data);
</span><span class="cx">         esl_req.client_sock = tmp-&gt;client_sock;
</span><del>-        esl_req.addr = &amp;*tmp-&gt;addr;
</del><ins>+        esl_req.addr = tmp-&gt;addr;
</ins><span class="cx">         free(tmp);
</span><span class="cx"> 
</span><span class="cx">         esl_attach_handle(&amp;eslC, esl_req.client_sock, esl_req.addr);
</span><span class="cx">         if (!(buf = esl_event_get_header(eslC.info_event, &quot;variable_ivr_path&quot;))) {
</span><span class="cx">                 esl_disconnect(&amp;eslC);
</span><del>-                esl_log(ESL_LOG_ERROR, &quot;No ivr_path variable set, check your dialplan!\n&quot;);
-                exit(0);
</del><ins>+                perror(&quot;No ivr_path variable set, check your dialplan!&quot;);
+                return NULL;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         strncpy(script_path, buf, sizeof(script_path) - 1);
</span><span class="cx"> 
</span><del>-        /* TODO: check for failure */
-        pipe(pipes.script);
-        pipe(pipes.socket);
</del><ins>+        if ( pipe(pipes.script) &lt; 0) {
+                esl_disconnect(&amp;eslC);
+                perror(&quot;script pipes failed...&quot;);
+                return NULL;
+        }
+        if ( pipe(pipes.socket) &lt; 0 ) {
+                close(pipes.script[0]);
+                close(pipes.script[1]);
+                esl_disconnect(&amp;eslC);
+                perror(&quot;socket pipes failed...&quot;);
+                return NULL;
+        }
</ins><span class="cx"> 
</span><span class="cx">         thread_running = 1;
</span><span class="cx">         pid = fork();
</span><span class="cx">         if (pid &lt; 0) {
</span><del>-                /* Close the pipes/socket and warn */
-                esl_log(ESL_LOG_ERROR, &quot;Fork failed, aie aie aie!\n&quot;);
</del><ins>+                close(pipes.script[0]);
+                close(pipes.script[1]);
+                close(pipes.socket[0]);
+                close(pipes.socket[1]);
+                esl_disconnect(&amp;eslC);
+                perror(&quot;Fork failed, aie aie aie!&quot;);
+                return NULL;
</ins><span class="cx">         }
</span><span class="cx">         else if (pid == 0) {
</span><span class="cx">                 /* Child */
</span><span class="lines">@@ -88,9 +100,7 @@
</span><span class="cx"> 
</span><span class="cx">                 execl(script_path, script_path, NULL);
</span><span class="cx">                 thread_running=0;
</span><del>-#ifdef _DEBUG_STDERR
</del><span class="cx">                 perror(&quot;Error running script&quot;);
</span><del>-#endif
</del><span class="cx">                 close(pipes.socket[0]);
</span><span class="cx">                 close(pipes.script[1]);
</span><span class="cx">                 exit(0);
</span><span class="lines">@@ -131,8 +141,7 @@
</span><span class="cx">                                 else if (status == ESL_SUCCESS) {
</span><span class="cx">                                         /* Translation ESL TO AGI
</span><span class="cx">                                          * - DTMF events.
</span><del>-                                         * - Command results
-                                         * - 
</del><ins>+                                         * - what else ?
</ins><span class="cx">                                          */
</span><span class="cx">                                 }
</span><span class="cx">                         }
</span><span class="lines">@@ -149,6 +158,10 @@
</span><span class="cx">                                                 if ( handle_hangup(&amp;eslC,pipes.socket[1]) &lt; 0)
</span><span class="cx">                                                         goto end;
</span><span class="cx">                                         }
</span><ins>+                                        else if ( !strncasecmp(&quot;EXEC&quot;,sbuf,4) ) {
+                                                if ( handle_exec(&amp;eslC,pipes.socket[1],(char *) &amp;sbuf) &lt; 0)
+                                                        goto end;
+                                        }
</ins><span class="cx">                                 }
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="lines">@@ -215,8 +228,8 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /* Setup env 
</span><del>- * TODO:        - should check write result.
- *                - add missing informations and correct wrong ones.
</del><ins>+ * TODO:        - correct parameters
+ *                - add a generic routine instead of blindly repeating code
</ins><span class="cx">  */
</span><span class="cx"> static int handle_setup_env(int fd,esl_handle_t *eslC) {
</span><span class="cx">         char buf[1024];
</span><span class="lines">@@ -225,7 +238,8 @@
</span><span class="cx">         /* Setup Env for AGI scripts */
</span><span class="cx">         if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;variable_ivr_path&quot;)) ) {
</span><span class="cx">                 sprintf(buf,&quot;agi_request: %s\n&quot;,sbuf);
</span><del>-                write(fd, buf,strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx">         else
</span><span class="cx">                 return -1;
</span><span class="lines">@@ -235,7 +249,8 @@
</span><span class="cx"> 
</span><span class="cx">         if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;variable_channel_name&quot;)) ) {
</span><span class="cx">                 sprintf(buf,&quot;agi_channel: %s\n&quot;,sbuf);
</span><del>-                write(fd, buf,strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx">         else
</span><span class="cx">                 return -1;
</span><span class="lines">@@ -243,11 +258,13 @@
</span><span class="cx">         perror(&quot;Setup ok on chan name&quot;);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-        write(fd, &quot;agi_language: en\n&quot;,18);
</del><ins>+        if ( write(fd, &quot;agi_language: en\n&quot;,18) &lt; 0 )
+                return -1;
</ins><span class="cx"> 
</span><span class="cx">         if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Channel-Source&quot;)) ) {
</span><span class="cx">                 sprintf(buf, &quot;agi_type: %s\n&quot;, sbuf);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx">         else
</span><span class="cx">                 return -1;
</span><span class="lines">@@ -257,7 +274,8 @@
</span><span class="cx"> 
</span><span class="cx">         if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Channel-Unique-ID&quot;)) ) {
</span><span class="cx">                 sprintf(buf, &quot;agi_uniqueid: %s\n&quot;, sbuf);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx">         else
</span><span class="cx">                 return -1;
</span><span class="lines">@@ -268,22 +286,26 @@
</span><span class="cx">         /* ANI/DNIS */
</span><span class="cx">         if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Channel-Caller-ID-Number&quot;)) ) {
</span><span class="cx">                 sprintf(buf, &quot;agi_callerid: %s\n&quot;, sbuf);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx">         else {
</span><span class="cx">                 sprintf(buf, &quot;agi_callerid: %s\n&quot;, &quot;unknown&quot;);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx"> #ifdef _DEBUG_STDERR
</span><span class="cx">         perror(&quot;Setup ok on callerid&quot;);
</span><span class="cx"> #endif
</span><span class="cx">         if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Channel-Caller-ID-Name&quot;)) ) {
</span><span class="cx">                 sprintf(buf, &quot;agi_calleridname: %s\n&quot;, sbuf);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx">         else {
</span><span class="cx">                 sprintf(buf, &quot;agi_calleridname: %s\n&quot;, &quot;unknown&quot;);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx"> #ifdef _DEBUG_STDERR
</span><span class="cx">         perror(&quot;Setup ok on calleridname&quot;);
</span><span class="lines">@@ -291,11 +313,13 @@
</span><span class="cx"> 
</span><span class="cx">         if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Channel-Screen-Bit&quot;)) ) {
</span><span class="cx">                 sprintf(buf, &quot;agi_callingpres: %s\n&quot;, sbuf);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx">         else {
</span><span class="cx">                 sprintf(buf, &quot;agi_callingpres: %s\n&quot;, &quot;unknown&quot;);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx"> #ifdef _DEBUG_STDERR
</span><span class="cx">         perror(&quot;Setup ok on agi_callingpres&quot;);
</span><span class="lines">@@ -303,11 +327,13 @@
</span><span class="cx">         /* TODO */
</span><span class="cx">         if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Caller-Caller-ID-Number&quot;)) ) {
</span><span class="cx">                 sprintf(buf, &quot;agi_callingani2: %s\n&quot;, sbuf);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx">         else {
</span><span class="cx">                 sprintf(buf, &quot;agi_callingani2: %s\n&quot;, &quot;unknown&quot;);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx"> #ifdef _DEBUG_STDERR
</span><span class="cx">         perror(&quot;Setup ok on agi_callingani2&quot;);
</span><span class="lines">@@ -315,22 +341,26 @@
</span><span class="cx">         /* TODO */
</span><span class="cx">         if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Caller-Caller-ID-Number&quot;)) ) {
</span><span class="cx">                 sprintf(buf, &quot;agi_callington: %s\n&quot;, sbuf);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx">         else {
</span><span class="cx">                 sprintf(buf, &quot;agi_callington: %s\n&quot;, &quot;unknown&quot;);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx"> #ifdef _DEBUG_STDERR
</span><span class="cx">         perror(&quot;Setup ok on agi_callington&quot;);
</span><span class="cx"> #endif
</span><span class="cx">         if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Caller-Destination-Number&quot;)) ) {
</span><span class="cx">                 sprintf(buf, &quot;agi_dnid: %s\n&quot;, sbuf);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx">         else {
</span><span class="cx">                 sprintf(buf, &quot;agi_dnid: %s\n&quot;, &quot;unknown&quot;);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx"> #ifdef _DEBUG_STDERR
</span><span class="cx">         perror(&quot;Setup ok on agi_dnid&quot;);
</span><span class="lines">@@ -338,11 +368,13 @@
</span><span class="cx">         /* TODO */
</span><span class="cx">         if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Caller-Destination-Number&quot;)) ) {
</span><span class="cx">                 sprintf(buf, &quot;agi_callingtns: %s\n&quot;, sbuf);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx">         else {
</span><span class="cx">                 sprintf(buf, &quot;agi_callingtns: %s\n&quot;, &quot;unknown&quot;);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx"> #ifdef _DEBUG_STDERR
</span><span class="cx">         perror(&quot;Setup ok on agi_callingtns&quot;);
</span><span class="lines">@@ -351,22 +383,26 @@
</span><span class="cx">         /* TODO: correct info */
</span><span class="cx">         if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Caller-Destination-Number&quot;)) ) {
</span><span class="cx">                 sprintf(buf, &quot;agi_rdnis: %s\n&quot;, sbuf);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx">         else {
</span><span class="cx">                 sprintf(buf, &quot;agi_rdnis: %s\n&quot;, &quot;unknown&quot;);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx"> #ifdef _DEBUG_STDERR
</span><span class="cx">         perror(&quot;Setup ok on agi_callingtns&quot;);
</span><span class="cx"> #endif
</span><span class="cx">         if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Channel-Context&quot;)) ) {
</span><span class="cx">                 sprintf(buf, &quot;agi_context: %s\n&quot;, sbuf);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx">         else {
</span><span class="cx">                 sprintf(buf, &quot;agi_context: %s\n&quot;, &quot;unknown&quot;);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx"> #ifdef _DEBUG_STDERR
</span><span class="cx">         perror(&quot;Setup ok on agi_context&quot;);
</span><span class="lines">@@ -374,11 +410,13 @@
</span><span class="cx"> 
</span><span class="cx">         if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Channel-Destination-Number&quot;)) ) {
</span><span class="cx">                 sprintf(buf, &quot;agi_extension: %s\n&quot;, sbuf);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx">         else {
</span><span class="cx">                 sprintf(buf, &quot;agi_extension: %s\n&quot;, &quot;unknown&quot;);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx"> #ifdef _DEBUG_STDERR
</span><span class="cx">         perror(&quot;Setup ok on agi_extension&quot;);
</span><span class="lines">@@ -386,18 +424,22 @@
</span><span class="cx">         /* TODO: correct info */
</span><span class="cx">         if ( (sbuf = esl_event_get_header(eslC-&gt;info_event, &quot;Channel-State-Number&quot;)) ) {
</span><span class="cx">                 sprintf(buf, &quot;agi_priority: %s\n&quot;, sbuf);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx">         else {
</span><span class="cx">                 sprintf(buf, &quot;agi_priority: %s\n&quot;, &quot;unknown&quot;);
</span><del>-                write(fd, buf, strlen(buf) );
</del><ins>+                if ( write(fd, buf,strlen(buf) ) &lt; 0)
+                        return -1;
</ins><span class="cx">         }
</span><span class="cx"> #ifdef _DEBUG_STDERR
</span><span class="cx">         perror(&quot;Setup ok on agi_priority&quot;);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-        write(fd, &quot;agi_enhanced: 0.0\n&quot;, 19);
-        write(fd, &quot;agi_accountcode: \n\n&quot;, 21);
</del><ins>+        if ( write(fd, &quot;agi_enhanced: 0.0\n&quot;, 19) &lt; 0 )
+                return -1;
+        if ( write(fd, &quot;agi_accountcode: \n\n&quot;, 21) &lt; 0 )
+                return -1;
</ins><span class="cx">         return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -449,3 +491,28 @@
</span><span class="cx">         }
</span><span class="cx">         return 0;
</span><span class="cx"> }
</span><ins>+
+/*
+ * EXEC AGI cmd
+ * TODO:        - parse arguments
+ */
+static int handle_exec(esl_handle_t *eslC,int fd,char *buf) {
+        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 EXEC&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="modfile"><h4>Modified: freeswitch/trunk/contrib/gled/esl2agi/esl2agi.h (14712 => 14713)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/gled/esl2agi/esl2agi.h        2009-09-01 13:57:14 UTC (rev 14712)
+++ freeswitch/trunk/contrib/gled/esl2agi/esl2agi.h        2009-09-01 16:24:34 UTC (rev 14713)
</span><span class="lines">@@ -34,13 +34,13 @@
</span><span class="cx"> /* 
</span><span class="cx">  * Define Section
</span><span class="cx">  */
</span><del>-
</del><span class="cx"> #define _GNU_SOURCE
</span><ins>+/* #undef _DEBUG_STDERR */
+#define _DEBUG_STDERR
</ins><span class="cx"> 
</span><span class="cx"> /* 
</span><span class="cx">  * Inc Section
</span><span class="cx">  */
</span><del>-
</del><span class="cx"> #include &lt;stdio.h&gt;
</span><span class="cx"> #include &lt;stdlib.h&gt;
</span><span class="cx"> #include &lt;esl.h&gt;
</span><span class="lines">@@ -48,22 +48,19 @@
</span><span class="cx"> #include &lt;errno.h&gt;
</span><span class="cx"> #include &lt;sys/time.h&gt;
</span><span class="cx"> #include &lt;pthread.h&gt;
</span><ins>+
</ins><span class="cx"> /* 
</span><span class="cx">  * Macros Section
</span><span class="cx">  */
</span><del>-
</del><span class="cx"> #define PIPES_TO_VOID(v)        ((void*)(v))
</span><span class="cx"> #define VOID_TO_PIPES(p)        ((esl2agi_pipes_t*)(p))
</span><del>-
</del><span class="cx"> #define ESL_A_TO_VOID(v)        ((void*)(v))
</span><span class="cx"> #define VOID_TO_ESL_A(p)        ((esl_accept_t*)(p))
</span><del>-
</del><span class="cx"> #define MAX(x,y)                ((x) &gt; (y) ? (x) : (y))
</span><span class="cx"> 
</span><span class="cx"> /* 
</span><span class="cx">  * Struct Section
</span><span class="cx">  */
</span><del>-
</del><span class="cx"> typedef struct {
</span><span class="cx">         esl_socket_t client_sock;
</span><span class="cx">         struct sockaddr_in *addr;
</span><span class="lines">@@ -77,7 +74,6 @@
</span><span class="cx"> /* 
</span><span class="cx">  * Func Section
</span><span class="cx">  */
</span><del>-
</del><span class="cx"> static void esl2agi(esl_socket_t server_sock, esl_socket_t client_sock, struct sockaddr_in *addr);
</span><span class="cx"> 
</span><span class="cx"> static void *esl2agi_thread(void *data);
</span><span class="lines">@@ -96,9 +92,28 @@
</span><span class="cx">  * - wait for digit timeout
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> static int handle_setup_env(int fd,esl_handle_t *eslC);
</span><span class="cx"> 
</span><span class="cx"> static int handle_hangup(esl_handle_t *eslC,int fd);
</span><span class="cx"> 
</span><span class="cx"> static int handle_answer(esl_handle_t *eslC,int fd);
</span><ins>+
+static int handle_exec(esl_handle_t *eslC,int fd,char *buf);
+
+/*
+static int handle_getdata(esl_handle_t *eslC,int fd,char *buf);
+
+static int handle_getvar(esl_handle_t *eslC,int fd,char *buf);
+
+static int handle_record(esl_handle_t *eslC,int fd,char *buf);
+
+static int handle_say(esl_handle_t *eslC,int fd,char *buf);
+
+static int handle_setvar(esl_handle_t *eslC,int fd,char *buf);
+
+static int handle_set(esl_handle_t *eslC,int fd,char *buf);
+
+static int handle_streamfile(esl_handle_t *eslC,int fd,char *buf);
+
+static int handle_waitdigits(esl_handle_t *eslC,int fd,char *buf);
+*/
</ins></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>