Mercurial > irccd
diff irccdctl/main.cpp @ 796:1a6152af0866
misc: use ipv4 as option rather than family
Now, all sections and JSON options that require a IP family will take ipv4 and
ipv6 boolean options for convenience.
It reduces parsing complexity and is more convenient for the user.
Examples:
# IPv6 server only
[server]
name = example
port = 6667
hostname = example.org
ipv4 = false
ipv6 = true
# IPv4 transport only
[transport]
type = ip
ipv4 = true
ipv6 = false
port = 3320
If both options are defined (default everywhere), both protocols will be tried
or bound.
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 11 Nov 2018 14:56:04 +0100 |
parents | 2d04f5e5f343 |
children | f26bb089232d |
line wrap: on
line diff
--- a/irccdctl/main.cpp Sun Nov 11 14:53:14 2018 +0100 +++ b/irccdctl/main.cpp Sun Nov 11 14:56:04 2018 +0100 @@ -79,7 +79,8 @@ * type = "ip" * hostname = "ip or hostname" * port = "port number or service" - * family = "ipv4, ipv6" (Optional, default: ipv4, ipv6) + * ipv4 = try IPv4 (Optional, default: true) + * ipv6 = try IPv6 (Optional, default: true) * ssl = true | false (Optional, default: false) */ auto read_connect_ip(const ini::section& sc) -> std::unique_ptr<connector> @@ -89,16 +90,10 @@ bool ipv4 = true; bool ipv6 = true; - if (auto it = sc.find("family"); it != sc.end()) { - ipv4 = ipv6 = false; - - for (auto v : *it) { - if (v == "ipv4") - ipv4 = true; - else if (v == "ipv6") - ipv6 = true; - } - } + if (const auto it = sc.find("ipv4"); it != sc.end()) + ipv4 = string_util::is_boolean(it->get_value()); + if (const auto it = sc.find("ipv6"); it != sc.end()) + ipv6 = string_util::is_boolean(it->get_value()); if (!ipv4 && !ipv6) throw transport_error(transport_error::invalid_family);