diff --git a/build/Makefile.centos5 b/build/Makefile.centos5 new file mode 100644 index 0000000000..0fee662b2c --- /dev/null +++ b/build/Makefile.centos5 @@ -0,0 +1,92 @@ +# +# FreeSWITCH auto-build Makefile (CentOS 5.10 Wingardium Leviosa Edition) +# http://www.freeswitch.org +# put this file anywhere and type make to +# create a fully-built freeswitch.git from scratch +# in that same directory. +# +# Brian West +# +FSPREFIX=/usr/local/freeswitch +PREFIX=/opt/fs-libs +JPEG=v8d +OPENSSL=1.0.1g +SQLITE=autoconf-3080403 +PCRE=8.35 +CURL=7.36.0 +SPEEX=1.2rc1 +LIBEDIT=20140213-3.1 +LDNS=1.6.17 + +freeswitch: deps has-git freeswitch.git/Makefile + cd freeswitch.git && make + +freeswitch.git/Makefile: freeswitch.git/configure + cd freeswitch.git && PKG_CONFIG_PATH=$(PREFIX)/lib/pkgconfig ./configure LDFLAGS='-L$(PREFIX)/lib -Wl,-rpath=$(PREFIX)/lib' CFLAGS='-I$(PREFIX)/include' --prefix=$(FSPREFIX) + +freeswitch.git/configure: freeswitch.git/bootstrap.sh + cd freeswitch.git && sh bootstrap.sh + +freeswitch.git/bootstrap.sh: has-git + test -d freeswitch.git || git clone git://git.freeswitch.org/freeswitch.git freeswitch.git + +install: freeswitch + cd freeswitch.git && make install + +install-git: + rpm -i http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS//rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm + yum update -y + yum install -y git gcc-c++ wget ncurses-devel zlib-devel e2fsprogs-devel libtool automake autoconf + +has-git: + @git --version || (echo "please install git by running 'make install-git'" && false) + +libjpeg: jpeg-8d/Makefile + +jpeg-8d/Makefile: + (test -d jpeg-8d) || (wget -4 -O jpegsrc.$(JPEG).tar.gz http://www.ijg.org/files/jpegsrc.$(JPEG).tar.gz && tar zxfv jpegsrc.$(JPEG).tar.gz) + (cd jpeg-8d && ./configure --prefix=$(PREFIX) && make && sudo make install) + +openssl: openssl-$(OPENSSL) + +openssl-$(OPENSSL): + (test -d $@) || (wget -4 -O $@.tar.gz http://www.openssl.org/source/$@.tar.gz && tar zxfv $@.tar.gz) + (cd $@ && ./Configure --prefix=$(PREFIX) linux-x86_64 shared && make && sudo make install) + +sqlite: sqlite-$(SQLITE) + +sqlite-$(SQLITE): + (test -d $@) || (wget -4 -O $@.tar.gz http://www.sqlite.org/2014/$@.tar.gz && tar zxfv $@.tar.gz) + (cd $@ && ./configure --prefix=$(PREFIX) && make && sudo make install) + +pcre: pcre-$(PCRE) + +pcre-$(PCRE): + (test -d $@) || (wget -4 -O $@.tar.gz http://downloads.sourceforge.net/project/pcre/pcre/$(PCRE)/$@.tar.gz && tar zxfv $@.tar.gz) + (cd $@ && ./configure --prefix=$(PREFIX) && make && sudo make install) + +curl: curl-$(CURL) + +curl-$(CURL): + (test -d $@) || (wget -4 -O $@.tar.gz http://curl.haxx.se/download/$@.tar.gz && tar zxfv $@.tar.gz) + (cd $@ && ./configure --prefix=$(PREFIX) && make && sudo make install) + +speex: speex-$(SPEEX) + +speex-$(SPEEX): + (test -d $@) || (wget -4 -O $@.tar.gz http://downloads.xiph.org/releases/speex/$@.tar.gz && tar zxfv $@.tar.gz) + (cd $@ && ./configure --prefix=$(PREFIX) && make && sudo make install) + +libedit: libedit-$(LIBEDIT) + +libedit-$(LIBEDIT): + (test -d $@) || (wget -4 -O $@.tar.gz http://thrysoee.dk/editline/$@.tar.gz && tar zxfv $@.tar.gz) + (cd $@ && ./configure --prefix=$(PREFIX) && make && sudo make install) + +ldns: ldns-$(LDNS) + +ldns-$(LDNS): openssl + (test -d $@) || (wget -4 -O $@.tar.gz http://www.nlnetlabs.nl/downloads/ldns/$@.tar.gz && tar zxfv $@.tar.gz) + (cd $@ && ./configure --with-ssl=$(PREFIX) --prefix=$(PREFIX) && make && sudo make install) + +deps: libjpeg openssl sqlite pcre curl speex libedit ldns diff --git a/build/Makefile.centos6 b/build/Makefile.centos6 new file mode 100644 index 0000000000..9c27f2e7ad --- /dev/null +++ b/build/Makefile.centos6 @@ -0,0 +1,34 @@ +# +# FreeSWITCH auto-build Makefile (CentOS 6.5/Debian 7 Nike Edition, JUST DO IT!) +# http://www.freeswitch.org +# put this file anywhere and type make to +# create a fully-built freeswitch.git from scratch +# in that same directory. +# +# +RPMS=git gcc-c++ autoconf automake libtool wget python ncurses-devel zlib-devel libjpeg-devel openssl-devel e2fsprogs-devel sqlite-devel libcurl-devel pcre-devel speex-devel ldns-devel libedit-devel +DEBS=git build-essential automake autoconf libtool wget python zlib1g-dev libjpeg-dev libncurses5-dev libssl-dev libpcre3-dev libcurl4-openssl-dev libldns-dev libedit-dev libspeexdsp-dev libspeexdsp-dev libsqlite3-dev + +freeswitch: deps has-git freeswitch.git/Makefile + cd freeswitch.git && make + +freeswitch.git/Makefile: freeswitch.git/configure + cd freeswitch.git && ./configure + +freeswitch.git/configure: freeswitch.git/bootstrap.sh + cd freeswitch.git && sh bootstrap.sh + +freeswitch.git/bootstrap.sh: has-git + test -d freeswitch.git || git clone git://git.freeswitch.org/freeswitch.git freeswitch.git + +rpmforge: + (which rpm && rpm -i http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm) || true + +install: + cd freeswitch.git && make install + +has-git: + @git --version || (echo "please install git" && false) + +deps: rpmforge + ((which yum && yum -y install $(RPMS)) || (which apt-get && apt-get -y install $(DEBS))) || true diff --git a/build/coverity_model.c b/build/coverity_model.c new file mode 100644 index 0000000000..b72daa6639 --- /dev/null +++ b/build/coverity_model.c @@ -0,0 +1,47 @@ +/* Coverity Scan model + * + * This is a modelling file for Coverity Scan. Modelling helps to avoid false + * positives. + * + * - A model file can't import any header files. + * - Therefore only some built-in primitives like int, char and void are + * available but not NULL etc. + * - Modelling doesn't need full structs and typedefs. Rudimentary structs + * and similar types are sufficient. + * - An uninitialised local pointer is not an error. It signifies that the + * variable could be either NULL or have some data. + * + * Coverity Scan doesn't pick up modifications automatically. The model file + * must be uploaded by an admin in the analysis. + * + * Based on: + * http://hg.python.org/cpython/file/tip/Misc/coverity_model.c + * Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, + * 2011, 2012, 2013 Python Software Foundation; All Rights Reserved + * + */ + +/* + * Useful references: + * https://scan.coverity.com/models + */ + +typedef unsigned int switch_status_t; + +struct pthread_mutex_t {}; + +struct switch_mutex +{ + struct pthread_mutex_t lock; +}; +typedef struct switch_mutex switch_mutex_t; + +switch_status_t switch_mutex_lock(switch_mutex_t *lock) +{ + __coverity_recursive_lock_acquire__(&lock->lock); +} + +switch_status_t switch_mutex_unlock(switch_mutex_t *lock) +{ + __coverity_recursive_lock_release__(&lock->lock); +} diff --git a/build/modules.conf.in b/build/modules.conf.in index 953613b2fb..34e16be048 100644 --- a/build/modules.conf.in +++ b/build/modules.conf.in @@ -68,7 +68,7 @@ codecs/mod_vp8 #codecs/mod_ilbc #codecs/mod_isac #codecs/mod_mp4v -#codecs/mod_opus +codecs/mod_opus #codecs/mod_sangoma_codec #codecs/mod_silk #codecs/mod_siren @@ -82,6 +82,7 @@ dialplans/mod_dialplan_xml #endpoints/mod_gsmopen #endpoints/mod_h323 #endpoints/mod_khomp +endpoints/mod_rtc endpoints/mod_loopback #endpoints/mod_opal #endpoints/mod_portaudio @@ -121,6 +122,7 @@ languages/mod_lua #languages/mod_v8 #languages/mod_yaml loggers/mod_console +#loggers/mod_graylog2 loggers/mod_logfile loggers/mod_syslog #say/mod_say_de diff --git a/conf/rayo/autoload_configs/shout.conf.xml b/conf/rayo/autoload_configs/shout.conf.xml index 3f381e6278..c3d1334b68 100644 --- a/conf/rayo/autoload_configs/shout.conf.xml +++ b/conf/rayo/autoload_configs/shout.conf.xml @@ -3,6 +3,7 @@ - + + diff --git a/conf/vanilla/autoload_configs/modules.conf.xml b/conf/vanilla/autoload_configs/modules.conf.xml index e2dce594fa..4cd8f8e1ce 100644 --- a/conf/vanilla/autoload_configs/modules.conf.xml +++ b/conf/vanilla/autoload_configs/modules.conf.xml @@ -90,7 +90,7 @@ - + diff --git a/conf/vanilla/vars.xml b/conf/vanilla/vars.xml index 92c57a2a60..20016cd85f 100644 --- a/conf/vanilla/vars.xml +++ b/conf/vanilla/vars.xml @@ -243,7 +243,7 @@ 127 - BV32 --> - + + + + + + + + + + + + + + diff --git a/src/mod/loggers/mod_graylog2/mod_graylog2.c b/src/mod/loggers/mod_graylog2/mod_graylog2.c new file mode 100644 index 0000000000..44f5286ee8 --- /dev/null +++ b/src/mod/loggers/mod_graylog2/mod_graylog2.c @@ -0,0 +1,347 @@ +/* + * mod_graylog2 for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * Copyright (C) 2014, Grasshopper + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mod_graylog2 for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * + * The Initial Developer of the Original Code is Grasshopper + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Christopher Rienzo + * + * mod_graylog2.c -- Graylog2 GELF logger + * + */ +#include + +#include +#include + +SWITCH_MODULE_LOAD_FUNCTION(mod_graylog2_load); +SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_graylog2_shutdown); +SWITCH_MODULE_DEFINITION(mod_graylog2, mod_graylog2_load, mod_graylog2_shutdown, NULL); + +static struct { + /** memory pool for this module */ + switch_memory_pool_t *pool; + /** graylog2 server address */ + const char *server_host; + /** graylog2 server port */ + switch_port_t server_port; + /** minimum log level to allow */ + switch_log_level_t log_level; + /** shutdown flag */ + int shutdown; + /** prevents context shutdown until all threads are finished */ + switch_thread_rwlock_t *shutdown_rwlock; + /** log delivery queue */ + switch_queue_t *log_queue; +} globals; + +/** + * Convert log level to graylog2 log level + */ +static int to_graylog2_level(switch_log_level_t level) +{ + switch (level) { + case SWITCH_LOG_DEBUG: return 7; + case SWITCH_LOG_INFO: return 6; + case SWITCH_LOG_NOTICE: return 5; + case SWITCH_LOG_WARNING: return 4; + case SWITCH_LOG_ERROR: return 3; + case SWITCH_LOG_CRIT: return 2; + case SWITCH_LOG_ALERT: return 1; + default: return 8; + } +} + +/** + * Encode log as GELF + */ +static char *to_gelf(const switch_log_node_t *node, switch_log_level_t log_level) +{ + char *gelf_text = NULL; + cJSON *gelf = cJSON_CreateObject(); + char *hostname; + char timestamp[32]; + char *full_message = node->content; + char short_message[151]; + char *short_message_end = NULL; + + cJSON_AddItemToObject(gelf, "version", cJSON_CreateString("1.1")); + if ((hostname = switch_core_get_variable("hostname")) && !zstr(hostname)) { + cJSON_AddItemToObject(gelf, "host", cJSON_CreateString(hostname)); + } else if ((hostname = switch_core_get_variable("local_ip_v4")) && !zstr(hostname)) { + cJSON_AddItemToObject(gelf, "host", cJSON_CreateString(hostname)); + } + switch_snprintf(timestamp, 32, "%"SWITCH_UINT64_T_FMT".%d", (uint64_t)(node->timestamp / 1000000), node->timestamp % 1000000); + cJSON_AddItemToObject(gelf, "timestamp", cJSON_CreateString(timestamp)); + cJSON_AddItemToObject(gelf, "level", cJSON_CreateNumber(to_graylog2_level(log_level))); + cJSON_AddItemToObject(gelf, "_ident", cJSON_CreateString("freeswitch")); + cJSON_AddItemToObject(gelf, "_pid", cJSON_CreateNumber((int)getpid())); + if (!zstr(node->userdata)) { + cJSON_AddItemToObject(gelf, "_uuid", cJSON_CreateString(node->userdata)); + } + if (!zstr_buf(node->file)) { + cJSON_AddItemToObject(gelf, "_file", cJSON_CreateString(node->file)); + cJSON_AddItemToObject(gelf, "_line", cJSON_CreateNumber(node->line)); + } + if (!zstr_buf(node->func)) { + cJSON_AddItemToObject(gelf, "_function", cJSON_CreateString(node->func)); + } + + /* skip initial space and new line */ + if (*full_message == ' ') { + full_message++; + } + if (*full_message == '\n') { + full_message++; + } + + cJSON_AddItemToObject(gelf, "full_message", cJSON_CreateString(full_message)); + + switch_snprintf(short_message, sizeof(short_message) - 1, "%s", full_message); + if ((short_message_end = strchr(short_message, '\n'))) { + *short_message_end = '\0'; + } + cJSON_AddItemToObject(gelf, "short_message", cJSON_CreateString(short_message)); + + gelf_text = cJSON_PrintUnformatted(gelf); + cJSON_Delete(gelf); + return gelf_text; +} + +/** + * Open connection to graylog2 server + */ +static switch_socket_t *open_graylog2_socket(const char *host, switch_port_t port, switch_memory_pool_t *pool) +{ + switch_sockaddr_t *graylog2_addr = NULL; + switch_socket_t *graylog2_sock = NULL; + + if (switch_sockaddr_info_get(&graylog2_addr, host, SWITCH_UNSPEC, port, 0, pool) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Bad address: %s:%d\n", host, port); + return NULL; + } + + if (switch_socket_create(&graylog2_sock, switch_sockaddr_get_family(graylog2_addr), SOCK_DGRAM, 0, pool) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open UDP socket\n"); + return NULL; + } + + if (switch_socket_connect(graylog2_sock, graylog2_addr) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to connect to: %s:%d\n", host, port); + switch_socket_close(graylog2_sock); + return NULL; + } + + return graylog2_sock; +} + +/** + * Thread that delivers logs to graylog2 server + * @param thread this thread + * @param obj unused + * @return NULL + */ +static void *SWITCH_THREAD_FUNC deliver_graylog2_thread(switch_thread_t *thread, void *obj) +{ + switch_socket_t *graylog2_sock = NULL; + char *log; + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "graylog2 delivery thread started\n"); + + switch_thread_rwlock_rdlock(globals.shutdown_rwlock); + + graylog2_sock = open_graylog2_socket(globals.server_host, globals.server_port, globals.pool); + if (graylog2_sock) { + while (!globals.shutdown) { + if (switch_queue_pop(globals.log_queue, (void *)&log) == SWITCH_STATUS_SUCCESS) { + if (!zstr(log)) { + switch_size_t len = strlen(log); + if (len <= 8192) { + switch_socket_send_nonblock(graylog2_sock, (void *)log, &len); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Skipping log with length > 8192 bytes\n"); + } + } + switch_safe_free(log); + } + } + } + + globals.shutdown = 1; + + /* clean up remaining logs */ + while(switch_queue_trypop(globals.log_queue, (void *)&log) == SWITCH_STATUS_SUCCESS) { + switch_safe_free(log); + } + + if (graylog2_sock) { + switch_socket_close(graylog2_sock); + } + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "graylog2 delivery thread finished\n"); + switch_thread_rwlock_unlock(globals.shutdown_rwlock); + + return NULL; +} + +/** + * Create a new graylog2 delivery thread + * @param pool to use + */ +static void start_deliver_graylog2_thread(switch_memory_pool_t *pool) +{ + switch_thread_t *thread; + switch_threadattr_t *thd_attr = NULL; + switch_threadattr_create(&thd_attr, pool); + switch_threadattr_detach_set(thd_attr, 1); + switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); + switch_thread_create(&thread, thd_attr, deliver_graylog2_thread, NULL, pool); +} + +/** + * Stop graylog2 delivery thread + */ +static void stop_deliver_graylog2_thread(void) +{ + globals.shutdown = 1; + switch_queue_interrupt_all(globals.log_queue); + switch_thread_rwlock_wrlock(globals.shutdown_rwlock); +} + +/** + * Handle log from core + * @param node the log + * @param level the log level + */ +static switch_status_t mod_graylog2_logger(const switch_log_node_t *node, switch_log_level_t level) +{ + if (!globals.shutdown && level <= globals.log_level && level != SWITCH_LOG_CONSOLE) { + if (!zstr(node->content) && !zstr(node->content + 1)) { + char *log = to_gelf(node, level); + if (switch_queue_trypush(globals.log_queue, log) != SWITCH_STATUS_SUCCESS) { + free(log); + } + } + } + return SWITCH_STATUS_SUCCESS; +} + +/** + * Configure module + */ +static switch_status_t do_config(void) +{ + switch_xml_t cfg, xml, settings; + + if (!(xml = switch_xml_open_cfg("graylog2.conf", &cfg, NULL))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of graylog2.conf failed\n"); + return SWITCH_STATUS_TERM; + } + + /* set defaults */ + globals.log_level = SWITCH_LOG_WARNING; + globals.server_host = "127.0.0.1"; + globals.server_port = 12201; + + if ((settings = switch_xml_child(cfg, "settings"))) { + switch_xml_t param; + for (param = switch_xml_child(settings, "param"); param; param = param->next) { + char *name = (char *) switch_xml_attr_soft(param, "name"); + char *value = (char *) switch_xml_attr_soft(param, "value"); + + if (zstr(name)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring empty param\n"); + continue; + } + + if (zstr(value)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring empty value for param \"%s\"\n", name); + continue; + } + + if (!strcmp(name, "server-host")) { + globals.server_host = switch_core_strdup(globals.pool, value); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\"%s\" = \"%s\"\n", name, value); + } else if (!strcasecmp(name, "server-port")) { + int port = -1; + if (switch_is_number(value)) { + port = atoi(value); + } + if (port > 0 && port <= 65535) { + globals.server_port = port; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\"%s\" = \"%s\"\n", name, value); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid port: \"%s\"\n", value); + } + } else if (!strcasecmp(name, "loglevel")) { + switch_log_level_t log_level = switch_log_str2level(value); + if (log_level == SWITCH_LOG_INVALID) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring invalid log level: \"%s\"\n", value); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\"%s\" = \"%s\"\n", name, value); + globals.log_level = log_level; + } + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring unknown param: \"%s\"\n", name); + } + } + } + switch_xml_free(xml); + return SWITCH_STATUS_SUCCESS; +} + +SWITCH_MODULE_LOAD_FUNCTION(mod_graylog2_load) +{ + *module_interface = switch_loadable_module_create_module_interface(pool, modname); + + memset(&globals, 0, sizeof(globals)); + globals.pool = pool; + + if (do_config() != SWITCH_STATUS_SUCCESS) { + return SWITCH_STATUS_TERM; + } + + switch_thread_rwlock_create(&globals.shutdown_rwlock, pool); + switch_queue_create(&globals.log_queue, 25000, pool); + + start_deliver_graylog2_thread(globals.pool); + switch_log_bind_logger(mod_graylog2_logger, SWITCH_LOG_DEBUG, SWITCH_FALSE); + + return SWITCH_STATUS_SUCCESS; +} + +SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_graylog2_shutdown) +{ + switch_log_unbind_logger(mod_graylog2_logger); + stop_deliver_graylog2_thread(); + + return SWITCH_STATUS_SUCCESS; +} + +/* For Emacs: + * Local Variables: + * mode:c + * indent-tabs-mode:t + * tab-width:4 + * c-basic-offset:4 + * End: + * For VIM: + * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet: + */ diff --git a/src/mod/xml_int/mod_xml_radius/mod_xml_radius.c b/src/mod/xml_int/mod_xml_radius/mod_xml_radius.c index 1ad31a58f4..95b437722c 100644 --- a/src/mod/xml_int/mod_xml_radius/mod_xml_radius.c +++ b/src/mod/xml_int/mod_xml_radius/mod_xml_radius.c @@ -479,7 +479,7 @@ switch_status_t mod_xml_radius_add_params(switch_core_session_t *session, switch if ( GLOBAL_TIME_FORMAT == 1 ) { av_value = switch_mprintf("%02u:%02u:%02u.%03u %s %s %s %02u %04u", tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec/1000, - GLOBAL_TIME_FORMAT, radattrdays[tm.tm_wday], radattrmonths[tm.tm_mon], + GLOBAL_TIME_ZONE, radattrdays[tm.tm_wday], radattrmonths[tm.tm_mon], tm.tm_mday, tm.tm_year + 1900); } else { av_value = switch_mprintf("%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d", diff --git a/src/switch_core_session.c b/src/switch_core_session.c index 15f18c5ab0..61c8ac54e2 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -1547,11 +1547,11 @@ SWITCH_DECLARE(void) switch_core_session_enable_heartbeat(switch_core_session_t session->track_duration = seconds; - if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) || + if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) || !switch_channel_media_ready(session->channel) || switch_true(switch_channel_get_variable_dup(session->channel, "heartbeat_use_scheduler", SWITCH_FALSE, -1)) || switch_true(switch_channel_get_variable_dup(session->channel, "bypass_media", SWITCH_FALSE, -1)) || switch_true(switch_channel_get_variable_dup(session->channel, "bypass_media_after_bridge", SWITCH_FALSE, -1))) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s using scheduler due to bypass_media mode\n", + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s using scheduler due to bypass media or media is not established.\n", switch_channel_get_name(session->channel)); switch_core_session_sched_heartbeat(session, seconds); return; diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index 23ef1a0feb..31e835e760 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -1699,6 +1699,9 @@ SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_destroy(switch_sql_queu SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_push(switch_sql_queue_manager_t *qm, const char *sql, uint32_t pos, switch_bool_t dup) { + char *sqlptr = NULL; + switch_status_t status; + int x = 0; if (sql_manager.paused || qm->thread_running != 1) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "DROP [%s]\n", sql); @@ -1716,10 +1719,20 @@ SWITCH_DECLARE(switch_status_t) switch_sql_queue_manager_push(switch_sql_queue_m pos = 0; } - switch_mutex_lock(qm->mutex); - switch_queue_push(qm->sql_queue[pos], dup ? strdup(sql) : (char *)sql); - switch_mutex_unlock(qm->mutex); + sqlptr = dup ? strdup(sql) : (char *)sql; + do { + switch_mutex_lock(qm->mutex); + status = switch_queue_trypush(qm->sql_queue[pos], sqlptr); + switch_mutex_unlock(qm->mutex); + if (status != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Delay %d sending sql\n", x); + if (x++) { + switch_yield(1000000 * x); + } + } + } while(status != SWITCH_STATUS_SUCCESS); + qm_wake(qm); return SWITCH_STATUS_SUCCESS; @@ -2256,8 +2269,8 @@ static void core_event_handler(switch_event_t *event) break; } case SWITCH_EVENT_CHANNEL_CREATE: - new_sql() = switch_mprintf("insert into channels (uuid,direction,created,created_epoch, name,state,callstate,dialplan,context,hostname) " - "values('%q','%q','%q','%ld','%q','%q','%q','%q','%q','%q')", + new_sql() = switch_mprintf("insert into channels (uuid,direction,created,created_epoch, name,state,callstate,dialplan,context,hostname,initial_cid_name,initial_cid_num,initial_ip_addr,initial_dest,initial_dialplan,initial_context) " + "values('%q','%q','%q','%ld','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q','%q')", switch_event_get_header_nil(event, "unique-id"), switch_event_get_header_nil(event, "call-direction"), switch_event_get_header_nil(event, "event-date-local"), @@ -2266,7 +2279,13 @@ static void core_event_handler(switch_event_t *event) switch_event_get_header_nil(event, "channel-state"), switch_event_get_header_nil(event, "channel-call-state"), switch_event_get_header_nil(event, "caller-dialplan"), - switch_event_get_header_nil(event, "caller-context"), switch_core_get_switchname() + switch_event_get_header_nil(event, "caller-context"), switch_core_get_switchname(), + switch_event_get_header_nil(event, "caller-caller-id-name"), + switch_event_get_header_nil(event, "caller-caller-id-number"), + switch_event_get_header_nil(event, "caller-network-addr"), + switch_event_get_header_nil(event, "caller-destination-number"), + switch_event_get_header_nil(event, "caller-dialplan"), + switch_event_get_header_nil(event, "caller-context") ); break; case SWITCH_EVENT_CHANNEL_ANSWER: @@ -2653,7 +2672,13 @@ static char create_channels_sql[] = " callee_direction VARCHAR(5),\n" " call_uuid VARCHAR(256),\n" " sent_callee_name VARCHAR(1024),\n" - " sent_callee_num VARCHAR(256)\n" + " sent_callee_num VARCHAR(256),\n" + " initial_cid_name VARCHAR(1024),\n" + " initial_cid_num VARCHAR(256),\n" + " initial_ip_addr VARCHAR(256),\n" + " initial_dest VARCHAR(1024),\n" + " initial_dialplan VARCHAR(128),\n" + " initial_context VARCHAR(128)\n" ");\n"; static char create_calls_sql[] = @@ -3372,7 +3397,7 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_ char *err; int result = 0; - switch_cache_db_test_reactive(sql_manager.dbh, "select call_uuid, read_bit_rate, sent_callee_name from channels", "DROP TABLE channels", create_channels_sql); + switch_cache_db_test_reactive(sql_manager.dbh, "select call_uuid, read_bit_rate, sent_callee_name, initial_cid_name, initial_cid_num, initial_ip_addr, initial_dest, initial_dialplan, initial_context from channels", "DROP TABLE channels", create_channels_sql); switch_cache_db_test_reactive(sql_manager.dbh, "select * from detailed_calls where sent_callee_name=''", "DROP VIEW detailed_calls", detailed_calls_sql); switch_cache_db_test_reactive(sql_manager.dbh, "select * from basic_calls where sent_callee_name=''", "DROP VIEW basic_calls", basic_calls_sql); switch_cache_db_test_reactive(sql_manager.dbh, "select call_uuid from calls", "DROP TABLE calls", create_calls_sql); diff --git a/src/switch_nat.c b/src/switch_nat.c index 2b95f8b959..c998c60b8b 100644 --- a/src/switch_nat.c +++ b/src/switch_nat.c @@ -585,6 +585,7 @@ SWITCH_DECLARE(switch_status_t) switch_nat_add_mapping_internal(switch_port_t po switch_status_t status = SWITCH_STATUS_FALSE; switch_event_t *event = NULL; + if (!initialized || !nat_globals.nat_type) return status; if (!nat_globals.mapping) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "NAT port mapping disabled\n"); return status;