Skip to content

Commit

Permalink
LV2 Client: Add basic LV2URI validation at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
reuk committed Aug 30, 2023
1 parent 88e5e23 commit 583f90b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions modules/juce_audio_plugin_client/juce_audio_plugin_client_LV2.cpp
Expand Up @@ -61,6 +61,24 @@ namespace juce
namespace lv2_client
{

constexpr bool startsWithValidScheme (const std::string_view str)
{
constexpr const char* prefixes[] { "http://", "https://", "urn:" };

for (const std::string_view prefix : prefixes)
if (prefix == str.substr (0, prefix.size()))
return true;

return false;
}

// If your LV2 plugin fails to build here, it may be because you haven't explicitly set an LV2 URI,
// or you've requested a malformed URI.
// If you're using the Projucer, update the value of the "LV2 URI" field in your project settings.
// If you're using CMake, specify a valid LV2URI argument to juce_add_plugin.
static_assert (startsWithValidScheme (JucePlugin_LV2URI),
"Your configured LV2 URI must include a leading scheme specifier.");

constexpr auto uriSeparator = ":";
const auto JucePluginLV2UriUi = String (JucePlugin_LV2URI) + uriSeparator + "UI";
const auto JucePluginLV2UriState = String (JucePlugin_LV2URI) + uriSeparator + "StateString";
Expand Down
1 change: 1 addition & 0 deletions modules/juce_core/system/juce_StandardHeader.h
Expand Up @@ -67,6 +67,7 @@
#include <queue>
#include <set>
#include <sstream>
#include <string_view>
#include <thread>
#include <typeindex>
#include <unordered_map>
Expand Down

0 comments on commit 583f90b

Please sign in to comment.