summaryrefslogtreecommitdiff
path: root/src/irc
diff options
context:
space:
mode:
Diffstat (limited to 'src/irc')
-rw-r--r--src/irc/irc-commands.c96
-rw-r--r--src/irc/irc-recv.c50
-rw-r--r--src/irc/irc.h5
3 files changed, 45 insertions, 106 deletions
diff --git a/src/irc/irc-commands.c b/src/irc/irc-commands.c
index 7ebd1921f..ddc295f20 100644
--- a/src/irc/irc-commands.c
+++ b/src/irc/irc-commands.c
@@ -307,74 +307,8 @@ t_irc_command irc_commands[] =
"", 1, MAX_ARGS, 0, 1, NULL, irc_cmd_send_whowas, NULL },
{ "001", N_("a server message"), "", "",
NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_001 },
- { "002", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "003", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "004", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "005", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "006", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "007", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "008", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "020", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "042", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "212", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "219", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
{ "221", N_("user mode string"), "", "",
NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_221 },
- { "250", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "251", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "252", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "253", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "254", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "255", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "256", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "257", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "258", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "259", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "260", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "261", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "262", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "263", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "264", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "265", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "266", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "267", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "268", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "269", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "290", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "292", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
{ "301", N_("away message"), "", "",
NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_301 },
{ "302", N_("userhost"), "", "",
@@ -387,8 +321,6 @@ t_irc_command irc_commands[] =
NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_306 },
{ "307", N_("whois (registered nick)"), "", "",
NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_307 },
- { "310", N_("available for help"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
{ "311", N_("whois (user)"), "", "",
NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_311 },
{ "312", N_("whois (server)"), "", "",
@@ -445,40 +377,14 @@ t_irc_command irc_commands[] =
N_("channel: name of channel\n"
" nick: nick on the channel"),
NULL, 2, 0, MAX_ARGS, 1, NULL, NULL, irc_cmd_recv_353 },
- { "364", N_("links"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "365", N_("end of /links list"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
{ "366", N_("end of /names list"), "", "",
NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_366 },
{ "367", N_("banlist"), "", "",
NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_367 },
{ "368", N_("end of banlist"), "", "",
NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_368 },
- { "369", N_("end of /whowas list"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "371", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "372", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "373", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "374", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "375", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "376", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
{ "378", N_("connecting from"), "", "",
NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_378 },
- { "379", N_("using modes"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "381", N_("you are now an IRC operator"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "382", N_("rehashing"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
- { "391", N_("server local time"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
{ "401", N_("no such nick/channel"), "", "",
NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_cmd_recv_error },
{ "402", N_("no such server"), "", "",
@@ -585,8 +491,6 @@ t_irc_command irc_commands[] =
NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_cmd_recv_error },
{ "502", N_("can't change mode for other users"), "", "",
NULL, 0, 0, MAX_ARGS, 1, NULL, NULL, irc_cmd_recv_error },
- { "505", N_("a server message"), "", "",
- NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_server_msg },
{ "671", N_("whois (secure connection)"), "", "",
NULL, 0, 0, 0, 1, NULL, NULL, irc_cmd_recv_671 },
{ "973", N_("whois (secure connection)"), "", "",
diff --git a/src/irc/irc-recv.c b/src/irc/irc-recv.c
index 56e1de775..225b57f4e 100644
--- a/src/irc/irc-recv.c
+++ b/src/irc/irc-recv.c
@@ -74,6 +74,21 @@ irc_is_word_char (char c)
return 0;
}
+/*
+ * irc_is_numeric: return 1 if given string is 100% numeric
+ */
+
+int
+irc_is_numeric (char *str)
+{
+ while (str && str[0])
+ {
+ if (!isdigit (str[0]))
+ return 0;
+ str++;
+ }
+ return 1;
+}
/*
* irc_is_highlight: returns 1 if given message contains highlight (with given nick
@@ -211,6 +226,8 @@ irc_recv_command (t_irc_server *server, char *entire_line,
int i, cmd_found, return_code;
char *pos, *nick, *args_after_color;
char *dup_entire_line, *dup_host, *dup_arguments;
+ t_irc_recv_func *cmd_recv_func;
+ char *cmd_name;
if (!command)
return -2;
@@ -225,21 +242,38 @@ irc_recv_command (t_irc_server *server, char *entire_line,
break;
}
}
-
+
/* command not found */
if (cmd_found < 0)
- return -3;
+ {
+ /* for numeric commands, we use default recv function (irc_recv_server_msg) */
+ if (irc_is_numeric (command))
+ {
+ cmd_name = command;
+ cmd_recv_func = irc_cmd_recv_server_msg;
+ }
+ else
+ return -3;
+ }
+ else
+ {
+ cmd_name = irc_commands[cmd_found].command_name;
+ cmd_recv_func = irc_commands[cmd_found].recv_function;
+ }
- if (irc_commands[i].recv_function != NULL)
+ if (cmd_recv_func != NULL)
{
dup_entire_line = (entire_line) ? strdup (entire_line) : NULL;
dup_host = (host) ? strdup (host) : NULL;
dup_arguments = (arguments) ? strdup (arguments) : NULL;
- command_ignored = ignore_check (dup_host, irc_commands[i].command_name, NULL, server->name);
+ command_ignored = ignore_check (dup_host,
+ cmd_name,
+ NULL,
+ server->name);
#ifdef PLUGINS
return_code = plugin_msg_handler_exec (server->name,
- irc_commands[i].command_name,
+ cmd_name,
dup_entire_line);
/* plugin handler choosed to discard message for WeeChat,
so we ignore this message in standard handler */
@@ -255,9 +289,9 @@ irc_recv_command (t_irc_server *server, char *entire_line,
args_after_color = (char *)gui_color_decode ((unsigned char *)dup_arguments,
cfg_irc_colors_receive);
irc_last_command_received = strdup (dup_entire_line);
- return_code = (int) (irc_commands[i].recv_function) (server, dup_host, nick,
- (args_after_color) ?
- args_after_color : dup_arguments);
+ return_code = (int) (cmd_recv_func) (server, dup_host, nick,
+ (args_after_color) ?
+ args_after_color : dup_arguments);
if (irc_last_command_received)
free (irc_last_command_received);
if (args_after_color)
diff --git a/src/irc/irc.h b/src/irc/irc.h
index 25f826c41..f1b9ee3f9 100644
--- a/src/irc/irc.h
+++ b/src/irc/irc.h
@@ -200,6 +200,8 @@ struct t_irc_server
/* irc commands */
+typedef int (t_irc_recv_func)(t_irc_server *, char *, char *, char *);
+
typedef struct t_irc_command t_irc_command;
struct t_irc_command
@@ -218,8 +220,7 @@ struct t_irc_command
/* function called when user enters cmd */
int (*cmd_function_1arg)(t_irc_server *, t_irc_channel *, char *);
/* function called when user enters cmd */
- int (*recv_function)(t_irc_server *, char *, char *, char *);
- /* function called when cmd is received */
+ t_irc_recv_func *recv_function; /* function called when cmd is received */
};
/* irc messages */