[Freeswitch-svn] [commit] r8689 - in freeswitch/trunk/src/mod: applications/mod_commands applications/mod_conference applications/mod_dptools applications/mod_enum applications/mod_esf applications/mod_expr applications/mod_fifo applications/mod_fsv applications/mod_limit applications/mod_rss applications/mod_skel applications/mod_soundtouch applications/mod_voicemail asr_tts/mod_cepstral asr_tts/mod_lumenvox asr_tts/mod_openmrcp codecs/mod_amr codecs/mod_g723_1 codecs/mod_g729 codecs/mod_h26x codecs/mod_ilbc codecs/mod_speex codecs/mod_voipcodecs dialplans/mod_dialplan_asterisk dialplans/mod_dialplan_directory dialplans/mod_dialplan_xml endpoints/mod_alsa endpoints/mod_dingaling endpoints/mod_iax endpoints/mod_portaudio endpoints/mod_reference endpoints/mod_sofia endpoints/mod_wanpipe endpoints/mod_woomera event_handlers/mod_cdr_csv event_handlers/mod_event_multicast event_handlers/mod_event_socket event_handlers/mod_event_test event_handlers/mod_radius_cdr formats/mod_local_stream formats/mod_shout formats/mod_sndfile formats/mod_tone_stream languages/mod_lua languages/mod_mono languages/mod_perl languages/mod_python languages/mod_spidermonkey languages/mod_spidermonkey_core_db languages/mod_spidermonkey_curl languages/mod_spidermonkey_odbc languages/mod_spidermonkey_skel languages/mod_spidermonkey_socket languages/mod_spidermonkey_teletone loggers/mod_console loggers/mod_logfile loggers/mod_syslog say/mod_say_de say/mod_say_en say/mod_say_es say/mod_say_fr say/mod_say_it say/mod_say_nl say/mod_say_zh xml_int/mod_xml_cdr xml_int/mod_xml_curl xml_int/mod_xml_ldap xml_int/mod_xml_rpc

Freeswitch SVN anthm at freeswitch.org
Tue May 27 00:54:52 EDT 2008


Author: anthm
Date: Tue May 27 00:54:52 2008
New Revision: 8689

Modified:
   freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
   freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
   freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
   freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c
   freeswitch/trunk/src/mod/applications/mod_esf/mod_esf.c
   freeswitch/trunk/src/mod/applications/mod_expr/expreval.c
   freeswitch/trunk/src/mod/applications/mod_expr/exprfunc.c
   freeswitch/trunk/src/mod/applications/mod_expr/exprinit.c
   freeswitch/trunk/src/mod/applications/mod_expr/exprmem.c
   freeswitch/trunk/src/mod/applications/mod_expr/exprobj.c
   freeswitch/trunk/src/mod/applications/mod_expr/exprpars.c
   freeswitch/trunk/src/mod/applications/mod_expr/exprutil.c
   freeswitch/trunk/src/mod/applications/mod_expr/exprval.c
   freeswitch/trunk/src/mod/applications/mod_expr/mod_expr.c
   freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c
   freeswitch/trunk/src/mod/applications/mod_fsv/mod_fsv.c
   freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c
   freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c
   freeswitch/trunk/src/mod/applications/mod_skel/mod_skel.c
   freeswitch/trunk/src/mod/applications/mod_soundtouch/mod_soundtouch.cpp
   freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
   freeswitch/trunk/src/mod/asr_tts/mod_cepstral/mod_cepstral.c
   freeswitch/trunk/src/mod/asr_tts/mod_lumenvox/mod_lumenvox.cpp
   freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c
   freeswitch/trunk/src/mod/codecs/mod_amr/mod_amr.c
   freeswitch/trunk/src/mod/codecs/mod_g723_1/mod_g723_1.c
   freeswitch/trunk/src/mod/codecs/mod_g729/mod_g729.c
   freeswitch/trunk/src/mod/codecs/mod_h26x/mod_h26x.c
   freeswitch/trunk/src/mod/codecs/mod_ilbc/mod_ilbc.c
   freeswitch/trunk/src/mod/codecs/mod_speex/mod_speex.c
   freeswitch/trunk/src/mod/codecs/mod_voipcodecs/mod_voipcodecs.c
   freeswitch/trunk/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c
   freeswitch/trunk/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c
   freeswitch/trunk/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c
   freeswitch/trunk/src/mod/endpoints/mod_alsa/mod_alsa.c
   freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c
   freeswitch/trunk/src/mod/endpoints/mod_iax/iax-mutex.c
   freeswitch/trunk/src/mod/endpoints/mod_iax/iax.c
   freeswitch/trunk/src/mod/endpoints/mod_iax/iax2-parser.c
   freeswitch/trunk/src/mod/endpoints/mod_iax/jitterbuf.c
   freeswitch/trunk/src/mod/endpoints/mod_iax/md5.c
   freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c
   freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c
   freeswitch/trunk/src/mod/endpoints/mod_portaudio/pablio.c
   freeswitch/trunk/src/mod/endpoints/mod_reference/mod_reference.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
   freeswitch/trunk/src/mod/endpoints/mod_wanpipe/lib_api.c
   freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
   freeswitch/trunk/src/mod/endpoints/mod_wanpipe/ss7boost_client.c
   freeswitch/trunk/src/mod/endpoints/mod_wanpipe/testapp.c
   freeswitch/trunk/src/mod/endpoints/mod_woomera/mod_woomera.c
   freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c
   freeswitch/trunk/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c
   freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
   freeswitch/trunk/src/mod/event_handlers/mod_event_test/mod_event_test.c
   freeswitch/trunk/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c
   freeswitch/trunk/src/mod/formats/mod_local_stream/mod_local_stream.c
   freeswitch/trunk/src/mod/formats/mod_shout/layer3.c
   freeswitch/trunk/src/mod/formats/mod_shout/mod_shout.c
   freeswitch/trunk/src/mod/formats/mod_sndfile/mod_sndfile.c
   freeswitch/trunk/src/mod/formats/mod_tone_stream/mod_tone_stream.c
   freeswitch/trunk/src/mod/languages/mod_lua/freeswitch_lua.cpp
   freeswitch/trunk/src/mod/languages/mod_lua/mod_lua.cpp
   freeswitch/trunk/src/mod/languages/mod_lua/mod_lua_extra.c
   freeswitch/trunk/src/mod/languages/mod_lua/mod_lua_wrap.cpp
   freeswitch/trunk/src/mod/languages/mod_mono/freeswitch_mono.cpp
   freeswitch/trunk/src/mod/languages/mod_mono/mod_mono.cpp
   freeswitch/trunk/src/mod/languages/mod_perl/freeswitch_perl.cpp
   freeswitch/trunk/src/mod/languages/mod_perl/mod_perl.c
   freeswitch/trunk/src/mod/languages/mod_perl/mod_perl_extra.c
   freeswitch/trunk/src/mod/languages/mod_perl/mod_perl_wrap.cpp
   freeswitch/trunk/src/mod/languages/mod_perl/perlxsi.c
   freeswitch/trunk/src/mod/languages/mod_python/freeswitch_python.cpp
   freeswitch/trunk/src/mod/languages/mod_python/mod_python.c
   freeswitch/trunk/src/mod/languages/mod_python/mod_python_wrap.cpp
   freeswitch/trunk/src/mod/languages/mod_python/switch_swig_wrap.c
   freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
   freeswitch/trunk/src/mod/languages/mod_spidermonkey_core_db/mod_spidermonkey_core_db.c
   freeswitch/trunk/src/mod/languages/mod_spidermonkey_curl/mod_spidermonkey_curl.c
   freeswitch/trunk/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c
   freeswitch/trunk/src/mod/languages/mod_spidermonkey_skel/mod_spidermonkey_skel.c
   freeswitch/trunk/src/mod/languages/mod_spidermonkey_socket/mod_spidermonkey_socket.c
   freeswitch/trunk/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c
   freeswitch/trunk/src/mod/loggers/mod_console/mod_console.c
   freeswitch/trunk/src/mod/loggers/mod_logfile/mod_logfile.c
   freeswitch/trunk/src/mod/loggers/mod_syslog/mod_syslog.c
   freeswitch/trunk/src/mod/say/mod_say_de/mod_say_de.c
   freeswitch/trunk/src/mod/say/mod_say_en/mod_say_en.c
   freeswitch/trunk/src/mod/say/mod_say_es/mod_say_es.c
   freeswitch/trunk/src/mod/say/mod_say_fr/mod_say_fr.c
   freeswitch/trunk/src/mod/say/mod_say_it/mod_say_it.c
   freeswitch/trunk/src/mod/say/mod_say_nl/mod_say_nl.c
   freeswitch/trunk/src/mod/say/mod_say_zh/mod_say_zh.c
   freeswitch/trunk/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c
   freeswitch/trunk/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c
   freeswitch/trunk/src/mod/xml_int/mod_xml_ldap/mod_xml_ldap.c
   freeswitch/trunk/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c

Log:
indent pass 2

Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	Tue May 27 00:54:52 2008
@@ -43,7 +43,7 @@
 
 SWITCH_STANDARD_API(user_data_function)
 {
-	switch_xml_t x_domain, xml = NULL, x_user = NULL, x_param, x_params;	
+	switch_xml_t x_domain, xml = NULL, x_user = NULL, x_param, x_params;
 	int argc;
 	char *mydata = NULL, *argv[3], *key = NULL, *type = NULL, *user, *domain;
 	char delim = ' ';
@@ -94,7 +94,7 @@
 		}
 	}
 
-end:
+  end:
 	switch_xml_free(xml);
 	free(mydata);
 	switch_event_destroy(&params);
@@ -115,7 +115,7 @@
 	const char *err = NULL;
 
 	if (stream->param_event && (host = switch_event_get_header(stream->param_event, "http-host"))) {
-		stream->write_function(stream,  "Content-Type: text/xml\r\n\r\n");
+		stream->write_function(stream, "Content-Type: text/xml\r\n\r\n");
 		if ((path_info = switch_event_get_header(stream->param_event, "http-path-info"))) {
 			cmd = path_info;
 			delim = '/';
@@ -151,16 +151,16 @@
 		goto end;
 	}
 
-end:
+  end:
 	if (session || tf) {
 		stream->write_function(stream, err ? "false" : "true");
 		switch_xml_free(xml);
 	} else {
 		if (err) {
 			if (host) {
-				stream->write_function(stream,  "<error>%s</error>\n", err);
+				stream->write_function(stream, "<error>%s</error>\n", err);
 			} else {
-				stream->write_function(stream,  "-Error %s\n", err);
+				stream->write_function(stream, "-Error %s\n", err);
 			}
 		}
 
@@ -168,7 +168,7 @@
 			xmlstr = switch_xml_toxml(x_user, SWITCH_FALSE);
 			switch_assert(xmlstr);
 
-			stream->write_function(stream,  "%s", xmlstr);
+			stream->write_function(stream, "%s", xmlstr);
 			free(xmlstr);
 			switch_xml_free(xml);
 		}
@@ -201,7 +201,7 @@
 	const char *err = NULL;
 
 	if (stream->param_event && (host = switch_event_get_header(stream->param_event, "http-host"))) {
-		stream->write_function(stream,  "Content-Type: text/xml\r\n\r\n");
+		stream->write_function(stream, "Content-Type: text/xml\r\n\r\n");
 		if ((path_info = switch_event_get_header(stream->param_event, "http-path-info"))) {
 			cmd = path_info;
 			delim = '/';
@@ -243,16 +243,16 @@
 	switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "tag_attr_val", tag_attr_val);
 
 	if (switch_xml_locate(section, tag, tag_attr_name, tag_attr_val, &xml, &obj, params) != SWITCH_STATUS_SUCCESS) {
-		stream->write_function(stream,  "can't find anything\n");
+		stream->write_function(stream, "can't find anything\n");
 		goto end;
 	}
 
-end:
+  end:
 	if (err) {
 		if (host) {
-			stream->write_function(stream,  "<error>%s</error>\n", err);
+			stream->write_function(stream, "<error>%s</error>\n", err);
 		} else {
-			stream->write_function(stream,  "-Error %s\n", err);
+			stream->write_function(stream, "-Error %s\n", err);
 		}
 	}
 
@@ -260,7 +260,7 @@
 		xmlstr = switch_xml_toxml(obj, SWITCH_FALSE);
 		switch_assert(xmlstr);
 
-		stream->write_function(stream,  "%s", xmlstr);
+		stream->write_function(stream, "%s", xmlstr);
 		free(xmlstr);
 		switch_xml_free(xml);
 
@@ -274,11 +274,11 @@
 SWITCH_STANDARD_API(reload_acl_function)
 {
 	const char *err;
-    switch_xml_t xml_root;
+	switch_xml_t xml_root;
 
-    if (session) {
-        return SWITCH_STATUS_FALSE;
-    }
+	if (session) {
+		return SWITCH_STATUS_FALSE;
+	}
 
 	if (cmd && !strcmp(cmd, "reloadxml")) {
 		if ((xml_root = switch_xml_open_root(1, &err))) {
@@ -311,15 +311,15 @@
 	}
 
 	if (switch_check_network_list_ip(argv[0], argv[1])) {
-		stream->write_function(stream, "true");    
+		stream->write_function(stream, "true");
 		goto ok;
 	}
 
-error:
+  error:
 
-	stream->write_function(stream, "false");    
+	stream->write_function(stream, "false");
 
-ok:
+  ok:
 
 	switch_safe_free(mydata);
 
@@ -357,10 +357,10 @@
 			substituted = malloc(len);
 			switch_assert(substituted);
 			memset(substituted, 0, len);
-			switch_replace_char(argv[2], '%','$', SWITCH_FALSE);
+			switch_replace_char(argv[2], '%', '$', SWITCH_FALSE);
 			switch_perform_substitution(re, proceed, argv[2], argv[0], substituted, len, ovector);
 
-			stream->write_function(stream, "%s", substituted);    			
+			stream->write_function(stream, "%s", substituted);
 			free(substituted);
 		} else {
 			stream->write_function(stream, "true");
@@ -370,9 +370,9 @@
 	}
 	goto ok;
 
-error:
-	stream->write_function(stream, "-ERR");    
-ok:
+  error:
+	stream->write_function(stream, "-ERR");
+  ok:
 	switch_regex_safe_free(re);
 	switch_safe_free(mydata);
 	return SWITCH_STATUS_SUCCESS;
@@ -426,14 +426,14 @@
 			o = O_NE;
 		}
 	} else if ((expr = strchr(a, '>'))) {
-		if (*(expr+1) == '=') {
+		if (*(expr + 1) == '=') {
 			*expr++ = '\0';
 			o = O_GE;
 		} else {
 			o = O_GT;
 		}
 	} else if ((expr = strchr(a, '<'))) {
-		if (*(expr+1) == '=') {
+		if (*(expr + 1) == '=') {
 			*expr++ = '\0';
 			o = O_LE;
 		} else {
@@ -493,11 +493,11 @@
 		switch_safe_free(s_b);
 		stream->write_function(stream, "%s", is_true ? argv[1] : argv[2]);
 		goto ok;
-	} 
+	}
 
-error:
-	stream->write_function(stream, "-ERR");    
-ok:
+  error:
+	stream->write_function(stream, "-ERR");
+  ok:
 
 	switch_safe_free(mydata);
 	return SWITCH_STATUS_SUCCESS;
@@ -512,7 +512,7 @@
 SWITCH_STANDARD_API(status_function)
 {
 	uint8_t html = 0;
-	switch_core_time_duration_t duration = {0};
+	switch_core_time_duration_t duration = { 0 };
 	char *http = NULL;
 	int sps = 0, last_sps = 0;
 
@@ -532,13 +532,13 @@
 	}
 
 	stream->write_function(stream,
-		"UP %u year%s, %u day%s, %u hour%s, %u minute%s, %u second%s, %u millisecond%s, %u microsecond%s\n",
-		duration.yr, duration.yr == 1 ? "" : "s", duration.day, duration.day == 1 ? "" : "s",
-		duration.hr, duration.hr == 1 ? "" : "s", duration.min, duration.min == 1 ? "" : "s",
-		duration.sec, duration.sec == 1 ? "" : "s", duration.ms, duration.ms == 1 ? "" : "s", duration.mms,
-		duration.mms == 1 ? "" : "s");
+						   "UP %u year%s, %u day%s, %u hour%s, %u minute%s, %u second%s, %u millisecond%s, %u microsecond%s\n",
+						   duration.yr, duration.yr == 1 ? "" : "s", duration.day, duration.day == 1 ? "" : "s",
+						   duration.hr, duration.hr == 1 ? "" : "s", duration.min, duration.min == 1 ? "" : "s",
+						   duration.sec, duration.sec == 1 ? "" : "s", duration.ms, duration.ms == 1 ? "" : "s", duration.mms,
+						   duration.mms == 1 ? "" : "s");
 
-	stream->write_function(stream, "%"SWITCH_SIZE_T_FMT" session(s) since startup\n", switch_core_session_id() - 1 );
+	stream->write_function(stream, "%" SWITCH_SIZE_T_FMT " session(s) since startup\n", switch_core_session_id() - 1);
 	switch_core_session_ctl(SCSC_LAST_SPS, &last_sps);
 	switch_core_session_ctl(SCSC_SPS, &sps);
 	stream->write_function(stream, "%d session(s) %d/%d\n", switch_core_session_count(), last_sps, sps);
@@ -644,10 +644,10 @@
 		} else {
 			stream->write_function(stream, "-ERR INVALID COMMAND\nUSAGE: fsctl %s", CTL_SYNTAX);
 			goto end;
-		} 
+		}
 
 		stream->write_function(stream, "+OK\n");
-end:
+	  end:
 		free(mydata);
 	} else {
 		stream->write_function(stream, "-ERR Memory error\n");
@@ -831,7 +831,7 @@
 
 	switch_core_session_rwunlock(tsession);
 
-done:
+  done:
 	switch_safe_free(mycmd);
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -866,7 +866,7 @@
 	if (argv[4]) {
 		uint32_t mto;
 		if (*argv[4] == '+') {
-			if ((mto = atoi(argv[4]+1)) > 0) {
+			if ((mto = atoi(argv[4] + 1)) > 0) {
 				to = switch_timestamp(NULL) + mto;
 			} else {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID Timeout!\n");
@@ -884,7 +884,7 @@
 	switch_ivr_tone_detect_session(rsession, argv[1], argv[2], argv[3], to, argv[5], argv[6]);
 	stream->write_function(stream, "+OK Enabling tone detection '%s' '%s' '%s'\n", argv[1], argv[2], argv[3]);
 
-done:
+  done:
 
 	free(mydata);
 	switch_core_session_rwunlock(rsession);
@@ -1246,13 +1246,13 @@
 	} else {
 		switch_status_t status;
 		char *who = NULL;
-		
+
 		if ((status = switch_ivr_uuid_bridge(argv[0], argv[1])) != SWITCH_STATUS_SUCCESS) {
 			if (argv[2]) {
 				if ((status = switch_ivr_uuid_bridge(argv[0], argv[2])) == SWITCH_STATUS_SUCCESS) {
 					who = argv[2];
 				}
-			} 
+			}
 		} else {
 			who = argv[1];
 		}
@@ -1317,11 +1317,11 @@
 
 	goto done;
 
-usage:
+  usage:
 	stream->write_function(stream, "-USAGE: %s\n", SESS_REC_SYNTAX);
 	switch_safe_free(mycmd);
 
-done:
+  done:
 	if (rsession) {
 		switch_core_session_rwunlock(rsession);
 	}
@@ -1377,11 +1377,11 @@
 
 	goto done;
 
-usage:
+  usage:
 	stream->write_function(stream, "-USAGE: %s\n", DISPLACE_SYNTAX);
 	switch_safe_free(mycmd);
 
-done:
+  done:
 	if (rsession) {
 		switch_core_session_rwunlock(rsession);
 	}
@@ -1513,7 +1513,8 @@
 		timeout = atoi(argv[6]);
 	}
 
-	if (switch_ivr_originate(NULL, &caller_session, &cause, aleg, timeout, NULL, cid_name, cid_num, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS || !caller_session) {
+	if (switch_ivr_originate(NULL, &caller_session, &cause, aleg, timeout, NULL, cid_name, cid_num, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS
+		|| !caller_session) {
 		if (machine) {
 			stream->write_function(stream, "-ERR %s\n", switch_channel_cause2str(cause));
 		} else {
@@ -1557,7 +1558,7 @@
 
 	switch_core_session_rwunlock(caller_session);
 
-done:
+  done:
 	switch_safe_free(mycmd);
 	return status;
 }
@@ -1594,7 +1595,7 @@
 		int64_t tmp;
 		tmp = (uint32_t) atoi(cmd);
 		if (tmp > 0) {
-			cnt = switch_scheduler_del_task_id((uint32_t)tmp);
+			cnt = switch_scheduler_del_task_id((uint32_t) tmp);
 		}
 	} else {
 		cnt = switch_scheduler_del_task_group(cmd);
@@ -1643,14 +1644,7 @@
 			}
 		}
 
-		stream->write_function(stream, 
-			"<result>\n"
-			"  <row id=\"1\">\n"
-			"    <data>%s</data>\n"
-			"  </row>\n"
-			"</result>\n",
-			send ? send : "ERROR"
-			);
+		stream->write_function(stream, "<result>\n" "  <row id=\"1\">\n" "    <data>%s</data>\n" "  </row>\n" "</result>\n", send ? send : "ERROR");
 		switch_safe_free(mystream.data);
 		switch_safe_free(edata);
 		free(dcommand);
@@ -1688,12 +1682,12 @@
 			id = switch_scheduler_add_task(when, sch_api_callback, (char *) __SWITCH_FUNC__, group, 0, strdup(dcmd), SSHF_FREE_ARG);
 			stream->write_function(stream, "+OK Added: %u\n", id);
 			goto good;
-		} 
+		}
 	}
 
 	stream->write_function(stream, "-ERR Invalid syntax\n");
 
-good:
+  good:
 	switch_safe_free(tm);
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -1701,7 +1695,7 @@
 struct bg_job {
 	char *cmd;
 	char *arg;
-	char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];	
+	char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
 	switch_memory_pool_t *pool;
 };
 
@@ -1715,7 +1709,8 @@
 	char *arg;
 	switch_memory_pool_t *pool;
 
-	if (!job) return NULL;
+	if (!job)
+		return NULL;
 
 	pool = job->pool;
 
@@ -1817,7 +1812,7 @@
 
 	switch_xml_set_attr(switch_xml_set_flag(row, SWITCH_XML_DUP), strdup("row_id"), strdup(id));
 
-	for(x = 0; x < argc; x++) {
+	for (x = 0; x < argc; x++) {
 		char *name = columnNames[x];
 		char *val = switch_str_nil(argv[x]);
 
@@ -1896,7 +1891,7 @@
 	} else {
 		stream->write_function(stream, "-USAGE: %s\n", COMPLETE_SYNTAX);
 	}
-	
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -1912,7 +1907,7 @@
 	} else {
 		stream->write_function(stream, "-USAGE: %s\n", ALIAS_SYNTAX);
 	}
-	
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -1924,7 +1919,7 @@
 	switch_core_db_t *db;
 	struct holder holder = { 0 };
 	int help = 0;
-	char *mydata = NULL, *argv[6] = {0};
+	char *mydata = NULL, *argv[6] = { 0 };
 	int argc;
 	char *command = NULL, *as = NULL;
 	switch_core_flag_t cflags = switch_core_flags();
@@ -1980,7 +1975,8 @@
 		holder.print_title = 0;
 		if ((cmdname = strchr(command, ' ')) != 0) {
 			*cmdname++ = '\0';
-			switch_snprintf(sql, sizeof(sql) - 1, "select name, syntax, description from interfaces where type = 'api' and name = '%s' order by name", cmdname);
+			switch_snprintf(sql, sizeof(sql) - 1, "select name, syntax, description from interfaces where type = 'api' and name = '%s' order by name",
+							cmdname);
 		} else {
 			switch_snprintf(sql, sizeof(sql) - 1, "select name, syntax, description from interfaces where type = 'api' order by name");
 		}
@@ -2127,10 +2123,10 @@
 
 	stream->write_function(stream, "-USAGE: %s\n", SETVAR_SYNTAX);
 
-done:
+  done:
 	switch_safe_free(mycmd);
 	return SWITCH_STATUS_SUCCESS;
-} 
+}
 
 #define GETVAR_SYNTAX "<uuid> <var>"
 SWITCH_STANDARD_API(uuid_getvar_function)
@@ -2177,7 +2173,7 @@
 
 	stream->write_function(stream, "-USAGE: %s\n", GETVAR_SYNTAX);
 
-done:
+  done:
 	switch_safe_free(mycmd);
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -2224,7 +2220,7 @@
 					}
 
 					switch_assert(buf);
-					stream->raw_write_function(stream, (unsigned char *)buf, strlen(buf));
+					stream->raw_write_function(stream, (unsigned char *) buf, strlen(buf));
 					switch_event_destroy(&event);
 					free(buf);
 				} else {
@@ -2242,7 +2238,7 @@
 
 	stream->write_function(stream, "-USAGE: %s\n", DUMP_SYNTAX);
 
-done:
+  done:
 	switch_safe_free(mycmd);
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -2270,10 +2266,10 @@
 
 	stream->write_function(stream, "-USAGE: %s\n", GLOBAL_SETVAR_SYNTAX);
 
-done:
+  done:
 	switch_safe_free(mycmd);
 	return SWITCH_STATUS_SUCCESS;
-} 
+}
 
 #define GLOBAL_GETVAR_SYNTAX "<var>"
 SWITCH_STANDARD_API(global_getvar_function)
@@ -2285,7 +2281,7 @@
 	}
 
 	stream->write_function(stream, "-USAGE: %s\n", GLOBAL_GETVAR_SYNTAX);
-done:
+  done:
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -2325,8 +2321,10 @@
 	SWITCH_ADD_API(commands_api_interface, "help", "Show help for all the api commands", help_function, "");
 	SWITCH_ADD_API(commands_api_interface, "version", "Show version of the switch", version_function, "");
 	SWITCH_ADD_API(commands_api_interface, "sched_hangup", "Schedule a running call to hangup", sched_hangup_function, SCHED_HANGUP_SYNTAX);
-	SWITCH_ADD_API(commands_api_interface, "sched_broadcast", "Schedule a broadcast event to a running call", sched_broadcast_function, SCHED_BROADCAST_SYNTAX);
-	SWITCH_ADD_API(commands_api_interface, "sched_transfer", "Schedule a broadcast event to a running call", sched_transfer_function, SCHED_TRANSFER_SYNTAX);
+	SWITCH_ADD_API(commands_api_interface, "sched_broadcast", "Schedule a broadcast event to a running call", sched_broadcast_function,
+				   SCHED_BROADCAST_SYNTAX);
+	SWITCH_ADD_API(commands_api_interface, "sched_transfer", "Schedule a broadcast event to a running call", sched_transfer_function,
+				   SCHED_TRANSFER_SYNTAX);
 	SWITCH_ADD_API(commands_api_interface, "create_uuid", "Create a uuid", uuid_function, UUID_SYNTAX);
 	SWITCH_ADD_API(commands_api_interface, "sched_api", "Schedule an api command", sched_api_function, "[+]<time> <group_name> <command_string>");
 	SWITCH_ADD_API(commands_api_interface, "bgapi", "Execute an api command in a thread", bgapi_function, "<command>[ <arg>]");

Modified: freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c	Tue May 27 00:54:52 2008
@@ -137,7 +137,7 @@
 	MFLAG_WASTE_BANDWIDTH = (1 << 7),
 	MFLAG_FLUSH_BUFFER = (1 << 8),
 	MFLAG_ENDCONF = (1 << 9),
-    MFLAG_HAS_AUDIO = (1 << 10),
+	MFLAG_HAS_AUDIO = (1 << 10),
 	MFLAG_TALKING = (1 << 11)
 } member_flag_t;
 
@@ -257,9 +257,9 @@
 	uint8_t min;
 	switch_speech_handle_t lsh;
 	switch_speech_handle_t *sh;
-    switch_byte_t *not_talking_buf;
-    uint32_t not_talking_buf_len;
-    int comfort_noise_level;
+	switch_byte_t *not_talking_buf;
+	uint32_t not_talking_buf_len;
+	int comfort_noise_level;
 	int video_running;
 	uint32_t eflags;
 } conference_obj_t;
@@ -290,7 +290,7 @@
 	switch_codec_t write_codec;
 	char *rec_path;
 	uint8_t *frame;
-    uint32_t frame_size;
+	uint32_t frame_size;
 	uint8_t *mux_frame;
 	uint32_t read;
 	int32_t energy_level;
@@ -298,8 +298,8 @@
 	int32_t volume_out_level;
 	uint32_t native_rate;
 	switch_audio_resampler_t *read_resampler;
-    int16_t *resample_out;
-    uint32_t resample_out_len;
+	int16_t *resample_out;
+	uint32_t resample_out_len;
 	conference_file_node_t *fnode;
 	conference_relationship_t *relationships;
 	switch_ivr_digit_stream_parser_t *dtmf_parser;
@@ -335,54 +335,54 @@
 
 /* Function Prototypes */
 static uint32_t next_member_id(void);
-static conference_relationship_t *member_get_relationship(conference_member_t * member, conference_member_t * other_member);
-static conference_member_t *conference_member_get(conference_obj_t * conference, uint32_t id);
-static conference_relationship_t *member_add_relationship(conference_member_t * member, uint32_t id);
-static switch_status_t member_del_relationship(conference_member_t * member, uint32_t id);
-static switch_status_t conference_add_member(conference_obj_t * conference, conference_member_t * member);
-static switch_status_t conference_del_member(conference_obj_t * conference, conference_member_t * member);
-static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t * thread, void *obj);
-static void *SWITCH_THREAD_FUNC conference_video_thread_run(switch_thread_t * thread, void *obj);
-static void conference_loop_output(conference_member_t * member);
-static uint32_t conference_stop_file(conference_obj_t * conference, file_stop_t stop);
-static switch_status_t conference_play_file(conference_obj_t * conference, char *file, uint32_t leadin, switch_channel_t *channel, uint8_t async);
-static switch_status_t conference_say(conference_obj_t * conference, const char *text, uint32_t leadin);
-static void conference_list(conference_obj_t * conference, switch_stream_handle_t *stream, char *delim);
+static conference_relationship_t *member_get_relationship(conference_member_t *member, conference_member_t *other_member);
+static conference_member_t *conference_member_get(conference_obj_t *conference, uint32_t id);
+static conference_relationship_t *member_add_relationship(conference_member_t *member, uint32_t id);
+static switch_status_t member_del_relationship(conference_member_t *member, uint32_t id);
+static switch_status_t conference_add_member(conference_obj_t *conference, conference_member_t *member);
+static switch_status_t conference_del_member(conference_obj_t *conference, conference_member_t *member);
+static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t *thread, void *obj);
+static void *SWITCH_THREAD_FUNC conference_video_thread_run(switch_thread_t *thread, void *obj);
+static void conference_loop_output(conference_member_t *member);
+static uint32_t conference_stop_file(conference_obj_t *conference, file_stop_t stop);
+static switch_status_t conference_play_file(conference_obj_t *conference, char *file, uint32_t leadin, switch_channel_t *channel, uint8_t async);
+static switch_status_t conference_say(conference_obj_t *conference, const char *text, uint32_t leadin);
+static void conference_list(conference_obj_t *conference, switch_stream_handle_t *stream, char *delim);
 SWITCH_STANDARD_API(conf_api_main);
 
-static switch_status_t conference_outcall(conference_obj_t * conference,
+static switch_status_t conference_outcall(conference_obj_t *conference,
 										  char *conference_name,
 										  switch_core_session_t *session,
 										  char *bridgeto, uint32_t timeout, char *flags, char *cid_name, char *cid_num, switch_call_cause_t *cause);
-static switch_status_t conference_outcall_bg(conference_obj_t * conference,
+static switch_status_t conference_outcall_bg(conference_obj_t *conference,
 											 char *conference_name,
-											 switch_core_session_t *session, char *bridgeto, uint32_t timeout, const char *flags, const char *cid_name, const char *cid_num);
+											 switch_core_session_t *session, char *bridgeto, uint32_t timeout, const char *flags, const char *cid_name,
+											 const char *cid_num);
 SWITCH_STANDARD_APP(conference_function);
-static void launch_conference_thread(conference_obj_t * conference);
-static void launch_conference_video_thread(conference_obj_t * conference);
-static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t * thread, void *obj);
-static switch_status_t conference_local_play_file(conference_obj_t * conference,
-												  switch_core_session_t *session, char *path, uint32_t leadin);
-static switch_status_t conference_member_play_file(conference_member_t * member, char *file, uint32_t leadin);
-static switch_status_t conference_member_say(conference_member_t * member, char *text, uint32_t leadin);
-static uint32_t conference_member_stop_file(conference_member_t * member, file_stop_t stop);
+static void launch_conference_thread(conference_obj_t *conference);
+static void launch_conference_video_thread(conference_obj_t *conference);
+static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t *thread, void *obj);
+static switch_status_t conference_local_play_file(conference_obj_t *conference, switch_core_session_t *session, char *path, uint32_t leadin);
+static switch_status_t conference_member_play_file(conference_member_t *member, char *file, uint32_t leadin);
+static switch_status_t conference_member_say(conference_member_t *member, char *text, uint32_t leadin);
+static uint32_t conference_member_stop_file(conference_member_t *member, file_stop_t stop);
 static conference_obj_t *conference_new(char *name, conf_xml_cfg_t cfg, switch_memory_pool_t *pool);
 static switch_status_t chat_send(char *proto, char *from, char *to, char *subject, char *body, char *hint);
-static void launch_conference_record_thread(conference_obj_t * conference, char *path);
+static void launch_conference_record_thread(conference_obj_t *conference, char *path);
 
 typedef switch_status_t (*conf_api_args_cmd_t) (conference_obj_t *, switch_stream_handle_t *, int, char **);
 typedef switch_status_t (*conf_api_member_cmd_t) (conference_member_t *, switch_stream_handle_t *, void *);
 typedef switch_status_t (*conf_api_text_cmd_t) (conference_obj_t *, switch_stream_handle_t *, const char *);
 
-static void conference_member_itterator(conference_obj_t * conference, switch_stream_handle_t *stream, conf_api_member_cmd_t pfncallback, void *data);
-static switch_status_t conf_api_sub_mute(conference_member_t * member, switch_stream_handle_t *stream, void *data);
-static switch_status_t conf_api_sub_unmute(conference_member_t * member, switch_stream_handle_t *stream, void *data);
-static switch_status_t conf_api_sub_deaf(conference_member_t * member, switch_stream_handle_t *stream, void *data);
-static switch_status_t conf_api_sub_undeaf(conference_member_t * member, switch_stream_handle_t *stream, void *data);
-static switch_status_t conference_add_event_data(conference_obj_t * conference, switch_event_t *event);
-static switch_status_t conference_add_event_member_data(conference_member_t * member, switch_event_t *event);
+static void conference_member_itterator(conference_obj_t *conference, switch_stream_handle_t *stream, conf_api_member_cmd_t pfncallback, void *data);
+static switch_status_t conf_api_sub_mute(conference_member_t *member, switch_stream_handle_t *stream, void *data);
+static switch_status_t conf_api_sub_unmute(conference_member_t *member, switch_stream_handle_t *stream, void *data);
+static switch_status_t conf_api_sub_deaf(conference_member_t *member, switch_stream_handle_t *stream, void *data);
+static switch_status_t conf_api_sub_undeaf(conference_member_t *member, switch_stream_handle_t *stream, void *data);
+static switch_status_t conference_add_event_data(conference_obj_t *conference, switch_event_t *event);
+static switch_status_t conference_add_event_member_data(conference_member_t *member, switch_event_t *event);
 
-static switch_status_t conference_add_event_data(conference_obj_t * conference, switch_event_t *event)
+static switch_status_t conference_add_event_data(conference_obj_t *conference, switch_event_t *event)
 {
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
 
@@ -392,11 +392,12 @@
 
 	return status;
 }
-static switch_status_t conference_add_event_member_data(conference_member_t * member, switch_event_t *event)
+static switch_status_t conference_add_event_member_data(conference_member_t *member, switch_event_t *event)
 {
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
-	
-	if (!member) return status;
+
+	if (!member)
+		return status;
 
 	if (member->session) {
 		switch_channel_t *channel = switch_core_session_get_channel(member->session);
@@ -426,11 +427,12 @@
 }
 
 /* if other_member has a relationship with member, produce it */
-static conference_relationship_t *member_get_relationship(conference_member_t * member, conference_member_t * other_member)
+static conference_relationship_t *member_get_relationship(conference_member_t *member, conference_member_t *other_member)
 {
 	conference_relationship_t *rel = NULL, *global = NULL;
 
-	if (member == NULL || other_member == NULL || member->relationships == NULL) return NULL;
+	if (member == NULL || other_member == NULL || member->relationships == NULL)
+		return NULL;
 
 	switch_mutex_lock(member->flag_mutex);
 	switch_mutex_lock(other_member->flag_mutex);
@@ -453,11 +455,11 @@
 }
 
 /* traverse the conference member list for the specified member id and return it's pointer */
-static conference_member_t *conference_member_get(conference_obj_t * conference, uint32_t id)
+static conference_member_t *conference_member_get(conference_obj_t *conference, uint32_t id)
 {
 	conference_member_t *member = NULL;
 
-	switch_assert(conference != NULL); 
+	switch_assert(conference != NULL);
 	if (!id) {
 		return NULL;
 	}
@@ -484,7 +486,7 @@
 }
 
 /* stop the specified recording */
-static switch_status_t conference_record_stop(conference_obj_t * conference, char *path)
+static switch_status_t conference_record_stop(conference_obj_t *conference, char *path)
 {
 	conference_member_t *member = NULL;
 	int count = 0;
@@ -502,11 +504,12 @@
 }
 
 /* Add a custom relationship to a member */
-static conference_relationship_t *member_add_relationship(conference_member_t * member, uint32_t id)
+static conference_relationship_t *member_add_relationship(conference_member_t *member, uint32_t id)
 {
 	conference_relationship_t *rel = NULL;
 
-	if (member == NULL || id == 0 || !(rel = switch_core_alloc(member->pool, sizeof(*rel)))) return NULL;
+	if (member == NULL || id == 0 || !(rel = switch_core_alloc(member->pool, sizeof(*rel))))
+		return NULL;
 
 	rel->id = id;
 
@@ -519,12 +522,13 @@
 }
 
 /* Remove a custom relationship from a member */
-static switch_status_t member_del_relationship(conference_member_t * member, uint32_t id)
+static switch_status_t member_del_relationship(conference_member_t *member, uint32_t id)
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	conference_relationship_t *rel, *last = NULL;
 
-	if (member == NULL || id == 0) return status;
+	if (member == NULL || id == 0)
+		return status;
 
 	switch_mutex_lock(member->flag_mutex);
 	for (rel = member->relationships; rel; rel = rel->next) {
@@ -546,11 +550,11 @@
 }
 
 /* Gain exclusive access and add the member to the list */
-static switch_status_t conference_add_member(conference_obj_t * conference, conference_member_t * member)
+static switch_status_t conference_add_member(conference_obj_t *conference, conference_member_t *member)
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	switch_event_t *event;
-	char msg[512];					/* conference count anouncement */
+	char msg[512];				/* conference count anouncement */
 	call_list_t *call_list = NULL;
 	switch_channel_t *channel;
 
@@ -600,7 +604,7 @@
 
 		channel = switch_core_session_get_channel(member->session);
 		call_list = (call_list_t *) switch_channel_get_private(channel, "_conference_autocall_list_");
-			
+
 		if (call_list) {
 			char saymsg[1024];
 			switch_snprintf(saymsg, sizeof(saymsg), "Auto Calling %d parties", call_list->itteration);
@@ -613,13 +617,14 @@
 					conference_member_say(member, msg, CONF_DEFAULT_LEADIN);
 				} else if (conference->count == 1 && !conference->perpetual_sound) {
 					if (conference->alone_sound) {
-						conference_play_file(conference, conference->alone_sound, CONF_DEFAULT_LEADIN, switch_core_session_get_channel(member->session), 0);
+						conference_play_file(conference, conference->alone_sound, CONF_DEFAULT_LEADIN, switch_core_session_get_channel(member->session),
+											 0);
 					} else {
 						switch_snprintf(msg, sizeof(msg), "You are currently the only person in this conference.");
 						conference_member_say(member, msg, CONF_DEFAULT_LEADIN);
 					}
 				}
-			} 
+			}
 		}
 
 		if (conference->count == 1) {
@@ -650,7 +655,7 @@
 }
 
 /* Gain exclusive access and remove the member from the list */
-static switch_status_t conference_del_member(conference_obj_t * conference, conference_member_t * member)
+static switch_status_t conference_del_member(conference_obj_t *conference, conference_member_t *member)
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	conference_member_t *imember, *last = NULL;
@@ -712,7 +717,7 @@
 	}
 
 	member->conference = NULL;
-	
+
 	if (!switch_test_flag(member, MFLAG_NOCHANNEL)) {
 		conference->count--;
 		if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
@@ -773,7 +778,7 @@
 	switch_frame_t *vid_frame;
 	switch_status_t status;
 	int has_vid = 1, req_iframe = 0;
-	
+
 	conference->video_running = 1;
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Video thread started for conference %s\n", conference->name);
 
@@ -781,17 +786,17 @@
 		if (!conference->floor_holder) {
 			switch_yield(100000);
 			continue;
-		} 
-		
+		}
+
 		if (switch_channel_test_flag(switch_core_session_get_channel(conference->floor_holder->session), CF_VIDEO)) {
 			status = switch_core_session_read_video_frame(conference->floor_holder->session, &vid_frame, SWITCH_IO_FLAG_NONE, 0);
-			
+
 			if (!SWITCH_READ_ACCEPTABLE(status)) {
 				conference->floor_holder = NULL;
 				req_iframe = 0;
 				continue;
 			}
-			
+
 			if (switch_test_flag(vid_frame, SFF_CNG)) {
 				continue;
 			}
@@ -810,18 +815,18 @@
 					req_iframe = 1;
 				}
 #endif
-		
-				if (vid_frame->codec->implementation->ianacode == 34) { /* h.263 */
-					iframe = (*((int16_t*)vid_frame->data) >> 12 == 6);
-				} else if (vid_frame->codec->implementation->ianacode == 115) { /* h.263-1998 */
-					int y = *((int8_t*)vid_frame->data + 2) & 0xfe;
-					iframe = (y == 0x80 || y == 0x82);					
-				} else if (vid_frame->codec->implementation->ianacode == 99) { /* h.264 */
-					iframe = (*((int16_t*)vid_frame->data) >> 5 == 0x11);
-				} else { /* we need more defs */
+
+				if (vid_frame->codec->implementation->ianacode == 34) {	/* h.263 */
+					iframe = (*((int16_t *) vid_frame->data) >> 12 == 6);
+				} else if (vid_frame->codec->implementation->ianacode == 115) {	/* h.263-1998 */
+					int y = *((int8_t *) vid_frame->data + 2) & 0xfe;
+					iframe = (y == 0x80 || y == 0x82);
+				} else if (vid_frame->codec->implementation->ianacode == 99) {	/* h.264 */
+					iframe = (*((int16_t *) vid_frame->data) >> 5 == 0x11);
+				} else {		/* we need more defs */
 					iframe = 1;
 				}
-				
+
 				if (!iframe) {
 					continue;
 				}
@@ -830,8 +835,8 @@
 			}
 
 			last_member = conference->floor_holder;
-			
-			switch_mutex_lock(conference->member_mutex);	
+
+			switch_mutex_lock(conference->member_mutex);
 			has_vid = 0;
 			for (imember = conference->members; imember; imember = imember->next) {
 				if (switch_channel_test_flag(switch_core_session_get_channel(imember->session), CF_VIDEO)) {
@@ -849,7 +854,7 @@
 }
 
 /* Main monitor thread (1 per distinct conference room) */
-static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t * thread, void *obj)
+static void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t *thread, void *obj)
 {
 	conference_obj_t *conference = (conference_obj_t *) obj;
 	conference_member_t *imember, *omember;
@@ -860,7 +865,7 @@
 	switch_event_t *event;
 	uint8_t *file_frame;
 	uint8_t *async_file_frame;
-	
+
 	file_frame = switch_core_alloc(conference->pool, SWITCH_RECOMMENDED_BUFFER_SIZE);
 	async_file_frame = switch_core_alloc(conference->pool, SWITCH_RECOMMENDED_BUFFER_SIZE);
 
@@ -879,7 +884,7 @@
 		switch_size_t file_sample_len = samples;
 		switch_size_t file_data_len = samples * 2;
 		int has_file_data = 0, members_with_video = 0;
-		
+
 		if (conference->perpetual_sound && !conference->async_fnode) {
 			conference_play_file(conference, conference->perpetual_sound, CONF_DEFAULT_LEADIN, NULL, 1);
 		} else if (conference->moh_sound && conference->count == 1 && !conference->async_fnode) {
@@ -891,7 +896,7 @@
 			switch_set_flag(conference, CFLAG_DESTRUCT);
 			break;
 		}
-		
+
 		switch_mutex_lock(conference->mutex);
 		has_file_data = ready = total = 0;
 
@@ -908,11 +913,11 @@
 			switch_clear_flag_locked(imember, MFLAG_HAS_AUDIO);
 			switch_mutex_lock(imember->audio_in_mutex);
 
-			if (switch_buffer_inuse(imember->audio_buffer) >= bytes 
-                && (buf_read = (uint32_t) switch_buffer_read(imember->audio_buffer, imember->frame, bytes))) {
-                imember->read = buf_read;
-                switch_set_flag_locked(imember, MFLAG_HAS_AUDIO);
-                ready++;
+			if (switch_buffer_inuse(imember->audio_buffer) >= bytes
+				&& (buf_read = (uint32_t) switch_buffer_read(imember->audio_buffer, imember->frame, bytes))) {
+				imember->read = buf_read;
+				switch_set_flag_locked(imember, MFLAG_HAS_AUDIO);
+				ready++;
 			}
 			switch_mutex_unlock(imember->audio_in_mutex);
 		}
@@ -940,15 +945,15 @@
 				} else if (conference->fnode->type == NODE_TYPE_FILE) {
 					switch_core_file_read(&conference->fnode->fh, file_frame, &file_sample_len);
 				}
-				
+
 				if (file_sample_len <= 0) {
 					conference->fnode->done++;
 				} else {
 					has_file_data = 1;
 				}
-			}			
+			}
 		}
-		
+
 		if (conference->async_fnode) {
 			/* Lead in time */
 			if (conference->async_fnode->leadin) {
@@ -984,25 +989,25 @@
 		if (ready || has_file_data) {
 			//int nt = 0;
 			/* Build a muxed frame for every member that contains the mixed audio of everyone else */
-			
+
 			for (omember = conference->members; omember; omember = omember->next) {
 				if (has_file_data && file_sample_len) {
-                    uint32_t sample_bytes = file_sample_len * 2;
+					uint32_t sample_bytes = file_sample_len * 2;
 					memcpy(omember->mux_frame, file_frame, sample_bytes);
-                    if (sample_bytes < bytes) {
-                        if (conference->comfort_noise_level) {
-                            switch_generate_sln_silence((int16_t *)omember->mux_frame + sample_bytes, 
-                                                        (bytes - sample_bytes) / 2, conference->comfort_noise_level);
-                        } else {
-                            memset(omember->mux_frame + sample_bytes, 255, bytes - sample_bytes);
-                        }
-                    }
-                } else {
-                    if (conference->comfort_noise_level) {
-                        switch_generate_sln_silence((int16_t *)omember->mux_frame, bytes / 2, conference->comfort_noise_level);
-                    } else {
-                        memset(omember->mux_frame, 255, bytes);
-                    }
+					if (sample_bytes < bytes) {
+						if (conference->comfort_noise_level) {
+							switch_generate_sln_silence((int16_t *) omember->mux_frame + sample_bytes,
+														(bytes - sample_bytes) / 2, conference->comfort_noise_level);
+						} else {
+							memset(omember->mux_frame + sample_bytes, 255, bytes - sample_bytes);
+						}
+					}
+				} else {
+					if (conference->comfort_noise_level) {
+						switch_generate_sln_silence((int16_t *) omember->mux_frame, bytes / 2, conference->comfort_noise_level);
+					} else {
+						memset(omember->mux_frame, 255, bytes);
+					}
 				}
 				for (imember = conference->members; imember; imember = imember->next) {
 					uint32_t x;
@@ -1022,7 +1027,7 @@
 								continue;
 							}
 						}
-					} 
+					}
 
 					/* If we are not supposed to hear them then don't let it happen */
 					if (imember->relationships) {
@@ -1168,7 +1173,7 @@
 
 	if (conference->video_running == 1) {
 		conference->video_running = -1;
-		while(conference->video_running) {
+		while (conference->video_running) {
 			switch_yield(1000);
 		}
 	}
@@ -1207,9 +1212,10 @@
 	return NULL;
 }
 
-static void conference_loop_fn_mute_toggle(conference_member_t * member, caller_control_action_t * action)
+static void conference_loop_fn_mute_toggle(conference_member_t *member, caller_control_action_t *action)
 {
-	if (member == NULL) return;
+	if (member == NULL)
+		return;
 
 	if (switch_test_flag(member, MFLAG_CAN_SPEAK)) {
 		conf_api_sub_mute(member, NULL, NULL);
@@ -1221,9 +1227,10 @@
 	}
 }
 
-static void conference_loop_fn_deafmute_toggle(conference_member_t * member, caller_control_action_t * action)
+static void conference_loop_fn_deafmute_toggle(conference_member_t *member, caller_control_action_t *action)
 {
-	if (member == NULL) return;
+	if (member == NULL)
+		return;
 
 	if (switch_test_flag(member, MFLAG_CAN_SPEAK)) {
 		conf_api_sub_mute(member, NULL, NULL);
@@ -1238,12 +1245,13 @@
 	}
 }
 
-static void conference_loop_fn_energy_up(conference_member_t * member, caller_control_action_t * action)
+static void conference_loop_fn_energy_up(conference_member_t *member, caller_control_action_t *action)
 {
 	char msg[512];
 	switch_event_t *event;
 
-	if (member == NULL) return;
+	if (member == NULL)
+		return;
 
 	switch_mutex_lock(member->flag_mutex);
 	member->energy_level += 200;
@@ -1264,12 +1272,13 @@
 	conference_member_say(member, msg, 0);
 }
 
-static void conference_loop_fn_energy_equ_conf(conference_member_t * member, caller_control_action_t * action)
+static void conference_loop_fn_energy_equ_conf(conference_member_t *member, caller_control_action_t *action)
 {
 	char msg[512];
 	switch_event_t *event;
 
-	if (member == NULL) return;
+	if (member == NULL)
+		return;
 
 	switch_mutex_lock(member->flag_mutex);
 	member->energy_level = member->conference->energy_level;
@@ -1287,12 +1296,13 @@
 	conference_member_say(member, msg, 0);
 }
 
-static void conference_loop_fn_energy_dn(conference_member_t * member, caller_control_action_t * action)
+static void conference_loop_fn_energy_dn(conference_member_t *member, caller_control_action_t *action)
 {
 	char msg[512];
 	switch_event_t *event;
 
-	if (member == NULL) return;
+	if (member == NULL)
+		return;
 
 	switch_mutex_lock(member->flag_mutex);
 	member->energy_level -= 100;
@@ -1313,12 +1323,13 @@
 	conference_member_say(member, msg, 0);
 }
 
-static void conference_loop_fn_volume_talk_up(conference_member_t * member, caller_control_action_t * action)
+static void conference_loop_fn_volume_talk_up(conference_member_t *member, caller_control_action_t *action)
 {
 	char msg[512];
 	switch_event_t *event;
 
-	if (member == NULL) return;
+	if (member == NULL)
+		return;
 
 	switch_mutex_lock(member->flag_mutex);
 	member->volume_out_level++;
@@ -1337,12 +1348,13 @@
 	conference_member_say(member, msg, 0);
 }
 
-static void conference_loop_fn_volume_talk_zero(conference_member_t * member, caller_control_action_t * action)
+static void conference_loop_fn_volume_talk_zero(conference_member_t *member, caller_control_action_t *action)
 {
 	char msg[512];
 	switch_event_t *event;
 
-	if (member == NULL) return;
+	if (member == NULL)
+		return;
 
 	switch_mutex_lock(member->flag_mutex);
 	member->volume_out_level = 0;
@@ -1360,12 +1372,13 @@
 	conference_member_say(member, msg, 0);
 }
 
-static void conference_loop_fn_volume_talk_dn(conference_member_t * member, caller_control_action_t * action)
+static void conference_loop_fn_volume_talk_dn(conference_member_t *member, caller_control_action_t *action)
 {
 	char msg[512];
 	switch_event_t *event;
 
-	if (member == NULL) return;
+	if (member == NULL)
+		return;
 
 	switch_mutex_lock(member->flag_mutex);
 	member->volume_out_level--;
@@ -1384,12 +1397,13 @@
 	conference_member_say(member, msg, 0);
 }
 
-static void conference_loop_fn_volume_listen_up(conference_member_t * member, caller_control_action_t * action)
+static void conference_loop_fn_volume_listen_up(conference_member_t *member, caller_control_action_t *action)
 {
 	char msg[512];
 	switch_event_t *event;
 
-	if (member == NULL) return;
+	if (member == NULL)
+		return;
 
 	switch_mutex_lock(member->flag_mutex);
 	member->volume_in_level++;
@@ -1408,12 +1422,13 @@
 	conference_member_say(member, msg, 0);
 }
 
-static void conference_loop_fn_volume_listen_zero(conference_member_t * member, caller_control_action_t * action)
+static void conference_loop_fn_volume_listen_zero(conference_member_t *member, caller_control_action_t *action)
 {
 	char msg[512];
 	switch_event_t *event;
 
-	if (member == NULL) return;
+	if (member == NULL)
+		return;
 
 	switch_mutex_lock(member->flag_mutex);
 	member->volume_in_level = 0;
@@ -1431,12 +1446,13 @@
 	conference_member_say(member, msg, 0);
 }
 
-static void conference_loop_fn_volume_listen_dn(conference_member_t * member, caller_control_action_t * action)
+static void conference_loop_fn_volume_listen_dn(conference_member_t *member, caller_control_action_t *action)
 {
 	char msg[512];
 	switch_event_t *event;
 
-	if (member == NULL) return;
+	if (member == NULL)
+		return;
 
 	switch_mutex_lock(member->flag_mutex);
 	member->volume_in_level--;
@@ -1455,11 +1471,10 @@
 	conference_member_say(member, msg, 0);
 }
 
-static void conference_loop_fn_event(conference_member_t * member, caller_control_action_t * action)
+static void conference_loop_fn_event(conference_member_t *member, caller_control_action_t *action)
 {
 	switch_event_t *event;
-	if (test_eflag(member->conference, EFLAG_DTMF) &&
-		switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+	if (test_eflag(member->conference, EFLAG_DTMF) && switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
 		conference_add_event_member_data(member, event);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "dtmf");
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "DTMF-Key", "%s", action->binded_dtmf);
@@ -1467,13 +1482,13 @@
 	}
 }
 
-static void conference_loop_fn_hangup(conference_member_t * member, caller_control_action_t * action)
+static void conference_loop_fn_hangup(conference_member_t *member, caller_control_action_t *action)
 {
 	switch_clear_flag_locked(member, MFLAG_RUNNING);
 }
 
 /* marshall frames from the call leg to the conference thread for muxing to other call legs */
-static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t * thread, void *obj)
+static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t *thread, void *obj)
 {
 	conference_member_t *member = obj;
 	switch_channel_t *channel;
@@ -1564,23 +1579,22 @@
 						switch_event_t *event;
 						switch_set_flag_locked(member, MFLAG_TALKING);
 						switch_mutex_lock(member->conference->member_mutex);
-						if (!member->conference->floor_holder || 
-							!switch_test_flag(member->conference->floor_holder, MFLAG_TALKING) || member->score > 
+						if (!member->conference->floor_holder ||
+							!switch_test_flag(member->conference->floor_holder, MFLAG_TALKING) || member->score >
 							member->conference->floor_holder->score + 200) {
 							if (test_eflag(member->conference, EFLAG_FLOOR_CHANGE) &&
 								switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
 								conference_add_event_member_data(member, event);
 								switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "floor-change");
-								switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Old-ID", "%d", 
+								switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Old-ID", "%d",
 														member->conference->floor_holder ? member->conference->floor_holder->id : 0);
-								switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-ID", "%d", 
-														member->conference->floor_holder ? member->id : 0);
+								switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-ID", "%d", member->conference->floor_holder ? member->id : 0);
 								switch_event_fire(&event);
 							}
 							member->conference->floor_holder = member;
 						}
 						switch_mutex_unlock(member->conference->member_mutex);
-						
+
 						if (test_eflag(member->conference, EFLAG_START_TALKING) &&
 							switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
 							conference_add_event_member_data(member, event);
@@ -1621,11 +1635,9 @@
 				int len = (int) read_frame->datalen;
 
 				read_resampler->from_len = switch_short_to_float(bptr, read_resampler->from, (int) len / 2);
-				read_resampler->to_len = switch_resample_process(read_resampler, 
+				read_resampler->to_len = switch_resample_process(read_resampler,
 																 read_resampler->from,
-																 read_resampler->from_len, 
-																 read_resampler->to, 
-																 read_resampler->to_size, 0);
+																 read_resampler->from_len, read_resampler->to, read_resampler->to_size, 0);
 
 				switch_float_to_short(read_resampler->to, member->resample_out, read_resampler->to_len);
 				len = read_resampler->to_len * 2;
@@ -1655,12 +1667,13 @@
 }
 
 /* launch an input thread for the call leg */
-static void launch_conference_loop_input(conference_member_t * member, switch_memory_pool_t *pool)
+static void launch_conference_loop_input(conference_member_t *member, switch_memory_pool_t *pool)
 {
 	switch_thread_t *thread;
 	switch_threadattr_t *thd_attr = NULL;
 
-	if (member == NULL) return;
+	if (member == NULL)
+		return;
 
 	switch_threadattr_create(&thd_attr, pool);
 	switch_threadattr_detach_set(thd_attr, 1);
@@ -1689,7 +1702,7 @@
 
 /* marshall frames from the conference (or file or tts output) to the call leg */
 /* NB. this starts the input thread after some initial setup for the call leg */
-static void conference_loop_output(conference_member_t * member)
+static void conference_loop_output(conference_member_t *member)
 {
 	switch_channel_t *channel = switch_core_session_get_channel(member->session);
 	switch_frame_t write_frame = { 0 };
@@ -1698,12 +1711,12 @@
 	switch_codec_t *read_codec = switch_core_session_get_read_codec(member->session);
 	uint32_t interval = read_codec->implementation->microseconds_per_frame / 1000;
 	uint32_t samples = switch_samples_per_frame(member->conference->rate, interval);
-    uint32_t csamples = samples;
+	uint32_t csamples = samples;
 	uint32_t tsamples = member->orig_read_codec->implementation->samples_per_frame;
 	uint32_t flush_len = 0;
 	uint32_t low_count = 0, bytes = samples * 2;
 	call_list_t *call_list = NULL, *cp = NULL;
-    
+
 	switch_assert(member->conference != NULL);
 
 	flush_len = switch_samples_per_frame(member->conference->rate, member->conference->interval) * 10;
@@ -1770,8 +1783,8 @@
 		int use_timer = 0;
 		switch_size_t file_sample_len = csamples;
 		switch_size_t file_data_len = file_sample_len * 2;
-			
-			
+
+
 		switch_mutex_lock(member->flag_mutex);
 
 
@@ -1894,7 +1907,7 @@
 						switch_core_session_write_frame(member->session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
 						switch_core_timer_next(&timer);
 
-                            
+
 						/* forget the conference data we played file node data instead */
 						switch_set_flag_locked(member, MFLAG_FLUSH_BUFFER);
 					}
@@ -1914,9 +1927,9 @@
 					/* getting behind, clear the buffer */
 					switch_set_flag_locked(member, MFLAG_FLUSH_BUFFER);
 				}
-			} 
-				
-				
+			}
+
+
 			use_timer = 1;
 
 			if (mux_used) {
@@ -1962,7 +1975,7 @@
 			}
 			switch_clear_flag_locked(member, MFLAG_FLUSH_BUFFER);
 		}
-			
+
 		switch_mutex_unlock(member->flag_mutex);
 
 		if (use_timer) {
@@ -1971,7 +1984,7 @@
 			switch_yield(1000);
 		}
 
-	} /* Rinse ... Repeat */
+	}							/* Rinse ... Repeat */
 
 	if (member->digit_stream != NULL) {
 		switch_ivr_digit_stream_destroy(member->digit_stream);
@@ -1995,7 +2008,7 @@
 }
 
 /* Sub-Routine called by a record entity inside a conference */
-static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t * thread, void *obj)
+static void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *thread, void *obj)
 {
 	uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
 	switch_file_handle_t fh = { 0 };
@@ -2029,9 +2042,9 @@
 	member->id = next_member_id();
 	member->pool = rec->pool;
 
-    member->frame_size = SWITCH_RECOMMENDED_BUFFER_SIZE;
-    member->frame = switch_core_alloc(member->pool, member->frame_size);
-    member->mux_frame = switch_core_alloc(member->pool, member->frame_size);
+	member->frame_size = SWITCH_RECOMMENDED_BUFFER_SIZE;
+	member->frame = switch_core_alloc(member->pool, member->frame_size);
+	member->mux_frame = switch_core_alloc(member->pool, member->frame_size);
 
 
 	switch_mutex_init(&member->flag_mutex, SWITCH_MUTEX_NESTED, rec->pool);
@@ -2080,7 +2093,7 @@
 	while (switch_test_flag(member, MFLAG_RUNNING) && switch_test_flag(conference, CFLAG_RUNNING) && conference->count) {
 		switch_size_t len;
 		mux_used = (uint32_t) switch_buffer_inuse(member->mux_buffer);
-		
+
 		if (switch_test_flag(member, MFLAG_FLUSH_BUFFER)) {
 			if (mux_used) {
 				switch_mutex_lock(member->audio_out_mutex);
@@ -2095,7 +2108,7 @@
 			/* Flush the output buffer and write all the data (presumably muxed) to the file */
 			switch_mutex_lock(member->audio_out_mutex);
 			low_count = 0;
-			
+
 			if ((rlen = (uint32_t) switch_buffer_read(member->mux_buffer, data, sizeof(data)))) {
 				if (!switch_test_flag((&fh), SWITCH_FILE_PAUSE)) {
 					len = (switch_size_t) rlen / sizeof(int16_t);
@@ -2117,9 +2130,9 @@
 		}
 
 		switch_core_timer_next(&timer);
-	} /* Rinse ... Repeat */
+	}							/* Rinse ... Repeat */
 
- end:
+  end:
 
 	switch_core_timer_destroy(&timer);
 	conference_del_member(conference, member);
@@ -2146,7 +2159,7 @@
 }
 
 /* Make files stop playing in a conference either the current one or all of them */
-static uint32_t conference_stop_file(conference_obj_t * conference, file_stop_t stop)
+static uint32_t conference_stop_file(conference_obj_t *conference, file_stop_t stop)
 {
 	uint32_t count = 0;
 	conference_file_node_t *nptr;
@@ -2182,12 +2195,13 @@
 }
 
 /* stop playing a file for the member of the conference */
-static uint32_t conference_member_stop_file(conference_member_t * member, file_stop_t stop)
+static uint32_t conference_member_stop_file(conference_member_t *member, file_stop_t stop)
 {
 	conference_file_node_t *nptr;
 	uint32_t count = 0;
 
-	if (member == NULL) return count;
+	if (member == NULL)
+		return count;
 
 	switch_mutex_lock(member->flag_mutex);
 
@@ -2209,7 +2223,7 @@
 }
 
 /* Play a file in the conference room */
-static switch_status_t conference_play_file(conference_obj_t * conference, char *file, uint32_t leadin, switch_channel_t *channel, uint8_t async)
+static switch_status_t conference_play_file(conference_obj_t *conference, char *file, uint32_t leadin, switch_channel_t *channel, uint8_t async)
 {
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
 	conference_file_node_t *fnode, *nptr = NULL;
@@ -2225,7 +2239,8 @@
 	switch_mutex_unlock(conference->member_mutex);
 	switch_mutex_unlock(conference->mutex);
 
-	if (!count) return SWITCH_STATUS_FALSE;
+	if (!count)
+		return SWITCH_STATUS_FALSE;
 
 	if (channel) {
 		if ((expanded = switch_channel_expand_variables(channel, file)) != file) {
@@ -2310,7 +2325,7 @@
 
 	switch_mutex_unlock(conference->mutex);
 
- done:
+  done:
 
 	switch_safe_free(expanded);
 	switch_safe_free(dfile);
@@ -2319,14 +2334,15 @@
 }
 
 /* Play a file in the conference room to a member */
-static switch_status_t conference_member_play_file(conference_member_t * member, char *file, uint32_t leadin)
+static switch_status_t conference_member_play_file(conference_member_t *member, char *file, uint32_t leadin)
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	char *dfile = NULL, *expanded = NULL;
 	conference_file_node_t *fnode, *nptr = NULL;
 	switch_memory_pool_t *pool;
 
-	if (member == NULL || file == NULL) return status;
+	if (member == NULL || file == NULL)
+		return status;
 
 	if ((expanded = switch_channel_expand_variables(switch_core_session_get_channel(member->session), file)) != file) {
 		file = expanded;
@@ -2384,7 +2400,7 @@
 	switch_mutex_unlock(member->flag_mutex);
 	status = SWITCH_STATUS_SUCCESS;
 
- done:
+  done:
 
 	switch_safe_free(expanded);
 	switch_safe_free(dfile);
@@ -2393,7 +2409,7 @@
 }
 
 /* Say some thing with TTS in the conference room */
-static switch_status_t conference_member_say(conference_member_t * member, char *text, uint32_t leadin)
+static switch_status_t conference_member_say(conference_member_t *member, char *text, uint32_t leadin)
 {
 	conference_obj_t *conference = (member != NULL ? member->conference : NULL);
 	conference_file_node_t *fnode, *nptr;
@@ -2401,7 +2417,8 @@
 	switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
 	switch_status_t status = SWITCH_STATUS_FALSE;
 
-	if (member == NULL || switch_strlen_zero(text)) return SWITCH_STATUS_FALSE;
+	if (member == NULL || switch_strlen_zero(text))
+		return SWITCH_STATUS_FALSE;
 
 	switch_assert(conference != NULL);
 
@@ -2428,7 +2445,7 @@
 
 	if (!member->sh) {
 		memset(&member->lsh, 0, sizeof(member->lsh));
-		if (switch_core_speech_open(&member->lsh, conference->tts_engine, conference->tts_voice, 
+		if (switch_core_speech_open(&member->lsh, conference->tts_engine, conference->tts_voice,
 									conference->rate, conference->interval, &flags, switch_core_session_get_pool(member->session)) !=
 			SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid TTS module [%s]!\n", conference->tts_engine);
@@ -2452,7 +2469,7 @@
 	switch_sleep(200000);
 
 	if (*text == '#') {
-		char *tmp = (char *)text + 1;
+		char *tmp = (char *) text + 1;
 		char *vp = tmp, voice[128] = "";
 		if ((tmp = strchr(tmp, '#'))) {
 			text = tmp + 1;
@@ -2472,7 +2489,7 @@
 }
 
 /* Say some thing with TTS in the conference room */
-static switch_status_t conference_say(conference_obj_t * conference, const char *text, uint32_t leadin)
+static switch_status_t conference_say(conference_obj_t *conference, const char *text, uint32_t leadin)
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	conference_file_node_t *fnode, *nptr;
@@ -2514,12 +2531,11 @@
 
 	fnode->type = NODE_TYPE_SPEECH;
 	fnode->leadin = leadin;
-	
+
 	if (!conference->sh) {
 		memset(&conference->lsh, 0, sizeof(conference->lsh));
-		if (switch_core_speech_open(&conference->lsh, conference->tts_engine, conference->tts_voice, 
-									conference->rate, conference->interval, &flags, conference->pool) !=
-			SWITCH_STATUS_SUCCESS) {
+		if (switch_core_speech_open(&conference->lsh, conference->tts_engine, conference->tts_voice,
+									conference->rate, conference->interval, &flags, conference->pool) != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid TTS module [%s]!\n", conference->tts_engine);
 			return SWITCH_STATUS_FALSE;
 		}
@@ -2540,7 +2556,7 @@
 
 	fnode->sh = conference->sh;
 	if (*text == '#') {
-		char *tmp = (char *)text + 1;
+		char *tmp = (char *) text + 1;
 		char *vp = tmp, voice[128] = "";
 		if ((tmp = strchr(tmp, '#'))) {
 			text = tmp + 1;
@@ -2562,7 +2578,7 @@
 }
 
 /* execute a callback for every member of the conference */
-static void conference_member_itterator(conference_obj_t * conference, switch_stream_handle_t *stream, conf_api_member_cmd_t pfncallback, void *data)
+static void conference_member_itterator(conference_obj_t *conference, switch_stream_handle_t *stream, conf_api_member_cmd_t pfncallback, void *data)
 {
 	conference_member_t *member = NULL;
 
@@ -2578,7 +2594,7 @@
 
 }
 
-static void conference_list_pretty(conference_obj_t * conference, switch_stream_handle_t *stream)
+static void conference_list_pretty(conference_obj_t *conference, switch_stream_handle_t *stream)
 {
 	conference_member_t *member = NULL;
 
@@ -2603,7 +2619,7 @@
 	switch_mutex_unlock(conference->member_mutex);
 }
 
-static void conference_list(conference_obj_t * conference, switch_stream_handle_t *stream, char *delim)
+static void conference_list(conference_obj_t *conference, switch_stream_handle_t *stream, char *delim)
 {
 	conference_member_t *member = NULL;
 
@@ -2663,11 +2679,12 @@
 	switch_mutex_unlock(conference->member_mutex);
 }
 
-static switch_status_t conf_api_sub_mute(conference_member_t * member, switch_stream_handle_t *stream, void *data)
+static switch_status_t conf_api_sub_mute(conference_member_t *member, switch_stream_handle_t *stream, void *data)
 {
 	switch_event_t *event;
 
-	if (member == NULL)  return SWITCH_STATUS_GENERR;
+	if (member == NULL)
+		return SWITCH_STATUS_GENERR;
 
 	switch_clear_flag_locked(member, MFLAG_CAN_SPEAK);
 	if (member->conference->muted_sound) {
@@ -2691,11 +2708,12 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t conf_api_sub_unmute(conference_member_t * member, switch_stream_handle_t *stream, void *data)
+static switch_status_t conf_api_sub_unmute(conference_member_t *member, switch_stream_handle_t *stream, void *data)
 {
 	switch_event_t *event;
 
-	if (member == NULL) return SWITCH_STATUS_GENERR;
+	if (member == NULL)
+		return SWITCH_STATUS_GENERR;
 
 	switch_set_flag_locked(member, MFLAG_CAN_SPEAK);
 	if (stream != NULL) {
@@ -2719,11 +2737,12 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t conf_api_sub_deaf(conference_member_t * member, switch_stream_handle_t *stream, void *data)
+static switch_status_t conf_api_sub_deaf(conference_member_t *member, switch_stream_handle_t *stream, void *data)
 {
 	switch_event_t *event;
 
-	if (member == NULL) return SWITCH_STATUS_GENERR;
+	if (member == NULL)
+		return SWITCH_STATUS_GENERR;
 
 	switch_clear_flag_locked(member, MFLAG_CAN_HEAR);
 	if (stream != NULL) {
@@ -2738,11 +2757,12 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t conf_api_sub_undeaf(conference_member_t * member, switch_stream_handle_t *stream, void *data)
+static switch_status_t conf_api_sub_undeaf(conference_member_t *member, switch_stream_handle_t *stream, void *data)
 {
 	switch_event_t *event;
-	
-	if (member == NULL) return SWITCH_STATUS_GENERR;
+
+	if (member == NULL)
+		return SWITCH_STATUS_GENERR;
 
 	switch_set_flag_locked(member, MFLAG_CAN_HEAR);
 	if (stream != NULL) {
@@ -2757,11 +2777,12 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t conf_api_sub_kick(conference_member_t * member, switch_stream_handle_t *stream, void *data)
+static switch_status_t conf_api_sub_kick(conference_member_t *member, switch_stream_handle_t *stream, void *data)
 {
 	switch_event_t *event;
 
-	if (member == NULL) return SWITCH_STATUS_GENERR;
+	if (member == NULL)
+		return SWITCH_STATUS_GENERR;
 
 	switch_mutex_lock(member->flag_mutex);
 	switch_clear_flag(member, MFLAG_RUNNING);
@@ -2781,11 +2802,11 @@
 }
 
 
-static switch_status_t conf_api_sub_dtmf(conference_member_t * member, switch_stream_handle_t *stream, void *data)
+static switch_status_t conf_api_sub_dtmf(conference_member_t *member, switch_stream_handle_t *stream, void *data)
 {
 	switch_event_t *event;
 	char *dtmf = (char *) data;
-	
+
 	if (member == NULL) {
 		stream->write_function(stream, "Invalid member!\n");
 		return SWITCH_STATUS_GENERR;
@@ -2798,7 +2819,7 @@
 
 	switch_mutex_lock(member->flag_mutex);
 	switch_core_session_kill_channel(member->session, SWITCH_SIG_BREAK);
-	switch_core_session_send_dtmf_string(member->session, (char *)data);
+	switch_core_session_send_dtmf_string(member->session, (char *) data);
 	switch_mutex_unlock(member->flag_mutex);
 
 	if (stream != NULL) {
@@ -2816,11 +2837,12 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t conf_api_sub_energy(conference_member_t * member, switch_stream_handle_t *stream, void *data)
+static switch_status_t conf_api_sub_energy(conference_member_t *member, switch_stream_handle_t *stream, void *data)
 {
 	switch_event_t *event;
 
-	if (member == NULL) return SWITCH_STATUS_GENERR;
+	if (member == NULL)
+		return SWITCH_STATUS_GENERR;
 
 	if (data) {
 		switch_mutex_lock(member->flag_mutex);
@@ -2831,21 +2853,22 @@
 		stream->write_function(stream, "Energy %u = %d\n", member->id, member->energy_level);
 	}
 	if (test_eflag(member->conference, EFLAG_ENERGY_LEVEL_MEMBER) &&
-		data && switch_event_create_subclass(& event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+		data && switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
 		conference_add_event_member_data(member, event);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "energy-level-member");
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Energy-Level", "%d", member->energy_level);
-		switch_event_fire(& event);
+		switch_event_fire(&event);
 	}
 
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t conf_api_sub_volume_in(conference_member_t * member, switch_stream_handle_t *stream, void *data)
+static switch_status_t conf_api_sub_volume_in(conference_member_t *member, switch_stream_handle_t *stream, void *data)
 {
 	switch_event_t *event;
 
-	if (member == NULL) return SWITCH_STATUS_GENERR;
+	if (member == NULL)
+		return SWITCH_STATUS_GENERR;
 
 	if (data) {
 		switch_mutex_lock(member->flag_mutex);
@@ -2857,21 +2880,22 @@
 		stream->write_function(stream, "Volume IN %u = %d\n", member->id, member->volume_in_level);
 	}
 	if (test_eflag(member->conference, EFLAG_VOLUME_IN_MEMBER) &&
-		data && switch_event_create_subclass(& event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+		data && switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
 		conference_add_event_member_data(member, event);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "volume-in-member");
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Volume-Level", "%u", member->volume_in_level);
-		switch_event_fire(& event);
+		switch_event_fire(&event);
 	}
 
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t conf_api_sub_volume_out(conference_member_t * member, switch_stream_handle_t *stream, void *data)
+static switch_status_t conf_api_sub_volume_out(conference_member_t *member, switch_stream_handle_t *stream, void *data)
 {
 	switch_event_t *event;
 
-	if (member == NULL) return SWITCH_STATUS_GENERR;
+	if (member == NULL)
+		return SWITCH_STATUS_GENERR;
 
 	if (data) {
 		switch_mutex_lock(member->flag_mutex);
@@ -2883,17 +2907,17 @@
 		stream->write_function(stream, "Volume OUT %u = %d\n", member->id, member->volume_out_level);
 	}
 	if (test_eflag(member->conference, EFLAG_VOLUME_OUT_MEMBER) && data &&
-		switch_event_create_subclass(& event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+		switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
 		conference_add_event_member_data(member, event);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "volume-out-member");
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Volume-Level", "%u", member->volume_out_level);
-		switch_event_fire(& event);
+		switch_event_fire(&event);
 	}
 
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t conf_api_sub_list(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
+static switch_status_t conf_api_sub_list(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char **argv)
 {
 	int ret_status = SWITCH_STATUS_GENERR;
 	int count = 0;
@@ -2955,7 +2979,7 @@
 	return ret_status;
 }
 
-static switch_status_t conf_api_sub_play(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
+static switch_status_t conf_api_sub_play(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char **argv)
 {
 	int ret_status = SWITCH_STATUS_GENERR;
 	switch_event_t *event;
@@ -3009,7 +3033,7 @@
 	return ret_status;
 }
 
-static switch_status_t conf_api_sub_say(conference_obj_t * conference, switch_stream_handle_t *stream, const char *text)
+static switch_status_t conf_api_sub_say(conference_obj_t *conference, switch_stream_handle_t *stream, const char *text)
 {
 	switch_event_t *event;
 
@@ -3024,8 +3048,7 @@
 	}
 
 	stream->write_function(stream, "(say) OK\n");
-	if (test_eflag(conference, EFLAG_SPEAK_TEXT) &&
-		switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+	if (test_eflag(conference, EFLAG_SPEAK_TEXT) && switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
 		conference_add_event_data(conference, event);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "speak-text");
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Text", "%s", text);
@@ -3034,7 +3057,7 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t conf_api_sub_saymember(conference_obj_t * conference, switch_stream_handle_t *stream, const char *text)
+static switch_status_t conf_api_sub_saymember(conference_obj_t *conference, switch_stream_handle_t *stream, const char *text)
 {
 	int ret_status = SWITCH_STATUS_GENERR;
 	char *expanded = NULL;
@@ -3077,10 +3100,10 @@
 		expanded = NULL;
 	}
 
-	if (!text || conference_member_say(member, (char*)text, 0) != SWITCH_STATUS_SUCCESS) {
+	if (!text || conference_member_say(member, (char *) text, 0) != SWITCH_STATUS_SUCCESS) {
 		stream->write_function(stream, "(saymember) Error!");
 		goto done;
-	} 
+	}
 
 	stream->write_function(stream, "(saymember) OK\n");
 	if (test_eflag(member->conference, EFLAG_SPEAK_TEXT_MEMBER) &&
@@ -3092,13 +3115,13 @@
 	}
 	ret_status = SWITCH_STATUS_SUCCESS;
 
- done:
+  done:
 	switch_safe_free(workspace);
 	switch_safe_free(expanded);
 	return ret_status;
 }
 
-static switch_status_t conf_api_sub_stop(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
+static switch_status_t conf_api_sub_stop(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char **argv)
 {
 	uint8_t current = 0, all = 0;
 
@@ -3112,7 +3135,8 @@
 		all = 1;
 	}
 
-	if (!(current || all)) return SWITCH_STATUS_GENERR;
+	if (!(current || all))
+		return SWITCH_STATUS_GENERR;
 
 	if (argc == 4) {
 		uint32_t id = atoi(argv[3]);
@@ -3131,14 +3155,15 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t conf_api_sub_relate(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
+static switch_status_t conf_api_sub_relate(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char **argv)
 {
 	uint8_t nospeak = 0, nohear = 0, clear = 0;
 
 	switch_assert(conference != NULL);
 	switch_assert(stream != NULL);
 
-	if (argc <= 4) return SWITCH_STATUS_GENERR;
+	if (argc <= 4)
+		return SWITCH_STATUS_GENERR;
 
 	nospeak = strstr(argv[4], "nospeak") ? 1 : 0;
 	nohear = strstr(argv[4], "nohear") ? 1 : 0;
@@ -3150,7 +3175,7 @@
 	if (!(clear || nospeak || nohear)) {
 		return SWITCH_STATUS_GENERR;
 	}
-	
+
 	if (clear) {
 		conference_member_t *member = NULL;
 		uint32_t id = atoi(argv[2]);
@@ -3163,8 +3188,8 @@
 			stream->write_function(stream, "relationship %u->%u not found", id, oid);
 		}
 		return SWITCH_STATUS_SUCCESS;
-	} 
-	
+	}
+
 	if (nospeak || nohear) {
 		conference_member_t *member = NULL, *other_member = NULL;
 		uint32_t id = atoi(argv[2]);
@@ -3199,7 +3224,7 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t conf_api_sub_lock(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
+static switch_status_t conf_api_sub_lock(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char **argv)
 {
 	switch_event_t *event;
 
@@ -3212,8 +3237,7 @@
 
 	switch_set_flag_locked(conference, CFLAG_LOCKED);
 	stream->write_function(stream, "OK %s locked\n", argv[0]);
-	if (test_eflag(conference, EFLAG_LOCK) &&
-		switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+	if (test_eflag(conference, EFLAG_LOCK) && switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
 		conference_add_event_data(conference, event);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "lock");
 		switch_event_fire(&event);
@@ -3222,7 +3246,7 @@
 	return 0;
 }
 
-static switch_status_t conf_api_sub_unlock(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
+static switch_status_t conf_api_sub_unlock(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char **argv)
 {
 	switch_event_t *event;
 
@@ -3235,8 +3259,7 @@
 
 	switch_clear_flag_locked(conference, CFLAG_LOCKED);
 	stream->write_function(stream, "OK %s unlocked\n", argv[0]);
-	if (test_eflag(conference, EFLAG_UNLOCK) &&
-		switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
+	if (test_eflag(conference, EFLAG_UNLOCK) && switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
 		conference_add_event_data(conference, event);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "unlock");
 		switch_event_fire(&event);
@@ -3245,7 +3268,7 @@
 	return 0;
 }
 
-static switch_status_t conf_api_sub_dial(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
+static switch_status_t conf_api_sub_dial(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char **argv)
 {
 	switch_call_cause_t cause;
 
@@ -3267,7 +3290,7 @@
 }
 
 
-static switch_status_t conf_api_sub_bgdial(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
+static switch_status_t conf_api_sub_bgdial(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char **argv)
 {
 	switch_assert(stream != NULL);
 
@@ -3285,7 +3308,7 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t conf_api_sub_transfer(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
+static switch_status_t conf_api_sub_transfer(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char **argv)
 {
 	switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
 	char *conf_name = NULL, *profile_name;
@@ -3303,7 +3326,7 @@
 		} else {
 			profile_name = "default";
 		}
-		
+
 		for (x = 3; x < argc; x++) {
 			conference_member_t *member = NULL;
 			uint32_t id = atoi(argv[x]);
@@ -3393,7 +3416,7 @@
 			switch_mutex_unlock(new_conference->mutex);
 			switch_mutex_unlock(member->flag_mutex);
 			stream->write_function(stream, "OK Members sent to conference %s.\n", argv[2]);
-			
+
 			/* tell them what happened */
 			if (test_eflag(conference, EFLAG_TRANSFER) &&
 				switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
@@ -3408,7 +3431,7 @@
 		ret_status = SWITCH_STATUS_GENERR;
 	}
 
- done:
+  done:
 	if (params) {
 		switch_event_destroy(&params);
 	}
@@ -3416,26 +3439,28 @@
 	return ret_status;
 }
 
-static switch_status_t conf_api_sub_record(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
+static switch_status_t conf_api_sub_record(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char **argv)
 {
 	switch_assert(conference != NULL);
 	switch_assert(stream != NULL);
 
-	if (argc <= 2) return SWITCH_STATUS_GENERR;
+	if (argc <= 2)
+		return SWITCH_STATUS_GENERR;
 
 	stream->write_function(stream, "Record file %s\n", argv[2]);
 	launch_conference_record_thread(conference, argv[2]);
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t conf_api_sub_norecord(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
+static switch_status_t conf_api_sub_norecord(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char **argv)
 {
 	int all;
 
 	switch_assert(conference != NULL);
 	switch_assert(stream != NULL);
 
-	if (argc <= 2) return SWITCH_STATUS_GENERR;
+	if (argc <= 2)
+		return SWITCH_STATUS_GENERR;
 
 	all = (strcasecmp(argv[2], "all") == 0);
 	stream->write_function(stream, "Stop recording file %s\n", argv[2]);
@@ -3446,7 +3471,7 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t conf_api_sub_pin(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
+static switch_status_t conf_api_sub_pin(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char **argv)
 {
 	switch_assert(conference != NULL);
 	switch_assert(stream != NULL);
@@ -3493,47 +3518,47 @@
 /* API Interface Function sub-commands */
 /* Entries in this list should be kept in sync with the enum above */
 static api_command_t conf_api_sub_commands[] = {
-	{"list", (void_fn_t) & conf_api_sub_list, CONF_API_SUB_ARGS_SPLIT, "<confname> list [delim <string>]"},
-	{"energy", (void_fn_t) & conf_api_sub_energy, CONF_API_SUB_MEMBER_TARGET,
+	{"list", (void_fn_t) &conf_api_sub_list, CONF_API_SUB_ARGS_SPLIT, "<confname> list [delim <string>]"},
+	{"energy", (void_fn_t) &conf_api_sub_energy, CONF_API_SUB_MEMBER_TARGET,
 	 "<confname> energy <member_id|all|last> [<newval>]"},
-	{"volume_in", (void_fn_t) & conf_api_sub_volume_in, CONF_API_SUB_MEMBER_TARGET,
+	{"volume_in", (void_fn_t) &conf_api_sub_volume_in, CONF_API_SUB_MEMBER_TARGET,
 	 "<confname> volume_in <member_id|all|last> [<newval>]"},
-	{"volume_out", (void_fn_t) & conf_api_sub_volume_out, CONF_API_SUB_MEMBER_TARGET,
+	{"volume_out", (void_fn_t) &conf_api_sub_volume_out, CONF_API_SUB_MEMBER_TARGET,
 	 "<confname> volume_out <member_id|all|last> [<newval>]"},
-	{"play", (void_fn_t) & conf_api_sub_play, CONF_API_SUB_ARGS_SPLIT, "<confname> play <file_path> [<member_id>]"},
-	{"say", (void_fn_t) & conf_api_sub_say, CONF_API_SUB_ARGS_AS_ONE, "<confname> say <text>"},
-	{"saymember", (void_fn_t) & conf_api_sub_saymember, CONF_API_SUB_ARGS_AS_ONE,
+	{"play", (void_fn_t) &conf_api_sub_play, CONF_API_SUB_ARGS_SPLIT, "<confname> play <file_path> [<member_id>]"},
+	{"say", (void_fn_t) &conf_api_sub_say, CONF_API_SUB_ARGS_AS_ONE, "<confname> say <text>"},
+	{"saymember", (void_fn_t) &conf_api_sub_saymember, CONF_API_SUB_ARGS_AS_ONE,
 	 "<confname> saymember <member_id> <text>"},
-	{"stop", (void_fn_t) & conf_api_sub_stop, CONF_API_SUB_ARGS_SPLIT,
+	{"stop", (void_fn_t) &conf_api_sub_stop, CONF_API_SUB_ARGS_SPLIT,
 	 "<confname> stop <[current|all|last]> [<member_id>]"},
-	{"dtmf", (void_fn_t) & conf_api_sub_dtmf, CONF_API_SUB_MEMBER_TARGET,
+	{"dtmf", (void_fn_t) &conf_api_sub_dtmf, CONF_API_SUB_MEMBER_TARGET,
 	 "<confname> dtmf <[member_id|all|last]> <digits>"},
-	{"kick", (void_fn_t) & conf_api_sub_kick, CONF_API_SUB_MEMBER_TARGET, "<confname> kick <[member_id|all|last]>"},
-	{"mute", (void_fn_t) & conf_api_sub_mute, CONF_API_SUB_MEMBER_TARGET, "<confname> mute <[member_id|all]|last>"},
-	{"unmute", (void_fn_t) & conf_api_sub_unmute, CONF_API_SUB_MEMBER_TARGET,
+	{"kick", (void_fn_t) &conf_api_sub_kick, CONF_API_SUB_MEMBER_TARGET, "<confname> kick <[member_id|all|last]>"},
+	{"mute", (void_fn_t) &conf_api_sub_mute, CONF_API_SUB_MEMBER_TARGET, "<confname> mute <[member_id|all]|last>"},
+	{"unmute", (void_fn_t) &conf_api_sub_unmute, CONF_API_SUB_MEMBER_TARGET,
 	 "<confname> unmute <[member_id|all]|last>"},
-	{"deaf", (void_fn_t) & conf_api_sub_deaf, CONF_API_SUB_MEMBER_TARGET, "<confname> deaf <[member_id|all]|last>"},
-	{"undeaf", (void_fn_t) & conf_api_sub_undeaf, CONF_API_SUB_MEMBER_TARGET,
+	{"deaf", (void_fn_t) &conf_api_sub_deaf, CONF_API_SUB_MEMBER_TARGET, "<confname> deaf <[member_id|all]|last>"},
+	{"undeaf", (void_fn_t) &conf_api_sub_undeaf, CONF_API_SUB_MEMBER_TARGET,
 	 "<confname> undeaf <[member_id|all]|last>"},
-	{"relate", (void_fn_t) & conf_api_sub_relate, CONF_API_SUB_ARGS_SPLIT,
+	{"relate", (void_fn_t) &conf_api_sub_relate, CONF_API_SUB_ARGS_SPLIT,
 	 "<confname> relate <member_id> <other_member_id> [nospeak|nohear|clear]"},
-	{"lock", (void_fn_t) & conf_api_sub_lock, CONF_API_SUB_ARGS_SPLIT, "<confname> lock"},
-	{"unlock", (void_fn_t) & conf_api_sub_unlock, CONF_API_SUB_ARGS_SPLIT, "<confname> unlock"},
-	{"dial", (void_fn_t) & conf_api_sub_dial, CONF_API_SUB_ARGS_SPLIT,
+	{"lock", (void_fn_t) &conf_api_sub_lock, CONF_API_SUB_ARGS_SPLIT, "<confname> lock"},
+	{"unlock", (void_fn_t) &conf_api_sub_unlock, CONF_API_SUB_ARGS_SPLIT, "<confname> unlock"},
+	{"dial", (void_fn_t) &conf_api_sub_dial, CONF_API_SUB_ARGS_SPLIT,
 	 "<confname> dial <endpoint_module_name>/<destination> <callerid number> <callerid name>"},
-	{"bgdial", (void_fn_t) & conf_api_sub_bgdial, CONF_API_SUB_ARGS_SPLIT,
+	{"bgdial", (void_fn_t) &conf_api_sub_bgdial, CONF_API_SUB_ARGS_SPLIT,
 	 "<confname> bgdial <endpoint_module_name>/<destination> <callerid number> <callerid name>"},
-	{"transfer", (void_fn_t) & conf_api_sub_transfer, CONF_API_SUB_ARGS_SPLIT,
+	{"transfer", (void_fn_t) &conf_api_sub_transfer, CONF_API_SUB_ARGS_SPLIT,
 	 "<confname> transfer <conference_name> <member id> [...<member id>]"},
-	{"record", (void_fn_t) & conf_api_sub_record, CONF_API_SUB_ARGS_SPLIT, "<confname> record <filename>"},
-	{"norecord", (void_fn_t) & conf_api_sub_norecord, CONF_API_SUB_ARGS_SPLIT, "<confname> norecord <[filename|all]>"},
-	{"pin", (void_fn_t) & conf_api_sub_pin, CONF_API_SUB_ARGS_SPLIT, "<confname> pin <pin#>"},
-	{"nopin", (void_fn_t) & conf_api_sub_pin, CONF_API_SUB_ARGS_SPLIT, "<confname> nopin"},
+	{"record", (void_fn_t) &conf_api_sub_record, CONF_API_SUB_ARGS_SPLIT, "<confname> record <filename>"},
+	{"norecord", (void_fn_t) &conf_api_sub_norecord, CONF_API_SUB_ARGS_SPLIT, "<confname> norecord <[filename|all]>"},
+	{"pin", (void_fn_t) &conf_api_sub_pin, CONF_API_SUB_ARGS_SPLIT, "<confname> pin <pin#>"},
+	{"nopin", (void_fn_t) &conf_api_sub_pin, CONF_API_SUB_ARGS_SPLIT, "<confname> nopin"},
 };
 
 #define CONFFUNCAPISIZE (sizeof(conf_api_sub_commands)/sizeof(conf_api_sub_commands[0]))
 
-switch_status_t conf_api_dispatch(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv, const char *cmdline, int argn)
+switch_status_t conf_api_dispatch(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char **argv, const char *cmdline, int argn)
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	uint32_t i, found = 0;
@@ -3719,7 +3744,7 @@
 		stream->write_function(stream, "No parameters specified.\nTry 'help conference'\n");
 	}
 
- done:
+  done:
 	switch_safe_free(lbuf);
 
 	return status;
@@ -3727,7 +3752,7 @@
 }
 
 /* generate an outbound call from the conference */
-static switch_status_t conference_outcall(conference_obj_t * conference,
+static switch_status_t conference_outcall(conference_obj_t *conference,
 										  char *conference_name,
 										  switch_core_session_t *session,
 										  char *bridgeto, uint32_t timeout, char *flags, char *cid_name, char *cid_num, switch_call_cause_t *cause)
@@ -3776,21 +3801,19 @@
 	}
 
 	/* establish an outbound call leg */
-		
-	if (switch_ivr_originate(session,
-							 &peer_session, cause, bridgeto, timeout, NULL,  cid_name, cid_num,
-							 NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS) {
+
+	if (switch_ivr_originate(session, &peer_session, cause, bridgeto, timeout, NULL, cid_name, cid_num, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot create outgoing channel, cause: %s\n", switch_channel_cause2str(*cause));
 		if (caller_channel) {
 			switch_channel_hangup(caller_channel, *cause);
 		}
 		goto done;
 	}
-	
+
 	rdlock = 1;
 	peer_channel = switch_core_session_get_channel(peer_session);
 	switch_channel_set_state(peer_channel, CS_SOFT_EXECUTE);
-	
+
 	/* make sure the conference still exists */
 	if (!switch_test_flag(conference, CFLAG_RUNNING)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Conference is gone now, nevermind..\n");
@@ -3805,7 +3828,7 @@
 		switch_channel_answer(caller_channel);
 	}
 
- callup:
+  callup:
 
 	/* if the outbound call leg is ready */
 	if (switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA)) {
@@ -3834,7 +3857,7 @@
 		goto done;
 	}
 
- done:
+  done:
 	if (conference) {
 		switch_thread_rwlock_unlock(conference->rwlock);
 	}
@@ -3856,7 +3879,7 @@
 	char *conference_name;
 };
 
-static void *SWITCH_THREAD_FUNC conference_outcall_run(switch_thread_t * thread, void *obj)
+static void *SWITCH_THREAD_FUNC conference_outcall_run(switch_thread_t *thread, void *obj)
 {
 	struct bg_call *call = (struct bg_call *) obj;
 
@@ -3864,7 +3887,7 @@
 		switch_call_cause_t cause;
 		switch_event_t *event;
 
-		conference_outcall(call->conference, call->conference_name, 
+		conference_outcall(call->conference, call->conference_name,
 						   call->session, call->bridgeto, call->timeout, call->flags, call->cid_name, call->cid_num, &cause);
 
 		if (test_eflag(call->conference, EFLAG_BGDIAL_RESULT) &&
@@ -3885,15 +3908,17 @@
 	return NULL;
 }
 
-static switch_status_t conference_outcall_bg(conference_obj_t * conference,
+static switch_status_t conference_outcall_bg(conference_obj_t *conference,
 											 char *conference_name,
-											 switch_core_session_t *session, char *bridgeto, uint32_t timeout, const char *flags, const char *cid_name, const char *cid_num)
+											 switch_core_session_t *session, char *bridgeto, uint32_t timeout, const char *flags, const char *cid_name,
+											 const char *cid_num)
 {
 	struct bg_call *call = NULL;
 	switch_thread_t *thread;
 	switch_threadattr_t *thd_attr = NULL;
 
-	if (!(call = malloc(sizeof(*call)))) return SWITCH_STATUS_MEMERR;
+	if (!(call = malloc(sizeof(*call))))
+		return SWITCH_STATUS_MEMERR;
 
 	memset(call, 0, sizeof(*call));
 	call->conference = conference;
@@ -3927,8 +3952,7 @@
 }
 
 /* Play a file */
-static switch_status_t conference_local_play_file(conference_obj_t * conference,
-												  switch_core_session_t *session, char *path, uint32_t leadin)
+static switch_status_t conference_local_play_file(conference_obj_t *conference, switch_core_session_t *session, char *path, uint32_t leadin)
 {
 	uint32_t x = 0;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
@@ -3948,7 +3972,7 @@
 	/* if all is well, really play the file */
 	if (status == SWITCH_STATUS_SUCCESS) {
 		char *dpath = NULL;
-	
+
 		channel = switch_core_session_get_channel(session);
 		if ((expanded = switch_channel_expand_variables(channel, path)) != path) {
 			path = expanded;
@@ -3977,13 +4001,13 @@
 		switch_safe_free(dpath);
 	}
 
- done:
+  done:
 	switch_safe_free(expanded);
-	
+
 	return status;
 }
 
-static void set_mflags(char *flags, member_flag_t * f)
+static void set_mflags(char *flags, member_flag_t *f)
 {
 	if (flags) {
 		if (strstr(flags, "mute")) {
@@ -3999,11 +4023,11 @@
 
 }
 
-static void clear_eflags(char *events, uint32_t * f)
+static void clear_eflags(char *events, uint32_t *f)
 {
 	char buf[512] = "";
-	char* next = NULL;
-	char* event = buf;
+	char *next = NULL;
+	char *event = buf;
 
 	if (events) {
 		switch_copy_string(buf, events, sizeof(buf));
@@ -4122,7 +4146,7 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Channel has no media!\n");
 		return;
 	}
-	
+
 
 	if (switch_strlen_zero(data)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Invalid arguments\n");
@@ -4176,7 +4200,7 @@
 	if (0) {
 		member.dtmf_parser = conference->dtmf_parser;
 	} else {
-		
+
 	}
 #endif
 
@@ -4245,7 +4269,7 @@
 		if (!(conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, conf_name))) {
 			/* couldn't find the conference, create one */
 			conference = conference_new(conf_name, xml_cfg, NULL);
-			
+
 			if (!conference) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
 				goto done;
@@ -4317,7 +4341,7 @@
 				goto done;
 			}
 		}
-		
+
 		if (conference->special_announce) {
 			conference_local_play_file(conference, session, conference->special_announce, CONF_DEFAULT_LEADIN);
 		}
@@ -4367,7 +4391,7 @@
 		if (!switch_channel_test_flag(channel, CF_OUTBOUND))
 			switch_set_flag(conference, CFLAG_ANSWERED);
 	}
-	
+
 	member.orig_read_codec = read_codec;
 	member.native_rate = read_codec->implementation->samples_per_second;
 	member.pool = switch_core_session_get_pool(session);
@@ -4375,9 +4399,7 @@
 	/* Setup a Signed Linear codec for reading audio. */
 	if (switch_core_codec_init(&member.read_codec,
 							   "L16",
-							   NULL,
-							   read_codec->implementation->actual_samples_per_second,
-							   read_codec->implementation->microseconds_per_frame / 1000,
+							   NULL, read_codec->implementation->actual_samples_per_second, read_codec->implementation->microseconds_per_frame / 1000,
 							   //conference->interval,
 							   1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, member.pool) == SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
@@ -4387,30 +4409,27 @@
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed L16@%uhz 1 channel %dms\n",
 						  read_codec->implementation->actual_samples_per_second, read_codec->implementation->microseconds_per_frame / 1000);
-                          
+
 		flags = 0;
 		goto done;
 	}
 
-    member.frame_size = SWITCH_RECOMMENDED_BUFFER_SIZE;
-    member.frame = switch_core_alloc(member.pool, member.frame_size);
-    member.mux_frame = switch_core_alloc(member.pool, member.frame_size);
-    
+	member.frame_size = SWITCH_RECOMMENDED_BUFFER_SIZE;
+	member.frame = switch_core_alloc(member.pool, member.frame_size);
+	member.mux_frame = switch_core_alloc(member.pool, member.frame_size);
+
 	if (read_codec->implementation->actual_samples_per_second != conference->rate) {
 		if (switch_resample_create(&member.read_resampler,
 								   read_codec->implementation->actual_samples_per_second,
-								   member.frame_size,
-								   conference->rate,
-                                   member.frame_size,
-								   member.pool) != SWITCH_STATUS_SUCCESS) {
+								   member.frame_size, conference->rate, member.frame_size, member.pool) != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
 			goto done;
 		}
 
 
-        member.resample_out = switch_core_alloc(member.pool, member.frame_size);
-        member.resample_out_len = member.frame_size;
-        
+		member.resample_out = switch_core_alloc(member.pool, member.frame_size);
+		member.resample_out_len = member.frame_size;
+
 		/* Setup an audio buffer for the resampled audio */
 		if (switch_buffer_create_dynamic(&member.resample_buffer, CONF_DBLOCK_SIZE, CONF_DBUFFER_SIZE, CONF_DBUFFER_MAX)
 			!= SWITCH_STATUS_SUCCESS) {
@@ -4478,7 +4497,7 @@
 	/* Run the confernece loop */
 	conference_loop_output(&member);
 	switch_channel_set_private(channel, "_conference_autocall_list_", NULL);
-	
+
 	/* Tell the channel we are no longer going to be in a bridge */
 	msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE;
 	switch_core_session_receive_message(session, &msg);
@@ -4490,11 +4509,11 @@
 	switch_core_session_set_read_codec(member.session, read_codec);
 
 	/* Clean Up.  codec_done(X): is for error situations after the codecs were setup and done: is for situations before */
- codec_done1:
+  codec_done1:
 	switch_core_codec_destroy(&member.read_codec);
- codec_done2:
+  codec_done2:
 	switch_core_codec_destroy(&member.write_codec);
- done:
+  done:
 	switch_event_destroy(&params);
 	switch_buffer_destroy(&member.resample_buffer);
 	switch_buffer_destroy(&member.audio_buffer);
@@ -4521,7 +4540,7 @@
 		char *dfile = NULL;
 
 		if (conference->sound_prefix) {
-			dfile = switch_mprintf("%s%s%s", conference->sound_prefix, SWITCH_PATH_SEPARATOR,  conference->kicked_sound);
+			dfile = switch_mprintf("%s%s%s", conference->sound_prefix, SWITCH_PATH_SEPARATOR, conference->kicked_sound);
 			switch_assert(dfile);
 			toplay = dfile;
 		} else {
@@ -4541,7 +4560,7 @@
 }
 
 /* Create a thread for the conference and launch it */
-static void launch_conference_thread(conference_obj_t * conference)
+static void launch_conference_thread(conference_obj_t *conference)
 {
 	switch_thread_t *thread;
 	switch_threadattr_t *thd_attr = NULL;
@@ -4569,7 +4588,7 @@
 	switch_thread_create(&thread, thd_attr, conference_video_thread_run, conference, conference->pool);
 }
 
-static void launch_conference_record_thread(conference_obj_t * conference, char *path)
+static void launch_conference_record_thread(conference_obj_t *conference, char *path)
 {
 	switch_thread_t *thread;
 	switch_threadattr_t *thd_attr = NULL;
@@ -4624,7 +4643,7 @@
 	} else {
 		switch_copy_string(name, to, sizeof(name));
 	}
-	
+
 
 	if (!(conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, name))) {
 		ci->chat_send(CONF_CHAT_PROTO, to, hint && strchr(hint, '/') ? hint : from, "", "Conference not active.", NULL);
@@ -4638,8 +4657,7 @@
 		if (switch_stristr("list", lbuf)) {
 			conference_list_pretty(conference, &stream);
 			/* provide help */
-		}
-		else {
+		} else {
 			return SWITCH_STATUS_SUCCESS;
 		}
 #if 0
@@ -4660,7 +4678,7 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t conf_default_controls(conference_obj_t * conference)
+static switch_status_t conf_default_controls(conference_obj_t *conference)
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	uint32_t i;
@@ -4688,7 +4706,7 @@
 	return status;
 }
 
-static switch_status_t conference_new_install_caller_controls_custom(conference_obj_t * conference, switch_xml_t xml_controls, switch_xml_t xml_menus)
+static switch_status_t conference_new_install_caller_controls_custom(conference_obj_t *conference, switch_xml_t xml_controls, switch_xml_t xml_menus)
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	switch_xml_t xml_kvp;
@@ -4778,7 +4796,7 @@
 	char *maxmember_sound = NULL;
 	uint32_t rate = 8000, interval = 20;
 	switch_status_t status;
-    int comfort_noise_level = 0;
+	int comfort_noise_level = 0;
 	char *suppress_events = NULL;
 
 	/* Validate the conference name */
@@ -4805,10 +4823,10 @@
 		}
 
 		if (!strcasecmp(var, "rate") && !switch_strlen_zero(val)) {
-            uint32_t tmp = atoi(val);
-            if (tmp == 8000 || tmp == 16000 || tmp == 32000) {
-                rate = tmp;
-            }
+			uint32_t tmp = atoi(val);
+			if (tmp == 8000 || tmp == 16000 || tmp == 32000) {
+				rate = tmp;
+			}
 		} else if (!strcasecmp(var, "domain") && !switch_strlen_zero(val)) {
 			domain = val;
 		} else if (!strcasecmp(var, "interval") && !switch_strlen_zero(val)) {
@@ -4817,7 +4835,7 @@
 				interval = tmp;
 			} else {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
-								  "Interval must be multipe of 10 and less than %d, Using default of 20\n", SWITCH_MAX_INTERVAL); 
+								  "Interval must be multipe of 10 and less than %d, Using default of 20\n", SWITCH_MAX_INTERVAL);
 			}
 		} else if (!strcasecmp(var, "timer-name") && !switch_strlen_zero(val)) {
 			timer_name = val;
@@ -4868,13 +4886,13 @@
 		} else if (!strcasecmp(var, "caller-controls") && !switch_strlen_zero(val)) {
 			caller_controls = val;
 		} else if (!strcasecmp(var, "comfort-noise") && !switch_strlen_zero(val)) {
-            int tmp;
-            tmp = atoi(val);
-            if (tmp > 1 && tmp < 10000) {
-                comfort_noise_level = tmp;
-            } else if (switch_true(val)) {
-                comfort_noise_level = 1400;
-            }
+			int tmp;
+			tmp = atoi(val);
+			if (tmp > 1 && tmp < 10000) {
+				comfort_noise_level = tmp;
+			} else if (switch_true(val)) {
+				comfort_noise_level = 1400;
+			}
 		} else if (!strcasecmp(var, "sound-prefix") && !switch_strlen_zero(val)) {
 			sound_prefix = val;
 		} else if (!strcasecmp(var, "max-members") && !switch_strlen_zero(val)) {
@@ -4897,7 +4915,7 @@
 			}
 		} else if (!strcasecmp(var, "suppress-events") && !switch_strlen_zero(val)) {
 			suppress_events = val;
-        }
+		}
 	}
 
 	/* Set defaults and various paramaters */
@@ -4946,7 +4964,7 @@
 		conference->tts_voice = switch_core_strdup(conference->pool, tts_voice);
 	}
 
-    conference->comfort_noise_level = comfort_noise_level;
+	conference->comfort_noise_level = comfort_noise_level;
 	conference->caller_id_name = switch_core_strdup(conference->pool, caller_id_name);
 	conference->caller_id_number = switch_core_strdup(conference->pool, caller_id_number);
 
@@ -5140,11 +5158,11 @@
 {
 	switch_xml_t cxml, cfg, advertise, room;
 	switch_event_t *params = NULL;
-	
+
 	switch_event_create(&params, SWITCH_EVENT_MESSAGE);
 	switch_assert(params);
 	switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "presence", "true");
-	
+
 
 	/* Open the config from the xml registry */
 	if (!(cxml = switch_xml_open_cfg(global_cf_name, &cfg, params))) {
@@ -5170,7 +5188,7 @@
 		}
 	}
 
- done:
+  done:
 	switch_event_destroy(&params);
 
 	/* Release the config registry handle */

Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	Tue May 27 00:54:52 2008
@@ -49,7 +49,7 @@
 
 	if (!caller_profile) {
 		caller_profile = switch_channel_get_caller_profile(channel);
-	}	
+	}
 
 	if ((extension = switch_caller_extension_new(session, "inline", "inline")) == 0) {
 		abort();
@@ -58,26 +58,26 @@
 	if (switch_strlen_zero(target)) {
 		target = caller_profile->destination_number;
 	}
-	
+
 	if (!switch_strlen_zero(target) && (lbuf = switch_core_session_strdup(session, target))
 		&& (argc = switch_separate_string(lbuf, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) {
 	} else {
 		return NULL;
 	}
 
-	
-	for(x = 0; x < argc; x++) {
+
+	for (x = 0; x < argc; x++) {
 		char *app = argv[x];
 		char *data = strchr(app, ':');
 
 		if (data) {
 			*data++ = '\0';
 		}
-		
-		while(*app == ' ') {
+
+		while (*app == ' ') {
 			app++;
 		}
-		
+
 		switch_caller_extension_add_application(session, extension, app, data);
 	}
 
@@ -119,7 +119,7 @@
 	char *argv[4] = { 0 };
 	int argc;
 	char *lbuf = NULL;
-	
+
 	if (!switch_strlen_zero(data) && (lbuf = switch_core_session_strdup(session, data))
 		&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
 		switch_core_session_execute_exten(session, argv[0], argv[1], argv[2]);
@@ -135,13 +135,13 @@
 	char *argv[4] = { 0 };
 	int argc;
 	char *lbuf = NULL;
-	
+
 	if (!switch_strlen_zero(data) && (lbuf = switch_core_session_strdup(session, data))
 		&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) == 4) {
 		switch_ivr_say(session, argv[3], argv[0], argv[1], argv[2], NULL);
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage: %s\n", SAY_SYNTAX);
-	}	
+	}
 
 }
 
@@ -151,7 +151,7 @@
 	char *argv[3] = { 0 };
 	int argc;
 	char *lbuf = NULL;
-	
+
 	if (!switch_strlen_zero(data) && (lbuf = switch_core_session_strdup(session, data))
 		&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) >= 1) {
 		switch_ivr_soft_hold(session, argv[0], argv[1], argv[2]);
@@ -166,7 +166,7 @@
 	char *argv[4] = { 0 };
 	int argc;
 	char *lbuf = NULL;
-	
+
 	if (!switch_strlen_zero(data) && (lbuf = switch_core_session_strdup(session, data))
 		&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) == 4) {
 		int kval = atoi(argv[0]);
@@ -239,7 +239,7 @@
 			} else {
 				uuid = argv[0];
 			}
-			
+
 			switch_ivr_intercept_session(session, uuid, bleg);
 		}
 		return;
@@ -275,10 +275,10 @@
 	} else {
 		switch_channel_t *channel = switch_core_session_get_channel(session);
 		const char *require_group = switch_channel_get_variable(channel, "eavesdrop_require_group");
-		if (!strcasecmp((char *)data, "all")) {
+		if (!strcasecmp((char *) data, "all")) {
 			switch_core_db_t *db = switch_core_db_handle();
 			char *errmsg = NULL;
-			struct e_data e_data = {{ 0 }};
+			struct e_data e_data = { {0} };
 			char *sql = switch_mprintf("select uuid from channels where uuid != '%q'", switch_core_session_get_uuid(session));
 			const char *file = NULL;
 			int x = 0;
@@ -286,9 +286,9 @@
 			switch_size_t buflen = sizeof(buf);
 			char terminator;
 			switch_status_t status;
-			
-			while(switch_channel_ready(channel)) {
-				for(x = 0; x < MAX_SPY; x++) {
+
+			while (switch_channel_ready(channel)) {
+				for (x = 0; x < MAX_SPY; x++) {
 					switch_safe_free(e_data.uuid_list[x]);
 				}
 				e_data.total = 0;
@@ -326,12 +326,12 @@
 				}
 			}
 
-			for(x = 0; x < MAX_SPY; x++) {
+			for (x = 0; x < MAX_SPY; x++) {
 				switch_safe_free(e_data.uuid_list[x]);
 			}
 
 			switch_core_db_close(db);
-			
+
 		} else {
 			switch_ivr_eavesdrop_session(session, data, require_group, ED_DTMF);
 		}
@@ -352,7 +352,7 @@
 #define SET_USER_SYNTAX "<user>@<domain>"
 SWITCH_STANDARD_APP(set_user_function)
 {
-	switch_xml_t x_domain, xml = NULL, x_user, x_param, x_params;	
+	switch_xml_t x_domain, xml = NULL, x_user, x_param, x_params;
 	char *user, *mailbox, *domain;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 
@@ -367,21 +367,21 @@
 	}
 
 	*domain++ = '\0';
-	
+
 	if (switch_xml_locate_user("id", user, domain, NULL, &xml, &x_domain, &x_user, NULL) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", user, domain);
 		goto done;
 	}
 
-	if ((mailbox = (char *)switch_xml_attr(x_user, "mailbox"))) {
+	if ((mailbox = (char *) switch_xml_attr(x_user, "mailbox"))) {
 		switch_channel_set_variable(channel, "mailbox", mailbox);
 	}
-	
+
 	if ((x_params = switch_xml_child(x_user, "variables"))) {
 		for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
 			const char *var = switch_xml_attr(x_param, "name");
 			const char *val = switch_xml_attr(x_param, "value");
-			
+
 			if (var && val) {
 				switch_channel_set_variable(channel, var, val);
 			}
@@ -393,10 +393,10 @@
 
 	goto done;
 
- error:
+  error:
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No user at domain specified.\n");
 
- done:
+  done:
 	if (xml) {
 		switch_xml_free(xml);
 	}
@@ -425,7 +425,7 @@
 SWITCH_STANDARD_APP(check_acl_function)
 {
 	int argc;
-    char *argv[3] = { 0 };
+	char *argv[3] = { 0 };
 	char *mydata;
 	switch_call_cause_t cause = SWITCH_CAUSE_CALL_REJECTED;
 
@@ -441,7 +441,7 @@
 			}
 		}
 	}
-	
+
 }
 
 SWITCH_STANDARD_APP(transfer_function)
@@ -451,7 +451,7 @@
 	char *mydata;
 	int bleg = 0, both = 0;
 
-	
+
 	if (!switch_strlen_zero(data) && (mydata = switch_core_session_strdup(session, data))) {
 		if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) >= 1) {
 			bleg = !strcasecmp(argv[0], "-bleg");
@@ -459,7 +459,7 @@
 
 			if (bleg || both) {
 				const char *uuid;
-				switch_channel_t *channel = switch_core_session_get_channel(session);																		
+				switch_channel_t *channel = switch_core_session_get_channel(session);
 				if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
 					switch_core_session_t *b_session;
 					if ((b_session = switch_core_session_locate(uuid))) {
@@ -592,7 +592,7 @@
 	} else {
 		len = atoi(data);
 	}
-	
+
 	switch_ivr_delay_echo(session, len);
 }
 
@@ -776,16 +776,16 @@
 			caller_profile->caller_id_number = val;
 		}
 		if (val && !strcasecmp(name, "caller_ton")) {
-			caller_profile->caller_ton = (uint8_t)atoi(val);
+			caller_profile->caller_ton = (uint8_t) atoi(val);
 		}
 		if (val && !strcasecmp(name, "caller_numplan")) {
-			caller_profile->caller_numplan = (uint8_t)atoi(val);
+			caller_profile->caller_numplan = (uint8_t) atoi(val);
 		}
 		if (val && !strcasecmp(name, "destination_number_ton")) {
-			caller_profile->destination_number_ton = (uint8_t)atoi(val);
+			caller_profile->destination_number_ton = (uint8_t) atoi(val);
 		}
 		if (val && !strcasecmp(name, "destination_number_numplan")) {
-			caller_profile->destination_number_numplan = (uint8_t)atoi(val);
+			caller_profile->destination_number_numplan = (uint8_t) atoi(val);
 		}
 		if (!strcasecmp(name, "ani")) {
 			caller_profile->ani = val;
@@ -846,7 +846,8 @@
 			}
 		}
 
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "EXPORT %s[%s]=[%s]\n", local ? "" : "(REMOTE ONLY) ", var_name ? var_name : "", val ? val : "UNDEF");
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "EXPORT %s[%s]=[%s]\n", local ? "" : "(REMOTE ONLY) ", var_name ? var_name : "",
+						  val ? val : "UNDEF");
 		switch_channel_set_variable(channel, var, val);
 
 		if (var && val) {
@@ -929,17 +930,20 @@
 				if (this) {
 					char *var, *val;
 					p = this;
-					while(*p == ' ') *p++ = '\0';
+					while (*p == ' ')
+						*p++ = '\0';
 					this = p;
-				
+
 					var = this;
 					val = NULL;
 					if ((val = strchr(var, '='))) {
 						p = val - 1;
 						*val++ = '\0';
-						while(*p == ' ') *p-- = '\0';
+						while (*p == ' ')
+							*p-- = '\0';
 						p = val;
-						while(*p == ' ') *p++ = '\0';
+						while (*p == ' ')
+							*p++ = '\0';
 						val = p;
 						switch_event_add_header(event, SWITCH_STACK_BOTTOM, var, "%s", val);
 					}
@@ -1019,8 +1023,8 @@
 	switch_time_t thetime;
 	char *p;
 	if (!switch_strlen_zero(cmd) && (p = strchr(cmd, '|'))) {
-		thetime = switch_time_make(atoi(cmd),0);
-		cmd = p+1;
+		thetime = switch_time_make(atoi(cmd), 0);
+		cmd = p + 1;
 	} else {
 		thetime = switch_timestamp_now();
 	}
@@ -1091,7 +1095,7 @@
 static char *ivr_cf_name = "ivr.conf";
 
 #ifdef _TEST_CALLBACK_
-static switch_ivr_action_t menu_handler(switch_ivr_menu_t * menu, char *param, char *buf, size_t buflen, void *obj)
+static switch_ivr_action_t menu_handler(switch_ivr_menu_t *menu, char *param, char *buf, size_t buflen, void *obj)
 {
 	switch_ivr_action_t action = SWITCH_IVR_ACTION_NOOP;
 
@@ -1107,7 +1111,7 @@
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	switch_event_t *params;
-	
+
 	if (channel) {
 		switch_xml_t cxml = NULL, cfg = NULL, xml_menus = NULL, xml_menu = NULL;
 
@@ -1118,7 +1122,7 @@
 
 		if ((cxml = switch_xml_open_cfg(ivr_cf_name, &cfg, params)) != NULL) {
 			if ((xml_menus = switch_xml_child(cfg, "menus"))) {
-				xml_menu = switch_xml_find_child(xml_menus, "menu", "name", (char *)data);
+				xml_menu = switch_xml_find_child(xml_menus, "menu", "name", (char *) data);
 
 				// if the menu was found
 				if (xml_menu != NULL) {
@@ -1134,7 +1138,7 @@
 						switch_xml_free(cxml);
 						cxml = NULL;
 						switch_channel_pre_answer(channel);
-						switch_ivr_menu_execute(session, menu_stack, (char *)data, NULL);
+						switch_ivr_menu_execute(session, menu_stack, (char *) data, NULL);
 						switch_ivr_menu_stack_free(menu_stack);
 					} else {
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to create menu\n");
@@ -1164,12 +1168,12 @@
 SWITCH_STANDARD_APP(dtmf_session_generate_function)
 {
 	switch_bool_t do_read = SWITCH_TRUE;
-	
+
 	if (!switch_strlen_zero(data)) {
 		if (!strcasecmp(data, "write")) {
 			do_read = SWITCH_FALSE;
 		}
-	}	
+	}
 	switch_ivr_inband_dtmf_generate_session(session, do_read);
 }
 
@@ -1185,9 +1189,9 @@
 
 SWITCH_STANDARD_APP(system_session_function)
 {
-    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Executing command: %s\n",data);
-    if (!system(data)) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Failed to execute command: %s\n",data);
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Executing command: %s\n", data);
+	if (!system(data)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Failed to execute command: %s\n", data);
 	}
 }
 
@@ -1211,7 +1215,7 @@
 	if (argv[3]) {
 		uint32_t mto;
 		if (*argv[3] == '+') {
-			if ((mto = atol(argv[3]+1)) > 0) {
+			if ((mto = atol(argv[3] + 1)) > 0) {
 				to = switch_timestamp(NULL) + mto;
 			} else {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID Timeout!\n");
@@ -1225,7 +1229,7 @@
 	}
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Enabling tone detection '%s' '%s'\n", argv[0], argv[1]);
-	
+
 	switch_ivr_tone_detect_session(session, argv[0], argv[1], argv[2], to, argv[4], argv[5]);
 }
 
@@ -1261,7 +1265,7 @@
 static switch_status_t bridge_on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
 {
 	char *str = (char *) buf;
-	
+
 	if (str && input && itype == SWITCH_INPUT_TYPE_DTMF) {
 		switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
 		if (strchr(str, dtmf->digit)) {
@@ -1288,7 +1292,7 @@
 				terminators = NULL;
 			}
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digit %c\n", dtmf->digit);
-			
+
 			for (p = terminators; p && *p; p++) {
 				if (*p == dtmf->digit) {
 					return SWITCH_STATUS_BREAK;
@@ -1326,7 +1330,7 @@
 	}
 
 	argc = switch_separate_string(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]));
-	
+
 	if (argc == 0) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Params!\n");
 		return;
@@ -1381,11 +1385,11 @@
 
 	switch (itype) {
 	case SWITCH_INPUT_TYPE_DTMF:
-		{			
+		{
 			switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
 			switch_channel_t *channel = switch_core_session_get_channel(session);
 			switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session);
-			
+
 			if (dtmf->digit == '#') {
 				return SWITCH_STATUS_FALSE;
 			}
@@ -1404,12 +1408,12 @@
 					}
 					switch_core_session_rwunlock(b_session);
 				}
-				
+
 				if ((extension = switch_caller_extension_new(peer_session, app, app_arg)) == 0) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
 					abort();
 				}
-				
+
 				switch_caller_extension_add_application(peer_session, extension, app, app_arg);
 				switch_channel_set_caller_extension(peer_channel, extension);
 				switch_channel_set_flag(peer_channel, CF_TRANSFER);
@@ -1418,7 +1422,7 @@
 
 				return SWITCH_STATUS_FALSE;
 			}
-			
+
 		}
 		break;
 	default:
@@ -1444,7 +1448,7 @@
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\nHangup Command uuid_bridge(%s):\n%s\n", id, switch_str_nil((char *) stream.data));
 			switch_safe_free(stream.data);
 		}
-		
+
 		switch_core_event_hook_remove_state_change(session, hanguphook);
 	}
 	return SWITCH_STATUS_SUCCESS;
@@ -1468,8 +1472,8 @@
 	}
 
 	switch_channel_set_variable(channel, SWITCH_HOLDING_UUID_VARIABLE, bond);
-	
-	
+
+
 	if ((var = switch_channel_get_variable(channel, SWITCH_CALL_TIMEOUT_VARIABLE))) {
 		timelimit = atoi(var);
 	}
@@ -1481,9 +1485,9 @@
 	peer_channel = switch_core_session_get_channel(peer_session);
 	switch_channel_set_flag(peer_channel, CF_INNER_BRIDGE);
 	switch_channel_set_flag(channel, CF_INNER_BRIDGE);
-	
+
 	switch_ivr_multi_threaded_bridge(session, peer_session, xfer_on_dtmf, peer_session, NULL);
-	
+
 	switch_channel_clear_flag(peer_channel, CF_INNER_BRIDGE);
 	switch_channel_clear_flag(channel, CF_INNER_BRIDGE);
 
@@ -1510,13 +1514,13 @@
 
 			switch_core_session_rwunlock(b_session);
 		}
-		
+
 		switch_channel_set_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE, bond);
 	}
-	
+
 	switch_core_session_rwunlock(peer_session);
-	
- end:
+
+  end:
 	switch_channel_set_variable(channel, SWITCH_HOLDING_UUID_VARIABLE, NULL);
 }
 
@@ -1538,12 +1542,12 @@
 	if (!switch_strlen_zero(data) && (mydata = switch_core_session_strdup(session, data))) {
 		argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
 	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No arguements specified.\n");		
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No arguements specified.\n");
 		return;
 	}
 
 	min_digits = atoi(argv[0]);
-	
+
 	if (argc > 1) {
 		max_digits = atoi(argv[1]);
 	}
@@ -1551,19 +1555,19 @@
 	if (argc > 2) {
 		prompt_audio_file = argv[2];
 	}
-	
+
 	if (argc > 3) {
 		var_name = argv[3];
 	}
-	
+
 	if (argc > 4) {
 		timeout = atoi(argv[4]);
 	}
-	
+
 	if (argc > 5) {
 		valid_terminators = argv[5];
 	}
-	
+
 	if (min_digits <= 1) {
 		min_digits = 1;
 	}
@@ -1571,7 +1575,7 @@
 	if (max_digits < min_digits) {
 		max_digits = min_digits;
 	}
-	
+
 	if (timeout <= 1000) {
 		timeout = 1000;
 	}
@@ -1634,7 +1638,7 @@
 	if (!switch_strlen_zero(data) && (lbuf = switch_core_session_strdup(session, data))
 		&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
 		path = argv[0];
-		for(x = 1; x < argc; x++) {
+		for (x = 1; x < argc; x++) {
 			if (strchr(argv[x], '+')) {
 				limit = atoi(argv[x]);
 			} else if (!switch_strlen_zero(argv[x])) {
@@ -1659,7 +1663,7 @@
 	switch_input_args_t args = { 0 };
 	switch_file_handle_t fh = { 0 };
 	int argc;
-    char *mydata, *argv[4] = { 0 };
+	char *mydata, *argv[4] = { 0 };
 	char *l = NULL;
 	const char *tmp;
 	int rate;
@@ -1667,10 +1671,10 @@
 	if (!switch_strlen_zero(data) && (mydata = switch_core_session_strdup(session, data))) {
 		argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
 	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No file specified.\n");		
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No file specified.\n");
 		return;
 	}
-	
+
 	path = argv[0];
 	l = argv[1];
 
@@ -1726,11 +1730,12 @@
 
 	path = switch_core_session_strdup(session, data);
 
-	if (!path) return;
+	if (!path)
+		return;
 
 	if ((p = strchr(path, '+'))) {
 		char *q = p - 1;
-		while(q && *q == ' ') {
+		while (q && *q == ' ') {
 			*q = '\0';
 			q--;
 		}
@@ -1767,11 +1772,11 @@
 	}
 
 	continue_on_fail = switch_channel_get_variable(caller_channel, "continue_on_fail");
-	
+
 	if ((var = switch_channel_get_variable(caller_channel, SWITCH_PROXY_MEDIA_VARIABLE)) && switch_true(var)) {
 		switch_channel_set_flag(caller_channel, CF_PROXY_MEDIA);
 	}
-	
+
 	if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE)
 		|| ((var = switch_channel_get_variable(caller_channel, SWITCH_BYPASS_MEDIA_VARIABLE)) && switch_true(var))) {
 		if (!switch_channel_test_flag(caller_channel, CF_ANSWERED)
@@ -1801,7 +1806,7 @@
 		   'true' to continue on all failures.
 		   'false' to not continue.
 		   A list of codes either names or numbers eg "user_busy,normal_temporary_failure,603"
-		*/
+		 */
 		if (continue_on_fail) {
 			const char *cause_str;
 			char cause_num[35] = "";
@@ -1850,11 +1855,11 @@
 			} else {
 				switch_channel_t *channel = switch_core_session_get_channel(session);
 				switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session);
-				char *a_key = (char *)switch_channel_get_variable(channel, "bridge_terminate_key");
-				char *b_key = (char *)switch_channel_get_variable(peer_channel, "bridge_terminate_key");
+				char *a_key = (char *) switch_channel_get_variable(channel, "bridge_terminate_key");
+				char *b_key = (char *) switch_channel_get_variable(peer_channel, "bridge_terminate_key");
 				int ok = 0;
 				switch_input_callback_function_t func = NULL;
-				
+
 				if (a_key) {
 					a_key = switch_core_session_strdup(session, a_key);
 					ok++;
@@ -1873,7 +1878,7 @@
 				switch_ivr_multi_threaded_bridge(session, peer_session, func, a_key, a_key);
 			}
 		}
-	end:
+	  end:
 		if (peer_session) {
 			switch_core_session_rwunlock(peer_session);
 		}
@@ -1885,9 +1890,7 @@
 static switch_call_cause_t user_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);
+												 switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags);
 switch_io_routines_t user_io_routines = {
 	/*.outgoing_channel */ user_outgoing_channel
 };
@@ -1895,11 +1898,9 @@
 static switch_call_cause_t user_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)
+												 switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags)
 {
-	switch_xml_t x_domain = NULL, xml = NULL, x_user = NULL, x_param, x_params;	
+	switch_xml_t x_domain = NULL, xml = NULL, x_user = NULL, x_param, x_params;
 	char *user = NULL, *domain = NULL;
 	const char *dest = NULL;
 	static switch_call_cause_t cause = SWITCH_CAUSE_UNALLOCATED;
@@ -1912,7 +1913,8 @@
 
 	user = strdup(outbound_profile->destination_number);
 
-	if (!user) goto done;
+	if (!user)
+		goto done;
 
 	if (!(domain = strchr(user, '@'))) {
 		goto done;
@@ -1934,7 +1936,7 @@
 		for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
 			const char *var = switch_xml_attr(x_param, "name");
 			const char *val = switch_xml_attr(x_param, "value");
-			
+
 			if (!strcasecmp(var, "dial-string")) {
 				dest = val;
 				break;
@@ -1946,7 +1948,7 @@
 		for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
 			const char *var = switch_xml_attr(x_param, "name");
 			const char *val = switch_xml_attr(x_param, "value");
-			
+
 			if (!strcasecmp(var, "dial-string")) {
 				dest = val;
 				break;
@@ -1965,10 +1967,10 @@
 			if ((var = switch_channel_get_variable(channel, SWITCH_CALL_TIMEOUT_VARIABLE))) {
 				timelimit = atoi(var);
 			}
-			
+
 			switch_channel_set_variable(channel, "dialed_user", user);
 			switch_channel_set_variable(channel, "dialed_domain", domain);
-			
+
 			d_dest = switch_channel_expand_variables(channel, dest);
 
 		} else {
@@ -1977,7 +1979,7 @@
 				switch_event_create(&event, SWITCH_EVENT_MESSAGE);
 				switch_assert(event);
 			}
-			
+
 			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "dialed_user", user);
 			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "dialed_domain", domain);
 			d_dest = switch_event_expand_headers(event, dest);
@@ -1985,7 +1987,7 @@
 				switch_event_destroy(&event);
 			}
 		}
-		
+
 		if ((flags & SOF_FORKED_DIAL)) {
 			myflags |= SOF_NOBLOCK;
 		}
@@ -1995,7 +1997,7 @@
 			switch_caller_profile_t *cp;
 
 			new_channel = switch_core_session_get_channel(*new_session);
-			
+
 			if ((context = switch_channel_get_variable(new_channel, "user_context"))) {
 				if ((cp = switch_channel_get_caller_profile(new_channel))) {
 					cp->context = switch_core_strdup(cp->pool, context);
@@ -2027,12 +2029,12 @@
 		}
 	}
 
- done:
+  done:
 
 	if (xml) {
 		switch_xml_free(xml);
 	}
-	
+
 	if (params) {
 		switch_event_destroy(&params);
 	}
@@ -2080,20 +2082,22 @@
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 
 	user_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
-    user_endpoint_interface->interface_name = "USER";
-    user_endpoint_interface->io_routines = &user_io_routines;
+	user_endpoint_interface->interface_name = "USER";
+	user_endpoint_interface->io_routines = &user_io_routines;
 
 	SWITCH_ADD_API(api_interface, "strepoch", "Convert a date string into epoch time", strepoch_api_function, "<string>");
 	SWITCH_ADD_API(api_interface, "chat", "chat", chat_api_function, "<proto>|<from>|<to>|<message>");
 	SWITCH_ADD_API(api_interface, "strftime", "strftime", strftime_api_function, "<format_string>");
 	SWITCH_ADD_API(api_interface, "presence", "presence", presence_api_function, "<user> <rpid> <message>");
-	SWITCH_ADD_APP(app_interface, "privacy", "Set privacy on calls", "Set caller privacy on calls.", privacy_function, "off|on|name|full|number", SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "privacy", "Set privacy on calls", "Set caller privacy on calls.", privacy_function, "off|on|name|full|number",
+				   SAF_SUPPORT_NOMEDIA);
 
 	SWITCH_ADD_APP(app_interface, "hold", "Send a hold message", "Send a hold message", hold_function, HOLD_SYNTAX, SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "unhold", "Send a un-hold message", "Send a un-hold message", unhold_function, UNHOLD_SYNTAX, SAF_SUPPORT_NOMEDIA);
-	SWITCH_ADD_APP(app_interface, "transfer", "Transfer a channel", TRANSFER_LONG_DESC, transfer_function, "<exten> [<dialplan> <context>]", SAF_SUPPORT_NOMEDIA);
-	SWITCH_ADD_APP(app_interface, "check_acl", "Check an ip against an ACL list", 
-				   "Check an ip against an ACL list", check_acl_function, "<ip> <acl | cidr> [<hangup_cause>]", SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "transfer", "Transfer a channel", TRANSFER_LONG_DESC, transfer_function, "<exten> [<dialplan> <context>]",
+				   SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "check_acl", "Check an ip against an ACL list", "Check an ip against an ACL list", check_acl_function,
+				   "<ip> <acl | cidr> [<hangup_cause>]", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "sleep", "Pause a channel", SLEEP_LONG_DESC, sleep_function, "<pausemilliseconds>", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "delay_echo", "echo audio at a specified delay", "Delay n ms", delay_function, "<delay ms>", SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "strftime", NULL, NULL, strftime_function, NULL, SAF_SUPPORT_NOMEDIA);
@@ -2106,36 +2110,50 @@
 	SWITCH_ADD_APP(app_interface, "log", "Logs a channel variable", LOG_LONG_DESC, log_function, "<varname>", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "info", "Display Call Info", "Display Call Info", info_function, "", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "event", "Fire an event", "Fire an event", event_function, "", SAF_SUPPORT_NOMEDIA);
-	SWITCH_ADD_APP(app_interface, "export", "Export a channel variable across a bridge", EXPORT_LONG_DESC, export_function, "<varname>=<value>", SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "export", "Export a channel variable across a bridge", EXPORT_LONG_DESC, export_function, "<varname>=<value>",
+				   SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "set", "Set a channel variable", SET_LONG_DESC, set_function, "<varname>=<value>", SAF_SUPPORT_NOMEDIA);
-	SWITCH_ADD_APP(app_interface, "set_global", "Set a global variable", SET_GLOBAL_LONG_DESC, set_global_function, "<varname>=<value>", SAF_SUPPORT_NOMEDIA);
-	SWITCH_ADD_APP(app_interface, "set_profile_var", "Set a caller profile variable", SET_PROFILE_VAR_LONG_DESC, set_profile_var_function, "<varname>=<value>", SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "set_global", "Set a global variable", SET_GLOBAL_LONG_DESC, set_global_function, "<varname>=<value>",
+				   SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "set_profile_var", "Set a caller profile variable", SET_PROFILE_VAR_LONG_DESC, set_profile_var_function,
+				   "<varname>=<value>", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "unset", "Unset a channel variable", UNSET_LONG_DESC, unset_function, "<varname>", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "ring_ready", "Indicate Ring_Ready", "Indicate Ring_Ready on a channel.", ring_ready_function, "", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "break", "Break", "Set the break flag.", break_function, "", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "detect_speech", "Detect speech", "Detect speech on a channel.", detect_speech_function, DETECT_SPEECH_SYNTAX, SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "ivr", "Run an ivr menu", "Run an ivr menu.", ivr_application_function, "<menu_name>", SAF_NONE);
-	SWITCH_ADD_APP(app_interface, "redirect", "Send session redirect", "Send a redirect message to a session.", redirect_function, "<redirect_data>", SAF_SUPPORT_NOMEDIA);
-	SWITCH_ADD_APP(app_interface, "send_display", "Send session a new display", "Send session a new display.", display_function, "<text>", SAF_SUPPORT_NOMEDIA);
-	SWITCH_ADD_APP(app_interface, "respond", "Send session respond", "Send a respond message to a session.", respond_function, "<respond_data>", SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "redirect", "Send session redirect", "Send a redirect message to a session.", redirect_function, "<redirect_data>",
+				   SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "send_display", "Send session a new display", "Send session a new display.", display_function, "<text>",
+				   SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "respond", "Send session respond", "Send a respond message to a session.", respond_function, "<respond_data>",
+				   SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "deflect", "Send call deflect", "Send a call deflect.", deflect_function, "<deflect_data>", SAF_SUPPORT_NOMEDIA);
-	SWITCH_ADD_APP(app_interface, "queue_dtmf", "Queue dtmf to be sent", "Queue dtmf to be sent from a session", queue_dtmf_function, "<dtmf_data>", SAF_SUPPORT_NOMEDIA);
-	SWITCH_ADD_APP(app_interface, "send_dtmf", "Send dtmf to be sent", "Send dtmf to be sent from a session", send_dtmf_function, "<dtmf_data>", SAF_SUPPORT_NOMEDIA);
-	SWITCH_ADD_APP(app_interface, "sched_hangup", SCHED_HANGUP_DESCR, SCHED_HANGUP_DESCR, sched_hangup_function, "[+]<time> [<cause>]", SAF_SUPPORT_NOMEDIA);
-	SWITCH_ADD_APP(app_interface, "sched_broadcast", SCHED_BROADCAST_DESCR, SCHED_BROADCAST_DESCR, sched_broadcast_function, "[+]<time> <path> [aleg|bleg|both]", SAF_SUPPORT_NOMEDIA);
-	SWITCH_ADD_APP(app_interface, "sched_transfer", SCHED_TRANSF_DESCR, SCHED_TRANSF_DESCR, sched_transfer_function, "[+]<time> <extension> <dialplan> <context>", SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "queue_dtmf", "Queue dtmf to be sent", "Queue dtmf to be sent from a session", queue_dtmf_function, "<dtmf_data>",
+				   SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "send_dtmf", "Send dtmf to be sent", "Send dtmf to be sent from a session", send_dtmf_function, "<dtmf_data>",
+				   SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "sched_hangup", SCHED_HANGUP_DESCR, SCHED_HANGUP_DESCR, sched_hangup_function, "[+]<time> [<cause>]",
+				   SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "sched_broadcast", SCHED_BROADCAST_DESCR, SCHED_BROADCAST_DESCR, sched_broadcast_function,
+				   "[+]<time> <path> [aleg|bleg|both]", SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "sched_transfer", SCHED_TRANSF_DESCR, SCHED_TRANSF_DESCR, sched_transfer_function,
+				   "[+]<time> <extension> <dialplan> <context>", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "execute_extension", "Execute an extension", "Execute an extension", exe_function, EXE_SYNTAX, SAF_SUPPORT_NOMEDIA);
-	SWITCH_ADD_APP(app_interface, "soft_hold", "Put a bridged channel on hold", "Put a bridged channel on hold", soft_hold_function, SOFT_HOLD_SYNTAX, SAF_NONE);
-	SWITCH_ADD_APP(app_interface, "bind_meta_app", "Bind a key to an application", "Bind a key to an application", dtmf_bind_function, BIND_SYNTAX, SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "soft_hold", "Put a bridged channel on hold", "Put a bridged channel on hold", soft_hold_function, SOFT_HOLD_SYNTAX,
+				   SAF_NONE);
+	SWITCH_ADD_APP(app_interface, "bind_meta_app", "Bind a key to an application", "Bind a key to an application", dtmf_bind_function, BIND_SYNTAX,
+				   SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "intercept", "intercept", "intercept", intercept_function, INTERCEPT_SYNTAX, SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "eavesdrop", "eavesdrop on a uuid", "eavesdrop on a uuid", eavesdrop_function, eavesdrop_SYNTAX, SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "three_way", "three way call with a uuid", "three way call with a uuid", three_way_function, threeway_SYNTAX, SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "set_user", "Set a User", "Set a User", set_user_function, SET_USER_SYNTAX, SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "stop_dtmf", "stop inband dtmf", "Stop detecting inband dtmf.", stop_dtmf_session_function, "", SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "start_dtmf", "Detect dtmf", "Detect inband dtmf on the session", dtmf_session_function, "", SAF_NONE);
-	SWITCH_ADD_APP(app_interface, "stop_dtmf_generate", "stop inband dtmf generation", "Stop generating inband dtmf.", 
+	SWITCH_ADD_APP(app_interface, "stop_dtmf_generate", "stop inband dtmf generation", "Stop generating inband dtmf.",
 				   stop_dtmf_session_generate_function, "[write]", SAF_NONE);
-	SWITCH_ADD_APP(app_interface, "start_dtmf_generate", "Generate dtmf", "Generate inband dtmf on the session", dtmf_session_generate_function, "", SAF_NONE);
+	SWITCH_ADD_APP(app_interface, "start_dtmf_generate", "Generate dtmf", "Generate inband dtmf on the session", dtmf_session_generate_function, "",
+				   SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "stop_tone_detect", "stop detecting tones", "Stop detecting tones", stop_fax_detect_session_function, "", SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "fax_detect", "Detect faxes", "Detect fax send tone", fax_detect_session_function, "", SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "tone_detect", "Detect tones", "Detect tones", tone_detect_session_function, "", SAF_NONE);
@@ -2148,13 +2166,19 @@
 	SWITCH_ADD_APP(app_interface, "read", "Read Digits", "Read Digits", read_function, "<min> <max> <file> <var name> <timeout> <terminators>", SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "stop_record_session", "Stop Record Session", STOP_SESS_REC_DESC, stop_record_session_function, "<path>", SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "record_session", "Record Session", SESS_REC_DESC, record_session_function, "<path>", SAF_NONE);
-	SWITCH_ADD_APP(app_interface, "record", "Record File", "Record a file from the channels input", record_function, "<path> [<time_limit_secs>] [<silence_thresh>] [<silence_hits>]", SAF_NONE);
-	SWITCH_ADD_APP(app_interface, "stop_displace_session", "Stop Displace File", "Stop Displacing to a file", stop_displace_session_function, "<path>", SAF_NONE);
-	SWITCH_ADD_APP(app_interface, "displace_session", "Displace File", DISPLACE_DESC, displace_session_function, "<path> [+time_limit_ms] [mux]", SAF_NONE);
+	SWITCH_ADD_APP(app_interface, "record", "Record File", "Record a file from the channels input", record_function,
+				   "<path> [<time_limit_secs>] [<silence_thresh>] [<silence_hits>]", SAF_NONE);
+	SWITCH_ADD_APP(app_interface, "stop_displace_session", "Stop Displace File", "Stop Displacing to a file", stop_displace_session_function, "<path>",
+				   SAF_NONE);
+	SWITCH_ADD_APP(app_interface, "displace_session", "Displace File", DISPLACE_DESC, displace_session_function, "<path> [+time_limit_ms] [mux]",
+				   SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "speak", "Speak text", SPEAK_DESC, speak_function, "<engine>|<voice>|<text>", SAF_NONE);
-	SWITCH_ADD_APP(app_interface, "clear_speech_cache", "Clear Speech Handle Cache", "Clear Speech Handle Cache", clear_speech_cache_function, "", SAF_NONE);
-	SWITCH_ADD_APP(app_interface, "bridge", "Bridge Audio", "Bridge the audio between two sessions", audio_bridge_function, "<channel_url>", SAF_SUPPORT_NOMEDIA);
-	SWITCH_ADD_APP(app_interface, "system", "Execute a system command", "Execute a system command", system_session_function, "<command>", SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "clear_speech_cache", "Clear Speech Handle Cache", "Clear Speech Handle Cache", clear_speech_cache_function, "",
+				   SAF_NONE);
+	SWITCH_ADD_APP(app_interface, "bridge", "Bridge Audio", "Bridge the audio between two sessions", audio_bridge_function, "<channel_url>",
+				   SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "system", "Execute a system command", "Execute a system command", system_session_function, "<command>",
+				   SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "say", "say", "say", say_function, SAY_SYNTAX, SAF_NONE);
 
 	SWITCH_ADD_DIALPLAN(dp_interface, "inline", inline_dialplan_hunt);

Modified: freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c	Tue May 27 00:54:52 2008
@@ -200,16 +200,16 @@
 	return out;
 }
 
-static void dnserror(enum_query_t * q, int errnum)
+static void dnserror(enum_query_t *q, int errnum)
 {
-	
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unable to lookup %s record for %s: %s\n",
 					  dns_typename(q->qtyp), dns_dntosp(q->dn), dns_strerror(errnum));
 	q->errs++;
 }
 
 
-static void add_result(enum_query_t * q, int order, int preference, char *service, char *route, int supported)
+static void add_result(enum_query_t *q, int order, int preference, char *service, char *route, int supported)
 {
 	enum_record_t *new_result, *rp, *prev = NULL;
 
@@ -255,7 +255,7 @@
 }
 
 
-static void free_results(enum_record_t ** results)
+static void free_results(enum_record_t **results)
 {
 	enum_record_t *fp, *rp;
 
@@ -269,7 +269,7 @@
 	*results = NULL;
 }
 
-static void parse_rr(const struct dns_parse *p, enum_query_t * q, struct dns_rr *rr)
+static void parse_rr(const struct dns_parse *p, enum_query_t *q, struct dns_rr *rr)
 {
 	const unsigned char *pkt = p->dnsp_pkt;
 	const unsigned char *end = p->dnsp_end;
@@ -287,17 +287,17 @@
 	int argc = 0;
 	char *argv[4] = { 0 };
 	int n;
-	char string_arg[3][256] = {{0}};
+	char string_arg[3][256] = { {0} };
 
 	switch (rr->dnsrr_typ) {
-	case DNS_T_NAPTR:/* prio weight port targetDN */
+	case DNS_T_NAPTR:			/* prio weight port targetDN */
 		c = dptr;
-		c += 4; /* order, pref */
+		c += 4;					/* order, pref */
 
 		for (n = 0; n < 3; ++n) {
 			if (c >= dend) {
 				goto xperr;
-			} else { 
+			} else {
 				c += *c + 1;
 			}
 		}
@@ -307,18 +307,18 @@
 		}
 
 		c = dptr;
-		order = dns_get16(c+0);
-		preference = dns_get16(c+2);
+		order = dns_get16(c + 0);
+		preference = dns_get16(c + 2);
 		flags = (char) dns_get16(c + 4);
 		c += 4;
 
-		for(n = 0; n < 3; n++) {
+		for (n = 0; n < 3; n++) {
 			uint32_t len = *c++, cpylen = len;
 			switch_assert(string_arg[n]);
 			if (len > sizeof(string_arg[n]) - 1) {
 				cpylen = sizeof(string_arg[n]) - 1;
 			}
-			strncpy(string_arg[n], (char *)c, cpylen);
+			strncpy(string_arg[n], (char *) c, cpylen);
 			*(string_arg[n] + len) = '\0';
 			c += len;
 		}
@@ -357,7 +357,7 @@
 				}
 
 				switch_mutex_lock(MUTEX);
-				for(route = globals.route_order; route; route = route->next) {
+				for (route = globals.route_order; route; route = route->next) {
 					if (strcasecmp(service, route->service)) {
 						continue;
 					}
@@ -377,9 +377,9 @@
 				if (!supported) {
 					add_result(q, order, preference, service, uri, 0);
 				}
-			} 
+			}
 			switch_mutex_unlock(MUTEX);
-			
+
 
 			switch_regex_safe_free(re);
 		}
@@ -392,7 +392,7 @@
 
 	return;
 
-	xperr:
+  xperr:
 	//printf("<parse error>\n");
 	return;
 }
@@ -452,7 +452,7 @@
 }
 
 
-static switch_status_t enum_lookup(char *root, char *in, enum_record_t ** results)
+static switch_status_t enum_lookup(char *root, char *in, enum_record_t **results)
 {
 	switch_status_t sstatus = SWITCH_STATUS_SUCCESS;
 	char *name = NULL;
@@ -467,7 +467,7 @@
 	char *num, *mnum = NULL, *mroot = NULL, *p;
 
 	mnum = switch_mprintf("%s%s", *in == '+' ? "" : "+", in);
-	
+
 	if ((p = strchr(mnum, '*'))) {
 		*p++ = '\0';
 		mroot = switch_mprintf("%s.%s", p, root ? root : globals.isn_root);
@@ -587,15 +587,15 @@
 		}
 		switch_channel_set_variable(channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE, "true");
 
-		
+
 		for (rp = results; rp; rp = rp->next) {
 			if (!rp->supported) {
 				continue;
 			}
 
-			switch_caller_extension_add_application(session, extension, "bridge", rp->route);			
+			switch_caller_extension_add_application(session, extension, "bridge", rp->route);
 		}
-		
+
 
 		free_results(&results);
 	}
@@ -644,7 +644,7 @@
 					continue;
 				}
 				switch_snprintf(vbuf, sizeof(vbuf), "enum_route_%d", cnt++);
-				switch_channel_set_variable(channel, vbuf, rp->route);						
+				switch_channel_set_variable(channel, vbuf, rp->route);
 				if (rp->preference == last_pref && rp->order == last_order) {
 					*last_delim = ',';
 				}
@@ -656,7 +656,7 @@
 				rbp += l;
 				rbl -= l;
 			}
-			
+
 			switch_snprintf(vbuf, sizeof(vbuf), "%d", cnt);
 			switch_channel_set_variable(channel, "enum_route_count", vbuf);
 			*(rbuf + strlen(rbuf) - 1) = '\0';
@@ -681,7 +681,7 @@
 	int last_order = -1, last_pref = -2;
 	char *last_delim = "|";
 	int ok = 0;
-	
+
 	if (switch_strlen_zero(cmd)) {
 		stream->write_function(stream, "%s", "none");
 		return SWITCH_STATUS_SUCCESS;
@@ -709,7 +709,7 @@
 				l = strlen(rp->route) + 1;
 				rbp += l;
 				rbl -= l;
-			
+
 			}
 			*(rbuf + strlen(rbuf) - 1) = '\0';
 			stream->write_function(stream, "%s", rbuf);
@@ -738,7 +738,7 @@
 	memset(&globals, 0, sizeof(globals));
 	switch_core_new_memory_pool(&globals.pool);
 	globals.timeout = 10;
-    load_config();
+	load_config();
 	switch_mutex_unlock(MUTEX);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "ENUM Reloaded\n");
 
@@ -772,7 +772,7 @@
 		if (!strcasecmp(dest, "reload")) {
 			do_load();
 			stream->write_function(stream, "+OK ENUM Reloaded.\n");
-            return SWITCH_STATUS_SUCCESS;
+			return SWITCH_STATUS_SUCCESS;
 
 		}
 
@@ -843,10 +843,11 @@
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 	SWITCH_ADD_API(api_interface, "enum", "ENUM", enum_function, "");
 	SWITCH_ADD_API(api_interface, "enum_auto", "ENUM", enum_api, "");
-	SWITCH_ADD_APP(app_interface, "enum", "Perform an ENUM lookup", "Perform an ENUM lookup", enum_app_function, "[reload | <number> [<root>]]", SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "enum", "Perform an ENUM lookup", "Perform an ENUM lookup", enum_app_function, "[reload | <number> [<root>]]",
+				   SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_DIALPLAN(dp_interface, "enum", enum_dialplan_hunt);
 
-	
+
 	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;
 }

Modified: freeswitch/trunk/src/mod/applications/mod_esf/mod_esf.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_esf/mod_esf.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_esf/mod_esf.c	Tue May 27 00:54:52 2008
@@ -63,7 +63,7 @@
 	switch_status_t status;
 	switch_size_t bytes;
 	ls_control_packet_t control_packet;
-	switch_codec_t codec = { 0}, *read_codec, *orig_codec = NULL;
+	switch_codec_t codec = { 0 }, *read_codec, *orig_codec = NULL;
 	uint32_t flags = 0;
 	const char *err;
 	switch_rtp_t *rtp_session = NULL;
@@ -71,7 +71,7 @@
 	char guess_ip[25];
 	ls_how_t ready = SEND_TYPE_UNKNOWN;
 	int argc;
-    char *mydata, *argv[5];
+	char *mydata, *argv[5];
 	char *mcast_ip = "224.168.168.168";
 	switch_port_t mcast_port = 34567;
 	switch_port_t mcast_control_port = 6061;
@@ -84,7 +84,7 @@
 		assert(mydata != NULL);
 
 		argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
-	
+
 		if ((var = switch_channel_get_variable(channel, "esf_multicast_ip"))) {
 			mcast_ip = switch_core_session_strdup(session, var);
 		}
@@ -95,23 +95,23 @@
 
 		if (!switch_strlen_zero(argv[1])) {
 			mcast_port_str = argv[1];
-			mcast_port = (switch_port_t)atoi(mcast_port_str);
+			mcast_port = (switch_port_t) atoi(mcast_port_str);
 		}
 
 		if (!switch_strlen_zero(argv[2])) {
-			mcast_control_port = (switch_port_t)atoi(argv[2]);
+			mcast_control_port = (switch_port_t) atoi(argv[2]);
 		}
 	}
 
-	
+
 	if (switch_true(switch_channel_get_variable(channel, SWITCH_BYPASS_MEDIA_VARIABLE))) {
 		switch_core_session_message_t msg = { 0 };
 
 		ready = SEND_TYPE_NOMEDIA;
-		
+
 		switch_channel_set_variable(channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE, mcast_ip);
 		switch_channel_set_variable(channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE, mcast_port_str);
-		
+
 		/* special answer with the mcast addr */
 		msg.from = __FILE__;
 		msg.string_arg = "recvonly";
@@ -119,7 +119,7 @@
 		switch_core_session_receive_message(session, &msg);
 	} else {
 		switch_channel_answer(channel);
-	} 
+	}
 
 	read_codec = switch_core_session_get_read_codec(session);
 
@@ -128,14 +128,14 @@
 		goto fail;
 	}
 
-	if (switch_sockaddr_info_get(&control_packet_addr, mcast_ip, SWITCH_UNSPEC, 
+	if (switch_sockaddr_info_get(&control_packet_addr, mcast_ip, SWITCH_UNSPEC,
 								 mcast_control_port, 0, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error 3\n");
 		goto fail;
 	}
 
 
-	while(!ready) {
+	while (!ready) {
 		status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
 		if (read_frame && switch_test_flag(read_frame, SFF_CNG)) {
 			continue;
@@ -144,7 +144,7 @@
 		if (!SWITCH_READ_ACCEPTABLE(status) || !read_frame) {
 			goto fail;
 		}
-		
+
 		if (read_frame->packet && read_frame->packetlen && read_codec->implementation->ianacode == 0) {
 			ready = SEND_TYPE_RAW;
 		} else {
@@ -153,23 +153,23 @@
 	}
 
 	if (ready == SEND_TYPE_RTP) {
-        if (read_codec->implementation->ianacode != 0) {
-            if (switch_core_codec_init(&codec,
-                                       "PCMU",
-                                       NULL,
-                                       8000,
-                                       20,
-                                       1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, 
-                                       NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
-                orig_codec = read_codec;
-                read_codec = &codec;
-                switch_core_session_set_read_codec(session, read_codec);
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Codec Activation Success\n");
-            } else {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Activation Fail\n");
-                goto fail;
-            }
-        }
+		if (read_codec->implementation->ianacode != 0) {
+			if (switch_core_codec_init(&codec,
+									   "PCMU",
+									   NULL,
+									   8000,
+									   20,
+									   1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+									   NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
+				orig_codec = read_codec;
+				read_codec = &codec;
+				switch_core_session_set_read_codec(session, read_codec);
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Codec Activation Success\n");
+			} else {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Activation Fail\n");
+				goto fail;
+			}
+		}
 
 		if ((var = switch_channel_get_variable(channel, "esf_broadcast_ip"))) {
 			esf_broadcast_ip = switch_core_session_strdup(session, var);
@@ -191,9 +191,8 @@
 									 read_codec->implementation->ianacode,
 									 read_codec->implementation->samples_per_frame,
 									 read_codec->implementation->microseconds_per_frame,
-									 (switch_rtp_flag_t) flags,
-									 "soft", &err, switch_core_session_get_pool(session));
-	
+									 (switch_rtp_flag_t) flags, "soft", &err, switch_core_session_get_pool(session));
+
 		if (!switch_rtp_ready(rtp_session)) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "RTP Error\n");
 			goto fail;
@@ -207,23 +206,23 @@
 		}
 	}
 
-	control_packet.unique_id = htonl((u_long)switch_timestamp(NULL));
+	control_packet.unique_id = htonl((u_long) switch_timestamp(NULL));
 	control_packet.command = htonl(LS_START_BCAST);
 	control_packet.ip = inet_addr(mcast_ip);
 	control_packet.port = htonl(mcast_port);
 
 	bytes = 16;
-	switch_socket_sendto(socket, control_packet_addr, 0, (void *)&control_packet, &bytes);
+	switch_socket_sendto(socket, control_packet_addr, 0, (void *) &control_packet, &bytes);
 	bytes = 16;
-	switch_socket_sendto(socket, control_packet_addr, 0, (void *)&control_packet, &bytes);
+	switch_socket_sendto(socket, control_packet_addr, 0, (void *) &control_packet, &bytes);
 
-	for(;;) {
+	for (;;) {
 
 		status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
 
-        if (!SWITCH_READ_ACCEPTABLE(status)) {
-            break;
-        }
+		if (!SWITCH_READ_ACCEPTABLE(status)) {
+			break;
+		}
 		if (switch_test_flag(read_frame, SFF_CNG)) {
 			continue;
 		}
@@ -235,23 +234,23 @@
 		}
 	}
 
-	control_packet.unique_id = htonl((u_long)switch_timestamp(NULL));
+	control_packet.unique_id = htonl((u_long) switch_timestamp(NULL));
 	control_packet.command = htonl(LS_STOP_BCAST);
 	bytes = 8;
-	switch_socket_sendto(socket, control_packet_addr, 0, (void *)&control_packet, &bytes);
+	switch_socket_sendto(socket, control_packet_addr, 0, (void *) &control_packet, &bytes);
 	bytes = 8;
-	switch_socket_sendto(socket, control_packet_addr, 0, (void *)&control_packet, &bytes);
+	switch_socket_sendto(socket, control_packet_addr, 0, (void *) &control_packet, &bytes);
 
- fail:
+  fail:
 
-    if (orig_codec) {
-        switch_core_session_set_read_codec(session, orig_codec);
-        switch_core_codec_destroy(&codec);
-    }
+	if (orig_codec) {
+		switch_core_session_set_read_codec(session, orig_codec);
+		switch_core_codec_destroy(&codec);
+	}
 
 	if (rtp_session && ready == SEND_TYPE_RTP && switch_rtp_ready(rtp_session)) {
 		switch_rtp_destroy(&rtp_session);
-	}	
+	}
 
 	if (socket) {
 		switch_socket_close(socket);

Modified: freeswitch/trunk/src/mod/applications/mod_expr/expreval.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_expr/expreval.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_expr/expreval.c	Tue May 27 00:54:52 2008
@@ -25,244 +25,224 @@
 
 
 /* This routine will evaluate an expression */
-int exprEval(exprObj *obj, EXPRTYPE *val)
-    {
-    EXPRTYPE dummy;
-
-    if(val ==  NULL)
-        val = &dummy;
-
-    /* Make sure it was parsed successfully */
-    if(!obj->parsedbad && obj->parsedgood && obj->headnode)
-        {
-        /* Do NOT reset the break count.  Let is accumulate
-           between calls until breaker function is called */
-        return exprEvalNode(obj, obj->headnode, 0, val);
-        }
-    else
-        return EXPR_ERROR_BADEXPR;
-    }
+int exprEval(exprObj * obj, EXPRTYPE * val)
+{
+	EXPRTYPE dummy;
+
+	if (val == NULL)
+		val = &dummy;
+
+	/* Make sure it was parsed successfully */
+	if (!obj->parsedbad && obj->parsedgood && obj->headnode) {
+		/* Do NOT reset the break count.  Let is accumulate
+		   between calls until breaker function is called */
+		return exprEvalNode(obj, obj->headnode, 0, val);
+	} else
+		return EXPR_ERROR_BADEXPR;
+}
 
 /* Evaluate a node */
-int exprEvalNode(exprObj *obj, exprNode *nodes, int curnode, EXPRTYPE *val)
-    {
-    int err;
-    int pos;
-    EXPRTYPE d1, d2;
-
-    if(obj == NULL || nodes == NULL)
-        return EXPR_ERROR_NULLPOINTER;
-
-    /* Update n to point to correct node */
-    nodes += curnode;
-
-    /* Check breaker count */
-    if(obj->breakcur-- <= 0)
-        {
-        /* Reset count before returning */
-        obj->breakcur = obj->breakcount;
-                
-        if(exprGetBreakResult(obj))
-            {
-            return EXPR_ERROR_BREAK;
-            }
-        }
-
-    switch(nodes->type)
-        {
-        case EXPR_NODETYPE_MULTI:
-            {
-            /* Multi for multiple expressions in one string */
-            for(pos = 0; pos < nodes->data.oper.nodecount; pos++)
-                {
-                err = exprEvalNode(obj, nodes->data.oper.nodes, pos, val);
-                if(err)
-                    return err;
-                }
-            break;
-            }
-
-        case EXPR_NODETYPE_ADD:
-            {
-            /* Addition */
-            err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
-
-            if(!err)
-                err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
-
-            if(!err)
-                *val = d1 + d2;
-            else
-                return err;
-
-            break;
-            }
-
-        case EXPR_NODETYPE_SUBTRACT:
-            {
-            /* Subtraction */
-            err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
-            
-            if(!err)
-                err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
-
-            if(!err)
-                *val = d1 - d2;
-            else
-                return err;
-
-            break;
-            }
-
-        case EXPR_NODETYPE_MULTIPLY:
-            {
-            /* Multiplication */
-            err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
-
-            if(!err)
-                err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
-
-            if(!err)
-                *val = d1 * d2;
-            else
-                return err;
-
-            break;
-            }
-
-        case EXPR_NODETYPE_DIVIDE:
-            {
-            /* Division */
-            err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
-
-            if(!err)
-                err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
-
-            if(!err)
-                {
-                if(d2 != 0.0)
-                    *val = d1 / d2;
-                else
-                    {
+int exprEvalNode(exprObj * obj, exprNode * nodes, int curnode, EXPRTYPE * val)
+{
+	int err;
+	int pos;
+	EXPRTYPE d1, d2;
+
+	if (obj == NULL || nodes == NULL)
+		return EXPR_ERROR_NULLPOINTER;
+
+	/* Update n to point to correct node */
+	nodes += curnode;
+
+	/* Check breaker count */
+	if (obj->breakcur-- <= 0) {
+		/* Reset count before returning */
+		obj->breakcur = obj->breakcount;
+
+		if (exprGetBreakResult(obj)) {
+			return EXPR_ERROR_BREAK;
+		}
+	}
+
+	switch (nodes->type) {
+	case EXPR_NODETYPE_MULTI:
+		{
+			/* Multi for multiple expressions in one string */
+			for (pos = 0; pos < nodes->data.oper.nodecount; pos++) {
+				err = exprEvalNode(obj, nodes->data.oper.nodes, pos, val);
+				if (err)
+					return err;
+			}
+			break;
+		}
+
+	case EXPR_NODETYPE_ADD:
+		{
+			/* Addition */
+			err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
+
+			if (!err)
+				err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
+
+			if (!err)
+				*val = d1 + d2;
+			else
+				return err;
+
+			break;
+		}
+
+	case EXPR_NODETYPE_SUBTRACT:
+		{
+			/* Subtraction */
+			err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
+
+			if (!err)
+				err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
+
+			if (!err)
+				*val = d1 - d2;
+			else
+				return err;
+
+			break;
+		}
+
+	case EXPR_NODETYPE_MULTIPLY:
+		{
+			/* Multiplication */
+			err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
+
+			if (!err)
+				err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
+
+			if (!err)
+				*val = d1 * d2;
+			else
+				return err;
+
+			break;
+		}
+
+	case EXPR_NODETYPE_DIVIDE:
+		{
+			/* Division */
+			err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
+
+			if (!err)
+				err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
+
+			if (!err) {
+				if (d2 != 0.0)
+					*val = d1 / d2;
+				else {
 #if(EXPR_ERROR_LEVEL >= EXPR_ERROR_LEVEL_CHECK)
-                    return EXPR_ERROR_DIVBYZERO;
+					return EXPR_ERROR_DIVBYZERO;
 #else
-                    *val = 0.0;
-                    return EXPR_ERROR_NOERROR;
+					*val = 0.0;
+					return EXPR_ERROR_NOERROR;
 #endif
-                    }
-                }
-            else
-                return err;
-
-            break;
-            }
-
-        case EXPR_NODETYPE_EXPONENT:
-            {
-            /* Exponent */
-            err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
-
-            if(!err)
-                err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
-
-            if(!err)
-                {
-                EXPR_RESET_ERR();
-                *val = pow(d1, d2);
-                EXPR_CHECK_ERR();
-                }
-            else
-                return err;
-
-            break;
-            }
-
-        case EXPR_NODETYPE_NEGATE:
-            {
-            /* Negative value */
-            err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
-
-            if(!err)
-                *val = -d1;
-            else
-                return err;
-           
-            break;
-            }
-
-
-        case EXPR_NODETYPE_VALUE:
-            {
-            /* Directly access the value */
-            *val = nodes->data.value.value;
-            break;
-            }
-
-        case EXPR_NODETYPE_VARIABLE:
-            {
-            /* Directly access the variable or constant */
-            *val = *(nodes->data.variable.vaddr);
-            break;
-            }
-
-        case EXPR_NODETYPE_ASSIGN:
-            {
-            /* Evaluate assignment subnode */
-            err = exprEvalNode(obj, nodes->data.assign.node, 0, val);
-
-            if(!err)
-                {
-                /* Directly assign the variable */
-                *(nodes->data.assign.vaddr) = *val;
-                }
-            else
-                return err;
-            
-            break;
-            }
-
-        case EXPR_NODETYPE_FUNCTION:
-            {
-            /* Evaluate the function */
-            if(nodes->data.function.fptr == NULL)
-                {
-                /* No function pointer means we are not using
-                   function solvers.  See if the function has a
-                   type to solve directly. */
-                switch(nodes->data.function.type)
-                    {
-                    /* This is to keep the file from being too crowded.
-                       See exprilfs.h for the definitions. */
+				}
+			} else
+				return err;
+
+			break;
+		}
+
+	case EXPR_NODETYPE_EXPONENT:
+		{
+			/* Exponent */
+			err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
+
+			if (!err)
+				err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
+
+			if (!err) {
+				EXPR_RESET_ERR();
+				*val = pow(d1, d2);
+				EXPR_CHECK_ERR();
+			} else
+				return err;
+
+			break;
+		}
+
+	case EXPR_NODETYPE_NEGATE:
+		{
+			/* Negative value */
+			err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
+
+			if (!err)
+				*val = -d1;
+			else
+				return err;
+
+			break;
+		}
+
+
+	case EXPR_NODETYPE_VALUE:
+		{
+			/* Directly access the value */
+			*val = nodes->data.value.value;
+			break;
+		}
+
+	case EXPR_NODETYPE_VARIABLE:
+		{
+			/* Directly access the variable or constant */
+			*val = *(nodes->data.variable.vaddr);
+			break;
+		}
+
+	case EXPR_NODETYPE_ASSIGN:
+		{
+			/* Evaluate assignment subnode */
+			err = exprEvalNode(obj, nodes->data.assign.node, 0, val);
+
+			if (!err) {
+				/* Directly assign the variable */
+				*(nodes->data.assign.vaddr) = *val;
+			} else
+				return err;
+
+			break;
+		}
+
+	case EXPR_NODETYPE_FUNCTION:
+		{
+			/* Evaluate the function */
+			if (nodes->data.function.fptr == NULL) {
+				/* No function pointer means we are not using
+				   function solvers.  See if the function has a
+				   type to solve directly. */
+				switch (nodes->data.function.type) {
+					/* This is to keep the file from being too crowded.
+					   See exprilfs.h for the definitions. */
 #include "exprilfs.h"
-                   
-
-                    default:
-                        {
-                        return EXPR_ERROR_UNKNOWN;
-                        }
-                    }
-                }
-            else
-                {
-                /* Call the correct function */
-                return (*(nodes->data.function.fptr))(obj,
-                    nodes->data.function.nodes, nodes->data.function.nodecount,
-                    nodes->data.function.refs, nodes->data.function.refcount, val);
-                }
-
-            break;
-            }
-
-        default:
-            {
-            /* Unknown node type */
-            return EXPR_ERROR_UNKNOWN;
-            }
-        }
-
-    return EXPR_ERROR_NOERROR;
-    }
 
 
+				default:
+					{
+						return EXPR_ERROR_UNKNOWN;
+					}
+				}
+			} else {
+				/* Call the correct function */
+				return (*(nodes->data.function.fptr)) (obj,
+													   nodes->data.function.nodes, nodes->data.function.nodecount,
+													   nodes->data.function.refs, nodes->data.function.refcount, val);
+			}
+
+			break;
+		}
+
+	default:
+		{
+			/* Unknown node type */
+			return EXPR_ERROR_UNKNOWN;
+		}
+	}
 
+	return EXPR_ERROR_NOERROR;
+}

Modified: freeswitch/trunk/src/mod/applications/mod_expr/exprfunc.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_expr/exprfunc.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_expr/exprfunc.c	Tue May 27 00:54:52 2008
@@ -17,313 +17,296 @@
 
 /* Internal functions */
 static exprFunc *exprCreateFunc(char *name, exprFuncType ptr, int type, int min, int max, int refmin, int refmax);
-static void exprFuncListFreeData(exprFunc *func);
+static void exprFuncListFreeData(exprFunc * func);
 
 
 /* This function creates the function list, */
-int exprFuncListCreate(exprFuncList **flist)
-    {
-    exprFuncList *tmp;
+int exprFuncListCreate(exprFuncList ** flist)
+{
+	exprFuncList *tmp;
 
-    if(flist == NULL)
-        return EXPR_ERROR_NULLPOINTER;
+	if (flist == NULL)
+		return EXPR_ERROR_NULLPOINTER;
 
-    *flist = NULL; /* Set to NULL initially */
+	*flist = NULL;				/* Set to NULL initially */
 
-    tmp = exprAllocMem(sizeof(exprFuncList));
+	tmp = exprAllocMem(sizeof(exprFuncList));
 
-    if(tmp == NULL)
-        return EXPR_ERROR_MEMORY; /* Could not allocate memory */
+	if (tmp == NULL)
+		return EXPR_ERROR_MEMORY;	/* Could not allocate memory */
 
-    /* Update pointer */
-    *flist = tmp;
+	/* Update pointer */
+	*flist = tmp;
 
-    return EXPR_ERROR_NOERROR;
-    }
+	return EXPR_ERROR_NOERROR;
+}
 
 /* Add a function to the list */
-int exprFuncListAdd(exprFuncList *flist, char *name, exprFuncType ptr, int min, int max, int refmin, int refmax)
-    {
-    exprFunc *tmp;
-    exprFunc *cur;
-    int result;
-
-    if(flist == NULL)
-        return EXPR_ERROR_NULLPOINTER;
-
-    /* Make sure the name is valid */
-    if(!exprValidIdent(name))
-        return EXPR_ERROR_BADIDENTIFIER;
-
-    /* Fix values only if none are negative (negative values mean no limit) */
-
-    /* if both are neg, no min or max number of args */
-    /* if min is neg, max pos, no min number of args but a maximum */
-    /* if min is pos, max neg, there is a min number of args, but no max */
-    /* if both pos, then a min and max limit.  We swap to make sure it works
-       right. I.E.  Min of 3 and max of 2 would make function unusable */
-    if(min >= 0 && max >= 0)
-        {
-        if(min > max)
-            {
-            result = min;
-            min = max;
-            max = result;
-            }
-        }
-
-    if(refmin >= 0 && refmax >= 0)
-        {
-        if(refmin > refmax)
-            {
-            result = refmin;
-            refmin = max;
-            refmax = result;
-            }
-        }
-
-    if(flist->head == NULL)
-        {
-        /* Create the node right here */
-        tmp = exprCreateFunc(name, ptr, EXPR_NODETYPE_FUNCTION, min, max, refmin, refmax);
-
-        if(tmp == NULL)
-            return EXPR_ERROR_MEMORY;
-
-        flist->head = tmp;
-        return EXPR_ERROR_NOERROR;
-        }
-
-    /* See if it already exists */
-    cur = flist->head;
-    
-    while(cur)
-        {
-        result = strcmp(name, cur->fname);
-        
-        if(result == 0)
-            return EXPR_ERROR_ALREADYEXISTS;
-            
-        cur = cur->next;
-        }
-        
-    /* It did not exist, so add it at the head */
-    tmp = exprCreateFunc(name, ptr, EXPR_NODETYPE_FUNCTION, min, max, refmin, refmax);
-        
-    if(tmp == NULL)
-        return EXPR_ERROR_MEMORY;
-            
-    tmp->next = flist->head;
-    flist->head = tmp;
-    return EXPR_ERROR_NOERROR;
-    }
+int exprFuncListAdd(exprFuncList * flist, char *name, exprFuncType ptr, int min, int max, int refmin, int refmax)
+{
+	exprFunc *tmp;
+	exprFunc *cur;
+	int result;
+
+	if (flist == NULL)
+		return EXPR_ERROR_NULLPOINTER;
+
+	/* Make sure the name is valid */
+	if (!exprValidIdent(name))
+		return EXPR_ERROR_BADIDENTIFIER;
+
+	/* Fix values only if none are negative (negative values mean no limit) */
+
+	/* if both are neg, no min or max number of args */
+	/* if min is neg, max pos, no min number of args but a maximum */
+	/* if min is pos, max neg, there is a min number of args, but no max */
+	/* if both pos, then a min and max limit.  We swap to make sure it works
+	   right. I.E.  Min of 3 and max of 2 would make function unusable */
+	if (min >= 0 && max >= 0) {
+		if (min > max) {
+			result = min;
+			min = max;
+			max = result;
+		}
+	}
+
+	if (refmin >= 0 && refmax >= 0) {
+		if (refmin > refmax) {
+			result = refmin;
+			refmin = max;
+			refmax = result;
+		}
+	}
+
+	if (flist->head == NULL) {
+		/* Create the node right here */
+		tmp = exprCreateFunc(name, ptr, EXPR_NODETYPE_FUNCTION, min, max, refmin, refmax);
+
+		if (tmp == NULL)
+			return EXPR_ERROR_MEMORY;
+
+		flist->head = tmp;
+		return EXPR_ERROR_NOERROR;
+	}
+
+	/* See if it already exists */
+	cur = flist->head;
+
+	while (cur) {
+		result = strcmp(name, cur->fname);
+
+		if (result == 0)
+			return EXPR_ERROR_ALREADYEXISTS;
+
+		cur = cur->next;
+	}
+
+	/* It did not exist, so add it at the head */
+	tmp = exprCreateFunc(name, ptr, EXPR_NODETYPE_FUNCTION, min, max, refmin, refmax);
+
+	if (tmp == NULL)
+		return EXPR_ERROR_MEMORY;
+
+	tmp->next = flist->head;
+	flist->head = tmp;
+	return EXPR_ERROR_NOERROR;
+}
 
 /* Add a function node type to the list
    This works pretty much the same way, except the function
    pointer is NULL and the node type specifies the function
    to do.  exprEvalNode handles this, instead of calling
    a function solver. */
-int exprFuncListAddType(exprFuncList *flist, char *name, int type, int min, int max, int refmin, int refmax)
-    {
-    exprFunc *tmp;
-    exprFunc *cur;
-    int result;
-
-    if(flist == NULL)
-        return EXPR_ERROR_NULLPOINTER;
-
-    /* Make sure the name is valid */
-    if(!exprValidIdent(name))
-        return EXPR_ERROR_BADIDENTIFIER;
-
-    /* Fix values only if none are negative (negative values mean no limit) */
-
-    /* if both are neg, no min or max number of args */
-    /* if min is neg, max pos, no min number of args but a maximum */
-    /* if min is pos, max neg, there is a min number of args, but no max */
-    /* if both pos, then a min and max limit.  We swap to make sure it works
-       right. I.E.  Min of 3 and max of 2 would make function unusable */
-    if(min >= 0 && max >= 0)
-        {
-        if(min > max)
-            {
-            result = min;
-            min = max;
-            max = result;
-            }
-        }
-
-    if(refmin >= 0 && refmax >= 0)
-        {
-        if(refmin > refmax)
-            {
-            result = refmin;
-            refmin = max;
-            refmax = result;
-            }
-        }
-
-    if(flist->head == NULL)
-        {
-        /* Create the node right here */
-        tmp = exprCreateFunc(name, NULL, type, min, max, refmin, refmax);
-
-        if(tmp == NULL)
-            return EXPR_ERROR_MEMORY;
-
-        flist->head = tmp;
-        return EXPR_ERROR_NOERROR;
-        }
-
-    /* See if it already exists */
-    cur = flist->head;
-    
-    while(cur)
-        {
-        result = strcmp(name, cur->fname);
-        
-        if(result == 0)
-            return EXPR_ERROR_ALREADYEXISTS;
-            
-        cur = cur->next;
-        }
-        
-    /* It did not exist, so add it at the head */
-    tmp = exprCreateFunc(name, NULL, type, min, max, refmin, refmax);
-    
-    if(tmp == NULL)
-        return EXPR_ERROR_MEMORY;
-        
-    tmp->next = flist->head;
-    flist->head = tmp;
-    return EXPR_ERROR_NOERROR;
-    }
+int exprFuncListAddType(exprFuncList * flist, char *name, int type, int min, int max, int refmin, int refmax)
+{
+	exprFunc *tmp;
+	exprFunc *cur;
+	int result;
+
+	if (flist == NULL)
+		return EXPR_ERROR_NULLPOINTER;
+
+	/* Make sure the name is valid */
+	if (!exprValidIdent(name))
+		return EXPR_ERROR_BADIDENTIFIER;
+
+	/* Fix values only if none are negative (negative values mean no limit) */
+
+	/* if both are neg, no min or max number of args */
+	/* if min is neg, max pos, no min number of args but a maximum */
+	/* if min is pos, max neg, there is a min number of args, but no max */
+	/* if both pos, then a min and max limit.  We swap to make sure it works
+	   right. I.E.  Min of 3 and max of 2 would make function unusable */
+	if (min >= 0 && max >= 0) {
+		if (min > max) {
+			result = min;
+			min = max;
+			max = result;
+		}
+	}
+
+	if (refmin >= 0 && refmax >= 0) {
+		if (refmin > refmax) {
+			result = refmin;
+			refmin = max;
+			refmax = result;
+		}
+	}
+
+	if (flist->head == NULL) {
+		/* Create the node right here */
+		tmp = exprCreateFunc(name, NULL, type, min, max, refmin, refmax);
+
+		if (tmp == NULL)
+			return EXPR_ERROR_MEMORY;
+
+		flist->head = tmp;
+		return EXPR_ERROR_NOERROR;
+	}
+
+	/* See if it already exists */
+	cur = flist->head;
+
+	while (cur) {
+		result = strcmp(name, cur->fname);
+
+		if (result == 0)
+			return EXPR_ERROR_ALREADYEXISTS;
+
+		cur = cur->next;
+	}
+
+	/* It did not exist, so add it at the head */
+	tmp = exprCreateFunc(name, NULL, type, min, max, refmin, refmax);
+
+	if (tmp == NULL)
+		return EXPR_ERROR_MEMORY;
+
+	tmp->next = flist->head;
+	flist->head = tmp;
+	return EXPR_ERROR_NOERROR;
+}
 
 
 /* Get the function from a list along with it's min an max data */
-int exprFuncListGet(exprFuncList *flist, char *name, exprFuncType *ptr, int *type, int *min, int *max, int *refmin, int *refmax)
-    {
-    exprFunc *cur;
-    int result;
-
-    if(flist == NULL)
-        return EXPR_ERROR_NULLPOINTER;
-
-    if(name == NULL || name[0] == '\0')
-        return EXPR_ERROR_NOTFOUND;
-
-    /* Search for the item */
-    cur = flist->head;
-    
-    while(cur)
-        {
-        result = strcmp(name, cur->fname);
-
-        if(result == 0)
-            {
-            /* We found it. */
-            *ptr = cur->fptr;
-            *min = cur->min;
-            *max = cur->max;
-            *refmin = cur->refmin;
-            *refmax = cur->refmax;
-            *type = cur->type;
-
-            /* return now */
-            return EXPR_ERROR_NOERROR;
-            }
-            
-        cur = cur->next;
-        }
-
-    /* If we got here, we did not find the item in the list */
-    return EXPR_ERROR_NOTFOUND;
-    }
+int exprFuncListGet(exprFuncList * flist, char *name, exprFuncType * ptr, int *type, int *min, int *max, int *refmin, int *refmax)
+{
+	exprFunc *cur;
+	int result;
+
+	if (flist == NULL)
+		return EXPR_ERROR_NULLPOINTER;
+
+	if (name == NULL || name[0] == '\0')
+		return EXPR_ERROR_NOTFOUND;
+
+	/* Search for the item */
+	cur = flist->head;
+
+	while (cur) {
+		result = strcmp(name, cur->fname);
+
+		if (result == 0) {
+			/* We found it. */
+			*ptr = cur->fptr;
+			*min = cur->min;
+			*max = cur->max;
+			*refmin = cur->refmin;
+			*refmax = cur->refmax;
+			*type = cur->type;
+
+			/* return now */
+			return EXPR_ERROR_NOERROR;
+		}
+
+		cur = cur->next;
+	}
+
+	/* If we got here, we did not find the item in the list */
+	return EXPR_ERROR_NOTFOUND;
+}
 
 /* This routine will free the function list */
-int exprFuncListFree(exprFuncList *flist)
-    {
-    /* Make sure it exists, if not it is not error */
-    if(flist == NULL)
-        return EXPR_ERROR_NOERROR;
+int exprFuncListFree(exprFuncList * flist)
+{
+	/* Make sure it exists, if not it is not error */
+	if (flist == NULL)
+		return EXPR_ERROR_NOERROR;
 
-    /* Free the nodes */
-    exprFuncListFreeData(flist->head);
+	/* Free the nodes */
+	exprFuncListFreeData(flist->head);
 
-    /* Free the container */
-    exprFreeMem(flist);
+	/* Free the container */
+	exprFreeMem(flist);
 
-    return EXPR_ERROR_NOERROR;
-    }
+	return EXPR_ERROR_NOERROR;
+}
 
 /* This routine will clear the function list */
-int exprFuncListClear(exprFuncList *flist)
-    {
-    if(flist == NULL)
-        return EXPR_ERROR_NOERROR;
-
-    /* Free the nodes only */
-    if(flist->head)
-        {
-        exprFuncListFreeData(flist->head);
+int exprFuncListClear(exprFuncList * flist)
+{
+	if (flist == NULL)
+		return EXPR_ERROR_NOERROR;
+
+	/* Free the nodes only */
+	if (flist->head) {
+		exprFuncListFreeData(flist->head);
 
-        flist->head = NULL;
-        }
+		flist->head = NULL;
+	}
 
-    return EXPR_ERROR_NOERROR;
-    }
+	return EXPR_ERROR_NOERROR;
+}
 
 /* This routine will free any child nodes, and then free itself */
-void exprFuncListFreeData(exprFunc *func)
-    {
-    exprFunc *next;
-    
-    while(func)
-        {
-        /* Remember the next item */
-        next = func->next;
-
-        /* Free name */
-        exprFreeMem(func->fname);
-
-        /* Free ourself */
-        exprFreeMem(func);
-        
-        func = next;
-        }
-    }
+void exprFuncListFreeData(exprFunc * func)
+{
+	exprFunc *next;
+
+	while (func) {
+		/* Remember the next item */
+		next = func->next;
+
+		/* Free name */
+		exprFreeMem(func->fname);
+
+		/* Free ourself */
+		exprFreeMem(func);
+
+		func = next;
+	}
+}
 
 /* This routine will create the function object */
 exprFunc *exprCreateFunc(char *name, exprFuncType ptr, int type, int min, int max, int refmin, int refmax)
-    {
-    exprFunc *tmp;
-    char *vtmp;
-
-    /* We already checked the name in exprFuncListAdd */
-
-    /* Create it */
-    tmp = exprAllocMem(sizeof(exprFunc));
-    if(tmp == NULL)
-        return NULL;
-
-    /* Allocate space for the name */
-    vtmp = exprAllocMem(strlen(name) + 1);
-
-    if(vtmp == NULL)
-        {
-        exprFreeMem(tmp);
-        return NULL;
-        }
-
-    /* Copy the data over */
-    strcpy(vtmp, name);
-    tmp->fname = vtmp;
-    tmp->fptr = ptr;
-    tmp->min = min;
-    tmp->max = max;
-    tmp->refmin = refmin;
-    tmp->refmax = refmax;
-    tmp->type = type;
+{
+	exprFunc *tmp;
+	char *vtmp;
+
+	/* We already checked the name in exprFuncListAdd */
+
+	/* Create it */
+	tmp = exprAllocMem(sizeof(exprFunc));
+	if (tmp == NULL)
+		return NULL;
+
+	/* Allocate space for the name */
+	vtmp = exprAllocMem(strlen(name) + 1);
+
+	if (vtmp == NULL) {
+		exprFreeMem(tmp);
+		return NULL;
+	}
+
+	/* Copy the data over */
+	strcpy(vtmp, name);
+	tmp->fname = vtmp;
+	tmp->fptr = ptr;
+	tmp->min = min;
+	tmp->max = max;
+	tmp->refmin = refmin;
+	tmp->refmax = refmax;
+	tmp->type = type;
 
-    return tmp;
-    }
+	return tmp;
+}

Modified: freeswitch/trunk/src/mod/applications/mod_expr/exprinit.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_expr/exprinit.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_expr/exprinit.c	Tue May 27 00:54:52 2008
@@ -26,90 +26,88 @@
     return err;
 
 /* Call this function to initialize these functions into a function list */
-int exprFuncListInit(exprFuncList *flist)
-    {
-    int err;
-
-    if(flist == NULL)
-        return EXPR_ERROR_NULLPOINTER;
-
-    EXPR_ADDFUNC_TYPE("abs", EXPR_NODEFUNC_ABS, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("mod", EXPR_NODEFUNC_MOD, 2, 2, 0, 0);
-    EXPR_ADDFUNC_TYPE("ipart", EXPR_NODEFUNC_IPART, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("fpart", EXPR_NODEFUNC_FPART, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("min", EXPR_NODEFUNC_MIN, 1, -1, 0, 0);
-    EXPR_ADDFUNC_TYPE("max", EXPR_NODEFUNC_MAX, 1, -1, 0, 0);
-    EXPR_ADDFUNC_TYPE("pow", EXPR_NODEFUNC_POW, 2, 2, 0, 0);
-    EXPR_ADDFUNC_TYPE("sqrt", EXPR_NODEFUNC_SQRT, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("sin", EXPR_NODEFUNC_SIN, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("sinh", EXPR_NODEFUNC_SINH, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("asin", EXPR_NODEFUNC_ASIN, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("cos", EXPR_NODEFUNC_COS, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("cosh", EXPR_NODEFUNC_COSH, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("acos", EXPR_NODEFUNC_ACOS, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("tan", EXPR_NODEFUNC_TAN, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("tanh", EXPR_NODEFUNC_TANH, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("atan", EXPR_NODEFUNC_ATAN, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("atan2", EXPR_NODEFUNC_ATAN2, 2, 2, 0, 0);
-    EXPR_ADDFUNC_TYPE("log", EXPR_NODEFUNC_LOG, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("pow10", EXPR_NODEFUNC_POW10, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("ln", EXPR_NODEFUNC_LN, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("exp", EXPR_NODEFUNC_EXP, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("logn", EXPR_NODEFUNC_LOGN, 2, 2, 0, 0);
-    EXPR_ADDFUNC_TYPE("ceil", EXPR_NODEFUNC_CEIL, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("floor", EXPR_NODEFUNC_FLOOR, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("rand", EXPR_NODEFUNC_RAND, 0, 0, 1, 1);
-    EXPR_ADDFUNC_TYPE("random", EXPR_NODEFUNC_RANDOM, 2, 2, 1, 1);
-    EXPR_ADDFUNC_TYPE("randomize", EXPR_NODEFUNC_RANDOMIZE, 0, 0, 1, 1);
-    EXPR_ADDFUNC_TYPE("deg", EXPR_NODEFUNC_DEG, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("rad", EXPR_NODEFUNC_RAD, 1, 1, 0, 0);
-    EXPR_ADDFUNC_TYPE("recttopolr", EXPR_NODEFUNC_RECTTOPOLR, 2, 2, 0, 0);
-    EXPR_ADDFUNC_TYPE("recttopola", EXPR_NODEFUNC_RECTTOPOLA, 2, 2, 0, 0);
-    EXPR_ADDFUNC_TYPE("poltorectx", EXPR_NODEFUNC_POLTORECTX, 2, 2, 0, 0);
-    EXPR_ADDFUNC_TYPE("poltorecty", EXPR_NODEFUNC_POLTORECTY, 2, 2, 0, 0);
-    EXPR_ADDFUNC_TYPE("if", EXPR_NODEFUNC_IF, 3, 3, 0, 0);
-    EXPR_ADDFUNC_TYPE("select", EXPR_NODEFUNC_SELECT, 3, 4, 0, 0);
-    EXPR_ADDFUNC_TYPE("equal", EXPR_NODEFUNC_EQUAL, 2, 2, 0, 0);
-    EXPR_ADDFUNC_TYPE("above", EXPR_NODEFUNC_ABOVE, 2, 2, 0, 0);
-    EXPR_ADDFUNC_TYPE("below", EXPR_NODEFUNC_BELOW, 2, 2, 0, 0);
-    EXPR_ADDFUNC_TYPE("avg", EXPR_NODEFUNC_AVG, 1, -1, 0, 0);
-    EXPR_ADDFUNC_TYPE("clip", EXPR_NODEFUNC_CLIP, 3, 3, 0, 0);
-    EXPR_ADDFUNC_TYPE("clamp", EXPR_NODEFUNC_CLAMP, 3, 3, 0, 0);
-    EXPR_ADDFUNC_TYPE("pntchange", EXPR_NODEFUNC_PNTCHANGE, 5, 5, 0, 0);
-    EXPR_ADDFUNC_TYPE("poly", EXPR_NODEFUNC_POLY, 2, -1, 0, 0);
-    EXPR_ADDFUNC_TYPE("and", EXPR_NODEFUNC_AND, 2, 2, 0, 0);
-    EXPR_ADDFUNC_TYPE("or", EXPR_NODEFUNC_OR, 2, 2, 0, 0);
-    EXPR_ADDFUNC_TYPE("not", EXPR_NODEFUNC_NOT, 1 ,1, 0, 0);
-    EXPR_ADDFUNC_TYPE("for", EXPR_NODEFUNC_FOR, 4, -1, 0, 0);
-    EXPR_ADDFUNC_TYPE("many", EXPR_NODEFUNC_MANY, 1, -1, 0, 0);
+int exprFuncListInit(exprFuncList * flist)
+{
+	int err;
+
+	if (flist == NULL)
+		return EXPR_ERROR_NULLPOINTER;
+
+	EXPR_ADDFUNC_TYPE("abs", EXPR_NODEFUNC_ABS, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("mod", EXPR_NODEFUNC_MOD, 2, 2, 0, 0);
+	EXPR_ADDFUNC_TYPE("ipart", EXPR_NODEFUNC_IPART, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("fpart", EXPR_NODEFUNC_FPART, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("min", EXPR_NODEFUNC_MIN, 1, -1, 0, 0);
+	EXPR_ADDFUNC_TYPE("max", EXPR_NODEFUNC_MAX, 1, -1, 0, 0);
+	EXPR_ADDFUNC_TYPE("pow", EXPR_NODEFUNC_POW, 2, 2, 0, 0);
+	EXPR_ADDFUNC_TYPE("sqrt", EXPR_NODEFUNC_SQRT, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("sin", EXPR_NODEFUNC_SIN, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("sinh", EXPR_NODEFUNC_SINH, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("asin", EXPR_NODEFUNC_ASIN, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("cos", EXPR_NODEFUNC_COS, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("cosh", EXPR_NODEFUNC_COSH, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("acos", EXPR_NODEFUNC_ACOS, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("tan", EXPR_NODEFUNC_TAN, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("tanh", EXPR_NODEFUNC_TANH, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("atan", EXPR_NODEFUNC_ATAN, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("atan2", EXPR_NODEFUNC_ATAN2, 2, 2, 0, 0);
+	EXPR_ADDFUNC_TYPE("log", EXPR_NODEFUNC_LOG, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("pow10", EXPR_NODEFUNC_POW10, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("ln", EXPR_NODEFUNC_LN, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("exp", EXPR_NODEFUNC_EXP, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("logn", EXPR_NODEFUNC_LOGN, 2, 2, 0, 0);
+	EXPR_ADDFUNC_TYPE("ceil", EXPR_NODEFUNC_CEIL, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("floor", EXPR_NODEFUNC_FLOOR, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("rand", EXPR_NODEFUNC_RAND, 0, 0, 1, 1);
+	EXPR_ADDFUNC_TYPE("random", EXPR_NODEFUNC_RANDOM, 2, 2, 1, 1);
+	EXPR_ADDFUNC_TYPE("randomize", EXPR_NODEFUNC_RANDOMIZE, 0, 0, 1, 1);
+	EXPR_ADDFUNC_TYPE("deg", EXPR_NODEFUNC_DEG, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("rad", EXPR_NODEFUNC_RAD, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("recttopolr", EXPR_NODEFUNC_RECTTOPOLR, 2, 2, 0, 0);
+	EXPR_ADDFUNC_TYPE("recttopola", EXPR_NODEFUNC_RECTTOPOLA, 2, 2, 0, 0);
+	EXPR_ADDFUNC_TYPE("poltorectx", EXPR_NODEFUNC_POLTORECTX, 2, 2, 0, 0);
+	EXPR_ADDFUNC_TYPE("poltorecty", EXPR_NODEFUNC_POLTORECTY, 2, 2, 0, 0);
+	EXPR_ADDFUNC_TYPE("if", EXPR_NODEFUNC_IF, 3, 3, 0, 0);
+	EXPR_ADDFUNC_TYPE("select", EXPR_NODEFUNC_SELECT, 3, 4, 0, 0);
+	EXPR_ADDFUNC_TYPE("equal", EXPR_NODEFUNC_EQUAL, 2, 2, 0, 0);
+	EXPR_ADDFUNC_TYPE("above", EXPR_NODEFUNC_ABOVE, 2, 2, 0, 0);
+	EXPR_ADDFUNC_TYPE("below", EXPR_NODEFUNC_BELOW, 2, 2, 0, 0);
+	EXPR_ADDFUNC_TYPE("avg", EXPR_NODEFUNC_AVG, 1, -1, 0, 0);
+	EXPR_ADDFUNC_TYPE("clip", EXPR_NODEFUNC_CLIP, 3, 3, 0, 0);
+	EXPR_ADDFUNC_TYPE("clamp", EXPR_NODEFUNC_CLAMP, 3, 3, 0, 0);
+	EXPR_ADDFUNC_TYPE("pntchange", EXPR_NODEFUNC_PNTCHANGE, 5, 5, 0, 0);
+	EXPR_ADDFUNC_TYPE("poly", EXPR_NODEFUNC_POLY, 2, -1, 0, 0);
+	EXPR_ADDFUNC_TYPE("and", EXPR_NODEFUNC_AND, 2, 2, 0, 0);
+	EXPR_ADDFUNC_TYPE("or", EXPR_NODEFUNC_OR, 2, 2, 0, 0);
+	EXPR_ADDFUNC_TYPE("not", EXPR_NODEFUNC_NOT, 1, 1, 0, 0);
+	EXPR_ADDFUNC_TYPE("for", EXPR_NODEFUNC_FOR, 4, -1, 0, 0);
+	EXPR_ADDFUNC_TYPE("many", EXPR_NODEFUNC_MANY, 1, -1, 0, 0);
 
-    return EXPR_ERROR_NOERROR;
-    }
+	return EXPR_ERROR_NOERROR;
+}
 
 /* Call this function to initialize some constants into a value list */
-int exprValListInit(exprValList *vlist)
-    {
-    int err;
-
-    if(vlist == NULL)
-        return EXPR_ERROR_NULLPOINTER;
-
-    EXPR_ADDCONST("M_E", M_E);
-    EXPR_ADDCONST("M_LOG2E", M_LOG2E);
-    EXPR_ADDCONST("M_LOG10E", M_LOG10E);
-    EXPR_ADDCONST("M_LN2", M_LN2);
-    EXPR_ADDCONST("M_LN10", M_LN10);
-    EXPR_ADDCONST("M_PI", M_PI);
-    EXPR_ADDCONST("M_PI_2", M_PI_2);
-    EXPR_ADDCONST("M_PI_4", M_PI_4);
-    EXPR_ADDCONST("M_1_PI", M_1_PI);
-    EXPR_ADDCONST("M_2_PI", M_2_PI);
-    EXPR_ADDCONST("M_1_SQRTPI", M_1_SQRTPI);
-    EXPR_ADDCONST("M_2_SQRTPI", M_2_SQRTPI);
-    EXPR_ADDCONST("M_SQRT2", M_SQRT2);
-    EXPR_ADDCONST("M_1_SQRT2", M_1_SQRT2);
-
-    return EXPR_ERROR_NOERROR;
-    }
-
+int exprValListInit(exprValList * vlist)
+{
+	int err;
+
+	if (vlist == NULL)
+		return EXPR_ERROR_NULLPOINTER;
+
+	EXPR_ADDCONST("M_E", M_E);
+	EXPR_ADDCONST("M_LOG2E", M_LOG2E);
+	EXPR_ADDCONST("M_LOG10E", M_LOG10E);
+	EXPR_ADDCONST("M_LN2", M_LN2);
+	EXPR_ADDCONST("M_LN10", M_LN10);
+	EXPR_ADDCONST("M_PI", M_PI);
+	EXPR_ADDCONST("M_PI_2", M_PI_2);
+	EXPR_ADDCONST("M_PI_4", M_PI_4);
+	EXPR_ADDCONST("M_1_PI", M_1_PI);
+	EXPR_ADDCONST("M_2_PI", M_2_PI);
+	EXPR_ADDCONST("M_1_SQRTPI", M_1_SQRTPI);
+	EXPR_ADDCONST("M_2_SQRTPI", M_2_SQRTPI);
+	EXPR_ADDCONST("M_SQRT2", M_SQRT2);
+	EXPR_ADDCONST("M_1_SQRT2", M_1_SQRT2);
 
+	return EXPR_ERROR_NOERROR;
+}

Modified: freeswitch/trunk/src/mod/applications/mod_expr/exprmem.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_expr/exprmem.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_expr/exprmem.c	Tue May 27 00:54:52 2008
@@ -13,27 +13,26 @@
 #include "exprmem.h"
 
 /* Allocate memory and zero it */
-void* exprAllocMem(size_t size)
-    {
-    void *data = malloc(size);
-    
-    if(data)
-        {
-        memset(data, 0, size);
-        }
-    
-    return data;
-    }
+void *exprAllocMem(size_t size)
+{
+	void *data = malloc(size);
+
+	if (data) {
+		memset(data, 0, size);
+	}
+
+	return data;
+}
 
 /* Free memory */
 void exprFreeMem(void *data)
-    {
-    if(data)
-        free(data);
-    }
+{
+	if (data)
+		free(data);
+}
 
 /* Allocate a list of nodes */
 exprNode *exprAllocNodes(size_t count)
-    {
-    return exprAllocMem(count * sizeof(exprNode));
-    }
+{
+	return exprAllocMem(count * sizeof(exprNode));
+}

Modified: freeswitch/trunk/src/mod/applications/mod_expr/exprobj.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_expr/exprobj.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_expr/exprobj.c	Tue May 27 00:54:52 2008
@@ -14,224 +14,215 @@
 #include "exprmem.h"
 
 /* Internal functions */
-static void exprFreeNodeData(exprNode *node);
+static void exprFreeNodeData(exprNode * node);
 
 
 /* Function to create an expression object */
-int exprCreate(exprObj **obj, exprFuncList *flist, exprValList *vlist, exprValList *clist,
-    exprBreakFuncType breaker, void *userdata)
-    {
-    exprObj *tmp;
-
-    /* Allocate memory for the object */
-    tmp = exprAllocMem(sizeof(exprObj));
-
-    if(tmp == NULL)
-        return EXPR_ERROR_MEMORY;
-
-
-    /* Assign data */
-    tmp->flist = flist;
-    tmp->vlist = vlist;
-    tmp->clist = clist;
-    tmp->breakerfunc = breaker;
-    tmp->userdata = userdata;
-    tmp->breakcount = 100000; /* Default breaker count setting */
-    tmp->breakcur = 0;
+int exprCreate(exprObj ** obj, exprFuncList * flist, exprValList * vlist, exprValList * clist, exprBreakFuncType breaker, void *userdata)
+{
+	exprObj *tmp;
+
+	/* Allocate memory for the object */
+	tmp = exprAllocMem(sizeof(exprObj));
+
+	if (tmp == NULL)
+		return EXPR_ERROR_MEMORY;
+
+
+	/* Assign data */
+	tmp->flist = flist;
+	tmp->vlist = vlist;
+	tmp->clist = clist;
+	tmp->breakerfunc = breaker;
+	tmp->userdata = userdata;
+	tmp->breakcount = 100000;	/* Default breaker count setting */
+	tmp->breakcur = 0;
 
-    /* Update pointer */
-    *obj = tmp;
+	/* Update pointer */
+	*obj = tmp;
 
-    return EXPR_ERROR_NOERROR;
-    }
+	return EXPR_ERROR_NOERROR;
+}
 
 
 /* Free the expression */
-int exprFree(exprObj *obj)
-    {
-    if(obj == NULL)
-        return EXPR_ERROR_NOERROR;
-
-    /* First free the node data */
-    exprFreeNodeData(obj->headnode);
-    exprFreeMem(obj->headnode);
+int exprFree(exprObj * obj)
+{
+	if (obj == NULL)
+		return EXPR_ERROR_NOERROR;
+
+	/* First free the node data */
+	exprFreeNodeData(obj->headnode);
+	exprFreeMem(obj->headnode);
 
-    /* Free ourself */
-    exprFreeMem(obj);
+	/* Free ourself */
+	exprFreeMem(obj);
 
-    return EXPR_ERROR_NOERROR;
-    }
+	return EXPR_ERROR_NOERROR;
+}
 
 /* Clear expression, keep lists, etc */
-int exprClear(exprObj *obj)
-    {
-    if(obj == NULL)
-        return EXPR_ERROR_NOERROR;
-
-    /* Free the node data only, keep function, variable, constant lists */
-    exprFreeNodeData(obj->headnode);
-    exprFreeMem(obj->headnode);
-
-    obj->headnode = NULL;
-    obj->parsedbad = 0;
-    obj->parsedgood = 0;
+int exprClear(exprObj * obj)
+{
+	if (obj == NULL)
+		return EXPR_ERROR_NOERROR;
+
+	/* Free the node data only, keep function, variable, constant lists */
+	exprFreeNodeData(obj->headnode);
+	exprFreeMem(obj->headnode);
+
+	obj->headnode = NULL;
+	obj->parsedbad = 0;
+	obj->parsedgood = 0;
 
-    return EXPR_ERROR_NOERROR;
-    }
+	return EXPR_ERROR_NOERROR;
+}
 
 
 /* Get functions to get information about the expression object */
 
 /* Get the function list */
-exprFuncList *exprGetFuncList(exprObj *obj)
-    {
-    return (obj == NULL) ? NULL : obj->flist;
-    }
+exprFuncList *exprGetFuncList(exprObj * obj)
+{
+	return (obj == NULL) ? NULL : obj->flist;
+}
 
 /* Get the variable list */
-exprValList *exprGetVarList(exprObj *obj)
-    {
-    return (obj == NULL) ? NULL : obj->vlist;
-    }
+exprValList *exprGetVarList(exprObj * obj)
+{
+	return (obj == NULL) ? NULL : obj->vlist;
+}
 
 /* Get the constant list */
-exprValList *exprGetConstList(exprObj *obj)
-    {
-    return (obj == NULL) ? NULL : obj->clist;
-    }
+exprValList *exprGetConstList(exprObj * obj)
+{
+	return (obj == NULL) ? NULL : obj->clist;
+}
 
 /* Get the breaker function */
-exprBreakFuncType exprGetBreakFunc(exprObj *obj)
-    {
-    return (obj == NULL) ? NULL : obj->breakerfunc;
-    }
+exprBreakFuncType exprGetBreakFunc(exprObj * obj)
+{
+	return (obj == NULL) ? NULL : obj->breakerfunc;
+}
 
 /* Check for break status */
-int exprGetBreakResult(exprObj *obj)
-    {
-    if(obj == NULL)
-        return 0;
+int exprGetBreakResult(exprObj * obj)
+{
+	if (obj == NULL)
+		return 0;
 
-    if(obj->breakerfunc == NULL)
-        return 0;
+	if (obj->breakerfunc == NULL)
+		return 0;
 
-    return (*(obj->breakerfunc))(obj);
-    }
+	return (*(obj->breakerfunc)) (obj);
+}
 
 /* Get the user data */
-void *exprGetUserData(exprObj *obj)
-    {
-    return (obj == NULL) ? NULL : obj->userdata;
-    }
+void *exprGetUserData(exprObj * obj)
+{
+	return (obj == NULL) ? NULL : obj->userdata;
+}
 
 
 /* Set functions to set certain data */
 
 /* Set user data */
-void exprSetUserData(exprObj *obj, void *userdata)
-    {
-    if(obj)
-        obj->userdata = userdata;
-    }
+void exprSetUserData(exprObj * obj, void *userdata)
+{
+	if (obj)
+		obj->userdata = userdata;
+}
 
 
 /* Set breaker count */
-void exprSetBreakCount(exprObj *obj, int count)
-    {
-    if(obj)
-        {
-        /* If count is negative, make it positive */
-        if(count < 0)
-            count = -count;
-
-        obj->breakcount = count;
-
-        /* Make sure the current value is not bigger than count */
-        if(obj->breakcur > count)
-            obj->breakcur = count;
-        }
-    }
+void exprSetBreakCount(exprObj * obj, int count)
+{
+	if (obj) {
+		/* If count is negative, make it positive */
+		if (count < 0)
+			count = -count;
+
+		obj->breakcount = count;
+
+		/* Make sure the current value is not bigger than count */
+		if (obj->breakcur > count)
+			obj->breakcur = count;
+	}
+}
 
 /* Get error position */
-void exprGetErrorPosition(exprObj *obj, int *start, int *end)
-    {
-    if(obj)
-        {
-        if(start)
-            *start = obj->starterr;
-
-        if(end)
-            *end = obj->enderr;
-        }
-    }
+void exprGetErrorPosition(exprObj * obj, int *start, int *end)
+{
+	if (obj) {
+		if (start)
+			*start = obj->starterr;
+
+		if (end)
+			*end = obj->enderr;
+	}
+}
 
 /* This function will free a node's data */
-static void exprFreeNodeData(exprNode *node)
-    {
-    int pos;
-
-    if(node == NULL)
-        return;
-
-    /* free data based on type */
-    switch(node->type)
-        {
-        case EXPR_NODETYPE_ADD:
-        case EXPR_NODETYPE_SUBTRACT:
-        case EXPR_NODETYPE_MULTIPLY:
-        case EXPR_NODETYPE_DIVIDE:
-        case EXPR_NODETYPE_EXPONENT:
-        case EXPR_NODETYPE_NEGATE:
-        case EXPR_NODETYPE_MULTI:
-            /* Free operation data */
-            if(node->data.oper.nodes)
-                {
-                for(pos = 0; pos < node->data.oper.nodecount; pos++)
-                    exprFreeNodeData(&(node->data.oper.nodes[pos]));
-
-                exprFreeMem(node->data.oper.nodes);
-                }
-
-            break;
-
-
-        case EXPR_NODETYPE_VALUE:
-            /* Nothing to free for value */
-            break;
-
-        case EXPR_NODETYPE_VARIABLE:
-            /* Nothing to free for variable */
-            break;
-
-        case EXPR_NODETYPE_FUNCTION:
-            /* Free data of each subnode */
-            if(node->data.function.nodes)
-                {
-                for(pos = 0; pos < node->data.function.nodecount; pos++)
-                    exprFreeNodeData(&(node->data.function.nodes[pos]));
-
-                /* Free the subnode array */
-                exprFreeMem(node->data.function.nodes);
-                }
-
-            /* Free reference variable list */
-            if(node->data.function.refs)
-                exprFreeMem(node->data.function.refs);
-
-            break;
-
-        case EXPR_NODETYPE_ASSIGN:
-            /* Free subnode data */
-            if(node->data.assign.node)
-                {
-                exprFreeNodeData(node->data.assign.node);
-
-                /* Free the subnode */
-                exprFreeMem(node->data.assign.node);
-                }
-
-            break;
-        }
-    }
-
-
+static void exprFreeNodeData(exprNode * node)
+{
+	int pos;
+
+	if (node == NULL)
+		return;
+
+	/* free data based on type */
+	switch (node->type) {
+	case EXPR_NODETYPE_ADD:
+	case EXPR_NODETYPE_SUBTRACT:
+	case EXPR_NODETYPE_MULTIPLY:
+	case EXPR_NODETYPE_DIVIDE:
+	case EXPR_NODETYPE_EXPONENT:
+	case EXPR_NODETYPE_NEGATE:
+	case EXPR_NODETYPE_MULTI:
+		/* Free operation data */
+		if (node->data.oper.nodes) {
+			for (pos = 0; pos < node->data.oper.nodecount; pos++)
+				exprFreeNodeData(&(node->data.oper.nodes[pos]));
+
+			exprFreeMem(node->data.oper.nodes);
+		}
+
+		break;
+
+
+	case EXPR_NODETYPE_VALUE:
+		/* Nothing to free for value */
+		break;
+
+	case EXPR_NODETYPE_VARIABLE:
+		/* Nothing to free for variable */
+		break;
+
+	case EXPR_NODETYPE_FUNCTION:
+		/* Free data of each subnode */
+		if (node->data.function.nodes) {
+			for (pos = 0; pos < node->data.function.nodecount; pos++)
+				exprFreeNodeData(&(node->data.function.nodes[pos]));
+
+			/* Free the subnode array */
+			exprFreeMem(node->data.function.nodes);
+		}
+
+		/* Free reference variable list */
+		if (node->data.function.refs)
+			exprFreeMem(node->data.function.refs);
+
+		break;
+
+	case EXPR_NODETYPE_ASSIGN:
+		/* Free subnode data */
+		if (node->data.assign.node) {
+			exprFreeNodeData(node->data.assign.node);
+
+			/* Free the subnode */
+			exprFreeMem(node->data.assign.node);
+		}
+
+		break;
+	}
+}

Modified: freeswitch/trunk/src/mod/applications/mod_expr/exprpars.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_expr/exprpars.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_expr/exprpars.c	Tue May 27 00:54:52 2008
@@ -14,18 +14,16 @@
 #include "exprmem.h"
 
 /* Data structure used by parser */
-typedef struct _exprToken
-    {
-    int type; /* token type */
-    int start; /* token start position */
-    int end; /* token end position */
-
-    union _tdata
-        {
-        char *str; /* string data */
-        EXPRTYPE val; /* value data */
-        } data;
-    } exprToken;
+typedef struct _exprToken {
+	int type;					/* token type */
+	int start;					/* token start position */
+	int end;					/* token end position */
+
+	union _tdata {
+		char *str;				/* string data */
+		EXPRTYPE val;			/* value data */
+	} data;
+} exprToken;
 
 /* Defines for token types */
 #define EXPR_TOKEN_UNKNOWN 0
@@ -44,1515 +42,1378 @@
 #define EXPR_TOKEN_HAT 13
 
 /* Internal functions */
-int exprMultiParse(exprObj *obj, exprNode *node, exprToken *tokens, int count);
-int exprInternalParse(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end);
-int exprInternalParseAssign(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end, int index);
-int exprInternalParseAdd(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end, int index);
-int exprInternalParseSub(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end, int index);
-int exprInternalParseMul(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end, int index);
-int exprInternalParseDiv(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end, int index);
-int exprInternalParsePosNeg(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end, int index);
-int exprInternalParseExp(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end, int index);
-int exprInternalParseFunction(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end, int p1, int p2);
-int exprInternalParseVarVal(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end);
-int exprStringToTokenList(exprObj *obj, char *expr, exprToken **tokens, int *count);
-void exprFreeTokenList(exprToken *tokens, int count);
+int exprMultiParse(exprObj * obj, exprNode * node, exprToken * tokens, int count);
+int exprInternalParse(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end);
+int exprInternalParseAssign(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end, int index);
+int exprInternalParseAdd(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end, int index);
+int exprInternalParseSub(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end, int index);
+int exprInternalParseMul(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end, int index);
+int exprInternalParseDiv(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end, int index);
+int exprInternalParsePosNeg(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end, int index);
+int exprInternalParseExp(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end, int index);
+int exprInternalParseFunction(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end, int p1, int p2);
+int exprInternalParseVarVal(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end);
+int exprStringToTokenList(exprObj * obj, char *expr, exprToken ** tokens, int *count);
+void exprFreeTokenList(exprToken * tokens, int count);
 
 /* This frees a token list */
-void exprFreeTokenList(exprToken *tokens, int count)
-    {
-    int pos;
-
-    if(tokens == NULL)
-        return;
-
-    for(pos = 0; pos < count; pos++)
-        {
-        if(tokens[pos].type == EXPR_TOKEN_IDENTIFIER)
-            exprFreeMem(tokens[pos].data.str);
-        }
+void exprFreeTokenList(exprToken * tokens, int count)
+{
+	int pos;
+
+	if (tokens == NULL)
+		return;
+
+	for (pos = 0; pos < count; pos++) {
+		if (tokens[pos].type == EXPR_TOKEN_IDENTIFIER)
+			exprFreeMem(tokens[pos].data.str);
+	}
 
-    exprFreeMem(tokens);
-    }
+	exprFreeMem(tokens);
+}
 
 /* This converts an expression string to a token list */
-int exprStringToTokenList(exprObj *obj, char *expr, exprToken **tokens, int *count)
-    {
-    int found;
-    exprToken *list;
-    int pass;
-    int pos, len;
-    int tpos;
-    int comment; /* Is a comment active */
-    int start, ilen;
-    char buf[EXPR_MAXIDENTSIZE + 1];
-
-    /* Set initial variables */
-    found = 0;
-    tpos = 0;
-    list = NULL;
-    comment = 0;
-    *tokens = NULL;
-    *count = 0;
-
-
-    /* Check string length */
-    len = (int)strlen(expr);
-    if(len == 0)
-        return EXPR_ERROR_EMPTYEXPR;
-
-    /* Two passes, one to count, one to tokenize */
-    for(pass = 0; pass <= 1; pass++)
-        {
-        for(pos = 0; pos < len; pos++)
-            {
-            switch(expr[pos])
-                {
-                /* Comment */
-                case '#':
-                    {
-                    /* Only set it if a comment is not already active */
-                    if(!comment)
-                        comment = 1;
-
-                    break;
-                    }
-
-                /* Newline characters turn off comments */
-                case '\r':
-                case '\n':
-                    {
-                    /* If a comment is active, unset it */
-                    if(comment)
-                        comment = 0;
-
-                    break;
-                    }
-
-                /* Open parenthesis */
-                case '(':
-                    {
-                    if(!comment)
-                        {
-                        if(pass == 0)
-                            found++;
-                        else
-                            {
-                            list[tpos].type = EXPR_TOKEN_OPAREN;
-                            list[tpos].start = pos;
-                            list[tpos].end = pos;
-                            tpos++;
-                            }
-                        }
-
-                    break;
-                    }
-
-                /* Close parenthesis */
-                case ')':
-                    {
-                    if(!comment)
-                        {
-                        if(pass == 0)
-                            found++;
-                        else
-                            {
-                            list[tpos].type = EXPR_TOKEN_CPAREN;
-                            list[tpos].start = pos;
-                            list[tpos].end = pos;
-                            tpos++;
-                            }
-                        }
-
-                    break;
-                    }
-
-                /* Plus */
-                case '+':
-                    {
-                    if(!comment)
-                        {
-                        if(pass == 0)
-                            found++;
-                        else
-                            {
-                            list[tpos].type = EXPR_TOKEN_PLUS;
-                            list[tpos].start = pos;
-                            list[tpos].end = pos;
-                            tpos++;
-                            }
-                        }
-
-                    break;
-                    }
-
-                /* Hyphen */
-                case '-':
-                    {
-                    if(!comment)
-                        {
-                        if(pass == 0)
-                            found++;
-                        else
-                            {
-                            list[tpos].type = EXPR_TOKEN_HYPHEN;
-                            list[tpos].start = pos;
-                            list[tpos].end = pos;
-                            tpos++;
-                            }
-                        }
-
-                    break;
-                    }
-
-                /* Asterisk */
-                case '*':
-                    {
-                    if(!comment)
-                        {
-                        if(pass == 0)
-                            found++;
-                        else
-                            {
-                            list[tpos].type = EXPR_TOKEN_ASTERISK;
-                            list[tpos].start = pos;
-                            list[tpos].end = pos;
-                            tpos++;
-                            }
-                        }
-
-                    break;
-                    }
-
-                /* Forward slash */
-                case '/':
-                    {
-                    if(!comment)
-                        {
-                        if(pass == 0)
-                            found++;
-                        else
-                            {
-                            list[tpos].type = EXPR_TOKEN_FSLASH;
-                            list[tpos].start = pos;
-                            list[tpos].end = pos;
-                            tpos++;
-                            }
-                        }
-
-                    break;
-                    }
-
-                /* Hat */
-                case '^':
-                    {
-                    if(!comment)
-                        {
-                        if(pass == 0)
-                            found++;
-                        else
-                            {
-                            list[tpos].type = EXPR_TOKEN_HAT;
-                            list[tpos].start = pos;
-                            list[tpos].end = pos;
-                            tpos++;
-                            }
-                        }
-
-                    break;
-                    }
-
-                /* Ampersand */
-                case '&':
-                    {
-                    if(!comment)
-                        {
-                        if(pass == 0)
-                            found++;
-                        else
-                            {
-                            list[tpos].type = EXPR_TOKEN_AMPERSAND;
-                            list[tpos].start = pos;
-                            list[tpos].end = pos;
-                            tpos++;
-                            }
-                        }
-
-                    break;
-                    }
-
-                /* Semicolon */
-                case ';':
-                    {
-                    if(!comment)
-                        {
-                        if(pass == 0)
-                            found++;
-                        else
-                            {
-                            list[tpos].type = EXPR_TOKEN_SEMICOLON;
-                            list[tpos].start = pos;
-                            list[tpos].end = pos;
-                            tpos++;
-                            }
-                        }
-
-                    break;
-                    }
-
-                /* Comma */
-                case ',':
-                    {
-                    if(!comment)
-                        {
-                        if(pass == 0)
-                            found++;
-                        else
-                            {
-                            list[tpos].type = EXPR_TOKEN_COMMA;
-                            list[tpos].start = pos;
-                            list[tpos].end = pos;
-                            tpos++;
-                            }
-                        }
-
-                    break;
-                    }
-
-                /* Equal sign */
-                case '=':
-                    {
-                    if(!comment)
-                        {
-                        if(pass == 0)
-                            found++;
-                        else
-                            {
-                            list[tpos].type = EXPR_TOKEN_EQUAL;
-                            list[tpos].start = pos;
-                            list[tpos].end = pos;
-                            tpos++;
-                            }
-                        }
-
-                    break;
-                    }
-
-                /* Identifiers and values */
-                default:
-                    {
-                    if(!comment)
-                        {
-                        if(expr[pos] == '.' || isdigit(expr[pos]))
-                            {
-                            /* Value */
-                            start = pos;
-
-                            /* Find digits before a period */
-                            while(isdigit(expr[pos]))
-                                pos++;
-
-                            /* Find a period */
-                            if(expr[pos] == '.')
-                                pos++;
-
-                            /* Find digits after a period */
-                            while(isdigit(expr[pos]))
-                                pos++;
-
-                            /* pos is AFTER last item, back up */
-                            pos--;
-
-                            if(pass == 0)
-                                found++;
-                            else
-                                {
-                                ilen = pos - start + 1;
-
-                                /* Is the value to large */
-                                if(ilen > EXPR_MAXIDENTSIZE)
-                                    {
-                                    obj->starterr = start;
-                                    obj->enderr = pos;
-                                    exprFreeTokenList(list, found);
-                                    return EXPR_ERROR_BADIDENTIFIER;
-                                    }
-
-                                /* Create value token */
-                                strncpy(buf, expr + start, ilen);
-                                buf[ilen] = '\0';
-
-                                list[tpos].type = EXPR_TOKEN_VALUE;
-                                list[tpos].start = start;
-                                list[tpos].end = pos;
-                                list[tpos].data.val = (EXPRTYPE)atof(buf);
-                                tpos++;
-                                }
-                            }
-                        else if(expr[pos] == '_' || isalpha(expr[pos]))
-                            {
-                            /* Identifier */
-                            start = pos;
-
-                            /* Find rest of identifier */
-                            while(expr[pos] == '_' || isalnum(expr[pos]))
-                                pos++;
-
-                            /* pos is AFTER last item, back up */
-                            pos--;
-
-                            if(pass == 0)
-                                found++;
-                            else
-                                {
-                                ilen = pos - start + 1;
-
-                                /* Is the value to large */
-                                if(ilen > EXPR_MAXIDENTSIZE)
-                                    {
-                                    obj->starterr = start;
-                                    obj->enderr = pos;
-                                    exprFreeTokenList(list, found);
-                                    return EXPR_ERROR_BADIDENTIFIER;
-                                    }
-
-                                /* Create value token */
-                                strncpy(buf, expr + start, ilen);
-                                buf[ilen] = '\0';
-
-                                /* Allocate memory for identifier */
-                                list[tpos].data.str = exprAllocMem(ilen + 1);
-                                if(list[tpos].data.str == NULL)
-                                    {
-                                    exprFreeTokenList(list, found);
-                                    return EXPR_ERROR_MEMORY;
-                                    }
-
-                                list[tpos].type = EXPR_TOKEN_IDENTIFIER;
-                                list[tpos].start = start;
-                                list[tpos].end = pos;
-                                strcpy(list[tpos].data.str, buf);
-                                tpos++;
-                                }
-                            }
-                        else if(isspace(expr[pos]))
-                            {
-                            /* Spaces are ignored, do nothing */
-                            }
-                        else
-                            {
-                            /* Unknown */
-                            obj->starterr = obj->enderr = pos;
-                            exprFreeTokenList(list, found);
-                            return EXPR_ERROR_INVALIDCHAR;
-                            }
-                        }
-
-                    break;
-                    }
-                }
-            }
-
-        /* If pass is 0, allocate memory for next pass */
-        if(pass == 0)
-            {
-            /* First, make sure all comments were ended */
-            if(comment)
-                comment = 0;
-
-            /* Make sure the expression is not empty */
-            if(found == 0)
-                return EXPR_ERROR_EMPTYEXPR;
-
-            /* Allocate memory for token list */
-            list = exprAllocMem(found * sizeof(exprToken));
-            if(list == NULL)
-                return EXPR_ERROR_MEMORY;
-
-            tpos = 0;
-            }
-        }
-
-    *count = found;
-    *tokens = list;
-    return EXPR_ERROR_NOERROR;
-    }
+int exprStringToTokenList(exprObj * obj, char *expr, exprToken ** tokens, int *count)
+{
+	int found;
+	exprToken *list;
+	int pass;
+	int pos, len;
+	int tpos;
+	int comment;				/* Is a comment active */
+	int start, ilen;
+	char buf[EXPR_MAXIDENTSIZE + 1];
+
+	/* Set initial variables */
+	found = 0;
+	tpos = 0;
+	list = NULL;
+	comment = 0;
+	*tokens = NULL;
+	*count = 0;
+
+
+	/* Check string length */
+	len = (int) strlen(expr);
+	if (len == 0)
+		return EXPR_ERROR_EMPTYEXPR;
+
+	/* Two passes, one to count, one to tokenize */
+	for (pass = 0; pass <= 1; pass++) {
+		for (pos = 0; pos < len; pos++) {
+			switch (expr[pos]) {
+				/* Comment */
+			case '#':
+				{
+					/* Only set it if a comment is not already active */
+					if (!comment)
+						comment = 1;
+
+					break;
+				}
+
+				/* Newline characters turn off comments */
+			case '\r':
+			case '\n':
+				{
+					/* If a comment is active, unset it */
+					if (comment)
+						comment = 0;
+
+					break;
+				}
+
+				/* Open parenthesis */
+			case '(':
+				{
+					if (!comment) {
+						if (pass == 0)
+							found++;
+						else {
+							list[tpos].type = EXPR_TOKEN_OPAREN;
+							list[tpos].start = pos;
+							list[tpos].end = pos;
+							tpos++;
+						}
+					}
+
+					break;
+				}
+
+				/* Close parenthesis */
+			case ')':
+				{
+					if (!comment) {
+						if (pass == 0)
+							found++;
+						else {
+							list[tpos].type = EXPR_TOKEN_CPAREN;
+							list[tpos].start = pos;
+							list[tpos].end = pos;
+							tpos++;
+						}
+					}
+
+					break;
+				}
+
+				/* Plus */
+			case '+':
+				{
+					if (!comment) {
+						if (pass == 0)
+							found++;
+						else {
+							list[tpos].type = EXPR_TOKEN_PLUS;
+							list[tpos].start = pos;
+							list[tpos].end = pos;
+							tpos++;
+						}
+					}
+
+					break;
+				}
+
+				/* Hyphen */
+			case '-':
+				{
+					if (!comment) {
+						if (pass == 0)
+							found++;
+						else {
+							list[tpos].type = EXPR_TOKEN_HYPHEN;
+							list[tpos].start = pos;
+							list[tpos].end = pos;
+							tpos++;
+						}
+					}
+
+					break;
+				}
+
+				/* Asterisk */
+			case '*':
+				{
+					if (!comment) {
+						if (pass == 0)
+							found++;
+						else {
+							list[tpos].type = EXPR_TOKEN_ASTERISK;
+							list[tpos].start = pos;
+							list[tpos].end = pos;
+							tpos++;
+						}
+					}
+
+					break;
+				}
+
+				/* Forward slash */
+			case '/':
+				{
+					if (!comment) {
+						if (pass == 0)
+							found++;
+						else {
+							list[tpos].type = EXPR_TOKEN_FSLASH;
+							list[tpos].start = pos;
+							list[tpos].end = pos;
+							tpos++;
+						}
+					}
+
+					break;
+				}
+
+				/* Hat */
+			case '^':
+				{
+					if (!comment) {
+						if (pass == 0)
+							found++;
+						else {
+							list[tpos].type = EXPR_TOKEN_HAT;
+							list[tpos].start = pos;
+							list[tpos].end = pos;
+							tpos++;
+						}
+					}
+
+					break;
+				}
+
+				/* Ampersand */
+			case '&':
+				{
+					if (!comment) {
+						if (pass == 0)
+							found++;
+						else {
+							list[tpos].type = EXPR_TOKEN_AMPERSAND;
+							list[tpos].start = pos;
+							list[tpos].end = pos;
+							tpos++;
+						}
+					}
+
+					break;
+				}
+
+				/* Semicolon */
+			case ';':
+				{
+					if (!comment) {
+						if (pass == 0)
+							found++;
+						else {
+							list[tpos].type = EXPR_TOKEN_SEMICOLON;
+							list[tpos].start = pos;
+							list[tpos].end = pos;
+							tpos++;
+						}
+					}
+
+					break;
+				}
+
+				/* Comma */
+			case ',':
+				{
+					if (!comment) {
+						if (pass == 0)
+							found++;
+						else {
+							list[tpos].type = EXPR_TOKEN_COMMA;
+							list[tpos].start = pos;
+							list[tpos].end = pos;
+							tpos++;
+						}
+					}
+
+					break;
+				}
+
+				/* Equal sign */
+			case '=':
+				{
+					if (!comment) {
+						if (pass == 0)
+							found++;
+						else {
+							list[tpos].type = EXPR_TOKEN_EQUAL;
+							list[tpos].start = pos;
+							list[tpos].end = pos;
+							tpos++;
+						}
+					}
+
+					break;
+				}
+
+				/* Identifiers and values */
+			default:
+				{
+					if (!comment) {
+						if (expr[pos] == '.' || isdigit(expr[pos])) {
+							/* Value */
+							start = pos;
+
+							/* Find digits before a period */
+							while (isdigit(expr[pos]))
+								pos++;
+
+							/* Find a period */
+							if (expr[pos] == '.')
+								pos++;
+
+							/* Find digits after a period */
+							while (isdigit(expr[pos]))
+								pos++;
+
+							/* pos is AFTER last item, back up */
+							pos--;
+
+							if (pass == 0)
+								found++;
+							else {
+								ilen = pos - start + 1;
+
+								/* Is the value to large */
+								if (ilen > EXPR_MAXIDENTSIZE) {
+									obj->starterr = start;
+									obj->enderr = pos;
+									exprFreeTokenList(list, found);
+									return EXPR_ERROR_BADIDENTIFIER;
+								}
+
+								/* Create value token */
+								strncpy(buf, expr + start, ilen);
+								buf[ilen] = '\0';
+
+								list[tpos].type = EXPR_TOKEN_VALUE;
+								list[tpos].start = start;
+								list[tpos].end = pos;
+								list[tpos].data.val = (EXPRTYPE) atof(buf);
+								tpos++;
+							}
+						} else if (expr[pos] == '_' || isalpha(expr[pos])) {
+							/* Identifier */
+							start = pos;
+
+							/* Find rest of identifier */
+							while (expr[pos] == '_' || isalnum(expr[pos]))
+								pos++;
+
+							/* pos is AFTER last item, back up */
+							pos--;
+
+							if (pass == 0)
+								found++;
+							else {
+								ilen = pos - start + 1;
+
+								/* Is the value to large */
+								if (ilen > EXPR_MAXIDENTSIZE) {
+									obj->starterr = start;
+									obj->enderr = pos;
+									exprFreeTokenList(list, found);
+									return EXPR_ERROR_BADIDENTIFIER;
+								}
+
+								/* Create value token */
+								strncpy(buf, expr + start, ilen);
+								buf[ilen] = '\0';
+
+								/* Allocate memory for identifier */
+								list[tpos].data.str = exprAllocMem(ilen + 1);
+								if (list[tpos].data.str == NULL) {
+									exprFreeTokenList(list, found);
+									return EXPR_ERROR_MEMORY;
+								}
+
+								list[tpos].type = EXPR_TOKEN_IDENTIFIER;
+								list[tpos].start = start;
+								list[tpos].end = pos;
+								strcpy(list[tpos].data.str, buf);
+								tpos++;
+							}
+						} else if (isspace(expr[pos])) {
+							/* Spaces are ignored, do nothing */
+						} else {
+							/* Unknown */
+							obj->starterr = obj->enderr = pos;
+							exprFreeTokenList(list, found);
+							return EXPR_ERROR_INVALIDCHAR;
+						}
+					}
+
+					break;
+				}
+			}
+		}
+
+		/* If pass is 0, allocate memory for next pass */
+		if (pass == 0) {
+			/* First, make sure all comments were ended */
+			if (comment)
+				comment = 0;
+
+			/* Make sure the expression is not empty */
+			if (found == 0)
+				return EXPR_ERROR_EMPTYEXPR;
+
+			/* Allocate memory for token list */
+			list = exprAllocMem(found * sizeof(exprToken));
+			if (list == NULL)
+				return EXPR_ERROR_MEMORY;
+
+			tpos = 0;
+		}
+	}
+
+	*count = found;
+	*tokens = list;
+	return EXPR_ERROR_NOERROR;
+}
 
 
 /* This is the main parsing routine */
-int exprParse(exprObj *obj, char *expr)
-    {
-    exprToken *tokens;
-    int count;
-    int err;
-    exprNode *tmp;
-
-    /* Make sure an object was passed */
-    if(obj == NULL)
-        return EXPR_ERROR_NULLPOINTER;
-
-    /* Clear expression error position */
-    obj->starterr = obj->enderr = -1;
-
-    /* Have we already been parsed? */
-    if(obj->parsedbad != 0)
-        return EXPR_ERROR_ALREADYPARSEDBAD;
-
-    if(obj->parsedgood != 0)
-        return EXPR_ERROR_ALREADYPARSEDGOOD;
-
-    /* Make sure an expression was passed */
-    if(expr == NULL)
-        return EXPR_ERROR_NULLPOINTER;
-
-    /* Create token list */
-    err = exprStringToTokenList(obj, expr, &tokens, &count);
-    if(err != EXPR_ERROR_NOERROR)
-        return err;
-    
-    /* Create head pointer */
-    tmp = exprAllocNodes(1);
-    if(tmp == NULL)
-        {
-        exprFreeTokenList(tokens, count);
-        return EXPR_ERROR_MEMORY;
-        }
-
-    obj->headnode = tmp;
-
-    /* Call the multiparse routine to parse subexpressions */
-    err = exprMultiParse(obj, tmp, tokens, count);
-
-    /* Free the token list */
-    exprFreeTokenList(tokens, count);
-
-    /* successful parse? */
-    if(err == EXPR_ERROR_NOERROR)
-        {
-        obj->parsedgood = 1;
-        obj->parsedbad = 0;
-        }
-    else
-        {
-        obj->parsedbad = 1;
-        obj->parsedgood = 0;
-        }
+int exprParse(exprObj * obj, char *expr)
+{
+	exprToken *tokens;
+	int count;
+	int err;
+	exprNode *tmp;
+
+	/* Make sure an object was passed */
+	if (obj == NULL)
+		return EXPR_ERROR_NULLPOINTER;
+
+	/* Clear expression error position */
+	obj->starterr = obj->enderr = -1;
+
+	/* Have we already been parsed? */
+	if (obj->parsedbad != 0)
+		return EXPR_ERROR_ALREADYPARSEDBAD;
+
+	if (obj->parsedgood != 0)
+		return EXPR_ERROR_ALREADYPARSEDGOOD;
+
+	/* Make sure an expression was passed */
+	if (expr == NULL)
+		return EXPR_ERROR_NULLPOINTER;
+
+	/* Create token list */
+	err = exprStringToTokenList(obj, expr, &tokens, &count);
+	if (err != EXPR_ERROR_NOERROR)
+		return err;
+
+	/* Create head pointer */
+	tmp = exprAllocNodes(1);
+	if (tmp == NULL) {
+		exprFreeTokenList(tokens, count);
+		return EXPR_ERROR_MEMORY;
+	}
+
+	obj->headnode = tmp;
+
+	/* Call the multiparse routine to parse subexpressions */
+	err = exprMultiParse(obj, tmp, tokens, count);
+
+	/* Free the token list */
+	exprFreeTokenList(tokens, count);
+
+	/* successful parse? */
+	if (err == EXPR_ERROR_NOERROR) {
+		obj->parsedgood = 1;
+		obj->parsedbad = 0;
+	} else {
+		obj->parsedbad = 1;
+		obj->parsedgood = 0;
+	}
 
-    return err;
-    }
+	return err;
+}
 
 
 /* Parse the subexpressions, each ending with semicolons */
-int exprMultiParse(exprObj *obj, exprNode *node, exprToken *tokens, int count)
-    {
-    int pos, plevel, last;
-    int num, cur, err;
-    exprNode *tmp;
-
-    plevel = 0;
-    num = 0;
-    last = -1;
-
-    /* First count the number of arguments */
-    for(pos = 0; pos < count; pos++)
-        {
-        switch(tokens[pos].type)
-            {
-            case EXPR_TOKEN_OPAREN:
-                /* increase plevel */
-                plevel++;
-                break;
-
-            case EXPR_TOKEN_CPAREN:
-                /* decrease plevel */
-                plevel--;
-
-                if(plevel < 0)
-                    {
-                    obj->starterr = tokens[pos].start;
-                    obj->enderr = tokens[pos].end;
-                    return EXPR_ERROR_UNMATCHEDPAREN;
-                    }
-
-                break;
-
-            case EXPR_TOKEN_SEMICOLON:
-                if(plevel == 0)
-                    {
-                    if(last == pos - 1 || pos == 0)
-                        {
-                        /* last semicolon is before us or we are at the start */
-                        obj->starterr = tokens[pos].start;
-                        obj->enderr = tokens[pos].end;
-                        return EXPR_ERROR_SYNTAX;
-                        }
-                    else
-                        {
-                        /* last semicolon is not right before us */
-                        num++;
-                        }
-                    }
-                else
-                    {
-                    /* Semicolon should not be in a parenthesis */
-                    obj->starterr = tokens[pos].start;
-                    obj->enderr = tokens[pos].end;
-                    return EXPR_ERROR_SYNTAX;
-                    }
-
-                last = pos; /* update position of last semicolon */
-                break;
-            }
-        }
-
-    /* plevel should be zero now */
-    if(plevel != 0)
-        return EXPR_ERROR_UNMATCHEDPAREN;
-
-    /* the last character should be a semicolon */
-    if(last != pos - 1)
-        return EXPR_ERROR_MISSINGSEMICOLON;
-
-    /* Now we know how many arguments there are */
-
-    /* Allocate array of subnodes */
-    tmp = exprAllocNodes(num);
-    if(tmp == NULL)
-        return EXPR_ERROR_MEMORY;
-
-    /* Set the current node's data */
-    node->type = EXPR_NODETYPE_MULTI;
-    node->data.oper.nodes = tmp;
-    node->data.oper.nodecount = num;
-
-    /* now we parse each subexpression */
-    last = 0; /* Not for last semicolon, but for first char of subexpr */
-    cur = 0;
-
-    for(pos = 0; pos < count; pos++)
-        {
-        if(tokens[pos].type == EXPR_TOKEN_SEMICOLON)
-            {
-            /* Everything from last up to pos - 1 is a parameter */
-            err = exprInternalParse(obj, &(tmp[cur]), tokens, last, pos - 1);
-            if(err != EXPR_ERROR_NOERROR)
-                return err;
-
-            /* Update last position and current argument */
-            last = pos + 1;
-            cur++;
-            }
-        }
+int exprMultiParse(exprObj * obj, exprNode * node, exprToken * tokens, int count)
+{
+	int pos, plevel, last;
+	int num, cur, err;
+	exprNode *tmp;
+
+	plevel = 0;
+	num = 0;
+	last = -1;
+
+	/* First count the number of arguments */
+	for (pos = 0; pos < count; pos++) {
+		switch (tokens[pos].type) {
+		case EXPR_TOKEN_OPAREN:
+			/* increase plevel */
+			plevel++;
+			break;
+
+		case EXPR_TOKEN_CPAREN:
+			/* decrease plevel */
+			plevel--;
+
+			if (plevel < 0) {
+				obj->starterr = tokens[pos].start;
+				obj->enderr = tokens[pos].end;
+				return EXPR_ERROR_UNMATCHEDPAREN;
+			}
+
+			break;
+
+		case EXPR_TOKEN_SEMICOLON:
+			if (plevel == 0) {
+				if (last == pos - 1 || pos == 0) {
+					/* last semicolon is before us or we are at the start */
+					obj->starterr = tokens[pos].start;
+					obj->enderr = tokens[pos].end;
+					return EXPR_ERROR_SYNTAX;
+				} else {
+					/* last semicolon is not right before us */
+					num++;
+				}
+			} else {
+				/* Semicolon should not be in a parenthesis */
+				obj->starterr = tokens[pos].start;
+				obj->enderr = tokens[pos].end;
+				return EXPR_ERROR_SYNTAX;
+			}
+
+			last = pos;			/* update position of last semicolon */
+			break;
+		}
+	}
+
+	/* plevel should be zero now */
+	if (plevel != 0)
+		return EXPR_ERROR_UNMATCHEDPAREN;
+
+	/* the last character should be a semicolon */
+	if (last != pos - 1)
+		return EXPR_ERROR_MISSINGSEMICOLON;
+
+	/* Now we know how many arguments there are */
+
+	/* Allocate array of subnodes */
+	tmp = exprAllocNodes(num);
+	if (tmp == NULL)
+		return EXPR_ERROR_MEMORY;
+
+	/* Set the current node's data */
+	node->type = EXPR_NODETYPE_MULTI;
+	node->data.oper.nodes = tmp;
+	node->data.oper.nodecount = num;
+
+	/* now we parse each subexpression */
+	last = 0;					/* Not for last semicolon, but for first char of subexpr */
+	cur = 0;
+
+	for (pos = 0; pos < count; pos++) {
+		if (tokens[pos].type == EXPR_TOKEN_SEMICOLON) {
+			/* Everything from last up to pos - 1 is a parameter */
+			err = exprInternalParse(obj, &(tmp[cur]), tokens, last, pos - 1);
+			if (err != EXPR_ERROR_NOERROR)
+				return err;
+
+			/* Update last position and current argument */
+			last = pos + 1;
+			cur++;
+		}
+	}
 
-    return EXPR_ERROR_NOERROR;
-    }
+	return EXPR_ERROR_NOERROR;
+}
 
 /* This function parses each subnode and recurses if needed */
-int exprInternalParse(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end)
-    {
-    int pos;
-    int plevel = 0; /* Paren level */
-    int fgopen = -1; /* First paren group open index */
-    int fgclose = -1; /* First paren group close index */
-    int assignindex = -1; /* First = at plevel 0 for assignment */
-    int addsubindex = -1; /* Last + or - at plevel 0 for adding or subtracting */
-    int muldivindex = -1; /* Last * or / at plevel 0 for multiplying or dividing */
-    int expindex = -1; /* Last ^ fount at plevel 0 for exponents */
-    int posnegindex = -1; /* First +,- at plevel 0 for positive,negative */
-
-    /* Make sure some conditions are right */
-    if(start > end)
-        return EXPR_ERROR_UNKNOWN;
-
-    /* Scan the string for certain characters */
-    for(pos = start; pos <= end; pos++)
-        {
-        switch(tokens[pos].type)
-            {
-            case EXPR_TOKEN_OPAREN:
-                plevel++;
-
-                /* First group open? */
-                if(plevel == 1 && fgopen == -1)
-                    fgopen = pos;
-                break;
-
-            case EXPR_TOKEN_CPAREN:
-                plevel--;
-
-                /* First group close? */
-                if(plevel == 0 && fgclose == -1)
-                    fgclose = pos;
-
-                if(plevel < 0)
-                    {
-                    obj->starterr = tokens[pos].start;
-                    obj->enderr = tokens[pos].end;
-                    return EXPR_ERROR_UNMATCHEDPAREN;
-                    }
-                break;
-
-            case EXPR_TOKEN_EQUAL:
-                /* Assignment found */
-                if(plevel == 0)
-                    {
-                    if(assignindex == -1)
-                        assignindex = pos;
-                    }
-                break;
-
-            case EXPR_TOKEN_ASTERISK:
-            case EXPR_TOKEN_FSLASH:
-                /* Multiplication or division */
-                if(plevel == 0)
-                    muldivindex = pos;
-                break;
-
-            case EXPR_TOKEN_HAT:
-                /* Exponent */
-                if(plevel == 0)
-                    expindex = pos;
-                break;
-
-
-            case EXPR_TOKEN_PLUS:
-            case EXPR_TOKEN_HYPHEN:
-                /* Addition or positive or subtraction or negative*/
-                if(plevel == 0)
-                    {
-                    if(pos == start)
-                        {
-                        /* At the start area, positive/negative */
-                        if(posnegindex == -1)
-                            posnegindex = pos;
-                        }
-                    else
-                        {
-                        /* Not at start, check item in front */
-                        switch(tokens[pos - 1].type)
-                            {
-                            case EXPR_TOKEN_EQUAL: /* Equal sign */
-                            case EXPR_TOKEN_PLUS: /* Add/positive sign */
-                            case EXPR_TOKEN_HYPHEN: /* Subtract/negative sign */
-                            case EXPR_TOKEN_ASTERISK: /* Multiply sign */
-                            case EXPR_TOKEN_FSLASH: /* Divide sign */
-                            case EXPR_TOKEN_HAT: /* Exponent sign */
-
-                                /* After theses, it is positive/negative */
-                                if(posnegindex == -1)
-                                    posnegindex = pos;
-
-                                break;
-
-                            default:
-                                /* Otherwise it is addition/subtraction */
-                                addsubindex = pos;
-                                break;
-                            }
-                        }
-                    }
-                break;
-
-            }
-        }
-
-    /* plevel should now be zero */
-    if(plevel != 0)
-        return EXPR_ERROR_UNMATCHEDPAREN;
-
-    /* We must parse the data in a certain order to maintain the
-       correct order of operators at evaluation time */
-
-    /* First, take care of assignment */
-    if(assignindex != -1)
-        return exprInternalParseAssign(obj, node, tokens, start, end, assignindex);
-
-    /* Addition or subtraction is next */
-    if(addsubindex != -1)
-        {
-        if(tokens[addsubindex].type == EXPR_TOKEN_PLUS)
-            return exprInternalParseAdd(obj, node, tokens, start, end, addsubindex);
-        else
-            return exprInternalParseSub(obj, node, tokens, start, end, addsubindex);
-        }
-
-
-    /* Multiplycation or division */
-    if(muldivindex != -1)
-        {
-        if(tokens[muldivindex].type == EXPR_TOKEN_ASTERISK)
-            return exprInternalParseMul(obj, node, tokens, start, end, muldivindex);
-        else
-            return exprInternalParseDiv(obj, node, tokens, start, end, muldivindex);
-        }
-
-    /* Exponent */
-    if(expindex != -1)
-        return exprInternalParseExp(obj, node, tokens, start, end, expindex);
-
-    /* Negation */
-    if(posnegindex != -1)
-        return exprInternalParsePosNeg(obj, node, tokens, start, end, posnegindex);
-
-
-    /* Grouped parenthesis */
-    if(fgopen == start)
-        {
-        /* Closing paren. should be at the end */
-        if(fgclose == end)
-            {
-            /* Anything between them */
-            if(fgclose > fgopen + 1)
-                {
-                return exprInternalParse(obj, node, tokens, fgopen + 1, fgclose - 1);
-                }
-            else
-                {
-                /* Nothing between them */
-                obj->starterr = tokens[fgopen].start;
-                obj->enderr = tokens[fgclose].end;
-                return EXPR_ERROR_SYNTAX;
-                }
-            }
-        else /* Closing paren not at the end */
-            return EXPR_ERROR_SYNTAX;
-        }
-
-    /* Functions */
-    if(fgopen > start)
-        {
-        /* Closing paren should be at end */
-        if(fgclose == end)
-            {
-            return exprInternalParseFunction(obj, node, tokens, start, end, fgopen, fgclose);
-            }
-        else /* Closing paren not at end */
-            return EXPR_ERROR_SYNTAX;
-        }
-
-    /* If it was none of the above, it must be a variable or value */
-    return exprInternalParseVarVal(obj, node, tokens, start, end);
-    }
+int exprInternalParse(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end)
+{
+	int pos;
+	int plevel = 0;				/* Paren level */
+	int fgopen = -1;			/* First paren group open index */
+	int fgclose = -1;			/* First paren group close index */
+	int assignindex = -1;		/* First = at plevel 0 for assignment */
+	int addsubindex = -1;		/* Last + or - at plevel 0 for adding or subtracting */
+	int muldivindex = -1;		/* Last * or / at plevel 0 for multiplying or dividing */
+	int expindex = -1;			/* Last ^ fount at plevel 0 for exponents */
+	int posnegindex = -1;		/* First +,- at plevel 0 for positive,negative */
+
+	/* Make sure some conditions are right */
+	if (start > end)
+		return EXPR_ERROR_UNKNOWN;
+
+	/* Scan the string for certain characters */
+	for (pos = start; pos <= end; pos++) {
+		switch (tokens[pos].type) {
+		case EXPR_TOKEN_OPAREN:
+			plevel++;
+
+			/* First group open? */
+			if (plevel == 1 && fgopen == -1)
+				fgopen = pos;
+			break;
+
+		case EXPR_TOKEN_CPAREN:
+			plevel--;
+
+			/* First group close? */
+			if (plevel == 0 && fgclose == -1)
+				fgclose = pos;
+
+			if (plevel < 0) {
+				obj->starterr = tokens[pos].start;
+				obj->enderr = tokens[pos].end;
+				return EXPR_ERROR_UNMATCHEDPAREN;
+			}
+			break;
+
+		case EXPR_TOKEN_EQUAL:
+			/* Assignment found */
+			if (plevel == 0) {
+				if (assignindex == -1)
+					assignindex = pos;
+			}
+			break;
+
+		case EXPR_TOKEN_ASTERISK:
+		case EXPR_TOKEN_FSLASH:
+			/* Multiplication or division */
+			if (plevel == 0)
+				muldivindex = pos;
+			break;
+
+		case EXPR_TOKEN_HAT:
+			/* Exponent */
+			if (plevel == 0)
+				expindex = pos;
+			break;
+
+
+		case EXPR_TOKEN_PLUS:
+		case EXPR_TOKEN_HYPHEN:
+			/* Addition or positive or subtraction or negative */
+			if (plevel == 0) {
+				if (pos == start) {
+					/* At the start area, positive/negative */
+					if (posnegindex == -1)
+						posnegindex = pos;
+				} else {
+					/* Not at start, check item in front */
+					switch (tokens[pos - 1].type) {
+					case EXPR_TOKEN_EQUAL:	/* Equal sign */
+					case EXPR_TOKEN_PLUS:	/* Add/positive sign */
+					case EXPR_TOKEN_HYPHEN:	/* Subtract/negative sign */
+					case EXPR_TOKEN_ASTERISK:	/* Multiply sign */
+					case EXPR_TOKEN_FSLASH:	/* Divide sign */
+					case EXPR_TOKEN_HAT:	/* Exponent sign */
+
+						/* After theses, it is positive/negative */
+						if (posnegindex == -1)
+							posnegindex = pos;
+
+						break;
+
+					default:
+						/* Otherwise it is addition/subtraction */
+						addsubindex = pos;
+						break;
+					}
+				}
+			}
+			break;
+
+		}
+	}
+
+	/* plevel should now be zero */
+	if (plevel != 0)
+		return EXPR_ERROR_UNMATCHEDPAREN;
+
+	/* We must parse the data in a certain order to maintain the
+	   correct order of operators at evaluation time */
+
+	/* First, take care of assignment */
+	if (assignindex != -1)
+		return exprInternalParseAssign(obj, node, tokens, start, end, assignindex);
+
+	/* Addition or subtraction is next */
+	if (addsubindex != -1) {
+		if (tokens[addsubindex].type == EXPR_TOKEN_PLUS)
+			return exprInternalParseAdd(obj, node, tokens, start, end, addsubindex);
+		else
+			return exprInternalParseSub(obj, node, tokens, start, end, addsubindex);
+	}
+
+
+	/* Multiplycation or division */
+	if (muldivindex != -1) {
+		if (tokens[muldivindex].type == EXPR_TOKEN_ASTERISK)
+			return exprInternalParseMul(obj, node, tokens, start, end, muldivindex);
+		else
+			return exprInternalParseDiv(obj, node, tokens, start, end, muldivindex);
+	}
+
+	/* Exponent */
+	if (expindex != -1)
+		return exprInternalParseExp(obj, node, tokens, start, end, expindex);
+
+	/* Negation */
+	if (posnegindex != -1)
+		return exprInternalParsePosNeg(obj, node, tokens, start, end, posnegindex);
+
+
+	/* Grouped parenthesis */
+	if (fgopen == start) {
+		/* Closing paren. should be at the end */
+		if (fgclose == end) {
+			/* Anything between them */
+			if (fgclose > fgopen + 1) {
+				return exprInternalParse(obj, node, tokens, fgopen + 1, fgclose - 1);
+			} else {
+				/* Nothing between them */
+				obj->starterr = tokens[fgopen].start;
+				obj->enderr = tokens[fgclose].end;
+				return EXPR_ERROR_SYNTAX;
+			}
+		} else					/* Closing paren not at the end */
+			return EXPR_ERROR_SYNTAX;
+	}
+
+	/* Functions */
+	if (fgopen > start) {
+		/* Closing paren should be at end */
+		if (fgclose == end) {
+			return exprInternalParseFunction(obj, node, tokens, start, end, fgopen, fgclose);
+		} else					/* Closing paren not at end */
+			return EXPR_ERROR_SYNTAX;
+	}
+
+	/* If it was none of the above, it must be a variable or value */
+	return exprInternalParseVarVal(obj, node, tokens, start, end);
+}
 
 /* Function to parse an assignment node */
-int exprInternalParseAssign(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end, int index)
-    {
-    exprNode *tmp;
-    exprValList *l;
-    EXPRTYPE *addr;
-
-    /* Make sure the equal sign is not at the start or end */
-    if(index != start + 1 || index >= end)
-        {
-        obj->starterr = tokens[index].start;
-        obj->enderr = tokens[index].end;
-        return EXPR_ERROR_SYNTAX;
-        }
-
-    /* Make sure item before equal sign is an identifier */
-    if(tokens[index - 1].type != EXPR_TOKEN_IDENTIFIER)
-        {
-        obj->starterr = tokens[index - 1].start;
-        obj->enderr = tokens[index].end;
-        return EXPR_ERROR_SYNTAX;
-        }
-
-    /* Create expression subnode */
-    tmp = exprAllocNodes(1);
-    if(tmp == NULL)
-        {
-        return EXPR_ERROR_MEMORY;
-        }
-
-
-    /* Set the data */
-    node->type = EXPR_NODETYPE_ASSIGN;
-    node->data.assign.node = tmp;
-
-
-    /*
-        The fast access method directly accesses the memory address
-        of the variable's value at evaluation time.  Because of this,
-        we must make sure the variable does exists in the variable list.
-    */
-
-    /* Make sure name is not a constant name */
-    l = exprGetConstList(obj);
-    if(l)
-        {
-        exprValListGetAddress(l, tokens[index - 1].data.str, &addr);
-        if(addr)
-            {
-            obj->starterr = tokens[index - 1].start;
-            obj->enderr = tokens[index].end;
-            return EXPR_ERROR_CONSTANTASSIGN;
-            }
-        }
-
-    /* Get the variable list */
-    l = exprGetVarList(obj);
-    if(l == NULL)
-        return EXPR_ERROR_NOVARLIST;
-
-    /* Get variable address if already in the list */
-    exprValListGetAddress(l, tokens[index - 1].data.str, &addr);
-    if(addr == NULL) /* Variable not in the list, add it */
-        {
-        exprValListAdd(l, tokens[index - 1].data.str, 0.0);
-
-        /* Try to get address again */
-        exprValListGetAddress(l, tokens[index - 1].data.str, &addr);
-        if(addr == NULL) /* Could not add variable */
-            return EXPR_ERROR_MEMORY; /* Could not add variable to list */
-        }
-
-    node->data.assign.vaddr = addr;
-
-    /* Parse the subnode */
-    return exprInternalParse(obj, tmp, tokens, index + 1, end);
-    }
+int exprInternalParseAssign(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end, int index)
+{
+	exprNode *tmp;
+	exprValList *l;
+	EXPRTYPE *addr;
+
+	/* Make sure the equal sign is not at the start or end */
+	if (index != start + 1 || index >= end) {
+		obj->starterr = tokens[index].start;
+		obj->enderr = tokens[index].end;
+		return EXPR_ERROR_SYNTAX;
+	}
+
+	/* Make sure item before equal sign is an identifier */
+	if (tokens[index - 1].type != EXPR_TOKEN_IDENTIFIER) {
+		obj->starterr = tokens[index - 1].start;
+		obj->enderr = tokens[index].end;
+		return EXPR_ERROR_SYNTAX;
+	}
+
+	/* Create expression subnode */
+	tmp = exprAllocNodes(1);
+	if (tmp == NULL) {
+		return EXPR_ERROR_MEMORY;
+	}
+
+
+	/* Set the data */
+	node->type = EXPR_NODETYPE_ASSIGN;
+	node->data.assign.node = tmp;
+
+
+	/*
+	   The fast access method directly accesses the memory address
+	   of the variable's value at evaluation time.  Because of this,
+	   we must make sure the variable does exists in the variable list.
+	 */
+
+	/* Make sure name is not a constant name */
+	l = exprGetConstList(obj);
+	if (l) {
+		exprValListGetAddress(l, tokens[index - 1].data.str, &addr);
+		if (addr) {
+			obj->starterr = tokens[index - 1].start;
+			obj->enderr = tokens[index].end;
+			return EXPR_ERROR_CONSTANTASSIGN;
+		}
+	}
+
+	/* Get the variable list */
+	l = exprGetVarList(obj);
+	if (l == NULL)
+		return EXPR_ERROR_NOVARLIST;
+
+	/* Get variable address if already in the list */
+	exprValListGetAddress(l, tokens[index - 1].data.str, &addr);
+	if (addr == NULL) {			/* Variable not in the list, add it */
+		exprValListAdd(l, tokens[index - 1].data.str, 0.0);
+
+		/* Try to get address again */
+		exprValListGetAddress(l, tokens[index - 1].data.str, &addr);
+		if (addr == NULL)		/* Could not add variable */
+			return EXPR_ERROR_MEMORY;	/* Could not add variable to list */
+	}
+
+	node->data.assign.vaddr = addr;
+
+	/* Parse the subnode */
+	return exprInternalParse(obj, tmp, tokens, index + 1, end);
+}
 
 /* Function to parse an addition operator */
-int exprInternalParseAdd(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end, int index)
-    {
-    exprNode *tmp;
-    int err;
-
-    /* Make sure plus sign is at a good place */
-    if(index <= start || index >= end)
-        {
-        obj->starterr = tokens[index].start;
-        obj->enderr = tokens[index].end;
-        return EXPR_ERROR_SYNTAX;
-        }
-
-    /* Allocate space for 2 subnodes */
-    tmp = exprAllocNodes(2);
-    if(tmp == NULL)
-        return EXPR_ERROR_MEMORY;
-
-
-    /* Set the data */
-    node->type = EXPR_NODETYPE_ADD;
-    node->data.oper.nodes = tmp;
-    node->data.oper.nodecount = 2;
-
-    /* parse the left side */
-    err = exprInternalParse(obj, &(tmp[0]), tokens, start, index - 1);
-    if(err != EXPR_ERROR_NOERROR)
-        return err;
-
-    /* parse the right side */
-    return exprInternalParse(obj, &(tmp[1]), tokens, index + 1, end);
-    }
+int exprInternalParseAdd(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end, int index)
+{
+	exprNode *tmp;
+	int err;
+
+	/* Make sure plus sign is at a good place */
+	if (index <= start || index >= end) {
+		obj->starterr = tokens[index].start;
+		obj->enderr = tokens[index].end;
+		return EXPR_ERROR_SYNTAX;
+	}
+
+	/* Allocate space for 2 subnodes */
+	tmp = exprAllocNodes(2);
+	if (tmp == NULL)
+		return EXPR_ERROR_MEMORY;
+
+
+	/* Set the data */
+	node->type = EXPR_NODETYPE_ADD;
+	node->data.oper.nodes = tmp;
+	node->data.oper.nodecount = 2;
+
+	/* parse the left side */
+	err = exprInternalParse(obj, &(tmp[0]), tokens, start, index - 1);
+	if (err != EXPR_ERROR_NOERROR)
+		return err;
+
+	/* parse the right side */
+	return exprInternalParse(obj, &(tmp[1]), tokens, index + 1, end);
+}
 
 /* Function to parse a subtraction operator */
-int exprInternalParseSub(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end, int index)
-    {
-    exprNode *tmp;
-    int err;
-
-    /* Make sure minus sign is at a good place */
-    if(index <= start || index >= end)
-        {
-        obj->starterr = tokens[index].start;
-        obj->enderr = tokens[index].end;
-        return EXPR_ERROR_SYNTAX;
-        }
-
-    /* Allocate space for 2 subnodes */
-    tmp = exprAllocNodes(2);
-    if(tmp == NULL)
-        return EXPR_ERROR_MEMORY;
-
-
-    /* Set the data */
-    node->type = EXPR_NODETYPE_SUBTRACT;
-    node->data.oper.nodes = tmp;
-    node->data.oper.nodecount = 2;
-    
-    /* parse the left side */
-    err = exprInternalParse(obj, &(tmp[0]), tokens, start, index - 1);
-    if(err != EXPR_ERROR_NOERROR)
-        return err;
-
-    /* parse the right side */
-    return exprInternalParse(obj, &(tmp[1]), tokens, index + 1, end);
-    }
+int exprInternalParseSub(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end, int index)
+{
+	exprNode *tmp;
+	int err;
+
+	/* Make sure minus sign is at a good place */
+	if (index <= start || index >= end) {
+		obj->starterr = tokens[index].start;
+		obj->enderr = tokens[index].end;
+		return EXPR_ERROR_SYNTAX;
+	}
+
+	/* Allocate space for 2 subnodes */
+	tmp = exprAllocNodes(2);
+	if (tmp == NULL)
+		return EXPR_ERROR_MEMORY;
+
+
+	/* Set the data */
+	node->type = EXPR_NODETYPE_SUBTRACT;
+	node->data.oper.nodes = tmp;
+	node->data.oper.nodecount = 2;
+
+	/* parse the left side */
+	err = exprInternalParse(obj, &(tmp[0]), tokens, start, index - 1);
+	if (err != EXPR_ERROR_NOERROR)
+		return err;
+
+	/* parse the right side */
+	return exprInternalParse(obj, &(tmp[1]), tokens, index + 1, end);
+}
 
 /* Function to parse a multiplication operator */
-int exprInternalParseMul(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end, int index)
-    {
-    exprNode *tmp;
-    int err;
-
-    /* Make sure times sign is at a good place */
-    if(index <= start || index >= end)
-        {
-        obj->starterr = tokens[index].start;
-        obj->enderr = tokens[index].end;
-        return EXPR_ERROR_SYNTAX;
-        }
-
-
-    /* Allocate space for 2 subnodes */
-    tmp = exprAllocNodes(2);
-    if(tmp == NULL)
-        return EXPR_ERROR_MEMORY;
-
-
-    /* Set the data */
-    node->type = EXPR_NODETYPE_MULTIPLY;
-    node->data.oper.nodes = tmp;
-    node->data.oper.nodecount = 2;
-
-    /* parse the left side */
-    err = exprInternalParse(obj, &(tmp[0]), tokens, start, index - 1);
-    if(err != EXPR_ERROR_NOERROR)
-        return err;
-
-    /* parse the right side */
-    return exprInternalParse(obj, &(tmp[1]), tokens, index + 1, end);
-    }
+int exprInternalParseMul(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end, int index)
+{
+	exprNode *tmp;
+	int err;
+
+	/* Make sure times sign is at a good place */
+	if (index <= start || index >= end) {
+		obj->starterr = tokens[index].start;
+		obj->enderr = tokens[index].end;
+		return EXPR_ERROR_SYNTAX;
+	}
+
+
+	/* Allocate space for 2 subnodes */
+	tmp = exprAllocNodes(2);
+	if (tmp == NULL)
+		return EXPR_ERROR_MEMORY;
+
+
+	/* Set the data */
+	node->type = EXPR_NODETYPE_MULTIPLY;
+	node->data.oper.nodes = tmp;
+	node->data.oper.nodecount = 2;
+
+	/* parse the left side */
+	err = exprInternalParse(obj, &(tmp[0]), tokens, start, index - 1);
+	if (err != EXPR_ERROR_NOERROR)
+		return err;
+
+	/* parse the right side */
+	return exprInternalParse(obj, &(tmp[1]), tokens, index + 1, end);
+}
 
 /* Function to parse a division operator */
-int exprInternalParseDiv(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end, int index)
-    {
-    exprNode *tmp;
-    int err;
-
-    /* Make sure slash sign is at a good place */
-    if(index <= start || index >= end)
-        {
-        obj->starterr = tokens[index].start;
-        obj->enderr = tokens[index].end;
-        return EXPR_ERROR_SYNTAX;
-        }
-
-
-    /* Allocate space for 2 subnodes */
-    tmp = exprAllocNodes(2);
-    if(tmp == NULL)
-        return EXPR_ERROR_MEMORY;
-
-
-    /* Set the data */
-    node->type = EXPR_NODETYPE_DIVIDE;
-    node->data.oper.nodes = tmp;
-    node->data.oper.nodecount = 2;
-
-    /* parse the left side */
-    err = exprInternalParse(obj, &(tmp[0]), tokens, start, index - 1);
-    if(err != EXPR_ERROR_NOERROR)
-        return err;
-
-    /* parse the right side */
-    return exprInternalParse(obj, &(tmp[1]), tokens, index + 1, end);
-    }
+int exprInternalParseDiv(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end, int index)
+{
+	exprNode *tmp;
+	int err;
+
+	/* Make sure slash sign is at a good place */
+	if (index <= start || index >= end) {
+		obj->starterr = tokens[index].start;
+		obj->enderr = tokens[index].end;
+		return EXPR_ERROR_SYNTAX;
+	}
+
+
+	/* Allocate space for 2 subnodes */
+	tmp = exprAllocNodes(2);
+	if (tmp == NULL)
+		return EXPR_ERROR_MEMORY;
+
+
+	/* Set the data */
+	node->type = EXPR_NODETYPE_DIVIDE;
+	node->data.oper.nodes = tmp;
+	node->data.oper.nodecount = 2;
+
+	/* parse the left side */
+	err = exprInternalParse(obj, &(tmp[0]), tokens, start, index - 1);
+	if (err != EXPR_ERROR_NOERROR)
+		return err;
+
+	/* parse the right side */
+	return exprInternalParse(obj, &(tmp[1]), tokens, index + 1, end);
+}
 
 /* Function to parse an exponent operator */
-int exprInternalParseExp(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end, int index)
-    {
-    exprNode *tmp;
-    int err;
-
-    /* Make sure exponent sign is at a good place */
-    if(index <= start || index >= end)
-        {
-        obj->starterr = tokens[index].start;
-        obj->enderr = tokens[index].end;
-        return EXPR_ERROR_SYNTAX;
-        }
-
-
-    /* Allocate space for 2 subnodes */
-    tmp = exprAllocNodes(2);
-    if(tmp == NULL)
-        return EXPR_ERROR_MEMORY;
-
-
-    /* Set the data */
-    node->type = EXPR_NODETYPE_EXPONENT;
-    node->data.oper.nodes = tmp;
-    node->data.oper.nodecount = 2;
-
-    /* parse the left side */
-    err = exprInternalParse(obj, &(tmp[0]), tokens, start, index - 1);
-    if(err != EXPR_ERROR_NOERROR)
-        return err;
-
-    /* parse the right side */
-    return exprInternalParse(obj, &(tmp[1]), tokens, index + 1, end);
-    }
+int exprInternalParseExp(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end, int index)
+{
+	exprNode *tmp;
+	int err;
+
+	/* Make sure exponent sign is at a good place */
+	if (index <= start || index >= end) {
+		obj->starterr = tokens[index].start;
+		obj->enderr = tokens[index].end;
+		return EXPR_ERROR_SYNTAX;
+	}
+
+
+	/* Allocate space for 2 subnodes */
+	tmp = exprAllocNodes(2);
+	if (tmp == NULL)
+		return EXPR_ERROR_MEMORY;
+
+
+	/* Set the data */
+	node->type = EXPR_NODETYPE_EXPONENT;
+	node->data.oper.nodes = tmp;
+	node->data.oper.nodecount = 2;
+
+	/* parse the left side */
+	err = exprInternalParse(obj, &(tmp[0]), tokens, start, index - 1);
+	if (err != EXPR_ERROR_NOERROR)
+		return err;
+
+	/* parse the right side */
+	return exprInternalParse(obj, &(tmp[1]), tokens, index + 1, end);
+}
 
 /* Function to parse for positive and negative */
-int exprInternalParsePosNeg(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end, int index)
-    {
-    exprNode *tmp;
-
-    /* Position should be the same as start */
-    if(index != start)
-        {
-        obj->starterr = tokens[index].start;
-        obj->enderr = tokens[index].end;
-        return EXPR_ERROR_UNKNOWN;
-        }
-
-    /* If it is a positive, just parse the internal of it */
-    if(tokens[index].type == EXPR_TOKEN_PLUS)
-        return exprInternalParse(obj, node, tokens, index + 1, end);
-    else
-        {
-        /* Allocate subnode */
-        tmp = exprAllocNodes(1);
-        if(tmp == NULL)
-            return EXPR_ERROR_NOERROR;
-
-
-        /* Set data */
-        node->type = EXPR_NODETYPE_NEGATE;
-        node->data.oper.nodes = tmp;
-        node->data.oper.nodecount = 1;
-
-        /* Parse the subnode */
-        return exprInternalParse(obj, tmp, tokens, index + 1, end);
-        }
-    }
+int exprInternalParsePosNeg(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end, int index)
+{
+	exprNode *tmp;
+
+	/* Position should be the same as start */
+	if (index != start) {
+		obj->starterr = tokens[index].start;
+		obj->enderr = tokens[index].end;
+		return EXPR_ERROR_UNKNOWN;
+	}
+
+	/* If it is a positive, just parse the internal of it */
+	if (tokens[index].type == EXPR_TOKEN_PLUS)
+		return exprInternalParse(obj, node, tokens, index + 1, end);
+	else {
+		/* Allocate subnode */
+		tmp = exprAllocNodes(1);
+		if (tmp == NULL)
+			return EXPR_ERROR_NOERROR;
+
+
+		/* Set data */
+		node->type = EXPR_NODETYPE_NEGATE;
+		node->data.oper.nodes = tmp;
+		node->data.oper.nodecount = 1;
+
+		/* Parse the subnode */
+		return exprInternalParse(obj, tmp, tokens, index + 1, end);
+	}
+}
 
 /* Function will parse a call to a function */
-int exprInternalParseFunction(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end, int p1, int p2)
-    {
-    int pos;
-    int num, cur;
-    int refnum, refcur;
-    int plevel = 0;
-    int lv, err;
-    exprNode *tmp;
-    exprFuncType fptr;
-    int argmin, argmax;
-    int refargmin, refargmax;
-    int type;
-    exprFuncList *l;
-    exprValList *vars;
-    EXPRTYPE *addr;
-    EXPRTYPE **reftmp;
-
-    /* We should have a function list */
-    l = exprGetFuncList(obj);
-    if(l == NULL)
-        return EXPR_ERROR_NOSUCHFUNCTION;
-
-    /* check paren. location */
-    if(p2 <= p1)
-        return EXPR_ERROR_SYNTAX;
-
-    /* second paren. should not be after the end */
-    if(p2 > end)
-        return EXPR_ERROR_SYNTAX;
-
-    /* Item before parenthesis should be an identifier */
-    if(tokens[p1 - 1].type != EXPR_TOKEN_IDENTIFIER)
-        {
-        obj->starterr = tokens[p1 - 1].start;
-        obj->enderr = tokens[p1].end;
-        return EXPR_ERROR_SYNTAX;
-        }
-
-
-    /* Look up the function */
-    err = exprFuncListGet(l, tokens[p1 - 1].data.str, &fptr, &type, &argmin, &argmax, &refargmin, &refargmax);
-    if(err != EXPR_ERROR_NOERROR)
-        {
-        if(err == EXPR_ERROR_NOTFOUND)
-            {
-            obj->starterr = tokens[p1 - 1].start;
-            obj->enderr = tokens[p1 - 1].end;
-            return EXPR_ERROR_NOSUCHFUNCTION;
-            }
-        else
-            return err;
-        }
-
-    /* Make sure the function exists */
-    if(fptr == NULL && type == 0)
-        {
-        obj->starterr = tokens[p1 - 1].start;
-        obj->enderr = tokens[p1 - 1].end;
-        return EXPR_ERROR_NOSUCHFUNCTION;
-        }
-
-    /* Count arguments */
-    if(p2 == p1 + 1)
-        {
-        num = 0;
-        refnum = 0;
-        }
-    else
-        {
-        num = 1;
-        refnum = 0;
-
-
-        /* count commas */
-        for(pos = p1 + 1; pos < p2; pos++)
-            {
-            switch(tokens[pos].type)
-                {
-                case EXPR_TOKEN_OPAREN:
-                    plevel++;
-                    break;
-
-                case EXPR_TOKEN_CPAREN:
-                    plevel--;
-                    if(plevel < 0)
-                        {
-                        obj->starterr = tokens[pos].start;
-                        obj->enderr = tokens[pos].end;
-                        return EXPR_ERROR_UNMATCHEDPAREN;
-                        }
-                    break;
-
-                case EXPR_TOKEN_COMMA:
-                    /* Found comma */
-                    if(plevel == 0)
-                        num++;
-                    break;
-
-                case EXPR_TOKEN_AMPERSAND:
-                    /* Found reference mark */
-                    if(plevel == 0)
-                        {
-                        /* This may only occur after the open parenthesis or comma */
-                        if(tokens[pos - 1].type == EXPR_TOKEN_OPAREN || tokens[pos - 1].type == EXPR_TOKEN_COMMA)
-                            refnum++;
-                        else
-                            return EXPR_ERROR_SYNTAX;
-                        }
-                    break;
-                }
-            }
-
-        /* plevel should be zero */
-        if(plevel != 0)
-            return EXPR_ERROR_UNMATCHEDPAREN;
-        }
-
-    /* We now have the number of total arguments and
-       number of ref arguments.  Get number of normal
-       arguments */
-    num = num - refnum;
-
-    /* Make sure number of arguments is correct */
-    /* Here we make sure the limits are greater
-       or equal to zero because any negative number
-       could be used to specify no limit */
-    if(argmin >= 0 && num < argmin)
-        {
-        obj->starterr = tokens[p1 - 1].start;
-        obj->enderr = tokens[p2].end;
-        return EXPR_ERROR_BADNUMBERARGUMENTS;
-        }
-
-    if(argmax >= 0 && num > argmax)
-        {
-        obj->starterr = tokens[p1 - 1].start;
-        obj->enderr = tokens[p2].end;
-        return EXPR_ERROR_BADNUMBERARGUMENTS;
-        }
-
-    if(refargmin >= 0 && refnum < refargmin)
-        {
-        obj->starterr = tokens[p1 - 1].start;
-        obj->enderr = tokens[p2].end;
-        return EXPR_ERROR_BADNUMBERARGUMENTS;
-        }
-
-    if(refargmax >= 0 && refnum > refargmax)
-        {
-        obj->starterr = tokens[p1 - 1].start;
-        obj->enderr = tokens[p2].end;
-        return EXPR_ERROR_BADNUMBERARGUMENTS;
-        }
-
-    /* Set tmp to null in case of no arguments */
-    tmp = NULL;
-    reftmp = NULL;
-
-    if(num > 0)
-        {
-        /* Allocate subnodes */
-        tmp = exprAllocNodes(num);
-        if(tmp == NULL)
-            return EXPR_ERROR_MEMORY;
-        }
-
-    if(refnum > 0)
-        {
-        /* Allocate ref pointers */
-        reftmp = exprAllocMem(sizeof(EXPRTYPE*) * refnum);
-        if(reftmp == NULL)
-            {
-            exprFreeMem(tmp);
-            return EXPR_ERROR_MEMORY;
-            }
-        }
-
-
-
-    /* Set this node's data */
-    node->type = EXPR_NODETYPE_FUNCTION;
-    node->data.function.fptr = fptr;
-    node->data.function.nodecount = num;
-    node->data.function.nodes = tmp;
-    node->data.function.refcount = refnum;
-    node->data.function.refs = reftmp;
-    node->data.function.type = type;
-
-    /* parse each subnode */
-    if(num + refnum > 0)
-        {
-        plevel = 0;
-        cur = 0;
-        refcur = 0;
-        lv = p1 + 1;
-
-        /* look for commas if more than 1 arg */
-        if(num + refnum > 1)
-            {
-            for(pos = p1 + 1; pos < p2; pos++)
-                {
-                switch(tokens[pos].type)
-                    {
-                    case EXPR_TOKEN_OPAREN:
-                        plevel++;
-                        break;
-
-                    case EXPR_TOKEN_CPAREN:
-                        plevel--;
-                        break; /* Already checked paren nesting above */
-
-                    case EXPR_TOKEN_COMMA:
-                        /* Found comma */
-                        if(plevel == 0)
-                            {
-                            /* parse inside */
-                            if(tokens[lv].type == EXPR_TOKEN_AMPERSAND)
-                                {
-                                if(lv != pos - 2)
-                                    {
-                                    obj->starterr = tokens[lv].start;
-                                    obj->enderr = tokens[pos].end;
-                                    return EXPR_ERROR_SYNTAX;
-                                    }
-
-                                /* It is a reference */
-                                if(tokens[lv + 1].type != EXPR_TOKEN_IDENTIFIER)
-                                    {
-                                    obj->starterr = tokens[lv].start;
-                                    obj->enderr = tokens[lv + 1].end;
-                                    return EXPR_ERROR_SYNTAX;
-                                    }
-
-                                
-                                /* Make sure it is not a constant */
-                                vars = exprGetConstList(obj);
-                                if(vars)
-                                    {
-                                    exprValListGetAddress(vars, tokens[lv + 1].data.str, &addr);
-                                    if(addr)
-                                        {
-                                        obj->starterr = tokens[lv].start;
-                                        obj->enderr = tokens[lv + 1].start;
-                                        return EXPR_ERROR_REFCONSTANT;
-                                        }
-                                    }
-
-                                /* Get variable list */
-                                vars = exprGetVarList(obj);
-                                if(vars == NULL)
-                                    return EXPR_ERROR_NOVARLIST;
-
-                                /* Get variable address */
-                                exprValListGetAddress(vars, tokens[lv + 1].data.str, &addr);
-                                if(addr == NULL)
-                                    {
-                                    /* Add variable to list */
-                                    exprValListAdd(vars, tokens[lv + 1].data.str, 0.0);
-
-                                    /* Try to get address again */
-                                    exprValListGetAddress(vars, tokens[lv + 1].data.str, &addr);
-                                    if(addr == NULL)
-                                        return EXPR_ERROR_MEMORY; /* Could not add variable */
-                                    }
-
-                                /* Set reference item */
-                                reftmp[refcur] = addr;
-
-                                /* increase ref arg number and lv position*/
-                                refcur++;
-                                lv = pos + 1;
-                                }
-                            else
-                                {
-                                err = exprInternalParse(obj, &(tmp[cur]), tokens, lv, pos - 1);
-                                if(err != EXPR_ERROR_NOERROR)
-                                    return err;
-
-                                /* increase arg number and lv position*/
-                                lv = pos + 1;
-                                cur++;
-                                }
-                            }
-                        break;
-                    }
-                }
-            }
-
-        /* lv should point after the last comma, or open paren. if only 1 arg */
-        if(tokens[lv].type == EXPR_TOKEN_AMPERSAND)
-            {
-            if(lv != p2 - 2)
-                {
-                obj->starterr = tokens[lv].start;
-                obj->enderr = tokens[p2].end; 
-                return EXPR_ERROR_SYNTAX;
-                }
-
-            /* It is a reference */
-            if(tokens[lv + 1].type != EXPR_TOKEN_IDENTIFIER)
-                {
-                obj->starterr = tokens[lv].start;
-                obj->enderr = tokens[lv + 1].end;
-                return EXPR_ERROR_SYNTAX;
-                }
-            
-            /* Make sure it is not a constant */
-            vars = exprGetConstList(obj);
-            if(vars)
-                {
-                exprValListGetAddress(vars, tokens[lv + 1].data.str, &addr);
-                if(addr)
-                    {
-                    obj->starterr = tokens[lv].start;
-                    obj->enderr = tokens[lv + 1].start;
-                    return EXPR_ERROR_REFCONSTANT;
-                    }
-                }
-
-            /* Get variable list */
-            vars = exprGetVarList(obj);
-            if(vars == NULL)
-                return EXPR_ERROR_NOVARLIST;
-
-            /* Get variable address */
-            exprValListGetAddress(vars, tokens[lv + 1].data.str, &addr);
-            if(addr == NULL)
-                {
-                /* Add variable to list */
-                exprValListAdd(vars, tokens[lv + 1].data.str, 0.0);
-
-                /* Try to get address again */
-                exprValListGetAddress(vars, tokens[lv + 1].data.str, &addr);
-                if(addr == NULL)
-                    return EXPR_ERROR_MEMORY; /* Could not add variable */
-                }
-
-            /* Set reference item */
-            reftmp[refcur] = addr;
-            }
-        else
-            {
-            err = exprInternalParse(obj, &(tmp[cur]), tokens, lv, p2 - 1);
-            if(err != EXPR_ERROR_NOERROR)
-                return err;
-            }
-        }
+int exprInternalParseFunction(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end, int p1, int p2)
+{
+	int pos;
+	int num, cur;
+	int refnum, refcur;
+	int plevel = 0;
+	int lv, err;
+	exprNode *tmp;
+	exprFuncType fptr;
+	int argmin, argmax;
+	int refargmin, refargmax;
+	int type;
+	exprFuncList *l;
+	exprValList *vars;
+	EXPRTYPE *addr;
+	EXPRTYPE **reftmp;
+
+	/* We should have a function list */
+	l = exprGetFuncList(obj);
+	if (l == NULL)
+		return EXPR_ERROR_NOSUCHFUNCTION;
+
+	/* check paren. location */
+	if (p2 <= p1)
+		return EXPR_ERROR_SYNTAX;
+
+	/* second paren. should not be after the end */
+	if (p2 > end)
+		return EXPR_ERROR_SYNTAX;
+
+	/* Item before parenthesis should be an identifier */
+	if (tokens[p1 - 1].type != EXPR_TOKEN_IDENTIFIER) {
+		obj->starterr = tokens[p1 - 1].start;
+		obj->enderr = tokens[p1].end;
+		return EXPR_ERROR_SYNTAX;
+	}
+
+
+	/* Look up the function */
+	err = exprFuncListGet(l, tokens[p1 - 1].data.str, &fptr, &type, &argmin, &argmax, &refargmin, &refargmax);
+	if (err != EXPR_ERROR_NOERROR) {
+		if (err == EXPR_ERROR_NOTFOUND) {
+			obj->starterr = tokens[p1 - 1].start;
+			obj->enderr = tokens[p1 - 1].end;
+			return EXPR_ERROR_NOSUCHFUNCTION;
+		} else
+			return err;
+	}
+
+	/* Make sure the function exists */
+	if (fptr == NULL && type == 0) {
+		obj->starterr = tokens[p1 - 1].start;
+		obj->enderr = tokens[p1 - 1].end;
+		return EXPR_ERROR_NOSUCHFUNCTION;
+	}
+
+	/* Count arguments */
+	if (p2 == p1 + 1) {
+		num = 0;
+		refnum = 0;
+	} else {
+		num = 1;
+		refnum = 0;
+
+
+		/* count commas */
+		for (pos = p1 + 1; pos < p2; pos++) {
+			switch (tokens[pos].type) {
+			case EXPR_TOKEN_OPAREN:
+				plevel++;
+				break;
+
+			case EXPR_TOKEN_CPAREN:
+				plevel--;
+				if (plevel < 0) {
+					obj->starterr = tokens[pos].start;
+					obj->enderr = tokens[pos].end;
+					return EXPR_ERROR_UNMATCHEDPAREN;
+				}
+				break;
+
+			case EXPR_TOKEN_COMMA:
+				/* Found comma */
+				if (plevel == 0)
+					num++;
+				break;
+
+			case EXPR_TOKEN_AMPERSAND:
+				/* Found reference mark */
+				if (plevel == 0) {
+					/* This may only occur after the open parenthesis or comma */
+					if (tokens[pos - 1].type == EXPR_TOKEN_OPAREN || tokens[pos - 1].type == EXPR_TOKEN_COMMA)
+						refnum++;
+					else
+						return EXPR_ERROR_SYNTAX;
+				}
+				break;
+			}
+		}
+
+		/* plevel should be zero */
+		if (plevel != 0)
+			return EXPR_ERROR_UNMATCHEDPAREN;
+	}
+
+	/* We now have the number of total arguments and
+	   number of ref arguments.  Get number of normal
+	   arguments */
+	num = num - refnum;
+
+	/* Make sure number of arguments is correct */
+	/* Here we make sure the limits are greater
+	   or equal to zero because any negative number
+	   could be used to specify no limit */
+	if (argmin >= 0 && num < argmin) {
+		obj->starterr = tokens[p1 - 1].start;
+		obj->enderr = tokens[p2].end;
+		return EXPR_ERROR_BADNUMBERARGUMENTS;
+	}
+
+	if (argmax >= 0 && num > argmax) {
+		obj->starterr = tokens[p1 - 1].start;
+		obj->enderr = tokens[p2].end;
+		return EXPR_ERROR_BADNUMBERARGUMENTS;
+	}
+
+	if (refargmin >= 0 && refnum < refargmin) {
+		obj->starterr = tokens[p1 - 1].start;
+		obj->enderr = tokens[p2].end;
+		return EXPR_ERROR_BADNUMBERARGUMENTS;
+	}
+
+	if (refargmax >= 0 && refnum > refargmax) {
+		obj->starterr = tokens[p1 - 1].start;
+		obj->enderr = tokens[p2].end;
+		return EXPR_ERROR_BADNUMBERARGUMENTS;
+	}
+
+	/* Set tmp to null in case of no arguments */
+	tmp = NULL;
+	reftmp = NULL;
+
+	if (num > 0) {
+		/* Allocate subnodes */
+		tmp = exprAllocNodes(num);
+		if (tmp == NULL)
+			return EXPR_ERROR_MEMORY;
+	}
+
+	if (refnum > 0) {
+		/* Allocate ref pointers */
+		reftmp = exprAllocMem(sizeof(EXPRTYPE *) * refnum);
+		if (reftmp == NULL) {
+			exprFreeMem(tmp);
+			return EXPR_ERROR_MEMORY;
+		}
+	}
+
+
+
+	/* Set this node's data */
+	node->type = EXPR_NODETYPE_FUNCTION;
+	node->data.function.fptr = fptr;
+	node->data.function.nodecount = num;
+	node->data.function.nodes = tmp;
+	node->data.function.refcount = refnum;
+	node->data.function.refs = reftmp;
+	node->data.function.type = type;
+
+	/* parse each subnode */
+	if (num + refnum > 0) {
+		plevel = 0;
+		cur = 0;
+		refcur = 0;
+		lv = p1 + 1;
+
+		/* look for commas if more than 1 arg */
+		if (num + refnum > 1) {
+			for (pos = p1 + 1; pos < p2; pos++) {
+				switch (tokens[pos].type) {
+				case EXPR_TOKEN_OPAREN:
+					plevel++;
+					break;
+
+				case EXPR_TOKEN_CPAREN:
+					plevel--;
+					break;		/* Already checked paren nesting above */
+
+				case EXPR_TOKEN_COMMA:
+					/* Found comma */
+					if (plevel == 0) {
+						/* parse inside */
+						if (tokens[lv].type == EXPR_TOKEN_AMPERSAND) {
+							if (lv != pos - 2) {
+								obj->starterr = tokens[lv].start;
+								obj->enderr = tokens[pos].end;
+								return EXPR_ERROR_SYNTAX;
+							}
+
+							/* It is a reference */
+							if (tokens[lv + 1].type != EXPR_TOKEN_IDENTIFIER) {
+								obj->starterr = tokens[lv].start;
+								obj->enderr = tokens[lv + 1].end;
+								return EXPR_ERROR_SYNTAX;
+							}
+
+
+							/* Make sure it is not a constant */
+							vars = exprGetConstList(obj);
+							if (vars) {
+								exprValListGetAddress(vars, tokens[lv + 1].data.str, &addr);
+								if (addr) {
+									obj->starterr = tokens[lv].start;
+									obj->enderr = tokens[lv + 1].start;
+									return EXPR_ERROR_REFCONSTANT;
+								}
+							}
+
+							/* Get variable list */
+							vars = exprGetVarList(obj);
+							if (vars == NULL)
+								return EXPR_ERROR_NOVARLIST;
+
+							/* Get variable address */
+							exprValListGetAddress(vars, tokens[lv + 1].data.str, &addr);
+							if (addr == NULL) {
+								/* Add variable to list */
+								exprValListAdd(vars, tokens[lv + 1].data.str, 0.0);
+
+								/* Try to get address again */
+								exprValListGetAddress(vars, tokens[lv + 1].data.str, &addr);
+								if (addr == NULL)
+									return EXPR_ERROR_MEMORY;	/* Could not add variable */
+							}
+
+							/* Set reference item */
+							reftmp[refcur] = addr;
+
+							/* increase ref arg number and lv position */
+							refcur++;
+							lv = pos + 1;
+						} else {
+							err = exprInternalParse(obj, &(tmp[cur]), tokens, lv, pos - 1);
+							if (err != EXPR_ERROR_NOERROR)
+								return err;
+
+							/* increase arg number and lv position */
+							lv = pos + 1;
+							cur++;
+						}
+					}
+					break;
+				}
+			}
+		}
+
+		/* lv should point after the last comma, or open paren. if only 1 arg */
+		if (tokens[lv].type == EXPR_TOKEN_AMPERSAND) {
+			if (lv != p2 - 2) {
+				obj->starterr = tokens[lv].start;
+				obj->enderr = tokens[p2].end;
+				return EXPR_ERROR_SYNTAX;
+			}
+
+			/* It is a reference */
+			if (tokens[lv + 1].type != EXPR_TOKEN_IDENTIFIER) {
+				obj->starterr = tokens[lv].start;
+				obj->enderr = tokens[lv + 1].end;
+				return EXPR_ERROR_SYNTAX;
+			}
+
+			/* Make sure it is not a constant */
+			vars = exprGetConstList(obj);
+			if (vars) {
+				exprValListGetAddress(vars, tokens[lv + 1].data.str, &addr);
+				if (addr) {
+					obj->starterr = tokens[lv].start;
+					obj->enderr = tokens[lv + 1].start;
+					return EXPR_ERROR_REFCONSTANT;
+				}
+			}
+
+			/* Get variable list */
+			vars = exprGetVarList(obj);
+			if (vars == NULL)
+				return EXPR_ERROR_NOVARLIST;
+
+			/* Get variable address */
+			exprValListGetAddress(vars, tokens[lv + 1].data.str, &addr);
+			if (addr == NULL) {
+				/* Add variable to list */
+				exprValListAdd(vars, tokens[lv + 1].data.str, 0.0);
+
+				/* Try to get address again */
+				exprValListGetAddress(vars, tokens[lv + 1].data.str, &addr);
+				if (addr == NULL)
+					return EXPR_ERROR_MEMORY;	/* Could not add variable */
+			}
+
+			/* Set reference item */
+			reftmp[refcur] = addr;
+		} else {
+			err = exprInternalParse(obj, &(tmp[cur]), tokens, lv, p2 - 1);
+			if (err != EXPR_ERROR_NOERROR)
+				return err;
+		}
+	}
 
 
-    return EXPR_ERROR_NOERROR;
-    }
+	return EXPR_ERROR_NOERROR;
+}
 
 /* Parse a variable or value */
-int exprInternalParseVarVal(exprObj *obj, exprNode *node, exprToken *tokens, int start, int end)
-    {
-    exprValList *l;
-    EXPRTYPE *addr;
-
-
-    /* Make sure positions are correct */
-    if(start != end)
-        {
-        return EXPR_ERROR_UNKNOWN;
-        }
-    
-    
-    /* Are we an identifier */
-    if(tokens[start].type == EXPR_TOKEN_IDENTIFIER)
-        {
-        /* we are an identifier */
-
-        /* check to see if it is a constant */
-        l = exprGetConstList(obj);
-        if(l != NULL)
-            {
-            if(exprValListGetAddress(l, tokens[start].data.str, &addr) == EXPR_ERROR_NOERROR)
-                {
-                /* We found it in the constant list */
-
-                /*
-                    Treat is like a variable node so application can change
-                    constant value and it will reflect in expression
-                */
-
-                node->type = EXPR_NODETYPE_VARIABLE;
-                node->data.variable.vaddr = addr;
-                return EXPR_ERROR_NOERROR;
-                }
-            }
-
-        /* Not found in the constant list, so it must be a variable */
-
-        /* Set node type */
-        node->type = EXPR_NODETYPE_VARIABLE;
-
-        /*
-            The fast access method directly accesses the memory address
-            of the variable's value at evaluation time.  Because of this,
-            we must make sure the variable does exists in the variable list.
-        */
-
-        /* Get the variable list */
-        l = exprGetVarList(obj);
-        if(l == NULL)
-            return EXPR_ERROR_NOVARLIST;
-
-        /* Get variable address if already in the list */
-        exprValListGetAddress(l, tokens[start].data.str, &addr);
-        if(addr == NULL) /* Variable not in the list, add it */
-            {
-            exprValListAdd(l, tokens[start].data.str, 0.0);
-
-            /* Try to get address again */
-            exprValListGetAddress(l, tokens[start].data.str, &addr);
-            if(addr == NULL) /* Could not add variable */
-                return EXPR_ERROR_MEMORY; /* Could not add variable to list */
-            }
-
-        node->data.variable.vaddr = addr;
-
-        return EXPR_ERROR_NOERROR;
-        }
-    else if(tokens[start].type == EXPR_TOKEN_VALUE)
-        {
-        /* we are a value */
-        node->type = EXPR_NODETYPE_VALUE;
-        node->data.value.value = tokens[start].data.val;
-        return EXPR_ERROR_NOERROR;
-        }
-    else
-        {
-        obj->starterr = tokens[start].start;
-        obj->enderr = tokens[end].end;
-        return EXPR_ERROR_UNKNOWN;
-        }
-    }
+int exprInternalParseVarVal(exprObj * obj, exprNode * node, exprToken * tokens, int start, int end)
+{
+	exprValList *l;
+	EXPRTYPE *addr;
+
+
+	/* Make sure positions are correct */
+	if (start != end) {
+		return EXPR_ERROR_UNKNOWN;
+	}
+
+
+	/* Are we an identifier */
+	if (tokens[start].type == EXPR_TOKEN_IDENTIFIER) {
+		/* we are an identifier */
+
+		/* check to see if it is a constant */
+		l = exprGetConstList(obj);
+		if (l != NULL) {
+			if (exprValListGetAddress(l, tokens[start].data.str, &addr) == EXPR_ERROR_NOERROR) {
+				/* We found it in the constant list */
+
+				/*
+				   Treat is like a variable node so application can change
+				   constant value and it will reflect in expression
+				 */
+
+				node->type = EXPR_NODETYPE_VARIABLE;
+				node->data.variable.vaddr = addr;
+				return EXPR_ERROR_NOERROR;
+			}
+		}
+
+		/* Not found in the constant list, so it must be a variable */
+
+		/* Set node type */
+		node->type = EXPR_NODETYPE_VARIABLE;
+
+		/*
+		   The fast access method directly accesses the memory address
+		   of the variable's value at evaluation time.  Because of this,
+		   we must make sure the variable does exists in the variable list.
+		 */
+
+		/* Get the variable list */
+		l = exprGetVarList(obj);
+		if (l == NULL)
+			return EXPR_ERROR_NOVARLIST;
+
+		/* Get variable address if already in the list */
+		exprValListGetAddress(l, tokens[start].data.str, &addr);
+		if (addr == NULL) {		/* Variable not in the list, add it */
+			exprValListAdd(l, tokens[start].data.str, 0.0);
+
+			/* Try to get address again */
+			exprValListGetAddress(l, tokens[start].data.str, &addr);
+			if (addr == NULL)	/* Could not add variable */
+				return EXPR_ERROR_MEMORY;	/* Could not add variable to list */
+		}
+
+		node->data.variable.vaddr = addr;
+
+		return EXPR_ERROR_NOERROR;
+	} else if (tokens[start].type == EXPR_TOKEN_VALUE) {
+		/* we are a value */
+		node->type = EXPR_NODETYPE_VALUE;
+		node->data.value.value = tokens[start].data.val;
+		return EXPR_ERROR_NOERROR;
+	} else {
+		obj->starterr = tokens[start].start;
+		obj->enderr = tokens[end].end;
+		return EXPR_ERROR_UNKNOWN;
+	}
+}

Modified: freeswitch/trunk/src/mod/applications/mod_expr/exprutil.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_expr/exprutil.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_expr/exprutil.c	Tue May 27 00:54:52 2008
@@ -15,29 +15,27 @@
 
 /* Return the version number */
 void exprGetVersion(int *major, int *minor)
-    {
-    *major = EXPR_VERSIONMAJOR;
-    *minor = EXPR_VERSIONMINOR;
-    }
+{
+	*major = EXPR_VERSIONMAJOR;
+	*minor = EXPR_VERSIONMINOR;
+}
 
 /* This utility function determines if an identifier is valid */
 int exprValidIdent(char *name)
-    {
-    if(name == NULL) /* Null string */
-        return 0;
-
-    /* First must be letter or underscore */
-    if(isalpha(*name) || *name == '_')
-        name++; /* Point to next letter */
-    else
-        return 0; /* Not letter or underscore, maybe empty*/
-
-    /* others can be letter, number, or underscore */
-    while(isalnum(*name) || *name == '_')
-        name++;
-
-    /* When the while breaks out, we should be at the end */
-    return (*name == '\0') ? 1 : 0;
-    }
-
-
+{
+	if (name == NULL)			/* Null string */
+		return 0;
+
+	/* First must be letter or underscore */
+	if (isalpha(*name) || *name == '_')
+		name++;					/* Point to next letter */
+	else
+		return 0;				/* Not letter or underscore, maybe empty */
+
+	/* others can be letter, number, or underscore */
+	while (isalnum(*name) || *name == '_')
+		name++;
+
+	/* When the while breaks out, we should be at the end */
+	return (*name == '\0') ? 1 : 0;
+}

Modified: freeswitch/trunk/src/mod/applications/mod_expr/exprval.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_expr/exprval.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_expr/exprval.c	Tue May 27 00:54:52 2008
@@ -15,381 +15,365 @@
 
 
 /* Internal functions */
-static exprVal *exprCreateVal(char *name, EXPRTYPE val, EXPRTYPE *addr);
-static void exprValListFreeData(exprVal *val);
-static void exprValListResetData(exprVal *val);
+static exprVal *exprCreateVal(char *name, EXPRTYPE val, EXPRTYPE * addr);
+static void exprValListFreeData(exprVal * val);
+static void exprValListResetData(exprVal * val);
 
 /* This function creates the value list, */
-int exprValListCreate(exprValList **vlist)
-    {
-    exprValList *tmp;
+int exprValListCreate(exprValList ** vlist)
+{
+	exprValList *tmp;
 
-    if(vlist == NULL)
-        return EXPR_ERROR_NULLPOINTER;
+	if (vlist == NULL)
+		return EXPR_ERROR_NULLPOINTER;
 
-    *vlist = NULL; /* Set to NULL initially */
+	*vlist = NULL;				/* Set to NULL initially */
 
-    tmp = exprAllocMem(sizeof(exprValList));
+	tmp = exprAllocMem(sizeof(exprValList));
 
-    if(tmp == NULL)
-        return EXPR_ERROR_MEMORY; /* Could not allocate memory */
+	if (tmp == NULL)
+		return EXPR_ERROR_MEMORY;	/* Could not allocate memory */
 
-    /* Update pointer */
-    *vlist = tmp;
+	/* Update pointer */
+	*vlist = tmp;
 
-    return EXPR_ERROR_NOERROR;
-    }
+	return EXPR_ERROR_NOERROR;
+}
 
 /* Add a value to the list */
-int exprValListAdd(exprValList *vlist, char *name, EXPRTYPE val)
-    {
-    exprVal *tmp;
-    exprVal *cur;
-    int result;
-
-    if(vlist == NULL)
-        return EXPR_ERROR_NULLPOINTER;
-
-    /* Make sure the name is valid */
-    if(!exprValidIdent(name))
-        return EXPR_ERROR_BADIDENTIFIER;
-
-    if(vlist->head == NULL)
-        {
-        /* Create the node right here */
-        tmp = exprCreateVal(name, val, NULL);
-
-        if(tmp == NULL)
-            return EXPR_ERROR_MEMORY;
-
-        vlist->head = tmp;
-        return EXPR_ERROR_NOERROR;
-        }
-
-    /* See if already exists */
-    cur = vlist->head;
-
-    while(cur)
-        {
-        result = strcmp(name, cur->vname);
-        
-        if(result == 0)
-            return EXPR_ERROR_ALREADYEXISTS;
-            
-        cur = cur->next;
-        }
-        
-    /* We did not find it, create it and add it to the beginning */
-    tmp = exprCreateVal(name, val, NULL);
-
-    if(tmp == NULL)
-        return EXPR_ERROR_MEMORY;
-        
-    tmp->next = vlist->head;
-    vlist->head = tmp;
-    
-    return EXPR_ERROR_NOERROR;
-    }
-    
+int exprValListAdd(exprValList * vlist, char *name, EXPRTYPE val)
+{
+	exprVal *tmp;
+	exprVal *cur;
+	int result;
+
+	if (vlist == NULL)
+		return EXPR_ERROR_NULLPOINTER;
+
+	/* Make sure the name is valid */
+	if (!exprValidIdent(name))
+		return EXPR_ERROR_BADIDENTIFIER;
+
+	if (vlist->head == NULL) {
+		/* Create the node right here */
+		tmp = exprCreateVal(name, val, NULL);
+
+		if (tmp == NULL)
+			return EXPR_ERROR_MEMORY;
+
+		vlist->head = tmp;
+		return EXPR_ERROR_NOERROR;
+	}
+
+	/* See if already exists */
+	cur = vlist->head;
+
+	while (cur) {
+		result = strcmp(name, cur->vname);
+
+		if (result == 0)
+			return EXPR_ERROR_ALREADYEXISTS;
+
+		cur = cur->next;
+	}
+
+	/* We did not find it, create it and add it to the beginning */
+	tmp = exprCreateVal(name, val, NULL);
+
+	if (tmp == NULL)
+		return EXPR_ERROR_MEMORY;
+
+	tmp->next = vlist->head;
+	vlist->head = tmp;
+
+	return EXPR_ERROR_NOERROR;
+}
+
 /* Set a value in the list */
-int exprValListSet(exprValList *vlist, char *name, EXPRTYPE val)
-    {
-    exprVal *cur;
-    int result;
-
-    if(vlist == NULL)
-        return EXPR_ERROR_NULLPOINTER;
-
-    if(name == NULL || name[0] == '\0')
-        return EXPR_ERROR_NOTFOUND;
-
-    /* Find and set it */
-    cur = vlist->head;
-
-    while(cur)
-        {
-        result = strcmp(name, cur->vname);
-        
-        if(result == 0)
-            {
-            if(cur->vptr)
-                *(cur->vptr) = val;
-            else
-                cur->vval = val;
-                
-            return EXPR_ERROR_NOERROR;                
-            }
-            
-        cur = cur->next;
-        }
-        
-    return EXPR_ERROR_NOTFOUND;
-    }    
+int exprValListSet(exprValList * vlist, char *name, EXPRTYPE val)
+{
+	exprVal *cur;
+	int result;
+
+	if (vlist == NULL)
+		return EXPR_ERROR_NULLPOINTER;
+
+	if (name == NULL || name[0] == '\0')
+		return EXPR_ERROR_NOTFOUND;
+
+	/* Find and set it */
+	cur = vlist->head;
+
+	while (cur) {
+		result = strcmp(name, cur->vname);
+
+		if (result == 0) {
+			if (cur->vptr)
+				*(cur->vptr) = val;
+			else
+				cur->vval = val;
+
+			return EXPR_ERROR_NOERROR;
+		}
+
+		cur = cur->next;
+	}
+
+	return EXPR_ERROR_NOTFOUND;
+}
 
 /* Get the value from a list  */
-int exprValListGet(exprValList *vlist, char *name, EXPRTYPE *val)
-    {
-    exprVal *cur;
-    int result;
-
-    if(vlist == NULL)
-        return EXPR_ERROR_NULLPOINTER;
-
-    if(name == NULL || name[0] == '\0')
-        return EXPR_ERROR_NOTFOUND;
-
-    /* Search for the item */
-    cur = vlist->head;
-
-    while(cur)
-        {
-        result = strcmp(name, cur->vname);
-
-        if(result == 0)
-            {
-            /* We found it. */
-            if(cur->vptr)
-                *val = *(cur->vptr);
-            else
-                *val = cur->vval;
-
-            /* return now */
-            return EXPR_ERROR_NOERROR;
-            }
-
-        cur = cur->next;
-        }
-
-    /* If we got here, we did not find the item in the list */
-    return EXPR_ERROR_NOTFOUND;
-    }
-    
+int exprValListGet(exprValList * vlist, char *name, EXPRTYPE * val)
+{
+	exprVal *cur;
+	int result;
+
+	if (vlist == NULL)
+		return EXPR_ERROR_NULLPOINTER;
+
+	if (name == NULL || name[0] == '\0')
+		return EXPR_ERROR_NOTFOUND;
+
+	/* Search for the item */
+	cur = vlist->head;
+
+	while (cur) {
+		result = strcmp(name, cur->vname);
+
+		if (result == 0) {
+			/* We found it. */
+			if (cur->vptr)
+				*val = *(cur->vptr);
+			else
+				*val = cur->vval;
+
+			/* return now */
+			return EXPR_ERROR_NOERROR;
+		}
+
+		cur = cur->next;
+	}
+
+	/* If we got here, we did not find the item in the list */
+	return EXPR_ERROR_NOTFOUND;
+}
+
 /* Add an address to the list */
-int exprValListAddAddress(exprValList *vlist, char *name, EXPRTYPE *addr)
-    {
-    exprVal *tmp;
-    exprVal *cur;
-    int result;
-
-    if(vlist == NULL)
-        return EXPR_ERROR_NULLPOINTER;
-
-    /* Make sure the name is valid */
-    if(!exprValidIdent(name))
-        return EXPR_ERROR_BADIDENTIFIER;
-
-    if(vlist->head == NULL)
-        {
-        /* Create the node right here */
-        tmp = exprCreateVal(name, (EXPRTYPE)0.0, addr);
-
-        if(tmp == NULL)
-            return EXPR_ERROR_MEMORY;
-
-        vlist->head = tmp;
-        return EXPR_ERROR_NOERROR;
-        }
-
-    /* See if it already exists */
-    cur = vlist->head;
-    
-    while(cur)
-        {
-        result = strcmp(name, cur->vname);
-
-        if(result == 0)
-            return EXPR_ERROR_ALREADYEXISTS;
-            
-        cur = cur->next;
-        }
-        
-    /* Add it to the list */
-    tmp = exprCreateVal(name, (EXPRTYPE)0.0, addr);
-
-    if(tmp == NULL)
-        return EXPR_ERROR_MEMORY;
-        
-    tmp->next = vlist->head;
-    vlist->head = tmp;
+int exprValListAddAddress(exprValList * vlist, char *name, EXPRTYPE * addr)
+{
+	exprVal *tmp;
+	exprVal *cur;
+	int result;
 
-    return EXPR_ERROR_NOERROR;
-    }    
+	if (vlist == NULL)
+		return EXPR_ERROR_NULLPOINTER;
+
+	/* Make sure the name is valid */
+	if (!exprValidIdent(name))
+		return EXPR_ERROR_BADIDENTIFIER;
+
+	if (vlist->head == NULL) {
+		/* Create the node right here */
+		tmp = exprCreateVal(name, (EXPRTYPE) 0.0, addr);
+
+		if (tmp == NULL)
+			return EXPR_ERROR_MEMORY;
+
+		vlist->head = tmp;
+		return EXPR_ERROR_NOERROR;
+	}
+
+	/* See if it already exists */
+	cur = vlist->head;
+
+	while (cur) {
+		result = strcmp(name, cur->vname);
+
+		if (result == 0)
+			return EXPR_ERROR_ALREADYEXISTS;
+
+		cur = cur->next;
+	}
+
+	/* Add it to the list */
+	tmp = exprCreateVal(name, (EXPRTYPE) 0.0, addr);
+
+	if (tmp == NULL)
+		return EXPR_ERROR_MEMORY;
+
+	tmp->next = vlist->head;
+	vlist->head = tmp;
+
+	return EXPR_ERROR_NOERROR;
+}
 
 /* Get memory address of a variable value in a value list */
-int exprValListGetAddress(exprValList *vlist, char *name, EXPRTYPE **addr)
-    {
-    exprVal *cur;
-    int result;
-
-    /* Not found yet */
-    *addr = NULL;
-
-    if(vlist == NULL || addr == NULL)
-        return EXPR_ERROR_NULLPOINTER;
-
-
-    if(name == NULL || name[0] == '\0')
-        return EXPR_ERROR_NOTFOUND;
-
-    /* Search for the item */
-    cur = vlist->head;
-
-    while(cur)
-        {
-        result = strcmp(name, cur->vname);
-
-        if(result == 0)
-            {
-            /* We found it. */
-            if(cur->vptr)
-                *addr = cur->vptr;
-            else
-                *addr = &(cur->vval);
-
-            /* return now */
-            return EXPR_ERROR_NOERROR;
-            }
-            
-        cur = cur->next;
-        }
-
-    /* If we got here, we did not find it in the list */
-    return EXPR_ERROR_NOTFOUND;
-    }
-    
+int exprValListGetAddress(exprValList * vlist, char *name, EXPRTYPE ** addr)
+{
+	exprVal *cur;
+	int result;
+
+	/* Not found yet */
+	*addr = NULL;
+
+	if (vlist == NULL || addr == NULL)
+		return EXPR_ERROR_NULLPOINTER;
+
+
+	if (name == NULL || name[0] == '\0')
+		return EXPR_ERROR_NOTFOUND;
+
+	/* Search for the item */
+	cur = vlist->head;
+
+	while (cur) {
+		result = strcmp(name, cur->vname);
+
+		if (result == 0) {
+			/* We found it. */
+			if (cur->vptr)
+				*addr = cur->vptr;
+			else
+				*addr = &(cur->vval);
+
+			/* return now */
+			return EXPR_ERROR_NOERROR;
+		}
+
+		cur = cur->next;
+	}
+
+	/* If we got here, we did not find it in the list */
+	return EXPR_ERROR_NOTFOUND;
+}
+
 /* This function is used to enumerate the values in a value list */
-void *exprValListGetNext(exprValList *vlist, char **name, EXPRTYPE *value, EXPRTYPE** addr, void *cookie)
-    {
-    exprVal *cur;
-    
-    if(vlist == NULL)
-        return NULL;
-        
-    /* Get the current item */
-    cur = (exprVal*)cookie;
-    
-    /* Find the next item */
-    if(cur == NULL)
-        cur = vlist->head;
-    else
-        cur = cur->next;
-        
-    /* Set up the data */
-    if(cur)
-        {
-        if(name)
-            *name = cur->vname;
-           
-        if(value)
-            {
-            if(cur->vptr)
-                *value = *(cur->vptr);
-            else
-                *value = cur->vval;
-            }
-            
-        if(addr)
-            {
-            if(cur->vptr)
-                *addr = cur->vptr;
-            else
-                *addr = &(cur->vval);
-            }                                
-        }
-        
-    /* If there was no value, return NULL, otherwise, return the item */
-    return (void*)cur;
-    }
+void *exprValListGetNext(exprValList * vlist, char **name, EXPRTYPE * value, EXPRTYPE ** addr, void *cookie)
+{
+	exprVal *cur;
+
+	if (vlist == NULL)
+		return NULL;
+
+	/* Get the current item */
+	cur = (exprVal *) cookie;
+
+	/* Find the next item */
+	if (cur == NULL)
+		cur = vlist->head;
+	else
+		cur = cur->next;
+
+	/* Set up the data */
+	if (cur) {
+		if (name)
+			*name = cur->vname;
+
+		if (value) {
+			if (cur->vptr)
+				*value = *(cur->vptr);
+			else
+				*value = cur->vval;
+		}
+
+		if (addr) {
+			if (cur->vptr)
+				*addr = cur->vptr;
+			else
+				*addr = &(cur->vval);
+		}
+	}
+
+	/* If there was no value, return NULL, otherwise, return the item */
+	return (void *) cur;
+}
 
 /* This routine will free the value list */
-int exprValListFree(exprValList *vlist)
-    {
-    /* Make sure it exists, if not it is not error */
-    if(vlist == NULL)
-        return EXPR_ERROR_NOERROR;
+int exprValListFree(exprValList * vlist)
+{
+	/* Make sure it exists, if not it is not error */
+	if (vlist == NULL)
+		return EXPR_ERROR_NOERROR;
 
-    /* Free the nodes */
-    exprValListFreeData(vlist->head);
+	/* Free the nodes */
+	exprValListFreeData(vlist->head);
 
-    /* Freethe container */
-    exprFreeMem(vlist);
+	/* Freethe container */
+	exprFreeMem(vlist);
 
-    return EXPR_ERROR_NOERROR;
-    }
+	return EXPR_ERROR_NOERROR;
+}
 
 /* This routine will reset the value list to 0.0 */
-int exprValListClear(exprValList *vlist)
-    {
-    if(vlist == NULL)
-        return EXPR_ERROR_NOERROR;
+int exprValListClear(exprValList * vlist)
+{
+	if (vlist == NULL)
+		return EXPR_ERROR_NOERROR;
 
-    exprValListResetData(vlist->head);
+	exprValListResetData(vlist->head);
 
-    return EXPR_ERROR_NOERROR;
-    }
+	return EXPR_ERROR_NOERROR;
+}
 
 /* This routine will free any child nodes, and then free itself */
-static void exprValListFreeData(exprVal *val)
-    {
-    exprVal *next;
-    
-    while(val)
-        {
-        /* Remember the next */
-        next = val->next;
-        
-        /* Free name */
-        exprFreeMem(val->vname);
-
-        /* Free ourself */
-        exprFreeMem(val);
-        
-        val = next;
-        }
-    }
+static void exprValListFreeData(exprVal * val)
+{
+	exprVal *next;
+
+	while (val) {
+		/* Remember the next */
+		next = val->next;
+
+		/* Free name */
+		exprFreeMem(val->vname);
+
+		/* Free ourself */
+		exprFreeMem(val);
+
+		val = next;
+	}
+}
 
 /* This routine will reset variables to 0.0 */
-static void exprValListResetData(exprVal *val)
-    {
-    while(val)
-        {
-        /* Reset data */
-        if(val->vptr)
-            *(val->vptr) = 0.0;
-      
-        val->vval = 0.0;
-        
-        val = val->next;
-        }
-    }
+static void exprValListResetData(exprVal * val)
+{
+	while (val) {
+		/* Reset data */
+		if (val->vptr)
+			*(val->vptr) = 0.0;
+
+		val->vval = 0.0;
+
+		val = val->next;
+	}
+}
 
 /* This routine will create the value object */
-static exprVal *exprCreateVal(char *name, EXPRTYPE val, EXPRTYPE *addr)
-    {
-    exprVal *tmp;
-    char *vtmp;
-
-    /* Name already tested in exprValListAdd */
-
-    /* Create it */
-    tmp = exprAllocMem(sizeof(exprVal));
-    if(tmp == NULL)
-        return NULL;
-
-    /* Allocate space for the name */
-    vtmp = exprAllocMem(strlen(name) + 1);
-
-    if(vtmp == NULL)
-        {
-        exprFreeMem(tmp);
-        return NULL;
-        }
-
-    /* Copy the data over */
-    strcpy(vtmp, name);
-    tmp->vname = vtmp;
-    tmp->vval = val;
-    tmp->vptr = addr;
+static exprVal *exprCreateVal(char *name, EXPRTYPE val, EXPRTYPE * addr)
+{
+	exprVal *tmp;
+	char *vtmp;
+
+	/* Name already tested in exprValListAdd */
+
+	/* Create it */
+	tmp = exprAllocMem(sizeof(exprVal));
+	if (tmp == NULL)
+		return NULL;
+
+	/* Allocate space for the name */
+	vtmp = exprAllocMem(strlen(name) + 1);
+
+	if (vtmp == NULL) {
+		exprFreeMem(tmp);
+		return NULL;
+	}
+
+	/* Copy the data over */
+	strcpy(vtmp, name);
+	tmp->vname = vtmp;
+	tmp->vval = val;
+	tmp->vptr = addr;
 
-    return tmp;
-    }
+	return tmp;
+}

Modified: freeswitch/trunk/src/mod/applications/mod_expr/mod_expr.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_expr/mod_expr.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_expr/mod_expr.c	Tue May 27 00:54:52 2008
@@ -33,145 +33,145 @@
 
 /* Breaker function to break out of long expression functions
    such as the 'for' function */
-int breaker(exprObj *o)
+int breaker(exprObj * o)
 {
-    /* Return nonzero to break out */
-    return -1;
+	/* Return nonzero to break out */
+	return -1;
 }
 
 
 SWITCH_STANDARD_API(expr_function)
 {
-    exprObj *e = NULL;
-    exprFuncList *f = NULL;
-    exprValList *v = NULL;
-    exprValList *c = NULL;
-    EXPRTYPE last_expr;
+	exprObj *e = NULL;
+	exprFuncList *f = NULL;
+	exprValList *v = NULL;
+	exprValList *c = NULL;
+	EXPRTYPE last_expr;
 	const char *expr;
 	int err;
-    char val[512] = "", *p;
-    char *m_cmd = NULL;
-    size_t len;
-
-    if (switch_strlen_zero(cmd)) {
-        goto error;
-    }
-
-    len = strlen(cmd) + 3;
-
-
-    m_cmd = malloc(len);
-    switch_assert(m_cmd);
-    switch_copy_string(m_cmd, cmd, len);
-    
-    for (p = m_cmd; p && *p; p++) {
-        if (*p == '|') {
-            *p = ';';
-        }
-    }
-
-    p = m_cmd + (strlen(m_cmd) - 1);
-    if (*p != ';') {
-        p++;
-        *p = ';';
-        p++;
-        *p = '\0';
-    }
-
-    expr = m_cmd;
-
-    /* Create function list */
-    err = exprFuncListCreate(&f);
-    if (err != EXPR_ERROR_NOERROR)
-        goto error;
-
-    /* Init function list with internal functions */
-    err = exprFuncListInit(f);
-    if (err != EXPR_ERROR_NOERROR)
-        goto error;
-
-    /* Add custom function */
-    //err = exprFuncListAdd(f, my_func, "myfunc", 1, 1, 1, 1);
-    //if (err != EXPR_ERROR_NOERROR)
+	char val[512] = "", *p;
+	char *m_cmd = NULL;
+	size_t len;
+
+	if (switch_strlen_zero(cmd)) {
+		goto error;
+	}
+
+	len = strlen(cmd) + 3;
+
+
+	m_cmd = malloc(len);
+	switch_assert(m_cmd);
+	switch_copy_string(m_cmd, cmd, len);
+
+	for (p = m_cmd; p && *p; p++) {
+		if (*p == '|') {
+			*p = ';';
+		}
+	}
+
+	p = m_cmd + (strlen(m_cmd) - 1);
+	if (*p != ';') {
+		p++;
+		*p = ';';
+		p++;
+		*p = '\0';
+	}
+
+	expr = m_cmd;
+
+	/* Create function list */
+	err = exprFuncListCreate(&f);
+	if (err != EXPR_ERROR_NOERROR)
+		goto error;
+
+	/* Init function list with internal functions */
+	err = exprFuncListInit(f);
+	if (err != EXPR_ERROR_NOERROR)
+		goto error;
+
+	/* Add custom function */
+	//err = exprFuncListAdd(f, my_func, "myfunc", 1, 1, 1, 1);
+	//if (err != EXPR_ERROR_NOERROR)
 	//goto error;
 
-    /* Create constant list */
-    err = exprValListCreate(&c);
-    if (err != EXPR_ERROR_NOERROR)
-        goto error;
-
-    /* Init constant list with internal constants */
-    err = exprValListInit(c);
-    if (err != EXPR_ERROR_NOERROR)
-        goto error;
-
-    /* Create variable list */
-    err = exprValListCreate(&v);
-    if (err != EXPR_ERROR_NOERROR)
-        goto error;
-
-    /* Create expression object */
-    err = exprCreate(&e, f, v, c, breaker, NULL);
-    if (err != EXPR_ERROR_NOERROR)
-        goto error;
-
-    /* Parse expression */
-    err = exprParse(e, (char *)expr);
-
-    if (err != EXPR_ERROR_NOERROR)
-        goto error;
-
-    /* Enable soft errors */
-    //exprSetSoftErrors(e, 1);
-    
+	/* Create constant list */
+	err = exprValListCreate(&c);
+	if (err != EXPR_ERROR_NOERROR)
+		goto error;
+
+	/* Init constant list with internal constants */
+	err = exprValListInit(c);
+	if (err != EXPR_ERROR_NOERROR)
+		goto error;
+
+	/* Create variable list */
+	err = exprValListCreate(&v);
+	if (err != EXPR_ERROR_NOERROR)
+		goto error;
+
+	/* Create expression object */
+	err = exprCreate(&e, f, v, c, breaker, NULL);
+	if (err != EXPR_ERROR_NOERROR)
+		goto error;
+
+	/* Parse expression */
+	err = exprParse(e, (char *) expr);
+
+	if (err != EXPR_ERROR_NOERROR)
+		goto error;
+
+	/* Enable soft errors */
+	//exprSetSoftErrors(e, 1);
+
 	do {
 		err = exprEval(e, &last_expr);
 	} while (err);
 
-    switch_snprintf(val, sizeof(val), "%0.10f", last_expr);
-    for (p = (val + strlen(val) - 1); p != val; p--) {
-        if (*p != '0') {
-            *(p+1) = '\0';
-            break;
-        } 
-    }
+	switch_snprintf(val, sizeof(val), "%0.10f", last_expr);
+	for (p = (val + strlen(val) - 1); p != val; p--) {
+		if (*p != '0') {
+			*(p + 1) = '\0';
+			break;
+		}
+	}
 
-    p = val + strlen(val) - 1;
-    if (*p == '.') {
-        *p = '\0';
-    }
+	p = val + strlen(val) - 1;
+	if (*p == '.') {
+		*p = '\0';
+	}
 
-    stream->write_function(stream, "%s", val);
+	stream->write_function(stream, "%s", val);
 
 
-    goto done;
+	goto done;
 
- error:
-    /* Alert user of error */
-    stream->write_function(stream, "!err!");
+  error:
+	/* Alert user of error */
+	stream->write_function(stream, "!err!");
 
 
- done:
-    /* Do cleanup */
-    if (e) {
-        exprFree(e); 
-    }
+  done:
+	/* Do cleanup */
+	if (e) {
+		exprFree(e);
+	}
 
-    if (f) {
-        exprFuncListFree(f);
-    }
+	if (f) {
+		exprFuncListFree(f);
+	}
 
-    if (v) {
-        exprValListFree(v);
-    }
+	if (v) {
+		exprValListFree(v);
+	}
 
-    if (c) {
-        exprValListFree(c);
-    }
+	if (c) {
+		exprValListFree(c);
+	}
 
-    switch_safe_free(m_cmd);
+	switch_safe_free(m_cmd);
 
-    return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
 
@@ -181,10 +181,10 @@
 SWITCH_MODULE_LOAD_FUNCTION(mod_expr_load)
 {
 	switch_api_interface_t *commands_api_interface;
-    
+
 	/* connect my internal structure to the blank pointer passed to me */
-    *module_interface = switch_loadable_module_create_module_interface(pool, modname);
-    
+	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
+
 	SWITCH_ADD_API(commands_api_interface, "expr", "Eval an expession", expr_function, "<expr>");
 
 

Modified: freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c	Tue May 27 00:54:52 2008
@@ -39,13 +39,13 @@
 #define MAX_PRI 10
 
 struct fifo_node {
-    char *name;
-    switch_mutex_t *mutex;
-    switch_queue_t *fifo_list[MAX_PRI];
-    switch_hash_t *caller_hash;
-    switch_hash_t *consumer_hash;
-    int caller_count;
-    int consumer_count;
+	char *name;
+	switch_mutex_t *mutex;
+	switch_queue_t *fifo_list[MAX_PRI];
+	switch_hash_t *caller_hash;
+	switch_hash_t *consumer_hash;
+	int caller_count;
+	int consumer_count;
 	switch_time_t start_waiting;
 	uint32_t importance;
 };
@@ -57,12 +57,12 @@
 
 static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
 {
-    switch_core_session_t *bleg = (switch_core_session_t *) buf;
+	switch_core_session_t *bleg = (switch_core_session_t *) buf;
 
 	switch (itype) {
 	case SWITCH_INPUT_TYPE_DTMF:
-        {
-            switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
+		{
+			switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
 			switch_channel_t *bchan = switch_core_session_get_channel(bleg);
 			switch_channel_t *channel = switch_core_session_get_channel(session);
 			if (switch_channel_test_flag(switch_core_session_get_channel(session), CF_ORIGINATOR)) {
@@ -71,11 +71,11 @@
 					return SWITCH_STATUS_BREAK;
 				} else if (dtmf->digit == '0') {
 					const char *moh_a = NULL, *moh_b = NULL;
-					
+
 					if (!(moh_b = switch_channel_get_variable(bchan, "fifo_music"))) {
 						moh_b = switch_channel_get_variable(bchan, "hold_music");
 					}
-					
+
 					if (!(moh_a = switch_channel_get_variable(channel, "fifo_hold_music"))) {
 						if (!(moh_a = switch_channel_get_variable(channel, "fifo_music"))) {
 							moh_a = switch_channel_get_variable(channel, "hold_music");
@@ -86,7 +86,7 @@
 					return SWITCH_STATUS_IGNORE;
 				}
 			}
-        }
+		}
 		break;
 	default:
 		break;
@@ -101,17 +101,17 @@
 
 	switch (itype) {
 	case SWITCH_INPUT_TYPE_DTMF:
-        {
-            switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
+		{
+			switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
 			switch_channel_t *channel = switch_core_session_get_channel(session);
 			const char *caller_exit_key = switch_channel_get_variable(channel, "fifo_caller_exit_key");
-			
-            if (caller_exit_key && dtmf->digit == *caller_exit_key) {
+
+			if (caller_exit_key && dtmf->digit == *caller_exit_key) {
 				char *bp = buf;
 				*bp = dtmf->digit;
 				return SWITCH_STATUS_BREAK;
-            }
-        }
+			}
+		}
 		break;
 	default:
 		break;
@@ -125,7 +125,7 @@
 static int node_consumer_wait_count(fifo_node_t *node)
 {
 	int i, len = 0;
-	
+
 	for (i = 0; i < MAX_PRI; i++) {
 		len += switch_queue_size(node->fifo_list[i]);
 	}
@@ -142,9 +142,9 @@
 		if (!(len = switch_queue_size(node->fifo_list[i]))) {
 			continue;
 		}
-		while(len) {
+		while (len) {
 			if (switch_queue_trypop(node->fifo_list[i], &pop) == SWITCH_STATUS_SUCCESS && pop) {
-				if (!done && !strcmp((char *)pop, uuid)) {
+				if (!done && !strcmp((char *) pop, uuid)) {
 					free(pop);
 					done++;
 				} else {
@@ -181,7 +181,7 @@
 static switch_status_t caller_read_frame_callback(switch_core_session_t *session, switch_frame_t *frame, void *user_data)
 {
 	fifo_chime_data_t *cd = (fifo_chime_data_t *) user_data;
-	
+
 	if (!cd) {
 		return SWITCH_STATUS_SUCCESS;
 	}
@@ -220,8 +220,8 @@
 {
 	fifo_node_t *node, **node_list = (fifo_node_t **) user_data;
 	int x = 0, total = 0, i = 0;
-	
-	for(i = 0; ; i++) {
+
+	for (i = 0;; i++) {
 		if (!(node = node_list[i])) {
 			break;
 		}
@@ -230,74 +230,74 @@
 		}
 	}
 
-    if (total) {
-        return SWITCH_STATUS_FALSE;
-    }
+	if (total) {
+		return SWITCH_STATUS_FALSE;
+	}
 
-    return SWITCH_STATUS_SUCCESS;
+	return SWITCH_STATUS_SUCCESS;
 }
 
 static struct {
-    switch_hash_t *fifo_hash;
-    switch_mutex_t *mutex;
-    switch_memory_pool_t *pool;
-    int running;
+	switch_hash_t *fifo_hash;
+	switch_mutex_t *mutex;
+	switch_memory_pool_t *pool;
+	int running;
 } globals;
 
 
 static fifo_node_t *create_node(const char *name, uint32_t importance)
 {
-    fifo_node_t *node;
+	fifo_node_t *node;
 	int x = 0;
-	
-    if (!globals.running) {
-        return NULL;
-    }
 
-    node = switch_core_alloc(globals.pool, sizeof(*node));
-    node->name = switch_core_strdup(globals.pool, name);
+	if (!globals.running) {
+		return NULL;
+	}
+
+	node = switch_core_alloc(globals.pool, sizeof(*node));
+	node->name = switch_core_strdup(globals.pool, name);
 	for (x = 0; x < MAX_PRI; x++) {
 		switch_queue_create(&node->fifo_list[x], SWITCH_CORE_QUEUE_LEN, globals.pool);
 		switch_assert(node->fifo_list[x]);
 	}
-    switch_core_hash_init(&node->caller_hash, globals.pool);
-    switch_core_hash_init(&node->consumer_hash, globals.pool);
-	
-    switch_mutex_init(&node->mutex, SWITCH_MUTEX_NESTED, globals.pool);
-    switch_core_hash_insert(globals.fifo_hash, name, node);
+	switch_core_hash_init(&node->caller_hash, globals.pool);
+	switch_core_hash_init(&node->consumer_hash, globals.pool);
+
+	switch_mutex_init(&node->mutex, SWITCH_MUTEX_NESTED, globals.pool);
+	switch_core_hash_insert(globals.fifo_hash, name, node);
 
 	node->importance = importance;
 
-    return node;
+	return node;
 }
 
 static void send_presence(fifo_node_t *node)
 {
-    switch_event_t *event;
+	switch_event_t *event;
 	int wait_count = 0;
 
-    if (!globals.running) {
-        return;
-    }
+	if (!globals.running) {
+		return;
+	}
 
 	if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", "%s", "park");
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", node->name);
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s", node->name);
-        if ((wait_count = node_consumer_wait_count(node)) > 0) {
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "Active (%d waiting)", wait_count);
-        } else {
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "Idle");
-        }
-        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "rpid", "%s", "unknown");
+		if ((wait_count = node_consumer_wait_count(node)) > 0) {
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "Active (%d waiting)", wait_count);
+		} else {
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "Idle");
+		}
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "rpid", "%s", "unknown");
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
 		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_count", "%d", 0);
 
-        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-state", "%s", wait_count > 0 ? "CS_ROUTING" : "CS_HANGUP");
-        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "unique-id", "%s", node->name);
-        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "answer-state", "%s", wait_count > 0 ? "early" : "terminated");
-        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-direction", "%s", "inbound");
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-state", "%s", wait_count > 0 ? "CS_ROUTING" : "CS_HANGUP");
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "unique-id", "%s", node->name);
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "answer-state", "%s", wait_count > 0 ? "early" : "terminated");
+		switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-direction", "%s", "inbound");
 		switch_event_fire(&event);
 	}
 }
@@ -307,29 +307,29 @@
 {
 	char *to = switch_event_get_header(event, "to");
 	char *dup_to = NULL, *node_name;
-    fifo_node_t *node;
+	fifo_node_t *node;
+
+	if (!globals.running) {
+		return;
+	}
 
-    if (!globals.running) {
-        return;
-    }
-    
 	if (!to || strncasecmp(to, "park+", 5)) {
 		return;
 	}
 
 	dup_to = strdup(to);
-    switch_assert(dup_to);
+	switch_assert(dup_to);
 
 	node_name = dup_to + 5;
 
-    switch_mutex_lock(globals.mutex);
-    if (!(node = switch_core_hash_find(globals.fifo_hash, node_name))) {
-        node = create_node(node_name, 0);
-    }
+	switch_mutex_lock(globals.mutex);
+	if (!(node = switch_core_hash_find(globals.fifo_hash, node_name))) {
+		node = create_node(node_name, 0);
+	}
 
-    send_presence(node);
+	send_presence(node);
 
-    switch_mutex_unlock(globals.mutex);
+	switch_mutex_unlock(globals.mutex);
 
 	switch_safe_free(dup_to);
 }
@@ -344,18 +344,18 @@
 #define FIFO_USAGE "<fifo name> [in [<announce file>|undef] [<music file>|undef] | out [wait|nowait] [<announce file>|undef] [<music file>|undef]]"
 SWITCH_STANDARD_APP(fifo_function)
 {
-    int argc;
-    char *mydata = NULL, *argv[5] = { 0 };
-    fifo_node_t *node = NULL, *node_list[MAX_NODES_PER_CONSUMER+1] = { 0 };
-    switch_channel_t *channel = switch_core_session_get_channel(session);
-    int do_wait = 1, node_count = 0, i = 0;
-    const char *moh = NULL;
-    const char *announce = NULL;
-    switch_event_t *event = NULL;
-    char date[80] = "";
-    switch_time_exp_t tm;
-    switch_time_t ts = switch_timestamp_now();
-    switch_size_t retsize;
+	int argc;
+	char *mydata = NULL, *argv[5] = { 0 };
+	fifo_node_t *node = NULL, *node_list[MAX_NODES_PER_CONSUMER + 1] = { 0 };
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+	int do_wait = 1, node_count = 0, i = 0;
+	const char *moh = NULL;
+	const char *announce = NULL;
+	switch_event_t *event = NULL;
+	char date[80] = "";
+	switch_time_exp_t tm;
+	switch_time_t ts = switch_timestamp_now();
+	switch_size_t retsize;
 	char *list_string;
 	int nlist_count;
 	char *nlist[MAX_NODES_PER_CONSUMER];
@@ -364,51 +364,51 @@
 	const char *arg_inout = NULL;
 	const char *serviced_uuid = NULL;
 
-    if (!globals.running) {
-        return;
-    }
+	if (!globals.running) {
+		return;
+	}
 
 	if (switch_strlen_zero(data)) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Args\n");
-        return;
-    }
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Args\n");
+		return;
+	}
 
-    mydata = switch_core_session_strdup(session, data);
-    switch_assert(mydata);
+	mydata = switch_core_session_strdup(session, data);
+	switch_assert(mydata);
 
 	argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
 	arg_fifo_name = argv[0];
 	arg_inout = argv[1];
-	
-    if (!(arg_fifo_name && arg_inout)) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "USAGE %s\n", FIFO_USAGE);
-        return;
-    }
+
+	if (!(arg_fifo_name && arg_inout)) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "USAGE %s\n", FIFO_USAGE);
+		return;
+	}
 
 	if (!strcasecmp(arg_inout, "out")) {
 		consumer = 1;
 	} else if (strcasecmp(arg_inout, "in")) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "USAGE %s\n", FIFO_USAGE);
-        return;
+		return;
 	}
 
 	list_string = switch_core_session_strdup(session, arg_fifo_name);
 
-    if (!(nlist_count = switch_separate_string(list_string, ',', nlist, (sizeof(nlist) / sizeof(nlist[0]))))) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "USAGE %s\n", FIFO_USAGE);
-        return;
+	if (!(nlist_count = switch_separate_string(list_string, ',', nlist, (sizeof(nlist) / sizeof(nlist[0]))))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "USAGE %s\n", FIFO_USAGE);
+		return;
 	}
 
 	if (!consumer && nlist_count > 1) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "USAGE %s\n", FIFO_USAGE);
-        return;
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "USAGE %s\n", FIFO_USAGE);
+		return;
 	}
 
 	switch_mutex_lock(globals.mutex);
-	for(i = 0; i < nlist_count; i++) {
+	for (i = 0; i < nlist_count; i++) {
 		int importance = 0;
 		char *p;
-		
+
 		if ((p = strrchr(nlist[i], '!'))) {
 			*p++ = '\0';
 			importance = atoi(p);
@@ -422,37 +422,37 @@
 		}
 		node_list[node_count++] = node;
 	}
-    switch_mutex_unlock(globals.mutex);
+	switch_mutex_unlock(globals.mutex);
 
 	moh = switch_channel_get_variable(channel, "fifo_music");
-    announce = switch_channel_get_variable(channel, "fifo_announce");
+	announce = switch_channel_get_variable(channel, "fifo_announce");
 
 	if (consumer) {
 		if (argc > 3) {
-            announce = argv[3];
-        }
+			announce = argv[3];
+		}
 
-        if (argc > 4) {
-            moh = argv[4];
-        }
+		if (argc > 4) {
+			moh = argv[4];
+		}
 
 	} else {
 		if (argc > 2) {
-            announce = argv[2];
-        }
+			announce = argv[2];
+		}
 
-        if (argc > 3) {
-            moh = argv[3];
-        }
+		if (argc > 3) {
+			moh = argv[3];
+		}
 	}
 
 	check_string(announce);
 	check_string(moh);
 
-    if (!consumer && node) {
-        switch_core_session_t *other_session;
+	if (!consumer && node) {
+		switch_core_session_t *other_session;
 		switch_channel_t *other_channel;
-        const char *uuid = switch_core_session_get_uuid(session);
+		const char *uuid = switch_core_session_get_uuid(session);
 		const char *pri;
 		char tmp[25] = "";
 		int p = 0;
@@ -479,8 +479,8 @@
 				cd.orbit_timeout = switch_timestamp(NULL) + to;
 			}
 		}
-		
-		
+
+
 		if (chime_freq) {
 			ftmp = atoi(chime_freq);
 			if (ftmp > 0) {
@@ -490,50 +490,50 @@
 
 
 
-        switch_channel_answer(channel);
+		switch_channel_answer(channel);
+
+		switch_mutex_lock(node->mutex);
+		node->caller_count++;
 
-        switch_mutex_lock(node->mutex);
-        node->caller_count++;
+		switch_core_hash_insert(node->caller_hash, uuid, session);
 
-        switch_core_hash_insert(node->caller_hash, uuid, session);
-		
 
-        if ((pri = switch_channel_get_variable(channel, "fifo_priority"))) {
+		if ((pri = switch_channel_get_variable(channel, "fifo_priority"))) {
 			p = atoi(pri);
 		}
 
 		if (p >= MAX_PRI) {
 			p = MAX_PRI - 1;
 		}
-		
+
 		if (!node_consumer_wait_count(node)) {
 			node->start_waiting = switch_timestamp_now();
 		}
-		
-        switch_queue_push(node->fifo_list[p], (void *)strdup(uuid));
+
+		switch_queue_push(node->fifo_list[p], (void *) strdup(uuid));
 
 		if (!pri) {
 			switch_snprintf(tmp, sizeof(tmp), "%d", p);
 			switch_channel_set_variable(channel, "fifo_priority", tmp);
 		}
 
-        switch_mutex_unlock(node->mutex);
-		
-        ts = switch_timestamp_now();
-        switch_time_exp_lt(&tm, ts);
-        switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
-        switch_channel_set_variable(channel, "fifo_status", "WAITING");
-        switch_channel_set_variable(channel, "fifo_timestamp", date);
-        
+		switch_mutex_unlock(node->mutex);
+
+		ts = switch_timestamp_now();
+		switch_time_exp_lt(&tm, ts);
+		switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+		switch_channel_set_variable(channel, "fifo_status", "WAITING");
+		switch_channel_set_variable(channel, "fifo_timestamp", date);
+
 		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
 			switch_channel_event_set_data(channel, event);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Name", "%s", argv[0]);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "push");
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Slot", "%d", p);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Name", "%s", argv[0]);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "push");
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Slot", "%d", p);
 			switch_event_fire(&event);
 		}
-		
-        switch_channel_set_flag(channel, CF_TAGGED);
+
+		switch_channel_set_flag(channel, CF_TAGGED);
 
 		if (chime_list) {
 			char *list_dup = switch_core_session_strdup(session, chime_list);
@@ -542,12 +542,12 @@
 			cd.next = switch_timestamp(NULL) + cd.freq;
 		}
 
-        send_presence(node);
+		send_presence(node);
 
-		while(switch_channel_ready(channel)) {
+		while (switch_channel_ready(channel)) {
 			switch_input_args_t args = { 0 };
 			char buf[25] = "";
-			
+
 			args.input_callback = moh_on_dtmf;
 			args.buf = buf;
 			args.buflen = sizeof(buf);
@@ -559,7 +559,7 @@
 
 			if (cd.abort || cd.do_orbit) {
 				aborted = 1;
-                goto abort;
+				goto abort;
 			}
 
 			if ((serviced_uuid = switch_channel_get_variable(channel, "fifo_serviced_uuid"))) {
@@ -577,7 +577,7 @@
 			} else {
 				switch_ivr_collect_digits_callback(session, &args, 0);
 			}
-			
+
 			if (caller_exit_key && *buf == *caller_exit_key) {
 				aborted = 1;
 				goto abort;
@@ -596,59 +596,59 @@
 				switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
 			}
 		}
-		
+
 		switch_core_session_flush_private_events(session);
 
 		if (switch_channel_ready(channel)) {
-            if (announce) {
-                switch_ivr_play_file(session, NULL, announce, NULL);
-            }
-        }
-
-        switch_channel_clear_flag(channel, CF_TAGGED);
-		
-	abort:
-		
-        if (!aborted && switch_channel_ready(channel)) {
-            switch_channel_set_state(channel, CS_HIBERNATE);            
-        } else {
-            ts = switch_timestamp_now();
-            switch_time_exp_lt(&tm, ts);
-            switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
-            switch_channel_set_variable(channel, "fifo_status", cd.do_orbit ? "TIMEOUT" : "ABORTED");
-            switch_channel_set_variable(channel, "fifo_timestamp", date);
-            
-            if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
-                switch_channel_event_set_data(channel, event);
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Name", "%s", argv[0]);
-                switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Action", cd.do_orbit ? "timeout" : "abort");
-                switch_event_fire(&event);
-            }
-            switch_mutex_lock(node->mutex);
+			if (announce) {
+				switch_ivr_play_file(session, NULL, announce, NULL);
+			}
+		}
+
+		switch_channel_clear_flag(channel, CF_TAGGED);
+
+	  abort:
+
+		if (!aborted && switch_channel_ready(channel)) {
+			switch_channel_set_state(channel, CS_HIBERNATE);
+		} else {
+			ts = switch_timestamp_now();
+			switch_time_exp_lt(&tm, ts);
+			switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+			switch_channel_set_variable(channel, "fifo_status", cd.do_orbit ? "TIMEOUT" : "ABORTED");
+			switch_channel_set_variable(channel, "fifo_timestamp", date);
+
+			if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
+				switch_channel_event_set_data(channel, event);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Name", "%s", argv[0]);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Action", cd.do_orbit ? "timeout" : "abort");
+				switch_event_fire(&event);
+			}
+			switch_mutex_lock(node->mutex);
 			node_remove_uuid(node, uuid);
-            node->caller_count--;
-            switch_core_hash_delete(node->caller_hash, uuid);
-            switch_mutex_unlock(node->mutex);
-            send_presence(node);
-			
-        }
-        
+			node->caller_count--;
+			switch_core_hash_delete(node->caller_hash, uuid);
+			switch_mutex_unlock(node->mutex);
+			send_presence(node);
+
+		}
+
 		if (cd.do_orbit && cd.orbit_exten) {
-            if (orbit_ann) {
-                switch_ivr_play_file(session, NULL, orbit_ann, NULL);
-            }
+			if (orbit_ann) {
+				switch_ivr_play_file(session, NULL, orbit_ann, NULL);
+			}
 			switch_ivr_session_transfer(session, cd.orbit_exten, NULL, NULL);
 		}
 
-        return;
-    } else { /* consumer */
-        void *pop = NULL;
-        switch_frame_t *read_frame;
-        switch_status_t status;
-        char *uuid;
-        int done = 0;
-        switch_core_session_t *other_session;
-        switch_input_args_t args = { 0 };
+		return;
+	} else {					/* consumer */
+		void *pop = NULL;
+		switch_frame_t *read_frame;
+		switch_status_t status;
+		char *uuid;
+		int done = 0;
+		switch_core_session_t *other_session;
+		switch_input_args_t args = { 0 };
 		const char *pop_order = NULL;
 		int custom_pop = 0;
 		int pop_array[MAX_PRI] = { 0 };
@@ -660,7 +660,7 @@
 		const char *strat_str = switch_channel_get_variable(channel, "fifo_strategy");
 		fifo_strategy_t strat = STRAT_WAITING_LONGER;
 
-		
+
 		if (!switch_strlen_zero(strat_str)) {
 			if (!strcasecmp(strat_str, "more_ppl")) {
 				strat = STRAT_MORE_PPL;
@@ -687,8 +687,8 @@
 			my_id = switch_core_session_get_uuid(session);
 		}
 
-        
-        if (do_wait) {
+
+		if (do_wait) {
 			for (i = 0; i < node_count; i++) {
 				if (!(node = node_list[i])) {
 					continue;
@@ -698,28 +698,28 @@
 				switch_core_hash_insert(node->consumer_hash, switch_core_session_get_uuid(session), session);
 				switch_mutex_unlock(node->mutex);
 			}
-            switch_channel_answer(channel);
-        }
-		
+			switch_channel_answer(channel);
+		}
+
 		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
-            switch_channel_event_set_data(channel, event);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Name", "%s", argv[0]);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "consumer_start");
-            switch_event_fire(&event);
-        }
-
-        ts = switch_timestamp_now();
-        switch_time_exp_lt(&tm, ts);
-        switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
-        switch_channel_set_variable(channel, "fifo_status", "WAITING");
-        switch_channel_set_variable(channel, "fifo_timestamp", date);
+			switch_channel_event_set_data(channel, event);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Name", "%s", argv[0]);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "consumer_start");
+			switch_event_fire(&event);
+		}
+
+		ts = switch_timestamp_now();
+		switch_time_exp_lt(&tm, ts);
+		switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+		switch_channel_set_variable(channel, "fifo_status", "WAITING");
+		switch_channel_set_variable(channel, "fifo_timestamp", date);
 
-        if ((pop_order = switch_channel_get_variable(channel, "fifo_pop_order"))) {
+		if ((pop_order = switch_channel_get_variable(channel, "fifo_pop_order"))) {
 			char *tmp = switch_core_session_strdup(session, pop_order);
 			int x;
 			custom_pop = switch_separate_string(tmp, ',', pop_list, (sizeof(pop_list) / sizeof(pop_list[0])));
 			if (custom_pop >= MAX_PRI) {
-				custom_pop = MAX_PRI -1;
+				custom_pop = MAX_PRI - 1;
 			}
 
 			for (x = 0; x < custom_pop; x++) {
@@ -731,33 +731,33 @@
 				}
 			}
 		}
-		
-		while(switch_channel_ready(channel)) {
+
+		while (switch_channel_ready(channel)) {
 			int x = 0, winner = -1;
 			switch_time_t longest = 0xFFFFFFFFFFFFFFFF / 2;
 			uint32_t importance = 0, waiting = 0, most_waiting = 0;
-			
+
 			pop = NULL;
-			
-            if (moh && do_wait) {
+
+			if (moh && do_wait) {
 				switch_status_t moh_status = switch_ivr_play_file(session, NULL, moh, &args);
 				memset(&args, 0, sizeof(args));
-                args.read_frame_callback = consumer_read_frame_callback;
-                args.user_data = node_list;
-                switch_ivr_play_file(session, NULL, moh, &args);
-				
+				args.read_frame_callback = consumer_read_frame_callback;
+				args.user_data = node_list;
+				switch_ivr_play_file(session, NULL, moh, &args);
+
 				if (!SWITCH_READ_ACCEPTABLE(moh_status)) {
 					break;
 				}
-            }
-			
-			for(i = 0; i < node_count; i++) {
+			}
+
+			for (i = 0; i < node_count; i++) {
 				if (!(node = node_list[i])) {
 					continue;
 				}
-				
+
 				if ((waiting = node_consumer_wait_count(node))) {
-					
+
 					if (!importance || node->importance > importance) {
 						if (strat == STRAT_WAITING_LONGER) {
 							if (node->start_waiting < longest) {
@@ -771,14 +771,14 @@
 							}
 						}
 					}
-					
+
 					if (node->importance > importance) {
 						importance = node->importance;
 					}
 				}
 
 			}
-			
+
 			if (winner > -1) {
 				node = node_list[winner];
 			} else {
@@ -787,76 +787,76 @@
 
 			if (node) {
 				if (custom_pop) {
-					for(x = 0; x < MAX_PRI; x++) {
+					for (x = 0; x < MAX_PRI; x++) {
 						if (switch_queue_trypop(node->fifo_list[pop_array[x]], &pop) == SWITCH_STATUS_SUCCESS && pop) {
 							break;
 						}
 					}
 				} else {
-					for(x = 0; x < MAX_PRI; x++) {
+					for (x = 0; x < MAX_PRI; x++) {
 						if (switch_queue_trypop(node->fifo_list[x], &pop) == SWITCH_STATUS_SUCCESS && pop) {
 							break;
 						}
 					}
 				}
-			
+
 				if (pop && !node_consumer_wait_count(node)) {
 					switch_mutex_lock(node->mutex);
 					node->start_waiting = 0;
 					switch_mutex_unlock(node->mutex);
 				}
 			}
-			
+
 
 			if (!pop) {
-                if (!do_wait) {
-                    break;
-                }
-
-                status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
-
-                if (!SWITCH_READ_ACCEPTABLE(status)) {
-                    break;
-                }
-
-                continue;
-            }
-			
-            uuid = (char *) pop;
+				if (!do_wait) {
+					break;
+				}
+
+				status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
+
+				if (!SWITCH_READ_ACCEPTABLE(status)) {
+					break;
+				}
+
+				continue;
+			}
+
+			uuid = (char *) pop;
 			pop = NULL;
 
-            if (node && (other_session = switch_core_session_locate(uuid))) {
-                switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
-                switch_caller_profile_t *cloned_profile;
+			if (node && (other_session = switch_core_session_locate(uuid))) {
+				switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
+				switch_caller_profile_t *cloned_profile;
 				const char *o_announce = NULL;
 				const char *record_template = switch_channel_get_variable(channel, "fifo_record_template");
 				char *expanded = NULL;
-				
+
 				if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
-                    switch_channel_event_set_data(other_channel, event);
-                    switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Name", "%s", argv[0]);
-                    switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "caller_pop");
-                    switch_event_fire(&event);
-                }
-
-                if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
-                    switch_channel_event_set_data(channel, event);
-                    switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Name", "%s", argv[0]);
-                    switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "consumer_pop");
-                    switch_event_fire(&event);
-                }
+					switch_channel_event_set_data(other_channel, event);
+					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Name", "%s", argv[0]);
+					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "caller_pop");
+					switch_event_fire(&event);
+				}
+
+				if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
+					switch_channel_event_set_data(channel, event);
+					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Name", "%s", argv[0]);
+					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "consumer_pop");
+					switch_event_fire(&event);
+				}
 
 				if ((o_announce = switch_channel_get_variable(other_channel, "fifo_override_announce"))) {
 					announce = o_announce;
 				}
 
 				if (announce) {
-                    switch_ivr_play_file(session, NULL, announce, NULL);
-                } else {
+					switch_ivr_play_file(session, NULL, announce, NULL);
+				} else {
 					switch_ivr_sleep(session, 500);
-                }
-				
-				
+				}
+
+
 				switch_channel_set_variable(other_channel, "fifo_serviced_by", my_id);
 				switch_channel_set_variable(other_channel, "fifo_serviced_uuid", switch_core_session_get_uuid(session));
 
@@ -868,7 +868,7 @@
 						break;
 					}
 				}
-				
+
 				if (!(switch_channel_ready(channel))) {
 					switch_channel_hangup(other_channel, SWITCH_CAUSE_NORMAL_CLEARING);
 					switch_core_session_rwunlock(other_session);
@@ -876,28 +876,28 @@
 				}
 
 
-                switch_channel_answer(channel);
+				switch_channel_answer(channel);
 				cloned_profile = switch_caller_profile_clone(other_session, switch_channel_get_caller_profile(channel));
-                switch_assert(cloned_profile);
-                switch_channel_set_originator_caller_profile(other_channel, cloned_profile);
+				switch_assert(cloned_profile);
+				switch_channel_set_originator_caller_profile(other_channel, cloned_profile);
 
 				cloned_profile = switch_caller_profile_clone(session, switch_channel_get_caller_profile(other_channel));
-                switch_assert(cloned_profile);
-                switch_assert(cloned_profile->next == NULL);
-                switch_channel_set_originatee_caller_profile(channel, cloned_profile);
-				
-                ts = switch_timestamp_now();
-                switch_time_exp_lt(&tm, ts);
-                switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
-                switch_channel_set_variable(channel, "fifo_status", "TALKING");
-                switch_channel_set_variable(channel, "fifo_target", uuid);
-                switch_channel_set_variable(channel, "fifo_timestamp", date);
-                
-                switch_channel_set_variable(other_channel, "fifo_status", "TALKING");
-                switch_channel_set_variable(other_channel, "fifo_timestamp", date);
-                switch_channel_set_variable(other_channel, "fifo_target", switch_core_session_get_uuid(session));
+				switch_assert(cloned_profile);
+				switch_assert(cloned_profile->next == NULL);
+				switch_channel_set_originatee_caller_profile(channel, cloned_profile);
+
+				ts = switch_timestamp_now();
+				switch_time_exp_lt(&tm, ts);
+				switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+				switch_channel_set_variable(channel, "fifo_status", "TALKING");
+				switch_channel_set_variable(channel, "fifo_target", uuid);
+				switch_channel_set_variable(channel, "fifo_timestamp", date);
+
+				switch_channel_set_variable(other_channel, "fifo_status", "TALKING");
+				switch_channel_set_variable(other_channel, "fifo_timestamp", date);
+				switch_channel_set_variable(other_channel, "fifo_target", switch_core_session_get_uuid(session));
 
-                send_presence(node);
+				send_presence(node);
 
 
 				if (record_template) {
@@ -905,7 +905,7 @@
 					switch_ivr_record_session(session, expanded, 0, NULL);
 				}
 
-                switch_ivr_multi_threaded_bridge(session, other_session, on_dtmf, other_session, session);
+				switch_ivr_multi_threaded_bridge(session, other_session, on_dtmf, other_session, session);
 
 				if (record_template) {
 					switch_ivr_stop_record_session(session, expanded);
@@ -914,26 +914,26 @@
 					}
 				}
 
-                ts = switch_timestamp_now();
-                switch_time_exp_lt(&tm, ts);
-                switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
-                switch_channel_set_variable(channel, "fifo_status", "WAITING");
-                switch_channel_set_variable(channel, "fifo_timestamp", date);
-
-                switch_channel_set_variable(other_channel, "fifo_status", "DONE");
-                switch_channel_set_variable(other_channel, "fifo_timestamp", date);
-                
-                switch_mutex_lock(node->mutex);
-                node->caller_count--;
-                switch_core_hash_delete(node->caller_hash, uuid);
-                switch_mutex_unlock(node->mutex);
-                send_presence(node);
-                switch_core_session_rwunlock(other_session);
-
-
-                if (!do_wait) {
-                    done = 1;
-                }
+				ts = switch_timestamp_now();
+				switch_time_exp_lt(&tm, ts);
+				switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
+				switch_channel_set_variable(channel, "fifo_status", "WAITING");
+				switch_channel_set_variable(channel, "fifo_timestamp", date);
+
+				switch_channel_set_variable(other_channel, "fifo_status", "DONE");
+				switch_channel_set_variable(other_channel, "fifo_timestamp", date);
+
+				switch_mutex_lock(node->mutex);
+				node->caller_count--;
+				switch_core_hash_delete(node->caller_hash, uuid);
+				switch_mutex_unlock(node->mutex);
+				send_presence(node);
+				switch_core_session_rwunlock(other_session);
+
+
+				if (!do_wait) {
+					done = 1;
+				}
 
 				fifo_consumer_wrapup_sound = switch_channel_get_variable(channel, "fifo_consumer_wrapup_sound");
 				fifo_consumer_wrapup_key = switch_channel_get_variable(channel, "fifo_consumer_wrapup_key");
@@ -947,33 +947,33 @@
 				}
 
 				if (!switch_strlen_zero(fifo_consumer_wrapup_key) && strcmp(buf, fifo_consumer_wrapup_key)) {
-					for(;;) {
-						char terminator = 0;                        
-						switch_ivr_collect_digits_count(session, buf, sizeof(buf)-1, 1, fifo_consumer_wrapup_key, &terminator, 0, 0, 0);
+					for (;;) {
+						char terminator = 0;
+						switch_ivr_collect_digits_count(session, buf, sizeof(buf) - 1, 1, fifo_consumer_wrapup_key, &terminator, 0, 0, 0);
 						if (terminator == *fifo_consumer_wrapup_key) {
 							break;
 						}
 					}
 				}
 			}
-			
-            switch_safe_free(uuid);
 
-            if (done) {
-                break;
-            }
-        }
-		
+			switch_safe_free(uuid);
+
+			if (done) {
+				break;
+			}
+		}
+
 		if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
-            switch_channel_event_set_data(channel, event);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Name", "%s", argv[0]);
-            switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "consumer_stop");
-            switch_event_fire(&event);
-        }
+			switch_channel_event_set_data(channel, event);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Name", "%s", argv[0]);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "consumer_stop");
+			switch_event_fire(&event);
+		}
 
-        if (do_wait) {
+		if (do_wait) {
 			for (i = 0; i < node_count; i++) {
-                if (!(node = node_list[i])) {
+				if (!(node = node_list[i])) {
 					continue;
 				}
 				switch_mutex_lock(node->mutex);
@@ -981,150 +981,150 @@
 				node->consumer_count--;
 				switch_mutex_unlock(node->mutex);
 			}
-        }
-		
-    }
+		}
+
+	}
 }
 
 static int xml_hash(switch_xml_t xml, switch_hash_t *hash, char *container, char *tag, int cc_off, int verbose)
 {
-    switch_xml_t x_tmp, x_caller, x_cp, variables;
-    switch_hash_index_t *hi;
-    switch_core_session_t *session;
-    switch_channel_t *channel;
-    void *val;
-    const void *var;
-
-    x_tmp = switch_xml_add_child_d(xml, container, cc_off++);
-    switch_assert(x_tmp);
-
-    for (hi = switch_hash_first(NULL, hash); hi; hi = switch_hash_next(hi)) {
-        int c_off = 0, d_off = 0;
-        const char *status;
-        const char *ts;
-
-        switch_hash_this(hi, &var, NULL, &val);
-        session = (switch_core_session_t *) val;
-        channel = switch_core_session_get_channel(session);
-        x_caller = switch_xml_add_child_d(x_tmp, tag, c_off++);
-        switch_assert(x_caller);
-        
-        switch_xml_set_attr_d(x_caller, "uuid", switch_core_session_get_uuid(session));
-
-        if ((status = switch_channel_get_variable(channel, "fifo_status"))) {
-            switch_xml_set_attr_d(x_caller, "status", status);
-        }
-
-        if ((ts = switch_channel_get_variable(channel, "fifo_timestamp"))) {
-            switch_xml_set_attr_d(x_caller, "timestamp", ts);
-        }
-
-        if ((ts = switch_channel_get_variable(channel, "fifo_target"))) {
-            switch_xml_set_attr_d(x_caller, "target", ts);
-        }
-        
+	switch_xml_t x_tmp, x_caller, x_cp, variables;
+	switch_hash_index_t *hi;
+	switch_core_session_t *session;
+	switch_channel_t *channel;
+	void *val;
+	const void *var;
+
+	x_tmp = switch_xml_add_child_d(xml, container, cc_off++);
+	switch_assert(x_tmp);
+
+	for (hi = switch_hash_first(NULL, hash); hi; hi = switch_hash_next(hi)) {
+		int c_off = 0, d_off = 0;
+		const char *status;
+		const char *ts;
+
+		switch_hash_this(hi, &var, NULL, &val);
+		session = (switch_core_session_t *) val;
+		channel = switch_core_session_get_channel(session);
+		x_caller = switch_xml_add_child_d(x_tmp, tag, c_off++);
+		switch_assert(x_caller);
+
+		switch_xml_set_attr_d(x_caller, "uuid", switch_core_session_get_uuid(session));
+
+		if ((status = switch_channel_get_variable(channel, "fifo_status"))) {
+			switch_xml_set_attr_d(x_caller, "status", status);
+		}
+
+		if ((ts = switch_channel_get_variable(channel, "fifo_timestamp"))) {
+			switch_xml_set_attr_d(x_caller, "timestamp", ts);
+		}
+
+		if ((ts = switch_channel_get_variable(channel, "fifo_target"))) {
+			switch_xml_set_attr_d(x_caller, "target", ts);
+		}
+
 		if (!(x_cp = switch_xml_add_child_d(x_caller, "caller_profile", d_off++))) {
-            abort();
+			abort();
 		}
-        if (verbose) {
-            d_off += switch_ivr_set_xml_profile_data(x_cp, switch_channel_get_caller_profile(channel), d_off);
-        
-            if (!(variables = switch_xml_add_child_d(x_caller, "variables", c_off++))) {
-                abort();
-            }
-        
-            switch_ivr_set_xml_chan_vars(variables, channel, c_off);
-        }
-        
-    }
+		if (verbose) {
+			d_off += switch_ivr_set_xml_profile_data(x_cp, switch_channel_get_caller_profile(channel), d_off);
+
+			if (!(variables = switch_xml_add_child_d(x_caller, "variables", c_off++))) {
+				abort();
+			}
+
+			switch_ivr_set_xml_chan_vars(variables, channel, c_off);
+		}
+
+	}
 
-    return cc_off;
+	return cc_off;
 }
 
 static void list_node(fifo_node_t *node, switch_xml_t x_report, int *off, int verbose)
 {
 
-    switch_xml_t x_fifo;
-    int cc_off = 0;
-    char buffer[35];
+	switch_xml_t x_fifo;
+	int cc_off = 0;
+	char buffer[35];
 	char *tmp = buffer;
 
-    x_fifo = switch_xml_add_child_d(x_report, "fifo", (*off)++);;
-    switch_assert(x_fifo);
+	x_fifo = switch_xml_add_child_d(x_report, "fifo", (*off)++);;
+	switch_assert(x_fifo);
+
+	switch_xml_set_attr_d(x_fifo, "name", node->name);
+	switch_snprintf(tmp, sizeof(buffer), "%d", node->consumer_count);
+	switch_xml_set_attr_d(x_fifo, "consumer_count", tmp);
+	switch_snprintf(tmp, sizeof(buffer), "%d", node->caller_count);
+	switch_xml_set_attr_d(x_fifo, "caller_count", tmp);
+	switch_snprintf(tmp, sizeof(buffer), "%d", node_consumer_wait_count(node));
+	switch_xml_set_attr_d(x_fifo, "waiting_count", tmp);
+	switch_snprintf(tmp, sizeof(buffer), "%u", node->importance);
+	switch_xml_set_attr_d(x_fifo, "importance", tmp);
 
-    switch_xml_set_attr_d(x_fifo, "name", node->name);
-    switch_snprintf(tmp, sizeof(buffer), "%d", node->consumer_count);
-    switch_xml_set_attr_d(x_fifo, "consumer_count", tmp);
-    switch_snprintf(tmp, sizeof(buffer), "%d", node->caller_count);
-    switch_xml_set_attr_d(x_fifo, "caller_count", tmp);
-    switch_snprintf(tmp, sizeof(buffer), "%d", node_consumer_wait_count(node));
-    switch_xml_set_attr_d(x_fifo, "waiting_count", tmp);
-    switch_snprintf(tmp, sizeof(buffer), "%u", node->importance);
-    switch_xml_set_attr_d(x_fifo, "importance", tmp);
-    
-    cc_off = xml_hash(x_fifo, node->caller_hash, "callers", "caller", cc_off, verbose);
-    cc_off = xml_hash(x_fifo, node->consumer_hash, "consumers", "consumer", cc_off, verbose);
+	cc_off = xml_hash(x_fifo, node->caller_hash, "callers", "caller", cc_off, verbose);
+	cc_off = xml_hash(x_fifo, node->consumer_hash, "consumers", "consumer", cc_off, verbose);
 
 }
 
 #define FIFO_API_SYNTAX "list|list_verbose|count|importance [<fifo name>]"
 SWITCH_STANDARD_API(fifo_api_function)
 {
-    int len = 0;
-    fifo_node_t *node;
-    char *data = NULL;
-    int argc = 0;
-    char *argv[5] = { 0 };
-    switch_hash_index_t *hi;
-    void *val;
-    const void *var;
-    int x = 0, verbose = 0;
-
-
-    if (!globals.running) {
-        return SWITCH_STATUS_FALSE;
-    }
-
-    if (!switch_strlen_zero(cmd)) {
-        data = strdup(cmd);
-        switch_assert(data);
-    }
-    
-    if (switch_strlen_zero(cmd) || (argc = switch_separate_string(data, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) < 1 || !argv[0]) {
-        stream->write_function(stream, "%s\n", FIFO_API_SYNTAX);
-        return SWITCH_STATUS_SUCCESS;
-    }
-
-    switch_mutex_lock(globals.mutex);
-    verbose = !strcasecmp(argv[0], "list_verbose");
-
-    if (!strcasecmp(argv[0], "list") || verbose) {    
-        char *xml_text = NULL;
-        switch_xml_t x_report = switch_xml_new("fifo_report");
-        switch_assert(x_report);
-		
-        if (argc < 2) {
-            for (hi = switch_hash_first(NULL, globals.fifo_hash); hi; hi = switch_hash_next(hi)) {
-                switch_hash_this(hi, &var, NULL, &val);
-                node = (fifo_node_t *) val;
-                switch_mutex_lock(node->mutex);
-                list_node(node, x_report, &x, verbose);
-                switch_mutex_unlock(node->mutex);
-            }
-        } else {
-            if ((node = switch_core_hash_find(globals.fifo_hash, argv[1]))) {
-                switch_mutex_lock(node->mutex);
-                list_node(node, x_report, &x, verbose);
-                switch_mutex_unlock(node->mutex);
-            }
-        }
-        xml_text = switch_xml_toxml(x_report, SWITCH_FALSE);
-        switch_assert(xml_text);
-        stream->write_function(stream, "%s\n", xml_text);
-        switch_xml_free(x_report);
-        switch_safe_free(xml_text);
-        
-    } else if (!strcasecmp(argv[0], "importance")) {
+	int len = 0;
+	fifo_node_t *node;
+	char *data = NULL;
+	int argc = 0;
+	char *argv[5] = { 0 };
+	switch_hash_index_t *hi;
+	void *val;
+	const void *var;
+	int x = 0, verbose = 0;
+
+
+	if (!globals.running) {
+		return SWITCH_STATUS_FALSE;
+	}
+
+	if (!switch_strlen_zero(cmd)) {
+		data = strdup(cmd);
+		switch_assert(data);
+	}
+
+	if (switch_strlen_zero(cmd) || (argc = switch_separate_string(data, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) < 1 || !argv[0]) {
+		stream->write_function(stream, "%s\n", FIFO_API_SYNTAX);
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+	switch_mutex_lock(globals.mutex);
+	verbose = !strcasecmp(argv[0], "list_verbose");
+
+	if (!strcasecmp(argv[0], "list") || verbose) {
+		char *xml_text = NULL;
+		switch_xml_t x_report = switch_xml_new("fifo_report");
+		switch_assert(x_report);
+
+		if (argc < 2) {
+			for (hi = switch_hash_first(NULL, globals.fifo_hash); hi; hi = switch_hash_next(hi)) {
+				switch_hash_this(hi, &var, NULL, &val);
+				node = (fifo_node_t *) val;
+				switch_mutex_lock(node->mutex);
+				list_node(node, x_report, &x, verbose);
+				switch_mutex_unlock(node->mutex);
+			}
+		} else {
+			if ((node = switch_core_hash_find(globals.fifo_hash, argv[1]))) {
+				switch_mutex_lock(node->mutex);
+				list_node(node, x_report, &x, verbose);
+				switch_mutex_unlock(node->mutex);
+			}
+		}
+		xml_text = switch_xml_toxml(x_report, SWITCH_FALSE);
+		switch_assert(xml_text);
+		stream->write_function(stream, "%s\n", xml_text);
+		switch_xml_free(x_report);
+		switch_safe_free(xml_text);
+
+	} else if (!strcasecmp(argv[0], "importance")) {
 		if ((node = switch_core_hash_find(globals.fifo_hash, argv[1]))) {
 			int importance = 0;
 			if (argc > 2) {
@@ -1138,40 +1138,40 @@
 		} else {
 			stream->write_function(stream, "no fifo by that name\n");
 		}
-    } else if (!strcasecmp(argv[0], "count")) {
-        if (argc < 2) {
-            for (hi = switch_hash_first(NULL, globals.fifo_hash); hi; hi = switch_hash_next(hi)) {
-                switch_hash_this(hi, &var, NULL, &val);
-                node = (fifo_node_t *) val;
+	} else if (!strcasecmp(argv[0], "count")) {
+		if (argc < 2) {
+			for (hi = switch_hash_first(NULL, globals.fifo_hash); hi; hi = switch_hash_next(hi)) {
+				switch_hash_this(hi, &var, NULL, &val);
+				node = (fifo_node_t *) val;
 				len = node_consumer_wait_count(node);
-                switch_mutex_lock(node->mutex);
-                stream->write_function(stream, "%s:%d:%d:%d\n", (char *)var, node->consumer_count, node->caller_count, len);
-                switch_mutex_unlock(node->mutex);
-                x++;
-            }
-            
-            if (!x) {
-                stream->write_function(stream, "none\n");
-            }
-        } else if ((node = switch_core_hash_find(globals.fifo_hash, argv[1]))) {
+				switch_mutex_lock(node->mutex);
+				stream->write_function(stream, "%s:%d:%d:%d\n", (char *) var, node->consumer_count, node->caller_count, len);
+				switch_mutex_unlock(node->mutex);
+				x++;
+			}
+
+			if (!x) {
+				stream->write_function(stream, "none\n");
+			}
+		} else if ((node = switch_core_hash_find(globals.fifo_hash, argv[1]))) {
 			len = node_consumer_wait_count(node);
-            switch_mutex_lock(node->mutex);
-            stream->write_function(stream, "%s:%d:%d:%d\n", argv[1], node->consumer_count, node->caller_count, len);
-            switch_mutex_unlock(node->mutex);
+			switch_mutex_lock(node->mutex);
+			stream->write_function(stream, "%s:%d:%d:%d\n", argv[1], node->consumer_count, node->caller_count, len);
+			switch_mutex_unlock(node->mutex);
 		} else {
 			stream->write_function(stream, "none\n");
-        }
-    }
+		}
+	}
 
-    switch_mutex_unlock(globals.mutex);
-    return SWITCH_STATUS_SUCCESS;
+	switch_mutex_unlock(globals.mutex);
+	return SWITCH_STATUS_SUCCESS;
 }
 
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load)
 {
 	switch_application_interface_t *app_interface;
-    switch_api_interface_t *commands_api_interface;
+	switch_api_interface_t *commands_api_interface;
 
 
 	/* create/register custom event message type */
@@ -1186,15 +1186,15 @@
 		return SWITCH_STATUS_GENERR;
 	}
 
-    switch_core_new_memory_pool(&globals.pool);
-    switch_core_hash_init(&globals.fifo_hash, globals.pool);
-    switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, globals.pool);
+	switch_core_new_memory_pool(&globals.pool);
+	switch_core_hash_init(&globals.fifo_hash, globals.pool);
+	switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, globals.pool);
 
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 	SWITCH_ADD_APP(app_interface, "fifo", "Park with FIFO", FIFO_DESC, fifo_function, FIFO_USAGE, SAF_NONE);
-    SWITCH_ADD_API(commands_api_interface, "fifo", "Return data about a fifo", fifo_api_function, FIFO_API_SYNTAX);
-    globals.running = 1;
+	SWITCH_ADD_API(commands_api_interface, "fifo", "Return data about a fifo", fifo_api_function, FIFO_API_SYNTAX);
+	globals.running = 1;
 
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -1204,32 +1204,32 @@
 */
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fifo_shutdown)
 {
-    switch_hash_index_t *hi;
-    void *val, *pop;
-    fifo_node_t *node;
-    switch_memory_pool_t *pool = globals.pool;
-    switch_mutex_t *mutex = globals.mutex;
-
-    switch_mutex_lock(mutex);
-    
-    globals.running = 0;
-    /* Cleanup*/
-    for (hi = switch_hash_first(NULL, globals.fifo_hash); hi; hi = switch_hash_next(hi)) {
-		int x = 0 ;
-        switch_hash_this(hi, NULL, NULL, &val);
-        node = (fifo_node_t *) val;
+	switch_hash_index_t *hi;
+	void *val, *pop;
+	fifo_node_t *node;
+	switch_memory_pool_t *pool = globals.pool;
+	switch_mutex_t *mutex = globals.mutex;
+
+	switch_mutex_lock(mutex);
+
+	globals.running = 0;
+	/* Cleanup */
+	for (hi = switch_hash_first(NULL, globals.fifo_hash); hi; hi = switch_hash_next(hi)) {
+		int x = 0;
+		switch_hash_this(hi, NULL, NULL, &val);
+		node = (fifo_node_t *) val;
 		for (x = 0; x < MAX_PRI; x++) {
 			while (switch_queue_trypop(node->fifo_list[x], &pop) == SWITCH_STATUS_SUCCESS) {
 				free(pop);
 			}
 		}
-        switch_core_hash_destroy(&node->caller_hash);
-        switch_core_hash_destroy(&node->consumer_hash);
-    }
-    switch_core_hash_destroy(&globals.fifo_hash);
-    memset(&globals, 0, sizeof(globals));    
-    switch_mutex_unlock(mutex);
-    switch_core_destroy_memory_pool(&pool);
+		switch_core_hash_destroy(&node->caller_hash);
+		switch_core_hash_destroy(&node->consumer_hash);
+	}
+	switch_core_hash_destroy(&globals.fifo_hash);
+	memset(&globals, 0, sizeof(globals));
+	switch_mutex_unlock(mutex);
+	switch_core_destroy_memory_pool(&pool);
 	return SWITCH_STATUS_SUCCESS;
 }
 

Modified: freeswitch/trunk/src/mod/applications/mod_fsv/mod_fsv.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_fsv/mod_fsv.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_fsv/mod_fsv.c	Tue May 27 00:54:52 2008
@@ -61,35 +61,35 @@
 	switch_status_t status;
 	switch_frame_t *read_frame;
 	int bytes;
-	
-	eh->up = 1;	
-	while(switch_channel_ready(channel)) {
+
+	eh->up = 1;
+	while (switch_channel_ready(channel)) {
 		status = switch_core_session_read_video_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
 
 		if (!SWITCH_READ_ACCEPTABLE(status)) {
 			break;
 		}
-		
+
 		if (switch_test_flag(read_frame, SFF_CNG)) {
 			continue;
 		}
 
-		bytes = read_frame->packetlen |VID_BIT;
-		
+		bytes = read_frame->packetlen | VID_BIT;
+
 		switch_mutex_lock(eh->mutex);
-		
-		if (write(eh->fd, &bytes, sizeof(bytes)) != (int)sizeof(bytes)) {
+
+		if (write(eh->fd, &bytes, sizeof(bytes)) != (int) sizeof(bytes)) {
 			switch_mutex_unlock(eh->mutex);
 			break;
 		}
 
-		if (write(eh->fd, read_frame->packet, read_frame->packetlen) != (int)read_frame->packetlen) {
+		if (write(eh->fd, read_frame->packet, read_frame->packetlen) != (int) read_frame->packetlen) {
 			switch_mutex_unlock(eh->mutex);
 			break;
 		}
 
 		switch_mutex_unlock(eh->mutex);
-        
+
 		switch_core_session_write_video_frame(session, read_frame, SWITCH_IO_FLAG_NONE, 0);
 	}
 	eh->up = 0;
@@ -101,24 +101,24 @@
 	switch_status_t status;
 	switch_frame_t *read_frame;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
-	struct record_helper eh = {0};
+	struct record_helper eh = { 0 };
 	switch_thread_t *thread;
 	switch_threadattr_t *thd_attr = NULL;
 	int fd;
 	switch_mutex_t *mutex = NULL;
 	switch_codec_t codec, *read_codec, *vid_codec;
-	
+
 	switch_channel_answer(channel);
-	
-	if ((fd = open((char *)data, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) < 0) {
+
+	if ((fd = open((char *) data, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) < 0) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error opening file %s\n", (char *) data);
 		return;
 	}
-	
+
 	switch_channel_answer(channel);
 
 	read_codec = switch_core_session_get_read_codec(session);
-	
+
 	if (switch_core_codec_init(&codec,
 							   "L16",
 							   NULL,
@@ -131,14 +131,14 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Audio Codec Activation Fail\n");
 		goto end;
 	}
-	
+
 	switch_core_session_set_read_codec(session, &codec);
-	
+
 	if (switch_channel_test_flag(channel, CF_VIDEO)) {
 		struct file_header h;
 		memset(&h, 0, sizeof(h));
 		vid_codec = switch_core_session_get_video_read_codec(session);
-		
+
 		h.version = VERSION;
 		h.created = switch_timestamp_now();
 		switch_set_string(h.video_codec_name, vid_codec->implementation->iananame);
@@ -147,11 +147,11 @@
 		}
 		h.audio_rate = read_codec->implementation->samples_per_second;
 		h.audio_ptime = read_codec->implementation->microseconds_per_frame / 1000;
-		
+
 		if (write(fd, &h, sizeof(h)) != sizeof(h)) {
 			goto end;
 		}
-		
+
 		switch_mutex_init(&mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
 		eh.mutex = mutex;
 		eh.fd = fd;
@@ -161,12 +161,12 @@
 		switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
 		switch_thread_create(&thread, thd_attr, record_video_thread, &eh, switch_core_session_get_pool(session));
 	}
-	
-	
-	while(switch_channel_ready(channel)) {
+
+
+	while (switch_channel_ready(channel)) {
 
 		status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
-		
+
 		if (!SWITCH_READ_ACCEPTABLE(status)) {
 			break;
 		}
@@ -186,7 +186,7 @@
 			break;
 		}
 
-		if (write(fd, read_frame->data, read_frame->datalen) != (int)read_frame->datalen) {
+		if (write(fd, read_frame->data, read_frame->datalen) != (int) read_frame->datalen) {
 			if (mutex) {
 				switch_mutex_unlock(mutex);
 			}
@@ -198,42 +198,44 @@
 		}
 	}
 
-	
- end:
+
+  end:
 
 	if (eh.up) {
-		while(eh.up) {
+		while (eh.up) {
 			switch_yield(1000);
 		}
 	}
 
 	switch_core_session_set_read_codec(session, read_codec);
 	switch_core_codec_destroy(&codec);
-	
+
 }
 
 SWITCH_STANDARD_APP(play_fsv_function)
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);
-	switch_frame_t write_frame = {0}, vid_frame = {0};
+	switch_frame_t write_frame = { 0 }, vid_frame = {
+	0};
 	int fd = -1;
 	int bytes;
-	switch_codec_t *read_codec = NULL, codec = {0}, vid_codec = {0}, *read_vid_codec;
+	switch_codec_t *read_codec = NULL, codec = { 0 }, vid_codec = {
+	0}, *read_vid_codec;
 	unsigned char *aud_buffer;
 	unsigned char *vid_buffer;
 	struct file_header h;
-	uint32_t ts = 0, last = 0;	
-	switch_timer_t timer = {0};
+	uint32_t ts = 0, last = 0;
+	switch_timer_t timer = { 0 };
 	switch_payload_t pt = 0;
 
 	aud_buffer = switch_core_session_alloc(session, SWITCH_RECOMMENDED_BUFFER_SIZE);
 	vid_buffer = switch_core_session_alloc(session, SWITCH_RECOMMENDED_BUFFER_SIZE);
-	
-	if ((fd = open((char *)data, O_RDONLY)) < 0) {
+
+	if ((fd = open((char *) data, O_RDONLY)) < 0) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error opening file %s\n", (char *) data);
 		return;
 	}
-	
+
 	if (read(fd, &h, sizeof(h)) != sizeof(h)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "error reading file header\n");
 		goto end;
@@ -246,7 +248,7 @@
 
 	switch_channel_set_variable(channel, "sip_force_video_fmtp", h.video_fmtp);
 	switch_channel_answer(channel);
-	
+
 	if ((read_vid_codec = switch_core_session_get_video_read_codec(session))) {
 		pt = read_vid_codec->agreed_pt;
 	}
@@ -254,16 +256,16 @@
 	write_frame.codec = &codec;
 	write_frame.data = aud_buffer;
 	write_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
-	
+
 	vid_frame.codec = &vid_codec;
 	vid_frame.packet = vid_buffer;
 	vid_frame.data = vid_buffer + 12;
 	vid_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE - 12;
 	switch_set_flag((&vid_frame), SFF_RAW_RTP);
-	
+
 	read_codec = switch_core_session_get_read_codec(session);
 
-	if (switch_core_timer_init(&timer, "soft", read_codec->implementation->microseconds_per_frame / 1000, 
+	if (switch_core_timer_init(&timer, "soft", read_codec->implementation->microseconds_per_frame / 1000,
 							   read_codec->implementation->samples_per_frame, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "timer Activation Fail\n");
 		goto end;
@@ -281,7 +283,7 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Audio Codec Activation Fail\n");
 		goto end;
 	}
-	
+
 	if (switch_core_codec_init(&vid_codec,
 							   h.video_codec_name,
 							   NULL,
@@ -296,20 +298,20 @@
 	}
 	switch_core_session_set_read_codec(session, &codec);
 
-	while(switch_channel_ready(channel)) {
+	while (switch_channel_ready(channel)) {
 
 		if (read(fd, &bytes, sizeof(bytes)) != sizeof(bytes)) {
 			break;
 		}
-		
+
 		if (bytes & VID_BIT) {
 			switch_rtp_hdr_t *hdr = vid_frame.packet;
 			bytes &= ~VID_BIT;
 
-			if ((vid_frame.packetlen = read(fd, vid_frame.packet, bytes)) != (uint32_t)bytes) {
+			if ((vid_frame.packetlen = read(fd, vid_frame.packet, bytes)) != (uint32_t) bytes) {
 				break;
 			}
-			
+
 			ts = ntohl(hdr->ts);
 			if (pt) {
 				hdr->pt = pt;
@@ -322,7 +324,7 @@
 			}
 			last = ts;
 		} else {
-			if (bytes > (int)write_frame.buflen) {
+			if (bytes > (int) write_frame.buflen) {
 				bytes = write_frame.buflen;
 			}
 			if ((write_frame.datalen = read(fd, write_frame.data, bytes)) <= 0) {
@@ -333,9 +335,9 @@
 		}
 
 	}
-	
- end:
-	
+
+  end:
+
 	if (timer.interval) {
 		switch_core_timer_destroy(&timer);
 	}
@@ -343,15 +345,15 @@
 	if (read_codec) {
 		switch_core_session_set_read_codec(session, read_codec);
 	}
-	
+
 	if (codec.implementation) {
 		switch_core_codec_destroy(&codec);
 	}
-	
+
 	if (vid_codec.implementation) {
 		switch_core_codec_destroy(&vid_codec);
 	}
-	
+
 	if (fd > -1) {
 		close(fd);
 	}
@@ -362,7 +364,7 @@
 	switch_application_interface_t *app_interface;
 
 	/* connect my internal structure to the blank pointer passed to me */
-    *module_interface = switch_loadable_module_create_module_interface(pool, modname);
+	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 
 	SWITCH_ADD_APP(app_interface, "play_fsv", "play an fsv file", "play an fsv file", play_fsv_function, "<file>", SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "record_fsv", "record an fsv file", "record an fsv file", record_fsv_function, "<file>", SAF_NONE);

Modified: freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c	Tue May 27 00:54:52 2008
@@ -53,28 +53,16 @@
 
 static char limit_sql[] =
 	"CREATE TABLE limit_data (\n"
-	"   hostname   VARCHAR(255),\n"
-	"   realm      VARCHAR(255),\n"
-	"   id         VARCHAR(255),\n" 
-	"   uuid       VARCHAR(255)\n"
-	");\n";
+	"   hostname   VARCHAR(255),\n" "   realm      VARCHAR(255),\n" "   id         VARCHAR(255),\n" "   uuid       VARCHAR(255)\n" ");\n";
 
 
 static char db_sql[] =
 	"CREATE TABLE db_data (\n"
-	"   hostname   VARCHAR(255),\n"
-	"   realm      VARCHAR(255),\n"
-	"   data_key   VARCHAR(255),\n" 
-	"   data       VARCHAR(255)\n"
-	");\n";
+	"   hostname   VARCHAR(255),\n" "   realm      VARCHAR(255),\n" "   data_key   VARCHAR(255),\n" "   data       VARCHAR(255)\n" ");\n";
 
 
 static char group_sql[] =
-	"CREATE TABLE group_data (\n"
-	"   hostname   VARCHAR(255),\n"
-	"   groupname  VARCHAR(255),\n"
-	"   url        VARCHAR(255)\n"
-	");\n";
+	"CREATE TABLE group_data (\n" "   hostname   VARCHAR(255),\n" "   groupname  VARCHAR(255),\n" "   url        VARCHAR(255)\n" ");\n";
 
 
 
@@ -86,9 +74,8 @@
 	if (mutex) {
 		switch_mutex_lock(mutex);
 	}
-
 #ifdef SWITCH_HAVE_ODBC
-    if (globals.odbc_dsn) {
+	if (globals.odbc_dsn) {
 		SQLHSTMT stmt;
 		if (switch_odbc_handle_exec(globals.master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
 			char *err_str;
@@ -110,33 +97,29 @@
 		switch_core_db_close(db);
 
 #ifdef SWITCH_HAVE_ODBC
-    }
+	}
 #endif
 
 
- end:
+  end:
 	if (mutex) {
 		switch_mutex_unlock(mutex);
 	}
 
-    return status;
+	return status;
 }
 
 
-static switch_bool_t limit_execute_sql_callback(switch_mutex_t *mutex,
-                                                char *sql,
-                                                switch_core_db_callback_func_t callback,
-                                                void *pdata)
+static switch_bool_t limit_execute_sql_callback(switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback, void *pdata)
 {
 	switch_bool_t ret = SWITCH_FALSE;
 	switch_core_db_t *db;
 	char *errmsg = NULL;
-	
+
 	if (mutex) {
 		switch_mutex_lock(mutex);
 	}
 
-
 #ifdef SWITCH_HAVE_ODBC
 	if (globals.odbc_dsn) {
 		switch_odbc_handle_callback_exec(globals.master_odbc, sql, callback, pdata);
@@ -161,7 +144,7 @@
 	}
 #endif
 
- end:
+  end:
 	if (mutex) {
 		switch_mutex_unlock(mutex);
 	}
@@ -185,12 +168,12 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
 		return SWITCH_STATUS_TERM;
 	}
-    
+
 	if ((settings = switch_xml_child(cfg, "settings"))) {
 		for (param = switch_xml_child(settings, "param"); param; param = param->next) {
 			char *var = NULL;
 			char *val = NULL;
-            
+
 			var = (char *) switch_xml_attr_soft(param, "name");
 			val = (char *) switch_xml_attr_soft(param, "value");
 
@@ -198,9 +181,9 @@
 #ifdef SWITCH_HAVE_ODBC
 				globals.odbc_dsn = switch_core_strdup(globals.pool, val);
 				if ((odbc_user = strchr(globals.odbc_dsn, ':'))) {
-				*odbc_user++ = '\0';
+					*odbc_user++ = '\0';
 					if ((odbc_pass = strchr(odbc_user, ':'))) {
-					*odbc_pass++ = '\0';
+						*odbc_pass++ = '\0';
 					}
 				}
 #else
@@ -214,7 +197,6 @@
 	if (switch_strlen_zero(globals.odbc_dsn) || switch_strlen_zero(odbc_user) || switch_strlen_zero(odbc_pass)) {
 		globals.dbname = "call_limit";
 	}
-    
 
 #ifdef SWITCH_HAVE_ODBC
 	if (globals.odbc_dsn) {
@@ -228,11 +210,11 @@
 			status = SWITCH_STATUS_FALSE;
 			goto done;
 		}
-        
+
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", globals.odbc_dsn);
 		if (switch_odbc_handle_exec(globals.master_odbc, "select count(*) from limit_data", NULL) != SWITCH_STATUS_SUCCESS) {
 			if (switch_odbc_handle_exec(globals.master_odbc, limit_sql, NULL) != SWITCH_STATUS_SUCCESS) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Create SQL Database!\n");
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Create SQL Database!\n");
 			}
 		}
 		if (switch_odbc_handle_exec(globals.master_odbc, "select count(*) from db_data", NULL) != SWITCH_STATUS_SUCCESS) {
@@ -258,10 +240,10 @@
 		}
 		switch_core_db_close(db);
 #ifdef SWITCH_HAVE_ODBC
-	}           
+	}
 #endif
 
- done:
+  done:
 
 	sql = switch_mprintf("delete from limit_data where hostname='%q';", globals.hostname);
 	limit_execute_sql(sql, globals.mutex);
@@ -284,8 +266,8 @@
 	if (state == CS_HANGUP || state == CS_ROUTING) {
 		id = switch_channel_get_variable(channel, "limit_id");
 		realm = switch_channel_get_variable(channel, "limit_realm");
-		sql = switch_mprintf("delete from limit_data where uuid='%q' and hostname='%q' and realm='%q'and id='%q';", 
-                             switch_core_session_get_uuid(session), globals.hostname, realm, id);
+		sql = switch_mprintf("delete from limit_data where uuid='%q' and hostname='%q' and realm='%q'and id='%q';",
+							 switch_core_session_get_uuid(session), globals.hostname, realm, id);
 		limit_execute_sql(sql, globals.mutex);
 		switch_safe_free(sql);
 		switch_core_event_hook_remove_state_change(session, hanguphook);
@@ -343,8 +325,10 @@
 		sql = switch_mprintf("delete from db_data where realm='%q' and data_key='%q'", argv[1], argv[2]);
 		assert(sql);
 		limit_execute_sql(sql, NULL);
-		switch_safe_free(sql);    
-		sql = switch_mprintf("insert into db_data (hostname, realm, data_key, data) values('%q','%q','%q','%q');", globals.hostname, argv[1], argv[2], argv[3]);
+		switch_safe_free(sql);
+		sql =
+			switch_mprintf("insert into db_data (hostname, realm, data_key, data) values('%q','%q','%q','%q');", globals.hostname, argv[1], argv[2],
+						   argv[3]);
 		assert(sql);
 		limit_execute_sql(sql, NULL);
 		switch_safe_free(sql);
@@ -357,7 +341,7 @@
 		sql = switch_mprintf("delete from db_data where realm='%q' and data_key='%q'", argv[1], argv[2]);
 		assert(sql);
 		limit_execute_sql(sql, NULL);
-		switch_safe_free(sql);    
+		switch_safe_free(sql);
 		stream->write_function(stream, "+OK");
 		goto done;
 	} else if (!strcasecmp(argv[0], "select")) {
@@ -372,18 +356,18 @@
 		limit_execute_sql_callback(NULL, sql, sql2str_callback, &cbt);
 		stream->write_function(stream, "%s", buf);
 		goto done;
-	} 
+	}
 
 
- error:
+  error:
 	stream->write_function(stream, "!err!");
-    
- done:
+
+  done:
 
 	switch_mutex_unlock(globals.mutex);
 	switch_safe_free(mydata);
 	return SWITCH_STATUS_SUCCESS;
-    
+
 }
 
 
@@ -411,8 +395,10 @@
 		switch_assert(sql);
 		limit_execute_sql(sql, globals.mutex);
 		switch_safe_free(sql);
-        
-		sql = switch_mprintf("insert into db_data (hostname, realm, data_key, data) values('%q','%q','%q','%q');", globals.hostname, argv[1], argv[2], argv[3]);
+
+		sql =
+			switch_mprintf("insert into db_data (hostname, realm, data_key, data) values('%q','%q','%q','%q');", globals.hostname, argv[1], argv[2],
+						   argv[3]);
 	} else if (!strcasecmp(argv[0], "delete")) {
 		sql = switch_mprintf("delete from db_data where realm='%q' and data_key='%q'", argv[1], argv[2]);
 	}
@@ -422,7 +408,7 @@
 	switch_safe_free(sql);
 	return;
 
-error:
+  error:
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "USAGE: db %s\n", DB_USAGE);
 }
 
@@ -481,7 +467,7 @@
 		callback_t cbt = { 0 };
 		cbt.buf = buf;
 		cbt.len = sizeof(buf);
-        
+
 		if (argc > 2) {
 			if (!strcasecmp(argv[2], "order")) {
 				how = "|";
@@ -497,15 +483,15 @@
 		goto done;
 	}
 
- error:
+  error:
 	stream->write_function(stream, "!err!");
-    
- done:
+
+  done:
 
 	switch_mutex_unlock(globals.mutex);
 	switch_safe_free(mydata);
 	return SWITCH_STATUS_SUCCESS;
-    
+
 }
 
 #define GROUP_USAGE "[insert|delete]:<group name>:<val>"
@@ -544,7 +530,7 @@
 
 #define LIMIT_USAGE "<realm> <id> <max> [transfer_destination_number]"
 #define LIMIT_DESC "limit access to an extension"
-static char *limit_def_xfer_exten="limit_exceeded";
+static char *limit_def_xfer_exten = "limit_exceeded";
 
 SWITCH_STANDARD_APP(limit_function)
 {
@@ -585,7 +571,7 @@
 	if (max < 0) {
 		max = 0;
 	}
-    
+
 	switch_channel_set_variable(channel, "limit_realm", realm);
 	switch_channel_set_variable(channel, "limit_id", id);
 	switch_channel_set_variable(channel, "limit_max", argv[2]);
@@ -602,11 +588,13 @@
 	}
 
 	switch_core_event_hook_add_state_change(session, hanguphook);
-	sql = switch_mprintf("insert into limit_data (hostname, realm, id, uuid) values('%q','%q','%q','%q');", globals.hostname, realm, id, switch_core_session_get_uuid(session));
+	sql =
+		switch_mprintf("insert into limit_data (hostname, realm, id, uuid) values('%q','%q','%q','%q');", globals.hostname, realm, id,
+					   switch_core_session_get_uuid(session));
 	limit_execute_sql(sql, NULL);
 	switch_safe_free(sql);
 
-done:
+  done:
 	switch_mutex_unlock(globals.mutex);
 }
 
@@ -626,7 +614,7 @@
 	}
 
 	switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, globals.pool);
-    
+
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 

Modified: freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c	Tue May 27 00:54:52 2008
@@ -91,7 +91,7 @@
 {
 	switch (itype) {
 	case SWITCH_INPUT_TYPE_DTMF:{
-		switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
+			switch_dtmf_t *dtmf = (switch_dtmf_t *) input;
 			struct dtmf_buffer *dtb;
 			dtb = (struct dtmf_buffer *) buf;
 
@@ -175,7 +175,8 @@
 	uint32_t last;
 	char *mydata = NULL;
 	char *filename = NULL;
-	char *argv[3], *feed_list[TTS_MAX_ENTRIES] = { 0 }, *feed_names[TTS_MAX_ENTRIES] = {0};
+	char *argv[3], *feed_list[TTS_MAX_ENTRIES] = { 0 }, *feed_names[TTS_MAX_ENTRIES] = {
+	0};
 	int argc, feed_index = 0;
 	const char *cf = "rss.conf";
 	switch_xml_t cfg, cxml, feeds, feed;
@@ -311,12 +312,12 @@
 			switch_core_speech_flush_tts(&sh);
 #ifdef MATCH_COUNT
 			switch_snprintf(buf + len, sizeof(buf) - len, "%s",
-					 ",<break time=\"500ms\"/>Main Menu. <break time=\"600ms\"/> "
-					 "Select one of the following news sources, or press 0 to exit. " ",<break time=\"600ms\"/>");
+							",<break time=\"500ms\"/>Main Menu. <break time=\"600ms\"/> "
+							"Select one of the following news sources, or press 0 to exit. " ",<break time=\"600ms\"/>");
 #else
 			switch_snprintf(buf + len, sizeof(buf) - len, "%s",
-					 ",<break time=\"500ms\"/>Main Menu. <break time=\"600ms\"/> "
-					 "Select one of the following news sources, followed by the pound key or press 0 to exit. " ",<break time=\"600ms\"/>");
+							",<break time=\"500ms\"/>Main Menu. <break time=\"600ms\"/> "
+							"Select one of the following news sources, followed by the pound key or press 0 to exit. " ",<break time=\"600ms\"/>");
 #endif
 			len = (int32_t) strlen(buf);
 
@@ -482,8 +483,8 @@
 
 
 			switch_snprintf(buf, sizeof(buf),
-					 ",<break time=\"500ms\"/>%s. %s. %s. local time: %s, Press 0 for options, 5 to change voice, or pound to return to the main menu. ",
-					 title_txt, description_txt, rights_txt, date);
+							",<break time=\"500ms\"/>%s. %s. %s. local time: %s, Press 0 for options, 5 to change voice, or pound to return to the main menu. ",
+							title_txt, description_txt, rights_txt, date);
 			args.input_callback = NULL;
 			args.buf = dtmf;
 			args.buflen = sizeof(dtmf);
@@ -539,7 +540,8 @@
 					}
 					if (switch_test_flag(&dtb, SFLAG_INFO)) {
 						switch_clear_flag(&dtb, SFLAG_INFO);
-						switch_snprintf(tmpbuf + tmplen, sizeof(tmpbuf) - tmplen, "%s %s. I am speaking at %u words per minute. ", sh.engine, sh.voice, dtb.speed);
+						switch_snprintf(tmpbuf + tmplen, sizeof(tmpbuf) - tmplen, "%s %s. I am speaking at %u words per minute. ", sh.engine, sh.voice,
+										dtb.speed);
 						tmplen = (uint32_t) strlen(tmpbuf);
 					}
 
@@ -547,12 +549,12 @@
 						switch_clear_flag(&dtb, SFLAG_INSTRUCT);
 						cont = 1;
 						switch_snprintf(tmpbuf + tmplen, sizeof(tmpbuf) - tmplen, "%s",
-								 "Press star to pause or resume speech. "
-								 "To go to the next item, press six. "
-								 "To go back, press 4. "
-								 "Press two to go faster, eight to slow down, or 7 to resume normal speed. "
-								 "To change voices, press five. To restore the original voice press 9. "
-								 "To hear these options again, press zero or press pound to return to the main menu. ");
+										"Press star to pause or resume speech. "
+										"To go to the next item, press six. "
+										"To go back, press 4. "
+										"Press two to go faster, eight to slow down, or 7 to resume normal speed. "
+										"To change voices, press five. To restore the original voice press 9. "
+										"To hear these options again, press zero or press pound to return to the main menu. ");
 					} else {
 						switch_snprintf(tmpbuf + tmplen, sizeof(tmpbuf) - tmplen, "Story %d. ", dtb.index + 1);
 						tmplen = (uint32_t) strlen(tmpbuf);

Modified: freeswitch/trunk/src/mod/applications/mod_skel/mod_skel.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_skel/mod_skel.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_skel/mod_skel.c	Tue May 27 00:54:52 2008
@@ -41,7 +41,7 @@
 SWITCH_MODULE_LOAD_FUNCTION(mod_skel_load)
 {
 	/* connect my internal structure to the blank pointer passed to me */
-    *module_interface = switch_loadable_module_create_module_interface(pool, modname);
+	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hello World!\n");
 

Modified: freeswitch/trunk/src/mod/applications/mod_soundtouch/mod_soundtouch.cpp
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_soundtouch/mod_soundtouch.cpp	(original)
+++ freeswitch/trunk/src/mod/applications/mod_soundtouch/mod_soundtouch.cpp	Tue May 27 00:54:52 2008
@@ -43,107 +43,107 @@
 SWITCH_MODULE_DEFINITION(mod_soundtouch, mod_soundtouch_load, NULL, NULL);
 
 struct soundtouch_helper {
-    SoundTouch *st;
-    switch_core_session_t *session;
-    int send;
-    int read;
-    float pitch;
-    float octaves;
-    float semi;
-    float rate;
-    float tempo;
-    int literal;
+	SoundTouch *st;
+	switch_core_session_t *session;
+	int send;
+	int read;
+	float pitch;
+	float octaves;
+	float semi;
+	float rate;
+	float tempo;
+	int literal;
 };
 
 static switch_status_t on_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf, switch_dtmf_direction_t direction)
 {
 
-    switch_media_bug_t *bug;
-    switch_channel_t *channel = switch_core_session_get_channel(session);
-    
-    if ((bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_soundtouch_"))) {
-        struct soundtouch_helper *sth = (struct soundtouch_helper *) switch_core_media_bug_get_user_data(bug);
-        
-        if (sth) {
-            if (sth->literal) {
-                sth->literal = 0;
-                return SWITCH_STATUS_SUCCESS;
-            }
-
-            
-            switch(dtmf->digit) {
-            case '*':
-                sth->literal++;
-                break;
-            case '3':
-                sth->semi += .5;
-                sth->st->setPitchSemiTones(sth->semi);
-                sth->st->flush();
-                break;
-            case '2':
-                sth->semi = 0;
-                sth->st->setPitchSemiTones(sth->semi);
-                sth->st->flush();
-                break;
-            case '1':
-                sth->semi -= .5;
-                sth->st->setPitchSemiTones(sth->semi);
-                sth->st->flush();
-                break;
-
-            case '6':
-                sth->pitch += .2;
-                sth->st->setPitch(sth->pitch);
-                sth->st->flush();
-                break;
-            case '5':
-                sth->pitch = 1;
-                sth->st->setPitch(sth->pitch);
-                sth->st->flush();
-                break;
-            case '4':
-                sth->pitch -= .2;
-                if (sth->pitch <= 0) {
-                    sth->pitch = .2;
-                }
-                sth->st->setPitch(sth->pitch);
-                sth->st->flush();
-                break;
-
-            case '9':
-                sth->octaves += .2;
-                sth->st->setPitchOctaves(sth->octaves);
-                sth->st->flush();
-                break;
-            case '8':
-                sth->octaves = 0;
-                sth->st->setPitchOctaves(sth->octaves);
-                sth->st->flush();
-                break;
-            case '7':
-                sth->octaves -= .2;
-                sth->st->setPitchOctaves(sth->octaves);
-                sth->st->flush();
-                break;
-
-
-            case '0':
-                sth->octaves = 0;
-                sth->st->setPitchOctaves(sth->octaves);
-                sth->pitch = 1;
-                sth->st->setPitch(sth->pitch);
-                sth->semi = 0;
-                sth->st->setPitchSemiTones(sth->semi);
-                sth->st->flush();
-                    
-            }
-
-        }
-        
-
-        return SWITCH_STATUS_FALSE;
-    }
-    return SWITCH_STATUS_SUCCESS;
+	switch_media_bug_t *bug;
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+
+	if ((bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_soundtouch_"))) {
+		struct soundtouch_helper *sth = (struct soundtouch_helper *) switch_core_media_bug_get_user_data(bug);
+
+		if (sth) {
+			if (sth->literal) {
+				sth->literal = 0;
+				return SWITCH_STATUS_SUCCESS;
+			}
+
+
+			switch (dtmf->digit) {
+			case '*':
+				sth->literal++;
+				break;
+			case '3':
+				sth->semi += .5;
+				sth->st->setPitchSemiTones(sth->semi);
+				sth->st->flush();
+				break;
+			case '2':
+				sth->semi = 0;
+				sth->st->setPitchSemiTones(sth->semi);
+				sth->st->flush();
+				break;
+			case '1':
+				sth->semi -= .5;
+				sth->st->setPitchSemiTones(sth->semi);
+				sth->st->flush();
+				break;
+
+			case '6':
+				sth->pitch += .2;
+				sth->st->setPitch(sth->pitch);
+				sth->st->flush();
+				break;
+			case '5':
+				sth->pitch = 1;
+				sth->st->setPitch(sth->pitch);
+				sth->st->flush();
+				break;
+			case '4':
+				sth->pitch -= .2;
+				if (sth->pitch <= 0) {
+					sth->pitch = .2;
+				}
+				sth->st->setPitch(sth->pitch);
+				sth->st->flush();
+				break;
+
+			case '9':
+				sth->octaves += .2;
+				sth->st->setPitchOctaves(sth->octaves);
+				sth->st->flush();
+				break;
+			case '8':
+				sth->octaves = 0;
+				sth->st->setPitchOctaves(sth->octaves);
+				sth->st->flush();
+				break;
+			case '7':
+				sth->octaves -= .2;
+				sth->st->setPitchOctaves(sth->octaves);
+				sth->st->flush();
+				break;
+
+
+			case '0':
+				sth->octaves = 0;
+				sth->st->setPitchOctaves(sth->octaves);
+				sth->pitch = 1;
+				sth->st->setPitch(sth->pitch);
+				sth->semi = 0;
+				sth->st->setPitchSemiTones(sth->semi);
+				sth->st->flush();
+
+			}
+
+		}
+
+
+		return SWITCH_STATUS_FALSE;
+	}
+	return SWITCH_STATUS_SUCCESS;
 }
 
 
@@ -153,85 +153,85 @@
 
 	switch (type) {
 	case SWITCH_ABC_TYPE_INIT:
-        {
-            switch_codec_t *read_codec = switch_core_session_get_read_codec(sth->session);
-            sth->st = new SoundTouch();
-            sth->st->setSampleRate(read_codec->implementation->samples_per_second);
-            sth->st->setChannels(read_codec->implementation->number_of_channels);
-            
-            sth->st->setSetting(SETTING_USE_QUICKSEEK, 1);
-            sth->st->setSetting(SETTING_USE_AA_FILTER, 1);
-
-            if (sth->semi) {
-                sth->st->setPitchSemiTones(sth->semi);
-            }
-
-            if (sth->pitch) {
-                sth->st->setPitch(sth->pitch);
-            }
-
-            if (sth->octaves) {
-                sth->st->setPitchOctaves(sth->octaves);
-            }
-
-            if (sth->rate) {
-                sth->st->setRate(sth->rate);
-            }
-
-            if (sth->tempo) {
-                sth->st->setRate(sth->tempo);
-            }
-            
-            if (sth->send) {
-                switch_core_event_hook_add_send_dtmf(sth->session, on_dtmf);
-            } else {
-                switch_core_event_hook_add_recv_dtmf(sth->session, on_dtmf);
-            }
-        }
-        break;
+		{
+			switch_codec_t *read_codec = switch_core_session_get_read_codec(sth->session);
+			sth->st = new SoundTouch();
+			sth->st->setSampleRate(read_codec->implementation->samples_per_second);
+			sth->st->setChannels(read_codec->implementation->number_of_channels);
+
+			sth->st->setSetting(SETTING_USE_QUICKSEEK, 1);
+			sth->st->setSetting(SETTING_USE_AA_FILTER, 1);
+
+			if (sth->semi) {
+				sth->st->setPitchSemiTones(sth->semi);
+			}
+
+			if (sth->pitch) {
+				sth->st->setPitch(sth->pitch);
+			}
+
+			if (sth->octaves) {
+				sth->st->setPitchOctaves(sth->octaves);
+			}
+
+			if (sth->rate) {
+				sth->st->setRate(sth->rate);
+			}
+
+			if (sth->tempo) {
+				sth->st->setRate(sth->tempo);
+			}
+
+			if (sth->send) {
+				switch_core_event_hook_add_send_dtmf(sth->session, on_dtmf);
+			} else {
+				switch_core_event_hook_add_recv_dtmf(sth->session, on_dtmf);
+			}
+		}
+		break;
 	case SWITCH_ABC_TYPE_CLOSE:
-        {
-            delete sth->st;
-            if (sth->send) {
-                switch_core_event_hook_remove_send_dtmf(sth->session, on_dtmf);
-            } else {
-                switch_core_event_hook_remove_recv_dtmf(sth->session, on_dtmf);
-            }
-        }
+		{
+			delete sth->st;
+			if (sth->send) {
+				switch_core_event_hook_remove_send_dtmf(sth->session, on_dtmf);
+			} else {
+				switch_core_event_hook_remove_recv_dtmf(sth->session, on_dtmf);
+			}
+		}
 		break;
 	case SWITCH_ABC_TYPE_READ:
 	case SWITCH_ABC_TYPE_WRITE:
-        break;
+		break;
 	case SWITCH_ABC_TYPE_READ_REPLACE:
 	case SWITCH_ABC_TYPE_WRITE_REPLACE:
-        {
-            switch_frame_t *frame;
-            
-            assert(sth != NULL);
-            assert(sth->st != NULL);
-
-            if (sth->read) {
-                frame = switch_core_media_bug_get_read_replace_frame(bug);
-            } else {
-                frame = switch_core_media_bug_get_write_replace_frame(bug);
-            }
-
-            sth->st->putSamples((SAMPLETYPE *)frame->data, frame->samples);
-
-            if (sth->st->numSamples() >= frame->samples * 2) {
-                frame->samples = sth->st->receiveSamples((SAMPLETYPE *)frame->data, frame->samples);
-                frame->datalen = frame->samples * 2;
-            } else {
-                memset(frame->data, 0, frame->datalen);
-            }
-
-            if (sth->read) {
-                switch_core_media_bug_set_read_replace_frame(bug, frame);
-            } else {
-                switch_core_media_bug_set_write_replace_frame(bug, frame);
-            }
-            
-        }
+		{
+			switch_frame_t *frame;
+
+			assert(sth != NULL);
+			assert(sth->st != NULL);
+
+			if (sth->read) {
+				frame = switch_core_media_bug_get_read_replace_frame(bug);
+			} else {
+				frame = switch_core_media_bug_get_write_replace_frame(bug);
+			}
+
+			sth->st->putSamples((SAMPLETYPE *) frame->data, frame->samples);
+
+			if (sth->st->numSamples() >= frame->samples * 2) {
+				frame->samples = sth->st->receiveSamples((SAMPLETYPE *) frame->data, frame->samples);
+				frame->datalen = frame->samples * 2;
+			} else {
+				memset(frame->data, 0, frame->datalen);
+			}
+
+			if (sth->read) {
+				switch_core_media_bug_set_read_replace_frame(bug, frame);
+			} else {
+				switch_core_media_bug_set_write_replace_frame(bug, frame);
+			}
+
+		}
 	default:
 		break;
 	}
@@ -241,68 +241,68 @@
 
 SWITCH_STANDARD_APP(soundtouch_start_function)
 {
-    switch_media_bug_t *bug;
-    switch_status_t status;
-    switch_channel_t *channel = switch_core_session_get_channel(session);
-    struct soundtouch_helper *sth;
-    char *argv[6];
+	switch_media_bug_t *bug;
+	switch_status_t status;
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+	struct soundtouch_helper *sth;
+	char *argv[6];
 	int argc;
 	char *lbuf = NULL;
-    int x;
- 
-    if ((bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_soundtouch_"))) {
-        if (!switch_strlen_zero(data) && !strcasecmp(data, "stop")) {
-            switch_channel_set_private(channel, "_soundtouch_", NULL);
-            switch_core_media_bug_remove(session, &bug);
-        } else {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
-        }
-        return;
-    }
+	int x;
+
+	if ((bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_soundtouch_"))) {
+		if (!switch_strlen_zero(data) && !strcasecmp(data, "stop")) {
+			switch_channel_set_private(channel, "_soundtouch_", NULL);
+			switch_core_media_bug_remove(session, &bug);
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
+		}
+		return;
+	}
 
-    sth = (struct soundtouch_helper *) switch_core_session_alloc(session, sizeof(*sth));
-    assert(sth != NULL);
+	sth = (struct soundtouch_helper *) switch_core_session_alloc(session, sizeof(*sth));
+	assert(sth != NULL);
 
 
 	if (data && (lbuf = switch_core_session_strdup(session, data))
 		&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
-        sth->send = 0;
-        sth->read = 0;
-        sth->pitch = 1;
-        for(x = 0; x < argc; x++) {
-            if (!strncasecmp(argv[x], "send", 4)) {
-                sth->send = 1;
-            } else if (!strncasecmp(argv[x], "read", 4)) {
-                sth->read = 1;
-            } else if (strchr(argv[x], 'p')) {
-                if ((sth->pitch = atof(argv[x]) < 0)) {
-                    sth->pitch = 0;
-                }
-            } else if (strchr(argv[x], 'r')) {
-                sth->rate = atof(argv[x]);
-            } else if (strchr(argv[x], 'o')) {
-                sth->octaves = atof(argv[x]);
-            } else if (strchr(argv[x], 's')) {
-                sth->semi = atof(argv[x]);
-            } else if (strchr(argv[x], 't')) {
-                if ((sth->tempo = atof(argv[x]) < 0)) {
-                    sth->tempo = 0;
-                }
-            }
-        }
-    }
-    
-
-    sth->session = session;
-
-	if ((status = switch_core_media_bug_add(session, soundtouch_callback, sth, 0, 
-                                            sth->read ? SMBF_READ_REPLACE : SMBF_WRITE_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) {
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failure!\n");
+		sth->send = 0;
+		sth->read = 0;
+		sth->pitch = 1;
+		for (x = 0; x < argc; x++) {
+			if (!strncasecmp(argv[x], "send", 4)) {
+				sth->send = 1;
+			} else if (!strncasecmp(argv[x], "read", 4)) {
+				sth->read = 1;
+			} else if (strchr(argv[x], 'p')) {
+				if ((sth->pitch = atof(argv[x]) < 0)) {
+					sth->pitch = 0;
+				}
+			} else if (strchr(argv[x], 'r')) {
+				sth->rate = atof(argv[x]);
+			} else if (strchr(argv[x], 'o')) {
+				sth->octaves = atof(argv[x]);
+			} else if (strchr(argv[x], 's')) {
+				sth->semi = atof(argv[x]);
+			} else if (strchr(argv[x], 't')) {
+				if ((sth->tempo = atof(argv[x]) < 0)) {
+					sth->tempo = 0;
+				}
+			}
+		}
+	}
+
+
+	sth->session = session;
+
+	if ((status = switch_core_media_bug_add(session, soundtouch_callback, sth, 0,
+											sth->read ? SMBF_READ_REPLACE : SMBF_WRITE_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failure!\n");
 		return;
 	}
-    
+
 	switch_channel_set_private(channel, "_soundtouch_", bug);
-    
+
 }
 static switch_application_interface_t soundtouch_application_interface = {
 	/*.interface_name */ "soundtouch",
@@ -311,8 +311,8 @@
 	/* short_desc */ "Alter the audio stream",
 	/* syntax */ "[send|recv] [-]<X>s [.]<X>p",
 	/* flags */ SAF_NONE,
-    /* next*/ 
-    
+	/* next */
+
 };
 
 static switch_loadable_module_interface_t soundtouch_module_interface = {

Modified: freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	Tue May 27 00:54:52 2008
@@ -35,7 +35,7 @@
 #include <switch_odbc.h>
 #endif
 
-#ifdef _MSC_VER /* compilers are stupid sometimes */
+#ifdef _MSC_VER					/* compilers are stupid sometimes */
 #define TRY_CODE(code) for(;;) {status = code; if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;}
 #else
 #define TRY_CODE(code) do { status = code; if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;} while(status)
@@ -62,7 +62,7 @@
 	char play_new_messages_key[2];
 	char play_saved_messages_key[2];
 
-	char main_menu_key[2];    
+	char main_menu_key[2];
 	char config_menu_key[2];
 	char record_greeting_key[2];
 	char choose_greeting_key[2];
@@ -141,7 +141,7 @@
 		switch_core_db_close(db);
 	}
 
-end:
+  end:
 	if (mutex) {
 		switch_mutex_unlock(mutex);
 	}
@@ -149,11 +149,7 @@
 }
 
 
-static switch_bool_t vm_execute_sql_callback(vm_profile_t *profile,
-											 switch_mutex_t *mutex,
-											 char *sql,
-											 switch_core_db_callback_func_t callback,
-											 void *pdata)
+static switch_bool_t vm_execute_sql_callback(vm_profile_t *profile, switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback, void *pdata)
 {
 	switch_bool_t ret = SWITCH_FALSE;
 	switch_core_db_t *db;
@@ -185,7 +181,7 @@
 		}
 	}
 
-end:
+  end:
 	if (mutex) {
 		switch_mutex_unlock(mutex);
 	}
@@ -196,26 +192,19 @@
 static char vm_sql[] =
 	"CREATE TABLE voicemail_msgs (\n"
 	"   created_epoch INTEGER,\n"
-	"   read_epoch    INTEGER,\n" 
-	"   username      VARCHAR(255),\n" 
-	"   domain        VARCHAR(255),\n" 
-	"   uuid          VARCHAR(255),\n" 
-	"   cid_name      VARCHAR(255),\n" 
-	"   cid_number    VARCHAR(255),\n" 
-	"   in_folder     VARCHAR(255),\n" 
-	"   file_path     VARCHAR(255),\n" 
-	"   message_len   INTEGER,\n" 
-	"   flags         VARCHAR(255),\n"
-	"   read_flags    VARCHAR(255)\n" 
-	");\n";
+	"   read_epoch    INTEGER,\n"
+	"   username      VARCHAR(255),\n"
+	"   domain        VARCHAR(255),\n"
+	"   uuid          VARCHAR(255),\n"
+	"   cid_name      VARCHAR(255),\n"
+	"   cid_number    VARCHAR(255),\n"
+	"   in_folder     VARCHAR(255),\n"
+	"   file_path     VARCHAR(255),\n" "   message_len   INTEGER,\n" "   flags         VARCHAR(255),\n" "   read_flags    VARCHAR(255)\n" ");\n";
 
 static char vm_pref_sql[] =
 	"CREATE TABLE voicemail_prefs (\n"
-	"   username        VARCHAR(255),\n" 
-	"   domain          VARCHAR(255),\n" 
-	"   name_path       VARCHAR(255),\n" 
-	"   greeting_path VARCHAR(255)\n" 
-	");\n";
+	"   username        VARCHAR(255),\n"
+	"   domain          VARCHAR(255),\n" "   name_path       VARCHAR(255),\n" "   greeting_path VARCHAR(255)\n" ");\n";
 
 static switch_status_t load_config(void)
 {
@@ -254,7 +243,7 @@
 		char *play_new_messages_key = "1";
 		char *play_saved_messages_key = "2";
 
-		char *main_menu_key = "0";    
+		char *main_menu_key = "0";
 		char *config_menu_key = "5";
 		char *record_greeting_key = "1";
 		char *choose_greeting_key = "2";
@@ -328,17 +317,14 @@
 					if (switch_is_file_path(val)) {
 						path = val;
 					} else {
-						dpath = switch_mprintf("%s%s%s", 
-							SWITCH_GLOBAL_dirs.conf_dir, 
-							SWITCH_PATH_SEPARATOR,
-							val);
+						dpath = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.conf_dir, SWITCH_PATH_SEPARATOR, val);
 						path = dpath;
 					}
 
 					if ((fd = open(path, O_RDONLY)) > -1) {
 						char buf[2048];
 						SWITCH_STANDARD_STREAM(stream);
-						while(switch_fd_read_line(fd, buf, sizeof(buf))) {
+						while (switch_fd_read_line(fd, buf, sizeof(buf))) {
 							stream.write_function(&stream, "%s", buf);
 						}
 						close(fd);
@@ -373,17 +359,14 @@
 				if (switch_is_file_path(val)) {
 					path = val;
 				} else {
-					dpath = switch_mprintf("%s%s%s", 
-						SWITCH_GLOBAL_dirs.conf_dir, 
-						SWITCH_PATH_SEPARATOR,
-						val);
+					dpath = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.conf_dir, SWITCH_PATH_SEPARATOR, val);
 					path = dpath;
 				}
 
 				if ((fd = open(path, O_RDONLY)) > -1) {
 					char buf[2048];
 					SWITCH_STANDARD_STREAM(stream);
-					while(switch_fd_read_line(fd, buf, sizeof(buf))) {
+					while (switch_fd_read_line(fd, buf, sizeof(buf))) {
 						stream.write_function(&stream, "%s", buf);
 					}
 					close(fd);
@@ -437,10 +420,10 @@
 				operator_key = val;
 			} else if (!strcasecmp(var, "operator-extension") && !switch_strlen_zero(val)) {
 				operator_ext = val;
-                        } else if (!strcasecmp(var, "vmain-key") && !switch_strlen_zero(val)) {
-                                vmain_key = val;
-                        } else if (!strcasecmp(var, "vmain-extension") && !switch_strlen_zero(val)) {
-                                vmain_ext = val;
+			} else if (!strcasecmp(var, "vmain-key") && !switch_strlen_zero(val)) {
+				vmain_key = val;
+			} else if (!strcasecmp(var, "vmain-extension") && !switch_strlen_zero(val)) {
+				vmain_ext = val;
 			} else if (!strcasecmp(var, "storage-dir") && !switch_strlen_zero(val)) {
 				storage_dir = val;
 			} else if (!strcasecmp(var, "callback-dialplan") && !switch_strlen_zero(val)) {
@@ -577,19 +560,18 @@
 					switch_odbc_handle_exec(profile->master_odbc, vm_pref_sql, NULL);
 				}
 
-                if (switch_odbc_handle_exec(profile->master_odbc, "select count(message_len) from voicemail_data", NULL) == SWITCH_ODBC_SUCCESS) {
-                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Old table voicemail_data found, migrating data!\n");
-                    /* XXX: Old table found.. migrating data into new table */
-                    if (switch_odbc_handle_exec(profile->master_odbc,
+				if (switch_odbc_handle_exec(profile->master_odbc, "select count(message_len) from voicemail_data", NULL) == SWITCH_ODBC_SUCCESS) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Old table voicemail_data found, migrating data!\n");
+					/* XXX: Old table found.. migrating data into new table */
+					if (switch_odbc_handle_exec(profile->master_odbc,
 												"insert into voicemail_msgs select created_epoch, read_epoch, user as username, domain, uuid,"
 												"cid_name, cid_number, in_folder, file_path, message_len, flags, read_flags from voicemail_data",
 												NULL) != SWITCH_ODBC_SUCCESS) {
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to migrate old voicemail_data to voicemail_msgs!\n");
-                        continue;
-                    }
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to migrate old voicemail_data to voicemail_msgs!\n");
+						continue;
+					}
 					switch_odbc_handle_exec(profile->master_odbc, "drop table voicemail_data", NULL);
-                }
-
+				}
 #endif
 			} else {
 				if ((db = switch_core_db_open_file(profile->dbname))) {
@@ -604,12 +586,12 @@
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Migrating data from voicemail_data to voicemail_msgs!\n");
 						switch_core_db_exec(db, "insert into voicemail_msgs select created_epoch, read_epoch, user as username, domain, uuid,"
 											"cid_name, cid_number, in_folder, file_path, message_len, flags, read_flags from voicemail_data",
-										    NULL, NULL, &errmsg);
+											NULL, NULL, &errmsg);
 						if (errmsg) {
 							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n", errmsg);
 							switch_core_db_free(errmsg);
 							errmsg = NULL;
-						} 
+						}
 						switch_core_db_exec(db, "drop table voicemail_data", NULL, NULL, &errmsg);
 						if (errmsg) {
 							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n", errmsg);
@@ -625,7 +607,7 @@
 					continue;
 				}
 				switch_core_db_close(db);
-			}            
+			}
 
 			profile->web_head = web_head;
 			profile->web_tail = web_tail;
@@ -660,13 +642,13 @@
 			*profile->rew_key = *rew_key;
 			*profile->urgent_key = *urgent_key;
 			*profile->operator_key = *operator_key;
-                        *profile->vmain_key = *vmain_key;
+			*profile->vmain_key = *vmain_key;
 			profile->record_threshold = record_threshold;
 			profile->record_silence_hits = record_silence_hits;
 			profile->record_sample_rate = record_sample_rate;
 
 			profile->operator_ext = switch_core_strdup(globals.pool, operator_ext);
-                        profile->vmain_ext = switch_core_strdup(globals.pool, vmain_ext);
+			profile->vmain_ext = switch_core_strdup(globals.pool, vmain_ext);
 			profile->storage_dir = switch_core_strdup(globals.pool, storage_dir);
 			profile->tone_spec = switch_core_strdup(globals.pool, tone_spec);
 			profile->callback_dialplan = switch_core_strdup(globals.pool, callback_dialplan);
@@ -684,7 +666,7 @@
 		}
 	}
 
-end:
+  end:
 	switch_xml_free(xml);
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -730,7 +712,9 @@
 			switch_file_handle_t *fh = cc->fh;
 			uint32_t pos = 0;
 
-			if (!cc->noexit && (dtmf->digit == *cc->profile->delete_file_key || dtmf->digit == *cc->profile->save_file_key || dtmf->digit == *cc->profile->terminator_key)) {
+			if (!cc->noexit
+				&& (dtmf->digit == *cc->profile->delete_file_key || dtmf->digit == *cc->profile->save_file_key
+					|| dtmf->digit == *cc->profile->terminator_key)) {
 				*cc->buf = dtmf->digit;
 				return SWITCH_STATUS_BREAK;
 			}
@@ -770,7 +754,7 @@
 		break;
 	default:
 		break;
-		}
+	}
 
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -834,12 +818,7 @@
 static switch_status_t vm_macro_get(switch_core_session_t *session,
 									char *macro,
 									char *macro_arg,
-									char *buf,
-									switch_size_t buflen,
-									switch_size_t maxlen,
-									char *term_chars,
-									char *terminator_key,
-									uint32_t timeout)
+									char *buf, switch_size_t buflen, switch_size_t maxlen, char *term_chars, char *terminator_key, uint32_t timeout)
 {
 	switch_input_args_t args = { 0 }, *ap = NULL;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
@@ -849,7 +828,7 @@
 		memset(buf, 0, buflen);
 		args.input_callback = cancel_on_dtmf;
 		args.buf = buf;
-		args.buflen = (uint32_t)buflen;
+		args.buflen = (uint32_t) buflen;
 		ap = &args;
 	}
 
@@ -869,7 +848,7 @@
 	bslen = strlen(buf);
 
 	if (maxlen == 0 || maxlen > buflen - 1) {
-		maxlen = buflen -1;
+		maxlen = buflen - 1;
 	}
 	if (bslen < maxlen) {
 		status = switch_ivr_collect_digits_count(session, buf + bslen, buflen, maxlen - bslen, term_chars, terminator_key, timeout, 0, 0);
@@ -913,29 +892,26 @@
 } msg_type_t;
 
 
-static switch_status_t create_file(switch_core_session_t *session, vm_profile_t *profile, 
-                                   char *macro_name, char *file_path, switch_size_t *message_len, switch_bool_t limit)
+static switch_status_t create_file(switch_core_session_t *session, vm_profile_t *profile,
+								   char *macro_name, char *file_path, switch_size_t *message_len, switch_bool_t limit)
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
 	switch_file_handle_t fh = { 0 };
 	switch_input_args_t args = { 0 };
 	char term;
-	char input[10] = "" , key_buf[80] = "";
+	char input[10] = "", key_buf[80] = "";
 	cc_t cc = { 0 };
 	switch_codec_t *read_codec;
 
 	read_codec = switch_core_session_get_read_codec(session);
 
-	while(switch_channel_ready(channel)) {
+	while (switch_channel_ready(channel)) {
 
-		switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s", 
-			profile->listen_file_key,
-			profile->save_file_key,
-			profile->record_file_key);
+		switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s", profile->listen_file_key, profile->save_file_key, profile->record_file_key);
 
-record_file:
-        *message_len = 0;
+	  record_file:
+		*message_len = 0;
 		args.input_callback = cancel_on_dtmf;
 		TRY_CODE(switch_ivr_phrase_macro(session, macro_name, NULL, NULL, NULL));
 		TRY_CODE(switch_ivr_gentones(session, profile->tone_spec, 0, NULL));
@@ -946,22 +922,22 @@
 		fh.samplerate = profile->record_sample_rate;
 		switch_ivr_record_file(session, &fh, file_path, &args, profile->max_record_len);
 		if (limit && (*message_len = fh.sample_count / read_codec->implementation->actual_samples_per_second) < profile->min_record_len) {
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Message is less than minimum record length: %d, discarding it.\n", 
-                              profile->min_record_len);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Message is less than minimum record length: %d, discarding it.\n",
+							  profile->min_record_len);
 			if (unlink(file_path) != 0) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "failed to delete file [%s]\n", file_path);
 			}
-            if (switch_channel_ready(channel)) {
-                /* TODO Rel 1.0 : Add Playback of Prompt <message is too short, please rerecord your message>, then go back at record_file */
-                goto record_file;
-            } else {
-                status = SWITCH_STATUS_BREAK;
-                goto end;
-            }
-        } else {
-            status = SWITCH_STATUS_SUCCESS;
-        }
-play_file:
+			if (switch_channel_ready(channel)) {
+				/* TODO Rel 1.0 : Add Playback of Prompt <message is too short, please rerecord your message>, then go back at record_file */
+				goto record_file;
+			} else {
+				status = SWITCH_STATUS_BREAK;
+				goto end;
+			}
+		} else {
+			status = SWITCH_STATUS_SUCCESS;
+		}
+	  play_file:
 		memset(&fh, 0, sizeof(fh));
 		args.input_callback = control_playback;
 		memset(&cc, 0, sizeof(cc));
@@ -970,15 +946,14 @@
 		args.buf = &cc;
 		switch_ivr_play_file(session, &fh, file_path, &args);
 
-		while(switch_channel_ready(channel)) {
+		while (switch_channel_ready(channel)) {
 			if (*cc.buf) {
 				*input = *cc.buf;
-				*(input+1) = '\0';
+				*(input + 1) = '\0';
 				status = SWITCH_STATUS_SUCCESS;
 				*cc.buf = '\0';
 			} else {
-				status = vm_macro_get(session, VM_RECORD_FILE_CHECK_MACRO, 
-					key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout);
+				status = vm_macro_get(session, VM_RECORD_FILE_CHECK_MACRO, key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout);
 			}
 
 			if (!strcmp(input, profile->listen_file_key)) {
@@ -992,7 +967,7 @@
 		}
 	}
 
-end:
+  end:
 	return status;
 }
 
@@ -1042,7 +1017,7 @@
 }
 
 
-static void message_count(vm_profile_t *profile, const char *myid, const char *domain_name, char *myfolder, 
+static void message_count(vm_profile_t *profile, const char *myid, const char *domain_name, char *myfolder,
 						  int *total_new_messages, int *total_saved_messages, int *total_new_urgent_messages, int *total_saved_urgent_messages)
 {
 	char msg_count[80] = "";
@@ -1052,37 +1027,27 @@
 	cbt.buf = msg_count;
 	cbt.len = sizeof(msg_count);
 
-	switch_snprintf(sql, sizeof(sql), 
-		"select count(*) from voicemail_msgs where username='%s' and domain='%s' and in_folder='%s' and read_epoch=0", 
-		myid,
-		domain_name,
-		myfolder);
+	switch_snprintf(sql, sizeof(sql),
+					"select count(*) from voicemail_msgs where username='%s' and domain='%s' and in_folder='%s' and read_epoch=0",
+					myid, domain_name, myfolder);
 	vm_execute_sql_callback(profile, profile->mutex, sql, sql2str_callback, &cbt);
 	*total_new_messages = atoi(msg_count);
 
-	switch_snprintf(sql, sizeof(sql), 
-		"select count(*) from voicemail_msgs where username='%s' and domain='%s' and in_folder='%s' and read_epoch=0 and read_flags='%s'", 
-		myid,
-		domain_name,
-		myfolder, 
-		URGENT_FLAG_STRING);
+	switch_snprintf(sql, sizeof(sql),
+					"select count(*) from voicemail_msgs where username='%s' and domain='%s' and in_folder='%s' and read_epoch=0 and read_flags='%s'",
+					myid, domain_name, myfolder, URGENT_FLAG_STRING);
 	vm_execute_sql_callback(profile, profile->mutex, sql, sql2str_callback, &cbt);
 	*total_new_urgent_messages = atoi(msg_count);
 
-	switch_snprintf(sql, sizeof(sql), 
-		"select count(*) from voicemail_msgs where username='%s' and domain='%s' and in_folder='%s' and read_epoch!=0", 
-		myid,
-		domain_name,
-		myfolder);
+	switch_snprintf(sql, sizeof(sql),
+					"select count(*) from voicemail_msgs where username='%s' and domain='%s' and in_folder='%s' and read_epoch!=0",
+					myid, domain_name, myfolder);
 	vm_execute_sql_callback(profile, profile->mutex, sql, sql2str_callback, &cbt);
 	*total_saved_messages = atoi(msg_count);
 
-	switch_snprintf(sql, sizeof(sql), 
-		"select count(*) from voicemail_msgs where username='%s' and domain='%s' and in_folder='%s' and read_epoch!=0 and read_flags='%s'", 
-		myid,
-		domain_name,
-		myfolder,
-		URGENT_FLAG_STRING);
+	switch_snprintf(sql, sizeof(sql),
+					"select count(*) from voicemail_msgs where username='%s' and domain='%s' and in_folder='%s' and read_epoch!=0 and read_flags='%s'",
+					myid, domain_name, myfolder, URGENT_FLAG_STRING);
 	vm_execute_sql_callback(profile, profile->mutex, sql, sql2str_callback, &cbt);
 	*total_saved_urgent_messages = atoi(msg_count);
 }
@@ -1094,7 +1059,7 @@
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
 	switch_input_args_t args = { 0 };
 	char term;
-	char input[10] = "" , key_buf[80] = "";
+	char input[10] = "", key_buf[80] = "";
 	switch_file_handle_t fh = { 0 };
 	cc_t cc = { 0 };
 
@@ -1102,14 +1067,10 @@
 
 		args.input_callback = cancel_on_dtmf;
 
-		switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s:%s:%s", 
-			profile->listen_file_key,
-			profile->save_file_key,
-			profile->delete_file_key,
-			profile->email_key,
-			profile->callback_key);
+		switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s:%s:%s",
+						profile->listen_file_key, profile->save_file_key, profile->delete_file_key, profile->email_key, profile->callback_key);
 
-		switch_snprintf(input, sizeof(input), "%s:%d", cbt->type == MSG_NEW ? "new" : "saved", cbt->want+1);
+		switch_snprintf(input, sizeof(input), "%s:%d", cbt->type == MSG_NEW ? "new" : "saved", cbt->want + 1);
 		memset(&cc, 0, sizeof(cc));
 		cc.profile = profile;
 		args.buf = &cc;
@@ -1118,7 +1079,7 @@
 		if (!*cc.buf) {
 			TRY_CODE(switch_ivr_phrase_macro(session, VM_SAY_DATE_MACRO, cbt->created_epoch, NULL, &args));
 		}
-play_file:
+	  play_file:
 
 		if (!*cc.buf) {
 			memset(&fh, 0, sizeof(fh));
@@ -1133,12 +1094,11 @@
 		if (switch_channel_ready(channel)) {
 			if (*cc.buf) {
 				*input = *cc.buf;
-				*(input+1) = '\0';
+				*(input + 1) = '\0';
 				status = SWITCH_STATUS_SUCCESS;
 				*cc.buf = '\0';
 			} else {
-				status = vm_macro_get(session, VM_LISTEN_FILE_CHECK_MACRO, 
-					key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout);
+				status = vm_macro_get(session, VM_LISTEN_FILE_CHECK_MACRO, key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout);
 			}
 			if (!strcmp(input, profile->listen_file_key)) {
 				goto play_file;
@@ -1157,7 +1117,7 @@
 					switch_size_t retsize;
 					switch_time_exp_t tm;
 					char date[80] = "";
-					char tmp[50]="";
+					char tmp[50] = "";
 					int total_new_messages = 0;
 					int total_saved_messages = 0;
 					int total_new_urgent_messages = 0;
@@ -1173,18 +1133,18 @@
 					}
 
 					message_count(profile, cbt->user, cbt->domain, cbt->in_folder, &total_new_messages, &total_saved_messages,
-						&total_new_urgent_messages, &total_saved_urgent_messages);
+								  &total_new_urgent_messages, &total_saved_urgent_messages);
 
 					switch_time_exp_lt(&tm, atoi(cbt->created_epoch) * 1000000);
 					switch_strftime(date, &retsize, sizeof(date), profile->date_fmt, &tm);
 
-					switch_snprintf(tmp,sizeof(tmp), "%d", total_new_messages);
+					switch_snprintf(tmp, sizeof(tmp), "%d", total_new_messages);
 					switch_channel_set_variable(channel, "voicemail_total_new_messages", tmp);
-					switch_snprintf(tmp,sizeof(tmp), "%d", total_saved_messages);
+					switch_snprintf(tmp, sizeof(tmp), "%d", total_saved_messages);
 					switch_channel_set_variable(channel, "voicemail_total_saved_messages", tmp);
-					switch_snprintf(tmp,sizeof(tmp), "%d", total_new_urgent_messages);
+					switch_snprintf(tmp, sizeof(tmp), "%d", total_new_urgent_messages);
 					switch_channel_set_variable(channel, "voicemail_urgent_new_messages", tmp);
-					switch_snprintf(tmp,sizeof(tmp), "%d", total_saved_urgent_messages);
+					switch_snprintf(tmp, sizeof(tmp), "%d", total_saved_urgent_messages);
 					switch_channel_set_variable(channel, "voicemail_urgent_saved_messages", tmp);
 					switch_channel_set_variable(channel, "voicemail_current_folder", cbt->in_folder);
 					switch_channel_set_variable(channel, "voicemail_account", cbt->user);
@@ -1194,7 +1154,7 @@
 					switch_channel_set_variable(channel, "voicemail_file_path", cbt->file_path);
 					switch_channel_set_variable(channel, "voicemail_read_flags", cbt->read_flags);
 					switch_channel_set_variable(channel, "voicemail_time", date);
-					switch_snprintf(tmp,sizeof(tmp), "%d", priority);
+					switch_snprintf(tmp, sizeof(tmp), "%d", priority);
 					switch_channel_set_variable(channel, "voicemail_priority", tmp);
 					message_len = atoi(cbt->message_len);
 
@@ -1203,11 +1163,7 @@
 					duration.day += duration.yr * 365;
 					duration.hr += duration.day * 24;
 
-					switch_snprintf(duration_str, sizeof(duration_str), "%.2u:%.2u:%.2u", 
-						duration.hr,
-						duration.min,
-						duration.sec
-						);
+					switch_snprintf(duration_str, sizeof(duration_str), "%.2u:%.2u:%.2u", duration.hr, duration.min, duration.sec);
 
 					switch_channel_set_variable(channel, "voicemail_message_len", duration_str);
 					switch_channel_set_variable(channel, "voicemail_email", cbt->email);
@@ -1215,20 +1171,20 @@
 					if (switch_strlen_zero(profile->email_headers)) {
 						from = switch_core_session_sprintf(session, "%s@%s", cbt->user, cbt->domain);
 					} else {
-						from = switch_channel_expand_variables(channel,profile->email_from);
+						from = switch_channel_expand_variables(channel, profile->email_from);
 					}
 
 					if (switch_strlen_zero(profile->email_headers)) {
-						headers = switch_core_session_sprintf(session, 
-							"From: FreeSWITCH mod_voicemail <%s@%s>\nSubject: Voicemail from %s %s\nX-Priority: %d", 
-							cbt->user, cbt->domain, cbt->cid_name, cbt->cid_number, priority);
+						headers = switch_core_session_sprintf(session,
+															  "From: FreeSWITCH mod_voicemail <%s@%s>\nSubject: Voicemail from %s %s\nX-Priority: %d",
+															  cbt->user, cbt->domain, cbt->cid_name, cbt->cid_number, priority);
 					} else {
-						headers = switch_channel_expand_variables(channel,profile->email_headers);
+						headers = switch_channel_expand_variables(channel, profile->email_headers);
 					}
 
 					p = headers + (strlen(headers) - 1);
 					if (*p == '\n') {
-						if (*(p-1) == '\r') {
+						if (*(p - 1) == '\r') {
 							p--;
 						}
 						*p = '\0';
@@ -1238,8 +1194,8 @@
 
 					if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
 						/* this isnt done?  it was in the other place
-						* switch_channel_event_set_data(channel, event);
-						*/
+						 * switch_channel_event_set_data(channel, event);
+						 */
 						switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Message-Type", "forwarded-voicemail");
 						switch_event_fire(&event);
 					}
@@ -1247,8 +1203,7 @@
 					if (profile->email_body) {
 						body = switch_channel_expand_variables(channel, profile->email_body);
 					} else {
-						body = switch_mprintf("%u second Voicemail from %s %s", message_len, 
-							cbt->cid_name, cbt->cid_number);
+						body = switch_mprintf("%u second Voicemail from %s %s", message_len, cbt->cid_name, cbt->cid_number);
 					}
 
 					switch_simple_email(cbt->email, from, header_string, body, cbt->file_path);
@@ -1267,7 +1222,7 @@
 		}
 	}
 
-end:
+  end:
 
 	return status;
 }
@@ -1307,413 +1262,407 @@
 	args.buflen = sizeof(foo);
 	status = switch_ivr_phrase_macro(session, VM_HELLO_MACRO, NULL, NULL, &args);
 
-	while(switch_channel_ready(channel)) {
+	while (switch_channel_ready(channel)) {
 		switch_ivr_sleep(session, 100);
 
-		switch(vm_check_state) {
-case VM_CHECK_START:
-	{
-		total_new_messages = 0;
-		total_saved_messages = 0;
-		total_new_urgent_messages = 0;
-		total_saved_urgent_messages = 0;
-		heard_auto_saved = 0;
-		heard_auto_new = 0;
-		play_msg_type = MSG_NONE;
-		attempts = profile->max_login_attempts;
-		myid = id;
-		mypass = NULL;
-		myfolder = "inbox";
-		vm_check_state = VM_CHECK_AUTH;
-		if (x_domain_root) {
-			switch_xml_free(x_domain_root);
-		}
-		x_user = x_domain = x_domain_root = NULL;
-	}
-	break;
-case VM_CHECK_FOLDER_SUMMARY:
-	{
-		int informed = 0;
-		char msg_count[80] = "";
+		switch (vm_check_state) {
+		case VM_CHECK_START:
+			{
+				total_new_messages = 0;
+				total_saved_messages = 0;
+				total_new_urgent_messages = 0;
+				total_saved_urgent_messages = 0;
+				heard_auto_saved = 0;
+				heard_auto_new = 0;
+				play_msg_type = MSG_NONE;
+				attempts = profile->max_login_attempts;
+				myid = id;
+				mypass = NULL;
+				myfolder = "inbox";
+				vm_check_state = VM_CHECK_AUTH;
+				if (x_domain_root) {
+					switch_xml_free(x_domain_root);
+				}
+				x_user = x_domain = x_domain_root = NULL;
+			}
+			break;
+		case VM_CHECK_FOLDER_SUMMARY:
+			{
+				int informed = 0;
+				char msg_count[80] = "";
 
-		switch_channel_set_variable(channel, "voicemail_current_folder", myfolder);
-		message_count(profile, myid, domain_name, myfolder, &total_new_messages, &total_saved_messages, 
-			&total_new_urgent_messages, &total_saved_urgent_messages);
+				switch_channel_set_variable(channel, "voicemail_current_folder", myfolder);
+				message_count(profile, myid, domain_name, myfolder, &total_new_messages, &total_saved_messages,
+							  &total_new_urgent_messages, &total_saved_urgent_messages);
 
-		if (total_new_urgent_messages > 0) {
-			switch_snprintf(msg_count, sizeof(msg_count), "%d:urgent-new", total_new_urgent_messages);
-			TRY_CODE(switch_ivr_phrase_macro(session, VM_MESSAGE_COUNT_MACRO, msg_count, NULL, NULL));
-			informed++;
-		}
-		if (total_new_messages > 0 && total_new_messages != total_new_urgent_messages) {
-			switch_snprintf(msg_count, sizeof(msg_count), "%d:new", total_new_messages);
-			TRY_CODE(switch_ivr_phrase_macro(session, VM_MESSAGE_COUNT_MACRO, msg_count, NULL, NULL));
-			informed++;
-		}
+				if (total_new_urgent_messages > 0) {
+					switch_snprintf(msg_count, sizeof(msg_count), "%d:urgent-new", total_new_urgent_messages);
+					TRY_CODE(switch_ivr_phrase_macro(session, VM_MESSAGE_COUNT_MACRO, msg_count, NULL, NULL));
+					informed++;
+				}
+				if (total_new_messages > 0 && total_new_messages != total_new_urgent_messages) {
+					switch_snprintf(msg_count, sizeof(msg_count), "%d:new", total_new_messages);
+					TRY_CODE(switch_ivr_phrase_macro(session, VM_MESSAGE_COUNT_MACRO, msg_count, NULL, NULL));
+					informed++;
+				}
 
-		if (!heard_auto_new && total_new_messages + total_new_urgent_messages> 0) {
-			heard_auto_new = 1;
-			play_msg_type = MSG_NEW;
-			vm_check_state = VM_CHECK_PLAY_MESSAGES;
-			continue;
-		}
+				if (!heard_auto_new && total_new_messages + total_new_urgent_messages > 0) {
+					heard_auto_new = 1;
+					play_msg_type = MSG_NEW;
+					vm_check_state = VM_CHECK_PLAY_MESSAGES;
+					continue;
+				}
 
-		if (total_saved_urgent_messages > 0) {
-			switch_snprintf(msg_count, sizeof(msg_count), "%d:urgent-saved", total_saved_urgent_messages);
-			TRY_CODE(switch_ivr_phrase_macro(session, VM_MESSAGE_COUNT_MACRO, msg_count, NULL, NULL));
-			informed++;
-		}
+				if (total_saved_urgent_messages > 0) {
+					switch_snprintf(msg_count, sizeof(msg_count), "%d:urgent-saved", total_saved_urgent_messages);
+					TRY_CODE(switch_ivr_phrase_macro(session, VM_MESSAGE_COUNT_MACRO, msg_count, NULL, NULL));
+					informed++;
+				}
+
+				if (total_saved_messages > 0 && total_saved_messages != total_saved_urgent_messages) {
+					switch_snprintf(msg_count, sizeof(msg_count), "%d:saved", total_saved_messages);
+					TRY_CODE(switch_ivr_phrase_macro(session, VM_MESSAGE_COUNT_MACRO, msg_count, NULL, NULL));
+					informed++;
+				}
+
+				if (!heard_auto_saved && total_saved_messages + total_saved_urgent_messages > 0) {
+					heard_auto_saved = 1;
+					play_msg_type = MSG_SAVED;
+					vm_check_state = VM_CHECK_PLAY_MESSAGES;
+					continue;
+				}
 
-		if (total_saved_messages > 0 && total_saved_messages != total_saved_urgent_messages) {
-			switch_snprintf(msg_count, sizeof(msg_count), "%d:saved", total_saved_messages);
-			TRY_CODE(switch_ivr_phrase_macro(session, VM_MESSAGE_COUNT_MACRO, msg_count, NULL, NULL));
-			informed++;
-		}
+				if (!informed) {
+					switch_snprintf(msg_count, sizeof(msg_count), "0:new");
+					TRY_CODE(switch_ivr_phrase_macro(session, VM_MESSAGE_COUNT_MACRO, msg_count, NULL, NULL));
+					informed++;
+				}
 
-		if (!heard_auto_saved && total_saved_messages + total_saved_urgent_messages> 0) {
-			heard_auto_saved = 1;
-			play_msg_type = MSG_SAVED;
-			vm_check_state = VM_CHECK_PLAY_MESSAGES;
-			continue;
-		}
+				vm_check_state = VM_CHECK_MENU;
+			}
+			break;
+		case VM_CHECK_PLAY_MESSAGES:
+			{
+				listen_callback_t cbt;
+				char sql[256];
+				int cur_message, total_messages;
+				switch_event_t *event;
 
-		if (!informed) {
-			switch_snprintf(msg_count, sizeof(msg_count), "0:new");
-			TRY_CODE(switch_ivr_phrase_macro(session, VM_MESSAGE_COUNT_MACRO, msg_count, NULL, NULL));
-			informed++;
-		}
+				message_count(profile, myid, domain_name, myfolder, &total_new_messages, &total_saved_messages,
+							  &total_new_urgent_messages, &total_saved_urgent_messages);
+				memset(&cbt, 0, sizeof(cbt));
+				cbt.email = email_vm;
+				switch (play_msg_type) {
+				case MSG_NEW:
+					{
+						switch_snprintf(sql, sizeof(sql),
+										"select * from voicemail_msgs where username='%s' and domain='%s' and read_epoch=0 order by read_flags", myid,
+										domain_name);
+						total_messages = total_new_messages;
+						heard_auto_new = heard_auto_saved = 1;
+					}
+					break;
+				case MSG_SAVED:
+				default:
+					{
+						switch_snprintf(sql, sizeof(sql),
+										"select * from voicemail_msgs where username='%s' and domain='%s' and read_epoch !=0 order by read_flags", myid,
+										domain_name);
+						total_messages = total_saved_messages;
+						heard_auto_new = heard_auto_saved = 1;
+					}
+					break;
+				}
+				for (cur_message = 0; cur_message < total_messages; cur_message++) {
+					cbt.index = 0;
+					cbt.want = cur_message;
+					cbt.type = play_msg_type;
+					vm_execute_sql_callback(profile, profile->mutex, sql, listen_callback, &cbt);
+					status = listen_file(session, profile, &cbt);
+					if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
+						break;
+					}
+				}
+				switch_snprintf(sql, sizeof(sql), "update voicemail_msgs set read_epoch=%ld where username='%s' and domain='%s' and flags='save'",
+								(long) switch_timestamp(NULL), myid, domain_name);
+				vm_execute_sql(profile, sql, profile->mutex);
+				switch_snprintf(sql, sizeof(sql), "select file_path from voicemail_msgs where username='%s' and domain='%s' and flags='delete'", myid,
+								domain_name);
+				vm_execute_sql_callback(profile, profile->mutex, sql, unlink_callback, NULL);
+				switch_snprintf(sql, sizeof(sql), "delete from voicemail_msgs where username='%s' and domain='%s' and flags='delete'", myid, domain_name);
+				vm_execute_sql(profile, sql, profile->mutex);
+				vm_check_state = VM_CHECK_FOLDER_SUMMARY;
 
-		vm_check_state = VM_CHECK_MENU;
-	}
-	break;
-case VM_CHECK_PLAY_MESSAGES:
-	{
-		listen_callback_t cbt;
-		char sql[256];
-		int cur_message, total_messages;
-		switch_event_t *event;
+				message_count(profile, id, domain_name, myfolder, &total_new_messages, &total_saved_messages,
+							  &total_new_urgent_messages, &total_saved_urgent_messages);
 
-		message_count(profile, myid, domain_name, myfolder, &total_new_messages, &total_saved_messages, 
-			&total_new_urgent_messages, &total_saved_urgent_messages);
-		memset(&cbt, 0, sizeof(cbt));
-		cbt.email = email_vm;
-		switch(play_msg_type) {
-case MSG_NEW:
-	{
-		switch_snprintf(sql, sizeof(sql),
-			"select * from voicemail_msgs where username='%s' and domain='%s' and read_epoch=0 order by read_flags", myid, domain_name);
-		total_messages = total_new_messages;
-		heard_auto_new = heard_auto_saved = 1;
-	}
-	break;
-case MSG_SAVED:
-default:
-	{
-		switch_snprintf(sql, sizeof(sql),
-			"select * from voicemail_msgs where username='%s' and domain='%s' and read_epoch !=0 order by read_flags", myid, domain_name);
-		total_messages = total_saved_messages;
-		heard_auto_new = heard_auto_saved = 1;                        
-	}
-	break;
-		}
-		for (cur_message = 0; cur_message < total_messages; cur_message++) {
-			cbt.index = 0;
-			cbt.want = cur_message;
-			cbt.type = play_msg_type;
-			vm_execute_sql_callback(profile, profile->mutex, sql, listen_callback, &cbt);
-			status = listen_file(session, profile, &cbt);
-			if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
-				break;
+				if (switch_event_create(&event, SWITCH_EVENT_MESSAGE_WAITING) == SWITCH_STATUS_SUCCESS) {
+					char *mwi_id;
+					const char *yn = "no";
+					if (total_new_messages || total_new_urgent_messages) {
+						yn = "yes";
+					}
+					mwi_id = switch_mprintf("%s@%s", myid, domain_name);
+					switch_assert(mwi_id);
+					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Messages-Waiting", "%s", yn);
+					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Message-Account", mwi_id);
+					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d (%d/%d)",
+											total_new_messages, total_saved_messages, total_new_urgent_messages, total_saved_urgent_messages);
+					switch_event_fire(&event);
+					switch_safe_free(mwi_id);
+				}
 			}
-		}
-		switch_snprintf(sql, sizeof(sql), "update voicemail_msgs set read_epoch=%ld where username='%s' and domain='%s' and flags='save'", 
-			(long)switch_timestamp(NULL), myid, domain_name);
-		vm_execute_sql(profile, sql, profile->mutex);
-		switch_snprintf(sql, sizeof(sql), "select file_path from voicemail_msgs where username='%s' and domain='%s' and flags='delete'", myid, domain_name);
-		vm_execute_sql_callback(profile, profile->mutex, sql, unlink_callback, NULL);
-		switch_snprintf(sql, sizeof(sql), "delete from voicemail_msgs where username='%s' and domain='%s' and flags='delete'", myid, domain_name);
-		vm_execute_sql(profile, sql, profile->mutex);
-		vm_check_state = VM_CHECK_FOLDER_SUMMARY;
+			break;
+		case VM_CHECK_CONFIG:
+			{
+				char *sql = NULL;
+				char input[10] = "";
+				char key_buf[80] = "";
+				callback_t cbt = { 0 };
+				char msg_count[80] = "";
+				cc_t cc = { 0 };
+				switch_size_t message_len = 0;
+
+				cbt.buf = msg_count;
+				cbt.len = sizeof(msg_count);
+				sql = switch_mprintf("select count(*) from voicemail_prefs where username='%q' and domain = '%q'", myid, domain_name);
+				vm_execute_sql_callback(profile, profile->mutex, sql, sql2str_callback, &cbt);
+				switch_safe_free(sql);
+				if (*msg_count == '\0' || !atoi(msg_count)) {
+					sql = switch_mprintf("insert into voicemail_prefs values('%q','%q','','')", myid, domain_name);
+					vm_execute_sql(profile, sql, profile->mutex);
+					switch_safe_free(sql);
+				}
 
-		message_count(profile, id, domain_name, myfolder, &total_new_messages, &total_saved_messages,
-			&total_new_urgent_messages, &total_saved_urgent_messages);
+				switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s:%s",
+								profile->record_greeting_key, profile->choose_greeting_key, profile->record_name_key, profile->main_menu_key);
 
-		if (switch_event_create(&event, SWITCH_EVENT_MESSAGE_WAITING) == SWITCH_STATUS_SUCCESS) {
-			char *mwi_id;
-			const char *yn = "no";
-			if (total_new_messages || total_new_urgent_messages ) {
-				yn = "yes";
-			}
-			mwi_id = switch_mprintf("%s@%s", myid, domain_name);
-			switch_assert(mwi_id);
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Messages-Waiting", "%s", yn);
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Message-Account", mwi_id);
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d (%d/%d)", 
-				total_new_messages, total_saved_messages, total_new_urgent_messages, total_saved_urgent_messages);
-			switch_event_fire(&event);
-			switch_safe_free(mwi_id);
-		} 
-	}
-	break;
-case VM_CHECK_CONFIG:
-	{
-		char *sql = NULL;
-		char input[10] = "";
-		char key_buf[80] = "";
-		callback_t cbt = { 0 };
-		char msg_count[80] = "";
-		cc_t cc = { 0 };
-		switch_size_t message_len = 0;
-
-		cbt.buf = msg_count;
-		cbt.len = sizeof(msg_count);
-		sql = switch_mprintf("select count(*) from voicemail_prefs where username='%q' and domain = '%q'", myid, domain_name);
-		vm_execute_sql_callback(profile, profile->mutex, sql, sql2str_callback, &cbt);
-		switch_safe_free(sql);
-		if (*msg_count == '\0' || !atoi(msg_count)) {
-			sql = switch_mprintf("insert into voicemail_prefs values('%q','%q','','')", myid, domain_name);
-			vm_execute_sql(profile, sql, profile->mutex);
-			switch_safe_free(sql);
-		}
-
-		switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s:%s", 
-			profile->record_greeting_key, 
-			profile->choose_greeting_key, 
-			profile->record_name_key,
-			profile->main_menu_key);
 
+				TRY_CODE(vm_macro_get(session, VM_CONFIG_MENU_MACRO, key_buf, input, sizeof(input), 1, "", &term, timeout));
+				if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
+					goto end;
+				}
 
-		TRY_CODE(vm_macro_get(session, VM_CONFIG_MENU_MACRO, key_buf, input, sizeof(input), 1, "", &term, timeout));
-		if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
-			goto end;
-		}
+				if (!strcmp(input, profile->main_menu_key)) {
+					vm_check_state = VM_CHECK_MENU;
+				} else if (!strcmp(input, profile->choose_greeting_key)) {
+					int num;
+					switch_input_args_t greeting_args = { 0 };
+					greeting_args.input_callback = cancel_on_dtmf;
+
+					TRY_CODE(vm_macro_get(session, VM_CHOOSE_GREETING_MACRO, key_buf, input, sizeof(input), 1, "", &term, timeout));
 
-		if (!strcmp(input, profile->main_menu_key)) {
-			vm_check_state = VM_CHECK_MENU;
-		} else if (!strcmp(input, profile->choose_greeting_key)) {
-			int num;
-			switch_input_args_t greeting_args = { 0 };
-			greeting_args.input_callback = cancel_on_dtmf;
-
-			TRY_CODE(vm_macro_get(session, VM_CHOOSE_GREETING_MACRO, key_buf, input, sizeof(input), 1, "", &term, timeout));
 
+					num = atoi(input);
+					file_path = switch_mprintf("%s%sgreeting_%d.%s", dir_path, SWITCH_PATH_SEPARATOR, num, profile->file_ext);
+					if (num < 1 || num > VM_MAX_GREETINGS) {
+						status = SWITCH_STATUS_FALSE;
+					} else {
+						switch_file_handle_t fh = { 0 };
+						memset(&fh, 0, sizeof(fh));
+						greeting_args.input_callback = control_playback;
+						memset(&cc, 0, sizeof(cc));
+						cc.profile = profile;
+						cc.fh = &fh;
+						cc.noexit = 1;
+						greeting_args.buf = &cc;
+						status = switch_ivr_play_file(session, NULL, file_path, &greeting_args);
+					}
+					if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
+						TRY_CODE(switch_ivr_phrase_macro(session, VM_CHOOSE_GREETING_FAIL_MACRO, NULL, NULL, NULL));
+					} else {
+						TRY_CODE(switch_ivr_phrase_macro(session, VM_CHOOSE_GREETING_SELECTED_MACRO, input, NULL, NULL));
+						sql =
+							switch_mprintf("update voicemail_prefs set greeting_path='%s' where username='%s' and domain='%s'", file_path, myid,
+										   domain_name);
+						vm_execute_sql(profile, sql, profile->mutex);
+						switch_safe_free(sql);
+					}
+					switch_safe_free(file_path);
+				} else if (!strcmp(input, profile->record_greeting_key)) {
+					int num;
+					TRY_CODE(vm_macro_get(session, VM_CHOOSE_GREETING_MACRO, key_buf, input, sizeof(input), 1, "", &term, timeout));
+
+					num = atoi(input);
+					if (num < 1 || num > VM_MAX_GREETINGS) {
+						TRY_CODE(switch_ivr_phrase_macro(session, VM_CHOOSE_GREETING_FAIL_MACRO, NULL, NULL, NULL));
+					} else {
+						file_path = switch_mprintf("%s%sgreeting_%d.%s", dir_path, SWITCH_PATH_SEPARATOR, num, profile->file_ext);
+						TRY_CODE(create_file(session, profile, VM_RECORD_GREETING_MACRO, file_path, &message_len, SWITCH_TRUE));
+						sql =
+							switch_mprintf("update voicemail_prefs set greeting_path='%s' where username='%s' and domain='%s'", file_path, myid,
+										   domain_name);
+						vm_execute_sql(profile, sql, profile->mutex);
+						switch_safe_free(sql);
+						switch_safe_free(file_path);
+					}
 
-			num = atoi(input);
-			file_path = switch_mprintf("%s%sgreeting_%d.%s", dir_path, SWITCH_PATH_SEPARATOR, num, profile->file_ext);
-			if (num < 1 || num > VM_MAX_GREETINGS) {
-				status = SWITCH_STATUS_FALSE;
-			} else {
-				switch_file_handle_t fh = { 0 };
-				memset(&fh, 0, sizeof(fh));
-				greeting_args.input_callback = control_playback;
-				memset(&cc, 0, sizeof(cc));
-				cc.profile = profile;
-				cc.fh = &fh;
-				cc.noexit = 1;
-				greeting_args.buf = &cc;
-				status = switch_ivr_play_file(session, NULL, file_path, &greeting_args);
-			}
-			if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
-				TRY_CODE(switch_ivr_phrase_macro(session, VM_CHOOSE_GREETING_FAIL_MACRO, NULL, NULL, NULL));
-			} else {
-				TRY_CODE(switch_ivr_phrase_macro(session, VM_CHOOSE_GREETING_SELECTED_MACRO, input, NULL, NULL));
-				sql = switch_mprintf("update voicemail_prefs set greeting_path='%s' where username='%s' and domain='%s'", file_path, myid, domain_name);
-				vm_execute_sql(profile, sql, profile->mutex);
-				switch_safe_free(sql);
-			}
-			switch_safe_free(file_path);
-		} else if (!strcmp(input, profile->record_greeting_key)) {
-			int num;
-			TRY_CODE(vm_macro_get(session, VM_CHOOSE_GREETING_MACRO, key_buf, input, sizeof(input), 1, "", &term, timeout));
-
-			num = atoi(input);
-			if (num < 1 || num > VM_MAX_GREETINGS) {
-				TRY_CODE(switch_ivr_phrase_macro(session, VM_CHOOSE_GREETING_FAIL_MACRO, NULL, NULL, NULL));
-			} else {
-				file_path = switch_mprintf("%s%sgreeting_%d.%s", dir_path, SWITCH_PATH_SEPARATOR, num, profile->file_ext);
-				TRY_CODE(create_file(session, profile, VM_RECORD_GREETING_MACRO, file_path, &message_len, SWITCH_TRUE));
-				sql = switch_mprintf("update voicemail_prefs set greeting_path='%s' where username='%s' and domain='%s'", file_path, myid, domain_name);
-				vm_execute_sql(profile, sql, profile->mutex);
-				switch_safe_free(sql);
-				switch_safe_free(file_path);
+				} else if (!strcmp(input, profile->record_name_key)) {
+					file_path = switch_mprintf("%s%srecorded_name.%s", dir_path, SWITCH_PATH_SEPARATOR, profile->file_ext);
+					TRY_CODE(create_file(session, profile, VM_RECORD_NAME_MACRO, file_path, &message_len, SWITCH_FALSE));
+					sql = switch_mprintf("update voicemail_prefs set name_path='%s' where username='%s' and domain='%s'", file_path, myid, domain_name);
+					vm_execute_sql(profile, sql, profile->mutex);
+					switch_safe_free(file_path);
+					switch_safe_free(sql);
+				}
+				continue;
 			}
+			break;
+		case VM_CHECK_MENU:
+			{
+				char input[10] = "";
+				char key_buf[80] = "";
+				play_msg_type = MSG_NONE;
 
-		} else if (!strcmp(input, profile->record_name_key)) {
-			file_path = switch_mprintf("%s%srecorded_name.%s", dir_path, SWITCH_PATH_SEPARATOR, profile->file_ext);
-			TRY_CODE(create_file(session, profile, VM_RECORD_NAME_MACRO, file_path, &message_len, SWITCH_FALSE));
-			sql = switch_mprintf("update voicemail_prefs set name_path='%s' where username='%s' and domain='%s'", file_path, myid, domain_name);
-			vm_execute_sql(profile, sql, profile->mutex);
-			switch_safe_free(file_path);
-			switch_safe_free(sql);
-		}
-		continue;
-	}
-	break;
-case VM_CHECK_MENU:
-	{
-		char input[10] = "";
-		char key_buf[80] = "";
-		play_msg_type = MSG_NONE;
-
-		switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s:%s", 
-			profile->play_new_messages_key, 
-			profile->play_saved_messages_key,
-			profile->config_menu_key,
-			profile->terminator_key);
+				switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s:%s",
+								profile->play_new_messages_key, profile->play_saved_messages_key, profile->config_menu_key, profile->terminator_key);
 
-		status = vm_macro_get(session, VM_MENU_MACRO, key_buf, input, sizeof(input), 1, "", &term, timeout);
+				status = vm_macro_get(session, VM_MENU_MACRO, key_buf, input, sizeof(input), 1, "", &term, timeout);
 
-		if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
-			goto end;
-		}
+				if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
+					goto end;
+				}
 
-		if (!strcmp(input, profile->play_new_messages_key)) {
-			play_msg_type = MSG_NEW;
-		} else if (!strcmp(input, profile->play_saved_messages_key)) {
-			play_msg_type = MSG_SAVED;
-		} else if (!strcmp(input, profile->terminator_key)) {
-			goto end;
-		} else if (!strcmp(input, profile->config_menu_key)) {
-			vm_check_state = VM_CHECK_CONFIG;
-		}
+				if (!strcmp(input, profile->play_new_messages_key)) {
+					play_msg_type = MSG_NEW;
+				} else if (!strcmp(input, profile->play_saved_messages_key)) {
+					play_msg_type = MSG_SAVED;
+				} else if (!strcmp(input, profile->terminator_key)) {
+					goto end;
+				} else if (!strcmp(input, profile->config_menu_key)) {
+					vm_check_state = VM_CHECK_CONFIG;
+				}
 
-		if (play_msg_type) {
-			vm_check_state = VM_CHECK_PLAY_MESSAGES;
-		}
+				if (play_msg_type) {
+					vm_check_state = VM_CHECK_PLAY_MESSAGES;
+				}
 
-		continue;
-	}
-	break;
-case VM_CHECK_AUTH:
-	{
-		if (!attempts) {
-			failed = 1;
-			goto end;
-		}
+				continue;
+			}
+			break;
+		case VM_CHECK_AUTH:
+			{
+				if (!attempts) {
+					failed = 1;
+					goto end;
+				}
 
-		attempts--;
+				attempts--;
 
-		if (!myid) {
-			status = vm_macro_get(session, VM_ENTER_ID_MACRO, profile->terminator_key, id_buf, sizeof(id_buf), 0, 
-				profile->terminator_key, &term, timeout);
-			if (status != SWITCH_STATUS_SUCCESS) {
-				goto end;
-			}
+				if (!myid) {
+					status = vm_macro_get(session, VM_ENTER_ID_MACRO, profile->terminator_key, id_buf, sizeof(id_buf), 0,
+										  profile->terminator_key, &term, timeout);
+					if (status != SWITCH_STATUS_SUCCESS) {
+						goto end;
+					}
 
-			if (*id_buf == '\0') {
-				continue;
-			} else {
-				myid = id_buf;
-			} 
-		}
+					if (*id_buf == '\0') {
+						continue;
+					} else {
+						myid = id_buf;
+					}
+				}
 
-		if (!x_user) {
-            switch_event_t *params;
-			int ok = 1;
-			caller_profile = switch_channel_get_caller_profile(channel);
-
-            switch_event_create(&params, SWITCH_EVENT_MESSAGE);
-            switch_assert(params);
-            switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "mailbox", myid);
-            switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "destination_number", caller_profile->destination_number);
-            switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "caller_id_number", caller_profile->caller_id_number);
-            
-            
-			if (switch_xml_locate_user("id", myid, domain_name, switch_channel_get_variable(channel, "network_addr"), 
-                                       &x_domain_root, &x_domain, &x_user, params) != SWITCH_STATUS_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", myid, domain_name);
-                ok = 0;
-			}
-            
-            switch_event_destroy(&params);
+				if (!x_user) {
+					switch_event_t *params;
+					int ok = 1;
+					caller_profile = switch_channel_get_caller_profile(channel);
+
+					switch_event_create(&params, SWITCH_EVENT_MESSAGE);
+					switch_assert(params);
+					switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "mailbox", myid);
+					switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "destination_number", caller_profile->destination_number);
+					switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "caller_id_number", caller_profile->caller_id_number);
+
+
+					if (switch_xml_locate_user("id", myid, domain_name, switch_channel_get_variable(channel, "network_addr"),
+											   &x_domain_root, &x_domain, &x_user, params) != SWITCH_STATUS_SUCCESS) {
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", myid, domain_name);
+						ok = 0;
+					}
 
-			if (!ok) {
-				goto end;
-			}
-		}
+					switch_event_destroy(&params);
 
-		if (!mypass) {
-			if (auth) {
-				mypass = "OK";
-			} else {
-				status = vm_macro_get(session, VM_ENTER_PASS_MACRO, profile->terminator_key, 
-					pass_buf, sizeof(pass_buf), 0, profile->terminator_key, &term, timeout);
-				if (status != SWITCH_STATUS_SUCCESS) {
-					goto end;
+					if (!ok) {
+						goto end;
+					}
 				}
-				if (*pass_buf == '\0') {
-					continue;
-				} else {
-					mypass = pass_buf;
+
+				if (!mypass) {
+					if (auth) {
+						mypass = "OK";
+					} else {
+						status = vm_macro_get(session, VM_ENTER_PASS_MACRO, profile->terminator_key,
+											  pass_buf, sizeof(pass_buf), 0, profile->terminator_key, &term, timeout);
+						if (status != SWITCH_STATUS_SUCCESS) {
+							goto end;
+						}
+						if (*pass_buf == '\0') {
+							continue;
+						} else {
+							mypass = pass_buf;
+						}
+					}
 				}
-			}
-		}
 
-		if (!(x_params = switch_xml_child(x_user, "params"))) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find params for user [%s@%s]\n", myid, domain_name);
-			goto failed;
-		}
+				if (!(x_params = switch_xml_child(x_user, "params"))) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find params for user [%s@%s]\n", myid, domain_name);
+					goto failed;
+				}
+
+				thepass = NULL;
+				for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
+					const char *var = switch_xml_attr_soft(x_param, "name");
+					const char *val = switch_xml_attr_soft(x_param, "value");
+
+					if (!strcasecmp(var, "password")) {
+						thepass = val;
+					} else if (!strcasecmp(var, "vm-password")) {
+						thepass = val;
+					} else if (!strcasecmp(var, "vm-mailto")) {
+						email_vm = switch_core_session_strdup(session, val);
+					}
+				}
+				switch_xml_free(x_domain_root);
+				x_domain_root = NULL;
 
-		thepass = NULL;
-		for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
-			const char *var = switch_xml_attr_soft(x_param, "name");
-			const char *val = switch_xml_attr_soft(x_param, "value");
+				if (auth || !thepass || (thepass && mypass && !strcmp(thepass, mypass))) {
+					if (!dir_path) {
+						if (switch_strlen_zero(profile->storage_dir)) {
+							dir_path = switch_core_session_sprintf(session, "%s%svoicemail%s%s%s%s%s%s", SWITCH_GLOBAL_dirs.storage_dir,
+																   SWITCH_PATH_SEPARATOR,
+																   SWITCH_PATH_SEPARATOR,
+																   profile->name, SWITCH_PATH_SEPARATOR, domain_name, SWITCH_PATH_SEPARATOR, myid);
+						} else {
+							dir_path = switch_core_session_sprintf(session, "%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR, myid);
+						}
 
-			if (!strcasecmp(var, "password")) {
-				thepass = val;
-			} else if (!strcasecmp(var, "vm-password")) {
-				thepass = val;
-			} else if (!strcasecmp(var, "vm-mailto")) {
-				email_vm = switch_core_session_strdup(session, val);
-			}
-		}
-		switch_xml_free(x_domain_root);
-		x_domain_root = NULL;
+						if (switch_dir_make_recursive(dir_path, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", dir_path);
+							return;
+						}
+					}
 
-		if (auth || !thepass || (thepass && mypass && !strcmp(thepass, mypass))) {
-			if (!dir_path) {
-				if (switch_strlen_zero(profile->storage_dir)) {
-					dir_path = switch_core_session_sprintf(session, "%s%svoicemail%s%s%s%s%s%s", SWITCH_GLOBAL_dirs.storage_dir, 
-						SWITCH_PATH_SEPARATOR,
-						SWITCH_PATH_SEPARATOR,
-						profile->name,
-						SWITCH_PATH_SEPARATOR,
-						domain_name,
-						SWITCH_PATH_SEPARATOR,
-						myid);
+					vm_check_state = VM_CHECK_FOLDER_SUMMARY;
 				} else {
-					dir_path = switch_core_session_sprintf(session, "%s%s%s",
-						profile->storage_dir,
-						SWITCH_PATH_SEPARATOR,
-						myid);
+					goto failed;
 				}
 
-				if (switch_dir_make_recursive(dir_path, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", dir_path);
-					return;
-				}
-			}
-
-			vm_check_state = VM_CHECK_FOLDER_SUMMARY;
-		} else {
-			goto failed;
-		}
-
-		continue;
+				continue;
 
-failed:
-		status = switch_ivr_phrase_macro(session, VM_FAIL_AUTH_MACRO, NULL, NULL, NULL);
-		myid = id;
-		mypass = NULL;
-		continue;
-	}
-	break;
-default:
-	break;
+			  failed:
+				status = switch_ivr_phrase_macro(session, VM_FAIL_AUTH_MACRO, NULL, NULL, NULL);
+				myid = id;
+				mypass = NULL;
+				continue;
+			}
+			break;
+		default:
+			break;
 		}
 	}
 
-end:
+  end:
 
 	if (switch_channel_ready(channel)) {
 		if (failed) {
@@ -1743,9 +1692,9 @@
 	switch_file_handle_t fh = { 0 };
 	switch_input_args_t args = { 0 };
 	char *email_vm = NULL;
-    char *email_vm_notify = NULL;
+	char *email_vm_notify = NULL;
 	int send_mail = 0;
-    int send_mail_only = 0;
+	int send_mail_only = 0;
 	cc_t cc = { 0 };
 	char *read_flags = NORMAL_FLAG_STRING;
 	int priority = 3;
@@ -1768,19 +1717,11 @@
 	}
 
 	if (switch_strlen_zero(profile->storage_dir)) {
-		dir_path = switch_core_session_sprintf(session, "%s%svoicemail%s%s%s%s%s%s", SWITCH_GLOBAL_dirs.storage_dir, 
-			SWITCH_PATH_SEPARATOR,
-			SWITCH_PATH_SEPARATOR,
-			profile->name,
-			SWITCH_PATH_SEPARATOR,
-			domain_name,
-			SWITCH_PATH_SEPARATOR,
-			id);
+		dir_path = switch_core_session_sprintf(session, "%s%svoicemail%s%s%s%s%s%s", SWITCH_GLOBAL_dirs.storage_dir,
+											   SWITCH_PATH_SEPARATOR,
+											   SWITCH_PATH_SEPARATOR, profile->name, SWITCH_PATH_SEPARATOR, domain_name, SWITCH_PATH_SEPARATOR, id);
 	} else {
-		dir_path = switch_core_session_sprintf(session, "%s%s%s",
-			profile->storage_dir,
-			SWITCH_PATH_SEPARATOR,
-			id);
+		dir_path = switch_core_session_sprintf(session, "%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR, id);
 	}
 
 	if (switch_dir_make_recursive(dir_path, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
@@ -1790,60 +1731,57 @@
 
 	if (id) {
 		int ok = 1;
-        switch_event_t *params = NULL;
+		switch_event_t *params = NULL;
 		switch_xml_t x_domain, x_domain_root, x_user, x_params, x_param;
 		const char *email_addr = NULL;
-        
-        switch_event_create(&params, SWITCH_EVENT_MESSAGE);
-        switch_assert(params);
-        switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "mailbox", id);
-        
+
+		switch_event_create(&params, SWITCH_EVENT_MESSAGE);
+		switch_assert(params);
+		switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "mailbox", id);
+
 		x_user = x_domain = x_domain_root = NULL;
-		if (switch_xml_locate_user("id", id, domain_name, switch_channel_get_variable(channel, "network_addr"), 
-                                   &x_domain_root, &x_domain, &x_user, params) == SWITCH_STATUS_SUCCESS) {
-            if ((x_params = switch_xml_child(x_user, "params"))) {
-                for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
-						const char *var = switch_xml_attr_soft(x_param, "name");
-						const char *val = switch_xml_attr_soft(x_param, "value");
-
-						if (!strcasecmp(var, "vm-mailto")) {
-							email_vm = switch_core_session_strdup(session, val);
-                        } else if (!strcasecmp(var, "vm-mailto-notify")) {
-                            email_vm_notify = switch_core_session_strdup(session, val);
-						} else if (!strcasecmp(var, "email-addr")) {
-							email_addr = val;
-                        } else if (!strcasecmp(var, "vm-email-only")) {
-                            send_mail_only = switch_true(val);
-						} else if (!strcasecmp(var, "vm-email-all-messages")) {
-							send_mail = switch_true(val);
-						} else if (!strcasecmp(var, "vm-delete-file")) {
-							email_delete = switch_true(val);
-						} else if (!strcasecmp(var, "vm-attach-file")) {
-							email_attach = switch_true(val);
-						}
+		if (switch_xml_locate_user("id", id, domain_name, switch_channel_get_variable(channel, "network_addr"),
+								   &x_domain_root, &x_domain, &x_user, params) == SWITCH_STATUS_SUCCESS) {
+			if ((x_params = switch_xml_child(x_user, "params"))) {
+				for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
+					const char *var = switch_xml_attr_soft(x_param, "name");
+					const char *val = switch_xml_attr_soft(x_param, "value");
+
+					if (!strcasecmp(var, "vm-mailto")) {
+						email_vm = switch_core_session_strdup(session, val);
+					} else if (!strcasecmp(var, "vm-mailto-notify")) {
+						email_vm_notify = switch_core_session_strdup(session, val);
+					} else if (!strcasecmp(var, "email-addr")) {
+						email_addr = val;
+					} else if (!strcasecmp(var, "vm-email-only")) {
+						send_mail_only = switch_true(val);
+					} else if (!strcasecmp(var, "vm-email-all-messages")) {
+						send_mail = switch_true(val);
+					} else if (!strcasecmp(var, "vm-delete-file")) {
+						email_delete = switch_true(val);
+					} else if (!strcasecmp(var, "vm-attach-file")) {
+						email_attach = switch_true(val);
 					}
 				}
+			}
 
-				if (send_mail && switch_strlen_zero(email_vm) && !switch_strlen_zero(email_addr)) {
-					email_vm = switch_core_session_strdup(session, email_addr);
-				}
+			if (send_mail && switch_strlen_zero(email_vm) && !switch_strlen_zero(email_addr)) {
+				email_vm = switch_core_session_strdup(session, email_addr);
+			}
 
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", id, domain_name);
 			ok = 0;
 		}
 
-        switch_event_destroy(&params);
+		switch_event_destroy(&params);
 		switch_xml_free(x_domain_root);
 		if (!ok) {
 			goto end;
 		}
 	}
 
-	switch_snprintf(sql, sizeof(sql), 
-		"select * from voicemail_prefs where username='%s' and domain='%s'", 
-		id,
-		domain_name);
+	switch_snprintf(sql, sizeof(sql), "select * from voicemail_prefs where username='%s' and domain='%s'", id, domain_name);
 	vm_execute_sql_callback(profile, profile->mutex, sql, prefs_callback, &cbt);
 
 	file_path = switch_mprintf("%s%smsg_%s.%s", dir_path, SWITCH_PATH_SEPARATOR, uuid, profile->file_ext);
@@ -1857,7 +1795,7 @@
 		greet_path = cbt.greeting_path;
 	}
 
-greet:
+  greet:
 	memset(buf, 0, sizeof(buf));
 	args.input_callback = cancel_on_dtmf;
 	args.buf = buf;
@@ -1890,7 +1828,7 @@
 				if (argc >= 1 && argc <= 4) {
 					switch_ivr_session_transfer(session, argv[0], argv[1], argv[2]);
 					/* the application still runs after we leave it so we need to make sure that we dont do anything evil */
-					send_mail=0;
+					send_mail = 0;
 					goto end;
 				}
 			}
@@ -1904,7 +1842,7 @@
 				if (argc >= 1 && argc <= 4) {
 					switch_ivr_session_transfer(session, argv[0], argv[1], argv[2]);
 					/* the application still runs after we leave it so we need to make sure that we dont do anything evil */
-					send_mail=0;
+					send_mail = 0;
 					goto end;
 				}
 			}
@@ -1938,9 +1876,7 @@
 	if ((status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK) && switch_channel_ready(channel)) {
 		char input[10] = "", key_buf[80] = "", term = 0;
 
-		switch_snprintf(key_buf, sizeof(key_buf), "%s:%s", 
-			profile->urgent_key,
-			profile->terminator_key);
+		switch_snprintf(key_buf, sizeof(key_buf), "%s:%s", profile->urgent_key, profile->terminator_key);
 
 		vm_macro_get(session, VM_RECORD_URGENT_CHECK_MACRO, key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout);
 		if (*profile->urgent_key == *input) {
@@ -1961,14 +1897,14 @@
 		int total_new_urgent_messages = 0;
 		int total_saved_urgent_messages = 0;
 
-		usql = switch_mprintf("insert into voicemail_msgs values(%ld,0,'%q','%q','%q','%q','%q','%q','%q','%u','','%q')", (long)switch_timestamp(NULL),
-			id, domain_name, uuid, caller_profile->caller_id_name, caller_profile->caller_id_number, 
-			myfolder, file_path, message_len, read_flags);
+		usql = switch_mprintf("insert into voicemail_msgs values(%ld,0,'%q','%q','%q','%q','%q','%q','%q','%u','','%q')", (long) switch_timestamp(NULL),
+							  id, domain_name, uuid, caller_profile->caller_id_name, caller_profile->caller_id_number,
+							  myfolder, file_path, message_len, read_flags);
 		vm_execute_sql(profile, usql, profile->mutex);
 		switch_safe_free(usql);
 
 		message_count(profile, id, domain_name, myfolder, &total_new_messages, &total_saved_messages,
-			&total_new_urgent_messages, &total_saved_urgent_messages);
+					  &total_new_urgent_messages, &total_saved_urgent_messages);
 
 		if (switch_event_create(&event, SWITCH_EVENT_MESSAGE_WAITING) == SWITCH_STATUS_SUCCESS) {
 			const char *yn = "no";
@@ -1978,14 +1914,14 @@
 			mwi_id = switch_mprintf("%s@%s", id, domain_name);
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Messages-Waiting", "%s", yn);
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Message-Account", mwi_id);
-			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d (%d/%d)", 
-				total_new_messages, total_saved_messages, total_new_urgent_messages, total_saved_urgent_messages);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d (%d/%d)",
+									total_new_messages, total_saved_messages, total_new_urgent_messages, total_saved_urgent_messages);
 			switch_event_fire(&event);
 			switch_safe_free(mwi_id);
-		}    
+		}
 	}
 
-end:
+  end:
 
 	if (send_mail && !switch_strlen_zero(email_vm) && switch_file_exists(file_path, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
 		switch_event_t *event;
@@ -1993,7 +1929,7 @@
 		char *body;
 		char *headers;
 		char *header_string;
-		char tmp[50]="";
+		char tmp[50] = "";
 		int total_new_messages = 0;
 		int total_saved_messages = 0;
 		int total_new_urgent_messages = 0;
@@ -2004,19 +1940,19 @@
 		char duration_str[80];
 
 		message_count(profile, id, domain_name, myfolder, &total_new_messages, &total_saved_messages,
-			&total_new_urgent_messages, &total_saved_urgent_messages);
+					  &total_new_urgent_messages, &total_saved_urgent_messages);
 
 		switch_time_exp_lt(&tm, switch_timestamp_now());
 		switch_strftime(date, &retsize, sizeof(date), profile->date_fmt, &tm);
 
 		switch_channel_set_variable(channel, "voicemail_current_folder", myfolder);
-		switch_snprintf(tmp,sizeof(tmp), "%d", total_new_messages);
+		switch_snprintf(tmp, sizeof(tmp), "%d", total_new_messages);
 		switch_channel_set_variable(channel, "voicemail_total_new_messages", tmp);
-		switch_snprintf(tmp,sizeof(tmp), "%d", total_saved_messages);
+		switch_snprintf(tmp, sizeof(tmp), "%d", total_saved_messages);
 		switch_channel_set_variable(channel, "voicemail_total_saved_messages", tmp);
-		switch_snprintf(tmp,sizeof(tmp), "%d", total_new_urgent_messages);
+		switch_snprintf(tmp, sizeof(tmp), "%d", total_new_urgent_messages);
 		switch_channel_set_variable(channel, "voicemail_urgent_new_messages", tmp);
-		switch_snprintf(tmp,sizeof(tmp), "%d", total_saved_urgent_messages);
+		switch_snprintf(tmp, sizeof(tmp), "%d", total_saved_urgent_messages);
 		switch_channel_set_variable(channel, "voicemail_urgent_saved_messages", tmp);
 		switch_channel_set_variable(channel, "voicemail_account", id);
 		switch_channel_set_variable(channel, "voicemail_domain", domain_name);
@@ -2025,19 +1961,15 @@
 		switch_channel_set_variable(channel, "voicemail_file_path", file_path);
 		switch_channel_set_variable(channel, "voicemail_read_flags", read_flags);
 		switch_channel_set_variable(channel, "voicemail_time", date);
-		switch_snprintf(tmp,sizeof(tmp), "%d", priority);
+		switch_snprintf(tmp, sizeof(tmp), "%d", priority);
 		switch_channel_set_variable(channel, "voicemail_priority", tmp);
 		switch_channel_set_variable(channel, "voicemail_email", email_vm);
 
-		l_duration = (long)message_len * 1000000;
+		l_duration = (long) message_len *1000000;
 		switch_core_measure_time(l_duration, &duration);
 		duration.day += duration.yr * 365;
 		duration.hr += duration.day * 24;
-		switch_snprintf(duration_str, sizeof(duration_str), "%.2u:%.2u:%.2u",
-			duration.hr,
-			duration.min,
-			duration.sec
-			);
+		switch_snprintf(duration_str, sizeof(duration_str), "%.2u:%.2u:%.2u", duration.hr, duration.min, duration.sec);
 
 		switch_channel_set_variable(channel, "voicemail_message_len", duration_str);
 
@@ -2048,13 +1980,10 @@
 		}
 
 		if (switch_strlen_zero(profile->email_headers)) {
-			headers = switch_core_session_sprintf(session, 
-				"From: FreeSWITCH mod_voicemail <%s@%s>\n"
-				"Subject: Voicemail from %s %s\nX-Priority: %d", 
-				id, domain_name,
-				caller_profile->caller_id_name, 
-				caller_profile->caller_id_number,
-				priority);
+			headers = switch_core_session_sprintf(session,
+												  "From: FreeSWITCH mod_voicemail <%s@%s>\n"
+												  "Subject: Voicemail from %s %s\nX-Priority: %d",
+												  id, domain_name, caller_profile->caller_id_name, caller_profile->caller_id_number, priority);
 		} else {
 			headers = switch_channel_expand_variables(channel, profile->email_headers);
 		}
@@ -2062,7 +1991,7 @@
 		p = headers + (strlen(headers) - 1);
 
 		if (*p == '\n') {
-			if (*(p-1) == '\r') {
+			if (*(p - 1) == '\r') {
 				p--;
 			}
 			*p = '\0';
@@ -2079,8 +2008,7 @@
 		if (profile->email_body) {
 			body = switch_channel_expand_variables(channel, profile->email_body);
 		} else {
-			body = switch_mprintf("%u second Voicemail from %s %s", message_len,
-				caller_profile->caller_id_name, caller_profile->caller_id_number);
+			body = switch_mprintf("%u second Voicemail from %s %s", message_len, caller_profile->caller_id_name, caller_profile->caller_id_number);
 		}
 
 		if (email_attach) {
@@ -2088,9 +2016,9 @@
 		} else {
 			switch_simple_email(email_vm, from, header_string, body, NULL);
 		}
-        if (!switch_strlen_zero(email_vm_notify)) {
-            switch_simple_email(email_vm_notify, from, header_string, body, NULL);
-        }
+		if (!switch_strlen_zero(email_vm_notify)) {
+			switch_simple_email(email_vm_notify, from, header_string, body, NULL);
+		}
 
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending message to %s\n", email_vm);
 		switch_safe_free(body);
@@ -2126,7 +2054,8 @@
 	int x = 0, check = 0, auth = 0;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 
-	if (switch_dir_make_recursive(SWITCH_GLOBAL_dirs.storage_dir, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+	if (switch_dir_make_recursive(SWITCH_GLOBAL_dirs.storage_dir, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) !=
+		SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", SWITCH_GLOBAL_dirs.storage_dir);
 		return;
 	}
@@ -2216,18 +2145,18 @@
 			free(dup);
 			return SWITCH_STATUS_SUCCESS;
 		}
-		
+
 		if ((domain = strchr(id, '@'))) {
 			*domain++ = '\0';
 			if ((p = strchr(domain, '|'))) {
 				*p++ = '\0';
 				how = p;
 			}
-			
+
 			for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
 				switch_hash_this(hi, NULL, NULL, &val);
 				profile = (vm_profile_t *) val;
-				total_new_messages =  total_saved_messages = 0;
+				total_new_messages = total_saved_messages = 0;
 				message_count(profile, id, domain, "inbox", &total_new_messages, &total_saved_messages,
 							  &total_new_urgent_messages, &total_saved_urgent_messages);
 			}
@@ -2285,19 +2214,19 @@
 			for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
 				switch_hash_this(hi, NULL, NULL, &val);
 				profile = (vm_profile_t *) val;
-				total_new_messages =  total_saved_messages = 0;
+				total_new_messages = total_saved_messages = 0;
 				message_count(profile, id, domain, "inbox", &total_new_messages, &total_saved_messages,
-					&total_new_urgent_messages, &total_saved_urgent_messages);
+							  &total_new_urgent_messages, &total_saved_urgent_messages);
 				if (total_new_messages || total_saved_messages) {
 					if (switch_event_create(&new_event, SWITCH_EVENT_MESSAGE_WAITING) == SWITCH_STATUS_SUCCESS) {
 						const char *yn = "no";
-						if (total_new_messages || total_new_urgent_messages ) {
+						if (total_new_messages || total_new_urgent_messages) {
 							yn = "yes";
 						}
 						switch_event_add_header(new_event, SWITCH_STACK_BOTTOM, "MWI-Messages-Waiting", "%s", yn);
 						switch_event_add_header(new_event, SWITCH_STACK_BOTTOM, "MWI-Message-Account", account);
-						switch_event_add_header(new_event, SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d (%d/%d)", 
-							total_new_messages, total_saved_messages, total_new_urgent_messages, total_saved_urgent_messages);
+						switch_event_add_header(new_event, SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d (%d/%d)",
+												total_new_messages, total_saved_messages, total_new_urgent_messages, total_saved_urgent_messages);
 						created++;
 					}
 				}
@@ -2383,8 +2312,8 @@
 	if (switch_file_open(&fd, argv[8], SWITCH_FOPEN_READ, SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE, holder->pool) == SWITCH_STATUS_SUCCESS) {
 		flen = switch_file_get_size(fd);
 		holder->stream->write_function(holder->stream, "Content-type: %s\n", mime_type);
-		holder->stream->write_function(holder->stream, "Content-length: %ld\n\n", (long)flen);
-		for(;;) {
+		holder->stream->write_function(holder->stream, "Content-length: %ld\n\n", (long) flen);
+		for (;;) {
 			switch_status_t status;
 
 			flen = sizeof(chunk);
@@ -2405,8 +2334,8 @@
 	char *sql;
 	struct holder holder;
 
-	sql = switch_mprintf("update voicemail_msgs set read_epoch=%ld where username='%s' and domain='%s' and file_path like '%%%s'", 
-		(long)switch_timestamp(NULL), user, domain, file);
+	sql = switch_mprintf("update voicemail_msgs set read_epoch=%ld where username='%s' and domain='%s' and file_path like '%%%s'",
+						 (long) switch_timestamp(NULL), user, domain, file);
 
 	vm_execute_sql(profile, sql, profile->mutex);
 	free(sql);
@@ -2444,9 +2373,8 @@
 	free(sql);
 
 	if (ref) {
-		stream->write_function(stream,"Content-type: text/html\n\n<h2>Message Deleted</h2>\n"
-			"<META http-equiv=\"refresh\" content=\"1;URL=%s\">",  ref);
-	} 
+		stream->write_function(stream, "Content-type: text/html\n\n<h2>Message Deleted</h2>\n" "<META http-equiv=\"refresh\" content=\"1;URL=%s\">", ref);
+	}
 }
 
 
@@ -2467,7 +2395,7 @@
 	const char *fmt = "%a, %e %b %Y %T %z";
 	char heard[80];
 	char title_b4[128] = "";
-	char title_aft[128*3] = "";
+	char title_aft[128 * 3] = "";
 
 	if (argc > 0) {
 		l_created = atol(argv[0]) * 1000000;
@@ -2495,11 +2423,7 @@
 	duration.day += duration.yr * 365;
 	duration.hr += duration.day * 24;
 
-	switch_snprintf(duration_str, sizeof(duration_str), "%.2u:%.2u:%.2u", 
-		duration.hr,
-		duration.min,
-		duration.sec
-		);
+	switch_snprintf(duration_str, sizeof(duration_str), "%.2u:%.2u:%.2u", duration.hr, duration.min, duration.sec);
 
 	if (l_created) {
 		switch_time_exp_lt(&tm, l_created);
@@ -2517,25 +2441,22 @@
 	get = switch_mprintf("http://%s:%s%s/get/%s", holder->host, holder->port, holder->uri, fname);
 	del = switch_mprintf("http://%s:%s%s/del/%s", holder->host, holder->port, holder->uri, fname);
 
-	holder->stream->write_function(holder->stream, "<font face=tahoma><div class=title><b>Message from %s %s</b></div><hr noshade size=1>\n", 
-		argv[5], argv[6]);
-	holder->stream->write_function(holder->stream, "Priority: %s<br>\n"
-		"Created: %s<br>\n"
-		"Last Heard: %s<br>\n"
-		"Duration: %s<br>\n",
-		//"<a href=%s>Delete This Message</a><br><hr noshade size=1>", 
-		strcmp(argv[10], URGENT_FLAG_STRING) ? "normal" : "urgent", create_date, heard, duration_str);
+	holder->stream->write_function(holder->stream, "<font face=tahoma><div class=title><b>Message from %s %s</b></div><hr noshade size=1>\n",
+								   argv[5], argv[6]);
+	holder->stream->write_function(holder->stream, "Priority: %s<br>\n" "Created: %s<br>\n" "Last Heard: %s<br>\n" "Duration: %s<br>\n",
+								   //"<a href=%s>Delete This Message</a><br><hr noshade size=1>", 
+								   strcmp(argv[10], URGENT_FLAG_STRING) ? "normal" : "urgent", create_date, heard, duration_str);
 
 	switch_snprintf(title_b4, sizeof(title_b4), "%s <%s> %s", argv[5], argv[6], rss_date);
 	switch_url_encode(title_b4, title_aft, sizeof(title_aft));
 
 	holder->stream->write_function(holder->stream,
-		"<br><object width=550 height=15 \n"
-		"type=\"application/x-shockwave-flash\" \n"
-		"data=\"http://%s:%s/pub/slim.swf?song_url=%s&player_title=%s\">\n"
-		"<param name=movie value=\"http://%s:%s/pub/slim.swf?song_url=%s&player_title=%s\"></object><br><br>\n"
-		"[<a href=%s>delete</a>] [<a href=%s>download</a>] [<a href=tel:%s>call</a>] <br><br><br></font>\n",
-		holder->host, holder->port, get, title_aft, holder->host, holder->port, get, title_aft, del, get, argv[6]);
+								   "<br><object width=550 height=15 \n"
+								   "type=\"application/x-shockwave-flash\" \n"
+								   "data=\"http://%s:%s/pub/slim.swf?song_url=%s&player_title=%s\">\n"
+								   "<param name=movie value=\"http://%s:%s/pub/slim.swf?song_url=%s&player_title=%s\"></object><br><br>\n"
+								   "[<a href=%s>delete</a>] [<a href=%s>download</a>] [<a href=tel:%s>call</a>] <br><br><br></font>\n",
+								   holder->host, holder->port, get, title_aft, holder->host, holder->port, get, title_aft, del, get, argv[6]);
 
 	free(get);
 	free(del);
@@ -2582,11 +2503,7 @@
 	duration.day += duration.yr * 365;
 	duration.hr += duration.day * 24;
 
-	switch_snprintf(duration_str, sizeof(duration_str), "%.2u:%.2u:%.2u", 
-		duration.hr,
-		duration.min,
-		duration.sec
-		);
+	switch_snprintf(duration_str, sizeof(duration_str), "%.2u:%.2u:%.2u", duration.hr, duration.min, duration.sec);
 
 	if (l_created) {
 		switch_time_exp_lt(&tm, l_created);
@@ -2622,10 +2539,9 @@
 	switch_xml_set_txt_d(x_link, del);
 
 	tmp = switch_mprintf("<![CDATA[Priority: %s<br>"
-		"Last Heard: %s<br>Duration: %s<br>"
-		"<a href=%s>Delete This Message</a><br>"
-		"]]>", 
-		strcmp(argv[10], URGENT_FLAG_STRING) ? "normal" : "urgent", heard, duration_str, del);
+						 "Last Heard: %s<br>Duration: %s<br>"
+						 "<a href=%s>Delete This Message</a><br>"
+						 "]]>", strcmp(argv[10], URGENT_FLAG_STRING) ? "normal" : "urgent", heard, duration_str, del);
 
 	switch_xml_set_txt_d(x_tmp, tmp);
 	free(tmp);
@@ -2740,7 +2656,7 @@
 	holder.uri = uri;
 
 	if (profile->web_head) {
-		stream->raw_write_function(stream, (uint8_t *)profile->web_head, strlen(profile->web_head));
+		stream->raw_write_function(stream, (uint8_t *) profile->web_head, strlen(profile->web_head));
 	}
 
 	cbt.buf = buf;
@@ -2758,7 +2674,7 @@
 	stream->write_function(stream, "%d message%s<br>", ttl, ttl == 1 ? "" : "s");
 
 	if (profile->web_tail) {
-		stream->raw_write_function(stream, (uint8_t *)profile->web_tail, strlen(profile->web_tail));
+		stream->raw_write_function(stream, (uint8_t *) profile->web_tail, strlen(profile->web_tail));
 	}
 }
 
@@ -2840,9 +2756,9 @@
 
 	if (path_info) {
 		if (!strncasecmp(path_info, "get/", 4)) {
-			do_play(profile, user, domain, path_info + 4, stream);        
+			do_play(profile, user, domain, path_info + 4, stream);
 		} else if (!strncasecmp(path_info, "del/", 4)) {
-			do_del(profile, user, domain, path_info + 4, stream);        
+			do_del(profile, user, domain, path_info + 4, stream);
 		} else if (!strncasecmp(path_info, "web", 3)) {
 			do_web(profile, user, domain, host, port, uri, stream);
 		}
@@ -2854,7 +2770,7 @@
 
 	goto done;
 
-error:
+  error:
 	if (host) {
 		if (!ct) {
 			stream->write_function(stream, "Content-type: text/html\n\n<h2>");
@@ -2862,7 +2778,7 @@
 	}
 	stream->write_function(stream, "Error: %s\n", VOICEMAIL_SYNTAX);
 
-done:
+  done:
 	switch_safe_free(mydata);
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -2883,13 +2799,13 @@
 
 	if (switch_event_bind((char *) modname, SWITCH_EVENT_MESSAGE_QUERY, SWITCH_EVENT_SUBCLASS_ANY, message_query_handler, NULL)
 		!= SWITCH_STATUS_SUCCESS) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
-			return SWITCH_STATUS_GENERR;
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
+		return SWITCH_STATUS_GENERR;
 	}
 
 	SWITCH_ADD_API(commands_api_interface, "voicemail", "voicemail", voicemail_api_function, VOICEMAIL_SYNTAX);
 	SWITCH_ADD_API(commands_api_interface, "vm_boxcount", "vm_boxcount", boxcount_api_function, BOXCOUNT_SYNTAX);
-	
+
 	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_NOUNLOAD;
 }

Modified: freeswitch/trunk/src/mod/asr_tts/mod_cepstral/mod_cepstral.c
==============================================================================
--- freeswitch/trunk/src/mod/asr_tts/mod_cepstral/mod_cepstral.c	(original)
+++ freeswitch/trunk/src/mod/asr_tts/mod_cepstral/mod_cepstral.c	Tue May 27 00:54:52 2008
@@ -257,7 +257,7 @@
 	swift_port_stop(cepstral->port, SWIFT_ASYNC_ANY, SWIFT_EVENT_NOW);
 }
 
-static switch_status_t cepstral_speech_read_tts(switch_speech_handle_t *sh, void *data, size_t *datalen, uint32_t * rate, switch_speech_flag_t *flags)
+static switch_status_t cepstral_speech_read_tts(switch_speech_handle_t *sh, void *data, size_t *datalen, uint32_t *rate, switch_speech_flag_t *flags)
 {
 	cepstral_t *cepstral;
 	size_t desired = *datalen;

Modified: freeswitch/trunk/src/mod/asr_tts/mod_lumenvox/mod_lumenvox.cpp
==============================================================================
--- freeswitch/trunk/src/mod/asr_tts/mod_lumenvox/mod_lumenvox.cpp	(original)
+++ freeswitch/trunk/src/mod/asr_tts/mod_lumenvox/mod_lumenvox.cpp	Tue May 27 00:54:52 2008
@@ -56,7 +56,7 @@
 	switch_mutex_t *flag_mutex;
 } lumenvox_t;
 
-static void log_callback(const char* message, void* userdata)
+static void log_callback(const char *message, void *userdata)
 {
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s\n", message);
 }
@@ -72,50 +72,47 @@
 	"BEEP"
 };
 
-std::ostream& operator << (std::ostream& os ,const LVSemanticData& Data)
+std::ostream & operator <<(std::ostream & os, const LVSemanticData & Data)
 {
 	int i;
 	LVSemanticObject Obj;
-	switch (Data.Type())
-		{
-		case SI_TYPE_BOOL:
-			os << Data.GetBool();
-			break;
-		case SI_TYPE_INT:
-			os << Data.GetInt();
-			break;
-		case SI_TYPE_DOUBLE:
-			os << Data.GetDouble();
-			break;
-		case SI_TYPE_STRING:
-			os << Data.GetString();
-			break;
-		case SI_TYPE_OBJECT:
-			Obj = Data.GetSemanticObject();
-			for (i = 0; i < Obj.NumberOfProperties(); ++i)
-				{
-					os << "<" << Obj.PropertyName(i) << ">";
-					os << Obj.PropertyValue(i);
-					os << "</" << Obj.PropertyName(i) << ">";
-				}
-			break;
-		case SI_TYPE_ARRAY:
-			for (i = 0; i < Data.GetSemanticArray().Size(); ++i)
-				{
-					os << Data.GetArray().At(i);
-				}
-			break;
+	switch (Data.Type()) {
+	case SI_TYPE_BOOL:
+		os << Data.GetBool();
+		break;
+	case SI_TYPE_INT:
+		os << Data.GetInt();
+		break;
+	case SI_TYPE_DOUBLE:
+		os << Data.GetDouble();
+		break;
+	case SI_TYPE_STRING:
+		os << Data.GetString();
+		break;
+	case SI_TYPE_OBJECT:
+		Obj = Data.GetSemanticObject();
+		for (i = 0; i < Obj.NumberOfProperties(); ++i) {
+			os << "<" << Obj.PropertyName(i) << ">";
+			os << Obj.PropertyValue(i);
+			os << "</" << Obj.PropertyName(i) << ">";
+		}
+		break;
+	case SI_TYPE_ARRAY:
+		for (i = 0; i < Data.GetSemanticArray().Size(); ++i) {
+			os << Data.GetArray().At(i);
 		}
+		break;
+	}
 	return os;
 }
 
 //==============================================================================================
 // code to plug LVInterpretation into any standard stream
-std::ostream& operator << (std::ostream& os, const LVInterpretation& Interp)
+std::ostream & operator <<(std::ostream & os, const LVInterpretation & Interp)
 {
-	os << "<interpretation grammar=\""<<Interp.GrammarLabel()
-	   <<"\" score=\""<<Interp.Score()<<"\">";
-	os << "<result name=\""<<Interp.ResultName()<<"\">";
+	os << "<interpretation grammar=\"" << Interp.GrammarLabel()
+		<< "\" score=\"" << Interp.Score() << "\">";
+	os << "<result name=\"" << Interp.ResultName() << "\">";
 	os << Interp.ResultData();
 	os << "</result>";
 	os << "<input>";
@@ -126,30 +123,26 @@
 }
 
 
-static void state_change_callback(long new_state, unsigned long total_bytes,
-				   unsigned long recorded_bytes, void *user_data)
+static void state_change_callback(long new_state, unsigned long total_bytes, unsigned long recorded_bytes, void *user_data)
 {
 	lumenvox_t *lv = (lumenvox_t *) user_data;
-	
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "State: [%s] total bytes: [%ld] recorded bytes: [%ld]\n",
-					  state_names[new_state],
-					  total_bytes,
-					  recorded_bytes);
-
-	switch (new_state)
-		{
-		case STREAM_STATUS_READY:
-			break;
-		case STREAM_STATUS_STOPPED:
-			switch_clear_flag_locked(lv, LVFLAG_READY);
-			break;
-		case STREAM_STATUS_END_SPEECH:
-			switch_set_flag_locked(lv, LVFLAG_HAS_TEXT);
-			break;
-		case STREAM_STATUS_BARGE_IN:
-			switch_set_flag_locked(lv, LVFLAG_BARGE);
-			break;
-		}
+					  state_names[new_state], total_bytes, recorded_bytes);
+
+	switch (new_state) {
+	case STREAM_STATUS_READY:
+		break;
+	case STREAM_STATUS_STOPPED:
+		switch_clear_flag_locked(lv, LVFLAG_READY);
+		break;
+	case STREAM_STATUS_END_SPEECH:
+		switch_set_flag_locked(lv, LVFLAG_HAS_TEXT);
+		break;
+	case STREAM_STATUS_BARGE_IN:
+		switch_set_flag_locked(lv, LVFLAG_BARGE);
+		break;
+	}
 }
 
 static switch_status_t lumenvox_asr_pause(switch_asr_handle_t *ah)
@@ -177,20 +170,20 @@
 			lv->port.ClosePort();
 			return SWITCH_STATUS_GENERR;
 		}
-		switch_set_flag_locked(lv, LVFLAG_READY);		
+		switch_set_flag_locked(lv, LVFLAG_READY);
 		return SWITCH_STATUS_SUCCESS;
 	}
-	
+
 	return SWITCH_STATUS_GENERR;
 }
 
 /*! function to open the asr interface */
-static switch_status_t lumenvox_asr_open(switch_asr_handle_t *ah, char *codec, int rate, char *dest, switch_asr_flag_t *flags) 
+static switch_status_t lumenvox_asr_open(switch_asr_handle_t *ah, char *codec, int rate, char *dest, switch_asr_flag_t *flags)
 {
-	
+
 	lumenvox_t *lv;
 	int error_code;
-	
+
 	if (!(lv = (lumenvox_t *) switch_core_alloc(ah->memory_pool, sizeof(*lv)))) {
 		return SWITCH_STATUS_MEMERR;
 	}
@@ -199,7 +192,7 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Rate: Pick 8000 or 16000\n");
 		return SWITCH_STATUS_FALSE;
 	}
-	
+
 	if (!strcasecmp(codec, "PCMU")) {
 		switch (rate) {
 		case 8000:
@@ -238,36 +231,35 @@
 	if (!lv->sound_format) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot negotiate sound format.\n");
 		return SWITCH_STATUS_FALSE;
-	}	
+	}
 
 	ah->rate = rate;
 	ah->codec = switch_core_strdup(ah->memory_pool, codec);
-	
+
 	lv->port.OpenPort(log_callback, NULL, 5);
 	error_code = lv->port.GetOpenPortStatus();
-	
-	switch(error_code)
-		{
-		case LV_FAILURE:
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Licenses Exceeded!\n");
-			return SWITCH_STATUS_GENERR;
-		case LV_OPEN_PORT_FAILED__PRIMARY_SERVER_NOT_RESPONDING:
-		case LV_NO_SERVER_RESPONDING:
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SRE Server Unavailable!\n");
-			return SWITCH_STATUS_GENERR;
-		case LV_SUCCESS:
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Port Opened %d %dkhz.\n", lv->sound_format, rate);
-			break;
-		}
+
+	switch (error_code) {
+	case LV_FAILURE:
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Licenses Exceeded!\n");
+		return SWITCH_STATUS_GENERR;
+	case LV_OPEN_PORT_FAILED__PRIMARY_SERVER_NOT_RESPONDING:
+	case LV_NO_SERVER_RESPONDING:
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SRE Server Unavailable!\n");
+		return SWITCH_STATUS_GENERR;
+	case LV_SUCCESS:
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Port Opened %d %dkhz.\n", lv->sound_format, rate);
+		break;
+	}
 
 
 	// turn on sound and response file logging
 	/*
-	  int save_sound_files = 1;
-	  lv->port.SetPropertyEx(PROP_EX_SAVE_SOUND_FILES,
-						   PROP_EX_VALUE_TYPE_INT_PTR,
-						   &save_sound_files);
-	*/
+	   int save_sound_files = 1;
+	   lv->port.SetPropertyEx(PROP_EX_SAVE_SOUND_FILES,
+	   PROP_EX_VALUE_TYPE_INT_PTR,
+	   &save_sound_files);
+	 */
 	lv->channel = 1;
 	lv->flags = *flags;
 	lv->port.StreamSetParameter(STREAM_PARM_DETECT_BARGE_IN, 1);
@@ -275,9 +267,9 @@
 	lv->port.StreamSetParameter(STREAM_PARM_AUTO_DECODE, 1);
 	lv->port.StreamSetParameter(STREAM_PARM_DECODE_FLAGS, LV_DECODE_SEMANTIC_INTERPRETATION);
 	lv->port.StreamSetParameter(STREAM_PARM_VOICE_CHANNEL, lv->channel);
-	lv->port.StreamSetParameter(STREAM_PARM_GRAMMAR_SET, (long unsigned int) LV_ACTIVE_GRAMMAR_SET); 
+	lv->port.StreamSetParameter(STREAM_PARM_GRAMMAR_SET, (long unsigned int) LV_ACTIVE_GRAMMAR_SET);
+
 
-	
 	lv->port.StreamSetStateChangeCallBack(state_change_callback, lv);
 	lv->port.StreamSetParameter(STREAM_PARM_SOUND_FORMAT, lv->sound_format);
 
@@ -292,7 +284,7 @@
 		lv->port.ClosePort();
 		return SWITCH_STATUS_GENERR;
 	}
-	
+
 	ah->private_info = lv;
 
 	return SWITCH_STATUS_SUCCESS;
@@ -347,13 +339,13 @@
 {
 
 	lumenvox_t *lv = (lumenvox_t *) ah->private_info;
-	
+
 	if (!switch_test_flag(lv, LVFLAG_HAS_TEXT) && switch_test_flag(lv, LVFLAG_READY)) {
 		if (lv->port.StreamSendData(data, len)) {
-			return SWITCH_STATUS_FALSE;		
+			return SWITCH_STATUS_FALSE;
 		}
 	}
-	
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -384,21 +376,21 @@
 
 		lv->port.StreamStop();
 		code = lv->port.WaitForEngineToIdle(3000, lv->channel);
-	
+
 		if (code == LV_TIME_OUT) {
 			return SWITCH_STATUS_FALSE;
 		}
-		
+
 		numInterp = lv->port.GetNumberOfInterpretations(lv->channel);
-		
+
 		for (int t = 0; t < numInterp; ++t) {
 			ss << lv->port.GetInterpretation(lv->channel, t);
 		}
-		
-		*xmlstr = strdup((char *)ss.str().c_str());
+
+		*xmlstr = strdup((char *) ss.str().c_str());
 		switch_clear_flag_locked(lv, LVFLAG_HAS_TEXT);
 
-		
+
 		if (switch_test_flag(lv, SWITCH_ASR_FLAG_AUTO_RESUME)) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Auto Resuming\n");
 			switch_set_flag_locked(lv, LVFLAG_READY);
@@ -410,21 +402,21 @@
 
 		ret = SWITCH_STATUS_SUCCESS;
 	}
-	
+
 	return ret;
 }
 
 static const switch_asr_interface_t lumenvox_asr_interface = {
-	/*.interface_name*/			"lumenvox",
-	/*.asr_open*/				lumenvox_asr_open,
-	/*.asr_load_grammar*/		lumenvox_asr_load_grammar,
-	/*.asr_unload_grammar*/		lumenvox_asr_unload_grammar,
-	/*.asr_close*/				lumenvox_asr_close,
-	/*.asr_feed*/				lumenvox_asr_feed,
-	/*.asr_resume*/				lumenvox_asr_resume,
-	/*.asr_pause*/				lumenvox_asr_pause,
-	/*.asr_check_results*/		lumenvox_asr_check_results,
-	/*.asr_get_results*/		lumenvox_asr_get_results
+	/*.interface_name */ "lumenvox",
+	/*.asr_open */ lumenvox_asr_open,
+	/*.asr_load_grammar */ lumenvox_asr_load_grammar,
+	/*.asr_unload_grammar */ lumenvox_asr_unload_grammar,
+	/*.asr_close */ lumenvox_asr_close,
+	/*.asr_feed */ lumenvox_asr_feed,
+	/*.asr_resume */ lumenvox_asr_resume,
+	/*.asr_pause */ lumenvox_asr_pause,
+	/*.asr_check_results */ lumenvox_asr_check_results,
+	/*.asr_get_results */ lumenvox_asr_get_results
 };
 
 static const switch_loadable_module_interface_t lumenvox_module_interface = {
@@ -447,7 +439,7 @@
 {
 	LVSpeechPort::RegisterAppLogMsg(log_callback, NULL, 5);
 	//LVSpeechPort::SetClientPropertyEx(PROP_EX_SRE_SERVERS, PROP_EX_VALUE_TYPE_STRING, (void *)"127.0.0.1");
-	
+
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = &lumenvox_module_interface;
 

Modified: freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c
==============================================================================
--- freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c	(original)
+++ freeswitch/trunk/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c	Tue May 27 00:54:52 2008
@@ -66,40 +66,39 @@
 #include "mrcp_synthesizer.h"
 #include "mrcp_generic_header.h"
 
-	
+
 SWITCH_MODULE_LOAD_FUNCTION(mod_openmrcp_load);
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_openmrcp_shutdown);
-SWITCH_MODULE_DEFINITION(mod_openmrcp, mod_openmrcp_load, 
-						 mod_openmrcp_shutdown, NULL);
+SWITCH_MODULE_DEFINITION(mod_openmrcp, mod_openmrcp_load, mod_openmrcp_shutdown, NULL);
 
 typedef struct {
-	char                      *name;
+	char *name;
 	openmrcp_client_options_t *mrcp_options;
-	mrcp_client_t             *mrcp_client;
-	mrcp_client_context_t     *mrcp_context;
+	mrcp_client_t *mrcp_client;
+	mrcp_client_context_t *mrcp_context;
 } openmrcp_profile_t;
 
 typedef struct {
-	openmrcp_profile_t    *profile;
-	mrcp_session_t        *client_session;
+	openmrcp_profile_t *profile;
+	mrcp_session_t *client_session;
 	mrcp_client_channel_t *control_channel;
-	mrcp_audio_channel_t  *audio_channel;
-	mrcp_message_t        *mrcp_message_last_rcvd;
-	apr_pool_t            *pool;
-	switch_speech_flag_t   flags;
-	switch_mutex_t        *flag_mutex;
-	switch_thread_cond_t  *wait_object;
+	mrcp_audio_channel_t *audio_channel;
+	mrcp_message_t *mrcp_message_last_rcvd;
+	apr_pool_t *pool;
+	switch_speech_flag_t flags;
+	switch_mutex_t *flag_mutex;
+	switch_thread_cond_t *wait_object;
 } openmrcp_session_t;
 
 typedef enum {
-	FLAG_HAS_MESSAGE =    (1 << 0), 
-	FLAG_FEED_STARTED =   (1 << 1), 
-	FLAG_TERMINATING =    (1 << 2)
+	FLAG_HAS_MESSAGE = (1 << 0),
+	FLAG_FEED_STARTED = (1 << 1),
+	FLAG_TERMINATING = (1 << 2)
 } mrcp_flag_t;
 
 typedef struct {
 	switch_memory_pool_t *pool;
-	switch_hash_t        *profile_hash;
+	switch_hash_t *profile_hash;
 	char *asr_profile_name;
 	char *tts_profile_name;
 	//openmrcp_profile_t   *asr_profile;
@@ -109,7 +108,7 @@
 static openmrcp_module_t openmrcp_module;
 static switch_status_t openmrcp_profile_run(openmrcp_profile_t *profile);
 
-static openmrcp_session_t* openmrcp_session_create(openmrcp_profile_t *profile)
+static openmrcp_session_t *openmrcp_session_create(openmrcp_profile_t *profile)
 {
 	openmrcp_session_t *openmrcp_session;
 	apr_pool_t *session_pool;
@@ -172,14 +171,14 @@
 
 	if (switch_test_flag(openmrcp_session, FLAG_TERMINATING)) {
 		openmrcp_session_destroy(openmrcp_session);
-	}
-	else {
+	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "abnormal session terminate\n");
 	}
 	return MRCP_STATUS_SUCCESS;
 }
 
-static mrcp_status_t openmrcp_on_channel_add(mrcp_client_context_t *context, mrcp_session_t *session, mrcp_client_channel_t *control_channel, mrcp_audio_channel_t *audio_channel)
+static mrcp_status_t openmrcp_on_channel_add(mrcp_client_context_t *context, mrcp_session_t *session, mrcp_client_channel_t *control_channel,
+											 mrcp_audio_channel_t *audio_channel)
 {
 	openmrcp_session_t *openmrcp_session = mrcp_client_context_session_object_get(session);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "on_channel_add called\n");
@@ -242,8 +241,9 @@
 	apr_finfo_t finfo;
 	char *buf1;
 	apr_size_t bytes2read = 0;
-	
-	mrcp_message_t *mrcp_message = mrcp_client_context_message_get(context, asr_session->client_session, asr_session->control_channel, RECOGNIZER_RECOGNIZE);
+
+	mrcp_message_t *mrcp_message =
+		mrcp_client_context_message_get(context, asr_session->client_session, asr_session->control_channel, RECOGNIZER_RECOGNIZE);
 
 	if (!mrcp_message) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not create mrcp msg\n");
@@ -257,9 +257,9 @@
 		return -1;
 	}
 	rv = apr_file_info_get(&finfo, APR_FINFO_NORM, fp);
-	
-	buf1 = apr_palloc(mp, (apr_size_t)finfo.size + 1);
-	bytes2read = (apr_size_t)finfo.size;
+
+	buf1 = apr_palloc(mp, (apr_size_t) finfo.size + 1);
+	bytes2read = (apr_size_t) finfo.size;
 	rv = apr_file_read(fp, buf1, &bytes2read);
 	buf1[bytes2read] = '\0';
 
@@ -286,27 +286,23 @@
  * This code expects certain one-time initialization of the openmrcp client
  * engine/systeme to have already taken place.function to open the asr interface 
  */
-static switch_status_t openmrcp_asr_open(switch_asr_handle_t *ah,
-										 const char *codec,
-										 int rate,
-										 const char *dest,
-										 switch_asr_flag_t *flags) 
+static switch_status_t openmrcp_asr_open(switch_asr_handle_t *ah, const char *codec, int rate, const char *dest, switch_asr_flag_t *flags)
 {
 	openmrcp_session_t *asr_session;
 	mrcp_client_channel_t *asr_channel;
 	char *profile_name = openmrcp_module.asr_profile_name;
-	openmrcp_profile_t   *asr_profile = NULL;
+	openmrcp_profile_t *asr_profile = NULL;
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "asr_open called, codec: %s, rate: %d\n", codec, rate);
 
 	if (strcmp(codec, "L16")) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Sorry, only L16 codec supported\n");
-		return SWITCH_STATUS_GENERR;		
+		return SWITCH_STATUS_GENERR;
 	}
 	if (rate != 8000) {
 		// TODO: look into supporting other sample rates
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Sorry, only 8kz supported\n");
-		return SWITCH_STATUS_GENERR;		
+		return SWITCH_STATUS_GENERR;
 	}
 
 	if (!switch_strlen_zero(ah->param)) {
@@ -315,7 +311,7 @@
 
 	if (!(asr_profile = switch_core_hash_find(openmrcp_module.profile_hash, profile_name))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot locate profile %s\n", profile_name);
-		return SWITCH_STATUS_GENERR;		
+		return SWITCH_STATUS_GENERR;
 	}
 
 	/* create session */
@@ -336,7 +332,7 @@
 
 	switch_mutex_lock(asr_session->flag_mutex);
 	mrcp_client_context_channel_add(asr_session->profile->mrcp_context, asr_session->client_session, asr_channel, NULL);
-	if (switch_thread_cond_timedwait(asr_session->wait_object, asr_session->flag_mutex, 5000*1000) != APR_SUCCESS) {
+	if (switch_thread_cond_timedwait(asr_session->wait_object, asr_session->flag_mutex, 5000 * 1000) != APR_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No response from client stack\n");
 	}
 	switch_mutex_unlock(asr_session->flag_mutex);
@@ -358,15 +354,15 @@
 	
 	    TODO: - how does DEFINE-GRAMMAR fit into the picture here?  (if at all) 
 	*/
-	
+
 	openmrcp_session_t *asr_session = (openmrcp_session_t *) ah->private_info;
 	mrcp_client_context_t *context = asr_session->profile->mrcp_context;
-		
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Loading grammar\n");
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Start Recognizer\n");
 	openmrcp_recog_start(context, asr_session, path);
-	
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Finished loading grammar\n");
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -387,22 +383,22 @@
 	/* sampling rate and frame size should be retrieved from audio sink */
 	media_frame.codec_frame.size = 160;
 	media_frame.codec_frame.buffer = data;
-	while(len >= media_frame.codec_frame.size) {
+	while (len >= media_frame.codec_frame.size) {
 		if (!audio_sink) {
 			/*!
-			  If there is no audio_sink established yet, discard the audio and
-			  return SUCCESS.  returning anything other than success causes freeswitch
-			  to abort the call and tear down the channel.  One reason there might
-			  not be an audio sink is that the openmrcp client lib is still in the startup
-			  process.  
-			*/
+			   If there is no audio_sink established yet, discard the audio and
+			   return SUCCESS.  returning anything other than success causes freeswitch
+			   to abort the call and tear down the channel.  One reason there might
+			   not be an audio sink is that the openmrcp client lib is still in the startup
+			   process.  
+			 */
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "!audio_sink\n");
-			return SWITCH_STATUS_SUCCESS;  
+			return SWITCH_STATUS_SUCCESS;
 		}
 		audio_sink->method_set->write_frame(audio_sink, &media_frame);
-		
-		len -= (unsigned int)media_frame.codec_frame.size;
-		media_frame.codec_frame.buffer = (char*)media_frame.codec_frame.buffer + media_frame.codec_frame.size;
+
+		len -= (unsigned int) media_frame.codec_frame.size;
+		media_frame.codec_frame.buffer = (char *) media_frame.codec_frame.buffer + media_frame.codec_frame.size;
 	}
 	if (len > 0) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "None frame alligned data len [%d]\n", len);
@@ -452,9 +448,9 @@
 
 	// terminate client session
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Going to TERMINATE SESSION\n");
-	switch_set_flag_locked(asr_session, FLAG_TERMINATING);  
+	switch_set_flag_locked(asr_session, FLAG_TERMINATING);
 	mrcp_client_context_session_terminate(context, asr_session->client_session);
-	
+
 	switch_set_flag(ah, SWITCH_ASR_FLAG_CLOSED);
 
 	return SWITCH_STATUS_SUCCESS;
@@ -470,7 +466,7 @@
 static switch_status_t openmrcp_asr_check_results(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
 {
 	openmrcp_session_t *asr_session = (openmrcp_session_t *) ah->private_info;
-	
+
 	switch_status_t rv = (switch_test_flag(asr_session, FLAG_HAS_MESSAGE)) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
 
 	return rv;
@@ -491,49 +487,44 @@
 	switch_clear_flag_locked(asr_session, FLAG_HAS_MESSAGE);
 
 	if (message->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) {
-		if (message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS && 
-			message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS_WITH_IGNORE) {
+		if (message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS && message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS_WITH_IGNORE) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "error code received [%d]\n", message->start_line.status_code);
 			ret = SWITCH_STATUS_FALSE;
 		}
-	} 
-	else if (message->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) {
+	} else if (message->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) {
 		if (message->start_line.method_id == RECOGNIZER_RECOGNITION_COMPLETE) {
 			/*! 
 			   we have to extract the XML but stripping off the <?xml version="1.0"?>
 			   header.  the body looks like:
-			
+
 			   Completion-Cause:001 no-match
 			   Content-Type: application/nlsml+xml
 			   Content-Length: 260
-			 
-			  <?xml version="1.0"?>
-			  <result xmlns="http://www.ietf.org/xml/ns/mrcpv2" xmlns:ex="http://www.example.com/example" score="100" grammar="session:request1 at form-level.store">
-				<interpretation>             <input mode="speech">open a</input>
-				</interpretation>
-			  </result>
-			*/
+
+			   <?xml version="1.0"?>
+			   <result xmlns="http://www.ietf.org/xml/ns/mrcpv2" xmlns:ex="http://www.example.com/example" score="100" grammar="session:request1 at form-level.store">
+			   <interpretation>             <input mode="speech">open a</input>
+			   </interpretation>
+			   </result>
+			 */
 
 			if (message->body) {
-				char *marker = "?>";  // FIXME -- lame and brittle way of doing this.  use regex or better.
+				char *marker = "?>";	// FIXME -- lame and brittle way of doing this.  use regex or better.
 				char *position = strstr(message->body, marker);
 				if (!position) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Bad result received from mrcp server: %s", message->body);
 					ret = SWITCH_STATUS_FALSE;
-				}
-				else {
+				} else {
 					position += strlen(marker);
 					*xmlstr = strdup(position);
 				}
-			}
-			else {
+			} else {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No result received from mrcp server\n");
 				ret = SWITCH_STATUS_FALSE;
 			}
 
-			ret = SWITCH_STATUS_SUCCESS;	
-		} 
-		else if (message->start_line.method_id == RECOGNIZER_START_OF_INPUT) {
+			ret = SWITCH_STATUS_SUCCESS;
+		} else if (message->start_line.method_id == RECOGNIZER_START_OF_INPUT) {
 			ret = SWITCH_STATUS_BREAK;
 		}
 	}
@@ -546,23 +537,17 @@
 	mrcp_generic_header_t *generic_header;
 	mrcp_message_t *mrcp_message;
 	mrcp_status_t status = MRCP_STATUS_FAILURE;
-	
+
 	char *text2speak;
-	const char v2_xml_head[] = 
-		"<?xml version=\"1.0\"?>\r\n"
-		"<speak>\r\n"
-		"<paragraph>\r\n"
-		"    <sentence><break time=\"1000ms\"/>";
+	const char v2_xml_head[] = "<?xml version=\"1.0\"?>\r\n" "<speak>\r\n" "<paragraph>\r\n" "    <sentence><break time=\"1000ms\"/>";
 
-	const char v2_xml_tail[] = "<break time=\"1000ms\"/></sentence>\r\n"
-		"</paragraph>\r\n"
-		"</speak>\r\n";
+	const char v2_xml_tail[] = "<break time=\"1000ms\"/></sentence>\r\n" "</paragraph>\r\n" "</speak>\r\n";
 
-    const char v1_xml_head[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
-        "<speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\">\n<break time=\"1000ms\"/>";
+	const char v1_xml_head[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+		"<speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\">\n<break time=\"1000ms\"/>";
 
 
-    const char v1_xml_tail[] = "<break time=\"1000ms\"/>\n</speak>\n";
+	const char v1_xml_tail[] = "<break time=\"1000ms\"/>\n</speak>\n";
 
 	const char *xml_head, *xml_tail;
 
@@ -592,7 +577,7 @@
 
 	status = mrcp_client_context_channel_modify(context, tts_session->client_session, mrcp_message);
 
- end:
+  end:
 
 	return status;
 
@@ -609,12 +594,12 @@
 }
 
 
-static switch_status_t openmrcp_tts_open(switch_speech_handle_t *sh, const char *voice_name, int rate, switch_speech_flag_t *flags) 
+static switch_status_t openmrcp_tts_open(switch_speech_handle_t *sh, const char *voice_name, int rate, switch_speech_flag_t *flags)
 {
 	openmrcp_session_t *tts_session;
 	mrcp_client_channel_t *tts_channel;
 	char *profile_name = openmrcp_module.tts_profile_name;
-	openmrcp_profile_t   *tts_profile = NULL;
+	openmrcp_profile_t *tts_profile = NULL;
 
 	if (!switch_strlen_zero(sh->param)) {
 		profile_name = sh->param;
@@ -622,7 +607,7 @@
 
 	if (!(tts_profile = switch_core_hash_find(openmrcp_module.profile_hash, profile_name))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot locate profile %s\n", profile_name);
-		return SWITCH_STATUS_GENERR;		
+		return SWITCH_STATUS_GENERR;
 	}
 
 	/* create session */
@@ -642,7 +627,7 @@
 	}
 	switch_mutex_lock(tts_session->flag_mutex);
 	mrcp_client_context_channel_add(tts_session->profile->mrcp_context, tts_session->client_session, tts_channel, NULL);
-	if (switch_thread_cond_timedwait(tts_session->wait_object, tts_session->flag_mutex, 5000*1000) != APR_SUCCESS) {
+	if (switch_thread_cond_timedwait(tts_session->wait_object, tts_session->flag_mutex, 5000 * 1000) != APR_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No response from client stack\n");
 	}
 	switch_mutex_unlock(tts_session->flag_mutex);
@@ -665,7 +650,7 @@
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "terminate tts_session\n");
 	switch_set_flag_locked(tts_session, FLAG_TERMINATING);
 	mrcp_client_context_session_terminate(context, tts_session->client_session);
-	return SWITCH_STATUS_SUCCESS;	
+	return SWITCH_STATUS_SUCCESS;
 }
 
 static switch_status_t openmrcp_feed_tts(switch_speech_handle_t *sh, char *text, switch_speech_flag_t *flags)
@@ -677,11 +662,11 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "no synthesizer channel too feed tts\n");
 		return SWITCH_STATUS_FALSE;
 	}
-	
-	synth_speak(context, tts_session, text); 
-	
+
+	synth_speak(context, tts_session, text);
+
 	switch_clear_flag(tts_session, FLAG_FEED_STARTED);
-	return SWITCH_STATUS_SUCCESS;	
+	return SWITCH_STATUS_SUCCESS;
 }
 
 /**
@@ -693,7 +678,7 @@
 static switch_status_t openmrcp_read_tts(switch_speech_handle_t *sh, void *data, size_t *datalen, uint32_t *rate, switch_speech_flag_t *flags)
 {
 	openmrcp_session_t *tts_session = (openmrcp_session_t *) sh->private_info;
-	size_t return_len=0;
+	size_t return_len = 0;
 	media_frame_t media_frame;
 	audio_source_t *audio_source;
 
@@ -703,13 +688,11 @@
 		switch_clear_flag_locked(tts_session, FLAG_HAS_MESSAGE);
 
 		if (message->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) {
-			if (message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS && 
-				message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS_WITH_IGNORE) {
+			if (message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS && message->start_line.status_code != MRCP_STATUS_CODE_SUCCESS_WITH_IGNORE) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "error code received [%d]\n", message->start_line.status_code);
 				return SWITCH_STATUS_BREAK;
 			}
-		} 
-		else if (message->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) {
+		} else if (message->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) {
 			if (message->start_line.method_id == SYNTHESIZER_SPEAK_COMPLETE) {
 				/* tell fs we are done */
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "FLAG_SPEAK_COMPLETE\n");
@@ -724,7 +707,7 @@
 	}
 
 	if (!switch_test_flag(tts_session, FLAG_FEED_STARTED)) {
-		switch_set_flag(tts_session, FLAG_FEED_STARTED);  // shouldn't this use set_flag_locked? -tl
+		switch_set_flag(tts_session, FLAG_FEED_STARTED);	// shouldn't this use set_flag_locked? -tl
 		if (audio_source->method_set->open) {
 			audio_source->method_set->open(audio_source);
 		}
@@ -733,8 +716,8 @@
 	/* sampling rate and frame size should be retrieved from audio source */
 	*rate = 8000;
 	media_frame.codec_frame.size = 160;
-	while(return_len < *datalen) {
-		media_frame.codec_frame.buffer = (char*)data + return_len;
+	while (return_len < *datalen) {
+		media_frame.codec_frame.buffer = (char *) data + return_len;
 		audio_source->method_set->read_frame(audio_source, &media_frame);
 		if (media_frame.type != MEDIA_FRAME_TYPE_AUDIO) {
 			memset(media_frame.codec_frame.buffer, 0, media_frame.codec_frame.size);
@@ -742,7 +725,7 @@
 		return_len += media_frame.codec_frame.size;
 	}
 	*datalen = return_len;
-	return SWITCH_STATUS_SUCCESS;	
+	return SWITCH_STATUS_SUCCESS;
 }
 
 
@@ -752,7 +735,7 @@
 	mrcp_client_context_t *context = tts_session->profile->mrcp_context;
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "flush_tts called\n");
-	synth_stop(context, tts_session); // TODO
+	synth_stop(context, tts_session);	// TODO
 }
 
 static void openmrcp_text_param_tts(switch_speech_handle_t *sh, char *param, const char *val)
@@ -797,8 +780,7 @@
 				apt_log_priority_set(atoi(val));
 			}
 		}
-	}
-	else {
+	} else {
 		goto error;
 	}
 	if ((profiles = switch_xml_child(cfg, "profiles"))) {
@@ -818,9 +800,8 @@
 				const char *val = switch_xml_attr_soft(param, "value");
 
 				if (!strcasecmp(var, "proto_version")) {
-					mrcp_options->proto_version =(mrcp_version_t) atoi(val);
-				}
-				else if (!strcasecmp(var, "client_ip")) {
+					mrcp_options->proto_version = (mrcp_version_t) atoi(val);
+				} else if (!strcasecmp(var, "client_ip")) {
 					mrcp_options->client_ip = switch_core_strdup(openmrcp_module.pool, val);
 				} else if (!strcasecmp(var, "server_ip")) {
 					mrcp_options->server_ip = switch_core_strdup(openmrcp_module.pool, val);
@@ -835,27 +816,24 @@
 				}
 			}
 			mrcp_profile->mrcp_options = mrcp_options;
-			
+
 			/* add profile */
 			if (!switch_core_hash_find(openmrcp_module.profile_hash, mrcp_profile->name)) {
 				if (openmrcp_profile_run(mrcp_profile) == SWITCH_STATUS_SUCCESS) {
 					switch_core_hash_insert(openmrcp_module.profile_hash, mrcp_profile->name, mrcp_profile);
 				}
-			}
-			else {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, 
-					"profile with the name [%s] already exists\n", mrcp_profile->name);
+			} else {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "profile with the name [%s] already exists\n", mrcp_profile->name);
 			}
 		}
-	}
-	else {
+	} else {
 		goto error;
 	}
 
 	switch_xml_free(xml);
 	return SWITCH_STATUS_SUCCESS;
 
- error:
+  error:
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to load module configuration\n");
 	switch_xml_free(xml);
 	return SWITCH_STATUS_TERM;
@@ -867,10 +845,10 @@
 	mrcp_client_event_handler_t *mrcp_event_handler;
 	mrcp_client_t *mrcp_client;
 	mrcp_client_context_t *mrcp_context;
-	
+
 	/*!
-	Perform one-time initialization of mrcp client library
-	*/
+	   Perform one-time initialization of mrcp client library
+	 */
 	mrcp_event_handler = switch_core_alloc(openmrcp_module.pool, sizeof(mrcp_client_event_handler_t));
 	mrcp_event_handler->on_session_initiate = openmrcp_on_session_initiate;
 	mrcp_event_handler->on_session_terminate = openmrcp_on_session_terminate;
@@ -902,7 +880,7 @@
 static switch_status_t openmrcp_init()
 {
 	/* one-time mrcp global initialization */
-	if(apr_pool_create(&openmrcp_module.pool,NULL) != APR_SUCCESS) {
+	if (apr_pool_create(&openmrcp_module.pool, NULL) != APR_SUCCESS) {
 		return SWITCH_STATUS_FALSE;
 	}
 
@@ -931,7 +909,7 @@
 		/* shutdown client engine */
 		openmrcp_client_shutdown(mrcp_profile->mrcp_client);
 		/* destroy client context */
-		mrcp_client_context_destroy(mrcp_profile->mrcp_context);		
+		mrcp_client_context_destroy(mrcp_profile->mrcp_context);
 	}
 	switch_core_hash_destroy(&openmrcp_module.profile_hash);
 	openmrcp_module.profile_hash = NULL;
@@ -973,7 +951,7 @@
 
 	/* initialize openmrcp */
 	if (openmrcp_init() != SWITCH_STATUS_SUCCESS) {
-		return SWITCH_STATUS_FALSE;		
+		return SWITCH_STATUS_FALSE;
 	}
 
 	/* indicate that the module should continue to be loaded */

Modified: freeswitch/trunk/src/mod/codecs/mod_amr/mod_amr.c
==============================================================================
--- freeswitch/trunk/src/mod/codecs/mod_amr/mod_amr.c	(original)
+++ freeswitch/trunk/src/mod/codecs/mod_amr/mod_amr.c	Tue May 27 00:54:52 2008
@@ -139,8 +139,8 @@
 
 	if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct amr_context))))) {
 		return SWITCH_STATUS_FALSE;
-	} else {	
-	
+	} else {
+
 		context->dtx_mode = AMR_DTX_ENABLED;
 		if (codec->fmtp_in) {
 			argc = switch_separate_string(codec->fmtp_in, ';', argv, (sizeof(argv) / sizeof(argv[0])));
@@ -207,7 +207,8 @@
 			context->enc_mode = globals.default_bitrate;
 		}
 
-		switch_snprintf(fmtptmp, sizeof(fmtptmp), "octet-align=%d; mode-set=%d", switch_test_flag(context, AMR_OPT_OCTET_ALIGN) ? 1 : 0, context->enc_mode);
+		switch_snprintf(fmtptmp, sizeof(fmtptmp), "octet-align=%d; mode-set=%d", switch_test_flag(context, AMR_OPT_OCTET_ALIGN) ? 1 : 0,
+						context->enc_mode);
 		codec->fmtp_out = switch_core_strdup(codec->memory_pool, fmtptmp);
 
 		context->enc_mode = AMR_DEFAULT_BITRATE;
@@ -249,8 +250,7 @@
 										 switch_codec_t *other_codec,
 										 void *decoded_data,
 										 uint32_t decoded_data_len,
-										 uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
-										 unsigned int *flag)
+										 uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
 {
 #ifdef AMR_PASSTHROUGH
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
@@ -272,8 +272,7 @@
 										 switch_codec_t *other_codec,
 										 void *encoded_data,
 										 uint32_t encoded_data_len,
-										 uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
-										 unsigned int *flag)
+										 uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
 {
 #ifdef AMR_PASSTHROUGH
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
@@ -320,10 +319,9 @@
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 
 	SWITCH_ADD_CODEC(codec_interface, "AMR");
-    switch_core_codec_add_implementation(pool, codec_interface,
-                                         SWITCH_CODEC_TYPE_AUDIO, 96, "AMR", "octet-align=0", 8000, 8000, 12200,
-                                         20000, 160, 320, 0, 1, 1, 1,
-                                         switch_amr_init, switch_amr_encode, switch_amr_decode, switch_amr_destroy);
+	switch_core_codec_add_implementation(pool, codec_interface,
+										 SWITCH_CODEC_TYPE_AUDIO, 96, "AMR", "octet-align=0", 8000, 8000, 12200,
+										 20000, 160, 320, 0, 1, 1, 1, switch_amr_init, switch_amr_encode, switch_amr_decode, switch_amr_destroy);
 	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;
 }

Modified: freeswitch/trunk/src/mod/codecs/mod_g723_1/mod_g723_1.c
==============================================================================
--- freeswitch/trunk/src/mod/codecs/mod_g723_1/mod_g723_1.c	(original)
+++ freeswitch/trunk/src/mod/codecs/mod_g723_1/mod_g723_1.c	Tue May 27 00:54:52 2008
@@ -110,7 +110,7 @@
 										  switch_codec_t *other_codec,
 										  void *decoded_data,
 										  uint32_t decoded_data_len,
-										  uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										  uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
 										  unsigned int *flag)
 {
 #ifdef G723_PASSTHROUGH
@@ -141,7 +141,7 @@
 										  switch_codec_t *other_codec,
 										  void *encoded_data,
 										  uint32_t encoded_data_len,
-										  uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										  uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
 										  unsigned int *flag)
 {
 #ifdef G723_PASSTHROUGH
@@ -170,16 +170,16 @@
 SWITCH_MODULE_LOAD_FUNCTION(mod_g723_1_load)
 {
 	switch_codec_interface_t *codec_interface;
-    int mpf = 30000, spf = 240, bpf = 480, ebpf = 24, count;
+	int mpf = 30000, spf = 240, bpf = 480, ebpf = 24, count;
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 	SWITCH_ADD_CODEC(codec_interface, "G.723.1 6.3k");
-    for (count = 1; count > 0; count--) {
-        switch_core_codec_add_implementation(pool, codec_interface,
-                                             SWITCH_CODEC_TYPE_AUDIO, 4, "G723", NULL, 8000, 8000, 6300,
-                                             mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 4, 
-                                             switch_g723_init, switch_g723_encode, switch_g723_decode, switch_g723_destroy);
-    }
+	for (count = 1; count > 0; count--) {
+		switch_core_codec_add_implementation(pool, codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO, 4, "G723", NULL, 8000, 8000, 6300,
+											 mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 4,
+											 switch_g723_init, switch_g723_encode, switch_g723_decode, switch_g723_destroy);
+	}
 	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;
 }

Modified: freeswitch/trunk/src/mod/codecs/mod_g729/mod_g729.c
==============================================================================
--- freeswitch/trunk/src/mod/codecs/mod_g729/mod_g729.c	(original)
+++ freeswitch/trunk/src/mod/codecs/mod_g729/mod_g729.c	Tue May 27 00:54:52 2008
@@ -95,7 +95,7 @@
 										  switch_codec_t *other_codec,
 										  void *decoded_data,
 										  uint32_t decoded_data_len,
-										  uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										  uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
 										  unsigned int *flag)
 {
 #ifdef G729_PASSTHROUGH
@@ -138,7 +138,7 @@
 										  switch_codec_t *other_codec,
 										  void *encoded_data,
 										  uint32_t encoded_data_len,
-										  uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										  uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
 										  unsigned int *flag)
 {
 #ifdef G729_PASSTHROUGH
@@ -154,7 +154,7 @@
 	}
 
 	if (encoded_data_len % 2 == 0) {
-		
+
 		if (encoded_data_len == 2 || encoded_data_len % 12 == 0) {
 			return SWITCH_STATUS_BREAK;
 			//divisor = 12;
@@ -209,18 +209,18 @@
 SWITCH_MODULE_LOAD_FUNCTION(mod_g729_load)
 {
 	switch_codec_interface_t *codec_interface;
-    int mpf = 10000, spf = 80, bpf = 160, ebpf = 10, count;
+	int mpf = 10000, spf = 80, bpf = 160, ebpf = 10, count;
 
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 
 	SWITCH_ADD_CODEC(codec_interface, "G.729");
-    for (count = 12; count > 0; count--) { 
-        switch_core_codec_add_implementation(pool, codec_interface,
-                                             SWITCH_CODEC_TYPE_AUDIO, 18, "G729", NULL, 8000, 8000, 8000,
-                                             mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
-                                             switch_g729_init, switch_g729_encode, switch_g729_decode, switch_g729_destroy);
-    }
+	for (count = 12; count > 0; count--) {
+		switch_core_codec_add_implementation(pool, codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO, 18, "G729", NULL, 8000, 8000, 8000,
+											 mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
+											 switch_g729_init, switch_g729_encode, switch_g729_decode, switch_g729_destroy);
+	}
 	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;
 }

Modified: freeswitch/trunk/src/mod/codecs/mod_h26x/mod_h26x.c
==============================================================================
--- freeswitch/trunk/src/mod/codecs/mod_h26x/mod_h26x.c	(original)
+++ freeswitch/trunk/src/mod/codecs/mod_h26x/mod_h26x.c	Tue May 27 00:54:52 2008
@@ -45,7 +45,7 @@
 	if (!(encoding || decoding)) {
 		return SWITCH_STATUS_FALSE;
 	} else {
-		if (codec->fmtp_in) { 
+		if (codec->fmtp_in) {
 			codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->fmtp_in);
 		}
 		return SWITCH_STATUS_SUCCESS;
@@ -53,21 +53,21 @@
 }
 
 static switch_status_t switch_h26x_encode(switch_codec_t *codec,
-										 switch_codec_t *other_codec,
-										 void *decoded_data,
-										 uint32_t decoded_data_len,
-										 uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
-										 unsigned int *flag)
+										  switch_codec_t *other_codec,
+										  void *decoded_data,
+										  uint32_t decoded_data_len,
+										  uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
+										  unsigned int *flag)
 {
 	return SWITCH_STATUS_FALSE;
 }
 
 static switch_status_t switch_h26x_decode(switch_codec_t *codec,
-										 switch_codec_t *other_codec,
-										 void *encoded_data,
-										 uint32_t encoded_data_len,
-										 uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
-										 unsigned int *flag)
+										  switch_codec_t *other_codec,
+										  void *encoded_data,
+										  uint32_t encoded_data_len,
+										  uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
+										  unsigned int *flag)
 {
 	return SWITCH_STATUS_FALSE;
 }
@@ -83,30 +83,25 @@
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 	SWITCH_ADD_CODEC(codec_interface, "H.264 Video (passthru)");
-    switch_core_codec_add_implementation(pool, codec_interface,
-                                         SWITCH_CODEC_TYPE_VIDEO, 99, "H264", NULL, 90000, 90000, 0,
-                                         0, 0, 0, 0, 1, 1, 1,
-                                         switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
+	switch_core_codec_add_implementation(pool, codec_interface,
+										 SWITCH_CODEC_TYPE_VIDEO, 99, "H264", NULL, 90000, 90000, 0,
+										 0, 0, 0, 0, 1, 1, 1, switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
 	SWITCH_ADD_CODEC(codec_interface, "H.263 Video (passthru)");
-    switch_core_codec_add_implementation(pool, codec_interface,
-                                         SWITCH_CODEC_TYPE_VIDEO, 34, "H263", NULL, 90000, 90000, 0,
-                                         0, 0, 0, 0, 1, 1, 1,
-                                         switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
+	switch_core_codec_add_implementation(pool, codec_interface,
+										 SWITCH_CODEC_TYPE_VIDEO, 34, "H263", NULL, 90000, 90000, 0,
+										 0, 0, 0, 0, 1, 1, 1, switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
 	SWITCH_ADD_CODEC(codec_interface, "H.263+ Video (passthru)");
-    switch_core_codec_add_implementation(pool, codec_interface,
-                                         SWITCH_CODEC_TYPE_VIDEO, 115, "H263-1998", NULL, 90000, 90000, 0,
-                                         0, 0, 0, 0, 1, 1, 1,
-                                         switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
+	switch_core_codec_add_implementation(pool, codec_interface,
+										 SWITCH_CODEC_TYPE_VIDEO, 115, "H263-1998", NULL, 90000, 90000, 0,
+										 0, 0, 0, 0, 1, 1, 1, switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
 	SWITCH_ADD_CODEC(codec_interface, "H.263++ Video (passthru)");
-    switch_core_codec_add_implementation(pool, codec_interface,
-                                         SWITCH_CODEC_TYPE_VIDEO, 121, "H263-2000", NULL, 90000, 90000, 0,
-                                         0, 0, 0, 0, 1, 1, 1,
-                                         switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
+	switch_core_codec_add_implementation(pool, codec_interface,
+										 SWITCH_CODEC_TYPE_VIDEO, 121, "H263-2000", NULL, 90000, 90000, 0,
+										 0, 0, 0, 0, 1, 1, 1, switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
 	SWITCH_ADD_CODEC(codec_interface, "H.261 Video (passthru)");
-    switch_core_codec_add_implementation(pool, codec_interface,
-                                         SWITCH_CODEC_TYPE_VIDEO, 31, "H261", NULL, 90000, 90000, 0,
-                                         0, 0, 0, 0, 1, 1, 1,
-                                         switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
+	switch_core_codec_add_implementation(pool, codec_interface,
+										 SWITCH_CODEC_TYPE_VIDEO, 31, "H261", NULL, 90000, 90000, 0,
+										 0, 0, 0, 0, 1, 1, 1, switch_h26x_init, switch_h26x_encode, switch_h26x_decode, switch_h26x_destroy);
 	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;
 }

Modified: freeswitch/trunk/src/mod/codecs/mod_ilbc/mod_ilbc.c
==============================================================================
--- freeswitch/trunk/src/mod/codecs/mod_ilbc/mod_ilbc.c	(original)
+++ freeswitch/trunk/src/mod/codecs/mod_ilbc/mod_ilbc.c	Tue May 27 00:54:52 2008
@@ -97,7 +97,7 @@
 										  switch_codec_t *other_codec,
 										  void *decoded_data,
 										  uint32_t decoded_data_len,
-										  uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										  uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
 										  unsigned int *flag)
 {
 	struct ilbc_context *context = codec->private_info;
@@ -137,7 +137,7 @@
 										  switch_codec_t *other_codec,
 										  void *encoded_data,
 										  uint32_t encoded_data_len,
-										  uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										  uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
 										  unsigned int *flag)
 {
 	struct ilbc_context *context = codec->private_info;
@@ -187,31 +187,31 @@
 
 	SWITCH_ADD_CODEC(codec_interface, "iLBC");
 
-    switch_core_codec_add_implementation(pool, codec_interface,
-                                         SWITCH_CODEC_TYPE_AUDIO, 97, "iLBC", "mode=20", 8000, 8000, NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
-                                         20000, 160, 320, NO_OF_BYTES_20MS, 1, 1, 1,
-                                         switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
-    switch_core_codec_add_implementation(pool, codec_interface,
-                                         SWITCH_CODEC_TYPE_AUDIO, 102, "iLBC", "mode=20", 8000, 8000, NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
-                                         20000, 160, 320, NO_OF_BYTES_20MS, 1, 1, 1,
-                                         switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
-    switch_core_codec_add_implementation(pool, codec_interface,
-                                         SWITCH_CODEC_TYPE_AUDIO, 102, "iLBC102", "mode=20", 8000, 8000, NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
-                                         20000, 160, 320, NO_OF_BYTES_20MS, 1, 1, 1,
-                                         switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
-    switch_core_codec_add_implementation(pool, codec_interface,
-                                         SWITCH_CODEC_TYPE_AUDIO, 102, "iLBC20ms", "mode=20", 8000, 8000, NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
-                                         20000, 160, 320, NO_OF_BYTES_20MS, 1, 1, 1,
-                                         switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
-    /* 30ms variants */
-    switch_core_codec_add_implementation(pool, codec_interface,
-                                         SWITCH_CODEC_TYPE_AUDIO, 98, "iLBC", "mode=30", 8000, 8000, NO_OF_BYTES_30MS * 8 * 8000 / BLOCKL_30MS,
-                                         30000, 240, 480, NO_OF_BYTES_30MS, 1, 1, 1,
-                                         switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
-    switch_core_codec_add_implementation(pool, codec_interface,
-                                         SWITCH_CODEC_TYPE_AUDIO, 102, "iLBC", "mode=30", 8000, 8000, NO_OF_BYTES_30MS * 8 * 8000 / BLOCKL_30MS,
-                                         30000, 240, 480, NO_OF_BYTES_30MS, 1, 1, 1,
-                                         switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
+	switch_core_codec_add_implementation(pool, codec_interface,
+										 SWITCH_CODEC_TYPE_AUDIO, 97, "iLBC", "mode=20", 8000, 8000, NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
+										 20000, 160, 320, NO_OF_BYTES_20MS, 1, 1, 1,
+										 switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
+	switch_core_codec_add_implementation(pool, codec_interface,
+										 SWITCH_CODEC_TYPE_AUDIO, 102, "iLBC", "mode=20", 8000, 8000, NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
+										 20000, 160, 320, NO_OF_BYTES_20MS, 1, 1, 1,
+										 switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
+	switch_core_codec_add_implementation(pool, codec_interface,
+										 SWITCH_CODEC_TYPE_AUDIO, 102, "iLBC102", "mode=20", 8000, 8000, NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
+										 20000, 160, 320, NO_OF_BYTES_20MS, 1, 1, 1,
+										 switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
+	switch_core_codec_add_implementation(pool, codec_interface,
+										 SWITCH_CODEC_TYPE_AUDIO, 102, "iLBC20ms", "mode=20", 8000, 8000, NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
+										 20000, 160, 320, NO_OF_BYTES_20MS, 1, 1, 1,
+										 switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
+	/* 30ms variants */
+	switch_core_codec_add_implementation(pool, codec_interface,
+										 SWITCH_CODEC_TYPE_AUDIO, 98, "iLBC", "mode=30", 8000, 8000, NO_OF_BYTES_30MS * 8 * 8000 / BLOCKL_30MS,
+										 30000, 240, 480, NO_OF_BYTES_30MS, 1, 1, 1,
+										 switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
+	switch_core_codec_add_implementation(pool, codec_interface,
+										 SWITCH_CODEC_TYPE_AUDIO, 102, "iLBC", "mode=30", 8000, 8000, NO_OF_BYTES_30MS * 8 * 8000 / BLOCKL_30MS,
+										 30000, 240, 480, NO_OF_BYTES_30MS, 1, 1, 1,
+										 switch_ilbc_init, switch_ilbc_encode, switch_ilbc_decode, switch_ilbc_destroy);
 
 	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;

Modified: freeswitch/trunk/src/mod/codecs/mod_speex/mod_speex.c
==============================================================================
--- freeswitch/trunk/src/mod/codecs/mod_speex/mod_speex.c	(original)
+++ freeswitch/trunk/src/mod/codecs/mod_speex/mod_speex.c	Tue May 27 00:54:52 2008
@@ -159,7 +159,7 @@
 										   switch_codec_t *other_codec,
 										   void *decoded_data,
 										   uint32_t decoded_data_len,
-										   uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										   uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
 										   unsigned int *flag)
 {
 	struct speex_context *context = codec->private_info;
@@ -211,7 +211,7 @@
 										   switch_codec_t *other_codec,
 										   void *encoded_data,
 										   uint32_t encoded_data_len,
-										   uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										   uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
 										   unsigned int *flag)
 {
 	struct speex_context *context = codec->private_info;
@@ -264,24 +264,24 @@
 SWITCH_MODULE_LOAD_FUNCTION(mod_speex_load)
 {
 	switch_codec_interface_t *codec_interface;
-    int mpf = 20000, spf = 160, bpf = 320, ebpf = 0, rate = 8000, counta, countb;
-    switch_payload_t ianacode[4] = { 0, 98, 99, 103};
-    int bps[4] = { 0, 24600, 42200, 44000 };
+	int mpf = 20000, spf = 160, bpf = 320, ebpf = 0, rate = 8000, counta, countb;
+	switch_payload_t ianacode[4] = { 0, 98, 99, 103 };
+	int bps[4] = { 0, 24600, 42200, 44000 };
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 	SWITCH_ADD_CODEC(codec_interface, "Speex");
-    for (counta = 1; counta <= 3; counta++) {
-        for (countb = 1; countb > 0; countb--) {
-            switch_core_codec_add_implementation(pool, codec_interface,
-                                                 SWITCH_CODEC_TYPE_AUDIO, ianacode[counta], "SPEEX", NULL, rate, rate, bps[counta],
-                                                 mpf * countb, spf * countb, bpf * countb, ebpf * countb, 1, 1, 6,
-                                                 switch_speex_init, switch_speex_encode, switch_speex_decode, switch_speex_destroy);
-        }
-        rate = rate * 2;
-        spf = spf * 2;
-        bpf = bpf * 2;
-        ebpf = ebpf * 2;
-    }
+	for (counta = 1; counta <= 3; counta++) {
+		for (countb = 1; countb > 0; countb--) {
+			switch_core_codec_add_implementation(pool, codec_interface,
+												 SWITCH_CODEC_TYPE_AUDIO, ianacode[counta], "SPEEX", NULL, rate, rate, bps[counta],
+												 mpf * countb, spf * countb, bpf * countb, ebpf * countb, 1, 1, 6,
+												 switch_speex_init, switch_speex_encode, switch_speex_decode, switch_speex_destroy);
+		}
+		rate = rate * 2;
+		spf = spf * 2;
+		bpf = bpf * 2;
+		ebpf = ebpf * 2;
+	}
 
 
 

Modified: freeswitch/trunk/src/mod/codecs/mod_voipcodecs/mod_voipcodecs.c
==============================================================================
--- freeswitch/trunk/src/mod/codecs/mod_voipcodecs/mod_voipcodecs.c	(original)
+++ freeswitch/trunk/src/mod/codecs/mod_voipcodecs/mod_voipcodecs.c	Tue May 27 00:54:52 2008
@@ -81,7 +81,7 @@
 										   switch_codec_t *other_codec,
 										   void *decoded_data,
 										   uint32_t decoded_data_len,
-										   uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										   uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
 										   unsigned int *flag)
 {
 	struct lpc10_context *context = codec->private_info;
@@ -99,7 +99,7 @@
 										   switch_codec_t *other_codec,
 										   void *encoded_data,
 										   uint32_t encoded_data_len,
-										   uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										   uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
 										   unsigned int *flag)
 {
 	struct lpc10_context *context = codec->private_info;
@@ -138,8 +138,8 @@
 		}
 		if (decoding) {
 			gsm0610_init(&context->decoder_object, GSM0610_PACKING_VOIP);
- 		}
-		
+		}
+
 		codec->private_info = context;
 		return SWITCH_STATUS_SUCCESS;
 	}
@@ -149,8 +149,7 @@
 										 switch_codec_t *other_codec,
 										 void *decoded_data,
 										 uint32_t decoded_data_len,
-										 uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
-										 unsigned int *flag)
+										 uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
 {
 	struct gsm_context *context = codec->private_info;
 
@@ -167,8 +166,7 @@
 										 switch_codec_t *other_codec,
 										 void *encoded_data,
 										 uint32_t encoded_data_len,
-										 uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
-										 unsigned int *flag)
+										 uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
 {
 	struct gsm_context *context = codec->private_info;
 
@@ -187,6 +185,7 @@
 	codec->private_info = NULL;
 	return SWITCH_STATUS_SUCCESS;
 }
+
 /*  GSM       - END */
 
 #ifdef ENABLE_G711
@@ -209,7 +208,7 @@
 										   switch_codec_t *other_codec,
 										   void *decoded_data,
 										   uint32_t decoded_data_len,
-										   uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										   uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
 										   unsigned int *flag)
 {
 	short *dbuf;
@@ -232,7 +231,7 @@
 										   switch_codec_t *other_codec,
 										   void *encoded_data,
 										   uint32_t encoded_data_len,
-										   uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										   uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
 										   unsigned int *flag)
 {
 	short *dbuf;
@@ -280,7 +279,7 @@
 										   switch_codec_t *other_codec,
 										   void *decoded_data,
 										   uint32_t decoded_data_len,
-										   uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										   uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
 										   unsigned int *flag)
 {
 	short *dbuf;
@@ -303,7 +302,7 @@
 										   switch_codec_t *other_codec,
 										   void *encoded_data,
 										   uint32_t encoded_data_len,
-										   uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										   uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
 										   unsigned int *flag)
 {
 	short *dbuf;
@@ -370,7 +369,7 @@
 										  switch_codec_t *other_codec,
 										  void *decoded_data,
 										  uint32_t decoded_data_len,
-										  uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										  uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
 										  unsigned int *flag)
 {
 	struct g722_context *context = codec->private_info;
@@ -388,7 +387,7 @@
 										  switch_codec_t *other_codec,
 										  void *encoded_data,
 										  uint32_t encoded_data_len,
-										  uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										  uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
 										  unsigned int *flag)
 {
 	struct g722_context *context = codec->private_info;
@@ -416,8 +415,8 @@
 static switch_status_t switch_g726_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
 {
 	uint32_t encoding, decoding;
-    int packing = G726_PACKING_RIGHT;
-    g726_state_t *context;
+	int packing = G726_PACKING_RIGHT;
+	g726_state_t *context;
 
 	encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
 	decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
@@ -426,10 +425,10 @@
 		return SWITCH_STATUS_FALSE;
 	} else {
 		if ((flags & SWITCH_CODEC_FLAG_AAL2 || strstr(codec->implementation->iananame, "AAL2"))) {
-            packing = G726_PACKING_LEFT;
-        } 
+			packing = G726_PACKING_LEFT;
+		}
 
-        g726_init(context, codec->implementation->bits_per_second, G726_ENCODING_LINEAR, packing);
+		g726_init(context, codec->implementation->bits_per_second, G726_ENCODING_LINEAR, packing);
 
 		codec->private_info = context;
 		return SWITCH_STATUS_SUCCESS;
@@ -446,7 +445,7 @@
 										  switch_codec_t *other_codec,
 										  void *decoded_data,
 										  uint32_t decoded_data_len,
-										  uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										  uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
 										  unsigned int *flag)
 {
 	g726_state_t *context = codec->private_info;
@@ -455,7 +454,7 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
-    *encoded_data_len = g726_encode(context, (uint8_t *) encoded_data, (int16_t *) decoded_data, decoded_data_len / 2);
+	*encoded_data_len = g726_encode(context, (uint8_t *) encoded_data, (int16_t *) decoded_data, decoded_data_len / 2);
 
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -464,16 +463,16 @@
 										  switch_codec_t *other_codec,
 										  void *encoded_data,
 										  uint32_t encoded_data_len,
-										  uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										  uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
 										  unsigned int *flag)
 {
-    g726_state_t *context = codec->private_info;
+	g726_state_t *context = codec->private_info;
 
 	if (!context) {
 		return SWITCH_STATUS_FALSE;
 	}
 
-    *decoded_data_len = (2 * g726_decode(context, (int16_t *) decoded_data, (uint8_t *) encoded_data, encoded_data_len));
+	*decoded_data_len = (2 * g726_decode(context, (int16_t *) decoded_data, (uint8_t *) encoded_data, encoded_data_len));
 
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -503,8 +502,8 @@
 		}
 		if (decoding) {
 			ima_adpcm_init(&context->decoder_object, IMA_ADPCM_DVI4, 0);
- 		}
-		
+		}
+
 		codec->private_info = context;
 		return SWITCH_STATUS_SUCCESS;
 	}
@@ -514,7 +513,7 @@
 										   switch_codec_t *other_codec,
 										   void *decoded_data,
 										   uint32_t decoded_data_len,
-										   uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
+										   uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
 										   unsigned int *flag)
 {
 	struct ima_adpcm_context *context = codec->private_info;
@@ -532,7 +531,7 @@
 										   switch_codec_t *other_codec,
 										   void *encoded_data,
 										   uint32_t encoded_data_len,
-										   uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
+										   uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
 										   unsigned int *flag)
 {
 	struct ima_adpcm_context *context = codec->private_info;
@@ -559,7 +558,7 @@
 SWITCH_MODULE_LOAD_FUNCTION(mod_voipcodecs_load)
 {
 	switch_codec_interface_t *codec_interface;
-    int mpf, spf, bpf, ebpf, count;
+	int mpf, spf, bpf, ebpf, count;
 
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
@@ -567,134 +566,133 @@
 	/* IMA_ADPCM */
 	mpf = 10000, spf = 80, bpf = 160, ebpf = 80;
 	SWITCH_ADD_CODEC(codec_interface, "ADPCM (IMA)");
-    for (count = 12; count > 0; count--) {
-        switch_core_codec_add_implementation(pool, codec_interface,
-                                             SWITCH_CODEC_TYPE_AUDIO, 5, "DVI4", NULL, 8000, 8000, 32000,
-                                             mpf * count, spf * count, bpf * count, (ebpf * count) + 4, 1, 1, 12,
-                                             switch_adpcm_init, switch_adpcm_encode, switch_adpcm_decode, switch_adpcm_destroy);
-    }
+	for (count = 12; count > 0; count--) {
+		switch_core_codec_add_implementation(pool, codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO, 5, "DVI4", NULL, 8000, 8000, 32000,
+											 mpf * count, spf * count, bpf * count, (ebpf * count) + 4, 1, 1, 12,
+											 switch_adpcm_init, switch_adpcm_encode, switch_adpcm_decode, switch_adpcm_destroy);
+	}
 	mpf = 10000, spf = 160, bpf = 320, ebpf = 160;
-    for (count = 12; count > 0; count--) {
-        switch_core_codec_add_implementation(pool, codec_interface,
-                                             SWITCH_CODEC_TYPE_AUDIO, 6, "DVI4", NULL, 16000, 16000, 64000,
-                                             mpf * count, spf * count, bpf * count, (ebpf * count) + 4, 1, 1, 12,
-                                             switch_adpcm_init, switch_adpcm_encode, switch_adpcm_decode, switch_adpcm_destroy);
-    }
+	for (count = 12; count > 0; count--) {
+		switch_core_codec_add_implementation(pool, codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO, 6, "DVI4", NULL, 16000, 16000, 64000,
+											 mpf * count, spf * count, bpf * count, (ebpf * count) + 4, 1, 1, 12,
+											 switch_adpcm_init, switch_adpcm_encode, switch_adpcm_decode, switch_adpcm_destroy);
+	}
 
 	/* G726 */
 	mpf = 10000, spf = 80, bpf = 160, ebpf = 20;
 	SWITCH_ADD_CODEC(codec_interface, "G.726 16k (AAL2)");
-    for (count = 12; count > 0; count--) {
-        switch_core_codec_add_implementation(pool, codec_interface,
-                                             SWITCH_CODEC_TYPE_AUDIO, 124, "AAL2-G726-16", NULL, 8000, 8000, 16000,
-                                             mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
-                                             switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
-    }
+	for (count = 12; count > 0; count--) {
+		switch_core_codec_add_implementation(pool, codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO, 124, "AAL2-G726-16", NULL, 8000, 8000, 16000,
+											 mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
+											 switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
+	}
 	SWITCH_ADD_CODEC(codec_interface, "G.726 16k");
-    for (count = 12; count > 0; count--) {
-        switch_core_codec_add_implementation(pool, codec_interface,
-                                             SWITCH_CODEC_TYPE_AUDIO, 127, "G726-16", NULL, 8000, 8000, 16000,
-                                             mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
-                                             switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
-    }
-    /* Increase encoded bytes per frame by 10 */
-    ebpf = ebpf + 10;
+	for (count = 12; count > 0; count--) {
+		switch_core_codec_add_implementation(pool, codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO, 127, "G726-16", NULL, 8000, 8000, 16000,
+											 mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
+											 switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
+	}
+	/* Increase encoded bytes per frame by 10 */
+	ebpf = ebpf + 10;
 
 	SWITCH_ADD_CODEC(codec_interface, "G.726 24k (AAL2)");
-    for (count = 12; count > 0; count--) {
-        switch_core_codec_add_implementation(pool, codec_interface,
-                                             SWITCH_CODEC_TYPE_AUDIO, 123, "AAL2-G726-24", NULL, 8000, 8000, 24000,
-                                             mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
-                                             switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
-    }
+	for (count = 12; count > 0; count--) {
+		switch_core_codec_add_implementation(pool, codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO, 123, "AAL2-G726-24", NULL, 8000, 8000, 24000,
+											 mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
+											 switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
+	}
 	SWITCH_ADD_CODEC(codec_interface, "G.726 24k");
-    for (count = 12; count > 0; count--) {
-        switch_core_codec_add_implementation(pool, codec_interface,
-                                             SWITCH_CODEC_TYPE_AUDIO, 126, "G726-24", NULL, 8000, 8000, 24000,
-                                             mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
-                                             switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
-    }
-    /* Increase encoded bytes per frame by 10 */
-    ebpf = ebpf + 10;
+	for (count = 12; count > 0; count--) {
+		switch_core_codec_add_implementation(pool, codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO, 126, "G726-24", NULL, 8000, 8000, 24000,
+											 mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
+											 switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
+	}
+	/* Increase encoded bytes per frame by 10 */
+	ebpf = ebpf + 10;
 
 	SWITCH_ADD_CODEC(codec_interface, "G.726 32k (AAL2)");
-    for (count = 12; count > 0; count--) {
-        switch_core_codec_add_implementation(pool, codec_interface,
-                                             SWITCH_CODEC_TYPE_AUDIO, 2, "AAL2-G726-32", NULL, 8000, 8000, 32000,
-                                             mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
-                                             switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
-    }
+	for (count = 12; count > 0; count--) {
+		switch_core_codec_add_implementation(pool, codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO, 2, "AAL2-G726-32", NULL, 8000, 8000, 32000,
+											 mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
+											 switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
+	}
 	SWITCH_ADD_CODEC(codec_interface, "G.726 32k");
-    for (count = 12; count > 0; count--) {
-        switch_core_codec_add_implementation(pool, codec_interface,
-                                             SWITCH_CODEC_TYPE_AUDIO, 2, "G726-32", NULL, 8000, 8000, 32000,
-                                             mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
-                                             switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
-    }
-    /* Increase encoded bytes per frame by 10 */
-    ebpf = ebpf + 10;
+	for (count = 12; count > 0; count--) {
+		switch_core_codec_add_implementation(pool, codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO, 2, "G726-32", NULL, 8000, 8000, 32000,
+											 mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
+											 switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
+	}
+	/* Increase encoded bytes per frame by 10 */
+	ebpf = ebpf + 10;
 
 	SWITCH_ADD_CODEC(codec_interface, "G.726 40k (AAL2)");
-    for (count = 12; count > 0; count--) {
-        switch_core_codec_add_implementation(pool, codec_interface,
-                                             SWITCH_CODEC_TYPE_AUDIO, 122, "AAL2-G726-40", NULL, 8000, 8000, 40000,
-                                             mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
-                                             switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
-    }
+	for (count = 12; count > 0; count--) {
+		switch_core_codec_add_implementation(pool, codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO, 122, "AAL2-G726-40", NULL, 8000, 8000, 40000,
+											 mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
+											 switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
+	}
 	SWITCH_ADD_CODEC(codec_interface, "G.726 40k");
-    for (count = 12; count > 0; count--) {
-        switch_core_codec_add_implementation(pool, codec_interface,
-                                             SWITCH_CODEC_TYPE_AUDIO, 125, "G726-40", NULL, 8000, 8000, 40000,
-                                             mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
-                                             switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
-    }
+	for (count = 12; count > 0; count--) {
+		switch_core_codec_add_implementation(pool, codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO, 125, "G726-40", NULL, 8000, 8000, 40000,
+											 mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
+											 switch_g726_init, switch_g726_encode, switch_g726_decode, switch_g726_destroy);
+	}
 
 	/* G722 */
 	mpf = 10000, spf = 80, bpf = 320, ebpf = 80;
 	SWITCH_ADD_CODEC(codec_interface, "G.722");
-    for (count = 12; count > 0; count--) {
-        switch_core_codec_add_implementation(pool, codec_interface,
-                                             SWITCH_CODEC_TYPE_AUDIO, 9, "G722", NULL, 8000, 16000, 64000,
-                                             mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
-                                             switch_g722_init, switch_g722_encode, switch_g722_decode, switch_g722_destroy);
-    }
+	for (count = 12; count > 0; count--) {
+		switch_core_codec_add_implementation(pool, codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO, 9, "G722", NULL, 8000, 16000, 64000,
+											 mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
+											 switch_g722_init, switch_g722_encode, switch_g722_decode, switch_g722_destroy);
+	}
 
 #ifdef ENABLE_G711
 	/* G711 */
 	mpf = 10000, spf = 80, bpf = 160, ebpf = 80;
 	SWITCH_ADD_CODEC(codec_interface, "G.711 ulaw");
-    for (count = 12; count > 0; count--) {
-        switch_core_codec_add_implementation(pool, codec_interface,
-                                             SWITCH_CODEC_TYPE_AUDIO, 0, "PCMU", NULL, 8000, 8000, 64000,
-                                             mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
-                                             switch_g711u_init, switch_g711u_encode, switch_g711u_decode, switch_g711u_destroy);
-    }
-    
+	for (count = 12; count > 0; count--) {
+		switch_core_codec_add_implementation(pool, codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO, 0, "PCMU", NULL, 8000, 8000, 64000,
+											 mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
+											 switch_g711u_init, switch_g711u_encode, switch_g711u_decode, switch_g711u_destroy);
+	}
+
 	SWITCH_ADD_CODEC(codec_interface, "G.711 alaw");
-    for (count = 12; count > 0; count--) {
-        switch_core_codec_add_implementation(pool, codec_interface,
-                                             SWITCH_CODEC_TYPE_AUDIO, 8, "PCMA", NULL, 8000, 8000, 64000,
-                                             mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
-                                             switch_g711a_init, switch_g711a_encode, switch_g711a_decode, switch_g711a_destroy);
-    }
+	for (count = 12; count > 0; count--) {
+		switch_core_codec_add_implementation(pool, codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO, 8, "PCMA", NULL, 8000, 8000, 64000,
+											 mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 12,
+											 switch_g711a_init, switch_g711a_encode, switch_g711a_decode, switch_g711a_destroy);
+	}
 #endif
 
 	/* GSM */
 	mpf = 20000, spf = 160, bpf = 320, ebpf = 33;
 	SWITCH_ADD_CODEC(codec_interface, "GSM");
-    for (count = 6; count > 0; count--) {
-        switch_core_codec_add_implementation(pool, codec_interface,
-                                             SWITCH_CODEC_TYPE_AUDIO, 3, "GSM", NULL, 8000, 8000, 13200,
-                                             mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 6,
-                                             switch_gsm_init, switch_gsm_encode, switch_gsm_decode, switch_gsm_destroy);
-    }
+	for (count = 6; count > 0; count--) {
+		switch_core_codec_add_implementation(pool, codec_interface,
+											 SWITCH_CODEC_TYPE_AUDIO, 3, "GSM", NULL, 8000, 8000, 13200,
+											 mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 6,
+											 switch_gsm_init, switch_gsm_encode, switch_gsm_decode, switch_gsm_destroy);
+	}
 	/* LPC10 */
 #if SWITCH_MAX_INTERVAL >= 90
 	SWITCH_ADD_CODEC(codec_interface, "LPC-10");
 	switch_core_codec_add_implementation(pool, codec_interface,
 										 SWITCH_CODEC_TYPE_AUDIO, 7, "LPC", NULL, 8000, 8000, 2400,
-										 90000, 720, 1440, 28, 1, 1, 1,
-										 switch_lpc10_init, switch_lpc10_encode, switch_lpc10_decode, switch_lpc10_destroy);
+										 90000, 720, 1440, 28, 1, 1, 1, switch_lpc10_init, switch_lpc10_encode, switch_lpc10_decode, switch_lpc10_destroy);
 #endif
 	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;

Modified: freeswitch/trunk/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c
==============================================================================
--- freeswitch/trunk/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c	(original)
+++ freeswitch/trunk/src/mod/dialplans/mod_dialplan_asterisk/mod_dialplan_asterisk.c	Tue May 27 00:54:52 2008
@@ -58,31 +58,31 @@
 		if ((argc = switch_separate_string(mydata, '|', argv, (sizeof(argv) / sizeof(argv[0])))) < 2) {
 			goto error;
 		}
-		
+
 		if (argc > 1) {
 			switch_channel_set_variable(channel, "call_timeout", argv[1]);
 		}
-		
-		switch_replace_char(argv[0], '&',',', SWITCH_FALSE);
-		
+
+		switch_replace_char(argv[0], '&', ',', SWITCH_FALSE);
+
 		if (exec_app(session, "bridge", argv[0]) != SWITCH_STATUS_SUCCESS) {
 			goto error;
 		}
-		
+
 		goto ok;
 	}
-	
- error:
+
+  error:
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error!\n");
 
- ok:
-	
+  ok:
+
 	return;
 }
 
 SWITCH_STANDARD_APP(avoid_function)
 {
-    void *y = NULL;
+	void *y = NULL;
 	int x = 0;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 
@@ -92,7 +92,7 @@
 	}
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "I should never be called!.\n");
-    memset((void *) y, 0, 1000);
+	memset((void *) y, 0, 1000);
 }
 
 SWITCH_STANDARD_APP(goto_function)
@@ -105,16 +105,16 @@
 		if ((argc = switch_separate_string(mydata, '|', argv, (sizeof(argv) / sizeof(argv[0])))) < 1) {
 			goto error;
 		}
-		
+
 		switch_ivr_session_transfer(session, argv[1], "asterisk", argv[0]);
 		goto ok;
 	}
-	
- error:
+
+  error:
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error!\n");
 
- ok:
-	
+  ok:
+
 	return;
 }
 
@@ -134,14 +134,14 @@
 	if (!caller_profile) {
 		caller_profile = switch_channel_get_caller_profile(channel);
 	}
-	
+
 	if (!caller_profile || switch_strlen_zero(caller_profile->destination_number)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Obtaining Profile!\n");
 		return NULL;
 	}
 
 	context = caller_profile->context ? caller_profile->context : "default";
-	
+
 	if (!switch_config_open_file(&cfg, cf)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
 		switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
@@ -166,11 +166,11 @@
 				const char *field_data = caller_profile->destination_number;
 				int proceed = 0;
 				switch_regex_t *re = NULL;
-				int ovector[30] = {0};
+				int ovector[30] = { 0 };
 				char *cid = NULL;
 
 				expression = expression_buf;
-						
+
 				argc = switch_separate_string(val, ',', argv, (sizeof(argv) / sizeof(argv[0])));
 				if (argc < 3) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "parse error line %d!\n", cfg.lineno);
@@ -178,14 +178,14 @@
 				}
 
 				pattern = argv[0];
-				
+
 				if (!strcasecmp(var, "exten")) {
 					char *p;
 					if (pattern && (p = strchr(pattern, '/'))) {
 						*p++ = '\0';
 						cid = pattern;
 						pattern = p;
-					}	
+					}
 				} else {
 					if (strchr(var, '$')) {
 						if ((field_expanded = switch_channel_expand_variables(channel, var)) == var) {
@@ -198,19 +198,19 @@
 						field_data = switch_caller_get_field_by_name(caller_profile, var);
 					}
 				}
-				
+
 				if (pattern && (*pattern == '_' || *pattern == '~')) {
 					if (*pattern == '_') {
 						pattern++;
 						if (switch_ast2regex(pattern, expression_buf, sizeof(expression_buf))) {
-							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "converting [%s] to real regex [%s] you should try them!\n", 
+							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "converting [%s] to real regex [%s] you should try them!\n",
 											  pattern, expression_buf);
 						}
 					} else {
 						pattern++;
 						expression = pattern;
 					}
-					
+
 					if (!field_data) {
 						field_data = "";
 					}
@@ -225,7 +225,7 @@
 						continue;
 					}
 				}
-				
+
 				if (cid) {
 					if (strcasecmp(cid, caller_profile->caller_id_number)) {
 						continue;
@@ -235,21 +235,21 @@
 				switch_channel_set_variable(channel, "EXTEN", caller_profile->destination_number);
 				switch_channel_set_variable(channel, "CHANNEL", switch_channel_get_name(channel));
 				switch_channel_set_variable(channel, "UNIQUEID", switch_core_session_get_uuid(session));
-				
+
 				pri = argv[1];
 				app = argv[2];
-				
+
 				if ((argument = strchr(app, '('))) {
 					char *p;
 					*argument++ = '\0';
 					p = strrchr(argument, ')');
 					if (p) {
-							*p = '\0';
+						*p = '\0';
 					}
 				} else if ((argument = strchr(app, ','))) {
 					*argument++ = '\0';
 				}
-				
+
 				if (!argument) {
 					argument = "";
 				}
@@ -274,10 +274,10 @@
 						break;
 					}
 				}
-				
+
 				switch_caller_extension_add_application(session, extension, app, argument);
 			}
-			
+
 			switch_safe_free(field_expanded);
 		}
 	}
@@ -291,18 +291,14 @@
 switch_endpoint_interface_t *sip_endpoint_interface;
 static switch_call_cause_t sip_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);
+												switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags);
 switch_io_routines_t sip_io_routines = {
 	/*.outgoing_channel */ sip_outgoing_channel
 };
 
 static switch_call_cause_t sip_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)
+												switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags)
 {
 	const char *profile;
 
@@ -326,18 +322,14 @@
 switch_endpoint_interface_t *iax2_endpoint_interface;
 static switch_call_cause_t iax2_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);
+												 switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags);
 switch_io_routines_t iax2_io_routines = {
 	/*.outgoing_channel */ iax2_outgoing_channel
 };
 
 static switch_call_cause_t iax2_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)
+												 switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags)
 {
 	return switch_core_session_outgoing_channel(session, var_event, "iax", outbound_profile, new_session, pool, SOF_NONE);
 }
@@ -346,7 +338,7 @@
 #define WE_DONT_NEED_NO_STINKIN_KEY "true"
 static char *key()
 {
-    return WE_DONT_NEED_NO_STINKIN_KEY;
+	return WE_DONT_NEED_NO_STINKIN_KEY;
 }
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_dialplan_asterisk_load)
@@ -359,7 +351,7 @@
 	if ((mykey = key())) {
 		mykey = NULL;
 	}
-	
+
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 	/* add a dialplan interface */
@@ -369,7 +361,7 @@
 	SWITCH_ADD_APP(app_interface, "Dial", "Dial", "Dial", dial_function, "Dial", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "Goto", "Goto", "Goto", goto_function, "Goto", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "AvoidingDeadlock", "Avoid", "Avoid", avoid_function, "Avoid", SAF_SUPPORT_NOMEDIA);
-	
+
 	/* fake chan_sip facade */
 	sip_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
 	sip_endpoint_interface->interface_name = "SIP";
@@ -379,7 +371,7 @@
 	iax2_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
 	iax2_endpoint_interface->interface_name = "IAX2";
 	iax2_endpoint_interface->io_routines = &iax2_io_routines;
-	
+
 	if (getenv("FAITHFUL_EMULATION")) {
 		for (x = 0; x < 10; x++) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Avoiding Deadlock.\n");

Modified: freeswitch/trunk/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c
==============================================================================
--- freeswitch/trunk/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c	(original)
+++ freeswitch/trunk/src/mod/dialplans/mod_dialplan_directory/mod_dialplan_directory.c	Tue May 27 00:54:52 2008
@@ -96,7 +96,7 @@
 	if (!caller_profile) {
 		caller_profile = switch_channel_get_caller_profile(channel);
 	}
-	
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Hello %s You Dialed %s!\n", caller_profile->caller_id_name,
 					  caller_profile->destination_number);
 
@@ -134,7 +134,7 @@
 			}
 		}
 	}
- out:
+  out:
 
 	switch_core_directory_close(&dh);
 

Modified: freeswitch/trunk/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c
==============================================================================
--- freeswitch/trunk/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c	(original)
+++ freeswitch/trunk/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c	Tue May 27 00:54:52 2008
@@ -185,15 +185,14 @@
 	return proceed;
 }
 
-static switch_status_t dialplan_xml_locate(switch_core_session_t *session, switch_caller_profile_t *caller_profile, switch_xml_t * root,
-										   switch_xml_t * node)
+static switch_status_t dialplan_xml_locate(switch_core_session_t *session, switch_caller_profile_t *caller_profile, switch_xml_t *root, switch_xml_t *node)
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	switch_status_t status = SWITCH_STATUS_GENERR;
 	switch_event_t *params = NULL;
 
 	switch_event_create(&params, SWITCH_EVENT_MESSAGE);
-    switch_assert(params);
+	switch_assert(params);
 
 	switch_channel_event_set_data(channel, params);
 
@@ -215,7 +214,7 @@
 			goto done;
 		}
 	}
-	
+
 	if (!caller_profile->context) {
 		caller_profile->context = "default";
 	}
@@ -265,7 +264,7 @@
 
 		proceed = parse_exten(session, caller_profile, xexten, &extension);
 
-		if (proceed && !switch_true(cont)) { 
+		if (proceed && !switch_true(cont)) {
 			break;
 		}
 

Modified: freeswitch/trunk/src/mod/endpoints/mod_alsa/mod_alsa.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_alsa/mod_alsa.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_alsa/mod_alsa.c	Tue May 27 00:54:52 2008
@@ -139,8 +139,8 @@
 SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_device_name, globals.device_name);
 
 #define is_master(t) switch_test_flag(t, TFLAG_MASTER)
-static void add_pvt(private_t * tech_pvt, int master);
-static void remove_pvt(private_t * tech_pvt);
+static void add_pvt(private_t *tech_pvt, int master);
+static void remove_pvt(private_t *tech_pvt);
 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_routing(switch_core_session_t *session);
@@ -356,7 +356,7 @@
 
 
 
-static void add_pvt(private_t * tech_pvt, int master)
+static void add_pvt(private_t *tech_pvt, int master)
 {
 	private_t *tp;
 	uint8_t in_list = 0;
@@ -399,7 +399,7 @@
 	switch_mutex_unlock(globals.pvt_lock);
 }
 
-static void remove_pvt(private_t * tech_pvt)
+static void remove_pvt(private_t *tech_pvt)
 {
 	private_t *tp, *last = NULL;
 
@@ -562,8 +562,7 @@
 										  tech_pvt->hold_file,
 										  globals.read_codec.implementation->number_of_channels,
 										  globals.read_codec.implementation->actual_samples_per_second,
-										  SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
-										  NULL) != SWITCH_STATUS_SUCCESS) {
+										  SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
 					switch_core_codec_destroy(&tech_pvt->write_codec);
 					tech_pvt->hold_file = NULL;
 					goto cng;
@@ -578,12 +577,12 @@
 
 			goto hold;
 		}
-	cng:
+	  cng:
 		switch_yield(globals.read_codec.implementation->microseconds_per_frame);
 		*frame = &globals.cng_frame;
 		return SWITCH_STATUS_SUCCESS;
 
-	hold:
+	  hold:
 
 		{
 			switch_size_t olen = globals.read_codec.implementation->samples_per_frame;
@@ -612,7 +611,7 @@
 	}
 
 	switch_mutex_lock(globals.device_lock);
-	if ((samples = snd_pcm_readi (globals.audio_stream_in, globals.read_frame.data, globals.read_codec.implementation->samples_per_frame)) > 0) {
+	if ((samples = snd_pcm_readi(globals.audio_stream_in, globals.read_frame.data, globals.read_codec.implementation->samples_per_frame)) > 0) {
 		globals.read_frame.datalen = samples * 2;
 		globals.read_frame.samples = samples;
 
@@ -887,7 +886,7 @@
 					globals.codec_ms = tmp;
 				} else {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
-									  "codec-ms must be multipe of 10 and less than %d, Using default of 20\n", SWITCH_MAX_INTERVAL); 
+									  "codec-ms must be multipe of 10 and less than %d, Using default of 20\n", SWITCH_MAX_INTERVAL);
 				}
 			} else if (!strcmp(var, "dialplan")) {
 				set_global_dialplan(val);
@@ -951,18 +950,18 @@
 	int err = 0;
 	snd_pcm_hw_params_t *hw_params = NULL;
 	char *device = globals.device_name;
-	
+
 	if (globals.audio_stream_in && globals.audio_stream_out) {
 		return SWITCH_STATUS_SUCCESS;
-	} 
+	}
 
 	if (globals.audio_stream_in) {
-		snd_pcm_close (globals.audio_stream_in);
+		snd_pcm_close(globals.audio_stream_in);
 		globals.audio_stream_in = NULL;
 	}
 
 	if (globals.audio_stream_out) {
-		snd_pcm_close (globals.audio_stream_out);
+		snd_pcm_close(globals.audio_stream_out);
 		globals.audio_stream_out = NULL;
 	}
 
@@ -976,33 +975,30 @@
 
 	if (switch_core_codec_init(&globals.read_codec,
 							   "L16",
-							   NULL, sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
-							   NULL) != SWITCH_STATUS_SUCCESS) {
+							   NULL, sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
 		return SWITCH_STATUS_FALSE;
 	} else {
 		if (switch_core_codec_init(&globals.write_codec,
 								   "L16",
 								   NULL,
-								   sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
-								   NULL) != SWITCH_STATUS_SUCCESS) {
+								   sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
 			switch_core_codec_destroy(&globals.read_codec);
 			return SWITCH_STATUS_FALSE;
 		}
 	}
-	
+
 	if (switch_core_timer_init(&globals.timer,
-							   globals.timer_name, codec_ms, globals.read_codec.implementation->samples_per_frame,
-							   module_pool) != SWITCH_STATUS_SUCCESS) {
+							   globals.timer_name, codec_ms, globals.read_codec.implementation->samples_per_frame, module_pool) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setup timer failed!\n");
 		switch_core_codec_destroy(&globals.read_codec);
 		switch_core_codec_destroy(&globals.write_codec);
 		return SWITCH_STATUS_FALSE;
 	}
 
-	
-	
+
+
 	globals.read_frame.rate = sample_rate;
 	globals.read_frame.codec = &globals.read_codec;
 
@@ -1011,176 +1007,152 @@
 	switch_mutex_lock(globals.device_lock);
 	/* LOCKED ************************************************************************************************** */
 
-		
-	if ((err = snd_pcm_open (&globals.audio_stream_out, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot open audio device %s (%s)\n", 
-						  device,
-						  snd_strerror (err));
+
+	if ((err = snd_pcm_open(&globals.audio_stream_out, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot open audio device %s (%s)\n", device, snd_strerror(err));
 		goto fail;
 	}
 
-	if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot allocate hardware parameter structure (%s)\n",
-						  snd_strerror (err));
+	if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot allocate hardware parameter structure (%s)\n", snd_strerror(err));
 		goto fail;
 	}
-	 
-	if ((err = snd_pcm_hw_params_any (globals.audio_stream_out, hw_params)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot initialize hardware parameter structure (%s)\n",
-						  snd_strerror (err));
+
+	if ((err = snd_pcm_hw_params_any(globals.audio_stream_out, hw_params)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot initialize hardware parameter structure (%s)\n", snd_strerror(err));
 		goto fail;
 	}
-	
-	if ((err = snd_pcm_hw_params_set_access (globals.audio_stream_out, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot set access type (%s)\n",
-						  snd_strerror (err));
+
+	if ((err = snd_pcm_hw_params_set_access(globals.audio_stream_out, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set access type (%s)\n", snd_strerror(err));
 		goto fail;
 	}
-	
-	if ((err = snd_pcm_hw_params_set_format (globals.audio_stream_out, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot set sample format (%s)\n",
-						  snd_strerror (err));
+
+	if ((err = snd_pcm_hw_params_set_format(globals.audio_stream_out, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set sample format (%s)\n", snd_strerror(err));
 		goto fail;
 	}
-	
-	if ((err = snd_pcm_hw_params_set_rate_near (globals.audio_stream_out, hw_params, &sample_rate, 0)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot set sample rate (%s)\n",
-						  snd_strerror (err));
+
+	if ((err = snd_pcm_hw_params_set_rate_near(globals.audio_stream_out, hw_params, &sample_rate, 0)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set sample rate (%s)\n", snd_strerror(err));
 		goto fail;
 	}
-	
-	if ((err = snd_pcm_hw_params_set_channels (globals.audio_stream_out, hw_params, 1)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot set channel count (%s)\n",
-						  snd_strerror (err));
+
+	if ((err = snd_pcm_hw_params_set_channels(globals.audio_stream_out, hw_params, 1)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set channel count (%s)\n", snd_strerror(err));
 		goto fail;
 	}
-	
-	if ((err = snd_pcm_hw_params (globals.audio_stream_out, hw_params)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot set parameters (%s)\n",
-						  snd_strerror (err));
+
+	if ((err = snd_pcm_hw_params(globals.audio_stream_out, hw_params)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set parameters (%s)\n", snd_strerror(err));
 		goto fail;
 	}
-	
-	
-	snd_pcm_hw_params_free (hw_params);
+
+
+	snd_pcm_hw_params_free(hw_params);
 	hw_params = NULL;
 
 
-	if ((err = snd_pcm_open (&globals.audio_stream_in, device, SND_PCM_STREAM_CAPTURE, 0)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot open audio device %s (%s)\n", 
-						  device,
-						  snd_strerror (err));
+	if ((err = snd_pcm_open(&globals.audio_stream_in, device, SND_PCM_STREAM_CAPTURE, 0)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot open audio device %s (%s)\n", device, snd_strerror(err));
 		goto fail;
-	} 
+	}
 
-	if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot allocate hardware parameter structure (%s)\n",
-						  snd_strerror (err));
+	if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot allocate hardware parameter structure (%s)\n", snd_strerror(err));
 		goto fail;
 	}
-	 
-	if ((err = snd_pcm_hw_params_any (globals.audio_stream_in, hw_params)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot initialize hardware parameter structure (%s)\n",
-						  snd_strerror (err));
+
+	if ((err = snd_pcm_hw_params_any(globals.audio_stream_in, hw_params)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot initialize hardware parameter structure (%s)\n", snd_strerror(err));
 		goto fail;
 	}
-	
-	if ((err = snd_pcm_hw_params_set_access (globals.audio_stream_in, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot set access type (%s)\n",
-						  snd_strerror (err));
+
+	if ((err = snd_pcm_hw_params_set_access(globals.audio_stream_in, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set access type (%s)\n", snd_strerror(err));
 		goto fail;
 	}
-	
-	if ((err = snd_pcm_hw_params_set_format (globals.audio_stream_in, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot set sample format (%s)\n",
-						  snd_strerror (err));
+
+	if ((err = snd_pcm_hw_params_set_format(globals.audio_stream_in, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set sample format (%s)\n", snd_strerror(err));
 		goto fail;
 	}
-	
-	if ((err = snd_pcm_hw_params_set_rate_near (globals.audio_stream_in, hw_params, &sample_rate, 0)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot set sample rate (%s)\n",
-						  snd_strerror (err));
+
+	if ((err = snd_pcm_hw_params_set_rate_near(globals.audio_stream_in, hw_params, &sample_rate, 0)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set sample rate (%s)\n", snd_strerror(err));
 		goto fail;
 	}
-	
-	if ((err = snd_pcm_hw_params_set_channels (globals.audio_stream_in, hw_params, 1)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot set channel count (%s)\n",
-						  snd_strerror (err));
+
+	if ((err = snd_pcm_hw_params_set_channels(globals.audio_stream_in, hw_params, 1)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set channel count (%s)\n", snd_strerror(err));
 		goto fail;
 	}
 
-	if ((err = snd_pcm_hw_params_set_period_time (globals.audio_stream_in, hw_params, globals.read_codec.implementation->microseconds_per_frame, 0)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot set period time (%s)\n",
-						  snd_strerror (err));
+	if ((err = snd_pcm_hw_params_set_period_time(globals.audio_stream_in, hw_params, globals.read_codec.implementation->microseconds_per_frame, 0)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set period time (%s)\n", snd_strerror(err));
 		goto fail;
 	}
 
-	if ((err = snd_pcm_hw_params_set_period_size (globals.audio_stream_in, hw_params, globals.read_codec.implementation->samples_per_frame, 0)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot set period size (%s)\n",
-						  snd_strerror (err));
+	if ((err = snd_pcm_hw_params_set_period_size(globals.audio_stream_in, hw_params, globals.read_codec.implementation->samples_per_frame, 0)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set period size (%s)\n", snd_strerror(err));
 		goto fail;
 	}
 
-	if ((err = snd_pcm_hw_params (globals.audio_stream_in, hw_params)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot set parameters (%s)\n",
-						  snd_strerror (err));
+	if ((err = snd_pcm_hw_params(globals.audio_stream_in, hw_params)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot set parameters (%s)\n", snd_strerror(err));
 		goto fail;
 	}
-	
+
 	if (hw_params) {
-		snd_pcm_hw_params_free (hw_params);
+		snd_pcm_hw_params_free(hw_params);
 		hw_params = NULL;
 	}
 
-	if ((err = snd_pcm_prepare (globals.audio_stream_out)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot prepare audio interface for use (%s)\n",
-						  snd_strerror (err));
+	if ((err = snd_pcm_prepare(globals.audio_stream_out)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot prepare audio interface for use (%s)\n", snd_strerror(err));
 		goto fail;
 	}
 
-	if ((err = snd_pcm_start (globals.audio_stream_out)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot start audio interface for use (%s)\n",
-						  snd_strerror (err));
+	if ((err = snd_pcm_start(globals.audio_stream_out)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot start audio interface for use (%s)\n", snd_strerror(err));
 		goto fail;
 	}
 
-	if ((err = snd_pcm_prepare (globals.audio_stream_in)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot prepare audio interface for use (%s)\n",
-						  snd_strerror (err));
+	if ((err = snd_pcm_prepare(globals.audio_stream_in)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot prepare audio interface for use (%s)\n", snd_strerror(err));
 		goto fail;
 	}
 
-	if ((err = snd_pcm_start (globals.audio_stream_in)) < 0) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,  "cannot start audio interface for use (%s)\n",
-						  snd_strerror (err));
+	if ((err = snd_pcm_start(globals.audio_stream_in)) < 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot start audio interface for use (%s)\n", snd_strerror(err));
 		goto fail;
 	}
-		
+
 	switch_mutex_unlock(globals.device_lock);
 	return SWITCH_STATUS_SUCCESS;
 
- fail:
+  fail:
 
 	if (hw_params) {
-		snd_pcm_hw_params_free (hw_params);
+		snd_pcm_hw_params_free(hw_params);
 		hw_params = NULL;
 	}
 
 	switch_mutex_unlock(globals.device_lock);
 
 	if (globals.audio_stream_in) {
-		snd_pcm_close (globals.audio_stream_in);
+		snd_pcm_close(globals.audio_stream_in);
 	}
 
 	if (globals.audio_stream_out) {
-		snd_pcm_close (globals.audio_stream_out);
+		snd_pcm_close(globals.audio_stream_out);
 	}
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open audio device!\n");
 	switch_core_codec_destroy(&globals.read_codec);
 	switch_core_codec_destroy(&globals.write_codec);
-	
-	return SWITCH_STATUS_FALSE;	
+
+	return SWITCH_STATUS_FALSE;
 
 
 
@@ -1189,8 +1161,8 @@
 static switch_status_t dtmf_call(char **argv, int argc, switch_stream_handle_t *stream)
 {
 	char *dtmf_str = argv[0];
-	switch_dtmf_t dtmf = {0, switch_core_default_dtmf_duration(0)};
-	
+	switch_dtmf_t dtmf = { 0, switch_core_default_dtmf_duration(0) };
+
 	if (switch_strlen_zero(dtmf_str)) {
 		stream->write_function(stream, "No DTMF Supplied!\n");
 	} else {
@@ -1198,7 +1170,7 @@
 		if (globals.call_list) {
 			switch_channel_t *channel = switch_core_session_get_channel(globals.call_list->session);
 			char *p = dtmf_str;
-			while(p && *p) {
+			while (p && *p) {
 				dtmf.digit = *p;
 				switch_channel_queue_dtmf(channel, &dtmf);
 				p++;
@@ -1250,7 +1222,7 @@
 		stream->write_function(stream, "NO SUCH CALL\n");
 	}
 
- done:
+  done:
 	switch_mutex_unlock(globals.pvt_lock);
 
 	return SWITCH_STATUS_SUCCESS;
@@ -1317,7 +1289,7 @@
 			break;
 		}
 	}
- done:
+  done:
 	switch_mutex_unlock(globals.pvt_lock);
 
 	stream->write_function(stream, "Answered %d channels.\n", x);
@@ -1371,7 +1343,7 @@
 		goto bad;
 	}
 
- desc:
+  desc:
 	x = 0;
 	stream->write_function(stream, "FLAGS: ");
 	if (switch_test_flag((&globals), GFLAG_EAR)) {
@@ -1388,9 +1360,9 @@
 
 	goto done;
 
- bad:
+  bad:
 	stream->write_function(stream, "Usage: flags [on|off] <flags>\n");
- done:
+  done:
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -1487,12 +1459,9 @@
 
 		if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
 																  NULL,
-																  dialplan, cid_name, cid_num,
-																  ip, NULL, NULL, NULL, (char *) modname, NULL,
-																  dest)) != 0) {
+																  dialplan, cid_name, cid_num, ip, NULL, NULL, NULL, (char *) modname, NULL, dest)) != 0) {
 			char name[128];
-			snprintf(name, sizeof(name), "Alsa/%s",
-					 tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile->destination_number : modname);
+			snprintf(name, sizeof(name), "Alsa/%s", tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile->destination_number : modname);
 			switch_channel_set_name(channel, name);
 
 			switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
@@ -1504,7 +1473,7 @@
 			switch_channel_set_state(channel, CS_INIT);
 
 			if (switch_core_session_thread_launch(tech_pvt->session) != SWITCH_STATUS_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n");
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n");
 				switch_core_session_destroy(&session);
 				stream->write_function(stream, "FAIL:Thread Error!\n");
 			} else {
@@ -1536,7 +1505,7 @@
 		http = switch_event_get_header(stream->param_event, "http-host");
 	}
 
-	
+
 	const char *usage_string = "USAGE:\n"
 		"--------------------------------------------------------------------------------\n"
 		"alsa help\n"
@@ -1546,8 +1515,7 @@
 		"alsa list\n"
 		"alsa switch [<call_id>|none]\n"
 		"alsa dtmf <digit string>\n"
-		"alsa flags [on|off] [ear] [mouth]\n"
-		"--------------------------------------------------------------------------------\n";
+		"alsa flags [on|off] [ear] [mouth]\n" "--------------------------------------------------------------------------------\n";
 
 	if (http) {
 #if 0
@@ -1638,14 +1606,13 @@
 		stream->write_function(stream, "Unknown Command [%s]\n", argv[0]);
 	}
 
- done:
+  done:
 
 	if (http) {
 
 		stream->write_function(stream,
 							   "<br><br><table align=center><tr><td><center><form method=post>\n"
 							   "<input type=text name=wcmd size=40><br><br>\n"
-
 							   "<input name=action type=submit value=\"call\"> "
 							   "<input name=action type=submit value=\"hangup\"> "
 							   "<input name=action type=submit value=\"list\"> "
@@ -1658,25 +1625,18 @@
 							   "<td><input name=action type=submit value=\"2\"></td>"
 							   "<td><input name=action type=submit value=\"3\"></td>\n"
 							   "<td><input name=action type=submit value=\"A\"></td></tr>\n"
-
 							   "<tr><td><input name=action type=submit value=\"4\"></td>"
 							   "<td><input name=action type=submit value=\"5\"></td>"
 							   "<td><input name=action type=submit value=\"6\"></td>\n"
 							   "<td><input name=action type=submit value=\"B\"></td></tr>\n"
-
 							   "<tr><td><input name=action type=submit value=\"7\"></td>"
 							   "<td><input name=action type=submit value=\"8\"></td>"
 							   "<td><input name=action type=submit value=\"9\"></td>\n"
 							   "<td><input name=action type=submit value=\"C\"></td></tr>\n"
-
 							   "<tr><td><input name=action type=submit value=\"*\"></td>"
 							   "<td><input name=action type=submit value=\"0\"></td>"
 							   "<td><input name=action type=submit value=\"#\"></td>\n"
-							   "<td><input name=action type=submit value=\"D\"></td></tr>\n"
-							   "</table>"
-							   
-							   "</form><br></center></td></tr></table>\n"
-							   );
+							   "<td><input name=action type=submit value=\"D\"></td></tr>\n" "</table>" "</form><br></center></td></tr></table>\n");
 	}
 
 

Modified: freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c	Tue May 27 00:54:52 2008
@@ -53,11 +53,7 @@
 
 static char sub_sql[] =
 	"CREATE TABLE jabber_subscriptions (\n"
-	"   sub_from      VARCHAR(255),\n" 
-	"   sub_to        VARCHAR(255),\n" 
-	"   show_pres     VARCHAR(255),\n" 
-	"   status        VARCHAR(255)\n"
-	");\n";
+	"   sub_from      VARCHAR(255),\n" "   sub_to        VARCHAR(255),\n" "   show_pres     VARCHAR(255),\n" "   status        VARCHAR(255)\n" ");\n";
 
 
 typedef enum {
@@ -215,9 +211,9 @@
 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 ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlsession, ldl_signal_t dl_signal,
+static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsession, ldl_signal_t dl_signal,
 									char *to, char *from, char *subject, char *msg);
-static ldl_status handle_response(ldl_handle_t * handle, char *id);
+static ldl_status handle_response(ldl_handle_t *handle, char *id);
 static switch_status_t load_config(void);
 static int sin_callback(void *pArg, int argc, char **argv, char **columnNames);
 
@@ -270,9 +266,8 @@
 	if (mutex) {
 		switch_mutex_lock(mutex);
 	}
-
 #ifdef SWITCH_HAVE_ODBC
-    if (profile->odbc_dsn) {
+	if (profile->odbc_dsn) {
 		SQLHSTMT stmt;
 		if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
 			char *err_str;
@@ -292,11 +287,11 @@
 		switch_core_db_close(db);
 
 #ifdef SWITCH_HAVE_ODBC
-    }
+	}
 #endif
 
 
- end:
+  end:
 	if (mutex) {
 		switch_mutex_unlock(mutex);
 	}
@@ -304,22 +299,18 @@
 
 
 static switch_bool_t mdl_execute_sql_callback(mdl_profile_t *profile,
-											  switch_mutex_t *mutex,
-											  char *sql,
-											  switch_core_db_callback_func_t callback,
-											  void *pdata)
+											  switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback, void *pdata)
 {
 	switch_bool_t ret = SWITCH_FALSE;
 	switch_core_db_t *db;
 	char *errmsg = NULL;
-	
-	if (mutex) {
-        switch_mutex_lock(mutex);
-    }
 
+	if (mutex) {
+		switch_mutex_lock(mutex);
+	}
 
 #ifdef SWITCH_HAVE_ODBC
-    if (profile->odbc_dsn) {
+	if (profile->odbc_dsn) {
 		switch_odbc_handle_callback_exec(profile->master_odbc, sql, callback, pdata);
 	} else {
 #endif
@@ -331,7 +322,7 @@
 			goto end;
 		}
 
-	
+
 		switch_core_db_exec(db, sql, callback, pdata, &errmsg);
 
 		if (errmsg) {
@@ -342,18 +333,17 @@
 		if (db) {
 			switch_core_db_close(db);
 		}
-
 #ifdef SWITCH_HAVE_ODBC
-    }
+	}
 #endif
 
 
- end:
+  end:
 
 	if (mutex) {
-        switch_mutex_unlock(mutex);
-    }
-	
+		switch_mutex_unlock(mutex);
+	}
+
 
 
 	return ret;
@@ -418,11 +408,11 @@
 	char *rpid = switch_event_get_header(event, "rpid");
 	char *type = switch_event_get_header(event, "event_subtype");
 	char *sql;
-    
-    if (globals.running != 1) {
-        return;
-    }
-    
+
+	if (globals.running != 1) {
+		return;
+	}
+
 	if (!proto) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Missing 'proto' header\n");
 		return;
@@ -481,7 +471,8 @@
 	}
 
 
-	sql = switch_mprintf("select sub_from, sub_to,'%q','%q','%q','%q' from jabber_subscriptions where sub_to like '%%%q'", type, rpid, status, proto, from);
+	sql =
+		switch_mprintf("select sub_from, sub_to,'%q','%q','%q','%q' from jabber_subscriptions where sub_to like '%%%q'", type, rpid, status, proto, from);
 
 
 	for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
@@ -495,7 +486,7 @@
 
 		if (sql) {
 			switch_bool_t worked = mdl_execute_sql_callback(profile, profile->mutex, sql, sub_callback, profile);
-			
+
 			if (!worked) {
 				continue;
 			}
@@ -564,9 +555,9 @@
 	void *val;
 	char *sql;
 
-    if (globals.running != 1) {
-        return;
-    }
+	if (globals.running != 1) {
+		return;
+	}
 
 	if (status && !strcasecmp(status, "n/a")) {
 		status = NULL;
@@ -697,7 +688,7 @@
 
 		tech_pvt = switch_core_session_get_private(*session);
 
-		
+
 		if (tech_pvt && tech_pvt->profile && tech_pvt->profile->ip && tech_pvt->local_port) {
 			switch_rtp_release_port(tech_pvt->profile->ip, tech_pvt->local_port);
 		}
@@ -748,8 +739,7 @@
 						xml = switch_xml_parse_str(xmltxt, strlen(xmltxt));
 						form = switch_xml_toxml(xml, SWITCH_FALSE);
 						switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, level,
-										  "%s:\n-------------------------------------------------------------------------------\n"
-										  "%s\n", ll, form);
+										  "%s:\n-------------------------------------------------------------------------------\n" "%s\n", ll, form);
 						switch_xml_free(xml);
 						free(data);
 					}
@@ -774,8 +764,7 @@
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO codecs?\n");
 				return 0;
 			}
-		} else if (((tech_pvt->num_codecs =
-					 switch_loadable_module_get_codecs(tech_pvt->codecs, SWITCH_MAX_CODECS))) <= 0) {
+		} else if (((tech_pvt->num_codecs = switch_loadable_module_get_codecs(tech_pvt->codecs, SWITCH_MAX_CODECS))) <= 0) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO codecs?\n");
 			return 0;
 		}
@@ -786,7 +775,7 @@
 
 
 
-static void *SWITCH_THREAD_FUNC handle_thread_run(switch_thread_t * thread, void *obj)
+static void *SWITCH_THREAD_FUNC handle_thread_run(switch_thread_t *thread, void *obj)
 {
 	ldl_handle_t *handle = obj;
 	mdl_profile_t *profile = NULL;
@@ -805,7 +794,7 @@
 	return NULL;
 }
 
-static void handle_thread_launch(ldl_handle_t * handle)
+static void handle_thread_launch(ldl_handle_t *handle)
 {
 	switch_thread_t *thread;
 	switch_threadattr_t *thd_attr = NULL;
@@ -873,7 +862,7 @@
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SETUP RTP %s:%d -> %s:%d\n", tech_pvt->profile->ip,
 					  tech_pvt->local_port, tech_pvt->remote_ip, tech_pvt->remote_port);
-	
+
 	flags = SWITCH_RTP_FLAG_DATAWAIT | SWITCH_RTP_FLAG_GOOGLEHACK | SWITCH_RTP_FLAG_AUTOADJ | SWITCH_RTP_FLAG_RAW_WRITE | SWITCH_RTP_FLAG_AUTO_CNG;
 
 	if (switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) {
@@ -1089,8 +1078,7 @@
 	while (!(switch_test_flag(tech_pvt, TFLAG_CODEC_READY) &&
 			 switch_test_flag(tech_pvt, TFLAG_RTP_READY) &&
 			 switch_test_flag(tech_pvt, TFLAG_ANSWER) && switch_test_flag(tech_pvt, TFLAG_TRANSPORT_ACCEPT) &&
-			 tech_pvt->remote_ip && tech_pvt->remote_port
-			 && switch_test_flag(tech_pvt, TFLAG_TRANSPORT))) {
+			 tech_pvt->remote_ip && tech_pvt->remote_port && switch_test_flag(tech_pvt, TFLAG_TRANSPORT))) {
 		now = switch_timestamp_now();
 		elapsed = (unsigned int) ((now - started) / 1000);
 
@@ -1140,9 +1128,9 @@
 
 	goto done;
 
- out:
+  out:
 	terminate_session(&session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
- done:
+  done:
 
 	return ret;
 }
@@ -1222,7 +1210,7 @@
 	/* Dunno why, but if googletalk calls us for the first time, as soon as the call ends
 	   they think we are offline for no reason so we send this presence packet to stop it from happening
 	   We should find out why.....
-	*/
+	 */
 	if ((tech_pvt->profile->user_flags & LDL_FLAG_COMPONENT) && is_special(tech_pvt->them)) {
 		ldl_handle_send_presence(tech_pvt->profile->handle, tech_pvt->them, tech_pvt->us, NULL, NULL, "Click To Call", tech_pvt->profile->avatar);
 	}
@@ -1497,21 +1485,21 @@
 		break;
 	case SWITCH_MESSAGE_INDICATE_BRIDGE:
 		/*
-		if (tech_pvt->rtp_session && switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) {
-			switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "De-activate timed RTP!\n");
-			//switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_TIMER_RECLOCK);
-		}
-		*/
+		   if (tech_pvt->rtp_session && switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) {
+		   switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
+		   switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "De-activate timed RTP!\n");
+		   //switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_TIMER_RECLOCK);
+		   }
+		 */
 		break;
 	case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
 		/*
-		if (tech_pvt->rtp_session && switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) {
-			switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-activate timed RTP!\n");
-			//switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_TIMER_RECLOCK);
-		}
-		*/
+		   if (tech_pvt->rtp_session && switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) {
+		   switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
+		   switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-activate timed RTP!\n");
+		   //switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_TIMER_RECLOCK);
+		   }
+		 */
 		break;
 	default:
 		break;
@@ -1618,7 +1606,7 @@
 			} else {
 				if (!user) {
 					const char *id_num;
-					
+
 					if (!(id_num = outbound_profile->caller_id_number)) {
 						if (!(id_num = outbound_profile->caller_id_name)) {
 							id_num = "nobody";
@@ -1810,7 +1798,7 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static ldl_status handle_loop(ldl_handle_t * handle)
+static ldl_status handle_loop(ldl_handle_t *handle)
 {
 	if (!globals.running) {
 		return LDL_STATUS_FALSE;
@@ -1829,7 +1817,7 @@
 
 	if (!(profile->login && profile->password && profile->dialplan && profile->message && profile->ip && profile->name && profile->exten)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-						  "Invalid Profile\n" "login[%s]\n" "pass[%s]\n" "dialplan[%s]\n" 
+						  "Invalid Profile\n" "login[%s]\n" "pass[%s]\n" "dialplan[%s]\n"
 						  "message[%s]\n" "rtp-ip[%s]\n" "name[%s]\n" "exten[%s]\n",
 						  profile->login, profile->password, profile->dialplan, profile->message, profile->ip, profile->name, profile->exten);
 
@@ -1886,7 +1874,8 @@
 
 static void set_profile_val(mdl_profile_t *profile, char *var, char *val)
 {
-	if (!var) return;
+	if (!var)
+		return;
 
 	if (!strcasecmp(var, "login")) {
 		profile->login = switch_core_strdup(module_pool, val);
@@ -1903,8 +1892,7 @@
 				*profile->odbc_pass++ = '\0';
 			}
 		}
-		
-		
+
 #else
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
 #endif
@@ -1912,7 +1900,7 @@
 		switch_set_flag(profile, TFLAG_TIMER);
 	} else if (!strcasecmp(var, "dialplan") && !switch_strlen_zero(val)) {
 		profile->dialplan = switch_core_strdup(module_pool, val);
-#ifdef AUTO_REPLY // gotta fix looping on this
+#ifdef AUTO_REPLY				// gotta fix looping on this
 	} else if (!strcasecmp(var, "auto-reply")) {
 		profile->auto_reply = switch_core_strdup(module_pool, val);
 #endif
@@ -2182,7 +2170,7 @@
 				if (!(profile->master_odbc = switch_odbc_handle_new(profile->odbc_dsn, profile->odbc_user, profile->odbc_pass))) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
 					continue;
-					
+
 				}
 				if (switch_odbc_handle_connect(profile->master_odbc) != SWITCH_ODBC_SUCCESS) {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
@@ -2292,7 +2280,7 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
 	}
 
- end:
+  end:
 
 	switch_event_destroy(&params);
 
@@ -2307,8 +2295,7 @@
 	switch_safe_free(xmlstr);
 }
 
-static ldl_status handle_signalling(ldl_handle_t * handle, ldl_session_t * dlsession, ldl_signal_t dl_signal, char *to, char *from, char *subject,
-									char *msg)
+static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsession, ldl_signal_t dl_signal, char *to, char *from, char *subject, char *msg)
 {
 	mdl_profile_t *profile = NULL;
 	switch_core_session_t *session = NULL;
@@ -2350,11 +2337,8 @@
 						mdl_execute_sql(profile, sql, NULL);
 						switch_core_db_free(sql);
 					}
-					if ((sql = switch_mprintf("insert into jabber_subscriptions values('%q','%q','%q','%q');\n", 
-											  switch_str_nil(from),
-											  switch_str_nil(to),
-											  switch_str_nil(msg),
-											  switch_str_nil(subject)))) {
+					if ((sql = switch_mprintf("insert into jabber_subscriptions values('%q','%q','%q','%q');\n",
+											  switch_str_nil(from), switch_str_nil(to), switch_str_nil(msg), switch_str_nil(subject)))) {
 						mdl_execute_sql(profile, sql, NULL);
 						switch_core_db_free(sql);
 					}
@@ -2362,7 +2346,8 @@
 					if (is_special(to)) {
 						ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call", profile->avatar);
 					} else {
-						ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Authenticated.\nCome to ClueCon!\nhttp://www.cluecon.com", profile->avatar);
+						ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Authenticated.\nCome to ClueCon!\nhttp://www.cluecon.com",
+												 profile->avatar);
 					}
 #if 0
 					if (is_special(to)) {
@@ -2400,7 +2385,7 @@
 				break;
 			case LDL_SIGNAL_PRESENCE_IN:
 
-				if ((sql = switch_mprintf("update jabber_subscriptions set show_pres='%q', status='%q' where sub_from='%q'", 
+				if ((sql = switch_mprintf("update jabber_subscriptions set show_pres='%q', status='%q' where sub_from='%q'",
 										  switch_str_nil(msg), switch_str_nil(subject), switch_str_nil(from)))) {
 					mdl_execute_sql(profile, sql, profile->mutex);
 					switch_core_db_free(sql);
@@ -2435,7 +2420,7 @@
 
 			case LDL_SIGNAL_PRESENCE_OUT:
 
-				if ((sql = switch_mprintf("update jabber_subscriptions set show_pres='%q', status='%q' where sub_from='%q'", 
+				if ((sql = switch_mprintf("update jabber_subscriptions set show_pres='%q', status='%q' where sub_from='%q'",
 										  switch_str_nil(msg), switch_str_nil(subject), switch_str_nil(from)))) {
 					mdl_execute_sql(profile, sql, profile->mutex);
 					switch_core_db_free(sql);
@@ -2454,45 +2439,45 @@
 
 		switch (dl_signal) {
 		case LDL_SIGNAL_MSG:{
-			switch_chat_interface_t *ci;
-			char *proto = MDL_CHAT_PROTO;
-			char *pproto = NULL, *ffrom = NULL;
-			char *hint;
+				switch_chat_interface_t *ci;
+				char *proto = MDL_CHAT_PROTO;
+				char *pproto = NULL, *ffrom = NULL;
+				char *hint;
 #ifdef AUTO_REPLY
-			if (profile->auto_reply) {
-				ldl_handle_send_msg(handle,
-									(profile->user_flags & LDL_FLAG_COMPONENT) ? to : ldl_handle_get_login(profile->handle), from, "",
-									profile->auto_reply);
-			}
+				if (profile->auto_reply) {
+					ldl_handle_send_msg(handle,
+										(profile->user_flags & LDL_FLAG_COMPONENT) ? to : ldl_handle_get_login(profile->handle), from, "",
+										profile->auto_reply);
+				}
 #endif
 
-			if (strchr(to, '+')) {
-				pproto = strdup(to);
-				if ((to = strchr(pproto, '+'))) {
-					*to++ = '\0';
+				if (strchr(to, '+')) {
+					pproto = strdup(to);
+					if ((to = strchr(pproto, '+'))) {
+						*to++ = '\0';
+					}
+					proto = pproto;
 				}
-				proto = pproto;
-			}
 
-			hint = from;
+				hint = from;
 
-			if (strchr(from, '/') && (ffrom = strdup(from))) {
-				char *p;
-				if ((p = strchr(ffrom, '/'))) {
-					*p = '\0';
+				if (strchr(from, '/') && (ffrom = strdup(from))) {
+					char *p;
+					if ((p = strchr(ffrom, '/'))) {
+						*p = '\0';
+					}
+					from = ffrom;
 				}
-				from = ffrom;
-			}
 
-			if ((ci = switch_loadable_module_get_chat_interface(proto))) {
-				ci->chat_send(MDL_CHAT_PROTO, from, to, subject, msg, hint);
-			} else {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", proto);
-			}
+				if ((ci = switch_loadable_module_get_chat_interface(proto))) {
+					ci->chat_send(MDL_CHAT_PROTO, from, to, subject, msg, hint);
+				} else {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Chat Interface [%s]!\n", proto);
+				}
 
-			switch_safe_free(pproto);
-			switch_safe_free(ffrom);
-		}
+				switch_safe_free(pproto);
+				switch_safe_free(ffrom);
+			}
 			break;
 		case LDL_SIGNAL_LOGIN_SUCCESS:
 			if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, DL_EVENT_LOGIN_SUCCESS) == SWITCH_STATUS_SUCCESS) {
@@ -2547,7 +2532,7 @@
 		}
 		if ((session = switch_core_session_request(dingaling_endpoint_interface, NULL)) != 0) {
 			switch_core_session_add_stream(session, NULL);
-			
+
 			if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
 				char *exten;
 				char *context;
@@ -2641,10 +2626,7 @@
 																			  ldl_session_get_ip(dlsession),
 																			  ldl_session_get_value(dlsession, "ani"),
 																			  ldl_session_get_value(dlsession, "aniii"),
-																			  ldl_session_get_value(dlsession, "rdnis"),
-																			  modname,
-																			  context,
-																			  exten)) != 0) {
+																			  ldl_session_get_value(dlsession, "rdnis"), modname, context, exten)) != 0) {
 						char name[128];
 						switch_snprintf(name, sizeof(name), "DingaLing/%s", tech_pvt->caller_profile->destination_number);
 						switch_channel_set_name(channel, name);
@@ -2669,8 +2651,8 @@
 			if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n");
 				terminate_session(&session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-                status = LDL_STATUS_FALSE;
-                goto done;
+				status = LDL_STATUS_FALSE;
+				goto done;
 			}
 		} else {
 			status = LDL_STATUS_FALSE;
@@ -2832,7 +2814,7 @@
 			}
 
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%u candidates\n", len);
-			
+
 			if (profile->acl_count) {
 				for (x = 0; x < len; x++) {
 					uint32_t y = 0;
@@ -2843,18 +2825,18 @@
 						}
 
 						if (ok) {
-							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "candidate %s:%d PASS ACL %s\n", 
+							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "candidate %s:%d PASS ACL %s\n",
 											  candidates[x].address, candidates[x].port, profile->acl[y]);
 							break;
 						} else {
-							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "candidate %s:%d FAIL ACL %s\n", 
+							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "candidate %s:%d FAIL ACL %s\n",
 											  candidates[x].address, candidates[x].port, profile->acl[y]);
 						}
 					}
 				}
 			} else {
 				for (x = 0; x < len; x++) {
-					
+
 					if (profile->lanaddr) {
 						lanaddr = strncasecmp(candidates[x].address, profile->lanaddr, strlen(profile->lanaddr)) ? 0 : 1;
 					}
@@ -2879,9 +2861,8 @@
 									   strncasecmp(candidates[x].address, "172.2", 5) &&
 									   strncasecmp(candidates[x].address, "172.30.", 7) &&
 									   strncasecmp(candidates[x].address, "172.31.", 7) &&
-									   strncasecmp(candidates[x].address, "192.0.2.", 8) &&
-									   strncasecmp(candidates[x].address, "169.254.", 8)
-									   ))) {
+									   strncasecmp(candidates[x].address, "192.0.2.", 8) && strncasecmp(candidates[x].address, "169.254.", 8)
+						 ))) {
 						choice = x;
 						ok = 1;
 					}
@@ -2893,7 +2874,7 @@
 
 				memset(payloads, 0, sizeof(payloads));
 
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, 
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
 								  "Acceptable Candidate %s:%d\n", candidates[choice].address, candidates[choice].port);
 
 				if (!switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
@@ -2934,7 +2915,7 @@
 				status = LDL_STATUS_SUCCESS;
 			}
 
-			goto done;				
+			goto done;
 
 		}
 		break;
@@ -2961,14 +2942,14 @@
 		break;
 	}
 
-	
- done:
+
+  done:
 
 
 	return status;
 }
 
-static ldl_status handle_response(ldl_handle_t * handle, char *id)
+static ldl_status handle_response(ldl_handle_t *handle, char *id)
 {
 	return LDL_STATUS_SUCCESS;
 }

Modified: freeswitch/trunk/src/mod/endpoints/mod_iax/iax-mutex.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_iax/iax-mutex.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_iax/iax-mutex.c	Tue May 27 00:54:52 2008
@@ -47,7 +47,7 @@
 #endif
 	mutex_t *check = NULL;
 
-	check = (mutex_t *)malloc(sizeof(**mutex));
+	check = (mutex_t *) malloc(sizeof(**mutex));
 	if (!check)
 		goto done;
 #ifdef WIN32
@@ -64,16 +64,16 @@
 
 	goto success;
 
-fail:
-        pthread_mutexattr_destroy(&attr);
-		goto done;
+  fail:
+	pthread_mutexattr_destroy(&attr);
+	goto done;
 
-success:
+  success:
 #endif
 	*mutex = check;
 	status = MUTEX_SUCCESS;
 
-done:
+  done:
 	return status;
 }
 

Modified: freeswitch/trunk/src/mod/endpoints/mod_iax/iax.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_iax/iax.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_iax/iax.c	Tue May 27 00:54:52 2008
@@ -1,16 +1,16 @@
  /*
- * libiax: An implementation of Inter-Asterisk eXchange
- *
- * Copyright (C) 2001, Linux Support Services, Inc.
- *
- * Mark Spencer <markster at linux-support.net>
- *
- * This program is free software, distributed under the terms of
- * the GNU Lesser (Library) General Public License
- */
- 
+  * libiax: An implementation of Inter-Asterisk eXchange
+  *
+  * Copyright (C) 2001, Linux Support Services, Inc.
+  *
+  * Mark Spencer <markster at linux-support.net>
+  *
+  * This program is free software, distributed under the terms of
+  * the GNU Lesser (Library) General Public License
+  */
+
 #ifdef	WIN32
-#undef __STRICT_ANSI__ //for strdup with ms
+#undef __STRICT_ANSI__			//for strdup with ms
 
 #include <string.h>
 #include <process.h>
@@ -35,7 +35,7 @@
 #define strdup _strdup
 #endif
 
-void gettimeofday(struct timeval *tv, void /*struct timezone*/ *tz);
+void gettimeofday(struct timeval *tv, void /*struct timezone */ *tz);
 #include "winpoop.h"
 
 #else
@@ -56,7 +56,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <time.h>
-       
+
 #endif
 
 #include "iax2.h"
@@ -79,13 +79,13 @@
 /* Define socket options for IAX2 sockets, based on platform
  * availability of flags */
 #ifdef WIN32
- #define IAX_SOCKOPTS 0
+#define IAX_SOCKOPTS 0
 #else
- #ifdef LINUX
- #define IAX_SOCKOPTS MSG_DONTWAIT | MSG_NOSIGNAL
- #else
- #define IAX_SOCKOPTS MSG_DONTWAIT
- #endif
+#ifdef LINUX
+#define IAX_SOCKOPTS MSG_DONTWAIT | MSG_NOSIGNAL
+#else
+#define IAX_SOCKOPTS MSG_DONTWAIT
+#endif
 #endif
 
 
@@ -141,12 +141,12 @@
 static int maxretries = 10;
 
 /* configurable jitterbuffer options */
-static long jb_target_extra = -1; 
+static long jb_target_extra = -1;
 
 static int do_shutdown = 0;
 
 /* external global networking replacements */
-static sendto_t	  iax_sendto = (sendto_t) sendto;
+static sendto_t iax_sendto = (sendto_t) sendto;
 static recvfrom_t iax_recvfrom = (recvfrom_t) recvfrom;
 
 /* ping interval (seconds) */
@@ -162,7 +162,7 @@
 	int quelch;
 	/* Codec Pref Order */
 	char codec_order[32];
-	/* Codec Pref Order Index*/
+	/* Codec Pref Order Index */
 	int codec_order_len;
 	/* Last received voice format */
 	int voiceformat;
@@ -238,14 +238,14 @@
 
 	/* ping scheduler id */
 	int pingid;
-	
+
 	/* Transfer stuff */
 	struct sockaddr_in transfer;
 	int transferring;
 	int transfercallno;
 	int transferid;
-	int transferpeer;	/* for attended transfer */
-	int transfer_moh;	/* for music on hold while performing attended transfer */
+	int transferpeer;			/* for attended transfer */
+	int transfer_moh;			/* for music on hold while performing attended transfer */
 
 #ifdef NEWJB
 	jitterbuf *jb;
@@ -261,7 +261,7 @@
 
 static void destroy_session(struct iax_session *session);
 
-#define IAXERROR snprintf(iax_errstr, sizeof(iax_errstr), 
+#define IAXERROR snprintf(iax_errstr, sizeof(iax_errstr),
 
 #ifdef DEBUG_SUPPORT
 
@@ -281,15 +281,15 @@
 	debug = 0;
 }
 
-/* This is a little strange, but to debug you call DEBU(G "Hello World!\n"); */ 
+/* This is a little strange, but to debug you call DEBU(G "Hello World!\n"); */
 #ifdef WIN32
-#define G __FILE__, __LINE__, __FUNCTION__, 
+#define G __FILE__, __LINE__, __FUNCTION__,
 #else
-#define G __FILE__, __LINE__, (const char *)__func__, 
+#define G __FILE__, __LINE__, (const char *)__func__,
 #endif
 
-#define DEBU __debug 
-static int __debug(char *file, int lineno, const char *func, char *fmt, ...) 
+#define DEBU __debug
+static int __debug(char *file, int lineno, const char *func, char *fmt, ...)
 {
 	va_list args;
 	va_start(args, fmt);
@@ -311,7 +311,7 @@
 #define G
 #endif
 
-typedef void (*sched_func)(void *);
+typedef void (*sched_func) (void *);
 
 struct iax_sched {
 	/* These are scheduled things to be delivered */
@@ -396,16 +396,16 @@
 	/* Schedule event to be delivered to the client
 	   in ms milliseconds from now, or a reliable frame to be retransmitted */
 	struct iax_sched *sched, *cur, *prev = NULL;
-	
+
 	if (!event && !frame && !func) {
 		DEBU(G "No event, no frame, no func?  what are we scheduling?\n");
 		return -1;
 	}
-	
 
-	sched = (struct iax_sched*)malloc(sizeof(struct iax_sched));
+
+	sched = (struct iax_sched *) malloc(sizeof(struct iax_sched));
 	if (sched) {
-        memset(sched, 0, sizeof(struct iax_sched));
+		memset(sched, 0, sizeof(struct iax_sched));
 		sched->when = current_time_in_ms() + ms;
 		sched->event = event;
 		sched->frame = frame;
@@ -414,7 +414,7 @@
 		/* Put it in the list, in order */
 		iax_mutex_lock(sched_mutex);
 		cur = schedq;
-		while(cur && cur->when <= sched->when) {
+		while (cur && cur->when <= sched->when) {
 			prev = cur;
 			cur = cur->next;
 		}
@@ -446,7 +446,7 @@
 			else
 				schedq = cur->next;
 			tmp = cur;
-			cur = cur->next;	
+			cur = cur->next;
 			free(tmp);
 			if (!all) {
 				ret = -1;
@@ -457,7 +457,7 @@
 			cur = cur->next;
 		}
 	}
- done:
+  done:
 	iax_mutex_unlock(sched_mutex);
 
 	return 0;
@@ -469,7 +469,7 @@
 {
 	struct iax_sched *cur = NULL;
 	time_in_ms_t minimum = 999999999;
-	
+
 	iax_mutex_lock(sched_mutex);
 	cur = schedq;
 
@@ -478,7 +478,7 @@
 		iax_mutex_unlock(sched_mutex);
 		return -1;
 	}
-	while(cur) {
+	while (cur) {
 		if (cur->when < minimum) {
 			minimum = cur->when;
 		}
@@ -498,7 +498,7 @@
 struct iax_session *iax_session_new(void)
 {
 	struct iax_session *s;
-	s = (struct iax_session *)malloc(sizeof(struct iax_session));
+	s = (struct iax_session *) malloc(sizeof(struct iax_session));
 	if (s) {
 		memset(s, 0, sizeof(struct iax_session));
 		/* Initialize important fields */
@@ -507,12 +507,12 @@
 		/* Default pingtime to 30 ms */
 		s->pingtime = 30;
 		/* XXX Not quite right -- make sure it's not in use, but that won't matter
-	           unless you've had at least 65k calls.  XXX */
+		   unless you've had at least 65k calls.  XXX */
 		s->callno = callnums++;
 		if (callnums > 32767)
 			callnums = 1;
 		s->peercallno = 0;
-		s->transferpeer = 0;		/* for attended transfer */
+		s->transferpeer = 0;	/* for attended transfer */
 
 		s->sendto = iax_sendto;
 		s->pingid = -1;
@@ -542,7 +542,7 @@
 
 	iax_mutex_lock(session_mutex);
 	cur = sessions;
-	while(cur) {
+	while (cur) {
 		if (session == cur) {
 			iax_mutex_unlock(session_mutex);
 			return -1;
@@ -554,31 +554,34 @@
 	return 0;
 }
 
-int iax_get_netstats(struct iax_session *session, time_in_ms_t *rtt, struct iax_netstat *local, struct iax_netstat *remote) {
+int iax_get_netstats(struct iax_session *session, time_in_ms_t *rtt, struct iax_netstat *local, struct iax_netstat *remote)
+{
 
-  if(!iax_session_valid(session)) return -1;
+	if (!iax_session_valid(session))
+		return -1;
 
-  *rtt = session->pingtime;
+	*rtt = session->pingtime;
 
-  *remote = session->remote_netstats;
+	*remote = session->remote_netstats;
 
 #ifdef NEWJB
-  {
-      jb_info stats;
-      jb_getinfo(session->jb, &stats);
-
-      local->jitter = stats.jitter;
-      /* XXX: should be short-term loss pct.. */
-      if(stats.frames_in == 0) stats.frames_in = 1;
-      local->losspct = stats.losspct/1000;
-      local->losscnt = stats.frames_lost;
-      local->packets = stats.frames_in;
-      local->delay = stats.current - stats.min;
-      local->dropped = stats.frames_dropped;
-      local->ooo = stats.frames_ooo;
-  }
+	{
+		jb_info stats;
+		jb_getinfo(session->jb, &stats);
+
+		local->jitter = stats.jitter;
+		/* XXX: should be short-term loss pct.. */
+		if (stats.frames_in == 0)
+			stats.frames_in = 1;
+		local->losspct = stats.losspct / 1000;
+		local->losscnt = stats.frames_lost;
+		local->packets = stats.frames_in;
+		local->delay = stats.current - stats.min;
+		local->dropped = stats.frames_dropped;
+		local->ooo = stats.frames_ooo;
+	}
 #endif
-  return 0;
+	return 0;
 }
 
 static time_in_ms_t calc_timestamp(struct iax_session *session, time_in_ms_t ts, struct ast_frame *f)
@@ -587,13 +590,13 @@
 	time_in_ms_t time_in_ms;
 	int voice = 0;
 	int genuine = 0;
-	
+
 	if (f && f->frametype == AST_FRAME_VOICE) {
 		voice = 1;
 	} else if (!f || f->frametype == AST_FRAME_IAX) {
 		genuine = 1;
 	}
-	
+
 	/* If this is the first packet we're sending, get our
 	   offset now. */
 	if (!session->offset) {
@@ -616,34 +619,34 @@
 		ms = 0;
 	}
 
-	if(voice) {
+	if (voice) {
 #ifdef USE_VOICE_TS_PREDICTION
 
 		/* If we haven't most recently sent silence, and we're
 		 * close in time, use predicted time */
-		if(session->notsilenttx && iax_abs(ms - session->nextpred) <= 240) {
-		    /* Adjust our txcore, keeping voice and non-voice
-		     * synchronized */
-			session->offset += (int)(ms - session->nextpred)/10;
-		    
-		    if(!session->nextpred) {
-				session->nextpred = ms; 
+		if (session->notsilenttx && iax_abs(ms - session->nextpred) <= 240) {
+			/* Adjust our txcore, keeping voice and non-voice
+			 * synchronized */
+			session->offset += (int) (ms - session->nextpred) / 10;
+
+			if (!session->nextpred) {
+				session->nextpred = ms;
 			}
-		    ms = session->nextpred; 
+			ms = session->nextpred;
 		} else {
-		    /* in this case, just use the actual time, since
-		     * we're either way off (shouldn't happen), or we're
-		     * ending a silent period -- and seed the next predicted
-		     * time.  Also, round ms to the next multiple of
-		     * frame size (so our silent periods are multiples
-		     * of frame size too) */
-		    time_in_ms_t diff = ms % (f->samples / 8);
-		    if(diff)
-			ms += f->samples/8 - diff;
-		    session->nextpred = ms; 
+			/* in this case, just use the actual time, since
+			 * we're either way off (shouldn't happen), or we're
+			 * ending a silent period -- and seed the next predicted
+			 * time.  Also, round ms to the next multiple of
+			 * frame size (so our silent periods are multiples
+			 * of frame size too) */
+			time_in_ms_t diff = ms % (f->samples / 8);
+			if (diff)
+				ms += f->samples / 8 - diff;
+			session->nextpred = ms;
 		}
 #else
-		if(ms <= session->lastsent)
+		if (ms <= session->lastsent)
 			ms = session->lastsent + 3;
 #endif
 		session->notsilenttx = 1;
@@ -656,7 +659,7 @@
 		} else if (iax_abs(ms - session->lastsent) <= 240) {
 			ms = session->lastsent + 3;
 		}
-	      
+
 	}
 
 	/* Record the last sent packet for future reference */
@@ -666,8 +669,8 @@
 
 #ifdef USE_VOICE_TS_PREDICTION
 	/* set next predicted ts based on 8khz samples */
-	if(voice)
-	    session->nextpred = session->nextpred + f->samples / 8;
+	if (voice)
+		session->nextpred = session->nextpred + f->samples / 8;
 #endif
 
 	return ms;
@@ -676,44 +679,42 @@
 #ifdef NEWJB
 static unsigned char get_n_bits_at(unsigned char *data, int n, int bit)
 {
-	int byte = bit / 8;       /* byte containing first bit */
-	int rem = 8 - (bit % 8);  /* remaining bits in first byte */
+	int byte = bit / 8;			/* byte containing first bit */
+	int rem = 8 - (bit % 8);	/* remaining bits in first byte */
 	unsigned char ret = 0;
-	
+
 	if (n <= 0 || n > 8)
 		return 0;
 
 	if (rem < n) {
-		ret = (unsigned char)(data[byte] << (n - rem));
+		ret = (unsigned char) (data[byte] << (n - rem));
 		ret |= (data[byte + 1] >> (8 - n + rem));
 	} else {
-		ret = (unsigned char)(data[byte] >> (rem - n));
+		ret = (unsigned char) (data[byte] >> (rem - n));
 	}
 
-	return (unsigned char)(ret & (0xff >> (8 - n)));
+	return (unsigned char) (ret & (0xff >> (8 - n)));
 }
 
 static int speex_get_wb_sz_at(unsigned char *data, int len, int bit)
 {
 	static int SpeexWBSubModeSz[] = {
 		0, 36, 112, 192,
-		352, 0, 0, 0 };
+		352, 0, 0, 0
+	};
 	int off = bit;
 	unsigned char c;
 
 	/* skip up to two wideband frames */
-	if (((len * 8 - off) >= 5) && 
-		get_n_bits_at(data, 1, off)) {
+	if (((len * 8 - off) >= 5) && get_n_bits_at(data, 1, off)) {
 		c = get_n_bits_at(data, 3, off + 1);
 		off += SpeexWBSubModeSz[c];
 
-		if (((len * 8 - off) >= 5) && 
-			get_n_bits_at(data, 1, off)) {
+		if (((len * 8 - off) >= 5) && get_n_bits_at(data, 1, off)) {
 			c = get_n_bits_at(data, 3, off + 1);
 			off += SpeexWBSubModeSz[c];
 
-			if (((len * 8 - off) >= 5) && 
-				get_n_bits_at(data, 1, off)) {
+			if (((len * 8 - off) >= 5) && get_n_bits_at(data, 1, off)) {
 				/* too many in a row */
 				DEBU(G "\tCORRUPT too many wideband streams in a row\n");
 				return -1;
@@ -727,15 +728,17 @@
 static int speex_get_samples(unsigned char *data, int len)
 {
 	static int SpeexSubModeSz[] = {
-		0, 43, 119, 160, 
-		220, 300, 364, 492, 
+		0, 43, 119, 160,
+		220, 300, 364, 492,
 		79, 0, 0, 0,
-		0, 0, 0, 0 };
-	static int SpeexInBandSz[] = { 
+		0, 0, 0, 0
+	};
+	static int SpeexInBandSz[] = {
 		1, 1, 4, 4,
 		4, 4, 4, 4,
 		8, 8, 16, 16,
-		32, 32, 64, 64 };
+		32, 32, 64, 64
+	};
 	int bit = 0;
 	int cnt = 0;
 	int off = 0;
@@ -745,7 +748,7 @@
 	while ((len * 8 - bit) >= 5) {
 		/* skip wideband frames */
 		off = speex_get_wb_sz_at(data, len, bit);
-		if (off < 0)  {
+		if (off < 0) {
 			DEBU(G "\tERROR reading wideband frames\n");
 			break;
 		}
@@ -761,7 +764,7 @@
 		DEBU(G "\tCONTROL: %d at %d\n", c, bit);
 		bit += 5;
 
-		if (c == 15) { 
+		if (c == 15) {
 			DEBU(G "\tTERMINATOR\n");
 			break;
 		} else if (c == 14) {
@@ -784,7 +787,7 @@
 			DEBU(G "\tSUBMODE %d %d bits\n", c, SpeexSubModeSz[c]);
 			bit += SpeexSubModeSz[c] - 5;
 
-			cnt += 160; /* new frame */
+			cnt += 160;			/* new frame */
 		}
 	}
 	DEBU(G "\tSAMPLES: %d\n", cnt);
@@ -803,42 +806,42 @@
 	/*
 	 * In the case of zero length frames, do not return a cnt of 0
 	 */
-	if ( e->datalen == 0 ) {
-		return get_interp_len( e->subclass ) * 8;
+	if (e->datalen == 0) {
+		return get_interp_len(e->subclass) * 8;
 	}
 
 	switch (e->subclass) {
-	  case AST_FORMAT_SPEEX:
-	    cnt = speex_get_samples(e->data, e->datalen);
-	    break;
-	  case AST_FORMAT_G723_1:
-	    cnt = 240;		/* FIXME Not always the case */
-	    break;
-	  case AST_FORMAT_ILBC:
-	    cnt = 240 * (e->datalen / 50);
-	    break;
-	  case AST_FORMAT_GSM:
-	    cnt = 160 * (e->datalen / 33);
-	    break;
-	  case AST_FORMAT_G729A:
-	    cnt = 160 * (e->datalen / 20);
-	    break;
-	  case AST_FORMAT_SLINEAR:
-	    cnt = e->datalen / 2;
-	    break;
-	  case AST_FORMAT_LPC10:
-	    cnt = 22 * 8 + (((char *)(e->data))[7] & 0x1) * 8;
-	    break;
-	  case AST_FORMAT_ULAW:
-	  case AST_FORMAT_ALAW:
-	    cnt = e->datalen;
-	    break;
-	  case AST_FORMAT_ADPCM:
-	  case AST_FORMAT_G726:
-	    cnt = e->datalen * 2;
-	    break;
-	  default:
-	    return 0;
+	case AST_FORMAT_SPEEX:
+		cnt = speex_get_samples(e->data, e->datalen);
+		break;
+	case AST_FORMAT_G723_1:
+		cnt = 240;				/* FIXME Not always the case */
+		break;
+	case AST_FORMAT_ILBC:
+		cnt = 240 * (e->datalen / 50);
+		break;
+	case AST_FORMAT_GSM:
+		cnt = 160 * (e->datalen / 33);
+		break;
+	case AST_FORMAT_G729A:
+		cnt = 160 * (e->datalen / 20);
+		break;
+	case AST_FORMAT_SLINEAR:
+		cnt = e->datalen / 2;
+		break;
+	case AST_FORMAT_LPC10:
+		cnt = 22 * 8 + (((char *) (e->data))[7] & 0x1) * 8;
+		break;
+	case AST_FORMAT_ULAW:
+	case AST_FORMAT_ALAW:
+		cnt = e->datalen;
+		break;
+	case AST_FORMAT_ADPCM:
+	case AST_FORMAT_G726:
+		cnt = e->datalen * 2;
+		break;
+	default:
+		return 0;
 	}
 	return cnt;
 }
@@ -850,16 +853,13 @@
 #ifdef DEBUG_SUPPORT
 	struct ast_iax2_full_hdr *h = (f->data);
 	if (ntohs(h->scallno) & IAX_FLAG_FULL)
-		iax_showframe(f, NULL, 0, f->transfer ? 
-						&(f->session->transfer) :
-					&(f->session->peeraddr), f->datalen - sizeof(struct ast_iax2_full_hdr));
+		iax_showframe(f, NULL, 0, f->transfer ? &(f->session->transfer) : &(f->session->peeraddr), f->datalen - sizeof(struct ast_iax2_full_hdr));
 #endif
 
 	return f->session->sendto(netfd, (const char *) f->data, f->datalen,
-		IAX_SOCKOPTS,
-					f->transfer ? 
-						(struct sockaddr *)&(f->session->transfer) :
-					(struct sockaddr *)&(f->session->peeraddr), sizeof(f->session->peeraddr));
+							  IAX_SOCKOPTS,
+							  f->transfer ?
+							  (struct sockaddr *) &(f->session->transfer) : (struct sockaddr *) &(f->session->peeraddr), sizeof(f->session->peeraddr));
 }
 
 static int iax_reliable_xmit(struct iax_frame *f)
@@ -869,9 +869,9 @@
 	fh = (struct ast_iax2_full_hdr *) f->data;
 	if (!fh->type) {
 		DEBU(G "Asked to reliably transmit a non-packet.  Crashing.\n");
-		*((char *)0)=0;
+		*((char *) 0) = 0;
 	}
-	fc = (struct iax_frame *)malloc(sizeof(struct iax_frame));
+	fc = (struct iax_frame *) malloc(sizeof(struct iax_frame));
 	if (fc) {
 		/* Make a copy of the frame */
 		memcpy(fc, f, sizeof(struct iax_frame));
@@ -881,7 +881,7 @@
 			DEBU(G "No frame data?\n");
 			return -1;
 		} else {
-			fc->data = (char *)malloc(fc->datalen);
+			fc->data = (char *) malloc(fc->datalen);
 			if (!fc->data) {
 				DEBU(G "Out of memory\n");
 				IAXERROR "Out of memory\n");
@@ -895,40 +895,38 @@
 		return -1;
 }
 
-void iax_set_networking(sendto_t st, recvfrom_t rf)
-{
+void iax_set_networking(sendto_t st, recvfrom_t rf) {
 
 	init_time();
 	iax_sendto = st;
 	iax_recvfrom = rf;
 }
 
-int __iax_shutdown(void)
-{
+int __iax_shutdown(void) {
 	struct iax_sched *sp, *fp;
 
 	/* Hangup Calls */
 	if (sessions) {
 		struct iax_session *sp = NULL, *fp = NULL;
-		iax_mutex_lock(session_mutex); 
-		for(sp = sessions; sp ;) {
+		iax_mutex_lock(session_mutex);
+		for (sp = sessions; sp;) {
 			iax_hangup(sp, "System Shutdown");
 			fp = sp;
 			sp = sp->next;
 			destroy_session(fp);
 		}
-		iax_mutex_unlock(session_mutex); 
+		iax_mutex_unlock(session_mutex);
 	}
 
 	/* Clear Scheduler */
 	iax_mutex_lock(sched_mutex);
-	for(sp = schedq; sp ;) {
+	for (sp = schedq; sp;) {
 		fp = sp;
 		sp = sp->next;
 		free(fp);
 	}
 	iax_mutex_unlock(sched_mutex);
-	
+
 	if (netfd > -1) {
 		shutdown(netfd, 2);
 		close(netfd);
@@ -942,19 +940,16 @@
 	return 0;
 }
 
-int iax_shutdown(void)
-{
+int iax_shutdown(void) {
 	return do_shutdown++;
 }
 
-void iax_set_jb_target_extra( long value )
-{
+void iax_set_jb_target_extra(long value) {
 	/* store in jb_target_extra, a static global */
-	jb_target_extra = value ;
+	jb_target_extra = value;
 }
 
-int iax_init(char *ip, int preferredportno)
-{
+int iax_init(char *ip, int preferredportno) {
 	int portno = preferredportno;
 	struct sockaddr_in sin;
 #ifdef WIN32
@@ -969,102 +964,98 @@
 	iax_mutex_create(&sched_mutex);
 	iax_mutex_create(&session_mutex);
 
-	if(iax_recvfrom == (recvfrom_t) recvfrom) {
-	    if (netfd > -1) {
-		    /* Sokay, just don't do anything */
-		    DEBU(G "Already initialized.");
-		    return 0;
-	    }
-	    netfd = (int)socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
-	    if (netfd < 0) {
-		    DEBU(G "Unable to allocate UDP socket\n");
-		    IAXERROR "Unable to allocate UDP socket\n");
-		    return -1;
-	    }
-	    
-	    if (preferredportno == 0) preferredportno = IAX_DEFAULT_PORTNO;
-		if (preferredportno < 0)  preferredportno = 0;
+	if (iax_recvfrom == (recvfrom_t) recvfrom) {
+		if (netfd > -1) {
+			/* Sokay, just don't do anything */
+			DEBU(G "Already initialized.");
+			return 0;
+		}
+		netfd = (int) socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
+		if (netfd < 0) {
+			DEBU(G "Unable to allocate UDP socket\n");
+			IAXERROR "Unable to allocate UDP socket\n");
+			return -1;
+		}
+
+		if (preferredportno == 0)
+			preferredportno = IAX_DEFAULT_PORTNO;
+		if (preferredportno < 0)
+			preferredportno = 0;
 
 		sin.sin_family = AF_INET;
 		sin.sin_addr.s_addr = 0;
-		sin.sin_port = htons((short)preferredportno);
-		if (bind(netfd, (struct sockaddr *) &sin, sizeof(sin)) < 0) 
-		{
+		sin.sin_port = htons((short) preferredportno);
+		if (bind(netfd, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
 #if defined(WIN32)  ||  defined(_WIN32_WCE)
 			if (WSAGetLastError() == WSAEADDRINUSE)
 #else
 			if (errno == EADDRINUSE)
 #endif
 			{
-				/*the port is already in use, so bind to a free port chosen by the IP stack*/
+				/*the port is already in use, so bind to a free port chosen by the IP stack */
 				DEBU(G "Unable to bind to preferred port - port is in use. Trying to bind to a free one");
-				sin.sin_port = htons((short)0);
-				if (bind(netfd, (struct sockaddr *) &sin, sizeof(sin)) < 0)
-				{
+				sin.sin_port = htons((short) 0);
+				if (bind(netfd, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
 					IAXERROR "Unable to bind UDP socket\n");
 					return -1;
 				}
-			} else
-			{
+			} else {
 				IAXERROR "Unable to bind UDP socket\n");
 				return -1;
 			}
 		}
 		sinlen = sizeof(sin);
-	    if (getsockname(netfd, (struct sockaddr *) &sin, &sinlen) < 0) {
-		    close(netfd);
-		    netfd = -1;
-		    DEBU(G "Unable to figure out what I'm bound to.");
-		    IAXERROR "Unable to determine bound port number.");
-	    }
+		if (getsockname(netfd, (struct sockaddr *) &sin, &sinlen) < 0) {
+			close(netfd);
+			netfd = -1;
+			DEBU(G "Unable to figure out what I'm bound to.");
+			IAXERROR "Unable to determine bound port number.");
+		}
 #ifdef	WIN32
-	    flags = 1;
-	    if (ioctlsocket(netfd,FIONBIO,(unsigned long *) &flags)) {
-		    closesocket(netfd);
-		    netfd = -1;
-		    DEBU(G "Unable to set non-blocking mode.");
-		    IAXERROR "Unable to set non-blocking mode.");
-	    }
-	    
+		flags = 1;
+		if (ioctlsocket(netfd, FIONBIO, (unsigned long *) &flags)) {
+			closesocket(netfd);
+			netfd = -1;
+			DEBU(G "Unable to set non-blocking mode.");
+			IAXERROR "Unable to set non-blocking mode.");
+		}
 #else
-	    if ((flags = fcntl(netfd, F_GETFL)) < 0) {
-		    close(netfd);
-		    netfd = -1;
-		    DEBU(G "Unable to retrieve socket flags.");
-		    IAXERROR "Unable to retrieve socket flags.");
-	    }
-	    if (fcntl(netfd, F_SETFL, flags | O_NONBLOCK) < 0) {
-		    close(netfd);
-		    netfd = -1;
-		    DEBU(G "Unable to set non-blocking mode.");
-		    IAXERROR "Unable to set non-blocking mode.");
-	    }
+		if ((flags = fcntl(netfd, F_GETFL)) < 0) {
+			close(netfd);
+			netfd = -1;
+			DEBU(G "Unable to retrieve socket flags.");
+			IAXERROR "Unable to retrieve socket flags.");
+		}
+		if (fcntl(netfd, F_SETFL, flags | O_NONBLOCK) < 0) {
+			close(netfd);
+			netfd = -1;
+			DEBU(G "Unable to set non-blocking mode.");
+			IAXERROR "Unable to set non-blocking mode.");
+		}
 #endif
-	    portno = ntohs(sin.sin_port);
+		portno = ntohs(sin.sin_port);
 	}
-	srand((unsigned int)time(NULL));
+	srand((unsigned int) time(NULL));
 	callnums = rand() % 32767 + 1;
 	transfer_id = rand() % 32767 + 1;
 	DEBU(G "Started on port %d\n", portno);
-	return portno;	
+	return portno;
 }
 
 
 
-static void convert_reply(char *out, unsigned char *in)
-{
+static void convert_reply(char *out, unsigned char *in) {
 	int x;
-	for (x=0;x<16;x++)
-		out += sprintf(out, "%2.2x", (int)in[x]);
+	for (x = 0; x < 16; x++)
+		out += sprintf(out, "%2.2x", (int) in[x]);
 }
 
-static unsigned char compress_subclass(int subclass)
-{
+static unsigned char compress_subclass(int subclass) {
 	int x;
-	int power=-1;
+	int power = -1;
 	/* If it's 128 or smaller, just return it */
 	if (subclass < IAX_FLAG_SC_LOG)
-		return (unsigned char)subclass;
+		return (unsigned char) subclass;
 	/* Otherwise find its power */
 	for (x = 0; x < IAX_MAX_SHIFT; x++) {
 		if (subclass & (1 << x)) {
@@ -1075,45 +1066,45 @@
 				power = x;
 		}
 	}
-	return (unsigned char)(power | IAX_FLAG_SC_LOG);
+	return (unsigned char) (power | IAX_FLAG_SC_LOG);
 }
 
-static int iax_send(struct iax_session *pvt, struct ast_frame *f, time_in_ms_t ts, int seqno, int now, int transfer, int final) 
-{
+static int iax_send(struct iax_session *pvt, struct ast_frame *f, time_in_ms_t ts, int seqno, int now, int transfer, int final) {
 	/* Queue a packet for delivery on a given private structure.  Use "ts" for
 	   timestamp, or calculate if ts is 0.  Send immediately without retransmission
 	   or delayed, with retransmission */
 	struct ast_iax2_full_hdr *fh;
 	struct ast_iax2_mini_hdr *mh;
-	unsigned char	buf[5120];
+	unsigned char buf[5120];
 	struct iax_frame *fr;
 	int res;
-	int sendmini=0;
+	int sendmini = 0;
 	time_in_ms_t lastsent;
 	time_in_ms_t fts;
-	
+
 	if (!pvt) {
 		IAXERROR "No private structure for packet?\n");
 		return -1;
 	}
-	
+
 	/* this must come before the next call to calc_timestamp() since
-	 calc_timestamp() will change lastsent to the returned value */
+	   calc_timestamp() will change lastsent to the returned value */
 	lastsent = pvt->lastsent;
 
 	/* Calculate actual timestamp */
 	fts = calc_timestamp(pvt, ts, f);
 
 	if (((fts & 0xFFFF0000L) == (lastsent & 0xFFFF0000L))
-		/* High two bits are the same on timestamp, or sending on a trunk */ &&
-	    (f->frametype == AST_FRAME_VOICE) 
-		/* is a voice frame */ &&
-		(f->subclass == pvt->svoiceformat) 
-		/* is the same type */ ) {
-			/* Force immediate rather than delayed transmission */
-			now = 1;
-			/* Mark that mini-style frame is appropriate */
-			sendmini = 1;
+		/* High two bits are the same on timestamp, or sending on a trunk */
+		&& (f->frametype == AST_FRAME_VOICE)
+		/* is a voice frame */
+		&& (f->subclass == pvt->svoiceformat)
+		/* is the same type */
+		) {
+		/* Force immediate rather than delayed transmission */
+		now = 1;
+		/* Mark that mini-style frame is appropriate */
+		sendmini = 1;
 	}
 	/* Allocate an iax_frame */
 	if (now) {
@@ -1135,7 +1126,7 @@
 		return -1;
 	}
 
-	fr->callno = (unsigned short)pvt->callno;
+	fr->callno = (unsigned short) pvt->callno;
 	fr->transfer = transfer;
 	fr->final = final;
 	fr->session = pvt;
@@ -1146,22 +1137,22 @@
 		else
 			fr->oseqno = pvt->oseqno++;
 		fr->iseqno = pvt->iseqno;
-		fh = (struct ast_iax2_full_hdr *)(((char *)fr->af.data) - sizeof(struct ast_iax2_full_hdr));
+		fh = (struct ast_iax2_full_hdr *) (((char *) fr->af.data) - sizeof(struct ast_iax2_full_hdr));
 		fh->scallno = htons(fr->callno | IAX_FLAG_FULL);
-		fh->ts = htonl((long)(fr->ts));
-		fh->oseqno = (unsigned char)fr->oseqno;
+		fh->ts = htonl((long) (fr->ts));
+		fh->oseqno = (unsigned char) fr->oseqno;
 		if (transfer) {
 			fh->iseqno = 0;
 		} else
-			fh->iseqno = (unsigned char)fr->iseqno;
+			fh->iseqno = (unsigned char) fr->iseqno;
 		/* Keep track of the last thing we've acknowledged */
-		pvt->aseqno = (unsigned char)fr->iseqno;
-		fh->type = (char)(fr->af.frametype & 0xFF);
+		pvt->aseqno = (unsigned char) fr->iseqno;
+		fh->type = (char) (fr->af.frametype & 0xFF);
 		fh->csub = compress_subclass(fr->af.subclass);
 		if (transfer) {
-			fr->dcallno = (unsigned short)pvt->transfercallno;
+			fr->dcallno = (unsigned short) pvt->transfercallno;
 		} else
-			fr->dcallno = (unsigned short)pvt->peercallno;
+			fr->dcallno = (unsigned short) pvt->peercallno;
 		fh->dcallno = htons(fr->dcallno);
 		fr->datalen = fr->af.datalen + sizeof(struct ast_iax2_full_hdr);
 		fr->data = fh;
@@ -1187,22 +1178,21 @@
 		fr->oseqno = -1;
 		fr->iseqno = -1;
 		/* Mini frame will do */
-		mh = (struct ast_iax2_mini_hdr *)(((char *)fr->af.data) - sizeof(struct ast_iax2_mini_hdr));
+		mh = (struct ast_iax2_mini_hdr *) (((char *) fr->af.data) - sizeof(struct ast_iax2_mini_hdr));
 		mh->callno = htons(fr->callno);
-		mh->ts = htons((short)(fr->ts & 0xFFFF));
+		mh->ts = htons((short) (fr->ts & 0xFFFF));
 		fr->datalen = fr->af.datalen + sizeof(struct ast_iax2_mini_hdr);
 		fr->data = mh;
 		fr->retries = -1;
 		res = iax_xmit_frame(fr);
 	}
-	if( !now && fr!=NULL )
-	        iax_frame_free( fr ); 
+	if (!now && fr != NULL)
+		iax_frame_free(fr);
 	return res;
 }
 
 #if 0
-static int iax_predestroy(struct iax_session *pvt)
-{
+static int iax_predestroy(struct iax_session *pvt) {
 	if (!pvt) {
 		return -1;
 	}
@@ -1226,9 +1216,8 @@
 }
 #endif
 
-static int __send_command(struct iax_session *i, char type, int command, time_in_ms_t ts, unsigned char *data, int datalen, int seqno, 
-		int now, int transfer, int final, int samples)
-{
+static int __send_command(struct iax_session *i, char type, int command, time_in_ms_t ts, unsigned char *data, int datalen, int seqno,
+						  int now, int transfer, int final, int samples) {
 	struct ast_frame f;
 	f.frametype = type;
 	f.subclass = command;
@@ -1245,77 +1234,69 @@
 	return iax_send(i, &f, ts, seqno, now, transfer, final);
 }
 
-static int send_command(struct iax_session *i, char type, int command, time_in_ms_t ts, unsigned char *data, int datalen, int seqno)
-{
+static int send_command(struct iax_session *i, char type, int command, time_in_ms_t ts, unsigned char *data, int datalen, int seqno) {
 	return __send_command(i, type, command, ts, data, datalen, seqno, 0, 0, 0, 0);
 }
 
-static int send_command_final(struct iax_session *i, char type, int command, unsigned int ts, unsigned char *data, int datalen, int seqno)
-{
+static int send_command_final(struct iax_session *i, char type, int command, unsigned int ts, unsigned char *data, int datalen, int seqno) {
 #if 0
 	/* It is assumed that the callno has already been locked */
 	iax_predestroy(i);
-#endif	
+#endif
 	int r;
 	r = __send_command(i, type, command, ts, data, datalen, seqno, 0, 0, 1, 0);
 	if (r >= 0) {
-		iax_mutex_lock(session_mutex); 
+		iax_mutex_lock(session_mutex);
 		destroy_session(i);
 		iax_mutex_unlock(session_mutex);
 	}
 	return r;
 }
 
-static int send_command_immediate(struct iax_session *i, char type, int command, unsigned int ts, unsigned char *data, int datalen, int seqno)
-{
+static int send_command_immediate(struct iax_session *i, char type, int command, unsigned int ts, unsigned char *data, int datalen, int seqno) {
 	return __send_command(i, type, command, ts, data, datalen, seqno, 1, 0, 0, 0);
 }
 
-static int send_command_transfer(struct iax_session *i, char type, int command, unsigned int ts, unsigned char *data, int datalen)
-{
+static int send_command_transfer(struct iax_session *i, char type, int command, unsigned int ts, unsigned char *data, int datalen) {
 	return __send_command(i, type, command, ts, data, datalen, 0, 0, 1, 0, 0);
 }
 
-static int send_command_samples(struct iax_session *i, char type, int command, unsigned int ts, unsigned char *data, int datalen, int seqno, int samples)
-{
+static int send_command_samples(struct iax_session *i, char type, int command, unsigned int ts, unsigned char *data, int datalen, int seqno, int samples) {
 	return __send_command(i, type, command, ts, data, datalen, seqno, 0, 0, 0, samples);
 }
 
 
-int iax_transfer(struct iax_session *session, char *number)
-{	
+int iax_transfer(struct iax_session *session, char *number) {
 	static int res;				//Return Code
-	struct iax_ie_data ied;			//IE Data Structure (Stuff To Send)
+	struct iax_ie_data ied;		//IE Data Structure (Stuff To Send)
 
 	// Clear The Memory Used For IE Buffer
 	memset(&ied, 0, sizeof(ied));
-	
+
 	// Copy The Transfer Destination Into The IE Structure
 	iax_ie_append_str(&ied, IAX_IE_CALLED_NUMBER, (unsigned char *) number);
-	
-	// Send The Transfer Command - Asterisk Will Handle The Rest!			
+
+	// Send The Transfer Command - Asterisk Will Handle The Rest!           
 	res = send_command(session, AST_FRAME_IAX, IAX_COMMAND_TRANSFER, 0, ied.buf, ied.pos, -1);
-	
+
 	// Return Success
-	return 0;	
+	return 0;
 }
 
-static void stop_transfer(struct iax_session *session)
-{
+static void stop_transfer(struct iax_session *session) {
 	struct iax_sched *sch;
 
 	iax_mutex_lock(sched_mutex);
 	sch = schedq;
-	while(sch) {
+	while (sch) {
 		if (sch->frame && (sch->frame->session == session))
-					sch->frame->retries = -1;
+			sch->frame->retries = -1;
 		sch = sch->next;
 	}
 	iax_mutex_unlock(sched_mutex);
-}	/* stop_transfer */
+}								/* stop_transfer */
 
-static void complete_transfer(struct iax_session *session, int peercallno, int xfr2peer, int preserveSeq)
-{
+static void complete_transfer(struct iax_session *session, int peercallno, int xfr2peer, int preserveSeq) {
 	session->peercallno = peercallno;
 	/* Change from transfer to session now */
 	if (xfr2peer) {
@@ -1331,20 +1312,19 @@
 	session->rxcore = session->offset = 0;
 	memset(&session->history, 0, sizeof(session->history));
 #ifdef NEWJB
-	{ /* Reset jitterbuffer */
-	    jb_frame frame;
-	    while(jb_getall(session->jb,&frame) == JB_OK) 
-		iax_event_free(frame.data);
-	
-	    jb_reset(session->jb);
+	{							/* Reset jitterbuffer */
+		jb_frame frame;
+		while (jb_getall(session->jb, &frame) == JB_OK)
+			iax_event_free(frame.data);
+
+		jb_reset(session->jb);
 	}
 #endif
 	session->jitterbuffer = 0;
 	session->jitter = 0;
 	session->lag = 0;
 
-	if (! preserveSeq)
-	{
+	if (!preserveSeq) {
 		/* Reset sequence numbers */
 		session->aseqno = 0;
 		session->oseqno = 0;
@@ -1358,10 +1338,9 @@
 	/* We have to dump anything we were going to (re)transmit now that we've been
 	   transferred since they're all invalid and for the old host. */
 	stop_transfer(session);
-}	/* complete_transfer */
+}								/* complete_transfer */
 
-int iax_setup_transfer(struct iax_session *org_session, struct iax_session *new_session)
-{
+int iax_setup_transfer(struct iax_session *org_session, struct iax_session *new_session) {
 	int res;
 	struct iax_ie_data ied0;
 	struct iax_ie_data ied1;
@@ -1374,11 +1353,11 @@
 
 	/* reversed setup */
 	iax_ie_append_addr(&ied0, IAX_IE_APPARENT_ADDR, &s1->peeraddr);
-	iax_ie_append_short(&ied0, IAX_IE_CALLNO, (unsigned short)s1->peercallno);
+	iax_ie_append_short(&ied0, IAX_IE_CALLNO, (unsigned short) s1->peercallno);
 	iax_ie_append_int(&ied0, IAX_IE_TRANSFERID, transfer_id);
 
 	iax_ie_append_addr(&ied1, IAX_IE_APPARENT_ADDR, &s0->peeraddr);
-	iax_ie_append_short(&ied1, IAX_IE_CALLNO, (unsigned short)s0->peercallno);
+	iax_ie_append_short(&ied1, IAX_IE_CALLNO, (unsigned short) s0->peercallno);
 	iax_ie_append_int(&ied1, IAX_IE_TRANSFERID, transfer_id);
 
 	s0->transfer = s1->peeraddr;
@@ -1414,8 +1393,7 @@
 	return 0;
 }
 
-static int iax_finish_transfer(struct iax_session *s, short new_peer)
-{
+static int iax_finish_transfer(struct iax_session *s, short new_peer) {
 	int res;
 	struct iax_ie_data ied;
 
@@ -1431,28 +1409,26 @@
 
 }
 
-static struct iax_session *iax_find_session2(short callno)
-{
+static struct iax_session *iax_find_session2(short callno) {
 	struct iax_session *cur;
 
-	iax_mutex_lock(session_mutex); 
+	iax_mutex_lock(session_mutex);
 	cur = sessions;
-	while(cur) {
-		if (callno == cur->callno && callno != 0)  {
-			iax_mutex_unlock(session_mutex); 
+	while (cur) {
+		if (callno == cur->callno && callno != 0) {
+			iax_mutex_unlock(session_mutex);
 			return cur;
 		}
 		cur = cur->next;
 	}
-	iax_mutex_unlock(session_mutex); 
+	iax_mutex_unlock(session_mutex);
 
 	return NULL;
 }
 
-static int iax_handle_txready(struct iax_session *s)
-{
+static int iax_handle_txready(struct iax_session *s) {
 	struct iax_session *s0, *s1;
-	short	s0_org_peer, s1_org_peer;
+	short s0_org_peer, s1_org_peer;
 
 	if (s->transfer_moh) {
 		s->transfer_moh = 0;
@@ -1464,15 +1440,12 @@
 	s->transferring = TRANSFER_REL;
 
 	s0 = s;
-	s1 = iax_find_session2((short)s0->transferpeer);
+	s1 = iax_find_session2((short) s0->transferpeer);
 
-	if (s1 != NULL &&
-	    s1->callno == s0->transferpeer &&
-		 s0->transferring == TRANSFER_REL &&
-		 s1->transferring == TRANSFER_REL) {
+	if (s1 != NULL && s1->callno == s0->transferpeer && s0->transferring == TRANSFER_REL && s1->transferring == TRANSFER_REL) {
 
-		s0_org_peer = (short)s0->peercallno;
-		s1_org_peer = (short)s1->peercallno;
+		s0_org_peer = (short) s0->peercallno;
+		s1_org_peer = (short) s1->peercallno;
 
 		iax_finish_transfer(s0, s1_org_peer);
 		iax_finish_transfer(s1, s0_org_peer);
@@ -1482,15 +1455,12 @@
 	return 0;
 }
 
-static void iax_handle_txreject(struct iax_session *s)
-{
+static void iax_handle_txreject(struct iax_session *s) {
 	struct iax_session *s0, *s1;
 
 	s0 = s;
-	s1 = iax_find_session2((short)s0->transferpeer);
-	if (s1 != NULL &&
-		 s0->transferpeer == s1->callno &&
-		 s1->transferring) {
+	s1 = iax_find_session2((short) s0->transferpeer);
+	if (s1 != NULL && s0->transferpeer == s1->callno && s1->transferring) {
 		if (s1->transfer_moh) {
 			s1->transfer_moh = 0;
 			send_command_immediate(s1, AST_FRAME_IAX, IAX_COMMAND_UNQUELCH, 0, NULL, 0, s1->iseqno);
@@ -1507,15 +1477,14 @@
 	s->transfer_moh = 0;
 }
 
-static void destroy_session(struct iax_session *session)
-{
-	struct iax_session *cur, *prev=NULL;
-	struct iax_sched *curs, *prevs=NULL, *nexts=NULL;
-	int    loop_cnt=0;
+static void destroy_session(struct iax_session *session) {
+	struct iax_session *cur, *prev = NULL;
+	struct iax_sched *curs, *prevs = NULL, *nexts = NULL;
+	int loop_cnt = 0;
 
 	iax_mutex_lock(sched_mutex);
 	curs = schedq;
-	while(curs) {
+	while (curs) {
 		nexts = curs->next;
 		if (curs->frame && curs->frame->session == session) {
 			/* Just mark these frames as if they've been sent */
@@ -1535,10 +1504,10 @@
 		loop_cnt++;
 	}
 	iax_mutex_unlock(sched_mutex);
-	
+
 
 	cur = sessions;
-	while(cur) {
+	while (cur) {
 		if (cur == session) {
 			if (prev)
 				prev->next = session->next;
@@ -1546,11 +1515,11 @@
 				sessions = session->next;
 #ifdef NEWJB
 			{
-			    jb_frame frame;
-			    while(jb_getall(session->jb,&frame) == JB_OK) 
-				iax_event_free(frame.data);
-		   	
-			    jb_destroy(session->jb);
+				jb_frame frame;
+				while (jb_getall(session->jb, &frame) == JB_OK)
+					iax_event_free(frame.data);
+
+				jb_destroy(session->jb);
 			}
 #endif
 			free(session);
@@ -1564,15 +1533,14 @@
 static int iax_send_lagrp(struct iax_session *session, time_in_ms_t ts);
 static int iax_send_pong(struct iax_session *session, time_in_ms_t ts);
 
-static struct iax_event *handle_event(struct iax_event *event)
-{
+static struct iax_event *handle_event(struct iax_event *event) {
 	/* We have a candidate event to be delievered.  Be sure
 	   the session still exists. */
 	if (event) {
 		if (iax_session_valid(event->session)) {
 			/* Lag requests are never actually sent to the client, but
 			   other than that are handled as normal packets */
-			switch(event->etype) {
+			switch (event->etype) {
 				/* the user on the outside may need to look at the session so we will not free 
 				   it here anymore we will test for hangup event in iax_event_free and do it
 				   there.
@@ -1595,48 +1563,42 @@
 				iax_send_pong(event->session, event->ts);
 				iax_destroy(event->session);
 				iax_event_free(event);
-				break;         
+				break;
 			default:
 				return event;
 			}
-		} else 
+		} else
 			iax_event_free(event);
 	}
 	return NULL;
 }
 
-static int iax2_vnak(struct iax_session *session)
-{
+static int iax2_vnak(struct iax_session *session) {
 	return send_command_immediate(session, AST_FRAME_IAX, IAX_COMMAND_VNAK, 0, NULL, 0, session->iseqno);
 }
 
-int iax_send_dtmf(struct iax_session *session, char digit)
-{
+int iax_send_dtmf(struct iax_session *session, char digit) {
 	return send_command(session, AST_FRAME_DTMF, digit, 0, NULL, 0, -1);
 }
 
-int iax_send_voice(struct iax_session *session, int format, unsigned char *data, int datalen, int samples)
-{
+int iax_send_voice(struct iax_session *session, int format, unsigned char *data, int datalen, int samples) {
 	/* Send a (possibly compressed) voice frame */
 	if (!session->quelch)
 		return send_command_samples(session, AST_FRAME_VOICE, format, 0, data, datalen, -1, samples);
 	return 0;
 }
 
-int iax_send_cng(struct iax_session *session, int level, unsigned char *data, int datalen)
-{    
+int iax_send_cng(struct iax_session *session, int level, unsigned char *data, int datalen) {
 	session->notsilenttx = 0;
 	return send_command(session, AST_FRAME_CNG, level, 0, data, datalen, -1);
 }
 
-int iax_send_image(struct iax_session *session, int format, unsigned char *data, int datalen)
-{
+int iax_send_image(struct iax_session *session, int format, unsigned char *data, int datalen) {
 	/* Send an image frame */
 	return send_command(session, AST_FRAME_IMAGE, format, 0, data, datalen, -1);
 }
 
-int iax_register(struct iax_session *session, char *server, char *peer, char *secret, int refresh)
-{
+int iax_register(struct iax_session *session, char *server, char *peer, char *secret, int refresh) {
 	/* Send a registration request */
 	char tmp[256];
 	char *p;
@@ -1644,15 +1606,15 @@
 	int portno = IAX_DEFAULT_PORTNO;
 	struct iax_ie_data ied;
 	struct hostent *hp;
-	
+
 	tmp[255] = '\0';
 	strncpy(tmp, server, sizeof(tmp) - 1);
 	p = strchr(tmp, ':');
 	if (p) {
 		*p = '\0';
-		portno = atoi(p+1);
+		portno = atoi(p + 1);
 	}
-	
+
 	memset(&ied, 0, sizeof(ied));
 	if (secret)
 		strncpy(session->secret, secret, sizeof(session->secret) - 1);
@@ -1666,44 +1628,39 @@
 		return -1;
 	}
 	memcpy(&session->peeraddr.sin_addr, hp->h_addr, sizeof(session->peeraddr.sin_addr));
-	session->peeraddr.sin_port = htons((unsigned short)portno);
+	session->peeraddr.sin_port = htons((unsigned short) portno);
 	session->peeraddr.sin_family = AF_INET;
 	strncpy(session->username, peer, sizeof(session->username) - 1);
 	session->refresh = refresh;
 	iax_ie_append_str(&ied, IAX_IE_USERNAME, (unsigned char *) peer);
-	iax_ie_append_short(&ied, IAX_IE_REFRESH, (unsigned short)refresh);
+	iax_ie_append_short(&ied, IAX_IE_REFRESH, (unsigned short) refresh);
 	res = send_command(session, AST_FRAME_IAX, IAX_COMMAND_REGREQ, 0, ied.buf, ied.pos, -1);
 	return res;
 }
 
-int iax_reject_registration(struct iax_session *session, char *reason)
-{
+int iax_reject_registration(struct iax_session *session, char *reason) {
 	struct iax_ie_data ied;
 	memset(&ied, 0, sizeof(ied));
 	iax_ie_append_str(&ied, IAX_IE_CAUSE, reason ? (unsigned char *) reason : (unsigned char *) "Unspecified");
 	return send_command_final(session, AST_FRAME_IAX, IAX_COMMAND_REGREJ, 0, ied.buf, ied.pos, -1);
 }
 
-int iax_ack_registration(struct iax_session *session)
-{
+int iax_ack_registration(struct iax_session *session) {
 	return send_command_final(session, AST_FRAME_IAX, IAX_COMMAND_REGACK, 0, NULL, 0, -1);
 }
 
-int iax_auth_registration(struct iax_session *session)
-{
+int iax_auth_registration(struct iax_session *session) {
 	return send_command_final(session, AST_FRAME_IAX, IAX_COMMAND_REGAUTH, 0, NULL, 0, -1);
 }
 
-int iax_reject(struct iax_session *session, const char *reason)
-{
+int iax_reject(struct iax_session *session, const char *reason) {
 	struct iax_ie_data ied;
 	memset(&ied, 0, sizeof(ied));
 	iax_ie_append_str(&ied, IAX_IE_CAUSE, reason ? (unsigned char *) reason : (unsigned char *) "Unspecified");
 	return send_command_final(session, AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied.buf, ied.pos, -1);
 }
 
-int iax_hangup(struct iax_session *session, char *byemsg)
-{
+int iax_hangup(struct iax_session *session, char *byemsg) {
 	struct iax_ie_data ied;
 	iax_sched_del(NULL, NULL, send_ping, (void *) session, 1);
 	memset(&ied, 0, sizeof(ied));
@@ -1711,159 +1668,139 @@
 	return send_command_final(session, AST_FRAME_IAX, IAX_COMMAND_HANGUP, 0, ied.buf, ied.pos, -1);
 }
 
-int iax_sendurl(struct iax_session *session, char *url)
-{
-	return send_command(session, AST_FRAME_HTML, AST_HTML_URL, 0, (unsigned char *) url, (int)strlen(url), -1);
+int iax_sendurl(struct iax_session *session, char *url) {
+	return send_command(session, AST_FRAME_HTML, AST_HTML_URL, 0, (unsigned char *) url, (int) strlen(url), -1);
 }
 
-int iax_ring_announce(struct iax_session *session)
-{
+int iax_ring_announce(struct iax_session *session) {
 	return send_command(session, AST_FRAME_CONTROL, AST_CONTROL_RINGING, 0, NULL, 0, -1);
 }
 
-int iax_lag_request(struct iax_session *session)
-{
+int iax_lag_request(struct iax_session *session) {
 	return send_command(session, AST_FRAME_IAX, IAX_COMMAND_LAGRQ, 0, NULL, 0, -1);
 }
 
-int iax_busy(struct iax_session *session)
-{
+int iax_busy(struct iax_session *session) {
 	return send_command(session, AST_FRAME_CONTROL, AST_CONTROL_BUSY, 0, NULL, 0, -1);
 }
 
-int iax_congestion(struct iax_session *session)
-{
+int iax_congestion(struct iax_session *session) {
 	return send_command(session, AST_FRAME_CONTROL, AST_CONTROL_CONGESTION, 0, NULL, 0, -1);
 }
 
 
-int iax_accept(struct iax_session *session, int format)
-{
+int iax_accept(struct iax_session *session, int format) {
 	struct iax_ie_data ied;
 	memset(&ied, 0, sizeof(ied));
 	iax_ie_append_int(&ied, IAX_IE_FORMAT, format);
 	return send_command(session, AST_FRAME_IAX, IAX_COMMAND_ACCEPT, 0, ied.buf, ied.pos, -1);
 }
 
-int iax_answer(struct iax_session *session)
-{
+int iax_answer(struct iax_session *session) {
 	return send_command(session, AST_FRAME_CONTROL, AST_CONTROL_ANSWER, 0, NULL, 0, -1);
 }
 
-int iax_load_complete(struct iax_session *session)
-{
+int iax_load_complete(struct iax_session *session) {
 	return send_command(session, AST_FRAME_HTML, AST_HTML_LDCOMPLETE, 0, NULL, 0, -1);
 }
 
-int iax_send_url(struct iax_session *session, char *url, int link)
-{
-	return send_command(session, AST_FRAME_HTML, link ? AST_HTML_LINKURL : AST_HTML_URL, 0, (unsigned char *) url, (int)strlen(url), -1);
+int iax_send_url(struct iax_session *session, char *url, int link) {
+	return send_command(session, AST_FRAME_HTML, link ? AST_HTML_LINKURL : AST_HTML_URL, 0, (unsigned char *) url, (int) strlen(url), -1);
 }
 
-int iax_send_text(struct iax_session *session, char *text)
-{
-	return send_command(session, AST_FRAME_TEXT, 0, 0, (unsigned char *) text, (int)strlen(text) + 1, -1);
+int iax_send_text(struct iax_session *session, char *text) {
+	return send_command(session, AST_FRAME_TEXT, 0, 0, (unsigned char *) text, (int) strlen(text) + 1, -1);
 }
 
-int iax_send_unlink(struct iax_session *session)
-{
+int iax_send_unlink(struct iax_session *session) {
 	return send_command(session, AST_FRAME_HTML, AST_HTML_UNLINK, 0, NULL, 0, -1);
 }
 
-int iax_send_link_reject(struct iax_session *session)
-{
+int iax_send_link_reject(struct iax_session *session) {
 	return send_command(session, AST_FRAME_HTML, AST_HTML_LINKREJECT, 0, NULL, 0, -1);
 }
 
-static int iax_send_pong(struct iax_session *session, time_in_ms_t ts)
-{
-        struct iax_ie_data ied;
+static int iax_send_pong(struct iax_session *session, time_in_ms_t ts) {
+	struct iax_ie_data ied;
 
-        memset(&ied, 0, sizeof(ied));
+	memset(&ied, 0, sizeof(ied));
 #ifdef NEWJB
 	{
-	    jb_info stats;
-	    jb_getinfo(session->jb, &stats);
+		jb_info stats;
+		jb_getinfo(session->jb, &stats);
 
-	    iax_ie_append_int(&ied,IAX_IE_RR_JITTER, (int)stats.jitter);
-	    /* XXX: should be short-term loss pct.. */
-	    if(stats.frames_in == 0) stats.frames_in = 1;
-	    iax_ie_append_int(&ied,IAX_IE_RR_LOSS, 
-		((0xff & (stats.losspct/1000)) << 24 | (stats.frames_lost & 0x00ffffff)));
-	    iax_ie_append_int(&ied,IAX_IE_RR_PKTS, stats.frames_in);
-	    iax_ie_append_short(&ied,IAX_IE_RR_DELAY, (unsigned short)(stats.current - stats.min));
-	    iax_ie_append_int(&ied,IAX_IE_RR_DROPPED, stats.frames_dropped);
-	    iax_ie_append_int(&ied,IAX_IE_RR_OOO, stats.frames_ooo);
+		iax_ie_append_int(&ied, IAX_IE_RR_JITTER, (int) stats.jitter);
+		/* XXX: should be short-term loss pct.. */
+		if (stats.frames_in == 0)
+			stats.frames_in = 1;
+		iax_ie_append_int(&ied, IAX_IE_RR_LOSS, ((0xff & (stats.losspct / 1000)) << 24 | (stats.frames_lost & 0x00ffffff)));
+		iax_ie_append_int(&ied, IAX_IE_RR_PKTS, stats.frames_in);
+		iax_ie_append_short(&ied, IAX_IE_RR_DELAY, (unsigned short) (stats.current - stats.min));
+		iax_ie_append_int(&ied, IAX_IE_RR_DROPPED, stats.frames_dropped);
+		iax_ie_append_int(&ied, IAX_IE_RR_OOO, stats.frames_ooo);
 	}
 #else
-	    iax_ie_append_int(&ied,IAX_IE_RR_JITTER, session->jitter);
-	    /* don't know, don't send! iax_ie_append_int(&ied,IAX_IE_RR_LOSS, 0); */
-	    /* don't know, don't send! iax_ie_append_int(&ied,IAX_IE_RR_PKTS, stats.frames_in); */
-	    /* don't know, don't send! iax_ie_append_short(&ied,IAX_IE_RR_DELAY, stats.current - stats.min); */
+	iax_ie_append_int(&ied, IAX_IE_RR_JITTER, session->jitter);
+	/* don't know, don't send! iax_ie_append_int(&ied,IAX_IE_RR_LOSS, 0); */
+	/* don't know, don't send! iax_ie_append_int(&ied,IAX_IE_RR_PKTS, stats.frames_in); */
+	/* don't know, don't send! iax_ie_append_short(&ied,IAX_IE_RR_DELAY, stats.current - stats.min); */
 #endif
 
 	return send_command(session, AST_FRAME_IAX, IAX_COMMAND_PONG, ts, ied.buf, ied.pos, -1);
 }
 
 /* external API; deprecated since we send pings ourselves now (finally) */
-int iax_send_ping(struct iax_session *session)
-{
+int iax_send_ping(struct iax_session *session) {
 	return send_command(session, AST_FRAME_IAX, IAX_COMMAND_PING, 0, NULL, 0, -1);
 }
 
 /* scheduled ping sender; sends ping, then reschedules */
-static void send_ping(void *s)
-{
-	struct iax_session *session = (struct iax_session *)s;
+static void send_ping(void *s) {
+	struct iax_session *session = (struct iax_session *) s;
 
 	/* important, eh? */
-	if(!iax_session_valid(session)) return;
+	if (!iax_session_valid(session))
+		return;
 
 	send_command(session, AST_FRAME_IAX, IAX_COMMAND_PING, 0, NULL, 0, -1);
-	session->pingid = iax_sched_add(NULL,NULL, send_ping, (void *)session, ping_time * 1000);
+	session->pingid = iax_sched_add(NULL, NULL, send_ping, (void *) session, ping_time * 1000);
 	return;
 }
 
-static int iax_send_lagrp(struct iax_session *session, time_in_ms_t ts)
-{
+static int iax_send_lagrp(struct iax_session *session, time_in_ms_t ts) {
 	return send_command(session, AST_FRAME_IAX, IAX_COMMAND_LAGRP, ts, NULL, 0, -1);
 }
 
-static int iax_send_txcnt(struct iax_session *session)
-{
+static int iax_send_txcnt(struct iax_session *session) {
 	struct iax_ie_data ied;
 	memset(&ied, 0, sizeof(ied));
 	iax_ie_append_int(&ied, IAX_IE_TRANSFERID, session->transferid);
 	return send_command_transfer(session, AST_FRAME_IAX, IAX_COMMAND_TXCNT, 0, ied.buf, ied.pos);
 }
 
-static int iax_send_txrej(struct iax_session *session)
-{
+static int iax_send_txrej(struct iax_session *session) {
 	struct iax_ie_data ied;
 	memset(&ied, 0, sizeof(ied));
 	iax_ie_append_int(&ied, IAX_IE_TRANSFERID, session->transferid);
 	return send_command_transfer(session, AST_FRAME_IAX, IAX_COMMAND_TXREJ, 0, ied.buf, ied.pos);
 }
 
-static int iax_send_txaccept(struct iax_session *session)
-{
+static int iax_send_txaccept(struct iax_session *session) {
 	struct iax_ie_data ied;
 	memset(&ied, 0, sizeof(ied));
 	iax_ie_append_int(&ied, IAX_IE_TRANSFERID, session->transferid);
 	return send_command_transfer(session, AST_FRAME_IAX, IAX_COMMAND_TXACC, 0, ied.buf, ied.pos);
 }
 
-static int iax_send_txready(struct iax_session *session)
-{
+static int iax_send_txready(struct iax_session *session) {
 	struct iax_ie_data ied;
 	memset(&ied, 0, sizeof(ied));
 	/* see asterisk chan_iax2.c */
-	iax_ie_append_short(&ied, IAX_IE_CALLNO, (unsigned short)session->callno);
+	iax_ie_append_short(&ied, IAX_IE_CALLNO, (unsigned short) session->callno);
 	return send_command(session, AST_FRAME_IAX, IAX_COMMAND_TXREADY, 0, ied.buf, ied.pos, -1);
 }
 
-int iax_auth_reply(struct iax_session *session, char *password, char *challenge, int methods)
-{
+int iax_auth_reply(struct iax_session *session, char *password, char *challenge, int methods) {
 	char reply[16];
 	struct MD5Context md5;
 	char realreply[256];
@@ -1871,8 +1808,8 @@
 	memset(&ied, 0, sizeof(ied));
 	if ((methods & IAX_AUTH_MD5) && challenge) {
 		MD5Init(&md5);
-		MD5Update(&md5, (const unsigned char *) challenge, (unsigned int)strlen(challenge));
-		MD5Update(&md5, (const unsigned char *) password, (unsigned int)strlen(password));
+		MD5Update(&md5, (const unsigned char *) challenge, (unsigned int) strlen(challenge));
+		MD5Update(&md5, (const unsigned char *) password, (unsigned int) strlen(password));
 		MD5Final((unsigned char *) reply, &md5);
 		memset(realreply, 0, sizeof(realreply));
 		convert_reply(realreply, (unsigned char *) reply);
@@ -1883,19 +1820,18 @@
 	return send_command(session, AST_FRAME_IAX, IAX_COMMAND_AUTHREP, 0, ied.buf, ied.pos, -1);
 }
 
-static int iax_regauth_reply(struct iax_session *session, char *password, char *challenge, int methods)
-{
+static int iax_regauth_reply(struct iax_session *session, char *password, char *challenge, int methods) {
 	char reply[16];
 	struct MD5Context md5;
 	char realreply[256];
 	struct iax_ie_data ied;
 	memset(&ied, 0, sizeof(ied));
 	iax_ie_append_str(&ied, IAX_IE_USERNAME, (unsigned char *) session->username);
-	iax_ie_append_short(&ied, IAX_IE_REFRESH, (unsigned short)session->refresh);
+	iax_ie_append_short(&ied, IAX_IE_REFRESH, (unsigned short) session->refresh);
 	if ((methods & IAX_AUTHMETHOD_MD5) && challenge) {
 		MD5Init(&md5);
-		MD5Update(&md5, (const unsigned char *) challenge, (unsigned int)strlen(challenge));
-		MD5Update(&md5, (const unsigned char *) password, (unsigned int)strlen(password));
+		MD5Update(&md5, (const unsigned char *) challenge, (unsigned int) strlen(challenge));
+		MD5Update(&md5, (const unsigned char *) password, (unsigned int) strlen(password));
 		MD5Final((unsigned char *) reply, &md5);
 		memset(realreply, 0, sizeof(realreply));
 		convert_reply(realreply, (unsigned char *) reply);
@@ -1907,63 +1843,56 @@
 }
 
 
-int iax_dial(struct iax_session *session, char *number)
-{
+int iax_dial(struct iax_session *session, char *number) {
 	struct iax_ie_data ied;
 	memset(&ied, 0, sizeof(ied));
 	iax_ie_append_str(&ied, IAX_IE_CALLED_NUMBER, (unsigned char *) number);
 	return send_command(session, AST_FRAME_IAX, IAX_COMMAND_DIAL, 0, ied.buf, ied.pos, -1);
 }
 
-int iax_quelch(struct iax_session *session)
-{
+int iax_quelch(struct iax_session *session) {
 	return send_command(session, AST_FRAME_IAX, IAX_COMMAND_QUELCH, 0, NULL, 0, -1);
 }
 
-int iax_unquelch(struct iax_session *session)
-{
+int iax_unquelch(struct iax_session *session) {
 	return send_command(session, AST_FRAME_IAX, IAX_COMMAND_UNQUELCH, 0, NULL, 0, -1);
 }
 
-int iax_dialplan_request(struct iax_session *session, char *number)
-{
+int iax_dialplan_request(struct iax_session *session, char *number) {
 	struct iax_ie_data ied;
 	memset(&ied, 0, sizeof(ied));
 	iax_ie_append_str(&ied, IAX_IE_CALLED_NUMBER, (unsigned char *) number);
 	return send_command(session, AST_FRAME_IAX, IAX_COMMAND_DPREQ, 0, ied.buf, ied.pos, -1);
 }
 
-static inline int which_bit(unsigned int i)
-{
-    unsigned char x;
-    for(x = 0; x < 32; x++) {
-        if ((unsigned)(1 << x) == i) {
-            return x + 1;
-        }
-    }
-    return 0;
+static inline int which_bit(unsigned int i) {
+	unsigned char x;
+	for (x = 0; x < 32; x++) {
+		if ((unsigned) (1 << x) == i) {
+			return x + 1;
+		}
+	}
+	return 0;
 }
 
-char iax_pref_codec_add(struct iax_session *session, unsigned int format)
-{
+char iax_pref_codec_add(struct iax_session *session, unsigned int format) {
 	int diff = (int) 'A';
-	session->codec_order[session->codec_order_len++] = (char)((which_bit(format)) + diff);
+	session->codec_order[session->codec_order_len++] = (char) ((which_bit(format)) + diff);
 	session->codec_order[session->codec_order_len] = '\0';
-	return session->codec_order[session->codec_order_len-1];
+	return session->codec_order[session->codec_order_len - 1];
 }
 
 
-void iax_pref_codec_del(struct iax_session *session, unsigned int format)
-{
+void iax_pref_codec_del(struct iax_session *session, unsigned int format) {
 	int diff = (int) 'A';
 	size_t x;
 	char old[32];
-	char remove = (char)(which_bit(format) + diff);
+	char remove = (char) (which_bit(format) + diff);
 
 	strncpy(old, session->codec_order, sizeof(old));
 	session->codec_order_len = 0;
 
-	for (x = 0; x < strlen(old) ; x++) {
+	for (x = 0; x < strlen(old); x++) {
 		if (old[x] != remove) {
 			session->codec_order[session->codec_order_len++] = old[x];
 		}
@@ -1971,11 +1900,10 @@
 	session->codec_order[session->codec_order_len] = '\0';
 }
 
-int iax_pref_codec_get(struct iax_session *session, unsigned int *array, int len)
-{
+int iax_pref_codec_get(struct iax_session *session, unsigned int *array, int len) {
 	int diff = (int) 'A';
 	int x;
-	
+
 	for (x = 0; x < session->codec_order_len && x < len; x++) {
 		array[x] = (1 << (session->codec_order[x] - diff - 1));
 	}
@@ -1983,15 +1911,13 @@
 	return x;
 }
 
-void iax_set_samplerate(struct iax_session *session, unsigned short samplemask)
-{
+void iax_set_samplerate(struct iax_session *session, unsigned short samplemask) {
 	session->samplemask = samplemask;
 }
 
 
-int iax_call(struct iax_session *session, const char *cidnum, const char *cidname, char *ich, char *lang, int wait, int formats, int capabilities)
-{
-	char tmp[256]="";
+int iax_call(struct iax_session *session, const char *cidnum, const char *cidname, char *ich, char *lang, int wait, int formats, int capabilities) {
+	char tmp[256] = "";
 	char *part1, *part2;
 	int res;
 	int portno;
@@ -2006,10 +1932,10 @@
 		return -1;
 	}
 	memset(&ied, 0, sizeof(ied));
-	strncpy(tmp, ich, sizeof(tmp) - 1);	
+	strncpy(tmp, ich, sizeof(tmp) - 1);
 
 	iax_ie_append_short(&ied, IAX_IE_VERSION, IAX_PROTO_VERSION);
-    if (session->samplemask) {
+	if (session->samplemask) {
 		iax_ie_append_short(&ied, IAX_IE_SAMPLINGRATE, session->samplemask);
 	}
 	if (cidnum)
@@ -2022,20 +1948,20 @@
 	}
 
 	session->capability = capabilities;
-	session->pingid = iax_sched_add(NULL,NULL, send_ping, (void *)session, 2 * 1000);
+	session->pingid = iax_sched_add(NULL, NULL, send_ping, (void *) session, 2 * 1000);
 
 	/* XXX We should have a preferred format XXX */
 	iax_ie_append_int(&ied, IAX_IE_FORMAT, formats);
 	iax_ie_append_int(&ied, IAX_IE_CAPABILITY, capabilities);
 	if (lang)
 		iax_ie_append_str(&ied, IAX_IE_LANGUAGE, (unsigned char *) lang);
-	
+
 	/* Part 1 is [user[:password]@]peer[:port] */
 	part1 = strtok(tmp, "/");
 
 	/* Part 2 is exten[@context] if it is anything all */
 	part2 = strtok(NULL, "/");
-	
+
 	if (strchr(part1, '@')) {
 		username = strtok(part1, "@");
 		hostname = strtok(NULL, "@");
@@ -2043,19 +1969,19 @@
 		username = NULL;
 		hostname = part1;
 	}
-	
+
 	if (username && strchr(username, ':')) {
 		username = strtok(username, ":");
 		secret = strtok(NULL, ":");
 	} else
 		secret = NULL;
 
-	if(username)
-	  strncpy(session->username, username, sizeof(session->username) - 1);
+	if (username)
+		strncpy(session->username, username, sizeof(session->username) - 1);
+
+	if (secret)
+		strncpy(session->secret, secret, sizeof(session->secret) - 1);
 
-	if(secret)
-	  strncpy(session->secret, secret, sizeof(session->secret) - 1);
-	
 	if (strchr(hostname, ':')) {
 		strtok(hostname, ":");
 		portno = atoi(strtok(NULL, ":"));
@@ -2087,7 +2013,7 @@
 		return -1;
 	}
 	memcpy(&session->peeraddr.sin_addr, hp->h_addr, sizeof(session->peeraddr.sin_addr));
-	session->peeraddr.sin_port = htons((unsigned short)portno);
+	session->peeraddr.sin_port = htons((unsigned short) portno);
 	session->peeraddr.sin_family = AF_INET;
 	res = send_command(session, AST_FRAME_IAX, IAX_COMMAND_NEW, 0, ied.buf, ied.pos, -1);
 	if (res < 0)
@@ -2099,8 +2025,7 @@
 	return res;
 }
 
-static time_in_ms_t calc_rxstamp(struct iax_session *session)
-{
+static time_in_ms_t calc_rxstamp(struct iax_session *session) {
 	time_in_ms_t time_in_ms;
 
 	time_in_ms = current_time_in_ms();
@@ -2113,20 +2038,16 @@
 }
 
 #ifdef notdef_cruft
-static int match(struct sockaddr_in *sin, short callno, short dcallno, struct iax_session *cur)
-{
-	if ((cur->peeraddr.sin_addr.s_addr == sin->sin_addr.s_addr) &&
-		(cur->peeraddr.sin_port == sin->sin_port)) {
+static int match(struct sockaddr_in *sin, short callno, short dcallno, struct iax_session *cur) {
+	if ((cur->peeraddr.sin_addr.s_addr == sin->sin_addr.s_addr) && (cur->peeraddr.sin_port == sin->sin_port)) {
 		/* This is the main host */
-		if ((cur->peercallno == callno) || 
-			((dcallno == cur->callno) && !cur->peercallno)) {
+		if ((cur->peercallno == callno) || ((dcallno == cur->callno) && !cur->peercallno)) {
 			/* That's us.  Be sure we keep track of the peer call number */
 			cur->peercallno = callno;
 			return 1;
 		}
 	}
-	if ((cur->transfer.sin_addr.s_addr == sin->sin_addr.s_addr) &&
-	    (cur->transfer.sin_port == sin->sin_port) && (cur->transferring)) {
+	if ((cur->transfer.sin_addr.s_addr == sin->sin_addr.s_addr) && (cur->transfer.sin_port == sin->sin_port) && (cur->transferring)) {
 		/* We're transferring */
 		if (dcallno == cur->callno)
 			return 1;
@@ -2141,21 +2062,17 @@
    same peercallno (from two different asterisks) exist in more than
 	one session.
  */
-static int forward_match(struct sockaddr_in *sin, short callno, short dcallno, struct iax_session *cur)
-{
-	if ((cur->transfer.sin_addr.s_addr == sin->sin_addr.s_addr) &&
-		(cur->transfer.sin_port == sin->sin_port) && (cur->transferring)) {
+static int forward_match(struct sockaddr_in *sin, short callno, short dcallno, struct iax_session *cur) {
+	if ((cur->transfer.sin_addr.s_addr == sin->sin_addr.s_addr) && (cur->transfer.sin_port == sin->sin_port) && (cur->transferring)) {
 		/* We're transferring */
-		if (dcallno == cur->callno)
-		{
+		if (dcallno == cur->callno) {
 			return 1;
 		}
 	}
 
-	if ((cur->peeraddr.sin_addr.s_addr == sin->sin_addr.s_addr) &&
-		(cur->peeraddr.sin_port == sin->sin_port)) {
-		if (dcallno == cur->callno && dcallno != 0)  {
-					/* That's us.  Be sure we keep track of the peer call number */
+	if ((cur->peeraddr.sin_addr.s_addr == sin->sin_addr.s_addr) && (cur->peeraddr.sin_port == sin->sin_port)) {
+		if (dcallno == cur->callno && dcallno != 0) {
+			/* That's us.  Be sure we keep track of the peer call number */
 			if (cur->peercallno == 0) {
 				cur->peercallno = callno;
 			}
@@ -2166,18 +2083,15 @@
 	return 0;
 }
 
-static int reverse_match(struct sockaddr_in *sin, short callno, struct iax_session *cur)
-{
-	if ((cur->transfer.sin_addr.s_addr == sin->sin_addr.s_addr) &&
-		(cur->transfer.sin_port == sin->sin_port) && (cur->transferring)) {
+static int reverse_match(struct sockaddr_in *sin, short callno, struct iax_session *cur) {
+	if ((cur->transfer.sin_addr.s_addr == sin->sin_addr.s_addr) && (cur->transfer.sin_port == sin->sin_port) && (cur->transferring)) {
 		/* We're transferring */
-		if (callno == cur->peercallno)  {
+		if (callno == cur->peercallno) {
 			return 1;
 		}
 	}
-	if ((cur->peeraddr.sin_addr.s_addr == sin->sin_addr.s_addr) &&
-		(cur->peeraddr.sin_port == sin->sin_port)) {
-		if (callno == cur->peercallno)  {
+	if ((cur->peeraddr.sin_addr.s_addr == sin->sin_addr.s_addr) && (cur->peeraddr.sin_port == sin->sin_port)) {
+		if (callno == cur->peercallno) {
 			return 1;
 		}
 	}
@@ -2185,33 +2099,29 @@
 	return 0;
 }
 
-static struct iax_session *iax_find_session(struct sockaddr_in *sin, 
-											short callno, 
-											short dcallno,
-											int makenew)
-{
+static struct iax_session *iax_find_session(struct sockaddr_in *sin, short callno, short dcallno, int makenew) {
 	struct iax_session *cur;
 
-	iax_mutex_lock(session_mutex); 
+	iax_mutex_lock(session_mutex);
 	cur = sessions;
-	while(cur) {
+	while (cur) {
 		if (forward_match(sin, callno, dcallno, cur)) {
-			iax_mutex_unlock(session_mutex); 
+			iax_mutex_unlock(session_mutex);
 			return cur;
 		}
 		cur = cur->next;
 	}
 
 	cur = sessions;
-	while(cur) {
+	while (cur) {
 		if (reverse_match(sin, callno, cur)) {
-			iax_mutex_unlock(session_mutex); 
+			iax_mutex_unlock(session_mutex);
 			return cur;
 		}
 		cur = cur->next;
 	}
 
-	iax_mutex_unlock(session_mutex); 
+	iax_mutex_unlock(session_mutex);
 
 	if (makenew && !dcallno) {
 		cur = iax_session_new();
@@ -2219,18 +2129,17 @@
 		cur->peeraddr.sin_addr.s_addr = sin->sin_addr.s_addr;
 		cur->peeraddr.sin_port = sin->sin_port;
 		cur->peeraddr.sin_family = AF_INET;
-		cur->pingid = iax_sched_add(NULL,NULL, send_ping, (void *)cur, 2 * 1000);
+		cur->pingid = iax_sched_add(NULL, NULL, send_ping, (void *) cur, 2 * 1000);
 		DEBU(G "Making new session, peer callno %d, our callno %d\n", callno, cur->callno);
 	} else {
 		DEBU(G "No session, peer = %d, us = %d\n", callno, dcallno);
 	}
 
-	return cur;	
+	return cur;
 }
 
 #ifdef EXTREME_DEBUG
-static int display_time(int ms)
-{
+static int display_time(int ms) {
 	static int oldms = -1;
 	if (oldms < 0) {
 		DEBU(G "First measure\n");
@@ -2247,36 +2156,34 @@
 
 #ifdef NEWJB
 /* From chan_iax2/steve davies:  need to get permission from steve or digium, I guess */
-static time_in_ms_t unwrap_timestamp(time_in_ms_t ts, time_in_ms_t last)
-{
-        time_in_ms_t x;
+static time_in_ms_t unwrap_timestamp(time_in_ms_t ts, time_in_ms_t last) {
+	time_in_ms_t x;
 
-        if ( (ts & 0xFFFF0000) == (last & 0xFFFF0000) ) {
-                x = ts - last;
-                if (x < -50000) {
-                        /* Sudden big jump backwards in timestamp:
-                           What likely happened here is that miniframe timestamp has circled but we haven't
-                           gotten the update from the main packet.  We'll just pretend that we did, and
-                           update the timestamp appropriately. */
-                        ts = ( (last & 0xFFFF0000) + 0x10000) | (ts & 0xFFFF);
-                                DEBU(G "schedule_delivery: pushed forward timestamp\n");
-                }
-                if (x > 50000) {
-                        /* Sudden apparent big jump forwards in timestamp:
-                           What's likely happened is this is an old miniframe belonging to the previous
-                           top-16-bit timestamp that has turned up out of order.
-                           Adjust the timestamp appropriately. */
-                        ts = ( (last & 0xFFFF0000) - 0x10000) | (ts & 0xFFFF);
-                                DEBU(G "schedule_delivery: pushed back timestamp\n");
-                }
-        }
+	if ((ts & 0xFFFF0000) == (last & 0xFFFF0000)) {
+		x = ts - last;
+		if (x < -50000) {
+			/* Sudden big jump backwards in timestamp:
+			   What likely happened here is that miniframe timestamp has circled but we haven't
+			   gotten the update from the main packet.  We'll just pretend that we did, and
+			   update the timestamp appropriately. */
+			ts = ((last & 0xFFFF0000) + 0x10000) | (ts & 0xFFFF);
+			DEBU(G "schedule_delivery: pushed forward timestamp\n");
+		}
+		if (x > 50000) {
+			/* Sudden apparent big jump forwards in timestamp:
+			   What's likely happened is this is an old miniframe belonging to the previous
+			   top-16-bit timestamp that has turned up out of order.
+			   Adjust the timestamp appropriately. */
+			ts = ((last & 0xFFFF0000) - 0x10000) | (ts & 0xFFFF);
+			DEBU(G "schedule_delivery: pushed back timestamp\n");
+		}
+	}
 	return ts;
 }
 #endif
 
 
-static struct iax_event *schedule_delivery(struct iax_event *e, time_in_ms_t ts, int updatehistory)
-{
+static struct iax_event *schedule_delivery(struct iax_event *e, time_in_ms_t ts, int updatehistory) {
 	/* 
 	 * This is the core of the IAX jitterbuffer delivery mechanism: 
 	 * Dynamically adjust the jitterbuffer and decide how time_in_ms_t to wait
@@ -2285,21 +2192,21 @@
 #ifndef NEWJB
 	int ms, x;
 	int drops[MEMORY_SIZE];
-	int min, max=0, maxone=0, y, z, match;
+	int min, max = 0, maxone = 0, y, z, match;
 #endif
 
-#ifdef EXTREME_DEBUG	
+#ifdef EXTREME_DEBUG
 	DEBU(G "[%p] We are at %d, packet is for %d\n", e->session, calc_rxstamp(e->session), ts);
 #endif
-	
+
 #ifdef VOICE_SMOOTHING
 	if (e->etype == IAX_EVENT_VOICE) {
 		/* Smooth voices if we know enough about the format */
-		switch(e->event.voice.format) {
+		switch (e->event.voice.format) {
 		case AST_FORMAT_GSM:
 			/* GSM frames are 20 ms long, although there could be periods of 
 			   silence.  If the time is < 50 ms, assume it ought to be 20 ms */
-			if (ts - e->session->lastts < 50)  
+			if (ts - e->session->lastts < 50)
 				ts = e->session->lastts + 20;
 #ifdef EXTREME_DEBUG
 			display_time(ts);
@@ -2314,38 +2221,38 @@
 
 #ifdef NEWJB
 	{
-	    int type = JB_TYPE_CONTROL;
-	    int len = 0;
+		int type = JB_TYPE_CONTROL;
+		int len = 0;
+
+		if (e->etype == IAX_EVENT_VOICE) {
+			type = JB_TYPE_VOICE;
+			len = get_sample_cnt(e) / 8;
+		} else if (e->etype == IAX_EVENT_CNG) {
+			type = JB_TYPE_SILENCE;
+		}
+
+		/* unwrap timestamp */
+		ts = unwrap_timestamp(ts, e->session->last_ts);
 
-	    if(e->etype == IAX_EVENT_VOICE) {
-	      type = JB_TYPE_VOICE;
-	      len = get_sample_cnt(e) / 8;
-	    } else if(e->etype == IAX_EVENT_CNG) {
-	      type = JB_TYPE_SILENCE;	
-	    }
-
-	    /* unwrap timestamp */
-	    ts = unwrap_timestamp(ts,e->session->last_ts);
-
-	    /* move forward last_ts if it's greater.  We do this _after_ unwrapping, because
-	     * asterisk _still_ has cases where it doesn't send full frames when it ought to */
-	    if(ts > e->session->last_ts) {
-		e->session->last_ts = ts;		
-	    }
-
-
-	    /* insert into jitterbuffer */
-	    /* TODO: Perhaps we could act immediately if it's not droppable and late */
-	    if(jb_put(e->session->jb, e, type, len, ts, calc_rxstamp(e->session)) == JB_DROP) {
-		  iax_event_free(e);
-	    }
+		/* move forward last_ts if it's greater.  We do this _after_ unwrapping, because
+		 * asterisk _still_ has cases where it doesn't send full frames when it ought to */
+		if (ts > e->session->last_ts) {
+			e->session->last_ts = ts;
+		}
+
+
+		/* insert into jitterbuffer */
+		/* TODO: Perhaps we could act immediately if it's not droppable and late */
+		if (jb_put(e->session->jb, e, type, len, ts, calc_rxstamp(e->session)) == JB_DROP) {
+			iax_event_free(e);
+		}
 
 	}
 #else
-	
+
 	/* How many ms from now should this packet be delivered? (remember
 	   this can be a negative number, too */
-	ms = (int)(calc_rxstamp(e->session) - ts);
+	ms = (int) (calc_rxstamp(e->session) - ts);
 
 	/*  
 	   Drop voice frame if timestamp is way off 
@@ -2354,7 +2261,7 @@
 	   free(e);
 	   return NULL;
 	   }
-	*/
+	 */
 
 	/* Adjust if voice frame timestamp is off by a step */
 	if (ms > 32768) {
@@ -2368,33 +2275,32 @@
 		   time frame */
 		ms += 65536;
 	}
-
-#if 0	
+#if 0
 	printf("rxstamp is %d, timestamp is %d, ms is %d\n", calc_rxstamp(e->session), ts, ms);
 #endif
 	/* Rotate history queue.  Leading 0's are irrelevant. */
 	if (updatehistory) {
-	    for (x=0; x < MEMORY_SIZE - 1; x++) 
-		    e->session->history[x] = e->session->history[x+1];
-	    
-	    /* Add new entry for this time */
-	    e->session->history[x] = ms;
+		for (x = 0; x < MEMORY_SIZE - 1; x++)
+			e->session->history[x] = e->session->history[x + 1];
+
+		/* Add new entry for this time */
+		e->session->history[x] = ms;
 	}
-	
+
 	/* We have to find the maximum and minimum time delay we've had to deliver. */
 	min = e->session->history[0];
-	for (z=0;z < iax_dropcount + 1; z++) {
+	for (z = 0; z < iax_dropcount + 1; z++) {
 		/* We drop the top iax_dropcount entries.  iax_dropcount represents
 		   a tradeoff between quality of voice and latency.  3% drop seems to
 		   be unnoticable to the client and can significantly improve latency.  
 		   We add one more to our droplist, but that's the one we actually use, 
 		   and don't drop.  */
 		max = -99999999;
-		for (x=0;x<MEMORY_SIZE;x++) {
+		for (x = 0; x < MEMORY_SIZE; x++) {
 			if (max < e->session->history[x]) {
 				/* New candidate value.  Make sure we haven't dropped it. */
-				match=0;
-				for(y=0;!match && (y<z); y++) 
+				match = 0;
+				for (y = 0; !match && (y < z); y++)
 					match |= (drops[y] == x);
 				/* If there is no match, this is our new maximum */
 				if (!match) {
@@ -2413,7 +2319,7 @@
 	/* Again, just for reference.  The "jitter buffer" is the max.  The difference
 	   is the perceived jitter correction. */
 	e->session->jitter = max - min;
-	
+
 	/* If the jitter buffer is substantially too large, shrink it, slowly enough
 	   that the client won't notice ;-) . */
 	if (max < e->session->jitterbuffer - max_extra_jitterbuffer) {
@@ -2422,27 +2328,27 @@
 #endif
 		e->session->jitterbuffer -= 1;
 	}
-		
+
 	/* Keep the jitter buffer from becoming unreasonably large */
 	if (max > min + max_jitterbuffer) {
 		DEBU(G "Constraining jitter buffer (min = %d, max = %d)...\n", min, max);
 		max = min + max_jitterbuffer;
 	}
-	
+
 	/* If the jitter buffer is too small, we immediately grow our buffer to
 	   accomodate */
 	if (max > e->session->jitterbuffer)
 		e->session->jitterbuffer = max;
-	
+
 	/* Start with our jitter buffer delay, and subtract the lateness (or earliness).
 	   Remember these times are all relative to the first packet, so their absolute
 	   values are really irrelevant. */
 	ms = e->session->jitterbuffer - ms - IAX_SCHEDULE_FUZZ;
-	
+
 	/* If the jitterbuffer is disabled, always deliver immediately */
 	if (!iax_use_jitterbuffer)
 		ms = 0;
-	
+
 	if (ms < 1) {
 #ifdef EXTREME_DEBUG
 		DEBU(G "Calculated delay is only %d\n", ms);
@@ -2469,11 +2375,10 @@
 #endif
 #endif /* NEWJB */
 	return NULL;
-	
+
 }
 
-static int uncompress_subclass(unsigned char csub)
-{
+static int uncompress_subclass(unsigned char csub) {
 	/* If the SC_LOG flag is set, return 2^csub otherwise csub */
 	if (csub & IAX_FLAG_SC_LOG)
 		return 1 << (csub & ~IAX_FLAG_SC_LOG & IAX_MAX_SHIFT);
@@ -2481,8 +2386,7 @@
 		return csub;
 }
 
-static inline char *extract(char *src, char *string)
-{
+static inline char *extract(char *src, char *string) {
 	/* Extract and duplicate what we need from a string */
 	char *s, *t;
 	s = strstr(src, string);
@@ -2496,13 +2400,10 @@
 		}
 	}
 	return s;
-		
+
 }
 
-static struct iax_event *iax_header_to_event(struct iax_session *session,
-											 struct ast_iax2_full_hdr *fh,
-											 int datalen, struct sockaddr_in *sin)
-{
+static struct iax_event *iax_header_to_event(struct iax_session *session, struct ast_iax2_full_hdr *fh, int datalen, struct sockaddr_in *sin) {
 	struct iax_event *e;
 	struct iax_sched *sch;
 	unsigned int ts;
@@ -2512,14 +2413,10 @@
 	ts = ntohl(fh->ts);
 	/* don't run last_ts backwards; i.e. for retransmits and the like */
 	if (ts > session->last_ts &&
-	    (fh->type == AST_FRAME_IAX && 
-	     subclass != IAX_COMMAND_ACK &&
-	     subclass != IAX_COMMAND_PONG &&
-	     subclass != IAX_COMMAND_LAGRP)) {
-	    session->last_ts = ts;
+		(fh->type == AST_FRAME_IAX && subclass != IAX_COMMAND_ACK && subclass != IAX_COMMAND_PONG && subclass != IAX_COMMAND_LAGRP)) {
+		session->last_ts = ts;
 	}
 
-
 #ifdef DEBUG_SUPPORT
 	iax_showframe(NULL, fh, 1, sin, datalen);
 #endif
@@ -2527,89 +2424,75 @@
 	/* Get things going with it, timestamp wise, if we
 	   haven't already. */
 
-		/* Handle implicit ACKing unless this is an INVAL, and only if this is 
-		   from the real peer, not the transfer peer */
-		if (!inaddrcmp(sin, &session->peeraddr) && 
-			(((subclass != IAX_COMMAND_INVAL)) ||
-			(fh->type != AST_FRAME_IAX))) {
-			unsigned char x;
-			/* XXX This code is not very efficient.  Surely there is a better way which still
-			       properly handles boundary conditions? XXX */
-			/* First we have to qualify that the ACKed value is within our window */
-			for (x=session->rseqno; x != session->oseqno; x++)
-				if (fh->iseqno == x)
-					break;
-			if ((x != session->oseqno) || (session->oseqno == fh->iseqno)) {
-				/* The acknowledgement is within our window.  Time to acknowledge everything
-				   that it says to */
-				for (x=session->rseqno; x != fh->iseqno; x++) {
-					/* Ack the packet with the given timestamp */
-					DEBU(G "Cancelling transmission of packet %d\n", x);
-					iax_mutex_lock(sched_mutex);
-					sch = schedq;
-					while(sch) {
-						if (sch->frame && (sch->frame->session == session) && 
-						    (sch->frame->oseqno == x)) 
-							sch->frame->retries = -1;
-						sch = sch->next;
-					}
-					iax_mutex_unlock(sched_mutex);
+	/* Handle implicit ACKing unless this is an INVAL, and only if this is 
+	   from the real peer, not the transfer peer */
+	if (!inaddrcmp(sin, &session->peeraddr) && (((subclass != IAX_COMMAND_INVAL)) || (fh->type != AST_FRAME_IAX))) {
+		unsigned char x;
+		/* XXX This code is not very efficient.  Surely there is a better way which still
+		   properly handles boundary conditions? XXX */
+		/* First we have to qualify that the ACKed value is within our window */
+		for (x = session->rseqno; x != session->oseqno; x++)
+			if (fh->iseqno == x)
+				break;
+		if ((x != session->oseqno) || (session->oseqno == fh->iseqno)) {
+			/* The acknowledgement is within our window.  Time to acknowledge everything
+			   that it says to */
+			for (x = session->rseqno; x != fh->iseqno; x++) {
+				/* Ack the packet with the given timestamp */
+				DEBU(G "Cancelling transmission of packet %d\n", x);
+				iax_mutex_lock(sched_mutex);
+				sch = schedq;
+				while (sch) {
+					if (sch->frame && (sch->frame->session == session) && (sch->frame->oseqno == x))
+						sch->frame->retries = -1;
+					sch = sch->next;
 				}
-				/* Note how much we've received acknowledgement for */
-				session->rseqno = fh->iseqno;
-			} else
-				DEBU(G "Received iseqno %d not within window %d->%d\n", fh->iseqno, session->rseqno, session->oseqno);
-		}
+				iax_mutex_unlock(sched_mutex);
+			}
+			/* Note how much we've received acknowledgement for */
+			session->rseqno = fh->iseqno;
+		} else
+			DEBU(G "Received iseqno %d not within window %d->%d\n", fh->iseqno, session->rseqno, session->oseqno);
+	}
 
 	/* Check where we are */
-		if ((ntohs(fh->dcallno) & IAX_FLAG_RETRANS) || (fh->type != AST_FRAME_VOICE))
-			updatehistory = 0;
-		if ((session->iseqno != fh->oseqno) &&
-			(session->iseqno ||
-			   ((subclass != IAX_COMMAND_TXREADY) &&
-			    (subclass != IAX_COMMAND_TXREL) &&
-				(subclass != IAX_COMMAND_TXCNT) &&
-				(subclass != IAX_COMMAND_TXACC)) ||
-			  (fh->type != AST_FRAME_IAX))) {
-			if (
-			 ((subclass != IAX_COMMAND_ACK) &&
-			  (subclass != IAX_COMMAND_INVAL) &&
-			  (subclass != IAX_COMMAND_TXREADY) &&
-			  (subclass != IAX_COMMAND_TXREL) &&
-			  (subclass != IAX_COMMAND_TXCNT) &&
-			  (subclass != IAX_COMMAND_TXACC) &&
-			  (subclass != IAX_COMMAND_VNAK)) ||
-			  (fh->type != AST_FRAME_IAX)) {
-			 	/* If it's not an ACK packet, it's out of order. */
-				DEBU(G "Packet arrived out of order (expecting %d, got %d) (frametype = %d, subclass = %d)\n", 
-					session->iseqno, fh->oseqno, fh->type, subclass);
-				if (session->iseqno > fh->oseqno) {
-					/* If we've already seen it, ack it XXX There's a border condition here XXX */
-					if ((fh->type != AST_FRAME_IAX) || 
-							((subclass != IAX_COMMAND_ACK) && (subclass != IAX_COMMAND_INVAL))) {
-						DEBU(G "Acking anyway\n");
-						/* XXX Maybe we should handle its ack to us, but then again, it's probably outdated anyway, and if
-						   we have anything to send, we'll retransmit and get an ACK back anyway XXX */
-						send_command_immediate(session, AST_FRAME_IAX, IAX_COMMAND_ACK, ts, NULL, 0,fh->iseqno);
-					}
-				} else {
-					/* Send a VNAK requesting retransmission */
-					iax2_vnak(session);
+	if ((ntohs(fh->dcallno) & IAX_FLAG_RETRANS) || (fh->type != AST_FRAME_VOICE))
+		updatehistory = 0;
+	if ((session->iseqno != fh->oseqno) &&
+		(session->iseqno ||
+		 ((subclass != IAX_COMMAND_TXREADY) &&
+		  (subclass != IAX_COMMAND_TXREL) && (subclass != IAX_COMMAND_TXCNT) && (subclass != IAX_COMMAND_TXACC)) || (fh->type != AST_FRAME_IAX))) {
+		if (((subclass != IAX_COMMAND_ACK) &&
+			 (subclass != IAX_COMMAND_INVAL) &&
+			 (subclass != IAX_COMMAND_TXREADY) &&
+			 (subclass != IAX_COMMAND_TXREL) &&
+			 (subclass != IAX_COMMAND_TXCNT) && (subclass != IAX_COMMAND_TXACC) && (subclass != IAX_COMMAND_VNAK)) || (fh->type != AST_FRAME_IAX)) {
+			/* If it's not an ACK packet, it's out of order. */
+			DEBU(G "Packet arrived out of order (expecting %d, got %d) (frametype = %d, subclass = %d)\n",
+				 session->iseqno, fh->oseqno, fh->type, subclass);
+			if (session->iseqno > fh->oseqno) {
+				/* If we've already seen it, ack it XXX There's a border condition here XXX */
+				if ((fh->type != AST_FRAME_IAX) || ((subclass != IAX_COMMAND_ACK) && (subclass != IAX_COMMAND_INVAL))) {
+					DEBU(G "Acking anyway\n");
+					/* XXX Maybe we should handle its ack to us, but then again, it's probably outdated anyway, and if
+					   we have anything to send, we'll retransmit and get an ACK back anyway XXX */
+					send_command_immediate(session, AST_FRAME_IAX, IAX_COMMAND_ACK, ts, NULL, 0, fh->iseqno);
 				}
-				return NULL;
+			} else {
+				/* Send a VNAK requesting retransmission */
+				iax2_vnak(session);
 			}
-		} else {
-			/* Increment unless it's an ACK or VNAK */
-			if (((subclass != IAX_COMMAND_ACK) &&
-			    (subclass != IAX_COMMAND_INVAL) &&
-			    (subclass != IAX_COMMAND_TXCNT) &&
-			    (subclass != IAX_COMMAND_TXACC) &&
-				(subclass != IAX_COMMAND_VNAK)) ||
-			    (fh->type != AST_FRAME_IAX))
-				session->iseqno++;
+			return NULL;
 		}
-			
-	e = (struct iax_event *)malloc(sizeof(struct iax_event) + datalen + 1);
+	} else {
+		/* Increment unless it's an ACK or VNAK */
+		if (((subclass != IAX_COMMAND_ACK) &&
+			 (subclass != IAX_COMMAND_INVAL) &&
+			 (subclass != IAX_COMMAND_TXCNT) && (subclass != IAX_COMMAND_TXACC) && (subclass != IAX_COMMAND_VNAK)) || (fh->type != AST_FRAME_IAX))
+			session->iseqno++;
+	}
+
+	e = (struct iax_event *) malloc(sizeof(struct iax_event) + datalen + 1);
 
 	if (e) {
 		memset(e, 0, sizeof(struct iax_event) + datalen);
@@ -2618,14 +2501,14 @@
 		 */
 		e->etype = -1;
 		e->session = session;
-		switch(fh->type) {
+		switch (fh->type) {
 		case AST_FRAME_DTMF:
 			e->etype = IAX_EVENT_DTMF;
 			e->subclass = subclass;
 			/* 
-			 We want the DTMF event deliver immediately so all I/O can be
-			 terminate quickly in an IVR system.
-			e = schedule_delivery(e, ts, updatehistory); */
+			   We want the DTMF event deliver immediately so all I/O can be
+			   terminate quickly in an IVR system.
+			   e = schedule_delivery(e, ts, updatehistory); */
 			break;
 		case AST_FRAME_VOICE:
 			e->etype = IAX_EVENT_VOICE;
@@ -2640,12 +2523,12 @@
 		case AST_FRAME_CNG:
 			e->etype = IAX_EVENT_CNG;
 			e->subclass = subclass;
-                        if (datalen) {
-                                memcpy(e->data, fh->iedata, datalen);
-                                e->datalen = datalen;
-                        }
-                        e = schedule_delivery(e, ts, updatehistory);
-                        break;
+			if (datalen) {
+				memcpy(e->data, fh->iedata, datalen);
+				e->datalen = datalen;
+			}
+			e = schedule_delivery(e, ts, updatehistory);
+			break;
 		case AST_FRAME_IAX:
 			/* Parse IE's */
 			if (datalen) {
@@ -2658,14 +2541,14 @@
 				e = NULL;
 				break;
 			}
-			switch(subclass) {
+			switch (subclass) {
 			case IAX_COMMAND_NEW:
 				/* This is a new, incoming call */
 				/* save the capability for validation */
 				session->capability = e->ies.capability;
 				if (e->ies.codec_prefs) {
 					strncpy(session->codec_order, e->ies.codec_prefs, sizeof(session->codec_order));
-					session->codec_order_len = (int)strlen(session->codec_order);
+					session->codec_order_len = (int) strlen(session->codec_order);
 				}
 				e->etype = IAX_EVENT_CONNECT;
 				e = schedule_delivery(e, ts, updatehistory);
@@ -2673,13 +2556,12 @@
 			case IAX_COMMAND_AUTHREQ:
 				/* This is a request for a call */
 				e->etype = IAX_EVENT_AUTHRQ;
-				if (strlen(session->username) && !strcmp(e->ies.username, session->username) &&
-					strlen(session->secret)) {
-						/* Hey, we already know this one */
-						iax_auth_reply(session, session->secret, e->ies.challenge, e->ies.authmethods);
-						free(e);
-						e = NULL;
-						break;
+				if (strlen(session->username) && !strcmp(e->ies.username, session->username) && strlen(session->secret)) {
+					/* Hey, we already know this one */
+					iax_auth_reply(session, session->secret, e->ies.challenge, e->ies.authmethods);
+					free(e);
+					e = NULL;
+					break;
 				}
 				e = schedule_delivery(e, ts, updatehistory);
 				break;
@@ -2717,7 +2599,7 @@
 			case IAX_COMMAND_PONG:
 				e->etype = IAX_EVENT_PONG;
 				/* track weighted average of ping time */
-				session->pingtime = ((2 * session->pingtime) + (calc_timestamp(session,0,NULL) - ts)) / 3;
+				session->pingtime = ((2 * session->pingtime) + (calc_timestamp(session, 0, NULL) - ts)) / 3;
 				session->remote_netstats.jitter = e->ies.rr_jitter;
 				session->remote_netstats.losspct = e->ies.rr_loss >> 24;;
 				session->remote_netstats.losscnt = e->ies.rr_loss & 0xffffff;
@@ -2729,13 +2611,12 @@
 			case IAX_COMMAND_ACCEPT:
 				if (e->ies.format & session->capability) {
 					e->etype = IAX_EVENT_ACCEPT;
-				}
-				else {
+				} else {
 					struct iax_ie_data ied;
 					/* Although this should not happen, we added this to make sure
 					   the negotiation protocol is enforced.
-						For lack of event to notify the application we use the defined
-						REJECT event.
+					   For lack of event to notify the application we use the defined
+					   REJECT event.
 					 */
 					memset(&ied, 0, sizeof(ied));
 					iax_ie_append_str(&ied, IAX_IE_CAUSE, (unsigned char *) "Unable to negotiate codec");
@@ -2779,15 +2660,15 @@
 				 *  apparent transfer address
 				 */
 				if (e->ies.apparent_addr != NULL) {
-				    /* so a full voice frame is sent on the 
-				       next voice output */
-				    session->svoiceformat = -1;	
-				    session->transfer = *e->ies.apparent_addr;
-				    session->transfer.sin_family = AF_INET;
-				    session->transfercallno = e->ies.callno;
-				    session->transferring = TRANSFER_BEGIN;
-				    session->transferid = e->ies.transferid;
-				    iax_send_txcnt(session);
+					/* so a full voice frame is sent on the 
+					   next voice output */
+					session->svoiceformat = -1;
+					session->transfer = *e->ies.apparent_addr;
+					session->transfer.sin_family = AF_INET;
+					session->transfercallno = e->ies.callno;
+					session->transferring = TRANSFER_BEGIN;
+					session->transferid = e->ies.transferid;
+					iax_send_txcnt(session);
 				}
 				free(e);
 				e = NULL;
@@ -2798,7 +2679,7 @@
 				/* Return immediately, makes no sense to schedule */
 				break;
 			case IAX_COMMAND_TXCNT:
-				if (session->transferring)  {
+				if (session->transferring) {
 					session->transfer = *sin;
 					iax_send_txaccept(session);
 				}
@@ -2816,11 +2697,10 @@
 				break;
 			case IAX_COMMAND_TXREL:
 				/* Release the transfer */
-			   send_command_immediate(session, AST_FRAME_IAX, IAX_COMMAND_ACK, fh->ts, NULL, 0, fh->iseqno);
+				send_command_immediate(session, AST_FRAME_IAX, IAX_COMMAND_ACK, fh->ts, NULL, 0, fh->iseqno);
 				if (session->transferring) {
 					complete_transfer(session, e->ies.callno, 1, 0);
-				}
-				else {
+				} else {
 					complete_transfer(session, session->peercallno, 0, 1);
 				}
 				e->etype = IAX_EVENT_TRANSFER;
@@ -2844,8 +2724,7 @@
 				send_command_immediate(session, AST_FRAME_IAX, IAX_COMMAND_ACK, ts, NULL, 0, fh->iseqno);
 				if (iax_handle_txready(session)) {
 					e->etype = IAX_EVENT_TXREADY;
-				}
-				else {
+				} else {
 					free(e);
 					e = NULL;
 				}
@@ -2857,7 +2736,7 @@
 			}
 			break;
 		case AST_FRAME_CONTROL:
-			switch(subclass) {
+			switch (subclass) {
 			case AST_CONTROL_ANSWER:
 				e->etype = IAX_EVENT_ANSWER;
 				e = schedule_delivery(e, ts, updatehistory);
@@ -2895,7 +2774,7 @@
 			break;
 
 		case AST_FRAME_HTML:
-			switch(fh->csub) {
+			switch (fh->csub) {
 			case AST_HTML_LINKURL:
 				e->etype = IAX_EVENT_LINKURL;
 				/* Fall through */
@@ -2934,22 +2813,19 @@
 		}
 	} else
 		DEBU(G "Out of memory\n");
-	    
+
 	/* Already ack'd iax frames */
 	if (session->aseqno != session->iseqno) {
-	    send_command_immediate(session, AST_FRAME_IAX, IAX_COMMAND_ACK, ts, NULL, 0, fh->iseqno);
+		send_command_immediate(session, AST_FRAME_IAX, IAX_COMMAND_ACK, ts, NULL, 0, fh->iseqno);
 	}
 	return e;
 }
 
-static struct iax_event *iax_miniheader_to_event(struct iax_session *session,
-						struct ast_iax2_mini_hdr *mh,
-						int datalen)
-{
+static struct iax_event *iax_miniheader_to_event(struct iax_session *session, struct ast_iax2_mini_hdr *mh, int datalen) {
 	struct iax_event *e;
 	time_in_ms_t ts;
 	int updatehistory = 1;
-	e = (struct iax_event *)malloc(sizeof(struct iax_event) + datalen);
+	e = (struct iax_event *) malloc(sizeof(struct iax_event) + datalen);
 	if (e) {
 		if (session->voiceformat > 0) {
 			e->etype = IAX_EVENT_VOICE;
@@ -2974,15 +2850,13 @@
 	return e;
 }
 
-void iax_destroy(struct iax_session *session)
-{
-	iax_mutex_lock(session_mutex); 
+void iax_destroy(struct iax_session *session) {
+	iax_mutex_lock(session_mutex);
 	destroy_session(session);
-	iax_mutex_unlock(session_mutex); 
+	iax_mutex_unlock(session_mutex);
 }
 
-static struct iax_event *iax_net_read(void)
-{
+static struct iax_event *iax_net_read(void) {
 	unsigned char buf[65536];
 	int res;
 #ifndef __Linux__
@@ -2993,7 +2867,7 @@
 	struct sockaddr_in sin;
 
 	sinlen = sizeof(sin);
-	res = iax_recvfrom(netfd, (char *)buf, sizeof(buf), 0, (struct sockaddr *) &sin, &sinlen);
+	res = iax_recvfrom(netfd, (char *) buf, sizeof(buf), 0, (struct sockaddr *) &sin, &sinlen);
 
 	if (res < 0) {
 #ifdef	WIN32
@@ -3012,48 +2886,44 @@
 	return iax_net_process(buf, res, &sin);
 }
 
-static struct iax_session *iax_txcnt_session(struct ast_iax2_full_hdr *fh, int datalen,
-				struct sockaddr_in *sin, short callno, short dcallno)
-{
+static struct iax_session *iax_txcnt_session(struct ast_iax2_full_hdr *fh, int datalen, struct sockaddr_in *sin, short callno, short dcallno) {
 	int subclass = uncompress_subclass(fh->csub);
-	unsigned char buf[ 65536 ]; /* allocated on stack with same size as iax_net_read() */
+	unsigned char buf[65536];	/* allocated on stack with same size as iax_net_read() */
 	struct iax_ies ies;
 	struct iax_session *cur;
 
 	if ((fh->type != AST_FRAME_IAX) || (subclass != IAX_COMMAND_TXCNT) || (!datalen)) {
-		return NULL; /* special handling for TXCNT only */
+		return NULL;			/* special handling for TXCNT only */
 	}
 	memcpy(buf, fh->iedata, datalen);	/* prepare local buf for iax_parse_ies() */
 
 	if (iax_parse_ies(&ies, buf, datalen)) {
-		return NULL;	/* Unable to parse IE's */
+		return NULL;			/* Unable to parse IE's */
 	}
 	if (!ies.transferid) {
-		return NULL;	/* TXCNT without proper IAX_IE_TRANSFERID */
+		return NULL;			/* TXCNT without proper IAX_IE_TRANSFERID */
 	}
-	iax_mutex_lock(session_mutex); 
-	for( cur=sessions; cur; cur=cur->next ) {
-		if ((cur->transferring) && (cur->transferid == (int)ies.transferid) &&
-		   	(cur->callno == dcallno) && (cur->transfercallno == callno)) {
+	iax_mutex_lock(session_mutex);
+	for (cur = sessions; cur; cur = cur->next) {
+		if ((cur->transferring) && (cur->transferid == (int) ies.transferid) && (cur->callno == dcallno) && (cur->transfercallno == callno)) {
 			/* We're transferring ---
-			 * 	skip address/port checking which would fail while remote peer behind symmetric NAT
-			 * 	verify transferid instead
+			 *  skip address/port checking which would fail while remote peer behind symmetric NAT
+			 *  verify transferid instead
 			 */
 			cur->transfer.sin_addr.s_addr = sin->sin_addr.s_addr;	/* setup for further handling */
 			cur->transfer.sin_port = sin->sin_port;
-			break;		
+			break;
 		}
 	}
-	iax_mutex_unlock(session_mutex); 
+	iax_mutex_unlock(session_mutex);
 	return cur;
 }
 
-struct iax_event *iax_net_process(unsigned char *buf, int len, struct sockaddr_in *sin)
-{
-	struct ast_iax2_full_hdr *fh = (struct ast_iax2_full_hdr *)buf;
-	struct ast_iax2_mini_hdr *mh = (struct ast_iax2_mini_hdr *)buf;
+struct iax_event *iax_net_process(unsigned char *buf, int len, struct sockaddr_in *sin) {
+	struct ast_iax2_full_hdr *fh = (struct ast_iax2_full_hdr *) buf;
+	struct ast_iax2_mini_hdr *mh = (struct ast_iax2_mini_hdr *) buf;
 	struct iax_session *session;
-	
+
 	if (ntohs(fh->scallno) & IAX_FLAG_FULL) {
 		int subclass = uncompress_subclass(fh->csub);
 		int makenew = 0;
@@ -3066,17 +2936,17 @@
 		}
 		/* Only allow it to make new sessions on types where that makes sense */
 		if ((fh->type == AST_FRAME_IAX) && ((subclass == IAX_COMMAND_NEW) ||
-											(subclass == IAX_COMMAND_POKE) ||
-											(subclass == IAX_COMMAND_REGREL) ||
-											(subclass == IAX_COMMAND_REGREQ))) {
+											(subclass == IAX_COMMAND_POKE) || (subclass == IAX_COMMAND_REGREL) || (subclass == IAX_COMMAND_REGREQ))) {
 			makenew = 1;
 		}
 
 		/* We have a full header, process appropriately */
 		session = iax_find_session(sin, ntohs(fh->scallno) & ~IAX_FLAG_FULL, ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS, makenew);
 		if (!session)
-			session = iax_txcnt_session(fh, len-sizeof(struct ast_iax2_full_hdr), sin, ntohs(fh->scallno) & ~IAX_FLAG_FULL, ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS);
-		if (session) 
+			session =
+				iax_txcnt_session(fh, len - sizeof(struct ast_iax2_full_hdr), sin, ntohs(fh->scallno) & ~IAX_FLAG_FULL,
+								  ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS);
+		if (session)
 			return iax_header_to_event(session, fh, len - sizeof(struct ast_iax2_full_hdr), sin);
 		/* if we get here, the frame was invalid for some reason, we should probably send IAX_COMMAND_INVAL (as long as the subclass was not already IAX_COMMAND_INVAL) */
 		DEBU(G "No session?\n");
@@ -3096,13 +2966,12 @@
 	}
 }
 
-static struct iax_sched *iax_get_sched(time_in_ms_t time_in_ms)
-{
-	struct iax_sched *cur, *prev=NULL;
+static struct iax_sched *iax_get_sched(time_in_ms_t time_in_ms) {
+	struct iax_sched *cur, *prev = NULL;
 	iax_mutex_lock(sched_mutex);
 	cur = schedq;
 	/* Check the event schedule first. */
-	while(cur) {
+	while (cur) {
 		if (time_in_ms > cur->when) {
 			/* Take it out of the event queue */
 			if (prev) {
@@ -3119,20 +2988,19 @@
 	return NULL;
 }
 
-struct iax_event *iax_get_event(int blocking)
-{
+struct iax_event *iax_get_event(int blocking) {
 	struct iax_event *event;
 	struct iax_frame *frame;
 	time_in_ms_t time_in_ms;
 	struct iax_sched *cur;
-	
+
 	if (do_shutdown) {
 		__iax_shutdown();
 		do_shutdown = 0;
 		return NULL;
 	}
 	time_in_ms = current_time_in_ms();
-	while((cur = iax_get_sched(time_in_ms))) {
+	while ((cur = iax_get_sched(time_in_ms))) {
 
 		event = cur->event;
 		frame = cur->frame;
@@ -3144,15 +3012,15 @@
 				free(cur);
 				return event;
 			}
-		} else if(frame) {
+		} else if (frame) {
 			/* It's a frame, transmit it and schedule a retry */
 			if (frame->retries < 0) {
 				/* It's been acked.  No need to send it.   Destroy the old
 				   frame. If final, destroy the session. */
 				if (frame->final) {
-					iax_mutex_lock(session_mutex); 
+					iax_mutex_lock(session_mutex);
 					destroy_session(frame->session);
-					iax_mutex_unlock(session_mutex); 
+					iax_mutex_unlock(session_mutex);
 				}
 				if (frame->data)
 					free(frame->data);
@@ -3170,14 +3038,14 @@
 					/* We haven't been able to get an ACK on this packet. If a 
 					   final frame, destroy the session, otherwise, pass up timeout */
 					if (frame->final) {
-						iax_mutex_lock(session_mutex); 
+						iax_mutex_lock(session_mutex);
 						destroy_session(frame->session);
-						iax_mutex_unlock(session_mutex); 
+						iax_mutex_unlock(session_mutex);
 						if (frame->data)
 							free(frame->data);
 						free(frame);
 					} else {
-						event = (struct iax_event *)malloc(sizeof(struct iax_event));
+						event = (struct iax_event *) malloc(sizeof(struct iax_event));
 						if (event) {
 							event->etype = IAX_EVENT_TIMEOUT;
 							event->session = frame->session;
@@ -3201,7 +3069,7 @@
 						frame->retrytime = MAX_RETRY_TIME;
 				} else if (frame->retrytime > 1000)
 					frame->retrytime = 1000;
-				fh = (struct ast_iax2_full_hdr *)(frame->data);
+				fh = (struct ast_iax2_full_hdr *) (frame->data);
 				fh->dcallno = htons(IAX_FLAG_RETRANS | frame->dcallno);
 				iax_xmit_frame(frame);
 				/* Schedule another retransmission */
@@ -3209,7 +3077,7 @@
 				iax_sched_add(NULL, frame, NULL, NULL, frame->retrytime);
 			}
 		} else if (cur->func) {
-		    cur->func(cur->arg);
+			cur->func(cur->arg);
 		}
 		free(cur);
 	}
@@ -3217,20 +3085,20 @@
 #ifdef NEWJB
 	/* get jitterbuffer-scheduled events */
 	{
-	    struct iax_session *cur;
-	    jb_frame frame;
-		iax_mutex_lock(session_mutex); 
-	    for(cur=sessions; cur; cur=cur->next) {
+		struct iax_session *cur;
+		jb_frame frame;
+		iax_mutex_lock(session_mutex);
+		for (cur = sessions; cur; cur = cur->next) {
 			int ret;
 			time_in_ms_t now;
 			time_in_ms_t next;
 
 			now = time_in_ms - cur->rxcore;
-			if(now > (next = jb_next(cur->jb))) {
-				ret = jb_get(cur->jb,&frame,now,get_interp_len(cur->voiceformat));
-				switch(ret) {
+			if (now > (next = jb_next(cur->jb))) {
+				ret = jb_get(cur->jb, &frame, now, get_interp_len(cur->voiceformat));
+				switch (ret) {
 				case JB_OK:
-					//			    if(frame.type == JB_TYPE_VOICE && next + 20 != jb_next(cur->jb)) fprintf(stderr, "NEXT %ld is not %ld+20!\n", jb_next(cur->jb), next);
+					//              if(frame.type == JB_TYPE_VOICE && next + 20 != jb_next(cur->jb)) fprintf(stderr, "NEXT %ld is not %ld+20!\n", jb_next(cur->jb), next);
 					event = frame.data;
 					event = handle_event(event);
 					if (event) {
@@ -3239,25 +3107,25 @@
 					}
 					break;
 				case JB_INTERP:
-					//			    if(next + 20 != jb_next(cur->jb)) fprintf(stderr, "NEXT %ld is not %ld+20!\n", jb_next(cur->jb), next);
+					//              if(next + 20 != jb_next(cur->jb)) fprintf(stderr, "NEXT %ld is not %ld+20!\n", jb_next(cur->jb), next);
 					/* create an interpolation frame */
 					//fprintf(stderr, "Making Interpolation frame\n");
-					event = (struct iax_event *)malloc(sizeof(struct iax_event));
+					event = (struct iax_event *) malloc(sizeof(struct iax_event));
 					if (event) {
-						event->etype    = IAX_EVENT_VOICE;
+						event->etype = IAX_EVENT_VOICE;
 						event->subclass = cur->voiceformat;
-						event->ts	    = now; /* XXX: ??? applications probably ignore this anyway */
-						event->session  = cur;
-						event->datalen  = 0;
+						event->ts = now;	/* XXX: ??? applications probably ignore this anyway */
+						event->session = cur;
+						event->datalen = 0;
 						event = handle_event(event);
-						if(event) {
+						if (event) {
 							iax_mutex_unlock(session_mutex);
 							return event;
 						}
 					}
 					break;
 				case JB_DROP:
-					//			    if(next != jb_next(cur->jb)) fprintf(stderr, "NEXT %ld is not next %ld!\n", jb_next(cur->jb), next);
+					//              if(next != jb_next(cur->jb)) fprintf(stderr, "NEXT %ld is not next %ld!\n", jb_next(cur->jb), next);
 					iax_event_free(frame.data);
 					break;
 				case JB_NOFRAME:
@@ -3269,7 +3137,7 @@
 					break;
 				}
 			}
-	    }
+		}
 		iax_mutex_unlock(session_mutex);
 	}
 
@@ -3279,97 +3147,89 @@
 		/* Block until there is data if desired */
 		fd_set fds;
 		time_in_ms_t nextEventTime;
-		
+
 		FD_ZERO(&fds);
 		FD_SET(netfd, &fds);
 
-		nextEventTime = iax_time_to_next_event(); 
-		if(nextEventTime < 0 && blocking > 1) {
+		nextEventTime = iax_time_to_next_event();
+		if (nextEventTime < 0 && blocking > 1) {
 			nextEventTime = blocking;
 		}
-		if(nextEventTime < 0) 
+		if (nextEventTime < 0)
 			select(netfd + 1, &fds, NULL, NULL, NULL);
-		else 
-		{ 
-			struct timeval nextEvent; 
+		else {
+			struct timeval nextEvent;
 
-			nextEvent.tv_sec = (long)(nextEventTime / 1000); 
-			nextEvent.tv_usec = (long)((nextEventTime % 1000) * 1000);
+			nextEvent.tv_sec = (long) (nextEventTime / 1000);
+			nextEvent.tv_usec = (long) ((nextEventTime % 1000) * 1000);
 
-			select(netfd + 1, &fds, NULL, NULL, &nextEvent); 
-		} 
+			select(netfd + 1, &fds, NULL, NULL, &nextEvent);
+		}
 
 	}
 	event = iax_net_read();
-	
+
 	return handle_event(event);
 }
 
-struct sockaddr_in iax_get_peer_addr(struct iax_session *session)
-{
+struct sockaddr_in iax_get_peer_addr(struct iax_session *session) {
 	return session->peeraddr;
 }
 
-char *iax_get_peer_ip(struct iax_session *session)
-{
+char *iax_get_peer_ip(struct iax_session *session) {
 	return inet_ntoa(session->peeraddr.sin_addr);
 }
 
-char *iax_event_get_apparent_ip(struct iax_event *event)
-{
+char *iax_event_get_apparent_ip(struct iax_event *event) {
 	return inet_ntoa(event->ies.apparent_addr->sin_addr);
 }
 
-void iax_session_destroy(struct iax_session **session) 
-{
-	iax_mutex_lock(session_mutex); 
+void iax_session_destroy(struct iax_session **session) {
+	iax_mutex_lock(session_mutex);
 	destroy_session(*session);
 	*session = NULL;
-	iax_mutex_unlock(session_mutex); 
+	iax_mutex_unlock(session_mutex);
 }
 
-void iax_event_free(struct iax_event *event)
-{
+void iax_event_free(struct iax_event *event) {
 	/* 
 	   We gave the user a chance to play with the session now we need to destroy it 
 	   if you are not calling this function on every event you read you are now going
 	   to leak sessions as well as events!
-	*/
-	switch(event->etype) {
+	 */
+	switch (event->etype) {
 	case IAX_EVENT_REJECT:
 	case IAX_EVENT_HANGUP:
 		/* Destroy this session -- it's no longer valid */
-		if (event->session) { /* maybe the user did it already */
-			iax_mutex_lock(session_mutex); 
+		if (event->session) {	/* maybe the user did it already */
+			iax_mutex_lock(session_mutex);
 			destroy_session(event->session);
-			iax_mutex_unlock(session_mutex); 
+			iax_mutex_unlock(session_mutex);
 		}
 		break;
 	}
 	free(event);
 }
 
-int iax_get_fd(void) 
-{
+int iax_get_fd(void) {
 	/* Return our network file descriptor.  The client can select on this (probably with other
 	   things, or can add it to a network add sort of gtk_input_add for example */
 	return netfd;
 }
 
-int iax_quelch_moh(struct iax_session *session, int MOH)
-{
-	
-	struct iax_ie_data ied;			//IE Data Structure (Stuff To Send)
-	memset(&ied, 0, sizeof(ied));	
-	
+int iax_quelch_moh(struct iax_session *session, int MOH) {
+
+	struct iax_ie_data ied;		//IE Data Structure (Stuff To Send)
+	memset(&ied, 0, sizeof(ied));
+
 	// You can't quelch the quelched
 	if (session->quelch == 1)
 		return -1;
-		
+
 	if (MOH) {
 		iax_ie_append(&ied, IAX_IE_MUSICONHOLD);
 		session->transfer_moh = 1;
 	}
-		
+
 	return send_command(session, AST_FRAME_IAX, IAX_COMMAND_QUELCH, 0, ied.buf, ied.pos, -1);
 }

Modified: freeswitch/trunk/src/mod/endpoints/mod_iax/iax2-parser.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_iax/iax2-parser.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_iax/iax2-parser.c	Tue May 27 00:54:52 2008
@@ -40,12 +40,12 @@
 #ifdef ALIGN32
 static unsigned int get_uint32(unsigned char *p)
 {
-  return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
+	return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
 }
 
 static unsigned short get_uint16(unsigned char *p)
 {
-  return (p[0] << 8) | p[1] ;
+	return (p[0] << 8) | p[1];
 }
 
 #else
@@ -64,8 +64,8 @@
 	fprintf(stderr, "WARNING: %s", str);
 }
 
-static void (*outputf)(const char *str) = internaloutput;
-static void (*errorf)(const char *str) = internalerror;
+static void (*outputf) (const char *str) = internaloutput;
+static void (*errorf) (const char *str) = internalerror;
 
 static void dump_addr(char *output, int maxlen, void *value, int len)
 {
@@ -83,21 +83,21 @@
 	maxlen--;
 	if (maxlen > len)
 		maxlen = len;
-	strncpy(output,value, maxlen);
+	strncpy(output, value, maxlen);
 	output[maxlen] = '\0';
 }
 
 static void dump_int(char *output, int maxlen, void *value, int len)
 {
-	if (len == (int)sizeof(unsigned int))
-		snprintf(output, maxlen, "%lu", (unsigned long)ntohl(get_uint32(value)));
+	if (len == (int) sizeof(unsigned int))
+		snprintf(output, maxlen, "%lu", (unsigned long) ntohl(get_uint32(value)));
 	else
 		snprintf(output, maxlen, "Invalid INT");
 }
 
 static void dump_short(char *output, int maxlen, void *value, int len)
 {
-	if (len == (int)sizeof(unsigned short))
+	if (len == (int) sizeof(unsigned short))
 		snprintf(output, maxlen, "%d", ntohs(get_uint16(value)));
 	else
 		snprintf(output, maxlen, "Invalid SHORT");
@@ -105,8 +105,8 @@
 
 static void dump_byte(char *output, int maxlen, void *value, int len)
 {
-	if (len == (int)sizeof(unsigned char))
-		snprintf(output, maxlen, "%d", *((unsigned char *)value));
+	if (len == (int) sizeof(unsigned char))
+		snprintf(output, maxlen, "%d", *((unsigned char *) value));
 	else
 		snprintf(output, maxlen, "Invalid BYTE");
 }
@@ -115,7 +115,7 @@
 static void dump_ipaddr(char *output, int maxlen, void *value, int len)
 {
 	struct sockaddr_in sin;
-	if (len == (int)sizeof(unsigned int)) {
+	if (len == (int) sizeof(unsigned int)) {
 		memcpy(&sin.sin_addr, value, len);
 		snprintf(output, maxlen, "%s", inet_ntoa(sin.sin_addr));
 	} else
@@ -124,9 +124,8 @@
 
 static void dump_prov_flags(char *output, int maxlen, void *value, int len)
 {
-	if (len == (int)sizeof(unsigned int))
-		snprintf(output, maxlen, "%lu (%s)", (unsigned long)ntohl(get_uint32(value)),
-			"PROVISION_PARSING_NOT_IMPLEMENTED");
+	if (len == (int) sizeof(unsigned int))
+		snprintf(output, maxlen, "%lu (%s)", (unsigned long) ntohl(get_uint32(value)), "PROVISION_PARSING_NOT_IMPLEMENTED");
 	else
 		snprintf(output, maxlen, "Invalid INT");
 }
@@ -134,10 +133,10 @@
 
 static void dump_samprate(char *output, int maxlen, void *value, int len)
 {
-	char tmp[256]="";
+	char tmp[256] = "";
 	int sr;
-	if (len == (int)sizeof(unsigned short)) {
-		sr = ntohs(*((unsigned short *)value));
+	if (len == (int) sizeof(unsigned short)) {
+		sr = ntohs(*((unsigned short *) value));
 		if (sr & IAX_RATE_8KHZ)
 			strcat(tmp, ",8khz");
 		if (sr & IAX_RATE_11KHZ)
@@ -170,61 +169,61 @@
 static struct iax2_ie {
 	int ie;
 	char *name;
-	void (*dump)(char *output, int maxlen, void *value, int len);
+	void (*dump) (char *output, int maxlen, void *value, int len);
 } ies[] = {
-	{ IAX_IE_CALLED_NUMBER, "CALLED NUMBER", dump_string },
-	{ IAX_IE_CALLING_NUMBER, "CALLING NUMBER", dump_string },
-	{ IAX_IE_CALLING_ANI, "ANI", dump_string },
-	{ IAX_IE_CALLING_NAME, "CALLING NAME", dump_string },
-	{ IAX_IE_CALLED_CONTEXT, "CALLED CONTEXT", dump_string },
-	{ IAX_IE_USERNAME, "USERNAME", dump_string },
-	{ IAX_IE_PASSWORD, "PASSWORD", dump_string },
-	{ IAX_IE_CAPABILITY, "CAPABILITY", dump_int },
-	{ IAX_IE_FORMAT, "FORMAT", dump_int },
-	{ IAX_IE_LANGUAGE, "LANGUAGE", dump_string },
-	{ IAX_IE_CODEC_PREFS, "CODEC_PREFS", dump_string },
-	{ IAX_IE_VERSION, "VERSION", dump_short },
-	{ IAX_IE_ADSICPE, "ADSICPE", dump_short },
-	{ IAX_IE_DNID, "DNID", dump_string },
-	{ IAX_IE_AUTHMETHODS, "AUTHMETHODS", dump_short },
-	{ IAX_IE_CHALLENGE, "CHALLENGE", dump_string },
-	{ IAX_IE_MD5_RESULT, "MD5 RESULT", dump_string },
-	{ IAX_IE_RSA_RESULT, "RSA RESULT", dump_string },
-	{ IAX_IE_APPARENT_ADDR, "APPARENT ADDRESS", dump_addr },
-	{ IAX_IE_REFRESH, "REFRESH", dump_short },
-	{ IAX_IE_DPSTATUS, "DIALPLAN STATUS", dump_short },
-	{ IAX_IE_CALLNO, "CALL NUMBER", dump_short },
-	{ IAX_IE_CAUSE, "CAUSE", dump_string },
-	{ IAX_IE_IAX_UNKNOWN, "UNKNOWN IAX CMD", dump_byte },
-	{ IAX_IE_MSGCOUNT, "MESSAGE COUNT", dump_short },
-	{ IAX_IE_AUTOANSWER, "AUTO ANSWER REQ" },
-	{ IAX_IE_TRANSFERID, "TRANSFER ID", dump_int },
-	{ IAX_IE_RDNIS, "REFERRING DNIS", dump_string },
-	{ IAX_IE_PROVISIONING, "PROVISIONING", dump_prov },
-	{ IAX_IE_AESPROVISIONING, "AES PROVISIONG" },
-	{ IAX_IE_DATETIME, "DATE TIME", dump_int },
-	{ IAX_IE_DEVICETYPE, "DEVICE TYPE", dump_string },
-	{ IAX_IE_SERVICEIDENT, "SERVICE IDENT", dump_string },
-	{ IAX_IE_FIRMWAREVER, "FIRMWARE VER", dump_short },
-	{ IAX_IE_FWBLOCKDESC, "FW BLOCK DESC", dump_int },
-	{ IAX_IE_FWBLOCKDATA, "FW BLOCK DATA" },
-	{ IAX_IE_PROVVER, "PROVISIONG VER", dump_int },
-	{ IAX_IE_CALLINGPRES, "CALLING PRESNTN", dump_byte },
-	{ IAX_IE_CALLINGTON, "CALLING TYPEOFNUM", dump_byte },
-	{ IAX_IE_CALLINGTNS, "CALLING TRANSITNET", dump_short },
-	{ IAX_IE_SAMPLINGRATE, "SAMPLINGRATE", dump_samprate },
-	{ IAX_IE_RR_JITTER, "RR_JITTER", dump_int },
-	{ IAX_IE_RR_LOSS, "RR_LOSS", dump_int },
-	{ IAX_IE_RR_PKTS, "RR_PKTS", dump_int },
-	{ IAX_IE_RR_DELAY, "RR_DELAY", dump_short },
-	{ IAX_IE_RR_DROPPED, "RR_DROPPED", dump_int },
-	{ IAX_IE_RR_OOO, "RR_OOO", dump_int },
-};
+	{
+	IAX_IE_CALLED_NUMBER, "CALLED NUMBER", dump_string}, {
+	IAX_IE_CALLING_NUMBER, "CALLING NUMBER", dump_string}, {
+	IAX_IE_CALLING_ANI, "ANI", dump_string}, {
+	IAX_IE_CALLING_NAME, "CALLING NAME", dump_string}, {
+	IAX_IE_CALLED_CONTEXT, "CALLED CONTEXT", dump_string}, {
+	IAX_IE_USERNAME, "USERNAME", dump_string}, {
+	IAX_IE_PASSWORD, "PASSWORD", dump_string}, {
+	IAX_IE_CAPABILITY, "CAPABILITY", dump_int}, {
+	IAX_IE_FORMAT, "FORMAT", dump_int}, {
+	IAX_IE_LANGUAGE, "LANGUAGE", dump_string}, {
+	IAX_IE_CODEC_PREFS, "CODEC_PREFS", dump_string}, {
+	IAX_IE_VERSION, "VERSION", dump_short}, {
+	IAX_IE_ADSICPE, "ADSICPE", dump_short}, {
+	IAX_IE_DNID, "DNID", dump_string}, {
+	IAX_IE_AUTHMETHODS, "AUTHMETHODS", dump_short}, {
+	IAX_IE_CHALLENGE, "CHALLENGE", dump_string}, {
+	IAX_IE_MD5_RESULT, "MD5 RESULT", dump_string}, {
+	IAX_IE_RSA_RESULT, "RSA RESULT", dump_string}, {
+	IAX_IE_APPARENT_ADDR, "APPARENT ADDRESS", dump_addr}, {
+	IAX_IE_REFRESH, "REFRESH", dump_short}, {
+	IAX_IE_DPSTATUS, "DIALPLAN STATUS", dump_short}, {
+	IAX_IE_CALLNO, "CALL NUMBER", dump_short}, {
+	IAX_IE_CAUSE, "CAUSE", dump_string}, {
+	IAX_IE_IAX_UNKNOWN, "UNKNOWN IAX CMD", dump_byte}, {
+	IAX_IE_MSGCOUNT, "MESSAGE COUNT", dump_short}, {
+	IAX_IE_AUTOANSWER, "AUTO ANSWER REQ"}, {
+	IAX_IE_TRANSFERID, "TRANSFER ID", dump_int}, {
+	IAX_IE_RDNIS, "REFERRING DNIS", dump_string}, {
+	IAX_IE_PROVISIONING, "PROVISIONING", dump_prov}, {
+	IAX_IE_AESPROVISIONING, "AES PROVISIONG"}, {
+	IAX_IE_DATETIME, "DATE TIME", dump_int}, {
+	IAX_IE_DEVICETYPE, "DEVICE TYPE", dump_string}, {
+	IAX_IE_SERVICEIDENT, "SERVICE IDENT", dump_string}, {
+	IAX_IE_FIRMWAREVER, "FIRMWARE VER", dump_short}, {
+	IAX_IE_FWBLOCKDESC, "FW BLOCK DESC", dump_int}, {
+	IAX_IE_FWBLOCKDATA, "FW BLOCK DATA"}, {
+	IAX_IE_PROVVER, "PROVISIONG VER", dump_int}, {
+	IAX_IE_CALLINGPRES, "CALLING PRESNTN", dump_byte}, {
+	IAX_IE_CALLINGTON, "CALLING TYPEOFNUM", dump_byte}, {
+	IAX_IE_CALLINGTNS, "CALLING TRANSITNET", dump_short}, {
+	IAX_IE_SAMPLINGRATE, "SAMPLINGRATE", dump_samprate}, {
+	IAX_IE_RR_JITTER, "RR_JITTER", dump_int}, {
+	IAX_IE_RR_LOSS, "RR_LOSS", dump_int}, {
+	IAX_IE_RR_PKTS, "RR_PKTS", dump_int}, {
+	IAX_IE_RR_DELAY, "RR_DELAY", dump_short}, {
+	IAX_IE_RR_DROPPED, "RR_DROPPED", dump_int}, {
+IAX_IE_RR_OOO, "RR_OOO", dump_int},};
 
 const char *iax_ie2str(int ie)
 {
 	int x;
-	for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) {
+	for (x = 0; x < (int) sizeof(ies) / (int) sizeof(ies[0]); x++) {
 		if (ies[x].ie == ie)
 			return ies[x].name;
 	}
@@ -240,22 +239,25 @@
 	char tmp[256];
 	if (len < 2)
 		return;
-	strcpy(output, "\n"); 
-	maxlen -= (int)strlen(output); output += strlen(output);
-	while(len > 2) {
+	strcpy(output, "\n");
+	maxlen -= (int) strlen(output);
+	output += strlen(output);
+	while (len > 2) {
 		ie = iedata[0];
 		ielen = iedata[1];
-		if (ielen + 2> len) {
-			snprintf(tmp, (int)sizeof(tmp), "Total Prov IE length of %d bytes exceeds remaining prov frame length of %d bytes\n", ielen + 2, len);
+		if (ielen + 2 > len) {
+			snprintf(tmp, (int) sizeof(tmp), "Total Prov IE length of %d bytes exceeds remaining prov frame length of %d bytes\n", ielen + 2, len);
 			strncpy(output, tmp, maxlen - 1);
-			maxlen -= (int)strlen(output); output += strlen(output);
+			maxlen -= (int) strlen(output);
+			output += strlen(output);
 			return;
 		}
 		found = 0;
 		if (!found) {
-			snprintf(tmp, (int)sizeof(tmp), "       Unknown Prov IE %03d  : Present\n", ie);
+			snprintf(tmp, (int) sizeof(tmp), "       Unknown Prov IE %03d  : Present\n", ie);
 			strncpy(output, tmp, maxlen - 1);
-			maxlen -= (int)strlen(output); output += strlen(output);
+			maxlen -= (int) strlen(output);
+			output += strlen(output);
 		}
 		iedata += (2 + ielen);
 		len -= (2 + ielen);
@@ -272,34 +274,34 @@
 	char tmp[1024];
 	if (len < 2)
 		return;
-	while(len > 2) {
+	while (len > 2) {
 		ie = iedata[0];
 		ielen = iedata[1];
-		if (ielen + 2> len) {
-			snprintf(tmp, (int)sizeof(tmp), "Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2, len);
+		if (ielen + 2 > len) {
+			snprintf(tmp, (int) sizeof(tmp), "Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2, len);
 			outputf(tmp);
 			return;
 		}
 		found = 0;
-		for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) {
+		for (x = 0; x < (int) sizeof(ies) / (int) sizeof(ies[0]); x++) {
 			if (ies[x].ie == ie) {
 				if (ies[x].dump) {
-					ies[x].dump(interp, (int)sizeof(interp), iedata + 2, ielen);
-					snprintf(tmp, (int)sizeof(tmp), "   %-15.15s : %s\n", ies[x].name, interp);
+					ies[x].dump(interp, (int) sizeof(interp), iedata + 2, ielen);
+					snprintf(tmp, (int) sizeof(tmp), "   %-15.15s : %s\n", ies[x].name, interp);
 					outputf(tmp);
 				} else {
 					if (ielen)
-						snprintf(interp, (int)sizeof(interp), "%d bytes", ielen);
+						snprintf(interp, (int) sizeof(interp), "%d bytes", ielen);
 					else
 						strcpy(interp, "Present");
-					snprintf(tmp, (int)sizeof(tmp), "   %-15.15s : %s\n", ies[x].name, interp);
+					snprintf(tmp, (int) sizeof(tmp), "   %-15.15s : %s\n", ies[x].name, interp);
 					outputf(tmp);
 				}
 				found++;
 			}
 		}
 		if (!found) {
-			snprintf(tmp, (int)sizeof(tmp), "   Unknown IE %03d  : Present\n", ie);
+			snprintf(tmp, (int) sizeof(tmp), "   Unknown IE %03d  : Present\n", ie);
 			outputf(tmp);
 		}
 		iedata += (2 + ielen);
@@ -319,7 +321,8 @@
 		"NULL   ",
 		"IAX    ",
 		"TEXT   ",
-		"IMAGE  " };
+		"IMAGE  "
+	};
 	const char *iaxs[] = {
 		"(0?)",
 		"NEW    ",
@@ -368,7 +371,8 @@
 		"ANSWER ",
 		"BUSY   ",
 		"TKOFFHK ",
-		"OFFHOOK" };
+		"OFFHOOK"
+	};
 	struct ast_iax2_full_hdr *fh;
 	char retries[20];
 	char class2[20];
@@ -379,7 +383,7 @@
 
 	if (f) {
 		fh = f->data;
-		snprintf(retries, (int)sizeof(retries), "%03d", f->retries);
+		snprintf(retries, (int) sizeof(retries), "%03d", f->retries);
 	} else {
 		fh = fhi;
 		if (ntohs(fh->dcallno) & IAX_FLAG_RETRANS)
@@ -391,43 +395,41 @@
 		/* Don't mess with mini-frames */
 		return;
 	}
-	if (fh->type > ((int)sizeof(frames)/(int)sizeof(char *)) - 1) {
-		snprintf(class2, (int)sizeof(class2), "(%d?)", fh->type);
+	if (fh->type > ((int) sizeof(frames) / (int) sizeof(char *)) - 1) {
+		snprintf(class2, (int) sizeof(class2), "(%d?)", fh->type);
 		class = class2;
 	} else {
-		class = frames[(int)fh->type];
+		class = frames[(int) fh->type];
 	}
 	if (fh->type == AST_FRAME_DTMF) {
 		sprintf(subclass2, "%c", fh->csub);
 		subclass = subclass2;
 	} else if (fh->type == AST_FRAME_IAX) {
-		if (fh->csub >= (int)sizeof(iaxs)/(int)sizeof(iaxs[0])) {
-			snprintf(subclass2, (int)sizeof(subclass2), "(%d?)", fh->csub);
+		if (fh->csub >= (int) sizeof(iaxs) / (int) sizeof(iaxs[0])) {
+			snprintf(subclass2, (int) sizeof(subclass2), "(%d?)", fh->csub);
 			subclass = subclass2;
 		} else {
-			subclass = iaxs[(int)fh->csub];
+			subclass = iaxs[(int) fh->csub];
 		}
 	} else if (fh->type == AST_FRAME_CONTROL) {
-		if (fh->csub > (int)sizeof(cmds)/(int)sizeof(char *)) {
-			snprintf(subclass2, (int)sizeof(subclass2), "(%d?)", fh->csub);
+		if (fh->csub > (int) sizeof(cmds) / (int) sizeof(char *)) {
+			snprintf(subclass2, (int) sizeof(subclass2), "(%d?)", fh->csub);
 			subclass = subclass2;
 		} else {
-			subclass = cmds[(int)fh->csub];
+			subclass = cmds[(int) fh->csub];
 		}
 	} else {
-		snprintf(subclass2, (int)sizeof(subclass2), "%d", fh->csub);
+		snprintf(subclass2, (int) sizeof(subclass2), "%d", fh->csub);
 		subclass = subclass2;
 	}
-snprintf(tmp, (int)sizeof(tmp), 
-"%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s Subclass: %s\n",
-	(rx ? "Rx" : "Tx"),
-	retries, fh->oseqno, fh->iseqno, class, subclass);
+	snprintf(tmp, (int) sizeof(tmp),
+			 "%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s Subclass: %s\n",
+			 (rx ? "Rx" : "Tx"), retries, fh->oseqno, fh->iseqno, class, subclass);
 	outputf(tmp);
-snprintf(tmp, (int)sizeof(tmp), 
-"   Timestamp: %05lums  SCall: %5.5d  DCall: %5.5d [%s:%d]\n",
-	(unsigned long)ntohl(fh->ts),
-	ntohs(fh->scallno) & ~IAX_FLAG_FULL, ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS,
-		inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
+	snprintf(tmp, (int) sizeof(tmp),
+			 "   Timestamp: %05lums  SCall: %5.5d  DCall: %5.5d [%s:%d]\n",
+			 (unsigned long) ntohl(fh->ts),
+			 ntohs(fh->scallno) & ~IAX_FLAG_FULL, ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS, inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
 	outputf(tmp);
 	if (fh->type == AST_FRAME_IAX)
 		dump_ies(fh->iedata, datalen);
@@ -436,13 +438,14 @@
 int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, const void *data, int datalen)
 {
 	char tmp[256];
-	if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
-		snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", iax_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
+	if (datalen > ((int) sizeof(ied->buf) - ied->pos)) {
+		snprintf(tmp, (int) sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", iax_ie2str(ie), ie, datalen,
+				 (int) sizeof(ied->buf) - ied->pos);
 		errorf(tmp);
 		return -1;
 	}
 	ied->buf[ied->pos++] = ie;
-	ied->buf[ied->pos++] = (unsigned char)datalen;
+	ied->buf[ied->pos++] = (unsigned char) datalen;
 	memcpy(ied->buf + ied->pos, data, datalen);
 	ied->pos += datalen;
 	return 0;
@@ -450,26 +453,26 @@
 
 int iax_ie_append_addr(struct iax_ie_data *ied, unsigned char ie, struct sockaddr_in *sin)
 {
-	return iax_ie_append_raw(ied, ie, sin, (int)sizeof(struct sockaddr_in));
+	return iax_ie_append_raw(ied, ie, sin, (int) sizeof(struct sockaddr_in));
 }
 
-int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value) 
+int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value)
 {
 	unsigned int newval;
 	newval = htonl(value);
-	return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
+	return iax_ie_append_raw(ied, ie, &newval, (int) sizeof(newval));
 }
 
-int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value) 
+int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value)
 {
 	unsigned short newval;
 	newval = htons(value);
-	return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
+	return iax_ie_append_raw(ied, ie, &newval, (int) sizeof(newval));
 }
 
 int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, const unsigned char *str)
 {
-	return iax_ie_append_raw(ied, ie, str, (int)strlen((char *) str));
+	return iax_ie_append_raw(ied, ie, str, (int) strlen((char *) str));
 }
 
 int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char dat)
@@ -477,17 +480,17 @@
 	return iax_ie_append_raw(ied, ie, &dat, 1);
 }
 
-int iax_ie_append(struct iax_ie_data *ied, unsigned char ie) 
+int iax_ie_append(struct iax_ie_data *ied, unsigned char ie)
 {
 	return iax_ie_append_raw(ied, ie, NULL, 0);
 }
 
-void iax_set_output(void (*func)(const char *))
+void iax_set_output(void (*func) (const char *))
 {
 	outputf = func;
 }
 
-void iax_set_error(void (*func)(const char *))
+void iax_set_error(void (*func) (const char *))
 {
 	errorf = func;
 }
@@ -498,21 +501,21 @@
 	int len;
 	int ie;
 	char tmp[256];
-	memset(my_ies, 0, (int)sizeof(struct iax_ies));
+	memset(my_ies, 0, (int) sizeof(struct iax_ies));
 	my_ies->msgcount = -1;
 	my_ies->firmwarever = -1;
 	my_ies->calling_ton = -1;
 	my_ies->calling_tns = -1;
 	my_ies->calling_pres = -1;
 	my_ies->samprate = IAX_RATE_8KHZ;
-	while(datalen >= 2) {
+	while (datalen >= 2) {
 		ie = data[0];
 		len = data[1];
 		if (len > datalen - 2) {
 			errorf("Information element length exceeds message size\n");
 			return -1;
 		}
-		switch(ie) {
+		switch (ie) {
 		case IAX_IE_CALLED_NUMBER:
 			my_ies->called_number = (char *) data + 2;
 			break;
@@ -535,15 +538,15 @@
 			my_ies->password = (char *) data + 2;
 			break;
 		case IAX_IE_CAPABILITY:
-			if (len != (int)sizeof(unsigned int)) {
-				snprintf(tmp, (int)sizeof(tmp), "Expecting capability to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
+			if (len != (int) sizeof(unsigned int)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expecting capability to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
 				errorf(tmp);
 			} else
 				my_ies->capability = ntohl(get_uint32(data + 2));
 			break;
 		case IAX_IE_FORMAT:
-			if (len != (int)sizeof(unsigned int)) {
-				snprintf(tmp, (int)sizeof(tmp), "Expecting format to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
+			if (len != (int) sizeof(unsigned int)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expecting format to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
 				errorf(tmp);
 			} else
 				my_ies->format = ntohl(get_uint32(data + 2));
@@ -555,22 +558,22 @@
 			my_ies->codec_prefs = (char *) data + 2;
 			break;
 		case IAX_IE_VERSION:
-			if (len != (int)sizeof(unsigned short)) {
-				snprintf(tmp, (int)sizeof(tmp),  "Expecting version to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
+			if (len != (int) sizeof(unsigned short)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expecting version to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
 				errorf(tmp);
 			} else
 				my_ies->version = ntohs(get_uint16(data + 2));
 			break;
 		case IAX_IE_ADSICPE:
-			if (len != (int)sizeof(unsigned short)) {
-				snprintf(tmp, (int)sizeof(tmp), "Expecting adsicpe to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
+			if (len != (int) sizeof(unsigned short)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expecting adsicpe to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
 				errorf(tmp);
 			} else
 				my_ies->adsicpe = ntohs(get_uint16(data + 2));
 			break;
 		case IAX_IE_SAMPLINGRATE:
-			if (len != (int)sizeof(unsigned short)) {
-				snprintf(tmp, (int)sizeof(tmp), "Expecting samplingrate to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
+			if (len != (int) sizeof(unsigned short)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expecting samplingrate to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
 				errorf(tmp);
 			} else
 				my_ies->samprate = ntohs(get_uint16(data + 2));
@@ -582,8 +585,8 @@
 			my_ies->rdnis = (char *) data + 2;
 			break;
 		case IAX_IE_AUTHMETHODS:
-			if (len != (int)sizeof(unsigned short))  {
-				snprintf(tmp, (int)sizeof(tmp), "Expecting authmethods to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
+			if (len != (int) sizeof(unsigned short)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expecting authmethods to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
 				errorf(tmp);
 			} else
 				my_ies->authmethods = ntohs(get_uint16(data + 2));
@@ -598,25 +601,25 @@
 			my_ies->rsa_result = (char *) data + 2;
 			break;
 		case IAX_IE_APPARENT_ADDR:
-			my_ies->apparent_addr = ((struct sockaddr_in *)(data + 2));
+			my_ies->apparent_addr = ((struct sockaddr_in *) (data + 2));
 			break;
 		case IAX_IE_REFRESH:
-			if (len != (int)sizeof(unsigned short)) {
-				snprintf(tmp, (int)sizeof(tmp),  "Expecting refresh to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
+			if (len != (int) sizeof(unsigned short)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expecting refresh to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
 				errorf(tmp);
 			} else
 				my_ies->refresh = ntohs(get_uint16(data + 2));
 			break;
 		case IAX_IE_DPSTATUS:
-			if (len != (int)sizeof(unsigned short)) {
-				snprintf(tmp, (int)sizeof(tmp),  "Expecting dpstatus to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
+			if (len != (int) sizeof(unsigned short)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expecting dpstatus to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
 				errorf(tmp);
 			} else
 				my_ies->dpstatus = ntohs(get_uint16(data + 2));
 			break;
 		case IAX_IE_CALLNO:
-			if (len != (int)sizeof(unsigned short)) {
-				snprintf(tmp, (int)sizeof(tmp),  "Expecting callno to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
+			if (len != (int) sizeof(unsigned short)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expecting callno to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
 				errorf(tmp);
 			} else
 				my_ies->callno = ntohs(get_uint16(data + 2));
@@ -626,7 +629,7 @@
 			break;
 		case IAX_IE_CAUSECODE:
 			if (len != 1) {
-				snprintf(tmp, (int)sizeof(tmp), "Expecting causecode to be single byte but was %d\n", len);
+				snprintf(tmp, (int) sizeof(tmp), "Expecting causecode to be single byte but was %d\n", len);
 				errorf(tmp);
 			} else {
 				my_ies->causecode = data[2];
@@ -636,16 +639,16 @@
 			if (len == 1)
 				my_ies->iax_unknown = data[2];
 			else {
-				snprintf(tmp, (int)sizeof(tmp), "Expected single byte Unknown command, but was %d long\n", len);
+				snprintf(tmp, (int) sizeof(tmp), "Expected single byte Unknown command, but was %d long\n", len);
 				errorf(tmp);
 			}
 			break;
 		case IAX_IE_MSGCOUNT:
-			if (len != (int)sizeof(unsigned short)) {
-				snprintf(tmp, (int)sizeof(tmp), "Expecting msgcount to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
+			if (len != (int) sizeof(unsigned short)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expecting msgcount to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
 				errorf(tmp);
 			} else
-				my_ies->msgcount = ntohs(get_uint16(data + 2));	
+				my_ies->msgcount = ntohs(get_uint16(data + 2));
 			break;
 		case IAX_IE_AUTOANSWER:
 			my_ies->autoanswer = 1;
@@ -654,25 +657,25 @@
 			my_ies->musiconhold = 1;
 			break;
 		case IAX_IE_TRANSFERID:
-			if (len != (int)sizeof(unsigned int)) {
-				snprintf(tmp, (int)sizeof(tmp), "Expecting transferid to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
+			if (len != (int) sizeof(unsigned int)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expecting transferid to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
 				errorf(tmp);
 			} else
 				my_ies->transferid = ntohl(get_uint32(data + 2));
 			break;
 		case IAX_IE_DATETIME:
-			if (len != (int)sizeof(unsigned int)) {
-				snprintf(tmp, (int)sizeof(tmp), "Expecting date/time to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
+			if (len != (int) sizeof(unsigned int)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expecting date/time to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
 				errorf(tmp);
 			} else
 				my_ies->datetime = ntohl(get_uint32(data + 2));
 			break;
 		case IAX_IE_FIRMWAREVER:
-			if (len != (int)sizeof(unsigned short)) {
-				snprintf(tmp, (int)sizeof(tmp), "Expecting firmwarever to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
+			if (len != (int) sizeof(unsigned short)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expecting firmwarever to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
 				errorf(tmp);
 			} else
-				my_ies->firmwarever = ntohs(get_uint16(data + 2));	
+				my_ies->firmwarever = ntohs(get_uint16(data + 2));
 			break;
 		case IAX_IE_DEVICETYPE:
 			my_ies->devicetype = (char *) data + 2;
@@ -681,19 +684,19 @@
 			my_ies->serviceident = (char *) data + 2;
 			break;
 		case IAX_IE_FWBLOCKDESC:
-			if (len != (int)sizeof(unsigned int)) {
-				snprintf(tmp, (int)sizeof(tmp), "Expected block desc to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
+			if (len != (int) sizeof(unsigned int)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expected block desc to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
 				errorf(tmp);
 			} else
 				my_ies->fwdesc = ntohl(get_uint32(data + 2));
 			break;
 		case IAX_IE_FWBLOCKDATA:
 			my_ies->fwdata = data + 2;
-			my_ies->fwdatalen = (unsigned char)len;
+			my_ies->fwdatalen = (unsigned char) len;
 			break;
 		case IAX_IE_PROVVER:
-			if (len != (int)sizeof(unsigned int)) {
-				snprintf(tmp, (int)sizeof(tmp), "Expected provisioning version to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
+			if (len != (int) sizeof(unsigned int)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expected provisioning version to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
 				errorf(tmp);
 			} else {
 				my_ies->provverpres = 1;
@@ -704,7 +707,7 @@
 			if (len == 1)
 				my_ies->calling_pres = data[2];
 			else {
-				snprintf(tmp, (int)sizeof(tmp), "Expected single byte callingpres, but was %d long\n", len);
+				snprintf(tmp, (int) sizeof(tmp), "Expected single byte callingpres, but was %d long\n", len);
 				errorf(tmp);
 			}
 			break;
@@ -712,67 +715,67 @@
 			if (len == 1)
 				my_ies->calling_ton = data[2];
 			else {
-				snprintf(tmp, (int)sizeof(tmp), "Expected single byte callington, but was %d long\n", len);
+				snprintf(tmp, (int) sizeof(tmp), "Expected single byte callington, but was %d long\n", len);
 				errorf(tmp);
 			}
 			break;
 		case IAX_IE_CALLINGTNS:
-			if (len != (int)sizeof(unsigned short)) {
-				snprintf(tmp, (int)sizeof(tmp), "Expecting callingtns to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
+			if (len != (int) sizeof(unsigned short)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expecting callingtns to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
 				errorf(tmp);
 			} else
-				my_ies->calling_tns = ntohs(get_uint16(data + 2));	
+				my_ies->calling_tns = ntohs(get_uint16(data + 2));
 			break;
 		case IAX_IE_RR_JITTER:
-			if (len != (int)sizeof(unsigned int)) {
-				snprintf(tmp, (int)sizeof(tmp), "Expected jitter rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
+			if (len != (int) sizeof(unsigned int)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expected jitter rr to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
 				errorf(tmp);
 			} else {
 				my_ies->rr_jitter = ntohl(get_uint32(data + 2));
 			}
 			break;
 		case IAX_IE_RR_LOSS:
-			if (len != (int)sizeof(unsigned int)) {
-				snprintf(tmp, (int)sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
+			if (len != (int) sizeof(unsigned int)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
 				errorf(tmp);
 			} else {
 				my_ies->rr_loss = ntohl(get_uint32(data + 2));
 			}
 			break;
 		case IAX_IE_RR_PKTS:
-			if (len != (int)sizeof(unsigned int)) {
-				snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
+			if (len != (int) sizeof(unsigned int)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
 				errorf(tmp);
 			} else {
 				my_ies->rr_pkts = ntohl(get_uint32(data + 2));
 			}
 			break;
 		case IAX_IE_RR_DELAY:
-			if (len != (int)sizeof(unsigned short)) {
-				snprintf(tmp, (int)sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
+			if (len != (int) sizeof(unsigned short)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
 				errorf(tmp);
 			} else {
 				my_ies->rr_delay = ntohs(get_uint16(data + 2));
 			}
 			break;
 		case IAX_IE_RR_DROPPED:
-			if (len != (int)sizeof(unsigned int)) {
-				snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
+			if (len != (int) sizeof(unsigned int)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
 				errorf(tmp);
 			} else {
 				my_ies->rr_dropped = ntohl(get_uint32(data + 2));
 			}
 			break;
 		case IAX_IE_RR_OOO:
-			if (len != (int)sizeof(unsigned int)) {
-				snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
+			if (len != (int) sizeof(unsigned int)) {
+				snprintf(tmp, (int) sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
 				errorf(tmp);
 			} else {
 				my_ies->rr_ooo = ntohl(get_uint32(data + 2));
 			}
 			break;
 		default:
-			snprintf(tmp, (int)sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", iax_ie2str(ie), ie, len);
+			snprintf(tmp, (int) sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", iax_ie2str(ie), ie, len);
 			outputf(tmp);
 		}
 		/* Overwrite information element with 0, to null terminate previous portion */
@@ -793,20 +796,20 @@
 {
 	fr->af.frametype = f->frametype;
 	fr->af.subclass = f->subclass;
-	fr->af.mallocd = 0;				/* Our frame is static relative to the container */
+	fr->af.mallocd = 0;			/* Our frame is static relative to the container */
 	fr->af.datalen = f->datalen;
 	fr->af.samples = f->samples;
 	fr->af.offset = AST_FRIENDLY_OFFSET;
 	fr->af.src = f->src;
 	fr->af.data = fr->afdata;
-	if (fr->af.datalen) 
+	if (fr->af.datalen)
 		memcpy(fr->af.data, f->data, fr->af.datalen);
 }
 
 struct iax_frame *iax_frame_new(int direction, int datalen)
 {
 	struct iax_frame *fr;
-	fr = malloc((int)sizeof(struct iax_frame) + datalen);
+	fr = malloc((int) sizeof(struct iax_frame) + datalen);
 	if (fr) {
 		fr->direction = direction;
 		fr->retrans = -1;
@@ -835,6 +838,15 @@
 	frame_count--;
 }
 
-int iax_get_frames(void) { return frame_count; }
-int iax_get_iframes(void) { return iframes; }
-int iax_get_oframes(void) { return oframes; }
+int iax_get_frames(void)
+{
+	return frame_count;
+}
+int iax_get_iframes(void)
+{
+	return iframes;
+}
+int iax_get_oframes(void)
+{
+	return oframes;
+}

Modified: freeswitch/trunk/src/mod/endpoints/mod_iax/jitterbuf.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_iax/jitterbuf.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_iax/jitterbuf.c	Tue May 27 00:54:52 2008
@@ -32,9 +32,9 @@
 #define jb_dbg if (dbgf) dbgf
 
 #ifdef DEEP_DEBUG
-  #define jb_dbg2 if (dbgf) dbgf
+#define jb_dbg2 if (dbgf) dbgf
 #else
-  #define jb_dbg2 if (0) dbgf
+#define jb_dbg2 if (0) dbgf
 #endif
 
 #else
@@ -60,17 +60,17 @@
 	dbgf = dbg;
 }
 
-static void increment_losspct(jitterbuf *jb)
+static void increment_losspct(jitterbuf * jb)
 {
-	jb->info.losspct = (100000 + 499 * jb->info.losspct)/500;
+	jb->info.losspct = (100000 + 499 * jb->info.losspct) / 500;
 }
 
-static void decrement_losspct(jitterbuf *jb)
+static void decrement_losspct(jitterbuf * jb)
 {
-	jb->info.losspct = (499 * jb->info.losspct)/500;
+	jb->info.losspct = (499 * jb->info.losspct) / 500;
 }
 
-void jb_reset(jitterbuf *jb)
+void jb_reset(jitterbuf * jb)
 {
 	/* only save settings */
 	jb_conf s = jb->info.conf;
@@ -82,11 +82,12 @@
 	jb->info.silence_begin_ts = -1;
 }
 
-jitterbuf * jb_new()
+jitterbuf *jb_new()
 {
-	jitterbuf *jb = (jitterbuf *)malloc(sizeof(*jb));
+	jitterbuf *jb = (jitterbuf *) malloc(sizeof(*jb));
 
-	if (!jb) return NULL;
+	if (!jb)
+		return NULL;
 
 	jb->info.conf.target_extra = JB_TARGET_EXTRA;
 
@@ -95,7 +96,7 @@
 	return jb;
 }
 
-void jb_destroy(jitterbuf *jb)
+void jb_destroy(jitterbuf * jb)
 {
 	jb_frame *frame;
 
@@ -116,7 +117,7 @@
 #if 0
 static int longcmp(const void *a, const void *b)
 {
-	return *(long *)a - *(long *)b;
+	return *(long *) a - *(long *) b;
 }
 #endif
 
@@ -124,7 +125,7 @@
 /* maybe later we can make the history buckets variable size, or something? */
 /* drop parameter determines whether we will drop outliers to minimize
  * delay */
-static int history_put(jitterbuf *jb, time_in_ms_t ts, time_in_ms_t now)
+static int history_put(jitterbuf * jb, time_in_ms_t ts, time_in_ms_t now)
 {
 	time_in_ms_t delay = now - (ts - jb->info.resync_offset);
 	time_in_ms_t threshold = 2 * jb->info.jitter + jb->info.conf.resync_threshold;
@@ -144,9 +145,10 @@
 				jb->hist_ptr = 0;
 				jb->hist_maxbuf_valid = 0;
 
-				jb_warn("Resyncing the jb. last_delay %ld, this delay %ld, threshold %ld, new offset %ld\n", jb->info.last_delay, delay, threshold, ts - now);
+				jb_warn("Resyncing the jb. last_delay %ld, this delay %ld, threshold %ld, new offset %ld\n", jb->info.last_delay, delay, threshold,
+						ts - now);
 				jb->info.resync_offset = ts - now;
-				jb->info.last_delay = delay = 0; /* after resync, frame is right on time */
+				jb->info.last_delay = delay = 0;	/* after resync, frame is right on time */
 			} else {
 				return -1;
 			}
@@ -176,18 +178,18 @@
 		goto invalidate;
 
 	/* if the new delay would go into min */
-	if (delay < jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ-1])
+	if (delay < jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ - 1])
 		goto invalidate;
 
 	/* or max.. */
-	if (delay > jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ-1])
+	if (delay > jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ - 1])
 		goto invalidate;
 
 	/* or the kicked delay would be in min */
-	if (kicked <= jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ-1])
+	if (kicked <= jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ - 1])
 		goto invalidate;
 
-	if (kicked >= jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ-1])
+	if (kicked >= jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ - 1])
 		goto invalidate;
 
 	/* if we got here, we don't need to invalidate, 'cause this delay didn't
@@ -196,21 +198,21 @@
 	/* end optimization */
 
 
-invalidate:
+  invalidate:
 	jb->hist_maxbuf_valid = 0;
 	return 0;
 }
 
-static void history_calc_maxbuf(jitterbuf *jb)
+static void history_calc_maxbuf(jitterbuf * jb)
 {
-	int i,j;
+	int i, j;
 
 	if (jb->hist_ptr == 0)
 		return;
 
 
 	/* initialize maxbuf/minbuf to the latest value */
-	for (i=0;i<JB_HISTORY_MAXBUF_SZ;i++) {
+	for (i = 0; i < JB_HISTORY_MAXBUF_SZ; i++) {
 		/*
 		 * jb->hist_maxbuf[i] = jb->history[(jb->hist_ptr-1) % JB_HISTORY_SZ];
 		 * jb->hist_minbuf[i] = jb->history[(jb->hist_ptr-1) % JB_HISTORY_SZ];
@@ -225,14 +227,14 @@
 	/* start at the beginning, or JB_HISTORY_SZ frames ago */
 	i = (jb->hist_ptr > JB_HISTORY_SZ) ? (jb->hist_ptr - JB_HISTORY_SZ) : 0;
 
-	for (;i<jb->hist_ptr;i++) {
-	time_in_ms_t toins = jb->history[i % JB_HISTORY_SZ];
+	for (; i < jb->hist_ptr; i++) {
+		time_in_ms_t toins = jb->history[i % JB_HISTORY_SZ];
 
 		/* if the maxbuf should get this */
-		if (toins > jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ-1])  {
+		if (toins > jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ - 1]) {
 
 			/* insertion-sort it into the maxbuf */
-			for (j=0;j<JB_HISTORY_MAXBUF_SZ;j++) {
+			for (j = 0; j < JB_HISTORY_MAXBUF_SZ; j++) {
 				/* found where it fits */
 				if (toins > jb->hist_maxbuf[j]) {
 					/* move over */
@@ -246,10 +248,10 @@
 		}
 
 		/* if the minbuf should get this */
-		if (toins < jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ-1])  {
+		if (toins < jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ - 1]) {
 
 			/* insertion-sort it into the maxbuf */
-			for (j=0;j<JB_HISTORY_MAXBUF_SZ;j++) {
+			for (j = 0; j < JB_HISTORY_MAXBUF_SZ; j++) {
 				/* found where it fits */
 				if (toins < jb->hist_minbuf[j]) {
 					/* move over */
@@ -261,15 +263,14 @@
 				}
 			}
 		}
-
 #if 0
 		int k;
 		fprintf(stderr, "toins = %ld\n", toins);
 		fprintf(stderr, "maxbuf =");
-		for (k=0;k<JB_HISTORY_MAXBUF_SZ;k++)
+		for (k = 0; k < JB_HISTORY_MAXBUF_SZ; k++)
 			fprintf(stderr, "%ld ", jb->hist_maxbuf[k]);
 		fprintf(stderr, "\nminbuf =");
-		for (k=0;k<JB_HISTORY_MAXBUF_SZ;k++)
+		for (k = 0; k < JB_HISTORY_MAXBUF_SZ; k++)
 			fprintf(stderr, "%ld ", jb->hist_minbuf[k]);
 		fprintf(stderr, "\n");
 #endif
@@ -278,9 +279,9 @@
 	jb->hist_maxbuf_valid = 1;
 }
 
-static void history_get(jitterbuf *jb)
+static void history_get(jitterbuf * jb)
 {
-    time_in_ms_t max, min, jitter;
+	time_in_ms_t max, min, jitter;
 	int index;
 	int count;
 
@@ -312,16 +313,16 @@
 	/* these debug stmts compare the difference between looking at the absolute jitter, and the
 	 * values we get by throwing away the outliers */
 	/*
-	fprintf(stderr, "[%d] min=%d, max=%d, jitter=%d\n", index, min, max, jitter);
-	fprintf(stderr, "[%d] min=%d, max=%d, jitter=%d\n", 0, jb->hist_minbuf[0], jb->hist_maxbuf[0], jb->hist_maxbuf[0]-jb->hist_minbuf[0]);
-	*/
+	   fprintf(stderr, "[%d] min=%d, max=%d, jitter=%d\n", index, min, max, jitter);
+	   fprintf(stderr, "[%d] min=%d, max=%d, jitter=%d\n", 0, jb->hist_minbuf[0], jb->hist_maxbuf[0], jb->hist_maxbuf[0]-jb->hist_minbuf[0]);
+	 */
 
 	jb->info.min = min;
 	jb->info.jitter = jitter;
 }
 
 /* returns 1 if frame was inserted into head of queue, 0 otherwise */
-static int queue_put(jitterbuf *jb, void *data, const enum jb_frame_type type, long ms, time_in_ms_t ts)
+static int queue_put(jitterbuf * jb, void *data, const enum jb_frame_type type, long ms, time_in_ms_t ts)
 {
 	jb_frame *frame = jb->free;
 	jb_frame *p;
@@ -331,7 +332,7 @@
 	if (frame) {
 		jb->free = frame->next;
 	} else {
-		frame = (jb_frame *)malloc(sizeof(*frame));
+		frame = (jb_frame *) malloc(sizeof(*frame));
 		if (!frame) {
 			jb_err("cannot allocate frame\n");
 			return 0;
@@ -350,7 +351,7 @@
 	 * jb->frames->prev points to the highest ts
 	 */
 
-	if (!jb->frames) {  /* queue is empty */
+	if (!jb->frames) {			/* queue is empty */
 		jb->frames = frame;
 		frame->next = frame;
 		frame->prev = frame;
@@ -371,7 +372,8 @@
 		p = jb->frames;
 
 		/* frame is out of order */
-		if (resync_ts < p->prev->ts) jb->info.frames_ooo++;
+		if (resync_ts < p->prev->ts)
+			jb->info.frames_ooo++;
 
 		while (resync_ts < p->prev->ts && p->prev != jb->frames)
 			p = p->prev;
@@ -385,7 +387,7 @@
 	return head;
 }
 
-static time_in_ms_t queue_next(jitterbuf *jb) 
+static time_in_ms_t queue_next(jitterbuf * jb)
 {
 	if (jb->frames)
 		return jb->frames->ts;
@@ -393,7 +395,7 @@
 		return -1;
 }
 
-static time_in_ms_t queue_last(jitterbuf *jb) 
+static time_in_ms_t queue_last(jitterbuf * jb)
 {
 	if (jb->frames)
 		return jb->frames->prev->ts;
@@ -401,7 +403,7 @@
 		return -1;
 }
 
-static jb_frame *_queue_get(jitterbuf *jb, time_in_ms_t ts, int all) 
+static jb_frame *_queue_get(jitterbuf * jb, time_in_ms_t ts, int all)
 {
 	jb_frame *frame;
 	frame = jb->frames;
@@ -436,46 +438,41 @@
 	return NULL;
 }
 
-static jb_frame *queue_get(jitterbuf *jb, time_in_ms_t ts) 
+static jb_frame *queue_get(jitterbuf * jb, time_in_ms_t ts)
 {
-	return _queue_get(jb,ts,0);
+	return _queue_get(jb, ts, 0);
 }
 
-static jb_frame *queue_getall(jitterbuf *jb)
+static jb_frame *queue_getall(jitterbuf * jb)
 {
-	return _queue_get(jb,0,1);
+	return _queue_get(jb, 0, 1);
 }
 
 #if 0
 /* some diagnostics */
-static void jb_dbginfo(jitterbuf *jb)
+static void jb_dbginfo(jitterbuf * jb)
 {
 	if (dbgf == NULL)
 		return;
 
 	jb_dbg("\njb info: fin=%ld fout=%ld flate=%ld flost=%ld fdrop=%ld fcur=%ld\n",
-		jb->info.frames_in, jb->info.frames_out, jb->info.frames_late, jb->info.frames_lost, jb->info.frames_dropped, jb->info.frames_cur);
+		   jb->info.frames_in, jb->info.frames_out, jb->info.frames_late, jb->info.frames_lost, jb->info.frames_dropped, jb->info.frames_cur);
 
 	jb_dbg("jitter=%ld current=%ld target=%ld min=%ld sil=%d len=%d len/fcur=%ld\n",
-		jb->info.jitter, jb->info.current, jb->info.target, jb->info.min, jb->info.silence_begin_ts, jb->info.current - jb->info.min,
-		jb->info.frames_cur ? (jb->info.current - jb->info.min)/jb->info.frames_cur : -8);
+		   jb->info.jitter, jb->info.current, jb->info.target, jb->info.min, jb->info.silence_begin_ts, jb->info.current - jb->info.min,
+		   jb->info.frames_cur ? (jb->info.current - jb->info.min) / jb->info.frames_cur : -8);
 	if (jb->info.frames_in > 0)
 		jb_dbg("jb info: Loss PCT = %ld%%, Late PCT = %ld%%\n",
-		jb->info.frames_lost * 100/(jb->info.frames_in + jb->info.frames_lost),
-		jb->info.frames_late * 100/jb->info.frames_in);
+			   jb->info.frames_lost * 100 / (jb->info.frames_in + jb->info.frames_lost), jb->info.frames_late * 100 / jb->info.frames_in);
 	jb_dbg("jb info: queue %d -> %d.  last_ts %d (queue len: %d) last_ms %d\n",
-		queue_next(jb),
-		queue_last(jb),
-		jb->info.next_voice_ts,
-		queue_last(jb) - queue_next(jb),
-		jb->info.last_voice_ms);
+		   queue_next(jb), queue_last(jb), jb->info.next_voice_ts, queue_last(jb) - queue_next(jb), jb->info.last_voice_ms);
 }
 #endif
 
 #ifdef DEEP_DEBUG
-static void jb_chkqueue(jitterbuf *jb)
+static void jb_chkqueue(jitterbuf * jb)
 {
-	int i=0;
+	int i = 0;
 	jb_frame *p = jb->frames;
 
 	if (!p) {
@@ -483,17 +480,17 @@
 	}
 
 	do {
-		if (p->next == NULL)  {
+		if (p->next == NULL) {
 			jb_err("Queue is BROKEN at item [%d]", i);
 		}
 		i++;
-		p=p->next;
+		p = p->next;
 	} while (p->next != jb->frames);
 }
 
-static void jb_dbgqueue(jitterbuf *jb)
+static void jb_dbgqueue(jitterbuf * jb)
 {
-	int i=0;
+	int i = 0;
 	jb_frame *p = jb->frames;
 
 	jb_dbg("queue: ");
@@ -505,14 +502,14 @@
 
 	do {
 		jb_dbg("[%d]=%ld ", i++, p->ts);
-		p=p->next;
+		p = p->next;
 	} while (p->next != jb->frames);
 
 	jb_dbg("\n");
 }
 #endif
 
-enum jb_return_code jb_put(jitterbuf *jb, void *data, const enum jb_frame_type type, long ms, time_in_ms_t ts, time_in_ms_t now)
+enum jb_return_code jb_put(jitterbuf * jb, void *data, const enum jb_frame_type type, long ms, time_in_ms_t ts, time_in_ms_t now)
 {
 	jb->info.frames_in++;
 
@@ -522,12 +519,12 @@
 		 * sending retransmitted control frames with their awkward
 		 * timestamps through
 		 */
-		if (history_put(jb,ts,now))
+		if (history_put(jb, ts, now))
 			return JB_DROP;
 	}
 
 	/* if put into head of queue, caller needs to reschedule */
-	if (queue_put(jb,data,type,ms,ts)) {
+	if (queue_put(jb, data, type, ms, ts)) {
 		return JB_SCHED;
 	}
 
@@ -535,7 +532,7 @@
 }
 
 
-static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms_t now, long interpl)
+static enum jb_return_code _jb_get(jitterbuf * jb, jb_frame * frameout, time_in_ms_t now, long interpl)
 {
 	jb_frame *frame;
 	time_in_ms_t diff;
@@ -557,7 +554,7 @@
 	diff = jb->info.target - jb->info.current;
 
 	/* jb_warn("diff = %d lms=%d last = %d now = %d\n", diff,  */
-	/*	jb->info.last_voice_ms, jb->info.last_adjustment, now); */
+	/*  jb->info.last_voice_ms, jb->info.last_adjustment, now); */
 
 	/* let's work on non-silent case first */
 	if (!jb->info.silence_begin_ts) {
@@ -565,8 +562,8 @@
 		if ((diff > 0) &&
 			/* we haven't grown in the delay length */
 			(((jb->info.last_adjustment + JB_ADJUST_DELAY) < now) ||
-			/* we need to grow more than the "length" we have left */
-			(diff > queue_last(jb) - queue_next(jb)) ) ) {
+			 /* we need to grow more than the "length" we have left */
+			 (diff > queue_last(jb) - queue_next(jb)))) {
 			/* grow by interp frame length */
 			jb->info.current += interpl;
 			jb->info.next_voice_ts += interpl;
@@ -619,7 +616,7 @@
 				jb->info.frames_lost--;
 				jb_dbg("l");
 				/*jb_warn("\nlate: wanted=%ld, this=%ld, next=%ld\n", jb->info.next_voice_ts - jb->info.current, frame->ts, queue_next(jb));
-				  jb_warninfo(jb); */
+				   jb_warninfo(jb); */
 				return JB_DROP;
 			}
 		}
@@ -633,9 +630,7 @@
 		/* unless we don't have a frame, then shrink 1 frame */
 		/* every 80ms (though perhaps we can shrink even faster */
 		/* in this case) */
-		if (diff < -jb->info.conf.target_extra &&
-				((!frame && jb->info.last_adjustment + 80 < now) ||
-				 (jb->info.last_adjustment + 500 < now))) {
+		if (diff < -jb->info.conf.target_extra && ((!frame && jb->info.last_adjustment + 80 < now) || (jb->info.last_adjustment + 500 < now))) {
 
 			jb->info.last_adjustment = now;
 			jb->info.cnt_contig_interp = 0;
@@ -677,11 +672,11 @@
 			 * lost frame get interpolated two or more times, when there was "room" to grow, so it might
 			 * be a bit of a bad idea overall */
 			/*if (diff > -1 * jb->info.last_voice_ms) {
-				jb->info.current += jb->info.last_voice_ms;
-				jb->info.last_adjustment = now;
-				jb_warn("g");
-				return JB_INTERP;
-			} */
+			   jb->info.current += jb->info.last_voice_ms;
+			   jb->info.last_adjustment = now;
+			   jb_warn("g");
+			   return JB_INTERP;
+			   } */
 			jb->info.frames_lost++;
 			increment_losspct(jb);
 			jb->info.next_voice_ts += interpl;
@@ -712,8 +707,7 @@
 		/* jb->info.silence_begin_ts = 0; */
 
 		/* shrink interpl len every 10ms during silence */
-		if (diff < -jb->info.conf.target_extra &&
-			jb->info.last_adjustment + 10 <= now) {
+		if (diff < -jb->info.conf.target_extra && jb->info.last_adjustment + 10 <= now) {
 			jb->info.current -= interpl;
 			jb->info.last_adjustment = now;
 		}
@@ -736,7 +730,7 @@
 			jb->info.frames_lost--;
 			jb_dbg("l");
 			/*jb_warn("\nlate: wanted=%ld, this=%ld, next=%ld\n", jb->info.next_voice_ts - jb->info.current, frame->ts, queue_next(jb));
-			  jb_warninfo(jb); */
+			   jb_warninfo(jb); */
 			return JB_DROP;
 		} else {
 			/* voice frame */
@@ -754,7 +748,7 @@
 	}
 }
 
-time_in_ms_t jb_next(jitterbuf *jb)
+time_in_ms_t jb_next(jitterbuf * jb)
 {
 	if (jb->info.silence_begin_ts) {
 		if (jb->frames) {
@@ -764,28 +758,28 @@
 			if (jb->info.target - jb->info.current < -jb->info.conf.target_extra)
 				return jb->info.last_adjustment + 10;
 			return next + jb->info.target;
-		}
-		else
+		} else
 			return JB_LONGMAX;
 	} else {
 		return jb->info.next_voice_ts;
 	}
 }
 
-enum jb_return_code jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms_t now, long interpl)
+enum jb_return_code jb_get(jitterbuf * jb, jb_frame * frameout, time_in_ms_t now, long interpl)
 {
 	enum jb_return_code ret = _jb_get(jb, frameout, now, interpl);
 #if 0
-	static int lastts=0;
+	static int lastts = 0;
 	int thists = ((ret == JB_OK) || (ret == JB_DROP)) ? frameout->ts : 0;
 	jb_warn("jb_get(%x,%x,%ld) = %d (%d)\n", jb, frameout, now, ret, thists);
-	if (thists && thists < lastts) jb_warn("XXXX timestamp roll-back!!!\n");
+	if (thists && thists < lastts)
+		jb_warn("XXXX timestamp roll-back!!!\n");
 	lastts = thists;
 #endif
 	return ret;
 }
 
-enum jb_return_code jb_getall(jitterbuf *jb, jb_frame *frameout)
+enum jb_return_code jb_getall(jitterbuf * jb, jb_frame * frameout)
 {
 	jb_frame *frame;
 	frame = queue_getall(jb);
@@ -799,7 +793,7 @@
 }
 
 
-enum jb_return_code jb_getinfo(jitterbuf *jb, jb_info *stats)
+enum jb_return_code jb_getinfo(jitterbuf * jb, jb_info * stats)
 {
 	history_get(jb);
 
@@ -808,7 +802,7 @@
 	return JB_OK;
 }
 
-enum jb_return_code jb_setconf(jitterbuf *jb, jb_conf *conf)
+enum jb_return_code jb_setconf(jitterbuf * jb, jb_conf * conf)
 {
 	/* take selected settings from the struct */
 
@@ -817,10 +811,8 @@
 	jb->info.conf.max_contig_interp = conf->max_contig_interp;
 
 	/* -1 indicates use of the default JB_TARGET_EXTRA value */
-	jb->info.conf.target_extra = ( conf->target_extra == -1 )
-		? JB_TARGET_EXTRA
-		: conf->target_extra
-		;
+	jb->info.conf.target_extra = (conf->target_extra == -1)
+		? JB_TARGET_EXTRA : conf->target_extra;
 
 	/* update these to match new target_extra setting */
 	jb->info.current = jb->info.conf.target_extra;
@@ -828,5 +820,3 @@
 
 	return JB_OK;
 }
-
-

Modified: freeswitch/trunk/src/mod/endpoints/mod_iax/md5.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_iax/md5.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_iax/md5.c	Tue May 27 00:54:52 2008
@@ -3,13 +3,13 @@
 
 #ifdef FREEBSD
 # include <machine/endian.h>
-#elif defined(LINUX)  
+#elif defined(LINUX)
 # include <endian.h>
 # include <features.h>
 # include <sys/types.h>
 #elif defined(SOLARIS)
   /* each solaris is different -- this won't work on 2.6 or 2.7 */
-# include <sys/isa_defs.h> /* Defines either _LITTLE_ENDIAN or _BIG_ENDIAN */
+# include <sys/isa_defs.h>		/* Defines either _LITTLE_ENDIAN or _BIG_ENDIAN */
 #  define __BIG_ENDIAN		4321
 #  define __LITTLE_ENDIAN	1234
 #  define BIG_ENDIAN		4321
@@ -59,7 +59,7 @@
  * needed on buffers full of bytes, and then call MD5Final, which
  * will fill a supplied 16-byte array with the digest.
  */
-#include <string.h>		/* for memcpy() */
+#include <string.h>				/* for memcpy() */
 #include "md5.h"
 
 #ifndef HIGHFIRST
@@ -73,13 +73,12 @@
  */
 void byteReverse(unsigned char *buf, unsigned longs)
 {
-    uint32 t;
-    do {
-	t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
-	    ((unsigned) buf[1] << 8 | buf[0]);
-	*(uint32 *) buf = t;
-	buf += 4;
-    } while (--longs);
+	uint32 t;
+	do {
+		t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 | ((unsigned) buf[1] << 8 | buf[0]);
+		*(uint32 *) buf = t;
+		buf += 4;
+	} while (--longs);
 }
 #endif
 #endif
@@ -90,13 +89,13 @@
  */
 void MD5Init(struct MD5Context *ctx)
 {
-    ctx->buf[0] = 0x67452301;
-    ctx->buf[1] = 0xefcdab89;
-    ctx->buf[2] = 0x98badcfe;
-    ctx->buf[3] = 0x10325476;
+	ctx->buf[0] = 0x67452301;
+	ctx->buf[1] = 0xefcdab89;
+	ctx->buf[2] = 0x98badcfe;
+	ctx->buf[3] = 0x10325476;
 
-    ctx->bits[0] = 0;
-    ctx->bits[1] = 0;
+	ctx->bits[0] = 0;
+	ctx->bits[1] = 0;
 }
 
 /*
@@ -105,46 +104,46 @@
  */
 void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
 {
-    uint32 t;
+	uint32 t;
 
-    /* Update bitcount */
+	/* Update bitcount */
 
-    t = ctx->bits[0];
-    if ((ctx->bits[0] = t + ((uint32) len << 3)) < t)
-	ctx->bits[1]++;		/* Carry from low to high */
-    ctx->bits[1] += len >> 29;
-
-    t = (t >> 3) & 0x3f;	/* Bytes already in shsInfo->data */
-
-    /* Handle any leading odd-sized chunks */
-
-    if (t) {
-	unsigned char *p = (unsigned char *) ctx->in + t;
+	t = ctx->bits[0];
+	if ((ctx->bits[0] = t + ((uint32) len << 3)) < t)
+		ctx->bits[1]++;			/* Carry from low to high */
+	ctx->bits[1] += len >> 29;
+
+	t = (t >> 3) & 0x3f;		/* Bytes already in shsInfo->data */
+
+	/* Handle any leading odd-sized chunks */
+
+	if (t) {
+		unsigned char *p = (unsigned char *) ctx->in + t;
+
+		t = 64 - t;
+		if (len < t) {
+			memcpy(p, buf, len);
+			return;
+		}
+		memcpy(p, buf, t);
+		byteReverse(ctx->in, 16);
+		MD5Transform(ctx->buf, (uint32 *) ctx->in);
+		buf += t;
+		len -= t;
+	}
+	/* Process data in 64-byte chunks */
 
-	t = 64 - t;
-	if (len < t) {
-	    memcpy(p, buf, len);
-	    return;
+	while (len >= 64) {
+		memcpy(ctx->in, buf, 64);
+		byteReverse(ctx->in, 16);
+		MD5Transform(ctx->buf, (uint32 *) ctx->in);
+		buf += 64;
+		len -= 64;
 	}
-	memcpy(p, buf, t);
-	byteReverse(ctx->in, 16);
-	MD5Transform(ctx->buf, (uint32 *) ctx->in);
-	buf += t;
-	len -= t;
-    }
-    /* Process data in 64-byte chunks */
-
-    while (len >= 64) {
-	memcpy(ctx->in, buf, 64);
-	byteReverse(ctx->in, 16);
-	MD5Transform(ctx->buf, (uint32 *) ctx->in);
-	buf += 64;
-	len -= 64;
-    }
 
-    /* Handle any remaining bytes of data. */
+	/* Handle any remaining bytes of data. */
 
-    memcpy(ctx->in, buf, len);
+	memcpy(ctx->in, buf, len);
 }
 
 /*
@@ -153,43 +152,43 @@
  */
 void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
 {
-    unsigned count;
-    unsigned char *p;
+	unsigned count;
+	unsigned char *p;
 
-    /* Compute number of bytes mod 64 */
-    count = (ctx->bits[0] >> 3) & 0x3F;
+	/* Compute number of bytes mod 64 */
+	count = (ctx->bits[0] >> 3) & 0x3F;
 
-    /* Set the first char of padding to 0x80.  This is safe since there is
-       always at least one byte free */
-    p = ctx->in + count;
-    *p++ = 0x80;
-
-    /* Bytes of padding needed to make 64 bytes */
-    count = 64 - 1 - count;
-
-    /* Pad out to 56 mod 64 */
-    if (count < 8) {
-	/* Two lots of padding:  Pad the first block to 64 bytes */
-	memset(p, 0, count);
-	byteReverse(ctx->in, 16);
-	MD5Transform(ctx->buf, (uint32 *) ctx->in);
+	/* Set the first char of padding to 0x80.  This is safe since there is
+	   always at least one byte free */
+	p = ctx->in + count;
+	*p++ = 0x80;
+
+	/* Bytes of padding needed to make 64 bytes */
+	count = 64 - 1 - count;
+
+	/* Pad out to 56 mod 64 */
+	if (count < 8) {
+		/* Two lots of padding:  Pad the first block to 64 bytes */
+		memset(p, 0, count);
+		byteReverse(ctx->in, 16);
+		MD5Transform(ctx->buf, (uint32 *) ctx->in);
+
+		/* Now fill the next block with 56 bytes */
+		memset(ctx->in, 0, 56);
+	} else {
+		/* Pad block to 56 bytes */
+		memset(p, 0, count - 8);
+	}
+	byteReverse(ctx->in, 14);
 
-	/* Now fill the next block with 56 bytes */
-	memset(ctx->in, 0, 56);
-    } else {
-	/* Pad block to 56 bytes */
-	memset(p, 0, count - 8);
-    }
-    byteReverse(ctx->in, 14);
-
-    /* Append length in bits and transform */
-    ((uint32 *) ctx->in)[14] = ctx->bits[0];
-    ((uint32 *) ctx->in)[15] = ctx->bits[1];
-
-    MD5Transform(ctx->buf, (uint32 *) ctx->in);
-    byteReverse((unsigned char *) ctx->buf, 4);
-    memcpy(digest, ctx->buf, 16);
-    memset(ctx, 0, sizeof(ctx));	/* In case it's sensitive */
+	/* Append length in bits and transform */
+	((uint32 *) ctx->in)[14] = ctx->bits[0];
+	((uint32 *) ctx->in)[15] = ctx->bits[1];
+
+	MD5Transform(ctx->buf, (uint32 *) ctx->in);
+	byteReverse((unsigned char *) ctx->buf, 4);
+	memcpy(digest, ctx->buf, 16);
+	memset(ctx, 0, sizeof(ctx));	/* In case it's sensitive */
 }
 
 #ifndef ASM_MD5
@@ -213,85 +212,85 @@
  */
 void MD5Transform(uint32 buf[4], uint32 const in[16])
 {
-    register uint32 a, b, c, d;
+	register uint32 a, b, c, d;
 
-    a = buf[0];
-    b = buf[1];
-    c = buf[2];
-    d = buf[3];
-
-    MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
-    MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
-    MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
-    MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
-    MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
-    MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
-    MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
-    MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
-    MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
-    MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
-    MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
-    MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
-    MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
-    MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
-    MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
-    MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
-
-    MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
-    MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
-    MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
-    MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
-    MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
-    MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
-    MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
-    MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
-    MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
-    MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
-    MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
-    MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
-    MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
-    MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
-    MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
-    MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
-
-    MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
-    MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
-    MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
-    MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
-    MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
-    MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
-    MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
-    MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
-    MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
-    MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
-    MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
-    MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
-    MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
-    MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
-    MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
-    MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
-
-    MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
-    MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
-    MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
-    MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
-    MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
-    MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
-    MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
-    MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
-    MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
-    MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
-    MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
-    MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
-    MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
-    MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
-    MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
-    MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
-
-    buf[0] += a;
-    buf[1] += b;
-    buf[2] += c;
-    buf[3] += d;
+	a = buf[0];
+	b = buf[1];
+	c = buf[2];
+	d = buf[3];
+
+	MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
+	MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
+	MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
+	MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
+	MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
+	MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
+	MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
+	MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
+	MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
+	MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
+	MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
+	MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
+	MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
+	MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
+	MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
+	MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
+
+	MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
+	MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
+	MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
+	MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
+	MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
+	MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
+	MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
+	MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
+	MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
+	MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
+	MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
+	MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
+	MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
+	MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
+	MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
+	MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
+
+	MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
+	MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
+	MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
+	MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
+	MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
+	MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
+	MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
+	MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
+	MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
+	MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
+	MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
+	MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
+	MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
+	MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
+	MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
+	MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
+
+	MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
+	MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
+	MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
+	MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
+	MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
+	MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
+	MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
+	MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
+	MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
+	MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
+	MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
+	MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
+	MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
+	MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
+	MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
+	MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
+
+	buf[0] += a;
+	buf[1] += b;
+	buf[2] += c;
+	buf[3] += d;
 }
 
 #endif

Modified: freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c	Tue May 27 00:54:52 2008
@@ -110,14 +110,14 @@
 
 
 static char *IAXNAMES[] = { "IAX_EVENT_CONNECT", "IAX_EVENT_ACCEPT", "IAX_EVENT_HANGUP", "IAX_EVENT_REJECT", "IAX_EVENT_VOICE",
-							"IAX_EVENT_DTMF", "IAX_EVENT_TIMEOUT", "IAX_EVENT_LAGRQ", "IAX_EVENT_LAGRP", "IAX_EVENT_RINGA",
-							"IAX_EVENT_PING", "IAX_EVENT_PONG", "IAX_EVENT_BUSY", "IAX_EVENT_ANSWER", "IAX_EVENT_IMAGE",
-							"IAX_EVENT_AUTHRQ", "IAX_EVENT_AUTHRP", "IAX_EVENT_REGREQ", "IAX_EVENT_REGACK",
-							"IAX_EVENT_URL", "IAX_EVENT_LDCOMPLETE", "IAX_EVENT_TRANSFER", "IAX_EVENT_DPREQ",
-							"IAX_EVENT_DPREP", "IAX_EVENT_DIAL", "IAX_EVENT_QUELCH", "IAX_EVENT_UNQUELCH",
-							"IAX_EVENT_UNLINK", "IAX_EVENT_LINKREJECT", "IAX_EVENT_TEXT", "IAX_EVENT_REGREJ",
-							"IAX_EVENT_LINKURL", "IAX_EVENT_CNG", "IAX_EVENT_REREQUEST", "IAX_EVENT_TXREPLY",
-							"IAX_EVENT_TXREJECT", "IAX_EVENT_TXACCEPT", "IAX_EVENT_TXREADY"
+	"IAX_EVENT_DTMF", "IAX_EVENT_TIMEOUT", "IAX_EVENT_LAGRQ", "IAX_EVENT_LAGRP", "IAX_EVENT_RINGA",
+	"IAX_EVENT_PING", "IAX_EVENT_PONG", "IAX_EVENT_BUSY", "IAX_EVENT_ANSWER", "IAX_EVENT_IMAGE",
+	"IAX_EVENT_AUTHRQ", "IAX_EVENT_AUTHRP", "IAX_EVENT_REGREQ", "IAX_EVENT_REGACK",
+	"IAX_EVENT_URL", "IAX_EVENT_LDCOMPLETE", "IAX_EVENT_TRANSFER", "IAX_EVENT_DPREQ",
+	"IAX_EVENT_DPREP", "IAX_EVENT_DIAL", "IAX_EVENT_QUELCH", "IAX_EVENT_UNQUELCH",
+	"IAX_EVENT_UNLINK", "IAX_EVENT_LINKREJECT", "IAX_EVENT_TEXT", "IAX_EVENT_REGREJ",
+	"IAX_EVENT_LINKURL", "IAX_EVENT_CNG", "IAX_EVENT_REREQUEST", "IAX_EVENT_TXREPLY",
+	"IAX_EVENT_TXREJECT", "IAX_EVENT_TXACCEPT", "IAX_EVENT_TXREADY"
 };
 
 
@@ -129,24 +129,24 @@
 
 //999 means it's wrong nad i dont know the real one 
 static struct ast_iana AST_IANA[] = { {AST_FORMAT_G723_1, 4, "g723.1"},
-									  {AST_FORMAT_GSM, 3, "gsm"},
-									  {AST_FORMAT_ULAW, 0, "ulaw"},
-									  {AST_FORMAT_ALAW, 8, "alaw"},
-									  {AST_FORMAT_G726, 999, "g726"},
-									  {AST_FORMAT_ADPCM, 999, "adpcm"},
-									  {AST_FORMAT_SLINEAR, 10, "slinear"},
-									  {AST_FORMAT_LPC10, 7, "lpc10"},
-									  {AST_FORMAT_G729A, 18, "g729"},
-									  {AST_FORMAT_SPEEX, 97, "speex"},
-									  {AST_FORMAT_SPEEX, 98, "speex"},
-									  {AST_FORMAT_ILBC, 102, "ilbc"},
-									  {AST_FORMAT_MAX_AUDIO, 999, ""},
-									  {AST_FORMAT_JPEG, 999, ""},
-									  {AST_FORMAT_PNG, 999, ""},
-									  {AST_FORMAT_H261, 999, ""},
-									  {AST_FORMAT_H263, 999, ""},
-									  {AST_FORMAT_MAX_VIDEO, 999, ""},
-									  {0, 0}
+{AST_FORMAT_GSM, 3, "gsm"},
+{AST_FORMAT_ULAW, 0, "ulaw"},
+{AST_FORMAT_ALAW, 8, "alaw"},
+{AST_FORMAT_G726, 999, "g726"},
+{AST_FORMAT_ADPCM, 999, "adpcm"},
+{AST_FORMAT_SLINEAR, 10, "slinear"},
+{AST_FORMAT_LPC10, 7, "lpc10"},
+{AST_FORMAT_G729A, 18, "g729"},
+{AST_FORMAT_SPEEX, 97, "speex"},
+{AST_FORMAT_SPEEX, 98, "speex"},
+{AST_FORMAT_ILBC, 102, "ilbc"},
+{AST_FORMAT_MAX_AUDIO, 999, ""},
+{AST_FORMAT_JPEG, 999, ""},
+{AST_FORMAT_PNG, 999, ""},
+{AST_FORMAT_H261, 999, ""},
+{AST_FORMAT_H263, 999, ""},
+{AST_FORMAT_MAX_VIDEO, 999, ""},
+{0, 0}
 };
 
 static char *ast2str(int ast)
@@ -214,7 +214,7 @@
 	IAX_QUERY = 2
 } iax_io_t;
 
-static switch_status_t iax_set_codec(private_t * tech_pvt, struct iax_session *iax_session,
+static switch_status_t iax_set_codec(private_t *tech_pvt, struct iax_session *iax_session,
 									 unsigned int *format, unsigned int *cababilities, unsigned short *samprate, iax_io_t io)
 {
 	char *dname = NULL;
@@ -281,8 +281,8 @@
 			char pref_str[256] = "(";
 
 			for (x = 0; x < len; x++) {
-				strncat(pref_str, ast2str(prefs[x]), sizeof(pref_str)-1);
-				strncat(pref_str, x == len - 1 ? ")" : ",", sizeof(pref_str)-1);
+				strncat(pref_str, ast2str(prefs[x]), sizeof(pref_str) - 1);
+				strncat(pref_str, x == len - 1 ? ")" : ",", sizeof(pref_str) - 1);
 			}
 
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Codec Prefs Detected: %s\n", pref_str);
@@ -439,7 +439,7 @@
 	}
 }
 
-static void tech_init(private_t * tech_pvt, switch_core_session_t *session)
+static void 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);
@@ -619,7 +619,7 @@
 
 	return SWITCH_STATUS_FALSE;
 
- cng:
+  cng:
 	data = (switch_byte_t *) tech_pvt->read_frame.data;
 	data[0] = 65;
 	data[1] = 0;
@@ -791,7 +791,7 @@
 	/*.write_frame */ channel_write_frame,
 	/*.kill_channel */ channel_kill_channel,
 	/*.send_dtmf */ channel_send_dtmf,
-	/*.receive_message*/ channel_receive_message,
+	/*.receive_message */ channel_receive_message,
 	/*.receive_event */ channel_receive_event
 };
 
@@ -867,7 +867,7 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t tech_media(private_t * tech_pvt, struct iax_event *iaxevent)
+static switch_status_t tech_media(private_t *tech_pvt, struct iax_event *iaxevent)
 {
 	unsigned int cap = iax_session_get_capability(iaxevent->session);
 	unsigned int format = iaxevent->ies.format;
@@ -1025,8 +1025,7 @@
 																				  NULL,
 																				  NULL,
 																				  modname,
-																				  iaxevent->ies.called_context,
-																				  iaxevent->ies.called_number)) != 0) {
+																				  iaxevent->ies.called_context, iaxevent->ies.called_number)) != 0) {
 							char name[128];
 							switch_snprintf(name, sizeof(name), "IAX/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff);
 							switch_channel_set_name(channel, name);
@@ -1062,7 +1061,7 @@
 					switch_clear_flag(tech_pvt, TFLAG_VOICE);
 					switch_mutex_unlock(tech_pvt->flag_mutex);
 
-					
+
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hangup %s\n", switch_channel_get_name(channel));
 					switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
 					switch_channel_hangup(channel, iaxevent->etype == IAX_EVENT_HANGUP ? SWITCH_CAUSE_NORMAL_CLEARING : SWITCH_CAUSE_FACILITY_REJECTED);
@@ -1102,7 +1101,7 @@
 				break;
 			case IAX_EVENT_DTMF:
 				if (channel) {
-					switch_dtmf_t dtmf = { (char) iaxevent->subclass , switch_core_default_dtmf_duration(0) };
+					switch_dtmf_t dtmf = { (char) iaxevent->subclass, switch_core_default_dtmf_duration(0) };
 					if (globals.debug) {
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%c DTMF %s\n", dtmf.digit, switch_channel_get_name(channel));
 					}
@@ -1118,7 +1117,7 @@
 				break;
 			}
 			iax_event_free(iaxevent);
-			switch_mutex_unlock(globals.mutex);			
+			switch_mutex_unlock(globals.mutex);
 			if (tech_pvt && tech_pvt->session) {
 				switch_core_session_signal_unlock(tech_pvt->session);
 			}

Modified: freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c	Tue May 27 00:54:52 2008
@@ -136,8 +136,8 @@
 SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_timer_name, globals.timer_name);
 #define is_master(t) switch_test_flag(t, TFLAG_MASTER)
 
-static void add_pvt(private_t * tech_pvt, int master);
-static void remove_pvt(private_t * tech_pvt);
+static void add_pvt(private_t *tech_pvt, int master);
+static void remove_pvt(private_t *tech_pvt);
 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_routing(switch_core_session_t *session);
@@ -234,7 +234,7 @@
 
 		while (switch_channel_get_state(channel) == CS_INIT && !switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
 			switch_size_t olen = globals.timer.samples;
-				
+
 			if (switch_timestamp_now() - last >= waitsec) {
 				char buf[512];
 				switch_event_t *event;
@@ -250,7 +250,7 @@
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s\n", buf);
 				last = switch_timestamp_now();
 			}
-			
+
 			if (ring_file) {
 				if (switch_core_timer_next(&globals.timer) != SWITCH_STATUS_SUCCESS) {
 					switch_core_file_close(&fh);
@@ -324,7 +324,7 @@
 
 
 
-static void add_pvt(private_t * tech_pvt, int master)
+static void add_pvt(private_t *tech_pvt, int master)
 {
 	private_t *tp;
 	uint8_t in_list = 0;
@@ -367,7 +367,7 @@
 	switch_mutex_unlock(globals.pvt_lock);
 }
 
-static void remove_pvt(private_t * tech_pvt)
+static void remove_pvt(private_t *tech_pvt)
 {
 	private_t *tp, *last = NULL;
 
@@ -485,8 +485,7 @@
 										  tech_pvt->hold_file,
 										  globals.read_codec.implementation->number_of_channels,
 										  globals.read_codec.implementation->actual_samples_per_second,
-										  SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
-										  NULL) != SWITCH_STATUS_SUCCESS) {
+										  SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
 					tech_pvt->hold_file = NULL;
 					goto cng;
 				}
@@ -500,12 +499,12 @@
 
 			goto hold;
 		}
-	cng:
+	  cng:
 		switch_yield(globals.read_codec.implementation->microseconds_per_frame);
 		*frame = &globals.cng_frame;
 		return SWITCH_STATUS_SUCCESS;
 
-	hold:
+	  hold:
 		{
 			switch_size_t olen = globals.read_codec.implementation->samples_per_frame;
 			if (switch_core_timer_next(&globals.timer) != SWITCH_STATUS_SUCCESS) {
@@ -531,13 +530,12 @@
 
 	switch_mutex_lock(globals.device_lock);
 
- get_samples:
+  get_samples:
 
-	if ((samples = ReadAudioStream(globals.audio_stream, globals.read_frame.data, 
-								   globals.read_codec.implementation->samples_per_frame, 
-								   &globals.timer)) == 0) {
-        switch_yield(1000);
-        goto get_samples;
+	if ((samples = ReadAudioStream(globals.audio_stream, globals.read_frame.data,
+								   globals.read_codec.implementation->samples_per_frame, &globals.timer)) == 0) {
+		switch_yield(1000);
+		goto get_samples;
 	} else {
 		globals.read_frame.datalen = samples * 2;
 		globals.read_frame.samples = samples;
@@ -576,8 +574,7 @@
 
 	if (globals.audio_stream) {
 		if (switch_test_flag((&globals), GFLAG_EAR)) {
-			WriteAudioStream(globals.audio_stream, (short *) frame->data, (int) (frame->datalen / sizeof(SAMPLE)),
-							 &globals.timer);
+			WriteAudioStream(globals.audio_stream, (short *) frame->data, (int) (frame->datalen / sizeof(SAMPLE)), &globals.timer);
 		}
 		status = SWITCH_STATUS_SUCCESS;
 	}
@@ -667,7 +664,7 @@
 			if (outbound_profile->destination_number && !strcasecmp(outbound_profile->destination_number, "auto_answer")) {
 				switch_set_flag(tech_pvt, TFLAG_ANSWER);
 			}
-			
+
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n");
 			switch_core_session_destroy(new_session);
@@ -775,7 +772,7 @@
 					globals.codec_ms = tmp;
 				} else {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
-									  "codec-ms must be multipe of 10 and less than %d, Using default of 20\n", SWITCH_MAX_INTERVAL); 
+									  "codec-ms must be multipe of 10 and less than %d, Using default of 20\n", SWITCH_MAX_INTERVAL);
 				}
 			} else if (!strcmp(var, "dialplan")) {
 				set_global_dialplan(val);
@@ -936,7 +933,8 @@
 	int i, printCount, cr = 7;
 	PaError err;
 	static double standardSampleRates[] = { 8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0,
-											44100.0, 48000.0, 88200.0, 96000.0, 192000.0, -1};
+		44100.0, 48000.0, 88200.0, 96000.0, 192000.0, -1
+	};
 
 	printCount = cr;
 	for (i = 0; standardSampleRates[i] > 0; i++) {
@@ -1077,7 +1075,7 @@
 
 	return 0;
 
- error:
+  error:
 	switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "An error occured while using the portaudio stream\n");
 	switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "Error number: %d\n", err);
 	switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "Error message: %s\n", Pa_GetErrorText(err));
@@ -1140,7 +1138,7 @@
 		outputParameters.sampleFormat = SAMPLE_TYPE;
 		outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency;
 		outputParameters.hostApiSpecificStreamInfo = NULL;
-		err = OpenAudioStream(&globals.audio_stream, &inputParameters, &outputParameters, sample_rate, paClipOff, 
+		err = OpenAudioStream(&globals.audio_stream, &inputParameters, &outputParameters, sample_rate, paClipOff,
 							  globals.read_codec.implementation->samples_per_frame);
 		/* UNLOCKED ************************************************************************************************* */
 		switch_mutex_unlock(globals.device_lock);
@@ -1174,8 +1172,7 @@
 		outputParameters.sampleFormat = SAMPLE_TYPE;
 		outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency;
 		outputParameters.hostApiSpecificStreamInfo = NULL;
-		err = OpenAudioStream(&globals.ring_stream, NULL, &outputParameters, sample_rate, paClipOff,
-							  globals.read_codec.implementation->samples_per_frame);
+		err = OpenAudioStream(&globals.ring_stream, NULL, &outputParameters, sample_rate, paClipOff, globals.read_codec.implementation->samples_per_frame);
 		/* UNLOCKED ************************************************************************************************* */
 		switch_mutex_unlock(globals.device_lock);
 
@@ -1192,8 +1189,8 @@
 static switch_status_t dtmf_call(char **argv, int argc, switch_stream_handle_t *stream)
 {
 	char *dtmf_str = argv[0];
-	switch_dtmf_t dtmf = {0, switch_core_default_dtmf_duration(0)};
-	
+	switch_dtmf_t dtmf = { 0, switch_core_default_dtmf_duration(0) };
+
 	if (switch_strlen_zero(dtmf_str)) {
 		stream->write_function(stream, "No DTMF Supplied!\n");
 	} else {
@@ -1201,7 +1198,7 @@
 		if (globals.call_list) {
 			switch_channel_t *channel = switch_core_session_get_channel(globals.call_list->session);
 			char *p = dtmf_str;
-			while(p && *p) {
+			while (p && *p) {
 				dtmf.digit = *p;
 				switch_channel_queue_dtmf(channel, &dtmf);
 				p++;
@@ -1253,7 +1250,7 @@
 		stream->write_function(stream, "NO SUCH CALL\n");
 	}
 
- done:
+  done:
 	switch_mutex_unlock(globals.pvt_lock);
 
 	return SWITCH_STATUS_SUCCESS;
@@ -1317,7 +1314,7 @@
 			break;
 		}
 	}
- done:
+  done:
 	switch_mutex_unlock(globals.pvt_lock);
 	stream->write_function(stream, "Answered %d channels.\n", x);
 
@@ -1368,7 +1365,7 @@
 		goto bad;
 	}
 
- desc:
+  desc:
 	x = 0;
 	stream->write_function(stream, "FLAGS: ");
 	if (switch_test_flag((&globals), GFLAG_EAR)) {
@@ -1385,9 +1382,9 @@
 
 	goto done;
 
- bad:
+  bad:
 	stream->write_function(stream, "Usage: flags [on|off] <flags>\n");
- done:
+  done:
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -1474,20 +1471,18 @@
 		if (!switch_strlen_zero(argv[4])) {
 			tech_pvt->sample_rate = atoi(argv[4]);
 		}
-		
+
 		if (!switch_strlen_zero(argv[5])) {
 			tech_pvt->codec_ms = atoi(argv[5]);
 		}
-		
+
 		switch_find_local_ip(ip, sizeof(ip), AF_INET);
 
 		if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
-																  NULL, dialplan, cid_name, cid_num,
-																  ip, NULL, NULL, NULL, modname, NULL,
-																  dest)) != 0) {
+																  NULL, dialplan, cid_name, cid_num, ip, NULL, NULL, NULL, modname, NULL, dest)) != 0) {
 			char name[128];
 			switch_snprintf(name, sizeof(name), "PortAudio/%s",
-					 tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile->destination_number : modname);
+							tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile->destination_number : modname);
 			switch_channel_set_name(channel, name);
 
 			switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
@@ -1498,7 +1493,7 @@
 			switch_channel_mark_answered(channel);
 			switch_channel_set_state(channel, CS_INIT);
 			if (switch_core_session_thread_launch(tech_pvt->session) != SWITCH_STATUS_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n");
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error spawning thread\n");
 				switch_core_session_destroy(&session);
 				stream->write_function(stream, "FAIL:Thread Error!\n");
 			} else {
@@ -1674,7 +1669,7 @@
 		}
 	}
 
- done:
+  done:
 	if (http) {
 		stream->write_function(stream,
 							   "<br><br><table align=center><tr><td><center><form method=post>\n"
@@ -1691,25 +1686,18 @@
 							   "<td><input name=action type=submit value=\"2\"></td>"
 							   "<td><input name=action type=submit value=\"3\"></td>\n"
 							   "<td><input name=action type=submit value=\"A\"></td></tr>\n"
-
 							   "<tr><td><input name=action type=submit value=\"4\"></td>"
 							   "<td><input name=action type=submit value=\"5\"></td>"
 							   "<td><input name=action type=submit value=\"6\"></td>\n"
 							   "<td><input name=action type=submit value=\"B\"></td></tr>\n"
-
 							   "<tr><td><input name=action type=submit value=\"7\"></td>"
 							   "<td><input name=action type=submit value=\"8\"></td>"
 							   "<td><input name=action type=submit value=\"9\"></td>\n"
 							   "<td><input name=action type=submit value=\"C\"></td></tr>\n"
-
 							   "<tr><td><input name=action type=submit value=\"*\"></td>"
 							   "<td><input name=action type=submit value=\"0\"></td>"
 							   "<td><input name=action type=submit value=\"#\"></td>\n"
-							   "<td><input name=action type=submit value=\"D\"></td></tr>\n"
-							   "</table>"
-							   
-							   "</form><br></center></td></tr></table>\n"
-							   );
+							   "<td><input name=action type=submit value=\"D\"></td></tr>\n" "</table>" "</form><br></center></td></tr></table>\n");
 	}
 
 	switch_safe_free(mycmd);

Modified: freeswitch/trunk/src/mod/endpoints/mod_portaudio/pablio.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_portaudio/pablio.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_portaudio/pablio.c	Tue May 27 00:54:52 2008
@@ -72,7 +72,7 @@
 {
 	PABLIO_Stream *data = (PABLIO_Stream *) userData;
 	long numBytes = data->bytesPerFrame * framesPerBuffer;
-	
+
 	/* This may get called with NULL inputBuffer during initial setup. */
 	if (inputBuffer != NULL) {
 		if (PaUtil_WriteRingBuffer(&data->inFIFO, inputBuffer, numBytes) != numBytes) {
@@ -146,26 +146,26 @@
 	long bytesRead = 0;
 	char *p = (char *) data;
 	long avail, totalBytes = 0, neededBytes = aStream->bytesPerFrame * numFrames;
-	
-	for(;;) {
+
+	for (;;) {
 		avail = PaUtil_GetRingBufferReadAvailable(&aStream->inFIFO);
-		
+
 		if (switch_core_timer_check(timer, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
 			break;
 		}
-		
-		if (avail >= neededBytes * 6) { 
+
+		if (avail >= neededBytes * 6) {
 			PaUtil_FlushRingBuffer(&aStream->inFIFO);
 			avail = 0;
 		}
-		
+
 		bytesRead = 0;
 
 		if (totalBytes < neededBytes && avail >= neededBytes) {
 			bytesRead = PaUtil_ReadRingBuffer(&aStream->inFIFO, p, neededBytes);
 			totalBytes += bytesRead;
 		}
-		
+
 		if (bytesRead) {
 			p += bytesRead;
 		} else {
@@ -201,7 +201,7 @@
 {
 	long numBits = 0;
 	if (((n - 1) & n) == 0)
-		return n;				
+		return n;
 	while (n > 0) {
 		n = n >> 1;
 		numBits++;
@@ -217,11 +217,8 @@
  *
  */
 PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
-						const PaStreamParameters *inputParameters,
-						const PaStreamParameters *outputParameters,
-						double sampleRate,
-						PaStreamFlags streamFlags,
-						long samples_per_frame)
+						const PaStreamParameters * inputParameters,
+						const PaStreamParameters * outputParameters, double sampleRate, PaStreamFlags streamFlags, long samples_per_frame)
 {
 	long bytesPerSample = 2;
 	PaError err;

Modified: freeswitch/trunk/src/mod/endpoints/mod_reference/mod_reference.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_reference/mod_reference.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_reference/mod_reference.c	Tue May 27 00:54:52 2008
@@ -34,7 +34,7 @@
 SWITCH_MODULE_LOAD_FUNCTION(mod_reference_load);
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_reference_shutdown);
 //SWITCH_MODULE_RUNTIME_FUNCTION(mod_reference_runtime);
-SWITCH_MODULE_DEFINITION(mod_reference, mod_reference_load, mod_reference_shutdown, NULL);//mod_reference_runtime);
+SWITCH_MODULE_DEFINITION(mod_reference, mod_reference_load, mod_reference_shutdown, NULL);	//mod_reference_runtime);
 
 
 switch_endpoint_interface_t *reference_endpoint_interface;
@@ -112,7 +112,7 @@
 
 
 
-static void tech_init(private_t * tech_pvt, switch_core_session_t *session)
+static void 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);
@@ -140,9 +140,9 @@
 	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. */
+	   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++;
@@ -315,7 +315,7 @@
 
 	return SWITCH_STATUS_FALSE;
 
- cng:
+  cng:
 	data = (switch_byte_t *) tech_pvt->read_frame.data;
 	data[0] = 65;
 	data[1] = 0;
@@ -346,7 +346,7 @@
 		switch_swap_linear(frame->data, (int) frame->datalen / 2);
 	}
 #endif
-	
+
 
 	return SWITCH_STATUS_SUCCESS;
 
@@ -363,7 +363,7 @@
 	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
-	
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -375,7 +375,7 @@
 
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
-			
+
 	tech_pvt = (private_t *) switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
@@ -471,7 +471,7 @@
 	/*.write_frame */ channel_write_frame,
 	/*.kill_channel */ channel_kill_channel,
 	/*.send_dtmf */ channel_send_dtmf,
-	/*.receive_message*/ channel_receive_message,
+	/*.receive_message */ channel_receive_message,
 	/*.receive_event */ channel_receive_event
 };
 
@@ -531,7 +531,7 @@
 {
 
 	module_pool = pool;
-	
+
 	load_config();
 
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
@@ -540,7 +540,7 @@
 	reference_endpoint_interface->io_routines = &reference_io_routines;
 	reference_endpoint_interface->state_handler = &reference_state_handlers;
 
-	
+
 
 	/* indicate that the module should continue to be loaded */
 	return SWITCH_STATUS_SUCCESS;

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	Tue May 27 00:54:52 2008
@@ -98,14 +98,14 @@
 
 		if (sofia_glue_do_invite(session) != SWITCH_STATUS_SUCCESS) {
 			switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-			assert( switch_channel_get_state(channel) != CS_INIT);
+			assert(switch_channel_get_state(channel) != CS_INIT);
 			return SWITCH_STATUS_FALSE;
 		}
 	}
 
 	/* Move channel's state machine to ROUTING */
 	switch_channel_set_state(channel, CS_ROUTING);
-	assert( switch_channel_get_state(channel) != CS_INIT);
+	assert(switch_channel_get_state(channel) != CS_INIT);
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -115,7 +115,7 @@
 	switch_assert(tech_pvt != NULL);
 
 	switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
-	
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s SOFIA ROUTING\n", switch_channel_get_name(switch_core_session_get_channel(session)));
 
 	return SWITCH_STATUS_SUCCESS;
@@ -128,7 +128,7 @@
 	switch_assert(tech_pvt != NULL);
 
 	switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
-	
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s SOFIA RESET\n", switch_channel_get_name(switch_core_session_get_channel(session)));
 
 	return SWITCH_STATUS_SUCCESS;
@@ -141,7 +141,7 @@
 	switch_assert(tech_pvt != NULL);
 
 	switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
-	
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s SOFIA HIBERNATE\n", switch_channel_get_name(switch_core_session_get_channel(session)));
 
 	return SWITCH_STATUS_SUCCESS;
@@ -160,7 +160,7 @@
 
 /* map QSIG cause codes to SIP from RFC4497 section 8.4.1 */
 static int hangup_cause_to_sip(switch_call_cause_t cause)
-{		
+{
 	switch (cause) {
 	case SWITCH_CAUSE_NO_ROUTE_TRANSIT_NET:
 	case SWITCH_CAUSE_NO_ROUTE_DESTINATION:
@@ -223,11 +223,11 @@
 	switch_call_cause_t cause = switch_channel_get_cause(channel);
 	int sip_cause = hangup_cause_to_sip(cause);
 	const char *ps_cause = switch_channel_get_variable(channel, SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE);
-	
+
 	if (!switch_strlen_zero(ps_cause) && !strncasecmp(ps_cause, "sip:", 4)) {
 		int new_cause = atoi(ps_cause + 4);
 		if (new_cause) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Overriding SIP cause %d with %d from the other leg\n", 
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Overriding SIP cause %d with %d from the other leg\n",
 							  switch_channel_get_name(channel), sip_cause, new_cause);
 			sip_cause = new_cause;
 		}
@@ -262,7 +262,7 @@
 	sofia_glue_deactivate_rtp(tech_pvt);
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel %s hanging up, cause: %s\n",
-		switch_channel_get_name(channel), switch_channel_cause2str(cause));
+					  switch_channel_get_name(channel), switch_channel_cause2str(cause));
 
 	if (tech_pvt->hash_key) {
 		switch_core_hash_delete(tech_pvt->profile->chat_hash, tech_pvt->hash_key);
@@ -282,7 +282,7 @@
 
 	switch_mutex_lock(tech_pvt->profile->flag_mutex);
 
-	if (tech_pvt->nh  && !switch_test_flag(tech_pvt, TFLAG_BYE)) {
+	if (tech_pvt->nh && !switch_test_flag(tech_pvt, TFLAG_BYE)) {
 		char reason[128] = "";
 		if (cause > 1 && cause < 128) {
 			switch_snprintf(reason, sizeof(reason), "Q.850;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause));
@@ -291,7 +291,7 @@
 		} else {
 			switch_snprintf(reason, sizeof(reason), "FreeSWITCH;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause));
 		}
-			
+
 		if (switch_test_flag(tech_pvt, TFLAG_ANS)) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending BYE to %s\n", switch_channel_get_name(channel));
 			nua_bye(tech_pvt->nh, SIPTAG_REASON_STR(reason), TAG_END());
@@ -349,7 +349,7 @@
 
 	b_sdp = switch_channel_get_variable(channel, SWITCH_B_SDP_VARIABLE);
 	is_proxy = (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA));
-	
+
 	if (b_sdp && is_proxy) {
 		tech_pvt->local_sdp_str = switch_core_session_strdup(session, b_sdp);
 
@@ -373,7 +373,7 @@
 				const char *r_sdp = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE);
 				tech_pvt->num_codecs = 0;
 				sofia_glue_tech_prepare_codecs(tech_pvt);
-				
+
 				if (sofia_glue_tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) {
 					switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR");
 					//nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END());
@@ -394,8 +394,7 @@
 
 		if (tech_pvt->nh) {
 			if (tech_pvt->local_sdp_str) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Local SDP %s:\n%s\n", switch_channel_get_name(channel),
-								  tech_pvt->local_sdp_str);
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Local SDP %s:\n%s\n", switch_channel_get_name(channel), tech_pvt->local_sdp_str);
 			}
 		}
 	}
@@ -406,16 +405,16 @@
 			session_timeout = v_session_timeout;
 		}
 	}
-	
+
 	if (switch_test_flag(tech_pvt, TFLAG_NAT) ||
-		(val = switch_channel_get_variable(channel, "sip-force-contact")) || 
+		(val = switch_channel_get_variable(channel, "sip-force-contact")) ||
 		((val = switch_channel_get_variable(channel, "sip_sticky_contact")) && switch_true(val))) {
 		sticky = tech_pvt->record_route;
 		session_timeout = SOFIA_NAT_SESSION_TIMEOUT;
 		switch_channel_set_variable(channel, "sip_nat_detected", "true");
 	}
 
-	
+
 
 	nua_respond(tech_pvt->nh, SIP_200_OK,
 				NUTAG_AUTOANSWER(0),
@@ -423,11 +422,7 @@
 				NUTAG_SESSION_TIMER(session_timeout),
 				SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
 				SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
-				SOATAG_REUSE_REJECTED(1),
-				SOATAG_ORDERED_USER(1),
-				SOATAG_AUDIO_AUX("cn telephone-event"),
-				NUTAG_INCLUDE_EXTRA_SDP(1),
-				TAG_END());
+				SOATAG_REUSE_REJECTED(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), TAG_END());
 
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -474,7 +469,7 @@
 				}
 				return status;
 			}
-			
+
 			payload = tech_pvt->video_read_frame.payload;
 
 			if (tech_pvt->video_read_frame.datalen > 0) {
@@ -524,13 +519,13 @@
 	if (!switch_test_flag(frame, SFF_CNG)) {
 		switch_rtp_write_frame(tech_pvt->video_rtp_session, frame);
 	}
-	
+
 	return status;
 }
 
 static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
 {
-	private_object_t *tech_pvt =  switch_core_session_get_private(session);
+	private_object_t *tech_pvt = switch_core_session_get_private(session);
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	int payload = 0;
 
@@ -558,7 +553,7 @@
 
 	if (switch_test_flag(tech_pvt, TFLAG_IO)) {
 		switch_status_t status;
-		
+
 		if (!switch_test_flag(tech_pvt, TFLAG_RTP)) {
 			return SWITCH_STATUS_GENERR;
 		}
@@ -570,22 +565,22 @@
 			tech_pvt->read_frame.flags = SFF_NONE;
 
 			status = switch_rtp_zerocopy_read_frame(tech_pvt->rtp_session, &tech_pvt->read_frame, flags);
-			
+
 			if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
 				if (status == SWITCH_STATUS_TIMEOUT) {
 					switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_MEDIA_TIMEOUT);
 				}
 				return status;
 			}
-			
+
 			payload = tech_pvt->read_frame.payload;
 
 			if (switch_rtp_has_dtmf(tech_pvt->rtp_session)) {
-				switch_dtmf_t dtmf = {0};
+				switch_dtmf_t dtmf = { 0 };
 				switch_rtp_dequeue_dtmf(tech_pvt->rtp_session, &dtmf);
 				switch_channel_queue_dtmf(channel, &dtmf);
 			}
-			
+
 			if (tech_pvt->read_frame.datalen > 0) {
 				size_t bytes = 0;
 				int frames = 1;
@@ -712,10 +707,7 @@
 
 	case DTMF_INFO:
 		snprintf(message, sizeof(message), "Signal=%c\r\nDuration=%d\r\n", dtmf->digit, dtmf->duration / 8);
-		nua_info(tech_pvt->nh,
-				 SIPTAG_CONTENT_TYPE_STR("application/dtmf-relay"),
-				 SIPTAG_PAYLOAD_STR(message),
-				 TAG_END());
+		nua_info(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("application/dtmf-relay"), SIPTAG_PAYLOAD_STR(message), TAG_END());
 		break;
 	default:
 		break;
@@ -750,18 +742,11 @@
 				" <media_control>\r\n"
 				"  <vc_primitive>\r\n"
 				"   <to_encoder>\r\n"
-				"    <picture_fast_update>\r\n"
-				"    </picture_fast_update>\r\n"
-				"   </to_encoder>\r\n"
-				"  </vc_primitive>\r\n"
-				" </media_control>\r\n";
-			
-			nua_info(tech_pvt->nh,
-					 SIPTAG_CONTENT_TYPE_STR("application/media_control+xml"),
-					 SIPTAG_PAYLOAD_STR(pl),
-					 TAG_END());
+				"    <picture_fast_update>\r\n" "    </picture_fast_update>\r\n" "   </to_encoder>\r\n" "  </vc_primitive>\r\n" " </media_control>\r\n";
+
+			nua_info(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("application/media_control+xml"), SIPTAG_PAYLOAD_STR(pl), TAG_END());
+
 
-			
 		}
 		break;
 	case SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY:
@@ -770,31 +755,27 @@
 			switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_PASS_RFC2833);
 		}
 		break;
-	case SWITCH_MESSAGE_INDICATE_BROADCAST: {
-		const char *ip = NULL, *port = NULL;
-		ip = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE);
-		port = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE);
-		if (ip && port) {
-			sofia_glue_set_local_sdp(tech_pvt, ip, atoi(port), msg->string_arg, 1);
-		}
-		nua_respond(tech_pvt->nh, SIP_200_OK,
-					SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
-					SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
-					SOATAG_REUSE_REJECTED(1),
-					SOATAG_ORDERED_USER(1),
-					SOATAG_AUDIO_AUX("cn telephone-event"),
-					NUTAG_INCLUDE_EXTRA_SDP(1),
-					TAG_END());
-		switch_channel_mark_answered(channel);
-	}
+	case SWITCH_MESSAGE_INDICATE_BROADCAST:{
+			const char *ip = NULL, *port = NULL;
+			ip = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_IP_VARIABLE);
+			port = switch_channel_get_variable(channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE);
+			if (ip && port) {
+				sofia_glue_set_local_sdp(tech_pvt, ip, atoi(port), msg->string_arg, 1);
+			}
+			nua_respond(tech_pvt->nh, SIP_200_OK,
+						SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
+						SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
+						SOATAG_REUSE_REJECTED(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), TAG_END());
+			switch_channel_mark_answered(channel);
+		}
 		break;
-	case SWITCH_MESSAGE_INDICATE_NOMEDIA: 
+	case SWITCH_MESSAGE_INDICATE_NOMEDIA:
 		{
 			const char *uuid;
 			switch_core_session_t *other_session;
 			switch_channel_t *other_channel;
 			const char *ip = NULL, *port = NULL;
-			
+
 			switch_channel_set_flag(channel, CF_PROXY_MODE);
 			tech_pvt->local_sdp_str = NULL;
 			if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))
@@ -826,14 +807,14 @@
 	case SWITCH_MESSAGE_INDICATE_MEDIA:
 		{
 			uint32_t send_invite = 1;
-			
+
 			switch_channel_clear_flag(channel, CF_PROXY_MODE);
 			tech_pvt->local_sdp_str = NULL;
 
 			if (!switch_channel_media_ready(channel)) {
 				if (!switch_channel_test_flag(tech_pvt->channel, CF_OUTBOUND)) {
 					const char *r_sdp = switch_channel_get_variable(channel, SWITCH_R_SDP_VARIABLE);
-					
+
 					tech_pvt->num_codecs = 0;
 					sofia_glue_tech_prepare_codecs(tech_pvt);
 					if (sofia_glue_tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) {
@@ -882,7 +863,7 @@
 			}
 		}
 		break;
-		
+
 	case SWITCH_MESSAGE_INDICATE_UNHOLD:
 		{
 			switch_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
@@ -890,7 +871,7 @@
 		}
 		break;
 	case SWITCH_MESSAGE_INDICATE_BRIDGE:
-		
+
 		if (switch_test_flag(tech_pvt, TFLAG_XFER)) {
 			switch_clear_flag_locked(tech_pvt, TFLAG_XFER);
 			if (msg->pointer_arg) {
@@ -918,19 +899,19 @@
 			}
 		}
 		/*
-		if (tech_pvt->rtp_session && switch_test_flag(tech_pvt, TFLAG_TIMER)) {
-			switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "De-activate timed RTP!\n");
-		}
-		*/
+		   if (tech_pvt->rtp_session && switch_test_flag(tech_pvt, TFLAG_TIMER)) {
+		   switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
+		   switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "De-activate timed RTP!\n");
+		   }
+		 */
 		break;
 	case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
 		/*
-		if (tech_pvt->rtp_session && switch_test_flag(tech_pvt, TFLAG_TIMER)) {
-			switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-activate timed RTP!\n");
-		}
-		*/
+		   if (tech_pvt->rtp_session && switch_test_flag(tech_pvt, TFLAG_TIMER)) {
+		   switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);
+		   switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-activate timed RTP!\n");
+		   }
+		 */
 		break;
 	case SWITCH_MESSAGE_INDICATE_REDIRECT:
 		if (msg->string_arg) {
@@ -962,7 +943,7 @@
 			if (code) {
 				reason = msg->string_arg;
 			} else {
-				if (!switch_strlen_zero(msg->string_arg)){
+				if (!switch_strlen_zero(msg->string_arg)) {
 					if ((code = atoi(msg->string_arg))) {
 						if ((reason = strchr(msg->string_arg, ' '))) {
 							reason++;
@@ -974,14 +955,14 @@
 			if (!code) {
 				code = 488;
 			}
-			
+
 			if (switch_strlen_zero(reason) && code != 407) {
 				reason = sip_status_phrase(code);
 				if (switch_strlen_zero(reason)) {
 					reason = "Because";
 				}
 			}
-			
+
 			if (code == 407 && !msg->numeric_arg) {
 				const char *to_uri = switch_channel_get_variable(channel, "sip_to_uri");
 				const char *to_host = reason;
@@ -990,14 +971,14 @@
 					to_host = switch_channel_get_variable(channel, "sip_to_host");
 				}
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Challenging call %s\n", to_uri);
-				sofia_reg_auth_challange(NULL, tech_pvt->profile, tech_pvt->nh, REG_INVITE, to_host, 0); 
+				sofia_reg_auth_challange(NULL, tech_pvt->profile, tech_pvt->nh, REG_INVITE, to_host, 0);
 				switch_channel_hangup(channel, SWITCH_CAUSE_USER_CHALLENGE);
 			} else if (code == 484 && msg->numeric_arg) {
 				const char *to = switch_channel_get_variable(channel, "sip_to_uri");
 				const char *max_forwards = switch_channel_get_variable(channel, SWITCH_MAX_FORWARDS_VARIABLE);
-				
+
 				char *to_uri = NULL;
-				
+
 				if (to) {
 					char *p;
 					to_uri = switch_core_session_sprintf(session, "sip:%s", to);
@@ -1015,9 +996,9 @@
 				}
 			} else {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Responding with %d [%s]\n", code, reason);
-				
-				if (!switch_strlen_zero(((char *)msg->pointer_arg))) {
-					tech_pvt->local_sdp_str = switch_core_session_strdup(tech_pvt->session, (char *)msg->pointer_arg);
+
+				if (!switch_strlen_zero(((char *) msg->pointer_arg))) {
+					tech_pvt->local_sdp_str = switch_core_session_strdup(tech_pvt->session, (char *) msg->pointer_arg);
 					if (switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
 						sofia_glue_tech_patch_sdp(tech_pvt);
 						sofia_glue_tech_proxy_remote_addr(tech_pvt);
@@ -1025,10 +1006,7 @@
 					nua_respond(tech_pvt->nh, code, reason, SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
 								SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
 								SOATAG_REUSE_REJECTED(1),
-								SOATAG_ORDERED_USER(1),
-								SOATAG_AUDIO_AUX("cn telephone-event"),
-								NUTAG_INCLUDE_EXTRA_SDP(1),
-								TAG_END());
+								SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), TAG_END());
 				} else {
 					nua_respond(tech_pvt->nh, code, reason, SIPTAG_CONTACT_STR(tech_pvt->reply_contact), TAG_END());
 				}
@@ -1036,11 +1014,11 @@
 					switch_set_flag_locked(tech_pvt, TFLAG_BYE);
 				}
 			}
-			
+
 		}
 		break;
 	case SWITCH_MESSAGE_INDICATE_RINGING:
-		if (!switch_channel_test_flag(channel, CF_RING_READY) && 
+		if (!switch_channel_test_flag(channel, CF_RING_READY) &&
 			!switch_channel_test_flag(channel, CF_EARLY_MEDIA) && !switch_channel_test_flag(channel, CF_ANSWERED)) {
 			nua_respond(tech_pvt->nh, SIP_180_RINGING, SIPTAG_CONTACT_STR(tech_pvt->reply_contact), TAG_END());
 			switch_channel_mark_ring_ready(channel);
@@ -1055,10 +1033,10 @@
 			const char *val = NULL;
 
 			if (!switch_test_flag(tech_pvt, TFLAG_ANS) && !switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) {
-				
+
 				switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA);
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Asked to send early media by %s\n", msg->from);
-				
+
 				/* Transmit 183 Progress with SDP */
 				if (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
 					const char *sdp = NULL;
@@ -1105,7 +1083,7 @@
 
 
 				if (switch_test_flag(tech_pvt, TFLAG_NAT) ||
-					(val = switch_channel_get_variable(channel, "sip-force-contact")) || 
+					(val = switch_channel_get_variable(channel, "sip-force-contact")) ||
 					((val = switch_channel_get_variable(channel, "sip_sticky_contact")) && switch_true(val))) {
 					sticky = tech_pvt->record_route;
 					switch_channel_set_variable(channel, "sip_nat_detected", "true");
@@ -1117,8 +1095,7 @@
 							TAG_IF(sticky, NUTAG_PROXY(tech_pvt->record_route)),
 							SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
 							SOATAG_REUSE_REJECTED(1),
-							SOATAG_ORDERED_USER(1),
-							SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_AUDIO_AUX("cn telephone-event"), TAG_END());
+							SOATAG_ORDERED_USER(1), SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_AUDIO_AUX("cn telephone-event"), TAG_END());
 			}
 		}
 		break;
@@ -1126,10 +1103,10 @@
 		break;
 	}
 
- end:
-	
+  end:
+
 	return status;
-	
+
 }
 
 static switch_status_t sofia_receive_event(switch_core_session_t *session, switch_event_t *event)
@@ -1158,14 +1135,15 @@
 typedef switch_status_t (*sofia_command_t) (char **argv, int argc, switch_stream_handle_t *stream);
 
 static const char *sofia_state_names[] = { "UNREGED",
-										   "TRYING",
-										   "REGISTER",
-										   "REGED",
-										   "UNREGISTER",
-										   "FAILED",
-										   "EXPIRED",
-										   "NOREG",
-										   NULL};
+	"TRYING",
+	"REGISTER",
+	"REGED",
+	"UNREGISTER",
+	"FAILED",
+	"EXPIRED",
+	"NOREG",
+	NULL
+};
 
 struct cb_helper {
 	sofia_profile_t *profile;
@@ -1188,17 +1166,14 @@
 		switch_strftime(exp_buf, &retsize, sizeof(exp_buf), "%Y-%m-%d %T", &tm);
 	}
 
-	cb->stream->write_function(cb->stream, 
+	cb->stream->write_function(cb->stream,
 							   "Call-ID \t%s\n"
 							   "User    \t%s@%s\n"
 							   "Contact \t%s\n"
 							   "Agent   \t%s\n"
-							   "Status  \t%s(%s) EXP(%s)\n\n", 
-							   switch_str_nil(argv[0]), switch_str_nil(argv[1]), switch_str_nil(argv[2]), switch_str_nil(argv[3]), 
-							   switch_str_nil(argv[7]), 
-							   switch_str_nil(argv[4]), 
-							   switch_str_nil(argv[5]), 
-							   exp_buf);
+							   "Status  \t%s(%s) EXP(%s)\n\n",
+							   switch_str_nil(argv[0]), switch_str_nil(argv[1]), switch_str_nil(argv[2]), switch_str_nil(argv[3]),
+							   switch_str_nil(argv[7]), switch_str_nil(argv[4]), switch_str_nil(argv[5]), exp_buf);
 	return 0;
 }
 
@@ -1254,24 +1229,24 @@
 				stream->write_function(stream, "Name       \t%s\n", switch_str_nil(argv[1]));
 				stream->write_function(stream, "Domain Name\t%s\n", switch_str_nil(profile->domain_name));
 				if (strcasecmp(argv[1], profile->name)) {
-				stream->write_function(stream, "Alias Of   \t%s\n", switch_str_nil(profile->name));
+					stream->write_function(stream, "Alias Of   \t%s\n", switch_str_nil(profile->name));
 				}
 				stream->write_function(stream, "DBName     \t%s\n", switch_str_nil(profile->dbname));
 				stream->write_function(stream, "Dialplan   \t%s\n", switch_str_nil(profile->dialplan));
 				stream->write_function(stream, "RTP-IP     \t%s\n", switch_str_nil(profile->rtpip));
 				if (profile->extrtpip) {
-				stream->write_function(stream, "Ext-RTP-IP \t%s\n", profile->extrtpip);
+					stream->write_function(stream, "Ext-RTP-IP \t%s\n", profile->extrtpip);
 				}
-				
+
 				stream->write_function(stream, "SIP-IP     \t%s\n", switch_str_nil(profile->sipip));
 				if (profile->extsipip) {
-				stream->write_function(stream, "Ext-SIP-IP \t%s\n", profile->extsipip);
+					stream->write_function(stream, "Ext-SIP-IP \t%s\n", profile->extsipip);
 				}
 				stream->write_function(stream, "URL        \t%s\n", switch_str_nil(profile->url));
 				stream->write_function(stream, "BIND-URL   \t%s\n", switch_str_nil(profile->bindurl));
 				if (sofia_test_pflag(profile, PFLAG_TLS)) {
-				stream->write_function(stream, "TLS-URL   \t%s\n", switch_str_nil(profile->tls_url));
-				stream->write_function(stream, "TLS-BIND-URL   \t%s\n", switch_str_nil(profile->tls_bindurl));
+					stream->write_function(stream, "TLS-URL   \t%s\n", switch_str_nil(profile->tls_url));
+					stream->write_function(stream, "TLS-BIND-URL   \t%s\n", switch_str_nil(profile->tls_bindurl));
 				}
 				stream->write_function(stream, "HOLD-MUSIC \t%s\n", switch_str_nil(profile->hold_music));
 				stream->write_function(stream, "CODECS     \t%s\n", switch_str_nil(profile->codec_string));
@@ -1283,10 +1258,8 @@
 
 				cb.profile = profile;
 				cb.stream = stream;
-				
-				sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex,
-												"select * from sip_registrations",
-												show_reg_callback, &cb);
+
+				sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, "select * from sip_registrations", show_reg_callback, &cb);
 
 				stream->write_function(stream, "%s\n", line);
 
@@ -1308,7 +1281,7 @@
 		switch_hash_this(hi, &vvar, NULL, &val);
 		profile = (sofia_profile_t *) val;
 		if (sofia_test_pflag(profile, PFLAG_RUNNING)) {
-			
+
 			if (strcmp(vvar, profile->name)) {
 				ac++;
 				stream->write_function(stream, "%25s\t%s\t  %32s\t%s\n", vvar, "  alias", profile->name, "ALIASED");
@@ -1317,8 +1290,8 @@
 									   sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN", profile->inuse);
 
 				if (sofia_test_pflag(profile, PFLAG_TLS)) {
-				stream->write_function(stream, "%25s\t%s\t  %32s\t%s (%u) (TLS)\n", profile->name, "profile", profile->tls_url,
-									   sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN", profile->inuse);
+					stream->write_function(stream, "%25s\t%s\t  %32s\t%s (%u) (TLS)\n", profile->name, "profile", profile->tls_url,
+										   sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN", profile->inuse);
 				}
 
 				c++;
@@ -1366,12 +1339,12 @@
 		}
 		return SWITCH_STATUS_SUCCESS;
 	}
-	
+
 	if (switch_strlen_zero(profile_name) || !(profile = sofia_glue_find_profile(profile_name))) {
 		stream->write_function(stream, "Invalid Profile [%s]", switch_str_nil(profile_name));
 		return SWITCH_STATUS_SUCCESS;
 	}
-	
+
 	if (!strcasecmp(argv[1], "flush_inbound_reg")) {
 		if (argc > 2) {
 			sofia_reg_expire_call_id(profile, argv[2]);
@@ -1407,7 +1380,7 @@
 		} else {
 			stream->write_function(stream, "Invalid gateway!\n");
 		}
-		
+
 		goto done;
 	}
 
@@ -1442,7 +1415,7 @@
 		int diff = (int) (switch_timestamp(NULL) - profile->started);
 		int remain = rsec - diff;
 		if (diff < rsec) {
-			stream->write_function(stream, "Profile %s must be up for at least %d seconds to stop/restart.\nPlease wait %d second%s\n", 
+			stream->write_function(stream, "Profile %s must be up for at least %d seconds to stop/restart.\nPlease wait %d second%s\n",
 								   profile->name, rsec, remain, remain == 1 ? "" : "s");
 		} else {
 
@@ -1467,7 +1440,7 @@
 
 	stream->write_function(stream, "-ERR Unknown command!\n");
 
- done:
+  done:
 	if (profile) {
 		sofia_glue_release_profile(profile);
 	}
@@ -1524,14 +1497,14 @@
 	if ((domain = strchr(user, '@'))) {
 		*domain++ = '\0';
 	}
-	
+
 	if (!profile_name && domain) {
 		profile_name = domain;
 	}
 
 	if (user && profile_name) {
 		char *sql;
-		
+
 		if (!(profile = sofia_glue_find_profile(profile_name))) {
 			profile_name = domain;
 			domain = NULL;
@@ -1544,7 +1517,7 @@
 		if (profile) {
 			struct cb_helper cb;
 			switch_stream_handle_t mystream = { 0 };
-			
+
 			if (!domain || !strchr(domain, '.')) {
 				domain = profile->name;
 			}
@@ -1553,9 +1526,9 @@
 			switch_assert(mystream.data);
 			cb.profile = profile;
 			cb.stream = &mystream;
-			
+
 			if (exclude_contact) {
-				sql = switch_mprintf("select contact from sip_registrations where sip_user='%q' and sip_host='%q' and contact not like '%%%s%%'", 
+				sql = switch_mprintf("select contact from sip_registrations where sip_user='%q' and sip_host='%q' and contact not like '%%%s%%'",
 									 user, domain, exclude_contact);
 			} else {
 				sql = switch_mprintf("select contact from sip_registrations where sip_user='%q' and sip_host='%q'", user, domain);
@@ -1573,7 +1546,7 @@
 			switch_safe_free(mystream.data);
 		}
 	}
-	
+
 	if (reply) {
 		stream->write_function(stream, "%s", reply);
 	}
@@ -1600,13 +1573,12 @@
 		"sofia help\n"
 		"sofia profile <profile_name> [start|stop|restart|flush_inbound_reg [<call_id>]|[register|unregister] [<gateway name>|all]] [reloadxml]\n"
 		"sofia status [[profile | gateway] <name>]\n"
-		"sofia loglevel [0-9]\n"
-		"--------------------------------------------------------------------------------\n";
-		
+		"sofia loglevel [0-9]\n" "--------------------------------------------------------------------------------\n";
+
 	if (session) {
 		return SWITCH_STATUS_FALSE;
 	}
-	
+
 	if (switch_strlen_zero(cmd)) {
 		stream->write_function(stream, "%s", usage_string);
 		goto done;
@@ -1621,7 +1593,7 @@
 		stream->write_function(stream, "%s", usage_string);
 		goto done;
 	}
-	
+
 	if (!strcasecmp(argv[0], "profile")) {
 		func = cmd_profile;
 	} else if (!strcasecmp(argv[0], "status")) {
@@ -1664,9 +1636,9 @@
 	/*.send_dtmf */ sofia_send_dtmf,
 	/*.receive_message */ sofia_receive_message,
 	/*.receive_event */ sofia_receive_event,
-	/*.state_change*/ NULL,
-	/*.read_video_frame*/ sofia_read_video_frame,
-	/*.write_video_frame*/ sofia_write_video_frame
+	/*.state_change */ NULL,
+	/*.read_video_frame */ sofia_read_video_frame,
+	/*.write_video_frame */ sofia_write_video_frame
 };
 
 switch_state_handler_table_t sofia_event_handlers = {
@@ -1677,8 +1649,8 @@
 	/*.on_exchange_media */ sofia_on_exchange_media,
 	/*.on_soft_execute */ sofia_on_soft_execute,
 	/*.on_consume_media */ NULL,
-	/*.on_hibernate*/ sofia_on_hibernate,
-	/*.on_reset*/ sofia_on_reset
+	/*.on_hibernate */ sofia_on_hibernate,
+	/*.on_reset */ sofia_on_reset
 };
 
 static switch_status_t sofia_manage(char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen)
@@ -1698,7 +1670,7 @@
 	private_object_t *tech_pvt = NULL;
 	switch_channel_t *nchannel;
 	char *host = NULL, *dest_to = NULL;
-	
+
 	*new_session = NULL;
 
 	if (!(nsession = switch_core_session_request(sofia_endpoint_interface, pool))) {
@@ -1758,14 +1730,14 @@
 		 * invite contact.
 		 *
 		 * TODO:
-		 *	- Add parameters back to destination url?
+		 *  - Add parameters back to destination url?
 		 */
 		if ((params = strchr(dest, ';'))) {
 			char *tp_param;
 
 			*params++ = '\0';
 
-			if ((tp_param = (char *)switch_stristr("port=", params))) {
+			if ((tp_param = (char *) switch_stristr("port=", params))) {
 				tp_param += 5;
 				tech_pvt->transport = sofia_glue_str2transport(tp_param);
 				if (tech_pvt->transport == SOFIA_TRANSPORT_UNKNOWN) {
@@ -1776,7 +1748,8 @@
 		}
 
 		if (tech_pvt->transport != gateway_ptr->register_transport) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "You are trying to use a different transport type for this gateway (overriding the register-transport), this is unsupported!\n");
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+							  "You are trying to use a different transport type for this gateway (overriding the register-transport), this is unsupported!\n");
 			cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
 			goto error;
 		}
@@ -1860,7 +1833,7 @@
 			tech_pvt->dest_to = switch_core_session_sprintf(nsession, "sip:%s@%s", dest_to, host);
 		}
 	}
-	
+
 
 	if (!tech_pvt->dest_to) {
 		tech_pvt->dest_to = tech_pvt->dest;
@@ -1961,7 +1934,7 @@
 	switch_core_hash_init(&mod_sofia_globals.profile_hash, mod_sofia_globals.pool);
 	switch_core_hash_init(&mod_sofia_globals.gateway_hash, mod_sofia_globals.pool);
 	switch_mutex_init(&mod_sofia_globals.hash_mutex, SWITCH_MUTEX_NESTED, mod_sofia_globals.pool);
-	
+
 	switch_mutex_lock(mod_sofia_globals.mutex);
 	mod_sofia_globals.running = 1;
 	switch_mutex_unlock(mod_sofia_globals.mutex);
@@ -2034,7 +2007,7 @@
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_sofia_shutdown)
 {
 	int sanity = 0;
-	
+
 	switch_mutex_lock(mod_sofia_globals.mutex);
 	if (mod_sofia_globals.running == 1) {
 		mod_sofia_globals.running = 0;

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	Tue May 27 00:54:52 2008
@@ -56,14 +56,15 @@
 
 static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
 									 char const *phrase,
-									 nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
+									 nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+									 tagi_t tags[]);
 
 static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status,
-									 char const *phrase,
-									 nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
-static void sofia_handle_sip_r_options(switch_core_session_t *session, int status,
-									 char const *phrase,
-									  nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
+									  char const *phrase,
+									  nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+									  tagi_t tags[]);
+static void sofia_handle_sip_r_options(switch_core_session_t *session, int status, char const *phrase, nua_t *nua, sofia_profile_t *profile,
+									   nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
 
 void sofia_handle_sip_r_notify(switch_core_session_t *session, int status,
 							   char const *phrase,
@@ -79,16 +80,11 @@
 }
 
 void sofia_handle_sip_i_notify(switch_core_session_t *session, int status,
-							  char const *phrase,
-							  nua_t *nua,
-							  sofia_profile_t *profile,
-							  nua_handle_t *nh,
-							  sofia_private_t *sofia_private,
-							  sip_t const *sip,
-							  tagi_t tags[])
+							   char const *phrase,
+							   nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
 {
 	switch_channel_t *channel = NULL;
-	
+
 	/* make sure we have a proper event */
 	if (!sip || !sip->sip_event) {
 		goto error;
@@ -110,41 +106,36 @@
 	if (!switch_channel_test_flag(channel, CF_OUTBOUND)) {
 		switch_channel_answer(channel);
 		switch_channel_set_variable(channel, "auto_answer_destination", switch_channel_get_variable(channel, "destination_number"));
-		switch_ivr_session_transfer(session, "auto_answer", NULL , NULL);
+		switch_ivr_session_transfer(session, "auto_answer", NULL, NULL);
 		nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
 		return;
 	}
 
-error:
+  error:
 	nua_respond(nh, 481, "Subscription Does Not Exist", NUTAG_WITH_THIS(nua), TAG_END());
 	return;
 }
 
 void sofia_handle_sip_i_bye(switch_core_session_t *session, int status,
-							  char const *phrase,
-							  nua_t *nua,
-							  sofia_profile_t *profile,
-							  nua_handle_t *nh,
-							  sofia_private_t *sofia_private,
-							  sip_t const *sip,
-							  tagi_t tags[])
+							char const *phrase,
+							nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
 {
 	const char *tmp;
 	switch_channel_t *channel;
 
-	if (!session) return;
+	if (!session)
+		return;
 
-	channel = switch_core_session_get_channel(session); 
+	channel = switch_core_session_get_channel(session);
 
 
-    if (sip->sip_reason && sip->sip_reason->re_protocol && 
-        (!strcasecmp(sip->sip_reason->re_protocol, "Q.850") || !strcasecmp(sip->sip_reason->re_protocol, "FreeSWITCH")) &&
-        sip->sip_reason->re_cause) {
-        private_object_t *tech_pvt = switch_core_session_get_private(session);
-        tech_pvt->q850_cause = atoi(sip->sip_reason->re_cause);
-    }
+	if (sip->sip_reason && sip->sip_reason->re_protocol &&
+		(!strcasecmp(sip->sip_reason->re_protocol, "Q.850") || !strcasecmp(sip->sip_reason->re_protocol, "FreeSWITCH")) && sip->sip_reason->re_cause) {
+		private_object_t *tech_pvt = switch_core_session_get_private(session);
+		tech_pvt->q850_cause = atoi(sip->sip_reason->re_cause);
+	}
 
-	if (sip->sip_user_agent && !switch_strlen_zero(sip->sip_user_agent->g_string)){
+	if (sip->sip_user_agent && !switch_strlen_zero(sip->sip_user_agent->g_string)) {
 		switch_channel_set_variable(channel, "sip_user_agent", sip->sip_user_agent->g_string);
 	}
 	if ((tmp = sofia_glue_get_unknown_header(sip, "rtp-txstat"))) {
@@ -163,12 +154,7 @@
 void sofia_event_callback(nua_event_t event,
 						  int status,
 						  char const *phrase,
-						  nua_t *nua,
-						  sofia_profile_t *profile,
-						  nua_handle_t *nh,
-						  sofia_private_t *sofia_private,
-						  sip_t const *sip,
-						  tagi_t tags[])
+						  nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
 {
 	struct private_object *tech_pvt = NULL;
 	auth_res_t auth_res = AUTH_FORBIDDEN;
@@ -199,7 +185,7 @@
 			}
 		}
 	}
-	
+
 	if (status != 100 && status != 200) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "event [%s] status [%d][%s] session: %s\n",
 						  nua_event_name(event), status, phrase, session ? switch_channel_get_name(channel) : "n/a");
@@ -216,7 +202,7 @@
 
 	if ((profile->pflags & PFLAG_AUTH_ALL) && tech_pvt && tech_pvt->key && sip) {
 		sip_authorization_t const *authorization = NULL;
-		
+
 		if (sip->sip_authorization) {
 			authorization = sip->sip_authorization;
 		} else if (sip->sip_proxy_authorization) {
@@ -226,8 +212,9 @@
 		if (authorization) {
 			char network_ip[80];
 			get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_addr);
-			auth_res = sofia_reg_parse_auth(profile, authorization, sip, 
-											(char *) sip->sip_request->rq_method_name, tech_pvt->key, strlen(tech_pvt->key), network_ip, NULL, 0, REG_INVITE, NULL);
+			auth_res = sofia_reg_parse_auth(profile, authorization, sip,
+											(char *) sip->sip_request->rq_method_name, tech_pvt->key, strlen(tech_pvt->key), network_ip, NULL, 0,
+											REG_INVITE, NULL);
 		}
 
 		if (auth_res != AUTH_OK) {
@@ -408,9 +395,9 @@
 
 		switch_mutex_lock(profile->ireg_mutex);
 		sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
-		
+
 		sql = switch_mprintf("insert into sip_registrations values ('%q', '%q','%q','%q','Registered', '%q', %ld, '%q')",
-							  call_id, from_user, from_host, contact_str, rpid, expires, user_agent);
+							 call_id, from_user, from_host, contact_str, rpid, expires, user_agent);
 
 		if (sql) {
 			sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
@@ -437,9 +424,9 @@
 	gateway_loops = GATEWAY_SECONDS;
 
 	sofia_set_pflag_locked(profile, PFLAG_WORKER_RUNNING);
-	
+
 	switch_queue_create(&profile->sql_queue, 500000, profile->pool);
-	
+
 	qsize = switch_queue_size(profile->sql_queue);
 
 	while ((mod_sofia_globals.running == 1 && sofia_test_pflag(profile, PFLAG_RUNNING)) || qsize) {
@@ -469,9 +456,9 @@
 		switch_yield(10000);
 		qsize = switch_queue_size(profile->sql_queue);
 	}
-	
+
 	sofia_clear_pflag_locked(profile, PFLAG_WORKER_RUNNING);
-	
+
 	return NULL;
 }
 
@@ -488,7 +475,7 @@
 	switch_threadattr_priority_increase(thd_attr);
 	switch_thread_create(&thread, thd_attr, sofia_profile_worker_thread_run, profile, profile->pool);
 
-	while(!sofia_test_pflag(profile, PFLAG_WORKER_RUNNING)) {
+	while (!sofia_test_pflag(profile, PFLAG_WORKER_RUNNING)) {
 		switch_yield(100000);
 		if (++x >= 100) {
 			break;
@@ -537,16 +524,9 @@
 	}
 
 	profile->nua = nua_create(profile->s_root,	/* Event loop */
-							sofia_event_callback,	/* Callback for processing events */
-							profile,	/* Additional data to pass to callback */
-							NUTAG_URL(profile->bindurl),
-							TAG_IF(sofia_test_pflag(profile, PFLAG_TLS), NUTAG_SIPS_URL(profile->tls_bindurl)),
-							TAG_IF(sofia_test_pflag(profile, PFLAG_TLS), NUTAG_CERTIFICATE_DIR(profile->tls_cert_dir)),
-							TAG_IF(sofia_test_pflag(profile, PFLAG_TLS), TPTAG_TLS_VERSION(profile->tls_version)),
-							NTATAG_UDP_MTU(65536),
-							NTATAG_SERVER_RPORT(2),
-							TAG_IF(tportlog, TPTAG_LOG(1)),
-							TAG_END());	/* Last tag should always finish the sequence */
+							  sofia_event_callback,	/* Callback for processing events */
+							  profile,	/* Additional data to pass to callback */
+							  NUTAG_URL(profile->bindurl), TAG_IF(sofia_test_pflag(profile, PFLAG_TLS), NUTAG_SIPS_URL(profile->tls_bindurl)), TAG_IF(sofia_test_pflag(profile, PFLAG_TLS), NUTAG_CERTIFICATE_DIR(profile->tls_cert_dir)), TAG_IF(sofia_test_pflag(profile, PFLAG_TLS), TPTAG_TLS_VERSION(profile->tls_version)), NTATAG_UDP_MTU(65536), NTATAG_SERVER_RPORT(2), TAG_IF(tportlog, TPTAG_LOG(1)), TAG_END());	/* Last tag should always finish the sequence */
 
 	if (!profile->nua) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Creating SIP UA for profile: %s\n", profile->name);
@@ -585,10 +565,9 @@
 
 	for (node = profile->aliases; node; node = node->next) {
 		node->nua = nua_create(profile->s_root,	/* Event loop */
-								sofia_event_callback,	/* Callback for processing events */
-								profile,	/* Additional data to pass to callback */
-								NTATAG_SERVER_RPORT(2),
-								NUTAG_URL(node->url), TAG_END());	/* Last tag should always finish the sequence */
+							   sofia_event_callback,	/* Callback for processing events */
+							   profile,	/* Additional data to pass to callback */
+							   NTATAG_SERVER_RPORT(2), NUTAG_URL(node->url), TAG_END());	/* Last tag should always finish the sequence */
 
 		nua_set_params(node->nua,
 					   NUTAG_APPL_METHOD("OPTIONS"),
@@ -600,8 +579,7 @@
 					   NUTAG_ALLOW("INFO"),
 					   TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW("PUBLISH")),
 					   TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ENABLEMESSAGE(1)),
-					   SIPTAG_SUPPORTED_STR(supported), 
-					   SIPTAG_USER_AGENT_STR(profile->user_agent), TAG_END());
+					   SIPTAG_SUPPORTED_STR(supported), SIPTAG_USER_AGENT_STR(profile->user_agent), TAG_END());
 	}
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "activated db for %s\n", profile->name);
@@ -653,11 +631,11 @@
 	sofia_clear_pflag_locked(profile, PFLAG_RUNNING);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "waiting for worker thread\n");
 
-	while(sofia_test_pflag(profile, PFLAG_WORKER_RUNNING)) {
+	while (sofia_test_pflag(profile, PFLAG_WORKER_RUNNING)) {
 		switch_yield(100000);
 	}
 
-	while(profile->inuse) {
+	while (profile->inuse) {
 		switch_yield(100000);
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "waiting for %d session(s)\n", profile->inuse);
 	}
@@ -671,7 +649,7 @@
 
 	if (switch_event_create(&s_event, SWITCH_EVENT_UNPUBLISH) == SWITCH_STATUS_SUCCESS) {
 		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "service", "_sip._udp,_sip._tcp,_sip._sctp%s",
-							(sofia_test_pflag(profile, PFLAG_TLS)) ? ",_sips._tcp" : "");
+								(sofia_test_pflag(profile, PFLAG_TLS)) ? ",_sips._tcp" : "");
 
 		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "port", "%d", profile->sip_port);
 		switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "module_name", "%s", "mod_sofia");
@@ -782,12 +760,7 @@
 				*context = "default",
 				*expire_seconds = "3600",
 				*retry_seconds = "30",
-				*from_user = "",
-				*from_domain = "",
-				*register_proxy = NULL,
-				*contact_params = NULL,
-				*params = NULL,
-				*register_transport = NULL;
+				*from_user = "", *from_domain = "", *register_proxy = NULL, *contact_params = NULL, *params = NULL, *register_transport = NULL;
 
 			uint32_t ping_freq = 0;
 
@@ -908,7 +881,7 @@
 			if (switch_true(caller_id_in_from)) {
 				switch_set_flag(gateway, REG_FLAG_CALLERID);
 			}
-			register_transport = (char *)sofia_glue_transport2str(gateway->register_transport);
+			register_transport = (char *) sofia_glue_transport2str(gateway->register_transport);
 			if (contact_params) {
 				if (*contact_params == ';') {
 					params = switch_core_sprintf(gateway->pool, "%s&transport=%s", contact_params, register_transport);
@@ -922,8 +895,9 @@
 			gateway->register_url = switch_core_sprintf(gateway->pool, "sip:%s;transport=%s", register_proxy, register_transport);
 			gateway->register_from = switch_core_sprintf(gateway->pool, "<sip:%s@%s;transport=%s>", from_user, from_domain, register_transport);
 			gateway->register_contact = switch_core_sprintf(gateway->pool, "<sip:%s@%s:%d%s>", extension,
-												 profile->extsipip ? profile->extsipip : profile->sipip,
-												 sofia_glue_transport_has_tls(gateway->register_transport) ? profile->tls_sip_port : profile->sip_port, params);
+															profile->extsipip ? profile->extsipip : profile->sipip,
+															sofia_glue_transport_has_tls(gateway->register_transport) ? profile->tls_sip_port : profile->
+															sip_port, params);
 
 			if (!strncasecmp(proxy, "sip:", 4)) {
 				gateway->register_proxy = switch_core_strdup(gateway->pool, proxy);
@@ -936,8 +910,7 @@
 			gateway->expires_str = switch_core_strdup(gateway->pool, expire_seconds);
 
 			if ((gateway->freq = atoi(gateway->expires_str)) < 5) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
-								   "Invalid Freq: %d.  Setting Register-Frequency to 3600\n", gateway->freq);
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid Freq: %d.  Setting Register-Frequency to 3600\n", gateway->freq);
 				gateway->freq = 3600;
 			}
 			gateway->freq -= 2;
@@ -947,7 +920,7 @@
 			sofia_reg_add_gateway(gateway->name, gateway);
 		}
 
-	skip:
+	  skip:
 		switch_assert(gateway_tag);
 	}
 }
@@ -960,11 +933,10 @@
 		if (sofia_glue_add_profile(switch_core_strdup(profile->pool, dname), profile) == SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding Alias [%s] for profile [%s]\n", dname, profile->name);
 		} else {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Adding Alias [%s] for profile [%s] (name in use)\n", 
-							  dname, profile->name);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Adding Alias [%s] for profile [%s] (name in use)\n", dname, profile->name);
 		}
 	}
-	
+
 	if (switch_true(parse)) {
 		switch_xml_t ut, gateways_tag;
 		for (ut = switch_xml_child(x_domain_tag, "user"); ut; ut = ut->next) {
@@ -985,7 +957,7 @@
 	char url[512] = "";
 	int profile_found = 0;
 	switch_event_t *params = NULL;;
-	
+
 	if (!reload) {
 		su_init();
 		if (sip_update_default_mclass(sip_extend_mclass(NULL)) < 0) {
@@ -1007,7 +979,7 @@
 	switch_event_create(&params, SWITCH_EVENT_MESSAGE);
 	switch_assert(params);
 	switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "profile", profile_name);
-	
+
 	if (!(xml = switch_xml_open_cfg(cf, &cfg, params))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
 		status = SWITCH_STATUS_FALSE;
@@ -1075,7 +1047,7 @@
 				profile->dtmf_duration = 100;
 				profile->tls_version = 0;
 				profile->mflags = MFLAG_REFER | MFLAG_REGISTER;
-				
+
 				for (param = switch_xml_child(settings, "param"); param; param = param->next) {
 					char *var = (char *) switch_xml_attr_soft(param, "name");
 					char *val = (char *) switch_xml_attr_soft(param, "value");
@@ -1095,7 +1067,6 @@
 								*profile->odbc_pass++ = '\0';
 							}
 						}
-
 #else
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
 #endif
@@ -1345,9 +1316,9 @@
 							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Duration out of bounds!\n");
 						}
 
-					/*
-					 * handle TLS params #1
-					 */
+						/*
+						 * handle TLS params #1
+						 */
 					} else if (!strcasecmp(var, "tls")) {
 						if (switch_true(val)) {
 							sofia_set_pflag(profile, PFLAG_TLS);
@@ -1365,7 +1336,7 @@
 						} else {
 							profile->tls_version = 0;
 						}
- 					}
+					}
 				}
 
 				if (!profile->cng_pt) {
@@ -1432,7 +1403,8 @@
 
 					if (profile->extsipip) {
 						profile->tls_url = switch_core_sprintf(profile->pool, "sip:mod_sofia@%s:%d", profile->extsipip, profile->tls_sip_port);
-						profile->tls_bindurl = switch_core_sprintf(profile->pool, "sips:mod_sofia@%s:%d;maddr=%s", profile->extsipip, profile->tls_sip_port, profile->sipip);
+						profile->tls_bindurl =
+							switch_core_sprintf(profile->pool, "sips:mod_sofia@%s:%d;maddr=%s", profile->extsipip, profile->tls_sip_port, profile->sipip);
 					} else {
 						profile->tls_url = switch_core_sprintf(profile->pool, "sip:mod_sofia@%s:%d", profile->sipip, profile->tls_sip_port);
 						profile->tls_bindurl = switch_core_sprintf(profile->pool, "sips:mod_sofia@%s:%d", profile->sipip, profile->tls_sip_port);
@@ -1464,12 +1436,12 @@
 						const char *dname = switch_xml_attr_soft(domain_tag, "name");
 						const char *parse = switch_xml_attr_soft(domain_tag, "parse");
 						const char *alias = switch_xml_attr_soft(domain_tag, "alias");
-						
-						if (!switch_strlen_zero(dname)) { 
+
+						if (!switch_strlen_zero(dname)) {
 							if (!strcasecmp(dname, "all")) {
 								switch_xml_t xml_root, x_domains;
 								if (switch_xml_locate("directory", NULL, NULL, NULL, &xml_root, &x_domains, NULL) == SWITCH_STATUS_SUCCESS) {
-									for(x_domain_tag = switch_xml_child(x_domains, "domain"); x_domain_tag; x_domain_tag = x_domain_tag->next) {
+									for (x_domain_tag = switch_xml_child(x_domains, "domain"); x_domain_tag; x_domain_tag = x_domain_tag->next) {
 										dname = switch_xml_attr_soft(x_domain_tag, "name");
 										parse_domain_tag(profile, x_domain_tag, dname, parse, alias);
 									}
@@ -1477,7 +1449,7 @@
 								}
 							} else if (switch_xml_locate_domain(dname, NULL, &droot, &x_domain_tag) == SWITCH_STATUS_SUCCESS) {
 								parse_domain_tag(profile, x_domain_tag, dname, parse, alias);
-								switch_xml_free(droot);									
+								switch_xml_free(droot);
 							}
 						}
 					}
@@ -1491,8 +1463,8 @@
 							if (sofia_glue_add_profile(switch_core_strdup(profile->pool, aname), profile) == SWITCH_STATUS_SUCCESS) {
 								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding Alias [%s] for profile [%s]\n", aname, profile->name);
 							} else {
-								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Adding Alias [%s] for profile [%s] (name in use)\n", 
-												   aname, profile->name);
+								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Adding Alias [%s] for profile [%s] (name in use)\n",
+												  aname, profile->name);
 							}
 						}
 					}
@@ -1529,7 +1501,8 @@
 
 static void sofia_handle_sip_r_options(switch_core_session_t *session, int status,
 									   char const *phrase,
-									  nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
+									   nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+									   tagi_t tags[])
 {
 	sofia_gateway_t *gateway = NULL;
 
@@ -1559,16 +1532,11 @@
 	} else if ((profile->pflags & PFLAG_UNREG_OPTIONS_FAIL) && status != 200 && sip && sip->sip_to) {
 		char *sql;
 		time_t now = switch_timestamp(NULL);
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Expire registration '%s@%s' due to options failure\n", 
-						  sip->sip_to->a_url->url_user,
-						  sip->sip_to->a_url->url_host
-						  );
-
-		sql = switch_mprintf("update sip_registrations set expired=%ld where sip_user='%s' and sip_host='%s'", 
-								   (long)now,
-								   sip->sip_to->a_url->url_user,
-								   sip->sip_to->a_url->url_host
-								   );
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Expire registration '%s@%s' due to options failure\n",
+						  sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host);
+
+		sql = switch_mprintf("update sip_registrations set expired=%ld where sip_user='%s' and sip_host='%s'",
+							 (long) now, sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host);
 		sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 	}
 }
@@ -1576,14 +1544,15 @@
 
 static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status,
 									  char const *phrase,
-									  nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
+									  nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+									  tagi_t tags[])
 {
 	if (sip && session) {
 		switch_channel_t *channel = switch_core_session_get_channel(session);
 		const char *uuid;
 		switch_core_session_t *other_session;
 		private_object_t *tech_pvt = switch_core_session_get_private(session);
-		
+
 		switch_channel_clear_flag(channel, CF_REQ_MEDIA);
 
 		if (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
@@ -1597,14 +1566,14 @@
 			if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
 				const char *r_sdp = NULL;
 				switch_core_session_message_t msg = { 0 };
-			
-				if (sip->sip_payload && sip->sip_payload->pl_data && 
+
+				if (sip->sip_payload && sip->sip_payload->pl_data &&
 					sip->sip_content_type && sip->sip_content_type->c_subtype && switch_stristr("sdp", sip->sip_content_type->c_subtype)) {
 					r_sdp = sip->sip_payload->pl_data;
 				}
 
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Passing %d %s to other leg\n", status, phrase);
-				
+
 				msg.message_id = SWITCH_MESSAGE_INDICATE_RESPOND;
 				msg.from = __FILE__;
 				msg.numeric_arg = status;
@@ -1640,7 +1609,7 @@
 				astate = "confirmed";
 			}
 
-			if (!switch_channel_test_flag(channel, CF_EARLY_MEDIA) && !switch_channel_test_flag(channel, CF_ANSWERED) && 
+			if (!switch_channel_test_flag(channel, CF_EARLY_MEDIA) && !switch_channel_test_flag(channel, CF_ANSWERED) &&
 				!switch_channel_test_flag(channel, CF_RING_READY)) {
 				const char *from_user = "", *from_host = "", *to_user = "", *to_host = "", *contact_user = "", *contact_host = "";
 				const char *user_agent = "", *call_id = "";
@@ -1670,30 +1639,20 @@
 				}
 
 				if (profile->pflags & PFLAG_PRESENCE) {
-					sql = switch_mprintf(
-										 "insert into sip_dialogs values('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q')",
+					sql = switch_mprintf("insert into sip_dialogs values('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q')",
 										 call_id,
 										 switch_core_session_get_uuid(session),
-										 to_user,
-										 to_host,
-										 from_user,
-										 from_host,
-										 contact_user,
-										 contact_host,
-										 astate,
-										 "outbound",
-										 user_agent
-										 );
+										 to_user, to_host, from_user, from_host, contact_user, contact_host, astate, "outbound", user_agent);
 
 					switch_assert(sql);
-					
+
 					sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 				}
-			} else if (status == 200 && (profile->pflags & PFLAG_PRESENCE)) { 
+			} else if (status == 200 && (profile->pflags & PFLAG_PRESENCE)) {
 				char *sql = NULL;
 				sql = switch_mprintf("update sip_dialogs set state='%s' where uuid='%s';\n", astate, switch_core_session_get_uuid(session));
-				switch_assert(sql); 
-				sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE); 
+				switch_assert(sql);
+				sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 			}
 		}
 	}
@@ -1701,7 +1660,8 @@
 
 static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
 									 char const *phrase,
-									 nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
+									 nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+									 tagi_t tags[])
 {
 	const char *l_sdp = NULL, *r_sdp = NULL;
 	int offer_recv = 0, answer_recv = 0, offer_sent = 0, answer_sent = 0;
@@ -1754,8 +1714,8 @@
 		}
 	}
 
- state_process:
-	
+  state_process:
+
 	switch ((enum nua_callstate) ss_state) {
 	case nua_callstate_init:
 		break;
@@ -1837,18 +1797,18 @@
 					switch_set_flag(tech_pvt, TFLAG_SDP);
 					goto done;
 				} else if (switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MEDIA)) {
-                    switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "PROXY MEDIA");
-                    switch_set_flag_locked(tech_pvt, TFLAG_READY);
-                    if (switch_channel_get_state(channel) == CS_NEW) {
-                        switch_channel_set_state(channel, CS_INIT);
-                    }
+					switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "PROXY MEDIA");
+					switch_set_flag_locked(tech_pvt, TFLAG_READY);
+					if (switch_channel_get_state(channel) == CS_NEW) {
+						switch_channel_set_state(channel, CS_INIT);
+					}
 				} else if (switch_test_flag(tech_pvt, TFLAG_LATE_NEGOTIATION)) {
-                    switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "DELAYED NEGOTIATION");
-                    switch_set_flag_locked(tech_pvt, TFLAG_READY);
-                    if (switch_channel_get_state(channel) == CS_NEW) {
-                        switch_channel_set_state(channel, CS_INIT);
-                    }
-                } else {
+					switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "DELAYED NEGOTIATION");
+					switch_set_flag_locked(tech_pvt, TFLAG_READY);
+					if (switch_channel_get_state(channel) == CS_NEW) {
+						switch_channel_set_state(channel, CS_INIT);
+					}
+				} else {
 					sdp_parser_t *parser;
 					sdp_session_t *sdp;
 					uint8_t match = 0;
@@ -1861,7 +1821,7 @@
 							sdp_parser_free(parser);
 						}
 					}
-					
+
 					if (match) {
 						nua_handle_t *bnh;
 						sip_replaces_t *replaces;
@@ -1883,11 +1843,11 @@
 								while (switch_channel_get_state(channel) < CS_EXECUTE) {
 									switch_yield(10000);
 								}
-								
+
 								if ((b_private = nua_handle_magic(bnh))) {
 									const char *br_b = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE);
 									char *br_a = b_private->uuid;
-									
+
 									if (br_b) {
 										switch_ivr_uuid_bridge(br_a, br_b);
 										switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER");
@@ -1925,10 +1885,7 @@
 								SIPTAG_CONTACT_STR(tech_pvt->profile->url),
 								SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
 								SOATAG_REUSE_REJECTED(1),
-								SOATAG_ORDERED_USER(1),
-								SOATAG_AUDIO_AUX("cn telephone-event"),
-								NUTAG_INCLUDE_EXTRA_SDP(1),
-								TAG_END());
+								SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), TAG_END());
 					goto done;
 				}
 			}
@@ -1943,11 +1900,11 @@
 		break;
 	case nua_callstate_completed:
 		if (tech_pvt && r_sdp) {
-			sdp_parser_t *parser; 
+			sdp_parser_t *parser;
 			sdp_session_t *sdp;
 			uint8_t match = 0;
 
-			if (r_sdp) { 
+			if (r_sdp) {
 				if (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
 					if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))
 						&& (other_session = switch_core_session_locate(uuid))) {
@@ -1960,7 +1917,7 @@
 						if (switch_core_session_receive_message(other_session, &msg) != SWITCH_STATUS_SUCCESS) {
 							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Other leg is not available\n");
 							nua_respond(tech_pvt->nh, 403, "Hangup in progress", TAG_END());
-						}					
+						}
 						switch_core_session_rwunlock(other_session);
 					} else {
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Re-INVITE to a no-media channel that is not in a bridge.\n");
@@ -1998,10 +1955,7 @@
 							SIPTAG_CONTACT_STR(tech_pvt->reply_contact),
 							SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
 							SOATAG_REUSE_REJECTED(1),
-							SOATAG_ORDERED_USER(1),
-							SOATAG_AUDIO_AUX("cn telephone-event"),
-							NUTAG_INCLUDE_EXTRA_SDP(1),
-							TAG_END());
+							SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), TAG_END());
 			}
 		}
 		break;
@@ -2026,7 +1980,7 @@
 		if (channel) {
 			if (switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) {
 				switch_set_flag_locked(tech_pvt, TFLAG_ANS);
-                switch_set_flag(tech_pvt, TFLAG_SDP);
+				switch_set_flag(tech_pvt, TFLAG_SDP);
 				switch_channel_mark_answered(channel);
 				if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))
 					&& (other_session = switch_core_session_locate(uuid))) {
@@ -2114,12 +2068,12 @@
 				if (switch_test_flag(tech_pvt, TFLAG_NOHUP)) {
 					switch_clear_flag_locked(tech_pvt, TFLAG_NOHUP);
 				} else {
-                    int cause;
-                    if (tech_pvt->q850_cause) {
-                        cause = tech_pvt->q850_cause;
-                    } else {
-                        cause = sofia_glue_sip_cause_to_freeswitch(status);
-                    }
+					int cause;
+					if (tech_pvt->q850_cause) {
+						cause = tech_pvt->q850_cause;
+					} else {
+						cause = sofia_glue_sip_cause_to_freeswitch(status);
+					}
 					if (status) {
 						switch_snprintf(st, sizeof(st), "%d", status);
 						switch_channel_set_variable(channel, "sip_term_status", st);
@@ -2131,14 +2085,14 @@
 					switch_channel_hangup(channel, cause);
 				}
 			}
-			
+
 			if (tech_pvt->sofia_private) {
 				sofia_private = tech_pvt->sofia_private;
 				tech_pvt->sofia_private = NULL;
 				sofia_private->destroy_me = 1;
 			}
 
-			tech_pvt->nh = NULL;		
+			tech_pvt->nh = NULL;
 
 
 		} else if (sofia_private) {
@@ -2183,11 +2137,11 @@
 
 	from = sip->sip_from;
 	to = sip->sip_to;
-	
+
 	home = su_home_new(sizeof(*home));
 	switch_assert(home != NULL);
 
-	if (sip->sip_referred_by) {		
+	if (sip->sip_referred_by) {
 		full_ref_by = sip_header_as_string(home, (void *) sip->sip_referred_by);
 	}
 
@@ -2206,13 +2160,12 @@
 			sip_replaces_t *replaces;
 			nua_handle_t *bnh;
 			char *rep;
-			
+
 			if (switch_channel_test_flag(channel_a, CF_PROXY_MODE)) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Attended Transfer BYPASS MEDIA CALLS!\n");
 				switch_channel_set_variable(channel_a, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER_ERROR");
 				nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
-						   NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden"), SIPTAG_EVENT_STR(etmp),
-						   TAG_END());
+						   NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden"), SIPTAG_EVENT_STR(etmp), TAG_END());
 				goto done;
 			}
 
@@ -2235,7 +2188,7 @@
 					sofia_private_t *b_private = NULL;
 					private_object_t *b_tech_pvt = NULL;
 					switch_core_session_t *b_session = NULL;
-					
+
 
 					switch_channel_set_variable(channel_a, SOFIA_REPLACES_HEADER, rep);
 					if ((b_private = nua_handle_magic(bnh))) {
@@ -2247,12 +2200,13 @@
 
 						br_a = switch_channel_get_variable(channel_a, SWITCH_SIGNAL_BOND_VARIABLE);
 						br_b = switch_channel_get_variable(channel_b, SWITCH_SIGNAL_BOND_VARIABLE);
-						
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Attended Transfer [%s][%s]\n", switch_str_nil(br_a), switch_str_nil(br_b));
+
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Attended Transfer [%s][%s]\n", switch_str_nil(br_a),
+										  switch_str_nil(br_b));
 
 						if (br_a && br_b) {
 							switch_core_session_t *new_b_session = NULL, *a_session = NULL;
-								
+
 							switch_ivr_uuid_bridge(br_b, br_a);
 							switch_channel_set_variable(channel_b, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER");
 							nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
@@ -2277,12 +2231,10 @@
 								b_tech_pvt->xferto = switch_core_session_strdup(b_session, switch_core_session_get_uuid(session));
 								switch_set_flag_locked(tech_pvt, TFLAG_BYE);
 								nua_notify(tech_pvt->nh,
-											NUTAG_NEWSUB(1),
-											SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
-											NUTAG_SUBSTATE(nua_substate_terminated),
-											SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"),
-											SIPTAG_EVENT_STR(etmp),
-											TAG_END());
+										   NUTAG_NEWSUB(1),
+										   SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
+										   NUTAG_SUBSTATE(nua_substate_terminated),
+										   SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"), SIPTAG_EVENT_STR(etmp), TAG_END());
 							} else {
 								switch_core_session_t *t_session;
 								switch_channel_t *hup_channel;
@@ -2311,15 +2263,13 @@
 									if (!switch_strlen_zero(full_ref_to)) {
 										switch_channel_set_variable(t_channel, SOFIA_REFER_TO_VARIABLE, full_ref_to);
 									}
-									
+
 									switch_ivr_session_transfer(t_session, ext, NULL, NULL);
 									nua_notify(tech_pvt->nh,
-												NUTAG_NEWSUB(1),
-												SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
-												NUTAG_SUBSTATE(nua_substate_terminated),
-												SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"),
-												SIPTAG_EVENT_STR(etmp),
-												TAG_END());
+											   NUTAG_NEWSUB(1),
+											   SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
+											   NUTAG_SUBSTATE(nua_substate_terminated),
+											   SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"), SIPTAG_EVENT_STR(etmp), TAG_END());
 									switch_core_session_rwunlock(t_session);
 									switch_channel_hangup(hup_channel, SWITCH_CAUSE_ATTENDED_TRANSFER);
 								} else {
@@ -2356,13 +2306,9 @@
 								port = "5060";
 							}
 							channel = switch_core_session_get_channel(a_session);
-							
-							exten = switch_mprintf("sofia/%s/%s@%s:%s",
-												   profile->name,
-												   refer_to->r_url->url_user,
-												   refer_to->r_url->url_host,
-												   port);
-							
+
+							exten = switch_mprintf("sofia/%s/%s@%s:%s", profile->name, refer_to->r_url->url_user, refer_to->r_url->url_host, port);
+
 							switch_channel_set_variable(channel, SOFIA_REPLACES_HEADER, rep);
 							if (!switch_strlen_zero(full_ref_by)) {
 								switch_channel_set_variable(channel, SOFIA_SIP_HEADER_PREFIX "Referred-By", full_ref_by);
@@ -2370,20 +2316,19 @@
 							if (!switch_strlen_zero(full_ref_to)) {
 								switch_channel_set_variable(channel, SOFIA_REFER_TO_VARIABLE, full_ref_to);
 							}
-							status = switch_ivr_originate(a_session,
-														  &tsession, &cause, exten, timeout, &noop_state_handler, NULL, NULL, NULL, SOF_NONE);
+							status = switch_ivr_originate(a_session, &tsession, &cause, exten, timeout, &noop_state_handler, NULL, NULL, NULL, SOF_NONE);
 
 							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel! [%s]\n", exten);
 							nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("messsage/sipfrag"),
 									   NUTAG_SUBSTATE(nua_substate_terminated),
 									   SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden"), SIPTAG_EVENT_STR(etmp), TAG_END());
-							
+
 							switch_core_session_rwunlock(a_session);
 
 							if (status != SWITCH_STATUS_SUCCESS) {
 								goto done;
 							}
-							
+
 							tuuid_str = switch_core_session_get_uuid(tsession);
 							switch_ivr_uuid_bridge(br_a, tuuid_str);
 							switch_channel_set_variable(channel_a, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER");
@@ -2421,7 +2366,7 @@
 
 		if ((br = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
 			switch_core_session_t *b_session;
-			
+
 			if ((b_session = switch_core_session_locate(br))) {
 				switch_channel_t *b_channel = switch_core_session_get_channel(b_session);
 				switch_channel_set_variable(channel, "transfer_fallback_extension", from->a_user);
@@ -2440,17 +2385,13 @@
 
 			switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "BLIND_TRANSFER");
 			nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
-			   NUTAG_SUBSTATE(nua_substate_terminated),
-			   SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"),
-			   SIPTAG_EVENT_STR(etmp),
-			   TAG_END());
-			 
+					   NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"), SIPTAG_EVENT_STR(etmp), TAG_END());
+
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Blind Transfer 1 Legged calls\n");
 			switch_channel_set_variable(channel_a, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER_ERROR");
 			nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
-					   NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden"), SIPTAG_EVENT_STR(etmp),
-					   TAG_END());
+					   NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden"), SIPTAG_EVENT_STR(etmp), TAG_END());
 		}
 	}
 
@@ -2475,7 +2416,7 @@
 	const char *rec_header;
 	const char *clientcode_header;
 	switch_dtmf_t dtmf = { 0, switch_core_default_dtmf_duration(0) };
-	
+
 	if (session) {
 		/* Get the channel */
 		switch_channel_t *channel = switch_core_session_get_channel(session);
@@ -2483,7 +2424,7 @@
 		/* Barf if we didn't get our private */
 		assert(switch_core_session_get_private(session));
 
-		if (sip && sip->sip_content_type && sip->sip_content_type->c_type && sip->sip_content_type->c_subtype && 
+		if (sip && sip->sip_content_type && sip->sip_content_type->c_type && sip->sip_content_type->c_subtype &&
 			sip->sip_payload && sip->sip_payload->pl_data) {
 			if (!strncasecmp(sip->sip_content_type->c_type, "application", 11) && !strcasecmp(sip->sip_content_type->c_subtype, "dtmf-relay")) {
 				/* Try and find signal information in the payload */
@@ -2501,7 +2442,7 @@
 					signal_ptr += 9;
 					if ((tmp = atoi(signal_ptr)) <= 0) {
 						tmp = switch_core_default_dtmf_duration(0);
-					} 
+					}
 					dtmf.duration = tmp * 8;
 				}
 			} else if (!strncasecmp(sip->sip_content_type->c_type, "application", 11) && !strcasecmp(sip->sip_content_type->c_subtype, "dtmf")) {
@@ -2509,7 +2450,7 @@
 			} else {
 				goto fail;
 			}
-		
+
 			if (dtmf.digit) {
 				/* queue it up */
 				switch_channel_queue_dtmf(channel, &dtmf);
@@ -2519,7 +2460,7 @@
 
 				/* Send 200 OK response */
 				nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
-	
+
 				return;
 			} else {
 				goto fail;
@@ -2571,7 +2512,7 @@
 	}
 	return;
 
- fail:
+  fail:
 	nua_respond(nh, 488, "Unsupported Request", NUTAG_WITH_THIS(nua), TAG_END());
 }
 
@@ -2664,7 +2605,7 @@
 		nua_respond(nh, SIP_503_SERVICE_UNAVAILABLE, TAG_END());
 		return;
 	}
-	
+
 	get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) my_addrinfo->ai_addr)->sin_addr);
 	network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port);
 
@@ -2672,7 +2613,7 @@
 		if (sip && sip->sip_via) {
 			const char *port = sip->sip_via->v_port;
 			const char *host = sip->sip_via->v_host;
-			
+
 			if (host && sip->sip_via->v_received) {
 				is_nat = "via received";
 			} else if (host && strcmp(network_ip, host)) {
@@ -2694,13 +2635,13 @@
 		}
 
 		if (!switch_strlen_zero(contact_host)) {
-			for (x = 0 ; x < profile->nat_acl_count; x++) {
+			for (x = 0; x < profile->nat_acl_count; x++) {
 				last_acl = profile->nat_acl[x];
 				if (!(ok = switch_check_network_list_ip(contact_host, last_acl))) {
 					break;
 				}
 			}
-			
+
 			if (ok) {
 				is_nat = last_acl;
 			}
@@ -2712,7 +2653,7 @@
 		int ok = 1;
 		char *last_acl = NULL;
 
-		for (x = 0 ; x < profile->acl_count; x++) {
+		for (x = 0; x < profile->acl_count; x++) {
 			last_acl = profile->acl[x];
 			if (!(ok = switch_check_network_list_ip(network_ip, last_acl))) {
 				break;
@@ -2721,7 +2662,7 @@
 
 		if (ok) {
 			if ((profile->pflags & PFLAG_AUTH_CALLS)) {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "IP %s Approved by acl %s. Access Granted.\n", 
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "IP %s Approved by acl %s. Access Granted.\n",
 								  network_ip, switch_str_nil(last_acl));
 				is_auth = 1;
 			}
@@ -2731,13 +2672,13 @@
 				nua_respond(nh, SIP_403_FORBIDDEN, TAG_END());
 				return;
 			} else {
-				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "IP %s Rejected by acl %s. Falling back to Digest auth.\n", 
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "IP %s Rejected by acl %s. Falling back to Digest auth.\n",
 								  network_ip, switch_str_nil(last_acl));
 			}
 		}
 	}
-	
-	if (!is_auth && 
+
+	if (!is_auth &&
 		((profile->pflags & PFLAG_AUTH_CALLS) || (!(profile->pflags & PFLAG_BLIND_AUTH) && (sip->sip_proxy_authorization || sip->sip_authorization)))) {
 		if (!strcmp(network_ip, profile->sipip) && network_port == profile->sip_port) {
 			calling_myself++;
@@ -2780,10 +2721,8 @@
 
 	if (sip->sip_contact && sip->sip_contact->m_url) {
 		char tmp[35] = "";
-		tech_pvt->record_route = switch_core_session_sprintf(session, "sip:%s@%s:%d", 
-															 sip->sip_contact->m_url->url_user, 
-															 tech_pvt->remote_ip,
-															 tech_pvt->remote_port);
+		tech_pvt->record_route = switch_core_session_sprintf(session, "sip:%s@%s:%d",
+															 sip->sip_contact->m_url->url_user, tech_pvt->remote_ip, tech_pvt->remote_port);
 		switch_channel_set_variable(channel, "sip_received_ip", tech_pvt->remote_ip);
 		snprintf(tmp, sizeof(tmp), "%d", tech_pvt->remote_port);
 		switch_channel_set_variable(channel, "sip_received_port", tmp);
@@ -2793,7 +2732,7 @@
 		tech_pvt->key = switch_core_session_strdup(session, key);
 	}
 
-	
+
 	if (is_auth) {
 		switch_channel_set_variable(channel, "sip_authorized", "true");
 	}
@@ -2804,8 +2743,8 @@
 
 	if (v_event) {
 		switch_event_header_t *hp;
-		
-		for(hp = v_event->headers; hp; hp = hp->next) {
+
+		for (hp = v_event->headers; hp; hp = hp->next) {
 			switch_channel_set_variable(channel, hp->name, hp->value);
 		}
 		switch_event_destroy(&v_event);
@@ -2901,7 +2840,7 @@
 
 			host = switch_channel_get_variable(channel, "sip_to_host");
 			user = switch_channel_get_variable(channel, "sip_to_user");
-		
+
 			switch_channel_set_variable(channel, "sip_to_comment", sip->sip_to->a_comment);
 
 			if (sip->sip_to->a_params) {
@@ -2914,8 +2853,7 @@
 				port = sofia_glue_transport_has_tls(transport) ? profile->tls_sip_port : profile->sip_port;
 			}
 
-			tech_pvt->to_uri = switch_core_session_sprintf(session, "sip:%s@%s:%d;transport=%s",
-						 user, host, port, sofia_glue_transport2str(transport));
+			tech_pvt->to_uri = switch_core_session_sprintf(session, "sip:%s@%s:%d;transport=%s", user, host, port, sofia_glue_transport2str(transport));
 
 			if (profile->ndlb & PFLAG_NDLB_TO_IN_200_CONTACT) {
 				if (strchr(tech_pvt->to_uri, '>')) {
@@ -3001,8 +2939,8 @@
 	if (sip->sip_subject && sip->sip_subject->g_string) {
 		switch_channel_set_variable(channel, "sip_subject", sip->sip_subject->g_string);
 	}
-	
-	if (sip->sip_user_agent && !switch_strlen_zero(sip->sip_user_agent->g_string)){
+
+	if (sip->sip_user_agent && !switch_strlen_zero(sip->sip_user_agent->g_string)) {
 		switch_channel_set_variable(channel, "sip_user_agent", sip->sip_user_agent->g_string);
 	}
 
@@ -3074,10 +3012,7 @@
 	tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
 														 from_user,
 														 dialplan,
-														 displayname,
-														 from_user,
-														 network_ip,
-														 NULL, NULL, NULL, MODNAME, context, destination_number);
+														 displayname, from_user, network_ip, NULL, NULL, NULL, MODNAME, context, destination_number);
 
 	if (tech_pvt->caller_profile) {
 
@@ -3095,8 +3030,8 @@
 					switch_clear_flag(tech_pvt->caller_profile, SWITCH_CPF_HIDE_NAME);
 					switch_clear_flag(tech_pvt->caller_profile, SWITCH_CPF_HIDE_NUMBER);
 				}
-			} 
-			
+			}
+
 			if (rpid->rpid_screen && !strcasecmp(rpid->rpid_screen, "no")) {
 				switch_clear_flag(tech_pvt->caller_profile, SWITCH_CPF_SCREEN);
 			}
@@ -3133,7 +3068,7 @@
 	}
 	memset(sofia_private, 0, sizeof(*sofia_private));
 	tech_pvt->sofia_private = sofia_private;
-	
+
 	if ((profile->pflags & PFLAG_PRESENCE)) {
 		sofia_presence_set_chat_hash(tech_pvt, sip);
 	}
@@ -3183,21 +3118,11 @@
 
 		if (profile->pflags & PFLAG_PRESENCE) {
 
-			sql = switch_mprintf(
-								 "insert into sip_dialogs values('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q')",
+			sql = switch_mprintf("insert into sip_dialogs values('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q')",
 								 call_id,
 								 tech_pvt->sofia_private->uuid,
-								 to_user,
-								 to_host,
-								 dialog_from_user,
-								 dialog_from_host,
-								 contact_user,
-								 contact_host,
-								 "confirmed",
-								 "inbound",
-								 user_agent
-								 );
-			
+								 to_user, to_host, dialog_from_user, dialog_from_host, contact_user, contact_host, "confirmed", "inbound", user_agent);
+
 			switch_assert(sql);
 			sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 		}
@@ -3207,7 +3132,7 @@
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Setting NAT mode based on %s\n", is_nat);
 			switch_channel_set_variable(channel, "sip_nat_detected", "true");
 		}
-		
+
 		return;
 	}
 
@@ -3218,8 +3143,7 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "LUKE'S VOICE: Artoo, see what you can do with it. Hang on back there....\n"
 						  "Green laserfire moves past the beeping little robot as his head turns.  "
 						  "After a few beeps and a twist of his mechanical arm,\n"
-						  "Artoo reduces the max sessions to %d thus, saving the switch from certian doom.\n", 
-						  sess_count - 10);
+						  "Artoo reduces the max sessions to %d thus, saving the switch from certian doom.\n", sess_count - 10);
 
 		switch_mutex_unlock(profile->flag_mutex);
 	}
@@ -3235,12 +3159,10 @@
 }
 
 void sofia_handle_sip_i_options(int status,
-						  char const *phrase,
-						  nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
+								char const *phrase,
+								nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
 {
-	nua_respond(nh, SIP_200_OK,
-				NUTAG_WITH_THIS(nua),
-				TAG_END());
+	nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
 }
 
 static void sofia_info_send_sipfrag(switch_core_session_t *aleg, switch_core_session_t *bleg)
@@ -3251,7 +3173,7 @@
 	if (aleg && bleg && switch_core_session_compare(aleg, bleg)) {
 		a_tech_pvt = (private_object_t *) switch_core_session_get_private(aleg);
 		b_tech_pvt = (private_object_t *) switch_core_session_get_private(bleg);
-		
+
 		if (b_tech_pvt && a_tech_pvt && a_tech_pvt->caller_profile) {
 			switch_caller_profile_t *acp = a_tech_pvt->caller_profile;
 
@@ -3294,27 +3216,27 @@
 	char var1[] = "sip_";
 	char *cp, *sh, *sh_end, *sh_save;
 
-	/* Build the static part of the sip_header_name variable from	*/
-	/* the header_type. If the header type is "referred_by" then	*/
-	/* sip_header_name = "sip_referred_by_".			*/
+	/* Build the static part of the sip_header_name variable from   */
+	/* the header_type. If the header type is "referred_by" then    */
+	/* sip_header_name = "sip_referred_by_".            */
 	sh = sip_header_name;
 	sh_end = sh + sizeof(sip_header_name) - 1;
-	for (cp=var1; *cp; cp++, sh++) {
+	for (cp = var1; *cp; cp++, sh++) {
 		*sh = *cp;
 	}
 	*sh = '\0';
 
-	/* Copy the header_type to the sip_header_name. Before copying 	*/
+	/* Copy the header_type to the sip_header_name. Before copying  */
 	/* each character, check that we aren't going to overflow the   */
-	/* the sip_header_name buffer.  We have to account for the 	*/
-	/* trailing underscore and NULL that will be added to the end.	*/
-	for (cp=header_type; (*cp && (sh < (sh_end-1))); cp++, sh++) {
+	/* the sip_header_name buffer.  We have to account for the  */
+	/* trailing underscore and NULL that will be added to the end.  */
+	for (cp = header_type; (*cp && (sh < (sh_end - 1))); cp++, sh++) {
 		*sh = *cp;
 	}
 	*sh++ = '_';
 	*sh = '\0';
 
-	/* sh now points to the NULL at the end of the partially built	*/
+	/* sh now points to the NULL at the end of the partially built  */
 	/* sip_header_name variable.  This is also the start of the     */
 	/* variable part of the sip_header_name built from the lvalue   */
 	/* of the parms data.                                           */
@@ -3322,21 +3244,21 @@
 
 	while (params && params[0]) {
 
-		/* Copy the params data to the sip_header_name variable until	*/
-		/* the end of the params string is reached, an '=' is detected	*/
-		/* or until the sip_header_name buffer has been exhausted.	*/
-		for (cp=(char *)(*params); ((*cp != '=') && *cp && (sh < sh_end)); cp++, sh++) {
+		/* Copy the params data to the sip_header_name variable until   */
+		/* the end of the params string is reached, an '=' is detected  */
+		/* or until the sip_header_name buffer has been exhausted.  */
+		for (cp = (char *) (*params); ((*cp != '=') && *cp && (sh < sh_end)); cp++, sh++) {
 			*sh = *cp;
 		}
 
-		/* cp now points to either the end of the parms data or the	*/
-		/* equal (=) sign spearating the lvalue and rvalue.		*/
+		/* cp now points to either the end of the parms data or the */
+		/* equal (=) sign spearating the lvalue and rvalue.     */
 		if (*cp == '=')
-			cp++;	
+			cp++;
 		*sh = '\0';
 		switch_channel_set_variable(channel, sip_header_name, cp);
 
-		/* Bump pointer to next param in the list.  Also reset the	*/
+		/* Bump pointer to next param in the list.  Also reset the  */
 		/* sip_header_name pointer to the beginning of the dynamic area */
 		params++;
 		sh = sh_save;

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	Tue May 27 00:54:52 2008
@@ -47,12 +47,13 @@
 	const char *pass_fmtp = switch_channel_get_variable(tech_pvt->channel, "sip_video_fmtp");
 	const char *ov_fmtp = switch_channel_get_variable(tech_pvt->channel, "sip_force_video_fmtp");
 
-	if (sofia_test_pflag(tech_pvt->profile, PFLAG_SUPRESS_CNG) || 
+	if (sofia_test_pflag(tech_pvt->profile, PFLAG_SUPRESS_CNG) ||
 		((val = switch_channel_get_variable(tech_pvt->channel, "supress_cng")) && switch_true(val))) {
 		use_cng = 0;
 	}
 
-	if (!force && !ip && !sr && (switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MODE) || switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MEDIA))) {
+	if (!force && !ip && !sr
+		&& (switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MODE) || switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MEDIA))) {
 		return;
 	}
 
@@ -76,21 +77,20 @@
 	}
 
 	if (!tech_pvt->session_id) {
-		tech_pvt->session_id = tech_pvt->owner_id ;
+		tech_pvt->session_id = tech_pvt->owner_id;
 	}
 
 	tech_pvt->session_id++;
-	
+
 	switch_snprintf(buf, sizeof(buf),
 					"v=0\n"
 					"o=FreeSWITCH %010u %010u IN IP4 %s\n"
-					"s=FreeSWITCH\n" 
-					"c=IN IP4 %s\n" "t=0 0\n" 
-					"a=%s\n" 
+					"s=FreeSWITCH\n"
+					"c=IN IP4 %s\n" "t=0 0\n"
+					"a=%s\n"
 					"m=audio %d RTP/%sAVP", tech_pvt->owner_id, tech_pvt->session_id, ip, ip, sr, port,
-					(!switch_strlen_zero(tech_pvt->local_crypto_key) && switch_test_flag(tech_pvt, TFLAG_SECURE)) ? "S" : ""
-					);
-	
+					(!switch_strlen_zero(tech_pvt->local_crypto_key) && switch_test_flag(tech_pvt, TFLAG_SECURE)) ? "S" : "");
+
 
 	if (tech_pvt->rm_encoding) {
 		switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %d", tech_pvt->pt);
@@ -103,7 +103,7 @@
 			if (imp->codec_type != SWITCH_CODEC_TYPE_AUDIO) {
 				continue;
 			}
-			
+
 			if (imp->ianacode < 128) {
 				if (already_did[imp->ianacode]) {
 					continue;
@@ -122,7 +122,7 @@
 	if (tech_pvt->dtmf_type == DTMF_2833 && tech_pvt->te > 95) {
 		switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %d", tech_pvt->te);
 	}
-	
+
 	if (tech_pvt->cng_pt && use_cng) {
 		switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %d", tech_pvt->cng_pt);
 	}
@@ -154,12 +154,12 @@
 				if (already_did[imp->ianacode]) {
 					continue;
 				}
-				
+
 				already_did[imp->ianacode] = 1;
 			}
-			
+
 			rate = imp->samples_per_second;
-			
+
 			switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=rtpmap:%d %s/%d\n", imp->ianacode, imp->iananame, rate);
 			if (imp->fmtp) {
 				switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=fmtp:%d %s\n", imp->ianacode, imp->fmtp);
@@ -188,7 +188,7 @@
 		//switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=encryption:optional\n");
 #if 0
 		switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "m=audio %d RTP/AVP", port);
-		
+
 		if (tech_pvt->rm_encoding) {
 			switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %d", tech_pvt->pt);
 		} else if (tech_pvt->num_codecs) {
@@ -196,16 +196,16 @@
 			int already_did[128] = { 0 };
 			for (i = 0; i < tech_pvt->num_codecs; i++) {
 				const switch_codec_implementation_t *imp = tech_pvt->codecs[i];
-				
+
 				if (imp->codec_type != SWITCH_CODEC_TYPE_AUDIO) {
 					continue;
 				}
-				
+
 				if (imp->ianacode < 128) {
 					if (already_did[imp->ianacode]) {
 						continue;
 					}
-					
+
 					already_did[imp->ianacode] = 1;
 				}
 
@@ -218,14 +218,14 @@
 	}
 
 	if (switch_test_flag(tech_pvt, TFLAG_VIDEO)) {
-		if (!switch_channel_test_flag(tech_pvt->channel, CF_ANSWERED) && !switch_channel_test_flag(tech_pvt->channel, CF_EARLY_MEDIA) && 
+		if (!switch_channel_test_flag(tech_pvt->channel, CF_ANSWERED) && !switch_channel_test_flag(tech_pvt->channel, CF_EARLY_MEDIA) &&
 			!tech_pvt->local_sdp_video_port) {
 			sofia_glue_tech_choose_video_port(tech_pvt, 0);
 		}
 
 		if ((v_port = tech_pvt->adv_sdp_video_port)) {
 			switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "m=video %d RTP/AVP", v_port);
-			
+
 			/*****************************/
 			if (tech_pvt->video_rm_encoding) {
 				sofia_glue_tech_set_video_codec(tech_pvt, 0);
@@ -235,18 +235,18 @@
 				int already_did[128] = { 0 };
 				for (i = 0; i < tech_pvt->num_codecs; i++) {
 					const switch_codec_implementation_t *imp = tech_pvt->codecs[i];
-				
+
 					if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO) {
 						continue;
 					}
-				
+
 					if (imp->ianacode < 128) {
 						if (already_did[imp->ianacode]) {
 							continue;
 						}
 						already_did[imp->ianacode] = 1;
 					}
-					
+
 					switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %d", imp->ianacode);
 					if (!ptime) {
 						ptime = imp->microseconds_per_frame / 1000;
@@ -259,16 +259,17 @@
 			if (tech_pvt->video_rm_encoding) {
 				const char *of;
 				rate = tech_pvt->video_rm_rate;
-				switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=rtpmap:%d %s/%ld\n", tech_pvt->video_pt, tech_pvt->video_rm_encoding, tech_pvt->video_rm_rate);
-				
+				switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=rtpmap:%d %s/%ld\n", tech_pvt->video_pt, tech_pvt->video_rm_encoding,
+								tech_pvt->video_rm_rate);
+
 				pass_fmtp = NULL;
 
 				if (switch_channel_get_variable(tech_pvt->channel, SWITCH_SIGNAL_BOND_VARIABLE)) {
 					if ((of = switch_channel_get_variable_partner(tech_pvt->channel, "sip_video_fmtp"))) {
 						pass_fmtp = of;
 					}
-				} 
-				
+				}
+
 				if (ov_fmtp) {
 					pass_fmtp = ov_fmtp;
 				}
@@ -283,7 +284,7 @@
 
 				for (i = 0; i < tech_pvt->num_codecs; i++) {
 					const switch_codec_implementation_t *imp = tech_pvt->codecs[i];
-				
+
 					if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO) {
 						continue;
 					}
@@ -294,12 +295,13 @@
 						}
 						already_did[imp->ianacode] = 1;
 					}
-					
+
 					if (!rate) {
 						rate = imp->samples_per_second;
 					}
 
-					switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=rtpmap:%d %s/%d\n", imp->ianacode, imp->iananame, imp->samples_per_second);
+					switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=rtpmap:%d %s/%d\n", imp->ianacode, imp->iananame,
+									imp->samples_per_second);
 					if (imp->fmtp) {
 						switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=fmtp:%d %s\n", imp->ianacode, imp->fmtp);
 					} else {
@@ -338,7 +340,7 @@
 				codec_string = tech_pvt->profile->codec_string;
 			}
 		}
-		
+
 		if ((ocodec = switch_channel_get_variable(tech_pvt->channel, SWITCH_ORIGINATOR_CODEC_VARIABLE))) {
 			if (!codec_string || (tech_pvt->profile->pflags & PFLAG_DISABLE_TRANSCODING)) {
 				codec_string = ocodec;
@@ -349,7 +351,7 @@
 			}
 		}
 	}
-	
+
 	if (codec_string) {
 		char *tmp_codec_string;
 		if ((tmp_codec_string = switch_core_session_strdup(tech_pvt->session, codec_string))) {
@@ -358,14 +360,13 @@
 				switch_loadable_module_get_codecs_sorted(tech_pvt->codecs, SWITCH_MAX_CODECS, tech_pvt->codec_order, tech_pvt->codec_order_last);
 		}
 	} else {
-		tech_pvt->num_codecs =
-			switch_loadable_module_get_codecs(tech_pvt->codecs, sizeof(tech_pvt->codecs) / sizeof(tech_pvt->codecs[0]));
+		tech_pvt->num_codecs = switch_loadable_module_get_codecs(tech_pvt->codecs, sizeof(tech_pvt->codecs) / sizeof(tech_pvt->codecs[0]));
 	}
- 
+
 
 }
 
-void sofia_glue_check_video_codecs(private_object_t *tech_pvt) 
+void sofia_glue_check_video_codecs(private_object_t *tech_pvt)
 {
 	if (tech_pvt->num_codecs && !switch_test_flag(tech_pvt, TFLAG_VIDEO)) {
 		int i;
@@ -481,7 +482,7 @@
 	char tmp[50];
 
 	if (!force) {
-		if (switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MODE) || 
+		if (switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MODE) ||
 			switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MEDIA) || tech_pvt->adv_sdp_audio_port) {
 			return SWITCH_STATUS_SUCCESS;
 		}
@@ -521,9 +522,10 @@
 	char *ip = tech_pvt->profile->rtpip;
 	switch_port_t sdp_port;
 	char tmp[50];
-	
+
 	if (!force) {
-		if (switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MODE) || switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MEDIA) || tech_pvt->local_sdp_video_port) {
+		if (switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MODE) || switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MEDIA)
+			|| tech_pvt->local_sdp_video_port) {
 			return SWITCH_STATUS_SUCCESS;
 		}
 	}
@@ -537,7 +539,7 @@
 		return SWITCH_STATUS_FALSE;
 	}
 	sdp_port = tech_pvt->local_sdp_video_port;
-	
+
 
 	if (tech_pvt->profile->extrtpip) {
 		if (sofia_glue_ext_address_lookup(&ip, &sdp_port, tech_pvt->profile->extrtpip, switch_core_session_get_pool(tech_pvt->session)) !=
@@ -559,26 +561,23 @@
 {
 	if (!strncasecmp(str, "udp", 3)) {
 		return SOFIA_TRANSPORT_UDP;
-	}
-	else if (!strncasecmp(str, "tcp", 3)) {
+	} else if (!strncasecmp(str, "tcp", 3)) {
 		return SOFIA_TRANSPORT_TCP;
-	}
-	else if (!strncasecmp(str, "sctp", 4)) {
+	} else if (!strncasecmp(str, "sctp", 4)) {
 		return SOFIA_TRANSPORT_SCTP;
-	}
-	else if (!strncasecmp(str, "tls", 3)) {
+	} else if (!strncasecmp(str, "tls", 3)) {
 		return SOFIA_TRANSPORT_TCP_TLS;
 	}
 
 	return SOFIA_TRANSPORT_UNKNOWN;
 }
 
-char * sofia_glue_find_parameter(const char *str, const char *param)
+char *sofia_glue_find_parameter(const char *str, const char *param)
 {
 	char *ptr = NULL;
 
-	ptr = (char *)str;
-	while(ptr) {
+	ptr = (char *) str;
+	while (ptr) {
 		if (!strncasecmp(ptr, param, strlen(param)))
 			return ptr;
 
@@ -625,14 +624,11 @@
 
 		if (!strncasecmp(ptr, "udp", 3)) {
 			return SOFIA_TRANSPORT_UDP;
-		}
-		else if (!strncasecmp(ptr, "tcp", 3)) {
+		} else if (!strncasecmp(ptr, "tcp", 3)) {
 			return SOFIA_TRANSPORT_TCP;
-		}
-		else if (!strncasecmp(ptr, "tls", 3)) {
+		} else if (!strncasecmp(ptr, "tls", 3)) {
 			return SOFIA_TRANSPORT_TCP_TLS;
-		}
-		else if (!strncasecmp(ptr, "sctp", 4)) {
+		} else if (!strncasecmp(ptr, "sctp", 4)) {
 			return SOFIA_TRANSPORT_SCTP;
 		}
 	}
@@ -642,7 +638,7 @@
 
 const char *sofia_glue_transport2str(const sofia_transport_t tp)
 {
-	switch(tp) {
+	switch (tp) {
 	case SOFIA_TRANSPORT_TCP:
 		return "tcp";
 
@@ -659,7 +655,7 @@
 
 int sofia_glue_transport_has_tls(const sofia_transport_t tp)
 {
-	switch(tp) {
+	switch (tp) {
 	case SOFIA_TRANSPORT_TCP_TLS:
 		return 1;
 
@@ -668,7 +664,8 @@
 	}
 }
 
-char *sofia_overcome_sip_uri_weakness(switch_core_session_t *session, const char *uri, const sofia_transport_t transport, switch_bool_t uri_only, const char *params)
+char *sofia_overcome_sip_uri_weakness(switch_core_session_t *session, const char *uri, const sofia_transport_t transport, switch_bool_t uri_only,
+									  const char *params)
 {
 	char *stripped = switch_core_session_strdup(session, uri);
 	char *new_uri = NULL;
@@ -679,7 +676,7 @@
 		if (switch_stristr("port=", stripped)) {
 			new_uri = switch_core_session_sprintf(session, "%s%s%s", uri_only ? "" : "<", stripped, uri_only ? "" : ">");
 		} else {
-			
+
 			if (strchr(stripped, ';')) {
 				if (params) {
 					new_uri = switch_core_session_sprintf(session, "%s%s&transport=%s;%s%s",
@@ -690,10 +687,10 @@
 				}
 			} else {
 				if (params) {
-					new_uri = switch_core_session_sprintf(session, "%s%s;transport=%s;%s%s", 
+					new_uri = switch_core_session_sprintf(session, "%s%s;transport=%s;%s%s",
 														  uri_only ? "" : "<", stripped, sofia_glue_transport2str(transport), params, uri_only ? "" : ">");
 				} else {
-					new_uri = switch_core_session_sprintf(session, "%s%s;transport=%s%s", 
+					new_uri = switch_core_session_sprintf(session, "%s%s;transport=%s%s",
 														  uri_only ? "" : "<", stripped, sofia_glue_transport2str(transport), uri_only ? "" : ">");
 				}
 			}
@@ -705,11 +702,11 @@
 			new_uri = stripped;
 		}
 	}
-	
+
 	return new_uri;
 }
 
-switch_status_t sofia_glue_tech_proxy_remote_addr(private_object_t *tech_pvt) 
+switch_status_t sofia_glue_tech_proxy_remote_addr(private_object_t *tech_pvt)
 {
 	const char *err;
 	char rip[128] = "";
@@ -722,39 +719,39 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
-	if ((p = (char *)switch_stristr("c=IN IP4 ", tech_pvt->remote_sdp_str))) {
+	if ((p = (char *) switch_stristr("c=IN IP4 ", tech_pvt->remote_sdp_str))) {
 		ip_ptr = p + 9;
 	}
 
-	if ((p = (char *)switch_stristr("m=audio ", tech_pvt->remote_sdp_str))) {
+	if ((p = (char *) switch_stristr("m=audio ", tech_pvt->remote_sdp_str))) {
 		port_ptr = p + 8;
 	}
 
-	if ((p = (char *)switch_stristr("m=video ", tech_pvt->remote_sdp_str))) {
+	if ((p = (char *) switch_stristr("m=video ", tech_pvt->remote_sdp_str))) {
 		vid_port_ptr = p + 8;
 	}
-	
+
 	if (!(ip_ptr && port_ptr)) {
 		return SWITCH_STATUS_FALSE;
 	}
 
 	p = ip_ptr;
 	x = 0;
-	while(x < sizeof(rip) && p && *p && ((*p >= '0' && *p <= '9') || *p == '.')) {
+	while (x < sizeof(rip) && p && *p && ((*p >= '0' && *p <= '9') || *p == '.')) {
 		rip[x++] = *p;
 		p++;
 	}
 
 	p = port_ptr;
 	x = 0;
-	while(x < sizeof(rp) && p && *p && (*p >= '0' && *p <= '9')) {
+	while (x < sizeof(rp) && p && *p && (*p >= '0' && *p <= '9')) {
 		rp[x++] = *p;
 		p++;
 	}
 
 	p = vid_port_ptr;
 	x = 0;
-	while(x < sizeof(rvp) && p && *p && (*p >= '0' && *p <= '9')) {
+	while (x < sizeof(rvp) && p && *p && (*p >= '0' && *p <= '9')) {
 		rvp[x++] = *p;
 		p++;
 	}
@@ -769,10 +766,10 @@
 		tech_pvt->remote_sdp_video_ip = switch_core_session_strdup(tech_pvt->session, rip);
 		tech_pvt->remote_sdp_video_port = (switch_port_t) atoi(rvp);
 	}
-	
+
 	if (tech_pvt->remote_sdp_video_ip && tech_pvt->remote_sdp_video_port) {
 		if (!strcmp(tech_pvt->remote_sdp_video_ip, rip) && atoi(rvp) == tech_pvt->remote_sdp_video_port) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Remote video address:port [%s:%d] has not changed.\n", 
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Remote video address:port [%s:%d] has not changed.\n",
 							  tech_pvt->remote_sdp_audio_ip, tech_pvt->remote_sdp_audio_port);
 		} else {
 			switch_set_flag_locked(tech_pvt, TFLAG_VIDEO);
@@ -792,7 +789,7 @@
 	}
 
 	if (tech_pvt->remote_sdp_audio_ip && !strcmp(tech_pvt->remote_sdp_audio_ip, rip) && atoi(rp) == tech_pvt->remote_sdp_audio_port) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Remote address:port [%s:%d] has not changed.\n", 
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Remote address:port [%s:%d] has not changed.\n",
 						  tech_pvt->remote_sdp_audio_ip, tech_pvt->remote_sdp_audio_port);
 		return SWITCH_STATUS_SUCCESS;
 	}
@@ -808,7 +805,7 @@
 			switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
 		}
 	}
-	
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -824,8 +821,8 @@
 	}
 
 	len = strlen(tech_pvt->local_sdp_str) + 384;
-	
-	if ((p = (char *)switch_stristr("c=IN IP4 ", tech_pvt->local_sdp_str))) {
+
+	if ((p = (char *) switch_stristr("c=IN IP4 ", tech_pvt->local_sdp_str))) {
 		ip_ptr = p + 9;
 	}
 
@@ -834,16 +831,16 @@
 		return;
 	}
 
-	if ((p = (char *)switch_stristr("m=audio ", tech_pvt->local_sdp_str))) {
+	if ((p = (char *) switch_stristr("m=audio ", tech_pvt->local_sdp_str))) {
 		port_ptr = p + 8;
 	}
 
-	if ((p = (char *)switch_stristr("m=video ", tech_pvt->local_sdp_str))) {
+	if ((p = (char *) switch_stristr("m=video ", tech_pvt->local_sdp_str))) {
 		vport_ptr = p + 8;
 	}
-	
+
 	if (!(ip_ptr && port_ptr)) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s SDP has no audio in it.\n%s\n", 
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s SDP has no audio in it.\n%s\n",
 						  switch_channel_get_name(tech_pvt->channel), tech_pvt->local_sdp_str);
 		return;
 	}
@@ -867,7 +864,7 @@
 
 	tech_pvt->orig_local_sdp_str = tech_pvt->local_sdp_str;
 	tech_pvt->local_sdp_str = switch_core_session_alloc(tech_pvt->session, len);
-	
+
 	q = tech_pvt->local_sdp_str;
 	p = tech_pvt->orig_local_sdp_str;
 
@@ -876,36 +873,36 @@
 			strncpy(q, tech_pvt->adv_sdp_audio_ip, strlen(tech_pvt->adv_sdp_audio_ip));
 			q += strlen(tech_pvt->adv_sdp_audio_ip);
 			x = 0;
-			while(p && *p && ((*p >= '0' && *p <= '9') || *p == '.')) {
+			while (p && *p && ((*p >= '0' && *p <= '9') || *p == '.')) {
 				p++;
 			}
 
 		} else if (p == port_ptr) {
 			char port_buf[25] = "";
-			
+
 			switch_snprintf(port_buf, sizeof(port_buf), "%u", tech_pvt->adv_sdp_audio_port);
 			strncpy(q, port_buf, strlen(port_buf));
 			q += strlen(port_buf);
 			x = 0;
-			while(p && *p && (*p >= '0' && *p <= '9')) {
+			while (p && *p && (*p >= '0' && *p <= '9')) {
 				p++;
 			}
-		} else if (vport_ptr && tech_pvt->adv_sdp_video_port &&  p == vport_ptr) {
+		} else if (vport_ptr && tech_pvt->adv_sdp_video_port && p == vport_ptr) {
 			char port_buf[25] = "";
-			
+
 			switch_snprintf(port_buf, sizeof(port_buf), "%u", tech_pvt->adv_sdp_video_port);
 			strncpy(q, port_buf, strlen(port_buf));
 			q += strlen(port_buf);
 			x = 0;
-			while(p && *p && (*p >= '0' && *p <= '9')) {
+			while (p && *p && (*p >= '0' && *p <= '9')) {
 				p++;
 			}
 		}
 
 		*q++ = *p++;
 	}
-	
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Patched SDP\n---\n%s\n+++\n%s\n", 
+
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Patched SDP\n---\n%s\n+++\n%s\n",
 					  switch_channel_get_name(tech_pvt->channel), tech_pvt->orig_local_sdp_str, tech_pvt->local_sdp_str);
 }
 
@@ -1014,9 +1011,9 @@
 		 * since all of them have been already taken care of in mod_sofia.c:sofia_outgoing_channel()
 		 */
 		if (tech_pvt->transport == SOFIA_TRANSPORT_UNKNOWN && switch_strlen_zero(tech_pvt->gateway_name)) {
-			if ((p = (char *)switch_stristr("port=", url))) {
+			if ((p = (char *) switch_stristr("port=", url))) {
 				p += 5;
-				tech_pvt->transport = sofia_glue_str2transport( p );
+				tech_pvt->transport = sofia_glue_str2transport(p);
 			} else {
 				if ((t_var = switch_channel_get_variable(channel, "sip_transport"))) {
 					tech_pvt->transport = sofia_glue_str2transport(t_var);
@@ -1045,23 +1042,19 @@
 		invite_contact = sofia_overcome_sip_uri_weakness(session, tech_pvt->invite_contact, tech_pvt->transport, SWITCH_FALSE, NULL);
 		from_str = sofia_overcome_sip_uri_weakness(session, use_from_str, 0, SWITCH_FALSE, NULL);
 		to_str = sofia_overcome_sip_uri_weakness(session, tech_pvt->dest_to, 0, SWITCH_FALSE, invite_params);
-												 
+
 
 		/*
 		   Does the "genius" who wanted SIP to be "text-based" so it was "easier to read" even use it now,
 		   or did he just suggest it to make our lives miserable?
-		*/
+		 */
 		use_from_str = from_str;
 		from_str = switch_core_session_sprintf(session, "\"%s\" <%s>", tech_pvt->caller_profile->caller_id_name, use_from_str);
 
 		tech_pvt->nh = nua_handle(tech_pvt->profile->nua, NULL,
-								  NUTAG_URL(url_str),
-								  SIPTAG_TO_STR(to_str),
-								  SIPTAG_FROM_STR(from_str),
-								  SIPTAG_CONTACT_STR(invite_contact),
-								  TAG_END());
+								  NUTAG_URL(url_str), SIPTAG_TO_STR(to_str), SIPTAG_FROM_STR(from_str), SIPTAG_CONTACT_STR(invite_contact), TAG_END());
+
 
-		
 		if (strstr(tech_pvt->dest, ";nat") || ((val = switch_channel_get_variable(channel, "sip_sticky_contact")) && switch_true(val))) {
 			switch_set_flag(tech_pvt, TFLAG_NAT);
 			tech_pvt->record_route = switch_core_session_strdup(tech_pvt->session, url_str);
@@ -1069,7 +1062,7 @@
 			session_timeout = SOFIA_NAT_SESSION_TIMEOUT;
 			switch_channel_set_variable(channel, "sip_nat_detected", "true");
 		}
-		
+
 		/* TODO: We should use the new tags for making an rpid and add profile options to turn this on/off */
 		if (switch_test_flag(caller_profile, SWITCH_CPF_HIDE_NAME)) {
 			priv = "name";
@@ -1084,14 +1077,12 @@
 			screen = "yes";
 		}
 
-		tech_pvt->rpid = switch_core_session_sprintf(tech_pvt->session, "Remote-Party-ID: \"%s\"<sip:%s@%s>;screen=%s;privacy=%s", 
-													 tech_pvt->caller_profile->caller_id_name, 
-													 tech_pvt->caller_profile->caller_id_number, 
-													 rpid_domain,
-													 screen, priv);
+		tech_pvt->rpid = switch_core_session_sprintf(tech_pvt->session, "Remote-Party-ID: \"%s\"<sip:%s@%s>;screen=%s;privacy=%s",
+													 tech_pvt->caller_profile->caller_id_name,
+													 tech_pvt->caller_profile->caller_id_number, rpid_domain, screen, priv);
 
 		switch_safe_free(d_url);
-		
+
 		if (!(sofia_private = malloc(sizeof(*sofia_private)))) {
 			abort();
 		}
@@ -1108,7 +1099,7 @@
 		e_dest = strdup(tech_pvt->e_dest);
 		switch_assert(e_dest != NULL);
 		user = e_dest;
-		
+
 		if ((host = strchr(user, '@'))) {
 			*host++ = '\0';
 		}
@@ -1132,7 +1123,7 @@
 		for (; hi; hi = hi->next) {
 			const char *name = (char *) hi->name;
 			char *value = (char *) hi->value;
-			
+
 			if (!strncasecmp(name, SOFIA_SIP_HEADER_PREFIX, strlen(SOFIA_SIP_HEADER_PREFIX))) {
 				const char *hname = name + strlen(SOFIA_SIP_HEADER_PREFIX);
 				stream.write_function(&stream, "%s: %s\r\n", hname, value);
@@ -1144,7 +1135,7 @@
 	if (stream.data) {
 		extra_headers = stream.data;
 	}
-	
+
 	session_timeout = tech_pvt->profile->session_timeout;
 	if ((val = switch_channel_get_variable(channel, SOFIA_SESSION_TIMEOUT))) {
 		int v_session_timeout = atoi(val);
@@ -1198,9 +1189,7 @@
 
 		tech_pvt->nh2 = nua_handle(tech_pvt->profile->nua, NULL,
 								   SIPTAG_TO_STR(tech_pvt->dest),
-								   SIPTAG_FROM_STR(tech_pvt->from_str),
-								   SIPTAG_CONTACT_STR(tech_pvt->profile->url),
-								   TAG_END());
+								   SIPTAG_FROM_STR(tech_pvt->from_str), SIPTAG_CONTACT_STR(tech_pvt->profile->url), TAG_END());
 
 		nua_handle_bind(tech_pvt->nh2, tech_pvt->sofia_private);
 
@@ -1329,7 +1318,7 @@
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set VIDEO Codec %s %s/%ld %d ms\n",
 							  switch_channel_get_name(tech_pvt->channel), tech_pvt->video_rm_encoding, tech_pvt->video_rm_rate, tech_pvt->video_codec_ms);
 			tech_pvt->video_read_frame.codec = &tech_pvt->video_read_codec;
-			
+
 			tech_pvt->video_fmtp_out = switch_core_session_strdup(tech_pvt->session, tech_pvt->video_write_codec.fmtp_out);
 
 			tech_pvt->video_write_codec.agreed_pt = tech_pvt->video_agreed_pt;
@@ -1378,7 +1367,7 @@
 							   NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
 		return SWITCH_STATUS_FALSE;
-	} 
+	}
 
 	if (switch_core_codec_init(&tech_pvt->write_codec,
 							   tech_pvt->iananame,
@@ -1390,7 +1379,7 @@
 							   NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
 		return SWITCH_STATUS_FALSE;
-	} 
+	}
 
 	tech_pvt->read_frame.rate = tech_pvt->rm_rate;
 	ms = tech_pvt->write_codec.implementation->microseconds_per_frame / 1000;
@@ -1402,10 +1391,9 @@
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set Codec %s %s/%ld %d ms %d samples\n",
 					  switch_channel_get_name(tech_pvt->channel), tech_pvt->iananame, tech_pvt->rm_rate, tech_pvt->codec_ms,
-					  tech_pvt->read_codec.implementation->samples_per_frame
-					  );
+					  tech_pvt->read_codec.implementation->samples_per_frame);
 	tech_pvt->read_frame.codec = &tech_pvt->read_codec;
-	
+
 	tech_pvt->write_codec.agreed_pt = tech_pvt->agreed_pt;
 	tech_pvt->read_codec.agreed_pt = tech_pvt->agreed_pt;
 
@@ -1441,12 +1429,12 @@
 		key = tech_pvt->remote_raw_key;
 
 	}
-	
+
 	switch_rtp_get_random(key, SWITCH_RTP_KEY_LEN);
 	switch_b64_encode(key, SWITCH_RTP_KEY_LEN, b64_key, sizeof(b64_key));
-	p = strrchr((char *)b64_key, '=');
+	p = strrchr((char *) b64_key, '=');
 
-	while(p && *p && *p == '=') {
+	while (p && *p && *p == '=') {
 		*p-- = '\0';
 	}
 
@@ -1469,12 +1457,12 @@
 	if (!switch_rtp_ready(tech_pvt->rtp_session)) {
 		goto bad;
 	}
-	
+
 	index = atoi(key_str);
 
 	p = strchr(key_str, ' ');
-	
-	if (p && *p && *(p+1)) {
+
+	if (p && *p && *(p + 1)) {
 		p++;
 		if (!strncasecmp(p, SWITCH_RTP_CRYPTO_KEY_32, strlen(SWITCH_RTP_CRYPTO_KEY_32))) {
 			type = AES_CM_128_HMAC_SHA1_32;
@@ -1486,7 +1474,7 @@
 		}
 
 		p = strchr(p, ' ');
-		if (p && *p && *(p+1)) {
+		if (p && *p && *(p + 1)) {
 			p++;
 			if (strncasecmp(p, "inline:", 7)) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error near [%s]\n", p);
@@ -1494,8 +1482,8 @@
 			}
 
 			p += 7;
-			switch_b64_decode(p, (char *)key, sizeof(key));
-			
+			switch_b64_decode(p, (char *) key, sizeof(key));
+
 			if (direction == SWITCH_RTP_CRYPTO_SEND) {
 				tech_pvt->crypto_send_type = type;
 				memcpy(tech_pvt->local_raw_key, key, SWITCH_RTP_KEY_LEN);
@@ -1507,8 +1495,8 @@
 		}
 
 	}
-	
- bad:
+
+  bad:
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error!\n");
 	return SWITCH_STATUS_FALSE;
@@ -1532,7 +1520,7 @@
 	switch_assert(tech_pvt != NULL);
 
 	switch_core_session_signal_lock(tech_pvt->session);
-	
+
 
 	if ((var = switch_channel_get_variable(tech_pvt->channel, SOFIA_SECURE_MEDIA_VARIABLE)) && switch_true(var)) {
 		switch_set_flag_locked(tech_pvt, TFLAG_SECURE);
@@ -1556,7 +1544,7 @@
 	bw = tech_pvt->read_codec.implementation->bits_per_second;
 	ms = tech_pvt->read_codec.implementation->microseconds_per_frame;
 
-	if (myflags)  {
+	if (myflags) {
 		flags = myflags;
 	} else {
 		flags = (switch_rtp_flag_t) (SWITCH_RTP_FLAG_AUTOADJ | SWITCH_RTP_FLAG_DATAWAIT);
@@ -1581,7 +1569,7 @@
 		flags |= SWITCH_RTP_FLAG_PASS_RFC2833;
 	}
 
-	if (!((tech_pvt->profile->pflags & PFLAG_REWRITE_TIMESTAMPS) || 
+	if (!((tech_pvt->profile->pflags & PFLAG_REWRITE_TIMESTAMPS) ||
 		  ((val = switch_channel_get_variable(tech_pvt->channel, "rtp_rewrite_timestamps")) && !switch_true(val)))) {
 		flags |= SWITCH_RTP_FLAG_RAW_WRITE;
 	}
@@ -1589,7 +1577,7 @@
 	if (tech_pvt->cng_pt) {
 		flags |= SWITCH_RTP_FLAG_AUTO_CNG;
 	}
-	
+
 	if (tech_pvt->rtp_session && switch_test_flag(tech_pvt, TFLAG_REINVITE)) {
 		const char *ip = switch_channel_get_variable(tech_pvt->channel, SWITCH_LOCAL_MEDIA_IP_VARIABLE);
 		const char *port = switch_channel_get_variable(tech_pvt->channel, SWITCH_LOCAL_MEDIA_PORT_VARIABLE);
@@ -1606,9 +1594,7 @@
 						  tech_pvt->local_sdp_audio_ip,
 						  tech_pvt->local_sdp_audio_port,
 						  tech_pvt->remote_sdp_audio_ip,
-						  tech_pvt->remote_sdp_audio_port,
-						  tech_pvt->agreed_pt,
-						  tech_pvt->read_codec.implementation->microseconds_per_frame / 1000);
+						  tech_pvt->remote_sdp_audio_port, tech_pvt->agreed_pt, tech_pvt->read_codec.implementation->microseconds_per_frame / 1000);
 	}
 
 	switch_snprintf(tmp, sizeof(tmp), "%d", tech_pvt->remote_sdp_audio_port);
@@ -1627,9 +1613,9 @@
 			/* Reactivate the NAT buster flag. */
 			switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
 		}
-        goto video;
+		goto video;
 	}
-	
+
 	if (switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MEDIA)) {
 		if ((status = sofia_glue_tech_proxy_remote_addr(tech_pvt)) != SWITCH_STATUS_SUCCESS) {
 			goto end;
@@ -1642,9 +1628,7 @@
 						  tech_pvt->local_sdp_audio_ip,
 						  tech_pvt->local_sdp_audio_port,
 						  tech_pvt->remote_sdp_audio_ip,
-						  tech_pvt->remote_sdp_audio_port,
-						  tech_pvt->agreed_pt,
-						  tech_pvt->read_codec.implementation->microseconds_per_frame / 1000);
+						  tech_pvt->remote_sdp_audio_port, tech_pvt->agreed_pt, tech_pvt->read_codec.implementation->microseconds_per_frame / 1000);
 
 	} else {
 		timer_name = tech_pvt->profile->timer_name;
@@ -1657,11 +1641,8 @@
 										   tech_pvt->agreed_pt,
 										   tech_pvt->read_codec.implementation->samples_per_frame,
 										   tech_pvt->codec_ms * 1000,
-										   (switch_rtp_flag_t) flags,
-										   timer_name,
-										   &err,
-										   switch_core_session_get_pool(tech_pvt->session));
-	
+										   (switch_rtp_flag_t) flags, timer_name, &err, switch_core_session_get_pool(tech_pvt->session));
+
 	if (switch_rtp_ready(tech_pvt->rtp_session)) {
 		uint8_t vad_in = switch_test_flag(tech_pvt, TFLAG_VAD_IN) ? 1 : 0;
 		uint8_t vad_out = switch_test_flag(tech_pvt, TFLAG_VAD_OUT) ? 1 : 0;
@@ -1694,14 +1675,14 @@
 
 		if ((val = switch_channel_get_variable(tech_pvt->channel, "jitterbuffer_msec"))) {
 			int len = atoi(val);
-			
+
 			if (len < 100 || len > 1000) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Jitterbuffer spec [%d] must be between 100 and 1000\n", len);
 			} else {
 				int qlen;
 
 				qlen = len / (tech_pvt->read_codec.implementation->microseconds_per_frame / 1000);
-				
+
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Setting Jitterbuffer to %dms (%d frames)\n", len, qlen);
 				switch_rtp_activate_jitter_buffer(tech_pvt->rtp_session, qlen);
 			}
@@ -1720,11 +1701,11 @@
 				rtp_hold_timeout_sec = v;
 			}
 		}
-		
+
 		if (rtp_timeout_sec) {
-			tech_pvt->max_missed_packets = (tech_pvt->read_codec.implementation->samples_per_second * rtp_timeout_sec) / 
+			tech_pvt->max_missed_packets = (tech_pvt->read_codec.implementation->samples_per_second * rtp_timeout_sec) /
 				tech_pvt->read_codec.implementation->samples_per_frame;
-			
+
 			switch_rtp_set_max_missed_packets(tech_pvt->rtp_session, tech_pvt->max_missed_packets);
 			if (!rtp_hold_timeout_sec) {
 				rtp_hold_timeout_sec = rtp_timeout_sec * 10;
@@ -1732,7 +1713,7 @@
 		}
 
 		if (rtp_hold_timeout_sec) {
-			tech_pvt->max_missed_hold_packets = (tech_pvt->read_codec.implementation->samples_per_second * rtp_hold_timeout_sec) / 
+			tech_pvt->max_missed_hold_packets = (tech_pvt->read_codec.implementation->samples_per_second * rtp_hold_timeout_sec) /
 				tech_pvt->read_codec.implementation->samples_per_frame;
 		}
 
@@ -1742,16 +1723,17 @@
 		if (tech_pvt->cng_pt) {
 			switch_rtp_set_cng_pt(tech_pvt->rtp_session, tech_pvt->cng_pt);
 		}
-		
+
 		if (tech_pvt->remote_crypto_key && switch_test_flag(tech_pvt, TFLAG_SECURE)) {
 			sofia_glue_add_crypto(tech_pvt, tech_pvt->remote_crypto_key, SWITCH_RTP_CRYPTO_RECV);
-			switch_rtp_add_crypto_key(tech_pvt->rtp_session, SWITCH_RTP_CRYPTO_SEND, 1, tech_pvt->crypto_type, tech_pvt->local_raw_key, SWITCH_RTP_KEY_LEN);
-			switch_rtp_add_crypto_key(tech_pvt->rtp_session, SWITCH_RTP_CRYPTO_RECV, tech_pvt->crypto_tag, 
-									  tech_pvt->crypto_type, tech_pvt->remote_raw_key, SWITCH_RTP_KEY_LEN);
+			switch_rtp_add_crypto_key(tech_pvt->rtp_session, SWITCH_RTP_CRYPTO_SEND, 1, tech_pvt->crypto_type, tech_pvt->local_raw_key,
+									  SWITCH_RTP_KEY_LEN);
+			switch_rtp_add_crypto_key(tech_pvt->rtp_session, SWITCH_RTP_CRYPTO_RECV, tech_pvt->crypto_tag, tech_pvt->crypto_type, tech_pvt->remote_raw_key,
+									  SWITCH_RTP_KEY_LEN);
 			switch_channel_set_variable(tech_pvt->channel, SOFIA_SECURE_MEDIA_CONFIRMED_VARIABLE, "true");
 		}
 
-    video:
+	  video:
 
 		sofia_glue_check_video_codecs(tech_pvt);
 
@@ -1760,7 +1742,7 @@
 				sofia_glue_tech_choose_video_port(tech_pvt, 1);
 			}
 
-			flags = (switch_rtp_flag_t) (SWITCH_RTP_FLAG_USE_TIMER | SWITCH_RTP_FLAG_AUTOADJ | 
+			flags = (switch_rtp_flag_t) (SWITCH_RTP_FLAG_USE_TIMER | SWITCH_RTP_FLAG_AUTOADJ |
 										 SWITCH_RTP_FLAG_DATAWAIT | SWITCH_RTP_FLAG_NOBLOCK | SWITCH_RTP_FLAG_RAW_WRITE);
 
 			if (switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MEDIA)) {
@@ -1774,12 +1756,7 @@
 														 tech_pvt->remote_sdp_video_ip,
 														 tech_pvt->remote_sdp_video_port,
 														 tech_pvt->video_agreed_pt,
-														 1,
-														 10000,
-														 (switch_rtp_flag_t) flags,
-														 NULL,
-														 &err, 
-														 switch_core_session_get_pool(tech_pvt->session));
+														 1, 10000, (switch_rtp_flag_t) flags, NULL, &err, switch_core_session_get_pool(tech_pvt->session));
 
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%sVIDEO RTP [%s] %s:%d->%s:%d codec: %u ms: %d [%s]\n",
 							  switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MEDIA) ? "PROXY " : "",
@@ -1788,8 +1765,7 @@
 							  tech_pvt->local_sdp_video_port,
 							  tech_pvt->remote_sdp_video_ip,
 							  tech_pvt->remote_sdp_video_port, tech_pvt->video_agreed_pt,
-							  0,
-							  switch_rtp_ready(tech_pvt->video_rtp_session) ? "SUCCESS" : err);
+							  0, switch_rtp_ready(tech_pvt->video_rtp_session) ? "SUCCESS" : err);
 
 			if (switch_rtp_ready(tech_pvt->video_rtp_session)) {
 				switch_channel_set_flag(tech_pvt->channel, CF_VIDEO);
@@ -1809,13 +1785,13 @@
 
 	switch_set_flag(tech_pvt, TFLAG_IO);
 	status = SWITCH_STATUS_SUCCESS;
-	
- end:
+
+  end:
 
 	switch_core_session_signal_unlock(tech_pvt->session);
 
 	return status;
-	
+
 }
 
 switch_status_t sofia_glue_tech_media(private_object_t *tech_pvt, const char *r_sdp)
@@ -1878,7 +1854,7 @@
 	switch_assert(tech_pvt != NULL);
 
 	greedy = !!(tech_pvt->profile->pflags & PFLAG_GREEDY);
-	
+
 	if (!greedy) {
 		if ((val = switch_channel_get_variable(channel, "sip_codec_negotiation")) && !strcasecmp(val, "greedy")) {
 			greedy = 1;
@@ -1893,7 +1869,7 @@
 	}
 
 	if (((m = sdp->sdp_media)) && m->m_mode == sdp_sendonly) {
-		sendonly = 2; /* global sendonly always wins */
+		sendonly = 2;			/* global sendonly always wins */
 	}
 
 	for (attr = sdp->sdp_attributes; attr; attr = attr->a_next) {
@@ -1924,7 +1900,7 @@
 			if (!(stream = switch_channel_get_variable(tech_pvt->channel, SWITCH_HOLD_MUSIC_VARIABLE))) {
 				stream = tech_pvt->profile->hold_music;
 			}
-			
+
 			if (stream && switch_is_moh(stream)) {
 				if (!strcasecmp(stream, "indicate_hold")) {
 					switch_channel_set_flag(tech_pvt->channel, CF_SUSPEND);
@@ -1939,7 +1915,7 @@
 		if (switch_test_flag(tech_pvt, TFLAG_SIP_HOLD)) {
 			const char *uuid;
 			switch_core_session_t *b_session;
-			
+
 			if (tech_pvt->max_missed_packets) {
 				switch_rtp_set_max_missed_packets(tech_pvt->rtp_session, tech_pvt->max_missed_packets);
 			}
@@ -1999,7 +1975,7 @@
 
 								if (switch_rtp_ready(tech_pvt->rtp_session) && switch_test_flag(tech_pvt, TFLAG_SECURE)) {
 									sofia_glue_add_crypto(tech_pvt, tech_pvt->remote_crypto_key, SWITCH_RTP_CRYPTO_RECV);
-									switch_rtp_add_crypto_key(tech_pvt->rtp_session, SWITCH_RTP_CRYPTO_RECV, tech_pvt->crypto_tag, 
+									switch_rtp_add_crypto_key(tech_pvt->rtp_session, SWITCH_RTP_CRYPTO_RECV, tech_pvt->crypto_tag,
 															  tech_pvt->crypto_type, tech_pvt->remote_raw_key, SWITCH_RTP_KEY_LEN);
 								}
 								got_crypto++;
@@ -2012,7 +1988,7 @@
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set Remote Key [%s]\n", tech_pvt->remote_crypto_key);
 						tech_pvt->crypto_tag = crypto_tag;
 						got_crypto++;
-						
+
 						if (switch_strlen_zero(tech_pvt->local_crypto_key)) {
 							if (switch_stristr(SWITCH_RTP_CRYPTO_KEY_32, crypto)) {
 								switch_channel_set_variable(tech_pvt->channel, SOFIA_HAS_CRYPTO_VARIABLE, SWITCH_RTP_CRYPTO_KEY_32);
@@ -2043,8 +2019,8 @@
 				match = 0;
 				break;
 			}
-			
-		greed:
+
+		  greed:
 			x = 0;
 
 			if (tech_pvt->rm_encoding) {
@@ -2054,12 +2030,12 @@
 					} else {
 						match = strcasecmp(switch_str_nil(map->rm_encoding), tech_pvt->iananame) ? 0 : 1;
 					}
-				
+
 					if (match) {
-						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Our existing codec [%s] is still good, let's keep it\n", 
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Our existing codec [%s] is still good, let's keep it\n",
 										  tech_pvt->rm_encoding);
-                        got_audio = 1;
-                        break;
+						got_audio = 1;
+						break;
 					}
 				}
 			}
@@ -2071,7 +2047,7 @@
 				uint32_t near_rate = 0;
 				const switch_codec_implementation_t *mimp = NULL, *near_match = NULL;
 				const char *rm_encoding;
-				
+
 				if (x++ < skip) {
 					continue;
 				}
@@ -2079,7 +2055,7 @@
 				if (!(rm_encoding = map->rm_encoding)) {
 					rm_encoding = "";
 				}
-				
+
 				if (!te && !strcasecmp(rm_encoding, "telephone-event")) {
 					te = tech_pvt->te = (switch_payload_t) map->rm_pt;
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set 2833 dtmf payload to %u\n", te);
@@ -2096,19 +2072,20 @@
 						switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_AUTO_CNG);
 					}
 				}
-				
+
 				if (match) {
 					if (te && cng_pt) {
 						break;
 					}
 					continue;
 				}
-				
+
 				if (greedy) {
 					first = mine;
 					last = first + 1;
 				} else {
-					first = 0; last = tech_pvt->num_codecs;
+					first = 0;
+					last = tech_pvt->num_codecs;
 				}
 
 				for (i = first; i < last && i < tech_pvt->num_codecs; i++) {
@@ -2119,13 +2096,13 @@
 					}
 
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Audio Codec Compare [%s:%d:%u]/[%s:%d:%u]\n",
-									  rm_encoding, map->rm_pt, (int)map->rm_rate, imp->iananame, imp->ianacode, codec_rate);
+									  rm_encoding, map->rm_pt, (int) map->rm_rate, imp->iananame, imp->ianacode, codec_rate);
 					if (map->rm_pt < 96) {
 						match = (map->rm_pt == imp->ianacode) ? 1 : 0;
 					} else {
 						match = strcasecmp(rm_encoding, imp->iananame) ? 0 : 1;
 					}
-					
+
 					if (match) {
 						if ((ptime && ptime * 1000 != imp->microseconds_per_frame) || map->rm_rate != codec_rate) {
 							near_rate = map->rm_rate;
@@ -2139,15 +2116,15 @@
 						match = 0;
 					}
 				}
-				
+
 				if (!match && near_match) {
 					const switch_codec_implementation_t *search[1];
 					char *prefs[1];
 					char tmp[80];
 					int num;
-					
+
 					switch_snprintf(tmp, sizeof(tmp), "%s@%uk@%ui", near_match->iananame, near_rate ? near_rate : near_match->samples_per_second, ptime);
-					
+
 					prefs[0] = tmp;
 					num = switch_loadable_module_get_codecs_sorted(search, 1, prefs, 1);
 
@@ -2156,7 +2133,7 @@
 					} else {
 						mimp = near_match;
 					}
-					
+
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Substituting codec %s@%ui@%uh\n",
 									  mimp->iananame, mimp->microseconds_per_frame / 1000, mimp->samples_per_second);
 					match = 1;
@@ -2197,14 +2174,14 @@
 				goto greed;
 			}
 
-		} else if (m->m_type == sdp_media_video && m->m_port) { 
+		} else if (m->m_type == sdp_media_video && m->m_port) {
 			sdp_rtpmap_t *map;
 			const char *rm_encoding;
 			int framerate = 0;
 			const switch_codec_implementation_t *mimp = NULL;
 			int vmatch = 0, i;
 			switch_channel_set_variable(tech_pvt->channel, "video_possible", "true");
-			
+
 			connection = sdp->sdp_connection;
 			if (m->m_connections) {
 				connection = m->m_connections;
@@ -2226,7 +2203,7 @@
 				if (!(rm_encoding = map->rm_encoding)) {
 					rm_encoding = "";
 				}
-				
+
 				for (i = 0; i < tech_pvt->num_codecs; i++) {
 					const switch_codec_implementation_t *imp = tech_pvt->codecs[i];
 
@@ -2241,7 +2218,7 @@
 					} else {
 						vmatch = strcasecmp(rm_encoding, imp->iananame) ? 0 : 1;
 					}
-					
+
 
 					if (vmatch && (map->rm_rate == imp->samples_per_second)) {
 						mimp = imp;
@@ -2251,7 +2228,7 @@
 					}
 				}
 
-                                        
+
 				if (mimp) {
 					if ((tech_pvt->video_rm_encoding = switch_core_session_strdup(session, (char *) rm_encoding))) {
 						char tmp[50];
@@ -2269,7 +2246,7 @@
 						switch_snprintf(tmp, sizeof(tmp), "%d", tech_pvt->video_agreed_pt);
 						switch_channel_set_variable(tech_pvt->channel, "sip_video_pt", tmp);
 						sofia_glue_check_video_codecs(tech_pvt);
-                        break;
+						break;
 					} else {
 						vmatch = 0;
 					}
@@ -2408,7 +2385,7 @@
 			switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "Profile %s is locked\n", profile->name);
 #endif
 			profile = NULL;
-		}		
+		}
 	} else {
 #ifdef SOFIA_DEBUG_RWLOCKS
 		switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "Profile %s is not in the hash\n", key);
@@ -2420,7 +2397,7 @@
 	}
 #endif
 
- done:
+  done:
 	switch_mutex_unlock(mod_sofia_globals.hash_mutex);
 
 	return profile;
@@ -2458,7 +2435,7 @@
 	const void *var;
 	void *val;
 	sofia_profile_t *pptr;
-	
+
 	switch_mutex_lock(mod_sofia_globals.hash_mutex);
 	if (mod_sofia_globals.profile_hash) {
 		for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
@@ -2492,12 +2469,9 @@
 		"   call_id         VARCHAR(255),\n"
 		"   sip_user        VARCHAR(255),\n"
 		"   sip_host        VARCHAR(255),\n"
-		"   contact         VARCHAR(1024),\n" 
-		"   status          VARCHAR(255),\n" 
-		"   rpid            VARCHAR(255),\n" 
-		"   expires         INTEGER,\n"
-		"   user_agent      VARCHAR(255)\n"
-		");\n";
+		"   contact         VARCHAR(1024),\n"
+		"   status          VARCHAR(255),\n"
+		"   rpid            VARCHAR(255),\n" "   expires         INTEGER,\n" "   user_agent      VARCHAR(255)\n" ");\n";
 
 	char dialog_sql[] =
 		"CREATE TABLE sip_dialogs (\n"
@@ -2507,12 +2481,9 @@
 		"   sip_to_host     VARCHAR(255),\n"
 		"   sip_from_user   VARCHAR(255),\n"
 		"   sip_from_host   VARCHAR(255),\n"
-		"   contact_user    VARCHAR(255),\n" 
-		"   contact_host    VARCHAR(255),\n" 
-		"   state           VARCHAR(255),\n" 
-		"   direction       VARCHAR(255),\n" 
-		"   user_agent      VARCHAR(255)\n"
-		");\n";
+		"   contact_user    VARCHAR(255),\n"
+		"   contact_host    VARCHAR(255),\n"
+		"   state           VARCHAR(255),\n" "   direction       VARCHAR(255),\n" "   user_agent      VARCHAR(255)\n" ");\n";
 
 	char sub_sql[] =
 		"CREATE TABLE sip_subscriptions (\n"
@@ -2523,21 +2494,14 @@
 		"   sub_to_host     VARCHAR(255),\n"
 		"   event           VARCHAR(255),\n"
 		"   contact         VARCHAR(1024),\n"
-		"   call_id         VARCHAR(255),\n" 
-		"   full_from       VARCHAR(255),\n" 
-		"   full_via        VARCHAR(255),\n" 
-		"   expires         INTEGER,\n"
-		"   user_agent      VARCHAR(255),\n"
-		"   accept          VARCHAR(255)\n" 
-		");\n";
+		"   call_id         VARCHAR(255),\n"
+		"   full_from       VARCHAR(255),\n"
+		"   full_via        VARCHAR(255),\n"
+		"   expires         INTEGER,\n" "   user_agent      VARCHAR(255),\n" "   accept          VARCHAR(255)\n" ");\n";
+
 
+	char auth_sql[] = "CREATE TABLE sip_authentication (\n" "   nonce           VARCHAR(255),\n" "   expires         INTEGER" ");\n";
 
-	char auth_sql[] =
-		"CREATE TABLE sip_authentication (\n"
-		"   nonce           VARCHAR(255),\n" 
-		"   expires         INTEGER"
-		");\n";
-	
 	if (profile->odbc_dsn) {
 #ifdef SWITCH_HAVE_ODBC
 		if (!(profile->master_odbc = switch_odbc_handle_new(profile->odbc_dsn, profile->odbc_user, profile->odbc_pass))) {
@@ -2549,13 +2513,14 @@
 		}
 
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", profile->odbc_dsn);
-			
+
 		if (switch_odbc_handle_exec(profile->master_odbc, "select sip_user,user_agent from sip_registrations", NULL) != SWITCH_ODBC_SUCCESS) {
 			switch_odbc_handle_exec(profile->master_odbc, "DROP TABLE sip_registrations", NULL);
 			switch_odbc_handle_exec(profile->master_odbc, reg_sql, NULL);
 		}
 
-		if (switch_odbc_handle_exec(profile->master_odbc, "delete from sip_subscriptions where sip_user != '' or accept != ''", NULL) != SWITCH_ODBC_SUCCESS) {
+		if (switch_odbc_handle_exec(profile->master_odbc, "delete from sip_subscriptions where sip_user != '' or accept != ''", NULL) !=
+			SWITCH_ODBC_SUCCESS) {
 			switch_odbc_handle_exec(profile->master_odbc, "DROP TABLE sip_subscriptions", NULL);
 			switch_odbc_handle_exec(profile->master_odbc, sub_sql, NULL);
 		}
@@ -2578,7 +2543,8 @@
 		}
 
 		switch_core_db_test_reactive(profile->master_db, "select sip_user,user_agent from sip_registrations", "DROP TABLE sip_registrations", reg_sql);
-		switch_core_db_test_reactive(profile->master_db, "delete from sip_subscriptions where sip_user != '' or accept != ''", "DROP TABLE sip_subscriptions", sub_sql);
+		switch_core_db_test_reactive(profile->master_db, "delete from sip_subscriptions where sip_user != '' or accept != ''",
+									 "DROP TABLE sip_subscriptions", sub_sql);
 		switch_core_db_test_reactive(profile->master_db, "delete from sip_dialogs", "DROP TABLE sip_dialogs", dialog_sql);
 		switch_core_db_test_reactive(profile->master_db, "select * from sip_authentication", "DROP TABLE sip_authentication", auth_sql);
 
@@ -2590,13 +2556,13 @@
 	}
 #endif
 
-	return profile->master_db ? 1: 0;
+	return profile->master_db ? 1 : 0;
 }
 
 void sofia_glue_sql_close(sofia_profile_t *profile)
 {
 #ifdef SWITCH_HAVE_ODBC
-    if (profile->odbc_dsn) {
+	if (profile->odbc_dsn) {
 		switch_odbc_handle_destroy(&profile->master_odbc);
 		return;
 	}
@@ -2614,7 +2580,7 @@
 
 	switch_assert(sqlp && *sqlp);
 	sql = *sqlp;
-	
+
 	if (profile->sql_queue) {
 		if (sql_already_dynamic) {
 			d_sql = sql;
@@ -2649,7 +2615,7 @@
 		switch_mutex_lock(mutex);
 	}
 
-    if (profile->odbc_dsn) {
+	if (profile->odbc_dsn) {
 #ifdef SWITCH_HAVE_ODBC
 		SQLHSTMT stmt;
 		if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
@@ -2678,7 +2644,7 @@
 		if (!master) {
 			switch_core_db_close(db);
 		}
-    }
+	}
 
   end:
 	if (mutex) {
@@ -2687,22 +2653,18 @@
 }
 
 switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile,
-											  switch_bool_t master,
-											  switch_mutex_t *mutex,
-											  char *sql,
-											  switch_core_db_callback_func_t callback,
-											  void *pdata)
+											  switch_bool_t master, switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback, void *pdata)
 {
 	switch_bool_t ret = SWITCH_FALSE;
 	switch_core_db_t *db;
 	char *errmsg = NULL;
-	
+
 	if (mutex) {
-        switch_mutex_lock(mutex);
-    }
+		switch_mutex_lock(mutex);
+	}
 
 
-    if (profile->odbc_dsn) {
+	if (profile->odbc_dsn) {
 #ifdef SWITCH_HAVE_ODBC
 		switch_odbc_handle_callback_exec(profile->master_odbc, sql, callback, pdata);
 #else
@@ -2718,7 +2680,7 @@
 				goto end;
 			}
 		}
-		
+
 		switch_core_db_exec(db, sql, callback, pdata, &errmsg);
 
 		if (errmsg) {
@@ -2729,12 +2691,12 @@
 		if (!master && db) {
 			switch_core_db_close(db);
 		}
-    }
+	}
 
- end:
+  end:
 	if (mutex) {
-        switch_mutex_unlock(mutex);
-    }
+		switch_mutex_unlock(mutex);
+	}
 	return ret;
 }
 
@@ -2760,7 +2722,7 @@
 		}
 
 		SQLDescribeCol(stmt, 1, name, sizeof(name), &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
-		SQLGetData(stmt, 1, SQL_C_CHAR, (SQLCHAR *)resbuf, (SQLLEN)len, NULL);
+		SQLGetData(stmt, 1, SQL_C_CHAR, (SQLCHAR *) resbuf, (SQLLEN) len, NULL);
 		SQLFreeHandle(SQL_HANDLE_STMT, stmt);
 		ret = resbuf;
 	}
@@ -2776,7 +2738,7 @@
 	char *ret = NULL;
 
 #ifdef SWITCH_HAVE_ODBC
-    if (profile->odbc_dsn) {
+	if (profile->odbc_dsn) {
 		return sofia_glue_execute_sql2str_odbc(profile, mutex, sql, resbuf, len);
 	}
 #endif

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c	Tue May 27 00:54:52 2008
@@ -127,7 +127,8 @@
 	void *val;
 	struct presence_helper helper = { 0 };
 
-	if (!mod_sofia_globals.profile_hash) return;
+	if (!mod_sofia_globals.profile_hash)
+		return;
 
 	if ((sql = switch_mprintf("select *,-1,'unavailable','unavailable' from sip_subscriptions where event='presence'"))) {
 		switch_mutex_lock(mod_sofia_globals.hash_mutex);
@@ -151,16 +152,15 @@
 void sofia_presence_establish_presence(sofia_profile_t *profile)
 {
 
-	if (sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, 
-										"select sip_user,sip_host,'Registered','unknown','' from sip_registrations", 
+	if (sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex,
+										"select sip_user,sip_host,'Registered','unknown','' from sip_registrations",
 										sofia_presence_resub_callback, profile) != SWITCH_TRUE) {
 		return;
 	}
 
 	if (sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex,
 										"select sub_to_user,sub_to_host,'Online','unknown',proto from sip_subscriptions "
-										"where proto='ext' or proto='user' or proto='conf'",
-										sofia_presence_resub_callback, profile) != SWITCH_TRUE) {
+										"where proto='ext' or proto='user' or proto='conf'", sofia_presence_resub_callback, profile) != SWITCH_TRUE) {
 		return;
 	}
 }
@@ -172,7 +172,7 @@
 	if (in && (switch_stristr("null", in))) {
 		in = NULL;
 	}
-	
+
 	if (!in) {
 		in = ext;
 	}
@@ -233,7 +233,7 @@
 			return;
 		}
 	}
-	
+
 	if (profile->domain_name && profile->domain_name != host) {
 		host = profile->domain_name;
 	}
@@ -251,43 +251,32 @@
 			if (!strcasecmp(hp->name, "mwi-message-account") && strncasecmp(hp->value, "sip:", 4)) {
 				tmp = switch_mprintf("sip:%s", hp->value);
 				value = tmp;
-			} 
+			}
 			stream.write_function(&stream, "%s: %s\r\n", hp->name + 4, value);
 			switch_safe_free(tmp);
 		}
 	}
 
 	stream.write_function(&stream, "\r\n");
-	
-	sql = switch_mprintf("select *,'%q' from sip_subscriptions where event='message-summary' and sub_to_user='%q' and sub_to_host='%q'", 
+
+	sql = switch_mprintf("select *,'%q' from sip_subscriptions where event='message-summary' and sub_to_user='%q' and sub_to_host='%q'",
 						 stream.data, user, host);
-	
 
-	switch_assert (sql != NULL);
-	sofia_glue_execute_sql_callback(profile,
-									SWITCH_FALSE,
-									profile->ireg_mutex,
-									sql,
-									sofia_presence_mwi_callback,
-									&h);
+
+	switch_assert(sql != NULL);
+	sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_mwi_callback, &h);
 
 	switch_safe_free(sql);
 
-	
 
-	sql = switch_mprintf("select sip_user,sip_host,contact,'%q' from sip_registrations where sip_user='%q' and sip_host='%q'", 
-						 stream.data, user, host);
-	
 
-		
-	switch_assert (sql != NULL);
-	sofia_glue_execute_sql_callback(profile,
-									SWITCH_FALSE,
-									profile->ireg_mutex,
-									sql,
-									sofia_presence_mwi_callback2,
-									&h);
-	
+	sql = switch_mprintf("select sip_user,sip_host,contact,'%q' from sip_registrations where sip_user='%q' and sip_host='%q'", stream.data, user, host);
+
+
+
+	switch_assert(sql != NULL);
+	sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_mwi_callback2, &h);
+
 	switch_safe_free(sql);
 
 	switch_safe_free(stream.data);
@@ -312,11 +301,11 @@
 	char *sql = NULL;
 	char *euser = NULL, *user = NULL, *host = NULL;
 
-	
+
 	if (!mod_sofia_globals.running) {
 		return;
 	}
-	
+
 	if (rpid && !strcasecmp(rpid, "n/a")) {
 		rpid = NULL;
 	}
@@ -350,8 +339,9 @@
 	if (event->event_id == SWITCH_EVENT_ROSTER) {
 		struct presence_helper helper = { 0 };
 
-		if (!mod_sofia_globals.profile_hash) return;
-		
+		if (!mod_sofia_globals.profile_hash)
+			return;
+
 		if (from) {
 			sql = switch_mprintf("select *,1,'%q','%q' from sip_subscriptions where event='presence' and full_from like '%%%q%%'", status, rpid, from);
 		} else {
@@ -367,13 +357,8 @@
 				continue;
 			}
 			helper.profile = profile;
-            helper.event = NULL;
-			sofia_glue_execute_sql_callback(profile,
-											SWITCH_FALSE,
-											profile->ireg_mutex,
-											sql,
-											sofia_presence_sub_callback,
-											&helper);
+			helper.event = NULL;
+			sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_sub_callback, &helper);
 		}
 		switch_mutex_unlock(mod_sofia_globals.hash_mutex);
 		free(sql);
@@ -387,7 +372,7 @@
 	if (switch_strlen_zero(alt_event_type)) {
 		alt_event_type = "presence";
 	}
-	
+
 	if ((user = strdup(from))) {
 		if ((host = strchr(user, '@'))) {
 			char *p;
@@ -432,15 +417,9 @@
 									 "from sip_registrations left join sip_dialogs on "
 									 "(sip_dialogs.sip_from_user = sip_registrations.sip_user) "
 									 "and sip_dialogs.sip_from_host = sip_registrations.sip_host "
-									 "where sip_registrations.sip_user='%q' and sip_registrations.sip_host='%q'",
-									 probe_euser, probe_host);
+									 "where sip_registrations.sip_user='%q' and sip_registrations.sip_host='%q'", probe_euser, probe_host);
 				switch_assert(sql);
-				sofia_glue_execute_sql_callback(profile,
-												SWITCH_FALSE,
-												profile->ireg_mutex,
-												sql,
-												sofia_presence_resub_callback,
-												profile);
+				sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_resub_callback, profile);
 
 				sofia_glue_release_profile(profile);
 				switch_safe_free(sql);
@@ -465,7 +444,8 @@
 		break;
 	}
 
-	if (!mod_sofia_globals.profile_hash) goto done;
+	if (!mod_sofia_globals.profile_hash)
+		goto done;
 
 	switch_mutex_lock(mod_sofia_globals.hash_mutex);
 	for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
@@ -478,31 +458,27 @@
 		if (sql) {
 			struct presence_helper helper = { 0 };
 			helper.profile = profile;
-            helper.event = event;
+			helper.event = event;
 			SWITCH_STANDARD_STREAM(helper.stream);
 			switch_assert(helper.stream.data);
 
-			sofia_glue_execute_sql_callback(profile,
-											SWITCH_FALSE,
+			sofia_glue_execute_sql_callback(profile, SWITCH_FALSE,
 											//profile->ireg_mutex,
-											NULL,
-											sql,
-											sofia_presence_sub_callback,
-											&helper);
-			
-			if (!switch_strlen_zero((char *)helper.stream.data)) {
-				char *this = (char *)helper.stream.data;
+											NULL, sql, sofia_presence_sub_callback, &helper);
+
+			if (!switch_strlen_zero((char *) helper.stream.data)) {
+				char *this = (char *) helper.stream.data;
 				char *next = NULL;
 				char *last = NULL;
-				
+
 				do {
 					if ((next = strchr(this, ';'))) {
 						*next++ = '\0';
-						while(*next == '\n' || *next == ' ' || *next == '\r') {
+						while (*next == '\n' || *next == ' ' || *next == '\r') {
 							*next++ = '\0';
 						}
 					}
-					
+
 					if (!switch_strlen_zero(this) && (!last || strcmp(last, this))) {
 						sofia_glue_execute_sql(profile, &this, SWITCH_FALSE);
 						last = this;
@@ -516,7 +492,7 @@
 	}
 	switch_mutex_unlock(mod_sofia_globals.hash_mutex);
 
-done:
+  done:
 	switch_safe_free(sql);
 	switch_safe_free(user);
 }
@@ -543,10 +519,10 @@
 	}
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Event Thread Started\n");
-	
+
 	while (mod_sofia_globals.running == 1) {
 		int count = 0;
-		
+
 		if (switch_queue_trypop(mod_sofia_globals.presence_queue, &pop) == SWITCH_STATUS_SUCCESS) {
 			switch_event_t *event = (switch_event_t *) pop;
 
@@ -580,7 +556,7 @@
 		switch_event_t *event = (switch_event_t *) pop;
 		switch_event_destroy(&event);
 	}
-	
+
 	while (switch_queue_trypop(mod_sofia_globals.mwi_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
 		switch_event_t *event = (switch_event_t *) pop;
 		switch_event_destroy(&event);
@@ -592,7 +568,7 @@
 	mod_sofia_globals.threads--;
 	EVENT_THREAD_RUNNING = EVENT_THREAD_STARTED = 0;
 	switch_mutex_unlock(mod_sofia_globals.mutex);
-	
+
 	return NULL;
 }
 
@@ -728,7 +704,7 @@
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "astate", "%s", state);
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-direction", "%s", direction);
 		}
-		
+
 		switch_event_fire(&event);
 	}
 
@@ -738,7 +714,7 @@
 static char *translate_rpid(char *in)
 {
 	char *r = in;
-	
+
 	if (in && (strstr(in, "null") || strstr(in, "NULL"))) {
 		in = NULL;
 	}
@@ -762,7 +738,7 @@
 		r = "busy";
 	}
 
- end:
+  end:
 	return r;
 }
 
@@ -792,17 +768,17 @@
 	char *prpid;
 	int done = 0;
 	const char *ct = "no/idea";
-	time_t exptime = switch_timestamp(NULL) + 3600; 
-	char exp[80] = "";   
+	time_t exptime = switch_timestamp(NULL) + 3600;
+	char exp[80] = "";
 	int is_dialog = 0;
 
-	if (expires) { 
-		long tmp = atol(expires); 
-		if (tmp > 0) { 
-			exptime = tmp - switch_timestamp(NULL); 
+	if (expires) {
+		long tmp = atol(expires);
+		if (tmp > 0) {
+			exptime = tmp - switch_timestamp(NULL);
 		}
 	}
-	
+
 	if (!(nh = nua_handle_by_call_id(profile->nua, call_id))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Cannot find handle for %s\n", call_id);
 		return 0;
@@ -817,7 +793,7 @@
 	if (in < 0) {
 		done = 1;
 		in = 0;
-	} 
+	}
 
 	if (!strcasecmp(proto, SOFIA_CHAT_PROTO)) {
 		clean_id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host);
@@ -838,7 +814,7 @@
 	to = switch_mprintf("sip:%s@%s", user, host);
 
 	is_dialog = !strcmp(event, "dialog");
-	
+
 	if (helper->event) {
 		switch_stream_handle_t stream = { 0 };
 		const char *direction = switch_str_nil(switch_event_get_header(helper->event, "call-direction"));
@@ -854,7 +830,7 @@
 		const char *clean_to_user = NULL;
 		const char *clean_from_user = NULL;
 
-		
+
 		if (is_dialog) {
 			SWITCH_STANDARD_STREAM(stream);
 		}
@@ -866,43 +842,43 @@
 			direction = "initiator";
 			dft_state = "confirmed";
 		}
-		
+
 		if (!strcasecmp(state, "cs_execute") && !strstr(event_status, "hold")) {
 			goto end;
-		} 
-		
+		}
+
 		if (!strcasecmp(event_status, "Registered")) {
 			answer_state = "resubscribe";
 		}
 
 		if (is_dialog) {
-			stream.write_function(&stream, 
+			stream.write_function(&stream,
 								  "<?xml version=\"1.0\"?>\n"
 								  "<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\" "
-								  "version=\"%s\" state=\"%s\" entity=\"%s\">\n", 
+								  "version=\"%s\" state=\"%s\" entity=\"%s\">\n",
 								  switch_str_nil(switch_event_get_header(helper->event, "event_count")),
 								  !strcasecmp(answer_state, "resubscribe") ? "partial" : "full", clean_id);
 		}
-		
+
 		if (strcasecmp(answer_state, "resubscribe")) {
 
 			if (!strcasecmp(state, "cs_hangup")) {
 				astate = "terminated";
-			} else if (switch_strlen_zero(astate))  {
+			} else if (switch_strlen_zero(astate)) {
 				astate = switch_str_nil(switch_event_get_header(helper->event, "answer-state"));
-				if (switch_strlen_zero(astate))  {
+				if (switch_strlen_zero(astate)) {
 					astate = dft_state;
 				}
-			} 
-			
+			}
+
 			if (!strcasecmp(event_status, "hold")) {
 				astate = "early";
 			}
-			
+
 			if (!strcasecmp(astate, "answered")) {
 				astate = "confirmed";
 			}
-			
+
 			if (!strcasecmp(astate, "ringing")) {
 				if (!strcasecmp(direction, "recipient")) {
 					astate = "early";
@@ -915,7 +891,7 @@
 				stream.write_function(&stream, "<state>%s</state>\n", astate);
 			}
 			if (!strcasecmp(astate, "early") || !strcasecmp(astate, "confirmed")) {
-				
+
 				clean_to_user = switch_mprintf("%s", sub_to_user ? sub_to_user : to_user);
 				clean_from_user = switch_mprintf("%s", from_id ? from_id : from_user);
 
@@ -923,24 +899,26 @@
 					if (!switch_strlen_zero(clean_to_user) && !switch_strlen_zero(clean_from_user)) {
 						stream.write_function(&stream, "<local>\n<identity display=\"%s\">sip:%s@%s</identity>\n", clean_to_user, clean_to_user, host);
 						stream.write_function(&stream, "<target uri=\"sip:%s@%s\">\n", clean_to_user, host);
-						stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"%s\"/>\n", !strcasecmp(event_status, "hold") ? "no" : "yes" );
-						stream.write_function(&stream, "</target>\n</local>\n");  
-						stream.write_function(&stream, "<remote>\n<identity display=\"%s\">sip:%s@%s</identity>\n", clean_from_user, clean_from_user, host);
+						stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"%s\"/>\n",
+											  !strcasecmp(event_status, "hold") ? "no" : "yes");
+						stream.write_function(&stream, "</target>\n</local>\n");
+						stream.write_function(&stream, "<remote>\n<identity display=\"%s\">sip:%s@%s</identity>\n", clean_from_user, clean_from_user,
+											  host);
 						stream.write_function(&stream, "<target uri=\"sip:**%s@%s\"/>\n", clean_to_user, host);
 						stream.write_function(&stream, "</remote>\n");
 					} else if (!strcasecmp(proto, "park")) {
-						stream.write_function(&stream, "<local>\n<identity display=\"parking\">sip:parking@%s;fifo=%s</identity>\n", 
+						stream.write_function(&stream, "<local>\n<identity display=\"parking\">sip:parking@%s;fifo=%s</identity>\n",
 											  host, !switch_strlen_zero(clean_to_user) ? clean_to_user : "unknown");
 						stream.write_function(&stream, "<target uri=\"sip:parking@%s\">\n", host);
-						stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"no\"/>\n</target>\n</local>\n");  
+						stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"no\"/>\n</target>\n</local>\n");
 						stream.write_function(&stream, "<remote>\n<identity display=\"parking\">sip:%s</identity>\n", uuid);
 						stream.write_function(&stream, "<target uri=\"sip:park+%s\"/>\n", uuid);
 						stream.write_function(&stream, "</remote>\n");
 					} else if (!strcasecmp(proto, "conf")) {
-						stream.write_function(&stream, "<local>\n<identity display=\"conference\">sip:conference@%s;conference=%s</identity>\n", 
+						stream.write_function(&stream, "<local>\n<identity display=\"conference\">sip:conference@%s;conference=%s</identity>\n",
 											  host, !switch_strlen_zero(clean_to_user) ? clean_to_user : "unknown");
 						stream.write_function(&stream, "<target uri=\"sip:conference@%s\">\n", host);
-						stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"yes\"/>\n</target>\n</local>\n");  
+						stream.write_function(&stream, "<param pname=\"+sip.rendering\" pvalue=\"yes\"/>\n</target>\n</local>\n");
 						stream.write_function(&stream, "<remote>\n<identity display=\"conference\">sip:%s@%s</identity>\n", uuid, host);
 						stream.write_function(&stream, "<target uri=\"sip:conf+%s@%s\"/>\n", uuid, host);
 						stream.write_function(&stream, "</remote>\n");
@@ -948,7 +926,7 @@
 				}
 			}
 			if (is_dialog) {
-				stream.write_function(&stream, "</dialog>\n");			
+				stream.write_function(&stream, "</dialog>\n");
 			}
 		}
 
@@ -957,10 +935,10 @@
 			pl = stream.data;
 			ct = "application/dialog-info+xml";
 		}
-		
+
 		if (!switch_strlen_zero(astate) && !switch_strlen_zero(uuid) && helper && helper->stream.data && strcmp(helper->last_uuid, uuid)) {
 			helper->stream.write_function(&helper->stream, "update sip_dialogs set state='%s' where uuid='%s';", astate, uuid);
-			
+
 			switch_copy_string(helper->last_uuid, uuid, sizeof(helper->last_uuid));
 		}
 
@@ -968,7 +946,7 @@
 		if (!is_dialog) {
 			if (in) {
 				char status_line[256] = "";
-				
+
 				if (!strcmp(astate, "early")) {
 					switch_snprintf(status_line, sizeof(status_line), "R %s", switch_str_nil(from_id));
 					rpid = "on-the-phone";
@@ -976,8 +954,8 @@
 					char *dest = switch_event_get_header(helper->event, "Caller-Destination-Number");
 					if (switch_strlen_zero(from_id) && !switch_strlen_zero(dest)) {
 						from_id = dest;
-					} 
-					
+					}
+
 					if (switch_strlen_zero(from_id)) {
 						switch_snprintf(status_line, sizeof(status_line), "Available");
 					} else {
@@ -994,7 +972,7 @@
 				note = NULL;
 				open = "closed";
 			}
-			
+
 			prpid = translate_rpid(rpid);
 			pl = switch_mprintf("<?xml version='1.0' encoding='UTF-8'?>\r\n"
 								"<presence xmlns='urn:ietf:params:xml:ns:pidf'\r\n"
@@ -1017,11 +995,8 @@
 								"</status>\r\n"
 								"</tuple>\r\n"
 								"<dm:person id='p06360c4a'>\r\n"
-								"<rpid:activities>\r\n" "<rpid:%s/>\r\n" 
-								"</rpid:activities>%s</dm:person>\r\n" 
-								"</presence>", id, 
-								id, profile->url, open, status, prpid,
-								open, rpid, note);
+								"<rpid:activities>\r\n" "<rpid:%s/>\r\n"
+								"</rpid:activities>%s</dm:person>\r\n" "</presence>", id, id, profile->url, open, status, prpid, open, rpid, note);
 			ct = "application/pidf+xml";
 		}
 
@@ -1055,21 +1030,16 @@
 							"</status>\r\n"
 							"</tuple>\r\n"
 							"<dm:person id='p06360c4a'>\r\n"
-							"<rpid:activities>\r\n" "<rpid:%s/>\r\n" 
-							"</rpid:activities>%s</dm:person>\r\n" 
-							"</presence>", id, 
-							id, profile->url, open, status, prpid,
-							open, rpid, note);
+							"<rpid:activities>\r\n" "<rpid:%s/>\r\n"
+							"</rpid:activities>%s</dm:person>\r\n" "</presence>", id, id, profile->url, open, status, prpid, open, rpid, note);
 		ct = "application/pidf+xml";
 	}
 
-	switch_snprintf(exp, sizeof(exp), "active;expires=%ld", (long) exptime); 
+	switch_snprintf(exp, sizeof(exp), "active;expires=%ld", (long) exptime);
 	nua_handle_bind(nh, &mod_sofia_globals.keep_private);
-	nua_notify(nh,
-			   SIPTAG_SUBSCRIPTION_STATE_STR(exp),
-			   SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR(ct), SIPTAG_PAYLOAD_STR(pl), TAG_END());
+	nua_notify(nh, SIPTAG_SUBSCRIPTION_STATE_STR(exp), SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR(ct), SIPTAG_PAYLOAD_STR(pl), TAG_END());
 
- end:
+  end:
 
 	switch_safe_free(id);
 	switch_safe_free(clean_id);
@@ -1101,15 +1071,15 @@
 	int expire_sec = atoi(expires);
 	//int *total = (int *) pArg;
 	struct mwi_helper *h = (struct mwi_helper *) pArg;
-	
-	
+
+
 	if (!(nh = nua_handle_by_call_id(h->profile->nua, call_id))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find handle for %s\n", call_id);
 		return 0;
 	}
 
 	id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host);
-	expire_sec = (int)(expire_sec - switch_timestamp(NULL));
+	expire_sec = (int) (expire_sec - switch_timestamp(NULL));
 	if (expire_sec < 0) {
 		expire_sec = 3600;
 	}
@@ -1118,7 +1088,7 @@
 	nua_notify(nh,
 			   SIPTAG_SUBSCRIPTION_STATE_STR(exp),
 			   SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END());
-	
+
 	switch_safe_free(id);
 	switch_safe_free(exp);
 
@@ -1139,33 +1109,29 @@
 	char *id = NULL;
 	nua_handle_t *nh;
 	struct mwi_helper *h = (struct mwi_helper *) pArg;
-	
-	
+
+
 	id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host);
 
 	contact = sofia_glue_get_url_from_contact(o_contact, 1);
-	
-	nh = nua_handle(h->profile->nua, NULL,
-					NUTAG_URL(contact),
-					SIPTAG_FROM_STR(id),
-					SIPTAG_TO_STR(id),
-					SIPTAG_CONTACT_STR(h->profile->url),
-					TAG_END());
-	
+
+	nh = nua_handle(h->profile->nua, NULL, NUTAG_URL(contact), SIPTAG_FROM_STR(id), SIPTAG_TO_STR(id), SIPTAG_CONTACT_STR(h->profile->url), TAG_END());
+
 	nua_notify(nh,
 			   NUTAG_NEWSUB(1),
 			   TAG_IF(strstr(o_contact, ";nat"), NUTAG_PROXY(contact)),
 			   SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END());
-	
+
 	switch_safe_free(contact);
 	switch_safe_free(id);
-	
+
 	return 0;
 }
 
 void sofia_presence_handle_sip_i_subscribe(int status,
-							char const *phrase,
-							nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
+										   char const *phrase,
+										   nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+										   tagi_t tags[])
 {
 	if (sip) {
 		long exp, exp_raw;
@@ -1205,15 +1171,14 @@
 		get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) my_addrinfo->ai_addr)->sin_addr);
 		network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port);
 
-		tl_gets(tags,
-				NUTAG_SUBSTATE_REF(sub_state), TAG_END());
+		tl_gets(tags, NUTAG_SUBSTATE_REF(sub_state), TAG_END());
 
 		event = sip_header_as_string(profile->home, (void *) sip->sip_event);
 
 		port = (char *) contact->m_url->url_port;
 		contact_host = sip->sip_contact->m_url->url_host;
 		contact_user = sip->sip_contact->m_url->url_user;
-			
+
 		display = contact->m_display;
 
 		if (switch_strlen_zero(display)) {
@@ -1226,12 +1191,12 @@
 		} else {
 			display = "\"user\"";
 		}
-			
+
 		if ((profile->pflags & PFLAG_AGGRESSIVE_NAT_DETECTION)) {
 			if (sip && sip->sip_via) {
 				const char *v_port = sip->sip_via->v_port;
 				const char *v_host = sip->sip_via->v_host;
-					
+
 				if (v_host && sip->sip_via->v_received) {
 					is_nat = "via received";
 				} else if (v_host && strcmp(network_ip, v_host)) {
@@ -1241,27 +1206,27 @@
 				}
 			}
 		}
-			
+
 		if (!is_nat && profile->nat_acl_count) {
 			uint32_t x = 0;
 			int ok = 1;
 			char *last_acl = NULL;
-				
+
 			if (!switch_strlen_zero(contact_host)) {
-				for (x = 0 ; x < profile->nat_acl_count; x++) {
+				for (x = 0; x < profile->nat_acl_count; x++) {
 					last_acl = profile->nat_acl[x];
 					if (!(ok = switch_check_network_list_ip(contact_host, last_acl))) {
 						break;
 					}
 				}
-					
+
 				if (ok) {
 					is_nat = last_acl;
 				}
 			}
 		}
-			
-			
+
+
 		if (is_nat) {
 			contact_host = network_ip;
 			switch_snprintf(new_port, sizeof(new_port), ":%d", network_port);
@@ -1272,14 +1237,14 @@
 		if (port) {
 			switch_snprintf(new_port, sizeof(new_port), ":%s", port);
 		}
-			
+
 		if (contact->m_url->url_params) {
 			contact_str = switch_mprintf("%s <sip:%s@%s%s;%s>%s",
 										 display, contact->m_url->url_user, contact_host, new_port, contact->m_url->url_params, is_nat ? ";nat" : "");
 		} else {
 			contact_str = switch_mprintf("%s <sip:%s@%s%s>%s", display, contact->m_url->url_user, contact_host, new_port, is_nat ? ";nat" : "");
 		}
-		
+
 
 		if (to) {
 			to_str = switch_mprintf("sip:%s@%s", to->a_url->url_user, to->a_url->url_host);	//, to->a_url->url_port);
@@ -1306,7 +1271,7 @@
 			if ((p = strchr(protocol, '+'))) {
 				*p = '\0';
 			}
-			
+
 			if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
 				switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "proto", protocol);
 				switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "login", "%s", profile->name);
@@ -1315,7 +1280,7 @@
 				switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "status", "Click To Call");
 				switch_event_fire(&sevent);
 			}
-		
+
 		} else {
 			if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
 				switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
@@ -1358,12 +1323,7 @@
 		} else {
 			sql = switch_mprintf("delete from sip_subscriptions where "
 								 "proto='%q' and sip_user='%q' and sip_host='%q' and sub_to_user='%q' and sub_to_host='%q' and event='%q'",
-								 proto,
-								 from_user,
-								 from_host,
-								 to_user,
-								 to_host, event
-								 );
+								 proto, from_user, from_host, to_user, to_host, event);
 		}
 
 
@@ -1377,34 +1337,30 @@
 			sip_accept_t *ap = sip->sip_accept;
 			char accept[256] = "";
 			full_agent = sip_header_as_string(profile->home, (void *) sip->sip_user_agent);
-			while(ap) {
+			while (ap) {
 				switch_snprintf(accept + strlen(accept), sizeof(accept) - strlen(accept), "%s%s ", ap->ac_type, ap->ac_next ? "," : "");
 				ap = ap->ac_next;
 			}
 			sql = switch_mprintf("insert into sip_subscriptions values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld,'%q','%q')",
-								 proto, from_user, from_host, to_user, to_host, event, 
-								 contact_str, call_id, full_from, full_via, exp, full_agent, accept);
-			
+								 proto, from_user, from_host, to_user, to_host, event, contact_str, call_id, full_from, full_via, exp, full_agent, accept);
+
 			switch_assert(sql != NULL);
 			sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 
 			sstr = switch_mprintf("active;expires=%ld", exp_raw);
 		}
-	
+
 		switch_mutex_unlock(profile->ireg_mutex);
 
 
 		if (status < 200) {
 			char *sticky = NULL;
-			
+
 			if (is_nat) {
 				sticky = switch_mprintf("sip:%s@%s:%d", contact_user, network_ip, network_port);
 			}
 
-			nua_respond(nh, SIP_202_ACCEPTED,						
-						NUTAG_WITH_THIS(nua),
-						SIPTAG_SUBSCRIPTION_STATE_STR(sstr), 
-						TAG_IF(sticky, NUTAG_PROXY(sticky)),
+			nua_respond(nh, SIP_202_ACCEPTED, NUTAG_WITH_THIS(nua), SIPTAG_SUBSCRIPTION_STATE_STR(sstr), TAG_IF(sticky, NUTAG_PROXY(sticky)),
 						//SIPTAG_FROM(sip->sip_to),
 						//SIPTAG_TO(sip->sip_from),
 						//SIPTAG_CONTACT_STR(contact_str),
@@ -1413,32 +1369,26 @@
 			switch_safe_free(sticky);
 
 		}
-		
+
 		sent_reply++;
 
 #if 0
 
-		nua_notify(nh, 
+		nua_notify(nh,
 				   NUTAG_NEWSUB(1),
-				   SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_EVENT_STR(event), 
+				   SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_EVENT_STR(event),
 				   SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"),
-				   SIPTAG_PAYLOAD_STR("Note: Come to ClueCon http://www.cluecon.com\n\n"),
-				   TAG_END());
+				   SIPTAG_PAYLOAD_STR("Note: Come to ClueCon http://www.cluecon.com\n\n"), TAG_END());
 #endif
 
 		switch_safe_free(sstr);
 
 		if ((sql = switch_mprintf("select * from sip_subscriptions where sip_user='%q' and sip_host='%q'", to_user, to_host))) {
-			sofia_glue_execute_sql_callback(profile,
-											SWITCH_FALSE,
-											profile->ireg_mutex,
-											sql,
-											sofia_presence_sub_reg_callback,
-											profile);
+			sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, sql, sofia_presence_sub_reg_callback, profile);
 
 			switch_safe_free(sql);
 		}
-	end:
+	  end:
 
 		if (event) {
 			su_free(profile->home, event);
@@ -1466,13 +1416,15 @@
 }
 
 void sofia_presence_handle_sip_r_subscribe(int status,
-							char const *phrase,
-							nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
+										   char const *phrase,
+										   nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+										   tagi_t tags[])
 {
 
 }
 
-void sofia_presence_handle_sip_i_publish(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
+void sofia_presence_handle_sip_i_publish(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+										 tagi_t tags[])
 {
 	if (sip) {
 		sip_from_t const *from = sip->sip_from;
@@ -1573,8 +1525,9 @@
 }
 
 void sofia_presence_handle_sip_i_message(int status,
-						  char const *phrase,
-						  nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
+										 char const *phrase,
+										 nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+										 tagi_t tags[])
 {
 	if (sip) {
 		sip_from_t const *from = sip->sip_from;
@@ -1692,7 +1645,7 @@
 
 	if (sofia_reg_find_reg_url(tech_pvt->profile, sip->sip_from->a_url->url_user, sip->sip_from->a_url->url_host, buf, sizeof(buf))) {
 		home = su_home_new(sizeof(*home));
-		switch_assert(home != NULL);		
+		switch_assert(home != NULL);
 		tech_pvt->chat_from = sip_header_as_string(home, (const sip_header_t *) sip->sip_to);
 		tech_pvt->chat_to = switch_core_session_strdup(tech_pvt->session, buf);
 		sofia_presence_set_hash_key(hash_key, sizeof(hash_key), sip);
@@ -1706,6 +1659,7 @@
 	switch_core_hash_insert(tech_pvt->profile->chat_hash, tech_pvt->hash_key, tech_pvt);
 
 }
+
 /* For Emacs:
  * Local Variables:
  * mode:c

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	Tue May 27 00:54:52 2008
@@ -38,21 +38,21 @@
 
 static void sofia_reg_kill_reg(sofia_gateway_t *gateway_ptr, int unreg)
 {
-    if (gateway_ptr->nh) {
-        if (unreg) {
-            nua_unregister(gateway_ptr->nh,
-                           NUTAG_URL(gateway_ptr->register_url),
-                           SIPTAG_FROM_STR(gateway_ptr->register_from),
-                           SIPTAG_TO_STR(gateway_ptr->register_from),
-                           SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
-                           SIPTAG_EXPIRES_STR(gateway_ptr->expires_str),
-                           NUTAG_REGISTRAR(gateway_ptr->register_proxy),
-                           NUTAG_OUTBOUND("no-options-keepalive"), NUTAG_OUTBOUND("no-validate"), NUTAG_KEEPALIVE(0), TAG_NULL());
-        }
-        nua_handle_bind(gateway_ptr->nh, NULL);
-        nua_handle_destroy(gateway_ptr->nh);
-        gateway_ptr->nh = NULL;
-    }
+	if (gateway_ptr->nh) {
+		if (unreg) {
+			nua_unregister(gateway_ptr->nh,
+						   NUTAG_URL(gateway_ptr->register_url),
+						   SIPTAG_FROM_STR(gateway_ptr->register_from),
+						   SIPTAG_TO_STR(gateway_ptr->register_from),
+						   SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
+						   SIPTAG_EXPIRES_STR(gateway_ptr->expires_str),
+						   NUTAG_REGISTRAR(gateway_ptr->register_proxy),
+						   NUTAG_OUTBOUND("no-options-keepalive"), NUTAG_OUTBOUND("no-validate"), NUTAG_KEEPALIVE(0), TAG_NULL());
+		}
+		nua_handle_bind(gateway_ptr->nh, NULL);
+		nua_handle_destroy(gateway_ptr->nh);
+		gateway_ptr->nh = NULL;
+	}
 
 }
 
@@ -64,7 +64,7 @@
 			free(gateway_ptr->sofia_private);
 			gateway_ptr->sofia_private = NULL;
 		}
-        sofia_reg_kill_reg(gateway_ptr, 1);
+		sofia_reg_kill_reg(gateway_ptr, 1);
 	}
 }
 
@@ -94,7 +94,7 @@
 			gateway_ptr->pinging = 1;
 			nua_options(nh, TAG_END());
 		}
-		
+
 		switch (ostate) {
 		case REG_STATE_NOREG:
 			gateway_ptr->status = SOFIA_GATEWAY_UP;
@@ -107,12 +107,12 @@
 			break;
 
 		case REG_STATE_UNREGISTER:
-            sofia_reg_kill_reg(gateway_ptr, 1);
+			sofia_reg_kill_reg(gateway_ptr, 1);
 			gateway_ptr->state = REG_STATE_NOREG;
 			break;
 		case REG_STATE_UNREGED:
 			gateway_ptr->status = SOFIA_GATEWAY_DOWN;
-            sofia_reg_kill_reg(gateway_ptr, 1);
+			sofia_reg_kill_reg(gateway_ptr, 1);
 
 			if ((gateway_ptr->nh = nua_handle(gateway_ptr->profile->nua, NULL,
 											  NUTAG_URL(gateway_ptr->register_proxy),
@@ -120,10 +120,10 @@
 											  NUTAG_CALLSTATE_REF(ss_state), SIPTAG_FROM_STR(gateway_ptr->register_from), TAG_END()))) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "registering %s\n", gateway_ptr->name);
 
-                if (!gateway_ptr->sofia_private) {
-                    gateway_ptr->sofia_private = malloc(sizeof(*gateway_ptr->sofia_private));
-                    switch_assert(gateway_ptr->sofia_private);
-                }
+				if (!gateway_ptr->sofia_private) {
+					gateway_ptr->sofia_private = malloc(sizeof(*gateway_ptr->sofia_private));
+					switch_assert(gateway_ptr->sofia_private);
+				}
 				memset(gateway_ptr->sofia_private, 0, sizeof(*gateway_ptr->sofia_private));
 
 				gateway_ptr->sofia_private->gateway = gateway_ptr;
@@ -159,7 +159,7 @@
 			break;
 
 		case REG_STATE_FAILED:
-            sofia_reg_kill_reg(gateway_ptr, 0);
+			sofia_reg_kill_reg(gateway_ptr, 0);
 			gateway_ptr->status = SOFIA_GATEWAY_DOWN;
 		case REG_STATE_TRYING:
 			if (gateway_ptr->retry && now >= gateway_ptr->retry) {
@@ -201,7 +201,7 @@
 	nua_options(nh, TAG_END());
 
 	switch_safe_free(contact);
-	
+
 	return 0;
 }
 
@@ -242,15 +242,10 @@
 {
 	char sql[1024];
 	char *psql = sql;
-	
+
 	switch_snprintf(sql, sizeof(sql), "select *,'%s' from sip_registrations where call_id='%s'", profile->name, call_id);
 	switch_mutex_lock(profile->ireg_mutex);
-	sofia_glue_execute_sql_callback(profile,
-									SWITCH_TRUE,
-									NULL,
-									sql,
-									sofia_reg_del_callback,
-									NULL);
+	sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_reg_del_callback, NULL);
 	switch_mutex_unlock(profile->ireg_mutex);
 
 	switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where call_id='%s'", call_id);
@@ -262,19 +257,19 @@
 	char sql[1024];
 
 #ifdef SWITCH_HAVE_ODBC
-    if (profile->odbc_dsn) {
-     	if (!profile->master_odbc) {
+	if (profile->odbc_dsn) {
+		if (!profile->master_odbc) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
 			return;
-		}   
-    } else {
+		}
+	} else {
 #endif
 		if (!profile->master_db) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
 			return;
 		}
 #ifdef SWITCH_HAVE_ODBC
-    }
+	}
 #endif
 
 
@@ -286,12 +281,7 @@
 		switch_snprintf(sql, sizeof(sql), "select *,'%s' from sip_registrations where expires > 0", profile->name);
 	}
 
-	sofia_glue_execute_sql_callback(profile,
-									SWITCH_TRUE,
-									NULL,
-									sql,
-									sofia_reg_del_callback,
-									NULL);
+	sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_reg_del_callback, NULL);
 	if (now) {
 		switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and expires <= %ld", (long) now);
 	} else {
@@ -299,7 +289,7 @@
 	}
 
 	sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, NULL);
-	
+
 	if (now) {
 		switch_snprintf(sql, sizeof(sql), "delete from sip_authentication where expires > 0 and expires <= %ld", (long) now);
 	} else {
@@ -307,7 +297,7 @@
 	}
 
 	sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, NULL);
-	
+
 
 
 	if (now) {
@@ -316,12 +306,7 @@
 		switch_snprintf(sql, sizeof(sql), "select call_id from sip_subscriptions where expires > 0");
 	}
 
-	sofia_glue_execute_sql_callback(profile,
-									SWITCH_TRUE,
-									NULL,
-									sql,
-									sofia_sub_del_callback,
-									profile);
+	sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_sub_del_callback, profile);
 
 	if (now) {
 		switch_snprintf(sql, sizeof(sql), "delete from sip_subscriptions where expires > 0 and expires <= %ld", (long) now);
@@ -330,16 +315,11 @@
 	}
 
 	sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, NULL);
-	
+
 
 	if (now) {
 		switch_snprintf(sql, sizeof(sql), "select * from sip_registrations where status like '%%AUTO-NAT%%'");
-		sofia_glue_execute_sql_callback(profile,
-										SWITCH_TRUE,
-										NULL,
-										sql,
-										sofia_reg_nat_callback,
-										profile);
+		sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_reg_nat_callback, profile);
 	}
 
 	switch_mutex_unlock(profile->ireg_mutex);
@@ -365,12 +345,7 @@
 	}
 
 
-	sofia_glue_execute_sql_callback(profile,
-									SWITCH_FALSE,
-									profile->ireg_mutex,
-									val,
-									sofia_reg_find_callback,
-									&cbt);
+	sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile->ireg_mutex, val, sofia_reg_find_callback, &cbt);
 
 
 	if (cbt.matches) {
@@ -390,30 +365,24 @@
 	switch_uuid_get(&uuid);
 	switch_uuid_format(uuid_str, &uuid);
 
-	sql = switch_mprintf("insert into sip_authentication (nonce, expires) values('%q', %ld)",
-						 uuid_str, switch_timestamp(NULL) + profile->nonce_ttl);
+	sql = switch_mprintf("insert into sip_authentication (nonce, expires) values('%q', %ld)", uuid_str, switch_timestamp(NULL) + profile->nonce_ttl);
 	switch_assert(sql != NULL);
 	sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
 	switch_safe_free(sql);
 	//sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 
-	auth_str =
-		switch_mprintf("Digest realm=\"%q\", nonce=\"%q\",%s algorithm=MD5, qop=\"auth\"", realm, uuid_str, stale ? " stale=\"true\"," : "");
+	auth_str = switch_mprintf("Digest realm=\"%q\", nonce=\"%q\",%s algorithm=MD5, qop=\"auth\"", realm, uuid_str, stale ? " stale=\"true\"," : "");
 
 	if (regtype == REG_REGISTER) {
-		nua_respond(nh, 
-					SIP_401_UNAUTHORIZED, 
-					TAG_IF(nua, NUTAG_WITH_THIS(nua)), SIPTAG_WWW_AUTHENTICATE_STR(auth_str), TAG_END());
+		nua_respond(nh, SIP_401_UNAUTHORIZED, TAG_IF(nua, NUTAG_WITH_THIS(nua)), SIPTAG_WWW_AUTHENTICATE_STR(auth_str), TAG_END());
 	} else if (regtype == REG_INVITE) {
-		nua_respond(nh, 
-					SIP_407_PROXY_AUTH_REQUIRED, 
-					TAG_IF(nua, NUTAG_WITH_THIS(nua)), SIPTAG_PROXY_AUTHENTICATE_STR(auth_str), TAG_END());
+		nua_respond(nh, SIP_407_PROXY_AUTH_REQUIRED, TAG_IF(nua, NUTAG_WITH_THIS(nua)), SIPTAG_PROXY_AUTHENTICATE_STR(auth_str), TAG_END());
 	}
 
 	switch_safe_free(auth_str);
 }
 
-uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh, sip_t const *sip, sofia_regtype_t regtype, char *key,
+uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sip_t const *sip, sofia_regtype_t regtype, char *key,
 								  uint32_t keylen, switch_event_t **v_event, const char *is_nat)
 {
 	sip_to_t const *to = NULL;
@@ -446,7 +415,7 @@
 
 	get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_addr);
 	network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port);
-	
+
 	expires = sip->sip_expires;
 	authorization = sip->sip_authorization;
 	contact = sip->sip_contact;
@@ -468,14 +437,14 @@
 		char new_port[25] = "";
 		const char *contact_host = contact->m_url->url_host;
 		display = contact->m_display;
-		
+
 		if (is_nat) {
 			reg_desc = "Registered(AUTO-NAT)";
 			contact_host = network_ip;
 			switch_snprintf(new_port, sizeof(new_port), ":%d", network_port);
 			port = NULL;
 		}
-		
+
 		if (switch_strlen_zero(display)) {
 			if (to) {
 				display = to->a_display;
@@ -495,13 +464,10 @@
 
 		if (contact->m_url->url_params) {
 			switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s%s;%s>%s%s",
-							display, contact->m_url->url_user, contact_host, new_port, contact->m_url->url_params, 
-							received_data,
-							is_nat ? ";nat" : "");
+							display, contact->m_url->url_user, contact_host, new_port, contact->m_url->url_params, received_data, is_nat ? ";nat" : "");
 		} else {
-			switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s%s>%s%s", display, contact->m_url->url_user, contact_host, new_port, 
-							received_data,
-							is_nat ? ";nat" : "");
+			switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s%s>%s%s", display, contact->m_url->url_user, contact_host, new_port,
+							received_data, is_nat ? ";nat" : "");
 		}
 	}
 
@@ -524,37 +490,38 @@
 
 	if (authorization) {
 		char *v_contact_str;
-		if ((auth_res = sofia_reg_parse_auth(profile, authorization, sip, sip->sip_request->rq_method_name, 
+		if ((auth_res = sofia_reg_parse_auth(profile, authorization, sip, sip->sip_request->rq_method_name,
 											 key, keylen, network_ip, v_event, exptime, regtype, to_user)) == AUTH_STALE) {
 			stale = 1;
 		}
-		
+
 		if (exptime && v_event && *v_event) {
 			char *exp_var;
 
 			register_gateway = switch_event_get_header(*v_event, "sip-register-gateway");
-	
+
 			/* Allow us to force the SIP user to be something specific - needed if 
 			 * we - for example - want to be able to ensure that the username a UA can
 			 * be contacted at is the same one that they used for authentication.
-			 */ 
+			 */
 			if ((force_user = switch_event_get_header(*v_event, "sip-force-user"))) {
 				to_user = force_user;
 			}
-			
+
 			if ((v_contact_str = switch_event_get_header(*v_event, "sip-force-contact"))) {
 
 				if (*received_data && (profile->pflags & PFLAG_RECIEVED_IN_NAT_REG_CONTACT)) {
 					switch_snprintf(received_data, sizeof(received_data), ";received=\"%s:%d\"", network_ip, network_port);
 				}
 
-				if (!strcasecmp(v_contact_str, "nat-connectile-dysfunction") || 
+				if (!strcasecmp(v_contact_str, "nat-connectile-dysfunction") ||
 					!strcasecmp(v_contact_str, "NDLB-connectile-dysfunction") || !strcasecmp(v_contact_str, "NDLB-tls-connectile-dysfunction")) {
 					if (contact->m_url->url_params) {
 						switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d;%s>%s;nat",
 										display, contact->m_url->url_user, network_ip, network_port, contact->m_url->url_params, received_data);
 					} else {
-						switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d>%s;nat", display, contact->m_url->url_user, network_ip, network_port, received_data);
+						switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d>%s;nat", display, contact->m_url->url_user, network_ip,
+										network_port, received_data);
 					}
 					if (strstr(v_contact_str, "tls")) {
 						reg_desc = "Registered(TLSHACK)";
@@ -566,14 +533,14 @@
 				} else {
 					char *p;
 					switch_copy_string(contact_str, v_contact_str, sizeof(contact_str));
-					for(p = contact_str; p && *p; p++) {
+					for (p = contact_str; p && *p; p++) {
 						if (*p == '\'' || *p == '[' || *p == ']') {
 							*p = '"';
 						}
 					}
 				}
 			}
-			
+
 			if ((exp_var = switch_event_get_header(*v_event, "sip-force-expires"))) {
 				int tmp = atoi(exp_var);
 				if (tmp > 0) {
@@ -585,13 +552,9 @@
 		if (auth_res != AUTH_OK && !stale) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "send %s for [%s@%s]\n", forbidden ? "forbidden" : "challange", to_user, to_host);
 			if (auth_res == AUTH_FORBIDDEN) {
-				nua_respond(nh, 
-							SIP_403_FORBIDDEN, 
-							NUTAG_WITH_THIS(nua), TAG_END());
+				nua_respond(nh, SIP_403_FORBIDDEN, NUTAG_WITH_THIS(nua), TAG_END());
 			} else {
-				nua_respond(nh, 
-							SIP_401_UNAUTHORIZED, 
-							NUTAG_WITH_THIS(nua), TAG_END());
+				nua_respond(nh, SIP_401_UNAUTHORIZED, NUTAG_WITH_THIS(nua), TAG_END());
 			}
 			return 1;
 		}
@@ -604,13 +567,13 @@
 		}
 		return 1;
 	}
- reg:
+  reg:
 
 	if (regtype != REG_REGISTER) {
 		return 0;
 	}
 
-	call_id = sip->sip_call_id->i_id; //sip_header_as_string(profile->home, (void *) sip->sip_call_id);
+	call_id = sip->sip_call_id->i_id;	//sip_header_as_string(profile->home, (void *) sip->sip_call_id);
 	switch_assert(call_id);
 
 	if (exptime) {
@@ -627,10 +590,9 @@
 		}
 		switch_mutex_lock(profile->ireg_mutex);
 		sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
-		
+
 		sql = switch_mprintf("insert into sip_registrations values ('%q', '%q','%q','%q','%q', '%q', %ld, '%q')", call_id,
-							 to_user, to_host, contact_str, reg_desc,
-							 rpid, (long) switch_timestamp(NULL) + (long) exptime * 2, agent);
+							 to_user, to_host, contact_str, reg_desc, rpid, (long) switch_timestamp(NULL) + (long) exptime * 2, agent);
 		if (sql) {
 			sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 		}
@@ -647,7 +609,7 @@
 			switch_event_fire(&s_event);
 		}
 
-		
+
 
 		if (profile->debug) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
@@ -676,7 +638,7 @@
 			if ((sql = switch_mprintf("delete from sip_subscriptions where call_id='%q'", call_id))) {
 				sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 			}
-			
+
 			if ((sql = switch_mprintf("delete from sip_registrations where call_id='%q'", call_id))) {
 				sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 			}
@@ -685,7 +647,7 @@
 			if ((sql = switch_mprintf("delete from sip_subscriptions where sip_user='%q' and sip_host='%q'", to_user, to_host))) {
 				sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 			}
-			
+
 			if ((sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q'", to_user, to_host))) {
 				sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
 			}
@@ -709,22 +671,22 @@
 		switch_event_fire(&event);
 	}
 
-	
+
 	/*
-	  if (call_id) {
-	  su_free(profile->home, call_id);
-	  }
-	*/
+	   if (call_id) {
+	   su_free(profile->home, call_id);
+	   }
+	 */
 
 	if (regtype == REG_REGISTER) {
 		char *new_contact = NULL;
 		char new_port[30] = "";
 		char exp_param[128] = "";
-		
+
 		if (exptime) {
 			switch_snprintf(exp_param, sizeof(exp_param), ";expires=%ld", exptime);
 		}
-			
+
 
 		if (contact->m_url->url_port) {
 			switch_snprintf(new_port, sizeof(new_port), ":%s", contact->m_url->url_port);
@@ -732,17 +694,12 @@
 
 		if (contact->m_url->url_params) {
 			new_contact = switch_mprintf("%s <sip:%s@%s%s;%s>%s",
-										 display, contact->m_url->url_user, contact->m_url->url_host, new_port, contact->m_url->url_params,
-										 exp_param);
+										 display, contact->m_url->url_user, contact->m_url->url_host, new_port, contact->m_url->url_params, exp_param);
 		} else {
-			new_contact = switch_mprintf("%s <sip:%s@%s%s>%s",
-										 display, contact->m_url->url_user, contact->m_url->url_host, new_port,
-										 exp_param);
-		}
-			
-		nua_respond(nh,
-					SIP_200_OK, 
-					SIPTAG_CONTACT_STR(new_contact), NUTAG_WITH_THIS(nua), TAG_END());
+			new_contact = switch_mprintf("%s <sip:%s@%s%s>%s", display, contact->m_url->url_user, contact->m_url->url_host, new_port, exp_param);
+		}
+
+		nua_respond(nh, SIP_200_OK, SIPTAG_CONTACT_STR(new_contact), NUTAG_WITH_THIS(nua), TAG_END());
 		switch_safe_free(new_contact);
 
 		if (exptime) {
@@ -763,7 +720,7 @@
 				}
 			}
 		}
-		
+
 
 		return 1;
 	}
@@ -773,7 +730,8 @@
 
 
 
-void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
+void sofia_reg_handle_sip_i_register(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+									 tagi_t tags[])
 {
 	char key[128] = "";
 	switch_event_t *v_event = NULL;
@@ -785,7 +743,7 @@
 
 	get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) my_addrinfo->ai_addr)->sin_addr);
 	network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port);
-	
+
 
 	if (!(sip->sip_contact && sip->sip_contact->m_url)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO CONTACT!\n");
@@ -794,9 +752,7 @@
 	}
 
 	if (!(profile->mflags & MFLAG_REGISTER)) {
-		nua_respond(nh, 
-					SIP_403_FORBIDDEN, 
-					NUTAG_WITH_THIS(nua), TAG_END());
+		nua_respond(nh, SIP_403_FORBIDDEN, NUTAG_WITH_THIS(nua), TAG_END());
 		goto end;
 	}
 
@@ -804,7 +760,7 @@
 		if (sip && sip->sip_via) {
 			const char *port = sip->sip_via->v_port;
 			const char *host = sip->sip_via->v_host;
-			
+
 			if (host && sip->sip_via->v_received) {
 				is_nat = "via received";
 			} else if (host && strcmp(network_ip, host)) {
@@ -826,13 +782,13 @@
 		}
 
 		if (!switch_strlen_zero(contact_host)) {
-			for (x = 0 ; x < profile->nat_acl_count; x++) {
+			for (x = 0; x < profile->nat_acl_count; x++) {
 				last_acl = profile->nat_acl[x];
 				if (!(ok = switch_check_network_list_ip(contact_host, last_acl))) {
 					break;
 				}
 			}
-			
+
 			if (ok) {
 				is_nat = last_acl;
 			}
@@ -844,29 +800,25 @@
 		int ok = 1;
 		char *last_acl = NULL;
 
-		for (x = 0 ; x < profile->reg_acl_count; x++) {
+		for (x = 0; x < profile->reg_acl_count; x++) {
 			last_acl = profile->reg_acl[x];
 			if (!(ok = switch_check_network_list_ip(network_ip, last_acl))) {
 				break;
 			}
 		}
-		
+
 		if (ok && !(profile->pflags & PFLAG_BLIND_REG)) {
 			type = REG_AUTO_REGISTER;
 		} else if (!ok) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "IP %s Rejected by acl %s\n", network_ip,  profile->reg_acl[x]);
-			nua_respond(nh, 
-						SIP_403_FORBIDDEN, 
-						NUTAG_WITH_THIS(nua), TAG_END());
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "IP %s Rejected by acl %s\n", network_ip, profile->reg_acl[x]);
+			nua_respond(nh, SIP_403_FORBIDDEN, NUTAG_WITH_THIS(nua), TAG_END());
 			goto end;
 		}
 	}
-	
+
 	if (!sip || !sip->sip_request || !sip->sip_request->rq_method_name) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received an invalid packet!\n");
-		nua_respond(nh, 
-					SIP_500_INTERNAL_SERVER_ERROR, 
-					TAG_END());
+		nua_respond(nh, SIP_500_INTERNAL_SERVER_ERROR, TAG_END());
 		goto end;
 	}
 
@@ -876,7 +828,7 @@
 		switch_event_fire(&v_event);
 	}
 
- end:	
+  end:
 
 	nua_handle_destroy(nh);
 
@@ -885,7 +837,8 @@
 
 void sofia_reg_handle_sip_r_register(int status,
 									 char const *phrase,
-									 nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh, sofia_private_t * sofia_private, sip_t const *sip, tagi_t tags[])
+									 nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
+									 tagi_t tags[])
 {
 	if (sofia_private && sofia_private->gateway) {
 		switch (status) {
@@ -915,7 +868,7 @@
 
 void sofia_reg_handle_sip_r_challenge(int status,
 									  char const *phrase,
-									  nua_t * nua, sofia_profile_t *profile, nua_handle_t * nh, 
+									  nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh,
 									  switch_core_session_t *session, sofia_gateway_t *gateway, sip_t const *sip, tagi_t tags[])
 {
 	sip_www_authenticate_t const *authenticate = NULL;
@@ -976,17 +929,17 @@
 
 	return;
 
- cancel:
+  cancel:
 
 	if (session) {
 		switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_MANDATORY_IE_MISSING);
 	} else {
 		nua_cancel(nh, TAG_END());
 	}
-	
+
 }
 
-auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization, sip_t const *sip, const char *regstr, 
+auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization, sip_t const *sip, const char *regstr,
 								char *np, size_t nplen, char *ip, switch_event_t **v_event, long exptime, sofia_regtype_t regtype, const char *to_user)
 {
 	int indexnum;
@@ -1001,13 +954,13 @@
 	const char *a1_hash = NULL;
 	char *sql;
 	char *mailbox = NULL;
-	switch_xml_t domain, xml = NULL, user, param, uparams, dparams;	
+	switch_xml_t domain, xml = NULL, user, param, uparams, dparams;
 	char hexdigest[2 * SU_MD5_DIGEST_SIZE + 1] = "";
 	char *domain_name = NULL;
 	switch_event_t *params = NULL;
 
 	username = realm = nonce = uri = qop = cnonce = nc = response = NULL;
-	
+
 	if (authorization->au_params) {
 		for (indexnum = 0; (cur = authorization->au_params[indexnum]); indexnum++) {
 			char *var, *val, *p, *work;
@@ -1052,7 +1005,7 @@
 		ret = AUTH_STALE;
 		goto end;
 	}
-	
+
 	/* Optional check that auth name == SIP username */
 	if ((regtype == REG_REGISTER) && (profile->pflags & PFLAG_CHECKUSER)) {
 		if (switch_strlen_zero(username) || switch_strlen_zero(to_user) || strcasecmp(to_user, username)) {
@@ -1072,44 +1025,45 @@
 			goto end;
 		}
 		free(sql);
-	} 
-	
+	}
+
 	switch_event_create(&params, SWITCH_EVENT_MESSAGE);
 	switch_assert(params);
 	switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "action", "sip_auth");
 	switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_profile", profile->name);
-	switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_user_agent", (sip && sip->sip_user_agent) ? sip->sip_user_agent->g_string : "unknown");
+	switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_user_agent",
+								   (sip && sip->sip_user_agent) ? sip->sip_user_agent->g_string : "unknown");
 	switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_username", username);
 	switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_realm", realm);
 	switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_nonce", nonce);
 	switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_uri", uri);
-    if (qop) {
-        switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_qop", qop);
-    }
-    if (cnonce) {
-        switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_cnonce", cnonce);
-    }
-    if (nc) {
-        switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_nc", nc);
-    }
+	if (qop) {
+		switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_qop", qop);
+	}
+	if (cnonce) {
+		switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_cnonce", cnonce);
+	}
+	if (nc) {
+		switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_nc", nc);
+	}
 	switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_response", response);
 
 	switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "sip_auth_method", (sip && sip->sip_request) ? sip->sip_request->rq_method_name : NULL);
 
-	
+
 	if (!switch_strlen_zero(profile->reg_domain)) {
 		domain_name = profile->reg_domain;
 	} else {
 		domain_name = realm;
 	}
-	
+
 	if (switch_xml_locate_user("id", username, domain_name, ip, &xml, &domain, &user, params) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", username, domain_name);
 		ret = AUTH_FORBIDDEN;
 		goto end;
 	}
 
-	if (!(mailbox = (char *)switch_xml_attr(user, "mailbox"))) {
+	if (!(mailbox = (char *) switch_xml_attr(user, "mailbox"))) {
 		mailbox = username;
 	}
 
@@ -1125,11 +1079,11 @@
 		for (param = switch_xml_child(dparams, "param"); param; param = param->next) {
 			const char *var = switch_xml_attr_soft(param, "name");
 			const char *val = switch_xml_attr_soft(param, "value");
-			
+
 			if (!strcasecmp(var, "password")) {
 				passwd = val;
 			}
-			
+
 			if (!strcasecmp(var, "a1-hash")) {
 				a1_hash = val;
 			}
@@ -1140,11 +1094,11 @@
 		for (param = switch_xml_child(uparams, "param"); param; param = param->next) {
 			const char *var = switch_xml_attr_soft(param, "name");
 			const char *val = switch_xml_attr_soft(param, "value");
-			
+
 			if (!strcasecmp(var, "password")) {
 				passwd = val;
 			}
-			
+
 			if (!strcasecmp(var, "a1-hash")) {
 				a1_hash = val;
 			}
@@ -1164,10 +1118,10 @@
 		su_md5_deinit(&ctx);
 		switch_safe_free(input);
 		a1_hash = hexdigest;
-			
+
 	}
 
- for_the_sake_of_interop:
+  for_the_sake_of_interop:
 
 	if ((input = switch_mprintf("%s:%q", regstr, uri))) {
 		su_md5_init(&ctx);
@@ -1176,38 +1130,38 @@
 		su_md5_deinit(&ctx);
 	}
 
-    if (nc && cnonce && qop) {
-        input2 = switch_mprintf("%q:%q:%q:%q:%q:%q", a1_hash, nonce, nc, cnonce, qop, uridigest);
-    } else {
-        input2 = switch_mprintf("%q:%q:%q", a1_hash, nonce, uridigest);
-    }
-
-    switch_assert(input2);
-
-    memset(&ctx, 0, sizeof(ctx));
-    su_md5_init(&ctx);
-    su_md5_strupdate(&ctx, input2);
-    su_md5_hexdigest(&ctx, bigdigest);
-    su_md5_deinit(&ctx);
-
-    if (!strcasecmp(bigdigest, response)) {
-        ret = AUTH_OK;
-    } else {
-        if ((profile->ndlb & PFLAG_NDLB_BROKEN_AUTH_HASH) && strcasecmp(regstr, "REGISTER") && strcasecmp(regstr, "INVITE")) {
-            /* some clients send an ACK with the method 'INVITE' in the hash which will break auth so we will
-               try again with INVITE so we don't get people complaining to us when someone else's client has a bug......
-            */
-            switch_safe_free(input);
-            switch_safe_free(input2);
-            regstr = "INVITE";
-            goto for_the_sake_of_interop;
-        }
-
-        ret = AUTH_FORBIDDEN;
-    }
-        
+	if (nc && cnonce && qop) {
+		input2 = switch_mprintf("%q:%q:%q:%q:%q:%q", a1_hash, nonce, nc, cnonce, qop, uridigest);
+	} else {
+		input2 = switch_mprintf("%q:%q:%q", a1_hash, nonce, uridigest);
+	}
 
- skip_auth:
+	switch_assert(input2);
+
+	memset(&ctx, 0, sizeof(ctx));
+	su_md5_init(&ctx);
+	su_md5_strupdate(&ctx, input2);
+	su_md5_hexdigest(&ctx, bigdigest);
+	su_md5_deinit(&ctx);
+
+	if (!strcasecmp(bigdigest, response)) {
+		ret = AUTH_OK;
+	} else {
+		if ((profile->ndlb & PFLAG_NDLB_BROKEN_AUTH_HASH) && strcasecmp(regstr, "REGISTER") && strcasecmp(regstr, "INVITE")) {
+			/* some clients send an ACK with the method 'INVITE' in the hash which will break auth so we will
+			   try again with INVITE so we don't get people complaining to us when someone else's client has a bug......
+			 */
+			switch_safe_free(input);
+			switch_safe_free(input2);
+			regstr = "INVITE";
+			goto for_the_sake_of_interop;
+		}
+
+		ret = AUTH_FORBIDDEN;
+	}
+
+
+  skip_auth:
 
 	if (first && ret == AUTH_OK) {
 		if (v_event) {
@@ -1223,7 +1177,7 @@
 			switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "mailbox", "%s", mailbox);
 			switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "user_name", "%s", username);
 			switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, "domain_name", "%s", realm);
-			
+
 			if ((dparams = switch_xml_child(domain, "variables"))) {
 				xparams[i++] = dparams;
 			}
@@ -1243,7 +1197,7 @@
 
 						if (!switch_strlen_zero(var) && !switch_strlen_zero(val)) {
 							switch_event_add_header(*v_event, SWITCH_STACK_BOTTOM, var, "%s", val);
-						
+
 							if (!strcasecmp(var, "register-gateway")) {
 								if (!strcasecmp(val, "all")) {
 									switch_xml_t gateways_tag, gateway_tag;
@@ -1253,7 +1207,7 @@
 											if (switch_strlen_zero(name)) {
 												name = "anonymous";
 											}
-									
+
 											if ((gateway_ptr = sofia_reg_find_gateway(name))) {
 												gateway_ptr->retry = 0;
 												if (exptime) {
@@ -1263,7 +1217,7 @@
 												}
 												sofia_reg_release_gateway(gateway_ptr);
 											}
-	
+
 										}
 									}
 								} else {
@@ -1272,11 +1226,11 @@
 
 									mydata = strdup(val);
 									switch_assert(mydata != NULL);
-								
+
 									argc = switch_separate_string(mydata, ',', argv, (sizeof(argv) / sizeof(argv[0])));
 
 									for (x = 0; x < argc; x++) {
-										if ((gateway_ptr = sofia_reg_find_gateway((char *)argv[x]))) {
+										if ((gateway_ptr = sofia_reg_find_gateway((char *) argv[x]))) {
 											gateway_ptr->retry = 0;
 											if (exptime) {
 												gateway_ptr->state = REG_STATE_UNREGED;
@@ -1298,7 +1252,7 @@
 			}
 		}
 	}
- end:
+  end:
 
 	switch_event_destroy(&params);
 
@@ -1329,7 +1283,7 @@
 	switch_mutex_lock(mod_sofia_globals.hash_mutex);
 	if ((gateway = (sofia_gateway_t *) switch_core_hash_find(mod_sofia_globals.gateway_hash, key))) {
 		if (!(gateway->profile->pflags & PFLAG_RUNNING)) {
-			gateway =  NULL;
+			gateway = NULL;
 			goto done;
 		}
 		if (switch_thread_rwlock_tryrdlock(gateway->profile->rwlock) != SWITCH_STATUS_SUCCESS) {
@@ -1343,7 +1297,7 @@
 #endif
 	}
 
- done:
+  done:
 	switch_mutex_unlock(mod_sofia_globals.hash_mutex);
 	return gateway;
 }

Modified: freeswitch/trunk/src/mod/endpoints/mod_wanpipe/lib_api.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_wanpipe/lib_api.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_wanpipe/lib_api.c	Tue May 27 00:54:52 2008
@@ -39,16 +39,16 @@
 #define RANGE_CHANNEL	0x1
 
 
-char	read_enable=0;
-char 	write_enable=0;
-char 	primary_enable=0;
-int 	tx_cnt=1;
-int	rx_cnt=0;
-int	tx_size=10;
-int	tx_delay=0;
-int	tx_data=-1;
-int	tx_ss7_type=0;
-int	rx_ss7_timer=0;
+char read_enable = 0;
+char write_enable = 0;
+char primary_enable = 0;
+int tx_cnt = 1;
+int rx_cnt = 0;
+int tx_size = 10;
+int tx_delay = 0;
+int tx_data = -1;
+int tx_ss7_type = 0;
+int rx_ss7_timer = 0;
 
 unsigned char card_name[WAN_IFNAME_SZ];
 unsigned char if_name[WAN_IFNAME_SZ];
@@ -63,343 +63,343 @@
 unsigned char saddr[TX_ADDR_STR_SZ];
 unsigned char udata[TX_ADDR_STR_SZ];
 
-int	files_used=0;
-int	verbose=0;
+int files_used = 0;
+int verbose = 0;
 
-int	tx_connections;
+int tx_connections;
 
-int	ds_prot=0;
-int	ds_prot_opt=0;
-int	ds_max_mult_cnt=0;
-unsigned int ds_active_ch=0;
-int	ds_7bit_hdlc=0;
-int 	direction=-1;
-
-int 	tx_channels=1;
-int	cause=0;
-int 	diagn=0;
+int ds_prot = 0;
+int ds_prot_opt = 0;
+int ds_max_mult_cnt = 0;
+unsigned int ds_active_ch = 0;
+int ds_7bit_hdlc = 0;
+int direction = -1;
+
+int tx_channels = 1;
+int cause = 0;
+int diagn = 0;
 
-int 	card_cnt=0;
-int 	i_cnt=0;
+int card_cnt = 0;
+int i_cnt = 0;
 
-unsigned long parse_active_channel(char* val);
+unsigned long parse_active_channel(char *val);
 
 int init_args(int argc, char *argv[])
 {
 	int i;
-	int c_cnt=0;
+	int c_cnt = 0;
 
-	sprintf(daddr,"111");
-	sprintf(saddr,"222");
-	sprintf(udata,"C9");
-	
-	for (i = 0; i < argc; i++){
-		
-		if (!strcmp(argv[i],"-i")){
+	sprintf(daddr, "111");
+	sprintf(saddr, "222");
+	sprintf(udata, "C9");
 
-			if (i+1 > argc-1){
+	for (i = 0; i < argc; i++) {
+
+		if (!strcmp(argv[i], "-i")) {
+
+			if (i + 1 > argc - 1) {
 				printf("ERROR: Invalid Interface Name!\n");
 				return WAN_FALSE;
 			}
 
-			strncpy(if_name, argv[i+1],WAN_IFNAME_SZ);
-			i_c