<!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][14731] </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=14731">14731</a></dd>
<dt>Author</dt> <dd>gled</dd>
<dt>Date</dt> <dd>2009-09-02 08:39:45 -0500 (Wed, 02 Sep 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>better binding matching... easier to add new ones</pre>

<h3>Modified Paths</h3>
<ul>
<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>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunkcontribgledesl2agiesl2agic"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/contrib/gled/esl2agi/esl2agi.c (14730 => 14731)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/gled/esl2agi/esl2agi.c        2009-09-02 13:22:44 UTC (rev 14730)
+++ freeswitch/trunk/contrib/gled/esl2agi/esl2agi.c        2009-09-02 13:39:45 UTC (rev 14731)
</span><span class="lines">@@ -146,22 +146,15 @@
</span><span class="cx">                                 }
</span><span class="cx">                         }
</span><span class="cx">                         if (FD_ISSET(pipes.script[0],&amp;rd) ) { /* AGI has something to say */
</span><ins>+                                bzero(&amp;sbuf,2047);
</ins><span class="cx">                                 r = read(pipes.script[0],&amp;sbuf,2047);
</span><span class="cx">                                 if (r&lt;0)
</span><span class="cx">                                         goto end;
</span><span class="cx">                                 else {
</span><del>-                                        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;
-                                        }
-                                        else if ( !strncasecmp(&quot;EXEC&quot;,sbuf,4) ) {
-                                                if ( handle_exec(&amp;eslC,pipes.socket[1],(char *) &amp;sbuf) &lt; 0)
-                                                        goto end;
-                                        }
</del><ins>+                                        /*TODO: correct ugly hack to remove final \n */
+                                        sbuf[r-1] = '\0';
+                                        if ( find_and_exec_command(&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">@@ -198,6 +191,7 @@
</span><span class="cx"> /* Main entry
</span><span class="cx">  * Esl listen and that's all.
</span><span class="cx">  * Copyright (c) 2009, Anthony Minessale II
</span><ins>+ * TODO:        - add mod_dialplan_asterisk lookup and load if not present.
</ins><span class="cx">  */
</span><span class="cx"> int main(int argc, char *argv[])
</span><span class="cx"> {
</span><span class="lines">@@ -243,9 +237,6 @@
</span><span class="cx">         }
</span><span class="cx">         else
</span><span class="cx">                 return -1;
</span><del>-#ifdef _DEBUG_STDERR
-        perror(&quot;Setup ok on request&quot;);
-#endif
</del><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><span class="lines">@@ -254,9 +245,6 @@
</span><span class="cx">         }
</span><span class="cx">         else
</span><span class="cx">                 return -1;
</span><del>-#ifdef _DEBUG_STDERR
-        perror(&quot;Setup ok on chan name&quot;);
-#endif
</del><span class="cx"> 
</span><span class="cx">         if ( write(fd, &quot;agi_language: en\n&quot;,18) &lt; 0 )
</span><span class="cx">                 return -1;
</span><span class="lines">@@ -268,9 +256,6 @@
</span><span class="cx">         }
</span><span class="cx">         else
</span><span class="cx">                 return -1;
</span><del>-#ifdef _DEBUG_STDERR
-        perror(&quot;Setup ok on source&quot;);
-#endif
</del><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><span class="lines">@@ -279,9 +264,6 @@
</span><span class="cx">         }
</span><span class="cx">         else
</span><span class="cx">                 return -1;
</span><del>-#ifdef _DEBUG_STDERR
-        perror(&quot;Setup ok on uniqueid&quot;);
-#endif
</del><span class="cx"> 
</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="lines">@@ -294,9 +276,6 @@
</span><span class="cx">                 if ( write(fd, buf,strlen(buf) ) &lt; 0)
</span><span class="cx">                         return -1;
</span><span class="cx">         }
</span><del>-#ifdef _DEBUG_STDERR
-        perror(&quot;Setup ok on callerid&quot;);
-#endif
</del><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><span class="cx">                 if ( write(fd, buf,strlen(buf) ) &lt; 0)
</span><span class="lines">@@ -307,9 +286,6 @@
</span><span class="cx">                 if ( write(fd, buf,strlen(buf) ) &lt; 0)
</span><span class="cx">                         return -1;
</span><span class="cx">         }
</span><del>-#ifdef _DEBUG_STDERR
-        perror(&quot;Setup ok on calleridname&quot;);
-#endif
</del><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><span class="lines">@@ -321,9 +297,6 @@
</span><span class="cx">                 if ( write(fd, buf,strlen(buf) ) &lt; 0)
</span><span class="cx">                         return -1;
</span><span class="cx">         }
</span><del>-#ifdef _DEBUG_STDERR
-        perror(&quot;Setup ok on agi_callingpres&quot;);
-#endif
</del><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><span class="lines">@@ -335,9 +308,6 @@
</span><span class="cx">                 if ( write(fd, buf,strlen(buf) ) &lt; 0)
</span><span class="cx">                         return -1;
</span><span class="cx">         }
</span><del>-#ifdef _DEBUG_STDERR
-        perror(&quot;Setup ok on agi_callingani2&quot;);
-#endif
</del><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><span class="lines">@@ -349,9 +319,6 @@
</span><span class="cx">                 if ( write(fd, buf,strlen(buf) ) &lt; 0)
</span><span class="cx">                         return -1;
</span><span class="cx">         }
</span><del>-#ifdef _DEBUG_STDERR
-        perror(&quot;Setup ok on agi_callington&quot;);
-#endif
</del><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><span class="cx">                 if ( write(fd, buf,strlen(buf) ) &lt; 0)
</span><span class="lines">@@ -362,9 +329,6 @@
</span><span class="cx">                 if ( write(fd, buf,strlen(buf) ) &lt; 0)
</span><span class="cx">                         return -1;
</span><span class="cx">         }
</span><del>-#ifdef _DEBUG_STDERR
-        perror(&quot;Setup ok on agi_dnid&quot;);
-#endif
</del><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><span class="lines">@@ -376,9 +340,6 @@
</span><span class="cx">                 if ( write(fd, buf,strlen(buf) ) &lt; 0)
</span><span class="cx">                         return -1;
</span><span class="cx">         }
</span><del>-#ifdef _DEBUG_STDERR
-        perror(&quot;Setup ok on agi_callingtns&quot;);
-#endif
</del><span class="cx"> 
</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="lines">@@ -391,9 +352,6 @@
</span><span class="cx">                 if ( write(fd, buf,strlen(buf) ) &lt; 0)
</span><span class="cx">                         return -1;
</span><span class="cx">         }
</span><del>-#ifdef _DEBUG_STDERR
-        perror(&quot;Setup ok on agi_callingtns&quot;);
-#endif
</del><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><span class="cx">                 if ( write(fd, buf,strlen(buf) ) &lt; 0)
</span><span class="lines">@@ -404,9 +362,6 @@
</span><span class="cx">                 if ( write(fd, buf,strlen(buf) ) &lt; 0)
</span><span class="cx">                         return -1;
</span><span class="cx">         }
</span><del>-#ifdef _DEBUG_STDERR
-        perror(&quot;Setup ok on agi_context&quot;);
-#endif
</del><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><span class="lines">@@ -418,9 +373,7 @@
</span><span class="cx">                 if ( write(fd, buf,strlen(buf) ) &lt; 0)
</span><span class="cx">                         return -1;
</span><span class="cx">         }
</span><del>-#ifdef _DEBUG_STDERR
-        perror(&quot;Setup ok on agi_extension&quot;);
-#endif
</del><ins>+
</ins><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><span class="lines">@@ -432,9 +385,6 @@
</span><span class="cx">                 if ( write(fd, buf,strlen(buf) ) &lt; 0)
</span><span class="cx">                         return -1;
</span><span class="cx">         }
</span><del>-#ifdef _DEBUG_STDERR
-        perror(&quot;Setup ok on agi_priority&quot;);
-#endif
</del><span class="cx"> 
</span><span class="cx">         if ( write(fd, &quot;agi_enhanced: 0.0\n&quot;, 19) &lt; 0 )
</span><span class="cx">                 return -1;
</span><span class="lines">@@ -447,22 +397,19 @@
</span><span class="cx">  * Hangup AGI cmd
</span><span class="cx">  * TODO:        - Add arg support to know which channel we want to hangup.
</span><span class="cx">  */
</span><del>-static int handle_hangup(esl_handle_t *eslC,int fd) {
</del><ins>+static int handle_hangup(esl_handle_t *eslC,int fd, char *args) {
</ins><span class="cx">         esl_status_t status;
</span><del>-        int r;
</del><span class="cx"> 
</span><span class="cx">         status = esl_execute(eslC,&quot;hangup&quot;,NULL,NULL);
</span><span class="cx">         if (status == ESL_FAIL) {
</span><span class="cx"> #ifdef _DEBUG_STDERR
</span><span class="cx">                 perror(&quot;ESL FAILED TO HANGUP&quot;);
</span><span class="cx"> #endif
</span><del>-                r = write(fd,&quot;200 result=failure\n\n&quot;,128);
-                if (r&lt;0)
</del><ins>+                if ( write(fd,&quot;200 result=failure\n\n&quot;,128) &lt; 0 )
</ins><span class="cx">                         return -1;
</span><del>-                }
</del><ins>+        }
</ins><span class="cx">         else if (status == ESL_SUCCESS) {
</span><del>-                r = write(fd,&quot;200 result=success\n\n&quot;,128);
-                if (r&lt;0)
</del><ins>+                if ( write(fd,&quot;200 result=success\n\n&quot;,128) &lt; 0 )
</ins><span class="cx">                         return -1;
</span><span class="cx">         }
</span><span class="cx">         return 0;
</span><span class="lines">@@ -471,48 +418,120 @@
</span><span class="cx"> /*
</span><span class="cx">  * Answer AGI cmd
</span><span class="cx">  */
</span><del>-static int handle_answer(esl_handle_t *eslC,int fd) {
</del><ins>+static int handle_answer(esl_handle_t *eslC,int fd,char *args) {
</ins><span class="cx">         esl_status_t status;
</span><del>-        int r;
</del><span class="cx"> 
</span><span class="cx">         status = esl_execute(eslC,&quot;answer&quot;,NULL,NULL);
</span><span class="cx">         if (status == ESL_FAIL) {
</span><span class="cx"> #ifdef _DEBUG_STDERR
</span><span class="cx">                 perror(&quot;ESL FAILED TO HANGUP&quot;);
</span><span class="cx"> #endif
</span><del>-                r = write(fd,&quot;200 result=failure\n\n&quot;,128);
-                if (r&lt;0)
</del><ins>+                if ( write(fd,&quot;200 result=failure\n\n&quot;,128) &lt; 0 )
</ins><span class="cx">                         return -1;
</span><del>-                }
</del><ins>+        }
</ins><span class="cx">         else if (status == ESL_SUCCESS) {
</span><del>-                r = write(fd,&quot;200 result=success\n\n&quot;,128);
-                if (r&lt;0)
</del><ins>+                if ( write(fd,&quot;200 result=success\n\n&quot;,128) &lt; 0 )
</ins><span class="cx">                         return -1;
</span><span class="cx">         }
</span><span class="cx">         return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-/*
- * EXEC AGI cmd
- * TODO:        - parse arguments
- */
-static int handle_exec(esl_handle_t *eslC,int fd,char *buf) {
-        esl_status_t status;
-        int r;
</del><ins>+static void parse_args(char *buf,int *argc,char *argv[_MAX_CMD_ARGS]) {
+        char *cur;
+        int x = 0;
+        int quote = 0;
+        int escaped = 0;
+        int space=1;
</ins><span class="cx"> 
</span><del>-        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;
</del><ins>+        cur = buf;
+        while (*buf) {
+                switch (*buf) {
+                        case '&quot;':
+                                if (escaped)
+                                        goto ok;
+                                else
+                                        quote = !quote;
+                                if (quote &amp;&amp; space) {
+                                        argv[x++] = cur;
+                                        space=0;
+                                }
+                                escaped = 0;
+                        break;
+                        case ' ':
+                        case '\t':
+                                if (!quote &amp;&amp; !escaped) {
+                                        space = 1;
+                                        *(cur++) = '\0';
+                                } else
+                                        goto ok;
+                        break;
+                        case '\\':
+                                if (escaped)
+                                        goto ok;
+                                else
+                                        escaped = 1;
+                        break;
+                        default:
+ok:
+                                if (space) {
+                                        argv[x++] = cur;
+                                        space=0;
+                                }
+                                *(cur++) = *buf;
+                                escaped=0;
</ins><span class="cx">                 }
</span><del>-        else if (status == ESL_SUCCESS) {
-                r = write(fd,&quot;200 result=success\n\n&quot;,128);
-                if (r&lt;0)
-                        return -1;
</del><ins>+                buf++;
</ins><span class="cx">         }
</span><del>-        return 0;
</del><ins>+        *(cur++) = '\0';
+        argv[x]= NULL;
+        *argc = x;
+        return;
</ins><span class="cx"> }
</span><ins>+
+static command_binding_t bindings[_MAX_CMD] = {
+        { {&quot;ANSWER&quot; , NULL}, handle_answer },
+        { {&quot;HANGUP&quot; , NULL}, handle_hangup },
+};
+
+
+static command_binding_t *find_binding(char *cmd[]) {
+        int x,y,match=0;
+
+        for (x=0; x &lt; sizeof(bindings); x++) {
+                if ( ! bindings[x].cmd[0] ) {
+                        break;
+                }
+                match = 1;
+
+                for (y=0; match &amp;&amp; cmd[y]; y++) {
+                        if (!bindings[x].cmd[y]) /* Is the next part existing ?*/
+                                break;
+                        if ( strncasecmp(bindings[x].cmd[y],cmd[y], MAX(strlen(bindings[x].cmd[y]),strlen(cmd[y]) ) ) )
+                                match=0;
+                }
+                if (bindings[x].cmd[y]) /* There's a word missing in cmd */
+                        match=0;
+                if (match)
+                        return &amp;bindings[x];
+        }
+        return NULL;
+}
+
+static int find_and_exec_command(esl_handle_t *eslC,int fd,char *buf) {
+        char *argv[1024];
+        int argc = 0;
+        int r = -1;
+        command_binding_t *bind;
+
+        parse_args(buf,&amp;argc,argv);
+
+        bind = find_binding(argv);
+        if (bind) {
+                r = bind-&gt;handler(eslC,fd,buf);
+        }
+        else {
+                fprintf(stderr,&quot;Binding not found: '%s'&quot;,buf);
+        }
+        return r;
+}
+
</ins></span></pre></div>
<a id="freeswitchtrunkcontribgledesl2agiesl2agih"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/contrib/gled/esl2agi/esl2agi.h (14730 => 14731)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/gled/esl2agi/esl2agi.h        2009-09-02 13:22:44 UTC (rev 14730)
+++ freeswitch/trunk/contrib/gled/esl2agi/esl2agi.h        2009-09-02 13:39:45 UTC (rev 14731)
</span><span class="lines">@@ -38,6 +38,10 @@
</span><span class="cx"> /* #undef _DEBUG_STDERR */
</span><span class="cx"> #define _DEBUG_STDERR
</span><span class="cx"> 
</span><ins>+#define _MAX_CMD_LEN 128
+#define _MAX_CMD_ARGS 128
+#define _MAX_CMD 128
+
</ins><span class="cx"> /* 
</span><span class="cx">  * Inc Section
</span><span class="cx">  */
</span><span class="lines">@@ -71,6 +75,12 @@
</span><span class="cx">         int socket[2];
</span><span class="cx"> } esl2agi_pipes_t;
</span><span class="cx"> 
</span><ins>+typedef struct command_binding_t {
+        char *cmd[_MAX_CMD_LEN];
+        int (*handler)(esl_handle_t *eslC,int fd,char *args);
+        struct command_binding *next;
+} command_binding_t;
+
</ins><span class="cx"> /* 
</span><span class="cx">  * Func Section
</span><span class="cx">  */
</span><span class="lines">@@ -94,26 +104,33 @@
</span><span class="cx"> 
</span><span class="cx"> static int handle_setup_env(int fd,esl_handle_t *eslC);
</span><span class="cx"> 
</span><del>-static int handle_hangup(esl_handle_t *eslC,int fd);
</del><ins>+static void parse_args(char *buf,int *argc,char *argv[1024]);
</ins><span class="cx"> 
</span><del>-static int handle_answer(esl_handle_t *eslC,int fd);
</del><ins>+static command_binding_t *find_binding(char *cmd[]);
</ins><span class="cx"> 
</span><del>-static int handle_exec(esl_handle_t *eslC,int fd,char *buf);
</del><ins>+static int handle_hangup(esl_handle_t *eslC,int fd,char *args);
</ins><span class="cx"> 
</span><ins>+static int handle_answer(esl_handle_t *eslC,int fd, char *args);
+
+static int find_and_exec_command(esl_handle_t *eslC,int fd,char *buf);
+
</ins><span class="cx"> /*
</span><del>-static int handle_getdata(esl_handle_t *eslC,int fd,char *buf);
</del><span class="cx"> 
</span><del>-static int handle_getvar(esl_handle_t *eslC,int fd,char *buf);
</del><ins>+static int handle_exec(esl_handle_t *eslC,int fd,char *args);
</ins><span class="cx"> 
</span><del>-static int handle_record(esl_handle_t *eslC,int fd,char *buf);
</del><ins>+static int handle_getdata(esl_handle_t *eslC,int fd,char *args);
</ins><span class="cx"> 
</span><del>-static int handle_say(esl_handle_t *eslC,int fd,char *buf);
</del><ins>+static int handle_getvar(esl_handle_t *eslC,int fd,char *args);
</ins><span class="cx"> 
</span><del>-static int handle_setvar(esl_handle_t *eslC,int fd,char *buf);
</del><ins>+static int handle_record(esl_handle_t *eslC,int fd,char *args);
</ins><span class="cx"> 
</span><del>-static int handle_set(esl_handle_t *eslC,int fd,char *buf);
</del><ins>+static int handle_say(esl_handle_t *eslC,int fd,char *args);
</ins><span class="cx"> 
</span><del>-static int handle_streamfile(esl_handle_t *eslC,int fd,char *buf);
</del><ins>+static int handle_setvar(esl_handle_t *eslC,int fd,char *args);
</ins><span class="cx"> 
</span><del>-static int handle_waitdigits(esl_handle_t *eslC,int fd,char *buf);
</del><ins>+static int handle_set(esl_handle_t *eslC,int fd,char *args);
+
+static int handle_streamfile(esl_handle_t *eslC,int fd,char *args);
+
+static int handle_waitdigits(esl_handle_t *eslC,int fd,char *args);
</ins><span class="cx"> */
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>