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 * It returns a string of info about the server to the client
* *
* usage: hello * Usage: hello
*/ */
int int
hello_func (Client * c, int argc, char **argv) hello_func (Client * c, int argc, char **argv)
@@ -72,13 +72,10 @@ hello_func (Client * c, int argc, char **argv)
debug(RPT_INFO, "Hello!"); debug(RPT_INFO, "Hello!");
memset(str, '\0', sizeof(str)); memset(str, '\0', sizeof(str));
snprintf (str, sizeof(str), "connect LCDproc %s protocol %s lcd wid %i hgt %i cellwid %i cellhgt %i\n", 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); VERSION, PROTOCOL_VERSION,
display_props->width, display_props->height,
/* lcdproc (client) depends on the above format... display_props->cellwidth, display_props->cellheight);
* 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);
*/
sock_send_string (c->sock, str); sock_send_string (c->sock, str);
@@ -87,10 +84,28 @@ hello_func (Client * c, int argc, char **argv)
return 0; 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 * sets info about the client, such as its name
* *
* usage: client_set -name <id> * Usage: client_set -name <id>
*/ */
int int
client_set_func (Client * c, int argc, char **argv) client_set_func (Client * c, int argc, char **argv)
@@ -103,17 +118,7 @@ client_set_func (Client * c, int argc, char **argv)
return 1; return 1;
if (argc != 3) { if (argc != 3) {
switch (argc) { sock_send_error(c->sock, "Usage: client_set -name <name>\n");
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;
}
return 0; 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 * Tells the server the client would like to accept keypresses
* of a particular type * of a particular type
* *
* usage: client_add_key [-exclusively|-shared] {<key>}+ * Usage: client_add_key [-exclusively|-shared] {<key>}+
*/ */
#define BUFLEN 80 #define BUFLEN 80
int int
@@ -177,11 +182,7 @@ client_add_key_func (Client * c, int argc, char **argv)
return 1; return 1;
if (argc < 2) { if (argc < 2) {
switch (argc) { sock_send_error(c->sock, "Usage: client_add_key [-exclusively|-shared] {<key>}+\n");
case 1:
sock_send_error(c->sock, "Usage: client_add_key [-exclusively|-shared] {<key>}+\n");
break;
}
return 0; 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 * Tells the server the client would NOT like to accept keypresses
* of a particular type * of a particular type
* *
* usage: client_del_key {<key>}+ * Usage: client_del_key {<key>}+
*/ */
int int
client_del_key_func (Client * c, int argc, char **argv) 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. * Toggles the backlight, if enabled.
* *
* usage: backlight <on|off|toggle|blink|flash> * Usage: backlight {on|off|toggle|blink|flash}
*/ */
int int
backlight_func (Client * c, int argc, char **argv) backlight_func (Client * c, int argc, char **argv)
@@ -247,14 +248,7 @@ backlight_func (Client * c, int argc, char **argv)
return 1; return 1;
if (argc != 2) { if (argc != 2) {
switch (argc) { sock_send_error(c->sock, "Usage: backlight {on|off|toggle|blink|flash}\n");
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;
}
return 0; return 0;
} }
@@ -291,7 +285,7 @@ backlight_func (Client * c, int argc, char **argv)
/**************************************************************************** /****************************************************************************
* info_func * info_func
* *
* usage: info * Usage: info
*/ */
int int
info_func (Client * c, int argc, char **argv) info_func (Client * c, int argc, char **argv)
+1
View File
@@ -14,6 +14,7 @@
#define COMMANDS_CLIENT_H #define COMMANDS_CLIENT_H
int hello_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_set_func (Client * c, int argc, char **argv);
int client_add_key_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 client_del_key_func (Client * c, int argc, char **argv);
+1
View File
@@ -52,6 +52,7 @@ static client_function commands[] = {
{ "noop", noop_func }, { "noop", noop_func },
{ "info", info_func }, { "info", info_func },
{ "sleep", sleep_func }, { "sleep", sleep_func },
{ "bye", bye_func },
{ NULL, NULL}, { NULL, NULL},
}; };
+7 -7
View File
@@ -242,7 +242,7 @@ menu_del_item_func (Client * c, int argc, char **argv)
if (!c->ack) if (!c->ack)
return 1; return 1;
if ((argc < 3 )) { if (argc != 3 ) {
sock_send_error(c->sock, "Usage: menu_del_item <menuid> <itemid>\n"); sock_send_error(c->sock, "Usage: menu_del_item <menuid> <itemid>\n");
return 0; return 0;
} }
@@ -451,7 +451,7 @@ menu_set_item_func (Client * c, int argc, char **argv)
if (!c->ack) if (!c->ack)
return 1; return 1;
if ((argc < 4 )) { if (argc < 4 ) {
sock_send_error(c->sock, "Usage: menu_set_item <menuid> <itemid> {<option>}+\n"); sock_send_error(c->sock, "Usage: menu_set_item <menuid> <itemid> {<option>}+\n");
return 0; 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 * to go to a menu of another client (or the server menus). Same
* restriction applies to the optional predecessor_id * restriction applies to the optional predecessor_id
* *
* usage: menu_goto <id> [<predecessor_id>] * Usage: menu_goto <id> [<predecessor_id>]
*/ */
int int
menu_goto_func (Client * c, int argc, char **argv) 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) if (!c->ack)
return 1; return 1;
if ((argc < 2 )) { if ((argc < 2 ) || (argc > 3)) {
sock_send_error(c->sock, "Usage: menu_goto <menuid> [<predecessor_id>]\n"); sock_send_error(c->sock, "Usage: menu_goto <menuid> [<predecessor_id>]\n");
return 0; return 0;
} }
@@ -746,7 +746,7 @@ menu_goto_func (Client * c, int argc, char **argv)
return 0; return 0;
} }
if ((argc > 2 )) if (argc > 2 )
set_predecessor(menu, argv[2], c); set_predecessor(menu, argv[2], c);
menuscreen_goto (menu); 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. * Requests the menu system to set the entry point into the menu system.
* *
* usage: menu_set_main <id> * Usage: menu_set_main <id>
*/ */
int int
menu_set_main_func (Client * c, int argc, char **argv) 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) if (!c->ack)
return 1; return 1;
if ((argc < 2 )) { if (argc != 2 ) {
sock_send_error(c->sock, "Usage: menu_set_main <menuid>\n"); sock_send_error(c->sock, "Usage: menu_set_main <menuid>\n");
return 0; return 0;
} }
+16 -26
View File
@@ -36,7 +36,7 @@
/*************************************************************** /***************************************************************
* Tells the server the client has another screen to offer * Tells the server the client has another screen to offer
* *
* usage: screen_add <id> * Usage: screen_add <id>
*/ */
int int
screen_add_func (Client * c, int argc, char **argv) screen_add_func (Client * c, int argc, char **argv)
@@ -48,14 +48,7 @@ screen_add_func (Client * c, int argc, char **argv)
return 1; return 1;
if (argc != 2) { if (argc != 2) {
switch (argc) { sock_send_error(c->sock, "Usage: screen_add <screenid>\n");
case 1:
sock_send_error(c->sock, "Usage: screen_add <screenid>\n");
break;
default:
sock_send_error(c->sock, "Too many parameters...\n");
break;
}
return 0; return 0;
} }
@@ -87,7 +80,7 @@ screen_add_func (Client * c, int argc, char **argv)
/**************************************************************** /****************************************************************
* Client requests that the server forget about a screen * Client requests that the server forget about a screen
* *
* usage: screen_del <screenid> * Usage: screen_del <screenid>
*/ */
int int
screen_del_func (Client * c, int argc, char **argv) screen_del_func (Client * c, int argc, char **argv)
@@ -99,10 +92,7 @@ screen_del_func (Client * c, int argc, char **argv)
return 1; return 1;
if (argc != 2) { if (argc != 2) {
if (argc == 1) sock_send_error(c->sock, "Usage: screen_del <screenid>\n");
sock_send_error(c->sock, "Usage: screen_del <screenid>\n");
else
sock_send_error(c->sock, "Too many parameters...\n");
return 0; return 0;
} }
@@ -132,10 +122,10 @@ screen_del_func (Client * c, int argc, char **argv)
* Configures info about a particular screen, such as its * Configures info about a particular screen, such as its
* name, priority, or duration * name, priority, or duration
* *
* usage: screen_set <id> [ -name <name> ] [ -wid <width> ] [ -hgt <height> ] * Usage: screen_set <id> [-name <name>] [-wid <width>] [-hgt <height>]
* [ -priority <prio> ] [ -duration <int> ] [ -timeout <int> ] * [-priority <prio>] [-duration <int>] [-timeout <int>]
* [ -heartbeat <type> ] [ -backlight <type> ] * [-heartbeat <type>] [-backlight <type>]
* [ -cursor <type> ] [ -cursor_x <xpos> ] [ -cursor_y <ypos> ] * [-cursor <type>] [-cursor_x <xpos>] [-cursor_y <ypos>]
*/ */
int int
screen_set_func (Client * c, int argc, char **argv) screen_set_func (Client * c, int argc, char **argv)
@@ -150,12 +140,12 @@ screen_set_func (Client * c, int argc, char **argv)
return 1; return 1;
if (argc == 1) { if (argc == 1) {
sock_send_error(c->sock, "Usage: screen_set <id> [ -name <name> ]" sock_send_error(c->sock, "Usage: screen_set <id> [-name <name>]"
" [ -wid <width> ] [ -hgt <height> [ -priority <int> ]" " [-wid <width>] [-hgt <height>] [-priority <int>]"
" [ -duration <int> ] [ -timeout <int> ]" " [-duration <int>] [-timeout <int>]"
" [ -heartbeat <type> ] [ -backlight <type> ]" " [-heartbeat <type>] [-backlight <type>]"
" [ -cursor <type> ]" " [-cursor <type>]"
" [ -cursor_x <xpos> ] [ -cursor_y <ypos> ]\n"); " [-cursor_x <xpos>] [-cursor_y <ypos>]\n");
return 0; return 0;
} else if (argc == 2) { } else if (argc == 2) {
sock_send_error(c->sock, "What do you want to set?\n"); 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 * Tells the server the client would like to accept keypresses
* of a particular type when the given screen is active on the display * 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 int
screen_add_key_func (Client * c, int argc, char **argv) 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 * Tells the server the client would NOT like to accept keypresses
* of a particular type when the given screen is active on the display * 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 int
screen_del_key_func (Client * c, int argc, char **argv) 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) * 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_ON -1
#define ALL_OUTPUTS_OFF 0 #define ALL_OUTPUTS_OFF 0
@@ -47,10 +47,7 @@ output_func (Client * c, int argc, char **argv)
char str[128]; char str[128];
if (argc != 2) { if (argc != 2) {
if (argc == 1) sock_send_error(c->sock, "Usage: output {on|off|<num>}\n");
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");
return 0; return 0;
} }
@@ -120,7 +117,7 @@ output_func (Client * c, int argc, char **argv)
/******************************************************************************* /*******************************************************************************
* sleep_func * sleep_func
* *
* usage: sleep <seconds> * Usage: sleep <seconds>
*/ */
int int
sleep_func (Client * c, int argc, char **argv) sleep_func (Client * c, int argc, char **argv)
@@ -134,10 +131,7 @@ sleep_func (Client * c, int argc, char **argv)
#define MIN_SECS 1 #define MIN_SECS 1
if (argc != 2) { if (argc != 2) {
if (argc == 1) sock_send_error(c->sock, "Usage: sleep <secs>\n");
sock_send_error(c->sock, "usage: sleep <secs>\n");
else
sock_send_error(c->sock, "Too many parameters...\n");
return 0; return 0;
} }
+4 -14
View File
@@ -39,7 +39,7 @@
/************************************************************************* /*************************************************************************
* Adds a widget to a screen, but doesn't give it a value * 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 int
widget_add_func (Client * c, int argc, char **argv) widget_add_func (Client * c, int argc, char **argv)
@@ -55,7 +55,7 @@ widget_add_func (Client * c, int argc, char **argv)
return 1; return 1;
if ((argc < 4) || (argc > 6)) { 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; 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 * Removes a widget from a screen, and forgets about it
* *
* usage: widget_del <screenid> <widgetid> * Usage: widget_del <screenid> <widgetid>
*/ */
int int
widget_del_func (Client * c, int argc, char **argv) widget_del_func (Client * c, int argc, char **argv)
@@ -142,17 +142,7 @@ widget_del_func (Client * c, int argc, char **argv)
return 1; return 1;
if (argc != 3) { if (argc != 3) {
switch (argc) { sock_send_error(c->sock, "Usage: widget_del <screenid> <widgetid>\n");
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;
}
return 0; return 0;
} }