diff --git a/userspace/falco/utils.cpp b/userspace/falco/utils.cpp index 12900799..76d20468 100644 --- a/userspace/falco/utils.cpp +++ b/userspace/falco/utils.cpp @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +#include + #include "utils.h" #include "banned.h" // This raises a compilation error when certain functions are used @@ -33,3 +35,15 @@ void falco::utils::read(const std::string& filename, std::string& data) return; } + +bool falco::utils::starts_with(const std::string& text, const std::string& prefix) +{ + return prefix.empty() || + (text.size() >= prefix.size() && + std::memcmp(text.data(), prefix.data(), prefix.size()) == 0); +} + +bool falco::utils::network::url_is_unix_scheme(const std::string& url) +{ + return starts_with(url, UNIX_SCHEME); +} diff --git a/userspace/falco/utils.h b/userspace/falco/utils.h index 30d6bd15..a91ea978 100644 --- a/userspace/falco/utils.h +++ b/userspace/falco/utils.h @@ -26,5 +26,12 @@ namespace falco namespace utils { void read(const std::string& filename, std::string& data); +bool starts_with(const std::string& text, const std::string& prefix); + +namespace network +{ +static const std::string UNIX_SCHEME{"unix://"}; +bool url_is_unix_scheme(const std::string& url); +} // namespace network } // namespace utils } // namespace falco