File: cf_uri.mli

package info (click to toggle)
pagodacf 0.10-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 1,204 kB
  • ctags: 2,320
  • sloc: ml: 8,458; ansic: 3,338; makefile: 171; sh: 27
file content (224 lines) | stat: -rw-r--r-- 8,905 bytes parent folder | download | duplicates (7)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
(*---------------------------------------------------------------------------*
  INTERFACE  cf_uri.mli

  Copyright (c) 2003-2006, James H. Woodyatt
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:

    Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.

    Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  OF THE POSSIBILITY OF SUCH DAMAGE. 
 *---------------------------------------------------------------------------*)

(** Operations with Universal Resource Identifier (URI).

    This module implements types for constructing and deconstructing Universal
    Resource Identifiers (URI), as well as convenience functions for
    manipulating their components, and also functions for parsing and emitting
    them as strings.
*)

(** {6 Types} *)

(** The sum type of "host" components of hierarchical URI's. *)
type host =
    | H_hostname of string
    | H_ip4_addr of Cf_ip4_addr.opaque Cf_ip4_addr.t

(** The type of "server" components of hierarchical URI's. *)
type server = {
    srv_user: string option;    (** An optional user name. *)
    srv_host: host;             (** The hostname or IPv4 address. *)
    srv_port: int option;       (** An optional port number. *)
}

(** The type of "authority" components of hierarchical URI's. *)
type authority =
    | A_server of server option     (** Server-based naming authority. *)
    | A_reg_name of string          (** Registry-based naming authority. *)

(** The type of path segments in hierarchical URI's. *)
type segment = {
    seg_name: string;               (** Segment name. *)
    seg_params: string list;        (** Segment parameters list. *)
}

(** The type of network paths in hierarchical URI's. *)
type net_path = {
    net_authority: authority;       (** Naming authority. *)
    net_path: segment list;         (** List of path segments. *)
}

(** The type of hierarchical URI network paths. *)
type net = [ `Net of net_path ]

(** The type of hierarchical URI absolute paths. *)
type abs = [ `Abs of segment * segment list ]

(** The type of hierarchical URI relative paths. *)
type rel = [ `Rel of segment list ]

(** The sum type of hierarchical URI paths. *)
type path = [ net | abs | rel ]

(** The type of absolute hierarchical URI paths with optional query parts. *)
type abs_special_hier = {
    abs_hier_path: [ net | abs ];       (** Path. *)
    abs_hier_query: string option;      (** Query part. *)
}

(** The sum type of absolute URI parts. *)
type abs_special =
    | S_hier of abs_special_hier        (** Hierarchical URI part. *)
    | S_opaque of string                (** Opaque URI part. *)

(** The type of absolute URI. *)
type absolute = {
    abs_scheme: string;             (** URI scheme name. *)
    abs_special: abs_special;       (** Absolute URI part. *)
}

(** The type of relative URI. *)
type relative = {
    rel_path: path;                 (** Path. *)
    rel_query: string option;       (** Query part. *)
}

(** The type of URI. *)
type t = A of absolute | R of relative

(** The type of URI references. *)
type reference = {
    ref_uri: t;                     (** URI *)
    ref_fragment: string option;    (** Optional fragment suffix. *)
}

(** The exception raised when a relative URI has no defined reference to an
    absolute URI for a given base, i.e. too many ".." segments.
*)
exception Rel_undefined

(** {6 Functions} *)

(** Use [escape ?allow s] to obtain a new string by replacing all the
    unreserved and "mark" characters in the string [s] with the equivalent URI
    escape sequence.  The optional [allow] function, if specified, can be used
    to prevent the escape of characters for which the function returns [true].
*)
val escape: ?allow:(char -> bool) -> string -> string

(** Use [unescape s] to obtain a new string by replacing all the URI escape
    sequences in the string [s] with the actual character they denote.
*)
val unescape: string -> string

(** Use [refer_to_base ~base ~rel] to compose an absolute URI by directing the
    relative URI [rel] from the base absolute URI [base].  Raises
    [Invalid_argument] if the base URI is opaque, and raises [Rel_undefined]
    if the URI cannot be referred, i.e. too many ".." segments.
*)
val refer_to_base: base:absolute -> rel:relative -> absolute

(** Use [message_to_uri m] to create a URI by parsing the contents of the
    message [m].  Raises [Invalid_argument] if the message does not contain a
    valid URI.
*)
val message_to_uri: Cf_message.t -> t

(** Use [message_to_absolute_uri ~base m] to create an absolute URI by parsing
    the contents of the message [m] and using [base] as the absolute URI for
    reference in parsing relative URI.  Raises [Invalid_argument] if the
    message does not contain a valid URI, or the base URI is opaque.  Raises
    [Rel_undefined] if the message contains a relative URI that cannot be
    referred by the base URI.
*)
val message_to_absolute_uri: base:absolute -> Cf_message.t -> absolute

(** Use [message_to_uri_reference m] to create a URI reference by parsing the
    contents of the message [m].  Raises [Invalid_argument] if the message does
    not contain a valid URI reference.
*)
val message_to_uri_reference: Cf_message.t -> reference

(** Use [message_to_absolute_uri_reference ~base m] to create a URI reference
    to an absolute URI by parsing the contents of the message [m] and using
    [base] as the absolute URI for reference parsing relative URI.  Raises
    [Invalid_argument] if the message does not contain a valid URI, or the base
    URI is opaque.  Raises [Rel_undefined] if the message contains a relative
    URI that cannot be referred by the base URI.
*)
val message_to_absolute_uri_reference:
    base:absolute -> Cf_message.t -> reference

(** Use [emit_host pp host] to print the host part of a URI [host] with the
    formatter [pp].  Reserved characters in the host name are escaped in the
    output.
*)
val emit_host: Format.formatter -> host -> unit

(** Use [emit_server pp server] to print the server part of a URI [server] with
    the formatter [pp].  Reserved characters in the host name or user name are
    escaped in the output.
*)
val emit_server: Format.formatter -> server -> unit

(** Use [emit_authority pp auth] to print the name authority part of a URI
    [authority] with the formatter [pp].  Reserved characters are escaped
    appropriately.
*)
val emit_authority: Format.formatter -> authority -> unit

(** Use [emit_path pp path] to print the path component of a URI [path] with
    the formatter [pp].  Reserved characters in the path segments or path
    segment parameter lists are escaped in the output.
*)
val emit_path: Format.formatter -> [< path ] -> unit

(** Use [emit_abs_special pp abs] to print the absolute URI specialization
    [abs] with the formatter [pp].  All reserved characters are escaped
    appropriately in the output.
*)
val emit_abs_special: Format.formatter -> abs_special -> unit

(** Use [emit_uri pp uri] to print the URI [uri] with the formatter [pp].  All
    reserved characters are escaped appropriately in the output.
*)
val emit_uri: Format.formatter -> t -> unit

(** Use [emit_uri_reference pp uriref] to print the URI reference [uriref] with
    the formatter [pp].  All reserved characters are escaped appropriately in
    the output.
*)
val emit_uri_reference: Format.formatter -> reference -> unit

(** Use [message_of_uri uri] to produce a message containing the formatted URI
    string produced by emitting [uri] into a string.
*)
val message_of_uri: t -> Cf_message.t

(** Use [message_of_uri_reference uriref] to produce a message containing the
    formatted URI reference string produced by emitting [uriref] into a string.
*)
val message_of_uri_reference: reference -> Cf_message.t

(*--- End of File [ cf_uri.mli ] ---*)