1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-09-29 20:20:46 +00:00
falk-werner_webfuse-provider/lib/webfuse/provider/impl/client.c
Falk Werner 07e32757f8
chore(webfuse) Increase test coverage (#34)
* removes unnecessary code

* adds test of wf_status

* adds tests of wf_message

* adds tests of wf_message_queue

* changed branch of coverage badge to display correct results

* moves core tests into separate subdirectory

* increases coverage of timer test

* moves adapter specific tests into separate directory

* moves provider specific tests into separate directory

* adds tests of jsonrpc utilities

* adds tests of jsonrpc request

* adds test of jsonrpc response

* adds tests of jsonrpc server

* adds tests of jsonrpc proxy

* adds integration test (found some issues)

* disables problematic tests

* fixes resource leak: pending timer after cleanup proxy

* fixes order of cleanup to prevent processing pending requests after filesystem shut down

* fixes some memcheck and helgrind errors: initialization of lws_log; setup of client and server

* disabled a test

* fixes error in msleep utility

* fixes deadlock at IntegrationTest using valgrind

* removes unit test code from coverage report

* adds some integration tests

* makes badge show coverage of master

* fixes some coding style issues

* fixes eary trigger of is_connected (provider)

* fixes read error in 32 bit environments\n\ninode is always 64 bit, but variadic wf_impl_jsonrpc_proxy_invoke expects int
2019-05-19 14:33:42 +02:00

115 lines
2.9 KiB
C

#include "webfuse/provider/impl/client.h"
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <libwebsockets.h>
#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
{
struct wfp_client_protocol protocol;
struct lws_context_creation_info info;
struct lws_protocols protocols[WFP_CLIENT_PROTOCOL_COUNT];
struct lws_context * context;
char * key_path;
char * cert_path;
};
struct wfp_client * wfp_impl_client_create(
struct wfp_client_config * config)
{
wf_lwslog_disable();
struct wfp_client * client = malloc(sizeof(struct wfp_client));
if (NULL != client)
{
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";
wfp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]);
memset(&client->info, 0, sizeof(struct lws_context_creation_info));
client->info.port = CONTEXT_PORT_NO_LISTEN;
client->info.protocols = client->protocols;
client->info.uid = -1;
client->info.gid = -1;
if ((NULL != config->cert_path) && (NULL != config->key_path))
{
}
client->context = lws_create_context(&client->info);
}
return client;
}
void wfp_impl_client_dispose(
struct wfp_client * client)
{
lws_context_destroy(client->context);
wfp_impl_client_protocol_cleanup(&client->protocol);
free(client);
}
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);
}
}
void wfp_impl_client_disconnect(
struct wfp_client * client)
{
(void) client;
// ToDo: implement me
}
bool wfp_impl_client_is_connected(
struct wfp_client * client)
{
return client->protocol.is_connected;
}
void wfp_impl_client_service(
struct wfp_client * client,
int timeout_ms)
{
lws_service(client->context, timeout_ms);
}