Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file ocsigen_lib_base.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525(* Ocsigen
* Copyright (C) 2005-2008 Vincent Balat, Stéphane Glondu
*
* 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.
*)exceptionOcsigen_Internal_ErrorofstringexceptionInput_is_too_largeexceptionOcsigen_Bad_RequestexceptionOcsigen_Request_too_longexternalid:'a->'a="%identity"let(>>=)=Lwt.bindlet(>|=)=Lwt.(>|=)let(!!)=Lazy.forcelet(|>)xf=fxlet(@@)fx=fxletcompfgx=f(gx)letcurryfxy=f(x,y)letuncurryf(x,y)=fxytypepolyexternalto_poly:'a->poly="%identity"externalfrom_poly:poly->'a="%identity"moduleTuple3=structletfst(a,_,_)=aletsnd(_,a,_)=aletthd(_,_,a)=aendtypeyesnomaybe=Yes|No|Maybetype('a,'b)leftright=Leftof'a|Rightof'bletadvert="Page generated by OCaml with Ocsigen.
See http://ocsigen.org/ and http://caml.inria.fr/ for information"(*****************************************************************************)moduleOption=structtype'at='aoptionletmapf=function|Somex->Some(fx)|None->Noneletgetf=function|Somex->x|None->f()letget'a=function|Somex->x|None->aletiterf=function|Somex->fx|None->()letreturnx=Somexletbindoptk=matchoptwith|Somex->kx|None->Noneletto_list=function|None->[]|Somev->[v]moduleLwt=structletmapf=function|Somex->fx>>=funv->Lwt.return(Somev)|None->Lwt.returnNoneletgetf=function|Somex->Lwt.returnx|None->f()letget'a=function|Somex->Lwt.returnx|None->aletiterf=function|Somex->fx|None->Lwt.return()letbindoptk=matchoptwith|Somex->kx|None->Lwt.returnNoneendendmoduleList=structincludeListletmap_filterfl=letrecauxacc=function|[]->acc|t::q->matchftwith|None->auxaccq|Somer->aux(r::acc)qinList.rev(aux[]l)letrecremove_first_if_anya=function|[]->[]|b::lwhena=b->l|b::l->b::(remove_first_if_anyal)letrecremove_first_if_any_qa=function|[]->[]|b::lwhena==b->l|b::l->b::(remove_first_if_any_qal)letrecremove_firsta=function|[]->raiseNot_found|b::lwhena=b->l|b::l->b::(remove_firstal)letrecremove_first_qa=function|[]->raiseNot_found|b::lwhena==b->l|b::l->b::(remove_first_qal)letrecremove_alla=function|[]->[]|b::lwhena=b->remove_allal|b::l->b::(remove_allal)letrecremove_all_qa=function|[]->[]|b::lwhena==b->remove_all_qal|b::l->b::(remove_all_qal)letrecremove_all_assoca=function|[]->[]|(b,_)::lwhena=b->remove_all_assocal|b::l->b::(remove_all_assocal)letrecremove_all_assoc_qa=function|[]->[]|(b,_)::lwhena==b->remove_all_assoc_qal|b::l->b::(remove_all_assoc_qal)letreclast=function|[]->raiseNot_found|[b]->b|_::l->lastlletrecassoc_removea=function|[]->raiseNot_found|(b,c)::lwhena=b->c,l|b::l->letv,ll=assoc_removealin(v,b::ll)letrecis_prefixl1l2=match(l1,l2)with|[],_->true|a::ll1,b::ll2whena=b->is_prefixll1ll2|_->falseletrecchopnxs=ifn<=0thenxselsematchxswith|[]->[]|_x::xs->chop(n-1)xsletrecsplit_atnxs=ifn<=0then[],xselsematchxswith|[]->[],[]|x::xs->letl,r=split_at(n-1)xsinx::l,rend(*****************************************************************************)(* circular lists *)moduleClist:sigtype'attype'anodevalmake:'a->'anodevalcreate:unit->'atvalinsert:'at->'anode->unitvalremove:'anode->unitvalvalue:'anode->'avalin_list:'anode->boolvalis_empty:'at->boolvaliter:('a->unit)->'at->unitvalfold_left:('a->'b->'a)->'a->'bt->'aend=structtype'anode={content:'aoption;mutableprev:'anode;mutablenext:'anode}type'at='anodeletmake'c=letrecx={content=c;prev=x;next=x}inxletmakec=make'(Somec)letcreate()=make'Noneletinsertpx=letn=p.nextinp.next<-x;x.prev<-p;x.next<-n;n.prev<-xletremovex=letp=x.previnletn=x.nextinp.next<-n;n.prev<-p;x.next<-x;x.prev<-xletin_listx=x.next!=xletis_emptyset=set.next==setletvaluec=matchc.contentwith|None->failwith"Clist.value"|Somec->cletreciterf(node:'at)=matchnode.next.contentwith|Somec->fc;iterfnode.next|None->()letrecfold_leftfa(node:'at)=matchnode.next.contentwith|Somec->fold_leftf(fac)node.next|None->aend(*****************************************************************************)moduleInt=structmoduleTable=Map.Make(structtypet=intletcompare=compareend)end(*****************************************************************************)moduleString_base=structincludeString(* Returns a copy of the string from beg to endd,
removing spaces at the beginning and at the end *)letremove_spacessbegendd=letrecfind_not_spacesistep=if(i>endd)||(beg>i)thenielseifs.[i]=' 'thenfind_not_spaces(i+step)stepelseiinletfirst=find_not_spacesbeg1inletlast=find_not_spacesendd(-1)iniflast>=firstthenString.subsfirst(1+last-first)else""(* Cut a string to the next separator *)letbasic_sepchars=tryletseppos=String.indexscharin((String.subs0seppos),(String.subs(seppos+1)((String.lengths)-seppos-1)))withInvalid_argument_->raiseNot_found(* Cut a string to the next separator, removing spaces.
Raises Not_found if the separator cannot be found.
*)letsepchars=letlen=String.lengthsinletseppos=String.indexscharin((remove_spacess0(seppos-1)),(remove_spacess(seppos+1)(len-1)))(* splits a string, for ex "azert, sdfmlskdf, dfdsfs" *)letsplit?(multisep=false)chars=letlongueur=String.lengthsinletrecauxdeb=ifdeb>=longueurthen[]elsetryletfirstsep=String.index_fromsdebcharinifmultisep&&firstsep=debthenaux(deb+1)else(remove_spacessdeb(firstsep-1))::(aux(firstsep+1))withNot_found->[remove_spacessdeb(longueur-1)]inaux0letmay_appends1~sep=function|""->s1|s2->s1^sep^s2letmay_concats1~seps2=matchs1,s2with|_,""->s1|"",_->s2|_->String.concatsep[s1;s2](* returns the index of the first difference between s1 and s2,
starting from n and ending at last.
returns (last + 1) if no difference is found.
*)letrecfirst_diffs1s2nlast=tryifs1.[n]=s2.[n]thenifn=lastthenlast+1elsefirst_diffs1s2(n+1)lastelsenwithInvalid_argument_->nmoduleTable=Map.Make(String)moduleSet=Set.Make(String)moduleMap=Map.Make(String)end(*****************************************************************************)moduleUrl_base=structtypet=stringtypeuri=stringtypepath=stringlistletmake_absolute_url~https~host~porturi=(ifhttpsthen"https://"else"http://")^host^(if(port=80&¬https)||(https&&port=443)then""else":"^string_of_intport)^uriletremove_dotdot=(* removes "../" *)letrecaux=function|[]->[]|[""]asl->l(* | ""::l -> aux l *)(* we do not remove "//" any more,
because of optional suffixes in Eliom *)|".."::l->auxl|a::l->a::(auxl)infunction|[]->[]|""::l->""::(auxl)|l->auxlletremove_end_slashs=tryifs.[(String.lengths)-1]='/'thenString.subs0((String.lengths)-1)elseswithInvalid_argument_->sletremove_internal_slashu=letrecaux=function|[]->[]|[a]->[a]|""::l->auxl|a::l->a::(auxl)inmatchuwith|[]->[]|a::l->a::(auxl)letchange_empty_list=function|[]->[""](* It is not possible to register an empty URL *)|l->lletrecadd_end_slash_if_missing=function|[]->[""]|[""]asa->a|a::l->a::(add_end_slash_if_missingl)letrecremove_slash_at_end=function|[]|[""]->[]|a::l->a::(remove_slash_at_endl)letremove_slash_at_beginning=function|[]->[]|[""]->[""]|""::l->l|l->lletrecis_prefix_skip_end_slashl1l2=match(l1,l2)with|[""],_|[],_->true|a::ll1,b::ll2whena=b->is_prefix_skip_end_slashll1ll2|_->falseletsplit_fragments=tryletpos=String.indexs'#'inString.subs0pos,Some(String.subs(pos+1)(String.lengths-1-pos))withNot_found->s,Noneletjoin_path=function[""]->"/"|l->String.concat"/"l(* Taken from Ocamlnet 4.1.2 *)letsplit_paths=letl=String.lengthsinletreccollect_wordsk=letk'=tryString.index_fromsk'/'withNot_found->linletword=String.subsk(k'-k)inifk'>=lthen[word]elseword::collect_words(k'+1)inmatchcollect_words0with|[""]->[]|["";""]->[""]|other->other(* Taken from Ocamlnet 4.1.2 *)letnorm_pathl=letrecremove_slash_slashlfirst=matchlwith|[""]->[""]|["";""]whenfirst->[""]|""::l'whennotfirst->remove_slash_slashl'false|x::l'->x::remove_slash_slashl'false|[]->[]inletrecremove_dotlfirst=matchlwith|(["."]|[".";""])->iffirstthen[]else[""]|"."::x::l'->remove_dot(x::l')false|x::l'->x::remove_dotl'false|[]->[]inletrecremove_dot_dot_oncelfirst=matchlwithx::".."::[]whenx<>""&&x<>".."&¬first->[""]|x::".."::l'whenx<>""&&x<>".."->l'|x::l'->x::remove_dot_dot_oncel'false|[]->raiseNot_foundinletrecremove_dot_dotl=tryletl'=remove_dot_dot_onceltrueinremove_dot_dotl'withNot_found->linletl'=remove_dot_dot(remove_dot(remove_slash_slashltrue)true)inmatchl'with[".."]->["..";""]|["";""]->[""]|_->l'end(*****************************************************************************)letdebug=prerr_endline