Compare commits

...

3 Commits

Author SHA1 Message Date
windy-wang 7add00961e
Merge 06a53c6e8e 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
windy-wang 06a53c6e8e add uuid_partner command 2020-04-07 10:00:05 +08:00
2 changed files with 58 additions and 1 deletions

View File

@ -5039,6 +5039,34 @@ SWITCH_STANDARD_API(break_function)
return status;
}
#define PARTNER_SYNTAX "<uuid>"
SWITCH_STANDARD_API(partner_function)
{
switch_core_session_t *asession = NULL;
if (zstr(cmd)) {
stream->write_function(stream, "-ERR Missing UUID");
}
if ((asession = switch_core_session_locate(cmd))) {
switch_core_session_t *bsession = NULL;
if (switch_core_session_get_partner(asession, &bsession) == SWITCH_STATUS_SUCCESS) {
char *uuid = switch_core_session_get_uuid(bsession);
stream->write_function(stream, "+OK %s", uuid);
switch_core_session_rwunlock(bsession);
} else {
stream->write_function(stream, "-ERR Channel Not in bridge %s\n", cmd);
}
switch_core_session_rwunlock(asession);
} else {
stream->write_function(stream, "-ERR No such channel %s\n", cmd);
}
return SWITCH_STATUS_SUCCESS;
}
#define PAUSE_SYNTAX "<uuid> <on|off>"
SWITCH_STANDARD_API(pause_function)
{
@ -7709,6 +7737,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
SWITCH_ADD_API(commands_api_interface, "uuid_media_3p", "Reinvite FS in or out of media path using 3pcc", uuid_media_3p_function, MEDIA_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_media_reneg", "Media negotiation", uuid_media_neg_function, MEDIA_RENEG_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_park", "Park channel", park_function, PARK_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_partner", "Find bridged uuid", partner_function, PARTNER_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_pause", "Pause media on a channel", pause_function, PAUSE_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_phone_event", "Send an event to the phone", uuid_phone_event_function, PHONE_EVENT_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_ring_ready", "Sending ringing to a channel", uuid_ring_ready_function, RING_READY_SYNTAX);
@ -7863,6 +7892,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
switch_console_set_complete("add uuid_audio ::console::list_uuid stop");
switch_console_set_complete("add uuid_break ::console::list_uuid all");
switch_console_set_complete("add uuid_break ::console::list_uuid both");
switch_console_set_complete("add uuid_partner ::console::list_uuid");
switch_console_set_complete("add uuid_pause ::console::list_uuid on");
switch_console_set_complete("add uuid_pause ::console::list_uuid off");
switch_console_set_complete("add uuid_bridge ::console::list_uuid ::console::list_uuid");

View File

@ -106,6 +106,22 @@ char * pgsql_handle_get_error(switch_pgsql_handle_t *handle)
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)
{
int ret = 0;
@ -553,8 +569,15 @@ switch_status_t pgsql_handle_exec_detailed(const char *file, const char *func, i
goto error;
}
return pgsql_finish_results(handle);
if (pgsql_finish_results(handle) != SWITCH_STATUS_SUCCESS) {
goto error;
}
return SWITCH_STATUS_SUCCESS;
error:
pgsql_handle_set_error_if_not_set(handle, err);
return SWITCH_STATUS_FALSE;
}
@ -630,6 +653,7 @@ done:
pgsql_free_result(&result);
if (pgsql_finish_results(handle) != SWITCH_STATUS_SUCCESS) {
pgsql_handle_set_error_if_not_set(handle, err);
sstatus = SWITCH_STATUS_FALSE;
}
@ -638,6 +662,7 @@ done:
error:
pgsql_free_result(&result);
pgsql_handle_set_error_if_not_set(handle, err);
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;
error:
pgsql_handle_set_error_if_not_set(handle, err);
return SWITCH_STATUS_FALSE;
}