2019-03-26 22:04:53 +00:00
|
|
|
#include "webfuse/provider/impl/client.h"
|
2019-02-16 15:08:17 +00:00
|
|
|
|
2019-02-17 13:31:04 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2019-02-18 22:30:39 +00:00
|
|
|
#include <libwebsockets.h>
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
#include "webfuse/provider/impl/provider.h"
|
|
|
|
#include "webfuse/provider/impl/client_protocol.h"
|
|
|
|
#include "webfuse/provider/impl/client_config.h"
|
2019-05-19 12:33:42 +00:00
|
|
|
#include "webfuse/core/lws_log.h"
|
2019-02-18 22:30:39 +00:00
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
#define WFP_CLIENT_PROTOCOL_COUNT 2
|
2019-02-17 13:31:04 +00:00
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
struct wfp_client
|
2019-02-17 13:31:04 +00:00
|
|
|
{
|
2019-03-26 22:04:53 +00:00
|
|
|
struct wfp_client_protocol protocol;
|
2019-02-18 22:30:39 +00:00
|
|
|
struct lws_context_creation_info info;
|
2019-03-26 22:04:53 +00:00
|
|
|
struct lws_protocols protocols[WFP_CLIENT_PROTOCOL_COUNT];
|
2019-02-18 22:30:39 +00:00
|
|
|
struct lws_context * context;
|
2019-03-04 20:17:37 +00:00
|
|
|
char * key_path;
|
|
|
|
char * cert_path;
|
2019-02-17 13:31:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
struct wfp_client * wfp_impl_client_create(
|
|
|
|
struct wfp_client_config * config)
|
2019-02-17 13:31:04 +00:00
|
|
|
{
|
2019-05-19 12:33:42 +00:00
|
|
|
wf_lwslog_disable();
|
2019-02-18 22:30:39 +00:00
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
struct wfp_client * client = malloc(sizeof(struct wfp_client));
|
2019-02-17 13:31:04 +00:00
|
|
|
if (NULL != client)
|
|
|
|
{
|
2019-03-26 22:04:53 +00:00
|
|
|
wfp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data);
|
2019-02-18 22:30:39 +00:00
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
memset(client->protocols, 0, sizeof(struct lws_protocols) * WFP_CLIENT_PROTOCOL_COUNT);
|
|
|
|
wfp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]);
|
2019-02-18 22:30:39 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2019-03-04 20:17:37 +00:00
|
|
|
if ((NULL != config->cert_path) && (NULL != config->key_path))
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-02-18 22:30:39 +00:00
|
|
|
client->context = lws_create_context(&client->info);
|
2019-02-17 13:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
void wfp_impl_client_dispose(
|
|
|
|
struct wfp_client * client)
|
2019-02-17 13:31:04 +00:00
|
|
|
{
|
2019-02-18 22:30:39 +00:00
|
|
|
lws_context_destroy(client->context);
|
2019-03-26 22:04:53 +00:00
|
|
|
wfp_impl_client_protocol_cleanup(&client->protocol);
|
2019-02-17 13:31:04 +00:00
|
|
|
free(client);
|
|
|
|
}
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
void wfp_impl_client_connect(
|
|
|
|
struct wfp_client * client,
|
2019-02-17 13:31:04 +00:00
|
|
|
char const * url)
|
|
|
|
{
|
2020-02-19 21:44:56 +00:00
|
|
|
wfp_impl_client_protocol_connect(&client->protocol, client->context, url);
|
2019-02-17 13:31:04 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
void wfp_impl_client_disconnect(
|
|
|
|
struct wfp_client * client)
|
2019-02-17 13:31:04 +00:00
|
|
|
{
|
|
|
|
(void) client;
|
|
|
|
|
|
|
|
// ToDo: implement me
|
|
|
|
}
|
|
|
|
|
2019-05-19 12:33:42 +00:00
|
|
|
bool wfp_impl_client_is_connected(
|
|
|
|
struct wfp_client * client)
|
|
|
|
{
|
|
|
|
return client->protocol.is_connected;
|
|
|
|
}
|
|
|
|
|
2019-04-26 18:51:24 +00:00
|
|
|
void wfp_impl_client_service(
|
|
|
|
struct wfp_client * client,
|
|
|
|
int timeout_ms)
|
2019-02-17 13:31:04 +00:00
|
|
|
{
|
2019-04-26 18:51:24 +00:00
|
|
|
lws_service(client->context, timeout_ms);
|
2019-02-17 13:31:04 +00:00
|
|
|
}
|
|
|
|
|