aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Davidson <colrdavidson@gmail.com>2023-03-02 06:56:54 -0800
committerColin Davidson <colrdavidson@gmail.com>2023-03-02 06:56:54 -0800
commit38d58e818c171761e91ce81a480cca2955fe12bf (patch)
tree5fba5b060956a54d2ffb5a0be131870a9c442609
parent090723179bb965ee879b7f75f33963a1ec9d4fac (diff)
ripple bill-suggestions
-rw-r--r--core/net/addr.odin11
-rw-r--r--core/net/dns.odin26
-rw-r--r--core/net/url.odin2
3 files changed, 15 insertions, 24 deletions
diff --git a/core/net/addr.odin b/core/net/addr.odin
index 77debcf26..52222f904 100644
--- a/core/net/addr.odin
+++ b/core/net/addr.odin
@@ -34,11 +34,8 @@ import "core:fmt"
If `allow_non_decimal` is true, `aton` is told each component must be decimal and max 255.
*/
parse_ip4_address :: proc(address_and_maybe_port: string, allow_non_decimal := false) -> (addr: IP4_Address, ok: bool) {
- res, res_ok := aton(address_and_maybe_port, .IP4, !allow_non_decimal)
- if ip4, ip4_ok := res.(IP4_Address); ip4_ok {
- return ip4, res_ok
- }
- return {}, false
+ res := aton(address_and_maybe_port, .IP4, !allow_non_decimal) or_return
+ return res.?
}
/*
@@ -432,7 +429,7 @@ parse_hostname_or_endpoint :: proc(endpoint_str: string) -> (target: Host_Or_End
// Returns ok=false if port is not a number.
split_port :: proc(endpoint_str: string) -> (addr_or_host: string, port: int, ok: bool) {
// IP6 [addr_or_host]:port
- if i := strings.last_index(endpoint_str, "]:"); i != -1 {
+ if i := strings.last_index(endpoint_str, "]:"); i >= 0 {
addr_or_host = endpoint_str[1:i]
port, ok = strconv.parse_int(endpoint_str[i+2:], 10)
@@ -741,4 +738,4 @@ parse_ip_component :: proc(input: string, max_value := u64(max(u32)), bases := D
// If we consumed at least 1 digit byte, `value` *should* continue a valid number in an appropriate base in the allowable range.
return value, digit_bytes + prefix_bytes, digit_bytes >= 1
-} \ No newline at end of file
+}
diff --git a/core/net/dns.odin b/core/net/dns.odin
index 2875029de..e2c74d359 100644
--- a/core/net/dns.odin
+++ b/core/net/dns.odin
@@ -58,7 +58,7 @@ dns_configuration := DEFAULT_DNS_CONFIGURATION
replace_environment_path :: proc(path: string, allocator := context.allocator) -> (res: string, ok: bool) {
// Nothing to replace. Return a clone of the original.
if strings.count(path, "%") != 2 {
- return strings.clone(path), true
+ return strings.clone(path, allocator), true
}
left := strings.index(path, "%") + 1
@@ -68,10 +68,10 @@ replace_environment_path :: proc(path: string, allocator := context.allocator) -
assert(right > 0 && right <= len(path)) // should be covered by there being two %
env_key := path[left: right]
- env_val := os.get_env(env_key)
+ env_val := os.get_env(env_key, allocator)
defer delete(env_val)
- res, _ = strings.replace(path, path[left - 1: right + 1], env_val, 1)
+ res, _ = strings.replace(path, path[left - 1: right + 1], env_val, 1, allocator)
return res, true
}
@@ -356,10 +356,7 @@ unpack_dns_header :: proc(id: u16be, bits: u16be) -> (hdr: DNS_Header) {
load_resolv_conf :: proc(resolv_conf_path: string, allocator := context.allocator) -> (name_servers: []Endpoint, ok: bool) {
context.allocator = allocator
- res, success := os.read_entire_file_from_filename(resolv_conf_path)
- if !success {
- return
- }
+ res := os.read_entire_file_from_filename(resolv_conf_path) or_return
defer delete(res)
resolv_str := string(res)
@@ -393,10 +390,7 @@ load_resolv_conf :: proc(resolv_conf_path: string, allocator := context.allocato
load_hosts :: proc(hosts_file_path: string, allocator := context.allocator) -> (hosts: []DNS_Host_Entry, ok: bool) {
context.allocator = allocator
- res, success := os.read_entire_file_from_filename(hosts_file_path, allocator)
- if !success {
- return
- }
+ res := os.read_entire_file_from_filename(hosts_file_path, allocator) or_return
defer delete(res)
_hosts := make([dynamic]DNS_Host_Entry, 0, allocator)
@@ -800,7 +794,7 @@ parse_response :: proc(response: []u8, filter: DNS_Record_Type = nil, allocator
cur_idx := header_size_bytes
- for i := 0; i < question_count; i += 1 {
+ for _ in 0..<question_count {
if cur_idx == len(response) {
continue
}
@@ -812,7 +806,7 @@ parse_response :: proc(response: []u8, filter: DNS_Record_Type = nil, allocator
cur_idx += hn_sz + dq_sz
}
- for i := 0; i < answer_count; i += 1 {
+ for _ in 0..<answer_count {
if cur_idx == len(response) {
continue
}
@@ -825,7 +819,7 @@ parse_response :: proc(response: []u8, filter: DNS_Record_Type = nil, allocator
append(&_records, rec)
}
- for i := 0; i < authority_count; i += 1 {
+ for _ in 0..<authority_count {
if cur_idx == len(response) {
continue
}
@@ -838,7 +832,7 @@ parse_response :: proc(response: []u8, filter: DNS_Record_Type = nil, allocator
append(&_records, rec)
}
- for i := 0; i < additional_count; i += 1 {
+ for _ in 0..<additional_count {
if cur_idx == len(response) {
continue
}
@@ -852,4 +846,4 @@ parse_response :: proc(response: []u8, filter: DNS_Record_Type = nil, allocator
}
return _records[:], true
-} \ No newline at end of file
+}
diff --git a/core/net/url.odin b/core/net/url.odin
index 980fb5e90..c1d46033f 100644
--- a/core/net/url.odin
+++ b/core/net/url.odin
@@ -25,7 +25,7 @@ split_url :: proc(url: string, allocator := context.allocator) -> (scheme, host,
s := url
i := strings.last_index(s, "://")
- if i != -1 {
+ if i >= 0 {
scheme = s[:i]
s = s[i+3:]
}