From 89a2ca8d008c4782d7e1895ead7f2d63d2b9036b Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 5 May 2011 18:17:30 -0400 Subject: [PATCH 1/7] rename to NBE SS7 --- libs/esl/fs_cli.c | 22 +++++++++++----------- src/mod/endpoints/mod_sofia/mod_sofia.h | 2 +- src/switch.c | 4 ++-- src/switch_core.c | 21 ++++++++++----------- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/libs/esl/fs_cli.c b/libs/esl/fs_cli.c index 8006297ddd..d7130fd2d2 100644 --- a/libs/esl/fs_cli.c +++ b/libs/esl/fs_cli.c @@ -8,7 +8,7 @@ #include #define CMD_BUFLEN 1024 -#define PROMPT_PREFIX "sangoma-media-gateway" +#define PROMPT_PREFIX "netborder-ss7" static int WARN_STOP = 0; #ifdef WIN32 @@ -854,7 +854,7 @@ static void print_banner(FILE *stream) "\n" "*******************************************************\n" - "* Sangoma Media Gateway *\n" + "* Netborder SS7 Gateway *\n" "* Powered by FreeSWITCH (http://www.freeswitch.org) *\n" "*******************************************************\n" "\n" @@ -1002,13 +1002,13 @@ int main(int argc, char *argv[]) int rv = 0; #ifndef WIN32 - char hfile[512] = "/etc/smg_cli_history"; - char cfile[512] = "/etc/smg_cli.conf"; - char dft_cfile[512] = "/etc/smg_cli.conf"; + char hfile[512] = "/etc/nbess7_cli_history"; + char cfile[512] = "/etc/nbess7_cli.conf"; + char dft_cfile[512] = "/etc/nbess7_cli.conf"; #else - char hfile[512] = "smg_cli_history"; - char cfile[512] = "smg_cli.conf"; - char dft_cfile[512] = "smg_cli.conf"; + char hfile[512] = "nbess7_cli_history"; + char cfile[512] = "nbess7_cli.conf"; + char dft_cfile[512] = "nbess7_cli.conf"; #endif char *home = getenv("HOME"); /* Vars for optargs */ @@ -1054,8 +1054,8 @@ int main(int argc, char *argv[]) if (home) { - snprintf(hfile, sizeof(hfile), "%s/.smg_cli_history", home); - snprintf(cfile, sizeof(cfile), "%s/.smg_cli_conf", home); + snprintf(hfile, sizeof(hfile), "%s/.nbess7_cli_history", home); + snprintf(cfile, sizeof(cfile), "%s/.nbess7_cli_conf", home); } signal(SIGINT, handle_SIGINT); @@ -1368,7 +1368,7 @@ int main(int argc, char *argv[]) print_banner(stdout); - esl_log(ESL_LOG_INFO, "Sangoma Media Gateway CLI Ready.\nenter /help for a list of commands.\n"); + esl_log(ESL_LOG_INFO, "Netborder SS7 CLI Ready.\nenter /help for a list of commands.\n"); printf("%s\n", handle.last_sr_reply); while (running > 0) { diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 01aa8412a1..75efdd6e40 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -90,7 +90,7 @@ typedef struct private_object private_object_t; #define MULTICAST_EVENT "multicast::event" #define SOFIA_REPLACES_HEADER "_sofia_replaces_" -#define SOFIA_USER_AGENT "SangomaMediaGateway/" SWITCH_VERSION_MAJOR "." SWITCH_VERSION_MINOR "." SWITCH_VERSION_MICRO "-" SWITCH_VERSION_REVISION +#define SOFIA_USER_AGENT "NetborderSS7/" SWITCH_VERSION_MAJOR "." SWITCH_VERSION_MINOR "." SWITCH_VERSION_MICRO "-" SWITCH_VERSION_REVISION #define SOFIA_CHAT_PROTO "sip" #define SOFIA_MULTIPART_PREFIX "sip_mp_" #define SOFIA_MULTIPART_PREFIX_T "~sip_mp_" diff --git a/src/switch.c b/src/switch.c index de99a905e5..7633fcae9f 100644 --- a/src/switch.c +++ b/src/switch.c @@ -48,7 +48,7 @@ #include "private/switch_core_pvt.h" /* pid filename: Stores the process id of the freeswitch process */ -#define PIDFILE "sangoma-media-gateway.pid" +#define PIDFILE "netborder-ss7.pid" static char *pfile = PIDFILE; static int system_ready = 0; @@ -540,7 +540,7 @@ int main(int argc, char *argv[]) } if (local_argv[x] && !strcmp(local_argv[x], "-version")) { - fprintf(stdout, "Sangoma Media Gateway Version: %s\n", SWITCH_VERSION_FULL); + fprintf(stdout, "Netborder SS7 Version: %s\n", SWITCH_VERSION_FULL); return 0; known_opt++; } diff --git a/src/switch_core.c b/src/switch_core.c index 07aca5752e..0d7bfa8a11 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -1758,17 +1758,16 @@ SWITCH_DECLARE(const char *) switch_core_banner(void) "* Brought to you by ClueCon http://www.cluecon.com/ *\n" "************************************************************\n" "\n"); #else return ( -"\n _____ ___ ___ _ _ _____ _ \n" -"/ ___| | \\/ | | (_) | __ \\ | | \n" -"\\ `--. __ _ _ __ __ _ ___ _ __ ___ __ _ | . . | ___ __| |_ __ _ | | \\/ __ _| |_ _____ ____ _ _ _ \n" -" `--. \\/ _` | '_ \\ / _` |/ _ \\| '_ ` _ \\ / _` | | |\\/| |/ _ \\/ _` | |/ _` | | | __ / _` | __|/ _ \\ \\ /\\ / / _` | | | |\n" -"/\\__/ / (_| | | | | (_| | (_) | | | | | | (_| | | | | | __/ (_| | | (_| | | |_\\ \\ (_| | |_| __/\\ V V / (_| | |_| |\n" -"\\____/ \\__,_|_| |_|\\__, |\\___/|_| |_| |_|\\__,_| \\_| |_/\\___|\\__,_|_|\\__,_| \\____/\\__,_|\\__|\\___| \\_/\\_/ \\__,_|\\__, |\n" -" __/ | __/ |\n" -" |___/ |___/ \n" - "************************************************************\n" - "* Powered by: FreeSWITCH (http://www.freeswitch.org) *\n" - "************************************************************\n" "\n"); + "************************************************************************\n" + "* .__ __. .______ _______ _______. _______. ______ *\n" + "* | \ | | | _ \ | ____| / | / ||____ |*\n" + "* | \| | | |_) | | |__ | (----` | (----` / / *\n" + "* | . ` | | _ < | __| \ \ \ \ / / *\n" + "* | |\ | | |_) | | |____ .----) | .----) | / / *\n" + "* |__| \__| |______/ |_______| |_______/ |_______/ /_/ *\n" + "* *\n" + "* Powered by: FreeSWITCH (http://www.freeswitch.org) *\n" + "**************************************************************************\n" "\n"); #endif } From 42d40227d93ca7500518161904e76757c6e7c5ba Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 5 May 2011 18:25:47 -0400 Subject: [PATCH 2/7] fix banner --- src/switch_core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/switch_core.c b/src/switch_core.c index 0d7bfa8a11..3c7f70c8dd 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -1760,11 +1760,11 @@ SWITCH_DECLARE(const char *) switch_core_banner(void) return ( "************************************************************************\n" "* .__ __. .______ _______ _______. _______. ______ *\n" - "* | \ | | | _ \ | ____| / | / ||____ |*\n" - "* | \| | | |_) | | |__ | (----` | (----` / / *\n" - "* | . ` | | _ < | __| \ \ \ \ / / *\n" - "* | |\ | | |_) | | |____ .----) | .----) | / / *\n" - "* |__| \__| |______/ |_______| |_______/ |_______/ /_/ *\n" + "* | \\ | | | _ \\ | ____| / | / ||____ |*\n" + "* | \\| | | |_) | | |__ | (----` | (----` / / *\n" + "* | . ` | | _ < | __| \\ \\ \\ \\ / / *\n" + "* | |\\ | | |_) | | |____ .----) | .----) | / / *\n" + "* |__| \\__| |______/ |_______| |_______/ |_______/ /_/ *\n" "* *\n" "* Powered by: FreeSWITCH (http://www.freeswitch.org) *\n" "**************************************************************************\n" "\n"); From a8d1b80b83bb7a8ae66d883d5733351513065acd Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 5 May 2011 19:33:02 -0400 Subject: [PATCH 3/7] remove pid file when failing to load modules --- src/switch.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/switch.c b/src/switch.c index 7633fcae9f..f5ffe950e2 100644 --- a/src/switch.c +++ b/src/switch.c @@ -921,7 +921,10 @@ int main(int argc, char *argv[]) switch_file_write(fd, pid_buffer, &pid_len); if (switch_core_init_and_modload(flags, nc ? SWITCH_FALSE : SWITCH_TRUE, &err) != SWITCH_STATUS_SUCCESS) { - fprintf(stderr, "Cannot Initialize [%s]\n", err); + fprintf(stderr, "Cannot Initialize [%s], deleting pid file [%s]\n", err, pid_path); + if (unlink(pid_path) != 0) { + fprintf(stderr, "Failed to delete pid file [%s]\n", pid_path); + } return 255; } From 034cb7a6870f4075ccc52c5c86cbdbf6ba08ea69 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 9 May 2011 12:39:53 -0400 Subject: [PATCH 4/7] Added modified build/modules.conf.in --- build/modules.conf.in | 114 ++---------------------------------------- 1 file changed, 4 insertions(+), 110 deletions(-) diff --git a/build/modules.conf.in b/build/modules.conf.in index d31bb31b76..1d27aaad1b 100644 --- a/build/modules.conf.in +++ b/build/modules.conf.in @@ -1,119 +1,13 @@ loggers/mod_console loggers/mod_logfile loggers/mod_syslog -#applications/mod_cidlookup -applications/mod_commands -applications/mod_conference applications/mod_dptools -applications/mod_enum -#applications/mod_osp -applications/mod_fifo -#applications/mod_curl -applications/mod_db +applications/mod_commands applications/mod_hash -#applications/mod_redis -applications/mod_voicemail -#applications/mod_directory -#applications/mod_lcr -applications/mod_expr -applications/mod_esf -#applications/mod_easyroute -applications/mod_fsv -#applications/mod_nibblebill -#applications/mod_soundtouch -#applications/mod_rss applications/mod_spandsp -#applications/mod_snom -#applications/mod_vmd -#applications/mod_avmd -#applications/mod_memcache -#applications/mod_spy -applications/mod_cluechoo -applications/mod_valet_parking -#applications/mod_distributor -#applications/mod_stress -#applications/mod_snapshot -#applications/mod_snipe_hunt -#applications/mod_callcenter -#applications/mod_fsk -#applications/mod_ladspa -codecs/mod_g723_1 -codecs/mod_amr -#codecs/mod_amrwb -#codecs/mod_silk -#codecs/mod_codec2 -codecs/mod_g729 -#codecs/mod_com_g729 -codecs/mod_h26x -codecs/mod_bv -codecs/mod_ilbc -codecs/mod_speex -codecs/mod_siren -#codecs/mod_celt -#codecs/mod_opus -#codecs/mod_sangoma_codec -#codecs/mod_dahdi_codec -#dialplans/mod_dialplan_directory dialplans/mod_dialplan_xml -dialplans/mod_dialplan_asterisk -#directories/mod_ldap -#endpoints/mod_dingaling -#endpoints/mod_portaudio endpoints/mod_sofia -endpoints/mod_loopback -#endpoints/mod_alsa -#endpoints/mod_opal -#endpoints/mod_skinny -#endpoints/mod_skypopen -#endpoints/mod_h323 -#endpoints/mod_khomp -#../../libs/openzap/mod_openzap -#../../libs/freetdm/mod_freetdm -#asr_tts/mod_unimrcp -#asr_tts/mod_flite -#asr_tts/mod_pocketsphinx -#asr_tts/mod_cepstral -#asr_tts/mod_tts_commandline -#event_handlers/mod_event_multicast -event_handlers/mod_event_socket -#event_handlers/mod_event_zmq -event_handlers/mod_cdr_csv -event_handlers/mod_cdr_sqlite -#event_handlers/mod_cdr_pg_csv -#event_handlers/mod_radius_cdr -#event_handlers/mod_erlang_event -#event_handlers/mod_snmp -formats/mod_native_file -formats/mod_sndfile -#formats/mod_shout -formats/mod_local_stream -formats/mod_tone_stream -#formats/mod_portaudio_stream -#formats/mod_shell_stream -#languages/mod_python -languages/mod_spidermonkey -languages/mod_lua -#languages/mod_perl -#languages/mod_yaml -#languages/mod_java -#languages/mod_managed -xml_int/mod_xml_rpc -#xml_int/mod_xml_curl +../../libs/freetdm/mod_freetdm xml_int/mod_xml_cdr -#xml_int/mod_xml_ldap -say/mod_say_en -#say/mod_say_de -#say/mod_say_es -#say/mod_say_fr -#say/mod_say_it -#say/mod_say_nl -#say/mod_say_pt -#say/mod_say_ru -#say/mod_say_zh -#say/mod_say_hu -#say/mod_say_th -#say/mod_say_he -#timers/mod_timerfd - -## Experimental Modules (don't cry if they're broken) -#../../contrib/mod/xml_int/mod_xml_odbc +event_handlers/mod_event_socket +codecs/mod_sangoma_codec From 0bdf79b17c8ed811b0a75f537e58bab63d7d0f94 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 17 May 2011 14:17:00 -0400 Subject: [PATCH 5/7] mod_sangoma_codec: AMR codec fixes - Set the proper RTP payload - Do not validate RTP reads when the size is dynamic (zero) --- src/mod/codecs/mod_sangoma_codec/mod_sangoma_codec.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/mod/codecs/mod_sangoma_codec/mod_sangoma_codec.c b/src/mod/codecs/mod_sangoma_codec/mod_sangoma_codec.c index dd97453c7a..5b12eb6448 100644 --- a/src/mod/codecs/mod_sangoma_codec/mod_sangoma_codec.c +++ b/src/mod/codecs/mod_sangoma_codec/mod_sangoma_codec.c @@ -96,7 +96,7 @@ vocallo_codec_t g_codec_map[] = /* manually initialized */ { SNGTC_CODEC_GSM_FR, IANA_GSM_A_8000_1, "GSM", "Sangoma GSM", 20, 13200, 20000, 160, 320, 33, 8000, 8000, 0 }, { SNGTC_CODEC_G723_1_63, IANA_G723_A_8000_1, "G723", "Sangoma G723", 90, 6300, 30000, 240, 480, 24, 8000, 8000, 0 }, - { SNGTC_CODEC_AMR_1220, IANA_AMR_WB_16000_1, "AMR", "Sangoma AMR", 20, 12200, 20000, 160, 320, 0, 8000, 8000, 0 }, + { SNGTC_CODEC_AMR_1220, IANA_AMR_A_8000_1, "AMR", "Sangoma AMR", 20, 12200, 20000, 160, 320, 0, 8000, 8000, 0 }, { SNGTC_CODEC_SIREN7_24, IANA_SIREN7, "G7221", "Sangoma G722.1", 20, 24000, 20000, 320, 640, 60, 16000, 16000, 0 }, { SNGTC_CODEC_SIREN7_32, IANA_SIREN7, "G7221", "Sangoma G722.1", 20, 32000, 20000, 320, 640, 80, 16000, 16000, 0 }, { SNGTC_CODEC_ILBC_133, IANA_ILBC_133_8000_1, "iLBC", "Sangoma iLBC", 30, 13300, 30000, 240, 480, 50, 8000, 8000, 0 }, @@ -131,6 +131,7 @@ struct codec_data { /* packet counters */ unsigned long tx; unsigned long rx; + unsigned long ticks; /* Lost packets */ long lastrxseqno; @@ -467,6 +468,8 @@ static switch_status_t switch_sangoma_encode(switch_codec_t *codec, switch_codec func_start_time = switch_micro_time_now(); } + sess->encoder.ticks++; + /* start assuming we will not encode anything */ *encoded_data_len = 0; @@ -547,7 +550,7 @@ static switch_status_t switch_sangoma_encode(switch_codec_t *codec, switch_codec continue; } - if (encoded_frame.datalen != codec->implementation->encoded_bytes_per_packet) { + if (codec->implementation->encoded_bytes_per_packet && encoded_frame.datalen != codec->implementation->encoded_bytes_per_packet) { /* seen when silence suppression is enabled */ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Ignoring encoded frame of %d bytes intead of %d bytes\n", encoded_frame.datalen, codec->implementation->encoded_bytes_per_packet); continue; @@ -619,7 +622,7 @@ static switch_status_t switch_sangoma_encode(switch_codec_t *codec, switch_codec sess->encoder.rtp_queue[sess->encoder.queue_rindex].datalen = 0; SAFE_INDEX_INC(sess->encoder.rtp_queue, sess->encoder.queue_rindex); sess->encoder.queue_size--; - if (*encoded_data_len != codec->implementation->encoded_bytes_per_packet) { + if (codec->implementation->encoded_bytes_per_packet && *encoded_data_len != codec->implementation->encoded_bytes_per_packet) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Returning odd encoded frame of %d bytes intead of %d bytes\n", *encoded_data_len, codec->implementation->encoded_bytes_per_packet); } } else { @@ -667,6 +670,7 @@ static switch_status_t switch_sangoma_decode(switch_codec_t *codec, /* codec ses } dbuf_linear = decoded_data; + sess->decoder.ticks++; /* start assuming we will not decode anything */ *decoded_data_len = 0; @@ -989,6 +993,7 @@ SWITCH_STANDARD_API(sangoma_function) stream->write_function(stream, "Rx %s at %d.%d.%d.%d:%d from %d.%d.%d.%d:%d\n\n", sess->impl->iananame, SNGTC_NIPV4(sess->encoder.reply.b.host_ip), sess->encoder.reply.b.host_udp_port, SNGTC_NIPV4(sess->encoder.reply.b.codec_ip), sess->encoder.reply.b.codec_udp_port); + stream->write_function(stream, "Ticks: %lu\n", sess->encoder.ticks); stream->write_function(stream, "-- Inbound Stats --\n"); stream->write_function(stream, "Rx Discarded: %lu\n", sess->encoder.rxdiscarded); @@ -1008,6 +1013,7 @@ SWITCH_STANDARD_API(sangoma_function) SNGTC_NIPV4(sess->decoder.reply.a.codec_ip), sess->decoder.reply.a.codec_udp_port); stream->write_function(stream, "Rx L16 at %d.%d.%d.%d:%d from %d.%d.%d.%d:%d\n\n", SNGTC_NIPV4(sess->decoder.reply.b.host_ip), sess->decoder.reply.b.host_udp_port, SNGTC_NIPV4(sess->decoder.reply.b.codec_ip), sess->decoder.reply.b.codec_udp_port); + stream->write_function(stream, "Ticks: %lu\n", sess->decoder.ticks); stream->write_function(stream, "-- Inbound Stats --\n"); stream->write_function(stream, "Rx Discarded: %lu\n", sess->decoder.rxdiscarded); From 7db91251c8dbed559ca2b62e89daaf5a5c61d7b7 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Mon, 30 May 2011 18:49:15 -0400 Subject: [PATCH 6/7] modified switch.c to not create PID file until all modules are loaded this help init scripts to check when everything is really loaded. Also return 1 when loading modules fails, do not return 255 which can be confused with a segmentation fault or some other more violent code --- src/switch.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/switch.c b/src/switch.c index f5ffe950e2..5b71b64e8d 100644 --- a/src/switch.c +++ b/src/switch.c @@ -894,6 +894,11 @@ int main(int argc, char *argv[]) switch_dir_make_recursive(SWITCH_GLOBAL_dirs.run_dir, SWITCH_DEFAULT_DIR_PERMS, pool); + if (switch_core_init_and_modload(flags, nc ? SWITCH_FALSE : SWITCH_TRUE, &err) != SWITCH_STATUS_SUCCESS) { + fprintf(stderr, "Failed to initialize modules: %s\n", err); + return 1; + } + if (switch_file_open(&fd, pid_path, SWITCH_FOPEN_READ, SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE, pool) == SWITCH_STATUS_SUCCESS) { old_pid_len = sizeof(old_pid_buffer); @@ -920,14 +925,6 @@ int main(int argc, char *argv[]) switch_file_write(fd, pid_buffer, &pid_len); - if (switch_core_init_and_modload(flags, nc ? SWITCH_FALSE : SWITCH_TRUE, &err) != SWITCH_STATUS_SUCCESS) { - fprintf(stderr, "Cannot Initialize [%s], deleting pid file [%s]\n", err, pid_path); - if (unlink(pid_path) != 0) { - fprintf(stderr, "Failed to delete pid file [%s]\n", pid_path); - } - return 255; - } - #ifndef WIN32 if (do_wait) { kill(getppid(), SIGUSR2); From 86072ad4edb1b1cee4bd91327ad6a334ef62fcb7 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 31 May 2011 19:56:50 -0400 Subject: [PATCH 7/7] freetdm: added fail-on-error global configuration to refuse to load the module if there is any error --- libs/freetdm/conf/freetdm.conf.xml | 5 + libs/freetdm/mod_freetdm/mod_freetdm.c | 192 +++++++------------------ 2 files changed, 59 insertions(+), 138 deletions(-) diff --git a/libs/freetdm/conf/freetdm.conf.xml b/libs/freetdm/conf/freetdm.conf.xml index 7d5de5a189..29232d927b 100644 --- a/libs/freetdm/conf/freetdm.conf.xml +++ b/libs/freetdm/conf/freetdm.conf.xml @@ -18,6 +18,11 @@ with the signaling protocols that you can run on top of your I/O interfaces. --> + + diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c index 8739c4c0bf..890ca504e5 100755 --- a/libs/freetdm/mod_freetdm/mod_freetdm.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -88,6 +88,8 @@ static struct { switch_hash_t *ss7_configs; int sip_headers; uint8_t crash_on_assert; + uint8_t fail_on_error; + uint8_t config_error; } globals; /* private data attached to each fs session */ @@ -2302,6 +2304,10 @@ static uint32_t enable_analog_option(const char *str, uint32_t current_options) } +#define CONFIG_ERROR(...) do { \ + ftdm_log(FTDM_LOG_ERROR, __VA_ARGS__); \ + globals.config_error = 1; \ + } while(0) /* create ftdm_conf_node_t tree based on a fixed pattern XML configuration list * last 2 args are for limited aka dumb recursivity * */ @@ -2494,7 +2500,7 @@ static int add_profile_parameters(switch_xml_t cfg, const char *profname, ftdm_c profnode = switch_xml_child(cfg, "config_profiles"); if (!profnode) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cannot find profile '%s', there is no 'config_profiles' XML section\n", profname); + CONFIG_ERROR("cannot find profile '%s', there is no 'config_profiles' XML section\n", profname); return 0; } @@ -2510,7 +2516,7 @@ static int add_profile_parameters(switch_xml_t cfg, const char *profname, ftdm_c } if (!profile) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed to find profile '%s'\n", profname); + CONFIG_ERROR("failed to find profile '%s'\n", profname); return 0; } @@ -2545,7 +2551,7 @@ static void parse_bri_pri_spans(switch_xml_t cfg, switch_xml_t spans) unsigned paramindex = 0; if (!name && !id) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "sangoma isdn span missing required attribute 'id' or 'name', skipping ...\n"); + CONFIG_ERROR("sangoma isdn span missing required attribute 'id' or 'name', skipping ...\n"); continue; } @@ -2563,7 +2569,7 @@ static void parse_bri_pri_spans(switch_xml_t cfg, switch_xml_t spans) } if (zstatus != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error finding FreeTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + CONFIG_ERROR("Error finding FreeTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -2590,7 +2596,7 @@ static void parse_bri_pri_spans(switch_xml_t cfg, switch_xml_t spans) char *val = (char *) switch_xml_attr_soft(param, "value"); if (ftdm_array_len(spanparameters) - 1 == paramindex) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Too many parameters for ss7 span, ignoring any parameter after %s\n", var); + CONFIG_ERROR("Too many parameters for ss7 span, ignoring any parameter after %s\n", var); break; } @@ -2605,10 +2611,10 @@ static void parse_bri_pri_spans(switch_xml_t cfg, switch_xml_t spans) int calls; int seconds; if (sscanf(val, "%d/%d", &calls, &seconds) != 2) { - ftdm_log(FTDM_LOG_ERROR, "Invalid %s parameter, format example: 3/1 for 3 calls per second\n", var); + CONFIG_ERROR("Invalid %s parameter, format example: 3/1 for 3 calls per second\n", var); } else { if (calls < 1 || seconds < 1) { - ftdm_log(FTDM_LOG_ERROR, "Invalid %s parameter value, minimum call limit must be 1 per second\n", var); + CONFIG_ERROR("Invalid %s parameter value, minimum call limit must be 1 per second\n", var); } else { SPAN_CONFIG[span_id].limit_calls = calls; SPAN_CONFIG[span_id].limit_seconds = seconds; @@ -2618,7 +2624,7 @@ static void parse_bri_pri_spans(switch_xml_t cfg, switch_xml_t spans) if (!strcasecmp(val, "answer")) { SPAN_CONFIG[span_id].limit_reset_event = FTDM_LIMIT_RESET_ON_ANSWER; } else { - ftdm_log(FTDM_LOG_ERROR, "Invalid %s parameter value, only accepted event is 'answer'\n", var); + CONFIG_ERROR("Invalid %s parameter value, only accepted event is 'answer'\n", var); } } else { spanparameters[paramindex].var = var; @@ -2631,7 +2637,7 @@ static void parse_bri_pri_spans(switch_xml_t cfg, switch_xml_t spans) "sangoma_isdn", on_clear_channel_signal, spanparameters) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error configuring Sangoma ISDN FreeTDM span %d\n", span_id); + CONFIG_ERROR("Error configuring Sangoma ISDN FreeTDM span %d\n", span_id); continue; } SPAN_CONFIG[span_id].span = span; @@ -2648,15 +2654,11 @@ static switch_status_t load_config(void) const char *cf = "freetdm.conf"; switch_xml_t cfg, xml, settings, param, spans, myspan; ftdm_conf_node_t *ss7confnode = NULL; - ftdm_span_t *boost_spans[FTDM_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN]; - ftdm_span_t *boost_span = NULL; - unsigned boosti = 0; unsigned int i = 0; ftdm_channel_t *fchan = NULL; ftdm_iterator_t *chaniter = NULL; ftdm_iterator_t *curr = NULL; - memset(boost_spans, 0, sizeof(boost_spans)); memset(&globals, 0, sizeof(globals)); switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool); if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { @@ -2675,6 +2677,8 @@ static switch_status_t load_config(void) switch_set_string(globals.hold_music, val); } else if (!strcasecmp(var, "crash-on-assert")) { globals.crash_on_assert = switch_true(val); + } else if (!strcasecmp(var, "fail-on-error")) { + globals.fail_on_error = switch_true(val); } else if (!strcasecmp(var, "sip-headers")) { globals.sip_headers = switch_true(val); } else if (!strcasecmp(var, "enable-analog-option")) { @@ -2705,11 +2709,11 @@ static switch_status_t load_config(void) uint32_t span_id = 0; unsigned paramindex = 0; if (!name && !id) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ss7 span missing required attribute 'id' or 'name', skipping ...\n"); + CONFIG_ERROR("ss7 span missing required attribute 'id' or 'name', skipping ...\n"); continue; } if (!configname) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ss7 span missing required attribute, skipping ...\n"); + CONFIG_ERROR("ss7 span missing required attribute, skipping ...\n"); continue; } if (name) { @@ -2726,7 +2730,7 @@ static switch_status_t load_config(void) } if (zstatus != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error finding FreeTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + CONFIG_ERROR("Error finding FreeTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -2736,7 +2740,7 @@ static switch_status_t load_config(void) ss7confnode = get_ss7_config_node(cfg, configname); if (!ss7confnode) { - ftdm_log(FTDM_LOG_ERROR, "Error finding ss7config '%s' for FreeTDM span id: %s\n", configname, switch_str_nil(id)); + CONFIG_ERROR("Error finding ss7config '%s' for FreeTDM span id: %s\n", configname, switch_str_nil(id)); continue; } @@ -2750,7 +2754,7 @@ static switch_status_t load_config(void) char *val = (char *) switch_xml_attr_soft(param, "value"); if (ftdm_array_len(spanparameters) - 1 == paramindex) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Too many parameters for ss7 span, ignoring any parameter after %s\n", var); + CONFIG_ERROR("Too many parameters for ss7 span, ignoring any parameter after %s\n", var); break; } @@ -2769,7 +2773,7 @@ static switch_status_t load_config(void) "sangoma_ss7", on_clear_channel_signal, spanparameters) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error configuring ss7 FreeTDM span %d\n", span_id); + CONFIG_ERROR("Error configuring ss7 FreeTDM span %d\n", span_id); continue; } SPAN_CONFIG[span_id].span = span; @@ -2820,7 +2824,7 @@ static switch_status_t load_config(void) } if (zstatus != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error finding FreeTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + CONFIG_ERROR("Error finding FreeTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -2854,10 +2858,10 @@ static switch_status_t load_config(void) int calls; int seconds; if (sscanf(val, "%d/%d", &calls, &seconds) != 2) { - ftdm_log(FTDM_LOG_ERROR, "Invalid %s parameter, format example: 3/1 for 3 calls per second\n", var); + CONFIG_ERROR("Invalid %s parameter, format example: 3/1 for 3 calls per second\n", var); } else { if (calls < 1 || seconds < 1) { - ftdm_log(FTDM_LOG_ERROR, "Invalid %s parameter value, minimum call limit must be 1 per second\n", var); + CONFIG_ERROR("Invalid %s parameter value, minimum call limit must be 1 per second\n", var); } else { SPAN_CONFIG[span_id].limit_calls = calls; SPAN_CONFIG[span_id].limit_seconds = seconds; @@ -2867,7 +2871,7 @@ static switch_status_t load_config(void) if (!strcasecmp(val, "answer")) { SPAN_CONFIG[span_id].limit_reset_event = FTDM_LIMIT_RESET_ON_ANSWER; } else { - ftdm_log(FTDM_LOG_ERROR, "Invalid %s parameter value, only accepted event is 'answer'\n", var); + CONFIG_ERROR("Invalid %s parameter value, only accepted event is 'answer'\n", var); } } else if (!strcasecmp(var, "dial-regex")) { dial_regex = val; @@ -2895,7 +2899,7 @@ static switch_status_t load_config(void) } if (!id && !name) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); + CONFIG_ERROR("span missing required param 'id'\n"); continue; } @@ -2925,7 +2929,7 @@ static switch_status_t load_config(void) } if (zstatus != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error finding FreeTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + CONFIG_ERROR("Error finding FreeTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -2945,7 +2949,7 @@ static switch_status_t load_config(void) "callwaiting", &callwaiting, "wait_dialtone_timeout", &dialtone_timeout, FTDM_TAG_END) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error configuring FreeTDM analog span %s\n", ftdm_span_get_name(span)); + CONFIG_ERROR("Error configuring FreeTDM analog span %s\n", ftdm_span_get_name(span)); continue; } @@ -3021,7 +3025,7 @@ static switch_status_t load_config(void) } if (!id && !name) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required param 'id'\n"); + CONFIG_ERROR("span missing required param 'id'\n"); continue; } @@ -3053,7 +3057,7 @@ static switch_status_t load_config(void) } if (zstatus != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error finding FreeTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); + CONFIG_ERROR("Error finding FreeTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); continue; } @@ -3067,7 +3071,7 @@ static switch_status_t load_config(void) "digit_timeout", &to, "max_dialstr", &max, FTDM_TAG_END) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error starting FreeTDM span %d\n", span_id); + CONFIG_ERROR("Error starting FreeTDM span %d\n", span_id); continue; } @@ -3104,7 +3108,7 @@ static switch_status_t load_config(void) uint32_t span_id = 0; if (!name) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required attribute 'name'\n"); + CONFIG_ERROR("span missing required attribute 'name'\n"); continue; } @@ -3115,7 +3119,7 @@ static switch_status_t load_config(void) char *val = (char *) switch_xml_attr_soft(param, "value"); if (ftdm_array_len(spanparameters) - 1 == paramindex) { - ftdm_log(FTDM_LOG_ERROR, "Too many parameters for pri span '%s', ignoring everything after '%s'\n", name, var); + CONFIG_ERROR("Too many parameters for pri span '%s', ignoring everything after '%s'\n", name, var); break; } @@ -3137,13 +3141,13 @@ static switch_status_t load_config(void) zstatus = ftdm_span_find_by_name(name, &span); if (zstatus != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error finding FreeTDM span %s\n", name); + CONFIG_ERROR("Error finding FreeTDM span %s\n", name); continue; } span_id = ftdm_span_get_id(span); if (ftdm_configure_span_signaling(span, "isdn", on_clear_channel_signal, spanparameters) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error configuring FreeTDM span %s\n", name); + CONFIG_ERROR("Error configuring FreeTDM span %s\n", name); continue; } @@ -3170,7 +3174,7 @@ static switch_status_t load_config(void) int span_id = 0; if (!name) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required attribute 'name'\n"); + CONFIG_ERROR("span missing required attribute 'name'\n"); continue; } @@ -3181,7 +3185,7 @@ static switch_status_t load_config(void) char *val = (char *) switch_xml_attr_soft(param, "value"); if (ftdm_array_len(spanparameters) - 1 == paramindex) { - ftdm_log(FTDM_LOG_ERROR, "Too many parameters for pritap span '%s', ignoring everything after '%s'\n", name, var); + CONFIG_ERROR("Too many parameters for pritap span '%s', ignoring everything after '%s'\n", name, var); break; } @@ -3198,13 +3202,13 @@ static switch_status_t load_config(void) zstatus = ftdm_span_find_by_name(name, &span); if (zstatus != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error finding FreeTDM span %s\n", name); + CONFIG_ERROR("Error finding FreeTDM span %s\n", name); continue; } span_id = ftdm_span_get_id(span); if (ftdm_configure_span_signaling(span, "pritap", on_clear_channel_signal, spanparameters) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error configuring FreeTDM span %s\n", name); + CONFIG_ERROR("Error configuring FreeTDM span %s\n", name); continue; } @@ -3230,7 +3234,7 @@ static switch_status_t load_config(void) uint32_t span_id = 0; if (!name) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "span missing required attribute 'name'\n"); + CONFIG_ERROR("span missing required attribute 'name'\n"); continue; } @@ -3241,7 +3245,7 @@ static switch_status_t load_config(void) char *val = (char *) switch_xml_attr_soft(param, "value"); if (ftdm_array_len(spanparameters) - 1 == paramindex) { - ftdm_log(FTDM_LOG_ERROR, "Too many parameters for libpri span, ignoring everything after '%s'\n", var); + CONFIG_ERROR("Too many parameters for libpri span, ignoring everything after '%s'\n", var); break; } @@ -3263,13 +3267,13 @@ static switch_status_t load_config(void) zstatus = ftdm_span_find_by_name(name, &span); if (zstatus != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error finding FreeTDM span %s\n", name); + CONFIG_ERROR("Error finding FreeTDM span %s\n", name); continue; } span_id = ftdm_span_get_id(span); if (ftdm_configure_span_signaling(span, "libpri", on_clear_channel_signal, spanparameters) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error configuring FreeTDM span %s\n", name); + CONFIG_ERROR("Error configuring FreeTDM span %s\n", name); continue; } @@ -3282,86 +3286,6 @@ static switch_status_t load_config(void) } } - if ((spans = switch_xml_child(cfg, "boost_spans"))) { - for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { - char *id = (char *) switch_xml_attr(myspan, "id"); - char *name = (char *) switch_xml_attr(myspan, "name"); - char *sigmod = (char *) switch_xml_attr(myspan, "sigmod"); - ftdm_status_t zstatus = FTDM_FAIL; - const char *context = "default"; - const char *dialplan = "XML"; - uint32_t span_id = 0; - ftdm_span_t *span = NULL; - ftdm_conf_parameter_t spanparameters[30]; - unsigned paramindex = 0; - - if (!id && !name) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "boost span requires an id or name as attribute: \n"); - continue; - } - memset(spanparameters, 0, sizeof(spanparameters)); - if (sigmod) { - spanparameters[paramindex].var = "sigmod"; - spanparameters[paramindex].val = sigmod; - paramindex++; - } - - for (param = switch_xml_child(myspan, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr_soft(param, "name"); - char *val = (char *) switch_xml_attr_soft(param, "value"); - - if (ftdm_array_len(spanparameters) - 1 == paramindex) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Too many parameters for boost span, ignoring any parameter after %s\n", var); - break; - } - - if (!strcasecmp(var, "context")) { - context = val; - } else if (!strcasecmp(var, "dialplan")) { - dialplan = val; - } else { - spanparameters[paramindex].var = var; - spanparameters[paramindex].val = val; - paramindex++; - } - } - - if (name) { - zstatus = ftdm_span_find_by_name(name, &span); - } else { - if (switch_is_number(id)) { - span_id = atoi(id); - zstatus = ftdm_span_find(span_id, &span); - } - - if (zstatus != FTDM_SUCCESS) { - zstatus = ftdm_span_find_by_name(id, &span); - } - } - - if (zstatus != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error finding FreeTDM span id:%s name:%s\n", switch_str_nil(id), switch_str_nil(name)); - continue; - } - - if (!span_id) { - span_id = ftdm_span_get_id(span); - } - - if (ftdm_configure_span_signaling(span, "sangoma_boost", on_clear_channel_signal, spanparameters) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error starting FreeTDM span %d error: %s\n", span_id, ftdm_span_get_last_error(span)); - continue; - } - - SPAN_CONFIG[span_id].span = span; - switch_copy_string(SPAN_CONFIG[span_id].context, context, sizeof(SPAN_CONFIG[span_id].context)); - switch_copy_string(SPAN_CONFIG[span_id].dialplan, dialplan, sizeof(SPAN_CONFIG[span_id].dialplan)); - - switch_copy_string(SPAN_CONFIG[span_id].type, "Sangoma (boost)", sizeof(SPAN_CONFIG[span_id].type)); - boost_spans[boosti++] = span; - } - } - if ((spans = switch_xml_child(cfg, "r2_spans"))) { for (myspan = switch_xml_child(spans, "span"); myspan; myspan = myspan->next) { char *name = (char *) switch_xml_attr(myspan, "name"); @@ -3380,7 +3304,7 @@ static switch_status_t load_config(void) unsigned paramindex = 0; if (!name) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "'name' attribute required for R2 spans!\n"); + CONFIG_ERROR("'name' attribute required for R2 spans!\n"); continue; } @@ -3415,14 +3339,13 @@ static switch_status_t load_config(void) zstatus = ftdm_span_find_by_name(name, &span); if (zstatus != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error finding FreeTDM R2 Span '%s'\n", name); + CONFIG_ERROR("Error finding FreeTDM R2 Span '%s'\n", name); continue; } span_id = ftdm_span_get_id(span); if (ftdm_configure_span_signaling(span, "r2", on_r2_signal, spanparameters) != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Error configuring FreeTDM R2 span %s, error: %s\n", - name, ftdm_span_get_last_error(span)); + CONFIG_ERROR("Error configuring FreeTDM R2 span %s, error: %s\n", name, ftdm_span_get_last_error(span)); continue; } @@ -3440,24 +3363,12 @@ static switch_status_t load_config(void) switch_copy_string(SPAN_CONFIG[span_id].type, "R2", sizeof(SPAN_CONFIG[span_id].type)); if (ftdm_span_start(span) == FTDM_FAIL) { - ftdm_log(FTDM_LOG_ERROR, "Error starting FreeTDM R2 span %s, error: %s\n", name, ftdm_span_get_last_error(span)); + CONFIG_ERROR("Error starting FreeTDM R2 span %s, error: %s\n", name, ftdm_span_get_last_error(span)); continue; } } } - /* start all boost spans now that we're done configuring. Unfortunately at this point boost modules have the limitation - * of needing all spans to be configured before starting them */ - for (i=0 ; i < boosti; i++) { - boost_span = boost_spans[i]; - ftdm_log(FTDM_LOG_DEBUG, "Starting boost span %d\n", ftdm_span_get_id(boost_span)); - if (ftdm_span_start(boost_span) == FTDM_FAIL) { - ftdm_log(FTDM_LOG_ERROR, "Error starting boost FreeTDM span %d, error: %s\n", - ftdm_span_get_id(boost_span), ftdm_span_get_last_error(boost_span)); - continue; - } - } - if (globals.crash_on_assert) { ftdm_log(FTDM_LOG_WARNING, "Crash on assert enabled\n"); ftdm_global_set_crash_policy(FTDM_CRASH_ON_ASSERT); @@ -3465,6 +3376,11 @@ static switch_status_t load_config(void) switch_xml_free(xml); + if (globals.fail_on_error && globals.config_error) { + ftdm_log(FTDM_LOG_ERROR, "Refusing to load module with errors\n"); + return SWITCH_STATUS_TERM; + } + return SWITCH_STATUS_SUCCESS; }