mod_skinny: initial reg wasn't able to clean up due to missing device name, add new function to clean up given explicit device name, also add more logging
This commit is contained in:
parent
2eb010758e
commit
878c232b06
|
@ -1326,12 +1326,64 @@ static int flush_listener_callback(void *pArg, int argc, char **argv, char **col
|
|||
return 0;
|
||||
}
|
||||
|
||||
void skinny_clean_device_from_db(listener_t *listener, char *device_name)
|
||||
{
|
||||
if(!zstr(device_name)) {
|
||||
skinny_profile_t *profile = listener->profile;
|
||||
char *sql;
|
||||
|
||||
skinny_log_l(listener, SWITCH_LOG_DEBUG,
|
||||
"Clean device from DB with name '%s'\n",
|
||||
device_name);
|
||||
|
||||
if ((sql = switch_mprintf(
|
||||
"DELETE FROM skinny_devices "
|
||||
"WHERE name='%s'",
|
||||
device_name))) {
|
||||
skinny_execute_sql(profile, sql, profile->sql_mutex);
|
||||
switch_safe_free(sql);
|
||||
}
|
||||
|
||||
if ((sql = switch_mprintf(
|
||||
"DELETE FROM skinny_lines "
|
||||
"WHERE device_name='%s'",
|
||||
device_name))) {
|
||||
skinny_execute_sql(profile, sql, profile->sql_mutex);
|
||||
switch_safe_free(sql);
|
||||
}
|
||||
|
||||
if ((sql = switch_mprintf(
|
||||
"DELETE FROM skinny_buttons "
|
||||
"WHERE device_name='%s'",
|
||||
device_name))) {
|
||||
skinny_execute_sql(profile, sql, profile->sql_mutex);
|
||||
switch_safe_free(sql);
|
||||
}
|
||||
|
||||
if ((sql = switch_mprintf(
|
||||
"DELETE FROM skinny_active_lines "
|
||||
"WHERE device_name='%s'",
|
||||
device_name))) {
|
||||
skinny_execute_sql(profile, sql, profile->sql_mutex);
|
||||
switch_safe_free(sql);
|
||||
}
|
||||
|
||||
} else {
|
||||
skinny_log_l_msg(listener, SWITCH_LOG_DEBUG,
|
||||
"Clean device from DB, missing device name.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void skinny_clean_listener_from_db(listener_t *listener)
|
||||
{
|
||||
if(!zstr(listener->device_name)) {
|
||||
skinny_profile_t *profile = listener->profile;
|
||||
char *sql;
|
||||
|
||||
skinny_log_l(listener, SWITCH_LOG_DEBUG,
|
||||
"Clean listener from DB with name '%s' and instance '%d'\n",
|
||||
listener->device_name, listener->device_instance);
|
||||
|
||||
if ((sql = switch_mprintf(
|
||||
"DELETE FROM skinny_devices "
|
||||
"WHERE name='%s' and instance=%d",
|
||||
|
@ -1364,6 +1416,9 @@ void skinny_clean_listener_from_db(listener_t *listener)
|
|||
switch_safe_free(sql);
|
||||
}
|
||||
|
||||
} else {
|
||||
skinny_log_l_msg(listener, SWITCH_LOG_DEBUG,
|
||||
"Clean listener from DB, missing device name.\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -276,6 +276,7 @@ uint8_t listener_is_ready(listener_t *listener);
|
|||
switch_status_t kill_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);
|
||||
void skinny_clean_device_from_db(listener_t *listener, char *device_name);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* CHANNEL FUNCTIONS */
|
||||
|
|
|
@ -975,6 +975,9 @@ switch_status_t skinny_handle_register(listener_t *listener, skinny_message_t *r
|
|||
skinny_device_event(listener, ¶ms, SWITCH_EVENT_REQUEST_PARAMS, SWITCH_EVENT_SUBCLASS_ANY);
|
||||
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "action", "skinny-auth");
|
||||
|
||||
/* clean up all traces before adding to database */
|
||||
skinny_clean_device_from_db(listener, request->data.reg.device_name);
|
||||
|
||||
if (switch_xml_locate_user("id", request->data.reg.device_name, profile->domain, "", &xroot, &xdomain, &xuser, &xgroup, params) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Can't find device [%s@%s]\n"
|
||||
"You must define a domain called '%s' in your directory and add a user with id=\"%s\".\n"
|
||||
|
@ -984,6 +987,11 @@ switch_status_t skinny_handle_register(listener_t *listener, skinny_message_t *r
|
|||
goto end;
|
||||
}
|
||||
|
||||
/* we clean up device above, so this below block will never trigger. I don't
|
||||
know the full details of why there would be multiple listeners with
|
||||
the same device - maybe a VGC or similar? Not really high priority for
|
||||
support at the moment, but may need to revisit this later */
|
||||
|
||||
skinny_profile_find_listener_by_device_name_and_instance(listener->profile,
|
||||
request->data.reg.device_name, request->data.reg.instance, &listener2);
|
||||
if (listener2) {
|
||||
|
@ -995,9 +1003,6 @@ switch_status_t skinny_handle_register(listener_t *listener, skinny_message_t *r
|
|||
goto end;
|
||||
}
|
||||
|
||||
/* clean up all traces before adding to database */
|
||||
skinny_clean_listener_from_db(listener);
|
||||
|
||||
if ((sql = switch_mprintf(
|
||||
"INSERT INTO skinny_devices "
|
||||
"(name, user_id, instance, ip, type, max_streams, codec_string) "
|
||||
|
|
Loading…
Reference in New Issue