From aa21dde5fbd77ecefb946961ea2231d31d8f8e3b Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Sun, 7 Jan 2018 18:44:03 +0100 Subject: [PATCH] Add the Client_find_by_session() function. Will be used to clean up duplicated logic in the future. --- src/client.c | 15 +++++++++++++++ src/client.h | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/src/client.c b/src/client.c index 240700e..b69da17 100644 --- a/src/client.c +++ b/src/client.c @@ -427,6 +427,21 @@ void Client_disconnect_all() } } +client_t *Client_find_by_session(int session_id) +{ + struct dlist *itr; + + list_iterate(itr, &clients) { + client_t *client = list_get_entry(itr, client_t, node); + + if (client->sessionId == session_id) { + return client; + } + } + + return NULL; +} + client_t *Client_find_by_fd(int fd) { struct dlist *itr; diff --git a/src/client.h b/src/client.h index 2759060..9e3fcb5 100644 --- a/src/client.h +++ b/src/client.h @@ -136,4 +136,10 @@ bool_t Client_token_match(client_t *client, char const *str); void Client_token_free(client_t *client); void Client_token_add(client_t *client, char *token_string); +/** + * Retrieve the client that matches the given session ID. + * Returns NULL if there's no such client. + */ +client_t *Client_find_by_session(int session_id); + #endif -- 2.30.2