From 431e3c027bd173b06693ba04598bae0d76a663c6 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 6 Apr 2020 21:44:24 +0200 Subject: [PATCH 1/5] removed dead code --- lib/webfuse/adapter/impl/filesystem.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/webfuse/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c index 0c321e9..a033190 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -130,9 +130,4 @@ void wf_impl_filesystem_process_request( { fuse_session_process_buf(filesystem->session, &filesystem->buffer); } - else if (-EINTR != result) - { - // ToDo - } - } From 8539ce9338193075b9f7d33a4f3a0a964ab6e959 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Tue, 7 Apr 2020 19:34:19 +0200 Subject: [PATCH 2/5] clone mountpoint factory --- lib/webfuse/adapter/impl/mountpoint_factory.c | 5 +---- lib/webfuse/adapter/impl/mountpoint_factory.h | 2 +- lib/webfuse/adapter/impl/server_config.c | 4 +--- lib/webfuse/adapter/impl/server_protocol.c | 2 +- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/webfuse/adapter/impl/mountpoint_factory.c b/lib/webfuse/adapter/impl/mountpoint_factory.c index 2da5db3..3062888 100644 --- a/lib/webfuse/adapter/impl/mountpoint_factory.c +++ b/lib/webfuse/adapter/impl/mountpoint_factory.c @@ -20,15 +20,12 @@ wf_impl_mountpoint_factory_init( } void -wf_impl_mountpoint_factory_move( +wf_impl_mountpoint_factory_clone( struct wf_impl_mountpoint_factory * factory, struct wf_impl_mountpoint_factory * other) { other->create_mountpoint = factory->create_mountpoint; other->user_data = factory->user_data; - - factory->create_mountpoint = NULL; - factory->user_data = NULL; } bool diff --git a/lib/webfuse/adapter/impl/mountpoint_factory.h b/lib/webfuse/adapter/impl/mountpoint_factory.h index 63bbbfc..8675879 100644 --- a/lib/webfuse/adapter/impl/mountpoint_factory.h +++ b/lib/webfuse/adapter/impl/mountpoint_factory.h @@ -26,7 +26,7 @@ wf_impl_mountpoint_factory_init( void * user_data); extern void -wf_impl_mountpoint_factory_move( +wf_impl_mountpoint_factory_clone( struct wf_impl_mountpoint_factory * factory, struct wf_impl_mountpoint_factory * other); diff --git a/lib/webfuse/adapter/impl/server_config.c b/lib/webfuse/adapter/impl/server_config.c index ab214f3..4233094 100644 --- a/lib/webfuse/adapter/impl/server_config.c +++ b/lib/webfuse/adapter/impl/server_config.c @@ -48,9 +48,7 @@ void wf_impl_server_config_clone( clone->port = config->port; wf_impl_authenticators_clone(&config->authenticators, &clone->authenticators); - - // ToDo: remove this: move is not clone :-/ - wf_impl_mountpoint_factory_move(&config->mountpoint_factory, &clone->mountpoint_factory); + wf_impl_mountpoint_factory_clone(&config->mountpoint_factory, &clone->mountpoint_factory); } struct wf_server_config * wf_impl_server_config_create(void) diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index d97c9a8..1996c67 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -216,7 +216,7 @@ void wf_impl_server_protocol_init( { protocol->is_operational = false; - wf_impl_mountpoint_factory_move(mountpoint_factory, &protocol->mountpoint_factory); + wf_impl_mountpoint_factory_clone(mountpoint_factory, &protocol->mountpoint_factory); protocol->timer_manager = wf_timer_manager_create(); wf_impl_session_manager_init(&protocol->session_manager); From 36f2b82a67642d2ecf074129d819029b26455c8e Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Tue, 7 Apr 2020 19:43:10 +0200 Subject: [PATCH 3/5] fix: added missing call of mock object --- test/webfuse/tests/core/jsonrpc/test_proxy.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/test/webfuse/tests/core/jsonrpc/test_proxy.cc b/test/webfuse/tests/core/jsonrpc/test_proxy.cc index bdc8a15..e594e89 100644 --- a/test/webfuse/tests/core/jsonrpc/test_proxy.cc +++ b/test/webfuse/tests/core/jsonrpc/test_proxy.cc @@ -396,6 +396,7 @@ TEST(wf_jsonrpc_proxy, swallow_timeout_if_no_request_pending) EXPECT_CALL(timer_api, wf_timer_create(_, _, _)) .Times(1) .WillOnce(DoAll(SaveArg<1>(&on_timer), SaveArg<2>(&timer_context), Return(nullptr))); + EXPECT_CALL(timer_api, wf_timer_dispose(_)).Times(1); SendContext send_context; void * send_data = reinterpret_cast(&send_context); From 3eb5dc89a79d219d70edaaf6c3f046ecf672778a Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Tue, 7 Apr 2020 20:37:50 +0200 Subject: [PATCH 4/5] added implementation of wfp_client_disconnect --- include/webfuse/provider/client_protocol.h | 15 ++++++++++++++- lib/webfuse/provider/api.c | 6 ++++++ lib/webfuse/provider/impl/client.c | 4 +--- lib/webfuse/provider/impl/client_protocol.c | 14 ++++++++++++++ lib/webfuse/provider/impl/client_protocol.h | 3 +++ test/webfuse/tests/integration/provider.cc | 6 ++++++ .../tests/provider/test_client_protocol.cc | 18 +++++++++++++++++- 7 files changed, 61 insertions(+), 5 deletions(-) diff --git a/include/webfuse/provider/client_protocol.h b/include/webfuse/provider/client_protocol.h index ab1ba85..8108030 100644 --- a/include/webfuse/provider/client_protocol.h +++ b/include/webfuse/provider/client_protocol.h @@ -89,12 +89,25 @@ extern WFP_API void wfp_client_protocol_init_lws( /// \see wfp_connected_fn /// \see wfp_client_config_set_onconnected //------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ extern WFP_API void wfp_client_protocol_connect( struct wfp_client_protocol * protocol, struct lws_context * context, char const * url); +//------------------------------------------------------------------------------ +/// \brief Disconnects the protocol from a remote webfuse adapter server. +/// +/// \note This call starts to disconnect. A callback is invoked, +/// when the connection is estanlished. +/// +/// \param protocol pointer to protocol +/// +/// \see wfp_connected_fn +/// \see wfp_client_config_set_ondisconnected +//------------------------------------------------------------------------------ +extern WFP_API void wfp_client_protocol_disconnect( + struct wfp_client_protocol * protocol); + #ifdef __cplusplus } #endif diff --git a/lib/webfuse/provider/api.c b/lib/webfuse/provider/api.c index 0c5f164..0c916d2 100644 --- a/lib/webfuse/provider/api.c +++ b/lib/webfuse/provider/api.c @@ -202,6 +202,12 @@ void wfp_client_protocol_connect( wfp_impl_client_protocol_connect(protocol, context, url); } +void wfp_client_protocol_disconnect( + struct wfp_client_protocol * protocol) +{ + wfp_impl_client_protocol_disconnect(protocol); +} + // client diff --git a/lib/webfuse/provider/impl/client.c b/lib/webfuse/provider/impl/client.c index 9f45a5a..e7c6e81 100644 --- a/lib/webfuse/provider/impl/client.c +++ b/lib/webfuse/provider/impl/client.c @@ -79,9 +79,7 @@ void wfp_impl_client_connect( void wfp_impl_client_disconnect( struct wfp_client * client) { - (void) client; - - // ToDo: implement me + wfp_impl_client_protocol_disconnect(&client->protocol); } bool wfp_impl_client_is_connected( diff --git a/lib/webfuse/provider/impl/client_protocol.c b/lib/webfuse/provider/impl/client_protocol.c index a85514a..db78137 100644 --- a/lib/webfuse/provider/impl/client_protocol.c +++ b/lib/webfuse/provider/impl/client_protocol.c @@ -324,3 +324,17 @@ void wfp_impl_client_protocol_connect( } } + +void wfp_impl_client_protocol_disconnect( + struct wfp_client_protocol * protocol) +{ + if (protocol->is_connected) + { + protocol->is_shutdown_requested = true; + lws_callback_on_writable(protocol->wsi); + } + else + { + protocol->provider.disconnected(protocol->user_data); + } +} diff --git a/lib/webfuse/provider/impl/client_protocol.h b/lib/webfuse/provider/impl/client_protocol.h index af5c74b..d6dd8ab 100644 --- a/lib/webfuse/provider/impl/client_protocol.h +++ b/lib/webfuse/provider/impl/client_protocol.h @@ -53,6 +53,9 @@ extern void wfp_impl_client_protocol_connect( struct lws_context * context, char const * url); +extern void wfp_impl_client_protocol_disconnect( + struct wfp_client_protocol * protocol); + #ifdef __cplusplus } #endif diff --git a/test/webfuse/tests/integration/provider.cc b/test/webfuse/tests/integration/provider.cc index ada19b8..e813b4d 100644 --- a/test/webfuse/tests/integration/provider.cc +++ b/test/webfuse/tests/integration/provider.cc @@ -67,6 +67,12 @@ private: { wfp_client_service(context->client); } + + wfp_client_disconnect(context->client); + while (wfp_impl_client_is_connected(context->client)) + { + wfp_client_service(context->client); + } } std::mutex shutdown_lock; diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index 3563949..2035b0f 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -52,6 +52,11 @@ public: server->waitForConnection(); } + void Disconnect() + { + wfp_client_protocol_disconnect(protocol); + } + void SendToClient(json_t * request) { server->sendMessage(request); @@ -166,6 +171,16 @@ TEST(client_protocol, connect) if (HasFatalFailure()) { return; } } +TEST(client_protocol, disconnect_without_connect) +{ + MockProviderClient provider; + ClientProtocolFixture fixture(provider); + + EXPECT_CALL(provider, OnDisconnected()).Times(1); + + fixture.Disconnect(); +} + TEST(client_protocol, connect_with_username_authentication) { MockProviderClient provider; @@ -184,7 +199,6 @@ TEST(client_protocol, connect_with_username_authentication) std::string filesystem; fixture.AwaitAddFilesystem(filesystem); if (HasFatalFailure()) { return; } - } TEST(client_protocol, getattr) @@ -216,4 +230,6 @@ TEST(client_protocol, getattr) ASSERT_TRUE(json_is_object(response)); json_decref(response); + + fixture.Disconnect(); } \ No newline at end of file From 69af19193aae8959a970804bc3e30ea89d147bd3 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Tue, 7 Apr 2020 20:52:50 +0200 Subject: [PATCH 5/5] removed wfp_client_ontimer (breaking change) --- include/webfuse/provider/client_config.h | 20 -------------------- lib/webfuse/provider/api.c | 7 ------- lib/webfuse/provider/impl/client_config.c | 7 ------- lib/webfuse/provider/impl/client_config.h | 4 ---- lib/webfuse/provider/impl/provider.c | 10 ---------- lib/webfuse/provider/impl/provider.h | 4 ---- test/webfuse/mocks/mock_provider.cc | 8 -------- test/webfuse/mocks/mock_provider_client.cc | 8 -------- test/webfuse/mocks/mock_provider_client.hpp | 2 -- 9 files changed, 70 deletions(-) diff --git a/include/webfuse/provider/client_config.h b/include/webfuse/provider/client_config.h index fe138f6..26654bc 100644 --- a/include/webfuse/provider/client_config.h +++ b/include/webfuse/provider/client_config.h @@ -45,14 +45,6 @@ typedef void wfp_connected_fn( typedef void wfp_disconnected_fn( void * user_data); -//------------------------------------------------------------------------------ -/// \brief Callback to signal when a timer event occued. -/// -/// \param user_data user defined context -//------------------------------------------------------------------------------ -typedef void wfp_ontimer_fn( - void * user_data); - //------------------------------------------------------------------------------ /// \brief Creates a new client configuration. /// @@ -145,18 +137,6 @@ extern WFP_API void wfp_client_config_set_ondisconnected( struct wfp_client_config * config, wfp_disconnected_fn * handler); -//------------------------------------------------------------------------------ -/// \brief Sets ontimer handler. -/// -/// The handler is invoked, when a timer event occured. -/// -/// \param config pointer to client configuration -/// \param handler pointer to handler -//------------------------------------------------------------------------------ -extern WFP_API void wfp_client_config_set_ontimer( - struct wfp_client_config * config, - wfp_ontimer_fn * handler); - //------------------------------------------------------------------------------ /// \brief Sets onlookup handler. /// diff --git a/lib/webfuse/provider/api.c b/lib/webfuse/provider/api.c index 0c916d2..ad288bd 100644 --- a/lib/webfuse/provider/api.c +++ b/lib/webfuse/provider/api.c @@ -116,13 +116,6 @@ void wfp_client_config_set_ondisconnected( wfp_impl_client_config_set_ondisconnected(config, handler); } -void wfp_client_config_set_ontimer( - struct wfp_client_config * config, - wfp_ontimer_fn * handler) -{ - wfp_impl_client_config_set_ontimer(config, handler); -} - void wfp_client_config_set_onlookup( struct wfp_client_config * config, wfp_lookup_fn * handler) diff --git a/lib/webfuse/provider/impl/client_config.c b/lib/webfuse/provider/impl/client_config.c index 9e6489b..cd7b015 100644 --- a/lib/webfuse/provider/impl/client_config.c +++ b/lib/webfuse/provider/impl/client_config.c @@ -69,13 +69,6 @@ void wfp_impl_client_config_set_ondisconnected( config->provider.disconnected = handler; } -void wfp_impl_client_config_set_ontimer( - struct wfp_client_config * config, - wfp_ontimer_fn * handler) -{ - config->provider.ontimer = handler; -} - void wfp_impl_client_config_set_onlookup( struct wfp_client_config * config, wfp_lookup_fn * handler) diff --git a/lib/webfuse/provider/impl/client_config.h b/lib/webfuse/provider/impl/client_config.h index a15ff87..9e588b0 100644 --- a/lib/webfuse/provider/impl/client_config.h +++ b/lib/webfuse/provider/impl/client_config.h @@ -47,10 +47,6 @@ extern void wfp_impl_client_config_set_ondisconnected( struct wfp_client_config * config, wfp_disconnected_fn * handler); -extern void wfp_impl_client_config_set_ontimer( - struct wfp_client_config * config, - wfp_ontimer_fn * handler); - extern void wfp_impl_client_config_set_onlookup( struct wfp_client_config * config, wfp_lookup_fn * handler); diff --git a/lib/webfuse/provider/impl/provider.c b/lib/webfuse/provider/impl/provider.c index c9c159f..397a563 100644 --- a/lib/webfuse/provider/impl/provider.c +++ b/lib/webfuse/provider/impl/provider.c @@ -66,7 +66,6 @@ void wfp_impl_provider_init( provider->read = &wfp_impl_read_default; provider->connected = &wfp_impl_connected_default; provider->disconnected = &wfp_impl_disconnected_default; - provider->ontimer = &wfp_impl_ontimer_default; provider->get_credentials = NULL; } @@ -82,7 +81,6 @@ void wfp_impl_provider_init_from_prototype( provider->read = prototype->read; provider->connected = prototype->connected; provider->disconnected = prototype->disconnected; - provider->ontimer = prototype->ontimer; provider->get_credentials = prototype->get_credentials; } @@ -119,14 +117,6 @@ void wfp_impl_disconnected_default( // empty } -void wfp_impl_ontimer_default( - void * user_data) -{ - (void) user_data; - - // empty -} - bool wfp_impl_provider_is_authentication_enabled( struct wfp_provider * provider) { diff --git a/lib/webfuse/provider/impl/provider.h b/lib/webfuse/provider/impl/provider.h index 1e8ec1f..aff4420 100644 --- a/lib/webfuse/provider/impl/provider.h +++ b/lib/webfuse/provider/impl/provider.h @@ -18,7 +18,6 @@ struct wfp_provider { wfp_connected_fn * connected; wfp_disconnected_fn * disconnected; - wfp_ontimer_fn * ontimer; wfp_lookup_fn * lookup; wfp_getattr_fn * getattr; wfp_readdir_fn * readdir; @@ -56,9 +55,6 @@ extern void wfp_impl_connected_default( extern void wfp_impl_disconnected_default( void * user_data); -extern void wfp_impl_ontimer_default( - void * user_data); - #ifdef __cplusplus } #endif diff --git a/test/webfuse/mocks/mock_provider.cc b/test/webfuse/mocks/mock_provider.cc index a81b302..1aab4cf 100644 --- a/test/webfuse/mocks/mock_provider.cc +++ b/test/webfuse/mocks/mock_provider.cc @@ -18,13 +18,6 @@ static void webfuse_test_MockProvider_disconnected( provider->disconnected(); } -static void webfuse_test_MockProvider_on_timer( - void * user_data) -{ - auto * provider = reinterpret_cast(user_data); - provider->on_timer(); -} - static void webfuse_test_MockProvider_lookup( wfp_request * request, ino_t parent, @@ -100,7 +93,6 @@ static wfp_provider const webfuse_test_MockProvider = { &webfuse_test_MockProvider_connected, &webfuse_test_MockProvider_disconnected, - &webfuse_test_MockProvider_on_timer, &webfuse_test_MockProvider_lookup, &webfuse_test_MockProvider_getattr, &webfuse_test_MockProvider_readdir, diff --git a/test/webfuse/mocks/mock_provider_client.cc b/test/webfuse/mocks/mock_provider_client.cc index ff73bd9..779c0ef 100644 --- a/test/webfuse/mocks/mock_provider_client.cc +++ b/test/webfuse/mocks/mock_provider_client.cc @@ -21,13 +21,6 @@ static void webfuse_test_iproviderclient_ondisconnected( self->OnDisconnected(); } -static void webfuse_test_iproviderclient_ontimer( - void * user_data) -{ - auto * self = reinterpret_cast(user_data); - self->OnTimer(); -} - static void webfuse_test_iproviderclient_onlookup( struct wfp_request * request, ino_t parent, @@ -207,7 +200,6 @@ void IProviderClient::AttachTo(wfp_client_config * config, bool enableAuthentica wfp_client_config_set_userdata(config, self); wfp_client_config_set_onconnected(config, &webfuse_test_iproviderclient_onconnected); wfp_client_config_set_ondisconnected(config, &webfuse_test_iproviderclient_ondisconnected); - wfp_client_config_set_ontimer(config, &webfuse_test_iproviderclient_ontimer); wfp_client_config_set_onlookup(config, &webfuse_test_iproviderclient_onlookup); wfp_client_config_set_ongetattr(config, &webfuse_test_iproviderclient_ongetattr); diff --git a/test/webfuse/mocks/mock_provider_client.hpp b/test/webfuse/mocks/mock_provider_client.hpp index 57db042..b60e743 100644 --- a/test/webfuse/mocks/mock_provider_client.hpp +++ b/test/webfuse/mocks/mock_provider_client.hpp @@ -23,7 +23,6 @@ namespace webfuse_test virtual ~IProviderClient() = default; virtual void OnConnected() = 0; virtual void OnDisconnected() = 0; - virtual void OnTimer() = 0; virtual void Lookup(ino_t parent, char const * name, struct stat * result) = 0; virtual void GetAttr(ino_t inode, struct stat * buffer) = 0; virtual void ReadDir(ino_t directory, wfp_dirbuffer * buffer) = 0; @@ -41,7 +40,6 @@ namespace webfuse_test ~MockProviderClient() override = default; MOCK_METHOD0( OnConnected, void()); MOCK_METHOD0( OnDisconnected, void()); - MOCK_METHOD0( OnTimer, void()); MOCK_METHOD3( Lookup, void(ino_t parent, char const * name, struct stat * result)); MOCK_METHOD2( GetAttr, void(ino_t inode, struct stat * buffer)); MOCK_METHOD2( ReadDir, void(ino_t directory, wfp_dirbuffer * buffer));