From f5339edbbc921dc225ba5fba2cc59d19b08db7c7 Mon Sep 17 00:00:00 2001 From: Ailin Nemui Date: Fri, 12 Mar 2021 21:15:58 +0100 Subject: [PATCH] fail redirects on freenode 263 --- src/irc/core/servers-redirect.c | 38 +++++++++++++++++++++++++++------ src/irc/core/servers-redirect.h | 5 ++--- src/perl/irc/Server.xs | 7 +++--- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/irc/core/servers-redirect.c b/src/irc/core/servers-redirect.c index 2790c75a..72601d34 100644 --- a/src/irc/core/servers-redirect.c +++ b/src/irc/core/servers-redirect.c @@ -39,6 +39,7 @@ typedef struct { int remote; int timeout; + int pos; GSList *start, *stop, *opt; /* char *event, int argpos, ... */ } REDIRECT_CMD_REC; @@ -151,13 +152,11 @@ void server_redirect_register(const char *command, va_end(va); - server_redirect_register_list(command, remote, timeout, - start, stop, opt); + server_redirect_register_list(command, remote, timeout, start, stop, opt, 0); } -void server_redirect_register_list(const char *command, - int remote, int timeout, - GSList *start, GSList *stop, GSList *opt) +void server_redirect_register_list(const char *command, int remote, int timeout, GSList *start, + GSList *stop, GSList *opt, int pos) { REDIRECT_CMD_REC *rec; gpointer key, value; @@ -181,7 +180,8 @@ void server_redirect_register_list(const char *command, rec->start = start; rec->stop = stop; rec->opt = opt; - g_hash_table_insert(command_redirects, rec->name, rec); + rec->pos = pos; + g_hash_table_insert(command_redirects, rec->name, rec); } void server_redirect_event(IRC_SERVER_REC *server, const char *command, @@ -483,6 +483,32 @@ static REDIRECT_REC *redirect_find(IRC_SERVER_REC *server, const char *event, } } + if (g_strcmp0("event 263", event) == 0) { /* RPL_TRYAGAIN */ + char *params, *command; + params = event_get_params(args, 3, NULL, &command, NULL); + + for (tmp = server->redirects; tmp != NULL; tmp = next) { + REDIRECT_REC *rec = tmp->data; + + next = tmp->next; + + if (rec == redirect) + break; + + if (g_slist_find(server->redirect_active, rec) != NULL) + continue; + + if (redirect_args_match(rec->cmd->name, command, rec->cmd->pos)) { + /* the server crashed our command with RPL_TRYAGAIN, send the + failure */ + rec->aborted = TRUE; + redirect_abort(server, rec); + break; + } + } + g_free(params); + } + /* remove the destroyed, non-remote and timeouted remote redirections that should have happened before this redirection */ now = time(NULL); diff --git a/src/irc/core/servers-redirect.h b/src/irc/core/servers-redirect.h index f8ca605f..0d8b63f8 100644 --- a/src/irc/core/servers-redirect.h +++ b/src/irc/core/servers-redirect.h @@ -22,9 +22,8 @@ void server_redirect_register(const char *command, int remote, int timeout, ...); /* start/stop/opt lists shouldn't be free'd after, and their strings should be dynamically allocated */ -void server_redirect_register_list(const char *command, - int remote, int timeout, - GSList *start, GSList *stop, GSList *opt); +void server_redirect_register_list(const char *command, int remote, int timeout, GSList *start, + GSList *stop, GSList *opt, int pos); /* Specify that the next command sent to server will be redirected. NOTE: This command MUST be called before irc_send_cmd(). diff --git a/src/perl/irc/Server.xs b/src/perl/irc/Server.xs index a42f5c82..54361ec9 100644 --- a/src/perl/irc/Server.xs +++ b/src/perl/irc/Server.xs @@ -97,10 +97,9 @@ server_redirect_register(command, remote, timeout, start, stop, opt) SV *stop SV *opt CODE: - server_redirect_register_list(command, remote, timeout, - register_hash2list(hvref(start)), - register_hash2list(hvref(stop)), - register_hash2list(hvref(opt))); + server_redirect_register_list(command, remote, timeout, register_hash2list(hvref(start)), + register_hash2list(hvref(stop)), + register_hash2list(hvref(opt)), 1); void server_redirect_event(server, command, count, arg, remote, failure_signal, signals)