2020-06-28 13:51:34 +00:00
|
|
|
#include "webfuse/impl/session_manager.h"
|
2020-06-28 17:43:08 +00:00
|
|
|
#include "webfuse/impl/util/util.h"
|
|
|
|
#include "webfuse/impl/util/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)
|
|
|
|
{
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_slist_init(&manager->sessions);
|
2019-03-26 22:04:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wf_impl_session_manager_cleanup(
|
|
|
|
struct wf_impl_session_manager * manager)
|
|
|
|
{
|
2020-06-28 17:43:08 +00:00
|
|
|
struct wf_slist_item * item = wf_impl_slist_first(&manager->sessions);
|
2019-04-17 20:51:16 +00:00
|
|
|
while (NULL != item)
|
|
|
|
{
|
|
|
|
struct wf_slist_item * next = item->next;
|
2019-04-25 18:08:34 +00:00
|
|
|
struct wf_impl_session * session = wf_container_of(item, struct wf_impl_session, item);
|
2019-04-17 20:51:16 +00:00
|
|
|
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,
|
2020-02-16 20:03:17 +00:00
|
|
|
struct wf_impl_mountpoint_factory * mountpoint_factory,
|
2020-02-29 20:06:40 +00:00
|
|
|
struct wf_timer_manager * timer_manager,
|
2020-03-01 15:55:58 +00:00
|
|
|
struct wf_jsonrpc_server * server)
|
2019-03-26 22:04:53 +00:00
|
|
|
{
|
2019-04-17 20:51:16 +00:00
|
|
|
struct wf_impl_session * session = wf_impl_session_create(
|
2020-02-29 20:06:40 +00:00
|
|
|
wsi, authenticators, timer_manager, server, mountpoint_factory);
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_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;
|
|
|
|
|
2020-06-28 17:43:08 +00:00
|
|
|
struct wf_slist_item * item = wf_impl_slist_first(&manager->sessions);
|
2019-04-17 20:51:16 +00:00
|
|
|
while (NULL != item)
|
|
|
|
{
|
|
|
|
struct wf_slist_item * next = item->next;
|
2019-04-25 18:08:34 +00:00
|
|
|
struct wf_impl_session * current = wf_container_of(item, struct wf_impl_session, item);
|
2019-03-26 22:04:53 +00:00
|
|
|
|
2019-04-17 20:51:16 +00:00
|
|
|
if (wf_impl_session_contains_wsi(current, wsi)) {
|
|
|
|
session = current;
|
|
|
|
break;
|
|
|
|
}
|
2019-04-01 20:15:12 +00:00
|
|
|
|
2019-04-17 20:51:16 +00:00
|
|
|
item = next;
|
2019-04-01 20:15:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
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-26 18:50:57 +00:00
|
|
|
struct wf_slist_item * prev = &manager->sessions.head;
|
|
|
|
while (NULL != prev->next)
|
2019-03-26 22:04:53 +00:00
|
|
|
{
|
2019-04-26 18:50:57 +00:00
|
|
|
struct wf_slist_item * item = prev->next;
|
2019-04-25 18:08:34 +00:00
|
|
|
struct wf_impl_session * session = wf_container_of(item, struct wf_impl_session, item);
|
2019-04-17 20:51:16 +00:00
|
|
|
if (wsi == session->wsi)
|
|
|
|
{
|
2020-06-28 17:43:08 +00:00
|
|
|
wf_impl_slist_remove_after(&manager->sessions, prev);
|
2019-04-17 20:51:16 +00:00
|
|
|
wf_impl_session_dispose(session);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-04-26 18:50:57 +00:00
|
|
|
prev = prev->next;
|
2019-03-26 22:04:53 +00:00
|
|
|
}
|
|
|
|
}
|