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.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iomanip>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
@ -26,6 +25,7 @@
|
||||||
#include "pbd/xml++.h"
|
#include "pbd/xml++.h"
|
||||||
|
|
||||||
#include "manifest.h"
|
#include "manifest.h"
|
||||||
|
#include "resources.h"
|
||||||
|
|
||||||
static const char* const manifest_filename = "manifest.xml";
|
static const char* const manifest_filename = "manifest.xml";
|
||||||
|
|
||||||
|
@ -77,9 +77,9 @@ SurfaceManifest::to_json ()
|
||||||
|
|
||||||
ss << "{"
|
ss << "{"
|
||||||
<< "\"path\":\"" << Glib::path_get_basename (_path) << "\""
|
<< "\"path\":\"" << Glib::path_get_basename (_path) << "\""
|
||||||
<< ",\"name\":\"" << escape_json (_name) << "\""
|
<< ",\"name\":\"" << ServerResources::escape_json (_name) << "\""
|
||||||
<< ",\"description\":\"" << escape_json (_description) << "\""
|
<< ",\"description\":\"" << ServerResources::escape_json (_description) << "\""
|
||||||
<< ",\"version\":\"" << escape_json (_version) << "\""
|
<< ",\"version\":\"" << ServerResources::escape_json (_version) << "\""
|
||||||
<< "}";
|
<< "}";
|
||||||
|
|
||||||
return ss.str ();
|
return ss.str ();
|
||||||
|
@ -91,20 +91,3 @@ SurfaceManifest::exists_at_path (std::string path)
|
||||||
std::string xml_path = Glib::build_filename (path, manifest_filename);
|
std::string xml_path = Glib::build_filename (path, manifest_filename);
|
||||||
return Glib::file_test (xml_path, Glib::FILE_TEST_EXISTS);
|
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 ();
|
std::string to_json ();
|
||||||
|
|
||||||
static bool exists_at_path (std::string);
|
static bool exists_at_path (std::string);
|
||||||
static std::string escape_json (const std::string&);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _valid;
|
bool _valid;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#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&
|
const std::string&
|
||||||
ServerResources::index_dir ()
|
ServerResources::index_dir ()
|
||||||
{
|
{
|
||||||
|
@ -84,8 +102,8 @@ ServerResources::scan ()
|
||||||
SurfaceManifestVector builtin = read_manifests (builtin_dir_str);
|
SurfaceManifestVector builtin = read_manifests (builtin_dir_str);
|
||||||
|
|
||||||
ss << "[{"
|
ss << "[{"
|
||||||
<< "\"filesystemPath\":\"" << builtin_dir_str << "\""
|
<< "\"filesystemPath\":\"" << escape_json (builtin_dir_str) << "\""
|
||||||
<< ",\"path\":\"" << builtin_dir_name << "\""
|
<< ",\"path\":\"" << escape_json (builtin_dir_name) << "\""
|
||||||
<< ",\"surfaces\":"
|
<< ",\"surfaces\":"
|
||||||
<< "[";
|
<< "[";
|
||||||
|
|
||||||
|
@ -100,8 +118,8 @@ ServerResources::scan ()
|
||||||
SurfaceManifestVector user = read_manifests (user_dir_str);
|
SurfaceManifestVector user = read_manifests (user_dir_str);
|
||||||
|
|
||||||
ss << "]},{"
|
ss << "]},{"
|
||||||
<< "\"filesystemPath\":\"" << user_dir_str << "\""
|
<< "\"filesystemPath\":\"" << escape_json(user_dir_str) << "\""
|
||||||
<< ",\"path\":\"" << user_dir_name << "\""
|
<< ",\"path\":\"" << escape_json(user_dir_name) << "\""
|
||||||
<< ",\"surfaces\":"
|
<< ",\"surfaces\":"
|
||||||
<< "[";
|
<< "[";
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,8 @@ class ServerResources
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ServerResources ();
|
ServerResources ();
|
||||||
|
|
||||||
|
static std::string escape_json (const std::string&);
|
||||||
|
|
||||||
const std::string& index_dir ();
|
const std::string& index_dir ();
|
||||||
const std::string& builtin_dir ();
|
const std::string& builtin_dir ();
|
||||||
|
|
|
@ -69,21 +69,18 @@ WebsocketsServer::WebsocketsServer (ArdourSurface::ArdourWebsockets& surface)
|
||||||
memset (&_lws_mnt_root, 0, sizeof (lws_http_mount));
|
memset (&_lws_mnt_root, 0, sizeof (lws_http_mount));
|
||||||
_lws_mnt_root.mountpoint = "/";
|
_lws_mnt_root.mountpoint = "/";
|
||||||
_lws_mnt_root.mountpoint_len = strlen (_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 = _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_max_age = 3600;
|
||||||
_lws_mnt_root.cache_reusable = 1;
|
_lws_mnt_root.cache_reusable = 1;
|
||||||
_lws_mnt_root.cache_revalidate = 1;
|
_lws_mnt_root.cache_revalidate = 1;
|
||||||
|
|
||||||
/* user defined surfaces in the user config directory */
|
/* 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 = "/user";
|
||||||
_lws_mnt_user.mountpoint_len = strlen (_lws_mnt_user.mountpoint);
|
_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.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;
|
_lws_mnt_root.mount_next = &_lws_mnt_user;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user