dxva2: remove dead code
[vlc.git] / include / vlc_url.h
blob5a20c27edc1de1c225754da2c5941d1535d7d209
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 */
159 * Parses an URI or IRI.
161 * Extracts the following parts from an URI string:
162 * - scheme (i.e. protocol),
163 * - user (deprecated),
164 * - password (also deprecated),
165 * - host name or IP address literal,
166 * - port number,
167 * - path (including the filename preceded by any and all directories)
168 * - request parameters (excluding the leading question mark '?').
170 * The function accepts URIs, as well as UTF-8-encoded IRIs. For IRIs, the hier
171 * part (specifically, the host name) is assumed to be an IDN and is decoded to
172 * ASCII according, so it can be used for DNS resolution. If the host is an
173 * IPv6 address literal, brackets are stripped.
175 * Any missing part is set to nul. For historical reasons, the target structure
176 * is always initialized, even if parsing the URI string fails.
178 * On error, errno is set to one of the following value:
179 * - ENOMEM in case of memory allocation failure,
180 * - EINVAL in case of syntax error in the input string.
182 * \bug The URI fragment is discarded if present.
184 * \note This function allocates memory. vlc_UrlClean() must be used free
185 * associated the allocations, even if the function fails.
187 * \param url structure of URL parts [OUT]
188 * \param str nul-terminated URL string to split
189 * \retval 0 success
190 * \retval -1 failure
192 VLC_API int vlc_UrlParse(vlc_url_t *url, const char *str);
195 * Releases resources allocated by vlc_UrlParse().
197 VLC_API void vlc_UrlClean(vlc_url_t *);
199 /** @} */
201 #endif