code & style cleanup
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
/* \file client_commands.c
|
||||
* Defines handlers for general client commands.
|
||||
*/
|
||||
|
||||
/*
|
||||
* client_commands.c
|
||||
* This file is part of LCDd, the lcdproc server.
|
||||
*
|
||||
* This file is released under the GNU General Public License. Refer to the
|
||||
@@ -14,9 +17,6 @@
|
||||
*
|
||||
* The client's available function set is defined here, as is the syntax
|
||||
* for each command.
|
||||
*
|
||||
* This particular file defines actions concerning clients.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
@@ -41,12 +41,10 @@ int
|
||||
test_func_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char str[256];
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
snprintf (str, sizeof(str), "%s: %i -> %s\n", __FUNCTION__, i, argv[i]);
|
||||
report (RPT_INFO, "%s", str);
|
||||
sock_send_string (c->sock, str);
|
||||
report(RPT_INFO, "%s: %i -> %s", __FUNCTION__, i, argv[i]);
|
||||
sock_printf(c->sock, "%s: %i -> %s\n", __FUNCTION__, i, argv[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -61,8 +59,6 @@ test_func_func (Client * c, int argc, char **argv)
|
||||
int
|
||||
hello_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
char str[256];
|
||||
|
||||
/* TODO: Give *real* info about the server/lcd...*/
|
||||
|
||||
if (argc > 1) {
|
||||
@@ -71,14 +67,12 @@ hello_func (Client * c, int argc, char **argv)
|
||||
|
||||
debug(RPT_INFO, "Hello!");
|
||||
|
||||
memset(str, '\0', sizeof(str));
|
||||
snprintf(str, sizeof(str), "connect LCDproc %s protocol %s lcd wid %i hgt %i cellwid %i cellhgt %i\n",
|
||||
sock_printf(c->sock, "connect LCDproc %s protocol %s lcd wid %i hgt %i cellwid %i cellhgt %i\n",
|
||||
VERSION, PROTOCOL_VERSION,
|
||||
display_props->width, display_props->height,
|
||||
display_props->cellwidth, display_props->cellheight);
|
||||
|
||||
sock_send_string (c->sock, str);
|
||||
|
||||
/* make note that client has sent hello */
|
||||
c->ack = 1;
|
||||
|
||||
return 0;
|
||||
@@ -111,9 +105,7 @@ int
|
||||
client_set_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char str[256];
|
||||
|
||||
memset(str, '\0', sizeof(str));
|
||||
if (!c->ack)
|
||||
return 1;
|
||||
|
||||
@@ -124,14 +116,13 @@ client_set_func (Client * c, int argc, char **argv)
|
||||
|
||||
i = 1;
|
||||
do {
|
||||
char *p;
|
||||
char *p = argv[i];
|
||||
|
||||
/* This bit of code means that "-name" is the same as "name"...*/
|
||||
p = argv[i];
|
||||
/* ignore leading '-' in options: we allow both forms */
|
||||
if (*p == '-')
|
||||
p++;
|
||||
|
||||
/* Handle the "name" parameter*/
|
||||
/* Handle the "name" option */
|
||||
if (strcmp(p, "name") == 0) {
|
||||
i++;
|
||||
if (argv[i] == '\0') {
|
||||
@@ -139,25 +130,21 @@ client_set_func (Client * c, int argc, char **argv)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strlen(argv[i]) > sizeof(str) -1) {
|
||||
sock_send_error(c->sock, "name too long\n");
|
||||
} else {
|
||||
strncpy(str, argv[i], sizeof(str) - 1);
|
||||
|
||||
debug(RPT_DEBUG, "client_set: name=\"%s\"", argv[i]);
|
||||
|
||||
/* set the name...*/
|
||||
if (c->name)
|
||||
if (c->name != NULL)
|
||||
free(c->name);
|
||||
|
||||
if ((c->name = strdup (str)) == NULL) {
|
||||
if ((c->name = strdup(argv[i])) == NULL) {
|
||||
sock_send_error(c->sock, "error allocating memory!\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sock_send_string(c->sock, "success\n");
|
||||
i++; /* bypass argument (name string)*/
|
||||
}
|
||||
}
|
||||
} else {
|
||||
else {
|
||||
sock_printf_error(c->sock, "invalid parameter (%s)\n", p);
|
||||
}
|
||||
} while (++i < argc);
|
||||
@@ -171,7 +158,6 @@ client_set_func (Client * c, int argc, char **argv)
|
||||
*
|
||||
* Usage: client_add_key [-exclusively|-shared] {<key>}+
|
||||
*/
|
||||
#define BUFLEN 80
|
||||
int
|
||||
client_add_key_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
@@ -259,20 +245,20 @@ backlight_func (Client * c, int argc, char **argv)
|
||||
|
||||
if (strcmp ("on", argv[1]) == 0) {
|
||||
c->backlight = BACKLIGHT_ON;
|
||||
|
||||
} else if (strcmp ("off", argv[1]) == 0) {
|
||||
}
|
||||
else if (strcmp ("off", argv[1]) == 0) {
|
||||
c->backlight = BACKLIGHT_OFF;
|
||||
|
||||
} else if (strcmp ("toggle", argv[1]) == 0) {
|
||||
}
|
||||
else if (strcmp ("toggle", argv[1]) == 0) {
|
||||
if (c->backlight == BACKLIGHT_ON)
|
||||
c->backlight = BACKLIGHT_OFF;
|
||||
else if (c->backlight == BACKLIGHT_OFF)
|
||||
c->backlight = BACKLIGHT_ON;
|
||||
|
||||
} else if (strcmp ("blink", argv[1]) == 0) {
|
||||
}
|
||||
else if (strcmp ("blink", argv[1]) == 0) {
|
||||
c->backlight |= BACKLIGHT_BLINK;
|
||||
|
||||
} else if (strcmp ("flash", argv[1]) == 0) {
|
||||
}
|
||||
else if (strcmp ("flash", argv[1]) == 0) {
|
||||
c->backlight |= BACKLIGHT_FLASH;
|
||||
}
|
||||
|
||||
@@ -290,17 +276,14 @@ backlight_func (Client * c, int argc, char **argv)
|
||||
int
|
||||
info_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
char str[1024];
|
||||
if (!c->ack)
|
||||
return 1;
|
||||
|
||||
if (argc > 1) {
|
||||
sock_send_error(c->sock, "Extra arguments ignored...\n");
|
||||
}
|
||||
|
||||
memset(str, '\0', sizeof(str));
|
||||
snprintf (str, sizeof(str)-1, "%s\n", drivers_get_info());
|
||||
str[sizeof(str)-1] = '\0';
|
||||
|
||||
sock_send_string (c->sock, str);
|
||||
sock_printf(c->sock, "%s\n", drivers_get_info());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/* \file client_commands.h
|
||||
* Declares handlers for general client commands.
|
||||
*/
|
||||
|
||||
/*
|
||||
* client_commands.h
|
||||
* This file is part of LCDd, the lcdproc server.
|
||||
*
|
||||
* This file is released under the GNU General Public License. Refer to the
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/* \file command_list.c
|
||||
* Defines the dispatcher for handlers dealing with the client commands.
|
||||
*/
|
||||
|
||||
/*
|
||||
* commands/command_list.c
|
||||
* This file is part of LCDd, the lcdproc server.
|
||||
*
|
||||
* This file is released under the GNU General Public License. Refer to the
|
||||
@@ -14,7 +17,6 @@
|
||||
*
|
||||
* The client's available function set is defined here, as is the syntax
|
||||
* for each command. <-- TODO !
|
||||
*
|
||||
*/
|
||||
|
||||
#include "command_list.h"
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/* \file command_list.h
|
||||
* Declares client command dispatcher function.
|
||||
*/
|
||||
|
||||
/*
|
||||
* commands/command_list.h
|
||||
* This file is part of LCDd, the lcdproc server.
|
||||
*
|
||||
* This file is released under the GNU General Public License. Refer to the
|
||||
|
||||
+139
-150
@@ -1,5 +1,8 @@
|
||||
/* \file menu_commands.c
|
||||
* Defines handlers for client commands concerning menus.
|
||||
*/
|
||||
|
||||
/*
|
||||
* menu_commands.c
|
||||
* This file is part of LCDd, the lcdproc server.
|
||||
*
|
||||
* This file is released under the GNU General Public License. Refer to the
|
||||
@@ -16,9 +19,6 @@
|
||||
*
|
||||
* The client's available function set is defined here, as is the syntax
|
||||
* for each command.
|
||||
*
|
||||
* This particular file defines actions concerning client supplied menus.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -51,12 +51,11 @@ static char *argv2string(int argc, char **argv)
|
||||
char *rtn = NULL;
|
||||
int len;
|
||||
int i;
|
||||
for (i = len = 0; i < argc; ++i)
|
||||
for (i = len = 0; i < argc; i++)
|
||||
len += strlen(argv[i]) + 1;
|
||||
rtn = malloc(len + 1);
|
||||
rtn[0] = '\0';
|
||||
for (i = len = 0; i < argc; ++i)
|
||||
{
|
||||
for (i = len = 0; i < argc; i++) {
|
||||
strcat(rtn, argv[i]);
|
||||
strcat(rtn, " ");
|
||||
}
|
||||
@@ -102,12 +101,12 @@ menu_add_item_func (Client * c, int argc, char **argv)
|
||||
if (!c->ack)
|
||||
return 1;
|
||||
|
||||
if (!c->name) {
|
||||
if (c->name == NULL) {
|
||||
sock_send_error(c->sock, "You need to give your client a name first\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((argc < 4 )) {
|
||||
if (argc < 4) {
|
||||
sock_send_error(c->sock, "Usage: menu_add_item <menuid> <newitemid> <type> [<text>]\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -116,27 +115,24 @@ menu_add_item_func (Client * c, int argc, char **argv)
|
||||
item_id = argv[2];
|
||||
|
||||
/* Does the client have a menu already ? */
|
||||
if (!c->menu) {
|
||||
if (c->menu == NULL) {
|
||||
/* We need to create it */
|
||||
report(RPT_INFO, "Client [%d] is using the menu", c->sock);
|
||||
c->menu = menu_create("_client_menu_", menu_commands_handler, c->name, c);
|
||||
menu_add_item(main_menu, c->menu);
|
||||
}
|
||||
|
||||
if ( menu_id[0] == 0 ) {
|
||||
/* No menu specified = client's main menu */
|
||||
menu = c->menu;
|
||||
} else {
|
||||
/* A specified menu */
|
||||
menu = menu_find_item (c->menu, menu_id, true);
|
||||
}
|
||||
if (!menu) {
|
||||
/* use either the given menu or the client's main menu if none was specified */
|
||||
menu = (menu_id[0] != '\0')
|
||||
? menu_find_item(c->menu, menu_id, true)
|
||||
: c->menu;
|
||||
if (menu == NULL) {
|
||||
sock_send_error(c->sock, "Cannot find menu id\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
item = menu_find_item(c->menu, item_id, true);
|
||||
if (item) {
|
||||
if (item != NULL) {
|
||||
sock_send_error(c->sock, "Item id already in use\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -149,7 +145,7 @@ menu_add_item_func (Client * c, int argc, char **argv)
|
||||
}
|
||||
|
||||
/* Is a text given (options don't count)? */
|
||||
if (argc >= 5 && argv[4][0] != '-') {
|
||||
if ((argc >= 5) && (argv[4][0] != '-')) {
|
||||
text = argv[4];
|
||||
}
|
||||
else {
|
||||
@@ -198,20 +194,19 @@ menu_add_item_func (Client * c, int argc, char **argv)
|
||||
|
||||
/* are there any options (starting with '-')?
|
||||
* - create a temporary argv for menu_set_item() call */
|
||||
if (argc > 5 || argv[4][0] == '-') {
|
||||
if ((argc > 5) || (argv[4][0] == '-')) {
|
||||
// menu_add_item <menuid> <newitemid> <type> [<text>]
|
||||
// menu_set_item <menuid> <itemid> {<option>}+
|
||||
int i, j;
|
||||
argv_set = malloc(argc * sizeof(char *));
|
||||
assert(argv_set);
|
||||
argv_set[0] = "menu_set_item";
|
||||
for (i = j = 1; i < argc; ++i)
|
||||
{
|
||||
for (i = j = 1; i < argc; i++) {
|
||||
/* skip "type" */
|
||||
if (i == 3)
|
||||
continue;
|
||||
/* skip "text" */
|
||||
if (i == 4 && argv[4][0] != '-')
|
||||
if ((i == 4) && (argv[4][0] != '-'))
|
||||
continue;
|
||||
|
||||
argv_set[j++] = argv[i];
|
||||
@@ -251,25 +246,22 @@ menu_del_item_func (Client * c, int argc, char **argv)
|
||||
item_id = argv[2];
|
||||
|
||||
/* Does the client have a menu already ? */
|
||||
if (!c->menu) {
|
||||
if (c->menu == NULL) {
|
||||
sock_send_error(c->sock, "Client has no menu\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( menu_id[0] == 0 ) {
|
||||
/* No menu specified = client's main menu */
|
||||
menu = c->menu;
|
||||
} else {
|
||||
/* A specified menu */
|
||||
menu = menu_find_item (c->menu, menu_id, true);
|
||||
}
|
||||
if (!menu) {
|
||||
/* use either the given menu or the client's main menu if none was specified */
|
||||
menu = (menu_id[0] != '\0')
|
||||
? menu_find_item(c->menu, menu_id, true)
|
||||
: c->menu;
|
||||
if (menu == NULL) {
|
||||
sock_send_error(c->sock, "Cannot find menu id\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
item = menu_find_item(c->menu, item_id, true);
|
||||
if (!item) {
|
||||
if (item == NULL) {
|
||||
sock_send_error(c->sock, "Cannot find item\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -459,20 +451,17 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
menu_id = argv[1];
|
||||
item_id = argv[2];
|
||||
|
||||
if ( menu_id[0] == 0 ) {
|
||||
/* No menu specified = client's main menu */
|
||||
menu = c->menu;
|
||||
} else {
|
||||
/* A specified menu */
|
||||
menu = menu_find_item (c->menu, menu_id, true);
|
||||
}
|
||||
if (!menu) {
|
||||
/* use either the given menu or the client's main menu if none was specified */
|
||||
menu = (menu_id[0] != '\0')
|
||||
? menu_find_item(c->menu, menu_id, true)
|
||||
: c->menu;
|
||||
if (menu == NULL) {
|
||||
sock_send_error(c->sock, "Cannot find menu id\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
item = menu_find_item(c->menu, item_id, true);
|
||||
if (!item) {
|
||||
if (item == NULL) {
|
||||
sock_send_error(c->sock, "Cannot find item\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -488,7 +477,8 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
/* Find the option in the table */
|
||||
if (argv[argnr][0] == '-') {
|
||||
int i;
|
||||
for( i=0; option_table[i].name; i++ ) {
|
||||
|
||||
for (i = 0; option_table[i].name != NULL; i++) {
|
||||
if (strcmp(argv[argnr]+1, option_table[i].name) == 0) {
|
||||
found_option_name = 1;
|
||||
if (item->type == option_table[i].menuitem_type
|
||||
@@ -505,7 +495,8 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
if (option_nr == -1) {
|
||||
if (found_option_name) {
|
||||
sock_printf_error(c->sock, "Option not valid for menuitem type: \"%.40s\"\n", argv[argnr]);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sock_printf_error(c->sock, "Unknown option: \"%.40s\"\n", argv[argnr]);
|
||||
}
|
||||
continue; /* Skip to next arg */
|
||||
@@ -528,9 +519,11 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
case BOOLEAN:
|
||||
if (strcmp(argv[argnr+1], "false") == 0) {
|
||||
bool_value = false;
|
||||
} else if( strcmp( argv[argnr+1], "true" ) == 0 ) {
|
||||
}
|
||||
else if (strcmp(argv[argnr+1], "true") == 0) {
|
||||
bool_value = true;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
@@ -541,11 +534,14 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
case CHECKBOX_VALUE:
|
||||
if (strcmp(argv[argnr+1], "off") == 0) {
|
||||
checkbox_value = CHECKBOX_OFF;
|
||||
} else if( strcmp( argv[argnr+1], "on" ) == 0 ) {
|
||||
}
|
||||
else if (strcmp(argv[argnr+1], "on") == 0) {
|
||||
checkbox_value = CHECKBOX_ON;
|
||||
} else if( strcmp( argv[argnr+1], "gray" ) == 0 ) {
|
||||
}
|
||||
else if (strcmp(argv[argnr+1], "gray") == 0) {
|
||||
checkbox_value = CHECKBOX_GRAY;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
@@ -555,7 +551,7 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
break;
|
||||
case SHORT:
|
||||
short_value = strtol(argv[argnr+1], &p, 0);
|
||||
if( argv[argnr+1][0] == '\0' || *p != '\0' ) {
|
||||
if ((argv[argnr+1][0] == '\0') || (*p != '\0')) {
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
@@ -565,7 +561,7 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
break;
|
||||
case INT:
|
||||
int_value = strtol(argv[argnr+1], &p, 0);
|
||||
if( argv[argnr+1][0] == '\0' || *p != '\0' ) {
|
||||
if ((argv[argnr+1][0] == '\0') || (*p != '\0')) {
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
@@ -575,7 +571,7 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
break;
|
||||
case FLOAT:
|
||||
float_value = strtod(argv[argnr+1], &p);
|
||||
if( argv[argnr+1][0] == '\0' || *p != '\0' ) {
|
||||
if ((argv[argnr+1][0] == '\0') || (*p != '\0')) {
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
@@ -611,11 +607,14 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
if (strcmp(argv[argnr]+1, "menu_result") == 0) {
|
||||
if (strcmp(argv[argnr+1], "none") == 0) {
|
||||
set_successor(item, "_none_", c);
|
||||
} else if( strcmp( argv[argnr+1], "close" ) == 0 ) {
|
||||
}
|
||||
else if (strcmp(argv[argnr+1], "close") == 0) {
|
||||
set_successor(item, "_close_", c);
|
||||
} else if( strcmp( argv[argnr+1], "quit" ) == 0 ) {
|
||||
}
|
||||
else if (strcmp(argv[argnr+1], "quit") == 0) {
|
||||
set_successor(item, "_quit_", c);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
error = 1;
|
||||
}
|
||||
}
|
||||
@@ -623,7 +622,8 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
case MENUITEM_SLIDER:
|
||||
if (item->data.slider.value < item->data.slider.minvalue) {
|
||||
item->data.slider.value = item->data.slider.minvalue;
|
||||
} else if( item->data.slider.value > item->data.slider.maxvalue ) {
|
||||
}
|
||||
else if (item->data.slider.value > item->data.slider.maxvalue) {
|
||||
item->data.slider.value = item->data.slider.maxvalue;
|
||||
}
|
||||
break;
|
||||
@@ -643,7 +643,7 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
}
|
||||
else if (strcmp(argv[argnr]+1, "maxlength") == 0) {
|
||||
char * new_buf;
|
||||
if( short_value < 0 || short_value > 1000 ) {
|
||||
if ((short_value < 0) || (short_value > 1000)) {
|
||||
error = 2;
|
||||
break;
|
||||
}
|
||||
@@ -721,8 +721,8 @@ menu_goto_func (Client * c, int argc, char **argv)
|
||||
Menu *menu;
|
||||
|
||||
debug(RPT_DEBUG, "%s(Client [%d], %s, %s)",
|
||||
__FUNCTION__, c->sock, (argc > 1 ? argv[1] : "<null>"),
|
||||
(argc > 2 ? argv[2] : "<null>") );
|
||||
__FUNCTION__, c->sock, ((argc > 1) ? argv[1] : "<null>"),
|
||||
((argc > 2) ? argv[2] : "<null>"));
|
||||
if (!c->ack)
|
||||
return 1;
|
||||
|
||||
@@ -733,15 +733,11 @@ menu_goto_func (Client * c, int argc, char **argv)
|
||||
|
||||
menu_id = argv[1];
|
||||
|
||||
if ( menu_id[0] == 0 ) {
|
||||
/* No menu specified = client's main menu */
|
||||
menu = c->menu;
|
||||
} else {
|
||||
/* A specified menu */
|
||||
menu = menuitem_search(menu_id, c);
|
||||
}
|
||||
|
||||
if (!menu) {
|
||||
/* use either the given menu or the client's main menu if none was specified */
|
||||
menu = (menu_id[0] != '\0')
|
||||
? menuitem_search(menu_id, c)
|
||||
: c->menu;
|
||||
if (menu == NULL) {
|
||||
sock_send_error(c->sock, "Cannot find menu id\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -766,14 +762,14 @@ int set_predecessor(MenuItem *item, char *itemid, Client *c)
|
||||
assert(item != NULL);
|
||||
debug(RPT_DEBUG, "%s(%s, %s, %d)", __FUNCTION__,
|
||||
item->id, itemid, c->sock);
|
||||
|
||||
// handle these special
|
||||
if (strcmp("_quit_", itemid) != 0
|
||||
&& strcmp("_close_", itemid) != 0
|
||||
&& strcmp("_none_", itemid) != 0)
|
||||
{
|
||||
if ((strcmp("_quit_", itemid) != 0) &&
|
||||
(strcmp("_close_", itemid) != 0) &&
|
||||
(strcmp("_none_", itemid) != 0)) {
|
||||
MenuItem *predecessor = menuitem_search(itemid, c);
|
||||
if ( ! predecessor)
|
||||
{
|
||||
|
||||
if (predecessor == NULL) {
|
||||
sock_printf_error(c->sock, "Cannot find predecessor '%s'"
|
||||
" for item '%s'\n", itemid, item->id);
|
||||
return -1;
|
||||
@@ -783,7 +779,7 @@ int set_predecessor(MenuItem *item, char *itemid, Client *c)
|
||||
" setting '%s's predecessor from '%s' to '%s'",
|
||||
__FUNCTION__, c->sock, item->id,
|
||||
item->predecessor_id, itemid);
|
||||
if (item->predecessor_id)
|
||||
if (item->predecessor_id != NULL)
|
||||
free(item->predecessor_id);
|
||||
item->predecessor_id = strdup(itemid);
|
||||
return 0;
|
||||
@@ -803,21 +799,20 @@ int set_successor(MenuItem *item, char *itemid, Client *c)
|
||||
assert(item != NULL);
|
||||
debug(RPT_DEBUG, "%s(%s, %s, %d)", __FUNCTION__,
|
||||
item->id, itemid, c->sock);
|
||||
|
||||
// handle these special
|
||||
if (strcmp("_quit_", itemid) != 0
|
||||
&& strcmp("_close_", itemid) != 0
|
||||
&& strcmp("_none_", itemid) != 0)
|
||||
{
|
||||
if ((strcmp("_quit_", itemid) != 0) &&
|
||||
(strcmp("_close_", itemid) != 0) &&
|
||||
(strcmp("_none_", itemid) != 0)) {
|
||||
MenuItem *successor = menuitem_search(itemid, c);
|
||||
if ( ! successor)
|
||||
{
|
||||
|
||||
if (successor == NULL) {
|
||||
sock_printf_error(c->sock, "Cannot find successor '%s'"
|
||||
" for item '%s'\n", itemid, item->id);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (item->type == MENUITEM_MENU)
|
||||
{
|
||||
if (item->type == MENUITEM_MENU) {
|
||||
sock_printf_error(c->sock, "Cannot set successor of '%s':"
|
||||
" wrong type '%s'\n", item->id,
|
||||
menuitem_type_to_typename(item->type));
|
||||
@@ -827,7 +822,7 @@ int set_successor(MenuItem *item, char *itemid, Client *c)
|
||||
" setting '%s's successor from '%s' to '%s'",
|
||||
__FUNCTION__, c->sock, item->id,
|
||||
item->successor_id, itemid);
|
||||
if (item->successor_id)
|
||||
if (item->successor_id != NULL)
|
||||
free(item->successor_id);
|
||||
item->successor_id = strdup(itemid);
|
||||
return 0;
|
||||
@@ -845,8 +840,8 @@ menu_set_main_func (Client * c, int argc, char **argv)
|
||||
Menu *menu;
|
||||
|
||||
debug(RPT_DEBUG, "%s(Client [%d], %s, %s)",
|
||||
__FUNCTION__, c->sock, (argc > 1 ? argv[1] : "<null>"),
|
||||
(argc > 2 ? argv[2] : "<null>") );
|
||||
__FUNCTION__, c->sock, ((argc > 1) ? argv[1] : "<null>"),
|
||||
((argc > 2) ? argv[2] : "<null>"));
|
||||
if (!c->ack)
|
||||
return 1;
|
||||
|
||||
@@ -857,7 +852,7 @@ menu_set_main_func (Client * c, int argc, char **argv)
|
||||
|
||||
menu_id = argv[1];
|
||||
|
||||
if ( menu_id[0] == 0 ) {
|
||||
if (menu_id[0] == '\0') {
|
||||
/* No menu specified = client's main menu */
|
||||
menu = c->menu;
|
||||
}
|
||||
@@ -867,7 +862,7 @@ menu_set_main_func (Client * c, int argc, char **argv)
|
||||
else {
|
||||
/* A specified menu */
|
||||
menu = menu_find_item(c->menu, menu_id, true);
|
||||
if ( ! menu) {
|
||||
if (menu == NULL) {
|
||||
sock_send_error(c->sock, "Cannot find menu id\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -880,80 +875,74 @@ menu_set_main_func (Client * c, int argc, char **argv)
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
* This function cathes the event for the menus that have been
|
||||
* This function catches the event for the menus that have been
|
||||
* created on behalf of the clients. It informs the client with
|
||||
* an event message.
|
||||
*/
|
||||
MenuEventFunc(menu_commands_handler)
|
||||
{
|
||||
char buf[80] = "";
|
||||
Client *c;
|
||||
|
||||
/* Compose message */
|
||||
if( event == MENUEVENT_UPDATE
|
||||
|| event == MENUEVENT_MINUS
|
||||
|| event == MENUEVENT_PLUS) {
|
||||
switch( item->type ) {
|
||||
case MENUITEM_CHECKBOX:
|
||||
snprintf (buf, sizeof(buf)-1, "menuevent %s %.40s %s\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id, ((char*[]){"off","on","gray"})[item->data.checkbox.value] );
|
||||
break;
|
||||
case MENUITEM_SLIDER:
|
||||
snprintf (buf, sizeof(buf)-1, "menuevent %s %.40s %d\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id, item->data.slider.value );
|
||||
break;
|
||||
case MENUITEM_RING:
|
||||
snprintf (buf, sizeof(buf)-1, "menuevent %s %.40s %d\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id, item->data.ring.value );
|
||||
break;
|
||||
case MENUITEM_NUMERIC:
|
||||
snprintf (buf, sizeof(buf)-1, "menuevent %s %.40s %d\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id, item->data.numeric.value );
|
||||
break;
|
||||
case MENUITEM_ALPHA:
|
||||
snprintf (buf, sizeof(buf)-1, "menuevent %s %.40s %.40s\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id, item->data.alpha.value );
|
||||
break;
|
||||
case MENUITEM_IP:
|
||||
snprintf (buf, sizeof(buf)-1, "menuevent %s %.40s %.40s\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id, item->data.ip.value );
|
||||
break;
|
||||
default:
|
||||
snprintf (buf, sizeof(buf)-1, "menuevent %s %.40s\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id);
|
||||
}
|
||||
}
|
||||
else if (event == MENUEVENT_ENTER
|
||||
|| event == MENUEVENT_LEAVE)
|
||||
{
|
||||
snprintf (buf, sizeof(buf)-1, "menuevent %s %.40s\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id);
|
||||
}
|
||||
else {
|
||||
snprintf (buf, sizeof(buf)-1, "menuevent %s %.40s\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id);
|
||||
}
|
||||
|
||||
buf[sizeof(buf)-1] = 0;
|
||||
|
||||
/* Where should the message go to ? */
|
||||
c = menuitem_get_client(item);
|
||||
if( !c ) {
|
||||
if (c == NULL) {
|
||||
report(RPT_ERR, "%s: Could not find client of item \"%s\"",
|
||||
__FUNCTION__, item->id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Send it */
|
||||
sock_send_string (c->sock, buf);
|
||||
/* Compose & send message */
|
||||
if ((event == MENUEVENT_UPDATE) ||
|
||||
(event == MENUEVENT_MINUS) ||
|
||||
(event == MENUEVENT_PLUS)) {
|
||||
switch (item->type) {
|
||||
case MENUITEM_CHECKBOX:
|
||||
sock_printf(c->sock, "menuevent %s %.40s %s\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id, ((char *[]) {"off","on","gray"})[item->data.checkbox.value]);
|
||||
break;
|
||||
case MENUITEM_SLIDER:
|
||||
sock_printf(c->sock, "menuevent %s %.40s %d\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id, item->data.slider.value);
|
||||
break;
|
||||
case MENUITEM_RING:
|
||||
sock_printf(c->sock, "menuevent %s %.40s %d\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id, item->data.ring.value);
|
||||
break;
|
||||
case MENUITEM_NUMERIC:
|
||||
sock_printf(c->sock, "menuevent %s %.40s %d\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id, item->data.numeric.value);
|
||||
break;
|
||||
case MENUITEM_ALPHA:
|
||||
sock_printf(c->sock, "menuevent %s %.40s %.40s\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id, item->data.alpha.value);
|
||||
break;
|
||||
case MENUITEM_IP:
|
||||
sock_printf(c->sock, "menuevent %s %.40s %.40s\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id, item->data.ip.value);
|
||||
break;
|
||||
default:
|
||||
sock_printf(c->sock, "menuevent %s %.40s\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id);
|
||||
}
|
||||
}
|
||||
else if ((event == MENUEVENT_ENTER) ||
|
||||
(event == MENUEVENT_LEAVE)) {
|
||||
sock_printf(c->sock, "menuevent %s %.40s\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id);
|
||||
}
|
||||
else {
|
||||
sock_printf(c->sock, "menuevent %s %.40s\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/* \file menu_commands.h
|
||||
* Declares handlers for client menu commands.
|
||||
*/
|
||||
|
||||
/*
|
||||
* menu_commands.h
|
||||
* This file is part of LCDd, the lcdproc server.
|
||||
*
|
||||
* This file is released under the GNU General Public License. Refer to the
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/* \file screens_commands.c
|
||||
* Defines handlers for the client commands concerning screens.
|
||||
*/
|
||||
|
||||
/*
|
||||
* screens_commands.c
|
||||
* This file is part of LCDd, the lcdproc server.
|
||||
*
|
||||
* This file is released under the GNU General Public License. Refer to the
|
||||
@@ -14,9 +17,6 @@
|
||||
*
|
||||
* The client's available function set is defined here, as is the syntax
|
||||
* for each command.
|
||||
*
|
||||
* This particular file defines actions concerning screens.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
@@ -55,13 +55,13 @@ screen_add_func (Client * c, int argc, char **argv)
|
||||
debug(RPT_DEBUG, "screen_add: Adding screen %s", argv[1]);
|
||||
|
||||
s = client_find_screen(c, argv[1]);
|
||||
if (s) {
|
||||
if (s != NULL) {
|
||||
sock_send_error(c->sock, "Screen already exists\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
s = screen_create(argv[1], c);
|
||||
if (!s) {
|
||||
if (s == NULL) {
|
||||
sock_send_error(c->sock, "failed to create screen\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -99,18 +99,21 @@ screen_del_func (Client * c, int argc, char **argv)
|
||||
debug(RPT_DEBUG, "screen_del: Deleting screen %s", argv[1]);
|
||||
|
||||
s = client_find_screen(c, argv[1]);
|
||||
if (!s) {
|
||||
if (s == NULL) {
|
||||
sock_send_error(c->sock, "Unknown screen id\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = client_remove_screen(c, s);
|
||||
if ( err == 0 )
|
||||
if (err == 0) {
|
||||
sock_send_string(c->sock, "success\n");
|
||||
}
|
||||
else if (err < 0) {
|
||||
sock_send_error(c->sock, "failed to remove screen\n");
|
||||
} else
|
||||
}
|
||||
else {
|
||||
sock_send_error(c->sock, "Unknown screen id\n");
|
||||
}
|
||||
|
||||
report(RPT_INFO, "Client on socket %d removed screen \"%s\"", c->sock, s->id);
|
||||
|
||||
@@ -147,27 +150,23 @@ screen_set_func (Client * c, int argc, char **argv)
|
||||
" [-cursor <type>]"
|
||||
" [-cursor_x <xpos>] [-cursor_y <ypos>]\n");
|
||||
return 0;
|
||||
} else if (argc == 2) {
|
||||
}
|
||||
else if (argc == 2) {
|
||||
sock_send_error(c->sock, "What do you want to set?\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
id = argv[1];
|
||||
s = client_find_screen(c, id);
|
||||
if (!s) {
|
||||
if (s == NULL) {
|
||||
sock_send_error(c->sock, "Unknown screen id\n");
|
||||
return 0;
|
||||
}
|
||||
/* Handle the rest of the parameters*/
|
||||
for (i = 2; i < argc; i++) {
|
||||
char *p;
|
||||
char *p = argv[i];
|
||||
|
||||
/* The following code allows us to use p for comparisions,
|
||||
* ignoring a (valid) single leading '-' - reduces string comparisons
|
||||
* by half.
|
||||
*/
|
||||
|
||||
p = argv[i];
|
||||
/* ignore leading '-' in options: we allow both forms */
|
||||
if (*p == '-')
|
||||
p++;
|
||||
|
||||
@@ -178,11 +177,12 @@ screen_set_func (Client * c, int argc, char **argv)
|
||||
debug(RPT_DEBUG, "screen_set: name=\"%s\"", argv[i]);
|
||||
|
||||
/* set the name...*/
|
||||
if (s->name)
|
||||
if (s->name != NULL)
|
||||
free(s->name);
|
||||
s->name = strdup(argv[i]);
|
||||
sock_send_string(c->sock, "success\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sock_send_error(c->sock, "-name requires a parameter\n");
|
||||
}
|
||||
}
|
||||
@@ -195,24 +195,26 @@ screen_set_func (Client * c, int argc, char **argv)
|
||||
/* first try to interpret it as a number */
|
||||
number = atoi(argv[i]);
|
||||
if (number > 0) {
|
||||
if (number <= 64) {
|
||||
if (number <= 64)
|
||||
s->priority = PRI_FOREGROUND;
|
||||
} else if (number < 192) {
|
||||
else if (number < 192)
|
||||
s->priority = PRI_INFO;
|
||||
} else {
|
||||
else
|
||||
s->priority = PRI_BACKGROUND;
|
||||
}
|
||||
} else {
|
||||
else {
|
||||
/* Try if it is a priority class */
|
||||
number = screen_pri_name_to_pri(argv[i]);
|
||||
}
|
||||
if (number >= 0) {
|
||||
s->priority = number;
|
||||
sock_send_string(c->sock, "success\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sock_send_error(c->sock, "invalid argument at -priority\n");
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sock_send_error(c->sock, "-priority requires a parameter\n");
|
||||
}
|
||||
}
|
||||
@@ -227,7 +229,8 @@ screen_set_func (Client * c, int argc, char **argv)
|
||||
if (number > 0)
|
||||
s->duration = number;
|
||||
sock_send_string(c->sock, "success\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sock_send_error(c->sock, "-duration requires a parameter\n");
|
||||
}
|
||||
}
|
||||
@@ -245,7 +248,8 @@ screen_set_func (Client * c, int argc, char **argv)
|
||||
else if (0 == strcmp(argv[i], "open"))
|
||||
s->heartbeat = HEARTBEAT_OPEN;
|
||||
sock_send_string(c->sock, "success\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sock_send_error(c->sock, "-heartbeat requires a parameter\n");
|
||||
}
|
||||
}
|
||||
@@ -260,7 +264,8 @@ screen_set_func (Client * c, int argc, char **argv)
|
||||
if (number > 0)
|
||||
s->width = number;
|
||||
sock_send_string(c->sock, "success\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sock_send_error(c->sock, "-wid requires a parameter\n");
|
||||
}
|
||||
|
||||
@@ -276,7 +281,8 @@ screen_set_func (Client * c, int argc, char **argv)
|
||||
if (number > 0)
|
||||
s->height = number;
|
||||
sock_send_string(c->sock, "success\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sock_send_error(c->sock, "-hgt requires a parameter\n");
|
||||
}
|
||||
}
|
||||
@@ -295,7 +301,8 @@ screen_set_func (Client * c, int argc, char **argv)
|
||||
report(RPT_NOTICE, "Timeout set.");
|
||||
}
|
||||
sock_send_string(c->sock, "success\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sock_send_error(c->sock, "-timeout requires a parameter\n");
|
||||
}
|
||||
}
|
||||
@@ -332,7 +339,8 @@ screen_set_func (Client * c, int argc, char **argv)
|
||||
break;
|
||||
}
|
||||
sock_send_string(c->sock, "success\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sock_send_error(c->sock, "-backlight requires a parameter\n");
|
||||
}
|
||||
}
|
||||
@@ -352,7 +360,8 @@ screen_set_func (Client * c, int argc, char **argv)
|
||||
if (0 == strcmp(argv[i], "block"))
|
||||
s->cursor = CURSOR_BLOCK;
|
||||
sock_send_string(c->sock, "success\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sock_send_error(c->sock, "-cursor requires a parameter\n");
|
||||
}
|
||||
}
|
||||
@@ -371,7 +380,8 @@ screen_set_func (Client * c, int argc, char **argv)
|
||||
else {
|
||||
sock_send_error(c->sock, "Cursor position outside screen\n");
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sock_send_error(c->sock, "-cursor_x requires a parameter\n");
|
||||
}
|
||||
}
|
||||
@@ -390,7 +400,8 @@ screen_set_func (Client * c, int argc, char **argv)
|
||||
else {
|
||||
sock_send_error(c->sock, "Cursor position outside screen\n");
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sock_send_error(c->sock, "-cursor_y requires a parameter\n");
|
||||
}
|
||||
}
|
||||
@@ -409,7 +420,6 @@ screen_set_func (Client * c, int argc, char **argv)
|
||||
int
|
||||
screen_add_key_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
/*widget * w ;*/ /* Keys are stored on a WID_KEYS widget */
|
||||
Screen *s; /* Attached to a specific screen */
|
||||
char *id; /* Screen ID */
|
||||
char *keys; /* Keys wanted */
|
||||
@@ -444,10 +454,11 @@ screen_add_key_func (Client * c, int argc, char **argv)
|
||||
}
|
||||
|
||||
/* Save the keys*/
|
||||
if (!s->keys) {
|
||||
if (s->keys == NULL) {
|
||||
/* Save supplied key list*/
|
||||
s->keys = strdup(keys);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
/* Add supplied keys to existing list
|
||||
* NOTE: There could be duplicates in the resulting list
|
||||
* That's OK, it's the existence of the key in the list
|
||||
@@ -461,15 +472,16 @@ screen_add_key_func (Client * c, int argc, char **argv)
|
||||
strcat(new_keys, keys);
|
||||
free(s->keys);
|
||||
s->keys = new_keys;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sock_send_error(c->sock, "Could not add new keys\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!s->keys) {
|
||||
if (s->keys == NULL)
|
||||
sock_send_error(c->sock, "failed\n");
|
||||
} else
|
||||
else
|
||||
sock_send_string(c->sock, "success\n");
|
||||
|
||||
return 0;
|
||||
@@ -484,7 +496,6 @@ screen_add_key_func (Client * c, int argc, char **argv)
|
||||
int
|
||||
screen_del_key_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
/*widget * w ;*/ /* Keys are stored on a WID_KEYS widget */
|
||||
Screen *s; /* Attached to a specific screen */
|
||||
char *id; /* Screen ID */
|
||||
char *keys; /* Keys wanted */
|
||||
@@ -513,14 +524,13 @@ screen_del_key_func (Client * c, int argc, char **argv)
|
||||
|
||||
/* Find the screen*/
|
||||
s = client_find_screen(c, id);
|
||||
|
||||
if (!s) {
|
||||
if (s == NULL) {
|
||||
sock_send_error(c->sock, "Unknown screen id\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Do we have keys?*/
|
||||
if (s->keys) {
|
||||
if (s->keys != NULL) {
|
||||
/* Have keys, remove keys from the list
|
||||
* NOTE: We let malloc/realloc remember the length
|
||||
* of the allocated storage. If keys are later
|
||||
@@ -531,12 +541,13 @@ screen_del_key_func (Client * c, int argc, char **argv)
|
||||
char *to;
|
||||
|
||||
to = from = s->keys;
|
||||
while( *from ) {
|
||||
while (*from != NULL) {
|
||||
/* Is this key to be deleted from the list? */
|
||||
if( strchr( keys, *from ) ) {
|
||||
if (strchr(keys, *from) == 0) {
|
||||
/* Yes, skip it */
|
||||
++from;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
/* No, save it */
|
||||
*to++ = *from++;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/* \file screen_commands.h
|
||||
* Declares handlers for client screen commands.
|
||||
*/
|
||||
|
||||
/*
|
||||
* screen_commands.h
|
||||
* This file is part of LCDd, the lcdproc server.
|
||||
*
|
||||
* This file is released under the GNU General Public License. Refer to the
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/* \file server_commands.c
|
||||
* Defines handlers for client commands concerning the server settings.
|
||||
*/
|
||||
|
||||
/*
|
||||
* server_commands.c
|
||||
* This file is part of LCDd, the lcdproc server.
|
||||
*
|
||||
* This file is released under the GNU General Public License. Refer to the
|
||||
@@ -14,9 +17,6 @@
|
||||
*
|
||||
* The client's available function set is defined here, as is the syntax
|
||||
* for each command.
|
||||
*
|
||||
* This particular file defines actions concerning the server settings.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
@@ -43,8 +43,8 @@
|
||||
int
|
||||
output_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
/*int rc = 0;*/
|
||||
char str[128];
|
||||
if (!c->ack)
|
||||
return 1;
|
||||
|
||||
if (argc != 2) {
|
||||
sock_send_error(c->sock, "Usage: output {on|off|<num>}\n");
|
||||
@@ -57,45 +57,26 @@ output_func (Client * c, int argc, char **argv)
|
||||
output_state = ALL_OUTPUTS_OFF;
|
||||
else {
|
||||
long out;
|
||||
char *endptr, *p;
|
||||
char *endptr;
|
||||
|
||||
/* Note that there is no valid range set for
|
||||
* output_state; thus a value in the 12 digits
|
||||
* is not considered out of range.
|
||||
*/
|
||||
|
||||
/* set errno to be able to detect errors in strtol() */
|
||||
errno = 0;
|
||||
|
||||
/* errno is set here, because if strtol does not result in
|
||||
* ERANGE (out of range error) it will not set errno (!).
|
||||
* At least, this is the case with glibc 2.1.3 ...
|
||||
*/
|
||||
|
||||
p = argv[1];
|
||||
out = strtol(p, &endptr, 0);
|
||||
|
||||
/* From the man page for strtol(3)
|
||||
*
|
||||
* In particular, if *nptr is not `\0' but **endptr is
|
||||
* `\0' on return, the entire string is valid.
|
||||
*
|
||||
* In this case, argv[1] is *nptr, and &endptr is **endptr.
|
||||
*/
|
||||
out = strtol(argv[1], &endptr, 0);
|
||||
|
||||
if (errno) {
|
||||
int space;
|
||||
|
||||
strcat(str, "number argument: ");
|
||||
space = sizeof(str) - 3 - strlen(str);
|
||||
|
||||
strncat(str, strerror(errno), space);
|
||||
strcat(str, "\n");
|
||||
|
||||
sock_send_error(c->sock, str);
|
||||
sock_printf_error(c->sock, "number argument: %s\n", strerror(errno));
|
||||
return 0;
|
||||
} else if (*p != '\0' && *endptr == '\0') {
|
||||
}
|
||||
else if ((*argv[1] != '\0') && (*endptr == '\0')) {
|
||||
output_state = out;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sock_send_error(c->sock, "invalid parameter...\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -124,26 +105,23 @@ sleep_func (Client * c, int argc, char **argv)
|
||||
{
|
||||
int secs;
|
||||
long out;
|
||||
char *endptr, *p;
|
||||
char str[120];
|
||||
char *endptr;
|
||||
|
||||
#define MAX_SECS 60
|
||||
#define MIN_SECS 1
|
||||
|
||||
if (!c->ack)
|
||||
return 1;
|
||||
|
||||
if (argc != 2) {
|
||||
sock_send_error(c->sock, "Usage: sleep <secs>\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* set errno to be able to detect errors in strtol() */
|
||||
errno = 0;
|
||||
|
||||
/* errno is set here, because if strtol does not result in
|
||||
* ERANGE (out of range error) it will not set errno (!).
|
||||
* At least, this is the case with glibc 2.1.3 ...
|
||||
*/
|
||||
|
||||
p = argv[1];
|
||||
out = strtol(p, &endptr, 0);
|
||||
out = strtol(argv[1], &endptr, 0);
|
||||
|
||||
/* From the man page for strtol(3)
|
||||
*
|
||||
@@ -154,29 +132,23 @@ sleep_func (Client * c, int argc, char **argv)
|
||||
*/
|
||||
|
||||
if (errno) {
|
||||
int space;
|
||||
|
||||
strcat(str, "number argument: ");
|
||||
space = sizeof(str) - 3 - strlen(str);
|
||||
|
||||
strncat(str, strerror(errno), space);
|
||||
strcat(str, "\n");
|
||||
|
||||
sock_send_error(c->sock, str);
|
||||
sock_printf_error(c->sock, "number argument: %s\n", strerror(errno));
|
||||
return 0;
|
||||
} else if (*p != '\0' && *endptr == '\0') {
|
||||
}
|
||||
else if ((*argv[1] != '\0') && (*endptr == '\0')) {
|
||||
/* limit seconds to range: MIN_SECS - MAX_SECS */
|
||||
out = (out > MAX_SECS) ? MAX_SECS : out;
|
||||
out = (out < MIN_SECS) ? MIN_SECS : out;
|
||||
secs = out;
|
||||
out = out > MAX_SECS ? MAX_SECS : out;
|
||||
out = out < MIN_SECS ? MIN_SECS : out;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
sock_send_error(c->sock, "invalid parameter...\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Repeat until no more remains - should normally be zero
|
||||
* on exit the first time...*/
|
||||
snprintf(str, sizeof(str), "sleeping %d seconds\n", secs);
|
||||
sock_send_string (c->sock, str);
|
||||
sock_printf(c->sock, "sleeping %d seconds\n", secs);
|
||||
|
||||
/* whoops.... if this takes place as planned, ALL screens
|
||||
* will "freeze" for the alloted time...
|
||||
@@ -198,6 +170,9 @@ sleep_func (Client * c, int argc, char **argv)
|
||||
int
|
||||
noop_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
if (!c->ack)
|
||||
return 1;
|
||||
|
||||
sock_send_string(c->sock, "noop complete\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/* \file server_commands.h
|
||||
* Declares handlers for client commands dealing with server properties.
|
||||
*/
|
||||
|
||||
/*
|
||||
* server_commands.h
|
||||
* This file is part of LCDd, the lcdproc server.
|
||||
*
|
||||
* This file is released under the GNU General Public License. Refer to the
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/* \file widget_commands.c
|
||||
* Defines handlers for client commands concerning widgets.
|
||||
*/
|
||||
|
||||
/*
|
||||
* widget_commands.c
|
||||
* This file is part of LCDd, the lcdproc server.
|
||||
*
|
||||
* This file is released under the GNU General Public License. Refer to the
|
||||
@@ -14,9 +17,6 @@
|
||||
*
|
||||
* The client's available function set is defined here, as is the syntax
|
||||
* for each command.
|
||||
*
|
||||
* This particular file defines actions concerning widgets.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
@@ -63,7 +63,7 @@ widget_add_func (Client * c, int argc, char **argv)
|
||||
wid = argv[2];
|
||||
|
||||
s = client_find_screen(c, sid);
|
||||
if (!s) {
|
||||
if (s == NULL) {
|
||||
sock_send_error(c->sock, "Invalid screen id\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -77,9 +77,9 @@ widget_add_func (Client * c, int argc, char **argv)
|
||||
|
||||
/* Check for additional flags...*/
|
||||
if (argc > 4) {
|
||||
char *p;
|
||||
char *p = argv[4];
|
||||
|
||||
p = argv[4];
|
||||
/* ignore leading '-' in options: we allow both forms */
|
||||
if (*p == '-')
|
||||
p++;
|
||||
|
||||
@@ -97,7 +97,7 @@ widget_add_func (Client * c, int argc, char **argv)
|
||||
* but in the framescreen.
|
||||
*/
|
||||
frame = screen_find_widget(s, argv[5]);
|
||||
if (!frame) {
|
||||
if (frame == NULL) {
|
||||
sock_send_error(c->sock, "Error finding frame\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -107,7 +107,7 @@ widget_add_func (Client * c, int argc, char **argv)
|
||||
|
||||
/* Create the widget */
|
||||
w = widget_create(wid, wtype, s);
|
||||
if (!w) {
|
||||
if (w == NULL) {
|
||||
sock_send_error(c->sock, "Error adding widget\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -116,9 +116,8 @@ widget_add_func (Client * c, int argc, char **argv)
|
||||
err = screen_add_widget(s, w);
|
||||
if (err == 0)
|
||||
sock_send_string(c->sock, "success\n");
|
||||
else {
|
||||
else
|
||||
sock_send_error(c->sock, "Error adding widget\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -152,13 +151,13 @@ widget_del_func (Client * c, int argc, char **argv)
|
||||
debug(RPT_DEBUG, "screen_del: Deleting widget %s.%s", sid, wid);
|
||||
|
||||
s = client_find_screen(c, sid);
|
||||
if (!s) {
|
||||
if (s == NULL) {
|
||||
sock_send_error(c->sock, "Invalid screen id\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
w = screen_find_widget(s, wid);
|
||||
if (!w) {
|
||||
if (w == NULL) {
|
||||
sock_send_error(c->sock, "Invalid widget id\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -166,9 +165,8 @@ widget_del_func (Client * c, int argc, char **argv)
|
||||
err = screen_remove_widget(s, w);
|
||||
if (err == 0)
|
||||
sock_send_string(c->sock, "success\n");
|
||||
else {
|
||||
else
|
||||
sock_send_error(c->sock, "Error removing widget\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -213,14 +211,14 @@ widget_set_func (Client * c, int argc, char **argv)
|
||||
/* Find screen */
|
||||
sid = argv[1];
|
||||
s = client_find_screen(c, sid);
|
||||
if (!s) {
|
||||
if (s == NULL) {
|
||||
sock_send_error(c->sock, "Unknown screen id\n");
|
||||
return 0;
|
||||
}
|
||||
/* Find widget */
|
||||
wid = argv[2];
|
||||
w = screen_find_widget(s, wid);
|
||||
if (!w) {
|
||||
if (w == NULL) {
|
||||
sock_send_error(c->sock, "Unknown widget id\n");
|
||||
/* Client Debugging...*/
|
||||
{
|
||||
@@ -240,17 +238,16 @@ widget_set_func (Client * c, int argc, char **argv)
|
||||
if ((!isdigit((unsigned int) argv[i][0])) ||
|
||||
(!isdigit((unsigned int) argv[i + 1][0]))) {
|
||||
sock_send_error(c->sock, "Invalid coordinates\n");
|
||||
} else /* Set all the data...*/
|
||||
{
|
||||
}
|
||||
else { /* Set all the data...*/
|
||||
x = atoi(argv[i]);
|
||||
y = atoi(argv[i + 1]);
|
||||
w->x = x;
|
||||
w->y = y;
|
||||
if (w->text)
|
||||
if (w->text != NULL)
|
||||
free(w->text);
|
||||
w->text = strdup(argv[i + 2]);
|
||||
if (!w->text) {
|
||||
debug (RPT_DEBUG, "Widget %s set to %s", wid, w->text);
|
||||
if (w->text == NULL) {
|
||||
report(RPT_WARNING, "widget_set_func: Allocation error");
|
||||
return -1;
|
||||
}
|
||||
@@ -306,12 +303,14 @@ widget_set_func (Client * c, int argc, char **argv)
|
||||
sock_send_error(c->sock, "Invalid coordinates\n");
|
||||
} else {
|
||||
int icon;
|
||||
|
||||
x = atoi(argv[i]);
|
||||
y = atoi(argv[i + 1]);
|
||||
icon = widget_iconname_to_icon(argv[i + 2]);
|
||||
if (icon == -1) {
|
||||
sock_send_error(c->sock, "Invalid icon name\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
w->x = x;
|
||||
w->y = y;
|
||||
w->length = icon;
|
||||
@@ -324,10 +323,10 @@ widget_set_func (Client * c, int argc, char **argv)
|
||||
if (argc != i + 1)
|
||||
sock_send_error(c->sock, "Wrong number of arguments\n");
|
||||
else {
|
||||
if (w->text)
|
||||
if (w->text != NULL)
|
||||
free(w->text);
|
||||
w->text = strdup(argv[i]);
|
||||
if (!w->text) {
|
||||
if (w->text == NULL) {
|
||||
report(RPT_WARNING, "widget_set_func: Allocation error");
|
||||
return -1;
|
||||
}
|
||||
@@ -338,42 +337,38 @@ widget_set_func (Client * c, int argc, char **argv)
|
||||
}
|
||||
break;
|
||||
case WID_SCROLLER: /* Scroller takes "left top right bottom direction speed text" */
|
||||
if (argc != i + 7) {
|
||||
if (argc != i + 7)
|
||||
sock_send_error(c->sock, "Wrong number of arguments\n");
|
||||
} else {
|
||||
else {
|
||||
if ((!isdigit((unsigned int) argv[i][0])) ||
|
||||
(!isdigit((unsigned int) argv[i + 1][0])) ||
|
||||
(!isdigit((unsigned int) argv[i + 2][0])) ||
|
||||
(!isdigit((unsigned int) argv[i + 3][0]))) {
|
||||
sock_send_error(c->sock, "Invalid coordinates\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
left = atoi(argv[i]);
|
||||
/*debug("left: %d",left);*/
|
||||
top = atoi(argv[i + 1]);
|
||||
/*debug("top: %d",top);*/
|
||||
right = atoi(argv[i + 2]);
|
||||
/*debug("right: %d",right);*/
|
||||
bottom = atoi(argv[i + 3]);
|
||||
/*debug("bottom: %d",bottom);*/
|
||||
direction = (int) (argv[i + 4][0]);
|
||||
/*debug("dir: %c",(char)direction);*/
|
||||
speed = atoi(argv[i + 5]);
|
||||
/*debug("speed: %d",speed);*/
|
||||
/* Direction must be m, v or h*/
|
||||
if (((char) direction != 'h') && ((char) direction != 'v') &&
|
||||
((char) direction != 'm')) {
|
||||
sock_send_error(c->sock, "Invalid direction\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
w->left = left;
|
||||
w->top = top;
|
||||
w->right = right;
|
||||
w->bottom = bottom;
|
||||
w->length = direction;
|
||||
w->speed = speed;
|
||||
if (w->text)
|
||||
if (w->text != NULL)
|
||||
free(w->text);
|
||||
w->text = strdup(argv[i + 6]);
|
||||
if (!w->text) {
|
||||
if (w->text == NULL) {
|
||||
sock_send_error(c->sock, "Allocation error\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -384,9 +379,9 @@ widget_set_func (Client * c, int argc, char **argv)
|
||||
}
|
||||
break;
|
||||
case WID_FRAME: /* Frame takes "left top right bottom wid hgt direction speed" */
|
||||
if (argc != i + 8) {
|
||||
if (argc != i + 8)
|
||||
sock_send_error(c->sock, "Wrong number of arguments\n");
|
||||
} else {
|
||||
else {
|
||||
if ((!isdigit((unsigned int) argv[i][0])) ||
|
||||
(!isdigit((unsigned int) argv[i + 1][0])) ||
|
||||
(!isdigit((unsigned int) argv[i + 2][0])) ||
|
||||
@@ -394,27 +389,21 @@ widget_set_func (Client * c, int argc, char **argv)
|
||||
(!isdigit((unsigned int) argv[i + 4][0])) ||
|
||||
(!isdigit((unsigned int) argv[i + 5][0]))) {
|
||||
sock_send_error(c->sock, "Invalid coordinates\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
left = atoi(argv[i]);
|
||||
/*debug("left: %d",left);*/
|
||||
top = atoi(argv[i + 1]);
|
||||
/*debug("top: %d",top);*/
|
||||
right = atoi(argv[i + 2]);
|
||||
/*debug("right: %d",right);*/
|
||||
bottom = atoi(argv[i + 3]);
|
||||
/*debug("bottom: %d",bottom);*/
|
||||
width = atoi(argv[i + 4]);
|
||||
/*debug("right: %d",right);*/
|
||||
height = atoi(argv[i + 5]);
|
||||
/*debug("bottom: %d",bottom);*/
|
||||
direction = (int) (argv[i + 6][0]);
|
||||
/*debug("dir: %c",(char)direction);*/
|
||||
speed = atoi(argv[i + 7]);
|
||||
/*debug("speed: %d",speed);*/
|
||||
/* Direction must be v or h*/
|
||||
if (((char) direction != 'h') && ((char) direction != 'v')) {
|
||||
sock_send_error(c->sock, "Invalid direction\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
w->left = left;
|
||||
w->top = top;
|
||||
w->right = right;
|
||||
@@ -435,9 +424,11 @@ widget_set_func (Client * c, int argc, char **argv)
|
||||
else {
|
||||
if (!isdigit((unsigned int) argv[i][0])) {
|
||||
sock_send_error(c->sock, "Invalid coordinates\n");
|
||||
} else if (!isdigit ((unsigned int) argv[i + 1][0])) {
|
||||
}
|
||||
else if (!isdigit((unsigned int) argv[i + 1][0])) {
|
||||
sock_send_error(c->sock, "Invalid number\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
x = atoi(argv[i]);
|
||||
y = atoi(argv[i + 1]);
|
||||
w->x = x;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/* \file widget_commands.h
|
||||
* Declares handlers for client widget commands.
|
||||
*/
|
||||
|
||||
/*
|
||||
* widget_commands.h
|
||||
* This file is part of LCDd, the lcdproc server.
|
||||
*
|
||||
* This file is released under the GNU General Public License. Refer to the
|
||||
|
||||
Reference in New Issue
Block a user