mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
48185776b6
* makes wsfs_server_config opaque * feature: try to create mount point, if not present * fixes server start failure due to existing mountpoint * added basic authentication infrastructure * makes wsfs_server_config opaque * feature: try to create mount point, if not present * fixes server start failure due to existing mountpoint * added basic authentication infrastructure * added unit tests for credentials * added unit tests for authenticators * propagates authenticators to server protocol * enabled username authentication in daemon example * adds example to compute password hash * adds infrastructure to execute commands * added userdb to encapsulate authentication stuff * adds session and session_manager * fixes warning about unused param * moves some logic from server_protocol to session * makes wsfs_server_config opaque * feature: try to create mount point, if not present * fixes server start failure due to existing mountpoint * added basic authentication infrastructure * makes wsfs_server_config opaque * added unit tests for credentials * added unit tests for authenticators * propagates authenticators to server protocol * enabled username authentication in daemon example * adds example to compute password hash * adds infrastructure to execute commands * added userdb to encapsulate authentication stuff * adds session and session_manager * fixes warning about unused param * moves some logic from server_protocol to session * updates libcrypto to version 1.1.0
84 lines
2.1 KiB
C
84 lines
2.1 KiB
C
#include "wsfs/adapter/session.h"
|
|
#include "wsfs/adapter/authenticators.h"
|
|
#include "wsfs/message_queue.h"
|
|
#include "wsfs/message.h"
|
|
#include "wsfs/adapter/jsonrpc/server.h"
|
|
|
|
#include <libwebsockets.h>
|
|
#include <stddef.h>
|
|
|
|
void wsfs_session_init(
|
|
struct wsfs_session * session,
|
|
struct lws * wsi,
|
|
struct wsfs_authenticators * authenticators,
|
|
struct wsfs_jsonrpc_server * rpc)
|
|
{
|
|
session->wsi = wsi;
|
|
session->is_authenticated = false;
|
|
session->authenticators = authenticators;
|
|
session->rpc = rpc;
|
|
wsfs_message_queue_init(&session->queue);
|
|
}
|
|
|
|
void wsfs_session_cleanup(
|
|
struct wsfs_session * session)
|
|
{
|
|
wsfs_message_queue_cleanup(&session->queue);
|
|
session->is_authenticated = false;
|
|
session->wsi = NULL;
|
|
session->authenticators = NULL;
|
|
session->rpc = NULL;
|
|
}
|
|
|
|
void wsfs_session_authenticate(
|
|
struct wsfs_session * session,
|
|
struct wsfs_credentials * creds)
|
|
{
|
|
session->is_authenticated = wsfs_authenticators_authenticate(session->authenticators, creds);
|
|
}
|
|
|
|
bool wsfs_session_send(
|
|
struct wsfs_session * session,
|
|
struct wsfs_message * message)
|
|
{
|
|
bool result = (session->is_authenticated) && (NULL != session->wsi);
|
|
|
|
if (result)
|
|
{
|
|
wsfs_message_queue_push(&session->queue, message);
|
|
lws_callback_on_writable(session->wsi);
|
|
|
|
result = true;
|
|
}
|
|
else
|
|
{
|
|
wsfs_message_dispose(message);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
void wsfs_session_onwritable(
|
|
struct wsfs_session * session)
|
|
{
|
|
if (!wsfs_message_queue_empty(&session->queue))
|
|
{
|
|
struct wsfs_message * message = wsfs_message_queue_pop(&session->queue);
|
|
lws_write(session->wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT);
|
|
wsfs_message_dispose(message);
|
|
|
|
if (!wsfs_message_queue_empty(&session->queue))
|
|
{
|
|
lws_callback_on_writable(session->wsi);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void wsfs_session_receive(
|
|
struct wsfs_session * session,
|
|
char const * data,
|
|
size_t length)
|
|
{
|
|
wsfs_jsonrpc_server_onresult(session->rpc, data, length);
|
|
} |