123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240(* Ocsigen
* http://www.ocsigen.org
* Module eliommod_sessadmin.ml
* Copyright (C) 2007 Vincent Balat
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, with linking exception;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)(*****************************************************************************)(*****************************************************************************)(** Internal functions used by Eliom: *)(** Administration of sessions *)(*****************************************************************************)(*****************************************************************************)openLwtletsection=Lwt_log.Section.make"eliom:admin"(*
(** Iterator on volatile sessions *)
let iter_sessions f =
(** Iterator on persistent sessions *)
let iter_persistent_sessions f =
*)letclose_all_service_states2full_st_namesitedata=Eliom_common.SessionCookies.fold(fun_{Eliom_common.Service_cookie.full_state_name;timeout;session_group_node;_}thr->let%lwt()=thriniffull_st_name=full_state_name&&!timeout=Eliom_common.TGlobalthenEliommod_sessiongroups.Serv.removesession_group_node;Lwt.pause())sitedata.Eliom_common.session_servicesreturn_unit(** Close all service states for one session name.
If the optional parameter [?state_name] (session name) is not present,
only the state with default name is closed.
*)letclose_all_service_states~scope~securesitedata=letfull_st_name=Eliom_common.make_full_state_name2(Eliom_common.get_site_dir_stringsitedata)secure~scopeinclose_all_service_states2full_st_namesitedata(*VVV Missing:
- close all sessions, whatever be the state_name
- secure
- close all groups (but closing sessions will close the groups (?))
*)letclose_all_data_states2full_st_namesitedata=Eliom_common.SessionCookies.fold(fun_{Eliom_common.Data_cookie.full_state_name;timeout;session_group_node;_}thr->thr>>=fun()->iffull_st_name=full_state_name&&!timeout=Eliom_common.TGlobalthenEliommod_sessiongroups.Data.removesession_group_node;Lwt.pause())sitedata.Eliom_common.session_datareturn_unit(** Close all in memory data sessions for one session name.
If the optional parameter [?state_name] (session name) is not present,
only the session with default name is closed.
*)letclose_all_data_states~scope~securesitedata=letfull_st_name=Eliom_common.make_full_state_name2(Eliom_common.get_site_dir_stringsitedata)secure~scopeinclose_all_data_states2full_st_namesitedata(*VVV Missing:
- close all sessions, whatever be the state_name
- secure
- close all groups (but closing sessions will close the groups (?))
*)letclose_all_persistent_states2full_st_namesitedata=Eliommod_cookies.Persistent_cookies.Cookies.iter(funk{Eliommod_cookies.full_state_name;timeout=old_t;session_group;_}->letscope=full_state_name.Eliom_common.user_scopeiniffull_st_name=full_state_name&&old_t=Eliom_common.TGlobalthenEliommod_persess.close_persistent_state2~scopesitedatasession_groupk>>=Lwt.pauseelsereturn_unit)(** Close all persistent sessions for one session name.
If the optional parameter [?state_name] (session name) is not present,
only the session with default name is closed.
*)letclose_all_persistent_states~scope~securesitedata=letfull_st_name=Eliom_common.make_full_state_name2(Eliom_common.get_site_dir_stringsitedata)secure~scopeinclose_all_persistent_states2full_st_namesitedata(*VVV Missing:
- close all sessions, whatever be the state_name
- secure
- close all groups (but closing sessions will close the groups (?))
*)(* Update the expiration date for all service sessions *)letupdate_serv_expfull_st_namesitedataold_glob_timeoutnew_glob_timeout=Lwt_log.ign_notice~section"Updating expiration date for all service sessions";matchnew_glob_timeoutwith|Sometwhent<=0.->(* We close all sessions but those with user defined timeout *)close_all_service_states2full_st_namesitedata|_->letnow=Unix.time()inEliom_common.SessionCookies.fold(fun_{Eliom_common.Service_cookie.full_state_name;expiry;timeout;session_group_node;_}thr->let%lwt()=thrin(iffull_st_name=full_state_name&&!timeout=Eliom_common.TGlobalthenletnewexp=match!expiry,old_glob_timeout,new_glob_timeoutwith|_,_,None->None|None,_,Somet|Some_,None,Somet->Some(now+.t)|Someoldexp,Someoldt,Somet->Some(oldexp-.oldt+.t)inmatchnewexpwith|Sometwhent<=now->Eliommod_sessiongroups.Serv.removesession_group_node|_->expiry:=newexp);Lwt.pause())sitedata.Eliom_common.session_servicesreturn_unit(* Update the expiration date for all in memory data sessions *)letupdate_data_expfull_st_namesitedataold_glob_timeoutnew_glob_timeout=Lwt_log.ign_notice~section"Updating expiration date for all data sessions";matchnew_glob_timeoutwith|Sometwhent<=0.->(* We close all sessions but those with user defined timeout *)close_all_data_states2full_st_namesitedata|_->letnow=Unix.time()inEliom_common.SessionCookies.fold(fun_{Eliom_common.Data_cookie.full_state_name;expiry;timeout;session_group_node;_}thr->thr>>=fun()->(iffull_st_name=full_state_name&&!timeout=Eliom_common.TGlobalthenletnewexp=match!expiry,old_glob_timeout,new_glob_timeoutwith|_,_,None->None|None,_,Somet|Some_,None,Somet->Some(now+.t)|Someoldexp,Someoldt,Somet->Some(oldexp-.oldt+.t)inmatchnewexpwith|Sometwhent<=now->Eliommod_sessiongroups.Data.removesession_group_node|_->expiry:=newexp);Lwt.pause())sitedata.Eliom_common.session_datareturn_unit(* Update the expiration date for all sessions *)letupdate_pers_expfull_st_namesitedataold_glob_timeoutnew_glob_timeout=Lwt_log.ign_notice~section"Updating expiration date for all persistent sessions";matchnew_glob_timeoutwith|Sometwhent<=0.->(* We close all sessions but those with user defined timeout *)close_all_persistent_states2full_st_namesitedata|_->letnow=Unix.time()inEliommod_cookies.Persistent_cookies.Cookies.iter(funk{Eliommod_cookies.full_state_name;expiry=old_exp;timeout=old_t;session_group}->letscope=full_state_name.Eliom_common.user_scopeiniffull_st_name=full_state_name&&old_t=Eliom_common.TGlobalthenletnewexp=matchold_exp,old_glob_timeout,new_glob_timeoutwith|_,_,None->None|None,_,Somet|Some_,None,Somet->Some(now+.t)|Someoldexp,Someoldt,Somet->Some(oldexp-.oldt+.t)inmatchnewexpwith|Sometwhent<=now->Eliommod_persess.close_persistent_state2~scopesitedatasession_groupk|_->let%lwt()=Eliommod_cookies.Persistent_cookies.addk{Eliommod_cookies.full_state_name;expiry=newexp;timeout=Eliom_common.TGlobal;session_group}inEliommod_cookies.Persistent_cookies.Expiry_dates.remove_cookieold_expk>>=Lwt.pauseelsereturn_unit)