1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2026-03-02 04:09:18 +00:00

fixed client protocol low level API (#49)

* fixed client protocol low level API: enables usage of providing clients along with other websocket protocols

* fix: made some c'tors explicit
This commit is contained in:
Falk Werner
2020-02-19 22:44:56 +01:00
committed by GitHub
parent 9d83f1687e
commit abd6efe477
11 changed files with 460 additions and 46 deletions

View File

@@ -160,10 +160,9 @@ void wfp_client_config_set_onread(
struct wfp_client_protocol * wfp_client_protocol_create(
struct wfp_provider const * provider,
void * user_data)
struct wfp_client_config const * config)
{
return wfp_impl_client_protocol_create(provider, user_data);
return wfp_impl_client_protocol_create(config);
}
void wfp_client_protocol_dispose(
@@ -179,6 +178,15 @@ void wfp_client_protocol_init_lws(
wfp_impl_client_protocol_init_lws(protocol, lws_protocol);
}
void wfp_client_protocol_connect(
struct wfp_client_protocol * protocol,
struct lws_context * context,
char const * url)
{
wfp_impl_client_protocol_connect(protocol, context, url);
}
// client
struct wfp_client * wfp_client_create(

View File

@@ -9,10 +9,8 @@
#include "webfuse/provider/impl/provider.h"
#include "webfuse/provider/impl/client_protocol.h"
#include "webfuse/provider/impl/client_config.h"
#include "webfuse/provider/impl/url.h"
#include "webfuse/core/lws_log.h"
#define WFP_PROTOCOL ("fs")
#define WFP_CLIENT_PROTOCOL_COUNT 2
struct wfp_client
@@ -37,7 +35,7 @@ struct wfp_client * wfp_impl_client_create(
wfp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data);
memset(client->protocols, 0, sizeof(struct lws_protocols) * WFP_CLIENT_PROTOCOL_COUNT);
client->protocols[0].name = "fs";
client->protocols[0].name = WFP_CLIENT_PROTOCOL_NAME;
wfp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]);
memset(&client->info, 0, sizeof(struct lws_context_creation_info));
@@ -69,26 +67,7 @@ void wfp_impl_client_connect(
struct wfp_client * client,
char const * url)
{
struct wfp_impl_url url_data;
bool const success = wfp_impl_url_init(&url_data, url);
if (success)
{
struct lws_client_connect_info info;
memset(&info, 0, sizeof(struct lws_client_connect_info));
info.context = client->context;
info.port = url_data.port;
info.address = url_data.host;
info.path = url_data.path;
info.host = info.address;
info.origin = info.address;
info.ssl_connection = (url_data.use_tls) ? LCCSCF_USE_SSL : 0;
info.protocol = WFP_PROTOCOL;
info.pwsi = &client->protocol.wsi;
lws_client_connect_via_info(&info);
wfp_impl_url_cleanup(&url_data);
}
wfp_impl_client_protocol_connect(&client->protocol, client->context, url);
}
void wfp_impl_client_disconnect(

View File

@@ -7,11 +7,13 @@
#include <jansson.h>
#include "webfuse/provider/impl/client_config.h"
#include "webfuse/provider/impl/provider.h"
#include "webfuse/core/util.h"
#include "webfuse/core/message.h"
#include "webfuse/core/message_queue.h"
#include "webfuse/core/container_of.h"
#include "webfuse/provider/impl/url.h"
static void wfp_impl_client_protocol_respond(
json_t * response,
@@ -156,13 +158,12 @@ void wfp_impl_client_protocol_cleanup(
}
struct wfp_client_protocol * wfp_impl_client_protocol_create(
struct wfp_provider const * provider,
void * user_data)
struct wfp_client_config const * config)
{
struct wfp_client_protocol * protocol = malloc(sizeof(struct wfp_client_protocol));
if (NULL != protocol)
{
wfp_impl_client_protocol_init(protocol, provider, user_data);
wfp_impl_client_protocol_init(protocol, &config->provider, config->user_data);
}
return protocol;
@@ -183,3 +184,35 @@ void wfp_impl_client_protocol_init_lws(
lws_protocol->per_session_data_size = 0;
lws_protocol->user = protocol;
}
void wfp_impl_client_protocol_connect(
struct wfp_client_protocol * protocol,
struct lws_context * context,
char const * url)
{
struct wfp_impl_url url_data;
bool const success = wfp_impl_url_init(&url_data, url);
if (success)
{
struct lws_client_connect_info info;
memset(&info, 0, sizeof(struct lws_client_connect_info));
info.context = context;
info.port = url_data.port;
info.address = url_data.host;
info.path = url_data.path;
info.host = info.address;
info.origin = info.address;
info.ssl_connection = (url_data.use_tls) ? LCCSCF_USE_SSL : 0;
info.protocol = WFP_CLIENT_PROTOCOL_NAME;
info.pwsi = &protocol->wsi;
lws_client_connect_via_info(&info);
wfp_impl_url_cleanup(&url_data);
}
else
{
protocol->provider.disconnected(protocol->user_data);
}
}

View File

@@ -11,8 +11,11 @@ extern "C"
{
#endif
struct wfp_provider;
#define WFP_CLIENT_PROTOCOL_NAME ("fs")
struct wfp_client_config;
struct lws_protocols;
struct lws_context;
struct wfp_client_protocol
{
@@ -33,8 +36,7 @@ extern void wfp_impl_client_protocol_cleanup(
struct wfp_client_protocol * protocol);
extern struct wfp_client_protocol * wfp_impl_client_protocol_create(
struct wfp_provider const * provider,
void * user_data);
struct wfp_client_config const * config);
extern void wfp_impl_client_protocol_dispose(
struct wfp_client_protocol * protocol);
@@ -43,6 +45,11 @@ extern void wfp_impl_client_protocol_init_lws(
struct wfp_client_protocol * protocol,
struct lws_protocols * lws_protocol);
extern void wfp_impl_client_protocol_connect(
struct wfp_client_protocol * protocol,
struct lws_context * context,
char const * url);
#ifdef __cplusplus
}
#endif