Compare commits

...

7 Commits

Author SHA1 Message Date
wmasilva 39a5cc59c3
Merge 73e826d993 into 5cb74797fe 2025-01-17 16:40:18 +00:00
Aron Podrigal 5cb74797fe
[mod_pgsql] err is now set correctly (dbh:last_error())
New function, `void pgsql_handle_set_error_if_not_set(switch_pgsql_handle_t *handle, char **err)` has been added to mod_pgsql module. This function is now called at several points where an error occurred but *err was not yet set.
2025-01-17 18:51:45 +03:00
Antonio Silva 73e826d993 fix coding stylte 2023-04-19 11:46:11 +01:00
wmasilva fc09cbd484
Merge branch 'signalwire:master' into mod_verto-cmd-profile 2023-04-19 11:37:01 +01:00
wmasilva 92c7ff89e2
Merge branch 'signalwire:master' into mod_verto-cmd-profile 2021-10-28 10:42:20 +01:00
António Silva b8ce15549f mod_verto: fix missing init function for cmd_profile 2021-10-28 11:40:45 +02:00
António Silva 26c8a0de39 mod_verto: add cmd profile restart all 2021-10-26 16:39:43 +01:00
3 changed files with 82 additions and 1 deletions

View File

@ -106,6 +106,22 @@ char * pgsql_handle_get_error(switch_pgsql_handle_t *handle)
return err_str; return err_str;
} }
void pgsql_handle_set_error_if_not_set(switch_pgsql_handle_t *handle, char **err)
{
char *err_str;
if (err && !(*err)) {
err_str = pgsql_handle_get_error(handle);
if (zstr(err_str)) {
switch_safe_free(err_str);
err_str = strdup((char *)"SQL ERROR!");
}
*err = err_str;
}
}
static int db_is_up(switch_pgsql_handle_t *handle) static int db_is_up(switch_pgsql_handle_t *handle)
{ {
int ret = 0; int ret = 0;
@ -553,8 +569,15 @@ switch_status_t pgsql_handle_exec_detailed(const char *file, const char *func, i
goto error; goto error;
} }
return pgsql_finish_results(handle); if (pgsql_finish_results(handle) != SWITCH_STATUS_SUCCESS) {
goto error;
}
return SWITCH_STATUS_SUCCESS;
error: error:
pgsql_handle_set_error_if_not_set(handle, err);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
@ -630,6 +653,7 @@ done:
pgsql_free_result(&result); pgsql_free_result(&result);
if (pgsql_finish_results(handle) != SWITCH_STATUS_SUCCESS) { if (pgsql_finish_results(handle) != SWITCH_STATUS_SUCCESS) {
pgsql_handle_set_error_if_not_set(handle, err);
sstatus = SWITCH_STATUS_FALSE; sstatus = SWITCH_STATUS_FALSE;
} }
@ -638,6 +662,7 @@ done:
error: error:
pgsql_free_result(&result); pgsql_free_result(&result);
pgsql_handle_set_error_if_not_set(handle, err);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
@ -1050,6 +1075,8 @@ switch_status_t pgsql_handle_callback_exec_detailed(const char *file, const char
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
error: error:
pgsql_handle_set_error_if_not_set(handle, err);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }

View File

@ -1362,6 +1362,23 @@ static void drop_detached(void)
switch_thread_rwlock_unlock(verto_globals.tech_rwlock); 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) static void attach_calls(jsock_t *jsock)
{ {
verto_pvt_t *tech_pvt; verto_pvt_t *tech_pvt;
@ -1422,6 +1439,36 @@ static void detach_calls(jsock_t *jsock)
if (wake) attach_wake(); 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) static void process_jrpc_response(jsock_t *jsock, cJSON *json)
{ {
} }
@ -5709,6 +5756,7 @@ SWITCH_STANDARD_API(verto_function)
"verto debug [0-10]\n" "verto debug [0-10]\n"
"verto perm <sessid> <type> <value>\n" "verto perm <sessid> <type> <value>\n"
"verto noperm <sessid> <type> <value>\n" "verto noperm <sessid> <type> <value>\n"
"verto profile restart all \n"
"--------------------------------------------------------------------------------\n"; "--------------------------------------------------------------------------------\n";
if (zstr(cmd)) { if (zstr(cmd)) {
@ -5771,6 +5819,8 @@ SWITCH_STANDARD_API(verto_function)
} }
stream->write_function(stream, "Debug Level: %s\n", switch_log_level2str(verto_globals.debug_level)); stream->write_function(stream, "Debug Level: %s\n", switch_log_level2str(verto_globals.debug_level));
goto done; goto done;
} else if (!strcasecmp(argv[0], "profile")) {
func = cmd_profile;
} }
if (func) { if (func) {
@ -6880,6 +6930,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_verto_load)
switch_console_set_complete("add verto debug-level"); switch_console_set_complete("add verto debug-level");
switch_console_set_complete("add verto status"); switch_console_set_complete("add verto status");
switch_console_set_complete("add verto xmlstatus"); 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, ""); SWITCH_ADD_JSON_API(json_api_interface, "store", "JSON store", json_store_function, "");

View File

@ -345,6 +345,9 @@ typedef switch_bool_t (*jrpc_func_t)(const char *method, cJSON *params, jsock_t
void set_log_path(const char *path); void set_log_path(const char *path);
static void kill_profiles(void);
static void run_profiles(void);
static int init(void);
/** @} */ /** @} */
#endif #endif