mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Moved /DISCONNECT to core, other multiprotocol fixes.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@687 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
ec8c613101
commit
e256b3a108
@ -153,6 +153,7 @@ static void sig_reconnect(SERVER_REC *server)
|
||||
return;
|
||||
|
||||
conn = server_connect_copy_skeleton(server->connrec);
|
||||
g_return_if_fail(conn != NULL);
|
||||
|
||||
/* save the server status */
|
||||
if (server->connected) {
|
||||
|
@ -38,7 +38,7 @@
|
||||
GSList *servers, *lookup_servers;
|
||||
|
||||
/* connection to server failed */
|
||||
static void server_cant_connect(SERVER_REC *server, const char *msg)
|
||||
void server_connect_failed(SERVER_REC *server, const char *msg)
|
||||
{
|
||||
g_return_if_fail(IS_SERVER(server));
|
||||
|
||||
@ -114,23 +114,9 @@ static char *server_create_tag(SERVER_CONNECT_REC *conn)
|
||||
return tag;
|
||||
}
|
||||
|
||||
static void server_connect_callback_init(SERVER_REC *server, int handle)
|
||||
/* Connection to server finished, fill the rest of the fields */
|
||||
void server_connect_finished(SERVER_REC *server)
|
||||
{
|
||||
int error;
|
||||
|
||||
g_return_if_fail(IS_SERVER(server));
|
||||
|
||||
error = net_geterror(handle);
|
||||
if (error != 0) {
|
||||
server->connection_lost = TRUE;
|
||||
server_cant_connect(server, g_strerror(error));
|
||||
return;
|
||||
}
|
||||
|
||||
lookup_servers = g_slist_remove(lookup_servers, server);
|
||||
|
||||
g_source_remove(server->connect_tag);
|
||||
server->connect_tag = -1;
|
||||
server->connect_time = time(NULL);
|
||||
server->rawlog = rawlog_create();
|
||||
|
||||
@ -142,6 +128,26 @@ static void server_connect_callback_init(SERVER_REC *server, int handle)
|
||||
signal_emit("server connected", 1, server);
|
||||
}
|
||||
|
||||
static void server_connect_callback_init(SERVER_REC *server, int handle)
|
||||
{
|
||||
int error;
|
||||
|
||||
g_return_if_fail(IS_SERVER(server));
|
||||
|
||||
error = net_geterror(handle);
|
||||
if (error != 0) {
|
||||
server->connection_lost = TRUE;
|
||||
server_connect_failed(server, g_strerror(error));
|
||||
return;
|
||||
}
|
||||
|
||||
lookup_servers = g_slist_remove(lookup_servers, server);
|
||||
g_source_remove(server->connect_tag);
|
||||
server->connect_tag = -1;
|
||||
|
||||
server_connect_finished(server);
|
||||
}
|
||||
|
||||
static void server_connect_callback_readpipe(SERVER_REC *server)
|
||||
{
|
||||
SERVER_CONNECT_REC *conn;
|
||||
@ -186,7 +192,7 @@ static void server_connect_callback_readpipe(SERVER_REC *server)
|
||||
errormsg = iprec.errorstr != NULL ? iprec.errorstr :
|
||||
"Host lookup failed";
|
||||
}
|
||||
server_cant_connect(server, errormsg);
|
||||
server_connect_failed(server, errormsg);
|
||||
g_free_not_null(iprec.errorstr);
|
||||
return;
|
||||
}
|
||||
@ -199,12 +205,10 @@ static void server_connect_callback_readpipe(SERVER_REC *server)
|
||||
signal_emit("server connecting", 2, server, &iprec.ip);
|
||||
}
|
||||
|
||||
int server_start_connect(SERVER_REC *server)
|
||||
/* initializes server record but doesn't start connecting */
|
||||
void server_connect_init(SERVER_REC *server)
|
||||
{
|
||||
const char *connect_address;
|
||||
|
||||
g_return_val_if_fail(server != NULL, FALSE);
|
||||
if (server->connrec->port <= 0) return FALSE;
|
||||
g_return_if_fail(server != NULL);
|
||||
|
||||
MODULE_DATA_INIT(server);
|
||||
server->type = module_get_uniq_id("SERVER", 0);
|
||||
@ -225,13 +229,25 @@ int server_start_connect(SERVER_REC *server)
|
||||
server->connrec->realname = g_strdup(server->connrec->realname);
|
||||
}
|
||||
|
||||
server->tag = server_create_tag(server->connrec);
|
||||
}
|
||||
|
||||
/* starts connecting to server */
|
||||
int server_start_connect(SERVER_REC *server)
|
||||
{
|
||||
const char *connect_address;
|
||||
|
||||
g_return_val_if_fail(server != NULL, FALSE);
|
||||
if (server->connrec->port <= 0) return FALSE;
|
||||
|
||||
server_connect_init(server);
|
||||
|
||||
if (pipe(server->connect_pipe) != 0) {
|
||||
g_warning("server_connect(): pipe() failed.");
|
||||
g_free(server->tag);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
server->tag = server_create_tag(server->connrec);
|
||||
|
||||
connect_address = server->connrec->proxy != NULL ?
|
||||
server->connrec->proxy : server->connrec->address;
|
||||
server->connect_pid =
|
||||
@ -295,7 +311,7 @@ void server_disconnect(SERVER_REC *server)
|
||||
/* still connecting to server.. */
|
||||
if (server->connect_pid != -1)
|
||||
net_disconnect_nonblock(server->connect_pid);
|
||||
server_cant_connect(server, NULL);
|
||||
server_connect_failed(server, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -437,6 +453,52 @@ SERVER_REC *cmd_options_get_server(const char *cmd,
|
||||
return server;
|
||||
}
|
||||
|
||||
/* SYNTAX: DISCONNECT *|<tag> [<message>] */
|
||||
static void cmd_disconnect(const char *data, SERVER_REC *server)
|
||||
{
|
||||
char *tag, *msg;
|
||||
void *free_arg;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &tag, &msg))
|
||||
return;
|
||||
|
||||
if (*tag != '\0' && strcmp(tag, "*") != 0)
|
||||
server = server_find_tag(tag);
|
||||
if (server == NULL) cmd_param_error(CMDERR_NOT_CONNECTED);
|
||||
|
||||
if (*msg == '\0') msg = (char *) settings_get_str("quit_message");
|
||||
signal_emit("server quit", 2, server, msg);
|
||||
|
||||
cmd_params_free(free_arg);
|
||||
server_disconnect(server);
|
||||
}
|
||||
|
||||
/* SYNTAX: QUIT [<message>] */
|
||||
static void cmd_quit(const char *data)
|
||||
{
|
||||
GSList *tmp, *next;
|
||||
const char *quitmsg;
|
||||
char *str;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
|
||||
quitmsg = *data != '\0' ? data :
|
||||
settings_get_str("quit_message");
|
||||
|
||||
/* disconnect from every server */
|
||||
for (tmp = servers; tmp != NULL; tmp = next) {
|
||||
next = tmp->next;
|
||||
|
||||
str = g_strdup_printf("* %s", quitmsg);
|
||||
cmd_disconnect(str, tmp->data);
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
signal_emit("gui exit", 0);
|
||||
}
|
||||
|
||||
void servers_init(void)
|
||||
{
|
||||
lookup_servers = servers = NULL;
|
||||
@ -444,14 +506,20 @@ void servers_init(void)
|
||||
servers_reconnect_init();
|
||||
servers_redirect_init();
|
||||
servers_setup_init();
|
||||
|
||||
command_bind("disconnect", NULL, (SIGNAL_FUNC) cmd_disconnect);
|
||||
command_bind("quit", NULL, (SIGNAL_FUNC) cmd_quit);
|
||||
}
|
||||
|
||||
void servers_deinit(void)
|
||||
{
|
||||
command_unbind("disconnect", (SIGNAL_FUNC) cmd_disconnect);
|
||||
command_unbind("quit", (SIGNAL_FUNC) cmd_quit);
|
||||
|
||||
while (servers != NULL)
|
||||
server_disconnect(servers->data);
|
||||
while (lookup_servers != NULL)
|
||||
server_cant_connect(lookup_servers->data, NULL);
|
||||
server_connect_failed(lookup_servers->data, NULL);
|
||||
|
||||
servers_setup_deinit();
|
||||
servers_redirect_deinit();
|
||||
|
@ -45,9 +45,17 @@ void server_disconnect(SERVER_REC *server);
|
||||
SERVER_REC *server_find_tag(const char *tag);
|
||||
SERVER_REC *server_find_chatnet(const char *chatnet);
|
||||
|
||||
/* starts connecting to server */
|
||||
int server_start_connect(SERVER_REC *server);
|
||||
void server_connect_free(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 */
|
||||
void server_connect_finished(SERVER_REC *server);
|
||||
/* connection to server failed */
|
||||
void server_connect_failed(SERVER_REC *server, const char *msg);
|
||||
|
||||
/* `optlist' should contain only one key - the server tag.
|
||||
returns NULL if there was unknown -option */
|
||||
SERVER_REC *cmd_options_get_server(const char *cmd,
|
||||
|
@ -102,39 +102,10 @@ static void cmd_connect(const char *data)
|
||||
irc_connect_server(data);
|
||||
}
|
||||
|
||||
|
||||
/* SYNTAX: DISCONNECT *|<tag> [<message>] */
|
||||
static void cmd_disconnect(const char *data, IRC_SERVER_REC *server)
|
||||
{
|
||||
char *tag, *msg, *str;
|
||||
void *free_arg;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &tag, &msg))
|
||||
return;
|
||||
|
||||
if (*tag != '\0' && strcmp(tag, "*") != 0)
|
||||
server = (IRC_SERVER_REC *) server_find_tag(tag);
|
||||
if (server == NULL || !IS_IRC_SERVER(server))
|
||||
cmd_param_error(CMDERR_NOT_CONNECTED);
|
||||
|
||||
if (*msg == '\0') msg = (char *) settings_get_str("quit_message");
|
||||
signal_emit("server quit", 2, server, msg);
|
||||
|
||||
if (server->handle != NULL && server->buffer != NULL) {
|
||||
str = g_strdup_printf("QUIT :%s", msg);
|
||||
irc_send_cmd_now(server, str);
|
||||
g_free(str);
|
||||
}
|
||||
cmd_params_free(free_arg);
|
||||
|
||||
server_disconnect((SERVER_REC *) server);
|
||||
}
|
||||
|
||||
/* SYNTAX: SERVER [-ircnet <ircnet>] [-host <hostname>]
|
||||
[+]<address>|<ircnet> [<port> [<password> [<nick>]]] */
|
||||
static void cmd_server(const char *data, IRC_SERVER_REC *server)
|
||||
static void cmd_server(const char *data, IRC_SERVER_REC *server,
|
||||
void *item)
|
||||
{
|
||||
GHashTable *optlist;
|
||||
char *addr, *channels, *away_reason, *usermode, *ircnet;
|
||||
@ -161,7 +132,8 @@ static void cmd_server(const char *data, IRC_SERVER_REC *server)
|
||||
usermode = g_strdup(server->usermode);
|
||||
away_reason = !server->usermode_away ? NULL :
|
||||
g_strdup(server->away_reason);
|
||||
cmd_disconnect("* Changing server", server);
|
||||
signal_emit("command disconnect", 3,
|
||||
"* Changing server", server, item);
|
||||
}
|
||||
|
||||
server = IRC_SERVER(irc_connect_server(data));
|
||||
@ -181,30 +153,6 @@ static void cmd_server(const char *data, IRC_SERVER_REC *server)
|
||||
cmd_params_free(free_arg);
|
||||
}
|
||||
|
||||
/* SYNTAX: QUIT [<message>] */
|
||||
static void cmd_quit(const char *data)
|
||||
{
|
||||
GSList *tmp, *next;
|
||||
const char *quitmsg;
|
||||
char *str;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
|
||||
quitmsg = *data != '\0' ? data :
|
||||
settings_get_str("quit_message");
|
||||
|
||||
/* disconnect from every server */
|
||||
for (tmp = servers; tmp != NULL; tmp = next) {
|
||||
next = tmp->next;
|
||||
|
||||
str = g_strdup_printf("* %s", quitmsg);
|
||||
cmd_disconnect(str, tmp->data);
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
signal_emit("gui exit", 0);
|
||||
}
|
||||
|
||||
/* SYNTAX: MSG [-<server tag>] <targets> <message> */
|
||||
static void cmd_msg(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
|
||||
{
|
||||
@ -995,12 +943,10 @@ void irc_commands_init(void)
|
||||
signal_add("server connected", (SIGNAL_FUNC) sig_connected);
|
||||
command_bind("server", NULL, (SIGNAL_FUNC) cmd_server);
|
||||
command_bind("connect", NULL, (SIGNAL_FUNC) cmd_connect);
|
||||
command_bind("disconnect", NULL, (SIGNAL_FUNC) cmd_disconnect);
|
||||
command_bind("msg", NULL, (SIGNAL_FUNC) cmd_msg);
|
||||
command_bind("notice", NULL, (SIGNAL_FUNC) cmd_notice);
|
||||
command_bind("ctcp", NULL, (SIGNAL_FUNC) cmd_ctcp);
|
||||
command_bind("nctcp", NULL, (SIGNAL_FUNC) cmd_nctcp);
|
||||
command_bind("quit", NULL, (SIGNAL_FUNC) cmd_quit);
|
||||
command_bind("join", NULL, (SIGNAL_FUNC) cmd_join);
|
||||
command_bind("part", NULL, (SIGNAL_FUNC) cmd_part);
|
||||
command_bind("kick", NULL, (SIGNAL_FUNC) cmd_kick);
|
||||
@ -1097,12 +1043,10 @@ void irc_commands_deinit(void)
|
||||
signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
|
||||
command_unbind("server", (SIGNAL_FUNC) cmd_server);
|
||||
command_unbind("connect", (SIGNAL_FUNC) cmd_connect);
|
||||
command_unbind("disconnect", (SIGNAL_FUNC) cmd_disconnect);
|
||||
command_unbind("msg", (SIGNAL_FUNC) cmd_msg);
|
||||
command_unbind("notice", (SIGNAL_FUNC) cmd_notice);
|
||||
command_unbind("ctcp", (SIGNAL_FUNC) cmd_ctcp);
|
||||
command_unbind("nctcp", (SIGNAL_FUNC) cmd_nctcp);
|
||||
command_unbind("quit", (SIGNAL_FUNC) cmd_quit);
|
||||
command_unbind("join", (SIGNAL_FUNC) cmd_join);
|
||||
command_unbind("part", (SIGNAL_FUNC) cmd_part);
|
||||
command_unbind("kick", (SIGNAL_FUNC) cmd_kick);
|
||||
|
@ -172,6 +172,19 @@ static void sig_disconnected(IRC_SERVER_REC *server)
|
||||
g_free_not_null(server->last_invite);
|
||||
}
|
||||
|
||||
static void sig_server_quit(IRC_SERVER_REC *server, const char *msg)
|
||||
{
|
||||
char *str;
|
||||
|
||||
if (!IS_IRC_SERVER(server) || server->handle == NULL ||
|
||||
server->buffer == NULL)
|
||||
return;
|
||||
|
||||
str = g_strdup_printf("QUIT :%s", msg);
|
||||
irc_send_cmd_now(server, str);
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
static void server_cmd_timeout(IRC_SERVER_REC *server, GTimeVal *now)
|
||||
{
|
||||
long usecs;
|
||||
@ -387,6 +400,7 @@ void irc_servers_init(void)
|
||||
signal_add("server connect", (SIGNAL_FUNC) sig_server_connect);
|
||||
signal_add_first("server connected", (SIGNAL_FUNC) sig_connected);
|
||||
signal_add_last("server disconnected", (SIGNAL_FUNC) sig_disconnected);
|
||||
signal_add_last("server quit", (SIGNAL_FUNC) sig_server_quit);
|
||||
signal_add("event 001", (SIGNAL_FUNC) event_connected);
|
||||
signal_add("event 004", (SIGNAL_FUNC) event_server_info);
|
||||
signal_add("event 465", (SIGNAL_FUNC) event_server_banned);
|
||||
@ -412,6 +426,7 @@ void irc_servers_deinit(void)
|
||||
signal_remove("server connect", (SIGNAL_FUNC) sig_server_connect);
|
||||
signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
|
||||
signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected);
|
||||
signal_remove("server quit", (SIGNAL_FUNC) sig_server_quit);
|
||||
signal_remove("event 001", (SIGNAL_FUNC) event_connected);
|
||||
signal_remove("event 004", (SIGNAL_FUNC) event_server_info);
|
||||
signal_remove("event 465", (SIGNAL_FUNC) event_server_banned);
|
||||
|
@ -348,6 +348,9 @@ static void irc_init_server(IRC_SERVER_REC *server)
|
||||
{
|
||||
g_return_if_fail(server != NULL);
|
||||
|
||||
if (!IS_IRC_SERVER(server))
|
||||
return;
|
||||
|
||||
server->readtag =
|
||||
g_input_add(net_sendbuffer_handle(server->handle),
|
||||
G_INPUT_READ,
|
||||
|
Loading…
Reference in New Issue
Block a user