Exemple #1
0
static void sig_layout_save_item(WINDOW_REC *window, WI_ITEM_REC *item,
				 CONFIG_NODE *node)
{
	CONFIG_NODE *subnode;
        CHAT_PROTOCOL_REC *proto;
	const char *type;

	type = module_find_id_str("WINDOW ITEM TYPE", item->type);
	if (type == NULL)
		return;

	subnode = config_node_section(node, NULL, NODE_TYPE_BLOCK);

	iconfig_node_set_str(subnode, "type", type);
	proto = item->chat_type == 0 ? NULL :
		chat_protocol_find_id(item->chat_type);
	if (proto != NULL)
		iconfig_node_set_str(subnode, "chat_type", proto->name);
	iconfig_node_set_str(subnode, "name", item->visible_name);

	if (item->server != NULL)
		iconfig_node_set_str(subnode, "tag", item->server->tag);
	else if (IS_QUERY(item)) {
		iconfig_node_set_str(subnode, "tag", QUERY(item)->server_tag);
	}
}
Exemple #2
0
static void window_save_items(WINDOW_REC *window, CONFIG_NODE *node)
{
	CONFIG_NODE *subnode;
	GSList *tmp;
	const char *type;

	node = config_node_section(node, "items", NODE_TYPE_LIST);
	for (tmp = window->items; tmp != NULL; tmp = tmp->next) {
		WI_ITEM_REC *rec = tmp->data;
		SERVER_REC *server = rec->server;

		type = module_find_id_str("WINDOW ITEM TYPE", rec->type);
		if (type == NULL) continue;

		subnode = config_node_section(node, NULL, NODE_TYPE_BLOCK);

		iconfig_node_set_str(subnode, "type", type);
		type = chat_protocol_find_id(rec->chat_type)->name;
		iconfig_node_set_str(subnode, "chat_type", type);
		iconfig_node_set_str(subnode, "name", rec->name);

		if (server != NULL)
			iconfig_node_set_str(subnode, "tag", server->tag);
		else if (IS_QUERY(rec)) {
			iconfig_node_set_str(subnode, "tag",
					     QUERY(rec)->server_tag);
		}
	}
}
Exemple #3
0
static void session_save_server(SERVER_REC *server, CONFIG_REC *config,
				CONFIG_NODE *node)
{
	int handle;

	node = config_node_section(node, NULL, NODE_TYPE_BLOCK);

	config_node_set_str(config, node, "chat_type",
			    chat_protocol_find_id(server->chat_type)->name);
	config_node_set_str(config, node, "address", server->connrec->address);
	config_node_set_int(config, node, "port", server->connrec->port);
	config_node_set_str(config, node, "chatnet", server->connrec->chatnet);
	config_node_set_str(config, node, "password", server->connrec->password);
	config_node_set_str(config, node, "nick", server->nick);

	config_node_set_bool(config, node, "use_ssl", server->connrec->use_ssl);

	handle = g_io_channel_unix_get_fd(net_sendbuffer_handle(server->handle));
	config_node_set_int(config, node, "handle", handle);

	signal_emit("session save server", 3, server, config, node);

	/* fake the server disconnection */
	g_io_channel_unref(net_sendbuffer_handle(server->handle));
	net_sendbuffer_destroy(server->handle, FALSE);
	server->handle = NULL;

	server->connection_lost = TRUE;
        server->no_reconnect = TRUE;
        server_disconnect(server);
}
Exemple #4
0
/* SYNTAX: SERVER ADD [-auto | -noauto] [-host <hostname>]
                      [-cmdspeed <ms>] [-cmdmax <count>] [-port <port>]
		      <address> [<port> [<password>]] */
static void cmd_server_add(const char *data)
{
        GHashTable *optlist;
	SERVER_SETUP_REC *rec;
	char *addr, *portstr, *password, *value;
	void *free_arg;
	int port;

	if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS,
			    "server add", &optlist, &addr, &portstr, &password))
		return;

	if (*addr == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
	port = *portstr == '\0' ? 6667 : atoi(portstr);

	rec = server_setup_find_port(addr, port);
	if (rec == NULL) {
		signal_emit("server add create", 2, &rec, optlist);
		if (rec == NULL) {
			/* no chatnet option specified, use the first. */
			g_hash_table_insert(optlist, chat_protocol_find_id(1)->name, "");
			signal_emit("server add create", 2, &rec, optlist);
			if (rec == NULL) {
                                /* bug? */
				cmd_params_free(free_arg);
				return;
			}
		}
		rec->address = g_strdup(addr);
		rec->port = port;
	} else {
		value = g_hash_table_lookup(optlist, "port");
		if (value != NULL && *value != '\0') rec->port = atoi(value);

		if (*password != '\0') g_free_and_null(rec->password);
		if (g_hash_table_lookup(optlist, "host")) {
			g_free_and_null(rec->own_host);
			rec->own_ip = NULL;
		}
	}

	if (g_hash_table_lookup(optlist, "auto")) rec->autoconnect = TRUE;
	if (g_hash_table_lookup(optlist, "noauto")) rec->autoconnect = FALSE;

	if (*password != '\0' && strcmp(password, "-") != 0) rec->password = g_strdup(password);
	value = g_hash_table_lookup(optlist, "host");
	if (value != NULL && *value != '\0') {
		rec->own_host = g_strdup(value);
		rec->own_ip = NULL;
	}

	signal_emit("server add fill", 2, rec, optlist);

	server_setup_add(rec);
	printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_SETUPSERVER_ADDED, addr, port);

	cmd_params_free(free_arg);
}
Exemple #5
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;
}
Exemple #6
0
static void chatnet_config_save(CHATNET_REC *chatnet)
{
	CONFIG_NODE *node;

	node = iconfig_node_traverse("chatnets", TRUE);
	node = config_node_section(node, chatnet->name, NODE_TYPE_BLOCK);
	iconfig_node_clear(node);

	iconfig_node_set_str(node, "type", chat_protocol_find_id(chatnet->chat_type)->name);
	iconfig_node_set_str(node, "nick", chatnet->nick);
	iconfig_node_set_str(node, "username", chatnet->username);
	iconfig_node_set_str(node, "realname", chatnet->realname);
	iconfig_node_set_str(node, "host", chatnet->own_host);
	iconfig_node_set_str(node, "autosendcmd", chatnet->autosendcmd);

        signal_emit("chatnet saved", 2, chatnet, node);
}
Exemple #7
0
static SERVER_CONNECT_REC *get_server_connect(const char *data, int *plus_addr,
					      char **rawlog_file)
{
        CHAT_PROTOCOL_REC *proto;
	SERVER_CONNECT_REC *conn;
	GHashTable *optlist;
	char *addr, *portstr, *password, *nick, *chatnet, *host, *tmp;
	void *free_arg;

	g_return_val_if_fail(data != NULL, NULL);

	if (!cmd_get_params(data, &free_arg, 4 | PARAM_FLAG_OPTIONS,
			    "connect", &optlist, &addr, &portstr,
			    &password, &nick))
		return NULL;
	if (plus_addr != NULL) *plus_addr = *addr == '+';
	if (*addr == '+') addr++;
	if (*addr == '\0') {
		signal_emit("error command", 1,
			    GINT_TO_POINTER(CMDERR_NOT_ENOUGH_PARAMS));
		cmd_params_free(free_arg);
		return NULL;
	}

	if (strcmp(password, "-") == 0)
		*password = '******';

        /* check if -<chatnet> option is used to specify chat protocol */
	proto = chat_protocol_find_net(optlist);

	/* connect to server */
	chatnet = proto == NULL ? NULL :
		g_hash_table_lookup(optlist, proto->chatnet);

	if (chatnet == NULL)
		chatnet = g_hash_table_lookup(optlist, "network");

	conn = server_create_conn(proto != NULL ? proto->id : -1, addr,
				  atoi(portstr), chatnet, password, nick);
	if (proto == NULL)
		proto = chat_protocol_find_id(conn->chat_type);

	if (proto->not_initialized) {
		/* trying to use protocol that isn't yet initialized */
		signal_emit("chat protocol unknown", 1, proto->name);
		server_connect_unref(conn);
                cmd_params_free(free_arg);
		return NULL;
	}

	if (strchr(addr, '/') != NULL)
		conn->unix_socket = TRUE;

	if (g_hash_table_lookup(optlist, "6") != NULL)
		conn->family = AF_INET6;
	else if (g_hash_table_lookup(optlist, "4") != NULL)
		conn->family = AF_INET;

	if (g_hash_table_lookup(optlist, "ssl") != NULL)
		conn->use_ssl = TRUE;
	if ((tmp = g_hash_table_lookup(optlist, "ssl_cert")) != NULL)
		conn->ssl_cert = g_strdup(tmp);
	if ((tmp = g_hash_table_lookup(optlist, "ssl_pkey")) != NULL)
		conn->ssl_pkey = g_strdup(tmp);
	if ((tmp = g_hash_table_lookup(optlist, "ssl_pass")) != NULL)
		conn->ssl_pass = g_strdup(tmp);
	if (g_hash_table_lookup(optlist, "ssl_verify") != NULL)
		conn->ssl_verify = TRUE;
	if ((tmp = g_hash_table_lookup(optlist, "ssl_cafile")) != NULL)
		conn->ssl_cafile = g_strdup(tmp);
	if ((tmp = g_hash_table_lookup(optlist, "ssl_capath")) != NULL)
		conn->ssl_capath = g_strdup(tmp);
	if ((conn->ssl_capath != NULL && conn->ssl_capath[0] != '\0')
	||  (conn->ssl_cafile != NULL && conn->ssl_cafile[0] != '\0'))
		conn->ssl_verify = TRUE;
	if ((conn->ssl_cert != NULL && conn->ssl_cert[0] != '\0') || conn->ssl_verify)
		conn->use_ssl = TRUE;

	if (g_hash_table_lookup(optlist, "!") != NULL)
		conn->no_autojoin_channels = TRUE;

    if (g_hash_table_lookup(optlist, "noautosendcmd") != NULL)
        conn->no_autosendcmd = TRUE;

	if (g_hash_table_lookup(optlist, "noproxy") != NULL)
                g_free_and_null(conn->proxy);


	*rawlog_file = g_strdup(g_hash_table_lookup(optlist, "rawlog"));

        host = g_hash_table_lookup(optlist, "host");
	if (host != NULL && *host != '\0') {
		IPADDR ip4, ip6;

		if (net_gethostbyname(host, &ip4, &ip6) == 0)
                        server_connect_own_ip_save(conn, &ip4, &ip6);
	}

	cmd_params_free(free_arg);
        return conn;
}