Module Ocsigen


module Ocsigen: sig .. end
Ocsigen.ml defines the functions you need to interact with the Ocsigenmod module:

val get_config : unit -> Simplexmlparser.xml list
Allows extensions of the configuration file for your modules

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

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 service_kind = [ `External_Service
| `Internal_Service of [ `Local_Service | `Public_Service ] ]
Kind of service
type ('a, 'b, +'c, +'d, +'e, +'f) service 
Typed services. The 'kind parameter is subset of service_kind. 'get and 'post are the type of GET and POST parameters.
type url_path = string list 
This type is used to represent URL paths; For example the path coucou/ciao is represented by the list ["coucou";"ciao"]

Types of pages parameters



Here are some examples of how to specify the types and names of pages parameters:
type server_params 
Type of server parameters
val get_user_agent : server_params -> string
val get_hostname : server_params -> string option
val get_full_url : server_params -> string
val get_inet_addr : server_params -> Unix.inet_addr
val get_ip : server_params -> string
val get_port : server_params -> int
val get_get_params : server_params -> (string * string) list
val get_post_params : server_params -> (string * string) list Lwt.t
val get_current_url : server_params -> url_path
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

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, [ `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, [ `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 suffix_only : (string, [ `WithSuffix ], string param_name) 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 suffix : ('a, [ `WithoutSuffix ], 'b) params_type ->
(string * 'a, [ `WithSuffix ], string param_name * 'b)
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")
val static_dir : server_params ->
(string, unit, [ `Internal_Service of [ `Public_Service ] ], [ `WithSuffix ],
string param_name, unit param_name)
service

Misc

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.

val close_session : server_params -> unit
Close the session

Registering actions


type ('a, 'b) action 
Type of actions. Actions are like services but they do not generate any page. When an action is called, the function associated is launched and current page is (possibly) reloaded.
val new_action : post_params:('a, [ `WithoutSuffix ], 'b) params_type ->
('a, 'b) action
Creates an action
val register_action : action:('a, 'b) action ->
(server_params -> 'a -> unit Lwt.t) -> unit
Register an action in the global table
val register_action_for_session : server_params ->
action:('a, 'b) action ->
(server_params -> 'a -> unit Lwt.t) -> unit
Register an action in the session table
val register_new_action : post_params:('a, [ `WithoutSuffix ], 'b) params_type ->
(server_params -> 'a -> unit Lwt.t) -> ('a, 'b) action
Same as new_action followed by register_action
val register_new_action_for_session : server_params ->
post_params:('a, [ `WithoutSuffix ], 'b) params_type ->
(server_params -> 'a -> unit Lwt.t) -> ('a, 'b) action
Same as new_action followed by register_action_for_session
val new_service : url:url_path ->
?prefix:bool ->
get_params:('a, [< `WithSuffix | `WithoutSuffix ] as 'b, 'c)
params_type ->
unit ->
('a, unit, [ `Internal_Service of [ `Public_Service ] ], 'b, 'c,
unit param_name)
service

Definitions of entry points (services/URLs)

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 ~prefix: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"] ~prefix:true suffix_only will match all the URL of the shape http://myserver/mysite/mywiki/thesuffix

val new_external_service : url:url_path ->
?prefix:bool ->
get_params:('a, [< `WithSuffix | `WithoutSuffix ] as 'b, 'c)
params_type ->
post_params:('d, [ `WithoutSuffix ], 'e) params_type ->
unit -> ('a, 'd, [ `External_Service ], 'b, 'c, 'e) service
Creates an service for an external web site
val new_auxiliary_service : fallback:('a, unit, [ `Internal_Service of [ `Public_Service ] ], 'b, 'c, 'd)
service ->
('a, unit, [ `Internal_Service of [ `Local_Service ] ], 'b, 'c, 'd)
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_post_service : fallback:('a, unit, [ `Internal_Service of [ `Public_Service ] ], 'b, 'c,
unit param_name)
service ->
post_params:('d, [ `WithoutSuffix ], 'e) params_type ->
('a, 'd, [ `Internal_Service of [ `Public_Service ] ], 'b, 'c, 'e)
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_auxiliary_service : fallback:('a, 'b, [ `Internal_Service of [ `Public_Service ] ], 'c, 'd, 'e)
service ->
post_params:('f, [ `WithoutSuffix ], 'g) params_type ->
('a, 'f, [ `Internal_Service of [ `Local_Service ] ], 'c, 'd, 'g)
service
Creates a auxiliary service with POST parameters
module Xhtml: sig .. end
Pages registration (typed xhtml)

Using other ways (than the module Ocsigen.Xhtml) to create pages


module type REGCREATE = sig .. end
module type FORMCREATE = sig .. end
module type OCSIGENFORMSIG = sig .. end
module type OCSIGENREGSIG = sig .. end
module type OCSIGENSIG = sig .. end
module MakeRegister: 
functor (Pages : REGCREATE) -> OCSIGENREGSIG with type page = Pages.page
module MakeForms: 
functor (Pages : FORMCREATE) -> OCSIGENFORMSIG 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 Text: OCSIGENSIG  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