From fcb08df0ae0cb60127da7c94aeaad9f882719242 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 3 Jun 2019 10:34:58 -0400 Subject: [PATCH] TT#59805 add dtmf-log-dest option Change-Id: Id6f7ce7fa627b138e0b0ea3d410b8af53532b290 --- daemon/dtmf.c | 27 ++++++++++++++++++++++----- daemon/main.c | 8 ++++++++ daemon/rtpengine.pod | 7 +++++++ include/dtmf.h | 1 + include/main.h | 1 + 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/daemon/dtmf.c b/daemon/dtmf.c index 71c277dcf..cfc1d3f60 100644 --- a/daemon/dtmf.c +++ b/daemon/dtmf.c @@ -3,9 +3,20 @@ #include "log.h" #include "call.h" #include "dtmflib.h" +#include "main.h" +static socket_t dtmf_log_sock; + +void dtmf_init(void) { + if (rtpe_config.dtmf_udp_ep.port) { + if (connect_socket(&dtmf_log_sock, SOCK_DGRAM, &rtpe_config.dtmf_udp_ep)) + ilog(LOG_ERR, "Failed to open/connect DTMF logging socket: %s", strerror(errno)); + } +} + + static GString *dtmf_json_print(struct media_packet *mp, struct telephone_event_payload *dtmf, int clockrate) { @@ -61,12 +72,18 @@ int dtmf_event(struct media_packet *mp, str *payload, int clockrate) { int ret = 0; - if (_log_facility_dtmf) { - GString *buf = dtmf_json_print(mp, dtmf, clockrate); - if (buf) { + GString *buf = NULL; + + if (_log_facility_dtmf || dtmf_log_sock.family) + buf = dtmf_json_print(mp, dtmf, clockrate); + + if (buf) { + if (_log_facility_dtmf) dtmflog(buf); - ret = 1; // END event - } + if (dtmf_log_sock.family) + send(dtmf_log_sock.fd, buf->str, buf->len, 0); + + ret = 1; // END event } return ret; diff --git a/daemon/main.c b/daemon/main.c index 01fa2e535..c36924082 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -306,6 +306,7 @@ static void options(int *argc, char ***argv) { int codecs = 0; double max_load = 0; double max_cpu = 0; + char *dtmf_udp_ep = NULL; GOptionEntry e[] = { { "table", 't', 0, G_OPTION_ARG_INT, &rtpe_config.kernel_table, "Kernel table to use", "INT" }, @@ -341,6 +342,7 @@ static void options(int *argc, char ***argv) { { "log-facility-rtcp",0, 0, G_OPTION_ARG_STRING, &log_facility_rtcp_s, "Syslog facility to use for logging RTCP", "daemon|local0|...|local7"}, { "log-facility-dtmf",0, 0, G_OPTION_ARG_STRING, &log_facility_dtmf_s, "Syslog facility to use for logging DTMF", "daemon|local0|...|local7"}, { "log-format", 0, 0, G_OPTION_ARG_STRING, &log_format, "Log prefix format", "default|parsable"}, + { "dtmf-log-dest", 0,0, G_OPTION_ARG_STRING, &dtmf_udp_ep, "Destination address for DTMF logging via UDP", "IP46|HOSTNAME:PORT" }, { "xmlrpc-format",'x', 0, G_OPTION_ARG_INT, &rtpe_config.fmt, "XMLRPC timeout request format to use. 0: SEMS DI, 1: call-id only, 2: Kamailio", "INT" }, { "num-threads", 0, 0, G_OPTION_ARG_INT, &rtpe_config.num_threads, "Number of worker threads to create", "INT" }, { "media-num-threads", 0, 0, G_OPTION_ARG_INT, &rtpe_config.media_num_threads, "Number of worker threads for media playback", "INT" }, @@ -518,6 +520,11 @@ static void options(int *argc, char ***argv) { die("Invalid --log-format option"); } + if (dtmf_udp_ep) { + if (endpoint_parse_any_getaddrinfo_full(&rtpe_config.dtmf_udp_ep, dtmf_udp_ep)) + die("Invalid IP or port '%s' (--dtmf-log-dest)", dtmf_udp_ep); + } + if (!sip_source) trust_address_def = 1; @@ -643,6 +650,7 @@ static void init_everything(void) { statistics_init(); codeclib_init(0); media_player_init(); + dtmf_init(); } diff --git a/daemon/rtpengine.pod b/daemon/rtpengine.pod index d25af0c96..146fe5c44 100644 --- a/daemon/rtpengine.pod +++ b/daemon/rtpengine.pod @@ -235,6 +235,13 @@ The B output style is similar, but makes the ID easier to parse by enclosing it in quotes, such as B<[ID="CALLID"]> or B<[ID="CALLID" port="12345"]>. +=item B<--dtmf-log-dest=>I:I + +Configures a target address for logging detected DTMF event. Similar +to the feature enabled by B<--log-facilty-dtmf>, but instead of writing +detected DTMF events to syslog, this sends the JSON payload to the +given address as UDP packets. + =item B<--log-srtp-keys> Write SRTP keys to error log instead of debug log. diff --git a/include/dtmf.h b/include/dtmf.h index a2b9bf660..05d6a1afe 100644 --- a/include/dtmf.h +++ b/include/dtmf.h @@ -14,6 +14,7 @@ struct dtmf_event { uint64_t ts; }; +void dtmf_init(void); int dtmf_event(struct media_packet *, str *, int); int dtmf_event_payload(str *, uint64_t *, uint64_t, struct dtmf_event *, GQueue *); void dtmf_event_free(void *); diff --git a/include/main.h b/include/main.h index 23ca13fc4..1b689b620 100644 --- a/include/main.h +++ b/include/main.h @@ -83,6 +83,7 @@ struct rtpengine_config { char *mysql_user; char *mysql_pass; char *mysql_query; + endpoint_t dtmf_udp_ep; };