1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 * This file is part of LibreOffice published API.
24 #ifndef INCLUDED_RTL_URI_H
25 #define INCLUDED_RTL_URI_H
27 #include "sal/config.h"
29 #include "rtl/textenc.h"
30 #include "rtl/ustring.h"
31 #include "sal/saldllapi.h"
32 #include "sal/types.h"
34 #if defined __cplusplus
36 #endif /* __cplusplus */
38 /** Various predefined URI 'char classes.'
40 A 'char class' defines which (ASCII) characters can be written 'as they
41 are' in a part of a Uri, and which characters have to be written using
42 escape sequences ('%' followed by two hex digits). Characters outside
43 the ASCII range are always written using escape sequences.
45 If there are other frequently used char classes, they can be added to
46 this enumeration; the function rtl_getUriCharClass() has to be adapted
51 /** The empty char class.
53 All characters are written using escape sequences.
57 /** The RFC 2732 @<uric> char class.
60 The 'valid' characters are !$&'()*+,-./:;=?@[]_~ plus digits and
63 This differs from RFC 3986 @<fragment> in additionally allowing []
68 /** The RFC 2396 @<uric_no_slash> char class.
71 The 'valid' characters are !$&'()*+,-.:;=?@_~ plus digits and letters.
73 This differs from RFC 3986 @<fragment> in additionally encoding /
74 This differs from RFC 3986 @<pchar> in additionally allowing ?
77 rtl_UriCharClassUricNoSlash
,
79 /** The RFC 2396 @<rel_segment> char class.
82 The 'valid' characters are !$&'()*+,-.;=@_~ plus digits and letters.
84 This is the same as RFC 3986 @<segment-nz-nc>
87 rtl_UriCharClassRelSegment
,
89 /** The RFC 2396 @<reg_name> char class.
92 The 'valid' characters are !$&'()*+,-.:;=@_~ plus digits and letters.
94 This differs from RFC 3986 @<reg_name> in additionally allowing @
97 rtl_UriCharClassRegName
,
99 /** The RFC 2396 @<userinfo> char class.
102 The 'valid' characters are !$&'()*+,-.:;=_~ plus digits and letters.
104 This is the same as RFC 3986 @<userinfo>
107 rtl_UriCharClassUserinfo
,
109 /** The RFC 2396 @<pchar> char class.
112 The 'valid' characters are !$&'()*+,-.:=@_~ plus digits and letters.
114 This differs from RFC 3986 @<pchar> in additionally encoding ;
117 rtl_UriCharClassPchar
,
119 /** The char class for the values of uno URL parameters.
122 The 'valid' characters are !$&'()*+-./:?@_~ plus digits and letters.
125 rtl_UriCharClassUnoParamValue
,
127 rtl_UriCharClass_FORCE_EQUAL_SIZE
= SAL_MAX_ENUM
131 /** The mechanism describing how escape sequences in the input of
132 rtl_uriEncode() are handled.
136 /** The special meaning of '%' is ignored (i.e., there are by definition
137 no escape sequences in the input).
139 This mechanism is useful to encode user input as part of a URI (e.g.,
140 the user-supplied password in an ftp URL---'%20abcde' is a valid
141 password, so do not assume that the '%20' is an escaped space).
143 rtl_UriEncodeIgnoreEscapes
,
145 /** All escape sequences ('%' followed by two hex digits) are kept intact,
146 even if they represent characters that need not be escaped or if they
147 do not even map to characters in the given charset.
149 This mechanism is useful when passing on complete URIs more or less
150 unmodified (e.g., within an HTTP proxy): missing escape sequences are
151 added, but existing escape sequences are not touched (except that any
152 lower case hex digits are replaced by upper case hex digits).
154 rtl_UriEncodeKeepEscapes
,
156 /** All escape sequences ('%' followed by two hex digits) are resolved in
157 a first step; only those that represent characters that need to be
158 escaped are kept intact.
160 This mechanism is useful to properly encode complete URIs entered by
161 the user: the URI is brought into a 'canonic form,' but care is taken
162 not to damage (valid) escape sequences the (careful) user already
165 rtl_UriEncodeCheckEscapes
,
167 /** Like rtl_UriEncodeIgnoreEscapes, but indicating failure when converting
168 unmappable characters.
174 /** Like rtl_UriEncodeKeepEscapes, but indicating failure when converting
175 unmappable characters.
179 rtl_UriEncodeStrictKeepEscapes
,
181 rtl_UriEncode_FORCE_EQUAL_SIZE
= SAL_MAX_ENUM
183 rtl_UriEncodeMechanism
;
185 /** The mechanism describing how rtl_uriDecode() translates (part of) a URI
186 into a Unicode string.
190 /** The text is returned completely unmodified.
194 /** The text is returned in the form of an IURI (cf.
195 draft-masinter-url-i18n-05.txt).
197 All escape sequences representing ASCII characters (%00--%7F) are
198 kept, all other escape sequences are interpreted as UTF-8 characters
199 and translated to Unicode, if possible.
203 /** The text is decoded.
205 All escape sequences representing characters from the given charset
206 are decoded and translated to Unicode, if possible.
208 rtl_UriDecodeWithCharset
,
210 /** Like rtl_UriDecodeWithCharset, but indicating failure when converting
211 unmappable characters.
217 rtl_UriDecode_FORCE_EQUAL_SIZE
= SAL_MAX_ENUM
219 rtl_UriDecodeMechanism
;
221 /** Map a predefined rtl_UriCharClass to a form usable by rtl_uriEncode().
223 The function rtl_uriEncode() expects an array of 128 booleans, and this
224 function maps rtl_UriCharClass enumeration members to such arrays.
227 Any valid member of rtl_UriCharClass.
230 An array of 128 booleans, to be used in calls to rtl_uriEncode().
232 SAL_DLLPUBLIC sal_Bool
const * SAL_CALL
rtl_getUriCharClass(rtl_UriCharClass eCharClass
)
233 SAL_THROW_EXTERN_C();
235 /** Encode a text as (part of) a URI.
238 Any Unicode string. Must not be null.
241 A char class, represented as an array of 128 booleans (true means keep the
242 corresponding ASCII character unencoded, false means encode it). Must not
243 be null, and the boolean corresponding to the percent sign (0x25) must be
244 false. (See rtl_getUriCharClass() for a function mapping from
245 rtl_UriCharClass to such arrays.)
248 The mechanism describing how escape sequences in the input text are
252 When Unicode characters from the input text have to be written using
253 escape sequences (because they are either outside the ASCII range or do
254 not belong to the given char class), they are first translated into this
255 charset before being encoded using escape sequences.
257 Also, if the encode mechanism is rtl_UriEncodeCheckEscapes, all escape
258 sequences already present in the input text are interpreted as characters
262 Returns an encoded representation of the input text. Must itself not be
263 null, and must point to either null or a valid string.
265 If the encode mechanism is rtl_UriEncodeStrict, and pText cannot be
266 converted to eCharset because it contains unmappable characters (which
267 implies that pText is not empty), then an empty string is returned.
269 SAL_DLLPUBLIC
void SAL_CALL
rtl_uriEncode(
271 sal_Bool
const * pCharClass
,
272 rtl_UriEncodeMechanism eMechanism
,
273 rtl_TextEncoding eCharset
,
274 rtl_uString
** pResult
)
275 SAL_THROW_EXTERN_C();
277 /** Decode (a part of) a URI.
280 Any Unicode string. Must not be null. (If the input is indeed part of a
281 valid URI, this string will only contain a subset of the ASCII characters,
282 but this function also handles other Unicode characters properly.)
285 The mechanism describing how the input text is translated into a Unicode
289 When the decode mechanism is rtl_UriDecodeWithCharset, all escape
290 sequences in the input text are interpreted as characters from this
291 charset. Those characters are translated to Unicode characters in the
292 resulting output, if possible.
294 When the decode mechanism is rtl_UriDecodeNone or rtl_UriDecodeToIuri,
295 this parameter is ignored (and is best specified as
296 RTL_TEXTENCODING_UTF8).
299 Returns a decoded representation of the input text. Must itself not be
300 null, and must point to either null or a valid string.
302 If the decode mechanism is rtl_UriDecodeStrict, and pText cannot be
303 converted to eCharset because it contains (encodings of) unmappable
304 characters (which implies that pText is not empty), then an empty string is
307 SAL_DLLPUBLIC
void SAL_CALL
rtl_uriDecode(
309 rtl_UriDecodeMechanism eMechanism
,
310 rtl_TextEncoding eCharset
,
311 rtl_uString
** pResult
)
312 SAL_THROW_EXTERN_C();
314 /** Convert a relative URI reference into an absolute URI.
316 This function uses the strict parser algorithm described in RFC 3986,
319 This function signals exceptions by returning false and letting pException
320 point to a message explaining the exception.
323 An absolute URI that serves as the base URI. If it has to be inspected
324 (i.e., pRelUriRef is not an absolute URI already), and it is not an absolute
325 URI (i.e., does not begin with a @<scheme ":"> part), an exception will be
329 A URI reference that may be either absolute or relative. If it is
330 absolute, it will be returned unmodified.
333 Returns an absolute URI. Must itself not be null, and must point to either
334 null or a valid string. If an exception is signalled, it is left unchanged.
337 Returns an explanatory message in case an exception is signalled. Must
338 itself not be null, and must point to either null or a valid string. If no
339 exception is signalled, it is left unchanged.
342 True if no exception is signalled, otherwise false.
344 SAL_DLLPUBLIC sal_Bool SAL_CALL
rtl_uriConvertRelToAbs(
345 rtl_uString
* pBaseUriRef
,
346 rtl_uString
* pRelUriRef
,
347 rtl_uString
** pResult
,
348 rtl_uString
** pException
)
349 SAL_THROW_EXTERN_C();
351 #if defined __cplusplus
353 #endif /* __cplusplus */
355 #endif // INCLUDED_RTL_URI_H
357 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */