Beispiel #1
0
static void update_reconnection(SERVER_CONNECT_REC *conn, SERVER_REC *server)
{
	SERVER_CONNECT_REC *oldconn;
	RECONNECT_REC *recon;

	if (server != NULL) {
		oldconn = server->connrec;
                server_connect_ref(oldconn);
                reconnect_save_status(conn, server);
	} else {
		/* maybe we can reconnect some server from
		   reconnection queue */
		recon = find_reconnect_server(conn->chat_type,
					      conn->address, conn->port);
		if (recon == NULL) return;

		oldconn = recon->conn;
                server_connect_ref(oldconn);
		server_reconnect_destroy(recon);

		conn->away_reason = g_strdup(oldconn->away_reason);
		conn->channels = g_strdup(oldconn->channels);
	}

	conn->reconnection = TRUE;

	if (conn->chatnet == NULL && oldconn->chatnet != NULL)
		conn->chatnet = g_strdup(oldconn->chatnet);

	server_connect_unref(oldconn);
	if (server != NULL) {
		signal_emit("command disconnect", 2,
			    "* Changing server", server);
	}
}
Beispiel #2
0
static void reconnect_all(void)
{
	GSList *list;
	SERVER_CONNECT_REC *conn;
	RECONNECT_REC *rec;

	/* first move reconnects to another list so if server_connect()
	   fails and goes to reconnection list again, we won't get stuck
	   here forever */
	list = NULL;
	while (reconnects != NULL) {
		rec = reconnects->data;

		list = g_slist_append(list, rec->conn);
                server_connect_ref(rec->conn);
		server_reconnect_destroy(rec);
	}


	while (list != NULL) {
		conn = list->data;

		server_connect(conn);
                server_connect_unref(conn);
                list = g_slist_remove(list, conn);
	}
}
Beispiel #3
0
static SERVER_CONNECT_REC *
create_addr_conn(int chat_type, const char *address, int port,
		 const char *chatnet, const char *password,
		 const char *nick)
{
        CHAT_PROTOCOL_REC *proto;
	SERVER_CONNECT_REC *conn;
	SERVER_SETUP_REC *sserver;
	CHATNET_REC *chatnetrec;

	g_return_val_if_fail(address != NULL, NULL);

	sserver = server_setup_find(address, port, chatnet);
	if (sserver != NULL) {
		if (chat_type < 0)
			chat_type = sserver->chat_type;
		else if (chat_type != sserver->chat_type)
                        sserver = NULL;
	}

	proto = chat_type >= 0 ? chat_protocol_find_id(chat_type) :
                chat_protocol_get_default();

	conn = proto->create_server_connect();
	server_connect_ref(conn);

	conn->chat_type = proto->id;
        if (chatnet != NULL && *chatnet != '\0')
		conn->chatnet = g_strdup(chatnet);

	/* fill in the defaults */
	server_setup_fill(conn, address, port);

	/* fill the rest from chat network settings */
	chatnetrec = chatnet != NULL ? chatnet_find(chatnet) :
		(sserver == NULL || sserver->chatnet == NULL ? NULL :
		 chatnet_find(sserver->chatnet));
	if (chatnetrec != NULL)
		server_setup_fill_chatnet(conn, chatnetrec);

	/* fill the information from setup */
	if (sserver != NULL)
		server_setup_fill_server(conn, sserver);

	/* nick / password given in command line overrides all settings */
	if (password && *password) {
		g_free_not_null(conn->password);
		conn->password = g_strdup(password);
	}
	if (nick && *nick) {
		g_free_not_null(conn->nick);
		conn->nick = g_strdup(nick);
	}

	return conn;
}
Beispiel #4
0
static SERVER_CONNECT_REC *
server_connect_copy_skeleton(SERVER_CONNECT_REC *src, int connect_info)
{
	SERVER_CONNECT_REC *dest;

        dest = NULL;
	signal_emit("server connect copy", 2, &dest, src);
	g_return_val_if_fail(dest != NULL, NULL);

        server_connect_ref(dest);
	dest->type = module_get_uniq_id("SERVER CONNECT", 0);
	dest->reconnection = src->reconnection;
	dest->proxy = g_strdup(src->proxy);
        dest->proxy_port = src->proxy_port;
	dest->proxy_string = g_strdup(src->proxy_string);
	dest->proxy_string_after = g_strdup(src->proxy_string_after);
	dest->proxy_password = g_strdup(src->proxy_password);

	dest->tag = g_strdup(src->tag);

	if (connect_info) {
                dest->family = src->family;
		dest->address = g_strdup(src->address);
		dest->port = src->port;
		dest->password = g_strdup(src->password);
	}

	dest->chatnet = g_strdup(src->chatnet);
	dest->nick = g_strdup(src->nick);
	dest->username = g_strdup(src->username);
	dest->realname = g_strdup(src->realname);

	if (src->own_ip4 != NULL) {
		dest->own_ip4 = g_new(IPADDR, 1);
		memcpy(dest->own_ip4, src->own_ip4, sizeof(IPADDR));
	}
	if (src->own_ip6 != NULL) {
		dest->own_ip6 = g_new(IPADDR, 1);
		memcpy(dest->own_ip6, src->own_ip6, sizeof(IPADDR));
	}

	dest->channels = g_strdup(src->channels);
	dest->away_reason = g_strdup(src->away_reason);
	dest->no_autojoin_channels = src->no_autojoin_channels;
	dest->no_autosendcmd = src->no_autosendcmd;

	dest->use_ssl = src->use_ssl;
	dest->ssl_cert = g_strdup(src->ssl_cert);
	dest->ssl_pkey = g_strdup(src->ssl_pkey);
	dest->ssl_verify = src->ssl_verify;
	dest->ssl_cafile = g_strdup(src->ssl_cafile);
	dest->ssl_capath = g_strdup(src->ssl_capath);
	dest->ssl_ciphers = g_strdup(src->ssl_ciphers);

	return dest;
}
Beispiel #5
0
static void server_reconnect_add(SERVER_CONNECT_REC *conn,
				 time_t next_connect)
{
	RECONNECT_REC *rec;

	g_return_if_fail(IS_SERVER_CONNECT(conn));

	rec = g_new(RECONNECT_REC, 1);
	rec->tag = ++last_reconnect_tag;
	rec->next_connect = next_connect;

	rec->conn = conn;
	server_connect_ref(conn);

	reconnects = g_slist_append(reconnects, rec);
}
Beispiel #6
0
static int server_reconnect_timeout(void)
{
	SERVER_CONNECT_REC *conn;
	GSList *list, *tmp, *next;
	time_t now;

	now = time(NULL);

	/* timeout any connections that haven't gotten to connected-stage */
	for (tmp = servers; tmp != NULL; tmp = next) {
		SERVER_REC *server = tmp->data;

		next = tmp->next;
		if (!server->connected &&
		    server->connect_time + connect_timeout < now &&
		    connect_timeout > 0) {
			server->connection_lost = TRUE;
			server_disconnect(server);
		}
	}

	/* If server_connect() removes the next reconnection in queue,
	   we're screwed. I don't think this should happen anymore, but just
	   to be sure we don't crash, do this safely. */
	list = g_slist_copy(reconnects);
	for (tmp = list; tmp != NULL; tmp = tmp->next) {
		RECONNECT_REC *rec = tmp->data;

		if (g_slist_find(reconnects, rec) == NULL)
			continue;

		if (rec->next_connect <= now) {
			conn = rec->conn;
			server_connect_ref(conn);
			server_reconnect_destroy(rec);
			server_connect(conn);
			server_connect_unref(conn);
		}
	}

	g_slist_free(list);
	return 1;
}
Beispiel #7
0
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);
	if (conn->address == NULL || *conn->address == '\0') return NULL;
	if (conn->nick == NULL || *conn->nick == '\0') return NULL;

	server = g_new0(IRC_SERVER_REC, 1);
	server->chat_type = IRC_PROTOCOL;

	ircconn = (IRC_SERVER_CONNECT_REC *) conn;
	server->connrec = ircconn;
        server_connect_ref(conn);

	if (server->connrec->port <= 0) {
		server->connrec->port =
			server->connrec->use_ssl ? 6697 : 6667;
	}

	server->cmd_queue_speed = ircconn->cmd_queue_speed > 0 ?
		ircconn->cmd_queue_speed : settings_get_time("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 = 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;
	server->connrec->use_ssl = conn->use_ssl;

	modes_server_init(server);

        server_connect_init((SERVER_REC *) server);
	return (SERVER_REC *) server;
}
Beispiel #8
0
/* SYNTAX: RECONNECT <tag> [<quit message>] */
static void cmd_reconnect(const char *data, SERVER_REC *server)
{
	SERVER_CONNECT_REC *conn;
	RECONNECT_REC *rec;
	char *tag, *msg;
	void *free_arg;
	int tagnum;

	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) {
		/* reconnect connected server */
		conn = server_connect_copy_skeleton(server->connrec, TRUE);

		if (server->connected)
			reconnect_save_status(conn, server);

		msg = g_strconcat("* ", *msg == '\0' ?
				  "Reconnecting" : msg, NULL);
		signal_emit("command disconnect", 2, msg, server);
		g_free(msg);

		conn->reconnection = TRUE;
		server_connect(conn);
		server_connect_unref(conn);
		cmd_params_free(free_arg);
                return;
	}

	if (g_ascii_strcasecmp(tag, "all") == 0) {
		/* reconnect all servers in reconnect queue */
                reconnect_all();
		cmd_params_free(free_arg);
                return;
	}

	if (*data == '\0') {
		/* reconnect to first server in reconnection list */
		if (reconnects == NULL)
			cmd_param_error(CMDERR_NOT_CONNECTED);
                rec = reconnects->data;
	} else {
		if (g_ascii_strncasecmp(data, "RECON-", 6) == 0)
			data += 6;

		tagnum = atoi(tag);
		rec = tagnum <= 0 ? NULL : reconnect_find_tag(tagnum);
	}

	if (rec == NULL) {
		signal_emit("server reconnect not found", 1, data);
	} else {
		conn = rec->conn;
		server_connect_ref(conn);
		server_reconnect_destroy(rec);
		server_connect(conn);
		server_connect_unref(conn);
	}

	cmd_params_free(free_arg);
}
Beispiel #9
0
SERVER_REC *
xmpp_server_init_connect(SERVER_CONNECT_REC *connrec)
{
	XMPP_SERVER_REC *server;
	XMPP_SERVER_CONNECT_REC *conn = (XMPP_SERVER_CONNECT_REC *)connrec;
	char *recoded;

	if (conn->address == NULL || conn->address[0] == '\0')
		return NULL;
	if (conn->nick == NULL || conn->nick[0] == '\0')
		return NULL;
	g_return_val_if_fail(IS_XMPP_SERVER_CONNECT(conn), NULL);

	server = g_new0(XMPP_SERVER_REC, 1);
	server->chat_type = XMPP_PROTOCOL;
	server->user = xmpp_extract_user(conn->nick);
	server->domain = xmpp_have_domain(conn->nick) ?
	    xmpp_extract_domain(conn->nick) : g_strdup(conn->address);
	server->jid = xmpp_have_domain(conn->nick) ?
	    xmpp_strip_resource(conn->nick)
	    : g_strconcat(server->user, "@", server->domain, (void *)NULL);
	server->resource = xmpp_extract_resource(conn->nick);
	if (server->resource == NULL)
		server->resource = g_strdup("irssi-xmpp");
	server->priority = settings_get_int("xmpp_priority");
	if (xmpp_priority_out_of_bound(server->priority))
		server->priority = 0;
	server->ping_id = NULL;
	server->server_features = NULL;
	server->my_resources = NULL;
	server->roster = NULL;
	server->msg_handlers = NULL;
	server->channels_join = channels_join;
	server->isnickflag = isnickflag_func;
	server->ischannel = ischannel_func;
	server->get_nick_flags = get_nick_flags;
	server->send_message = send_message;
	server->connrec = (XMPP_SERVER_CONNECT_REC *)conn;
	server_connect_ref(connrec);

	/* don't use irssi's sockets */
	server->connrec->no_connect = TRUE;
	server->connect_pid = -1;

	if (server->connrec->port <= 0)
		server->connrec->port = (server->connrec->use_ssl) ?
		    LM_CONNECTION_DEFAULT_PORT_SSL : LM_CONNECTION_DEFAULT_PORT;

	if (conn->real_jid == NULL)
		conn->real_jid = conn->nick;
	else
		g_free(conn->nick);
	conn->nick = g_strdup(settings_get_bool("xmpp_set_nick_as_username") ?
	    server->user : server->jid);

	/* init loudmouth connection structure */
	server->lmconn = lm_connection_new(NULL);
	lm_connection_set_server(server->lmconn, server->connrec->address);
	lm_connection_set_port(server->lmconn, server->connrec->port);
	recoded = xmpp_recode_out(server->jid);
	lm_connection_set_jid(server->lmconn, recoded);
	g_free(recoded);
	lm_connection_set_keep_alive_rate(server->lmconn, 30);

	server->timeout_tag = 0;
	server_connect_init((SERVER_REC *)server);
	server->connect_tag = 1;
	return (SERVER_REC *)server;
}