Module Eliom


module Eliom: sig .. end
Eliom.ml defines the functions you need to interact with the Eliommod module:

exception Eliom_Link_too_old
exception Eliom_Session_expired
exception Eliom_Wrong_parameter
exception Eliom_Typing_Error of (string * exn) list
val get_config : unit -> Simplexmlparser.xml list
Allows extensions of the configuration file for your modules

Put your options between <eliom ...> and </eliom>

val sync : ('a -> 'b -> 'c -> 'd) -> 'a -> 'b -> 'c -> 'd Lwt.t
This function may be used for services that can not be interrupted (no cooperation point for threads). It is defined by let sync f sp g p = Lwt.return (f sp g p)

Types


type suff = [ `WithSuffix | `WithoutSuffix ] 
type servcoserv = [ `Coservice | `Service ] 
type getpost = [ `Get | `Post ] 
type attached_service_kind = [ `External | `Internal of servcoserv * getpost ] 
type get_attached_service_kind = [ `External | `Internal of servcoserv * [ `Get ] ] 
type post_attached_service_kind = [ `External | `Internal of servcoserv * [ `Post ] ] 
type internal = [ `Internal of servcoserv * getpost ] 
type registrable = [ `Registrable | `Unregistrable ] 
You can call register function only on registrable services
type +'a a_s 
type +'a na_s 
type service_kind = [ `Attached of attached_service_kind a_s
| `Nonattached of getpost na_s ]
type get_service_kind = [ `Attached of get_attached_service_kind a_s
| `Nonattached of [ `Get ] na_s ]
type post_service_kind = [ `Attached of post_attached_service_kind a_s
| `Nonattached of [ `Post ] na_s ]
type internal_service_kind = [ `Attached of internal a_s
| `Nonattached of getpost na_s ]
type attached = [ `Attached of attached_service_kind a_s ] 
type nonattached = [ `Nonattached of getpost na_s ] 
type ('a, 'b, +'c, +'d, +'e, +'f, +'g) service 
Typed services. The 'kind parameter is a subset of service_kind. 'get and 'post are the type of GET and POST parameters.
type url_path = string list 
val string_of_url_path : url_path -> string
This type is used to represent URL paths; For example the path coucou/ciao is represented by the list ["coucou";"ciao"]

Server parameters


type server_params 
Type of server parameters
val get_user_agent : server_params -> string
val get_full_url : server_params -> string
val get_ip : server_params -> string
val get_inet_addr : server_params -> Unix.inet_addr
val get_all_get_params : server_params -> (string * string) list
All GET parameters in the URL
val get_get_params : server_params -> (string * string) list
Only GET parameters concerning that page
val get_all_post_params : server_params -> (string * string) list
All POST parameters in the request
val get_post_params : server_params -> (string * string) list Lwt.t
Only POST parameters concerning that page
val get_current_path_string : server_params -> string
val get_current_path : server_params -> url_path
val get_hostname : server_params -> string option
val get_port : server_params -> int
val get_other_get_params : server_params -> (string * string) list
val get_suffix : server_params -> url_path
val get_exn : server_params -> exn list
val get_config_file_charset : server_params -> string option
val get_cookies : server_params -> (string * string) list
val set_user_timeout : server_params -> float option -> unit
val unset_user_timeout : server_params -> unit
val get_user_timeout : server_params -> float option
val set_user_persistent_timeout : server_params -> float option -> unit
val unset_user_persistent_timeout : server_params -> unit
val get_user_persistent_timeout : server_params -> float option
val set_user_expdate : server_params -> float option -> unit
Setting and getting cookie expiration date for the session. None means the cookie will expire when the browser is closed.
val get_user_expdate : server_params -> float option
val set_user_persistent_expdate : server_params -> float option -> unit
val get_user_persistent_expdate : server_params -> float option
val set_global_timeout : ?sp:server_params -> float option -> unit
Setting and getting timeout for the session (server side). The session will be closed after this amount of time of inactivity from the user. If you use these function after the initialisation phase, you must give the ~sp parameter.
val get_global_timeout : ?sp:server_params -> unit -> float option
val get_default_timeout : unit -> float option
val set_global_persistent_timeout : ?sp:server_params -> float option -> unit
val get_global_persistent_timeout : ?sp:server_params -> unit -> float option
val get_default_persistent_timeout : unit -> float option
val set_exn_handler : ?sp:server_params ->
(server_params -> exn -> Eliommod.result_to_send Lwt.t) -> unit
Use your own error pages (404, or any exception during page generation)
val get_tmp_filename : Extensions.file_info -> string
Type of files
val get_filesize : Extensions.file_info -> int64
val get_original_filename : Extensions.file_info -> string

Types of pages parameters



Here are some examples of how to specify the types and names of pages parameters:

type ('a, 'b) binsum =
| Inj1 of 'a
| Inj2 of 'b (*Binary sums*)
type 'a param_name 
Type for names of page parameters
type ('a, 'b, 'c) params_type 
Type for parameters of a web page

type 'a listnames = {
   it : 'b 'c. ('a -> 'b -> 'c list) -> 'b list -> 'c list -> 'c list;
}
Type of the iterator used to construct forms from lists
val int : string -> (int, [ `WithoutSuffix ], int param_name) params_type
int s tells that the page takes an integer as parameter, labeled s
val float : string ->
(float, [ `WithoutSuffix ], float param_name) params_type
float s tells that the page takes a floating point number as parameter, labeled s
val string : string ->
(string, [ `WithoutSuffix ], string param_name) params_type
string s tells that the page takes a string as parameter, labeled s
val bool : string -> (bool, [ `WithoutSuffix ], bool param_name) params_type
bool s tells that the page takes a boolean as parameter, labeled s (to use for example with boolean checkboxes)
val file : string ->
(Extensions.file_info, [ `WithoutSuffix ],
Extensions.file_info param_name)
params_type
file s tells that the page takes a file as parameter, labeled s
val radio_answer : string ->
(string option, [ `WithoutSuffix ], string option param_name)
params_type
radio_answer s tells that the page takes the result of a click on a radio button as parameter.
val unit : (unit, [ `WithoutSuffix ], unit param_name) params_type
used for pages that don't have any parameters
val user_type : (string -> 'a) ->
('a -> string) ->
string -> ('a, [ `WithoutSuffix ], 'a param_name) params_type
Allows to use whatever type you want for a parameter of the page. user_type s_to_t t_to_s s tells that the page take a parameter, labeled s, and that the server will have to use s_to_t and t_to_s to make the conversion from and to string.
val sum : ('a, [ `WithoutSuffix ], 'b) params_type ->
('a, [ `WithoutSuffix ], 'b) params_type ->
(('a, 'a) binsum, [ `WithoutSuffix ], 'b * 'b) params_type
val prod : ('a, [ `WithoutSuffix ], 'b) params_type ->
('c, [ `Endsuffix | `WithoutSuffix ], 'd) params_type ->
('a * 'c, [ `WithoutSuffix ], 'b * 'd) params_type
See ** above
val opt : ('a, [ `WithoutSuffix ], 'b) params_type ->
('a option, [ `WithoutSuffix ], 'b) params_type
Use this if you want a parameter to be optional
val list : string ->
('a, [ `WithoutSuffix ], 'b) params_type ->
('a list, [ `WithoutSuffix ], 'b listnames) params_type
The page takes a list of parameters. The first parameter of this function is the name of the list.
val (**) : ('a, [ `WithoutSuffix ], 'b) params_type ->
('c, [< `Endsuffix | `WithoutSuffix ], 'd) params_type ->
('a * 'c, [ `WithoutSuffix ], 'b * 'd) params_type
This is a combinator to allow the page to take several parameters (see examples above) Warning: it is a binary operator. Pages cannot take tuples but only pairs.
val regexp : Netstring_pcre.regexp ->
string ->
string ->
(string, [ `WithoutSuffix ], string param_name) params_type
regexp r d s tells that the page takes a string that matches r as parameter, labeled s, and that will be rewritten in d
val suffix : ('a, [< `Endsuffix | `WithoutSuffix ], 'b) params_type ->
('a, [ `WithSuffix ], 'b) params_type
Tells that the only parameter of the function that will generate the page is the suffix of the URL of the current page. (see register_new_service)
val all_suffix : string ->
(string list, [ `Endsuffix ], string list param_name) params_type
Takes all the suffix, as long as possible, as a string list
val all_suffix_string : string param_name ->
(string, [ `Endsuffix ], string param_name) params_type
Takes all the suffix, as long as possible, as a string
val all_suffix_user : (string -> 'a) ->
('a -> string) ->
string -> ('a, [ `Endsuffix ], 'a param_name) params_type
Takes all the suffix, as long as possible, with a type specified by the user
val all_suffix_regexp : Netstring_pcre.regexp ->
string ->
string -> (string, [ `Endsuffix ], string param_name) params_type
Takes all the suffix, as long as possible, matching the regexp
val suffix_prod : ('a, [< `Endsuffix | `WithoutSuffix ], 'b) params_type ->
('c, [ `WithoutSuffix ], 'd) params_type ->
('a * 'c, [ `WithSuffix ], 'b * 'd) params_type
Tells that the function that will generate the page takes a pair whose first element is the suffix of the URL of the current page. (see register_new_service). e.g. suffix (int "i" ** string "s")

Misc


val static_dir : server_params ->
(string list, unit,
[> `Attached of [> `Internal of [> `Service ] * [> `Get ] ] a_s ],
[ `WithSuffix ], string list param_name, unit param_name,
[> `Unregistrable ])
service
The service that correponds to the directory where static pages are. This directory is chosen in the config file (ocsigen.conf). This service takes the name of the static file as a parameter.

Definitions of entry points (services/URLs)


val new_service : ?sp:server_params ->
url:url_path ->
get_params:('a, [< suff ] as 'b, 'c) params_type ->
unit ->
('a, unit,
[> `Attached of [> `Internal of [> `Service ] * [> `Get ] ] a_s ], 'b,
'c, unit param_name, [> `Registrable ])
service
new_service ~url:p ~get_params:pa () creates an service associated to the url_path p and that takes the parameters pa.

If you specify ~suffix:true, your service will match all requests from client beginning by path. You can have access to the suffix of the URL using suffix or suffix_only. For example new_service ["mysite";"mywiki"] ~suffix:true suffix_only will match all the URL of the shape http://myserver/mysite/mywiki/thesuffix

If you want to create dynamically a new service during session, you must add the ~sp parameter (current server parameters)

val new_external_service : url:url_path ->
get_params:('a, [< suff ] as 'b, 'c) params_type ->
post_params:('d, [ `WithoutSuffix ], 'e) params_type ->
unit ->
('a, 'd, [> `Attached of [> `External ] a_s ], 'b, 'c, 'e,
[> `Unregistrable ])
service
Creates an service for an external web site
val new_coservice : ?max_use:int ->
?timeout:float ->
fallback:(unit, unit,
[ `Attached of [ `Internal of [ `Service ] * [ `Get ] ] a_s ],
[ `WithoutSuffix ], unit param_name, unit param_name,
[< registrable ])
service ->
get_params:('a, [ `WithoutSuffix ], 'b) params_type ->
unit ->
('a, unit,
[> `Attached of [> `Internal of [> `Coservice ] * [> `Get ] ] a_s ],
[ `WithoutSuffix ], 'b, unit param_name, [> `Registrable ])
service
Creates another version of an already existing service, where you can register another treatment. The two versions are automatically distinguished thanks to an extra parameter. It allows to have several links towards the same page, that will behave differently. See the tutorial for more informations.
val new_coservice' : ?max_use:int ->
?timeout:float ->
get_params:('a, [ `WithoutSuffix ], 'b) params_type ->
unit ->
('a, unit, [> `Nonattached of [> `Get ] na_s ], [ `WithoutSuffix ], 'b,
unit param_name, [> `Registrable ])
service
Creates a non-attached coservice. Links towards such services will not change the URL, just add extra parameters.
val new_post_service : ?sp:server_params ->
fallback:('a, unit,
[ `Attached of
[ `Internal of [ `Coservice | `Service ] * [ `Get ] ] a_s ],
[< suff ] as 'b, 'c, unit param_name,
[< `Registrable ])
service ->
post_params:('d, [ `WithoutSuffix ], 'e) params_type ->
unit ->
('a, 'd,
[> `Attached of
[> `Internal of [ `Coservice | `Service ] * [> `Post ] ] a_s ],
'b, 'c, 'e, [> `Registrable ])
service
Creates an service that takes POST parameters. fallback is the same service without POST parameters. You can create an service with POST parameters if the same service does not exist without POST parameters. Thus, the user can't bookmark a page that does not exist.
val new_post_coservice : ?max_use:int ->
?timeout:float ->
fallback:('a, unit,
[ `Attached of
[ `Internal of [< `Coservice | `Service ] * [ `Get ] ]
a_s ],
[< suff ] as 'b, 'c, unit param_name,
[< `Registrable ])
service ->
post_params:('d, [ `WithoutSuffix ], 'e) params_type ->
unit ->
('a, 'd,
[> `Attached of [> `Internal of [> `Coservice ] * [> `Post ] ] a_s ],
'b, 'c, 'e, [> `Registrable ])
service
Creates a coservice with POST parameters
val new_post_coservice' : ?max_use:int ->
?timeout:float ->
post_params:('a, [ `WithoutSuffix ], 'b) params_type ->
unit ->
(unit, 'a, [> `Nonattached of [> `Post ] na_s ], [ `WithoutSuffix ],
unit param_name, 'b, [> `Registrable ])
service
Creates a non attached coservice with POST parameters
val preapply : ('a, 'b, [> `Attached of 'd a_s ] as 'c, [< suff ], 'e, 'f, 'g)
service ->
'a ->
(unit, 'b, 'c, [ `WithoutSuffix ], unit param_name, 'f,
[ `Unregistrable ])
service
Preapplied services are created from a service and its GET parameters. It is not possible to register something on an preapplied service. Preapplied services may be used in links or as fallbacks for coservices
val make_string_uri : ('a, unit, [< get_service_kind ], [< suff ], 'b,
unit param_name, [< registrable ])
service -> server_params -> 'a -> string

Creating modules to register services for one type of pages


module type REGCREATE = sig .. end
module type FORMCREATE = sig .. end
module type ELIOMFORMSIG = sig .. end
module type ELIOMREGSIG1 = sig .. end
module type ELIOMREGSIG = sig .. end
module type ELIOMSIG = sig .. end
module MakeRegister: 
functor (Pages : REGCREATE) -> ELIOMREGSIG with type page = Pages.page
module MakeForms: 
functor (Pages : FORMCREATE) -> ELIOMFORMSIG with type form_content_elt = Pages.form_content_elt and type form_content_elt_list = Pages.form_content_elt_list and type form_elt = Pages.form_elt and type a_content_elt = Pages.a_content_elt and type a_content_elt_list = Pages.a_content_elt_list and type a_elt = Pages.a_elt and type a_elt_list = Pages.a_elt_list and type div_content_elt = Pages.div_content_elt and type div_content_elt_list = Pages.div_content_elt_list and type uri = Pages.uri and type link_elt = Pages.link_elt and type script_elt = Pages.script_elt and type textarea_elt = Pages.textarea_elt and type select_elt = Pages.select_elt and type input_elt = Pages.input_elt and type pcdata_elt = Pages.pcdata_elt and type a_attrib_t = Pages.a_attrib_t and type form_attrib_t = Pages.form_attrib_t and type input_attrib_t = Pages.input_attrib_t and type textarea_attrib_t = Pages.textarea_attrib_t and type select_attrib_t = Pages.select_attrib_t and type link_attrib_t = Pages.link_attrib_t and type script_attrib_t = Pages.script_attrib_t and type input_type_t = Pages.input_type_t

Module for registering typed Xhtml pages



Creating links, forms, etc.


module type XHTMLFORMSSIG = sig .. end
module Xhtml: sig .. end
module Blocks: sig .. end
module SubXhtml: 
functor (T : sig
type content 
end) -> sig .. end

Modules to register other types of pages


module HtmlText: ELIOMSIG  with 
type page = string
and type form_content_elt = string
and type form_content_elt_list = string
and type form_elt = string 
and type a_content_elt = string 
and type a_content_elt_list = string 
and type a_elt = string 
and type a_elt_list = string 
and type div_content_elt = string 
and type div_content_elt_list = string 
and type uri = string 
and type link_elt = string 
and type script_elt = string 
and type textarea_elt = string 
and type select_elt = string 
and type input_elt = string 
and type pcdata_elt = string 
and type a_attrib_t = string 
and type form_attrib_t = string 
and type input_attrib_t = string 
and type textarea_attrib_t = string 
and type select_attrib_t = string 
and type link_attrib_t = string 
and type script_attrib_t = string 
and type input_type_t = string
module CssText: ELIOMREGSIG  with type page = string
module Text: ELIOMREGSIG  with type page = string * string
The first string is the content, the second is the content type, for example "text/html"
module Actions: ELIOMREGSIG  with 
  type page = exn list
module Unit: ELIOMREGSIG  with 
  type page = unit
module Redirections: ELIOMREGSIG  with 
  type page = string
module Files: ELIOMREGSIG  with 
  type page = string
module Any: ELIOMREGSIG  with 
  type page = Eliommod.result_to_send

Session data in memory


type 'a table 
val create_table : ?sp:server_params -> unit -> 'a table
Create a table in memory where you can store your session data After initialization phase, you must give the ~sp parameter
val get_session_data : 'a table -> server_params -> 'a option
val set_session_data : 'a table -> server_params -> 'a -> unit
val remove_session_data : 'a table -> server_params -> unit

Persistent sessions


type 'a persistent_table 
val create_persistent_table : string -> 'a persistent_table
val get_persistent_data : 'a persistent_table -> server_params -> 'a option Lwt.t
val set_persistent_data : 'a persistent_table -> server_params -> 'a -> unit Lwt.t
val remove_persistent_data : 'a persistent_table -> server_params -> unit Lwt.t
val close_persistent_session : server_params -> unit Lwt.t
Close the persistent session (destroying all persistent data)
val close_volatile_session : server_params -> unit
Close Eliom's volatile session
val close_session : server_params -> unit Lwt.t
Close noth sessions