1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00

removed unused code

This commit is contained in:
Falk Werner 2020-06-28 15:30:33 +02:00
parent 01951c4184
commit 179dcf2be9
63 changed files with 0 additions and 5249 deletions

View File

@ -1,32 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// \file provider/api.h
/// \brief API define for webfuse provider.
////////////////////////////////////////////////////////////////////////////////
#ifndef WFP_PROVIDER_API_H
#define WFP_PROVIDER_API_H
//------------------------------------------------------------------------------
/// \def WFP_API
/// \brief Marks public symbols of libwebfuse_provider.
//------------------------------------------------------------------------------
#ifndef WFP_API
#define WFP_API
#endif
//------------------------------------------------------------------------------
/// \def WFP_EXPORT
/// \brief Marks exported symbols as visible.
///
/// Set WFP_API to WFP_EXPORT when building libwebfuse_provider.so to export
/// public symbols.
//------------------------------------------------------------------------------
#ifndef WFP_EXPORT
#ifdef __GNUC__
#define WFP_EXPORT __attribute__ ((visibility ("default")))
#else
#define WFP_EXPORT
#endif
#endif
#endif

View File

@ -1,105 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// \file provider/client.h
/// \brief Webfuse provider client.
////////////////////////////////////////////////////////////////////////////////
#ifndef WF_PROVIDER_CLIENT_H
#define WF_PROVIDER_CLIENT_H
#include "webfuse/provider/api.h"
#ifdef __cplusplus
extern "C"
{
#endif
//------------------------------------------------------------------------------
/// \struct wfp_client
/// \brief Webfuse provider client.
//------------------------------------------------------------------------------
struct wfp_client;
struct wfp_client_config;
//------------------------------------------------------------------------------
/// \brief Creates a webfuse provider client.
///
/// \note Client configuration is not managed by the client.
///
/// \param config pointer to client configuration.
/// \return newly created client or NULL in case of an error.
//------------------------------------------------------------------------------
extern WFP_API struct wfp_client * wfp_client_create(
struct wfp_client_config * config);
//------------------------------------------------------------------------------
/// \brief Connects the client to a remote webfuse adapter server.
///
/// \note This call starts to establish a connection. A callback is invoked,
/// when the connection is estanlished.
///
/// \param client pointer to client
/// \param url URL of remote webfuse adapter server
///
/// \see wfp_connected_fn
/// \see wfp_client_config_set_onconnected
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_connect(
struct wfp_client * client,
char const * url);
//------------------------------------------------------------------------------
/// \brief Disconnects a connected client.
///
/// \note This call starts to disconnect the connection. A callback is invoked
/// when conntection is disconnected.
///
/// \param client pointer to client
///
/// \see wfp_disconnected_fn
/// \see wfp_client_config_set_ondisconnected
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_disconnect(
struct wfp_client * client);
//------------------------------------------------------------------------------
/// \brief Disposes a client.
///
/// \note Client configuration is not managed by client.
///
/// \param client pointer to client
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_dispose(
struct wfp_client * client);
//------------------------------------------------------------------------------
/// \brief Triggers the client.
///
/// This function must be invoked in a loop while the client is running. It
/// makes the server wait for the next event and processes it.
///
/// \param client pointer to client
///
/// \see wfp_client_interrupt
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_service(
struct wfp_client * client);
//------------------------------------------------------------------------------
/// \brief interrupt wfp_client_service
///
/// This function can be called from another thread.
///
/// \param client pointer to client
///
/// \see wfp_client_service
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_interrupt(
struct wfp_client * client);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,240 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// \file provider/client_config.h
/// \brief Client configuration of webfuse provider.
////////////////////////////////////////////////////////////////////////////////
#ifndef WF_PROVIDER_CLIENT_CONFIG_H
#define WF_PROVIDER_CLIENT_CONFIG_H
#include <webfuse/provider/api.h>
#include <webfuse/provider/operation/lookup.h>
#include <webfuse/provider/operation/getattr.h>
#include <webfuse/provider/operation/readdir.h>
#include <webfuse/provider/operation/open.h>
#include <webfuse/provider/operation/close.h>
#include <webfuse/provider/operation/read.h>
#include <webfuse/provider/credentials.h>
#ifdef __cplusplus
extern "C"
{
#endif
//------------------------------------------------------------------------------
/// \struct wfp_client_config
/// \brief Provider client configuration object.
///
/// Holds configuration of webfuse provider client.
//------------------------------------------------------------------------------
struct wfp_client_config;
//------------------------------------------------------------------------------
/// \brief Callback to signal when the client's connection is established.
///
/// \param user_data user defined context
//------------------------------------------------------------------------------
typedef void wfp_connected_fn(
void * user_data);
//------------------------------------------------------------------------------
/// \brief Callback to signal when a client's connection is disconnected.
///
/// \param user_data user defined context
//------------------------------------------------------------------------------
typedef void wfp_disconnected_fn(
void * user_data);
//------------------------------------------------------------------------------
/// \brief Creates a new client configuration.
///
/// \return newly created client configuration
//------------------------------------------------------------------------------
extern WFP_API struct wfp_client_config * wfp_client_config_create(void);
//------------------------------------------------------------------------------
/// \brief Disposes a client configuration.
///
/// \note The user defined context is not managed by the client configuration.
///
/// \param config pointer to client configuration
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_config_dispose(
struct wfp_client_config * config);
//------------------------------------------------------------------------------
/// \brief Sets a user defined context.
///
/// \note The user is responsible to manage the lifetime of user data.
///
/// \param config pointer to client configuration
/// \param user_data user defined context
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_config_set_userdata(
struct wfp_client_config * config,
void * user_data);
//------------------------------------------------------------------------------
/// \brief Sets the path to clients private key.
///
/// \note To enable TLS both, private key and certificate, must be specified.
/// Otherwise, TLS is not used.
///
/// \param config pointer to client configuration
/// \param key_path path of clients private key (pem file)
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_config_set_keypath(
struct wfp_client_config * config,
char const * key_path);
//------------------------------------------------------------------------------
/// \brief Sets the path of clients certificate.
///
/// \note To enable TLS both, private key and certificate, must be specified.
/// Otherwise, TLS is not used.
///
/// \param config pointer to client configuration
/// \param cert_path path of the clients certificate (pem file)
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_config_set_certpath(
struct wfp_client_config * config,
char const * cert_path);
//------------------------------------------------------------------------------
/// \brief Sets the path of ca file to verify servers.
///
/// \note To enable TLS both, private key and certificate, must be specified.
/// Otherwise, TLS is not used.
///
/// \param config pointer to client configuration
/// \param ca_filepath path of the ca file (pem file)
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_config_set_ca_filepath(
struct wfp_client_config * config,
char const * ca_filepath);
//------------------------------------------------------------------------------
/// \brief Sets the onconnected handler.
///
/// The handler is invoked, when the client's conntection is established.
///
/// \param config pointer to client configuration
/// \param handler pointer to handler
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_config_set_onconnected(
struct wfp_client_config * config,
wfp_connected_fn * handler);
//------------------------------------------------------------------------------
/// \brief Sets ondisconnected handler
///
/// The handler is invoked, when the client's conntection is lost.
///
/// \param config pointer to client configuration
/// \param handler pointer to handler
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_config_set_ondisconnected(
struct wfp_client_config * config,
wfp_disconnected_fn * handler);
//------------------------------------------------------------------------------
/// \brief Sets onlookup handler.
///
/// The handler is invoked, when the identifier of a file is requested.
///
/// \param config pointer to client configuration
/// \param handler pointer to handler
///
/// \see wfp_lookup_fn
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_config_set_onlookup(
struct wfp_client_config * config,
wfp_lookup_fn * handler);
//------------------------------------------------------------------------------
/// \brief Sets ongetattr handler.
///
/// The handler is invoked, when attributes of a file are requested.
///
/// \param config pointer to client configuration
/// \param handler pointer to handler
///
/// \see wfp_getattr_fn
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_config_set_ongetattr(
struct wfp_client_config * config,
wfp_getattr_fn * handler);
//------------------------------------------------------------------------------
/// \brief Sets onreaddir handler.
///
/// The handler is invoked, when the contents of directory are requested-
///
/// \param config pointer to client configuration
/// \param handler pointer to handler
///
/// \see wfp_readdir_fn
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_config_set_onreaddir(
struct wfp_client_config * config,
wfp_readdir_fn * handler);
//------------------------------------------------------------------------------
/// \brief Sets onopen handler.
///
/// The handler is invoked, whe a file should be opened.
///
/// \param config pointer to client configuration
/// \param handler pointer to handler
///
/// \see wfp_open_fn
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_config_set_onopen(
struct wfp_client_config * config,
wfp_open_fn * handler);
//------------------------------------------------------------------------------
/// \brief Sets onclose handler.
///
/// The handler is invoked, when a file is closed.
///
/// \param config pointer to client configuration
/// \param handler pointer to handler
///
/// \see wfp_close_fn
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_config_set_onclose(
struct wfp_client_config * config,
wfp_close_fn * handler);
//------------------------------------------------------------------------------
/// \brief Sets onread handler.
///
/// The handler is invoked, when a files content is requested.
///
/// \param config pointer to client configuration
/// \param handler pointer to handler
///
/// \see wfp_read_fn
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_config_set_onread(
struct wfp_client_config * config,
wfp_read_fn * handler);
//------------------------------------------------------------------------------
/// \brief Enabled authentication.
///
/// \param config pointer to client configuration
/// \param get_credentials pointer to function providing credentials when
// needed.
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_config_enable_authentication(
struct wfp_client_config * config,
wfp_get_credentials_fn * get_credentials);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,117 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// \file provider/client_protocol.h
/// \brief Provides low level access to libwebsockets protocol.
///
/// By default, libwebfuse encapsulates libwebsockets protocol by \ref
/// wfp_client. But sometimes it might come in handy to have access to
/// libwebsockets protocol. This allows to integrate libwebfuse in existing
/// libwebsockets applications.
////////////////////////////////////////////////////////////////////////////////
#ifndef WF_PROVIDER_CLIENT_PROTOCOL_H
#define WF_PROVIDER_CLIENT_PROTOCOL_H
#include "webfuse/provider/api.h"
#ifdef __cplusplus
extern "C"
{
#endif
//------------------------------------------------------------------------------
/// \struct wfp_client_protocol
/// \brief Opaque webfuse client protocol..
//------------------------------------------------------------------------------
struct wfp_client_protocol;
//------------------------------------------------------------------------------
/// \struct lws_protocols
/// \brief Forward declaration of libwebsockets protocols structure.
//------------------------------------------------------------------------------
struct lws_protocols;
//------------------------------------------------------------------------------
/// \struct lws_context
/// \brief Forward declaration of libwebsockets context structure.
//------------------------------------------------------------------------------
struct lws_context;
//------------------------------------------------------------------------------
/// \struct wfp_client_config
/// \copydoc wfp_client_config
//------------------------------------------------------------------------------
struct wfp_client_config;
//------------------------------------------------------------------------------
/// \brief Creates a new webfuse provider client protocol.
///
/// \note The user is responsible to manage lifetime of \arg config.
///
/// \note TLS configuration is ignored, since TLS is managed by libwebsockets.
///
/// \param config pointer to client config
/// \return newly created protocol
//------------------------------------------------------------------------------
extern WFP_API struct wfp_client_protocol * wfp_client_protocol_create(
struct wfp_client_config const * config);
//------------------------------------------------------------------------------
/// \brief Disposes a protocol.
///
/// \note The user defined context is not managed by the protocol.
///
/// \param protocol pointer to protocol.
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_protocol_dispose(
struct wfp_client_protocol * protocol);
//------------------------------------------------------------------------------
/// \brief Initialized libwebsockets protocol structure.
///
/// \param protocol pointer to protocol
/// \param lws_protocol pointer to libwebsockets protocol structure.
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_protocol_init_lws(
struct wfp_client_protocol * protocol,
struct lws_protocols * lws_protocol);
//------------------------------------------------------------------------------
/// \brief Connects the protocol to a remote webfuse adapter server.
///
/// \note This call starts to establish a connection. A callback is invoked,
/// when the connection is estanlished.
///
/// \param protocol pointer to protocol
/// \param context lws context
/// \param url URL of remote webfuse adapter server
///
/// \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
#endif

View File

@ -1,30 +0,0 @@
#ifndef WF_PROVIDER_CREDENTIALS_H
#define WF_PROVIDER_CREDENTIALS_H
#include <webfuse/provider/api.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_credentials;
typedef void wfp_get_credentials_fn(
struct wfp_credentials * credentials,
void * user_data);
extern WFP_API void wfp_credentials_set_type(
struct wfp_credentials * credentials,
char const * type);
extern WFP_API void wfp_credentials_add(
struct wfp_credentials * credentials,
char const * key,
char const * value);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,60 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// \file provider/dirbuffer.h
/// \brief Buffer used for directory listing.
////////////////////////////////////////////////////////////////////////////////
#ifndef WF_PROVIDER_DIRBUFFER_H
#define WF_PROVIDER_DIRBUFFER_H
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "webfuse/provider/api.h"
#ifdef __cplusplus
extern "C"
{
#endif
//------------------------------------------------------------------------------
/// \struct wfp_dirbuffer
/// \brief Buffer used for directory listing.
///
/// \see wfp_respond_readdir
//------------------------------------------------------------------------------
struct wfp_dirbuffer;
//------------------------------------------------------------------------------
/// \brief Creates a new dir buffer.
///
/// \return newly created dir buffer.
//------------------------------------------------------------------------------
extern WFP_API struct wfp_dirbuffer * wfp_dirbuffer_create(void);
//------------------------------------------------------------------------------
/// \brief Disposes a dir buffer.
///
/// \param buffer pointer to dir buffer
//------------------------------------------------------------------------------
extern WFP_API void wfp_dirbuffer_dispose(
struct wfp_dirbuffer * buffer);
//------------------------------------------------------------------------------
/// \brief Adds an entry to dir buffer.
///
/// \param buffer pointer to dir buffer
/// \param name name of the entry (file or directory)
/// \param inode inode of the entry
//------------------------------------------------------------------------------
extern WFP_API void wfp_dirbuffer_add(
struct wfp_dirbuffer * buffer,
char const * name,
ino_t inode);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,46 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// \file provider/operation/close.h
/// \brief Provider's close callback.
////////////////////////////////////////////////////////////////////////////////
#ifndef WFP_OPERATION_CLOSE_H
#define WFP_OPERATION_CLOSE_H
#ifndef __cplusplus
#include <inttypes.h>
#else
#include <cinttypes>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "webfuse/provider/api.h"
#ifdef __cplusplus
extern "C"
{
#endif
//------------------------------------------------------------------------------
/// \brief Callback invoked when a file is invoked.
///
/// This function does not respond.
///
/// \param inode inode of file to close
/// \param handle handle of file to close
/// \param flags file close flags
/// \param user_data user defined context
//------------------------------------------------------------------------------
typedef void wfp_close_fn(
ino_t inode,
uint32_t handle,
int flags,
void * user_data);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,36 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// \file provider/operation/error.h
/// \brief Respond with error code.
////////////////////////////////////////////////////////////////////////////////
#ifndef WFP_OPERATION_ERROR_H
#define WFP_OPERATION_ERROR_H
#include "webfuse/provider/api.h"
#include "webfuse/core/status.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_request;
//------------------------------------------------------------------------------
/// \brief Respond to a request with an error.
///
/// A client's callback must respond with exactly one responde, either with a
/// valid reponse regarding to the concrete request or with an error response.
///
/// \param request pointer to request
/// \param status error code
//------------------------------------------------------------------------------
extern WFP_API void wfp_respond_error(
struct wfp_request * request,
wf_status status);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,55 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// \file provider/operation/getattr.h
/// \brief Get file attributes.
////////////////////////////////////////////////////////////////////////////////
#ifndef WFP_OPERATION_GETATTR_H
#define WFP_OPERATION_GETATTR_H
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "webfuse/provider/api.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_request;
//------------------------------------------------------------------------------
/// \brief Get file attributes.
///
/// \note After this function is called, exactly one response must be sent,
/// either via \ref wfp_respond_getattr or via \ref wfp_respond_error.
///
/// \param request pointer to request
/// \param inode inode of file to get attributes
/// \param user_data user defined context
///
/// \see wfp_respond_getattr
/// \see wfp_respond_error
//------------------------------------------------------------------------------
typedef void wfp_getattr_fn(
struct wfp_request * request,
ino_t inode,
void * user_data);
//------------------------------------------------------------------------------
/// \brief Respond to a get attributes request.
///
/// \param request pointer to request
/// \param stat file attributes
//------------------------------------------------------------------------------
extern WFP_API void wfp_respond_getattr(
struct wfp_request * request,
struct stat const * stat);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,57 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// \file provider/operation/lookup.h
/// \brief Lookup file.
////////////////////////////////////////////////////////////////////////////////
#ifndef WFP_OPERATION_LOOKUP_H
#define WFP_OPERATION_LOOKUP_H
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "webfuse/provider/api.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_request;
//------------------------------------------------------------------------------
/// \brief Lookup a file or directory.
///
/// \note After this function is called, exactly one response must be sent,
/// either via \ref wfp_respond_lookup or via \ref wfp_respond_error.
///
/// \param request pointer to request
/// \param parent inode of parent
/// \param name name of the filesystem object to lookup
/// \param user_data pointer to user defined context
///
/// \see wfp_respond_lookup
/// \see wfp_respond_error
//------------------------------------------------------------------------------
typedef void wfp_lookup_fn(
struct wfp_request * request,
ino_t parent,
char const * name,
void * user_data);
//------------------------------------------------------------------------------
/// \brief Respond to lookup request.
///
/// \param request pointer to request
/// \param stat attributes of filesystem object
//------------------------------------------------------------------------------
extern WFP_API void wfp_respond_lookup(
struct wfp_request * request,
struct stat const * stat);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,63 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// \file provider/operation/open.h
/// \brief Open a file.
////////////////////////////////////////////////////////////////////////////////
#ifndef WFP_OPERATION_OPEN_H
#define WFP_OPERATION_OPEN_H
#ifndef __cplusplus
#include <inttypes.h>
#else
#include <cinttypes>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "webfuse/provider/api.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_request;
//------------------------------------------------------------------------------
/// \brief Open a file.
///
/// \note After this function is called, exactly one response must be sent,
/// either via \ref wfp_respond_open or via \ref wfp_respond_error.
///
/// \param request pointer to request
/// \param inode inode of the file to open
/// \param flags file open flags
/// \param user_data user defined context
///
/// \see wfp_respond_open
/// \see wfp_respond_error
//------------------------------------------------------------------------------
typedef void wfp_open_fn(
struct wfp_request * request,
ino_t inode,
int flags,
void * user_data);
//------------------------------------------------------------------------------
/// \brief Respond to open file.
///
/// \param request pointer to request
/// \param handle handle of the opened file
//------------------------------------------------------------------------------
extern WFP_API void wfp_respond_open(
struct wfp_request * request,
uint32_t handle);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,76 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// \file provider/operation/read.h
/// \brief Read contents of a file.
////////////////////////////////////////////////////////////////////////////////
#ifndef WFP_OPERATION_READ_H
#define WFP_OPERATION_READ_H
#ifndef __cplusplus
#include <stddef.h>
#include <inttypes.h>
#else
#include <cstddef>
#include <cinttypes>
using std::size_t;
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "webfuse/provider/api.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_request;
//------------------------------------------------------------------------------
/// \brief Requests content of a file.
///
/// On success, up to \arg length bytes should be returned via \ref
/// wfp_respond_read.
///
/// \note After this function is called, exactly one response must be sent,
/// either via \ref wfp_respond_read or via \ref wfp_respond_error.
///
/// \param request pointer to request
/// \param inode inode of the file to read
/// \param handle handle of the file to read (returned by open)
/// \param offset offset within the file where to start reading
/// \param length amount of bytes to read
/// \param user_data used defined context
///
/// \see wfp_respond_read
/// \see wfp_respond_error
//------------------------------------------------------------------------------
typedef void wfp_read_fn(
struct wfp_request * request,
ino_t inode,
uint32_t handle,
size_t offset,
size_t length,
void * user_data);
//------------------------------------------------------------------------------
/// \brief Respond to read.
///
/// \note The user is responsible to manage lifetime of \arg data.
///
/// \param request pointer to request
/// \param data data read from file
/// \param length amount of bytes read
//------------------------------------------------------------------------------
extern WFP_API void wfp_respond_read(
struct wfp_request * request,
char const * data,
size_t length);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,58 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// \file provider/operation/readdir.h
/// \brief List directory contents.
////////////////////////////////////////////////////////////////////////////////
#ifndef WFP_OPERATION_READDIR_H
#define WFP_OPERATION_READDIR_H
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "webfuse/provider/api.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_dirbuffer;
struct wfp_request;
//------------------------------------------------------------------------------
/// \brief Requests the contents of a directory.
///
/// \note After this function is called, exactly one response must be sent,
/// either via \ref wfp_respond_readdir or via \ref wfp_respond_error.
///
/// \param request pointer to request
/// \param directory inode of directory to list
/// \param user_data user defined context
///
/// \see wfp_respond_readdir
/// \see wfp_respond_error
//------------------------------------------------------------------------------
typedef void wfp_readdir_fn(
struct wfp_request * request,
ino_t directory,
void * user_data);
//------------------------------------------------------------------------------
/// \brief Respond to list directory contents.
///
/// \note The user is responsible to manage dirbuffe, p.e. to dispose
/// it after this function is called.
///
/// \param request pointer to request
/// \param dirbuffer contains contents of directory
//------------------------------------------------------------------------------
extern WFP_API void wfp_respond_readdir(
struct wfp_request * request,
struct wfp_dirbuffer * dirbuffer);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,27 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// \file webfuse_provider.h
/// \brief Convenience header to include all functionality of libfuse_provider.
////////////////////////////////////////////////////////////////////////////////
#ifndef WF_PROVIDER_H
#define WF_PROVIDER_H
#include <webfuse/core/status.h>
#include <webfuse/core/protocol_names.h>
#include <webfuse/provider/api.h>
#include <webfuse/provider/client.h>
#include <webfuse/provider/client_config.h>
#include <webfuse/provider/client_protocol.h>
#include <webfuse/provider/dirbuffer.h>
#include <webfuse/provider/credentials.h>
#include <webfuse/provider/operation/error.h>
#include <webfuse/provider/operation/lookup.h>
#include <webfuse/provider/operation/getattr.h>
#include <webfuse/provider/operation/readdir.h>
#include <webfuse/provider/operation/open.h>
#include <webfuse/provider/operation/close.h>
#include <webfuse/provider/operation/read.h>
#endif

View File

@ -1,281 +0,0 @@
#include "webfuse_provider.h"
#include "webfuse/provider/impl/request.h"
#include "webfuse/provider/impl/operation/getattr.h"
#include "webfuse/provider/impl/operation/lookup.h"
#include "webfuse/provider/impl/operation/readdir.h"
#include "webfuse/provider/impl/operation/open.h"
#include "webfuse/provider/impl/operation/close.h"
#include "webfuse/provider/impl/operation/read.h"
#include "webfuse/provider/impl/client_protocol.h"
#include "webfuse/provider/impl/client_config.h"
#include "webfuse/provider/impl/client.h"
#include "webfuse/provider/impl/dirbuffer.h"
#include "webfuse/provider/impl/credentials.h"
#include "webfuse/core/util.h"
// respond
void wfp_respond_error(
struct wfp_request * request,
wf_status status)
{
wfp_impl_respond_error(request, status);
}
void wfp_respond_getattr(
struct wfp_request * request,
struct stat const * stat)
{
wfp_impl_respond_getattr(request, stat);
}
void wfp_respond_lookup(
struct wfp_request * request,
struct stat const * stat)
{
wfp_impl_respond_lookup(request, stat);
}
void wfp_respond_open(
struct wfp_request * request,
uint32_t handle)
{
wfp_impl_respond_open(request, handle);
}
void wfp_respond_read(
struct wfp_request * request,
char const * data,
size_t length)
{
wfp_impl_respond_read(request, data, length);
}
void wfp_respond_readdir(
struct wfp_request * request,
struct wfp_dirbuffer * dirbuffer)
{
wfp_impl_respond_readdir(request, dirbuffer);
}
// config
struct wfp_client_config * wfp_client_config_create(void)
{
return wfp_impl_client_config_create();
}
void wfp_client_config_dispose(
struct wfp_client_config * config)
{
wfp_impl_client_config_dispose(config);
}
void wfp_client_config_set_userdata(
struct wfp_client_config * config,
void * user_data)
{
wfp_impl_client_config_set_userdata(config, user_data);
}
void wfp_client_config_set_keypath(
struct wfp_client_config * config,
char const * key_path)
{
wfp_impl_client_config_set_keypath(config, key_path);
}
void wfp_client_config_set_certpath(
struct wfp_client_config * config,
char const * cert_path)
{
wfp_impl_client_config_set_certpath(config, cert_path);
}
void wfp_client_config_set_ca_filepath(
struct wfp_client_config * config,
char const * ca_filepath)
{
wfp_impl_client_config_set_ca_filepath(config, ca_filepath);
}
void wfp_client_config_set_onconnected(
struct wfp_client_config * config,
wfp_connected_fn * handler)
{
wfp_impl_client_config_set_onconnected(config, handler);
}
void wfp_client_config_set_ondisconnected(
struct wfp_client_config * config,
wfp_disconnected_fn * handler)
{
wfp_impl_client_config_set_ondisconnected(config, handler);
}
void wfp_client_config_set_onlookup(
struct wfp_client_config * config,
wfp_lookup_fn * handler)
{
wfp_impl_client_config_set_onlookup(config, handler);
}
void wfp_client_config_set_ongetattr(
struct wfp_client_config * config,
wfp_getattr_fn * handler)
{
wfp_impl_client_config_set_ongetattr(config, handler);
}
void wfp_client_config_set_onreaddir(
struct wfp_client_config * config,
wfp_readdir_fn * handler)
{
wfp_impl_client_config_set_onreaddir(config, handler);
}
void wfp_client_config_set_onopen(
struct wfp_client_config * config,
wfp_open_fn * handler)
{
wfp_impl_client_config_set_onopen(config, handler);
}
void wfp_client_config_set_onclose(
struct wfp_client_config * config,
wfp_close_fn * handler)
{
wfp_impl_client_config_set_onclose(config, handler);
}
void wfp_client_config_set_onread(
struct wfp_client_config * config,
wfp_read_fn * handler)
{
wfp_impl_client_config_set_onread(config, handler);
}
void wfp_client_config_enable_authentication(
struct wfp_client_config * config,
wfp_get_credentials_fn * get_credentials)
{
wfp_impl_client_config_enable_authentication(config, get_credentials);
}
// protocol
struct wfp_client_protocol * wfp_client_protocol_create(
struct wfp_client_config const * config)
{
return wfp_impl_client_protocol_create(config);
}
void wfp_client_protocol_dispose(
struct wfp_client_protocol * protocol)
{
wfp_impl_client_protocol_dispose(protocol);
}
void wfp_client_protocol_init_lws(
struct wfp_client_protocol * protocol,
struct lws_protocols * lws_protocol)
{
wfp_impl_client_protocol_init_lws(protocol, lws_protocol);
}
void wfp_client_protocol_connect(
struct wfp_client_protocol * protocol,
struct lws_context * context,
char const * url)
{
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
struct wfp_client * wfp_client_create(
struct wfp_client_config * config)
{
return wfp_impl_client_create(config);
}
void wfp_client_connect(
struct wfp_client * client,
char const * url)
{
wfp_impl_client_connect(client, url);
}
void wfp_client_disconnect(
struct wfp_client * client)
{
wfp_impl_client_disconnect(client);
}
void wfp_client_dispose(
struct wfp_client * client)
{
wfp_impl_client_dispose(client);
}
void wfp_client_service(
struct wfp_client * client)
{
wfp_impl_client_service(client);
}
void wfp_client_interrupt(
struct wfp_client * client)
{
wfp_impl_client_interrupt(client);
}
// dirbuffer
struct wfp_dirbuffer * wfp_dirbuffer_create(void)
{
return wfp_impl_dirbuffer_create();
}
void wfp_dirbuffer_dispose(
struct wfp_dirbuffer * buffer)
{
wfp_impl_dirbuffer_dispose(buffer);
}
void wfp_dirbuffer_add(
struct wfp_dirbuffer * buffer,
char const * name,
ino_t inode)
{
wfp_impl_dirbuffer_add(buffer, name, inode);
}
// credentials
void wfp_credentials_set_type(
struct wfp_credentials * credentials,
char const * type)
{
wfp_impl_credentials_set_type(credentials, type);
}
void wfp_credentials_add(
struct wfp_credentials * credentials,
char const * key,
char const * value)
{
wfp_impl_credentials_add(credentials, key, value);
}

View File

@ -1,95 +0,0 @@
#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/core/lws_log.h"
#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));
wfp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data);
memset(client->protocols, 0, sizeof(struct lws_protocols) * WFP_CLIENT_PROTOCOL_COUNT);
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->info.options |= LWS_SERVER_OPTION_EXPLICIT_VHOSTS;
}
client->context = lws_create_context(&client->info);
if ((NULL != config->cert_path) && (NULL != config->key_path))
{
struct lws_vhost * vhost = lws_create_vhost(client->context, &client->info);
client->info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
client->info.client_ssl_cert_filepath = config->cert_path;
client->info.client_ssl_private_key_filepath = config->key_path;
client->info.client_ssl_ca_filepath = config->ca_filepath;
lws_init_vhost_client_ssl(&client->info, vhost);
}
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)
{
wfp_impl_client_protocol_connect(&client->protocol, client->context, url);
}
void wfp_impl_client_disconnect(
struct wfp_client * client)
{
wfp_impl_client_protocol_disconnect(&client->protocol);
}
void wfp_impl_client_service(
struct wfp_client * client)
{
lws_service(client->context, 0);
}
void wfp_impl_client_interrupt(
struct wfp_client * client)
{
lws_cancel_service(client->context);
}

View File

@ -1,48 +0,0 @@
#ifndef WF_PROVIDER_IMPL_CLIENT_H
#define WF_PROVIDER_IMPL_CLIENT_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_client;
struct wfp_client_config;
extern struct wfp_client * wfp_impl_client_create(
struct wfp_client_config * config);
extern void wfp_impl_client_set_keypath(
struct wfp_client * client,
char * key_path);
extern void wfp_impl_client_set_certpath(
struct wfp_client * client,
char * cert_path);
extern void wfp_impl_client_connect(
struct wfp_client * client,
char const * url);
extern void wfp_impl_client_disconnect(
struct wfp_client * client);
extern void wfp_impl_client_dispose(
struct wfp_client * client);
extern void wfp_impl_client_service(
struct wfp_client * client);
extern void wfp_impl_client_interrupt(
struct wfp_client * client);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,119 +0,0 @@
#include "webfuse/provider/impl/client_config.h"
#include "webfuse/provider/impl/provider.h"
#include <stdlib.h>
#include <string.h>
struct wfp_client_config * wfp_impl_client_config_create(void)
{
struct wfp_client_config * config = malloc(sizeof(struct wfp_client_config));
wfp_impl_provider_init(&config->provider);
config->user_data = NULL;
config->key_path = NULL;
config->cert_path = NULL;
config->ca_filepath = NULL;
return config;
}
void wfp_impl_client_config_dispose(
struct wfp_client_config * config)
{
free(config->key_path);
free(config->cert_path);
free(config->ca_filepath);
free(config);
}
void wfp_impl_client_config_set_userdata(
struct wfp_client_config * config,
void * user_data)
{
config->user_data = user_data;
}
void wfp_impl_client_config_set_keypath(
struct wfp_client_config * config,
char const * key_path)
{
free(config->key_path);
config->key_path = strdup(key_path);
}
void wfp_impl_client_config_set_certpath(
struct wfp_client_config * config,
char const * cert_path)
{
free(config->cert_path);
config->cert_path = strdup(cert_path);
}
void wfp_impl_client_config_set_ca_filepath(
struct wfp_client_config * config,
char const * ca_filepath)
{
free(config->ca_filepath);
config->ca_filepath = strdup(ca_filepath);
}
void wfp_impl_client_config_set_onconnected(
struct wfp_client_config * config,
wfp_connected_fn * handler)
{
config->provider.connected = handler;
}
void wfp_impl_client_config_set_ondisconnected(
struct wfp_client_config * config,
wfp_disconnected_fn * handler)
{
config->provider.disconnected = handler;
}
void wfp_impl_client_config_set_onlookup(
struct wfp_client_config * config,
wfp_lookup_fn * handler)
{
config->provider.lookup = handler;
}
void wfp_impl_client_config_set_ongetattr(
struct wfp_client_config * config,
wfp_getattr_fn * handler)
{
config->provider.getattr = handler;
}
void wfp_impl_client_config_set_onreaddir(
struct wfp_client_config * config,
wfp_readdir_fn * handler)
{
config->provider.readdir = handler;
}
void wfp_impl_client_config_set_onopen(
struct wfp_client_config * config,
wfp_open_fn * handler)
{
config->provider.open = handler;
}
void wfp_impl_client_config_set_onclose(
struct wfp_client_config * config,
wfp_close_fn * handler)
{
config->provider.close = handler;
}
void wfp_impl_client_config_set_onread(
struct wfp_client_config * config,
wfp_read_fn * handler)
{
config->provider.read = handler;
}
void wfp_impl_client_config_enable_authentication(
struct wfp_client_config * config,
wfp_get_credentials_fn * get_credentials)
{
config->provider.get_credentials = get_credentials;
}

View File

@ -1,82 +0,0 @@
#ifndef WF_PROVIDER_IMPL_CLIENT_CONFIG_H
#define WF_PROVIDER_IMPL_CLIENT_CONFIG_H
#include "webfuse/provider/client_config.h"
#include "webfuse/provider/impl/provider.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_client_config
{
struct wfp_provider provider;
void * user_data;
char * key_path;
char * cert_path;
char * ca_filepath;
};
extern struct wfp_client_config * wfp_impl_client_config_create(void);
extern void wfp_impl_client_config_dispose(
struct wfp_client_config * config);
extern void wfp_impl_client_config_set_userdata(
struct wfp_client_config * config,
void * user_data);
extern void wfp_impl_client_config_set_keypath(
struct wfp_client_config * config,
char const * key_path);
extern void wfp_impl_client_config_set_certpath(
struct wfp_client_config * config,
char const * cert_path);
extern void wfp_impl_client_config_set_ca_filepath(
struct wfp_client_config * config,
char const * ca_filepath);
extern void wfp_impl_client_config_set_onconnected(
struct wfp_client_config * config,
wfp_connected_fn * handler);
extern void wfp_impl_client_config_set_ondisconnected(
struct wfp_client_config * config,
wfp_disconnected_fn * handler);
extern void wfp_impl_client_config_set_onlookup(
struct wfp_client_config * config,
wfp_lookup_fn * handler);
extern void wfp_impl_client_config_set_ongetattr(
struct wfp_client_config * config,
wfp_getattr_fn * handler);
extern void wfp_impl_client_config_set_onreaddir(
struct wfp_client_config * config,
wfp_readdir_fn * handler);
extern void wfp_impl_client_config_set_onopen(
struct wfp_client_config * config,
wfp_open_fn * handler);
extern void wfp_impl_client_config_set_onclose(
struct wfp_client_config * config,
wfp_close_fn * handler);
extern void wfp_impl_client_config_set_onread(
struct wfp_client_config * config,
wfp_read_fn * handler);
extern void wfp_impl_client_config_enable_authentication(
struct wfp_client_config * config,
wfp_get_credentials_fn * get_credentials);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,340 +0,0 @@
#include "webfuse/provider/impl/client_protocol.h"
#include <stdlib.h>
#include <string.h>
#include <libwebsockets.h>
#include <jansson.h>
#include "webfuse/provider/impl/client_config.h"
#include "webfuse/provider/impl/provider.h"
#include "webfuse/provider/impl/credentials.h"
#include "webfuse/core/util.h"
#include "webfuse/core/message.h"
#include "webfuse/core/message_queue.h"
#include "webfuse/core/container_of.h"
#include "webfuse/core/url.h"
#include "webfuse/core/protocol_names.h"
#include "webfuse/core/timer/manager.h"
#include "webfuse/core/jsonrpc/response.h"
#include "webfuse/core/jsonrpc/request.h"
#include "webfuse/core/jsonrpc/proxy.h"
#define WF_DEFAULT_TIMEOUT (10 * 1000)
static void wfp_impl_client_protocol_respond(
json_t * response,
void * user_data)
{
struct wfp_client_protocol * protocol = (struct wfp_client_protocol *) user_data;
struct wf_message * message = wf_message_create(response);
if (NULL != message)
{
wf_slist_append(&protocol->messages, &message->item);
lws_callback_on_writable(protocol->wsi);
}
}
static void wfp_impl_client_protocol_process(
struct wfp_client_protocol * protocol,
char const * data,
size_t length)
{
json_t * message = json_loadb(data, length, 0, NULL);
if (NULL != message)
{
if (wf_jsonrpc_is_response(message))
{
wf_jsonrpc_proxy_onresult(protocol->proxy, message);
}
if (wf_jsonrpc_is_request(message))
{
struct wfp_impl_invokation_context context =
{
.provider = &protocol->provider,
.user_data = protocol->user_data,
.request = &protocol->request
};
wfp_impl_provider_invoke(&context, message);
}
json_decref(message);
}
}
static void
wfp_impl_client_protocol_on_add_filesystem_finished(
void * user_data,
json_t const * result,
json_t const * WF_UNUSED_PARAM(error))
{
struct wfp_client_protocol * protocol = user_data;
if (NULL == protocol->wsi) { return; }
if (NULL != result)
{
protocol->is_connected = true;
protocol->provider.connected(protocol->user_data);
}
else
{
protocol->is_shutdown_requested = true;
lws_callback_on_writable(protocol->wsi);
}
}
static void wfp_impl_client_protocol_add_filesystem(
struct wfp_client_protocol * protocol)
{
wf_jsonrpc_proxy_invoke(
protocol->proxy,
&wfp_impl_client_protocol_on_add_filesystem_finished,
protocol,
"add_filesystem",
"s",
"cprovider");
}
static void
wfp_impl_client_protocol_on_authenticate_finished(
void * user_data,
json_t const * result,
json_t const * WF_UNUSED_PARAM(error))
{
struct wfp_client_protocol * protocol = user_data;
if (NULL == protocol->wsi) { return; }
if (NULL != result)
{
wfp_impl_client_protocol_add_filesystem(protocol);
}
else
{
protocol->is_shutdown_requested = true;
lws_callback_on_writable(protocol->wsi);
}
}
static void wfp_impl_client_protocol_authenticate(
struct wfp_client_protocol * protocol)
{
struct wfp_credentials credentials;
wfp_impl_credentials_init(&credentials);
protocol->provider.get_credentials(&credentials, protocol->user_data);
char const * cred_type = wfp_impl_credentials_get_type(&credentials);
json_t * creds = wfp_impl_credentials_get(&credentials);
json_incref(creds);
wf_jsonrpc_proxy_invoke(
protocol->proxy,
&wfp_impl_client_protocol_on_authenticate_finished,
protocol,
"authenticate",
"sj",
cred_type, creds);
wfp_impl_credentials_cleanup(&credentials);
}
static void wfp_impl_client_protocol_handshake(
struct wfp_client_protocol * protocol)
{
if (wfp_impl_provider_is_authentication_enabled(&protocol->provider))
{
wfp_impl_client_protocol_authenticate(protocol);
}
else
{
wfp_impl_client_protocol_add_filesystem(protocol);
}
}
static int wfp_impl_client_protocol_callback(
struct lws * wsi,
enum lws_callback_reasons reason,
void * WF_UNUSED_PARAM(user),
void * in,
size_t len)
{
int result = 0;
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
struct wfp_client_protocol * protocol = (NULL != ws_protocol) ? ws_protocol->user: NULL;
if (NULL != protocol)
{
wf_timer_manager_check(protocol->timer_manager);
switch (reason)
{
case LWS_CALLBACK_CLIENT_ESTABLISHED:
wfp_impl_client_protocol_handshake(protocol);
break;
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
protocol->is_connected = false;
protocol->provider.disconnected(protocol->user_data);
break;
case LWS_CALLBACK_CLIENT_CLOSED:
protocol->is_connected = false;
protocol->provider.disconnected(protocol->user_data);
protocol->wsi = NULL;
break;
case LWS_CALLBACK_CLIENT_RECEIVE:
wfp_impl_client_protocol_process(protocol, in, len);
break;
case LWS_CALLBACK_SERVER_WRITEABLE:
// fall-through
case LWS_CALLBACK_CLIENT_WRITEABLE:
if (wsi == protocol->wsi)
{
if (protocol->is_shutdown_requested)
{
result = 1;
}
else if (!wf_slist_empty(&protocol->messages))
{
struct wf_slist_item * item = wf_slist_remove_first(&protocol->messages);
struct wf_message * message = wf_container_of(item, struct wf_message, item);
lws_write(wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT);
wf_message_dispose(message);
if (!wf_slist_empty(&protocol->messages))
{
lws_callback_on_writable(wsi);
}
}
}
break;
default:
break;
}
}
return result;
}
static bool wfp_impl_client_protocol_send(
json_t * request,
void * user_data)
{
bool result = false;
struct wfp_client_protocol * protocol = user_data;
struct wf_message * message = wf_message_create(request);
if (NULL != message)
{
wf_slist_append(&protocol->messages, &message->item);
lws_callback_on_writable(protocol->wsi);
result = true;
}
return result;
}
void wfp_impl_client_protocol_init(
struct wfp_client_protocol * protocol,
struct wfp_provider const * provider,
void * user_data)
{
protocol->is_connected = false;
protocol->is_shutdown_requested = false;
wf_slist_init(&protocol->messages);
protocol->wsi = NULL;
protocol->request.respond = &wfp_impl_client_protocol_respond;
protocol->request.user_data = protocol;
protocol->timer_manager = wf_timer_manager_create();
protocol->proxy = wf_jsonrpc_proxy_create(protocol->timer_manager, WF_DEFAULT_TIMEOUT, &wfp_impl_client_protocol_send, protocol);
protocol->user_data = user_data;
wfp_impl_provider_init_from_prototype(&protocol->provider, provider);
}
void wfp_impl_client_protocol_cleanup(
struct wfp_client_protocol * protocol)
{
wf_jsonrpc_proxy_dispose(protocol->proxy);
wf_timer_manager_dispose(protocol->timer_manager);
wf_message_queue_cleanup(&protocol->messages);
}
struct wfp_client_protocol * wfp_impl_client_protocol_create(
struct wfp_client_config const * config)
{
struct wfp_client_protocol * protocol = malloc(sizeof(struct wfp_client_protocol));
wfp_impl_client_protocol_init(protocol, &config->provider, config->user_data);
return protocol;
}
void wfp_impl_client_protocol_dispose(
struct wfp_client_protocol * protocol)
{
wfp_impl_client_protocol_cleanup(protocol);
free(protocol);
}
void wfp_impl_client_protocol_init_lws(
struct wfp_client_protocol * protocol,
struct lws_protocols * lws_protocol)
{
lws_protocol->name = WF_PROTOCOL_NAME_PROVIDER_CLIENT;
lws_protocol->callback = &wfp_impl_client_protocol_callback;
lws_protocol->per_session_data_size = 0;
lws_protocol->user = protocol;
}
void wfp_impl_client_protocol_connect(
struct wfp_client_protocol * protocol,
struct lws_context * context,
char const * url)
{
struct wf_url url_data;
bool const success = wf_url_init(&url_data, url);
if (success)
{
struct lws_client_connect_info info;
memset(&info, 0, sizeof(struct lws_client_connect_info));
info.context = 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 = WF_PROTOCOL_NAME_ADAPTER_SERVER;
info.local_protocol_name = WF_PROTOCOL_NAME_PROVIDER_CLIENT;
info.pwsi = &protocol->wsi;
lws_client_connect_via_info(&info);
wf_url_cleanup(&url_data);
}
else
{
protocol->provider.disconnected(protocol->user_data);
}
}
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);
}
}

View File

@ -1,63 +0,0 @@
#ifndef WF_PROVIDER_IMPL_CLIENT_PROTOCOL_H
#define WF_PROVIDER_IMPL_CLIENT_PROTOCOL_H
#include "webfuse/provider/impl/provider.h"
#include "webfuse/provider/impl/request.h"
#include "webfuse/core/slist.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_client_config;
struct lws_protocols;
struct lws_context;
struct wf_jsonrpc_proxy;
struct wf_timer_manager;
struct wfp_client_protocol
{
bool is_connected;
bool is_shutdown_requested;
struct wfp_request request;
struct wfp_provider provider;
void * user_data;
struct lws * wsi;
struct wf_timer_manager * timer_manager;
struct wf_jsonrpc_proxy * proxy;
struct wf_slist messages;
};
extern void wfp_impl_client_protocol_init(
struct wfp_client_protocol * protocol,
struct wfp_provider const * provider,
void * user_data);
extern void wfp_impl_client_protocol_cleanup(
struct wfp_client_protocol * protocol);
extern struct wfp_client_protocol * wfp_impl_client_protocol_create(
struct wfp_client_config const * config);
extern void wfp_impl_client_protocol_dispose(
struct wfp_client_protocol * protocol);
extern void wfp_impl_client_protocol_init_lws(
struct wfp_client_protocol * protocol,
struct lws_protocols * lws_protocol);
extern void wfp_impl_client_protocol_connect(
struct wfp_client_protocol * protocol,
struct lws_context * context,
char const * url);
extern void wfp_impl_client_protocol_disconnect(
struct wfp_client_protocol * protocol);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,46 +0,0 @@
#include "webfuse/provider/impl/credentials.h"
#include <stdlib.h>
#include <string.h>
void wfp_impl_credentials_init(
struct wfp_credentials * credentials)
{
credentials->type = NULL;
credentials->contents = json_object();
}
void wfp_impl_credentials_cleanup(
struct wfp_credentials * credentials)
{
free(credentials->type);
json_decref(credentials->contents);
}
void wfp_impl_credentials_set_type(
struct wfp_credentials * credentials,
char const * type)
{
free(credentials->type);
credentials->type = strdup(type);
}
void wfp_impl_credentials_add(
struct wfp_credentials * credentials,
char const * key,
char const * value)
{
json_object_set_new(credentials->contents, key, json_string(value));
}
char const * wfp_impl_credentials_get_type(
struct wfp_credentials * credentials)
{
return credentials->type;
}
json_t * wfp_impl_credentials_get(
struct wfp_credentials * credentials)
{
return credentials->contents;
}

View File

@ -1,43 +0,0 @@
#ifndef WF_PROVIDER_IMPL_CREDENTIALS_H
#define WF_PROVIDER_IMPL_CREDENTIALS_H
#include "webfuse/provider/credentials.h"
#include <jansson.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_credentials
{
char * type;
json_t * contents;
};
extern void wfp_impl_credentials_init(
struct wfp_credentials * credentials);
extern void wfp_impl_credentials_cleanup(
struct wfp_credentials * credentials);
extern void wfp_impl_credentials_set_type(
struct wfp_credentials * credentials,
char const * type);
extern void wfp_impl_credentials_add(
struct wfp_credentials * credentials,
char const * key,
char const * value);
extern char const * wfp_impl_credentials_get_type(
struct wfp_credentials * credentials);
extern json_t * wfp_impl_credentials_get(
struct wfp_credentials * credentials);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,42 +0,0 @@
#include "webfuse/provider/impl/dirbuffer.h"
#include <stdlib.h>
struct wfp_dirbuffer * wfp_impl_dirbuffer_create(void)
{
struct wfp_dirbuffer * buffer = malloc(sizeof(struct wfp_dirbuffer));
buffer->entries = json_array();
return buffer;
}
void wfp_impl_dirbuffer_dispose(
struct wfp_dirbuffer * buffer)
{
if (NULL != buffer->entries)
{
json_decref(buffer->entries);
}
free(buffer);
}
void wfp_impl_dirbuffer_add(
struct wfp_dirbuffer * buffer,
char const * name,
ino_t inode)
{
json_t * entry = json_object();
json_object_set_new(entry, "name", json_string(name));
json_object_set_new(entry, "inode", json_integer(inode));
json_array_append_new(buffer->entries, entry);
}
json_t * wfp_impl_dirbuffer_take(
struct wfp_dirbuffer * buffer)
{
json_t * entries = buffer->entries;
buffer->entries = NULL;
return entries;
}

View File

@ -1,37 +0,0 @@
#ifndef WF_PROVIDER_IMPL_DIRBUFFER_H
#define WF_PROVIDER_IMPL_DIRBUFFER_H
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <jansson.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_dirbuffer
{
json_t * entries;
};
extern struct wfp_dirbuffer * wfp_impl_dirbuffer_create(void);
extern void wfp_impl_dirbuffer_dispose(
struct wfp_dirbuffer * buffer);
extern void wfp_impl_dirbuffer_add(
struct wfp_dirbuffer * buffer,
char const * name,
ino_t inode);
extern json_t * wfp_impl_dirbuffer_take(
struct wfp_dirbuffer * buffer);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,38 +0,0 @@
#include "webfuse/provider/impl/operation/close.h"
#include <limits.h>
#include "webfuse/core/util.h"
void wfp_impl_close(
struct wfp_impl_invokation_context * context,
json_t * params,
int WF_UNUSED_PARAM(id))
{
size_t const param_count = json_array_size(params);
if (4 == param_count)
{
json_t * inode_holder = json_array_get(params, 1);
json_t * handle_holder = json_array_get(params, 2);
json_t * flags_holder = json_array_get(params, 3);
if (json_is_integer(inode_holder) &&
json_is_integer(handle_holder) &&
json_is_integer(flags_holder))
{
ino_t inode = (ino_t) json_integer_value(inode_holder);
uint32_t handle = (uint32_t) (json_integer_value(handle_holder) & UINT32_MAX);
int flags = json_integer_value(flags_holder);
context->provider->close(inode, handle, flags, context->user_data);
}
}
}
void wfp_impl_close_default(
ino_t WF_UNUSED_PARAM(inode),
uint32_t WF_UNUSED_PARAM(handle),
int WF_UNUSED_PARAM(flags),
void * WF_UNUSED_PARAM(user_data))
{
// empty
}

View File

@ -1,26 +0,0 @@
#ifndef WF_PROVIDER_IMPL_OPERATION_CLOSE_H
#define WF_PROVIDER_IMPL_OPERATION_CLOSE_H
#include "webfuse/provider/impl/provider.h"
#ifdef __cplusplus
extern "C"
{
#endif
extern void wfp_impl_close(
struct wfp_impl_invokation_context * context,
json_t * params,
int id);
extern void wfp_impl_close_default(
ino_t inode,
uint32_t handle,
int flags,
void * user_data);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,22 +0,0 @@
#ifndef WFP_OPERATION_IMPL_ERROR_H
#define WFP_OPERATION_IMPL_ERROR_H
#include "webfuse/provider/api.h"
#include "webfuse/core/status.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_request;
extern WFP_API void wfp_impl_respond_error(
struct wfp_request * request,
wf_status status);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,64 +0,0 @@
#include "webfuse/provider/impl/operation/getattr.h"
#include <stdbool.h>
#include "webfuse/provider/impl/operation/error.h"
#include "webfuse/provider/impl/request.h"
#include "webfuse/core/util.h"
void wfp_impl_getattr(
struct wfp_impl_invokation_context * context,
json_t * params,
int id)
{
size_t const count = json_array_size(params);
if (2 == count)
{
json_t * inode_holder = json_array_get(params, 1);
if (json_is_integer(inode_holder))
{
ino_t inode = (ino_t) json_integer_value(inode_holder);
struct wfp_request * request = wfp_impl_request_create(context->request, id);
context->provider->getattr(request, inode, context->user_data);
}
}
}
void wfp_impl_getattr_default(
struct wfp_request * request,
ino_t WF_UNUSED_PARAM(inode),
void * WF_UNUSED_PARAM(user_data))
{
wfp_impl_respond_error(request, WF_BAD_NOENTRY);
}
void wfp_impl_respond_getattr(
struct wfp_request * request,
struct stat const * stat)
{
bool const is_file = (0 != (stat->st_mode & S_IFREG));
bool const is_dir = (0 != (stat->st_mode & S_IFDIR));
json_t * result = json_object();
json_object_set_new(result, "inode", json_integer(stat->st_ino));
json_object_set_new(result, "mode", json_integer(stat->st_mode & 0777));
json_object_set_new(result, "atime", json_integer(stat->st_atime));
json_object_set_new(result, "mtime", json_integer(stat->st_mtime));
json_object_set_new(result, "ctime", json_integer(stat->st_ctime));
if (is_file)
{
json_object_set_new(result, "type", json_string("file"));
json_object_set_new(result, "size", json_integer(stat->st_size));
}
if (is_dir)
{
json_object_set_new(result, "type", json_string("dir"));
}
wfp_impl_respond(request, result);
}

View File

@ -1,29 +0,0 @@
#ifndef WF_PROVIDER_IMPL_OPERATION_GETATTR_H
#define WF_PROVIDER_IMPL_OPERATION_GETATTR_H
#include "webfuse/provider/impl/provider.h"
#ifdef __cplusplus
extern "C"
{
#endif
extern void wfp_impl_respond_getattr(
struct wfp_request * request,
struct stat const * stat);
extern void wfp_impl_getattr(
struct wfp_impl_invokation_context * context,
json_t * params,
int id);
extern void wfp_impl_getattr_default(
struct wfp_request * request,
ino_t inode,
void * user_data);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,68 +0,0 @@
#include "webfuse/provider/impl/operation/lookup.h"
#include <stdbool.h>
#include "webfuse/provider/impl/operation/error.h"
#include "webfuse/provider/impl/request.h"
#include "webfuse/core/util.h"
void wfp_impl_lookup(
struct wfp_impl_invokation_context * context,
json_t * params,
int id)
{
size_t const count = json_array_size(params);
if (3 == count)
{
json_t * inode_holder = json_array_get(params, 1);
json_t * name_holder = json_array_get(params, 2);
if (json_is_integer(inode_holder) &&
json_is_string(name_holder))
{
ino_t inode = json_integer_value(inode_holder);
char const * name = json_string_value(name_holder);
struct wfp_request * request = wfp_impl_request_create(context->request, id);
context->provider->lookup(request, inode, name, context->user_data);
}
}
}
void wfp_impl_respond_lookup(
struct wfp_request * request,
struct stat const * stat)
{
bool const is_file = (0 != (stat->st_mode & S_IFREG));
bool const is_dir = (0 != (stat->st_mode & S_IFDIR));
json_t * result = json_object();
json_object_set_new(result, "inode", json_integer(stat->st_ino));
json_object_set_new(result, "mode", json_integer(stat->st_mode & 0777));
json_object_set_new(result, "atime", json_integer(stat->st_atime));
json_object_set_new(result, "mtime", json_integer(stat->st_mtime));
json_object_set_new(result, "ctime", json_integer(stat->st_ctime));
if (is_file)
{
json_object_set_new(result, "type", json_string("file"));
json_object_set_new(result, "size", json_integer(stat->st_size));
}
if (is_dir)
{
json_object_set_new(result, "type", json_string("dir"));
}
wfp_impl_respond(request, result);
}
void wfp_impl_lookup_default(
struct wfp_request * request,
ino_t WF_UNUSED_PARAM(parent),
char const * WF_UNUSED_PARAM(name),
void * WF_UNUSED_PARAM(user_data))
{
wfp_impl_respond_error(request, WF_BAD_NOENTRY);
}

View File

@ -1,30 +0,0 @@
#ifndef WF_PROVIDER_IMPL_OPERATION_LOOKUP_H
#define WF_PROVIDER_IMPL_OPERATION_LOOKUP_H
#include "webfuse/provider/impl/provider.h"
#ifdef __cplusplus
extern "C"
{
#endif
extern void wfp_impl_respond_lookup(
struct wfp_request * request,
struct stat const * stat);
extern void wfp_impl_lookup(
struct wfp_impl_invokation_context * context,
json_t * params,
int id);
extern void wfp_impl_lookup_default(
struct wfp_request * request,
ino_t parent,
char const * name,
void * user_data);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,47 +0,0 @@
#include "webfuse/provider/impl/operation/open.h"
#include "webfuse/provider/impl/operation/error.h"
#include "webfuse/provider/impl/request.h"
#include "webfuse/core/util.h"
void wfp_impl_open(
struct wfp_impl_invokation_context * context,
json_t * params,
int id)
{
size_t const count = json_array_size(params);
if (3 == count)
{
json_t * inode_holder = json_array_get(params, 1);
json_t * flags_holder = json_array_get(params, 2);
if (json_is_integer(inode_holder) &&
json_is_integer(flags_holder))
{
ino_t inode = (ino_t) json_integer_value(inode_holder);
int flags = (ino_t) json_integer_value(flags_holder);
struct wfp_request * request = wfp_impl_request_create(context->request, id);
context->provider->open(request, inode, flags, context->user_data);
}
}
}
void wfp_impl_open_default(
struct wfp_request * request,
ino_t WF_UNUSED_PARAM(inode),
int WF_UNUSED_PARAM(flags),
void * WF_UNUSED_PARAM(user_data))
{
wfp_impl_respond_error(request, WF_BAD_NOENTRY);
}
void wfp_impl_respond_open(
struct wfp_request * request,
uint32_t handle)
{
json_t * result = json_object();
json_object_set_new(result, "handle", json_integer((int) handle));
wfp_impl_respond(request, result);
}

View File

@ -1,30 +0,0 @@
#ifndef WF_PROVIDER_IMPL_OPERATION_OPEN_H
#define WF_PROVIDER_IMPL_OPERATION_OPEN_H
#include "webfuse/provider/impl/provider.h"
#ifdef __cplusplus
extern "C"
{
#endif
extern void wfp_impl_respond_open(
struct wfp_request * request,
uint32_t handle);
extern void wfp_impl_open(
struct wfp_impl_invokation_context * context,
json_t * params,
int id);
extern void wfp_impl_open_default(
struct wfp_request * request,
ino_t inode,
int flags,
void * user_data);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,78 +0,0 @@
#include "webfuse/provider/impl/operation/read.h"
#include <stdlib.h>
#include "webfuse/provider/impl/operation/error.h"
#include "webfuse/provider/impl/request.h"
#include "webfuse/core/util.h"
#include "webfuse/core/base64.h"
void wfp_impl_read(
struct wfp_impl_invokation_context * context,
json_t * params,
int id)
{
size_t const count = json_array_size(params);
if (5 == count)
{
json_t * inode_holder = json_array_get(params, 1);
json_t * handle_holder = json_array_get(params, 2);
json_t * offset_holder = json_array_get(params, 3);
json_t * length_holder = json_array_get(params, 4);
if (json_is_integer(inode_holder) &&
json_is_integer(handle_holder) &&
json_is_integer(offset_holder) &&
json_is_integer(length_holder))
{
ino_t inode = (ino_t) json_integer_value(inode_holder);
int handle = json_integer_value(handle_holder);
size_t offset = json_integer_value(offset_holder);
size_t length = json_integer_value(length_holder);
struct wfp_request * request = wfp_impl_request_create(context->request, id);
context->provider->read(request, inode, handle, offset, length, context->user_data);
}
}
}
void wfp_impl_read_default(
struct wfp_request * request,
ino_t WF_UNUSED_PARAM(inode),
uint32_t WF_UNUSED_PARAM(handle),
size_t WF_UNUSED_PARAM(offset),
size_t WF_UNUSED_PARAM(length),
void * WF_UNUSED_PARAM(user_data))
{
wfp_impl_respond_error(request, WF_BAD_NOENTRY);
}
void wfp_impl_respond_read(
struct wfp_request * request,
char const * data,
size_t length)
{
if (0 < length)
{
size_t const size = wf_base64_encoded_size(length) + 1;
char * buffer = malloc(size);
wf_base64_encode((uint8_t const *) data, length, buffer, size);
json_t * result = json_object();
json_object_set_new(result, "data", json_string(buffer));
json_object_set_new(result, "format", json_string("base64"));
json_object_set_new(result, "count", json_integer((int) length));
wfp_impl_respond(request, result);
free(buffer);
}
else
{
json_t * result = json_object();
json_object_set_new(result, "data", json_string(""));
json_object_set_new(result, "format", json_string("identity"));
json_object_set_new(result, "count", json_integer(0));
wfp_impl_respond(request, result);
}
}

View File

@ -1,33 +0,0 @@
#ifndef WF_PROVIDER_IMPL_OPERATION_READ_H
#define WF_PROVIDER_IMPL_OPERATION_READ_H
#include "webfuse/provider/impl/provider.h"
#ifdef __cplusplus
extern "C"
{
#endif
extern void wfp_impl_respond_read(
struct wfp_request * request,
char const * data,
size_t length);
extern void wfp_impl_read(
struct wfp_impl_invokation_context * context,
json_t * params,
int id);
extern void wfp_impl_read_default(
struct wfp_request * request,
ino_t inode,
uint32_t handle,
size_t offset,
size_t length,
void * user_data);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,42 +0,0 @@
#include "webfuse/provider/impl/operation/readdir.h"
#include "webfuse/provider/impl/operation/error.h"
#include "webfuse/provider/impl/dirbuffer.h"
#include "webfuse/provider/impl/request.h"
#include "webfuse/core/util.h"
void wfp_impl_readdir(
struct wfp_impl_invokation_context * context,
json_t * params,
int id)
{
size_t const count = json_array_size(params);
if (2 == count)
{
json_t * inode_holder = json_array_get(params, 1);
if (json_is_integer(inode_holder))
{
ino_t inode = (ino_t) json_integer_value(inode_holder);
struct wfp_request * request = wfp_impl_request_create(context->request, id);
context->provider->readdir(request, inode, context->user_data);
}
}
}
void wfp_impl_readdir_default(
struct wfp_request * request,
ino_t WF_UNUSED_PARAM(directory),
void * WF_UNUSED_PARAM(user_data))
{
wfp_impl_respond_error(request, WF_BAD_NOENTRY);
}
void wfp_impl_respond_readdir(
struct wfp_request * request,
struct wfp_dirbuffer * dirbuffer)
{
json_t * result = wfp_impl_dirbuffer_take(dirbuffer);
wfp_impl_respond(request, result);
}

View File

@ -1,29 +0,0 @@
#ifndef WF_PROVIDER_IMPL_OPERATION_READDIR_H
#define WF_PROVIDER_IMPL_OPERATION_READDIR_H
#include "webfuse/provider/impl/provider.h"
#ifdef __cplusplus
extern "C"
{
#endif
extern void wfp_impl_respond_readdir(
struct wfp_request * request,
struct wfp_dirbuffer * dirbuffer);
extern void wfp_impl_readdir(
struct wfp_impl_invokation_context * context,
json_t * params,
int id);
extern void wfp_impl_readdir_default(
struct wfp_request * request,
ino_t directory,
void * user_data);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,125 +0,0 @@
#include "webfuse/provider/impl/provider.h"
#include <stdbool.h>
#include <string.h>
#include "webfuse/provider/impl/request.h"
#include "webfuse/provider/impl/operation/lookup.h"
#include "webfuse/provider/impl/operation/getattr.h"
#include "webfuse/provider/impl/operation/readdir.h"
#include "webfuse/provider/impl/operation/open.h"
#include "webfuse/provider/impl/operation/close.h"
#include "webfuse/provider/impl/operation/read.h"
typedef void wfp_impl_invoke_fn(
struct wfp_impl_invokation_context * context,
json_t * params,
int id);
struct wfp_impl_method
{
char const * name;
wfp_impl_invoke_fn * invoke;
bool is_notification;
};
static void wfp_impl_provider_invoke_method(
struct wfp_impl_invokation_context * context,
char const * method_name,
json_t * params,
int id)
{
static struct wfp_impl_method const methods[] =
{
{"lookup", &wfp_impl_lookup, false},
{"getattr", &wfp_impl_getattr, false},
{"readdir", &wfp_impl_readdir, false},
{"open", &wfp_impl_open, false},
{"close", &wfp_impl_close, true},
{"read", &wfp_impl_read, false}
};
static size_t const count = sizeof(methods) / sizeof(methods[0]);
for (size_t i = 0; i < count; i++)
{
struct wfp_impl_method const * method = &methods[i];
if (0 == strcmp(method_name, method->name))
{
if ((0 < id) || (method->is_notification))
{
method->invoke(context, params, id);
}
break;
}
}
}
void wfp_impl_provider_init(
struct wfp_provider * provider)
{
provider->lookup = &wfp_impl_lookup_default;
provider->getattr = &wfp_impl_getattr_default;
provider->readdir = &wfp_impl_readdir_default;
provider->open = &wfp_impl_open_default;
provider->close = &wfp_impl_close_default;
provider->read = &wfp_impl_read_default;
provider->connected = &wfp_impl_connected_default;
provider->disconnected = &wfp_impl_disconnected_default;
provider->get_credentials = NULL;
}
void wfp_impl_provider_init_from_prototype(
struct wfp_provider * provider,
struct wfp_provider const * prototype)
{
provider->lookup = prototype->lookup;
provider->getattr = prototype->getattr;
provider->readdir = prototype->readdir;
provider->open = prototype->open;
provider->close = prototype->close;
provider->read = prototype->read;
provider->connected = prototype->connected;
provider->disconnected = prototype->disconnected;
provider->get_credentials = prototype->get_credentials;
}
void wfp_impl_provider_invoke(
struct wfp_impl_invokation_context * context,
json_t * request)
{
json_t * method_holder = json_object_get(request, "method");
json_t * params = json_object_get(request, "params");
json_t * id_holder = json_object_get(request, "id");
if ((json_is_string(method_holder)) && (json_is_array(params)))
{
char const * method = json_string_value(method_holder);
int id = json_is_integer(id_holder) ? json_integer_value(id_holder) : 0;
wfp_impl_provider_invoke_method(context, method, params, id);
}
}
void wfp_impl_connected_default(
void * user_data)
{
(void) user_data;
// empty
}
void wfp_impl_disconnected_default(
void * user_data)
{
(void) user_data;
// empty
}
bool wfp_impl_provider_is_authentication_enabled(
struct wfp_provider * provider)
{
return (NULL != provider->get_credentials);
}

View File

@ -1,62 +0,0 @@
#ifndef WF_PROVIDER_IMPL_PROVIDER_H
#define WF_PROVIDER_IMPL_PROVIDER_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include <jansson.h>
#include "webfuse/provider/client_config.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_provider
{
wfp_connected_fn * connected;
wfp_disconnected_fn * disconnected;
wfp_lookup_fn * lookup;
wfp_getattr_fn * getattr;
wfp_readdir_fn * readdir;
wfp_open_fn * open;
wfp_close_fn * close;
wfp_read_fn * read;
wfp_get_credentials_fn * get_credentials;
};
struct wfp_impl_invokation_context
{
struct wfp_provider const * provider;
void * user_data;
struct wfp_request * request;
};
extern void wfp_impl_provider_init(
struct wfp_provider * provider);
extern void wfp_impl_provider_init_from_prototype(
struct wfp_provider * provider,
struct wfp_provider const * prototype);
extern void wfp_impl_provider_invoke(
struct wfp_impl_invokation_context * context,
json_t * request);
extern bool wfp_impl_provider_is_authentication_enabled(
struct wfp_provider * provider);
extern void wfp_impl_connected_default(
void * user_data);
extern void wfp_impl_disconnected_default(
void * user_data);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,52 +0,0 @@
#include "webfuse/provider/impl/request.h"
#include <stdlib.h>
#include "webfuse/provider/impl/operation/error.h"
struct wfp_request * wfp_impl_request_create(
struct wfp_request * prototype,
int id)
{
struct wfp_request * request = malloc(sizeof(struct wfp_request));
request->respond = prototype->respond;
request->user_data = prototype->user_data;
request->id = id;
return request;
}
void wfp_impl_request_dispose(
struct wfp_request * request)
{
free(request);
}
extern void wfp_impl_respond(
struct wfp_request * request,
json_t * result)
{
json_t * response = json_object();
json_object_set_new(response, "result", result);
json_object_set_new(response, "id", json_integer(request->id));
request->respond(response, request->user_data);
json_decref(response);
wfp_impl_request_dispose(request);
}
void wfp_impl_respond_error(
struct wfp_request * request,
wf_status status)
{
json_t * response = json_object();
json_t * error = json_object();
json_object_set_new(error, "code", json_integer(status));
json_object_set_new(response, "error", error);
json_object_set_new(response, "id", json_integer(request->id));
request->respond(response, request->user_data);
json_decref(response);
wfp_impl_request_dispose(request);
}

View File

@ -1,43 +0,0 @@
#ifndef WF_PROVIDER_IMPL_REQUEST_H
#define WF_PROVIDER_IMPL_REQUEST_H
#include <jansson.h>
#include "webfuse/provider/impl/provider.h"
#include "webfuse/core/status.h"
#ifdef __cplusplus
extern "C"
{
#endif
typedef void wfp_impl_request_respond_fn(
json_t * response,
void * user_data);
struct wfp_request
{
wfp_impl_request_respond_fn * respond;
void * user_data;
int id;
};
extern void wfp_impl_respond_error(
struct wfp_request * request,
wf_status status);
extern struct wfp_request * wfp_impl_request_create(
struct wfp_request * prototype,
int id);
extern void wfp_impl_request_dispose(
struct wfp_request * request);
extern void wfp_impl_respond(
struct wfp_request * request,
json_t * result);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -132,15 +132,11 @@ alltests = executable('alltests',
'test/webfuse/utils/tempdir.cc',
'test/webfuse/utils/file_utils.cc',
'test/webfuse/utils/timeout_watcher.cc',
'test/webfuse/utils/path.c',
'test/webfuse/utils/ws_server.cc',
'test/webfuse/utils/ws_server2.cc',
'test/webfuse/utils/adapter_client.cc',
'test/webfuse/utils/jansson_test_environment.cc',
'test/webfuse/mocks/fake_invokation_context.cc',
'test/webfuse/mocks/mock_authenticator.cc',
'test/webfuse/mocks/mock_request.cc',
'test/webfuse/mocks/mock_provider.cc',
'test/webfuse/mocks/mock_fuse.cc',
'test/webfuse/mocks/mock_operation_context.cc',
'test/webfuse/mocks/mock_jsonrpc_proxy.cc',

View File

@ -1,17 +0,0 @@
#include "webfuse/mocks/fake_invokation_context.hpp"
namespace webfuse_test
{
wfp_impl_invokation_context create_context(MockProvider& provider, wfp_request * request)
{
wfp_impl_invokation_context context =
{
provider.get_provider(),
provider.get_userdata(),
request
};
return context;
}
}

View File

@ -1,16 +0,0 @@
#ifndef FAKE_INVOCATION_CONTEXT_HPP
#define FAKE_INVOCATION_CONTEXT_HPP
#include "webfuse/provider/impl/provider.h"
#include "webfuse/mocks/mock_provider.hpp"
namespace webfuse_test
{
wfp_impl_invokation_context create_context(
MockProvider& provider,
wfp_request * request = nullptr);
}
#endif

View File

@ -1,130 +0,0 @@
#include "webfuse/mocks/mock_provider.hpp"
extern "C"
{
using webfuse_test::MockProvider;
static void webfuse_test_MockProvider_connected(
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->connected();
}
static void webfuse_test_MockProvider_disconnected(
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->disconnected();
}
static void webfuse_test_MockProvider_lookup(
wfp_request * request,
ino_t parent,
char const * name,
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->lookup(request, parent, name);
}
static void webfuse_test_MockProvider_getattr(
wfp_request * request,
ino_t inode,
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->getattr(request, inode);
}
static void webfuse_test_MockProvider_readdir(
wfp_request * request,
ino_t directory,
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->readdir(request, directory);
}
static void webfuse_test_MockProvider_open(
wfp_request * request,
ino_t inode,
int flags,
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->open(request, inode, flags);
}
static void webfuse_test_MockProvider_close(
ino_t inode,
uint32_t handle,
int flags,
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->close(inode, handle, flags);
}
static void webfuse_test_MockProvider_read(
wfp_request * request,
ino_t inode,
uint32_t handle,
size_t offset,
size_t length,
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->read(request, inode, handle, offset, length);
}
static void webfuse_test_MockProvider_get_credentials(
wfp_credentials * credentials,
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->get_credentials(credentials);
}
static wfp_provider const webfuse_test_MockProvider =
{
&webfuse_test_MockProvider_connected,
&webfuse_test_MockProvider_disconnected,
&webfuse_test_MockProvider_lookup,
&webfuse_test_MockProvider_getattr,
&webfuse_test_MockProvider_readdir,
&webfuse_test_MockProvider_open,
&webfuse_test_MockProvider_close,
&webfuse_test_MockProvider_read,
&webfuse_test_MockProvider_get_credentials,
};
}
namespace webfuse_test
{
MockProvider::MockProvider()
{
}
MockProvider::~MockProvider()
{
}
wfp_provider const * MockProvider::get_provider()
{
return &webfuse_test_MockProvider;
}
void * MockProvider::get_userdata()
{
return reinterpret_cast<void*>(this);
}
}

View File

@ -1,31 +0,0 @@
#ifndef WF_MOCK_PROVIDER_HPP
#define WF_MOCK_PROVIDER_HPP
#include "webfuse/provider/impl/provider.h"
#include <gmock/gmock.h>
namespace webfuse_test
{
class MockProvider
{
public:
MockProvider();
~MockProvider();
wfp_provider const * get_provider();
void * get_userdata();
MOCK_METHOD0(connected, void ());
MOCK_METHOD0(disconnected, void ());
MOCK_METHOD0(on_timer, void());
MOCK_METHOD3(lookup, void(wfp_request * request, ino_t parent, char const * name));
MOCK_METHOD2(getattr, void(wfp_request * request, ino_t inode));
MOCK_METHOD2(readdir, void(wfp_request * request, ino_t directory));
MOCK_METHOD3(open, void(wfp_request * request, ino_t inode, int flags));
MOCK_METHOD3(close, void(ino_t inode, uint32_t handle, int flags));
MOCK_METHOD5(read, void(wfp_request * request, ino_t inode, uint32_t handle, size_t offset, size_t length));
MOCK_METHOD1(get_credentials, void(wfp_credentials * credentials));
};
}
#endif

View File

@ -1,50 +0,0 @@
#include "webfuse/mocks/mock_request.hpp"
#include <cstdlib>
extern "C"
{
static void webfuse_test_MockRequest_respond(
json_t * response,
void * user_data)
{
auto * request = reinterpret_cast<webfuse_test::MockRequest*>(user_data);
json_t * result = json_object_get(response, "result");
json_t * error = json_object_get(response, "error");
json_t * id_holder = json_object_get(response, "id");
int id = -1;
if (json_is_integer(id_holder))
{
id = json_integer_value(id_holder);
}
if (nullptr != result)
{
request->respond(result, id);
}
else
{
request->respond_error(error, id);
}
}
}
namespace webfuse_test
{
struct wfp_request * MockRequest::create_request(int id)
{
auto * request = reinterpret_cast<wfp_request*>(malloc(sizeof(wfp_request)));
request->respond = &webfuse_test_MockRequest_respond;
request->user_data = reinterpret_cast<void*>(this);
request->id = id;
return request;
}
}

View File

@ -1,147 +0,0 @@
#ifndef WF_MOCK_REQUEST_HPP
#define WF_MOCK_REQUEST_HPP
#include <gmock/gmock.h>
#include <jansson.h>
#include <cstring>
#include "webfuse/provider/impl/request.h"
namespace webfuse_test
{
class MockRequest
{
public:
struct wfp_request * create_request(int id);
MOCK_METHOD2(respond, void(json_t * result, int id));
MOCK_METHOD2(respond_error, void(json_t * error, int id));
};
MATCHER_P3(StatMatcher, inode, mode, file_type, "")
{
json_t * inode_holder = json_object_get(arg, "inode");
if ((!json_is_integer(inode_holder)) || (inode != json_integer_value(inode_holder)))
{
*result_listener << "missing inode";
return false;
}
json_t * mode_holder = json_object_get(arg, "mode");
if ((!json_is_integer(mode_holder)) || (mode != json_integer_value(mode_holder)))
{
*result_listener << "missing mode";
return false;
}
json_t * type_holder = json_object_get(arg, "type");
if ((!json_is_string(type_holder)) || (0 != strcmp(file_type, json_string_value(type_holder))))
{
*result_listener << "missing type";
return false;
}
return true;
}
MATCHER_P(OpenMatcher, handle, "")
{
json_t * handle_holder = json_object_get(arg, "handle");
if ((!json_is_integer(handle_holder)) || (handle != json_integer_value(handle_holder)))
{
*result_listener << "missing handle";
return false;
}
return true;
}
MATCHER_P3(ReadResultMatcher, data, format, count, "")
{
json_t * format_holder = json_object_get(arg, "format");
if ((!json_is_string(format_holder)) || (0 != strcmp(format, json_string_value(format_holder))))
{
*result_listener << "invalid or missing format: " << json_string_value(format_holder);
return false;
}
json_t * count_holder = json_object_get(arg, "count");
if ((!json_is_integer(count_holder)) || (count != json_integer_value(count_holder)))
{
*result_listener << "invalid or missing count: " << json_integer_value(count_holder);
return false;
}
json_t * data_holder = json_object_get(arg, "data");
if ((!json_is_string(data_holder)) || (0 != strcmp(data, json_string_value(data_holder))))
{
*result_listener << "invalid or missing data: " << json_string_value(data_holder);
return false;
}
return true;
}
MATCHER_P(ReaddirMatcher, contained_elements , "")
{
if (!json_is_array(arg))
{
*result_listener << "result is not array";
return false;
}
{
size_t i;
json_t * value;
json_array_foreach(arg, i, value)
{
json_t * inode = json_object_get(value, "inode");
json_t * name = json_object_get(value, "name");
if(!json_is_integer(inode))
{
*result_listener << "invalid result: missing inode";
return false;
}
if (!json_is_string(name))
{
*result_listener << "invalid result: missing name";
return false;
}
}
}
for(size_t i = 0; NULL != contained_elements[i]; i++)
{
char const * element = contained_elements[i];
bool found = false;
size_t j;
json_t * value;
json_array_foreach(arg, j, value)
{
json_t * name = json_object_get(value, "name");
found = (0 == strcmp(element, json_string_value(name)));
if (found)
{
break;
}
}
if (!found)
{
*result_listener << "missing required directory element: " << element;
return false;
}
}
return true;
}
}
#endif

View File

@ -1,148 +0,0 @@
#include "webfuse/tests/integration/provider.hpp"
#include "webfuse_provider.h"
#include "webfuse/provider/impl/client.h"
#include <thread>
#include <mutex>
#include <chrono>
#include <string>
#include "webfuse/utils/static_filesystem.h"
using namespace std::chrono_literals;
namespace
{
enum class ConnectionState
{
disconnected,
connected,
connecting
};
}
extern "C"
{
void
webfuse_test_provider_onconnected(
void * user_data)
{
auto * fs = reinterpret_cast<wfp_static_filesystem*>(user_data);
auto * connection_state = reinterpret_cast<ConnectionState*>(wfp_static_filesystem_get_user_data(fs));
*connection_state = ConnectionState::connected;
}
void
webfuse_test_provider_ondisconnected(
void * user_data)
{
auto * fs = reinterpret_cast<wfp_static_filesystem*>(user_data);
auto * connection_state = reinterpret_cast<ConnectionState*>(wfp_static_filesystem_get_user_data(fs));
*connection_state = ConnectionState::disconnected;
}
}
namespace webfuse_test
{
class Provider::Private
{
public:
explicit Private(char const * url)
: is_shutdown_requested(false)
, connection_state(ConnectionState::connecting)
{
config = wfp_client_config_create();
wfp_client_config_set_certpath(config, "client-cert.pem");
wfp_client_config_set_keypath(config, "client-key.pem");
wfp_client_config_set_ca_filepath(config, "server-cert.pem");
wfp_client_config_set_onconnected(config, &webfuse_test_provider_onconnected);
wfp_client_config_set_ondisconnected(config, &webfuse_test_provider_ondisconnected);
fs = wfp_static_filesystem_create(config);
wfp_static_filesystem_set_user_data(fs, reinterpret_cast<void*>(&connection_state));
wfp_static_filesystem_add_text(fs, "hello.txt", 0444, "Hello, World");
client = wfp_client_create(config);
wfp_client_connect(client, url);
while (ConnectionState::connecting == connection_state)
{
wfp_client_service(client);
}
if (ConnectionState::connected == connection_state)
{
thread = std::thread(Run, this);
std::this_thread::sleep_for(200ms);
}
else
{
wfp_client_dispose(client);
wfp_static_filesystem_dispose(fs);
wfp_client_config_dispose(config);
throw std::runtime_error("unable to connect");
}
}
~Private()
{
RequestShutdown();
thread.join();
wfp_client_disconnect(client);
while (ConnectionState::disconnected != connection_state)
{
wfp_client_service(client);
}
wfp_client_dispose(client);
wfp_static_filesystem_dispose(fs);
wfp_client_config_dispose(config);
}
bool IsShutdownRequested()
{
std::lock_guard<std::mutex> lock(shutdown_lock);
return is_shutdown_requested;
}
private:
void RequestShutdown()
{
std::lock_guard<std::mutex> lock(shutdown_lock);
is_shutdown_requested = true;
wfp_client_interrupt(client);
}
static void Run(Provider::Private * context)
{
while (!context->IsShutdownRequested())
{
wfp_client_service(context->client);
}
}
std::mutex shutdown_lock;
std::thread thread;
bool is_shutdown_requested;
ConnectionState connection_state;
wfp_client_config * config;
wfp_static_filesystem * fs;
public:
wfp_client * client;
};
Provider::Provider(char const * url)
: d(new Provider::Private(url))
{
}
Provider::~Provider()
{
delete d;
}
}

View File

@ -1,19 +0,0 @@
#ifndef WF_TEST_INTEGRATION_PROVIDER
#define WF_TEST_INTEGRATION_PROVIDER
namespace webfuse_test
{
class Provider
{
public:
explicit Provider(char const * url);
~Provider();
private:
class Private;
Private * d;
};
}
#endif

View File

@ -1,99 +0,0 @@
#include "webfuse/provider/impl/operation/close.h"
#include "webfuse/mocks/mock_provider.hpp"
#include "webfuse/mocks/fake_invokation_context.hpp"
#include <gtest/gtest.h>
using ::webfuse_test::MockProvider;
using ::webfuse_test::create_context;
using ::testing::_;
TEST(wfp_close, close)
{
int inode = 42;
int handle = 0xdeadbeef;
int flags = 23;
MockProvider provider;
EXPECT_CALL(provider, close(inode, handle, flags)).Times(1);
wfp_impl_invokation_context context = create_context(provider);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_integer(inode));
json_array_append_new(params, json_integer(handle));
json_array_append_new(params, json_integer(flags));
wfp_impl_close(&context, params, 42);
json_decref(params);
}
TEST(wfp_close, close_fail_invalid_param_count)
{
MockProvider provider;
EXPECT_CALL(provider, close(_,_,_)).Times(0);
wfp_impl_invokation_context context = create_context(provider);
json_t * params = json_array();
wfp_impl_close(&context, params, 42);
json_decref(params);
}
TEST(wfp_close, close_fail_inode_invalid_type)
{
MockProvider provider;
EXPECT_CALL(provider, close(_,_,_)).Times(0);
wfp_impl_invokation_context context = create_context(provider);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_string("42"));
json_array_append_new(params, json_integer(0));
json_array_append_new(params, json_integer(0));
wfp_impl_close(&context, params, 42);
json_decref(params);
}
TEST(wfp_close, close_fail_handle_invalid_type)
{
MockProvider provider;
EXPECT_CALL(provider, close(_,_,_)).Times(0);
wfp_impl_invokation_context context = create_context(provider);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_integer(0));
json_array_append_new(params, json_string("42"));
json_array_append_new(params, json_integer(0));
wfp_impl_close(&context, params, 42);
json_decref(params);
}
TEST(wfp_close, close_fail_flags_invalid_type)
{
MockProvider provider;
EXPECT_CALL(provider, close(_,_,_)).Times(0);
wfp_impl_invokation_context context = create_context(provider);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_integer(0));
json_array_append_new(params, json_integer(0));
json_array_append_new(params, json_string("42"));
wfp_impl_close(&context, params, 42);
json_decref(params);
}
TEST(wfp_close, default_nop)
{
wfp_impl_close_default(0, 0, 0, nullptr);
}

View File

@ -1,107 +0,0 @@
#include "webfuse/provider/impl/operation/getattr.h"
#include "webfuse/mocks/mock_request.hpp"
#include "webfuse/mocks/mock_provider.hpp"
#include "webfuse/mocks/fake_invokation_context.hpp"
#include <gtest/gtest.h>
#include <cstdlib>
using ::webfuse_test::MockProvider;
using ::webfuse_test::MockRequest;
using ::webfuse_test::StatMatcher;
using ::webfuse_test::create_context;
using ::testing::_;
using ::testing::Invoke;
namespace
{
void free_request(wfp_request * request, ino_t)
{
free(request);
}
}
TEST(wfp_impl_getattr, default_responds_error)
{
MockRequest request;
auto * req = request.create_request(42);
EXPECT_CALL(request, respond_error(_,42)).Times(1);
wfp_impl_getattr_default(req, 0, nullptr);
}
TEST(wfp_impl_getattr, respond_file)
{
MockRequest request;
auto * req = request.create_request(42);
EXPECT_CALL(request, respond(StatMatcher(23, 0754, "file"), 42)).Times(1);
struct stat buffer;
memset(&buffer, 0, sizeof(buffer));
buffer.st_ino = 23;
buffer.st_mode = S_IFREG | 0754;
wfp_impl_respond_getattr(req, &buffer);
}
TEST(wfp_impl_getattr, respond_dir)
{
MockRequest request;
auto * req = request.create_request(42);
EXPECT_CALL(request, respond(StatMatcher(23, 0754, "dir"), 42)).Times(1);
struct stat buffer;
memset(&buffer, 0, sizeof(buffer));
buffer.st_ino = 23;
buffer.st_mode = S_IFDIR | 0754;
wfp_impl_respond_getattr(req, &buffer);
}
TEST(wfp_impl_getattr, invoke_provider)
{
ino_t inode = 23;
MockProvider provider;
EXPECT_CALL(provider,getattr(_, inode)).Times(1).WillOnce(Invoke(free_request));
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_integer(inode));
wfp_impl_getattr(&context, params, 42);
json_decref(params);
}
TEST(wfp_impl_getattr, fail_invalid_param_count)
{
MockProvider provider;
EXPECT_CALL(provider,getattr(_, _)).Times(0);
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
wfp_impl_getattr(&context, params, 42);
json_decref(params);
}
TEST(wfp_impl_getattr, fail_invalid_inode_type)
{
MockProvider provider;
EXPECT_CALL(provider,getattr(_, _)).Times(0);
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_string("42"));
wfp_impl_getattr(&context, params, 42);
json_decref(params);
}

View File

@ -1,129 +0,0 @@
#include "webfuse/provider/impl/operation/lookup.h"
#include "webfuse/mocks/mock_request.hpp"
#include "webfuse/mocks/mock_provider.hpp"
#include "webfuse/mocks/fake_invokation_context.hpp"
#include <gtest/gtest.h>
#include <cstdlib>
using ::webfuse_test::MockProvider;
using ::webfuse_test::MockRequest;
using ::webfuse_test::StatMatcher;
using ::webfuse_test::create_context;
using ::testing::_;
using ::testing::Invoke;
using ::testing::StrEq;
namespace
{
void free_request(wfp_request * request, ino_t, char const *)
{
free(request);
}
}
TEST(wfp_impl_lookup, invoke_provider)
{
ino_t inode = 42;
MockProvider provider;
EXPECT_CALL(provider,lookup(_, inode,StrEq("some.file"))).Times(1)
.WillOnce(Invoke(free_request));
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_integer(inode));
json_array_append_new(params, json_string("some.file"));
wfp_impl_lookup(&context, params, 42);
json_decref(params);
}
TEST(wfp_impl_lookup, fail_invalid_param_count)
{
MockProvider provider;
EXPECT_CALL(provider,lookup(_, _,_)).Times(0);
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_integer(23));
wfp_impl_lookup(&context, params, 42);
json_decref(params);
}
TEST(wfp_impl_lookup, fail_invalid_inode_type)
{
MockProvider provider;
EXPECT_CALL(provider,lookup(_, _,_)).Times(0);
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_string("23"));
json_array_append_new(params, json_string("some.file"));
wfp_impl_lookup(&context, params, 42);
json_decref(params);
}
TEST(wfp_impl_lookup, fail_invalid_name_type)
{
MockProvider provider;
EXPECT_CALL(provider,lookup(_, _,_)).Times(0);
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_integer(23));
json_array_append_new(params, json_integer(1));
wfp_impl_lookup(&context, params, 42);
json_decref(params);
}
TEST(wfp_impl_lookup, default_responds_error)
{
MockRequest request;
auto * req = request.create_request(42);
EXPECT_CALL(request, respond_error(_,42)).Times(1);
wfp_impl_lookup_default(req, 1, "some.file", nullptr);
}
TEST(wfp_impl_lookup, respond_file)
{
MockRequest request;
auto * req = request.create_request(42);
EXPECT_CALL(request, respond(StatMatcher(23, 0754, "file"), 42)).Times(1);
struct stat buffer;
memset(&buffer, 0, sizeof(buffer));
buffer.st_ino = 23;
buffer.st_mode = S_IFREG | 0754;
wfp_impl_respond_lookup(req, &buffer);
}
TEST(wfp_impl_lookup, respond_dir)
{
MockRequest request;
auto * req = request.create_request(42);
EXPECT_CALL(request, respond(StatMatcher(23, 0754, "dir"), 42)).Times(1);
struct stat buffer;
memset(&buffer, 0, sizeof(buffer));
buffer.st_ino = 23;
buffer.st_mode = S_IFDIR | 0754;
wfp_impl_respond_lookup(req, &buffer);
}

View File

@ -1,114 +0,0 @@
#include "webfuse/provider/impl/operation/open.h"
#include "webfuse/mocks/mock_request.hpp"
#include "webfuse/mocks/mock_provider.hpp"
#include "webfuse/mocks/fake_invokation_context.hpp"
#include <gtest/gtest.h>
#include <cstdlib>
using ::webfuse_test::MockProvider;
using ::webfuse_test::MockRequest;
using ::webfuse_test::OpenMatcher;
using ::webfuse_test::create_context;
using ::testing::_;
using ::testing::Invoke;
using ::testing::StrEq;
namespace
{
void free_request(wfp_request * request, ino_t, int)
{
free(request);
}
}
TEST(wfp_impl_open, invoke_provider)
{
ino_t inode = 42;
int flags = 0;
MockProvider provider;
EXPECT_CALL(provider,open(_, inode, flags)).Times(1)
.WillOnce(Invoke(free_request));
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_integer(inode));
json_array_append_new(params, json_integer(flags));
wfp_impl_open(&context, params, 42);
json_decref(params);
}
TEST(wfp_impl_open, fail_invalid_param_count)
{
MockProvider provider;
EXPECT_CALL(provider,open(_, _, _)).Times(0);
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_integer(23));
wfp_impl_open(&context, params, 42);
json_decref(params);
}
TEST(wfp_impl_open, fail_invalid_inode_type)
{
MockProvider provider;
EXPECT_CALL(provider,open(_, _, _)).Times(0);
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_string(""));
json_array_append_new(params, json_integer(0));
wfp_impl_open(&context, params, 42);
json_decref(params);
}
TEST(wfp_impl_open, fail_invalid_flags_type)
{
MockProvider provider;
EXPECT_CALL(provider,open(_, _, _)).Times(0);
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_integer(23));
json_array_append_new(params, json_string(""));
wfp_impl_open(&context, params, 42);
json_decref(params);
}
TEST(wfp_impl_open, default_responds_error)
{
MockRequest request;
auto * req = request.create_request(42);
EXPECT_CALL(request, respond_error(_,42)).Times(1);
wfp_impl_open_default(req, 1, 0, nullptr);
}
TEST(wfp_impl_open, respond)
{
MockRequest request;
auto * req = request.create_request(42);
EXPECT_CALL(request, respond(OpenMatcher(23), 42)).Times(1);
wfp_impl_respond_open(req, 23);
}

View File

@ -1,173 +0,0 @@
#include "webfuse/provider/impl/operation/read.h"
#include "webfuse/mocks/mock_request.hpp"
#include "webfuse/mocks/mock_provider.hpp"
#include "webfuse/mocks/fake_invokation_context.hpp"
#include <gtest/gtest.h>
#include <cstdlib>
using ::webfuse_test::MockProvider;
using ::webfuse_test::MockRequest;
using ::webfuse_test::ReadResultMatcher;
using ::webfuse_test::create_context;
using ::testing::_;
using ::testing::Invoke;
using ::testing::StrEq;
namespace
{
void free_request(wfp_request * request, ino_t, uint32_t, size_t ,size_t)
{
free(request);
}
}
TEST(wfp_impl_read, invoke_provider)
{
ino_t inode = 42;
uint32_t handle = 5;
size_t offset = 2;
size_t length = 1;
MockProvider provider;
EXPECT_CALL(provider, read(_, inode, handle, offset, length)).Times(1)
.WillOnce(Invoke(free_request));
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_integer(inode));
json_array_append_new(params, json_integer(handle));
json_array_append_new(params, json_integer(offset));
json_array_append_new(params, json_integer(length));
wfp_impl_read(&context, params, 42);
json_decref(params);
}
TEST(wfp_impl_read, fail_invalid_param_count)
{
MockProvider provider;
EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0);
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_integer(1));
json_array_append_new(params, json_integer(2));
json_array_append_new(params, json_integer(3));
json_array_append_new(params, json_integer(4));
json_array_append_new(params, json_integer(5));
wfp_impl_read(&context, params, 42);
json_decref(params);
}
TEST(wfp_impl_read, fail_invalid_inode_type)
{
MockProvider provider;
EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0);
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_string("42"));
json_array_append_new(params, json_integer(2));
json_array_append_new(params, json_integer(3));
json_array_append_new(params, json_integer(4));
wfp_impl_read(&context, params, 42);
json_decref(params);
}
TEST(wfp_impl_read, fail_invalid_handle_type)
{
MockProvider provider;
EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0);
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_integer(1));
json_array_append_new(params, json_string("42"));
json_array_append_new(params, json_integer(3));
json_array_append_new(params, json_integer(4));
wfp_impl_read(&context, params, 42);
json_decref(params);
}
TEST(wfp_impl_read, fail_invalid_offset_type)
{
MockProvider provider;
EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0);
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_integer(1));
json_array_append_new(params, json_integer(2));
json_array_append_new(params, json_string("42"));
json_array_append_new(params, json_integer(4));
wfp_impl_read(&context, params, 42);
json_decref(params);
}
TEST(wfp_impl_read, fail_invalid_length_type)
{
MockProvider provider;
EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0);
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_integer(1));
json_array_append_new(params, json_integer(2));
json_array_append_new(params, json_integer(3));
json_array_append_new(params, json_string("42"));
wfp_impl_read(&context, params, 42);
json_decref(params);
}
TEST(wfp_impl_read, default_responds_error)
{
MockRequest request;
auto * req = request.create_request(42);
EXPECT_CALL(request, respond_error(_,42)).Times(1);
wfp_impl_read_default(req, 0, 0, 1, 2, nullptr);
}
TEST(wfp_impl_read, respond)
{
MockRequest request;
auto * req = request.create_request(42);
EXPECT_CALL(request, respond(ReadResultMatcher("d2Y=", "base64", 2), 42)).Times(1);
char const data[] = "wf";
wfp_impl_respond_read(req, data, 2);
}
TEST(wfp_impl_read, respond_empty)
{
MockRequest request;
auto * req = request.create_request(42);
EXPECT_CALL(request, respond(ReadResultMatcher("", "identity", 0), 42)).Times(1);
wfp_impl_respond_read(req, nullptr, 0);
}

View File

@ -1,100 +0,0 @@
#include "webfuse/provider/impl/operation/readdir.h"
#include "webfuse/mocks/mock_request.hpp"
#include "webfuse/mocks/mock_provider.hpp"
#include "webfuse/mocks/fake_invokation_context.hpp"
#include "webfuse/provider/dirbuffer.h"
#include <gtest/gtest.h>
#include <cstdlib>
using ::webfuse_test::MockProvider;
using ::webfuse_test::MockRequest;
using ::webfuse_test::ReaddirMatcher;
using ::webfuse_test::create_context;
using ::testing::_;
using ::testing::Invoke;
namespace
{
void free_request(wfp_request * request, ino_t)
{
free(request);
}
}
TEST(wfp_impl_readdir, invoke_provider)
{
ino_t inode = 23;
MockProvider provider;
EXPECT_CALL(provider,readdir(_, inode)).Times(1).WillOnce(Invoke(free_request));
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_integer(inode));
wfp_impl_readdir(&context, params, 42);
json_decref(params);
}
TEST(wfp_impl_readdir, fail_invalid_param_count)
{
MockProvider provider;
EXPECT_CALL(provider,readdir(_, _)).Times(0);
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_integer(1));
json_array_append_new(params, json_integer(1));
wfp_impl_readdir(&context, params, 42);
json_decref(params);
}
TEST(wfp_impl_readdir, fail_invalid_inode_type)
{
MockProvider provider;
EXPECT_CALL(provider,readdir(_, _)).Times(0);
wfp_request request = {nullptr, nullptr, 0};
wfp_impl_invokation_context context = create_context(provider, &request);
json_t * params = json_array();
json_array_append_new(params, json_string("test.filesystem"));
json_array_append_new(params, json_string("1"));
wfp_impl_readdir(&context, params, 42);
json_decref(params);
}
TEST(wfp_impl_readdir, default_responds_error)
{
MockRequest request;
auto * req = request.create_request(42);
EXPECT_CALL(request, respond_error(_,42)).Times(1);
wfp_impl_readdir_default(req, 0, nullptr);
}
TEST(wfp_impl_readdir, respond)
{
char const item0[] = "some.file";
char const * items[] = { item0, nullptr };
MockRequest request;
auto * req = request.create_request(42);
EXPECT_CALL(request, respond(ReaddirMatcher(items), 42)).Times(1);
wfp_dirbuffer * buffer = wfp_dirbuffer_create();
wfp_dirbuffer_add(buffer, item0, 42);
wfp_impl_respond_readdir(req, buffer);
wfp_dirbuffer_dispose(buffer);
}

View File

@ -1,268 +0,0 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <webfuse/provider/client_protocol.h>
#include <webfuse/provider/client_config.h>
#include "webfuse/utils/ws_server.h"
#include "webfuse/mocks/mock_provider_client.hpp"
#include "webfuse/core/protocol_names.h"
#include "webfuse/utils/timeout_watcher.hpp"
#include <libwebsockets.h>
#include <cstring>
#include <thread>
#include <atomic>
using webfuse_test::WsServer;
using webfuse_test::MockProviderClient;
using webfuse_test::IProviderClient;
using webfuse_test::TimeoutWatcher;
using testing::_;
using testing::AtMost;
using testing::Invoke;
#define DEFAULT_TIMEOUT (std::chrono::milliseconds(5 * 1000))
namespace
{
class ClientProtocolFixture
{
ClientProtocolFixture(ClientProtocolFixture const &) = delete;
ClientProtocolFixture& operator=(ClientProtocolFixture const &) = delete;
public:
explicit ClientProtocolFixture(IProviderClient& client, bool enableAuthentication = false)
{
server = new WsServer(WF_PROTOCOL_NAME_ADAPTER_SERVER);
config = wfp_client_config_create();
client.AttachTo(config, enableAuthentication);
protocol = wfp_client_protocol_create(config);
memset(protocols, 0, sizeof(struct lws_protocols) * 2);
wfp_client_protocol_init_lws(protocol, protocols);
memset(&info, 0, sizeof(struct lws_context_creation_info));
info.port = CONTEXT_PORT_NO_LISTEN;
info.protocols = protocols;
info.uid = -1;
info.gid = -1;
context = lws_create_context(&info);
}
~ClientProtocolFixture()
{
lws_context_destroy(context);
wfp_client_protocol_dispose(protocol);
wfp_client_config_dispose(config);
delete server;
}
void Connect()
{
TimeoutWatcher watcher(DEFAULT_TIMEOUT);
wfp_client_protocol_connect(protocol, context, server->GetUrl().c_str());
while (!server->IsConnected())
{
watcher.check();
lws_service(context, 0);
}
}
void Disconnect()
{
wfp_client_protocol_disconnect(protocol);
}
void SendToClient(json_t * request)
{
server->SendMessage(request);
}
json_t * ReceiveMessageFromClient()
{
TimeoutWatcher watcher(DEFAULT_TIMEOUT);
json_t * result = server->ReceiveMessage();
while (nullptr == result)
{
watcher.check();
lws_service(context, 0);
result = server->ReceiveMessage();
}
return result;
}
void AwaitAuthentication(
std::string const & expected_username,
std::string const & expected_password)
{
json_t * request = ReceiveMessageFromClient();
ASSERT_TRUE(json_is_object(request));
json_t * method = json_object_get(request, "method");
ASSERT_TRUE(json_is_string(method));
ASSERT_STREQ("authenticate", json_string_value(method));
json_t * id = json_object_get(request, "id");
ASSERT_TRUE(json_is_integer(id));
json_t * params = json_object_get(request, "params");
ASSERT_TRUE(json_is_array(params));
ASSERT_EQ(2, json_array_size(params));
json_t * type = json_array_get(params, 0);
ASSERT_TRUE(json_is_string(type));
ASSERT_STREQ("username", json_string_value(type));
json_t * credentials = json_array_get(params, 1);
ASSERT_TRUE(json_is_object(credentials));
json_t * username = json_object_get(credentials, "username");
ASSERT_TRUE(json_is_string(username));
ASSERT_STREQ(expected_username.c_str(), json_string_value(username));
json_t * password = json_object_get(credentials, "password");
ASSERT_TRUE(json_is_string(password));
ASSERT_STREQ(expected_password.c_str(), json_string_value(password));
json_t * response = json_object();
json_object_set_new(response, "result", json_object());
json_object_set(response, "id", id);
SendToClient(response);
json_decref(request);
}
void AwaitAddFilesystem(std::string& filesystemName)
{
json_t * addFilesystemRequest = ReceiveMessageFromClient();
ASSERT_NE(nullptr, addFilesystemRequest);
ASSERT_TRUE(json_is_object(addFilesystemRequest));
json_t * method = json_object_get(addFilesystemRequest, "method");
ASSERT_TRUE(json_is_string(method));
ASSERT_STREQ("add_filesystem", json_string_value(method));
json_t * params = json_object_get(addFilesystemRequest, "params");
ASSERT_TRUE(json_is_array(params));
ASSERT_EQ(1, json_array_size(params));
json_t * filesystem = json_array_get(params, 0);
ASSERT_TRUE(json_is_string(filesystem));
filesystemName = json_string_value(filesystem);
json_t * id = json_object_get(addFilesystemRequest, "id");
ASSERT_TRUE(json_is_integer(id));
json_t * response = json_object();
json_t * result = json_object();
json_object_set(result, "id", filesystem);
json_object_set_new(response, "result", result);
json_object_set(response, "id", id);
SendToClient(response);
json_decref(addFilesystemRequest);
}
private:
WsServer * server;
wfp_client_config * config;
wfp_client_protocol * protocol;
struct lws_context_creation_info info;
struct lws_protocols protocols[2];
struct lws_context * context;
};
void GetCredentials(wfp_credentials * credentials)
{
wfp_credentials_set_type(credentials, "username");
wfp_credentials_add(credentials, "username", "bob");
wfp_credentials_add(credentials, "password", "secret");
}
}
TEST(client_protocol, connect)
{
MockProviderClient provider;
ClientProtocolFixture fixture(provider);
EXPECT_CALL(provider, OnConnected()).Times(AtMost(1));
EXPECT_CALL(provider, OnDisconnected()).Times(1);
fixture.Connect();
if (HasFatalFailure()) { return; }
std::string filesystem;
fixture.AwaitAddFilesystem(filesystem);
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;
ClientProtocolFixture fixture(provider, true);
EXPECT_CALL(provider, OnConnected()).Times(AtMost(1));
EXPECT_CALL(provider, OnDisconnected()).Times(1);
EXPECT_CALL(provider, GetCredentials(_)).Times(1).WillOnce(Invoke(GetCredentials));
fixture.Connect();
if (HasFatalFailure()) { return; }
fixture.AwaitAuthentication("bob", "secret");
if (HasFatalFailure()) { return; }
std::string filesystem;
fixture.AwaitAddFilesystem(filesystem);
if (HasFatalFailure()) { return; }
}
TEST(client_protocol, getattr)
{
MockProviderClient provider;
ClientProtocolFixture fixture(provider);
EXPECT_CALL(provider, OnConnected()).Times(1);
EXPECT_CALL(provider, OnDisconnected()).Times(1);
EXPECT_CALL(provider, GetAttr(1, _)).Times(1);
fixture.Connect();
if (HasFatalFailure()) { return; }
std::string filesystem;
fixture.AwaitAddFilesystem(filesystem);
if (HasFatalFailure()) { return; }
json_t * params = json_array();
json_array_append_new(params, json_string(filesystem.c_str()));
json_array_append_new(params, json_integer(1));
json_t * request = json_object();
json_object_set_new(request, "method", json_string("getattr"));
json_object_set_new(request, "params", params);
json_object_set_new(request, "id", json_integer(42));
fixture.SendToClient(request);
json_t * response = fixture.ReceiveMessageFromClient();
ASSERT_TRUE(json_is_object(response));
json_decref(response);
fixture.Disconnect();
}

View File

@ -1,32 +0,0 @@
#include "webfuse/provider/impl/dirbuffer.h"
#include <gtest/gtest.h>
TEST(DirBuffer, CreateDispose)
{
wfp_dirbuffer * buffer = wfp_impl_dirbuffer_create();
wfp_impl_dirbuffer_dispose(buffer);
}
TEST(DirBuffer, Add)
{
wfp_dirbuffer * buffer = wfp_impl_dirbuffer_create();
wfp_impl_dirbuffer_add(buffer, "answer", 42);
ASSERT_EQ(1, json_array_size(buffer->entries));
json_t * entry = json_array_get(buffer->entries, 0);
ASSERT_STREQ("answer", json_string_value(json_object_get(entry, "name")));
ASSERT_EQ(42, json_integer_value(json_object_get(entry, "inode")));
wfp_impl_dirbuffer_dispose(buffer);
}
TEST(DirBuffer, Take)
{
wfp_dirbuffer * buffer = wfp_impl_dirbuffer_create();
json_t * entries = wfp_impl_dirbuffer_take(buffer);
wfp_impl_dirbuffer_dispose(buffer);
ASSERT_TRUE(json_is_array(entries));
json_decref(entries);
}

View File

@ -1,113 +0,0 @@
#include "webfuse/utils/path.h"
#include <stdlib.h>
#include <string.h>
#define WF_PATH_DEFAULT_CAPACITY (8)
struct wf_path
{
char * * elements;
size_t count;
size_t capacity;
};
static void
wf_path_add(
struct wf_path * path,
char const * element,
size_t element_size)
{
if (0 < element_size)
{
if (path->count >= path->capacity)
{
size_t new_capacity = 2 * path->capacity;
size_t new_size = sizeof(char*) * new_capacity;
char * * elements = realloc(path->elements, new_size);
if (NULL != elements)
{
path->elements = elements;
path->capacity = new_capacity;
}
}
if (path->count < path->capacity)
{
path->elements[path->count] = strndup(element, element_size);
path->count++;
}
}
}
struct wf_path *
wf_path_create(
char const * value)
{
struct wf_path * path = malloc(sizeof(struct wf_path));
path->elements = malloc(sizeof(char*) * WF_PATH_DEFAULT_CAPACITY);
path->capacity = WF_PATH_DEFAULT_CAPACITY;
path->count = 0;
char const * remainder = value;
char const * pos = strchr(remainder, '/');
while (NULL != pos)
{
wf_path_add(path, remainder, (pos - remainder));
remainder = pos + 1;
pos = strchr(remainder, '/');
}
wf_path_add(path, remainder, strlen(remainder));
return path;
}
void
wf_path_dispose(
struct wf_path * path)
{
for(size_t i = 0; i < path->count; i++)
{
free(path->elements[i]);
}
free(path->elements);
free(path);
(void) path;
}
size_t
wf_path_element_count(
struct wf_path * path)
{
return path->count;
}
char const *
wf_path_get_element(
struct wf_path * path,
size_t i)
{
char const * result = NULL;
if (i < path->count)
{
result = path->elements[i];
}
return result;
}
char const *
wf_path_get_filename(
struct wf_path * path)
{
char const * result = NULL;
if (0 < path->count)
{
result = path->elements[path->count - 1];
}
return result;
}

View File

@ -1,43 +0,0 @@
#ifndef WF_PATH_H
#define WF_PATH_H
#ifndef __cplusplus
#include <stddef.h>
#else
#include <cstddef>
using ::std::size_t;
#endif
#ifdef __cplusplus
extern "C"
{
#endif
struct wf_path;
extern struct wf_path *
wf_path_create(
char const * value);
extern void
wf_path_dispose(
struct wf_path * path);
extern size_t
wf_path_element_count(
struct wf_path * path);
extern char const *
wf_path_get_element(
struct wf_path * path,
size_t i);
extern char const *
wf_path_get_filename(
struct wf_path * path);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,421 +0,0 @@
#include "webfuse/utils/static_filesystem.h"
#include "webfuse/provider/client_config.h"
#include "webfuse/provider/dirbuffer.h"
#include "webfuse/provider/operation/error.h"
#include "webfuse/utils/path.h"
#include "webfuse/core/util.h"
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#define WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY (16)
#define WFP_STATIC_FILSYSTEM_INODE_ROOT (1)
#define WFP_STATIC_FILESYSTEM_MAX_READ_SIZE (4 * 1024)
struct wfp_static_filesystem_entry
{
size_t inode;
size_t parent;
char * name;
bool is_file;
int mode;
size_t size;
char * content;
wfp_static_filesystem_read_fn * read;
wfp_static_filesystem_get_info_fn * get_info;
void * user_data;
};
struct wfp_static_filesystem
{
struct wfp_static_filesystem_entry * entries;
size_t size;
size_t capacity;
void * user_data;
};
static struct wfp_static_filesystem_entry *
wfp_static_filesystem_get_entry(
struct wfp_static_filesystem * filesystem,
size_t inode)
{
struct wfp_static_filesystem_entry * entry = NULL;
if ((0 < inode) && (inode <= filesystem->size))
{
entry = &filesystem->entries[inode - 1];
}
return entry;
}
static struct wfp_static_filesystem_entry *
wfp_static_filesystem_get_entry_by_name(
struct wfp_static_filesystem * filesystem,
size_t parent,
char const * name)
{
struct wfp_static_filesystem_entry * entry = NULL;
for(size_t i = 0; i < filesystem->size; i++)
{
struct wfp_static_filesystem_entry * current = &filesystem->entries[i];
if ((parent == current->parent) && (0 == strcmp(name, current->name)))
{
entry = current;
break;
}
}
return entry;
}
static struct wfp_static_filesystem_entry *
wfp_static_filesystem_add_entry(
struct wfp_static_filesystem * filesystem)
{
struct wfp_static_filesystem_entry * entry = NULL;
if (filesystem->size >= filesystem->capacity)
{
struct wfp_static_filesystem_entry * entries;
size_t new_capacity = 2 * filesystem->capacity;
size_t new_size = new_capacity * sizeof(struct wfp_static_filesystem_entry);
entries = realloc(filesystem->entries, new_size);
if (NULL != entries)
{
filesystem->entries = entries;
filesystem->capacity = new_capacity;
}
}
if (filesystem->size < filesystem->capacity)
{
entry = &filesystem->entries[filesystem->size];
entry->inode = filesystem->size + 1;
filesystem->size++;
}
return entry;
}
static size_t
wfp_static_filesystem_entry_read(
size_t offset,
char * buffer,
size_t buffer_size,
void * user_data)
{
size_t result = 0;
struct wfp_static_filesystem_entry * entry = user_data;
if (offset < entry->size)
{
size_t remaining = (entry->size - offset);
result = (buffer_size < remaining) ? buffer_size : remaining;
memcpy(buffer, entry->content, result);
}
return result;
}
static void
wfp_static_filesystem_entry_get_info(
void * user_data,
int * result_mode,
size_t * result_size)
{
struct wfp_static_filesystem_entry * entry = user_data;
*result_mode = entry->mode;
*result_size = entry->size;
}
static size_t
wfp_static_filesystem_add_dir(
struct wfp_static_filesystem * filesystem,
size_t parent,
char const * name
)
{
struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry_by_name(filesystem, parent, name);
if (NULL == entry)
{
entry = wfp_static_filesystem_add_entry(filesystem);
entry->parent = parent;
entry->is_file = false;
entry->mode = 0555;
entry->name = strdup(name);
entry->user_data = entry;
entry->read = &wfp_static_filesystem_entry_read;
entry->get_info = &wfp_static_filesystem_entry_get_info;
entry->size = 0;
entry->content = NULL;
}
return entry->inode;
}
static size_t
wfp_static_filesystem_make_parent(
struct wfp_static_filesystem * filesystem,
struct wf_path * path)
{
size_t result = WFP_STATIC_FILSYSTEM_INODE_ROOT;
size_t count = wf_path_element_count(path);
if (0 < count)
{
for(size_t i = 0; i < (count - 1); i++)
{
char const * name = wf_path_get_element(path, i);
result = wfp_static_filesystem_add_dir(filesystem, result, name);
}
}
return result;
}
static void
wfp_static_filesystem_stat(
struct wfp_static_filesystem_entry * entry,
struct stat * stat
)
{
memset(stat, 0, sizeof(struct stat));
int mode;
size_t size;
entry->get_info(entry->user_data, &mode, &size);
stat->st_ino = entry->inode;
stat->st_size = entry->size;
stat->st_mode = entry->mode & 0777;
stat->st_mode |= (entry->is_file) ? S_IFREG: S_IFDIR;
}
static void wfp_static_filesystem_lookup(
struct wfp_request * request,
ino_t parent,
char const * name,
void * user_data)
{
struct wfp_static_filesystem * filesystem = user_data;
struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry_by_name(filesystem, parent, name);
if (NULL != entry)
{
struct stat stat;
wfp_static_filesystem_stat(entry, &stat);
wfp_respond_lookup(request, &stat);
}
else
{
wfp_respond_error(request, WF_BAD_NOENTRY);
}
}
static void wfp_static_filesystem_getattr(
struct wfp_request * request,
ino_t inode,
void * user_data)
{
struct wfp_static_filesystem * filesystem = user_data;
struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry(filesystem, inode);
if (NULL != entry)
{
struct stat stat;
wfp_static_filesystem_stat(entry, &stat);
wfp_respond_getattr(request, &stat);
}
else
{
wfp_respond_error(request, WF_BAD_NOENTRY);
}
}
static void wfp_static_filesystem_readdir(
struct wfp_request * request,
ino_t directory,
void * user_data)
{
struct wfp_static_filesystem * filesystem = user_data;
struct wfp_static_filesystem_entry * dir = wfp_static_filesystem_get_entry(filesystem, directory);
if ((NULL != dir) && (!dir->is_file))
{
struct wfp_dirbuffer * buffer = wfp_dirbuffer_create();
wfp_dirbuffer_add(buffer, ".", dir->inode);
wfp_dirbuffer_add(buffer, "..", dir->inode);
for(size_t i = 0; i < filesystem->size; i++)
{
struct wfp_static_filesystem_entry const * entry = &filesystem->entries[i];
if (directory == entry->parent)
{
wfp_dirbuffer_add(buffer, entry->name, entry->inode);
}
}
wfp_respond_readdir(request, buffer);
wfp_dirbuffer_dispose(buffer);
}
else
{
wfp_respond_error(request, WF_BAD_NOENTRY);
}
}
static void wfp_static_filesystem_open(
struct wfp_request * request,
ino_t inode,
int flags,
void * user_data)
{
struct wfp_static_filesystem * filesystem = user_data;
struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry(filesystem, inode);
if ((NULL != entry) && (entry->is_file))
{
if (O_RDONLY == (flags & O_ACCMODE))
{
wfp_respond_open(request, 0U);
}
else
{
wfp_respond_error(request, WF_BAD_ACCESS_DENIED);
}
}
else
{
wfp_respond_error(request, WF_BAD_NOENTRY);
}
}
static void wfp_static_filesystem_read(
struct wfp_request * request,
ino_t inode,
uint32_t WF_UNUSED_PARAM(handle),
size_t offset,
size_t length,
void * user_data)
{
struct wfp_static_filesystem * filesystem = user_data;
struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry(filesystem, inode);
if ((NULL != entry) && (entry->is_file))
{
char buffer[WFP_STATIC_FILESYSTEM_MAX_READ_SIZE];
size_t max_size = (length < WFP_STATIC_FILESYSTEM_MAX_READ_SIZE) ? length : WFP_STATIC_FILESYSTEM_MAX_READ_SIZE;
size_t count = entry->read(offset, buffer, max_size, entry->user_data);
wfp_respond_read(request, buffer, count);
}
else
{
wfp_respond_error(request, WF_BAD_NOENTRY);
}
}
struct wfp_static_filesystem *
wfp_static_filesystem_create(
struct wfp_client_config * config)
{
(void) config;
struct wfp_static_filesystem * filesystem = malloc(sizeof(struct wfp_static_filesystem));
filesystem->entries = malloc(sizeof(struct wfp_static_filesystem_entry) * WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY);
filesystem->size = 0;
filesystem->capacity = WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY;
filesystem->user_data = NULL;
wfp_static_filesystem_add_dir(filesystem, 0, "<root>");
wfp_client_config_set_userdata(config, filesystem);
wfp_client_config_set_onlookup(config, &wfp_static_filesystem_lookup);
wfp_client_config_set_ongetattr(config, &wfp_static_filesystem_getattr);
wfp_client_config_set_onreaddir(config, &wfp_static_filesystem_readdir);
wfp_client_config_set_onopen(config, &wfp_static_filesystem_open);
wfp_client_config_set_onread(config, &wfp_static_filesystem_read);
return filesystem;
}
void
wfp_static_filesystem_dispose(
struct wfp_static_filesystem * filesystem)
{
for(size_t i = 0; i < filesystem->size; i++)
{
struct wfp_static_filesystem_entry * entry = &filesystem->entries[i];
free(entry->name);
free(entry->content);
}
free(filesystem->entries);
free(filesystem);
}
void
wfp_static_filesystem_add(
struct wfp_static_filesystem * filesystem,
char const * path,
int mode,
char const * content,
size_t length)
{
struct wf_path * path_ = wf_path_create(path);
if (NULL != path_)
{
size_t parent = wfp_static_filesystem_make_parent(filesystem, path_);
struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_add_entry(filesystem);
entry->parent = parent;
entry->is_file = true;
entry->name = strdup(wf_path_get_filename(path_));
entry->mode = mode;
entry->size = length;
entry->get_info = &wfp_static_filesystem_entry_get_info;
entry->read = &wfp_static_filesystem_entry_read;
entry->user_data = entry;
entry->content = malloc(length);
memcpy(entry->content, content, length);
wf_path_dispose(path_);
}
}
void
wfp_static_filesystem_add_text(
struct wfp_static_filesystem * filesystem,
char const * path,
int mode,
char const * content)
{
size_t length = strlen(content);
wfp_static_filesystem_add(filesystem, path, mode, content, length);
}
void
wfp_static_filesystem_set_user_data(
struct wfp_static_filesystem * filesystem,
void * user_data)
{
filesystem->user_data = user_data;
}
void *
wfp_static_filesystem_get_user_data(
struct wfp_static_filesystem * filesystem)
{
return filesystem->user_data;
}

View File

@ -1,72 +0,0 @@
#ifndef WFP_STATIC_FILESYSTEM_H
#define WFP_STATIC_FILESYSTEM_H
#ifndef __cplusplus
#include <stddef.h>
#else
#include <cstddef>
using ::std::size_t;
#endif
#include <webfuse/provider/api.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_client_config;
struct wfp_static_filesystem;
typedef size_t
wfp_static_filesystem_read_fn(
size_t offset,
char * buffer,
size_t buffer_size,
void * user_data);
typedef void
wfp_static_filesystem_get_info_fn(
void * user_data,
int * result_mode,
size_t * result_size);
extern WFP_API struct wfp_static_filesystem *
wfp_static_filesystem_create(
struct wfp_client_config * config);
extern WFP_API void
wfp_static_filesystem_dispose(
struct wfp_static_filesystem * filesystem);
extern WFP_API void
wfp_static_filesystem_add(
struct wfp_static_filesystem * filesystem,
char const * path,
int mode,
char const * content,
size_t length);
extern WFP_API void
wfp_static_filesystem_add_text(
struct wfp_static_filesystem * filesystem,
char const * path,
int mode,
char const * content);
extern void
wfp_static_filesystem_set_user_data(
struct wfp_static_filesystem * filesystem,
void * user_data);
extern void *
wfp_static_filesystem_get_user_data(
struct wfp_static_filesystem * filesystem);
#ifdef __cplusplus
}
#endif
#endif