Skip to content

Commit

Permalink
Renaming library
Browse files Browse the repository at this point in the history
  • Loading branch information
andrenth committed Jul 10, 2012
1 parent cbb15ef commit de8720e
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 81 deletions.
2 changes: 1 addition & 1 deletion _oasis
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Library spf
Path: lib Path: lib
BuildTools: ocamlbuild BuildTools: ocamlbuild
CompiledObject: best CompiledObject: best
Modules: Spf Modules: SPF
CSources: spf_stubs.c CSources: spf_stubs.c
CCLib: -lspf2 CCLib: -lspf2
CCOpt: -Wall -Werror CCOpt: -Wall -Werror
Expand Down
6 changes: 3 additions & 3 deletions lib/spf.ml → lib/SPF.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ type response =
; header_comment : string ; header_comment : string
} }


exception Spf_error of string exception SPF_error of string


let _ = Callback.register_exception "Spf.Spf_error" (Spf_error "") let _ = Callback.register_exception "SPF.SPF_error" (SPF_error "")


external server : ?debug:bool -> dns -> server = "caml_spf_server_new" external server : ?debug:bool -> dns -> server = "caml_spf_server_new"


Expand Down Expand Up @@ -91,7 +91,7 @@ let set_envelope_from req from =
let process req = let process req =
try try
`Response (query_mailfrom req.request) `Response (query_mailfrom req.request)
with Spf_error err -> with SPF_error err ->
`Error err `Error err


let check_helo server client_addr helo = let check_helo server client_addr helo =
Expand Down
2 changes: 1 addition & 1 deletion lib/spf.mli → lib/SPF.mli
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type result
| Temperror | Temperror
| Permerror | Permerror


exception Spf_error of string exception SPF_error of string


val server : ?debug:bool -> dns -> server val server : ?debug:bool -> dns -> server


Expand Down
4 changes: 0 additions & 4 deletions lib/libspf.clib

This file was deleted.

4 changes: 2 additions & 2 deletions lib/spf.mllib
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
# OASIS_START # OASIS_START
# DO NOT EDIT (digest: 5fe65aaadc52937c34be7016e4dd4d14) # DO NOT EDIT (digest: b4efb35349e5d93905531be07dbacd6d)
Spf SPF
# OASIS_STOP # OASIS_STOP
2 changes: 1 addition & 1 deletion lib/spf_stubs.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dns_type_of_val(value v)
static void static void
spf_error(const char *err) spf_error(const char *err)
{ {
caml_raise_with_string(*caml_named_value("Spf.Spf_error"), err); caml_raise_with_string(*caml_named_value("SPF.SPF_error"), err);
} }


static void static void
Expand Down
52 changes: 26 additions & 26 deletions lib_test/test.ml
Original file line number Original file line Diff line number Diff line change
@@ -1,50 +1,50 @@
open Printf open Printf


let () = let () =
let server = Spf.server Spf.Dns_cache in let server = SPF.server SPF.Dns_cache in
let client_addr = Unix.inet_addr_of_string "187.73.32.159" in let client_addr = Unix.inet_addr_of_string "187.73.32.159" in
let helo = "mta98.f1.k8.com.br" in let helo = "mta98.f1.k8.com.br" in
let from = "andre@andrenathan.com" in let from = "andre@andrenathan.com" in
match Spf.check_from server client_addr helo from with match SPF.check_from server client_addr helo from with
| `Error e -> | `Error e ->
printf "SPF error: %s\n%!" e printf "SPF error: %s\n%!" e
| `Response r -> | `Response r ->
printf "SPF response:\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n%!" printf "SPF response:\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n%!"
(Spf.string_of_result (Spf.result r)) (SPF.string_of_result (SPF.result r))
(Spf.string_of_reason (Spf.reason r)) (SPF.string_of_reason (SPF.reason r))
(Spf.received_spf r) (SPF.received_spf r)
(Spf.received_spf_value r) (SPF.received_spf_value r)
(Spf.header_comment r); (SPF.header_comment r);
match Spf.result r with match SPF.result r with
| Spf.Neutral c | SPF.Neutral c
| Spf.Fail c | SPF.Fail c
| Spf.Softfail c -> | SPF.Softfail c ->
printf "\t\t%s\n\t\t%s\n%!" printf "\t\t%s\n\t\t%s\n%!"
(Spf.explanation c) (SPF.explanation c)
(Spf.smtp_comment c) (SPF.smtp_comment c)
| _ -> () | _ -> ()


let () = let () =
let server = Spf.server ~debug:false Spf.Dns_cache in let server = SPF.server ~debug:false SPF.Dns_cache in
let client_addr = Unix.inet_addr_of_string "189.57.226.93" in let client_addr = Unix.inet_addr_of_string "189.57.226.93" in
let helo = "gwmail.bradescoseguros.com.br" in let helo = "gwmail.bradescoseguros.com.br" in
let _from = "andre@bradescoseguros.com.br" in let _from = "andre@bradescoseguros.com.br" in
match Spf.check_helo server client_addr helo with match SPF.check_helo server client_addr helo with
| `Error e -> | `Error e ->
printf "SPF error: %s\n%!" e printf "SPF error: %s\n%!" e
| `Response r -> | `Response r ->
printf "SPF response:\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n%!" printf "SPF response:\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n%!"
(Spf.string_of_result (Spf.result r)) (SPF.string_of_result (SPF.result r))
(Spf.string_of_reason (Spf.reason r)) (SPF.string_of_reason (SPF.reason r))
(Spf.received_spf r) (SPF.received_spf r)
(Spf.received_spf_value r) (SPF.received_spf_value r)
(Spf.header_comment r); (SPF.header_comment r);
printf ">>>\n%!"; printf ">>>\n%!";
match Spf.result r with match SPF.result r with
| Spf.Neutral c | SPF.Neutral c
| Spf.Fail c | SPF.Fail c
| Spf.Softfail c -> | SPF.Softfail c ->
printf "\t\t%s\n\t\t%s\n%!" printf "\t\t%s\n\t\t%s\n%!"
(Spf.explanation c) (SPF.explanation c)
(Spf.smtp_comment c) (SPF.smtp_comment c)
| _ -> () | _ -> ()
6 changes: 3 additions & 3 deletions setup.ml
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
(* setup.ml generated for the first time by OASIS v0.2.0 *) (* setup.ml generated for the first time by OASIS v0.2.0 *)


(* OASIS_START *) (* OASIS_START *)
(* DO NOT EDIT (digest: ca6cad8e2e57eac64dc639c68761d1f6) *) (* DO NOT EDIT (digest: 38e3df07861572eab06a4b5f381256dd) *)
(* (*
Regenerated by OASIS v0.3.0 Regenerated by OASIS v0.3.0
Visit http://oasis.forge.ocamlcore.org for more information and Visit http://oasis.forge.ocamlcore.org for more information and
Expand Down Expand Up @@ -5655,7 +5655,7 @@ let setup_t =
bs_nativeopt = [(OASISExpr.EBool true, [])]; bs_nativeopt = [(OASISExpr.EBool true, [])];
}, },
{ {
lib_modules = ["Spf"]; lib_modules = ["SPF"];
lib_pack = false; lib_pack = false;
lib_internal_modules = []; lib_internal_modules = [];
lib_findlib_parent = None; lib_findlib_parent = None;
Expand Down Expand Up @@ -5797,7 +5797,7 @@ let setup_t =
}; };
oasis_fn = Some "_oasis"; oasis_fn = Some "_oasis";
oasis_version = "0.3.0"; oasis_version = "0.3.0";
oasis_digest = Some "v \015[\142\207q;\241\232C\242\222\031+\157"; oasis_digest = Some "\253\155\\\184\230ml{\018\170\241z\177\160\205\146";
oasis_exec = None; oasis_exec = None;
oasis_setup_args = []; oasis_setup_args = [];
setup_update = false; setup_update = false;
Expand Down
26 changes: 13 additions & 13 deletions src/milter_callbacks.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ open Util
type result type result
= No_result = No_result
| Whitelisted of string | Whitelisted of string
| Spf_response of Spf.response | Spf_response of SPF.response


type priv = type priv =
{ addr : Unix.inet_addr { addr : Unix.inet_addr
; helo : string option ; helo : string option
; result : result ; result : result
} }


let spf_server = Spf.server Spf.Dns_cache let spf_server = SPF.server SPF.Dns_cache


let config = Config.default let config = Config.default


Expand Down Expand Up @@ -50,13 +50,13 @@ let milter_tempfail ctx comment =
let spf_check_helo ctx priv = let spf_check_helo ctx priv =
let addr = priv.addr in let addr = priv.addr in
let helo = some (priv.helo) in let helo = some (priv.helo) in
let spf_res = unbox_spf (Spf.check_helo spf_server addr helo) in let spf_res = unbox_spf (SPF.check_helo spf_server addr helo) in
let milter_res = match Spf.result spf_res with let milter_res = match SPF.result spf_res with
| Spf.Fail c -> | SPF.Fail c ->
milter_reject ctx (Spf.smtp_comment c) milter_reject ctx (SPF.smtp_comment c)
| Spf.Temperror -> | SPF.Temperror ->
if config.Config.fail_on_helo_temperror then if config.Config.fail_on_helo_temperror then
milter_tempfail ctx (Spf.header_comment spf_res) milter_tempfail ctx (SPF.header_comment spf_res)
else else
Milter.Continue Milter.Continue
| _ -> | _ ->
Expand All @@ -66,10 +66,10 @@ let spf_check_helo ctx priv =
let spf_check_from ctx priv from = let spf_check_from ctx priv from =
let addr = priv.addr in let addr = priv.addr in
let helo = some (priv.helo) in let helo = some (priv.helo) in
let spf_res = unbox_spf (Spf.check_from spf_server addr helo from) in let spf_res = unbox_spf (SPF.check_from spf_server addr helo from) in
let milter_res = match Spf.result spf_res with let milter_res = match SPF.result spf_res with
| Spf.Fail c -> milter_reject ctx (Spf.smtp_comment c) | SPF.Fail c -> milter_reject ctx (SPF.smtp_comment c)
| Spf.Temperror -> milter_tempfail ctx (Spf.header_comment spf_res) | SPF.Temperror -> milter_tempfail ctx (SPF.header_comment spf_res)
| _ -> Milter.Continue in | _ -> Milter.Continue in
spf_res, milter_res spf_res, milter_res


Expand Down Expand Up @@ -149,7 +149,7 @@ let eom ctx =
(match priv.result with (match priv.result with
| No_result -> () | No_result -> ()
| Whitelisted s -> milter_add_header ctx s | Whitelisted s -> milter_add_header ctx s
| Spf_response r -> milter_add_header ctx (Spf.received_spf r)); | Spf_response r -> milter_add_header ctx (SPF.received_spf r));
priv, Milter.Continue) priv, Milter.Continue)


let abort ctx = let abort ctx =
Expand Down
50 changes: 25 additions & 25 deletions src/policy.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ type response


type cache = type cache =
{ instance : string { instance : string
; mutable helo_response : Spf.response option ; mutable helo_response : SPF.response option
; mutable from_response : Spf.response option ; mutable from_response : SPF.response option
; mutable spf_header_added : bool ; mutable spf_header_added : bool
; mutable timestamp : float ; mutable timestamp : float
} }


type handler = (Spf.server -> Postfix.attrs -> cache -> response Lwt.t) type handler = (SPF.server -> Postfix.attrs -> cache -> response Lwt.t)


let new_cache_entry instance = let new_cache_entry instance =
{ instance = instance { instance = instance
Expand Down Expand Up @@ -77,51 +77,51 @@ let fail_on_helo_temperror = true


let handle_helo_response sender cache = let handle_helo_response sender cache =
let res = some cache.helo_response in let res = some cache.helo_response in
match Spf.result res with match SPF.result res with
| Spf.Fail comment -> | SPF.Fail comment ->
Five_zero_five (Spf.smtp_comment comment) Five_zero_five (SPF.smtp_comment comment)
| Spf.Temperror -> | SPF.Temperror ->
if fail_on_helo_temperror then if fail_on_helo_temperror then
let comment = Spf.header_comment res in let comment = SPF.header_comment res in
Defer_if_permit (sprintf "SPF-Result=%s" comment) Defer_if_permit (sprintf "SPF-Result=%s" comment)
else else
Dunno Dunno
| _ -> | _ ->
if sender = "" && not cache.spf_header_added then begin if sender = "" && not cache.spf_header_added then begin
cache.spf_header_added <- true; cache.spf_header_added <- true;
let expl = match Spf.result res with let expl = match SPF.result res with
| Spf.Neutral c | Spf.Fail c | SPF.Neutral c | SPF.Fail c
| Spf.Softfail c -> | SPF.Softfail c ->
sprintf " %s" (Spf.smtp_comment c) sprintf " %s" (SPF.smtp_comment c)
| _ -> | _ ->
"" in "" in
Prepend (sprintf "%s%s" (Spf.received_spf res) expl) Prepend (sprintf "%s%s" (SPF.received_spf res) expl)
end else end else
Dunno Dunno


let handle_from_response cache = let handle_from_response cache =
let res = some cache.from_response in let res = some cache.from_response in
match Spf.result res with match SPF.result res with
| Spf.Fail comment -> | SPF.Fail comment ->
Five_zero_five (Spf.explanation comment) Five_zero_five (SPF.explanation comment)
| Spf.Temperror -> | SPF.Temperror ->
let comment = Spf.header_comment res in let comment = SPF.header_comment res in
Defer_if_permit (sprintf "SPF-Result=%s" comment) Defer_if_permit (sprintf "SPF-Result=%s" comment)
| _ -> | _ ->
if not cache.spf_header_added then begin if not cache.spf_header_added then begin
cache.spf_header_added <- true; cache.spf_header_added <- true;
let expl = match Spf.result res with let expl = match SPF.result res with
| Spf.Neutral c | Spf.Fail c | SPF.Neutral c | SPF.Fail c
| Spf.Softfail c -> | SPF.Softfail c ->
sprintf " %s" (Spf.explanation c) sprintf " %s" (SPF.explanation c)
| _ -> | _ ->
"" in "" in
Prepend (sprintf "%s%s" (Spf.received_spf res) expl) Prepend (sprintf "%s%s" (SPF.received_spf res) expl)
end else end else
Dunno Dunno


let check_helo server addr helo = let check_helo server addr helo =
Lwt_preemptive.detach (fun () -> Spf.check_helo server addr helo) () Lwt_preemptive.detach (fun () -> SPF.check_helo server addr helo) ()


let process_helo spf_server client_addr helo_name sender cache = let process_helo spf_server client_addr helo_name sender cache =
lwt () = if cache.helo_response = None then begin lwt () = if cache.helo_response = None then begin
Expand All @@ -134,7 +134,7 @@ let process_helo spf_server client_addr helo_name sender cache =
return (handle_helo_response sender cache) return (handle_helo_response sender cache)


let check_from server addr helo sender = let check_from server addr helo sender =
Lwt_preemptive.detach (fun () -> Spf.check_from server addr helo sender) () Lwt_preemptive.detach (fun () -> SPF.check_from server addr helo sender) ()


let process_from spf_server client_addr helo_name sender cache = let process_from spf_server client_addr helo_name sender cache =
lwt () = if cache.from_response = None then begin lwt () = if cache.from_response = None then begin
Expand Down
2 changes: 1 addition & 1 deletion src/policy.mli
Original file line number Original file line Diff line number Diff line change
@@ -1 +1 @@
val handle_attrs : Spf.server -> Postfix.attrs -> string Lwt.t val handle_attrs : SPF.server -> Postfix.attrs -> string Lwt.t
2 changes: 1 addition & 1 deletion src/spf_policyd.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let handle_sigterm _ =
exit 0 exit 0


let spf_handler fd = let spf_handler fd =
let spf_server = Spf.server Spf.Dns_cache in let spf_server = SPF.server SPF.Dns_cache in
match_lwt Postfix.parse_attrs fd with match_lwt Postfix.parse_attrs fd with
| None -> | None ->
return () return ()
Expand Down

0 comments on commit de8720e

Please sign in to comment.