.TH "Eliom_state" 3o 2014-07-10 OCamldoc "" .SH NAME Eliom_state \- Storing server-side values for your applications or sessions. .SH Module Module Eliom_state .SH Documentation .sp Module .BI "Eliom_state" : .B sig end .sp Storing server\-side values for your applications or sessions\&. .sp .sp .sp .sp .PP .B === Please read the .B {% <> %} .B before this page to learn how server side state works\&. .B .B {% <> >> %} === .PP .PP .B === .B Managing the state of an application .B === .PP .PP .B === .B Closing sessions, removing state data and services .B === .PP .I val discard : .B scope:[< `Client_process of Eliom_common.scope_hierarchy .B | `Request .B | `Session of Eliom_common.scope_hierarchy .B | `Session_group of Eliom_common.scope_hierarchy ] -> .B ?secure:bool -> unit -> unit Lwt.t .sp Delete server\-side (volatile and persistent) state data and services for a session, a group of sessions, a client process or a request\&. .sp Use that function to close a session (using scope .B Eliom_common\&.session )\&. .sp Closing a group of sessions will close all sessions in the group\&. .sp By default will remove both secure and unsecure data and services, but if .B ~secure is present\&. .sp Warning: you may also want to unset some request\-scoped Eliom references when discarding a state\&. .sp .sp .I val discard_all_scopes : .B ?secure:bool -> unit -> unit Lwt.t .sp .sp .I val discard_data : .B ?persistent:bool -> .B scope:[< `Client_process of Eliom_common.scope_hierarchy .B | `Request .B | `Session of Eliom_common.scope_hierarchy .B | `Session_group of Eliom_common.scope_hierarchy ] -> .B ?secure:bool -> unit -> unit Lwt.t .sp Remove current state data\&. .sp If the optional parameter .B ?persistent is not present, will remove both volatile and persistent data\&. Otherwise only volatile or persistent data\&. .sp .sp .I val discard_services : .B scope:[< Eliom_common.user_scope ] -> ?secure:bool -> unit -> unit .sp Remove all services registered for the given scope (the default beeing .B `Session )\&. .sp .sp .PP .B === .B State status .B === .PP .I type state_status = | Alive_state | Empty_state | Expired_state .sp The following functions return the current state of the state for a given scope: .sp \- .B Alive_state means that data has been recorded for this scope .sp \- .B Empty_state means that there is no data for this scope .sp \- .B Expired_state means that data for this scope has been removed because the timeout has been reached\&. The default scope is .B `Session \&. .sp .sp .I val service_state_status : .B scope:[< Eliom_common.user_scope ] -> .B ?secure:bool -> unit -> state_status .sp .sp .I val volatile_data_state_status : .B scope:[< Eliom_common.user_scope ] -> .B ?secure:bool -> unit -> state_status .sp .sp .I val persistent_data_state_status : .B scope:[< Eliom_common.user_scope ] -> .B ?secure:bool -> unit -> state_status Lwt.t .sp .sp .PP .B === .B User cookies .B .B .B If you want to store a client\-side state, and ask the browser to .B send it back with each request, you can set manually your own cookies\&. .B Usual cookies correspond to scope `Session (that is, one browser)\&. .B The browser send them with each request to the same Web site\&. .B But Eliom also implements client\-side process cookies .B (scope `Client_process), that behave in the same way, .B but for one instance of the client\-side Eliom program (if there is one)\&. .B .B Cookies can be limited to a subsite using the ?path optional .B parameter\&. This path is relative to the main path of your Web site\&. .B (It is not possible to set a cookie for a subsite larger than your current .B Web site)\&. .B .B Cookies can have an expiration date, specified (in seconds .B since the 1st of January 1970) in the optional parameter ?exp\&. .B If the parameter is not set, .B the expiration date will be when the browser is closed\&. .B .B Secure cookies are sent by the browser only with HTTPS (default: false)\&. === .PP .I val set_cookie : .B ?cookie_level:Eliom_common.cookie_level -> .B ?path:string list -> .B ?exp:float -> ?secure:bool -> name:string -> value:string -> unit -> unit .sp Ask the browser to record a cookie\&. .sp .sp .I val unset_cookie : .B ?cookie_level:Eliom_common.cookie_level -> .B ?path:string list -> name:string -> unit -> unit .sp Ask the browser to remove a cookie\&. .sp .sp .PP .B === .B Session groups .B === .PP .PP .B === If your Web site has users, .B it is a good idea to group together all the sessions for one user\&. .B Otherwise, you may want to group sessions according to another .B criterion\&. .B .B Session groups may be used for example to limit .B the number of sessions one user can open at the same time, or to implement .B a "close all your sessions" feature\&. .B Usually, the group is the user name\&. === .PP .PP .B === .B Putting a session in a group, removing a session from a group .B === .PP .I val set_service_session_group : .B ?set_max:int -> .B ?scope:Eliom_common.session_scope -> ?secure:bool -> string -> unit .sp sets the group to which belong the service session\&. .sp If the optional .B ?set_max parameter is present, also sets the maximum number of sessions in the group\&. Default: follow current configuration for the group or default configuration if the group does not exist\&. .sp If .B ~secure is true, it will affect the secure session (secure cookies), otherwise (default), the unsecure one (behavior change in Eliom 4)\&. .sp .sp .I val unset_service_session_group : .B ?set_max:int -> .B ?scope:Eliom_common.session_scope -> ?secure:bool -> unit -> unit .sp Remove the session from its group\&. Will not close the session if it contains data\&. .sp .sp .I val get_service_session_group : .B ?scope:Eliom_common.session_scope -> ?secure:bool -> unit -> string option .sp returns the group to which belong the service session\&. If the session does not belong to any group, or if no session is opened, return .B None \&. .sp .sp .I val get_service_session_group_size : .B ?scope:Eliom_common.session_scope -> ?secure:bool -> unit -> int option .sp returns the number of sessions in the group\&. If he session does not belong to any group or if no session is opened, returns .B None .sp .sp .I val set_volatile_data_session_group : .B ?set_max:int -> .B ?scope:Eliom_common.session_scope -> ?secure:bool -> string -> unit .sp sets the group to which belong the volatile data session\&. .sp If the optional .B ?set_max parameter is present, also sets the maximum number of sessions in the group\&. Default: follow current configuration for the group or default configuration if the group does not exist\&. .sp .sp .I val unset_volatile_data_session_group : .B ?set_max:int -> .B ?scope:Eliom_common.session_scope -> ?secure:bool -> unit -> unit .sp Remove the session from its group\&. Will not close the session if it contains data\&. .sp .sp .I val get_volatile_data_session_group : .B ?scope:Eliom_common.session_scope -> ?secure:bool -> unit -> string option .sp returns the group to which belong the data session\&. If the session does not belong to any group, or if no session is opened, return .B None \&. .sp .sp .I val get_volatile_data_session_group_size : .B ?scope:Eliom_common.session_scope -> ?secure:bool -> unit -> int option .sp returns the number of sessions in the group\&. If he session does not belong to any group or if no session is opened, returns .B None .sp .sp .I val set_persistent_data_session_group : .B ?set_max:int option -> .B ?scope:Eliom_common.session_scope -> ?secure:bool -> string -> unit Lwt.t .sp sets the group to which belong the persistent session\&. .sp If the optional .B ?set_max parameter is present, also sets the maximum number of sessions in the group\&. When .B ~set_max:None is present, the number of session is unlimited\&. Default: follow current configuration for the group or default configuration if the group does not exist\&. .sp .sp .I val unset_persistent_data_session_group : .B ?scope:Eliom_common.session_scope -> ?secure:bool -> unit -> unit Lwt.t .sp Remove the session from its group\&. Will not close the session if it contains data\&. .sp .sp .I val get_persistent_data_session_group : .B ?scope:Eliom_common.session_scope -> .B ?secure:bool -> unit -> string option Lwt.t .sp returns the group to which belong the persistent session\&. If the session does not belong to any group, or if no session is opened, return .B None \&. .sp .sp .PP .B === .B Maximum group size .B === .PP .PP .B === The following functions of this section set the maximum number of .B sessions in a session group, for the different kinds of session\&. .B This won\&'t modify existing groups\&. .B That value will be used only as default value if you do not specify the .B optional parameter ?set_max of function .B Eliom_state\&.set_volatile_data_session_group\&. .B .B If there is no group, the number of sessions is limitated by sub network .B (which can be a problem for example if the server is behind a .B reverse proxy)\&. .B It is highly recommended to use session groups! .B .B \- Default number of sessions in a group: 5 .B \- Default number of sessions in a sub network: 1000000 .B \- Default IPV4 sub network: /16 .B \- Default IPV6 sub network: /56 .B .B These default can be changed from configuration file and/or .B using these functions\&. .B .B If ~override_configfile is true (default (false), .B then the function will set the value even if it has been .B modified in the configuration file\&. .B It means that by default, these functions have no effect .B if there is a value in the configuration file\&. .B This gives the ability to override the values chosen by the module .B in the configuration file\&. .B Use ~override_configfile:true for example if your .B Eliom module wants to change the values afterwards .B (for example in the site configuration Web interface)\&. === .PP .I val set_default_max_service_sessions_per_group : .B ?override_configfile:bool -> int -> unit .sp Sets the maximum number of service sessions in a session group (see above)\&. .sp .sp .I val set_default_max_volatile_data_sessions_per_group : .B ?override_configfile:bool -> int -> unit .sp Sets the maximum number of volatile data sessions in a session group (see above)\&. .sp .sp .I val set_default_max_persistent_data_sessions_per_group : .B ?override_configfile:bool -> int option -> unit .sp Sets the maximum number of persistent data sessions in a session group (see above)\&. .B None means "no limitation"\&. .sp .sp .I val set_default_max_volatile_sessions_per_group : .B ?override_configfile:bool -> int -> unit .sp Sets the maximum number of volatile sessions (data and service) in a session group (see above)\&. .sp .sp .I val set_default_max_service_sessions_per_subnet : .B ?override_configfile:bool -> int -> unit .sp Sets the maximum number of service sessions in a subnet (see above)\&. .sp .sp .I val set_default_max_volatile_data_sessions_per_subnet : .B ?override_configfile:bool -> int -> unit .sp Sets the maximum number of volatile data sessions in a subnet (see above)\&. .sp .sp .I val set_default_max_volatile_sessions_per_subnet : .B ?override_configfile:bool -> int -> unit .sp Sets the maximum number of volatile sessions (data and service) in a subnet (see above)\&. .sp .sp .I val set_default_max_service_tab_sessions_per_group : .B ?override_configfile:bool -> int -> unit .sp Sets the maximum number of tab service sessions in a session group (see above)\&. .sp .sp .I val set_default_max_volatile_data_tab_sessions_per_group : .B ?override_configfile:bool -> int -> unit .sp Sets the maximum number of volatile data tab sessions in a session group (see above)\&. .sp .sp .I val set_default_max_persistent_data_tab_sessions_per_group : .B ?override_configfile:bool -> int option -> unit .sp Sets the maximum number of persistent data tab sessions in a session group (see above)\&. .sp .sp .I val set_default_max_volatile_tab_sessions_per_group : .B ?override_configfile:bool -> int -> unit .sp Sets the maximum number of volatile tab sessions (data and service) in a session group (see above)\&. .sp .sp .I val set_ipv4_subnet_mask : .B ?override_configfile:bool -> int -> unit .sp Sets the mask for subnet (IPV4)\&. .sp .sp .I val set_ipv6_subnet_mask : .B ?override_configfile:bool -> int -> unit .sp Sets the mask for subnet (IPV6)\&. .sp .sp .I val set_max_service_states_for_group_or_subnet : .B scope:Eliom_common.user_scope -> ?secure:bool -> int -> unit .sp Sets the maximum number of service sessions in the current session group (or for the client sub network, if there is no group)\&. .sp .sp .I val set_max_volatile_data_states_for_group_or_subnet : .B scope:Eliom_common.user_scope -> ?secure:bool -> int -> unit .sp Sets the maximum number of volatile data sessions in the current session group (or for the client sub network, if there is no group)\&. .sp .sp .I val set_max_volatile_states_for_group_or_subnet : .B scope:Eliom_common.user_scope -> ?secure:bool -> int -> unit .sp Sets the maximum number of volatile sessions (both data and service sessions) in the current group (or for the client sub network, if there is no group)\&. .sp .sp .PP .B === .B Expiration of cookies and timeouts .B === .PP .PP .B === .B Cookie expiration .B === .PP .PP .B === The functions in this section ask the browser to set the state cookie .B expiration date, for the different kinds of session, in seconds, .B since the 1st of January 1970\&. None means the cookie will expire .B when the browser is closed\&. Note: there is no way to set cookies .B for an infinite time on browsers\&. .B .B By default, it will affect regular browser cookies (sessions)\&. .B But if you set ~cookie_level:`Client_process, .B it will only affect the client\-side Eliom process (if there is one), .B which simulates some kind of "tab cookies"\&. === .PP .I val set_service_cookie_exp_date : .B cookie_scope:Eliom_common.cookie_scope -> .B ?secure:bool -> float option -> unit .sp Sets the cookie expiration date for the current service state (see above)\&. .sp .sp .I val set_volatile_data_cookie_exp_date : .B cookie_scope:Eliom_common.cookie_scope -> .B ?secure:bool -> float option -> unit .sp Sets the cookie expiration date for the current data state (see above)\&. .sp .sp .I val set_persistent_data_cookie_exp_date : .B cookie_scope:Eliom_common.cookie_scope -> .B ?secure:bool -> float option -> unit Lwt.t .sp Sets the cookie expiration date for the persistent state (see above)\&. .sp .sp .PP .B === .B Global configuration of state timeouts .B === .PP .PP .B === The following functions set the timeout for states, for the .B different kinds of states\&. States will be closed after .B this amount of time of inactivity from the user\&. None means no .B timeout\&. .B .B The optional parameter ?recompute_expdates is false by .B default\&. If you set it to true, the expiration dates for all .B states in the table will be recomputed with the new timeout\&. .B That is, the difference between the new timeout and the old one .B will be added to their expiration dates (asynchronously, .B by another Lwt thread, as this can take a long time)\&. .B States whose timeout has been set individually with .B functions like .B Eliom_state\&.set_volatile_data_state_timeout won\&'t be affected\&. .B .B If ~scope_hierarchy is not present, .B it is the default for all scope hierarchies, .B and in that case recompute_expdates is ignored\&. ~scope_hierarchy:None .B means the default scope hierarchy\&. .B .B If ~override_configfile is true (default (false), .B then the function will set the timeout even if it has been .B modified in the configuration file\&. .B It means that by default, these functions have no effect .B if there is a value in the configuration file\&. .B This gives the ability to override the values chosen by the module .B in the configuration file\&. .B Use ~override_configfile:true for example if your .B Eliom module wants to change the values afterwards .B (for example in the site configuration Web interface)\&. === .PP .I val set_global_volatile_state_timeout : .B cookie_scope:[< Eliom_common.cookie_scope ] -> .B ?secure:bool -> .B ?recompute_expdates:bool -> ?override_configfile:bool -> float option -> unit .sp Sets the (server side) timeout for volatile (= "in memory") sessions (both service session and volatile data session)\&. .sp .sp .I val set_default_global_service_state_timeout : .B cookie_level:[< Eliom_common.cookie_level ] -> .B ?override_configfile:bool -> float option -> unit .sp .sp .I val set_global_service_state_timeout : .B cookie_scope:[< Eliom_common.cookie_scope ] -> .B ?secure:bool -> .B ?recompute_expdates:bool -> ?override_configfile:bool -> float option -> unit .sp Sets the (server side) timeout for service states\&. .sp .sp .I val set_default_global_service_state_timeout : .B cookie_level:[< Eliom_common.cookie_level ] -> .B ?override_configfile:bool -> float option -> unit .sp .sp .I val set_global_volatile_data_state_timeout : .B cookie_scope:[< Eliom_common.cookie_scope ] -> .B ?secure:bool -> .B ?recompute_expdates:bool -> ?override_configfile:bool -> float option -> unit .sp Sets the (server side) timeout for volatile (= "in memory") data states\&. .sp .sp .I val set_default_global_volatile_data_state_timeout : .B cookie_level:[< Eliom_common.cookie_level ] -> .B ?override_configfile:bool -> float option -> unit .sp .sp .I val set_global_persistent_data_state_timeout : .B cookie_scope:[< Eliom_common.cookie_scope ] -> .B ?secure:bool -> .B ?recompute_expdates:bool -> ?override_configfile:bool -> float option -> unit .sp Sets the (server side) timeout for persistent states\&. .sp .sp .I val set_default_global_persistent_data_state_timeout : .B cookie_level:[< Eliom_common.cookie_level ] -> .B ?override_configfile:bool -> float option -> unit .sp .sp .I val get_global_service_state_timeout : .B ?secure:bool -> .B cookie_scope:[< Eliom_common.cookie_scope ] -> unit -> float option .sp Returns the (server side) timeout for service states\&. .sp .sp .I val get_global_volatile_data_state_timeout : .B ?secure:bool -> .B cookie_scope:[< Eliom_common.cookie_scope ] -> unit -> float option .sp Returns the (server side) timeout for "volatile data" states\&. .sp .sp .I val get_global_persistent_data_state_timeout : .B ?secure:bool -> .B cookie_scope:[< Eliom_common.cookie_scope ] -> unit -> float option .sp Returns the (server side) timeout for persistent states\&. .sp .sp .PP .B === .B Personalizing timeouts for current state .B === .PP .I val set_service_state_timeout : .B cookie_scope:Eliom_common.cookie_scope -> .B ?secure:bool -> float option -> unit .sp sets the timeout for service state (server side) for current user, in seconds\&. .B None = no timeout .sp .sp .I val unset_service_state_timeout : .B cookie_scope:[< Eliom_common.cookie_scope ] -> ?secure:bool -> unit -> unit .sp remove the service state timeout for current user (and turn back to the default)\&. .sp .sp .I val get_service_state_timeout : .B cookie_scope:[< Eliom_common.cookie_scope ] -> .B ?secure:bool -> unit -> float option .sp returns the timeout for current service state\&. .B None = no timeout .sp .sp .I val set_volatile_data_state_timeout : .B cookie_scope:[< Eliom_common.cookie_scope ] -> .B ?secure:bool -> float option -> unit .sp sets the (server side) timeout for volatile data state for current user, in seconds\&. .B None = no timeout .sp .sp .I val unset_volatile_data_state_timeout : .B cookie_scope:[< Eliom_common.cookie_scope ] -> ?secure:bool -> unit -> unit .sp remove the "volatile data" state timeout for current user (and turn back to the default)\&. .sp .sp .I val get_volatile_data_state_timeout : .B cookie_scope:[< Eliom_common.cookie_scope ] -> .B ?secure:bool -> unit -> float option .sp returns the timeout for current volatile data state\&. .B None = no timeout .sp .sp .I val set_persistent_data_state_timeout : .B cookie_scope:[< Eliom_common.cookie_scope ] -> .B ?secure:bool -> float option -> unit Lwt.t .sp sets the (server side) timeout for persistent state for current user, in seconds\&. .B None = no timeout .sp .sp .I val unset_persistent_data_state_timeout : .B cookie_scope:[< Eliom_common.cookie_scope ] -> .B ?secure:bool -> unit -> unit Lwt.t .sp remove the persistent state timeout for current user (and turn back to the default)\&. .sp .sp .I val get_persistent_data_state_timeout : .B cookie_scope:[< Eliom_common.cookie_scope ] -> .B ?secure:bool -> unit -> float option Lwt.t .sp returns the persistent state timeout for current user\&. .B None = no timeout .sp .sp .PP .B === .B Administrating server side state .B === .PP .PP .B === Warning: Most these functions must be called when the site .B information is available, that is, either .B during a request or during the initialisation phase of the site\&. .B Otherwise, it will raise the exception .B Eliom_common\&.Eliom_site_information_not_available\&. .B If you are using static linking, you must delay the call to this function .B until the configuration file is read, using .B Eliom_service\&.register_eliom_module\&. Otherwise you will also get .B this exception\&. === .PP .I type .B 'a .I volatile_table .sp The type of (volatile) state data tables\&. .sp .sp .I type .B 'a .I persistent_table .sp The type of persistent state data tables\&. .sp .sp .I val discard_everything : .B unit -> unit Lwt.t .sp Discard all services and persistent and volatile data for every scopes\&. .sp .sp .I val discard_all : .B scope:Eliom_common.user_scope -> ?secure:bool -> unit -> unit Lwt.t .sp Discard all services and persistent and volatile data for one scope\&. .sp .sp .I val discard_all_data : .B ?persistent:bool -> .B scope:Eliom_common.user_scope -> ?secure:bool -> unit -> unit Lwt.t .sp Discard server side data for all clients, for the given scope\&. .sp If the optional parameter .B ?persistent is not present, both the persistent and volatile data will be removed\&. .sp .sp .I val discard_all_services : .B scope:Eliom_common.user_scope -> ?secure:bool -> unit -> unit Lwt.t .sp Remove all services registered for clients for the given scope\&. .sp .sp .I module Ext : .B sig end .sp .sp