mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-11 15:07:07 +00:00
add check_sync to sofia cli (like flush_inbound_reg without the unreg)
This commit is contained in:
parent
1d3417a97b
commit
079f48458e
src/mod/endpoints/mod_sofia
@ -3273,6 +3273,19 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!strcasecmp(argv[1], "check_sync")) {
|
||||
if (argc > 2) {
|
||||
sofia_reg_check_call_id(profile, argv[2]);
|
||||
stream->write_function(stream, "+OK syncing all registrations matching specified call_id\n");
|
||||
} else {
|
||||
sofia_reg_check_sync(profile);
|
||||
stream->write_function(stream, "+OK syncing all registrations\n");
|
||||
}
|
||||
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
||||
if (!strcasecmp(argv[1], "flush_inbound_reg")) {
|
||||
int reboot = 0;
|
||||
|
||||
@ -3853,6 +3866,7 @@ SWITCH_STANDARD_API(sofia_function)
|
||||
" watchdog <on|off>\n\n"
|
||||
"sofia profile <name> [start | stop | restart | rescan]\n"
|
||||
" flush_inbound_reg [<call_id> | <[user]@domain>] [reboot]\n"
|
||||
" check_sync [<call_id> | <[user]@domain>]\n"
|
||||
" [register | unregister] [<gateway name> | all]\n"
|
||||
" killgw <gateway name>\n"
|
||||
" [stun-auto-disable | stun-enabled] [true | false]]\n"
|
||||
@ -5158,6 +5172,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
|
||||
switch_console_set_complete("add sofia profile ::sofia::list_profiles restart");
|
||||
|
||||
switch_console_set_complete("add sofia profile ::sofia::list_profiles flush_inbound_reg");
|
||||
switch_console_set_complete("add sofia profile ::sofia::list_profiles check_sync");
|
||||
switch_console_set_complete("add sofia profile ::sofia::list_profiles register ::sofia::list_profile_gateway");
|
||||
switch_console_set_complete("add sofia profile ::sofia::list_profiles unregister ::sofia::list_profile_gateway");
|
||||
switch_console_set_complete("add sofia profile ::sofia::list_profiles killgw ::sofia::list_profile_gateway");
|
||||
|
@ -983,6 +983,8 @@ void sofia_glue_tech_patch_sdp(private_object_t *tech_pvt);
|
||||
switch_status_t sofia_glue_tech_proxy_remote_addr(private_object_t *tech_pvt);
|
||||
void sofia_presence_event_thread_start(void);
|
||||
void sofia_reg_expire_call_id(sofia_profile_t *profile, const char *call_id, int reboot);
|
||||
void sofia_reg_check_call_id(sofia_profile_t *profile, const char *call_id);
|
||||
void sofia_reg_check_sync(sofia_profile_t *profile);
|
||||
switch_status_t sofia_glue_tech_choose_video_port(private_object_t *tech_pvt, int force);
|
||||
switch_status_t sofia_glue_tech_set_video_codec(private_object_t *tech_pvt, int force);
|
||||
char *sofia_glue_get_register_host(const char *uri);
|
||||
|
@ -733,6 +733,92 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now, int reboot)
|
||||
|
||||
}
|
||||
|
||||
|
||||
int sofia_reg_check_callback(void *pArg, int argc, char **argv, char **columnNames)
|
||||
{
|
||||
sofia_profile_t *profile = (sofia_profile_t *) pArg;
|
||||
|
||||
sofia_reg_send_reboot(profile, argv[1], argv[2], argv[3], argv[7], argv[11]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sofia_reg_check_call_id(sofia_profile_t *profile, const char *call_id)
|
||||
{
|
||||
char *sql = NULL;
|
||||
char *sqlextra = NULL;
|
||||
char *dup = strdup(call_id);
|
||||
char *host = NULL, *user = NULL;
|
||||
|
||||
switch_assert(dup);
|
||||
|
||||
if ((host = strchr(dup, '@'))) {
|
||||
*host++ = '\0';
|
||||
user = dup;
|
||||
} else {
|
||||
host = dup;
|
||||
}
|
||||
|
||||
if (!host) {
|
||||
host = "none";
|
||||
}
|
||||
|
||||
if (zstr(user)) {
|
||||
sqlextra = switch_mprintf(" or (sip_host='%q')", host);
|
||||
} else {
|
||||
sqlextra = switch_mprintf(" or (sip_user='%q' and sip_host='%q')", user, host);
|
||||
}
|
||||
|
||||
sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,rpid,expires"
|
||||
",user_agent,server_user,server_host,profile_name,network_ip"
|
||||
" from sip_registrations where call_id='%q' %s", call_id, sqlextra);
|
||||
|
||||
switch_mutex_lock(profile->ireg_mutex);
|
||||
sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_reg_check_callback, profile);
|
||||
switch_mutex_unlock(profile->ireg_mutex);
|
||||
|
||||
switch_safe_free(sql);
|
||||
switch_safe_free(sqlextra);
|
||||
switch_safe_free(dup);
|
||||
|
||||
}
|
||||
|
||||
void sofia_reg_check_sync(sofia_profile_t *profile)
|
||||
{
|
||||
char sql[1024];
|
||||
|
||||
switch_mutex_lock(profile->ireg_mutex);
|
||||
|
||||
switch_snprintf(sql, sizeof(sql), "select call_id,sip_user,sip_host,contact,status,rpid,expires"
|
||||
",user_agent,server_user,server_host,profile_name,network_ip"
|
||||
" from sip_registrations where expires > 0");
|
||||
|
||||
|
||||
sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_reg_del_callback, profile);
|
||||
switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and hostname='%s'", mod_sofia_globals.hostname);
|
||||
sofia_glue_actually_execute_sql(profile, sql, NULL);
|
||||
|
||||
|
||||
switch_snprintf(sql, sizeof(sql), "delete from sip_presence where expires > 0 and hostname='%s'", mod_sofia_globals.hostname);
|
||||
sofia_glue_actually_execute_sql(profile, sql, NULL);
|
||||
|
||||
switch_snprintf(sql, sizeof(sql), "delete from sip_authentication where expires > 0 and hostname='%s'", mod_sofia_globals.hostname);
|
||||
sofia_glue_actually_execute_sql(profile, sql, NULL);
|
||||
|
||||
switch_snprintf(sql, sizeof(sql), "select sub_to_user,sub_to_host,call_id from sip_subscriptions where expires >= -1 and hostname='%s'",
|
||||
mod_sofia_globals.hostname);
|
||||
sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_sub_del_callback, profile);
|
||||
|
||||
switch_snprintf(sql, sizeof(sql), "delete from sip_subscriptions where expires >= -1 and hostname='%s'", mod_sofia_globals.hostname);
|
||||
sofia_glue_actually_execute_sql(profile, sql, NULL);
|
||||
|
||||
switch_snprintf(sql, sizeof(sql), "delete from sip_dialogs where expires >= -1 and hostname='%s'", mod_sofia_globals.hostname);
|
||||
sofia_glue_actually_execute_sql(profile, sql, NULL);
|
||||
|
||||
switch_mutex_unlock(profile->ireg_mutex);
|
||||
|
||||
}
|
||||
|
||||
char *sofia_reg_find_reg_url(sofia_profile_t *profile, const char *user, const char *host, char *val, switch_size_t len)
|
||||
{
|
||||
struct callback_t cbt = { 0 };
|
||||
|
Loading…
x
Reference in New Issue
Block a user