Skip to content

Commit

Permalink
Merge pull request #745 from ilankri/server-state-discard-state
Browse files Browse the repository at this point in the history
[server-state] Make `Eliom_state.Ext.discard_state` more robust
  • Loading branch information
balat authored Mar 10, 2022
2 parents c3e0eea + 2644eb8 commit 81e24ad
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 33 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
===== 10.0 (2022-03-08) =====
* Make Eliom_state.Ext.discard_state more robust

===== 9.0 (2021-10-16) =====
* compatibility with ocsigenserver.5.0.0 (outsourced Ocsipersist)

Expand Down
2 changes: 1 addition & 1 deletion opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
opam-version: "2.0"
name: "eliom"
version: "9.4.0"
version: "10.0.0"
maintainer: "[email protected]"
authors: "[email protected]"
synopsis: "Client/server Web framework"
Expand Down
58 changes: 31 additions & 27 deletions src/lib/eliom_state.server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1202,33 +1202,35 @@ module Ext = struct
, Eliom_common.(Hashed_cookies.to_string cookie.sc_hvalue) )

let get_service_cookie_info
?(sitedata =
Eliom_request_info.find_sitedata "Eliom_state.get_service_cookie_info")
((_, _, cookie) : ([< Eliom_common.cookie_level], [`Service]) state)
=
( cookie
, Eliom_common.SessionCookies.find
(Eliom_request_info.find_sitedata "Eliom_state.xxx")
.Eliom_common.session_services cookie )
, Eliom_common.SessionCookies.find sitedata.Eliom_common.session_services
cookie )

let get_volatile_data_cookie_info
?(sitedata =
Eliom_request_info.find_sitedata
"Eliom_state.get_volatile_data_cookie_info")
((_, _, cookie) : ([< Eliom_common.cookie_level], [`Data]) state)
=
( cookie
, Eliom_common.SessionCookies.find
(Eliom_request_info.find_sitedata "Eliom_state.xxx")
.Eliom_common.session_data cookie )
, Eliom_common.SessionCookies.find sitedata.Eliom_common.session_data cookie
)

let get_persistent_cookie_info
((_, _, cookie) : ([< Eliom_common.cookie_level], [`Pers]) state)
=
Eliommod_cookies.Persistent_cookies.Cookies.find cookie >>= fun v ->
Lwt.return (cookie, v)

let discard_state ~state =
let get_sitedata () =
Eliom_request_info.find_sitedata "Eliom_state.discard_state"
in
let discard_state
?(sitedata = Eliom_request_info.find_sitedata "Eliom_state.discard_state")
~state ()
=
let make_sessgrp n =
let sitedata = get_sitedata () in
sitedata.Eliom_common.site_dir_string, `Session, Left n
in
match state with
Expand All @@ -1249,34 +1251,36 @@ module Ext = struct
| None -> ());
Lwt.return_unit
| `Session_group _, `Pers, group_name ->
let sitedata = get_sitedata () in
let sgr_o =
Eliom_common.make_persistent_full_group_name ~cookie_level:`Session
sitedata.Eliom_common.site_dir_string (Some group_name)
in
Eliommod_sessiongroups.Pers.remove_group ~cookie_level:`Session sitedata
sgr_o
| _, `Service, (_cookie : string) ->
let _, {Eliom_common.Service_cookie.session_group_node} =
get_service_cookie_info state
let () =
match get_service_cookie_info ~sitedata state with
| exception Not_found -> ()
| _, {Eliom_common.Service_cookie.session_group_node} ->
Eliommod_sessiongroups.Serv.remove session_group_node
in
Eliommod_sessiongroups.Serv.remove session_group_node;
Lwt.return_unit
| _, `Data, _cookie ->
let _, {Eliom_common.Data_cookie.session_group_node} =
get_volatile_data_cookie_info state
let () =
match get_volatile_data_cookie_info ~sitedata state with
| exception Not_found -> ()
| _, {Eliom_common.Data_cookie.session_group_node} ->
Eliommod_sessiongroups.Data.remove session_group_node
in
Eliommod_sessiongroups.Data.remove session_group_node;
Lwt.return_unit
| _, `Pers, _cookie ->
let%lwt cookie, {Eliommod_cookies.full_state_name; session_group} =
get_persistent_cookie_info state
in
let scope = full_state_name.Eliom_common.user_scope in
let sitedata = get_sitedata () in
let cookie_level = Eliom_common.cookie_level_of_user_scope scope in
Eliommod_sessiongroups.Pers.close_persistent_session2 ~cookie_level
sitedata session_group cookie
| _, `Pers, _cookie -> (
match%lwt get_persistent_cookie_info state with
| exception Not_found -> Lwt.return_unit
| cookie, {Eliommod_cookies.full_state_name; session_group} ->
let scope = full_state_name.Eliom_common.user_scope in
let cookie_level = Eliom_common.cookie_level_of_user_scope scope in
Eliommod_sessiongroups.Pers.close_persistent_session2 ~cookie_level
sitedata session_group cookie)
(*VVV!!! est-ce que session_group est fullsessgrp ? *)

let fold_sub_states_aux_aux
Expand Down
25 changes: 20 additions & 5 deletions src/lib/eliom_state.server.mli
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,15 @@ module Ext : sig
-> ([< Eliom_common.user_level], [< `Service]) state
(** Same for services *)

val discard_state : state:('a, 'b) state -> unit Lwt.t
(** Discard external states *)
val discard_state
: ?sitedata:Eliom_common.sitedata
-> state:('a, 'b) state
-> unit
-> unit Lwt.t
(** Discard external states.
See {!fold_volatile_sub_states} for explanation about the [?sitedata]
parameter.
*)

val fold_volatile_sub_states
: ?sitedata:Eliom_common.sitedata
Expand Down Expand Up @@ -901,13 +908,21 @@ module Ext : sig
end

val get_service_cookie_info
: ([< Eliom_common.cookie_level], [`Service]) state
: ?sitedata:Eliom_common.sitedata
-> ([< Eliom_common.cookie_level], [`Service]) state
-> service_cookie_info
(** Get the infomration about cookies (timeouts, etc.) *)
(** Get the infomration about cookies (timeouts, etc.).
See {!fold_volatile_sub_states} for explanation about the [?sitedata]
parameter.
*)

val get_volatile_data_cookie_info
: ([< Eliom_common.cookie_level], [`Data]) state
: ?sitedata:Eliom_common.sitedata
-> ([< Eliom_common.cookie_level], [`Data]) state
-> data_cookie_info
(** See {!fold_volatile_sub_states} for explanation about the [?sitedata]
parameter.
*)

val get_persistent_cookie_info
: ([< Eliom_common.cookie_level], [`Pers]) state
Expand Down

0 comments on commit 81e24ad

Please sign in to comment.