express: Added help command handling.

Summary:
I've not added help for all the commands. Let me know how the way it is. In the _handle_txt function, I was thinking of handling all the commands. Then, for each command a function to handle that command. What do you think about it?

Signed-off-by: Srivardhan Hebbar <sri.hebbar@samsung.com>

Reviewers: devilhorns

Differential Revision: https://phab.enlightenment.org/D2316
This commit is contained in:
Srivardhan Hebbar 2015-04-16 10:55:16 -04:00 committed by Chris Michael
parent 718f1153b4
commit bc86fdcdb5
4 changed files with 338 additions and 7 deletions

View File

@ -39,7 +39,8 @@ options_channels.h \
options_tools.h \
gravatar.h \
md5/md5.h \
media.h
media.h \
commands.h
express_SOURCES = \
$(EXPRESSHEADERS) \
@ -68,7 +69,8 @@ options_channels.c \
options_tools.c \
gravatar.c \
md5/md5.c \
media.c
media.c \
commands.c
express_LDADD = \
$(top_builddir)/src/lib/libexpress.la \

View File

@ -5,6 +5,7 @@
#include "window.h"
#include "grid.h"
#include "utils.h"
#include "commands.h"
struct _Channel
{
@ -23,7 +24,7 @@ struct _Channel
Evas_Object *o_img;
Evas_Object *o_entry;
struct
struct
{
Evas_Object *o_frame;
Evas_Object *o_spacer;
@ -36,7 +37,7 @@ struct _Channel
int opcount;
} userlist;
struct
struct
{
Evas_Object *o_frame;
Evas_Object *o_box;
@ -47,7 +48,7 @@ struct _Channel
struct
{
struct
struct
{
Evas_Object *o_box;
Eina_List *tabs;
@ -253,8 +254,7 @@ _cb_entry_go(void *data, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
char buff[PATH_MAX];
const char *nick;
snprintf(buff, sizeof(buff), "%s\r\n", txt);
express_network_channel_priv_send(chl->net, chl->name, buff);
handle_txt(chl->net, chl->name, txt, buff);
nick = express_network_nickname_get(chl->net);
_channel_text_append(chl, nick, buff);

323
src/bin/commands.c Normal file
View File

@ -0,0 +1,323 @@
#include <private.h>
#include "channel.h"
static void
_handle_help_cmd(char *token, char *buff)
{
if (!token) goto help_help;
if (!strcmp(token,"ADMIN"))
snprintf(buff, PATH_MAX, "Syntax: ADMIN [<target>]\n"
"Instructs the server to return information about "
"the administrators of the server specified by "
"<target>. Where <target> is either a server or a "
"user. If <target> is omitted, the server should "
"return information about the administrators of "
"the current server.\r\n");
else if (!strcmp(token, "AWAY"))
snprintf(buff, PATH_MAX, "Syntax: AWAY [<message>]\n"
"Provides the server with a message to automatically "
"send in reply to a PRIVMSG directed at the user, but "
"not to a channel they are on.[2] If <message> is "
"omitted, the away status is removed.\r\n");
else if (!strcmp(token, "CNOTICE"))
snprintf(buff, PATH_MAX, "Syntax: CNOTICE <nickname> <channel> :<message>\n"
"Sends a channel NOTICE message to <nickname> on <channel> that "
"bypasses flood protection limits. The target nickname must be "
"in the same channel as the client issuing the command, and the "
"client must be a channel operator.\r\n");
else if (!strcmp(token, "CPRIVMSG"))
snprintf(buff, PATH_MAX, "Syntax: CPRIVMSG <nickname> <channel> :<message>\n"
"Sends a private message to <nickname> on <channel> that bypasses "
"flood protection limits. The target nickname must be in the same "
"channel as the client issuing the command, and the client must be "
"a channel operator.\r\n");
else if (!strcmp(token, "CONNECT"))
snprintf(buff, PATH_MAX, "Syntax: CONNECT <target server> [<port> [<remote server>]]\n"
"Instructs the server <remote server> (or the current server, if "
"<remote server> is omitted) to connect to <target server> on port "
"<port>. This command should only be available to IRC Operators.\r\n");
else if (!strcmp(token, "DIE"))
snprintf(buff, PATH_MAX, "Syntax: DIE\n"
"This command may only be issued by IRC server operators.\r\n");
else if (!strcmp(token, "ENCAP"))
snprintf(buff, PATH_MAX, "Syntax: :<source> ENCAP <destination> <subcommand> <parameters>\n"
"This command is for use by servers to encapsulate commands so that they will "
"propagate across hub servers not yet updated to support them, and indicates the "
"subcommand and its parameters should be passed unaltered to the destination, "
"where it will be unencapsulated and parsed. This facilitates implementation of "
"new features without a need to restart all servers before they are usable across "
"the network.\r\n");
else if (!strcmp(token, "ERROR"))
snprintf(buff, PATH_MAX, "Syntax: ERROR <error message>\n"
"This command is for use by servers to report errors "
"to other servers. It is also used before terminating "
"client connections.\r\n");
else if (!strcmp(token, "INFO"))
snprintf(buff, PATH_MAX, "Syntax: INFO [<target>]\n"
"Returns information about the <target> server, or "
"the current server if <target> is omitted. Information "
"returned includes the server's version, when it was "
"compiled, the patch level, when it was started, and "
"any other information which may be considered to be "
"relevant.\r\n");
else if (!strcmp(token, "INVITE"))
snprintf(buff, PATH_MAX, "Syntax: INVITE <nickname> <channel>\n"
"Invites <nickname> to the channel <channel>. <channel> "
"does not have to exist, but if it does, only members of "
"the channel are allowed to invite other clients. If the "
"channel mode i is set, only channel operators may invite "
"other clients.\r\n");
else if (!strcmp(token, "ISON"))
snprintf(buff, PATH_MAX, "Syntax: ISON <nicknames>\n"
"Queries the server to see if the clients in the "
"space-separated list <nicknames> are currently on the "
"network. The server returns only the nicknames that are "
"on the network in a space-separated list. If none of "
"the clients are on the network the server returns an "
"empty list.\r\n");
else if (!strcmp(token, "JOIN"))
snprintf(buff, PATH_MAX, "Syntax: JOIN <channels> [<keys>]\n"
"Makes the client join the channels in the comma-separated "
"list <channels>, specifying the passwords, if needed, in "
"the comma-separated list <keys>. If the channel(s) do not "
"exist then they will be created.\r\n");
else if (!strcmp(token, "KICK"))
snprintf(buff, PATH_MAX, "Syntax: KICK <channel> <client> [<message>]\n"
"Forcibly removes <client> from <channel>. This command may "
"only be issued by channel operators.\r\n");
else if (!strcmp(token, "KILL"))
snprintf(buff, PATH_MAX, "Syntax: KILL <client> <comment>\n"
"Forcibly removes <client> from the network. This command "
"may only be issued by IRC operators.\r\n");
else if (!strcmp(token, "KNOCK"))
snprintf(buff, PATH_MAX, "Syntax: KNOCK <channel> [<message>]\n"
"Sends a NOTICE to an invitation-only <channel> with an "
"optional <message>, requesting an invite.\r\n");
else if (!strcmp(token, "LINKS"))
snprintf(buff, PATH_MAX, "Syntax: LINKS [<remote server> [<server mask>]]\n"
"Lists all server links matching <server mask>, if given, on "
"<remote server>, or the current server if omitted.\r\n");
else if (!strcmp(token, "LIST"))
snprintf(buff, PATH_MAX, "Syntax: LIST [<channels> [<server>]]\n"
"Lists all channels on the server. If the comma-separated "
"list <channels> is given, it will return the channel topics. "
"If <server> is given, the command will be forwarded to "
"<server> for evaluation.\r\n");
else if (!strcmp(token, "LUSERS"))
snprintf(buff, PATH_MAX, "Syntax: LUSERS [<mask> [<server>]]\n"
"Returns statistics about the size of the network. If called "
"with no arguments, the statistics will reflect the entire "
"network. If <mask> is given, it will return only statistics "
"reflecting the masked subset of the network. If <target> is "
"given, the command will be forwarded to <server> for "
"evaluation.\r\n");
else if (!strcmp(token, "MODE"))
snprintf(buff, PATH_MAX, "Syntax: MODE <nickname> <flags> (user)\n MODE <channel> <flags> [<args>]\n"
"The MODE command is dual-purpose. It can be used to set both user and channel modes.\r\n");
else if (!strcmp(token, "MOTD"))
snprintf(buff, PATH_MAX, "Syntax: MOTD [<server>]\n"
"Returns the message of the day on <server> or the current "
"server if it is omitted.\r\n");
else if (!strcmp(token, "NAMES"))
snprintf(buff, PATH_MAX,"Syntax: NAMES [<channels> [<server>]]\n"
"Returns a list of who is on the comma-separated list of "
"<channels>, by channel name. If <channels> is omitted, "
"all users are shown, grouped by channel name with all users "
"who are not on a channel being shown as part of channel \"*\". "
"If <server> is specified, the command is sent to <server> "
"for evaluation\r\n");
else if (!strcmp(token, "NAMESX"))
snprintf(buff, PATH_MAX,"Syntax: PROTOCTL NAMESX\n"
"Instructs the server to send names in an RPL_NAMES reply "
"prefixed with all their respective channel statuses instead "
"of just the highest one (similar to IRCv3's multi-prefix).\r\n");
else if (!strcmp(token, "NICK"))
snprintf(buff, PATH_MAX,"Syntax: NICK <nickname> [<hopcount>]\n"
"Allows a client to change their IRC nickname. Hopcount "
"is for use between servers to specify how far away a "
"nickname is from its home server.\r\n");
else if (!strcmp(token, "NOTICE"))
snprintf(buff, PATH_MAX,"Syntax: NOTICE <msgtarget> <message>\n"
"This command works similarly to PRIVMSG, except automatic "
"replies must never be sent in reply to NOTICE messages.\r\n");
else if (!strcmp(token, "OPER"))
snprintf(buff, PATH_MAX,"Syntax: OPER <username> <password>\n"
"Authenticates a user as an IRC operator on that server/network.\r\n");
else if (!strcmp(token, "PART"))
snprintf(buff, PATH_MAX,"Syntax: PART <channels> [<message>]\n"
"Causes a user to leave the channels in the comma-separated "
"list <channels>.\r\n");
else if (!strcmp(token, "PASS"))
snprintf(buff, PATH_MAX,"Syntax: PASS <password>\n"
"Sets a connection password. This command must be sent "
"before the NICK/USER registration combination.\r\n");
else if (!strcmp(token, "PING"))
snprintf(buff, PATH_MAX,"Syntax: PING <server1> [<server2>]\n"
"Tests the presence of a connection. A PING message results "
"in a PONG reply. If <server2> is specified, the message "
"gets passed on to it.\r\n");
else if (!strcmp(token, "PONG"))
snprintf(buff, PATH_MAX,"Syntax: PONG <server1> [<server2>]"
"This command is a reply to the PING command and works "
"in much the same way.\r\n");
else if (!strcmp(token, "PRIVMSG"))
snprintf(buff, PATH_MAX,"Syntax: PRIVMSG <msgtarget> <message>\n"
"Sends <message> to <msgtarget>, which is usually a user "
"or channel.\r\n");
else if (!strcmp(token, "QUIT"))
snprintf(buff, PATH_MAX,"Syntax: QUIT [<message>]\n"
"Disconnects the user from the server.\r\n");
else if (!strcmp(token, "REHASH"))
snprintf(buff, PATH_MAX,"Syntax: REHASH\n"
"Causes the server to re-read and re-process its configuration "
"file(s). This command can only be sent by IRC Operators.\r\n");
else if (!strcmp(token, "RESTART"))
snprintf(buff, PATH_MAX,"Syntax: RESTART\n"
"Restarts a server. It may only be sent by IRC Operators.\r\n");
else if (!strcmp(token, "RULES"))
snprintf(buff, PATH_MAX,"Syntax: RULES\n"
"Requests the server rules.\r\n");
else if (!strcmp(token, "SERVER"))
snprintf(buff, PATH_MAX,"Syntax: SERVER <servername> <hopcount> <info>\n"
"The server message is used to tell a server that the other "
"end of a new connection is a server.[36] This message is also "
"used to pass server data over whole net. <hopcount> details "
"how many hops (server connections) away <servername> is. "
"<info> contains addition human-readable information about "
"the server.\r\n");
else if (!strcmp(token, "SERVICE"))
snprintf(buff, PATH_MAX,"Syntax: SERVICE <nickname> <reserved> <distribution> <type> <reserved> <info>\n"
"Registers a new service on the network.\r\n");
else if (!strcmp(token, "SERVLIST"))
snprintf(buff, PATH_MAX,"Syntax: SERVLIST [<mask> [<type>]]\n"
"Lists the services currently on the network.\r\n");
else if (!strcmp(token, "SQUERY"))
snprintf(buff, PATH_MAX,"Syntax: SQUERY <servicename> <text>\n"
"Identical to PRIVMSG except the recipient must be a "
"service.\r\n");
else if (!strcmp(token, "SQUIT"))
snprintf(buff, PATH_MAX,"Syntax: SQUIT <server> <comment>\n"
"Causes <server> to quit the network.\r\n");
else if (!strcmp(token, "SETNAME"))
snprintf(buff, PATH_MAX,"Syntax: SETNAME <new real name>\n"
"Allows a client to change the \"real name\" specified "
"when registering a connection.\r\n");
else if (!strcmp(token, "SILENCE"))
snprintf(buff, PATH_MAX,"Syntax: SILENCE [+/-<hostmask>]\n"
"Adds or removes a host mask to a server-side ignore list "
"that prevents matching users from sending the client messages. "
"More than one mask may be specified in a space-separated list, "
"each item prefixed with a \"+\" or \"-\" to designate whether "
"it is being added or removed. Sending the command with no "
"parameters returns the entries in the client's ignore list.\r\n");
else if (!strcmp(token, "STATS"))
snprintf(buff, PATH_MAX,"Syntax: STATS <query> [<server>]\n"
"Returns statistics about the current server, or <server> "
"if it's specified.\r\n");
else if (!strcmp(token, "SUMMON"))
snprintf(buff, PATH_MAX,"Syntax: SUMMON <user> [<server> [<channel>]]\n"
"Gives users who are on the same host as <server> a message "
"asking them to join IRC.\r\n");
else if (!strcmp(token, "TIME"))
snprintf(buff, PATH_MAX,"Syntax: TIME [<server>]\n"
"Returns the local time on the current server, or <server> "
"if specified.\r\n");
else if (!strcmp(token, "TOPIC"))
snprintf(buff, PATH_MAX,"Syntax: TOPIC <channel> [<topic>]\n"
"Allows the client to query or set the channel topic on "
"<channel>. If <topic> is given, it sets the channel topic "
"to <topic>. If channel mode +t is set, only a channel "
"operator may set the topic.\r\n");
else if (!strcmp(token, "TRACE"))
snprintf(buff, PATH_MAX,"Syntax: TRACE [<target>]\n"
"Trace a path across the IRC network to a specific server "
"or client, in a similar method to traceroute.\r\n");
else if (!strcmp(token, "UHNAMES"))
snprintf(buff, PATH_MAX,"Syntax: PROTOCTL UHNAMES\n"
"Instructs the server to send names in an RPL_NAMES reply "
"in the long format.\r\n");
else if (!strcmp(token, "USER"))
snprintf(buff, PATH_MAX,"Syntax: USER <username> <hostname> <servername> <realname>\n"
"This command is used at the beginning of a connection to specify the "
"username, hostname, real name and initial user modes of the connecting "
"client. <realname> may contain spaces, and thus must be prefixed with a "
"colon.\r\n");
else if (!strcmp(token, "USERHOST"))
snprintf(buff, PATH_MAX,"Syntatx: USERHOST <nickname> [<nickname> <nickname> ...]\n"
"Returns a list of information about the nicknames specified.\r\n");
else if (!strcmp(token, "USERIP"))
snprintf(buff, PATH_MAX,"Syntatx: USERIP <nickname>\n"
"Requests the direct IP address of the user with the "
"specified nickname.\r\n");
else if (!strcmp(token, "USERS"))
snprintf(buff, PATH_MAX,"Syntatx: USERS [<server>]\n"
"Returns a list of users and information about those users "
"in a format similar to the UNIX commands who, rusers and "
"finger.\r\n");
else if (!strcmp(token, "VERSION"))
snprintf(buff, PATH_MAX,"Syntatx: VERSION [<server>]\n"
"Returns the version of <server>, or the current server "
"if omitted.\r\n");
else if (!strcmp(token, "WALLOPS"))
snprintf(buff, PATH_MAX,"Syntatx: WALLOPS <message>\n"
"Sends <message> to all operators connected to the server, "
"or all users with user mode 'w' set.\r\n");
else if (!strcmp(token, "WATCH"))
snprintf(buff, PATH_MAX,"Syntatx: WATCH [+/-<nicknames>]\n"
"Adds or removes a user to a client's server-side friends "
"list. More than one nickname may be specified in a "
"space-separated list, each item prefixed with a \"+\" or "
"\"-\" to designate whether it is being added or removed. "
"Sending the command with no parameters returns the "
"entries in the client's friends list.\r\n");
else if (!strcmp(token, "WHO"))
snprintf(buff, PATH_MAX,"Syntatx: WHO [<name> [\"o\"]]\n"
"Returns a list of users who match <name>. If the flag "
"\"o\" is given, the server will only return information "
"about IRC Operators.\r\n");
else if (!strcmp(token, "WHOIS"))
snprintf(buff, PATH_MAX,"Syntatx: WHOIS [<server>] <nicknames>\n"
"Returns information about the comma-separated list of "
"nicknames masks <nicknames>. If <server> is given, the "
"command is forwarded to it for processing.\r\n");
else if (!strcmp(token, "WHOWAS"))
snprintf(buff, PATH_MAX,"Syntatx: WHOWAS <nickname> [<count> [<server>]]\n"
"Used to return information about a nickname that is no longer "
"in use (due to client disconnection, or nickname changes). If "
"given, the server will return information from the last <count> "
"times the nickname has been used. If <server> is given, the "
"command is forwarded to it for processing. <nickname> can be "
"a comma-separated list of nicknames.\r\n");
else
help_help:
snprintf(buff, PATH_MAX, "/HELP <command>\n Available commands"
" are: ADMIN AWAY CNOTICE CPRIVMSG CONNECT DIE ENCAP "
"ERROR INFO INVITE ISON JOIN KICK KILL KNOCK LINKS "
"LIST LUSERS MODE MOTD NAMES NAMESX NICK NOTICE OPER "
"PART PASS PING PONG PRIVMSG QUIT REHASH RESTART "
"RULES SERVER SERVICE SERVLIST SQUERY SQUIT SETNAME "
"SILENCE STATS SUMMON TIME TOPIC TRACE UHNAMES USER "
"USERHOST USERIP USERS VERSION WALLOPS WATCH WHO "
"WHOIS WHOWAS\r\n");
}
void
handle_txt(Express_Network *channel_net, const char *channel_name, char *str, char *buff)
{
char **tokens, *cmd = strdup(str);
eina_str_toupper(&cmd);
tokens = eina_str_split(cmd, " ", 0);
if (!strcmp(tokens[0], "/HELP"))
{
_handle_help_cmd(tokens[1], buff);
}
else
{
snprintf(buff, PATH_MAX, "%s\r\n", str);
express_network_channel_priv_send(channel_net, channel_name, buff);
}
free(cmd);
}

6
src/bin/commands.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef _COMMANDS_H_
# define _COMMANDS_H_ 1
void handle_txt(Express_Network *channel_net, const char *channel_name, char *str, char *buff);
#endif