[Freeswitch-svn] [commit] r11041 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax

FreeSWITCH SVN gmaruzz at freeswitch.org
Thu Jan 1 04:10:04 PST 2009


Author: gmaruzz
Date: Thu Jan  1 07:10:03 2009
New Revision: 11041

Log:
skypiax: let's switch_channel_mark_answered the channel when it's actually answered, and *NOT* after having been pre_answered. Also, indent all

Modified:
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c	Thu Jan  1 07:10:03 2009
@@ -393,15 +393,15 @@
 
   sent = frame->datalen;
   //DEBUGA_SKYPE("CLI PIPE to write %d\n", SKYPIAX_P_LOG, sent);
-#ifdef WIN32 
+#ifdef WIN32
   switch_file_write(p->audioskypepipe[1], frame->data, &sent);
 #else /* WIN32 */
   sent = write(p->audioskypepipe[1], frame->data, sent);
 #endif /* WIN32 */
-  if(sent != frame->datalen){
-	ERRORA("CLI PIPE write %d\n", SKYPIAX_P_LOG, sent);
-  }else{
-	//NOTICA("CLI PIPE write %d\n", SKYPIAX_P_LOG, sent);
+  if (sent != frame->datalen && sent != -1) {
+    DEBUGA_SKYPE("CLI PIPE write %d\n", SKYPIAX_P_LOG, sent);
+  } else {
+    //NOTICA("CLI PIPE write %d\n", SKYPIAX_P_LOG, sent);
   }
 
   return SWITCH_STATUS_SUCCESS;
@@ -511,8 +511,8 @@
     switch_core_session_add_stream(*new_session, NULL);
     if ((tech_pvt =
          (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) {
-      tech_pvt->p = &globals.SKYPIAX_INTERFACES[19]; //FIXME
-      globals.SKYPIAX_INTERFACES[19].tech_pvt = tech_pvt; //FIXME
+      tech_pvt->p = &globals.SKYPIAX_INTERFACES[19];    //FIXME
+      globals.SKYPIAX_INTERFACES[19].tech_pvt = tech_pvt;   //FIXME
       channel = switch_core_session_get_channel(*new_session);
       skypiax_tech_init(tech_pvt, *new_session, NULL);
     } else {
@@ -542,7 +542,7 @@
     switch_channel_set_flag(channel, CF_OUTBOUND);
     switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
     switch_channel_set_state(channel, CS_INIT);
-                switch_channel_mark_pre_answered(channel);
+    //switch_channel_mark_pre_answered(channel);
     return SWITCH_CAUSE_SUCCESS;
   }
 
@@ -590,20 +590,20 @@
           if (channel) {
             switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
             //DEBUGA_SKYPE("after channel_on_hangup\n", SKYPIAX_P_LOG);
-          
-      } else {
-      ERRORA("no channel?\n", SKYPIAX_P_LOG);
-      }
+
+          } else {
+            ERRORA("no channel?\n", SKYPIAX_P_LOG);
+          }
+
+        } else {
+          ERRORA("no session?\n", SKYPIAX_P_LOG);
+        }
 
       } else {
-      ERRORA("no session?\n", SKYPIAX_P_LOG);
-      }
-        
-      } else {
-      ERRORA("no tech_pvt?\n", SKYPIAX_P_LOG);
+        ERRORA("no tech_pvt?\n", SKYPIAX_P_LOG);
       }
-    p->interface_state = SKYPIAX_STATE_DOWN;
-    global_session = NULL;    //FIXME
+      p->interface_state = SKYPIAX_STATE_DOWN;
+      global_session = NULL;    //FIXME
     }
   }
 
@@ -802,14 +802,13 @@
       if (name) {
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "name=%s\n", name);
       }
-
 #ifndef WIN32
-  if (!XInitThreads()) {
-    ERRORA("Not initialized XInitThreads!\n", SKYPIAX_P_LOG);
-  } else {
-    DEBUGA_SKYPE("Initialized XInitThreads!\n", SKYPIAX_P_LOG);
-  }
-  switch_sleep(100);
+      if (!XInitThreads()) {
+        ERRORA("Not initialized XInitThreads!\n", SKYPIAX_P_LOG);
+      } else {
+        DEBUGA_SKYPE("Initialized XInitThreads!\n", SKYPIAX_P_LOG);
+      }
+      switch_sleep(100);
 #endif /* WIN32 */
 
       if (interface_id && interface_id < SKYPIAX_MAX_INTERFACES) {
@@ -828,36 +827,45 @@
           switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].name, "N/A");
         }
 #ifdef WIN32
-		globals.SKYPIAX_INTERFACES[interface_id].tcp_cli_port = (unsigned short)atoi(tcp_cli_port);
-		globals.SKYPIAX_INTERFACES[interface_id].tcp_srv_port = (unsigned short)atoi(tcp_srv_port);
+        globals.SKYPIAX_INTERFACES[interface_id].tcp_cli_port =
+          (unsigned short) atoi(tcp_cli_port);
+        globals.SKYPIAX_INTERFACES[interface_id].tcp_srv_port =
+          (unsigned short) atoi(tcp_srv_port);
 #else /* WIN32 */
-		globals.SKYPIAX_INTERFACES[interface_id].tcp_cli_port = atoi(tcp_cli_port);
-		globals.SKYPIAX_INTERFACES[interface_id].tcp_srv_port = atoi(tcp_srv_port);
+        globals.SKYPIAX_INTERFACES[interface_id].tcp_cli_port = atoi(tcp_cli_port);
+        globals.SKYPIAX_INTERFACES[interface_id].tcp_srv_port = atoi(tcp_srv_port);
 #endif /* WIN32 */
         //switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].tcp_cli_port, tcp_cli_port);
         //switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].tcp_srv_port, tcp_srv_port);
-        switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].X11_display, X11_display);
-        switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].skype_user, skype_user);
-        switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].skype_password, skype_password);
+        switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].X11_display,
+                          X11_display);
+        switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].skype_user,
+                          skype_user);
+        switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].skype_password,
+                          skype_password);
         switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].context, context);
         switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].dialplan, dialplan);
 
-
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
                           "interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].X11_display=%s\n",
-                          interface_id, globals.SKYPIAX_INTERFACES[interface_id].X11_display);
+                          interface_id,
+                          globals.SKYPIAX_INTERFACES[interface_id].X11_display);
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
                           "interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].skype_user=%s\n",
-                          interface_id, globals.SKYPIAX_INTERFACES[interface_id].skype_user);
+                          interface_id,
+                          globals.SKYPIAX_INTERFACES[interface_id].skype_user);
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
                           "interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].skype_password=%s\n",
-                          interface_id, globals.SKYPIAX_INTERFACES[interface_id].skype_password);
+                          interface_id,
+                          globals.SKYPIAX_INTERFACES[interface_id].skype_password);
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
                           "interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].tcp_cli_port=%d\n",
-                          interface_id, globals.SKYPIAX_INTERFACES[interface_id].tcp_cli_port);
+                          interface_id,
+                          globals.SKYPIAX_INTERFACES[interface_id].tcp_cli_port);
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
                           "interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].tcp_srv_port=%d\n",
-                          interface_id, globals.SKYPIAX_INTERFACES[interface_id].tcp_srv_port);
+                          interface_id,
+                          globals.SKYPIAX_INTERFACES[interface_id].tcp_srv_port);
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
                           "interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].name=%s\n",
                           interface_id, globals.SKYPIAX_INTERFACES[interface_id].name);
@@ -866,15 +874,18 @@
                           interface_id, globals.SKYPIAX_INTERFACES[interface_id].context);
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
                           "interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].dialplan=%s\n",
-                          interface_id, globals.SKYPIAX_INTERFACES[interface_id].dialplan);
+                          interface_id,
+                          globals.SKYPIAX_INTERFACES[interface_id].dialplan);
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
                           "STARTING interface_id=%d\n", interface_id);
 
         switch_threadattr_create(&do_skype_thd_attr, skypiax_module_pool);
         //switch_threadattr_detach_set(do_skype_thd_attr, 1);
         switch_threadattr_stacksize_set(do_skype_thd_attr, SWITCH_THREAD_STACKSIZE);
-        switch_thread_create(&globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_skype_thread_thread, do_skype_thd_attr, do_skype_thread,
-                             &globals.SKYPIAX_INTERFACES[interface_id], skypiax_module_pool);
+        switch_thread_create(&globals.SKYPIAX_INTERFACES[interface_id].
+                             skypiax_do_skype_thread_thread, do_skype_thd_attr,
+                             do_skype_thread, &globals.SKYPIAX_INTERFACES[interface_id],
+                             skypiax_module_pool);
 
         switch_sleep(100000);
 
@@ -883,10 +894,12 @@
         //switch_threadattr_detach_set(skypiax_do_controldev_thread_thd_attr, 1);
         switch_threadattr_stacksize_set(skypiax_do_controldev_thread_thd_attr,
                                         SWITCH_THREAD_STACKSIZE);
-        switch_thread_create(&globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_controldev_thread_thread,
+        switch_thread_create(&globals.SKYPIAX_INTERFACES[interface_id].
+                             skypiax_do_controldev_thread_thread,
                              skypiax_do_controldev_thread_thd_attr,
                              skypiax_do_controldev_thread,
-                             &globals.SKYPIAX_INTERFACES[interface_id], skypiax_module_pool);
+                             &globals.SKYPIAX_INTERFACES[interface_id],
+                             skypiax_module_pool);
 
         switch_sleep(1000000);
 
@@ -932,7 +945,7 @@
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_skypiax_load)
 {
-  struct skypiax_interface *p = NULL; //for logging
+  struct skypiax_interface *p = NULL;   //for logging
 
   skypiax_module_pool = pool;
 
@@ -966,58 +979,61 @@
   struct skypiax_interface *p = NULL;
   switch_status_t status;
   unsigned int howmany = 8;
-int interface_id;
+  int interface_id;
 
   //p = &globals.SKYPIAX_INTERFACES[2];
 
   running = 0;
 
-for(interface_id=0; interface_id < SKYPIAX_MAX_INTERFACES; interface_id++){
-  p = &globals.SKYPIAX_INTERFACES[interface_id];
+  for (interface_id = 0; interface_id < SKYPIAX_MAX_INTERFACES; interface_id++) {
+    p = &globals.SKYPIAX_INTERFACES[interface_id];
 
-if(globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_controldev_thread_thread){
+    if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_controldev_thread_thread) {
 #ifdef WIN32
-  switch_file_write(p->AsteriskHandlesAst.fdesc[1], "sciutati", &howmany);  // let's the controldev_thread die
+      switch_file_write(p->AsteriskHandlesAst.fdesc[1], "sciutati", &howmany);  // let's the controldev_thread die
 #else /* WIN32 */
-          write(p->AsteriskHandlesAst.fdesc[1], "sciutati", howmany);
+      write(p->AsteriskHandlesAst.fdesc[1], "sciutati", howmany);
 #endif /* WIN32 */
-  }
+    }
 
-if(globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_skype_thread_thread){
+    if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_skype_thread_thread) {
 #ifdef WIN32
-  if (SendMessage(p->AsteriskHandlesAst.win32_hInit_MainWindowHandle, WM_DESTROY, 0, 0) == FALSE) {   // let's the do_skype_thread die
-    ERRORA("WHY FALSE HERE? %d\n", SKYPIAX_P_LOG, GetLastError());
-  }
+      if (SendMessage(p->AsteriskHandlesAst.win32_hInit_MainWindowHandle, WM_DESTROY, 0, 0) == FALSE) { // let's the do_skype_thread die
+        ERRORA("WHY FALSE HERE? %d\n", SKYPIAX_P_LOG, GetLastError());
+      }
 #else
-  XEvent e;
-  Atom atom1 =
-    XInternAtom(p->AsteriskHandlesAst.disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False);
-  memset(&e, 0, sizeof(e));
-  e.xclient.type = ClientMessage;
-  e.xclient.message_type = atom1;   /*  leading message */
-  e.xclient.display = p->AsteriskHandlesAst.disp;
-  e.xclient.window = p->AsteriskHandlesAst.skype_win;
-  e.xclient.format = 8;
+      XEvent e;
+      Atom atom1 =
+        XInternAtom(p->AsteriskHandlesAst.disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False);
+      memset(&e, 0, sizeof(e));
+      e.xclient.type = ClientMessage;
+      e.xclient.message_type = atom1;   /*  leading message */
+      e.xclient.display = p->AsteriskHandlesAst.disp;
+      e.xclient.window = p->AsteriskHandlesAst.skype_win;
+      e.xclient.format = 8;
 
-  XSendEvent(p->AsteriskHandlesAst.disp, p->AsteriskHandlesAst.win, False, 0, &e);
-  XSync(p->AsteriskHandlesAst.disp, False);
+      XSendEvent(p->AsteriskHandlesAst.disp, p->AsteriskHandlesAst.win, False, 0, &e);
+      XSync(p->AsteriskHandlesAst.disp, False);
 #endif
-  }
-  while (x) {
-    x--;
-    switch_yield(20000);
-  }
-if(globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_controldev_thread_thread){
-  switch_thread_join(&status, globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_controldev_thread_thread);
-  }
-if(globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_skype_thread_thread){
-  switch_thread_join(&status, globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_skype_thread_thread);
-  }
+    }
+    while (x) {
+      x--;
+      switch_yield(20000);
+    }
+    if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_controldev_thread_thread) {
+      switch_thread_join(&status,
+                         globals.SKYPIAX_INTERFACES[interface_id].
+                         skypiax_do_controldev_thread_thread);
+    }
+    if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_skype_thread_thread) {
+      switch_thread_join(&status,
+                         globals.SKYPIAX_INTERFACES[interface_id].
+                         skypiax_do_skype_thread_thread);
+    }
   }
   return SWITCH_STATUS_SUCCESS;
 }
 
-
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h	Thu Jan  1 07:10:03 2009
@@ -136,7 +136,7 @@
   Window skype_win;
   Display *disp;
   Window win;
-int api_connected;
+  int api_connected;
   int fdesc[2];
 };
 #else //WIN32
@@ -144,11 +144,11 @@
 struct AsteriskHandles {
   HWND win32_hInit_MainWindowHandle;
   HWND win32_hGlobal_SkypeAPIWindowHandle;
-HINSTANCE win32_hInit_ProcessHandle;
-char win32_acInit_WindowClassName[128];
-UINT win32_uiGlobal_MsgID_SkypeControlAPIAttach;
-UINT win32_uiGlobal_MsgID_SkypeControlAPIDiscover;
-int api_connected;
+  HINSTANCE win32_hInit_ProcessHandle;
+  char win32_acInit_WindowClassName[128];
+  UINT win32_uiGlobal_MsgID_SkypeControlAPIAttach;
+  UINT win32_uiGlobal_MsgID_SkypeControlAPIDiscover;
+  int api_connected;
   switch_file_t *fdesc[2];
 };
 
@@ -195,10 +195,10 @@
 #ifdef WIN32
   switch_file_t *audiopipe[2];
   switch_file_t *audioskypepipe[2];
-#else /* WIN32 */
+#else                           /* WIN32 */
   int audiopipe[2];
   int audioskypepipe[2];
-#endif /* WIN32 */
+#endif                          /* WIN32 */
   switch_thread_t *tcp_srv_thread;
   switch_thread_t *tcp_cli_thread;
   switch_thread_t *skypiax_do_controldev_thread_thread;
@@ -247,4 +247,5 @@
 int skypiax_skype_write(struct skypiax_interface *p, char *msg_to_skype);
 int skypiax_skype_read(struct skypiax_interface *p);
 
-int skypiax_skype_call(struct skypiax_interface *p, char *idest, int timeout, switch_core_session_t * session);
+int skypiax_skype_call(struct skypiax_interface *p, char *idest, int timeout,
+                       switch_core_session_t * session);

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	Thu Jan  1 07:10:03 2009
@@ -6,23 +6,17 @@
 extern switch_endpoint_interface_t *skypiax_endpoint_interface;
 extern int running;
 
-
-
 /**********************************************************/
 /**********************************************************/
 /**********************************************************/
 
-
 extern switch_core_session_t *global_session;
 
-
 #ifdef WIN32
 #else /* NOT WIN32 */
 #define SKYPE_X11_BUF_SIZE 512
 #endif /* WIN32 */
 
-
-
 /**********************************************************/
 /**********************************************************/
 /**********************************************************/
@@ -57,27 +51,26 @@
   short totalbuf[SAMPLES_PER_FRAME];
   //int one = 1;
 
-  if (option_debug > 10) {
-    WARNINGA("ENTERING FUNC\n", SKYPIAX_P_LOG);
+  if (option_debug > 100) {
+    DEBUGA_SKYPE("ENTERING FUNC\n", SKYPIAX_P_LOG);
   }
   memset(&my_addr, 0, sizeof(my_addr));
   my_addr.sin_family = AF_INET;
   my_addr.sin_addr.s_addr = htonl(0x7f000001);  /* use the localhost */
-  my_addr.sin_port = htons(p->tcp_srv_port);   
+  my_addr.sin_port = htons(p->tcp_srv_port);
 
   if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
     ERRORA("socket Error\n", SKYPIAX_P_LOG);
-    if (option_debug > 10) {
+    if (option_debug > 100) {
       DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
     }
     return NULL;
   }
-
   //setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
 
   if (bind(s, (struct sockaddr *) &my_addr, sizeof(struct sockaddr)) < 0) {
     ERRORA("bind Error\n", SKYPIAX_P_LOG);
-    if (option_debug > 10) {
+    if (option_debug > 100) {
       DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
     }
     return NULL;
@@ -111,152 +104,147 @@
       fdselect = fd;
       FD_ZERO(&fs);
       FD_SET(fdselect, &fs);
-      to.tv_usec = 2000000; //20 msec
+      to.tv_usec = 2000000;     //20 msec
       to.tv_sec = 0;
 
       rt = select(fdselect + 1, &fs, NULL, NULL, &to);
-	  //rt=0;
+      //rt=0;
       if (rt > 0) {
 
 #ifdef WIN32
-	      len = recv(fd, (char *)srv_in, 320, 0); //seems that Skype only sends 320 bytes at time
+        len = recv(fd, (char *) srv_in, 320, 0);    //seems that Skype only sends 320 bytes at time
 #else /* WIN32 */
-	      len = recv(fd, (char *)srv_in, 320, 0); //seems that Skype only sends 320 bytes at time
+        len = recv(fd, (char *) srv_in, 320, 0);    //seems that Skype only sends 320 bytes at time
 #endif /* WIN32 */
 
-		  if ((SAMPLERATE_SKYPIAX - 8000) == 0) {
+        if ((SAMPLERATE_SKYPIAX - 8000) == 0) {
 
-		      /****************************************************************/
-		      if (len > 0) {
-			      a = 0;
-			      for (i = 0; i < len / sizeof(short); i++) {
-				      srv_out[a] = srv_in[i];
-				      i++;
-				      a++;
-			      }
-
-			      if (!p->audiobuf_is_loaded) {
-				      for (i = 0; i < (len / sizeof(short)) / 2; i++) {
-					      p->audiobuf[i] = srv_out[i];
-				      }
-				      p->audiobuf_is_loaded = 1;
-			      } else {
-				      unsigned int howmany;
-
-				      howmany = len / 2 / 2;
-				      for (i = 0; i < howmany; i++)
-					      totalbuf[i] = p->audiobuf[i];
-
-				      howmany = len / 2 / 2;
-				      for (a = 0; a < howmany; a++) {
-					      totalbuf[i] = srv_out[a];
-					      i++;
-				      }
+              /****************************************************************/
+          if (len > 0) {
+            a = 0;
+            for (i = 0; i < len / sizeof(short); i++) {
+              srv_out[a] = srv_in[i];
+              i++;
+              a++;
+            }
 
-				      howmany = len;
+            if (!p->audiobuf_is_loaded) {
+              for (i = 0; i < (len / sizeof(short)) / 2; i++) {
+                p->audiobuf[i] = srv_out[i];
+              }
+              p->audiobuf_is_loaded = 1;
+            } else {
+              unsigned int howmany;
 
-#ifdef WIN32 
-				      switch_file_write(p->audiopipe[1], totalbuf, &howmany);
-#else /* WIN32 */
-				      howmany = write(p->audiopipe[1], totalbuf, howmany);
-#endif /* WIN32 */
-				      p->audiobuf_is_loaded = 0;
-				      //DEBUGA_SKYPE("read=====> req=%d recv=%d to sent=%d sent=%d\n", SKYPIAX_P_LOG, sizeof(short)*SAMPLES_PER_FRAME, len, (len*sizeof(short))/2, howmany);
-			      }
-
-		      } else if (len == 0) {
-			      DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG);
-				  switch_sleep(1000);
-		      } else {
-			      ERRORA("len=%d\n", SKYPIAX_P_LOG, len);
-			      exit = 1;
-			      break;
-		      }
-		      /****************************************************************/
-	      } else if (SAMPLERATE_SKYPIAX == 16000) {
-
-
-		      /****************************************************************/
-		      if (len > 0) {
-			      if (len == SAMPLES_PER_FRAME * sizeof(short)) {
-				      unsigned int howmany;
-				      howmany = len;
+              howmany = len / 2 / 2;
+              for (i = 0; i < howmany; i++)
+                totalbuf[i] = p->audiobuf[i];
+
+              howmany = len / 2 / 2;
+              for (a = 0; a < howmany; a++) {
+                totalbuf[i] = srv_out[a];
+                i++;
+              }
 
-						WARNINGA("SRV recv %d\n", SKYPIAX_P_LOG, len);
+              howmany = len;
 
-#ifdef WIN32 
-				      switch_file_write(p->audiopipe[1], srv_in, &howmany);
+#ifdef WIN32
+              switch_file_write(p->audiopipe[1], totalbuf, &howmany);
 #else /* WIN32 */
-				      howmany = write(p->audiopipe[1], srv_in, howmany);
+              howmany = write(p->audiopipe[1], totalbuf, howmany);
 #endif /* WIN32 */
-				      p->audiobuf_is_loaded = 0;
-				      WARNINGA("SRV PIPE WRITE=====> req=%lu recv=%d to sent=%d sent=%u\n", SKYPIAX_P_LOG, sizeof(short)*SAMPLES_PER_FRAME, len, len, howmany);
-			      }else if (len == SAMPLES_PER_FRAME * sizeof(short) / 2) {
+              p->audiobuf_is_loaded = 0;
+              //DEBUGA_SKYPE("read=====> req=%d recv=%d to sent=%d sent=%d\n", SKYPIAX_P_LOG, sizeof(short)*SAMPLES_PER_FRAME, len, (len*sizeof(short))/2, howmany);
+            }
 
-#if 1
+          } else if (len == 0) {
+            DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG);
+            switch_sleep(1000);
+          } else {
+            ERRORA("len=%d\n", SKYPIAX_P_LOG, len);
+            exit = 1;
+            break;
+          }
+              /****************************************************************/
+        } else if (SAMPLERATE_SKYPIAX == 16000) {
 
+              /****************************************************************/
+          if (len > 0) {
+            if (len == SAMPLES_PER_FRAME * sizeof(short)) {
+              unsigned int howmany;
+              howmany = len;
 
-				      if (!p->audiobuf_is_loaded) {
-					      for (i = 0; i < (len / sizeof(short)); i++) {
-						      p->audiobuf[i] = srv_in[i];
-					      }
-					      p->audiobuf_is_loaded = 1;
-				      } else {
-					      unsigned int howmany = SAMPLES_PER_FRAME * sizeof(short);
-					      //short totalbuf[SAMPLES_PER_FRAME];
-
-					      for (i = 0; i < (len / sizeof(short)); i++)
-						      totalbuf[i] = p->audiobuf[i];
-					      for (a = 0; a < (len / sizeof(short)); a++) {
-						      totalbuf[i] = srv_in[a];
-						      i++;
-					      }
+              WARNINGA("SRV recv %d\n", SKYPIAX_P_LOG, len);
 
-#ifdef WIN32 
-					      switch_file_write(p->audiopipe[1], totalbuf, &howmany);
+#ifdef WIN32
+              switch_file_write(p->audiopipe[1], srv_in, &howmany);
 #else /* WIN32 */
-					      howmany = write(p->audiopipe[1], totalbuf, howmany);
+              howmany = write(p->audiopipe[1], srv_in, howmany);
 #endif /* WIN32 */
-					      p->audiobuf_is_loaded = 0;
-					      //NOTICA("SRV PIPE WRITE=====> req=%d recv=%d to sent=%d sent=%d\n", SKYPIAX_P_LOG, SAMPLES_PER_FRAME * sizeof(short), len, SAMPLES_PER_FRAME * sizeof(short), howmany);
-				      }
-#endif
-
+              p->audiobuf_is_loaded = 0;
+              WARNINGA("SRV PIPE WRITE=====> req=%lu recv=%d to sent=%d sent=%u\n",
+                       SKYPIAX_P_LOG, sizeof(short) * SAMPLES_PER_FRAME, len, len,
+                       howmany);
+            } else if (len == SAMPLES_PER_FRAME * sizeof(short) / 2) {
 
+#if 1
 
+              if (!p->audiobuf_is_loaded) {
+                for (i = 0; i < (len / sizeof(short)); i++) {
+                  p->audiobuf[i] = srv_in[i];
+                }
+                p->audiobuf_is_loaded = 1;
+              } else {
+                unsigned int howmany = SAMPLES_PER_FRAME * sizeof(short);
+                //short totalbuf[SAMPLES_PER_FRAME];
 
-			      } else {
+                for (i = 0; i < (len / sizeof(short)); i++)
+                  totalbuf[i] = p->audiobuf[i];
+                for (a = 0; a < (len / sizeof(short)); a++) {
+                  totalbuf[i] = srv_in[a];
+                  i++;
+                }
 
-			      ERRORA("SRV len=%d\n", SKYPIAX_P_LOG, len);
+#ifdef WIN32
+                switch_file_write(p->audiopipe[1], totalbuf, &howmany);
+#else /* WIN32 */
+                howmany = write(p->audiopipe[1], totalbuf, howmany);
+#endif /* WIN32 */
+                p->audiobuf_is_loaded = 0;
+                //NOTICA("SRV PIPE WRITE=====> req=%d recv=%d to sent=%d sent=%d\n", SKYPIAX_P_LOG, SAMPLES_PER_FRAME * sizeof(short), len, SAMPLES_PER_FRAME * sizeof(short), howmany);
+              }
+#endif
 
-				}
+            } else {
 
-		      } else if (len == 0) {
-			      DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG);
-				  switch_sleep(1000);
-			      //break;
-		      } else {
-			      ERRORA("SRV len=%d\n", SKYPIAX_P_LOG, len);
-			      exit = 1;
-			      break;
-		      }
-		      /****************************************************************/
+              ERRORA("SRV len=%d\n", SKYPIAX_P_LOG, len);
 
+            }
 
+          } else if (len == 0) {
+            DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG);
+            switch_sleep(1000);
+            //break;
+          } else {
+            ERRORA("SRV len=%d\n", SKYPIAX_P_LOG, len);
+            exit = 1;
+            break;
+          }
+              /****************************************************************/
 
-	      } else {
+        } else {
 
-		      ERRORA("SAMPLERATE_SKYPIAX can only be 8000 or 16000\n", SKYPIAX_P_LOG);
-	      }
+          ERRORA("SAMPLERATE_SKYPIAX can only be 8000 or 16000\n", SKYPIAX_P_LOG);
+        }
       } else {
 
-		  if(rt)
-			ERRORA("SRV rt=%d\n", SKYPIAX_P_LOG, rt);
-		  switch_sleep(10000);
-	  }
+        if (rt)
+          ERRORA("SRV rt=%d\n", SKYPIAX_P_LOG, rt);
+        switch_sleep(10000);
+      }
     }
 
-#ifdef WIN32 
+#ifdef WIN32
     kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
     switch_file_write(p->audiopipe[1], kill_cli_buff, &kill_cli_size);
     kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
@@ -295,7 +283,7 @@
 #else
   closesocket(s);
 #endif
-  if (option_debug > 10) {
+  if (option_debug > 100) {
     DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
   }
   return NULL;
@@ -328,27 +316,26 @@
 #endif /* WIN32 */
   //int one = 1;
 
-  if (option_debug > 10) {
-    WARNINGA("ENTERING FUNC\n", SKYPIAX_P_LOG);
+  if (option_debug > 100) {
+    DEBUGA_SKYPE("ENTERING FUNC\n", SKYPIAX_P_LOG);
   }
   memset(&my_addr, 0, sizeof(my_addr));
   my_addr.sin_family = AF_INET;
   my_addr.sin_addr.s_addr = htonl(0x7f000001);  /* use the localhost */
-  my_addr.sin_port = htons(p->tcp_cli_port);   //FIXME configurable!
+  my_addr.sin_port = htons(p->tcp_cli_port);    //FIXME configurable!
 
   if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
     ERRORA("socket Error\n", SKYPIAX_P_LOG);
-    if (option_debug > 10) {
+    if (option_debug > 100) {
       DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
     }
     return NULL;
   }
-
   //setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
 
   if (bind(s, (struct sockaddr *) &my_addr, sizeof(struct sockaddr)) < 0) {
     ERRORA("bind Error\n", SKYPIAX_P_LOG);
-    if (option_debug > 10) {
+    if (option_debug > 100) {
       DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
     }
 #ifndef WIN32
@@ -382,99 +369,99 @@
       if (!running)
         break;
 #ifdef WIN32
-      fdselect = fd; //cannot select on audioskypepipe, let's select on socket write
+      fdselect = fd;            //cannot select on audioskypepipe, let's select on socket write
 #else /* WIN32 */
       fdselect = p->audioskypepipe[0];
 #endif /* WIN32 */
       FD_ZERO(&fs);
       FD_SET(fdselect, &fs);
-      to.tv_usec = 2000000; //20 msec
+      to.tv_usec = 2000000;     //20 msec
       to.tv_sec = 0;
 
 #ifdef WIN32
-      rt = select(fdselect + 1, NULL, &fs, NULL, &to);//cannot select on audioskypepipe, let's select on socket write
+      rt = select(fdselect + 1, NULL, &fs, NULL, &to);  //cannot select on audioskypepipe, let's select on socket write
 #else /* WIN32 */
       rt = select(fdselect + 1, &fs, NULL, NULL, &to);
 #endif /* WIN32 */
-	  //switch_sleep(1000);//FIXME
-	  //memset(cli_in, '\0', sizeof(cli_in));
+      //switch_sleep(1000);//FIXME
+      //memset(cli_in, '\0', sizeof(cli_in));
       //rt = 0;
-	  if (rt > 0) {
-			  /*********************************************/
-		  if ((SAMPLERATE_SKYPIAX - 8000) == 0) {
-			  got = SAMPLES_PER_FRAME * sizeof(short);
-#ifdef WIN32 
-			  switch_file_read(p->audioskypepipe[0], cli_in, &got);
+      if (rt > 0) {
+              /*********************************************/
+        if ((SAMPLERATE_SKYPIAX - 8000) == 0) {
+          got = SAMPLES_PER_FRAME * sizeof(short);
+#ifdef WIN32
+          switch_file_read(p->audioskypepipe[0], cli_in, &got);
 #else /* WIN32 */
-			  got = read(p->audioskypepipe[0], cli_in, got);
+          got = read(p->audioskypepipe[0], cli_in, got);
 #endif /* WIN32 */
 
-			  if (got > 0) {
-				  //DEBUGA_SKYPE("CLI PIPE read %d\n", SKYPIAX_P_LOG, got);
-				  a = 0;
-				  for (i = 0; i < got / sizeof(short); i++) {
-					  cli_out[a] = cli_in[i];
-					  a++;
-					  cli_out[a] = cli_in[i];
-					  a++;
-				  }
+          if (got > 0) {
+            //DEBUGA_SKYPE("CLI PIPE read %d\n", SKYPIAX_P_LOG, got);
+            a = 0;
+            for (i = 0; i < got / sizeof(short); i++) {
+              cli_out[a] = cli_in[i];
+              a++;
+              cli_out[a] = cli_in[i];
+              a++;
+            }
 
 #ifdef WIN32
-				  len = send(fd, (char *)cli_out, got * 2, 0);
+            len = send(fd, (char *) cli_out, got * 2, 0);
 #else /* WIN32 */
-				  len = send(fd, cli_out, got * 2, 0);
+            len = send(fd, cli_out, got * 2, 0);
 #endif /* WIN32 */
-				  //DEBUGA_SKYPE("CLI PIPE send %d\n", SKYPIAX_P_LOG, len);
+            //DEBUGA_SKYPE("CLI PIPE send %d\n", SKYPIAX_P_LOG, len);
 
-				  if (len == 0) {
-					  ERRORA("Skype server GONE\n", SKYPIAX_P_LOG);
-					  break;
-				  }
-			  } else {
-				  switch_sleep(1000);
-				  ERRORA("CLI PIPE give us: %u\n", SKYPIAX_P_LOG, got);
-				  //break;
-			  }
-		  }
-		  /*********************************************/
-			  /*********************************************/
-		  else if (SAMPLERATE_SKYPIAX == 16000) {
-			  got = SAMPLES_PER_FRAME * sizeof(short);
-#ifdef WIN32 
-			  switch_file_read(p->audioskypepipe[0], cli_in, &got);
+            if (len == 0) {
+              ERRORA("Skype server GONE\n", SKYPIAX_P_LOG);
+              break;
+            }
+          } else {
+            switch_sleep(1000);
+            ERRORA("CLI PIPE give us: %u\n", SKYPIAX_P_LOG, got);
+            //break;
+          }
+        }
+          /*********************************************/
+              /*********************************************/
+        else if (SAMPLERATE_SKYPIAX == 16000) {
+          got = SAMPLES_PER_FRAME * sizeof(short);
+#ifdef WIN32
+          switch_file_read(p->audioskypepipe[0], cli_in, &got);
 #else /* WIN32 */
-			  got = read(p->audioskypepipe[0], cli_in, got);
+          got = read(p->audioskypepipe[0], cli_in, got);
 #endif /* WIN32 */
 
-			  if (got > 0) {
-				  if(got != SAMPLES_PER_FRAME * sizeof(short) )
-					ERRORA("CLI PIPE read %d\n", SKYPIAX_P_LOG, got);
+          if (got > 0) {
+            if (got != SAMPLES_PER_FRAME * sizeof(short))
+              ERRORA("CLI PIPE read %d\n", SKYPIAX_P_LOG, got);
 
 #ifdef WIN32
-				  len = send(fd, (char *)cli_in, got, 0);
+            len = send(fd, (char *) cli_in, got, 0);
 #else /* WIN32 */
-				  len = send(fd, cli_in, got, 0);
+            len = send(fd, cli_in, got, 0);
 #endif /* WIN32 */
 
-				  if(len != got )
-					ERRORA("CLI PIPE send %d\n", SKYPIAX_P_LOG, len);
+            if (len != got && len != -1)
+              DEBUGA_SKYPE("CLI PIPE send %d\n", SKYPIAX_P_LOG, len);
 
-				  if (len == 0) {
-					  ERRORA("Skype server GONE\n", SKYPIAX_P_LOG);
-					  break;
-				  }
-			  } else {
-				  switch_sleep(1000);
-				  ERRORA("CLI PIPE give us: %u\n", SKYPIAX_P_LOG, got);
-			  }
-		  }
-		  /*********************************************/
-
-	  } else {
-				  switch_sleep(1000);
-				  if(rt)
-					ERRORA("select give us: %u\n", SKYPIAX_P_LOG, rt);
-			  }
+            if (len == 0) {
+              ERRORA("Skype server GONE\n", SKYPIAX_P_LOG);
+              break;
+            }
+          } else {
+            switch_sleep(1000);
+            ERRORA("CLI PIPE give us: %u\n", SKYPIAX_P_LOG, got);
+          }
+        }
+          /*********************************************/
+
+      } else {
+        switch_sleep(1000);
+        if (rt)
+          ERRORA("select give us: %u\n", SKYPIAX_P_LOG, rt);
+      }
 
     }
     DEBUGA_SKYPE("Skype server GONE\n", SKYPIAX_P_LOG);
@@ -492,7 +479,7 @@
 #else
   closesocket(s);
 #endif
-  if (option_debug > 10) {
+  if (option_debug > 100) {
     DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
   }
   return NULL;
@@ -501,13 +488,12 @@
 int skypiax_skypeaudio_init(struct skypiax_interface *p)
 {
 
-
 #ifdef WIN32
   switch_status_t rv;
+  rv = switch_file_pipe_create(&p->audiopipe[0], &p->audiopipe[1], skypiax_module_pool);
   rv =
-    switch_file_pipe_create(&p->audiopipe[0], &p->audiopipe[1], skypiax_module_pool);
-  rv =
-    switch_file_pipe_create(&p->audioskypepipe[0], &p->audioskypepipe[1], skypiax_module_pool);
+    switch_file_pipe_create(&p->audioskypepipe[0], &p->audioskypepipe[1],
+                            skypiax_module_pool);
 #else /* WIN32 */
   pipe(p->audiopipe);
   fcntl(p->audiopipe[0], F_SETFL, O_NONBLOCK);
@@ -539,7 +525,6 @@
   struct timeval to;
 #endif /* WIN32 */
 
-
   p = tech_pvt->p;
 
   //DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
@@ -551,7 +536,7 @@
   fdselect = p->audiopipe[0];
   FD_ZERO(&fs);
   FD_SET(fdselect, &fs);
-  to.tv_usec = 2000000; //20 msec
+  to.tv_usec = 2000000;         //20 msec
   to.tv_sec = 0;
   rt = select(fdselect + 1, &fs, NULL, NULL, &to);
 #endif /* WIN32 */
@@ -564,14 +549,14 @@
     switch_file_read(p->audiopipe[0], tech_pvt->read_frame.data, &samples);
 #else /* WIN32 */
 
-	//samples = read(p->audiopipe[0], buf, SAMPLES_PER_FRAME * sizeof(short));
+    //samples = read(p->audiopipe[0], buf, SAMPLES_PER_FRAME * sizeof(short));
     samples = read(p->audiopipe[0], tech_pvt->read_frame.data, samples);
 #endif /* WIN32 */
 
     if (samples != SAMPLES_PER_FRAME * sizeof(short)) {
       if (samples)
         ERRORA("SRV PIPE READ=====> NOT GOOD samples=%u expected=%lu\n", SKYPIAX_P_LOG,
-                     samples, SAMPLES_PER_FRAME * sizeof(short));
+               samples, SAMPLES_PER_FRAME * sizeof(short));
       //do nothing
     } else {
       tech_pvt->read_frame.datalen = samples;
@@ -579,8 +564,8 @@
       /* A real frame */
     }
   } else {
-	  if(rt)
-		DEBUGA_SKYPE("select returned %d\n", SKYPIAX_P_LOG, rt);
+    if (rt)
+      DEBUGA_SKYPE("select returned %d\n", SKYPIAX_P_LOG, rt);
 
   }
 
@@ -589,38 +574,32 @@
   return SWITCH_STATUS_SUCCESS;
 }
 
-
 #ifdef WIN32
 int LaunchSkype(struct skypiax_interface *p)
 {
-	LPTSTR pszMessage;
-	DWORD dwLastError; 
-	char skypelogin[256];
-
-	memset(skypelogin, '\0', sizeof(skypelogin));
-	sprintf(skypelogin, "/secondary /username:%s /password:%s", p->skype_user, p->skype_password);
-
-
-	ShellExecute(NULL, "open", "C:\\Program Files\\Skype\\Phone\\Skype.exe", skypelogin, ".", SW_SHOWNORMAL);
-
-	dwLastError = GetLastError();
-
-	FormatMessage(
-			FORMAT_MESSAGE_ALLOCATE_BUFFER | 
-			FORMAT_MESSAGE_FROM_SYSTEM |
-			FORMAT_MESSAGE_IGNORE_INSERTS,
-			NULL,
-			dwLastError,
-			MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-			(LPTSTR)&pszMessage,
-			0, NULL );
-
-	NOTICA("ShellExecute gave: %s\n", SKYPIAX_P_LOG,pszMessage);
-	LocalFree(pszMessage);
-	return 1;
+  LPTSTR pszMessage;
+  DWORD dwLastError;
+  char skypelogin[256];
+
+  memset(skypelogin, '\0', sizeof(skypelogin));
+  sprintf(skypelogin, "/secondary /username:%s /password:%s", p->skype_user,
+          p->skype_password);
+
+  ShellExecute(NULL, "open", "C:\\Program Files\\Skype\\Phone\\Skype.exe", skypelogin,
+               ".", SW_SHOWNORMAL);
+
+  dwLastError = GetLastError();
+
+  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
+                FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwLastError, MAKELANGID(LANG_NEUTRAL,
+                                                                             SUBLANG_DEFAULT),
+                (LPTSTR) & pszMessage, 0, NULL);
 
-}
+  NOTICA("ShellExecute gave: %s\n", SKYPIAX_P_LOG, pszMessage);
+  LocalFree(pszMessage);
+  return 1;
 
+}
 
 enum {
   SKYPECONTROLAPI_ATTACH_SUCCESS = 0,   /*  Client is successfully 
@@ -673,11 +652,11 @@
 
   lReturnCode = 0;
   fIssueDefProc = 0;
-	  p = ( struct skypiax_interface *)GetWindowLong(hWindow, GWL_USERDATA);
+  p = (struct skypiax_interface *) GetWindowLong(hWindow, GWL_USERDATA);
   switch (uiMessage) {
   case WM_CREATE:
-	  p=( struct skypiax_interface *)((LPCREATESTRUCT)ulParam)->lpCreateParams;
-	  SetWindowLong(hWindow, GWL_USERDATA, (LONG)p);
+    p = (struct skypiax_interface *) ((LPCREATESTRUCT) ulParam)->lpCreateParams;
+    SetWindowLong(hWindow, GWL_USERDATA, (LONG) p);
     DEBUGA_SKYPE("got CREATE\n", SKYPIAX_P_LOG);
     break;
   case WM_DESTROY:
@@ -703,50 +682,52 @@
     }
     break;
   default:
-    if(p && p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIAttach) {
-    if (uiMessage == p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIAttach) {
-      switch (ulParam) {
-      case SKYPECONTROLAPI_ATTACH_SUCCESS:
-	if(!p->AsteriskHandlesAst.api_connected){
-        NOTICA("\n\n\tConnected to Skype API!\n", SKYPIAX_P_LOG);
-        p->AsteriskHandlesAst.win32_hGlobal_SkypeAPIWindowHandle = (HWND) uiParam;
-        //switch_sleep(5000);
-        p->AsteriskHandlesAst.win32_hGlobal_SkypeAPIWindowHandle =
-          p->AsteriskHandlesAst.win32_hGlobal_SkypeAPIWindowHandle;
-	}
-        break;
-      case SKYPECONTROLAPI_ATTACH_PENDING_AUTHORIZATION:
-        WARNINGA
-          ("\n\n\tIf I do not (almost) immediately connect to Skype API,\n\tplease give the Skype client authorization to be connected \n\tby Asterisk and to not ask you again.\n\n",
-           SKYPIAX_P_LOG);
-        switch_sleep(5000);
-	if(!p->AsteriskHandlesAst.api_connected){
-        SendMessage
-            (HWND_BROADCAST, p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIDiscover,
-             (WPARAM) p->AsteriskHandlesAst.win32_hInit_MainWindowHandle, 0);
-	}
-        break;
-      case SKYPECONTROLAPI_ATTACH_REFUSED:
-        ERRORA("Skype client refused to be connected by Skypiax!\n", SKYPIAX_P_LOG);
-        break;
-      case SKYPECONTROLAPI_ATTACH_NOT_AVAILABLE:
-        ERRORA("Skype API not (yet?) available\n", SKYPIAX_P_LOG);
-        break;
-      case SKYPECONTROLAPI_ATTACH_API_AVAILABLE:
-        DEBUGA_SKYPE("Skype API available\n", SKYPIAX_P_LOG);
-        switch_sleep(5000);
-	if(!p->AsteriskHandlesAst.api_connected){
-        SendMessage
-            (HWND_BROADCAST, p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIDiscover,
-             (WPARAM) p->AsteriskHandlesAst.win32_hInit_MainWindowHandle, 0);
-	}
+    if (p && p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIAttach) {
+      if (uiMessage == p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIAttach) {
+        switch (ulParam) {
+        case SKYPECONTROLAPI_ATTACH_SUCCESS:
+          if (!p->AsteriskHandlesAst.api_connected) {
+            NOTICA("\n\n\tConnected to Skype API!\n", SKYPIAX_P_LOG);
+            p->AsteriskHandlesAst.win32_hGlobal_SkypeAPIWindowHandle = (HWND) uiParam;
+            //switch_sleep(5000);
+            p->AsteriskHandlesAst.win32_hGlobal_SkypeAPIWindowHandle =
+              p->AsteriskHandlesAst.win32_hGlobal_SkypeAPIWindowHandle;
+          }
+          break;
+        case SKYPECONTROLAPI_ATTACH_PENDING_AUTHORIZATION:
+          WARNINGA
+            ("\n\n\tIf I do not (almost) immediately connect to Skype API,\n\tplease give the Skype client authorization to be connected \n\tby Asterisk and to not ask you again.\n\n",
+             SKYPIAX_P_LOG);
+          switch_sleep(5000);
+          if (!p->AsteriskHandlesAst.api_connected) {
+            SendMessage(HWND_BROADCAST,
+                        p->AsteriskHandlesAst.
+                        win32_uiGlobal_MsgID_SkypeControlAPIDiscover,
+                        (WPARAM) p->AsteriskHandlesAst.win32_hInit_MainWindowHandle, 0);
+          }
+          break;
+        case SKYPECONTROLAPI_ATTACH_REFUSED:
+          ERRORA("Skype client refused to be connected by Skypiax!\n", SKYPIAX_P_LOG);
+          break;
+        case SKYPECONTROLAPI_ATTACH_NOT_AVAILABLE:
+          ERRORA("Skype API not (yet?) available\n", SKYPIAX_P_LOG);
+          break;
+        case SKYPECONTROLAPI_ATTACH_API_AVAILABLE:
+          DEBUGA_SKYPE("Skype API available\n", SKYPIAX_P_LOG);
+          switch_sleep(5000);
+          if (!p->AsteriskHandlesAst.api_connected) {
+            SendMessage(HWND_BROADCAST,
+                        p->AsteriskHandlesAst.
+                        win32_uiGlobal_MsgID_SkypeControlAPIDiscover,
+                        (WPARAM) p->AsteriskHandlesAst.win32_hInit_MainWindowHandle, 0);
+          }
+          break;
+        default:
+          WARNINGA("GOT AN UNKNOWN SKYPE WINDOWS MSG\n", SKYPIAX_P_LOG);
+        }
+        lReturnCode = 1;
         break;
-      default:
-        WARNINGA("GOT AN UNKNOWN SKYPE WINDOWS MSG\n", SKYPIAX_P_LOG);
       }
-      lReturnCode = 1;
-      break;
-    }
     }
     fIssueDefProc = 1;
     break;
@@ -793,20 +774,24 @@
     }
   }
   if (fReturnStatus == 0)
-    CloseHandle(p->AsteriskHandlesAst.win32_hInit_ProcessHandle), p->AsteriskHandlesAst.win32_hInit_ProcessHandle = NULL;
+    CloseHandle(p->AsteriskHandlesAst.win32_hInit_ProcessHandle),
+      p->AsteriskHandlesAst.win32_hInit_ProcessHandle = NULL;
   return (fReturnStatus);
 }
 
 void win32_DeInitialize_DestroyWindowClass(struct skypiax_interface *p)
 {
-  UnregisterClass(p->AsteriskHandlesAst.win32_acInit_WindowClassName, p->AsteriskHandlesAst.win32_hInit_ProcessHandle);
-  CloseHandle(p->AsteriskHandlesAst.win32_hInit_ProcessHandle), p->AsteriskHandlesAst.win32_hInit_ProcessHandle = NULL;
+  UnregisterClass(p->AsteriskHandlesAst.win32_acInit_WindowClassName,
+                  p->AsteriskHandlesAst.win32_hInit_ProcessHandle);
+  CloseHandle(p->AsteriskHandlesAst.win32_hInit_ProcessHandle),
+    p->AsteriskHandlesAst.win32_hInit_ProcessHandle = NULL;
 }
 
 int win32_Initialize_CreateMainWindow(struct skypiax_interface *p)
 {
   p->AsteriskHandlesAst.win32_hInit_MainWindowHandle =
-    CreateWindowEx(WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, p->AsteriskHandlesAst.win32_acInit_WindowClassName, "",
+    CreateWindowEx(WS_EX_APPWINDOW | WS_EX_WINDOWEDGE,
+                   p->AsteriskHandlesAst.win32_acInit_WindowClassName, "",
                    WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT,
                    128, 128, NULL, 0, p->AsteriskHandlesAst.win32_hInit_ProcessHandle, p);
   return (p->AsteriskHandlesAst.win32_hInit_MainWindowHandle != NULL ? 1 : 0);
@@ -815,7 +800,8 @@
 void win32_DeInitialize_DestroyMainWindow(struct skypiax_interface *p)
 {
   if (p->AsteriskHandlesAst.win32_hInit_MainWindowHandle != NULL)
-    DestroyWindow(p->AsteriskHandlesAst.win32_hInit_MainWindowHandle), p->AsteriskHandlesAst.win32_hInit_MainWindowHandle = NULL;
+    DestroyWindow(p->AsteriskHandlesAst.win32_hInit_MainWindowHandle),
+      p->AsteriskHandlesAst.win32_hInit_MainWindowHandle = NULL;
 }
 
 DWORD win32_dwThreadId;
@@ -835,19 +821,17 @@
   //DWORD MsgWaitResult;
   p = obj;
 
-
-
-  switch_file_pipe_create(&p->AsteriskHandlesAst.fdesc[0], &p->AsteriskHandlesAst.fdesc[1], skypiax_module_pool);
+  switch_file_pipe_create(&p->AsteriskHandlesAst.fdesc[0],
+                          &p->AsteriskHandlesAst.fdesc[1], skypiax_module_pool);
   //switch_file_pipe_timeout_set(p->AsteriskHandlesAst.fdesc[0], 100);
 
-
   p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIAttach =
     RegisterWindowMessage("SkypeControlAPIAttach");
   p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIDiscover =
     RegisterWindowMessage("SkypeControlAPIDiscover");
 
   LaunchSkype(p);
-	switch_sleep(2000000);
+  switch_sleep(2000000);
 
   if (p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIAttach != 0
       && p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIDiscover != 0) {
@@ -855,7 +839,8 @@
       if (win32_Initialize_CreateMainWindow(p)) {
 #if 1
         if (SendMessage
-            (HWND_BROADCAST, p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIDiscover,
+            (HWND_BROADCAST,
+             p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIDiscover,
              (WPARAM) p->AsteriskHandlesAst.win32_hInit_MainWindowHandle, 0) != 0) {
 #else
 
@@ -974,8 +959,10 @@
   //X11_errors_trap();
   //XLockDisplay(disp);
   status =
-    XGetWindowProperty(AsteriskHandlesAst->disp, DefaultRootWindow(AsteriskHandlesAst->disp), skype_inst, 0, 1, False, XA_WINDOW,
-                       &type_ret, &format_ret, &nitems_ret, &bytes_after_ret, &prop);
+    XGetWindowProperty(AsteriskHandlesAst->disp,
+                       DefaultRootWindow(AsteriskHandlesAst->disp), skype_inst, 0, 1,
+                       False, XA_WINDOW, &type_ret, &format_ret, &nitems_ret,
+                       &bytes_after_ret, &prop);
   //XUnlockDisplay(disp);
   //X11_errors_untrap();
 
@@ -1053,7 +1040,7 @@
   //FIXME pthread_cleanup_push(skypiax_skype_clean_disp, &xfd);
   DEBUGA_SKYPE("PUSH disp %d\n", SKYPIAX_P_LOG, xfd);
 
-    AsteriskHandlesAst->disp = disp;
+  AsteriskHandlesAst->disp = disp;
 
   if (skypiax_skype_present(AsteriskHandlesAst)) {
     root = DefaultRootWindow(disp);
@@ -1098,7 +1085,7 @@
     b = buffer;
 
     while (1) {
-		//switch_sleep(10000);
+      //switch_sleep(10000);
       XNextEvent(disp, &an_event);
       if (!running)
         break;
@@ -1158,7 +1145,7 @@
   struct AsteriskHandles *AsteriskHandlesAst;
 #endif /* WIN32 */
 
-    DEBUGA_SKYPE("SENDING: |||%s||||\n", SKYPIAX_P_LOG, msg_to_skype);
+  DEBUGA_SKYPE("SENDING: |||%s||||\n", SKYPIAX_P_LOG, msg_to_skype);
 
 #ifdef WIN32
 
@@ -1196,7 +1183,6 @@
   }
   AsteriskHandlesAst = &p->AsteriskHandlesAst;
 
-
   if (!skypiax_skype_send_message(AsteriskHandlesAst, msg_to_skype)) {
     ERRORA
       ("Sending message failed - probably Skype crashed.\n\nPlease shutdown Skypiax (Asterisk), then restart Skype from the menu, then launch Skypiax and try again.\n",
@@ -1248,459 +1234,464 @@
   fdselect = p->AsteriskHandlesAst.fdesc[0];
   FD_ZERO(&fs);
   FD_SET(fdselect, &fs);
-  to.tv_usec = 2000000; //500 msec
+  to.tv_usec = 2000000;         //500 msec
   to.tv_sec = 0;
   rt = select(fdselect + 1, &fs, NULL, NULL, &to);
 #endif /* WIN32 */
 
   if (rt > 0) {
-  if (p->AsteriskHandlesAst.fdesc[0]) {
-    howmany = sizeof(read_from_pipe);
+    if (p->AsteriskHandlesAst.fdesc[0]) {
+      howmany = sizeof(read_from_pipe);
 #ifdef WIN32
-    switch_file_read(p->AsteriskHandlesAst.fdesc[0], read_from_pipe, &howmany);
+      switch_file_read(p->AsteriskHandlesAst.fdesc[0], read_from_pipe, &howmany);
 #else /* WIN32 */
-    howmany =
-      read(p->AsteriskHandlesAst.fdesc[0], read_from_pipe, sizeof(read_from_pipe));
+      howmany =
+        read(p->AsteriskHandlesAst.fdesc[0], read_from_pipe, sizeof(read_from_pipe));
 #endif /* WIN32 */
 
-    a = 0;
-    for (i = 0; i < howmany; i++) {
-      messaggio[a] = read_from_pipe[i];
-      a++;
-
-      if (read_from_pipe[i] == '\0') {
-
-        //if (option_debug > 101)
-        DEBUGA_SKYPE("read_skype: howmany=%d, i=%d, a=%d, |||%s||| \n", SKYPIAX_P_LOG,
-                     howmany, i, a, messaggio);
-
-        if (!strncasecmp(messaggio, "ERROR 92 CALL", 12)) {
-          ERRORA("Skype got ERROR: |||%s|||, the number we called was not recognized\n",
-                 SKYPIAX_P_LOG, messaggio);
-          p->skype_callflow = CALLFLOW_STATUS_FINISHED;
-          if (option_debug)
-            DEBUGA_SKYPE("skype_call now is DOWN\n", SKYPIAX_P_LOG);
-          p->skype_call_id[0] = '\0';
-
-          if (p->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
-            if (option_debug > 100) {
-              DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+      a = 0;
+      for (i = 0; i < howmany; i++) {
+        messaggio[a] = read_from_pipe[i];
+        a++;
+
+        if (read_from_pipe[i] == '\0') {
+
+          //if (option_debug > 101)
+          DEBUGA_SKYPE("read_skype: howmany=%d, i=%d, a=%d, |||%s||| \n", SKYPIAX_P_LOG,
+                       howmany, i, a, messaggio);
+
+          if (!strncasecmp(messaggio, "ERROR 92 CALL", 12)) {
+            ERRORA("Skype got ERROR: |||%s|||, the number we called was not recognized\n",
+                   SKYPIAX_P_LOG, messaggio);
+            p->skype_callflow = CALLFLOW_STATUS_FINISHED;
+            if (option_debug)
+              DEBUGA_SKYPE("skype_call now is DOWN\n", SKYPIAX_P_LOG);
+            p->skype_call_id[0] = '\0';
+
+            if (p->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
+              if (option_debug > 100) {
+                DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+              }
+              p->interface_state = SKYPIAX_STATE_DOWN;
+              return CALLFLOW_INCOMING_HANGUP;
+            } else {
+              p->interface_state = SKYPIAX_STATE_DOWN;
             }
-            p->interface_state = SKYPIAX_STATE_DOWN;
-            return CALLFLOW_INCOMING_HANGUP;
-          } else {
-            p->interface_state = SKYPIAX_STATE_DOWN;
           }
-        }
 
-        strncpy(messaggio_2, messaggio, sizeof(messaggio) - 1);
+          strncpy(messaggio_2, messaggio, sizeof(messaggio) - 1);
 
-        buf = messaggio;
-        stringp = &buf;
-        where = strsep(stringp, " ");
-        if (!where) {
-          WARNINGA("Skype MSG without spaces: %s\n", SKYPIAX_P_LOG, messaggio);
-        }
+          buf = messaggio;
+          stringp = &buf;
+          where = strsep(stringp, " ");
+          if (!where) {
+            WARNINGA("Skype MSG without spaces: %s\n", SKYPIAX_P_LOG, messaggio);
+          }
 
-        if (!strcasecmp(messaggio, "#333")) {
-          /* DEBUGA_SKYPE("Skype MSG: messaggio_2: %s, messaggio2[11]: %s\n", SKYPIAX_P_LOG,
-           * messaggio_2, &messaggio_2[11]); */
-          memset(p->skype_friends, 0, 4096);
-          strncpy(p->skype_friends, &messaggio_2[11], 4095);
-        }
-        if (!strcasecmp(messaggio, "#222")) {
-          /* DEBUGA_SKYPE("Skype MSG: messaggio_2: %s, messaggio2[10]: %s\n", SKYPIAX_P_LOG,
-           * messaggio_2, &messaggio_2[10]); */
-          memset(p->skype_fullname, 0, 512);
-          strncpy(p->skype_fullname, &messaggio_2[10], 511);
-        }
-        if (!strcasecmp(messaggio, "#765")) {
-          /* DEBUGA_SKYPE("Skype MSG: messaggio_2: %s, messaggio2[10]: %s\n", SKYPIAX_P_LOG,
-           * messaggio_2, &messaggio_2[10]); */
-          memset(p->skype_displayname, 0, 512);
-          strncpy(p->skype_displayname, &messaggio_2[10], 511);
-        }
-        if (!strcasecmp(messaggio, "ERROR")) {
-          ERRORA("Skype got ERROR: |||%s|||\n", SKYPIAX_P_LOG, messaggio);
-          p->skype_callflow = CALLFLOW_STATUS_FINISHED;
-          if (option_debug)
-            DEBUGA_SKYPE("skype_call now is DOWN\n", SKYPIAX_P_LOG);
-          p->skype_call_id[0] = '\0';
-
-          if (p->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
-            if (option_debug > 100) {
-              DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
-            }
-            p->interface_state = SKYPIAX_STATE_DOWN;
-            return CALLFLOW_INCOMING_HANGUP;
-          } else {
-            p->interface_state = SKYPIAX_STATE_DOWN;
+          if (!strcasecmp(messaggio, "#333")) {
+            /* DEBUGA_SKYPE("Skype MSG: messaggio_2: %s, messaggio2[11]: %s\n", SKYPIAX_P_LOG,
+             * messaggio_2, &messaggio_2[11]); */
+            memset(p->skype_friends, 0, 4096);
+            strncpy(p->skype_friends, &messaggio_2[11], 4095);
           }
-        }
-          if (!strcasecmp(messaggio, "CURRENTUSERHANDLE") ) {
-          strncpy(obj, where, sizeof(obj) - 1);
+          if (!strcasecmp(messaggio, "#222")) {
+            /* DEBUGA_SKYPE("Skype MSG: messaggio_2: %s, messaggio2[10]: %s\n", SKYPIAX_P_LOG,
+             * messaggio_2, &messaggio_2[10]); */
+            memset(p->skype_fullname, 0, 512);
+            strncpy(p->skype_fullname, &messaggio_2[10], 511);
+          }
+          if (!strcasecmp(messaggio, "#765")) {
+            /* DEBUGA_SKYPE("Skype MSG: messaggio_2: %s, messaggio2[10]: %s\n", SKYPIAX_P_LOG,
+             * messaggio_2, &messaggio_2[10]); */
+            memset(p->skype_displayname, 0, 512);
+            strncpy(p->skype_displayname, &messaggio_2[10], 511);
+          }
+          if (!strcasecmp(messaggio, "ERROR")) {
+            ERRORA("Skype got ERROR: |||%s|||\n", SKYPIAX_P_LOG, messaggio);
+            p->skype_callflow = CALLFLOW_STATUS_FINISHED;
+            if (option_debug)
+              DEBUGA_SKYPE("skype_call now is DOWN\n", SKYPIAX_P_LOG);
+            p->skype_call_id[0] = '\0';
 
-          where = strsep(stringp, " ");
+            if (p->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
+              if (option_debug > 100) {
+                DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+              }
+              p->interface_state = SKYPIAX_STATE_DOWN;
+              return CALLFLOW_INCOMING_HANGUP;
+            } else {
+              p->interface_state = SKYPIAX_STATE_DOWN;
+            }
+          }
+          if (!strcasecmp(messaggio, "CURRENTUSERHANDLE")) {
+            strncpy(obj, where, sizeof(obj) - 1);
 
-          strncpy(id, where, sizeof(id) - 1);
+            where = strsep(stringp, " ");
 
+            strncpy(id, where, sizeof(id) - 1);
 
-          if (!strcasecmp(id, p->skype_user)) {
-		  p->AsteriskHandlesAst.api_connected = 1;
-            //DEBUGA_SKYPE ("Skype MSG: messaggio: %s, currentuserhandle: %s, cuh: %s, skype_user: %s!\n", SKYPIAX_P_LOG, messaggio, obj, id, p->skype_user);
-          }
+            if (!strcasecmp(id, p->skype_user)) {
+              p->AsteriskHandlesAst.api_connected = 1;
+              //DEBUGA_SKYPE ("Skype MSG: messaggio: %s, currentuserhandle: %s, cuh: %s, skype_user: %s!\n", SKYPIAX_P_LOG, messaggio, obj, id, p->skype_user);
+            }
           }
 
-        if (!strcasecmp(messaggio, "CALL")) {
-
-          strncpy(obj, where, sizeof(obj) - 1);
+          if (!strcasecmp(messaggio, "CALL")) {
 
-          where = strsep(stringp, " ");
+            strncpy(obj, where, sizeof(obj) - 1);
 
-          strncpy(id, where, sizeof(id) - 1);
+            where = strsep(stringp, " ");
 
-          where = strsep(stringp, " ");
+            strncpy(id, where, sizeof(id) - 1);
 
-          strncpy(prop, where, sizeof(prop) - 1);
+            where = strsep(stringp, " ");
 
-          where = strsep(stringp, " ");
+            strncpy(prop, where, sizeof(prop) - 1);
 
-          strncpy(value, where, sizeof(value) - 1);
+            where = strsep(stringp, " ");
 
-          where = strsep(stringp, " ");
+            strncpy(value, where, sizeof(value) - 1);
 
-          if (option_debug > 101)
-            DEBUGA_SKYPE
-              ("Skype MSG: messaggio: %s, obj: %s, id: %s, prop: %s, value: %s,where: %s!\n",
-               SKYPIAX_P_LOG, messaggio, obj, id, prop, value, where ? where : "NULL");
+            where = strsep(stringp, " ");
 
+            if (option_debug > 101)
+              DEBUGA_SKYPE
+                ("Skype MSG: messaggio: %s, obj: %s, id: %s, prop: %s, value: %s,where: %s!\n",
+                 SKYPIAX_P_LOG, messaggio, obj, id, prop, value, where ? where : "NULL");
 
-          if (!strcasecmp(prop, "PARTNER_HANDLE")) {
-            strncpy(p->callid_number, value, sizeof(p->callid_number) - 1);
-            WARNINGA
-              ("the skype_call %s caller PARTNER_HANDLE (p->callid_number) is: %s\n",
-               SKYPIAX_P_LOG, id, p->callid_number);
-            return CALLFLOW_INCOMING_RING;
-          }
-          if (!strcasecmp(prop, "PARTNER_DISPNAME")) {
-            snprintf(p->callid_name, sizeof(p->callid_name) - 1, "%s%s%s", value,
-                     where ? " " : "", where ? where : "");
-            WARNINGA
-              ("the skype_call %s caller PARTNER_DISPNAME (p->callid_name) is: %s\n",
-               SKYPIAX_P_LOG, id, p->callid_name);
-          }
-          if (!strcasecmp(prop, "CONF_ID") && !strcasecmp(value, "0")) {
-            DEBUGA_SKYPE("the skype_call %s is NOT a conference call\n", SKYPIAX_P_LOG,
-                         id);
-            if (p->interface_state == SKYPIAX_STATE_DOWN)
-              p->interface_state = SKYPIAX_STATE_PRERING;
-          }
-          if (!strcasecmp(prop, "CONF_ID") && strcasecmp(value, "0")) {
-            DEBUGA_SKYPE("the skype_call %s is a conference call\n", SKYPIAX_P_LOG, id);
-            if (p->interface_state == SKYPIAX_STATE_DOWN)
-              p->interface_state = SKYPIAX_STATE_PRERING;
-          }
+            if (!strcasecmp(prop, "PARTNER_HANDLE")) {
+              strncpy(p->callid_number, value, sizeof(p->callid_number) - 1);
+              WARNINGA
+                ("the skype_call %s caller PARTNER_HANDLE (p->callid_number) is: %s\n",
+                 SKYPIAX_P_LOG, id, p->callid_number);
+              return CALLFLOW_INCOMING_RING;
+            }
+            if (!strcasecmp(prop, "PARTNER_DISPNAME")) {
+              snprintf(p->callid_name, sizeof(p->callid_name) - 1, "%s%s%s", value,
+                       where ? " " : "", where ? where : "");
+              WARNINGA
+                ("the skype_call %s caller PARTNER_DISPNAME (p->callid_name) is: %s\n",
+                 SKYPIAX_P_LOG, id, p->callid_name);
+            }
+            if (!strcasecmp(prop, "CONF_ID") && !strcasecmp(value, "0")) {
+              DEBUGA_SKYPE("the skype_call %s is NOT a conference call\n", SKYPIAX_P_LOG,
+                           id);
+              if (p->interface_state == SKYPIAX_STATE_DOWN)
+                p->interface_state = SKYPIAX_STATE_PRERING;
+            }
+            if (!strcasecmp(prop, "CONF_ID") && strcasecmp(value, "0")) {
+              DEBUGA_SKYPE("the skype_call %s is a conference call\n", SKYPIAX_P_LOG, id);
+              if (p->interface_state == SKYPIAX_STATE_DOWN)
+                p->interface_state = SKYPIAX_STATE_PRERING;
+            }
 
-          if (!strcasecmp(prop, "DTMF")) {
-            switch_core_session_t *session = NULL;
-            private_t *tech_pvt = NULL;
-            switch_channel_t *channel = NULL;
-
-            DEBUGA_SKYPE("Call %s received a DTMF: %s\n", SKYPIAX_P_LOG, id, value);
-
-            tech_pvt = p->tech_pvt;
-			//if(tech_pvt)
-				session = tech_pvt->session;
-			//if(session)
-            channel = switch_core_session_get_channel(session);
-
-            if (channel) {
-              switch_dtmf_t dtmf =
-                { (char) value[0], switch_core_default_dtmf_duration(0) };
-              switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%c DTMF %s\n",
-                                dtmf.digit, switch_channel_get_name(channel));
-              switch_mutex_lock(tech_pvt->flag_mutex);
-              switch_channel_queue_dtmf(channel, &dtmf);
-              switch_set_flag(tech_pvt, TFLAG_DTMF);
-              switch_mutex_unlock(tech_pvt->flag_mutex);
+            if (!strcasecmp(prop, "DTMF")) {
+              switch_core_session_t *session = NULL;
+              private_t *tech_pvt = NULL;
+              switch_channel_t *channel = NULL;
+
+              DEBUGA_SKYPE("Call %s received a DTMF: %s\n", SKYPIAX_P_LOG, id, value);
+
+              tech_pvt = p->tech_pvt;
+              //if(tech_pvt)
+              session = tech_pvt->session;
+              //if(session)
+              channel = switch_core_session_get_channel(session);
+
+              if (channel) {
+                switch_dtmf_t dtmf =
+                  { (char) value[0], switch_core_default_dtmf_duration(0) };
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%c DTMF %s\n",
+                                  dtmf.digit, switch_channel_get_name(channel));
+                switch_mutex_lock(tech_pvt->flag_mutex);
+                switch_channel_queue_dtmf(channel, &dtmf);
+                switch_set_flag(tech_pvt, TFLAG_DTMF);
+                switch_mutex_unlock(tech_pvt->flag_mutex);
+              }
             }
-          }
 
-          if (!strcasecmp(prop, "FAILUREREASON")) {
-            DEBUGA_SKYPE
-              ("Skype has FAILED on skype_call %s. Let's wait for the FAILED message.\n",
-               SKYPIAX_P_LOG, id);
-          }
-          if (!strcasecmp(prop, "DURATION") && (!strcasecmp(value, "1"))) {
-            if (strcasecmp(id, p->skype_call_id)) {
-              strncpy(p->skype_call_id, id, sizeof(p->skype_call_id) - 1);
-              if (option_debug > 1)
-                DEBUGA_SKYPE
-                  ("We called a Skype contact and he answered us on skype_call: %s.\n",
-                   SKYPIAX_P_LOG, id);
+            if (!strcasecmp(prop, "FAILUREREASON")) {
+              DEBUGA_SKYPE
+                ("Skype has FAILED on skype_call %s. Let's wait for the FAILED message.\n",
+                 SKYPIAX_P_LOG, id);
             }
-          }
+            if (!strcasecmp(prop, "DURATION") && (!strcasecmp(value, "1"))) {
+              if (strcasecmp(id, p->skype_call_id)) {
+                strncpy(p->skype_call_id, id, sizeof(p->skype_call_id) - 1);
+                if (option_debug > 1)
+                  DEBUGA_SKYPE
+                    ("We called a Skype contact and he answered us on skype_call: %s.\n",
+                     SKYPIAX_P_LOG, id);
+              }
+            }
+
+            if (!strcasecmp(prop, "STATUS")) {
 
-          if (!strcasecmp(prop, "STATUS")) {
+              if (!strcasecmp(value, "RINGING")) {
+                char msg_to_skype[1024];
+                if (p->interface_state != SKYPIAX_STATE_DIALING) {
+                  /* we are not calling out */
 
-            if (!strcasecmp(value, "RINGING")) {
-              char msg_to_skype[1024];
-              if (p->interface_state != SKYPIAX_STATE_DIALING) {
-                /* we are not calling out */
+                  if (!strlen(p->skype_call_id)) {  //FIXME
+                    /* we are not inside an active call */
+                    p->skype_callflow = CALLFLOW_STATUS_RINGING;
+                    p->interface_state = SKYPIAX_STATE_RING;
+                    /* no owner, no active call, let's answer */
+                    skypiax_skype_write(p, "SET AGC OFF");
+                    switch_sleep(10000);
+                    skypiax_skype_write(p, "SET AEC OFF");
+                    switch_sleep(10000);
+                    sprintf(msg_to_skype, "GET CALL %s PARTNER_DISPNAME", id);
+                    skypiax_skype_write(p, msg_to_skype);
+                    switch_sleep(10000);
+                    sprintf(msg_to_skype, "GET CALL %s PARTNER_HANDLE", id);
+                    skypiax_skype_write(p, msg_to_skype);
+                    switch_sleep(10000);
+                    sprintf(msg_to_skype, "ALTER CALL %s ANSWER", id);
+                    skypiax_skype_write(p, msg_to_skype);
+                    if (option_debug)
+                      DEBUGA_SKYPE("We answered a Skype RING on skype_call %s\n",
+                                   SKYPIAX_P_LOG, id);
+                    strncpy(p->skype_call_id, id, sizeof(p->skype_call_id) - 1);
+                  } else {
+                    /* we're owned, we're in a call, let's refuse */
+                    //sprintf(msg_to_skype, "SET CALL %s STATUS REFUSED", id);
+                    sprintf(msg_to_skype, "ALTER CALL %s END HANGUP", id);
+                    skypiax_skype_write(p, msg_to_skype);
+                    switch_sleep(10000);
+                    DEBUGA_SKYPE
+                      ("We have NOT answered a Skype RING on skype_call %s, because we are already in a skypiax call\n",
+                       SKYPIAX_P_LOG, id);
 
-                if (!strlen(p->skype_call_id)) {        //FIXME
-                  /* we are not inside an active call */
+                  }
+                } else {
+                  /* we are calling out */
                   p->skype_callflow = CALLFLOW_STATUS_RINGING;
-                  p->interface_state = SKYPIAX_STATE_RING;
-                  /* no owner, no active call, let's answer */
-                  skypiax_skype_write(p, "SET AGC OFF");
-                  switch_sleep(10000);
-                  skypiax_skype_write(p, "SET AEC OFF");
-                  switch_sleep(10000);
-                  sprintf(msg_to_skype, "GET CALL %s PARTNER_DISPNAME", id);
-                  skypiax_skype_write(p, msg_to_skype);
-                  switch_sleep(10000);
-                  sprintf(msg_to_skype, "GET CALL %s PARTNER_HANDLE", id);
-                  skypiax_skype_write(p, msg_to_skype);
-                  switch_sleep(10000);
-                  sprintf(msg_to_skype, "ALTER CALL %s ANSWER", id);
-                  skypiax_skype_write(p, msg_to_skype);
-                  if (option_debug)
-                    DEBUGA_SKYPE("We answered a Skype RING on skype_call %s\n",
-                                 SKYPIAX_P_LOG, id);
+                  p->interface_state = SKYPIAX_STATE_RINGING;
+                  //FIXME ast_queue_control(p->owner, SKYPIAX_CONTROL_RINGING);
                   strncpy(p->skype_call_id, id, sizeof(p->skype_call_id) - 1);
-                } else {
-                  /* we're owned, we're in a call, let's refuse */
-                  //sprintf(msg_to_skype, "SET CALL %s STATUS REFUSED", id);
-                  sprintf(msg_to_skype, "ALTER CALL %s END HANGUP", id);
-                  skypiax_skype_write(p, msg_to_skype);
-                  switch_sleep(10000);
-                  DEBUGA_SKYPE
-                    ("We have NOT answered a Skype RING on skype_call %s, because we are already in a skypiax call\n",
-                     SKYPIAX_P_LOG, id);
-
+                  DEBUGA_SKYPE("Our remote party in skype_call %s is RINGING\n",
+                               SKYPIAX_P_LOG, id);
                 }
-              } else {
-                /* we are calling out */
-                p->skype_callflow = CALLFLOW_STATUS_RINGING;
-                p->interface_state = SKYPIAX_STATE_RINGING;
+              } else if (!strcasecmp(value, "EARLYMEDIA")) {
+                p->skype_callflow = CALLFLOW_STATUS_EARLYMEDIA;
+                p->interface_state = SKYPIAX_STATE_DIALING;
                 //FIXME ast_queue_control(p->owner, SKYPIAX_CONTROL_RINGING);
-                strncpy(p->skype_call_id, id, sizeof(p->skype_call_id) - 1);
-                DEBUGA_SKYPE("Our remote party in skype_call %s is RINGING\n",
+                DEBUGA_SKYPE("Our remote party in skype_call %s is EARLYMEDIA\n",
                              SKYPIAX_P_LOG, id);
-              }
-            } else if (!strcasecmp(value, "EARLYMEDIA")) {
-              p->skype_callflow = CALLFLOW_STATUS_EARLYMEDIA;
-              p->interface_state = SKYPIAX_STATE_DIALING;
-              //FIXME ast_queue_control(p->owner, SKYPIAX_CONTROL_RINGING);
-              DEBUGA_SKYPE("Our remote party in skype_call %s is EARLYMEDIA\n",
-                           SKYPIAX_P_LOG, id);
-            } else if (!strcasecmp(value, "MISSED")) {
-              DEBUGA_SKYPE("We missed skype_call %s\n", SKYPIAX_P_LOG, id);
-
-            } else if (!strcasecmp(value, "FINISHED")) {
-              //p->skype_callflow = CALLFLOW_STATUS_FINISHED;
-              if (option_debug)
-                DEBUGA_SKYPE("skype_call %s now is DOWN\n", SKYPIAX_P_LOG, id);
-              p->skype_call_id[0] = '\0';
+              } else if (!strcasecmp(value, "MISSED")) {
+                DEBUGA_SKYPE("We missed skype_call %s\n", SKYPIAX_P_LOG, id);
 
-              if (p->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
-                if (option_debug > 100) {
-                  DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+              } else if (!strcasecmp(value, "FINISHED")) {
+                //p->skype_callflow = CALLFLOW_STATUS_FINISHED;
+                if (option_debug)
+                  DEBUGA_SKYPE("skype_call %s now is DOWN\n", SKYPIAX_P_LOG, id);
+                p->skype_call_id[0] = '\0';
+
+                if (p->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
+                  if (option_debug > 100) {
+                    DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+                  }
+                  //p->interface_state = SKYPIAX_STATE_DOWN;
+                  return CALLFLOW_INCOMING_HANGUP;
+                } else {
+                  p->interface_state = SKYPIAX_STATE_DOWN;
                 }
-                //p->interface_state = SKYPIAX_STATE_DOWN;
-                return CALLFLOW_INCOMING_HANGUP;
-              } else {
-                p->interface_state = SKYPIAX_STATE_DOWN;
-              }
 
-            } else if (!strcasecmp(value, "CANCELLED")) {
-              p->skype_callflow = CALLFLOW_STATUS_CANCELLED;
-              if (option_debug)
-                DEBUGA_SKYPE
-                  ("we tried to call Skype on skype_call %s and Skype has now CANCELLED\n",
-                   SKYPIAX_P_LOG, id);
-              p->skype_call_id[0] = '\0';
+              } else if (!strcasecmp(value, "CANCELLED")) {
+                p->skype_callflow = CALLFLOW_STATUS_CANCELLED;
+                if (option_debug)
+                  DEBUGA_SKYPE
+                    ("we tried to call Skype on skype_call %s and Skype has now CANCELLED\n",
+                     SKYPIAX_P_LOG, id);
+                p->skype_call_id[0] = '\0';
 
-              if (p->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
-                if (option_debug > 100) {
-                  DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+                if (p->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
+                  if (option_debug > 100) {
+                    DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+                  }
+                  p->interface_state = SKYPIAX_STATE_DOWN;
+                  return CALLFLOW_INCOMING_HANGUP;
+                } else {
+                  p->interface_state = SKYPIAX_STATE_DOWN;
                 }
-                p->interface_state = SKYPIAX_STATE_DOWN;
-                return CALLFLOW_INCOMING_HANGUP;
-              } else {
-                p->interface_state = SKYPIAX_STATE_DOWN;
-              }
-            } else if (!strcasecmp(value, "FAILED")) {
-              p->skype_callflow = CALLFLOW_STATUS_FAILED;
-              if (option_debug)
-                DEBUGA_SKYPE
-                  ("we tried to call Skype on skype_call %s and Skype has now FAILED\n",
-                   SKYPIAX_P_LOG, id);
-              p->skype_call_id[0] = '\0';
-              strncpy(p->skype_call_id, id, sizeof(p->skype_call_id) - 1);
-              p->interface_state = SKYPIAX_STATE_DOWN;
-              if (option_debug > 100) {
-                DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
-              }
-              return CALLFLOW_INCOMING_HANGUP;
-            } else if (!strcasecmp(value, "REFUSED")) {
-              if (!strcasecmp(id, p->skype_call_id)) {
-                /* this is the id of the call we are in, probably we generated it */
-                p->skype_callflow = CALLFLOW_STATUS_REFUSED;
+              } else if (!strcasecmp(value, "FAILED")) {
+                p->skype_callflow = CALLFLOW_STATUS_FAILED;
                 if (option_debug)
                   DEBUGA_SKYPE
-                    ("we tried to call Skype on skype_call %s and Skype has now REFUSED\n",
+                    ("we tried to call Skype on skype_call %s and Skype has now FAILED\n",
                      SKYPIAX_P_LOG, id);
+                p->skype_call_id[0] = '\0';
                 strncpy(p->skype_call_id, id, sizeof(p->skype_call_id) - 1);
                 p->interface_state = SKYPIAX_STATE_DOWN;
-                p->skype_call_id[0] = '\0';
                 if (option_debug > 100) {
                   DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
                 }
                 return CALLFLOW_INCOMING_HANGUP;
-              } else {
-                /* we're here because were us that refused an incoming call */
-                DEBUGA_SKYPE("we REFUSED skype_call %s\n", SKYPIAX_P_LOG, id);
-
-              }
-            } else if (!strcasecmp(value, "ROUTING")) {
-              p->skype_callflow = CALLFLOW_STATUS_ROUTING;
-              p->interface_state = SKYPIAX_STATE_DIALING;
-              strncpy(p->skype_call_id, id, sizeof(p->skype_call_id) - 1);
-              DEBUGA_SKYPE("skype_call: %s is now ROUTING\n", SKYPIAX_P_LOG, id);
-            } else if (!strcasecmp(value, "UNPLACED")) {
-              p->skype_callflow = CALLFLOW_STATUS_UNPLACED;
-              p->interface_state = SKYPIAX_STATE_DIALING;
-              strncpy(p->skype_call_id, id, sizeof(p->skype_call_id) - 1);
-              DEBUGA_SKYPE("skype_call: %s is now UNPLACED\n", SKYPIAX_P_LOG, id);
-            } else if (!strcasecmp(value, "INPROGRESS")) {
-              p->skype_callflow = CALLFLOW_STATUS_INPROGRESS;
-              strncpy(p->skype_call_id, id, sizeof(p->skype_call_id) - 1);
-              p->interface_state = SKYPIAX_STATE_UP;
-              if (option_debug > 1)
-                DEBUGA_SKYPE("skype_call: %s is now active\n", SKYPIAX_P_LOG, id);
-
-              if (option_debug > 1)
-                DEBUGA_SKYPE("skype_call: %s SKYPIAX_CONTROL_ANSWER sent\n",
-                             SKYPIAX_P_LOG, id);
+              } else if (!strcasecmp(value, "REFUSED")) {
+                if (!strcasecmp(id, p->skype_call_id)) {
+                  /* this is the id of the call we are in, probably we generated it */
+                  p->skype_callflow = CALLFLOW_STATUS_REFUSED;
+                  if (option_debug)
+                    DEBUGA_SKYPE
+                      ("we tried to call Skype on skype_call %s and Skype has now REFUSED\n",
+                       SKYPIAX_P_LOG, id);
+                  strncpy(p->skype_call_id, id, sizeof(p->skype_call_id) - 1);
+                  p->interface_state = SKYPIAX_STATE_DOWN;
+                  p->skype_call_id[0] = '\0';
+                  if (option_debug > 100) {
+                    DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+                  }
+                  return CALLFLOW_INCOMING_HANGUP;
+                } else {
+                  /* we're here because were us that refused an incoming call */
+                  DEBUGA_SKYPE("we REFUSED skype_call %s\n", SKYPIAX_P_LOG, id);
 
-              if (1) {          //FIXME
-                char msg_to_skype[1024];
+                }
+              } else if (!strcasecmp(value, "ROUTING")) {
+                p->skype_callflow = CALLFLOW_STATUS_ROUTING;
+                p->interface_state = SKYPIAX_STATE_DIALING;
+                strncpy(p->skype_call_id, id, sizeof(p->skype_call_id) - 1);
+                DEBUGA_SKYPE("skype_call: %s is now ROUTING\n", SKYPIAX_P_LOG, id);
+              } else if (!strcasecmp(value, "UNPLACED")) {
+                p->skype_callflow = CALLFLOW_STATUS_UNPLACED;
+                p->interface_state = SKYPIAX_STATE_DIALING;
+                strncpy(p->skype_call_id, id, sizeof(p->skype_call_id) - 1);
+                DEBUGA_SKYPE("skype_call: %s is now UNPLACED\n", SKYPIAX_P_LOG, id);
+              } else if (!strcasecmp(value, "INPROGRESS")) {
+                p->skype_callflow = CALLFLOW_STATUS_INPROGRESS;
+                strncpy(p->skype_call_id, id, sizeof(p->skype_call_id) - 1);
+                p->interface_state = SKYPIAX_STATE_UP;
+                if (option_debug > 1)
+                  DEBUGA_SKYPE("skype_call: %s is now active\n", SKYPIAX_P_LOG, id);
+
+                if (option_debug > 1)
+                  DEBUGA_SKYPE("skype_call: %s SKYPIAX_CONTROL_ANSWER sent\n",
+                               SKYPIAX_P_LOG, id);
 
                 if (1) {        //FIXME
-                  switch_threadattr_t *thd_attr = NULL;
+                  char msg_to_skype[1024];
 
-                  switch_threadattr_create(&thd_attr, skypiax_module_pool);
-                  switch_threadattr_detach_set(thd_attr, 1);
-                  switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-                  switch_thread_create(&p->tcp_srv_thread, thd_attr,
-                                       skypiax_do_tcp_srv_thread, p, skypiax_module_pool);
-                  DEBUGA_SKYPE("started tcp_srv_thread thread.\n", SKYPIAX_P_LOG);
-
-                  switch_threadattr_create(&thd_attr, skypiax_module_pool);
-                  switch_threadattr_detach_set(thd_attr, 1);
-                  switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-                  switch_thread_create(&p->tcp_cli_thread, thd_attr,
-                                       skypiax_do_tcp_cli_thread, p, skypiax_module_pool);
-                  DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
+                  if (1) {      //FIXME
+                    switch_threadattr_t *thd_attr = NULL;
+
+                    switch_threadattr_create(&thd_attr, skypiax_module_pool);
+                    switch_threadattr_detach_set(thd_attr, 1);
+                    switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+                    switch_thread_create(&p->tcp_srv_thread, thd_attr,
+                                         skypiax_do_tcp_srv_thread, p,
+                                         skypiax_module_pool);
+                    DEBUGA_SKYPE("started tcp_srv_thread thread.\n", SKYPIAX_P_LOG);
+
+                    switch_threadattr_create(&thd_attr, skypiax_module_pool);
+                    switch_threadattr_detach_set(thd_attr, 1);
+                    switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+                    switch_thread_create(&p->tcp_cli_thread, thd_attr,
+                                         skypiax_do_tcp_cli_thread, p,
+                                         skypiax_module_pool);
+                    DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
+                  }
+                  switch_sleep(100000);
+                  sprintf(msg_to_skype, "ALTER CALL %s SET_OUTPUT PORT=\"%d\"", id,
+                          p->tcp_srv_port);
+                  skypiax_skype_write(p, msg_to_skype);
+                  switch_sleep(100000);
+                  sprintf(msg_to_skype, "ALTER CALL %s SET_INPUT PORT=\"%d\"", id,
+                          p->tcp_cli_port);
+                  skypiax_skype_write(p, msg_to_skype);
+                  switch_sleep(100000);
                 }
-                switch_sleep(100000);
-                sprintf(msg_to_skype, "ALTER CALL %s SET_OUTPUT PORT=\"%d\"", id, p->tcp_srv_port);
-                skypiax_skype_write(p, msg_to_skype);
-                switch_sleep(100000);
-                sprintf(msg_to_skype, "ALTER CALL %s SET_INPUT PORT=\"%d\"", id, p->tcp_cli_port);
-                skypiax_skype_write(p, msg_to_skype);
-                switch_sleep(100000);
-              }
 
-              p->skype_callflow = SKYPIAX_STATE_UP;
+                p->skype_callflow = SKYPIAX_STATE_UP;
 
               /**************************/
 
-              //FIXME switch_core_session_t **new_session;
+                //FIXME switch_core_session_t **new_session;
 
-              //FIXME *new_session=switch_loadable_module_create_interface(skypiax_endpoint_interface, pool);
+                //FIXME *new_session=switch_loadable_module_create_interface(skypiax_endpoint_interface, pool);
 
-              if (!global_session) {    //FIXME FIXME FIXME 
-                switch_core_session_t *session = NULL;
-                private_t *tech_pvt = NULL;
-                switch_channel_t *channel = NULL;
-
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
-                                  "New Inbound Channel!\n");
-
-                if ((session =
-                     switch_core_session_request(skypiax_endpoint_interface,
-                                                 NULL)) != 0) {
-                  switch_core_session_add_stream(session, NULL);
-                  if ((tech_pvt =
-                       (private_t *) switch_core_session_alloc(session,
-                                                               sizeof(private_t))) != 0) {
-                    channel = switch_core_session_get_channel(session);
-                    skypiax_tech_init(tech_pvt, session, p);
-                  } else {
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
-                                      "Hey where is my memory pool?\n");
-                    switch_core_session_destroy(&session);
-                    break;
+                if (!global_session) {  //FIXME FIXME FIXME 
+                  switch_core_session_t *session = NULL;
+                  private_t *tech_pvt = NULL;
+                  switch_channel_t *channel = NULL;
+
+                  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
+                                    "New Inbound Channel!\n");
+
+                  if ((session =
+                       switch_core_session_request(skypiax_endpoint_interface,
+                                                   NULL)) != 0) {
+                    switch_core_session_add_stream(session, NULL);
+                    if ((tech_pvt =
+                         (private_t *) switch_core_session_alloc(session,
+                                                                 sizeof(private_t))) !=
+                        0) {
+                      channel = switch_core_session_get_channel(session);
+                      skypiax_tech_init(tech_pvt, session, p);
+                    } else {
+                      switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
+                                        "Hey where is my memory pool?\n");
+                      switch_core_session_destroy(&session);
+                      break;
+                    }
+
+                    // if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), NULL, dialplan, cid_name, cid_num, ip, NULL, NULL, NULL, modname, NULL, dest)) != 0) 
+
+                    if ((tech_pvt->caller_profile =
+                         switch_caller_profile_new(switch_core_session_get_pool(session),
+                                                   "skypiax", "XML", p->callid_name,
+                                                   p->callid_number, NULL, "calling_ani",
+                                                   NULL, NULL, "mod_skypiax", "public",
+                                                   "5000")) != 0) {
+                      char name[128];
+                      switch_snprintf(name, sizeof(name), "skypiax/%s-%04x",
+                                      tech_pvt->caller_profile->destination_number,
+                                      rand() & 0xffff);
+                      switch_channel_set_name(channel, name);
+                      switch_channel_set_caller_profile(channel,
+                                                        tech_pvt->caller_profile);
+                    }
+                    switch_channel_set_state(channel, CS_INIT);
+                    if (switch_core_session_thread_launch(session) !=
+                        SWITCH_STATUS_SUCCESS) {
+                      switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
+                                        "Error spawning thread\n");
+                      switch_core_session_destroy(&session);
+                    }
                   }
+                  //DEBUGA_SKYPE("skype_call: %s, answered\n", SKYPIAX_P_LOG, id);
+                  switch_channel_mark_answered(channel);
+                } else {
+                  switch_core_session_t *session = NULL;
+                  private_t *tech_pvt = NULL;
+                  switch_channel_t *channel = NULL;
+
+                  tech_pvt = p->tech_pvt;
+                  //session = tech_pvt->session;
+                  session = global_session;
+                  channel = switch_core_session_get_channel(session);
+                  //DEBUGA_SKYPE("skype_call: %s, answered\n", SKYPIAX_P_LOG, id);
+                  switch_channel_mark_answered(channel);
 
-                  // if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), NULL, dialplan, cid_name, cid_num, ip, NULL, NULL, NULL, modname, NULL, dest)) != 0) 
+                  //switch_channel_set_state(channel, CS_EXECUTE);
 
-                  if ((tech_pvt->caller_profile =
-                       switch_caller_profile_new(switch_core_session_get_pool(session),
-                                                 "skypiax", "XML", p->callid_name,
-                                                 p->callid_number, NULL, "calling_ani",
-                                                 NULL, NULL, "mod_skypiax", "public",
-                                                 "5000")) != 0) {
-                    char name[128];
-                    switch_snprintf(name, sizeof(name), "skypiax/%s-%04x",
-                                    tech_pvt->caller_profile->destination_number,
-                                    rand() & 0xffff);
-                    switch_channel_set_name(channel, name);
-                    switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
-                  }
-                  switch_channel_set_state(channel, CS_INIT);
-                  if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) {
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
-                                      "Error spawning thread\n");
-                    switch_core_session_destroy(&session);
-                  }
                 }
-              WARNINGA("skype_call: %s, answered\n", SKYPIAX_P_LOG, id);
-                switch_channel_mark_answered(channel);
-              } else {
-                switch_core_session_t *session = NULL;
-                private_t *tech_pvt = NULL;
-                switch_channel_t *channel = NULL;
-
-                tech_pvt = p->tech_pvt;
-                //session = tech_pvt->session;
-                session = global_session;
-                channel = switch_core_session_get_channel(session);
-              WARNINGA("skype_call: %s, answered\n", SKYPIAX_P_LOG, id);
-                switch_channel_mark_answered(channel);
-
-                //switch_channel_set_state(channel, CS_EXECUTE);
-
-              }
               /**************************/
 
-            } else {
-              WARNINGA("skype_call: %s, STATUS: %s is not recognized\n", SKYPIAX_P_LOG,
-                       id, value);
+              } else {
+                WARNINGA("skype_call: %s, STATUS: %s is not recognized\n", SKYPIAX_P_LOG,
+                         id, value);
 
-            }
-          }                     //STATUS
+              }
+            }                   //STATUS
 
-        }                       //CALL
+          }                     //CALL
 
-        a = 0;
-      }                         //message end
-    }                           //read_from_pipe
+          a = 0;
+        }                       //message end
+      }                         //read_from_pipe
 
-  }
+    }
   }
 
   if (option_debug > 100) {
@@ -1710,7 +1701,8 @@
   return 0;
 }
 
-int skypiax_skype_call(struct skypiax_interface *p, char *idest, int timeout, switch_core_session_t * session)
+int skypiax_skype_call(struct skypiax_interface *p, char *idest, int timeout,
+                       switch_core_session_t * session)
 {
   char *rdest;
   char msg_to_skype[1024];
@@ -1745,5 +1737,3 @@
   //FIXME ast_queue_control(p->owner, SKYPIAX_CONTROL_RINGING);
   return 0;
 }
-
-



More information about the Freeswitch-svn mailing list