return 0;
}
-static void flush_listener(listener_t *listener)
+void skinny_clean_listener_from_db(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);
- }
-
if ((sql = switch_mprintf(
"DELETE FROM skinny_devices "
"WHERE name='%s' and instance=%d",
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, "");
}
}
if (!zstr(listener->device_name)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
- "A device is already registred on this listener.\n");
- send_register_reject(listener, "A device is already registred on this listener");
+ "A device is already registered on this listener.\n");
+ send_register_reject(listener, "A device is already registered on this listener");
return SWITCH_STATUS_FALSE;
}
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) "
/* Close socket */
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;
}