From a999e7c05bf3137d50c45a0a1705e5f655c48569 Mon Sep 17 00:00:00 2001 From: Jeff Lenk Date: Sun, 11 Jul 2010 17:11:45 -0500 Subject: [PATCH 01/68] more tweaks for VS2010 --- libs/win32/pcre/libpcre.2010.vcxproj | 67 ---------------------------- 1 file changed, 67 deletions(-) diff --git a/libs/win32/pcre/libpcre.2010.vcxproj b/libs/win32/pcre/libpcre.2010.vcxproj index 4ca6dbcb9d..22db6b7a50 100644 --- a/libs/win32/pcre/libpcre.2010.vcxproj +++ b/libs/win32/pcre/libpcre.2010.vcxproj @@ -120,12 +120,6 @@ false - - _DEBUG;%(PreprocessorDefinitions) - true - true - Win32 - Disabled $(ProjectDir);$(ProjectDir)..\..\pcre;%(AdditionalIncludeDirectories) @@ -136,27 +130,11 @@ Level3 true - - _DEBUG;%(PreprocessorDefinitions) - 0x0409 - - - true - - - odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - true - - _DEBUG;%(PreprocessorDefinitions) - true - true - X64 - Disabled $(ProjectDir);$(ProjectDir)..\..\pcre;%(AdditionalIncludeDirectories) @@ -167,27 +145,8 @@ Level3 true - - _DEBUG;%(PreprocessorDefinitions) - 0x0409 - - - true - - - odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - - - true - - - NDEBUG;%(PreprocessorDefinitions) - true - true - Win32 - MaxSpeed OnlyExplicitInline @@ -199,27 +158,11 @@ Level3 true - - NDEBUG;%(PreprocessorDefinitions) - 0x0409 - - - true - - - odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - true - - NDEBUG;%(PreprocessorDefinitions) - true - true - X64 - MaxSpeed OnlyExplicitInline @@ -231,16 +174,6 @@ Level3 true - - NDEBUG;%(PreprocessorDefinitions) - 0x0409 - - - true - - - odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - true From 1734df82ca421efb6900e592c2897bc69ae1acc9 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 11 Jul 2010 21:00:13 -0500 Subject: [PATCH 02/68] presence_data_cols --- src/switch_core_sqldb.c | 145 ++++++++++++++++++++++++++++++++-------- 1 file changed, 117 insertions(+), 28 deletions(-) diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index 7fc32c0a3f..c67d553daa 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -964,6 +964,45 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread, return NULL; } +static char *parse_presence_data_cols(switch_event_t *event) +{ + char *cols[25] = { 0 }; + int col_count = 0; + char *data_copy; + switch_stream_handle_t stream = { 0 }; + int i; + char *r; + char col_name[128] = ""; + const char *data = switch_event_get_header(event, "variable_presence_data_cols"); + + if (zstr(data)) { + return NULL; + } + + data_copy = strdup(data); + + col_count = switch_split(data_copy, ':', cols); + + SWITCH_STANDARD_STREAM(stream); + + for (i = 0; i < col_count; i++) { + switch_snprintf(col_name, sizeof(col_name), "variable_%s", cols[i]); + stream.write_function(&stream, "%q='%q',", cols[i], switch_event_get_header_nil(event, col_name)); + } + + r = (char *) stream.data; + + if (end_of(r) == ',') { + end_of(r) = '\0'; + } + + switch_safe_free(data_copy); + + return r; + +} + + #define MAX_SQL 5 #define new_sql() switch_assert(sql_idx+1 < MAX_SQL); sql[sql_idx++] @@ -971,6 +1010,7 @@ static void core_event_handler(switch_event_t *event) { char *sql[MAX_SQL] = { 0 }; int sql_idx = 0; + char *extra_cols; switch_assert(event); @@ -1053,26 +1093,57 @@ static void core_event_handler(switch_event_t *event) break; case SWITCH_EVENT_CHANNEL_HOLD: case SWITCH_EVENT_CHANNEL_UNHOLD: - case SWITCH_EVENT_CHANNEL_EXECUTE: - new_sql() = switch_mprintf("update channels set application='%q',application_data='%q'," - "presence_id='%q',presence_data='%q' where uuid='%q' and hostname='%q'", - switch_event_get_header_nil(event, "application"), - switch_event_get_header_nil(event, "application-data"), - switch_event_get_header_nil(event, "channel-presence-id"), - switch_event_get_header_nil(event, "channel-presence-data"), - switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname") + case SWITCH_EVENT_CHANNEL_EXECUTE: { - ); + if ((extra_cols = parse_presence_data_cols(event))) { + + new_sql() = switch_mprintf("update channels set application='%q',application_data='%q'," + "presence_id='%q',presence_data='%q',%s where uuid='%q' and hostname='%q'", + switch_event_get_header_nil(event, "application"), + switch_event_get_header_nil(event, "application-data"), + switch_event_get_header_nil(event, "channel-presence-id"), + switch_event_get_header_nil(event, "channel-presence-data"), + extra_cols, + switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname") + + ); + + free(extra_cols); + + } else { + + new_sql() = switch_mprintf("update channels set application='%q',application_data='%q'," + "presence_id='%q',presence_data='%q' where uuid='%q' and hostname='%q'", + switch_event_get_header_nil(event, "application"), + switch_event_get_header_nil(event, "application-data"), + switch_event_get_header_nil(event, "channel-presence-id"), + switch_event_get_header_nil(event, "channel-presence-data"), + switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname") + + ); + } + } break; case SWITCH_EVENT_CHANNEL_ORIGINATE: { - new_sql() = switch_mprintf("update channels set " - "presence_id='%q',presence_data='%q', call_uuid='%q' where uuid='%q' and hostname='%q'", - switch_event_get_header_nil(event, "channel-presence-id"), - switch_event_get_header_nil(event, "channel-presence-data"), - switch_event_get_header_nil(event, "channel-call-uuid"), - switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname")); + if ((extra_cols = parse_presence_data_cols(event))) { + new_sql() = switch_mprintf("update channels set " + "presence_id='%q',presence_data='%q', call_uuid='%q',%s where uuid='%q' and hostname='%q'", + switch_event_get_header_nil(event, "channel-presence-id"), + switch_event_get_header_nil(event, "channel-presence-data"), + switch_event_get_header_nil(event, "channel-call-uuid"), + extra_cols, + switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname")); + free(extra_cols); + } else { + new_sql() = switch_mprintf("update channels set " + "presence_id='%q',presence_data='%q', call_uuid='%q' where uuid='%q' and hostname='%q'", + switch_event_get_header_nil(event, "channel-presence-id"), + switch_event_get_header_nil(event, "channel-presence-data"), + switch_event_get_header_nil(event, "channel-call-uuid"), + switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname")); + } } @@ -1124,19 +1195,37 @@ static void core_event_handler(switch_event_t *event) case CS_DESTROY: break; case CS_ROUTING: - new_sql() = switch_mprintf("update channels set state='%s',cid_name='%q',cid_num='%q'," - "ip_addr='%s',dest='%q',dialplan='%q',context='%q',presence_id='%q',presence_data='%q' " - "where uuid='%s' and hostname='%q'", - switch_event_get_header_nil(event, "channel-state"), - switch_event_get_header_nil(event, "caller-caller-id-name"), - switch_event_get_header_nil(event, "caller-caller-id-number"), - switch_event_get_header_nil(event, "caller-network-addr"), - switch_event_get_header_nil(event, "caller-destination-number"), - switch_event_get_header_nil(event, "caller-dialplan"), - switch_event_get_header_nil(event, "caller-context"), - switch_event_get_header_nil(event, "channel-presence-id"), - switch_event_get_header_nil(event, "channel-presence-data"), - switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname")); + if ((extra_cols = parse_presence_data_cols(event))) { + new_sql() = switch_mprintf("update channels set state='%s',cid_name='%q',cid_num='%q'," + "ip_addr='%s',dest='%q',dialplan='%q',context='%q',presence_id='%q',presence_data='%q',%s " + "where uuid='%s' and hostname='%q'", + switch_event_get_header_nil(event, "channel-state"), + switch_event_get_header_nil(event, "caller-caller-id-name"), + switch_event_get_header_nil(event, "caller-caller-id-number"), + switch_event_get_header_nil(event, "caller-network-addr"), + switch_event_get_header_nil(event, "caller-destination-number"), + switch_event_get_header_nil(event, "caller-dialplan"), + switch_event_get_header_nil(event, "caller-context"), + switch_event_get_header_nil(event, "channel-presence-id"), + switch_event_get_header_nil(event, "channel-presence-data"), + extra_cols, + switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname")); + free(extra_cols); + } else { + new_sql() = switch_mprintf("update channels set state='%s',cid_name='%q',cid_num='%q'," + "ip_addr='%s',dest='%q',dialplan='%q',context='%q',presence_id='%q',presence_data='%q' " + "where uuid='%s' and hostname='%q'", + switch_event_get_header_nil(event, "channel-state"), + switch_event_get_header_nil(event, "caller-caller-id-name"), + switch_event_get_header_nil(event, "caller-caller-id-number"), + switch_event_get_header_nil(event, "caller-network-addr"), + switch_event_get_header_nil(event, "caller-destination-number"), + switch_event_get_header_nil(event, "caller-dialplan"), + switch_event_get_header_nil(event, "caller-context"), + switch_event_get_header_nil(event, "channel-presence-id"), + switch_event_get_header_nil(event, "channel-presence-data"), + switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname")); + } break; default: new_sql() = switch_mprintf("update channels set state='%s' where uuid='%s' and hostname='%q'", From d6f14d03075de222a0a9cd53735ad08e7236c4c8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 11 Jul 2010 23:25:00 -0500 Subject: [PATCH 03/68] add fifo_member_usage app --- src/mod/applications/mod_fifo/mod_fifo.c | 82 +++++++++++++++++++++++- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index cc2589a4f4..3075c1d926 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -729,6 +729,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void char *parsed = NULL; switch_event_create_brackets(h->originate_string, '{', '}', ',', &ovars, &parsed); + switch_event_del_header(ovars, "fifo_outbound_uuid"); if (!h->timeout) h->timeout = 60; if (timeout < h->timeout) timeout = h->timeout; @@ -1363,6 +1364,46 @@ SWITCH_STANDARD_API(fifo_add_outbound_function) } +static switch_status_t hanguphook(switch_core_session_t *session) +{ + switch_channel_t *channel = switch_core_session_get_channel(session); + switch_channel_state_t state = switch_channel_get_state(channel); + const char *uuid = NULL; + char sql[256] = ""; + + if (state == CS_HANGUP || state == CS_ROUTING) { + if ((uuid = switch_channel_get_variable(channel, "fifo_outbound_uuid"))) { + switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, " + "outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s'", + (long)switch_epoch_time_now(NULL), uuid); + + fifo_execute_sql(sql, globals.sql_mutex); + } + switch_core_event_hook_remove_state_change(session, hanguphook); + } + return SWITCH_STATUS_SUCCESS; +} + + +SWITCH_STANDARD_APP(fifo_member_usage_function) +{ + char *sql; + switch_channel_t *channel = switch_core_session_get_channel(session); + + if (zstr(data)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid!\n"); + return; + } + + switch_channel_set_variable(channel, "fifo_outbound_uuid", data); + sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,outbound_fail_count=0 where uuid='%s'", data); + + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + + switch_core_event_hook_add_state_change(session, hanguphook); + +} typedef enum { STRAT_MORE_PPL, @@ -2772,6 +2813,26 @@ const char bridge_sql[] = ");\n" ; + + +static void extract_fifo_outbound_uuid(char *string, char *uuid, switch_size_t len) +{ + switch_event_t *ovars; + char *parsed = NULL; + const char *fifo_outbound_uuid; + + switch_event_create(&ovars, SWITCH_EVENT_REQUEST_PARAMS); + + switch_event_create_brackets(string, '{', '}', ',', &ovars, &parsed); + + if ((fifo_outbound_uuid = switch_event_get_header(ovars, "fifo_outbound_uuid"))) { + switch_snprintf(uuid, len, "%s", fifo_outbound_uuid); + } + + switch_safe_free(parsed); + switch_event_destroy(&ovars); +} + static switch_status_t load_config(int reload, int del_all) { char *cf = "fifo.conf"; @@ -2919,8 +2980,13 @@ static switch_status_t load_config(int reload, int del_all) const char *taking_calls = switch_xml_attr_soft(member, "taking_calls"); char *name_dup, *p; char digest[SWITCH_MD5_DIGEST_STRING_SIZE] = { 0 }; - switch_md5_string(digest, (void *) member->txt, strlen(member->txt)); + if (switch_stristr("fifo_outbound_uuid=", member->txt)) { + extract_fifo_outbound_uuid(member->txt, digest, sizeof(digest)); + } else { + switch_md5_string(digest, (void *) member->txt, strlen(member->txt)); + } + if (simo) { simo_i = atoi(simo); } @@ -3023,7 +3089,11 @@ static void fifo_member_add(char *fifo_name, char *originate_string, int simo_co char *sql, *name_dup, *p; fifo_node_t *node = NULL; - switch_md5_string(digest, (void *) originate_string, strlen(originate_string)); + if (switch_stristr("fifo_outbound_uuid=", originate_string)) { + extract_fifo_outbound_uuid(originate_string, digest, sizeof(digest)); + } else { + switch_md5_string(digest, (void *) originate_string, strlen(originate_string)); + } sql = switch_mprintf("delete from fifo_outbound where fifo_name='%q' and uuid = '%q'", fifo_name, digest); switch_assert(sql); @@ -3065,7 +3135,11 @@ static void fifo_member_del(char *fifo_name, char *originate_string) callback_t cbt = { 0 }; fifo_node_t *node = NULL; - switch_md5_string(digest, (void *) originate_string, strlen(originate_string)); + if (switch_stristr("fifo_outbound_uuid=", originate_string)) { + extract_fifo_outbound_uuid(originate_string, digest, sizeof(digest)); + } else { + switch_md5_string(digest, (void *) originate_string, strlen(originate_string)); + } sql = switch_mprintf("delete from fifo_outbound where fifo_name='%q' and uuid = '%q' and hostname='%q'", fifo_name, digest, globals.hostname); switch_assert(sql); @@ -3212,6 +3286,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load) /* 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_APP(app_interface, "fifo_member_usage", "increment a member usage until the call ends", + "", fifo_member_usage_function, "", SAF_NONE); SWITCH_ADD_API(commands_api_interface, "fifo", "Return data about a fifo", fifo_api_function, FIFO_API_SYNTAX); SWITCH_ADD_API(commands_api_interface, "fifo_member", "Add members to a fifo", fifo_member_api_function, FIFO_MEMBER_API_SYNTAX); SWITCH_ADD_API(commands_api_interface, "fifo_add_outbound", "Add outbound members to a fifo", fifo_add_outbound_function, " []"); From a96cbd0e36b1443fef4afc19f95f392813a282ae Mon Sep 17 00:00:00 2001 From: Jeff Lenk Date: Mon, 12 Jul 2010 09:48:34 -0500 Subject: [PATCH 04/68] more tweaks for VS2010 --- libs/win32/apr-util/libaprutil.2010.vcxproj | 68 ++------------------- libs/win32/apr/libapr.2010.vcxproj | 28 ++------- 2 files changed, 10 insertions(+), 86 deletions(-) diff --git a/libs/win32/apr-util/libaprutil.2010.vcxproj b/libs/win32/apr-util/libaprutil.2010.vcxproj index a39f21e091..b105ab4bc8 100644 --- a/libs/win32/apr-util/libaprutil.2010.vcxproj +++ b/libs/win32/apr-util/libaprutil.2010.vcxproj @@ -73,17 +73,10 @@ if not exist "$(ProjectDir)..\..\apr-util\include\apu.h" type "$(ProjectDir)..\..\apr-util\include\apu.hw" > "$(ProjectDir)..\..\apr-util\include\apu.h" if not exist "$(ProjectDir)..\..\apr-util\include\apu_config.h" type "$(ProjectDir)..\..\apr-util\include\apu_config.hw" > "$(ProjectDir)..\..\apr-util\include\apu_config.h" if not exist "$(ProjectDir)..\..\apr-util\include\apu_select_dbm.h" type "$(ProjectDir)..\..\apr-util\include\apu_select_dbm.hw" > "$(ProjectDir)..\..\apr-util\include\apu_select_dbm.h" -if not exist "$(ProjectDir)..\..\apr-util\include\apu_want.h" type "$(ProjectDir)..\..\apr-util\include\apu_want.hw" > "$(ProjectDir)..\..\apr-util\include\apu_want.h" +if not exist "$(ProjectDir)..\..\apr-util\include\apu_want.h" type "$(ProjectDir)..\..\apr-util\include\apu_want.hw" > "$(ProjectDir)..\..\apr-util\include\apu_want.h" +xcopy "$(ProjectDir)..\..\apr-util\include\*.h" "$(ProjectDir)..\..\include\" /C /D /Y + - - _DEBUG;%(PreprocessorDefinitions) - true - true - Win32 - $(IntDir)libaprutil.tlb - - - /EHsc %(AdditionalOptions) Disabled @@ -100,7 +93,6 @@ if not exist "$(ProjectDir)..\..\apr-util\include\apu_want.h" type "$(ProjectDir ws2_32.lib;mswsock.lib;wldap32.lib;%(AdditionalDependencies) - $(OutDir)$(ProjectName).dll true %(AdditionalLibraryDirectories) true @@ -111,12 +103,7 @@ if not exist "$(ProjectDir)..\..\apr-util\include\apu_want.h" type "$(ProjectDir true - $(IntDir)libaprutil.bsc - - - - @@ -125,17 +112,9 @@ if not exist "$(ProjectDir)..\..\apr-util\include\apu.h" type "$(ProjectDir)..\. if not exist "$(ProjectDir)..\..\apr-util\include\apu_config.h" type "$(ProjectDir)..\..\apr-util\include\apu_config.hw" > "$(ProjectDir)..\..\apr-util\include\apu_config.h" if not exist "$(ProjectDir)..\..\apr-util\include\apu_select_dbm.h" type "$(ProjectDir)..\..\apr-util\include\apu_select_dbm.hw" > "$(ProjectDir)..\..\apr-util\include\apu_select_dbm.h" if not exist "$(ProjectDir)..\..\apr-util\include\apu_want.h" type "$(ProjectDir)..\..\apr-util\include\apu_want.hw" > "$(ProjectDir)..\..\apr-util\include\apu_want.h" +xcopy "$(ProjectDir)..\..\apr-util\include\*.h" "$(ProjectDir)..\..\include\" /C /D /Y - - _DEBUG;%(PreprocessorDefinitions) - true - true - X64 - $(IntDir)libaprutil.tlb - - - /EHsc %(AdditionalOptions) Disabled @@ -152,7 +131,6 @@ if not exist "$(ProjectDir)..\..\apr-util\include\apu_want.h" type "$(ProjectDir ws2_32.lib;mswsock.lib;wldap32.lib;%(AdditionalDependencies) - $(OutDir)$(ProjectName).dll true %(AdditionalLibraryDirectories) true @@ -163,12 +141,7 @@ if not exist "$(ProjectDir)..\..\apr-util\include\apu_want.h" type "$(ProjectDir true - $(IntDir)libaprutil.bsc - - - - @@ -177,17 +150,9 @@ if not exist "$(ProjectDir)..\..\apr-util\include\apu.h" type "$(ProjectDir)..\. if not exist "$(ProjectDir)..\..\apr-util\include\apu_config.h" type "$(ProjectDir)..\..\apr-util\include\apu_config.hw" > "$(ProjectDir)..\..\apr-util\include\apu_config.h" if not exist "$(ProjectDir)..\..\apr-util\include\apu_select_dbm.h" type "$(ProjectDir)..\..\apr-util\include\apu_select_dbm.hw" > "$(ProjectDir)..\..\apr-util\include\apu_select_dbm.h" if not exist "$(ProjectDir)..\..\apr-util\include\apu_want.h" type "$(ProjectDir)..\..\apr-util\include\apu_want.hw" > "$(ProjectDir)..\..\apr-util\include\apu_want.h" +xcopy "$(ProjectDir)..\..\apr-util\include\*.h" "$(ProjectDir)..\..\include\" /C /D /Y - - NDEBUG;%(PreprocessorDefinitions) - true - true - Win32 - $(IntDir)libaprutil.tlb - - - MaxSpeed OnlyExplicitInline @@ -206,7 +171,6 @@ if not exist "$(ProjectDir)..\..\apr-util\include\apu_want.h" type "$(ProjectDir ws2_32.lib;mswsock.lib;wldap32.lib;%(AdditionalDependencies) - $(OutDir)$(ProjectName).dll true %(AdditionalLibraryDirectories) true @@ -214,17 +178,11 @@ if not exist "$(ProjectDir)..\..\apr-util\include\apu_want.h" type "$(ProjectDir true 0x6EE60000 false - $(IntDir)libaprutil-1.lib MachineX86 true - $(IntDir)libaprutil.bsc - - - - @@ -233,17 +191,9 @@ if not exist "$(ProjectDir)..\..\apr-util\include\apu.h" type "$(ProjectDir)..\. if not exist "$(ProjectDir)..\..\apr-util\include\apu_config.h" type "$(ProjectDir)..\..\apr-util\include\apu_config.hw" > "$(ProjectDir)..\..\apr-util\include\apu_config.h" if not exist "$(ProjectDir)..\..\apr-util\include\apu_select_dbm.h" type "$(ProjectDir)..\..\apr-util\include\apu_select_dbm.hw" > "$(ProjectDir)..\..\apr-util\include\apu_select_dbm.h" if not exist "$(ProjectDir)..\..\apr-util\include\apu_want.h" type "$(ProjectDir)..\..\apr-util\include\apu_want.hw" > "$(ProjectDir)..\..\apr-util\include\apu_want.h" +xcopy "$(ProjectDir)..\..\apr-util\include\*.h" "$(ProjectDir)..\..\include\" /C /D /Y - - NDEBUG;%(PreprocessorDefinitions) - true - true - X64 - $(IntDir)libaprutil.tlb - - - MaxSpeed OnlyExplicitInline @@ -262,7 +212,6 @@ if not exist "$(ProjectDir)..\..\apr-util\include\apu_want.h" type "$(ProjectDir ws2_32.lib;mswsock.lib;wldap32.lib;%(AdditionalDependencies) - $(OutDir)$(ProjectName).dll true %(AdditionalLibraryDirectories) true @@ -274,12 +223,7 @@ if not exist "$(ProjectDir)..\..\apr-util\include\apu_want.h" type "$(ProjectDir true - $(IntDir)libaprutil.bsc - - - - diff --git a/libs/win32/apr/libapr.2010.vcxproj b/libs/win32/apr/libapr.2010.vcxproj index 6638ec7d43..5c6b686ee0 100644 --- a/libs/win32/apr/libapr.2010.vcxproj +++ b/libs/win32/apr/libapr.2010.vcxproj @@ -70,6 +70,7 @@ if not exist "$(ProjectDir)..\..\apr\include\apr.h" type "$(ProjectDir)apr.hw" > "$(ProjectDir)..\..\apr\include\apr.h" +xcopy "$(ProjectDir)..\..\apr\include\*.h" "$(ProjectDir)..\..\include\" /C /D /Y @@ -88,7 +89,6 @@ ws2_32.lib;mswsock.lib;rpcrt4.lib;advapi32.lib;%(AdditionalDependencies) - $(OutDir)$(ProjectName).dll true true Windows @@ -100,16 +100,12 @@ true - $(IntDir)libapr.bsc - - - - if not exist "$(ProjectDir)..\..\apr\include\apr.h" type "$(ProjectDir)apr.hw" > "$(ProjectDir)..\..\apr\include\apr.h" +xcopy "$(ProjectDir)..\..\apr\include\*.h" "$(ProjectDir)..\..\include\" /C /D /Y @@ -128,7 +124,6 @@ ws2_32.lib;mswsock.lib;rpcrt4.lib;advapi32.lib;%(AdditionalDependencies) - $(OutDir)$(ProjectName).dll true true Windows @@ -138,16 +133,12 @@ true - $(IntDir)libapr.bsc - - - - if not exist "$(ProjectDir)..\..\apr\include\apr.h" type "$(ProjectDir)apr.hw" > "$(ProjectDir)..\..\apr\include\apr.h" +xcopy "$(ProjectDir)..\..\apr\include\*.h" "$(ProjectDir)..\..\include\" /C /D /Y @@ -168,7 +159,6 @@ ws2_32.lib;mswsock.lib;rpcrt4.lib;advapi32.lib;%(AdditionalDependencies) - $(OutDir)$(ProjectName).dll true true Windows @@ -179,16 +169,12 @@ true - $(IntDir)libapr.bsc - - - - if not exist "$(ProjectDir)..\..\apr\include\apr.h" type "$(ProjectDir)apr.hw" > "$(ProjectDir)..\..\apr\include\apr.h" +xcopy "$(ProjectDir)..\..\apr\include\*.h" "$(ProjectDir)..\..\include\" /C /D /Y @@ -209,7 +195,6 @@ ws2_32.lib;mswsock.lib;rpcrt4.lib;advapi32.lib;%(AdditionalDependencies) - $(OutDir)$(ProjectName).dll true true Windows @@ -220,12 +205,7 @@ true - $(IntDir)libapr.bsc - - - - From 859b713ea7a4ffd9da6ed2e274260f89cb2ceb1e Mon Sep 17 00:00:00 2001 From: Jeff Lenk Date: Mon, 12 Jul 2010 10:01:46 -0500 Subject: [PATCH 05/68] more tweaks for VS2010 --- libs/libteletone/libteletone.2010.vcxproj | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/libs/libteletone/libteletone.2010.vcxproj b/libs/libteletone/libteletone.2010.vcxproj index e8335ddd41..8d2c30a66a 100644 --- a/libs/libteletone/libteletone.2010.vcxproj +++ b/libs/libteletone/libteletone.2010.vcxproj @@ -48,19 +48,19 @@ - + - + - + - + @@ -79,7 +79,6 @@ true - $(ProjectDir)teletone.def false false false @@ -102,7 +101,6 @@ true - $(ProjectDir)teletone.def false false false @@ -120,7 +118,6 @@ true - $(ProjectDir)teletone.def false @@ -137,7 +134,6 @@ true - $(ProjectDir)teletone.def false MachineX64 From 93d38441a91505631fdc4b32629d07d976700de8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 12 Jul 2010 12:00:53 -0500 Subject: [PATCH 06/68] refactor --- src/mod/applications/mod_fifo/mod_fifo.c | 70 +++++++++++------------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 3075c1d926..2e4df02e91 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -136,7 +136,11 @@ static switch_status_t fifo_queue_pop(fifo_queue_t *queue, switch_event_t **pop, return SWITCH_STATUS_FALSE; } - *pop = queue->data[0]; + if (remove) { + *pop = queue->data[0]; + } else { + switch_event_dup(pop, queue->data[0]); + } if (remove) { for (i = 1; i < queue->idx; i++) { @@ -169,7 +173,12 @@ static switch_status_t fifo_queue_pop_nameval(fifo_queue_t *queue, const char *n for (j = 0; j < queue->idx; j++) { const char *j_val = switch_event_get_header(queue->data[j], name); if (j_val && val && !strcmp(j_val, val)) { - *pop = queue->data[j]; + + if (remove) { + *pop = queue->data[j]; + } else { + switch_event_dup(pop, queue->data[j]); + } break; } } @@ -178,7 +187,7 @@ static switch_status_t fifo_queue_pop_nameval(fifo_queue_t *queue, const char *n switch_mutex_unlock(queue->mutex); return SWITCH_STATUS_FALSE; } - + if (remove) { for (i = j+1; i < queue->idx; i++) { queue->data[i-1] = queue->data[i]; @@ -688,7 +697,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_caller_extension_t *extension = NULL; switch_channel_t *channel; char *caller_id_name = NULL, *cid_num = NULL, *id = NULL; - switch_event_t *pop = NULL; + switch_event_t *pop = NULL, *pop_dup = NULL; fifo_queue_t *q = NULL; int x = 0; switch_event_t *event; @@ -697,8 +706,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_uuid_get(&uuid); switch_uuid_format(uuid_str, &uuid); - - + if (!cbh->rowcount) { goto end; } @@ -712,7 +720,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void if (node) { switch_mutex_lock(node->mutex); node->busy++; - node->ring_consumer_count++; + node->ring_consumer_count = cbh->rowcount; switch_mutex_unlock(node->mutex); } else { goto end; @@ -748,41 +756,28 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void if (!timeout) timeout = 60; + pop = pop_dup = NULL; + for (x = 0; x < MAX_PRI; x++) { q = node->fifo_list[x]; - switch_mutex_lock(q->mutex); - - if (fifo_queue_pop_nameval(q, "variable_fifo_vip", "true", &pop, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS && pop) { - goto found; + if (fifo_queue_pop_nameval(q, "variable_fifo_vip", "true", &pop_dup, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS && pop_dup) { + pop = pop_dup; } - switch_mutex_unlock(q->mutex); - q = NULL; } if (!pop) { for (x = 0; x < MAX_PRI; x++) { q = node->fifo_list[x]; - switch_mutex_lock(q->mutex); - - if (fifo_queue_pop(node->fifo_list[x], &pop, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS && pop) { - goto found; + if (fifo_queue_pop(node->fifo_list[x], &pop_dup, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS && pop_dup) { + pop = pop_dup; } } - switch_mutex_unlock(q->mutex); - q = NULL; } - found: - - - if (!q) goto end; - if (!pop) { - if (q) switch_mutex_unlock(q->mutex); goto end; } - - + if (!switch_event_get_header(ovars, "origination_caller_id_name")) { if ((caller_id_name = switch_event_get_header(pop, "caller-caller-id-name"))) { if (node->outbound_name) { @@ -828,8 +823,6 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_event_fire(&event); } - switch_mutex_unlock(q->mutex); - pop = NULL; status = switch_ivr_originate(NULL, &session, &cause, originate_string, timeout, NULL, NULL, NULL, NULL, ovars, SOF_NONE, NULL); @@ -886,11 +879,14 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_safe_free(originate_string); switch_event_destroy(&ovars); + + if (pop_dup) { + switch_event_destroy(&pop_dup); + } + if (node) { switch_mutex_lock(node->mutex); - if (node->ring_consumer_count-- < 0) { - node->ring_consumer_count = 0; - } + node->ring_consumer_count = 0; if (node->busy) node->busy--; switch_mutex_unlock(node->mutex); } @@ -3147,11 +3143,11 @@ static void fifo_member_del(char *fifo_name, char *originate_string) free(sql); switch_mutex_lock(globals.mutex); - if (!(node = switch_core_hash_find(globals.fifo_hash, fifo_name))) { - node = create_node(fifo_name, 0, globals.sql_mutex); - node->ready = 1; - } - switch_mutex_unlock(globals.mutex); + if (!(node = switch_core_hash_find(globals.fifo_hash, fifo_name))) { + node = create_node(fifo_name, 0, globals.sql_mutex); + node->ready = 1; + } + switch_mutex_unlock(globals.mutex); cbt.buf = outbound_count; cbt.len = sizeof(outbound_count); From 251d1f06899b1f941a332231973f086da8e2ec76 Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Mon, 12 Jul 2010 13:08:14 -0400 Subject: [PATCH 07/68] Add commented out load directive for mod_erlang_event to modules.conf.xml --- conf/autoload_configs/modules.conf.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/autoload_configs/modules.conf.xml b/conf/autoload_configs/modules.conf.xml index b4dff4d96e..d8ae5e1a03 100644 --- a/conf/autoload_configs/modules.conf.xml +++ b/conf/autoload_configs/modules.conf.xml @@ -22,6 +22,7 @@ + From 85d3428372c5818d1016fee8cc1c9c2c2bd0e87d Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 12 Jul 2010 16:12:07 -0400 Subject: [PATCH 08/68] freetdm: fix custom old ss7 data --- .../src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c index 42090710b1..b5121b995b 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c @@ -1031,6 +1031,10 @@ tryagain: ftdm_set_string(ftdmchan->caller_data.ani.digits, (char *)event->calling.digits); ftdm_set_string(ftdmchan->caller_data.dnis.digits, (char *)event->called.digits); ftdm_set_string(ftdmchan->caller_data.rdnis.digits, (char *)event->rdnis.digits); + if (event->custom_data_size) { + ftdm_set_string(ftdmchan->caller_data.raw_data, event->custom_data); + ftdmchan->caller_data.raw_data_len = event->custom_data_size; + } if (strlen(event->calling_name)) { ftdm_set_string(ftdmchan->caller_data.cid_name, (char *)event->calling_name); From 60af226890a190ad3aa25ab46eff9e1d0e7e6938 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 12 Jul 2010 15:37:07 -0500 Subject: [PATCH 09/68] deal with empty param to serialize() --- libs/esl/src/esl_oop.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/esl/src/esl_oop.cpp b/libs/esl/src/esl_oop.cpp index 1b6629c066..231950f892 100644 --- a/libs/esl/src/esl_oop.cpp +++ b/libs/esl/src/esl_oop.cpp @@ -355,7 +355,7 @@ const char *ESLevent::serialize(const char *format) return ""; } - if (!strcasecmp(format, "json")) { + if (format && !strcasecmp(format, "json")) { esl_event_serialize_json(event, &serialized_string); return serialized_string; } From 88d6336f3d6081c6d86ad347f41328e62e02d465 Mon Sep 17 00:00:00 2001 From: Michael S Collins Date: Mon, 12 Jul 2010 17:37:04 -0700 Subject: [PATCH 10/68] Update ChangeLog through June 11; more to come --- docs/ChangeLog | 58 ++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/docs/ChangeLog b/docs/ChangeLog index 993463c8ef..99c87c5657 100644 --- a/docs/ChangeLog +++ b/docs/ChangeLog @@ -7,13 +7,15 @@ freeswitch (1.0.7) build: apply fix for MODSOFIA-71 to windows build build: Add more excludes to .gitignore (for Windows) (r:b6628d26/FSBUILD-269) build: Bump version of en-us-callie sounds to 1.0.13 (r:ca0a69a3) - build: change build to use mod_spandsp instead of mod_fax and mod_voipcodecs (r: 988147a7) - build: add mod_spandsp to windows build (r: 4fa8be62) + build: change build to use mod_spandsp instead of mod_fax and mod_voipcodecs (r:988147a7) + build: add mod_spandsp to windows build (r:4fa8be62) + build: merge -j option for bootstrap (r:abb7d2e5/FSBUILD-237) + build: dont fail on bootstrap due to missing libs (r:ff960d78) config: move limit.conf to db.conf config: Update VM phrase macros to voice option then action on main, config menus config: Remove 99xx extension numbers to avoid dp conflicts (r:0c9bb174/DP-17) config: update config example for caller-id-type (r:8f03a7cd) - config: default to 48k since most sound cards can do that (r: 170404a4) + config: default to 48k since most sound cards can do that (r:170404a4) core: Add RTCP support (FSRTP-14) core: handle some errors on missing db handle conditions core: add ... and shutdown as a fail-safe when no modules are loaded @@ -45,8 +47,9 @@ freeswitch (1.0.7) core: (Win) bridge fails because session read lock failure (r:f8f91362/FSCORE-606) core: Add option to hangup channel if record fails (r:a3e6bead/FSBUILD-591) core: Crash when using tab completion on uuid_ commands (r:9637b89e/FSCORE-613) - core: fix uuid_media state change (r: 2cc59f1e/FSCORE-615) - core: add new callstate field to channels table (r: 0f133eae) + core: fix uuid_media state change (r:2cc59f1e/FSCORE-615) + core: add new callstate field to channels table (r:0f133eae) + core: fix leg_timeout issue (r:3fbd9e21/MODAPP-433) embedded languages: Provide core level support for conditional Set Global Variable (r:c017c24b/FSCORE-612) lang: Improve French phrase files (FSCONFIG-23) libdingaling: fix race on shutdown causing crash (FSMOD-47) @@ -59,7 +62,7 @@ freeswitch (1.0.7) libsopenzap: Add CLI tracing libspandsp: Fixed a typo in spandsp's msvc/inttypes.h Updated sig_tone processing in spandsp to the latest, to allow moy to proceed with his signaling work. libspandsp: removed a saturate16 from spandsp that was causing problems fixed a typo in the MSVC inttypes.h file for spandsp - libspandsp: Changes to the signaling tone detector to detect concurrent 2400Hz + 2600Hz tones. This passes voice immunity and other key tests, but it bounces a bit when transitions like 2400 -> 2400+2600 -> 2600 occur. Transitions between tone off and tone on are clean. (r: bc13e944) + libspandsp: Changes to the signaling tone detector to detect concurrent 2400Hz + 2600Hz tones. This passes voice immunity and other key tests, but it bounces a bit when transitions like 2400 -> 2400+2600 -> 2600 occur. Transitions between tone off and tone on are clean. (r:bc13e944) mod_avmd: Initial check in - Advanced Voicemail Detect (r:10c6a30a) (by Eric Des Courtis) mod_avmd: Add to windows build (r:df4bd935) mod_cidlookup: null xml is bad (r:095815f8) @@ -67,9 +70,8 @@ freeswitch (1.0.7) mod_commands: make break uuid_break and add cascade flag mod_commands: add uuid_autoanswer command (now uuid_phone_event) mod_commands: expand last patch to do hold as well and rename the command to uuid_phone_event - mod_commands: make break uuid_break and add cascade flag - mod_commands: allow uuid_break to interrupt one or all in a delimited string of files the same as several individual files (r: eba05c3c) - mod_commands: add show channels count auto-completion for mod_commands (r: 5ffc57e5/FSMOD-54) + mod_commands: allow uuid_break to interrupt one or all in a delimited string of files the same as several individual files (r:eba05c3c) + mod_commands: add show channels count auto-completion for mod_commands (r:5ffc57e5/FSMOD-54) mod_conference: Fix reporting of volume up/down (MODAPP-419) mod_conference: add last talking time per member to conference xml list mod_conference: add terminate-on-silence conference param @@ -78,6 +80,8 @@ freeswitch (1.0.7) mod_conference: fix relate nohear (r:f029ce07/MODAPP-428) mod_db: fix stack corruption (MODAPP-407) mod_dptools: add eavesdrop_enable_dtmf chan var (r:596c0012) + mod_dptools: Make park app not send 183 session progress (r:76932995/FSCORE-567) + mod_dptools: add block_dtmf and unblock_dtmf apps (r:d9eb0197) mod_fifo: allow multiple dtmf to exit fifo, set fifo_caller_exit_key to specify which (MODAPP-420) mod_freetdm: Fix for TON and NPI not passed through to channel variables on incoming calls mod_freetdm: add pvt data to freetdm channels fix fxs features (r:9d456900) @@ -93,19 +97,19 @@ freeswitch (1.0.7) mod_freetdm: run sched in the background if requested (r:22e8a442) mod_freetdm: fix makefile and remove binary app (r:63d9768d) mod_freetdm: add trace/notrace commands to trace input and output from channels (r:f4da0e5c) - mod_freetdm: add logging when failing to read a frame in mod_freetdm (r: e596fc2e) - mod_freetdm: add new logging macro (r: 75be3da8) - mod_freetdm: check for hw dtmf before enabling (r: b1fd88d7) - mod_freetdm: adding ftmod_sangoma_ss7 support (r: 94283355) - mod_freetdm: added SIGEVENT_COLLISION (r: 501f8704) + mod_freetdm: add logging when failing to read a frame in mod_freetdm (r:e596fc2e) + mod_freetdm: add new logging macro (r:75be3da8) + mod_freetdm: check for hw dtmf before enabling (r:b1fd88d7) + mod_freetdm: adding ftmod_sangoma_ss7 support (r:94283355) + mod_freetdm: added SIGEVENT_COLLISION (r:501f8704) mod_gsmopen: copy from branch mod_java: fix eventConsumer issue and add flush() method (r:7fd3aff6) - mod_java: Allow user defined java methods to be called at startup and shutdown of JVM (r: 1339e218/MODLANG-117) + mod_java: Allow user defined java methods to be called at startup and shutdown of JVM (r:1339e218/MODLANG-117) mod_lcr: Expand variables (MODAPP-418) mod_lcr: add enable_sip_redir parameter (r:70bf7a0a/MODAPP-427) mod_loopback: add loopback_bowout_on_execute var to make 1 legged loopback calls bow out of the picture - mod_loopback: only execute app once in app mode (r: 64f58f2d) - mod_managed: Added wrapper for switch_event_bind for .net (r: a5f07a80/MODLANG-165) + mod_loopback: only execute app once in app mode (r:64f58f2d) + mod_managed: Added wrapper for switch_event_bind for .net (r:a5f07a80/MODLANG-165) mod_mp4v: MP4V-ES passthru for washibechi on IRC mod_nibblebill: free allocated mem at shutdown; free properly if using custom_sql mod_nibblebill: Add SAF_SUPPORT_NOMEDIA to nibblebill @@ -122,7 +126,7 @@ freeswitch (1.0.7) mod_sangoma_codec: Add sample config file mod_sangoma_codec: added load/noload options for the supported codecs mod_sangoma_codec: rename load/noload to register/noregister - mod_sangoma_codec: silence suppression (r: 73d9d56f) + mod_sangoma_codec: silence suppression (r:73d9d56f) mod_say_es: fix grammar when saying dates and time (r:6bed19b2/MODAPP-429) mod_say_zh: Number reading should now be OK for the whole range of integers for Cantonese and Mandarin mod_skinny: Add the missing api files @@ -154,12 +158,14 @@ freeswitch (1.0.7) mod_sofia: fire an event for gateway ping mod_sofia: initial handling of udptl and t.38 re-invite mod_sofia: Implement "redirect server" functionality with 300 Multiple Choices (r:e15abcf9/BOUNTY-18) - mod_sofia: allow video negotiation on re-invite (r: be92e5d/SFSIP-211) - mod_sofia: use rfc recommended default session timeout of 30 min according to RFC 4028 4.2 (r: 52cd8cdd/MODSOFIA-76) - mod_sofia: add sip_force_audio_fmtp (r: 6360264f) - mod_sofia: add sip_copy_multipart to work like sip_copy_custom_headers (r: a291af57) - mod_sofia: Rename sofia_glue_get_user_host to switch_split_user_domain and move to switch_utils. To allow use by other modules. (r: 3f7cafd7) - mod_sofia: allow the profile gateway config to set sip_cid_type for each gateway (r: 0152706f/BOUNTY-19) + mod_sofia: allow video negotiation on re-invite (r:be92e5d/SFSIP-211) + mod_sofia: use rfc recommended default session timeout of 30 min according to RFC 4028 4.2 (r:52cd8cdd/MODSOFIA-76) + mod_sofia: add sip_force_audio_fmtp (r:6360264f) + mod_sofia: add sip_copy_multipart to work like sip_copy_custom_headers (r:a291af57) + mod_sofia: Rename sofia_glue_get_user_host to switch_split_user_domain and move to switch_utils. To allow use by other modules. (r:3f7cafd7) + mod_sofia: allow the profile gateway config to set sip_cid_type for each gateway (r:0152706f/BOUNTY-19) + mod_sofia: Adding subject to SEND_MESSAGE (r:2e347c93) + mod_sofia: add multiple rtp-ip support to sofia profiles add extra rtp-ip params to a profile to add more ip which will be used round-robin as new calls progress. (r:22569d4a) mod_spandsp: initial checkin of mod_fax/mod_voipcodecs merge into mod_spandsp (r:fa9a59a8) mod_spandsp: rework of new mod_spandsp to have functions broken up into different c files (r:65400642) mod_spandsp: improve duplicate digit detection and add 'min_dup_digit_spacing_ms' channel variable for use with the dtmf detector (r:eab4f246/FSMOD-45) @@ -175,9 +181,9 @@ freeswitch (1.0.7) mod_xml_cdr: add force_process_cdr var to process b leg cdr on a case by case basis when b leg cdr is disabled (XML-17) mod_xml_cdr: add leg param to query string (XML-24) mod_xml_cdr: fix locked sessions (XML-26) - mod_xml_cdr: fix minor memory leaks and config bug (r: 19253d83/MODEVENT-62) + mod_xml_cdr: fix minor memory leaks and config bug (r:19253d83/MODEVENT-62) sofia-sip: fix null derefernce segfault in soa (r:f356c5e6) - sofia-sip: extend timeout for session expires on short timeouts to be 90% of timeout instead of 1/3 to handle devices that do not refresh in time such as polycom (r: a7f48928/SFSIP-212) + sofia-sip: extend timeout for session expires on short timeouts to be 90% of timeout instead of 1/3 to handle devices that do not refresh in time such as polycom (r:a7f48928/SFSIP-212) freeswitch (1.0.6) From d277778743a25ab23606f6f4c01199b70866fc0b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 12 Jul 2010 20:58:39 -0500 Subject: [PATCH 11/68] tweak --- src/mod/applications/mod_fifo/mod_fifo.c | 74 ++++++++++++++++-------- 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 2e4df02e91..aa956f48b4 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -679,6 +679,26 @@ struct callback_helper { }; +static switch_status_t hanguphook(switch_core_session_t *session) +{ + switch_channel_t *channel = switch_core_session_get_channel(session); + switch_channel_state_t state = switch_channel_get_state(channel); + const char *uuid = NULL; + char sql[256] = ""; + + if (state == CS_HANGUP || state == CS_ROUTING) { + if ((uuid = switch_channel_get_variable(channel, "fifo_outbound_uuid"))) { + switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, " + "outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", + (long)switch_epoch_time_now(NULL), uuid); + + fifo_execute_sql(sql, globals.sql_mutex); + } + switch_core_event_hook_remove_state_change(session, hanguphook); + } + return SWITCH_STATUS_SUCCESS; +} + static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void *obj) { @@ -824,13 +844,23 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_event_fire(&event); } + for (i = 0; i < cbh->rowcount; i++) { + struct call_helper *h = cbh->rows[i]; + char *sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,outbound_fail_count=0 where uuid='%s'", h->uuid); + + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + + } + status = switch_ivr_originate(NULL, &session, &cause, originate_string, timeout, NULL, NULL, NULL, NULL, ovars, SOF_NONE, NULL); if (status != SWITCH_STATUS_SUCCESS) { for (i = 0; i < cbh->rowcount; i++) { struct call_helper *h = cbh->rows[i]; - char *sql = switch_mprintf("update fifo_outbound set outbound_fail_count=outbound_fail_count+1, next_avail=%ld + lag where uuid='%q'", - (long) switch_epoch_time_now(NULL), h->uuid); + char *sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, " + "outbound_fail_count=outbound_fail_count+1, next_avail=%ld + lag where uuid='%q' and use_count > 0", + (long) switch_epoch_time_now(NULL), h->uuid); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); @@ -865,6 +895,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_channel_set_variable(channel, "fifo_pop_order", NULL); + switch_core_event_hook_add_state_change(session, hanguphook); app_name = "fifo"; arg = switch_core_session_sprintf(session, "%s out nowait", node_name); @@ -910,6 +941,7 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) switch_event_t *ovars = NULL; switch_status_t status = SWITCH_STATUS_FALSE; switch_event_t *event = NULL; + char *sql = NULL; switch_mutex_lock(globals.mutex); node = switch_core_hash_find(globals.fifo_hash, h->node_name); @@ -951,6 +983,11 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) switch_event_fire(&event); } + + sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,outbound_fail_count=0 where uuid='%s'", h->uuid); + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + status = switch_ivr_originate(NULL, &session, &cause, originate_string, h->timeout, NULL, NULL, NULL, NULL, ovars, SOF_NONE, NULL); free(originate_string); @@ -958,6 +995,12 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) if (status != SWITCH_STATUS_SUCCESS) { + sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, " + "outbound_fail_count=outbound_fail_count+1, next_avail=%ld + lag where uuid='%q' and use_count > 0", + (long) switch_epoch_time_now(NULL), h->uuid); + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", node->name); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "post-dial"); @@ -992,6 +1035,7 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) } } + switch_core_event_hook_add_state_change(session, hanguphook); switch_channel_set_variable(channel, "fifo_outbound_uuid", h->uuid); app_name = "fifo"; arg = switch_core_session_sprintf(session, "%s out %s", h->node_name, member_wait ? member_wait : "wait"); @@ -1360,27 +1404,6 @@ SWITCH_STANDARD_API(fifo_add_outbound_function) } -static switch_status_t hanguphook(switch_core_session_t *session) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_channel_state_t state = switch_channel_get_state(channel); - const char *uuid = NULL; - char sql[256] = ""; - - if (state == CS_HANGUP || state == CS_ROUTING) { - if ((uuid = switch_channel_get_variable(channel, "fifo_outbound_uuid"))) { - switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, " - "outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s'", - (long)switch_epoch_time_now(NULL), uuid); - - fifo_execute_sql(sql, globals.sql_mutex); - } - switch_core_event_hook_remove_state_change(session, hanguphook); - } - return SWITCH_STATUS_SUCCESS; -} - - SWITCH_STANDARD_APP(fifo_member_usage_function) { char *sql; @@ -1762,7 +1785,12 @@ SWITCH_STANDARD_APP(fifo_function) const char *caller_uuid = NULL; switch_event_t *call_event; const char *outbound_id = switch_channel_get_variable(channel, "fifo_outbound_uuid"); + const char *track_use_count = switch_channel_get_variable(channel, "fifo_track_use_count"); + if (!switch_true(track_use_count)) { + outbound_id = NULL; + } + if (!zstr(strat_str)) { if (!strcasecmp(strat_str, "more_ppl")) { From 1ed7837bc6eb6161a17725ebdb55df75b95eea45 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 12 Jul 2010 21:58:24 -0500 Subject: [PATCH 12/68] tweak2 --- src/mod/applications/mod_fifo/mod_fifo.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index aa956f48b4..2527acd6a9 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -2339,7 +2339,7 @@ struct xml_helper { static int xml_callback(void *pArg, int argc, char **argv, char **columnNames) { struct xml_helper *h = (struct xml_helper *) pArg; - switch_xml_t x_tmp, x_out; + switch_xml_t x_out; int c_off = 0; char exp_buf[128] = ""; switch_time_exp_t tm; @@ -2357,9 +2357,9 @@ static int xml_callback(void *pArg, int argc, char **argv, char **columnNames) } } - x_tmp = switch_xml_add_child_d(h->xml, h->container, h->cc_off++); + - x_out = switch_xml_add_child_d(x_tmp, h->tag, c_off++); + x_out = switch_xml_add_child_d(h->xml, h->tag, c_off++); switch_xml_set_attr_d(x_out, "simo", argv[3]); switch_xml_set_attr_d(x_out, "use_count", argv[4]); switch_xml_set_attr_d(x_out, "timeout", argv[5]); @@ -2390,6 +2390,8 @@ static int xml_outbound(switch_xml_t xml, fifo_node_t *node, char *container, ch h.row_off = 0; h.verbose = verbose; + h.xml = switch_xml_add_child_d(h.xml, h.container, h.cc_off++); + fifo_execute_sql_callback(globals.sql_mutex, sql, xml_callback, &h); switch_safe_free(sql); From 32f6aa3b9e81ec230556a59fc02276d138ebe7cb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 13 Jul 2010 00:47:41 -0500 Subject: [PATCH 13/68] update --- src/switch_channel.c | 13 ++++++++++--- src/switch_core_sqldb.c | 38 ++++++++++---------------------------- 2 files changed, 20 insertions(+), 31 deletions(-) diff --git a/src/switch_channel.c b/src/switch_channel.c index 9a85d5efbd..edf162c0fd 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1761,6 +1761,11 @@ SWITCH_DECLARE(void) switch_channel_event_set_basic_data(switch_channel_t *chann switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Presence-Data", v); } + + if ((v = switch_channel_get_variable(channel, "presence_data_cols"))) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Presence-Data-Cols", v); + } + if ((v = switch_channel_get_variable(channel, "call_uuid"))) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Call-UUID", v); } @@ -1813,13 +1818,15 @@ SWITCH_DECLARE(void) switch_channel_event_set_basic_data(switch_channel_t *chann SWITCH_DECLARE(void) switch_channel_event_set_extended_data(switch_channel_t *channel, switch_event_t *event) { switch_event_header_t *hi; - int x, global_verbos_events = 0; + int x, global_verbose_events = 0; switch_mutex_lock(channel->profile_mutex); - switch_core_session_ctl(SCSC_VERBOSE_EVENTS, &global_verbos_events); + switch_core_session_ctl(SCSC_VERBOSE_EVENTS, &global_verbose_events); - if (global_verbos_events || switch_channel_test_flag(channel, CF_VERBOSE_EVENTS) || + if (global_verbose_events || + switch_channel_test_flag(channel, CF_VERBOSE_EVENTS) || + switch_event_get_header(event, "presence-data-cols") || event->event_id == SWITCH_EVENT_CHANNEL_CREATE || event->event_id == SWITCH_EVENT_CHANNEL_ORIGINATE || event->event_id == SWITCH_EVENT_CHANNEL_UUID || diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index c67d553daa..810de2ddda 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -973,7 +973,7 @@ static char *parse_presence_data_cols(switch_event_t *event) int i; char *r; char col_name[128] = ""; - const char *data = switch_event_get_header(event, "variable_presence_data_cols"); + const char *data = switch_event_get_header(event, "presence-data-cols"); if (zstr(data)) { return NULL; @@ -1094,34 +1094,16 @@ static void core_event_handler(switch_event_t *event) case SWITCH_EVENT_CHANNEL_HOLD: case SWITCH_EVENT_CHANNEL_UNHOLD: case SWITCH_EVENT_CHANNEL_EXECUTE: { - - if ((extra_cols = parse_presence_data_cols(event))) { - - new_sql() = switch_mprintf("update channels set application='%q',application_data='%q'," - "presence_id='%q',presence_data='%q',%s where uuid='%q' and hostname='%q'", - switch_event_get_header_nil(event, "application"), - switch_event_get_header_nil(event, "application-data"), - switch_event_get_header_nil(event, "channel-presence-id"), - switch_event_get_header_nil(event, "channel-presence-data"), - extra_cols, - switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname") - - ); - - free(extra_cols); - - } else { - new_sql() = switch_mprintf("update channels set application='%q',application_data='%q'," - "presence_id='%q',presence_data='%q' where uuid='%q' and hostname='%q'", - switch_event_get_header_nil(event, "application"), - switch_event_get_header_nil(event, "application-data"), - switch_event_get_header_nil(event, "channel-presence-id"), - switch_event_get_header_nil(event, "channel-presence-data"), - switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname") - - ); - } + new_sql() = switch_mprintf("update channels set application='%q',application_data='%q'," + "presence_id='%q',presence_data='%q' where uuid='%q' and hostname='%q'", + switch_event_get_header_nil(event, "application"), + switch_event_get_header_nil(event, "application-data"), + switch_event_get_header_nil(event, "channel-presence-id"), + switch_event_get_header_nil(event, "channel-presence-data"), + switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname") + ); + } break; From fa1148e9eecfded674bb6f10c55e5879701a1638 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 13 Jul 2010 01:41:27 -0500 Subject: [PATCH 14/68] update --- src/mod/applications/mod_fifo/mod_fifo.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 2527acd6a9..b380cc5531 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -1786,12 +1786,8 @@ SWITCH_STANDARD_APP(fifo_function) switch_event_t *call_event; const char *outbound_id = switch_channel_get_variable(channel, "fifo_outbound_uuid"); const char *track_use_count = switch_channel_get_variable(channel, "fifo_track_use_count"); - - if (!switch_true(track_use_count)) { - outbound_id = NULL; - } + int do_track = switch_true(track_use_count); - if (!zstr(strat_str)) { if (!strcasecmp(strat_str, "more_ppl")) { strat = STRAT_MORE_PPL; @@ -2138,7 +2134,7 @@ SWITCH_STANDARD_APP(fifo_function) switch_event_fire(&event); } - if (outbound_id) { + if (outbound_id && do_track) { sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,outbound_fail_count=0 where uuid='%s'", outbound_id); fifo_execute_sql(sql, globals.sql_mutex); @@ -2163,7 +2159,7 @@ SWITCH_STANDARD_APP(fifo_function) switch_ivr_multi_threaded_bridge(session, other_session, on_dtmf, other_session, session); - if (outbound_id) { + if (outbound_id && do_track) { sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", (long) switch_epoch_time_now(NULL), outbound_id); fifo_execute_sql(sql, globals.sql_mutex); From 548c9061ab9a3b0ad168332fcf7b0487440f792f Mon Sep 17 00:00:00 2001 From: Rupa Schomaker Date: Tue, 13 Jul 2010 06:07:49 -0500 Subject: [PATCH 15/68] MODAPP-441: mod_lcr: add lcr_user_rate to imported a-leg vars --- src/mod/applications/mod_lcr/mod_lcr.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/mod/applications/mod_lcr/mod_lcr.c b/src/mod/applications/mod_lcr/mod_lcr.c index c6f1a56d1b..f0362b71bf 100644 --- a/src/mod/applications/mod_lcr/mod_lcr.c +++ b/src/mod/applications/mod_lcr/mod_lcr.c @@ -1311,11 +1311,11 @@ static switch_call_cause_t lcr_outgoing_channel(switch_core_session_t *session, if (lcr_do_lookup(&routes) == SWITCH_STATUS_SUCCESS) { if (channel) { if (zstr(switch_channel_get_variable(channel, "import"))) { - switch_channel_set_variable(channel, "import", "lcr_carrier,lcr_rate"); + switch_channel_set_variable(channel, "import", "lcr_carrier,lcr_rate,lcr_user_rate"); } else { const char *tmp = switch_channel_get_variable(channel, "import"); - if (!strstr(tmp, "lcr_carrier,lcr_rate")) { - switch_channel_set_variable_printf(channel, "import", "%s,lcr_carrier,lcr_rate", tmp); + if (!strstr(tmp, "lcr_carrier,lcr_rate,lcr_user_rate")) { + switch_channel_set_variable_printf(channel, "import", "%s,lcr_carrier,lcr_rate,lcr_user_rate", tmp); } } } @@ -1440,11 +1440,11 @@ SWITCH_STANDARD_DIALPLAN(lcr_dialplan_hunt) switch_channel_set_variable(channel, SWITCH_CONTINUE_ON_FAILURE_VARIABLE, "true"); switch_channel_set_variable(channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE, "true"); if (zstr(switch_channel_get_variable(channel, "import"))) { - switch_channel_set_variable(channel, "import", "lcr_carrier,lcr_rate"); + switch_channel_set_variable(channel, "import", "lcr_carrier,lcr_rate,lcr_user_rate"); } else { const char *tmp = switch_channel_get_variable(channel, "import"); - if (!strstr(tmp, "lcr_carrier,lcr_rate")) { - switch_channel_set_variable_printf(channel, "import", "%s,lcr_carrier,lcr_rate", tmp); + if (!strstr(tmp, "lcr_carrier,lcr_rate,lcr_user_rate")) { + switch_channel_set_variable_printf(channel, "import", "%s,lcr_carrier,lcr_rate,lcr_user_rate", tmp); } } @@ -1589,11 +1589,11 @@ SWITCH_STANDARD_APP(lcr_app_function) switch_channel_set_variable(channel, "lcr_route_count", vbuf); switch_channel_set_variable(channel, "lcr_auto_route", (char *)dig_stream.data); if (zstr(switch_channel_get_variable(channel, "import"))) { - switch_channel_set_variable(channel, "import", "lcr_carrier,lcr_rate"); + switch_channel_set_variable(channel, "import", "lcr_carrier,lcr_rate,lcr_user_rate"); } else { const char *tmp = switch_channel_get_variable(channel, "import"); - if (!strstr(tmp, "lcr_carrier,lcr_rate")) { - switch_channel_set_variable_printf(channel, "import", "%s,lcr_carrier,lcr_rate", tmp); + if (!strstr(tmp, "lcr_carrier,lcr_rate,lcr_user_rate")) { + switch_channel_set_variable_printf(channel, "import", "%s,lcr_carrier,lcr_rate,lcr_user_rate", tmp); } } free(dig_stream.data); From 17a7a0dd7b33b454c29fa12ab04874fdf34444e8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 13 Jul 2010 08:33:59 -0500 Subject: [PATCH 16/68] don't reset outbound_fail_count on pre-call use_count increments --- src/mod/applications/mod_fifo/mod_fifo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index b380cc5531..646d5d0ff1 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -846,7 +846,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void for (i = 0; i < cbh->rowcount; i++) { struct call_helper *h = cbh->rows[i]; - char *sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,outbound_fail_count=0 where uuid='%s'", h->uuid); + char *sql = switch_mprintf("update fifo_outbound set use_count=use_count+1 where uuid='%s'", h->uuid); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); @@ -984,7 +984,7 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) } - sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,outbound_fail_count=0 where uuid='%s'", h->uuid); + sql = switch_mprintf("update fifo_outbound set use_count=use_count+1 where uuid='%s'", h->uuid); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); From f3907f771d6cced8c501af305cbe4ec2c4dc062e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 13 Jul 2010 12:42:36 -0500 Subject: [PATCH 17/68] fix ringall issue --- src/mod/applications/mod_fifo/mod_fifo.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 646d5d0ff1..126b36e97e 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -1075,11 +1075,14 @@ static int place_call_ringall_callback(void *pArg, int argc, char **argv, char * cbh->rows[cbh->rowcount++] = h; - cbh->need--; - if (cbh->rowcount == MAX_ROWS) return -1; - - return cbh->need ? 0 : -1; + + if (cbh->need) { + cbh->need--; + return cbh->need ? 0 : -1; + } + + return 0; } @@ -1150,9 +1153,9 @@ static void find_consumers(fifo_node_t *node) switch_core_new_memory_pool(&pool); cbh = switch_core_alloc(pool, sizeof(*cbh)); cbh->pool = pool; - cbh->need = node_consumer_wait_count(node); + cbh->need = 1; - if (node->outbound_per_cycle && node->outbound_per_cycle < cbh->need) { + if (node->outbound_per_cycle != cbh->need) { cbh->need = node->outbound_per_cycle; } @@ -2916,6 +2919,8 @@ static switch_status_t load_config(int reload, int del_all) switch_cache_db_test_reactive(dbh, "delete from fifo_bridge", "drop table fifo_bridge", bridge_sql); switch_cache_db_release_db_handle(&dbh); + fifo_execute_sql("update fifo_outbound set use_count=0,outbound_call_count=0,outbound_fail_count=0", globals.sql_mutex); + if (reload) { switch_hash_index_t *hi; fifo_node_t *node; @@ -2945,7 +2950,7 @@ static switch_status_t load_config(int reload, int del_all) for (fifo = switch_xml_child(fifos, "fifo"); fifo; fifo = fifo->next) { const char *name, *outbound_strategy; const char *val; - int imp = 0, outbound_per_cycle = 0; + int imp = 0, outbound_per_cycle = 1; int simo_i = 1; int taking_calls_i = 1; int timeout_i = 60; From ac77c76818969ea29edc91c207fcd63db00bbf6f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 13 Jul 2010 15:43:37 -0500 Subject: [PATCH 18/68] add nomedia flag --- src/mod/applications/mod_fifo/mod_fifo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 126b36e97e..c3e9f534a7 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -3314,7 +3314,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load) *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_APP(app_interface, "fifo_member_usage", "increment a member usage until the call ends", - "", fifo_member_usage_function, "", SAF_NONE); + "", fifo_member_usage_function, "", SAF_SUPPORT_NOMEDIA); SWITCH_ADD_API(commands_api_interface, "fifo", "Return data about a fifo", fifo_api_function, FIFO_API_SYNTAX); SWITCH_ADD_API(commands_api_interface, "fifo_member", "Add members to a fifo", fifo_member_api_function, FIFO_MEMBER_API_SYNTAX); SWITCH_ADD_API(commands_api_interface, "fifo_add_outbound", "Add outbound members to a fifo", fifo_add_outbound_function, " []"); From 119d01f65c630fc25ac3c561c2a1737d0d26c3fd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 13 Jul 2010 16:52:32 -0500 Subject: [PATCH 19/68] fix small mem leak in util func --- src/switch_event.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/switch_event.c b/src/switch_event.c index c2cbc7cb2e..eccc695679 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -1062,8 +1062,8 @@ SWITCH_DECLARE(switch_status_t) switch_event_create_brackets(char *data, char a, int var_count = 0; char *next; - vdata = strdup(data); - vdatap = vdata; + vdatap = strdup(data); + vdata = vdatap; end = switch_find_end_paren(vdata, a, b); @@ -1081,7 +1081,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_create_brackets(char *data, char a, vdata++; *end++ = '\0'; } else { - vdata = NULL; + free(vdatap); return SWITCH_STATUS_FALSE; } From d355c28d4d51e6c8a8e15baae07fb46de53de263 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 13 Jul 2010 17:27:37 -0500 Subject: [PATCH 20/68] fix logic bug and memory leak in new code --- src/mod/applications/mod_fifo/mod_fifo.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index c3e9f534a7..fbaf170191 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -782,6 +782,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void q = node->fifo_list[x]; if (fifo_queue_pop_nameval(q, "variable_fifo_vip", "true", &pop_dup, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS && pop_dup) { pop = pop_dup; + break; } } @@ -790,6 +791,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void q = node->fifo_list[x]; if (fifo_queue_pop(node->fifo_list[x], &pop_dup, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS && pop_dup) { pop = pop_dup; + break; } } } From e76d7d925ea6ffc804e1971b1e2a178f63513669 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Tue, 13 Jul 2010 19:04:41 -0400 Subject: [PATCH 21/68] mod_hash: free all hashtables on shutdown --- src/mod/applications/mod_hash/mod_hash.c | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/mod/applications/mod_hash/mod_hash.c b/src/mod/applications/mod_hash/mod_hash.c index eb02e5104a..8179690928 100644 --- a/src/mod/applications/mod_hash/mod_hash.c +++ b/src/mod/applications/mod_hash/mod_hash.c @@ -486,8 +486,35 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_hash_load) SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_hash_shutdown) { + switch_hash_index_t *hi = NULL; + switch_scheduler_del_task_group("mod_hash"); + switch_thread_rwlock_wrlock(globals.limit_hash_rwlock); + switch_thread_rwlock_wrlock(globals.db_hash_rwlock); + + while ((hi = switch_hash_first(NULL, globals.limit_hash))) { + void *val = NULL; + const void *key; + switch_ssize_t keylen; + switch_hash_this(hi, &key, &keylen, &val); + free(val); + switch_core_hash_delete(globals.limit_hash, key); + } + + while ((hi = switch_hash_first(NULL, globals.db_hash))) { + void *val = NULL; + const void *key; + switch_ssize_t keylen; + switch_hash_this(hi, &key, &keylen, &val); + free(val); + switch_core_hash_delete(globals.db_hash, key); + } + + + switch_thread_rwlock_unlock(globals.limit_hash_rwlock); + switch_thread_rwlock_unlock(globals.db_hash_rwlock); + switch_thread_rwlock_destroy(globals.db_hash_rwlock); switch_thread_rwlock_destroy(globals.limit_hash_rwlock); From c73d98cd83b36a8a6d6ffc62ca8e3cd9e1892b42 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 12:40:08 -0500 Subject: [PATCH 22/68] fifo up --- src/mod/applications/mod_fifo/mod_fifo.c | 323 ++++++++++++++++++++--- src/switch_core_session.c | 60 +++-- src/switch_ivr_bridge.c | 16 +- 3 files changed, 331 insertions(+), 68 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index fbaf170191..41b3213588 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -34,6 +34,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fifo_shutdown); SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load); SWITCH_MODULE_DEFINITION(mod_fifo, mod_fifo_load, mod_fifo_shutdown, NULL); +#define MANUAL_QUEUE_NAME "manual_calls" #define FIFO_EVENT "fifo::info" #define FIFO_DELAY_DESTROY 100 static switch_status_t load_config(int reload, int del_all); @@ -679,22 +680,190 @@ struct callback_helper { }; +static switch_status_t messagehook (switch_core_session_t *session, switch_core_session_message_t *msg) +{ + switch_event_t *event; + switch_core_session_t *other_session, *caller_session, *consumer_session; + switch_channel_t *channel, *other_channel, *caller_channel, *consumer_channel; + const char *outbound_id; + char *sql; + + channel = switch_core_session_get_channel(session); + outbound_id = switch_channel_get_variable(channel, "fifo_outbound_uuid"); + + if ((other_session = switch_core_session_force_locate(msg->string_arg))) { + + other_channel = switch_core_session_get_channel(other_session); + + consumer_channel = channel; + caller_channel = other_channel; + + consumer_session = session; + caller_session = other_session; + + } else { + return SWITCH_STATUS_SUCCESS; + } + + + switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_BRIDGE: + { + const char *col1 = NULL, *col2 = NULL; + + if (switch_true(switch_channel_get_variable(channel, "fifo_bridged"))) { + return SWITCH_STATUS_SUCCESS; + } + + switch_process_import(consumer_session, caller_channel, "fifo_caller_consumer_import"); + switch_process_import(caller_session, consumer_channel, "fifo_consumer_caller_import"); + + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + switch_channel_event_set_data(consumer_channel, event); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer"); + switch_event_fire(&event); + } + + 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller"); + switch_event_fire(&event); + } + + sql = switch_mprintf("insert into fifo_bridge " + "(fifo_name,caller_uuid,caller_caller_id_name,caller_caller_id_number,consumer_uuid,consumer_outgoing_uuid,bridge_start) " + "values ('%q','%q','%q','%q','%q','%q',%ld)", + MANUAL_QUEUE_NAME, + switch_core_session_get_uuid(other_session), + switch_str_nil(switch_channel_get_variable(other_channel, "caller_id_name")), + switch_str_nil(switch_channel_get_variable(other_channel, "caller_id_number")), + switch_core_session_get_uuid(session), + switch_str_nil(outbound_id), + (long) switch_epoch_time_now(NULL) + ); + + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + + if (switch_channel_direction(consumer_channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { + col1 = "manual_calls_in_count"; + col2 = "manual_calls_in_total_count"; + } else { + col1 = "manual_calls_out_count"; + col2 = "manual_calls_out_total_count"; + } + + sql = switch_mprintf("update fifo_outbound set %s=%s+1,%s=%s+1 where uuid='%q'", col1, col1, col2, col2, outbound_id); + printf("WTF [%s]\n", sql); + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + + + switch_channel_set_variable(consumer_channel, "fifo_bridged", "true"); + switch_channel_set_variable(consumer_channel, "fifo_manual_bridge", "true"); + + } + break; + case SWITCH_MESSAGE_INDICATE_UNBRIDGE: + { + if (switch_true(switch_channel_get_variable(channel, "fifo_bridged"))) { + char date[80] = ""; + switch_time_exp_t tm; + switch_time_t ts = switch_micro_time_now(); + switch_size_t retsize; + + switch_channel_set_variable(channel, "fifo_bridged", NULL); + + ts = switch_micro_time_now(); + switch_time_exp_lt(&tm, ts); + switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm); + + sql = switch_mprintf("delete from fifo_bridge where consumer_uuid='%q'", switch_core_session_get_uuid(consumer_session)); + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + + switch_channel_set_variable(consumer_channel, "fifo_status", "WAITING"); + switch_channel_set_variable(consumer_channel, "fifo_timestamp", date); + + switch_channel_set_variable(caller_channel, "fifo_status", "DONE"); + switch_channel_set_variable(caller_channel, "fifo_timestamp", date); + + + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + switch_channel_event_set_data(consumer_channel, event); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-stop"); + switch_event_fire(&event); + } + + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + switch_channel_event_set_data(caller_channel, event); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-stop"); + switch_event_fire(&event); + } + + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + switch_channel_event_set_data(consumer_channel, event); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "consumer_stop"); + switch_event_fire(&event); + } + } + + } + break; + default: + break; + } + + if (other_session) { + switch_core_session_rwunlock(other_session); + } + + return SWITCH_STATUS_SUCCESS; +} + static switch_status_t hanguphook(switch_core_session_t *session) { switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_state_t state = switch_channel_get_state(channel); const char *uuid = NULL; - char sql[256] = ""; + char sql[512] = ""; + switch_core_session_message_t msg = { 0 }; if (state == CS_HANGUP || state == CS_ROUTING) { if ((uuid = switch_channel_get_variable(channel, "fifo_outbound_uuid"))) { - switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, " - "outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", - (long)switch_epoch_time_now(NULL), uuid); + if ((switch_true(switch_channel_get_variable(channel, "fifo_manual_bridge")))) { + switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, " + "next_avail=%ld + lag where uuid='%s' and use_count > 0", + (long)switch_epoch_time_now(NULL), uuid); + } else { + + switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, " + "outbound_call_count=outbound_call_count+1, " + "outbound_call_total_count=outbound_call_total_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", + (long)switch_epoch_time_now(NULL), uuid); + } fifo_execute_sql(sql, globals.sql_mutex); } switch_core_event_hook_remove_state_change(session, hanguphook); + switch_core_event_hook_remove_receive_message(session, messagehook); + + if (switch_true(switch_channel_get_variable(channel, "fifo_bridged"))) { + msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE; + msg.from = __FILE__; + msg.string_arg = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE); + + if (msg.string_arg && switch_ivr_uuid_exists(msg.string_arg)) { + messagehook(session, &msg); + } + } + + } return SWITCH_STATUS_SUCCESS; } @@ -1424,7 +1593,7 @@ SWITCH_STANDARD_APP(fifo_member_usage_function) fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); - + switch_core_event_hook_add_receive_message(session, messagehook); switch_core_event_hook_add_state_change(session, hanguphook); } @@ -2163,9 +2332,25 @@ SWITCH_STANDARD_APP(fifo_function) switch_safe_free(sql); switch_ivr_multi_threaded_bridge(session, other_session, on_dtmf, other_session, session); + + + 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-stop"); + switch_event_fire(&event); + } + 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-stop"); + switch_event_fire(&event); + } if (outbound_id && do_track) { - sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", (long) switch_epoch_time_now(NULL), outbound_id); + sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, outbound_call_total_count=outbound_call_total_count+1 " + "outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", + (long) switch_epoch_time_now(NULL), outbound_id); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); @@ -2345,7 +2530,17 @@ static int xml_callback(void *pArg, int argc, char **argv, char **columnNames) char exp_buf[128] = ""; switch_time_exp_t tm; switch_time_t etime = 0; - char *expires = exp_buf; + char atime[128] = ""; + char *expires = exp_buf, *tb = atime; + int arg = 0; + + for(arg = 0; arg < argc; arg++) { + if (!argv[arg]) { + argv[arg] = ""; + } + } + + arg = 0; if (argv[7]) { if ((etime = atol(argv[7]))) { @@ -2358,7 +2553,23 @@ static int xml_callback(void *pArg, int argc, char **argv, char **columnNames) } } - + + if (atoi(argv[13])) { + arg = 17; + } else { + arg = 18; + } + + + if ((etime = atol(argv[arg]))) { + switch_size_t retsize; + + switch_time_exp_lt(&tm, switch_time_from_sec(etime)); + switch_strftime_nocheck(atime, &retsize, sizeof(atime), "%Y-%m-%d %T", &tm); + } else { + switch_set_string(atime, "now"); + } + x_out = switch_xml_add_child_d(h->xml, h->tag, c_off++); switch_xml_set_attr_d(x_out, "simo", argv[3]); @@ -2369,6 +2580,22 @@ static int xml_callback(void *pArg, int argc, char **argv, char **columnNames) switch_xml_set_attr_d(x_out, "outbound-fail-count", argv[11]); switch_xml_set_attr_d(x_out, "taking-calls", argv[13]); switch_xml_set_attr_d(x_out, "status", argv[14]); + + switch_xml_set_attr_d(x_out, "outbound_call_total_count", argv[15]); + switch_xml_set_attr_d(x_out, "outbound_fail_total_count", argv[16]); + + if (arg == 17) { + switch_xml_set_attr_d(x_out, "logged_on_since", tb); + } else { + switch_xml_set_attr_d(x_out, "logged_off_since", tb); + } + + switch_xml_set_attr_d(x_out, "manual_calls_out_count", argv[19]); + switch_xml_set_attr_d(x_out, "manual_calls_in_count", argv[20]); + switch_xml_set_attr_d(x_out, "manual_calls_out_total_count", argv[21]); + switch_xml_set_attr_d(x_out, "manual_calls_in_total_count", argv[22]); + + switch_xml_set_attr_d(x_out, "next-available", expires); switch_xml_set_txt_d(x_out, argv[2]); @@ -2379,9 +2606,20 @@ static int xml_callback(void *pArg, int argc, char **argv, char **columnNames) static int xml_outbound(switch_xml_t xml, fifo_node_t *node, char *container, char *tag, int cc_off, int verbose) { struct xml_helper h = { 0 }; - char *sql = switch_mprintf("select uuid, fifo_name, originate_string, simo_count, use_count, timeout, " - "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, " - "hostname, taking_calls, status from fifo_outbound where fifo_name = '%q'", node->name); + char *sql; + + if (!strcmp(node->name, MANUAL_QUEUE_NAME)) { + sql = strdup("select uuid, fifo_name, originate_string, simo_count, use_count, timeout, " + "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, " + "hostname, taking_calls, status, outbound_call_total_count, outbound_fail_total_count, active_time, inactive_time, " + "manual_calls_out_count, manual_calls_in_count, manual_calls_out_total_count, manual_calls_in_total_count from fifo_outbound"); + } else { + sql = switch_mprintf("select uuid, fifo_name, originate_string, simo_count, use_count, timeout, " + "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, " + "hostname, taking_calls, status, outbound_call_total_count, outbound_fail_total_count, active_time, inactive_time, " + "manual_calls_out_count, manual_calls_in_count, manual_calls_out_total_count, manual_calls_in_total_count " + "from fifo_outbound where fifo_name = '%q'", node->name); + } h.xml = xml; h.node = node; @@ -2816,14 +3054,22 @@ const char outbound_sql[] = " use_count integer,\n" " timeout integer,\n" " lag integer,\n" - " next_avail integer,\n" - " expires integer,\n" - " static integer,\n" - " outbound_call_count integer,\n" - " outbound_fail_count integer,\n" + " next_avail integer not null default 0,\n" + " expires integer not null default 0,\n" + " static integer not null default 0,\n" + " outbound_call_count integer not null default 0,\n" + " outbound_fail_count integer not null default 0,\n" " hostname varchar(255),\n" " taking_calls integer not null default 1,\n" - " status varchar(255)\n" + " status varchar(255),\n" + " outbound_call_total_count integer not null default 0,\n" + " outbound_fail_total_count integer not null default 0,\n" + " active_time integer not null default 0,\n" + " inactive_time integer not null default 0,\n" + " manual_calls_out_count integer not null default 0,\n" + " manual_calls_in_count integer not null default 0,\n" + " manual_calls_out_total_count integer not null default 0,\n" + " manual_calls_in_total_count integer not null default 0\n" ");\n"; @@ -2868,6 +3114,7 @@ static switch_status_t load_config(int reload, int del_all) char *sql; switch_bool_t delete_all_outbound_member_on_startup = SWITCH_FALSE; switch_cache_db_handle_t *dbh = NULL; + fifo_node_t *node; gethostname(globals.hostname, sizeof(globals.hostname)); @@ -2917,7 +3164,7 @@ static switch_status_t load_config(int reload, int del_all) goto done; } - switch_cache_db_test_reactive(dbh, "delete from fifo_outbound where static = 1 or taking_calls < 0", "drop table fifo_outbound", outbound_sql); + switch_cache_db_test_reactive(dbh, "delete from fifo_outbound where static = 1 or taking_calls < 0 or manual_calls_in < 0", "drop table fifo_outbound", outbound_sql); switch_cache_db_test_reactive(dbh, "delete from fifo_bridge", "drop table fifo_bridge", bridge_sql); switch_cache_db_release_db_handle(&dbh); @@ -2946,6 +3193,10 @@ static switch_status_t load_config(int reload, int del_all) fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); + if (!(node = switch_core_hash_find(globals.fifo_hash, MANUAL_QUEUE_NAME))) { + node = create_node(MANUAL_QUEUE_NAME, 0, globals.sql_mutex); + node->is_static = 0; + } if ((fifos = switch_xml_child(cfg, "fifos"))) { @@ -2957,9 +3208,19 @@ static switch_status_t load_config(int reload, int del_all) int taking_calls_i = 1; int timeout_i = 60; int lag_i = 10; - fifo_node_t *node; name = switch_xml_attr(fifo, "name"); + + if (!name) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "fifo has no name!\n"); + continue; + } + + if (!strcasecmp(name, MANUAL_QUEUE_NAME)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s is a reserved name, use another name please.\n", MANUAL_QUEUE_NAME); + continue; + } + outbound_strategy = switch_xml_attr(fifo, "outbound_strategy"); @@ -2974,12 +3235,7 @@ static switch_status_t load_config(int reload, int del_all) outbound_per_cycle = 0; } } - - if (!name) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "fifo has no name!\n"); - continue; - } - + switch_mutex_lock(globals.mutex); if (!(node = switch_core_hash_find(globals.fifo_hash, name))) { node = create_node(name, imp, globals.sql_mutex); @@ -3047,9 +3303,11 @@ static switch_status_t load_config(int reload, int del_all) sql = switch_mprintf("insert into fifo_outbound " "(uuid, fifo_name, originate_string, simo_count, use_count, timeout, lag, " - "next_avail, expires, static, outbound_call_count, outbound_fail_count, hostname, taking_calls) " - "values ('%q','%q','%q',%d,%d,%d,%d,0,0,1,0,0,'%q',%d)", - digest, node->name, member->txt, simo_i, 0, timeout_i, lag_i, globals.hostname, taking_calls_i); + "next_avail, expires, static, outbound_call_count, outbound_fail_count, hostname, taking_calls, " + "active_time, inactive_time) " + "values ('%q','%q','%q',%d,%d,%d,%d,0,0,1,0,0,'%q',%d,%ld,0)", + digest, node->name, member->txt, simo_i, 0, timeout_i, lag_i, globals.hostname, taking_calls_i, + (long) switch_epoch_time_now(NULL)); switch_assert(sql); fifo_execute_sql(sql, globals.sql_mutex); @@ -3146,9 +3404,10 @@ static void fifo_member_add(char *fifo_name, char *originate_string, int simo_co sql = switch_mprintf("insert into fifo_outbound " "(uuid, fifo_name, originate_string, simo_count, use_count, timeout, " - "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, hostname, taking_calls) " - "values ('%q','%q','%q',%d,%d,%d,%d,%d,%ld,0,0,0,'%q',%d)", - digest, fifo_name, originate_string, simo_count, 0, timeout, lag, 0, (long) expires, globals.hostname, taking_calls); + "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, hostname, taking_calls, active_time, inactive_time) " + "values ('%q','%q','%q',%d,%d,%d,%d,%d,%ld,0,0,0,'%q',%d,%ld,0)", + digest, fifo_name, originate_string, simo_count, 0, timeout, lag, 0, (long) expires, globals.hostname, taking_calls, + (long)switch_epoch_time_now(NULL)); switch_assert(sql); fifo_execute_sql(sql, globals.sql_mutex); free(sql); @@ -3315,7 +3574,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load) /* 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_APP(app_interface, "fifo_member_usage", "increment a member usage until the call ends", + SWITCH_ADD_APP(app_interface, "fifo_track_call", "Count a call as a fifo call in the manual_calls queue", "", fifo_member_usage_function, "", SAF_SUPPORT_NOMEDIA); SWITCH_ADD_API(commands_api_interface, "fifo", "Return data about a fifo", fifo_api_function, FIFO_API_SYNTAX); SWITCH_ADD_API(commands_api_interface, "fifo_member", "Add members to a fifo", fifo_member_api_function, FIFO_MEMBER_API_SYNTAX); diff --git a/src/switch_core_session.c b/src/switch_core_session.c index b1196adda0..ea5ecc119b 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -569,14 +569,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_perform_receive_message(swit switch_assert(session != NULL); - if (switch_channel_down(session->channel)) { - return SWITCH_STATUS_FALSE; - } - - if ((status = switch_core_session_read_lock(session)) != SWITCH_STATUS_SUCCESS) { + if ((status = switch_core_session_read_lock_hangup(session)) != SWITCH_STATUS_SUCCESS) { return status; } - + if (!message->_file) { message->_file = file; } @@ -610,7 +606,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_perform_receive_message(swit goto end; } - if (session->endpoint_interface->io_routines->receive_message) { + if (switch_channel_down(session->channel)) { + switch_log_printf(SWITCH_CHANNEL_ID_LOG, message->_file, message->_func, message->_line, + switch_core_session_get_uuid(session), SWITCH_LOG_DEBUG, "%s skip receive message [%s] (channel is hungup already)\n", + switch_channel_get_name(session->channel), message_names[message->message_id]); + + } else if (session->endpoint_interface->io_routines->receive_message) { status = session->endpoint_interface->io_routines->receive_message(session, message); } @@ -626,28 +627,29 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_perform_receive_message(swit message->_func = NULL; message->_line = 0; - - switch (message->message_id) { - case SWITCH_MESSAGE_REDIRECT_AUDIO: - case SWITCH_MESSAGE_INDICATE_ANSWER: - case SWITCH_MESSAGE_INDICATE_PROGRESS: - case SWITCH_MESSAGE_INDICATE_BRIDGE: - case SWITCH_MESSAGE_INDICATE_UNBRIDGE: - case SWITCH_MESSAGE_INDICATE_TRANSFER: - case SWITCH_MESSAGE_INDICATE_RINGING: - case SWITCH_MESSAGE_INDICATE_MEDIA: - case SWITCH_MESSAGE_INDICATE_NOMEDIA: - case SWITCH_MESSAGE_INDICATE_HOLD: - case SWITCH_MESSAGE_INDICATE_UNHOLD: - case SWITCH_MESSAGE_INDICATE_REDIRECT: - case SWITCH_MESSAGE_INDICATE_RESPOND: - case SWITCH_MESSAGE_INDICATE_BROADCAST: - case SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT: - case SWITCH_MESSAGE_INDICATE_DEFLECT: - switch_core_session_kill_channel(session, SWITCH_SIG_BREAK); - break; - default: - break; + if (switch_channel_up(session->channel)) { + switch (message->message_id) { + case SWITCH_MESSAGE_REDIRECT_AUDIO: + case SWITCH_MESSAGE_INDICATE_ANSWER: + case SWITCH_MESSAGE_INDICATE_PROGRESS: + case SWITCH_MESSAGE_INDICATE_BRIDGE: + case SWITCH_MESSAGE_INDICATE_UNBRIDGE: + case SWITCH_MESSAGE_INDICATE_TRANSFER: + case SWITCH_MESSAGE_INDICATE_RINGING: + case SWITCH_MESSAGE_INDICATE_MEDIA: + case SWITCH_MESSAGE_INDICATE_NOMEDIA: + case SWITCH_MESSAGE_INDICATE_HOLD: + case SWITCH_MESSAGE_INDICATE_UNHOLD: + case SWITCH_MESSAGE_INDICATE_REDIRECT: + case SWITCH_MESSAGE_INDICATE_RESPOND: + case SWITCH_MESSAGE_INDICATE_BROADCAST: + case SWITCH_MESSAGE_INDICATE_MEDIA_REDIRECT: + case SWITCH_MESSAGE_INDICATE_DEFLECT: + switch_core_session_kill_channel(session, SWITCH_SIG_BREAK); + break; + default: + break; + } } end: diff --git a/src/switch_ivr_bridge.c b/src/switch_ivr_bridge.c index 356d07956a..b32a61f1a2 100644 --- a/src/switch_ivr_bridge.c +++ b/src/switch_ivr_bridge.c @@ -515,12 +515,6 @@ static void *audio_bridge_thread(switch_thread_t *thread, void *obj) switch_safe_free(stream.data); } - - msg.string_arg = data->b_uuid; - msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE; - msg.from = __FILE__; - switch_core_session_receive_message(session_a, &msg); - if (!inner_bridge && switch_channel_up(chan_a)) { if ((app_name = switch_channel_get_variable(chan_a, SWITCH_EXEC_AFTER_BRIDGE_APP_VARIABLE))) { switch_caller_extension_t *extension = NULL; @@ -1048,6 +1042,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses int inner_bridge = switch_channel_test_flag(caller_channel, CF_INNER_BRIDGE); const char *var; switch_call_cause_t cause; + switch_core_session_message_t msg = { 0 }; if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE)) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Call has no media... Redirecting to signal bridge.\n"); @@ -1084,7 +1079,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses if (switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA) || switch_channel_test_flag(peer_channel, CF_RING_READY)) { - switch_core_session_message_t msg = { 0 }; const char *app, *data; switch_channel_set_state(peer_channel, CS_CONSUME_MEDIA); @@ -1250,6 +1244,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses switch_event_fire(&event); } + msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE; + msg.from = __FILE__; + msg.string_arg = switch_core_session_strdup(peer_session, switch_core_session_get_uuid(session)); + switch_core_session_receive_message(peer_session, &msg); + + msg.string_arg = switch_core_session_strdup(session, switch_core_session_get_uuid(peer_session)); + switch_core_session_receive_message(session, &msg); + state = switch_channel_get_state(caller_channel); From 634ca37067e0b4870527c17e9d814a157971517a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 12:40:41 -0500 Subject: [PATCH 23/68] fifo up --- src/mod/applications/mod_fifo/mod_fifo.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 41b3213588..262fa0fbdc 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -756,7 +756,6 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ } sql = switch_mprintf("update fifo_outbound set %s=%s+1,%s=%s+1 where uuid='%q'", col1, col1, col2, col2, outbound_id); - printf("WTF [%s]\n", sql); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); From 8ceb2a9b279a39cdf932722d852cb2e4e05b8db0 Mon Sep 17 00:00:00 2001 From: Marc Olivier Chouinard Date: Wed, 14 Jul 2010 14:29:24 -0400 Subject: [PATCH 24/68] mod_commands: Fix a segfault if no arguments is provided to limit_hash_usage --- src/mod/applications/mod_commands/mod_commands.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 29d7d17140..800923fcc5 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -4279,12 +4279,17 @@ end: return SWITCH_STATUS_SUCCESS; } -#define LIMIT_HASH_USAGE_USAGE " [rate]" +#define LIMIT_HASH_USAGE_USAGE " [rate] (Using deprecated limit api, check limit_usage with backend param)" SWITCH_STANDARD_API(limit_hash_usage_function) { char *mydata = NULL; - mydata = switch_core_session_sprintf(session, "hash %s", cmd); - return limit_usage_function(mydata, session, stream); + if (!zstr(cmd)) { + mydata = switch_core_session_sprintf(session, "hash %s", cmd); + return limit_usage_function(mydata, session, stream); + } else { + stream->write_function(stream, "USAGE: limit_hash_usage %s\n", LIMIT_HASH_USAGE_USAGE); + return SWITCH_STATUS_SUCCESS; + } } #define LIMIT_STATUS_USAGE "" From c50f59e36c4e941a14689877b7daf62aa958cc89 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 15:47:41 -0500 Subject: [PATCH 25/68] add reporting vars --- src/mod/applications/mod_fifo/mod_fifo.c | 63 ++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 262fa0fbdc..81f2b2629f 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -710,6 +710,11 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ case SWITCH_MESSAGE_INDICATE_BRIDGE: { const char *col1 = NULL, *col2 = NULL; + long epoch_start = 0; + char date[80] = ""; + switch_time_t ts; + switch_time_exp_t tm; + switch_size_t retsize; if (switch_true(switch_channel_get_variable(channel, "fifo_bridged"))) { return SWITCH_STATUS_SUCCESS; @@ -760,6 +765,29 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_safe_free(sql); + epoch_start = (long)switch_epoch_time_now(NULL); + + ts = switch_micro_time_now(); + switch_time_exp_lt(&tm, ts); + epoch_start = (long)switch_epoch_time_now(NULL); + switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm); + switch_channel_set_variable(consumer_channel, "fifo_status", "TALKING"); + switch_channel_set_variable(consumer_channel, "fifo_target", switch_core_session_get_uuid(caller_session)); + switch_channel_set_variable(consumer_channel, "fifo_timestamp", date); + switch_channel_set_variable_printf(consumer_channel, "fifo_epoch_start_bridge", "%ld", epoch_start); + switch_channel_set_variable(consumer_channel, "fifo_role", "consumer"); + + switch_channel_set_variable(caller_channel, "fifo_status", "TALKING"); + switch_channel_set_variable(caller_channel, "fifo_timestamp", date); + switch_channel_set_variable_printf(caller_channel, "fifo_epoch_start_bridge", "%ld", epoch_start); + switch_channel_set_variable(caller_channel, "fifo_target", switch_core_session_get_uuid(session)); + switch_channel_set_variable(caller_channel, "fifo_role", "caller"); + + + + switch_channel_set_variable(consumer_channel, "fifo_role", "consumer"); + switch_channel_set_variable(caller_channel, "fifo_role", "caller"); + switch_channel_set_variable(consumer_channel, "fifo_bridged", "true"); switch_channel_set_variable(consumer_channel, "fifo_manual_bridge", "true"); @@ -772,24 +800,37 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_time_exp_t tm; switch_time_t ts = switch_micro_time_now(); switch_size_t retsize; - + long epoch_start = 0, epoch_end = 0; + const char *epoch_start_a = NULL; + switch_channel_set_variable(channel, "fifo_bridged", NULL); ts = switch_micro_time_now(); switch_time_exp_lt(&tm, ts); switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm); - + sql = switch_mprintf("delete from fifo_bridge where consumer_uuid='%q'", switch_core_session_get_uuid(consumer_session)); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); switch_channel_set_variable(consumer_channel, "fifo_status", "WAITING"); switch_channel_set_variable(consumer_channel, "fifo_timestamp", date); - + switch_channel_set_variable(caller_channel, "fifo_status", "DONE"); switch_channel_set_variable(caller_channel, "fifo_timestamp", date); + if ((epoch_start_a = switch_channel_get_variable(consumer_channel, "fifo_epoch_start_bridge"))) { + epoch_start = atol(epoch_start_a); + } + + epoch_end = (long)switch_epoch_time_now(NULL); + switch_channel_set_variable_printf(consumer_channel, "fifo_epoch_stop_bridge", "%ld", epoch_end); + switch_channel_set_variable_printf(consumer_channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start); + + switch_channel_set_variable_printf(caller_channel, "fifo_epoch_stop_bridge", "%ld", epoch_end); + switch_channel_set_variable_printf(caller_channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start); + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { switch_channel_event_set_data(consumer_channel, event); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); @@ -2207,7 +2248,8 @@ SWITCH_STANDARD_APP(fifo_function) const char *record_template = switch_channel_get_variable(channel, "fifo_record_template"); char *expanded = NULL; char *sql = NULL; - + long epoch_start, epoch_end; + 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); @@ -2274,14 +2316,19 @@ SWITCH_STANDARD_APP(fifo_function) ts = switch_micro_time_now(); switch_time_exp_lt(&tm, ts); + epoch_start = (long)switch_epoch_time_now(NULL); switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm); switch_channel_set_variable(channel, "fifo_status", "TALKING"); switch_channel_set_variable(channel, "fifo_target", caller_uuid); switch_channel_set_variable(channel, "fifo_timestamp", date); + switch_channel_set_variable_printf(channel, "fifo_epoch_start_bridge", "%ld", epoch_start); + switch_channel_set_variable(channel, "fifo_role", "consumer"); switch_channel_set_variable(other_channel, "fifo_status", "TALKING"); switch_channel_set_variable(other_channel, "fifo_timestamp", date); + switch_channel_set_variable_printf(other_channel, "fifo_epoch_start_bridge", "%ld", epoch_start); switch_channel_set_variable(other_channel, "fifo_target", switch_core_session_get_uuid(session)); + switch_channel_set_variable(other_channel, "fifo_role", "caller"); send_presence(node); @@ -2355,6 +2402,14 @@ SWITCH_STANDARD_APP(fifo_function) switch_safe_free(sql); } + epoch_end = (long)switch_epoch_time_now(NULL); + + switch_channel_set_variable_printf(channel, "fifo_epoch_stop_bridge", "%ld", epoch_end); + switch_channel_set_variable_printf(channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start); + + switch_channel_set_variable_printf(other_channel, "fifo_epoch_stop_bridge", "%ld", epoch_end); + switch_channel_set_variable_printf(other_channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start); + sql = switch_mprintf("delete from fifo_bridge where consumer_uuid='%q'", switch_core_session_get_uuid(session)); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); From 76c4f2751c15ddd66aff44a28eb21cf3494a6d45 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 16:52:55 -0500 Subject: [PATCH 26/68] update --- src/mod/applications/mod_fifo/mod_fifo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 81f2b2629f..6a4e426d82 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -3218,7 +3218,7 @@ static switch_status_t load_config(int reload, int del_all) goto done; } - switch_cache_db_test_reactive(dbh, "delete from fifo_outbound where static = 1 or taking_calls < 0 or manual_calls_in < 0", "drop table fifo_outbound", outbound_sql); + switch_cache_db_test_reactive(dbh, "delete from fifo_outbound where static = 1 or taking_calls < 0 or manual_calls_in_total_count < 0", "drop table fifo_outbound", outbound_sql); switch_cache_db_test_reactive(dbh, "delete from fifo_bridge", "drop table fifo_bridge", bridge_sql); switch_cache_db_release_db_handle(&dbh); From 7339e6eb14f8e07037615d04a22718e1a54ca376 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 17:14:39 -0500 Subject: [PATCH 27/68] fix sql stmt --- src/mod/applications/mod_fifo/mod_fifo.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 6a4e426d82..0cfd2064cd 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -2663,10 +2663,19 @@ static int xml_outbound(switch_xml_t xml, fifo_node_t *node, char *container, ch char *sql; if (!strcmp(node->name, MANUAL_QUEUE_NAME)) { - sql = strdup("select uuid, fifo_name, originate_string, simo_count, use_count, timeout, " - "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, " - "hostname, taking_calls, status, outbound_call_total_count, outbound_fail_total_count, active_time, inactive_time, " - "manual_calls_out_count, manual_calls_in_count, manual_calls_out_total_count, manual_calls_in_total_count from fifo_outbound"); + + sql = switch_mprintf("select uuid, '%s', originate_string, simo_count, use_count, timeout," + "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count," + "hostname, taking_calls, status, outbound_call_total_count, outbound_fail_total_count, active_time, inactive_time," + "manual_calls_out_count, manual_calls_in_count, manual_calls_out_total_count, manual_calls_in_total_count from fifo_outbound " + "group by " + "uuid, originate_string, simo_count, use_count, timeout," + "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count," + "hostname, taking_calls, status, outbound_call_total_count, outbound_fail_total_count, active_time, inactive_time," + "manual_calls_out_count, manual_calls_in_count, manual_calls_out_total_count, manual_calls_in_total_count", + MANUAL_QUEUE_NAME); + + } else { sql = switch_mprintf("select uuid, fifo_name, originate_string, simo_count, use_count, timeout, " "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, " From 62d0aa3ec387587844765e3edc28b65635dcfded Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 17:49:44 -0500 Subject: [PATCH 28/68] add zstr --- src/mod/applications/mod_fifo/mod_fifo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 0cfd2064cd..00e28ed75f 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -1011,7 +1011,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void if (!switch_event_get_header(ovars, "origination_caller_id_name")) { if ((caller_id_name = switch_event_get_header(pop, "caller-caller-id-name"))) { - if (node->outbound_name) { + if (!zstr(node->outbound_name)) { switch_event_add_header(ovars, SWITCH_STACK_BOTTOM, "origination_caller_id_name", "(%s) %s", node->outbound_name, caller_id_name); } else { switch_event_add_header_string(ovars, SWITCH_STACK_BOTTOM, "origination_caller_id_name", caller_id_name); @@ -1173,7 +1173,7 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) originate_string = switch_mprintf("{execute_on_answer='unset fifo_hangup_check',fifo_hangup_check='%q'}%s", node->name, h->originate_string); } else { - if (node->outbound_name) { + if (!zstr(node->outbound_name)) { originate_string = switch_mprintf("{execute_on_answer='unset fifo_hangup_check',fifo_hangup_check='%q'," "origination_caller_id_name=Queue,origination_caller_id_number='Queue: %q'}%s", node->name, node->outbound_name, h->originate_string); @@ -3304,7 +3304,7 @@ static switch_status_t load_config(int reload, int del_all) node = create_node(name, imp, globals.sql_mutex); } - if ((val = switch_xml_attr(fifo, "outbound_name"))) { + if ((val = switch_xml_attr(fifo, "outbound_name")) && !zstr(val)) { node->outbound_name = switch_core_strdup(node->pool, val); } From e12be241194a34ac66319b141b3d97ca534efc8a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 18:11:07 -0500 Subject: [PATCH 29/68] typo --- src/mod/applications/mod_fifo/mod_fifo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 00e28ed75f..6162bb4ad8 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -726,14 +726,14 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { switch_channel_event_set_data(consumer_channel, event); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-start"); switch_event_fire(&event); } 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-start"); switch_event_fire(&event); } @@ -2344,13 +2344,13 @@ SWITCH_STANDARD_APP(fifo_function) 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-start"); switch_event_fire(&event); } 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-start"); switch_event_fire(&event); } From 28bc54a08d37b78239b1009f92a8a43a8b9bb7a9 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 18:59:42 -0500 Subject: [PATCH 30/68] skip runs when messages are not needed --- src/mod/applications/mod_fifo/mod_fifo.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 6162bb4ad8..6ab262253f 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -688,6 +688,14 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ const char *outbound_id; char *sql; + switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_BRIDGE: + case SWITCH_MESSAGE_INDICATE_UNBRIDGE: + break; + default: + return SWITCH_STATUS_SUCCESS; + } + channel = switch_core_session_get_channel(session); outbound_id = switch_channel_get_variable(channel, "fifo_outbound_uuid"); From ea6a549003aa1de98a6afd4a6bc113b11c028510 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 19:38:40 -0500 Subject: [PATCH 31/68] update --- src/mod/applications/mod_fifo/mod_fifo.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 6ab262253f..8fc0d50ec2 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -715,6 +715,10 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_DISPLAY: + sql = switch_mprintf("update fifo_bridge set caller_caller_id_name='%q', caller_caller_id_number='%q' where consumer_uuid='%q'", + switch_core_session_get_uuid(session)); + break; case SWITCH_MESSAGE_INDICATE_BRIDGE: { const char *col1 = NULL, *col2 = NULL; @@ -723,7 +727,8 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_time_t ts; switch_time_exp_t tm; switch_size_t retsize; - + const char *cid_name, *cid_number; + if (switch_true(switch_channel_get_variable(channel, "fifo_bridged"))) { return SWITCH_STATUS_SUCCESS; } @@ -745,13 +750,25 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_event_fire(&event); } + cid_name = switch_channel_get_variable(consumer_channel, "callee_id_name"); + cid_number = switch_channel_get_variable(consumer_channel, "callee_id_number"); + + if (zstr(cid_name)) { + cid_name = cid_number; + } + + if (zstr(cid_number)) { + cid_name = switch_channel_get_variable(consumer_channel, "destination_number"); + cid_number = cid_name; + } + sql = switch_mprintf("insert into fifo_bridge " "(fifo_name,caller_uuid,caller_caller_id_name,caller_caller_id_number,consumer_uuid,consumer_outgoing_uuid,bridge_start) " "values ('%q','%q','%q','%q','%q','%q',%ld)", MANUAL_QUEUE_NAME, switch_core_session_get_uuid(other_session), - switch_str_nil(switch_channel_get_variable(other_channel, "caller_id_name")), - switch_str_nil(switch_channel_get_variable(other_channel, "caller_id_number")), + cid_name, + cid_number, switch_core_session_get_uuid(session), switch_str_nil(outbound_id), (long) switch_epoch_time_now(NULL) From 6b19019aadc6fc0097701047f68305d333abe20f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 19:43:31 -0500 Subject: [PATCH 32/68] update --- src/mod/applications/mod_fifo/mod_fifo.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 8fc0d50ec2..06a576d862 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -691,6 +691,7 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_BRIDGE: case SWITCH_MESSAGE_INDICATE_UNBRIDGE: + case SWITCH_MESSAGE_INDICATE_DISPLAY: break; default: return SWITCH_STATUS_SUCCESS; @@ -718,7 +719,9 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ case SWITCH_MESSAGE_INDICATE_DISPLAY: sql = switch_mprintf("update fifo_bridge set caller_caller_id_name='%q', caller_caller_id_number='%q' where consumer_uuid='%q'", switch_core_session_get_uuid(session)); - break; + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + return SWITCH_STATUS_SUCCESS; case SWITCH_MESSAGE_INDICATE_BRIDGE: { const char *col1 = NULL, *col2 = NULL; From 395dc14a8df70d8ee795b4d559f9cd60cb1f66e0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 19:47:43 -0500 Subject: [PATCH 33/68] update --- src/mod/applications/mod_fifo/mod_fifo.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 06a576d862..455305d965 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -730,7 +730,7 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_time_t ts; switch_time_exp_t tm; switch_size_t retsize; - const char *cid_name, *cid_number; + const char *ced_name, *ced_number, *cid_name, *cid_number; if (switch_true(switch_channel_get_variable(channel, "fifo_bridged"))) { return SWITCH_STATUS_SUCCESS; @@ -753,16 +753,19 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_event_fire(&event); } - cid_name = switch_channel_get_variable(consumer_channel, "callee_id_name"); - cid_number = switch_channel_get_variable(consumer_channel, "callee_id_number"); + ced_name = switch_channel_get_variable(consumer_channel, "callee_id_name"); + ced_number = switch_channel_get_variable(consumer_channel, "callee_id_number"); - if (zstr(cid_name)) { - cid_name = cid_number; + cid_name = switch_channel_get_variable(consumer_channel, "caller_id_name"); + cid_number = switch_channel_get_variable(consumer_channel, "caller_id_number"); + + if (zstr(ced_name) || !strcmp(ced_name, cid_name)) { + ced_name = ced_number; } - if (zstr(cid_number)) { - cid_name = switch_channel_get_variable(consumer_channel, "destination_number"); - cid_number = cid_name; + if (zstr(ced_number) || !strcmp(ced_number, cid_number)) { + ced_name = switch_channel_get_variable(consumer_channel, "destination_number"); + ced_number = ced_name; } sql = switch_mprintf("insert into fifo_bridge " @@ -770,8 +773,8 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ "values ('%q','%q','%q','%q','%q','%q',%ld)", MANUAL_QUEUE_NAME, switch_core_session_get_uuid(other_session), - cid_name, - cid_number, + ced_name, + ced_number, switch_core_session_get_uuid(session), switch_str_nil(outbound_id), (long) switch_epoch_time_now(NULL) From c3dcc603b1e3fc4ab2518c2de966aa5799ff44e1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 15 Jul 2010 01:00:08 -0500 Subject: [PATCH 34/68] fifo update --- src/include/private/switch_core_pvt.h | 1 + src/include/switch_core.h | 6 + .../applications/mod_dptools/mod_dptools.c | 18 +- src/mod/applications/mod_fifo/mod_fifo.c | 217 +++++++++--------- src/switch_core_session.c | 25 ++ 5 files changed, 156 insertions(+), 111 deletions(-) diff --git a/src/include/private/switch_core_pvt.h b/src/include/private/switch_core_pvt.h index bc174c67eb..50dde95dc7 100644 --- a/src/include/private/switch_core_pvt.h +++ b/src/include/private/switch_core_pvt.h @@ -166,6 +166,7 @@ struct switch_core_session { uint32_t track_duration; uint32_t track_id; switch_log_level_t loglevel; + uint32_t soft_lock; }; struct switch_media_bug { diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 9d7d02b6e1..3cd9d46d7f 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -483,6 +483,7 @@ SWITCH_DECLARE(unsigned int) switch_core_session_started(_In_ switch_core_sessio SWITCH_DECLARE(void *) switch_core_perform_permanent_alloc(_In_ switch_size_t memory, _In_z_ const char *file, _In_z_ const char *func, _In_ int line); + /*! \brief Allocate memory from the main pool with no intention of returning it \param _memory the number of bytes to allocate @@ -698,6 +699,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_loglevel(switch_core_ses */ SWITCH_DECLARE(switch_log_level_t) switch_core_session_get_loglevel(switch_core_session_t *session); + +SWITCH_DECLARE(void) switch_core_session_soft_lock(switch_core_session_t *session, uint32_t sec); +SWITCH_DECLARE(void) switch_core_session_soft_unlock(switch_core_session_t *session); + + /*! \brief Retrieve the unique identifier from the core \return a string representing the uuid diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index a394d64a9a..00dcda3c08 100755 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -2688,20 +2688,22 @@ static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session, } + switch_event_create(¶ms, SWITCH_EVENT_REQUEST_PARAMS); + switch_assert(params); + switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "as_channel", "true"); + switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "action", "user_call"); + + if (var_event) { + switch_event_merge(params, var_event); + } + if (var_event && (skip = switch_event_get_header(var_event, "user_recurse_variables")) && switch_false(skip)) { if ((var = switch_event_get_header(var_event, SWITCH_CALL_TIMEOUT_VARIABLE)) || (var = switch_event_get_header(var_event, "leg_timeout"))) { timelimit = atoi(var); } var_event = NULL; } - - - - switch_event_create(¶ms, SWITCH_EVENT_REQUEST_PARAMS); - switch_assert(params); - switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "as_channel", "true"); - switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "action", "user_call"); - + if (switch_xml_locate_user("id", user, domain, NULL, &xml, &x_domain, &x_user, &x_group, params) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Can't find user [%s@%s]\n", user, domain); cause = SWITCH_CAUSE_SUBSCRIBER_ABSENT; diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 455305d965..079dacc7fc 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -683,45 +683,41 @@ struct callback_helper { static switch_status_t messagehook (switch_core_session_t *session, switch_core_session_message_t *msg) { switch_event_t *event; - switch_core_session_t *other_session, *caller_session, *consumer_session; - switch_channel_t *channel, *other_channel, *caller_channel, *consumer_channel; + switch_core_session_t *caller_session = NULL, *consumer_session = NULL; + switch_channel_t *caller_channel = NULL, *consumer_channel = NULL; const char *outbound_id; char *sql; + consumer_session = session; + consumer_channel = switch_core_session_get_channel(consumer_session); + switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_BRIDGE: case SWITCH_MESSAGE_INDICATE_UNBRIDGE: - case SWITCH_MESSAGE_INDICATE_DISPLAY: - break; - default: - return SWITCH_STATUS_SUCCESS; - } - - channel = switch_core_session_get_channel(session); - outbound_id = switch_channel_get_variable(channel, "fifo_outbound_uuid"); - - if ((other_session = switch_core_session_force_locate(msg->string_arg))) { - - other_channel = switch_core_session_get_channel(other_session); - - consumer_channel = channel; - caller_channel = other_channel; - - consumer_session = session; - caller_session = other_session; - - } else { - return SWITCH_STATUS_SUCCESS; - } - - - switch (msg->message_id) { + if ((caller_session = switch_core_session_force_locate(msg->string_arg))) { + caller_channel = switch_core_session_get_channel(caller_session); + if (msg->message_id == SWITCH_MESSAGE_INDICATE_BRIDGE) { + switch_core_session_soft_lock(caller_session, 3); + } else { + switch_core_session_soft_unlock(caller_session); + } + } + break; case SWITCH_MESSAGE_INDICATE_DISPLAY: sql = switch_mprintf("update fifo_bridge set caller_caller_id_name='%q', caller_caller_id_number='%q' where consumer_uuid='%q'", + switch_str_nil(msg->string_array_arg[0]), + switch_str_nil(msg->string_array_arg[1]), switch_core_session_get_uuid(session)); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); - return SWITCH_STATUS_SUCCESS; + goto end; + default: + goto end; + } + + outbound_id = switch_channel_get_variable(consumer_channel, "fifo_outbound_uuid"); + + switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_BRIDGE: { const char *col1 = NULL, *col2 = NULL; @@ -731,48 +727,62 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_time_exp_t tm; switch_size_t retsize; const char *ced_name, *ced_number, *cid_name, *cid_number; - - if (switch_true(switch_channel_get_variable(channel, "fifo_bridged"))) { - return SWITCH_STATUS_SUCCESS; + + if (switch_channel_test_app_flag(consumer_channel, CF_APP_TAGGED)) { + goto end; } + switch_channel_set_app_flag(consumer_channel, CF_APP_TAGGED); + + switch_channel_set_variable(consumer_channel, "fifo_bridged", "true"); + switch_channel_set_variable(consumer_channel, "fifo_manual_bridge", "true"); + switch_channel_set_variable(consumer_channel, "fifo_role", "consumer"); + switch_channel_set_variable(caller_channel, "fifo_role", "caller"); + switch_process_import(consumer_session, caller_channel, "fifo_caller_consumer_import"); switch_process_import(caller_session, consumer_channel, "fifo_consumer_caller_import"); - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(consumer_channel, event); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-start"); - switch_event_fire(&event); - } - - 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-start"); - switch_event_fire(&event); - } - ced_name = switch_channel_get_variable(consumer_channel, "callee_id_name"); ced_number = switch_channel_get_variable(consumer_channel, "callee_id_number"); cid_name = switch_channel_get_variable(consumer_channel, "caller_id_name"); cid_number = switch_channel_get_variable(consumer_channel, "caller_id_number"); - - if (zstr(ced_name) || !strcmp(ced_name, cid_name)) { - ced_name = ced_number; - } - if (zstr(ced_number) || !strcmp(ced_number, cid_number)) { - ced_name = switch_channel_get_variable(consumer_channel, "destination_number"); - ced_number = ced_name; + if (switch_channel_direction(consumer_channel) == SWITCH_CALL_DIRECTION_INBOUND) { + if (zstr(ced_name) || !strcmp(ced_name, cid_name)) { + ced_name = ced_number; + } + + if (zstr(ced_number) || !strcmp(ced_number, cid_number)) { + ced_name = switch_channel_get_variable(consumer_channel, "destination_number"); + ced_number = ced_name; + } + } else { + ced_name = cid_name; + ced_number = cid_number; + } + + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + switch_channel_event_set_data(consumer_channel, event); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-start"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Caller-CID-Name", ced_name); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Caller-CID-Number", ced_number); + switch_event_fire(&event); + } + + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + switch_channel_event_set_data(caller_channel, event); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-start"); + switch_event_fire(&event); } sql = switch_mprintf("insert into fifo_bridge " "(fifo_name,caller_uuid,caller_caller_id_name,caller_caller_id_number,consumer_uuid,consumer_outgoing_uuid,bridge_start) " "values ('%q','%q','%q','%q','%q','%q',%ld)", MANUAL_QUEUE_NAME, - switch_core_session_get_uuid(other_session), + switch_core_session_get_uuid(caller_session), ced_name, ced_number, switch_core_session_get_uuid(session), @@ -813,20 +823,11 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_channel_set_variable_printf(caller_channel, "fifo_epoch_start_bridge", "%ld", epoch_start); switch_channel_set_variable(caller_channel, "fifo_target", switch_core_session_get_uuid(session)); switch_channel_set_variable(caller_channel, "fifo_role", "caller"); - - - - switch_channel_set_variable(consumer_channel, "fifo_role", "consumer"); - switch_channel_set_variable(caller_channel, "fifo_role", "caller"); - - switch_channel_set_variable(consumer_channel, "fifo_bridged", "true"); - switch_channel_set_variable(consumer_channel, "fifo_manual_bridge", "true"); - } break; case SWITCH_MESSAGE_INDICATE_UNBRIDGE: { - if (switch_true(switch_channel_get_variable(channel, "fifo_bridged"))) { + if (switch_channel_test_app_flag(consumer_channel, CF_APP_TAGGED)) { char date[80] = ""; switch_time_exp_t tm; switch_time_t ts = switch_micro_time_now(); @@ -834,7 +835,8 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ long epoch_start = 0, epoch_end = 0; const char *epoch_start_a = NULL; - switch_channel_set_variable(channel, "fifo_bridged", NULL); + switch_channel_clear_app_flag(consumer_channel, CF_APP_TAGGED); + switch_channel_set_variable(consumer_channel, "fifo_bridged", NULL); ts = switch_micro_time_now(); switch_time_exp_lt(&tm, ts); @@ -847,8 +849,10 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_channel_set_variable(consumer_channel, "fifo_status", "WAITING"); switch_channel_set_variable(consumer_channel, "fifo_timestamp", date); - switch_channel_set_variable(caller_channel, "fifo_status", "DONE"); - switch_channel_set_variable(caller_channel, "fifo_timestamp", date); + if (caller_channel) { + switch_channel_set_variable(caller_channel, "fifo_status", "DONE"); + switch_channel_set_variable(caller_channel, "fifo_timestamp", date); + } if ((epoch_start_a = switch_channel_get_variable(consumer_channel, "fifo_epoch_start_bridge"))) { epoch_start = atol(epoch_start_a); @@ -859,9 +863,11 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_channel_set_variable_printf(consumer_channel, "fifo_epoch_stop_bridge", "%ld", epoch_end); switch_channel_set_variable_printf(consumer_channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start); - switch_channel_set_variable_printf(caller_channel, "fifo_epoch_stop_bridge", "%ld", epoch_end); - switch_channel_set_variable_printf(caller_channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start); - + if (caller_channel) { + switch_channel_set_variable_printf(caller_channel, "fifo_epoch_stop_bridge", "%ld", epoch_end); + switch_channel_set_variable_printf(caller_channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start); + } + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { switch_channel_event_set_data(consumer_channel, event); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); @@ -869,11 +875,13 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_event_fire(&event); } - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(caller_channel, event); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-stop"); - switch_event_fire(&event); + if (caller_channel) { + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + switch_channel_event_set_data(caller_channel, event); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-stop"); + switch_event_fire(&event); + } } if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { @@ -890,23 +898,26 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ break; } - if (other_session) { - switch_core_session_rwunlock(other_session); + end: + + if (caller_session) { + switch_core_session_rwunlock(caller_session); } return SWITCH_STATUS_SUCCESS; } + static switch_status_t hanguphook(switch_core_session_t *session) { switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_state_t state = switch_channel_get_state(channel); const char *uuid = NULL; char sql[512] = ""; - switch_core_session_message_t msg = { 0 }; if (state == CS_HANGUP || state == CS_ROUTING) { if ((uuid = switch_channel_get_variable(channel, "fifo_outbound_uuid"))) { + if ((switch_true(switch_channel_get_variable(channel, "fifo_manual_bridge")))) { switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, " "next_avail=%ld + lag where uuid='%s' and use_count > 0", @@ -920,25 +931,23 @@ static switch_status_t hanguphook(switch_core_session_t *session) } fifo_execute_sql(sql, globals.sql_mutex); - } - switch_core_event_hook_remove_state_change(session, hanguphook); - switch_core_event_hook_remove_receive_message(session, messagehook); - - if (switch_true(switch_channel_get_variable(channel, "fifo_bridged"))) { - msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE; - msg.from = __FILE__; - msg.string_arg = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE); - - if (msg.string_arg && switch_ivr_uuid_exists(msg.string_arg)) { - messagehook(session, &msg); - } } - - } return SWITCH_STATUS_SUCCESS; } +static switch_status_t r_hanguphook(switch_core_session_t *session) +{ + + switch_channel_t *channel = switch_core_session_get_channel(session); + switch_channel_state_t state = switch_channel_get_state(channel); + + if (state == CS_HANGUP || state == CS_ROUTING) { + hanguphook(session); + switch_core_event_hook_remove_state_change(session, r_hanguphook); + } + return SWITCH_STATUS_SUCCESS; +} static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void *obj) { @@ -1062,6 +1071,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_event_add_header_string(ovars, SWITCH_STACK_BOTTOM, "fifo_originate_uuid", uuid_str); + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { switch_core_session_t *session; if (id && (session = switch_core_session_locate(id))) { @@ -1137,7 +1147,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_channel_set_variable(channel, "fifo_pop_order", NULL); - switch_core_event_hook_add_state_change(session, hanguphook); + switch_core_event_hook_add_state_change(session, r_hanguphook); app_name = "fifo"; arg = switch_core_session_sprintf(session, "%s out nowait", node_name); @@ -1277,7 +1287,7 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) } } - switch_core_event_hook_add_state_change(session, hanguphook); + switch_core_event_hook_add_state_change(session, r_hanguphook); switch_channel_set_variable(channel, "fifo_outbound_uuid", h->uuid); app_name = "fifo"; arg = switch_core_session_sprintf(session, "%s out %s", h->node_name, member_wait ? member_wait : "wait"); @@ -1661,9 +1671,9 @@ SWITCH_STANDARD_APP(fifo_member_usage_function) switch_channel_set_variable(channel, "fifo_outbound_uuid", data); sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,outbound_fail_count=0 where uuid='%s'", data); - fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); + switch_core_event_hook_add_receive_message(session, messagehook); switch_core_event_hook_add_state_change(session, hanguphook); @@ -2410,6 +2420,16 @@ SWITCH_STANDARD_APP(fifo_function) switch_ivr_multi_threaded_bridge(session, other_session, on_dtmf, other_session, session); + if (outbound_id && do_track) { + sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, outbound_call_total_count=outbound_call_total_count+1 " + "outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", + (long) switch_epoch_time_now(NULL), outbound_id); + + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + } + + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { switch_channel_event_set_data(channel, event); @@ -2423,15 +2443,6 @@ SWITCH_STANDARD_APP(fifo_function) switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-stop"); switch_event_fire(&event); } - - if (outbound_id && do_track) { - sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, outbound_call_total_count=outbound_call_total_count+1 " - "outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", - (long) switch_epoch_time_now(NULL), outbound_id); - - fifo_execute_sql(sql, globals.sql_mutex); - switch_safe_free(sql); - } epoch_end = (long)switch_epoch_time_now(NULL); diff --git a/src/switch_core_session.c b/src/switch_core_session.c index ea5ecc119b..45c83de320 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -38,6 +38,16 @@ struct switch_session_manager session_manager; +SWITCH_DECLARE(void) switch_core_session_soft_lock(switch_core_session_t *session, uint32_t sec) +{ + session->soft_lock = sec; +} + +SWITCH_DECLARE(void) switch_core_session_soft_unlock(switch_core_session_t *session) +{ + session->soft_lock = 0; +} + #ifdef SWITCH_DEBUG_RWLOCKS SWITCH_DECLARE(switch_core_session_t *) switch_core_session_perform_locate(const char *uuid_str, const char *file, const char *func, int line) #else @@ -1174,6 +1184,21 @@ static void *SWITCH_THREAD_FUNC switch_core_session_thread(switch_thread_t *thre switch_core_session_run(session); switch_core_media_bug_remove_all(session); + + if (session->soft_lock) { + uint32_t loops = session->soft_lock * 10; + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Session %" SWITCH_SIZE_T_FMT " (%s) Soft-Locked, " + "Waiting %u for external entities\n", + session->id, switch_channel_get_name(session->channel), session->soft_lock); + + while(--loops > 0) { + if (!session->soft_lock) break; + switch_yield(100000); + } + + } + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Session %" SWITCH_SIZE_T_FMT " (%s) Locked, Waiting on external entities\n", session->id, switch_channel_get_name(session->channel)); switch_core_session_write_lock(session); From 5cd072a3fb3a70611eaddb9f7e503d83c5b1e4ba Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 15 Jul 2010 08:42:51 -0500 Subject: [PATCH 35/68] allow vars to be set containing vars from languages --- src/mod/languages/mod_spidermonkey/mod_spidermonkey.c | 2 +- src/switch_cpp.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c index ccaba559fd..177b5586a1 100644 --- a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c +++ b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c @@ -1823,7 +1823,7 @@ static JSBool session_set_variable(JSContext * cx, JSObject * obj, uintN argc, j var = JS_GetStringBytes(JS_ValueToString(cx, argv[0])); val = JS_GetStringBytes(JS_ValueToString(cx, argv[1])); - switch_channel_set_variable(channel, var, val); + switch_channel_set_variable_var_check(channel, var, val, SWITCH_FALSE); *rval = BOOLEAN_TO_JSVAL(JS_TRUE); } else { *rval = BOOLEAN_TO_JSVAL(JS_FALSE); diff --git a/src/switch_cpp.cpp b/src/switch_cpp.cpp index ec4c9c40b4..5368cdddeb 100644 --- a/src/switch_cpp.cpp +++ b/src/switch_cpp.cpp @@ -623,7 +623,7 @@ SWITCH_DECLARE(void) CoreSession::setVariable(char *var, char *val) { this_check_void(); sanity_check_noreturn; - switch_channel_set_variable(channel, var, val); + switch_channel_set_variable_var_check(channel, var, val, SWITCH_FALSE); } SWITCH_DECLARE(const char *)CoreSession::getVariable(char *var) From 41852592097986a4989e5a61e51a3b50a136026e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 12 Jul 2010 12:00:53 -0500 Subject: [PATCH 36/68] refactor --- src/mod/applications/mod_fifo/mod_fifo.c | 541 +++-------------------- 1 file changed, 72 insertions(+), 469 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 079dacc7fc..2e4df02e91 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -34,7 +34,6 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fifo_shutdown); SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load); SWITCH_MODULE_DEFINITION(mod_fifo, mod_fifo_load, mod_fifo_shutdown, NULL); -#define MANUAL_QUEUE_NAME "manual_calls" #define FIFO_EVENT "fifo::info" #define FIFO_DELAY_DESTROY 100 static switch_status_t load_config(int reload, int del_all); @@ -680,274 +679,6 @@ struct callback_helper { }; -static switch_status_t messagehook (switch_core_session_t *session, switch_core_session_message_t *msg) -{ - switch_event_t *event; - switch_core_session_t *caller_session = NULL, *consumer_session = NULL; - switch_channel_t *caller_channel = NULL, *consumer_channel = NULL; - const char *outbound_id; - char *sql; - - consumer_session = session; - consumer_channel = switch_core_session_get_channel(consumer_session); - - switch (msg->message_id) { - case SWITCH_MESSAGE_INDICATE_BRIDGE: - case SWITCH_MESSAGE_INDICATE_UNBRIDGE: - if ((caller_session = switch_core_session_force_locate(msg->string_arg))) { - caller_channel = switch_core_session_get_channel(caller_session); - if (msg->message_id == SWITCH_MESSAGE_INDICATE_BRIDGE) { - switch_core_session_soft_lock(caller_session, 3); - } else { - switch_core_session_soft_unlock(caller_session); - } - } - break; - case SWITCH_MESSAGE_INDICATE_DISPLAY: - sql = switch_mprintf("update fifo_bridge set caller_caller_id_name='%q', caller_caller_id_number='%q' where consumer_uuid='%q'", - switch_str_nil(msg->string_array_arg[0]), - switch_str_nil(msg->string_array_arg[1]), - switch_core_session_get_uuid(session)); - fifo_execute_sql(sql, globals.sql_mutex); - switch_safe_free(sql); - goto end; - default: - goto end; - } - - outbound_id = switch_channel_get_variable(consumer_channel, "fifo_outbound_uuid"); - - switch (msg->message_id) { - case SWITCH_MESSAGE_INDICATE_BRIDGE: - { - const char *col1 = NULL, *col2 = NULL; - long epoch_start = 0; - char date[80] = ""; - switch_time_t ts; - switch_time_exp_t tm; - switch_size_t retsize; - const char *ced_name, *ced_number, *cid_name, *cid_number; - - if (switch_channel_test_app_flag(consumer_channel, CF_APP_TAGGED)) { - goto end; - } - - switch_channel_set_app_flag(consumer_channel, CF_APP_TAGGED); - - switch_channel_set_variable(consumer_channel, "fifo_bridged", "true"); - switch_channel_set_variable(consumer_channel, "fifo_manual_bridge", "true"); - switch_channel_set_variable(consumer_channel, "fifo_role", "consumer"); - switch_channel_set_variable(caller_channel, "fifo_role", "caller"); - - switch_process_import(consumer_session, caller_channel, "fifo_caller_consumer_import"); - switch_process_import(caller_session, consumer_channel, "fifo_consumer_caller_import"); - - ced_name = switch_channel_get_variable(consumer_channel, "callee_id_name"); - ced_number = switch_channel_get_variable(consumer_channel, "callee_id_number"); - - cid_name = switch_channel_get_variable(consumer_channel, "caller_id_name"); - cid_number = switch_channel_get_variable(consumer_channel, "caller_id_number"); - - if (switch_channel_direction(consumer_channel) == SWITCH_CALL_DIRECTION_INBOUND) { - if (zstr(ced_name) || !strcmp(ced_name, cid_name)) { - ced_name = ced_number; - } - - if (zstr(ced_number) || !strcmp(ced_number, cid_number)) { - ced_name = switch_channel_get_variable(consumer_channel, "destination_number"); - ced_number = ced_name; - } - } else { - ced_name = cid_name; - ced_number = cid_number; - } - - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(consumer_channel, event); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-start"); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Caller-CID-Name", ced_name); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Caller-CID-Number", ced_number); - switch_event_fire(&event); - } - - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(caller_channel, event); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-start"); - switch_event_fire(&event); - } - - sql = switch_mprintf("insert into fifo_bridge " - "(fifo_name,caller_uuid,caller_caller_id_name,caller_caller_id_number,consumer_uuid,consumer_outgoing_uuid,bridge_start) " - "values ('%q','%q','%q','%q','%q','%q',%ld)", - MANUAL_QUEUE_NAME, - switch_core_session_get_uuid(caller_session), - ced_name, - ced_number, - switch_core_session_get_uuid(session), - switch_str_nil(outbound_id), - (long) switch_epoch_time_now(NULL) - ); - - fifo_execute_sql(sql, globals.sql_mutex); - switch_safe_free(sql); - - if (switch_channel_direction(consumer_channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { - col1 = "manual_calls_in_count"; - col2 = "manual_calls_in_total_count"; - } else { - col1 = "manual_calls_out_count"; - col2 = "manual_calls_out_total_count"; - } - - sql = switch_mprintf("update fifo_outbound set %s=%s+1,%s=%s+1 where uuid='%q'", col1, col1, col2, col2, outbound_id); - fifo_execute_sql(sql, globals.sql_mutex); - switch_safe_free(sql); - - - epoch_start = (long)switch_epoch_time_now(NULL); - - ts = switch_micro_time_now(); - switch_time_exp_lt(&tm, ts); - epoch_start = (long)switch_epoch_time_now(NULL); - switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm); - switch_channel_set_variable(consumer_channel, "fifo_status", "TALKING"); - switch_channel_set_variable(consumer_channel, "fifo_target", switch_core_session_get_uuid(caller_session)); - switch_channel_set_variable(consumer_channel, "fifo_timestamp", date); - switch_channel_set_variable_printf(consumer_channel, "fifo_epoch_start_bridge", "%ld", epoch_start); - switch_channel_set_variable(consumer_channel, "fifo_role", "consumer"); - - switch_channel_set_variable(caller_channel, "fifo_status", "TALKING"); - switch_channel_set_variable(caller_channel, "fifo_timestamp", date); - switch_channel_set_variable_printf(caller_channel, "fifo_epoch_start_bridge", "%ld", epoch_start); - switch_channel_set_variable(caller_channel, "fifo_target", switch_core_session_get_uuid(session)); - switch_channel_set_variable(caller_channel, "fifo_role", "caller"); - } - break; - case SWITCH_MESSAGE_INDICATE_UNBRIDGE: - { - if (switch_channel_test_app_flag(consumer_channel, CF_APP_TAGGED)) { - char date[80] = ""; - switch_time_exp_t tm; - switch_time_t ts = switch_micro_time_now(); - switch_size_t retsize; - long epoch_start = 0, epoch_end = 0; - const char *epoch_start_a = NULL; - - switch_channel_clear_app_flag(consumer_channel, CF_APP_TAGGED); - switch_channel_set_variable(consumer_channel, "fifo_bridged", NULL); - - ts = switch_micro_time_now(); - switch_time_exp_lt(&tm, ts); - switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm); - - sql = switch_mprintf("delete from fifo_bridge where consumer_uuid='%q'", switch_core_session_get_uuid(consumer_session)); - fifo_execute_sql(sql, globals.sql_mutex); - switch_safe_free(sql); - - switch_channel_set_variable(consumer_channel, "fifo_status", "WAITING"); - switch_channel_set_variable(consumer_channel, "fifo_timestamp", date); - - if (caller_channel) { - switch_channel_set_variable(caller_channel, "fifo_status", "DONE"); - switch_channel_set_variable(caller_channel, "fifo_timestamp", date); - } - - if ((epoch_start_a = switch_channel_get_variable(consumer_channel, "fifo_epoch_start_bridge"))) { - epoch_start = atol(epoch_start_a); - } - - epoch_end = (long)switch_epoch_time_now(NULL); - - switch_channel_set_variable_printf(consumer_channel, "fifo_epoch_stop_bridge", "%ld", epoch_end); - switch_channel_set_variable_printf(consumer_channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start); - - if (caller_channel) { - switch_channel_set_variable_printf(caller_channel, "fifo_epoch_stop_bridge", "%ld", epoch_end); - switch_channel_set_variable_printf(caller_channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start); - } - - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(consumer_channel, event); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-stop"); - switch_event_fire(&event); - } - - if (caller_channel) { - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(caller_channel, event); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-stop"); - switch_event_fire(&event); - } - } - - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(consumer_channel, event); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "consumer_stop"); - switch_event_fire(&event); - } - } - - } - break; - default: - break; - } - - end: - - if (caller_session) { - switch_core_session_rwunlock(caller_session); - } - - return SWITCH_STATUS_SUCCESS; -} - - -static switch_status_t hanguphook(switch_core_session_t *session) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_channel_state_t state = switch_channel_get_state(channel); - const char *uuid = NULL; - char sql[512] = ""; - - if (state == CS_HANGUP || state == CS_ROUTING) { - if ((uuid = switch_channel_get_variable(channel, "fifo_outbound_uuid"))) { - - if ((switch_true(switch_channel_get_variable(channel, "fifo_manual_bridge")))) { - switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, " - "next_avail=%ld + lag where uuid='%s' and use_count > 0", - (long)switch_epoch_time_now(NULL), uuid); - } else { - - switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, " - "outbound_call_count=outbound_call_count+1, " - "outbound_call_total_count=outbound_call_total_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", - (long)switch_epoch_time_now(NULL), uuid); - } - - fifo_execute_sql(sql, globals.sql_mutex); - } - } - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t r_hanguphook(switch_core_session_t *session) -{ - - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_channel_state_t state = switch_channel_get_state(channel); - - if (state == CS_HANGUP || state == CS_ROUTING) { - hanguphook(session); - switch_core_event_hook_remove_state_change(session, r_hanguphook); - } - return SWITCH_STATUS_SUCCESS; -} static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void *obj) { @@ -1031,7 +762,6 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void q = node->fifo_list[x]; if (fifo_queue_pop_nameval(q, "variable_fifo_vip", "true", &pop_dup, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS && pop_dup) { pop = pop_dup; - break; } } @@ -1040,7 +770,6 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void q = node->fifo_list[x]; if (fifo_queue_pop(node->fifo_list[x], &pop_dup, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS && pop_dup) { pop = pop_dup; - break; } } } @@ -1051,7 +780,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void if (!switch_event_get_header(ovars, "origination_caller_id_name")) { if ((caller_id_name = switch_event_get_header(pop, "caller-caller-id-name"))) { - if (!zstr(node->outbound_name)) { + if (node->outbound_name) { switch_event_add_header(ovars, SWITCH_STACK_BOTTOM, "origination_caller_id_name", "(%s) %s", node->outbound_name, caller_id_name); } else { switch_event_add_header_string(ovars, SWITCH_STACK_BOTTOM, "origination_caller_id_name", caller_id_name); @@ -1071,7 +800,6 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_event_add_header_string(ovars, SWITCH_STACK_BOTTOM, "fifo_originate_uuid", uuid_str); - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { switch_core_session_t *session; if (id && (session = switch_core_session_locate(id))) { @@ -1096,23 +824,13 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_event_fire(&event); } - for (i = 0; i < cbh->rowcount; i++) { - struct call_helper *h = cbh->rows[i]; - char *sql = switch_mprintf("update fifo_outbound set use_count=use_count+1 where uuid='%s'", h->uuid); - - fifo_execute_sql(sql, globals.sql_mutex); - switch_safe_free(sql); - - } - status = switch_ivr_originate(NULL, &session, &cause, originate_string, timeout, NULL, NULL, NULL, NULL, ovars, SOF_NONE, NULL); if (status != SWITCH_STATUS_SUCCESS) { for (i = 0; i < cbh->rowcount; i++) { struct call_helper *h = cbh->rows[i]; - char *sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, " - "outbound_fail_count=outbound_fail_count+1, next_avail=%ld + lag where uuid='%q' and use_count > 0", - (long) switch_epoch_time_now(NULL), h->uuid); + char *sql = switch_mprintf("update fifo_outbound set outbound_fail_count=outbound_fail_count+1, next_avail=%ld + lag where uuid='%q'", + (long) switch_epoch_time_now(NULL), h->uuid); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); @@ -1147,7 +865,6 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_channel_set_variable(channel, "fifo_pop_order", NULL); - switch_core_event_hook_add_state_change(session, r_hanguphook); app_name = "fifo"; arg = switch_core_session_sprintf(session, "%s out nowait", node_name); @@ -1193,7 +910,6 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) switch_event_t *ovars = NULL; switch_status_t status = SWITCH_STATUS_FALSE; switch_event_t *event = NULL; - char *sql = NULL; switch_mutex_lock(globals.mutex); node = switch_core_hash_find(globals.fifo_hash, h->node_name); @@ -1214,7 +930,7 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) originate_string = switch_mprintf("{execute_on_answer='unset fifo_hangup_check',fifo_hangup_check='%q'}%s", node->name, h->originate_string); } else { - if (!zstr(node->outbound_name)) { + if (node->outbound_name) { originate_string = switch_mprintf("{execute_on_answer='unset fifo_hangup_check',fifo_hangup_check='%q'," "origination_caller_id_name=Queue,origination_caller_id_number='Queue: %q'}%s", node->name, node->outbound_name, h->originate_string); @@ -1235,11 +951,6 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) switch_event_fire(&event); } - - sql = switch_mprintf("update fifo_outbound set use_count=use_count+1 where uuid='%s'", h->uuid); - fifo_execute_sql(sql, globals.sql_mutex); - switch_safe_free(sql); - status = switch_ivr_originate(NULL, &session, &cause, originate_string, h->timeout, NULL, NULL, NULL, NULL, ovars, SOF_NONE, NULL); free(originate_string); @@ -1247,12 +958,6 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) if (status != SWITCH_STATUS_SUCCESS) { - sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, " - "outbound_fail_count=outbound_fail_count+1, next_avail=%ld + lag where uuid='%q' and use_count > 0", - (long) switch_epoch_time_now(NULL), h->uuid); - fifo_execute_sql(sql, globals.sql_mutex); - switch_safe_free(sql); - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", node->name); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "post-dial"); @@ -1287,7 +992,6 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) } } - switch_core_event_hook_add_state_change(session, r_hanguphook); switch_channel_set_variable(channel, "fifo_outbound_uuid", h->uuid); app_name = "fifo"; arg = switch_core_session_sprintf(session, "%s out %s", h->node_name, member_wait ? member_wait : "wait"); @@ -1327,14 +1031,11 @@ static int place_call_ringall_callback(void *pArg, int argc, char **argv, char * cbh->rows[cbh->rowcount++] = h; + cbh->need--; + if (cbh->rowcount == MAX_ROWS) return -1; - - if (cbh->need) { - cbh->need--; - return cbh->need ? 0 : -1; - } - - return 0; + + return cbh->need ? 0 : -1; } @@ -1405,9 +1106,9 @@ static void find_consumers(fifo_node_t *node) switch_core_new_memory_pool(&pool); cbh = switch_core_alloc(pool, sizeof(*cbh)); cbh->pool = pool; - cbh->need = 1; + cbh->need = node_consumer_wait_count(node); - if (node->outbound_per_cycle != cbh->need) { + if (node->outbound_per_cycle && node->outbound_per_cycle < cbh->need) { cbh->need = node->outbound_per_cycle; } @@ -1659,6 +1360,27 @@ SWITCH_STANDARD_API(fifo_add_outbound_function) } +static switch_status_t hanguphook(switch_core_session_t *session) +{ + switch_channel_t *channel = switch_core_session_get_channel(session); + switch_channel_state_t state = switch_channel_get_state(channel); + const char *uuid = NULL; + char sql[256] = ""; + + if (state == CS_HANGUP || state == CS_ROUTING) { + if ((uuid = switch_channel_get_variable(channel, "fifo_outbound_uuid"))) { + switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, " + "outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s'", + (long)switch_epoch_time_now(NULL), uuid); + + fifo_execute_sql(sql, globals.sql_mutex); + } + switch_core_event_hook_remove_state_change(session, hanguphook); + } + return SWITCH_STATUS_SUCCESS; +} + + SWITCH_STANDARD_APP(fifo_member_usage_function) { char *sql; @@ -1671,10 +1393,10 @@ SWITCH_STANDARD_APP(fifo_member_usage_function) switch_channel_set_variable(channel, "fifo_outbound_uuid", data); sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,outbound_fail_count=0 where uuid='%s'", data); + fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); - switch_core_event_hook_add_receive_message(session, messagehook); switch_core_event_hook_add_state_change(session, hanguphook); } @@ -2040,9 +1762,8 @@ SWITCH_STANDARD_APP(fifo_function) const char *caller_uuid = NULL; switch_event_t *call_event; const char *outbound_id = switch_channel_get_variable(channel, "fifo_outbound_uuid"); - const char *track_use_count = switch_channel_get_variable(channel, "fifo_track_use_count"); - int do_track = switch_true(track_use_count); - + + if (!zstr(strat_str)) { if (!strcasecmp(strat_str, "more_ppl")) { strat = STRAT_MORE_PPL; @@ -2289,8 +2010,7 @@ SWITCH_STANDARD_APP(fifo_function) const char *record_template = switch_channel_get_variable(channel, "fifo_record_template"); char *expanded = NULL; char *sql = NULL; - long epoch_start, epoch_end; - + 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); @@ -2357,19 +2077,14 @@ SWITCH_STANDARD_APP(fifo_function) ts = switch_micro_time_now(); switch_time_exp_lt(&tm, ts); - epoch_start = (long)switch_epoch_time_now(NULL); switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm); switch_channel_set_variable(channel, "fifo_status", "TALKING"); switch_channel_set_variable(channel, "fifo_target", caller_uuid); switch_channel_set_variable(channel, "fifo_timestamp", date); - switch_channel_set_variable_printf(channel, "fifo_epoch_start_bridge", "%ld", epoch_start); - switch_channel_set_variable(channel, "fifo_role", "consumer"); switch_channel_set_variable(other_channel, "fifo_status", "TALKING"); switch_channel_set_variable(other_channel, "fifo_timestamp", date); - switch_channel_set_variable_printf(other_channel, "fifo_epoch_start_bridge", "%ld", epoch_start); switch_channel_set_variable(other_channel, "fifo_target", switch_core_session_get_uuid(session)); - switch_channel_set_variable(other_channel, "fifo_role", "caller"); send_presence(node); @@ -2385,17 +2100,17 @@ SWITCH_STANDARD_APP(fifo_function) 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-start"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer"); switch_event_fire(&event); } 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-start"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller"); switch_event_fire(&event); } - if (outbound_id && do_track) { + if (outbound_id) { sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,outbound_fail_count=0 where uuid='%s'", outbound_id); fifo_execute_sql(sql, globals.sql_mutex); @@ -2419,39 +2134,14 @@ SWITCH_STANDARD_APP(fifo_function) switch_safe_free(sql); switch_ivr_multi_threaded_bridge(session, other_session, on_dtmf, other_session, session); - - if (outbound_id && do_track) { - sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, outbound_call_total_count=outbound_call_total_count+1 " - "outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", - (long) switch_epoch_time_now(NULL), outbound_id); + + if (outbound_id) { + sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", (long) switch_epoch_time_now(NULL), outbound_id); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); } - - - 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-stop"); - switch_event_fire(&event); - } - 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-stop"); - switch_event_fire(&event); - } - - epoch_end = (long)switch_epoch_time_now(NULL); - - switch_channel_set_variable_printf(channel, "fifo_epoch_stop_bridge", "%ld", epoch_end); - switch_channel_set_variable_printf(channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start); - - switch_channel_set_variable_printf(other_channel, "fifo_epoch_stop_bridge", "%ld", epoch_end); - switch_channel_set_variable_printf(other_channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start); - sql = switch_mprintf("delete from fifo_bridge where consumer_uuid='%q'", switch_core_session_get_uuid(session)); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); @@ -2621,22 +2311,12 @@ struct xml_helper { static int xml_callback(void *pArg, int argc, char **argv, char **columnNames) { struct xml_helper *h = (struct xml_helper *) pArg; - switch_xml_t x_out; + switch_xml_t x_tmp, x_out; int c_off = 0; char exp_buf[128] = ""; switch_time_exp_t tm; switch_time_t etime = 0; - char atime[128] = ""; - char *expires = exp_buf, *tb = atime; - int arg = 0; - - for(arg = 0; arg < argc; arg++) { - if (!argv[arg]) { - argv[arg] = ""; - } - } - - arg = 0; + char *expires = exp_buf; if (argv[7]) { if ((etime = atol(argv[7]))) { @@ -2649,25 +2329,9 @@ static int xml_callback(void *pArg, int argc, char **argv, char **columnNames) } } + x_tmp = switch_xml_add_child_d(h->xml, h->container, h->cc_off++); - if (atoi(argv[13])) { - arg = 17; - } else { - arg = 18; - } - - - if ((etime = atol(argv[arg]))) { - switch_size_t retsize; - - switch_time_exp_lt(&tm, switch_time_from_sec(etime)); - switch_strftime_nocheck(atime, &retsize, sizeof(atime), "%Y-%m-%d %T", &tm); - } else { - switch_set_string(atime, "now"); - } - - - x_out = switch_xml_add_child_d(h->xml, h->tag, c_off++); + x_out = switch_xml_add_child_d(x_tmp, h->tag, c_off++); switch_xml_set_attr_d(x_out, "simo", argv[3]); switch_xml_set_attr_d(x_out, "use_count", argv[4]); switch_xml_set_attr_d(x_out, "timeout", argv[5]); @@ -2676,22 +2340,6 @@ static int xml_callback(void *pArg, int argc, char **argv, char **columnNames) switch_xml_set_attr_d(x_out, "outbound-fail-count", argv[11]); switch_xml_set_attr_d(x_out, "taking-calls", argv[13]); switch_xml_set_attr_d(x_out, "status", argv[14]); - - switch_xml_set_attr_d(x_out, "outbound_call_total_count", argv[15]); - switch_xml_set_attr_d(x_out, "outbound_fail_total_count", argv[16]); - - if (arg == 17) { - switch_xml_set_attr_d(x_out, "logged_on_since", tb); - } else { - switch_xml_set_attr_d(x_out, "logged_off_since", tb); - } - - switch_xml_set_attr_d(x_out, "manual_calls_out_count", argv[19]); - switch_xml_set_attr_d(x_out, "manual_calls_in_count", argv[20]); - switch_xml_set_attr_d(x_out, "manual_calls_out_total_count", argv[21]); - switch_xml_set_attr_d(x_out, "manual_calls_in_total_count", argv[22]); - - switch_xml_set_attr_d(x_out, "next-available", expires); switch_xml_set_txt_d(x_out, argv[2]); @@ -2702,29 +2350,9 @@ static int xml_callback(void *pArg, int argc, char **argv, char **columnNames) static int xml_outbound(switch_xml_t xml, fifo_node_t *node, char *container, char *tag, int cc_off, int verbose) { struct xml_helper h = { 0 }; - char *sql; - - if (!strcmp(node->name, MANUAL_QUEUE_NAME)) { - - sql = switch_mprintf("select uuid, '%s', originate_string, simo_count, use_count, timeout," - "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count," - "hostname, taking_calls, status, outbound_call_total_count, outbound_fail_total_count, active_time, inactive_time," - "manual_calls_out_count, manual_calls_in_count, manual_calls_out_total_count, manual_calls_in_total_count from fifo_outbound " - "group by " - "uuid, originate_string, simo_count, use_count, timeout," - "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count," - "hostname, taking_calls, status, outbound_call_total_count, outbound_fail_total_count, active_time, inactive_time," - "manual_calls_out_count, manual_calls_in_count, manual_calls_out_total_count, manual_calls_in_total_count", - MANUAL_QUEUE_NAME); - - - } else { - sql = switch_mprintf("select uuid, fifo_name, originate_string, simo_count, use_count, timeout, " - "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, " - "hostname, taking_calls, status, outbound_call_total_count, outbound_fail_total_count, active_time, inactive_time, " - "manual_calls_out_count, manual_calls_in_count, manual_calls_out_total_count, manual_calls_in_total_count " - "from fifo_outbound where fifo_name = '%q'", node->name); - } + char *sql = switch_mprintf("select uuid, fifo_name, originate_string, simo_count, use_count, timeout, " + "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, " + "hostname, taking_calls, status from fifo_outbound where fifo_name = '%q'", node->name); h.xml = xml; h.node = node; @@ -2734,8 +2362,6 @@ static int xml_outbound(switch_xml_t xml, fifo_node_t *node, char *container, ch h.row_off = 0; h.verbose = verbose; - h.xml = switch_xml_add_child_d(h.xml, h.container, h.cc_off++); - fifo_execute_sql_callback(globals.sql_mutex, sql, xml_callback, &h); switch_safe_free(sql); @@ -3159,22 +2785,14 @@ const char outbound_sql[] = " use_count integer,\n" " timeout integer,\n" " lag integer,\n" - " next_avail integer not null default 0,\n" - " expires integer not null default 0,\n" - " static integer not null default 0,\n" - " outbound_call_count integer not null default 0,\n" - " outbound_fail_count integer not null default 0,\n" + " next_avail integer,\n" + " expires integer,\n" + " static integer,\n" + " outbound_call_count integer,\n" + " outbound_fail_count integer,\n" " hostname varchar(255),\n" " taking_calls integer not null default 1,\n" - " status varchar(255),\n" - " outbound_call_total_count integer not null default 0,\n" - " outbound_fail_total_count integer not null default 0,\n" - " active_time integer not null default 0,\n" - " inactive_time integer not null default 0,\n" - " manual_calls_out_count integer not null default 0,\n" - " manual_calls_in_count integer not null default 0,\n" - " manual_calls_out_total_count integer not null default 0,\n" - " manual_calls_in_total_count integer not null default 0\n" + " status varchar(255)\n" ");\n"; @@ -3219,7 +2837,6 @@ static switch_status_t load_config(int reload, int del_all) char *sql; switch_bool_t delete_all_outbound_member_on_startup = SWITCH_FALSE; switch_cache_db_handle_t *dbh = NULL; - fifo_node_t *node; gethostname(globals.hostname, sizeof(globals.hostname)); @@ -3269,12 +2886,10 @@ static switch_status_t load_config(int reload, int del_all) goto done; } - switch_cache_db_test_reactive(dbh, "delete from fifo_outbound where static = 1 or taking_calls < 0 or manual_calls_in_total_count < 0", "drop table fifo_outbound", outbound_sql); + switch_cache_db_test_reactive(dbh, "delete from fifo_outbound where static = 1 or taking_calls < 0", "drop table fifo_outbound", outbound_sql); switch_cache_db_test_reactive(dbh, "delete from fifo_bridge", "drop table fifo_bridge", bridge_sql); switch_cache_db_release_db_handle(&dbh); - fifo_execute_sql("update fifo_outbound set use_count=0,outbound_call_count=0,outbound_fail_count=0", globals.sql_mutex); - if (reload) { switch_hash_index_t *hi; fifo_node_t *node; @@ -3298,34 +2913,20 @@ static switch_status_t load_config(int reload, int del_all) fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); - if (!(node = switch_core_hash_find(globals.fifo_hash, MANUAL_QUEUE_NAME))) { - node = create_node(MANUAL_QUEUE_NAME, 0, globals.sql_mutex); - node->is_static = 0; - } if ((fifos = switch_xml_child(cfg, "fifos"))) { for (fifo = switch_xml_child(fifos, "fifo"); fifo; fifo = fifo->next) { const char *name, *outbound_strategy; const char *val; - int imp = 0, outbound_per_cycle = 1; + int imp = 0, outbound_per_cycle = 0; int simo_i = 1; int taking_calls_i = 1; int timeout_i = 60; int lag_i = 10; + fifo_node_t *node; name = switch_xml_attr(fifo, "name"); - - if (!name) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "fifo has no name!\n"); - continue; - } - - if (!strcasecmp(name, MANUAL_QUEUE_NAME)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s is a reserved name, use another name please.\n", MANUAL_QUEUE_NAME); - continue; - } - outbound_strategy = switch_xml_attr(fifo, "outbound_strategy"); @@ -3340,13 +2941,18 @@ static switch_status_t load_config(int reload, int del_all) outbound_per_cycle = 0; } } - + + if (!name) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "fifo has no name!\n"); + continue; + } + switch_mutex_lock(globals.mutex); if (!(node = switch_core_hash_find(globals.fifo_hash, name))) { node = create_node(name, imp, globals.sql_mutex); } - if ((val = switch_xml_attr(fifo, "outbound_name")) && !zstr(val)) { + if ((val = switch_xml_attr(fifo, "outbound_name"))) { node->outbound_name = switch_core_strdup(node->pool, val); } @@ -3408,11 +3014,9 @@ static switch_status_t load_config(int reload, int del_all) sql = switch_mprintf("insert into fifo_outbound " "(uuid, fifo_name, originate_string, simo_count, use_count, timeout, lag, " - "next_avail, expires, static, outbound_call_count, outbound_fail_count, hostname, taking_calls, " - "active_time, inactive_time) " - "values ('%q','%q','%q',%d,%d,%d,%d,0,0,1,0,0,'%q',%d,%ld,0)", - digest, node->name, member->txt, simo_i, 0, timeout_i, lag_i, globals.hostname, taking_calls_i, - (long) switch_epoch_time_now(NULL)); + "next_avail, expires, static, outbound_call_count, outbound_fail_count, hostname, taking_calls) " + "values ('%q','%q','%q',%d,%d,%d,%d,0,0,1,0,0,'%q',%d)", + digest, node->name, member->txt, simo_i, 0, timeout_i, lag_i, globals.hostname, taking_calls_i); switch_assert(sql); fifo_execute_sql(sql, globals.sql_mutex); @@ -3509,10 +3113,9 @@ static void fifo_member_add(char *fifo_name, char *originate_string, int simo_co sql = switch_mprintf("insert into fifo_outbound " "(uuid, fifo_name, originate_string, simo_count, use_count, timeout, " - "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, hostname, taking_calls, active_time, inactive_time) " - "values ('%q','%q','%q',%d,%d,%d,%d,%d,%ld,0,0,0,'%q',%d,%ld,0)", - digest, fifo_name, originate_string, simo_count, 0, timeout, lag, 0, (long) expires, globals.hostname, taking_calls, - (long)switch_epoch_time_now(NULL)); + "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, hostname, taking_calls) " + "values ('%q','%q','%q',%d,%d,%d,%d,%d,%ld,0,0,0,'%q',%d)", + digest, fifo_name, originate_string, simo_count, 0, timeout, lag, 0, (long) expires, globals.hostname, taking_calls); switch_assert(sql); fifo_execute_sql(sql, globals.sql_mutex); free(sql); @@ -3679,8 +3282,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load) /* 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_APP(app_interface, "fifo_track_call", "Count a call as a fifo call in the manual_calls queue", - "", fifo_member_usage_function, "", SAF_SUPPORT_NOMEDIA); + SWITCH_ADD_APP(app_interface, "fifo_member_usage", "increment a member usage until the call ends", + "", fifo_member_usage_function, "", SAF_NONE); SWITCH_ADD_API(commands_api_interface, "fifo", "Return data about a fifo", fifo_api_function, FIFO_API_SYNTAX); SWITCH_ADD_API(commands_api_interface, "fifo_member", "Add members to a fifo", fifo_member_api_function, FIFO_MEMBER_API_SYNTAX); SWITCH_ADD_API(commands_api_interface, "fifo_add_outbound", "Add outbound members to a fifo", fifo_add_outbound_function, " []"); From 2ac5dd548d882508658096ee18189bf8f08cdf8e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 12 Jul 2010 20:58:39 -0500 Subject: [PATCH 37/68] tweak --- src/mod/applications/mod_fifo/mod_fifo.c | 74 ++++++++++++++++-------- 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 2e4df02e91..aa956f48b4 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -679,6 +679,26 @@ struct callback_helper { }; +static switch_status_t hanguphook(switch_core_session_t *session) +{ + switch_channel_t *channel = switch_core_session_get_channel(session); + switch_channel_state_t state = switch_channel_get_state(channel); + const char *uuid = NULL; + char sql[256] = ""; + + if (state == CS_HANGUP || state == CS_ROUTING) { + if ((uuid = switch_channel_get_variable(channel, "fifo_outbound_uuid"))) { + switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, " + "outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", + (long)switch_epoch_time_now(NULL), uuid); + + fifo_execute_sql(sql, globals.sql_mutex); + } + switch_core_event_hook_remove_state_change(session, hanguphook); + } + return SWITCH_STATUS_SUCCESS; +} + static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void *obj) { @@ -824,13 +844,23 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_event_fire(&event); } + for (i = 0; i < cbh->rowcount; i++) { + struct call_helper *h = cbh->rows[i]; + char *sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,outbound_fail_count=0 where uuid='%s'", h->uuid); + + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + + } + status = switch_ivr_originate(NULL, &session, &cause, originate_string, timeout, NULL, NULL, NULL, NULL, ovars, SOF_NONE, NULL); if (status != SWITCH_STATUS_SUCCESS) { for (i = 0; i < cbh->rowcount; i++) { struct call_helper *h = cbh->rows[i]; - char *sql = switch_mprintf("update fifo_outbound set outbound_fail_count=outbound_fail_count+1, next_avail=%ld + lag where uuid='%q'", - (long) switch_epoch_time_now(NULL), h->uuid); + char *sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, " + "outbound_fail_count=outbound_fail_count+1, next_avail=%ld + lag where uuid='%q' and use_count > 0", + (long) switch_epoch_time_now(NULL), h->uuid); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); @@ -865,6 +895,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_channel_set_variable(channel, "fifo_pop_order", NULL); + switch_core_event_hook_add_state_change(session, hanguphook); app_name = "fifo"; arg = switch_core_session_sprintf(session, "%s out nowait", node_name); @@ -910,6 +941,7 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) switch_event_t *ovars = NULL; switch_status_t status = SWITCH_STATUS_FALSE; switch_event_t *event = NULL; + char *sql = NULL; switch_mutex_lock(globals.mutex); node = switch_core_hash_find(globals.fifo_hash, h->node_name); @@ -951,6 +983,11 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) switch_event_fire(&event); } + + sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,outbound_fail_count=0 where uuid='%s'", h->uuid); + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + status = switch_ivr_originate(NULL, &session, &cause, originate_string, h->timeout, NULL, NULL, NULL, NULL, ovars, SOF_NONE, NULL); free(originate_string); @@ -958,6 +995,12 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) if (status != SWITCH_STATUS_SUCCESS) { + sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, " + "outbound_fail_count=outbound_fail_count+1, next_avail=%ld + lag where uuid='%q' and use_count > 0", + (long) switch_epoch_time_now(NULL), h->uuid); + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", node->name); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "post-dial"); @@ -992,6 +1035,7 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) } } + switch_core_event_hook_add_state_change(session, hanguphook); switch_channel_set_variable(channel, "fifo_outbound_uuid", h->uuid); app_name = "fifo"; arg = switch_core_session_sprintf(session, "%s out %s", h->node_name, member_wait ? member_wait : "wait"); @@ -1360,27 +1404,6 @@ SWITCH_STANDARD_API(fifo_add_outbound_function) } -static switch_status_t hanguphook(switch_core_session_t *session) -{ - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_channel_state_t state = switch_channel_get_state(channel); - const char *uuid = NULL; - char sql[256] = ""; - - if (state == CS_HANGUP || state == CS_ROUTING) { - if ((uuid = switch_channel_get_variable(channel, "fifo_outbound_uuid"))) { - switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, " - "outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s'", - (long)switch_epoch_time_now(NULL), uuid); - - fifo_execute_sql(sql, globals.sql_mutex); - } - switch_core_event_hook_remove_state_change(session, hanguphook); - } - return SWITCH_STATUS_SUCCESS; -} - - SWITCH_STANDARD_APP(fifo_member_usage_function) { char *sql; @@ -1762,7 +1785,12 @@ SWITCH_STANDARD_APP(fifo_function) const char *caller_uuid = NULL; switch_event_t *call_event; const char *outbound_id = switch_channel_get_variable(channel, "fifo_outbound_uuid"); + const char *track_use_count = switch_channel_get_variable(channel, "fifo_track_use_count"); + if (!switch_true(track_use_count)) { + outbound_id = NULL; + } + if (!zstr(strat_str)) { if (!strcasecmp(strat_str, "more_ppl")) { From 8f878ecddad16a7f3b3d7471b8da1fad3572c97e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 12 Jul 2010 21:58:24 -0500 Subject: [PATCH 38/68] tweak2 --- src/mod/applications/mod_fifo/mod_fifo.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index aa956f48b4..2527acd6a9 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -2339,7 +2339,7 @@ struct xml_helper { static int xml_callback(void *pArg, int argc, char **argv, char **columnNames) { struct xml_helper *h = (struct xml_helper *) pArg; - switch_xml_t x_tmp, x_out; + switch_xml_t x_out; int c_off = 0; char exp_buf[128] = ""; switch_time_exp_t tm; @@ -2357,9 +2357,9 @@ static int xml_callback(void *pArg, int argc, char **argv, char **columnNames) } } - x_tmp = switch_xml_add_child_d(h->xml, h->container, h->cc_off++); + - x_out = switch_xml_add_child_d(x_tmp, h->tag, c_off++); + x_out = switch_xml_add_child_d(h->xml, h->tag, c_off++); switch_xml_set_attr_d(x_out, "simo", argv[3]); switch_xml_set_attr_d(x_out, "use_count", argv[4]); switch_xml_set_attr_d(x_out, "timeout", argv[5]); @@ -2390,6 +2390,8 @@ static int xml_outbound(switch_xml_t xml, fifo_node_t *node, char *container, ch h.row_off = 0; h.verbose = verbose; + h.xml = switch_xml_add_child_d(h.xml, h.container, h.cc_off++); + fifo_execute_sql_callback(globals.sql_mutex, sql, xml_callback, &h); switch_safe_free(sql); From b32a75c452cca8e4c11cd4d053618fd0a5870f29 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 13 Jul 2010 01:41:27 -0500 Subject: [PATCH 39/68] update --- src/mod/applications/mod_fifo/mod_fifo.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 2527acd6a9..b380cc5531 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -1786,12 +1786,8 @@ SWITCH_STANDARD_APP(fifo_function) switch_event_t *call_event; const char *outbound_id = switch_channel_get_variable(channel, "fifo_outbound_uuid"); const char *track_use_count = switch_channel_get_variable(channel, "fifo_track_use_count"); - - if (!switch_true(track_use_count)) { - outbound_id = NULL; - } + int do_track = switch_true(track_use_count); - if (!zstr(strat_str)) { if (!strcasecmp(strat_str, "more_ppl")) { strat = STRAT_MORE_PPL; @@ -2138,7 +2134,7 @@ SWITCH_STANDARD_APP(fifo_function) switch_event_fire(&event); } - if (outbound_id) { + if (outbound_id && do_track) { sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,outbound_fail_count=0 where uuid='%s'", outbound_id); fifo_execute_sql(sql, globals.sql_mutex); @@ -2163,7 +2159,7 @@ SWITCH_STANDARD_APP(fifo_function) switch_ivr_multi_threaded_bridge(session, other_session, on_dtmf, other_session, session); - if (outbound_id) { + if (outbound_id && do_track) { sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", (long) switch_epoch_time_now(NULL), outbound_id); fifo_execute_sql(sql, globals.sql_mutex); From b9616e13df50e844c10eaccbc0261f031d430aba Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 13 Jul 2010 08:33:59 -0500 Subject: [PATCH 40/68] don't reset outbound_fail_count on pre-call use_count increments --- src/mod/applications/mod_fifo/mod_fifo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index b380cc5531..646d5d0ff1 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -846,7 +846,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void for (i = 0; i < cbh->rowcount; i++) { struct call_helper *h = cbh->rows[i]; - char *sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,outbound_fail_count=0 where uuid='%s'", h->uuid); + char *sql = switch_mprintf("update fifo_outbound set use_count=use_count+1 where uuid='%s'", h->uuid); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); @@ -984,7 +984,7 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) } - sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,outbound_fail_count=0 where uuid='%s'", h->uuid); + sql = switch_mprintf("update fifo_outbound set use_count=use_count+1 where uuid='%s'", h->uuid); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); From 4ddc02a73f9b629da72b657ac0b2fec205120fdf Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 13 Jul 2010 12:42:36 -0500 Subject: [PATCH 41/68] fix ringall issue --- src/mod/applications/mod_fifo/mod_fifo.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 646d5d0ff1..126b36e97e 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -1075,11 +1075,14 @@ static int place_call_ringall_callback(void *pArg, int argc, char **argv, char * cbh->rows[cbh->rowcount++] = h; - cbh->need--; - if (cbh->rowcount == MAX_ROWS) return -1; - - return cbh->need ? 0 : -1; + + if (cbh->need) { + cbh->need--; + return cbh->need ? 0 : -1; + } + + return 0; } @@ -1150,9 +1153,9 @@ static void find_consumers(fifo_node_t *node) switch_core_new_memory_pool(&pool); cbh = switch_core_alloc(pool, sizeof(*cbh)); cbh->pool = pool; - cbh->need = node_consumer_wait_count(node); + cbh->need = 1; - if (node->outbound_per_cycle && node->outbound_per_cycle < cbh->need) { + if (node->outbound_per_cycle != cbh->need) { cbh->need = node->outbound_per_cycle; } @@ -2916,6 +2919,8 @@ static switch_status_t load_config(int reload, int del_all) switch_cache_db_test_reactive(dbh, "delete from fifo_bridge", "drop table fifo_bridge", bridge_sql); switch_cache_db_release_db_handle(&dbh); + fifo_execute_sql("update fifo_outbound set use_count=0,outbound_call_count=0,outbound_fail_count=0", globals.sql_mutex); + if (reload) { switch_hash_index_t *hi; fifo_node_t *node; @@ -2945,7 +2950,7 @@ static switch_status_t load_config(int reload, int del_all) for (fifo = switch_xml_child(fifos, "fifo"); fifo; fifo = fifo->next) { const char *name, *outbound_strategy; const char *val; - int imp = 0, outbound_per_cycle = 0; + int imp = 0, outbound_per_cycle = 1; int simo_i = 1; int taking_calls_i = 1; int timeout_i = 60; From 2d30a8c2867b8f585bc13e1d1c33c5b6d5d365b7 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 13 Jul 2010 15:43:37 -0500 Subject: [PATCH 42/68] add nomedia flag --- src/mod/applications/mod_fifo/mod_fifo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 126b36e97e..c3e9f534a7 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -3314,7 +3314,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load) *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_APP(app_interface, "fifo_member_usage", "increment a member usage until the call ends", - "", fifo_member_usage_function, "", SAF_NONE); + "", fifo_member_usage_function, "", SAF_SUPPORT_NOMEDIA); SWITCH_ADD_API(commands_api_interface, "fifo", "Return data about a fifo", fifo_api_function, FIFO_API_SYNTAX); SWITCH_ADD_API(commands_api_interface, "fifo_member", "Add members to a fifo", fifo_member_api_function, FIFO_MEMBER_API_SYNTAX); SWITCH_ADD_API(commands_api_interface, "fifo_add_outbound", "Add outbound members to a fifo", fifo_add_outbound_function, " []"); From cad1d49d6b9e47009087f7d6e2e73d322b097ccf Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 13 Jul 2010 17:27:37 -0500 Subject: [PATCH 43/68] fix logic bug and memory leak in new code --- src/mod/applications/mod_fifo/mod_fifo.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index c3e9f534a7..fbaf170191 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -782,6 +782,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void q = node->fifo_list[x]; if (fifo_queue_pop_nameval(q, "variable_fifo_vip", "true", &pop_dup, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS && pop_dup) { pop = pop_dup; + break; } } @@ -790,6 +791,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void q = node->fifo_list[x]; if (fifo_queue_pop(node->fifo_list[x], &pop_dup, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS && pop_dup) { pop = pop_dup; + break; } } } From 0df997987e53c6a1b5d87fb0ba2f4b804211cc8c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 12:40:08 -0500 Subject: [PATCH 44/68] fifo up --- src/mod/applications/mod_fifo/mod_fifo.c | 323 ++++++++++++++++++++--- 1 file changed, 291 insertions(+), 32 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index fbaf170191..41b3213588 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -34,6 +34,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fifo_shutdown); SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load); SWITCH_MODULE_DEFINITION(mod_fifo, mod_fifo_load, mod_fifo_shutdown, NULL); +#define MANUAL_QUEUE_NAME "manual_calls" #define FIFO_EVENT "fifo::info" #define FIFO_DELAY_DESTROY 100 static switch_status_t load_config(int reload, int del_all); @@ -679,22 +680,190 @@ struct callback_helper { }; +static switch_status_t messagehook (switch_core_session_t *session, switch_core_session_message_t *msg) +{ + switch_event_t *event; + switch_core_session_t *other_session, *caller_session, *consumer_session; + switch_channel_t *channel, *other_channel, *caller_channel, *consumer_channel; + const char *outbound_id; + char *sql; + + channel = switch_core_session_get_channel(session); + outbound_id = switch_channel_get_variable(channel, "fifo_outbound_uuid"); + + if ((other_session = switch_core_session_force_locate(msg->string_arg))) { + + other_channel = switch_core_session_get_channel(other_session); + + consumer_channel = channel; + caller_channel = other_channel; + + consumer_session = session; + caller_session = other_session; + + } else { + return SWITCH_STATUS_SUCCESS; + } + + + switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_BRIDGE: + { + const char *col1 = NULL, *col2 = NULL; + + if (switch_true(switch_channel_get_variable(channel, "fifo_bridged"))) { + return SWITCH_STATUS_SUCCESS; + } + + switch_process_import(consumer_session, caller_channel, "fifo_caller_consumer_import"); + switch_process_import(caller_session, consumer_channel, "fifo_consumer_caller_import"); + + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + switch_channel_event_set_data(consumer_channel, event); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer"); + switch_event_fire(&event); + } + + 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller"); + switch_event_fire(&event); + } + + sql = switch_mprintf("insert into fifo_bridge " + "(fifo_name,caller_uuid,caller_caller_id_name,caller_caller_id_number,consumer_uuid,consumer_outgoing_uuid,bridge_start) " + "values ('%q','%q','%q','%q','%q','%q',%ld)", + MANUAL_QUEUE_NAME, + switch_core_session_get_uuid(other_session), + switch_str_nil(switch_channel_get_variable(other_channel, "caller_id_name")), + switch_str_nil(switch_channel_get_variable(other_channel, "caller_id_number")), + switch_core_session_get_uuid(session), + switch_str_nil(outbound_id), + (long) switch_epoch_time_now(NULL) + ); + + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + + if (switch_channel_direction(consumer_channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { + col1 = "manual_calls_in_count"; + col2 = "manual_calls_in_total_count"; + } else { + col1 = "manual_calls_out_count"; + col2 = "manual_calls_out_total_count"; + } + + sql = switch_mprintf("update fifo_outbound set %s=%s+1,%s=%s+1 where uuid='%q'", col1, col1, col2, col2, outbound_id); + printf("WTF [%s]\n", sql); + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + + + switch_channel_set_variable(consumer_channel, "fifo_bridged", "true"); + switch_channel_set_variable(consumer_channel, "fifo_manual_bridge", "true"); + + } + break; + case SWITCH_MESSAGE_INDICATE_UNBRIDGE: + { + if (switch_true(switch_channel_get_variable(channel, "fifo_bridged"))) { + char date[80] = ""; + switch_time_exp_t tm; + switch_time_t ts = switch_micro_time_now(); + switch_size_t retsize; + + switch_channel_set_variable(channel, "fifo_bridged", NULL); + + ts = switch_micro_time_now(); + switch_time_exp_lt(&tm, ts); + switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm); + + sql = switch_mprintf("delete from fifo_bridge where consumer_uuid='%q'", switch_core_session_get_uuid(consumer_session)); + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + + switch_channel_set_variable(consumer_channel, "fifo_status", "WAITING"); + switch_channel_set_variable(consumer_channel, "fifo_timestamp", date); + + switch_channel_set_variable(caller_channel, "fifo_status", "DONE"); + switch_channel_set_variable(caller_channel, "fifo_timestamp", date); + + + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + switch_channel_event_set_data(consumer_channel, event); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-stop"); + switch_event_fire(&event); + } + + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + switch_channel_event_set_data(caller_channel, event); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-stop"); + switch_event_fire(&event); + } + + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + switch_channel_event_set_data(consumer_channel, event); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "consumer_stop"); + switch_event_fire(&event); + } + } + + } + break; + default: + break; + } + + if (other_session) { + switch_core_session_rwunlock(other_session); + } + + return SWITCH_STATUS_SUCCESS; +} + static switch_status_t hanguphook(switch_core_session_t *session) { switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_state_t state = switch_channel_get_state(channel); const char *uuid = NULL; - char sql[256] = ""; + char sql[512] = ""; + switch_core_session_message_t msg = { 0 }; if (state == CS_HANGUP || state == CS_ROUTING) { if ((uuid = switch_channel_get_variable(channel, "fifo_outbound_uuid"))) { - switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, " - "outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", - (long)switch_epoch_time_now(NULL), uuid); + if ((switch_true(switch_channel_get_variable(channel, "fifo_manual_bridge")))) { + switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, " + "next_avail=%ld + lag where uuid='%s' and use_count > 0", + (long)switch_epoch_time_now(NULL), uuid); + } else { + + switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, " + "outbound_call_count=outbound_call_count+1, " + "outbound_call_total_count=outbound_call_total_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", + (long)switch_epoch_time_now(NULL), uuid); + } fifo_execute_sql(sql, globals.sql_mutex); } switch_core_event_hook_remove_state_change(session, hanguphook); + switch_core_event_hook_remove_receive_message(session, messagehook); + + if (switch_true(switch_channel_get_variable(channel, "fifo_bridged"))) { + msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE; + msg.from = __FILE__; + msg.string_arg = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE); + + if (msg.string_arg && switch_ivr_uuid_exists(msg.string_arg)) { + messagehook(session, &msg); + } + } + + } return SWITCH_STATUS_SUCCESS; } @@ -1424,7 +1593,7 @@ SWITCH_STANDARD_APP(fifo_member_usage_function) fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); - + switch_core_event_hook_add_receive_message(session, messagehook); switch_core_event_hook_add_state_change(session, hanguphook); } @@ -2163,9 +2332,25 @@ SWITCH_STANDARD_APP(fifo_function) switch_safe_free(sql); switch_ivr_multi_threaded_bridge(session, other_session, on_dtmf, other_session, session); + + + 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-stop"); + switch_event_fire(&event); + } + 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-stop"); + switch_event_fire(&event); + } if (outbound_id && do_track) { - sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", (long) switch_epoch_time_now(NULL), outbound_id); + sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, outbound_call_total_count=outbound_call_total_count+1 " + "outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", + (long) switch_epoch_time_now(NULL), outbound_id); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); @@ -2345,7 +2530,17 @@ static int xml_callback(void *pArg, int argc, char **argv, char **columnNames) char exp_buf[128] = ""; switch_time_exp_t tm; switch_time_t etime = 0; - char *expires = exp_buf; + char atime[128] = ""; + char *expires = exp_buf, *tb = atime; + int arg = 0; + + for(arg = 0; arg < argc; arg++) { + if (!argv[arg]) { + argv[arg] = ""; + } + } + + arg = 0; if (argv[7]) { if ((etime = atol(argv[7]))) { @@ -2358,7 +2553,23 @@ static int xml_callback(void *pArg, int argc, char **argv, char **columnNames) } } - + + if (atoi(argv[13])) { + arg = 17; + } else { + arg = 18; + } + + + if ((etime = atol(argv[arg]))) { + switch_size_t retsize; + + switch_time_exp_lt(&tm, switch_time_from_sec(etime)); + switch_strftime_nocheck(atime, &retsize, sizeof(atime), "%Y-%m-%d %T", &tm); + } else { + switch_set_string(atime, "now"); + } + x_out = switch_xml_add_child_d(h->xml, h->tag, c_off++); switch_xml_set_attr_d(x_out, "simo", argv[3]); @@ -2369,6 +2580,22 @@ static int xml_callback(void *pArg, int argc, char **argv, char **columnNames) switch_xml_set_attr_d(x_out, "outbound-fail-count", argv[11]); switch_xml_set_attr_d(x_out, "taking-calls", argv[13]); switch_xml_set_attr_d(x_out, "status", argv[14]); + + switch_xml_set_attr_d(x_out, "outbound_call_total_count", argv[15]); + switch_xml_set_attr_d(x_out, "outbound_fail_total_count", argv[16]); + + if (arg == 17) { + switch_xml_set_attr_d(x_out, "logged_on_since", tb); + } else { + switch_xml_set_attr_d(x_out, "logged_off_since", tb); + } + + switch_xml_set_attr_d(x_out, "manual_calls_out_count", argv[19]); + switch_xml_set_attr_d(x_out, "manual_calls_in_count", argv[20]); + switch_xml_set_attr_d(x_out, "manual_calls_out_total_count", argv[21]); + switch_xml_set_attr_d(x_out, "manual_calls_in_total_count", argv[22]); + + switch_xml_set_attr_d(x_out, "next-available", expires); switch_xml_set_txt_d(x_out, argv[2]); @@ -2379,9 +2606,20 @@ static int xml_callback(void *pArg, int argc, char **argv, char **columnNames) static int xml_outbound(switch_xml_t xml, fifo_node_t *node, char *container, char *tag, int cc_off, int verbose) { struct xml_helper h = { 0 }; - char *sql = switch_mprintf("select uuid, fifo_name, originate_string, simo_count, use_count, timeout, " - "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, " - "hostname, taking_calls, status from fifo_outbound where fifo_name = '%q'", node->name); + char *sql; + + if (!strcmp(node->name, MANUAL_QUEUE_NAME)) { + sql = strdup("select uuid, fifo_name, originate_string, simo_count, use_count, timeout, " + "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, " + "hostname, taking_calls, status, outbound_call_total_count, outbound_fail_total_count, active_time, inactive_time, " + "manual_calls_out_count, manual_calls_in_count, manual_calls_out_total_count, manual_calls_in_total_count from fifo_outbound"); + } else { + sql = switch_mprintf("select uuid, fifo_name, originate_string, simo_count, use_count, timeout, " + "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, " + "hostname, taking_calls, status, outbound_call_total_count, outbound_fail_total_count, active_time, inactive_time, " + "manual_calls_out_count, manual_calls_in_count, manual_calls_out_total_count, manual_calls_in_total_count " + "from fifo_outbound where fifo_name = '%q'", node->name); + } h.xml = xml; h.node = node; @@ -2816,14 +3054,22 @@ const char outbound_sql[] = " use_count integer,\n" " timeout integer,\n" " lag integer,\n" - " next_avail integer,\n" - " expires integer,\n" - " static integer,\n" - " outbound_call_count integer,\n" - " outbound_fail_count integer,\n" + " next_avail integer not null default 0,\n" + " expires integer not null default 0,\n" + " static integer not null default 0,\n" + " outbound_call_count integer not null default 0,\n" + " outbound_fail_count integer not null default 0,\n" " hostname varchar(255),\n" " taking_calls integer not null default 1,\n" - " status varchar(255)\n" + " status varchar(255),\n" + " outbound_call_total_count integer not null default 0,\n" + " outbound_fail_total_count integer not null default 0,\n" + " active_time integer not null default 0,\n" + " inactive_time integer not null default 0,\n" + " manual_calls_out_count integer not null default 0,\n" + " manual_calls_in_count integer not null default 0,\n" + " manual_calls_out_total_count integer not null default 0,\n" + " manual_calls_in_total_count integer not null default 0\n" ");\n"; @@ -2868,6 +3114,7 @@ static switch_status_t load_config(int reload, int del_all) char *sql; switch_bool_t delete_all_outbound_member_on_startup = SWITCH_FALSE; switch_cache_db_handle_t *dbh = NULL; + fifo_node_t *node; gethostname(globals.hostname, sizeof(globals.hostname)); @@ -2917,7 +3164,7 @@ static switch_status_t load_config(int reload, int del_all) goto done; } - switch_cache_db_test_reactive(dbh, "delete from fifo_outbound where static = 1 or taking_calls < 0", "drop table fifo_outbound", outbound_sql); + switch_cache_db_test_reactive(dbh, "delete from fifo_outbound where static = 1 or taking_calls < 0 or manual_calls_in < 0", "drop table fifo_outbound", outbound_sql); switch_cache_db_test_reactive(dbh, "delete from fifo_bridge", "drop table fifo_bridge", bridge_sql); switch_cache_db_release_db_handle(&dbh); @@ -2946,6 +3193,10 @@ static switch_status_t load_config(int reload, int del_all) fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); + if (!(node = switch_core_hash_find(globals.fifo_hash, MANUAL_QUEUE_NAME))) { + node = create_node(MANUAL_QUEUE_NAME, 0, globals.sql_mutex); + node->is_static = 0; + } if ((fifos = switch_xml_child(cfg, "fifos"))) { @@ -2957,9 +3208,19 @@ static switch_status_t load_config(int reload, int del_all) int taking_calls_i = 1; int timeout_i = 60; int lag_i = 10; - fifo_node_t *node; name = switch_xml_attr(fifo, "name"); + + if (!name) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "fifo has no name!\n"); + continue; + } + + if (!strcasecmp(name, MANUAL_QUEUE_NAME)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s is a reserved name, use another name please.\n", MANUAL_QUEUE_NAME); + continue; + } + outbound_strategy = switch_xml_attr(fifo, "outbound_strategy"); @@ -2974,12 +3235,7 @@ static switch_status_t load_config(int reload, int del_all) outbound_per_cycle = 0; } } - - if (!name) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "fifo has no name!\n"); - continue; - } - + switch_mutex_lock(globals.mutex); if (!(node = switch_core_hash_find(globals.fifo_hash, name))) { node = create_node(name, imp, globals.sql_mutex); @@ -3047,9 +3303,11 @@ static switch_status_t load_config(int reload, int del_all) sql = switch_mprintf("insert into fifo_outbound " "(uuid, fifo_name, originate_string, simo_count, use_count, timeout, lag, " - "next_avail, expires, static, outbound_call_count, outbound_fail_count, hostname, taking_calls) " - "values ('%q','%q','%q',%d,%d,%d,%d,0,0,1,0,0,'%q',%d)", - digest, node->name, member->txt, simo_i, 0, timeout_i, lag_i, globals.hostname, taking_calls_i); + "next_avail, expires, static, outbound_call_count, outbound_fail_count, hostname, taking_calls, " + "active_time, inactive_time) " + "values ('%q','%q','%q',%d,%d,%d,%d,0,0,1,0,0,'%q',%d,%ld,0)", + digest, node->name, member->txt, simo_i, 0, timeout_i, lag_i, globals.hostname, taking_calls_i, + (long) switch_epoch_time_now(NULL)); switch_assert(sql); fifo_execute_sql(sql, globals.sql_mutex); @@ -3146,9 +3404,10 @@ static void fifo_member_add(char *fifo_name, char *originate_string, int simo_co sql = switch_mprintf("insert into fifo_outbound " "(uuid, fifo_name, originate_string, simo_count, use_count, timeout, " - "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, hostname, taking_calls) " - "values ('%q','%q','%q',%d,%d,%d,%d,%d,%ld,0,0,0,'%q',%d)", - digest, fifo_name, originate_string, simo_count, 0, timeout, lag, 0, (long) expires, globals.hostname, taking_calls); + "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, hostname, taking_calls, active_time, inactive_time) " + "values ('%q','%q','%q',%d,%d,%d,%d,%d,%ld,0,0,0,'%q',%d,%ld,0)", + digest, fifo_name, originate_string, simo_count, 0, timeout, lag, 0, (long) expires, globals.hostname, taking_calls, + (long)switch_epoch_time_now(NULL)); switch_assert(sql); fifo_execute_sql(sql, globals.sql_mutex); free(sql); @@ -3315,7 +3574,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load) /* 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_APP(app_interface, "fifo_member_usage", "increment a member usage until the call ends", + SWITCH_ADD_APP(app_interface, "fifo_track_call", "Count a call as a fifo call in the manual_calls queue", "", fifo_member_usage_function, "", SAF_SUPPORT_NOMEDIA); SWITCH_ADD_API(commands_api_interface, "fifo", "Return data about a fifo", fifo_api_function, FIFO_API_SYNTAX); SWITCH_ADD_API(commands_api_interface, "fifo_member", "Add members to a fifo", fifo_member_api_function, FIFO_MEMBER_API_SYNTAX); From 1d712f313a7880d6a2d574a8f96ccc7f95485f56 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 12:40:41 -0500 Subject: [PATCH 45/68] fifo up --- src/mod/applications/mod_fifo/mod_fifo.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 41b3213588..262fa0fbdc 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -756,7 +756,6 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ } sql = switch_mprintf("update fifo_outbound set %s=%s+1,%s=%s+1 where uuid='%q'", col1, col1, col2, col2, outbound_id); - printf("WTF [%s]\n", sql); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); From 6506cccfa5e729ada8e0e70693c1e6cbe6ce97b7 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 15:47:41 -0500 Subject: [PATCH 46/68] add reporting vars --- src/mod/applications/mod_fifo/mod_fifo.c | 63 ++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 262fa0fbdc..81f2b2629f 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -710,6 +710,11 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ case SWITCH_MESSAGE_INDICATE_BRIDGE: { const char *col1 = NULL, *col2 = NULL; + long epoch_start = 0; + char date[80] = ""; + switch_time_t ts; + switch_time_exp_t tm; + switch_size_t retsize; if (switch_true(switch_channel_get_variable(channel, "fifo_bridged"))) { return SWITCH_STATUS_SUCCESS; @@ -760,6 +765,29 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_safe_free(sql); + epoch_start = (long)switch_epoch_time_now(NULL); + + ts = switch_micro_time_now(); + switch_time_exp_lt(&tm, ts); + epoch_start = (long)switch_epoch_time_now(NULL); + switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm); + switch_channel_set_variable(consumer_channel, "fifo_status", "TALKING"); + switch_channel_set_variable(consumer_channel, "fifo_target", switch_core_session_get_uuid(caller_session)); + switch_channel_set_variable(consumer_channel, "fifo_timestamp", date); + switch_channel_set_variable_printf(consumer_channel, "fifo_epoch_start_bridge", "%ld", epoch_start); + switch_channel_set_variable(consumer_channel, "fifo_role", "consumer"); + + switch_channel_set_variable(caller_channel, "fifo_status", "TALKING"); + switch_channel_set_variable(caller_channel, "fifo_timestamp", date); + switch_channel_set_variable_printf(caller_channel, "fifo_epoch_start_bridge", "%ld", epoch_start); + switch_channel_set_variable(caller_channel, "fifo_target", switch_core_session_get_uuid(session)); + switch_channel_set_variable(caller_channel, "fifo_role", "caller"); + + + + switch_channel_set_variable(consumer_channel, "fifo_role", "consumer"); + switch_channel_set_variable(caller_channel, "fifo_role", "caller"); + switch_channel_set_variable(consumer_channel, "fifo_bridged", "true"); switch_channel_set_variable(consumer_channel, "fifo_manual_bridge", "true"); @@ -772,24 +800,37 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_time_exp_t tm; switch_time_t ts = switch_micro_time_now(); switch_size_t retsize; - + long epoch_start = 0, epoch_end = 0; + const char *epoch_start_a = NULL; + switch_channel_set_variable(channel, "fifo_bridged", NULL); ts = switch_micro_time_now(); switch_time_exp_lt(&tm, ts); switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm); - + sql = switch_mprintf("delete from fifo_bridge where consumer_uuid='%q'", switch_core_session_get_uuid(consumer_session)); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); switch_channel_set_variable(consumer_channel, "fifo_status", "WAITING"); switch_channel_set_variable(consumer_channel, "fifo_timestamp", date); - + switch_channel_set_variable(caller_channel, "fifo_status", "DONE"); switch_channel_set_variable(caller_channel, "fifo_timestamp", date); + if ((epoch_start_a = switch_channel_get_variable(consumer_channel, "fifo_epoch_start_bridge"))) { + epoch_start = atol(epoch_start_a); + } + + epoch_end = (long)switch_epoch_time_now(NULL); + switch_channel_set_variable_printf(consumer_channel, "fifo_epoch_stop_bridge", "%ld", epoch_end); + switch_channel_set_variable_printf(consumer_channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start); + + switch_channel_set_variable_printf(caller_channel, "fifo_epoch_stop_bridge", "%ld", epoch_end); + switch_channel_set_variable_printf(caller_channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start); + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { switch_channel_event_set_data(consumer_channel, event); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); @@ -2207,7 +2248,8 @@ SWITCH_STANDARD_APP(fifo_function) const char *record_template = switch_channel_get_variable(channel, "fifo_record_template"); char *expanded = NULL; char *sql = NULL; - + long epoch_start, epoch_end; + 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); @@ -2274,14 +2316,19 @@ SWITCH_STANDARD_APP(fifo_function) ts = switch_micro_time_now(); switch_time_exp_lt(&tm, ts); + epoch_start = (long)switch_epoch_time_now(NULL); switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm); switch_channel_set_variable(channel, "fifo_status", "TALKING"); switch_channel_set_variable(channel, "fifo_target", caller_uuid); switch_channel_set_variable(channel, "fifo_timestamp", date); + switch_channel_set_variable_printf(channel, "fifo_epoch_start_bridge", "%ld", epoch_start); + switch_channel_set_variable(channel, "fifo_role", "consumer"); switch_channel_set_variable(other_channel, "fifo_status", "TALKING"); switch_channel_set_variable(other_channel, "fifo_timestamp", date); + switch_channel_set_variable_printf(other_channel, "fifo_epoch_start_bridge", "%ld", epoch_start); switch_channel_set_variable(other_channel, "fifo_target", switch_core_session_get_uuid(session)); + switch_channel_set_variable(other_channel, "fifo_role", "caller"); send_presence(node); @@ -2355,6 +2402,14 @@ SWITCH_STANDARD_APP(fifo_function) switch_safe_free(sql); } + epoch_end = (long)switch_epoch_time_now(NULL); + + switch_channel_set_variable_printf(channel, "fifo_epoch_stop_bridge", "%ld", epoch_end); + switch_channel_set_variable_printf(channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start); + + switch_channel_set_variable_printf(other_channel, "fifo_epoch_stop_bridge", "%ld", epoch_end); + switch_channel_set_variable_printf(other_channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start); + sql = switch_mprintf("delete from fifo_bridge where consumer_uuid='%q'", switch_core_session_get_uuid(session)); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); From d11ed65838ce18a0b35366fab226bce7a99c0a74 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 16:52:55 -0500 Subject: [PATCH 47/68] update --- src/mod/applications/mod_fifo/mod_fifo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 81f2b2629f..6a4e426d82 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -3218,7 +3218,7 @@ static switch_status_t load_config(int reload, int del_all) goto done; } - switch_cache_db_test_reactive(dbh, "delete from fifo_outbound where static = 1 or taking_calls < 0 or manual_calls_in < 0", "drop table fifo_outbound", outbound_sql); + switch_cache_db_test_reactive(dbh, "delete from fifo_outbound where static = 1 or taking_calls < 0 or manual_calls_in_total_count < 0", "drop table fifo_outbound", outbound_sql); switch_cache_db_test_reactive(dbh, "delete from fifo_bridge", "drop table fifo_bridge", bridge_sql); switch_cache_db_release_db_handle(&dbh); From e3b06f7d0e68ef24549e4ad8d34e0279e4f30d1b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 17:14:39 -0500 Subject: [PATCH 48/68] fix sql stmt --- src/mod/applications/mod_fifo/mod_fifo.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 6a4e426d82..0cfd2064cd 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -2663,10 +2663,19 @@ static int xml_outbound(switch_xml_t xml, fifo_node_t *node, char *container, ch char *sql; if (!strcmp(node->name, MANUAL_QUEUE_NAME)) { - sql = strdup("select uuid, fifo_name, originate_string, simo_count, use_count, timeout, " - "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, " - "hostname, taking_calls, status, outbound_call_total_count, outbound_fail_total_count, active_time, inactive_time, " - "manual_calls_out_count, manual_calls_in_count, manual_calls_out_total_count, manual_calls_in_total_count from fifo_outbound"); + + sql = switch_mprintf("select uuid, '%s', originate_string, simo_count, use_count, timeout," + "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count," + "hostname, taking_calls, status, outbound_call_total_count, outbound_fail_total_count, active_time, inactive_time," + "manual_calls_out_count, manual_calls_in_count, manual_calls_out_total_count, manual_calls_in_total_count from fifo_outbound " + "group by " + "uuid, originate_string, simo_count, use_count, timeout," + "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count," + "hostname, taking_calls, status, outbound_call_total_count, outbound_fail_total_count, active_time, inactive_time," + "manual_calls_out_count, manual_calls_in_count, manual_calls_out_total_count, manual_calls_in_total_count", + MANUAL_QUEUE_NAME); + + } else { sql = switch_mprintf("select uuid, fifo_name, originate_string, simo_count, use_count, timeout, " "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, " From 348237485d4d0f5c5e239324cefce08343b8b223 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 17:49:44 -0500 Subject: [PATCH 49/68] add zstr --- src/mod/applications/mod_fifo/mod_fifo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 0cfd2064cd..00e28ed75f 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -1011,7 +1011,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void if (!switch_event_get_header(ovars, "origination_caller_id_name")) { if ((caller_id_name = switch_event_get_header(pop, "caller-caller-id-name"))) { - if (node->outbound_name) { + if (!zstr(node->outbound_name)) { switch_event_add_header(ovars, SWITCH_STACK_BOTTOM, "origination_caller_id_name", "(%s) %s", node->outbound_name, caller_id_name); } else { switch_event_add_header_string(ovars, SWITCH_STACK_BOTTOM, "origination_caller_id_name", caller_id_name); @@ -1173,7 +1173,7 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) originate_string = switch_mprintf("{execute_on_answer='unset fifo_hangup_check',fifo_hangup_check='%q'}%s", node->name, h->originate_string); } else { - if (node->outbound_name) { + if (!zstr(node->outbound_name)) { originate_string = switch_mprintf("{execute_on_answer='unset fifo_hangup_check',fifo_hangup_check='%q'," "origination_caller_id_name=Queue,origination_caller_id_number='Queue: %q'}%s", node->name, node->outbound_name, h->originate_string); @@ -3304,7 +3304,7 @@ static switch_status_t load_config(int reload, int del_all) node = create_node(name, imp, globals.sql_mutex); } - if ((val = switch_xml_attr(fifo, "outbound_name"))) { + if ((val = switch_xml_attr(fifo, "outbound_name")) && !zstr(val)) { node->outbound_name = switch_core_strdup(node->pool, val); } From 4b57e7c8b74c5c4dbe3176b7ed17b4d40a87034a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 18:11:07 -0500 Subject: [PATCH 50/68] typo --- src/mod/applications/mod_fifo/mod_fifo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 00e28ed75f..6162bb4ad8 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -726,14 +726,14 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { switch_channel_event_set_data(consumer_channel, event); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-start"); switch_event_fire(&event); } 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-start"); switch_event_fire(&event); } @@ -2344,13 +2344,13 @@ SWITCH_STANDARD_APP(fifo_function) 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-start"); switch_event_fire(&event); } 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-start"); switch_event_fire(&event); } From b55ba88380145c135019569b5f1eb2f9a506aa0b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 18:59:42 -0500 Subject: [PATCH 51/68] skip runs when messages are not needed --- src/mod/applications/mod_fifo/mod_fifo.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 6162bb4ad8..6ab262253f 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -688,6 +688,14 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ const char *outbound_id; char *sql; + switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_BRIDGE: + case SWITCH_MESSAGE_INDICATE_UNBRIDGE: + break; + default: + return SWITCH_STATUS_SUCCESS; + } + channel = switch_core_session_get_channel(session); outbound_id = switch_channel_get_variable(channel, "fifo_outbound_uuid"); From cd05bd0e9160b8cc2d433b5b1693fd7a01731461 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 19:38:40 -0500 Subject: [PATCH 52/68] update --- src/mod/applications/mod_fifo/mod_fifo.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 6ab262253f..8fc0d50ec2 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -715,6 +715,10 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_DISPLAY: + sql = switch_mprintf("update fifo_bridge set caller_caller_id_name='%q', caller_caller_id_number='%q' where consumer_uuid='%q'", + switch_core_session_get_uuid(session)); + break; case SWITCH_MESSAGE_INDICATE_BRIDGE: { const char *col1 = NULL, *col2 = NULL; @@ -723,7 +727,8 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_time_t ts; switch_time_exp_t tm; switch_size_t retsize; - + const char *cid_name, *cid_number; + if (switch_true(switch_channel_get_variable(channel, "fifo_bridged"))) { return SWITCH_STATUS_SUCCESS; } @@ -745,13 +750,25 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_event_fire(&event); } + cid_name = switch_channel_get_variable(consumer_channel, "callee_id_name"); + cid_number = switch_channel_get_variable(consumer_channel, "callee_id_number"); + + if (zstr(cid_name)) { + cid_name = cid_number; + } + + if (zstr(cid_number)) { + cid_name = switch_channel_get_variable(consumer_channel, "destination_number"); + cid_number = cid_name; + } + sql = switch_mprintf("insert into fifo_bridge " "(fifo_name,caller_uuid,caller_caller_id_name,caller_caller_id_number,consumer_uuid,consumer_outgoing_uuid,bridge_start) " "values ('%q','%q','%q','%q','%q','%q',%ld)", MANUAL_QUEUE_NAME, switch_core_session_get_uuid(other_session), - switch_str_nil(switch_channel_get_variable(other_channel, "caller_id_name")), - switch_str_nil(switch_channel_get_variable(other_channel, "caller_id_number")), + cid_name, + cid_number, switch_core_session_get_uuid(session), switch_str_nil(outbound_id), (long) switch_epoch_time_now(NULL) From cfc14e5eecc3db3a09f797f2925ec11d98872293 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 19:43:31 -0500 Subject: [PATCH 53/68] update --- src/mod/applications/mod_fifo/mod_fifo.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 8fc0d50ec2..06a576d862 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -691,6 +691,7 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_BRIDGE: case SWITCH_MESSAGE_INDICATE_UNBRIDGE: + case SWITCH_MESSAGE_INDICATE_DISPLAY: break; default: return SWITCH_STATUS_SUCCESS; @@ -718,7 +719,9 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ case SWITCH_MESSAGE_INDICATE_DISPLAY: sql = switch_mprintf("update fifo_bridge set caller_caller_id_name='%q', caller_caller_id_number='%q' where consumer_uuid='%q'", switch_core_session_get_uuid(session)); - break; + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + return SWITCH_STATUS_SUCCESS; case SWITCH_MESSAGE_INDICATE_BRIDGE: { const char *col1 = NULL, *col2 = NULL; From 7ec56500fb920b3d53339e44b6de7b0aa0cdf54d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 14 Jul 2010 19:47:43 -0500 Subject: [PATCH 54/68] update --- src/mod/applications/mod_fifo/mod_fifo.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 06a576d862..455305d965 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -730,7 +730,7 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_time_t ts; switch_time_exp_t tm; switch_size_t retsize; - const char *cid_name, *cid_number; + const char *ced_name, *ced_number, *cid_name, *cid_number; if (switch_true(switch_channel_get_variable(channel, "fifo_bridged"))) { return SWITCH_STATUS_SUCCESS; @@ -753,16 +753,19 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_event_fire(&event); } - cid_name = switch_channel_get_variable(consumer_channel, "callee_id_name"); - cid_number = switch_channel_get_variable(consumer_channel, "callee_id_number"); + ced_name = switch_channel_get_variable(consumer_channel, "callee_id_name"); + ced_number = switch_channel_get_variable(consumer_channel, "callee_id_number"); - if (zstr(cid_name)) { - cid_name = cid_number; + cid_name = switch_channel_get_variable(consumer_channel, "caller_id_name"); + cid_number = switch_channel_get_variable(consumer_channel, "caller_id_number"); + + if (zstr(ced_name) || !strcmp(ced_name, cid_name)) { + ced_name = ced_number; } - if (zstr(cid_number)) { - cid_name = switch_channel_get_variable(consumer_channel, "destination_number"); - cid_number = cid_name; + if (zstr(ced_number) || !strcmp(ced_number, cid_number)) { + ced_name = switch_channel_get_variable(consumer_channel, "destination_number"); + ced_number = ced_name; } sql = switch_mprintf("insert into fifo_bridge " @@ -770,8 +773,8 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ "values ('%q','%q','%q','%q','%q','%q',%ld)", MANUAL_QUEUE_NAME, switch_core_session_get_uuid(other_session), - cid_name, - cid_number, + ced_name, + ced_number, switch_core_session_get_uuid(session), switch_str_nil(outbound_id), (long) switch_epoch_time_now(NULL) From 2a7eca492e58e1ad2707998915e8caeb457d2bf7 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 15 Jul 2010 01:00:08 -0500 Subject: [PATCH 55/68] fifo update --- src/mod/applications/mod_fifo/mod_fifo.c | 217 ++++++++++++----------- 1 file changed, 114 insertions(+), 103 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 455305d965..079dacc7fc 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -683,45 +683,41 @@ struct callback_helper { static switch_status_t messagehook (switch_core_session_t *session, switch_core_session_message_t *msg) { switch_event_t *event; - switch_core_session_t *other_session, *caller_session, *consumer_session; - switch_channel_t *channel, *other_channel, *caller_channel, *consumer_channel; + switch_core_session_t *caller_session = NULL, *consumer_session = NULL; + switch_channel_t *caller_channel = NULL, *consumer_channel = NULL; const char *outbound_id; char *sql; + consumer_session = session; + consumer_channel = switch_core_session_get_channel(consumer_session); + switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_BRIDGE: case SWITCH_MESSAGE_INDICATE_UNBRIDGE: - case SWITCH_MESSAGE_INDICATE_DISPLAY: - break; - default: - return SWITCH_STATUS_SUCCESS; - } - - channel = switch_core_session_get_channel(session); - outbound_id = switch_channel_get_variable(channel, "fifo_outbound_uuid"); - - if ((other_session = switch_core_session_force_locate(msg->string_arg))) { - - other_channel = switch_core_session_get_channel(other_session); - - consumer_channel = channel; - caller_channel = other_channel; - - consumer_session = session; - caller_session = other_session; - - } else { - return SWITCH_STATUS_SUCCESS; - } - - - switch (msg->message_id) { + if ((caller_session = switch_core_session_force_locate(msg->string_arg))) { + caller_channel = switch_core_session_get_channel(caller_session); + if (msg->message_id == SWITCH_MESSAGE_INDICATE_BRIDGE) { + switch_core_session_soft_lock(caller_session, 3); + } else { + switch_core_session_soft_unlock(caller_session); + } + } + break; case SWITCH_MESSAGE_INDICATE_DISPLAY: sql = switch_mprintf("update fifo_bridge set caller_caller_id_name='%q', caller_caller_id_number='%q' where consumer_uuid='%q'", + switch_str_nil(msg->string_array_arg[0]), + switch_str_nil(msg->string_array_arg[1]), switch_core_session_get_uuid(session)); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); - return SWITCH_STATUS_SUCCESS; + goto end; + default: + goto end; + } + + outbound_id = switch_channel_get_variable(consumer_channel, "fifo_outbound_uuid"); + + switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_BRIDGE: { const char *col1 = NULL, *col2 = NULL; @@ -731,48 +727,62 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_time_exp_t tm; switch_size_t retsize; const char *ced_name, *ced_number, *cid_name, *cid_number; - - if (switch_true(switch_channel_get_variable(channel, "fifo_bridged"))) { - return SWITCH_STATUS_SUCCESS; + + if (switch_channel_test_app_flag(consumer_channel, CF_APP_TAGGED)) { + goto end; } + switch_channel_set_app_flag(consumer_channel, CF_APP_TAGGED); + + switch_channel_set_variable(consumer_channel, "fifo_bridged", "true"); + switch_channel_set_variable(consumer_channel, "fifo_manual_bridge", "true"); + switch_channel_set_variable(consumer_channel, "fifo_role", "consumer"); + switch_channel_set_variable(caller_channel, "fifo_role", "caller"); + switch_process_import(consumer_session, caller_channel, "fifo_caller_consumer_import"); switch_process_import(caller_session, consumer_channel, "fifo_consumer_caller_import"); - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(consumer_channel, event); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-start"); - switch_event_fire(&event); - } - - 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-start"); - switch_event_fire(&event); - } - ced_name = switch_channel_get_variable(consumer_channel, "callee_id_name"); ced_number = switch_channel_get_variable(consumer_channel, "callee_id_number"); cid_name = switch_channel_get_variable(consumer_channel, "caller_id_name"); cid_number = switch_channel_get_variable(consumer_channel, "caller_id_number"); - - if (zstr(ced_name) || !strcmp(ced_name, cid_name)) { - ced_name = ced_number; - } - if (zstr(ced_number) || !strcmp(ced_number, cid_number)) { - ced_name = switch_channel_get_variable(consumer_channel, "destination_number"); - ced_number = ced_name; + if (switch_channel_direction(consumer_channel) == SWITCH_CALL_DIRECTION_INBOUND) { + if (zstr(ced_name) || !strcmp(ced_name, cid_name)) { + ced_name = ced_number; + } + + if (zstr(ced_number) || !strcmp(ced_number, cid_number)) { + ced_name = switch_channel_get_variable(consumer_channel, "destination_number"); + ced_number = ced_name; + } + } else { + ced_name = cid_name; + ced_number = cid_number; + } + + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + switch_channel_event_set_data(consumer_channel, event); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-start"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Caller-CID-Name", ced_name); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Caller-CID-Number", ced_number); + switch_event_fire(&event); + } + + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + switch_channel_event_set_data(caller_channel, event); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-start"); + switch_event_fire(&event); } sql = switch_mprintf("insert into fifo_bridge " "(fifo_name,caller_uuid,caller_caller_id_name,caller_caller_id_number,consumer_uuid,consumer_outgoing_uuid,bridge_start) " "values ('%q','%q','%q','%q','%q','%q',%ld)", MANUAL_QUEUE_NAME, - switch_core_session_get_uuid(other_session), + switch_core_session_get_uuid(caller_session), ced_name, ced_number, switch_core_session_get_uuid(session), @@ -813,20 +823,11 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_channel_set_variable_printf(caller_channel, "fifo_epoch_start_bridge", "%ld", epoch_start); switch_channel_set_variable(caller_channel, "fifo_target", switch_core_session_get_uuid(session)); switch_channel_set_variable(caller_channel, "fifo_role", "caller"); - - - - switch_channel_set_variable(consumer_channel, "fifo_role", "consumer"); - switch_channel_set_variable(caller_channel, "fifo_role", "caller"); - - switch_channel_set_variable(consumer_channel, "fifo_bridged", "true"); - switch_channel_set_variable(consumer_channel, "fifo_manual_bridge", "true"); - } break; case SWITCH_MESSAGE_INDICATE_UNBRIDGE: { - if (switch_true(switch_channel_get_variable(channel, "fifo_bridged"))) { + if (switch_channel_test_app_flag(consumer_channel, CF_APP_TAGGED)) { char date[80] = ""; switch_time_exp_t tm; switch_time_t ts = switch_micro_time_now(); @@ -834,7 +835,8 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ long epoch_start = 0, epoch_end = 0; const char *epoch_start_a = NULL; - switch_channel_set_variable(channel, "fifo_bridged", NULL); + switch_channel_clear_app_flag(consumer_channel, CF_APP_TAGGED); + switch_channel_set_variable(consumer_channel, "fifo_bridged", NULL); ts = switch_micro_time_now(); switch_time_exp_lt(&tm, ts); @@ -847,8 +849,10 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_channel_set_variable(consumer_channel, "fifo_status", "WAITING"); switch_channel_set_variable(consumer_channel, "fifo_timestamp", date); - switch_channel_set_variable(caller_channel, "fifo_status", "DONE"); - switch_channel_set_variable(caller_channel, "fifo_timestamp", date); + if (caller_channel) { + switch_channel_set_variable(caller_channel, "fifo_status", "DONE"); + switch_channel_set_variable(caller_channel, "fifo_timestamp", date); + } if ((epoch_start_a = switch_channel_get_variable(consumer_channel, "fifo_epoch_start_bridge"))) { epoch_start = atol(epoch_start_a); @@ -859,9 +863,11 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_channel_set_variable_printf(consumer_channel, "fifo_epoch_stop_bridge", "%ld", epoch_end); switch_channel_set_variable_printf(consumer_channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start); - switch_channel_set_variable_printf(caller_channel, "fifo_epoch_stop_bridge", "%ld", epoch_end); - switch_channel_set_variable_printf(caller_channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start); - + if (caller_channel) { + switch_channel_set_variable_printf(caller_channel, "fifo_epoch_stop_bridge", "%ld", epoch_end); + switch_channel_set_variable_printf(caller_channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start); + } + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { switch_channel_event_set_data(consumer_channel, event); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); @@ -869,11 +875,13 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_event_fire(&event); } - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(caller_channel, event); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-stop"); - switch_event_fire(&event); + if (caller_channel) { + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + switch_channel_event_set_data(caller_channel, event); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-stop"); + switch_event_fire(&event); + } } if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { @@ -890,23 +898,26 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ break; } - if (other_session) { - switch_core_session_rwunlock(other_session); + end: + + if (caller_session) { + switch_core_session_rwunlock(caller_session); } return SWITCH_STATUS_SUCCESS; } + static switch_status_t hanguphook(switch_core_session_t *session) { switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_state_t state = switch_channel_get_state(channel); const char *uuid = NULL; char sql[512] = ""; - switch_core_session_message_t msg = { 0 }; if (state == CS_HANGUP || state == CS_ROUTING) { if ((uuid = switch_channel_get_variable(channel, "fifo_outbound_uuid"))) { + if ((switch_true(switch_channel_get_variable(channel, "fifo_manual_bridge")))) { switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, " "next_avail=%ld + lag where uuid='%s' and use_count > 0", @@ -920,25 +931,23 @@ static switch_status_t hanguphook(switch_core_session_t *session) } fifo_execute_sql(sql, globals.sql_mutex); - } - switch_core_event_hook_remove_state_change(session, hanguphook); - switch_core_event_hook_remove_receive_message(session, messagehook); - - if (switch_true(switch_channel_get_variable(channel, "fifo_bridged"))) { - msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE; - msg.from = __FILE__; - msg.string_arg = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE); - - if (msg.string_arg && switch_ivr_uuid_exists(msg.string_arg)) { - messagehook(session, &msg); - } } - - } return SWITCH_STATUS_SUCCESS; } +static switch_status_t r_hanguphook(switch_core_session_t *session) +{ + + switch_channel_t *channel = switch_core_session_get_channel(session); + switch_channel_state_t state = switch_channel_get_state(channel); + + if (state == CS_HANGUP || state == CS_ROUTING) { + hanguphook(session); + switch_core_event_hook_remove_state_change(session, r_hanguphook); + } + return SWITCH_STATUS_SUCCESS; +} static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void *obj) { @@ -1062,6 +1071,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_event_add_header_string(ovars, SWITCH_STACK_BOTTOM, "fifo_originate_uuid", uuid_str); + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { switch_core_session_t *session; if (id && (session = switch_core_session_locate(id))) { @@ -1137,7 +1147,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_channel_set_variable(channel, "fifo_pop_order", NULL); - switch_core_event_hook_add_state_change(session, hanguphook); + switch_core_event_hook_add_state_change(session, r_hanguphook); app_name = "fifo"; arg = switch_core_session_sprintf(session, "%s out nowait", node_name); @@ -1277,7 +1287,7 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) } } - switch_core_event_hook_add_state_change(session, hanguphook); + switch_core_event_hook_add_state_change(session, r_hanguphook); switch_channel_set_variable(channel, "fifo_outbound_uuid", h->uuid); app_name = "fifo"; arg = switch_core_session_sprintf(session, "%s out %s", h->node_name, member_wait ? member_wait : "wait"); @@ -1661,9 +1671,9 @@ SWITCH_STANDARD_APP(fifo_member_usage_function) switch_channel_set_variable(channel, "fifo_outbound_uuid", data); sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,outbound_fail_count=0 where uuid='%s'", data); - fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); + switch_core_event_hook_add_receive_message(session, messagehook); switch_core_event_hook_add_state_change(session, hanguphook); @@ -2410,6 +2420,16 @@ SWITCH_STANDARD_APP(fifo_function) switch_ivr_multi_threaded_bridge(session, other_session, on_dtmf, other_session, session); + if (outbound_id && do_track) { + sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, outbound_call_total_count=outbound_call_total_count+1 " + "outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", + (long) switch_epoch_time_now(NULL), outbound_id); + + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + } + + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { switch_channel_event_set_data(channel, event); @@ -2423,15 +2443,6 @@ SWITCH_STANDARD_APP(fifo_function) switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-stop"); switch_event_fire(&event); } - - if (outbound_id && do_track) { - sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, outbound_call_total_count=outbound_call_total_count+1 " - "outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", - (long) switch_epoch_time_now(NULL), outbound_id); - - fifo_execute_sql(sql, globals.sql_mutex); - switch_safe_free(sql); - } epoch_end = (long)switch_epoch_time_now(NULL); From 30d2e7fda2f76c5ec1b89df2df6fc0051f2801e9 Mon Sep 17 00:00:00 2001 From: Jeff Lenk Date: Thu, 15 Jul 2010 08:50:45 -0500 Subject: [PATCH 56/68] FSCORE-626 Add alternate timing method support for Windows XP and 2003 - must be conditionally compiled(default is original timing) --- src/include/switch_core.h | 1 + .../applications/mod_commands/mod_commands.c | 12 ++--- src/switch_time.c | 51 +++++++++++++++++-- 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 3cd9d46d7f..650ffc15fb 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -1979,6 +1979,7 @@ SWITCH_DECLARE(void) switch_core_memory_reclaim_events(void); SWITCH_DECLARE(void) switch_core_memory_reclaim_logger(void); SWITCH_DECLARE(void) switch_core_memory_reclaim_all(void); SWITCH_DECLARE(void) switch_core_setrlimits(void); +SWITCH_DECLARE(switch_time_t) switch_time_ref(void); SWITCH_DECLARE(void) switch_time_sync(void); /*! \brief Get the current epoch time diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 800923fcc5..c7d3df2843 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -235,9 +235,9 @@ SWITCH_STANDARD_API(time_test_function) } for (x = 1; x <= max; x++) { - then = switch_time_now(); + then = switch_time_ref(); switch_yield(mss); - now = switch_time_now(); + now = switch_time_ref(); diff = (int) (now - then); stream->write_function(stream, "test %d sleep %ld %d\n", x, mss, diff); total += diff; @@ -299,17 +299,17 @@ SWITCH_STANDARD_API(timer_test_function) goto end; } - start = switch_time_now(); + start = switch_time_ref(); for (x = 1; x <= max; x++) { - then = switch_time_now(); + then = switch_time_ref(); switch_core_timer_next(&timer); - now = switch_time_now(); + now = switch_time_ref(); diff = (int) (now - then); //stream->write_function(stream, "test %d sleep %ld %d\n", x, mss, diff); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Timer Test: %d sleep %d %d\n", x, mss, diff); total += diff; } - end = switch_time_now(); + end = switch_time_ref(); switch_yield(250000); diff --git a/src/switch_time.c b/src/switch_time.c index 2d74e60594..5e93d59261 100644 --- a/src/switch_time.c +++ b/src/switch_time.c @@ -48,7 +48,10 @@ #define MAX_ELEMENTS 3600 #define IDLE_SPEED 100 -#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) +/* For now enable WIN32_MONOTONIC on Windows 2003 Server and Windows XP systems for improved timer support */ +/* GetSystemTimeAsFileTime does not update on timeBeginPeriod on these OS */ +/* we leave the normal timer support as the default for now */ +#if (defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)) || defined(WIN32_MONOTONIC) static int MONO = 1; #else static int MONO = 0; @@ -67,6 +70,12 @@ static int COND = 1; static int MATRIX = 1; +#ifdef WIN32 +static switch_time_t win32_tick_time_since_start = -1; +static DWORD win32_last_get_time_tick = 0; +CRITICAL_SECTION timer_section; +#endif + #define ONEMS #ifdef ONEMS static int STEP_MS = 1; @@ -174,9 +183,9 @@ static switch_interval_time_t average_time(switch_interval_time_t t, int reps) switch_time_t start, stop, sum = 0; for (x = 0; x < reps; x++) { - start = switch_time_now(); + start = switch_time_ref(); do_sleep(t); - stop = switch_time_now(); + stop = switch_time_ref(); sum += (stop - start); } @@ -335,22 +344,49 @@ static switch_time_t time_now(int64_t offset) { switch_time_t now; -#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) +#if (defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)) || defined(WIN32_MONOTONIC) if (MONO) { +#ifndef WIN32 struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); now = ts.tv_sec * APR_USEC_PER_SEC + (ts.tv_nsec / 1000) + offset; +#else + DWORD tick_now; + DWORD tick_diff; + + tick_now = timeGetTime(); + if (win32_tick_time_since_start != -1) { + EnterCriticalSection(&timer_section); + /* just add diff (to make it work more than 50 days). */ + tick_diff = tick_now - win32_last_get_time_tick; + win32_tick_time_since_start += tick_diff; + + win32_last_get_time_tick = tick_now; + now = (win32_tick_time_since_start * 1000) + offset; + LeaveCriticalSection(&timer_section); + } else { + /* If someone is calling us before timer is initialized, + * return the current tick + offset + */ + now = (tick_now * 1000) + offset; + } +#endif } else { #endif now = switch_time_now(); -#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) +#if (defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)) || defined(WIN32_MONOTONIC) } #endif return now; } +SWITCH_DECLARE(switch_time_t) switch_time_ref(void) +{ + return time_now(0); +} + SWITCH_DECLARE(void) switch_time_sync(void) { runtime.reference = switch_time_now(); @@ -999,6 +1035,9 @@ SWITCH_MODULE_LOAD_FUNCTION(softtimer_load) #if defined(WIN32) timeBeginPeriod(1); + InitializeCriticalSection(&timer_section); + win32_last_get_time_tick = timeGetTime(); + win32_tick_time_since_start = win32_last_get_time_tick; #endif memset(&globals, 0, sizeof(globals)); @@ -1054,6 +1093,8 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(softtimer_shutdown) } #if defined(WIN32) timeEndPeriod(1); + win32_tick_time_since_start = -1; /* we are not initialized anymore */ + DeleteCriticalSection(&timer_section); #endif if (TIMEZONES_LIST.hash) { From e44b3da65eeaa6210d44b8e388f11b3fed2d8737 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Thu, 15 Jul 2010 10:43:59 -0400 Subject: [PATCH 57/68] limit: fix leak and tweak switch_channel_log -> switch_channel_session_log() --- src/switch_limit.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/switch_limit.c b/src/switch_limit.c index a27a822156..810d83b105 100755 --- a/src/switch_limit.c +++ b/src/switch_limit.c @@ -81,19 +81,18 @@ static switch_status_t limit_state_handler(switch_core_session_t *session) switch_channel_state_t state = switch_channel_get_state(channel); const char *vval = switch_channel_get_variable(channel, LIMIT_IGNORE_TRANSFER_VARIABLE); const char *backendlist = switch_channel_get_variable(channel, LIMIT_BACKEND_VARIABLE); - int argc = 0; - char *argv[6] = { 0 }; - char *mydata = NULL; if (zstr(backendlist)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unset limit backendlist!\n"); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Unset limit backendlist!\n"); return SWITCH_STATUS_SUCCESS; } - mydata = strdup(backendlist); - if (state >= CS_HANGUP || (state == CS_ROUTING && !switch_true(vval))) { + int argc = 0; + char *argv[6] = { 0 }; + char *mydata = strdup(backendlist); int x; + argc = switch_separate_string(mydata, ',', argv, (sizeof(argv) / sizeof(argv[0]))); for (x = 0; x < argc; x++) { switch_limit_release(argv[x], session, NULL, NULL); @@ -101,7 +100,10 @@ static switch_status_t limit_state_handler(switch_core_session_t *session) switch_core_event_hook_remove_state_change(session, limit_state_handler); /* Remove limit_realm variable so we register another hook if limit is called again */ switch_channel_set_variable(channel, "limit_realm", NULL); + + free(mydata); } + return SWITCH_STATUS_SUCCESS; } @@ -117,7 +119,7 @@ SWITCH_DECLARE(switch_status_t) switch_limit_incr(const char *backend, switch_co /* locate impl, call appropriate func */ if (!(limit = get_backend(backend))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Limit subsystem %s not found!\n", backend); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Limit subsystem %s not found!\n", backend); switch_goto_status(SWITCH_STATUS_GENERR, end); } @@ -149,7 +151,7 @@ SWITCH_DECLARE(switch_status_t) switch_limit_release(const char *backend, switch /* locate impl, call appropriate func */ if (!(limit = get_backend(backend))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Limit subsystem %s not found!\n", backend); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Limit subsystem %s not found!\n", backend); switch_goto_status(SWITCH_STATUS_GENERR, end); } From ade0dcd7cbe681625f1a2c960a2d773c3dc26353 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Thu, 15 Jul 2010 11:21:36 -0400 Subject: [PATCH 58/68] declinato mortuus obfirmo! --- src/switch_channel.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/switch_channel.c b/src/switch_channel.c index edf162c0fd..22f66bad25 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1230,7 +1230,9 @@ SWITCH_DECLARE(void) switch_channel_set_flag_value(switch_channel_t *channel, sw switch_mutex_lock(channel->flag_mutex); if (flag == CF_LEG_HOLDING && !channel->flags[flag] && channel->flags[CF_ANSWERED]) { + switch_mutex_unlock(channel->flag_mutex); switch_channel_set_callstate(channel, CCS_HELD); + switch_mutex_lock(channel->flag_mutex); } channel->flags[flag] = value; switch_mutex_unlock(channel->flag_mutex); From 1381d02a589048dae4629b846ede78d7b032aa9a Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 15 Jul 2010 20:36:54 -0500 Subject: [PATCH 59/68] fifo tweaks --- src/mod/applications/mod_fifo/mod_fifo.c | 192 ++++++++++++----------- src/switch_channel.c | 11 +- 2 files changed, 108 insertions(+), 95 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 079dacc7fc..75fb72677e 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -495,6 +495,8 @@ static switch_status_t consumer_read_frame_callback(switch_core_session_t *sessi } static struct { + switch_hash_t *orig_hash; + switch_mutex_t *orig_mutex; switch_hash_t *fifo_hash; switch_mutex_t *mutex; switch_mutex_t *sql_mutex; @@ -697,10 +699,12 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ if ((caller_session = switch_core_session_force_locate(msg->string_arg))) { caller_channel = switch_core_session_get_channel(caller_session); if (msg->message_id == SWITCH_MESSAGE_INDICATE_BRIDGE) { - switch_core_session_soft_lock(caller_session, 3); + switch_core_session_soft_lock(caller_session, 5); } else { switch_core_session_soft_unlock(caller_session); } + } else if (msg->message_id == SWITCH_MESSAGE_INDICATE_BRIDGE) { + goto end; } break; case SWITCH_MESSAGE_INDICATE_DISPLAY: @@ -728,7 +732,7 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_size_t retsize; const char *ced_name, *ced_number, *cid_name, *cid_number; - if (switch_channel_test_app_flag(consumer_channel, CF_APP_TAGGED)) { + if (!caller_channel || switch_channel_test_app_flag(consumer_channel, CF_APP_TAGGED)) { goto end; } @@ -777,6 +781,18 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-start"); switch_event_fire(&event); } + + if (switch_channel_direction(consumer_channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { + col1 = "manual_calls_in_count"; + col2 = "manual_calls_in_total_count"; + } else { + col1 = "manual_calls_out_count"; + col2 = "manual_calls_out_total_count"; + } + + sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,%s=%s+1,%s=%s+1 where uuid='%q'", col1, col1, col2, col2, outbound_id); + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); sql = switch_mprintf("insert into fifo_bridge " "(fifo_name,caller_uuid,caller_caller_id_name,caller_caller_id_number,consumer_uuid,consumer_outgoing_uuid,bridge_start) " @@ -793,19 +809,7 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); - if (switch_channel_direction(consumer_channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { - col1 = "manual_calls_in_count"; - col2 = "manual_calls_in_total_count"; - } else { - col1 = "manual_calls_out_count"; - col2 = "manual_calls_out_total_count"; - } - - sql = switch_mprintf("update fifo_outbound set %s=%s+1,%s=%s+1 where uuid='%q'", col1, col1, col2, col2, outbound_id); - fifo_execute_sql(sql, globals.sql_mutex); - switch_safe_free(sql); - epoch_start = (long)switch_epoch_time_now(NULL); ts = switch_micro_time_now(); @@ -845,6 +849,11 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ sql = switch_mprintf("delete from fifo_bridge where consumer_uuid='%q'", switch_core_session_get_uuid(consumer_session)); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); + + sql = switch_mprintf("update fifo_outbound set use_count=use_count-1 where use_count > 0 and uuid='%q'", outbound_id); + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + switch_channel_set_variable(consumer_channel, "fifo_status", "WAITING"); switch_channel_set_variable(consumer_channel, "fifo_timestamp", date); @@ -908,45 +917,29 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ } -static switch_status_t hanguphook(switch_core_session_t *session) +static void add_outbound_call(const char *key, switch_call_cause_t *cancel_cause) { - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_channel_state_t state = switch_channel_get_state(channel); - const char *uuid = NULL; - char sql[512] = ""; - - if (state == CS_HANGUP || state == CS_ROUTING) { - if ((uuid = switch_channel_get_variable(channel, "fifo_outbound_uuid"))) { - - if ((switch_true(switch_channel_get_variable(channel, "fifo_manual_bridge")))) { - switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, " - "next_avail=%ld + lag where uuid='%s' and use_count > 0", - (long)switch_epoch_time_now(NULL), uuid); - } else { - - switch_snprintf(sql, sizeof(sql), "update fifo_outbound set use_count=use_count-1, " - "outbound_call_count=outbound_call_count+1, " - "outbound_call_total_count=outbound_call_total_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", - (long)switch_epoch_time_now(NULL), uuid); - } - - fifo_execute_sql(sql, globals.sql_mutex); - } - } - return SWITCH_STATUS_SUCCESS; + switch_mutex_lock(globals.orig_mutex); + switch_core_hash_insert(globals.orig_hash, key, cancel_cause); + switch_mutex_unlock(globals.orig_mutex); } -static switch_status_t r_hanguphook(switch_core_session_t *session) +static void del_outbound_call(const char *key) { + switch_mutex_lock(globals.orig_mutex); + switch_core_hash_delete(globals.orig_hash, key); + switch_mutex_unlock(globals.orig_mutex); +} - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_channel_state_t state = switch_channel_get_state(channel); +static void cancel_outbound_call(const char *key, switch_call_cause_t cause) +{ + switch_call_cause_t *cancel_cause = NULL; - if (state == CS_HANGUP || state == CS_ROUTING) { - hanguphook(session); - switch_core_event_hook_remove_state_change(session, r_hanguphook); + switch_mutex_lock(globals.orig_mutex); + if ((cancel_cause = (switch_call_cause_t *) switch_core_hash_find(globals.orig_hash, key))) { + *cancel_cause = cause; } - return SWITCH_STATUS_SUCCESS; + switch_mutex_unlock(globals.orig_mutex); } static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void *obj) @@ -956,6 +949,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void int i = 0; int timeout = 0; switch_stream_handle_t stream = { 0 }; + switch_stream_handle_t stream2 = { 0 }; fifo_node_t *node = NULL; char *originate_string = NULL; switch_event_t *ovars = NULL; @@ -972,6 +966,8 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_event_t *event; switch_uuid_t uuid; char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1]; + switch_call_cause_t cancel_cause = 0; + char *uuid_list = NULL; switch_uuid_get(&uuid); switch_uuid_format(uuid_str, &uuid); @@ -996,6 +992,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void } SWITCH_STANDARD_STREAM(stream); + SWITCH_STANDARD_STREAM(stream2); switch_event_create(&ovars, SWITCH_EVENT_REQUEST_PARAMS); switch_assert(ovars); @@ -1012,17 +1009,23 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void if (timeout < h->timeout) timeout = h->timeout; stream.write_function(&stream, "[leg_timeout=%d,fifo_outbound_uuid=%s]%s,", h->timeout, h->uuid, parsed ? parsed : h->originate_string); + stream2.write_function(&stream2, "%s,", h->uuid); switch_safe_free(parsed); } - originate_string = (char *) stream.data; if (originate_string) { end_of(originate_string) = '\0'; } + uuid_list = (char *) stream2.data; + + if (uuid_list) { + end_of(uuid_list) = '\0'; + } + if (!timeout) timeout = 60; pop = pop_dup = NULL; @@ -1058,7 +1061,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void } } } - + if (!switch_event_get_header(ovars, "origination_caller_id_number")) { if ((cid_num = switch_event_get_header(pop, "caller-caller-id-number"))) { switch_event_add_header_string(ovars, SWITCH_STACK_BOTTOM, "origination_caller_id_number", cid_num); @@ -1081,37 +1084,37 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_channel_event_set_data(channel, event); switch_core_session_rwunlock(session); } - + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", node->name); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "pre-dial"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "outbound-strategy", "ringall"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "caller-uuid", id); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "originate_string", originate_string); - - for (i = 0; i < cbh->rowcount; i++) { - struct call_helper *h = cbh->rows[i]; - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Outbound-UUID", h->uuid); - } + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Outbound-UUID-List", uuid_list); switch_event_fire(&event); } for (i = 0; i < cbh->rowcount; i++) { struct call_helper *h = cbh->rows[i]; - char *sql = switch_mprintf("update fifo_outbound set use_count=use_count+1 where uuid='%s'", h->uuid); - + char *sql = switch_mprintf("update fifo_outbound set ring_count=ring_count+1 where uuid='%s'", h->uuid); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); } - status = switch_ivr_originate(NULL, &session, &cause, originate_string, timeout, NULL, NULL, NULL, NULL, ovars, SOF_NONE, NULL); + add_outbound_call(id, &cancel_cause); + + status = switch_ivr_originate(NULL, &session, &cause, originate_string, timeout, NULL, NULL, NULL, NULL, ovars, SOF_NONE, &cancel_cause); + + del_outbound_call(id); + - if (status != SWITCH_STATUS_SUCCESS) { + if (status != SWITCH_STATUS_SUCCESS || cause != SWITCH_CAUSE_SUCCESS) { for (i = 0; i < cbh->rowcount; i++) { struct call_helper *h = cbh->rows[i]; - char *sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, " - "outbound_fail_count=outbound_fail_count+1, next_avail=%ld + lag where uuid='%q' and use_count > 0", + char *sql = switch_mprintf("update fifo_outbound set ring_count=ring_count-1, " + "outbound_fail_count=outbound_fail_count+1, next_avail=%ld + lag where uuid='%q' and ring_count > 0", (long) switch_epoch_time_now(NULL), h->uuid); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); @@ -1126,6 +1129,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "result", "failure"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "cause", switch_channel_cause2str(cause)); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "originate_string", originate_string); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Outbound-UUID-List", uuid_list); switch_event_fire(&event); } goto end; @@ -1140,6 +1144,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "outbound-strategy", "ringall"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "caller-uuid", id); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Outbound-UUID", switch_channel_get_variable(channel, "fifo_outbound_uuid")); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Outbound-UUID-List", uuid_list); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "result", "success"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "originate_string", originate_string); switch_event_fire(&event); @@ -1147,7 +1152,6 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_channel_set_variable(channel, "fifo_pop_order", NULL); - switch_core_event_hook_add_state_change(session, r_hanguphook); app_name = "fifo"; arg = switch_core_session_sprintf(session, "%s out nowait", node_name); @@ -1155,11 +1159,20 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_caller_extension_add_application(session, extension, app_name, arg); switch_channel_set_caller_extension(channel, extension); switch_channel_set_state(channel, CS_EXECUTE); + switch_channel_wait_for_state(channel, NULL, CS_EXECUTE); switch_core_session_rwunlock(session); + + for (i = 0; i < cbh->rowcount; i++) { + struct call_helper *h = cbh->rows[i]; + char *sql = switch_mprintf("update fifo_outbound set ring_count=ring_count-1 where uuid='%q' and ring_count > 0", h->uuid); + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + } end: switch_safe_free(originate_string); + switch_safe_free(uuid_list); switch_event_destroy(&ovars); @@ -1236,18 +1249,16 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) } - sql = switch_mprintf("update fifo_outbound set use_count=use_count+1 where uuid='%s'", h->uuid); + sql = switch_mprintf("update fifo_outbound set ring_count=ring_count+1 where uuid='%s'", h->uuid); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); - status = switch_ivr_originate(NULL, &session, &cause, originate_string, h->timeout, NULL, NULL, NULL, NULL, ovars, SOF_NONE, NULL); free(originate_string); - if (status != SWITCH_STATUS_SUCCESS) { - sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, " + sql = switch_mprintf("update fifo_outbound set ring_count=ring_count-1, " "outbound_fail_count=outbound_fail_count+1, next_avail=%ld + lag where uuid='%q' and use_count > 0", (long) switch_epoch_time_now(NULL), h->uuid); fifo_execute_sql(sql, globals.sql_mutex); @@ -1287,7 +1298,6 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) } } - switch_core_event_hook_add_state_change(session, r_hanguphook); switch_channel_set_variable(channel, "fifo_outbound_uuid", h->uuid); app_name = "fifo"; arg = switch_core_session_sprintf(session, "%s out %s", h->node_name, member_wait ? member_wait : "wait"); @@ -1375,7 +1385,7 @@ static void find_consumers(fifo_node_t *node) sql = switch_mprintf("select uuid, fifo_name, originate_string, simo_count, use_count, timeout, lag, " "next_avail, expires, static, outbound_call_count, outbound_fail_count, hostname " "from fifo_outbound " - "where taking_calls = 1 and (fifo_name = '%q') and (use_count < simo_count) and (next_avail = 0 or next_avail <= %ld) " + "where taking_calls = 1 and (fifo_name = '%q') and ((use_count+ring_count) < simo_count) and (next_avail = 0 or next_avail <= %ld) " "order by next_avail, outbound_fail_count, outbound_call_count", node->name, (long) switch_epoch_time_now(NULL) ); @@ -1620,7 +1630,6 @@ static uint32_t fifo_add_outbound(const char *node_name, const char *url, uint32 } - SWITCH_STANDARD_API(fifo_add_outbound_function) { char *data = NULL, *argv[4] = { 0 }; @@ -1661,7 +1670,6 @@ SWITCH_STANDARD_API(fifo_add_outbound_function) SWITCH_STANDARD_APP(fifo_member_usage_function) { - char *sql; switch_channel_t *channel = switch_core_session_get_channel(session); if (zstr(data)) { @@ -1670,12 +1678,8 @@ SWITCH_STANDARD_APP(fifo_member_usage_function) } switch_channel_set_variable(channel, "fifo_outbound_uuid", data); - sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,outbound_fail_count=0 where uuid='%s'", data); - fifo_execute_sql(sql, globals.sql_mutex); - switch_safe_free(sql); switch_core_event_hook_add_receive_message(session, messagehook); - switch_core_event_hook_add_state_change(session, hanguphook); } @@ -1709,6 +1713,8 @@ SWITCH_STANDARD_APP(fifo_function) const char *arg_inout = NULL; const char *serviced_uuid = NULL; + switch_core_event_hook_remove_receive_message(session, messagehook); + if (!globals.running) { return; } @@ -2040,8 +2046,8 @@ SWITCH_STANDARD_APP(fifo_function) const char *caller_uuid = NULL; switch_event_t *call_event; const char *outbound_id = switch_channel_get_variable(channel, "fifo_outbound_uuid"); - const char *track_use_count = switch_channel_get_variable(channel, "fifo_track_use_count"); - int do_track = switch_true(track_use_count); + //const char *track_use_count = switch_channel_get_variable(channel, "fifo_track_use_count"); + //int do_track = switch_true(track_use_count); if (!zstr(strat_str)) { if (!strcasecmp(strat_str, "more_ppl")) { @@ -2169,6 +2175,7 @@ SWITCH_STANDARD_APP(fifo_function) if ((varval = switch_channel_get_variable(channel, "fifo_bridge_uuid"))) { for (x = 0; x < MAX_PRI; x++) { if (fifo_queue_pop_nameval(node->fifo_list[pop_array[x]], "unique-id", varval, &pop, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS && pop) { + cancel_outbound_call(varval, SWITCH_CAUSE_PICKED_OFF); break; } } @@ -2395,9 +2402,8 @@ SWITCH_STANDARD_APP(fifo_function) switch_event_fire(&event); } - if (outbound_id && do_track) { + if (outbound_id) { sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,outbound_fail_count=0 where uuid='%s'", outbound_id); - fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); } @@ -2420,8 +2426,8 @@ SWITCH_STANDARD_APP(fifo_function) switch_ivr_multi_threaded_bridge(session, other_session, on_dtmf, other_session, session); - if (outbound_id && do_track) { - sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, outbound_call_total_count=outbound_call_total_count+1 " + if (outbound_id) { + sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, outbound_call_total_count=outbound_call_total_count+1, " "outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", (long) switch_epoch_time_now(NULL), outbound_id); @@ -2677,19 +2683,19 @@ static int xml_callback(void *pArg, int argc, char **argv, char **columnNames) switch_xml_set_attr_d(x_out, "taking-calls", argv[13]); switch_xml_set_attr_d(x_out, "status", argv[14]); - switch_xml_set_attr_d(x_out, "outbound_call_total_count", argv[15]); - switch_xml_set_attr_d(x_out, "outbound_fail_total_count", argv[16]); + switch_xml_set_attr_d(x_out, "outbound-call-total-count", argv[15]); + switch_xml_set_attr_d(x_out, "outbound-fail-total-count", argv[16]); if (arg == 17) { - switch_xml_set_attr_d(x_out, "logged_on_since", tb); + switch_xml_set_attr_d(x_out, "logged-on-since", tb); } else { - switch_xml_set_attr_d(x_out, "logged_off_since", tb); + switch_xml_set_attr_d(x_out, "logged-off-since", tb); } - switch_xml_set_attr_d(x_out, "manual_calls_out_count", argv[19]); - switch_xml_set_attr_d(x_out, "manual_calls_in_count", argv[20]); - switch_xml_set_attr_d(x_out, "manual_calls_out_total_count", argv[21]); - switch_xml_set_attr_d(x_out, "manual_calls_in_total_count", argv[22]); + switch_xml_set_attr_d(x_out, "manual-calls-out-count", argv[19]); + switch_xml_set_attr_d(x_out, "manual-calls-in-count", argv[20]); + switch_xml_set_attr_d(x_out, "manual-calls-out-total-count", argv[21]); + switch_xml_set_attr_d(x_out, "manual-calls-in-total-count", argv[22]); switch_xml_set_attr_d(x_out, "next-available", expires); @@ -3174,7 +3180,8 @@ const char outbound_sql[] = " manual_calls_out_count integer not null default 0,\n" " manual_calls_in_count integer not null default 0,\n" " manual_calls_out_total_count integer not null default 0,\n" - " manual_calls_in_total_count integer not null default 0\n" + " manual_calls_in_total_count integer not null default 0,\n" + " ring_count integer not null default 0\n" ");\n"; @@ -3269,11 +3276,12 @@ static switch_status_t load_config(int reload, int del_all) goto done; } - switch_cache_db_test_reactive(dbh, "delete from fifo_outbound where static = 1 or taking_calls < 0 or manual_calls_in_total_count < 0", "drop table fifo_outbound", outbound_sql); + switch_cache_db_test_reactive(dbh, "delete from fifo_outbound where static = 1 or taking_calls < 0 or ring_count < 0", + "drop table fifo_outbound", outbound_sql); switch_cache_db_test_reactive(dbh, "delete from fifo_bridge", "drop table fifo_bridge", bridge_sql); switch_cache_db_release_db_handle(&dbh); - fifo_execute_sql("update fifo_outbound set use_count=0,outbound_call_count=0,outbound_fail_count=0", globals.sql_mutex); + fifo_execute_sql("update fifo_outbound set ring_count=0,use_count=0,outbound_call_count=0,outbound_fail_count=0", globals.sql_mutex); if (reload) { switch_hash_index_t *hi; @@ -3663,6 +3671,10 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load) switch_core_new_memory_pool(&globals.pool); switch_core_hash_init(&globals.fifo_hash, globals.pool); + + switch_core_hash_init(&globals.orig_hash, globals.pool); + switch_mutex_init(&globals.orig_mutex, SWITCH_MUTEX_NESTED, globals.pool); + switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, globals.pool); switch_mutex_init(&globals.sql_mutex, SWITCH_MUTEX_NESTED, globals.pool); diff --git a/src/switch_channel.c b/src/switch_channel.c index 22f66bad25..1557830a31 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1072,18 +1072,19 @@ SWITCH_DECLARE(switch_bool_t) switch_channel_clear_flag_partner(switch_channel_t SWITCH_DECLARE(void) switch_channel_wait_for_state(switch_channel_t *channel, switch_channel_t *other_channel, switch_channel_state_t want_state) { - switch_channel_state_t state, mystate, ostate; - ostate = switch_channel_get_state(channel); + switch_channel_state_t state, mystate; for (;;) { - state = switch_channel_get_running_state(other_channel); + if (other_channel) { + state = switch_channel_get_running_state(other_channel); + } mystate = switch_channel_get_running_state(channel); if ((channel->state == channel->running_state && channel->running_state == want_state) || - other_channel->state >= CS_HANGUP || channel->state >= CS_HANGUP) { + (other_channel && other_channel->state >= CS_HANGUP) || channel->state >= CS_HANGUP) { break; } - switch_cond_next(); + switch_yield(20000); } } From bfe3128838c886926d8f37dadfd8f8f9890c942e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 15 Jul 2010 21:09:48 -0500 Subject: [PATCH 60/68] FSCORE-631 --- src/switch_ivr_originate.c | 39 ++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index 605a23270e..f54639d883 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -32,6 +32,8 @@ */ #include +#define QUOTED_ESC_COMMA 1 +#define UNQUOTED_ESC_COMMA 2 static const switch_state_handler_table_t originate_state_handlers; @@ -2268,6 +2270,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess for (r = 0; r < or_argc; r++) { char *p, *end = NULL; const char *var_begin, *var_end; + int q = 0; oglobals.hups = 0; reason = SWITCH_CAUSE_NONE; @@ -2287,6 +2290,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess oglobals.sent_ring = 0; oglobals.progress = 0; myflags = dftflags; + if (try > 0) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Originate attempt %d/%d in %d ms\n", try + 1, retries, @@ -2308,8 +2312,16 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess end = switch_find_end_paren(p, '[', ']'); } + if (*p == '\'') { + q = !q; + } + if (end && p < end && *p == ',') { - *p = '|'; + if (q) { + *p = QUOTED_ESC_COMMA; + } else { + *p = UNQUOTED_ESC_COMMA; + } } if (p == end) { @@ -2450,7 +2462,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess if (vdata && (var_begin = switch_stristr("origination_uuid=", vdata))) { char tmp[512] = ""; var_begin += strlen("origination_uuid="); - var_end = strchr(var_begin, '|'); + var_end = strchr(var_begin, UNQUOTED_ESC_COMMA); if (var_end) { strncpy(tmp, var_begin, var_end - var_begin); @@ -2467,7 +2479,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess if (vdata && (var_begin = switch_stristr("origination_caller_id_number=", vdata))) { var_begin += strlen("origination_caller_id_number="); - var_end = strchr(var_begin, '|'); + var_end = strchr(var_begin, UNQUOTED_ESC_COMMA); if (var_end) { strncpy(variable_buffer, var_begin, var_end - var_begin); @@ -2487,7 +2499,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess if (vdata && (var_begin = switch_stristr("origination_caller_id_name=", vdata))) { var_begin += strlen("origination_caller_id_name="); - var_end = strchr(var_begin, '|'); + var_end = strchr(var_begin, UNQUOTED_ESC_COMMA); if (var_end) { strncpy(variable_buffer, var_begin, var_end - var_begin); @@ -2507,7 +2519,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess if (vdata && (var_begin = switch_stristr("origination_privacy=", vdata))) { var_begin += strlen("origination_privacy="); - var_end = strchr(var_begin, '|'); + var_end = strchr(var_begin, UNQUOTED_ESC_COMMA); if (var_end) { strncpy(variable_buffer, var_begin, var_end - var_begin); @@ -2556,16 +2568,27 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess } } - if ((var_count = switch_separate_string(vdata, '|', var_array, (sizeof(var_array) / sizeof(var_array[0]))))) { + if ((var_count = switch_separate_string(vdata, UNQUOTED_ESC_COMMA, var_array, (sizeof(var_array) / sizeof(var_array[0]))))) { int x = 0; for (x = 0; x < var_count; x++) { char *inner_var_array[2] = { 0 }; int inner_var_count; - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "local variable string %d = [%s]\n", - x, var_array[x]); + char *p; + + for (p = var_array[x]; p && *p; p++) { + if (*p == QUOTED_ESC_COMMA) { + *p = ','; + } + } + + + if ((inner_var_count = switch_separate_string(var_array[x], '=', inner_var_array, (sizeof(inner_var_array) / sizeof(inner_var_array[0])))) == 2) { + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "local variable string %d = [%s=%s]\n", + x, inner_var_array[0], inner_var_array[1]); switch_event_add_header_string(local_var_event, SWITCH_STACK_BOTTOM, inner_var_array[0], inner_var_array[1]); } From 90dec5c79d6296a60850e68b2054fb7196c17b01 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 15 Jul 2010 22:08:20 -0500 Subject: [PATCH 61/68] fifo up --- src/mod/applications/mod_fifo/mod_fifo.c | 71 ++++++++++++++++-------- 1 file changed, 47 insertions(+), 24 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 75fb72677e..2e10e4fcea 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -1111,27 +1111,53 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void if (status != SWITCH_STATUS_SUCCESS || cause != SWITCH_CAUSE_SUCCESS) { - for (i = 0; i < cbh->rowcount; i++) { - struct call_helper *h = cbh->rows[i]; - char *sql = switch_mprintf("update fifo_outbound set ring_count=ring_count-1, " - "outbound_fail_count=outbound_fail_count+1, next_avail=%ld + lag where uuid='%q' and ring_count > 0", - (long) switch_epoch_time_now(NULL), h->uuid); - fifo_execute_sql(sql, globals.sql_mutex); - switch_safe_free(sql); - - } + const char *acceptable = "false"; + switch (cause) { + case SWITCH_CAUSE_ORIGINATOR_CANCEL: + case SWITCH_CAUSE_PICKED_OFF: + { + acceptable = "true"; + + for (i = 0; i < cbh->rowcount; i++) { + struct call_helper *h = cbh->rows[i]; + char *sql = switch_mprintf("update fifo_outbound set ring_count=ring_count-1 " + "where uuid='%q' and ring_count > 0", h->uuid); + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + } + + } + break; + default: + { + for (i = 0; i < cbh->rowcount; i++) { + struct call_helper *h = cbh->rows[i]; + char *sql = switch_mprintf("update fifo_outbound set ring_count=ring_count-1, " + "outbound_fail_count=outbound_fail_count+1, " + "outbound_fail_total_count = outbound_fail_total_count+1, " + "next_avail=%ld + lag where uuid='%q' and ring_count > 0", + (long) switch_epoch_time_now(NULL), h->uuid); + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + + } + } + } + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", node->name); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "post-dial"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "outbound-strategy", "ringall"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "caller-uuid", id); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "result", "failure"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "acceptable", acceptable); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "cause", switch_channel_cause2str(cause)); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "originate_string", originate_string); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Outbound-UUID-List", uuid_list); switch_event_fire(&event); } + goto end; } @@ -1512,32 +1538,29 @@ static int stop_node_thread(void) static void check_ocancel(switch_core_session_t *session) { - switch_channel_t *channel; - const char *var; + //switch_channel_t *channel; + //const char *var; switch_assert(session); - channel = switch_core_session_get_channel(session); + //channel = switch_core_session_get_channel(session); + + cancel_outbound_call(switch_core_session_get_uuid(session), SWITCH_CAUSE_ORIGINATOR_CANCEL); - if (!switch_channel_test_flag(channel, CF_TRANSFER) && (var = switch_channel_get_variable(channel, "fifo_originate_uuid"))) { - switch_core_session_hupall_matching_var("fifo_originate_uuid", var, - switch_channel_test_flag(channel, CF_ANSWERED) ? - SWITCH_CAUSE_NORMAL_CLEARING : SWITCH_CAUSE_ORIGINATOR_CANCEL); - } } static void check_cancel(fifo_node_t *node) { - int ppl_waiting = node_consumer_wait_count(node); + int ppl_waiting = node_consumer_wait_count(node); - if (node->ring_consumer_count > 0 && ppl_waiting < 1) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Outbound call count (%d) exceeds required value for queue %s (%d), " - "Ending extraneous calls\n", node->ring_consumer_count, node->name, ppl_waiting); + if (node->ring_consumer_count > 0 && ppl_waiting < 1) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Outbound call count (%d) exceeds required value for queue %s (%d), " + "Ending extraneous calls\n", node->ring_consumer_count, node->name, ppl_waiting); - - switch_core_session_hupall_matching_var("fifo_hangup_check", node->name, SWITCH_CAUSE_ORIGINATOR_CANCEL); - } + + switch_core_session_hupall_matching_var("fifo_hangup_check", node->name, SWITCH_CAUSE_ORIGINATOR_CANCEL); + } } static void send_presence(fifo_node_t *node) From 72be253d2b4fe77e5dd2f8069bd8e75b136d8950 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 16 Jul 2010 10:05:12 -0500 Subject: [PATCH 62/68] MODSOFIA-83 --- src/mod/endpoints/mod_sofia/sofia.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index ae35a47fb3..f47711ecb1 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -684,6 +684,12 @@ void sofia_event_callback(nua_event_t event, int locked = 0; int check_destroy = 1; + + if (!sofia_test_pflag(profile, PFLAG_RUNNING)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Profile is shutting down.\n"); + return; + } + /* sofia_private will be == &mod_sofia_globals.keep_private whenever a request is done with a new handle that has to be freed whenever the request is done */ if (nh && sofia_private == &mod_sofia_globals.keep_private) { From 67c07ee1d160c634b6944be652fbd7df07cc0af9 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 16 Jul 2010 11:43:14 -0500 Subject: [PATCH 63/68] avoidance a different way --- src/switch_channel.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/switch_channel.c b/src/switch_channel.c index 1557830a31..e82af1e792 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1226,18 +1226,22 @@ SWITCH_DECLARE(char *) switch_channel_get_cap_string(switch_channel_t *channel) SWITCH_DECLARE(void) switch_channel_set_flag_value(switch_channel_t *channel, switch_channel_flag_t flag, uint32_t value) { + int HELD = 0; + switch_assert(channel); switch_assert(channel->flag_mutex); switch_mutex_lock(channel->flag_mutex); if (flag == CF_LEG_HOLDING && !channel->flags[flag] && channel->flags[CF_ANSWERED]) { - switch_mutex_unlock(channel->flag_mutex); - switch_channel_set_callstate(channel, CCS_HELD); - switch_mutex_lock(channel->flag_mutex); + HELD = 1; } channel->flags[flag] = value; switch_mutex_unlock(channel->flag_mutex); + if (HELD) { + switch_channel_set_callstate(channel, CCS_HELD); + } + if (flag == CF_OUTBOUND) { switch_channel_set_variable(channel, "is_outbound", "true"); } @@ -1319,16 +1323,22 @@ SWITCH_DECLARE(void) switch_channel_set_state_flag(switch_channel_t *channel, sw SWITCH_DECLARE(void) switch_channel_clear_flag(switch_channel_t *channel, switch_channel_flag_t flag) { + int ACTIVE = 0; + switch_assert(channel != NULL); switch_assert(channel->flag_mutex); switch_mutex_lock(channel->flag_mutex); if (flag == CF_LEG_HOLDING && channel->flags[flag] && channel->flags[CF_ANSWERED]) { - switch_channel_set_callstate(channel, CCS_ACTIVE); + ACTIVE = 1; } channel->flags[flag] = 0; switch_mutex_unlock(channel->flag_mutex); + if (ACTIVE) { + switch_channel_set_callstate(channel, CCS_ACTIVE); + } + if (flag == CF_OUTBOUND) { switch_channel_set_variable(channel, "is_outbound", NULL); } From 7055d02750cbd1b954c534a991d3115658cc6576 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 16 Jul 2010 11:43:23 -0500 Subject: [PATCH 64/68] fifo tweaks --- src/mod/applications/mod_fifo/mod_fifo.c | 43 +++++++++++++++++------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 2e10e4fcea..14192851c7 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -255,7 +255,7 @@ struct fifo_node { switch_memory_pool_t *pool; int has_outbound; int ready; - int busy; + long busy; int is_static; int outbound_per_cycle; char *outbound_name; @@ -968,6 +968,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1]; switch_call_cause_t cancel_cause = 0; char *uuid_list = NULL; + int connected = 0; switch_uuid_get(&uuid); switch_uuid_format(uuid_str, &uuid); @@ -984,8 +985,8 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void if (node) { switch_mutex_lock(node->mutex); - node->busy++; - node->ring_consumer_count = cbh->rowcount; + node->busy = switch_epoch_time_now(NULL) + 600; + node->ring_consumer_count = 1; switch_mutex_unlock(node->mutex); } else { goto end; @@ -1161,6 +1162,8 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void goto end; } + connected = 1; + channel = switch_core_session_get_channel(session); if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { @@ -1209,7 +1212,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void if (node) { switch_mutex_lock(node->mutex); node->ring_consumer_count = 0; - if (node->busy) node->busy--; + node->busy = switch_epoch_time_now(NULL) + connected; switch_mutex_unlock(node->mutex); } @@ -1233,7 +1236,8 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) switch_status_t status = SWITCH_STATUS_FALSE; switch_event_t *event = NULL; char *sql = NULL; - + int connected = 0; + switch_mutex_lock(globals.mutex); node = switch_core_hash_find(globals.fifo_hash, h->node_name); switch_mutex_unlock(globals.mutex); @@ -1241,7 +1245,7 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) if (node) { switch_mutex_lock(node->mutex); node->ring_consumer_count++; - node->busy++; + node->busy = switch_epoch_time_now(NULL) + 600; switch_mutex_unlock(node->mutex); } @@ -1304,6 +1308,8 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) goto end; } + connected = 1; + channel = switch_core_session_get_channel(session); if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { @@ -1341,7 +1347,7 @@ static void *SWITCH_THREAD_FUNC o_thread_run(switch_thread_t *thread, void *obj) if (node->ring_consumer_count-- < 0) { node->ring_consumer_count = 0; } - if (node->busy) node->busy--; + node->busy = switch_epoch_time_now(NULL) + connected; switch_mutex_unlock(node->mutex); } switch_core_destroy_memory_pool(&h->pool); @@ -1482,8 +1488,8 @@ static void *SWITCH_THREAD_FUNC node_thread_run(switch_thread_t *thread, void *o for (hi = switch_hash_first(NULL, globals.fifo_hash); hi; hi = switch_hash_next(hi)) { switch_hash_this(hi, &var, NULL, &val); if ((node = (fifo_node_t *) val)) { - if (node->has_outbound && node->ready && !node->busy) { - switch_mutex_lock(node->mutex); + switch_mutex_lock(node->mutex); + if (node->has_outbound && node->ready && switch_epoch_time_now(NULL) > node->busy) { ppl_waiting = node_consumer_wait_count(node); consumer_total = node->consumer_count; idle_consumers = node_idle_consumers(node); @@ -1494,8 +1500,8 @@ static void *SWITCH_THREAD_FUNC node_thread_run(switch_thread_t *thread, void *o if ((ppl_waiting - node->ring_consumer_count > 0) && (!consumer_total || !idle_consumers)) { find_consumers(node); } - switch_mutex_unlock(node->mutex); } + switch_mutex_unlock(node->mutex); } } switch_mutex_unlock(globals.mutex); @@ -1552,7 +1558,13 @@ static void check_ocancel(switch_core_session_t *session) static void check_cancel(fifo_node_t *node) { - int ppl_waiting = node_consumer_wait_count(node); + int ppl_waiting; + + if (node->outbound_strategy != NODE_STRATEGY_ENTERPRISE) { + return; + } + + ppl_waiting = node_consumer_wait_count(node); if (node->ring_consumer_count > 0 && ppl_waiting < 1) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Outbound call count (%d) exceeds required value for queue %s (%d), " @@ -1694,7 +1706,8 @@ SWITCH_STANDARD_API(fifo_add_outbound_function) SWITCH_STANDARD_APP(fifo_member_usage_function) { switch_channel_t *channel = switch_core_session_get_channel(session); - + char *sql; + if (zstr(data)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid!\n"); return; @@ -1702,6 +1715,10 @@ SWITCH_STANDARD_APP(fifo_member_usage_function) switch_channel_set_variable(channel, "fifo_outbound_uuid", data); + sql = switch_mprintf("update fifo_outbound set next_avail=%ld + lag where uuid='%q'", (long) switch_epoch_time_now(NULL), data); + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + switch_core_event_hook_add_receive_message(session, messagehook); } @@ -3304,7 +3321,7 @@ static switch_status_t load_config(int reload, int del_all) switch_cache_db_test_reactive(dbh, "delete from fifo_bridge", "drop table fifo_bridge", bridge_sql); switch_cache_db_release_db_handle(&dbh); - fifo_execute_sql("update fifo_outbound set ring_count=0,use_count=0,outbound_call_count=0,outbound_fail_count=0", globals.sql_mutex); + fifo_execute_sql("update fifo_outbound set ring_count=0,use_count=0,outbound_call_count=0,outbound_fail_count=0 where static=0", globals.sql_mutex); if (reload) { switch_hash_index_t *hi; From f7e2410e61a99fe67575ed667a061b7d76026216 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 16 Jul 2010 14:42:02 -0500 Subject: [PATCH 65/68] FSCORE-634 --- src/mod/applications/mod_commands/mod_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index c7d3df2843..f41e95cca1 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -1599,7 +1599,7 @@ SWITCH_STANDARD_API(ctl_function) arg = atoi(argv[1]); } switch_core_session_ctl(SCSC_MAX_SESSIONS, &arg); - stream->write_function(stream, "+OK max sessions: %f\n", arg); + stream->write_function(stream, "+OK max sessions: %d\n", arg); } else if (!strcasecmp(argv[0], "min_idle_cpu")) { double d = -1; From 98cc6311e31d731a900fd1e8b7299c12d60e899b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 16 Jul 2010 16:58:23 -0500 Subject: [PATCH 66/68] FSCORE-635 --- src/switch_rtp.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 0d4420eabe..da037e3086 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -2077,10 +2077,12 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t rtp_session->stats.inbound.packet_count++; } - if (rtp_session->recv_te && rtp_session->recv_msg.header.pt == rtp_session->recv_te) { + if ((rtp_session->recv_te && rtp_session->recv_msg.header.pt == rtp_session->recv_te) || + *bytes < rtp_header_len || + switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA) || switch_test_flag(rtp_session, SWITCH_RTP_FLAG_UDPTL)) { return SWITCH_STATUS_SUCCESS; } - + if (rtp_session->jb && rtp_session->recv_msg.header.version == 2 && *bytes) { if (rtp_session->recv_msg.header.m && rtp_session->recv_msg.header.pt != rtp_session->recv_te && @@ -2537,6 +2539,11 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ goto end; } + if (bytes < rtp_header_len) { + bytes = 0; + goto do_continue; + } + if (bytes) { rtp_session->missed_count = 0; @@ -2667,7 +2674,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ we put up with as much as we can so we don't have to deal with being punished for doing it right. Nice guys finish last! */ - if (bytes && !switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA) && + if (bytes > rtp_header_len && !switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA) && !switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PASS_RFC2833) && rtp_session->recv_msg.header.pt == rtp_session->recv_te) { switch_size_t len = bytes - rtp_header_len; unsigned char *packet = (unsigned char *) rtp_session->recv_msg.body; @@ -2959,7 +2966,9 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_read(switch_rtp_t *rtp_session, void *datalen = 0; return SWITCH_STATUS_BREAK; } else { - bytes -= rtp_header_len; + if (bytes > rtp_header_len) { + bytes -= rtp_header_len; + } } *datalen = bytes; @@ -3069,7 +3078,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read_frame(switch_rtp_t *rtp if (bytes < 0) { frame->datalen = 0; return bytes == -2 ? SWITCH_STATUS_TIMEOUT : SWITCH_STATUS_GENERR; - } else if (bytes == 0) { + } else if (bytes < rtp_header_len) { frame->datalen = 0; return SWITCH_STATUS_BREAK; } else { @@ -3098,7 +3107,9 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read(switch_rtp_t *rtp_sessi *datalen = 0; return SWITCH_STATUS_GENERR; } else { - bytes -= rtp_header_len; + if (bytes > rtp_header_len) { + bytes -= rtp_header_len; + } } *datalen = bytes; @@ -3126,7 +3137,9 @@ static int rtp_common_write(switch_rtp_t *rtp_session, send_msg->header.pt = rtp_session->te; } data = send_msg->body; - datalen -= rtp_header_len; + if (datalen > rtp_header_len) { + datalen -= rtp_header_len; + } } else { uint8_t m = 0; From f79e62f305f77a9a8e63e354a615f4817625e8c8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 16 Jul 2010 18:31:00 -0500 Subject: [PATCH 67/68] fifo up --- src/mod/applications/mod_fifo/mod_fifo.c | 235 +++++++++++++++++------ 1 file changed, 177 insertions(+), 58 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 14192851c7..58d7879aaf 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -696,15 +696,13 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_BRIDGE: case SWITCH_MESSAGE_INDICATE_UNBRIDGE: - if ((caller_session = switch_core_session_force_locate(msg->string_arg))) { + if ((caller_session = switch_core_session_locate(msg->string_arg))) { caller_channel = switch_core_session_get_channel(caller_session); if (msg->message_id == SWITCH_MESSAGE_INDICATE_BRIDGE) { switch_core_session_soft_lock(caller_session, 5); } else { switch_core_session_soft_unlock(caller_session); } - } else if (msg->message_id == SWITCH_MESSAGE_INDICATE_BRIDGE) { - goto end; } break; case SWITCH_MESSAGE_INDICATE_DISPLAY: @@ -724,7 +722,7 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch (msg->message_id) { case SWITCH_MESSAGE_INDICATE_BRIDGE: { - const char *col1 = NULL, *col2 = NULL; + long epoch_start = 0; char date[80] = ""; switch_time_t ts; @@ -732,7 +730,7 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_size_t retsize; const char *ced_name, *ced_number, *cid_name, *cid_number; - if (!caller_channel || switch_channel_test_app_flag(consumer_channel, CF_APP_TAGGED)) { + if (switch_channel_test_app_flag(consumer_channel, CF_APP_TAGGED)) { goto end; } @@ -741,11 +739,14 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_channel_set_variable(consumer_channel, "fifo_bridged", "true"); switch_channel_set_variable(consumer_channel, "fifo_manual_bridge", "true"); switch_channel_set_variable(consumer_channel, "fifo_role", "consumer"); - switch_channel_set_variable(caller_channel, "fifo_role", "caller"); - switch_process_import(consumer_session, caller_channel, "fifo_caller_consumer_import"); - switch_process_import(caller_session, consumer_channel, "fifo_consumer_caller_import"); + if (caller_channel) { + switch_channel_set_variable(caller_channel, "fifo_role", "caller"); + switch_process_import(consumer_session, caller_channel, "fifo_caller_consumer_import"); + switch_process_import(caller_session, consumer_channel, "fifo_consumer_caller_import"); + } + ced_name = switch_channel_get_variable(consumer_channel, "callee_id_name"); ced_number = switch_channel_get_variable(consumer_channel, "callee_id_number"); @@ -775,36 +776,38 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_event_fire(&event); } - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(caller_channel, event); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-start"); - switch_event_fire(&event); - } - - if (switch_channel_direction(consumer_channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { - col1 = "manual_calls_in_count"; - col2 = "manual_calls_in_total_count"; + if (caller_channel) { + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + switch_channel_event_set_data(caller_channel, event); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-start"); + switch_event_fire(&event); + } + + sql = switch_mprintf("insert into fifo_bridge " + "(fifo_name,caller_uuid,caller_caller_id_name,caller_caller_id_number,consumer_uuid,consumer_outgoing_uuid,bridge_start) " + "values ('%q','%q','%q','%q','%q','%q',%ld)", + MANUAL_QUEUE_NAME, + switch_core_session_get_uuid(caller_session), + ced_name, + ced_number, + switch_core_session_get_uuid(session), + switch_str_nil(outbound_id), + (long) switch_epoch_time_now(NULL) + ); } else { - col1 = "manual_calls_out_count"; - col2 = "manual_calls_out_total_count"; + sql = switch_mprintf("insert into fifo_bridge " + "(fifo_name,caller_uuid,caller_caller_id_name,caller_caller_id_number,consumer_uuid,consumer_outgoing_uuid,bridge_start) " + "values ('%q','%q','%q','%q','%q','%q',%ld)", + MANUAL_QUEUE_NAME, + "N/A", + ced_name, + ced_number, + switch_core_session_get_uuid(session), + switch_str_nil(outbound_id), + (long) switch_epoch_time_now(NULL) + ); } - - sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,%s=%s+1,%s=%s+1 where uuid='%q'", col1, col1, col2, col2, outbound_id); - fifo_execute_sql(sql, globals.sql_mutex); - switch_safe_free(sql); - - sql = switch_mprintf("insert into fifo_bridge " - "(fifo_name,caller_uuid,caller_caller_id_name,caller_caller_id_number,consumer_uuid,consumer_outgoing_uuid,bridge_start) " - "values ('%q','%q','%q','%q','%q','%q',%ld)", - MANUAL_QUEUE_NAME, - switch_core_session_get_uuid(caller_session), - ced_name, - ced_number, - switch_core_session_get_uuid(session), - switch_str_nil(outbound_id), - (long) switch_epoch_time_now(NULL) - ); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); @@ -817,16 +820,20 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ epoch_start = (long)switch_epoch_time_now(NULL); switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm); switch_channel_set_variable(consumer_channel, "fifo_status", "TALKING"); - switch_channel_set_variable(consumer_channel, "fifo_target", switch_core_session_get_uuid(caller_session)); + if (caller_session) { + switch_channel_set_variable(consumer_channel, "fifo_target", switch_core_session_get_uuid(caller_session)); + } switch_channel_set_variable(consumer_channel, "fifo_timestamp", date); switch_channel_set_variable_printf(consumer_channel, "fifo_epoch_start_bridge", "%ld", epoch_start); switch_channel_set_variable(consumer_channel, "fifo_role", "consumer"); - switch_channel_set_variable(caller_channel, "fifo_status", "TALKING"); - switch_channel_set_variable(caller_channel, "fifo_timestamp", date); - switch_channel_set_variable_printf(caller_channel, "fifo_epoch_start_bridge", "%ld", epoch_start); - switch_channel_set_variable(caller_channel, "fifo_target", switch_core_session_get_uuid(session)); - switch_channel_set_variable(caller_channel, "fifo_role", "caller"); + if (caller_channel) { + switch_channel_set_variable(caller_channel, "fifo_status", "TALKING"); + switch_channel_set_variable(caller_channel, "fifo_timestamp", date); + switch_channel_set_variable_printf(caller_channel, "fifo_epoch_start_bridge", "%ld", epoch_start); + switch_channel_set_variable(caller_channel, "fifo_target", switch_core_session_get_uuid(session)); + switch_channel_set_variable(caller_channel, "fifo_role", "caller"); + } } break; case SWITCH_MESSAGE_INDICATE_UNBRIDGE: @@ -850,9 +857,6 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); - sql = switch_mprintf("update fifo_outbound set use_count=use_count-1 where use_count > 0 and uuid='%q'", outbound_id); - fifo_execute_sql(sql, globals.sql_mutex); - switch_safe_free(sql); switch_channel_set_variable(consumer_channel, "fifo_status", "WAITING"); @@ -969,6 +973,7 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void switch_call_cause_t cancel_cause = 0; char *uuid_list = NULL; int connected = 0; + const char *codec; switch_uuid_get(&uuid); switch_uuid_format(uuid_str, &uuid); @@ -1104,6 +1109,20 @@ static void *SWITCH_THREAD_FUNC ringall_thread_run(switch_thread_t *thread, void } + if ((codec = switch_event_get_header(pop, "variable_sip_use_codec_name"))) { + const char *rate = switch_event_get_header(pop, "variable_sip_use_codec_rate"); + const char *ptime = switch_event_get_header(pop, "variable_sip_use_codec_ptime"); + char nstr[256] = ""; + + if (strcasecmp(codec, "PCMU") && strcasecmp(codec, "PCMA")) { + switch_snprintf(nstr, sizeof(nstr), "%s@%si@%sh,PCMU,PCMA", codec, ptime, rate); + } else { + switch_snprintf(nstr, sizeof(nstr), "%s@%si@%sh", codec, ptime, rate); + } + + switch_event_add_header_string(ovars, SWITCH_STACK_BOTTOM, "absolute_codec_string", nstr); + } + add_outbound_call(id, &cancel_cause); status = switch_ivr_originate(NULL, &session, &cause, originate_string, timeout, NULL, NULL, NULL, NULL, ovars, SOF_NONE, &cancel_cause); @@ -1703,10 +1722,49 @@ SWITCH_STANDARD_API(fifo_add_outbound_function) } -SWITCH_STANDARD_APP(fifo_member_usage_function) +static void dec_use_count(switch_channel_t *channel) +{ + char *sql; + const char *outbound_id; + switch_event_t *event; + long now = (long) switch_epoch_time_now(NULL); + + if ((outbound_id = switch_channel_get_variable(channel, "fifo_outbound_uuid"))) { + sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, stop_time=%ld, next_avail=%ld + lag where use_count > 0 and uuid='%q'", + now, now, outbound_id); + fifo_execute_sql(sql, globals.sql_mutex); + switch_safe_free(sql); + } + + 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-stop"); + switch_event_fire(&event); + } + + +} + +static switch_status_t hanguphook(switch_core_session_t *session) +{ + switch_channel_t *channel = switch_core_session_get_channel(session); + switch_channel_state_t state = switch_channel_get_state(channel); + + if (state == CS_HANGUP) { + dec_use_count(channel); + switch_core_event_hook_remove_state_change(session, hanguphook); + } + + return SWITCH_STATUS_SUCCESS; +} + +SWITCH_STANDARD_APP(fifo_track_call_function) { switch_channel_t *channel = switch_core_session_get_channel(session); char *sql; + const char *col1 = NULL, *col2 = NULL, *cid_name, *cid_number; + switch_event_t *event; if (zstr(data)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid!\n"); @@ -1714,13 +1772,40 @@ SWITCH_STANDARD_APP(fifo_member_usage_function) } switch_channel_set_variable(channel, "fifo_outbound_uuid", data); + + if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { + col1 = "manual_calls_in_count"; + col2 = "manual_calls_in_total_count"; + } else { + col1 = "manual_calls_out_count"; + col2 = "manual_calls_out_total_count"; + } - sql = switch_mprintf("update fifo_outbound set next_avail=%ld + lag where uuid='%q'", (long) switch_epoch_time_now(NULL), data); + sql = switch_mprintf("update fifo_outbound set start_time=%ld,outbound_fail_count=0,use_count=use_count+1,%s=%s+1,%s=%s+1 where uuid='%q'", + (long) switch_epoch_time_now(NULL), col1, col1, col2, col2, data); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); + + if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND) { + cid_name = switch_channel_get_variable(channel, "destination_number"); + cid_number = cid_name; + } else { + cid_name = switch_channel_get_variable(channel, "caller_id_name"); + cid_number = switch_channel_get_variable(channel, "caller_id_number"); + } + + 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_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-start"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Caller-CID-Name", cid_name); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Caller-CID-Number", cid_number); + switch_event_fire(&event); + } + switch_core_event_hook_add_receive_message(session, messagehook); - + switch_core_event_hook_add_state_change(session, hanguphook); } typedef enum { @@ -1753,7 +1838,10 @@ SWITCH_STANDARD_APP(fifo_function) const char *arg_inout = NULL; const char *serviced_uuid = NULL; - switch_core_event_hook_remove_receive_message(session, messagehook); + if (switch_core_event_hook_remove_receive_message(session, messagehook) == SWITCH_STATUS_SUCCESS) { + dec_use_count(channel); + switch_core_event_hook_remove_state_change(session, hanguphook); + } if (!globals.running) { return; @@ -2443,7 +2531,8 @@ SWITCH_STANDARD_APP(fifo_function) } if (outbound_id) { - sql = switch_mprintf("update fifo_outbound set use_count=use_count+1,outbound_fail_count=0 where uuid='%s'", outbound_id); + sql = switch_mprintf("update fifo_outbound set start_time=%ld,use_count=use_count+1,outbound_fail_count=0 where uuid='%s'", + switch_epoch_time_now(NULL), outbound_id); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); } @@ -2467,9 +2556,12 @@ SWITCH_STANDARD_APP(fifo_function) switch_ivr_multi_threaded_bridge(session, other_session, on_dtmf, other_session, session); if (outbound_id) { - sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, outbound_call_total_count=outbound_call_total_count+1, " + long now = (long) switch_epoch_time_now(NULL); + + sql = switch_mprintf("update fifo_outbound set stop_time=%ld, use_count=use_count-1, " + "outbound_call_total_count=outbound_call_total_count+1, " "outbound_call_count=outbound_call_count+1, next_avail=%ld + lag where uuid='%s' and use_count > 0", - (long) switch_epoch_time_now(NULL), outbound_id); + now, now, outbound_id); fifo_execute_sql(sql, globals.sql_mutex); switch_safe_free(sql); @@ -2705,7 +2797,6 @@ static int xml_callback(void *pArg, int argc, char **argv, char **columnNames) if ((etime = atol(argv[arg]))) { switch_size_t retsize; - switch_time_exp_lt(&tm, switch_time_from_sec(etime)); switch_strftime_nocheck(atime, &retsize, sizeof(atime), "%Y-%m-%d %T", &tm); } else { @@ -2737,6 +2828,30 @@ static int xml_callback(void *pArg, int argc, char **argv, char **columnNames) switch_xml_set_attr_d(x_out, "manual-calls-out-total-count", argv[21]); switch_xml_set_attr_d(x_out, "manual-calls-in-total-count", argv[22]); + if (argc > 23) { + switch_xml_set_attr_d(x_out, "ring-count", argv[23]); + + if ((etime = atol(argv[24]))) { + switch_size_t retsize; + switch_time_exp_lt(&tm, switch_time_from_sec(etime)); + switch_strftime_nocheck(atime, &retsize, sizeof(atime), "%Y-%m-%d %T", &tm); + } else { + switch_set_string(atime, "never"); + } + + switch_xml_set_attr_d(x_out, "start-time", tb); + + if ((etime = atol(argv[25]))) { + switch_size_t retsize; + switch_time_exp_lt(&tm, switch_time_from_sec(etime)); + switch_strftime_nocheck(atime, &retsize, sizeof(atime), "%Y-%m-%d %T", &tm); + } else { + switch_set_string(atime, "never"); + } + + switch_xml_set_attr_d(x_out, "stop-time", tb); + } + switch_xml_set_attr_d(x_out, "next-available", expires); @@ -2768,7 +2883,8 @@ static int xml_outbound(switch_xml_t xml, fifo_node_t *node, char *container, ch sql = switch_mprintf("select uuid, fifo_name, originate_string, simo_count, use_count, timeout, " "lag, next_avail, expires, static, outbound_call_count, outbound_fail_count, " "hostname, taking_calls, status, outbound_call_total_count, outbound_fail_total_count, active_time, inactive_time, " - "manual_calls_out_count, manual_calls_in_count, manual_calls_out_total_count, manual_calls_in_total_count " + "manual_calls_out_count, manual_calls_in_count, manual_calls_out_total_count, manual_calls_in_total_count," + "ring_count,start_time,stop_time " "from fifo_outbound where fifo_name = '%q'", node->name); } @@ -3221,7 +3337,9 @@ const char outbound_sql[] = " manual_calls_in_count integer not null default 0,\n" " manual_calls_out_total_count integer not null default 0,\n" " manual_calls_in_total_count integer not null default 0,\n" - " ring_count integer not null default 0\n" + " ring_count integer not null default 0,\n" + " start_time integer not null default 0,\n" + " stop_time integer not null default 0\n" ");\n"; @@ -3316,12 +3434,13 @@ static switch_status_t load_config(int reload, int del_all) goto done; } - switch_cache_db_test_reactive(dbh, "delete from fifo_outbound where static = 1 or taking_calls < 0 or ring_count < 0", + switch_cache_db_test_reactive(dbh, "delete from fifo_outbound where static = 1 or taking_calls < 0 or stop_time < 0", "drop table fifo_outbound", outbound_sql); switch_cache_db_test_reactive(dbh, "delete from fifo_bridge", "drop table fifo_bridge", bridge_sql); switch_cache_db_release_db_handle(&dbh); - fifo_execute_sql("update fifo_outbound set ring_count=0,use_count=0,outbound_call_count=0,outbound_fail_count=0 where static=0", globals.sql_mutex); + fifo_execute_sql("update fifo_outbound set start_time=0,stop_time=0,ring_count=0,use_count=0," + "outbound_call_count=0,outbound_fail_count=0 where static=0", globals.sql_mutex); if (reload) { switch_hash_index_t *hi; @@ -3732,7 +3851,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load) *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_APP(app_interface, "fifo_track_call", "Count a call as a fifo call in the manual_calls queue", - "", fifo_member_usage_function, "", SAF_SUPPORT_NOMEDIA); + "", fifo_track_call_function, "", SAF_SUPPORT_NOMEDIA); SWITCH_ADD_API(commands_api_interface, "fifo", "Return data about a fifo", fifo_api_function, FIFO_API_SYNTAX); SWITCH_ADD_API(commands_api_interface, "fifo_member", "Add members to a fifo", fifo_member_api_function, FIFO_MEMBER_API_SYNTAX); SWITCH_ADD_API(commands_api_interface, "fifo_add_outbound", "Add outbound members to a fifo", fifo_add_outbound_function, " []"); From 44b760ceb1ffc0a073aef9341abd9d892045c10b Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sat, 17 Jul 2010 03:54:20 -0400 Subject: [PATCH 68/68] revert 98cc631 (FSCORE-635) causes incorrect media timeouts on some bridged sip to sip calls --- src/switch_rtp.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/switch_rtp.c b/src/switch_rtp.c index da037e3086..0d4420eabe 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -2077,12 +2077,10 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t rtp_session->stats.inbound.packet_count++; } - if ((rtp_session->recv_te && rtp_session->recv_msg.header.pt == rtp_session->recv_te) || - *bytes < rtp_header_len || - switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA) || switch_test_flag(rtp_session, SWITCH_RTP_FLAG_UDPTL)) { + if (rtp_session->recv_te && rtp_session->recv_msg.header.pt == rtp_session->recv_te) { return SWITCH_STATUS_SUCCESS; } - + if (rtp_session->jb && rtp_session->recv_msg.header.version == 2 && *bytes) { if (rtp_session->recv_msg.header.m && rtp_session->recv_msg.header.pt != rtp_session->recv_te && @@ -2539,11 +2537,6 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ goto end; } - if (bytes < rtp_header_len) { - bytes = 0; - goto do_continue; - } - if (bytes) { rtp_session->missed_count = 0; @@ -2674,7 +2667,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ we put up with as much as we can so we don't have to deal with being punished for doing it right. Nice guys finish last! */ - if (bytes > rtp_header_len && !switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA) && + if (bytes && !switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA) && !switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PASS_RFC2833) && rtp_session->recv_msg.header.pt == rtp_session->recv_te) { switch_size_t len = bytes - rtp_header_len; unsigned char *packet = (unsigned char *) rtp_session->recv_msg.body; @@ -2966,9 +2959,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_read(switch_rtp_t *rtp_session, void *datalen = 0; return SWITCH_STATUS_BREAK; } else { - if (bytes > rtp_header_len) { - bytes -= rtp_header_len; - } + bytes -= rtp_header_len; } *datalen = bytes; @@ -3078,7 +3069,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read_frame(switch_rtp_t *rtp if (bytes < 0) { frame->datalen = 0; return bytes == -2 ? SWITCH_STATUS_TIMEOUT : SWITCH_STATUS_GENERR; - } else if (bytes < rtp_header_len) { + } else if (bytes == 0) { frame->datalen = 0; return SWITCH_STATUS_BREAK; } else { @@ -3107,9 +3098,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read(switch_rtp_t *rtp_sessi *datalen = 0; return SWITCH_STATUS_GENERR; } else { - if (bytes > rtp_header_len) { - bytes -= rtp_header_len; - } + bytes -= rtp_header_len; } *datalen = bytes; @@ -3137,9 +3126,7 @@ static int rtp_common_write(switch_rtp_t *rtp_session, send_msg->header.pt = rtp_session->te; } data = send_msg->body; - if (datalen > rtp_header_len) { - datalen -= rtp_header_len; - } + datalen -= rtp_header_len; } else { uint8_t m = 0;