WebSockets: compatibility fixes for Windows
Escape path strings in surfaces.json Default to index.html in mount points
This commit is contained in:
parent
47e4216012
commit
cc08a2d945
|
@ -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 ();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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\":"
|
||||
<< "[";
|
||||
|
||||
|
|
|
@ -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 ();
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user