media-session: sanitize name and nick

Replace unwanted chars in the name with _. This makes it compatible
with pulseaudio names and avoids problems with regex.
Replace unwanred chars in the nick with ' '. This ensures JACK
clients don't receive ':' in the device names, which cause it to
fail when parsing the ports.

See #714 and #130
This commit is contained in:
Wim Taymans 2021-02-12 20:47:41 +01:00
parent ac910c7c1c
commit 062911640c
5 changed files with 55 additions and 10 deletions

View file

@ -1798,6 +1798,31 @@ int sm_media_session_save_state(struct sm_media_session *sess,
return pw_conf_save_state(SESSION_PREFIX, name, props);
}
char *sm_media_session_sanitize_name(char *name, int size, char sub, const char *fmt, ...)
{
char *p;
va_list varargs;
va_start(varargs, fmt);
if (vsnprintf(name, size, fmt, varargs) < 0)
return NULL;
va_end(varargs);
for (p = name; *p; p++) {
switch(*p) {
case '0' ... '9':
case 'a' ... 'z':
case 'A' ... 'Z':
case '.': case '-': case '_':
break;
default:
*p = sub;
break;
}
}
return name;
}
static void monitor_core_done(void *data, uint32_t id, int seq)
{
struct impl *impl = data;