From 015c25d140a83c2b2249904e23c9dc0955a22780 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 4 Jan 2024 09:33:03 -0500 Subject: [PATCH] MT#59069 support arbitrary pattern replacements Support a replacement pattern of %{...} to look up arbitrary keys from the given metadata and use the respective values. Change-Id: I2cc6c791629ed494b32e3352a555298c3b9cb4fc --- docs/rtpengine-recording.md | 12 ++++++++++++ recording-daemon/output.c | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/docs/rtpengine-recording.md b/docs/rtpengine-recording.md index 6a3f56aa9..0c583b3d9 100644 --- a/docs/rtpengine-recording.md +++ b/docs/rtpengine-recording.md @@ -208,6 +208,18 @@ sufficient for a standard installation of rtpengine. example, if the call ID is __abcdefgh__ and the output pattern is configured as __%2/%3/%c__, then the resulting output file name would be __ab/cde/abcdefgh__. + - __%{__ + + Take the string between the enclosing opening and closing brace + (between this __{__ and the next __}__) and use it as a key to look up + a corresponding value in the metadata string provided by *rtpengine*. + The metadata string must be given as a pipe (__|__) separated list of + `key:value` pairs, as described in the *rtpengine* documentation. + + Example: If the metadata string is given as __foo:bar|blah:baz__ and + the pattern includes the format __%{foo}__ then __bar__ will be + inserted into the file name at that position. + - __\-\-output-format=wav__\|__mp3__\|__none__ File format to be used for media files that are produced. Defaults to PCM WAV diff --git a/recording-daemon/output.c b/recording-daemon/output.c index ed387e262..c1f4d2f45 100644 --- a/recording-daemon/output.c +++ b/recording-daemon/output.c @@ -100,6 +100,17 @@ static output_t *output_alloc(const char *path, const char *name) { return ret; } +static void output_append_str_from_ht(GString *f, metadata_ht ht, const str *s) { + str *val = t_hash_table_lookup(ht, s); + if (!val) { + ilog(LOG_WARN, "Key '{" STR_FORMAT "}' used in file name pattern not present in metadata", + STR_FMT(s)); + return; + } + g_autoptr(char) esc = g_uri_escape_string(val->s, NULL, false); + g_string_append(f, esc); +} + static output_t *output_new(const char *path, const metafile_t *mf, const char *type, const char *kind, const char *label) { @@ -181,6 +192,18 @@ static output_t *output_new(const char *path, const metafile_t *mf, const char * g_string_append_c(f, *ax++); p = end - 1; // will be advanced +1 in the next loop break; + case '{': + // find matching end '}' + p++; + end = strchr(p, '}'); + if (!end) { + ilog(LOG_ERR, "Missing ending brace '}' in file name pattern"); + break; + } + str fmt = STR_INIT_LEN((char *) p, end - p); + p = end; // skip over {...} + output_append_str_from_ht(f, mf->metadata_parsed, &fmt); + break; default: ilog(LOG_ERR, "Invalid output pattern (unknown format character '%c')", *p); break;