diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 768c8f6b7..5ce132b79 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -37,6 +37,7 @@ static pcre2_code *streams_re; bool trust_address_def; bool dtls_passive_def; str_case_value_ht rtpe_signalling_templates; +str rtpe_default_signalling_templates[OP_COUNT + 1]; enum basic_errors { NG_ERROR_NO_SDP_BODY = 1, @@ -2090,6 +2091,14 @@ static void call_ng_process_flags(sdp_ng_flags *out, ng_command_ctx_t *ctx, enum call_ng_flags_init(out, opmode); ctx->opmode = opmode; ctx->flags = out; + + // check for default templates, "default" first + if (rtpe_default_signalling_templates[OP_OTHER].len) + parse_rtpp_flags(&rtpe_default_signalling_templates[OP_OTHER], out); + // and then one matching the current command + if (opmode != OP_OTHER && rtpe_default_signalling_templates[opmode].len) + parse_rtpp_flags(&rtpe_default_signalling_templates[opmode], out); + parser->dict_iter(parser, ctx->req, call_ng_main_flags, out); } @@ -4028,6 +4037,19 @@ static void parse_templates(GHashTable *templates) { char *value = valuep; t_hash_table_insert(rtpe_signalling_templates, str_dup(STR_PTR(key)), str_dup(STR_PTR(value))); } + + // look for templates matching known commands + for (unsigned int i = 0; i < OP_COUNT; i++) { + const char *cmd = ng_command_strings[i]; + str *tmpl = t_hash_table_lookup(rtpe_signalling_templates, STR_PTR(cmd)); + if (tmpl) + rtpe_default_signalling_templates[i] = *tmpl; + } + + // finally look for "default" and store it in the OTHER slot + str *tmpl = t_hash_table_lookup(rtpe_signalling_templates, STR_PTR("default")); + if (tmpl) + rtpe_default_signalling_templates[OP_OTHER] = *tmpl; } int call_interfaces_init(GHashTable *templates) { diff --git a/docs/rtpengine.md b/docs/rtpengine.md index f9d3759a5..e628beecf 100644 --- a/docs/rtpengine.md +++ b/docs/rtpengine.md @@ -1576,6 +1576,14 @@ The __offer__ command in Kamailio or OpenSIPS can then simply be turned into: rtpengine_offer("template=WebRTC"); +In addition to named signalling templates, *rtpengine* supports default +signalling templates that are automatically applied. Default signalling +templates are templates using a name that matches a signalling command (e.g. +__offer__ or __start recording__), or the special name __default__ which is a +template that is applied to all signalling messages. These templates are +automatically applied without needing to refer to them by name using +__template=...__ from within the signalling message. + ## EXIT STATUS - __0__ diff --git a/include/call_interfaces.h b/include/call_interfaces.h index 9786097ab..1e3c46218 100644 --- a/include/call_interfaces.h +++ b/include/call_interfaces.h @@ -264,6 +264,7 @@ RTPE_NG_FLAGS_STR_CASE_HT_PARAMS extern bool trust_address_def; extern bool dtls_passive_def; extern str_case_value_ht rtpe_signalling_templates; +extern str rtpe_default_signalling_templates[OP_COUNT + 1]; str *call_request_tcp(char **); str *call_lookup_tcp(char **); diff --git a/t/Makefile b/t/Makefile index ac95064ee..2f72befff 100644 --- a/t/Makefile +++ b/t/Makefile @@ -101,7 +101,8 @@ include ../lib/common.Makefile daemon-tests-main daemon-tests-jb daemon-tests-dtx daemon-tests-dtx-cn daemon-tests-pubsub \ daemon-tests-intfs daemon-tests-stats daemon-tests-delay-buffer daemon-tests-delay-timing \ daemon-tests-evs daemon-tests-player-cache daemon-tests-redis daemon-tests-redis-json \ - daemon-tests-measure-rtp daemon-tests-mos-legacy daemon-tests-mos-fullband daemon-tests-config-file + daemon-tests-measure-rtp daemon-tests-mos-legacy daemon-tests-mos-fullband daemon-tests-config-file \ + daemon-tests-templ-def daemon-tests-templ-def-offer TESTS= test-bitstr aes-crypt aead-aes-crypt test-const_str_hash.strhash ifeq ($(with_transcoding),yes) @@ -140,7 +141,8 @@ daemon-tests: daemon-tests-main daemon-tests-jb daemon-tests-pubsub daemon-tests daemon-tests-audio-player daemon-tests-audio-player-play-media \ daemon-tests-intfs daemon-tests-stats daemon-tests-player-cache daemon-tests-redis \ daemon-tests-rtpp-flags daemon-tests-redis-json daemon-tests-measure-rtp daemon-tests-mos-legacy \ - daemon-tests-mos-fullband daemon-tests-config-file + daemon-tests-mos-fullband daemon-tests-config-file \ + daemon-tests-templ-def daemon-tests-templ-def-offer daemon-test-deps: tests-preload.so $(MAKE) -C ../daemon @@ -211,6 +213,12 @@ daemon-tests-mos-fullband: daemon-test-deps daemon-tests-config-file: daemon-test-deps ./auto-test-helper "$@" perl -I../perl auto-daemon-tests-config-file.pl +daemon-tests-templ-def-offer: daemon-test-deps + ./auto-test-helper "$@" perl -I../perl auto-daemon-tests-templ-def-offer.pl + +daemon-tests-templ-def: daemon-test-deps + ./auto-test-helper "$@" perl -I../perl auto-daemon-tests-templ-def.pl + test-bitstr: test-bitstr.o test-mix-buffer: test-mix-buffer.o $(COMMONOBJS) mix_buffer.o ssrc.o rtp.o crypto.o helpers.o \ diff --git a/t/auto-daemon-tests-templ-def-offer.pl b/t/auto-daemon-tests-templ-def-offer.pl new file mode 100755 index 000000000..cf9371d1d --- /dev/null +++ b/t/auto-daemon-tests-templ-def-offer.pl @@ -0,0 +1,64 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use NGCP::Rtpengine::Test; +use NGCP::Rtpclient::SRTP; +use NGCP::Rtpengine::AutoTest; +use Test::More; +use Test2::Tools::Compare qw(); +use NGCP::Rtpclient::ICE; +use POSIX; + + +autotest_start(qw(--config-file=test3.conf)) or die; + + + + +my ($sock_a, $sock_b, $sock_c, $sock_d, $port_a, $port_b, $ssrc, $ssrc_b, $resp, + $sock_ax, $sock_bx, $port_ax, $port_bx, + $srtp_ctx_a, $srtp_ctx_b, $srtp_ctx_a_rev, $srtp_ctx_b_rev, $ufrag_a, $ufrag_b, + @ret1, @ret2, @ret3, @ret4, $srtp_key_a, $srtp_key_b, $ts, $seq, $has_recv); + + + +new_call; + +offer('template', { }, <