parent
dcbe4f075a
commit
06a24e09da
@ -0,0 +1,32 @@
|
||||
#ifndef WF_ADAPTER_CLIENT_TLSCONFIG_H
|
||||
#define WF_ADAPTER_CLIENT_TLSCONFIG_H
|
||||
|
||||
#include <webfuse/adapter/api.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_client_tlsconfig;
|
||||
|
||||
extern WF_API void
|
||||
wf_client_tlsconfig_set_keypath(
|
||||
struct wf_client_tlsconfig * config,
|
||||
char const * key_path);
|
||||
|
||||
extern WF_API void
|
||||
wf_client_tlsconfig_set_certpath(
|
||||
struct wf_client_tlsconfig * config,
|
||||
char const * cert_path);
|
||||
|
||||
extern WF_API void
|
||||
wf_client_tlsconfig_set_cafilepath(
|
||||
struct wf_client_tlsconfig * config,
|
||||
char const * cafile_path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,55 @@
|
||||
#include "webfuse/adapter/impl/client_protocol.h"
|
||||
#include "webfuse/adapter/client_callback.h"
|
||||
#include "webfuse/core/protocol_names.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <libwebsockets.h>
|
||||
|
||||
static int wf_impl_client_protocol_lws_callback(
|
||||
struct lws * WF_UNUSED_PARAM(wsi),
|
||||
enum lws_callback_reasons WF_UNUSED_PARAM(reason),
|
||||
void * WF_UNUSED_PARAM(user),
|
||||
void * WF_UNUSED_PARAM(in),
|
||||
size_t WF_UNUSED_PARAM(len))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_protocol_init(
|
||||
struct wf_client_protocol * protocol,
|
||||
wf_client_callback_fn * callback,
|
||||
void * user_data)
|
||||
{
|
||||
protocol->callback = callback;
|
||||
protocol->user_data = user_data;
|
||||
protocol->callback(protocol->user_data, WF_CLIENT_INIT, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_protocol_cleanup(
|
||||
struct wf_client_protocol * protocol)
|
||||
{
|
||||
protocol->callback(protocol->user_data, WF_CLIENT_CLEANUP, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_protocol_callback(
|
||||
struct wf_client_protocol * protocol,
|
||||
int reason,
|
||||
void * arg)
|
||||
{
|
||||
protocol->callback(protocol->user_data, reason, arg);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_protocol_init_lws(
|
||||
struct wf_client_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol)
|
||||
{
|
||||
lws_protocol->name = WF_PROTOCOL_NAME_ADAPTER_CLIENT;
|
||||
lws_protocol->callback = &wf_impl_client_protocol_lws_callback;
|
||||
lws_protocol->per_session_data_size = 0;
|
||||
lws_protocol->user = protocol;
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
#ifndef WF_ADAPTER_IMPL_CLIENT_PROTOCOL_H
|
||||
#define WF_ADAPTER_IMPL_CLIENT_PROTOCOL_H
|
||||
|
||||
#include "webfuse/adapter/client_callback.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct lws_protocols;
|
||||
|
||||
typedef void
|
||||
wf_client_protocol_callback_fn(
|
||||
void * user_data,
|
||||
int reason,
|
||||
void * arg);
|
||||
|
||||
struct wf_client_protocol
|
||||
{
|
||||
wf_client_callback_fn * callback;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
extern void
|
||||
wf_impl_client_protocol_init(
|
||||
struct wf_client_protocol * protocol,
|
||||
wf_client_callback_fn * callback,
|
||||
void * user_data);
|
||||
|
||||
extern void
|
||||
wf_impl_client_protocol_cleanup(
|
||||
struct wf_client_protocol * protocol);
|
||||
|
||||
extern void
|
||||
wf_impl_client_protocol_callback(
|
||||
struct wf_client_protocol * protocol,
|
||||
int reason,
|
||||
void * arg);
|
||||
|
||||
extern void
|
||||
wf_impl_client_protocol_init_lws(
|
||||
struct wf_client_protocol * protocol,
|
||||
struct lws_protocols * lws_protocol);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,55 @@
|
||||
#include "webfuse/adapter/impl/client_tlsconfig.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
wf_impl_client_tlsconfig_init(
|
||||
struct wf_client_tlsconfig * config)
|
||||
{
|
||||
config->key_path = NULL;
|
||||
config->cert_path = NULL;
|
||||
config->cafile_path = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_tlsconfig_cleanup(
|
||||
struct wf_client_tlsconfig * config)
|
||||
{
|
||||
free(config->key_path);
|
||||
free(config->cert_path);
|
||||
free(config->cafile_path);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_tlsconfig_set_keypath(
|
||||
struct wf_client_tlsconfig * config,
|
||||
char const * key_path)
|
||||
{
|
||||
free(config->key_path);
|
||||
config->key_path = strdup(key_path);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_tlsconfig_set_certpath(
|
||||
struct wf_client_tlsconfig * config,
|
||||
char const * cert_path)
|
||||
{
|
||||
free(config->cert_path);
|
||||
config->cert_path = strdup(cert_path);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_client_tlsconfig_set_cafilepath(
|
||||
struct wf_client_tlsconfig * config,
|
||||
char const * cafile_path)
|
||||
{
|
||||
free(config->cafile_path);
|
||||
config->cafile_path = strdup(cafile_path);
|
||||
}
|
||||
|
||||
bool
|
||||
wf_impl_client_tlsconfig_isset(
|
||||
struct wf_client_tlsconfig const * config)
|
||||
{
|
||||
return (NULL != config->cert_path) && (NULL != config->key_path);
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
#ifndef WF_ADAPTER_IMPL_CLIENT_TLSCONFIG_H
|
||||
#define WF_ADAPTER_IMPL_CLIENT_TLSCONFIG_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_client_tlsconfig
|
||||
{
|
||||
char * key_path;
|
||||
char * cert_path;
|
||||
char * cafile_path;
|
||||
};
|
||||
|
||||
extern void
|
||||
wf_impl_client_tlsconfig_init(
|
||||
struct wf_client_tlsconfig * config);
|
||||
|
||||
extern void
|
||||
wf_impl_client_tlsconfig_cleanup(
|
||||
struct wf_client_tlsconfig * config);
|
||||
|
||||
extern void
|
||||
wf_impl_client_tlsconfig_set_keypath(
|
||||
struct wf_client_tlsconfig * config,
|
||||
char const * key_path);
|
||||
|
||||
extern void
|
||||
wf_impl_client_tlsconfig_set_certpath(
|
||||
struct wf_client_tlsconfig * config,
|
||||
char const * cert_path);
|
||||
|
||||
extern void
|
||||
wf_impl_client_tlsconfig_set_cafilepath(
|
||||
struct wf_client_tlsconfig * config,
|
||||
char const * cafile_path);
|
||||
|
||||
extern bool
|
||||
wf_impl_client_tlsconfig_isset(
|
||||
struct wf_client_tlsconfig const * config);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,69 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse/adapter/client_tlsconfig.h"
|
||||
#include "webfuse/adapter/impl/client_tlsconfig.h"
|
||||
|
||||
TEST(ClientTlsConfig, InitAndCleanup)
|
||||
{
|
||||
wf_client_tlsconfig config;
|
||||
|
||||
wf_impl_client_tlsconfig_init(&config);
|
||||
wf_impl_client_tlsconfig_cleanup(&config);
|
||||
}
|
||||
|
||||
TEST(ClientTlsConfig, SetKeyPath)
|
||||
{
|
||||
wf_client_tlsconfig config;
|
||||
wf_impl_client_tlsconfig_init(&config);
|
||||
|
||||
wf_client_tlsconfig_set_keypath(&config, "/path/to/key.pem");
|
||||
ASSERT_STREQ("/path/to/key.pem", config.key_path);
|
||||
|
||||
wf_impl_client_tlsconfig_cleanup(&config);
|
||||
}
|
||||
|
||||
TEST(ClientTlsConfig, SetCertPath)
|
||||
{
|
||||
wf_client_tlsconfig config;
|
||||
wf_impl_client_tlsconfig_init(&config);
|
||||
|
||||
wf_client_tlsconfig_set_certpath(&config, "/path/to/cert.pem");
|
||||
ASSERT_STREQ("/path/to/cert.pem", config.cert_path);
|
||||
|
||||
wf_impl_client_tlsconfig_cleanup(&config);
|
||||
}
|
||||
|
||||
TEST(ClientTlsConfig, SetCafilePath)
|
||||
{
|
||||
wf_client_tlsconfig config;
|
||||
wf_impl_client_tlsconfig_init(&config);
|
||||
|
||||
wf_client_tlsconfig_set_cafilepath(&config, "/path/to/cafile.pem");
|
||||
ASSERT_STREQ("/path/to/cafile.pem", config.cafile_path);
|
||||
|
||||
wf_impl_client_tlsconfig_cleanup(&config);
|
||||
}
|
||||
|
||||
TEST(ClientTslConfig, IsSet)
|
||||
{
|
||||
wf_client_tlsconfig config;
|
||||
|
||||
wf_impl_client_tlsconfig_init(&config);
|
||||
ASSERT_FALSE(wf_impl_client_tlsconfig_isset(&config));
|
||||
wf_impl_client_tlsconfig_cleanup(&config);
|
||||
|
||||
wf_impl_client_tlsconfig_init(&config);
|
||||
wf_client_tlsconfig_set_keypath(&config, "/path/to/key.pem");
|
||||
ASSERT_FALSE(wf_impl_client_tlsconfig_isset(&config));
|
||||
wf_impl_client_tlsconfig_cleanup(&config);
|
||||
|
||||
wf_impl_client_tlsconfig_init(&config);
|
||||
wf_client_tlsconfig_set_certpath(&config, "/path/to/cert.pem");
|
||||
ASSERT_FALSE(wf_impl_client_tlsconfig_isset(&config));
|
||||
wf_impl_client_tlsconfig_cleanup(&config);
|
||||
|
||||
wf_impl_client_tlsconfig_init(&config);
|
||||
wf_client_tlsconfig_set_keypath(&config, "/path/to/key.pem");
|
||||
wf_client_tlsconfig_set_certpath(&config, "/path/to/cert.pem");
|
||||
ASSERT_TRUE(wf_impl_client_tlsconfig_isset(&config));
|
||||
wf_impl_client_tlsconfig_cleanup(&config);
|
||||
}
|
Loading…
Reference in new issue