3 * This file is part of LCDd, the lcdproc server.
5 * This file is released under the GNU General Public License. Refer to the
6 * COPYING file distributed with this package.
8 * Copyright (c) 1999, William Ferrell, Scott Scriven
12 * Inits/shuts down client system,
13 * and searches for clients in the list.
14 * On short: manages the list of clients that are connected.
25 #include "shared/report.h"
28 LinkedList
*clientlist
= NULL
;
30 /* Initialize and kill client list...*/
34 debug(RPT_DEBUG
, "%s()", __FUNCTION__
);
36 clientlist
= LL_new();
38 report(RPT_ERR
, "%s: Unable to create client list", __FUNCTION__
);
46 clients_shutdown(void)
50 debug(RPT_DEBUG
, "%s()", __FUNCTION__
);
53 /* Program shutdown before completed startup */
57 /* Free all client structures... */
58 for (c
= LL_GetFirst(clientlist
); c
; c
= LL_GetNext(clientlist
)) {
59 debug(RPT_DEBUG
, "%s: ...", __FUNCTION__
);
61 debug(RPT_DEBUG
, "%s: ... %i ...", __FUNCTION__
, c
->sock
);
62 if (client_destroy(c
) != 0) {
63 report(RPT_ERR
, "%s: Error freeing client", __FUNCTION__
);
65 debug(RPT_DEBUG
, "%s: Freed client...", __FUNCTION__
);
68 debug(RPT_DEBUG
, "%s: No client!", __FUNCTION__
);
72 /* Then, free the list...*/
73 LL_Destroy(clientlist
);
75 debug(RPT_DEBUG
, "%s: done", __FUNCTION__
);
81 clients_add_client(Client
*c
)
83 /* Add the client to the clients list... */
84 return LL_Push(clientlist
, c
);
88 clients_remove_client(Client
*c
)
90 /* Remove the client from the clients list... */
91 return(LL_Remove(clientlist
, c
) == NULL
)?-1:0;
95 clients_getfirst(void)
97 return (Client
*) LL_GetFirst(clientlist
);
101 clients_getnext(void)
103 return (Client
*) LL_GetNext(clientlist
);
107 clients_client_count(void)
109 return LL_Length(clientlist
);
113 /* A client is identified by the file descriptor
114 * associated with it. Find one.
118 clients_find_client_by_sock(int sock
)
122 debug(RPT_DEBUG
, "%s(sock=%i)", __FUNCTION__
, sock
);
124 for (c
= LL_GetFirst(clientlist
); c
; c
= LL_GetNext(clientlist
)) {
125 if (c
->sock
== sock
) {
130 debug(RPT_ERR
, "%s: failed", __FUNCTION__
);