123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127# 1 "src/lib/eliom_process.client.ml"(* Ocsigen
* http://www.ocsigen.org
* Copyright (C) 2010 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.
*)openJs_of_ocamlopenEliom_lib(* Logs *)letsection=Lwt_log.Section.make"eliom:process"letlog_section=sectionlethistory_api=Dom_html.hasPushState()letget_set_js_serverside_valuername=((funs->r:=Somes),(fun()->not(!r=None)),(fun()->match!rwith|Somes->s|None->(* if variable toto does not exist,
Js.Unsafe.variable "toto" fails, but
Js.Unsafe.get Js.Unsafe.global (Js.string "toto") returns undefined *)Js.Optdef.case(Js.def(Js.Unsafe.getJs.Unsafe.global(Js.stringname)))(fun()->failwith(name^" not defined. A client Eliom application must either be sent by an Eliom server application or you must call Eliom_client.init_client_app."))(funvar->lets=unmarshal_jsvarinr:=Somes;s)),fun()->r:=None)let(set_sitedata,is_set_sitedata,(get_sitedata:unit->Eliom_types.sitedata),reset_sitedata)=get_set_js_serverside_valueEliom_common.sitedata"__eliom_appl_sitedata"letignored_get_params=ref[]letignored_post_params=ref[]letset_ignored_paramsgetpost=letcompile=List.map(funs->Re.seq[Re.start;Re.Pcre.res;Re.stop]|>Re.compile)inignored_get_params:=compileget;ignored_post_params:=compilepostlet(set_info,is_set_info,(get_info:unit->Eliom_common.client_process_info),reset_info)=get_set_js_serverside_value(refNone)"__eliom_appl_process_info"let(set_request_cookies,is_set_request_cookies,(get_request_cookies:unit->Ocsigen_cookie_map.t),reset_request_cookies)=get_set_js_serverside_value(refNone)"__eliom_request_cookies"let(set_request_template,is_set_request_template,(get_request_template:unit->stringoption),reset_request_template)=get_set_js_serverside_value(refNone)"__eliom_request_template"letappl_name=lazy(let_,v,_=(* We are using an appl cookie for this,
and not a JS variable,
because we want to send it back with each request.
For mobile apps, we set the cookie from JS variable. *)Ocsigen_cookie_map.Map_inner.findEliom_common.appl_name_cookie_name(Ocsigen_cookie_map.Map_path.find(get_sitedata()).Eliom_types.site_dir(Eliommod_cookies.get_table(Some(get_info()).cpi_hostname)))inv)letset_base_url,get_base_url=letr:stringoptionref=refNonein((funs->r:=Somes),fun()->match!rwith|Somes->s|None->failwith"base_url not set. Did you forget to call Eliom_client.init_client_app?")(** None on server side *)letappl_name_r=refNone(* Set by Eliom_client.init_client_app *)letget_application_name()=match!appl_name_rwith|None->(try!!appl_namewithNot_found->Lwt_log.raise_error~section"Application name not defined")|Somen->nletclient_side=true