contrib: gcrypt: Disable asm for NACL
[vlc.git] / include / vlc_url.h
blobe13b7a5abb57e777e5252c5287bed9f52c7e2de0
1 /*****************************************************************************
2 * vlc_url.h: URL related macros
3 *****************************************************************************
4 * Copyright (C) 2002-2006 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * Rémi Denis-Courmont <rem # videolan.org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #ifndef VLC_URL_H
26 # define VLC_URL_H
28 /**
29 * \file
30 * This file defines functions for manipulating URL in vlc
32 * \ingroup strings
33 * @{
36 /**
37 * Converts local path to URL.
39 * Builds a URL representation from a local UTF-8 null-terminated file path.
41 * @param path file path
42 * @param scheme URI scheme to use (default is auto: "file", "fd" or "smb")
43 * @return a heap-allocated URI string on success
44 * or NULL in case of error (errno will be set accordingly)
46 VLC_API char *vlc_path2uri(const char *path, const char *scheme) VLC_MALLOC;
48 /**
49 * Converts a URI to a local path.
51 * Builds a local path (UTF-8-encoded null-terminated string) from a URI if
52 * the URI scheme allows.
54 * @param url URI
55 * @return a heap-allocated string or success
56 * or NULL on error
58 VLC_API char *vlc_uri2path(const char *url) VLC_MALLOC;
60 /**
61 * Decodes an URI component in place.
63 * Decodes one null-terminated UTF-8 URI component to aa null-terminated UTF-8
64 * string in place.
66 * See also vlc_uri_decode_duplicate() for the not-in-place variant.
68 * \warning <b>This function does NOT decode entire URIs.</b>
69 * URI can only be decoded (and encoded) one component at a time
70 * (e.g. the host name, one directory, the file name).
71 * Complete URIs are always "encoded" (or they are syntaxically invalid).
72 * See IETF RFC3986, especially §2.4 for details.
74 * \note URI encoding is <b>different</b> from Javascript escaping. Especially,
75 * white spaces and Unicode non-ASCII code points are encoded differently.
77 * \param str null-terminated component
78 * \return str is returned on success. NULL if str was not properly encoded.
80 VLC_API char *vlc_uri_decode(char *str);
82 /**
83 * Decodes an URI component.
85 * See also vlc_uri_decode() for the in-place variant.
87 * \return a heap-allocated string on success or NULL on error.
89 VLC_API char *vlc_uri_decode_duplicate(const char *str) VLC_MALLOC;
91 /**
92 * Encodes a URI component.
94 * Substitutes URI-unsafe, URI delimiters and non-ASCII characters into their
95 * URI-encoded URI-safe representation. See also IETF RFC3986 §2.
97 * @param str nul-terminated UTF-8 representation of the component.
98 * @note Obviously, a URI containing nul bytes cannot be passed.
99 * @return heap-allocated string, or NULL if out of memory.
101 VLC_API char *vlc_uri_encode(const char *str) VLC_MALLOC;
104 * Composes an URI.
106 * Converts a decomposed/parsed URI structure (\ref vlc_url_t) into a
107 * nul-terminated URI literal string.
109 * See also IETF RFC3986 section 5.3 for details.
111 * \bug URI fragments (i.e. HTML anchors) are not handled
113 * \return a heap-allocated nul-terminated string or NULL if out of memory
115 VLC_API char *vlc_uri_compose(const vlc_url_t *) VLC_MALLOC;
118 * Resolves an URI reference.
120 * Resolves an URI reference relative to a base URI.
121 * If the reference is an absolute URI, then this function simply returns a
122 * copy of the URI reference.
124 * \param base base URI (as a nul-terminated string)
125 * \param ref URI reference (also as a nul-terminated string)
127 * \return a heap-allocated nul-terminated string representing the resolved
128 * absolute URI, or NULL if out of memory.
130 VLC_API char *vlc_uri_resolve(const char *base, const char *ref) VLC_MALLOC;
133 * Fixes up a URI string.
135 * Attempts to convert a nul-terminated string into a syntactically valid URI.
136 * If the string is, or may be, a syntactically valid URI, an exact copy is
137 * returned. In any case, the result will only contain URI-safe and URI
138 * delimiter characters (generic delimiters or sub-delimiters) and all percent
139 * signs will be followed by two hexadecimal characters.
141 * @return a heap-allocated string, or NULL if on out of memory.
143 VLC_API char *vlc_uri_fixup(const char *) VLC_MALLOC;
145 struct vlc_url_t
147 char *psz_protocol;
148 char *psz_username;
149 char *psz_password;
150 char *psz_host;
151 unsigned i_port;
152 char *psz_path;
153 char *psz_option;
155 char *psz_buffer; /* to be freed */
156 char *psz_pathbuffer; /* to be freed */
160 * Parses an URI or IRI.
162 * Extracts the following parts from an URI string:
163 * - scheme (i.e. protocol),
164 * - user (deprecated),
165 * - password (also deprecated),
166 * - host name or IP address literal,
167 * - port number,
168 * - path (including the filename preceded by any and all directories)
169 * - request parameters (excluding the leading question mark '?').
171 * The function accepts URIs, as well as UTF-8-encoded IRIs. For IRIs, the hier
172 * part (specifically, the host name) is assumed to be an IDN and is decoded to
173 * ASCII according, so it can be used for DNS resolution. If the host is an
174 * IPv6 address literal, brackets are stripped.
176 * Any missing part is set to nul. For historical reasons, the target structure
177 * is always initialized, even if parsing the URI string fails.
179 * On error, errno is set to one of the following value:
180 * - ENOMEM in case of memory allocation failure,
181 * - EINVAL in case of syntax error in the input string.
183 * \bug The URI fragment is discarded if present.
185 * \note This function allocates memory. vlc_UrlClean() must be used free
186 * associated the allocations, even if the function fails.
188 * \param url structure of URL parts [OUT]
189 * \param str nul-terminated URL string to split
190 * \retval 0 success
191 * \retval -1 failure
193 VLC_API int vlc_UrlParse(vlc_url_t *url, const char *str);
196 * Parses an URI or IRI and fix up the path part.
198 * \see vlc_UrlParse
199 * \see vlc_uri_fixup
201 VLC_API int vlc_UrlParseFixup(vlc_url_t *url, const char *str);
204 * Releases resources allocated by vlc_UrlParse().
206 VLC_API void vlc_UrlClean(vlc_url_t *);
208 /** @} */
210 #endif