summaryrefslogtreecommitdiff
path: root/libs/surfaces
diff options
context:
space:
mode:
authorLuciano Iam <lucianito@gmail.com>2020-04-21 14:13:15 +0200
committerLuciano Iam <lucianito@gmail.com>2020-04-21 15:53:27 +0200
commitcc08a2d945568fc83cdf03d228bd20c3e6cccc02 (patch)
tree0cd5fc9eaa7bfcc1ad8b86c8300691f3b630a612 /libs/surfaces
parent47e4216012b9c31666a857d0d9259811a899c244 (diff)
WebSockets: compatibility fixes for Windows
Escape path strings in surfaces.json Default to index.html in mount points
Diffstat (limited to 'libs/surfaces')
-rw-r--r--libs/surfaces/websockets/manifest.cc25
-rw-r--r--libs/surfaces/websockets/manifest.h1
-rw-r--r--libs/surfaces/websockets/resources.cc26
-rw-r--r--libs/surfaces/websockets/resources.h2
-rw-r--r--libs/surfaces/websockets/server.cc9
5 files changed, 31 insertions, 32 deletions
diff --git a/libs/surfaces/websockets/manifest.cc b/libs/surfaces/websockets/manifest.cc
index d0174e640d..c24977c681 100644
--- a/libs/surfaces/websockets/manifest.cc
+++ b/libs/surfaces/websockets/manifest.cc
@@ -16,7 +16,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include <iomanip>
#include <iostream>
#include <sstream>
@@ -26,6 +25,7 @@
#include "pbd/xml++.h"
#include "manifest.h"
+#include "resources.h"
static const char* const manifest_filename = "manifest.xml";
@@ -77,9 +77,9 @@ SurfaceManifest::to_json ()
ss << "{"
<< "\"path\":\"" << Glib::path_get_basename (_path) << "\""
- << ",\"name\":\"" << escape_json (_name) << "\""
- << ",\"description\":\"" << escape_json (_description) << "\""
- << ",\"version\":\"" << escape_json (_version) << "\""
+ << ",\"name\":\"" << ServerResources::escape_json (_name) << "\""
+ << ",\"description\":\"" << ServerResources::escape_json (_description) << "\""
+ << ",\"version\":\"" << ServerResources::escape_json (_version) << "\""
<< "}";
return ss.str ();
@@ -91,20 +91,3 @@ SurfaceManifest::exists_at_path (std::string path)
std::string xml_path = Glib::build_filename (path, manifest_filename);
return Glib::file_test (xml_path, Glib::FILE_TEST_EXISTS);
}
-
-/* adapted from https://stackoverflow.com/questions/7724448/simple-json-string-escape-for-c
- CC BY-SA 4.0 license */
-std::string
-SurfaceManifest::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 ();
-}
diff --git a/libs/surfaces/websockets/manifest.h b/libs/surfaces/websockets/manifest.h
index 40b6e177a3..45ecc37f6a 100644
--- a/libs/surfaces/websockets/manifest.h
+++ b/libs/surfaces/websockets/manifest.h
@@ -37,7 +37,6 @@ public:
std::string to_json ();
static bool exists_at_path (std::string);
- static std::string escape_json (const std::string&);
private:
bool _valid;
diff --git a/libs/surfaces/websockets/resources.cc b/libs/surfaces/websockets/resources.cc
index ec43ae7c44..18f41621cc 100644
--- a/libs/surfaces/websockets/resources.cc
+++ b/libs/surfaces/websockets/resources.cc
@@ -16,6 +16,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include <iomanip>
#include <iostream>
#include <sstream>
@@ -45,6 +46,23 @@ 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 ()
{
@@ -84,8 +102,8 @@ ServerResources::scan ()
SurfaceManifestVector builtin = read_manifests (builtin_dir_str);
ss << "[{"
- << "\"filesystemPath\":\"" << builtin_dir_str << "\""
- << ",\"path\":\"" << builtin_dir_name << "\""
+ << "\"filesystemPath\":\"" << escape_json (builtin_dir_str) << "\""
+ << ",\"path\":\"" << escape_json (builtin_dir_name) << "\""
<< ",\"surfaces\":"
<< "[";
@@ -100,8 +118,8 @@ ServerResources::scan ()
SurfaceManifestVector user = read_manifests (user_dir_str);
ss << "]},{"
- << "\"filesystemPath\":\"" << user_dir_str << "\""
- << ",\"path\":\"" << user_dir_name << "\""
+ << "\"filesystemPath\":\"" << escape_json(user_dir_str) << "\""
+ << ",\"path\":\"" << escape_json(user_dir_name) << "\""
<< ",\"surfaces\":"
<< "[";
diff --git a/libs/surfaces/websockets/resources.h b/libs/surfaces/websockets/resources.h
index f942ec1ce7..9d6f72d280 100644
--- a/libs/surfaces/websockets/resources.h
+++ b/libs/surfaces/websockets/resources.h
@@ -30,6 +30,8 @@ class ServerResources
{
public:
ServerResources ();
+
+ static std::string escape_json (const std::string&);
const std::string& index_dir ();
const std::string& builtin_dir ();
diff --git a/libs/surfaces/websockets/server.cc b/libs/surfaces/websockets/server.cc
index 2a69b5eff8..5dba36c5fa 100644
--- a/libs/surfaces/websockets/server.cc
+++ b/libs/surfaces/websockets/server.cc
@@ -69,21 +69,18 @@ WebsocketsServer::WebsocketsServer (ArdourSurface::ArdourWebsockets& surface)
memset (&_lws_mnt_root, 0, sizeof (lws_http_mount));
_lws_mnt_root.mountpoint = "/";
_lws_mnt_root.mountpoint_len = strlen (_lws_mnt_root.mountpoint);
- _lws_mnt_root.origin_protocol = LWSMPRO_FILE;
_lws_mnt_root.origin = _resources.index_dir ().c_str ();
+ _lws_mnt_root.origin_protocol = LWSMPRO_FILE;
+ _lws_mnt_root.def = "index.html";
_lws_mnt_root.cache_max_age = 3600;
_lws_mnt_root.cache_reusable = 1;
_lws_mnt_root.cache_revalidate = 1;
/* user defined surfaces in the user config directory */
- memset (&_lws_mnt_user, 0, sizeof (lws_http_mount));
+ memcpy (&_lws_mnt_user, &_lws_mnt_root, sizeof (lws_http_mount));
_lws_mnt_user.mountpoint = "/user";
_lws_mnt_user.mountpoint_len = strlen (_lws_mnt_user.mountpoint);
- _lws_mnt_user.origin_protocol = LWSMPRO_FILE;
_lws_mnt_user.origin = _resources.user_dir ().c_str ();
- _lws_mnt_user.cache_max_age = 3600;
- _lws_mnt_user.cache_reusable = 1;
- _lws_mnt_user.cache_revalidate = 1;
_lws_mnt_root.mount_next = &_lws_mnt_user;