123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174(*********************************************************************************)(* OCaml-IRI *)(* *)(* Copyright (C) 2016 Institut National de Recherche en Informatique *)(* et en Automatique. All rights reserved. *)(* *)(* This program is free software; you can redistribute it and/or modify *)(* it under the terms of the GNU Lesser General Public License version *)(* 3 as published by the Free Software Foundation. *)(* *)(* 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 Library 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 *)(* *)(* Contact: Maxence.Guesdon@inria.fr *)(* *)(* *)(*********************************************************************************)typeerror=Iri_types.errorexceptionError=Iri_types.ErroropenIri_typesletstring_of_error=function|Parse_error(str,e)->letmsg=matchewithIri_lexer.Errore->Iri_lexer.string_of_errore|_->Printexc.to_stringeinPrintf.sprintf"Parse error in %s\n%s"strmsgletparse_errorstre=raise(Error(Parse_error(str,e)))typeiri=tmoduleOrd=structtypet=iriletcompare=Iri_types.compare~normalize:trueendmoduleSet=Set.Make(Ord)moduleMap=Map.Make(Ord)letof_lexbuf?pctdecode?pos?normalizelexbuf=letiri=Iri_lexer.iri?pctdecode?poslexbufinmatchnormalize,is_relativeiriwithSometrue,_|None,false->Iri_types.normalizeiri|_->iriletof_string?pctdecode?pos?normalizestr=letlexbuf=Sedlexing.Utf8.from_stringstrintryof_lexbuf?pctdecode?pos?normalizelexbufwith(Iri_lexer.Error_)ase->parse_errorstreletresolve?(normalize=true)~baseiri=letresolved=matchis_relativeiriwithfalse->iri|true->letstr=to_stringiriin(*prerr_endline
(Printf.sprintf "%s=\nscheme=%s\nhost=%s\npath=%s"
str (scheme iri)
(match host iri with None -> "" | Some s -> s)
(path_string iri)
);*)letlen=String.lengthstriniflen<=0thenbaseelsematchString.getstr0with|'#'->with_fragmentbase(fragmentiri)|'?'->letbase=with_fragmentbaseNoneinwith_querybase(queryiri)|_->letbase=with_querybaseNoneinletbase=with_fragmentbaseNoneinletbase=matchhostiriwithNone->base|Somehost->letbase=with_hostbase(Somehost)inletbase=with_portbase(portiri)inwith_userbase(useriri)inletpath=matchpathiriwith|Absolutep->Absolutep|Relativeiri_path->letpath_base=pathbaseinletpath=letl=matchpath_basewith|Absolutel->l|Relativel->linletrl=List.revlinletrip=List.reviri_pathinletp=matchrl,ripwith|[],_->List.revrip|""::ql,[]->l|""::ql,_->List.rev(rip@ql)(*| ("." | "..") :: _, _ -> List.rev (rip @ rl)*)|_::ql,_->List.rev(rip@ql)in(*prerr_endline (let f l = String.concat "/" l in
Printf.sprintf "resolve: l=%s, iri_path=%s => p=%s"
(f l) (f iri_path) (f p)
);*)matchpath_basewith|Absolute_->Absolutep|Relative_->Relativepinpathinleti=with_pathbasepathinleti=with_fragmenti(fragmentiri)inleti=with_queryi(queryiri)iniinifnormalizethenIri_types.normalizeresolvedelseresolvedletparse_http_linkstr=letlexbuf=trySedlexing.Utf8.from_stringstrwithSedlexing.MalFormedase->raise(Error(Parse_error("Malformed character in http link: "^str,e)))inIri_lexer.http_linklexbufletto_uri=Iri_types.to_uriletnormalize=Iri_types.normalizeletwith_fragment=Iri_types.with_fragmentletfragment=Iri_types.fragmentletquery_set=Iri_types.query_setletquery_opt=Iri_types.query_optletquery_get=Iri_types.query_getletwith_query_kv=Iri_types.with_query_kvletwith_query=Iri_types.with_queryletquery_kv=Iri_types.query_kvletquery=Iri_types.queryletappend_path=Iri_types.append_pathletpath_string=Iri_types.path_stringletwith_path=Iri_types.with_pathletpath=Iri_types.pathletwith_port=Iri_types.with_portletport=Iri_types.portletwith_host=Iri_types.with_hostlethost=Iri_types.hostletwith_user=Iri_types.with_userletuser=Iri_types.userletwith_scheme=Iri_types.with_schemeletscheme=Iri_types.schemeletto_string=Iri_types.to_stringletto_string_details=Iri_types.to_string_detailsletpp=Iri_types.ppletpp_details=Iri_types.pp_detailsletequal=Iri_types.equalletcompare=Iri_types.compareletis_relative=Iri_types.is_relativeletis_absolute=Iri_types.is_absoluteletiri=Iri_types.iritypet=Iri_types.ttypepath=Iri_types.path=Absoluteofstringlist|Relativeofstringlisttypequery_kv=Iri_types.query_kvmoduleKV=Iri_types.KV