diff --git a/.ocamlformat b/.ocamlformat index a84459a472..7f5bf133b6 100644 --- a/.ocamlformat +++ b/.ocamlformat @@ -1,34 +1,17 @@ -version=0.28.1 +version=0.29.0 parse-docstrings = false wrap-comments = false -break-cases = fit -break-collection-expressions = fit-or-vertical -break-fun-decl = wrap -break-fun-sig = wrap -break-infix = wrap -break-infix-before-func = false break-sequences = false break-separators = before break-string-literals = never -break-struct = force cases-matching-exp-indent = compact -doc-comments = after-when-possible dock-collection-brackets = false -indicate-multiline-delimiters = no -infix-precedence = indent -let-and = compact -let-binding-spacing = compact -module-item-spacing = compact parens-tuple = multi-line-only -parens-tuple-patterns = multi-line-only -sequence-style = terminator sequence-blank-line = compact -single-case = compact -type-decl = compact if-then-else = keyword-first -field-space = loose space-around-arrays = false space-around-records = false space-around-lists = false space-around-variants = false -ocp-indent-compat = true +function-indent-nested = always +indicate-multiline-delimiters = closing-on-separate-line diff --git a/build/build.ml b/build/build.ml index 44995935d4..4df031afb0 100644 --- a/build/build.ml +++ b/build/build.ml @@ -15,7 +15,8 @@ module Intern = struct Some (function | `Client -> "src/ppx/ppx_eliom_client_ex." ^ best - | `Server -> "src/ppx/ppx_eliom_server_ex." ^ best) + | `Server -> "src/ppx/ppx_eliom_server_ex." ^ best + ) let with_package = function | "eliom.ppx.type" -> "pkg_ppx_eliom_types" @@ -35,8 +36,8 @@ let _ = Doc.init (); let link source dest = rule (Printf.sprintf "%s -> %s" source dest) ~dep:source ~prod:dest - (fun env _ -> - Cmd (S [A "ln"; A "-f"; P (env source); P (env dest)])) + (fun env _ -> Cmd (S [A "ln"; A "-f"; P (env source); P (env dest)]) + ) in (* add I pflag *) pflag ["ocaml"; "compile"] "I" (fun x -> S [A "-I"; A x]); @@ -51,18 +52,24 @@ let _ = ["ocaml"; "compile"; "pkg_" ^ name] (S [ A "-ppx" - ; Quote (S [P (path ^ name ^ "_ex." ^ best); A "-as-ppx"]) ]); + ; Quote (S [P (path ^ name ^ "_ex." ^ best); A "-as-ppx"]) + ] + ); flag ["ocaml"; "ocamldep"; "pkg_" ^ name] (S [ A "-ppx" - ; Quote (S [P (path ^ name ^ "_ex." ^ best); A "-as-ppx"]) ]); + ; Quote (S [P (path ^ name ^ "_ex." ^ best); A "-as-ppx"]) + ] + ); dep ["ocaml"; "ocamldep"; "pkg_" ^ name] [path ^ name ^ "_ex." ^ best]; flag_and_dep ["ocaml"; "infer_interface"; "pkg_" ^ name] (S [ A "-ppx" - ; Quote (S [P (path ^ name ^ "_ex." ^ best); A "-as-ppx"]) ]); + ; Quote (S [P (path ^ name ^ "_ex." ^ best); A "-as-ppx"]) + ] + ); dep ["ocaml"; "infer_interface"; "pkg_" ^ name] [path ^ name ^ "_ex." ^ best]; @@ -70,7 +77,9 @@ let _ = ["doc"; "pkg_" ^ name] (S [ A "-ppx" - ; Quote (S [P (path ^ name ^ "_ex." ^ best); A "-as-ppx"]) ]); + ; Quote (S [P (path ^ name ^ "_ex." ^ best); A "-as-ppx"]) + ] + ); dep ["doc"; "pkg_" ^ name] [path ^ name ^ "_ex." ^ best] in add_syntax "ppx_eliom_utils" "src/ppx/"; @@ -86,7 +95,8 @@ let _ = in List.iter (link_exec "eliomc") ["eliomopt"; "eliomcp"; "js_of_eliom"]; link_exec "distillery" "eliom-distillery" - | _ -> ()) + | _ -> () + ) let _ = Options.make_links := false; diff --git a/build/doc.ml b/build/doc.ml index 9ffdc744cd..d505ce3164 100644 --- a/build/doc.ml +++ b/build/doc.ml @@ -32,11 +32,13 @@ let init_wikidoc () = ~stamp:"%.wikidocdir/wiki.stamp" ~dep:"%.odocl" (Ocamlbuild_pack.Ocaml_tools.document_ocaml_project ~ocamldoc:ocamldoc_wiki "%.odocl" "%.wikidocdir/index.wiki" - "%.wikidocdir"); + "%.wikidocdir" + ); flag ["wikidoc"] & S [A "-colorize-code"; A "-i"; A wikidoc_dir; A "-g"; A "odoc_wiki.cma"]; pflag ["wikidoc"] "subproject" (fun sub -> - S [A "-passopt"; A "-subproject"; A sub]) + S [A "-passopt"; A "-subproject"; A sub] + ) with Failure e -> () (* Silently fail if the package wikidoc isn't available *) @@ -46,12 +48,15 @@ let init_mandoc () = ~prod:"%.mandocdir/man.%(ext)" ~stamp:"%.mandocdir/man.%(ext).stamp" ~dep:"%.odocl" (Ocamlbuild_pack.Ocaml_tools.document_ocaml_project ~ocamldoc:ocamldoc_man - "%.odocl" "%.mandocdir/man.%(ext)" "%.mandocdir"); + "%.odocl" "%.mandocdir/man.%(ext)" "%.mandocdir" + ); pflag ["apiref"] "man_ext" (fun ext -> - S [A "-man-mini"; A "-man-section"; A ext; A "-man-suffix"; A ext]) + S [A "-man-mini"; A "-man-section"; A ext; A "-man-suffix"; A ext] + ) let init () = init_wikidoc (); init_mandoc (); (* ocamldoc intro *) - pflag_and_dep ["doc"] "with_intro" (fun f -> S [A "-intro"; P f]) + pflag_and_dep ["doc"] "with_intro" (fun f -> S [A "-intro"; P f] + ) diff --git a/pkg/build.ml b/pkg/build.ml old mode 100755 new mode 100644 index cad36985c3..ba9f213d4c --- a/pkg/build.ml +++ b/pkg/build.ml @@ -91,7 +91,8 @@ let () = "src/ppx/ppx_eliom_server" ; Pkg.bin ~auto:true ~dst:"ppx_eliom_client" "src/ppx/ppx_eliom_client_ex" ; Pkg.bin ~auto:true ~dst:"ppx_eliom_server" "src/ppx/ppx_eliom_server_ex" - ; Pkg.bin ~auto:true ~dst:"ppx_eliom_types" "src/ppx/ppx_eliom_types_ex" ] + ; Pkg.bin ~auto:true ~dst:"ppx_eliom_types" "src/ppx/ppx_eliom_types_ex" + ] (* CLIENT LIBS *) @ Pkg.lib ~dst:"client/client" ~exts:[".cma"] "src/lib/client/client" :: Pkg.lib ~dst:"client/eliom_client_main.cmo" @@ -102,7 +103,8 @@ let () = :: Pkg.stublibs "src/lib/client/dlleliom_stubs.so" :: List.map (fun x -> - Pkg.lib ~dst:(spf "client/%s" x) (spf "src/lib/client/%s" x)) + Pkg.lib ~dst:(spf "client/%s" x) (spf "src/lib/client/%s" x) + ) client_extra (* SERVER LIBS *) @ Pkg.lib ~dst:"server/monitor/eliom_monitor" ~exts:Exts.module_library @@ -112,19 +114,25 @@ let () = :: Pkg.lib ~dst:"server/server" ~exts:exts_lib "src/lib/server/server" :: List.map (fun x -> - Pkg.lib ~dst:(spf "server/%s" x) (spf "src/lib/server/%s" x)) + Pkg.lib ~dst:(spf "server/%s" x) (spf "src/lib/server/%s" x) + ) server_extra @ [ (* MISC *) Pkg.doc "README.md" ; Pkg.doc "CHANGES" - ; Pkg.etc "pkg/etc/mime.types" ] + ; Pkg.etc "pkg/etc/mime.types" + ] @ List.flatten (List.map (fun (name, files) -> - List.map - (fun file -> - Pkg.lib - ~dst:(spf "templates/%s/%s" name file) - (spf "%s/%s/%s" templates_dir name file)) - files) - templates_files)) + List.map + (fun file -> + Pkg.lib + ~dst:(spf "templates/%s/%s" name file) + (spf "%s/%s/%s" templates_dir name file) + ) + files + ) + templates_files + ) + ) diff --git a/pkg/filelist.ml b/pkg/filelist.ml index d3601f5a90..82734c067c 100644 --- a/pkg/filelist.ml +++ b/pkg/filelist.ml @@ -8,7 +8,8 @@ let server = ; "eliom_parameter_sigs" ; "eliom_registration_sigs" ; "eliom_service_sigs" - ; "eliom_shared_sigs" ] + ; "eliom_shared_sigs" + ] ; interface = [ "eliom_bus" ; "eliom_client_value" @@ -34,7 +35,8 @@ let server = ; "eliom_tools" ; "eliom_types" ; "eliom_uri" - ; "eliom_wrap" ] + ; "eliom_wrap" + ] ; internal = [ "eliom_comet_base" ; "eliom_common_base" @@ -66,7 +68,9 @@ let server = ; "eliommod_sessadmin" ; "eliommod_sessexpl" ; "eliommod_sessiongroups" - ; "eliommod_timeouts" ] } + ; "eliommod_timeouts" + ] + } let client = { interface_only = @@ -75,7 +79,8 @@ let client = ; "eliom_parameter_sigs" ; "eliom_registration_sigs" ; "eliom_service_sigs" - ; "eliom_shared_sigs" ] + ; "eliom_shared_sigs" + ] ; interface = [ "eliom_bus" ; "eliom_client_value" @@ -96,7 +101,8 @@ let client = ; "eliom_tools" ; "eliom_types" ; "eliom_unwrap" - ; "eliom_uri" ] + ; "eliom_uri" + ] ; internal = [ "eliom_comet_base" ; "eliom_common" @@ -117,12 +123,15 @@ let client = ; "eliom_types_base" ; "eliommod_cookies" ; "eliommod_dom" - ; "eliommod_parameters" ] } + ; "eliommod_parameters" + ] + } let server_ext = { interface_only = [] ; interface = ["atom_feed"; "eliom_atom"; "eliom_openid"; "eliom_s2s"] - ; internal = [] } + ; internal = [] + } let ocamlbuild = {interface_only = []; interface = ["ocamlbuild_eliom"]; internal = []} @@ -131,7 +140,8 @@ let ppx = { interface_only = [] ; interface = ["ppx_eliom"; "ppx_eliom_client"; "ppx_eliom_type"; "ppx_eliom_server"] - ; internal = ["ppx_eliom_utils"] } + ; internal = ["ppx_eliom_utils"] + } let ( -.- ) name ext = name ^ "." ^ ext diff --git a/pkg/topkg.ml b/pkg/topkg.ml index 9bf11f5e25..e1f77d1ba8 100644 --- a/pkg/topkg.ml +++ b/pkg/topkg.ml @@ -45,7 +45,7 @@ module type Pkg = sig (** The type for install moves. *) type field = - ?cond:bool + ?cond:bool -> ?exts:string list -> ?dst:string -> ?target:string @@ -128,7 +128,8 @@ end = struct ignore (List.assoc key acc); err_mdef key with Not_found -> parse_env ((key, bool) :: acc) args - with Invalid_argument _ | Not_found | Exit -> err_parse arg) + with Invalid_argument _ | Not_found | Exit -> err_parse arg + ) | [] -> acc in match List.tl (Array.to_list Sys.argv) with @@ -174,7 +175,7 @@ module Pkg : Pkg = struct type moves = move list type field = - ?cond:bool + ?cond:bool -> ?exts:string list -> ?dst:string -> ?target:string @@ -235,8 +236,9 @@ module Pkg : Pkg = struct let l = List.filter (fun f -> has_suffix f s_suffix) l in List.map (fun s -> - ( str "%s/%s%s" bdir s_path s - , str "%s%s%s" d_path (Filename.chop_suffix s s_suffix) d_suffix )) + ( str "%s/%s%s" bdir s_path s + , str "%s%s%s" d_path (Filename.chop_suffix s s_suffix) d_suffix ) + ) l let build_install bdir mvs = @@ -251,8 +253,9 @@ module Pkg : Pkg = struct in List.iter (fun (src, dst) -> - Buffer.add_string install - (str "\n \"%s%s\" {\"%s\"}" option src dst)) + Buffer.add_string install + (str "\n \"%s%s\" {\"%s\"}" option src dst) + ) (list_files bdir src dst); add_mvs current mvs | {field_name = field} :: _ as mvs -> diff --git a/src/lib/client/eliommod_cookies.ml b/src/lib/client/eliommod_cookies.ml index 33900a74ed..2edb668b58 100644 --- a/src/lib/client/eliommod_cookies.ml +++ b/src/lib/client/eliommod_cookies.ml @@ -24,17 +24,16 @@ include Eliom_cookies_base (* CCC The tables are indexed by the hostname, not the port appear. there are no particular reason. If needed it is possible to add it *) let cookie_tables : - (float option * string * bool) Ocsigen_cookie_map.Map_inner.t + (float option * string * bool) Ocsigen_cookie_map.Map_inner.t Ocsigen_cookie_map.Map_path.t - Jstable.t - = + Jstable.t = Jstable.create () module Map (Ord : sig - type key [@@deriving json] + type key [@@deriving json] - val compare : key -> key -> int - end) = + val compare : key -> key -> int +end) = struct type 'a t = | Empty @@ -60,7 +59,8 @@ struct match lr with | Empty -> invalid_arg "Map.bal" | Node {l = lrl; v = lrv; d = lrd; r = lrr; _} -> - create (create ll lv ld lrl) lrv lrd (create lrr x d r)) + create (create ll lv ld lrl) lrv lrd (create lrr x d r) + ) else if hr > hl + 2 then match r with @@ -72,7 +72,8 @@ struct match rl with | Empty -> invalid_arg "Map.bal" | Node {l = rll; v = rlv; d = rld; r = rlr; _} -> - create (create l x d rll) rlv rld (create rlr rv rd rr)) + create (create l x d rll) rlv rld (create rlr rv rd rr) + ) else Node {l; v = x; d; r; h = (if hl >= hr then hl + 1 else hr + 1)} let rec add x data = function @@ -100,16 +101,16 @@ end [@@@warning "-39"] module Map_path = Map (struct - type key = string list [@@deriving json] + type key = string list [@@deriving json] - let compare = compare - end) + let compare = compare +end) module Map_inner = Map (struct - type key = string [@@deriving json] + type key = string [@@deriving json] - let compare = compare - end) + let compare = compare +end) [@@@warning "+39"] @@ -119,18 +120,21 @@ let json_cookies = let extern_cookies c = Ocsigen_cookie_map.Map_path.fold (fun path inner m -> - Map_path.add path - (Ocsigen_cookie_map.Map_inner.fold Map_inner.add inner Map_inner.empty) - m) + Map_path.add path + (Ocsigen_cookie_map.Map_inner.fold Map_inner.add inner Map_inner.empty) + m + ) c Map_path.empty let intern_cookies c = Map_path.fold (fun path inner m -> - Ocsigen_cookie_map.Map_path.add path - (Map_inner.fold Ocsigen_cookie_map.Map_inner.add inner - Ocsigen_cookie_map.Map_inner.empty) - m) + Ocsigen_cookie_map.Map_path.add path + (Map_inner.fold Ocsigen_cookie_map.Map_inner.add inner + Ocsigen_cookie_map.Map_inner.empty + ) + m + ) c Ocsigen_cookie_map.Map_path.empty (** [in_local_storage] implements cookie substitutes for iOS WKWebView *) @@ -144,11 +148,13 @@ let get_table ?(in_local_storage = false) = function Dom_html.window##.localStorage (fun () -> Ocsigen_cookie_map.Map_path.empty) (fun st -> - Js.Opt.case - st##(getItem host) - (fun () -> Ocsigen_cookie_map.Map_path.empty) - (fun v -> - intern_cookies (of_json ~typ:json_cookies (Js.to_string v)))) + Js.Opt.case + st##(getItem host) + (fun () -> Ocsigen_cookie_map.Map_path.empty) + (fun v -> + intern_cookies (of_json ~typ:json_cookies (Js.to_string v)) + ) + ) else Js.Optdef.get (Jstable.find cookie_tables (Js.string host)) @@ -166,8 +172,10 @@ let set_table ?(in_local_storage = false) host t = Dom_html.window##.localStorage (fun () -> ()) (fun st -> - st##(setItem host - (Js.string (to_json ~typ:json_cookies (extern_cookies t))))) + st##(setItem host + (Js.string (to_json ~typ:json_cookies (extern_cookies t))) + ) + ) else Jstable.add cookie_tables (Js.string host) t let now () = @@ -179,21 +187,26 @@ let update_cookie_table ?(in_local_storage = false) host cookies = let now = now () in Ocsigen_cookie_map.Map_path.iter (fun path table -> - Ocsigen_cookie_map.Map_inner.iter - (fun name -> function - | OSet (Some exp, _, _) when exp <= now -> - set_table ~in_local_storage host - (Ocsigen_cookie_map.Poly.remove ~path name - (get_table ~in_local_storage host)) - | OUnset -> - set_table ~in_local_storage host - (Ocsigen_cookie_map.Poly.remove ~path name - (get_table ~in_local_storage host)) - | OSet (exp, value, secure) -> - set_table ~in_local_storage host - (Ocsigen_cookie_map.Poly.add ~path name (exp, value, secure) - (get_table ~in_local_storage host))) - table) + Ocsigen_cookie_map.Map_inner.iter + (fun name -> function + | OSet (Some exp, _, _) when exp <= now -> + set_table ~in_local_storage host + (Ocsigen_cookie_map.Poly.remove ~path name + (get_table ~in_local_storage host) + ) + | OUnset -> + set_table ~in_local_storage host + (Ocsigen_cookie_map.Poly.remove ~path name + (get_table ~in_local_storage host) + ) + | OSet (exp, value, secure) -> + set_table ~in_local_storage host + (Ocsigen_cookie_map.Poly.add ~path name (exp, value, secure) + (get_table ~in_local_storage host) + ) + ) + table + ) cookies (** [in_local_storage] implements cookie substitutes for iOS WKWebView *) @@ -201,25 +214,28 @@ let get_cookies_to_send ?(in_local_storage = false) host https path = let now = now () in Ocsigen_cookie_map.Map_path.fold (fun cpath t cookies_to_send -> - if - Url.is_prefix_skip_end_slash - (Url.remove_slash_at_beginning cpath) - (Url.remove_slash_at_beginning path) - then - Ocsigen_cookie_map.Map_inner.fold - (fun name (exp, value, secure) cookies_to_send -> - match exp with - | Some exp when exp <= now -> - set_table ~in_local_storage host - (Ocsigen_cookie_map.Poly.remove ~path:cpath name - (get_table ~in_local_storage host)); - cookies_to_send - | _ -> - if (not secure) || https - then (name, value) :: cookies_to_send - else cookies_to_send) - t cookies_to_send - else cookies_to_send) + if + Url.is_prefix_skip_end_slash + (Url.remove_slash_at_beginning cpath) + (Url.remove_slash_at_beginning path) + then + Ocsigen_cookie_map.Map_inner.fold + (fun name (exp, value, secure) cookies_to_send -> + match exp with + | Some exp when exp <= now -> + set_table ~in_local_storage host + (Ocsigen_cookie_map.Poly.remove ~path:cpath name + (get_table ~in_local_storage host) + ); + cookies_to_send + | _ -> + if (not secure) || https + then (name, value) :: cookies_to_send + else cookies_to_send + ) + t cookies_to_send + else cookies_to_send + ) (get_table ~in_local_storage host) [] diff --git a/src/lib/client/eliommod_dom.ml b/src/lib/client/eliommod_dom.ml index 8d17b6fa94..71f58cef06 100644 --- a/src/lib/client/eliommod_dom.ml +++ b/src/lib/client/eliommod_dom.ml @@ -30,10 +30,8 @@ let iter_nodeList nodeList f = f (Js.Unsafe.get nodeList i) done -let iter_attrList - (attrList : Dom.attr Dom.namedNodeMap Js.t) - (f : Dom.attr Js.t -> unit) - = +let iter_attrList (attrList : Dom.attr Dom.namedNodeMap Js.t) + (f : Dom.attr Js.t -> unit) = for i = 0 to attrList##.length - 1 do (* Unsafe.get is ten time faster than nodeList##item. Is it the same for attrList ? *) @@ -100,37 +98,42 @@ let ancessor = let fast_select_request_nodes root = root##(querySelectorAll - (Js.string ("." ^ Eliom_runtime.RawXML.request_node_class))) + (Js.string ("." ^ Eliom_runtime.RawXML.request_node_class)) + ) let fast_select_nodes root = if !Eliom_config.debug_timings then Console.console##(time (Js.string "fast_select_nodes")); let a_nodeList : Dom_html.element Dom.nodeList Js.t = root##(querySelectorAll - (Js.string ("a." ^ Eliom_runtime.RawXML.ce_call_service_class))) + (Js.string ("a." ^ Eliom_runtime.RawXML.ce_call_service_class)) + ) in let a_nodeList : Dom_html.anchorElement Dom.nodeList Js.t = Js.Unsafe.coerce a_nodeList in let form_nodeList : Dom_html.element Dom.nodeList Js.t = root##(querySelectorAll - (Js.string ("form." ^ Eliom_runtime.RawXML.ce_call_service_class))) + (Js.string ("form." ^ Eliom_runtime.RawXML.ce_call_service_class)) + ) in let form_nodeList : Dom_html.formElement Dom.nodeList Js.t = Js.Unsafe.coerce form_nodeList in let process_node_nodeList = root##(querySelectorAll - (Js.string ("." ^ Eliom_runtime.RawXML.process_node_class))) + (Js.string ("." ^ Eliom_runtime.RawXML.process_node_class)) + ) in let closure_nodeList = root##(querySelectorAll - (Js.string - ("." ^ Eliom_runtime.RawXML.ce_registered_closure_class))) + (Js.string ("." ^ Eliom_runtime.RawXML.ce_registered_closure_class)) + ) in let attrib_nodeList = root##(querySelectorAll - (Js.string ("." ^ Eliom_runtime.RawXML.ce_registered_attr_class))) + (Js.string ("." ^ Eliom_runtime.RawXML.ce_registered_attr_class)) + ) in if !Eliom_config.debug_timings then Console.console##(timeEnd (Js.string "fast_select_nodes")); @@ -192,23 +195,30 @@ let slow_has_request_class (node : Dom_html.element Js.t) = let fast_has_classes (node : Dom_html.element Js.t) = ( Js.to_bool node##.classList##(contains - (Js.string Eliom_runtime.RawXML.ce_call_service_class)) + (Js.string Eliom_runtime.RawXML.ce_call_service_class) + ) , Js.to_bool node##.classList##(contains - (Js.string Eliom_runtime.RawXML.process_node_class)) + (Js.string Eliom_runtime.RawXML.process_node_class) + ) , Js.to_bool node##.classList##(contains (Js.string - Eliom_runtime.RawXML.ce_registered_closure_class)) + Eliom_runtime.RawXML.ce_registered_closure_class + ) + ) , Js.to_bool node##.classList##(contains (Js.string - Eliom_runtime.RawXML.ce_registered_attr_class)) ) + Eliom_runtime.RawXML.ce_registered_attr_class + ) + ) ) let fast_has_request_class (node : Dom_html.element Js.t) = Js.to_bool node##.classList##(contains - (Js.string Eliom_runtime.RawXML.request_node_class)) + (Js.string Eliom_runtime.RawXML.request_node_class) + ) let has_classes : Dom_html.element Js.t -> bool * bool * bool * bool = if test_classList () then fast_has_classes else slow_has_classes @@ -240,14 +250,15 @@ let slow_select_nodes (root : Dom_html.element Js.t) = | Dom.ELEMENT -> let node = (Js.Unsafe.coerce node : Dom_html.element Js.t) in let call_service, process_node, closure, attrib = has_classes node in - (if call_service - then - match Dom_html.tagged node with - | Dom_html.A e -> ignore a_array##(push e) - | Dom_html.Form e -> ignore form_array##(push e) - | _ -> - raise_error ~section "%s element tagged as eliom link" - (Js.to_string node##.tagName)); + ( if call_service + then + match Dom_html.tagged node with + | Dom_html.A e -> ignore a_array##(push e) + | Dom_html.Form e -> ignore form_array##(push e) + | _ -> + raise_error ~section "%s element tagged as eliom link" + (Js.to_string node##.tagName) + ); if process_node then ignore node_array##(push node); if closure then ignore closure_array##(push node); if attrib then ignore attrib_array##(push node); @@ -306,14 +317,13 @@ let get_body (page : 'element #get_tag Js.t) : 'element Js.t = page##(getElementsByTagName (Js.string "body"))##(item 0) (fun () -> raise_error ~section "get_body") -let iter_dom_array - (f : 'a -> unit) - (a : - < length : < get : int ; .. > Js.gen_prop - ; item : int -> 'a Js.opt Js.meth - ; .. > - Js.t) - = +let iter_dom_array (f : 'a -> unit) + (a : + < length : < get : int ; .. > Js.gen_prop + ; item : int -> 'a Js.opt Js.meth + ; .. > + Js.t + ) = let length = a##.length in for i = 0 to length - 1 do Js.Opt.iter a##(item i) f @@ -365,20 +375,20 @@ let add_childrens (elt : Dom_html.element Js.t) (sons : Dom.node Js.t list) = let d = Dom_html.createHead Dom_html.document in Dom.appendChild d elt; (Js.Unsafe.coerce elt)##.styleSheet##.cssText := concat sons - | _ -> raise_error ~section ~exn "add_childrens: can't appendChild") + | _ -> raise_error ~section ~exn "add_childrens: can't appendChild" + ) (* END IE HACK *) -let copy_element - (e : Dom.element Js.t) - (registered_process_node : Js.js_string Js.t -> bool) : - Dom_html.element Js.t - = +let copy_element (e : Dom.element Js.t) + (registered_process_node : Js.js_string Js.t -> bool) : + Dom_html.element Js.t = let rec aux (e : Dom.element Js.t) = let copy = Dom_html.document##(createElement e##.tagName) in (* IE<9: Copy className separately, it's not updated when displayed *) Js.Opt.iter (Dom_html.CoerceTo.element e) (fun e -> - copy##.className := e##.className); + copy##.className := e##.className + ); let node_id = Js.Opt.to_option e##(getAttribute (Js.string Eliom_runtime.RawXML.node_id_attrib)) @@ -395,16 +405,18 @@ let copy_element Js.Opt.iter (Dom.CoerceTo.attr a) (* we don't use copy##attributes##setNameditem: in ie 9 it fail setting types of buttons... *) - (fun a -> copy##(setAttribute a##.name a##.value)) + (fun a -> copy##(setAttribute a##.name a##.value) + ) in iter_dom_array add_attribute e##.attributes; let child_copies = List.map_filter (fun child -> - match Dom.nodeType child with - | Dom.Text t -> Some (copy_text t :> Dom.node Js.t) - | Dom.Element child -> (aux child :> Dom.node Js.t option) - | _ -> None) + match Dom.nodeType child with + | Dom.Text t -> Some (copy_text t :> Dom.node Js.t) + | Dom.Element child -> (aux child :> Dom.node Js.t option) + | _ -> None + ) (Dom.list_of_nodeList e##.childNodes) in add_childrens copy child_copies; @@ -413,8 +425,7 @@ let copy_element match aux e with None -> raise_error ~section "copy_element" | Some e -> e let html_document (src : Dom.element Dom.document Js.t) registered_process_node - : Dom_html.element Js.t - = + : Dom_html.element Js.t = let content = src##.documentElement in match Js.Opt.to_option (Dom_html.CoerceTo.element content) with | Some e -> ( @@ -423,17 +434,22 @@ let html_document (src : Dom.element Dom.document Js.t) registered_process_node Logs.debug ~src:section (fun fmt -> fmt ("can't adopt node, import instead" ^^ "@\n%s") - (Printexc.to_string exn)); + (Printexc.to_string exn) + ); try Dom_html.document##(importNode (e :> Dom.element Js.t) Js._true) with exn -> Logs.debug ~src:section (fun fmt -> fmt ("can't import node, copy instead" ^^ "@\n%s") - (Printexc.to_string exn)); - copy_element content registered_process_node)) + (Printexc.to_string exn) + ); + copy_element content registered_process_node + ) + ) | None -> Logs.debug ~src:section (fun fmt -> - fmt "can't adopt node, document not parsed as html. copy instead"); + fmt "can't adopt node, document not parsed as html. copy instead" + ); copy_element content registered_process_node (** CSS preloading. *) @@ -446,10 +462,11 @@ let is_stylesheet e = (Dom_html.CoerceTo.link (Js.Unsafe.coerce e)) (fun _ -> false) (fun e -> - List.exists - (fun s -> s = "stylesheet") - (Regexp.split spaces_re (Js.to_string e##.rel)) - && e##._type == Js.string "text/css") + List.exists + (fun s -> s = "stylesheet") + (Regexp.split spaces_re (Js.to_string e##.rel)) + && e##._type == Js.string "text/css" + ) let basedir_re = Regexp.regexp "^(([^/?]*/)*)([^/?]*)(\\?.*)?$" @@ -459,11 +476,14 @@ let basedir path = | Some res -> ( match Regexp.matched_group res 1 with | None -> ( - match Regexp.matched_group res 3 with Some ".." -> "../" | _ -> "/") + match Regexp.matched_group res 3 with Some ".." -> "../" | _ -> "/" + ) | Some dir -> ( match Regexp.matched_group res 3 with | Some ".." -> dir ^ "../" - | _ -> dir)) + | _ -> dir + ) + ) let fetch_linked_css e = let rec extract acc (e : Dom.node Js.t) = @@ -498,7 +518,8 @@ let quoted_url_raw = "'(([^\\\\']|\\\\.)*)'" let url_re = Regexp.regexp (Printf.sprintf "url\\s*\\(\\s*(%s|%s|%s)\\s*\\)\\s*" dbl_quoted_url_raw - quoted_url_raw url_content_raw) + quoted_url_raw url_content_raw + ) let raw_url_re = Regexp.regexp @@ -519,8 +540,10 @@ let parse_absolute ~prefix href = | Some (i, res) when i = 0 -> ( match Regexp.matched_group res 1 with | Some href -> (* absolute URL -> do not rewrite *) href - | None -> raise Incorrect_url) - | _ -> prefix ^ href) + | None -> raise Incorrect_url + ) + | _ -> prefix ^ href + ) let parse_url ~prefix css pos = match Regexp.search url_re css pos with @@ -534,15 +557,20 @@ let parse_url ~prefix css pos = | None -> ( match Regexp.matched_group res 4 with | Some href -> parse_absolute ~prefix href - | None -> raise Incorrect_url)) )) + | None -> raise Incorrect_url + ) + ) ) + ) | _ -> ( match Regexp.search raw_url_re css pos with | Some (i, res) when i = pos -> ( ( i + String.length (Regexp.matched_string res) , match Regexp.matched_group res 1 with | Some href -> parse_absolute ~prefix href - | None -> raise Incorrect_url )) - | _ -> raise Incorrect_url) + | None -> raise Incorrect_url ) + ) + | _ -> raise Incorrect_url + ) let parse_media css pos = let i = @@ -571,7 +599,8 @@ let rewrite_css_url ~prefix css pos = Buffer.add_string buf "')"; rewrite i with Incorrect_url -> - Buffer.add_substring buf css i (String.length css - i)) + Buffer.add_substring buf css i (String.length css - i) + ) in rewrite pos; Buffer.contents buf @@ -580,17 +609,18 @@ let import_re = Regexp.regexp "@import\\s*" let rec rewrite_css ~max (media, href, css) = Lwt.catch (fun () -> - css >>= function - | None -> Lwt.return_nil - | Some css -> - if !Eliom_config.debug_timings - then Console.console##(time (Js.string ("rewrite_CSS: " ^ href))); - let* imports, css = - rewrite_css_import ~max ~prefix:(basedir href) ~media css 0 - in - if !Eliom_config.debug_timings - then Console.console##(timeEnd (Js.string ("rewrite_CSS: " ^ href))); - Lwt.return (imports @ [media, css])) + css >>= function + | None -> Lwt.return_nil + | Some css -> + if !Eliom_config.debug_timings + then Console.console##(time (Js.string ("rewrite_CSS: " ^ href))); + let* imports, css = + rewrite_css_import ~max ~prefix:(basedir href) ~media css 0 + in + if !Eliom_config.debug_timings + then Console.console##(timeEnd (Js.string ("rewrite_CSS: " ^ href))); + Lwt.return (imports @ [media, css]) + ) (fun _ -> Lwt.return [media, Printf.sprintf "@import url(%s);" href]) and rewrite_css_import ?(charset = "") ~max ~prefix ~media css pos = @@ -634,10 +664,10 @@ and rewrite_css_import ?(charset = "") ~max ~prefix ~media css pos = | Incorrect_url -> Lwt.return ([], rewrite_css_url ~prefix css pos) | exn -> Logs.info ~src:section (fun fmt -> - fmt - ("Error while importing css" ^^ "@\n%s") - (Printexc.to_string exn)); - Lwt.return ([], rewrite_css_url ~prefix css pos)) + fmt ("Error while importing css" ^^ "@\n%s") (Printexc.to_string exn) + ); + Lwt.return ([], rewrite_css_url ~prefix css pos) + ) let max_preload_depth = ref 4 @@ -646,16 +676,17 @@ let build_style (e, css) = (* lwt css = *) Lwt_list.map_p (fun (media, css) -> - let style = Dom_html.createStyle Dom_html.document in - style##._type := Js.string "text/css"; - style##.media := media; - (* IE8: Assigning to style##innerHTML results in + let style = Dom_html.createStyle Dom_html.document in + style##._type := Js.string "text/css"; + style##.media := media; + (* IE8: Assigning to style##innerHTML results in "Unknown runtime error" *) - let styleSheet = Js.Unsafe.(get style (Js.string "styleSheet")) in - if Js.Optdef.test styleSheet - then Js.Unsafe.(set styleSheet (Js.string "cssText") (Js.string css)) - else style##.innerHTML := Js.string css; - Lwt.return (e, (style :> Dom.node Js.t))) + let styleSheet = Js.Unsafe.(get style (Js.string "styleSheet")) in + if Js.Optdef.test styleSheet + then Js.Unsafe.(set styleSheet (Js.string "cssText") (Js.string css)) + else style##.innerHTML := Js.string css; + Lwt.return (e, (style :> Dom.node Js.t)) + ) css (* IE8 doesn't allow appendChild on noscript-elements *) @@ -673,13 +704,15 @@ let preload_css (doc : Dom_html.element Js.t) = let css = List.concat css in List.iter (fun (e, css) -> - try Dom.replaceChild (get_head doc) css e - with _ -> - Logs.info - ~src: - (* Node was a unique node that has been removed... + try Dom.replaceChild (get_head doc) css e + with _ -> + Logs.info + ~src: + (* Node was a unique node that has been removed... in a perfect settings we won't have parsed it... *) - section (fun fmt -> fmt "Unique CSS skipped...")) + section (fun fmt -> fmt "Unique CSS skipped..." + ) + ) css; if !Eliom_config.debug_timings then Console.console##(timeEnd (Js.string "preload_css (fetch+rewrite)")); @@ -705,7 +738,8 @@ let createDocumentScroll () = { html_top = Js.to_float Dom_html.document##.documentElement##.scrollTop ; html_left = Js.to_float Dom_html.document##.documentElement##.scrollLeft ; body_top = Js.to_float Dom_html.document##.body##.scrollTop - ; body_left = Js.to_float Dom_html.document##.body##.scrollLeft } + ; body_left = Js.to_float Dom_html.document##.body##.scrollLeft + } (* With firefox, the scroll position is restored before to fire the popstate event. We maintain our own position. *) @@ -716,12 +750,15 @@ let _ = (* HACK: Remove this when js_of_ocaml 1.1.2 or greater is released... *) (* window##onscroll <- *) ignore - (Dom.addEventListener Dom_html.document (Dom.Event.make "scroll") - (Dom_html.handler (fun _event -> - current_position := createDocumentScroll (); - Js._false)) - Js._true - : Dom_html.event_listener_id) + ( Dom.addEventListener Dom_html.document (Dom.Event.make "scroll") + (Dom_html.handler (fun _event -> + current_position := createDocumentScroll (); + Js._false + ) + ) + Js._true + : Dom_html.event_listener_id + ) let getDocumentScroll () = !current_position @@ -739,11 +776,14 @@ let touch_base () = Js.Opt.iter (Js.Opt.bind Dom_html.document##(getElementById - (Js.string Eliom_common_base.base_elt_id)) - Dom_html.CoerceTo.base) + (Js.string Eliom_common_base.base_elt_id) + ) + Dom_html.CoerceTo.base + ) (fun e -> - let href = e##.href in - e##.href := href) + let href = e##.href in + e##.href := href + ) (* BEGIN FORMDATA HACK: This is only needed if FormData is not available in the browser. When it will be commonly available, remove all sections marked by "FORMDATA HACK" ! @@ -761,21 +801,23 @@ let touch_base () = * in js_of_ocaml, module Form: the code to emulate FormData *) let onclick_on_body_handler event = - (match Dom_html.tagged (Dom_html.eventTarget event) with + ( match Dom_html.tagged (Dom_html.eventTarget event) with | Dom_html.Button button -> Js.Unsafe.global##.eliomLastButton := Some button | Dom_html.Input input when input##._type = Js.string "submit" -> Js.Unsafe.global##.eliomLastButton := Some input - | _ -> Js.Unsafe.global##.eliomLastButton := None); + | _ -> Js.Unsafe.global##.eliomLastButton := None + ); Js._true let add_formdata_hack_onclick_handler () = ignore - (Dom_html.addEventListener - Dom_html.window##.document##.body - Dom_html.Event.click - (Dom_html.handler onclick_on_body_handler) - Js._true - : Dom_html.event_listener_id) + ( Dom_html.addEventListener + Dom_html.window##.document##.body + Dom_html.Event.click + (Dom_html.handler onclick_on_body_handler) + Js._true + : Dom_html.event_listener_id + ) (* END FORMDATA HACK *) @@ -787,20 +829,25 @@ let onhashchange f = if test_onhashchange () then ignore - (Dom.addEventListener Dom_html.window hashchange - (Dom_html.handler (fun _ -> - f Dom_html.window##.location##.hash; - Js._false)) - Js._true - : Dom_html.event_listener_id) + ( Dom.addEventListener Dom_html.window hashchange + (Dom_html.handler (fun _ -> + f Dom_html.window##.location##.hash; + Js._false + ) + ) + Js._true + : Dom_html.event_listener_id + ) else let last_fragment = ref Dom_html.window##.location##.hash in let check () = if not (Js.equals !last_fragment Dom_html.window##.location##.hash) then ( last_fragment := Dom_html.window##.location##.hash; - f Dom_html.window##.location##.hash) + f Dom_html.window##.location##.hash + ) in ignore Dom_html.window##(setInterval (Js.wrap_callback check) - (Js.float (0.2 *. 1000.))) + (Js.float (0.2 *. 1000.)) + ) diff --git a/src/lib/client/eliommod_dom.mli b/src/lib/client/eliommod_dom.mli index 6f58ad8ce5..7684d8c331 100644 --- a/src/lib/client/eliommod_dom.mli +++ b/src/lib/client/eliommod_dom.mli @@ -38,7 +38,7 @@ val get_head : 'element #get_tag Js.t -> 'element Js.t * nodes with attributes *) val select_nodes : - Dom_html.element Js.t + Dom_html.element Js.t -> Dom_html.anchorElement Dom.nodeList Js.t * Dom_html.formElement Dom.nodeList Js.t * Dom_html.element Dom.nodeList Js.t @@ -46,8 +46,7 @@ val select_nodes : * Dom_html.element Dom.nodeList Js.t val select_request_nodes : - Dom_html.element Js.t - -> Dom_html.element Dom.nodeList Js.t + Dom_html.element Js.t -> Dom_html.element Dom.nodeList Js.t (** [select_request_nodes root] finds the nodes below [root] in the page annotated to be: * request unique nodes *) @@ -58,14 +57,12 @@ val ancessor : #Dom.node Js.t -> #Dom.node Js.t -> bool val createEvent : Js.js_string Js.t -> #Dom_html.event Js.t val copy_element : - Dom.element Js.t - -> (Js.js_string Js.t -> bool) - -> Dom_html.element Js.t + Dom.element Js.t -> (Js.js_string Js.t -> bool) -> Dom_html.element Js.t (** [copy_element e] creates recursively a fresh html from any xml element avoiding browser bugs *) val html_document : - Dom.element Dom.document Js.t + Dom.element Dom.document Js.t -> (Js.js_string Js.t -> bool) -> Dom_html.element Js.t (** Assuming [d] has a body and head element, [html_document d] will @@ -79,9 +76,7 @@ val preload_css : Dom_html.element Js.t -> unit Lwt.t val iter_nodeList : 'a Dom.nodeList Js.t -> ('a Js.t -> unit) -> unit val iter_attrList : - Dom.attr Dom.namedNodeMap Js.t - -> (Dom.attr Js.t -> unit) - -> unit + Dom.attr Dom.namedNodeMap Js.t -> (Dom.attr Js.t -> unit) -> unit (** Window scrolling. *) diff --git a/src/lib/eliom.server.ml b/src/lib/eliom.server.ml index 44b317d596..aa46938358 100644 --- a/src/lib/eliom.server.ml +++ b/src/lib/eliom.server.ml @@ -1,55 +1,42 @@ let default_app_name = Eliom_common.default_app_name let set_app_name = Eliommod.set_app_name -let run - ?(app = default_app_name) - ?xhr_links - ?data_timeout - ?service_timeout - ?persistent_timeout - ?max_service_sessions_per_group - ?max_volatile_data_sessions_per_group - ?max_persistent_data_sessions_per_group - ?max_service_tab_sessions_per_group - ?max_volatile_data_tab_sessions_per_group - ?max_persistent_data_tab_sessions_per_group - ?max_anonymous_services_per_session - ?secure_cookies - ?application_script - ?enable_wasm - ?global_data_caching - ?html_content_type - ?ignored_get_params - ?ignored_post_params - ?omitpersistentstorage - () - vh - conf_info - site_dir - = +let run ?(app = default_app_name) ?xhr_links ?data_timeout ?service_timeout + ?persistent_timeout ?max_service_sessions_per_group + ?max_volatile_data_sessions_per_group + ?max_persistent_data_sessions_per_group ?max_service_tab_sessions_per_group + ?max_volatile_data_tab_sessions_per_group + ?max_persistent_data_tab_sessions_per_group + ?max_anonymous_services_per_session ?secure_cookies ?application_script + ?enable_wasm ?global_data_caching ?html_content_type ?ignored_get_params + ?ignored_post_params ?omitpersistentstorage () vh conf_info site_dir = let sitedata = Eliommod.update_sitedata app vh site_dir conf_info in (* customize sitedata according to optional parameters: *) Option.iter (fun v -> - sitedata.Eliom_common.default_links_xhr#set ~override_tenable:true v) + sitedata.Eliom_common.default_links_xhr#set ~override_tenable:true v + ) xhr_links; Option.iter (fun (level, hierarchyname, v) -> - Eliommod.set_timeout - (Eliommod_timeouts.set_global_ ~kind:`Data) - sitedata level hierarchyname v) + Eliommod.set_timeout + (Eliommod_timeouts.set_global_ ~kind:`Data) + sitedata level hierarchyname v + ) data_timeout; Option.iter (fun (level, hierarchyname, v) -> - Eliommod.set_timeout - (Eliommod_timeouts.set_global_ ~kind:`Service) - sitedata level hierarchyname v) + Eliommod.set_timeout + (Eliommod_timeouts.set_global_ ~kind:`Service) + sitedata level hierarchyname v + ) service_timeout; Option.iter (fun (level, hierarchyname, v) -> - Eliommod.set_timeout - (Eliommod_timeouts.set_global_ ~kind:`Persistent) - sitedata level hierarchyname v) + Eliommod.set_timeout + (Eliommod_timeouts.set_global_ ~kind:`Persistent) + sitedata level hierarchyname v + ) persistent_timeout; Option.iter (fun v -> sitedata.max_service_sessions_per_group <- v) @@ -68,7 +55,8 @@ let run max_volatile_data_tab_sessions_per_group; Option.iter (fun v -> - sitedata.max_persistent_data_tab_sessions_per_group <- Some v, true) + sitedata.max_persistent_data_tab_sessions_per_group <- Some v, true + ) max_persistent_data_tab_sessions_per_group; Option.iter (fun v -> sitedata.max_anonymous_services_per_session <- v) diff --git a/src/lib/eliom.server.mli b/src/lib/eliom.server.mli index 09d0144b6a..a4bf981b2a 100644 --- a/src/lib/eliom.server.mli +++ b/src/lib/eliom.server.mli @@ -9,7 +9,7 @@ val default_app_name : string (** The default application name, if you don't specify any *) val run : - ?app:string + ?app:string -> ?xhr_links:bool -> ?data_timeout: [< Eliom_common.cookie_level] diff --git a/src/lib/eliom_bus.client.ml b/src/lib/eliom_bus.client.ml index bb2474995f..1321df0982 100644 --- a/src/lib/eliom_bus.client.ml +++ b/src/lib/eliom_bus.client.ml @@ -36,7 +36,8 @@ type ('a, 'b) t = ; mutable waiter : unit -> unit Lwt.t ; mutable last_wait : unit Lwt.t ; mutable original_stream_available : bool - ; error_h : 'b option Lwt.t * exn Lwt.u } + ; error_h : 'b option Lwt.t * exn Lwt.u + } (* clone streams such that each clone of the original stream raise the same exceptions *) let consume (t, u) s = @@ -44,8 +45,9 @@ let consume (t, u) s = Lwt.catch (fun () -> Lwt_stream.iter (fun _ -> ()) s) (fun e -> - (match Lwt.state t with Lwt.Sleep -> Lwt.wakeup_exn u e | _ -> ()); - Lwt.fail e) + (match Lwt.state t with Lwt.Sleep -> Lwt.wakeup_exn u e | _ -> ()); + Lwt.fail e + ) in Lwt.choose [Lwt.bind t (fun _ -> Lwt.return_unit); t'] @@ -55,43 +57,49 @@ let clone_exn (t, u) s = Lwt.catch (fun () -> Lwt.choose [Lwt_stream.get s'; t]) (fun e -> - (match Lwt.state t with Lwt.Sleep -> Lwt.wakeup_exn u e | _ -> ()); - Lwt.fail e)) + (match Lwt.state t with Lwt.Sleep -> Lwt.wakeup_exn u e | _ -> ()); + Lwt.fail e + ) + ) type ('a, 'att, 'co, 'ext, 'reg) callable_bus_service = ( unit - , 'a list - , Eliom_service.post - , 'att - , 'co - , 'ext - , 'reg - , [`WithoutSuffix] - , unit - , [`One of 'a list Eliom_parameter.ocaml] Eliom_parameter.param_name - , Eliom_registration.Action.return ) - Eliom_service.t + , 'a list + , Eliom_service.post + , 'att + , 'co + , 'ext + , 'reg + , [`WithoutSuffix] + , unit + , [`One of 'a list Eliom_parameter.ocaml] Eliom_parameter.param_name + , Eliom_registration.Action.return + ) + Eliom_service.t let create service channel waiter = let write x = Lwt.catch (fun () -> - let* _ = - Eliom_client.call_service - ~service:(service :> ('a, _, _, _, _) callable_bus_service) - () x - in - Lwt.return_unit) + let* _ = + Eliom_client.call_service + ~service:(service :> ('a, _, _, _, _) callable_bus_service) + () x + in + Lwt.return_unit + ) (function | Eliom_request.Failed_request 204 -> Lwt.return_unit - | exc -> Lwt.reraise exc) + | exc -> Lwt.reraise exc + ) in let error_h = let t, u = Lwt.wait () in ( Lwt.catch (fun () -> - let* _ = t in - assert false) + let* _ = t in + assert false + ) (fun e -> Lwt.fail e) , u ) in @@ -100,7 +108,8 @@ let create service channel waiter = (let stream = Eliom_comet.register channel in (* iterate on the stream to consume messages: avoid memory leak *) let _ = consume error_h stream in - stream) + stream + ) in let t = { channel @@ -111,7 +120,8 @@ let create service channel waiter = ; waiter ; last_wait = Lwt.return_unit ; original_stream_available = true - ; error_h } + ; error_h + } in (* the comet channel start receiving after the load phase, so the original channel (i.e. without message lost) is only available in diff --git a/src/lib/eliom_bus.server.ml b/src/lib/eliom_bus.server.ml index c7814ceab2..4e6513511b 100644 --- a/src/lib/eliom_bus.server.ml +++ b/src/lib/eliom_bus.server.ml @@ -31,16 +31,17 @@ type ('a, 'b) t = ; service : 'a Ecb.bus_send_service ; service_registered : bool Eliom_state.volatile_table option ; size : int option - ; bus_mark : ('a, 'b) t Eliom_common.wrapper (* must be the last field ! *) } + ; bus_mark : ('a, 'b) t Eliom_common.wrapper (* must be the last field ! *) + } [@@warning "-69"] let register_sender scope service write = Eliom_registration.Action.register ~scope ~options:`NoReload ~service - (fun () x -> Lwt_list.iter_s write x) + (fun () x -> Lwt_list.iter_s write x + ) let internal_wrap (bus : ('a, 'b) t) : - ('a, 'b) Ecb.wrapped_bus * Eliom_common.unwrapper - = + ('a, 'b) Ecb.wrapped_bus * Eliom_common.unwrapper = let channel = match bus.channel with | None -> @@ -49,7 +50,7 @@ let internal_wrap (bus : ('a, 'b) t) : (Lwt_stream.clone bus.stream) | Some c -> c in - (match bus.service_registered with + ( match bus.service_registered with | None -> () | Some table -> ( match Eliom_state.get_volatile_data ~table () with @@ -57,21 +58,25 @@ let internal_wrap (bus : ('a, 'b) t) : | _ -> let {service = Ecb.Bus_send_service srv; _} = bus in register_sender bus.scope - (srv + ( srv :> ( _ - , _ list - , _ - , _ - , _ - , Eliom_service.non_ext - , _ - , _ - , _ - , _ - , _ ) - Eliom_service.t) + , _ list + , _ + , _ + , _ + , Eliom_service.non_ext + , _ + , _ + , _ + , _ + , _ + ) + Eliom_service.t + ) bus.write; - Eliom_state.set_volatile_data ~table true)); + Eliom_state.set_volatile_data ~table true + ) + ); ( (Eliom_comet.Channel.get_wrapped channel, bus.service) , Eliom_common.make_unwrapper Eliom_common.bus_unwrap_id ) @@ -79,16 +84,16 @@ let bus_mark () = Eliom_common.make_wrapper internal_wrap let deriving_to_list : 'a Deriving_Json.t -> 'a list Deriving_Json.t = fun (type typ) typ -> - let (typ_list : typ list Deriving_Json.t) = - let module M = Deriving_Json.Json_list (Deriving_Json.Defaults'' (struct - type a = typ + let (typ_list : typ list Deriving_Json.t) = + let module M = Deriving_Json.Json_list (Deriving_Json.Defaults'' (struct + type a = typ - let t = typ - end)) - in - M.t - in - typ_list + let t = typ + end)) + in + M.t + in + typ_list let create_filtered ?scope ?name ?size ~filter typ = (*The stream*) @@ -107,14 +112,16 @@ let create_filtered ?scope ?name ?size ~filter typ = | `Site -> Some (Eliom_comet.Channel.create ~scope ?name ?size - (Lwt_stream.clone stream)) + (Lwt_stream.clone stream) + ) | `Client_process _ -> None in let typ_list = deriving_to_list typ in (*The service*) let post_params = - (Eliom_parameter.ocaml "bus_write" typ_list - : ('a, 'aa, 'aaa) Eliom_parameter.params_type) + ( Eliom_parameter.ocaml "bus_write" typ_list + : ('a, 'aa, 'aaa) Eliom_parameter.params_type + ) in let distant_write = Eliom_service.create ?name @@ -139,7 +146,8 @@ let create_filtered ?scope ?name ?size ~filter typ = ; service = Eliom_comet_base.Bus_send_service distant_write ; service_registered ; bus_mark = bus_mark () - ; size } + ; size + } in bus diff --git a/src/lib/eliom_bus.server.mli b/src/lib/eliom_bus.server.mli index 7a716f2e52..69196cefe6 100644 --- a/src/lib/eliom_bus.server.mli +++ b/src/lib/eliom_bus.server.mli @@ -36,7 +36,7 @@ type ('a, 'b) t participants. *) val create : - ?scope:[< Eliom_comet.Channel.comet_scope] + ?scope:[< Eliom_comet.Channel.comet_scope] -> ?name:string -> ?size:int -> 'a Deriving_Json.t @@ -53,7 +53,7 @@ val create : *) val create_filtered : - ?scope:[< Eliom_comet.Channel.comet_scope] + ?scope:[< Eliom_comet.Channel.comet_scope] -> ?name:string -> ?size:int -> filter:('a -> 'b Lwt.t) diff --git a/src/lib/eliom_client.client.ml b/src/lib/eliom_client.client.ml index 7b156aca74..9cc2eeeeb7 100644 --- a/src/lib/eliom_client.client.ml +++ b/src/lib/eliom_client.client.ml @@ -37,24 +37,23 @@ type changepage_event = ; origin_uri : string ; target_uri : string ; origin_id : int - ; target_id : int option } + ; target_id : int option + } let run_lwt_callbacks : 'a -> ('a -> unit Lwt.t) list -> unit Lwt.t = fun ev handlers -> Lwt_list.iter_s (fun h -> h ev) handlers let (onload, _, flush_onload, _push_onload) : - ((unit -> unit) -> unit) - * (unit -> (unit -> unit) list) - * (unit -> (unit -> unit) list) - * (unit -> unit) - = + ((unit -> unit) -> unit) + * (unit -> (unit -> unit) list) + * (unit -> (unit -> unit) list) + * (unit -> unit) = Eliom_client_core.create_buffer () let ( (onchangepage : (changepage_event -> unit Lwt.t) -> unit) , _ , (flush_onchangepage : unit -> (changepage_event -> unit Lwt.t) list) - , _ ) - = + , _ ) = Eliom_client_core.create_buffer () let onunload, _, flush_onunload, _ = Eliom_client_core.create_buffer () @@ -64,7 +63,9 @@ let onbeforeunload, run_onbeforeunload, flush_onbeforeunload = let rec run lst = match lst with | [] -> None - | f :: rem -> ( match f () with None -> run rem | Some s -> Some s) + | f :: rem -> ( + match f () with None -> run rem | Some s -> Some s + ) in add, (fun () -> run (get ())), flush @@ -87,24 +88,25 @@ let check_global_data global_data = let missing_client_values = ref [] in let missing_injections = ref [] in String_map.iter - (fun compilation_unit_id - {Eliom_client_core.server_section; client_section} -> - List.iter - (fun data -> - missing_client_values := - List.rev_append - (List.map - (fun cv -> compilation_unit_id, cv) - (Array.to_list data)) - !missing_client_values) - server_section; - List.iter - (fun data -> - missing_injections := - List.rev_append (Array.to_list data) !missing_injections) - client_section) + (fun compilation_unit_id {Eliom_client_core.server_section; client_section} + -> + List.iter + (fun data -> + missing_client_values := + List.rev_append + (List.map (fun cv -> compilation_unit_id, cv) (Array.to_list data)) + !missing_client_values + ) + server_section; + List.iter + (fun data -> + missing_injections := + List.rev_append (Array.to_list data) !missing_injections + ) + client_section + ) global_data; - (match !missing_client_values with + ( match !missing_client_values with | [] -> () | l -> Printf.ksprintf @@ -112,19 +114,24 @@ let check_global_data global_data = "Code generating the following client values is not linked on the client:\n%s" (String.concat "\n" (List.rev_map - (fun (compilation_unit_id, {Eliom_runtime.closure_id; value; _}) -> - let instance_id = - Eliom_runtime.Client_value_server_repr.instance_id value - in - match Eliom_runtime.Client_value_server_repr.loc value with - | None -> - Printf.sprintf "%s:%s/%d" compilation_unit_id closure_id - instance_id - | Some pos -> - Printf.sprintf "%s:%s/%d at %s" compilation_unit_id - closure_id instance_id - (Eliom_lib.pos_to_string pos)) - l))); + (fun (compilation_unit_id, {Eliom_runtime.closure_id; value; _}) + -> + let instance_id = + Eliom_runtime.Client_value_server_repr.instance_id value + in + match Eliom_runtime.Client_value_server_repr.loc value with + | None -> + Printf.sprintf "%s:%s/%d" compilation_unit_id closure_id + instance_id + | Some pos -> + Printf.sprintf "%s:%s/%d at %s" compilation_unit_id + closure_id instance_id + (Eliom_lib.pos_to_string pos) + ) + l + ) + ) + ); match !missing_injections with | [] -> () | l -> @@ -134,20 +141,23 @@ let check_global_data global_data = (String.concat "\n" (List.rev_map (fun d -> - let id = d.Eliom_runtime.injection_id in - match d.Eliom_runtime.injection_dbg with - | None -> Printf.sprintf "%d" id - | Some (pos, Some i) -> - Printf.sprintf "%d (%s at %s)" id i - (Eliom_lib.pos_to_string pos) - | Some (pos, None) -> - Printf.sprintf "%d (at %s)" id - (Eliom_lib.pos_to_string pos)) - l)) + let id = d.Eliom_runtime.injection_id in + match d.Eliom_runtime.injection_dbg with + | None -> Printf.sprintf "%d" id + | Some (pos, Some i) -> + Printf.sprintf "%d (%s at %s)" id i + (Eliom_lib.pos_to_string pos) + | Some (pos, None) -> + Printf.sprintf "%d (at %s)" id (Eliom_lib.pos_to_string pos) + ) + l + ) + ) let do_request_data request_data = Logs.debug ~src:section (fun fmt -> - fmt "Do request data (%d)" (Array.length request_data)); + fmt "Do request data (%d)" (Array.length request_data) + ); (* On a request, i.e. after running the toplevel definitions, global_data must contain at most empty sections_data lists, which stem from server- only eliom files. *) @@ -166,20 +176,24 @@ let get_element_cookies_info elt = Js.Opt.to_option (Js.Opt.map elt##(getAttribute - (Js.string Eliom_runtime.RawXML.ce_call_service_attrib)) - (fun s -> of_json ~typ:[%json: bool * string list] (Js.to_string s))) + (Js.string Eliom_runtime.RawXML.ce_call_service_attrib) + ) + (fun s -> of_json ~typ:[%json: bool * string list] (Js.to_string s)) + ) let get_element_template elt = Js.Opt.to_option (Js.Opt.map elt##(getAttribute (Js.string Eliom_runtime.RawXML.ce_template_attrib)) - (fun s -> Js.to_string s)) + (fun s -> Js.to_string s) + ) let a_handler = Dom_html.full_handler (fun node ev -> let node = Js.Opt.get (Dom_html.CoerceTo.a node) (fun () -> - raise_error ~section "not an anchor element") + raise_error ~section "not an anchor element" + ) in (* We prevent default behaviour only if raw_a_handler has taken the change page itself *) @@ -188,15 +202,17 @@ let a_handler = (Eliom_client_core.raw_a_handler node (get_element_cookies_info node) (get_element_template node) - ev)) + ev + ) + ) let form_handler : - (Dom_html.element Js.t, #Dom_html.event Js.t) Dom_html.event_listener - = + (Dom_html.element Js.t, #Dom_html.event Js.t) Dom_html.event_listener = Dom_html.full_handler (fun node ev -> let form = Js.Opt.get (Dom_html.CoerceTo.form node) (fun () -> - raise_error ~section "not a form element") + raise_error ~section "not a form element" + ) in let kind = if String.lowercase_ascii (Js.to_string form##._method) = "get" @@ -207,7 +223,9 @@ let form_handler : (Eliom_client_core.raw_form_handler form kind (get_element_cookies_info form) (get_element_template node) - ev f)) + ev f + ) + ) let relink_process_node (node : Dom_html.element Js.t) = let id = @@ -218,21 +236,27 @@ let relink_process_node (node : Dom_html.element Js.t) = Js.Optdef.case (Eliom_client_core.find_process_node id) (fun () -> - Logs.debug ~src:section (fun fmt -> - fmt "Relink process node: did not find %s. Will add it." - (Js.to_string id)); - Eliom_client_core.register_process_node id (node :> Dom.node Js.t)) + Logs.debug ~src:section (fun fmt -> + fmt "Relink process node: did not find %s. Will add it." + (Js.to_string id) + ); + Eliom_client_core.register_process_node id (node :> Dom.node Js.t) + ) (fun pnode -> - Logs.debug ~src:section (fun fmt -> - fmt "Relink process node: found %s" (Js.to_string id)); - Js.Opt.iter node##.parentNode (fun parent -> - Dom.replaceChild parent pnode node); - if String.sub (Js.to_bytestring id) 0 7 <> "global_" - then ( - let childrens = Dom.list_of_nodeList pnode##.childNodes in - List.iter (fun c -> ignore pnode##(removeChild c)) childrens; - let childrens = Dom.list_of_nodeList node##.childNodes in - List.iter (fun c -> ignore pnode##(appendChild c)) childrens)) + Logs.debug ~src:section (fun fmt -> + fmt "Relink process node: found %s" (Js.to_string id) + ); + Js.Opt.iter node##.parentNode (fun parent -> + Dom.replaceChild parent pnode node + ); + if String.sub (Js.to_bytestring id) 0 7 <> "global_" + then ( + let childrens = Dom.list_of_nodeList pnode##.childNodes in + List.iter (fun c -> ignore pnode##(removeChild c)) childrens; + let childrens = Dom.list_of_nodeList node##.childNodes in + List.iter (fun c -> ignore pnode##(appendChild c)) childrens + ) + ) let relink_request_node (node : Dom_html.element Js.t) = let id = @@ -243,15 +267,20 @@ let relink_request_node (node : Dom_html.element Js.t) = Js.Optdef.case (Eliom_client_core.find_request_node id) (fun () -> - Logs.debug ~src:section (fun fmt -> - fmt "Relink request node: did not find %s. Will add it." - (Js.to_string id)); - Eliom_client_core.register_request_node id (node :> Dom.node Js.t)) + Logs.debug ~src:section (fun fmt -> + fmt "Relink request node: did not find %s. Will add it." + (Js.to_string id) + ); + Eliom_client_core.register_request_node id (node :> Dom.node Js.t) + ) (fun pnode -> - Logs.debug ~src:section (fun fmt -> - fmt "Relink request node: found %s" (Js.to_string id)); - Js.Opt.iter node##.parentNode (fun parent -> - Dom.replaceChild parent pnode node)) + Logs.debug ~src:section (fun fmt -> + fmt "Relink request node: found %s" (Js.to_string id) + ); + Js.Opt.iter node##.parentNode (fun parent -> + Dom.replaceChild parent pnode node + ) + ) let relink_request_nodes root = Logs.debug ~src:section (fun fmt -> fmt "Relink request nodes"); @@ -273,14 +302,13 @@ let relink_page_but_client_values (root : Dom_html.element Js.t) = , form_nodeList , process_nodeList , closure_nodeList - , attrib_nodeList ) - = + , attrib_nodeList ) = Eliommod_dom.select_nodes root in - Eliommod_dom.iter_nodeList a_nodeList (fun node -> - node##.onclick := a_handler); + Eliommod_dom.iter_nodeList a_nodeList (fun node -> node##.onclick := a_handler); Eliommod_dom.iter_nodeList form_nodeList (fun node -> - node##.onsubmit := form_handler); + node##.onsubmit := form_handler + ); Eliommod_dom.iter_nodeList process_nodeList relink_process_node; closure_nodeList, attrib_nodeList @@ -304,7 +332,8 @@ let is_closure_attrib, get_closure_name, get_closure_id = let n_prefix_js = Js.string n_prefix in ( (fun attr -> attr##.value##(substring 0 v_len) = v_prefix_js - && attr##.name##(substring 0 n_len) = n_prefix_js) + && attr##.name##(substring 0 n_len) = n_prefix_js + ) , (fun attr -> attr##.name##(substring_toEnd n_len)) , fun attr -> attr##.value##(substring_toEnd v_len) ) @@ -323,26 +352,27 @@ let relink_closure_node root onload table (node : Dom_html.element Js.t) = if Eliommod_dom.ancessor root node (* if not inside a unique node replaced by an older one *) - then onload := closure :: !onload) + then onload := closure :: !onload + ) else Js.Unsafe.set node name (Dom_html.handler (fun ev -> Js.bool (closure ev))) with Not_found -> Logs.err ~src:section (fun fmt -> - fmt "relink_closure_node: client value %s not found" cid) + fmt "relink_closure_node: client value %s not found" cid + ) in Eliommod_dom.iter_attrList node##.attributes aux -let relink_closure_nodes - (root : Dom_html.element Js.t) - event_handlers - closure_nodeList - = +let relink_closure_nodes (root : Dom_html.element Js.t) event_handlers + closure_nodeList = Logs.debug ~src:section (fun fmt -> - fmt "Relink %i closure nodes" closure_nodeList##.length); + fmt "Relink %i closure nodes" closure_nodeList##.length + ); let onload = ref [] in Eliommod_dom.iter_nodeList closure_nodeList (fun node -> - relink_closure_node root onload event_handlers node); + relink_closure_node root onload event_handlers node + ); fun () -> let ev = Eliommod_dom.createEvent (Js.string "load") in ignore (List.for_all (fun f -> f ev) (List.rev !onload)) @@ -356,7 +386,8 @@ let is_attrib_attrib, get_attrib_id = let n_prefix_js = Js.string n_prefix in ( (fun attr -> attr##.value##(substring 0 v_len) = v_prefix_js - && attr##.name##(substring 0 n_len) = n_prefix_js) + && attr##.name##(substring 0 n_len) = n_prefix_js + ) , fun attr -> attr##.value##(substring_toEnd v_len) ) let relink_attrib _root table (node : Dom_html.element Js.t) = @@ -378,9 +409,11 @@ let relink_attrib _root table (node : Dom_html.element Js.t) = let relink_attribs (root : Dom_html.element Js.t) attribs attrib_nodeList = Logs.debug ~src:section (fun fmt -> - fmt "Relink %i attributes" attrib_nodeList##.length); + fmt "Relink %i attributes" attrib_nodeList##.length + ); Eliommod_dom.iter_nodeList attrib_nodeList (fun node -> - relink_attrib root attribs node) + relink_attrib root attribs node + ) (* == Extract the request data and the request tab-cookies from a page @@ -400,7 +433,8 @@ let load_data_script page = | t -> raise_error ~section "Unable to find Eliom application data (script element expected, found %s element)" - t) + t + ) | _ -> raise_error ~section "Unable to find Eliom application data." in let script = data_script##.text in @@ -426,19 +460,22 @@ let scroll_to_fragment ?offset fragment = | Some fragment -> let scroll_to_element e = e##(scrollIntoView Js._true) in let elem = Dom_html.document##(getElementById (Js.string fragment)) in - Js.Opt.iter elem scroll_to_element) + Js.Opt.iter elem scroll_to_element + ) let with_progress_cursor : 'a Lwt.t -> 'a Lwt.t = fun t -> - Lwt.catch - (fun () -> + Lwt.catch + (fun () -> Dom_html.document##.body##.style##.cursor := Js.string "progress"; let* res = t in Dom_html.document##.body##.style##.cursor := Js.string "auto"; - Lwt.return res) - (fun exn -> + Lwt.return res + ) + (fun exn -> Dom_html.document##.body##.style##.cursor := Js.string "auto"; - Lwt.fail exn) + Lwt.fail exn + ) (* Type for partially unwrapped elt. *) type tmp_recontent = @@ -450,7 +487,8 @@ type tmp_recontent = type tmp_elt = { (* to be unwrapped *) tmp_elt : tmp_recontent - ; tmp_node_id : Xml.node_id } + ; tmp_node_id : Xml.node_id + } (******************************************************************************) (* Register unwrappers *) @@ -478,44 +516,52 @@ let unwrap_tyxml tmp_elt = let elt = let context = "unwrapping (i.e. utilize it in whatsoever form)" in Xml.make_lazy ~id:tmp_elt.tmp_node_id - (lazy - (match tmp_elt.tmp_node_id with + ( lazy + ( match tmp_elt.tmp_node_id with | Xml.ProcessId process_id as id -> Logs.debug ~src:section (fun fmt -> - fmt "Unwrap tyxml from ProcessId %s" process_id); + fmt "Unwrap tyxml from ProcessId %s" process_id + ); Js.Optdef.case (Eliom_client_core.find_process_node (Js.bytestring process_id)) (fun () -> - Logs.debug ~src:section (fun fmt -> fmt "not found"); - let xml_elt : Xml.elt = Xml.make ~id elt in - let xml_elt = - Eliom_content_core.Xml.set_classes_of_elt xml_elt - in - Eliom_client_core.register_process_node - (Js.bytestring process_id) - (Eliom_client_core.rebuild_node_ns `HTML5 context xml_elt); - xml_elt) + Logs.debug ~src:section (fun fmt -> fmt "not found"); + let xml_elt : Xml.elt = Xml.make ~id elt in + let xml_elt = + Eliom_content_core.Xml.set_classes_of_elt xml_elt + in + Eliom_client_core.register_process_node + (Js.bytestring process_id) + (Eliom_client_core.rebuild_node_ns `HTML5 context xml_elt); + xml_elt + ) (fun elt -> - Logs.debug ~src:section (fun fmt -> fmt "found"); - Xml.make_dom ~id elt) + Logs.debug ~src:section (fun fmt -> fmt "found"); + Xml.make_dom ~id elt + ) | Xml.RequestId request_id as id -> Logs.debug ~src:section (fun fmt -> - fmt "Unwrap tyxml from RequestId %s" request_id); + fmt "Unwrap tyxml from RequestId %s" request_id + ); Js.Optdef.case (Eliom_client_core.find_request_node (Js.bytestring request_id)) (fun () -> - Logs.debug ~src:section (fun fmt -> fmt "not found"); - let xml_elt : Xml.elt = Xml.make ~id elt in - Eliom_client_core.register_request_node - (Js.bytestring request_id) - (Eliom_client_core.rebuild_node_ns `HTML5 context xml_elt); - xml_elt) + Logs.debug ~src:section (fun fmt -> fmt "not found"); + let xml_elt : Xml.elt = Xml.make ~id elt in + Eliom_client_core.register_request_node + (Js.bytestring request_id) + (Eliom_client_core.rebuild_node_ns `HTML5 context xml_elt); + xml_elt + ) (fun elt -> - Logs.debug ~src:section (fun fmt -> fmt "found"); - Xml.make_dom ~id elt) + Logs.debug ~src:section (fun fmt -> fmt "found"); + Xml.make_dom ~id elt + ) | Xml.NoId as id -> Logs.debug ~src:section (fun fmt -> fmt "Unwrap tyxml from NoId"); - Xml.make ~id elt)) + Xml.make ~id elt + ) + ) in Eliom_client_core.register_unwrapped_elt elt; elt @@ -531,8 +577,10 @@ let unwrap_global_data (global_data', _) = Eliom_client_core.global_data := String_map.map (fun {Eliom_runtime.server_sections_data; client_sections_data} -> - { Eliom_client_core.server_section = Array.to_list server_sections_data - ; client_section = Array.to_list client_sections_data }) + { Eliom_client_core.server_section = Array.to_list server_sections_data + ; client_section = Array.to_list client_sections_data + } + ) global_data' let _ = @@ -586,7 +634,8 @@ let add_string_event_listener o e f capt : unit = type state = { (* TODO store cookies_info in state... *) template : string option - ; position : Eliommod_dom.position } + ; position : Eliommod_dom.position + } [@@deriving json] [@@@warning "+39"] @@ -599,7 +648,8 @@ let random_int = fun () -> let a = Js.Unsafe.global##.crypto##(getRandomValues - (new%js Typed_array.int16Array 2)) + (new%js Typed_array.int16Array 2) + ) in (Typed_array.unsafe_get a 0 lsl 16) lor Typed_array.unsafe_get a 1 else fun () -> truncate (4294967296. *. Js.to_float Js.math##random) @@ -635,7 +685,8 @@ type page = ; set_page_status : ?step:React.step -> Page_status_t.t -> unit ; mutable dom : Dom_html.bodyElement Js.t option ; mutable reload_function : - (unit -> unit -> Eliom_service.result Lwt.t) option } + (unit -> unit -> Eliom_service.result Lwt.t) option + } let string_of_page p = Printf.sprintf "%d/%d %s %s %d %b" p.page_unique_id p.page_id.state_index @@ -647,7 +698,8 @@ let string_of_page p = let set_page_status p st = Logs.debug ~src:section_page (fun fmt -> fmt "Set page status %d/%d: %s" p.page_unique_id p.page_id.state_index - (Page_status_t.to_string st)); + (Page_status_t.to_string st) + ); p.set_page_status st let retire_page p = @@ -666,30 +718,33 @@ let last_page_id = ref (-1) let mk_page ?(state_id = next_state_id ()) ?url ?previous_page ~status () = incr last_page_id; Logs.debug ~src:section_page (fun fmt -> - fmt "Create page %d/%d" !last_page_id state_id.state_index); + fmt "Create page %d/%d" !last_page_id state_id.state_index + ); let page_status, set_page_status = React.S.create status in (* protect page_status from React.S.stop ~strong:true *) ignore @@ React.S.map (fun _ -> ()) page_status; { page_unique_id = !last_page_id ; page_id = state_id ; url = - (match url with + ( match url with | Some u -> u | None -> fst - (Url.split_fragment - (Js.to_string Dom_html.window##.location##.href))) + (Url.split_fragment (Js.to_string Dom_html.window##.location##.href)) + ) ; page_status ; previous_page ; set_page_status ; dom = None - ; reload_function = None } + ; reload_function = None + } let active_page = ref @@ mk_page ~status:Active () let set_active_page p = Logs.debug ~src:section_page (fun fmt -> - fmt "Set active page %d/%d" p.page_unique_id p.page_id.state_index); + fmt "Set active page %d/%d" p.page_unique_id p.page_id.state_index + ); retire_page !active_page; active_page := p; set_page_status !active_page Active @@ -723,7 +778,8 @@ module History = struct let set h = Logs.debug ~src:section (fun fmt -> fmt "setting history:\n%s" - (String.concat "\n" @@ List.map string_of_page !history)); + (String.concat "\n" @@ List.map string_of_page !history) + ); history := h in (fun () -> !history), set @@ -799,7 +855,8 @@ module History = struct if !num_doms > max_num_doms then ( p.dom <- None; - set_page_status p Dead) + set_page_status p Dead + ) in List.iter maybe_delete_dom pages_ordered_by_distance_from_present end @@ -809,10 +866,12 @@ let advance_page () = if new_page != !active_page then ( new_page.previous_page <- Some !active_page.page_id.state_index; - (match History.find_by_state_index new_page.page_id.state_index with + ( match History.find_by_state_index new_page.page_id.state_index with | Some _ -> () - | None -> History.advance new_page); - set_active_page new_page) + | None -> History.advance new_page + ); + set_active_page new_page + ) let state_key {session_id; state_index} = Js.string (Printf.sprintf "state_history_%x_%x" session_id state_index) @@ -822,11 +881,13 @@ let get_state state_id : state = (Js.Optdef.case Dom_html.window##.sessionStorage (fun () -> - (* We use this only when the history API is + (* We use this only when the history API is available. Sessionstorage seems to be available everywhere the history API exists. *) - raise_error ~section "sessionStorage not available") - (fun s -> s##(getItem (state_key state_id)))) + raise_error ~section "sessionStorage not available" + ) + (fun s -> s##(getItem (state_key state_id))) + ) (fun () -> raise Not_found) (fun s -> of_json ~typ:[%json: state] (Js.to_string s)) @@ -835,12 +896,14 @@ let set_state i (v : state) = Dom_html.window##.sessionStorage (fun () -> ()) (fun s -> - s##(setItem (state_key i) (Js.string (to_json ~typ:[%json: state] v)))) + s##(setItem (state_key i) (Js.string (to_json ~typ:[%json: state] v))) + ) let update_state () = set_state !active_page.page_id { template = Eliom_request_info.get_request_template () - ; position = Eliommod_dom.getDocumentScroll () } + ; position = Eliommod_dom.getDocumentScroll () + } let lock_request_handling = Eliom_request.lock let unlock_request_handling = Eliom_request.unlock @@ -884,7 +947,7 @@ let normalize_app_path p = match List.rev p with "" :: p -> List.rev p | _ -> p let init_client_app ~app_name ?(ssl = false) ~hostname ?(port = 80) ~site_dir () - = + = Logs.debug (fun fmt -> fmt "Eliom_client.init_client_app called."); Eliom_process.appl_name_r := Some app_name; Eliom_request_info.client_app_initialised := true; @@ -901,13 +964,15 @@ let init_client_app ~app_name ?(ssl = false) ~hostname ?(port = 80) ~site_dir () { Eliom_common.cpi_ssl = ssl ; cpi_hostname = hostname ; cpi_server_port = port - ; cpi_original_full_path = site_dir @ [""] }; + ; cpi_original_full_path = site_dir @ [""] + }; Eliom_process.set_request_template None; (* We set the tab cookie table, with the app name inside: *) Eliom_process.set_request_cookies (Ocsigen_cookie_map.add ~path:[] Eliom_common.appl_name_cookie_name (Ocsigen_cookie_map.OSet (None, app_name, false)) - Ocsigen_cookie_map.empty); + Ocsigen_cookie_map.empty + ); ignore (get_global_data ()) let is_client_app () = !Eliom_common.is_client_app @@ -930,7 +995,9 @@ let set_base_url () = [ Js.to_string Dom_html.window##.location##.protocol ; "//" ; Js.to_string Dom_html.window##.location##.host - ; Js.to_string Dom_html.window##.location##.pathname ]) + ; Js.to_string Dom_html.window##.location##.pathname + ] + ) let dom_history_ready = ref false @@ -947,40 +1014,43 @@ let dom_history_ready = ref false server functions (see Eliom_uri). *) let init () = (* Initialize client app if the __eliom_server variable is defined *) - (if - is_client_app () - && Js.Optdef.test Js.Unsafe.global##.___eliom_server_ - && Js.Optdef.test Js.Unsafe.global##.___eliom_app_name_ - then - let app_name = Js.to_string Js.Unsafe.global##.___eliom_app_name_ - and site_dir = - Js.Optdef.case - Js.Unsafe.global##.___eliom_path_ - (fun () -> []) - (fun p -> normalize_app_path (Js.to_string p)) - in - match - Url.url_of_string (Js.to_string Js.Unsafe.global##.___eliom_server_) - with - | Some (Http {hu_host; hu_port; _}) -> - init_client_app ~app_name ~ssl:false ~hostname:hu_host ~port:hu_port - ~site_dir () - | Some (Https {hu_host; hu_port; _}) -> - init_client_app ~app_name ~ssl:true ~hostname:hu_host ~port:hu_port - ~site_dir () - | _ -> ()); + ( if + is_client_app () + && Js.Optdef.test Js.Unsafe.global##.___eliom_server_ + && Js.Optdef.test Js.Unsafe.global##.___eliom_app_name_ + then + let app_name = Js.to_string Js.Unsafe.global##.___eliom_app_name_ + and site_dir = + Js.Optdef.case + Js.Unsafe.global##.___eliom_path_ + (fun () -> []) + (fun p -> normalize_app_path (Js.to_string p)) + in + match + Url.url_of_string (Js.to_string Js.Unsafe.global##.___eliom_server_) + with + | Some (Http {hu_host; hu_port; _}) -> + init_client_app ~app_name ~ssl:false ~hostname:hu_host ~port:hu_port + ~site_dir () + | Some (Https {hu_host; hu_port; _}) -> + init_client_app ~app_name ~ssl:true ~hostname:hu_host ~port:hu_port + ~site_dir () + | _ -> () + ); let js_data = lazy (Eliom_request_info.get_request_data ()) in Js.Optdef.case Js.Unsafe.global##.___eliom_global_data_ (fun () -> - (* Global data are in [js_data], so we unmarshal it right away. *) - ignore (Lazy.force js_data)) + (* Global data are in [js_data], so we unmarshal it right away. *) + ignore (Lazy.force js_data) + ) (fun global_data -> - (* Global data are in a separate file. We should not unmarshal + (* Global data are in a separate file. We should not unmarshal [js_data] right away but only once the client program has been initialized. *) - ignore (Eliom_unwrap.unwrap_js global_data); - Js.Unsafe.delete Js.Unsafe.global "__eliom_global_data"); + ignore (Eliom_unwrap.unwrap_js global_data); + Js.Unsafe.delete Js.Unsafe.global "__eliom_global_data" + ); (* *) (* The first time we load the page, we record the initial URL in a client side ref, in order to set (on client-side) in header for each @@ -1000,11 +1070,12 @@ let init () = let onload _ev = let js_data = Lazy.force js_data in Logs.debug ~src:section (fun fmt -> fmt "onload (client main)"); - (match !onload_handler with + ( match !onload_handler with | Some h -> Dom.removeEventListener h; onload_handler := None - | None -> ()); + | None -> () + ); Eliom_client_core.set_initial_load (); Lwt.async (fun () -> if !Eliom_config.debug_timings @@ -1013,7 +1084,8 @@ let init () = Eliom_request_info.set_session_info ~uri: (String.concat "/" - (Eliom_request_info.get_csp_original_full_path ())) + (Eliom_request_info.get_csp_original_full_path ()) + ) js_data.Eliom_common.ejs_sess_info @@ fun () -> Lwt.return_unit in @@ -1048,7 +1120,8 @@ let init () = run_callbacks load_callbacks; if !Eliom_config.debug_timings then Console.console##(timeEnd (Js.string "onload")); - Lwt.return_unit); + Lwt.return_unit + ); Js._false in Logs.debug ~src:section (fun fmt -> fmt "Set load/onload events"); @@ -1062,31 +1135,22 @@ let init () = onload_handler := Some (Dom.addEventListener Dom_html.window (Dom.Event.make "load") - (Dom.handler onload) Js._true); + (Dom.handler onload) Js._true + ); add_string_event_listener Dom_html.window "beforeunload" onbeforeunload_fun false; ignore (Dom.addEventListener Dom_html.window (Dom.Event.make "unload") (Dom_html.handler onunload_fun) - Js._false) + Js._false + ) (* == Low-level: call service. *) -let create_request__ - ?absolute - ?absolute_path - ?https - (type m) - ~(service : (_, _, m, _, _, _, _, _, _, _, _) Eliom_service.t) - ?hostname - ?port - ?fragment - ?keep_nl_params - ?nl_params - ?keep_get_na_params - get_params - post_params - = +let create_request__ ?absolute ?absolute_path ?https (type m) + ~(service : (_, _, m, _, _, _, _, _, _, _, _) Eliom_service.t) ?hostname + ?port ?fragment ?keep_nl_params ?nl_params ?keep_get_na_params get_params + post_params = let path, get_params, fragment, post_params = Eliom_uri.make_post_uri_components__ ?absolute ?absolute_path ?https ~service ?hostname ?port ?fragment ?keep_nl_params ?nl_params @@ -1097,21 +1161,10 @@ let create_request__ in uri, get_params, post_params -let create_request_ - (type m) - ?absolute - ?absolute_path - ?https - ~(service : (_, _, m, _, _, _, _, _, _, _, _) Eliom_service.t) - ?hostname - ?port - ?fragment - ?keep_nl_params - ?nl_params - ?keep_get_na_params - get_params - post_params - = +let create_request_ (type m) ?absolute ?absolute_path ?https + ~(service : (_, _, m, _, _, _, _, _, _, _, _) Eliom_service.t) ?hostname + ?port ?fragment ?keep_nl_params ?nl_params ?keep_get_na_params get_params + post_params = (* TODO: allow get_get_or_post service to return also the service with the correct subtype. Then do use Eliom_uri.make_string_uri and Eliom_uri.make_post_uri_components instead of @@ -1129,35 +1182,24 @@ let create_request_ `Post (create_request__ ?absolute ?absolute_path ?https ~service ?hostname ?port ?fragment ?keep_nl_params ?nl_params ?keep_get_na_params - get_params post_params) + get_params post_params + ) | Eliom_service.Put' -> `Put (create_request__ ?absolute ?absolute_path ?https ~service ?hostname ?port ?fragment ?keep_nl_params ?nl_params ?keep_get_na_params - get_params post_params) + get_params post_params + ) | Eliom_service.Delete' -> `Delete (create_request__ ?absolute ?absolute_path ?https ~service ?hostname ?port ?fragment ?keep_nl_params ?nl_params ?keep_get_na_params - get_params post_params) - -let raw_call_service - ?absolute - ?absolute_path - ?https - ~service - ?hostname - ?port - ?fragment - ?keep_nl_params - ?nl_params - ?keep_get_na_params - ?progress - ?upload_progress - ?override_mime_type - get_params - post_params - = + get_params post_params + ) + +let raw_call_service ?absolute ?absolute_path ?https ~service ?hostname ?port + ?fragment ?keep_nl_params ?nl_params ?keep_get_na_params ?progress + ?upload_progress ?override_mime_type get_params post_params = (* with_credentials = true is necessary for client side apps when we want the Eliom server to be different from the server for static files (if any). For example when testing a mobile app @@ -1196,23 +1238,9 @@ let raw_call_service | None -> Lwt.fail (Eliom_request.Failed_request 204) | Some content -> Lwt.return (uri, content) -let call_service - ?absolute - ?absolute_path - ?https - ~service - ?hostname - ?port - ?fragment - ?keep_nl_params - ?nl_params - ?keep_get_na_params - ?progress - ?upload_progress - ?override_mime_type - get_params - post_params - = +let call_service ?absolute ?absolute_path ?https ~service ?hostname ?port + ?fragment ?keep_nl_params ?nl_params ?keep_get_na_params ?progress + ?upload_progress ?override_mime_type get_params post_params = let* _, content = raw_call_service ?absolute ?absolute_path ?https ~service ?hostname ?port ?fragment ?keep_nl_params ?nl_params ?keep_get_na_params ?progress @@ -1222,22 +1250,9 @@ let call_service (* == Leave an application. *) -let exit_to - ?window_name - ?window_features - ?absolute - ?absolute_path - ?https - ~service - ?hostname - ?port - ?fragment - ?keep_nl_params - ?nl_params - ?keep_get_na_params - get_params - post_params - = +let exit_to ?window_name ?window_features ?absolute ?absolute_path ?https + ~service ?hostname ?port ?fragment ?keep_nl_params ?nl_params + ?keep_get_na_params get_params post_params = match create_request_ ?absolute ?absolute_path ?https ~service ?hostname ?port ?fragment ?keep_nl_params ?nl_params ?keep_get_na_params get_params @@ -1252,28 +1267,17 @@ let exit_to | `Delete (uri, _, post_params) -> Eliom_request.redirect_delete ?window_name uri post_params -let window_open - ~window_name - ?window_features - ?absolute - ?absolute_path - ?https - ~service - ?hostname - ?port - ?fragment - ?keep_nl_params - ?nl_params - ?keep_get_na_params - get_params - = +let window_open ~window_name ?window_features ?absolute ?absolute_path ?https + ~service ?hostname ?port ?fragment ?keep_nl_params ?nl_params + ?keep_get_na_params get_params = match create_request_ ?absolute ?absolute_path ?https ~service ?hostname ?port ?fragment ?keep_nl_params ?nl_params ?keep_get_na_params get_params () with | `Get (uri, _) -> Dom_html.window##(open_ (Js.string uri) window_name - (Js.Opt.option window_features)) + (Js.Opt.option window_features) + ) | `Post (_, _, _) -> assert false | `Put (_, _, _) -> assert false | `Delete (_, _, _) -> assert false @@ -1290,23 +1294,9 @@ let unwrap_caml_content content = in Lwt.return (r.Eliom_runtime.ecs_data, r.Eliom_runtime.ecs_request_data) -let call_ocaml_service - ?absolute - ?absolute_path - ?https - ~service - ?hostname - ?port - ?fragment - ?keep_nl_params - ?nl_params - ?keep_get_na_params - ?progress - ?upload_progress - ?override_mime_type - get_params - post_params - = +let call_ocaml_service ?absolute ?absolute_path ?https ~service ?hostname ?port + ?fragment ?keep_nl_params ?nl_params ?keep_get_na_params ?progress + ?upload_progress ?override_mime_type get_params post_params = Logs.debug ~src:section (fun fmt -> fmt "Call OCaml service"); let* _, content = raw_call_service ?absolute ?absolute_path ?https ~service ?hostname ?port @@ -1344,7 +1334,8 @@ let path_and_args_of_uri uri = | Some n -> ( path_of_string String.(sub uri 0 n) , Url.decode_arguments String.(sub uri (n + 1) (length uri - n - 1)) ) - | None -> path_of_string uri, []) + | None -> path_of_string uri, [] + ) let set_current_uri, get_current_uri = let set_current_uri uri = @@ -1353,7 +1344,8 @@ let set_current_uri, get_current_uri = let path, all_get_params = path_and_args_of_uri current_uri in Lwt.async @@ fun () -> Eliom_request_info.update_session_info ~path ~all_get_params - ~all_post_params:None (fun () -> Lwt.return_unit) + ~all_post_params:None (fun () -> Lwt.return_unit + ) in let get_current_uri () = (get_this_page ()).url in set_current_uri, get_current_uri @@ -1384,7 +1376,8 @@ let push_history_dom () = else Dom_html.document##.documentElement in page.dom <- Some dom; - History.garbage_collect_doms ()) + History.garbage_collect_doms () + ) module Page_status = struct include Page_status_t @@ -1423,7 +1416,8 @@ module Page_status = struct if now && React.S.value (signal ()) = Active then ( action (); - if not once then on_event ()) + if not once then on_event () + ) else on_event () let oncached ?(once = false) ?stop action = @@ -1455,7 +1449,8 @@ let stash_reload_function f = let state_id = page.page_id in let id = state_id.state_index in Logs.debug ~src:section_page (fun fmt -> - fmt "Update reload function for page %d" id); + fmt "Update reload function for page %d" id + ); page.reload_function <- Some f let change_url_string ~replace uri = @@ -1471,46 +1466,45 @@ let change_url_string ~replace uri = Dom_html.window##.history##replaceState (Js.Opt.return (Js.string - (to_json ~typ:[%json: saved_state] (this_page.page_id, full_uri)))) + (to_json ~typ:[%json: saved_state] (this_page.page_id, full_uri)) + ) + ) (Js.string "") - (if !Eliom_common.is_client_app - then Js.null - else Js.Opt.return (Js.string uri))) + ( if !Eliom_common.is_client_app + then Js.null + else Js.Opt.return (Js.string uri) + ) + ) else ( update_state (); Opt.iter stash_reload_function !reload_function; Dom_html.window##.history##pushState (Js.Opt.return (Js.string - (to_json ~typ:[%json: saved_state] (this_page.page_id, full_uri)))) + (to_json ~typ:[%json: saved_state] (this_page.page_id, full_uri)) + ) + ) (Js.string "") - (if !Eliom_common.is_client_app - then Js.null - else Js.Opt.return (Js.string uri))); - Eliommod_dom.touch_base ()) + ( if !Eliom_common.is_client_app + then Js.null + else Js.Opt.return (Js.string uri) + ) + ); + Eliommod_dom.touch_base () + ) else ( current_pseudo_fragment := url_fragment_prefix_with_sharp ^ uri; if uri <> fst (Url.split_fragment Url.Current.as_string) then - Dom_html.window##.location##.hash := Js.string (url_fragment_prefix ^ uri)) + Dom_html.window##.location##.hash := Js.string (url_fragment_prefix ^ uri) + ) (* == Function [change_url] changes the URL, without doing a request. It takes a GET (co-)service as parameter and its parameters. *) -let change_url - ?(replace = false) - ?absolute - ?absolute_path - ?https - ~service - ?hostname - ?port - ?fragment - ?keep_nl_params - ?nl_params - params - = +let change_url ?(replace = false) ?absolute ?absolute_path ?https ~service + ?hostname ?port ?fragment ?keep_nl_params ?nl_params params = Logs.debug ~src:section_page (fun fmt -> fmt "Change url"); (reload_function := match Eliom_service.xhr_with_cookies service with @@ -1523,17 +1517,21 @@ let change_url | _ -> ( match Eliom_service.reload_fun service with | Some rf -> Some (fun () () -> rf params ()) - | None -> None)); + | None -> None + ) + ); change_url_string ~replace (Eliom_uri.make_string_uri ?absolute ?absolute_path ?https ~service - ?hostname ?port ?fragment ?keep_nl_params ?nl_params params) + ?hostname ?port ?fragment ?keep_nl_params ?nl_params params + ) let set_template_content ~replace ~uri ?fragment = let really_set content () = reload_function := None; - (match fragment with + ( match fragment with | None -> change_url_string ~replace uri - | Some fragment -> change_url_string ~replace (uri ^ "#" ^ fragment)); + | Some fragment -> change_url_string ~replace (uri ^ "#" ^ fragment) + ); let* () = Lwt_mutex.lock Eliom_client_core.load_mutex in let* (), request_data = unwrap_caml_content content in do_request_data request_data; @@ -1544,8 +1542,8 @@ let set_template_content ~replace ~uri ?fragment = Lwt.return_unit and cancel () = Lwt.return_unit in function - | None -> Lwt.return_unit - | Some content -> run_onunload_wrapper (really_set content) cancel + | None -> Lwt.return_unit + | Some content -> run_onunload_wrapper (really_set content) cancel let set_uri ~replace ?fragment uri = (* Changing url: *) @@ -1562,14 +1560,16 @@ let replace_page ~do_insert_base new_page = Js.Opt.iter new_body (fun new_body -> Dom.replaceChild Dom_html.document##.documentElement - new_body Dom_html.document##.body) + new_body Dom_html.document##.body + ) else ( (* We insert in the page. The URLs of all other pages will be computed w.r.t. the base URL. *) if do_insert_base then insert_base new_page; Dom.replaceChild Dom_html.document new_page - Dom_html.document##.documentElement); + Dom_html.document##.documentElement + ); if !Eliom_config.debug_timings then Console.console##(timeEnd (Js.string "replace_page")) @@ -1602,7 +1602,8 @@ let set_content_local ?offset ?fragment new_page = locked := false; Lwt_mutex.unlock Eliom_client_core.load_mutex; (* run callbacks upon page activation (or now), but just once *) - Page_status.onactive ~once:true (fun () -> run_callbacks load_callbacks); + Page_status.onactive ~once:true (fun () -> run_callbacks load_callbacks + ); scroll_to_fragment ?offset fragment; advance_page (); if !Eliom_config.debug_timings @@ -1612,16 +1613,19 @@ let set_content_local ?offset ?fragment new_page = let cancel () = recover (); Lwt.return_unit in Lwt.catch (fun () -> - let* () = Lwt_mutex.lock Eliom_client_core.load_mutex in - Eliom_client_core.set_loading_phase (); - if !Eliom_config.debug_timings - then Console.console##(time (Js.string "set_content_local")); - run_onunload_wrapper really_set cancel) + let* () = Lwt_mutex.lock Eliom_client_core.load_mutex in + Eliom_client_core.set_loading_phase (); + if !Eliom_config.debug_timings + then Console.console##(time (Js.string "set_content_local")); + run_onunload_wrapper really_set cancel + ) (fun exn -> - recover (); - Logs.debug ~src:section (fun fmt -> - fmt ("set_content_local" ^^ "@\n%s") (Printexc.to_string exn)); - Lwt.fail exn) + recover (); + Logs.debug ~src:section (fun fmt -> + fmt ("set_content_local" ^^ "@\n%s") (Printexc.to_string exn) + ); + Lwt.fail exn + ) (* Function to be called for server side services: *) let set_content ~replace ~uri ?offset ?fragment content = @@ -1634,7 +1638,8 @@ let set_content ~replace ~uri ?offset ?fragment content = ; origin_uri = get_current_uri () ; target_uri ; origin_id = !active_page.page_id.state_index - ; target_id = None } + ; target_id = None + } (flush_onchangepage ()) in match content with @@ -1725,17 +1730,20 @@ let set_content ~replace ~uri ?offset ?fragment content = in Lwt.catch (fun () -> - let* () = Lwt_mutex.lock Eliom_client_core.load_mutex in - Eliom_client_core.set_loading_phase (); - if !Eliom_config.debug_timings - then Console.console##(time (Js.string "set_content")); - let g () = recover (); Lwt.return_unit in - run_onunload_wrapper really_set g) + let* () = Lwt_mutex.lock Eliom_client_core.load_mutex in + Eliom_client_core.set_loading_phase (); + if !Eliom_config.debug_timings + then Console.console##(time (Js.string "set_content")); + let g () = recover (); Lwt.return_unit in + run_onunload_wrapper really_set g + ) (fun exn -> - recover (); - Logs.debug ~src:section (fun fmt -> - fmt ("set_content" ^^ "@\n%s") (Printexc.to_string exn)); - Lwt.fail exn) + recover (); + Logs.debug ~src:section (fun fmt -> + fmt ("set_content" ^^ "@\n%s") (Printexc.to_string exn) + ); + Lwt.fail exn + ) let ocamlify_params = List.map (function v, `String s -> v, Js.to_string s | _, _ -> assert false) @@ -1772,7 +1780,8 @@ let route ({Eliom_route.i_subpath; i_get_params; i_post_params; _} as info) = Eliom_route.call_service { info with Eliom_route.i_get_params = - Eliom_common.(remove_prefixed_param nl_param_prefix) i_get_params } + Eliom_common.(remove_prefixed_param nl_param_prefix) i_get_params + } in Lwt.return (uri, result) @@ -1798,7 +1807,8 @@ let string_of_result result = let rec handle_result ~replace ~uri result = let* result = result in Logs.debug ~src:section_page (fun fmt -> - fmt "%s" ("handle_result: result is " ^ string_of_result result)); + fmt "%s" ("handle_result: result is " ^ string_of_result result) + ); match result with | Eliom_service.No_contents -> Lwt.return_unit | Dom d -> @@ -1818,23 +1828,24 @@ let rec handle_result ~replace ~uri result = reload ~replace ~uri ~fallback:Eliom_service.reload_action_hidden | true, true -> switch_to_https (); - reload ~replace ~uri ~fallback:Eliom_service.reload_action_https_hidden) + reload ~replace ~uri ~fallback:Eliom_service.reload_action_https_hidden + ) (* == Main (exported) function: change the content of the page without leaving the javascript application. See [change_page_uri] for the function used to change page when clicking a link and [change_page_{get,post}_form] when submiting a form. *) and change_page : - 'get 'post 'meth 'attached 'co 'ext 'reg 'tipo 'gn 'pn. - ?ignore_client_fun:bool - -> ?replace:bool - -> ?window_name:string - -> ?window_features:string - -> ?absolute:bool - -> ?absolute_path:bool - -> ?https:bool - -> service: - ( 'get + 'get 'post 'meth 'attached 'co 'ext 'reg 'tipo 'gn 'pn. + ?ignore_client_fun:bool + -> ?replace:bool + -> ?window_name:string + -> ?window_features:string + -> ?absolute:bool + -> ?absolute_path:bool + -> ?https:bool + -> service: + ( 'get , 'post , 'meth , 'attached @@ -1844,161 +1855,151 @@ and change_page : , 'tipo , 'gn , 'pn - , Eliom_service.non_ocaml ) + , Eliom_service.non_ocaml + ) Eliom_service.t - -> ?hostname:string - -> ?port:int - -> ?fragment:string - -> ?keep_nl_params:[`All | `None | `Persistent] - -> ?nl_params:Eliom_parameter.nl_params_set - -> ?keep_get_na_params:bool - -> ?progress:(int -> int -> unit) - -> ?upload_progress:(int -> int -> unit) - -> ?override_mime_type:string - -> 'get - -> 'post - -> unit Lwt.t - = - fun (type m) - ?(ignore_client_fun = false) - ?(replace = false) - ?window_name - ?window_features - ?absolute - ?absolute_path - ?https - ~(service : (_, _, m, _, _, _, _, _, _, _, _) Eliom_service.t) - ?hostname - ?port - ?fragment - ?keep_nl_params - ?(nl_params = Eliom_parameter.empty_nl_params_set) - ?keep_get_na_params - ?progress - ?upload_progress - ?override_mime_type - get_params - post_params -> - Logs.debug ~src:section_page (fun fmt -> fmt "Change page"); - let xhr = Eliom_service.xhr_with_cookies service in - if - xhr = None - || (https = Some true && not Eliom_request_info.ssl_) - || (https = Some false && Eliom_request_info.ssl_) - || (window_name <> None && window_name <> Some "_self") - then - let () = - Logs.debug ~src:section_page (fun fmt -> fmt "change page: xhr is None") - in - Lwt.return - (exit_to ?window_name ?window_features ?absolute ?absolute_path ?https - ~service ?hostname ?port ?fragment ?keep_nl_params ~nl_params - ?keep_get_na_params get_params post_params) - else - with_progress_cursor - (match xhr with - | Some (Some tmpl as t) - when t = Eliom_request_info.get_request_template () -> - Logs.debug ~src:section_page (fun fmt -> - fmt "change page: xhr is Some of get request template"); - let nl_params = - Eliom_parameter.add_nl_parameter nl_params Eliom_request.nl_template - tmpl - in - let* uri, content = - raw_call_service ?absolute ?absolute_path ?https ~service ?hostname - ?port ?fragment ?keep_nl_params ~nl_params ?keep_get_na_params - ?progress ?upload_progress ?override_mime_type get_params - post_params - in - set_template_content ~replace ~uri ?fragment (Some content) - | _ -> ( - match Eliom_service.client_fun service with - | Some f when not ignore_client_fun -> - Logs.debug ~src:section_page (fun fmt -> - fmt - "change page: client_fun service is Some and (not ignore_client_fun)"); - (* The service has a client side implementation. + -> ?hostname:string + -> ?port:int + -> ?fragment:string + -> ?keep_nl_params:[`All | `None | `Persistent] + -> ?nl_params:Eliom_parameter.nl_params_set + -> ?keep_get_na_params:bool + -> ?progress:(int -> int -> unit) + -> ?upload_progress:(int -> int -> unit) + -> ?override_mime_type:string + -> 'get + -> 'post + -> unit Lwt.t = + fun (type m) ?(ignore_client_fun = false) ?(replace = false) ?window_name + ?window_features ?absolute ?absolute_path ?https + ~(service : (_, _, m, _, _, _, _, _, _, _, _) Eliom_service.t) ?hostname + ?port ?fragment ?keep_nl_params + ?(nl_params = Eliom_parameter.empty_nl_params_set) ?keep_get_na_params + ?progress ?upload_progress ?override_mime_type get_params post_params -> + Logs.debug ~src:section_page (fun fmt -> fmt "Change page"); + let xhr = Eliom_service.xhr_with_cookies service in + if + xhr = None + || (https = Some true && not Eliom_request_info.ssl_) + || (https = Some false && Eliom_request_info.ssl_) + || (window_name <> None && window_name <> Some "_self") + then + let () = + Logs.debug ~src:section_page (fun fmt -> fmt "change page: xhr is None") + in + Lwt.return + (exit_to ?window_name ?window_features ?absolute ?absolute_path ?https + ~service ?hostname ?port ?fragment ?keep_nl_params ~nl_params + ?keep_get_na_params get_params post_params + ) + else + with_progress_cursor + ( match xhr with + | Some (Some tmpl as t) + when t = Eliom_request_info.get_request_template () -> + Logs.debug ~src:section_page (fun fmt -> + fmt "change page: xhr is Some of get request template" + ); + let nl_params = + Eliom_parameter.add_nl_parameter nl_params + Eliom_request.nl_template tmpl + in + let* uri, content = + raw_call_service ?absolute ?absolute_path ?https ~service ?hostname + ?port ?fragment ?keep_nl_params ~nl_params ?keep_get_na_params + ?progress ?upload_progress ?override_mime_type get_params + post_params + in + set_template_content ~replace ~uri ?fragment (Some content) + | _ -> ( + match Eliom_service.client_fun service with + | Some f when not ignore_client_fun -> + Logs.debug ~src:section_page (fun fmt -> + fmt + "change page: client_fun service is Some and (not ignore_client_fun)" + ); + (* The service has a client side implementation. We do not make the request *) - (* I record the function to be used for void coservices: *) - Eliom_lib.Option.iter - (fun rf -> reload_function := Some (fun () -> rf get_params)) - (Eliom_service.reload_fun service); - let uri, l, l' = - match - create_request_ ~absolute:true ?absolute_path ?https ~service - ?hostname ?port ?fragment ?keep_nl_params ~nl_params - ?keep_get_na_params get_params post_params - with - | `Get (uri, l) -> uri, l, None - | `Post (uri, l, l') | `Put (uri, l, l') | `Delete (uri, l, l') -> - uri, l, Some (ocamlify_params l') - in - let l = ocamlify_params l in - Eliom_request_info.update_session_info - ~path:(Url.path_of_url_string uri) - ~all_get_params:l ~all_post_params:l' - @@ fun () -> - let* () = - run_lwt_callbacks - { in_cache = is_in_cache !active_page.page_id - ; origin_uri = get_current_uri () - ; target_uri = uri - ; origin_id = !active_page.page_id.state_index - ; target_id = None } - (flush_onchangepage ()) - in - with_new_page ~replace () @@ fun () -> - handle_result ~replace ~uri (f get_params post_params) - | None when is_client_app () -> - Logs.debug ~src:section_page (fun fmt -> - fmt "change page: client_fun service is None and is_client_app"); - Lwt.return - @@ exit_to ?absolute ?absolute_path ?https ~service ?hostname ?port - ?fragment ?keep_nl_params ~nl_params ?keep_get_na_params - get_params post_params - | _ -> - Logs.debug ~src:section_page (fun fmt -> - fmt "change page: client_fun service is anything else"); - if is_client_app () - then - failwith - (Printf.sprintf "change page: no client-side service (%b)" - ignore_client_fun); - (* No client-side implementation *) - with_new_page ~replace () @@ fun () -> - reload_function := None; - let cookies_info = Eliom_uri.make_cookies_info (https, service) in - let* uri, content = - match - create_request_ ?absolute ?absolute_path ?https ~service - ?hostname ?port ?fragment ?keep_nl_params ~nl_params - ?keep_get_na_params get_params post_params - with - | `Get (uri, _) -> - Eliom_request.http_get ~expecting_process_page:true - ?cookies_info uri [] Eliom_request.xml_result - | `Post (uri, _, p) -> - Eliom_request.http_post ~expecting_process_page:true - ?cookies_info uri p Eliom_request.xml_result - | `Put (uri, _, p) -> - Eliom_request.http_put ~expecting_process_page:true - ?cookies_info uri p Eliom_request.xml_result - | `Delete (uri, _, p) -> - Eliom_request.http_delete ~expecting_process_page:true - ?cookies_info uri p Eliom_request.xml_result - in - let uri, fragment = Url.split_fragment uri in - set_content ~replace ~uri ?fragment content)) - -and change_page_unknown - ?meth - ?hostname:_ - ?(replace = false) - i_subpath - i_get_params - i_post_params - = + (* I record the function to be used for void coservices: *) + Eliom_lib.Option.iter + (fun rf -> reload_function := Some (fun () -> rf get_params)) + (Eliom_service.reload_fun service); + let uri, l, l' = + match + create_request_ ~absolute:true ?absolute_path ?https ~service + ?hostname ?port ?fragment ?keep_nl_params ~nl_params + ?keep_get_na_params get_params post_params + with + | `Get (uri, l) -> uri, l, None + | `Post (uri, l, l') | `Put (uri, l, l') | `Delete (uri, l, l') + -> + uri, l, Some (ocamlify_params l') + in + let l = ocamlify_params l in + Eliom_request_info.update_session_info + ~path:(Url.path_of_url_string uri) + ~all_get_params:l ~all_post_params:l' + @@ fun () -> + let* () = + run_lwt_callbacks + { in_cache = is_in_cache !active_page.page_id + ; origin_uri = get_current_uri () + ; target_uri = uri + ; origin_id = !active_page.page_id.state_index + ; target_id = None + } + (flush_onchangepage ()) + in + with_new_page ~replace () @@ fun () -> + handle_result ~replace ~uri (f get_params post_params) + | None when is_client_app () -> + Logs.debug ~src:section_page (fun fmt -> + fmt "change page: client_fun service is None and is_client_app" + ); + Lwt.return + @@ exit_to ?absolute ?absolute_path ?https ~service ?hostname ?port + ?fragment ?keep_nl_params ~nl_params ?keep_get_na_params + get_params post_params + | _ -> + Logs.debug ~src:section_page (fun fmt -> + fmt "change page: client_fun service is anything else" + ); + if is_client_app () + then + failwith + (Printf.sprintf "change page: no client-side service (%b)" + ignore_client_fun + ); + (* No client-side implementation *) + with_new_page ~replace () @@ fun () -> + reload_function := None; + let cookies_info = Eliom_uri.make_cookies_info (https, service) in + let* uri, content = + match + create_request_ ?absolute ?absolute_path ?https ~service + ?hostname ?port ?fragment ?keep_nl_params ~nl_params + ?keep_get_na_params get_params post_params + with + | `Get (uri, _) -> + Eliom_request.http_get ~expecting_process_page:true + ?cookies_info uri [] Eliom_request.xml_result + | `Post (uri, _, p) -> + Eliom_request.http_post ~expecting_process_page:true + ?cookies_info uri p Eliom_request.xml_result + | `Put (uri, _, p) -> + Eliom_request.http_put ~expecting_process_page:true + ?cookies_info uri p Eliom_request.xml_result + | `Delete (uri, _, p) -> + Eliom_request.http_delete ~expecting_process_page:true + ?cookies_info uri p Eliom_request.xml_result + in + let uri, fragment = Url.split_fragment uri in + set_content ~replace ~uri ?fragment content + ) + ) + +and change_page_unknown ?meth ?hostname:_ ?(replace = false) i_subpath + i_get_params i_post_params = Logs.debug ~src:section_page (fun fmt -> fmt "Change page unknown"); let i_sess_info = Eliom_request_info.get_sess_info () and i_meth = @@ -2021,7 +2022,8 @@ and reload ~replace ~uri ~fallback = Lwt.catch (fun () -> change_page_unknown ~replace path args []) (fun _ -> - change_page ~replace ~ignore_client_fun:true ~service:fallback () ()) + change_page ~replace ~ignore_client_fun:true ~service:fallback () () + ) and reload_without_na_params ~replace ~uri ~fallback = let path, args = path_and_args_of_uri uri in @@ -2030,7 +2032,8 @@ and reload_without_na_params ~replace ~uri ~fallback = Lwt.catch (fun () -> change_page_unknown ~replace path args []) (fun _ -> - change_page ~replace ~ignore_client_fun:true ~service:fallback () ()) + change_page ~replace ~ignore_client_fun:true ~service:fallback () () + ) (* Function used in "onclick" event handler of . *) let change_page_uri_a ?cookies_info ?tmpl ?(get_params = []) full_uri = @@ -2054,31 +2057,39 @@ let change_page_uri_a ?cookies_info ?tmpl ?(get_params = []) full_uri = Eliom_request.http_get ~expecting_process_page:true ?cookies_info uri get_params Eliom_request.xml_result in - set_content ~replace:false ~uri ?fragment content) + set_content ~replace:false ~uri ?fragment content + ) else ( change_url_string ~replace:true full_uri; scroll_to_fragment fragment; - Lwt.return_unit)) + Lwt.return_unit + ) + ) let change_page_uri ?replace full_uri = Logs.debug ~src:section_page (fun fmt -> fmt "Change page uri"); Lwt.catch (fun () -> - match Url.url_of_string full_uri with - | Some (Url.Http url | Url.Https url) -> - Logs.debug ~src:section_page (fun fmt -> - fmt "change page uri: url is http or https"); - change_page_unknown ?replace url.Url.hu_path url.Url.hu_arguments [] - | _ -> failwith "invalid url") + match Url.url_of_string full_uri with + | Some (Url.Http url | Url.Https url) -> + Logs.debug ~src:section_page (fun fmt -> + fmt "change page uri: url is http or https" + ); + change_page_unknown ?replace url.Url.hu_path url.Url.hu_arguments [] + | _ -> failwith "invalid url" + ) (fun _ -> - if is_client_app () - then - failwith - (Printf.sprintf "Change page uri: can't find service for %s" full_uri) - else ( - Logs.debug ~src:section (fun fmt -> - fmt "Change page uri: resort to server"); - change_page_uri_a full_uri)) + if is_client_app () + then + failwith + (Printf.sprintf "Change page uri: can't find service for %s" full_uri) + else ( + Logs.debug ~src:section (fun fmt -> + fmt "Change page uri: resort to server" + ); + change_page_uri_a full_uri + ) + ) (* Functions used in "onsubmit" event handler of
. *) @@ -2099,7 +2110,8 @@ let change_page_get_form ?cookies_info ?tmpl form full_uri = Eliom_request.send_get_form ~expecting_process_page:true ?cookies_info form uri Eliom_request.xml_result in - set_content ~replace:false ~uri ?fragment content) + set_content ~replace:false ~uri ?fragment content + ) let change_page_post_form ?cookies_info ?tmpl form full_uri = with_progress_cursor @@ -2118,15 +2130,18 @@ let change_page_post_form ?cookies_info ?tmpl form full_uri = Eliom_request.send_post_form ~expecting_process_page:true ?cookies_info form uri Eliom_request.xml_result in - set_content ~replace:false ~uri ?fragment content) + set_content ~replace:false ~uri ?fragment content + ) let _ = (Eliom_client_core.change_page_uri_ := fun ?cookies_info ?tmpl href -> - Lwt.ignore_result (change_page_uri_a ?cookies_info ?tmpl href)); + Lwt.ignore_result (change_page_uri_a ?cookies_info ?tmpl href) + ); (Eliom_client_core.change_page_get_form_ := fun ?cookies_info ?tmpl form href -> - Lwt.ignore_result (change_page_get_form ?cookies_info ?tmpl form href)); + Lwt.ignore_result (change_page_get_form ?cookies_info ?tmpl form href) + ); Eliom_client_core.change_page_post_form_ := fun ?cookies_info ?tmpl form href -> Lwt.ignore_result (change_page_post_form ?cookies_info ?tmpl form href) @@ -2141,7 +2156,7 @@ let _ = let restore_history_dom id = match History.find_by_state_index id with | Some page -> - (match page.dom with + ( match page.dom with | Some dom -> if !only_replace_body then @@ -2151,7 +2166,8 @@ let restore_history_dom id = else Dom.replaceChild Dom_html.document dom Dom_html.document##.documentElement - | None -> Logs.err ~src:section (fun fmt -> fmt "DOM not actually cached")); + | None -> Logs.err ~src:section (fun fmt -> fmt "DOM not actually cached") + ); set_active_page page | _ -> Logs.err ~src:section (fun fmt -> fmt "cannot find DOM in history") @@ -2167,7 +2183,8 @@ let () = failwith (Printf.sprintf "revisit: state id %x/%x not found in sessionStorage (%s)" - state_id.session_id state_id.state_index full_uri) + state_id.session_id state_id.state_index full_uri + ) in let target_id = state_id.state_index in let ev = @@ -2175,7 +2192,8 @@ let () = ; origin_uri = get_current_uri () ; target_uri = full_uri ; origin_id = !active_page.page_id.state_index - ; target_id = Some target_id } + ; target_id = Some target_id + } in let tmpl = state.template in Lwt.ignore_result @@ with_progress_cursor @@ -2184,15 +2202,18 @@ let () = if uri = get_current_uri () then ( Logs.debug ~src:section_page (fun fmt -> - fmt "revisit: uri = get_current_uri"); + fmt "revisit: uri = get_current_uri" + ); !active_page.page_id <- state_id; scroll_to_fragment ~offset:state.position fragment; - Lwt.return_unit) + Lwt.return_unit + ) else try (* serve cached page from the from history_doms *) Logs.debug ~src:section_page (fun fmt -> - fmt "revisit: uri != get_current_uri"); + fmt "revisit: uri != get_current_uri" + ); if not (is_in_cache state_id) then raise Not_found; let* () = run_lwt_callbacks ev (flush_onchangepage ()) in restore_history_dom target_id; @@ -2217,12 +2238,14 @@ let () = failwith (Printf.sprintf "revisit: session changed on client: %d => %d (%s)" - state_id.session_id session_id full_uri); + state_id.session_id session_id full_uri + ); try (* same session *) if session_changed then raise Not_found; Logs.debug ~src:section_page (fun fmt -> - fmt "revisit: session has not changed"); + fmt "revisit: session has not changed" + ); let old_page = History.find_by_state_index state_id.state_index in let rf = Option.bind old_page @@ fun {reload_function = rf; _} -> rf @@ -2240,7 +2263,8 @@ let () = | Eliom_service.Dom d -> set_content_local d | r -> handle_result ~uri:(get_current_uri ()) ~replace:true - (Lwt.return r)) + (Lwt.return r) + ) in scroll_to_fragment ~offset:state.position fragment; Lwt.return_unit @@ -2251,7 +2275,8 @@ let () = | Some t when tmpl = Eliom_request_info.get_request_template () -> Logs.debug ~src:section_page (fun fmt -> fmt - "revisit: template is Some and equals to get_request_template"); + "revisit: template is Some and equals to get_request_template" + ); let* uri, content = Eliom_request.http_get uri [Eliom_request.nl_template_string, t] @@ -2266,9 +2291,11 @@ let () = failwith (Printf.sprintf "revisit: could not generate page client-side (%s)" - full_uri); + full_uri + ); Logs.debug ~src:section_page (fun fmt -> - fmt "revisit: template is anything else"); + fmt "revisit: template is anything else" + ); with_new_page ?state_id:(if session_changed then None else Some state_id) ~replace:false () @@ -2281,7 +2308,9 @@ let () = set_content ~uri ~replace:true ~offset:state.position ?fragment content in - Lwt.return_unit)) + Lwt.return_unit + ) + ) in let revisit_wrapper full_uri state_id = Logs.debug ~src:section_page (fun fmt -> fmt "revisit_wrapper"); @@ -2294,7 +2323,8 @@ let () = Lwt.ignore_result (let* () = wait_load_end () in Logs.debug ~src:section_page (fun fmt -> - fmt "revisit_wrapper: replaceState"); + fmt "revisit_wrapper: replaceState" + ); Dom_html.window##.history##(replaceState (Js.Opt.return (Js.string @@ -2302,23 +2332,30 @@ let () = ( !active_page.page_id , Js.to_string Dom_html.window##.location##.href - )))) - (Js.string "") Js.null); - Lwt.return_unit); + ) + ) + ) + ) + (Js.string "") Js.null + ); + Lwt.return_unit + ); Dom_html.window##.onpopstate := Dom_html.handler (fun event -> - Logs.debug ~src:section_page (fun fmt -> - fmt "revisit_wrapper: onpopstate"); + Logs.debug ~src:section_page (fun fmt -> fmt "revisit_wrapper: onpopstate"); Eliommod_dom.touch_base (); Js.Opt.case ((Js.Unsafe.coerce event)##.state : _ Js.opt) (fun () -> () (* Ignore dummy popstate event fired by chromium. *)) (fun saved_state -> - let state, full_uri = - of_json ~typ:[%json: saved_state] (Js.to_string saved_state) - in - revisit_wrapper full_uri state); - Js._false)) + let state, full_uri = + of_json ~typ:[%json: saved_state] (Js.to_string saved_state) + in + revisit_wrapper full_uri state + ); + Js._false + ) + ) else (* Without history API *) (* FIXME: This should be adapted to work with template... Solution: add the "state_id" in the fragment ?? @@ -2340,9 +2377,11 @@ let () = in Logs.debug ~src:section_page (fun fmt -> fmt "auto_change_page"); (* CCC TODO handle templates *) - change_page_uri uri) + change_page_uri uri + ) else Lwt.return_unit - else Lwt.return_unit) + else Lwt.return_unit + ) in Eliommod_dom.onhashchange (fun s -> auto_change_page (Js.to_string s)); let first_fragment = read_fragment () in @@ -2351,17 +2390,19 @@ let () = Lwt.ignore_result (let* () = wait_load_end () in auto_change_page first_fragment; - Lwt.return_unit) + Lwt.return_unit + ) let () = Eliom_unwrap.register_unwrapper (Eliom_unwrap.id_of_int Eliom_common_base.server_function_unwrap_id_int) (fun (service, _) -> - (* 2013-07-31 I make all RPC's absolute because otherwise + (* 2013-07-31 I make all RPC's absolute because otherwise it does not work with mobile apps. Is it a problem? -- Vincent *) - call_ocaml_service ~absolute:true ~service ()) + call_ocaml_service ~absolute:true ~service () + ) let get_application_name = Eliom_process.get_application_name let set_client_html_file = Eliom_common.set_client_html_file diff --git a/src/lib/eliom_client.client.mli b/src/lib/eliom_client.client.mli index 7454253438..b8e6435419 100644 --- a/src/lib/eliom_client.client.mli +++ b/src/lib/eliom_client.client.mli @@ -28,7 +28,7 @@ val unlock_request_handling : unit -> unit (** {2 Mobile applications} *) val init_client_app : - app_name:string + app_name:string -> ?ssl:bool -> hostname:string -> ?port:int @@ -63,7 +63,7 @@ val is_client_app : unit -> bool (** {2 Calling services} *) val change_page : - ?ignore_client_fun:bool + ?ignore_client_fun:bool -> ?replace:bool -> ?window_name:string -> ?window_features:string @@ -96,22 +96,23 @@ val change_page : *) val call_ocaml_service : - ?absolute:bool + ?absolute:bool -> ?absolute_path:bool -> ?https:bool -> service: ( 'a - , 'b - , _ - , _ - , _ - , _ - , _ - , _ - , _ - , _ - , 'return Eliom_service.ocaml ) - Eliom_service.t + , 'b + , _ + , _ + , _ + , _ + , _ + , _ + , _ + , _ + , 'return Eliom_service.ocaml + ) + Eliom_service.t -> ?hostname:string -> ?port:int -> ?fragment:string @@ -135,7 +136,7 @@ val call_ocaml_service : *) val exit_to : - ?window_name:string + ?window_name:string -> ?window_features:string -> ?absolute:bool -> ?absolute_path:bool @@ -163,7 +164,7 @@ val exit_to : *) val window_open : - window_name:Js.js_string Js.t + window_name:Js.js_string Js.t -> ?window_features:Js.js_string Js.t -> ?absolute:bool -> ?absolute_path:bool @@ -182,23 +183,24 @@ val window_open : *) val change_url : - ?replace:bool + ?replace:bool -> ?absolute:bool -> ?absolute_path:bool -> ?https:bool -> service: ( 'get - , unit - , Eliom_service.get - , _ - , _ - , _ - , _ - , _ - , _ - , unit - , _ ) - Eliom_service.t + , unit + , Eliom_service.get + , _ + , _ + , _ + , _ + , _ + , _ + , unit + , _ + ) + Eliom_service.t -> ?hostname:string -> ?port:int -> ?fragment:string @@ -213,7 +215,7 @@ val change_url : *) val call_service : - ?absolute:bool + ?absolute:bool -> ?absolute_path:bool -> ?https:bool -> service:('a, 'b, _, _, _, _, _, _, _, _, _) Eliom_service.t @@ -280,7 +282,8 @@ type changepage_event = ; origin_uri : string ; target_uri : string ; origin_id : int - ; target_id : int option } + ; target_id : int option + } (** [changepage_event] is a record of some parameters related to page changes. [in_cache] is true if the dom of the page is cached by [push_history_dom]. @@ -322,11 +325,7 @@ module Page_status : sig end val onactive : - ?now:bool - -> ?once:bool - -> ?stop:unit React.E.t - -> (unit -> unit) - -> unit + ?now:bool -> ?once:bool -> ?stop:unit React.E.t -> (unit -> unit) -> unit (** [onactive] is convenience function that attaches a handler to [Events.active], which behaves exactly like [fun f -> React.E.map f Events.active]. @@ -349,10 +348,7 @@ module Page_status : sig val oninactive : ?once:bool -> ?stop:unit React.E.t -> (unit -> unit) -> unit val while_active : - ?now:bool - -> ?stop:unit React.E.t - -> (unit -> unit Lwt.t) - -> unit + ?now:bool -> ?stop:unit React.E.t -> (unit -> unit Lwt.t) -> unit (** [while_active] initiates an action as [onactive] but cancels it whenever the page is not active anymore. *) end @@ -422,7 +418,7 @@ val set_client_html_file : string -> unit (**/**) val change_page_unknown : - ?meth:[`Get | `Post | `Put | `Delete] + ?meth:[`Get | `Post | `Put | `Delete] -> ?hostname:string -> ?replace:bool -> string list diff --git a/src/lib/eliom_client.server.ml b/src/lib/eliom_client.server.ml index 9404f4b77b..e3299a4eb4 100644 --- a/src/lib/eliom_client.server.ml +++ b/src/lib/eliom_client.server.ml @@ -26,25 +26,9 @@ type ('a, 'b) server_function = let mk_serv_fun a b : ('a, 'b) server_function = a, b -let server_function - ?scope - ?options - ?charset - ?code - ?content_type - ?headers - ?secure_session - ?name - ?csrf_safe - ?csrf_scope - ?csrf_secure - ?max_use - ?timeout - ?https - ?error_handler - argument_type - f - = +let server_function ?scope ?options ?charset ?code ?content_type ?headers + ?secure_session ?name ?csrf_safe ?csrf_scope ?csrf_secure ?max_use ?timeout + ?https ?error_handler argument_type f = mk_serv_fun (Eliom_registration.Ocaml.create ?scope ?options ?charset ?code ?content_type ?headers ?secure_session ?name ?csrf_safe ?csrf_scope @@ -52,8 +36,12 @@ let server_function ~meth: (Eliom_service.Post ( Eliom_parameter.unit - , Eliom_parameter.(ocaml "argument" argument_type) )) + , Eliom_parameter.(ocaml "argument" argument_type) + ) + ) ~path:Eliom_service.No_path - (fun () argument -> f argument)) + (fun () argument -> f argument) + ) (Eliom_wrap.create_unwrapper - (Eliom_wrap.id_of_int Eliom_common_base.server_function_unwrap_id_int)) + (Eliom_wrap.id_of_int Eliom_common_base.server_function_unwrap_id_int) + ) diff --git a/src/lib/eliom_client.server.mli b/src/lib/eliom_client.server.mli index c15d360796..18b72ec3d0 100644 --- a/src/lib/eliom_client.server.mli +++ b/src/lib/eliom_client.server.mli @@ -20,7 +20,7 @@ type ('a, 'b) server_function (* BBB This is not in Eliom_service because it depends on Eliom_registration *) val server_function : - ?scope:[< Eliom_common.scope] + ?scope:[< Eliom_common.scope] -> ?options:unit -> ?charset:string -> ?code:int diff --git a/src/lib/eliom_client_base.shared.ml b/src/lib/eliom_client_base.shared.ml index 97f32300e2..dbb50de5fe 100644 --- a/src/lib/eliom_client_base.shared.ml +++ b/src/lib/eliom_client_base.shared.ml @@ -1,13 +1,14 @@ type ('a, 'b) server_function_service = ( unit - , 'a - , Eliom_service.post - , Eliom_service.non_att - , Eliom_service.co - , Eliom_service.non_ext - , Eliom_service.reg - , [`WithoutSuffix] - , unit - , [`One of 'a Eliom_parameter.ocaml] Eliom_parameter.param_name - , 'b Eliom_service.ocaml ) - Eliom_service.t + , 'a + , Eliom_service.post + , Eliom_service.non_att + , Eliom_service.co + , Eliom_service.non_ext + , Eliom_service.reg + , [`WithoutSuffix] + , unit + , [`One of 'a Eliom_parameter.ocaml] Eliom_parameter.param_name + , 'b Eliom_service.ocaml + ) + Eliom_service.t diff --git a/src/lib/eliom_client_core.client.ml b/src/lib/eliom_client_core.client.ml index 726adcc4e5..8fd835b7e3 100644 --- a/src/lib/eliom_client_core.client.ml +++ b/src/lib/eliom_client_core.client.ml @@ -40,11 +40,12 @@ let create_buffer () = in let flush () = let res = get () in - (match !stack with + ( match !stack with | l :: r -> elts := l; stack := r - | [] -> elts := []); + | [] -> elts := [] + ); res in add, get, flush, push @@ -114,9 +115,7 @@ module Injection : sig val get : ?ident:string -> ?pos:pos -> name:string -> _ val initialize : - compilation_unit_id:string - -> Eliom_client_value.injection_datum - -> unit + compilation_unit_id:string -> Eliom_client_value.injection_datum -> unit end = struct let table = Jstable.create () @@ -126,24 +125,25 @@ end = struct (Js.Optdef.get (Jstable.find table (Js.string name)) (fun () -> - let name = - match ident, pos with - | None, None -> Printf.sprintf "%s" name - | None, Some pos -> - Printf.sprintf "%s at %s" name (Eliom_lib.pos_to_string pos) - | Some i, None -> Printf.sprintf "%s (%s)" name i - | Some i, Some pos -> - Printf.sprintf "%s (%s at %s)" name i - (Eliom_lib.pos_to_string pos) - in - raise_error "Did not find injection %s" name)) - - let initialize - ~compilation_unit_id - {Eliom_runtime.injection_id; injection_value; _} - = + let name = + match ident, pos with + | None, None -> Printf.sprintf "%s" name + | None, Some pos -> + Printf.sprintf "%s at %s" name (Eliom_lib.pos_to_string pos) + | Some i, None -> Printf.sprintf "%s (%s)" name i + | Some i, Some pos -> + Printf.sprintf "%s (%s at %s)" name i + (Eliom_lib.pos_to_string pos) + in + raise_error "Did not find injection %s" name + ) + ) + + let initialize ~compilation_unit_id + {Eliom_runtime.injection_id; injection_value; _} = Logs.debug ~src:section (fun fmt -> - fmt "Initialize injection %d" injection_id); + fmt "Initialize injection %d" injection_id + ); (* BBB One should assert that injection_value doesn't contain any value marked for late unwrapping. How to do this efficiently? *) Jstable.add table @@ -155,14 +155,16 @@ end type compilation_unit_global_data = { mutable server_section : Eliom_runtime.client_value_datum array list - ; mutable client_section : Eliom_runtime.injection_datum array list } + ; mutable client_section : Eliom_runtime.injection_datum array list + } let global_data = ref String_map.empty let do_next_server_section_data ~compilation_unit_id = Logs.debug ~src:section (fun fmt -> fmt "Do next client value data section in compilation unit %s" - compilation_unit_id); + compilation_unit_id + ); try let data = String_map.find compilation_unit_id !global_data in match data.server_section with @@ -179,7 +181,8 @@ let do_next_server_section_data ~compilation_unit_id = let do_next_client_section_data ~compilation_unit_id = Logs.debug ~src:section (fun fmt -> fmt "Do next injection data section in compilation unit %s" - compilation_unit_id); + compilation_unit_id + ); try let data = String_map.find compilation_unit_id !global_data in match data.client_section with @@ -210,12 +213,14 @@ let register_process_node, find_process_node = let process_nodes : Dom.node Js.t Jstable.t = Jstable.create () in let find id = Logs.debug ~src:section (fun fmt -> - fmt "Find process node %s" (Js.to_string id)); + fmt "Find process node %s" (Js.to_string id) + ); Jstable.find process_nodes id in let register id node = Logs.debug ~src:section (fun fmt -> - fmt "Register process node %s" (Js.to_string id)); + fmt "Register process node %s" (Js.to_string id) + ); let node = if node##.nodeName##toLowerCase == Js.string "script" then @@ -233,8 +238,9 @@ let getElementById id = Js.Optdef.case (find_process_node (Js.string id)) (fun () -> - Logs.warn ~src:section (fun fmt -> fmt "getElementById %s: Not_found" id); - raise Not_found) + Logs.warn ~src:section (fun fmt -> fmt "getElementById %s: Not_found" id); + raise Not_found + ) (fun pnode -> pnode) (* == Request nodes @@ -245,7 +251,8 @@ let register_request_node, find_request_node, reset_request_nodes = let find id = Jstable.find !request_nodes id in let register id node = Logs.debug ~src:section (fun fmt -> - fmt "Register request node %s" (Js.to_string id)); + fmt "Register request node %s" (Js.to_string id) + ); Jstable.add !request_nodes id node in let reset () = @@ -288,18 +295,17 @@ let in_onload, broadcast_load_end, wait_load_end, set_loading_phase = (* forward declaration... *) let change_page_uri_ : - (?cookies_info:bool * string list -> ?tmpl:string -> string -> unit) ref - = + (?cookies_info:bool * string list -> ?tmpl:string -> string -> unit) ref = ref (fun ?cookies_info:_ ?tmpl:_ _href -> assert false) let change_page_get_form_ : - (?cookies_info:bool * string list - -> ?tmpl:string - -> Dom_html.formElement Js.t - -> string - -> unit) - ref - = + ( ?cookies_info:bool * string list + -> ?tmpl:string + -> Dom_html.formElement Js.t + -> string + -> unit + ) + ref = ref (fun ?cookies_info:_ ?tmpl:_ _form _href -> assert false) let change_page_post_form_ = @@ -314,13 +320,15 @@ let raw_a_handler node cookies_info tmpl ev = middleClick ev || (not !Eliom_common.is_client_app) && ((https = Some true && not Eliom_request_info.ssl_) - || (https = Some false && Eliom_request_info.ssl_)) + || (https = Some false && Eliom_request_info.ssl_) + ) || - ((* If a link is clicked, we do not want to continue propagation + ( (* If a link is clicked, we do not want to continue propagation (for example if the link is in a wider clickable area) *) - Dom_html.stopPropagation ev; - !change_page_uri_ ?cookies_info ?tmpl (Js.to_string href); - false) + Dom_html.stopPropagation ev; + !change_page_uri_ ?cookies_info ?tmpl (Js.to_string href); + false + ) let raw_form_handler form kind cookies_info tmpl ev client_form_handler = let action = Js.to_string form##.action in @@ -338,14 +346,16 @@ let raw_form_handler form kind cookies_info tmpl ev client_form_handler = in (not !Eliom_common.is_client_app) && ((https = Some true && not Eliom_request_info.ssl_) - || (https = Some false && Eliom_request_info.ssl_)) + || (https = Some false && Eliom_request_info.ssl_) + ) || (f (); false) let raw_event_handler value = let handler = (*XXX???*) - (Eliom_lib.from_poly (Eliom_lib.to_poly value) - : #Dom_html.event Js.t -> unit) + ( Eliom_lib.from_poly (Eliom_lib.to_poly value) + : #Dom_html.event Js.t -> unit + ) in fun ev -> try handler ev; true with Eliom_client_value.False -> false @@ -361,21 +371,25 @@ let reify_caml_event name node ce = (fun ev -> let node = Js.Opt.get (Dom_html.CoerceTo.a node) (fun () -> - raise_error ~section "not an anchor element") + raise_error ~section "not an anchor element" + ) in - raw_a_handler node cookies_info tmpl ev) ) + raw_a_handler node cookies_info tmpl ev + ) ) | Xml.CE_call_service - (Some (((`Form_get | `Form_post) as kind), cookies_info, tmpl, client_hdlr)) - -> + (Some (((`Form_get | `Form_post) as kind), cookies_info, tmpl, client_hdlr) + ) -> ( name , `Other (fun ev -> let form = Js.Opt.get (Dom_html.CoerceTo.form node) (fun () -> - raise_error ~section "not a form element") + raise_error ~section "not a form element" + ) in raw_form_handler form kind cookies_info tmpl ev - (Eliom_lib.from_poly client_hdlr : client_form_handler)) ) + (Eliom_lib.from_poly client_hdlr : client_form_handler) + ) ) | Xml.CE_client_closure f -> ( name , `Other @@ -487,7 +501,9 @@ let iter_prop node name f = let iter_prop_protected node name f = match get_prop node name with - | Some n -> ( try f n with _ -> ()) + | Some n -> ( + try f n with _ -> () + ) | None -> () let space_re = Regexp.regexp " " @@ -534,24 +550,30 @@ let rec rebuild_rattrib node ra = | None -> node##(removeAttribute name); iter_prop_protected node name (fun name -> - Js.Unsafe.set node name Js.null) + Js.Unsafe.set node name Js.null + ) | Some v -> let v = rebuild_attrib_val v in node##(setAttribute name v); iter_prop_protected node name (fun name -> - Js.Unsafe.set node name v)) - s) + Js.Unsafe.set node name v + ) + ) + s + ) | Xml.RACamlEventHandler ev -> register_event_handler node (Xml.aname ra, ev) | Xml.RALazyStr s -> node##(setAttribute (Js.string (Xml.aname ra)) (Js.string s)) | Xml.RALazyStrL (Xml.Space, l) -> node##(setAttribute (Js.string (Xml.aname ra)) - (Js.string (String.concat " " l))) + (Js.string (String.concat " " l)) + ) | Xml.RALazyStrL (Xml.Comma, l) -> node##(setAttribute (Js.string (Xml.aname ra)) - (Js.string (String.concat "," l))) + (Js.string (String.concat "," l)) + ) | Xml.RAClient (_, _, value) -> rebuild_rattrib node (Eliom_lib.from_poly (Eliom_lib.to_poly value) : Xml.attrib) @@ -644,9 +666,11 @@ end = struct Js.Opt.case dom'##.parentNode (fun () -> (* no parent -> no replace needed *) ()) (fun parent -> - Js.Opt.iter (Dom.CoerceTo.element parent) (fun parent -> - (* really update the dom *) - ignore (Dom_html.element parent)##(replaceChild dom dom'))) + Js.Opt.iter (Dom.CoerceTo.element parent) (fun parent -> + (* really update the dom *) + ignore (Dom_html.element parent)##(replaceChild dom dom') + ) + ) end type content_ns = [`HTML5 | `SVG] @@ -667,10 +691,12 @@ let rec rebuild_node' ns elt = ReactState.start_signal (fun state -> React.S.map (fun elt' -> - let dom = rebuild_node' ns elt' in - Xml.set_dom_node elt dom; - ReactState.change_dom state dom) - signal) + let dom = rebuild_node' ns elt' in + Xml.set_dom_node elt dom; + ReactState.change_dom state dom + ) + signal + ) in Xml.set_dom_node elt dom; dom | Xml.TyXMLNode raw_elt -> ( @@ -685,10 +711,12 @@ let rec rebuild_node' ns elt = let id = Js.string id in Js.Optdef.case (find_process_node id) (fun () -> - let node = raw_rebuild_node ns (Xml.content elt) in - register_process_node id node; - node) - (fun n -> (n :> Dom.node Js.t))) + let node = raw_rebuild_node ns (Xml.content elt) in + register_process_node id node; + node + ) + (fun n -> (n :> Dom.node Js.t)) + ) and raw_rebuild_node ns = function | Xml.Empty | Xml.Comment _ -> @@ -711,7 +739,8 @@ and raw_rebuild_node ns = function | `SVG -> let svg_ns = "http://www.w3.org/2000/svg" in Dom_html.document##(createElementNS (Js.string svg_ns) - (Js.string name)) + (Js.string name) + ) in List.iter (rebuild_rattrib node) attribs; List.iter (fun c -> Dom.appendChild node (rebuild_node' ns c)) childrens; @@ -728,7 +757,8 @@ let rebuild_node_ns ns context elt' = Logs.debug ~src:section (fun fmt -> fmt "Rebuild node %s (%s)" (Eliom_content_core.Xml.string_of_node_id (Xml.get_node_id elt')) - context); + context + ); if is_before_initial_load () then ( log_inspect (rebuild_node' ns elt'); @@ -738,7 +768,9 @@ let rebuild_node_ns ns context elt' = match get_node_id elt' with | NoId -> " " | RequestId id -> " on request node " ^ id - | ProcessId id -> " on global node " ^ id)); + | ProcessId id -> " on global node " ^ id + ) + ); let node = Js.Unsafe.coerce (rebuild_node' ns elt') in flush_load_script (); node diff --git a/src/lib/eliom_client_value.server.ml b/src/lib/eliom_client_value.server.ml index 54374f560e..2e7870c300 100644 --- a/src/lib/eliom_client_value.server.ml +++ b/src/lib/eliom_client_value.server.ml @@ -32,11 +32,11 @@ let client_value_from_server_repr cv = cv let client_value_datum ~closure_id ~args ~value = { Eliom_runtime.closure_id ; args - ; value = Eliom_runtime.Client_value_server_repr.to_poly value } + ; value = Eliom_runtime.Client_value_server_repr.to_poly value + } exception Client_value_creation_invalid_context of string let escaped_value value : - Eliom_runtime.escaped_value (* * Eliom_wrap.unwrapper *) - = + Eliom_runtime.escaped_value (* * Eliom_wrap.unwrapper *) = Ocsigen_lib.to_poly value diff --git a/src/lib/eliom_client_value.server.mli b/src/lib/eliom_client_value.server.mli index eed11c3329..7eec3f1dbe 100644 --- a/src/lib/eliom_client_value.server.mli +++ b/src/lib/eliom_client_value.server.mli @@ -40,16 +40,15 @@ exception Client_value_creation_invalid_context of string (**/**) val create_client_value : - loc:Eliom_lib.pos option + loc:Eliom_lib.pos option -> instance_id:int -> _ Eliom_runtime.Client_value_server_repr.t val client_value_from_server_repr : - 'a Eliom_runtime.Client_value_server_repr.t - -> 'a t + 'a Eliom_runtime.Client_value_server_repr.t -> 'a t val client_value_datum : - closure_id:string + closure_id:string -> args:Ocsigen_lib.poly -> value:'a t -> Eliom_runtime.client_value_datum diff --git a/src/lib/eliom_comet.client.ml b/src/lib/eliom_comet.client.ml index af7eac7634..1de385a6ba 100644 --- a/src/lib/eliom_comet.client.ml +++ b/src/lib/eliom_comet.client.ml @@ -40,13 +40,15 @@ module Configuration = struct (we take the min of all values, for a given t) *) time_after_unfocus : float - ; time_between_request : float } + ; time_between_request : float + } let default_configuration = { active_until_timeout = false ; time_between_request_unfocused = Some [0.5, 60., 600.] ; time_after_unfocus = 180. - ; time_between_request = 0. } + ; time_between_request = 0. + } type t = int @@ -56,12 +58,13 @@ module Configuration = struct let config_min c1 c2 = { active_until_timeout = c1.active_until_timeout || c2.active_until_timeout ; time_between_request_unfocused = - (match - c1.time_between_request_unfocused, c2.time_between_request_unfocused - with + ( match + c1.time_between_request_unfocused, c2.time_between_request_unfocused + with | Some l1, Some l2 -> Some (l1 @ l2) | Some v, None | None, Some v -> Some v - | None, None -> None) + | None, None -> None + ) ; time_after_unfocus = max c1.time_after_unfocus c2.time_after_unfocus ; time_between_request = min c1.time_between_request c2.time_between_request } @@ -120,7 +123,8 @@ module Configuration = struct set_fun conf (fun c -> { c with time_between_request_unfocused = (if v then Some [0., 0., 0.] else None) - }) + } + ) let set_timeout conf v = set_fun conf (fun c -> {c with time_after_unfocus = v}) @@ -163,7 +167,8 @@ module Configuration = struct Lwt.pick [ Js_of_ocaml_lwt.Lwt_js.sleep t ; !update_configuration_waiter - ; active_waiter () ] + ; active_waiter () + ] in let remaining_time = sleep_duration () -. (Sys.time () -. time) in if remaining_time > 0. then aux remaining_time else Lwt.return_unit @@ -188,14 +193,17 @@ let handle_exn, set_handle_exn_function = | Some exn -> raise_error ~section ~exn "%s" s | None -> Logs.debug ~src:section (fun fmt -> fmt "%s" s); - Lwt.return_unit) + Lwt.return_unit + ) in ( (fun ?exn () -> if not !closed then ( closed := true; - !r ?exn ()) - else Lwt.return_unit) + !r ?exn () + ) + else Lwt.return_unit + ) , fun f -> r := f ) type chan_id = string @@ -212,8 +220,7 @@ module Service_handler : sig val make : Ecb.comet_service -> 'a kind -> 'a t val wait_data : - 'a t - -> (chan_id * int option * string Ecb.channel_data) list Lwt.t + 'a t -> (chan_id * int option * string Ecb.channel_data) list Lwt.t (** Returns the messages received in the last request. If the channel is stateless, it also returns the message number in the [int option] *) @@ -223,28 +230,26 @@ module Service_handler : sig val add_channel_stateful : stateful t -> chan_id -> unit val add_channel_stateless : - stateless t - -> chan_id - -> Ecb.stateless_kind - -> unit + stateless t -> chan_id -> Ecb.stateless_kind -> unit val close : 'a t -> chan_id -> unit end = struct type activity = { mutable active : [`Inactive | `Active | `Idle] - (** [!hd.active] is true when the [hd] channel handler is + (** [!hd.active] is true when the [hd] channel handler is receiving data. Idle means that the window is not active but we want to keep updated from time to time. *) ; mutable focused : float option - (** [focused] is None when the page is visible and Some [t] + (** [focused] is None when the page is visible and Some [t] when the page became hidden at time [t] (in ms) *) ; mutable active_waiter : unit Lwt.t - (** [active_waiter] terminates when the page get visible *) + (** [active_waiter] terminates when the page get visible *) ; mutable active_wakener : unit Lwt.u ; mutable restart_waiter : Ecb.answer Lwt.t ; mutable restart_wakener : Ecb.answer Lwt.u - ; mutable active_channels : Eliom_lib.String.Set.t } + ; mutable active_channels : Eliom_lib.String.Set.t + } type stateful_state = int ref (* id of the next request *) type stateless_state_ = {count : int; position : Ecb.position} @@ -266,7 +271,8 @@ end = struct type 'a t = { hd_service : Ecb.comet_service ; hd_state : channel_state - ; hd_activity : activity } + ; hd_activity : activity + } let add_listener target event f = let listener = Dom_html.handler (fun _ -> f (); Js._true) in @@ -306,7 +312,8 @@ end = struct if handler.hd_activity.focused <> None then ( handler.hd_activity.focused <- None; - set_activity handler `Active) + set_activity handler `Active + ) in let suspend_activity () = if handler.hd_activity.focused = None @@ -348,7 +355,8 @@ end = struct Some (Js.to_float (new%js Js.date_now)##getTime -. ((Configuration.get ()).Configuration.time_after_unfocus *. 1000.) - )) + ) + ) else hd.hd_activity.focused <- None; set_activity hd (expected_activity hd) @@ -381,7 +389,8 @@ end = struct then ( queue := []; Eliom_client.call_service ~service () - (false, Ecb.Stateful (Ecb.Commands (Array.of_list (List.rev q))))) + (false, Ecb.Stateful (Ecb.Commands (Array.of_list (List.rev q)))) + ) else Lwt.return "" | _ -> let* () = Eliom_client.wait_load_end () in @@ -414,8 +423,10 @@ end = struct | _chan_id, Ecb.Closed -> Logs.warn ~src:section (fun fmt -> fmt - "update_stateful_state: received Closed: should not happen, this is an eliom bug, please report it") - | chan_id, Ecb.Full -> stop_waiting hd chan_id) + "update_stateful_state: received Closed: should not happen, this is an eliom bug, please report it" + ) + | chan_id, Ecb.Full -> stop_waiting hd chan_id + ) message | Stateless_state _ -> raise (Comet_error "update_stateful_state on stateless one") @@ -443,20 +454,23 @@ end = struct let table = List.fold_left (fun table -> function - | chan_id, Ecb.Data (_, index) -> ( - try - let state = Eliom_lib.String.Table.find chan_id table in - if position_value state.position < index + 1 - then - Eliom_lib.String.Table.add chan_id - { state with - position = set_position state.position (index + 1) } - table - else table - with Not_found -> table) - | chan_id, Ecb.Closed | chan_id, Ecb.Full -> - stop_waiting hd chan_id; - Eliom_lib.String.Table.remove chan_id table) + | chan_id, Ecb.Data (_, index) -> ( + try + let state = Eliom_lib.String.Table.find chan_id table in + if position_value state.position < index + 1 + then + Eliom_lib.String.Table.add chan_id + { state with + position = set_position state.position (index + 1) + } + table + else table + with Not_found -> table + ) + | chan_id, Ecb.Closed | chan_id, Ecb.Full -> + stop_waiting hd chan_id; + Eliom_lib.String.Table.remove chan_id table + ) !r message in r := table @@ -464,8 +478,7 @@ end = struct raise (Comet_error "update_stateless_state on stateful one") let call_service - ({hd_activity; hd_service = Ecb.Comet_service (srv, queue); _} as hd) - = + ({hd_activity; hd_service = Ecb.Comet_service (srv, queue); _} as hd) = let* () = Configuration.sleep_before_next_request (fun () -> hd_activity.focused) @@ -487,9 +500,8 @@ end = struct let add_no_index = let aux = function - | chan, (Ecb.Data _ as m) - | chan, (Ecb.Closed as m) - | chan, (Ecb.Full as m) -> + | chan, (Ecb.Data _ as m) | chan, (Ecb.Closed as m) | chan, (Ecb.Full as m) + -> chan, None, m in List.map aux @@ -498,10 +510,12 @@ end = struct if hd.hd_activity.active <> `Inactive && (timeout - || not (Configuration.get ()).Configuration.active_until_timeout) + || not (Configuration.get ()).Configuration.active_until_timeout + ) then set_activity hd (expected_activity hd) - let wait_data hd : (string * int option * string Ecb.channel_data) list Lwt.t = + let wait_data hd : (string * int option * string Ecb.channel_data) list Lwt.t + = let rec aux retries = if hd.hd_activity.active = `Inactive then @@ -511,41 +525,43 @@ end = struct Lwt.try_bind (fun () -> Lwt.pick [call_service hd; hd.hd_activity.restart_waiter]) (fun s -> - match s with - | Ecb.Timeout -> - update_activity ~timeout:true hd; - aux 0 - | Ecb.State_closed -> Lwt.return (close_all_channels hd) - | Ecb.Comet_error e -> Lwt.fail (Comet_error e) - | Ecb.Stateless_messages l -> - let l = Array.to_list l in - update_stateless_state hd l; - Lwt.return (drop_message_index l) - | Ecb.Stateful_messages l -> - let l = Array.to_list l in - update_stateful_state hd l; - Lwt.return (add_no_index l)) + match s with + | Ecb.Timeout -> + update_activity ~timeout:true hd; + aux 0 + | Ecb.State_closed -> Lwt.return (close_all_channels hd) + | Ecb.Comet_error e -> Lwt.fail (Comet_error e) + | Ecb.Stateless_messages l -> + let l = Array.to_list l in + update_stateless_state hd l; + Lwt.return (drop_message_index l) + | Ecb.Stateful_messages l -> + let l = Array.to_list l in + update_stateful_state hd l; + Lwt.return (add_no_index l) + ) (fun e -> - match e with - | Eliom_request.Failed_request (0 | 502 | 504) -> - if retries > max_retries - then ( - Logs.app ~src:section (fun fmt -> fmt "connection failure"); - set_activity hd `Inactive; - aux 0) - else - let* () = Js_of_ocaml_lwt.Lwt_js.sleep (delay retries) in - aux (retries + 1) - | Restart -> - Logs.info ~src:section (fun fmt -> fmt "restart"); - aux 0 - | exn -> - Logs.app ~src:section (fun fmt -> - fmt - ("connection failure" ^^ "@\n%s") - (Printexc.to_string exn)); - let* () = handle_exn ~exn () in - Lwt.fail exn) + match e with + | Eliom_request.Failed_request (0 | 502 | 504) -> + if retries > max_retries + then ( + Logs.app ~src:section (fun fmt -> fmt "connection failure"); + set_activity hd `Inactive; + aux 0 + ) + else + let* () = Js_of_ocaml_lwt.Lwt_js.sleep (delay retries) in + aux (retries + 1) + | Restart -> + Logs.info ~src:section (fun fmt -> fmt "restart"); + aux 0 + | exn -> + Logs.app ~src:section (fun fmt -> + fmt ("connection failure" ^^ "@\n%s") (Printexc.to_string exn) + ); + let* () = handle_exn ~exn () in + Lwt.fail exn + ) in update_activity hd; aux 0 @@ -553,12 +569,16 @@ end = struct ignore (Lwt.catch (fun () -> - call_service_after_load_end srv queue - (false, Ecb.Stateful (Ecb.Commands command))) + call_service_after_load_end srv queue + (false, Ecb.Stateful (Ecb.Commands command)) + ) (fun exn -> - Logs.app ~src:section (fun fmt -> - fmt ("request failed" ^^ "@\n%s") (Printexc.to_string exn)); - Lwt.return "")) + Logs.app ~src:section (fun fmt -> + fmt ("request failed" ^^ "@\n%s") (Printexc.to_string exn) + ); + Lwt.return "" + ) + ) let close hd chan_id = match hd.hd_state with @@ -577,7 +597,9 @@ end = struct !map with Not_found -> Logs.info ~src:section (fun fmt -> - fmt "trying to close a non existent channel: %s" chan_id)) + fmt "trying to close a non existent channel: %s" chan_id + ) + ) let add_channel_stateful hd chan_id = hd.hd_activity.active_channels <- @@ -611,7 +633,8 @@ end = struct {count = old_state.count + 1; position = pos} with Not_found -> {count = 1; position = pos} in - map := Eliom_lib.String.Table.add chan_id state !map); + map := Eliom_lib.String.Table.add chan_id state !map + ); restart hd let init_activity () = @@ -623,7 +646,8 @@ end = struct ; active_wakener ; restart_waiter ; restart_wakener - ; active_channels = Eliom_lib.String.Set.empty } + ; active_channels = Eliom_lib.String.Set.empty + } let make hd_service hd_kind = let hd_state = @@ -637,7 +661,8 @@ end type 'a handler = { hd_service_handler : 'a Service_handler.t - ; hd_stream : (string * int option * string Ecb.channel_data) Lwt_stream.t } + ; hd_stream : (string * int option * string Ecb.channel_data) Lwt_stream.t + } let handler_stream hd = Lwt_stream.map_list @@ -646,16 +671,16 @@ let handler_stream hd = Lwt.try_bind (fun () -> Service_handler.wait_data hd) (fun s -> Lwt.return_some s) - (fun _ -> Lwt.return_none))) + (fun _ -> Lwt.return_none) + ) + ) let stateful_handler_table : - (Ecb.comet_service, Service_handler.stateful handler) Hashtbl.t - = + (Ecb.comet_service, Service_handler.stateful handler) Hashtbl.t = Hashtbl.create 1 let stateless_handler_table : - (Ecb.comet_service, Service_handler.stateless handler) Hashtbl.t - = + (Ecb.comet_service, Service_handler.stateless handler) Hashtbl.t = Hashtbl.create 1 let init (service : Ecb.comet_service) kind table = @@ -666,15 +691,13 @@ let init (service : Ecb.comet_service) kind table = hd let get_stateful_hd (service : Ecb.comet_service) : - Service_handler.stateful handler - = + Service_handler.stateful handler = try Hashtbl.find stateful_handler_table service with Not_found -> init service Service_handler.stateful stateful_handler_table let get_stateless_hd (service : Ecb.comet_service) : - Service_handler.stateless handler - = + Service_handler.stateless handler = try Hashtbl.find stateless_handler_table service with Not_found -> init service Service_handler.stateless stateless_handler_table @@ -736,8 +759,10 @@ let check_and_update_position position msg_pos data = if match relation with Equal -> j = i | Greater -> j >= i then ( r := Some (j + 1); - true) - else false) + true + ) + else false + ) (* stateless channels are registered with a position: when a channel is registered more than one time, it is possible to receive old @@ -752,18 +777,22 @@ let register' hd position (_ : Ecb.comet_service) (chan_id : 'a Ecb.chan_id) = match data with | Ecb.Full -> Lwt.fail Channel_full | Ecb.Closed -> Lwt.fail Channel_closed - | Ecb.Data x -> Lwt.return_some (unmarshal x : 'a)) - | _ -> Lwt.return_none) + | Ecb.Data x -> Lwt.return_some (unmarshal x : 'a) + ) + | _ -> Lwt.return_none + ) (Lwt_stream.clone hd.hd_stream) in let protect_and_close t = let t' = Lwt.protected t in Lwt.on_cancel t' (fun () -> - Service_handler.close hd.hd_service_handler chan_id); + Service_handler.close hd.hd_service_handler chan_id + ); t' in (* protect the stream from cancels *) - Lwt_stream.from (fun () -> protect_and_close (Lwt_stream.get stream)) + Lwt_stream.from (fun () -> protect_and_close (Lwt_stream.get stream) + ) let register_stateful ?(wake = true) service chan_id = let hd = get_stateful_hd service in @@ -806,7 +835,8 @@ let is_active () = max active (fun () -> Service_handler.is_active hd.hd_service_handler) in max (Hashtbl.fold f stateless_handler_table `Active) (fun () -> - Hashtbl.fold f stateful_handler_table `Active) + Hashtbl.fold f stateful_handler_table `Active + ) module Channel = struct type 'a t = 'a Lwt_stream.t diff --git a/src/lib/eliom_comet.client.mli b/src/lib/eliom_comet.client.mli index 51f4f481bd..098016babb 100644 --- a/src/lib/eliom_comet.client.mli +++ b/src/lib/eliom_comet.client.mli @@ -121,9 +121,7 @@ end (**/**) val register : - ?wake:bool - -> 'a Eliom_comet_base.wrapped_channel - -> 'a Lwt_stream.t + ?wake:bool -> 'a Eliom_comet_base.wrapped_channel -> 'a Lwt_stream.t (** if wake is false, the registration of the channel won't activate the handling loop ( no request will be sent ). Default is true *) diff --git a/src/lib/eliom_comet.server.ml b/src/lib/eliom_comet.server.ml index 896d880c4e..a91f217929 100644 --- a/src/lib/eliom_comet.server.ml +++ b/src/lib/eliom_comet.server.ml @@ -65,7 +65,8 @@ let fallback_service = Eliom_common.lazy_site_value_from_fun @@ fun () -> Comet.create ~meth:(Eliom_service.Get Eliom_parameter.unit) ~path:(Eliom_service.Path comet_path) (fun () () -> - Lwt.return state_closed_msg) + Lwt.return state_closed_msg + ) let fallback_global_service = Eliom_common.lazy_site_value_from_fun @@ fun () -> @@ -73,7 +74,9 @@ let fallback_global_service = ~path:(Eliom_service.Path comet_global_path) (fun () () -> Lwt.return (error_msg - "request with no post parameters, or there isn't any registered site comet channel")) + "request with no post parameters, or there isn't any registered site comet channel" + ) + ) let new_id = Eliom_lib.make_cryptographic_safe_string @@ -106,7 +109,8 @@ end = struct ; (* the number of messages already added to the channel *) ch_content : (string * int) Dlist.t ; ch_wakeup : unit Lwt_condition.t - (* condition broadcasted when there is a new message *) } + (* condition broadcasted when there is a new message *) + } module Channel_hash = struct type t = channel @@ -124,7 +128,8 @@ end = struct { ch_id = "" ; ch_index = 0 ; ch_content = Dlist.create 1 - ; ch_wakeup = Lwt_condition.create () } + ; ch_wakeup = Lwt_condition.create () + } in fun ch_id -> let dummy = {dummy_channel with ch_id} in @@ -151,9 +156,10 @@ end = struct Lwt.return_unit in ignore - (Lwt.with_value Eliom_common.sp_key None @@ fun () -> - Lwt_stream.iter_s f stream - : unit Lwt.t) + ( Lwt.with_value Eliom_common.sp_key None @@ fun () -> + Lwt_stream.iter_s f stream + : unit Lwt.t + ) let make_name name = "stateless:" ^ name @@ -166,7 +172,8 @@ end = struct { ch_id = name ; ch_index = 0 ; ch_content = Dlist.create size - ; ch_wakeup = Lwt_condition.create () } + ; ch_wakeup = Lwt_condition.create () + } in run_channel channel stream; match find_channel name with @@ -174,7 +181,8 @@ end = struct failwith (Printf.sprintf "can't create channel %s: a channel with the same name already exists" - name) + name + ) | None -> Weak_channel_table.add channels channel; channel @@ -191,9 +199,10 @@ end = struct try Dlist.fold (fun l (v, index) -> - if index >= last - then (channel.ch_id, Eliom_comet_base.Data (v, index)) :: l - else raise (Finished l)) + if index >= last + then (channel.ch_id, Eliom_comet_base.Data (v, index)) :: l + else raise (Finished l) + ) [] channel.ch_content with Finished l -> l @@ -210,7 +219,7 @@ end = struct match Dlist.newest channel.ch_content with | None -> [] (* should not happen *) | Some node -> [channel.ch_id, Eliom_comet_base.Data (Dlist.value node)] - ) + ) (* when the client is requesting the data after index i return all data with index gretter or equal to i*) | Eliom_comet_base.After i when i > channel.ch_index -> [] @@ -222,7 +231,8 @@ end = struct | Eliom_comet_base.After i -> queue_take channel i | Eliom_comet_base.Last (Some n) -> let i = channel.ch_index - min (Dlist.size channel.ch_content) n in - queue_take channel i) + queue_take channel i + ) let has_data = function | Eliom_lib.Right _ -> @@ -234,7 +244,8 @@ end = struct | Eliom_comet_base.After i when i > channel.ch_index -> false | Eliom_comet_base.After _ -> true | Eliom_comet_base.Last _ when Dlist.size channel.ch_content > 0 -> true - | Eliom_comet_base.Last _ -> false) + | Eliom_comet_base.Last _ -> false + ) let really_wait_data requests = let rec make_list = function @@ -249,8 +260,7 @@ end = struct let wait_data requests = if List.exists has_data requests then Lwt.return_unit - else - Lwt_unix.with_timeout (timeout ()) (fun () -> really_wait_data requests) + else Lwt_unix.with_timeout (timeout ()) (fun () -> really_wait_data requests) let handle_request () (_, req) = match req with @@ -262,10 +272,12 @@ end = struct let* res = Lwt.catch (fun () -> - let* () = wait_data requests in - Lwt.return (List.flatten (List.map get_available_data requests))) + let* () = wait_data requests in + Lwt.return (List.flatten (List.map get_available_data requests)) + ) (function - | Lwt_unix.Timeout -> Lwt.return_nil | exc -> Lwt.reraise exc) + | Lwt_unix.Timeout -> Lwt.return_nil | exc -> Lwt.reraise exc + ) in Lwt.return (encode_global_downgoing res) @@ -297,21 +309,22 @@ let () = Eliommod.register_site_init (fun () -> ignore (Eliom_common.force_lazy_site_value fallback_global_service); ignore (Eliom_common.force_lazy_site_value fallback_service); - ignore (Stateless.get_service ())) + ignore (Stateless.get_service ()) + ) (** String channels on which is build the module Channel *) module Stateful : sig type t val create : - ?scope:Eliom_common.client_process_scope + ?scope:Eliom_common.client_process_scope -> ?name:chan_id -> size:int -> _ React.event -> t val create_unlimited : - ?scope:Eliom_common.client_process_scope + ?scope:Eliom_common.client_process_scope -> ?name:chan_id -> _ Lwt_stream.t -> t @@ -323,9 +336,7 @@ module Stateful : sig val get_service : t -> comet_service val wait_timeout : - ?scope:Eliom_common.client_process_scope - -> float - -> unit Lwt.t + ?scope:Eliom_common.client_process_scope -> float -> unit Lwt.t end = struct type chan_id = string type comet_service = Eliom_comet_base.comet_service @@ -334,9 +345,9 @@ end = struct type activity = | Active of end_request_waiters list - (** There is currently a request from the client *) + (** There is currently a request from the client *) | Inactive of float - (** The last request from the client completed at that time *) + (** The last request from the client completed at that time *) type waiter = [`Data | `Update] Lwt.t @@ -345,28 +356,31 @@ end = struct { queue : string Eliom_comet_base.channel_data Queue.t ; (* Reference to the event stream, so that it does not get garbage collected *) - mutable events : Obj.t option } + mutable events : Obj.t option + } | Stream of { mutable stream : string Eliom_comet_base.channel_data Lwt_stream.t - ; mutable waiter : waiter } + ; mutable waiter : waiter + } type handler = { hd_scope : Eliom_common.client_process_scope ; (* id : int; pour tester que ce sont des service differents... *) mutable hd_active_channels : (chan_id * channel) list - (** streams that are currently sent to client *) + (** streams that are currently sent to client *) ; mutable hd_unregistered_channels : (chan_id * channel) list - (** streams that are created on the server side, but client did not register *) + (** streams that are created on the server side, but client did not register *) ; mutable hd_registered_chan_id : chan_id list - (** the fusion of all the streams from hd_active_channels *) + (** the fusion of all the streams from hd_active_channels *) ; mutable hd_update_streams_w : [`Data | `Update] Lwt.u option - (** used to signal new data or new active streams. *) + (** used to signal new data or new active streams. *) ; hd_service : internal_comet_service ; mutable hd_last : string * int - (** the last message sent to the client, if he sends a request + (** the last message sent to the client, if he sends a request with the same number, this message is immediately sent back.*) - ; mutable hd_activity : activity } + ; mutable hd_activity : activity + } exception Connection_closed @@ -436,7 +450,8 @@ end = struct Lwt.with_value Eliom_common.sp_key None @@ fun () -> Lwt.no_cancel (let* _ = Lwt_stream.peek s in - Lwt.return `Data) + Lwt.return `Data + ) (** read up to [n] messages in the list of streams [streams] without blocking. *) let read_channels n handler = @@ -463,9 +478,10 @@ end = struct let wait_channels handler = List.fold_left (fun acc (_, channel) -> - match channel with - | Events _ -> acc - | Stream {waiter; _} -> waiter :: acc) + match channel with + | Events _ -> acc + | Stream {waiter; _} -> waiter :: acc + ) [] handler.hd_active_channels (** wait for data on any channel that the client asks. It correctly @@ -476,12 +492,14 @@ end = struct (let hd_update_streams, hd_update_streams_w = Lwt.task () in handler.hd_update_streams_w <- Some hd_update_streams_w; Lwt.choose - (wait_closed_connection :: hd_update_streams :: wait_channels handler)) + (wait_closed_connection :: hd_update_streams :: wait_channels handler) + ) (function | `Data -> handler.hd_update_streams_w <- None; Lwt.return_unit - | `Update -> wait_data wait_closed_connection handler) + | `Update -> wait_data wait_closed_connection handler + ) let launch_channel handler chan_id channel = handler.hd_active_channels <- @@ -535,21 +553,21 @@ end = struct else Lwt.catch (fun () -> - Lwt_unix.with_timeout (timeout ()) (fun () -> - let* messages = - let messages = read_channels 100 handler in - if messages <> [] || idle - then Lwt.return messages - else - let* () = - wait_data (wait_closed_connection ()) handler - in - Lwt.return (read_channels 100 handler) - in - let message = encode_downgoing messages in - handler.hd_last <- message, number; - set_inactive handler; - Lwt.return message)) + Lwt_unix.with_timeout (timeout ()) (fun () -> + let* messages = + let messages = read_channels 100 handler in + if messages <> [] || idle + then Lwt.return messages + else + let* () = wait_data (wait_closed_connection ()) handler in + Lwt.return (read_channels 100 handler) + in + let message = encode_downgoing messages in + handler.hd_last <- message, number; + set_inactive handler; + Lwt.return message + ) + ) (function | New_connection -> Lwt.return (encode_downgoing []) (* happens if an other connection has been opened on that service *) @@ -560,14 +578,16 @@ end = struct set_inactive handler; (* it doesn't matter what we do here *) Lwt.return timeout_msg - | e -> set_inactive handler; Lwt.fail e) + | e -> set_inactive handler; Lwt.fail e + ) | Eliom_comet_base.Stateful (Eliom_comet_base.Commands commands) -> update_inactive handler; List.iter (function | Eliom_comet_base.Register channel -> register_channel handler channel - | Eliom_comet_base.Close channel -> close_channel' handler channel) + | Eliom_comet_base.Close channel -> close_channel' handler channel + ) (Array.to_list commands); (* command connections are replied immediately by an empty answer *) @@ -586,8 +606,9 @@ end = struct (* as of now only `Client_process scope are handled: so we only stock scope_hierarchy *) type handler_ref_table = ( Eliom_common.scope_hierarchy - , handler option Eliom_reference.Volatile.eref ) - Hashtbl.t + , handler option Eliom_reference.Volatile.eref + ) + Hashtbl.t let handler_ref_table : handler_ref_table = Hashtbl.create 1 @@ -616,11 +637,13 @@ end = struct (*VVV Why is it attached? --Vincent *) ~post_params: Eliom_parameter.( - bool "idle" ** Eliom_comet_base.comet_request_param) + bool "idle" ** Eliom_comet_base.comet_request_param + ) ~fallback:(Eliom_common.force_lazy_site_value fallback_service) (*~name:"comet" (* CCC faut il mettre un nom ? *)*) () - , ref [] ) + , ref [] + ) in let handler = { hd_scope = scope @@ -630,7 +653,8 @@ end = struct ; hd_service ; hd_update_streams_w = None ; hd_last = "", -1 - ; hd_activity = Inactive (Unix.gettimeofday ()) } + ; hd_activity = Inactive (Unix.gettimeofday ()) + } in Eliom_reference.Volatile.set eref (Some handler); run_handler handler; @@ -656,17 +680,13 @@ end = struct in Eliom_common.make_full_cookie_name pref name - let create - ?(scope = Eliom_common.comet_client_process_scope) - ?(name = new_id ()) - ~size - events - = + let create ?(scope = Eliom_common.comet_client_process_scope) + ?(name = new_id ()) ~size events = let name = name_of_scope (scope :> Eliom_common.user_scope) ^ name in let handler = get_handler scope in Logs.info ~src:section (fun fmt -> fmt "create channel %s" name); let channel = Events {queue = Queue.create (); events = None} in - (match channel with + ( match channel with | Stream _ -> assert false | Events channel -> channel.events <- @@ -674,36 +694,40 @@ end = struct (Obj.repr (React.E.fold (fun full x -> - let queue = channel.queue in - full - || - if Queue.length queue > size - then ( - channel.events <- None; - Queue.clear queue; - Queue.push Eliom_comet_base.Full queue; - signal_update handler `Data; - true) - else ( - Queue.push (Eliom_comet_base.Data (marshal x)) queue; - signal_update handler `Data; - false)) - false events))); + let queue = channel.queue in + full + || + if Queue.length queue > size + then ( + channel.events <- None; + Queue.clear queue; + Queue.push Eliom_comet_base.Full queue; + signal_update handler `Data; + true + ) + else ( + Queue.push (Eliom_comet_base.Data (marshal x)) queue; + signal_update handler `Data; + false + ) + ) + false events + ) + ) + ); if List.mem name handler.hd_registered_chan_id then ( handler.hd_registered_chan_id <- List.filter (( <> ) name) handler.hd_registered_chan_id; - launch_channel handler name channel) + launch_channel handler name channel + ) else handler.hd_unregistered_channels <- (name, channel) :: handler.hd_unregistered_channels; {ch_handler = handler; ch_id = name} - let create_unlimited - ?(scope = Eliom_common.comet_client_process_scope) - ?(name = new_id ()) - stream - = + let create_unlimited ?(scope = Eliom_common.comet_client_process_scope) + ?(name = new_id ()) stream = let name = name_of_scope (scope :> Eliom_common.user_scope) ^ name in let handler = get_handler scope in Logs.info ~src:section (fun fmt -> fmt "create channel %s" name); @@ -716,7 +740,8 @@ end = struct then ( handler.hd_registered_chan_id <- List.filter (( <> ) name) handler.hd_registered_chan_id; - launch_channel handler name channel) + launch_channel handler name channel + ) else handler.hd_unregistered_channels <- (name, channel) :: handler.hd_unregistered_channels; @@ -738,21 +763,21 @@ module Channel : sig [Eliom_common.site_scope | Eliom_common.client_process_scope] val create_from_events : - ?scope:[< comet_scope] + ?scope:[< comet_scope] -> ?name:string -> ?size:int -> 'a React.event -> 'a t val create : - ?scope:[< comet_scope] + ?scope:[< comet_scope] -> ?name:string -> ?size:int -> 'a Lwt_stream.t -> 'a t val create_unlimited : - ?scope:Eliom_common.client_process_scope + ?scope:Eliom_common.client_process_scope -> ?name:string -> 'a Lwt_stream.t -> 'a t @@ -761,17 +786,10 @@ module Channel : sig val get_wrapped : 'a t -> 'a Eliom_comet_base.wrapped_channel val external_channel : - ?history:int - -> ?newest:bool - -> prefix:string - -> name:string - -> unit - -> 'a t + ?history:int -> ?newest:bool -> prefix:string -> name:string -> unit -> 'a t val wait_timeout : - ?scope:Eliom_common.client_process_scope - -> float - -> unit Lwt.t + ?scope:Eliom_common.client_process_scope -> float -> unit Lwt.t end = struct type 'a channel = | Stateless of Stateless.channel @@ -787,17 +805,20 @@ end = struct | Stateful channel -> Eliom_comet_base.Stateful_channel ( Stateful.get_service channel - , Eliom_comet_base.chan_id_of_string (Stateful.get_id channel) ) + , Eliom_comet_base.chan_id_of_string (Stateful.get_id channel) + ) | Stateless channel -> Eliom_comet_base.Stateless_channel ( Stateless.get_service () , Eliom_comet_base.chan_id_of_string (Stateless.get_id channel) - , Stateless.get_kind ~newest:false channel ) + , Stateless.get_kind ~newest:false channel + ) | Stateless_newest channel -> Eliom_comet_base.Stateless_channel ( Stateless.get_service () , Eliom_comet_base.chan_id_of_string (Stateless.get_id channel) - , Stateless.get_kind ~newest:true channel ) + , Stateless.get_kind ~newest:true channel + ) | External wrapped -> wrapped let internal_wrap c = @@ -813,29 +834,37 @@ end = struct Stateless (Stateless.create ?name ~size ( Lwt.with_value Eliom_common.sp_key None @@ fun () -> - Lwt_stream.map marshal stream )) + Lwt_stream.map marshal stream + ) + ) let create_stateless_newest_channel ?name stream = Stateless_newest (Stateless.create ?name ~size:1 ( Lwt.with_value Eliom_common.sp_key None @@ fun () -> - Lwt_stream.map marshal stream )) + Lwt_stream.map marshal stream + ) + ) let create_stateful ?scope ?name ?(size = 1000) events = { channel = create_stateful_channel ?scope ?name ~size events - ; channel_mark = channel_mark () } + ; channel_mark = channel_mark () + } let create_unlimited ?scope ?name events = { channel = Stateful (Stateful.create_unlimited ?scope ?name events) - ; channel_mark = channel_mark () } + ; channel_mark = channel_mark () + } let create_stateless ?name ?(size = 1000) stream = { channel = create_stateless_channel ?name ~size stream - ; channel_mark = channel_mark () } + ; channel_mark = channel_mark () + } let create_newest ?name stream = { channel = create_stateless_newest_channel ?name stream - ; channel_mark = channel_mark () } + ; channel_mark = channel_mark () + } type comet_scope = [Eliom_common.site_scope | Eliom_common.client_process_scope] @@ -861,7 +890,10 @@ end = struct (Eliom_service.Post ( Eliom_parameter.unit , Eliom_parameter.( - bool "idle" ** Eliom_comet_base.comet_request_param) )) + bool "idle" ** Eliom_comet_base.comet_request_param + ) + ) + ) () in let last = if newest then None else Some history in @@ -870,8 +902,11 @@ end = struct (Eliom_comet_base.Stateless_channel ( Eliom_comet_base.Comet_service (service, ref []) , Stateless.chan_id_of_string name - , Eliom_comet_base.Last_kind last )) - ; channel_mark = channel_mark () } + , Eliom_comet_base.Last_kind last + ) + ) + ; channel_mark = channel_mark () + } let wait_timeout = Stateful.wait_timeout end diff --git a/src/lib/eliom_comet.server.mli b/src/lib/eliom_comet.server.mli index cbe7ee426d..dccc342d0d 100644 --- a/src/lib/eliom_comet.server.mli +++ b/src/lib/eliom_comet.server.mli @@ -37,7 +37,7 @@ module Channel : sig [Eliom_common.site_scope | Eliom_common.client_process_scope] val create : - ?scope:[< comet_scope] + ?scope:[< comet_scope] -> ?name:string -> ?size:int -> 'a Lwt_stream.t @@ -76,7 +76,7 @@ module Channel : sig [create_unlimited] instead, but be careful of memory leaks. *) val create_from_events : - ?scope:[< comet_scope] + ?scope:[< comet_scope] -> ?name:string -> ?size:int -> 'a React.event @@ -85,7 +85,7 @@ module Channel : sig by the event stream [e]. *) val create_unlimited : - ?scope:Eliom_common.client_process_scope + ?scope:Eliom_common.client_process_scope -> ?name:string -> 'a Lwt_stream.t -> 'a t @@ -103,12 +103,7 @@ module Channel : sig returned to the client. *) val external_channel : - ?history:int - -> ?newest:bool - -> prefix:string - -> name:string - -> unit - -> 'a t + ?history:int -> ?newest:bool -> prefix:string -> name:string -> unit -> 'a t (** [external_channel ~prefix ~name ()] declares an external channel. The channel was created by an instance of Eliom serving the prefix [prefix] (the prefix configured in the tag of @@ -121,9 +116,7 @@ module Channel : sig is [1]. *) val wait_timeout : - ?scope:Eliom_common.client_process_scope - -> float - -> unit Lwt.t + ?scope:Eliom_common.client_process_scope -> float -> unit Lwt.t (** [wait_timeout ~scope time] waits for a period of inactivity of length [time] in the [scope]. Only activity on stateful channels is taken into accounts. diff --git a/src/lib/eliom_comet_base.shared.ml b/src/lib/eliom_comet_base.shared.ml index bb0f21a0f9..4d5c76af85 100644 --- a/src/lib/eliom_comet_base.shared.ml +++ b/src/lib/eliom_comet_base.shared.ml @@ -61,38 +61,40 @@ let comet_request_param = type comet_service = | Comet_service : ( unit - , bool * comet_request - , Eliom_service.post - , Eliom_service.att - , _ - , _ - , _ - , [`WithoutSuffix] - , unit - , [`One of bool] Eliom_parameter.param_name - * [`One of comet_request Eliom_parameter.ocaml] - Eliom_parameter.param_name - , Eliom_service.non_ocaml ) - Eliom_service.t + , bool * comet_request + , Eliom_service.post + , Eliom_service.att + , _ + , _ + , _ + , [`WithoutSuffix] + , unit + , [`One of bool] Eliom_parameter.param_name + * [`One of comet_request Eliom_parameter.ocaml] + Eliom_parameter.param_name + , Eliom_service.non_ocaml + ) + Eliom_service.t * command list ref -> comet_service type internal_comet_service = | Internal_comet_service : ( unit - , bool * comet_request - , Eliom_service.post - , Eliom_service.att - , _ - , Eliom_service.non_ext - , Eliom_service.reg - , [`WithoutSuffix] - , unit - , [`One of bool] Eliom_parameter.param_name - * [`One of comet_request Eliom_parameter.ocaml] - Eliom_parameter.param_name - , Eliom_service.non_ocaml ) - Eliom_service.t + , bool * comet_request + , Eliom_service.post + , Eliom_service.att + , _ + , Eliom_service.non_ext + , Eliom_service.reg + , [`WithoutSuffix] + , unit + , [`One of bool] Eliom_parameter.param_name + * [`One of comet_request Eliom_parameter.ocaml] + Eliom_parameter.param_name + , Eliom_service.non_ocaml + ) + Eliom_service.t * command list ref -> internal_comet_service @@ -108,17 +110,18 @@ type 'a wrapped_channel = type 'a bus_send_service = | Bus_send_service : ( unit - , 'a list - , Eliom_service.post - , Eliom_service.non_att - , Eliom_service.co - , Eliom_service.non_ext - , Eliom_service.reg - , [`WithoutSuffix] - , unit - , [`One of 'a list Eliom_parameter.ocaml] Eliom_parameter.param_name - , Eliom_service.non_ocaml ) - Eliom_service.t + , 'a list + , Eliom_service.post + , Eliom_service.non_att + , Eliom_service.co + , Eliom_service.non_ext + , Eliom_service.reg + , [`WithoutSuffix] + , unit + , [`One of 'a list Eliom_parameter.ocaml] Eliom_parameter.param_name + , Eliom_service.non_ocaml + ) + Eliom_service.t -> 'a bus_send_service type ('a, 'b) wrapped_bus = 'b wrapped_channel * 'a bus_send_service diff --git a/src/lib/eliom_comet_base.shared.mli b/src/lib/eliom_comet_base.shared.mli index 05627dcd1d..310aac21f1 100644 --- a/src/lib/eliom_comet_base.shared.mli +++ b/src/lib/eliom_comet_base.shared.mli @@ -43,10 +43,10 @@ type comet_request = val comet_request_param : ( comet_request - , [`WithoutSuffix] - , [`One of comet_request Eliom_parameter.ocaml] Eliom_parameter.param_name - ) - Eliom_parameter.params_type + , [`WithoutSuffix] + , [`One of comet_request Eliom_parameter.ocaml] Eliom_parameter.param_name + ) + Eliom_parameter.params_type type 'a channel_data = Data of 'a | Full | Closed [@@deriving json] @@ -61,38 +61,40 @@ type answer = type comet_service = | Comet_service : ( unit - , bool * comet_request - , Eliom_service.post - , Eliom_service.att - , _ - , _ - , _ - , [`WithoutSuffix] - , unit - , [`One of bool] Eliom_parameter.param_name - * [`One of comet_request Eliom_parameter.ocaml] - Eliom_parameter.param_name - , Eliom_service.non_ocaml ) - Eliom_service.t + , bool * comet_request + , Eliom_service.post + , Eliom_service.att + , _ + , _ + , _ + , [`WithoutSuffix] + , unit + , [`One of bool] Eliom_parameter.param_name + * [`One of comet_request Eliom_parameter.ocaml] + Eliom_parameter.param_name + , Eliom_service.non_ocaml + ) + Eliom_service.t * command list ref -> comet_service type internal_comet_service = | Internal_comet_service : ( unit - , bool * comet_request - , Eliom_service.post - , Eliom_service.att - , _ - , Eliom_service.non_ext - , Eliom_service.reg - , [`WithoutSuffix] - , unit - , [`One of bool] Eliom_parameter.param_name - * [`One of comet_request Eliom_parameter.ocaml] - Eliom_parameter.param_name - , Eliom_service.non_ocaml ) - Eliom_service.t + , bool * comet_request + , Eliom_service.post + , Eliom_service.att + , _ + , Eliom_service.non_ext + , Eliom_service.reg + , [`WithoutSuffix] + , unit + , [`One of bool] Eliom_parameter.param_name + * [`One of comet_request Eliom_parameter.ocaml] + Eliom_parameter.param_name + , Eliom_service.non_ocaml + ) + Eliom_service.t * command list ref -> internal_comet_service @@ -108,17 +110,18 @@ type 'a wrapped_channel = type 'a bus_send_service = | Bus_send_service : ( unit - , 'a list - , Eliom_service.post - , Eliom_service.non_att - , Eliom_service.co - , Eliom_service.non_ext - , Eliom_service.reg - , [`WithoutSuffix] - , unit - , [`One of 'a list Eliom_parameter.ocaml] Eliom_parameter.param_name - , Eliom_service.non_ocaml ) - Eliom_service.t + , 'a list + , Eliom_service.post + , Eliom_service.non_att + , Eliom_service.co + , Eliom_service.non_ext + , Eliom_service.reg + , [`WithoutSuffix] + , unit + , [`One of 'a list Eliom_parameter.ocaml] Eliom_parameter.param_name + , Eliom_service.non_ocaml + ) + Eliom_service.t -> 'a bus_send_service type ('a, 'b) wrapped_bus = 'b wrapped_channel * 'a bus_send_service diff --git a/src/lib/eliom_common.client.ml b/src/lib/eliom_common.client.ml index 4f606702c4..9b9f72a1e3 100644 --- a/src/lib/eliom_common.client.ml +++ b/src/lib/eliom_common.client.ml @@ -74,7 +74,8 @@ let client_html_file, set_client_html_file = let defer get f = let r = ref None in - (match get () with + ( match get () with | Some v -> r := Some (f v) - | None -> raise (Eliom_site_information_not_available "defer")); + | None -> raise (Eliom_site_information_not_available "defer") + ); r diff --git a/src/lib/eliom_common.server.ml b/src/lib/eliom_common.server.ml index c221dcd5cd..b2a1f58f15 100644 --- a/src/lib/eliom_common.server.ml +++ b/src/lib/eliom_common.server.ml @@ -46,10 +46,12 @@ let tenable_value ~name v = if (not tenable) || override_tenable then ( value <- v; - tenable <- override_tenable) + tenable <- override_tenable + ) else Logs.warn ~src:eliom_logs_src (fun fmt -> - fmt "Ignored setting tenable value %S." name) + fmt "Ignored setting tenable value %S." name + ) end (*****************************************************************************) @@ -70,8 +72,7 @@ let eliom_link_too_old : bool Polytables.key = Polytables.make_key () The string lists are the list of names of expired sessions *) let eliom_service_session_expired : - (full_state_name list * full_state_name list) Polytables.key - = + (full_state_name list * full_state_name list) Polytables.key = Polytables.make_key () let found_stop_key = Polytables.make_key () @@ -100,11 +101,11 @@ type timeout = (* The table of tables for each session. Keys are hashes of cookies or group names *) module SessionCookies = Hashtbl.Make (struct - type t = string + type t = string - let equal = ( = ) - let hash = Hashtbl.hash - end) + let equal = ( = ) + let hash = Hashtbl.hash +end) (* keys in tables are hashes of cookie values *) module Hashed_cookies : sig @@ -141,8 +142,7 @@ type perssessgrp = string (* same triple, marshaled *) let make_persistent_full_group_name ~cookie_level site_dir_string = function | None -> None - | Some g -> - Some (Marshal.to_string (site_dir_string, cookie_level, Left g) []) + | Some g -> Some (Marshal.to_string (site_dir_string, cookie_level, Left g) []) let getperssessgrp a : 'a sessgrp = Marshal.from_string a 0 let string_of_perssessgrp = id @@ -154,102 +154,109 @@ type 'a one_service_cookie_info = sc_hvalue : Hashed_cookies.t (* hash of current value *) ; sc_set_value : string option (* new value to set *) ; sc_table : 'a ref - (* service session table + (* service session table ref towards cookie table *) ; sc_timeout : timeout ref - (* user timeout - + (* user timeout - ref towards cookie table *) ; sc_exp : float option ref - (* expiration date ref + (* expiration date ref (server side) - None = never ref towards cookie table *) ; sc_cookie_exp : cookie_exp ref (* cookie expiration date to set *) ; sc_session_group : cookie_level sessgrp ref (* session group *) - ; mutable sc_session_group_node : string Ocsigen_cache.Dlist.node } + ; mutable sc_session_group_node : string Ocsigen_cache.Dlist.node + } type one_data_cookie_info = { (* in memory data sessions: *) dc_hvalue : Hashed_cookies.t (* hash of current value *) ; dc_set_value : string option (* new value to set *) ; dc_timeout : timeout ref - (* user timeout - + (* user timeout - ref towards cookie table *) ; dc_exp : float option ref - (* expiration date ref (server side) - + (* expiration date ref (server side) - None = never ref towards cookie table *) ; dc_cookie_exp : cookie_exp ref (* cookie expiration date to set *) ; dc_session_group : cookie_level sessgrp ref (* session group *) - ; mutable dc_session_group_node : string Ocsigen_cache.Dlist.node } + ; mutable dc_session_group_node : string Ocsigen_cache.Dlist.node + } type one_persistent_cookie_info = { pc_hvalue : Hashed_cookies.t (* hash of current value *) ; pc_set_value : string option (* new value to set *) ; pc_timeout : timeout ref (* user timeout *) ; pc_cookie_exp : cookie_exp ref (* cookie expiration date to set *) - ; pc_session_group : perssessgrp option ref (* session group *) } + ; pc_session_group : perssessgrp option ref (* session group *) + } (*VVV heavy *) type 'a cookie_info1 = (* service sessions: *) - (string option + ( string option (* value sent by the browser *) (* None = new cookie (not sent by the browser) *) - * 'a one_service_cookie_info session_cookie ref) - (* SCNo_data = the session has been closed + * 'a one_service_cookie_info session_cookie ref + ) + (* SCNo_data = the session has been closed SCData_session_expired = the cookie has not been found in the table. For both of them, ask the browser to remove the cookie. *) - (* This one is not lazy because we must check all service sessions + (* This one is not lazy because we must check all service sessions at each request to find the services *) - Full_state_name_table.t - ref + Full_state_name_table.t + ref (* The key is the full session name *) * (* in memory data sessions: *) - (string option + ( string option (* value sent by the browser *) (* None = new cookie (not sent by the browser) *) - * one_data_cookie_info session_cookie ref) - (* SCNo_data = the session has been closed + * one_data_cookie_info session_cookie ref + ) + (* SCNo_data = the session has been closed SCData_session_expired = the cookie has not been found in the table. For both of them, ask the browser to remove the cookie. *) - Lazy.t - (* Lazy because we do not want to ask the browser to unset the cookie + Lazy.t + (* Lazy because we do not want to ask the browser to unset the cookie if the cookie has not been used, otherwise it is impossible to write a message "Your session has expired" *) - Full_state_name_table.t - ref + Full_state_name_table.t + ref (* The key is the full session name *) * (* persistent sessions: *) - ((string (* value sent by the browser *) - * timeout (* timeout at the beginning of the request *) - * float option - (* (server side) expdate + ( ( string (* value sent by the browser *) + * timeout (* timeout at the beginning of the request *) + * float option + (* (server side) expdate at the beginning of the request None = no exp *) - * perssessgrp option) - (* session group at beginning of request *) - option + * perssessgrp option + ) + (* session group at beginning of request *) + option (* None = new cookie (not sent by the browser) *) - * one_persistent_cookie_info session_cookie ref) - (* SCNo_data = the session has been closed + * one_persistent_cookie_info session_cookie ref + ) + (* SCNo_data = the session has been closed SCData_session_expired = the cookie has not been found in the table. For both of them, ask the browser to remove the cookie. *) - Lwt.t - Lazy.t - Full_state_name_table.t - ref + Lwt.t + Lazy.t + Full_state_name_table.t + ref type 'a cookie_info = 'a cookie_info1 (* unsecure *) * 'a cookie_info1 (* secure *) @@ -262,7 +269,8 @@ module Service_cookie = struct ; expiry : float option ref ; timeout : timeout ref ; session_group : cookie_level sessgrp ref - ; session_group_node : string Ocsigen_cache.Dlist.node } + ; session_group_node : string Ocsigen_cache.Dlist.node + } type 'a table = 'a t SessionCookies.t (* the table contains: @@ -282,7 +290,8 @@ module Data_cookie = struct ; expiry : float option ref ; timeout : timeout ref ; session_group : cookie_level sessgrp ref - ; session_group_node : string Ocsigen_cache.Dlist.node } + ; session_group_node : string Ocsigen_cache.Dlist.node + } type table = t SessionCookies.t end @@ -315,31 +324,28 @@ end = (* keys are IP address modulo "network equivalence" *) struct include Hashtbl.Make (struct - type t = Ipaddr.t + type t = Ipaddr.t - let equal a b = Ipaddr.compare a b = 0 - let hash = Hashtbl.hash - end) + let equal a b = Ipaddr.compare a b = 0 + let hash = Hashtbl.hash + end) let add m4 m6 t k v = add t (network_of_ip k (get_mask4 m4) (get_mask6 m6)) v - - let remove m4 m6 t k = - remove t (network_of_ip k (get_mask4 m4) (get_mask6 m6)) - + let remove m4 m6 t k = remove t (network_of_ip k (get_mask4 m4) (get_mask6 m6)) let find m4 m6 t k = find t (network_of_ip k (get_mask4 m4) (get_mask6 m6)) end module Serv_Table = Map.Make (struct - type t = page_table_key + type t = page_table_key - let compare = compare - end) + let compare = compare +end) module NAserv_Table = Map.Make (struct - type t = na_key_serv + type t = na_key_serv - let compare = compare - end) + let compare = compare +end) type node_info = {ni_id : node_ref; mutable ni_sent : bool} @@ -361,19 +367,20 @@ type server_params = as sent by the browser *) sp_suffix : Url.path option (* suffix *) ; sp_full_state_name : full_state_name option - (* the name of the session + (* the name of the session to which belong the service that answered (if it is a session service) *) - ; sp_client_process_info : client_process_info } + ; sp_client_process_info : client_process_info + } and page_table = page_table_content Serv_Table.t and page_table_content = [ `Ptc of - (page_table ref * page_table_key, na_key_serv) leftright - Ocsigen_cache.Dlist.node - option - * (server_params, Ocsigen_response.t) service list ] + (page_table ref * page_table_key, na_key_serv) leftright + Ocsigen_cache.Dlist.node + option + * (server_params, Ocsigen_response.t) service list ] and naservice_table_content = int @@ -385,8 +392,8 @@ and naservice_table_content = (* timeout and expiration date *) * (server_params -> Ocsigen_response.t Lwt.t) * (page_table ref * page_table_key, na_key_serv) leftright - Ocsigen_cache.Dlist.node - option + Ocsigen_cache.Dlist.node + option (* for limitation of number of dynamic coservices *) and naservice_table = AVide | ATable of naservice_table_content NAserv_Table.t @@ -394,7 +401,7 @@ and naservice_table = AVide | ATable of naservice_table_content NAserv_Table.t and tables = { mutable table_services : (int (* generation *) * int (* priority *) * page_table dircontent ref) - list + list ; table_naservices : naservice_table ref ; (* ref, and not mutable field because it simpler to use recursively with Dir of dircontent ref *) @@ -417,11 +424,11 @@ and tables = the service record. *) service_dlist_add : - ?sp:server_params + ?sp:server_params -> (page_table ref * page_table_key, na_key_serv) leftright -> (page_table ref * page_table_key, na_key_serv) leftright - Ocsigen_cache.Dlist.node - (* We use a dlist for limiting the number of dynamic + Ocsigen_cache.Dlist.node + (* We use a dlist for limiting the number of dynamic anonymous coservices in each table (and avoid DoS). There is one dlist for each session, and one for each IP in global tables. The dlist parameter is the table and @@ -431,7 +438,7 @@ and tables = and sitedata = { mutable site_dir : Url.path option - (* None when statically linked + (* None when statically linked before module init*) ; mutable site_dir_string : string option (* idem *) ; mutable config_info : Ocsigen_extensions.config_info option (* idem *) @@ -498,11 +505,12 @@ and sitedata = ; mutable html_content_type : string option ; mutable ignored_get_params : (string * Re.re) list ; mutable ignored_post_params : (string * Re.re) list - ; mutable omitpersistentstorage : omitpersistentstorage_rule list option } + ; mutable omitpersistentstorage : omitpersistentstorage_rule list option + } and dlist_ip_table = (page_table ref * page_table_key, na_key_serv) leftright Ocsigen_cache.Dlist.t - Net_addr_Hashtbl.t + Net_addr_Hashtbl.t let check_initialised field = match field with @@ -515,13 +523,12 @@ let get_config_info sitedata = check_initialised sitedata.config_info let create_dlist_ip_table = Net_addr_Hashtbl.create let find_dlist_ip_table : - int option * 'b - -> int option * 'b - -> dlist_ip_table - -> Ipaddr.t - -> (page_table ref * page_table_key, na_key_serv) leftright - Ocsigen_cache.Dlist.t - = + int option * 'b + -> int option * 'b + -> dlist_ip_table + -> Ipaddr.t + -> (page_table ref * page_table_key, na_key_serv) leftright + Ocsigen_cache.Dlist.t = Net_addr_Hashtbl.find (*****************************************************************************) @@ -539,8 +546,7 @@ let make_full_cookie_name cookieprefix {user_scope; secure; site_dir_str} = String.concat "" [cookieprefix; secure; site_dir_str; hier1; hiername] let make_full_state_name2 site_dir_str secure ~(scope : [< user_scope]) : - full_state_name - = + full_state_name = (* The information in the cookie name, without the kind of session *) {user_scope = (scope :> user_scope); secure; site_dir_str} @@ -556,22 +562,20 @@ type info = ; session_info : sess_info ; all_cookie_info : tables cookie_info ; tab_cookie_info : tables cookie_info - ; user_tab_cookies : Ocsigen_cookie_map.t } + ; user_tab_cookies : Ocsigen_cookie_map.t + } (*****************************************************************************) (** Create server parameters record *) -let make_server_params - sitedata - ({request = ri; session_info = si; _} as info) - suffix - full_state_name - = +let make_server_params sitedata ({request = ri; session_info = si; _} as info) + suffix full_state_name = let appl_name = try Some (Ocsigen_cookie_map.Map_inner.find appl_name_cookie_name - si.si_tab_cookies) + si.si_tab_cookies + ) (* It is an XHR from the client application, or an internal form *) with Not_found -> None in @@ -584,7 +588,8 @@ let make_server_params ; cpi_hostname = Ocsigen_extensions.get_hostname ri ; cpi_server_port = Ocsigen_extensions.get_port ri ; cpi_original_full_path = - Ocsigen_request.original_full_path request_info } + Ocsigen_request.original_full_path request_info + } in { sp_request = ri ; sp_si = si @@ -596,7 +601,8 @@ let make_server_params ; sp_client_appl_name = appl_name ; sp_suffix = suffix ; sp_full_state_name = full_state_name - ; sp_client_process_info = cpi } + ; sp_client_process_info = cpi + } let sp_key = Lwt.new_key () let get_sp_option () = Lwt.get sp_key @@ -641,7 +647,8 @@ let register_scope_hierarchy (name : string) = then failwith (Printf.sprintf "the scope hierarchy %s has already been registered" - name) + name + ) else registered_scope_hierarchies := Hier_set.add name !registered_scope_hierarchies @@ -652,7 +659,8 @@ let register_scope_hierarchy (name : string) = then failwith (Printf.sprintf "the scope hierarchy %s has already been registered" - name) + name + ) else sp.sp_sitedata.registered_scope_hierarchies <- Hier_set.add name sp.sp_sitedata.registered_scope_hierarchies @@ -669,7 +677,8 @@ let list_scope_hierarchies () = (Hier_set.elements !registered_scope_hierarchies) @ List.map (fun s -> User_hier s) - (Hier_set.elements sp.sp_sitedata.registered_scope_hierarchies)) + (Hier_set.elements sp.sp_sitedata.registered_scope_hierarchies) + ) (*****************************************************************************) (* The current registration directory *) @@ -679,9 +688,9 @@ let absolute_change_sitedata, get_current_sitedata, end_current_sitedata = ( (fun sitedata -> f2 := sitedata :: !f2) (* absolute_change_sitedata *) , (fun () -> match !f2 with - | [] -> - raise (Eliom_site_information_not_available "get_current_sitedata") - | sd :: _ -> sd) + | [] -> raise (Eliom_site_information_not_available "get_current_sitedata") + | sd :: _ -> sd + ) (* get_current_sitedata *) , fun () -> popf2 () (* end_current_sitedata *) ) (* Warning: these functions are used only during the initialisation @@ -742,7 +751,8 @@ let force_lazy_site_value v = match global_register_allowed () with | Some f -> f () | None -> - raise (Eliom_site_information_not_available "force_lazy_site_value")) + raise (Eliom_site_information_not_available "force_lazy_site_value") + ) in try Polytables.get ~table:sitedata.site_value_table ~key:v.lazy_sv_key with Not_found -> @@ -789,7 +799,8 @@ let dlist_finaliser_ip sitedata ip na_table_ref node = try Net_addr_Hashtbl.remove sitedata.ipv4mask sitedata.ipv6mask sitedata.dlist_ip_table ip - with Not_found -> ()) + with Not_found -> () + ) | None -> () let add_dlist_ dlist v = @@ -810,49 +821,53 @@ let empty_tables max forsession = ; csrf_get_or_na_registration_functions = Int.Table.empty ; csrf_post_registration_functions = Int.Table.empty ; service_dlist_add = - (if forsession - then ( - let dlist = Ocsigen_cache.Dlist.create max in - Ocsigen_cache.Dlist.set_finaliser_before (dlist_finaliser t2) dlist; - fun ?sp:_ v -> add_dlist_ dlist v) - else - fun ?sp v -> - let ip, max, sitedata = - match sp with - | None -> ( - ( default_ip_table_key - , max - , match global_register_allowed () with - | None -> - failwith "global tables created outside initialisation" - | Some get -> get () )) - | Some sp -> - let ip = - match - Ocsigen_request.client_conn - sp.sp_request.Ocsigen_extensions.request_info - with - | `Inet (ip, _) -> ip - | _ -> default_ip_table_key - in - ( ip - , fst sp.sp_sitedata.max_anonymous_services_per_subnet - , sp.sp_sitedata ) - in - let dlist = - try - Net_addr_Hashtbl.find sitedata.ipv4mask sitedata.ipv6mask - sitedata.dlist_ip_table ip - with Not_found -> - let dlist = Ocsigen_cache.Dlist.create max in - Net_addr_Hashtbl.add sitedata.ipv4mask sitedata.ipv6mask - sitedata.dlist_ip_table ip dlist; - Ocsigen_cache.Dlist.set_finaliser_before - (dlist_finaliser_ip sitedata ip t2) - dlist; - dlist - in - add_dlist_ dlist v) } + ( if forsession + then ( + let dlist = Ocsigen_cache.Dlist.create max in + Ocsigen_cache.Dlist.set_finaliser_before (dlist_finaliser t2) dlist; + fun ?sp:_ v -> add_dlist_ dlist v + ) + else + fun ?sp v -> + let ip, max, sitedata = + match sp with + | None -> ( + ( default_ip_table_key + , max + , match global_register_allowed () with + | None -> + failwith "global tables created outside initialisation" + | Some get -> get () ) + ) + | Some sp -> + let ip = + match + Ocsigen_request.client_conn + sp.sp_request.Ocsigen_extensions.request_info + with + | `Inet (ip, _) -> ip + | _ -> default_ip_table_key + in + ( ip + , fst sp.sp_sitedata.max_anonymous_services_per_subnet + , sp.sp_sitedata ) + in + let dlist = + try + Net_addr_Hashtbl.find sitedata.ipv4mask sitedata.ipv6mask + sitedata.dlist_ip_table ip + with Not_found -> + let dlist = Ocsigen_cache.Dlist.create max in + Net_addr_Hashtbl.add sitedata.ipv4mask sitedata.ipv6mask + sitedata.dlist_ip_table ip dlist; + Ocsigen_cache.Dlist.set_finaliser_before + (dlist_finaliser_ip sitedata ip t2) + dlist; + dlist + in + add_dlist_ dlist v + ) + } let new_service_session_tables sitedata = empty_tables (fst sitedata.max_anonymous_services_per_session) true @@ -893,15 +908,16 @@ let getcookies secure cookie_level cookienamepref cookies = let last = length - 1 in Ocsigen_cookie_map.Map_inner.fold (fun name value beg -> - if String.first_diff cookienamepref name 0 last = length - then - try - let expcn = full_state_name_of_cookie_name cookie_level name in - if expcn.secure = secure - then Full_state_name_table.add expcn value beg - else beg - with Not_found -> beg - else beg) + if String.first_diff cookienamepref name 0 last = length + then + try + let expcn = full_state_name_of_cookie_name cookie_level name in + if expcn.secure = secure + then Full_state_name_table.add expcn value beg + else beg + with Not_found -> beg + else beg + ) cookies Full_state_name_table.empty (* After an action, we do not take into account actual get params, @@ -917,7 +933,8 @@ type cpi = client_process_info = { cpi_ssl : bool ; cpi_hostname : string ; cpi_server_port : int - ; cpi_original_full_path : string list } + ; cpi_original_full_path : string list + } [@@deriving json] [@@@warning "+39"] @@ -986,7 +1003,8 @@ let get_session_info ~sitedata ~req previous_extension_err = (fun t (k, v) -> Ocsigen_cookie_map.Map_inner.add k v t) Ocsigen_cookie_map.Map_inner.empty tc , post_params ) - | None -> Ocsigen_cookie_map.Map_inner.empty, post_params) + | None -> Ocsigen_cookie_map.Map_inner.empty, post_params + ) in None, tab_cookies, post_params in @@ -1000,12 +1018,13 @@ let get_session_info ~sitedata ~req previous_extension_err = in let epd = lazy - (match - Ocsigen_request.header ri - (Ocsigen_header.Name.of_string expecting_process_page_name) - with + ( match + Ocsigen_request.header ri + (Ocsigen_header.Name.of_string expecting_process_page_name) + with | Some epd -> [%of_json: bool] epd - | None -> false) + | None -> false + ) in let post_params, get_params, to_be_considered_as_get = let g = Ocsigen_request.get_params_flat ri in @@ -1040,8 +1059,8 @@ let get_session_info ~sitedata ~req previous_extension_err = , nl_file_params , all_get_but_nl (*204FORMS*, internal_form *) , ignored_get - , ignored_post ) ) - = + , ignored_post + ) ) = try ( get_params , post_params @@ -1073,7 +1092,8 @@ let get_session_info ~sitedata ~req previous_extension_err = , nl_file_params , all_get_but_nl (*204FORMS*, internal_form *) , ignored_get - , ignored_post ) ) + , ignored_post + ) ) in let browser_cookies = match @@ -1110,8 +1130,7 @@ let get_session_info ~sitedata ~req previous_extension_err = , (get_state, post_state) , (get_params, other_get_params) , na_get_params - , post_params ) - = + , post_params ) = let post_naservice_name, na_post_params = try let n, pp = List.assoc_remove naservice_num post_params in @@ -1120,7 +1139,8 @@ let get_session_info ~sitedata ~req previous_extension_err = try let n, pp = List.assoc_remove naservice_name post_params in RNa_post_ n, pp - with Not_found -> RNa_no, []) + with Not_found -> RNa_no, [] + ) in match post_naservice_name with | RNa_post_ _ | RNa_post' _ -> @@ -1129,12 +1149,14 @@ let get_session_info ~sitedata ~req previous_extension_err = , (RAtt_no, RAtt_no) , ([], get_params) , lazy - (try - (try naservice_name, List.assoc naservice_name get_params - with Not_found -> - naservice_num, List.assoc naservice_num get_params) - :: fst (split_prefix_param na_co_param_prefix get_params) - with Not_found -> []) + ( try + ( try naservice_name, List.assoc naservice_name get_params + with Not_found -> + naservice_num, List.assoc naservice_num get_params + ) + :: fst (split_prefix_param na_co_param_prefix get_params) + with Not_found -> [] + ) , na_post_params ) | _ -> ( let get_naservice_name, na_name_num, (na_get_params, other_get_params) = @@ -1149,7 +1171,8 @@ let get_session_info ~sitedata ~req previous_extension_err = ( RNa_get_ n , [naservice_name, n] , split_prefix_param na_co_param_prefix gp ) - with Not_found -> RNa_no, [], ([], get_params)) + with Not_found -> RNa_no, [], ([], get_params) + ) in match get_naservice_name with | RNa_get_ _ | RNa_get' _ -> @@ -1176,7 +1199,8 @@ let get_session_info ~sitedata ~req previous_extension_err = List.assoc_remove post_state_param_name post_params in RAtt_named s, pp - with Not_found -> RAtt_no, post_params) + with Not_found -> RAtt_no, post_params + ) in let get_state, (get_params, other_get_params) = try @@ -1190,19 +1214,22 @@ let get_session_info ~sitedata ~req previous_extension_err = List.assoc_remove get_state_param_name get_params in RAtt_named s, split_prefix_param co_param_prefix gp - with Not_found -> RAtt_no, (get_params, [])) + with Not_found -> RAtt_no, (get_params, []) + ) in ( RNa_no , (get_state, post_state) , (get_params, other_get_params) , lazy (na_name_num @ na_get_params) - , post_params )) + , post_params ) + ) in let persistent_nl_get_params = lazy (String.Table.fold (fun k a t -> if nl_is_persistent k then String.Table.add k a t else t) - nl_get_params String.Table.empty) + nl_get_params String.Table.empty + ) in let data_cookies_tab = getcookies false `Client_process datacookiename tab_cookies @@ -1231,19 +1258,21 @@ let get_session_info ~sitedata ~req previous_extension_err = *) ( Ocsigen_request.update ri ?meth: - (if Ocsigen_request.meth ri = `HEAD || to_be_considered_as_get - then Some `GET - else - None - (* Here we modify ri, instead of putting service parameters in + ( if Ocsigen_request.meth ri = `HEAD || to_be_considered_as_get + then Some `GET + else + None + (* Here we modify ri, instead of putting service parameters in si. Thus it works better after actions: the request can be taken by other extensions, with new parameters. Initial - parameters are kept in si. *)) + parameters are kept in si. *) + ) ~get_params_flat:get_params ?post_data: - (if no_post_param - then None - else Some (Some (post_params, file_params))) + ( if no_post_param + then None + else Some (Some (post_params, file_params)) + ) , { si_service_session_cookies = service_cookies ; si_data_session_cookies = data_cookies ; si_persistent_session_cookies = persistent_cookies @@ -1271,12 +1300,14 @@ let get_session_info ~sitedata ~req previous_extension_err = ; si_ignored_post_params = ignored_post ; si_client_process_info = cpi ; si_expect_process_data = - epd (*204FORMS* si_internal_form= internal_form; *) } ) + epd (*204FORMS* si_internal_form= internal_form; *) + } ) in Lwt.return ( {req_whole with Ocsigen_extensions.request_info = ri} , sess - , previous_tab_cookies_info ) + , previous_tab_cookies_info + ) exception Eliom_retry_with of info @@ -1294,7 +1325,8 @@ module Omit_persistent_storage = struct header_name with | None -> false (* no User-Agent header *) - | Some header_value -> Re.execp regexp header_value) + | Some header_value -> Re.execp regexp header_value + ) in List.for_all apply_rule rules | _ -> false @@ -1311,15 +1343,18 @@ module Ocsipersist = struct let add table key value = Omit_persistent_storage.not_if_omitting_storage (fun () -> - add table key value) + add table key value + ) let remove table key = Omit_persistent_storage.not_if_omitting_storage (fun () -> - remove table key) + remove table key + ) let replace_if_exists table key value = Omit_persistent_storage.not_if_omitting_storage (fun () -> - replace_if_exists table key value) + replace_if_exists table key value + ) end module Store = struct @@ -1334,27 +1369,28 @@ module Ocsipersist = struct module Table (T : sig - val name : string - end) + val name : string + end) (Key : COLUMN) (Value : COLUMN) = struct include Table (T) (Key) (Value) let add key value = - Omit_persistent_storage.not_if_omitting_storage (fun () -> - add key value) + Omit_persistent_storage.not_if_omitting_storage (fun () -> add key value) let remove key = Omit_persistent_storage.not_if_omitting_storage (fun () -> remove key) let replace_if_exists key value = Omit_persistent_storage.not_if_omitting_storage (fun () -> - replace_if_exists key value) + replace_if_exists key value + ) let modify_opt key f = Omit_persistent_storage.not_if_omitting_storage (fun () -> - modify_opt key f) + modify_opt key f + ) end end end @@ -1374,14 +1410,14 @@ module Persistent_tables = struct let remove_key_from_all_tables key = (* doesn't remove entry from Persistent_cookies_expiry_dates; not a problem *) Lwt_list.iter_s - (fun (module T : Ocsipersist.TABLE with type key = string) -> - T.remove key) + (fun (module T : Ocsipersist.TABLE with type key = string) -> T.remove key) !functorial_tables >>= fun () -> Lwt_list.iter_s (* could be replaced by iter_p *) (fun t -> - Ocsipersist.Polymorphic.open_table t >>= fun table -> - Ocsipersist.Polymorphic.remove table key >>= Lwt.pause) + Ocsipersist.Polymorphic.open_table t >>= fun table -> + Ocsipersist.Polymorphic.remove table key >>= Lwt.pause + ) !polymorphic_tables let number_of_tables () = @@ -1390,13 +1426,15 @@ module Persistent_tables = struct let number_of_table_elements () = Lwt_list.map_s (fun t -> - Ocsipersist.Polymorphic.open_table t >>= fun table -> - Ocsipersist.Polymorphic.length table >>= fun e -> Lwt.return (t, e)) + Ocsipersist.Polymorphic.open_table t >>= fun table -> + Ocsipersist.Polymorphic.length table >>= fun e -> Lwt.return (t, e) + ) !polymorphic_tables >>= fun polymorphic_counts -> Lwt_list.map_s (fun (module T : Ocsipersist.TABLE with type key = string) -> - T.length () >>= fun n -> Lwt.return (T.name, n)) + T.length () >>= fun n -> Lwt.return (T.name, n) + ) !functorial_tables >>= fun functorial_counts -> Lwt.return @@ polymorphic_counts @ functorial_counts @@ -1439,7 +1477,9 @@ let patch_request_info ({Ocsigen_extensions.request_info; _} as r) = List.remove_assoc nl_get_appl_parameter (Ocsigen_request.get_params_flat request_info) in - Ocsigen_request.update ~get_params_flat request_info) } + Ocsigen_request.update ~get_params_flat request_info + ) + } | None -> r (* Returns if we want secure cookie *) @@ -1453,7 +1493,8 @@ module To_and_of_shared = struct type 'a t = { server : 'a to_and_of ; client : 'a to_and_of Eliom_client_value.t option - ; wrapper : wrapper } + ; wrapper : wrapper + } [@@warning "-69"] let wrapper : wrapper = @@ -1479,11 +1520,13 @@ let get_app_name () = !current_app_name let defer get f = let r = ref None in - (match get () with + ( match get () with | Some v -> r := Some (f v) | None -> Ocsigen_loader.add_module_init_function (get_app_name ()) (fun () -> match get () with | Some v -> r := Some (f v) - | None -> raise (Eliom_site_information_not_available "defer"))); + | None -> raise (Eliom_site_information_not_available "defer") + ) + ); r diff --git a/src/lib/eliom_common.server.mli b/src/lib/eliom_common.server.mli index 04de1afa2d..9a1a9214cc 100644 --- a/src/lib/eliom_common.server.mli +++ b/src/lib/eliom_common.server.mli @@ -241,7 +241,8 @@ type client_process_info = { cpi_ssl : bool ; cpi_hostname : string ; cpi_server_port : int - ; cpi_original_full_path : Url.path } + ; cpi_original_full_path : Url.path + } type sess_info = { si_other_get_params : (string * string) list @@ -292,10 +293,7 @@ type 'a sessgrp = string * cookie_level * (string, Ipaddr.t) leftright type perssessgrp (* the same triple, marshaled *) val make_persistent_full_group_name : - cookie_level:cookie_level - -> string - -> string option - -> perssessgrp option + cookie_level:cookie_level -> string -> string option -> perssessgrp option val getperssessgrp : perssessgrp -> 'a sessgrp val string_of_perssessgrp : perssessgrp -> string @@ -331,7 +329,8 @@ type 'a one_service_cookie_info = ; sc_exp : float option ref ; sc_cookie_exp : cookie_exp ref ; sc_session_group : cookie_level sessgrp ref (* session group *) - ; mutable sc_session_group_node : string Ocsigen_cache.Dlist.node } + ; mutable sc_session_group_node : string Ocsigen_cache.Dlist.node + } type one_data_cookie_info = { dc_hvalue : Hashed_cookies.t @@ -340,28 +339,31 @@ type one_data_cookie_info = ; dc_exp : float option ref ; dc_cookie_exp : cookie_exp ref ; dc_session_group : cookie_level sessgrp ref (* session group *) - ; mutable dc_session_group_node : string Ocsigen_cache.Dlist.node } + ; mutable dc_session_group_node : string Ocsigen_cache.Dlist.node + } type one_persistent_cookie_info = { pc_hvalue : Hashed_cookies.t ; pc_set_value : string option ; pc_timeout : timeout ref ; pc_cookie_exp : cookie_exp ref - ; pc_session_group : perssessgrp option ref } + ; pc_session_group : perssessgrp option ref + } type 'a cookie_info1 = (string option * 'a one_service_cookie_info session_cookie ref) + Full_state_name_table.t + ref + * (string option * one_data_cookie_info session_cookie ref) Lazy.t + Full_state_name_table.t + ref + * ( (string * timeout * float option * perssessgrp option) option + * one_persistent_cookie_info session_cookie ref + ) + Lwt.t + Lazy.t Full_state_name_table.t ref - * (string option * one_data_cookie_info session_cookie ref) Lazy.t - Full_state_name_table.t - ref - * ((string * timeout * float option * perssessgrp option) option - * one_persistent_cookie_info session_cookie ref) - Lwt.t - Lazy.t - Full_state_name_table.t - ref type 'a cookie_info = 'a cookie_info1 (* unsecure *) * 'a cookie_info1 (* secure *) @@ -373,7 +375,8 @@ module Service_cookie : sig ; expiry : float option ref ; timeout : timeout ref ; session_group : cookie_level sessgrp ref - ; session_group_node : string Ocsigen_cache.Dlist.node } + ; session_group_node : string Ocsigen_cache.Dlist.node + } type 'a table = 'a t SessionCookies.t end @@ -385,7 +388,8 @@ module Data_cookie : sig ; expiry : float option ref ; timeout : timeout ref ; session_group : cookie_level sessgrp ref - ; session_group_node : string Ocsigen_cache.Dlist.node } + ; session_group_node : string Ocsigen_cache.Dlist.node + } type table = t SessionCookies.t end @@ -412,7 +416,8 @@ type ('params, 'result) service = { s_id : anon_params_type * anon_params_type ; mutable s_max_use : int option ; s_expire : (float * float ref) option - ; s_f : bool -> 'params -> 'result Lwt.t } + ; s_f : bool -> 'params -> 'result Lwt.t + } type server_params = { sp_request : Ocsigen_extensions.request @@ -429,7 +434,7 @@ type server_params = sp_suffix : Url.path option ; sp_full_state_name : full_state_name option ; sp_client_process_info : client_process_info - (* Contains the base URL information from which the client process + (* Contains the base URL information from which the client process has been launched (if any). All relative links and forms will be created with respect to this information (if present - from current URL otherwise). It is taken form a client process state @@ -442,10 +447,10 @@ and page_table = page_table_content Serv_Table.t and page_table_content = [ `Ptc of - (page_table ref * page_table_key, na_key_serv) leftright - Ocsigen_cache.Dlist.node - option - * (server_params, Ocsigen_response.t) service list ] + (page_table ref * page_table_key, na_key_serv) leftright + Ocsigen_cache.Dlist.node + option + * (server_params, Ocsigen_response.t) service list ] and naservice_table_content = int @@ -457,8 +462,8 @@ and naservice_table_content = (* timeout and expiration date *) * (server_params -> Ocsigen_response.t Lwt.t) * (page_table ref * page_table_key, na_key_serv) leftright - Ocsigen_cache.Dlist.node - option + Ocsigen_cache.Dlist.node + option (* for limitation of number of dynamic coservices *) and naservice_table = AVide | ATable of naservice_table_content NAserv_Table.t @@ -466,7 +471,7 @@ and naservice_table = AVide | ATable of naservice_table_content NAserv_Table.t and tables = { mutable table_services : (int (* generation *) * int (* priority *) * page_table dircontent ref) - list + list ; table_naservices : naservice_table ref ; (* Information for the GC: *) mutable table_contains_services_with_timeout : bool @@ -487,11 +492,11 @@ and tables = the service record. *) service_dlist_add : - ?sp:server_params + ?sp:server_params -> (page_table ref * page_table_key, na_key_serv) leftright -> (page_table ref * page_table_key, na_key_serv) leftright - Ocsigen_cache.Dlist.node - (* Add in a dlist + Ocsigen_cache.Dlist.node + (* Add in a dlist for limiting the number of dynamic anonymous coservices in each table (and avoid DoS). There is one dlist for each session, and one for each IP @@ -504,7 +509,7 @@ and tables = and sitedata = { mutable site_dir : Url.path option - (* None when statically linked + (* None when statically linked before module init*) ; mutable site_dir_string : string option (* idem *) ; mutable config_info : Ocsigen_extensions.config_info option (* idem *) @@ -563,7 +568,8 @@ and sitedata = ; mutable html_content_type : string option ; mutable ignored_get_params : (string * Re.re) list ; mutable ignored_post_params : (string * Re.re) list - ; mutable omitpersistentstorage : omitpersistentstorage_rule list option } + ; mutable omitpersistentstorage : omitpersistentstorage_rule list option + } type 'a lazy_site_value (** lazy site values, are lazy values with @@ -579,16 +585,13 @@ type info = ; session_info : sess_info ; all_cookie_info : tables cookie_info ; tab_cookie_info : tables cookie_info - ; user_tab_cookies : Ocsigen_cookie_map.t } + ; user_tab_cookies : Ocsigen_cookie_map.t + } exception Eliom_retry_with of info val make_server_params : - sitedata - -> info - -> Url.path option - -> full_state_name option - -> server_params + sitedata -> info -> Url.path option -> full_state_name option -> server_params val empty_page_table : unit -> page_table val empty_dircontent : unit -> 'a dircontent @@ -598,41 +601,33 @@ val empty_tables : int -> bool -> tables val new_service_session_tables : sitedata -> tables val split_prefix_param : - string - -> (string * 'a) list - -> (string * 'a) list * (string * 'a) list + string -> (string * 'a) list -> (string * 'a) list * (string * 'a) list val get_session_info : - sitedata:sitedata + sitedata:sitedata -> req:Ocsigen_extensions.request -> int - -> (Ocsigen_extensions.request + -> ( Ocsigen_extensions.request * sess_info - * (tables cookie_info * Ocsigen_cookie_map.t) option) - Lwt.t + * (tables cookie_info * Ocsigen_cookie_map.t) option + ) + Lwt.t type ('a, 'b) foundornot = Found of 'a | Notfound of 'b val make_full_cookie_name : string -> full_state_name -> string val make_full_state_name : - sp:server_params - -> secure:bool - -> scope:[< user_scope] - -> full_state_name + sp:server_params -> secure:bool -> scope:[< user_scope] -> full_state_name val make_full_state_name2 : - string - -> bool - -> scope:[< user_scope] - -> full_state_name + string -> bool -> scope:[< user_scope] -> full_state_name module Persistent_tables : sig val create : string -> 'a Ocsipersist.table Lwt.t val add_functorial_table : - (module Ocsipersist.TABLE with type key = string) - -> unit + (module Ocsipersist.TABLE with type key = string) -> unit val remove_key_from_all_tables : string -> unit Lwt.t val number_of_tables : unit -> int @@ -654,7 +649,7 @@ val get_site_data : unit -> sitedata modules, and during a request.} *) val eliom_params_after_action : - ((string * string) list + ( (string * string) list * (string * string) list option * (string * file_info) list option * (string * string) list String.Table.t @@ -663,16 +658,15 @@ val eliom_params_after_action : * (string * string) list (*204FORMS* * bool *) * (string * string) list - * (string * string) list) - Polytables.key + * (string * string) list + ) + Polytables.key val att_key_serv_of_req : att_key_req -> att_key_serv val na_key_serv_of_req : na_key_req -> na_key_serv val remove_naservice_table : - naservice_table - -> NAserv_Table.key - -> naservice_table + naservice_table -> NAserv_Table.key -> naservice_table val get_mask4 : sitedata -> int val get_mask6 : sitedata -> int @@ -682,20 +676,21 @@ val ipv6mask : int ref val create_dlist_ip_table : int -> dlist_ip_table val find_dlist_ip_table : - int option * 'a + int option * 'a -> int option * 'a -> dlist_ip_table -> Ipaddr.t -> (page_table ref * page_table_key, na_key_serv) leftright - Ocsigen_cache.Dlist.t + Ocsigen_cache.Dlist.t val get_cookie_info : server_params -> [< cookie_level] -> tables cookie_info val tab_cookie_action_info_key : - (tables cookie_info + ( tables cookie_info * Ocsigen_cookie_map.t - * string Ocsigen_cookie_map.Map_inner.t) - Polytables.key + * string Ocsigen_cookie_map.Map_inner.t + ) + Polytables.key val sp_key : server_params Lwt.key val get_sp_option : unit -> server_params option @@ -723,8 +718,7 @@ val bus_unwrap_id : unwrap_id val nl_get_appl_parameter : string val patch_request_info : - Ocsigen_extensions.request - -> Ocsigen_extensions.request + Ocsigen_extensions.request -> Ocsigen_extensions.request type eliom_js_page_data = { ejs_global_data : (Eliom_runtime.global_data * Eliom_wrap.unwrapper) option @@ -734,7 +728,8 @@ type eliom_js_page_data = ; (* Client attrib *) ejs_client_attrib_table : Eliom_runtime.RawXML.client_attrib_table ; (* Session info *) - ejs_sess_info : sess_info } + ejs_sess_info : sess_info + } val get_site_dir : sitedata -> Url.path val get_site_dir_string : sitedata -> string @@ -749,9 +744,7 @@ module To_and_of_shared : sig type 'a t val create : - ?client_to_and_of:'a to_and_of Eliom_client_value.t - -> 'a to_and_of - -> 'a t + ?client_to_and_of:'a to_and_of Eliom_client_value.t -> 'a to_and_of -> 'a t val to_string : 'a t -> 'a -> string val of_string : 'a t -> string -> 'a diff --git a/src/lib/eliom_common_base.shared.ml b/src/lib/eliom_common_base.shared.ml index 51c1e01b26..485670c1a9 100644 --- a/src/lib/eliom_common_base.shared.ml +++ b/src/lib/eliom_common_base.shared.ml @@ -72,10 +72,10 @@ type full_state_name = {user_scope : user_scope; secure : bool; site_dir_str : string} module Full_state_name_table = Map.Make (struct - type t = full_state_name + type t = full_state_name - let compare = compare - end) + let compare = compare +end) (******************************************************************) (* Service kinds: *) @@ -183,7 +183,8 @@ type client_process_info = { cpi_ssl : bool ; cpi_hostname : string ; cpi_server_port : int - ; cpi_original_full_path : string list } + ; cpi_original_full_path : string list + } [@@deriving json] [@@@warning "+39"] @@ -206,7 +207,7 @@ type sess_info = string Full_state_name_table.t * string Full_state_name_table.t * string Full_state_name_table.t - (* the same, but for secure cookies *) + (* the same, but for secure cookies *) ; (* now for tab cookies: *) si_service_session_cookies_tab : string Full_state_name_table.t ; si_data_session_cookies_tab : string Full_state_name_table.t @@ -219,7 +220,7 @@ type sess_info = ; si_nonatt_info : na_key_req ; si_state_info : att_key_req * att_key_req ; si_previous_extension_error : int - (* HTTP error code sent by previous extension (default: 404) *) + (* HTTP error code sent by previous extension (default: 404) *) ; si_na_get_params : (string * string) list Lazy.t ; si_nl_get_params : (string * string) list String.Table.t ; si_nl_post_params : (string * string) list String.Table.t @@ -231,7 +232,8 @@ type sess_info = ; si_ignored_post_params : (string * string) list ; si_client_process_info : client_process_info option ; si_expect_process_data : bool Lazy.t - (*204FORMS* si_internal_form: bool; *) } + (*204FORMS* si_internal_form: bool; *) + } type eliom_js_page_data = { ejs_global_data : (Eliom_runtime.global_data * Eliom_wrap.unwrapper) option @@ -241,7 +243,8 @@ type eliom_js_page_data = ; (* Client Attributes *) ejs_client_attrib_table : Eliom_runtime.RawXML.client_attrib_table ; (* Session info *) - ejs_sess_info : sess_info } + ejs_sess_info : sess_info + } (************ unwrapping identifiers *********************) @@ -312,7 +315,8 @@ let split_prefix_param pref l = let len = String.length pref in List.partition (fun (n, _) -> - try String.sub n 0 len = pref with Invalid_argument _ -> false) + try String.sub n 0 len = pref with Invalid_argument _ -> false + ) l (* Remove all parameters whose name starts with pref *) @@ -322,7 +326,8 @@ let remove_prefixed_param pref l = | [] -> [] | ((n, _) as a) :: l -> ( try if String.sub n 0 len = pref then aux l else a :: aux l - with Invalid_argument _ -> a :: aux l) + with Invalid_argument _ -> a :: aux l + ) in aux l @@ -364,7 +369,8 @@ type ('params, 'result) service = s_id : anon_params_type * anon_params_type ; mutable s_max_use : int option ; s_expire : (float * float ref) option - ; s_f : bool -> 'params -> 'result Lwt.t } + ; s_f : bool -> 'params -> 'result Lwt.t + } type 'a to_and_of = {of_string : string -> 'a; to_string : 'a -> string} diff --git a/src/lib/eliom_config.server.ml b/src/lib/eliom_config.server.ml index a9ef09e749..26d51669fc 100644 --- a/src/lib/eliom_config.server.ml +++ b/src/lib/eliom_config.server.ml @@ -137,11 +137,13 @@ let get_config () = | Some _ -> ( match !Eliommod.config with | Some c -> c - | None -> failwith "No config file. Is it a statically linked executable?") + | None -> failwith "No config file. Is it a statically linked executable?" + ) | None -> raise (Eliom_common.Eliom_site_information_not_available - "Eliom_config.get_config") + "Eliom_config.get_config" + ) let parse_config ?pcdata ?other_elements elements = Ocsigen_extensions.Configuration.process_elements diff --git a/src/lib/eliom_config.server.mli b/src/lib/eliom_config.server.mli index c58712d495..47ab8f7280 100644 --- a/src/lib/eliom_config.server.mli +++ b/src/lib/eliom_config.server.mli @@ -53,25 +53,25 @@ val set_persistent_session_gc_frequency : int option -> unit [None] means never. *) val set_volatile_timeout : - ?scope_hierarchy:Eliom_common.scope_hierarchy + ?scope_hierarchy:Eliom_common.scope_hierarchy -> cookie_level:[< `Session | `Client_process] -> int option -> unit val set_data_timeout : - ?scope_hierarchy:Eliom_common.scope_hierarchy + ?scope_hierarchy:Eliom_common.scope_hierarchy -> cookie_level:[< `Session | `Client_process] -> int option -> unit val set_service_timeout : - ?scope_hierarchy:Eliom_common.scope_hierarchy + ?scope_hierarchy:Eliom_common.scope_hierarchy -> cookie_level:[< `Session | `Client_process] -> int option -> unit val set_persistent_timeout : - ?scope_hierarchy:Eliom_common.scope_hierarchy + ?scope_hierarchy:Eliom_common.scope_hierarchy -> cookie_level:[< `Session | `Client_process] -> int option -> unit @@ -109,8 +109,7 @@ val add_ignored_get_params : string * Re.re -> unit val add_ignored_post_params : string * Re.re -> unit val set_omitpersistentstorage : - Eliom_common.omitpersistentstorage_rule list option - -> unit + Eliom_common.omitpersistentstorage_rule list option -> unit val get_default_hostname : unit -> string (** The function [get_default_hostname ()]returns the hostname @@ -171,7 +170,7 @@ val get_config : unit -> Xml.xml list *) val parse_config : - ?pcdata:(string -> unit) + ?pcdata:(string -> unit) -> ?other_elements:(string -> (string * string) list -> Xml.xml list -> unit) -> Ocsigen_extensions.Configuration.element list -> unit @@ -195,7 +194,6 @@ val get_debugmode : unit -> bool (**/**) val get_config_info_sp : - Eliom_common.server_params - -> Ocsigen_extensions.config_info + Eliom_common.server_params -> Ocsigen_extensions.config_info val get_config_default_charset_sp : Eliom_common.server_params -> string diff --git a/src/lib/eliom_content.client.mli b/src/lib/eliom_content.client.mli index f06f51b624..8f39937c20 100644 --- a/src/lib/eliom_content.client.mli +++ b/src/lib/eliom_content.client.mli @@ -61,8 +61,8 @@ module Svg : sig module Raw' : Svg_sigs.Make(Xml).T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib (**/**) @@ -84,8 +84,8 @@ module Svg : sig module Raw' : Svg_sigs.Make(Xml).T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib (**/**) @@ -106,8 +106,8 @@ module Svg : sig module Raw : Svg_sigs.Make(Eliom_content_core.Xml_wed).T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib include module type of Raw end @@ -326,8 +326,8 @@ module Html : sig module Raw' : Html_sigs.Make(Xml)(Svg.F.Raw').T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib (**/**) @@ -340,11 +340,11 @@ module Html : sig include Eliom_content_sigs.LINKS_AND_FORMS - with type +'a elt := 'a elt - and type +'a attrib := 'a attrib - and type uri := uri - and type ('a, 'b, 'c) star := ('a, 'b, 'c) star - and type 'a form_param := 'a form_param + with type +'a elt := 'a elt + and type +'a attrib := 'a attrib + and type uri := uri + and type ('a, 'b, 'c) star := ('a, 'b, 'c) star + and type 'a form_param := 'a form_param end (** Creation of HTML5 content with {e D}OM semantics (referable) *) @@ -358,8 +358,8 @@ module Html : sig module Raw' : Html_sigs.Make(Xml)(Svg.D.Raw').T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib (**/**) @@ -372,11 +372,11 @@ module Html : sig include Eliom_content_sigs.LINKS_AND_FORMS - with type +'a elt := 'a elt - and type +'a attrib := 'a attrib - and type uri := uri - and type ('a, 'b, 'c) star := ('a, 'b, 'c) star - and type 'a form_param := 'a form_param + with type +'a elt := 'a elt + and type +'a attrib := 'a attrib + and type uri := uri + and type ('a, 'b, 'c) star := ('a, 'b, 'c) star + and type 'a form_param := 'a form_param end (** Creation of HTML5 content from @@ -404,8 +404,8 @@ module Html : sig (** Cf. {% <> %}. *) module Raw : Html_sigs.Make(Eliom_content_core.Xml_wed)(Svg.R.Raw).T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib include module type of Raw end @@ -461,7 +461,7 @@ module Html : sig (** Custom data with values of type ['a]. *) val create : - name:string + name:string -> ?default:'a -> to_string:('a -> string) -> of_string:(string -> 'a) @@ -563,7 +563,7 @@ module Html : sig (** [children elt] returns the list of html children of [elt]. *) val addEventListener : - ?capture:bool + ?capture:bool -> 'a elt -> (#Dom_html.event as 'b) Js.t Dom_html.Event.typ -> ('a elt -> 'b Js.t -> bool) @@ -601,7 +601,7 @@ module Html : sig (** see [replaceChildren] *) val addEventListener : - ?capture:bool + ?capture:bool -> 'a Id.id -> (#Dom_html.event as 'b) Js.t Dom_html.Event.typ -> ('a elt -> 'b Js.t -> bool) @@ -929,7 +929,7 @@ val force_link : unit (**/**) val set_client_fun : - ?app:string + ?app:string -> service:('a, 'b, _, _, _, _, _, _, _, _, _) Eliom_service.t -> ('a -> 'b -> Eliom_service.result Lwt.t) -> unit diff --git a/src/lib/eliom_content.server.mli b/src/lib/eliom_content.server.mli index 8e23399f95..ae4a107405 100644 --- a/src/lib/eliom_content.server.mli +++ b/src/lib/eliom_content.server.mli @@ -89,15 +89,16 @@ module Xml : sig include Xml_sigs.Iterable - with type 'a wrap = 'a - and type 'a list_wrap = 'a list - and type event_handler = (Dom_html.event Js.t -> unit) Eliom_client_value.t - and type mouse_event_handler = - (Dom_html.mouseEvent Js.t -> unit) Eliom_client_value.t - and type keyboard_event_handler = - (Dom_html.keyboardEvent Js.t -> unit) Eliom_client_value.t - and type touch_event_handler = - (Dom_html.touchEvent Js.t -> unit) Eliom_client_value.t + with type 'a wrap = 'a + and type 'a list_wrap = 'a list + and type event_handler = + (Dom_html.event Js.t -> unit) Eliom_client_value.t + and type mouse_event_handler = + (Dom_html.mouseEvent Js.t -> unit) Eliom_client_value.t + and type keyboard_event_handler = + (Dom_html.keyboardEvent Js.t -> unit) Eliom_client_value.t + and type touch_event_handler = + (Dom_html.touchEvent Js.t -> unit) Eliom_client_value.t (** {2 Unique nodes } *) @@ -131,8 +132,7 @@ module Xml : sig val make_client_attrib_table : elt -> Eliom_runtime.RawXML.client_attrib_table val caml_event_handler : - (Dom_html.event Js.t -> unit) Eliom_client_value.t - -> caml_event_handler + (Dom_html.event Js.t -> unit) Eliom_client_value.t -> caml_event_handler type racontent = | RA of acontent @@ -158,15 +158,15 @@ end module Xml_shared : Xml_sigs.T - with type 'a W.t = 'a Eliom_shared.React.S.t - and type 'a W.tlist = 'a Eliom_shared.ReactiveData.RList.t - and type event_handler = (Dom_html.event Js.t -> unit) Eliom_client_value.t - and type mouse_event_handler = - (Dom_html.mouseEvent Js.t -> unit) Eliom_client_value.t - and type keyboard_event_handler = - (Dom_html.keyboardEvent Js.t -> unit) Eliom_client_value.t - and type touch_event_handler = - (Dom_html.touchEvent Js.t -> unit) Eliom_client_value.t + with type 'a W.t = 'a Eliom_shared.React.S.t + and type 'a W.tlist = 'a Eliom_shared.ReactiveData.RList.t + and type event_handler = (Dom_html.event Js.t -> unit) Eliom_client_value.t + and type mouse_event_handler = + (Dom_html.mouseEvent Js.t -> unit) Eliom_client_value.t + and type keyboard_event_handler = + (Dom_html.keyboardEvent Js.t -> unit) Eliom_client_value.t + and type touch_event_handler = + (Dom_html.touchEvent Js.t -> unit) Eliom_client_value.t (** Building and pretty-printing valid SVG tree. Information about Svg api can be found at {% <> %}*) @@ -198,8 +198,8 @@ module Svg : sig module Raw' : Svg_sigs.Make(Xml).T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib (**/**) @@ -220,8 +220,8 @@ module Svg : sig module Raw' : Svg_sigs.Make(Xml).T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib (**/**) @@ -240,8 +240,8 @@ module Svg : sig module R : sig module Raw : Svg_sigs.Make(Xml_shared).T - with type 'a elt = 'a elt - and type 'a attrib = 'a attrib + with type 'a elt = 'a elt + and type 'a attrib = 'a attrib include module type of Raw @@ -343,8 +343,8 @@ module Html : sig module Raw' : Html_sigs.Make(Xml)(Svg.F.Raw').T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib (**/**) @@ -357,11 +357,11 @@ module Html : sig include Eliom_content_sigs.LINKS_AND_FORMS - with type +'a elt := 'a elt - and type +'a attrib := 'a attrib - and type uri := uri - and type ('a, 'b, 'c) star := ('a, 'b, 'c) star - and type 'a form_param := 'a form_param + with type +'a elt := 'a elt + and type +'a attrib := 'a attrib + and type uri := uri + and type ('a, 'b, 'c) star := ('a, 'b, 'c) star + and type 'a form_param := 'a form_param end (** Creation of HTML content with {b D}OM semantics (referable, see @@ -381,8 +381,8 @@ module Html : sig module Raw' : Html_sigs.Make(Xml)(Svg.D.Raw').T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib (**/**) @@ -395,11 +395,11 @@ module Html : sig include Eliom_content_sigs.LINKS_AND_FORMS - with type +'a elt := 'a elt - and type +'a attrib := 'a attrib - and type uri := uri - and type ('a, 'b, 'c) star := ('a, 'b, 'c) star - and type 'a form_param := 'a form_param + with type +'a elt := 'a elt + and type +'a attrib := 'a attrib + and type uri := uri + and type ('a, 'b, 'c) star := ('a, 'b, 'c) star + and type 'a form_param := 'a form_param end (** Creation of HTML content from client-side values. This makes @@ -465,8 +465,8 @@ module Html : sig module R : sig include Html_sigs.Make(Xml_shared)(Svg.R.Raw).T - with type 'a elt = 'a elt - and type 'a attrib = 'a attrib + with type 'a elt = 'a elt + and type 'a attrib = 'a attrib val pcdata : string Eliom_shared.React.S.t -> [> Html_types.span] elt (** [pcdata s] produces a node of type @@ -490,7 +490,7 @@ module Html : sig (** Custom data with values of type ['a]. *) val create : - name:string + name:string -> ?default:'a -> to_string:('a -> string) -> of_string:(string -> 'a) diff --git a/src/lib/eliom_content_.client.ml b/src/lib/eliom_content_.client.ml index 5b21d796b1..9bd0174bef 100644 --- a/src/lib/eliom_content_.client.ml +++ b/src/lib/eliom_content_.client.ml @@ -22,26 +22,21 @@ open Eliom_lib open Eliom_content_core module Xml = Xml -module MakeManip - (Kind : sig - type +'a elt - - val toelt : 'a elt -> Xml.elt - end) - (To_dom : sig - val of_element : 'a Kind.elt -> Dom_html.element Js.t - end) - (Of_dom : sig - val of_element : Dom_html.element Js.t -> 'a Kind.elt - end) - (Id : sig - type 'a id - - val get_element' : 'a id -> Dom.node Js.t - end) - (Ns : sig - val content_ns : Eliom_client_core.content_ns - end) = +module MakeManip (Kind : sig + type +'a elt + + val toelt : 'a elt -> Xml.elt +end) (To_dom : sig + val of_element : 'a Kind.elt -> Dom_html.element Js.t +end) (Of_dom : sig + val of_element : Dom_html.element Js.t -> 'a Kind.elt +end) (Id : sig + type 'a id + + val get_element' : 'a id -> Dom.node Js.t +end) (Ns : sig + val content_ns : Eliom_client_core.content_ns +end) = struct let get_node elt = (To_dom.of_element elt :> Dom.node Js.t) @@ -58,16 +53,18 @@ struct (Eliom_client_core.rebuild_node' Ns.content_ns (Kind.toelt elt)); raise_error ~section:eliom_logs_src "Cannot call %s on an element with functional semantics" context - | _ -> get_node elt) + | _ -> get_node elt + ) let get_unique_elt name elt : Dom_html.element Js.t = Js.Opt.case (Dom_html.CoerceTo.element (get_unique_node name elt)) (fun () -> - log_inspect - (Eliom_client_core.rebuild_node' Ns.content_ns (Kind.toelt elt)); - raise_error ~section:eliom_logs_src - "Cannot call %s on a node which is not an element" name) + log_inspect + (Eliom_client_core.rebuild_node' Ns.content_ns (Kind.toelt elt)); + raise_error ~section:eliom_logs_src + "Cannot call %s on a node which is not an element" name + ) id let raw_appendChild ?before node elt2 = @@ -85,7 +82,8 @@ struct let node3 = get_unique_node "appendChild" elt3 in List.iter (fun elt2 -> - ignore node##(insertBefore (get_node elt2) (Js.some node3))) + ignore node##(insertBefore (get_node elt2) (Js.some node3)) + ) elts let raw_removeChild node1 elt2 = @@ -110,8 +108,10 @@ struct Js.Opt.bind node##.childNodes##(item n) (fun node -> - Js.Opt.map (Dom.CoerceTo.element node) (fun node -> - Of_dom.of_element (Dom_html.element node))) + Js.Opt.map (Dom.CoerceTo.element node) (fun node -> + Of_dom.of_element (Dom_html.element node) + ) + ) in Js.Opt.to_option res @@ -136,7 +136,9 @@ struct let res = Js.Opt.bind node##.parentNode (fun node -> Js.Opt.map (Dom.CoerceTo.element node) (fun node -> - Of_dom.of_element (Dom_html.element node))) + Of_dom.of_element (Dom_html.element node) + ) + ) in Js.Opt.iter res (fun p -> removeChild p elt) @@ -175,14 +177,17 @@ struct let node = get_unique_node "children" elt in List.map Of_dom.of_element (filterElements Dom_html.CoerceTo.element - (Dom.list_of_nodeList node##.childNodes)) + (Dom.list_of_nodeList node##.childNodes) + ) let parentNode elt = let node = get_unique_node "parentNode" elt in let res = Js.Opt.bind node##.parentNode (fun node -> Js.Opt.map (Dom.CoerceTo.element node) (fun node -> - Of_dom.of_element (Dom_html.element node))) + Of_dom.of_element (Dom_html.element node) + ) + ) in Js.Opt.to_option res @@ -191,7 +196,9 @@ struct let res = Js.Opt.bind node##.nextSibling (fun node -> Js.Opt.map (Dom.CoerceTo.element node) (fun node -> - Of_dom.of_element (Dom_html.element node))) + Of_dom.of_element (Dom_html.element node) + ) + ) in Js.Opt.to_option res @@ -200,7 +207,9 @@ struct let res = Js.Opt.bind node##.previousSibling (fun node -> Js.Opt.map (Dom.CoerceTo.element node) (fun node -> - Of_dom.of_element (Dom_html.element node))) + Of_dom.of_element (Dom_html.element node) + ) + ) in Js.Opt.to_option res @@ -212,8 +221,9 @@ struct let insertAfter ~after elt = Eliom_lib.Option.iter (fun parent -> - let before = nextSibling after in - appendChild ?before parent elt) + let before = nextSibling after in + appendChild ?before parent elt + ) (parentNode after) let replaceSelf elt1 elt2 = @@ -377,7 +387,9 @@ module Html = struct Eliom_content_core.( Html.F.to_attrib (Xml.internal_event_handler_attrib s - (Xml.internal_event_handler_of_service info))) + (Xml.internal_event_handler_of_service info) + ) + ) let to_elt = toelt end @@ -403,7 +415,9 @@ module Html = struct Eliom_content_core.( Html.D.to_attrib (Xml.internal_event_handler_attrib s - (Xml.internal_event_handler_of_service info))) + (Xml.internal_event_handler_of_service info) + ) + ) let to_elt = toelt end @@ -426,10 +440,10 @@ module Html = struct module Of_dom = Eliom_content_core.Html.Of_dom module To_dom = Js_of_ocaml_tyxml.Tyxml_cast.MakeTo (struct - type 'a elt = 'a F.elt + type 'a elt = 'a F.elt - let elt x = Js.Unsafe.coerce (Eliom_client_core.rebuild_node "n/a" x) - end) + let elt x = Js.Unsafe.coerce (Eliom_client_core.rebuild_node "n/a" x) + end) module Id = struct include Html.Id @@ -461,7 +475,9 @@ module Html = struct let raw_addEventListener ?(capture = false) node event handler = Dom_html.addEventListener node event (Dom_html.full_handler (fun n e -> - Js.bool (handler (Html.F.tot (Xml.make_dom (n :> Dom.node Js.t))) e))) + Js.bool (handler (Html.F.tot (Xml.make_dom (n :> Dom.node Js.t))) e) + ) + ) (Js.bool capture) let addEventListener ?capture target event handler = @@ -484,7 +500,8 @@ module Html = struct Js.Opt.case (Js.Opt.bind (Dom_html.CoerceTo.element (get_unique_node name elt)) - Dom_html.CoerceTo.input) + Dom_html.CoerceTo.input + ) (fun () -> failwith (Printf.sprintf "Non element node (%s)" name)) id @@ -492,7 +509,8 @@ module Html = struct Js.Opt.case (Js.Opt.bind (Dom_html.CoerceTo.element (get_unique_node name elt)) - Dom_html.CoerceTo.select) + Dom_html.CoerceTo.select + ) (fun () -> failwith (Printf.sprintf "Non element node (%s)" name)) id @@ -500,7 +518,8 @@ module Html = struct Js.Opt.case (Js.Opt.bind (Dom_html.CoerceTo.element (get_unique_node name elt)) - Dom_html.CoerceTo.textarea) + Dom_html.CoerceTo.textarea + ) (fun () -> failwith (Printf.sprintf "Non element node (%s)" name)) id @@ -508,7 +527,8 @@ module Html = struct Js.Opt.case (Js.Opt.bind (Dom_html.CoerceTo.element (get_unique_node name elt)) - Dom_html.CoerceTo.img) + Dom_html.CoerceTo.img + ) (fun () -> failwith (Printf.sprintf "Non element node (%s)" name)) id @@ -572,23 +592,23 @@ module Html = struct let onfocus :> (_, Dom_html.event) ev = fun elt f -> - let elt = get_unique_elt_input "Ev.onfocus" elt in - elt##.onfocus := bool_cb f + let elt = get_unique_elt_input "Ev.onfocus" elt in + elt##.onfocus := bool_cb f let onblur :> (_, Dom_html.event) ev = fun elt f -> - let elt = get_unique_elt_input "Ev.onblur" elt in - elt##.onblur := bool_cb f + let elt = get_unique_elt_input "Ev.onblur" elt in + elt##.onblur := bool_cb f let onfocus_textarea :> (_, Dom_html.event) ev = fun elt f -> - let elt = get_unique_elt_textarea "Ev.onfocus" elt in - elt##.onfocus := bool_cb f + let elt = get_unique_elt_textarea "Ev.onfocus" elt in + elt##.onfocus := bool_cb f let onblur_textarea :> (_, Dom_html.event) ev = fun elt f -> - let elt = get_unique_elt_textarea "Ev.onblur" elt in - elt##.onblur := bool_cb f + let elt = get_unique_elt_textarea "Ev.onblur" elt in + elt##.onblur := bool_cb f let onscroll elt f = let elt = get_unique_elt "Ev.onscroll" elt in @@ -1178,8 +1198,7 @@ module Html = struct let elt = get_unique_elt "SetCss.borderLeftWidth" elt in elt##.style##.borderLeftWidth := Js.bytestring v - let borderLeftWidthPx elt v = - borderLeftWidth elt (Printf.sprintf "%dpx" v) + let borderLeftWidthPx elt v = borderLeftWidth elt (Printf.sprintf "%dpx" v) let borderRight elt v = let elt = get_unique_elt "SetCss.borderRight" elt in diff --git a/src/lib/eliom_content_.server.ml b/src/lib/eliom_content_.server.ml index 9aa8f24df1..79131c2f02 100644 --- a/src/lib/eliom_content_.server.ml +++ b/src/lib/eliom_content_.server.ml @@ -60,7 +60,9 @@ module Html = struct Eliom_content_core.( Html.F.to_attrib (Xml.internal_event_handler_attrib s - (Xml.internal_event_handler_of_service info))) + (Xml.internal_event_handler_of_service info) + ) + ) let to_elt = toelt end @@ -82,7 +84,9 @@ module Html = struct Eliom_content_core.( Html.D.to_attrib (Xml.internal_event_handler_attrib s - (Xml.internal_event_handler_of_service info))) + (Xml.internal_event_handler_of_service info) + ) + ) let to_elt = toelt end diff --git a/src/lib/eliom_content_core.client.ml b/src/lib/eliom_content_core.client.ml index 5a2bc216ec..0f33cfc700 100644 --- a/src/lib/eliom_content_core.client.ml +++ b/src/lib/eliom_content_core.client.ml @@ -51,7 +51,8 @@ module Xml = struct { (* See Eliom_content.Html.To_dom for the 'unwrap' function that convert the server's tree representation into the client one. *) mutable elt : node lazy_t - ; node_id : node_id } + ; node_id : node_id + } let content e = match Lazy.force e.elt with @@ -107,7 +108,8 @@ module Xml = struct let node_react_children ?(a = []) name children = { elt = Lazy.from_val (ReactChildren (Node (name, a, []), children)) - ; node_id = NoId } + ; node_id = NoId + } let end_re = Regexp.regexp_string "]]>" @@ -162,7 +164,8 @@ module Xml = struct | ReactChildren _ -> failwith "Eliom_content_core.set_classes_of_elt" | TyXMLNode econtent -> { elt with - elt = Lazy.from_val (TyXMLNode (set_classes elt.node_id econtent)) } + elt = Lazy.from_val (TyXMLNode (set_classes elt.node_id econtent)) + } let string_of_node_id = function | NoId -> "NoId" @@ -220,7 +223,8 @@ module Xml_wed = struct , Xml.RAReact (React.S.map (fun f -> Some (Xml.AStrL (Xml.Space, Eliom_lazy.force f))) - value) ) + value + ) ) type elt = Xml.elt type ename = Xml.ename @@ -239,12 +243,12 @@ end module Svg = struct module Ev' (A : sig - type 'a attrib + type 'a attrib - module Unsafe : sig - val string_attrib : string -> string -> 'a attrib - end - end) = + module Unsafe : sig + val string_attrib : string -> string -> 'a attrib + end + end) = struct let a_onabort s = A.Unsafe.string_attrib "onabort" s let a_onactivate s = A.Unsafe.string_attrib "onactivate" s @@ -273,17 +277,17 @@ module Svg = struct module D = struct module Raw' = Svg_f.Make (struct - include Xml - - let make elt = make_request_node (make elt) - let empty () = make Empty - let comment c = make (Comment c) - let pcdata d = make (PCDATA d) - let encodedpcdata d = make (EncodedPCDATA d) - let entity e = make (Entity e) - let leaf ?(a = []) name = make (Leaf (name, a)) - let node ?(a = []) name children = make (Node (name, a, children)) - end) + include Xml + + let make elt = make_request_node (make elt) + let empty () = make Empty + let comment c = make (Comment c) + let pcdata d = make (PCDATA d) + let encodedpcdata d = make (EncodedPCDATA d) + let entity e = make (Entity e) + let leaf ?(a = []) name = make (Leaf (name, a)) + let node ?(a = []) name children = make (Node (name, a, children)) + end) module Raw = struct include Raw' @@ -343,12 +347,12 @@ end module Html = struct module Ev' (A : sig - type 'a attrib + type 'a attrib - module Unsafe : sig - val string_attrib : string -> string -> 'a attrib - end - end) = + module Unsafe : sig + val string_attrib : string -> string -> 'a attrib + end + end) = struct let a_onabort s = A.Unsafe.string_attrib "onabort" s let a_onafterprint s = A.Unsafe.string_attrib "onafterprint" s @@ -458,7 +462,8 @@ module Html = struct let lazy_form ?(a = []) elts = tot (Xml'.lazy_node ~a:(to_xmlattribs a) "form" - (Eliom_lazy.from_fun (fun () -> toeltl (Eliom_lazy.force elts)))) + (Eliom_lazy.from_fun (fun () -> toeltl (Eliom_lazy.force elts))) + ) end module R = struct @@ -479,15 +484,19 @@ module Html = struct (React.S.map (function | true -> Some (Xml.AStr (Eliom_lazy.force s)) - | false -> None) - on) + | false -> None + ) + on + ) | Xml.RALazyStrL (sep, l) -> Xml.RAReact (React.S.map (function | true -> Some (Xml.AStrL (sep, List.map Eliom_lazy.force l)) - | false -> None) - on) + | false -> None + ) + on + ) | Xml.RACamlEventHandler _ -> failwith "R.filter_attrib not implemented for event handler" | Xml.RAClient _ -> assert false @@ -514,7 +523,8 @@ module Html = struct let lazy_form ?(a = []) elts = tot (Xml'.lazy_node ~a:(to_xmlattribs a) "form" - (Eliom_lazy.from_fun (fun () -> toeltl (Eliom_lazy.force elts)))) + (Eliom_lazy.from_fun (fun () -> toeltl (Eliom_lazy.force elts))) + ) end type +'a elt = 'a F.elt @@ -544,7 +554,8 @@ module Html = struct { name : string ; to_string : 'a -> string ; of_string : string -> 'a - ; default : 'a option } + ; default : 'a option + } let create ~name ?default ~to_string ~of_string () = {name; of_string; to_string; default} @@ -561,22 +572,24 @@ module Html = struct Js.Opt.case element##(getAttribute (Js.string (attribute_name custom_data.name))) (fun () -> - match custom_data.default with - | Some value -> value - | None -> raise Not_found) + match custom_data.default with + | Some value -> value + | None -> raise Not_found + ) (fun str -> custom_data.of_string (Js.to_string str)) let set_dom element custom_data value = element##(setAttribute (Js.string (attribute_name custom_data.name)) - (Js.string (custom_data.to_string value))) + (Js.string (custom_data.to_string value)) + ) end module Of_dom = Js_of_ocaml_tyxml.Tyxml_cast.MakeOf (struct - type 'a elt = 'a F.elt + type 'a elt = 'a F.elt - let elt (node : 'a Js.t) : 'a elt = Xml.make_dom (node :> Dom.node Js.t) - end) + let elt (node : 'a Js.t) : 'a elt = Xml.make_dom (node :> Dom.node Js.t) + end) let set_classes_of_elt elt = F.tot (Xml.set_classes_of_elt (F.toelt elt)) end diff --git a/src/lib/eliom_content_core.client.mli b/src/lib/eliom_content_core.client.mli index c8bd795a28..fe29b059de 100644 --- a/src/lib/eliom_content_core.client.mli +++ b/src/lib/eliom_content_core.client.mli @@ -25,9 +25,9 @@ open Js_of_ocaml module Xml : sig module W : Xml_wrap.T - with type 'a t = 'a - and type 'a tlist = 'a list - and type (-'a, 'b) ft = 'a -> 'b + with type 'a t = 'a + and type 'a tlist = 'a list + and type (-'a, 'b) ft = 'a -> 'b type uri = string @@ -49,13 +49,14 @@ module Xml : sig | CE_client_closure_touch of (Dom_html.touchEvent Js.t -> unit) (* Client side-only *) | CE_call_service of - ([`A | `Form_get | `Form_post] + ( [`A | `Form_get | `Form_post] * (bool * string list) option * string option - * Ocsigen_lib_base.poly) - (* (unit -> bool) client_value *) - option - Eliom_lazy.request + * Ocsigen_lib_base.poly + ) + (* (unit -> bool) client_value *) + option + Eliom_lazy.request type internal_event_handler = Raw of string | Caml of caml_event_handler type event_handler = Dom_html.event Js.t -> unit @@ -79,10 +80,11 @@ module Xml : sig (**/**) val internal_event_handler_of_service : - ([`A | `Form_get | `Form_post] - * (bool * string list) option - * string option - * Eliom_lib.poly) + ( [`A | `Form_get | `Form_post] + * (bool * string list) option + * string option + * Eliom_lib.poly + ) option Eliom_lazy.request -> internal_event_handler @@ -159,14 +161,14 @@ end module Xml_wed : sig include Xml_sigs.T - with module W = Js_of_ocaml_tyxml.Tyxml_js.Wrap - and type elt = Xml.elt - and type aname = Xml.aname - and type attrib = Xml.attrib - and type uri = Xml.uri - and type 'a W.t = 'a React.signal - and type 'a W.tlist = 'a ReactiveData.RList.t - and type ('a, 'b) W.ft = 'a -> 'b + with module W = Js_of_ocaml_tyxml.Tyxml_js.Wrap + and type elt = Xml.elt + and type aname = Xml.aname + and type attrib = Xml.attrib + and type uri = Xml.uri + and type 'a W.t = 'a React.signal + and type 'a W.tlist = 'a ReactiveData.RList.t + and type ('a, 'b) W.ft = 'a -> 'b val float_attrib : aname -> float React.S.t -> attrib val int_attrib : aname -> int React.S.t -> attrib @@ -194,12 +196,12 @@ module Svg : sig (**/**) module Ev' (A : sig - type 'a attrib + type 'a attrib - module Unsafe : sig - val string_attrib : string -> string -> 'a attrib - end - end) : sig + module Unsafe : sig + val string_attrib : string -> string -> 'a attrib + end + end) : sig val a_onabort : string -> [> `OnAbort] A.attrib val a_onactivate : string -> [> `OnActivate] A.attrib val a_onbegin : string -> [> `OnBegin] A.attrib @@ -240,8 +242,8 @@ module Svg : sig module Raw' : Svg_sigs.Make(Xml).T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib (**/**) @@ -263,8 +265,8 @@ module Svg : sig module Raw' : Svg_sigs.Make(Xml).T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib (**/**) @@ -288,8 +290,8 @@ module Svg : sig module Raw : Svg_sigs.Make(Xml_wed).T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib include module type of Raw (** See {% <> %}. *) @@ -339,12 +341,12 @@ module Html : sig (**/**) module Ev' (A : sig - type 'a attrib + type 'a attrib - module Unsafe : sig - val string_attrib : string -> string -> 'a attrib - end - end) : sig + module Unsafe : sig + val string_attrib : string -> string -> 'a attrib + end + end) : sig val a_onabort : string -> [> `OnAbort] A.attrib val a_onafterprint : string -> [> `OnAfterPrint] A.attrib val a_onbeforeprint : string -> [> `OnBeforePrint] A.attrib @@ -430,8 +432,8 @@ module Html : sig module Raw' : Html_sigs.Make(Xml)(Svg.F.Raw').T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib (**/**) @@ -452,9 +454,10 @@ module Html : sig val lazy_form : ( [< Html_types.form_attrib] - , [< Html_types.form_content_fun] - , [> Html_types.form] ) - lazy_star + , [< Html_types.form_content_fun] + , [> Html_types.form] + ) + lazy_star end (** Typed interface for building valid HTML5 tree (DOM semantics). See @@ -464,8 +467,8 @@ module Html : sig module Raw' : Html_sigs.Make(Xml)(Svg.D.Raw').T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib (**/**) @@ -483,9 +486,10 @@ module Html : sig val lazy_form : ( [< Html_types.form_attrib] - , [< Html_types.form_content_fun] - , [> Html_types.form] ) - lazy_star + , [< Html_types.form_content_fun] + , [> Html_types.form] + ) + lazy_star end (** Typed interface for building valid HTML5 tree from @@ -504,8 +508,8 @@ module Html : sig module Raw : Html_sigs.Make(Xml_wed)(Svg.R.Raw).T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib include module type of Raw end @@ -544,7 +548,7 @@ module Html : sig (** Custom data with values of type ['a]. *) val create : - name:string + name:string -> ?default:'a -> to_string:('a -> string) -> of_string:(string -> 'a) diff --git a/src/lib/eliom_content_core.server.ml b/src/lib/eliom_content_core.server.ml index cc8253fbf9..9c79dfcc79 100644 --- a/src/lib/eliom_content_core.server.ml +++ b/src/lib/eliom_content_core.server.ml @@ -47,7 +47,8 @@ module Xml = struct and elt' = { recontent : recontent ; node_id : node_id - ; unwrapper_mark : Eliom_wrap.unwrapper } + ; unwrapper_mark : Eliom_wrap.unwrapper + } [@@warning "-69"] and elt = {elt : elt'; wrapper_mark : elt Eliom_wrap.wrapper} @@ -58,10 +59,10 @@ module Xml = struct match elt.recontent with RE e -> e | RELazy e -> Eliom_lazy.force e module Node_id_set = Set.Make (struct - type t = node_id + type t = node_id - let compare : t -> t -> int = compare - end) + let compare : t -> t -> int = compare + end) let node_ids_in_content = ref Node_id_set.empty @@ -69,7 +70,8 @@ module Xml = struct Eliom_wrap.create_wrapper (fun {elt; _} -> if Node_id_set.mem elt.node_id !node_ids_in_content then {elt with recontent = RE Empty} - else elt) + else elt + ) let wrap page value = let node_ids = ref [] in @@ -94,15 +96,19 @@ module Xml = struct { elt = { recontent = RE elt ; node_id = NoId - ; unwrapper_mark = Eliom_wrap.create_unwrapper tyxml_unwrap_id } - ; wrapper_mark } + ; unwrapper_mark = Eliom_wrap.create_unwrapper tyxml_unwrap_id + } + ; wrapper_mark + } let make_lazy elt = { elt = { recontent = RELazy elt ; node_id = NoId - ; unwrapper_mark = Eliom_wrap.create_unwrapper tyxml_unwrap_id } - ; wrapper_mark } + ; unwrapper_mark = Eliom_wrap.create_unwrapper tyxml_unwrap_id + } + ; wrapper_mark + } let empty () = make Empty let comment c = make (Comment c) @@ -228,10 +234,11 @@ module Xml = struct let f acc attribs = List.fold_right (fun att acc -> - match racontent att with - | RACamlEventHandler (CE_registered_closure (closure_id, cv)) -> - ClosureMap.add closure_id cv acc - | _ -> acc) + match racontent att with + | RACamlEventHandler (CE_registered_closure (closure_id, cv)) -> + ClosureMap.add closure_id cv acc + | _ -> acc + ) attribs acc in fold_attrib f ClosureMap.empty elt @@ -240,9 +247,10 @@ module Xml = struct let f acc attribs = List.fold_right (fun att acc -> - match racontent att with - | RAClient (id, _, cv) -> ClosureMap.add id cv acc - | _ -> acc) + match racontent att with + | RAClient (id, _, cv) -> ClosureMap.add id cv acc + | _ -> acc + ) attribs acc in fold_attrib f ClosureMap.empty elt @@ -262,12 +270,12 @@ end module Svg = struct module Ev' (A : sig - type 'a attrib + type 'a attrib - module Unsafe : sig - val string_attrib : string -> string -> 'a attrib - end - end) = + module Unsafe : sig + val string_attrib : string -> string -> 'a attrib + end + end) = struct let a_onabort s = A.Unsafe.string_attrib "onabort" s let a_onactivate s = A.Unsafe.string_attrib "onactivate" s @@ -363,12 +371,12 @@ end module Html = struct module Ev' (A : sig - type 'a attrib + type 'a attrib - module Unsafe : sig - val string_attrib : string -> string -> 'a attrib - end - end) = + module Unsafe : sig + val string_attrib : string -> string -> 'a attrib + end + end) = struct let a_onabort s = A.Unsafe.string_attrib "onabort" s let a_onafterprint s = A.Unsafe.string_attrib "onafterprint" s @@ -464,7 +472,9 @@ module Html = struct let lazy_node ?(a = []) name children = make_lazy (Eliom_lazy.from_fun (fun () -> - Node (name, a, Eliom_lazy.force children))) + Node (name, a, Eliom_lazy.force children) + ) + ) end module Raw' = Html_f.Make (Xml') (Svg.F.Raw') @@ -485,7 +495,8 @@ module Html = struct let lazy_form ?(a = []) elts = tot (Xml'.lazy_node ~a:(to_xmlattribs a) "form" - (Eliom_lazy.from_fun (fun () -> toeltl (Eliom_lazy.force elts)))) + (Eliom_lazy.from_fun (fun () -> toeltl (Eliom_lazy.force elts))) + ) end module F = struct @@ -505,7 +516,8 @@ module Html = struct let lazy_form ?(a = []) elts = tot (Xml'.lazy_node ~a:(to_xmlattribs a) "form" - (Eliom_lazy.from_fun (fun () -> toeltl (Eliom_lazy.force elts)))) + (Eliom_lazy.from_fun (fun () -> toeltl (Eliom_lazy.force elts))) + ) end module Make @@ -542,7 +554,8 @@ module Html = struct { name : string ; to_string : 'a -> string ; of_string : string -> 'a - ; default : 'a option } + ; default : 'a option + } [@@warning "-69"] let create ~name ?default ~to_string ~of_string () = diff --git a/src/lib/eliom_content_core.server.mli b/src/lib/eliom_content_core.server.mli index 1d6be3aec0..73ff57f7b0 100644 --- a/src/lib/eliom_content_core.server.mli +++ b/src/lib/eliom_content_core.server.mli @@ -24,15 +24,16 @@ open Js_of_ocaml module Xml : sig include Xml_sigs.Iterable - with type 'a wrap = 'a - and type 'a list_wrap = 'a list - and type event_handler = (Dom_html.event Js.t -> unit) Eliom_client_value.t - and type mouse_event_handler = - (Dom_html.mouseEvent Js.t -> unit) Eliom_client_value.t - and type keyboard_event_handler = - (Dom_html.keyboardEvent Js.t -> unit) Eliom_client_value.t - and type touch_event_handler = - (Dom_html.touchEvent Js.t -> unit) Eliom_client_value.t + with type 'a wrap = 'a + and type 'a list_wrap = 'a list + and type event_handler = + (Dom_html.event Js.t -> unit) Eliom_client_value.t + and type mouse_event_handler = + (Dom_html.mouseEvent Js.t -> unit) Eliom_client_value.t + and type keyboard_event_handler = + (Dom_html.keyboardEvent Js.t -> unit) Eliom_client_value.t + and type touch_event_handler = + (Dom_html.touchEvent Js.t -> unit) Eliom_client_value.t type caml_event_handler @@ -54,17 +55,17 @@ module Xml : sig val internal_event_handler_attrib : aname -> internal_event_handler -> attrib val internal_event_handler_of_service : - ([`A | `Form_get | `Form_post] - * (bool * string list) option - * string option - * Eliom_lib.poly) + ( [`A | `Form_get | `Form_post] + * (bool * string list) option + * string option + * Eliom_lib.poly + ) option Eliom_lazy.request -> internal_event_handler val caml_event_handler : - (Dom_html.event Js.t -> unit) Eliom_client_value.t - -> caml_event_handler + (Dom_html.event Js.t -> unit) Eliom_client_value.t -> caml_event_handler type racontent = | RA of acontent @@ -94,12 +95,12 @@ module Svg : sig (**/**) module Ev' (A : sig - type 'a attrib + type 'a attrib - module Unsafe : sig - val string_attrib : string -> string -> 'a attrib - end - end) : sig + module Unsafe : sig + val string_attrib : string -> string -> 'a attrib + end + end) : sig val a_onabort : string -> [> `OnAbort] A.attrib val a_onactivate : string -> [> `OnActivate] A.attrib val a_onbegin : string -> [> `OnBegin] A.attrib @@ -136,8 +137,8 @@ module Svg : sig module Raw' : Svg_sigs.Make(Xml).T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib (**/**) @@ -154,8 +155,8 @@ module Svg : sig module Raw' : Svg_sigs.Make(Xml).T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib (**/**) @@ -167,17 +168,15 @@ module Svg : sig include module type of Raw' val client_attrib : - ?init:'a attrib - -> 'a attrib Eliom_client_value.t - -> 'a attrib + ?init:'a attrib -> 'a attrib Eliom_client_value.t -> 'a attrib end module Make (Xml : Xml_sigs.T with type elt = Xml.elt and type attrib = Xml.attrib) (_ : Svg_sigs.Wrapped_functions with module Xml = Xml) : Svg_sigs.Make(Xml).T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib module Id : sig type +'a id @@ -207,12 +206,12 @@ module Html : sig (**/**) module Ev' (A : sig - type 'a attrib + type 'a attrib - module Unsafe : sig - val string_attrib : string -> string -> 'a attrib - end - end) : sig + module Unsafe : sig + val string_attrib : string -> string -> 'a attrib + end + end) : sig val a_onabort : string -> [> `OnAbort] A.attrib val a_onafterprint : string -> [> `OnAfterPrint] A.attrib val a_onbeforeprint : string -> [> `OnBeforePrint] A.attrib @@ -296,8 +295,8 @@ module Html : sig module Raw' : Html_sigs.Make(Xml)(Svg.F.Raw').T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib (**/**) @@ -315,9 +314,10 @@ module Html : sig val lazy_form : ( [< Html_types.form_attrib] - , [< Html_types.form_content_fun] - , [> Html_types.form] ) - lazy_star + , [< Html_types.form_content_fun] + , [> Html_types.form] + ) + lazy_star end module D : sig @@ -325,8 +325,8 @@ module Html : sig module Raw' : Html_sigs.Make(Xml)(Svg.F.Raw').T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib (**/**) @@ -338,9 +338,7 @@ module Html : sig include module type of Raw' val client_attrib : - ?init:'a attrib - -> 'a attrib Eliom_client_value.t - -> 'a attrib + ?init:'a attrib -> 'a attrib Eliom_client_value.t -> 'a attrib (**/**) @@ -349,9 +347,10 @@ module Html : sig val lazy_form : ( [< Html_types.form_attrib] - , [< Html_types.form_content_fun] - , [> Html_types.form] ) - lazy_star + , [< Html_types.form_content_fun] + , [> Html_types.form] + ) + lazy_star end module Make @@ -359,8 +358,8 @@ module Html : sig (_ : Html_sigs.Wrapped_functions with module Xml = Xml) (Svg : Svg_sigs.T with module Xml := Xml) : Html_sigs.Make(Xml)(Svg).T - with type +'a elt = 'a elt - and type +'a attrib = 'a attrib + with type +'a elt = 'a elt + and type +'a attrib = 'a attrib module Id : sig type +'a id @@ -379,7 +378,7 @@ module Html : sig type 'a t val create : - name:string + name:string -> ?default:'a -> to_string:('a -> string) -> of_string:(string -> 'a) diff --git a/src/lib/eliom_content_sigs.shared.mli b/src/lib/eliom_content_sigs.shared.mli index 5b5e8c4336..1688990c1e 100644 --- a/src/lib/eliom_content_sigs.shared.mli +++ b/src/lib/eliom_content_sigs.shared.mli @@ -29,20 +29,21 @@ module type LINKS_AND_FORMS = sig val lazy_form : ( [< Html_types.form_attrib] - , [< Html_types.form_content_fun] - , [> Html_types.form] ) - lazy_star + , [< Html_types.form_content_fun] + , [> Html_types.form] + ) + lazy_star include Eliom_form_sigs.LINKS - with type +'a elt := 'a elt - and type +'a attrib := 'a attrib - and type uri := uri + with type +'a elt := 'a elt + and type +'a attrib := 'a attrib + and type uri := uri module Form : Eliom_form_sigs.S - with type +'a elt := 'a elt - and type +'a attrib := 'a attrib - and type uri := uri - and type 'a param = 'a form_param + with type +'a elt := 'a elt + and type +'a attrib := 'a attrib + and type uri := uri + and type 'a param = 'a form_param end diff --git a/src/lib/eliom_cookies_base.shared.ml b/src/lib/eliom_cookies_base.shared.ml index 823eaf1299..dba25e9541 100644 --- a/src/lib/eliom_cookies_base.shared.ml +++ b/src/lib/eliom_cookies_base.shared.ml @@ -26,11 +26,13 @@ let cookieset_of_json json = let cookietable_array array = Array.fold_left (fun set (name, cookie) -> - Ocsigen_cookie_map.Map_inner.add name cookie set) + Ocsigen_cookie_map.Map_inner.add name cookie set + ) Ocsigen_cookie_map.Map_inner.empty array in Array.fold_left (fun set (path, cookietable) -> - let path = Array.to_list path in - Ocsigen_cookie_map.Map_path.add path (cookietable_array cookietable) set) + let path = Array.to_list path in + Ocsigen_cookie_map.Map_path.add path (cookietable_array cookietable) set + ) Ocsigen_cookie_map.empty array diff --git a/src/lib/eliom_error_pages.server.ml b/src/lib/eliom_error_pages.server.ml index 02d82860eb..5aa1cd69c1 100644 --- a/src/lib/eliom_error_pages.server.ml +++ b/src/lib/eliom_error_pages.server.ml @@ -41,43 +41,54 @@ let page_bad_param after_action gl pl = (body (h1 [txt s] :: - (if Ocsigen_config.get_debugmode () - then - [ h2 [txt "Debugging information:"] - ; (if after_action - then - p - [ txt - "An action occurred successfully. But Eliom was unable to find the service for displaying the page." - ] - else - p - [ txt - "Eliom was unable to find a service matching these parameters." - ]) - ; (match gl with - | [] -> p [txt "No GET parameters have been given to services."] - | (n, a) :: l -> - p - [ txt "GET parameters given to services: " - ; em - (txt n :: txt "=" :: txt a - :: List.fold_right - (fun (n, a) b -> - txt "&" :: txt n :: txt "=" :: txt a :: b) - l - [txt "."]) ]) - ; (match pl with - | [] -> p [txt "No POST parameters have been given to services."] - | a :: l -> - p - (txt "Names of POST parameters given to services: " - :: em [txt a] - :: List.fold_right - (fun n b -> txt ", " :: em [txt n] :: b) - l - [txt "."])) ] - else []))) + ( if Ocsigen_config.get_debugmode () + then + [ h2 [txt "Debugging information:"] + ; ( if after_action + then + p + [ txt + "An action occurred successfully. But Eliom was unable to find the service for displaying the page." + ] + else + p + [ txt + "Eliom was unable to find a service matching these parameters." + ] + ) + ; ( match gl with + | [] -> p [txt "No GET parameters have been given to services."] + | (n, a) :: l -> + p + [ txt "GET parameters given to services: " + ; em + (txt n :: txt "=" :: txt a + :: List.fold_right + (fun (n, a) b -> + txt "&" :: txt n :: txt "=" :: txt a :: b + ) + l + [txt "."] + ) + ] + ) + ; ( match pl with + | [] -> p [txt "No POST parameters have been given to services."] + | a :: l -> + p + (txt "Names of POST parameters given to services: " + :: em [txt a] + :: List.fold_right + (fun n b -> txt ", " :: em [txt n] :: b) + l + [txt "."] + ) + ) + ] + else [] + ) + ) + ) let page_session_expired = let s = "Session expired" in diff --git a/src/lib/eliom_extension.server.mli b/src/lib/eliom_extension.server.mli index 879345536c..6dffffb9de 100644 --- a/src/lib/eliom_extension.server.mli +++ b/src/lib/eliom_extension.server.mli @@ -31,7 +31,7 @@ val register_eliom_extension : eliom_extension_sig -> unit val get_eliom_extension : unit -> eliom_extension_sig val run_eliom_extension : - eliom_extension_sig + eliom_extension_sig -> float -> Eliom_common.info -> Eliom_common.sitedata diff --git a/src/lib/eliom_form_sigs.shared.mli b/src/lib/eliom_form_sigs.shared.mli index 0b6d1dc2fe..2161ee058f 100644 --- a/src/lib/eliom_form_sigs.shared.mli +++ b/src/lib/eliom_form_sigs.shared.mli @@ -25,22 +25,23 @@ module type LINKS = sig type uri val make_uri : - ?absolute:bool + ?absolute:bool -> ?absolute_path:bool -> ?https:bool -> service: ( 'get - , unit - , Eliom_service.get - , _ - , _ - , _ - , _ - , _ - , _ - , unit - , _ ) - Eliom_service.t + , unit + , Eliom_service.get + , _ + , _ + , _ + , _ + , _ + , _ + , unit + , _ + ) + Eliom_service.t -> ?hostname:string -> ?port:int -> ?fragment:string @@ -133,7 +134,7 @@ module type LINKS = sig For other module, the function [f] is immediately applied. *) val css_link : - ?a:[< Html_types.link_attrib] attrib list + ?a:[< Html_types.link_attrib] attrib list -> uri:uri -> unit -> [> Html_types.link] elt @@ -149,7 +150,7 @@ module type LINKS = sig attributes to the generated node. *) val js_script : - ?a:[< Html_types.script_attrib] attrib list + ?a:[< Html_types.script_attrib] attrib list -> uri:uri -> unit -> [> Html_types.script] elt @@ -165,23 +166,24 @@ module type LINKS = sig attributes to the generated node. *) val a : - ?absolute:bool + ?absolute:bool -> ?absolute_path:bool -> ?https:bool -> ?a:[< Html_types.a_attrib] attrib list -> service: ( 'get - , unit - , Eliom_service.get - , _ - , _ - , _ - , _ - , _ - , _ - , unit - , Eliom_service.non_ocaml ) - Eliom_service.t + , unit + , Eliom_service.get + , _ + , _ + , _ + , _ + , _ + , _ + , unit + , Eliom_service.non_ocaml + ) + Eliom_service.t -> ?hostname:string -> ?port:int -> ?fragment:string @@ -243,22 +245,23 @@ module type S = sig val user : ('a -> string) -> 'a param val make_post_uri_components : - ?absolute:bool + ?absolute:bool -> ?absolute_path:bool -> ?https:bool -> service: ( 'get - , 'post - , Eliom_service.post - , _ - , _ - , _ - , _ - , _ - , _ - , _ - , _ ) - Eliom_service.t + , 'post + , Eliom_service.post + , _ + , _ + , _ + , _ + , _ + , _ + , _ + , _ + ) + Eliom_service.t -> ?hostname:string -> ?port:int -> ?fragment:string @@ -275,23 +278,24 @@ module type S = sig post parameters. *) val get_form : - ?absolute:bool + ?absolute:bool -> ?absolute_path:bool -> ?https:bool -> ?a:[< Html_types.form_attrib] attrib list -> service: ( _ - , unit - , Eliom_service.get - , _ - , _ - , _ - , _ - , _ - , 'gn - , _ - , Eliom_service.non_ocaml ) - Eliom_service.t + , unit + , Eliom_service.get + , _ + , _ + , _ + , _ + , _ + , 'gn + , _ + , Eliom_service.non_ocaml + ) + Eliom_service.t -> ?hostname:string -> ?port:int -> ?fragment:string @@ -327,23 +331,24 @@ module type S = sig parameters. *) val lwt_get_form : - ?absolute:bool + ?absolute:bool -> ?absolute_path:bool -> ?https:bool -> ?a:[< Html_types.form_attrib] attrib list -> service: ( _ - , unit - , Eliom_service.get - , _ - , _ - , _ - , _ - , _ - , 'gn - , _ - , Eliom_service.non_ocaml ) - Eliom_service.t + , unit + , Eliom_service.get + , _ + , _ + , _ + , _ + , _ + , 'gn + , _ + , Eliom_service.non_ocaml + ) + Eliom_service.t -> ?hostname:string -> ?port:int -> ?fragment:string @@ -356,23 +361,24 @@ module type S = sig [] content generation. *) val post_form : - ?absolute:bool + ?absolute:bool -> ?absolute_path:bool -> ?https:bool -> ?a:[< Html_types.form_attrib] attrib list -> service: ( 'get - , _ - , Eliom_service.post - , _ - , _ - , _ - , _ - , _ - , _ - , 'pn - , Eliom_service.non_ocaml ) - Eliom_service.t + , _ + , Eliom_service.post + , _ + , _ + , _ + , _ + , _ + , _ + , 'pn + , Eliom_service.non_ocaml + ) + Eliom_service.t -> ?hostname:string -> ?port:int -> ?fragment:string @@ -398,23 +404,24 @@ module type S = sig [~xhr] and see {!make_uri} for other optional parameters. *) val lwt_post_form : - ?absolute:bool + ?absolute:bool -> ?absolute_path:bool -> ?https:bool -> ?a:[< Html_types.form_attrib] attrib list -> service: ( 'get - , _ - , Eliom_service.post - , _ - , _ - , _ - , _ - , _ - , _ - , 'pn - , Eliom_service.non_ocaml ) - Eliom_service.t + , _ + , Eliom_service.post + , _ + , _ + , _ + , _ + , _ + , _ + , 'pn + , Eliom_service.non_ocaml + ) + Eliom_service.t -> ?hostname:string -> ?port:int -> ?fragment:string @@ -429,7 +436,7 @@ module type S = sig [] content generation. *) val input : - ?a:[< Html_types.input_attrib] attrib list + ?a:[< Html_types.input_attrib] attrib list -> input_type:[< Html_types.input_type] -> ?name:[< 'a setoneradio] param_name -> ?value:'a @@ -438,14 +445,14 @@ module type S = sig (** Creates an [] tag. *) val file_input : - ?a:[< Html_types.input_attrib] attrib list + ?a:[< Html_types.input_attrib] attrib list -> name:[< file_info setoneradio] param_name -> unit -> [> Html_types.input] elt (** Creates an [] tag for sending a file *) val image_input : - ?a:[< Html_types.input_attrib] attrib list + ?a:[< Html_types.input_attrib] attrib list -> name:[< coordinates oneradio] param_name -> ?src:uri -> unit @@ -454,7 +461,7 @@ module type S = sig receives the coordinates that the user clicked on. *) val checkbox : - ?a:[< Html_types.input_attrib] attrib list + ?a:[< Html_types.input_attrib] attrib list -> ?checked:bool -> name:[`Set of 'a] Eliom_parameter.param_name -> value:'a @@ -465,7 +472,7 @@ module type S = sig service must declare a parameter of type [set]. *) val bool_checkbox_one : - ?a:[< Html_types.input_attrib] attrib list + ?a:[< Html_types.input_attrib] attrib list -> ?checked:bool -> name:[`One of bool] Eliom_parameter.param_name -> unit @@ -474,7 +481,7 @@ module type S = sig with the same [name] is allowed. *) val radio : - ?a:[< Html_types.input_attrib] attrib list + ?a:[< Html_types.input_attrib] attrib list -> ?checked:bool -> name:[`Radio of 'a] param_name -> value:'a @@ -483,7 +490,7 @@ module type S = sig (** Creates a radio [] tag. *) val string_radio_required : - ?a:[< Html_types.input_attrib] attrib list + ?a:[< Html_types.input_attrib] attrib list -> ?checked:bool -> name:[`One of string] param_name -> value:string @@ -491,7 +498,7 @@ module type S = sig -> [> Html_types.input] elt val button : - ?a:[< Html_types.button_attrib] attrib list + ?a:[< Html_types.button_attrib] attrib list -> button_type:[< button_type] -> name:[< 'a setone] param_name -> value:'a @@ -501,14 +508,14 @@ module type S = sig (** Creates a [