From 26c8a0de39f093e508f554449ce7a9982f960943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Silva?= Date: Tue, 26 Oct 2021 16:39:43 +0100 Subject: [PATCH 1/3] mod_verto: add cmd profile restart all --- src/mod/endpoints/mod_verto/mod_verto.c | 47 +++++++++++++++++++++++++ src/mod/endpoints/mod_verto/mod_verto.h | 2 ++ 2 files changed, 49 insertions(+) diff --git a/src/mod/endpoints/mod_verto/mod_verto.c b/src/mod/endpoints/mod_verto/mod_verto.c index 8b69519f6f..60487e6b40 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.c +++ b/src/mod/endpoints/mod_verto/mod_verto.c @@ -1367,6 +1367,20 @@ static void drop_detached(void) switch_thread_rwlock_unlock(verto_globals.tech_rwlock); } +static void drop_calls(void) +{ + verto_pvt_t *tech_pvt; + + switch_thread_rwlock_rdlock(verto_globals.tech_rwlock); + for(tech_pvt = verto_globals.tech_head; tech_pvt; tech_pvt = tech_pvt->next) { + if (!switch_channel_up_nosig(tech_pvt->channel)) { + continue; + } + switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + } + switch_thread_rwlock_unlock(verto_globals.tech_rwlock); +} + static void attach_calls(jsock_t *jsock) { verto_pvt_t *tech_pvt; @@ -1427,6 +1441,34 @@ static void detach_calls(jsock_t *jsock) if (wake) attach_wake(); } +static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t *stream) +{ + const char *err; + + if (argc < 2) { + stream->write_function(stream, "Invalid Args!\n"); + return SWITCH_STATUS_SUCCESS; + } + + if (argv[1] && !strcasecmp(argv[0], "restart") && !strcasecmp(argv[1], "all")) { + switch_xml_reload(&err); + stream->write_function(stream, "Restart all profiles\n"); + /* hangup all calls */ + drop_calls(); + /* stop all profiles */ + kill_profiles(); + /* reload config: init ssl, load profiles, start profiles */ + init(); + run_profiles(); + return SWITCH_STATUS_SUCCESS; + } + + stream->write_function(stream, "-ERR Unknown command!\n"); + + return SWITCH_STATUS_SUCCESS; +} + + static void process_jrpc_response(jsock_t *jsock, cJSON *json) { } @@ -5698,6 +5740,7 @@ SWITCH_STANDARD_API(verto_function) "verto debug [0-10]\n" "verto perm \n" "verto noperm \n" + "verto profile restart all \n" "--------------------------------------------------------------------------------\n"; if (zstr(cmd)) { @@ -5761,6 +5804,9 @@ SWITCH_STANDARD_API(verto_function) stream->write_function(stream, "Debug Level: %s\n", switch_log_level2str(verto_globals.debug_level)); goto done; } + else if (!strcasecmp(argv[0], "profile")) { + func = cmd_profile; + } if (func) { status = func(&argv[lead], argc - lead, stream); @@ -6833,6 +6879,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_verto_load) switch_console_set_complete("add verto debug-level"); switch_console_set_complete("add verto status"); switch_console_set_complete("add verto xmlstatus"); + switch_console_set_complete("add verto profile restart all"); SWITCH_ADD_JSON_API(json_api_interface, "store", "JSON store", json_store_function, ""); diff --git a/src/mod/endpoints/mod_verto/mod_verto.h b/src/mod/endpoints/mod_verto/mod_verto.h index f3326f605d..8c992ac964 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.h +++ b/src/mod/endpoints/mod_verto/mod_verto.h @@ -345,6 +345,8 @@ typedef switch_bool_t (*jrpc_func_t)(const char *method, cJSON *params, jsock_t void set_log_path(const char *path); +static void kill_profiles(void); +static void run_profiles(void); /** @} */ #endif From b8ce15549fc34d6e25b22fca964395d5b36ab97a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Silva?= Date: Thu, 28 Oct 2021 11:40:45 +0200 Subject: [PATCH 2/3] mod_verto: fix missing init function for cmd_profile --- src/mod/endpoints/mod_verto/mod_verto.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mod/endpoints/mod_verto/mod_verto.h b/src/mod/endpoints/mod_verto/mod_verto.h index 8c992ac964..992b6a61b7 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.h +++ b/src/mod/endpoints/mod_verto/mod_verto.h @@ -347,6 +347,7 @@ void set_log_path(const char *path); static void kill_profiles(void); static void run_profiles(void); +static int init(void); /** @} */ #endif From 73e826d993cce6461b657656f59a93a976270a2a Mon Sep 17 00:00:00 2001 From: Antonio Silva Date: Wed, 19 Apr 2023 11:46:11 +0100 Subject: [PATCH 3/3] fix coding stylte --- src/mod/endpoints/mod_verto/mod_verto.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/mod/endpoints/mod_verto/mod_verto.c b/src/mod/endpoints/mod_verto/mod_verto.c index 88a6da0c45..b1fc508c61 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.c +++ b/src/mod/endpoints/mod_verto/mod_verto.c @@ -1368,12 +1368,15 @@ static void drop_calls(void) verto_pvt_t *tech_pvt; switch_thread_rwlock_rdlock(verto_globals.tech_rwlock); + for(tech_pvt = verto_globals.tech_head; tech_pvt; tech_pvt = tech_pvt->next) { + if (!switch_channel_up_nosig(tech_pvt->channel)) { continue; } switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); } + switch_thread_rwlock_unlock(verto_globals.tech_rwlock); } @@ -1443,6 +1446,7 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t if (argc < 2) { stream->write_function(stream, "Invalid Args!\n"); + return SWITCH_STATUS_SUCCESS; } @@ -1456,6 +1460,7 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t /* reload config: init ssl, load profiles, start profiles */ init(); run_profiles(); + return SWITCH_STATUS_SUCCESS; } @@ -5808,8 +5813,7 @@ SWITCH_STANDARD_API(verto_function) } stream->write_function(stream, "Debug Level: %s\n", switch_log_level2str(verto_globals.debug_level)); goto done; - } - else if (!strcasecmp(argv[0], "profile")) { + } else if (!strcasecmp(argv[0], "profile")) { func = cmd_profile; }