123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143# 1 "src/lib/eliom_parameter.client.ml"(* Ocsigen
* http://www.ocsigen.org
* Copyright (C) 2016 Vasilis Papavasileiou
*
* 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_ocamlincludeEliom_parameter_basetyperaw_post_data=unitmoduleM:sigtype'atvalremove:'at->string->('a*'at)optionvalof_assoc_list:(string*'a)list->'atend=structmoduleRaw=Map.Make(structtypet=stringletcompare=compareend)type'at='alistRaw.tletremovemid=trymatch Raw.findidmwith|[h]->Some(h,Raw.removeidm)|h::t->Some(h,Raw.addidtm)|[]->NonewithNot_found->Noneletof_assoc_listl=letfacc(id,v)=tryletl=Raw.findidaccinRaw.addid(v::l)accwithNot_found->Raw.addid[v]accinList.fold_leftfRaw.emptylendletreconstruct_atom~fmname=trymatchM.removemnamewith|Some(`Stringv,m)->letv=f(Js.to_stringv)inSome(v,m)|_->Nonewith_->Nonelet(>>=)xf=matchxwithSomex->fx|None->Noneletrecreconstruct_set:typeac.alist*Form.form_eltM.t->(a,_,c)params_type->alist*Form.form_eltM.t=fun((acc,m)asp)y->matchreconstruct_params_formmywith|Some(v,m)->reconstruct_set(v::acc,m)y|None->pandreconstruct_params_form:typeac.Form.form_eltM.t->(a,[`WithoutSuffix],c)params_type->(a*Form.form_eltM.t)option=funm->function|TAtom(name,TBool)->(matchM.removemnamewith|Some(_,m)->Some(true,m)|None->Some(false,m))|TAtom(name,y)->reconstruct_atom~f:(atom_of_stringy)mname|TProd(TList_,_)->failwith"Lists or sets in suffixes must be last"|TProd(TSet_,_)->failwith"Lists or sets in suffixes must be last"|TProd(y1,y2)->reconstruct_params_formmy1>>=fun(x1,m)->reconstruct_params_formmy2>>=fun(x2,m)->Some((x1,x2),m)|TUnit->Some((),m)|TOption((TAtom(_,TString)asy),_)->(match reconstruct_params_formmywith|Some("",m)->Some(None,m)|Some(s,m)->Some (Somes,m)|None->Some(None,m))|TOption(y,_)->(matchreconstruct_params_formmywith|Some (x,m)->Some(Somex,m)|None->Some(None,m))|TSet(TAtom(_,TBool)asy)->reconstruct_params_form my>>=fun(x,m)->Some([x],m)|TSety->Some(reconstruct_set ([],m)y)|TSum(y1,y2)->(matchreconstruct_params_formmy1with|Some(x,m)->Some(Inj1x,m)|None->reconstruct_params_formmy2>>=fun(x,m)->Some(Inj2x,m))|TCoordname->letf=int_of_stringinreconstruct_atom~fm(name^".x")>>=fun(abscissa,m)->reconstruct_atom~fm(name^".y")>>=fun(ordinate,m)->Some({abscissa;ordinate},m)|TUserType(name,{of_string=f})->reconstruct_atom~fmname|_->Noneletuser_type~of_string~to_stringn=TUserType(n,{of_string;to_string})letall_suffix_user~of_string~to_stringn=TESuffixu(n,{of_string;to_string})letreconstruct_params_formly=reconstruct_params_form(M.of_assoc_listl)y>>=fun(v,_)->Somevletget_non_localized_get_parameters{name;param}=(* Simplified version of the server-side code that
- only deals with GET params
- doesn't cache the result
- doesn't deal with files *)trySome(reconstruct_params_param(tryEliom_lib.String.Table.findname(Eliom_request_info.get_sess_info()).si_nl_get_paramswithNot_found->[])[]falseNone)withEliom_common.Eliom_Wrong_parameter|Not_found->None