From b5169e770c255afd19a87ab7478239e7ec1077cd Mon Sep 17 00:00:00 2001 From: Hesaam Farhang Date: Wed, 4 May 2016 19:12:44 -0700 Subject: [PATCH 1/2] FS-9132: [mod_kazoo] Add more vars to default filter --- .../event_handlers/mod_kazoo/kazoo_utils.c | 19 +++++++++++++++++++ src/mod/event_handlers/mod_kazoo/mod_kazoo.c | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_utils.c b/src/mod/event_handlers/mod_kazoo/kazoo_utils.c index 1284118daf..127f849cdc 100644 --- a/src/mod/event_handlers/mod_kazoo/kazoo_utils.c +++ b/src/mod/event_handlers/mod_kazoo/kazoo_utils.c @@ -477,6 +477,9 @@ switch_hash_t *create_default_filter() { switch_core_hash_insert(filter, "whistle_application_name", "1"); switch_core_hash_insert(filter, "whistle_application_response", "1"); switch_core_hash_insert(filter, "whistle_event_name", "1"); + switch_core_hash_insert(filter, "kazoo_application_name", "1"); + switch_core_hash_insert(filter, "kazoo_application_response", "1"); + switch_core_hash_insert(filter, "kazoo_event_name", "1"); switch_core_hash_insert(filter, "sip_auto_answer_notify", "1"); switch_core_hash_insert(filter, "eavesdrop_group", "1"); switch_core_hash_insert(filter, "origination_caller_id_name", "1"); @@ -489,6 +492,21 @@ switch_hash_t *create_default_filter() { switch_core_hash_insert(filter, "effective_caller_id_number", "1"); switch_core_hash_insert(filter, "effective_callee_id_name", "1"); switch_core_hash_insert(filter, "effective_callee_id_number", "1"); + switch_core_hash_insert(filter, "variable_destination_number", "1"); + switch_core_hash_insert(filter, "variable_effective_callee_id_name", "1"); + switch_core_hash_insert(filter, "variable_effective_callee_id_number", "1"); + switch_core_hash_insert(filter, "variable_record_silence_hits", "1"); + switch_core_hash_insert(filter, "variable_refer_uuid", "1"); + switch_core_hash_insert(filter, "variable_sip_call_id", "1"); + switch_core_hash_insert(filter, "variable_sip_h_Referred-By", "1"); + switch_core_hash_insert(filter, "variable_sip_h_X-AUTH-PORT", "1"); + switch_core_hash_insert(filter, "variable_sip_loopback_req_uri", "1"); + switch_core_hash_insert(filter, "variable_sip_received_port", "1"); + switch_core_hash_insert(filter, "variable_sip_refer_to", "1"); + switch_core_hash_insert(filter, "variable_sip_req_host", "1"); + switch_core_hash_insert(filter, "variable_sip_req_uri", "1"); + switch_core_hash_insert(filter, "variable_transfer_source", "1"); + switch_core_hash_insert(filter, "variable_uuid", "1"); /* Registration headers */ switch_core_hash_insert(filter, "call-id", "1"); @@ -570,6 +588,7 @@ switch_hash_t *create_default_filter() { switch_core_hash_insert(filter, "variable_fax_timezone", "1"); switch_core_hash_insert(filter, "variable_fax_doc_id", "1"); switch_core_hash_insert(filter, "variable_fax_doc_database", "1"); + switch_core_hash_insert(filter, "variable_has_t38", "1"); /* Secure headers */ switch_core_hash_insert(filter, "variable_sdp_secure_savp_only", "1"); diff --git a/src/mod/event_handlers/mod_kazoo/mod_kazoo.c b/src/mod/event_handlers/mod_kazoo/mod_kazoo.c index ebf3af3f8c..4771f53c2d 100644 --- a/src/mod/event_handlers/mod_kazoo/mod_kazoo.c +++ b/src/mod/event_handlers/mod_kazoo/mod_kazoo.c @@ -340,7 +340,8 @@ 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 = globals.send_all_private_headers = 0; + globals.send_all_headers = 0; + globals.send_all_private_headers = 1; globals.connection_timeout = 500; globals.receive_timeout = 200; globals.receive_msg_preallocate = 2000; From 8153b6fdeef9785dc044de7068cab38ee1ea9e5d Mon Sep 17 00:00:00 2001 From: Hesaam Farhang Date: Fri, 6 May 2016 10:44:34 -0700 Subject: [PATCH 2/2] FS-9132: [mod_kazoo] remove whitespaces --- .../event_handlers/mod_kazoo/kazoo_commands.c | 2 +- .../event_handlers/mod_kazoo/kazoo_dptools.c | 6 +- .../mod_kazoo/kazoo_event_stream.c | 30 +-- src/mod/event_handlers/mod_kazoo/kazoo_node.c | 2 +- src/mod/event_handlers/mod_kazoo/mod_kazoo.c | 216 +++++++++--------- 5 files changed, 128 insertions(+), 128 deletions(-) diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_commands.c b/src/mod/event_handlers/mod_kazoo/kazoo_commands.c index ab9b65386b..4de71398f4 100644 --- a/src/mod/event_handlers/mod_kazoo/kazoo_commands.c +++ b/src/mod/event_handlers/mod_kazoo/kazoo_commands.c @@ -148,5 +148,5 @@ void add_kz_commands(switch_loadable_module_interface_t **module_interface, swit SWITCH_ADD_API(api_interface, "kz_uuid_setvar_multi", UUID_SET_DESC, uuid_setvar_multi_function, UUID_MULTISET_SYNTAX); switch_console_set_complete("add kz_uuid_setvar_multi ::console::list_uuid"); SWITCH_ADD_API(api_interface, "kz_uuid_setvar", UUID_MULTISET_DESC, uuid_setvar_function, UUID_SET_SYNTAX); - switch_console_set_complete("add kz_uuid_setvar ::console::list_uuid"); + switch_console_set_complete("add kz_uuid_setvar ::console::list_uuid"); } diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_dptools.c b/src/mod/event_handlers/mod_kazoo/kazoo_dptools.c index e6453d6490..352edaae82 100644 --- a/src/mod/event_handlers/mod_kazoo/kazoo_dptools.c +++ b/src/mod/event_handlers/mod_kazoo/kazoo_dptools.c @@ -141,7 +141,7 @@ SWITCH_STANDARD_APP(multiset_function) { arg = switch_core_session_strdup(session, arg); argc = switch_split(arg, delim, array); - + for(i = 0; i < argc; i++) { base_set(session, array[i], SWITCH_STACK_BOTTOM); } @@ -178,7 +178,7 @@ SWITCH_STANDARD_APP(unset_function) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "UNSET [%s]\n", (char *) data); switch_channel_set_variable(switch_core_session_get_channel(session), data, NULL); } - + if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) { switch_channel_event_set_data(channel, event); switch_event_fire(&event); @@ -242,7 +242,7 @@ void add_kz_dptools(switch_loadable_module_interface_t **module_interface, switc SWITCH_ADD_APP(app_interface, "kz_unset", UNSET_SHORT_DESC, UNSET_LONG_DESC, unset_function, UNSET_SYNTAX, SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC); SWITCH_ADD_APP(app_interface, "kz_multiunset", MULTISET_SHORT_DESC, MULTISET_LONG_DESC, multiunset_function, MULTIUNSET_SYNTAX, - SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC); + SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC); SWITCH_ADD_APP(app_interface, "kz_export", EXPORT_SHORT_DESC, EXPORT_LONG_DESC, export_function, EXPORT_SYNTAX, SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC | SAF_ZOMBIE_EXEC); } diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_event_stream.c b/src/mod/event_handlers/mod_kazoo/kazoo_event_stream.c index 00eb06a126..cf43ce1f45 100644 --- a/src/mod/event_handlers/mod_kazoo/kazoo_event_stream.c +++ b/src/mod/event_handlers/mod_kazoo/kazoo_event_stream.c @@ -37,7 +37,7 @@ static char *my_dup(const char *s) { size_t len = strlen(s) + 1; void *new = malloc(len); switch_assert(new); - + return (char *) memcpy(new, s, len); } @@ -58,21 +58,21 @@ static int is_private_header(const char *name) { static switch_status_t kazoo_event_dup(switch_event_t **clone, switch_event_t *event, switch_hash_t *filter) { switch_event_header_t *header; - + if (switch_event_create_subclass(clone, SWITCH_EVENT_CLONE, event->subclass_name) != SWITCH_STATUS_SUCCESS) { return SWITCH_STATUS_GENERR; } - + (*clone)->event_id = event->event_id; (*clone)->event_user_data = event->event_user_data; (*clone)->bind_user_data = event->bind_user_data; (*clone)->flags = event->flags; - + for (header = event->headers; header; header = header->next) { if (event->subclass_name && !strcmp(header->name, "Event-Subclass")) { continue; } - + if (strncmp(header->name, globals.kazoo_var_prefix, globals.var_prefix_length) && filter && !switch_core_hash_find(filter, header->name) @@ -82,7 +82,7 @@ static switch_status_t kazoo_event_dup(switch_event_t **clone, switch_event_t *e { continue; } - + if (header->idx) { int i; for (i = 0; i < header->idx; i++) { @@ -92,33 +92,33 @@ static switch_status_t kazoo_event_dup(switch_event_t **clone, switch_event_t *e switch_event_add_header_string(*clone, SWITCH_STACK_BOTTOM, header->name, header->value); } } - + if (event->body) { (*clone)->body = DUP(event->body); } - + (*clone)->key = event->key; - + return SWITCH_STATUS_SUCCESS; } static void event_handler(switch_event_t *event) { switch_event_t *clone = NULL; 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)) { return; } - + if (event->event_id == SWITCH_EVENT_CUSTOM) { ei_event_binding_t *event_binding = event_stream->bindings; unsigned short int found = 0; - + if (!event->subclass_name) { return; } - + while(event_binding != NULL) { if (event_binding->type == SWITCH_EVENT_CUSTOM) { if(event_binding->subclass_name @@ -238,9 +238,9 @@ static void *SWITCH_THREAD_FUNC event_stream_loop(switch_thread_t *thread, void } else { ei_x_new_with_version(&ebuf); } - + ei_encode_switch_event(&ebuf, event); - + if (globals.event_stream_preallocate > 0 && ebuf.buffsz > globals.event_stream_preallocate) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "increased event stream buffer size to %d\n", ebuf.buffsz); } diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_node.c b/src/mod/event_handlers/mod_kazoo/kazoo_node.c index 0ffd3ffdf0..1efe7e3e82 100644 --- a/src/mod/event_handlers/mod_kazoo/kazoo_node.c +++ b/src/mod/event_handlers/mod_kazoo/kazoo_node.c @@ -1092,7 +1092,7 @@ static void *SWITCH_THREAD_FUNC handle_node(switch_thread_t *thread, void *obj) ei_x_new(&received_msg->buf); } } - + while (switch_queue_trypop(ei_node->send_msgs, &pop) == SWITCH_STATUS_SUCCESS && ++send_msg_count <= globals.send_msg_batch) { ei_send_msg_t *send_msg = (ei_send_msg_t *) pop; diff --git a/src/mod/event_handlers/mod_kazoo/mod_kazoo.c b/src/mod/event_handlers/mod_kazoo/mod_kazoo.c index 4771f53c2d..dd305fe911 100644 --- a/src/mod/event_handlers/mod_kazoo/mod_kazoo.c +++ b/src/mod/event_handlers/mod_kazoo/mod_kazoo.c @@ -53,16 +53,16 @@ static switch_status_t api_erlang_status(switch_stream_handle_t *stream) { char ipbuf[25]; const char *ip_addr; ei_node_t *ei_node; - + switch_socket_addr_get(&sa, SWITCH_FALSE, 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); - + if (globals.ei_compat_rel) { stream->write_function(stream, "Using Erlang compatibility mode: %d\n", globals.ei_compat_rel); } @@ -75,7 +75,7 @@ static switch_status_t api_erlang_status(switch_stream_handle_t *stream) { stream->write_function(stream, "Connected to:\n"); while(ei_node != NULL) { unsigned int year, day, hour, min, sec, delta; - + delta = (switch_micro_time_now() - ei_node->created_time) / 1000000; sec = delta % 60; min = delta / 60 % 60; @@ -88,14 +88,14 @@ static switch_status_t api_erlang_status(switch_stream_handle_t *stream) { } } switch_thread_rwlock_unlock(globals.ei_nodes_lock); - + return SWITCH_STATUS_SUCCESS; } 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)) { const void *key; void *val; @@ -106,20 +106,20 @@ static switch_status_t api_erlang_event_filter(switch_stream_handle_t *stream) { column = 0; } } - + if (++column > 2) { stream->write_function(stream, "\n"); column = 0; } - + stream->write_function(stream, "%-50s", globals.kazoo_var_prefix); - + return SWITCH_STATUS_SUCCESS; } 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; while(ei_node != NULL) { @@ -127,14 +127,14 @@ static switch_status_t api_erlang_nodes_list(switch_stream_handle_t *stream) { ei_node = ei_node->next; } switch_thread_rwlock_unlock(globals.ei_nodes_lock); - + return SWITCH_STATUS_SUCCESS; } 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; while(ei_node != NULL) { @@ -142,9 +142,9 @@ static switch_status_t api_erlang_nodes_count(switch_stream_handle_t *stream) { ei_node = ei_node->next; } switch_thread_rwlock_unlock(globals.ei_nodes_lock); - + stream->write_function(stream, "%d\n", count); - + return SWITCH_STATUS_SUCCESS; } @@ -152,7 +152,7 @@ static switch_status_t api_complete_erlang_node(const char *line, const char *cu switch_console_callback_match_t *my_matches = NULL; 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; while(ei_node != NULL) { @@ -160,34 +160,34 @@ static switch_status_t api_complete_erlang_node(const char *line, const char *cu ei_node = ei_node->next; } switch_thread_rwlock_unlock(globals.ei_nodes_lock); - + if (my_matches) { *matches = my_matches; status = SWITCH_STATUS_SUCCESS; } - + return status; } static switch_status_t handle_node_api_event_stream(ei_event_stream_t *event_stream, switch_stream_handle_t *stream) { ei_event_binding_t *binding; int column = 0; - + switch_mutex_lock(event_stream->socket_mutex); if (event_stream->connected == SWITCH_FALSE) { switch_sockaddr_t *sa; uint16_t port; char ipbuf[25] = {0}; const char *ip_addr; - + switch_socket_addr_get(&sa, SWITCH_TRUE, event_stream->acceptor); port = switch_sockaddr_get_port(sa); ip_addr = switch_get_addr(ipbuf, sizeof (ipbuf), sa); - + if (zstr(ip_addr)) { ip_addr = globals.ip; } - + stream->write_function(stream, "%s:%d -> disconnected\n" ,ip_addr, port); } else { @@ -195,7 +195,7 @@ static switch_status_t handle_node_api_event_stream(ei_event_stream_t *event_str ,event_stream->local_ip, event_stream->local_port ,event_stream->remote_ip, event_stream->remote_port); } - + binding = event_stream->bindings; while(binding != NULL) { if (binding->type == SWITCH_EVENT_CUSTOM) { @@ -203,22 +203,22 @@ static switch_status_t handle_node_api_event_stream(ei_event_stream_t *event_str } else { stream->write_function(stream, "%-50s", switch_event_name(binding->type)); } - + if (++column > 2) { stream->write_function(stream, "\n"); column = 0; } - + binding = binding->next; } switch_mutex_unlock(event_stream->socket_mutex); - + if (!column) { stream->write_function(stream, "\n"); } else { stream->write_function(stream, "\n\n"); } - + return SWITCH_STATUS_SUCCESS; } @@ -232,13 +232,13 @@ static switch_status_t handle_node_api_event_streams(ei_node_t *ei_node, switch_ event_stream = event_stream->next; } switch_mutex_unlock(ei_node->event_streams_mutex); - + return SWITCH_STATUS_SUCCESS; } static switch_status_t handle_node_api_command(ei_node_t *ei_node, switch_stream_handle_t *stream, uint32_t command) { unsigned int year, day, hour, min, sec, delta; - + switch (command) { case API_COMMAND_DISCONNECT: stream->write_function(stream, "Disconnecting erlang node %s at managers request\n", ei_node->peer_nodename); @@ -251,7 +251,7 @@ static switch_status_t handle_node_api_command(ei_node_t *ei_node, switch_stream hour = delta / 3600 % 24; day = delta / 86400 % 7; year = delta / 31556926 % 12; - + stream->write_function(stream, "Uptime %d years, %d days, %d hours, %d minutes, %d seconds\n", year, day, hour, min, sec); stream->write_function(stream, "Local Address %s:%d\n", ei_node->local_ip, ei_node->local_port); stream->write_function(stream, "Remote Address %s:%d\n", ei_node->remote_ip, ei_node->remote_port); @@ -265,28 +265,28 @@ static switch_status_t handle_node_api_command(ei_node_t *ei_node, switch_stream default: break; } - + return SWITCH_STATUS_SUCCESS; } 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; 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); return SWITCH_STATUS_SUCCESS; } - + ei_node = ei_node->next; } switch_thread_rwlock_unlock(globals.ei_nodes_lock); - + return SWITCH_STATUS_NOTFOUND; } @@ -296,7 +296,7 @@ static int read_cookie_from_file(char *filename) { char *end; struct stat buf; ssize_t res; - + if (!stat(filename, &buf)) { if ((buf.st_mode & S_IRWXG) || (buf.st_mode & S_IRWXO)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s must only be accessible by owner only.\n", filename); @@ -311,24 +311,24 @@ static int read_cookie_from_file(char *filename) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to open cookie file %s : %d.\n", filename, errno); return 2; } - + if ((res = read(fd, cookie, MAXATOMLEN)) < 1) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to read cookie file %s : %d.\n", filename, errno); } - + cookie[MAXATOMLEN] = '\0'; - + /* replace any end of line characters with a null */ if ((end = strchr(cookie, '\n'))) { *end = '\0'; } - + if ((end = strchr(cookie, '\r'))) { *end = '\0'; } - + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set cookie from file %s: %s\n", filename, cookie); - + set_pref_ei_cookie(cookie); return 0; } else { @@ -349,7 +349,7 @@ static switch_status_t config(void) { globals.send_msg_batch = 10; globals.event_stream_framing = 2; globals.port = 0; - + 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); return SWITCH_STATUS_FALSE; @@ -358,7 +358,7 @@ static switch_status_t config(void) { for (param = switch_xml_child(child, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); - + if (!strcmp(var, "listen-ip")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set bind ip address: %s\n", val); set_pref_ip(val); @@ -413,19 +413,19 @@ static switch_status_t config(void) { } } } - + if ((child = switch_xml_child(cfg, "event-filter"))) { switch_hash_t *filter; - + switch_core_hash_init(&filter); for (param = switch_xml_child(child, "header"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); switch_core_hash_insert(filter, var, "1"); } - + globals.event_filter = filter; } - + switch_xml_free(xml); } @@ -433,17 +433,17 @@ static switch_status_t config(void) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid receive message preallocate value, disabled\n"); globals.receive_msg_preallocate = 0; } - + if (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; } - + if (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; } - + if (!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(); @@ -453,7 +453,7 @@ static switch_status_t config(void) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid event stream framing value, using default\n"); globals.event_stream_framing = 2; } - + if (zstr(globals.kazoo_var_prefix)) { set_pref_kazoo_var_prefix("variable_ecallmgr*"); globals.var_prefix_length = 17; //ignore the * @@ -462,33 +462,33 @@ static switch_status_t config(void) { * 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; - + 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 * } - + if (!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; } - + if (zstr(globals.ip)) { set_pref_ip("0.0.0.0"); } - + if (zstr(globals.ei_cookie)) { int res; char *home_dir = getenv("HOME"); char path_buf[1024]; - + if (!zstr(home_dir)) { /* $HOME/.erlang.cookie */ switch_snprintf(path_buf, sizeof (path_buf), "%s%s%s", home_dir, SWITCH_PATH_SEPARATOR, ".erlang.cookie"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking for cookie at path: %s\n", path_buf); - + res = read_cookie_from_file(path_buf); if (res) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No cookie or valid cookie file specified, using default cookie\n"); @@ -496,15 +496,15 @@ static switch_status_t config(void) { } } } - + if (!globals.ei_nodename) { set_pref_ei_nodename("freeswitch"); } - + if (!globals.nat_map) { globals.nat_map = 0; } - + return SWITCH_STATUS_SUCCESS; } @@ -513,38 +513,38 @@ static switch_status_t create_acceptor() { uint16_t port; char ipbuf[25]; 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 (!(globals.acceptor = create_socket_with_port(globals.pool, globals.port))) { return SWITCH_STATUS_SOCKERR; } - + switch_socket_addr_get(&sa, SWITCH_FALSE, globals.acceptor); - + port = switch_sockaddr_get_port(sa); ip_addr = switch_get_addr(ipbuf, sizeof (ipbuf), sa); - + 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) { 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) { 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); - + return SWITCH_STATUS_SUCCESS; } @@ -553,7 +553,7 @@ SWITCH_STANDARD_API(exec_api_cmd) char *argv[1024] = { 0 }; int unknown_command = 1, argc = 0; char *mycmd = NULL; - + const char *usage_string = "USAGE:\n" "--------------------------------------------------------------------------------------------------------------------\n" "erlang status - provides an overview of the current status\n" @@ -565,28 +565,28 @@ SWITCH_STANDARD_API(exec_api_cmd) "erlang node event_streams - lists the event streams for an Erlang node\n" "erlang node fetch_bindings - lists the XML fetch bindings for an Erlang node\n" "---------------------------------------------------------------------------------------------------------------------\n"; - + if (zstr(cmd)) { stream->write_function(stream, "%s", usage_string); return SWITCH_STATUS_SUCCESS; } - + if (!(mycmd = strdup(cmd))) { return SWITCH_STATUS_MEMERR; } - + if (!(argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) { stream->write_function(stream, "%s", usage_string); switch_safe_free(mycmd); return SWITCH_STATUS_SUCCESS; } - + if (zstr(argv[0])) { stream->write_function(stream, "%s", usage_string); switch_safe_free(mycmd); return SWITCH_STATUS_SUCCESS; } - + if (!strncmp(argv[0], "status", 6)) { unknown_command = 0; api_erlang_status(stream); @@ -616,11 +616,11 @@ SWITCH_STANDARD_API(exec_api_cmd) api_erlang_node_command(stream, argv[1], API_COMMAND_BINDINGS); } } - + if (unknown_command) { stream->write_function(stream, "%s", usage_string); } - + switch_safe_free(mycmd); return SWITCH_STATUS_SUCCESS; } @@ -628,28 +628,28 @@ SWITCH_STANDARD_API(exec_api_cmd) 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)); - + globals.pool = pool; globals.ei_nodes = NULL; - + if(config() != SWITCH_STATUS_SUCCESS) { // TODO: what would we need to clean up here? switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Improper configuration!\n"); return SWITCH_STATUS_TERM; } - + 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); return SWITCH_STATUS_TERM; } - + /* connect my internal structure to the blank pointer passed to me */ *module_interface = switch_loadable_module_create_module_interface(pool, modname); - + /* create an api for cli debug commands */ SWITCH_ADD_API(api_interface, "erlang", KAZOO_DESC, exec_api_cmd, KAZOO_SYNTAX); switch_console_set_complete("add erlang status"); @@ -661,13 +661,13 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_kazoo_load) { switch_console_set_complete("add erlang node ::erlang::node event_streams"); 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_set_flag(&globals, LFLAG_RUNNING); - + /* create all XML fetch agents */ - bind_fetch_agents(); + bind_fetch_agents(); /* add our modified commands */ add_kz_commands(module_interface, api_interface); @@ -681,13 +681,13 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_kazoo_load) { SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_kazoo_shutdown) { int sanity = 0; - + switch_console_set_complete("del erlang"); switch_console_del_complete_func("::erlang::node"); - + /* stop taking new requests and start shuting down the threads */ switch_clear_flag(&globals, LFLAG_RUNNING); - + /* give everyone time to cleanly shutdown */ while (switch_atomic_read(&globals.threads)) { switch_yield(100000); @@ -696,52 +696,52 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_kazoo_shutdown) { break; } } - + if (globals.event_filter) { switch_core_hash_destroy(&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); - + /* close the connection to epmd and the acceptor */ close_socketfd(&globals.epmdfd); close_socket(&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); // } - + /* 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); - + return SWITCH_STATUS_SUCCESS; } SWITCH_MODULE_RUNTIME_FUNCTION(mod_kazoo_runtime) { switch_os_socket_t os_socket; - + switch_atomic_inc(&globals.threads); - + switch_os_sock_get(&os_socket, globals.acceptor); - + while (switch_test_flag(&globals, LFLAG_RUNNING)) { int nodefd; ErlConnect conn; - + /* zero out errno because ei_accept doesn't differentiate between a */ /* failed authentication or a socket failure, or a client version */ /* mismatch or a godzilla attack (and a godzilla attack is highly likely) */ 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 (erl_errno == ETIMEDOUT) { @@ -754,19 +754,19 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_kazoo_runtime) { } continue; } - + if (!switch_test_flag(&globals, LFLAG_RUNNING)) { break; } - + /* NEW ERLANG NODE CONNECTION! Hello friend! */ new_kazoo_node(nodefd, &conn); } - + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Erlang connection acceptor shut down\n"); - + switch_atomic_dec(&globals.threads); - + return SWITCH_STATUS_TERM; }