]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
mod_skinny: initial reg wasn't able to clean up due to missing device name, add new...
authorNathan Neulinger <nneul@neulinger.org>
Tue, 30 Jul 2013 19:35:39 +0000 (14:35 -0500)
committerNathan Neulinger <nneul@neulinger.org>
Tue, 30 Jul 2013 19:35:39 +0000 (14:35 -0500)
src/mod/endpoints/mod_skinny/mod_skinny.c
src/mod/endpoints/mod_skinny/mod_skinny.h
src/mod/endpoints/mod_skinny/skinny_server.c

index 407aa6549956dea137d8df0f58e940ca19e9af53..72cc82f9fadebd1d4a45de12f375caca89c45823 100644 (file)
@@ -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");
        }
 }
 
index 76ca8017ac7f86980e84b9b259873029ec825d8a..d8ed1b03bf3c5dcdc7f902d7affca00ac8bcf8a5 100644 (file)
@@ -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 */
index feac761cc37c63b3caec3b4114f14a769ec8aa55..95d486d3e0de0fd6ced62b758b95d39955646210 100644 (file)
@@ -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);
        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) "