skinny: improve cleanup of devices during registration and unregistration, resolves some weird state issues when devices get disconnected
This commit is contained in:
parent
6c5e4e2119
commit
2eab94be78
|
@ -1315,25 +1315,12 @@ static int flush_listener_callback(void *pArg, int argc, char **argv, char **col
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void flush_listener(listener_t *listener)
|
void skinny_clean_listener_from_db(listener_t *listener)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(!zstr(listener->device_name)) {
|
if(!zstr(listener->device_name)) {
|
||||||
skinny_profile_t *profile = listener->profile;
|
skinny_profile_t *profile = listener->profile;
|
||||||
char *sql;
|
char *sql;
|
||||||
|
|
||||||
if ((sql = switch_mprintf(
|
|
||||||
"SELECT '%q', value, '%q', '%q', '%d' "
|
|
||||||
"FROM skinny_lines "
|
|
||||||
"WHERE device_name='%s' AND device_instance=%d "
|
|
||||||
"ORDER BY position",
|
|
||||||
profile->name, profile->domain, listener->device_name, listener->device_instance,
|
|
||||||
listener->device_name, listener->device_instance
|
|
||||||
))) {
|
|
||||||
skinny_execute_sql_callback(profile, profile->sql_mutex, sql, flush_listener_callback, NULL);
|
|
||||||
switch_safe_free(sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((sql = switch_mprintf(
|
if ((sql = switch_mprintf(
|
||||||
"DELETE FROM skinny_devices "
|
"DELETE FROM skinny_devices "
|
||||||
"WHERE name='%s' and instance=%d",
|
"WHERE name='%s' and instance=%d",
|
||||||
|
@ -1358,6 +1345,38 @@ static void flush_listener(listener_t *listener)
|
||||||
switch_safe_free(sql);
|
switch_safe_free(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((sql = switch_mprintf(
|
||||||
|
"DELETE FROM skinny_active_lines "
|
||||||
|
"WHERE device_name='%s' and device_instance=%d",
|
||||||
|
listener->device_name, listener->device_instance))) {
|
||||||
|
skinny_execute_sql(profile, sql, profile->sql_mutex);
|
||||||
|
switch_safe_free(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void flush_listener(listener_t *listener)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(!zstr(listener->device_name)) {
|
||||||
|
skinny_profile_t *profile = listener->profile;
|
||||||
|
char *sql;
|
||||||
|
|
||||||
|
if ((sql = switch_mprintf(
|
||||||
|
"SELECT '%q', value, '%q', '%q', '%d' "
|
||||||
|
"FROM skinny_lines "
|
||||||
|
"WHERE device_name='%s' AND device_instance=%d "
|
||||||
|
"ORDER BY position",
|
||||||
|
profile->name, profile->domain, listener->device_name, listener->device_instance,
|
||||||
|
listener->device_name, listener->device_instance
|
||||||
|
))) {
|
||||||
|
skinny_execute_sql_callback(profile, profile->sql_mutex, sql, flush_listener_callback, NULL);
|
||||||
|
switch_safe_free(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
skinny_clean_listener_from_db(listener);
|
||||||
|
|
||||||
strcpy(listener->device_name, "");
|
strcpy(listener->device_name, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,6 +271,7 @@ switch_bool_t skinny_execute_sql_callback(skinny_profile_t *profile,
|
||||||
uint8_t listener_is_ready(listener_t *listener);
|
uint8_t listener_is_ready(listener_t *listener);
|
||||||
switch_status_t kill_listener(listener_t *listener, void *pvt);
|
switch_status_t kill_listener(listener_t *listener, void *pvt);
|
||||||
switch_status_t keepalive_listener(listener_t *listener, void *pvt);
|
switch_status_t keepalive_listener(listener_t *listener, void *pvt);
|
||||||
|
void skinny_clean_listener_from_db(listener_t *listener);
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* CHANNEL FUNCTIONS */
|
/* CHANNEL FUNCTIONS */
|
||||||
|
|
|
@ -964,8 +964,8 @@ switch_status_t skinny_handle_register(listener_t *listener, skinny_message_t *r
|
||||||
|
|
||||||
if (!zstr(listener->device_name)) {
|
if (!zstr(listener->device_name)) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
||||||
"A device is already registred on this listener.\n");
|
"A device is already registered on this listener.\n");
|
||||||
send_register_reject(listener, "A device is already registred on this listener");
|
send_register_reject(listener, "A device is already registered on this listener");
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -993,6 +993,9 @@ switch_status_t skinny_handle_register(listener_t *listener, skinny_message_t *r
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* clean up all traces before adding to database */
|
||||||
|
skinny_clean_listener_from_db(listener);
|
||||||
|
|
||||||
if ((sql = switch_mprintf(
|
if ((sql = switch_mprintf(
|
||||||
"INSERT INTO skinny_devices "
|
"INSERT INTO skinny_devices "
|
||||||
"(name, user_id, instance, ip, type, max_streams, codec_string) "
|
"(name, user_id, instance, ip, type, max_streams, codec_string) "
|
||||||
|
@ -1951,6 +1954,9 @@ switch_status_t skinny_handle_unregister(listener_t *listener, skinny_message_t
|
||||||
/* Close socket */
|
/* Close socket */
|
||||||
switch_clear_flag_locked(listener, LFLAG_RUNNING);
|
switch_clear_flag_locked(listener, LFLAG_RUNNING);
|
||||||
|
|
||||||
|
/* Clear this device from database and any active lines/etc. */
|
||||||
|
skinny_clean_listener_from_db(listener);
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue