Exemplo n.º 1
0
static void chatnet_read(CONFIG_NODE *node)
{
        CHAT_PROTOCOL_REC *proto;
	CHATNET_REC *rec;
        char *type;

	if (node == NULL || node->key == NULL)
		return;

	type = config_node_get_str(node, "type", NULL);
	proto = type == NULL ? NULL : chat_protocol_find(type);
	if (proto == NULL) {
		proto = type == NULL ? chat_protocol_get_default() :
			chat_protocol_get_unknown(type);
	}

	if (type == NULL)
		iconfig_node_set_str(node, "type", proto->name);

	rec = proto->create_chatnet();
	rec->type = module_get_uniq_id("CHATNET", 0);
	rec->chat_type = proto->id;
	rec->name = g_strdup(node->key);
	rec->nick = g_strdup(config_node_get_str(node, "nick", NULL));
	rec->username = g_strdup(config_node_get_str(node, "username", NULL));
	rec->realname = g_strdup(config_node_get_str(node, "realname", NULL));
	rec->own_host = g_strdup(config_node_get_str(node, "host", NULL));
	rec->autosendcmd = g_strdup(config_node_get_str(node, "autosendcmd", NULL));

	chatnets = g_slist_append(chatnets, rec);
        signal_emit("chatnet read", 2, rec, node);
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
static SERVER_SETUP_REC *create_server_setup(GHashTable *optlist)
{
	CHAT_PROTOCOL_REC *rec;
        SERVER_SETUP_REC *server;
        char *chatnet;

	rec = chat_protocol_find_net(optlist);
	if (rec == NULL)
                rec = chat_protocol_get_default();
	else {
		chatnet = g_hash_table_lookup(optlist, rec->chatnet);
		if (chatnet_find(chatnet) == NULL) {
			printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
				    TXT_UNKNOWN_CHATNET, chatnet);
			return NULL;
		}
	}

        server = rec->create_server_setup();
        server->chat_type = rec->id;
	return server;
}
Exemplo n.º 4
0
static SERVER_SETUP_REC *server_setup_read(CONFIG_NODE *node)
{
	SERVER_SETUP_REC *rec;
        CHATNET_REC *chatnetrec;
	char *server, *chatnet, *family;
	int port;

	g_return_val_if_fail(node != NULL, NULL);

	server = config_node_get_str(node, "address", NULL);
	if (server == NULL)
		return NULL;

	port = config_node_get_int(node, "port", 0);
	chatnet = config_node_get_str(node, "chatnet", NULL);

	if (server_setup_find(server, port, chatnet) != NULL) {
		return NULL;
	}

	rec = NULL;

	chatnetrec = chatnet == NULL ? NULL : chatnet_find(chatnet);
	if (chatnetrec == NULL && chatnet != NULL) {
                /* chat network not found, create it. */
		chatnetrec = chat_protocol_get_default()->create_chatnet();
		chatnetrec->chat_type = chat_protocol_get_default()->id;
		chatnetrec->name = g_strdup(chatnet);
		chatnet_create(chatnetrec);
	}

        family = config_node_get_str(node, "family", "");

	rec = CHAT_PROTOCOL(chatnetrec)->create_server_setup();
	rec->type = module_get_uniq_id("SERVER SETUP", 0);
        rec->chat_type = CHAT_PROTOCOL(chatnetrec)->id;
	rec->chatnet = chatnetrec == NULL ? NULL : g_strdup(chatnetrec->name);
	rec->family = g_ascii_strcasecmp(family, "inet6") == 0 ? AF_INET6 :
		(g_ascii_strcasecmp(family, "inet") == 0 ? AF_INET : 0);
	rec->address = g_strdup(server);
	rec->password = g_strdup(config_node_get_str(node, "password", NULL));
	rec->use_ssl = config_node_get_bool(node, "use_ssl", FALSE);
	rec->ssl_cert = g_strdup(config_node_get_str(node, "ssl_cert", NULL));
	rec->ssl_pkey = g_strdup(config_node_get_str(node, "ssl_pkey", NULL));
	rec->ssl_verify = config_node_get_bool(node, "ssl_verify", FALSE);
	rec->ssl_cafile = g_strdup(config_node_get_str(node, "ssl_cafile", NULL));
	rec->ssl_capath = g_strdup(config_node_get_str(node, "ssl_capath", NULL));
	if (rec->ssl_cafile || rec->ssl_capath)
		rec->ssl_verify = TRUE;
	if (rec->ssl_cert != NULL || rec->ssl_verify)
		rec->use_ssl = TRUE;
	rec->port = port;
	rec->autoconnect = config_node_get_bool(node, "autoconnect", FALSE);
	rec->no_proxy = config_node_get_bool(node, "no_proxy", FALSE);
	rec->own_host = g_strdup(config_node_get_str(node, "own_host", NULL));

	signal_emit("server setup read", 2, rec, node);

	setupservers = g_slist_append(setupservers, rec);
	return rec;
}