mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-10 00:34:59 +01:00
WebSockets: also json-escape strings in state messages
This commit is contained in:
parent
946094b25c
commit
dbb26daafa
7 changed files with 82 additions and 29 deletions
|
|
@ -16,7 +16,6 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
|
|
@ -27,6 +26,7 @@
|
|||
#include "pbd/file_utils.h"
|
||||
|
||||
#include "resources.h"
|
||||
#include "json.h"
|
||||
|
||||
static const char* const data_dir_env_var = "ARDOUR_WEBSURFACES_PATH";
|
||||
static const char* const data_dir_name = "web_surfaces";
|
||||
|
|
@ -46,23 +46,6 @@ ServerResources::ServerResources ()
|
|||
{
|
||||
}
|
||||
|
||||
/* adapted from https://stackoverflow.com/questions/7724448/simple-json-string-escape-for-c
|
||||
CC BY-SA 4.0 license */
|
||||
std::string
|
||||
ServerResources::escape_json (const std::string &s) {
|
||||
std::ostringstream o;
|
||||
|
||||
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
|
||||
if (*it == '"' || *it == '\\' || ('\x00' <= *it && *it <= '\x1f')) {
|
||||
o << "\\u" << std::hex << std::setw (4) << std::setfill ('0') << static_cast<int>(*it);
|
||||
} else {
|
||||
o << *it;
|
||||
}
|
||||
}
|
||||
|
||||
return o.str ();
|
||||
}
|
||||
|
||||
const std::string&
|
||||
ServerResources::index_dir ()
|
||||
{
|
||||
|
|
@ -102,8 +85,8 @@ ServerResources::scan ()
|
|||
SurfaceManifestVector builtin = read_manifests (builtin_dir_str);
|
||||
|
||||
ss << "[{"
|
||||
<< "\"filesystemPath\":\"" << escape_json (builtin_dir_str) << "\""
|
||||
<< ",\"path\":\"" << escape_json (builtin_dir_name) << "\""
|
||||
<< "\"filesystemPath\":\"" << Json::escape (builtin_dir_str) << "\""
|
||||
<< ",\"path\":\"" << Json::escape (builtin_dir_name) << "\""
|
||||
<< ",\"surfaces\":"
|
||||
<< "[";
|
||||
|
||||
|
|
@ -118,8 +101,8 @@ ServerResources::scan ()
|
|||
SurfaceManifestVector user = read_manifests (user_dir_str);
|
||||
|
||||
ss << "]},{"
|
||||
<< "\"filesystemPath\":\"" << escape_json(user_dir_str) << "\""
|
||||
<< ",\"path\":\"" << escape_json(user_dir_name) << "\""
|
||||
<< "\"filesystemPath\":\"" << Json::escape (user_dir_str) << "\""
|
||||
<< ",\"path\":\"" << Json::escape (user_dir_name) << "\""
|
||||
<< ",\"surfaces\":"
|
||||
<< "[";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue