1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00

added use_tls (determine from URL, whether TLS is used)

This commit is contained in:
Falk Werner 2019-02-23 16:19:00 +01:00
parent d18150d305
commit 9f468f600e
3 changed files with 8 additions and 3 deletions

View File

@ -8,6 +8,7 @@ struct wsfsp_url_protocol
char const * name;
size_t name_length;
int default_port;
bool use_tls;
};
static bool wsfsp_url_readprotocol(
@ -16,8 +17,8 @@ static bool wsfsp_url_readprotocol(
{
static struct wsfsp_url_protocol const known_protocols[] =
{
{"ws://", 5, 80},
{"wss://", 6, 443}
{"ws://", 5, 80, false},
{"wss://", 6, 443, true}
};
static size_t const count = (sizeof(known_protocols) / sizeof(known_protocols[0]));
@ -28,6 +29,7 @@ static bool wsfsp_url_readprotocol(
if (0 == strncmp(*data, protocol->name, protocol->name_length))
{
url->port = protocol->default_port;
url->use_tls = protocol->use_tls;
*data = *data + protocol->name_length;
found = true;
}

View File

@ -10,6 +10,7 @@ struct wsfsp_url
char * host;
int port;
char * path;
bool use_tls;
};
#ifdef __cplusplus

View File

@ -8,6 +8,7 @@ TEST(url, ParseWs)
bool result = wsfsp_url_init(&url, "ws://localhost/");
ASSERT_TRUE(result);
ASSERT_EQ(80, url.port);
ASSERT_FALSE(url.use_tls);
ASSERT_STREQ("localhost", url.host);
ASSERT_STREQ("/", url.path);
@ -20,6 +21,7 @@ TEST(url, ParswWss)
bool result = wsfsp_url_init(&url, "wss://localhost/");
ASSERT_TRUE(result);
ASSERT_EQ(443, url.port);
ASSERT_TRUE(url.use_tls);
ASSERT_STREQ("localhost", url.host);
ASSERT_STREQ("/", url.path);
@ -81,7 +83,7 @@ TEST(url, FailToParseMissingProtocol)
TEST(url, FailToParseMissingPath)
{
struct wsfsp_url url;
bool result = wsfsp_url_init(&url, "wss://localhost");
bool result = wsfsp_url_init(&url, "ws://localhost");
ASSERT_FALSE(result);
ASSERT_EQ(0, url.port);
ASSERT_EQ(nullptr, url.path);