switch_event_channel_id_t ID;
switch_thread_rwlock_t *rwlock;
switch_hash_t *hash;
+ switch_hash_t *perm_hash;
switch_hash_t *lahash;
switch_mutex_t *lamutex;
} event_channel_manager;
}
switch_core_hash_destroy(&event_channel_manager.lahash);
+ switch_core_hash_destroy(&event_channel_manager.hash);
+ switch_core_hash_destroy(&event_channel_manager.perm_hash);
switch_core_hash_destroy(&CUSTOM_HASH);
switch_core_memory_reclaim_events();
switch_thread_rwlock_create(&event_channel_manager.rwlock, RUNTIME_POOL);
switch_core_hash_init(&event_channel_manager.hash, RUNTIME_POOL);
+ switch_core_hash_init(&event_channel_manager.perm_hash, RUNTIME_POOL);
event_channel_manager.ID = 1;
switch_mutex_lock(EVENT_QUEUE_MUTEX);
static void unsub_all_switch_event_channel(void)
{
switch_hash_index_t *hi;
+ const void *var;
void *val;
switch_event_channel_sub_node_head_t *head;
switch_thread_rwlock_wrlock(event_channel_manager.rwlock);
- top:
- head = NULL;
- for (hi = switch_hash_first(NULL, event_channel_manager.hash); hi; hi = switch_hash_next(hi)) {
+ while ((hi = switch_hash_first(NULL, event_channel_manager.perm_hash))) {
+ switch_event_t *vals = NULL;
+ switch_hash_this(hi, &var, NULL, &val);
+ vals = (switch_event_t *) val;
+ switch_core_hash_delete(event_channel_manager.perm_hash, var);
+ switch_event_destroy(&vals);
+ }
+
+ while ((hi = switch_hash_first(NULL, event_channel_manager.hash))) {
switch_hash_this(hi, NULL, NULL, &val);
head = (switch_event_channel_sub_node_head_t *) val;
switch_event_channel_unsub_head(NULL, head);
switch_core_hash_delete(event_channel_manager.hash, head->event_channel);
free(head->event_channel);
free(head);
- goto top;
}
switch_thread_rwlock_unlock(event_channel_manager.rwlock);
return status;
}
+SWITCH_DECLARE(switch_bool_t) switch_event_channel_permission_verify(const char *cookie, const char *event_channel)
+{
+ switch_event_t *vals;
+ switch_bool_t r = SWITCH_FALSE;
+
+ switch_thread_rwlock_rdlock(event_channel_manager.rwlock);
+ if ((vals = switch_core_hash_find(event_channel_manager.perm_hash, cookie))) {
+ r = switch_true(switch_event_get_header(vals, event_channel));
+ }
+ switch_thread_rwlock_unlock(event_channel_manager.rwlock);
+
+ return r;
+}
+
+SWITCH_DECLARE(void) switch_event_channel_permission_modify(const char *cookie, const char *event_channel, switch_bool_t set)
+{
+ switch_event_t *vals;
+
+ switch_thread_rwlock_wrlock(event_channel_manager.rwlock);
+ if (!(vals = switch_core_hash_find(event_channel_manager.perm_hash, cookie))) {
+ if (!set) goto end;
+
+ switch_event_create_plain(&vals, SWITCH_EVENT_CHANNEL_DATA);
+ switch_core_hash_insert(event_channel_manager.perm_hash, cookie, vals);
+ }
+
+ if (set) {
+ switch_event_add_header_string(vals, SWITCH_STACK_BOTTOM, event_channel, "true");
+ } else {
+ switch_event_del_header(vals, event_channel);
+ }
+
+
+ end:
+
+ switch_thread_rwlock_unlock(event_channel_manager.rwlock);
+}
+
+SWITCH_DECLARE(void) switch_event_channel_permission_clear(const char *cookie)
+{
+ switch_event_t *vals;
+
+ switch_thread_rwlock_wrlock(event_channel_manager.rwlock);
+ if ((vals = switch_core_hash_find(event_channel_manager.perm_hash, cookie))) {
+ switch_core_hash_delete(event_channel_manager.perm_hash, cookie);
+ switch_event_destroy(&vals);
+ }
+ switch_thread_rwlock_unlock(event_channel_manager.rwlock);
+}
+
+
typedef struct alias_node_s {
char *event_channel;
char *name;
+ char *key;
struct alias_node_s *next;
} alias_node_t;
{
switch_live_array_t *la = *live_arrayP;
switch_memory_pool_t *pool;
+ alias_node_t *np;
*live_arrayP = NULL;
switch_mutex_lock(event_channel_manager.lamutex);
switch_core_hash_delete(event_channel_manager.lahash, la->key);
+ for (np = la->aliases; np; np = np->next) {
+ switch_core_hash_delete(event_channel_manager.lahash, np->key);
+ }
switch_mutex_unlock(event_channel_manager.lamutex);
switch_core_destroy_memory_pool(&pool);
SWITCH_DECLARE(switch_bool_t) switch_live_array_clear_alias(switch_live_array_t *la, const char *event_channel, const char *name)
{
- alias_node_t *np, *last = NULL;
+ alias_node_t *np, *last = NULL, *del = NULL;
switch_bool_t r = SWITCH_FALSE;
switch_mutex_lock(la->mutex);
for (np = la->aliases; np; np = np->next) {
if (!strcmp(np->event_channel, event_channel) && !strcmp(np->name, name)) {
r = SWITCH_TRUE;
+ del = np;
if (last) {
last->next = np->next;
}
switch_mutex_unlock(la->mutex);
+ if (r) {
+ switch_mutex_lock(event_channel_manager.lamutex);
+ switch_core_hash_delete(event_channel_manager.lahash, del->key);
+ switch_mutex_unlock(event_channel_manager.lamutex);
+ }
+
+
return r;
}
node = switch_core_alloc(la->pool, sizeof(*node));
node->event_channel = switch_core_strdup(la->pool, event_channel);
node->name = switch_core_strdup(la->pool, name);
+ node->key = switch_core_sprintf(la->pool, "%s.%s", event_channel, name);
+
if (np) {
np->next = node;
} else {
switch_mutex_unlock(la->mutex);
+ if (!exist) {
+ switch_mutex_lock(event_channel_manager.lamutex);
+ switch_core_hash_insert(event_channel_manager.lahash, node->key, la);
+ switch_mutex_unlock(event_channel_manager.lamutex);
+ }
+
+
return !exist;
}
if ((context = cJSON_GetObjectCstr(jla, "context")) && (name = cJSON_GetObjectCstr(jla, "name"))) {
const char *command = cJSON_GetObjectCstr(jla, "command");
const char *sessid = cJSON_GetObjectCstr(json, "sessid");
-
+
if (command) {
switch_live_array_create(context, name, channel_id, &la);