]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
MODAPP-264 prevent multiple bindings of the same event_hooks to make code simpler...
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 22 Apr 2009 15:02:32 +0000 (15:02 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 22 Apr 2009 15:02:32 +0000 (15:02 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13113 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_core_event_hook.h
src/mod/applications/mod_limit/mod_limit.c

index 20f7a1766db82f4485b173a98be340240f4c7ac8..6a590cae686264e43b206b6551f0d2d40eb6cbe7 100644 (file)
@@ -183,12 +183,12 @@ extern switch_io_event_hooks_t switch_core_session_get_event_hooks(switch_core_s
                assert(_NAME != NULL);                                                                                  \
                for (ptr = session->event_hooks._NAME; ptr && ptr->next; ptr = ptr->next) \
                        if (ptr->_NAME == _NAME) return SWITCH_STATUS_FALSE;            \
+               if (ptr && ptr->_NAME == _NAME) return SWITCH_STATUS_FALSE;             \
                if ((hook = switch_core_session_alloc(session, sizeof(*hook))) != 0) { \
                        hook->_NAME = _NAME ;                                                                           \
                        if (! session->event_hooks._NAME ) {                                            \
                                session->event_hooks._NAME = hook;                                              \
                        } else {                                                                                                        \
-                               for (ptr = session->event_hooks._NAME; ptr && ptr->next; ptr = ptr->next); \
                                ptr->next = hook;                                                                               \
                        }                                                                                                                       \
                        return SWITCH_STATUS_SUCCESS;                                                           \
index 3cab89dd93648cae5fedd77a9c19bf5c675b54c8..4e6b341a90b07547f69076e543252a1e95822ddb 100644 (file)
@@ -67,7 +67,6 @@ typedef struct  {
 } limit_hash_item_t;
 
 typedef struct {
-       uint8_t have_state_handler;
        switch_hash_t *hash;
        } limit_hash_private_t;
 
@@ -377,7 +376,7 @@ static switch_status_t hash_state_handler(switch_core_session_t *session)
                
                /* Remove handler */
                switch_core_event_hook_remove_state_change(session, hash_state_handler);
-               pvt->have_state_handler = 0;
+
                
                switch_mutex_unlock(globals.limit_hash_mutex);
        }
@@ -778,7 +777,6 @@ SWITCH_STANDARD_APP(limit_function)
        char buf[80] = "";
        callback_t cbt = { 0 };
        switch_channel_t *channel = switch_core_session_get_channel(session);
-       switch_bool_t new_channel = SWITCH_FALSE;
 
        if (!switch_strlen_zero(data)) {
                mydata = switch_core_session_strdup(session, data);
@@ -812,7 +810,6 @@ SWITCH_STANDARD_APP(limit_function)
        }
 
        
-       new_channel = !switch_channel_get_variable(channel, "limit_realm");
        switch_channel_set_variable(channel, "limit_realm", realm);
        switch_channel_set_variable(channel, "limit_id", id);
        switch_channel_set_variable(channel, "limit_max", argv[2]);
@@ -829,9 +826,9 @@ SWITCH_STANDARD_APP(limit_function)
                goto done;
        }
 
-       if (new_channel) {
-               switch_core_event_hook_add_state_change(session, db_state_handler);
-       }
+       switch_core_event_hook_add_state_change(session, db_state_handler);
+       switch_core_event_hook_add_state_change(session, db_state_handler);
+
        sql =
                switch_mprintf("insert into limit_data (hostname, realm, id, uuid) values('%q','%q','%q','%q');", globals.hostname, realm, id,
                                           switch_core_session_get_uuid(session));
@@ -1025,11 +1022,9 @@ SWITCH_STANDARD_APP(limit_hash_function)
                switch_channel_set_variable(channel, "limit_rate", srate);
                switch_channel_set_variable(channel, switch_core_session_sprintf(session, "limit_rate_%s", hashkey), srate);
        }
-       
-       if (!pvt->have_state_handler) {
-               switch_core_event_hook_add_state_change(session, hash_state_handler);
-               pvt->have_state_handler = 1;
-       }
+
+       switch_core_event_hook_add_state_change(session, hash_state_handler);
+
        
 end:   
        switch_mutex_unlock(globals.limit_hash_mutex);