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

88 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-16 20:09:35 +00:00
wf_slist_init(&manager->sessions);
2019-03-26 22:04:53 +00:00
}
void wf_impl_session_manager_cleanup(
struct wf_impl_session_manager * manager)
{
2019-04-16 20:09:35 +00:00
struct wf_slist_item * item = manager->sessions.first;
while (NULL != item)
{
struct wf_slist_item * next = item->next;
struct wf_impl_session * session = WF_CONTAINER_OF(item, struct wf_impl_session, item);
wf_impl_session_dispose(session);
item = next;
}
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-16 20:09:35 +00:00
wf_slist_append(&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-16 20:09:35 +00:00
struct wf_slist_item * item = manager->sessions.first;
while (NULL != item)
2019-03-26 22:04:53 +00:00
{
2019-04-16 20:09:35 +00:00
struct wf_slist_item * next = item->next;
struct wf_impl_session * current = WF_CONTAINER_OF(item, struct wf_impl_session, item);
2019-03-26 22:04:53 +00:00
2019-04-16 20:09:35 +00:00
if (wf_impl_session_contains_wsi(current, wsi)) {
session = current;
break;
}
2019-03-26 22:04:53 +00:00
2019-04-16 20:09:35 +00:00
item = next;
}
2019-04-09 20:54:41 +00:00
2019-04-16 20:09:35 +00:00
return session;
2019-04-09 20:54:41 +00:00
}
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-16 20:09:35 +00:00
struct wf_slist_item * item = manager->sessions.first;
struct wf_slist_item * prev = NULL;
while (NULL != item)
2019-03-26 22:04:53 +00:00
{
2019-04-16 20:09:35 +00:00
struct wf_slist_item * next = item->next;
struct wf_impl_session * session = WF_CONTAINER_OF(item, struct wf_impl_session, item);
if (wsi == session->wsi)
{
wf_slist_remove_after(&manager->sessions, prev);
wf_impl_session_dispose(session);
break;
}
prev = item;
item = next;
2019-03-26 22:04:53 +00:00
}
}