mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-11 20:17:05 +00:00
FS-10025: fix global symbol scope issue causing modules to use another modules global pointer
This commit is contained in:
1 parent
c125ab7315
commit
a3ee7595bb
31 files changed
+526
-528
No files matched your search
@@ -202,21 +202,21 @@ void ei_init_ref(ei_cnode * ec, erlang_ref * ref)
|
||||
memset(ref, 0, sizeof(*ref)); /* zero out the struct */
|
||||
snprintf(ref->node, MAXATOMLEN, "%s", ec->thisnodename);
|
||||
|
||||
switch_mutex_lock(globals.ref_mutex);
|
||||
globals.reference0++;
|
||||
if (globals.reference0 >= MAX_REFERENCE) {
|
||||
globals.reference0 = 0;
|
||||
globals.reference1++;
|
||||
if (globals.reference1 == 0) {
|
||||
globals.reference2++;
|
||||
switch_mutex_lock(mod_erlang_event_globals.ref_mutex);
|
||||
mod_erlang_event_globals.reference0++;
|
||||
if (mod_erlang_event_globals.reference0 >= MAX_REFERENCE) {
|
||||
mod_erlang_event_globals.reference0 = 0;
|
||||
mod_erlang_event_globals.reference1++;
|
||||
if (mod_erlang_event_globals.reference1 == 0) {
|
||||
mod_erlang_event_globals.reference2++;
|
||||
}
|
||||
}
|
||||
|
||||
ref->n[0] = globals.reference0;
|
||||
ref->n[1] = globals.reference1;
|
||||
ref->n[2] = globals.reference2;
|
||||
ref->n[0] = mod_erlang_event_globals.reference0;
|
||||
ref->n[1] = mod_erlang_event_globals.reference1;
|
||||
ref->n[2] = mod_erlang_event_globals.reference2;
|
||||
|
||||
switch_mutex_unlock(globals.ref_mutex);
|
||||
switch_mutex_unlock(mod_erlang_event_globals.ref_mutex);
|
||||
|
||||
ref->creation = 1; /* why is this 1 */
|
||||
ref->len = 3; /* why is this 3 */
|
||||
|
||||
@@ -958,7 +958,7 @@ static switch_status_t handle_msg_bind(listener_t *listener, erlang_msg * msg, e
|
||||
binding->process.pid = msg->from;
|
||||
binding->listener = listener;
|
||||
|
||||
switch_thread_rwlock_wrlock(globals.bindings_rwlock);
|
||||
switch_thread_rwlock_wrlock(mod_erlang_event_globals.bindings_rwlock);
|
||||
|
||||
for (ptr = bindings.head; ptr && ptr->next; ptr = ptr->next);
|
||||
|
||||
@@ -969,7 +969,7 @@ static switch_status_t handle_msg_bind(listener_t *listener, erlang_msg * msg, e
|
||||
}
|
||||
|
||||
switch_xml_set_binding_sections(bindings.search_binding, switch_xml_get_binding_sections(bindings.search_binding) | section);
|
||||
switch_thread_rwlock_unlock(globals.bindings_rwlock);
|
||||
switch_thread_rwlock_unlock(mod_erlang_event_globals.bindings_rwlock);
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "sections %d\n", switch_xml_get_binding_sections(bindings.search_binding));
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_l
|
||||
{
|
||||
listener_t *l;
|
||||
|
||||
switch_thread_rwlock_rdlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_rdlock(mod_erlang_event_globals.listener_rwlock);
|
||||
for (l = listen_list.listeners; l; l = l->next) {
|
||||
|
||||
if (switch_test_flag(l, LFLAG_LOG) && l->level >= node->level) {
|
||||
@@ -87,7 +87,7 @@ static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_l
|
||||
}
|
||||
|
||||
}
|
||||
switch_thread_rwlock_unlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_unlock(mod_erlang_event_globals.listener_rwlock);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
@@ -97,7 +97,7 @@ static void remove_binding(listener_t *listener, erlang_pid * pid)
|
||||
{
|
||||
struct erlang_binding *ptr, *lst = NULL;
|
||||
|
||||
switch_thread_rwlock_wrlock(globals.bindings_rwlock);
|
||||
switch_thread_rwlock_wrlock(mod_erlang_event_globals.bindings_rwlock);
|
||||
|
||||
switch_xml_set_binding_sections(bindings.search_binding, SWITCH_XML_SECTION_MAX);
|
||||
|
||||
@@ -124,7 +124,7 @@ static void remove_binding(listener_t *listener, erlang_pid * pid)
|
||||
}
|
||||
}
|
||||
|
||||
switch_thread_rwlock_unlock(globals.bindings_rwlock);
|
||||
switch_thread_rwlock_unlock(mod_erlang_event_globals.bindings_rwlock);
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ static void event_handler(switch_event_t *event)
|
||||
return;
|
||||
}
|
||||
|
||||
switch_thread_rwlock_rdlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_rdlock(mod_erlang_event_globals.listener_rwlock);
|
||||
|
||||
lp = listen_list.listeners;
|
||||
|
||||
@@ -304,7 +304,7 @@ static void event_handler(switch_event_t *event)
|
||||
}
|
||||
|
||||
}
|
||||
switch_thread_rwlock_unlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_unlock(mod_erlang_event_globals.listener_rwlock);
|
||||
}
|
||||
|
||||
|
||||
@@ -322,10 +322,10 @@ static void close_socket(switch_socket_t ** sock)
|
||||
static void add_listener(listener_t *listener)
|
||||
{
|
||||
/* add me to the listeners so I get events */
|
||||
switch_thread_rwlock_wrlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_wrlock(mod_erlang_event_globals.listener_rwlock);
|
||||
listener->next = listen_list.listeners;
|
||||
listen_list.listeners = listener;
|
||||
switch_thread_rwlock_unlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_unlock(mod_erlang_event_globals.listener_rwlock);
|
||||
}
|
||||
|
||||
|
||||
@@ -333,7 +333,7 @@ static void remove_listener(listener_t *listener)
|
||||
{
|
||||
listener_t *l, *last = NULL;
|
||||
|
||||
switch_thread_rwlock_wrlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_wrlock(mod_erlang_event_globals.listener_rwlock);
|
||||
for (l = listen_list.listeners; l; l = l->next) {
|
||||
if (l == listener) {
|
||||
if (last) {
|
||||
@@ -344,7 +344,7 @@ static void remove_listener(listener_t *listener)
|
||||
}
|
||||
last = l;
|
||||
}
|
||||
switch_thread_rwlock_unlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_unlock(mod_erlang_event_globals.listener_rwlock);
|
||||
}
|
||||
|
||||
/* Search for a listener already talking to the specified node and lock for reading*/
|
||||
@@ -352,14 +352,14 @@ static listener_t *find_listener(char *nodename)
|
||||
{
|
||||
listener_t *l = NULL;
|
||||
|
||||
switch_thread_rwlock_rdlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_rdlock(mod_erlang_event_globals.listener_rwlock);
|
||||
for (l = listen_list.listeners; l; l = l->next) {
|
||||
if (!strncmp(nodename, l->peer_nodename, MAXNODELEN)) {
|
||||
switch_thread_rwlock_rdlock(l->rwlock);
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch_thread_rwlock_unlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_unlock(mod_erlang_event_globals.listener_rwlock);
|
||||
return l;
|
||||
}
|
||||
|
||||
@@ -465,7 +465,7 @@ static fetch_reply_t *new_fetch_reply(const char *uuid_str)
|
||||
reply->reply = NULL;
|
||||
|
||||
switch_mutex_lock(reply->mutex);
|
||||
switch_core_hash_insert_locked(globals.fetch_reply_hash, uuid_str, reply, globals.fetch_reply_mutex);
|
||||
switch_core_hash_insert_locked(mod_erlang_event_globals.fetch_reply_hash, uuid_str, reply, mod_erlang_event_globals.fetch_reply_mutex);
|
||||
reply->state = reply_waiting;
|
||||
|
||||
return reply;
|
||||
@@ -473,7 +473,7 @@ static fetch_reply_t *new_fetch_reply(const char *uuid_str)
|
||||
|
||||
static void destroy_fetch_reply(fetch_reply_t *reply)
|
||||
{
|
||||
switch_core_hash_delete_locked(globals.fetch_reply_hash, reply->uuid_str, globals.fetch_reply_mutex);
|
||||
switch_core_hash_delete_locked(mod_erlang_event_globals.fetch_reply_hash, reply->uuid_str, mod_erlang_event_globals.fetch_reply_mutex);
|
||||
/* lock so nothing can have it while we delete it */
|
||||
switch_mutex_lock(reply->mutex);
|
||||
switch_mutex_unlock(reply->mutex);
|
||||
@@ -488,13 +488,13 @@ fetch_reply_t *find_fetch_reply(const char *uuid)
|
||||
{
|
||||
fetch_reply_t *reply = NULL;
|
||||
|
||||
switch_mutex_lock(globals.fetch_reply_mutex);
|
||||
if ((reply = switch_core_hash_find(globals.fetch_reply_hash, uuid))) {
|
||||
switch_mutex_lock(mod_erlang_event_globals.fetch_reply_mutex);
|
||||
if ((reply = switch_core_hash_find(mod_erlang_event_globals.fetch_reply_hash, uuid))) {
|
||||
if (switch_mutex_lock(reply->mutex) != SWITCH_STATUS_SUCCESS) {
|
||||
reply = NULL;
|
||||
}
|
||||
}
|
||||
switch_mutex_unlock(globals.fetch_reply_mutex);
|
||||
switch_mutex_unlock(mod_erlang_event_globals.fetch_reply_mutex);
|
||||
return reply;
|
||||
}
|
||||
|
||||
@@ -530,10 +530,10 @@ static switch_xml_t erlang_fetch(const char *sectionstr, const char *tag_name, c
|
||||
|
||||
section = switch_xml_parse_section_string((char *) sectionstr);
|
||||
|
||||
switch_thread_rwlock_rdlock(globals.bindings_rwlock);
|
||||
switch_thread_rwlock_rdlock(mod_erlang_event_globals.bindings_rwlock);
|
||||
|
||||
/* Keep the listener from getting pulled out from under us */
|
||||
switch_thread_rwlock_rdlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_rdlock(mod_erlang_event_globals.listener_rwlock);
|
||||
|
||||
for (ptr = bindings.head; ptr; ptr = ptr->next) {
|
||||
/* If we got listener_rwlock while a listner thread was dying after removing the listener
|
||||
@@ -570,8 +570,8 @@ static switch_xml_t erlang_fetch(const char *sectionstr, const char *tag_name, c
|
||||
switch_mutex_unlock(ptr->listener->sock_mutex);
|
||||
}
|
||||
|
||||
switch_thread_rwlock_unlock(globals.bindings_rwlock);
|
||||
switch_thread_rwlock_unlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_unlock(mod_erlang_event_globals.bindings_rwlock);
|
||||
switch_thread_rwlock_unlock(mod_erlang_event_globals.listener_rwlock);
|
||||
|
||||
ei_x_free(&buf);
|
||||
|
||||
@@ -612,7 +612,7 @@ static switch_xml_t erlang_fetch(const char *sectionstr, const char *tag_name, c
|
||||
|
||||
ei_decode_string_or_binary(rep->buff, &rep->index, size, xmlstr);
|
||||
|
||||
if (globals.debug) {
|
||||
if (mod_erlang_event_globals.debug) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "got data %s after %d milliseconds from %s for %s!\n", xmlstr, (int) (switch_micro_time_now() - now) / 1000, p->winner, uuid_str);
|
||||
}
|
||||
|
||||
@@ -1124,9 +1124,9 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
|
||||
{
|
||||
listener_t *listener = (listener_t *) obj;
|
||||
|
||||
switch_mutex_lock(globals.listener_count_mutex);
|
||||
switch_mutex_lock(mod_erlang_event_globals.listener_count_mutex);
|
||||
prefs.threads++;
|
||||
switch_mutex_unlock(globals.listener_count_mutex);
|
||||
switch_mutex_unlock(mod_erlang_event_globals.listener_count_mutex);
|
||||
|
||||
switch_assert(listener != NULL);
|
||||
|
||||
@@ -1146,9 +1146,9 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj)
|
||||
remove_listener(listener);
|
||||
destroy_listener(listener);
|
||||
|
||||
switch_mutex_lock(globals.listener_count_mutex);
|
||||
switch_mutex_lock(mod_erlang_event_globals.listener_count_mutex);
|
||||
prefs.threads--;
|
||||
switch_mutex_unlock(globals.listener_count_mutex);
|
||||
switch_mutex_unlock(mod_erlang_event_globals.listener_count_mutex);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -1794,7 +1794,7 @@ SWITCH_STANDARD_API(erlang_cmd)
|
||||
if (!strcasecmp(argv[0], "listeners")) {
|
||||
|
||||
listener_t *l;
|
||||
switch_thread_rwlock_rdlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_rdlock(mod_erlang_event_globals.listener_rwlock);
|
||||
|
||||
if (listen_list.listeners) {
|
||||
for (l = listen_list.listeners; l; l = l->next) {
|
||||
@@ -1808,12 +1808,12 @@ SWITCH_STANDARD_API(erlang_cmd)
|
||||
stream->write_function(stream, "No active listeners\n");
|
||||
}
|
||||
|
||||
switch_thread_rwlock_unlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_unlock(mod_erlang_event_globals.listener_rwlock);
|
||||
} else if (!strcasecmp(argv[0], "sessions") && argc == 2) {
|
||||
listener_t *l;
|
||||
int found = 0;
|
||||
|
||||
switch_thread_rwlock_rdlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_rdlock(mod_erlang_event_globals.listener_rwlock);
|
||||
for (l = listen_list.listeners; l; l = l->next) {
|
||||
if (!strcasecmp(l->peer_nodename, argv[1])) {
|
||||
session_elem_t *sp;
|
||||
@@ -1839,7 +1839,7 @@ SWITCH_STANDARD_API(erlang_cmd)
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch_thread_rwlock_unlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_unlock(mod_erlang_event_globals.listener_rwlock);
|
||||
|
||||
if (!found)
|
||||
stream->write_function(stream, "Could not find a listener for %s\n", argv[1]);
|
||||
@@ -1847,7 +1847,7 @@ SWITCH_STANDARD_API(erlang_cmd)
|
||||
} else if (!strcasecmp(argv[0], "handlers")) {
|
||||
listener_t *l;
|
||||
|
||||
switch_thread_rwlock_rdlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_rdlock(mod_erlang_event_globals.listener_rwlock);
|
||||
|
||||
if (listen_list.listeners) {
|
||||
for (l = listen_list.listeners; l; l = l->next) {
|
||||
@@ -1875,12 +1875,12 @@ SWITCH_STANDARD_API(erlang_cmd)
|
||||
stream->write_function(stream, "No active handlers\n");
|
||||
}
|
||||
|
||||
switch_thread_rwlock_unlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_unlock(mod_erlang_event_globals.listener_rwlock);
|
||||
|
||||
} else if (!strcasecmp(argv[0], "bindings")) {
|
||||
int found = 0;
|
||||
struct erlang_binding *ptr;
|
||||
switch_thread_rwlock_rdlock(globals.bindings_rwlock);
|
||||
switch_thread_rwlock_rdlock(mod_erlang_event_globals.bindings_rwlock);
|
||||
|
||||
for (ptr = bindings.head; ptr; ptr = ptr->next) {
|
||||
|
||||
@@ -1904,7 +1904,7 @@ SWITCH_STANDARD_API(erlang_cmd)
|
||||
found++;
|
||||
}
|
||||
|
||||
switch_thread_rwlock_unlock(globals.bindings_rwlock);
|
||||
switch_thread_rwlock_unlock(mod_erlang_event_globals.bindings_rwlock);
|
||||
|
||||
if (!found) {
|
||||
stream->write_function(stream, "No bindings\n");
|
||||
@@ -1913,12 +1913,12 @@ SWITCH_STANDARD_API(erlang_cmd)
|
||||
} else if (!strcasecmp(argv[0], "debug")) {
|
||||
if (argc == 2) {
|
||||
if (!strcasecmp(argv[1], "on")) {
|
||||
globals.debug = 1;
|
||||
mod_erlang_event_globals.debug = 1;
|
||||
} else {
|
||||
globals.debug = 0;
|
||||
mod_erlang_event_globals.debug = 0;
|
||||
}
|
||||
}
|
||||
stream->write_function(stream, "+OK debug %s\n", globals.debug ? "on" : "off");
|
||||
stream->write_function(stream, "+OK debug %s\n", mod_erlang_event_globals.debug ? "on" : "off");
|
||||
|
||||
} else {
|
||||
stream->write_function(stream, usage_string);
|
||||
@@ -1939,21 +1939,21 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_erlang_event_load)
|
||||
|
||||
memset(&prefs, 0, sizeof(prefs));
|
||||
|
||||
switch_thread_rwlock_create(&globals.listener_rwlock, pool);
|
||||
switch_thread_rwlock_create(&globals.bindings_rwlock, pool);
|
||||
switch_mutex_init(&globals.fetch_reply_mutex, SWITCH_MUTEX_DEFAULT, pool);
|
||||
switch_mutex_init(&globals.listener_count_mutex, SWITCH_MUTEX_UNNESTED, pool);
|
||||
switch_mutex_init(&globals.listener_mutex, SWITCH_MUTEX_NESTED, pool);
|
||||
switch_core_hash_init(&globals.fetch_reply_hash);
|
||||
switch_thread_rwlock_create(&mod_erlang_event_globals.listener_rwlock, pool);
|
||||
switch_thread_rwlock_create(&mod_erlang_event_globals.bindings_rwlock, pool);
|
||||
switch_mutex_init(&mod_erlang_event_globals.fetch_reply_mutex, SWITCH_MUTEX_DEFAULT, pool);
|
||||
switch_mutex_init(&mod_erlang_event_globals.listener_count_mutex, SWITCH_MUTEX_UNNESTED, pool);
|
||||
switch_mutex_init(&mod_erlang_event_globals.listener_mutex, SWITCH_MUTEX_NESTED, pool);
|
||||
switch_core_hash_init(&mod_erlang_event_globals.fetch_reply_hash);
|
||||
|
||||
/* intialize the unique reference stuff */
|
||||
switch_mutex_init(&listen_list.sock_mutex, SWITCH_MUTEX_NESTED, pool);
|
||||
switch_mutex_init(&globals.ref_mutex, SWITCH_MUTEX_NESTED, pool);
|
||||
globals.reference0 = 0;
|
||||
globals.reference1 = 0;
|
||||
globals.reference2 = 0;
|
||||
switch_mutex_init(&mod_erlang_event_globals.ref_mutex, SWITCH_MUTEX_NESTED, pool);
|
||||
mod_erlang_event_globals.reference0 = 0;
|
||||
mod_erlang_event_globals.reference1 = 0;
|
||||
mod_erlang_event_globals.reference2 = 0;
|
||||
|
||||
if (switch_event_bind_removable(modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL, &globals.node) != SWITCH_STATUS_SUCCESS) {
|
||||
if (switch_event_bind_removable(modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL, &mod_erlang_event_globals.node) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind to all events!\n");
|
||||
close_socket(&listen_list.sock);
|
||||
return SWITCH_STATUS_GENERR;
|
||||
@@ -2181,10 +2181,10 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_erlang_event_shutdown)
|
||||
}
|
||||
}
|
||||
|
||||
switch_event_unbind(&globals.node);
|
||||
switch_event_unbind(&mod_erlang_event_globals.node);
|
||||
switch_xml_unbind_search_function_ptr(erlang_fetch);
|
||||
|
||||
switch_thread_rwlock_wrlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_wrlock(mod_erlang_event_globals.listener_rwlock);
|
||||
|
||||
for (l = listen_list.listeners; l; l = l->next) {
|
||||
switch_os_sock_put(&sock, &l->sockdes, l->pool);
|
||||
@@ -2196,7 +2196,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_erlang_event_shutdown)
|
||||
WSACleanup();
|
||||
#endif
|
||||
|
||||
switch_thread_rwlock_unlock(globals.listener_rwlock);
|
||||
switch_thread_rwlock_unlock(mod_erlang_event_globals.listener_rwlock);
|
||||
|
||||
switch_sleep(1500000); /* sleep for 1.5 seconds */
|
||||
|
||||
|
||||
@@ -222,12 +222,12 @@ typedef struct prefs_struct prefs_t;
|
||||
|
||||
/* shared globals */
|
||||
#ifdef DEFINE_GLOBALS
|
||||
globals_t globals;
|
||||
globals_t mod_erlang_event_globals;
|
||||
listen_list_t listen_list;
|
||||
bindings_t bindings;
|
||||
prefs_t prefs;
|
||||
#else
|
||||
extern globals_t globals;
|
||||
extern globals_t mod_erlang_event_globals;
|
||||
extern listen_list_t listen_list;
|
||||
extern bindings_t bindings;
|
||||
extern prefs_t prefs;
|
||||
|
||||
@@ -73,11 +73,11 @@ static switch_status_t kazoo_event_dup(switch_event_t **clone, switch_event_t *e
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strncmp(header->name, globals.kazoo_var_prefix, globals.var_prefix_length)
|
||||
if (strncmp(header->name, kazoo_globals.kazoo_var_prefix, kazoo_globals.var_prefix_length)
|
||||
&& filter
|
||||
&& !switch_core_hash_find(filter, header->name)
|
||||
&& (!globals.send_all_headers)
|
||||
&& (!(globals.send_all_private_headers && is_private_header(header->name)))
|
||||
&& (!kazoo_globals.send_all_headers)
|
||||
&& (!(kazoo_globals.send_all_private_headers && is_private_header(header->name)))
|
||||
)
|
||||
{
|
||||
continue;
|
||||
@@ -107,7 +107,7 @@ static void event_handler(switch_event_t *event) {
|
||||
ei_event_stream_t *event_stream = (ei_event_stream_t *) event->bind_user_data;
|
||||
|
||||
/* if mod_kazoo or the event stream isn't running dont push a new event */
|
||||
if (!switch_test_flag(event_stream, LFLAG_RUNNING) || !switch_test_flag(&globals, LFLAG_RUNNING)) {
|
||||
if (!switch_test_flag(event_stream, LFLAG_RUNNING) || !switch_test_flag(&kazoo_globals, LFLAG_RUNNING)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ static void event_handler(switch_event_t *event) {
|
||||
/* try to clone the event and push it to the event stream thread */
|
||||
/* TODO: someday maybe the filter comes from the event_stream (set during init only)
|
||||
* and is per-binding so we only send headers that a process requests */
|
||||
if (kazoo_event_dup(&clone, event, globals.event_filter) == SWITCH_STATUS_SUCCESS) {
|
||||
if (kazoo_event_dup(&clone, event, kazoo_globals.event_filter) == SWITCH_STATUS_SUCCESS) {
|
||||
if (switch_queue_trypush(event_stream->queue, clone) != SWITCH_STATUS_SUCCESS) {
|
||||
/* if we couldn't place the cloned event into the listeners */
|
||||
/* event queue make sure we destroy it, real good like */
|
||||
@@ -157,9 +157,9 @@ static void *SWITCH_THREAD_FUNC event_stream_loop(switch_thread_t *thread, void
|
||||
char ipbuf[48];
|
||||
const char *ip_addr;
|
||||
void *pop;
|
||||
short event_stream_framing = globals.event_stream_framing;
|
||||
short event_stream_framing = kazoo_globals.event_stream_framing;
|
||||
|
||||
switch_atomic_inc(&globals.threads);
|
||||
switch_atomic_inc(&kazoo_globals.threads);
|
||||
|
||||
switch_assert(event_stream != NULL);
|
||||
|
||||
@@ -172,7 +172,7 @@ static void *SWITCH_THREAD_FUNC event_stream_loop(switch_thread_t *thread, void
|
||||
,(void *)event_stream, ip_addr, port, event_stream->pid.node, event_stream->pid.creation
|
||||
,event_stream->pid.num, event_stream->pid.serial);
|
||||
|
||||
while (switch_test_flag(event_stream, LFLAG_RUNNING) && switch_test_flag(&globals, LFLAG_RUNNING)) {
|
||||
while (switch_test_flag(event_stream, LFLAG_RUNNING) && switch_test_flag(&kazoo_globals, LFLAG_RUNNING)) {
|
||||
const switch_pollfd_t *fds;
|
||||
int32_t numfds;
|
||||
|
||||
@@ -226,9 +226,9 @@ static void *SWITCH_THREAD_FUNC event_stream_loop(switch_thread_t *thread, void
|
||||
short i = event_stream_framing;
|
||||
switch_size_t size = 1;
|
||||
|
||||
if(globals.event_stream_preallocate > 0) {
|
||||
ebuf.buff = malloc(globals.event_stream_preallocate);
|
||||
ebuf.buffsz = globals.event_stream_preallocate;
|
||||
if(kazoo_globals.event_stream_preallocate > 0) {
|
||||
ebuf.buff = malloc(kazoo_globals.event_stream_preallocate);
|
||||
ebuf.buffsz = kazoo_globals.event_stream_preallocate;
|
||||
ebuf.index = 0;
|
||||
if(ebuf.buff == NULL) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not pre-allocate memory for mod_kazoo message\n");
|
||||
@@ -241,7 +241,7 @@ static void *SWITCH_THREAD_FUNC event_stream_loop(switch_thread_t *thread, void
|
||||
|
||||
ei_encode_switch_event(&ebuf, event);
|
||||
|
||||
if (globals.event_stream_preallocate > 0 && ebuf.buffsz > globals.event_stream_preallocate) {
|
||||
if (kazoo_globals.event_stream_preallocate > 0 && ebuf.buffsz > kazoo_globals.event_stream_preallocate) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "increased event stream buffer size to %d\n", ebuf.buffsz);
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ static void *SWITCH_THREAD_FUNC event_stream_loop(switch_thread_t *thread, void
|
||||
/* clean up the memory */
|
||||
switch_core_destroy_memory_pool(&event_stream->pool);
|
||||
|
||||
switch_atomic_dec(&globals.threads);
|
||||
switch_atomic_dec(&kazoo_globals.threads);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ static switch_xml_t fetch_handler(const char *section, const char *tag_name, con
|
||||
|
||||
now = switch_micro_time_now();
|
||||
|
||||
if (!switch_test_flag(&globals, LFLAG_RUNNING)) {
|
||||
if (!switch_test_flag(&kazoo_globals, LFLAG_RUNNING)) {
|
||||
return xml;
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ static switch_xml_t fetch_handler(const char *section, const char *tag_name, con
|
||||
switch_thread_rwlock_rdlock(agent->lock);
|
||||
|
||||
/* serialize access to current, used to round-robin requests */
|
||||
/* TODO: check globals for round-robin boolean or loop all clients */
|
||||
/* TODO: check kazoo_globals for round-robin boolean or loop all clients */
|
||||
switch_mutex_lock(agent->current_client_mutex);
|
||||
if (!agent->current_client) {
|
||||
client = agent->clients;
|
||||
@@ -572,31 +572,31 @@ static switch_status_t handle_api_command_stream(ei_node_t *ei_node, switch_stre
|
||||
}
|
||||
|
||||
switch_status_t bind_fetch_agents() {
|
||||
bind_fetch_agent(SWITCH_XML_SECTION_CONFIG, &globals.config_fetch_binding);
|
||||
bind_fetch_agent(SWITCH_XML_SECTION_DIRECTORY, &globals.directory_fetch_binding);
|
||||
bind_fetch_agent(SWITCH_XML_SECTION_DIALPLAN, &globals.dialplan_fetch_binding);
|
||||
bind_fetch_agent(SWITCH_XML_SECTION_CHATPLAN, &globals.chatplan_fetch_binding);
|
||||
bind_fetch_agent(SWITCH_XML_SECTION_CHANNELS, &globals.channels_fetch_binding);
|
||||
bind_fetch_agent(SWITCH_XML_SECTION_CONFIG, &kazoo_globals.config_fetch_binding);
|
||||
bind_fetch_agent(SWITCH_XML_SECTION_DIRECTORY, &kazoo_globals.directory_fetch_binding);
|
||||
bind_fetch_agent(SWITCH_XML_SECTION_DIALPLAN, &kazoo_globals.dialplan_fetch_binding);
|
||||
bind_fetch_agent(SWITCH_XML_SECTION_CHATPLAN, &kazoo_globals.chatplan_fetch_binding);
|
||||
bind_fetch_agent(SWITCH_XML_SECTION_CHANNELS, &kazoo_globals.channels_fetch_binding);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t unbind_fetch_agents() {
|
||||
unbind_fetch_agent(&globals.config_fetch_binding);
|
||||
unbind_fetch_agent(&globals.directory_fetch_binding);
|
||||
unbind_fetch_agent(&globals.dialplan_fetch_binding);
|
||||
unbind_fetch_agent(&globals.chatplan_fetch_binding);
|
||||
unbind_fetch_agent(&globals.channels_fetch_binding);
|
||||
unbind_fetch_agent(&kazoo_globals.config_fetch_binding);
|
||||
unbind_fetch_agent(&kazoo_globals.directory_fetch_binding);
|
||||
unbind_fetch_agent(&kazoo_globals.dialplan_fetch_binding);
|
||||
unbind_fetch_agent(&kazoo_globals.chatplan_fetch_binding);
|
||||
unbind_fetch_agent(&kazoo_globals.channels_fetch_binding);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t remove_xml_clients(ei_node_t *ei_node) {
|
||||
remove_xml_client(ei_node, globals.config_fetch_binding);
|
||||
remove_xml_client(ei_node, globals.directory_fetch_binding);
|
||||
remove_xml_client(ei_node, globals.dialplan_fetch_binding);
|
||||
remove_xml_client(ei_node, globals.chatplan_fetch_binding);
|
||||
remove_xml_client(ei_node, globals.channels_fetch_binding);
|
||||
remove_xml_client(ei_node, kazoo_globals.config_fetch_binding);
|
||||
remove_xml_client(ei_node, kazoo_globals.directory_fetch_binding);
|
||||
remove_xml_client(ei_node, kazoo_globals.dialplan_fetch_binding);
|
||||
remove_xml_client(ei_node, kazoo_globals.chatplan_fetch_binding);
|
||||
remove_xml_client(ei_node, kazoo_globals.channels_fetch_binding);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
@@ -644,17 +644,17 @@ switch_status_t add_fetch_handler(ei_node_t *ei_node, erlang_pid *from, switch_x
|
||||
|
||||
switch_thread_rwlock_unlock(agent->lock);
|
||||
|
||||
ei_link(ei_node, ei_self(&globals.ei_cnode), from);
|
||||
ei_link(ei_node, ei_self(&kazoo_globals.ei_cnode), from);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
switch_status_t remove_fetch_handlers(ei_node_t *ei_node, erlang_pid *from) {
|
||||
remove_fetch_handler(ei_node, from, globals.config_fetch_binding);
|
||||
remove_fetch_handler(ei_node, from, globals.directory_fetch_binding);
|
||||
remove_fetch_handler(ei_node, from, globals.dialplan_fetch_binding);
|
||||
remove_fetch_handler(ei_node, from, globals.chatplan_fetch_binding);
|
||||
remove_fetch_handler(ei_node, from, globals.channels_fetch_binding);
|
||||
remove_fetch_handler(ei_node, from, kazoo_globals.config_fetch_binding);
|
||||
remove_fetch_handler(ei_node, from, kazoo_globals.directory_fetch_binding);
|
||||
remove_fetch_handler(ei_node, from, kazoo_globals.dialplan_fetch_binding);
|
||||
remove_fetch_handler(ei_node, from, kazoo_globals.chatplan_fetch_binding);
|
||||
remove_fetch_handler(ei_node, from, kazoo_globals.channels_fetch_binding);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
@@ -686,11 +686,11 @@ switch_status_t fetch_reply(char *uuid_str, char *xml_str, switch_xml_binding_t
|
||||
}
|
||||
|
||||
switch_status_t handle_api_command_streams(ei_node_t *ei_node, switch_stream_handle_t *stream) {
|
||||
handle_api_command_stream(ei_node, stream, globals.config_fetch_binding);
|
||||
handle_api_command_stream(ei_node, stream, globals.directory_fetch_binding);
|
||||
handle_api_command_stream(ei_node, stream, globals.dialplan_fetch_binding);
|
||||
handle_api_command_stream(ei_node, stream, globals.chatplan_fetch_binding);
|
||||
handle_api_command_stream(ei_node, stream, globals.channels_fetch_binding);
|
||||
handle_api_command_stream(ei_node, stream, kazoo_globals.config_fetch_binding);
|
||||
handle_api_command_stream(ei_node, stream, kazoo_globals.directory_fetch_binding);
|
||||
handle_api_command_stream(ei_node, stream, kazoo_globals.dialplan_fetch_binding);
|
||||
handle_api_command_stream(ei_node, stream, kazoo_globals.chatplan_fetch_binding);
|
||||
handle_api_command_stream(ei_node, stream, kazoo_globals.channels_fetch_binding);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -142,16 +142,16 @@ static void destroy_node_handler(ei_node_t *ei_node) {
|
||||
}
|
||||
|
||||
static switch_status_t add_to_ei_nodes(ei_node_t *this_ei_node) {
|
||||
switch_thread_rwlock_wrlock(globals.ei_nodes_lock);
|
||||
switch_thread_rwlock_wrlock(kazoo_globals.ei_nodes_lock);
|
||||
|
||||
if (!globals.ei_nodes) {
|
||||
globals.ei_nodes = this_ei_node;
|
||||
if (!kazoo_globals.ei_nodes) {
|
||||
kazoo_globals.ei_nodes = this_ei_node;
|
||||
} else {
|
||||
this_ei_node->next = globals.ei_nodes;
|
||||
globals.ei_nodes = this_ei_node;
|
||||
this_ei_node->next = kazoo_globals.ei_nodes;
|
||||
kazoo_globals.ei_nodes = this_ei_node;
|
||||
}
|
||||
|
||||
switch_thread_rwlock_unlock(globals.ei_nodes_lock);
|
||||
switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
@@ -160,10 +160,10 @@ static switch_status_t remove_from_ei_nodes(ei_node_t *this_ei_node) {
|
||||
ei_node_t *ei_node, *prev = NULL;
|
||||
int found = 0;
|
||||
|
||||
switch_thread_rwlock_wrlock(globals.ei_nodes_lock);
|
||||
switch_thread_rwlock_wrlock(kazoo_globals.ei_nodes_lock);
|
||||
|
||||
/* try to find the event bindings list for the requestor */
|
||||
ei_node = globals.ei_nodes;
|
||||
ei_node = kazoo_globals.ei_nodes;
|
||||
while(ei_node != NULL) {
|
||||
if (ei_node == this_ei_node) {
|
||||
found = 1;
|
||||
@@ -176,13 +176,13 @@ static switch_status_t remove_from_ei_nodes(ei_node_t *this_ei_node) {
|
||||
|
||||
if (found) {
|
||||
if (!prev) {
|
||||
globals.ei_nodes = this_ei_node->next;
|
||||
kazoo_globals.ei_nodes = this_ei_node->next;
|
||||
} else {
|
||||
prev->next = ei_node->next;
|
||||
}
|
||||
}
|
||||
|
||||
switch_thread_rwlock_unlock(globals.ei_nodes_lock);
|
||||
switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
@@ -301,7 +301,7 @@ static void *SWITCH_THREAD_FUNC bgapi3_exec(switch_thread_t *thread, void *obj)
|
||||
switch_malloc(send_msg, sizeof(*send_msg));
|
||||
memcpy(&send_msg->pid, &acs->pid, sizeof(erlang_pid));
|
||||
|
||||
if(!switch_test_flag(ei_node, LFLAG_RUNNING) || !switch_test_flag(&globals, LFLAG_RUNNING)) {
|
||||
if(!switch_test_flag(ei_node, LFLAG_RUNNING) || !switch_test_flag(&kazoo_globals, LFLAG_RUNNING)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring command while shuting down\n");
|
||||
switch_atomic_dec(&ei_node->pending_bgapi);
|
||||
return NULL;
|
||||
@@ -351,7 +351,7 @@ static void *SWITCH_THREAD_FUNC bgapi4_exec(switch_thread_t *thread, void *obj)
|
||||
ei_send_msg_t *send_msg;
|
||||
switch_stream_handle_t stream = { 0 };
|
||||
|
||||
if(!switch_test_flag(ei_node, LFLAG_RUNNING) || !switch_test_flag(&globals, LFLAG_RUNNING)) {
|
||||
if(!switch_test_flag(ei_node, LFLAG_RUNNING) || !switch_test_flag(&kazoo_globals, LFLAG_RUNNING)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring command while shuting down\n");
|
||||
switch_atomic_dec(&ei_node->pending_bgapi);
|
||||
return NULL;
|
||||
@@ -544,7 +544,7 @@ static switch_status_t handle_request_exit(ei_node_t *ei_node, erlang_pid *pid,
|
||||
}
|
||||
|
||||
static switch_status_t handle_request_link(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) {
|
||||
ei_link(ei_node, ei_self(&globals.ei_cnode), pid);
|
||||
ei_link(ei_node, ei_self(&kazoo_globals.ei_cnode), pid);
|
||||
|
||||
return erlang_response_ok(rbuf);
|
||||
}
|
||||
@@ -674,21 +674,21 @@ static switch_status_t handle_request_bind(ei_node_t *ei_node, erlang_pid *pid,
|
||||
|
||||
switch(section) {
|
||||
case SWITCH_XML_SECTION_CONFIG:
|
||||
add_fetch_handler(ei_node, pid, globals.config_fetch_binding);
|
||||
if(!globals.config_filters_fetched)
|
||||
add_fetch_handler(ei_node, pid, kazoo_globals.config_fetch_binding);
|
||||
if(!kazoo_globals.config_filters_fetched)
|
||||
fetch_config_filters();
|
||||
break;
|
||||
case SWITCH_XML_SECTION_DIRECTORY:
|
||||
add_fetch_handler(ei_node, pid, globals.directory_fetch_binding);
|
||||
add_fetch_handler(ei_node, pid, kazoo_globals.directory_fetch_binding);
|
||||
break;
|
||||
case SWITCH_XML_SECTION_DIALPLAN:
|
||||
add_fetch_handler(ei_node, pid, globals.dialplan_fetch_binding);
|
||||
add_fetch_handler(ei_node, pid, kazoo_globals.dialplan_fetch_binding);
|
||||
break;
|
||||
case SWITCH_XML_SECTION_CHATPLAN:
|
||||
add_fetch_handler(ei_node, pid, globals.chatplan_fetch_binding);
|
||||
add_fetch_handler(ei_node, pid, kazoo_globals.chatplan_fetch_binding);
|
||||
break;
|
||||
case SWITCH_XML_SECTION_CHANNELS:
|
||||
add_fetch_handler(ei_node, pid, globals.channels_fetch_binding);
|
||||
add_fetch_handler(ei_node, pid, kazoo_globals.channels_fetch_binding);
|
||||
break;
|
||||
default:
|
||||
return erlang_response_badarg(rbuf);
|
||||
@@ -701,7 +701,7 @@ static switch_status_t handle_request_getpid(ei_node_t *ei_node, erlang_pid *pid
|
||||
if (rbuf) {
|
||||
ei_x_encode_tuple_header(rbuf, 2);
|
||||
ei_x_encode_atom(rbuf, "ok");
|
||||
ei_x_encode_pid(rbuf, ei_self(&globals.ei_cnode));
|
||||
ei_x_encode_pid(rbuf, ei_self(&kazoo_globals.ei_cnode));
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
@@ -870,7 +870,7 @@ static switch_status_t handle_request_event(ei_node_t *ei_node, erlang_pid *pid,
|
||||
if (!(event_stream = find_event_stream(ei_node->event_streams, pid))) {
|
||||
event_stream = new_event_stream(&ei_node->event_streams, pid);
|
||||
/* ensure we are notified if the requesting processes dies so we can clean up */
|
||||
ei_link(ei_node, ei_self(&globals.ei_cnode), pid);
|
||||
ei_link(ei_node, ei_self(&kazoo_globals.ei_cnode), pid);
|
||||
}
|
||||
|
||||
for (int i = 1; i <= length; i++) {
|
||||
@@ -947,19 +947,19 @@ static switch_status_t handle_request_fetch_reply(ei_node_t *ei_node, erlang_pid
|
||||
|
||||
switch(section) {
|
||||
case SWITCH_XML_SECTION_CONFIG:
|
||||
result = fetch_reply(uuid_str, xml_str, globals.config_fetch_binding);
|
||||
result = fetch_reply(uuid_str, xml_str, kazoo_globals.config_fetch_binding);
|
||||
break;
|
||||
case SWITCH_XML_SECTION_DIRECTORY:
|
||||
result = fetch_reply(uuid_str, xml_str, globals.directory_fetch_binding);
|
||||
result = fetch_reply(uuid_str, xml_str, kazoo_globals.directory_fetch_binding);
|
||||
break;
|
||||
case SWITCH_XML_SECTION_DIALPLAN:
|
||||
result = fetch_reply(uuid_str, xml_str, globals.dialplan_fetch_binding);
|
||||
result = fetch_reply(uuid_str, xml_str, kazoo_globals.dialplan_fetch_binding);
|
||||
break;
|
||||
case SWITCH_XML_SECTION_CHATPLAN:
|
||||
result = fetch_reply(uuid_str, xml_str, globals.chatplan_fetch_binding);
|
||||
result = fetch_reply(uuid_str, xml_str, kazoo_globals.chatplan_fetch_binding);
|
||||
break;
|
||||
case SWITCH_XML_SECTION_CHANNELS:
|
||||
result = fetch_reply(uuid_str, xml_str, globals.channels_fetch_binding);
|
||||
result = fetch_reply(uuid_str, xml_str, kazoo_globals.channels_fetch_binding);
|
||||
break;
|
||||
default:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Recieved fetch reply for an unknown configuration section: %s\n", section_str);
|
||||
@@ -1252,14 +1252,14 @@ static switch_status_t handle_erl_msg(ei_node_t *ei_node, erlang_msg *msg, ei_x_
|
||||
static void *SWITCH_THREAD_FUNC receive_handler(switch_thread_t *thread, void *obj) {
|
||||
ei_node_t *ei_node = (ei_node_t *) obj;
|
||||
|
||||
switch_atomic_inc(&globals.threads);
|
||||
switch_atomic_inc(&kazoo_globals.threads);
|
||||
switch_atomic_inc(&ei_node->receive_handlers);
|
||||
|
||||
switch_assert(ei_node != NULL);
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Starting erlang receive handler %p: %s (%s:%d)\n", (void *)ei_node, ei_node->peer_nodename, ei_node->remote_ip, ei_node->remote_port);
|
||||
|
||||
while (switch_test_flag(ei_node, LFLAG_RUNNING) && switch_test_flag(&globals, LFLAG_RUNNING)) {
|
||||
while (switch_test_flag(ei_node, LFLAG_RUNNING) && switch_test_flag(&kazoo_globals, LFLAG_RUNNING)) {
|
||||
void *pop;
|
||||
|
||||
if (switch_queue_pop_timeout(ei_node->received_msgs, &pop, 500000) == SWITCH_STATUS_SUCCESS) {
|
||||
@@ -1273,7 +1273,7 @@ static void *SWITCH_THREAD_FUNC receive_handler(switch_thread_t *thread, void *o
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Shutdown erlang receive handler %p: %s (%s:%d)\n", (void *)ei_node, ei_node->peer_nodename, ei_node->remote_ip, ei_node->remote_port);
|
||||
|
||||
switch_atomic_dec(&ei_node->receive_handlers);
|
||||
switch_atomic_dec(&globals.threads);
|
||||
switch_atomic_dec(&kazoo_globals.threads);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -1283,7 +1283,7 @@ static void *SWITCH_THREAD_FUNC handle_node(switch_thread_t *thread, void *obj)
|
||||
ei_received_msg_t *received_msg = NULL;
|
||||
int fault_count = 0;
|
||||
|
||||
switch_atomic_inc(&globals.threads);
|
||||
switch_atomic_inc(&kazoo_globals.threads);
|
||||
|
||||
switch_assert(ei_node != NULL);
|
||||
|
||||
@@ -1291,7 +1291,7 @@ static void *SWITCH_THREAD_FUNC handle_node(switch_thread_t *thread, void *obj)
|
||||
|
||||
add_to_ei_nodes(ei_node);
|
||||
|
||||
while (switch_test_flag(ei_node, LFLAG_RUNNING) && switch_test_flag(&globals, LFLAG_RUNNING)) {
|
||||
while (switch_test_flag(ei_node, LFLAG_RUNNING) && switch_test_flag(&kazoo_globals, LFLAG_RUNNING)) {
|
||||
int status;
|
||||
int send_msg_count = 0;
|
||||
void *pop;
|
||||
@@ -1299,9 +1299,9 @@ static void *SWITCH_THREAD_FUNC handle_node(switch_thread_t *thread, void *obj)
|
||||
if (!received_msg) {
|
||||
switch_malloc(received_msg, sizeof(*received_msg));
|
||||
/* create a new buf for the erlang message and a rbuf for the reply */
|
||||
if(globals.receive_msg_preallocate > 0) {
|
||||
received_msg->buf.buff = malloc(globals.receive_msg_preallocate);
|
||||
received_msg->buf.buffsz = globals.receive_msg_preallocate;
|
||||
if(kazoo_globals.receive_msg_preallocate > 0) {
|
||||
received_msg->buf.buff = malloc(kazoo_globals.receive_msg_preallocate);
|
||||
received_msg->buf.buffsz = kazoo_globals.receive_msg_preallocate;
|
||||
received_msg->buf.index = 0;
|
||||
if(received_msg->buf.buff == NULL) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not pre-allocate memory for mod_kazoo message\n");
|
||||
@@ -1313,7 +1313,7 @@ static void *SWITCH_THREAD_FUNC handle_node(switch_thread_t *thread, void *obj)
|
||||
}
|
||||
|
||||
while (switch_queue_trypop(ei_node->send_msgs, &pop) == SWITCH_STATUS_SUCCESS
|
||||
&& ++send_msg_count <= globals.send_msg_batch) {
|
||||
&& ++send_msg_count <= kazoo_globals.send_msg_batch) {
|
||||
ei_send_msg_t *send_msg = (ei_send_msg_t *) pop;
|
||||
ei_helper_send(ei_node, &send_msg->pid, &send_msg->buf);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sent erlang message to %s <%d.%d.%d>\n"
|
||||
@@ -1326,7 +1326,7 @@ static void *SWITCH_THREAD_FUNC handle_node(switch_thread_t *thread, void *obj)
|
||||
}
|
||||
|
||||
/* wait for a erlang message, or timeout to check if the module is still running */
|
||||
status = ei_xreceive_msg_tmo(ei_node->nodefd, &received_msg->msg, &received_msg->buf, globals.receive_timeout);
|
||||
status = ei_xreceive_msg_tmo(ei_node->nodefd, &received_msg->msg, &received_msg->buf, kazoo_globals.receive_timeout);
|
||||
|
||||
switch (status) {
|
||||
case ERL_TICK:
|
||||
@@ -1340,7 +1340,7 @@ static void *SWITCH_THREAD_FUNC handle_node(switch_thread_t *thread, void *obj)
|
||||
switch_safe_free(received_msg);
|
||||
}
|
||||
|
||||
if (globals.receive_msg_preallocate > 0 && received_msg->buf.buffsz > globals.receive_msg_preallocate) {
|
||||
if (kazoo_globals.receive_msg_preallocate > 0 && received_msg->buf.buffsz > kazoo_globals.receive_msg_preallocate) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "increased received message buffer size to %d\n", received_msg->buf.buffsz);
|
||||
}
|
||||
|
||||
@@ -1360,7 +1360,7 @@ static void *SWITCH_THREAD_FUNC handle_node(switch_thread_t *thread, void *obj)
|
||||
case EIO:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Erlang communication fault with node %p %s (%s:%d): socket closed or I/O error [fault count %d]\n", (void *)ei_node, ei_node->peer_nodename, ei_node->remote_ip, ei_node->remote_port, ++fault_count);
|
||||
|
||||
if (fault_count >= globals.io_fault_tolerance) {
|
||||
if (fault_count >= kazoo_globals.io_fault_tolerance) {
|
||||
switch_clear_flag(ei_node, LFLAG_RUNNING);
|
||||
}
|
||||
|
||||
@@ -1397,7 +1397,7 @@ static void *SWITCH_THREAD_FUNC handle_node(switch_thread_t *thread, void *obj)
|
||||
|
||||
destroy_node_handler(ei_node);
|
||||
|
||||
switch_atomic_dec(&globals.threads);
|
||||
switch_atomic_dec(&kazoo_globals.threads);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1454,7 +1454,7 @@ switch_status_t new_kazoo_node(int nodefd, ErlConnect *conn) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "New erlang connection from node %s (%s:%d)\n", ei_node->peer_nodename, ei_node->remote_ip, ei_node->remote_port);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "New erlang connection to node %s (%s:%d)\n", ei_node->peer_nodename, ei_node->local_ip, ei_node->local_port);
|
||||
|
||||
for(i = 0; i < globals.num_worker_threads; i++) {
|
||||
for(i = 0; i < kazoo_globals.num_worker_threads; i++) {
|
||||
switch_threadattr_create(&thd_attr, ei_node->pool);
|
||||
switch_threadattr_detach_set(thd_attr, 1);
|
||||
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
|
||||
|
||||
@@ -142,7 +142,7 @@ switch_socket_t *create_socket_with_port(switch_memory_pool_t *pool, switch_port
|
||||
switch_sockaddr_t *sa;
|
||||
switch_socket_t *socket;
|
||||
|
||||
if(switch_sockaddr_info_get(&sa, globals.ip, SWITCH_UNSPEC, port, 0, pool)) {
|
||||
if(switch_sockaddr_info_get(&sa, kazoo_globals.ip, SWITCH_UNSPEC, port, 0, pool)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -162,9 +162,9 @@ switch_socket_t *create_socket_with_port(switch_memory_pool_t *pool, switch_port
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch_getnameinfo(&globals.hostname, sa, 0);
|
||||
switch_getnameinfo(&kazoo_globals.hostname, sa, 0);
|
||||
|
||||
// if (globals.nat_map && switch_nat_get_type()) {
|
||||
// if (kazoo_globals.nat_map && switch_nat_get_type()) {
|
||||
// switch_nat_add_mapping(port, SWITCH_NAT_TCP, NULL, SWITCH_FALSE);
|
||||
// }
|
||||
|
||||
@@ -188,20 +188,20 @@ switch_status_t create_ei_cnode(const char *ip_addr, const char *name, struct ei
|
||||
|
||||
if ((atsign = strchr(cnodename, '@'))) {
|
||||
/* we got a qualified node name, don't guess the host/domain */
|
||||
snprintf(nodename, MAXNODELEN + 1, "%s", globals.ei_nodename);
|
||||
snprintf(nodename, MAXNODELEN + 1, "%s", kazoo_globals.ei_nodename);
|
||||
/* truncate the alivename at the @ */
|
||||
*atsign = '\0';
|
||||
} else {
|
||||
if (zstr(globals.hostname) || !strncasecmp(globals.ip, "0.0.0.0", 7) || !strncasecmp(globals.ip, "::", 2)) {
|
||||
if (zstr(kazoo_globals.hostname) || !strncasecmp(kazoo_globals.ip, "0.0.0.0", 7) || !strncasecmp(kazoo_globals.ip, "::", 2)) {
|
||||
memcpy(hostname, switch_core_get_hostname(), EI_MAXHOSTNAMELEN);
|
||||
} else {
|
||||
memcpy(hostname, globals.hostname, EI_MAXHOSTNAMELEN);
|
||||
memcpy(hostname, kazoo_globals.hostname, EI_MAXHOSTNAMELEN);
|
||||
}
|
||||
|
||||
snprintf(nodename, MAXNODELEN + 1, "%s@%s", globals.ei_nodename, hostname);
|
||||
snprintf(nodename, MAXNODELEN + 1, "%s@%s", kazoo_globals.ei_nodename, hostname);
|
||||
}
|
||||
|
||||
if (globals.ei_shortname) {
|
||||
if (kazoo_globals.ei_shortname) {
|
||||
char *off;
|
||||
if ((off = strchr(nodename, '.'))) {
|
||||
*off = '\0';
|
||||
@@ -209,7 +209,7 @@ switch_status_t create_ei_cnode(const char *ip_addr, const char *name, struct ei
|
||||
}
|
||||
|
||||
/* init the ec stuff */
|
||||
if (ei_connect_xinit(ei_cnode, hostname, cnodename, nodename, (Erl_IpAddr) ip_addr, globals.ei_cookie, 0) < 0) {
|
||||
if (ei_connect_xinit(ei_cnode, hostname, cnodename, nodename, (Erl_IpAddr) ip_addr, kazoo_globals.ei_cookie, 0) < 0) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to initialize the erlang interface connection structure\n");
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
@@ -654,9 +654,9 @@ static void *SWITCH_THREAD_FUNC fetch_config_filters_exec(switch_thread_t *threa
|
||||
switch_core_hash_insert(filter, var, "1");
|
||||
}
|
||||
|
||||
old_filter = globals.event_filter;
|
||||
globals.config_filters_fetched = 1;
|
||||
globals.event_filter = filter;
|
||||
old_filter = kazoo_globals.event_filter;
|
||||
kazoo_globals.config_filters_fetched = 1;
|
||||
kazoo_globals.event_filter = filter;
|
||||
if (old_filter) {
|
||||
switch_core_hash_destroy(&old_filter);
|
||||
}
|
||||
|
||||
@@ -35,17 +35,17 @@
|
||||
#define KAZOO_DESC "kazoo information"
|
||||
#define KAZOO_SYNTAX "<command> [<args>]"
|
||||
|
||||
globals_t globals;
|
||||
globals_t kazoo_globals;
|
||||
|
||||
SWITCH_MODULE_LOAD_FUNCTION(mod_kazoo_load);
|
||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_kazoo_shutdown);
|
||||
SWITCH_MODULE_RUNTIME_FUNCTION(mod_kazoo_runtime);
|
||||
SWITCH_MODULE_DEFINITION(mod_kazoo, mod_kazoo_load, mod_kazoo_shutdown, mod_kazoo_runtime);
|
||||
|
||||
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_pref_ip, globals.ip);
|
||||
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_pref_ei_cookie, globals.ei_cookie);
|
||||
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_pref_ei_nodename, globals.ei_nodename);
|
||||
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_pref_kazoo_var_prefix, globals.kazoo_var_prefix);
|
||||
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_pref_ip, kazoo_globals.ip);
|
||||
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_pref_ei_cookie, kazoo_globals.ei_cookie);
|
||||
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_pref_ei_nodename, kazoo_globals.ei_nodename);
|
||||
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_pref_kazoo_var_prefix, kazoo_globals.kazoo_var_prefix);
|
||||
|
||||
static switch_status_t api_erlang_status(switch_stream_handle_t *stream) {
|
||||
switch_sockaddr_t *sa;
|
||||
@@ -54,21 +54,21 @@ static switch_status_t api_erlang_status(switch_stream_handle_t *stream) {
|
||||
const char *ip_addr;
|
||||
ei_node_t *ei_node;
|
||||
|
||||
switch_socket_addr_get(&sa, SWITCH_FALSE, globals.acceptor);
|
||||
switch_socket_addr_get(&sa, SWITCH_FALSE, kazoo_globals.acceptor);
|
||||
|
||||
port = switch_sockaddr_get_port(sa);
|
||||
ip_addr = switch_get_addr(ipbuf, sizeof (ipbuf), sa);
|
||||
|
||||
stream->write_function(stream, "Running %s\n", VERSION);
|
||||
stream->write_function(stream, "Listening for new Erlang connections on %s:%u with cookie %s\n", ip_addr, port, globals.ei_cookie);
|
||||
stream->write_function(stream, "Registered as Erlang node %s, visible as %s\n", globals.ei_cnode.thisnodename, globals.ei_cnode.thisalivename);
|
||||
stream->write_function(stream, "Listening for new Erlang connections on %s:%u with cookie %s\n", ip_addr, port, kazoo_globals.ei_cookie);
|
||||
stream->write_function(stream, "Registered as Erlang node %s, visible as %s\n", kazoo_globals.ei_cnode.thisnodename, kazoo_globals.ei_cnode.thisalivename);
|
||||
|
||||
if (globals.ei_compat_rel) {
|
||||
stream->write_function(stream, "Using Erlang compatibility mode: %d\n", globals.ei_compat_rel);
|
||||
if (kazoo_globals.ei_compat_rel) {
|
||||
stream->write_function(stream, "Using Erlang compatibility mode: %d\n", kazoo_globals.ei_compat_rel);
|
||||
}
|
||||
|
||||
switch_thread_rwlock_rdlock(globals.ei_nodes_lock);
|
||||
ei_node = globals.ei_nodes;
|
||||
switch_thread_rwlock_rdlock(kazoo_globals.ei_nodes_lock);
|
||||
ei_node = kazoo_globals.ei_nodes;
|
||||
if (!ei_node) {
|
||||
stream->write_function(stream, "No erlang nodes connected\n");
|
||||
} else {
|
||||
@@ -87,7 +87,7 @@ static switch_status_t api_erlang_status(switch_stream_handle_t *stream) {
|
||||
ei_node = ei_node->next;
|
||||
}
|
||||
}
|
||||
switch_thread_rwlock_unlock(globals.ei_nodes_lock);
|
||||
switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
@@ -96,7 +96,7 @@ static switch_status_t api_erlang_event_filter(switch_stream_handle_t *stream) {
|
||||
switch_hash_index_t *hi = NULL;
|
||||
int column = 0;
|
||||
|
||||
for (hi = (switch_hash_index_t *)switch_core_hash_first_iter(globals.event_filter, hi); hi; hi = switch_core_hash_next(&hi)) {
|
||||
for (hi = (switch_hash_index_t *)switch_core_hash_first_iter(kazoo_globals.event_filter, hi); hi; hi = switch_core_hash_next(&hi)) {
|
||||
const void *key;
|
||||
void *val;
|
||||
switch_core_hash_this(hi, &key, NULL, &val);
|
||||
@@ -112,7 +112,7 @@ static switch_status_t api_erlang_event_filter(switch_stream_handle_t *stream) {
|
||||
column = 0;
|
||||
}
|
||||
|
||||
stream->write_function(stream, "%-50s", globals.kazoo_var_prefix);
|
||||
stream->write_function(stream, "%-50s", kazoo_globals.kazoo_var_prefix);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
@@ -120,13 +120,13 @@ static switch_status_t api_erlang_event_filter(switch_stream_handle_t *stream) {
|
||||
static switch_status_t api_erlang_nodes_list(switch_stream_handle_t *stream) {
|
||||
ei_node_t *ei_node;
|
||||
|
||||
switch_thread_rwlock_rdlock(globals.ei_nodes_lock);
|
||||
ei_node = globals.ei_nodes;
|
||||
switch_thread_rwlock_rdlock(kazoo_globals.ei_nodes_lock);
|
||||
ei_node = kazoo_globals.ei_nodes;
|
||||
while(ei_node != NULL) {
|
||||
stream->write_function(stream, "%s (%s)\n", ei_node->peer_nodename, ei_node->remote_ip);
|
||||
ei_node = ei_node->next;
|
||||
}
|
||||
switch_thread_rwlock_unlock(globals.ei_nodes_lock);
|
||||
switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
@@ -135,13 +135,13 @@ static switch_status_t api_erlang_nodes_count(switch_stream_handle_t *stream) {
|
||||
ei_node_t *ei_node;
|
||||
int count = 0;
|
||||
|
||||
switch_thread_rwlock_rdlock(globals.ei_nodes_lock);
|
||||
ei_node = globals.ei_nodes;
|
||||
switch_thread_rwlock_rdlock(kazoo_globals.ei_nodes_lock);
|
||||
ei_node = kazoo_globals.ei_nodes;
|
||||
while(ei_node != NULL) {
|
||||
count++;
|
||||
ei_node = ei_node->next;
|
||||
}
|
||||
switch_thread_rwlock_unlock(globals.ei_nodes_lock);
|
||||
switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock);
|
||||
|
||||
stream->write_function(stream, "%d\n", count);
|
||||
|
||||
@@ -153,13 +153,13 @@ static switch_status_t api_complete_erlang_node(const char *line, const char *cu
|
||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||
ei_node_t *ei_node;
|
||||
|
||||
switch_thread_rwlock_rdlock(globals.ei_nodes_lock);
|
||||
ei_node = globals.ei_nodes;
|
||||
switch_thread_rwlock_rdlock(kazoo_globals.ei_nodes_lock);
|
||||
ei_node = kazoo_globals.ei_nodes;
|
||||
while(ei_node != NULL) {
|
||||
switch_console_push_match(&my_matches, ei_node->peer_nodename);
|
||||
ei_node = ei_node->next;
|
||||
}
|
||||
switch_thread_rwlock_unlock(globals.ei_nodes_lock);
|
||||
switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock);
|
||||
|
||||
if (my_matches) {
|
||||
*matches = my_matches;
|
||||
@@ -185,7 +185,7 @@ static switch_status_t handle_node_api_event_stream(ei_event_stream_t *event_str
|
||||
ip_addr = switch_get_addr(ipbuf, sizeof (ipbuf), sa);
|
||||
|
||||
if (zstr(ip_addr)) {
|
||||
ip_addr = globals.ip;
|
||||
ip_addr = kazoo_globals.ip;
|
||||
}
|
||||
|
||||
stream->write_function(stream, "%s:%d -> disconnected\n"
|
||||
@@ -272,20 +272,20 @@ static switch_status_t handle_node_api_command(ei_node_t *ei_node, switch_stream
|
||||
static switch_status_t api_erlang_node_command(switch_stream_handle_t *stream, const char *nodename, uint32_t command) {
|
||||
ei_node_t *ei_node;
|
||||
|
||||
switch_thread_rwlock_rdlock(globals.ei_nodes_lock);
|
||||
ei_node = globals.ei_nodes;
|
||||
switch_thread_rwlock_rdlock(kazoo_globals.ei_nodes_lock);
|
||||
ei_node = kazoo_globals.ei_nodes;
|
||||
while(ei_node != NULL) {
|
||||
int length = strlen(ei_node->peer_nodename);
|
||||
|
||||
if (!strncmp(ei_node->peer_nodename, nodename, length)) {
|
||||
handle_node_api_command(ei_node, stream, command);
|
||||
switch_thread_rwlock_unlock(globals.ei_nodes_lock);
|
||||
switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
ei_node = ei_node->next;
|
||||
}
|
||||
switch_thread_rwlock_unlock(globals.ei_nodes_lock);
|
||||
switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock);
|
||||
|
||||
return SWITCH_STATUS_NOTFOUND;
|
||||
}
|
||||
@@ -340,16 +340,16 @@ static int read_cookie_from_file(char *filename) {
|
||||
static switch_status_t config(void) {
|
||||
char *cf = "kazoo.conf";
|
||||
switch_xml_t cfg, xml, child, param;
|
||||
globals.send_all_headers = 0;
|
||||
globals.send_all_private_headers = 1;
|
||||
globals.connection_timeout = 500;
|
||||
globals.receive_timeout = 200;
|
||||
globals.receive_msg_preallocate = 2000;
|
||||
globals.event_stream_preallocate = 4000;
|
||||
globals.send_msg_batch = 10;
|
||||
globals.event_stream_framing = 2;
|
||||
globals.port = 0;
|
||||
globals.io_fault_tolerance = 10;
|
||||
kazoo_globals.send_all_headers = 0;
|
||||
kazoo_globals.send_all_private_headers = 1;
|
||||
kazoo_globals.connection_timeout = 500;
|
||||
kazoo_globals.receive_timeout = 200;
|
||||
kazoo_globals.receive_msg_preallocate = 2000;
|
||||
kazoo_globals.event_stream_preallocate = 4000;
|
||||
kazoo_globals.send_msg_batch = 10;
|
||||
kazoo_globals.event_stream_framing = 2;
|
||||
kazoo_globals.port = 0;
|
||||
kazoo_globals.io_fault_tolerance = 10;
|
||||
|
||||
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open configuration file %s\n", cf);
|
||||
@@ -365,7 +365,7 @@ static switch_status_t config(void) {
|
||||
set_pref_ip(val);
|
||||
} else if (!strcmp(var, "listen-port")) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set bind port: %s\n", val);
|
||||
globals.port = atoi(val);
|
||||
kazoo_globals.port = atoi(val);
|
||||
} else if (!strcmp(var, "cookie")) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set cookie: %s\n", val);
|
||||
set_pref_ei_cookie(val);
|
||||
@@ -377,43 +377,43 @@ static switch_status_t config(void) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set node name: %s\n", val);
|
||||
set_pref_ei_nodename(val);
|
||||
} else if (!strcmp(var, "shortname")) {
|
||||
globals.ei_shortname = switch_true(val);
|
||||
kazoo_globals.ei_shortname = switch_true(val);
|
||||
} else if (!strcmp(var, "kazoo-var-prefix")) {
|
||||
set_pref_kazoo_var_prefix(val);
|
||||
} else if (!strcmp(var, "compat-rel")) {
|
||||
if (atoi(val) >= 7)
|
||||
globals.ei_compat_rel = atoi(val);
|
||||
kazoo_globals.ei_compat_rel = atoi(val);
|
||||
else
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid compatibility release '%s' specified\n", val);
|
||||
} else if (!strcmp(var, "nat-map")) {
|
||||
globals.nat_map = switch_true(val);
|
||||
kazoo_globals.nat_map = switch_true(val);
|
||||
} else if (!strcmp(var, "send-all-headers")) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set send-all-headers: %s\n", val);
|
||||
globals.send_all_headers = switch_true(val);
|
||||
kazoo_globals.send_all_headers = switch_true(val);
|
||||
} else if (!strcmp(var, "send-all-private-headers")) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set send-all-private-headers: %s\n", val);
|
||||
globals.send_all_private_headers = switch_true(val);
|
||||
kazoo_globals.send_all_private_headers = switch_true(val);
|
||||
} else if (!strcmp(var, "connection-timeout")) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set connection-timeout: %s\n", val);
|
||||
globals.connection_timeout = atoi(val);
|
||||
kazoo_globals.connection_timeout = atoi(val);
|
||||
} else if (!strcmp(var, "receive-timeout")) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set receive-timeout: %s\n", val);
|
||||
globals.receive_timeout = atoi(val);
|
||||
kazoo_globals.receive_timeout = atoi(val);
|
||||
} else if (!strcmp(var, "receive-msg-preallocate")) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set receive-msg-preallocate: %s\n", val);
|
||||
globals.receive_msg_preallocate = atoi(val);
|
||||
kazoo_globals.receive_msg_preallocate = atoi(val);
|
||||
} else if (!strcmp(var, "event-stream-preallocate")) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set event-stream-preallocate: %s\n", val);
|
||||
globals.event_stream_preallocate = atoi(val);
|
||||
kazoo_globals.event_stream_preallocate = atoi(val);
|
||||
} else if (!strcmp(var, "send-msg-batch-size")) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set send-msg-batch-size: %s\n", val);
|
||||
globals.send_msg_batch = atoi(val);
|
||||
kazoo_globals.send_msg_batch = atoi(val);
|
||||
} else if (!strcmp(var, "event-stream-framing")) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set event-stream-framing: %s\n", val);
|
||||
globals.event_stream_framing = atoi(val);
|
||||
kazoo_globals.event_stream_framing = atoi(val);
|
||||
} else if (!strcmp(var, "io-fault-tolerance")) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set io-fault-tolerance: %s\n", val);
|
||||
globals.io_fault_tolerance = atoi(val);
|
||||
kazoo_globals.io_fault_tolerance = atoi(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -427,68 +427,68 @@ static switch_status_t config(void) {
|
||||
switch_core_hash_insert(filter, var, "1");
|
||||
}
|
||||
|
||||
globals.event_filter = filter;
|
||||
kazoo_globals.event_filter = filter;
|
||||
}
|
||||
|
||||
switch_xml_free(xml);
|
||||
}
|
||||
|
||||
if (globals.receive_msg_preallocate < 0) {
|
||||
if (kazoo_globals.receive_msg_preallocate < 0) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid receive message preallocate value, disabled\n");
|
||||
globals.receive_msg_preallocate = 0;
|
||||
kazoo_globals.receive_msg_preallocate = 0;
|
||||
}
|
||||
|
||||
if (globals.event_stream_preallocate < 0) {
|
||||
if (kazoo_globals.event_stream_preallocate < 0) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid event stream preallocate value, disabled\n");
|
||||
globals.event_stream_preallocate = 0;
|
||||
kazoo_globals.event_stream_preallocate = 0;
|
||||
}
|
||||
|
||||
if (globals.send_msg_batch < 1) {
|
||||
if (kazoo_globals.send_msg_batch < 1) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid send message batch size, reverting to default\n");
|
||||
globals.send_msg_batch = 10;
|
||||
kazoo_globals.send_msg_batch = 10;
|
||||
}
|
||||
|
||||
if (globals.io_fault_tolerance < 1) {
|
||||
if (kazoo_globals.io_fault_tolerance < 1) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid I/O fault tolerance, reverting to default\n");
|
||||
globals.io_fault_tolerance = 10;
|
||||
kazoo_globals.io_fault_tolerance = 10;
|
||||
}
|
||||
|
||||
if (!globals.event_filter) {
|
||||
if (!kazoo_globals.event_filter) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Event filter not found in configuration, using default\n");
|
||||
globals.event_filter = create_default_filter();
|
||||
kazoo_globals.event_filter = create_default_filter();
|
||||
}
|
||||
|
||||
if (globals.event_stream_framing < 1 || globals.event_stream_framing > 4) {
|
||||
if (kazoo_globals.event_stream_framing < 1 || kazoo_globals.event_stream_framing > 4) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid event stream framing value, using default\n");
|
||||
globals.event_stream_framing = 2;
|
||||
kazoo_globals.event_stream_framing = 2;
|
||||
}
|
||||
|
||||
if (zstr(globals.kazoo_var_prefix)) {
|
||||
if (zstr(kazoo_globals.kazoo_var_prefix)) {
|
||||
set_pref_kazoo_var_prefix("variable_ecallmgr*");
|
||||
globals.var_prefix_length = 17; //ignore the *
|
||||
kazoo_globals.var_prefix_length = 17; //ignore the *
|
||||
} else {
|
||||
/* we could use the global pool but then we would have to conditionally
|
||||
* free the pointer if it was not drawn from the XML */
|
||||
char *buf;
|
||||
int size = switch_snprintf(NULL, 0, "variable_%s*", globals.kazoo_var_prefix) + 1;
|
||||
int size = switch_snprintf(NULL, 0, "variable_%s*", kazoo_globals.kazoo_var_prefix) + 1;
|
||||
|
||||
switch_malloc(buf, size);
|
||||
switch_snprintf(buf, size, "variable_%s*", globals.kazoo_var_prefix);
|
||||
switch_safe_free(globals.kazoo_var_prefix);
|
||||
globals.kazoo_var_prefix = buf;
|
||||
globals.var_prefix_length = size - 2; //ignore the *
|
||||
switch_snprintf(buf, size, "variable_%s*", kazoo_globals.kazoo_var_prefix);
|
||||
switch_safe_free(kazoo_globals.kazoo_var_prefix);
|
||||
kazoo_globals.kazoo_var_prefix = buf;
|
||||
kazoo_globals.var_prefix_length = size - 2; //ignore the *
|
||||
}
|
||||
|
||||
if (!globals.num_worker_threads) {
|
||||
if (!kazoo_globals.num_worker_threads) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Number of worker threads not found in configuration, using default\n");
|
||||
globals.num_worker_threads = 10;
|
||||
kazoo_globals.num_worker_threads = 10;
|
||||
}
|
||||
|
||||
if (zstr(globals.ip)) {
|
||||
if (zstr(kazoo_globals.ip)) {
|
||||
set_pref_ip("0.0.0.0");
|
||||
}
|
||||
|
||||
if (zstr(globals.ei_cookie)) {
|
||||
if (zstr(kazoo_globals.ei_cookie)) {
|
||||
int res;
|
||||
char *home_dir = getenv("HOME");
|
||||
char path_buf[1024];
|
||||
@@ -506,12 +506,12 @@ static switch_status_t config(void) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!globals.ei_nodename) {
|
||||
if (!kazoo_globals.ei_nodename) {
|
||||
set_pref_ei_nodename("freeswitch");
|
||||
}
|
||||
|
||||
if (!globals.nat_map) {
|
||||
globals.nat_map = 0;
|
||||
if (!kazoo_globals.nat_map) {
|
||||
kazoo_globals.nat_map = 0;
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
@@ -524,16 +524,16 @@ static switch_status_t create_acceptor() {
|
||||
const char *ip_addr;
|
||||
|
||||
/* if the config has specified an erlang release compatibility then pass that along to the erlang interface */
|
||||
if (globals.ei_compat_rel) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Compatability with OTP R%d requested\n", globals.ei_compat_rel);
|
||||
ei_set_compat_rel(globals.ei_compat_rel);
|
||||
if (kazoo_globals.ei_compat_rel) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Compatability with OTP R%d requested\n", kazoo_globals.ei_compat_rel);
|
||||
ei_set_compat_rel(kazoo_globals.ei_compat_rel);
|
||||
}
|
||||
|
||||
if (!(globals.acceptor = create_socket_with_port(globals.pool, globals.port))) {
|
||||
if (!(kazoo_globals.acceptor = create_socket_with_port(kazoo_globals.pool, kazoo_globals.port))) {
|
||||
return SWITCH_STATUS_SOCKERR;
|
||||
}
|
||||
|
||||
switch_socket_addr_get(&sa, SWITCH_FALSE, globals.acceptor);
|
||||
switch_socket_addr_get(&sa, SWITCH_FALSE, kazoo_globals.acceptor);
|
||||
|
||||
port = switch_sockaddr_get_port(sa);
|
||||
ip_addr = switch_get_addr(ipbuf, sizeof (ipbuf), sa);
|
||||
@@ -541,18 +541,18 @@ static switch_status_t create_acceptor() {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Erlang connection acceptor listening on %s:%u\n", ip_addr, port);
|
||||
|
||||
/* try to initialize the erlang interface */
|
||||
if (create_ei_cnode(ip_addr, globals.ei_nodename, &globals.ei_cnode) != SWITCH_STATUS_SUCCESS) {
|
||||
if (create_ei_cnode(ip_addr, kazoo_globals.ei_nodename, &kazoo_globals.ei_cnode) != SWITCH_STATUS_SUCCESS) {
|
||||
return SWITCH_STATUS_SOCKERR;
|
||||
}
|
||||
|
||||
/* tell the erlang port manager where we can be reached. this returns a file descriptor pointing to epmd or -1 */
|
||||
if ((globals.epmdfd = ei_publish(&globals.ei_cnode, port)) == -1) {
|
||||
if ((kazoo_globals.epmdfd = ei_publish(&kazoo_globals.ei_cnode, port)) == -1) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
||||
"Failed to publish port to epmd. Try starting it yourself or run an erl shell with the -sname or -name option.\n");
|
||||
return SWITCH_STATUS_SOCKERR;
|
||||
}
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connected to epmd and published erlang cnode name %s at port %d\n", globals.ei_cnode.thisnodename, port);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connected to epmd and published erlang cnode name %s at port %d\n", kazoo_globals.ei_cnode.thisnodename, port);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
@@ -638,10 +638,10 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_kazoo_load) {
|
||||
switch_api_interface_t *api_interface = NULL;
|
||||
switch_application_interface_t *app_interface = NULL;
|
||||
|
||||
memset(&globals, 0, sizeof(globals));
|
||||
memset(&kazoo_globals, 0, sizeof(kazoo_globals));
|
||||
|
||||
globals.pool = pool;
|
||||
globals.ei_nodes = NULL;
|
||||
kazoo_globals.pool = pool;
|
||||
kazoo_globals.ei_nodes = NULL;
|
||||
|
||||
if(config() != SWITCH_STATUS_SUCCESS) {
|
||||
// TODO: what would we need to clean up here?
|
||||
@@ -652,7 +652,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_kazoo_load) {
|
||||
if(create_acceptor() != SWITCH_STATUS_SUCCESS) {
|
||||
// TODO: what would we need to clean up here
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to create erlang connection acceptor!\n");
|
||||
close_socket(&globals.acceptor);
|
||||
close_socket(&kazoo_globals.acceptor);
|
||||
return SWITCH_STATUS_TERM;
|
||||
}
|
||||
|
||||
@@ -671,9 +671,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_kazoo_load) {
|
||||
switch_console_set_complete("add erlang node ::erlang::node fetch_bindings");
|
||||
switch_console_add_complete_func("::erlang::node", api_complete_erlang_node);
|
||||
|
||||
switch_thread_rwlock_create(&globals.ei_nodes_lock, pool);
|
||||
switch_thread_rwlock_create(&kazoo_globals.ei_nodes_lock, pool);
|
||||
|
||||
switch_set_flag(&globals, LFLAG_RUNNING);
|
||||
switch_set_flag(&kazoo_globals, LFLAG_RUNNING);
|
||||
|
||||
/* create all XML fetch agents */
|
||||
bind_fetch_agents();
|
||||
@@ -695,10 +695,10 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_kazoo_shutdown) {
|
||||
switch_console_del_complete_func("::erlang::node");
|
||||
|
||||
/* stop taking new requests and start shuting down the threads */
|
||||
switch_clear_flag(&globals, LFLAG_RUNNING);
|
||||
switch_clear_flag(&kazoo_globals, LFLAG_RUNNING);
|
||||
|
||||
/* give everyone time to cleanly shutdown */
|
||||
while (switch_atomic_read(&globals.threads)) {
|
||||
while (switch_atomic_read(&kazoo_globals.threads)) {
|
||||
switch_yield(100000);
|
||||
if (++sanity >= 200) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to kill all threads, continuing. This probably wont end well.....good luck!\n");
|
||||
@@ -706,31 +706,31 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_kazoo_shutdown) {
|
||||
}
|
||||
}
|
||||
|
||||
if (globals.event_filter) {
|
||||
switch_core_hash_destroy(&globals.event_filter);
|
||||
if (kazoo_globals.event_filter) {
|
||||
switch_core_hash_destroy(&kazoo_globals.event_filter);
|
||||
}
|
||||
|
||||
switch_thread_rwlock_wrlock(globals.ei_nodes_lock);
|
||||
switch_thread_rwlock_unlock(globals.ei_nodes_lock);
|
||||
switch_thread_rwlock_destroy(globals.ei_nodes_lock);
|
||||
switch_thread_rwlock_wrlock(kazoo_globals.ei_nodes_lock);
|
||||
switch_thread_rwlock_unlock(kazoo_globals.ei_nodes_lock);
|
||||
switch_thread_rwlock_destroy(kazoo_globals.ei_nodes_lock);
|
||||
|
||||
/* close the connection to epmd and the acceptor */
|
||||
close_socketfd(&globals.epmdfd);
|
||||
close_socket(&globals.acceptor);
|
||||
close_socketfd(&kazoo_globals.epmdfd);
|
||||
close_socket(&kazoo_globals.acceptor);
|
||||
|
||||
/* remove all XML fetch agents */
|
||||
unbind_fetch_agents();
|
||||
|
||||
/* Close the port we reserved for uPnP/Switch behind firewall, if necessary */
|
||||
// if (globals.nat_map && switch_nat_get_type()) {
|
||||
// switch_nat_del_mapping(globals.port, SWITCH_NAT_TCP);
|
||||
// if (kazoo_globals.nat_map && switch_nat_get_type()) {
|
||||
// switch_nat_del_mapping(kazoo_globals.port, SWITCH_NAT_TCP);
|
||||
// }
|
||||
|
||||
/* clean up our allocated preferences */
|
||||
switch_safe_free(globals.ip);
|
||||
switch_safe_free(globals.ei_cookie);
|
||||
switch_safe_free(globals.ei_nodename);
|
||||
switch_safe_free(globals.kazoo_var_prefix);
|
||||
switch_safe_free(kazoo_globals.ip);
|
||||
switch_safe_free(kazoo_globals.ei_cookie);
|
||||
switch_safe_free(kazoo_globals.ei_nodename);
|
||||
switch_safe_free(kazoo_globals.kazoo_var_prefix);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
@@ -738,11 +738,11 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_kazoo_shutdown) {
|
||||
SWITCH_MODULE_RUNTIME_FUNCTION(mod_kazoo_runtime) {
|
||||
switch_os_socket_t os_socket;
|
||||
|
||||
switch_atomic_inc(&globals.threads);
|
||||
switch_atomic_inc(&kazoo_globals.threads);
|
||||
|
||||
switch_os_sock_get(&os_socket, globals.acceptor);
|
||||
switch_os_sock_get(&os_socket, kazoo_globals.acceptor);
|
||||
|
||||
while (switch_test_flag(&globals, LFLAG_RUNNING)) {
|
||||
while (switch_test_flag(&kazoo_globals, LFLAG_RUNNING)) {
|
||||
int nodefd;
|
||||
ErlConnect conn;
|
||||
|
||||
@@ -752,19 +752,19 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_kazoo_runtime) {
|
||||
errno = 0;
|
||||
|
||||
/* wait here for an erlang node to connect, timming out to check if our module is still running every now-and-again */
|
||||
if ((nodefd = ei_accept_tmo(&globals.ei_cnode, (int) os_socket, &conn, globals.connection_timeout)) == ERL_ERROR) {
|
||||
if ((nodefd = ei_accept_tmo(&kazoo_globals.ei_cnode, (int) os_socket, &conn, kazoo_globals.connection_timeout)) == ERL_ERROR) {
|
||||
if (erl_errno == ETIMEDOUT) {
|
||||
continue;
|
||||
} else if (errno) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Erlang connection acceptor socket error %d %d\n", erl_errno, errno);
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
|
||||
"Erlang node connection failed - ensure your cookie matches '%s' and you are using a good nodename\n", globals.ei_cookie);
|
||||
"Erlang node connection failed - ensure your cookie matches '%s' and you are using a good nodename\n", kazoo_globals.ei_cookie);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!switch_test_flag(&globals, LFLAG_RUNNING)) {
|
||||
if (!switch_test_flag(&kazoo_globals, LFLAG_RUNNING)) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -774,7 +774,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_kazoo_runtime) {
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Erlang connection acceptor shut down\n");
|
||||
|
||||
switch_atomic_dec(&globals.threads);
|
||||
switch_atomic_dec(&kazoo_globals.threads);
|
||||
|
||||
return SWITCH_STATUS_TERM;
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ struct globals_s {
|
||||
int io_fault_tolerance;
|
||||
};
|
||||
typedef struct globals_s globals_t;
|
||||
extern globals_t globals;
|
||||
extern globals_t kazoo_globals;
|
||||
|
||||
/* kazoo_node.c */
|
||||
switch_status_t new_kazoo_node(int nodefd, ErlConnect *conn);
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
/**
|
||||
* Module globals
|
||||
*/
|
||||
struct {
|
||||
static struct {
|
||||
/** signal subscribers */
|
||||
switch_hash_t *subscribers;
|
||||
/** synchronizes access to subscribers */
|
||||
|
||||
Reference in new issue
Block a user