Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.options
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ INCS= -I ${BLD}/server/.ocsigenserver.objs/byte \
## ${SERVER_PACKAGE} is not only used to build the 'ocsigenserver' executable
## but also to generate src/baselib/ocsigen_config_static.ml

SERVER_PACKAGE := lwt_ssl,bytes,lwt.unix,lwt_log,ipaddr,findlib,cryptokit,re,str,xml-light,dynlink,cohttp-lwt-unix
SERVER_PACKAGE := lwt_ssl,bytes,lwt.unix,logs,logs-syslog,syslog-message,ipaddr,findlib,cryptokit,re,str,xml-light,dynlink,cohttp-lwt-unix

LIBS := -package ${SERVER_PACKAGE} ${INCS}
3 changes: 2 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ check_library lwt "See: http://ocsigen.org/lwt"
check_library lwt.unix "Missing support for 'unix' in lwt."
check_library lwt_react "See: http://ocsigen.org/lwt"
check_library lwt_ssl "See: http://ocsigen.org/lwt"
check_library lwt_log "See: http://ocsigen.org/lwt"
check_library logs ""
check_library logs-syslog "Missing syslog support."

check_library re "See: https://github.com/ocaml/ocaml-re/"
check_library cryptokit "See: http://pauillac.inria.fr/~xleroy/software.html#cryptokit"
Expand Down
6 changes: 4 additions & 2 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
cryptokit
(ipaddr (>= 2.1))
(lwt (>= 3.0))
lwt_log
lwt_react
lwt_ssl
ocamlfind
(re (>= 1.11))
react
(ssl (>= 0.5.8))
xml-light)
xml-light
logs
logs-syslog
syslog-message)
(conflicts
(pgocaml (< 2.2))))
4 changes: 3 additions & 1 deletion ocsigenserver.opam
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ depends: [
"cryptokit"
"ipaddr" {>= "2.1"}
"lwt" {>= "3.0"}
"lwt_log"
"lwt_react"
"lwt_ssl"
"ocamlfind"
"re" {>= "1.11"}
"react"
"ssl" {>= "0.5.8"}
"xml-light"
"logs"
"logs-syslog"
"syslog-message"
"odoc" {with-doc}
]
conflicts: [
Expand Down
2 changes: 1 addition & 1 deletion src/baselib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
(libraries
str
findlib
lwt_log
lwt.unix
cryptokit
re
ocsigen_lib_base
logs
(select
dynlink_wrapper.ml
from
Expand Down
31 changes: 18 additions & 13 deletions src/baselib/ocsigen_loader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ open Ocsigen_lib
exception Dynlink_error of string * exn
exception Findlib_error of string * exn

let section = Lwt_log.Section.make "ocsigen:dynlink"
let section = Logs.Src.create "ocsigen:dynlink"

(************************************************************************)

Expand Down Expand Up @@ -68,22 +68,23 @@ let loadfile pre post force file =
if force
then (
pre ();
Lwt_log.ign_info_f ~section "Loading %s (will be reloaded every times)"
file;
Logs.info ~src:section (fun fmt ->
fmt "Loading %s (will be reloaded every times)" file);
try
Dynlink_wrapper.loadfile file;
post ()
with e -> post (); raise e)
else if not (isloaded file)
then (
pre ();
Lwt_log.ign_info_f ~section "Loading extension %s" file;
Logs.info ~src:section (fun fmt -> fmt "Loading extension %s" file);
(try
Dynlink_wrapper.loadfile file;
post ()
with e -> post (); raise e);
addloaded file)
else Lwt_log.ign_info_f ~section "Extension %s already loaded" file
else
Logs.info ~src:section (fun fmt -> fmt "Extension %s already loaded" file)
with e -> raise (Dynlink_error (file, e))

let id () = ()
Expand Down Expand Up @@ -114,22 +115,25 @@ let init_module pre post force name =
let l = List.rev @@ M.find name !init_functions in
fun () -> List.iter (fun f -> f ()) l
with Not_found ->
Lwt_log.ign_info_f ~section "No init function for named module %s." name;
Logs.info ~src:section (fun fmt ->
fmt "No init function for named module %s." name);
fun () -> ()
in
if force
then (
pre ();
Lwt_log.ign_info_f ~section
"Initializing %s (will be initialized every time)" name;
Logs.info ~src:section (fun fmt ->
fmt "Initializing %s (will be initialized every time)" name);
try f (); post () with e -> post (); raise e)
else if not (isloaded name)
then (
pre ();
Lwt_log.ign_info_f ~section "Initializing module %s " name;
Logs.info ~src:section (fun fmt -> fmt "Initializing module %s " name);
(try f (); post () with e -> post (); raise e);
addloaded name)
else Lwt_log.ign_info_f ~section "Module %s already initialized." name
else
Logs.info ~src:section (fun fmt ->
fmt "Module %s already initialized." name)

(************************************************************************)
(* Manipulating Findlib's search path *)
Expand Down Expand Up @@ -170,8 +174,8 @@ let findfiles =
not @@ String.Set.mem a Ocsigen_config_static.builtin_packages)
(Findlib.package_deep_ancestors preds [package])
in
Lwt_log.ign_info_f ~section "Dependencies of %s: %s" package
(String.concat ", " deps);
Logs.info ~src:section (fun fmt ->
fmt "Dependencies of %s: %s" package (String.concat ", " deps));
let rec aux = function
| [] -> []
| a :: q ->
Expand All @@ -189,7 +193,8 @@ let findfiles =
List.map (Findlib.resolve_path ~base) mods @ aux q
in
let res = aux deps in
Lwt_log.ign_info_f ~section "Needed: %s" (String.concat ", " res);
Logs.info ~src:section (fun fmt ->
fmt "Needed: %s" (String.concat ", " res));
res
with e -> raise (Findlib_error (package, e))

Expand Down
3 changes: 1 addition & 2 deletions src/baselib/ocsigen_loader.mli
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
exception Dynlink_error of string * exn
exception Findlib_error of string * exn

val section : Lwt_log_core.section
(** use Lwt_log.Section.set_level in order to debug *)
val section : Logs.src

val translate : string -> string
(** [translate filename] translate .cmo/.cma extensions to .cmxs in
Expand Down
92 changes: 53 additions & 39 deletions src/extensions/accesscontrol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
open Ocsigen_lib
open Xml

let section = Lwt_log.Section.make "ocsigen:ext:access-control"
let section = Logs.Src.create "ocsigen:ext:access-control"

type condition = Ocsigen_request.t -> bool

Expand All @@ -41,30 +41,28 @@ let ip s =
let r = Ipaddr.Prefix.mem (Ocsigen_request.remote_ip_parsed ri) prefix in
if r
then
Lwt_log.ign_info_f ~section "IP: %a matches %s"
(fun () -> Ocsigen_request.remote_ip)
ri s
Logs.info ~src:section (fun fmt ->
fmt "IP: %s matches %s" (Ocsigen_request.remote_ip ri) s)
else
Lwt_log.ign_info_f ~section "IP: %a does not match %s"
(fun () -> Ocsigen_request.remote_ip)
ri s;
Logs.info ~src:section (fun fmt ->
fmt "IP: %s does not match %s" (Ocsigen_request.remote_ip ri) s);
r

let port port ri =
let r = Ocsigen_request.port ri = port in
if r
then Lwt_log.ign_info_f ~section "PORT = %d: true" port
then Logs.info ~src:section (fun fmt -> fmt "PORT = %d: true" port)
else
Lwt_log.ign_info_f ~section "PORT = %d: false (it is %a)" port
(fun () ri -> string_of_int (Ocsigen_request.port ri))
ri;
Logs.info ~src:section (fun fmt ->
fmt "PORT = %d: false (it is %s)" port
(string_of_int (Ocsigen_request.port ri)));
r

let ssl ri =
let r = Ocsigen_request.ssl ri in
if r
then Lwt_log.ign_info ~section "SSL: true"
else Lwt_log.ign_info ~section "SSL: false";
then Logs.info ~src:section (fun fmt -> fmt "SSL: true")
else Logs.info ~src:section (fun fmt -> fmt "SSL: false");
r

let header ~name ~regexp:re =
Expand All @@ -79,12 +77,15 @@ let header ~name ~regexp:re =
List.exists
(fun a ->
let r = Netstring_pcre.string_match regexp a 0 <> None in
if r then Lwt_log.ign_info_f "HEADER: header %s matches %S" name re;
if r
then
Logs.info (fun fmt -> fmt "HEADER: header %s matches %S" name re);
r)
(Ocsigen_request.header_multi ri (Ocsigen_header.Name.of_string name))
in
if not r
then Lwt_log.ign_info_f "HEADER: header %s does not match %S" name re;
then
Logs.info (fun fmt -> fmt "HEADER: header %s does not match %S" name re);
r

let method_ m ri =
Expand All @@ -93,8 +94,9 @@ let method_ m ri =
let s' = Cohttp.Code.string_of_method m' in
let r = m = m' in
if r
then Lwt_log.ign_info_f ~section "METHOD: %s matches %s" s' s
else Lwt_log.ign_info_f ~section "METHOD: %s does not match %s" s' s;
then Logs.info ~src:section (fun fmt -> fmt "METHOD: %s matches %s" s' s)
else
Logs.info ~src:section (fun fmt -> fmt "METHOD: %s does not match %s" s' s);
r

let protocol v ri =
Expand All @@ -103,8 +105,10 @@ let protocol v ri =
let s' = Cohttp.Code.string_of_version v' in
let r = v = v' in
if r
then Lwt_log.ign_info_f ~section "PROTOCOL: %s matches %s" s' s
else Lwt_log.ign_info_f ~section "PROTOCOL: %s does not match %s" s' s;
then Logs.info ~src:section (fun fmt -> fmt "PROTOCOL: %s matches %s" s' s)
else
Logs.info ~src:section (fun fmt ->
fmt "PROTOCOL: %s does not match %s" s' s);
r

let path ~regexp:s =
Expand All @@ -118,8 +122,10 @@ let path ~regexp:s =
let sps = Ocsigen_request.sub_path_string ri in
let r = Netstring_pcre.string_match regexp sps 0 <> None in
if r
then Lwt_log.ign_info_f ~section "PATH: \"%s\" matches %S" sps s
else Lwt_log.ign_info_f ~section "PATH: \"%s\" does not match %S" sps s;
then Logs.info ~src:section (fun fmt -> fmt "PATH: \"%s\" matches %S" sps s)
else
Logs.info ~src:section (fun fmt ->
fmt "PATH: \"%s\" does not match %S" sps s);
r

let and_ sub ri = List.for_all (fun cond -> cond ri) sub
Expand Down Expand Up @@ -167,8 +173,12 @@ let rec parse_condition = function
let sps = Ocsigen_request.sub_path_string ri in
let r = Netstring_pcre.string_match regexp sps 0 <> None in
if r
then Lwt_log.ign_info_f ~section "PATH: \"%s\" matches %S" sps s
else Lwt_log.ign_info_f ~section "PATH: \"%s\" does not match %S" sps s;
then
Logs.info ~src:section (fun fmt ->
fmt "PATH: \"%s\" matches %S" sps s)
else
Logs.info ~src:section (fun fmt ->
fmt "PATH: \"%s\" does not match %S" sps s);
r
| Element (("path" as s), _, _) ->
Ocsigen_extensions.badconfig "Bad syntax for tag %s" s
Expand All @@ -192,11 +202,11 @@ let rec parse_condition = function
(*****************************************************************************)
(* Parsing filters *)

let comma_space_regexp = Netstring_pcre.regexp "\ *,\ *"
let comma_space_regexp = Netstring_pcre.regexp " *, *"

let allow_forward_for_handler ?(check_equal_ip = false) () =
let apply ({Ocsigen_extensions.request_info; _} as request) code =
Lwt_log.ign_info ~section "Allowed proxy";
Logs.info ~src:section (fun fmt -> fmt "Allowed proxy");
let request =
let header =
Ocsigen_request.header request_info Ocsigen_header.Name.x_forwarded_for
Expand All @@ -218,14 +228,15 @@ let allow_forward_for_handler ?(check_equal_ip = false) () =
~remote_ip:original_ip request_info }
else (
(* the announced ip of the proxy is not its real ip *)
Lwt_log.ign_warning_f ~section
"X-Forwarded-For: host ip (%s) does not match the header (%s)"
(Ocsigen_request.remote_ip request_info)
header;
Logs.warn ~src:section (fun fmt ->
fmt
"X-Forwarded-For: host ip (%s) does not match the header (%s)"
(Ocsigen_request.remote_ip request_info)
header);
request)
| _ ->
Lwt_log.ign_info_f ~section "Malformed X-Forwarded-For field: %s"
header;
Logs.info ~src:section (fun fmt ->
fmt "Malformed X-Forwarded-For field: %s" header);
request)
| None -> request
in
Expand All @@ -240,7 +251,7 @@ let allow_forward_for_handler ?(check_equal_ip = false) () =

let allow_forward_proto_handler =
let apply ({Ocsigen_extensions.request_info; _} as request) code =
Lwt_log.ign_info ~section "Allowed proxy for ssl";
Logs.info ~src:section (fun fmt -> fmt "Allowed proxy for ssl");
let request_info =
let header =
Ocsigen_request.header request_info
Expand All @@ -252,8 +263,8 @@ let allow_forward_proto_handler =
| "http" -> Ocsigen_request.update ~ssl:false request_info
| "https" -> Ocsigen_request.update ~ssl:true request_info
| _ ->
Lwt_log.ign_info_f ~section "Malformed X-Forwarded-Proto field: %s"
header;
Logs.info ~src:section (fun fmt ->
fmt "Malformed X-Forwarded-Proto field: %s" header);
request_info)
| None -> request_info
in
Expand Down Expand Up @@ -292,17 +303,19 @@ let parse_config parse_fun = function
Lwt.return
(if condition ri.Ocsigen_extensions.request_info
then (
Lwt_log.ign_info ~section "COND: going into <then> branch";
Logs.info ~src:section (fun fmt ->
fmt "COND: going into <then> branch");
Ocsigen_extensions.Ext_sub_result ithen)
else (
Lwt_log.ign_info ~section
"COND: going into <else> branch, if any";
Logs.info ~src:section (fun fmt ->
fmt "COND: going into <else> branch, if any");
Ocsigen_extensions.Ext_sub_result ielse)))
| Element (("if" as s), _, _) ->
Ocsigen_extensions.badconfig "Bad syntax for tag %s" s
| Element ("notfound", [], []) ->
fun _rs ->
Lwt_log.ign_info ~section "NOT_FOUND: taking in charge 404";
Logs.info ~src:section (fun fmt ->
fmt "NOT_FOUND: taking in charge 404");
Lwt.return
(Ocsigen_extensions.Ext_stop_all (Ocsigen_cookie_map.empty, `Not_found))
| Element (("notfound" as s), _, _) ->
Expand Down Expand Up @@ -340,7 +353,8 @@ let parse_config parse_fun = function
Ocsigen_extensions.badconfig "Bad syntax for tag %s" s
| Xml.Element ("forbidden", [], []) ->
fun _rs ->
Lwt_log.ign_info ~section "FORBIDDEN: taking in charge 403";
Logs.info ~src:section (fun fmt ->
fmt "FORBIDDEN: taking in charge 403");
Lwt.return
(Ocsigen_extensions.Ext_stop_all (Ocsigen_cookie_map.empty, `Forbidden))
| Element (("forbidden" as s), _, _) ->
Expand Down
4 changes: 1 addition & 3 deletions src/extensions/accesscontrol.mli
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,4 @@ val allow_forward_for :
-> Ocsigen_server.instruction

val allow_forward_proto : unit -> Ocsigen_server.instruction

val section : Lwt_log_core.section
(** Use Lwt_log.Section.set_level in order to change the log level *)
val section : Logs.src
Loading