hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 2c2d225e58bb28970411172328de5c277511a476
parent 7681a1f8cc90535280e7ccdb9ad87f89f3a7bb50
Author: Lassi Pulkkinen <lassi@pulk.fi>
Date:   Sat, 17 Dec 2022 07:13:36 +0200

net::dns: Move (un)parse_domain into their own file

Signed-off-by: Lassi Pulkkinen <lassi@pulk.fi>

Diffstat:
Mnet/dns/encode.ha | 11-----------
Anet/dns/strdomain.ha | 13+++++++++++++
Mscripts/gen-stdlib | 1+
Mstdlib.mk | 2++
4 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/net/dns/encode.ha b/net/dns/encode.ha @@ -3,23 +3,12 @@ use endian; use errors; use fmt; -use strings; type encoder = struct { buf: []u8, offs: size, }; -// Converts a human-readable domain name (e.g. "example.org") into a DNS-ready -// name slice (e.g. ["example", "org"]). The slice returned must be freed by the -// caller, but the members of the slice themselves are borrowed from the input. -export fn parse_domain(in: str) []str = strings::split(in, "."); - -// Converts a DNS name slice (e.g. ["example", "org"]) into a human-readable -// domain name (e.g. "example.org"). The return value must be freed by the -// caller. -export fn unparse_domain(in: []str) str = strings::join(".", in...); - // Encodes a DNS message, returning its size, or an error. export fn encode(buf: []u8, msg: *message) (size | error) = { let enc = encoder { buf = buf, offs = 0z }; diff --git a/net/dns/strdomain.ha b/net/dns/strdomain.ha @@ -0,0 +1,13 @@ +// License: MPL-2.0 +// (c) 2021 Drew DeVault <sir@cmpwn.com> +use strings; + +// Converts a human-readable domain name (e.g. "example.org") into a DNS-ready +// name slice (e.g. ["example", "org"]). The slice returned must be freed by the +// caller, but the members of the slice themselves are borrowed from the input. +export fn parse_domain(in: str) []str = strings::split(in, "."); + +// Converts a DNS name slice (e.g. ["example", "org"]) into a human-readable +// domain name (e.g. "example.org"). The return value must be freed by the +// caller. +export fn unparse_domain(in: []str) str = strings::join(".", in...); diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib @@ -1006,6 +1006,7 @@ net_dns() { error.ha \ encode.ha \ query.ha \ + strdomain.ha \ types.ha gen_ssa net::dns ascii endian net net::udp net::ip fmt strings \ unix::resolvconf unix::poll rt time errors diff --git a/stdlib.mk b/stdlib.mk @@ -1640,6 +1640,7 @@ stdlib_net_dns_any_srcs = \ $(STDLIB)/net/dns/error.ha \ $(STDLIB)/net/dns/encode.ha \ $(STDLIB)/net/dns/query.ha \ + $(STDLIB)/net/dns/strdomain.ha \ $(STDLIB)/net/dns/types.ha $(HARECACHE)/net/dns/net_dns-any.ssa: $(stdlib_net_dns_any_srcs) $(stdlib_rt) $(stdlib_ascii_$(PLATFORM)) $(stdlib_endian_$(PLATFORM)) $(stdlib_net_$(PLATFORM)) $(stdlib_net_udp_$(PLATFORM)) $(stdlib_net_ip_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_unix_resolvconf_$(PLATFORM)) $(stdlib_unix_poll_$(PLATFORM)) $(stdlib_rt_$(PLATFORM)) $(stdlib_time_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) @@ -3892,6 +3893,7 @@ testlib_net_dns_any_srcs = \ $(STDLIB)/net/dns/error.ha \ $(STDLIB)/net/dns/encode.ha \ $(STDLIB)/net/dns/query.ha \ + $(STDLIB)/net/dns/strdomain.ha \ $(STDLIB)/net/dns/types.ha $(TESTCACHE)/net/dns/net_dns-any.ssa: $(testlib_net_dns_any_srcs) $(testlib_rt) $(testlib_ascii_$(PLATFORM)) $(testlib_endian_$(PLATFORM)) $(testlib_net_$(PLATFORM)) $(testlib_net_udp_$(PLATFORM)) $(testlib_net_ip_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_unix_resolvconf_$(PLATFORM)) $(testlib_unix_poll_$(PLATFORM)) $(testlib_rt_$(PLATFORM)) $(testlib_time_$(PLATFORM)) $(testlib_errors_$(PLATFORM))