From 1f9bc6e9349718d1c7b9536f97d69ca18636b3de Mon Sep 17 00:00:00 2001 From: Marc Olivier Chouinard Date: Sun, 8 Dec 2019 10:26:57 -0500 Subject: [PATCH] [mod_distributor] Adding API distributor_check to verify if one exist. --- .../mod_distributor/mod_distributor.c | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/mod/applications/mod_distributor/mod_distributor.c b/src/mod/applications/mod_distributor/mod_distributor.c index cbdcc987ed..7a8d143bb1 100644 --- a/src/mod/applications/mod_distributor/mod_distributor.c +++ b/src/mod/applications/mod_distributor/mod_distributor.c @@ -283,7 +283,22 @@ static struct dist_node *find_next(struct dist_list *list, int etotal, char **ex return NULL; } +switch_bool_t dist_exist(const char *name) { + switch_bool_t result = SWITCH_FALSE; + struct dist_list *lp; + switch_mutex_lock(globals.mod_lock); + for (lp = globals.list; lp; lp = lp->next) { + if (!strcasecmp(name, lp->name)) { + result = SWITCH_TRUE; + break; + } + } + + switch_mutex_unlock(globals.mod_lock); + + return result; +} static char *dist_engine(const char *name) { struct dist_node *np = NULL; @@ -350,6 +365,19 @@ SWITCH_STANDARD_API(distributor_function) } +SWITCH_STANDARD_API(distributor_exist_function) +{ + if (!zstr(cmd)) { + switch_bool_t ret = dist_exist(cmd); + stream->write_function(stream, "%s", ret?"true":"false"); + } else { + stream->write_function(stream, "-err"); + } + + return SWITCH_STATUS_SUCCESS; + +} + static struct dist_list *find_list(const char *name) { struct dist_list *lp = NULL; @@ -507,6 +535,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_distributor_load) SWITCH_ADD_API(api_interface, "distributor", "Distributor API", distributor_function, "[ ]"); SWITCH_ADD_API(api_interface, "distributor_ctl", "Distributor API", distributor_ctl_function, "[reload]"); + SWITCH_ADD_API(api_interface, "distributor_exist", "Distributor Exist API", distributor_exist_function, ""); SWITCH_ADD_APP(app_interface, "distributor", "Distributor APP", "Distributor APP", distributor_exec, "[ ]", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);