123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122# 1 "src/lib/eliom_parameter.server.ml"(* Ocsigen
* http://www.ocsigen.org
* Copyright (C) 2007 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.
*)openEliom_libincludeEliom_parameter_basetyperaw_post_data=Eliom_request_info.raw_post_dataopenOcsigen_extensions(* server-specific constructors *)letuser_type?client_to_and_of~(of_string:string->'a)~(to_string:'a->string)(n:string)=TUserType(n,Eliom_common.To_and_of_shared.create?client_to_and_of{of_string;to_string})letall_suffix_user?client_to_and_of~(of_string:string->'a)~(to_string:'a->string)(n:string)=TESuffixu(n,Eliom_common.To_and_of_shared.create?client_to_and_of{of_string;to_string})(* types available only on server side (no pcre on browser) *)letregexpregdest~to_stringn=user_type~of_string:(funs->matchRe.Pcre.exec~rex:reg~pos:0swith|gwhen Re.Group.startg0=0->(tryOcsigen_extensions.replace_user_dirreg(Ocsigen_extensions.parse_user_dirdest)swithOcsigen_extensions.NoSuchUser->raise(Failure"User does not exist"))|_|(exceptionNot_found)->raise(Failure"Regexp not matching"))~to_stringnletall_suffix_regexpregdest~(to_string:'a->string)(n:string):(string,[`Endsuffix],[`Oneofstring]param_name)params_type=all_suffix_user~of_string:(funs->matchRe.Pcre.exec~rex:reg~pos:0swith|gwhenRe.Group.startg0=0->(tryOcsigen_extensions.replace_user_dirreg(Ocsigen_extensions.parse_user_dirdest)swithOcsigen_extensions.NoSuchUser->raise(Failure"User does not exist"))|_|(exceptionNot_found)->raise(Failure"Regexp not matching"))~to_stringn(* Non localized parameters *)letget_non_localized_parametersparamsfiles~getorpost~sp{name;get;post;param=paramtype;_}=(* non localized parameters are parsed only once,
and cached in request_cache *)letkey=matchgetorpostwith`Get ->get|`Post->postintry(* first, look in cache: *)Polytables.get~table:(Ocsigen_request.request_cachesp.Eliom_common.sp_request.request_info)~keywithNot_found->letp=trySome(letparams=tryString.Table.findnameparamswithNot_found->[]inletfiles=tryString.Table.findnamefileswithNot_found->[]inreconstruct_params_paramtypeparamsfilesfalseNone)withEliom_common.Eliom_Wrong_parameter|Not_found->Nonein(* add in cache: *)Polytables.set~table:(Ocsigen_request.request_cachesp.Eliom_common.sp_request.request_info)~key~value:p;pletget_non_localized_get_parameters p=letsp=Eliom_common.get_sp()inget_non_localized_parameterssp.Eliom_common.sp_si.Eliom_common.si_nl_get_paramssp.Eliom_common.sp_si.Eliom_common.si_nl_file_params~getorpost:`Get~sppletget_non_localized_post_parametersp=letsp=Eliom_common.get_sp()inget_non_localized_parameterssp.Eliom_common.sp_si.Eliom_common.si_nl_post_paramssp.Eliom_common.sp_si.Eliom_common.si_nl_file_params~getorpost:`Post~spp