From bc86fdcdb5f340d9e37f44648da8297126d10153 Mon Sep 17 00:00:00 2001 From: Srivardhan Hebbar Date: Thu, 16 Apr 2015 10:55:16 -0400 Subject: [PATCH] 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 Reviewers: devilhorns Differential Revision: https://phab.enlightenment.org/D2316 --- src/bin/Makefile.am | 6 +- src/bin/channel.c | 10 +- src/bin/commands.c | 323 ++++++++++++++++++++++++++++++++++++++++++++ src/bin/commands.h | 6 + 4 files changed, 338 insertions(+), 7 deletions(-) create mode 100644 src/bin/commands.c create mode 100644 src/bin/commands.h diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 5c6654a..feef8a0 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -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 \ diff --git a/src/bin/channel.c b/src/bin/channel.c index ee08ce0..903316d 100644 --- a/src/bin/channel.c +++ b/src/bin/channel.c @@ -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); diff --git a/src/bin/commands.c b/src/bin/commands.c new file mode 100644 index 0000000..4911e09 --- /dev/null +++ b/src/bin/commands.c @@ -0,0 +1,323 @@ +#include +#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 []\n" + "Instructs the server to return information about " + "the administrators of the server specified by " + ". Where is either a server or a " + "user. If 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 []\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 is " + "omitted, the away status is removed.\r\n"); + else if (!strcmp(token, "CNOTICE")) + snprintf(buff, PATH_MAX, "Syntax: CNOTICE :\n" + "Sends a channel NOTICE message to on 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 :\n" + "Sends a private message to on 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 [ []]\n" + "Instructs the server (or the current server, if " + " is omitted) to connect to on 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: : ENCAP \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 \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 []\n" + "Returns information about the server, or " + "the current server if 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 \n" + "Invites to the 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 \n" + "Queries the server to see if the clients in the " + "space-separated list 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 []\n" + "Makes the client join the channels in the comma-separated " + "list , specifying the passwords, if needed, in " + "the comma-separated list . 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 []\n" + "Forcibly removes from . This command may " + "only be issued by channel operators.\r\n"); + else if (!strcmp(token, "KILL")) + snprintf(buff, PATH_MAX, "Syntax: KILL \n" + "Forcibly removes 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 []\n" + "Sends a NOTICE to an invitation-only with an " + "optional , requesting an invite.\r\n"); + else if (!strcmp(token, "LINKS")) + snprintf(buff, PATH_MAX, "Syntax: LINKS [ []]\n" + "Lists all server links matching , if given, on " + ", or the current server if omitted.\r\n"); + else if (!strcmp(token, "LIST")) + snprintf(buff, PATH_MAX, "Syntax: LIST [ []]\n" + "Lists all channels on the server. If the comma-separated " + "list is given, it will return the channel topics. " + "If is given, the command will be forwarded to " + " for evaluation.\r\n"); + else if (!strcmp(token, "LUSERS")) + snprintf(buff, PATH_MAX, "Syntax: LUSERS [ []]\n" + "Returns statistics about the size of the network. If called " + "with no arguments, the statistics will reflect the entire " + "network. If is given, it will return only statistics " + "reflecting the masked subset of the network. If is " + "given, the command will be forwarded to for " + "evaluation.\r\n"); + else if (!strcmp(token, "MODE")) + snprintf(buff, PATH_MAX, "Syntax: MODE (user)\n MODE []\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 []\n" + "Returns the message of the day on or the current " + "server if it is omitted.\r\n"); + else if (!strcmp(token, "NAMES")) + snprintf(buff, PATH_MAX,"Syntax: NAMES [ []]\n" + "Returns a list of who is on the comma-separated list of " + ", by channel name. If 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 is specified, the command is sent to " + "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 []\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 \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 \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 []\n" + "Causes a user to leave the channels in the comma-separated " + "list .\r\n"); + else if (!strcmp(token, "PASS")) + snprintf(buff, PATH_MAX,"Syntax: PASS \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 []\n" + "Tests the presence of a connection. A PING message results " + "in a PONG reply. If is specified, the message " + "gets passed on to it.\r\n"); + else if (!strcmp(token, "PONG")) + snprintf(buff, PATH_MAX,"Syntax: PONG []" + "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 \n" + "Sends to , which is usually a user " + "or channel.\r\n"); + else if (!strcmp(token, "QUIT")) + snprintf(buff, PATH_MAX,"Syntax: QUIT []\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 \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. details " + "how many hops (server connections) away is. " + " contains addition human-readable information about " + "the server.\r\n"); + else if (!strcmp(token, "SERVICE")) + snprintf(buff, PATH_MAX,"Syntax: SERVICE \n" + "Registers a new service on the network.\r\n"); + else if (!strcmp(token, "SERVLIST")) + snprintf(buff, PATH_MAX,"Syntax: SERVLIST [ []]\n" + "Lists the services currently on the network.\r\n"); + else if (!strcmp(token, "SQUERY")) + snprintf(buff, PATH_MAX,"Syntax: SQUERY \n" + "Identical to PRIVMSG except the recipient must be a " + "service.\r\n"); + else if (!strcmp(token, "SQUIT")) + snprintf(buff, PATH_MAX,"Syntax: SQUIT \n" + "Causes to quit the network.\r\n"); + else if (!strcmp(token, "SETNAME")) + snprintf(buff, PATH_MAX,"Syntax: SETNAME \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 [+/-]\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 []\n" + "Returns statistics about the current server, or " + "if it's specified.\r\n"); + else if (!strcmp(token, "SUMMON")) + snprintf(buff, PATH_MAX,"Syntax: SUMMON [ []]\n" + "Gives users who are on the same host as a message " + "asking them to join IRC.\r\n"); + else if (!strcmp(token, "TIME")) + snprintf(buff, PATH_MAX,"Syntax: TIME []\n" + "Returns the local time on the current server, or " + "if specified.\r\n"); + else if (!strcmp(token, "TOPIC")) + snprintf(buff, PATH_MAX,"Syntax: TOPIC []\n" + "Allows the client to query or set the channel topic on " + ". If is given, it sets the channel topic " + "to . 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 []\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 \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. may contain spaces, and thus must be prefixed with a " + "colon.\r\n"); + else if (!strcmp(token, "USERHOST")) + snprintf(buff, PATH_MAX,"Syntatx: USERHOST [ ...]\n" + "Returns a list of information about the nicknames specified.\r\n"); + else if (!strcmp(token, "USERIP")) + snprintf(buff, PATH_MAX,"Syntatx: USERIP \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 []\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 []\n" + "Returns the version of , or the current server " + "if omitted.\r\n"); + else if (!strcmp(token, "WALLOPS")) + snprintf(buff, PATH_MAX,"Syntatx: WALLOPS \n" + "Sends 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 [+/-]\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 [ [\"o\"]]\n" + "Returns a list of users who match . 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 [] \n" + "Returns information about the comma-separated list of " + "nicknames masks . If is given, the " + "command is forwarded to it for processing.\r\n"); + else if (!strcmp(token, "WHOWAS")) + snprintf(buff, PATH_MAX,"Syntatx: WHOWAS [ []]\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 " + "times the nickname has been used. If is given, the " + "command is forwarded to it for processing. can be " + "a comma-separated list of nicknames.\r\n"); + else +help_help: + snprintf(buff, PATH_MAX, "/HELP \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); +} diff --git a/src/bin/commands.h b/src/bin/commands.h new file mode 100644 index 0000000..e853a0f --- /dev/null +++ b/src/bin/commands.h @@ -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