[FFmpeg-cvslog] avutil/avstring: add a "ALL" entry and the possibility to negate matches to av_match_name()

Michael Niedermayer git at videolan.org
Sat Feb 13 16:52:56 CET 2016


ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Thu Feb 11 20:49:05 2016 +0100| [a9b81bfd1c7a9b3d4c92af99aee9a284d1133b9e] | committer: Michael Niedermayer

avutil/avstring: add a "ALL" entry and the possibility to negate matches to av_match_name()

This will extend the whitelist features to allow blacklisting individual protocols and to
explicitly force everything to be enabled.

Reviewed-by: Stefano Sabatini <stefasab at gmail.com>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a9b81bfd1c7a9b3d4c92af99aee9a284d1133b9e
---

 libavutil/avstring.c |   15 ++++++++++-----
 libavutil/avstring.h |    5 +++++
 libavutil/version.h  |    2 +-
 3 files changed, 16 insertions(+), 6 deletions(-)

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;
+        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..15b04ba 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 the start to the end of the names list,
+ * 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.
+ *
  * @param name  Name to look for.
  * @param names List of names.
  * @return 1 on match, 0 otherwise.
diff --git a/libavutil/version.h b/libavutil/version.h
index 5352f26..f99624c 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -65,7 +65,7 @@
 
 #define LIBAVUTIL_VERSION_MAJOR  55
 #define LIBAVUTIL_VERSION_MINOR  17
-#define LIBAVUTIL_VERSION_MICRO 100
+#define LIBAVUTIL_VERSION_MICRO 101
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
                                                LIBAVUTIL_VERSION_MINOR, \



More information about the ffmpeg-cvslog mailing list