mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2024-12-04 14:46:30 -05:00
Feature: Allow lists and wildcard matches for event triggers
This commit is contained in:
parent
b2167151bb
commit
8508588997
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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__ */
|
||||
|
Loading…
Reference in New Issue
Block a user