Skip to content
Browse files

Move functions to module Postfix

  • Loading branch information...
1 parent 6e6eee9 commit aaecd1a76d588ab7ce6b4f281c989a7d24b4f89e @andrenth committed
Showing with 33 additions and 30 deletions.
  1. +1 −0 _tags
  2. +29 −0 src/postfix.ml
  3. +3 −30 src/spf_slave.ml
View
1 _tags
@@ -52,5 +52,6 @@
<*/*.ml>: annot
<*/*.ml>: warn_error
<src/policy.ml>: syntax_camlp4o
+<src/postfix.ml>: syntax_camlp4o
<src/spfd.ml>: syntax_camlp4o
<src/spf_slave.ml>: syntax_camlp4o
View
29 src/postfix.ml
@@ -1,3 +1,4 @@
+open Lwt
open Printf
type attrs =
@@ -59,3 +60,31 @@ let parse_lines lines =
AttrMap.empty
lines in
attrs_of_map map
+
+module B = Release_buffer
+
+let read_attrs fd =
+ let siz = 1024 in
+ let buf = B.create siz in
+ let rec read offset remain =
+ match_lwt Release_io.read_once fd buf offset remain with
+ | 0 ->
+ lwt () = Lwt_log.error "got eof on socket, closing" in
+ lwt () = Lwt_unix.close fd in
+ return None
+ | k ->
+ let len = B.length buf in
+ if B.get buf (len - 2) = '\n' && B.get buf (len - 1) = '\n' then
+ return (Some buf)
+ else
+ read (offset + k) (remain - k) in
+ lwt res = read 0 siz in
+ return res
+
+let parse_attrs fd =
+ match_lwt read_attrs fd with
+ | None ->
+ return None
+ | Some buf ->
+ let lines = Str.split (Str.regexp "\n") (B.to_string buf) in
+ return (parse_lines lines)
View
33 src/spf_slave.ml
@@ -28,42 +28,15 @@ let handle_sigterm _ =
Lwt_main.run (log_t >> cleanup_t);
exit 0
-module B = Release_buffer
-
-let read_postfix_attrs fd =
- let siz = 1024 in
- let buf = Release_buffer.create siz in
- let rec read offset remain =
- match_lwt Release_io.read_once fd buf offset remain with
- | 0 ->
- lwt () = Lwt_log.error "got eof on socket, closing" in
- lwt () = Lwt_unix.close fd in
- return None
- | k ->
- let len = B.length buf in
- if B.get buf (len - 2) = '\n' && B.get buf (len - 1) = '\n' then
- return (Some buf)
- else
- read (offset + k) (remain - k) in
- lwt res = read 0 siz in
- return res
-
-let parse_postfix_attrs fd =
- match_lwt read_postfix_attrs fd with
- | None ->
- return None
- | Some buf ->
- let lines = Str.split (Str.regexp "\n") (B.to_string buf) in
- return (Postfix.parse_lines lines)
-
let spf_handler fd =
let spf_server = Spf.server Spf.Dns_cache in
- match_lwt parse_postfix_attrs fd with
+ match_lwt Postfix.parse_attrs fd with
| None ->
return ()
| Some attrs ->
lwt action = Policy.handle_attrs spf_server attrs in
- Release_io.write fd (B.of_string (sprintf "action=%s\n\n" action))
+ let reply = sprintf "action=%s\n\n" action in
+ Release_io.write fd (Release_buffer.of_string reply)
let main fd =
ignore (Lwt_unix.on_signal Sys.sigterm handle_sigterm);

0 comments on commit aaecd1a

Please sign in to comment.
Something went wrong with that request. Please try again.