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>
|
||||
@@ -38,15 +38,13 @@
|
||||
* Debugging only.. prints out a list of arguments it receives
|
||||
*/
|
||||
int
|
||||
test_func_func (Client * c, int argc, char **argv)
|
||||
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;
|
||||
}
|
||||
@@ -59,10 +57,8 @@ test_func_func (Client * c, int argc, char **argv)
|
||||
* Usage: hello
|
||||
*/
|
||||
int
|
||||
hello_func (Client * c, int argc, char **argv)
|
||||
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;
|
||||
@@ -92,7 +86,7 @@ hello_func (Client * c, int argc, char **argv)
|
||||
* Usage: bye
|
||||
*/
|
||||
int
|
||||
bye_func (Client * c, int argc, char **argv)
|
||||
bye_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
if (c != NULL) {
|
||||
debug(RPT_INFO, "Bye, %s!", (c->name != NULL) ? c->name : "unknown client");
|
||||
@@ -108,12 +102,10 @@ bye_func (Client * c, int argc, char **argv)
|
||||
* Usage: client_set -name <id>
|
||||
*/
|
||||
int
|
||||
client_set_func (Client * c, int argc, char **argv)
|
||||
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,40 +116,35 @@ 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*/
|
||||
if (strcmp (p, "name") == 0) {
|
||||
/* Handle the "name" option */
|
||||
if (strcmp(p, "name") == 0) {
|
||||
i++;
|
||||
if (argv[i] == '\0') {
|
||||
sock_printf_error(c->sock, "internal error: no parameter #%d\n", i);
|
||||
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]);
|
||||
|
||||
debug(RPT_DEBUG, "client_set: name=\"%s\"", argv[i]);
|
||||
/* set the name...*/
|
||||
if (c->name != NULL)
|
||||
free(c->name);
|
||||
|
||||
/* set the name...*/
|
||||
if (c->name)
|
||||
free (c->name);
|
||||
|
||||
if ((c->name = strdup (str)) == NULL) {
|
||||
sock_send_error(c->sock, "error allocating memory!\n");
|
||||
} else {
|
||||
sock_send_string(c->sock, "success\n");
|
||||
i++; /* bypass argument (name string)*/
|
||||
}
|
||||
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 {
|
||||
sock_printf_error(c->sock, "invalid parameter (%s)\n", p);
|
||||
}
|
||||
} while (++i < argc);
|
||||
@@ -171,9 +158,8 @@ 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)
|
||||
client_add_key_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
int exclusively = 0;
|
||||
int argnr;
|
||||
@@ -187,20 +173,20 @@ client_add_key_func (Client * c, int argc, char **argv)
|
||||
}
|
||||
|
||||
argnr = 1;
|
||||
if( argv[argnr][0] == '-' ) {
|
||||
if( strcmp( argv[argnr], "-shared") == 0 ) {
|
||||
if (argv[argnr][0] == '-') {
|
||||
if (strcmp( argv[argnr], "-shared") == 0) {
|
||||
exclusively = 0;
|
||||
}
|
||||
else if( strcmp( argv[argnr], "-exclusively") == 0 ) {
|
||||
else if(strcmp(argv[argnr], "-exclusively") == 0) {
|
||||
exclusively = 1;
|
||||
}
|
||||
else {
|
||||
sock_printf_error(c->sock, "Invalid option: %s\n", argv[argnr]);
|
||||
}
|
||||
argnr ++;
|
||||
argnr++;
|
||||
}
|
||||
for ( ; argnr < argc; argnr++ ) {
|
||||
if( input_reserve_key( argv[argnr], exclusively, c ) < 0 ) {
|
||||
for ( ; argnr < argc; argnr++) {
|
||||
if (input_reserve_key(argv[argnr], exclusively, c) < 0) {
|
||||
sock_printf_error(c->sock, "Could not reserve key \"%s\"\n", argv[argnr]);
|
||||
}
|
||||
}
|
||||
@@ -216,7 +202,7 @@ client_add_key_func (Client * c, int argc, char **argv)
|
||||
* Usage: client_del_key {<key>}+
|
||||
*/
|
||||
int
|
||||
client_del_key_func (Client * c, int argc, char **argv)
|
||||
client_del_key_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
int argnr;
|
||||
|
||||
@@ -228,8 +214,8 @@ client_del_key_func (Client * c, int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
for( argnr=1; argnr < argc; argnr++) {
|
||||
input_release_key( argv[argnr], c );
|
||||
for (argnr = 1; argnr < argc; argnr++) {
|
||||
input_release_key(argv[argnr], c);
|
||||
}
|
||||
sock_send_string(c->sock, "success\n");
|
||||
|
||||
@@ -242,7 +228,7 @@ client_del_key_func (Client * c, int argc, char **argv)
|
||||
* Usage: backlight {on|off|toggle|blink|flash}
|
||||
*/
|
||||
int
|
||||
backlight_func (Client * c, int argc, char **argv)
|
||||
backlight_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
if (!c->ack)
|
||||
return 1;
|
||||
@@ -252,27 +238,27 @@ backlight_func (Client * c, int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
debug (RPT_DEBUG, "backlight(%s)", argv[1]);
|
||||
debug(RPT_DEBUG, "backlight(%s)", argv[1]);
|
||||
|
||||
|
||||
//backlight = (backlight && 1); /* only preserves ON/OFF bit*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -288,19 +274,16 @@ backlight_func (Client * c, int argc, char **argv)
|
||||
* Usage: info
|
||||
*/
|
||||
int
|
||||
info_func (Client * c, int argc, char **argv)
|
||||
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
|
||||
@@ -13,12 +16,12 @@
|
||||
#ifndef COMMANDS_CLIENT_H
|
||||
#define COMMANDS_CLIENT_H
|
||||
|
||||
int hello_func (Client * c, int argc, char **argv);
|
||||
int bye_func (Client * c, int argc, char **argv);
|
||||
int client_set_func (Client * c, int argc, char **argv);
|
||||
int client_add_key_func (Client * c, int argc, char **argv);
|
||||
int client_del_key_func (Client * c, int argc, char **argv);
|
||||
int backlight_func (Client * c, int argc, char **argv);
|
||||
int hello_func(Client *c, int argc, char **argv);
|
||||
int bye_func(Client *c, int argc, char **argv);
|
||||
int client_set_func(Client *c, int argc, char **argv);
|
||||
int client_add_key_func(Client *c, int argc, char **argv);
|
||||
int client_del_key_func(Client *c, int argc, char **argv);
|
||||
int backlight_func(Client *c, int argc, char **argv);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -19,7 +22,7 @@
|
||||
point to a function to call, defined below.
|
||||
*/
|
||||
|
||||
typedef int (*CommandFunc) (Client * c, int argc, char **argv);
|
||||
typedef int (*CommandFunc) (Client *c, int argc, char **argv);
|
||||
|
||||
typedef struct client_function {
|
||||
char *keyword;
|
||||
|
||||
+246
-257
@@ -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, " ");
|
||||
}
|
||||
@@ -87,27 +86,27 @@ static char *argv2string(int argc, char **argv)
|
||||
* - ip
|
||||
*/
|
||||
int
|
||||
menu_add_item_func (Client * c, int argc, char **argv)
|
||||
menu_add_item_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
char * menu_id;
|
||||
char * item_id;
|
||||
char * text = NULL;
|
||||
Menu * menu = NULL;
|
||||
MenuItem * item;
|
||||
char *menu_id;
|
||||
char *item_id;
|
||||
char *text = NULL;
|
||||
Menu *menu = NULL;
|
||||
MenuItem *item;
|
||||
MenuItemType itemtype;
|
||||
char** argv_set = NULL;
|
||||
char **argv_set = NULL;
|
||||
|
||||
debug (RPT_DEBUG, "%s( Client [%d], %s, %s )",
|
||||
debug(RPT_DEBUG, "%s(Client [%d], %s, %s)",
|
||||
__FUNCTION__, c->sock, argv[1], argv[2]);
|
||||
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,40 +115,37 @@ 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);
|
||||
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) {
|
||||
item = menu_find_item(c->menu, item_id, true);
|
||||
if (item != NULL) {
|
||||
sock_send_error(c->sock, "Item id already in use\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Find menuitem type */
|
||||
itemtype = menuitem_typename_to_type (argv[3]);
|
||||
itemtype = menuitem_typename_to_type(argv[3]);
|
||||
if (itemtype == -1) {
|
||||
sock_send_error(c->sock, "Invalid menuitem type\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Is a text given (options don't count)? */
|
||||
if (argc >= 5 && argv[4][0] != '-') {
|
||||
if ((argc >= 5) && (argv[4][0] != '-')) {
|
||||
text = argv[4];
|
||||
}
|
||||
else {
|
||||
@@ -159,59 +155,58 @@ menu_add_item_func (Client * c, int argc, char **argv)
|
||||
/* Create the menuitem */
|
||||
switch (itemtype) {
|
||||
case MENUITEM_MENU:
|
||||
item = menu_create (item_id, menu_commands_handler, text, c);
|
||||
item = menu_create(item_id, menu_commands_handler, text, c);
|
||||
break;
|
||||
case MENUITEM_ACTION:
|
||||
item = menuitem_create_action (item_id, menu_commands_handler, text, c,
|
||||
item = menuitem_create_action(item_id, menu_commands_handler, text, c,
|
||||
MENURESULT_NONE);
|
||||
break;
|
||||
case MENUITEM_CHECKBOX:
|
||||
item = menuitem_create_checkbox (item_id, menu_commands_handler, text, c,
|
||||
item = menuitem_create_checkbox(item_id, menu_commands_handler, text, c,
|
||||
false, false);
|
||||
break;
|
||||
case MENUITEM_RING:
|
||||
item = menuitem_create_ring (item_id, menu_commands_handler, text, c,
|
||||
item = menuitem_create_ring(item_id, menu_commands_handler, text, c,
|
||||
"", 0);
|
||||
break;
|
||||
case MENUITEM_SLIDER:
|
||||
item = menuitem_create_slider (item_id, menu_commands_handler, text, c,
|
||||
item = menuitem_create_slider(item_id, menu_commands_handler, text, c,
|
||||
"", "", 0, 100, 1, 25);
|
||||
break;
|
||||
case MENUITEM_NUMERIC:
|
||||
item = menuitem_create_numeric (item_id, menu_commands_handler, text, c,
|
||||
item = menuitem_create_numeric(item_id, menu_commands_handler, text, c,
|
||||
0, 100, 0);
|
||||
break;
|
||||
case MENUITEM_ALPHA:
|
||||
item = menuitem_create_alpha (item_id, menu_commands_handler, text, c,
|
||||
item = menuitem_create_alpha(item_id, menu_commands_handler, text, c,
|
||||
0, 0, 10, true, false, true, "-./", "");
|
||||
break;
|
||||
case MENUITEM_IP:
|
||||
item = menuitem_create_ip (item_id, menu_commands_handler, text, c,
|
||||
item = menuitem_create_ip(item_id, menu_commands_handler, text, c,
|
||||
0, "192.168.1.245");
|
||||
break;
|
||||
default:
|
||||
assert(!"unexpected menuitem type");
|
||||
}
|
||||
menu_add_item (menu, item);
|
||||
menuscreen_inform_item_modified (menu);
|
||||
menu_add_item(menu, item);
|
||||
menuscreen_inform_item_modified(menu);
|
||||
sock_send_string(c->sock, "success\n");
|
||||
|
||||
/* 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*));
|
||||
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];
|
||||
@@ -232,17 +227,17 @@ menu_add_item_func (Client * c, int argc, char **argv)
|
||||
* the items from your client menu, that menu will automatically be removed.
|
||||
*/
|
||||
int
|
||||
menu_del_item_func (Client * c, int argc, char **argv)
|
||||
menu_del_item_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
Menu * menu;
|
||||
MenuItem * item;
|
||||
char * menu_id;
|
||||
char * item_id;
|
||||
Menu *menu;
|
||||
MenuItem *item;
|
||||
char *menu_id;
|
||||
char *item_id;
|
||||
|
||||
if (!c->ack)
|
||||
return 1;
|
||||
|
||||
if (argc != 3 ) {
|
||||
if (argc != 3) {
|
||||
sock_send_error(c->sock, "Usage: menu_del_item <menuid> <itemid>\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -251,39 +246,36 @@ 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) {
|
||||
item = menu_find_item(c->menu, item_id, true);
|
||||
if (item == NULL) {
|
||||
sock_send_error(c->sock, "Cannot find item\n");
|
||||
return 0;
|
||||
}
|
||||
menuscreen_inform_item_destruction (item);
|
||||
menu_remove_item (menu, item);
|
||||
menuscreen_inform_item_modified (item->parent);
|
||||
menuitem_destroy (item);
|
||||
menuscreen_inform_item_destruction(item);
|
||||
menu_remove_item(menu, item);
|
||||
menuscreen_inform_item_modified(item->parent);
|
||||
menuitem_destroy(item);
|
||||
|
||||
/* Was it the last item in the client's menu ? */
|
||||
if (menu_getfirst_item(c->menu) == NULL) {
|
||||
menuscreen_inform_item_destruction (c->menu);
|
||||
menu_remove_item (main_menu, c->menu);
|
||||
menuscreen_inform_item_modified (main_menu);
|
||||
menu_destroy (c->menu);
|
||||
menuscreen_inform_item_destruction(c->menu);
|
||||
menu_remove_item(main_menu, c->menu);
|
||||
menuscreen_inform_item_modified(main_menu);
|
||||
menu_destroy(c->menu);
|
||||
c->menu = NULL;
|
||||
}
|
||||
sock_send_string(c->sock, "success\n");
|
||||
@@ -377,7 +369,7 @@ menu_del_item_func (Client * c, int argc, char **argv)
|
||||
* Hmm, this is getting very big. We might need a some real parser after all.
|
||||
*/
|
||||
int
|
||||
menu_set_item_func (Client * c, int argc, char **argv)
|
||||
menu_set_item_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
typedef enum AttrType { NOVALUE, BOOLEAN, CHECKBOX_VALUE, SHORT, INT,
|
||||
FLOAT, STRING } AttrType;
|
||||
@@ -391,7 +383,7 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
MenuItemType menuitem_type; /* For what MenuItem type is
|
||||
the option ?
|
||||
Use -1 for ALL types. */
|
||||
char * name; /* The option concerned */
|
||||
char *name; /* The option concerned */
|
||||
AttrType attr_type; /* Type of value */
|
||||
int attr_offset; /* Where to put the value
|
||||
in the structure.
|
||||
@@ -403,7 +395,7 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
} option_table[] = {
|
||||
{ -1, "text", STRING, offsetof(MenuItem,text) },
|
||||
{ -1, "is_hidden", BOOLEAN, offsetof(MenuItem,is_hidden) },
|
||||
{ -1, "prev", STRING, -1 },
|
||||
{ -1, "prev", STRING, -1 },
|
||||
{ -1, "next", STRING, -1 },
|
||||
{ MENUITEM_ACTION, "menu_result", STRING, -1 },
|
||||
{ MENUITEM_CHECKBOX, "value", CHECKBOX_VALUE, offsetof(MenuItem,data.checkbox.value) },
|
||||
@@ -438,20 +430,20 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
short short_value = 0;
|
||||
int int_value = 0;
|
||||
float float_value = 0;
|
||||
char * string_value = NULL;
|
||||
char *string_value = NULL;
|
||||
|
||||
Menu * menu;
|
||||
MenuItem * item;
|
||||
char * menu_id;
|
||||
char * item_id;
|
||||
Menu *menu;
|
||||
MenuItem *item;
|
||||
char *menu_id;
|
||||
char *item_id;
|
||||
int argnr;
|
||||
|
||||
debug (RPT_DEBUG, "%s( Client [%d]: %s)",
|
||||
debug(RPT_DEBUG, "%s(Client [%d]: %s)",
|
||||
__FUNCTION__, c->sock, argv2string(argc, argv));
|
||||
if (!c->ack)
|
||||
return 1;
|
||||
|
||||
if (argc < 4 ) {
|
||||
if (argc < 4) {
|
||||
sock_send_error(c->sock, "Usage: menu_set_item <menuid> <itemid> {<option>}+\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -459,40 +451,38 @@ 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) {
|
||||
item = menu_find_item(c->menu, item_id, true);
|
||||
if (item == NULL) {
|
||||
sock_send_error(c->sock, "Cannot find item\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Scan all arguments */
|
||||
for( argnr = 3; argnr < argc; argnr ++) {
|
||||
for (argnr = 3; argnr < argc; argnr++) {
|
||||
int option_nr = -1;
|
||||
int found_option_name = 0;
|
||||
int error = 0;
|
||||
void * location;
|
||||
char * p;
|
||||
void *location;
|
||||
char *p;
|
||||
|
||||
/* Find the option in the table */
|
||||
if( argv[argnr][0] == '-' ) {
|
||||
if (argv[argnr][0] == '-') {
|
||||
int i;
|
||||
for( i=0; option_table[i].name; i++ ) {
|
||||
if( strcmp( argv[argnr]+1, option_table[i].name ) == 0 ) {
|
||||
|
||||
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
|
||||
|| option_table[i].menuitem_type == -1 ) {
|
||||
if (item->type == option_table[i].menuitem_type
|
||||
|| option_table[i].menuitem_type == -1) {
|
||||
option_nr = i;
|
||||
}
|
||||
}
|
||||
@@ -502,10 +492,11 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
sock_printf_error(c->sock, "Found non-option: \"%.40s\"\n", argv[argnr]);
|
||||
continue; /* Skip to next arg */
|
||||
}
|
||||
if( option_nr == -1 ) {
|
||||
if( found_option_name ) {
|
||||
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 */
|
||||
@@ -514,80 +505,85 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
/* OK, we now know we have an option that is valid for the item type. */
|
||||
|
||||
/* Check for value */
|
||||
if( option_table[option_nr].attr_type != NOVALUE ) {
|
||||
if( argnr + 1 >= argc ) {
|
||||
if (option_table[option_nr].attr_type != NOVALUE) {
|
||||
if (argnr + 1 >= argc) {
|
||||
sock_printf_error(c->sock, "Missing value at option: \"%.40s\"\n", argv[argnr]);
|
||||
continue; /* Skip to next arg (probably is not existing :) */
|
||||
}
|
||||
}
|
||||
/* Process the value that goes with the option */
|
||||
location = (void*)item + option_table[option_nr].attr_offset;
|
||||
switch( option_table[option_nr].attr_type ) {
|
||||
location = (void *) item + option_table[option_nr].attr_offset;
|
||||
switch (option_table[option_nr].attr_type) {
|
||||
case NOVALUE:
|
||||
break;
|
||||
case BOOLEAN:
|
||||
if( strcmp( argv[argnr+1], "false" ) == 0 ) {
|
||||
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;
|
||||
}
|
||||
if( option_table[option_nr].attr_offset != -1 ) {
|
||||
*(bool *)location = bool_value;
|
||||
if (option_table[option_nr].attr_offset != -1) {
|
||||
*(bool *) location = bool_value;
|
||||
}
|
||||
break;
|
||||
case CHECKBOX_VALUE:
|
||||
if( strcmp( argv[argnr+1], "off" ) == 0 ) {
|
||||
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;
|
||||
}
|
||||
if( option_table[option_nr].attr_offset != -1 ) {
|
||||
*(CheckboxValue *)location = checkbox_value;
|
||||
if (option_table[option_nr].attr_offset != -1) {
|
||||
*(CheckboxValue *) location = checkbox_value;
|
||||
}
|
||||
break;
|
||||
case SHORT:
|
||||
short_value = strtol( argv[argnr+1], &p, 0 );
|
||||
if( argv[argnr+1][0] == '\0' || *p != '\0' ) {
|
||||
short_value = strtol(argv[argnr+1], &p, 0);
|
||||
if ((argv[argnr+1][0] == '\0') || (*p != '\0')) {
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
if( option_table[option_nr].attr_offset != -1 ) {
|
||||
*(short*)location = short_value;
|
||||
if (option_table[option_nr].attr_offset != -1) {
|
||||
*(short *) location = short_value;
|
||||
}
|
||||
break;
|
||||
case INT:
|
||||
int_value = strtol( argv[argnr+1], &p, 0 );
|
||||
if( argv[argnr+1][0] == '\0' || *p != '\0' ) {
|
||||
int_value = strtol(argv[argnr+1], &p, 0);
|
||||
if ((argv[argnr+1][0] == '\0') || (*p != '\0')) {
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
if( option_table[option_nr].attr_offset != -1 ) {
|
||||
*(int*)location = int_value;
|
||||
if (option_table[option_nr].attr_offset != -1) {
|
||||
*(int *) location = int_value;
|
||||
}
|
||||
break;
|
||||
case FLOAT:
|
||||
float_value = strtod( argv[argnr+1], &p );
|
||||
if( argv[argnr+1][0] == '\0' || *p != '\0' ) {
|
||||
float_value = strtod(argv[argnr+1], &p);
|
||||
if ((argv[argnr+1][0] == '\0') || (*p != '\0')) {
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
if( option_table[option_nr].attr_offset != -1 ) {
|
||||
*(float*)location = float_value;
|
||||
if (option_table[option_nr].attr_offset != -1) {
|
||||
*(float *) location = float_value;
|
||||
}
|
||||
break;
|
||||
case STRING:
|
||||
string_value = argv[argnr+1];
|
||||
if( option_table[option_nr].attr_offset != -1 ) {
|
||||
free( *(char**)location );
|
||||
*(char**)location = strdup( string_value );
|
||||
if (option_table[option_nr].attr_offset != -1) {
|
||||
free(*(char **) location);
|
||||
*(char **) location = strdup(string_value);
|
||||
}
|
||||
else if (strcmp(argv[argnr], "-prev") == 0) {
|
||||
set_predecessor(item, string_value, c);
|
||||
@@ -597,7 +593,7 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
}
|
||||
break;
|
||||
}
|
||||
switch( error ) {
|
||||
switch (error) {
|
||||
case 1:
|
||||
sock_printf_error(c->sock, "Could not interpret value at option: \"%.40s\"\n", argv[argnr]);
|
||||
argnr ++;
|
||||
@@ -608,86 +604,90 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
* Most useful for the attr_offset==-1 stuff. */
|
||||
switch (item->type) {
|
||||
case MENUITEM_ACTION:
|
||||
if( strcmp( argv[argnr]+1, "menu_result" ) == 0 ) {
|
||||
if( strcmp( argv[argnr+1], "none" ) == 0 ) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MENUITEM_SLIDER:
|
||||
if( item->data.slider.value < item->data.slider.minvalue ) {
|
||||
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;
|
||||
case MENUITEM_RING:
|
||||
if( strcmp( argv[argnr]+1, "strings" ) == 0 ) {
|
||||
free (item->data.ring.strings);
|
||||
item->data.ring.strings = tablist2linkedlist (string_value);
|
||||
if (strcmp(argv[argnr]+1, "strings") == 0) {
|
||||
free(item->data.ring.strings);
|
||||
item->data.ring.strings = tablist2linkedlist(string_value);
|
||||
}
|
||||
item->data.ring.value %= LL_Length( item->data.ring.strings );
|
||||
item->data.ring.value %= LL_Length(item->data.ring.strings);
|
||||
break;
|
||||
case MENUITEM_NUMERIC:
|
||||
menuitem_reset (item);
|
||||
menuitem_reset(item);
|
||||
break;
|
||||
case MENUITEM_ALPHA:
|
||||
if( strcmp( argv[argnr]+1, "password_char" ) == 0 ) {
|
||||
if (strcmp(argv[argnr]+1, "password_char") == 0) {
|
||||
item->data.alpha.password_char = string_value[0];
|
||||
}
|
||||
else if( strcmp( argv[argnr]+1, "maxlength" ) == 0 ) {
|
||||
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;
|
||||
}
|
||||
new_buf = malloc( short_value + 1 );
|
||||
strncpy( new_buf, item->data.alpha.value, short_value );
|
||||
new_buf = malloc(short_value + 1);
|
||||
strncpy(new_buf, item->data.alpha.value, short_value);
|
||||
new_buf[short_value] = '\0'; /* terminate */
|
||||
free( item->data.alpha.value );
|
||||
free(item->data.alpha.value);
|
||||
item->data.alpha.value = new_buf;
|
||||
free( item->data.alpha.edit_str );
|
||||
item->data.alpha.edit_str = malloc( short_value + 1 );
|
||||
free(item->data.alpha.edit_str);
|
||||
item->data.alpha.edit_str = malloc(short_value + 1);
|
||||
item->data.alpha.edit_str[0] = '\0';
|
||||
}
|
||||
else if( strcmp( argv[argnr]+1, "value" ) == 0 ) {
|
||||
strncpy( item->data.alpha.value, string_value, item->data.alpha.maxlength );
|
||||
else if (strcmp(argv[argnr]+1, "value") == 0) {
|
||||
strncpy(item->data.alpha.value, string_value, item->data.alpha.maxlength);
|
||||
item->data.alpha.value[ item->data.alpha.maxlength ] = 0; /* terminate */
|
||||
}
|
||||
menuitem_reset (item);
|
||||
menuitem_reset(item);
|
||||
break;
|
||||
case MENUITEM_IP:
|
||||
if( strcmp( argv[argnr]+1, "v6" ) == 0 ) {
|
||||
if (strcmp(argv[argnr]+1, "v6") == 0) {
|
||||
char * new_buf;
|
||||
/* set max lenth depending ob boolean option v6 */
|
||||
item->data.ip.maxlength = (bool_value == 0) ? 15 : 39;
|
||||
|
||||
new_buf = malloc(item->data.ip.maxlength + 1 );
|
||||
strncpy( new_buf, item->data.ip.value, item->data.ip.maxlength);
|
||||
new_buf = malloc(item->data.ip.maxlength + 1);
|
||||
strncpy(new_buf, item->data.ip.value, item->data.ip.maxlength);
|
||||
|
||||
new_buf[item->data.ip.maxlength] = '\0'; /* terminate */
|
||||
free( item->data.ip.value );
|
||||
free(item->data.ip.value);
|
||||
item->data.ip.value = new_buf;
|
||||
free( item->data.ip.edit_str );
|
||||
item->data.ip.edit_str = malloc( item->data.ip.maxlength +1);
|
||||
free(item->data.ip.edit_str);
|
||||
item->data.ip.edit_str = malloc(item->data.ip.maxlength +1);
|
||||
item->data.ip.edit_str[0] = '\0';
|
||||
}
|
||||
else if( strcmp( argv[argnr]+1, "value" ) == 0 ) {
|
||||
strncpy( item->data.ip.value, string_value, item->data.ip.maxlength );
|
||||
else if (strcmp(argv[argnr]+1, "value") == 0) {
|
||||
strncpy(item->data.ip.value, string_value, item->data.ip.maxlength);
|
||||
item->data.ip.value[item->data.ip.maxlength] = '\0'; /* terminate */
|
||||
}
|
||||
menuitem_reset (item);
|
||||
menuitem_reset(item);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch( error ) {
|
||||
switch (error) {
|
||||
case 1:
|
||||
sock_printf_error(c->sock, "Could not interpret value at option: \"%.40s\"\n", argv[argnr]);
|
||||
continue; /* Skip to next arg and retry it as an option */
|
||||
@@ -696,8 +696,8 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
argnr ++;
|
||||
continue; /* Skip current option and the invalid value */
|
||||
}
|
||||
menuscreen_inform_item_modified (item);
|
||||
if( option_table[option_nr].attr_type != NOVALUE ) {
|
||||
menuscreen_inform_item_modified(item);
|
||||
if (option_table[option_nr].attr_type != NOVALUE) {
|
||||
/* Skip the now used argument */
|
||||
argnr ++;
|
||||
}
|
||||
@@ -715,41 +715,37 @@ menu_set_item_func (Client * c, int argc, char **argv)
|
||||
* Usage: menu_goto <id> [<predecessor_id>]
|
||||
*/
|
||||
int
|
||||
menu_goto_func (Client * c, int argc, char **argv)
|
||||
menu_goto_func(Client * c, int argc, char **argv)
|
||||
{
|
||||
char * menu_id;
|
||||
Menu * menu;
|
||||
char *menu_id;
|
||||
Menu *menu;
|
||||
|
||||
debug (RPT_DEBUG, "%s( Client [%d], %s, %s )",
|
||||
__FUNCTION__, c->sock, (argc > 1 ? argv[1] : "<null>"),
|
||||
(argc > 2 ? argv[2] : "<null>") );
|
||||
debug(RPT_DEBUG, "%s(Client [%d], %s, %s)",
|
||||
__FUNCTION__, c->sock, ((argc > 1) ? argv[1] : "<null>"),
|
||||
((argc > 2) ? argv[2] : "<null>"));
|
||||
if (!c->ack)
|
||||
return 1;
|
||||
|
||||
if ((argc < 2 ) || (argc > 3)) {
|
||||
if ((argc < 2) || (argc > 3)) {
|
||||
sock_send_error(c->sock, "Usage: menu_goto <menuid> [<predecessor_id>]\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (argc > 2 )
|
||||
if (argc > 2)
|
||||
set_predecessor(menu, argv[2], c);
|
||||
|
||||
menuscreen_goto (menu);
|
||||
menuscreen_goto(menu);
|
||||
/* Failure is not returned (Robijn) */
|
||||
sock_send_string(c->sock, "success\n");
|
||||
return 0;
|
||||
@@ -766,24 +762,24 @@ 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;
|
||||
}
|
||||
}
|
||||
debug(RPT_DEBUG, "%s( Client [%d], ... )"
|
||||
debug(RPT_DEBUG, "%s(Client [%d], ...)"
|
||||
" 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,31 +799,30 @@ 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));
|
||||
return -1;
|
||||
}
|
||||
debug (RPT_DEBUG, "%s( Client [%d], ... )"
|
||||
debug(RPT_DEBUG, "%s(Client [%d], ...)"
|
||||
" 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;
|
||||
@@ -839,25 +834,25 @@ int set_successor(MenuItem *item, char *itemid, Client *c)
|
||||
* Usage: menu_set_main <id>
|
||||
*/
|
||||
int
|
||||
menu_set_main_func (Client * c, int argc, char **argv)
|
||||
menu_set_main_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
char * menu_id;
|
||||
Menu * menu;
|
||||
char *menu_id;
|
||||
Menu *menu;
|
||||
|
||||
debug (RPT_DEBUG, "%s( Client [%d], %s, %s )",
|
||||
__FUNCTION__, c->sock, (argc > 1 ? argv[1] : "<null>"),
|
||||
(argc > 2 ? argv[2] : "<null>") );
|
||||
debug(RPT_DEBUG, "%s(Client [%d], %s, %s)",
|
||||
__FUNCTION__, c->sock, ((argc > 1) ? argv[1] : "<null>"),
|
||||
((argc > 2) ? argv[2] : "<null>"));
|
||||
if (!c->ack)
|
||||
return 1;
|
||||
|
||||
if (argc != 2 ) {
|
||||
if (argc != 2) {
|
||||
sock_send_error(c->sock, "Usage: menu_set_main <menuid>\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
menu_id = argv[1];
|
||||
|
||||
if ( menu_id[0] == 0 ) {
|
||||
if (menu_id[0] == '\0') {
|
||||
/* No menu specified = client's main menu */
|
||||
menu = c->menu;
|
||||
}
|
||||
@@ -866,8 +861,8 @@ 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) {
|
||||
menu = menu_find_item(c->menu, menu_id, true);
|
||||
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)
|
||||
MenuEventFunc(menu_commands_handler)
|
||||
{
|
||||
char buf[80] = "";
|
||||
Client * c;
|
||||
Client *c;
|
||||
|
||||
/* Compose message */
|
||||
if( event == MENUEVENT_UPDATE
|
||||
|| event == MENUEVENT_MINUS
|
||||
|| event == MENUEVENT_PLUS) {
|
||||
switch( item->type ) {
|
||||
/* Where should the message go to ? */
|
||||
c = menuitem_get_client(item);
|
||||
if (c == NULL) {
|
||||
report(RPT_ERR, "%s: Could not find client of item \"%s\"",
|
||||
__FUNCTION__, item->id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Compose & send 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",
|
||||
sock_printf(c->sock, "menuevent %s %.40s %s\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id, ((char*[]){"off","on","gray"})[item->data.checkbox.value] );
|
||||
item->id, ((char *[]) {"off","on","gray"})[item->data.checkbox.value]);
|
||||
break;
|
||||
case MENUITEM_SLIDER:
|
||||
snprintf (buf, sizeof(buf)-1, "menuevent %s %.40s %d\n",
|
||||
sock_printf(c->sock, "menuevent %s %.40s %d\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id, item->data.slider.value );
|
||||
item->id, item->data.slider.value);
|
||||
break;
|
||||
case MENUITEM_RING:
|
||||
snprintf (buf, sizeof(buf)-1, "menuevent %s %.40s %d\n",
|
||||
sock_printf(c->sock, "menuevent %s %.40s %d\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id, item->data.ring.value );
|
||||
item->id, item->data.ring.value);
|
||||
break;
|
||||
case MENUITEM_NUMERIC:
|
||||
snprintf (buf, sizeof(buf)-1, "menuevent %s %.40s %d\n",
|
||||
sock_printf(c->sock, "menuevent %s %.40s %d\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id, item->data.numeric.value );
|
||||
item->id, item->data.numeric.value);
|
||||
break;
|
||||
case MENUITEM_ALPHA:
|
||||
snprintf (buf, sizeof(buf)-1, "menuevent %s %.40s %.40s\n",
|
||||
sock_printf(c->sock, "menuevent %s %.40s %.40s\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id, item->data.alpha.value );
|
||||
item->id, item->data.alpha.value);
|
||||
break;
|
||||
case MENUITEM_IP:
|
||||
snprintf (buf, sizeof(buf)-1, "menuevent %s %.40s %.40s\n",
|
||||
sock_printf(c->sock, "menuevent %s %.40s %.40s\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id, item->data.ip.value );
|
||||
item->id, item->data.ip.value);
|
||||
break;
|
||||
default:
|
||||
snprintf (buf, sizeof(buf)-1, "menuevent %s %.40s\n",
|
||||
sock_printf(c->sock, "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 if ((event == MENUEVENT_ENTER) ||
|
||||
(event == MENUEVENT_LEAVE)) {
|
||||
sock_printf(c->sock, "menuevent %s %.40s\n",
|
||||
menuitem_eventtype_to_eventtypename(event),
|
||||
item->id);
|
||||
}
|
||||
else {
|
||||
snprintf (buf, sizeof(buf)-1, "menuevent %s %.40s\n",
|
||||
sock_printf(c->sock, "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 ) {
|
||||
report( RPT_ERR, "%s: Could not find client of item \"%s\"",
|
||||
__FUNCTION__, item->id );
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Send it */
|
||||
sock_send_string (c->sock, buf);
|
||||
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
|
||||
@@ -13,11 +16,11 @@
|
||||
#ifndef COMMANDS_MENU_H
|
||||
#define COMMANDS_MENU_H
|
||||
|
||||
int menu_add_item_func (Client * c, int argc, char **argv);
|
||||
int menu_del_item_func (Client * c, int argc, char **argv);
|
||||
int menu_set_item_func (Client * c, int argc, char **argv);
|
||||
int menu_goto_func (Client * c, int argc, char **argv);
|
||||
int menu_set_main_func (Client * c, int argc, char **argv);
|
||||
int menu_add_item_func(Client *c, int argc, char **argv);
|
||||
int menu_del_item_func(Client *c, int argc, char **argv);
|
||||
int menu_set_item_func(Client *c, int argc, char **argv);
|
||||
int menu_goto_func(Client *c, int argc, char **argv);
|
||||
int menu_set_main_func(Client *c, int argc, char **argv);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+142
-131
@@ -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>
|
||||
@@ -39,10 +39,10 @@
|
||||
* Usage: screen_add <id>
|
||||
*/
|
||||
int
|
||||
screen_add_func (Client * c, int argc, char **argv)
|
||||
screen_add_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
int err = 0;
|
||||
Screen * s;
|
||||
Screen *s;
|
||||
|
||||
if (!c->ack)
|
||||
return 1;
|
||||
@@ -54,19 +54,19 @@ 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) {
|
||||
s = client_find_screen(c, argv[1]);
|
||||
if (s != NULL) {
|
||||
sock_send_error(c->sock, "Screen already exists\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
s = screen_create (argv[1], c);
|
||||
if (!s) {
|
||||
s = screen_create(argv[1], c);
|
||||
if (s == NULL) {
|
||||
sock_send_error(c->sock, "failed to create screen\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = client_add_screen (c, s);
|
||||
err = client_add_screen(c, s);
|
||||
|
||||
if (err == 0) {
|
||||
sock_send_string(c->sock, "success\n");
|
||||
@@ -83,10 +83,10 @@ screen_add_func (Client * c, int argc, char **argv)
|
||||
* Usage: screen_del <screenid>
|
||||
*/
|
||||
int
|
||||
screen_del_func (Client * c, int argc, char **argv)
|
||||
screen_del_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
int err = 0;
|
||||
Screen * s;
|
||||
Screen *s;
|
||||
|
||||
if (!c->ack)
|
||||
return 1;
|
||||
@@ -96,21 +96,24 @@ screen_del_func (Client * c, int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
debug (RPT_DEBUG, "screen_del: Deleting screen %s", argv[1]);
|
||||
debug(RPT_DEBUG, "screen_del: Deleting screen %s", argv[1]);
|
||||
|
||||
s = client_find_screen (c, argv[1]);
|
||||
if (!s) {
|
||||
s = client_find_screen(c, argv[1]);
|
||||
if (s == NULL) {
|
||||
sock_send_error(c->sock, "Unknown screen id\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = client_remove_screen (c, s);
|
||||
if ( err == 0 )
|
||||
err = client_remove_screen(c, s);
|
||||
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);
|
||||
|
||||
@@ -128,7 +131,7 @@ screen_del_func (Client * c, int argc, char **argv)
|
||||
* [-cursor <type>] [-cursor_x <xpos>] [-cursor_y <ypos>]
|
||||
*/
|
||||
int
|
||||
screen_set_func (Client * c, int argc, char **argv)
|
||||
screen_set_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -147,146 +150,149 @@ 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) {
|
||||
s = client_find_screen(c, id);
|
||||
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++;
|
||||
|
||||
/* Handle the "name" parameter*/
|
||||
if (strcmp (p, "name") == 0) {
|
||||
if (strcmp(p, "name") == 0) {
|
||||
if (argc > i + 1) {
|
||||
i++;
|
||||
debug (RPT_DEBUG, "screen_set: name=\"%s\"", argv[i]);
|
||||
debug(RPT_DEBUG, "screen_set: name=\"%s\"", argv[i]);
|
||||
|
||||
/* set the name...*/
|
||||
if (s->name)
|
||||
free (s->name);
|
||||
s->name = strdup (argv[i]);
|
||||
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");
|
||||
}
|
||||
}
|
||||
/* Handle the "priority" parameter*/
|
||||
else if (strcmp (p, "priority") == 0) {
|
||||
else if (strcmp(p, "priority") == 0) {
|
||||
if (argc > i + 1) {
|
||||
i++;
|
||||
debug (RPT_DEBUG, "screen_set: priority=\"%s\"", argv[i]);
|
||||
debug(RPT_DEBUG, "screen_set: priority=\"%s\"", argv[i]);
|
||||
|
||||
/* first try to interpret it as a number */
|
||||
number = atoi (argv[i]);
|
||||
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]);
|
||||
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");
|
||||
}
|
||||
}
|
||||
/* Handle the "duration" parameter*/
|
||||
else if (strcmp (p, "duration") == 0) {
|
||||
else if (strcmp(p, "duration") == 0) {
|
||||
if (argc > i + 1) {
|
||||
i++;
|
||||
debug (RPT_DEBUG, "screen_set: duration=\"%s\"", argv[i]);
|
||||
debug(RPT_DEBUG, "screen_set: duration=\"%s\"", argv[i]);
|
||||
|
||||
/* set the duration...*/
|
||||
number = atoi (argv[i]);
|
||||
number = atoi(argv[i]);
|
||||
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");
|
||||
}
|
||||
}
|
||||
/* Handle the "heartbeat" parameter*/
|
||||
else if (strcmp (p, "heartbeat") == 0) {
|
||||
else if (strcmp(p, "heartbeat") == 0) {
|
||||
if (argc > i + 1) {
|
||||
i++;
|
||||
debug (RPT_DEBUG, "screen_set: heartbeat=\"%s\"", argv[i]);
|
||||
debug(RPT_DEBUG, "screen_set: heartbeat=\"%s\"", argv[i]);
|
||||
|
||||
/* set the heartbeat type...*/
|
||||
if (0 == strcmp (argv[i], "on"))
|
||||
if (0 == strcmp(argv[i], "on"))
|
||||
s->heartbeat = HEARTBEAT_ON;
|
||||
else if (0 == strcmp (argv[i], "off"))
|
||||
else if (0 == strcmp(argv[i], "off"))
|
||||
s->heartbeat = HEARTBEAT_OFF;
|
||||
else if (0 == strcmp (argv[i], "open"))
|
||||
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");
|
||||
}
|
||||
}
|
||||
/* Handle the "wid" parameter*/
|
||||
else if (strcmp (p, "wid") == 0) {
|
||||
else if (strcmp(p, "wid") == 0) {
|
||||
if (argc > i + 1) {
|
||||
i++;
|
||||
debug (RPT_DEBUG, "screen_set: wid=\"%s\"", argv[i]);
|
||||
debug(RPT_DEBUG, "screen_set: wid=\"%s\"", argv[i]);
|
||||
|
||||
/* set the duration...*/
|
||||
number = atoi (argv[i]);
|
||||
number = atoi(argv[i]);
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
/* Handle the "hgt" parameter*/
|
||||
else if (strcmp (p, "hgt") == 0) {
|
||||
else if (strcmp(p, "hgt") == 0) {
|
||||
if (argc > i + 1) {
|
||||
i++;
|
||||
debug (RPT_DEBUG, "screen_set: hgt=\"%s\"", argv[i]);
|
||||
debug(RPT_DEBUG, "screen_set: hgt=\"%s\"", argv[i]);
|
||||
|
||||
/* set the duration...*/
|
||||
number = atoi (argv[i]);
|
||||
number = atoi(argv[i]);
|
||||
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");
|
||||
}
|
||||
}
|
||||
/* Handle the "timeout" parameter*/
|
||||
else if (strcmp (p, "timeout") == 0) {
|
||||
else if (strcmp(p, "timeout") == 0) {
|
||||
if (argc > i + 1) {
|
||||
i++;
|
||||
debug (RPT_DEBUG, "screen_set: timeout=\"%s\"", argv[i]);
|
||||
debug(RPT_DEBUG, "screen_set: timeout=\"%s\"", argv[i]);
|
||||
/* set the duration...*/
|
||||
number = atoi (argv[i]);
|
||||
number = atoi(argv[i]);
|
||||
/* Add the timeout value (count of TIME_UNITS)
|
||||
* to struct, TIME_UNIT is 1/8th of a second
|
||||
*/
|
||||
@@ -295,35 +301,36 @@ 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");
|
||||
}
|
||||
}
|
||||
/* Handle the "backlight" parameter*/
|
||||
else if (strcmp (p, "backlight") == 0) {
|
||||
else if (strcmp(p, "backlight") == 0) {
|
||||
if (argc > i + 1) {
|
||||
i++;
|
||||
debug (RPT_DEBUG, "screen_set: backlight=\"%s\"", argv[i]);
|
||||
debug(RPT_DEBUG, "screen_set: backlight=\"%s\"", argv[i]);
|
||||
/* set the backlight status based on what the client has set*/
|
||||
switch(c->backlight) {
|
||||
case BACKLIGHT_OPEN:
|
||||
if (strcmp ("on", argv[i]) == 0)
|
||||
if (strcmp("on", argv[i]) == 0)
|
||||
s->backlight = BACKLIGHT_ON;
|
||||
|
||||
if (strcmp ("off", argv[i]) == 0)
|
||||
if (strcmp("off", argv[i]) == 0)
|
||||
s->backlight = BACKLIGHT_OFF;
|
||||
|
||||
if (strcmp ("toggle", argv[i]) == 0) {
|
||||
if (strcmp("toggle", argv[i]) == 0) {
|
||||
if (s->backlight == BACKLIGHT_ON)
|
||||
s->backlight = BACKLIGHT_OFF;
|
||||
else if (s-backlight == BACKLIGHT_OFF)
|
||||
s->backlight = BACKLIGHT_ON;
|
||||
}
|
||||
|
||||
if (strcmp ("blink", argv[i]) == 0)
|
||||
if (strcmp("blink", argv[i]) == 0)
|
||||
s->backlight |= BACKLIGHT_BLINK;
|
||||
|
||||
if (strcmp ("flash", argv[i]) == 0)
|
||||
if (strcmp("flash", argv[i]) == 0)
|
||||
s->backlight |= BACKLIGHT_FLASH;
|
||||
break;
|
||||
default:
|
||||
@@ -332,38 +339,40 @@ 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");
|
||||
}
|
||||
}
|
||||
/* Handle the "cursor" parameter */
|
||||
else if (strcmp (p, "cursor") == 0) {
|
||||
else if (strcmp(p, "cursor") == 0) {
|
||||
if (argc > i + 1) {
|
||||
i++;
|
||||
debug (RPT_DEBUG, "screen_set: cursor=\"%s\"", argv[i]);
|
||||
debug(RPT_DEBUG, "screen_set: cursor=\"%s\"", argv[i]);
|
||||
|
||||
/* set the heartbeat type...*/
|
||||
if (0 == strcmp (argv[i], "off"))
|
||||
if (0 == strcmp(argv[i], "off"))
|
||||
s->cursor = CURSOR_OFF;
|
||||
if (0 == strcmp (argv[i], "on"))
|
||||
if (0 == strcmp(argv[i], "on"))
|
||||
s->cursor = CURSOR_DEFAULT_ON;
|
||||
if (0 == strcmp (argv[i], "under"))
|
||||
if (0 == strcmp(argv[i], "under"))
|
||||
s->cursor = CURSOR_UNDER;
|
||||
if (0 == strcmp (argv[i], "block"))
|
||||
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");
|
||||
}
|
||||
}
|
||||
/* Handle the "cursor_x" parameter */
|
||||
else if (strcmp (p, "cursor_x") == 0) {
|
||||
else if (strcmp(p, "cursor_x") == 0) {
|
||||
if (argc > i + 1) {
|
||||
i++;
|
||||
debug (RPT_DEBUG, "screen_set: cursor_x=\"%s\"", argv[i]);
|
||||
debug(RPT_DEBUG, "screen_set: cursor_x=\"%s\"", argv[i]);
|
||||
|
||||
/* set the position...*/
|
||||
number = atoi (argv[i]);
|
||||
number = atoi(argv[i]);
|
||||
if (number > 0 && number <= s->width) {
|
||||
s->cursor_x = number;
|
||||
sock_send_string(c->sock, "success\n");
|
||||
@@ -371,18 +380,19 @@ 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");
|
||||
}
|
||||
}
|
||||
/* Handle the "cursor_y" parameter */
|
||||
else if (strcmp (p, "cursor_y") == 0) {
|
||||
else if (strcmp(p, "cursor_y") == 0) {
|
||||
if (argc > i + 1) {
|
||||
i++;
|
||||
debug (RPT_DEBUG, "screen_set: cursor_y=\"%s\"", argv[i]);
|
||||
debug(RPT_DEBUG, "screen_set: cursor_y=\"%s\"", argv[i]);
|
||||
|
||||
/* set the position...*/
|
||||
number = atoi (argv[i]);
|
||||
number = atoi(argv[i]);
|
||||
if (number > 0 && number <= s->height) {
|
||||
s->cursor_y = number;
|
||||
sock_send_string(c->sock, "success\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");
|
||||
}
|
||||
}
|
||||
@@ -407,12 +418,11 @@ screen_set_func (Client * c, int argc, char **argv)
|
||||
* Usage: screen_add_key <screenid> <keylist>
|
||||
*/
|
||||
int
|
||||
screen_add_key_func (Client * c, int argc, char **argv)
|
||||
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 */
|
||||
Screen *s; /* Attached to a specific screen */
|
||||
char *id; /* Screen ID */
|
||||
char *keys; /* Keys wanted */
|
||||
|
||||
if (!c->ack)
|
||||
return 1;
|
||||
@@ -437,39 +447,41 @@ screen_add_key_func (Client * c, int argc, char **argv)
|
||||
debug(RPT_DEBUG, "screen_add_key: Adding key(s) %s to screen %s", keys, id);
|
||||
|
||||
/* Find the screen*/
|
||||
s = client_find_screen (c, id);
|
||||
s = client_find_screen(c, id);
|
||||
if (!s) {
|
||||
sock_send_error(c->sock, "Unknown screen id\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Save the keys*/
|
||||
if (!s->keys) {
|
||||
if (s->keys == NULL) {
|
||||
/* Save supplied key list*/
|
||||
s->keys = strdup( keys );
|
||||
} else {
|
||||
s->keys = strdup(keys);
|
||||
}
|
||||
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
|
||||
* that's important. We'll be more careful in the delete
|
||||
* key function.
|
||||
*/
|
||||
char * new_keys ;
|
||||
new_keys = realloc( s->keys, strlen(s->keys) + strlen(keys) +1 );
|
||||
char *new_keys;
|
||||
new_keys = realloc(s->keys, strlen(s->keys) + strlen(keys) +1);
|
||||
if (new_keys) {
|
||||
strcpy (new_keys, s->keys);
|
||||
strcat (new_keys, keys );
|
||||
free (s->keys);
|
||||
strcpy(new_keys, s->keys);
|
||||
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;
|
||||
@@ -482,12 +494,11 @@ screen_add_key_func (Client * c, int argc, char **argv)
|
||||
* Usage: screen_del_key <screenid> <keylist>
|
||||
*/
|
||||
int
|
||||
screen_del_key_func (Client * c, int argc, char **argv)
|
||||
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 */
|
||||
Screen *s; /* Attached to a specific screen */
|
||||
char *id; /* Screen ID */
|
||||
char *keys; /* Keys wanted */
|
||||
|
||||
if (!c->ack)
|
||||
return 1;
|
||||
@@ -507,38 +518,38 @@ screen_del_key_func (Client * c, int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
id = argv[1] ;
|
||||
keys = argv[2] ;
|
||||
id = argv[1];
|
||||
keys = argv[2];
|
||||
debug(RPT_DEBUG, "screen_del_key: Deleting key(s) %s from screen %s", keys, id);
|
||||
|
||||
/* Find the screen*/
|
||||
s = client_find_screen (c, id);
|
||||
|
||||
if (!s) {
|
||||
s = client_find_screen(c, id);
|
||||
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
|
||||
* added, realloc (in add_key above) will make
|
||||
* sure there is enough space at s->keys
|
||||
*/
|
||||
char * from ;
|
||||
char * to ;
|
||||
char *from;
|
||||
char *to;
|
||||
|
||||
to = from = s->keys ;
|
||||
while( *from ) {
|
||||
/* Is this key to be deleted from the list?*/
|
||||
if( strchr( keys, *from ) ) {
|
||||
/* Yes, skip it*/
|
||||
++from ;
|
||||
} else {
|
||||
/* No, save it*/
|
||||
*to++ = *from++ ;
|
||||
to = from = s->keys;
|
||||
while (*from != NULL) {
|
||||
/* Is this key to be deleted from the list? */
|
||||
if (strchr(keys, *from) == 0) {
|
||||
/* Yes, skip it */
|
||||
++from;
|
||||
}
|
||||
else {
|
||||
/* No, save it */
|
||||
*to++ = *from++;
|
||||
}
|
||||
}
|
||||
to = '\0'; /* terminates the new keys string...*/
|
||||
|
||||
@@ -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
|
||||
@@ -13,11 +16,11 @@
|
||||
#ifndef COMMANDS_SCREEN_H
|
||||
#define COMMANDS_SCREEN_H
|
||||
|
||||
int screen_add_func (Client * c, int argc, char **argv);
|
||||
int screen_del_func (Client * c, int argc, char **argv);
|
||||
int screen_set_func (Client * c, int argc, char **argv);
|
||||
int screen_add_key_func (Client * c, int argc, char **argv);
|
||||
int screen_del_key_func (Client * c, int argc, char **argv);
|
||||
int screen_add_func(Client *c, int argc, char **argv);
|
||||
int screen_del_func(Client *c, int argc, char **argv);
|
||||
int screen_set_func(Client *c, int argc, char **argv);
|
||||
int screen_add_key_func(Client *c, int argc, char **argv);
|
||||
int screen_del_key_func(Client *c, int argc, char **argv);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -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>
|
||||
@@ -41,61 +41,42 @@
|
||||
#define ALL_OUTPUTS_OFF 0
|
||||
|
||||
int
|
||||
output_func (Client * c, int argc, char **argv)
|
||||
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");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (0 == strcmp (argv[1], "on"))
|
||||
if (0 == strcmp(argv[1], "on"))
|
||||
output_state = ALL_OUTPUTS_ON;
|
||||
else if (0 == strcmp (argv[1], "off"))
|
||||
else if (0 == strcmp(argv[1], "off"))
|
||||
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;
|
||||
}
|
||||
@@ -105,10 +86,10 @@ output_func (Client * c, int argc, char **argv)
|
||||
|
||||
/* Makes sense to me to set the output immediately;
|
||||
* however, the outputs are currently set in
|
||||
* draw_screen(screen * s, int timer)
|
||||
* draw_screen(screen *s, int timer)
|
||||
* Whatever for? */
|
||||
|
||||
/* drivers_output (output_state); */
|
||||
/* drivers_output(output_state); */
|
||||
|
||||
report(RPT_NOTICE, "output states changed");
|
||||
return 0;
|
||||
@@ -120,30 +101,27 @@ output_func (Client * c, int argc, char **argv)
|
||||
* Usage: sleep <seconds>
|
||||
*/
|
||||
int
|
||||
sleep_func (Client * c, int argc, char **argv)
|
||||
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...
|
||||
@@ -196,9 +168,12 @@ sleep_func (Client * c, int argc, char **argv)
|
||||
* command and look for the "noop complete" message.
|
||||
*/
|
||||
int
|
||||
noop_func (Client * c, int argc, char **argv)
|
||||
noop_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
sock_send_string (c->sock, "noop complete\n");
|
||||
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
|
||||
@@ -13,10 +16,10 @@
|
||||
#ifndef COMMANDS_SERVER_H
|
||||
#define COMMANDS_SERVER_H
|
||||
|
||||
int output_func (Client * c, int argc, char **argv);
|
||||
int test_func_func (Client * c, int argc, char **argv);
|
||||
int noop_func (Client * c, int argc, char **argv);
|
||||
int info_func (Client * c, int argc, char **argv);
|
||||
int sleep_func (Client * c, int argc, char **argv);
|
||||
int output_func(Client *c, int argc, char **argv);
|
||||
int test_func_func(Client *c, int argc, char **argv);
|
||||
int noop_func(Client *c, int argc, char **argv);
|
||||
int info_func(Client *c, int argc, char **argv);
|
||||
int sleep_func(Client *c, int argc, char **argv);
|
||||
|
||||
#endif
|
||||
|
||||
+132
-141
@@ -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>
|
||||
@@ -42,7 +42,7 @@
|
||||
* Usage: widget_add <screenid> <widgetid> <widgettype> [-in <id>]
|
||||
*/
|
||||
int
|
||||
widget_add_func (Client * c, int argc, char **argv)
|
||||
widget_add_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
int err;
|
||||
char *sid;
|
||||
@@ -62,14 +62,14 @@ widget_add_func (Client * c, int argc, char **argv)
|
||||
sid = argv[1];
|
||||
wid = argv[2];
|
||||
|
||||
s = client_find_screen (c, sid);
|
||||
if (!s) {
|
||||
s = client_find_screen(c, sid);
|
||||
if (s == NULL) {
|
||||
sock_send_error(c->sock, "Invalid screen id\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Find widget type */
|
||||
wtype = widget_typename_to_type (argv[3]);
|
||||
wtype = widget_typename_to_type(argv[3]);
|
||||
if (wtype == WID_NONE) {
|
||||
sock_send_error(c->sock, "Invalid widget type\n");
|
||||
return 0;
|
||||
@@ -77,15 +77,15 @@ 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++;
|
||||
|
||||
/* Handle the "in" flag to place widgets in a container...*/
|
||||
if (strcmp (p, "in")==0) {
|
||||
Widget * frame;
|
||||
if (strcmp(p, "in") == 0) {
|
||||
Widget *frame;
|
||||
|
||||
if (argc < 6) {
|
||||
sock_send_error(c->sock, "Specify a frame to place widget in\n");
|
||||
@@ -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;
|
||||
}
|
||||
@@ -106,19 +106,18 @@ widget_add_func (Client * c, int argc, char **argv)
|
||||
}
|
||||
|
||||
/* Create the widget */
|
||||
w = widget_create (wid, wtype, s);
|
||||
if (!w) {
|
||||
w = widget_create(wid, wtype, s);
|
||||
if (w == NULL) {
|
||||
sock_send_error(c->sock, "Error adding widget\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Add the widget to the screen */
|
||||
err = screen_add_widget (s, w);
|
||||
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;
|
||||
}
|
||||
@@ -129,14 +128,14 @@ widget_add_func (Client * c, int argc, char **argv)
|
||||
* Usage: widget_del <screenid> <widgetid>
|
||||
*/
|
||||
int
|
||||
widget_del_func (Client * c, int argc, char **argv)
|
||||
widget_del_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
char *sid;
|
||||
char *wid;
|
||||
Screen * s;
|
||||
Widget * w;
|
||||
Screen *s;
|
||||
Widget *w;
|
||||
|
||||
if (!c->ack)
|
||||
return 1;
|
||||
@@ -149,26 +148,25 @@ widget_del_func (Client * c, int argc, char **argv)
|
||||
sid = argv[1];
|
||||
wid = argv[2];
|
||||
|
||||
debug (RPT_DEBUG, "screen_del: Deleting widget %s.%s", sid, wid);
|
||||
debug(RPT_DEBUG, "screen_del: Deleting widget %s.%s", sid, wid);
|
||||
|
||||
s = client_find_screen (c, sid);
|
||||
if (!s) {
|
||||
s = client_find_screen(c, sid);
|
||||
if (s == NULL) {
|
||||
sock_send_error(c->sock, "Invalid screen id\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
w = screen_find_widget (s, wid);
|
||||
if (!w) {
|
||||
w = screen_find_widget(s, wid);
|
||||
if (w == NULL) {
|
||||
sock_send_error(c->sock, "Invalid widget id\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = screen_remove_widget (s, w);
|
||||
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;
|
||||
}
|
||||
@@ -182,19 +180,19 @@ widget_del_func (Client * c, int argc, char **argv)
|
||||
* widget_set <screenid> <widgetid> <widget-SPECIFIC-data>
|
||||
*/
|
||||
int
|
||||
widget_set_func (Client * c, int argc, char **argv)
|
||||
widget_set_func(Client *c, int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char * wid;
|
||||
char * sid;
|
||||
char *wid;
|
||||
char *sid;
|
||||
|
||||
int x, y;
|
||||
int left, top, right, bottom;
|
||||
int length, direction;
|
||||
int width, height;
|
||||
int speed;
|
||||
Screen * s;
|
||||
Widget * w;
|
||||
Screen *s;
|
||||
Widget *w;
|
||||
|
||||
if (!c->ack)
|
||||
return 1;
|
||||
@@ -212,106 +210,107 @@ widget_set_func (Client * c, int argc, char **argv)
|
||||
|
||||
/* Find screen */
|
||||
sid = argv[1];
|
||||
s = client_find_screen (c, sid);
|
||||
if (!s) {
|
||||
s = client_find_screen(c, sid);
|
||||
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) {
|
||||
w = screen_find_widget(s, wid);
|
||||
if (w == NULL) {
|
||||
sock_send_error(c->sock, "Unknown widget id\n");
|
||||
/* Client Debugging...*/
|
||||
{
|
||||
int i;
|
||||
report( RPT_WARNING, "Unknown widget id (%s)", argv[2]);
|
||||
report(RPT_WARNING, "Unknown widget id (%s)", argv[2]);
|
||||
for (i = 0; i < argc; i++)
|
||||
report( RPT_WARNING, " %.40s ", argv[i]);
|
||||
report(RPT_WARNING, " %.40s ", argv[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
i = 3;
|
||||
switch (w->type) {
|
||||
case WID_STRING: /* String takes "x y text"*/
|
||||
case WID_STRING: /* String takes "x y text" */
|
||||
if (argc != i + 3)
|
||||
sock_send_error(c->sock, "Wrong number of arguments\n");
|
||||
else {
|
||||
if ((!isdigit ((unsigned int) argv[i][0])) ||
|
||||
(!isdigit ((unsigned int) argv[i + 1][0]))) {
|
||||
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...*/
|
||||
{
|
||||
x = atoi (argv[i]);
|
||||
y = atoi (argv[i + 1]);
|
||||
}
|
||||
else { /* Set all the data...*/
|
||||
x = atoi(argv[i]);
|
||||
y = atoi(argv[i + 1]);
|
||||
w->x = x;
|
||||
w->y = y;
|
||||
if (w->text)
|
||||
free (w->text);
|
||||
w->text = strdup (argv[i + 2]);
|
||||
if (!w->text) {
|
||||
debug (RPT_DEBUG, "Widget %s set to %s", wid, w->text);
|
||||
report( RPT_WARNING, "widget_set_func: Allocation error");
|
||||
if (w->text != NULL)
|
||||
free(w->text);
|
||||
w->text = strdup(argv[i + 2]);
|
||||
if (w->text == NULL) {
|
||||
report(RPT_WARNING, "widget_set_func: Allocation error");
|
||||
return -1;
|
||||
}
|
||||
debug (RPT_DEBUG, "Widget %s set to %s", wid, w->text);
|
||||
debug(RPT_DEBUG, "Widget %s set to %s", wid, w->text);
|
||||
sock_send_string(c->sock, "success\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WID_HBAR: /* Hbar takes "x y length"*/
|
||||
case WID_HBAR: /* Hbar takes "x y length" */
|
||||
if (argc != i + 3)
|
||||
sock_send_error(c->sock, "Wrong number of arguments\n");
|
||||
else {
|
||||
if ((!isdigit ((unsigned int) argv[i][0])) ||
|
||||
(!isdigit ((unsigned int) argv[i + 1][0]))) {
|
||||
if ((!isdigit((unsigned int) argv[i][0])) ||
|
||||
(!isdigit((unsigned int) argv[i + 1][0]))) {
|
||||
sock_send_error(c->sock, "Invalid coordinates\n");
|
||||
} else {
|
||||
x = atoi (argv[i]);
|
||||
y = atoi (argv[i + 1]);
|
||||
length = atoi (argv[i + 2]);
|
||||
x = atoi(argv[i]);
|
||||
y = atoi(argv[i + 1]);
|
||||
length = atoi(argv[i + 2]);
|
||||
w->x = x;
|
||||
w->y = y;
|
||||
w->length = length;
|
||||
}
|
||||
debug (RPT_DEBUG, "Widget %s set to %i", wid, w->length);
|
||||
debug(RPT_DEBUG, "Widget %s set to %i", wid, w->length);
|
||||
sock_send_string(c->sock, "success\n");
|
||||
}
|
||||
break;
|
||||
case WID_VBAR: /* Vbar takes "x y length"*/
|
||||
case WID_VBAR: /* Vbar takes "x y length" */
|
||||
if (argc != i + 3)
|
||||
sock_send_error(c->sock, "Wrong number of arguments\n");
|
||||
else {
|
||||
if ((!isdigit ((unsigned int) argv[i][0])) ||
|
||||
(!isdigit ((unsigned int) argv[i + 1][0]))) {
|
||||
if ((!isdigit((unsigned int) argv[i][0])) ||
|
||||
(!isdigit((unsigned int) argv[i + 1][0]))) {
|
||||
sock_send_error(c->sock, "Invalid coordinates\n");
|
||||
} else {
|
||||
x = atoi (argv[i]);
|
||||
y = atoi (argv[i + 1]);
|
||||
length = atoi (argv[i + 2]);
|
||||
x = atoi(argv[i]);
|
||||
y = atoi(argv[i + 1]);
|
||||
length = atoi(argv[i + 2]);
|
||||
w->x = x;
|
||||
w->y = y;
|
||||
w->length = length;
|
||||
}
|
||||
debug (RPT_DEBUG, "Widget %s set to %i", wid, w->length);
|
||||
debug(RPT_DEBUG, "Widget %s set to %i", wid, w->length);
|
||||
sock_send_string(c->sock, "success\n");
|
||||
}
|
||||
break;
|
||||
case WID_ICON: /* Icon takes "x y icon"*/
|
||||
case WID_ICON: /* Icon takes "x y icon" */
|
||||
if (argc != i + 3)
|
||||
sock_send_error(c->sock, "Wrong number of arguments\n");
|
||||
else {
|
||||
if ((!isdigit ((unsigned int) argv[i][0])) ||
|
||||
(!isdigit ((unsigned int) argv[i + 1][0]))) {
|
||||
if ((!isdigit((unsigned int) argv[i][0])) ||
|
||||
(!isdigit((unsigned int) argv[i + 1][0]))) {
|
||||
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]);
|
||||
|
||||
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;
|
||||
@@ -320,101 +319,91 @@ widget_set_func (Client * c, int argc, char **argv)
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WID_TITLE: /* title takes "text"*/
|
||||
case WID_TITLE: /* title takes "text" */
|
||||
if (argc != i + 1)
|
||||
sock_send_error(c->sock, "Wrong number of arguments\n");
|
||||
else {
|
||||
if (w->text)
|
||||
free (w->text);
|
||||
w->text = strdup (argv[i]);
|
||||
if (!w->text) {
|
||||
report( RPT_WARNING, "widget_set_func: Allocation error");
|
||||
if (w->text != NULL)
|
||||
free(w->text);
|
||||
w->text = strdup(argv[i]);
|
||||
if (w->text == NULL) {
|
||||
report(RPT_WARNING, "widget_set_func: Allocation error");
|
||||
return -1;
|
||||
}
|
||||
/* Set width too */
|
||||
w->width = display_props->width;
|
||||
debug (RPT_DEBUG, "Widget %s set to %s", wid, w->text);
|
||||
debug(RPT_DEBUG, "Widget %s set to %s", wid, w->text);
|
||||
sock_send_string(c->sock, "success\n");
|
||||
}
|
||||
break;
|
||||
case WID_SCROLLER: /* Scroller takes "left top right bottom direction speed text"*/
|
||||
if (argc != i + 7) {
|
||||
case WID_SCROLLER: /* Scroller takes "left top right bottom direction speed text" */
|
||||
if (argc != i + 7)
|
||||
sock_send_error(c->sock, "Wrong number of arguments\n");
|
||||
} 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]))) {
|
||||
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 {
|
||||
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);*/
|
||||
}
|
||||
else {
|
||||
left = atoi(argv[i]);
|
||||
top = atoi(argv[i + 1]);
|
||||
right = atoi(argv[i + 2]);
|
||||
bottom = atoi(argv[i + 3]);
|
||||
direction = (int) (argv[i + 4][0]);
|
||||
/*debug("dir: %c",(char)direction);*/
|
||||
speed = atoi (argv[i + 5]);
|
||||
/*debug("speed: %d",speed);*/
|
||||
speed = atoi(argv[i + 5]);
|
||||
/* 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)
|
||||
free (w->text);
|
||||
w->text = strdup (argv[i + 6]);
|
||||
if (!w->text) {
|
||||
if (w->text != NULL)
|
||||
free(w->text);
|
||||
w->text = strdup(argv[i + 6]);
|
||||
if (w->text == NULL) {
|
||||
sock_send_error(c->sock, "Allocation error\n");
|
||||
return -1;
|
||||
}
|
||||
debug (RPT_DEBUG, "Widget %s set to %s", wid, w->text);
|
||||
debug(RPT_DEBUG, "Widget %s set to %s", wid, w->text);
|
||||
sock_send_string(c->sock, "success\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WID_FRAME: /* Frame takes "left top right bottom wid hgt direction speed"*/
|
||||
if (argc != i + 8) {
|
||||
case WID_FRAME: /* Frame takes "left top right bottom wid hgt direction speed" */
|
||||
if (argc != i + 8)
|
||||
sock_send_error(c->sock, "Wrong number of arguments\n");
|
||||
} 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])) ||
|
||||
(!isdigit ((unsigned int) argv[i + 4][0])) ||
|
||||
(!isdigit ((unsigned int) argv[i + 5][0]))) {
|
||||
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])) ||
|
||||
(!isdigit((unsigned int) argv[i + 4][0])) ||
|
||||
(!isdigit((unsigned int) argv[i + 5][0]))) {
|
||||
sock_send_error(c->sock, "Invalid coordinates\n");
|
||||
} 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);*/
|
||||
}
|
||||
else {
|
||||
left = atoi(argv[i]);
|
||||
top = atoi(argv[i + 1]);
|
||||
right = atoi(argv[i + 2]);
|
||||
bottom = atoi(argv[i + 3]);
|
||||
width = atoi(argv[i + 4]);
|
||||
height = atoi(argv[i + 5]);
|
||||
direction = (int) (argv[i + 6][0]);
|
||||
/*debug("dir: %c",(char)direction);*/
|
||||
speed = atoi (argv[i + 7]);
|
||||
/*debug("speed: %d",speed);*/
|
||||
speed = atoi(argv[i + 7]);
|
||||
/* 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;
|
||||
@@ -423,27 +412,29 @@ widget_set_func (Client * c, int argc, char **argv)
|
||||
w->height = height;
|
||||
w->length = direction;
|
||||
w->speed = speed;
|
||||
debug (RPT_DEBUG, "Widget %s set to (%i,%i)-(%i,%i) %ix%i", wid, left, top, right, bottom, width, height);
|
||||
debug(RPT_DEBUG, "Widget %s set to (%i,%i)-(%i,%i) %ix%i", wid, left, top, right, bottom, width, height);
|
||||
sock_send_string(c->sock, "success\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WID_NUM: /* Num takes "x num"*/
|
||||
case WID_NUM: /* Num takes "x num" */
|
||||
if (argc != i + 2)
|
||||
sock_send_error(c->sock, "Wrong number of arguments\n");
|
||||
else {
|
||||
if (!isdigit ((unsigned int) argv[i][0])) {
|
||||
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 {
|
||||
x = atoi (argv[i]);
|
||||
y = atoi (argv[i + 1]);
|
||||
}
|
||||
else {
|
||||
x = atoi(argv[i]);
|
||||
y = atoi(argv[i + 1]);
|
||||
w->x = x;
|
||||
w->y = y;
|
||||
}
|
||||
debug (RPT_DEBUG, "Widget %s set to %i", wid, w->y);
|
||||
debug(RPT_DEBUG, "Widget %s set to %i", wid, w->y);
|
||||
sock_send_string(c->sock, "success\n");
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -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
|
||||
@@ -13,8 +16,8 @@
|
||||
#ifndef COMMANDS_WIDGET_H
|
||||
#define COMMANDS_WIDGET_H
|
||||
|
||||
int widget_add_func (Client * c, int argc, char **argv);
|
||||
int widget_del_func (Client * c, int argc, char **argv);
|
||||
int widget_set_func (Client * c, int argc, char **argv);
|
||||
int widget_add_func(Client *c, int argc, char **argv);
|
||||
int widget_del_func(Client *c, int argc, char **argv);
|
||||
int widget_set_func(Client *c, int argc, char **argv);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user