Revision
14444
Author
anthm
Date
2009-07-31 21:47:35 -0500 (Fri, 31 Jul 2009)

Log Message

MODSKYPIAX-35 (part1)

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c (14443 => 14444)


--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c	2009-08-01 01:02:02 UTC (rev 14443)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c	2009-08-01 02:47:35 UTC (rev 14444)
@@ -48,35 +48,35 @@
 #define DELTA_EPOCH_IN_MICROSECS  11644473600000000ULL
 #endif /*  */
 struct sk_timezone {
-  int tz_minuteswest;           /* minutes W of Greenwich */
-  int tz_dsttime;               /* type of dst correction */
+	int tz_minuteswest;			/* minutes W of Greenwich */
+	int tz_dsttime;				/* type of dst correction */
 };
 int gettimeofday(struct timeval *tv, struct sk_timezone *tz)
 {
-  FILETIME ft;
-  unsigned __int64 tmpres = 0;
-  static int tzflag;
-  if (NULL != tv) {
-    GetSystemTimeAsFileTime(&ft);
-    tmpres |= ft.dwHighDateTime;
-    tmpres <<= 32;
-    tmpres |= ft.dwLowDateTime;
+	FILETIME ft;
+	unsigned __int64 tmpres = 0;
+	static int tzflag;
+	if (NULL != tv) {
+		GetSystemTimeAsFileTime(&ft);
+		tmpres |= ft.dwHighDateTime;
+		tmpres <<= 32;
+		tmpres |= ft.dwLowDateTime;
 
-    /*converting file time to unix epoch */
-    tmpres /= 10;               /*convert into microseconds */
-    tmpres -= DELTA_EPOCH_IN_MICROSECS;
-    tv->tv_sec = (long) (tmpres / 1000000UL);
-    tv->tv_usec = (long) (tmpres % 1000000UL);
-  }
-  if (NULL != tz) {
-    if (!tzflag) {
-      _tzset();
-      tzflag++;
-    }
-    tz->tz_minuteswest = _timezone / 60;
-    tz->tz_dsttime = _daylight;
-  }
-  return 0;
+		/*converting file time to unix epoch */
+		tmpres /= 10;			/*convert into microseconds */
+		tmpres -= DELTA_EPOCH_IN_MICROSECS;
+		tv->tv_sec = (long) (tmpres / 1000000UL);
+		tv->tv_usec = (long) (tmpres % 1000000UL);
+	}
+	if (NULL != tz) {
+		if (!tzflag) {
+			_tzset();
+			tzflag++;
+		}
+		tz->tz_minuteswest = _timezone / 60;
+		tz->tz_dsttime = _daylight;
+	}
+	return 0;
 }
 
 /***************/
@@ -97,27 +97,27 @@
 /* END: Changes heres */
 
 static struct {
-  int debug;
-  char *ip;
-  int port;
-  char *dialplan;
-  char *destination;
-  char *context;
-  char *codec_string;
-  char *codec_order[SWITCH_MAX_CODECS];
-  int codec_order_last;
-  char *codec_rates_string;
-  char *codec_rates[SWITCH_MAX_CODECS];
-  int codec_rates_last;
-  unsigned int flags;
-  int fd;
-  int calls;          
-  int real_interfaces;
-  int next_interface;
-  char hold_music[256];
-  private_t SKYPIAX_INTERFACES[SKYPIAX_MAX_INTERFACES];
-  switch_mutex_t *mutex;
-  private_t *sk_console;
+	int debug;
+	char *ip;
+	int port;
+	char *dialplan;
+	char *destination;
+	char *context;
+	char *codec_string;
+	char *codec_order[SWITCH_MAX_CODECS];
+	int codec_order_last;
+	char *codec_rates_string;
+	char *codec_rates[SWITCH_MAX_CODECS];
+	int codec_rates_last;
+	unsigned int flags;
+	int fd;
+	int calls;
+	int real_interfaces;
+	int next_interface;
+	char hold_music[256];
+	private_t SKYPIAX_INTERFACES[SKYPIAX_MAX_INTERFACES];
+	switch_mutex_t *mutex;
+	private_t *sk_console;
 } globals;
 
 switch_endpoint_interface_t *skypiax_endpoint_interface;
@@ -128,243 +128,223 @@
 SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_context, globals.context);
 SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_destination, globals.destination);
 SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string);
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string,
-                                  globals.codec_rates_string);
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string);
 
 /* BEGIN: Changes here */
 static switch_status_t interface_exists(char *the_interface);
 static switch_status_t remove_interface(char *the_interface);
 /* END: Changes here */
 
-static switch_status_t channel_on_init(switch_core_session_t * session);
-static switch_status_t channel_on_hangup(switch_core_session_t * session);
-static switch_status_t channel_on_destroy(switch_core_session_t * session);
-static switch_status_t channel_on_routing(switch_core_session_t * session);
-static switch_status_t channel_on_exchange_media(switch_core_session_t * session);
-static switch_status_t channel_on_soft_execute(switch_core_session_t * session);
-static switch_call_cause_t channel_outgoing_channel(switch_core_session_t * session,
-                                                    switch_event_t * var_event,
-                                                    switch_caller_profile_t *
-                                                    outbound_profile,
-                                                    switch_core_session_t ** new_session,
-                                                    switch_memory_pool_t ** pool,
-                                                    switch_originate_flag_t flags);
-static switch_status_t channel_read_frame(switch_core_session_t * session,
-                                          switch_frame_t ** frame, switch_io_flag_t flags,
-                                          int stream_id);
-static switch_status_t channel_write_frame(switch_core_session_t * session,
-                                           switch_frame_t * frame, switch_io_flag_t flags,
-                                           int stream_id);
-static switch_status_t channel_kill_channel(switch_core_session_t * session, int sig);
+static switch_status_t channel_on_init(switch_core_session_t *session);
+static switch_status_t channel_on_hangup(switch_core_session_t *session);
+static switch_status_t channel_on_destroy(switch_core_session_t *session);
+static switch_status_t channel_on_routing(switch_core_session_t *session);
+static switch_status_t channel_on_exchange_media(switch_core_session_t *session);
+static switch_status_t channel_on_soft_execute(switch_core_session_t *session);
+static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
+													switch_event_t *var_event,
+													switch_caller_profile_t *outbound_profile,
+													switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags);
+static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id);
+static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
+static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
 
 static switch_status_t skypiax_codec(private_t * tech_pvt, int sample_rate, int codec_ms)
 {
-  switch_core_session_t *session = NULL;
+	switch_core_session_t *session = NULL;
 
-  if (switch_core_codec_init
-      (&tech_pvt->read_codec, "L16", NULL, sample_rate, codec_ms, 1,
-       SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
-       NULL) != SWITCH_STATUS_SUCCESS) {
-    ERRORA("Can't load codec?\n", SKYPIAX_P_LOG);
-    return SWITCH_STATUS_FALSE;
-  }
+	if (switch_core_codec_init
+		(&tech_pvt->read_codec, "L16", NULL, sample_rate, codec_ms, 1,
+		 SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
+		ERRORA("Can't load codec?\n", SKYPIAX_P_LOG);
+		return SWITCH_STATUS_FALSE;
+	}
 
-  if (switch_core_codec_init
-      (&tech_pvt->write_codec, "L16", NULL, sample_rate, codec_ms, 1,
-       SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
-       NULL) != SWITCH_STATUS_SUCCESS) {
-    ERRORA("Can't load codec?\n", SKYPIAX_P_LOG);
-    switch_core_codec_destroy(&tech_pvt->read_codec);
-    return SWITCH_STATUS_FALSE;
-  }
+	if (switch_core_codec_init
+		(&tech_pvt->write_codec, "L16", NULL, sample_rate, codec_ms, 1,
+		 SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
+		ERRORA("Can't load codec?\n", SKYPIAX_P_LOG);
+		switch_core_codec_destroy(&tech_pvt->read_codec);
+		return SWITCH_STATUS_FALSE;
+	}
 
-  tech_pvt->read_frame.rate = sample_rate;
-  tech_pvt->read_frame.codec = &tech_pvt->read_codec;
+	tech_pvt->read_frame.rate = sample_rate;
+	tech_pvt->read_frame.codec = &tech_pvt->read_codec;
 
-  session = switch_core_session_locate(tech_pvt->session_uuid_str);
+	session = switch_core_session_locate(tech_pvt->session_uuid_str);
 
-  switch_core_session_set_read_codec(session, &tech_pvt->read_codec);
-  switch_core_session_set_write_codec(session, &tech_pvt->write_codec);
+	switch_core_session_set_read_codec(session, &tech_pvt->read_codec);
+	switch_core_session_set_write_codec(session, &tech_pvt->write_codec);
 
-  switch_core_session_rwunlock(session);
+	switch_core_session_rwunlock(session);
 
-  return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 
 }
 
-void skypiax_tech_init(private_t * tech_pvt, switch_core_session_t * session)
+void skypiax_tech_init(private_t * tech_pvt, switch_core_session_t *session)
 {
 
-  tech_pvt->read_frame.data = tech_pvt->databuf;
-  tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf);
-  switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED,
-                    switch_core_session_get_pool(session));
-  switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED,
-                    switch_core_session_get_pool(session));
-  switch_core_session_set_private(session, tech_pvt);
-  switch_copy_string(tech_pvt->session_uuid_str, switch_core_session_get_uuid(session),
-                     sizeof(tech_pvt->session_uuid_str));
-  if (skypiax_codec(tech_pvt, SAMPLERATE_SKYPIAX, 20) != SWITCH_STATUS_SUCCESS) {
-    ERRORA("skypiax_codec FAILED\n", SKYPIAX_P_LOG);
-  } else {
-    DEBUGA_SKYPE("skypiax_codec SUCCESS\n", SKYPIAX_P_LOG);
-  }
+	tech_pvt->read_frame.data = tech_pvt->databuf;
+	tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf);
+	switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
+	switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
+	switch_core_session_set_private(session, tech_pvt);
+	switch_copy_string(tech_pvt->session_uuid_str, switch_core_session_get_uuid(session), sizeof(tech_pvt->session_uuid_str));
+	if (skypiax_codec(tech_pvt, SAMPLERATE_SKYPIAX, 20) != SWITCH_STATUS_SUCCESS) {
+		ERRORA("skypiax_codec FAILED\n", SKYPIAX_P_LOG);
+	} else {
+		DEBUGA_SKYPE("skypiax_codec SUCCESS\n", SKYPIAX_P_LOG);
+	}
 
 }
 
 /* BEGIN: Changes here */
 static switch_status_t interface_exists(char *the_interface)
 {
-  int i;
-  int interface_id;
+	int i;
+	int interface_id;
 
-  if ( *the_interface == '#') { /* look by interface id or interface name */
-    the_interface++;
-    switch_assert(the_interface);
-    interface_id = atoi(the_interface);
+	if (*the_interface == '#') {	/* look by interface id or interface name */
+		the_interface++;
+		switch_assert(the_interface);
+		interface_id = atoi(the_interface);
 
-      /* take a number as interface id */
-    if ( interface_id > 0 || (interface_id == 0 && strcmp(the_interface, "0") == 0 )) {
-        if (strlen(globals.SKYPIAX_INTERFACES[interface_id].name)) {
-          return SWITCH_STATUS_SUCCESS;
-        }
-    } else {
-      /* interface name */
-      for (interface_id = 0; interface_id < SKYPIAX_MAX_INTERFACES; interface_id++) {
-        if (strcmp(globals.SKYPIAX_INTERFACES[interface_id].name, the_interface) == 0) {
-          return SWITCH_STATUS_SUCCESS;
-          break;
-        }
-      }
-    }
-  } else { /* look by skype_user */
+		/* take a number as interface id */
+		if (interface_id > 0 || (interface_id == 0 && strcmp(the_interface, "0") == 0)) {
+			if (strlen(globals.SKYPIAX_INTERFACES[interface_id].name)) {
+				return SWITCH_STATUS_SUCCESS;
+			}
+		} else {
+			/* interface name */
+			for (interface_id = 0; interface_id < SKYPIAX_MAX_INTERFACES; interface_id++) {
+				if (strcmp(globals.SKYPIAX_INTERFACES[interface_id].name, the_interface) == 0) {
+					return SWITCH_STATUS_SUCCESS;
+					break;
+				}
+			}
+		}
+	} else {					/* look by skype_user */
 
 
-  for (i = 0; i < SKYPIAX_MAX_INTERFACES; i++) {
-    if (strlen(globals.SKYPIAX_INTERFACES[i].skype_user)) {
-      if (strcmp(globals.SKYPIAX_INTERFACES[i].skype_user, the_interface) == 0) {
-        return SWITCH_STATUS_SUCCESS;
-      }
-    }
-  }
-  }
-  return SWITCH_STATUS_FALSE;
+		for (i = 0; i < SKYPIAX_MAX_INTERFACES; i++) {
+			if (strlen(globals.SKYPIAX_INTERFACES[i].skype_user)) {
+				if (strcmp(globals.SKYPIAX_INTERFACES[i].skype_user, the_interface) == 0) {
+					return SWITCH_STATUS_SUCCESS;
+				}
+			}
+		}
+	}
+	return SWITCH_STATUS_FALSE;
 }
 
 static switch_status_t remove_interface(char *the_interface)
 {
-  int x = 100;
-  unsigned int howmany = 8;
-  int interface_id = -1;
-  private_t *tech_pvt = NULL;
-  switch_status_t status;
+	int x = 100;
+	unsigned int howmany = 8;
+	int interface_id = -1;
+	private_t *tech_pvt = NULL;
+	switch_status_t status;
 
-  //running = 0;
+	//running = 0;
 
 
-  if ( *the_interface == '#') { /* remove by interface id or interface name */
-    the_interface++;
-    switch_assert(the_interface);
-    interface_id = atoi(the_interface);
+	if (*the_interface == '#') {	/* remove by interface id or interface name */
+		the_interface++;
+		switch_assert(the_interface);
+		interface_id = atoi(the_interface);
 
-    if ( interface_id > 0 || (interface_id == 0 && strcmp(the_interface, "0") == 0 )) {
-      /* take a number as interface id */
-      tech_pvt = &globals.SKYPIAX_INTERFACES[interface_id];
-    } else {
+		if (interface_id > 0 || (interface_id == 0 && strcmp(the_interface, "0") == 0)) {
+			/* take a number as interface id */
+			tech_pvt = &globals.SKYPIAX_INTERFACES[interface_id];
+		} else {
 
-      for (interface_id = 0; interface_id < SKYPIAX_MAX_INTERFACES; interface_id++) {
-        if (strcmp(globals.SKYPIAX_INTERFACES[interface_id].name, the_interface) == 0) {
-          tech_pvt = &globals.SKYPIAX_INTERFACES[interface_id];
-          break;
-        }
-      }
-    }
-  } else { /* remove by skype_user */
-    for (interface_id = 0; interface_id < SKYPIAX_MAX_INTERFACES; interface_id++) {
-      if (strcmp(globals.SKYPIAX_INTERFACES[interface_id].skype_user, the_interface) == 0) {
-        tech_pvt = &globals.SKYPIAX_INTERFACES[interface_id];
-        break;
-      }
-    }
-  }
+			for (interface_id = 0; interface_id < SKYPIAX_MAX_INTERFACES; interface_id++) {
+				if (strcmp(globals.SKYPIAX_INTERFACES[interface_id].name, the_interface) == 0) {
+					tech_pvt = &globals.SKYPIAX_INTERFACES[interface_id];
+					break;
+				}
+			}
+		}
+	} else {					/* remove by skype_user */
+		for (interface_id = 0; interface_id < SKYPIAX_MAX_INTERFACES; interface_id++) {
+			if (strcmp(globals.SKYPIAX_INTERFACES[interface_id].skype_user, the_interface) == 0) {
+				tech_pvt = &globals.SKYPIAX_INTERFACES[interface_id];
+				break;
+			}
+		}
+	}
 
-  if (!tech_pvt) {
-    DEBUGA_SKYPE("interface '%s' does not exist\n", SKYPIAX_P_LOG,
-                 the_interface);
-    goto end;
-  }
+	if (!tech_pvt) {
+		DEBUGA_SKYPE("interface '%s' does not exist\n", SKYPIAX_P_LOG, the_interface);
+		goto end;
+	}
 
-  if (strlen(globals.SKYPIAX_INTERFACES[interface_id].session_uuid_str)) {
-    DEBUGA_SKYPE("interface '%s' is busy\n", SKYPIAX_P_LOG, the_interface);
-    goto end;
-  }
+	if (strlen(globals.SKYPIAX_INTERFACES[interface_id].session_uuid_str)) {
+		DEBUGA_SKYPE("interface '%s' is busy\n", SKYPIAX_P_LOG, the_interface);
+		goto end;
+	}
 
-  globals.SKYPIAX_INTERFACES[interface_id].running=0;
+	globals.SKYPIAX_INTERFACES[interface_id].running = 0;
 
-  if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_signaling_thread) {
+	if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_signaling_thread) {
 #ifdef WIN32
-    switch_file_write(tech_pvt->SkypiaxHandles.fdesc[1], "sciutati", &howmany); // let's the controldev_thread die
+		switch_file_write(tech_pvt->SkypiaxHandles.fdesc[1], "sciutati", &howmany);	// let's the controldev_thread die
 #else /* WIN32 */
-    howmany = write(tech_pvt->SkypiaxHandles.fdesc[1], "sciutati", howmany);
+		howmany = write(tech_pvt->SkypiaxHandles.fdesc[1], "sciutati", howmany);
 #endif /* WIN32 */
-  }
+	}
 
-  if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread) {
+	if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread) {
 #ifdef WIN32
-    if (SendMessage(tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle, WM_DESTROY, 0, 0) == FALSE) {    // let's the skypiax_api_thread_func die
-      DEBUGA_SKYPE
-        ("got FALSE here, thread probably was already dead. GetLastError returned: %d\n",
-         SKYPIAX_P_LOG, GetLastError());
-      globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread = NULL;
-    }
+		if (SendMessage(tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle, WM_DESTROY, 0, 0) == FALSE) {	// let's the skypiax_api_thread_func die
+			DEBUGA_SKYPE("got FALSE here, thread probably was already dead. GetLastError returned: %d\n", SKYPIAX_P_LOG, GetLastError());
+			globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread = NULL;
+		}
 #else
-    XEvent e;
-    Atom atom1 =
-      XInternAtom(tech_pvt->SkypiaxHandles.disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False);
-    memset(&e, 0, sizeof(e));
-    e.xclient.type = ClientMessage;
-    e.xclient.message_type = atom1; /*  leading message */
-    e.xclient.display = tech_pvt->SkypiaxHandles.disp;
-    e.xclient.window = tech_pvt->SkypiaxHandles.skype_win;
-    e.xclient.format = 8;
+		XEvent e;
+		Atom atom1 = XInternAtom(tech_pvt->SkypiaxHandles.disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False);
+		memset(&e, 0, sizeof(e));
+		e.xclient.type = ClientMessage;
+		e.xclient.message_type = atom1;	/*  leading message */
+		e.xclient.display = tech_pvt->SkypiaxHandles.disp;
+		e.xclient.window = tech_pvt->SkypiaxHandles.skype_win;
+		e.xclient.format = 8;
 
-    XSendEvent(tech_pvt->SkypiaxHandles.disp, tech_pvt->SkypiaxHandles.win, False, 0, &e);
-    XSync(tech_pvt->SkypiaxHandles.disp, False);
+		XSendEvent(tech_pvt->SkypiaxHandles.disp, tech_pvt->SkypiaxHandles.win, False, 0, &e);
+		XSync(tech_pvt->SkypiaxHandles.disp, False);
 #endif
-  }
+	}
 
-  while (x) {                  
-    x--;
-    switch_yield(20000);
-  }
+	while (x) {
+		x--;
+		switch_yield(20000);
+	}
 
-  if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_signaling_thread) {
-    switch_thread_join(&status,
-                       globals.SKYPIAX_INTERFACES[interface_id].skypiax_signaling_thread);
-  }
+	if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_signaling_thread) {
+		switch_thread_join(&status, globals.SKYPIAX_INTERFACES[interface_id].skypiax_signaling_thread);
+	}
 
-  if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread) {
-    switch_thread_join(&status,
-                       globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread);
-  }
+	if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread) {
+		switch_thread_join(&status, globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread);
+	}
 
-  switch_mutex_lock(globals.mutex);
-  if(globals.sk_console == &globals.SKYPIAX_INTERFACES[interface_id]){
-	DEBUGA_SKYPE("interface '%s' no more console\n", SKYPIAX_P_LOG, the_interface);
-	globals.sk_console = NULL;
-  } else {
-	DEBUGA_SKYPE("interface '%s' STILL console\n", SKYPIAX_P_LOG, the_interface);
-  }
-  memset(&globals.SKYPIAX_INTERFACES[interface_id], '\0', sizeof(private_t));
-  globals.real_interfaces--;
-  switch_mutex_unlock(globals.mutex);
+	switch_mutex_lock(globals.mutex);
+	if (globals.sk_console == &globals.SKYPIAX_INTERFACES[interface_id]) {
+		DEBUGA_SKYPE("interface '%s' no more console\n", SKYPIAX_P_LOG, the_interface);
+		globals.sk_console = NULL;
+	} else {
+		DEBUGA_SKYPE("interface '%s' STILL console\n", SKYPIAX_P_LOG, the_interface);
+	}
+	memset(&globals.SKYPIAX_INTERFACES[interface_id], '\0', sizeof(private_t));
+	globals.real_interfaces--;
+	switch_mutex_unlock(globals.mutex);
 
-  DEBUGA_SKYPE("interface '%s' deleted successfully\n", SKYPIAX_P_LOG,
-               the_interface);
-  globals.SKYPIAX_INTERFACES[interface_id].running=1;
-end:
-  //running = 1;
-  return SWITCH_STATUS_SUCCESS;
+	DEBUGA_SKYPE("interface '%s' deleted successfully\n", SKYPIAX_P_LOG, the_interface);
+	globals.SKYPIAX_INTERFACES[interface_id].running = 1;
+  end:
+	//running = 1;
+	return SWITCH_STATUS_SUCCESS;
 }
 
 /* END: Changes here */
@@ -374,1659 +354,1561 @@
    returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next
    so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it.
 */
-static switch_status_t channel_on_init(switch_core_session_t * session)
+static switch_status_t channel_on_init(switch_core_session_t *session)
 {
-  switch_channel_t *channel;
-  private_t *tech_pvt = NULL;
+	switch_channel_t *channel;
+	private_t *tech_pvt = NULL;
 
-  tech_pvt = switch_core_session_get_private(session);
-  switch_assert(tech_pvt != NULL);
+	tech_pvt = switch_core_session_get_private(session);
+	switch_assert(tech_pvt != NULL);
 
-  channel = switch_core_session_get_channel(session);
-  switch_assert(channel != NULL);
-  switch_set_flag_locked(tech_pvt, TFLAG_IO);
+	channel = switch_core_session_get_channel(session);
+	switch_assert(channel != NULL);
+	switch_set_flag_locked(tech_pvt, TFLAG_IO);
 
-  /* Move channel's state machine to ROUTING. This means the call is trying
-     to get from the initial start where the call because, to the point
-     where a destination has been identified. If the channel is simply
-     left in the initial state, nothing will happen. */
-  switch_channel_set_state(channel, CS_ROUTING);
-  switch_mutex_lock(globals.mutex);
-  globals.calls++;
+	/* Move channel's state machine to ROUTING. This means the call is trying
+	   to get from the initial start where the call because, to the point
+	   where a destination has been identified. If the channel is simply
+	   left in the initial state, nothing will happen. */
+	switch_channel_set_state(channel, CS_ROUTING);
+	switch_mutex_lock(globals.mutex);
+	globals.calls++;
 
-  switch_mutex_unlock(globals.mutex);
+	switch_mutex_unlock(globals.mutex);
 
-  DEBUGA_SKYPE("%s CHANNEL INIT\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
-  return SWITCH_STATUS_SUCCESS;
+	DEBUGA_SKYPE("%s CHANNEL INIT\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
+	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t channel_on_destroy(switch_core_session_t * session)
+static switch_status_t channel_on_destroy(switch_core_session_t *session)
 {
-  //switch_channel_t *channel = NULL;
-  private_t *tech_pvt = NULL;
+	private_t *tech_pvt = NULL;
 
-  //channel = switch_core_session_get_channel(session);
-  //switch_assert(channel != NULL);
+	tech_pvt = switch_core_session_get_private(session);
 
-  tech_pvt = switch_core_session_get_private(session);
+	if (tech_pvt) {
+		if (switch_core_codec_ready(&tech_pvt->read_codec)) {
+			switch_core_codec_destroy(&tech_pvt->read_codec);
+		}
 
-  if (tech_pvt) {
-    if (switch_core_codec_ready(&tech_pvt->read_codec)) {
-      switch_core_codec_destroy(&tech_pvt->read_codec);
-    }
+		if (switch_core_codec_ready(&tech_pvt->write_codec)) {
+			switch_core_codec_destroy(&tech_pvt->write_codec);
+		}
+		switch_core_session_set_private(session, NULL);
+	}
 
-    if (switch_core_codec_ready(&tech_pvt->write_codec)) {
-      switch_core_codec_destroy(&tech_pvt->write_codec);
-    }
-  }
-
-  return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t channel_on_hangup(switch_core_session_t * session)
+static switch_status_t channel_on_hangup(switch_core_session_t *session)
 {
-  switch_channel_t *channel = NULL;
-  private_t *tech_pvt = NULL;
-  char msg_to_skype[256];
+	switch_channel_t *channel = NULL;
+	private_t *tech_pvt = NULL;
+	char msg_to_skype[256];
 
-  channel = switch_core_session_get_channel(session);
-  switch_assert(channel != NULL);
+	channel = switch_core_session_get_channel(session);
+	switch_assert(channel != NULL);
 
-  tech_pvt = switch_core_session_get_private(session);
-  switch_assert(tech_pvt != NULL);
+	tech_pvt = switch_core_session_get_private(session);
+	switch_assert(tech_pvt != NULL);
 
-  switch_clear_flag_locked(tech_pvt, TFLAG_IO);
-  switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
-  //switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
+	switch_clear_flag_locked(tech_pvt, TFLAG_IO);
+	switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
+	//switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
 
-  if (strlen(tech_pvt->skype_call_id)) {
-    //switch_thread_cond_signal(tech_pvt->cond);
-    DEBUGA_SKYPE("hanging up skype call: %s\n", SKYPIAX_P_LOG, tech_pvt->skype_call_id);
-    sprintf(msg_to_skype, "ALTER CALL %s HANGUP", tech_pvt->skype_call_id);
-    skypiax_signaling_write(tech_pvt, msg_to_skype);
-  }
+	if (strlen(tech_pvt->skype_call_id)) {
+		//switch_thread_cond_signal(tech_pvt->cond);
+		DEBUGA_SKYPE("hanging up skype call: %s\n", SKYPIAX_P_LOG, tech_pvt->skype_call_id);
+		sprintf(msg_to_skype, "ALTER CALL %s HANGUP", tech_pvt->skype_call_id);
+		skypiax_signaling_write(tech_pvt, msg_to_skype);
+	}
+	//memset(tech_pvt->session_uuid_str, '\0', sizeof(tech_pvt->session_uuid_str));
+	*tech_pvt->session_uuid_str = '\0';
+	DEBUGA_SKYPE("%s CHANNEL HANGUP\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
+	switch_mutex_lock(globals.mutex);
+	globals.calls--;
+	if (globals.calls < 0) {
+		globals.calls = 0;
+	}
+	switch_mutex_unlock(globals.mutex);
 
-  memset(tech_pvt->session_uuid_str, '\0', sizeof(tech_pvt->session_uuid_str));
-  DEBUGA_SKYPE("%s CHANNEL HANGUP\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
-  switch_mutex_lock(globals.mutex);
-  globals.calls--;
-  if (globals.calls < 0) {
-    globals.calls = 0;
-  }
-  switch_mutex_unlock(globals.mutex);
-
-  return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t channel_on_routing(switch_core_session_t * session)
+static switch_status_t channel_on_routing(switch_core_session_t *session)
 {
-  switch_channel_t *channel = NULL;
-  private_t *tech_pvt = NULL;
+	switch_channel_t *channel = NULL;
+	private_t *tech_pvt = NULL;
 
-  channel = switch_core_session_get_channel(session);
-  switch_assert(channel != NULL);
+	channel = switch_core_session_get_channel(session);
+	switch_assert(channel != NULL);
 
-  tech_pvt = switch_core_session_get_private(session);
-  switch_assert(tech_pvt != NULL);
+	tech_pvt = switch_core_session_get_private(session);
+	switch_assert(tech_pvt != NULL);
 
-  DEBUGA_SKYPE("%s CHANNEL ROUTING\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
+	DEBUGA_SKYPE("%s CHANNEL ROUTING\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
 
-  return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t channel_on_execute(switch_core_session_t * session)
+static switch_status_t channel_on_execute(switch_core_session_t *session)
 {
 
-  switch_channel_t *channel = NULL;
-  private_t *tech_pvt = NULL;
+	switch_channel_t *channel = NULL;
+	private_t *tech_pvt = NULL;
 
-  channel = switch_core_session_get_channel(session);
-  switch_assert(channel != NULL);
+	channel = switch_core_session_get_channel(session);
+	switch_assert(channel != NULL);
 
-  tech_pvt = switch_core_session_get_private(session);
-  switch_assert(tech_pvt != NULL);
+	tech_pvt = switch_core_session_get_private(session);
+	switch_assert(tech_pvt != NULL);
 
-  DEBUGA_SKYPE("%s CHANNEL EXECUTE\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
+	DEBUGA_SKYPE("%s CHANNEL EXECUTE\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
 
-  return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t channel_kill_channel(switch_core_session_t * session, int sig)
+static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig)
 {
-  switch_channel_t *channel = NULL;
-  private_t *tech_pvt = NULL;
+	switch_channel_t *channel = NULL;
+	private_t *tech_pvt = NULL;
 
-  channel = switch_core_session_get_channel(session);
-  switch_assert(channel != NULL);
+	channel = switch_core_session_get_channel(session);
+	switch_assert(channel != NULL);
 
-  tech_pvt = switch_core_session_get_private(session);
-  switch_assert(tech_pvt != NULL);
+	tech_pvt = switch_core_session_get_private(session);
+	switch_assert(tech_pvt != NULL);
 
-  switch (sig) {
-  case SWITCH_SIG_KILL:
-    DEBUGA_SKYPE("%s CHANNEL got SWITCH_SIG_KILL\n", SKYPIAX_P_LOG,
-                 switch_channel_get_name(channel));
-    switch_clear_flag_locked(tech_pvt, TFLAG_IO);
-    switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
-    switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
-    break;
-  case SWITCH_SIG_BREAK:
-    DEBUGA_SKYPE("%s CHANNEL got SWITCH_SIG_BREAK\n", SKYPIAX_P_LOG,
-                 switch_channel_get_name(channel));
-    switch_set_flag_locked(tech_pvt, TFLAG_BREAK);
-    break;
-  default:
-    break;
-  }
+	switch (sig) {
+	case SWITCH_SIG_KILL:
+		DEBUGA_SKYPE("%s CHANNEL got SWITCH_SIG_KILL\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
+		switch_clear_flag_locked(tech_pvt, TFLAG_IO);
+		switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
+		switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
+		break;
+	case SWITCH_SIG_BREAK:
+		DEBUGA_SKYPE("%s CHANNEL got SWITCH_SIG_BREAK\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
+		switch_set_flag_locked(tech_pvt, TFLAG_BREAK);
+		break;
+	default:
+		break;
+	}
 
-  return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t channel_on_exchange_media(switch_core_session_t * session)
+static switch_status_t channel_on_exchange_media(switch_core_session_t *session)
 {
-  private_t *tech_pvt = NULL;
-  DEBUGA_SKYPE("CHANNEL LOOPBACK\n", SKYPIAX_P_LOG);
-  return SWITCH_STATUS_SUCCESS;
+	private_t *tech_pvt = NULL;
+	DEBUGA_SKYPE("CHANNEL LOOPBACK\n", SKYPIAX_P_LOG);
+	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t channel_on_soft_execute(switch_core_session_t * session)
+static switch_status_t channel_on_soft_execute(switch_core_session_t *session)
 {
-  private_t *tech_pvt = NULL;
-  DEBUGA_SKYPE("CHANNEL TRANSMIT\n", SKYPIAX_P_LOG);
-  return SWITCH_STATUS_SUCCESS;
+	private_t *tech_pvt = NULL;
+	DEBUGA_SKYPE("CHANNEL TRANSMIT\n", SKYPIAX_P_LOG);
+	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t channel_send_dtmf(switch_core_session_t * session,
-                                         const switch_dtmf_t * dtmf)
+static switch_status_t channel_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf)
 {
-  private_t *tech_pvt = switch_core_session_get_private(session);
-  switch_assert(tech_pvt != NULL);
+	private_t *tech_pvt = switch_core_session_get_private(session);
+	switch_assert(tech_pvt != NULL);
 
-  DEBUGA_SKYPE("DTMF: %c\n", SKYPIAX_P_LOG, dtmf->digit);
+	DEBUGA_SKYPE("DTMF: %c\n", SKYPIAX_P_LOG, dtmf->digit);
 
-  skypiax_senddigit(tech_pvt, dtmf->digit);
+	skypiax_senddigit(tech_pvt, dtmf->digit);
 
-  return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t channel_read_frame(switch_core_session_t * session,
-                                          switch_frame_t ** frame, switch_io_flag_t flags,
-                                          int stream_id)
+static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
 {
-  switch_channel_t *channel = NULL;
-  private_t *tech_pvt = NULL;
-  switch_byte_t *data;
+	switch_channel_t *channel = NULL;
+	private_t *tech_pvt = NULL;
+	switch_byte_t *data;
 
-  channel = switch_core_session_get_channel(session);
-  switch_assert(channel != NULL);
+	channel = switch_core_session_get_channel(session);
+	switch_assert(channel != NULL);
 
-  tech_pvt = switch_core_session_get_private(session);
-  switch_assert(tech_pvt != NULL);
-  tech_pvt->read_frame.flags = SFF_NONE;
-  *frame = NULL;
+	tech_pvt = switch_core_session_get_private(session);
+	switch_assert(tech_pvt != NULL);
 
-  if (!skypiax_audio_read(tech_pvt)) {
+	if (!switch_channel_ready(channel) || !switch_test_flag(tech_pvt, TFLAG_IO)) {
+		ERRORA("CIAPA \n", SKYPIAX_P_LOG);
+		return SWITCH_STATUS_FALSE;
+	}
 
-    ERRORA("skypiax_audio_read ERROR\n", SKYPIAX_P_LOG);
+	tech_pvt->read_frame.flags = SFF_NONE;
+	*frame = NULL;
 
-  } else {
-    switch_set_flag_locked(tech_pvt, TFLAG_VOICE);
-  }
+	if (!skypiax_audio_read(tech_pvt)) {
 
-  while (switch_test_flag(tech_pvt, TFLAG_IO)) {
-    if (switch_test_flag(tech_pvt, TFLAG_BREAK)) {
-      switch_clear_flag(tech_pvt, TFLAG_BREAK);
-      DEBUGA_SKYPE("CHANNEL READ FRAME goto CNG\n", SKYPIAX_P_LOG);
-      goto cng;
-    }
+		ERRORA("skypiax_audio_read ERROR\n", SKYPIAX_P_LOG);
 
-    if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
-      DEBUGA_SKYPE("CHANNEL READ FRAME not IO\n", SKYPIAX_P_LOG);
-      return SWITCH_STATUS_FALSE;
-    }
+	} else {
+		switch_set_flag_locked(tech_pvt, TFLAG_VOICE);
+	}
 
-    if (switch_test_flag(tech_pvt, TFLAG_IO) && switch_test_flag(tech_pvt, TFLAG_VOICE)) {
-      switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
-      if (!tech_pvt->read_frame.datalen) {
-        DEBUGA_SKYPE("CHANNEL READ CONTINUE\n", SKYPIAX_P_LOG);
-        continue;
-      }
-      *frame = &tech_pvt->read_frame;
+	while (switch_test_flag(tech_pvt, TFLAG_IO)) {
+		if (switch_test_flag(tech_pvt, TFLAG_BREAK)) {
+			switch_clear_flag(tech_pvt, TFLAG_BREAK);
+			DEBUGA_SKYPE("CHANNEL READ FRAME goto CNG\n", SKYPIAX_P_LOG);
+			goto cng;
+		}
+
+		if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
+			DEBUGA_SKYPE("CHANNEL READ FRAME not IO\n", SKYPIAX_P_LOG);
+			return SWITCH_STATUS_FALSE;
+		}
+
+		if (switch_test_flag(tech_pvt, TFLAG_IO) && switch_test_flag(tech_pvt, TFLAG_VOICE)) {
+			switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
+			if (!tech_pvt->read_frame.datalen) {
+				DEBUGA_SKYPE("CHANNEL READ CONTINUE\n", SKYPIAX_P_LOG);
+				continue;
+			}
+			*frame = &tech_pvt->read_frame;
 #ifdef BIGENDIAN
-      if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) {
-        switch_swap_linear((*frame)->data, (int) (*frame)->datalen / 2);
-      }
+			if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) {
+				switch_swap_linear((*frame)->data, (int) (*frame)->datalen / 2);
+			}
 #endif
-      return SWITCH_STATUS_SUCCESS;
-    }
+			return SWITCH_STATUS_SUCCESS;
+		}
 
-    DEBUGA_SKYPE("CHANNEL READ no TFLAG_IO\n", SKYPIAX_P_LOG);
-    return SWITCH_STATUS_FALSE;
+		DEBUGA_SKYPE("CHANNEL READ no TFLAG_IO\n", SKYPIAX_P_LOG);
+		return SWITCH_STATUS_FALSE;
 
-  }
+	}
 
-  DEBUGA_SKYPE("CHANNEL READ FALSE\n", SKYPIAX_P_LOG);
-  return SWITCH_STATUS_FALSE;
+	DEBUGA_SKYPE("CHANNEL READ FALSE\n", SKYPIAX_P_LOG);
+	return SWITCH_STATUS_FALSE;
 
-cng:
-  data = (switch_byte_t *) tech_pvt->read_frame.data;
-  data[0] = 65;
-  data[1] = 0;
-  tech_pvt->read_frame.datalen = 2;
-  tech_pvt->read_frame.flags = SFF_CNG;
-  *frame = &tech_pvt->read_frame;
-  return SWITCH_STATUS_SUCCESS;
+  cng:
+	data = (switch_byte_t *) tech_pvt->read_frame.data;
+	data[0] = 65;
+	data[1] = 0;
+	tech_pvt->read_frame.datalen = 2;
+	tech_pvt->read_frame.flags = SFF_CNG;
+	*frame = &tech_pvt->read_frame;
+	return SWITCH_STATUS_SUCCESS;
 
 }
 
-static switch_status_t channel_write_frame(switch_core_session_t * session,
-                                           switch_frame_t * frame, switch_io_flag_t flags,
-                                           int stream_id)
+static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)
 {
-  switch_channel_t *channel = NULL;
-  private_t *tech_pvt = NULL;
-  unsigned int sent;
+	switch_channel_t *channel = NULL;
+	private_t *tech_pvt = NULL;
+	unsigned int sent;
 
-  channel = switch_core_session_get_channel(session);
-  switch_assert(channel != NULL);
+	channel = switch_core_session_get_channel(session);
+	switch_assert(channel != NULL);
 
-  tech_pvt = switch_core_session_get_private(session);
-  switch_assert(tech_pvt != NULL);
+	tech_pvt = switch_core_session_get_private(session);
+	switch_assert(tech_pvt != NULL);
 
-  if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
-    ERRORA("CIAPA \n", SKYPIAX_P_LOG);
-    return SWITCH_STATUS_FALSE;
-  }
+	if (!switch_channel_ready(channel) || !switch_test_flag(tech_pvt, TFLAG_IO)) {
+		ERRORA("CIAPA \n", SKYPIAX_P_LOG);
+		return SWITCH_STATUS_FALSE;
+	}
 #ifdef BIGENDIAN
-  if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) {
-    switch_swap_linear(frame->data, (int) frame->datalen / 2);
-  }
+	if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) {
+		switch_swap_linear(frame->data, (int) frame->datalen / 2);
+	}
 #endif
 
-  sent = frame->datalen;
+	sent = frame->datalen;
 #ifdef WIN32
-  switch_file_write(tech_pvt->audioskypepipe[1], frame->data, &sent);
+	switch_file_write(tech_pvt->audioskypepipe[1], frame->data, &sent);
 #else /* WIN32 */
-  sent = write(tech_pvt->audioskypepipe[1], frame->data, sent);
+	sent = write(tech_pvt->audioskypepipe[1], frame->data, sent);
 #endif /* WIN32 */
-  if (sent != frame->datalen && sent != -1) {
-    DEBUGA_SKYPE("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);
+	}
 
-  return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t channel_answer_channel(switch_core_session_t * session)
+static switch_status_t channel_answer_channel(switch_core_session_t *session)
 {
-  private_t *tech_pvt;
-  switch_channel_t *channel = NULL;
+	private_t *tech_pvt;
+	switch_channel_t *channel = NULL;
 
-  channel = switch_core_session_get_channel(session);
-  switch_assert(channel != NULL);
+	channel = switch_core_session_get_channel(session);
+	switch_assert(channel != NULL);
 
-  tech_pvt = switch_core_session_get_private(session);
-  switch_assert(tech_pvt != NULL);
+	tech_pvt = switch_core_session_get_private(session);
+	switch_assert(tech_pvt != NULL);
 
-  DEBUGA_SKYPE("ANSWERED! \n", SKYPIAX_P_LOG);
+	DEBUGA_SKYPE("ANSWERED! \n", SKYPIAX_P_LOG);
 
-  return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t channel_receive_message(switch_core_session_t * session,
-                                               switch_core_session_message_t * msg)
+static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg)
 {
-  switch_channel_t *channel;
-  private_t *tech_pvt;
+	switch_channel_t *channel;
+	private_t *tech_pvt;
 
-  channel = switch_core_session_get_channel(session);
-  switch_assert(channel != NULL);
+	channel = switch_core_session_get_channel(session);
+	switch_assert(channel != NULL);
 
-  tech_pvt = (private_t *) switch_core_session_get_private(session);
-  switch_assert(tech_pvt != NULL);
+	tech_pvt = (private_t *) switch_core_session_get_private(session);
+	switch_assert(tech_pvt != NULL);
 
-  switch (msg->message_id) {
-  case SWITCH_MESSAGE_INDICATE_ANSWER:
-    {
-      DEBUGA_SKYPE("MSG_ID=%d, TO BE ANSWERED!\n", SKYPIAX_P_LOG, msg->message_id);
-      channel_answer_channel(session);
-    }
-    break;
-  default:
-    {
-      DEBUGA_SKYPE("MSG_ID=%d\n", SKYPIAX_P_LOG, msg->message_id);
-    }
-    break;
-  }
+	switch (msg->message_id) {
+	case SWITCH_MESSAGE_INDICATE_ANSWER:
+		{
+			DEBUGA_SKYPE("MSG_ID=%d, TO BE ANSWERED!\n", SKYPIAX_P_LOG, msg->message_id);
+			channel_answer_channel(session);
+		}
+		break;
+	default:
+		{
+			DEBUGA_SKYPE("MSG_ID=%d\n", SKYPIAX_P_LOG, msg->message_id);
+		}
+		break;
+	}
 
-  return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t channel_receive_event(switch_core_session_t * session,
-                                             switch_event_t * event)
+static switch_status_t channel_receive_event(switch_core_session_t *session, switch_event_t *event)
 {
-  struct private_object *tech_pvt = switch_core_session_get_private(session);
-  char *body = switch_event_get_body(event);
-  switch_assert(tech_pvt != NULL);
+	struct private_object *tech_pvt = switch_core_session_get_private(session);
+	char *body = switch_event_get_body(event);
+	switch_assert(tech_pvt != NULL);
 
-  if (!body) {
-    body = "";
-  }
+	if (!body) {
+		body = "";
+	}
 
-  WARNINGA("event: |||%s|||\n", SKYPIAX_P_LOG, body);
+	WARNINGA("event: |||%s|||\n", SKYPIAX_P_LOG, body);
 
-  return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
 switch_state_handler_table_t skypiax_state_handlers = {
-  /*.on_init */ channel_on_init,
-  /*.on_routing */ channel_on_routing,
-  /*.on_execute */ channel_on_execute,
-  /*.on_hangup */ channel_on_hangup,
-  /*.on_exchange_media */ channel_on_exchange_media,
-  /*.on_soft_execute */ channel_on_soft_execute,
-  /*.on_consume_media */ NULL,
-  /*.on_hibernate */ NULL,
-  /*.on_reset */ NULL,
-  /*.on_park */ NULL,
-  /*.on_reporting */ NULL,
-  /*.on_destroy */ channel_on_destroy
+	/*.on_init */ channel_on_init,
+	/*.on_routing */ channel_on_routing,
+	/*.on_execute */ channel_on_execute,
+	/*.on_hangup */ channel_on_hangup,
+	/*.on_exchange_media */ channel_on_exchange_media,
+	/*.on_soft_execute */ channel_on_soft_execute,
+	/*.on_consume_media */ NULL,
+	/*.on_hibernate */ NULL,
+	/*.on_reset */ NULL,
+	/*.on_park */ NULL,
+	/*.on_reporting */ NULL,
+	/*.on_destroy */ channel_on_destroy
 };
 
 switch_io_routines_t skypiax_io_routines = {
-  /*.outgoing_channel */ channel_outgoing_channel,
-  /*.read_frame */ channel_read_frame,
-  /*.write_frame */ channel_write_frame,
-  /*.kill_channel */ channel_kill_channel,
-  /*.send_dtmf */ channel_send_dtmf,
-  /*.receive_message */ channel_receive_message,
-  /*.receive_event */ channel_receive_event
+	/*.outgoing_channel */ channel_outgoing_channel,
+	/*.read_frame */ channel_read_frame,
+	/*.write_frame */ channel_write_frame,
+	/*.kill_channel */ channel_kill_channel,
+	/*.send_dtmf */ channel_send_dtmf,
+	/*.receive_message */ channel_receive_message,
+	/*.receive_event */ channel_receive_event
 };
 
-static switch_call_cause_t channel_outgoing_channel(switch_core_session_t * session,
-                                                    switch_event_t * var_event,
-                                                    switch_caller_profile_t *
-                                                    outbound_profile,
-                                                    switch_core_session_t ** new_session,
-                                                    switch_memory_pool_t ** pool,
-                                                    switch_originate_flag_t flags)
+static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
+													switch_event_t *var_event,
+													switch_caller_profile_t *outbound_profile,
+													switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags)
 {
-  if ((*new_session =
-       switch_core_session_request(skypiax_endpoint_interface,
-                                   SWITCH_CALL_DIRECTION_OUTBOUND, pool)) != 0) {
-    private_t *tech_pvt;
-    switch_channel_t *channel;
-    switch_caller_profile_t *caller_profile;
-    char *rdest;
+	if ((*new_session = switch_core_session_request(skypiax_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, pool)) != 0) {
+		private_t *tech_pvt = NULL;
+		switch_channel_t *channel;
+		switch_caller_profile_t *caller_profile;
+		char *rdest;
+		int found = 0;
+		char interface_name[256];
 
-    switch_core_session_add_stream(*new_session, NULL);
+		switch_core_session_add_stream(*new_session, NULL);
 
-    if ((tech_pvt =
-         (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) {
-      int found = 0;
-      char interface_name[256];
 
-      if (!switch_strlen_zero(outbound_profile->destination_number)) {
-        int i;
-        char *slash;
+		if (!switch_strlen_zero(outbound_profile->destination_number)) {
+			int i;
+			char *slash;
 
-        switch_copy_string(interface_name, outbound_profile->destination_number, 255);
-        slash = strrchr(interface_name, '/');
-        *slash = '\0';
+			switch_copy_string(interface_name, outbound_profile->destination_number, 255);
+			slash = strrchr(interface_name, '/');
+			*slash = '\0';
 
-  switch_mutex_lock(globals.mutex);
-        if (strncmp("ANY", interface_name, strlen(interface_name)) == 0) {
-          /* we've been asked for the "ANY" interface, let's find the first idle interface */
-          DEBUGA_SKYPE("Finding one available skype interface\n", SKYPIAX_P_LOG);
-          tech_pvt = find_available_skypiax_interface(NULL);
-          if (tech_pvt) found = 1;
-        } else if(strncmp("RR", interface_name, strlen(interface_name)) == 0) {
-          /* Find the first idle interface using Round Robin */
-          DEBUGA_SKYPE("Finding one available skype interface RR\n", SKYPIAX_P_LOG);
-          tech_pvt = find_available_skypiax_interface_rr();
-          if (tech_pvt) found = 1;
-        }
+			switch_mutex_lock(globals.mutex);
+			if (strncmp("ANY", interface_name, strlen(interface_name)) == 0) {
+				/* we've been asked for the "ANY" interface, let's find the first idle interface */
+				DEBUGA_SKYPE("Finding one available skype interface\n", SKYPIAX_P_LOG);
+				tech_pvt = find_available_skypiax_interface(NULL);
+				if (tech_pvt)
+					found = 1;
+			} else if (strncmp("RR", interface_name, strlen(interface_name)) == 0) {
+				/* Find the first idle interface using Round Robin */
+				DEBUGA_SKYPE("Finding one available skype interface RR\n", SKYPIAX_P_LOG);
+				tech_pvt = find_available_skypiax_interface_rr();
+				if (tech_pvt)
+					found = 1;
+			}
 
-        for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
-          /* we've been asked for a normal interface name, or we have not found idle interfaces to serve as the "ANY" interface */
-          if (strlen(globals.SKYPIAX_INTERFACES[i].name)
-              &&
-              (strncmp
-               (globals.SKYPIAX_INTERFACES[i].name, interface_name,
-                strlen(interface_name)) == 0)) {
-            if (strlen(globals.SKYPIAX_INTERFACES[i].session_uuid_str)) {
-              DEBUGA_SKYPE
-                ("globals.SKYPIAX_INTERFACES[%d].name=|||%s||| session_uuid_str=|||%s||| is BUSY\n",
-                 SKYPIAX_P_LOG, i, globals.SKYPIAX_INTERFACES[i].name,
-                 globals.SKYPIAX_INTERFACES[i].session_uuid_str);
-              switch_core_session_destroy(new_session);
-  switch_mutex_unlock(globals.mutex);
-              return SWITCH_CAUSE_NORMAL_TEMPORARY_FAILURE;
-            }
+			for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
+				/* we've been asked for a normal interface name, or we have not found idle interfaces to serve as the "ANY" interface */
+				if (strlen(globals.SKYPIAX_INTERFACES[i].name)
+					&& (strncmp(globals.SKYPIAX_INTERFACES[i].name, interface_name, strlen(interface_name)) == 0)) {
+					if (strlen(globals.SKYPIAX_INTERFACES[i].session_uuid_str)) {
+						DEBUGA_SKYPE
+							("globals.SKYPIAX_INTERFACES[%d].name=|||%s||| session_uuid_str=|||%s||| is BUSY\n",
+							 SKYPIAX_P_LOG, i, globals.SKYPIAX_INTERFACES[i].name, globals.SKYPIAX_INTERFACES[i].session_uuid_str);
+						switch_core_session_destroy(new_session);
+						switch_mutex_unlock(globals.mutex);
+						return SWITCH_CAUSE_NORMAL_TEMPORARY_FAILURE;
+					}
 
-            DEBUGA_SKYPE("globals.SKYPIAX_INTERFACES[%d].name=|||%s|||?\n", SKYPIAX_P_LOG,
-                         i, globals.SKYPIAX_INTERFACES[i].name);
-            tech_pvt = &globals.SKYPIAX_INTERFACES[i];
-            found = 1;
-            break;
-          }
+					DEBUGA_SKYPE("globals.SKYPIAX_INTERFACES[%d].name=|||%s|||?\n", SKYPIAX_P_LOG, i, globals.SKYPIAX_INTERFACES[i].name);
+					tech_pvt = &globals.SKYPIAX_INTERFACES[i];
+					found = 1;
+					break;
+				}
 
-        }
+			}
 
-      } else {
-        ERRORA("Doh! no destination number?\n", SKYPIAX_P_LOG);
-        switch_core_session_destroy(new_session);
-        return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
-      }
+		} else {
+			ERRORA("Doh! no destination number?\n", SKYPIAX_P_LOG);
+			switch_core_session_destroy(new_session);
+			return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+		}
 
-      if (!found) {
-        ERRORA("Doh! no matching interface for |||%s|||?\n", SKYPIAX_P_LOG,
-               interface_name);
-        switch_core_session_destroy(new_session);
-  switch_mutex_unlock(globals.mutex);
-        return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+		if (!found) {
+			ERRORA("Doh! no matching interface for |||%s|||?\n", SKYPIAX_P_LOG, interface_name);
+			switch_core_session_destroy(new_session);
+			switch_mutex_unlock(globals.mutex);
+			return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+		}
 
-      }
-      channel = switch_core_session_get_channel(*new_session);
-      skypiax_tech_init(tech_pvt, *new_session);
-    } else {
-      ERRORA("Hey where is my memory pool?\n", SKYPIAX_P_LOG);
-      switch_core_session_destroy(new_session);
-      return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
-    }
+		channel = switch_core_session_get_channel(*new_session);
+		skypiax_tech_init(tech_pvt, *new_session);
 
-    if (outbound_profile) {
-      char name[128];
 
-      snprintf(name, sizeof(name), "skypiax/%s", outbound_profile->destination_number);
-      //snprintf(name, sizeof(name), "skypiax/%s", tech_pvt->name);
-      switch_channel_set_name(channel, name);
-      caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
-      switch_channel_set_caller_profile(channel, caller_profile);
-      tech_pvt->caller_profile = caller_profile;
-    } else {
-      ERRORA("Doh! no caller profile\n", SKYPIAX_P_LOG);
-      switch_core_session_destroy(new_session);
-  switch_mutex_unlock(globals.mutex);
-      return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
-    }
+		if (outbound_profile) {
+			char name[128];
 
-    rdest = strchr(caller_profile->destination_number, '/');
-    *rdest++ = '\0';
+			snprintf(name, sizeof(name), "skypiax/%s", outbound_profile->destination_number);
+			//snprintf(name, sizeof(name), "skypiax/%s", tech_pvt->name);
+			switch_channel_set_name(channel, name);
+			caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
+			switch_channel_set_caller_profile(channel, caller_profile);
+			tech_pvt->caller_profile = caller_profile;
+		} else {
+			ERRORA("Doh! no caller profile\n", SKYPIAX_P_LOG);
+			switch_core_session_destroy(new_session);
+			switch_mutex_unlock(globals.mutex);
+			return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+		}
 
-    skypiax_call(tech_pvt, rdest, 30);
+		rdest = strchr(caller_profile->destination_number, '/');
+		*rdest++ = '\0';
 
-    switch_copy_string(tech_pvt->session_uuid_str,
-                       switch_core_session_get_uuid(*new_session),
-                       sizeof(tech_pvt->session_uuid_str));
-    caller_profile = tech_pvt->caller_profile;
-    caller_profile->destination_number = rdest;
+		skypiax_call(tech_pvt, rdest, 30);
 
-    switch_channel_set_flag(channel, CF_OUTBOUND);
-    switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
-    switch_channel_set_state(channel, CS_INIT);
-  switch_mutex_unlock(globals.mutex);
-    return SWITCH_CAUSE_SUCCESS;
-  }
+		switch_copy_string(tech_pvt->session_uuid_str, switch_core_session_get_uuid(*new_session), sizeof(tech_pvt->session_uuid_str));
+		caller_profile = tech_pvt->caller_profile;
+		caller_profile->destination_number = rdest;
 
-  return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+		switch_channel_set_flag(channel, CF_OUTBOUND);
+		switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
+		switch_channel_set_state(channel, CS_INIT);
+		switch_mutex_unlock(globals.mutex);
+		return SWITCH_CAUSE_SUCCESS;
+	}
+
+	return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
 }
 
 /*!
  * \brief This thread runs during a call, and monitor the interface for signaling, like hangup, caller id, etc most of signaling is handled inside the skypiax_signaling_read function
  *
  */
-static void *SWITCH_THREAD_FUNC skypiax_signaling_thread_func(switch_thread_t * thread,
-                                                              void *obj)
+static void *SWITCH_THREAD_FUNC skypiax_signaling_thread_func(switch_thread_t * thread, void *obj)
 {
-  private_t *tech_pvt = obj;
-  int res;
-  int forever = 1;
+	private_t *tech_pvt = obj;
+	int res;
+	int forever = 1;
 
-  if (!tech_pvt) return NULL;
+	if (!tech_pvt)
+		return NULL;
 
-  DEBUGA_SKYPE("In skypiax_signaling_thread_func: started, p=%p\n", SKYPIAX_P_LOG,
-               (void *) tech_pvt);
+	DEBUGA_SKYPE("In skypiax_signaling_thread_func: started, p=%p\n", SKYPIAX_P_LOG, (void *) tech_pvt);
 
-  while (forever) {
-    if (!(running && tech_pvt->running))
-      break;
-    res = skypiax_signaling_read(tech_pvt);
-    if (res == CALLFLOW_INCOMING_HANGUP) {
-      switch_core_session_t *session = NULL;
-      //private_t *tech_pvt = NULL;
-      switch_channel_t *channel = NULL;
+	while (forever) {
+		if (!(running && tech_pvt->running))
+			break;
+		res = skypiax_signaling_read(tech_pvt);
+		if (res == CALLFLOW_INCOMING_HANGUP) {
+			switch_core_session_t *session = NULL;
+			//private_t *tech_pvt = NULL;
+			switch_channel_t *channel = NULL;
 
-      DEBUGA_SKYPE("skype call ended\n", SKYPIAX_P_LOG);
+			DEBUGA_SKYPE("skype call ended\n", SKYPIAX_P_LOG);
 
-      if (tech_pvt) {
-        session = switch_core_session_locate(tech_pvt->session_uuid_str);
+			if (tech_pvt) {
+				session = switch_core_session_locate(tech_pvt->session_uuid_str);
 
-        if (session) {
-          channel = switch_core_session_get_channel(session);
-          if (channel) {
-            switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
-            switch_core_session_rwunlock(session);
-          } else {
-            ERRORA("no channel?\n", SKYPIAX_P_LOG);
-            switch_core_session_rwunlock(session);
-          }
-        } else {
-          DEBUGA_SKYPE("no session\n", SKYPIAX_P_LOG);
-        }
-        tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
-        memset(tech_pvt->session_uuid_str, '\0', sizeof(tech_pvt->session_uuid_str));
-      } else {
-        ERRORA("no tech_pvt?\n", SKYPIAX_P_LOG);
-      }
-    }
-  }
-  return NULL;
+				if (session) {
+					channel = switch_core_session_get_channel(session);
+					if (channel) {
+						switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+						switch_core_session_rwunlock(session);
+					} else {
+						ERRORA("no channel?\n", SKYPIAX_P_LOG);
+						switch_core_session_rwunlock(session);
+					}
+				} else {
+					DEBUGA_SKYPE("no session\n", SKYPIAX_P_LOG);
+				}
+				tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
+				*tech_pvt->session_uuid_str = '\0';
+				//memset(tech_pvt->session_uuid_str, '\0', sizeof(tech_pvt->session_uuid_str));
+			} else {
+				ERRORA("no tech_pvt?\n", SKYPIAX_P_LOG);
+			}
+		}
+	}
+	return NULL;
 }
 
 /* BEGIN: Changes heres */
 static switch_status_t load_config(int reload_type)
 /* END: Changes heres */
 {
-  char *cf = "skypiax.conf";
-  switch_xml_t cfg, xml, global_settings, param, interfaces, myinterface;
-  private_t *tech_pvt = NULL;
+	char *cf = "skypiax.conf";
+	switch_xml_t cfg, xml, global_settings, param, interfaces, myinterface;
+	private_t *tech_pvt = NULL;
 
-  switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, skypiax_module_pool);
-  if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
-    ERRORA("open of %s failed\n", SKYPIAX_P_LOG, cf);
-    running = 0;
-	switch_xml_free(xml);
-    return SWITCH_STATUS_TERM;
-  }
+	switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, skypiax_module_pool);
+	if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
+		ERRORA("open of %s failed\n", SKYPIAX_P_LOG, cf);
+		running = 0;
+		switch_xml_free(xml);
+		return SWITCH_STATUS_TERM;
+	}
 
-  switch_mutex_lock(globals.mutex);
-  if ((global_settings = switch_xml_child(cfg, "global_settings"))) {
-    for (param = switch_xml_child(global_settings, "param"); param; param = param->next) {
-      char *var = (char *) switch_xml_attr_soft(param, "name");
-      char *val = (char *) switch_xml_attr_soft(param, "value");
+	switch_mutex_lock(globals.mutex);
+	if ((global_settings = switch_xml_child(cfg, "global_settings"))) {
+		for (param = switch_xml_child(global_settings, "param"); param; param = param->next) {
+			char *var = (char *) switch_xml_attr_soft(param, "name");
+			char *val = (char *) switch_xml_attr_soft(param, "value");
 
-      if (!strcasecmp(var, "debug")) {
-        DEBUGA_SKYPE("globals.debug=%d\n", SKYPIAX_P_LOG, globals.debug);
-        globals.debug = atoi(val);
-        DEBUGA_SKYPE("globals.debug=%d\n", SKYPIAX_P_LOG, globals.debug);
-      } else if (!strcasecmp(var, "hold-music")) {
-        switch_set_string(globals.hold_music, val);
-        DEBUGA_SKYPE("globals.hold_music=%s\n", SKYPIAX_P_LOG, globals.hold_music);
-      } else if (!strcmp(var, "port")) {
-        globals.port = atoi(val);
-        DEBUGA_SKYPE("globals.port=%d\n", SKYPIAX_P_LOG, globals.port);
-      } else if (!strcmp(var, "codec-master")) {
-        if (!strcasecmp(val, "us")) {
-          switch_set_flag(&globals, GFLAG_MY_CODEC_PREFS);
-        }
-        DEBUGA_SKYPE("codec-master globals.debug=%d\n", SKYPIAX_P_LOG, globals.debug);
-      } else if (!strcmp(var, "dialplan")) {
-        set_global_dialplan(val);
-        DEBUGA_SKYPE("globals.dialplan=%s\n", SKYPIAX_P_LOG, globals.dialplan);
-      } else if (!strcmp(var, "destination")) {
-        set_global_destination(val);
-        DEBUGA_SKYPE("globals.destination=%s\n", SKYPIAX_P_LOG, globals.destination);
-      } else if (!strcmp(var, "context")) {
-        set_global_context(val);
-        DEBUGA_SKYPE("globals.context=%s\n", SKYPIAX_P_LOG, globals.context);
-      } else if (!strcmp(var, "codec-prefs")) {
-        set_global_codec_string(val);
-        DEBUGA_SKYPE("globals.codec_string=%s\n", SKYPIAX_P_LOG, globals.codec_string);
-        globals.codec_order_last =
-          switch_separate_string(globals.codec_string, ',', globals.codec_order,
-                                 SWITCH_MAX_CODECS);
-      } else if (!strcmp(var, "codec-rates")) {
-        set_global_codec_rates_string(val);
-        DEBUGA_SKYPE("globals.codec_rates_string=%s\n", SKYPIAX_P_LOG,
-                     globals.codec_rates_string);
-        globals.codec_rates_last =
-          switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates,
-                                 SWITCH_MAX_CODECS);
-      }
+			if (!strcasecmp(var, "debug")) {
+				DEBUGA_SKYPE("globals.debug=%d\n", SKYPIAX_P_LOG, globals.debug);
+				globals.debug = atoi(val);
+				DEBUGA_SKYPE("globals.debug=%d\n", SKYPIAX_P_LOG, globals.debug);
+			} else if (!strcasecmp(var, "hold-music")) {
+				switch_set_string(globals.hold_music, val);
+				DEBUGA_SKYPE("globals.hold_music=%s\n", SKYPIAX_P_LOG, globals.hold_music);
+			} else if (!strcmp(var, "port")) {
+				globals.port = atoi(val);
+				DEBUGA_SKYPE("globals.port=%d\n", SKYPIAX_P_LOG, globals.port);
+			} else if (!strcmp(var, "codec-master")) {
+				if (!strcasecmp(val, "us")) {
+					switch_set_flag(&globals, GFLAG_MY_CODEC_PREFS);
+				}
+				DEBUGA_SKYPE("codec-master globals.debug=%d\n", SKYPIAX_P_LOG, globals.debug);
+			} else if (!strcmp(var, "dialplan")) {
+				set_global_dialplan(val);
+				DEBUGA_SKYPE("globals.dialplan=%s\n", SKYPIAX_P_LOG, globals.dialplan);
+			} else if (!strcmp(var, "destination")) {
+				set_global_destination(val);
+				DEBUGA_SKYPE("globals.destination=%s\n", SKYPIAX_P_LOG, globals.destination);
+			} else if (!strcmp(var, "context")) {
+				set_global_context(val);
+				DEBUGA_SKYPE("globals.context=%s\n", SKYPIAX_P_LOG, globals.context);
+			} else if (!strcmp(var, "codec-prefs")) {
+				set_global_codec_string(val);
+				DEBUGA_SKYPE("globals.codec_string=%s\n", SKYPIAX_P_LOG, globals.codec_string);
+				globals.codec_order_last = switch_separate_string(globals.codec_string, ',', globals.codec_order, SWITCH_MAX_CODECS);
+			} else if (!strcmp(var, "codec-rates")) {
+				set_global_codec_rates_string(val);
+				DEBUGA_SKYPE("globals.codec_rates_string=%s\n", SKYPIAX_P_LOG, globals.codec_rates_string);
+				globals.codec_rates_last = switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates, SWITCH_MAX_CODECS);
+			}
 
-    }
-  }
+		}
+	}
 
-  if ((interfaces = switch_xml_child(cfg, "per_interface_settings"))) {
-    int i = 0;
+	if ((interfaces = switch_xml_child(cfg, "per_interface_settings"))) {
+		int i = 0;
 
-    for (myinterface = switch_xml_child(interfaces, "interface"); myinterface;
-         myinterface = myinterface->next) {
-      char *id = (char *) switch_xml_attr(myinterface, "id");
-      char *name = (char *) switch_xml_attr(myinterface, "name");
-      char *context = "default";
-      char *dialplan = "XML";
-      char *destination = "5000";
-      char *tonegroup = NULL;
-      char *digit_timeout = NULL;
-      char *max_digits = NULL;
-      char *hotline = NULL;
-      char *dial_regex = NULL;
-      char *hold_music = NULL;
-      char *fail_dial_regex = NULL;
-      char *enable_callerid = "true";
-      char *X11_display = NULL;
-      char *tcp_cli_port = NULL;
-      char *tcp_srv_port = NULL;
-      char *skype_user = NULL;
+		for (myinterface = switch_xml_child(interfaces, "interface"); myinterface; myinterface = myinterface->next) {
+			char *id = (char *) switch_xml_attr(myinterface, "id");
+			char *name = (char *) switch_xml_attr(myinterface, "name");
+			char *context = "default";
+			char *dialplan = "XML";
+			char *destination = "5000";
+			char *tonegroup = NULL;
+			char *digit_timeout = NULL;
+			char *max_digits = NULL;
+			char *hotline = NULL;
+			char *dial_regex = NULL;
+			char *hold_music = NULL;
+			char *fail_dial_regex = NULL;
+			char *enable_callerid = "true";
+			char *X11_display = NULL;
+			char *tcp_cli_port = NULL;
+			char *tcp_srv_port = NULL;
+			char *skype_user = NULL;
 
-      uint32_t interface_id = 0, to = 0, max = 0;
+			uint32_t interface_id = 0, to = 0, max = 0;
 
-      tech_pvt = NULL;
+			tech_pvt = NULL;
 
-      for (param = switch_xml_child(myinterface, "param"); param; param = param->next) {
-        char *var = (char *) switch_xml_attr_soft(param, "name");
-        char *val = (char *) switch_xml_attr_soft(param, "value");
+			for (param = switch_xml_child(myinterface, "param"); param; param = param->next) {
+				char *var = (char *) switch_xml_attr_soft(param, "name");
+				char *val = (char *) switch_xml_attr_soft(param, "value");
 
-        if (!strcasecmp(var, "tonegroup")) {
-          tonegroup = val;
-        } else if (!strcasecmp(var, "digit_timeout") || !strcasecmp(var, "digit-timeout")) {
-          digit_timeout = val;
-        } else if (!strcasecmp(var, "context")) {
-          context = val;
-        } else if (!strcasecmp(var, "dialplan")) {
-          dialplan = val;
-        } else if (!strcasecmp(var, "destination")) {
-          destination = val;
-        } else if (!strcasecmp(var, "dial-regex")) {
-          dial_regex = val;
-        } else if (!strcasecmp(var, "enable-callerid")) {
-          enable_callerid = val;
-        } else if (!strcasecmp(var, "fail-dial-regex")) {
-          fail_dial_regex = val;
-        } else if (!strcasecmp(var, "hold-music")) {
-          hold_music = val;
-        } else if (!strcasecmp(var, "skype_user")) {
-          skype_user = val;
-        } else if (!strcasecmp(var, "tcp_cli_port")) {
-          tcp_cli_port = val;
-        } else if (!strcasecmp(var, "tcp_srv_port")) {
-          tcp_srv_port = val;
-        } else if (!strcasecmp(var, "X11-display") || !strcasecmp(var, "X11_display")) {
-          X11_display = val;
-        } else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) {
-          max_digits = val;
-        } else if (!strcasecmp(var, "hotline")) {
-          hotline = val;
-        }
+				if (!strcasecmp(var, "tonegroup")) {
+					tonegroup = val;
+				} else if (!strcasecmp(var, "digit_timeout") || !strcasecmp(var, "digit-timeout")) {
+					digit_timeout = val;
+				} else if (!strcasecmp(var, "context")) {
+					context = val;
+				} else if (!strcasecmp(var, "dialplan")) {
+					dialplan = val;
+				} else if (!strcasecmp(var, "destination")) {
+					destination = val;
+				} else if (!strcasecmp(var, "dial-regex")) {
+					dial_regex = val;
+				} else if (!strcasecmp(var, "enable-callerid")) {
+					enable_callerid = val;
+				} else if (!strcasecmp(var, "fail-dial-regex")) {
+					fail_dial_regex = val;
+				} else if (!strcasecmp(var, "hold-music")) {
+					hold_music = val;
+				} else if (!strcasecmp(var, "skype_user")) {
+					skype_user = val;
+				} else if (!strcasecmp(var, "tcp_cli_port")) {
+					tcp_cli_port = val;
+				} else if (!strcasecmp(var, "tcp_srv_port")) {
+					tcp_srv_port = val;
+				} else if (!strcasecmp(var, "X11-display") || !strcasecmp(var, "X11_display")) {
+					X11_display = val;
+				} else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) {
+					max_digits = val;
+				} else if (!strcasecmp(var, "hotline")) {
+					hotline = val;
+				}
 
-      }
-      if (!skype_user) {
-        ERRORA("interface missing REQUIRED param 'skype_user'\n", SKYPIAX_P_LOG);
-        continue;
-      }
+			}
+			if (!skype_user) {
+				ERRORA("interface missing REQUIRED param 'skype_user'\n", SKYPIAX_P_LOG);
+				continue;
+			}
 
-      /* BEGIN: Changes here */
-      if (reload_type == SOFT_RELOAD) {
-		  char the_interface[256];
-		  sprintf(the_interface, "#%s", name);
+			/* BEGIN: Changes here */
+			if (reload_type == SOFT_RELOAD) {
+				char the_interface[256];
+				sprintf(the_interface, "#%s", name);
 
-        if (interface_exists(the_interface) == SWITCH_STATUS_SUCCESS) {
-          continue;
-        }
-      }
-      /* END: Changes here */
+				if (interface_exists(the_interface) == SWITCH_STATUS_SUCCESS) {
+					continue;
+				}
+			}
+			/* END: Changes here */
 
-      if (!X11_display) {
-        ERRORA("interface missing REQUIRED param 'X11_display'\n", SKYPIAX_P_LOG);
-        continue;
-      }
-      if (!tcp_cli_port) {
-        ERRORA("interface missing REQUIRED param 'tcp_cli_port'\n", SKYPIAX_P_LOG);
-        continue;
-      }
+			if (!X11_display) {
+				ERRORA("interface missing REQUIRED param 'X11_display'\n", SKYPIAX_P_LOG);
+				continue;
+			}
+			if (!tcp_cli_port) {
+				ERRORA("interface missing REQUIRED param 'tcp_cli_port'\n", SKYPIAX_P_LOG);
+				continue;
+			}
 
-      if (!tcp_srv_port) {
-        ERRORA("interface missing REQUIRED param 'tcp_srv_port'\n", SKYPIAX_P_LOG);
-        continue;
-      }
-      if (!id) {
-        ERRORA("interface missing REQUIRED param 'id'\n", SKYPIAX_P_LOG);
-        continue;
-      }
-      if (switch_is_number(id)) {
-        interface_id = atoi(id);
-        DEBUGA_SKYPE("interface_id=%d\n", SKYPIAX_P_LOG, interface_id);
-      } else {
-        ERRORA("interface param 'id' MUST be a number, now id='%s'\n", SKYPIAX_P_LOG, id);
-        continue;
-      }
+			if (!tcp_srv_port) {
+				ERRORA("interface missing REQUIRED param 'tcp_srv_port'\n", SKYPIAX_P_LOG);
+				continue;
+			}
+			if (!id) {
+				ERRORA("interface missing REQUIRED param 'id'\n", SKYPIAX_P_LOG);
+				continue;
+			}
+			if (switch_is_number(id)) {
+				interface_id = atoi(id);
+				DEBUGA_SKYPE("interface_id=%d\n", SKYPIAX_P_LOG, interface_id);
+			} else {
+				ERRORA("interface param 'id' MUST be a number, now id='%s'\n", SKYPIAX_P_LOG, id);
+				continue;
+			}
 
-      if (!name) {
-        WARNINGA("interface missing param 'name', not nice, but works\n", SKYPIAX_P_LOG);
-      }
+			if (!name) {
+				WARNINGA("interface missing param 'name', not nice, but works\n", SKYPIAX_P_LOG);
+			}
 
-      if (!tonegroup) {
-        tonegroup = "us";
-      }
+			if (!tonegroup) {
+				tonegroup = "us";
+			}
 
-      if (digit_timeout) {
-        to = atoi(digit_timeout);
-      }
+			if (digit_timeout) {
+				to = atoi(digit_timeout);
+			}
 
-      if (max_digits) {
-        max = atoi(max_digits);
-      }
+			if (max_digits) {
+				max = atoi(max_digits);
+			}
 
-      if (name) {
-        DEBUGA_SKYPE("name=%s\n", SKYPIAX_P_LOG, name);
-      }
+			if (name) {
+				DEBUGA_SKYPE("name=%s\n", SKYPIAX_P_LOG, 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) {
-        private_t newconf;
-        switch_threadattr_t *skypiax_api_thread_attr = NULL;
-        switch_threadattr_t *skypiax_signaling_thread_attr = NULL;
+			if (interface_id && interface_id < SKYPIAX_MAX_INTERFACES) {
+				private_t newconf;
+				switch_threadattr_t *skypiax_api_thread_attr = NULL;
+				switch_threadattr_t *skypiax_signaling_thread_attr = NULL;
 
-        memset(&newconf, '\0', sizeof(newconf));
-        globals.SKYPIAX_INTERFACES[interface_id] = newconf;
-		globals.SKYPIAX_INTERFACES[interface_id].running = 1;
+				memset(&newconf, '\0', sizeof(newconf));
+				globals.SKYPIAX_INTERFACES[interface_id] = newconf;
+				globals.SKYPIAX_INTERFACES[interface_id].running = 1;
 
 
-        tech_pvt = &globals.SKYPIAX_INTERFACES[interface_id];
+				tech_pvt = &globals.SKYPIAX_INTERFACES[interface_id];
 
-        switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].interface_id, id);
-        if (name) {
-          switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].name, name);
-        } else {
-          switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].name, "N/A");
-        }
-        DEBUGA_SKYPE("CONFIGURING interface_id=%d\n", SKYPIAX_P_LOG, interface_id);
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].interface_id, id);
+				if (name) {
+					switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].name, name);
+				} else {
+					switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].name, "N/A");
+				}
+				DEBUGA_SKYPE("CONFIGURING interface_id=%d\n", SKYPIAX_P_LOG, interface_id);
 #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].X11_display,
-                          X11_display);
-        switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].skype_user,
-                          skype_user);
-        switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].context, context);
-        switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].dialplan, dialplan);
-        switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].destination,
-                          destination);
-        switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].context, context);
+				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].context, context);
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].dialplan, dialplan);
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].destination, destination);
+				switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].context, context);
 
-        DEBUGA_SKYPE
-          ("interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].X11_display=%s\n",
-           SKYPIAX_P_LOG, interface_id,
-           globals.SKYPIAX_INTERFACES[interface_id].X11_display);
-        DEBUGA_SKYPE
-          ("interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].skype_user=%s\n",
-           SKYPIAX_P_LOG, interface_id,
-           globals.SKYPIAX_INTERFACES[interface_id].skype_user);
-        DEBUGA_SKYPE
-          ("interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].tcp_cli_port=%d\n",
-           SKYPIAX_P_LOG, interface_id,
-           globals.SKYPIAX_INTERFACES[interface_id].tcp_cli_port);
-        DEBUGA_SKYPE
-          ("interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].tcp_srv_port=%d\n",
-           SKYPIAX_P_LOG, interface_id,
-           globals.SKYPIAX_INTERFACES[interface_id].tcp_srv_port);
-        DEBUGA_SKYPE("interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].name=%s\n",
-                     SKYPIAX_P_LOG, interface_id,
-                     globals.SKYPIAX_INTERFACES[interface_id].name);
-        DEBUGA_SKYPE
-          ("interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].context=%s\n",
-           SKYPIAX_P_LOG, interface_id, globals.SKYPIAX_INTERFACES[interface_id].context);
-        DEBUGA_SKYPE
-          ("interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].dialplan=%s\n",
-           SKYPIAX_P_LOG, interface_id,
-           globals.SKYPIAX_INTERFACES[interface_id].dialplan);
-        DEBUGA_SKYPE
-          ("interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].destination=%s\n",
-           SKYPIAX_P_LOG, interface_id,
-           globals.SKYPIAX_INTERFACES[interface_id].destination);
-        DEBUGA_SKYPE
-          ("interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].context=%s\n",
-           SKYPIAX_P_LOG, interface_id, globals.SKYPIAX_INTERFACES[interface_id].context);
-        WARNINGA("STARTING interface_id=%d\n", SKYPIAX_P_LOG, interface_id);
+				DEBUGA_SKYPE
+					("interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].X11_display=%s\n",
+					 SKYPIAX_P_LOG, interface_id, globals.SKYPIAX_INTERFACES[interface_id].X11_display);
+				DEBUGA_SKYPE
+					("interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].skype_user=%s\n",
+					 SKYPIAX_P_LOG, interface_id, globals.SKYPIAX_INTERFACES[interface_id].skype_user);
+				DEBUGA_SKYPE
+					("interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].tcp_cli_port=%d\n",
+					 SKYPIAX_P_LOG, interface_id, globals.SKYPIAX_INTERFACES[interface_id].tcp_cli_port);
+				DEBUGA_SKYPE
+					("interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].tcp_srv_port=%d\n",
+					 SKYPIAX_P_LOG, interface_id, globals.SKYPIAX_INTERFACES[interface_id].tcp_srv_port);
+				DEBUGA_SKYPE("interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].name=%s\n",
+							 SKYPIAX_P_LOG, interface_id, globals.SKYPIAX_INTERFACES[interface_id].name);
+				DEBUGA_SKYPE
+					("interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].context=%s\n",
+					 SKYPIAX_P_LOG, interface_id, globals.SKYPIAX_INTERFACES[interface_id].context);
+				DEBUGA_SKYPE
+					("interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].dialplan=%s\n",
+					 SKYPIAX_P_LOG, interface_id, globals.SKYPIAX_INTERFACES[interface_id].dialplan);
+				DEBUGA_SKYPE
+					("interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].destination=%s\n",
+					 SKYPIAX_P_LOG, interface_id, globals.SKYPIAX_INTERFACES[interface_id].destination);
+				DEBUGA_SKYPE
+					("interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].context=%s\n",
+					 SKYPIAX_P_LOG, interface_id, globals.SKYPIAX_INTERFACES[interface_id].context);
+				WARNINGA("STARTING interface_id=%d\n", SKYPIAX_P_LOG, interface_id);
 
-        switch_threadattr_create(&skypiax_api_thread_attr, skypiax_module_pool);
-        switch_threadattr_stacksize_set(skypiax_api_thread_attr, SWITCH_THREAD_STACKSIZE);
-        switch_thread_create(&globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread,
-                             skypiax_api_thread_attr, skypiax_do_skypeapi_thread,
-                             &globals.SKYPIAX_INTERFACES[interface_id],
-                             skypiax_module_pool);
+				switch_threadattr_create(&skypiax_api_thread_attr, skypiax_module_pool);
+				switch_threadattr_stacksize_set(skypiax_api_thread_attr, SWITCH_THREAD_STACKSIZE);
+				switch_thread_create(&globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread,
+									 skypiax_api_thread_attr, skypiax_do_skypeapi_thread, &globals.SKYPIAX_INTERFACES[interface_id], skypiax_module_pool);
 
-        switch_sleep(100000);
+				switch_sleep(100000);
 
-        switch_threadattr_create(&skypiax_signaling_thread_attr, skypiax_module_pool);
-        switch_threadattr_stacksize_set(skypiax_signaling_thread_attr,
-                                        SWITCH_THREAD_STACKSIZE);
-        switch_thread_create(&globals.SKYPIAX_INTERFACES[interface_id].
-                             skypiax_signaling_thread, skypiax_signaling_thread_attr,
-                             skypiax_signaling_thread_func,
-                             &globals.SKYPIAX_INTERFACES[interface_id],
-                             skypiax_module_pool);
+				switch_threadattr_create(&skypiax_signaling_thread_attr, skypiax_module_pool);
+				switch_threadattr_stacksize_set(skypiax_signaling_thread_attr, SWITCH_THREAD_STACKSIZE);
+				switch_thread_create(&globals.SKYPIAX_INTERFACES[interface_id].
+									 skypiax_signaling_thread, skypiax_signaling_thread_attr,
+									 skypiax_signaling_thread_func, &globals.SKYPIAX_INTERFACES[interface_id], skypiax_module_pool);
 
-        switch_sleep(100000);
+				switch_sleep(100000);
 
-        skypiax_audio_init(&globals.SKYPIAX_INTERFACES[interface_id]);
+				skypiax_audio_init(&globals.SKYPIAX_INTERFACES[interface_id]);
 
-        NOTICA
-          ("WAITING roughly 10 seconds to find a running Skype client and connect to its SKYPE API for interface_id=%d\n",
-           SKYPIAX_P_LOG, interface_id);
-        i = 0;
-        while (globals.SKYPIAX_INTERFACES[interface_id].SkypiaxHandles.api_connected == 0 && running && i < 200) {  // 10 seconds! thanks Jeff Lenk
-          switch_sleep(50000);
-          i++;
-        }
-        if (globals.SKYPIAX_INTERFACES[interface_id].SkypiaxHandles.api_connected) {
-          NOTICA
-            ("Found a running Skype client, connected to its SKYPE API for interface_id=%d, waiting 60 seconds for CURRENTUSERHANDLE==%s\n",
-             SKYPIAX_P_LOG, interface_id,
-             globals.SKYPIAX_INTERFACES[interface_id].skype_user);
-        } else {
-          ERRORA
-            ("Failed to connect to a SKYPE API for interface_id=%d, no SKYPE client running, please (re)start Skype client. Skypiax exiting\n",
-             SKYPIAX_P_LOG, interface_id);
-          running = 0;
-  switch_mutex_unlock(globals.mutex);
-		  switch_xml_free(xml);
-          return SWITCH_STATUS_FALSE;
-        }
+				NOTICA
+					("WAITING roughly 10 seconds to find a running Skype client and connect to its SKYPE API for interface_id=%d\n",
+					 SKYPIAX_P_LOG, interface_id);
+				i = 0;
+				while (globals.SKYPIAX_INTERFACES[interface_id].SkypiaxHandles.api_connected == 0 && running && i < 200) {	// 10 seconds! thanks Jeff Lenk
+					switch_sleep(50000);
+					i++;
+				}
+				if (globals.SKYPIAX_INTERFACES[interface_id].SkypiaxHandles.api_connected) {
+					NOTICA
+						("Found a running Skype client, connected to its SKYPE API for interface_id=%d, waiting 60 seconds for CURRENTUSERHANDLE==%s\n",
+						 SKYPIAX_P_LOG, interface_id, globals.SKYPIAX_INTERFACES[interface_id].skype_user);
+				} else {
+					ERRORA
+						("Failed to connect to a SKYPE API for interface_id=%d, no SKYPE client running, please (re)start Skype client. Skypiax exiting\n",
+						 SKYPIAX_P_LOG, interface_id);
+					running = 0;
+					switch_mutex_unlock(globals.mutex);
+					switch_xml_free(xml);
+					return SWITCH_STATUS_FALSE;
+				}
 
-        i = 0;
-        while (globals.SKYPIAX_INTERFACES[interface_id].SkypiaxHandles.currentuserhandle == 0 && running && i < 1200) { // 60 seconds! thanks Jeff Lenk
-          switch_sleep(50000);
-          i++;
-        }
-        if (globals.SKYPIAX_INTERFACES[interface_id].SkypiaxHandles.currentuserhandle) {
-          WARNINGA
-            ("Interface_id=%d is now STARTED, the Skype client to which we are connected gave us the correct CURRENTUSERHANDLE (%s)\n",
-             SKYPIAX_P_LOG, interface_id,
-             globals.SKYPIAX_INTERFACES[interface_id].skype_user);
+				i = 0;
+				while (globals.SKYPIAX_INTERFACES[interface_id].SkypiaxHandles.currentuserhandle == 0 && running && i < 1200) {	// 60 seconds! thanks Jeff Lenk
+					switch_sleep(50000);
+					i++;
+				}
+				if (globals.SKYPIAX_INTERFACES[interface_id].SkypiaxHandles.currentuserhandle) {
+					WARNINGA
+						("Interface_id=%d is now STARTED, the Skype client to which we are connected gave us the correct CURRENTUSERHANDLE (%s)\n",
+						 SKYPIAX_P_LOG, interface_id, globals.SKYPIAX_INTERFACES[interface_id].skype_user);
 
-          skypiax_signaling_write(&globals.SKYPIAX_INTERFACES[interface_id],
-                                  "SET AUTOAWAY OFF");
-        } else {
-          ERRORA
-            ("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",
-             SKYPIAX_P_LOG, globals.SKYPIAX_INTERFACES[interface_id].skype_user,
-             interface_id, globals.SKYPIAX_INTERFACES[interface_id].skype_user,
-             globals.SKYPIAX_INTERFACES[interface_id].skype_user);
-          running = 0;
-		  switch_mutex_unlock(globals.mutex);
-		  switch_xml_free(xml);
-          return SWITCH_STATUS_FALSE;
-        }
+					skypiax_signaling_write(&globals.SKYPIAX_INTERFACES[interface_id], "SET AUTOAWAY OFF");
+				} else {
+					ERRORA
+						("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",
+						 SKYPIAX_P_LOG, globals.SKYPIAX_INTERFACES[interface_id].skype_user,
+						 interface_id, globals.SKYPIAX_INTERFACES[interface_id].skype_user, globals.SKYPIAX_INTERFACES[interface_id].skype_user);
+					running = 0;
+					switch_mutex_unlock(globals.mutex);
+					switch_xml_free(xml);
+					return SWITCH_STATUS_FALSE;
+				}
 
-      } else {
-        ERRORA("interface id %d is higher than SKYPIAX_MAX_INTERFACES (%d)\n",
-               SKYPIAX_P_LOG, interface_id, SKYPIAX_MAX_INTERFACES);
-        continue;
-      }
+			} else {
+				ERRORA("interface id %d is higher than SKYPIAX_MAX_INTERFACES (%d)\n", SKYPIAX_P_LOG, interface_id, SKYPIAX_MAX_INTERFACES);
+				continue;
+			}
 
-    }
+		}
 
-    for (i = 0; i < SKYPIAX_MAX_INTERFACES; i++) {
-      if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
-               /* How many real intterfaces */
-               globals.real_interfaces = i + 1;
+		for (i = 0; i < SKYPIAX_MAX_INTERFACES; i++) {
+			if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
+				/* How many real intterfaces */
+				globals.real_interfaces = i + 1;
 
-        tech_pvt = &globals.SKYPIAX_INTERFACES[i];
+				tech_pvt = &globals.SKYPIAX_INTERFACES[i];
 
-        DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].interface_id=%s\n",
-                     SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].interface_id);
-        DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].X11_display=%s\n",
-                     SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].X11_display);
-        DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].name=%s\n", SKYPIAX_P_LOG, i, i,
-                     globals.SKYPIAX_INTERFACES[i].name);
-        DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].context=%s\n", SKYPIAX_P_LOG, i,
-                     i, globals.SKYPIAX_INTERFACES[i].context);
-        DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].dialplan=%s\n", SKYPIAX_P_LOG,
-                     i, i, globals.SKYPIAX_INTERFACES[i].dialplan);
-        DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].destination=%s\n",
-                     SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].destination);
-        DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].context=%s\n", SKYPIAX_P_LOG, i,
-                     i, globals.SKYPIAX_INTERFACES[i].context);
-      }
-    }
-  }
+				DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].interface_id=%s\n", SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].interface_id);
+				DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].X11_display=%s\n", SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].X11_display);
+				DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].name=%s\n", SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].name);
+				DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].context=%s\n", SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].context);
+				DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].dialplan=%s\n", SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].dialplan);
+				DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].destination=%s\n", SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].destination);
+				DEBUGA_SKYPE("i=%d globals.SKYPIAX_INTERFACES[%d].context=%s\n", SKYPIAX_P_LOG, i, i, globals.SKYPIAX_INTERFACES[i].context);
+			}
+		}
+	}
 
-  switch_mutex_unlock(globals.mutex);
-  switch_xml_free(xml);
+	switch_mutex_unlock(globals.mutex);
+	switch_xml_free(xml);
 
-  return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_skypiax_load)
 {
-  switch_api_interface_t *commands_api_interface;
+	switch_api_interface_t *commands_api_interface;
 
-  skypiax_module_pool = pool;
-  memset(&globals, '\0', sizeof(globals));
+	skypiax_module_pool = pool;
+	memset(&globals, '\0', sizeof(globals));
 
-  running = 1;
+	running = 1;
 
-  if (load_config(FULL_RELOAD) != SWITCH_STATUS_SUCCESS) {
-    running = 0;
-    return SWITCH_STATUS_FALSE;
-  }
+	if (load_config(FULL_RELOAD) != SWITCH_STATUS_SUCCESS) {
+		running = 0;
+		return SWITCH_STATUS_FALSE;
+	}
 
-  *module_interface = switch_loadable_module_create_module_interface(pool, modname);
-  skypiax_endpoint_interface =
-    switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
-  skypiax_endpoint_interface->interface_name = "skypiax";
-  skypiax_endpoint_interface->io_routines = &skypiax_io_routines;
-  skypiax_endpoint_interface->state_handler = &skypiax_state_handlers;
+	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
+	skypiax_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
+	skypiax_endpoint_interface->interface_name = "skypiax";
+	skypiax_endpoint_interface->io_routines = &skypiax_io_routines;
+	skypiax_endpoint_interface->state_handler = &skypiax_state_handlers;
 
-  if (running) {
+	if (running) {
 
-    SWITCH_ADD_API(commands_api_interface, "sk", "Skypiax console commands", sk_function,
-                   SK_SYNTAX);
-    SWITCH_ADD_API(commands_api_interface, "skypiax", "Skypiax interface commands",
-                   skypiax_function, SKYPIAX_SYNTAX);
+		SWITCH_ADD_API(commands_api_interface, "sk", "Skypiax console commands", sk_function, SK_SYNTAX);
+		SWITCH_ADD_API(commands_api_interface, "skypiax", "Skypiax interface commands", skypiax_function, SKYPIAX_SYNTAX);
 
-    /* indicate that the module should continue to be loaded */
-    return SWITCH_STATUS_SUCCESS;
-  } else
-    return SWITCH_STATUS_FALSE;
+		/* indicate that the module should continue to be loaded */
+		return SWITCH_STATUS_SUCCESS;
+	} else
+		return SWITCH_STATUS_FALSE;
 }
 
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skypiax_shutdown)
 {
-  int x = 100;
-  private_t *tech_pvt = NULL;
-  switch_status_t status;
-  unsigned int howmany = 8;
-  int interface_id;
+	int x = 100;
+	private_t *tech_pvt = NULL;
+	switch_status_t status;
+	unsigned int howmany = 8;
+	int interface_id;
 
-  running = 0;
+	running = 0;
 
-  for (interface_id = 0; interface_id < SKYPIAX_MAX_INTERFACES; interface_id++) {
-    tech_pvt = &globals.SKYPIAX_INTERFACES[interface_id];
+	for (interface_id = 0; interface_id < SKYPIAX_MAX_INTERFACES; interface_id++) {
+		tech_pvt = &globals.SKYPIAX_INTERFACES[interface_id];
 
-    if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_signaling_thread) {
+		if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_signaling_thread) {
 #ifdef WIN32
-      switch_file_write(tech_pvt->SkypiaxHandles.fdesc[1], "sciutati", &howmany);   // let's the controldev_thread die
+			switch_file_write(tech_pvt->SkypiaxHandles.fdesc[1], "sciutati", &howmany);	// let's the controldev_thread die
 #else /* WIN32 */
-      howmany = write(tech_pvt->SkypiaxHandles.fdesc[1], "sciutati", howmany);
+			howmany = write(tech_pvt->SkypiaxHandles.fdesc[1], "sciutati", howmany);
 #endif /* WIN32 */
-    }
+		}
 
-    if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread) {
+		if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread) {
 #ifdef WIN32
-      if (SendMessage(tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle, WM_DESTROY, 0, 0) == FALSE) {  // let's the skypiax_api_thread_func die
-        DEBUGA_SKYPE
-          ("got FALSE here, thread probably was already dead. GetLastError returned: %d\n",
-           SKYPIAX_P_LOG, GetLastError());
-        globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread = NULL;
-      }
+			if (SendMessage(tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle, WM_DESTROY, 0, 0) == FALSE) {	// let's the skypiax_api_thread_func die
+				DEBUGA_SKYPE("got FALSE here, thread probably was already dead. GetLastError returned: %d\n", SKYPIAX_P_LOG, GetLastError());
+				globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread = NULL;
+			}
 #else
-      XEvent e;
-      Atom atom1 =
-        XInternAtom(tech_pvt->SkypiaxHandles.disp, "SKYPECONTROLAPI_MESSAGE_BEGIN",
-                    False);
-      memset(&e, 0, sizeof(e));
-      e.xclient.type = ClientMessage;
-      e.xclient.message_type = atom1;   /*  leading message */
-      e.xclient.display = tech_pvt->SkypiaxHandles.disp;
-      e.xclient.window = tech_pvt->SkypiaxHandles.skype_win;
-      e.xclient.format = 8;
+			XEvent e;
+			Atom atom1 = XInternAtom(tech_pvt->SkypiaxHandles.disp, "SKYPECONTROLAPI_MESSAGE_BEGIN",
+									 False);
+			memset(&e, 0, sizeof(e));
+			e.xclient.type = ClientMessage;
+			e.xclient.message_type = atom1;	/*  leading message */
+			e.xclient.display = tech_pvt->SkypiaxHandles.disp;
+			e.xclient.window = tech_pvt->SkypiaxHandles.skype_win;
+			e.xclient.format = 8;
 
-      XSendEvent(tech_pvt->SkypiaxHandles.disp, tech_pvt->SkypiaxHandles.win, False, 0,
-                 &e);
-      XSync(tech_pvt->SkypiaxHandles.disp, False);
+			XSendEvent(tech_pvt->SkypiaxHandles.disp, tech_pvt->SkypiaxHandles.win, False, 0, &e);
+			XSync(tech_pvt->SkypiaxHandles.disp, False);
 #endif
-    }
-    while (x) {                 //FIXME 2 seconds?
-      x--;
-      switch_yield(20000);
-    }
-    if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_signaling_thread) {
-      switch_thread_join(&status,
-                         globals.SKYPIAX_INTERFACES[interface_id].
-                         skypiax_signaling_thread);
-    }
-    if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread) {
-      switch_thread_join(&status,
-                         globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread);
-    }
-  }
+		}
+		while (x) {				//FIXME 2 seconds?
+			x--;
+			switch_yield(20000);
+		}
+		if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_signaling_thread) {
+			switch_thread_join(&status, globals.SKYPIAX_INTERFACES[interface_id].skypiax_signaling_thread);
+		}
+		if (globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread) {
+			switch_thread_join(&status, globals.SKYPIAX_INTERFACES[interface_id].skypiax_api_thread);
+		}
+	}
 
-  switch_safe_free(globals.dialplan);
-  switch_safe_free(globals.context);
-  switch_safe_free(globals.destination);
-  switch_safe_free(globals.codec_string);
-  switch_safe_free(globals.codec_rates_string);
+	switch_safe_free(globals.dialplan);
+	switch_safe_free(globals.context);
+	switch_safe_free(globals.destination);
+	switch_safe_free(globals.codec_string);
+	switch_safe_free(globals.codec_rates_string);
 
-  return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
 void *SWITCH_THREAD_FUNC skypiax_do_tcp_srv_thread(switch_thread_t * thread, void *obj)
 {
-  return skypiax_do_tcp_srv_thread_func(obj);
+	return skypiax_do_tcp_srv_thread_func(obj);
 }
 
 void *SWITCH_THREAD_FUNC skypiax_do_tcp_cli_thread(switch_thread_t * thread, void *obj)
 {
-  return skypiax_do_tcp_cli_thread_func(obj);
+	return skypiax_do_tcp_cli_thread_func(obj);
 }
 
 void *SWITCH_THREAD_FUNC skypiax_do_skypeapi_thread(switch_thread_t * thread, void *obj)
 {
-  return skypiax_do_skypeapi_thread_func(obj);
+	return skypiax_do_skypeapi_thread_func(obj);
 }
 
 int dtmf_received(private_t * tech_pvt, char *value)
 {
-  switch_core_session_t *session = NULL;
-  switch_channel_t *channel = NULL;
+	switch_core_session_t *session = NULL;
+	switch_channel_t *channel = NULL;
 
-  session = switch_core_session_locate(tech_pvt->session_uuid_str);
-  channel = switch_core_session_get_channel(session);
+	session = switch_core_session_locate(tech_pvt->session_uuid_str);
+	channel = switch_core_session_get_channel(session);
 
-  if (channel) {
+	if (channel) {
 
-    if (!switch_channel_test_flag(channel, CF_BRIDGED)) {
+		if (!switch_channel_test_flag(channel, CF_BRIDGED)) {
 
-      switch_dtmf_t dtmf = { (char) value[0], switch_core_default_dtmf_duration(0) };
-      DEBUGA_SKYPE("received DTMF %c on channel %s\n", SKYPIAX_P_LOG, dtmf.digit,
-                   switch_channel_get_name(channel));
-      switch_mutex_lock(tech_pvt->flag_mutex);
-      //FIXME: why sometimes DTMFs from here do not seems to be get by FS?
-      switch_channel_queue_dtmf(channel, &dtmf);
-      switch_set_flag(tech_pvt, TFLAG_DTMF);
-      switch_mutex_unlock(tech_pvt->flag_mutex);
-    } else {
-      DEBUGA_SKYPE
-        ("received a DTMF on channel %s, but we're BRIDGED, so let's NOT relay it out of band\n",
-         SKYPIAX_P_LOG, switch_channel_get_name(channel));
-    }
-  } else {
-    WARNINGA("received %c DTMF, but no channel?\n", SKYPIAX_P_LOG, value[0]);
-  }
-  switch_core_session_rwunlock(session);
+			switch_dtmf_t dtmf = { (char) value[0], switch_core_default_dtmf_duration(0) };
+			DEBUGA_SKYPE("received DTMF %c on channel %s\n", SKYPIAX_P_LOG, dtmf.digit, switch_channel_get_name(channel));
+			switch_mutex_lock(tech_pvt->flag_mutex);
+			//FIXME: why sometimes DTMFs from here do not seems to be get by FS?
+			switch_channel_queue_dtmf(channel, &dtmf);
+			switch_set_flag(tech_pvt, TFLAG_DTMF);
+			switch_mutex_unlock(tech_pvt->flag_mutex);
+		} else {
+			DEBUGA_SKYPE
+				("received a DTMF on channel %s, but we're BRIDGED, so let's NOT relay it out of band\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
+		}
+	} else {
+		WARNINGA("received %c DTMF, but no channel?\n", SKYPIAX_P_LOG, value[0]);
+	}
+	switch_core_session_rwunlock(session);
 
-  return 0;
+	return 0;
 }
 
 int start_audio_threads(private_t * tech_pvt)
 {
-  switch_threadattr_t *thd_attr = NULL;
+	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(&tech_pvt->tcp_srv_thread, thd_attr, skypiax_do_tcp_srv_thread,
-                       tech_pvt, 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(&tech_pvt->tcp_srv_thread, thd_attr, skypiax_do_tcp_srv_thread, tech_pvt, 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(&tech_pvt->tcp_cli_thread, thd_attr, skypiax_do_tcp_cli_thread,
-                       tech_pvt, skypiax_module_pool);
-  DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
-  switch_sleep(100000);
+	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(&tech_pvt->tcp_cli_thread, thd_attr, skypiax_do_tcp_cli_thread, tech_pvt, skypiax_module_pool);
+	DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
+	switch_sleep(100000);
 
-  return 0;
+	return 0;
 }
 
 int new_inbound_channel(private_t * tech_pvt)
 {
-  switch_core_session_t *session = NULL;
-  switch_channel_t *channel = NULL;
+	switch_core_session_t *session = NULL;
+	switch_channel_t *channel = NULL;
 
-  if ((session =
-       switch_core_session_request(skypiax_endpoint_interface,
-                                   SWITCH_CALL_DIRECTION_INBOUND, NULL)) != 0) {
-    switch_core_session_add_stream(session, NULL);
-    channel = switch_core_session_get_channel(session);
-    skypiax_tech_init(tech_pvt, session);
+	if ((session = switch_core_session_request(skypiax_endpoint_interface, SWITCH_CALL_DIRECTION_INBOUND, NULL)) != 0) {
+		switch_core_session_add_stream(session, NULL);
+		channel = switch_core_session_get_channel(session);
+		skypiax_tech_init(tech_pvt, session);
 
-    if ((tech_pvt->caller_profile =
-         switch_caller_profile_new(switch_core_session_get_pool(session), "skypiax",
-                                   tech_pvt->dialplan, tech_pvt->callid_name,
-                                   tech_pvt->callid_number, NULL, NULL, NULL, NULL,
-                                   "mod_skypiax", tech_pvt->context,
-                                   tech_pvt->destination)) != 0) {
-      char name[128];
-      //switch_snprintf(name, sizeof(name), "skypiax/%s/%s", tech_pvt->name, tech_pvt->caller_profile->destination_number);
-      switch_snprintf(name, sizeof(name), "skypiax/%s", tech_pvt->name);
-      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) {
-      ERRORA("Error spawning thread\n", SKYPIAX_P_LOG);
-      switch_core_session_destroy(&session);
-    }
-  }
-  switch_channel_mark_answered(channel);
+		if ((tech_pvt->caller_profile =
+			 switch_caller_profile_new(switch_core_session_get_pool(session), "skypiax",
+									   tech_pvt->dialplan, tech_pvt->callid_name,
+									   tech_pvt->callid_number, NULL, NULL, NULL, NULL, "mod_skypiax", tech_pvt->context, tech_pvt->destination)) != 0) {
+			char name[128];
+			//switch_snprintf(name, sizeof(name), "skypiax/%s/%s", tech_pvt->name, tech_pvt->caller_profile->destination_number);
+			switch_snprintf(name, sizeof(name), "skypiax/%s", tech_pvt->name);
+			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) {
+			ERRORA("Error spawning thread\n", SKYPIAX_P_LOG);
+			switch_core_session_destroy(&session);
+		}
+	}
+	switch_channel_mark_answered(channel);
 
-  DEBUGA_SKYPE("Here\n", SKYPIAX_P_LOG);
+	DEBUGA_SKYPE("Here\n", SKYPIAX_P_LOG);
 
-  return 0;
+	return 0;
 }
 
 int remote_party_is_ringing(private_t * tech_pvt)
 {
-  switch_core_session_t *session = NULL;
-  switch_channel_t *channel = NULL;
+	switch_core_session_t *session = NULL;
+	switch_channel_t *channel = NULL;
 
-  if (!switch_strlen_zero(tech_pvt->session_uuid_str)) {
-    session = switch_core_session_locate(tech_pvt->session_uuid_str);
-  } else {
-    ERRORA("No session???\n", SKYPIAX_P_LOG);
-    goto done;
-  }
-  if (session) {
-    channel = switch_core_session_get_channel(session);
-  } else {
-    ERRORA("No session???\n", SKYPIAX_P_LOG);
-    goto done;
-  }
-  if (channel) {
-    switch_channel_mark_ring_ready(channel);
-    DEBUGA_SKYPE("skype_call: REMOTE PARTY RINGING\n", SKYPIAX_P_LOG);
-  } else {
-    ERRORA("No channel???\n", SKYPIAX_P_LOG);
-    goto done;
-  }
+	if (!switch_strlen_zero(tech_pvt->session_uuid_str)) {
+		session = switch_core_session_locate(tech_pvt->session_uuid_str);
+	} else {
+		ERRORA("No session???\n", SKYPIAX_P_LOG);
+		goto done;
+	}
+	if (session) {
+		channel = switch_core_session_get_channel(session);
+	} else {
+		ERRORA("No session???\n", SKYPIAX_P_LOG);
+		goto done;
+	}
+	if (channel) {
+		switch_channel_mark_ring_ready(channel);
+		DEBUGA_SKYPE("skype_call: REMOTE PARTY RINGING\n", SKYPIAX_P_LOG);
+	} else {
+		ERRORA("No channel???\n", SKYPIAX_P_LOG);
+		goto done;
+	}
 
-  switch_core_session_rwunlock(session);
+	switch_core_session_rwunlock(session);
 
-done:
-  return 0;
+  done:
+	return 0;
 }
 
 int remote_party_is_early_media(private_t * tech_pvt)
 {
-  switch_core_session_t *session = NULL;
-  switch_channel_t *channel = NULL;
+	switch_core_session_t *session = NULL;
+	switch_channel_t *channel = NULL;
 
-  if (!switch_strlen_zero(tech_pvt->session_uuid_str)) {
-    session = switch_core_session_locate(tech_pvt->session_uuid_str);
-  } else {
-    ERRORA("No session???\n", SKYPIAX_P_LOG);
-    goto done;
-  }
-  if (session) {
-    channel = switch_core_session_get_channel(session);
-    switch_core_session_add_stream(session, NULL);
-  } else {
-    ERRORA("No session???\n", SKYPIAX_P_LOG);
-    goto done;
-  }
-  if (channel) {
-    switch_channel_mark_pre_answered(channel);
-    DEBUGA_SKYPE("skype_call: REMOTE PARTY EARLY MEDIA\n", SKYPIAX_P_LOG);
-  } else {
-    ERRORA("No channel???\n", SKYPIAX_P_LOG);
-    goto done;
-  }
+	if (!switch_strlen_zero(tech_pvt->session_uuid_str)) {
+		session = switch_core_session_locate(tech_pvt->session_uuid_str);
+	} else {
+		ERRORA("No session???\n", SKYPIAX_P_LOG);
+		goto done;
+	}
+	if (session) {
+		channel = switch_core_session_get_channel(session);
+		switch_core_session_add_stream(session, NULL);
+	} else {
+		ERRORA("No session???\n", SKYPIAX_P_LOG);
+		goto done;
+	}
+	if (channel) {
+		switch_channel_mark_pre_answered(channel);
+		DEBUGA_SKYPE("skype_call: REMOTE PARTY EARLY MEDIA\n", SKYPIAX_P_LOG);
+	} else {
+		ERRORA("No channel???\n", SKYPIAX_P_LOG);
+		goto done;
+	}
 
-  switch_core_session_rwunlock(session);
+	switch_core_session_rwunlock(session);
 
-done:
-  return 0;
+  done:
+	return 0;
 }
 
 int outbound_channel_answered(private_t * tech_pvt)
 {
-  switch_core_session_t *session = NULL;
-  switch_channel_t *channel = NULL;
+	switch_core_session_t *session = NULL;
+	switch_channel_t *channel = NULL;
 
-  if (!switch_strlen_zero(tech_pvt->session_uuid_str)) {
-    session = switch_core_session_locate(tech_pvt->session_uuid_str);
-  } else {
-    ERRORA("No session???\n", SKYPIAX_P_LOG);
-    goto done;
-  }
-  if (session) {
-    channel = switch_core_session_get_channel(session);
-  } else {
-    ERRORA("No session???\n", SKYPIAX_P_LOG);
-    goto done;
-  }
-  if (channel) {
-    switch_channel_mark_answered(channel);
-    //DEBUGA_SKYPE("skype_call: %s, answered\n", SKYPIAX_P_LOG, id);
-  } else {
-    ERRORA("No channel???\n", SKYPIAX_P_LOG);
-    goto done;
-  }
+	if (!switch_strlen_zero(tech_pvt->session_uuid_str)) {
+		session = switch_core_session_locate(tech_pvt->session_uuid_str);
+	} else {
+		ERRORA("No session???\n", SKYPIAX_P_LOG);
+		goto done;
+	}
+	if (session) {
+		channel = switch_core_session_get_channel(session);
+	} else {
+		ERRORA("No session???\n", SKYPIAX_P_LOG);
+		goto done;
+	}
+	if (channel) {
+		switch_channel_mark_answered(channel);
+		//DEBUGA_SKYPE("skype_call: %s, answered\n", SKYPIAX_P_LOG, id);
+	} else {
+		ERRORA("No channel???\n", SKYPIAX_P_LOG);
+		goto done;
+	}
 
-  switch_core_session_rwunlock(session);
+	switch_core_session_rwunlock(session);
 
-done:
-  DEBUGA_SKYPE("HERE!\n", SKYPIAX_P_LOG);
+  done:
+	DEBUGA_SKYPE("HERE!\n", SKYPIAX_P_LOG);
 
-  return 0;
+	return 0;
 }
 
 private_t *find_available_skypiax_interface(private_t * tech_pvt)
 {
-  private_t *tech_pvt2 = NULL;
-  int found = 0;
-  int i;
+	private_t *tech_pvt2 = NULL;
+	int found = 0;
+	int i;
 
-  switch_mutex_lock(globals.mutex);
+	switch_mutex_lock(globals.mutex);
 
-  for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
-    if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
-      int skype_state = 0;
+	for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
+		if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
+			int skype_state = 0;
 
-      tech_pvt2 = &globals.SKYPIAX_INTERFACES[i];
-      skype_state = tech_pvt2->interface_state;
-      DEBUGA_SKYPE("skype interface: %d, name: %s, state: %d\n", SKYPIAX_P_LOG, i,
-                   globals.SKYPIAX_INTERFACES[i].name, skype_state);
-      if ((tech_pvt ? strcmp(tech_pvt2->skype_user, tech_pvt->skype_user) : 1) && (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
-        found = 1;
-        break;
-      }
-    }
-  }
+			tech_pvt2 = &globals.SKYPIAX_INTERFACES[i];
+			skype_state = tech_pvt2->interface_state;
+			DEBUGA_SKYPE("skype interface: %d, name: %s, state: %d\n", SKYPIAX_P_LOG, i, globals.SKYPIAX_INTERFACES[i].name, skype_state);
+			if ((tech_pvt ? strcmp(tech_pvt2->skype_user, tech_pvt->skype_user) : 1) && (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
+				found = 1;
+				break;
+			}
+		}
+	}
 
-  switch_mutex_unlock(globals.mutex);
-  if (found)
-    return tech_pvt2;
-  else
-    return NULL;
+	switch_mutex_unlock(globals.mutex);
+	if (found)
+		return tech_pvt2;
+	else
+		return NULL;
 }
-   
+
 private_t *find_available_skypiax_interface_rr(void)
 {
-  private_t *tech_pvt = NULL;
-  int i;
-  //int num_interfaces = SKYPIAX_MAX_INTERFACES; 
-  //int num_interfaces = globals.real_interfaces;
+	private_t *tech_pvt = NULL;
+	int i;
+	//int num_interfaces = SKYPIAX_MAX_INTERFACES; 
+	//int num_interfaces = globals.real_interfaces;
 
-  switch_mutex_lock(globals.mutex);
+	switch_mutex_lock(globals.mutex);
 
-  /* Fact is the real interface start from 1 */
-  //XXX no, is just a convention, but you can have it start from 0. I do not, for aestetic reasons :-)  
-  //if (globals.next_interface == 0) globals.next_interface = 1;
+	/* Fact is the real interface start from 1 */
+	//XXX no, is just a convention, but you can have it start from 0. I do not, for aestetic reasons :-)  
+	//if (globals.next_interface == 0) globals.next_interface = 1;
 
-  for (i = 0; i < SKYPIAX_MAX_INTERFACES; i++) { 
-    int interface_id;
+	for (i = 0; i < SKYPIAX_MAX_INTERFACES; i++) {
+		int interface_id;
 
-    interface_id = globals.next_interface;
-    //interface_id = interface_id < SKYPIAX_MAX_INTERFACES ? interface_id : interface_id - SKYPIAX_MAX_INTERFACES + 1;
-        globals.next_interface = interface_id + 1 < SKYPIAX_MAX_INTERFACES ? interface_id + 1 : 0;
+		interface_id = globals.next_interface;
+		//interface_id = interface_id < SKYPIAX_MAX_INTERFACES ? interface_id : interface_id - SKYPIAX_MAX_INTERFACES + 1;
+		globals.next_interface = interface_id + 1 < SKYPIAX_MAX_INTERFACES ? interface_id + 1 : 0;
 
-    if (strlen(globals.SKYPIAX_INTERFACES[interface_id].name)) {
-      int skype_state = 0;
+		if (strlen(globals.SKYPIAX_INTERFACES[interface_id].name)) {
+			int skype_state = 0;
 
-      tech_pvt = &globals.SKYPIAX_INTERFACES[interface_id];
-      skype_state = tech_pvt->interface_state;
-      DEBUGA_SKYPE("skype interface: %d, name: %s, state: %d\n", SKYPIAX_P_LOG, interface_id,
-                         globals.SKYPIAX_INTERFACES[interface_id].name, skype_state);
-      if (SKYPIAX_STATE_DOWN == skype_state || 0 == skype_state) {
-        /*set to Dialing state to avoid other thread fint it, don't know if it is safe */
-        //XXX no, it's not safe 
-		  //tech_pvt->interface_state = SKYPIAX_STATE_DIALING ;
-        
-        switch_mutex_unlock(globals.mutex);
-        return tech_pvt;
-      }
-    }// else {
-      //DEBUGA_SKYPE("Skype interface: %d blank!! A hole here means we cannot hunt the last interface.\n", SKYPIAX_P_LOG, interface_id);
-    //}
-  }
+			tech_pvt = &globals.SKYPIAX_INTERFACES[interface_id];
+			skype_state = tech_pvt->interface_state;
+			DEBUGA_SKYPE("skype interface: %d, name: %s, state: %d\n", SKYPIAX_P_LOG, interface_id,
+						 globals.SKYPIAX_INTERFACES[interface_id].name, skype_state);
+			if (SKYPIAX_STATE_DOWN == skype_state || 0 == skype_state) {
+				/*set to Dialing state to avoid other thread fint it, don't know if it is safe */
+				//XXX no, it's not safe 
+				//tech_pvt->interface_state = SKYPIAX_STATE_DIALING ;
 
-  switch_mutex_unlock(globals.mutex);
-  return NULL;
+				switch_mutex_unlock(globals.mutex);
+				return tech_pvt;
+			}
+		}						// else {
+		//DEBUGA_SKYPE("Skype interface: %d blank!! A hole here means we cannot hunt the last interface.\n", SKYPIAX_P_LOG, interface_id);
+		//}
+	}
+
+	switch_mutex_unlock(globals.mutex);
+	return NULL;
 }
 
 SWITCH_STANDARD_API(sk_function)
 {
-  char *mycmd = NULL, *argv[10] = { 0 };
-  int argc = 0;
+	char *mycmd = NULL, *argv[10] = { 0 };
+	int argc = 0;
 
-  if (globals.sk_console)
-    stream->write_function(stream, "sk console is: |||%s|||\n", globals.sk_console->name);
-  else
-    stream->write_function(stream, "sk console is NOT yet assigned\n");
+	if (globals.sk_console)
+		stream->write_function(stream, "sk console is: |||%s|||\n", globals.sk_console->name);
+	else
+		stream->write_function(stream, "sk console is NOT yet assigned\n");
 
-  if (!switch_strlen_zero(cmd) && (mycmd = strdup(cmd))) {
-    argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
-  }
+	if (!switch_strlen_zero(cmd) && (mycmd = strdup(cmd))) {
+		argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+	}
 
-  if (!argc || !argv[0]) {
-    stream->write_function(stream, "%s", SK_SYNTAX);
-    goto end;
-  }
+	if (!argc || !argv[0]) {
+		stream->write_function(stream, "%s", SK_SYNTAX);
+		goto end;
+	}
 
-  if (!strcasecmp(argv[0], "list")) {
-    int i;             
-       char next_flag_char = ' ';
+	if (!strcasecmp(argv[0], "list")) {
+		int i;
+		char next_flag_char = ' ';
 
-    for (i = 0; i < SKYPIAX_MAX_INTERFACES; i++) {
-         next_flag_char = i == globals.next_interface ? '*' : ' ';
+		for (i = 0; i < SKYPIAX_MAX_INTERFACES; i++) {
+			next_flag_char = i == globals.next_interface ? '*' : ' ';
 
-      if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
-        if (strlen(globals.SKYPIAX_INTERFACES[i].session_uuid_str)) {
-          stream->write_function(stream,
-                                 "%c\t%d\t[%s]\tBUSY, session_uuid_str=|||%s|||\n",
-                                 next_flag_char,
-                                 i, globals.SKYPIAX_INTERFACES[i].name,
-                                 globals.SKYPIAX_INTERFACES[i].session_uuid_str);
-        } else {
-          stream->write_function(stream,
-                                 "%c\t%d\t[%s]\tIDLE\n",
-                                 next_flag_char,
-                                 i, globals.SKYPIAX_INTERFACES[i].name);
-        }
-      } else if(argc > 1 && !strcasecmp(argv[1], "full")) {
-        stream->write_function(stream, "%c\t%d\n", next_flag_char, i);
-      }                                                                      
+			if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
+				if (strlen(globals.SKYPIAX_INTERFACES[i].session_uuid_str)) {
+					stream->write_function(stream,
+										   "%c\t%d\t[%s]\tBUSY, session_uuid_str=|||%s|||\n",
+										   next_flag_char, i, globals.SKYPIAX_INTERFACES[i].name, globals.SKYPIAX_INTERFACES[i].session_uuid_str);
+				} else {
+					stream->write_function(stream, "%c\t%d\t[%s]\tIDLE\n", next_flag_char, i, globals.SKYPIAX_INTERFACES[i].name);
+				}
+			} else if (argc > 1 && !strcasecmp(argv[1], "full")) {
+				stream->write_function(stream, "%c\t%d\n", next_flag_char, i);
+			}
 
-    }
-    stream->write_function(stream, "\nTotal: %d\n", globals.real_interfaces - 1 );
+		}
+		stream->write_function(stream, "\nTotal: %d\n", globals.real_interfaces - 1);
 
-  } else if (!strcasecmp(argv[0], "console")) {
-    int i;
-    int found = 0;
+	} else if (!strcasecmp(argv[0], "console")) {
+		int i;
+		int found = 0;
 
-    if (argc == 2) {
-      for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
-        /* we've been asked for a normal interface name, or we have not found idle interfaces to serve as the "ANY" interface */
-        if (strlen(globals.SKYPIAX_INTERFACES[i].name)
-            && (strncmp(globals.SKYPIAX_INTERFACES[i].name, argv[1], strlen(argv[1])) ==
-                0)) {
-          globals.sk_console = &globals.SKYPIAX_INTERFACES[i];
-          stream->write_function(stream,
-                                 "sk console is now: globals.SKYPIAX_INTERFACES[%d].name=|||%s|||\n",
-                                 i, globals.SKYPIAX_INTERFACES[i].name);
-          stream->write_function(stream, "sk console is: |||%s|||\n",
-                                 globals.sk_console->name);
-          found = 1;
-          break;
-        }
+		if (argc == 2) {
+			for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
+				/* we've been asked for a normal interface name, or we have not found idle interfaces to serve as the "ANY" interface */
+				if (strlen(globals.SKYPIAX_INTERFACES[i].name)
+					&& (strncmp(globals.SKYPIAX_INTERFACES[i].name, argv[1], strlen(argv[1])) == 0)) {
+					globals.sk_console = &globals.SKYPIAX_INTERFACES[i];
+					stream->write_function(stream,
+										   "sk console is now: globals.SKYPIAX_INTERFACES[%d].name=|||%s|||\n", i, globals.SKYPIAX_INTERFACES[i].name);
+					stream->write_function(stream, "sk console is: |||%s|||\n", globals.sk_console->name);
+					found = 1;
+					break;
+				}
 
-      }
-      if (!found)
-        stream->write_function(stream,
-                               "ERROR: A Skypiax interface with name='%s' was not found\n",
-                               argv[1]);
-    } else {
+			}
+			if (!found)
+				stream->write_function(stream, "ERROR: A Skypiax interface with name='%s' was not found\n", argv[1]);
+		} else {
 
-      stream->write_function(stream, "-ERR Usage: sk console interface_name\n");
-      goto end;
-    }
+			stream->write_function(stream, "-ERR Usage: sk console interface_name\n");
+			goto end;
+		}
 
-  } else if (!strcasecmp(argv[0], "ciapalino")) {
+	} else if (!strcasecmp(argv[0], "ciapalino")) {
 
 /* BEGIN: Changes heres */
-  } else if (!strcasecmp(argv[0], "reload")) {
-    if (load_config(SOFT_RELOAD) != SWITCH_STATUS_SUCCESS) {
-      stream->write_function(stream, "sk reload failed\n");
-    } else {
-      stream->write_function(stream, "sk reload success\n");
-    }
-  } else if (!strcasecmp(argv[0], "remove")) {
-    if (argc == 2) {
-      if (remove_interface(argv[1]) == SWITCH_STATUS_SUCCESS) {
-        if (interface_exists(argv[1]) == SWITCH_STATUS_SUCCESS) {
-          stream->write_function(stream, "sk remove '%s' failed\n", argv[1]);
-        } else {
-          stream->write_function(stream, "sk remove '%s' success\n", argv[1]);
-        }
-      }
-    } else {
-      stream->write_function(stream, "-ERR Usage: sk remove interface_name\n");
-      goto end;
-    }
+	} else if (!strcasecmp(argv[0], "reload")) {
+		if (load_config(SOFT_RELOAD) != SWITCH_STATUS_SUCCESS) {
+			stream->write_function(stream, "sk reload failed\n");
+		} else {
+			stream->write_function(stream, "sk reload success\n");
+		}
+	} else if (!strcasecmp(argv[0], "remove")) {
+		if (argc == 2) {
+			if (remove_interface(argv[1]) == SWITCH_STATUS_SUCCESS) {
+				if (interface_exists(argv[1]) == SWITCH_STATUS_SUCCESS) {
+					stream->write_function(stream, "sk remove '%s' failed\n", argv[1]);
+				} else {
+					stream->write_function(stream, "sk remove '%s' success\n", argv[1]);
+				}
+			}
+		} else {
+			stream->write_function(stream, "-ERR Usage: sk remove interface_name\n");
+			goto end;
+		}
 /* END: Changes heres */
 
-  } else {
-    if (globals.sk_console)
-      skypiax_signaling_write(globals.sk_console, (char *) cmd);
-    else
-      stream->write_function(stream, "sk console is NOT yet assigned\n");
-  }
-end:
-  switch_safe_free(mycmd);
+	} else {
+		if (globals.sk_console)
+			skypiax_signaling_write(globals.sk_console, (char *) cmd);
+		else
+			stream->write_function(stream, "sk console is NOT yet assigned\n");
+	}
+  end:
+	switch_safe_free(mycmd);
 
-  return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
 SWITCH_STANDARD_API(skypiax_function)
 {
-  char *mycmd = NULL, *argv[10] = { 0 };
-  int argc = 0;
-  private_t *tech_pvt = NULL;
+	char *mycmd = NULL, *argv[10] = { 0 };
+	int argc = 0;
+	private_t *tech_pvt = NULL;
 
-  if (!switch_strlen_zero(cmd) && (mycmd = strdup(cmd))) {
-    argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
-  }
+	if (!switch_strlen_zero(cmd) && (mycmd = strdup(cmd))) {
+		argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+	}
 
-  if (!argc) {
-    stream->write_function(stream, "ERROR, usage: %s", SKYPIAX_SYNTAX);
-    goto end;
-  }
+	if (!argc) {
+		stream->write_function(stream, "ERROR, usage: %s", SKYPIAX_SYNTAX);
+		goto end;
+	}
 
-  if (argc < 2) {
-    stream->write_function(stream, "ERROR, usage: %s", SKYPIAX_SYNTAX);
-    goto end;
-  }
+	if (argc < 2) {
+		stream->write_function(stream, "ERROR, usage: %s", SKYPIAX_SYNTAX);
+		goto end;
+	}
 
-  if (argv[0]) {
-    int i;
-    int found = 0;
+	if (argv[0]) {
+		int i;
+		int found = 0;
 
-    for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
-      /* we've been asked for a normal interface name, or we have not found idle interfaces to serve as the "ANY" interface */
-      if (strlen(globals.SKYPIAX_INTERFACES[i].name)
-          && (strncmp(globals.SKYPIAX_INTERFACES[i].name, argv[0], strlen(argv[0])) == 0)) {
-        tech_pvt = &globals.SKYPIAX_INTERFACES[i];
-        stream->write_function(stream,
-                               "Using interface: globals.SKYPIAX_INTERFACES[%d].name=|||%s|||\n",
-                               i, globals.SKYPIAX_INTERFACES[i].name);
-        found = 1;
-        break;
-      }
+		for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
+			/* we've been asked for a normal interface name, or we have not found idle interfaces to serve as the "ANY" interface */
+			if (strlen(globals.SKYPIAX_INTERFACES[i].name)
+				&& (strncmp(globals.SKYPIAX_INTERFACES[i].name, argv[0], strlen(argv[0])) == 0)) {
+				tech_pvt = &globals.SKYPIAX_INTERFACES[i];
+				stream->write_function(stream, "Using interface: globals.SKYPIAX_INTERFACES[%d].name=|||%s|||\n", i, globals.SKYPIAX_INTERFACES[i].name);
+				found = 1;
+				break;
+			}
 
-    }
-    if (!found) {
-      stream->write_function(stream,
-                             "ERROR: A Skypiax interface with name='%s' was not found\n",
-                             argv[0]);
-      switch_safe_free(mycmd);
+		}
+		if (!found) {
+			stream->write_function(stream, "ERROR: A Skypiax interface with name='%s' was not found\n", argv[0]);
+			switch_safe_free(mycmd);
 
-      return SWITCH_STATUS_SUCCESS;
-    } else {
-      skypiax_signaling_write(tech_pvt, (char *) &cmd[strlen(argv[0]) + 1]);
-    }
-  } else {
-    stream->write_function(stream, "ERROR, usage: %s", SKYPIAX_SYNTAX);
-  }
-end:
-  switch_safe_free(mycmd);
+			return SWITCH_STATUS_SUCCESS;
+		} else {
+			skypiax_signaling_write(tech_pvt, (char *) &cmd[strlen(argv[0]) + 1]);
+		}
+	} else {
+		stream->write_function(stream, "ERROR, usage: %s", SKYPIAX_SYNTAX);
+	}
+  end:
+	switch_safe_free(mycmd);
 
-  return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
 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;
+	char msg_to_skype[1024];
+	int i;
+	int found = 0;
+	private_t *giovatech;
+	struct timeval timenow;
 
-  switch_mutex_lock(globals.mutex);
+	switch_mutex_lock(globals.mutex);
 
-  gettimeofday(&timenow, NULL);
-  for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
-    if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
+	gettimeofday(&timenow, NULL);
+	for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
+		if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
 
-      giovatech = &globals.SKYPIAX_INTERFACES[i];
-      //NOTICA("skype interface: %d, name: %s, state: %d, value=%s, giovatech->callid_number=%s, giovatech->skype_user=%s\n", SKYPIAX_P_LOG, i, giovatech->name, giovatech->interface_state, value, giovatech->callid_number, giovatech->skype_user);
-      //FIXME check a timestamp here
-      if (strlen(giovatech->skype_call_id) && (giovatech->interface_state != SKYPIAX_STATE_DOWN) && (!strcmp(giovatech->skype_user, tech_pvt->skype_user)) && (!strcmp(giovatech->callid_number, value)) && ((((timenow.tv_sec - giovatech->answer_time.tv_sec) * 1000000) + (timenow.tv_usec - giovatech->answer_time.tv_usec)) < 500000)) {   //0.5sec
-        found = 1;
-        DEBUGA_SKYPE
-          ("FOUND  (name=%s, giovatech->interface_state=%d != SKYPIAX_STATE_DOWN) && (giovatech->skype_user=%s == tech_pvt->skype_user=%s) && (giovatech->callid_number=%s == value=%s)\n",
-           SKYPIAX_P_LOG, giovatech->name, giovatech->interface_state,
-           giovatech->skype_user, tech_pvt->skype_user, giovatech->callid_number, value)
-          break;
-      }
-    }
-  }
+			giovatech = &globals.SKYPIAX_INTERFACES[i];
+			//NOTICA("skype interface: %d, name: %s, state: %d, value=%s, giovatech->callid_number=%s, giovatech->skype_user=%s\n", SKYPIAX_P_LOG, i, giovatech->name, giovatech->interface_state, value, giovatech->callid_number, giovatech->skype_user);
+			//FIXME check a timestamp here
+			if (strlen(giovatech->skype_call_id) && (giovatech->interface_state != SKYPIAX_STATE_DOWN) && (!strcmp(giovatech->skype_user, tech_pvt->skype_user)) && (!strcmp(giovatech->callid_number, value)) && ((((timenow.tv_sec - giovatech->answer_time.tv_sec) * 1000000) + (timenow.tv_usec - giovatech->answer_time.tv_usec)) < 500000)) {	//0.5sec
+				found = 1;
+				DEBUGA_SKYPE
+					("FOUND  (name=%s, giovatech->interface_state=%d != SKYPIAX_STATE_DOWN) && (giovatech->skype_user=%s == tech_pvt->skype_user=%s) && (giovatech->callid_number=%s == value=%s)\n",
+					 SKYPIAX_P_LOG, giovatech->name, giovatech->interface_state,
+					 giovatech->skype_user, tech_pvt->skype_user, giovatech->callid_number, value)
+					break;
+			}
+		}
+	}
 
-  if (found) {
-    //tech_pvt->callid_number[0]='\0';
-    switch_mutex_unlock(globals.mutex);
-    return 0;
-  }
-  DEBUGA_SKYPE("NOT FOUND\n", SKYPIAX_P_LOG);
+	if (found) {
+		//tech_pvt->callid_number[0]='\0';
+		switch_mutex_unlock(globals.mutex);
+		return 0;
+	}
+	DEBUGA_SKYPE("NOT FOUND\n", SKYPIAX_P_LOG);
 
-  if (tech_pvt && tech_pvt->skype_call_id && !strlen(tech_pvt->skype_call_id)) {
-    /* we are not inside an active call */
+	if (tech_pvt && tech_pvt->skype_call_id && !strlen(tech_pvt->skype_call_id)) {
+		/* we are not inside an active call */
 
-    sprintf(msg_to_skype, "GET CALL %s PARTNER_DISPNAME", id);
-    skypiax_signaling_write(tech_pvt, msg_to_skype);
-    switch_sleep(10000);
-    sprintf(msg_to_skype, "ALTER CALL %s ANSWER", id);
-    skypiax_signaling_write(tech_pvt, msg_to_skype);
-    DEBUGA_SKYPE("We answered a Skype RING on skype_call %s\n", SKYPIAX_P_LOG, id);
-    //FIXME write a timestamp here
-    gettimeofday(&tech_pvt->answer_time, NULL);
-    switch_copy_string(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1);
+		sprintf(msg_to_skype, "GET CALL %s PARTNER_DISPNAME", id);
+		skypiax_signaling_write(tech_pvt, msg_to_skype);
+		switch_sleep(10000);
+		sprintf(msg_to_skype, "ALTER CALL %s ANSWER", id);
+		skypiax_signaling_write(tech_pvt, msg_to_skype);
+		DEBUGA_SKYPE("We answered a Skype RING on skype_call %s\n", SKYPIAX_P_LOG, id);
+		//FIXME write a timestamp here
+		gettimeofday(&tech_pvt->answer_time, NULL);
+		switch_copy_string(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1);
 
-    switch_copy_string(tech_pvt->callid_number, value,
-                       sizeof(tech_pvt->callid_number) - 1);
+		switch_copy_string(tech_pvt->callid_number, value, sizeof(tech_pvt->callid_number) - 1);
 
-    DEBUGA_SKYPE
-      ("NEW!  name: %s, state: %d, value=%s, tech_pvt->callid_number=%s, tech_pvt->skype_user=%s\n",
-       SKYPIAX_P_LOG, tech_pvt->name, tech_pvt->interface_state, value,
-       tech_pvt->callid_number, tech_pvt->skype_user);
-  } else if (!tech_pvt || !tech_pvt->skype_call_id) {
-    ERRORA("No Call ID?\n", SKYPIAX_P_LOG);
-  } else {
-    ERRORA("We're in a call now %s\n", SKYPIAX_P_LOG, tech_pvt->skype_call_id);
-  }
+		DEBUGA_SKYPE
+			("NEW!  name: %s, state: %d, value=%s, tech_pvt->callid_number=%s, tech_pvt->skype_user=%s\n",
+			 SKYPIAX_P_LOG, tech_pvt->name, tech_pvt->interface_state, value, tech_pvt->callid_number, tech_pvt->skype_user);
+	} else if (!tech_pvt || !tech_pvt->skype_call_id) {
+		ERRORA("No Call ID?\n", SKYPIAX_P_LOG);
+	} else {
+		ERRORA("We're in a call now %s\n", SKYPIAX_P_LOG, tech_pvt->skype_call_id);
+	}
 
-  switch_mutex_unlock(globals.mutex);
-  return 0;
+	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;
+	char msg_to_skype[1024];
+	int i;
+	int found = 0;
+	private_t *giovatech;
+	struct timeval timenow;
 
-  switch_mutex_lock(globals.mutex);
+	switch_mutex_lock(globals.mutex);
 
-  gettimeofday(&timenow, NULL);
-  for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
-    if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
+	gettimeofday(&timenow, NULL);
+	for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
+		if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
 
-      giovatech = &globals.SKYPIAX_INTERFACES[i];
-      //NOTICA("skype interface: %d, name: %s, state: %d, value=%s, giovatech->callid_number=%s, giovatech->skype_user=%s\n", SKYPIAX_P_LOG, i, giovatech->name, giovatech->interface_state, value, giovatech->callid_number, giovatech->skype_user);
-      //FIXME check a timestamp here
-      if (strlen(giovatech->skype_call_id) && (giovatech->interface_state != SKYPIAX_STATE_DOWN) && (!strcmp(giovatech->skype_user, tech_pvt->skype_user)) && (!strcmp(giovatech->callid_number, value)) && ((((timenow.tv_sec - giovatech->answer_time.tv_sec) * 1000000) + (timenow.tv_usec - giovatech->answer_time.tv_usec)) < 500000)) {   //0.5sec
-        found = 1;
-        DEBUGA_SKYPE
-          ("FOUND  (name=%s, giovatech->interface_state=%d != SKYPIAX_STATE_DOWN) && (giovatech->skype_user=%s == tech_pvt->skype_user=%s) && (giovatech->callid_number=%s == value=%s)\n",
-           SKYPIAX_P_LOG, giovatech->name, giovatech->interface_state,
-           giovatech->skype_user, tech_pvt->skype_user, giovatech->callid_number, value)
-          break;
-      }
-    }
-  }
+			giovatech = &globals.SKYPIAX_INTERFACES[i];
+			//NOTICA("skype interface: %d, name: %s, state: %d, value=%s, giovatech->callid_number=%s, giovatech->skype_user=%s\n", SKYPIAX_P_LOG, i, giovatech->name, giovatech->interface_state, value, giovatech->callid_number, giovatech->skype_user);
+			//FIXME check a timestamp here
+			if (strlen(giovatech->skype_call_id) && (giovatech->interface_state != SKYPIAX_STATE_DOWN) && (!strcmp(giovatech->skype_user, tech_pvt->skype_user)) && (!strcmp(giovatech->callid_number, value)) && ((((timenow.tv_sec - giovatech->answer_time.tv_sec) * 1000000) + (timenow.tv_usec - giovatech->answer_time.tv_usec)) < 500000)) {	//0.5sec
+				found = 1;
+				DEBUGA_SKYPE
+					("FOUND  (name=%s, giovatech->interface_state=%d != SKYPIAX_STATE_DOWN) && (giovatech->skype_user=%s == tech_pvt->skype_user=%s) && (giovatech->callid_number=%s == value=%s)\n",
+					 SKYPIAX_P_LOG, giovatech->name, giovatech->interface_state,
+					 giovatech->skype_user, tech_pvt->skype_user, giovatech->callid_number, value)
+					break;
+			}
+		}
+	}
 
-  if (found) {
-    //tech_pvt->callid_number[0]='\0';
-    switch_mutex_unlock(globals.mutex);
-    return 0;
-  }
-  DEBUGA_SKYPE("NOT FOUND\n", SKYPIAX_P_LOG);
+	if (found) {
+		//tech_pvt->callid_number[0]='\0';
+		switch_mutex_unlock(globals.mutex);
+		return 0;
+	}
+	DEBUGA_SKYPE("NOT FOUND\n", SKYPIAX_P_LOG);
 
-  if (!tech_pvt || !tech_pvt->skype_call_id || !strlen(tech_pvt->skype_call_id)) {
-    /* we are not inside an active call */
-	  ERRORA("We're NO MORE in a call now %s\n", SKYPIAX_P_LOG, (tech_pvt && tech_pvt->skype_call_id) ? tech_pvt->skype_call_id : "" );
-    switch_mutex_unlock(globals.mutex);
+	if (!tech_pvt || !tech_pvt->skype_call_id || !strlen(tech_pvt->skype_call_id)) {
+		/* we are not inside an active call */
+		ERRORA("We're NO MORE in a call now %s\n", SKYPIAX_P_LOG, (tech_pvt && tech_pvt->skype_call_id) ? tech_pvt->skype_call_id : "");
+		switch_mutex_unlock(globals.mutex);
 
-  } else {
+	} else {
 
-    /* we're owned, we're in a call, let's try to transfer */
-        /************************** TODO
+		/* 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
 		  -> GET CALL 288 CAN_TRANSFER Test2
 		  <- CALL 288 CAN_TRANSFER test2 TRUE
 		 **********************************/
 
-    private_t *available_skypiax_interface = NULL;
+		private_t *available_skypiax_interface = NULL;
 
-    gettimeofday(&timenow, NULL);
-    for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
-      if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
+		gettimeofday(&timenow, NULL);
+		for (i = 0; !found && i < SKYPIAX_MAX_INTERFACES; i++) {
+			if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
 
-        giovatech = &globals.SKYPIAX_INTERFACES[i];
-        //NOTICA("skype interface: %d, name: %s, state: %d, value=%s, giovatech->callid_number=%s, giovatech->skype_user=%s\n", SKYPIAX_P_LOG, i, giovatech->name, giovatech->interface_state, value, giovatech->callid_number, giovatech->skype_user);
-        //FIXME check a timestamp here
-        if (strlen(giovatech->skype_transfer_call_id) && (giovatech->interface_state != SKYPIAX_STATE_DOWN) && (!strcmp(giovatech->skype_user, tech_pvt->skype_user)) && (!strcmp(giovatech->transfer_callid_number, value)) && ((((timenow.tv_sec - giovatech->transfer_time.tv_sec) * 1000000) + (timenow.tv_usec - giovatech->transfer_time.tv_usec)) < 1000000)) {  //1.0 sec
-          found = 1;
-          DEBUGA_SKYPE
-            ("FOUND  (name=%s, giovatech->interface_state=%d != SKYPIAX_STATE_DOWN) && (giovatech->skype_user=%s == tech_pvt->skype_user=%s) && (giovatech->transfer_callid_number=%s == value=%s)\n",
-             SKYPIAX_P_LOG, giovatech->name, giovatech->interface_state,
-             giovatech->skype_user, tech_pvt->skype_user,
-             giovatech->transfer_callid_number, value)
-            break;
-        }
-      }
-    }
+				giovatech = &globals.SKYPIAX_INTERFACES[i];
+				//NOTICA("skype interface: %d, name: %s, state: %d, value=%s, giovatech->callid_number=%s, giovatech->skype_user=%s\n", SKYPIAX_P_LOG, i, giovatech->name, giovatech->interface_state, value, giovatech->callid_number, giovatech->skype_user);
+				//FIXME check a timestamp here
+				if (strlen(giovatech->skype_transfer_call_id) && (giovatech->interface_state != SKYPIAX_STATE_DOWN) && (!strcmp(giovatech->skype_user, tech_pvt->skype_user)) && (!strcmp(giovatech->transfer_callid_number, value)) && ((((timenow.tv_sec - giovatech->transfer_time.tv_sec) * 1000000) + (timenow.tv_usec - giovatech->transfer_time.tv_usec)) < 1000000)) {	//1.0 sec
+					found = 1;
+					DEBUGA_SKYPE
+						("FOUND  (name=%s, giovatech->interface_state=%d != SKYPIAX_STATE_DOWN) && (giovatech->skype_user=%s == tech_pvt->skype_user=%s) && (giovatech->transfer_callid_number=%s == value=%s)\n",
+						 SKYPIAX_P_LOG, giovatech->name, giovatech->interface_state,
+						 giovatech->skype_user, tech_pvt->skype_user, giovatech->transfer_callid_number, value)
+						break;
+				}
+			}
+		}
 
-    if (found) {
-      //tech_pvt->callid_number[0]='\0';
-      switch_mutex_unlock(globals.mutex);
-      return 0;
-    }
-    DEBUGA_SKYPE("NOT FOUND\n", SKYPIAX_P_LOG);
+		if (found) {
+			//tech_pvt->callid_number[0]='\0';
+			switch_mutex_unlock(globals.mutex);
+			return 0;
+		}
+		DEBUGA_SKYPE("NOT FOUND\n", 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 */
+		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(&tech_pvt->transfer_time, NULL);
-      switch_copy_string(tech_pvt->skype_transfer_call_id, id,
-                         sizeof(tech_pvt->skype_transfer_call_id) - 1);
+			//FIXME write a timestamp here
+			gettimeofday(&tech_pvt->transfer_time, NULL);
+			switch_copy_string(tech_pvt->skype_transfer_call_id, id, sizeof(tech_pvt->skype_transfer_call_id) - 1);
 
-      switch_copy_string(tech_pvt->transfer_callid_number, value,
-                         sizeof(tech_pvt->transfer_callid_number) - 1);
+			switch_copy_string(tech_pvt->transfer_callid_number, value, sizeof(tech_pvt->transfer_callid_number) - 1);
 
-      DEBUGA_SKYPE
-        ("Let's transfer the skype_call %s to %s interface (with skype_user: %s), because we are already in a skypiax call(%s)\n",
-         SKYPIAX_P_LOG, tech_pvt->skype_call_id, available_skypiax_interface->name,
-         available_skypiax_interface->skype_user, id);
-      sprintf(msg_to_skype, "ALTER CALL %s TRANSFER %s", id,
-              available_skypiax_interface->skype_user);
-      skypiax_signaling_write(tech_pvt, msg_to_skype);
-    } else {
-      /* no skypiax interfaces idle, do nothing */
-      DEBUGA_SKYPE
-        ("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",
-         SKYPIAX_P_LOG, tech_pvt->skype_call_id, id);
-      //sprintf(msg_to_skype, "ALTER CALL %s END HANGUP", id);
-    }
-    switch_sleep(10000);
-    DEBUGA_SKYPE
-      ("We (%s) have NOT answered a Skype RING on skype_call %s, because we are already in a skypiax call\n",
-       SKYPIAX_P_LOG, tech_pvt->skype_call_id, id);
+			DEBUGA_SKYPE
+				("Let's transfer the skype_call %s to %s interface (with skype_user: %s), because we are already in a skypiax call(%s)\n",
+				 SKYPIAX_P_LOG, tech_pvt->skype_call_id, available_skypiax_interface->name, available_skypiax_interface->skype_user, id);
+			sprintf(msg_to_skype, "ALTER CALL %s TRANSFER %s", id, available_skypiax_interface->skype_user);
+			skypiax_signaling_write(tech_pvt, msg_to_skype);
+		} else {
+			/* no skypiax interfaces idle, do nothing */
+			DEBUGA_SKYPE
+				("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",
+				 SKYPIAX_P_LOG, tech_pvt->skype_call_id, id);
+			//sprintf(msg_to_skype, "ALTER CALL %s END HANGUP", id);
+		}
+		switch_sleep(10000);
+		DEBUGA_SKYPE
+			("We (%s) have NOT answered a Skype RING on skype_call %s, because we are already in a skypiax call\n",
+			 SKYPIAX_P_LOG, tech_pvt->skype_call_id, id);
 
-    switch_mutex_unlock(globals.mutex);
-  }
-  return 0;
+		switch_mutex_unlock(globals.mutex);
+	}
+	return 0;
 }
 
 /* For Emacs:

Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h (14443 => 14444)


--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h	2009-08-01 01:02:02 UTC (rev 14443)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax.h	2009-08-01 02:47:35 UTC (rev 14444)
@@ -58,19 +58,19 @@
 #endif /* SKYPIAX_SVN_VERSION */
 
 typedef enum {
-  TFLAG_IO = (1 << 0),
-  TFLAG_INBOUND = (1 << 1),
-  TFLAG_OUTBOUND = (1 << 2),
-  TFLAG_DTMF = (1 << 3),
-  TFLAG_VOICE = (1 << 4),
-  TFLAG_HANGUP = (1 << 5),
-  TFLAG_LINEAR = (1 << 6),
-  TFLAG_CODEC = (1 << 7),
-  TFLAG_BREAK = (1 << 8)
+	TFLAG_IO = (1 << 0),
+	TFLAG_INBOUND = (1 << 1),
+	TFLAG_OUTBOUND = (1 << 2),
+	TFLAG_DTMF = (1 << 3),
+	TFLAG_VOICE = (1 << 4),
+	TFLAG_HANGUP = (1 << 5),
+	TFLAG_LINEAR = (1 << 6),
+	TFLAG_CODEC = (1 << 7),
+	TFLAG_BREAK = (1 << 8)
 } TFLAGS;
 
 typedef enum {
-  GFLAG_MY_CODEC_PREFS = (1 << 0)
+	GFLAG_MY_CODEC_PREFS = (1 << 0)
 } GFLAGS;
 
 #define DEBUGA_SKYPE(...)  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, 		"rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][DEBUG_SKYPE  %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
@@ -135,116 +135,116 @@
 
 #ifndef WIN32
 struct SkypiaxHandles {
-  Window skype_win;
-  Display *disp;
-  Window win;
-  int currentuserhandle;
-  int api_connected;
-  int fdesc[2];
+	Window skype_win;
+	Display *disp;
+	Window win;
+	int currentuserhandle;
+	int api_connected;
+	int fdesc[2];
 };
 #else //WIN32
 
 struct SkypiaxHandles {
-  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 currentuserhandle;
-  int api_connected;
-  switch_file_t *fdesc[2];
+	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 currentuserhandle;
+	int api_connected;
+	switch_file_t *fdesc[2];
 };
 
 #endif //WIN32
 
 struct private_object {
-  unsigned int flags;
-  switch_codec_t read_codec;
-  switch_codec_t write_codec;
-  switch_frame_t read_frame;
-  unsigned char databuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
-  char session_uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
-  switch_caller_profile_t *caller_profile;
-  switch_mutex_t *mutex;
-  switch_mutex_t *flag_mutex;
+	unsigned int flags;
+	switch_codec_t read_codec;
+	switch_codec_t write_codec;
+	switch_frame_t read_frame;
+	unsigned char databuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
+	char session_uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
+	switch_caller_profile_t *caller_profile;
+	switch_mutex_t *mutex;
+	switch_mutex_t *flag_mutex;
 
-  char interface_id[80];
-  char name[80];
-  char dialplan[80];
-  char context[80];
-  char dial_regex[256];
-  char fail_dial_regex[256];
-  char hold_music[256];
-  char type[256];
-  char X11_display[256];
+	char interface_id[80];
+	char name[80];
+	char dialplan[80];
+	char context[80];
+	char dial_regex[256];
+	char fail_dial_regex[256];
+	char hold_music[256];
+	char type[256];
+	char X11_display[256];
 #ifdef WIN32
-  unsigned short tcp_cli_port;
-  unsigned short tcp_srv_port;
+	unsigned short tcp_cli_port;
+	unsigned short tcp_srv_port;
 #else
-  int tcp_cli_port;
-  int tcp_srv_port;
+	int tcp_cli_port;
+	int tcp_srv_port;
 #endif
-  struct SkypiaxHandles SkypiaxHandles;
+	struct SkypiaxHandles SkypiaxHandles;
 
-  int interface_state;          /*!< \brief 'state' of the interface (channel) */
-  char language[80];            /*!< \brief default Asterisk dialplan language for this interface */
-  char exten[80];               /*!< \brief default Asterisk dialplan extension for this interface */
-  int skypiax_sound_rate;       /*!< \brief rate of the sound device, in Hz, eg: 8000 */
-  char callid_name[50];
-  char callid_number[50];
-  double playback_boost;
-  double capture_boost;
-  int stripmsd;
-  char skype_call_id[512];
-  int skype_call_ongoing;
-  char skype_friends[4096];
-  char skype_fullname[512];
-  char skype_displayname[512];
-  int skype_callflow;           /*!< \brief 'callflow' of the skype interface (as opposed to phone interface) */
-  int skype;                    /*!< \brief config flag, bool, Skype support on this interface (0 if false, -1 if true) */
-  int control_to_send;
+	int interface_state;		/*!< \brief 'state' of the interface (channel) */
+	char language[80];			/*!< \brief default Asterisk dialplan language for this interface */
+	char exten[80];				/*!< \brief default Asterisk dialplan extension for this interface */
+	int skypiax_sound_rate;		/*!< \brief rate of the sound device, in Hz, eg: 8000 */
+	char callid_name[50];
+	char callid_number[50];
+	double playback_boost;
+	double capture_boost;
+	int stripmsd;
+	char skype_call_id[512];
+	int skype_call_ongoing;
+	char skype_friends[4096];
+	char skype_fullname[512];
+	char skype_displayname[512];
+	int skype_callflow;			/*!< \brief 'callflow' of the skype interface (as opposed to phone interface) */
+	int skype;					/*!< \brief config flag, bool, Skype support on this interface (0 if false, -1 if true) */
+	int control_to_send;
 #ifdef WIN32
-  switch_file_t *audiopipe[2];
-  switch_file_t *audioskypepipe[2];
-  switch_file_t *skypiax_sound_capt_fd; /*!< \brief file descriptor for sound capture dev */
-#else                           /* WIN32 */
-  int audiopipe[2];
-  int audioskypepipe[2];
-  int skypiax_sound_capt_fd;    /*!< \brief file descriptor for sound capture dev */
-#endif                          /* WIN32 */
-  switch_thread_t *tcp_srv_thread;
-  switch_thread_t *tcp_cli_thread;
-  switch_thread_t *skypiax_signaling_thread;
-  switch_thread_t *skypiax_api_thread;
-  short audiobuf[SAMPLES_PER_FRAME];
-  int audiobuf_is_loaded;
+	switch_file_t *audiopipe[2];
+	switch_file_t *audioskypepipe[2];
+	switch_file_t *skypiax_sound_capt_fd;	/*!< \brief file descriptor for sound capture dev */
+#else							/* WIN32 */
+	int audiopipe[2];
+	int audioskypepipe[2];
+	int skypiax_sound_capt_fd;	/*!< \brief file descriptor for sound capture dev */
+#endif							/* WIN32 */
+	switch_thread_t *tcp_srv_thread;
+	switch_thread_t *tcp_cli_thread;
+	switch_thread_t *skypiax_signaling_thread;
+	switch_thread_t *skypiax_api_thread;
+	short audiobuf[SAMPLES_PER_FRAME];
+	int audiobuf_is_loaded;
 
-  //int phonebook_listing;
-  //int phonebook_querying;
-  //int phonebook_listing_received_calls;
+	//int phonebook_listing;
+	//int phonebook_querying;
+	//int phonebook_listing_received_calls;
 
-  //int phonebook_first_entry;
-  //int phonebook_last_entry;
-  //int phonebook_number_lenght;
-  //int phonebook_text_lenght;
-  FILE *phonebook_writing_fp;
-  int skypiax_dir_entry_extension_prefix;
-  char skype_user[256];
-  char skype_password[256];
-  char destination[256];
-  struct timeval answer_time;
+	//int phonebook_first_entry;
+	//int phonebook_last_entry;
+	//int phonebook_number_lenght;
+	//int phonebook_text_lenght;
+	FILE *phonebook_writing_fp;
+	int skypiax_dir_entry_extension_prefix;
+	char skype_user[256];
+	char skype_password[256];
+	char destination[256];
+	struct timeval answer_time;
 
-  struct timeval transfer_time;
-  char transfer_callid_number[50];
-  char skype_transfer_call_id[512];
-  int running;
+	struct timeval transfer_time;
+	char transfer_callid_number[50];
+	char skype_transfer_call_id[512];
+	int running;
 };
 
 typedef struct private_object private_t;
 
 void *SWITCH_THREAD_FUNC skypiax_api_thread_func(switch_thread_t * thread, void *obj);
-void skypiax_tech_init(private_t * tech_pvt, switch_core_session_t * session);
+void skypiax_tech_init(private_t * tech_pvt, switch_core_session_t *session);
 int skypiax_audio_read(private_t * tech_pvt);
 int skypiax_audio_init(private_t * tech_pvt);
 int skypiax_signaling_write(private_t * tech_pvt, char *msg_to_skype);

Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c (14443 => 14444)


--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	2009-08-01 01:02:02 UTC (rev 14443)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	2009-08-01 02:47:35 UTC (rev 14444)
@@ -27,844 +27,791 @@
 /*************************************/
 int skypiax_signaling_read(private_t * tech_pvt)
 {
-  char read_from_pipe[4096];
-  char message[4096];
-  char message_2[4096];
-  char *buf, obj[512] = "", id[512] = "", prop[512] = "", value[512] = "", *where;
-  char **stringp = NULL;
-  int a;
-  unsigned int howmany;
-  unsigned int i;
+	char read_from_pipe[4096];
+	char message[4096];
+	char message_2[4096];
+	char *buf, obj[512] = "", id[512] = "", prop[512] = "", value[512] = "", *where;
+	char **stringp = NULL;
+	int a;
+	unsigned int howmany;
+	unsigned int i;
 
-  memset(read_from_pipe, 0, 4096);
-  memset(message, 0, 4096);
-  memset(message_2, 0, 4096);
+	memset(read_from_pipe, 0, 4096);
+	memset(message, 0, 4096);
+	memset(message_2, 0, 4096);
 
-  howmany =
-    skypiax_pipe_read(tech_pvt->SkypiaxHandles.fdesc[0], (short *) read_from_pipe,
-                      sizeof(read_from_pipe));
+	howmany = skypiax_pipe_read(tech_pvt->SkypiaxHandles.fdesc[0], (short *) read_from_pipe, sizeof(read_from_pipe));
 
-  a = 0;
-  for (i = 0; i < howmany; i++) {
-    message[a] = read_from_pipe[i];
-    a++;
+	a = 0;
+	for (i = 0; i < howmany; i++) {
+		message[a] = read_from_pipe[i];
+		a++;
 
-    if (read_from_pipe[i] == '\0') {
+		if (read_from_pipe[i] == '\0') {
 
-      if (!strstr(message, "DURATION")) {
-        DEBUGA_SKYPE("READING: |||%s||| \n", SKYPIAX_P_LOG, message);
-      }
+			if (!strstr(message, "DURATION")) {
+				DEBUGA_SKYPE("READING: |||%s||| \n", SKYPIAX_P_LOG, message);
+			}
 
-      if (!strcasecmp(message, "ERROR 68")) {
-        DEBUGA_SKYPE
-          ("If I don't connect immediately, please give the Skype client authorization to be connected by Skypiax (and to not ask you again)\n",
-           SKYPIAX_P_LOG);
-        skypiax_sleep(1000000);
-        skypiax_signaling_write(tech_pvt, "PROTOCOL 7");
-        skypiax_sleep(10000);
-        return 0;
-      }
-      if (!strncasecmp(message, "ERROR 92 CALL", 12)) {
-        ERRORA
-          ("Skype got ERROR: |||%s|||, the (skypeout) number we called was not recognized as valid\n",
-           SKYPIAX_P_LOG, message);
-        tech_pvt->skype_callflow = CALLFLOW_STATUS_FINISHED;
-        DEBUGA_SKYPE("skype_call now is DOWN\n", SKYPIAX_P_LOG);
-        tech_pvt->skype_call_id[0] = '\0';
+			if (!strcasecmp(message, "ERROR 68")) {
+				DEBUGA_SKYPE
+					("If I don't connect immediately, please give the Skype client authorization to be connected by Skypiax (and to not ask you again)\n",
+					 SKYPIAX_P_LOG);
+				skypiax_sleep(1000000);
+				skypiax_signaling_write(tech_pvt, "PROTOCOL 7");
+				skypiax_sleep(10000);
+				return 0;
+			}
+			if (!strncasecmp(message, "ERROR 92 CALL", 12)) {
+				ERRORA("Skype got ERROR: |||%s|||, the (skypeout) number we called was not recognized as valid\n", SKYPIAX_P_LOG, message);
+				tech_pvt->skype_callflow = CALLFLOW_STATUS_FINISHED;
+				DEBUGA_SKYPE("skype_call now is DOWN\n", SKYPIAX_P_LOG);
+				tech_pvt->skype_call_id[0] = '\0';
 
-        if (tech_pvt->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
-          tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
-          return CALLFLOW_INCOMING_HANGUP;
-        } else {
-          tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
-        }
-      }
-      skypiax_strncpy(message_2, message, sizeof(message) - 1);
-      buf = message;
-      stringp = &buf;
-      where = strsep(stringp, " ");
-      if (!where) {
-        WARNINGA("Skype MSG without spaces: %s\n", SKYPIAX_P_LOG, message);
-      }
-      if (!strcasecmp(message, "ERROR")) {
-        if (!strncasecmp(message, "ERROR 592 ALTER CALL", 19)) {
-          ERRORA("Skype got ERROR about TRANSFERRING, no problem: |||%s|||\n",
-                 SKYPIAX_P_LOG, message);
-        } else {
-          DEBUGA_SKYPE("Skype got ERROR: |||%s|||\n", SKYPIAX_P_LOG, message);
-          tech_pvt->skype_callflow = CALLFLOW_STATUS_FINISHED;
-          DEBUGA_SKYPE("skype_call now is DOWN\n", SKYPIAX_P_LOG);
-          tech_pvt->skype_call_id[0] = '\0';
+				if (tech_pvt->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
+					tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
+					return CALLFLOW_INCOMING_HANGUP;
+				} else {
+					tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
+				}
+			}
+			skypiax_strncpy(message_2, message, sizeof(message) - 1);
+			buf = message;
+			stringp = &buf;
+			where = strsep(stringp, " ");
+			if (!where) {
+				WARNINGA("Skype MSG without spaces: %s\n", SKYPIAX_P_LOG, message);
+			}
+			if (!strcasecmp(message, "ERROR")) {
+				if (!strncasecmp(message, "ERROR 592 ALTER CALL", 19)) {
+					ERRORA("Skype got ERROR about TRANSFERRING, no problem: |||%s|||\n", SKYPIAX_P_LOG, message);
+				} else {
+					DEBUGA_SKYPE("Skype got ERROR: |||%s|||\n", SKYPIAX_P_LOG, message);
+					tech_pvt->skype_callflow = CALLFLOW_STATUS_FINISHED;
+					DEBUGA_SKYPE("skype_call now is DOWN\n", SKYPIAX_P_LOG);
+					tech_pvt->skype_call_id[0] = '\0';
 
-          if (tech_pvt->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
-            tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
-            return CALLFLOW_INCOMING_HANGUP;
-          } else {
-            tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
-          }
-        }
-      }
-      if (!strcasecmp(message, "CURRENTUSERHANDLE")) {
-        skypiax_strncpy(obj, where, sizeof(obj) - 1);
-        where = strsep(stringp, " ");
-        skypiax_strncpy(id, where, sizeof(id) - 1);
-        if (!strcasecmp(id, tech_pvt->skype_user)) {
-          tech_pvt->SkypiaxHandles.currentuserhandle = 1;
-          DEBUGA_SKYPE
-            ("Skype MSG: message: %s, currentuserhandle: %s, cuh: %s, skype_user: %s!\n",
-             SKYPIAX_P_LOG, message, obj, id, tech_pvt->skype_user);
-        }
-      }
-      if (!strcasecmp(message, "USER")) {
-        skypiax_strncpy(obj, where, sizeof(obj) - 1);
-        where = strsep(stringp, " ");
-        skypiax_strncpy(id, where, sizeof(id) - 1);
-        where = strsep(stringp, " ");
-        skypiax_strncpy(prop, where, sizeof(prop) - 1);
-        if (!strcasecmp(prop, "RECEIVEDAUTHREQUEST")) {
-          char msg_to_skype[256];
-          DEBUGA_SKYPE("Skype MSG: message: %s, obj: %s, id: %s, prop: %s!\n",
-                       SKYPIAX_P_LOG, message, obj, id, prop);
-          //TODO: allow authorization based on config param
-          sprintf(msg_to_skype, "SET USER %s ISAUTHORIZED TRUE", id);
-          skypiax_signaling_write(tech_pvt, msg_to_skype);
-        }
-      }
-      if (!strcasecmp(message, "MESSAGE")) {
-        skypiax_strncpy(obj, where, sizeof(obj) - 1);
-        where = strsep(stringp, " ");
-        skypiax_strncpy(id, where, sizeof(id) - 1);
-        where = strsep(stringp, " ");
-        skypiax_strncpy(prop, where, sizeof(prop) - 1);
-        if (!strcasecmp(prop, "STATUS")) {
-          where = strsep(stringp, " ");
-          skypiax_strncpy(value, where, sizeof(value) - 1);
-          if (!strcasecmp(value, "RECEIVED")) {
-            char msg_to_skype[256];
-            DEBUGA_SKYPE("Skype MSG: message: %s, obj: %s, id: %s, prop: %s value: %s!\n",
-                         SKYPIAX_P_LOG, message, obj, id, prop, value);
-            //TODO: authomatically flag messages as read based on config param
-            sprintf(msg_to_skype, "SET MESSAGE %s SEEN", id);
-            skypiax_signaling_write(tech_pvt, msg_to_skype);
-          }
-        } else if (!strcasecmp(prop, "BODY")) {
-          char msg_to_skype[256];
-          DEBUGA_SKYPE("Skype MSG: message: %s, obj: %s, id: %s, prop: %s!\n",
-                       SKYPIAX_P_LOG, message, obj, id, prop);
-          //TODO: authomatically flag messages as read based on config param
-          sprintf(msg_to_skype, "SET MESSAGE %s SEEN", id);
-          skypiax_signaling_write(tech_pvt, msg_to_skype);
-        }
-      }
-      if (!strcasecmp(message, "CALL")) {
-        skypiax_strncpy(obj, where, sizeof(obj) - 1);
-        where = strsep(stringp, " ");
-        skypiax_strncpy(id, where, sizeof(id) - 1);
-        where = strsep(stringp, " ");
-        skypiax_strncpy(prop, where, sizeof(prop) - 1);
-        where = strsep(stringp, " ");
-        skypiax_strncpy(value, where, sizeof(value) - 1);
-        where = strsep(stringp, " ");
+					if (tech_pvt->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
+						tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
+						return CALLFLOW_INCOMING_HANGUP;
+					} else {
+						tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
+					}
+				}
+			}
+			if (!strcasecmp(message, "CURRENTUSERHANDLE")) {
+				skypiax_strncpy(obj, where, sizeof(obj) - 1);
+				where = strsep(stringp, " ");
+				skypiax_strncpy(id, where, sizeof(id) - 1);
+				if (!strcasecmp(id, tech_pvt->skype_user)) {
+					tech_pvt->SkypiaxHandles.currentuserhandle = 1;
+					DEBUGA_SKYPE
+						("Skype MSG: message: %s, currentuserhandle: %s, cuh: %s, skype_user: %s!\n",
+						 SKYPIAX_P_LOG, message, obj, id, tech_pvt->skype_user);
+				}
+			}
+			if (!strcasecmp(message, "USER")) {
+				skypiax_strncpy(obj, where, sizeof(obj) - 1);
+				where = strsep(stringp, " ");
+				skypiax_strncpy(id, where, sizeof(id) - 1);
+				where = strsep(stringp, " ");
+				skypiax_strncpy(prop, where, sizeof(prop) - 1);
+				if (!strcasecmp(prop, "RECEIVEDAUTHREQUEST")) {
+					char msg_to_skype[256];
+					DEBUGA_SKYPE("Skype MSG: message: %s, obj: %s, id: %s, prop: %s!\n", SKYPIAX_P_LOG, message, obj, id, prop);
+					//TODO: allow authorization based on config param
+					sprintf(msg_to_skype, "SET USER %s ISAUTHORIZED TRUE", id);
+					skypiax_signaling_write(tech_pvt, msg_to_skype);
+				}
+			}
+			if (!strcasecmp(message, "MESSAGE")) {
+				skypiax_strncpy(obj, where, sizeof(obj) - 1);
+				where = strsep(stringp, " ");
+				skypiax_strncpy(id, where, sizeof(id) - 1);
+				where = strsep(stringp, " ");
+				skypiax_strncpy(prop, where, sizeof(prop) - 1);
+				if (!strcasecmp(prop, "STATUS")) {
+					where = strsep(stringp, " ");
+					skypiax_strncpy(value, where, sizeof(value) - 1);
+					if (!strcasecmp(value, "RECEIVED")) {
+						char msg_to_skype[256];
+						DEBUGA_SKYPE("Skype MSG: message: %s, obj: %s, id: %s, prop: %s value: %s!\n", SKYPIAX_P_LOG, message, obj, id, prop, value);
+						//TODO: authomatically flag messages as read based on config param
+						sprintf(msg_to_skype, "SET MESSAGE %s SEEN", id);
+						skypiax_signaling_write(tech_pvt, msg_to_skype);
+					}
+				} else if (!strcasecmp(prop, "BODY")) {
+					char msg_to_skype[256];
+					DEBUGA_SKYPE("Skype MSG: message: %s, obj: %s, id: %s, prop: %s!\n", SKYPIAX_P_LOG, message, obj, id, prop);
+					//TODO: authomatically flag messages as read based on config param
+					sprintf(msg_to_skype, "SET MESSAGE %s SEEN", id);
+					skypiax_signaling_write(tech_pvt, msg_to_skype);
+				}
+			}
+			if (!strcasecmp(message, "CALL")) {
+				skypiax_strncpy(obj, where, sizeof(obj) - 1);
+				where = strsep(stringp, " ");
+				skypiax_strncpy(id, where, sizeof(id) - 1);
+				where = strsep(stringp, " ");
+				skypiax_strncpy(prop, where, sizeof(prop) - 1);
+				where = strsep(stringp, " ");
+				skypiax_strncpy(value, where, sizeof(value) - 1);
+				where = strsep(stringp, " ");
 
-        //DEBUGA_SKYPE
-        //("Skype MSG: message: %s, obj: %s, id: %s, prop: %s, value: %s,where: %s!\n",
-        //SKYPIAX_P_LOG, message, obj, id, prop, value, where ? where : "NULL");
+				//DEBUGA_SKYPE
+				//("Skype MSG: message: %s, obj: %s, id: %s, prop: %s, value: %s,where: %s!\n",
+				//SKYPIAX_P_LOG, message, obj, id, prop, value, where ? where : "NULL");
 
-        if (!strcasecmp(prop, "PARTNER_HANDLE")) {
-          if (!strlen(tech_pvt->skype_call_id)) {
-            /* we are NOT inside an active call */
-            DEBUGA_SKYPE("Call %s TRY ANSWER\n", SKYPIAX_P_LOG, id);
-            skypiax_answer(tech_pvt, id, value);
-          } else {
-            /* we are inside an active call */
-            if (!strcasecmp(tech_pvt->skype_call_id, id)) {
-              /* this is the call in which we are calling out */
-              DEBUGA_SKYPE("Call %s NOTHING\n", SKYPIAX_P_LOG, id);
-            } else {
-              skypiax_sleep(400000);    //0.4 seconds
-              DEBUGA_SKYPE("Call %s TRY TRANSFER\n", SKYPIAX_P_LOG, id);
-              skypiax_transfer(tech_pvt, id, value);
-            }
-          }
-        }
-        if (!strcasecmp(prop, "PARTNER_DISPNAME")) {
-          snprintf(tech_pvt->callid_name, sizeof(tech_pvt->callid_name) - 1, "%s%s%s",
-                   value, where ? " " : "", where ? where : "");
-          //DEBUGA_SKYPE
-          //("the skype_call %s caller PARTNER_DISPNAME (tech_pvt->callid_name) is: %s\n",
-          //SKYPIAX_P_LOG, id, tech_pvt->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 (tech_pvt->interface_state == SKYPIAX_STATE_DOWN)
-            tech_pvt->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 (tech_pvt->interface_state == SKYPIAX_STATE_DOWN)
-            tech_pvt->interface_state = SKYPIAX_STATE_PRERING;
-        }
-        if (!strcasecmp(prop, "DTMF")) {
-          DEBUGA_SKYPE("Call %s received a DTMF: %s\n", SKYPIAX_P_LOG, id, value);
-          dtmf_received(tech_pvt, value);
-        }
-        if (!strcasecmp(prop, "FAILUREREASON")) {
-          DEBUGA_SKYPE
-            ("Skype 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, tech_pvt->skype_call_id)) {
-            skypiax_strncpy(tech_pvt->skype_call_id, id,
-                            sizeof(tech_pvt->skype_call_id) - 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, "PARTNER_HANDLE")) {
+					if (!strlen(tech_pvt->skype_call_id)) {
+						/* we are NOT inside an active call */
+						DEBUGA_SKYPE("Call %s TRY ANSWER\n", SKYPIAX_P_LOG, id);
+						skypiax_answer(tech_pvt, id, value);
+					} else {
+						/* we are inside an active call */
+						if (!strcasecmp(tech_pvt->skype_call_id, id)) {
+							/* this is the call in which we are calling out */
+							DEBUGA_SKYPE("Call %s NOTHING\n", SKYPIAX_P_LOG, id);
+						} else {
+							skypiax_sleep(400000);	//0.4 seconds
+							DEBUGA_SKYPE("Call %s TRY TRANSFER\n", SKYPIAX_P_LOG, id);
+							skypiax_transfer(tech_pvt, id, value);
+						}
+					}
+				}
+				if (!strcasecmp(prop, "PARTNER_DISPNAME")) {
+					snprintf(tech_pvt->callid_name, sizeof(tech_pvt->callid_name) - 1, "%s%s%s", value, where ? " " : "", where ? where : "");
+					//DEBUGA_SKYPE
+					//("the skype_call %s caller PARTNER_DISPNAME (tech_pvt->callid_name) is: %s\n",
+					//SKYPIAX_P_LOG, id, tech_pvt->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 (tech_pvt->interface_state == SKYPIAX_STATE_DOWN)
+						tech_pvt->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 (tech_pvt->interface_state == SKYPIAX_STATE_DOWN)
+						tech_pvt->interface_state = SKYPIAX_STATE_PRERING;
+				}
+				if (!strcasecmp(prop, "DTMF")) {
+					DEBUGA_SKYPE("Call %s received a DTMF: %s\n", SKYPIAX_P_LOG, id, value);
+					dtmf_received(tech_pvt, value);
+				}
+				if (!strcasecmp(prop, "FAILUREREASON")) {
+					DEBUGA_SKYPE("Skype 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, tech_pvt->skype_call_id)) {
+						skypiax_strncpy(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 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(value, "RINGING")) {
-            char msg_to_skype[1024];
-            if (!strlen(tech_pvt->skype_call_id)) {
-              /* we are NOT inside an active call */
-              sprintf(msg_to_skype, "GET CALL %s PARTNER_HANDLE", id);
-              skypiax_signaling_write(tech_pvt, msg_to_skype);
-              skypiax_sleep(10000);
-            } else {
-              /* we are inside an active call */
-              if (!strcasecmp(tech_pvt->skype_call_id, id)) {
-                /* this is the call in which we are calling out */
-                tech_pvt->skype_callflow = CALLFLOW_STATUS_RINGING;
-                tech_pvt->interface_state = SKYPIAX_STATE_RINGING;
-                skypiax_strncpy(tech_pvt->skype_call_id, id,
-                                sizeof(tech_pvt->skype_call_id) - 1);
-                DEBUGA_SKYPE("Our remote party in skype_call %s is RINGING\n",
-                             SKYPIAX_P_LOG, id);
-                remote_party_is_ringing(tech_pvt);
-              } else {
-                sprintf(msg_to_skype, "GET CALL %s PARTNER_HANDLE", id);
-                skypiax_signaling_write(tech_pvt, msg_to_skype);
-                skypiax_sleep(10000);
-              }
-            }
-          } else if (!strcasecmp(value, "EARLYMEDIA")) {
-            char msg_to_skype[1024];
-            tech_pvt->skype_callflow = CALLFLOW_STATUS_EARLYMEDIA;
-            tech_pvt->interface_state = SKYPIAX_STATE_DIALING;
-            DEBUGA_SKYPE("Our remote party in skype_call %s is EARLYMEDIA\n",
-                         SKYPIAX_P_LOG, id);
-            start_audio_threads(tech_pvt);
-            skypiax_sleep(1000);
-            sprintf(msg_to_skype, "ALTER CALL %s SET_INPUT PORT=\"%d\"", id,
-                    tech_pvt->tcp_cli_port);
-            skypiax_signaling_write(tech_pvt, msg_to_skype);
-            sprintf(msg_to_skype, "#output ALTER CALL %s SET_OUTPUT PORT=\"%d\"", id,
-                    tech_pvt->tcp_srv_port);
-            skypiax_signaling_write(tech_pvt, msg_to_skype);
+					if (!strcasecmp(value, "RINGING")) {
+						char msg_to_skype[1024];
+						if (!strlen(tech_pvt->skype_call_id)) {
+							/* we are NOT inside an active call */
+							sprintf(msg_to_skype, "GET CALL %s PARTNER_HANDLE", id);
+							skypiax_signaling_write(tech_pvt, msg_to_skype);
+							skypiax_sleep(10000);
+						} else {
+							/* we are inside an active call */
+							if (!strcasecmp(tech_pvt->skype_call_id, id)) {
+								/* this is the call in which we are calling out */
+								tech_pvt->skype_callflow = CALLFLOW_STATUS_RINGING;
+								tech_pvt->interface_state = SKYPIAX_STATE_RINGING;
+								skypiax_strncpy(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1);
+								DEBUGA_SKYPE("Our remote party in skype_call %s is RINGING\n", SKYPIAX_P_LOG, id);
+								remote_party_is_ringing(tech_pvt);
+							} else {
+								sprintf(msg_to_skype, "GET CALL %s PARTNER_HANDLE", id);
+								skypiax_signaling_write(tech_pvt, msg_to_skype);
+								skypiax_sleep(10000);
+							}
+						}
+					} else if (!strcasecmp(value, "EARLYMEDIA")) {
+						char msg_to_skype[1024];
+						tech_pvt->skype_callflow = CALLFLOW_STATUS_EARLYMEDIA;
+						tech_pvt->interface_state = SKYPIAX_STATE_DIALING;
+						DEBUGA_SKYPE("Our remote party in skype_call %s is EARLYMEDIA\n", SKYPIAX_P_LOG, id);
+						start_audio_threads(tech_pvt);
+						skypiax_sleep(1000);
+						sprintf(msg_to_skype, "ALTER CALL %s SET_INPUT PORT=\"%d\"", id, tech_pvt->tcp_cli_port);
+						skypiax_signaling_write(tech_pvt, msg_to_skype);
+						sprintf(msg_to_skype, "#output ALTER CALL %s SET_OUTPUT PORT=\"%d\"", id, tech_pvt->tcp_srv_port);
+						skypiax_signaling_write(tech_pvt, msg_to_skype);
 
-            remote_party_is_early_media(tech_pvt);
-          } else if (!strcasecmp(value, "MISSED")) {
-            DEBUGA_SKYPE("We missed skype_call %s\n", SKYPIAX_P_LOG, id);
-          } else if (!strcasecmp(value, "FINISHED")) {
-            //DEBUGA_SKYPE("skype_call %s now is DOWN\n", SKYPIAX_P_LOG, id);
-            //usleep(150000);//150msec, let's give the TCP sockets time to timeout
-            if (!strcasecmp(tech_pvt->skype_call_id, id)) {
-              tech_pvt->skype_callflow = CALLFLOW_STATUS_FINISHED;
-              DEBUGA_SKYPE("skype_call %s is MY call, now I'm going DOWN\n",
-                           SKYPIAX_P_LOG, id);
-              tech_pvt->skype_call_id[0] = '\0';
-              if (tech_pvt->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
-                //tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
-                return CALLFLOW_INCOMING_HANGUP;
-              } else {
-                tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
-              }
-            } else {
-              DEBUGA_SKYPE("skype_call %s is NOT MY call, ignoring\n", SKYPIAX_P_LOG, id);
-            }
+						remote_party_is_early_media(tech_pvt);
+					} else if (!strcasecmp(value, "MISSED")) {
+						DEBUGA_SKYPE("We missed skype_call %s\n", SKYPIAX_P_LOG, id);
+					} else if (!strcasecmp(value, "FINISHED")) {
+						//DEBUGA_SKYPE("skype_call %s now is DOWN\n", SKYPIAX_P_LOG, id);
+						//usleep(150000);//150msec, let's give the TCP sockets time to timeout
+						if (!strcasecmp(tech_pvt->skype_call_id, id)) {
+							tech_pvt->skype_callflow = CALLFLOW_STATUS_FINISHED;
+							DEBUGA_SKYPE("skype_call %s is MY call, now I'm going DOWN\n", SKYPIAX_P_LOG, id);
+							tech_pvt->skype_call_id[0] = '\0';
+							if (tech_pvt->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
+								//tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
+								return CALLFLOW_INCOMING_HANGUP;
+							} else {
+								tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
+							}
+						} else {
+							DEBUGA_SKYPE("skype_call %s is NOT MY call, ignoring\n", SKYPIAX_P_LOG, id);
+						}
 
-          } else if (!strcasecmp(value, "CANCELLED")) {
-            tech_pvt->skype_callflow = CALLFLOW_STATUS_CANCELLED;
-            DEBUGA_SKYPE
-              ("we tried to call Skype on skype_call %s and Skype has now CANCELLED\n",
-               SKYPIAX_P_LOG, id);
-            tech_pvt->skype_call_id[0] = '\0';
-            if (tech_pvt->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
-              tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
-              return CALLFLOW_INCOMING_HANGUP;
-            } else {
-              tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
-            }
-          } else if (!strcasecmp(value, "FAILED")) {
-            tech_pvt->skype_callflow = CALLFLOW_STATUS_FAILED;
-            DEBUGA_SKYPE
-              ("we tried to call Skype on skype_call %s and Skype has now FAILED\n",
-               SKYPIAX_P_LOG, id);
-            tech_pvt->skype_call_id[0] = '\0';
-            skypiax_strncpy(tech_pvt->skype_call_id, id,
-                            sizeof(tech_pvt->skype_call_id) - 1);
-            tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
-            return CALLFLOW_INCOMING_HANGUP;
-          } else if (!strcasecmp(value, "REFUSED")) {
-            if (!strcasecmp(id, tech_pvt->skype_call_id)) {
-              /* this is the id of the call we are in, probably we generated it */
-              tech_pvt->skype_callflow = CALLFLOW_STATUS_REFUSED;
-              DEBUGA_SKYPE
-                ("we tried to call Skype on skype_call %s and Skype has now REFUSED\n",
-                 SKYPIAX_P_LOG, id);
-              skypiax_strncpy(tech_pvt->skype_call_id, id,
-                              sizeof(tech_pvt->skype_call_id) - 1);
-              tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
-              tech_pvt->skype_call_id[0] = '\0';
-              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, "TRANSFERRING")) {
-            DEBUGA_SKYPE("skype_call %s is transferring\n", SKYPIAX_P_LOG, id);
-          } else if (!strcasecmp(value, "TRANSFERRED")) {
-            DEBUGA_SKYPE("skype_call %s has been transferred\n", SKYPIAX_P_LOG, id);
-          } else if (!strcasecmp(value, "ROUTING")) {
-            tech_pvt->skype_callflow = CALLFLOW_STATUS_ROUTING;
-            tech_pvt->interface_state = SKYPIAX_STATE_DIALING;
-            skypiax_strncpy(tech_pvt->skype_call_id, id,
-                            sizeof(tech_pvt->skype_call_id) - 1);
-            DEBUGA_SKYPE("skype_call: %s is now ROUTING\n", SKYPIAX_P_LOG, id);
-          } else if (!strcasecmp(value, "UNPLACED")) {
-            tech_pvt->skype_callflow = CALLFLOW_STATUS_UNPLACED;
-            tech_pvt->interface_state = SKYPIAX_STATE_DIALING;
-            skypiax_strncpy(tech_pvt->skype_call_id, id,
-                            sizeof(tech_pvt->skype_call_id) - 1);
-            DEBUGA_SKYPE("skype_call: %s is now UNPLACED\n", SKYPIAX_P_LOG, id);
-          } else if (!strcasecmp(value, "INPROGRESS")) {
-            char msg_to_skype[1024];
+					} else if (!strcasecmp(value, "CANCELLED")) {
+						tech_pvt->skype_callflow = CALLFLOW_STATUS_CANCELLED;
+						DEBUGA_SKYPE("we tried to call Skype on skype_call %s and Skype has now CANCELLED\n", SKYPIAX_P_LOG, id);
+						tech_pvt->skype_call_id[0] = '\0';
+						if (tech_pvt->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) {
+							tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
+							return CALLFLOW_INCOMING_HANGUP;
+						} else {
+							tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
+						}
+					} else if (!strcasecmp(value, "FAILED")) {
+						tech_pvt->skype_callflow = CALLFLOW_STATUS_FAILED;
+						DEBUGA_SKYPE("we tried to call Skype on skype_call %s and Skype has now FAILED\n", SKYPIAX_P_LOG, id);
+						tech_pvt->skype_call_id[0] = '\0';
+						skypiax_strncpy(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1);
+						tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
+						return CALLFLOW_INCOMING_HANGUP;
+					} else if (!strcasecmp(value, "REFUSED")) {
+						if (!strcasecmp(id, tech_pvt->skype_call_id)) {
+							/* this is the id of the call we are in, probably we generated it */
+							tech_pvt->skype_callflow = CALLFLOW_STATUS_REFUSED;
+							DEBUGA_SKYPE("we tried to call Skype on skype_call %s and Skype has now REFUSED\n", SKYPIAX_P_LOG, id);
+							skypiax_strncpy(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1);
+							tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
+							tech_pvt->skype_call_id[0] = '\0';
+							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, "TRANSFERRING")) {
+						DEBUGA_SKYPE("skype_call %s is transferring\n", SKYPIAX_P_LOG, id);
+					} else if (!strcasecmp(value, "TRANSFERRED")) {
+						DEBUGA_SKYPE("skype_call %s has been transferred\n", SKYPIAX_P_LOG, id);
+					} else if (!strcasecmp(value, "ROUTING")) {
+						tech_pvt->skype_callflow = CALLFLOW_STATUS_ROUTING;
+						tech_pvt->interface_state = SKYPIAX_STATE_DIALING;
+						skypiax_strncpy(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1);
+						DEBUGA_SKYPE("skype_call: %s is now ROUTING\n", SKYPIAX_P_LOG, id);
+					} else if (!strcasecmp(value, "UNPLACED")) {
+						tech_pvt->skype_callflow = CALLFLOW_STATUS_UNPLACED;
+						tech_pvt->interface_state = SKYPIAX_STATE_DIALING;
+						skypiax_strncpy(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1);
+						DEBUGA_SKYPE("skype_call: %s is now UNPLACED\n", SKYPIAX_P_LOG, id);
+					} else if (!strcasecmp(value, "INPROGRESS")) {
+						char msg_to_skype[1024];
 
-            if (tech_pvt->skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
-              if (!strlen(tech_pvt->session_uuid_str) || !strlen(tech_pvt->skype_call_id)
-                  || !strcasecmp(tech_pvt->skype_call_id, id)) {
-                skypiax_strncpy(tech_pvt->skype_call_id, id,
-                                sizeof(tech_pvt->skype_call_id) - 1);
-                DEBUGA_SKYPE("skype_call: %s is now active\n", SKYPIAX_P_LOG, id);
+						if (tech_pvt->skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
+							if (!strlen(tech_pvt->session_uuid_str) || !strlen(tech_pvt->skype_call_id)
+								|| !strcasecmp(tech_pvt->skype_call_id, id)) {
+								skypiax_strncpy(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1);
+								DEBUGA_SKYPE("skype_call: %s is now active\n", SKYPIAX_P_LOG, id);
 
-                if (tech_pvt->skype_callflow != CALLFLOW_STATUS_EARLYMEDIA) {
-                  tech_pvt->skype_callflow = CALLFLOW_STATUS_INPROGRESS;
-                  tech_pvt->interface_state = SKYPIAX_STATE_UP;
-                  start_audio_threads(tech_pvt);
-                  skypiax_sleep(1000);  //FIXME
-                  sprintf(msg_to_skype, "ALTER CALL %s SET_INPUT PORT=\"%d\"", id,
-                          tech_pvt->tcp_cli_port);
-                  skypiax_signaling_write(tech_pvt, msg_to_skype);
-                  skypiax_sleep(1000);  //FIXME
-                  sprintf(msg_to_skype, "#output ALTER CALL %s SET_OUTPUT PORT=\"%d\"",
-                          id, tech_pvt->tcp_srv_port);
-                  skypiax_signaling_write(tech_pvt, msg_to_skype);
-                }
-                tech_pvt->skype_callflow = SKYPIAX_STATE_UP;
-                if (!strlen(tech_pvt->session_uuid_str)) {
-                  DEBUGA_SKYPE("New Inbound Channel!\n", SKYPIAX_P_LOG);
-                  new_inbound_channel(tech_pvt);
-                } else {
-                  DEBUGA_SKYPE("Outbound Channel Answered!\n", SKYPIAX_P_LOG);
-                  outbound_channel_answered(tech_pvt);
-                }
-              } else {
-                DEBUGA_SKYPE("I'm on %s, skype_call %s is NOT MY call, ignoring\n",
-                             SKYPIAX_P_LOG, tech_pvt->skype_call_id, id);
-              }
-            } else {
-              tech_pvt->skype_callflow = CALLFLOW_STATUS_INPROGRESS;
-              DEBUGA_SKYPE("Back from REMOTEHOLD!\n", SKYPIAX_P_LOG);
-            }
+								if (tech_pvt->skype_callflow != CALLFLOW_STATUS_EARLYMEDIA) {
+									tech_pvt->skype_callflow = CALLFLOW_STATUS_INPROGRESS;
+									tech_pvt->interface_state = SKYPIAX_STATE_UP;
+									start_audio_threads(tech_pvt);
+									skypiax_sleep(1000);	//FIXME
+									sprintf(msg_to_skype, "ALTER CALL %s SET_INPUT PORT=\"%d\"", id, tech_pvt->tcp_cli_port);
+									skypiax_signaling_write(tech_pvt, msg_to_skype);
+									skypiax_sleep(1000);	//FIXME
+									sprintf(msg_to_skype, "#output ALTER CALL %s SET_OUTPUT PORT=\"%d\"", id, tech_pvt->tcp_srv_port);
+									skypiax_signaling_write(tech_pvt, msg_to_skype);
+								}
+								tech_pvt->skype_callflow = SKYPIAX_STATE_UP;
+								if (!strlen(tech_pvt->session_uuid_str)) {
+									DEBUGA_SKYPE("New Inbound Channel!\n", SKYPIAX_P_LOG);
+									new_inbound_channel(tech_pvt);
+								} else {
+									DEBUGA_SKYPE("Outbound Channel Answered!\n", SKYPIAX_P_LOG);
+									outbound_channel_answered(tech_pvt);
+								}
+							} else {
+								DEBUGA_SKYPE("I'm on %s, skype_call %s is NOT MY call, ignoring\n", SKYPIAX_P_LOG, tech_pvt->skype_call_id, id);
+							}
+						} else {
+							tech_pvt->skype_callflow = CALLFLOW_STATUS_INPROGRESS;
+							DEBUGA_SKYPE("Back from REMOTEHOLD!\n", SKYPIAX_P_LOG);
+						}
 
-          } else if (!strcasecmp(value, "REMOTEHOLD")) {
-            tech_pvt->skype_callflow = CALLFLOW_STATUS_REMOTEHOLD;
-            DEBUGA_SKYPE("skype_call: %s is now REMOTEHOLD\n", SKYPIAX_P_LOG, id);
+					} else if (!strcasecmp(value, "REMOTEHOLD")) {
+						tech_pvt->skype_callflow = CALLFLOW_STATUS_REMOTEHOLD;
+						DEBUGA_SKYPE("skype_call: %s is now REMOTEHOLD\n", SKYPIAX_P_LOG, id);
 
-          } else if (!strcasecmp(value, "BUSY")) {
-            tech_pvt->skype_callflow = CALLFLOW_STATUS_FAILED;
-            DEBUGA_SKYPE
-              ("we tried to call Skype on skype_call %s and remote party (destination) was BUSY. Our outbound call has failed\n",
-               SKYPIAX_P_LOG, id);
-            skypiax_strncpy(tech_pvt->skype_call_id, id,
-                            sizeof(tech_pvt->skype_call_id) - 1);
-            tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
-            tech_pvt->skype_call_id[0] = '\0';
-            skypiax_sleep(1000);
-            return CALLFLOW_INCOMING_HANGUP;
-          } else if (!strcasecmp(value, "WAITING_REDIAL_COMMAND")) {
-            tech_pvt->skype_callflow = CALLFLOW_STATUS_FAILED;
-            DEBUGA_SKYPE
-              ("we tried to call Skype on skype_call %s and remote party (destination) has rejected us (WAITING_REDIAL_COMMAND). Our outbound call has failed\n",
-               SKYPIAX_P_LOG, id);
-            skypiax_strncpy(tech_pvt->skype_call_id, id,
-                            sizeof(tech_pvt->skype_call_id) - 1);
-            tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
-            tech_pvt->skype_call_id[0] = '\0';
-            skypiax_sleep(1000);
-            return CALLFLOW_INCOMING_HANGUP;
-          } else {
-            WARNINGA("skype_call: %s, STATUS: %s is not recognized\n", SKYPIAX_P_LOG, id,
-                     value);
-          }
-        }                       //STATUS
-      }                         //CALL
-      /* the "numbered" messages that follows are used by the directory application, not yet ported */
-      if (!strcasecmp(message, "#333")) {
-        /* DEBUGA_SKYPE("Skype MSG: message_2: %s, message2[11]: %s\n", SKYPIAX_P_LOG,
-         * message_2, &message_2[11]); */
-        memset(tech_pvt->skype_friends, 0, 4096);
-        skypiax_strncpy(tech_pvt->skype_friends, &message_2[11], 4095);
-      }
-      if (!strcasecmp(message, "#222")) {
-        /* DEBUGA_SKYPE("Skype MSG: message_2: %s, message2[10]: %s\n", SKYPIAX_P_LOG,
-         * message_2, &message_2[10]); */
-        memset(tech_pvt->skype_fullname, 0, 512);
-        skypiax_strncpy(tech_pvt->skype_fullname, &message_2[10], 511);
-      }
-      if (!strcasecmp(message, "#765")) {
-        /* DEBUGA_SKYPE("Skype MSG: message_2: %s, message2[10]: %s\n", SKYPIAX_P_LOG,
-         * message_2, &message_2[10]); */
-        memset(tech_pvt->skype_displayname, 0, 512);
-        skypiax_strncpy(tech_pvt->skype_displayname, &message_2[10], 511);
-      }
-      a = 0;
-    }                           //message end
-  }                             //read_from_pipe
-  return 0;
+					} else if (!strcasecmp(value, "BUSY")) {
+						tech_pvt->skype_callflow = CALLFLOW_STATUS_FAILED;
+						DEBUGA_SKYPE
+							("we tried to call Skype on skype_call %s and remote party (destination) was BUSY. Our outbound call has failed\n",
+							 SKYPIAX_P_LOG, id);
+						skypiax_strncpy(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1);
+						tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
+						tech_pvt->skype_call_id[0] = '\0';
+						skypiax_sleep(1000);
+						return CALLFLOW_INCOMING_HANGUP;
+					} else if (!strcasecmp(value, "WAITING_REDIAL_COMMAND")) {
+						tech_pvt->skype_callflow = CALLFLOW_STATUS_FAILED;
+						DEBUGA_SKYPE
+							("we tried to call Skype on skype_call %s and remote party (destination) has rejected us (WAITING_REDIAL_COMMAND). Our outbound call has failed\n",
+							 SKYPIAX_P_LOG, id);
+						skypiax_strncpy(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1);
+						tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
+						tech_pvt->skype_call_id[0] = '\0';
+						skypiax_sleep(1000);
+						return CALLFLOW_INCOMING_HANGUP;
+					} else {
+						WARNINGA("skype_call: %s, STATUS: %s is not recognized\n", SKYPIAX_P_LOG, id, value);
+					}
+				}				//STATUS
+			}					//CALL
+			/* the "numbered" messages that follows are used by the directory application, not yet ported */
+			if (!strcasecmp(message, "#333")) {
+				/* DEBUGA_SKYPE("Skype MSG: message_2: %s, message2[11]: %s\n", SKYPIAX_P_LOG,
+				 * message_2, &message_2[11]); */
+				memset(tech_pvt->skype_friends, 0, 4096);
+				skypiax_strncpy(tech_pvt->skype_friends, &message_2[11], 4095);
+			}
+			if (!strcasecmp(message, "#222")) {
+				/* DEBUGA_SKYPE("Skype MSG: message_2: %s, message2[10]: %s\n", SKYPIAX_P_LOG,
+				 * message_2, &message_2[10]); */
+				memset(tech_pvt->skype_fullname, 0, 512);
+				skypiax_strncpy(tech_pvt->skype_fullname, &message_2[10], 511);
+			}
+			if (!strcasecmp(message, "#765")) {
+				/* DEBUGA_SKYPE("Skype MSG: message_2: %s, message2[10]: %s\n", SKYPIAX_P_LOG,
+				 * message_2, &message_2[10]); */
+				memset(tech_pvt->skype_displayname, 0, 512);
+				skypiax_strncpy(tech_pvt->skype_displayname, &message_2[10], 511);
+			}
+			a = 0;
+		}						//message end
+	}							//read_from_pipe
+	return 0;
 }
 
 void *skypiax_do_tcp_srv_thread_func(void *obj)
 {
-  private_t *tech_pvt = obj;
-  int s;
-  unsigned int len;
-  unsigned int i;
-  unsigned int a;
+	private_t *tech_pvt = obj;
+	int s;
+	unsigned int len;
+	unsigned int i;
+	unsigned int a;
 #if defined(WIN32) && !defined(__CYGWIN__)
-  int sin_size;
+	int sin_size;
 #else /* WIN32 */
-  unsigned int sin_size;
+	unsigned int sin_size;
 #endif /* WIN32 */
-  unsigned int fd;
-  short srv_in[SAMPLES_PER_FRAME];
-  short srv_out[SAMPLES_PER_FRAME / 2];
-  struct sockaddr_in my_addr;
-  struct sockaddr_in remote_addr;
-  //int exit = 0;
-  unsigned int kill_cli_size;
-  short kill_cli_buff[SAMPLES_PER_FRAME];
-  short totalbuf[SAMPLES_PER_FRAME];
+	unsigned int fd;
+	short srv_in[SAMPLES_PER_FRAME];
+	short srv_out[SAMPLES_PER_FRAME / 2];
+	struct sockaddr_in my_addr;
+	struct sockaddr_in remote_addr;
+	//int exit = 0;
+	unsigned int kill_cli_size;
+	short kill_cli_buff[SAMPLES_PER_FRAME];
+	short totalbuf[SAMPLES_PER_FRAME];
 
-  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(tech_pvt->tcp_srv_port);
+	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(tech_pvt->tcp_srv_port);
 
-  if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
-    ERRORA("socket Error\n", SKYPIAX_P_LOG);
-    return NULL;
-  }
+	if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
+		ERRORA("socket Error\n", SKYPIAX_P_LOG);
+		return NULL;
+	}
 
-  if (bind(s, (struct sockaddr *) &my_addr, sizeof(struct sockaddr)) < 0) {
-    ERRORA("bind Error\n", SKYPIAX_P_LOG);
-    return NULL;
-  }
-  DEBUGA_SKYPE("started tcp_srv_thread thread.\n", SKYPIAX_P_LOG);
+	if (bind(s, (struct sockaddr *) &my_addr, sizeof(struct sockaddr)) < 0) {
+		ERRORA("bind Error\n", SKYPIAX_P_LOG);
+		return NULL;
+	}
+	DEBUGA_SKYPE("started tcp_srv_thread thread.\n", SKYPIAX_P_LOG);
 
-  listen(s, 6);
+	listen(s, 6);
 
-  sin_size = sizeof(remote_addr);
+	sin_size = sizeof(remote_addr);
 
   /****************************/
-  while (tech_pvt->interface_state != SKYPIAX_STATE_DOWN
-         && (tech_pvt->skype_callflow == CALLFLOW_STATUS_INPROGRESS
-             || tech_pvt->skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
-             || tech_pvt->skype_callflow == CALLFLOW_STATUS_REMOTEHOLD
-             || tech_pvt->skype_callflow == SKYPIAX_STATE_UP)) {
+	while (tech_pvt->interface_state != SKYPIAX_STATE_DOWN
+		   && (tech_pvt->skype_callflow == CALLFLOW_STATUS_INPROGRESS
+			   || tech_pvt->skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
+			   || tech_pvt->skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt->skype_callflow == SKYPIAX_STATE_UP)) {
 
-    unsigned int fdselectgio;
-    int rtgio;
-    fd_set fsgio;
-    struct timeval togio;
+		unsigned int fdselectgio;
+		int rtgio;
+		fd_set fsgio;
+		struct timeval togio;
 
-    if (!(running && tech_pvt->running))
-      break;
-    FD_ZERO(&fsgio);
-    togio.tv_usec = 20000;      //20msec
-    togio.tv_sec = 0;
-    fdselectgio = s;
-    FD_SET(fdselectgio, &fsgio);
+		if (!(running && tech_pvt->running))
+			break;
+		FD_ZERO(&fsgio);
+		togio.tv_usec = 20000;	//20msec
+		togio.tv_sec = 0;
+		fdselectgio = s;
+		FD_SET(fdselectgio, &fsgio);
 
-    rtgio = select(fdselectgio + 1, &fsgio, NULL, NULL, &togio);
+		rtgio = select(fdselectgio + 1, &fsgio, NULL, NULL, &togio);
 
-    if (rtgio) {
+		if (rtgio) {
 
   /****************************/
 
-      while ((fd = accept(s, (struct sockaddr *) &remote_addr, &sin_size)) > 0) {
-        DEBUGA_SKYPE("ACCEPTED here I send you %d\n", SKYPIAX_P_LOG,
-                     tech_pvt->tcp_srv_port);
-        if (!(running && tech_pvt->running))
-          break;
-        while (tech_pvt->interface_state != SKYPIAX_STATE_DOWN
-               && (tech_pvt->skype_callflow == CALLFLOW_STATUS_INPROGRESS
-                   || tech_pvt->skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
-                   || tech_pvt->skype_callflow == CALLFLOW_STATUS_REMOTEHOLD
-                   || tech_pvt->skype_callflow == SKYPIAX_STATE_UP)) {
+			while ((fd = accept(s, (struct sockaddr *) &remote_addr, &sin_size)) > 0) {
+				DEBUGA_SKYPE("ACCEPTED here I send you %d\n", SKYPIAX_P_LOG, tech_pvt->tcp_srv_port);
+				if (!(running && tech_pvt->running))
+					break;
+				while (tech_pvt->interface_state != SKYPIAX_STATE_DOWN
+					   && (tech_pvt->skype_callflow == CALLFLOW_STATUS_INPROGRESS
+						   || tech_pvt->skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
+						   || tech_pvt->skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt->skype_callflow == SKYPIAX_STATE_UP)) {
 
-          unsigned int fdselect;
-          int rt;
-          fd_set fs;
-          struct timeval to;
+					unsigned int fdselect;
+					int rt;
+					fd_set fs;
+					struct timeval to;
 
-          if (!(running && tech_pvt->running))
-            break;
-          //exit = 1;
+					if (!(running && tech_pvt->running))
+						break;
+					//exit = 1;
 
-          fdselect = fd;
-          FD_ZERO(&fs);
-          FD_SET(fdselect, &fs);
-          //to.tv_usec = 2000000;     //2000 msec
-          to.tv_usec = 60000;   //60 msec
-          to.tv_sec = 0;
+					fdselect = fd;
+					FD_ZERO(&fs);
+					FD_SET(fdselect, &fs);
+					//to.tv_usec = 2000000;     //2000 msec
+					to.tv_usec = 60000;	//60 msec
+					to.tv_sec = 0;
 
-          rt = select(fdselect + 1, &fs, NULL, NULL, &to);
-          if (rt > 0) {
+					rt = select(fdselect + 1, &fs, NULL, NULL, &to);
+					if (rt > 0) {
 
-            if (tech_pvt->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;
-            }
+						if (tech_pvt->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;
+						}
 
-            if (len == 320) {
-              unsigned int howmany;
+						if (len == 320) {
+							unsigned int howmany;
 
-              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 < 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 < len / sizeof(short); i++) {
-                  srv_out[i] = srv_in[i];
-                }
-              } else {
-                ERRORA("SAMPLERATE_SKYPIAX can only be 8000 or 16000\n", SKYPIAX_P_LOG);
-              }
-              /* if not yet done, let's store the half incoming frame */
-              if (!tech_pvt->audiobuf_is_loaded) {
-                for (i = 0; i < SAMPLES_PER_FRAME / 2; i++) {
-                  tech_pvt->audiobuf[i] = srv_out[i];
-                }
-                tech_pvt->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 < SAMPLES_PER_FRAME / 2; i++) {
-                  totalbuf[i] = tech_pvt->audiobuf[i];
-                }
-                for (a = 0; a < 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->audiopipe[1], totalbuf,
-                                     SAMPLES_PER_FRAME * sizeof(short));
-                if (howmany != SAMPLES_PER_FRAME * sizeof(short)) {
-                  ERRORA("howmany is %d, but was expected to be %d\n", SKYPIAX_P_LOG,
-                         howmany, (int) (SAMPLES_PER_FRAME * sizeof(short)));
-                }
-                /* done with the stored half frame */
-                tech_pvt->audiobuf_is_loaded = 0;
-              }
+							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 < 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 < len / sizeof(short); i++) {
+									srv_out[i] = srv_in[i];
+								}
+							} else {
+								ERRORA("SAMPLERATE_SKYPIAX can only be 8000 or 16000\n", SKYPIAX_P_LOG);
+							}
+							/* if not yet done, let's store the half incoming frame */
+							if (!tech_pvt->audiobuf_is_loaded) {
+								for (i = 0; i < SAMPLES_PER_FRAME / 2; i++) {
+									tech_pvt->audiobuf[i] = srv_out[i];
+								}
+								tech_pvt->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 < SAMPLES_PER_FRAME / 2; i++) {
+									totalbuf[i] = tech_pvt->audiobuf[i];
+								}
+								for (a = 0; a < 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->audiopipe[1], totalbuf, SAMPLES_PER_FRAME * sizeof(short));
+								if (howmany != SAMPLES_PER_FRAME * sizeof(short)) {
+									ERRORA("howmany is %d, but was expected to be %d\n", SKYPIAX_P_LOG,
+										   howmany, (int) (SAMPLES_PER_FRAME * sizeof(short)));
+								}
+								/* done with the stored half frame */
+								tech_pvt->audiobuf_is_loaded = 0;
+							}
 
-            } else if (len == 0) {
-              skypiax_sleep(1000);
-            } else {
-              ERRORA("len=%d, expected 320\n", SKYPIAX_P_LOG, len);
-            }
+						} else if (len == 0) {
+							skypiax_sleep(1000);
+						} else {
+							ERRORA("len=%d, expected 320\n", SKYPIAX_P_LOG, len);
+						}
 
-          } else {
-            if (rt)
-              ERRORA("SRV rt=%d\n", SKYPIAX_P_LOG, rt);
-            skypiax_sleep(10000);
-          }
+					} else {
+						if (rt)
+							ERRORA("SRV rt=%d\n", 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->audiopipe[1], kill_cli_buff, kill_cli_size);
-        kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
-        len =
-          skypiax_pipe_write(tech_pvt->audioskypepipe[1], kill_cli_buff, kill_cli_size);
-        tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
-        kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
-        len = skypiax_pipe_write(tech_pvt->audiopipe[1], kill_cli_buff, kill_cli_size);
-        kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
-        len =
-          skypiax_pipe_write(tech_pvt->audioskypepipe[1], kill_cli_buff, kill_cli_size);
+				/* 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->audiopipe[1], kill_cli_buff, kill_cli_size);
+				kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
+				len = skypiax_pipe_write(tech_pvt->audioskypepipe[1], kill_cli_buff, kill_cli_size);
+				tech_pvt->interface_state = SKYPIAX_STATE_DOWN;
+				kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
+				len = skypiax_pipe_write(tech_pvt->audiopipe[1], kill_cli_buff, kill_cli_size);
+				kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
+				len = skypiax_pipe_write(tech_pvt->audioskypepipe[1], kill_cli_buff, kill_cli_size);
 
-        DEBUGA_SKYPE("Skype incoming audio GONE\n", SKYPIAX_P_LOG);
-        skypiax_close_socket(fd);
-        //if (exit)
-        break;
-      }
-    }
-  }
+				DEBUGA_SKYPE("Skype incoming audio GONE\n", SKYPIAX_P_LOG);
+				skypiax_close_socket(fd);
+				//if (exit)
+				break;
+			}
+		}
+	}
 
-  DEBUGA_SKYPE("incoming audio server (I am it) EXITING\n", SKYPIAX_P_LOG);
-  skypiax_close_socket(s);
-  return NULL;
+	DEBUGA_SKYPE("incoming audio server (I am it) EXITING\n", SKYPIAX_P_LOG);
+	skypiax_close_socket(s);
+	return NULL;
 }
 
 void *skypiax_do_tcp_cli_thread_func(void *obj)
 {
-  private_t *tech_pvt = obj;
-  int s;
-  struct sockaddr_in my_addr;
-  struct sockaddr_in remote_addr;
-  unsigned int got;
-  unsigned int len;
-  unsigned int i;
-  unsigned int a;
-  unsigned int fd;
-  short cli_out[SAMPLES_PER_FRAME * 2];
-  short cli_in[SAMPLES_PER_FRAME];
+	private_t *tech_pvt = obj;
+	int s;
+	struct sockaddr_in my_addr;
+	struct sockaddr_in remote_addr;
+	unsigned int got;
+	unsigned int len;
+	unsigned int i;
+	unsigned int a;
+	unsigned int fd;
+	short cli_out[SAMPLES_PER_FRAME * 2];
+	short cli_in[SAMPLES_PER_FRAME];
 #ifdef WIN32
-  int sin_size;
+	int sin_size;
 #else
-  unsigned int sin_size;
+	unsigned int sin_size;
 #endif /* WIN32 */
 
-  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(tech_pvt->tcp_cli_port);
+	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(tech_pvt->tcp_cli_port);
 
-  if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
-    ERRORA("socket Error\n", SKYPIAX_P_LOG);
-    return NULL;
-  }
+	if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
+		ERRORA("socket Error\n", SKYPIAX_P_LOG);
+		return NULL;
+	}
 
-  if (bind(s, (struct sockaddr *) &my_addr, sizeof(struct sockaddr)) < 0) {
-    ERRORA("bind Error\n", SKYPIAX_P_LOG);
-    skypiax_close_socket(s);
-    return NULL;
-  }
-  DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
+	if (bind(s, (struct sockaddr *) &my_addr, sizeof(struct sockaddr)) < 0) {
+		ERRORA("bind Error\n", SKYPIAX_P_LOG);
+		skypiax_close_socket(s);
+		return NULL;
+	}
+	DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG);
 
-  listen(s, 6);
+	listen(s, 6);
 
-  sin_size = sizeof(remote_addr);
+	sin_size = sizeof(remote_addr);
 
   /****************************/
-  while (tech_pvt->interface_state != SKYPIAX_STATE_DOWN
-         && (tech_pvt->skype_callflow == CALLFLOW_STATUS_INPROGRESS
-             || tech_pvt->skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
-             || tech_pvt->skype_callflow == CALLFLOW_STATUS_REMOTEHOLD
-             || tech_pvt->skype_callflow == SKYPIAX_STATE_UP)) {
+	while (tech_pvt->interface_state != SKYPIAX_STATE_DOWN
+		   && (tech_pvt->skype_callflow == CALLFLOW_STATUS_INPROGRESS
+			   || tech_pvt->skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
+			   || tech_pvt->skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt->skype_callflow == SKYPIAX_STATE_UP)) {
 
-    unsigned int fdselectgio;
-    int rtgio;
-    fd_set fsgio;
-    struct timeval togio;
+		unsigned int fdselectgio;
+		int rtgio;
+		fd_set fsgio;
+		struct timeval togio;
 
-    if (!(running && tech_pvt->running))
-      break;
-    FD_ZERO(&fsgio);
-    togio.tv_usec = 20000;      //20msec
-    togio.tv_sec = 0;
-    fdselectgio = s;
-    FD_SET(fdselectgio, &fsgio);
+		if (!(running && tech_pvt->running))
+			break;
+		FD_ZERO(&fsgio);
+		togio.tv_usec = 20000;	//20msec
+		togio.tv_sec = 0;
+		fdselectgio = s;
+		FD_SET(fdselectgio, &fsgio);
 
-    rtgio = select(fdselectgio + 1, &fsgio, NULL, NULL, &togio);
+		rtgio = select(fdselectgio + 1, &fsgio, NULL, NULL, &togio);
 
-    if (rtgio) {
+		if (rtgio) {
 
   /****************************/
 
-      while ((fd = accept(s, (struct sockaddr *) &remote_addr, &sin_size)) > 0) {
-        DEBUGA_SKYPE("ACCEPTED here you send me %d\n", SKYPIAX_P_LOG,
-                     tech_pvt->tcp_cli_port);
+			while ((fd = accept(s, (struct sockaddr *) &remote_addr, &sin_size)) > 0) {
+				DEBUGA_SKYPE("ACCEPTED here you send me %d\n", SKYPIAX_P_LOG, tech_pvt->tcp_cli_port);
 #ifndef WIN32
-        fcntl(tech_pvt->audioskypepipe[0], F_SETFL, O_NONBLOCK);
+				fcntl(tech_pvt->audioskypepipe[0], F_SETFL, O_NONBLOCK);
+				fcntl(tech_pvt->audioskypepipe[1], F_SETFL, O_NONBLOCK);
 #endif //WIN32
 
-        if (!(running && tech_pvt->running))
-          break;
-        while (tech_pvt->interface_state != SKYPIAX_STATE_DOWN
-               && (tech_pvt->skype_callflow == CALLFLOW_STATUS_INPROGRESS
-                   || tech_pvt->skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
-                   || tech_pvt->skype_callflow == CALLFLOW_STATUS_REMOTEHOLD
-                   || tech_pvt->skype_callflow == SKYPIAX_STATE_UP)) {
-          unsigned int fdselect;
-          int rt;
-          fd_set fs;
-          struct timeval to;
+				if (!(running && tech_pvt->running))
+					break;
+				while (tech_pvt->interface_state != SKYPIAX_STATE_DOWN
+					   && (tech_pvt->skype_callflow == CALLFLOW_STATUS_INPROGRESS
+						   || tech_pvt->skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
+						   || tech_pvt->skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt->skype_callflow == SKYPIAX_STATE_UP)) {
+					unsigned int fdselect;
+					int rt;
+					fd_set fs;
+					struct timeval to;
 
-          if (!(running && tech_pvt->running))
-            break;
-          FD_ZERO(&fs);
-          to.tv_usec = 120000;  //120msec
-          to.tv_sec = 0;
+					if (!(running && tech_pvt->running))
+						break;
+					FD_ZERO(&fs);
+					to.tv_usec = 120000;	//120msec
+					to.tv_sec = 0;
 #if defined(WIN32) && !defined(__CYGWIN__)
 /* on win32 we cannot select from the apr "pipe", so we select on socket writability */
-          fdselect = fd;
-          FD_SET(fdselect, &fs);
+					fdselect = fd;
+					FD_SET(fdselect, &fs);
 
-          rt = select(fdselect + 1, NULL, &fs, NULL, &to);
+					rt = select(fdselect + 1, NULL, &fs, NULL, &to);
 #else
 /* on *unix and cygwin we select from the real pipe */
-          fdselect = tech_pvt->audioskypepipe[0];
-          FD_SET(fdselect, &fs);
+					fdselect = tech_pvt->audioskypepipe[0];
+					FD_SET(fdselect, &fs);
 
-          rt = select(fdselect + 1, &fs, NULL, NULL, &to);
+					rt = select(fdselect + 1, &fs, NULL, NULL, &to);
 #endif
 
-          if (rt > 0) {
-            int counter;
+					if (rt > 0) {
+						int counter;
 
-            /* until we drained the pipe to empty */
-            for (counter = 0; counter < 10; counter++) {
-              /* read from the pipe the audio frame we are supposed to send out */
-              got =
-                skypiax_pipe_read(tech_pvt->audioskypepipe[0], cli_in,
-                                  SAMPLES_PER_FRAME * sizeof(short));
-              if (got == -1)
-                break;
+						/* until we drained the pipe to empty */
+						for (counter = 0; counter < 10; counter++) {
+							/* read from the pipe the audio frame we are supposed to send out */
+							got = skypiax_pipe_read(tech_pvt->audioskypepipe[0], cli_in, SAMPLES_PER_FRAME * sizeof(short));
+							if (got == -1)
+								break;
 
-              if (got != SAMPLES_PER_FRAME * sizeof(short)) {
-                WARNINGA("got is %d, but was expected to be %d\n", SKYPIAX_P_LOG, got,
-                         (int) (SAMPLES_PER_FRAME * sizeof(short)));
-              }
+							if (got != SAMPLES_PER_FRAME * sizeof(short)) {
+								WARNINGA("got is %d, but was expected to be %d\n", SKYPIAX_P_LOG, got, (int) (SAMPLES_PER_FRAME * sizeof(short)));
+							}
 
-              if (got == SAMPLES_PER_FRAME * sizeof(short)) {
-                if (samplerate_skypiax == 8000) {
+							if (got == SAMPLES_PER_FRAME * sizeof(short)) {
+								if (samplerate_skypiax == 8000) {
 
-                  /* we're upsampling from 8khz to 16khz, cli_out will contain two times each sample from cli_in */
-                  a = 0;
-                  for (i = 0; i < 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 < got / sizeof(short); i++) {
-                    cli_out[i] = cli_in[i];
-                  }
-                } else {
-                  ERRORA("SAMPLERATE_SKYPIAX can only be 8000 or 16000\n", SKYPIAX_P_LOG);
-                }
+									/* we're upsampling from 8khz to 16khz, cli_out will contain two times each sample from cli_in */
+									a = 0;
+									for (i = 0; i < 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 < got / sizeof(short); i++) {
+										cli_out[i] = cli_in[i];
+									}
+								} else {
+									ERRORA("SAMPLERATE_SKYPIAX can only be 8000 or 16000\n", 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->skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
-                  len = send(fd, (char *) cli_out, got, 0);
-                  skypiax_sleep(5000);  //5 msec
+								/* send the 16khz frame to the Skype client waiting for incoming audio to be sent to the remote party */
+								if (tech_pvt->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("len=%d\n", SKYPIAX_P_LOG, len);
-                    skypiax_sleep(1000);
-                    break;
-                  }
-                }
+									if (len == -1) {
+										break;
+									} else if (len != got) {
+										ERRORA("len=%d\n", SKYPIAX_P_LOG, len);
+										skypiax_sleep(1000);
+										break;
+									}
+								}
 
-              } else {
+							} else {
 
-                WARNINGA("got is %d, but was expected to be %d\n", SKYPIAX_P_LOG, got,
-                         (int) (SAMPLES_PER_FRAME * sizeof(short)));
-              }
-            }
-          } else {
-            if (rt)
-              ERRORA("CLI rt=%d\n", SKYPIAX_P_LOG, rt);
-            memset(cli_out, 0, sizeof(cli_out));
-            if (tech_pvt->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("sent %d of zeros to keep the Skype client socket busy\n", SKYPIAX_P_LOG, sizeof(cli_out) + sizeof(cli_out)/2);
-            } else {
-              /*
-                 XXX do nothing 
-               */
-              //WARNINGA("we don't send it\n", SKYPIAX_P_LOG);
-            }
-            skypiax_sleep(1000);
-          }
+								WARNINGA("got is %d, but was expected to be %d\n", SKYPIAX_P_LOG, got, (int) (SAMPLES_PER_FRAME * sizeof(short)));
+							}
+						}
+					} else {
+						if (rt)
+							ERRORA("CLI rt=%d\n", SKYPIAX_P_LOG, rt);
+						memset(cli_out, 0, sizeof(cli_out));
+						if (tech_pvt->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("sent %d of zeros to keep the Skype client socket busy\n", SKYPIAX_P_LOG, sizeof(cli_out) + sizeof(cli_out)/2);
+						} else {
+							/*
+							   XXX do nothing 
+							 */
+							//WARNINGA("we don't send it\n", SKYPIAX_P_LOG);
+						}
+						skypiax_sleep(1000);
+					}
 
-        }
-        DEBUGA_SKYPE("Skype outbound audio GONE\n", SKYPIAX_P_LOG);
-        skypiax_close_socket(fd);
-        break;
-      }
-    }
-  }
+				}
+				DEBUGA_SKYPE("Skype outbound audio GONE\n", SKYPIAX_P_LOG);
+				skypiax_close_socket(fd);
+				break;
+			}
+		}
+	}
 
-  DEBUGA_SKYPE("outbound audio server (I am it) EXITING\n", SKYPIAX_P_LOG);
-  skypiax_close_socket(s);
-  return NULL;
+	DEBUGA_SKYPE("outbound audio server (I am it) EXITING\n", SKYPIAX_P_LOG);
+	skypiax_close_socket(s);
+	return NULL;
 }
 
 int skypiax_audio_read(private_t * tech_pvt)
 {
-  unsigned int samples;
+	unsigned int samples;
 
-  samples =
-    skypiax_pipe_read(tech_pvt->audiopipe[0], tech_pvt->read_frame.data,
-                      SAMPLES_PER_FRAME * sizeof(short));
+	samples = skypiax_pipe_read(tech_pvt->audiopipe[0], tech_pvt->read_frame.data, SAMPLES_PER_FRAME * sizeof(short));
 
-  if (samples != SAMPLES_PER_FRAME * sizeof(short)) {
-    if (samples)
-      WARNINGA("read samples=%u expected=%u\n", SKYPIAX_P_LOG, samples,
-               (int) (SAMPLES_PER_FRAME * sizeof(short)));
-    return 0;
-  } else {
-    /* A real frame */
-    tech_pvt->read_frame.datalen = samples;
-  }
-  return 1;
+	if (samples != SAMPLES_PER_FRAME * sizeof(short)) {
+		if (samples)
+			WARNINGA("read samples=%u expected=%u\n", SKYPIAX_P_LOG, samples, (int) (SAMPLES_PER_FRAME * sizeof(short)));
+		return 0;
+	} else {
+		/* A real frame */
+		tech_pvt->read_frame.datalen = samples;
+	}
+	return 1;
 }
 
 int skypiax_senddigit(private_t * tech_pvt, char digit)
 {
-  char msg_to_skype[1024];
+	char msg_to_skype[1024];
 
-  DEBUGA_SKYPE("DIGIT received: %c\n", SKYPIAX_P_LOG, digit);
-  sprintf(msg_to_skype, "SET CALL %s DTMF %c", tech_pvt->skype_call_id, digit);
-  skypiax_signaling_write(tech_pvt, msg_to_skype);
+	DEBUGA_SKYPE("DIGIT received: %c\n", SKYPIAX_P_LOG, digit);
+	sprintf(msg_to_skype, "SET CALL %s DTMF %c", tech_pvt->skype_call_id, digit);
+	skypiax_signaling_write(tech_pvt, msg_to_skype);
 
-  return 0;
+	return 0;
 }
 
 int skypiax_call(private_t * tech_pvt, char *rdest, int timeout)
 {
-  char msg_to_skype[1024];
+	char msg_to_skype[1024];
 
-  //skypiax_sleep(5000);
-  DEBUGA_SKYPE("Calling Skype, rdest is: %s\n", SKYPIAX_P_LOG, rdest);
-  //skypiax_signaling_write(tech_pvt, "SET AGC OFF");
-  //skypiax_sleep(10000);
-  //skypiax_signaling_write(tech_pvt, "SET AEC OFF");
-  //skypiax_sleep(10000);
+	//skypiax_sleep(5000);
+	DEBUGA_SKYPE("Calling Skype, rdest is: %s\n", SKYPIAX_P_LOG, rdest);
+	//skypiax_signaling_write(tech_pvt, "SET AGC OFF");
+	//skypiax_sleep(10000);
+	//skypiax_signaling_write(tech_pvt, "SET AEC OFF");
+	//skypiax_sleep(10000);
 
-  sprintf(msg_to_skype, "CALL %s", rdest);
-  if (skypiax_signaling_write(tech_pvt, msg_to_skype) < 0) {
-    ERRORA("failed to communicate with Skype client, now exit\n", SKYPIAX_P_LOG);
-    return -1;
-  }
-  return 0;
+	sprintf(msg_to_skype, "CALL %s", rdest);
+	if (skypiax_signaling_write(tech_pvt, msg_to_skype) < 0) {
+		ERRORA("failed to communicate with Skype client, now exit\n", SKYPIAX_P_LOG);
+		return -1;
+	}
+	return 0;
 }
 
 /***************************/
@@ -873,692 +820,649 @@
 #if defined(WIN32) && !defined(__CYGWIN__)
 int skypiax_pipe_read(switch_file_t * pipe, short *buf, int howmany)
 {
-  switch_size_t quantity;
+	switch_size_t quantity;
 
-  quantity = howmany;
+	quantity = howmany;
 
-  switch_file_read(pipe, buf, &quantity);
+	switch_file_read(pipe, buf, &quantity);
 
-  howmany = quantity;
+	howmany = quantity;
 
-  return howmany;
+	return howmany;
 }
 
 int skypiax_pipe_write(switch_file_t * pipe, short *buf, int howmany)
 {
-  switch_size_t quantity;
+	switch_size_t quantity;
 
-  quantity = howmany;
+	quantity = howmany;
 
-  switch_file_write(pipe, buf, &quantity);
+	switch_file_write(pipe, buf, &quantity);
 
-  howmany = quantity;
+	howmany = quantity;
 
-  return howmany;
+	return howmany;
 }
 
 int skypiax_close_socket(unsigned int fd)
 {
-  int res;
+	int res;
 
-  res = closesocket(fd);
+	res = closesocket(fd);
 
-  return res;
+	return res;
 }
 
 int skypiax_audio_init(private_t * tech_pvt)
 {
-  switch_status_t rv;
-  rv =
-    switch_file_pipe_create(&tech_pvt->audiopipe[0], &tech_pvt->audiopipe[1],
-                            skypiax_module_pool);
-  rv =
-    switch_file_pipe_create(&tech_pvt->audioskypepipe[0], &tech_pvt->audioskypepipe[1],
-                            skypiax_module_pool);
-  return 0;
+	switch_status_t rv;
+	rv = switch_file_pipe_create(&tech_pvt->audiopipe[0], &tech_pvt->audiopipe[1], skypiax_module_pool);
+	rv = switch_file_pipe_create(&tech_pvt->audioskypepipe[0], &tech_pvt->audioskypepipe[1], skypiax_module_pool);
+	return 0;
 }
 #else /* WIN32 */
 int skypiax_pipe_read(int pipe, short *buf, int howmany)
 {
-  howmany = read(pipe, buf, howmany);
-  return howmany;
+	howmany = read(pipe, buf, howmany);
+	return howmany;
 }
 
 int skypiax_pipe_write(int pipe, short *buf, int howmany)
 {
-  howmany = write(pipe, buf, howmany);
-  return howmany;
+	howmany = write(pipe, buf, howmany);
+	return howmany;
 }
 
 int skypiax_close_socket(unsigned int fd)
 {
-  int res;
+	int res;
 
-  res = close(fd);
+	res = close(fd);
 
-  return res;
+	return res;
 }
 
 int skypiax_audio_init(private_t * tech_pvt)
 {
-  if (pipe(tech_pvt->audiopipe)) {
-    fcntl(tech_pvt->audiopipe[0], F_SETFL, O_NONBLOCK);
-    fcntl(tech_pvt->audiopipe[1], F_SETFL, O_NONBLOCK);
-  }
-  if (pipe(tech_pvt->audioskypepipe)) {
-    fcntl(tech_pvt->audioskypepipe[0], F_SETFL, O_NONBLOCK);
-    fcntl(tech_pvt->audioskypepipe[1], F_SETFL, O_NONBLOCK);
-  }
+	if (pipe(tech_pvt->audiopipe)) {
+		fcntl(tech_pvt->audiopipe[0], F_SETFL, O_NONBLOCK);
+		fcntl(tech_pvt->audiopipe[1], F_SETFL, O_NONBLOCK);
+	}
+	if (pipe(tech_pvt->audioskypepipe)) {
+		fcntl(tech_pvt->audioskypepipe[0], F_SETFL, O_NONBLOCK);
+		fcntl(tech_pvt->audioskypepipe[1], F_SETFL, O_NONBLOCK);
+	}
 
 /* this pipe is the audio fd for asterisk to poll on during a call. FS do not use it */
-  tech_pvt->skypiax_sound_capt_fd = tech_pvt->audiopipe[0];
+	tech_pvt->skypiax_sound_capt_fd = tech_pvt->audiopipe[0];
 
-  return 0;
+	return 0;
 }
 #endif /* WIN32 */
 
 #ifdef WIN32
 
 enum {
-  SKYPECONTROLAPI_ATTACH_SUCCESS = 0,   /*  Client is successfully 
-                                           attached and API window handle can be found
-                                           in wParam parameter */
-  SKYPECONTROLAPI_ATTACH_PENDING_AUTHORIZATION = 1, /*  Skype has acknowledged
-                                                       connection request and is waiting
-                                                       for confirmation from the user. */
-  /*  The client is not yet attached 
-   * and should wait for SKYPECONTROLAPI_ATTACH_SUCCESS message */
-  SKYPECONTROLAPI_ATTACH_REFUSED = 2,   /*  User has explicitly
-                                           denied access to client */
-  SKYPECONTROLAPI_ATTACH_NOT_AVAILABLE = 3, /*  API is not available
-                                               at the moment.
-                                               For example, this happens when no user
-                                               is currently logged in. */
-  /*  Client should wait for 
-   * SKYPECONTROLAPI_ATTACH_API_AVAILABLE 
-   * broadcast before making any further */
-  /*  connection attempts. */
-  SKYPECONTROLAPI_ATTACH_API_AVAILABLE = 0x8001
+	SKYPECONTROLAPI_ATTACH_SUCCESS = 0,	/*  Client is successfully 
+										   attached and API window handle can be found
+										   in wParam parameter */
+	SKYPECONTROLAPI_ATTACH_PENDING_AUTHORIZATION = 1,	/*  Skype has acknowledged
+														   connection request and is waiting
+														   for confirmation from the user. */
+	/*  The client is not yet attached 
+	 * and should wait for SKYPECONTROLAPI_ATTACH_SUCCESS message */
+	SKYPECONTROLAPI_ATTACH_REFUSED = 2,	/*  User has explicitly
+										   denied access to client */
+	SKYPECONTROLAPI_ATTACH_NOT_AVAILABLE = 3,	/*  API is not available
+												   at the moment.
+												   For example, this happens when no user
+												   is currently logged in. */
+	/*  Client should wait for 
+	 * SKYPECONTROLAPI_ATTACH_API_AVAILABLE 
+	 * broadcast before making any further */
+	/*  connection attempts. */
+	SKYPECONTROLAPI_ATTACH_API_AVAILABLE = 0x8001
 };
 
 /* Visual C do not have strsep? */
 char
- *strsep(char **stringp, const char *delim)
+    *strsep(char **stringp, const char *delim)
 {
-  char *res;
+	char *res;
 
-  if (!stringp || !*stringp || !**stringp)
-    return (char *) 0;
+	if (!stringp || !*stringp || !**stringp)
+		return (char *) 0;
 
-  res = *stringp;
-  while (**stringp && !strchr(delim, **stringp))
-    ++(*stringp);
+	res = *stringp;
+	while (**stringp && !strchr(delim, **stringp))
+		++(*stringp);
 
-  if (**stringp) {
-    **stringp = '\0';
-    ++(*stringp);
-  }
+	if (**stringp) {
+		**stringp = '\0';
+		++(*stringp);
+	}
 
-  return res;
+	return res;
 }
 
 int skypiax_signaling_write(private_t * tech_pvt, char *msg_to_skype)
 {
-  static char acInputRow[1024];
-  COPYDATASTRUCT oCopyData;
+	static char acInputRow[1024];
+	COPYDATASTRUCT oCopyData;
 
-  DEBUGA_SKYPE("SENDING: |||%s||||\n", SKYPIAX_P_LOG, msg_to_skype);
+	DEBUGA_SKYPE("SENDING: |||%s||||\n", SKYPIAX_P_LOG, msg_to_skype);
 
-  sprintf(acInputRow, "%s", msg_to_skype);
-  DEBUGA_SKYPE("acInputRow: |||%s||||\n", SKYPIAX_P_LOG, acInputRow);
-  /*  send command to skype */
-  oCopyData.dwData = 0;
-  oCopyData.lpData = acInputRow;
-  oCopyData.cbData = strlen(acInputRow) + 1;
-  if (oCopyData.cbData != 1) {
-    if (SendMessage
-        (tech_pvt->SkypiaxHandles.win32_hGlobal_SkypeAPIWindowHandle, WM_COPYDATA,
-         (WPARAM) tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle,
-         (LPARAM) & oCopyData) == FALSE) {
-      ERRORA
-        ("Sending message failed - probably Skype crashed.\n\nPlease shutdown Skypiax, then launch Skypiax and try again.\n",
-         SKYPIAX_P_LOG);
-      return -1;
-    }
-  }
+	sprintf(acInputRow, "%s", msg_to_skype);
+	DEBUGA_SKYPE("acInputRow: |||%s||||\n", SKYPIAX_P_LOG, acInputRow);
+	/*  send command to skype */
+	oCopyData.dwData = 0;
+	oCopyData.lpData = acInputRow;
+	oCopyData.cbData = strlen(acInputRow) + 1;
+	if (oCopyData.cbData != 1) {
+		if (SendMessage
+			(tech_pvt->SkypiaxHandles.win32_hGlobal_SkypeAPIWindowHandle, WM_COPYDATA,
+			 (WPARAM) tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle, (LPARAM) & oCopyData) == FALSE) {
+			ERRORA("Sending message failed - probably Skype crashed.\n\nPlease shutdown Skypiax, then launch Skypiax and try again.\n", SKYPIAX_P_LOG);
+			return -1;
+		}
+	}
 
-  return 0;
+	return 0;
 
 }
 
-LRESULT APIENTRY skypiax_present(HWND hWindow, UINT uiMessage, WPARAM uiParam,
-                                 LPARAM ulParam)
+LRESULT APIENTRY skypiax_present(HWND hWindow, UINT uiMessage, WPARAM uiParam, LPARAM ulParam)
 {
-  LRESULT lReturnCode;
-  int fIssueDefProc;
-  private_t *tech_pvt = NULL;
+	LRESULT lReturnCode;
+	int fIssueDefProc;
+	private_t *tech_pvt = NULL;
 
-  lReturnCode = 0;
-  fIssueDefProc = 0;
-  tech_pvt = (private_t *) GetWindowLong(hWindow, GWL_USERDATA);
-  if (!running)
-    return lReturnCode;
-  switch (uiMessage) {
-  case WM_CREATE:
-    tech_pvt = (private_t *) ((LPCREATESTRUCT) ulParam)->lpCreateParams;
-    SetWindowLong(hWindow, GWL_USERDATA, (LONG) tech_pvt);
-    DEBUGA_SKYPE("got CREATE\n", SKYPIAX_P_LOG);
-    break;
-  case WM_DESTROY:
-    DEBUGA_SKYPE("got DESTROY\n", SKYPIAX_P_LOG);
-    tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle = NULL;
-    PostQuitMessage(0);
-    break;
-  case WM_COPYDATA:
-    if (tech_pvt->SkypiaxHandles.win32_hGlobal_SkypeAPIWindowHandle == (HWND) uiParam) {
-      unsigned int howmany;
-      char msg_from_skype[2048];
+	lReturnCode = 0;
+	fIssueDefProc = 0;
+	tech_pvt = (private_t *) GetWindowLong(hWindow, GWL_USERDATA);
+	if (!running)
+		return lReturnCode;
+	switch (uiMessage) {
+	case WM_CREATE:
+		tech_pvt = (private_t *) ((LPCREATESTRUCT) ulParam)->lpCreateParams;
+		SetWindowLong(hWindow, GWL_USERDATA, (LONG) tech_pvt);
+		DEBUGA_SKYPE("got CREATE\n", SKYPIAX_P_LOG);
+		break;
+	case WM_DESTROY:
+		DEBUGA_SKYPE("got DESTROY\n", SKYPIAX_P_LOG);
+		tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle = NULL;
+		PostQuitMessage(0);
+		break;
+	case WM_COPYDATA:
+		if (tech_pvt->SkypiaxHandles.win32_hGlobal_SkypeAPIWindowHandle == (HWND) uiParam) {
+			unsigned int howmany;
+			char msg_from_skype[2048];
 
-      PCOPYDATASTRUCT poCopyData = (PCOPYDATASTRUCT) ulParam;
+			PCOPYDATASTRUCT poCopyData = (PCOPYDATASTRUCT) ulParam;
 
-      memset(msg_from_skype, '\0', sizeof(msg_from_skype));
-      skypiax_strncpy(msg_from_skype, (const char *) poCopyData->lpData,
-                      sizeof(msg_from_skype) - 2);
+			memset(msg_from_skype, '\0', sizeof(msg_from_skype));
+			skypiax_strncpy(msg_from_skype, (const char *) poCopyData->lpData, sizeof(msg_from_skype) - 2);
 
-      howmany = strlen(msg_from_skype) + 1;
-      howmany =
-        skypiax_pipe_write(tech_pvt->SkypiaxHandles.fdesc[1], (short *) msg_from_skype,
-                           howmany);
-      //DEBUGA_SKYPE("From Skype API: %s\n", SKYPIAX_P_LOG, msg_from_skype);
-      lReturnCode = 1;
-    }
-    break;
-  default:
-    if (tech_pvt && tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIAttach) {
-      if (uiMessage ==
-          tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIAttach) {
-        switch (ulParam) {
-        case SKYPECONTROLAPI_ATTACH_SUCCESS:
-          if (!tech_pvt->SkypiaxHandles.currentuserhandle) {
-            //DEBUGA_SKYPE("\n\n\tConnected to Skype API!\n", SKYPIAX_P_LOG);
-            tech_pvt->SkypiaxHandles.api_connected = 1;
-            tech_pvt->SkypiaxHandles.win32_hGlobal_SkypeAPIWindowHandle = (HWND) uiParam;
-            tech_pvt->SkypiaxHandles.win32_hGlobal_SkypeAPIWindowHandle =
-              tech_pvt->SkypiaxHandles.win32_hGlobal_SkypeAPIWindowHandle;
-          }
-          break;
-        case SKYPECONTROLAPI_ATTACH_PENDING_AUTHORIZATION:
-          //DEBUGA_SKYPE ("\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);
-          skypiax_sleep(5000);
+			howmany = strlen(msg_from_skype) + 1;
+			howmany = skypiax_pipe_write(tech_pvt->SkypiaxHandles.fdesc[1], (short *) msg_from_skype, howmany);
+			//DEBUGA_SKYPE("From Skype API: %s\n", SKYPIAX_P_LOG, msg_from_skype);
+			lReturnCode = 1;
+		}
+		break;
+	default:
+		if (tech_pvt && tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIAttach) {
+			if (uiMessage == tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIAttach) {
+				switch (ulParam) {
+				case SKYPECONTROLAPI_ATTACH_SUCCESS:
+					if (!tech_pvt->SkypiaxHandles.currentuserhandle) {
+						//DEBUGA_SKYPE("\n\n\tConnected to Skype API!\n", SKYPIAX_P_LOG);
+						tech_pvt->SkypiaxHandles.api_connected = 1;
+						tech_pvt->SkypiaxHandles.win32_hGlobal_SkypeAPIWindowHandle = (HWND) uiParam;
+						tech_pvt->SkypiaxHandles.win32_hGlobal_SkypeAPIWindowHandle = tech_pvt->SkypiaxHandles.win32_hGlobal_SkypeAPIWindowHandle;
+					}
+					break;
+				case SKYPECONTROLAPI_ATTACH_PENDING_AUTHORIZATION:
+					//DEBUGA_SKYPE ("\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);
+					skypiax_sleep(5000);
 #if 0
-          if (!tech_pvt->SkypiaxHandles.currentuserhandle) {
-            SendMessage(HWND_BROADCAST,
-                        tech_pvt->SkypiaxHandles.
-                        win32_uiGlobal_MsgID_SkypeControlAPIDiscover,
-                        (WPARAM) tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle,
-                        0);
-          }
+					if (!tech_pvt->SkypiaxHandles.currentuserhandle) {
+						SendMessage(HWND_BROADCAST,
+									tech_pvt->SkypiaxHandles.
+									win32_uiGlobal_MsgID_SkypeControlAPIDiscover, (WPARAM) tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle, 0);
+					}
 #endif
-          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);
-          skypiax_sleep(5000);
+					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);
+					skypiax_sleep(5000);
 #if 0
-          if (!tech_pvt->SkypiaxHandles.currentuserhandle) {
-            SendMessage(HWND_BROADCAST,
-                        tech_pvt->SkypiaxHandles.
-                        win32_uiGlobal_MsgID_SkypeControlAPIDiscover,
-                        (WPARAM) tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle,
-                        0);
-          }
+					if (!tech_pvt->SkypiaxHandles.currentuserhandle) {
+						SendMessage(HWND_BROADCAST,
+									tech_pvt->SkypiaxHandles.
+									win32_uiGlobal_MsgID_SkypeControlAPIDiscover, (WPARAM) tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle, 0);
+					}
 #endif
-          break;
-        default:
-          WARNINGA("GOT AN UNKNOWN SKYPE WINDOWS MSG\n", SKYPIAX_P_LOG);
-        }
-        lReturnCode = 1;
-        break;
-      }
-    }
-    fIssueDefProc = 1;
-    break;
-  }
-  if (fIssueDefProc)
-    lReturnCode = DefWindowProc(hWindow, uiMessage, uiParam, ulParam);
-  return (lReturnCode);
+					break;
+				default:
+					WARNINGA("GOT AN UNKNOWN SKYPE WINDOWS MSG\n", SKYPIAX_P_LOG);
+				}
+				lReturnCode = 1;
+				break;
+			}
+		}
+		fIssueDefProc = 1;
+		break;
+	}
+	if (fIssueDefProc)
+		lReturnCode = DefWindowProc(hWindow, uiMessage, uiParam, ulParam);
+	return (lReturnCode);
 }
 
 int win32_Initialize_CreateWindowClass(private_t * tech_pvt)
 {
-  unsigned char *paucUUIDString;
-  RPC_STATUS lUUIDResult;
-  int fReturnStatus;
-  UUID oUUID;
+	unsigned char *paucUUIDString;
+	RPC_STATUS lUUIDResult;
+	int fReturnStatus;
+	UUID oUUID;
 
-  fReturnStatus = 0;
-  lUUIDResult = UuidCreate(&oUUID);
-  tech_pvt->SkypiaxHandles.win32_hInit_ProcessHandle =
-    (HINSTANCE) OpenProcess(PROCESS_DUP_HANDLE, FALSE, GetCurrentProcessId());
-  if (tech_pvt->SkypiaxHandles.win32_hInit_ProcessHandle != NULL
-      && (lUUIDResult == RPC_S_OK || lUUIDResult == RPC_S_UUID_LOCAL_ONLY)) {
-    if (UuidToString(&oUUID, &paucUUIDString) == RPC_S_OK) {
-      WNDCLASS oWindowClass;
+	fReturnStatus = 0;
+	lUUIDResult = UuidCreate(&oUUID);
+	tech_pvt->SkypiaxHandles.win32_hInit_ProcessHandle = (HINSTANCE) OpenProcess(PROCESS_DUP_HANDLE, FALSE, GetCurrentProcessId());
+	if (tech_pvt->SkypiaxHandles.win32_hInit_ProcessHandle != NULL && (lUUIDResult == RPC_S_OK || lUUIDResult == RPC_S_UUID_LOCAL_ONLY)) {
+		if (UuidToString(&oUUID, &paucUUIDString) == RPC_S_OK) {
+			WNDCLASS oWindowClass;
 
-      strcpy(tech_pvt->SkypiaxHandles.win32_acInit_WindowClassName, "Skype-API-Skypiax-");
-      strcat(tech_pvt->SkypiaxHandles.win32_acInit_WindowClassName,
-             (char *) paucUUIDString);
+			strcpy(tech_pvt->SkypiaxHandles.win32_acInit_WindowClassName, "Skype-API-Skypiax-");
+			strcat(tech_pvt->SkypiaxHandles.win32_acInit_WindowClassName, (char *) paucUUIDString);
 
-      oWindowClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
-      oWindowClass.lpfnWndProc = (WNDPROC) & skypiax_present;
-      oWindowClass.cbClsExtra = 0;
-      oWindowClass.cbWndExtra = 0;
-      oWindowClass.hInstance = tech_pvt->SkypiaxHandles.win32_hInit_ProcessHandle;
-      oWindowClass.hIcon = NULL;
-      oWindowClass.hCursor = NULL;
-      oWindowClass.hbrBackground = NULL;
-      oWindowClass.lpszMenuName = NULL;
-      oWindowClass.lpszClassName = tech_pvt->SkypiaxHandles.win32_acInit_WindowClassName;
+			oWindowClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
+			oWindowClass.lpfnWndProc = (WNDPROC) & skypiax_present;
+			oWindowClass.cbClsExtra = 0;
+			oWindowClass.cbWndExtra = 0;
+			oWindowClass.hInstance = tech_pvt->SkypiaxHandles.win32_hInit_ProcessHandle;
+			oWindowClass.hIcon = NULL;
+			oWindowClass.hCursor = NULL;
+			oWindowClass.hbrBackground = NULL;
+			oWindowClass.lpszMenuName = NULL;
+			oWindowClass.lpszClassName = tech_pvt->SkypiaxHandles.win32_acInit_WindowClassName;
 
-      if (RegisterClass(&oWindowClass) != 0)
-        fReturnStatus = 1;
+			if (RegisterClass(&oWindowClass) != 0)
+				fReturnStatus = 1;
 
-      RpcStringFree(&paucUUIDString);
-    }
-  }
-  if (fReturnStatus == 0)
-    CloseHandle(tech_pvt->SkypiaxHandles.win32_hInit_ProcessHandle);
-  tech_pvt->SkypiaxHandles.win32_hInit_ProcessHandle = NULL;
-  return (fReturnStatus);
+			RpcStringFree(&paucUUIDString);
+		}
+	}
+	if (fReturnStatus == 0)
+		CloseHandle(tech_pvt->SkypiaxHandles.win32_hInit_ProcessHandle);
+	tech_pvt->SkypiaxHandles.win32_hInit_ProcessHandle = NULL;
+	return (fReturnStatus);
 }
 
 void win32_DeInitialize_DestroyWindowClass(private_t * tech_pvt)
 {
-  UnregisterClass(tech_pvt->SkypiaxHandles.win32_acInit_WindowClassName,
-                  tech_pvt->SkypiaxHandles.win32_hInit_ProcessHandle);
-  CloseHandle(tech_pvt->SkypiaxHandles.win32_hInit_ProcessHandle);
-  tech_pvt->SkypiaxHandles.win32_hInit_ProcessHandle = NULL;
+	UnregisterClass(tech_pvt->SkypiaxHandles.win32_acInit_WindowClassName, tech_pvt->SkypiaxHandles.win32_hInit_ProcessHandle);
+	CloseHandle(tech_pvt->SkypiaxHandles.win32_hInit_ProcessHandle);
+	tech_pvt->SkypiaxHandles.win32_hInit_ProcessHandle = NULL;
 }
 
 int win32_Initialize_CreateMainWindow(private_t * tech_pvt)
 {
-  tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle =
-    CreateWindowEx(WS_EX_APPWINDOW | WS_EX_WINDOWEDGE,
-                   tech_pvt->SkypiaxHandles.win32_acInit_WindowClassName, "",
-                   WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT,
-                   128, 128, NULL, 0, tech_pvt->SkypiaxHandles.win32_hInit_ProcessHandle,
-                   tech_pvt);
-  return (tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle != NULL ? 1 : 0);
+	tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle =
+		CreateWindowEx(WS_EX_APPWINDOW | WS_EX_WINDOWEDGE,
+					   tech_pvt->SkypiaxHandles.win32_acInit_WindowClassName, "",
+					   WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT,
+					   128, 128, NULL, 0, tech_pvt->SkypiaxHandles.win32_hInit_ProcessHandle, tech_pvt);
+	return (tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle != NULL ? 1 : 0);
 }
 
 void win32_DeInitialize_DestroyMainWindow(private_t * tech_pvt)
 {
-  if (tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle != NULL)
-    DestroyWindow(tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle),
-      tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle = NULL;
+	if (tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle != NULL)
+		DestroyWindow(tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle), tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle = NULL;
 }
 
 void *skypiax_do_skypeapi_thread_func(void *obj)
 {
-  private_t *tech_pvt = obj;
+	private_t *tech_pvt = obj;
 #if defined(WIN32) && !defined(__CYGWIN__)
-  switch_status_t rv;
+	switch_status_t rv;
 
-  switch_file_pipe_create(&tech_pvt->SkypiaxHandles.fdesc[0],
-                          &tech_pvt->SkypiaxHandles.fdesc[1], skypiax_module_pool);
-  rv =
-    switch_file_pipe_create(&tech_pvt->SkypiaxHandles.fdesc[0],
-                            &tech_pvt->SkypiaxHandles.fdesc[1], skypiax_module_pool);
+	switch_file_pipe_create(&tech_pvt->SkypiaxHandles.fdesc[0], &tech_pvt->SkypiaxHandles.fdesc[1], skypiax_module_pool);
+	rv = switch_file_pipe_create(&tech_pvt->SkypiaxHandles.fdesc[0], &tech_pvt->SkypiaxHandles.fdesc[1], skypiax_module_pool);
 #else /* WIN32 */
-  if (pipe(tech_pvt->SkypiaxHandles.fdesc)) {
-    fcntl(tech_pvt->SkypiaxHandles.fdesc[0], F_SETFL, O_NONBLOCK);
-    fcntl(tech_pvt->SkypiaxHandles.fdesc[1], F_SETFL, O_NONBLOCK);
-  }
+	if (pipe(tech_pvt->SkypiaxHandles.fdesc)) {
+		fcntl(tech_pvt->SkypiaxHandles.fdesc[0], F_SETFL, O_NONBLOCK);
+		fcntl(tech_pvt->SkypiaxHandles.fdesc[1], F_SETFL, O_NONBLOCK);
+	}
 #endif /* WIN32 */
 
-  tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIAttach =
-    RegisterWindowMessage("SkypeControlAPIAttach");
-  tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIDiscover =
-    RegisterWindowMessage("SkypeControlAPIDiscover");
+	tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIAttach = RegisterWindowMessage("SkypeControlAPIAttach");
+	tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIDiscover = RegisterWindowMessage("SkypeControlAPIDiscover");
 
-  skypiax_sleep(200000);        //0,2 sec
+	skypiax_sleep(200000);		//0,2 sec
 
-  if (tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIAttach != 0
-      && tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIDiscover != 0) {
-    if (win32_Initialize_CreateWindowClass(tech_pvt)) {
-      if (win32_Initialize_CreateMainWindow(tech_pvt)) {
-        if (SendMessage
-            (HWND_BROADCAST,
-             tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIDiscover,
-             (WPARAM) tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle, 0) != 0) {
-          tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle =
-            tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle;
-          while (running && tech_pvt->running) {
-            MSG oMessage;
-            if (! (running && tech_pvt->running))
-              break;
-            while (GetMessage(&oMessage, 0, 0, 0)) {
-              TranslateMessage(&oMessage);
-              DispatchMessage(&oMessage);
-            }
-          }
-        }
-        win32_DeInitialize_DestroyMainWindow(tech_pvt);
-      }
-      win32_DeInitialize_DestroyWindowClass(tech_pvt);
-    }
-  }
+	if (tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIAttach != 0
+		&& tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIDiscover != 0) {
+		if (win32_Initialize_CreateWindowClass(tech_pvt)) {
+			if (win32_Initialize_CreateMainWindow(tech_pvt)) {
+				if (SendMessage
+					(HWND_BROADCAST,
+					 tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIDiscover,
+					 (WPARAM) tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle, 0) != 0) {
+					tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle = tech_pvt->SkypiaxHandles.win32_hInit_MainWindowHandle;
+					while (running && tech_pvt->running) {
+						MSG oMessage;
+						if (!(running && tech_pvt->running))
+							break;
+						while (GetMessage(&oMessage, 0, 0, 0)) {
+							TranslateMessage(&oMessage);
+							DispatchMessage(&oMessage);
+						}
+					}
+				}
+				win32_DeInitialize_DestroyMainWindow(tech_pvt);
+			}
+			win32_DeInitialize_DestroyWindowClass(tech_pvt);
+		}
+	}
 
-  return NULL;
+	return NULL;
 }
 
 #else /* NOT WIN32 */
 int X11_errors_handler(Display * dpy, XErrorEvent * err)
 {
-  (void) dpy;
-  private_t *tech_pvt = NULL;
+	(void) dpy;
+	private_t *tech_pvt = NULL;
 
-  xerror = err->error_code;
-  ERRORA("Received error code %d from X Server\n\n", SKYPIAX_P_LOG, xerror); ///FIXME why crash the entire skypiax? just crash the interface, instead
-  running = 0;
-  return 0;                     /*  ignore the error */
+	xerror = err->error_code;
+	ERRORA("Received error code %d from X Server\n\n", SKYPIAX_P_LOG, xerror);	///FIXME why crash the entire skypiax? just crash the interface, instead
+	running = 0;
+	return 0;					/*  ignore the error */
 }
 
 static void X11_errors_trap(void)
 {
-  xerror = 0;
-  old_handler = XSetErrorHandler(X11_errors_handler);
+	xerror = 0;
+	old_handler = XSetErrorHandler(X11_errors_handler);
 }
 
 static int X11_errors_untrap(void)
 {
-  XSetErrorHandler(old_handler);
-  return (xerror != BadValue) && (xerror != BadWindow);
+	XSetErrorHandler(old_handler);
+	return (xerror != BadValue) && (xerror != BadWindow);
 }
 
 int skypiax_send_message(struct SkypiaxHandles *SkypiaxHandles, const char *message_P)
 {
 
-  Window w_P;
-  Display *disp;
-  Window handle_P;
-  int ok;
-  private_t *tech_pvt = NULL;
+	Window w_P;
+	Display *disp;
+	Window handle_P;
+	int ok;
+	private_t *tech_pvt = NULL;
 
-  w_P = SkypiaxHandles->skype_win;
-  disp = SkypiaxHandles->disp;
-  handle_P = SkypiaxHandles->win;
+	w_P = SkypiaxHandles->skype_win;
+	disp = SkypiaxHandles->disp;
+	handle_P = SkypiaxHandles->win;
 
-  Atom atom1 = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False);
-  Atom atom2 = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE", False);
-  unsigned int pos = 0;
-  unsigned int len = strlen(message_P);
-  XEvent e;
+	Atom atom1 = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False);
+	Atom atom2 = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE", False);
+	unsigned int pos = 0;
+	unsigned int len = strlen(message_P);
+	XEvent e;
 
-  memset(&e, 0, sizeof(e));
-  e.xclient.type = ClientMessage;
-  e.xclient.message_type = atom1;   /*  leading message */
-  e.xclient.display = disp;
-  e.xclient.window = handle_P;
-  e.xclient.format = 8;
+	memset(&e, 0, sizeof(e));
+	e.xclient.type = ClientMessage;
+	e.xclient.message_type = atom1;	/*  leading message */
+	e.xclient.display = disp;
+	e.xclient.window = handle_P;
+	e.xclient.format = 8;
 
-  X11_errors_trap();
-  //XLockDisplay(disp);
-  do {
-    unsigned int i;
-    for (i = 0; i < 20 && i + pos <= len; ++i)
-      e.xclient.data.b[i] = message_P[i + pos];
-    XSendEvent(disp, w_P, False, 0, &e);
+	X11_errors_trap();
+	//XLockDisplay(disp);
+	do {
+		unsigned int i;
+		for (i = 0; i < 20 && i + pos <= len; ++i)
+			e.xclient.data.b[i] = message_P[i + pos];
+		XSendEvent(disp, w_P, False, 0, &e);
 
-    e.xclient.message_type = atom2; /*  following messages */
-    pos += i;
-  } while (pos <= len);
+		e.xclient.message_type = atom2;	/*  following messages */
+		pos += i;
+	} while (pos <= len);
 
-  XSync(disp, False);
-  ok = X11_errors_untrap();
+	XSync(disp, False);
+	ok = X11_errors_untrap();
 
-  if (!ok)
-    ERRORA("Sending message failed with status %d\n", SKYPIAX_P_LOG, xerror);
-  //XUnlockDisplay(disp);
+	if (!ok)
+		ERRORA("Sending message failed with status %d\n", SKYPIAX_P_LOG, xerror);
+	//XUnlockDisplay(disp);
 
-  return 1;
+	return 1;
 }
 
 int skypiax_signaling_write(private_t * tech_pvt, char *msg_to_skype)
 {
-  struct SkypiaxHandles *SkypiaxHandles;
+	struct SkypiaxHandles *SkypiaxHandles;
 
-  DEBUGA_SKYPE("SENDING: |||%s||||\n", SKYPIAX_P_LOG, msg_to_skype);
+	DEBUGA_SKYPE("SENDING: |||%s||||\n", SKYPIAX_P_LOG, msg_to_skype);
 
-  SkypiaxHandles = &tech_pvt->SkypiaxHandles;
+	SkypiaxHandles = &tech_pvt->SkypiaxHandles;
 
-  if (!skypiax_send_message(SkypiaxHandles, msg_to_skype)) {
-    ERRORA
-      ("Sending message failed - probably Skype crashed.\n\nPlease shutdown Skypiax, then restart Skype, then launch Skypiax and try again.\n",
-       SKYPIAX_P_LOG);
-    return -1;
-  }
+	if (!skypiax_send_message(SkypiaxHandles, msg_to_skype)) {
+		ERRORA
+			("Sending message failed - probably Skype crashed.\n\nPlease shutdown Skypiax, then restart Skype, then launch Skypiax and try again.\n",
+			 SKYPIAX_P_LOG);
+		return -1;
+	}
 
-  return 0;
+	return 0;
 
 }
 
 int skypiax_present(struct SkypiaxHandles *SkypiaxHandles)
 {
-  Atom skype_inst = XInternAtom(SkypiaxHandles->disp, "_SKYPE_INSTANCE", True);
+	Atom skype_inst = XInternAtom(SkypiaxHandles->disp, "_SKYPE_INSTANCE", True);
 
-  Atom type_ret;
-  int format_ret;
-  unsigned long nitems_ret;
-  unsigned long bytes_after_ret;
-  unsigned char *prop;
-  int status;
-  private_t *tech_pvt = NULL;
+	Atom type_ret;
+	int format_ret;
+	unsigned long nitems_ret;
+	unsigned long bytes_after_ret;
+	unsigned char *prop;
+	int status;
+	private_t *tech_pvt = NULL;
 
-  X11_errors_trap();
-  //XLockDisplay(disp);
-  status =
-    XGetWindowProperty(SkypiaxHandles->disp, DefaultRootWindow(SkypiaxHandles->disp),
-                       skype_inst, 0, 1, False, XA_WINDOW, &type_ret, &format_ret,
-                       &nitems_ret, &bytes_after_ret, &prop);
-  //XUnlockDisplay(disp);
-  X11_errors_untrap();
+	X11_errors_trap();
+	//XLockDisplay(disp);
+	status =
+		XGetWindowProperty(SkypiaxHandles->disp, DefaultRootWindow(SkypiaxHandles->disp),
+						   skype_inst, 0, 1, False, XA_WINDOW, &type_ret, &format_ret, &nitems_ret, &bytes_after_ret, &prop);
+	//XUnlockDisplay(disp);
+	X11_errors_untrap();
 
-  /*  sanity check */
-  if (status != Success || format_ret != 32 || nitems_ret != 1) {
-    SkypiaxHandles->skype_win = (Window) - 1;
-    DEBUGA_SKYPE("Skype instance not found\n", SKYPIAX_P_LOG);
-    running = 0;
-    SkypiaxHandles->api_connected = 0;
-    return 0;
-  }
+	/*  sanity check */
+	if (status != Success || format_ret != 32 || nitems_ret != 1) {
+		SkypiaxHandles->skype_win = (Window) - 1;
+		DEBUGA_SKYPE("Skype instance not found\n", SKYPIAX_P_LOG);
+		running = 0;
+		SkypiaxHandles->api_connected = 0;
+		return 0;
+	}
 
-  SkypiaxHandles->skype_win = *(const unsigned long *) prop & 0xffffffff;
-  DEBUGA_SKYPE("Skype instance found with id #%d\n", SKYPIAX_P_LOG,
-               (unsigned int) SkypiaxHandles->skype_win);
-  SkypiaxHandles->api_connected = 1;
-  return 1;
+	SkypiaxHandles->skype_win = *(const unsigned long *) prop & 0xffffffff;
+	DEBUGA_SKYPE("Skype instance found with id #%d\n", SKYPIAX_P_LOG, (unsigned int) SkypiaxHandles->skype_win);
+	SkypiaxHandles->api_connected = 1;
+	return 1;
 }
 
 void skypiax_clean_disp(void *data)
 {
 
-  int *dispptr;
-  int disp;
-  private_t *tech_pvt = NULL;
+	int *dispptr;
+	int disp;
+	private_t *tech_pvt = NULL;
 
-  dispptr = data;
-  disp = *dispptr;
+	dispptr = data;
+	disp = *dispptr;
 
-  if (disp) {
-    DEBUGA_SKYPE("to be destroyed disp %d\n", SKYPIAX_P_LOG, disp);
-    close(disp);
-    DEBUGA_SKYPE("destroyed disp\n", SKYPIAX_P_LOG);
-  } else {
-    DEBUGA_SKYPE("NOT destroyed disp\n", SKYPIAX_P_LOG);
-  }
-  DEBUGA_SKYPE("OUT destroyed disp\n", SKYPIAX_P_LOG);
-  skypiax_sleep(1000);
+	if (disp) {
+		DEBUGA_SKYPE("to be destroyed disp %d\n", SKYPIAX_P_LOG, disp);
+		close(disp);
+		DEBUGA_SKYPE("destroyed disp\n", SKYPIAX_P_LOG);
+	} else {
+		DEBUGA_SKYPE("NOT destroyed disp\n", SKYPIAX_P_LOG);
+	}
+	DEBUGA_SKYPE("OUT destroyed disp\n", SKYPIAX_P_LOG);
+	skypiax_sleep(1000);
 }
 
 void *skypiax_do_skypeapi_thread_func(void *obj)
 {
 
-  private_t *tech_pvt = obj;
-  struct SkypiaxHandles *SkypiaxHandles;
-  char buf[512];
-  Display *disp = NULL;
-  Window root = -1;
-  Window win = -1;
+	private_t *tech_pvt = obj;
+	struct SkypiaxHandles *SkypiaxHandles;
+	char buf[512];
+	Display *disp = NULL;
+	Window root = -1;
+	Window win = -1;
 
-  if (!strlen(tech_pvt->X11_display))
-    strcpy(tech_pvt->X11_display, getenv("DISPLAY"));
+	if (!strlen(tech_pvt->X11_display))
+		strcpy(tech_pvt->X11_display, getenv("DISPLAY"));
 
-  if (!tech_pvt->tcp_srv_port)
-    tech_pvt->tcp_srv_port = 10160;
+	if (!tech_pvt->tcp_srv_port)
+		tech_pvt->tcp_srv_port = 10160;
 
-  if (!tech_pvt->tcp_cli_port)
-    tech_pvt->tcp_cli_port = 10161;
+	if (!tech_pvt->tcp_cli_port)
+		tech_pvt->tcp_cli_port = 10161;
 
-  if (pipe(tech_pvt->SkypiaxHandles.fdesc)) {
-    fcntl(tech_pvt->SkypiaxHandles.fdesc[0], F_SETFL, O_NONBLOCK);
-    fcntl(tech_pvt->SkypiaxHandles.fdesc[1], F_SETFL, O_NONBLOCK);
-  }
-  SkypiaxHandles = &tech_pvt->SkypiaxHandles;
-  disp = XOpenDisplay(tech_pvt->X11_display);
-  if (!disp) {
-    ERRORA("Cannot open X Display '%s', exiting skype thread\n", SKYPIAX_P_LOG,
-           tech_pvt->X11_display);
-    running = 0;
-    return NULL;
-  } else {
-    DEBUGA_SKYPE("X Display '%s' opened\n", SKYPIAX_P_LOG, tech_pvt->X11_display);
-  }
+	if (pipe(tech_pvt->SkypiaxHandles.fdesc)) {
+		fcntl(tech_pvt->SkypiaxHandles.fdesc[0], F_SETFL, O_NONBLOCK);
+		fcntl(tech_pvt->SkypiaxHandles.fdesc[1], F_SETFL, O_NONBLOCK);
+	}
+	SkypiaxHandles = &tech_pvt->SkypiaxHandles;
+	disp = XOpenDisplay(tech_pvt->X11_display);
+	if (!disp) {
+		ERRORA("Cannot open X Display '%s', exiting skype thread\n", SKYPIAX_P_LOG, tech_pvt->X11_display);
+		running = 0;
+		return NULL;
+	} else {
+		DEBUGA_SKYPE("X Display '%s' opened\n", SKYPIAX_P_LOG, tech_pvt->X11_display);
+	}
 
-  int xfd;
-  xfd = XConnectionNumber(disp);
-  fcntl(xfd, F_SETFD, FD_CLOEXEC);
+	int xfd;
+	xfd = XConnectionNumber(disp);
+	fcntl(xfd, F_SETFD, FD_CLOEXEC);
 
-  SkypiaxHandles->disp = disp;
+	SkypiaxHandles->disp = disp;
 
-  if (skypiax_present(SkypiaxHandles)) {
-    root = DefaultRootWindow(disp);
-    win =
-      XCreateSimpleWindow(disp, root, 0, 0, 1, 1, 0,
-                          BlackPixel(disp, DefaultScreen(disp)), BlackPixel(disp,
-                                                                            DefaultScreen
-                                                                            (disp)));
+	if (skypiax_present(SkypiaxHandles)) {
+		root = DefaultRootWindow(disp);
+		win = XCreateSimpleWindow(disp, root, 0, 0, 1, 1, 0, BlackPixel(disp, DefaultScreen(disp)), BlackPixel(disp, DefaultScreen(disp)));
 
-    SkypiaxHandles->win = win;
+		SkypiaxHandles->win = win;
 
-    snprintf(buf, 512, "NAME skypiax");
+		snprintf(buf, 512, "NAME skypiax");
 
-    if (!skypiax_send_message(SkypiaxHandles, buf)) {
-      ERRORA
-        ("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n",
-         SKYPIAX_P_LOG);
-      running = 0;
-      return NULL;
-    }
+		if (!skypiax_send_message(SkypiaxHandles, buf)) {
+			ERRORA("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n", SKYPIAX_P_LOG);
+			running = 0;
+			return NULL;
+		}
 
-    snprintf(buf, 512, "PROTOCOL 7");
-    if (!skypiax_send_message(SkypiaxHandles, buf)) {
-      ERRORA
-        ("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n",
-         SKYPIAX_P_LOG);
-      running = 0;
-      return NULL;
-    }
+		snprintf(buf, 512, "PROTOCOL 7");
+		if (!skypiax_send_message(SkypiaxHandles, buf)) {
+			ERRORA("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n", SKYPIAX_P_LOG);
+			running = 0;
+			return NULL;
+		}
 
-    /* perform an events loop */
-    XEvent an_event;
-    char buf[21];               /*  can't be longer */
-    char buffer[17000];
-    char *b;
-    int i;
-    int continue_is_broken = 0;
-    Atom atom_begin = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False);
-    Atom atom_continue = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE", False);
+		/* perform an events loop */
+		XEvent an_event;
+		char buf[21];			/*  can't be longer */
+		char buffer[17000];
+		char *b;
+		int i;
+		int continue_is_broken = 0;
+		Atom atom_begin = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE_BEGIN", False);
+		Atom atom_continue = XInternAtom(disp, "SKYPECONTROLAPI_MESSAGE", False);
 
-    b = buffer;
+		b = buffer;
 
-    while (1) {
-      XNextEvent(disp, &an_event);
-      if (! (running && tech_pvt->running))
-        break;
-      switch (an_event.type) {
-      case ClientMessage:
+		while (1) {
+			XNextEvent(disp, &an_event);
+			if (!(running && tech_pvt->running))
+				break;
+			switch (an_event.type) {
+			case ClientMessage:
 
-        if (an_event.xclient.format != 8)
-          break;
+				if (an_event.xclient.format != 8)
+					break;
 
-        for (i = 0; i < 20 && an_event.xclient.data.b[i] != '\0'; ++i)
-          buf[i] = an_event.xclient.data.b[i];
+				for (i = 0; i < 20 && an_event.xclient.data.b[i] != '\0'; ++i)
+					buf[i] = an_event.xclient.data.b[i];
 
-        buf[i] = '\0';
+				buf[i] = '\0';
 
-        //DEBUGA_SKYPE ("BUF=|||%s|||\n", SKYPIAX_P_LOG, buf);
+				//DEBUGA_SKYPE ("BUF=|||%s|||\n", SKYPIAX_P_LOG, buf);
 
-        if (an_event.xclient.message_type == atom_begin) {
+				if (an_event.xclient.message_type == atom_begin) {
 
-          if (strlen(buffer)) {
-            unsigned int howmany;
-            howmany = strlen(b) + 1;
-            howmany = write(SkypiaxHandles->fdesc[1], b, howmany);
-            DEBUGA_SKYPE("RECEIVED2=|||%s|||\n", SKYPIAX_P_LOG, buffer);
-            memset(buffer, '\0', 17000);
-          }
-        }
-        if (an_event.xclient.message_type == atom_continue) {
+					if (strlen(buffer)) {
+						unsigned int howmany;
+						howmany = strlen(b) + 1;
+						howmany = write(SkypiaxHandles->fdesc[1], b, howmany);
+						DEBUGA_SKYPE("RECEIVED2=|||%s|||\n", SKYPIAX_P_LOG, buffer);
+						memset(buffer, '\0', 17000);
+					}
+				}
+				if (an_event.xclient.message_type == atom_continue) {
 
-          if (!strlen(buffer)) {
-            DEBUGA_SKYPE
-              ("Got a 'continue' XAtom without a previous 'begin'. It's value (between vertical bars) is=|||%s|||\n",
-               SKYPIAX_P_LOG, buf);
-            continue_is_broken = 1;
-            if (!strncmp(buf, "ognised identity", 15)) {
-              WARNINGA
-                ("Got a 'continue' XAtom without a previous 'begin'. It's value (between vertical bars) is=|||%s|||. Let's introduce a 1 second delay.\n",
-                 SKYPIAX_P_LOG, buf);
-              skypiax_sleep(1000000);   //1 sec
-            }
-            break;
-          }
-        }
+					if (!strlen(buffer)) {
+						DEBUGA_SKYPE
+							("Got a 'continue' XAtom without a previous 'begin'. It's value (between vertical bars) is=|||%s|||\n", SKYPIAX_P_LOG, buf);
+						continue_is_broken = 1;
+						if (!strncmp(buf, "ognised identity", 15)) {
+							WARNINGA
+								("Got a 'continue' XAtom without a previous 'begin'. It's value (between vertical bars) is=|||%s|||. Let's introduce a 1 second delay.\n",
+								 SKYPIAX_P_LOG, buf);
+							skypiax_sleep(1000000);	//1 sec
+						}
+						break;
+					}
+				}
 
-        strcat(buffer, buf);
+				strcat(buffer, buf);
 
-        if (i < 20 || continue_is_broken) { /* last fragment */
-          unsigned int howmany;
+				if (i < 20 || continue_is_broken) {	/* last fragment */
+					unsigned int howmany;
 
-          howmany = strlen(b) + 1;
+					howmany = strlen(b) + 1;
 
-          howmany = write(SkypiaxHandles->fdesc[1], b, howmany);
-          //DEBUGA_SKYPE ("RECEIVED=|||%s|||\n", SKYPIAX_P_LOG, buffer);
-          memset(buffer, '\0', 17000);
-          XFlush(disp);
-          continue_is_broken = 0;
-        }
+					howmany = write(SkypiaxHandles->fdesc[1], b, howmany);
+					//DEBUGA_SKYPE ("RECEIVED=|||%s|||\n", SKYPIAX_P_LOG, buffer);
+					memset(buffer, '\0', 17000);
+					XFlush(disp);
+					continue_is_broken = 0;
+				}
 
-        break;
-      default:
-        break;
-      }
-    }
-  } else {
-    ERRORA
-      ("Skype is not running, maybe crashed. Please run/restart Skype and relaunch Skypiax\n",
-       SKYPIAX_P_LOG);
-    running = 0;
-    return NULL;
-  }
-  //running = 0;
-  return NULL;
+				break;
+			default:
+				break;
+			}
+		}
+	} else {
+		ERRORA("Skype is not running, maybe crashed. Please run/restart Skype and relaunch Skypiax\n", SKYPIAX_P_LOG);
+		running = 0;
+		return NULL;
+	}
+	//running = 0;
+	return NULL;
 
 }
 #endif // WIN32

Modified: freeswitch/trunk/src/switch_core_io.c (14443 => 14444)


--- freeswitch/trunk/src/switch_core_io.c	2009-08-01 01:02:02 UTC (rev 14443)
+++ freeswitch/trunk/src/switch_core_io.c	2009-08-01 02:47:35 UTC (rev 14444)
@@ -246,7 +246,7 @@
 				switch_codec_t *use_codec = read_frame->codec;
 				if (do_bugs) {
 					if (!switch_core_codec_ready(&session->bug_codec)) {
-						switch_core_codec_copy(read_frame->codec, &session->bug_codec, switch_core_session_get_pool(session));
+						switch_core_codec_copy(read_frame->codec, &session->bug_codec, NULL);
 					}
 					use_codec = &session->bug_codec;
 				}