Parse single IP addresses

This commit is contained in:
jeltz 2022-09-07 06:21:56 +02:00
parent 4371d0f445
commit ae9d67eb8a
Signed by: jeltz
GPG key ID: 800882B66C0C3326

View file

@ -16,7 +16,13 @@ module Zone = struct
let rec of_json = function let rec of_json = function
| `String str -> | `String str ->
str |> V6.Prefix.of_string |> Result.map ipv6 str |> V6.Prefix.of_string |> Result.map ipv6
&?> (str |> V6.of_string
|> Result.map V6.Prefix.of_addr
|> Result.map ipv6)
&?> (str |> V4.Prefix.of_string |> Result.map ipv4) &?> (str |> V4.Prefix.of_string |> Result.map ipv4)
&?> (str |> V4.of_string
|> Result.map V4.Prefix.of_addr
|> Result.map ipv4)
&> (str |> name) &> (str |> name)
| `Assoc [ ("not", json) ] -> Not (of_json json) | `Assoc [ ("not", json) ] -> Not (of_json json)
| `List list -> List (List.map of_json list) | `List list -> List (List.map of_json list)
@ -34,7 +40,9 @@ module Addrs = struct
let open Yojson.Basic.Util in let open Yojson.Basic.Util in
let str = json |> to_string in let str = json |> to_string in
str |> V6.Prefix.of_string |> Result.map ipv6 str |> V6.Prefix.of_string |> Result.map ipv6
&?> (str |> V6.of_string |> Result.map V6.Prefix.of_addr |> Result.map ipv6)
&?> (str |> V4.Prefix.of_string |> Result.map ipv4) &?> (str |> V4.Prefix.of_string |> Result.map ipv4)
&?> (str |> V4.of_string |> Result.map V4.Prefix.of_addr |> Result.map ipv4)
&> (str |> name) &> (str |> name)
end end