]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add switch_core_session_findall_matching_var func to core to get a list of uuid with...
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 11 Oct 2012 14:57:02 +0000 (09:57 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 11 Oct 2012 14:57:02 +0000 (09:57 -0500)
src/include/switch_core.h
src/switch_core_session.c

index 3577bb4f471fe6c1c599f1597f9002c3dba20f65..b533a3e6da0d90d48359f0cd0118ca6cbbd5e611 100644 (file)
@@ -825,6 +825,8 @@ SWITCH_DECLARE(void) switch_core_session_hupall(_In_ switch_call_cause_t cause);
   \param cause the hangup cause to apply to the hungup channels
 */
 SWITCH_DECLARE(void) switch_core_session_hupall_matching_var(_In_ const char *var_name, _In_ const char *var_val, _In_ switch_call_cause_t cause);
+SWITCH_DECLARE(switch_console_callback_match_t *) switch_core_session_findall_matching_var(const char *var_name, const char *var_val);
+
 /*! 
   \brief Hangup all sessions that belong to an endpoint
   \param endpoint_interface The endpoint interface 
index e50c5f008e7f4ac0ae50ae5bc332d0becc8eadba..ab52bb89ddee622bcaef69d8e27b6c4558cffa9a 100644 (file)
@@ -238,6 +238,54 @@ SWITCH_DECLARE(void) switch_core_session_hupall_matching_var(const char *var_nam
 
 }
 
+
+SWITCH_DECLARE(switch_console_callback_match_t *) switch_core_session_findall_matching_var(const char *var_name, const char *var_val)
+{
+       switch_hash_index_t *hi;
+       void *val;
+       switch_core_session_t *session;
+       switch_memory_pool_t *pool;
+       struct str_node *head = NULL, *np;
+       switch_console_callback_match_t *my_matches = NULL;
+
+       switch_core_new_memory_pool(&pool);
+
+       if (!var_val)
+               return NULL;
+
+       switch_mutex_lock(runtime.session_hash_mutex);
+       for (hi = switch_hash_first(NULL, session_manager.session_table); hi; hi = switch_hash_next(hi)) {
+               switch_hash_this(hi, NULL, NULL, &val);
+               if (val) {
+                       session = (switch_core_session_t *) val;
+                       if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
+                               np = switch_core_alloc(pool, sizeof(*np));
+                               np->str = switch_core_strdup(pool, session->uuid_str);
+                               np->next = head;
+                               head = np;
+                               switch_core_session_rwunlock(session);
+                       }
+               }
+       }
+       switch_mutex_unlock(runtime.session_hash_mutex);
+
+       for(np = head; np; np = np->next) {
+               if ((session = switch_core_session_locate(np->str))) {
+                       const char *this_val;
+                       if (switch_channel_up_nosig(session->channel) &&
+                               (this_val = switch_channel_get_variable_dup(session->channel, var_name, SWITCH_FALSE, -1)) && (!strcmp(this_val, var_val))) {                   
+                               switch_console_push_match(&my_matches, (const char *) np->str);
+                       }
+                       switch_core_session_rwunlock(session);
+               }
+       }
+
+       switch_core_destroy_memory_pool(&pool);
+
+
+       return my_matches;
+}
+
 SWITCH_DECLARE(void) switch_core_session_hupall_endpoint(const switch_endpoint_interface_t *endpoint_interface, switch_call_cause_t cause)
 {
        switch_hash_index_t *hi;