<!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][14340] </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=14340">14340</a></dd>
<dt>Author</dt> <dd>gmaruzz</dd>
<dt>Date</dt> <dd>2009-07-24 08:36:43 -0500 (Fri, 24 Jul 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>skypiax: lot of changes to allow for the usage of multiple instances of the same skype username, eg: 10 instances of skypename 'Bob' and 10 instances of skypename 'alice'. Horrible hacks for deciding which instance answer an incoming call, which busy instance will transfer to another and when, etc... ;-) Let's hope it does not breaks havoc...</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcmodendpointsmod_skypiaxmod_skypiaxc">freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_skypiaxskypiaxh">freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_skypiaxskypiax_protocolc">freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcmodendpointsmod_skypiaxmod_skypiaxc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c (14339 => 14340)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c        2009-07-24 13:34:03 UTC (rev 14339)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c        2009-07-24 13:36:43 UTC (rev 14340)
</span><span class="lines">@@ -185,7 +185,7 @@
</span><span class="cx"> 
</span><span class="cx"> static switch_status_t channel_on_destroy(switch_core_session_t * session)
</span><span class="cx"> {
</span><del>-        //switch_channel_t *channel = NULL;
</del><ins>+  //switch_channel_t *channel = NULL;
</ins><span class="cx">   private_t *tech_pvt = NULL;
</span><span class="cx"> 
</span><span class="cx">   //channel = switch_core_session_get_channel(session);
</span><span class="lines">@@ -194,19 +194,18 @@
</span><span class="cx">   tech_pvt = switch_core_session_get_private(session);
</span><span class="cx"> 
</span><span class="cx">   if (tech_pvt) {
</span><del>-          if (switch_core_codec_ready(&amp;tech_pvt-&gt;read_codec)) {
-                  switch_core_codec_destroy(&amp;tech_pvt-&gt;read_codec);
-          }
-          
-          if (switch_core_codec_ready(&amp;tech_pvt-&gt;write_codec)) {
-                  switch_core_codec_destroy(&amp;tech_pvt-&gt;write_codec);
-          }
</del><ins>+    if (switch_core_codec_ready(&amp;tech_pvt-&gt;read_codec)) {
+      switch_core_codec_destroy(&amp;tech_pvt-&gt;read_codec);
+    }
+
+    if (switch_core_codec_ready(&amp;tech_pvt-&gt;write_codec)) {
+      switch_core_codec_destroy(&amp;tech_pvt-&gt;write_codec);
+    }
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">   return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> static switch_status_t channel_on_hangup(switch_core_session_t * session)
</span><span class="cx"> {
</span><span class="cx">   switch_channel_t *channel = NULL;
</span><span class="lines">@@ -230,7 +229,6 @@
</span><span class="cx">     skypiax_signaling_write(tech_pvt, msg_to_skype);
</span><span class="cx">   }
</span><span class="cx"> 
</span><del>-
</del><span class="cx">   memset(tech_pvt-&gt;session_uuid_str, '\0', sizeof(tech_pvt-&gt;session_uuid_str));
</span><span class="cx">   DEBUGA_SKYPE(&quot;%s CHANNEL HANGUP\n&quot;, SKYPIAX_P_LOG, switch_channel_get_name(channel));
</span><span class="cx">   switch_mutex_lock(globals.mutex);
</span><span class="lines">@@ -509,12 +507,12 @@
</span><span class="cx">   /*.on_hangup */ channel_on_hangup,
</span><span class="cx">   /*.on_exchange_media */ channel_on_exchange_media,
</span><span class="cx">   /*.on_soft_execute */ channel_on_soft_execute,
</span><del>-  /*.on_consume_media*/ NULL,
-  /*.on_hibernate*/ NULL,
-  /*.on_reset*/ NULL,
-  /*.on_park*/ NULL,
-  /*.on_reporting*/ NULL,
-  /*.on_destroy*/ channel_on_destroy
</del><ins>+  /*.on_consume_media */ NULL,
+  /*.on_hibernate */ NULL,
+  /*.on_reset */ NULL,
+  /*.on_park */ NULL,
+  /*.on_reporting */ NULL,
+  /*.on_destroy */ channel_on_destroy
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> switch_io_routines_t skypiax_io_routines = {
</span><span class="lines">@@ -561,7 +559,7 @@
</span><span class="cx">         if (strncmp(&quot;ANY&quot;, interface_name, strlen(interface_name)) == 0) {
</span><span class="cx">           /* we've been asked for the &quot;ANY&quot; interface, let's find the first idle interface */
</span><span class="cx">           DEBUGA_SKYPE(&quot;Finding one available skype interface\n&quot;, SKYPIAX_P_LOG);
</span><del>-          tech_pvt = find_available_skypiax_interface();
</del><ins>+          tech_pvt = find_available_skypiax_interface(NULL);
</ins><span class="cx">           if (tech_pvt)
</span><span class="cx">             found = 1;
</span><span class="cx">         }
</span><span class="lines">@@ -1002,6 +1000,9 @@
</span><span class="cx">             (&quot;Interface_id=%d is now STARTED, the Skype client to which we are connected gave us the correct CURRENTUSERHANDLE (%s)\n&quot;,
</span><span class="cx">              SKYPIAX_P_LOG, interface_id,
</span><span class="cx">              globals.SKYPIAX_INTERFACES[interface_id].skype_user);
</span><ins>+
+          skypiax_signaling_write(&amp;globals.SKYPIAX_INTERFACES[interface_id],
+                                  &quot;SET AUTOAWAY OFF&quot;);
</ins><span class="cx">         } else {
</span><span class="cx">           ERRORA
</span><span class="cx">             (&quot;The Skype client to which we are connected FAILED to gave us CURRENTUSERHANDLE=%s, interface_id=%d FAILED to start. No Skype client logged in as '%s' has been found. Please (re)launch a Skype client logged in as '%s'. Skypiax exiting now\n&quot;,
</span><span class="lines">@@ -1175,19 +1176,21 @@
</span><span class="cx"> 
</span><span class="cx">   if (channel) {
</span><span class="cx"> 
</span><del>-          if (! switch_channel_test_flag(channel, CF_BRIDGED)) {
</del><ins>+    if (!switch_channel_test_flag(channel, CF_BRIDGED)) {
</ins><span class="cx"> 
</span><del>-                  switch_dtmf_t dtmf = { (char) value[0], switch_core_default_dtmf_duration(0) };
-                  DEBUGA_SKYPE(&quot;received DTMF %c on channel %s\n&quot;, SKYPIAX_P_LOG, dtmf.digit,
-                                  switch_channel_get_name(channel));
-                  switch_mutex_lock(tech_pvt-&gt;flag_mutex);
-                  //FIXME: why sometimes DTMFs from here do not seems to be get by FS?
-                  switch_channel_queue_dtmf(channel, &amp;dtmf);
-                  switch_set_flag(tech_pvt, TFLAG_DTMF);
-                  switch_mutex_unlock(tech_pvt-&gt;flag_mutex);
-          } else {
-                  DEBUGA_SKYPE(&quot;received a DTMF on channel %s, but we're BRIDGED, so let's NOT relay it out of band\n&quot;, SKYPIAX_P_LOG, switch_channel_get_name(channel));
-          }
</del><ins>+      switch_dtmf_t dtmf = { (char) value[0], switch_core_default_dtmf_duration(0) };
+      DEBUGA_SKYPE(&quot;received DTMF %c on channel %s\n&quot;, SKYPIAX_P_LOG, dtmf.digit,
+                   switch_channel_get_name(channel));
+      switch_mutex_lock(tech_pvt-&gt;flag_mutex);
+      //FIXME: why sometimes DTMFs from here do not seems to be get by FS?
+      switch_channel_queue_dtmf(channel, &amp;dtmf);
+      switch_set_flag(tech_pvt, TFLAG_DTMF);
+      switch_mutex_unlock(tech_pvt-&gt;flag_mutex);
+    } else {
+      DEBUGA_SKYPE
+        (&quot;received a DTMF on channel %s, but we're BRIDGED, so let's NOT relay it out of band\n&quot;,
+         SKYPIAX_P_LOG, switch_channel_get_name(channel));
+    }
</ins><span class="cx">   } else {
</span><span class="cx">     WARNINGA(&quot;received %c DTMF, but no channel?\n&quot;, SKYPIAX_P_LOG, value[0]);
</span><span class="cx">   }
</span><span class="lines">@@ -1351,29 +1354,32 @@
</span><span class="cx">   return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-private_t *find_available_skypiax_interface(void)
</del><ins>+private_t *find_available_skypiax_interface(private_t * tech_pvt)
</ins><span class="cx"> {
</span><del>-  private_t *tech_pvt = NULL;
</del><ins>+  private_t *tech_pvt2 = NULL;
</ins><span class="cx">   int found = 0;
</span><span class="cx">   int i;
</span><span class="cx"> 
</span><ins>+  switch_mutex_lock(globals.mutex);
+
</ins><span class="cx">   for (i = 0; !found &amp;&amp; i &lt; SKYPIAX_MAX_INTERFACES; i++) {
</span><span class="cx">     if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
</span><span class="cx">       int skype_state = 0;
</span><span class="cx"> 
</span><del>-      tech_pvt = &amp;globals.SKYPIAX_INTERFACES[i];
-      skype_state = tech_pvt-&gt;interface_state;
</del><ins>+      tech_pvt2 = &amp;globals.SKYPIAX_INTERFACES[i];
+      skype_state = tech_pvt2-&gt;interface_state;
</ins><span class="cx">       DEBUGA_SKYPE(&quot;skype interface: %d, name: %s, state: %d\n&quot;, SKYPIAX_P_LOG, i,
</span><span class="cx">                    globals.SKYPIAX_INTERFACES[i].name, skype_state);
</span><del>-      if (SKYPIAX_STATE_DOWN == skype_state || 0 == skype_state) {
</del><ins>+      if ((tech_pvt ? strcmp(tech_pvt2-&gt;skype_user, tech_pvt-&gt;skype_user) : 1) &amp;&amp; (SKYPIAX_STATE_DOWN == skype_state || SKYPIAX_STATE_RING == skype_state || 0 == skype_state)) {   //(if we got tech_pvt NOT NULL) if user is NOT the same, and iface is idle
</ins><span class="cx">         found = 1;
</span><span class="cx">         break;
</span><span class="cx">       }
</span><span class="cx">     }
</span><span class="cx">   }
</span><span class="cx"> 
</span><ins>+  switch_mutex_unlock(globals.mutex);
</ins><span class="cx">   if (found)
</span><del>-    return tech_pvt;
</del><ins>+    return tech_pvt2;
</ins><span class="cx">   else
</span><span class="cx">     return NULL;
</span><span class="cx"> }
</span><span class="lines">@@ -1514,6 +1520,182 @@
</span><span class="cx">   return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+int skypiax_answer(private_t * tech_pvt, char *id, char *value)
+{
+  char msg_to_skype[1024];
+  int i;
+  int found = 0;
+  private_t *giovatech;
+  struct timeval timenow;
+
+  switch_mutex_lock(globals.mutex);
+
+  gettimeofday(&amp;timenow, NULL);
+  for (i = 0; !found &amp;&amp; i &lt; SKYPIAX_MAX_INTERFACES; i++) {
+    if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
+
+      giovatech = &amp;globals.SKYPIAX_INTERFACES[i];
+      //NOTICA(&quot;skype interface: %d, name: %s, state: %d, value=%s, giovatech-&gt;callid_number=%s, giovatech-&gt;skype_user=%s\n&quot;, SKYPIAX_P_LOG, i, giovatech-&gt;name, giovatech-&gt;interface_state, value, giovatech-&gt;callid_number, giovatech-&gt;skype_user);
+      //FIXME check a timestamp here
+      if (strlen(giovatech-&gt;skype_call_id) &amp;&amp; (giovatech-&gt;interface_state != SKYPIAX_STATE_DOWN) &amp;&amp; (!strcmp(giovatech-&gt;skype_user, tech_pvt-&gt;skype_user)) &amp;&amp; (!strcmp(giovatech-&gt;callid_number, value)) &amp;&amp; ((((timenow.tv_sec - giovatech-&gt;answer_time.tv_sec) * 1000000) + (timenow.tv_usec - giovatech-&gt;answer_time.tv_usec)) &lt; 500000)) {   //0.5sec
+        found = 1;
+        DEBUGA_SKYPE
+          (&quot;FOUND  (name=%s, giovatech-&gt;interface_state=%d != SKYPIAX_STATE_DOWN) &amp;&amp; (giovatech-&gt;skype_user=%s == tech_pvt-&gt;skype_user=%s) &amp;&amp; (giovatech-&gt;callid_number=%s == value=%s)\n&quot;,
+           SKYPIAX_P_LOG, giovatech-&gt;name, giovatech-&gt;interface_state,
+           giovatech-&gt;skype_user, tech_pvt-&gt;skype_user, giovatech-&gt;callid_number, value)
+          break;
+      }
+    }
+  }
+
+  if (found) {
+    //tech_pvt-&gt;callid_number[0]='\0';
+    switch_mutex_unlock(globals.mutex);
+    return 0;
+  }
+  DEBUGA_SKYPE(&quot;NOT FOUND\n&quot;, SKYPIAX_P_LOG);
+
+  if (!strlen(tech_pvt-&gt;skype_call_id)) {
+    /* we are not inside an active call */
+
+    sprintf(msg_to_skype, &quot;GET CALL %s PARTNER_DISPNAME&quot;, id);
+    skypiax_signaling_write(tech_pvt, msg_to_skype);
+    switch_sleep(10000);
+    sprintf(msg_to_skype, &quot;ALTER CALL %s ANSWER&quot;, id);
+    skypiax_signaling_write(tech_pvt, msg_to_skype);
+    DEBUGA_SKYPE(&quot;We answered a Skype RING on skype_call %s\n&quot;, SKYPIAX_P_LOG, id);
+    //FIXME write a timestamp here
+    gettimeofday(&amp;tech_pvt-&gt;answer_time, NULL);
+    switch_copy_string(tech_pvt-&gt;skype_call_id, id, sizeof(tech_pvt-&gt;skype_call_id) - 1);
+
+    switch_copy_string(tech_pvt-&gt;callid_number, value,
+                       sizeof(tech_pvt-&gt;callid_number) - 1);
+
+    DEBUGA_SKYPE
+      (&quot;NEW!  name: %s, state: %d, value=%s, tech_pvt-&gt;callid_number=%s, tech_pvt-&gt;skype_user=%s\n&quot;,
+       SKYPIAX_P_LOG, tech_pvt-&gt;name, tech_pvt-&gt;interface_state, value,
+       tech_pvt-&gt;callid_number, tech_pvt-&gt;skype_user);
+    switch_mutex_unlock(globals.mutex);
+  } else {
+
+    ERRORA(&quot;We're in a call now %s\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;skype_call_id);
+    switch_mutex_unlock(globals.mutex);
+  }
+  return 0;
+}
+int skypiax_transfer(private_t * tech_pvt, char *id, char *value)
+{
+  char msg_to_skype[1024];
+  int i;
+  int found = 0;
+  private_t *giovatech;
+  struct timeval timenow;
+
+  switch_mutex_lock(globals.mutex);
+
+  gettimeofday(&amp;timenow, NULL);
+  for (i = 0; !found &amp;&amp; i &lt; SKYPIAX_MAX_INTERFACES; i++) {
+    if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
+
+      giovatech = &amp;globals.SKYPIAX_INTERFACES[i];
+      //NOTICA(&quot;skype interface: %d, name: %s, state: %d, value=%s, giovatech-&gt;callid_number=%s, giovatech-&gt;skype_user=%s\n&quot;, SKYPIAX_P_LOG, i, giovatech-&gt;name, giovatech-&gt;interface_state, value, giovatech-&gt;callid_number, giovatech-&gt;skype_user);
+      //FIXME check a timestamp here
+      if (strlen(giovatech-&gt;skype_call_id) &amp;&amp; (giovatech-&gt;interface_state != SKYPIAX_STATE_DOWN) &amp;&amp; (!strcmp(giovatech-&gt;skype_user, tech_pvt-&gt;skype_user)) &amp;&amp; (!strcmp(giovatech-&gt;callid_number, value)) &amp;&amp; ((((timenow.tv_sec - giovatech-&gt;answer_time.tv_sec) * 1000000) + (timenow.tv_usec - giovatech-&gt;answer_time.tv_usec)) &lt; 500000)) {   //0.5sec
+        found = 1;
+        DEBUGA_SKYPE
+          (&quot;FOUND  (name=%s, giovatech-&gt;interface_state=%d != SKYPIAX_STATE_DOWN) &amp;&amp; (giovatech-&gt;skype_user=%s == tech_pvt-&gt;skype_user=%s) &amp;&amp; (giovatech-&gt;callid_number=%s == value=%s)\n&quot;,
+           SKYPIAX_P_LOG, giovatech-&gt;name, giovatech-&gt;interface_state,
+           giovatech-&gt;skype_user, tech_pvt-&gt;skype_user, giovatech-&gt;callid_number, value)
+          break;
+      }
+    }
+  }
+
+  if (found) {
+    //tech_pvt-&gt;callid_number[0]='\0';
+    switch_mutex_unlock(globals.mutex);
+    return 0;
+  }
+  DEBUGA_SKYPE(&quot;NOT FOUND\n&quot;, SKYPIAX_P_LOG);
+
+  if (!strlen(tech_pvt-&gt;skype_call_id)) {
+    /* we are not inside an active call */
+    ERRORA(&quot;We're NO MORE in a call now %s\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;skype_call_id);
+    switch_mutex_unlock(globals.mutex);
+
+  } else {
+
+    /* we're owned, we're in a call, let's try to transfer */
+        /************************** TODO
+                  Checking here if it is possible to transfer this call to Test2
+                  -&gt; GET CALL 288 CAN_TRANSFER Test2
+                  &lt;- CALL 288 CAN_TRANSFER test2 TRUE
+                 **********************************/
+
+    private_t *available_skypiax_interface = NULL;
+
+    gettimeofday(&amp;timenow, NULL);
+    for (i = 0; !found &amp;&amp; i &lt; SKYPIAX_MAX_INTERFACES; i++) {
+      if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
+
+        giovatech = &amp;globals.SKYPIAX_INTERFACES[i];
+        //NOTICA(&quot;skype interface: %d, name: %s, state: %d, value=%s, giovatech-&gt;callid_number=%s, giovatech-&gt;skype_user=%s\n&quot;, SKYPIAX_P_LOG, i, giovatech-&gt;name, giovatech-&gt;interface_state, value, giovatech-&gt;callid_number, giovatech-&gt;skype_user);
+        //FIXME check a timestamp here
+        if (strlen(giovatech-&gt;skype_transfer_call_id) &amp;&amp; (giovatech-&gt;interface_state != SKYPIAX_STATE_DOWN) &amp;&amp; (!strcmp(giovatech-&gt;skype_user, tech_pvt-&gt;skype_user)) &amp;&amp; (!strcmp(giovatech-&gt;transfer_callid_number, value)) &amp;&amp; ((((timenow.tv_sec - giovatech-&gt;transfer_time.tv_sec) * 1000000) + (timenow.tv_usec - giovatech-&gt;transfer_time.tv_usec)) &lt; 1000000)) {  //1.0 sec
+          found = 1;
+          DEBUGA_SKYPE
+            (&quot;FOUND  (name=%s, giovatech-&gt;interface_state=%d != SKYPIAX_STATE_DOWN) &amp;&amp; (giovatech-&gt;skype_user=%s == tech_pvt-&gt;skype_user=%s) &amp;&amp; (giovatech-&gt;transfer_callid_number=%s == value=%s)\n&quot;,
+             SKYPIAX_P_LOG, giovatech-&gt;name, giovatech-&gt;interface_state,
+             giovatech-&gt;skype_user, tech_pvt-&gt;skype_user,
+             giovatech-&gt;transfer_callid_number, value)
+            break;
+        }
+      }
+    }
+
+    if (found) {
+      //tech_pvt-&gt;callid_number[0]='\0';
+      switch_mutex_unlock(globals.mutex);
+      return 0;
+    }
+    DEBUGA_SKYPE(&quot;NOT FOUND\n&quot;, SKYPIAX_P_LOG);
+
+    available_skypiax_interface = find_available_skypiax_interface(tech_pvt);
+    if (available_skypiax_interface) {
+      /* there is a skypiax interface idle, let's transfer the call to it */
+
+      //FIXME write a timestamp here
+      gettimeofday(&amp;tech_pvt-&gt;transfer_time, NULL);
+      switch_copy_string(tech_pvt-&gt;skype_transfer_call_id, id,
+                         sizeof(tech_pvt-&gt;skype_transfer_call_id) - 1);
+
+      switch_copy_string(tech_pvt-&gt;transfer_callid_number, value,
+                         sizeof(tech_pvt-&gt;transfer_callid_number) - 1);
+
+      DEBUGA_SKYPE
+        (&quot;Let's transfer the skype_call %s to %s interface (with skype_user: %s), because we are already in a skypiax call(%s)\n&quot;,
+         SKYPIAX_P_LOG, tech_pvt-&gt;skype_call_id, available_skypiax_interface-&gt;name,
+         available_skypiax_interface-&gt;skype_user, id);
+      sprintf(msg_to_skype, &quot;ALTER CALL %s TRANSFER %s&quot;, id,
+              available_skypiax_interface-&gt;skype_user);
+      skypiax_signaling_write(tech_pvt, msg_to_skype);
+    } else {
+      /* no skypiax interfaces idle, do nothing */
+      DEBUGA_SKYPE
+        (&quot;Not answering the skype_call %s, because we are already in a skypiax call(%s) and no other skypiax interfaces are available OR another interface is answering this call\n&quot;,
+         SKYPIAX_P_LOG, tech_pvt-&gt;skype_call_id, id);
+      //sprintf(msg_to_skype, &quot;ALTER CALL %s END HANGUP&quot;, id);
+    }
+    switch_sleep(10000);
+    DEBUGA_SKYPE
+      (&quot;We (%s) have NOT answered a Skype RING on skype_call %s, because we are already in a skypiax call\n&quot;,
+       SKYPIAX_P_LOG, tech_pvt-&gt;skype_call_id, id);
+
+    switch_mutex_unlock(globals.mutex);
+  }
+  return 0;
+}
+
</ins><span class="cx"> /* For Emacs:
</span><span class="cx">  * Local Variables:
</span><span class="cx">  * mode:c
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_skypiaxskypiaxh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h (14339 => 14340)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h        2009-07-24 13:34:03 UTC (rev 14339)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h        2009-07-24 13:36:43 UTC (rev 14340)
</span><span class="lines">@@ -36,6 +36,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &lt;switch.h&gt;
</span><span class="cx"> #include &lt;switch_version.h&gt;
</span><ins>+#include &lt;sys/time.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> #ifndef WIN32
</span><span class="cx"> #include &lt;X11/Xlib.h&gt;
</span><span class="lines">@@ -232,7 +233,11 @@
</span><span class="cx">   char skype_user[256];
</span><span class="cx">   char skype_password[256];
</span><span class="cx">   char destination[256];
</span><ins>+  struct timeval answer_time;
</ins><span class="cx"> 
</span><ins>+  struct timeval transfer_time;
+  char transfer_callid_number[50];
+  char skype_transfer_call_id[512];
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> typedef struct private_object private_t;
</span><span class="lines">@@ -270,6 +275,8 @@
</span><span class="cx"> int skypiax_pipe_write(int pipe, short *buf, int howmany);
</span><span class="cx"> #endif /* WIN32 */
</span><span class="cx"> int skypiax_close_socket(unsigned int fd);
</span><del>-private_t *find_available_skypiax_interface(void);
</del><ins>+private_t *find_available_skypiax_interface(private_t * tech_pvt);
</ins><span class="cx"> int remote_party_is_ringing(private_t * tech_pvt);
</span><span class="cx"> int remote_party_is_early_media(private_t * tech_pvt);
</span><ins>+int skypiax_answer(private_t * tech_pvt, char *id, char *value);
+int skypiax_transfer(private_t * tech_pvt, char *id, char *value);
</ins></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_skypiaxskypiax_protocolc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c (14339 => 14340)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c        2009-07-24 13:34:03 UTC (rev 14339)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c        2009-07-24 13:36:43 UTC (rev 14340)
</span><span class="lines">@@ -25,7 +25,6 @@
</span><span class="cx"> int xerror = 0;
</span><span class="cx"> #endif /* WIN32 */
</span><span class="cx"> /*************************************/
</span><del>-
</del><span class="cx"> int skypiax_signaling_read(private_t * tech_pvt)
</span><span class="cx"> {
</span><span class="cx">   char read_from_pipe[4096];
</span><span class="lines">@@ -52,7 +51,9 @@
</span><span class="cx"> 
</span><span class="cx">     if (read_from_pipe[i] == '\0') {
</span><span class="cx"> 
</span><del>-      DEBUGA_SKYPE(&quot;READING: |||%s||| \n&quot;, SKYPIAX_P_LOG, message);
</del><ins>+      if (!strstr(message, &quot;DURATION&quot;)) {
+        DEBUGA_SKYPE(&quot;READING: |||%s||| \n&quot;, SKYPIAX_P_LOG, message);
+      }
</ins><span class="cx"> 
</span><span class="cx">       if (!strcasecmp(message, &quot;ERROR 68&quot;)) {
</span><span class="cx">         DEBUGA_SKYPE
</span><span class="lines">@@ -86,16 +87,21 @@
</span><span class="cx">         WARNINGA(&quot;Skype MSG without spaces: %s\n&quot;, SKYPIAX_P_LOG, message);
</span><span class="cx">       }
</span><span class="cx">       if (!strcasecmp(message, &quot;ERROR&quot;)) {
</span><del>-        DEBUGA_SKYPE(&quot;Skype got ERROR: |||%s|||\n&quot;, SKYPIAX_P_LOG, message);
-        tech_pvt-&gt;skype_callflow = CALLFLOW_STATUS_FINISHED;
-        DEBUGA_SKYPE(&quot;skype_call now is DOWN\n&quot;, SKYPIAX_P_LOG);
-        tech_pvt-&gt;skype_call_id[0] = '\0';
</del><ins>+        if (!strncasecmp(message, &quot;ERROR 592 ALTER CALL&quot;, 19)) {
+          ERRORA(&quot;Skype got ERROR about TRANSFERRING, no problem: |||%s|||\n&quot;,
+                 SKYPIAX_P_LOG, message);
+        } else {
+          DEBUGA_SKYPE(&quot;Skype got ERROR: |||%s|||\n&quot;, SKYPIAX_P_LOG, message);
+          tech_pvt-&gt;skype_callflow = CALLFLOW_STATUS_FINISHED;
+          DEBUGA_SKYPE(&quot;skype_call now is DOWN\n&quot;, SKYPIAX_P_LOG);
+          tech_pvt-&gt;skype_call_id[0] = '\0';
</ins><span class="cx"> 
</span><del>-        if (tech_pvt-&gt;interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
-          tech_pvt-&gt;interface_state = SKYPIAX_STATE_DOWN;
-          return CALLFLOW_INCOMING_HANGUP;
-        } else {
-          tech_pvt-&gt;interface_state = SKYPIAX_STATE_DOWN;
</del><ins>+          if (tech_pvt-&gt;interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
+            tech_pvt-&gt;interface_state = SKYPIAX_STATE_DOWN;
+            return CALLFLOW_INCOMING_HANGUP;
+          } else {
+            tech_pvt-&gt;interface_state = SKYPIAX_STATE_DOWN;
+          }
</ins><span class="cx">         }
</span><span class="cx">       }
</span><span class="cx">       if (!strcasecmp(message, &quot;CURRENTUSERHANDLE&quot;)) {
</span><span class="lines">@@ -160,27 +166,36 @@
</span><span class="cx">         skypiax_strncpy(value, where, sizeof(value) - 1);
</span><span class="cx">         where = strsep(stringp, &quot; &quot;);
</span><span class="cx"> 
</span><del>-        DEBUGA_SKYPE
-          (&quot;Skype MSG: message: %s, obj: %s, id: %s, prop: %s, value: %s,where: %s!\n&quot;,
-           SKYPIAX_P_LOG, message, obj, id, prop, value, where ? where : &quot;NULL&quot;);
</del><ins>+        //DEBUGA_SKYPE
+        //(&quot;Skype MSG: message: %s, obj: %s, id: %s, prop: %s, value: %s,where: %s!\n&quot;,
+        //SKYPIAX_P_LOG, message, obj, id, prop, value, where ? where : &quot;NULL&quot;);
</ins><span class="cx"> 
</span><span class="cx">         if (!strcasecmp(prop, &quot;PARTNER_HANDLE&quot;)) {
</span><del>-          skypiax_strncpy(tech_pvt-&gt;callid_number, value,
-                          sizeof(tech_pvt-&gt;callid_number) - 1);
-          DEBUGA_SKYPE
-            (&quot;the skype_call %s caller PARTNER_HANDLE (tech_pvt-&gt;callid_number) is: %s\n&quot;,
-             SKYPIAX_P_LOG, id, tech_pvt-&gt;callid_number);
-          return CALLFLOW_INCOMING_RING;
</del><ins>+          if (!strlen(tech_pvt-&gt;skype_call_id)) {
+            /* we are NOT inside an active call */
+            DEBUGA_SKYPE(&quot;Call %s TRY ANSWER\n&quot;, SKYPIAX_P_LOG, id);
+            skypiax_answer(tech_pvt, id, value);
+          } else {
+            /* we are inside an active call */
+            if (!strcasecmp(tech_pvt-&gt;skype_call_id, id)) {
+              /* this is the call in which we are calling out */
+              DEBUGA_SKYPE(&quot;Call %s NOTHING\n&quot;, SKYPIAX_P_LOG, id);
+            } else {
+              usleep(400000);   //0.4 seconds
+              DEBUGA_SKYPE(&quot;Call %s TRY TRANSFER\n&quot;, SKYPIAX_P_LOG, id);
+              skypiax_transfer(tech_pvt, id, value);
+            }
+          }
</ins><span class="cx">         }
</span><span class="cx">         if (!strcasecmp(prop, &quot;PARTNER_DISPNAME&quot;)) {
</span><span class="cx">           snprintf(tech_pvt-&gt;callid_name, sizeof(tech_pvt-&gt;callid_name) - 1, &quot;%s%s%s&quot;,
</span><span class="cx">                    value, where ? &quot; &quot; : &quot;&quot;, where ? where : &quot;&quot;);
</span><del>-          DEBUGA_SKYPE
-            (&quot;the skype_call %s caller PARTNER_DISPNAME (tech_pvt-&gt;callid_name) is: %s\n&quot;,
-             SKYPIAX_P_LOG, id, tech_pvt-&gt;callid_name);
</del><ins>+          //DEBUGA_SKYPE
+          //(&quot;the skype_call %s caller PARTNER_DISPNAME (tech_pvt-&gt;callid_name) is: %s\n&quot;,
+          //SKYPIAX_P_LOG, id, tech_pvt-&gt;callid_name);
</ins><span class="cx">         }
</span><span class="cx">         if (!strcasecmp(prop, &quot;CONF_ID&quot;) &amp;&amp; !strcasecmp(value, &quot;0&quot;)) {
</span><del>-          DEBUGA_SKYPE(&quot;the skype_call %s is NOT a conference call\n&quot;, SKYPIAX_P_LOG, id);
</del><ins>+          //DEBUGA_SKYPE(&quot;the skype_call %s is NOT a conference call\n&quot;, SKYPIAX_P_LOG, id);
</ins><span class="cx">           if (tech_pvt-&gt;interface_state == SKYPIAX_STATE_DOWN)
</span><span class="cx">             tech_pvt-&gt;interface_state = SKYPIAX_STATE_PRERING;
</span><span class="cx">         }
</span><span class="lines">@@ -211,71 +226,27 @@
</span><span class="cx"> 
</span><span class="cx">           if (!strcasecmp(value, &quot;RINGING&quot;)) {
</span><span class="cx">             char msg_to_skype[1024];
</span><del>-            if (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DIALING) {
-              /* we are not calling out */
-              if (!strlen(tech_pvt-&gt;skype_call_id)) {
-                /* we are not inside an active call */
</del><ins>+            if (!strlen(tech_pvt-&gt;skype_call_id)) {
+              /* we are NOT inside an active call */
+              sprintf(msg_to_skype, &quot;GET CALL %s PARTNER_HANDLE&quot;, id);
+              skypiax_signaling_write(tech_pvt, msg_to_skype);
+              skypiax_sleep(10000);
+            } else {
+              /* we are inside an active call */
+              if (!strcasecmp(tech_pvt-&gt;skype_call_id, id)) {
+                /* this is the call in which we are calling out */
</ins><span class="cx">                 tech_pvt-&gt;skype_callflow = CALLFLOW_STATUS_RINGING;
</span><del>-                tech_pvt-&gt;interface_state = SKYPIAX_STATE_RING;
-                /* no owner, no active call, let's answer */
-                skypiax_signaling_write(tech_pvt, &quot;SET AGC OFF&quot;);
-                skypiax_sleep(10000);
-                skypiax_signaling_write(tech_pvt, &quot;SET AEC OFF&quot;);
-                skypiax_sleep(10000);
-                sprintf(msg_to_skype, &quot;GET CALL %s PARTNER_DISPNAME&quot;, id);
-                skypiax_signaling_write(tech_pvt, msg_to_skype);
-                skypiax_sleep(10000);
-                sprintf(msg_to_skype, &quot;GET CALL %s PARTNER_HANDLE&quot;, id);
-                skypiax_signaling_write(tech_pvt, msg_to_skype);
-                skypiax_sleep(10000);
-                sprintf(msg_to_skype, &quot;ALTER CALL %s ANSWER&quot;, id);
-                skypiax_signaling_write(tech_pvt, msg_to_skype);
-                DEBUGA_SKYPE(&quot;We answered a Skype RING on skype_call %s\n&quot;, SKYPIAX_P_LOG,
-                             id);
</del><ins>+                tech_pvt-&gt;interface_state = SKYPIAX_STATE_RINGING;
</ins><span class="cx">                 skypiax_strncpy(tech_pvt-&gt;skype_call_id, id,
</span><span class="cx">                                 sizeof(tech_pvt-&gt;skype_call_id) - 1);
</span><ins>+                DEBUGA_SKYPE(&quot;Our remote party in skype_call %s is RINGING\n&quot;,
+                             SKYPIAX_P_LOG, id);
+                remote_party_is_ringing(tech_pvt);
</ins><span class="cx">               } else {
</span><del>-                /* we're owned, we're in a call, let's try to transfer */
-        /************************** TODO
-                 Checking here if it is possible to transfer this call to Test2
-                 -&gt; GET CALL 288 CAN_TRANSFER Test2
-                 &lt;- CALL 288 CAN_TRANSFER test2 TRUE
-                **********************************/
-
-                private_t *available_skypiax_interface;
-
-                available_skypiax_interface = find_available_skypiax_interface();
-                if (available_skypiax_interface) {
-                  /* there is a skypiax interface idle, let's transfer the call to it */
-                  DEBUGA_SKYPE
-                    (&quot;Let's transfer the skype_call %s to %s interface (with skype_user: %s), because we are already in a skypiax call(%s)\n&quot;,
-                     SKYPIAX_P_LOG, tech_pvt-&gt;skype_call_id,
-                     available_skypiax_interface-&gt;name,
-                     available_skypiax_interface-&gt;skype_user, id);
-                  sprintf(msg_to_skype, &quot;ALTER CALL %s TRANSFER %s&quot;, id,
-                          available_skypiax_interface-&gt;skype_user);
-                } else {
-                  /* no skypiax interfaces idle, let's refuse the call */
-                  DEBUGA_SKYPE
-                    (&quot;Let's refuse the skype_call %s, because we are already in a skypiax call(%s) and no other skypiax interfaces are available\n&quot;,
-                     SKYPIAX_P_LOG, tech_pvt-&gt;skype_call_id, id);
-                  sprintf(msg_to_skype, &quot;ALTER CALL %s END HANGUP&quot;, id);
-                }
</del><ins>+                sprintf(msg_to_skype, &quot;GET CALL %s PARTNER_HANDLE&quot;, id);
</ins><span class="cx">                 skypiax_signaling_write(tech_pvt, msg_to_skype);
</span><span class="cx">                 skypiax_sleep(10000);
</span><del>-                DEBUGA_SKYPE
-                  (&quot;We (%s) have NOT answered a Skype RING on skype_call %s, because we are already in a skypiax call\n&quot;,
-                   SKYPIAX_P_LOG, tech_pvt-&gt;skype_call_id, id);
</del><span class="cx">               }
</span><del>-            } else {
-              /* we are calling out */
-              tech_pvt-&gt;skype_callflow = CALLFLOW_STATUS_RINGING;
-              tech_pvt-&gt;interface_state = SKYPIAX_STATE_RINGING;
-              skypiax_strncpy(tech_pvt-&gt;skype_call_id, id,
-                              sizeof(tech_pvt-&gt;skype_call_id) - 1);
-              DEBUGA_SKYPE(&quot;Our remote party in skype_call %s is RINGING\n&quot;,
-                           SKYPIAX_P_LOG, id);
-              remote_party_is_ringing(tech_pvt);
</del><span class="cx">             }
</span><span class="cx">           } else if (!strcasecmp(value, &quot;EARLYMEDIA&quot;)) {
</span><span class="cx">             char msg_to_skype[1024];
</span><span class="lines">@@ -296,8 +267,10 @@
</span><span class="cx">           } else if (!strcasecmp(value, &quot;MISSED&quot;)) {
</span><span class="cx">             DEBUGA_SKYPE(&quot;We missed skype_call %s\n&quot;, SKYPIAX_P_LOG, id);
</span><span class="cx">           } else if (!strcasecmp(value, &quot;FINISHED&quot;)) {
</span><del>-            DEBUGA_SKYPE(&quot;skype_call %s now is DOWN\n&quot;, SKYPIAX_P_LOG, id);
</del><ins>+            //DEBUGA_SKYPE(&quot;skype_call %s now is DOWN\n&quot;, SKYPIAX_P_LOG, id);
+            //usleep(150000);//150msec, let's give the TCP sockets time to timeout
</ins><span class="cx">             if (!strcasecmp(tech_pvt-&gt;skype_call_id, id)) {
</span><ins>+              tech_pvt-&gt;skype_callflow = CALLFLOW_STATUS_FINISHED;
</ins><span class="cx">               DEBUGA_SKYPE(&quot;skype_call %s is MY call, now I'm going DOWN\n&quot;,
</span><span class="cx">                            SKYPIAX_P_LOG, id);
</span><span class="cx">               tech_pvt-&gt;skype_call_id[0] = '\0';
</span><span class="lines">@@ -365,50 +338,50 @@
</span><span class="cx">             skypiax_strncpy(tech_pvt-&gt;skype_call_id, id,
</span><span class="cx">                             sizeof(tech_pvt-&gt;skype_call_id) - 1);
</span><span class="cx">             DEBUGA_SKYPE(&quot;skype_call: %s is now UNPLACED\n&quot;, SKYPIAX_P_LOG, id);
</span><del>-          } else if (!strcasecmp(value, &quot;INPROGRESS&quot;)) {
-                  char msg_to_skype[1024];
</del><ins>+          } else if (!strcasecmp(value, &quot;INPROGRESS&quot;)) {
+            char msg_to_skype[1024];
</ins><span class="cx"> 
</span><del>-                  if (tech_pvt-&gt;skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
-                          if (!strlen(tech_pvt-&gt;session_uuid_str) || !strlen(tech_pvt-&gt;skype_call_id)
-                                          || !strcasecmp(tech_pvt-&gt;skype_call_id, id)) {
-                                  skypiax_strncpy(tech_pvt-&gt;skype_call_id, id,
-                                                  sizeof(tech_pvt-&gt;skype_call_id) - 1);
-                                  DEBUGA_SKYPE(&quot;skype_call: %s is now active\n&quot;, SKYPIAX_P_LOG, id);
</del><ins>+            if (tech_pvt-&gt;skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
+              if (!strlen(tech_pvt-&gt;session_uuid_str) || !strlen(tech_pvt-&gt;skype_call_id)
+                  || !strcasecmp(tech_pvt-&gt;skype_call_id, id)) {
+                skypiax_strncpy(tech_pvt-&gt;skype_call_id, id,
+                                sizeof(tech_pvt-&gt;skype_call_id) - 1);
+                DEBUGA_SKYPE(&quot;skype_call: %s is now active\n&quot;, SKYPIAX_P_LOG, id);
</ins><span class="cx"> 
</span><del>-                                  if (tech_pvt-&gt;skype_callflow != CALLFLOW_STATUS_EARLYMEDIA) {
-                                          tech_pvt-&gt;skype_callflow = CALLFLOW_STATUS_INPROGRESS;
-                                          tech_pvt-&gt;interface_state = SKYPIAX_STATE_UP;
-                                          start_audio_threads(tech_pvt);
-                                          skypiax_sleep(1000); //FIXME
-                                          sprintf(msg_to_skype, &quot;ALTER CALL %s SET_INPUT PORT=\&quot;%d\&quot;&quot;, id,
-                                                          tech_pvt-&gt;tcp_cli_port);
-                                          skypiax_signaling_write(tech_pvt, msg_to_skype);
-                                          skypiax_sleep(1000); //FIXME
-                                          sprintf(msg_to_skype, &quot;#output ALTER CALL %s SET_OUTPUT PORT=\&quot;%d\&quot;&quot;, id,
-                                                          tech_pvt-&gt;tcp_srv_port);
-                                          skypiax_signaling_write(tech_pvt, msg_to_skype);
-                                  }
-                                  tech_pvt-&gt;skype_callflow = SKYPIAX_STATE_UP;
-                                  if (!strlen(tech_pvt-&gt;session_uuid_str)) {
-                                          DEBUGA_SKYPE(&quot;New Inbound Channel!\n&quot;, SKYPIAX_P_LOG);
-                                          new_inbound_channel(tech_pvt);
-                                  } else {
-                                          DEBUGA_SKYPE(&quot;Outbound Channel Answered!\n&quot;, SKYPIAX_P_LOG);
-                                          outbound_channel_answered(tech_pvt);
-                                  }
-                          } else {
-                                  DEBUGA_SKYPE(&quot;I'm on %s, skype_call %s is NOT MY call, ignoring\n&quot;,
-                                                  SKYPIAX_P_LOG, tech_pvt-&gt;skype_call_id, id);
-                          }
-                  } else {
-                          tech_pvt-&gt;skype_callflow = CALLFLOW_STATUS_INPROGRESS;
-                          WARNINGA(&quot;Back from REMOTEHOLD!\n&quot;, SKYPIAX_P_LOG);
-                  }
</del><ins>+                if (tech_pvt-&gt;skype_callflow != CALLFLOW_STATUS_EARLYMEDIA) {
+                  tech_pvt-&gt;skype_callflow = CALLFLOW_STATUS_INPROGRESS;
+                  tech_pvt-&gt;interface_state = SKYPIAX_STATE_UP;
+                  start_audio_threads(tech_pvt);
+                  skypiax_sleep(1000);  //FIXME
+                  sprintf(msg_to_skype, &quot;ALTER CALL %s SET_INPUT PORT=\&quot;%d\&quot;&quot;, id,
+                          tech_pvt-&gt;tcp_cli_port);
+                  skypiax_signaling_write(tech_pvt, msg_to_skype);
+                  skypiax_sleep(1000);  //FIXME
+                  sprintf(msg_to_skype, &quot;#output ALTER CALL %s SET_OUTPUT PORT=\&quot;%d\&quot;&quot;,
+                          id, tech_pvt-&gt;tcp_srv_port);
+                  skypiax_signaling_write(tech_pvt, msg_to_skype);
+                }
+                tech_pvt-&gt;skype_callflow = SKYPIAX_STATE_UP;
+                if (!strlen(tech_pvt-&gt;session_uuid_str)) {
+                  DEBUGA_SKYPE(&quot;New Inbound Channel!\n&quot;, SKYPIAX_P_LOG);
+                  new_inbound_channel(tech_pvt);
+                } else {
+                  DEBUGA_SKYPE(&quot;Outbound Channel Answered!\n&quot;, SKYPIAX_P_LOG);
+                  outbound_channel_answered(tech_pvt);
+                }
+              } else {
+                DEBUGA_SKYPE(&quot;I'm on %s, skype_call %s is NOT MY call, ignoring\n&quot;,
+                             SKYPIAX_P_LOG, tech_pvt-&gt;skype_call_id, id);
+              }
+            } else {
+              tech_pvt-&gt;skype_callflow = CALLFLOW_STATUS_INPROGRESS;
+              WARNINGA(&quot;Back from REMOTEHOLD!\n&quot;, SKYPIAX_P_LOG);
+            }
</ins><span class="cx"> 
</span><del>-          } else if (!strcasecmp(value, &quot;REMOTEHOLD&quot;)) {
-                  tech_pvt-&gt;skype_callflow = CALLFLOW_STATUS_REMOTEHOLD;
-                  WARNINGA(&quot;skype_call: %s is now REMOTEHOLD\n&quot;, SKYPIAX_P_LOG, id);
-          } else {
</del><ins>+          } else if (!strcasecmp(value, &quot;REMOTEHOLD&quot;)) {
+            tech_pvt-&gt;skype_callflow = CALLFLOW_STATUS_REMOTEHOLD;
+            WARNINGA(&quot;skype_call: %s is now REMOTEHOLD\n&quot;, SKYPIAX_P_LOG, id);
+          } else {
</ins><span class="cx">             WARNINGA(&quot;skype_call: %s, STATUS: %s is not recognized\n&quot;, SKYPIAX_P_LOG, id,
</span><span class="cx">                      value);
</span><span class="cx">           }
</span><span class="lines">@@ -456,7 +429,7 @@
</span><span class="cx">   short srv_out[SAMPLES_PER_FRAME / 2];
</span><span class="cx">   struct sockaddr_in my_addr;
</span><span class="cx">   struct sockaddr_in remote_addr;
</span><del>-  int exit = 0;
</del><ins>+  //int exit = 0;
</ins><span class="cx">   unsigned int kill_cli_size;
</span><span class="cx">   short kill_cli_buff[SAMPLES_PER_FRAME];
</span><span class="cx">   short totalbuf[SAMPLES_PER_FRAME];
</span><span class="lines">@@ -480,115 +453,148 @@
</span><span class="cx">   listen(s, 6);
</span><span class="cx"> 
</span><span class="cx">   sin_size = sizeof(remote_addr);
</span><del>-  while ((fd = accept(s, (struct sockaddr *) &amp;remote_addr, &amp;sin_size)) &gt; 0) {
-    DEBUGA_SKYPE(&quot;ACCEPTED here I send you %d\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;tcp_srv_port);
</del><ins>+
+  /****************************/
+  while (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN
+         &amp;&amp; (tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_INPROGRESS
+             || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
+             || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_REMOTEHOLD
+             || tech_pvt-&gt;skype_callflow == SKYPIAX_STATE_UP)) {
+
+    unsigned int fdselectgio;
+    int rtgio;
+    fd_set fsgio;
+    struct timeval togio;
+
</ins><span class="cx">     if (!running)
</span><span class="cx">       break;
</span><del>-    while (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN
-           &amp;&amp; (tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_INPROGRESS
-               || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
-               || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_REMOTEHOLD
-               || tech_pvt-&gt;skype_callflow == SKYPIAX_STATE_UP)) {
</del><ins>+    FD_ZERO(&amp;fsgio);
+    togio.tv_usec = 20000;      //20msec
+    togio.tv_sec = 0;
+    fdselectgio = s;
+    FD_SET(fdselectgio, &amp;fsgio);
</ins><span class="cx"> 
</span><del>-      unsigned int fdselect;
-      int rt;
-      fd_set fs;
-      struct timeval to;
</del><ins>+    rtgio = select(fdselectgio + 1, &amp;fsgio, NULL, NULL, &amp;togio);
</ins><span class="cx"> 
</span><del>-      if (!running)
-        break;
-      exit = 1;
</del><ins>+    if (rtgio) {
</ins><span class="cx"> 
</span><del>-      fdselect = fd;
-      FD_ZERO(&amp;fs);
-      FD_SET(fdselect, &amp;fs);
-      to.tv_usec = 2000000;     //2000 msec
-      to.tv_sec = 0;
</del><ins>+  /****************************/
</ins><span class="cx"> 
</span><del>-      rt = select(fdselect + 1, &amp;fs, NULL, NULL, &amp;to);
-      if (rt &gt; 0) {
</del><ins>+      while ((fd = accept(s, (struct sockaddr *) &amp;remote_addr, &amp;sin_size)) &gt; 0) {
+        DEBUGA_SKYPE(&quot;ACCEPTED here I send you %d\n&quot;, SKYPIAX_P_LOG,
+                     tech_pvt-&gt;tcp_srv_port);
+        if (!running)
+          break;
+        while (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN
+               &amp;&amp; (tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_INPROGRESS
+                   || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
+                   || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_REMOTEHOLD
+                   || tech_pvt-&gt;skype_callflow == SKYPIAX_STATE_UP)) {
</ins><span class="cx"> 
</span><del>-              if (tech_pvt-&gt;skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
-                      len = recv(fd, (char *) srv_in, 320, 0);    //seems that Skype only sends 320 bytes at time
-              } else {
-                      len = 0;
-              }
</del><ins>+          unsigned int fdselect;
+          int rt;
+          fd_set fs;
+          struct timeval to;
</ins><span class="cx"> 
</span><del>-              if (len == 320) {
-                      unsigned int howmany;
</del><ins>+          if (!running)
+            break;
+          //exit = 1;
</ins><span class="cx"> 
</span><del>-                      if (samplerate_skypiax == 8000) {
-                              /* we're downsampling from 16khz to 8khz, srv_out will contain each other sample from srv_in */
-                              a = 0;
-                              for (i = 0; i &lt; len / sizeof(short); i++) {
-                                      srv_out[a] = srv_in[i];
-                                      i++;
-                                      a++;
-                              }
-                      } else if (samplerate_skypiax == 16000) {
-                              /* we're NOT downsampling, srv_out will contain ALL samples from srv_in */
-                              for (i = 0; i &lt; len / sizeof(short); i++) {
-                                      srv_out[i] = srv_in[i];
-                              }
-                      } else {
-                              ERRORA(&quot;SAMPLERATE_SKYPIAX can only be 8000 or 16000\n&quot;, SKYPIAX_P_LOG);
-                      }
-                      /* if not yet done, let's store the half incoming frame */
-                      if (!tech_pvt-&gt;audiobuf_is_loaded) {
-                              for (i = 0; i &lt; SAMPLES_PER_FRAME / 2; i++) {
-                                      tech_pvt-&gt;audiobuf[i] = srv_out[i];
-                              }
-                              tech_pvt-&gt;audiobuf_is_loaded = 1;
-                      } else {
-                              /* we got a stored half frame, build a complete frame in totalbuf using the stored half frame and the current half frame */
-                              for (i = 0; i &lt; SAMPLES_PER_FRAME / 2; i++) {
-                                      totalbuf[i] = tech_pvt-&gt;audiobuf[i];
-                              }
-                              for (a = 0; a &lt; SAMPLES_PER_FRAME / 2; a++) {
-                                      totalbuf[i] = srv_out[a];
-                                      i++;
-                              }
-                              /* send the complete frame through the pipe to our code waiting for incoming audio */
-                              howmany =
-                                      skypiax_pipe_write(tech_pvt-&gt;audiopipe[1], totalbuf,
-                                                      SAMPLES_PER_FRAME * sizeof(short));
-                              if (howmany != SAMPLES_PER_FRAME * sizeof(short)) {
-                                      ERRORA(&quot;howmany is %d, but was expected to be %d\n&quot;, SKYPIAX_P_LOG, howmany,
-                                                      (int) (SAMPLES_PER_FRAME * sizeof(short)));
-                              }
-                              /* done with the stored half frame */
-                              tech_pvt-&gt;audiobuf_is_loaded = 0;
-                      }
</del><ins>+          fdselect = fd;
+          FD_ZERO(&amp;fs);
+          FD_SET(fdselect, &amp;fs);
+          //to.tv_usec = 2000000;     //2000 msec
+          to.tv_usec = 60000;   //60 msec
+          to.tv_sec = 0;
</ins><span class="cx"> 
</span><del>-              } else if (len == 0) {
-                      skypiax_sleep(1000);
-              } else {
-                      ERRORA(&quot;len=%d, expected 320\n&quot;, SKYPIAX_P_LOG, len);
-              }
</del><ins>+          rt = select(fdselect + 1, &amp;fs, NULL, NULL, &amp;to);
+          if (rt &gt; 0) {
</ins><span class="cx"> 
</span><del>-      } else {
-        if (rt)
-          ERRORA(&quot;SRV rt=%d\n&quot;, SKYPIAX_P_LOG, rt);
-        skypiax_sleep(10000);
-      }
</del><ins>+            if (tech_pvt-&gt;skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
+              len = recv(fd, (char *) srv_in, 320, 0);  //seems that Skype only sends 320 bytes at time
+            } else {
+              len = 0;
+            }
</ins><span class="cx"> 
</span><del>-    }
</del><ins>+            if (len == 320) {
+              unsigned int howmany;
</ins><span class="cx"> 
</span><del>-    /* let's send some frame in the pipes, so both tcp_cli and tcp_srv will have an occasion to die */
-    kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
-    len = skypiax_pipe_write(tech_pvt-&gt;audiopipe[1], kill_cli_buff, kill_cli_size);
-    kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
-    len = skypiax_pipe_write(tech_pvt-&gt;audioskypepipe[1], kill_cli_buff, kill_cli_size);
-    tech_pvt-&gt;interface_state = SKYPIAX_STATE_DOWN;
-    kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
-    len = skypiax_pipe_write(tech_pvt-&gt;audiopipe[1], kill_cli_buff, kill_cli_size);
-    kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
-    len = skypiax_pipe_write(tech_pvt-&gt;audioskypepipe[1], kill_cli_buff, kill_cli_size);
</del><ins>+              if (samplerate_skypiax == 8000) {
+                /* we're downsampling from 16khz to 8khz, srv_out will contain each other sample from srv_in */
+                a = 0;
+                for (i = 0; i &lt; len / sizeof(short); i++) {
+                  srv_out[a] = srv_in[i];
+                  i++;
+                  a++;
+                }
+              } else if (samplerate_skypiax == 16000) {
+                /* we're NOT downsampling, srv_out will contain ALL samples from srv_in */
+                for (i = 0; i &lt; len / sizeof(short); i++) {
+                  srv_out[i] = srv_in[i];
+                }
+              } else {
+                ERRORA(&quot;SAMPLERATE_SKYPIAX can only be 8000 or 16000\n&quot;, SKYPIAX_P_LOG);
+              }
+              /* if not yet done, let's store the half incoming frame */
+              if (!tech_pvt-&gt;audiobuf_is_loaded) {
+                for (i = 0; i &lt; SAMPLES_PER_FRAME / 2; i++) {
+                  tech_pvt-&gt;audiobuf[i] = srv_out[i];
+                }
+                tech_pvt-&gt;audiobuf_is_loaded = 1;
+              } else {
+                /* we got a stored half frame, build a complete frame in totalbuf using the stored half frame and the current half frame */
+                for (i = 0; i &lt; SAMPLES_PER_FRAME / 2; i++) {
+                  totalbuf[i] = tech_pvt-&gt;audiobuf[i];
+                }
+                for (a = 0; a &lt; SAMPLES_PER_FRAME / 2; a++) {
+                  totalbuf[i] = srv_out[a];
+                  i++;
+                }
+                /* send the complete frame through the pipe to our code waiting for incoming audio */
+                howmany =
+                  skypiax_pipe_write(tech_pvt-&gt;audiopipe[1], totalbuf,
+                                     SAMPLES_PER_FRAME * sizeof(short));
+                if (howmany != SAMPLES_PER_FRAME * sizeof(short)) {
+                  ERRORA(&quot;howmany is %d, but was expected to be %d\n&quot;, SKYPIAX_P_LOG,
+                         howmany, (int) (SAMPLES_PER_FRAME * sizeof(short)));
+                }
+                /* done with the stored half frame */
+                tech_pvt-&gt;audiobuf_is_loaded = 0;
+              }
</ins><span class="cx"> 
</span><del>-    DEBUGA_SKYPE(&quot;Skype incoming audio GONE\n&quot;, SKYPIAX_P_LOG);
-    skypiax_close_socket(fd);
-    if (exit)
-      break;
</del><ins>+            } else if (len == 0) {
+              skypiax_sleep(1000);
+            } else {
+              ERRORA(&quot;len=%d, expected 320\n&quot;, SKYPIAX_P_LOG, len);
+            }
+
+          } else {
+            if (rt)
+              ERRORA(&quot;SRV rt=%d\n&quot;, SKYPIAX_P_LOG, rt);
+            skypiax_sleep(10000);
+          }
+
+        }
+
+        /* let's send some frame in the pipes, so both tcp_cli and tcp_srv will have an occasion to die */
+        kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
+        len = skypiax_pipe_write(tech_pvt-&gt;audiopipe[1], kill_cli_buff, kill_cli_size);
+        kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
+        len =
+          skypiax_pipe_write(tech_pvt-&gt;audioskypepipe[1], kill_cli_buff, kill_cli_size);
+        tech_pvt-&gt;interface_state = SKYPIAX_STATE_DOWN;
+        kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
+        len = skypiax_pipe_write(tech_pvt-&gt;audiopipe[1], kill_cli_buff, kill_cli_size);
+        kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
+        len =
+          skypiax_pipe_write(tech_pvt-&gt;audioskypepipe[1], kill_cli_buff, kill_cli_size);
+
+        DEBUGA_SKYPE(&quot;Skype incoming audio GONE\n&quot;, SKYPIAX_P_LOG);
+        skypiax_close_socket(fd);
+        //if (exit)
+        break;
+      }
+    }
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">   DEBUGA_SKYPE(&quot;incoming audio server (I am it) EXITING\n&quot;, SKYPIAX_P_LOG);
</span><span class="lines">@@ -635,110 +641,140 @@
</span><span class="cx">   listen(s, 6);
</span><span class="cx"> 
</span><span class="cx">   sin_size = sizeof(remote_addr);
</span><del>-  while ((fd = accept(s, (struct sockaddr *) &amp;remote_addr, &amp;sin_size)) &gt; 0) {
-    DEBUGA_SKYPE(&quot;ACCEPTED here you send me %d\n&quot;, SKYPIAX_P_LOG, tech_pvt-&gt;tcp_cli_port);
</del><ins>+
+  /****************************/
+  while (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN
+         &amp;&amp; (tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_INPROGRESS
+             || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
+             || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_REMOTEHOLD
+             || tech_pvt-&gt;skype_callflow == SKYPIAX_STATE_UP)) {
+
+    unsigned int fdselectgio;
+    int rtgio;
+    fd_set fsgio;
+    struct timeval togio;
+
</ins><span class="cx">     if (!running)
</span><span class="cx">       break;
</span><del>-    while (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN
-           &amp;&amp; (tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_INPROGRESS
-               || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
-               || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_REMOTEHOLD
-               || tech_pvt-&gt;skype_callflow == SKYPIAX_STATE_UP)) {
-      unsigned int fdselect;
-      int rt;
-      fd_set fs;
-      struct timeval to;
</del><ins>+    FD_ZERO(&amp;fsgio);
+    togio.tv_usec = 20000;      //20msec
+    togio.tv_sec = 0;
+    fdselectgio = s;
+    FD_SET(fdselectgio, &amp;fsgio);
</ins><span class="cx"> 
</span><del>-      if (!running)
-        break;
-      FD_ZERO(&amp;fs);
-      to.tv_usec = 60000;       //60msec
-      to.tv_sec = 0;
</del><ins>+    rtgio = select(fdselectgio + 1, &amp;fsgio, NULL, NULL, &amp;togio);
+
+    if (rtgio) {
+
+  /****************************/
+
+      while ((fd = accept(s, (struct sockaddr *) &amp;remote_addr, &amp;sin_size)) &gt; 0) {
+        DEBUGA_SKYPE(&quot;ACCEPTED here you send me %d\n&quot;, SKYPIAX_P_LOG,
+                     tech_pvt-&gt;tcp_cli_port);
+        if (!running)
+          break;
+        while (tech_pvt-&gt;interface_state != SKYPIAX_STATE_DOWN
+               &amp;&amp; (tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_INPROGRESS
+                   || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
+                   || tech_pvt-&gt;skype_callflow == CALLFLOW_STATUS_REMOTEHOLD
+                   || tech_pvt-&gt;skype_callflow == SKYPIAX_STATE_UP)) {
+          unsigned int fdselect;
+          int rt;
+          fd_set fs;
+          struct timeval to;
+
+          if (!running)
+            break;
+          FD_ZERO(&amp;fs);
+          to.tv_usec = 60000;   //60msec
+          to.tv_sec = 0;
</ins><span class="cx"> #if defined(WIN32) &amp;&amp; !defined(__CYGWIN__)
</span><span class="cx"> /* on win32 we cannot select from the apr &quot;pipe&quot;, so we select on socket writability */
</span><del>-      fdselect = fd;
-      FD_SET(fdselect, &amp;fs);
</del><ins>+          fdselect = fd;
+          FD_SET(fdselect, &amp;fs);
</ins><span class="cx"> 
</span><del>-      rt = select(fdselect + 1, NULL, &amp;fs, NULL, &amp;to);
</del><ins>+          rt = select(fdselect + 1, NULL, &amp;fs, NULL, &amp;to);
</ins><span class="cx"> #else
</span><span class="cx"> /* on *unix and cygwin we select from the real pipe */
</span><del>-      fdselect = tech_pvt-&gt;audioskypepipe[0];
-      FD_SET(fdselect, &amp;fs);
</del><ins>+          fdselect = tech_pvt-&gt;audioskypepipe[0];
+          FD_SET(fdselect, &amp;fs);
</ins><span class="cx"> 
</span><del>-      rt = select(fdselect + 1, &amp;fs, NULL, NULL, &amp;to);
</del><ins>+          rt = select(fdselect + 1, &amp;fs, NULL, NULL, &amp;to);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-      if (rt &gt; 0) {
-        /* read from the pipe the audio frame we are supposed to send out */
-        got =
-          skypiax_pipe_read(tech_pvt-&gt;audioskypepipe[0], cli_in,
-                            SAMPLES_PER_FRAME * sizeof(short));
-        if (got != SAMPLES_PER_FRAME * sizeof(short)) {
-          WARNINGA(&quot;got is %d, but was expected to be %d\n&quot;, SKYPIAX_P_LOG, got,
-                   (int) (SAMPLES_PER_FRAME * sizeof(short)));
-        }
</del><ins>+          if (rt &gt; 0) {
+            /* read from the pipe the audio frame we are supposed to send out */
+            got =
+              skypiax_pipe_read(tech_pvt-&gt;audioskypepipe[0], cli_in,
+                                SAMPLES_PER_FRAME * sizeof(short));
+            if (got != SAMPLES_PER_FRAME * sizeof(short)) {
+              WARNINGA(&quot;got is %d, but was expected to be %d\n&quot;, SKYPIAX_P_LOG, got,
+                       (int) (SAMPLES_PER_FRAME * sizeof(short)));
+            }
</ins><span class="cx"> 
</span><del>-        if (got == SAMPLES_PER_FRAME * sizeof(short)) {
-          if (samplerate_skypiax == 8000) {
</del><ins>+            if (got == SAMPLES_PER_FRAME * sizeof(short)) {
+              if (samplerate_skypiax == 8000) {
</ins><span class="cx"> 
</span><del>-            /* we're upsampling from 8khz to 16khz, cli_out will contain two times each sample from cli_in */
-            a = 0;
-            for (i = 0; i &lt; got / sizeof(short); i++) {
-              cli_out[a] = cli_in[i];
-              a++;
-              cli_out[a] = cli_in[i];
-              a++;
</del><ins>+                /* we're upsampling from 8khz to 16khz, cli_out will contain two times each sample from cli_in */
+                a = 0;
+                for (i = 0; i &lt; got / sizeof(short); i++) {
+                  cli_out[a] = cli_in[i];
+                  a++;
+                  cli_out[a] = cli_in[i];
+                  a++;
+                }
+                got = got * 2;
+              } else if (samplerate_skypiax == 16000) {
+                /* we're NOT upsampling, cli_out will contain just ALL samples from cli_in */
+                for (i = 0; i &lt; got / sizeof(short); i++) {
+                  cli_out[i] = cli_in[i];
+                }
+              } else {
+                ERRORA(&quot;SAMPLERATE_SKYPIAX can only be 8000 or 16000\n&quot;, SKYPIAX_P_LOG);
+              }
+
+              /* send the 16khz frame to the Skype client waiting for incoming audio to be sent to the remote party */
+              if (tech_pvt-&gt;skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
+                len = send(fd, (char *) cli_out, got, 0);
+                skypiax_sleep(5000);    //5 msec
+
+                if (len == -1) {
+                  break;
+                } else if (len != got) {
+                  ERRORA(&quot;len=%d\n&quot;, SKYPIAX_P_LOG, len);
+                  skypiax_sleep(1000);
+                  break;
+                }
+              }
+
+            } else {
+
+              WARNINGA(&quot;got is %d, but was expected to be %d\n&quot;, SKYPIAX_P_LOG, got,
+                       (int) (SAMPLES_PER_FRAME * sizeof(short)));
</ins><span class="cx">             }
</span><del>-            got = got * 2;
-          } else if (samplerate_skypiax == 16000) {
-            /* we're NOT upsampling, cli_out will contain just ALL samples from cli_in */
-            for (i = 0; i &lt; got / sizeof(short); i++) {
-              cli_out[i] = cli_in[i];
</del><ins>+          } else {
+            if (rt)
+              ERRORA(&quot;CLI rt=%d\n&quot;, SKYPIAX_P_LOG, rt);
+            memset(cli_out, 0, sizeof(cli_out));
+            if (tech_pvt-&gt;skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
+              len = send(fd, (char *) cli_out, sizeof(cli_out), 0);
+              len = send(fd, (char *) cli_out, sizeof(cli_out) / 2, 0);
+              //WARNINGA(&quot;sent %d of zeros to keep the Skype client socket busy\n&quot;, SKYPIAX_P_LOG, sizeof(cli_out) + sizeof(cli_out)/2);
+            } else {
+              /*
+                 XXX do nothing 
+               */
+              //WARNINGA(&quot;we don't send it\n&quot;, SKYPIAX_P_LOG);
</ins><span class="cx">             }
</span><del>-          } else {
-            ERRORA(&quot;SAMPLERATE_SKYPIAX can only be 8000 or 16000\n&quot;, SKYPIAX_P_LOG);
</del><ins>+            skypiax_sleep(1000);
</ins><span class="cx">           }
</span><span class="cx"> 
</span><del>-          /* send the 16khz frame to the Skype client waiting for incoming audio to be sent to the remote party */
-          if (tech_pvt-&gt;skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
-                  len = send(fd, (char *) cli_out, got, 0);
-                  skypiax_sleep(5000);  //5 msec
-
-                  if (len == -1) {
-                          break;
-                  } else if (len != got) {
-                          ERRORA(&quot;len=%d\n&quot;, SKYPIAX_P_LOG, len);
-                          skypiax_sleep(1000);
-                          break;
-                  }
-          }
-
-        } else {
-
-          WARNINGA(&quot;got is %d, but was expected to be %d\n&quot;, SKYPIAX_P_LOG, got,
-                   (int) (SAMPLES_PER_FRAME * sizeof(short)));
</del><span class="cx">         }
</span><del>-      } else {
-        if (rt)
-          ERRORA(&quot;CLI rt=%d\n&quot;, SKYPIAX_P_LOG, rt);
-        memset(cli_out, 0, sizeof(cli_out));
-        if (tech_pvt-&gt;skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
-                len = send(fd, (char *) cli_out, sizeof(cli_out), 0);
-                len = send(fd, (char *) cli_out, sizeof(cli_out) / 2, 0);
-                //WARNINGA(&quot;sent %d of zeros to keep the Skype client socket busy\n&quot;, SKYPIAX_P_LOG, sizeof(cli_out) + sizeof(cli_out)/2);
-        } else {
-                /*
-                   XXX do nothing 
-                 */
-                //WARNINGA(&quot;we don't send it\n&quot;, SKYPIAX_P_LOG);
-        }
-            skypiax_sleep(1000);
</del><ins>+        DEBUGA_SKYPE(&quot;Skype outbound audio GONE\n&quot;, SKYPIAX_P_LOG);
+        skypiax_close_socket(fd);
+        break;
</ins><span class="cx">       }
</span><del>-
</del><span class="cx">     }
</span><del>-    DEBUGA_SKYPE(&quot;Skype outbound audio GONE\n&quot;, SKYPIAX_P_LOG);
-    skypiax_close_socket(fd);
-    break;
</del><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">   DEBUGA_SKYPE(&quot;outbound audio server (I am it) EXITING\n&quot;, SKYPIAX_P_LOG);
</span><span class="lines">@@ -783,10 +819,10 @@
</span><span class="cx"> 
</span><span class="cx">   skypiax_sleep(5000);
</span><span class="cx">   DEBUGA_SKYPE(&quot;Calling Skype, rdest is: %s\n&quot;, SKYPIAX_P_LOG, rdest);
</span><del>-  skypiax_signaling_write(tech_pvt, &quot;SET AGC OFF&quot;);
-  skypiax_sleep(10000);
-  skypiax_signaling_write(tech_pvt, &quot;SET AEC OFF&quot;);
-  skypiax_sleep(10000);
</del><ins>+  //skypiax_signaling_write(tech_pvt, &quot;SET AGC OFF&quot;);
+  //skypiax_sleep(10000);
+  //skypiax_signaling_write(tech_pvt, &quot;SET AEC OFF&quot;);
+  //skypiax_sleep(10000);
</ins><span class="cx"> 
</span><span class="cx">   sprintf(msg_to_skype, &quot;CALL %s&quot;, rdest);
</span><span class="cx">   if (skypiax_signaling_write(tech_pvt, msg_to_skype) &lt; 0) {
</span><span class="lines">@@ -1022,8 +1058,8 @@
</span><span class="cx"> #if 0
</span><span class="cx">           if (!tech_pvt-&gt;SkypiaxHandles.currentuserhandle) {
</span><span class="cx">             SendMessage(HWND_BROADCAST,
</span><del>-                        tech_pvt-&gt;
-                        SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIDiscover,
</del><ins>+                        tech_pvt-&gt;SkypiaxHandles.
+                        win32_uiGlobal_MsgID_SkypeControlAPIDiscover,
</ins><span class="cx">                         (WPARAM) tech_pvt-&gt;SkypiaxHandles.win32_hInit_MainWindowHandle,
</span><span class="cx">                         0);
</span><span class="cx">           }
</span><span class="lines">@@ -1041,8 +1077,8 @@
</span><span class="cx"> #if 0
</span><span class="cx">           if (!tech_pvt-&gt;SkypiaxHandles.currentuserhandle) {
</span><span class="cx">             SendMessage(HWND_BROADCAST,
</span><del>-                        tech_pvt-&gt;
-                        SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIDiscover,
</del><ins>+                        tech_pvt-&gt;SkypiaxHandles.
+                        win32_uiGlobal_MsgID_SkypeControlAPIDiscover,
</ins><span class="cx">                         (WPARAM) tech_pvt-&gt;SkypiaxHandles.win32_hInit_MainWindowHandle,
</span><span class="cx">                         0);
</span><span class="cx">           }
</span><span class="lines">@@ -1155,7 +1191,7 @@
</span><span class="cx">   tech_pvt-&gt;SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIDiscover =
</span><span class="cx">     RegisterWindowMessage(&quot;SkypeControlAPIDiscover&quot;);
</span><span class="cx"> 
</span><del>-  skypiax_sleep(200000); //0,2 sec
</del><ins>+  skypiax_sleep(200000);        //0,2 sec
</ins><span class="cx"> 
</span><span class="cx">   if (tech_pvt-&gt;SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIAttach != 0
</span><span class="cx">       &amp;&amp; tech_pvt-&gt;SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIDiscover != 0) {
</span><span class="lines">@@ -1410,7 +1446,7 @@
</span><span class="cx">     char buffer[17000];
</span><span class="cx">     char *b;
</span><span class="cx">     int i;
</span><del>-    int continue_is_broken=0;
</del><ins>+    int continue_is_broken = 0;
</ins><span class="cx">     Atom atom_begin = XInternAtom(disp, &quot;SKYPECONTROLAPI_MESSAGE_BEGIN&quot;, False);
</span><span class="cx">     Atom atom_continue = XInternAtom(disp, &quot;SKYPECONTROLAPI_MESSAGE&quot;, False);
</span><span class="cx"> 
</span><span class="lines">@@ -1431,43 +1467,47 @@
</span><span class="cx"> 
</span><span class="cx">         buf[i] = '\0';
</span><span class="cx"> 
</span><del>-        DEBUGA_SKYPE (&quot;BUF=|||%s|||\n&quot;, SKYPIAX_P_LOG, buf);
</del><ins>+        //DEBUGA_SKYPE (&quot;BUF=|||%s|||\n&quot;, SKYPIAX_P_LOG, buf);
</ins><span class="cx"> 
</span><del>-        if(an_event.xclient.message_type == atom_begin){
</del><ins>+        if (an_event.xclient.message_type == atom_begin) {
</ins><span class="cx"> 
</span><del>-                if(strlen(buffer)){
-                        unsigned int howmany;
-                        howmany = strlen(b) + 1;
-                        howmany = write(SkypiaxHandles-&gt;fdesc[1], b, howmany);
-                        DEBUGA_SKYPE (&quot;RECEIVED2=|||%s|||\n&quot;, SKYPIAX_P_LOG, buffer);
-                        memset(buffer, '\0', 17000);
-                }
-        }
-        if(an_event.xclient.message_type == atom_continue){
</del><ins>+          if (strlen(buffer)) {
+            unsigned int howmany;
+            howmany = strlen(b) + 1;
+            howmany = write(SkypiaxHandles-&gt;fdesc[1], b, howmany);
+            DEBUGA_SKYPE(&quot;RECEIVED2=|||%s|||\n&quot;, SKYPIAX_P_LOG, buffer);
+            memset(buffer, '\0', 17000);
+          }
+        }
+        if (an_event.xclient.message_type == atom_continue) {
</ins><span class="cx"> 
</span><del>-                if(!strlen(buffer)){
-                        DEBUGA_SKYPE(&quot;Got a 'continue' XAtom without a previous 'begin'. It's value (between vertical bars) is=|||%s|||\n&quot;, SKYPIAX_P_LOG, buf);
-                        continue_is_broken=1;
-                        if(!strncmp(buf, &quot;ognised identity&quot;, 15)) {
-                                WARNINGA(&quot;Got a 'continue' XAtom without a previous 'begin'. It's value (between vertical bars) is=|||%s|||. Let's introduce a 1 second delay.\n&quot;, SKYPIAX_P_LOG, buf);
-                                skypiax_sleep(1000000); //1 sec
-                        }
-                        break;
-                }
-        }
-        
</del><ins>+          if (!strlen(buffer)) {
+            DEBUGA_SKYPE
+              (&quot;Got a 'continue' XAtom without a previous 'begin'. It's value (between vertical bars) is=|||%s|||\n&quot;,
+               SKYPIAX_P_LOG, buf);
+            continue_is_broken = 1;
+            if (!strncmp(buf, &quot;ognised identity&quot;, 15)) {
+              WARNINGA
+                (&quot;Got a 'continue' XAtom without a previous 'begin'. It's value (between vertical bars) is=|||%s|||. Let's introduce a 1 second delay.\n&quot;,
+                 SKYPIAX_P_LOG, buf);
+              skypiax_sleep(1000000);   //1 sec
+            }
+            break;
+          }
+        }
+
</ins><span class="cx">         strcat(buffer, buf);
</span><span class="cx"> 
</span><del>-        if (i &lt; 20 || continue_is_broken) {           /* last fragment */
</del><ins>+        if (i &lt; 20 || continue_is_broken) { /* last fragment */
</ins><span class="cx">           unsigned int howmany;
</span><span class="cx"> 
</span><span class="cx">           howmany = strlen(b) + 1;
</span><span class="cx"> 
</span><span class="cx">           howmany = write(SkypiaxHandles-&gt;fdesc[1], b, howmany);
</span><del>-          DEBUGA_SKYPE (&quot;RECEIVED=|||%s|||\n&quot;, SKYPIAX_P_LOG, buffer);
</del><ins>+          //DEBUGA_SKYPE (&quot;RECEIVED=|||%s|||\n&quot;, SKYPIAX_P_LOG, buffer);
</ins><span class="cx">           memset(buffer, '\0', 17000);
</span><span class="cx">           XFlush(disp);
</span><del>-          continue_is_broken=0;
</del><ins>+          continue_is_broken = 0;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         break;
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>