44 #define DISPATCH_QUEUE_LEN 10000 82 #define MAX_DISPATCH_VAL 64 106 #ifdef SWITCH_EVENT_RECYCLE 115 size_t len = strlen(s) + 1;
116 void *
new = malloc(len);
119 return (
char *) memcpy(
new, s, len);
123 #define ALLOC(size) malloc(size) 126 #define DUP(str) my_dup(str) 129 #define FREE(ptr) switch_safe_free(ptr) 146 "CHANNEL_HANGUP_COMPLETE",
148 "CHANNEL_EXECUTE_COMPLETE",
154 "CHANNEL_PROGRESS_MEDIA",
158 "CHANNEL_APPLICATION",
197 "PHONE_FEATURE_SUBSCRIBE",
205 "CLIENT_DISCONNECTED",
206 "SERVER_DISCONNECTED",
222 "CONFERENCE_DATA_QUERY",
229 "SHUTDOWN_REQUESTED",
251 match = !strcmp(node->
subclass_name + 5, file_header) ? 1 : 0;
256 match = !strcmp(node->
subclass_name + 5, func_header) ? 1 : 0;
285 td = malloc(
sizeof(*td));
314 if ( my_id >= MAX_DISPATCH_VAL ) {
408 for (node = EVENT_NODES[e]; node; node = node->
next) {
410 (*event)->bind_user_data = node->
user_data;
465 if (!strcmp(owner, subclass->
owner)) {
497 if (subclass->
bind) {
507 subclass->
name =
DUP(subclass_name);
512 free(subclass->
owner);
513 free(subclass->
name);
526 #ifdef SWITCH_EVENT_RECYCLE 568 if (EVENT_CHANNEL_DISPATCH_QUEUE) {
636 if (!EVENT_DISPATCH_QUEUE) {
639 if (!EVENT_DISPATCH_QUEUE) {
657 uint32_t sanity = 200;
733 #ifdef SWITCH_EVENT_RECYCLE 750 #ifdef SWITCH_EVENT_RECYCLE 759 #ifdef SWITCH_EVENT_RECYCLE 766 #ifdef SWITCH_EVENT_RECYCLE 782 (*event)->subclass_name =
DUP(subclass_name);
791 event->priority = priority;
800 unsigned long hash = 0;
812 if ((!hp->
hash || hash == hp->
hash) && !strcasecmp(hp->
name, header_name)) {
814 hp->
name =
DUP(new_header_name);
829 unsigned long hash = 0;
839 if ((!hp->
hash || hash == hp->
hash) && !strcasecmp(hp->
name, header_name)) {
853 return hp->
array[idx];
860 }
else if (!strcmp(header_name,
"_body")) {
869 return (event ? event->
body : NULL);
878 unsigned long hash = 0;
889 if ((!hp->
hash || hash == hp->
hash) && !strcasecmp(header_name, hp->
name) && (
zstr(val) || !strcmp(hp->
value, val))) {
893 event->headers = hp->
next;
896 event->last_header = lp;
912 #ifdef SWITCH_EVENT_RECYCLE 918 header =
ALLOC(
sizeof(*header));
920 #ifdef SWITCH_EVENT_RECYCLE 924 memset(header, 0,
sizeof(*header));
925 header->
name =
DUP(header_name);
936 if ((*header)->idx) {
937 if (!(*header)->array) {
942 for (i = 0; i < (*header)->idx; i++) {
943 FREE((*header)->array[i]);
945 FREE((*header)->array);
949 FREE((*header)->name);
950 FREE((*header)->value);
952 #ifdef SWITCH_EVENT_RECYCLE 971 if (strlen(val) < 8) {
979 while((p = strstr(p,
"|:"))) {
984 data = strdup(val + 7);
986 len = (
sizeof(
char *) * max) + 1;
995 for(i = 0; i < max; i++) {
1009 int exists = 0, fly = 0;
1012 char *real_header_name = NULL;
1015 if (!strcmp(header_name,
"_body")) {
1019 if ((index_ptr = strchr(header_name,
'['))) {
1021 index = atoi(index_ptr);
1022 real_header_name =
DUP(header_name);
1023 if ((index_ptr = strchr(real_header_name,
'['))) {
1024 *index_ptr++ =
'\0';
1026 header_name = real_header_name;
1034 tmp_header = header =
new_header(header_name);
1046 if (index > -1 && index <= 4000) {
1047 if (index < header->idx) {
1054 m = realloc(header->
array,
sizeof(
char *) * (index + 1));
1057 for (i = header->
idx; i < index; i++) {
1061 header->
idx = index + 1;
1069 }
else if (tmp_header) {
1076 if ((stack & SWITCH_STACK_PUSH) || (stack & SWITCH_STACK_UNSHIFT)) {
1099 if (!strncmp(data,
"ARRAY::", 7)) {
1109 if ((stack & SWITCH_STACK_PUSH) || (stack & SWITCH_STACK_UNSHIFT)) {
1115 if (header->
value && !header->
idx) {
1116 m = malloc(
sizeof(
char *));
1118 m[0] = header->
value;
1119 header->
value = NULL;
1125 i = header->
idx + 1;
1126 m = realloc(header->
array,
sizeof(
char *) * i);
1129 if ((stack & SWITCH_STACK_PUSH)) {
1130 m[header->
idx] = data;
1131 }
else if ((stack & SWITCH_STACK_UNSHIFT)) {
1132 for (j = header->
idx; j > 0; j--) {
1143 for(j = 0; j < header->
idx; j++) {
1145 if (!header->
array[j]) {
1148 len += strlen(header->
array[j]);
1153 hv = realloc(header->
value, len);
1157 if (header->
idx > 1) {
1160 *header->
value =
'\0';
1163 hv += strlen(header->
value);
1164 for(j = 0; j < header->
idx; j++) {
1166 memcpy(hv,
"|:", 2);
1169 if (!header->
array[j]) {
1172 memcpy(hv, header->
array[j], strlen(header->
array[j]));
1173 hv += strlen(header->
array[j]);
1180 header->
value = data;
1187 header->
next =
event->headers;
1188 event->headers = header;
1190 event->last_header = header;
1194 event->last_header->
next = header;
1196 event->headers = header;
1197 header->
next = NULL;
1199 event->last_header = header;
1229 if (!event || !subclass_name)
1233 event->subclass_name =
DUP(subclass_name);
1260 event->body =
DUP(body);
1302 #ifdef SWITCH_EVENT_RECYCLE 1325 for(i = 0; i < hp->
idx; i++) {
1342 (*event)->event_id = todup->
event_id;
1345 (*event)->flags = todup->
flags;
1353 for (i = 0; i < hp->
idx; i++) {
1362 (*event)->body =
DUP(todup->
body);
1365 (*event)->key = todup->
key;
1374 char hname[1024] =
"";
1381 (*event)->event_id = todup->
event_id;
1384 (*event)->flags = todup->
flags;
1393 if (!strncasecmp(hp->
name,
"from_", 5)) {
1397 }
else if (!strncasecmp(hp->
name,
"to_", 3)) {
1401 }
else if (!strcasecmp(name,
"to")) {
1403 }
else if (!strcasecmp(name,
"from")) {
1409 for (i = 0; i < hp->
idx; i++) {
1423 (*event)->key = todup->
key;
1428 #define SWITCH_SERIALIZED_EVENT_MAP "S(iiisss)A(S(ss))" 1445 how |= TPL_EXCESS_OK;
1448 tpl_load(tn, how, data, len);
1454 event->flags = e.
flags;
1456 event->owner = e.
owner;
1458 event->body = e.
body;
1461 while (tpl_unpack(tn, 1)) {
1493 e.
flags =
event->flags;
1495 e.
owner =
event->owner;
1497 e.
body =
event->body;
1504 if (eh->
idx)
continue;
1513 how |= TPL_PREALLOCD;
1516 tpl_dump(tn, how, data, len);
1531 switch_size_t llen = 0, dlen = 0, blocksize = 512, encode_len = 1536, new_len = 0;
1533 char *encode_buf = NULL;
1537 dlen = blocksize * 2;
1539 if (!(buf = malloc(dlen))) {
1544 if (!(encode_buf = malloc(encode_len))) {
1561 for(i = 0; i < hp->
idx; i++) {
1562 new_len += (strlen(hp->
array[i]) * 3) + 1;
1565 new_len = (strlen(hp->
value) * 3) + 1;
1568 if (encode_len < new_len) {
1572 encode_len = new_len;
1574 if (!(tmp = realloc(encode_buf, encode_len))) {
1591 llen = strlen(hp->
name) + strlen(encode_buf) + 8;
1593 if ((len + llen) > dlen) {
1595 dlen += (blocksize + (len + llen));
1596 if (!(m = realloc(buf, dlen))) {
1602 switch_snprintf(buf + len, dlen - len,
"%s: %s\n", hp->
name, *encode_buf ==
'\0' ?
"_undef_" : encode_buf);
1610 int blen = (int) strlen(event->
body);
1619 if ((len + llen) > dlen) {
1621 dlen += (blocksize + (len + llen));
1622 if (!(m = realloc(buf, dlen))) {
1649 for (r = 0; r < len; r++) {
1666 char *vdata, *vdatap = NULL;
1667 char *end, *check_a, *check_b;
1669 char *var_array[1024] = { 0 };
1671 char *
next = NULL, *vnext = NULL;
1674 vdatap = strdup(data);
1690 if (check_a) end = check_a;
1725 if (*vdata ==
'^' && *(vdata + 1) ==
'^') {
1731 if ((var_count =
switch_separate_string(vdata, c, var_array, (
sizeof(var_array) /
sizeof(var_array[0]))))) {
1733 for (x = 0; x < var_count; x++) {
1734 char *inner_var_array[2] = { 0 };
1736 if (
switch_separate_string(var_array[x],
'=', inner_var_array, (
sizeof(inner_var_array) /
sizeof(inner_var_array[0]))) == 2) {
1755 *new_data = strdup(end);
1773 if (!(cj = cJSON_Parse(json))) {
1782 for (cjp = cj->
child; cjp; cjp = cjp->
next) {
1786 if (name && value) {
1787 if (!strcasecmp(name,
"_body")) {
1790 if (!strcasecmp(name,
"event-name")) {
1800 int i, x = cJSON_GetArraySize(cjp);
1802 for (i = 0; i < x; i++) {
1803 cJSON *
item = cJSON_GetArrayItem(cjp, i);
1823 cj = cJSON_CreateObject();
1827 cJSON *a = cJSON_CreateArray();
1830 for(i = 0; i < hp->
idx; i++) {
1831 cJSON_AddItemToArray(a, cJSON_CreateString(hp->
array[i]));
1834 cJSON_AddItemToObject(cj, hp->
name, a);
1837 cJSON_AddItemToObject(cj, hp->
name, cJSON_CreateString(hp->
value));
1842 int blen = (int) strlen(event->
body);
1847 cJSON_AddItemToObject(cj,
"Content-Length", cJSON_CreateString(tmp));
1848 cJSON_AddItemToObject(cj,
"_body", cJSON_CreateString(event->
body));
1863 *str = cJSON_PrintUnformatted(cj);
1878 char *encode_buf = malloc(encode_len);
1882 memset(encode_buf, 0, encode_len);
1894 char *data = NULL, *body = NULL;
1907 #ifdef HAVE_VASPRINTF 1908 ret = vasprintf(&data, fmt, ap);
1910 data = (
char *) malloc(2048);
1917 ret = vsnprintf(data, 2048, fmt, ap);
1921 #ifndef HAVE_VASPRINTF 1936 for (i = 0; i < hp->
idx; i++) {
1947 }
else if (event->
body) {
1952 int blen = (int) strlen(body);
2073 if (subclass_name) {
2098 event_node->
id =
DUP(
id);
2100 if (subclass_name) {
2107 if (EVENT_NODES[event]) {
2108 event_node->
next = EVENT_NODES[event];
2111 EVENT_NODES[event] = event_node;
2146 for (np = EVENT_NODES[
id]; np;) {
2189 for (np = EVENT_NODES[n->
event_id]; np; np = np->
next) {
2214 const char *proto,
const char *login,
2215 const char *from,
const char *from_domain,
2216 const char *status,
const char *event_type,
2217 const char *alt_event_type,
int event_count,
2218 const char *unique_id,
const char *channel_state,
2219 const char *answer_state,
const char *call_direction)
2241 #define resize(l) {\ 2243 olen += (len + l + block);\ 2245 if ((dp = realloc(data, olen))) {\ 2248 memset(c, 0, olen - cpos);\ 2254 char *data, *indup, *endof_indup;
2255 size_t sp = 0, len = 0, olen = 0, vtype = 0, br = 0, cpos, block = 128;
2256 const char *sub_val = NULL;
2257 char *cloned_sub_val = NULL, *expanded_sub_val = NULL;
2258 char *func_val = NULL;
2260 char *gvar = NULL, *sb = NULL;
2277 olen = strlen(in) + 1;
2282 if ((data = malloc(olen))) {
2285 for (p = indup; p && p < endof_indup && *p; p++) {
2290 if (*(p + 1) ==
'$') {
2293 if (*(p + 1) ==
'$') {
2296 }
else if (*(p + 1) ==
'\'') {
2299 }
else if (*(p + 1) ==
'\\') {
2300 if (len + 1 >= olen) {
2310 if (*p ==
'$' && !nv) {
2311 if (*(p + 1) ==
'$') {
2317 if (*(p + 1) ==
'{') {
2318 vtype = global ? 3 : 1;
2328 if (len + 1 >= olen) {
2339 char *s = p, *e, *vname, *vval = NULL;
2344 if ((vtype == 1 || vtype == 3) && *s ==
'{') {
2352 if (br == 1 && *e ==
'}') {
2359 if (e != s && *e ==
'{') {
2361 }
else if (br > 1 && *e ==
'}') {
2368 p = e > endof_indup ? endof_indup : e;
2371 for(sb = vname; sb && *sb; sb++) {
2375 }
else if (*sb ==
'(') {
2394 }
else if (br > 1 && *e ==
')') {
2396 }
else if (br == 1 && *e ==
')') {
2406 if (vtype == 1 || vtype == 3) {
2407 char *expanded = NULL;
2418 if ((ptr = strchr(vname,
':'))) {
2421 if ((ptr = strchr(ptr,
':'))) {
2423 ooffset = atoi(ptr);
2427 if ((ptr = strchr(vname,
'[')) && strchr(ptr,
']')) {
2439 sub_val =
"<Variable Expansion Permission Denied>";
2444 expanded_sub_val = NULL;
2446 sub_val = expanded_sub_val;
2451 if (offset || ooffset) {
2452 cloned_sub_val = strdup(sub_val);
2454 sub_val = cloned_sub_val;
2459 }
else if ((
size_t) abs(offset) <= strlen(sub_val)) {
2460 sub_val = cloned_sub_val + (strlen(cloned_sub_val) + offset);
2463 if (ooffset > 0 && (
size_t) ooffset < strlen(sub_val)) {
2464 if ((ptr = (
char *) sub_val + ooffset)) {
2473 char *expanded = NULL;
2474 char *expanded_vname = NULL;
2477 expanded_vname = NULL;
2479 vname = expanded_vname;
2490 sub_val =
"<API execute Permission Denied>";
2494 func_val = stream.
data;
2504 if ((nlen = sub_val ? strlen(sub_val) : 0)) {
2505 if (len + nlen >= olen) {
2523 if (len + 1 >= olen) {
2535 if (len + 1 >= olen) {
2554 char *encode_buf = NULL;
2555 const char *prof[12] = { 0 }, *prof_names[12] = {
2568 encode_buf = malloc(encode_len);
2573 for (x = 0; prof[x]; x++) {
2574 if (
zstr(prof[x])) {
2577 new_len = (strlen(prof[x]) * 3) + 1;
2578 if (encode_len < new_len) {
2581 encode_len = new_len;
2583 if (!(tmp = realloc(encode_buf, encode_len))) {
2590 stream.
write_function(&stream,
"%s=%s&", prof_names[x], encode_buf);
2596 for (; hi; hi = hi->
next) {
2597 char *var = hi->
name;
2598 char *val = hi->
value;
2600 if (vars_map != NULL) {
2601 if ((data =
switch_core_hash_find(vars_map, var)) == NULL || strcasecmp(((
char *) data),
"enabled"))
2606 new_len = (strlen((
char *) val) * 3) + 1;
2607 if (encode_len < new_len) {
2610 encode_len = new_len;
2612 tmp = realloc(encode_buf, encode_len);
2618 stream.
write_function(&stream,
"%s=%s&", (
char *) var, encode_buf);
2624 e = (
char *) stream.
data + (strlen((
char *) stream.
data) - 1);
2626 if (e && *e ==
'&') {
2639 int default_allow = 0;
2648 return default_allow;
2668 if (!prefix) prefix =
"";
2671 char *cols[128] = { 0 };
2672 char header_name[128] =
"";
2673 int col_count = 0, i = 0;
2674 char *data_copy = NULL;
2676 data_copy = strdup(data);
2680 for (i = 0; i < col_count; i++) {
2681 const char *val = NULL;
2682 switch_snprintf(header_name,
sizeof(header_name),
"%s%s", prefix, cols[i]);
2698 if (!prefix) prefix =
"";
2701 char *cols[128] = { 0 };
2702 char header_name[128] =
"";
2703 int col_count = 0, i = 0;
2704 char *data_copy = NULL;
2706 data_copy = strdup(data);
2710 for (i = 0; i < col_count; i++) {
2711 const char *val = NULL;
2712 switch_snprintf(header_name,
sizeof(header_name),
"%s%s", prefix, cols[i]);
2751 if (!(func) || (thisnp->
func == func && (thisnp->
user_data == user_data || user_data == NULL))) {
2764 thisnp->
func = NULL;
2812 if (!event_channel) {
2862 for (np = head->
node; np; np = np->
next) {
2912 for (np = head->
node; np; np = np->
next) {
2934 cJSON_Delete(ecd->
json);
2941 #ifndef SWITCH_CHANNEL_DISPATCH_MAX_KEY_PARTS 2942 #define SWITCH_CHANNEL_DISPATCH_MAX_KEY_PARTS 10 2963 for(i=x_argc - 1; i > 0; i--) {
2968 for(z=1; z < i; z++) {
2970 strncat(buf, x_argv[z],
sizeof(buf) - strlen(buf) - 1);
2982 if ((p = strchr(key,
'.'))) {
2994 char *json = cJSON_Print(ecd->
json);
3056 cJSON_Delete(*json);
3065 ecd->
key = strdup(key);
3080 if (!EVENT_CHANNEL_DISPATCH_QUEUE) {
3084 td = malloc(
sizeof(*td));
3096 cJSON_Delete(ecd->
json);
3114 ecd->
key = strdup(key);
3238 cJSON *dup = cJSON_Duplicate(*json, 1);
3239 cJSON *data = cJSON_GetObjectItem(dup,
"data");
3241 cJSON_ReplaceItemInObject(dup,
"eventChannel", cJSON_CreateString(np->
event_channel));
3242 cJSON_ReplaceItemInObject(data,
"name", cJSON_CreateString(np->
name));
3259 if (la->
visible != visible || force) {
3262 msg = cJSON_CreateObject();
3265 cJSON_AddItemToObject(msg,
"eventChannel", cJSON_CreateString(la->
event_channel));
3266 cJSON_AddItemToObject(data,
"action", cJSON_CreateString(visible ?
"hide" :
"show"));
3267 cJSON_AddItemToObject(data,
"wireSerno", cJSON_CreateNumber(la->
serno++));
3286 msg = cJSON_CreateObject();
3289 cJSON_AddItemToObject(msg,
"eventChannel", cJSON_CreateString(la->
event_channel));
3290 cJSON_AddItemToObject(data,
"action", cJSON_CreateString(
"clear"));
3291 cJSON_AddItemToObject(data,
"name", cJSON_CreateString(la->
name));
3292 cJSON_AddItemToObject(data,
"wireSerno", cJSON_CreateNumber(-1));
3293 cJSON_AddItemToObject(data,
"data", cJSON_CreateObject());
3300 cJSON_Delete(cur->
obj);
3320 msg = cJSON_CreateObject();
3323 cJSON_AddItemToObject(msg,
"eventChannel", cJSON_CreateString(la->
event_channel));
3324 cJSON_AddItemToObject(data,
"action", cJSON_CreateString(
"clear"));
3325 cJSON_AddItemToObject(data,
"name", cJSON_CreateString(la->
name));
3326 cJSON_AddItemToObject(data,
"wireSerno", cJSON_CreateNumber(-1));
3327 cJSON_AddItemToObject(data,
"data", cJSON_CreateObject());
3331 for (np = la->
head; np; np = np->
next) {
3332 msg = cJSON_CreateObject();
3335 cJSON_AddItemToObject(msg,
"eventChannel", cJSON_CreateString(la->
event_channel));
3336 cJSON_AddItemToObject(data,
"action", cJSON_CreateString(
"add"));
3337 cJSON_AddItemToObject(data,
"name", cJSON_CreateString(la->
name));
3338 cJSON_AddItemToObject(data,
"hashKey", cJSON_CreateString(np->
name));
3339 cJSON_AddItemToObject(data,
"wireSerno", cJSON_CreateNumber(la->
serno++));
3340 cJSON_AddItemToObject(data,
"data", cJSON_Duplicate(np->
obj, 1));
3342 cJSON_AddItemToObject(msg,
"sessid", cJSON_CreateString(sessid));
3349 msg = cJSON_CreateObject();
3352 cJSON_AddItemToObject(msg,
"eventChannel", cJSON_CreateString(la->
event_channel));
3353 cJSON_AddItemToObject(data,
"action", cJSON_CreateString(
"bootObj"));
3354 cJSON_AddItemToObject(data,
"name", cJSON_CreateString(la->
name));
3355 cJSON_AddItemToObject(data,
"wireSerno", cJSON_CreateNumber(-1));
3358 cJSON_AddItemToObject(msg,
"sessid", cJSON_CreateString(sessid));
3363 for (np = la->
head; np; np = np->
next) {
3364 cJSON *row = cJSON_CreateArray();
3365 cJSON_AddItemToArray(row, cJSON_CreateString(np->
name));
3366 cJSON_AddItemToArray(row, cJSON_Duplicate(np->
obj, 1));
3367 cJSON_AddItemToArray(data, row);
3391 *live_arrayP = NULL;
3397 if (la->
refs) done = 1;
3466 if (!strcmp(np->event_channel, event_channel) && !strcmp(np->name, name)) {
3547 dup = cJSON_Duplicate(node->
obj, 1);
3560 for (node = la->
head; node; node = node->
next) {
3561 if (node->
pos == idx) {
3562 dup = cJSON_Duplicate(node->
obj, 1);
3585 cJSON *msg, *data = NULL;
3603 msg = cJSON_CreateObject();
3606 cJSON_AddItemToObject(msg,
"eventChannel", cJSON_CreateString(la->
event_channel));
3607 cJSON_AddItemToObject(data,
"name", cJSON_CreateString(la->
name));
3608 cJSON_AddItemToObject(data,
"action", cJSON_CreateString(
"del"));
3609 cJSON_AddItemToObject(data,
"hashKey", cJSON_CreateString(cur->
name));
3610 cJSON_AddItemToObject(data,
"wireSerno", cJSON_CreateNumber(la->
serno++));
3611 cJSON_AddItemToObject(data,
"data", cur->
obj);
3633 const char *action =
"add";
3634 cJSON *msg = NULL, *data = NULL;
3635 const char *visibility = NULL;
3645 cJSON_Delete(node->
obj);
3652 node->
name = strdup(name);
3655 if (index > -1 && index < la->pos && la->
head) {
3659 for(np = la->
head; np; np = np->
next) {
3696 node->
obj = cJSON_Duplicate(*obj, 1);
3701 msg = cJSON_CreateObject();
3704 cJSON_AddItemToObject(msg,
"contentVisibility", cJSON_CreateString(visibility));
3706 cJSON_AddItemToObject(msg,
"eventChannel", cJSON_CreateString(la->
event_channel));
3707 cJSON_AddItemToObject(data,
"action", cJSON_CreateString(action));
3710 cJSON_AddItemToObject(data,
"arrIndex", cJSON_CreateNumber(index));
3713 cJSON_AddItemToObject(data,
"name", cJSON_CreateString(la->
name));
3714 cJSON_AddItemToObject(data,
"hashKey", cJSON_CreateString(node->
name));
3715 cJSON_AddItemToObject(data,
"wireSerno", cJSON_CreateNumber(la->
serno++));
3716 cJSON_AddItemToObject(data,
"data", cJSON_Duplicate(node->
obj, 1));
3740 const char *context = NULL, *
name = NULL;
3744 if ((jla = cJSON_GetObjectItem(json,
"data")) && (jla = cJSON_GetObjectItem(jla,
"liveArray"))) {
3753 if (!strcasecmp(command,
"bootstrap")) {
switch_xml_t switch_xml_add_child_d(_In_ switch_xml_t xml, _In_z_ const char *name, _In_ switch_size_t off)
wrapper for switch_xml_add_child() that strdup()s name
char * switch_event_get_header_idx(switch_event_t *event, const char *header_name, int idx)
void switch_json_add_presence_data_cols(switch_event_t *event, cJSON *json, const char *prefix)
switch_status_t switch_event_serialize_json(switch_event_t *event, char **str)
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
const char * switch_core_get_switchname(void)
void switch_xml_free(_In_opt_ switch_xml_t xml)
frees the memory allocated for an switch_xml structure
unsigned int switch_queue_size(switch_queue_t *queue)
struct alias_node_s * next
switch_event_types_t event_id
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
switch_status_t switch_event_channel_bind(const char *event_channel, switch_event_channel_func_t func, switch_event_channel_id_t *id, void *user_data)
void switch_live_array_parse_json(cJSON *json, switch_event_channel_id_t channel_id)
#define SWITCH_SERIALIZED_EVENT_MAP
switch_status_t switch_event_running(void)
Determine if the event system has been initialized.
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
const char * switch_priority_name(switch_priority_t priority)
Return a printable name of a switch_priority_t.
switch_status_t switch_event_add_header_string_nodup(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
switch_status_t switch_event_bind_removable(const char *id, switch_event_types_t event, const char *subclass_name, switch_event_callback_t callback, void *user_data, switch_event_node_t **node)
Bind an event callback to a specific event.
#define SWITCH_CHANNEL_LOG
switch_status_t switch_core_hash_destroy(_Inout_ switch_hash_t **hash)
Destroy an existing hash table.
static uint8_t EVENT_DISPATCH_QUEUE_RUNNING[MAX_DISPATCH_VAL]
uint32_t switch_event_channel_id_t
switch_status_t switch_live_array_visible(switch_live_array_t *la, switch_bool_t visible, switch_bool_t force)
char * switch_find_end_paren(const char *s, char open, char close)
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
static char guess_ip_v6[80]
static unsigned int MAX_DISPATCH
static switch_event_node_t * EVENT_NODES[SWITCH_EVENT_ALL+1]
static switch_thread_rwlock_t * RWLOCK
struct alias_node_s alias_node_t
#define switch_event_del_header(_e, _h)
int switch_core_test_flag(int flag)
#define switch_core_hash_init(_hash)
static char * my_dup(const char *s)
switch_status_t switch_event_serialize_json_obj(switch_event_t *event, cJSON **json)
static int SYSTEM_RUNNING
void switch_live_array_lock(switch_live_array_t *la)
static switch_mutex_t * CUSTOM_HASH_MUTEX
void switch_event_channel_permission_modify(const char *cookie, const char *event_channel, switch_bool_t set)
switch_event_types_t
Built-in Events.
switch_status_t switch_event_binary_serialize(switch_event_t *event, void **data, switch_size_t *len)
#define DISPATCH_QUEUE_LEN
struct switch_event_channel_sub_node_head_s switch_event_channel_sub_node_head_t
int switch_event_add_array(switch_event_t *event, const char *var, const char *val)
static struct @5 event_channel_manager
switch_event_channel_id_t id
static int switch_string_has_escaped_data(const char *in)
switch_status_t switch_live_array_destroy(switch_live_array_t **live_arrayP)
unsigned int switch_separate_string_string(char *buf, char *delim, _Post_count_(return) char **array, unsigned int arraylen)
void switch_event_add_presence_data_cols(switch_channel_t *channel, switch_event_t *event, const char *prefix)
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)
static switch_xml_t add_xml_header(switch_xml_t xml, char *name, char *value, int offset)
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
switch_status_t switch_name_event(const char *name, switch_event_types_t *type)
return the event id that matches a given event name
static unsigned int SOFT_MAX_DISPATCH
#define switch_split(_data, _delim, _array)
switch_priority_t
Priority Indication.
switch_status_t switch_api_execute(const char *cmd, const char *arg, switch_core_session_t *session, switch_stream_handle_t *stream)
Execute a registered API command.
cJSON * switch_live_array_get_idx(switch_live_array_t *la, int idx)
switch_status_t switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize)
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
#define SWITCH_EVENT_SUBCLASS_ANY
switch_memory_pool_t * pool
Representation of an event.
int switch_event_check_permission_list(switch_event_t *list, const char *name)
const char *const const char *const const cJSON *const value
switch_status_t switch_queue_trypop(switch_queue_t *queue, void **data)
static uint32_t _switch_event_channel_broadcast(const char *event_channel, const char *broadcast_channel, cJSON *json, const char *key, switch_event_channel_id_t id)
static switch_queue_t * EVENT_CHANNEL_DISPATCH_QUEUE
void switch_event_launch_dispatch_threads(uint32_t max)
switch_status_t switch_event_set_priority(switch_event_t *event, switch_priority_t priority)
Set the priority of an event.
unsigned int switch_ci_hashfunc_default(const char *char_key, switch_ssize_t *klen)
struct switch_event_channel_sub_node_head_s * head
switch_status_t switch_time_exp_lt(switch_time_exp_t *result, switch_time_t input)
switch_event_header_t * last_header
void switch_event_channel_permission_clear(const char *cookie)
A representation of an XML tree.
switch_xml_t switch_event_xmlize(switch_event_t *event, const char *fmt,...)
switch_memory_pool_t * pool
uint32_t switch_core_cpu_count(void)
switch_status_t switch_queue_pop(switch_queue_t *queue, void **data)
switch_bool_t switch_live_array_isnew(switch_live_array_t *la)
A node to store binded events.
char * switch_url_encode(const char *url, char *buf, size_t len)
switch_status_t switch_event_dup(switch_event_t **event, switch_event_t *todup)
Duplicate an event.
switch_xml_t switch_xml_set_txt_d(switch_xml_t xml, const char *txt)
wrapper for switch_xml_set_txt() that strdup()s txt \ sets the character content for the given tag an...
switch_status_t switch_strftime_nocheck(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm)
#define switch_event_create_subclass(_e, _eid, _sn)
switch_event_channel_id_t id
static switch_thread_t * thread
static cJSON * json_add_child_array(cJSON *json, const char *name)
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
void(* switch_live_array_command_handler_t)(switch_live_array_t *la, const char *cmd, const char *sessid, cJSON *jla, void *user_data)
static void unsub_all_switch_event_channel(void)
struct switch_runtime runtime
#define SWITCH_CHANNEL_DISPATCH_MAX_KEY_PARTS
cJSON * switch_live_array_get(switch_live_array_t *la, const char *name)
static switch_thread_t * EVENT_DISPATCH_QUEUE_THREADS[MAX_DISPATCH_VAL]
static int switch_events_match(switch_event_t *event, switch_event_node_t *node)
switch_status_t switch_event_channel_deliver(const char *event_channel, cJSON **json, const char *key, switch_event_channel_id_t id)
static int EVENT_CHANNEL_DISPATCH_THREAD_STARTING
static char * switch_strchr_strict(const char *in, char find, const char *allowed)
switch_status_t switch_event_channel_broadcast(const char *event_channel, cJSON **json, const char *key, switch_event_channel_id_t id)
static void destroy_ecd(event_channel_data_t **ecdP)
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
switch_status_t switch_event_shutdown(void)
Stop the eventing system.
switch_status_t switch_thread_rwlock_rdlock(switch_thread_rwlock_t *rwlock)
switch_status_t switch_event_init(switch_memory_pool_t *pool)
Start the eventing system.
static switch_mutex_t * POOL_LOCK
static void switch_event_deliver_thread_pool(switch_event_t **event)
#define SWITCH_MUTEX_NESTED
void switch_event_prep_for_delivery_detailed(const char *file, const char *func, int line, switch_event_t *event)
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
switch_status_t switch_event_bind(const char *id, switch_event_types_t event, const char *subclass_name, switch_event_callback_t callback, void *user_data)
Bind an event callback to a specific event.
void switch_os_yield(void)
switch_byte_t switch_byte_t * buf
#define switch_yield(ms)
Wait a desired number of microseconds and yield the CPU.
switch_event_channel_id_t ID
static void *SWITCH_THREAD_FUNC switch_event_dispatch_thread(switch_thread_t *thread, void *obj)
unsigned int switch_separate_string(_In_ char *buf, char delim, _Post_count_(return) char **array, unsigned int arraylen)
Separate a string into an array based on a character delimiter.
static cJSON * json_add_child_obj(cJSON *json, const char *name, cJSON *obj)
switch_status_t switch_event_fire_detailed(const char *file, const char *func, int line, switch_event_t **event, void *user_data)
Fire an event with full arguement list.
switch_status_t switch_live_array_clear(switch_live_array_t *la)
static switch_hash_t * CUSTOM_HASH
switch_status_t switch_live_array_add(switch_live_array_t *la, const char *name, int index, cJSON **obj, switch_bool_t duplicate)
static uint32_t switch_event_channel_unsub_head(switch_event_channel_func_t func, switch_event_channel_sub_node_head_t *head, void *user_data)
static void ecd_deliver(event_channel_data_t **ecdP)
char * switch_core_get_uuid(void)
Retrieve the unique identifier from the core.
switch_status_t switch_event_create_pres_in_detailed(char *file, char *func, int line, const char *proto, const char *login, const char *from, const char *from_domain, const char *status, const char *event_type, const char *alt_event_type, int event_count, const char *unique_id, const char *channel_state, const char *answer_state, const char *call_direction)
switch_event_types_t event_id
switch_status_t switch_event_create_subclass_detailed(const char *file, const char *func, int line, switch_event_t **event, switch_event_types_t event_id, const char *subclass_name)
Create an event.
switch_event_channel_sub_node_t * node
static switch_queue_t * EVENT_DISPATCH_QUEUE
void switch_event_merge(switch_event_t *event, switch_event_t *tomerge)
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...)
char * switch_event_get_body(switch_event_t *event)
Retrieve the body value from an event.
static switch_memory_pool_t * RUNTIME_POOL
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
#define switch_channel_get_variable(_c, _v)
#define SWITCH_THREAD_STACKSIZE
switch_event_channel_func_t func
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
#define switch_zmalloc(ptr, len)
switch_status_t switch_event_binary_deserialize(switch_event_t **eventp, void **data, switch_size_t len, switch_bool_t destroy)
Render a string representation of an event suitable for printing or network transport.
const char * switch_event_name(switch_event_types_t event)
Render the name of an event id enumeration.
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
switch_thread_start_t func
switch_xml_t switch_xml_new(_In_opt_z_ const char *name)
returns a new empty switch_xml structure with the given root tag name
switch_status_t switch_event_set_subclass_name(switch_event_t *event, const char *subclass_name)
void switch_live_array_set_command_handler(switch_live_array_t *la, switch_live_array_command_handler_t command_handler)
void switch_console_push_match(switch_console_callback_match_t **matches, const char *new_val)
void switch_event_deliver(switch_event_t **event)
Deliver an event to all of the registered event listeners.
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
static switch_mutex_t * EVENT_QUEUE_MUTEX
switch_status_t switch_event_add_body(switch_event_t *event, const char *fmt,...)
void(* switch_event_channel_func_t)(const char *event_channel, cJSON *json, const char *key, switch_event_channel_id_t id, void *user_data)
switch_status_t switch_thread_join(switch_status_t *retval, switch_thread_t *thd)
static switch_event_header_t * new_header(const char *header_name)
void switch_core_hash_this(_In_ switch_hash_index_t *hi, _Out_opt_ptrdiff_cap_(klen) const void **key, _Out_opt_ switch_ssize_t *klen, _Out_ void **val)
Gets the key and value of the current hash element.
static switch_status_t la_broadcast(switch_live_array_t *la, cJSON **json)
static uint32_t switch_event_channel_unsub_channel(switch_event_channel_func_t func, const char *event_channel, void *user_data)
int switch_vasprintf(_Out_opt_ char **buf, _In_z_ _Printf_format_string_ const char *format, _In_ va_list ap)
switch_hash_index_t * switch_core_hash_next(_In_ switch_hash_index_t **hi)
Gets the next element of a hashtable.
switch_status_t switch_event_create_json(switch_event_t **event, const char *json)
static switch_mutex_t * BLOCK
static switch_bool_t switch_string_var_check_const(const char *s)
const char * cJSON_GetObjectCstr(const cJSON *object, const char *string)
switch_status_t switch_rfc822_date(char *date_str, switch_time_t t)
void switch_cond_next(void)
switch_live_array_command_handler_t command_handler
struct switch_event_channel_sub_node_s switch_event_channel_sub_node_t
#define SWITCH_STANDARD_STREAM(s)
static switch_status_t switch_event_create_plain(switch_event_t **event, switch_event_types_t event_id)
void * switch_core_hash_delete(_In_ switch_hash_t *hash, _In_z_ const char *key)
Delete data from a hash based on desired key.
void switch_core_memory_reclaim_events(void)
switch_status_t switch_event_del_header_val(switch_event_t *event, const char *header_name, const char *val)
static int EVENT_CHANNEL_DISPATCH_THREAD_COUNT
#define switch_str_nil(s)
Make a null string a blank string instead.
switch_event_channel_id_t channel_id
struct fspr_thread_mutex_t switch_mutex_t
static switch_memory_pool_t * THRUNTIME_POOL
static uint64_t EVENT_SEQUENCE_NR
uint32_t switch_event_channel_unbind(const char *event_channel, switch_event_channel_func_t func, void *user_data)
switch_bool_t switch_live_array_add_alias(switch_live_array_t *la, const char *event_channel, const char *name)
static void free_header(switch_event_header_t **header)
switch_stream_handle_write_function_t write_function
switch_status_t switch_live_array_bootstrap(switch_live_array_t *la, const char *sessid, switch_event_channel_id_t channel_id)
const char * switch_core_get_event_channel_key_separator(void)
switch_thread_rwlock_t * rwlock
switch_status_t
Common return values.
switch_event_channel_sub_node_t * tail
#define switch_goto_status(_status, _label)
switch_bool_t switch_live_array_clear_alias(switch_live_array_t *la, const char *event_channel, const char *name)
struct la_node_s la_node_t
switch_status_t switch_live_array_create(const char *event_channel, const char *name, switch_event_channel_id_t channel_id, switch_live_array_t **live_arrayP)
const char * switch_core_get_hostname(void)
switch_status_t switch_queue_interrupt_all(switch_queue_t *queue)
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)
void switch_live_array_set_user_data(switch_live_array_t *la, void *user_data)
switch_status_t switch_event_dup_reply(switch_event_t **event, switch_event_t *todup)
#define switch_core_hash_insert(_h, _k, _d)
static switch_status_t switch_event_channel_sub_channel(const char *event_channel, switch_event_channel_func_t func, switch_event_channel_id_t id, void *user_data)
#define SWITCH_EVENT_CHANNEL_GLOBAL
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
static void check_dispatch(void)
A registered custom event subclass.
void switch_live_array_unlock(switch_live_array_t *la)
#define switch_event_get_header(_e, _h)
switch_status_t switch_live_array_del(switch_live_array_t *la, const char *name)
switch_hash_t * perm_hash
switch_status_t switch_event_free_subclass_detailed(const char *owner, const char *subclass_name)
switch_status_t switch_queue_trypush(switch_queue_t *queue, void *data)
switch_status_t switch_event_create_array_pair(switch_event_t **event, char **names, char **vals, int len)
switch_status_t switch_queue_push(switch_queue_t *queue, void *data)
struct switch_event_node * next
static switch_status_t switch_event_queue_dispatch_event(switch_event_t **eventp)
char * switch_event_build_param_string(switch_event_t *event, const char *prefix, switch_hash_t *vars_map)
switch_stack_t
Expression of how to stack a list.
switch_memory_pool_t * pool
switch_status_t switch_event_unbind_callback(switch_event_callback_t callback)
switch_status_t switch_thread_rwlock_create(switch_thread_rwlock_t **rwlock, switch_memory_pool_t *pool)
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
void(* switch_event_callback_t)(switch_event_t *)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_status_t switch_threadattr_create(switch_threadattr_t **new_attr, switch_memory_pool_t *pool)
static char guess_ip_v4[80]
switch_status_t switch_thread_create(switch_thread_t **new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont)
switch_status_t switch_find_local_ip(_Out_opt_bytecapcount_(len) char *buf, _In_ int len, _In_opt_ int *mask, _In_ int family)
find local ip of the box
switch_status_t switch_event_reserve_subclass_detailed(const char *owner, const char *subclass_name)
Reserve a subclass name for private use with a custom event.
struct fspr_pool_t switch_memory_pool_t
switch_event_callback_t callback
switch_status_t switch_event_set_body(switch_event_t *event, const char *body)
switch_status_t switch_queue_create(switch_queue_t **queue, unsigned int queue_capacity, switch_memory_pool_t *pool)
switch_status_t switch_event_rename_header(switch_event_t *event, const char *header_name, const char *new_header_name)
void switch_event_destroy(switch_event_t **event)
Destroy an event.
struct switch_event_channel_sub_node_s * next
char * switch_core_sprintf(_In_ switch_memory_pool_t *pool, _In_z_ _Printf_format_string_ const char *fmt,...)
printf-style style printing routine. The data is output to a string allocated from the pool ...
struct fspr_thread_t switch_thread_t
const char * switch_cut_path(const char *in)
Create a pointer to the file name in a given file path eliminating the directory name.
static void *SWITCH_THREAD_FUNC switch_event_channel_deliver_thread(switch_thread_t *thread, void *obj)
switch_event_header_t * switch_event_get_header_ptr(switch_event_t *event, const char *header_name)
Retrieve a header value from an event.
static void *SWITCH_THREAD_FUNC switch_event_deliver_thread(switch_thread_t *thread, void *obj)
switch_bool_t switch_event_channel_permission_verify(const char *cookie, const char *event_channel)
struct fspr_thread_rwlock_t switch_thread_rwlock_t
switch_status_t switch_event_serialize(switch_event_t *event, char **str, switch_bool_t encode)
#define switch_core_hash_first(_h)
static int DISPATCH_THREAD_COUNT
static cJSON * json_add_child_string(cJSON *json, const char *name, const char *val)
switch_event_header_t * headers
switch_status_t switch_event_get_custom_events(switch_console_callback_match_t **matches)
char * switch_core_get_variable_dup(_In_z_ const char *varname)
static char * EVENT_NAMES[]
switch_status_t switch_thread_pool_launch_thread(switch_thread_data_t **tdp)
switch_status_t switch_event_unbind(switch_event_node_t **node)
Unbind a bound event consumer.
static switch_status_t switch_event_base_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, char *data)
switch_status_t switch_threadattr_priority_set(switch_threadattr_t *attr, switch_thread_priority_t priority)
switch_hash_index_t * switch_core_hash_first_iter(_In_ switch_hash_t *hash, switch_hash_index_t *hi)
Gets the first element of a hashtable.