1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-09-22 04:15:54 -04:00

Feature: Allow lists and wildcard matches for event triggers

This commit is contained in:
Philipp Schafft 2022-09-24 09:58:27 +00:00
parent b2167151bb
commit 8508588997
3 changed files with 37 additions and 1 deletions

View File

@ -222,7 +222,7 @@ static event_t *event_new(const char *trigger) {
/* subsystem functions */
static inline void _try_event(event_registration_t *er, event_t *event) {
/* er is already locked */
if (strcmp(er->trigger, event->trigger) != 0)
if (!util_is_in_list(er->trigger, event->trigger))
return;
if (er->emit)

View File

@ -309,3 +309,36 @@ int util_strtolower(char *str)
return 0;
}
bool util_is_in_list(const char *list, const char *needle)
{
while (*list) {
const char *t = needle;
bool positive = true;
for (; *list == ','; list++);
for (; *list == '!'; list++)
positive = !positive;
for (; *list; list++) {
if (*list == ',')
break;
if (*list == '*')
return positive;
if (*list == *t) {
t++;
} else {
break;
}
}
if ((*list == 0 || *list == ',') && *t == 0) {
return positive;
}
for (; *list && *list != ','; list++);
}
return false;
}

View File

@ -34,4 +34,7 @@ int util_replace_string(char **dst, const char *src);
bool util_replace_string_url_escape(char **dst, const char *src); /* returns true on success */
int util_strtolower(char *str);
/* Supports wildcards, supports negatives matches. */
bool util_is_in_list(const char *list, const char *needle);
#endif /* __UTIL_STRING_H__ */