42 #define DISPATCH_QUEUE_LEN 10000
80 #define MAX_DISPATCH_VAL 64
103 #ifdef SWITCH_EVENT_RECYCLE
112 size_t len = strlen(s) + 1;
113 void *
new = malloc(len);
116 return (
char *) memcpy(
new, s, len);
120 #define ALLOC(size) malloc(size)
123 #define DUP(str) my_dup(str)
126 #define FREE(ptr) switch_safe_free(ptr)
141 "CHANNEL_HANGUP_COMPLETE",
143 "CHANNEL_EXECUTE_COMPLETE",
149 "CHANNEL_PROGRESS_MEDIA",
153 "CHANNEL_APPLICATION",
192 "PHONE_FEATURE_SUBSCRIBE",
200 "CLIENT_DISCONNECTED",
201 "SERVER_DISCONNECTED",
216 "CONFERENCE_DATA_QUERY",
243 match = !strcmp(node->
subclass_name + 5, file_header) ? 1 : 0;
248 match = !strcmp(node->
subclass_name + 5, func_header) ? 1 : 0;
277 td = malloc(
sizeof(*td));
306 if ( my_id >= MAX_DISPATCH_VAL ) {
400 for (node = EVENT_NODES[e]; node; node = node->
next) {
402 (*event)->bind_user_data = node->
user_data;
455 if (!strcmp(owner, subclass->
owner)) {
482 if (subclass->
bind) {
492 subclass->
name =
DUP(subclass_name);
501 #ifdef SWITCH_EVENT_RECYCLE
628 uint32_t sanity = 200;
704 #ifdef SWITCH_EVENT_RECYCLE
721 #ifdef SWITCH_EVENT_RECYCLE
730 #ifdef SWITCH_EVENT_RECYCLE
737 #ifdef SWITCH_EVENT_RECYCLE
748 (*event)->event_id = event_id;
753 (*event)->subclass_name =
DUP(subclass_name);
762 event->priority = priority;
771 unsigned long hash = 0;
782 for (hp = event->headers; hp; hp = hp->
next) {
783 if ((!hp->
hash || hash == hp->
hash) && !strcasecmp(hp->
name, header_name)) {
785 hp->
name =
DUP(new_header_name);
800 unsigned long hash = 0;
809 for (hp = event->headers; hp; hp = hp->
next) {
810 if ((!hp->
hash || hash == hp->
hash) && !strcasecmp(hp->
name, header_name)) {
824 return hp->
array[idx];
831 }
else if (!strcmp(header_name,
"_body")) {
840 return (event ? event->body : NULL);
849 unsigned long hash = 0;
860 if ((!hp->
hash || hash == hp->
hash) && !strcasecmp(header_name, hp->
name) && (
zstr(val) || !strcmp(hp->
value, val))) {
864 event->headers = hp->
next;
866 if (hp == event->last_header || !hp->
next) {
867 event->last_header = lp;
874 for (i = 0; i < hp->
idx; i++) {
882 memset(hp, 0,
sizeof(*hp));
883 #ifdef SWITCH_EVENT_RECYCLE
903 #ifdef SWITCH_EVENT_RECYCLE
909 header =
ALLOC(
sizeof(*header));
911 #ifdef SWITCH_EVENT_RECYCLE
915 memset(header, 0,
sizeof(*header));
916 header->
name =
DUP(header_name);
931 if (strlen(val) < 8) {
939 while((p = strstr(p,
"|:"))) {
948 data = strdup(val + 7);
950 len = (
sizeof(
char *) * max) + 1;
958 for(i = 0; i < max; i++) {
972 int exists = 0, fly = 0;
975 char *real_header_name = NULL;
978 if (!strcmp(header_name,
"_body")) {
982 if ((index_ptr = strchr(header_name,
'['))) {
984 index = atoi(index_ptr);
985 real_header_name =
DUP(header_name);
986 if ((index_ptr = strchr(real_header_name,
'['))) {
989 header_name = real_header_name;
1008 if (index > -1 && index <= 4000) {
1009 if (index < header->idx) {
1016 m = realloc(header->
array,
sizeof(
char *) * (index + 1));
1019 for (i = header->
idx; i < index; i++) {
1022 m[index] =
DUP(data);
1023 header->
idx = index + 1;
1033 if ((stack & SWITCH_STACK_PUSH) || (stack & SWITCH_STACK_UNSHIFT)) {
1056 if (!strncmp(data,
"ARRAY::", 7)) {
1066 if ((stack & SWITCH_STACK_PUSH) || (stack & SWITCH_STACK_UNSHIFT)) {
1072 if (header->
value && !header->
idx) {
1073 m = malloc(
sizeof(
char *));
1075 m[0] = header->
value;
1076 header->
value = NULL;
1082 i = header->
idx + 1;
1083 m = realloc(header->
array,
sizeof(
char *) * i);
1086 if ((stack & SWITCH_STACK_PUSH)) {
1087 m[header->
idx] = data;
1088 }
else if ((stack & SWITCH_STACK_UNSHIFT)) {
1089 for (j = header->
idx; j > 0; j--) {
1100 for(j = 0; j < header->
idx; j++) {
1101 len += strlen(header->
array[j]) + 2;
1106 hv = realloc(header->
value, len);
1110 if (header->
idx > 1) {
1113 *header->
value =
'\0';
1116 hv += strlen(header->
value);
1117 for(j = 0; j < header->
idx; j++) {
1119 memcpy(hv,
"|:", 2);
1122 memcpy(hv, header->
array[j], strlen(header->
array[j]));
1123 hv += strlen(header->
array[j]);
1130 header->
value = data;
1137 header->
next =
event->headers;
1138 event->headers = header;
1140 event->last_header = header;
1144 event->last_header->
next = header;
1146 event->headers = header;
1147 header->
next = NULL;
1149 event->last_header = header;
1179 if (!event || !subclass_name)
1183 event->subclass_name =
DUP(subclass_name);
1202 event->body =
DUP(body);
1247 for (i = 0; i < this->idx; i++) {
1248 FREE(this->array[i]);
1258 #ifdef SWITCH_EVENT_RECYCLE
1270 #ifdef SWITCH_EVENT_RECYCLE
1289 for (hp = tomerge->headers; hp; hp = hp->
next) {
1293 for(i = 0; i < hp->
idx; i++) {
1310 (*event)->event_id = todup->event_id;
1311 (*event)->event_user_data = todup->event_user_data;
1312 (*event)->bind_user_data = todup->bind_user_data;
1313 (*event)->flags = todup->flags;
1314 for (hp = todup->headers; hp; hp = hp->
next) {
1315 if (todup->subclass_name && !strcmp(hp->
name,
"Event-Subclass")) {
1321 for (i = 0; i < hp->
idx; i++) {
1330 (*event)->body =
DUP(todup->body);
1333 (*event)->key = todup->key;
1342 char hname[1024] =
"";
1349 (*event)->event_id = todup->event_id;
1350 (*event)->event_user_data = todup->event_user_data;
1351 (*event)->bind_user_data = todup->bind_user_data;
1352 (*event)->flags = todup->flags;
1354 for (hp = todup->headers; hp; hp = hp->
next) {
1355 char *name = hp->
name, *value = hp->
value;
1357 if (todup->subclass_name && !strcmp(hp->
name,
"Event-Subclass")) {
1361 if (!strncasecmp(hp->
name,
"from_", 5)) {
1365 }
else if (!strncasecmp(hp->
name,
"to_", 3)) {
1369 }
else if (!strcasecmp(name,
"to")) {
1371 }
else if (!strcasecmp(name,
"from")) {
1377 for (i = 0; i < hp->
idx; i++) {
1391 (*event)->key = todup->key;
1396 #define SWITCH_SERIALIZED_EVENT_MAP "S(iiisss)A(S(ss))"
1412 how |= TPL_EXCESS_OK;
1415 tpl_load(tn, how, data, len);
1421 event->flags = e.
flags;
1423 event->owner = e.
owner;
1425 event->body = e.
body;
1428 while(tpl_unpack(tn, 1)) {
1456 e.
flags =
event->flags;
1458 e.
owner =
event->owner;
1460 e.
body =
event->body;
1466 for (eh = event->headers; eh; eh = eh->
next) {
1467 if (eh->
idx)
continue;
1476 how |= TPL_PREALLOCD;
1479 tpl_dump(tn, how, data, len);
1491 switch_size_t llen = 0, dlen = 0, blocksize = 512, encode_len = 1536, new_len = 0;
1493 char *encode_buf = NULL;
1497 dlen = blocksize * 2;
1499 if (!(buf = malloc(dlen))) {
1504 if (!(encode_buf = malloc(encode_len))) {
1509 for (hp = event->headers; hp; hp = hp->
next) {
1521 for(i = 0; i < hp->
idx; i++) {
1522 new_len += (strlen(hp->
array[i]) * 3) + 1;
1525 new_len = (strlen(hp->
value) * 3) + 1;
1528 if (encode_len < new_len) {
1532 encode_len = new_len;
1534 if (!(tmp = realloc(encode_buf, encode_len))) {
1551 llen = strlen(hp->
name) + strlen(encode_buf) + 8;
1553 if ((len + llen) > dlen) {
1555 dlen += (blocksize + (len + llen));
1556 if (!(buf = realloc(buf, dlen))) {
1562 switch_snprintf(buf + len, dlen - len,
"%s: %s\n", hp->
name, *encode_buf ==
'\0' ?
"_undef_" : encode_buf);
1570 int blen = (int) strlen(event->body);
1579 if ((len + llen) > dlen) {
1581 dlen += (blocksize + (len + llen));
1582 if (!(buf = realloc(buf, dlen))) {
1589 switch_snprintf(buf + len, dlen - len,
"Content-Length: %d\n\n%s", blen, event->body);
1609 for (r = 0; r < len; r++) {
1626 char *vdata, *vdatap = NULL;
1627 char *end, *check_a, *check_b;
1629 char *var_array[1024] = { 0 };
1631 char *next = NULL, *vnext = NULL;
1634 vdatap = strdup(data);
1650 if (check_a) end = check_a;
1684 if (*vdata ==
'^' && *(vdata + 1) ==
'^') {
1690 if ((var_count =
switch_separate_string(vdata, c, var_array, (
sizeof(var_array) /
sizeof(var_array[0]))))) {
1692 for (x = 0; x < var_count; x++) {
1693 char *inner_var_array[2] = { 0 };
1694 int inner_var_count;
1697 inner_var_array, (
sizeof(inner_var_array) /
sizeof(inner_var_array[0])))) == 2) {
1716 *new_data = strdup(end);
1743 for (cjp = cj->
child; cjp; cjp = cjp->
next) {
1744 char *name = cjp->
string;
1747 if (name && value) {
1748 if (!strcasecmp(name,
"_body")) {
1751 if (!strcasecmp(name,
"event-name")) {
1763 for (i = 0; i < x; i++) {
1786 for (hp = event->headers; hp; hp = hp->
next) {
1791 for(i = 0; i < hp->
idx; i++) {
1803 int blen = (int) strlen(event->body);
1839 char *encode_buf = malloc(encode_len);
1843 memset(encode_buf, 0, encode_len);
1855 char *data = NULL, *body = NULL;
1868 #ifdef HAVE_VASPRINTF
1869 ret = vasprintf(&data, fmt, ap);
1871 data = (
char *) malloc(2048);
1876 ret = vsnprintf(data, 2048, fmt, ap);
1880 #ifndef HAVE_VASPRINTF
1889 for (hp = event->headers; hp; hp = hp->
next) {
1893 for (i = 0; i < hp->
idx; i++) {
1904 }
else if (event->body) {
1909 int blen = (int) strlen(body);
1978 (*event)->event_user_data = user_data;
2026 if (subclass_name) {
2043 event_node->
id =
DUP(
id);
2045 if (subclass_name) {
2051 if (EVENT_NODES[event]) {
2052 event_node->
next = EVENT_NODES[event];
2055 EVENT_NODES[event] = event_node;
2090 for (np = EVENT_NODES[
id]; np;) {
2133 for (np = EVENT_NODES[n->
event_id]; np; np = np->
next) {
2158 const
char *proto, const
char *login,
2159 const
char *from, const
char *from_domain,
2160 const
char *status, const
char *event_type,
2161 const
char *alt_event_type,
int event_count,
2162 const
char *unique_id, const
char *channel_state,
2163 const
char *answer_state, const
char *call_direction)
2185 #define resize(l) {\
2187 olen += (len + l + block);\
2189 if ((dp = realloc(data, olen))) {\
2192 memset(c, 0, olen - cpos);\
2198 char *data, *indup, *endof_indup;
2199 size_t sp = 0, len = 0, olen = 0, vtype = 0, br = 0, cpos, block = 128;
2200 const char *sub_val = NULL;
2201 char *cloned_sub_val = NULL, *expanded_sub_val = NULL;
2202 char *func_val = NULL;
2204 char *gvar = NULL, *sb = NULL;
2221 olen = strlen(in) + 1;
2225 if ((data = malloc(olen))) {
2228 for (p = indup; p && p < endof_indup && *p; p++) {
2233 if (*(p + 1) ==
'$') {
2236 if (*(p + 1) ==
'$') {
2239 }
else if (*(p + 1) ==
'\'') {
2242 }
else if (*(p + 1) ==
'\\') {
2249 if (*p ==
'$' && !nv) {
2250 if (*(p + 1) ==
'$') {
2256 if (*(p + 1) ==
'{') {
2257 vtype = global ? 3 : 1;
2274 char *s = p, *e, *vname, *vval = NULL;
2279 if ((vtype == 1 || vtype == 3) && *s ==
'{') {
2287 if (br == 1 && *e ==
'}') {
2294 if (e != s && *e ==
'{') {
2296 }
else if (br > 1 && *e ==
'}') {
2303 p = e > endof_indup ? endof_indup : e;
2306 for(sb = vname; sb && *sb; sb++) {
2310 }
else if (*sb ==
'(') {
2329 }
else if (br > 1 && *e ==
')') {
2331 }
else if (br == 1 && *e ==
')') {
2341 if (vtype == 1 || vtype == 3) {
2342 char *expanded = NULL;
2353 if ((ptr = strchr(vname,
':'))) {
2356 if ((ptr = strchr(ptr,
':'))) {
2358 ooffset = atoi(ptr);
2362 if ((ptr = strchr(vname,
'[')) && strchr(ptr,
']')) {
2374 sub_val =
"<Variable Expansion Permission Denied>";
2379 expanded_sub_val = NULL;
2381 sub_val = expanded_sub_val;
2386 if (offset || ooffset) {
2387 cloned_sub_val = strdup(sub_val);
2389 sub_val = cloned_sub_val;
2394 }
else if ((
size_t) abs(offset) <= strlen(sub_val)) {
2395 sub_val = cloned_sub_val + (strlen(cloned_sub_val) + offset);
2398 if (ooffset > 0 && (
size_t) ooffset < strlen(sub_val)) {
2399 if ((ptr = (
char *) sub_val + ooffset)) {
2408 char *expanded = NULL;
2413 char *expanded_vname = NULL;
2416 expanded_vname = NULL;
2418 vname = expanded_vname;
2429 sub_val =
"<API execute Permission Denied>";
2432 func_val = stream.
data;
2449 if ((nlen = sub_val ? strlen(sub_val) : 0)) {
2450 if (len + nlen >= olen) {
2467 if (len + 1 >= olen) {
2495 char *encode_buf = NULL;
2496 const char *prof[12] = { 0 }, *prof_names[12] = {
2509 encode_buf = malloc(encode_len);
2514 for (x = 0; prof[x]; x++) {
2515 if (
zstr(prof[x])) {
2518 new_len = (strlen(prof[x]) * 3) + 1;
2519 if (encode_len < new_len) {
2522 encode_len = new_len;
2524 if (!(tmp = realloc(encode_buf, encode_len))) {
2531 stream.
write_function(&stream,
"%s=%s&", prof_names[x], encode_buf);
2535 if ((hi = event->headers)) {
2537 for (; hi; hi = hi->
next) {
2538 char *var = hi->
name;
2539 char *val = hi->
value;
2541 if (vars_map != NULL) {
2542 if ((data =
switch_core_hash_find(vars_map, var)) == NULL || strcasecmp(((
char *) data),
"enabled"))
2547 new_len = (strlen((
char *) var) * 3) + 1;
2548 if (encode_len < new_len) {
2551 encode_len = new_len;
2553 tmp = realloc(encode_buf, encode_len);
2559 stream.
write_function(&stream,
"%s=%s&", (
char *) var, encode_buf);
2565 e = (
char *) stream.
data + (strlen((
char *) stream.
data) - 1);
2567 if (e && *e ==
'&') {
2580 int default_allow = 0;
2588 if (!list->headers) {
2589 return default_allow;
2609 if (!prefix) prefix =
"";
2612 char *cols[128] = { 0 };
2613 char header_name[128] =
"";
2614 int col_count = 0, i = 0;
2615 char *data_copy = NULL;
2617 data_copy = strdup(data);
2621 for (i = 0; i < col_count; i++) {
2622 const char *val = NULL;
2623 switch_snprintf(header_name,
sizeof(header_name),
"%s%s", prefix, cols[i]);
2639 if (!prefix) prefix =
"";
2642 char *cols[128] = { 0 };
2643 char header_name[128] =
"";
2644 int col_count = 0, i = 0;
2645 char *data_copy = NULL;
2647 data_copy = strdup(data);
2651 for (i = 0; i < col_count; i++) {
2652 const char *val = NULL;
2653 switch_snprintf(header_name,
sizeof(header_name),
"%s%s", prefix, cols[i]);
2692 if (!func || thisnp->
func == func) {
2705 thisnp->
func = NULL;
2752 if (!event_channel) {
2801 for (np = head->
node; np; np = np->
next) {
2802 if (np->
func == func) {
2850 for (np = head->
node; np; np = np->
next) {
2855 np->
func(broadcast_channel, json, key,
id);
2890 p = strchr(main_channel,
'.');
2957 ecd->
key = strdup(key);
2976 td = malloc(
sizeof(*td));
3135 if (la->visible != visible || force) {
3147 la->visible = visible;
3181 la->head = la->tail = NULL;
3207 for (np = la->head; np; np = np->
next) {
3239 for (np = la->head; np; np = np->
next) {
3267 *live_arrayP = NULL;
3273 if (la->
refs) done = 1;
3309 for (np = la->aliases; np; np = np->
next) {
3317 la->aliases = np->
next;
3341 for (np = la->aliases; np && np->next; np = np->next) {
3342 if (!strcmp(np->event_channel, event_channel) && !strcmp(np->name, name)) {
3436 for (node = la->head; node; node = node->
next) {
3437 if (node->
pos == idx) {
3461 cJSON *msg, *data = NULL;
3475 la->head = cur->
next;
3494 cur->
pos = la->pos++;
3509 const char *action =
"add";
3510 cJSON *msg = NULL, *data = NULL;
3527 node->
name = strdup(name);
3530 if (index > -1 && index < la->pos && la->head) {
3534 for(np = la->head; np; np = np->
next) {
3542 node->
next = la->head;
3557 node->
pos = la->pos++;
3563 la->tail->
next = node;
3601 la->user_data = user_data;
3607 la->command_handler = command_handler;
3613 const char *context = NULL, *name = NULL;
3626 if (!strcasecmp(command,
"bootstrap")) {
struct apr_queue_t switch_queue_t
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)
cJSON * cJSON_CreateObject(void)
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)
cJSON * cJSON_CreateNumber(double num)
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.
const char * switch_priority_name(switch_priority_t priority)
Return a printable name of a switch_priority_t.
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)
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)
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
#define switch_xml_add_child_d(xml, name, off)
wrapper for switch_xml_add_child() that strdup()s name
Representation of an event.
int switch_event_check_permission_list(switch_event_t *list, const char *name)
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 struct @4 event_channel_manager
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.
void cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem)
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
int cJSON_GetArraySize(cJSON *array)
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)
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)
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_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,...)
static void unsub_all_switch_event_channel(void)
struct switch_runtime runtime
static int switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
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)
static int EVENT_CHANNEL_DISPATCH_THREAD_STARTING
void(* switch_live_array_command_handler_t)(switch_live_array_t *la, const char *cmd, const char *sessid, cJSON *jla, void *user_data)
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_thread_join(switch_status_t *retval, switch_thread_t *thd)
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.
#define SWITCH_UINT64_T_FMT
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 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)
cJSON * cJSON_GetArrayItem(cJSON *array, int item)
void cJSON_AddItemToArray(cJSON *array, cJSON *item)
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)
struct apr_thread_rwlock_t switch_thread_rwlock_t
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,...)
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)
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 cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item)
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)
cJSON * cJSON_GetObjectItem(const cJSON *object, const char *string)
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 uint32_t switch_event_channel_unsub_channel(switch_event_channel_func_t func, const char *event_channel)
static int EVENT_CHANNEL_DISPATCH_THREAD_COUNT
cJSON * cJSON_CreateString(const char *string)
void(* switch_event_callback_t)(switch_event_t *)
#define switch_str_nil(s)
Make a null string a blank string instead.
switch_event_channel_id_t channel_id
static switch_memory_pool_t * THRUNTIME_POOL
static uint64_t EVENT_SEQUENCE_NR
switch_bool_t switch_live_array_add_alias(switch_live_array_t *la, const char *event_channel, const char *name)
void(* switch_event_channel_func_t)(const char *event_channel, cJSON *json, const char *key, switch_event_channel_id_t id)
switch_stream_handle_write_function_t write_function
struct apr_thread_mutex_t switch_mutex_t
switch_status_t switch_live_array_bootstrap(switch_live_array_t *la, const char *sessid, switch_event_channel_id_t channel_id)
switch_thread_rwlock_t * rwlock
switch_status_t
Common return values.
switch_event_channel_sub_node_t * tail
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)
cJSON * cJSON_Parse(const char *value)
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)
struct apr_thread_t switch_thread_t
#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)
#define switch_xml_set_txt_d(xml, txt)
wrapper for switch_xml_set_txt() that strdup()s txt \ sets the character content for the given tag an...
A registered custom event subclass.
void switch_live_array_unlock(switch_live_array_t *la)
switch_status_t switch_event_channel_bind(const char *event_channel, switch_event_channel_func_t func, switch_event_channel_id_t *id)
#define switch_event_get_header(_e, _h)
switch_status_t switch_live_array_del(switch_live_array_t *la, const char *name)
cJSON * cJSON_Duplicate(cJSON *item, int recurse)
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)
cJSON * cJSON_CreateArray(void)
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)
struct apr_pool_t switch_memory_pool_t
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_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.
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 ...
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.
uint32_t switch_event_channel_unbind(const char *event_channel, switch_event_channel_func_t func)
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)
static uint32_t switch_event_channel_unsub_head(switch_event_channel_func_t func, switch_event_channel_sub_node_head_t *head)
switch_status_t switch_event_serialize(switch_event_t *event, char **str, switch_bool_t encode)
void cJSON_Delete(cJSON *c)
#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)
char * cJSON_PrintUnformatted(cJSON *item)
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.