FS-2731 significantly reworked version of Emmanuel's patch to allow subscribing and notifying for the as-feature-event events. we still need a module to handle the FS events for this automatically... coming soon to a repository near you

This commit is contained in:
Raymond Chandler committed 2013-08-23 15:54:49 -04:00
1 parent a524fadf17
commit 863e6cfa3f
8 files changed
+734 -414

No files matched your search

+71 -68
View File
@@ -1,4 +1,4 @@
/*
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2012, Anthony Minessale II <anthm@freeswitch.org>
*
@@ -22,11 +22,12 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
*
* Anthony Minessale II <anthm@freeswitch.org>
* Michael Jerris <mike@jerris.com>
* Paul D. Tinsley <pdt at jackhammer.org>
* William King <william.king@quentustech.com>
* Raymond Chandler <intralanman@freeswitch.org>
*
* switch_event.c -- Event System
*
@@ -153,6 +154,8 @@ static char *EVENT_NAMES[] = {
"MESSAGE",
"PRESENCE_IN",
"NOTIFY_IN",
"PHONE_FEATURE",
"PHONE_FEATURE_SUBSCRIBE",
"PRESENCE_OUT",
"PRESENCE_PROBE",
"MESSAGE_WAITING",
@@ -263,7 +266,7 @@ static void *SWITCH_THREAD_FUNC switch_event_dispatch_thread(switch_thread_t *th
EVENT_DISPATCH_QUEUE_RUNNING[my_id] = 1;
switch_mutex_unlock(EVENT_QUEUE_MUTEX);
for (;;) {
void *pop = NULL;
@@ -308,11 +311,11 @@ static switch_status_t switch_event_queue_dispatch_event(switch_event_t **eventp
if (!SYSTEM_RUNNING) {
return SWITCH_STATUS_FALSE;
}
while (event) {
int launch = 0;
switch_mutex_lock(EVENT_QUEUE_MUTEX);
switch_mutex_lock(EVENT_QUEUE_MUTEX);
if (!PENDING && switch_queue_size(EVENT_DISPATCH_QUEUE) > (unsigned int)(DISPATCH_QUEUE_LEN * DISPATCH_THREAD_COUNT)) {
if (SOFT_MAX_DISPATCH + 1 > MAX_DISPATCH) {
@@ -322,7 +325,7 @@ static switch_status_t switch_event_queue_dispatch_event(switch_event_t **eventp
}
switch_mutex_unlock(EVENT_QUEUE_MUTEX);
if (launch) {
if (SOFT_MAX_DISPATCH + 1 < MAX_DISPATCH) {
switch_event_launch_dispatch_threads(SOFT_MAX_DISPATCH + 1);
@@ -336,9 +339,9 @@ static switch_status_t switch_event_queue_dispatch_event(switch_event_t **eventp
*eventp = NULL;
switch_queue_push(EVENT_DISPATCH_QUEUE, event);
event = NULL;
}
return SWITCH_STATUS_SUCCESS;
}
@@ -579,12 +582,12 @@ SWITCH_DECLARE(switch_status_t) switch_event_init(switch_memory_pool_t *pool)
{
//switch_threadattr_t *thd_attr;
/*
/*
This statement doesn't do anything commenting it out for now.
switch_assert(switch_arraylen(EVENT_NAMES) == SWITCH_EVENT_ALL + 1);
*/
/* don't need any more dispatch threads than we have CPU's*/
MAX_DISPATCH = (switch_core_cpu_count() / 2) + 1;
if (MAX_DISPATCH < 2) {
@@ -751,7 +754,7 @@ SWITCH_DECLARE(char *) switch_event_get_header_idx(switch_event_t *event, const
}
}
return hp->value;
return hp->value;
} else if (!strcmp(header_name, "_body")) {
return event->body;
}
@@ -802,7 +805,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_del_header_val(switch_event_t *even
}
FREE(hp->value);
memset(hp, 0, sizeof(*hp));
#ifdef SWITCH_EVENT_RECYCLE
if (switch_queue_trypush(EVENT_HEADER_RECYCLE_QUEUE, hp) != SWITCH_STATUS_SUCCESS) {
@@ -834,7 +837,7 @@ static switch_event_header_t *new_header(const char *header_name)
switch_assert(header);
#ifdef SWITCH_EVENT_RECYCLE
}
#endif
#endif
memset(header, 0, sizeof(*header));
header->name = DUP(header_name);
@@ -870,15 +873,15 @@ SWITCH_DECLARE(int) switch_event_add_array(switch_event_t *event, const char *va
}
data = strdup(val + 7);
len = (sizeof(char *) * max) + 1;
switch_assert(len);
array = malloc(len);
memset(array, 0, len);
switch_separate_string_string(data, "|:", array, max);
for(i = 0; i < max; i++) {
switch_event_add_header_string(event, SWITCH_STACK_PUSH, var, array[i]);
}
@@ -914,20 +917,20 @@ static switch_status_t switch_event_base_add_header(switch_event_t *event, switc
}
if (index_ptr || (stack & SWITCH_STACK_PUSH) || (stack & SWITCH_STACK_UNSHIFT)) {
if (!(header = switch_event_get_header_ptr(event, header_name)) && index_ptr) {
header = new_header(header_name);
if (switch_test_flag(event, EF_UNIQ_HEADERS)) {
switch_event_del_header(event, header_name);
}
fly++;
}
if (header || (header = switch_event_get_header_ptr(event, header_name))) {
if (index_ptr) {
if (index > -1 && index <= 4000) {
if (index < header->idx) {
@@ -936,7 +939,7 @@ static switch_status_t switch_event_base_add_header(switch_event_t *event, switc
} else {
int i;
char **m;
m = realloc(header->array, sizeof(char *) * (index + 1));
switch_assert(m);
header->array = m;
@@ -986,7 +989,7 @@ static switch_status_t switch_event_base_add_header(switch_event_t *event, switc
header = new_header(header_name);
}
if ((stack & SWITCH_STACK_PUSH) || (stack & SWITCH_STACK_UNSHIFT)) {
char **m = NULL;
switch_size_t len = 0;
@@ -1004,7 +1007,7 @@ static switch_status_t switch_event_base_add_header(switch_event_t *event, switc
}
i = header->idx + 1;
m = realloc(header->array, sizeof(char *) * i);
m = realloc(header->array, sizeof(char *) * i);
switch_assert(m);
if ((stack & SWITCH_STACK_PUSH)) {
@@ -1016,7 +1019,7 @@ static switch_status_t switch_event_base_add_header(switch_event_t *event, switc
m[0] = data;
}
header->idx++;
header->idx++;
header->array = m;
redraw:
@@ -1118,7 +1121,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_set_body(switch_event_t *event, con
if (body) {
event->body = DUP(body);
}
return SWITCH_STATUS_SUCCESS;
}
@@ -1170,7 +1173,7 @@ SWITCH_DECLARE(void) switch_event_destroy(switch_event_t **event)
FREE(this->name);
FREE(this->value);
#ifdef SWITCH_EVENT_RECYCLE
if (switch_queue_trypush(EVENT_HEADER_RECYCLE_QUEUE, this) != SWITCH_STATUS_SUCCESS) {
@@ -1200,13 +1203,13 @@ SWITCH_DECLARE(void) switch_event_destroy(switch_event_t **event)
SWITCH_DECLARE(void) switch_event_merge(switch_event_t *event, switch_event_t *tomerge)
{
switch_event_header_t *hp;
switch_assert(tomerge && event);
for (hp = tomerge->headers; hp; hp = hp->next) {
if (hp->idx) {
int i;
for(i = 0; i < hp->idx; i++) {
switch_event_add_header_string(event, SWITCH_STACK_PUSH, hp->name, hp->array[i]);
}
@@ -1232,7 +1235,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_dup(switch_event_t **event, switch_
if (todup->subclass_name && !strcmp(hp->name, "Event-Subclass")) {
continue;
}
if (hp->idx) {
int i;
for (i = 0; i < hp->idx; i++) {
@@ -1270,11 +1273,11 @@ SWITCH_DECLARE(switch_status_t) switch_event_dup_reply(switch_event_t **event, s
for (hp = todup->headers; hp; hp = hp->next) {
char *name = hp->name, *value = hp->value;
if (todup->subclass_name && !strcmp(hp->name, "Event-Subclass")) {
continue;
}
if (!strncasecmp(hp->name, "from_", 5)) {
p = hp->name + 5;
switch_snprintf(hname, sizeof(hname), "to_%s", p);
@@ -1288,7 +1291,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_dup_reply(switch_event_t **event, s
} else if (!strcasecmp(name, "from")) {
name = "to";
}
if (hp->idx) {
int i;
for (i = 0; i < hp->idx; i++) {
@@ -1379,13 +1382,13 @@ SWITCH_DECLARE(switch_status_t) switch_event_binary_serialize(switch_event_t *ev
tn = tpl_map(SWITCH_SERIALIZED_EVENT_MAP, &e, &sh);
tpl_pack(tn, 0);
for (eh = event->headers; eh; eh = eh->next) {
if (eh->idx) continue; // no arrays yet
sh.name = eh->name;
sh.value = eh->value;
tpl_pack(tn, 1);
}
@@ -1427,7 +1430,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, ch
/*
* grab enough memory to store 3x the string (url encode takes one char and turns it into %XX)
* so we could end up with a string that is 3 times the originals length, unlikely but rather
* be safe than destroy the string, also add one for the null. And try to be smart about using
* be safe than destroy the string, also add one for the null. And try to be smart about using
* the memory, allocate and only reallocate if we need more. This avoids an alloc, free CPU
* destroying loop.
*/
@@ -1522,11 +1525,11 @@ SWITCH_DECLARE(switch_status_t) switch_event_create_array_pair(switch_event_t **
char *name, *val;
switch_event_create(event, SWITCH_EVENT_CLONE);
for (r = 0; r < len; r++) {
val = switch_str_nil(vals[r]);
name = names[r];
if (zstr(name)) {
name = "Unknown";
}
@@ -1535,7 +1538,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_create_array_pair(switch_event_t **
}
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) switch_event_create_brackets(char *data, char a, char b, char c, switch_event_t **event, char **new_data, switch_bool_t dup)
@@ -1555,17 +1558,17 @@ SWITCH_DECLARE(switch_status_t) switch_event_create_brackets(char *data, char a,
}
end = switch_find_end_paren(vdata, a, b);
check_a = end;
while (check_a && (check_b = switch_strchr_strict(check_a, a, " "))) {
if ((check_b = switch_find_end_paren(check_b, a, b))) {
check_a = check_b;
}
}
if (check_a) end = check_a;
if (end) {
next = end;
vdata++;
@@ -1576,12 +1579,12 @@ SWITCH_DECLARE(switch_status_t) switch_event_create_brackets(char *data, char a,
}
return SWITCH_STATUS_FALSE;
}
if (!e) {
switch_event_create_plain(&e, SWITCH_EVENT_CHANNEL_DATA);
}
for (;;) {
if (next) {
char *pnext;
@@ -1595,7 +1598,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_create_brackets(char *data, char a,
vnext = switch_find_end_paren(next, a, b);
next = NULL;
}
if (vdata) {
if (*vdata == '^' && *(vdata + 1) == '^') {
@@ -1603,7 +1606,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_create_brackets(char *data, char a,
c = *vdata++;
}
}
if ((var_count = switch_separate_string(vdata, c, var_array, (sizeof(var_array) / sizeof(var_array[0]))))) {
int x = 0;
for (x = 0; x < var_count; x++) {
@@ -1635,7 +1638,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_create_brackets(char *data, char a,
} else {
*new_data = end;
}
return SWITCH_STATUS_SUCCESS;
}
@@ -1687,7 +1690,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_create_json(switch_event_t **event,
}
}
}
cJSON_Delete(cj);
*event = new_event;
return SWITCH_STATUS_SUCCESS;
@@ -1699,7 +1702,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_serialize_json(switch_event_t *even
cJSON *cj;
*str = NULL;
cj = cJSON_CreateObject();
for (hp = event->headers; hp; hp = hp->next) {
@@ -1710,9 +1713,9 @@ SWITCH_DECLARE(switch_status_t) switch_event_serialize_json(switch_event_t *even
for(i = 0; i < hp->idx; i++) {
cJSON_AddItemToArray(a, cJSON_CreateString(hp->array[i]));
}
cJSON_AddItemToObject(cj, hp->name, a);
} else {
cJSON_AddItemToObject(cj, hp->name, cJSON_CreateString(hp->value));
}
@@ -1730,7 +1733,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_serialize_json(switch_event_t *even
*str = cJSON_Print(cj);
cJSON_Delete(cj);
return SWITCH_STATUS_SUCCESS;
}
@@ -1901,7 +1904,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_bind_removable(const char *id, swit
if (node) {
*node = NULL;
}
if (subclass_name) {
if (!(subclass = switch_core_hash_find(CUSTOM_HASH, subclass_name))) {
switch_event_reserve_subclass_detailed(id, subclass_name);
@@ -2066,9 +2069,9 @@ char *dp;\
olen += (len + l + block);\
cpos = c - data;\
if ((dp = realloc(data, olen))) {\
data = dp;\
c = data + cpos;\
memset(c, 0, olen - cpos);\
data = dp;\
c = data + cpos;\
memset(c, 0, olen - cpos);\
}} \
SWITCH_DECLARE(char *) switch_event_expand_headers_check(switch_event_t *event, const char *in, switch_event_t *var_list, switch_event_t *api_list, uint32_t recur)
@@ -2223,7 +2226,7 @@ SWITCH_DECLARE(char *) switch_event_expand_headers_check(switch_event_t *event,
int ooffset = 0;
char *ptr;
int idx = -1;
if ((expanded = switch_event_expand_headers_check(event, (char *) vname, var_list, api_list, recur+1)) == vname) {
expanded = NULL;
} else {
@@ -2266,7 +2269,7 @@ SWITCH_DECLARE(char *) switch_event_expand_headers_check(switch_event_t *event,
switch_assert(cloned_sub_val);
sub_val = cloned_sub_val;
}
if (offset >= 0) {
sub_val += offset;
} else if ((size_t) abs(offset) <= strlen(sub_val)) {
@@ -2278,7 +2281,7 @@ SWITCH_DECLARE(char *) switch_event_expand_headers_check(switch_event_t *event,
*ptr = '\0';
}
}
switch_safe_free(expanded);
} else {
@@ -2477,7 +2480,7 @@ SWITCH_DECLARE(int) switch_event_check_permission_list(switch_event_t *list, con
r = default_allow;
}
return r;
return r;
}
SWITCH_DECLARE(void) switch_event_add_presence_data_cols(switch_channel_t *channel, switch_event_t *event, const char *prefix)
@@ -2485,7 +2488,7 @@ SWITCH_DECLARE(void) switch_event_add_presence_data_cols(switch_channel_t *chann
const char *data;
if (!prefix) prefix = "";
if ((data = switch_channel_get_variable(channel, "presence_data_cols"))) {
char *cols[128] = { 0 };
char header_name[128] = "";
@@ -2493,17 +2496,17 @@ SWITCH_DECLARE(void) switch_event_add_presence_data_cols(switch_channel_t *chann
char *data_copy = NULL;
data_copy = strdup(data);
col_count = switch_split(data_copy, ':', cols);
for (i = 0; i < col_count; i++) {
const char *val = NULL;
switch_snprintf(header_name, sizeof(header_name), "%s%s", prefix, cols[i]);
val = switch_channel_get_variable(channel, cols[i]);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header_name, val);
}
switch_safe_free(data_copy);
}