From e5d5211402a0bb6d72d77ad1c76ab75b57eb8611 Mon Sep 17 00:00:00 2001 From: Gustavo Almeida Date: Tue, 11 Nov 2025 12:29:50 +0000 Subject: [PATCH 1/4] add command to show old calls --- .../applications/mod_commands/mod_commands.c | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 9184a78b93b..0054e113e9a 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -5697,7 +5697,7 @@ SWITCH_STANDARD_API(coalesce_function) return SWITCH_STATUS_SUCCESS; } -#define SHOW_SYNTAX "codec|endpoint|application|api|dialplan|file|timer|calls [count]|channels [count|like ]|calls|detailed_calls|bridged_calls|detailed_bridged_calls|aliases|complete|chat|management|modules|nat_map|say|interfaces|interface_types|tasks|limits|status" +#define SHOW_SYNTAX "codec|endpoint|application|api|dialplan|file|timer|calls [count]|channels [count|like ]|calls|detailed_calls|bridged_calls|detailed_bridged_calls|old_calls |aliases|complete|chat|management|modules|nat_map|say|interfaces|interface_types|tasks|limits|status" SWITCH_STANDARD_API(show_function) { char sql[1024]; @@ -5890,6 +5890,24 @@ SWITCH_STANDARD_API(show_function) if (argv[2] && !strcasecmp(argv[1], "as")) { as = argv[2]; } + } else if (!strcasecmp(command, "old_calls")) { + int age = 14400; // default 4 hours + + int format_arg_index = -1; + + if (argc > 1 && isdigit(*argv[1])) { + age = atoi(argv[1]); + format_arg_index = 2; + } else { + format_arg_index = 1; + } + + switch_snprintfv(sql, sizeof(sql), "SELECT * FROM calls where hostname='%q' and (strftime('%%s','now') - call_created_epoch) > %d order by call_created_epoch", + switch_core_get_switchname(), age); + + if (argc > format_arg_index + 1 && argv[format_arg_index+1] && !strcasecmp(argv[format_arg_index], "as")) { + as = argv[format_arg_index + 1]; + } } else { stream->write_function(stream, "-USAGE: %s\n", SHOW_SYNTAX); @@ -7844,6 +7862,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load) switch_console_set_complete("add show detailed_calls"); switch_console_set_complete("add show bridged_calls"); switch_console_set_complete("add show detailed_bridged_calls"); + switch_console_set_complete("add show old_calls"); switch_console_set_complete("add show endpoint"); switch_console_set_complete("add show file"); switch_console_set_complete("add show interfaces"); From 924a1fe16fe5fe2166aba08d5abb6c5a44b967c6 Mon Sep 17 00:00:00 2001 From: Gustavo Almeida Date: Tue, 11 Nov 2025 13:45:42 +0000 Subject: [PATCH 2/4] fix: remove argc --- src/mod/applications/mod_commands/mod_commands.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 0054e113e9a..1e54d43fc01 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -5892,20 +5892,17 @@ SWITCH_STANDARD_API(show_function) } } else if (!strcasecmp(command, "old_calls")) { int age = 14400; // default 4 hours + int format_arg_index = 1; - int format_arg_index = -1; - - if (argc > 1 && isdigit(*argv[1])) { + if (argv[1] && isdigit(*argv[1])) { age = atoi(argv[1]); format_arg_index = 2; - } else { - format_arg_index = 1; } switch_snprintfv(sql, sizeof(sql), "SELECT * FROM calls where hostname='%q' and (strftime('%%s','now') - call_created_epoch) > %d order by call_created_epoch", switch_core_get_switchname(), age); - if (argc > format_arg_index + 1 && argv[format_arg_index+1] && !strcasecmp(argv[format_arg_index], "as")) { + if (argv[format_arg_index] && argv[format_arg_index+1] && !strcasecmp(argv[format_arg_index], "as")) { as = argv[format_arg_index + 1]; } } else { From 46db19e72cf5946ebea700855ee55597a5d55dd5 Mon Sep 17 00:00:00 2001 From: Gustavo Almeida Date: Tue, 11 Nov 2025 14:02:58 +0000 Subject: [PATCH 3/4] feat: improvements to run in all ODBC --- src/mod/applications/mod_commands/mod_commands.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 1e54d43fc01..ad03da73361 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -5892,6 +5892,7 @@ SWITCH_STANDARD_API(show_function) } } else if (!strcasecmp(command, "old_calls")) { int age = 14400; // default 4 hours + time_t now = time(NULL); int format_arg_index = 1; if (argv[1] && isdigit(*argv[1])) { @@ -5899,12 +5900,16 @@ SWITCH_STANDARD_API(show_function) format_arg_index = 2; } - switch_snprintfv(sql, sizeof(sql), "SELECT * FROM calls where hostname='%q' and (strftime('%%s','now') - call_created_epoch) > %d order by call_created_epoch", - switch_core_get_switchname(), age); + time_t threshold_epoch = now - age; + + switch_snprintfv(sql, sizeof(sql), + "SELECT * FROM calls WHERE hostname='%q' AND call_created_epoch < %ld ORDER BY call_created_epoch", + switch_core_get_switchname(), threshold_epoch); if (argv[format_arg_index] && argv[format_arg_index+1] && !strcasecmp(argv[format_arg_index], "as")) { as = argv[format_arg_index + 1]; } + } else { stream->write_function(stream, "-USAGE: %s\n", SHOW_SYNTAX); From 5d8ee93eeec3bb743b42382d9f2e3991ba12fe2a Mon Sep 17 00:00:00 2001 From: Gustavo Almeida Date: Tue, 11 Nov 2025 14:56:24 +0000 Subject: [PATCH 4/4] fix: C90 problem --- src/mod/applications/mod_commands/mod_commands.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index ad03da73361..b7417532062 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -5893,6 +5893,7 @@ SWITCH_STANDARD_API(show_function) } else if (!strcasecmp(command, "old_calls")) { int age = 14400; // default 4 hours time_t now = time(NULL); + time_t threshold_epoch; int format_arg_index = 1; if (argv[1] && isdigit(*argv[1])) { @@ -5900,7 +5901,7 @@ SWITCH_STANDARD_API(show_function) format_arg_index = 2; } - time_t threshold_epoch = now - age; + threshold_epoch = now - age; switch_snprintfv(sql, sizeof(sql), "SELECT * FROM calls WHERE hostname='%q' AND call_created_epoch < %ld ORDER BY call_created_epoch",