extend deletion functions in LL.c, use them to make "bye" client command work

This commit is contained in:
marschap
2008-11-30 15:30:28 +00:00
parent a197581bd3
commit dcc643ec18
13 changed files with 79 additions and 51 deletions
+6 -4
View File
@@ -1,6 +1,8 @@
/*
* client.c
* This file is part of LCDd, the lcdproc server.
/** \file client.c
* Define all the client data and actions.
*/
/* This file is part of LCDd, the lcdproc server.
*
* This file is released under the GNU General Public License. Refer to the
* COPYING file distributed with this package.
@@ -228,7 +230,7 @@ client_remove_screen(Client *c, Screen *s)
debug(RPT_DEBUG, "%s(c=[%d], s=[%s])", __FUNCTION__, c->sock, s->id);
/* TODO: Check for errors here?*/
LL_Remove(c->screenlist, (void *) s);
LL_Remove(c->screenlist, (void *) s, NEXT);
/* Now, remove it from the screenlist...*/
screenlist_remove(s);
+11 -8
View File
@@ -1,9 +1,6 @@
/** \file clients.c
* Manage the list of clients that are connected.
* Init/shut down client system, and search for clients in the list.
*/
/* This file is part of LCDd, the lcdproc server.
/*
* clients.c
* This file is part of LCDd, the lcdproc server.
*
* This file is released under the GNU General Public License. Refer to the
* COPYING file distributed with this package.
@@ -11,6 +8,11 @@
* Copyright (c) 1999, William Ferrell, Scott Scriven
* 2002, Joris Robijn
*
*
* Inits/shuts down client system,
* and searches for clients in the list.
* On short: manages the list of clients that are connected.
*
*/
#include <stdio.h>
@@ -87,9 +89,9 @@ clients_add_client(Client *c)
/* Remove the client from the clients list... */
Client *
clients_remove_client(Client *c)
clients_remove_client(Client *c, Direction whereto)
{
Client *client = LL_Remove(clientlist, c);
Client *client = LL_Remove(clientlist, c, whereto);
return client;
}
@@ -116,6 +118,7 @@ clients_client_count(void)
/* A client is identified by the file descriptor
* associated with it. Find one.
*/
Client *
clients_find_client_by_sock(int sock)
{
+1 -1
View File
@@ -25,7 +25,7 @@ int clients_shutdown(void);
/* Add/remove clients (return NULL for error) */
Client *clients_add_client(Client *c);
Client *clients_remove_client(Client *c);
Client *clients_remove_client(Client *c, Direction whereto);
/* List functions */
Client *clients_getfirst(void);
+1 -1
View File
@@ -93,7 +93,7 @@ bye_func(Client *c, int argc, char **argv)
debug(RPT_INFO, "Bye, %s!", (c->name != NULL) ? c->name : "unknown client");
c->state = GONE;
sock_send_error(c->sock, "\"bye\" is currently ignored\n");
//sock_send_error(c->sock, "\"bye\" is currently ignored\n");
}
return 0;
}
+9 -13
View File
@@ -185,7 +185,7 @@ int input_reserve_key(const char *key, bool exclusive, Client *client)
/* Find out if this key is already reserved in a way that interferes
* with the new reservation.
*/
for (kr = LL_GetFirst(keylist); kr; kr = LL_GetNext(keylist)) {
for (kr = LL_GetFirst(keylist); kr != NULL; kr = LL_GetNext(keylist)) {
if (strcmp(kr->key, key) == 0) {
if (kr->exclusive || exclusive) {
/* Sorry ! */
@@ -214,13 +214,12 @@ void input_release_key(const char *key, Client *client)
debug(RPT_DEBUG, "%s(key=\"%.40s\", client=[%d])", __FUNCTION__, key, (client ? client->sock : -1));
for (kr = LL_GetFirst(keylist); kr != NULL; kr = LL_GetNext(keylist)) {
if (kr->client == client
&& strcmp(kr->key, key) == 0) {
free(kr->key);
free(kr);
LL_DeleteNode(keylist);
if ((kr->client == client) && (strcmp(kr->key, key) == 0)) {
report(RPT_INFO, "Key \"%.40s\" reserved %s by client [%d] and is now released",
key, (kr->exclusive ? "exclusively" : "shared"), (client ? client->sock : -1));
free(kr->key);
free(kr);
LL_DeleteNode(keylist, NEXT);
return;
}
}
@@ -232,17 +231,14 @@ void input_release_client_keys(Client *client)
debug(RPT_DEBUG, "%s(client=[%d])", __FUNCTION__, (client ? client->sock : -1));
kr = LL_GetFirst(keylist);
while (kr != NULL) {
for (kr = LL_GetFirst(keylist); kr != NULL; kr = LL_GetNext(keylist)) {
if (kr->client == client) {
report(RPT_INFO, "Key \"%.40s\" reserved %s by client [%d] and is now released",
kr->key, (kr->exclusive ? "exclusive" : "shared"), (client ? client->sock : -1));
kr->key, (kr->exclusive ? "exclusively" : "shared"), (client ? client->sock : -1));
free(kr->key);
free(kr);
LL_DeleteNode(keylist);
kr = LL_Get(keylist);
} else {
kr = LL_GetNext(keylist);
// jump to node before deleted one to not miss any
LL_DeleteNode(keylist, PREV);
}
}
}
+2 -2
View File
@@ -270,7 +270,7 @@ menu_remove_item(Menu *menu, MenuItem *item)
item2 != NULL;
item2 = LL_GetNext(menu->data.menu.contents), i++) {
if (item == item2) {
LL_DeleteNode(menu->data.menu.contents);
LL_DeleteNode(menu->data.menu.contents, NEXT);
if (menu->data.menu.selector_pos >= i) {
menu->data.menu.selector_pos--;
if (menu->data.menu.scroll > 0)
@@ -295,7 +295,7 @@ menu_destroy_all_items(Menu *menu)
for (item = menu_getfirst_item(menu); item != NULL; item = menu_getfirst_item(menu)) {
menuitem_destroy(item);
LL_Remove(menu->data.menu.contents, item);
LL_Remove(menu->data.menu.contents, item, NEXT);
}
}
+5
View File
@@ -229,6 +229,11 @@ parse_all_client_messages(void)
for (str = client_get_message(c); str != NULL; str = client_get_message(c)) {
parse_message(str, c);
free(str);
if (c->state == GONE) {
sock_destroy_client_socket(c);
break;
}
}
}
return 0;
+1 -1
View File
@@ -136,7 +136,7 @@ screen_remove_widget(Screen *s, Widget *w)
{
debug(RPT_DEBUG, "%s(s=[%.40s], widget=[%.40s])", __FUNCTION__, s->id, w->id);
LL_Remove(s->widgetlist, (void *) w);
LL_Remove(s->widgetlist, (void *) w, NEXT);
return 0;
}
+4 -3
View File
@@ -85,13 +85,13 @@ screenlist_remove(Screen *s)
screenlist_goto_next();
if (s == current_screen) {
/* Hmm, no other screen had same priority */
void *res = LL_Remove(screenlist, s);
void *res = LL_Remove(screenlist, s, NEXT);
/* And now once more */
screenlist_goto_next();
return (res == NULL) ? -1 : 0;
}
}
return (LL_Remove(screenlist, s) == NULL) ? -1 : 0;
return (LL_Remove(screenlist, s, NEXT) == NULL) ? -1 : 0;
}
@@ -221,7 +221,8 @@ screenlist_goto_next(void)
return -1;
/* Find current screen in screenlist */
for (s = LL_GetFirst(screenlist); s && s != current_screen; s = LL_GetNext(screenlist));
for (s = LL_GetFirst(screenlist); s && s != current_screen; s = LL_GetNext(screenlist))
;
/* One step forward */
s = LL_GetNext(screenlist);
+3 -3
View File
@@ -10,7 +10,7 @@
* Copyright (c) 1999, William Ferrell, Scott Scriven
* 2003, Benjamin Tse (blt@ieee.org) - Winsock port
* 2004, F5 Networks, Inc. - IP-address input
* 2005-2008, Peter Marschall - error checks, ...
* 2005, Peter Marschall - error checks, ...
*
*/
@@ -478,7 +478,7 @@ sock_destroy_socket(void)
report(RPT_NOTICE, "Client on socket %i disconnected",
entry->socket);
client_destroy(entry->client);
clients_remove_client(entry->client);
clients_remove_client(entry->client, PREV);
entry->client = NULL;
}
else {
@@ -490,7 +490,7 @@ sock_destroy_socket(void)
close(entry->socket);
/* re-add socket to the free socket pool */
entry = (ClientSocketMap *) LL_DeleteNode(openSocketList);
entry = (ClientSocketMap *) LL_DeleteNode(openSocketList, PREV);
LL_Push(freeClientSocketList, (void*) entry);
}
}