summaryrefslogtreecommitdiff
path: root/libs/surfaces/websockets/resources.cc
diff options
context:
space:
mode:
authorLuciano Iam <lucianito@gmail.com>2020-04-22 18:17:13 +0200
committerRobin Gareus <robin@gareus.org>2020-04-22 21:59:35 +0200
commitdbb26daafaea788d3b246e02c7d1cf8f858da7ab (patch)
treef789eb71012da639fda946c81f11d6e6e9016e17 /libs/surfaces/websockets/resources.cc
parent946094b25c7bef393601cef159bf54fdd6119226 (diff)
WebSockets: also json-escape strings in state messages
Diffstat (limited to 'libs/surfaces/websockets/resources.cc')
-rw-r--r--libs/surfaces/websockets/resources.cc27
1 files changed, 5 insertions, 22 deletions
diff --git a/libs/surfaces/websockets/resources.cc b/libs/surfaces/websockets/resources.cc
index 18f41621cc..afad30e887 100644
--- a/libs/surfaces/websockets/resources.cc
+++ b/libs/surfaces/websockets/resources.cc
@@ -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\":"
<< "[";