1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
(****************************************************************************)
(* Copyright (C) 2011,2012,2013 Ralf Treinen *)
(* <ralf.treinen@pps.univ-paris-diderot.fr> *)
(* *)
(* This library 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, either version 3 of the *)
(* License, or (at your option) any later version. A special linking *)
(* exception to the GNU Lesser General Public License applies to this *)
(* library, see the COPYING file for more information. *)
(****************************************************************************)
exception Invalid_url of string;;
include Util.Logging(struct let label = __FILE__ end) ;;
(***********************************************************************)
(* Input schemes *******************************************************)
type debtypes = [ `Edsp | `Deb ]
type rpmtypes = [ `Synthesis | `Hdlist ]
type osgitypes = [ `Eclipse ]
type othertypes = [ `Csw | `Cv ]
type filetypes = [ `Cudf | debtypes | rpmtypes | osgitypes | othertypes ]
let scheme_to_string = function
| `Edsp -> "edsp"
| `Csw -> "csw"
| `Cv -> "cv"
| `Deb -> "deb"
| `Eclipse -> "eclipse"
| `Cudf -> "cudf"
| `Synthesis -> "synthesis"
| `Hdlist -> "hdlist"
;;
let scheme_of_string = function
| "edsp" -> `Edsp
| "csw" -> `Csw
| "cv" -> `Cv
| "deb" -> `Deb
| "cudf" -> `Cudf
| "eclipse" -> `Eclipse
| "synthesis" -> `Synthesis
| "hdlist" -> `Hdlist
| s -> fatal "unknown input scheme" s
;;
let supported_input_types =
[`Edsp; `Deb ; `Synthesis ; `Hdlist ; `Eclipse ; `Csw ; `Cudf ; `Cv ]
;;
(***********************************************************************)
(* URLs ****************************************************************)
type url = {
scheme : filetypes;
path : string; (* filename *)
};;
let to_string u = (scheme_to_string u.scheme)^"://"^u.path
;;
let of_string s =
let l = String.length s in
let pos_colon =
try String.index s ':'
with Not_found -> fatal "missing '://' separator %s" s
in
if pos_colon+2 >= l
|| String.get s (pos_colon+1) <> '/'
|| String.get s (pos_colon+2) <> '/'
then fatal "missing '://' separator %s" s;
let scheme = scheme_of_string (String.sub s 0 pos_colon)
and start_rest = pos_colon+3 in
{ scheme = scheme;
path = String.sub s start_rest (l-start_rest);
}
;;
|