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

pull/34/head
Falk Werner 5 years ago
parent f5be771a2d
commit 315bd27dbd

@ -76,6 +76,7 @@ add_library(webfuse-core STATIC
lib/webfuse/core/status.c
lib/webfuse/core/string.c
lib/webfuse/core/path.c
lib/webfuse/core/lws_log.c
)
set_target_properties(webfuse-core PROPERTIES OUTPUT_NAME webfuse-core)

@ -10,8 +10,8 @@
#include "webfuse/adapter/impl/server_config.h"
#include "webfuse/adapter/impl/server_protocol.h"
#include "webfuse/core/lws_log.h"
#define WF_DISABLE_LWS_LOG 0
#define WF_SERVER_PROTOCOL_COUNT 3
struct wf_server
@ -33,7 +33,7 @@ static bool wf_impl_server_tls_enabled(
static struct lws_context * wf_impl_server_context_create(
struct wf_server * server)
{
lws_set_log_level(WF_DISABLE_LWS_LOG, NULL);
wf_lwslog_disable();
memset(server->ws_protocols, 0, sizeof(struct lws_protocols) * WF_SERVER_PROTOCOL_COUNT);
server->ws_protocols[0].name = "http";
@ -125,6 +125,12 @@ void wf_impl_server_dispose(
free(server);
}
bool wf_impl_server_is_operational(
struct wf_server * server)
{
return server->protocol.is_operational;
}
void wf_impl_server_service(
struct wf_server * server,
int timeout_ms)

@ -1,6 +1,10 @@
#ifndef WF_ADAPTER_IMPL_SERVER_H
#define WF_ADAPTER_IMPL_SERVER_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#ifdef __cplusplus
extern "C"
{
@ -15,6 +19,9 @@ extern struct wf_server * wf_impl_server_create(
extern void wf_impl_server_dispose(
struct wf_server * server);
extern bool wf_impl_server_is_operational(
struct wf_server * server);
extern void wf_impl_server_service(
struct wf_server * server,
int timeout_ms);

@ -30,6 +30,9 @@ static int wf_impl_server_protocol_callback(
switch (reason)
{
case LWS_CALLBACK_PROTOCOL_INIT:
protocol->is_operational = true;
break;
case LWS_CALLBACK_ESTABLISHED:
session = wf_impl_session_manager_add(
&protocol->session_manager,
@ -206,6 +209,7 @@ void wf_impl_server_protocol_init(
char * mount_point)
{
protocol->mount_point = strdup(mount_point);
protocol->is_operational = false;
wf_impl_timeout_manager_init(&protocol->timeout_manager);
wf_impl_session_manager_init(&protocol->session_manager);
@ -220,6 +224,8 @@ void wf_impl_server_protocol_cleanup(
struct wf_server_protocol * protocol)
{
free(protocol->mount_point);
protocol->is_operational = false;
wf_impl_jsonrpc_server_cleanup(&protocol->server);
wf_impl_timeout_manager_cleanup(&protocol->timeout_manager);
wf_impl_authenticators_cleanup(&protocol->authenticators);

@ -7,6 +7,10 @@
#include "webfuse/adapter/impl/session_manager.h"
#include "webfuse/adapter/impl/jsonrpc/server.h"
#ifndef __cplusplus
#include <stdbool.h>
#endif
#ifdef __cplusplus
extern "C"
{
@ -21,6 +25,7 @@ struct wf_server_protocol
struct wf_impl_authenticators authenticators;
struct wf_impl_session_manager session_manager;
struct wf_impl_jsonrpc_server server;
bool is_operational;
};
extern void wf_impl_server_protocol_init(

@ -0,0 +1,18 @@
#include "webfuse/core/lws_log.h"
#include <stdbool.h>
#include <libwebsockets.h>
#define WF_LWSLOG_DISABLE 0
static bool wf_lwslog_is_diabled = false;
void wf_lwslog_disable(void)
{
if (!wf_lwslog_is_diabled)
{
lws_set_log_level(WF_LWSLOG_DISABLE, NULL);
wf_lwslog_is_diabled = true;
}
}

@ -0,0 +1,15 @@
#ifndef WF_LWS_LOG_H
#define WF_LWS_LOG_H
#ifdef __cplusplus
extern "C"
{
#endif
extern void wf_lwslog_disable(void);
#ifdef __cplusplus
}
#endif
#endif

@ -10,9 +10,9 @@
#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_DISABLE_LWS_LOG 0
#define WFP_CLIENT_PROTOCOL_COUNT 2
struct wfp_client
@ -29,7 +29,7 @@ struct wfp_client
struct wfp_client * wfp_impl_client_create(
struct wfp_client_config * config)
{
lws_set_log_level(WFP_DISABLE_LWS_LOG, NULL);
wf_lwslog_disable();
struct wfp_client * client = malloc(sizeof(struct wfp_client));
if (NULL != client)
@ -99,6 +99,12 @@ void wfp_impl_client_disconnect(
// 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)

@ -1,6 +1,10 @@
#ifndef WF_PROVIDER_IMPL_CLIENT_H
#define WF_PROVIDER_IMPL_CLIENT_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#ifdef __cplusplus
extern "C"
{
@ -27,13 +31,12 @@ extern void wfp_impl_client_connect(
extern void wfp_impl_client_disconnect(
struct wfp_client * client);
extern void wfp_impl_client_settimeout(
struct wfp_client * client,
unsigned int timepoint);
extern void wfp_impl_client_dispose(
struct wfp_client * client);
extern bool wfp_impl_client_is_connected(
struct wfp_client * client);
extern void wfp_impl_client_service(
struct wfp_client * client,
int timeout_ms);

@ -84,13 +84,16 @@ static int wfp_impl_client_protocol_callback(
{
case LWS_CALLBACK_CLIENT_ESTABLISHED:
wfp_impl_client_protocol_add_filesystem(protocol);
protocol->is_connected = true;
protocol->provider.connected(protocol->user_data);
break;
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
protocol->is_connected = false;
protocol->provider.disconnected(protocol->user_data);
break;
case LWS_CALLBACK_CLIENT_CLOSED:
protocol->provider.connected(protocol->user_data);
protocol->is_connected = false;
protocol->provider.disconnected(protocol->user_data);
break;
case LWS_CALLBACK_CLIENT_RECEIVE:
wfp_impl_client_protocol_process_request(protocol, in, len);
@ -126,6 +129,7 @@ void wfp_impl_client_protocol_init(
struct wfp_provider const * provider,
void * user_data)
{
protocol->is_connected = false;
wf_slist_init(&protocol->messages);
protocol->wsi = NULL;

@ -16,6 +16,7 @@ struct lws_protocols;
struct wfp_client_protocol
{
bool is_connected;
struct wfp_request request;
struct wfp_provider provider;
void * user_data;

@ -1,5 +1,6 @@
#include "integration/provider.hpp"
#include "webfuse_provider.h"
#include "webfuse/provider/impl/client.h"
#include <thread>
#include <mutex>
#include <string>
@ -11,40 +12,33 @@ namespace webfuse_test
class Provider::Private
{
public:
Private(char const * url_)
: url(url_)
, is_running(false)
, is_shutdown_requested(false)
Private(char const * url)
: is_shutdown_requested(false)
{
}
~Private()
{
Stop();
}
config = wfp_client_config_create();
void Start()
{
std::lock_guard<std::mutex> lock(run_lock);
fs = wfp_static_filesystem_create(config);
wfp_static_filesystem_add_text(fs, "hello.txt", 0x444, "Hello, World");
if (!is_running)
client = wfp_client_create(config);
wfp_client_connect(client, url);
while (!wfp_impl_client_is_connected(client))
{
thread = std::thread(Run, this);
is_running = true;
msleep(200);
wfp_client_service(client, 100);
}
thread = std::thread(Run, this);
}
void Stop()
~Private()
{
std::lock_guard<std::mutex> lock(run_lock);
RequestShutdown();
thread.join();
if (is_running)
{
RequestShutdown();
thread.join();
is_running = false;
}
wfp_client_dispose(client);
wfp_static_filesystem_dispose(fs);
wfp_client_config_dispose(config);
}
bool IsShutdownRequested()
@ -52,11 +46,6 @@ public:
std::lock_guard<std::mutex> lock(shutdown_lock);
return is_shutdown_requested;
}
char const * GetUrl() const
{
return url.c_str();
}
private:
void RequestShutdown()
{
@ -66,36 +55,20 @@ private:
static void Run(Provider::Private * context)
{
wfp_client_config * config = wfp_client_config_create();
wfp_static_filesystem * fs = wfp_static_filesystem_create(config);
wfp_static_filesystem_add_text(fs, "hello.txt", 0x444, "Hello, World");
wfp_client * client = wfp_client_create(config);
if (nullptr != client)
while (!context->IsShutdownRequested())
{
wfp_client_connect(client, context->GetUrl());
while (!context->IsShutdownRequested())
{
wfp_client_service(client, 100);
}
wfp_client_dispose(client);
wfp_client_service(context->client, 100);
}
wfp_static_filesystem_dispose(fs);
wfp_client_config_dispose(config);
}
std::string url;
bool is_running;
std::mutex run_lock;
bool is_shutdown_requested;
std::mutex shutdown_lock;
std::thread thread;
bool is_shutdown_requested;
wfp_client_config * config;
wfp_static_filesystem * fs;
public:
wfp_client * client;
};
Provider::Provider(char const * url)
@ -108,14 +81,4 @@ Provider::~Provider()
delete d;
}
void Provider::Start(void)
{
d->Start();
}
void Provider::Stop(void)
{
d->Stop();
}
}

@ -9,8 +9,6 @@ class Provider
public:
Provider(char const * url);
~Provider();
void Start(void);
void Stop(void);
private:
class Private;
Private * d;

@ -5,6 +5,7 @@
#include <cstring>
#include <unistd.h>
#include "webfuse_adapter.h"
#include "webfuse/adapter/impl/server.h"
#include "msleep.hpp"
#define WF_PATH_MAX (100)
@ -16,41 +17,33 @@ class Server::Private
{
public:
Private()
: is_running(false)
, is_shutdown_requested(false)
: is_shutdown_requested(false)
{
snprintf(base_dir, WF_PATH_MAX, "%s", "/tmp/webfuse_test_integration_XXXXXX");
mkdtemp(base_dir);
}
~Private()
{
Stop();
rmdir(base_dir);
}
config = wf_server_config_create();
wf_server_config_set_port(config, 8080);
wf_server_config_set_mountpoint(config, base_dir);
void Start()
{
std::lock_guard<std::mutex> lock(run_lock);
server = wf_server_create(config);
if (!is_running)
while (!wf_impl_server_is_operational(server))
{
thread = std::thread(Run, this);
is_running = true;
msleep(200);
wf_server_service(server, 100);
}
thread = std::thread(Run, this);
}
void Stop()
~Private()
{
std::lock_guard<std::mutex> lock(run_lock);
if (is_running)
{
RequestShutdown();
thread.join();
is_running = false;
}
RequestShutdown();
thread.join();
rmdir(base_dir);
wf_server_dispose(server);
wf_server_config_dispose(config);
}
bool IsShutdownRequested()
@ -59,11 +52,6 @@ public:
return is_shutdown_requested;
}
char const * GetBaseDir()
{
return base_dir;
}
private:
void RequestShutdown()
{
@ -73,33 +61,22 @@ private:
static void Run(Server::Private * context)
{
wf_server_config * config = wf_server_config_create();
wf_server_config_set_port(config, 8080);
wf_server_config_set_mountpoint(config, context->GetBaseDir());
wf_server * server = wf_server_create(config);
if (nullptr != server)
while (!context->IsShutdownRequested())
{
while (!context->IsShutdownRequested())
{
wf_server_service(server, 100);
}
wf_server_dispose(server);
wf_server_service(context->server, 100);
}
wf_server_config_dispose(config);
}
char base_dir[WF_PATH_MAX];
bool is_running;
std::mutex run_lock;
bool is_shutdown_requested;
std::mutex shutdown_lock;
std::thread thread;
bool is_shutdown_requested;
public:
char base_dir[WF_PATH_MAX];
wf_server_config * config;
wf_server * server;
};
Server::Server()
@ -113,19 +90,9 @@ Server::~Server()
delete d;
}
void Server::Start(void)
{
d->Start();
}
void Server::Stop(void)
{
d->Stop();
}
char const * Server::GetBaseDir(void) const
{
return d->GetBaseDir();
return d->base_dir;
}

@ -2,12 +2,17 @@
#include "integration/server.hpp"
#include "integration/provider.hpp"
#include <csignal>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <jansson.h>
#include "webfuse/core/lws_log.h"
using webfuse_test::Server;
using webfuse_test::Provider;
@ -17,34 +22,35 @@ namespace
{
public:
IntegrationTest()
: provider("ws://localhost:8080/")
{
json_object_seed(0);
wf_lwslog_disable();
}
protected:
void SetUp()
{
server.Start();
provider.Start();
server = new Server();
provider = new Provider("ws://localhost:8080/");
}
void TearDown()
{
provider.Stop();
server.Stop();
delete provider;
delete server;
}
char const * GetBaseDir() const
{
return server.GetBaseDir();
return server->GetBaseDir();
}
private:
Server server;
Provider provider;
Server * server;
Provider * provider;
};
}
TEST_F(IntegrationTest, DISABLED_HasMountpoint)
TEST_F(IntegrationTest, HasMountpoint)
{
struct stat buffer;
int rc = stat(GetBaseDir(), &buffer);
@ -53,7 +59,7 @@ TEST_F(IntegrationTest, DISABLED_HasMountpoint)
ASSERT_TRUE(S_ISDIR(buffer.st_mode));
}
TEST_F(IntegrationTest, DISABLED_ProvidesTextFile)
TEST_F(IntegrationTest, ProvidesTextFile)
{
std::string file_name = std::string(GetBaseDir()) + "/cprovider/default/hello.txt";

Loading…
Cancel
Save