Merge branch 'master' into smgmaster

This commit is contained in:
Moises Silva committed 2010-09-20 12:31:15 -04:00
commit d4232aa8cc
13 files changed
+175 -45

No files matched your search

@@ -4063,7 +4063,7 @@ SWITCH_STANDARD_API(uuid_dump_function)
return SWITCH_STATUS_SUCCESS;
}
#define GLOBAL_SETVAR_SYNTAX "<var> <value> [<value2>]"
#define GLOBAL_SETVAR_SYNTAX "<var>=<value> [=<value2>]"
SWITCH_STANDARD_API(global_setvar_function)
{
char *mycmd = NULL, *argv[3] = { 0 };
@@ -120,6 +120,21 @@ static struct {
int thread_running;
} t38_state_list;
static void wake_thread(int force)
{
if (force) {
switch_thread_cond_signal(globals.cond);
return;
}
if (switch_mutex_trylock(globals.cond_mutex) == SWITCH_STATUS_SUCCESS) {
switch_thread_cond_signal(globals.cond);
switch_mutex_unlock(globals.cond_mutex);
}
}
static int add_pvt(pvt_t *pvt)
{
int r = 0;
@@ -130,7 +145,7 @@ static int add_pvt(pvt_t *pvt)
t38_state_list.head = pvt;
switch_mutex_unlock(t38_state_list.mutex);
r = 1;
switch_thread_cond_broadcast(globals.cond);
wake_thread(0);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error launching thread\n");
}
@@ -165,7 +180,7 @@ static int del_pvt(pvt_t *del_pvt)
switch_mutex_unlock(t38_state_list.mutex);
switch_thread_cond_broadcast(globals.cond);
wake_thread(0);
return r;
}
@@ -1335,7 +1350,7 @@ void mod_spandsp_fax_shutdown(void)
switch_status_t tstatus = SWITCH_STATUS_SUCCESS;
t38_state_list.thread_running = 0;
switch_thread_cond_broadcast(globals.cond);
wake_thread(1);
switch_thread_join(&tstatus, t38_state_list.thread);
memset(&globals, 0, sizeof(globals));
}
+22 -2
View File
@@ -3166,6 +3166,21 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
goto done;
}
if (!strcasecmp(argv[1], "gwlist")) {
int up = 1;
if (argc > 2) {
if (!strcasecmp(argv[2], "down")) {
up = 0;
}
}
sofia_glue_gateway_list(profile, stream, up);
goto done;
}
stream->write_function(stream, "-ERR Unknown command!\n");
done:
@@ -4707,8 +4722,10 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
switch_console_set_complete("add sofia help");
switch_console_set_complete("add sofia status");
switch_console_set_complete("add sofia xmlstatus");
switch_console_set_complete("add sofia loglevel");
switch_console_set_complete("add sofia tracelevel");
switch_console_set_complete("add sofia loglevel ::[all:default:tport:iptsec:nea:nta:nth_client:nth_server:nua:soa:sresolv:stun ::[0:1:2:3:4:5:6:7:8:9");
switch_console_set_complete("add sofia tracelevel ::[console:alert:crit:err:warning:notice:info:debug");
switch_console_set_complete("add sofia profile");
switch_console_set_complete("add sofia profile restart all");
@@ -4724,6 +4741,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
switch_console_set_complete("add sofia profile ::sofia::list_profiles siptrace on");
switch_console_set_complete("add sofia profile ::sofia::list_profiles siptrace off");
switch_console_set_complete("add sofia profile ::sofia::list_profiles gwlist up");
switch_console_set_complete("add sofia profile ::sofia::list_profiles gwlist down");
switch_console_set_complete("add sofia status profile ::sofia::list_profiles");
switch_console_set_complete("add sofia status profile ::sofia::list_profiles reg");
switch_console_set_complete("add sofia status gateway ::sofia::list_gateways");
+1
View File
@@ -942,6 +942,7 @@ switch_status_t sofia_glue_tech_set_video_codec(private_object_t *tech_pvt, int
const char *sofia_glue_strip_proto(const char *uri);
switch_status_t reconfig_sofia(sofia_profile_t *profile);
void sofia_glue_del_gateway(sofia_gateway_t *gp);
void sofia_glue_gateway_list(sofia_profile_t *profile, switch_stream_handle_t *stream, int up);
void sofia_glue_del_every_gateway(sofia_profile_t *profile);
void sofia_reg_send_reboot(sofia_profile_t *profile, const char *user, const char *host, const char *contact, const char *user_agent,
const char *network_ip);
+3 -2
View File
@@ -4109,7 +4109,8 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
}
}
if (tech_pvt && tech_pvt->remote_sdp_str && switch_stristr("m=image", tech_pvt->remote_sdp_str)) {
if (sip->sip_payload && sip->sip_payload->pl_data && switch_stristr("m=image", sip->sip_payload->pl_data)) {
has_t38 = 1;
}
@@ -4164,12 +4165,12 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status
}
if (status == 200 && sofia_test_flag(tech_pvt, TFLAG_T38_PASSTHRU) && has_t38) {
switch_core_session_receive_message(other_session, msg);
if (switch_rtp_ready(tech_pvt->rtp_session) && switch_rtp_ready(other_tech_pvt->rtp_session)) {
switch_rtp_udptl_mode(tech_pvt->rtp_session);
switch_rtp_udptl_mode(other_tech_pvt->rtp_session);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Activating T38 Passthru\n");
}
switch_core_session_receive_message(other_session, msg);
} else {
switch_core_session_queue_message(other_session, msg);
}
+22
View File
@@ -4267,6 +4267,28 @@ void sofia_glue_del_every_gateway(sofia_profile_t *profile)
}
void sofia_glue_gateway_list(sofia_profile_t *profile, switch_stream_handle_t *stream, int up)
{
sofia_gateway_t *gp = NULL;
char *r = (char *) stream->data;
switch_mutex_lock(mod_sofia_globals.hash_mutex);
for (gp = profile->gateways; gp; gp = gp->next) {
int reged = (gp->status == SOFIA_GATEWAY_UP);
if (up ? reged : !reged) {
stream->write_function(stream, "%s ", gp->name);
}
}
if (r) {
end_of(r) = '\0';
}
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
}
void sofia_glue_del_gateway(sofia_gateway_t *gp)
{
if (!gp->deleted) {
+23 -2
View File
@@ -483,9 +483,29 @@ static int comp_callback(void *pArg, int argc, char **argv, char **columnNames)
return -1;
}
if (!zstr(target) && *target == ':' && *(target + 1) == ':' && *(target + 2) == '[') {
char *p = target + 3, *list = NULL;
if (p) {
char *argv[100] = { 0 };
char *r_argv[1] = { 0 }, *r_cols[1] = {0};
list = strdup(p);
argc = switch_separate_string(list, ':', argv, (sizeof(argv) / sizeof(argv[0])));
for (i = 0; i < argc; i++) {
if (!cur || !strncmp(argv[i], cur, strlen(cur))) {
r_argv[0] = argv[i];
comp_callback(h, 1, r_argv, r_cols);
}
}
switch_safe_free(list);
}
return 0;
}
if (!zstr(target) && *target == ':' && *(target + 1) == ':') {
char *r_argv[1] = { 0 }, *r_cols[1] = {
0};
char *r_argv[1] = { 0 }, *r_cols[1] = {0};
switch_console_callback_match_t *matches;
if (switch_console_run_complete_func(target, str, cur, &matches) == SWITCH_STATUS_SUCCESS) {
switch_console_callback_match_node_t *m;
@@ -797,6 +817,7 @@ SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const ch
}
stream.write_function(&stream, " and hostname='%s' order by a%d", switch_core_get_variable("hostname"), h.words + 1);
switch_cache_db_execute_sql_callback(db, stream.data, comp_callback, &h, &errmsg);
if (errmsg) {
+59 -27
View File
@@ -34,6 +34,7 @@
#include <switch.h>
#include "private/switch_core_pvt.h"
//*#define DEBUG_SQL 1
static struct {
switch_cache_db_handle_t *event_db;
@@ -41,7 +42,9 @@ static struct {
switch_memory_pool_t *memory_pool;
switch_event_node_t *event_node;
switch_thread_t *thread;
switch_thread_t *db_thread;
int thread_running;
int db_thread_running;
switch_bool_t manage;
switch_mutex_t *io_mutex;
switch_mutex_t *dbh_mutex;
@@ -464,6 +467,19 @@ static switch_status_t switch_cache_db_execute_sql_real(switch_cache_db_handle_t
return status;
}
static void wake_thread(int force)
{
if (force) {
switch_thread_cond_signal(sql_manager.cond);
return;
}
if (switch_mutex_trylock(sql_manager.cond_mutex) == SWITCH_STATUS_SUCCESS) {
switch_thread_cond_signal(sql_manager.cond);
switch_mutex_unlock(sql_manager.cond_mutex);
}
}
/**
OMFG you cruel bastards. Who chooses 64k as a max buffer len for a sql statement, have you ever heard of transactions?
**/
@@ -846,7 +862,24 @@ SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive(switch_cache_db_hand
}
static void *SWITCH_THREAD_FUNC switch_core_sql_db_thread(switch_thread_t *thread, void *obj)
{
int sec = 0;
sql_manager.db_thread_running = 1;
while (sql_manager.db_thread_running == 1) {
if (++sec == SQL_CACHE_TIMEOUT) {
sql_close(switch_epoch_time_now(NULL));
wake_thread(1);
sec = 0;
}
switch_yield(1000);
}
return NULL;
}
static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread, void *obj)
{
@@ -859,16 +892,10 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
char *sql = NULL;
switch_size_t newlen;
int lc = 0;
uint32_t loops = 0, sec = 0;
uint32_t l1 = 1000;
uint32_t sanity = 120;
switch_assert(sqlbuf);
if (!sql_manager.manage) {
l1 = 10;
}
while (!sql_manager.event_db) {
if (switch_core_db_handle(&sql_manager.event_db) == SWITCH_STATUS_SUCCESS && sql_manager.event_db)
break;
@@ -882,26 +909,12 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
return NULL;
}
sql_manager.thread_running = 1;
while (sql_manager.thread_running == 1) {
switch_mutex_lock(sql_manager.cond_mutex);
if (++loops == l1) {
if (++sec == SQL_CACHE_TIMEOUT) {
sql_close(switch_epoch_time_now(NULL));
sec = 0;
}
loops = 0;
}
if (!sql_manager.manage) {
switch_yield(100000);
continue;
}
if (sql || switch_queue_trypop(sql_manager.sql_queue[0], &pop) == SWITCH_STATUS_SUCCESS ||
switch_queue_trypop(sql_manager.sql_queue[1], &pop) == SWITCH_STATUS_SUCCESS) {
@@ -919,9 +932,11 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
if (new_mlen < runtime.max_sql_buffer_len) {
sql_len = new_mlen;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10,
#ifdef DEBUG_SQL
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"REALLOC %ld %d %d\n", (long int)sql_len, switch_queue_size(sql_manager.sql_queue[0]),
switch_queue_size(sql_manager.sql_queue[1]));
#endif
if (!(tmp = realloc(sqlbuf, sql_len))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL thread ending on mem err\n");
abort();
@@ -929,8 +944,10 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
}
sqlbuf = tmp;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10,
#ifdef DEBUG_SQL
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"SAVE %d %d\n", switch_queue_size(sql_manager.sql_queue[0]), switch_queue_size(sql_manager.sql_queue[1]));
#endif
goto skip;
}
}
@@ -951,12 +968,16 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
lc = sql ? 1 : 0 + switch_queue_size(sql_manager.sql_queue[0]) + switch_queue_size(sql_manager.sql_queue[1]);
if (trans && iterations && (iterations > target || !lc)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10,
#ifdef DEBUG_SQL
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"RUN %d %d %d\n", switch_queue_size(sql_manager.sql_queue[0]), switch_queue_size(sql_manager.sql_queue[1]), iterations);
#endif
if (switch_cache_db_persistant_execute_trans(sql_manager.event_db, sqlbuf, 1) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL thread unable to commit transaction, records lost!\n");
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "DONE\n");
#ifdef DEBUG_SQL
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "DONE\n");
#endif
iterations = 0;
trans = 0;
len = 0;
@@ -965,6 +986,8 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
switch_yield(400000);
}
lc = sql ? 1 : 0 + switch_queue_size(sql_manager.sql_queue[0]) + switch_queue_size(sql_manager.sql_queue[1]);
if (!lc) {
switch_thread_cond_wait(sql_manager.cond, sql_manager.cond_mutex);
}
@@ -1399,7 +1422,7 @@ static void core_event_handler(switch_event_t *event)
switch_queue_push(sql_manager.sql_queue[0], sql[i]);
}
sql[i] = NULL;
switch_thread_cond_broadcast(sql_manager.cond);
wake_thread(1);
}
}
}
@@ -1650,7 +1673,10 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
switch_threadattr_create(&thd_attr, sql_manager.memory_pool);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
switch_thread_create(&sql_manager.thread, thd_attr, switch_core_sql_thread, NULL, sql_manager.memory_pool);
if (sql_manager.manage) {
switch_thread_create(&sql_manager.thread, thd_attr, switch_core_sql_thread, NULL, sql_manager.memory_pool);
}
switch_thread_create(&sql_manager.db_thread, thd_attr, switch_core_sql_db_thread, NULL, sql_manager.memory_pool);
while (!sql_manager.thread_running) {
switch_yield(10000);
@@ -1673,13 +1699,19 @@ void switch_core_sqldb_stop(void)
switch_queue_push(sql_manager.sql_queue[0], NULL);
switch_queue_push(sql_manager.sql_queue[1], NULL);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Waiting for unfinished SQL transactions\n");
switch_thread_cond_broadcast(sql_manager.cond);
wake_thread(1);
}
sql_manager.thread_running = -1;
switch_thread_join(&st, sql_manager.thread);
}
if (sql_manager.thread && sql_manager.db_thread_running) {
sql_manager.db_thread_running = -1;
switch_thread_join(&st, sql_manager.db_thread);
}
switch_cache_db_flush_handles();
sql_close(0);