diff --git a/modules/catch_dtmf/rtpp_catch_dtmf.c b/modules/catch_dtmf/rtpp_catch_dtmf.c index c3649d25d..550afb41f 100644 --- a/modules/catch_dtmf/rtpp_catch_dtmf.c +++ b/modules/catch_dtmf/rtpp_catch_dtmf.c @@ -247,10 +247,14 @@ rtpp_catch_dtmf_worker(const struct rtpp_wthrdata *wp) /* we received the end of the DTMF */ /* all good - send the notification */ eip->pending = 0; - rtpp_str_const_t notify_tag = {.s = buf}; - notify_tag.len = snprintf(buf, RTPP_MAX_NOTIFY_BUF, "%.*s %c %u %u %d", + int tlen = snprintf(buf, RTPP_MAX_NOTIFY_BUF, "%.*s %c %u %u %d", FMTSTR(wip->rtdp->notify_tag), ei.digit, dtmf->volume, eip->duration, (wip->edata->side == RTPP_SSIDE_CALLER) ? 0 : 1); + if (tlen < 0) + goto skip; + if (tlen >= RTPP_MAX_NOTIFY_BUF) + tlen = RTPP_MAX_NOTIFY_BUF - 1; + rtpp_str_const_t notify_tag = {.s = buf, .len = tlen}; CALL_METHOD(pvt->notifier, schedule, wip->rtdp->notify_target, rtpp_str_fix(¬ify_tag), notyfy_type); diff --git a/tests/catch_dtmf/basic b/tests/catch_dtmf/basic index bbf1f133d..ea5f0b42b 100755 --- a/tests/catch_dtmf/basic +++ b/tests/catch_dtmf/basic @@ -67,3 +67,22 @@ do report "checking ${prefix}.rlog for \"${msg}\"" done done + +# The long callee tags must be clamped to 511 bytes: expect exactly six such +# notifications per mode plus the timeout one, comparing the whole log so +# that extra or longer lines are caught. Sort to ignore interleaving. +LC_ALL=C awk 'BEGIN { + n = split("fixedlong: wildcardlong:", pfx, " ") + for (m = 1; m <= n; m++) { + line = pfx[m] + while (length(line) < 511) + line = line "A" + for (i = 0; i < 6; i++) + print line + print pfx[m] "DTAG" + } +}' | LC_ALL=C sort > "${OUT}.long.etlog" +grep '^[a-z]*long:' "${OUT}.tlog" | LC_ALL=C sort > "${OUT}.long.tlog" +report "collecting long tag notifications" +${DIFF} "${OUT}.long.etlog" "${OUT}.long.tlog" +report "checking clamped 511-byte notifications for fixed and wildcard modes" diff --git a/tests/catch_dtmf/basic.rptl b/tests/catch_dtmf/basic.rptl index ac37c2ca8..3928ae440 100644 --- a/tests/catch_dtmf/basic.rptl +++ b/tests/catch_dtmf/basic.rptl @@ -38,6 +38,16 @@ socket rtpp_wildcard: udp: -d dbug -n %%NS_wildcard%% -T3 -W3 --dso %%DSO%% -> % .sleep: 4 .foreach: MODE in fixed wildcard do finish.rptl + +# Long callee tags in extra sessions on the same daemons, after the final +# statistics were taken so that they are not affected. +.exec: awk 'BEGIN { for (i = 0; i < 512; i++) printf "A" }' -> LONG_TAG +.foreach: MODE in fixed wildcard do long.rptl +.wait: LREPLAY_fixed 30 +.wait: LREPLAY_wildcard 30 +# Let the sessions time out, so that their notifications are flushed. +.sleep: 4 +.foreach: MODE in fixed wildcard do close.rptl .close: sink .exec: %%PYINT%% %%CHECK_RELAYED%% %%RECORD_DIR%%/%%ROOT_OUT%%.fixed.sink=from_tag_1.a.rtp %%PORT_U_fixed%% %%PCAP%% 24272 .exec: %%PYINT%% %%CHECK_RELAYED%% %%RECORD_DIR%%/%%ROOT_OUT%%.wildcard.sink=from_tag_1.a.rtp %%PORT_U_wildcard%% %%PCAP%% 24272 diff --git a/tests/catch_dtmf/catch_dtmf.output b/tests/catch_dtmf/catch_dtmf.output index 04afac989..5e305ddc6 100644 --- a/tests/catch_dtmf/catch_dtmf.output +++ b/tests/catch_dtmf/catch_dtmf.output @@ -20,4 +20,6 @@ npkts_rcvd=203 npkts_played=0 npkts_relayed=158 npkts_discard=45 nplrs_created=0 rtpa_nsent=394 rtpa_nrcvd=151 rtpa_ndups=52 rtpa_nlost=243 rtpa_perrs=0 nsess_created=1 nsess_destroyed=1 nsess_timeout=1 nsess_complete=1 nsess_nortp=0 nsess_owrtp=0 nsess_nortcp=1 nsess_owrtcp=0 ncmds_rcvd=22 ncmds_succd=16 ncmds_errs=5 ncmds_repld=21 +24274 +24276 MEMDEB(rtpproxy): all clear diff --git a/tests/catch_dtmf/close.rptl b/tests/catch_dtmf/close.rptl new file mode 100644 index 000000000..4c23cdc7f --- /dev/null +++ b/tests/catch_dtmf/close.rptl @@ -0,0 +1,7 @@ +# Close one setup and release its recorder session. +.eval: rtpp_%%MODE%% -> R +.eval: %%ROOT_OUT%%.%%MODE%%.sink -> SINK_CID +.close: %%R%% +.echo: OK: %%R%% has exited + +sink: D %%SINK_CID%% from_tag_1 -> str_compare(RES_OK) diff --git a/tests/catch_dtmf/finish.rptl b/tests/catch_dtmf/finish.rptl index 1e1a222f3..6683af5fe 100644 --- a/tests/catch_dtmf/finish.rptl +++ b/tests/catch_dtmf/finish.rptl @@ -8,7 +8,3 @@ %%R%%: Gv ncmds_rcvd ncmds_succd ncmds_errs ncmds_repld .echo: OK: queried global stats -.close: %%R%% -.echo: OK: %%R%% has exited - -sink: D %%SINK_CID%% from_tag_1 -> str_compare(RES_OK) diff --git a/tests/catch_dtmf/long.rptl b/tests/catch_dtmf/long.rptl new file mode 100644 index 000000000..db422c0af --- /dev/null +++ b/tests/catch_dtmf/long.rptl @@ -0,0 +1,9 @@ +# Replay into a session whose callee notification tag exceeds the notify +# buffer. The "long" suffix keeps these lines apart from the regular ones. +.eval: %%ROOT_OUT%%.%%MODE%%.long -> OUT +.eval: rtpp_%%MODE%% -> R +.eval: NS_%%MODE%% -> deref(NS) +%%R%%: U %%CALLID%%_long 127.0.0.1 0 from_tag_1 %%NS%% %%MODE%%long:DTAG -> validate_port(LPORT_U) +%%R%%: L %%CALLID%%_long 127.0.0.1 0 from_tag_1 to_tag_1 && M3:1 %%MODE%%long:%%LONG_TAG%% 101 H -> validate_port(LPORT_L) +.exec: tcprewrite --portmap=24270:%%LPORT_U%%,24272:%%LPORT_L%% -i %%PCAP%% -o %%OUT%%.pcap +.spawn: exec udpreplay %%OUT%%.pcap -> LREPLAY_%%MODE%%