2019-03-26 22:04:53 +00:00
|
|
|
#include "webfuse/adapter/impl/session_manager.h"
|
2019-04-01 20:15:12 +00:00
|
|
|
#include "webfuse/core/util.h"
|
2019-04-17 20:51:16 +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-17 20:51:16 +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-26 18:50:57 +00:00
|
|
|
struct wf_slist_item * item = wf_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,
|
2019-04-01 20:15:12 +00:00
|
|
|
struct wf_impl_timeout_manager * timeout_manager,
|
2019-04-17 20:51:16 +00:00
|
|
|
struct wf_impl_jsonrpc_server * server,
|
|
|
|
char const * mount_point)
|
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(
|
|
|
|
wsi, authenticators, timeout_manager, server, mount_point);
|
|
|
|
if (NULL != session)
|
2019-03-26 22:04:53 +00:00
|
|
|
{
|
2019-04-17 20:51:16 +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-26 18:50:57 +00:00
|
|
|
struct wf_slist_item * item = wf_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)
|
|
|
|
{
|
|
|
|
wf_slist_remove_after(&manager->sessions, prev);
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|