From 4aa0b9111eb659954a19265d2c304e4fad93cb86 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 20 May 2002 04:12:12 +0000 Subject: [PATCH] /UPGRADE was broken, changed again the server connection code. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2821 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/core/chat-commands.c | 4 +-- src/core/chat-protocols.h | 3 ++- src/core/server-connect-rec.h | 1 - src/core/servers-reconnect.c | 8 +++--- src/core/servers.c | 20 +++++++++------ src/core/servers.h | 2 ++ src/core/session.c | 6 +++-- src/irc/core/irc-core.c | 4 +-- src/irc/core/irc-servers.c | 48 ++++++++++++++++++++--------------- src/irc/core/irc-servers.h | 3 ++- src/perl/irc/Server.xs | 6 ----- 11 files changed, 57 insertions(+), 48 deletions(-) diff --git a/src/core/chat-commands.c b/src/core/chat-commands.c index debe6655..cc44a213 100644 --- a/src/core/chat-commands.c +++ b/src/core/chat-commands.c @@ -118,7 +118,7 @@ static void cmd_connect(const char *data) conn = get_server_connect(data, NULL, &rawlog_file); if (conn != NULL) { - server = CHAT_PROTOCOL(conn)->server_connect(conn); + server = server_connect(conn); server_connect_unref(conn); if (server != NULL && rawlog_file != NULL) @@ -224,7 +224,7 @@ static void cmd_server_connect(const char *data, SERVER_REC *server) if (conn != NULL) { if (!plus_addr) update_reconnection(conn, server); - server = CHAT_PROTOCOL(conn)->server_connect(conn); + server = server_connect(conn); server_connect_unref(conn); if (server != NULL && rawlog_file != NULL) diff --git a/src/core/chat-protocols.h b/src/core/chat-protocols.h index 95ab0937..8b7dc170 100644 --- a/src/core/chat-protocols.h +++ b/src/core/chat-protocols.h @@ -17,7 +17,8 @@ struct _CHAT_PROTOCOL_REC { SERVER_CONNECT_REC *(*create_server_connect) (void); void (*destroy_server_connect) (SERVER_CONNECT_REC *); - SERVER_REC *(*server_connect) (SERVER_CONNECT_REC *); + SERVER_REC *(*server_init_connect) (SERVER_CONNECT_REC *); + void (*server_connect) (SERVER_REC *); CHANNEL_REC *(*channel_create) (SERVER_REC *, const char *, const char *, int); QUERY_REC *(*query_create) (const char *, const char *, int); diff --git a/src/core/server-connect-rec.h b/src/core/server-connect-rec.h index cc5afa57..3613759e 100644 --- a/src/core/server-connect-rec.h +++ b/src/core/server-connect-rec.h @@ -29,6 +29,5 @@ GIOChannel *connect_handle; /* connect using this handle */ unsigned int reconnection:1; /* we're trying to reconnect */ unsigned int no_autojoin_channels:1; /* don't autojoin any channels */ unsigned int unix_socket:1; /* Connect using named unix socket */ -unsigned int session_reconnect:1; /* Connected to this server with /UPGRADE */ char *channels; char *away_reason; diff --git a/src/core/servers-reconnect.c b/src/core/servers-reconnect.c index 1b17c921..93067b2b 100644 --- a/src/core/servers-reconnect.c +++ b/src/core/servers-reconnect.c @@ -99,7 +99,7 @@ static int server_reconnect_timeout(void) conn = rec->conn; server_connect_ref(conn); server_reconnect_destroy(rec); - CHAT_PROTOCOL(conn)->server_connect(conn); + server_connect(conn); server_connect_unref(conn); } } @@ -329,7 +329,7 @@ static void reconnect_all(void) while (list != NULL) { conn = list->data; - CHAT_PROTOCOL(conn)->server_connect(conn); + server_connect(conn); server_connect_unref(conn); list = g_slist_remove(list, conn); } @@ -351,7 +351,7 @@ static void cmd_reconnect(const char *data, SERVER_REC *server) signal_emit("command disconnect", 2, "* Reconnecting", server); conn->reconnection = TRUE; - CHAT_PROTOCOL(conn)->server_connect(conn); + server_connect(conn); server_connect_unref(conn); return; } @@ -383,7 +383,7 @@ static void cmd_reconnect(const char *data, SERVER_REC *server) conn = rec->conn; server_connect_ref(conn); server_reconnect_destroy(rec); - CHAT_PROTOCOL(conn)->server_connect(conn); + server_connect(conn); server_connect_unref(conn); } diff --git a/src/core/servers.c b/src/core/servers.c index e16d323c..4828750b 100644 --- a/src/core/servers.c +++ b/src/core/servers.c @@ -264,6 +264,18 @@ static void server_connect_callback_readpipe(SERVER_REC *server) g_free(iprec.errorstr); } +SERVER_REC *server_connect(SERVER_CONNECT_REC *conn) +{ + CHAT_PROTOCOL_REC *proto; + SERVER_REC *server; + + proto = CHAT_PROTOCOL(conn); + server = proto->server_init_connect(conn); + proto->server_connect(server); + + return server; +} + /* initializes server record but doesn't start connecting */ void server_connect_init(SERVER_REC *server) { @@ -305,16 +317,8 @@ int server_start_connect(SERVER_REC *server) if (!server->connrec->unix_socket && server->connrec->port <= 0) return FALSE; - server_connect_init(server); server->rawlog = rawlog_create(); - if (server->connrec->session_reconnect) { - /* /UPGRADE connection - the session_connect is meant - for us only once, move it into server->session_connect */ - server->connrec->session_reconnect = FALSE; - server->session_reconnect = TRUE; - } - if (server->connrec->connect_handle != NULL) { /* already connected */ GIOChannel *handle = server->connrec->connect_handle; diff --git a/src/core/servers.h b/src/core/servers.h index dddde263..3c2c8634 100644 --- a/src/core/servers.h +++ b/src/core/servers.h @@ -53,6 +53,8 @@ int server_start_connect(SERVER_REC *server); void server_connect_ref(SERVER_CONNECT_REC *conn); void server_connect_unref(SERVER_CONNECT_REC *conn); +SERVER_REC *server_connect(SERVER_CONNECT_REC *conn); + /* initializes server record but doesn't start connecting */ void server_connect_init(SERVER_REC *server); /* Connection to server finished, fill the rest of the fields */ diff --git a/src/core/session.c b/src/core/session.c index 94bedfb6..0f3d089c 100644 --- a/src/core/session.c +++ b/src/core/session.c @@ -277,10 +277,12 @@ static void session_restore_server(CONFIG_NODE *node) if (conn != NULL) { conn->reconnection = TRUE; conn->connect_handle = g_io_channel_unix_new(handle); - conn->session_reconnect = TRUE; - server = proto->server_connect(conn); + server = proto->server_init_connect(conn); + server->session_reconnect = TRUE; signal_emit("session restore server", 2, server, node); + + proto->server_connect(server); } } diff --git a/src/irc/core/irc-core.c b/src/irc/core/irc-core.c index 9d441f09..5386f372 100644 --- a/src/irc/core/irc-core.c +++ b/src/irc/core/irc-core.c @@ -91,8 +91,8 @@ void irc_core_init(void) rec->create_server_connect = create_server_connect; rec->destroy_server_connect = destroy_server_connect; - rec->server_connect = (SERVER_REC *(*) (SERVER_CONNECT_REC *)) - irc_server_connect; + rec->server_init_connect = irc_server_init_connect; + rec->server_connect = irc_server_connect; rec->channel_create = (CHANNEL_REC *(*) (SERVER_REC *, const char *, const char *, int)) diff --git a/src/irc/core/irc-servers.c b/src/irc/core/irc-servers.c index e294f9fc..5e5dba55 100644 --- a/src/irc/core/irc-servers.c +++ b/src/irc/core/irc-servers.c @@ -150,8 +150,9 @@ static void server_init(IRC_SERVER_REC *server) server->cmdcount = 0; } -IRC_SERVER_REC *irc_server_connect(IRC_SERVER_CONNECT_REC *conn) +SERVER_REC *irc_server_init_connect(SERVER_CONNECT_REC *conn) { + IRC_SERVER_CONNECT_REC *ircconn; IRC_SERVER_REC *server; g_return_val_if_fail(IS_IRC_SERVER_CONNECT(conn), NULL); @@ -161,34 +162,39 @@ IRC_SERVER_REC *irc_server_connect(IRC_SERVER_CONNECT_REC *conn) server = g_new0(IRC_SERVER_REC, 1); server->chat_type = IRC_PROTOCOL; - server->connrec = conn; - server_connect_ref(SERVER_CONNECT(conn)); + ircconn = (IRC_SERVER_CONNECT_REC *) conn; + server->connrec = ircconn; + server_connect_ref(conn); if (server->connrec->port <= 0) server->connrec->port = 6667; - server->cmd_queue_speed = conn->cmd_queue_speed > 0 ? - conn->cmd_queue_speed : settings_get_int("cmd_queue_speed"); - server->max_cmds_at_once = conn->max_cmds_at_once > 0 ? - conn->max_cmds_at_once : settings_get_int("cmds_max_at_once"); - server->max_query_chans = conn->max_query_chans > 0 ? - conn->max_query_chans : DEFAULT_MAX_QUERY_CHANS; + server->cmd_queue_speed = ircconn->cmd_queue_speed > 0 ? + ircconn->cmd_queue_speed : settings_get_int("cmd_queue_speed"); + server->max_cmds_at_once = ircconn->max_cmds_at_once > 0 ? + ircconn->max_cmds_at_once : settings_get_int("cmds_max_at_once"); + server->max_query_chans = ircconn->max_query_chans > 0 ? + ircconn->max_query_chans : DEFAULT_MAX_QUERY_CHANS; - server->max_kicks_in_cmd = conn->max_kicks > 0 ? - conn->max_kicks : DEFAULT_MAX_KICKS; - server->max_modes_in_cmd = conn->max_modes > 0 ? - conn->max_modes : DEFAULT_MAX_MODES; - server->max_whois_in_cmd = conn->max_whois > 0 ? - conn->max_whois : DEFAULT_MAX_WHOIS; - server->max_msgs_in_cmd = conn->max_msgs > 0 ? - conn->max_msgs : DEFAULT_MAX_MSGS; + server->max_kicks_in_cmd = ircconn->max_kicks > 0 ? + ircconn->max_kicks : DEFAULT_MAX_KICKS; + server->max_modes_in_cmd = ircconn->max_modes > 0 ? + ircconn->max_modes : DEFAULT_MAX_MODES; + server->max_whois_in_cmd = ircconn->max_whois > 0 ? + ircconn->max_whois : DEFAULT_MAX_WHOIS; + server->max_msgs_in_cmd = ircconn->max_msgs > 0 ? + ircconn->max_msgs : DEFAULT_MAX_MSGS; - if (!server_start_connect((SERVER_REC *) server)) { - server_connect_unref(SERVER_CONNECT(conn)); + server_connect_init((SERVER_REC *) server); + return (SERVER_REC *) server; +} + +void irc_server_connect(SERVER_REC *server) +{ + if (!server_start_connect(server)) { + server_connect_unref(server->connrec); g_free(server); - return NULL; } - return server; } /* Returns TRUE if `command' is sent to `target' */ diff --git a/src/irc/core/irc-servers.h b/src/irc/core/irc-servers.h index f6ee1821..ce6da564 100644 --- a/src/irc/core/irc-servers.h +++ b/src/irc/core/irc-servers.h @@ -97,7 +97,8 @@ struct _IRC_SERVER_REC { void *chanqueries; }; -IRC_SERVER_REC *irc_server_connect(IRC_SERVER_CONNECT_REC *conn); +SERVER_REC *irc_server_init_connect(SERVER_CONNECT_REC *conn); +void irc_server_connect(SERVER_REC *server); /* Purge server output, either all or for specified target */ void irc_server_purge_output(IRC_SERVER_REC *server, const char *target); diff --git a/src/perl/irc/Server.xs b/src/perl/irc/Server.xs index 85b13f80..bcab6f49 100644 --- a/src/perl/irc/Server.xs +++ b/src/perl/irc/Server.xs @@ -129,9 +129,3 @@ CODE: RETVAL = (char *) server_redirect_peek_signal(server, event, args, &redirection); OUTPUT: RETVAL - -MODULE = Irssi::Irc::Server PACKAGE = Irssi::Irc::Connect PREFIX = irc_server_ - -Irssi::Irc::Server -irc_server_connect(conn) - Irssi::Irc::Connect conn