[Freeswitch-trunk] [commit] r6349 - in freeswitch/trunk/src: include mod/endpoints/mod_sofia

Freeswitch SVN mikej at freeswitch.org
Mon Nov 19 21:27:49 EST 2007


Author: mikej
Date: Mon Nov 19 21:27:48 2007
New Revision: 6349

Modified:
   freeswitch/trunk/src/include/switch_odbc.h
   freeswitch/trunk/src/include/switch_types.h
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c

Log:
re-factor, cleanup ODBC ifdefs, whitespace and comment cleanup.

Modified: freeswitch/trunk/src/include/switch_odbc.h
==============================================================================
--- freeswitch/trunk/src/include/switch_odbc.h	(original)
+++ freeswitch/trunk/src/include/switch_odbc.h	Mon Nov 19 21:27:48 2007
@@ -54,7 +54,6 @@
 	SWITCH_ODBC_STATE_CONNECTED,
 	SWITCH_ODBC_STATE_ERROR
 } switch_odbc_state_t;
-typedef struct switch_odbc_handle switch_odbc_handle_t;
 
 typedef enum {
 	SWITCH_ODBC_SUCCESS = 0,

Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h	(original)
+++ freeswitch/trunk/src/include/switch_types.h	Mon Nov 19 21:27:48 2007
@@ -1047,7 +1047,7 @@
 typedef struct switch_codec_implementation switch_codec_implementation_t;
 typedef struct switch_buffer switch_buffer_t;
 typedef struct switch_codec_settings switch_codec_settings_t;
-
+typedef struct switch_odbc_handle switch_odbc_handle_t;
 
 typedef struct switch_io_routines switch_io_routines_t;
 typedef struct switch_speech_handle switch_speech_handle_t;

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	Mon Nov 19 21:27:48 2007
@@ -254,17 +254,10 @@
 	uint32_t session_timeout;
 	uint32_t max_proceeding;
 	uint32_t rtp_timeout_sec;
-#ifdef SWITCH_HAVE_ODBC
 	char *odbc_dsn;
 	char *odbc_user;
 	char *odbc_pass;
 	switch_odbc_handle_t *master_odbc;
-#else
-	void *filler1;
-	void *filler2;
-	void *filler3;
-	void *filler4;
-#endif
 };
 
 struct private_object {

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	Mon Nov 19 21:27:48 2007
@@ -67,7 +67,6 @@
 		}
 	}
 
-
 	if (!sr) {
 		sr = "sendrecv";
 	}
@@ -182,7 +181,6 @@
 		snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=ptime:%d\n", ptime);
 	}
 
-
 	if (switch_test_flag(tech_pvt, TFLAG_VIDEO) && tech_pvt->video_rm_encoding) {
 		sofia_glue_tech_choose_video_port(tech_pvt);
 		if ((v_port = tech_pvt->adv_sdp_video_port)) {
@@ -190,7 +188,6 @@
 			
 			sofia_glue_tech_set_video_codec(tech_pvt, 0);	
 
-
 			/*****************************/
 			if (tech_pvt->video_rm_encoding) {
 				snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %d", tech_pvt->video_pt);
@@ -208,7 +205,6 @@
 						if (already_did[imp->ianacode]) {
 							continue;
 						}
-
 						already_did[imp->ianacode] = 1;
 					}
 					
@@ -241,15 +237,13 @@
 						if (already_did[imp->ianacode]) {
 							continue;
 						}
-						
 						already_did[imp->ianacode] = 1;
 					}
 					
 					if (!rate) {
 						rate = imp->samples_per_second;
 					}
-			
-				
+
 					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) {
 						snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=fmtp:%d %s\n", imp->ianacode, imp->fmtp);
@@ -258,7 +252,6 @@
 			}
 		}
 	}
-	/*****************************/
 
 	tech_pvt->local_sdp_str = switch_core_session_strdup(tech_pvt->session, buf);
 }
@@ -278,7 +271,6 @@
 
 	assert(tech_pvt->session != NULL);
 
-
 	if ((abs = switch_channel_get_variable(tech_pvt->channel, "absolute_codec_string"))) {
 		codec_string = abs;
 	} else {
@@ -308,14 +300,10 @@
 		}
 	} else {
 		tech_pvt->num_codecs =
-			switch_loadable_module_get_codecs(tech_pvt->codecs,
-											  sizeof(tech_pvt->codecs) / sizeof(tech_pvt->codecs[0]));
+			switch_loadable_module_get_codecs(tech_pvt->codecs, sizeof(tech_pvt->codecs) / sizeof(tech_pvt->codecs[0]));
 	}
-
  end:
-
 	sofia_glue_check_video_codecs(tech_pvt);
-
 }
 
 void sofia_glue_check_video_codecs(private_object_t *tech_pvt) 
@@ -345,7 +333,6 @@
 
 	switch_core_session_add_stream(session, NULL);
 
-
 	switch_mutex_lock(tech_pvt->flag_mutex);
 	switch_mutex_lock(profile->flag_mutex);
 	tech_pvt->flags = profile->flags;
@@ -373,8 +360,6 @@
 
 	snprintf(name, sizeof(name), "sofia/%s/%s", profile->name, channame);
 	switch_channel_set_name(tech_pvt->channel, name);
-	//sofia_glue_tech_prepare_codecs(tech_pvt);
-
 }
 
 switch_status_t sofia_glue_ext_address_lookup(char **ip, switch_port_t *port, char *sourceip, switch_memory_pool_t *pool)
@@ -402,14 +387,12 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-
 switch_status_t sofia_glue_tech_choose_port(private_object_t *tech_pvt)
 {
 	char *ip = tech_pvt->profile->rtpip;
 	switch_port_t sdp_port;
 	char tmp[50];
 
-
 	if (switch_channel_test_flag(tech_pvt->channel, CF_BYPASS_MEDIA) || tech_pvt->adv_sdp_audio_port) {
 		return SWITCH_STATUS_SUCCESS;
 	}
@@ -432,24 +415,19 @@
 	switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_MEDIA_IP_VARIABLE, tech_pvt->adv_sdp_audio_ip);
 	switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_MEDIA_PORT_VARIABLE, tmp);
 
-
 	return SWITCH_STATUS_SUCCESS;
 }
 
-
-
 switch_status_t sofia_glue_tech_choose_video_port(private_object_t *tech_pvt)
 {
 	char *ip = tech_pvt->profile->rtpip;
 	switch_port_t sdp_port;
 	char tmp[50];
 
-
 	if (switch_channel_test_flag(tech_pvt->channel, CF_BYPASS_MEDIA) || tech_pvt->adv_sdp_video_port) {
 		return SWITCH_STATUS_SUCCESS;
 	}
 
-	
 	tech_pvt->local_sdp_video_port = switch_rtp_request_port();
 	sdp_port = tech_pvt->local_sdp_video_port;
 
@@ -466,7 +444,6 @@
 	switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_VIDEO_IP_VARIABLE, tech_pvt->adv_sdp_audio_ip);
 	switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_VIDEO_PORT_VARIABLE, tmp);
 
-
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -497,7 +474,6 @@
 	return new_uri;
 }
 
-
 switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
 {
 	char *rpid = NULL;
@@ -544,11 +520,8 @@
 														 cid_num,
 														 !switch_strlen_zero(cid_num) ? "@" : "",
 														 tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip);
-
 	}
 
-	assert(tech_pvt->from_str != NULL);
-	
 	if ((alertbuf = switch_channel_get_variable(channel, "alert_info"))) {
 		alert_info = switch_core_session_sprintf(tech_pvt->session, "Alert-Info: %s", alertbuf);
 	}
@@ -566,7 +539,7 @@
 
 	switch_set_flag_locked(tech_pvt, TFLAG_READY);
 
-	// forge a RPID for now KHR  -- Should wrap this in an if statement so it can be turned on and off
+	/* 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_SCREEN)) {
 		const char *priv = "off";
 		const char *screen = "no";
@@ -652,7 +625,6 @@
 		tech_pvt->sofia_private = sofia_private;
 		switch_copy_string(tech_pvt->sofia_private->uuid, switch_core_session_get_uuid(session), sizeof(tech_pvt->sofia_private->uuid));
 		nua_handle_bind(tech_pvt->nh, tech_pvt->sofia_private);
-
 	}
 
 	if (tech_pvt->e_dest) {
@@ -691,7 +663,6 @@
 				const char *hname = name + strlen(SOFIA_SIP_HEADER_PREFIX);
 				stream.write_function(&stream, "%s: %s\r\n", hname, value);
 			}
-			
 		}
 		switch_channel_variable_last(channel);
 	}
@@ -717,16 +688,11 @@
 			   SOATAG_RTP_SORT(SOA_RTP_SORT_REMOTE),
 			   SOATAG_RTP_SELECT(SOA_RTP_SELECT_ALL), TAG_IF(rep, SIPTAG_REPLACES_STR(rep)), SOATAG_HOLD(holdstr), TAG_END());
 
-
-
 	switch_safe_free(stream.data);
 
 	return SWITCH_STATUS_SUCCESS;
-
 }
 
-
-
 void sofia_glue_do_xfer_invite(switch_core_session_t *session)
 {
 	private_object_t *tech_pvt;
@@ -741,20 +707,19 @@
 
 	caller_profile = switch_channel_get_caller_profile(channel);
 
-
-
 	if ((tech_pvt->from_str = switch_core_session_sprintf(session, "\"%s\" <sip:%s@%s>",
-														  (char *) caller_profile->caller_id_name,
-														  (char *) caller_profile->caller_id_number,
+														  caller_profile->caller_id_name,
+														  caller_profile->caller_id_number,
 														  tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip))) {
 
 		const char *rep = switch_channel_get_variable(channel, SOFIA_REPLACES_HEADER);
 
 		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),
+								   SIPTAG_TO_STR(tech_pvt->dest),
+								   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);
 
 		nua_invite(tech_pvt->nh2,
@@ -764,7 +729,6 @@
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
 	}
-
 }
 
 void sofia_glue_tech_absorb_sdp(private_object_t *tech_pvt)
@@ -833,14 +797,12 @@
 							  tech_pvt->video_read_codec.implementation->iananame, tech_pvt->video_rm_encoding);
 			switch_core_codec_destroy(&tech_pvt->video_read_codec);
 			switch_core_codec_destroy(&tech_pvt->video_write_codec);
-			//switch_core_session_reset(tech_pvt->session);
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Already using %s\n", tech_pvt->video_read_codec.implementation->iananame);
 			return SWITCH_STATUS_SUCCESS;
 		}
 	}
 
-
 	if (!tech_pvt->video_rm_encoding) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec with no name?\n");
 		return SWITCH_STATUS_FALSE;
@@ -851,7 +813,6 @@
 							   tech_pvt->video_rm_fmtp,
 							   tech_pvt->video_rm_rate,
 							   0,
-							   //tech_pvt->video_codec_ms,
 							   1,
 							   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
 							   NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
@@ -862,7 +823,7 @@
 								   tech_pvt->video_rm_encoding,
 								   tech_pvt->video_rm_fmtp,
 								   tech_pvt->video_rm_rate,
-								   0,//tech_pvt->video_codec_ms,
+								   0,
 								   1,
 								   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
 								   NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
@@ -876,8 +837,6 @@
 							  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;
 			
-			//switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec);
-			//switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec);
 			tech_pvt->fmtp_out = switch_core_session_strdup(tech_pvt->session, tech_pvt->video_write_codec.fmtp_out);
 		}
 	}
@@ -949,10 +908,6 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-
-
-
-
 switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_flag_t myflags)
 {
 	int bw, ms;
@@ -1010,7 +965,9 @@
 					  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);
 
 	snprintf(tmp, sizeof(tmp), "%d", tech_pvt->remote_sdp_audio_port);
 	switch_channel_set_variable(tech_pvt->channel, SWITCH_LOCAL_MEDIA_IP_VARIABLE, tech_pvt->adv_sdp_audio_ip);
@@ -1086,7 +1043,6 @@
 			}
 		}
 
-
 		if ((val = switch_channel_get_variable(tech_pvt->channel, "rtp_timeout_sec"))) {
 			int v = atoi(val);
 			if (v >= 0) {
@@ -1120,28 +1076,25 @@
 													 tech_pvt->remote_sdp_video_port,
 													 tech_pvt->video_agreed_pt,
 													 tech_pvt->video_read_codec.implementation->samples_per_frame,
-													 0,//tech_pvt->video_codec_ms * 1000,
+													 0,
 													 (switch_rtp_flag_t) flags,
 													 NULL, 
-													 NULL,//tech_pvt->profile->timer_name, 
+													 NULL,
 													 &err, switch_core_session_get_pool(tech_pvt->session));
-			
-			
+
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "VIDEO RTP [%s] %s:%d->%s:%d codec: %u ms: %d [%s]\n",
 							  switch_channel_get_name(tech_pvt->channel),
 							  tech_pvt->local_sdp_audio_ip,
 							  tech_pvt->local_sdp_video_port,
 							  tech_pvt->remote_sdp_video_ip,
 							  tech_pvt->remote_sdp_video_port, tech_pvt->video_agreed_pt,
-							  0,//tech_pvt->video_read_codec.implementation->microseconds_per_frame / 1000,
+							  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);
 			}
 		}
-
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "RTP REPORTS ERROR: [%s]\n", err);
 		switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
@@ -1272,13 +1225,11 @@
 		}
 	}
 
-
 	for (m = sdp->sdp_media; m; m = m->m_next) {
 		sdp_connection_t *connection;
 
 		ptime = dptime;
 
-
 		if (m->m_type == sdp_media_audio) {
 			sdp_rtpmap_t *map;
 
@@ -1504,7 +1455,6 @@
 				}
 			}
 		}
-		
 	}
 
 	switch_set_flag_locked(tech_pvt, TFLAG_SDP);
@@ -1512,7 +1462,7 @@
 	return match;
 }
 
-// map sip responses to QSIG cause codes ala RFC4497 section 8.4.4
+/* map sip responses to QSIG cause codes ala RFC4497 section 8.4.4 */
 switch_call_cause_t sofia_glue_sip_cause_to_freeswitch(int status)
 {
 	switch (status) {
@@ -1571,21 +1521,17 @@
 		return SWITCH_CAUSE_EXCHANGE_ROUTING_ERROR;
 	case 487:
 		return SWITCH_CAUSE_ORIGINATOR_CANCEL;
-
 	default:
 		return SWITCH_CAUSE_NORMAL_UNSPECIFIED;
-
 	}
 }
 
-
 void sofia_glue_pass_sdp(private_object_t *tech_pvt, char *sdp)
 {
 	const char *val;
 	switch_core_session_t *other_session;
 	switch_channel_t *other_channel;
 
-
 	if ((val = switch_channel_get_variable(tech_pvt->channel, SWITCH_SIGNAL_BOND_VARIABLE))
 		&& (other_session = switch_core_session_locate(val))) {
 		other_channel = switch_core_session_get_channel(other_session);
@@ -1593,18 +1539,15 @@
 		switch_channel_set_variable(other_channel, SWITCH_B_SDP_VARIABLE, sdp);
 
 		if (!switch_test_flag(tech_pvt, TFLAG_CHANGE_MEDIA) && (switch_channel_test_flag(other_channel, CF_OUTBOUND) &&
-																//switch_channel_test_flag(other_channel, CF_BYPASS_MEDIA) && 
 																switch_channel_test_flag(tech_pvt->channel, CF_OUTBOUND) &&
 																switch_channel_test_flag(tech_pvt->channel, CF_BYPASS_MEDIA))) {
 			switch_ivr_nomedia(val, SMF_FORCE);
 			switch_set_flag_locked(tech_pvt, TFLAG_CHANGE_MEDIA);
 		}
-
 		switch_core_session_rwunlock(other_session);
 	}
 }
 
-
 char *sofia_glue_get_url_from_contact(char *buf, uint8_t to_dup)
 {
 	char *url = NULL, *e;
@@ -1624,7 +1567,6 @@
 			url = buf;
 		}
 	}
-
 	return url;
 }
 
@@ -1655,7 +1597,6 @@
 	return profile;
 }
 
-
 void sofia_glue_release_profile__(const char *file, const char *func, int line, sofia_profile_t *profile)
 {
 	if (profile) {
@@ -1713,13 +1654,10 @@
 	}
 
 	switch_mutex_unlock(mod_sofia_globals.hash_mutex);
-
 }
 
 int sofia_glue_init_sql(sofia_profile_t *profile)
 {
-
-	
 	char reg_sql[] =
 		"CREATE TABLE sip_registrations (\n"
 		"   call_id         VARCHAR(255),\n"
@@ -1731,7 +1669,6 @@
 		"   expires         INTEGER" 
 		");\n";
 
-
 	char sub_sql[] =
 		"CREATE TABLE sip_subscriptions (\n"
 		"   proto           VARCHAR(255),\n"
@@ -1754,8 +1691,8 @@
 		"   expires         INTEGER"
 		");\n";
 	
-#ifdef SWITCH_HAVE_ODBC
 	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))) {
 			return 0;
 		}
@@ -1780,8 +1717,10 @@
 			switch_odbc_handle_exec(profile->master_odbc, "DROP TABLE sip_authentication", NULL);
 			switch_odbc_handle_exec(profile->master_odbc, auth_sql, NULL);
 		}
-	} else {
+#else
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
 #endif
+	} else {
 		if (!(profile->master_db = switch_core_db_open_file(profile->dbname))) {
 			return 0;
 		}
@@ -1790,9 +1729,7 @@
 		switch_core_db_test_reactive(profile->master_db, "delete from sip_subscriptions where sip_user != ''", "DROP TABLE sip_subscriptions", sub_sql);
 		switch_core_db_test_reactive(profile->master_db, "select * from sip_authentication", "DROP TABLE sip_authentication", auth_sql);
 
-#ifdef SWITCH_HAVE_ODBC
 	}
-#endif
 
 #ifdef SWITCH_HAVE_ODBC
 	if (profile->odbc_dsn) {
@@ -1801,8 +1738,6 @@
 #endif
 
 	return profile->master_db ? 1: 0;
-
-
 }
 
 void sofia_glue_sql_close(sofia_profile_t *profile)
@@ -1810,13 +1745,12 @@
 #ifdef SWITCH_HAVE_ODBC
     if (profile->odbc_dsn) {
 		switch_odbc_handle_destroy(&profile->master_odbc);
-	} else {
-#endif
-		switch_core_db_close(profile->master_db);
-		profile->master_db = NULL;
-#ifdef SWITCH_HAVE_ODBC
+		return;
 	}
 #endif
+
+	switch_core_db_close(profile->master_db);
+	profile->master_db = NULL;
 }
 
 
@@ -1828,8 +1762,8 @@
 		switch_mutex_lock(mutex);
 	}
 
-#ifdef SWITCH_HAVE_ODBC
     if (profile->odbc_dsn) {
+#ifdef SWITCH_HAVE_ODBC
 		SQLHSTMT stmt;
 		if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
 			char *err_str;
@@ -1838,28 +1772,23 @@
 			switch_safe_free(err_str);
 		}
 		SQLFreeHandle(SQL_HANDLE_STMT, stmt);
-	} else {
+#else
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
 #endif
-
-
-	if (master) {
-		db = profile->master_db;
 	} else {
-		if (!(db = switch_core_db_open_file(profile->dbname))) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
-			goto end;
+		if (master) {
+			db = profile->master_db;
+		} else {
+			if (!(db = switch_core_db_open_file(profile->dbname))) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+				goto end;
+			}
+		}
+		switch_core_db_persistant_execute(db, sql, 25);
+		if (!master) {
+			switch_core_db_close(db);
 		}
-	}
-	switch_core_db_persistant_execute(db, sql, 25);
-	if (!master) {
-		switch_core_db_close(db);
-	}
-
-
-#ifdef SWITCH_HAVE_ODBC
     }
-#endif
-
 
   end:
 	if (mutex) {
@@ -1867,7 +1796,6 @@
 	}
 }
 
-
 switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile,
 											  switch_bool_t master,
 											  switch_mutex_t *mutex,
@@ -1884,48 +1812,40 @@
     }
 
 
-#ifdef SWITCH_HAVE_ODBC
     if (profile->odbc_dsn) {
+#ifdef SWITCH_HAVE_ODBC
 		switch_odbc_handle_callback_exec(profile->master_odbc, sql, callback, pdata);
-	} else {
+#else
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
 #endif
-
-
-	if (master) {
-		db = profile->master_db;
 	} else {
-		if (!(db = switch_core_db_open_file(profile->dbname))) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
-			goto end;
-		}
-	}
-	
-	switch_core_db_exec(db, sql, callback, pdata, &errmsg);
 
-	if (errmsg) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
-		free(errmsg);
-	}
+		if (master) {
+			db = profile->master_db;
+		} else {
+			if (!(db = switch_core_db_open_file(profile->dbname))) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
+				goto end;
+			}
+		}
+		
+		switch_core_db_exec(db, sql, callback, pdata, &errmsg);
 
-	if (!master && db) {
-		switch_core_db_close(db);
-	}
+		if (errmsg) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
+			free(errmsg);
+		}
 
-#ifdef SWITCH_HAVE_ODBC
+		if (!master && db) {
+			switch_core_db_close(db);
+		}
     }
-#endif
-
 
  end:
-
 	if (mutex) {
         switch_mutex_unlock(mutex);
     }
-	
-
-
 	return ret;
-
 }
 
 #ifdef SWITCH_HAVE_ODBC
@@ -1957,7 +1877,6 @@
 
 	return ret;
 }
-
 #endif
 
 char *sofia_glue_execute_sql2str(sofia_profile_t *profile, switch_mutex_t *mutex, char *sql, char *resbuf, size_t len)
@@ -2008,9 +1927,7 @@
 		switch_core_db_finalize(stmt);
 	}
 
-
   fail:
-
 	switch_core_db_close(db);
 
   end:
@@ -2048,5 +1965,4 @@
 	*host = h;
 
 	return 1;
-
 }



More information about the Freeswitch-trunk mailing list