Skip to content

Commit

Permalink
Static linking: new interface in Ocsigen_server
Browse files Browse the repository at this point in the history
Removing Ocsigen_server.Site.register and compose instructions instead
  • Loading branch information
balat committed May 10, 2024
1 parent be06ab6 commit fa82042
Show file tree
Hide file tree
Showing 21 changed files with 152 additions and 217 deletions.
5 changes: 1 addition & 4 deletions src/extensions/authbasic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,4 @@ let () =
()

(** Instruction for static linking without config file: *)
let instruction ~realm ~auth () _ _ _ = gen ~realm ~auth

let run ?site ~realm ~auth () =
Ocsigen_server.Site.register ?site (instruction ~realm ~auth ())
let run ~realm ~auth () _ _ _ = gen ~realm ~auth
9 changes: 2 additions & 7 deletions src/extensions/authbasic.mli
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,8 @@ val register_basic_authentication_method : (Xml.xml -> auth) -> unit
from the point of view of plugin developers and is totally
transparent to the plugin. *)

val run :
?site:Ocsigen_server.Site.t
-> realm:string
-> auth:auth
-> unit
-> unit
(** [run ~realm ~auth ()] makes it possible to use this extension without
val run : realm:string -> auth:auth -> unit -> Ocsigen_server.instruction
(** [run ~realm ~auth ()] makes it possible to use this extension without
configuration file. *)

(**/**)
Expand Down
6 changes: 1 addition & 5 deletions src/extensions/cors.ml
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,7 @@ let () =
~fun_site:(fun _ _ _ -> parse_config)
()

let instruction ?credentials ?max_age ?exposed_headers ?methods () _ _ _ =
let run ?credentials ?max_age ?exposed_headers ?methods () _ _ _ =
let credentials = Ocsigen_lib.Option.get' false credentials in
let exposed_headers = Ocsigen_lib.Option.get' [] exposed_headers in
main {credentials; methods; max_age; exposed_headers}

let run ?site ?credentials ?max_age ?exposed_headers ?methods () =
Ocsigen_server.Site.register ?site
(instruction ?credentials ?max_age ?exposed_headers ?methods ())
5 changes: 2 additions & 3 deletions src/extensions/cors.mli
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
val run :
?site:Ocsigen_server.Site.t
-> ?credentials:bool
?credentials:bool
-> ?max_age:int
-> ?exposed_headers:string list
-> ?methods:Cohttp.Code.meth list
-> unit
-> unit
-> Ocsigen_server.instruction
5 changes: 1 addition & 4 deletions src/extensions/deflatemod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,4 @@ let () =
~fun_site:(fun _ _ _ _ _ _ -> parse_config)
~init_fun:parse_global_config ()

let instruction ~mode () _ _ _ = filter mode

let run ?site ~mode () =
Ocsigen_server.Site.register ?site (instruction ~mode ())
let run ~mode () _ _ _ = filter mode
5 changes: 2 additions & 3 deletions src/extensions/deflatemod.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ val set_buffer_size : int -> unit
type filter = [`Type of string option * string option | `Extension of string]

val run :
?site:Ocsigen_server.Site.t
-> mode:[`All_but of filter list | `Only of filter list]
-> unit
mode:[`All_but of filter list | `Only of filter list]
-> unit
-> Ocsigen_server.instruction
5 changes: 1 addition & 4 deletions src/extensions/outputfilter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,5 @@ let () =
~fun_site:(fun _ _ _ _ _ _ -> parse_config)
()

let instruction ~mode () _ _ _ =
let run ~mode () _ _ _ =
match mode with `Code c -> gen_code c | #header_filter as f -> gen f

let run ?site ~mode () =
Ocsigen_server.Site.register ?site (instruction ~mode ())
11 changes: 5 additions & 6 deletions src/extensions/outputfilter.mli
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
val run :
?site:Ocsigen_server.Site.t
-> mode:
[ `Rewrite of Ocsigen_header.Name.t * Re.Pcre.regexp * string
| `Add of Ocsigen_header.Name.t * string * bool option
| `Code of Cohttp.Code.status ]
-> unit
mode:
[ `Rewrite of Ocsigen_header.Name.t * Re.Pcre.regexp * string
| `Add of Ocsigen_header.Name.t * string * bool option
| `Code of Cohttp.Code.status ]
-> unit
-> Ocsigen_server.instruction
5 changes: 1 addition & 4 deletions src/extensions/redirectmod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,4 @@ let () =
~fun_site:(fun _ _ _ _ _ _ -> parse_config)
()

let instruction ~redirection () _ _ _ = gen redirection

let run ?site ~redirection () =
Ocsigen_server.Site.register ?site (instruction ~redirection ())
let run ~redirection () _ _ _ = gen redirection
2 changes: 1 addition & 1 deletion src/extensions/redirectmod.mli
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ val create_redirection :
-> string
-> redirection

val run : ?site:Ocsigen_server.Site.t -> redirection:redirection -> unit -> unit
val run : redirection:redirection -> unit -> Ocsigen_server.instruction
5 changes: 1 addition & 4 deletions src/extensions/revproxy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,4 @@ let () =
when sending to extensions! *)
()

let instruction ~redirection () _ _ _ = gen redirection

let run ?site ~redirection () =
Ocsigen_server.Site.register ?site (instruction ~redirection ())
let run ~redirection () _ _ _ = gen redirection
2 changes: 1 addition & 1 deletion src/extensions/revproxy.mli
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ val create_redirection :
-> string
-> redirection

val run : ?site:Ocsigen_server.Site.t -> redirection:redirection -> unit -> unit
val run : redirection:redirection -> unit -> Ocsigen_server.instruction
8 changes: 1 addition & 7 deletions src/extensions/rewritemod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,10 @@ let () =
~fun_site:(fun _ _ _ _ _ _ -> parse_config)
()

let instruction ?(continue = false) ?(full_rewrite = false) ~regexp dest () _ _
_
=
let run ?(continue = false) ?(full_rewrite = false) ~regexp dest () _ _ _ =
gen
(Regexp
( Ocsigen_lib.Netstring_pcre.regexp ("^" ^ regexp ^ "$")
, dest
, full_rewrite ))
continue

let run ?site ?continue ?full_rewrite ~regexp dest () =
Ocsigen_server.Site.register ?site
(instruction ?continue ?full_rewrite ~regexp dest ())
5 changes: 2 additions & 3 deletions src/extensions/rewritemod.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ val section : Lwt_log_core.section
(** use Lwt_log.Section.set_level in order to debug *)

val run :
?site:Ocsigen_server.Site.t
-> ?continue:bool
?continue:bool
-> ?full_rewrite:bool
-> regexp:string
-> string
-> unit
-> unit
-> Ocsigen_server.instruction
6 changes: 1 addition & 5 deletions src/extensions/staticmod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ let () =
(* Registration for static linking: *)
let preprocess s = "^" ^ s ^ "$"

let instruction ?dir ?regexp ?dest ?code ?cache ?root () =
let run ?dir ?regexp ?dest ?code ?cache ?root () =
let kind =
kind dir
(Ocsigen_lib.Option.map (fun x -> Pcre.regexp (preprocess x)) regexp)
Expand All @@ -296,7 +296,3 @@ let instruction ?dir ?regexp ?dest ?code ?cache ?root () =
root)
in
fun _ _ _ -> gen ~usermode:None ?cache kind

let run ?site ?dir ?regexp ?dest ?code ?cache ?root () =
Ocsigen_server.Site.register ?site
(instruction ?dir ?regexp ?dest ?code ?cache ?root ())
5 changes: 2 additions & 3 deletions src/extensions/staticmod.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ val section : Lwt_log_core.section
(** use Lwt_log.Section.set_level in order to debug *)

val run :
?site:Ocsigen_server.Site.t
-> ?dir:string
?dir:string
-> ?regexp:string
-> ?dest:string
-> ?code:string
-> ?cache:int
-> ?root:string
-> unit
-> unit
-> Ocsigen_server.instruction
(** Run static mod on a specific directory.
Call this if you want to run Ocsigen Server without configuration file. *)
2 changes: 1 addition & 1 deletion src/ocsigenserver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ let () =
"usage: ocsigenserver [-c configfile]"
with Arg.Help s -> print_endline s; exit 0

let () = Ocsigen_server.start ~config:(Ocsigen_parseconfig.parse_config ()) ()
let () = Ocsigen_server.exec (Ocsigen_parseconfig.parse_config ())
4 changes: 2 additions & 2 deletions src/server/ocsigen_extensions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ type parse_fun = Xml.xml list -> extension_composite
type parse_host =
| Parse_host of (Url.path -> parse_host -> parse_fun -> Xml.xml -> extension)

let hosts : (virtual_hosts * config_info * extension_composite) list ref =
ref []
type host_config = virtual_hosts * config_info * extension_composite

let hosts : host_config list ref = ref []
let set_hosts v = hosts := v
let get_hosts () = !hosts

Expand Down
8 changes: 5 additions & 3 deletions src/server/ocsigen_extensions.mli
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ val site_ext :
-> Ocsigen_lib.Url.path
-> extension

val set_hosts : (virtual_hosts * config_info * extension_composite) list -> unit
type host_config = virtual_hosts * config_info * extension_composite

val set_hosts : host_config list -> unit
val get_hosts : unit -> (virtual_hosts * config_info * extension_composite) list

val compute_result :
Expand All @@ -416,9 +418,9 @@ val compute_result :
(** Compute the answer to be sent to the client, by trying all
extensions according the configuration file. *)

val get_number_of_connected : unit -> int
(** Profiling *)
(** {3 Profiling} *)

val get_number_of_connected : unit -> int
val during_initialisation : unit -> bool
val start_initialisation : unit -> unit
val end_initialisation : unit -> unit
Expand Down
Loading

0 comments on commit fa82042

Please sign in to comment.