mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-06 19:40:10 +02:00
Move XMML and URL escape functions to common/utils
So we don't need to include notifications.h on the Wine side. The alternative would be to put ifdef guards around everything involving notification sending in `notifications.cpp` but that would be even more problematic.
This commit is contained in:
@@ -19,6 +19,7 @@ vst2_chainloader_sources = files(
|
|||||||
'../common/linking.cpp',
|
'../common/linking.cpp',
|
||||||
'../common/notifications.cpp',
|
'../common/notifications.cpp',
|
||||||
'../common/process.cpp',
|
'../common/process.cpp',
|
||||||
|
'../common/utils.cpp',
|
||||||
'utils.cpp',
|
'utils.cpp',
|
||||||
'vst2-chainloader.cpp',
|
'vst2-chainloader.cpp',
|
||||||
)
|
)
|
||||||
@@ -29,6 +30,7 @@ if with_clap
|
|||||||
'../common/linking.cpp',
|
'../common/linking.cpp',
|
||||||
'../common/notifications.cpp',
|
'../common/notifications.cpp',
|
||||||
'../common/process.cpp',
|
'../common/process.cpp',
|
||||||
|
'../common/utils.cpp',
|
||||||
'utils.cpp',
|
'utils.cpp',
|
||||||
'clap-chainloader.cpp',
|
'clap-chainloader.cpp',
|
||||||
)
|
)
|
||||||
@@ -40,6 +42,7 @@ if with_vst3
|
|||||||
'../common/linking.cpp',
|
'../common/linking.cpp',
|
||||||
'../common/notifications.cpp',
|
'../common/notifications.cpp',
|
||||||
'../common/process.cpp',
|
'../common/process.cpp',
|
||||||
|
'../common/utils.cpp',
|
||||||
'utils.cpp',
|
'utils.cpp',
|
||||||
'vst3-chainloader.cpp',
|
'vst3-chainloader.cpp',
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -168,112 +168,3 @@ bool send_notification(const std::string& title,
|
|||||||
},
|
},
|
||||||
result);
|
result);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string xml_escape(std::string string) {
|
|
||||||
// Implementation idea stolen from https://stackoverflow.com/a/5665377
|
|
||||||
std::string escaped;
|
|
||||||
escaped.reserve(
|
|
||||||
static_cast<size_t>(static_cast<double>(string.size()) * 1.1));
|
|
||||||
for (const char& character : string) {
|
|
||||||
switch (character) {
|
|
||||||
case '&':
|
|
||||||
escaped.append("&");
|
|
||||||
break;
|
|
||||||
case '\"':
|
|
||||||
escaped.append(""");
|
|
||||||
break;
|
|
||||||
case '\'':
|
|
||||||
escaped.append("'");
|
|
||||||
break;
|
|
||||||
case '<':
|
|
||||||
escaped.append("<");
|
|
||||||
break;
|
|
||||||
case '>':
|
|
||||||
escaped.append(">");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
escaped.push_back(character);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return escaped;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string url_encode_path(std::string path) {
|
|
||||||
// We only need to escape a couple of special characters here. This is used
|
|
||||||
// in the notifications as well as in the XDND proxy. We encode the reserved
|
|
||||||
// characters mentioned here, with the exception of the forward slash:
|
|
||||||
// https://en.wikipedia.org/wiki/Percent-encoding#Reserved_characters
|
|
||||||
std::string escaped;
|
|
||||||
escaped.reserve(
|
|
||||||
static_cast<size_t>(static_cast<double>(path.size()) * 1.1));
|
|
||||||
for (const char& character : path) {
|
|
||||||
switch (character) {
|
|
||||||
// Spaces are somehow in the above list, but Bitwig Studio requires
|
|
||||||
// spaces to be escaped in the `text/uri-list` format
|
|
||||||
case ' ':
|
|
||||||
escaped.append("%20");
|
|
||||||
break;
|
|
||||||
case '!':
|
|
||||||
escaped.append("%21");
|
|
||||||
break;
|
|
||||||
case '#':
|
|
||||||
escaped.append("%23");
|
|
||||||
break;
|
|
||||||
case '$':
|
|
||||||
escaped.append("%24");
|
|
||||||
break;
|
|
||||||
case '%':
|
|
||||||
escaped.append("%25");
|
|
||||||
break;
|
|
||||||
case '&':
|
|
||||||
escaped.append("%26");
|
|
||||||
break;
|
|
||||||
case '\'':
|
|
||||||
escaped.append("%27");
|
|
||||||
break;
|
|
||||||
case '(':
|
|
||||||
escaped.append("%28");
|
|
||||||
break;
|
|
||||||
case ')':
|
|
||||||
escaped.append("%29");
|
|
||||||
break;
|
|
||||||
case '*':
|
|
||||||
escaped.append("%2A");
|
|
||||||
break;
|
|
||||||
case '+':
|
|
||||||
escaped.append("%2B");
|
|
||||||
break;
|
|
||||||
case ',':
|
|
||||||
escaped.append("%2C");
|
|
||||||
break;
|
|
||||||
case ':':
|
|
||||||
escaped.append("%3A");
|
|
||||||
break;
|
|
||||||
case ';':
|
|
||||||
escaped.append("%3B");
|
|
||||||
break;
|
|
||||||
case '=':
|
|
||||||
escaped.append("%3D");
|
|
||||||
break;
|
|
||||||
case '?':
|
|
||||||
escaped.append("%3F");
|
|
||||||
break;
|
|
||||||
case '@':
|
|
||||||
escaped.append("%40");
|
|
||||||
break;
|
|
||||||
case '[':
|
|
||||||
escaped.append("%5B");
|
|
||||||
break;
|
|
||||||
case ']':
|
|
||||||
escaped.append("%5D");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
escaped.push_back(character);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return escaped;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -45,14 +45,3 @@
|
|||||||
bool send_notification(const std::string& title,
|
bool send_notification(const std::string& title,
|
||||||
const std::string body,
|
const std::string body,
|
||||||
std::optional<ghc::filesystem::path> origin);
|
std::optional<ghc::filesystem::path> origin);
|
||||||
|
|
||||||
/**
|
|
||||||
* Escape XML entities within a string. Used inside of desktop notifications.
|
|
||||||
*/
|
|
||||||
std::string xml_escape(std::string string);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* URL encode a file path. We won't escape forward slashes, and `path` should
|
|
||||||
* not yet include the `file://` prefix.
|
|
||||||
*/
|
|
||||||
std::string url_encode_path(std::string path);
|
|
||||||
|
|||||||
@@ -107,6 +107,115 @@ size_t strlcpy_buffer(char* dst, const std::string& src, size_t size) {
|
|||||||
return src.size();
|
return src.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string xml_escape(std::string string) {
|
||||||
|
// Implementation idea stolen from https://stackoverflow.com/a/5665377
|
||||||
|
std::string escaped;
|
||||||
|
escaped.reserve(
|
||||||
|
static_cast<size_t>(static_cast<double>(string.size()) * 1.1));
|
||||||
|
for (const char& character : string) {
|
||||||
|
switch (character) {
|
||||||
|
case '&':
|
||||||
|
escaped.append("&");
|
||||||
|
break;
|
||||||
|
case '\"':
|
||||||
|
escaped.append(""");
|
||||||
|
break;
|
||||||
|
case '\'':
|
||||||
|
escaped.append("'");
|
||||||
|
break;
|
||||||
|
case '<':
|
||||||
|
escaped.append("<");
|
||||||
|
break;
|
||||||
|
case '>':
|
||||||
|
escaped.append(">");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
escaped.push_back(character);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return escaped;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string url_encode_path(std::string path) {
|
||||||
|
// We only need to escape a couple of special characters here. This is used
|
||||||
|
// in the notifications as well as in the XDND proxy. We encode the reserved
|
||||||
|
// characters mentioned here, with the exception of the forward slash:
|
||||||
|
// https://en.wikipedia.org/wiki/Percent-encoding#Reserved_characters
|
||||||
|
std::string escaped;
|
||||||
|
escaped.reserve(
|
||||||
|
static_cast<size_t>(static_cast<double>(path.size()) * 1.1));
|
||||||
|
for (const char& character : path) {
|
||||||
|
switch (character) {
|
||||||
|
// Spaces are somehow in the above list, but Bitwig Studio requires
|
||||||
|
// spaces to be escaped in the `text/uri-list` format
|
||||||
|
case ' ':
|
||||||
|
escaped.append("%20");
|
||||||
|
break;
|
||||||
|
case '!':
|
||||||
|
escaped.append("%21");
|
||||||
|
break;
|
||||||
|
case '#':
|
||||||
|
escaped.append("%23");
|
||||||
|
break;
|
||||||
|
case '$':
|
||||||
|
escaped.append("%24");
|
||||||
|
break;
|
||||||
|
case '%':
|
||||||
|
escaped.append("%25");
|
||||||
|
break;
|
||||||
|
case '&':
|
||||||
|
escaped.append("%26");
|
||||||
|
break;
|
||||||
|
case '\'':
|
||||||
|
escaped.append("%27");
|
||||||
|
break;
|
||||||
|
case '(':
|
||||||
|
escaped.append("%28");
|
||||||
|
break;
|
||||||
|
case ')':
|
||||||
|
escaped.append("%29");
|
||||||
|
break;
|
||||||
|
case '*':
|
||||||
|
escaped.append("%2A");
|
||||||
|
break;
|
||||||
|
case '+':
|
||||||
|
escaped.append("%2B");
|
||||||
|
break;
|
||||||
|
case ',':
|
||||||
|
escaped.append("%2C");
|
||||||
|
break;
|
||||||
|
case ':':
|
||||||
|
escaped.append("%3A");
|
||||||
|
break;
|
||||||
|
case ';':
|
||||||
|
escaped.append("%3B");
|
||||||
|
break;
|
||||||
|
case '=':
|
||||||
|
escaped.append("%3D");
|
||||||
|
break;
|
||||||
|
case '?':
|
||||||
|
escaped.append("%3F");
|
||||||
|
break;
|
||||||
|
case '@':
|
||||||
|
escaped.append("%40");
|
||||||
|
break;
|
||||||
|
case '[':
|
||||||
|
escaped.append("%5B");
|
||||||
|
break;
|
||||||
|
case ']':
|
||||||
|
escaped.append("%5D");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
escaped.push_back(character);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return escaped;
|
||||||
|
}
|
||||||
|
|
||||||
ScopedFlushToZero::ScopedFlushToZero() noexcept {
|
ScopedFlushToZero::ScopedFlushToZero() noexcept {
|
||||||
old_ftz_mode_ = _MM_GET_FLUSH_ZERO_MODE();
|
old_ftz_mode_ = _MM_GET_FLUSH_ZERO_MODE();
|
||||||
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
|
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
|
||||||
|
|||||||
@@ -140,6 +140,17 @@ std::optional<rlim_t> get_rttime_limit() noexcept;
|
|||||||
*/
|
*/
|
||||||
bool is_watchdog_timer_disabled();
|
bool is_watchdog_timer_disabled();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escape XML entities within a string. Used inside of desktop notifications.
|
||||||
|
*/
|
||||||
|
std::string xml_escape(std::string string);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL encode a file path. We won't escape forward slashes, and `path` should
|
||||||
|
* not yet include the `file://` prefix.
|
||||||
|
*/
|
||||||
|
std::string url_encode_path(std::string path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of BSD's `strlcpy()` function specialized for copying C++
|
* An implementation of BSD's `strlcpy()` function specialized for copying C++
|
||||||
* strings to char buffers.
|
* strings to char buffers.
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ if is_64bit_system
|
|||||||
|
|
||||||
asio_dep,
|
asio_dep,
|
||||||
bitsery_dep,
|
bitsery_dep,
|
||||||
dbus_dep,
|
|
||||||
function2_dep,
|
function2_dep,
|
||||||
ghc_filesystem_dep,
|
ghc_filesystem_dep,
|
||||||
rt_dep,
|
rt_dep,
|
||||||
@@ -38,7 +37,6 @@ if with_bitbridge
|
|||||||
asio_dep,
|
asio_dep,
|
||||||
ghc_filesystem_dep,
|
ghc_filesystem_dep,
|
||||||
bitsery_dep,
|
bitsery_dep,
|
||||||
dbus_dep,
|
|
||||||
function2_dep,
|
function2_dep,
|
||||||
rt_dep,
|
rt_dep,
|
||||||
tomlplusplus_dep,
|
tomlplusplus_dep,
|
||||||
@@ -65,7 +63,6 @@ host_sources = files(
|
|||||||
'../common/logging/common.cpp',
|
'../common/logging/common.cpp',
|
||||||
'../common/logging/vst2.cpp',
|
'../common/logging/vst2.cpp',
|
||||||
'../common/audio-shm.cpp',
|
'../common/audio-shm.cpp',
|
||||||
'../common/notifications.cpp',
|
|
||||||
'../common/plugins.cpp',
|
'../common/plugins.cpp',
|
||||||
'../common/process.cpp',
|
'../common/process.cpp',
|
||||||
'../common/utils.cpp',
|
'../common/utils.cpp',
|
||||||
|
|||||||
Reference in New Issue
Block a user