summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/fe-common/irc/fe-events-numeric.c38
-rw-r--r--src/fe-common/irc/fe-events.c18
-rw-r--r--src/fe-common/irc/module-formats.c3
-rw-r--r--src/fe-common/irc/module-formats.h3
-rw-r--r--src/irc/core/irc-commands.c72
-rw-r--r--src/irc/core/irc-server.h2
6 files changed, 127 insertions, 9 deletions
diff --git a/src/fe-common/irc/fe-events-numeric.c b/src/fe-common/irc/fe-events-numeric.c
index 246bdef9..3d66652c 100644
--- a/src/fe-common/irc/fe-events-numeric.c
+++ b/src/fe-common/irc/fe-events-numeric.c
@@ -425,6 +425,17 @@ static void event_whois_oper(gchar *data, IRC_SERVER_REC *server)
g_free(params);
}
+static void event_whowas(const char *data, IRC_SERVER_REC *server)
+{
+ char *params, *nick, *user, *host, *realname;
+
+ g_return_if_fail(data != NULL);
+
+ params = event_get_params(data, 6, NULL, &nick, &user, &host, NULL, &realname);
+ printformat(server, NULL, MSGLEVEL_CRAP, IRCTXT_WHOWAS, nick, user, host, realname);
+ g_free(params);
+}
+
static void event_whois_channels(gchar *data, IRC_SERVER_REC *server)
{
gchar *params, *nick, *chans;
@@ -473,15 +484,26 @@ static void event_whois_away(gchar *data, IRC_SERVER_REC *server)
g_free(params);
}
-static void event_end_of_whois(gchar *data, IRC_SERVER_REC *server)
+static void event_end_of_whois(const char *data, IRC_SERVER_REC *server)
{
- gchar *params, *nick;
+ char *params, *nick;
- g_return_if_fail(data != NULL);
+ g_return_if_fail(data != NULL);
- params = event_get_params(data, 2, NULL, &nick);
- printformat(server, NULL, MSGLEVEL_CRAP, IRCTXT_END_OF_WHOIS, nick);
- g_free(params);
+ params = event_get_params(data, 2, NULL, &nick);
+ if (server->whois_found) printformat(server, NULL, MSGLEVEL_CRAP, IRCTXT_END_OF_WHOIS, nick);
+ g_free(params);
+}
+
+static void event_end_of_whowas(const char *data, IRC_SERVER_REC *server)
+{
+ char *params, *nick;
+
+ g_return_if_fail(data != NULL);
+
+ params = event_get_params(data, 2, NULL, &nick);
+ printformat(server, NULL, MSGLEVEL_CRAP, IRCTXT_END_OF_WHOWAS, nick);
+ g_free(params);
}
static void event_target_unavailable(gchar *data, IRC_SERVER_REC *server)
@@ -646,8 +668,10 @@ void fe_events_numeric_init(void)
signal_add("event 301", (SIGNAL_FUNC) event_whois_away);
signal_add("event 312", (SIGNAL_FUNC) event_whois_server);
signal_add("event 313", (SIGNAL_FUNC) event_whois_oper);
+ signal_add("event 314", (SIGNAL_FUNC) event_whowas);
signal_add("event 317", (SIGNAL_FUNC) event_whois_idle);
signal_add("event 318", (SIGNAL_FUNC) event_end_of_whois);
+ signal_add("event 369", (SIGNAL_FUNC) event_end_of_whowas);
signal_add("event 319", (SIGNAL_FUNC) event_whois_channels);
signal_add("event 302", (SIGNAL_FUNC) event_userhost);
signal_add("event 341", (SIGNAL_FUNC) event_sent_invite);
@@ -698,8 +722,10 @@ void fe_events_numeric_deinit(void)
signal_remove("event 301", (SIGNAL_FUNC) event_whois_away);
signal_remove("event 312", (SIGNAL_FUNC) event_whois_server);
signal_remove("event 313", (SIGNAL_FUNC) event_whois_oper);
+ signal_remove("event 314", (SIGNAL_FUNC) event_whowas);
signal_remove("event 317", (SIGNAL_FUNC) event_whois_idle);
signal_remove("event 318", (SIGNAL_FUNC) event_end_of_whois);
+ signal_remove("event 369", (SIGNAL_FUNC) event_end_of_whowas);
signal_remove("event 319", (SIGNAL_FUNC) event_whois_channels);
signal_remove("event 302", (SIGNAL_FUNC) event_userhost);
signal_remove("event 341", (SIGNAL_FUNC) event_sent_invite);
diff --git a/src/fe-common/irc/fe-events.c b/src/fe-common/irc/fe-events.c
index ab893e15..b25e06f1 100644
--- a/src/fe-common/irc/fe-events.c
+++ b/src/fe-common/irc/fe-events.c
@@ -564,6 +564,22 @@ static void event_ban_type_changed(gchar *bantype)
}
}
+static void sig_whowas_event_end(const char *data, IRC_SERVER_REC *server, const char *sender, const char *addr)
+{
+ char *params, *nick;
+
+ g_return_if_fail(data != NULL);
+
+ if (server->whowas_found) {
+ signal_emit("event 369", 4, data, server, sender, addr);
+ return;
+ }
+
+ params = event_get_params(data, 2, NULL, &nick);
+ printformat(server, NULL, MSGLEVEL_CRAP, IRCTXT_WHOIS_NOT_FOUND, nick);
+ g_free(params);
+}
+
static void sig_server_lag_disconnected(IRC_SERVER_REC *server)
{
g_return_if_fail(server != NULL);
@@ -646,6 +662,7 @@ void fe_events_init(void)
signal_add("event connected", (SIGNAL_FUNC) event_connected);
signal_add("nickfind event whois", (SIGNAL_FUNC) event_nickfind_whois);
signal_add("ban type changed", (SIGNAL_FUNC) event_ban_type_changed);
+ signal_add("whowas event end", (SIGNAL_FUNC) sig_whowas_event_end);
signal_add("server lag disconnect", (SIGNAL_FUNC) sig_server_lag_disconnected);
signal_add("server reconnect remove", (SIGNAL_FUNC) sig_server_reconnect_removed);
@@ -678,6 +695,7 @@ void fe_events_deinit(void)
signal_remove("event connected", (SIGNAL_FUNC) event_connected);
signal_remove("nickfind event whois", (SIGNAL_FUNC) event_nickfind_whois);
signal_remove("ban type changed", (SIGNAL_FUNC) event_ban_type_changed);
+ signal_remove("whowas event end", (SIGNAL_FUNC) sig_whowas_event_end);
signal_remove("server lag disconnect", (SIGNAL_FUNC) sig_server_lag_disconnected);
signal_remove("server reconnect remove", (SIGNAL_FUNC) sig_server_reconnect_removed);
diff --git a/src/fe-common/irc/module-formats.c b/src/fe-common/irc/module-formats.c
index 244ec7f1..447ce8fe 100644
--- a/src/fe-common/irc/module-formats.c
+++ b/src/fe-common/irc/module-formats.c
@@ -122,6 +122,7 @@ FORMAT_REC fecommon_irc_formats[] = {
{ NULL, "Who queries", 0 },
{ "whois", "%_$0%_ %K[%n$1@$2%K]%n%: ircname : $3", 4, { 0, 0, 0, 0 } },
+ { "whowas", "%_$0%_ %K[%n$1@$2%K]%n%: ircname : $3", 4, { 0, 0, 0, 0 } },
{ "whois_idle", " idle : $1 hours $2 mins $3 secs", 4, { 0, 1, 1, 1 } },
{ "whois_idle_signon", " idle : $1 hours $2 mins $3 secs %K[%nsignon: $4%K]", 5, { 0, 1, 1, 1, 0 } },
{ "whois_server", " server : $1 %K[%n$2%K]", 3, { 0, 0, 0 } },
@@ -129,6 +130,8 @@ FORMAT_REC fecommon_irc_formats[] = {
{ "whois_channels", " channels : $1", 2, { 0, 0 } },
{ "whois_away", " away : $1", 2, { 0, 0 } },
{ "end_of_whois", "End of WHOIS", 1, { 0 } },
+ { "end_of_whowas", "End of WHOWAS", 1, { 0 } },
+ { "whois_not_found", "There is no such nick $0", 1, { 0 } },
{ "who", "$[-10]0 %|%_$[!9]1%_ $[!3]2 $[!2]3 $4@$5 %K(%W$6%K)", 7, { 0, 0, 0, 0, 0, 0, 0 } },
{ "end_of_who", "End of /WHO list", 1, { 0 } },
diff --git a/src/fe-common/irc/module-formats.h b/src/fe-common/irc/module-formats.h
index e5fc2def..1450b7cf 100644
--- a/src/fe-common/irc/module-formats.h
+++ b/src/fe-common/irc/module-formats.h
@@ -97,6 +97,7 @@ enum {
IRCTXT_FILL_5,
IRCTXT_WHOIS,
+ IRCTXT_WHOWAS,
IRCTXT_WHOIS_IDLE,
IRCTXT_WHOIS_IDLE_SIGNON,
IRCTXT_WHOIS_SERVER,
@@ -104,6 +105,8 @@ enum {
IRCTXT_WHOIS_CHANNELS,
IRCTXT_WHOIS_AWAY,
IRCTXT_END_OF_WHOIS,
+ IRCTXT_END_OF_WHOWAS,
+ IRCTXT_WHOIS_NOT_FOUND,
IRCTXT_WHO,
IRCTXT_END_OF_WHO,
diff --git a/src/irc/core/irc-commands.c b/src/irc/core/irc-commands.c
index 8df2c1bf..24b969ed 100644
--- a/src/irc/core/irc-commands.c
+++ b/src/irc/core/irc-commands.c
@@ -454,15 +454,74 @@ static void cmd_names(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item
static void cmd_whois(const char *data, IRC_SERVER_REC *server)
{
+ char *params, *qserver, *query, *nicks;
+ int one_nick;
+
g_return_if_fail(data != NULL);
if (server == NULL || !server->connected || !irc_server_check(server))
cmd_return_error(CMDERR_NOT_CONNECTED);
- while (*data == ' ') data++;
- if (*data == '\0') data = server->nick;
+ params = cmd_get_params(data, 2, &qserver, &query);
+ if (*query == '\0') {
+ g_free(params);
+ params = cmd_get_params(data, 1, &query);
+ qserver = "";
+ }
- g_string_sprintf(tmpstr, "WHOIS %s", data);
+ if (*query == '\0') query = server->nick;
+
+ if (*qserver == '\0')
+ g_string_sprintf(tmpstr, "WHOIS %s", query);
+ else
+ g_string_sprintf(tmpstr, "WHOIS %s %s", qserver, query);
irc_send_cmd_split(server, tmpstr->str, 2, server->max_whois_in_cmd);
+
+ /* do automatic /WHOWAS if any of the nicks wasn't found */
+ one_nick = strchr(query, ',') == NULL;
+ if (!one_nick) {
+ nicks = g_strdup(query);
+ g_strdelimit(query, ",", ' ');
+ query = g_strconcat(nicks, " ", query, NULL);
+ g_free(nicks);
+ }
+
+ server->whois_found = FALSE;
+ server_redirect_event((SERVER_REC *) server, query, 2,
+ "event 318", "event 318", 1,
+ "event 402", "event 402", -1,
+ "event 311", "whois event", 1,
+ "event 401", "whois not found", 1, NULL);
+ if (!one_nick) g_free(query);
+ g_free(params);
+}
+
+static void event_whois(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr)
+{
+ server->whois_found = TRUE;
+ signal_emit("event 311", 4, data, server, nick, addr);
+}
+
+static void sig_whois_not_found(const char *data, IRC_SERVER_REC *server)
+{
+ char *params, *nick;
+
+ g_return_if_fail(data != NULL);
+
+ params = event_get_params(data, 2, NULL, &nick);
+ irc_send_cmdv(server, "WHOWAS %s 1", nick);
+
+ server->whowas_found = FALSE;
+ server_redirect_event((SERVER_REC *) server, nick, 1,
+ "event 369", "whowas event end", 1,
+ "event 314", "whowas event", 1,
+ "event 406", "event empty", 1, NULL);
+ g_free(params);
+}
+
+static void event_whowas(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr)
+{
+ server->whowas_found = TRUE;
+ signal_emit("event 314", 4, data, server, nick, addr);
}
static void cmd_whowas(const char *data, IRC_SERVER_REC *server)
@@ -475,6 +534,7 @@ static void cmd_whowas(const char *data, IRC_SERVER_REC *server)
if (*data == '\0') data = server->nick;
irc_send_cmdv(server, "WHOWAS %s", data);
+ server->whowas_found = FALSE;
}
static void cmd_ping(const char *data, IRC_SERVER_REC *server, WI_IRC_REC *item)
@@ -855,6 +915,9 @@ void irc_commands_init(void)
signal_add("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed);
signal_add("server disconnected", (SIGNAL_FUNC) sig_server_disconnected);
+ signal_add("whois not found", (SIGNAL_FUNC) sig_whois_not_found);
+ signal_add("whois event", (SIGNAL_FUNC) event_whois);
+ signal_add("whowas event", (SIGNAL_FUNC) event_whowas);
}
void irc_commands_deinit(void)
@@ -918,6 +981,9 @@ void irc_commands_deinit(void)
command_unbind("knockout", (SIGNAL_FUNC) cmd_knockout);
signal_remove("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed);
signal_remove("server disconnected", (SIGNAL_FUNC) sig_server_disconnected);
+ signal_remove("whois not found", (SIGNAL_FUNC) sig_whois_not_found);
+ signal_remove("whois event", (SIGNAL_FUNC) event_whois);
+ signal_remove("whowas event", (SIGNAL_FUNC) event_whowas);
g_string_free(tmpstr, TRUE);
}
diff --git a/src/irc/core/irc-server.h b/src/irc/core/irc-server.h
index e3f7d960..00ced177 100644
--- a/src/irc/core/irc-server.h
+++ b/src/irc/core/irc-server.h
@@ -87,6 +87,8 @@ typedef struct {
int server_operator:1;
int whois_coming:1; /* Mostly just to display away message right.. */
+ int whois_found:1; /* Did WHOIS return any entries? */
+ int whowas_found:1; /* Did WHOWAS return any entries? */
int emode_known:1; /* Server understands ban exceptions and invite lists */
int no_multi_mode:1; /* Server doesn't understand MODE #chan1,#chan2,... */