Add the Client_find_by_session() function.
authorTilman Sauerbeck <tilman@code-monkey.de>
Sun, 7 Jan 2018 17:44:03 +0000 (18:44 +0100)
committerTilman Sauerbeck <tilman@code-monkey.de>
Sun, 7 Jan 2018 17:44:03 +0000 (18:44 +0100)
Will be used to clean up duplicated logic in the future.

src/client.c
src/client.h

index 240700e1253f1c270a6239c050289714dcbc8f70..b69da172cc51324bf87701bbe698d035fa321b55 100644 (file)
@@ -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;
 client_t *Client_find_by_fd(int fd)
 {
        struct dlist *itr;
index 2759060cc433729a1aac15ef750257499eb63858..9e3fcb5fa7b379f5ca18f2db33e6b2516b508910 100644 (file)
@@ -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);
 
 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
 #endif