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",
switch_safe_free(sql);
}
+ } else {
+ skinny_log_l_msg(listener, SWITCH_LOG_DEBUG,
+ "Clean listener from DB, missing device name.\n");
}
}
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"
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) {
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) "