add 'bye' command (currently ignored), harmonize errors due to wrong number of arguments

This commit is contained in:
marschap
2006-05-07 16:49:31 +00:00
parent 6355b22b31
commit 08bb695d8d
7 changed files with 64 additions and 94 deletions
+31 -37
View File
@@ -56,7 +56,7 @@ test_func_func (Client * c, int argc, char **argv)
*
* It returns a string of info about the server to the client
*
* usage: hello
* Usage: hello
*/
int
hello_func (Client * c, int argc, char **argv)
@@ -72,13 +72,10 @@ 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",
VERSION, PROTOCOL_VERSION, display_props->width, display_props->height, display_props->cellwidth, display_props->cellheight);
/* lcdproc (client) depends on the above format...
* snprintf (str, sizeof(str), "connect LCDproc %s protocol %s LCD %ix%i with cells %ix%i\n",
* version, protocol_version, lcd.wid, lcd.hgt, lcd.cellwid, lcd.cellhgt);
*/
snprintf(str, sizeof(str), "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);
@@ -87,10 +84,28 @@ hello_func (Client * c, int argc, char **argv)
return 0;
}
/*****************************************************************************
* The client should say "bye" before disconnecting
*
* The function does not respond to the client: it simply cuts connection
*
* Usage: bye
*/
int
bye_func (Client * c, int argc, char **argv)
{
if (c != NULL) {
debug(RPT_INFO, "Bye, %s!", (c->name != NULL) ? c->name : "unknown client");
sock_send_error(c->sock, "\"bye\" is currently ignored\n");
}
return 0;
}
/***************************************************
* sets info about the client, such as its name
*
* usage: client_set -name <id>
* Usage: client_set -name <id>
*/
int
client_set_func (Client * c, int argc, char **argv)
@@ -103,17 +118,7 @@ client_set_func (Client * c, int argc, char **argv)
return 1;
if (argc != 3) {
switch (argc) {
case 1:
sock_send_error(c->sock, "usage: client_set -name <name>\n");
break;
case 2:
sock_send_error(c->sock, "Not enough parameters\n");
break;
default:
sock_send_error(c->sock, "Too many parameters\n");
break;
}
sock_send_error(c->sock, "Usage: client_set -name <name>\n");
return 0;
}
@@ -164,7 +169,7 @@ client_set_func (Client * c, int argc, char **argv)
* Tells the server the client would like to accept keypresses
* of a particular type
*
* usage: client_add_key [-exclusively|-shared] {<key>}+
* Usage: client_add_key [-exclusively|-shared] {<key>}+
*/
#define BUFLEN 80
int
@@ -177,11 +182,7 @@ client_add_key_func (Client * c, int argc, char **argv)
return 1;
if (argc < 2) {
switch (argc) {
case 1:
sock_send_error(c->sock, "Usage: client_add_key [-exclusively|-shared] {<key>}+\n");
break;
}
sock_send_error(c->sock, "Usage: client_add_key [-exclusively|-shared] {<key>}+\n");
return 0;
}
@@ -212,7 +213,7 @@ client_add_key_func (Client * c, int argc, char **argv)
* Tells the server the client would NOT like to accept keypresses
* of a particular type
*
* usage: client_del_key {<key>}+
* Usage: client_del_key {<key>}+
*/
int
client_del_key_func (Client * c, int argc, char **argv)
@@ -238,7 +239,7 @@ client_del_key_func (Client * c, int argc, char **argv)
/***************************************************************************
* Toggles the backlight, if enabled.
*
* usage: backlight <on|off|toggle|blink|flash>
* Usage: backlight {on|off|toggle|blink|flash}
*/
int
backlight_func (Client * c, int argc, char **argv)
@@ -247,14 +248,7 @@ backlight_func (Client * c, int argc, char **argv)
return 1;
if (argc != 2) {
switch (argc) {
case 1:
sock_send_error(c->sock, "usage: backlight <on|off|toggle|blink|flash>\n");
break;
default:
sock_send_error(c->sock, "Too many parameters...\n");
break;
}
sock_send_error(c->sock, "Usage: backlight {on|off|toggle|blink|flash}\n");
return 0;
}
@@ -291,7 +285,7 @@ backlight_func (Client * c, int argc, char **argv)
/****************************************************************************
* info_func
*
* usage: info
* Usage: info
*/
int
info_func (Client * c, int argc, char **argv)
+1
View File
@@ -14,6 +14,7 @@
#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);
+1
View File
@@ -52,6 +52,7 @@ static client_function commands[] = {
{ "noop", noop_func },
{ "info", info_func },
{ "sleep", sleep_func },
{ "bye", bye_func },
{ NULL, NULL},
};
+7 -7
View File
@@ -242,7 +242,7 @@ menu_del_item_func (Client * c, int argc, char **argv)
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;
}
@@ -451,7 +451,7 @@ menu_set_item_func (Client * c, int argc, char **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;
}
@@ -712,7 +712,7 @@ menu_set_item_func (Client * c, int argc, char **argv)
* to go to a menu of another client (or the server menus). Same
* restriction applies to the optional predecessor_id
*
* usage: menu_goto <id> [<predecessor_id>]
* Usage: menu_goto <id> [<predecessor_id>]
*/
int
menu_goto_func (Client * c, int argc, char **argv)
@@ -726,7 +726,7 @@ menu_goto_func (Client * c, int argc, char **argv)
if (!c->ack)
return 1;
if ((argc < 2 )) {
if ((argc < 2 ) || (argc > 3)) {
sock_send_error(c->sock, "Usage: menu_goto <menuid> [<predecessor_id>]\n");
return 0;
}
@@ -746,7 +746,7 @@ menu_goto_func (Client * c, int argc, char **argv)
return 0;
}
if ((argc > 2 ))
if (argc > 2 )
set_predecessor(menu, argv[2], c);
menuscreen_goto (menu);
@@ -836,7 +836,7 @@ int set_successor(MenuItem *item, char *itemid, Client *c)
/***************************************************************
* Requests the menu system to set the entry point into the menu system.
*
* usage: menu_set_main <id>
* Usage: menu_set_main <id>
*/
int
menu_set_main_func (Client * c, int argc, char **argv)
@@ -850,7 +850,7 @@ menu_set_main_func (Client * c, int argc, char **argv)
if (!c->ack)
return 1;
if ((argc < 2 )) {
if (argc != 2 ) {
sock_send_error(c->sock, "Usage: menu_set_main <menuid>\n");
return 0;
}
+16 -26
View File
@@ -36,7 +36,7 @@
/***************************************************************
* Tells the server the client has another screen to offer
*
* usage: screen_add <id>
* Usage: screen_add <id>
*/
int
screen_add_func (Client * c, int argc, char **argv)
@@ -48,14 +48,7 @@ screen_add_func (Client * c, int argc, char **argv)
return 1;
if (argc != 2) {
switch (argc) {
case 1:
sock_send_error(c->sock, "Usage: screen_add <screenid>\n");
break;
default:
sock_send_error(c->sock, "Too many parameters...\n");
break;
}
sock_send_error(c->sock, "Usage: screen_add <screenid>\n");
return 0;
}
@@ -87,7 +80,7 @@ screen_add_func (Client * c, int argc, char **argv)
/****************************************************************
* Client requests that the server forget about a screen
*
* usage: screen_del <screenid>
* Usage: screen_del <screenid>
*/
int
screen_del_func (Client * c, int argc, char **argv)
@@ -99,10 +92,7 @@ screen_del_func (Client * c, int argc, char **argv)
return 1;
if (argc != 2) {
if (argc == 1)
sock_send_error(c->sock, "Usage: screen_del <screenid>\n");
else
sock_send_error(c->sock, "Too many parameters...\n");
sock_send_error(c->sock, "Usage: screen_del <screenid>\n");
return 0;
}
@@ -132,10 +122,10 @@ screen_del_func (Client * c, int argc, char **argv)
* Configures info about a particular screen, such as its
* name, priority, or duration
*
* usage: screen_set <id> [ -name <name> ] [ -wid <width> ] [ -hgt <height> ]
* [ -priority <prio> ] [ -duration <int> ] [ -timeout <int> ]
* [ -heartbeat <type> ] [ -backlight <type> ]
* [ -cursor <type> ] [ -cursor_x <xpos> ] [ -cursor_y <ypos> ]
* Usage: screen_set <id> [-name <name>] [-wid <width>] [-hgt <height>]
* [-priority <prio>] [-duration <int>] [-timeout <int>]
* [-heartbeat <type>] [-backlight <type>]
* [-cursor <type>] [-cursor_x <xpos>] [-cursor_y <ypos>]
*/
int
screen_set_func (Client * c, int argc, char **argv)
@@ -150,12 +140,12 @@ screen_set_func (Client * c, int argc, char **argv)
return 1;
if (argc == 1) {
sock_send_error(c->sock, "Usage: screen_set <id> [ -name <name> ]"
" [ -wid <width> ] [ -hgt <height> [ -priority <int> ]"
" [ -duration <int> ] [ -timeout <int> ]"
" [ -heartbeat <type> ] [ -backlight <type> ]"
" [ -cursor <type> ]"
" [ -cursor_x <xpos> ] [ -cursor_y <ypos> ]\n");
sock_send_error(c->sock, "Usage: screen_set <id> [-name <name>]"
" [-wid <width>] [-hgt <height>] [-priority <int>]"
" [-duration <int>] [-timeout <int>]"
" [-heartbeat <type>] [-backlight <type>]"
" [-cursor <type>]"
" [-cursor_x <xpos>] [-cursor_y <ypos>]\n");
return 0;
} else if (argc == 2) {
sock_send_error(c->sock, "What do you want to set?\n");
@@ -414,7 +404,7 @@ screen_set_func (Client * c, int argc, char **argv)
* Tells the server the client would like to accept keypresses
* of a particular type when the given screen is active on the display
*
* screen_add_key <screenid> <keylist>
* Usage: screen_add_key <screenid> <keylist>
*/
int
screen_add_key_func (Client * c, int argc, char **argv)
@@ -489,7 +479,7 @@ screen_add_key_func (Client * c, int argc, char **argv)
* Tells the server the client would NOT like to accept keypresses
* of a particular type when the given screen is active on the display
*
* usage: screen_del_key <screenid> <keylist>
* Usage: screen_del_key <screenid> <keylist>
*/
int
screen_del_key_func (Client * c, int argc, char **argv)
+4 -10
View File
@@ -35,7 +35,7 @@
/****************************************************************************
* Sets the state of the output port (such as on MtxOrb LCDs)
*
* usage: output <on|off|int>
* Usage: output <on|off|int>
*/
#define ALL_OUTPUTS_ON -1
#define ALL_OUTPUTS_OFF 0
@@ -47,10 +47,7 @@ output_func (Client * c, int argc, char **argv)
char str[128];
if (argc != 2) {
if (argc == 1)
sock_send_error(c->sock, "usage: output <on|off|num> -- num may be decimal, hex, or octal\n");
else
sock_send_error(c->sock, "Too many parameters...\n");
sock_send_error(c->sock, "Usage: output {on|off|<num>}\n");
return 0;
}
@@ -120,7 +117,7 @@ output_func (Client * c, int argc, char **argv)
/*******************************************************************************
* sleep_func
*
* usage: sleep <seconds>
* Usage: sleep <seconds>
*/
int
sleep_func (Client * c, int argc, char **argv)
@@ -134,10 +131,7 @@ sleep_func (Client * c, int argc, char **argv)
#define MIN_SECS 1
if (argc != 2) {
if (argc == 1)
sock_send_error(c->sock, "usage: sleep <secs>\n");
else
sock_send_error(c->sock, "Too many parameters...\n");
sock_send_error(c->sock, "Usage: sleep <secs>\n");
return 0;
}
+4 -14
View File
@@ -39,7 +39,7 @@
/*************************************************************************
* Adds a widget to a screen, but doesn't give it a value
*
* usage: widget_add <screenid> <widgetid> <widgettype> [ -in <id> ]
* Usage: widget_add <screenid> <widgetid> <widgettype> [-in <id>]
*/
int
widget_add_func (Client * c, int argc, char **argv)
@@ -55,7 +55,7 @@ widget_add_func (Client * c, int argc, char **argv)
return 1;
if ((argc < 4) || (argc > 6)) {
sock_send_error(c->sock, "Usage: widget_add <screenid> <widgetid> <widgettype> [ -in <id> ]\n");
sock_send_error(c->sock, "Usage: widget_add <screenid> <widgetid> <widgettype> [-in <id>]\n");
return 0;
}
@@ -126,7 +126,7 @@ widget_add_func (Client * c, int argc, char **argv)
/*******************************************************************
* Removes a widget from a screen, and forgets about it
*
* usage: widget_del <screenid> <widgetid>
* Usage: widget_del <screenid> <widgetid>
*/
int
widget_del_func (Client * c, int argc, char **argv)
@@ -142,17 +142,7 @@ widget_del_func (Client * c, int argc, char **argv)
return 1;
if (argc != 3) {
switch (argc) {
case 1:
sock_send_error(c->sock, "Usage: widget_del <screenid> <widgetid>\n");
break;
case 2:
sock_send_error(c->sock, "Specify a widget #id\n");
break;
default:
sock_send_error(c->sock, "Too many parameters...\n");
break;
}
sock_send_error(c->sock, "Usage: widget_del <screenid> <widgetid>\n");
return 0;
}