From: Tilman Sauerbeck Date: Sun, 7 Jan 2018 17:44:03 +0000 (+0100) Subject: Add the Client_find_by_session() function. X-Git-Url: http://git.code-monkey.de/?p=umurmur.git;a=commitdiff_plain;h=aa21dde5fbd77ecefb946961ea2231d31d8f8e3b Add the Client_find_by_session() function. Will be used to clean up duplicated logic in the future. --- 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