1
0
mirror of https://github.com/falk-werner/webfuse synced 2025-06-13 12:54:15 +00:00
falk-werner_webfuse/lib/webfuse/adapter/impl/session_manager.c

87 lines
2.4 KiB
C
Raw Normal View History

2019-03-26 22:04:53 +00:00
#include "webfuse/adapter/impl/session_manager.h"
#include "webfuse/core/util.h"
2019-04-09 20:54:41 +00:00
#include "webfuse/core/container_of.h"
2019-03-26 22:04:53 +00:00
#include <stddef.h>
void wf_impl_session_manager_init(
struct wf_impl_session_manager * manager)
{
2019-04-09 20:54:41 +00:00
wf_dlist_init(&manager->sessions);
2019-03-26 22:04:53 +00:00
}
2019-04-09 20:54:41 +00:00
static void wf_impl_session_manager_cleanup_session(
struct wf_dlist_item * item,
void * user_data)
{
(void) user_data;
struct wf_impl_session * session = WF_CONTAINER_OF(item, struct wf_impl_session, item);
wf_impl_session_dispose(session);
}
2019-03-26 22:04:53 +00:00
void wf_impl_session_manager_cleanup(
struct wf_impl_session_manager * manager)
{
2019-04-09 20:54:41 +00:00
wf_dlist_cleanup(&manager->sessions, &wf_impl_session_manager_cleanup_session, NULL);
2019-03-26 22:04:53 +00:00
}
struct wf_impl_session * wf_impl_session_manager_add(
struct wf_impl_session_manager * manager,
struct lws * wsi,
struct wf_impl_authenticators * authenticators,
struct wf_impl_timeout_manager * timeout_manager,
2019-04-02 21:00:03 +00:00
struct wf_impl_jsonrpc_server * server,
2019-04-13 19:44:53 +00:00
char const * mount_point)
2019-03-26 22:04:53 +00:00
{
2019-04-09 20:54:41 +00:00
struct wf_impl_session * session = wf_impl_session_create(
2019-04-13 19:44:53 +00:00
wsi, authenticators, timeout_manager, server, mount_point);
2019-04-09 20:54:41 +00:00
if (NULL != session)
2019-03-26 22:04:53 +00:00
{
2019-04-09 20:54:41 +00:00
wf_dlist_prepend(&manager->sessions, &session->item);
2019-03-26 22:04:53 +00:00
}
return session;
}
struct wf_impl_session * wf_impl_session_manager_get(
struct wf_impl_session_manager * manager,
struct lws * wsi)
{
struct wf_impl_session * session = NULL;
2019-04-09 20:54:41 +00:00
struct wf_dlist_item * item = wf_dlist_find_first(
2019-04-13 19:44:53 +00:00
&manager->sessions, &wf_impl_session_contains_wsi, wsi);
2019-04-09 20:54:41 +00:00
if (NULL != item)
2019-03-26 22:04:53 +00:00
{
2019-04-09 20:54:41 +00:00
session = WF_CONTAINER_OF(item, struct wf_impl_session, item);
2019-03-26 22:04:53 +00:00
}
return session;
}
2019-04-09 20:54:41 +00:00
static bool wf_impl_session_manager_remove_predicate(
struct wf_dlist_item * item,
void * user_data)
{
struct lws * wsi = user_data;
struct wf_impl_session * session = WF_CONTAINER_OF(item, struct wf_impl_session, item);
return (wsi == session->wsi);
}
2019-03-26 22:04:53 +00:00
void wf_impl_session_manager_remove(
struct wf_impl_session_manager * manager,
struct lws * wsi)
{
2019-04-09 20:54:41 +00:00
struct wf_impl_session * session = NULL;
struct wf_dlist_item * item = wf_dlist_find_first(
&manager->sessions, &wf_impl_session_manager_remove_predicate, wsi);
if (NULL != item)
2019-03-26 22:04:53 +00:00
{
2019-04-09 20:54:41 +00:00
wf_dlist_remove(&manager->sessions, item);
session = WF_CONTAINER_OF(item, struct wf_impl_session, item);
wf_impl_session_dispose(session);
2019-03-26 22:04:53 +00:00
}
}