1
0
mirror of https://github.com/irssi/irssi.git synced 2024-11-03 04:27:19 -05:00

Redirection fixes - added count parameter.

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1999 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2001-11-12 22:15:04 +00:00 committed by cras
parent 1673246497
commit e66ec6cf8b
11 changed files with 89 additions and 67 deletions

View File

@ -309,7 +309,7 @@ static void event_connected(IRC_SERVER_REC *server)
return;
/* someone has our nick, find out who. */
server_redirect_event(server, "whois", nick, FALSE, NULL,
server_redirect_event(server, "whois", 1, nick, FALSE, NULL,
"event 311", "nickfind event whois",
"", "event empty", NULL);
irc_send_cmdv(server, "WHOIS %s", nick);

View File

@ -169,7 +169,7 @@ static void channel_send_query(IRC_SERVER_REC *server, int query)
IRC_CHANNEL_REC *chanrec;
GSList *chans, *newchans;
char *cmd, *chanstr_commas, *chanstr;
int onlyone;
int onlyone, count;
rec = server->chanqueries;
g_return_if_fail(rec != NULL);
@ -183,15 +183,19 @@ static void channel_send_query(IRC_SERVER_REC *server, int query)
chans = g_slist_append(NULL, chanrec);
chanstr_commas = g_strdup(chanrec->name);
chanstr = g_strdup(chanrec->name);
count = 1;
} else {
char *chanstr_spaces;
chans = rec->queries[query];
count = g_slist_length(chans);
if ((int)g_slist_length(rec->queries[query]) > server->max_query_chans) {
if (count > server->max_query_chans) {
GSList *lastchan;
lastchan = g_slist_nth(rec->queries[query], server->max_query_chans-1);
lastchan = g_slist_nth(rec->queries[query],
server->max_query_chans-1);
count = server->max_query_chans;
newchans = lastchan->next;
lastchan->next = NULL;
}
@ -206,8 +210,10 @@ static void channel_send_query(IRC_SERVER_REC *server, int query)
switch (query) {
case CHANNEL_QUERY_MODE:
cmd = g_strdup_printf("MODE %s", chanstr_commas);
server_redirect_event(server, "mode channel", chanstr, -1,
"chanquery mode abort",
/* the stop-event is received once for each channel */
server_redirect_event(server, "mode channel", count,
chanstr, -1, "chanquery mode abort",
"event 324", "chanquery mode",
"", "chanquery mode abort", NULL);
break;
@ -215,7 +221,9 @@ static void channel_send_query(IRC_SERVER_REC *server, int query)
case CHANNEL_QUERY_WHO:
cmd = g_strdup_printf("WHO %s", chanstr_commas);
server_redirect_event(server, "who", chanstr, -1,
server_redirect_event(server, "who",
server->one_endofwho ? 1 : count,
chanstr, -1,
"chanquery who abort",
"event 315", "chanquery who end",
"event 352", "silent event who",
@ -228,7 +236,7 @@ static void channel_send_query(IRC_SERVER_REC *server, int query)
mode requests - if channels are joined manually
irssi could ask modes separately but afterwards
join the two b/e/I modes together */
server_redirect_event(server, "mode b", chanstr, -1,
server_redirect_event(server, "mode b", count, chanstr, -1,
"chanquery mode abort",
"event 367", "chanquery ban",
"event 368", "chanquery ban end",
@ -237,7 +245,7 @@ static void channel_send_query(IRC_SERVER_REC *server, int query)
case CHANNEL_QUERY_EMODE:
cmd = g_strdup_printf("MODE %s e", chanstr_commas);
server_redirect_event(server, "mode e", chanstr, -1,
server_redirect_event(server, "mode e", count, chanstr, -1,
"chanquery mode abort",
"event 348", "chanquery eban",
"event 349", "chanquery eban end",
@ -246,7 +254,7 @@ static void channel_send_query(IRC_SERVER_REC *server, int query)
case CHANNEL_QUERY_IMODE:
cmd = g_strdup_printf("MODE %s I", chanstr_commas);
server_redirect_event(server, "mode I", chanstr, -1,
server_redirect_event(server, "mode I", count, chanstr, -1,
"chanquery mode abort",
"event 346", "chanquery ilist",
"event 347", "chanquery ilist end",
@ -273,7 +281,8 @@ static void channel_send_query(IRC_SERVER_REC *server, int query)
rec->queries[query] = newchans;
} else {
/* remove the first channel from list */
rec->queries[query] = g_slist_remove(rec->queries[query], chans->data);
rec->queries[query] =
g_slist_remove(rec->queries[query], chans->data);
}
/* send the command */

View File

@ -384,7 +384,7 @@ static void cmd_whois(const char *data, IRC_SERVER_REC *server,
query = get_redirect_nicklist(query, &free_nick);
str = g_strconcat(qserver, " ", query, NULL);
server_redirect_event(server, "whois", str, *qserver != '\0',
server_redirect_event(server, "whois", 1, str, *qserver != '\0',
NULL,
"event 318", "event 318",
"event 402", event_402,
@ -415,7 +415,7 @@ static void sig_whois_not_found(IRC_SERVER_REC *server, const char *data)
params = event_get_params(data, 2, NULL, &nick);
server->whowas_found = FALSE;
server_redirect_event(server, "whowas", nick, -1, NULL,
server_redirect_event(server, "whowas", 1, nick, -1, NULL,
"event 314", "whowas event",
"event 369", "whowas event end",
"", "event empty", NULL);
@ -444,7 +444,7 @@ static void cmd_whowas(const char *data, IRC_SERVER_REC *server)
if (*nicks == '\0') nicks = server->nick;
nicks_redir = get_redirect_nicklist(nicks, &free_nick);
server_redirect_event(server, "whowas", nicks_redir, -1, NULL,
server_redirect_event(server, "whowas", 1, nicks_redir, -1, NULL,
"event 314", "whowas event", NULL);
if (free_nick) g_free(nicks_redir);

View File

@ -62,7 +62,7 @@ static void lag_send(LAG_REC *lag)
server = lag->server;
server->lag_sent = server->lag_last_check = time(NULL);
server_redirect_event(server, "ping", NULL, FALSE,
server_redirect_event(server, "ping", 1, NULL, FALSE,
"lag ping error",
"event pong", "lag pong", NULL);
irc_send_cmdv(server, "PING %s", server->real_address);

View File

@ -30,7 +30,8 @@ typedef struct {
char *arg;
int tag;
char *redirect_cmd;
char *redirect_cmd;
int count;
int remote;
char *failure_signal;
GSList *redirects;
@ -40,8 +41,9 @@ static int idle_tag, idlepos;
/* Add new idle command to queue */
static SERVER_IDLE_REC *
server_idle_create(const char *cmd, const char *redirect_cmd, const char *arg,
int remote, const char *failure_signal, va_list va)
server_idle_create(const char *cmd, const char *redirect_cmd, int count,
const char *arg, int remote, const char *failure_signal,
va_list va)
{
SERVER_IDLE_REC *rec;
const char *event, *signal;
@ -54,6 +56,7 @@ server_idle_create(const char *cmd, const char *redirect_cmd, const char *arg,
rec->tag = ++idlepos;
rec->redirect_cmd = g_strdup(redirect_cmd);
rec->count = count;
rec->remote = remote;
rec->failure_signal = g_strdup(failure_signal);
@ -93,7 +96,7 @@ static SERVER_IDLE_REC *server_idle_find_rec(IRC_SERVER_REC *server, int tag)
/* Add new idle command to queue */
int server_idle_add_redir(IRC_SERVER_REC *server, const char *cmd,
const char *redirect_cmd, const char *arg,
const char *redirect_cmd, int count, const char *arg,
int remote, const char *failure_signal, ...)
{
va_list va;
@ -102,7 +105,7 @@ int server_idle_add_redir(IRC_SERVER_REC *server, const char *cmd,
g_return_val_if_fail(server != NULL, -1);
va_start(va, failure_signal);
rec = server_idle_create(cmd, redirect_cmd, arg, remote,
rec = server_idle_create(cmd, redirect_cmd, count, arg, remote,
failure_signal, va);
server->idles = g_slist_append(server->idles, rec);
va_end(va);
@ -112,8 +115,9 @@ int server_idle_add_redir(IRC_SERVER_REC *server, const char *cmd,
/* Add new idle command to first of queue */
int server_idle_add_first_redir(IRC_SERVER_REC *server, const char *cmd,
const char *redirect_cmd, const char *arg,
int remote, const char *failure_signal, ...)
const char *redirect_cmd, int count,
const char *arg, int remote,
const char *failure_signal, ...)
{
va_list va;
SERVER_IDLE_REC *rec;
@ -121,7 +125,7 @@ int server_idle_add_first_redir(IRC_SERVER_REC *server, const char *cmd,
g_return_val_if_fail(server != NULL, -1);
va_start(va, failure_signal);
rec = server_idle_create(cmd, redirect_cmd, arg, remote,
rec = server_idle_create(cmd, redirect_cmd, count, arg, remote,
failure_signal, va);
server->idles = g_slist_prepend(server->idles, rec);
va_end(va);
@ -131,8 +135,9 @@ int server_idle_add_first_redir(IRC_SERVER_REC *server, const char *cmd,
/* Add new idle command to specified position of queue */
int server_idle_insert_redir(IRC_SERVER_REC *server, const char *cmd, int tag,
const char *redirect_cmd, const char *arg,
int remote, const char *failure_signal, ...)
const char *redirect_cmd, int count,
const char *arg, int remote,
const char *failure_signal, ...)
{
va_list va;
SERVER_IDLE_REC *rec;
@ -146,7 +151,7 @@ int server_idle_insert_redir(IRC_SERVER_REC *server, const char *cmd, int tag,
rec = server_idle_find_rec(server, tag);
pos = g_slist_index(server->idles, rec);
rec = server_idle_create(cmd, redirect_cmd, arg, remote,
rec = server_idle_create(cmd, redirect_cmd, count, arg, remote,
failure_signal, va);
server->idles = pos < 0 ?
g_slist_append(server->idles, rec) :
@ -206,7 +211,8 @@ static void server_idle_next(IRC_SERVER_REC *server)
/* Send command */
if (rec->redirect_cmd != NULL) {
server_redirect_event_list(server, rec->redirect_cmd, rec->arg,
server_redirect_event_list(server, rec->redirect_cmd,
rec->count, rec->arg,
rec->remote, rec->failure_signal,
rec->redirects);
}

View File

@ -3,24 +3,27 @@
/* Add new idle command to queue */
int server_idle_add_redir(IRC_SERVER_REC *server, const char *cmd,
const char *redirect_cmd, const char *arg,
int remote, const char *failure_signal, ...);
const char *redirect_cmd, int count,
const char *arg, int remote,
const char *failure_signal, ...);
#define server_idle_add(server, cmd) \
server_idle_add_redir(server, cmd, NULL, NULL, 0, NULL, NULL)
server_idle_add_redir(server, cmd, NULL, 0, NULL, 0, NULL, NULL)
/* Add new idle command to first of queue */
int server_idle_add_first_redir(IRC_SERVER_REC *server, const char *cmd,
const char *redirect_cmd, const char *arg,
int remote, const char *failure_signal, ...);
const char *redirect_cmd, int count,
const char *arg, int remote,
const char *failure_signal, ...);
#define server_idle_add_first(server, cmd) \
server_idle_add_first_redir(server, cmd, NULL, NULL, 0, NULL, NULL)
server_idle_add_first_redir(server, cmd, NULL, 0, NULL, 0, NULL, NULL)
/* Add new idle command to specified position of queue */
int server_idle_insert_redir(IRC_SERVER_REC *server, const char *cmd, int tag,
const char *redirect_cmd, const char *arg,
int remote, const char *failure_signal, ...);
const char *redirect_cmd, int count,
const char *arg, int remote,
const char *failure_signal, ...);
#define server_idle_insert(server, cmd, tag) \
server_idle_insert_redir(server, cmd, tag, NULL, NULL, 0, NULL, NULL)
server_idle_insert_redir(server, cmd, tag, NULL, 0, NULL, 0, NULL, NULL)
/* Check if record is still in queue */
int server_idle_find(IRC_SERVER_REC *server, int tag);

View File

@ -38,9 +38,10 @@ typedef struct {
struct _REDIRECT_REC {
REDIRECT_CMD_REC *cmd;
time_t created;
int destroyed;
int destroyed;
char *arg;
int count;
int remote;
char *failure_signal, *default_signal;
GSList *signals; /* event, signal, ... */
@ -160,7 +161,7 @@ void server_redirect_register_list(const char *command,
}
void server_redirect_event(IRC_SERVER_REC *server, const char *command,
const char *arg, int remote,
int count, const char *arg, int remote,
const char *failure_signal, ...)
{
GSList *signals;
@ -183,12 +184,12 @@ void server_redirect_event(IRC_SERVER_REC *server, const char *command,
va_end(va);
server_redirect_event_list(server, command, arg, remote,
server_redirect_event_list(server, command, count, arg, remote,
failure_signal, signals);
}
void server_redirect_event_list(IRC_SERVER_REC *server, const char *command,
const char *arg, int remote,
int count, const char *arg, int remote,
const char *failure_signal, GSList *signals)
{
REDIRECT_CMD_REC *cmdrec;
@ -200,11 +201,6 @@ void server_redirect_event_list(IRC_SERVER_REC *server, const char *command,
g_return_if_fail(command != NULL);
g_return_if_fail((g_slist_length(signals) & 1) == 0);
if (server->redirect_next != NULL) {
server_redirect_destroy(server->redirect_next);
server->redirect_next = NULL;
}
cmdrec = g_hash_table_lookup(command_redirects, command);
if (cmdrec == NULL) {
g_warning("Unknown redirection command: %s", command);
@ -217,6 +213,7 @@ void server_redirect_event_list(IRC_SERVER_REC *server, const char *command,
rec->created = time(NULL);
rec->cmd = cmdrec;
rec->arg = g_strdup(arg);
rec->count = count;
rec->remote = remote != -1 ? remote : cmdrec->remote;
rec->failure_signal = g_strdup(failure_signal);
@ -231,6 +228,8 @@ void server_redirect_event_list(IRC_SERVER_REC *server, const char *command,
}
rec->signals = signals;
if (server->redirect_next != NULL)
server_redirect_destroy(server->redirect_next);
server->redirect_next = rec;
}
@ -243,12 +242,12 @@ void server_redirect_command(IRC_SERVER_REC *server, const char *command,
g_return_if_fail(command != NULL);
if (redirect == NULL) {
/* no redirection wanted, but still register the command
so future redirections wont get messed up. */
cmdrec = redirect_cmd_find(command);
if (cmdrec == NULL)
return;
/* no redirection wanted, but still register the command
so future redirections wont get messed up. */
redirect_cmd_ref(cmdrec);
redirect = g_new0(REDIRECT_REC, 1);
@ -454,7 +453,8 @@ const char *server_redirect_get_signal(IRC_SERVER_REC *server,
/* stop event - remove this redirection next time this
function is called (can't destroy now or our return
value would be corrupted) */
redirect->destroyed = TRUE;
if (--redirect->count <= 0)
redirect->destroyed = TRUE;
server->redirect_continue = NULL;
}
@ -482,7 +482,7 @@ static void sig_disconnected(IRC_SERVER_REC *server)
g_slist_free(server->redirects);
if (server->redirect_next != NULL)
server_redirect_destroy(server->redirect_next);
server_redirect_destroy(server->redirect_next);
}
static void cmd_redirect_destroy(char *key, REDIRECT_CMD_REC *cmd)

View File

@ -29,6 +29,9 @@ void server_redirect_register_list(const char *command,
command - Specifies the registered command that should be used for this
redirection.
count - How many times to execute the redirection. Some commands may send
multiple stop events, like MODE #a,#b.
arg - The argument to be compared in event strings. You can give multiple
arguments separated with space.
@ -41,12 +44,12 @@ void server_redirect_register_list(const char *command,
If the `event' is "", all the events belonging to the redirection but not
specified here, will be sent there. */
void server_redirect_event(IRC_SERVER_REC *server, const char *command,
const char *arg, int remote,
int count, const char *arg, int remote,
const char *failure_signal, ...);
/* Signals list shouldn't be free'd after, and it's strings should be
dynamically allocated */
void server_redirect_event_list(IRC_SERVER_REC *server, const char *command,
const char *arg, int remote,
int count, const char *arg, int remote,
const char *failure_signal, GSList *signals);
/* INTERNAL: */

View File

@ -91,7 +91,7 @@ static void ison_send(IRC_SERVER_REC *server, GString *cmd)
g_string_truncate(cmd, cmd->len-1);
g_string_prepend(cmd, "ISON :");
server_redirect_event(server, "ison", NULL, -1, NULL,
server_redirect_event(server, "ison", 1, NULL, -1, NULL,
"event 303", "notifylist event", NULL);
irc_send_cmd(server, cmd->str);
@ -177,7 +177,7 @@ static void whois_send(IRC_SERVER_REC *server, char *nicks)
for (p = str+strlen(nicks)+1; *p != '\0'; p++)
if (*p == ',') *p = ' ';
server_redirect_event(server, "whois", str, FALSE,
server_redirect_event(server, "whois", 1, str, FALSE,
"notifylist event whois end",
"event 318", "notifylist event whois end",
"event 311", "notifylist event whois",

View File

@ -50,15 +50,15 @@ static void remove_client(CLIENT_REC *rec)
}
static void proxy_redirect_event(CLIENT_REC *client, const char *command,
const char *arg, int remote)
int count, const char *arg, int remote)
{
char *str;
g_return_if_fail(client != NULL);
str = g_strdup_printf("proxy %p", client);
server_redirect_event(client->server, command, arg, remote, NULL,
"", str, NULL);
server_redirect_event(client->server, command, count,
arg, remote, NULL, "", str, NULL);
g_free(str);
}
@ -79,7 +79,7 @@ static void grab_who(CLIENT_REC *client, const char *channel)
}
chanevent = g_strdup_printf("%s %s", chlist, *tmp);
proxy_redirect_event(client, "who", chanevent, -1);
proxy_redirect_event(client, "who", 1, chanevent, -1);
g_free(chanevent);
}
g_strfreev(list);
@ -146,11 +146,11 @@ static void handle_client_cmd(CLIENT_REC *client, char *cmd, char *args,
for (p = args; *p != '\0'; p++)
if (*p == ',') *p = ' ';
proxy_redirect_event(client, "whois", args, remote);
proxy_redirect_event(client, "whois", 1, args, remote);
} else if (strcmp(cmd, "ISON") == 0)
proxy_redirect_event(client, "ison", args, -1);
proxy_redirect_event(client, "ison", 1, args, -1);
else if (strcmp(cmd, "USERHOST") == 0)
proxy_redirect_event(client, "userhost", args, -1);
proxy_redirect_event(client, "userhost", 1, args, -1);
else if (strcmp(cmd, "MODE") == 0) {
/* convert dots to spaces */
char *slist, *str, mode, *p;
@ -173,16 +173,16 @@ static void handle_client_cmd(CLIENT_REC *client, char *cmd, char *args,
str = g_strdup_printf("%s %s", args, slist);
switch (mode) {
case '\0':
proxy_redirect_event(client, "mode channel", str, -1);
proxy_redirect_event(client, "mode channel", argc, str, -1);
break;
case 'b':
proxy_redirect_event(client, "mode b", str, -1);
proxy_redirect_event(client, "mode b", argc, str, -1);
break;
case 'e':
proxy_redirect_event(client, "mode e", str, -1);
proxy_redirect_event(client, "mode e", argc, str, -1);
break;
case 'I':
proxy_redirect_event(client, "mode I", str, -1);
proxy_redirect_event(client, "mode I", argc, str, -1);
break;
}
g_free(str);
@ -199,7 +199,7 @@ static void handle_client_cmd(CLIENT_REC *client, char *cmd, char *args,
g_free(params);
} else if (strcmp(cmd, "PING") == 0) {
/* send all PINGs to server. */
proxy_redirect_event(client, "ping", NULL, TRUE);
proxy_redirect_event(client, "ping", 1, NULL, TRUE);
}
irc_send_cmd(client->server, data);

View File

@ -93,15 +93,16 @@ CODE:
register_hash2list(hvref(ST(4))));
void
server_redirect_event(server, command, arg, remote, failure_signal, signals)
server_redirect_event(server, command, count, arg, remote, failure_signal, signals)
Irssi::Irc::Server server
char *command
int count
char *arg
int remote
char *failure_signal
void *signals
CODE:
server_redirect_event_list(server, command, *arg == '\0' ? NULL : arg, remote,
server_redirect_event_list(server, command, count, *arg == '\0' ? NULL : arg, remote,
*failure_signal == '\0' ? NULL : failure_signal,
event_hash2list(hvref(ST(5))));