mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
moved wf_url to core
This commit is contained in:
parent
06a24e09da
commit
f2bbebd670
@ -85,14 +85,14 @@ void
|
||||
wf_impl_client_service(
|
||||
struct wf_client * client)
|
||||
{
|
||||
(void) client;
|
||||
lws_service(client->context, 0);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_interrupt(
|
||||
struct wf_client * client)
|
||||
{
|
||||
(void) client;
|
||||
lws_cancel_service(client->context);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -53,3 +53,18 @@ wf_impl_client_protocol_init_lws(
|
||||
lws_protocol->per_session_data_size = 0;
|
||||
lws_protocol->user = protocol;
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_protocol_connect(
|
||||
struct wf_client_protocol * protocol,
|
||||
char const * url)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_protocol_disconnect(
|
||||
struct wf_client_protocol * protocol)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -43,6 +43,15 @@ wf_impl_client_protocol_init_lws(
|
||||
struct wf_client_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol);
|
||||
|
||||
extern void
|
||||
wf_impl_client_protocol_connect(
|
||||
struct wf_client_protocol * protocol,
|
||||
char const * url);
|
||||
|
||||
extern void
|
||||
wf_impl_client_protocol_disconnect(
|
||||
struct wf_client_protocol * protocol);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,4 +1,6 @@
|
||||
#include "webfuse/adapter/impl/client_tlsconfig.h"
|
||||
#include "webfuse/core/url.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include "webfuse/provider/impl/url.h"
|
||||
#include "webfuse/core/url.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wfp_impl_url_protocol
|
||||
struct wf_url_protocol
|
||||
{
|
||||
char const * name;
|
||||
size_t name_length;
|
||||
@ -11,11 +11,11 @@ struct wfp_impl_url_protocol
|
||||
bool use_tls;
|
||||
};
|
||||
|
||||
static bool wfp_impl_url_readprotocol(
|
||||
struct wfp_impl_url * url,
|
||||
static bool wf_url_readprotocol(
|
||||
struct wf_url * url,
|
||||
char const * * data)
|
||||
{
|
||||
static struct wfp_impl_url_protocol const known_protocols[] =
|
||||
static struct wf_url_protocol const known_protocols[] =
|
||||
{
|
||||
{"ws://", 5, 80, false},
|
||||
{"wss://", 6, 443, true}
|
||||
@ -25,7 +25,7 @@ static bool wfp_impl_url_readprotocol(
|
||||
bool found = false;
|
||||
for(size_t i = 0; (!found) && (i < count); i++)
|
||||
{
|
||||
struct wfp_impl_url_protocol const * protocol = &known_protocols[i];
|
||||
struct wf_url_protocol const * protocol = &known_protocols[i];
|
||||
if (0 == strncmp(*data, protocol->name, protocol->name_length))
|
||||
{
|
||||
url->port = protocol->default_port;
|
||||
@ -38,8 +38,8 @@ static bool wfp_impl_url_readprotocol(
|
||||
return found;
|
||||
}
|
||||
|
||||
static bool wfp_impl_url_readhost(
|
||||
struct wfp_impl_url * url,
|
||||
static bool wf_url_readhost(
|
||||
struct wf_url * url,
|
||||
char const * * data)
|
||||
{
|
||||
char * end = strpbrk(*data, ":/");
|
||||
@ -55,8 +55,8 @@ static bool wfp_impl_url_readhost(
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool wfp_impl_url_readport(
|
||||
struct wfp_impl_url * url,
|
||||
static bool wf_url_readport(
|
||||
struct wf_url * url,
|
||||
char const * * data)
|
||||
{
|
||||
bool result;
|
||||
@ -81,8 +81,8 @@ static bool wfp_impl_url_readport(
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool wfp_impl_url_readpath(
|
||||
struct wfp_impl_url * url,
|
||||
static bool wf_url_readpath(
|
||||
struct wf_url * url,
|
||||
char const * * data)
|
||||
{
|
||||
bool const result = ('/' == **data);
|
||||
@ -93,33 +93,33 @@ static bool wfp_impl_url_readpath(
|
||||
}
|
||||
|
||||
|
||||
bool wfp_impl_url_init(
|
||||
struct wfp_impl_url * url,
|
||||
bool wf_url_init(
|
||||
struct wf_url * url,
|
||||
char const * value)
|
||||
{
|
||||
memset(url, 0, sizeof(struct wfp_impl_url));
|
||||
memset(url, 0, sizeof(struct wf_url));
|
||||
char const * data = value;
|
||||
|
||||
bool const result =
|
||||
wfp_impl_url_readprotocol(url, &data) &&
|
||||
wfp_impl_url_readhost(url, &data) &&
|
||||
wfp_impl_url_readport(url, &data) &&
|
||||
wfp_impl_url_readpath(url, &data)
|
||||
wf_url_readprotocol(url, &data) &&
|
||||
wf_url_readhost(url, &data) &&
|
||||
wf_url_readport(url, &data) &&
|
||||
wf_url_readpath(url, &data)
|
||||
;
|
||||
|
||||
if (!result)
|
||||
{
|
||||
wfp_impl_url_cleanup(url);
|
||||
wf_url_cleanup(url);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void wfp_impl_url_cleanup(
|
||||
struct wfp_impl_url * url)
|
||||
void wf_url_cleanup(
|
||||
struct wf_url * url)
|
||||
{
|
||||
free(url->host);
|
||||
free(url->path);
|
||||
memset(url, 0, sizeof(struct wfp_impl_url));
|
||||
memset(url, 0, sizeof(struct wf_url));
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef WF_PROVIDER_IMPL_URL_H
|
||||
#define WF_PROVIDER_IMPL_URL_H
|
||||
#ifndef WF_URL_H
|
||||
#define WF_URL_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
@ -9,7 +9,7 @@
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
struct wfp_impl_url
|
||||
struct wf_url
|
||||
{
|
||||
char * host;
|
||||
int port;
|
||||
@ -17,12 +17,12 @@ struct wfp_impl_url
|
||||
bool use_tls;
|
||||
};
|
||||
|
||||
extern bool wfp_impl_url_init(
|
||||
struct wfp_impl_url * url,
|
||||
extern bool wf_url_init(
|
||||
struct wf_url * url,
|
||||
char const * value);
|
||||
|
||||
extern void wfp_impl_url_cleanup(
|
||||
struct wfp_impl_url * url);
|
||||
extern void wf_url_cleanup(
|
||||
struct wf_url * url);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
@ -13,7 +13,7 @@
|
||||
#include "webfuse/core/message.h"
|
||||
#include "webfuse/core/message_queue.h"
|
||||
#include "webfuse/core/container_of.h"
|
||||
#include "webfuse/provider/impl/url.h"
|
||||
#include "webfuse/core/url.h"
|
||||
#include "webfuse/core/protocol_names.h"
|
||||
|
||||
#include "webfuse/core/timer/manager.h"
|
||||
@ -297,8 +297,8 @@ void wfp_impl_client_protocol_connect(
|
||||
struct lws_context * context,
|
||||
char const * url)
|
||||
{
|
||||
struct wfp_impl_url url_data;
|
||||
bool const success = wfp_impl_url_init(&url_data, url);
|
||||
struct wf_url url_data;
|
||||
bool const success = wf_url_init(&url_data, url);
|
||||
if (success)
|
||||
{
|
||||
struct lws_client_connect_info info;
|
||||
@ -316,7 +316,7 @@ void wfp_impl_client_protocol_connect(
|
||||
|
||||
lws_client_connect_via_info(&info);
|
||||
|
||||
wfp_impl_url_cleanup(&url_data);
|
||||
wf_url_cleanup(&url_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -29,6 +29,7 @@ webfuse_core = static_library('webfuse_core',
|
||||
'lib/webfuse/core/base64.c',
|
||||
'lib/webfuse/core/lws_log.c',
|
||||
'lib/webfuse/core/json_util.c',
|
||||
'lib/webfuse/core/url.c',
|
||||
'lib/webfuse/core/timer/manager.c',
|
||||
'lib/webfuse/core/timer/timepoint.c',
|
||||
'lib/webfuse/core/timer/timer.c',
|
||||
@ -56,7 +57,6 @@ if not without_provider
|
||||
|
||||
webfuse_provider_static = static_library('webfuse_provider',
|
||||
'lib/webfuse/provider/api.c',
|
||||
'lib/webfuse/provider/impl/url.c',
|
||||
'lib/webfuse/provider/impl/client.c',
|
||||
'lib/webfuse/provider/impl/client_config.c',
|
||||
'lib/webfuse/provider/impl/client_protocol.c',
|
||||
@ -226,6 +226,7 @@ alltests = executable('alltests',
|
||||
'test/webfuse/tests/core/test_status.cc',
|
||||
'test/webfuse/tests/core/test_message.cc',
|
||||
'test/webfuse/tests/core/test_message_queue.cc',
|
||||
'test/webfuse/tests/core/test_url.cc',
|
||||
'test/webfuse/tests/adapter/test_server.cc',
|
||||
'test/webfuse/tests/adapter/test_server_config.cc',
|
||||
'test/webfuse/tests/adapter/test_credentials.cc',
|
||||
@ -240,7 +241,6 @@ alltests = executable('alltests',
|
||||
'test/webfuse/tests/adapter/operation/test_readdir.cc',
|
||||
'test/webfuse/tests/adapter/operation/test_getattr.cc',
|
||||
'test/webfuse/tests/adapter/operation/test_lookup.cc',
|
||||
'test/webfuse/tests/provider/test_url.cc',
|
||||
'test/webfuse/tests/provider/test_client_protocol.cc',
|
||||
'test/webfuse/tests/provider/operation/test_close.cc',
|
||||
'test/webfuse/tests/provider/operation/test_getattr.cc',
|
||||
|
@ -1,69 +1,69 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "webfuse/provider/impl/url.h"
|
||||
#include "webfuse/core/url.h"
|
||||
|
||||
TEST(url, ParseWs)
|
||||
{
|
||||
struct wfp_impl_url url;
|
||||
bool result = wfp_impl_url_init(&url, "ws://localhost/");
|
||||
struct wf_url url;
|
||||
bool result = wf_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);
|
||||
|
||||
wfp_impl_url_cleanup(&url);
|
||||
wf_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParswWss)
|
||||
{
|
||||
struct wfp_impl_url url;
|
||||
bool result = wfp_impl_url_init(&url, "wss://localhost/");
|
||||
struct wf_url url;
|
||||
bool result = wf_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);
|
||||
|
||||
wfp_impl_url_cleanup(&url);
|
||||
wf_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParseIPAdress)
|
||||
{
|
||||
struct wfp_impl_url url;
|
||||
bool result = wfp_impl_url_init(&url, "ws://127.0.0.1/");
|
||||
struct wf_url url;
|
||||
bool result = wf_url_init(&url, "ws://127.0.0.1/");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_EQ(80, url.port);
|
||||
ASSERT_STREQ("127.0.0.1", url.host);
|
||||
ASSERT_STREQ("/", url.path);
|
||||
|
||||
wfp_impl_url_cleanup(&url);
|
||||
wf_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParsePort)
|
||||
{
|
||||
struct wfp_impl_url url;
|
||||
bool result = wfp_impl_url_init(&url, "ws://localhost:54321/");
|
||||
struct wf_url url;
|
||||
bool result = wf_url_init(&url, "ws://localhost:54321/");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_EQ(54321, url.port);
|
||||
|
||||
wfp_impl_url_cleanup(&url);
|
||||
wf_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParseNonEmptyPath)
|
||||
{
|
||||
struct wfp_impl_url url;
|
||||
bool result = wfp_impl_url_init(&url, "ws://localhost/some_path?query");
|
||||
struct wf_url url;
|
||||
bool result = wf_url_init(&url, "ws://localhost/some_path?query");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_STREQ("/some_path?query", url.path);
|
||||
|
||||
wfp_impl_url_cleanup(&url);
|
||||
wf_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, FailToParseUnknownProtocol)
|
||||
{
|
||||
struct wfp_impl_url url;
|
||||
bool result = wfp_impl_url_init(&url, "unknown://localhost/");
|
||||
struct wf_url url;
|
||||
bool result = wf_url_init(&url, "unknown://localhost/");
|
||||
ASSERT_FALSE(result);
|
||||
ASSERT_EQ(0, url.port);
|
||||
ASSERT_EQ(nullptr, url.path);
|
||||
@ -72,8 +72,8 @@ TEST(url, FailToParseUnknownProtocol)
|
||||
|
||||
TEST(url, FailToParseMissingProtocol)
|
||||
{
|
||||
struct wfp_impl_url url;
|
||||
bool result = wfp_impl_url_init(&url, "unknown");
|
||||
struct wf_url url;
|
||||
bool result = wf_url_init(&url, "unknown");
|
||||
ASSERT_FALSE(result);
|
||||
ASSERT_EQ(0, url.port);
|
||||
ASSERT_EQ(nullptr, url.path);
|
||||
@ -82,8 +82,8 @@ TEST(url, FailToParseMissingProtocol)
|
||||
|
||||
TEST(url, FailToParseMissingPath)
|
||||
{
|
||||
struct wfp_impl_url url;
|
||||
bool result = wfp_impl_url_init(&url, "ws://localhost");
|
||||
struct wf_url url;
|
||||
bool result = wf_url_init(&url, "ws://localhost");
|
||||
ASSERT_FALSE(result);
|
||||
ASSERT_EQ(0, url.port);
|
||||
ASSERT_EQ(nullptr, url.path);
|
Loading…
Reference in New Issue
Block a user