Skip to content
This repository
tag: v1853
Fetching contributors…

Cannot retrieve contributors at this time

file 85 lines (62 sloc) 2.04 kb
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
(*
Copyright © 2011 MLstate

This file is part of OPA.

OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.

OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.

You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)

module A = ServerArg

type dialog = Scheduler.t -> HttpServerTypes.web_info -> unit

type t = {
  body : dialog Lazy.t;
  allowed : (Unix.inet_addr -> bool) ;
  content : (string -> int -> int -> unit) ;
  url_prefix : string
}

type options = {
  opt_allowed : Unix.inet_addr -> bool;
  dialog_name : string;
  dialog : unit -> dialog;
  opt_url_prefix : string;
}

type port = {
  set_dialog : t -> unit
}


let name = "httpDialog"
let version = "1.0"

let null_dialog = Obj.magic None

let default_options = {
  opt_allowed = (fun _ -> true);
  dialog_name = "default";
  dialog = null_dialog;
  opt_url_prefix = "";
}

let options_with_dialog dialog =
  {default_options with dialog = dialog}

let spec_args _name = []

let make _name opt _sched =
  if opt.dialog == null_dialog then begin
    Logger.error "No dialog provided"; exit 1
  end;
  {
    body = Lazy.lazy_from_fun opt.dialog;
    allowed = opt.opt_allowed ;
    url_prefix = opt.opt_url_prefix ;
    content = (fun _url _total _current -> ()) ;
  }

let get_ports _ _ = []

let get_description http_dialog _sched =
  `HttpDialog http_dialog

let run http_dialog _ = http_dialog

let close _ _ = ()

let body http_dialog sched winfo =
  (Lazy.force http_dialog.body) sched winfo

let content http_dialog = http_dialog.content

let is_allowed http_dialog conn =
  http_dialog.allowed (Scheduler.get_connection_inet_addr conn)
Something went wrong with that request. Please try again.