package uspf-lwt

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file uspf_lwt.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module Lwt_scheduler = Uspf.Sigs.Make (struct
  type 'a t = 'a Lwt.t
end)

let _state =
  let open Uspf.Sigs in
  let open Lwt_scheduler in
  let open Lwt.Infix in
  {
    bind = (fun x f -> inj (prj x >>= fun x -> prj (f x)));
    return = (fun x -> inj (Lwt.return x));
  }

module type DNS = sig
  type t

  type error =
    [ `Msg of string
    | `No_data of [ `raw ] Domain_name.t * Dns.Soa.t
    | `No_domain of [ `raw ] Domain_name.t * Dns.Soa.t ]

  val getrrecord :
    t -> 'r Dns.Rr_map.key -> _ Domain_name.t -> ('r, [> error ]) result Lwt.t
end

let get :
    type dns.
    domain:_ Domain_name.t -> dns -> (module DNS with type t = dns) -> _ =
 fun ~domain:domain_name dns (module DNS) ->
  let open Lwt.Infix in
  DNS.getrrecord dns Dns.Rr_map.Txt domain_name >>= function
  | Error (`Msg _) -> Lwt.return_error `Not_found
  | Error (`No_domain _ | `No_data _) -> Lwt.return_error `Not_found
  | Ok (_, txts) ->
  match
    let ( >>= ) x f = Result.bind x f in
    Uspf.select_spf1 (Dns.Rr_map.Txt_set.elements txts)
    >>= Uspf.Term.parse_record
  with
  | Ok terms -> Lwt.return_ok terms
  | Error `None -> Lwt.return_error `Not_found
  | Error (`Msg _) -> Lwt.return_error `Invalid_SPF_record
OCaml

Innovation. Community. Security.