Browse Source

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
pull/1786/head
Richard Fuchs 2 years ago
parent
commit
015c25d140
2 changed files with 35 additions and 0 deletions
  1. +12
    -0
      docs/rtpengine-recording.md
  2. +23
    -0
      recording-daemon/output.c

+ 12
- 0
docs/rtpengine-recording.md View File

@ -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


+ 23
- 0
recording-daemon/output.c View File

@ -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;


Loading…
Cancel
Save