提交 878c232b authored 作者: Nathan Neulinger's avatar Nathan Neulinger

mod_skinny: initial reg wasn't able to clean up due to missing device name, add…

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
上级 2eb01075
...@@ -1326,12 +1326,64 @@ static int flush_listener_callback(void *pArg, int argc, char **argv, char **col ...@@ -1326,12 +1326,64 @@ static int flush_listener_callback(void *pArg, int argc, char **argv, char **col
return 0; 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) 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;
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( if ((sql = switch_mprintf(
"DELETE FROM skinny_devices " "DELETE FROM skinny_devices "
"WHERE name='%s' and instance=%d", "WHERE name='%s' and instance=%d",
...@@ -1364,6 +1416,9 @@ void skinny_clean_listener_from_db(listener_t *listener) ...@@ -1364,6 +1416,9 @@ void skinny_clean_listener_from_db(listener_t *listener)
switch_safe_free(sql); 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); ...@@ -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 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); void skinny_clean_listener_from_db(listener_t *listener);
void skinny_clean_device_from_db(listener_t *listener, char *device_name);
/*****************************************************************************/ /*****************************************************************************/
/* CHANNEL FUNCTIONS */ /* CHANNEL FUNCTIONS */
......
...@@ -975,6 +975,9 @@ switch_status_t skinny_handle_register(listener_t *listener, skinny_message_t *r ...@@ -975,6 +975,9 @@ switch_status_t skinny_handle_register(listener_t *listener, skinny_message_t *r
skinny_device_event(listener, &params, SWITCH_EVENT_REQUEST_PARAMS, SWITCH_EVENT_SUBCLASS_ANY); skinny_device_event(listener, &params, SWITCH_EVENT_REQUEST_PARAMS, SWITCH_EVENT_SUBCLASS_ANY);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "action", "skinny-auth"); 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) { 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" 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" "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 ...@@ -984,6 +987,11 @@ switch_status_t skinny_handle_register(listener_t *listener, skinny_message_t *r
goto end; 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, skinny_profile_find_listener_by_device_name_and_instance(listener->profile,
request->data.reg.device_name, request->data.reg.instance, &listener2); request->data.reg.device_name, request->data.reg.instance, &listener2);
if (listener2) { if (listener2) {
...@@ -995,9 +1003,6 @@ switch_status_t skinny_handle_register(listener_t *listener, skinny_message_t *r ...@@ -995,9 +1003,6 @@ 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) "
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论