[FFmpeg-devel] [PATCH] avutil/avstring: add a "ALL" entry and the possibility to negate matches to av_match_name()
Stefano Sabatini
stefasab at gmail.com
Sat Feb 13 15:22:52 CET 2016
On date Thursday 2016-02-11 20:49:05 +0100, Michael Niedermayer encoded:
> This will extend the whitelist features to allow blacklisting individual protocols and to
> explicitly force everything to be enabled.
>
> Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> ---
> libavutil/avstring.c | 15 ++++++++++-----
> libavutil/avstring.h | 5 +++++
> 2 files changed, 15 insertions(+), 5 deletions(-)
Nit: bump micro
>
> diff --git a/libavutil/avstring.c b/libavutil/avstring.c
> index 57fe74d..85fb3e9 100644
> --- a/libavutil/avstring.c
> +++ b/libavutil/avstring.c
> @@ -326,13 +326,18 @@ int av_match_name(const char *name, const char *names)
> return 0;
>
> namelen = strlen(name);
> - while ((p = strchr(names, ','))) {
> + while (*names) {
> + int negate = '-' == *names;
> + p = strchr(names, ',');
> + if (!p)
> + p = names + strlen(names);
> + names += negate;
> len = FFMAX(p - names, namelen);
> - if (!av_strncasecmp(name, names, len))
> - return 1;
> - names = p + 1;
> + if (!av_strncasecmp(name, names, len) || !strncmp("ALL", names, FFMAX(3, p - names)))
> + return !negate;
So we have:
av_match_name("foo", "foo") => 1
av_match_name("foo", "ALL") => 1
av_match_name("foo", "-foo") => 0
av_match_name("foo", "ALL,-foo") => 1
av_match_name("foo", "-foo,ALL") => 0
Is this correct?
> + names = p + (*p == ',');
> }
> - return !av_strcasecmp(name, names);
> + return 0;
> }
> int av_utf8_decode(int32_t *codep, const uint8_t **bufp, const uint8_t *buf_end,
> diff --git a/libavutil/avstring.h b/libavutil/avstring.h
> index a46d012..ea08d4f 100644
> --- a/libavutil/avstring.h
> +++ b/libavutil/avstring.h
> @@ -284,6 +284,11 @@ const char *av_dirname(char *path);
>
> /**
> * Match instances of a name in a comma-separated list of names.
> + * List entries are checked from 0 to the end of the names list,
from 0 => from the start
> + * the first match ends further proessing. If a entry prefixed with '-'
> + * matches than 0 is returned. the "ALL" list entry is considered to
> + * match all names.
With typo-check on and my suggestion, this becomes:
* the first match ends further processing. If an entry prefixed with '-'
* matches, then 0 is returned. The "ALL" list entry is considered to
* match all names.
LGTM otherwise, thanks.
--
FFmpeg = Fabulous & Fostering Mega Power Elegant Gem
More information about the ffmpeg-devel
mailing list