mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
allow system to choose port of webfuse server
This commit is contained in:
parent
e72e78180e
commit
8a03f16aa5
@ -5,7 +5,11 @@
|
||||
### Breaking Changes
|
||||
|
||||
* Remove CMake support (change build system to meson)
|
||||
* Make argument credentials const in wf_authenticate_fn
|
||||
* Make argument credentials const in `wf_authenticate_fn`
|
||||
|
||||
### New Features
|
||||
|
||||
* Allow system to choose port of webfuse server (by setting port in `wf_server_config` to 0)
|
||||
|
||||
### Fixes
|
||||
|
||||
|
@ -65,6 +65,20 @@ extern WF_API void wf_server_service(
|
||||
extern WF_API void wf_server_interrupt(
|
||||
struct wf_server * server);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \brief Returns the port number used by the server
|
||||
///
|
||||
/// This function can be used to determine the port number of the server,
|
||||
/// if it was configured to let the system choose a free port.
|
||||
//
|
||||
/// \param server pointer to server
|
||||
/// \return Port number used by the server.
|
||||
///
|
||||
/// \see wf_server_config_set_port
|
||||
//------------------------------------------------------------------------------
|
||||
extern WF_API int wf_server_get_port(
|
||||
struct wf_server const * server);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -116,6 +116,8 @@ extern WF_API void wf_server_config_set_vhostname(
|
||||
//------------------------------------------------------------------------------
|
||||
/// \brief Sets the port number of the websockets server.
|
||||
///
|
||||
/// Note: Set port number to 0 to let system choose a free port.
|
||||
///
|
||||
/// \param config pointer of configuration object
|
||||
/// \param port port number of the websockets server
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -37,6 +37,11 @@ void wf_server_interrupt(
|
||||
wf_impl_server_interrupt(server);
|
||||
}
|
||||
|
||||
int wf_server_get_port(
|
||||
struct wf_server const * server)
|
||||
{
|
||||
return wf_impl_server_get_port(server);
|
||||
}
|
||||
|
||||
// server protocol
|
||||
|
||||
|
@ -22,6 +22,7 @@ struct wf_server
|
||||
struct lws_context * context;
|
||||
struct lws_http_mount mount;
|
||||
struct lws_context_creation_info info;
|
||||
int port;
|
||||
};
|
||||
|
||||
static bool wf_impl_server_tls_enabled(
|
||||
@ -55,6 +56,7 @@ static struct lws_context * wf_impl_server_context_create(
|
||||
server->info.vhost_name = server->config.vhost_name;
|
||||
server->info.ws_ping_pong_interval = 10;
|
||||
server->info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE;
|
||||
server->info.options |= LWS_SERVER_OPTION_EXPLICIT_VHOSTS;
|
||||
|
||||
if (NULL == server->config.document_root)
|
||||
{
|
||||
@ -71,8 +73,11 @@ static struct lws_context * wf_impl_server_context_create(
|
||||
}
|
||||
|
||||
struct lws_context * const context = lws_create_context(&server->info);
|
||||
return context;
|
||||
|
||||
struct lws_vhost * const vhost = lws_create_vhost(context, &server->info);
|
||||
server->port = lws_get_vhost_port(vhost);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
struct wf_server * wf_impl_server_create(
|
||||
@ -119,3 +124,8 @@ void wf_impl_server_interrupt(
|
||||
lws_cancel_service(server->context);
|
||||
}
|
||||
|
||||
extern int wf_impl_server_get_port(
|
||||
struct wf_server const * server)
|
||||
{
|
||||
return server->port;
|
||||
}
|
||||
|
@ -28,6 +28,9 @@ extern void wf_impl_server_service(
|
||||
extern void wf_impl_server_interrupt(
|
||||
struct wf_server * server);
|
||||
|
||||
extern int wf_impl_server_get_port(
|
||||
struct wf_server const * server);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "webfuse/tests/integration/server.hpp"
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
@ -59,7 +60,7 @@ public:
|
||||
|
||||
|
||||
config = wf_server_config_create();
|
||||
wf_server_config_set_port(config, 8080);
|
||||
wf_server_config_set_port(config, 0);
|
||||
wf_server_config_set_mountpoint_factory(config,
|
||||
&webfuse_test_server_create_mountpoint,
|
||||
reinterpret_cast<void*>(base_dir));
|
||||
@ -92,6 +93,14 @@ public:
|
||||
return is_shutdown_requested;
|
||||
}
|
||||
|
||||
std::string GetUrl(void) const
|
||||
{
|
||||
int const port = wf_server_get_port(server);
|
||||
std::ostringstream stream;
|
||||
stream << "wss://localhost:" << port << "/";
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
private:
|
||||
void RequestShutdown()
|
||||
{
|
||||
@ -136,5 +145,10 @@ char const * Server::GetBaseDir(void) const
|
||||
return d->base_dir;
|
||||
}
|
||||
|
||||
std::string Server::GetUrl(void) const
|
||||
{
|
||||
return d->GetUrl();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
#ifndef WF_TEST_INTEGRATION_SERVER_HPP
|
||||
#define WF_TEST_INTEGRATION_SERVER_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
@ -12,6 +14,7 @@ public:
|
||||
void Start(void);
|
||||
void Stop(void);
|
||||
char const * GetBaseDir(void) const;
|
||||
std::string GetUrl(void) const;
|
||||
private:
|
||||
class Private;
|
||||
Private * d;
|
||||
|
@ -38,7 +38,7 @@ namespace
|
||||
void SetUp()
|
||||
{
|
||||
server = new Server();
|
||||
provider = new Provider("wss://localhost:8080/");
|
||||
provider = new Provider(server->GetUrl().c_str());
|
||||
}
|
||||
|
||||
void TearDown()
|
||||
|
Loading…
Reference in New Issue
Block a user