I&#39;m ok with the idea as long as it&#39;s thoroughly tested.<br>If there is any more info you want to save from those events you should consider it now while we are modifying it.<br> <br><br><div class="gmail_quote">On Thu, Jul 16, 2009 at 9:02 AM,  <span dir="ltr">&lt;<a href="mailto:freeswitch-users@lists.freeswitch.org">freeswitch-users@lists.freeswitch.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi,<br>
<br>
I usually find it very useful when I can retrieve a list of the currents calls along with durations. I noticed that the &#39;show channels&#39; format does not include the duration (or the answered timestamp - so that one can extract it from there). So, I made a patch that includes the answered timestamp, the answered timestamp in epoch, and the duration in seconds. Of course these fields remain empty when the call hasn&#39;t been<br>

answered yet.<br>
<br>
I don&#39;t know if anyone else finds this functionality useful, so I am posting this patch here first (instead of JIRA) in order to get feedback from the users. If many of you (or the maintainers) find it interesting I can then proceed in posting it to JIRA.<br>
<font color="#888888">
<br>
-- <br>
-------------------------------------------<br>
Apostolos Pantsiopoulos<br>
Kinetix Tele.com R &amp; D<br>
email: <a href="mailto:regs@kinetix.gr" target="_blank">regs@kinetix.gr</a><br>
-------------------------------------------<br>
</font><br>Index: src/mod/applications/mod_commands/mod_commands.c<br>
===================================================================<br>
--- src/mod/applications/mod_commands/mod_commands.c    (revision 14256)<br>
+++ src/mod/applications/mod_commands/mod_commands.c    (working copy)<br>
@@ -2827,10 +2827,10 @@<br>
                                }<br>
                        }<br>
                        if (strchr(argv[2], &#39;%&#39;)) {<br>
-                               sprintf(sql, &quot;select * from channels where uuid like &#39;%s&#39; or name like &#39;%s&#39; or cid_name like &#39;%s&#39; or cid_num like &#39;%s&#39; order by created_epoch&quot;,<br>

+                               sprintf(sql, &quot;select *,strftime(&#39;%%s&#39;,DATETIME(&#39;NOW&#39;))-answered_epoch as duration from channels where uuid like &#39;%s&#39; or name like &#39;%s&#39; or cid_name like &#39;%s&#39; or cid_num like &#39;%s&#39; order by created_epoch&quot;,<br>

                                                argv[2], argv[2], argv[2], argv[2]);<br>
                        } else {<br>
-                               sprintf(sql, &quot;select * from channels where uuid like &#39;%%%s%%&#39; or name like &#39;%%%s%%&#39; or cid_name like &#39;%%%s%%&#39; or cid_num like &#39;%%%s%%&#39; order by created_epoch&quot;,<br>

+                               sprintf(sql, &quot;select *,strftime(&#39;%%s&#39;,DATETIME(&#39;NOW&#39;))-answered_epoch as duration from channels where uuid like &#39;%%%s%%&#39; or name like &#39;%%%s%%&#39; or cid_name like &#39;%%%s%%&#39; or cid_num like &#39;%%%s%%&#39; order by created_epoch&quot;,<br>

                                                argv[2], argv[2], argv[2], argv[2]);<br>
<br>
                        }<br>
@@ -2839,10 +2839,10 @@<br>
                                as = argv[4];<br>
                    }<br>
                } else {<br>
-                       sprintf(sql, &quot;select * from channels order by created_epoch&quot;);<br>
+                       sprintf(sql, &quot;select *,strftime(&#39;%%s&#39;,DATETIME(&#39;NOW&#39;))-answered_epoch as duration from channels order by created_epoch&quot;);<br>
                }<br>
        } else if (!strcasecmp(command, &quot;channels&quot;)) {<br>
-               sprintf(sql, &quot;select * from channels order by created_epoch&quot;);<br>
+               sprintf(sql, &quot;select *,strftime(&#39;%%s&#39;,DATETIME(&#39;NOW&#39;))-answered_epoch as duration from channels order by created_epoch&quot;);<br>
                if (argv[1] &amp;&amp; !strcasecmp(argv[1],&quot;count&quot;)) {<br>
                    holder.justcount = 1;<br>
                    if (argv[3] &amp;&amp; !strcasecmp(argv[2], &quot;as&quot;)) {<br>
@@ -2850,7 +2850,7 @@<br>
                    }<br>
                }<br>
        } else if (!strcasecmp(command, &quot;distinct_channels&quot;)) {<br>
-               sprintf(sql, &quot;select * from channels left join calls on &quot;<br>
+               sprintf(sql, &quot;select *,strftime(&#39;%%s&#39;,DATETIME(&#39;NOW&#39;))-answered_epoch as duration from channels left join calls on &quot;<br>
                                &quot;channels.uuid=calls.caller_uuid where channels.uuid not in (select callee_uuid from calls) order by created_epoch&quot;);<br>
                if (argv[2] &amp;&amp; !strcasecmp(argv[1], &quot;as&quot;)) {<br>
                        as = argv[2];<br>
Index: src/switch_core_sqldb.c<br>
===================================================================<br>
--- src/switch_core_sqldb.c     (revision 14256)<br>
+++ src/switch_core_sqldb.c     (working copy)<br>
@@ -309,9 +309,21 @@<br>
                                                         );<br>
<br>
                break;<br>
+       case SWITCH_EVENT_CHANNEL_ANSWER:<br>
+               {<br>
+<br>
+                       sql = switch_mprintf(&quot;update channels set answered=&#39;%s&#39;,answered_epoch=&#39;%ld&#39; where uuid=&#39;%s&#39;&quot;,<br>
+                                                         switch_event_get_header_nil(event, &quot;event-date-local&quot;),<br>
+                                                        (long)switch_epoch_time_now(NULL),<br>
+                                                        switch_event_get_header_nil(event, &quot;unique-id&quot;)<br>
+                                                         );<br>
+<br>
+               }<br>
+               break;<br>
        case SWITCH_EVENT_CHANNEL_STATE:<br>
                {<br>
                        char *state = switch_event_get_header_nil(event, &quot;channel-state-number&quot;);<br>
+<br>
                        switch_channel_state_t state_i = CS_DESTROY;<br>
<br>
                        if (!switch_strlen_zero(state)) {<br>
@@ -492,7 +504,9 @@<br>
                        &quot;   read_rate  VARCHAR(255),\n&quot;<br>
                        &quot;   write_codec  VARCHAR(255),\n&quot;<br>
                        &quot;   write_rate  VARCHAR(255),\n&quot;<br>
-                       &quot;   secure VARCHAR(255)\n&quot;<br>
+                       &quot;   secure VARCHAR(255),\n&quot;<br>
+                       &quot;   answered  VARCHAR(255),\n&quot;<br>
+                        &quot;   answered_epoch  INTEGER\n&quot;<br>
                        &quot;);\ncreate index uuindex on channels (uuid);\n&quot;;<br>
                char create_calls_sql[] =<br>
                        &quot;CREATE TABLE calls (\n&quot;<br>
<br>_______________________________________________<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Anthony Minessale II<br><br>FreeSWITCH <a href="http://www.freeswitch.org/">http://www.freeswitch.org/</a><br>ClueCon <a href="http://www.cluecon.com/">http://www.cluecon.com/</a><br>
Twitter: <a href="http://twitter.com/FreeSWITCH_wire">http://twitter.com/FreeSWITCH_wire</a><br><br>AIM: anthm<br><a href="mailto:MSN%3Aanthony_minessale@hotmail.com">MSN:anthony_minessale@hotmail.com</a><br>GTALK/JABBER/<a href="mailto:PAYPAL%3Aanthony.minessale@gmail.com">PAYPAL:anthony.minessale@gmail.com</a><br>
IRC: <a href="http://irc.freenode.net">irc.freenode.net</a> #freeswitch<br><br>FreeSWITCH Developer Conference<br><a href="mailto:sip%3A888@conference.freeswitch.org">sip:888@conference.freeswitch.org</a><br><a href="http://iax:guest@conference.freeswitch.org/888">iax:guest@conference.freeswitch.org/888</a><br>
<a href="mailto:googletalk%3Aconf%2B888@conference.freeswitch.org">googletalk:conf+888@conference.freeswitch.org</a><br>pstn:213-799-1400<br>