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 baaa301818..a258184d01 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 @@ -60,6 +60,9 @@ static time_t congestion_timeouts[MAX_TRUNK_GROUPS]; static ftdm_sangoma_boost_trunkgroup_t *g_trunkgroups[MAX_TRUNK_GROUPS]; +static ftdm_io_interface_t ftdm_sangoma_boost_interface; +static ftdm_status_t ftdm_sangoma_boost_list_sigmods(ftdm_stream_handle_t *stream); + #define BOOST_QUEUE_SIZE 500 /* get freetdm span and chan depending on the span mode */ @@ -1762,6 +1765,81 @@ end: return NULL; } + +#define FTDM_BOOST_SYNTAX "list sigmods | " +/** + * \brief API function to kill or debug a sangoma_boost span + * \param stream API stream handler + * \param data String containing argurments + * \return Flags + */ +static FIO_API_FUNCTION(ftdm_sangoma_boost_api) +{ + char *mycmd = NULL, *argv[10] = { 0 }; + int argc = 0; + + if (data) { + mycmd = ftdm_strdup(data); + argc = ftdm_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); + } + + if (argc > 1) { + if (!strcasecmp(argv[0], "list")) { + if (!strcasecmp(argv[1], "sigmods")) { + if (ftdm_sangoma_boost_list_sigmods(stream) != FTDM_SUCCESS) { + stream->write_function(stream, "%s: -ERR failed to execute cmd\n", __FILE__); + goto done; + } + goto done; + } + } else { + boost_sigmod_interface_t *sigmod_iface = NULL; + sigmod_iface = hashtable_search(g_boost_modules_hash, argv[0]); + if (sigmod_iface) { + char *p = strchr(data, ' '); + if (++p) { + char* mydup = strdup(p); + if(sigmod_iface->exec_api == NULL) { + stream->write_function(stream, "%s does not support api functions\n", sigmod_iface->name); + goto done; + } + //stream->write_function(stream, "sigmod:%s command:%s\n", sigmod_iface->name, mydup); + if (sigmod_iface->exec_api(stream, mydup) != FTDM_SUCCESS) { + stream->write_function(stream, "-ERR:failed to execute command:%s\n", mydup); + } + free(mydup); + } + + goto done; + } else { + stream->write_function(stream, "-ERR: Could not find sigmod %s\n", argv[0]); + } + } + } + stream->write_function(stream, "-ERR: Usage: %s\n", FTDM_BOOST_SYNTAX); +done: + ftdm_safe_free(mycmd); + return FTDM_SUCCESS; +} + +/** + * \brief Loads sangoma_boost IO module + * \param fio FreeTDM IO interface + * \return Success + */ +static FIO_IO_LOAD_FUNCTION(ftdm_sangoma_boost_io_init) +{ + assert(fio != NULL); + memset(&ftdm_sangoma_boost_interface, 0, sizeof(ftdm_sangoma_boost_interface)); + + ftdm_sangoma_boost_interface.name = "boost"; + ftdm_sangoma_boost_interface.api = ftdm_sangoma_boost_api; + + *fio = &ftdm_sangoma_boost_interface; + + return FTDM_SUCCESS; +} + /** * \brief Loads sangoma boost signaling module * \param fio FreeTDM IO interface @@ -2250,12 +2328,31 @@ static FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_sangoma_boost_configure_span) return FTDM_SUCCESS; } +static ftdm_status_t ftdm_sangoma_boost_list_sigmods(ftdm_stream_handle_t *stream) +{ + ftdm_hash_iterator_t *i = NULL; + boost_sigmod_interface_t *sigmod_iface = NULL; + const void *key = NULL; + void *val = NULL; + + stream->write_function(stream, "List of loaded sigmod modules:\n"); + for (i = hashtable_first(g_boost_modules_hash); i; i = hashtable_next(i)) { + hashtable_this(i, &key, NULL, &val); + if (key && val) { + sigmod_iface = val; + stream->write_function(stream, " %s\n", sigmod_iface->name); + } + } + stream->write_function(stream, "\n"); + return FTDM_SUCCESS; +} + /** * \brief FreeTDM sangoma boost signaling module definition */ EX_DECLARE_DATA ftdm_module_t ftdm_module = { /*.name =*/ "sangoma_boost", - /*.io_load =*/ NULL, + /*.io_load =*/ ftdm_sangoma_boost_io_init, /*.io_unload =*/ NULL, /*.sig_load = */ ftdm_sangoma_boost_init, /*.sig_configure =*/ NULL, diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_interface.h b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_interface.h index b555e24338..d7ad6de84f 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_interface.h +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_interface.h @@ -37,7 +37,6 @@ #include "freetdm.h" - #ifdef __cplusplus extern "C" { #endif @@ -180,6 +179,15 @@ typedef ftdm_status_t (*boost_on_load_func_t) BOOST_ON_LOAD_ARGS; typedef ftdm_status_t (*boost_on_unload_func_t) BOOST_ON_UNLOAD_ARGS; #define BOOST_ON_UNLOAD_FUNCTION(name) ftdm_status_t name BOOST_ON_UNLOAD_ARGS +/*! + \brief Called when user wants to execute sigmod api function + \return FTDM_SUCCESS or FTDM_FAIL + */ +#define BOOST_API_ARGS (ftdm_stream_handle_t *stream, char *cmd) +typedef ftdm_status_t (*boost_api_func_t) BOOST_API_ARGS; +#define BOOST_API_FUNCTION(name) ftdm_status_t name BOOST_API_ARGS + + /*! \brief The boost signaling module interface */ @@ -212,6 +220,8 @@ typedef struct boost_sigmod_interface_s { boost_on_load_func_t on_load; /*! \brief the module is about to be unloaded */ boost_on_unload_func_t on_unload; + /*! \brief module api function */ + boost_api_func_t exec_api; /*! \brief private pointer for the interface user */ void *pvt; } boost_sigmod_interface_t;