From 4fcae749dad230c2db143c787d6debdef21a618a Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 25 Jun 2019 14:29:55 +0200 Subject: [PATCH] Improved blacklisting/whitelisting code + MP3 in MP4 output blacklist for Trident browsers under Windows 7 and lower --- lib/stream.cpp | 14 ++++++++++++-- src/output/output_progressive_mp4.cpp | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/stream.cpp b/lib/stream.cpp index adb012ab..60fb711c 100644 --- a/lib/stream.cpp +++ b/lib/stream.cpp @@ -377,17 +377,27 @@ bool Util::checkException(const JSON::Value & ex, const std::string & useragent) bool ret = true; jsonForEachConst(ex, e){ if (!e->isArray() || !e->size()){continue;} - bool setTo = ((*e)[0u].asStringRef() == "whitelist"); + bool setTo = false; + bool except = false; + //whitelist makes the return value true if any value is contained in the UA, blacklist makes it false. + //the '_except' variants do so only if none of the values are contained in the UA. + if ((*e)[0u].asStringRef() == "whitelist"){setTo = true; except = false;} + if ((*e)[0u].asStringRef() == "whitelist_except"){setTo = true; except = true;} + if ((*e)[0u].asStringRef() == "blacklist"){setTo = false; except = false;} + if ((*e)[0u].asStringRef() == "blacklist_except"){setTo = false; except = true;} if (e->size() == 1){ ret = setTo; continue; } if (!(*e)[1].isArray()){continue;} + bool match = false; jsonForEachConst((*e)[1u], i){ if (useragent.find(i->asStringRef()) != std::string::npos){ - ret = setTo; + match = true; } } + //set the (temp) return value if this was either a match in regular mode, or a non-match in except-mode. + if (except != match){ret = setTo;} } return ret; } diff --git a/src/output/output_progressive_mp4.cpp b/src/output/output_progressive_mp4.cpp index 23980562..96ce9ba0 100644 --- a/src/output/output_progressive_mp4.cpp +++ b/src/output/output_progressive_mp4.cpp @@ -26,6 +26,7 @@ namespace Mist { capa["methods"][0u]["type"] = "html5/video/mp4"; capa["methods"][0u]["priority"] = 10; capa["methods"][0u]["nolive"] = 1; + capa["exceptions"]["codec:MP3"] = JSON::fromString("[[\"blacklist\",[\"Windows NT 5\", \"Windows NT 6.0\", \"Windows NT 6.1\"]],[\"whitelist_except\",[\"Trident\"]]]"); } uint64_t OutProgressiveMP4::estimateFileSize() { uint64_t retVal = 0;