1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>URI Functions</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
7 <link rel="home" href="index.html" title="GLib Reference Manual">
8 <link rel="up" href="glib-utilities.html" title="GLib Utilities">
9 <link rel="prev" href="glib-File-Utilities.html" title="File Utilities">
10 <link rel="next" href="glib-Hostname-Utilities.html" title="Hostname Utilities">
11 <meta name="generator" content="GTK-Doc V1.18 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
14 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
15 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
17 <td><a accesskey="p" href="glib-File-Utilities.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
18 <td><a accesskey="u" href="glib-utilities.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
19 <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
20 <th width="100%" align="center">GLib Reference Manual</th>
21 <td><a accesskey="n" href="glib-Hostname-Utilities.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
23 <tr><td colspan="5" class="shortcuts">
24 <a href="#glib-URI-Functions.synopsis" class="shortcut">Top</a>
26 <a href="#glib-URI-Functions.description" class="shortcut">Description</a>
29 <div class="refentry">
30 <a name="glib-URI-Functions"></a><div class="titlepage"></div>
31 <div class="refnamediv"><table width="100%"><tr>
33 <h2><span class="refentrytitle"><a name="glib-URI-Functions.top_of_page"></a>URI Functions</span></h2>
34 <p>URI Functions — manipulating URIs</p>
36 <td valign="top" align="right"></td>
38 <div class="refsynopsisdiv">
39 <a name="glib-URI-Functions.synopsis"></a><h2>Synopsis</h2>
40 <pre class="synopsis">
41 #include <glib.h>
43 #define <a class="link" href="glib-URI-Functions.html#G-URI-RESERVED-CHARS-ALLOWED-IN-PATH:CAPS" title="G_URI_RESERVED_CHARS_ALLOWED_IN_PATH">G_URI_RESERVED_CHARS_ALLOWED_IN_PATH</a>
44 #define <a class="link" href="glib-URI-Functions.html#G-URI-RESERVED-CHARS-ALLOWED-IN-PATH-ELEMENT:CAPS" title="G_URI_RESERVED_CHARS_ALLOWED_IN_PATH_ELEMENT">G_URI_RESERVED_CHARS_ALLOWED_IN_PATH_ELEMENT</a>
45 #define <a class="link" href="glib-URI-Functions.html#G-URI-RESERVED-CHARS-ALLOWED-IN-USERINFO:CAPS" title="G_URI_RESERVED_CHARS_ALLOWED_IN_USERINFO">G_URI_RESERVED_CHARS_ALLOWED_IN_USERINFO</a>
46 #define <a class="link" href="glib-URI-Functions.html#G-URI-RESERVED-CHARS-GENERIC-DELIMITERS:CAPS" title="G_URI_RESERVED_CHARS_GENERIC_DELIMITERS">G_URI_RESERVED_CHARS_GENERIC_DELIMITERS</a>
47 #define <a class="link" href="glib-URI-Functions.html#G-URI-RESERVED-CHARS-SUBCOMPONENT-DELIMITERS:CAPS" title="G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS">G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS</a>
48 <span class="returnvalue">char</span> * <a class="link" href="glib-URI-Functions.html#g-uri-parse-scheme" title="g_uri_parse_scheme ()">g_uri_parse_scheme</a> (<em class="parameter"><code>const <span class="type">char</span> *uri</code></em>);
49 <span class="returnvalue">char</span> * <a class="link" href="glib-URI-Functions.html#g-uri-escape-string" title="g_uri_escape_string ()">g_uri_escape_string</a> (<em class="parameter"><code>const <span class="type">char</span> *unescaped</code></em>,
50 <em class="parameter"><code>const <span class="type">char</span> *reserved_chars_allowed</code></em>,
51 <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="type">gboolean</span></a> allow_utf8</code></em>);
52 <span class="returnvalue">char</span> * <a class="link" href="glib-URI-Functions.html#g-uri-unescape-string" title="g_uri_unescape_string ()">g_uri_unescape_string</a> (<em class="parameter"><code>const <span class="type">char</span> *escaped_string</code></em>,
53 <em class="parameter"><code>const <span class="type">char</span> *illegal_characters</code></em>);
54 <span class="returnvalue">char</span> * <a class="link" href="glib-URI-Functions.html#g-uri-unescape-segment" title="g_uri_unescape_segment ()">g_uri_unescape_segment</a> (<em class="parameter"><code>const <span class="type">char</span> *escaped_string</code></em>,
55 <em class="parameter"><code>const <span class="type">char</span> *escaped_string_end</code></em>,
56 <em class="parameter"><code>const <span class="type">char</span> *illegal_characters</code></em>);
57 <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> ** <a class="link" href="glib-URI-Functions.html#g-uri-list-extract-uris" title="g_uri_list_extract_uris ()">g_uri_list_extract_uris</a> (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *uri_list</code></em>);
58 <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * <a class="link" href="glib-URI-Functions.html#g-filename-from-uri" title="g_filename_from_uri ()">g_filename_from_uri</a> (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *uri</code></em>,
59 <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> **hostname</code></em>,
60 <em class="parameter"><code><a class="link" href="glib-Error-Reporting.html#GError" title="struct GError"><span class="type">GError</span></a> **error</code></em>);
61 <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * <a class="link" href="glib-URI-Functions.html#g-filename-to-uri" title="g_filename_to_uri ()">g_filename_to_uri</a> (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *filename</code></em>,
62 <em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *hostname</code></em>,
63 <em class="parameter"><code><a class="link" href="glib-Error-Reporting.html#GError" title="struct GError"><span class="type">GError</span></a> **error</code></em>);
66 <div class="refsect1">
67 <a name="glib-URI-Functions.description"></a><h2>Description</h2>
69 Functions for manipulating Universal Resource Identifiers (URIs) as
70 defined by <a class="ulink" href="http://www.ietf.org/rfc/rfc3986.txt" target="_top">
71 RFC 3986</a>. It is highly recommended that you have read and
72 understand RFC 3986 for understanding this API.
75 <div class="refsect1">
76 <a name="glib-URI-Functions.details"></a><h2>Details</h2>
77 <div class="refsect2">
78 <a name="G-URI-RESERVED-CHARS-ALLOWED-IN-PATH:CAPS"></a><h3>G_URI_RESERVED_CHARS_ALLOWED_IN_PATH</h3>
79 <pre class="programlisting">#define G_URI_RESERVED_CHARS_ALLOWED_IN_PATH G_URI_RESERVED_CHARS_ALLOWED_IN_PATH_ELEMENT "/"
82 Allowed characters in a path. Includes "!$&'()*+,;=:@/".
86 <div class="refsect2">
87 <a name="G-URI-RESERVED-CHARS-ALLOWED-IN-PATH-ELEMENT:CAPS"></a><h3>G_URI_RESERVED_CHARS_ALLOWED_IN_PATH_ELEMENT</h3>
88 <pre class="programlisting">#define G_URI_RESERVED_CHARS_ALLOWED_IN_PATH_ELEMENT G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS ":@"
91 Allowed characters in path elements. Includes "!$&'()*+,;=:@".
95 <div class="refsect2">
96 <a name="G-URI-RESERVED-CHARS-ALLOWED-IN-USERINFO:CAPS"></a><h3>G_URI_RESERVED_CHARS_ALLOWED_IN_USERINFO</h3>
97 <pre class="programlisting">#define G_URI_RESERVED_CHARS_ALLOWED_IN_USERINFO G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS ":"
100 Allowed characters in userinfo as defined in RFC 3986. Includes "!$&'()*+,;=:".
104 <div class="refsect2">
105 <a name="G-URI-RESERVED-CHARS-GENERIC-DELIMITERS:CAPS"></a><h3>G_URI_RESERVED_CHARS_GENERIC_DELIMITERS</h3>
106 <pre class="programlisting">#define G_URI_RESERVED_CHARS_GENERIC_DELIMITERS ":/?#[]@"
109 Generic delimiters characters as defined in RFC 3986. Includes ":/?#[]@".
113 <div class="refsect2">
114 <a name="G-URI-RESERVED-CHARS-SUBCOMPONENT-DELIMITERS:CAPS"></a><h3>G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS</h3>
115 <pre class="programlisting">#define G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS "!$&'()*+,;="
118 Subcomponent delimiter characters as defined in RFC 3986. Includes "!$&'()*+,;=".
122 <div class="refsect2">
123 <a name="g-uri-parse-scheme"></a><h3>g_uri_parse_scheme ()</h3>
124 <pre class="programlisting"><span class="returnvalue">char</span> * g_uri_parse_scheme (<em class="parameter"><code>const <span class="type">char</span> *uri</code></em>);</pre>
126 Gets the scheme portion of a URI string. RFC 3986 decodes the scheme as:
128 <pre class="programlisting">
129 URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
132 Common schemes include "file", "http", "svn+ssh", etc.
134 <div class="variablelist"><table border="0">
135 <col align="left" valign="top">
138 <td><p><span class="term"><em class="parameter"><code>uri</code></em> :</span></p></td>
139 <td>a valid URI.</td>
142 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
143 <td>The "Scheme" component of the URI, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> on error.
144 The returned string should be freed when no longer needed.</td>
148 <p class="since">Since 2.16</p>
151 <div class="refsect2">
152 <a name="g-uri-escape-string"></a><h3>g_uri_escape_string ()</h3>
153 <pre class="programlisting"><span class="returnvalue">char</span> * g_uri_escape_string (<em class="parameter"><code>const <span class="type">char</span> *unescaped</code></em>,
154 <em class="parameter"><code>const <span class="type">char</span> *reserved_chars_allowed</code></em>,
155 <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="type">gboolean</span></a> allow_utf8</code></em>);</pre>
157 Escapes a string for use in a URI.
160 Normally all characters that are not "unreserved" (i.e. ASCII alphanumerical
161 characters plus dash, dot, underscore and tilde) are escaped.
162 But if you specify characters in <em class="parameter"><code>reserved_chars_allowed</code></em> they are not
163 escaped. This is useful for the "reserved" characters in the URI
164 specification, since those are allowed unescaped in some portions of
167 <div class="variablelist"><table border="0">
168 <col align="left" valign="top">
171 <td><p><span class="term"><em class="parameter"><code>unescaped</code></em> :</span></p></td>
172 <td>the unescaped input string.</td>
175 <td><p><span class="term"><em class="parameter"><code>reserved_chars_allowed</code></em> :</span></p></td>
176 <td>a string of reserved characters that are
177 allowed to be used, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>.</td>
180 <td><p><span class="term"><em class="parameter"><code>allow_utf8</code></em> :</span></p></td>
182 <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if the result can include UTF-8 characters.</td>
185 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
186 <td>an escaped version of <em class="parameter"><code>unescaped</code></em>. The returned string should be
187 freed when no longer needed.</td>
191 <p class="since">Since 2.16</p>
194 <div class="refsect2">
195 <a name="g-uri-unescape-string"></a><h3>g_uri_unescape_string ()</h3>
196 <pre class="programlisting"><span class="returnvalue">char</span> * g_uri_unescape_string (<em class="parameter"><code>const <span class="type">char</span> *escaped_string</code></em>,
197 <em class="parameter"><code>const <span class="type">char</span> *illegal_characters</code></em>);</pre>
199 Unescapes a whole escaped string.
202 If any of the characters in <em class="parameter"><code>illegal_characters</code></em> or the character zero appears
203 as an escaped character in <em class="parameter"><code>escaped_string</code></em> then that is an error and <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
204 will be returned. This is useful it you want to avoid for instance having a
205 slash being expanded in an escaped path element, which might confuse pathname
208 <div class="variablelist"><table border="0">
209 <col align="left" valign="top">
212 <td><p><span class="term"><em class="parameter"><code>escaped_string</code></em> :</span></p></td>
213 <td>an escaped string to be unescaped.</td>
216 <td><p><span class="term"><em class="parameter"><code>illegal_characters</code></em> :</span></p></td>
217 <td>an optional string of illegal characters not to be allowed.</td>
220 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
221 <td>an unescaped version of <em class="parameter"><code>escaped_string</code></em>. The returned string
222 should be freed when no longer needed.</td>
226 <p class="since">Since 2.16</p>
229 <div class="refsect2">
230 <a name="g-uri-unescape-segment"></a><h3>g_uri_unescape_segment ()</h3>
231 <pre class="programlisting"><span class="returnvalue">char</span> * g_uri_unescape_segment (<em class="parameter"><code>const <span class="type">char</span> *escaped_string</code></em>,
232 <em class="parameter"><code>const <span class="type">char</span> *escaped_string_end</code></em>,
233 <em class="parameter"><code>const <span class="type">char</span> *illegal_characters</code></em>);</pre>
235 Unescapes a segment of an escaped string.
238 If any of the characters in <em class="parameter"><code>illegal_characters</code></em> or the character zero appears
239 as an escaped character in <em class="parameter"><code>escaped_string</code></em> then that is an error and <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
240 will be returned. This is useful it you want to avoid for instance having a
241 slash being expanded in an escaped path element, which might confuse pathname
244 <div class="variablelist"><table border="0">
245 <col align="left" valign="top">
248 <td><p><span class="term"><em class="parameter"><code>escaped_string</code></em> :</span></p></td>
249 <td>A string, may be <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
253 <td><p><span class="term"><em class="parameter"><code>escaped_string_end</code></em> :</span></p></td>
254 <td>Pointer to end of <em class="parameter"><code>escaped_string</code></em>, may be <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
258 <td><p><span class="term"><em class="parameter"><code>illegal_characters</code></em> :</span></p></td>
259 <td>An optional string of illegal characters not to be allowed, may be <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
263 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
264 <td>an unescaped version of <em class="parameter"><code>escaped_string</code></em> or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> on error.
265 The returned string should be freed when no longer needed. As a
266 special case if <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> is given for <em class="parameter"><code>escaped_string</code></em>, this function
267 will return <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>.</td>
271 <p class="since">Since 2.16</p>
274 <div class="refsect2">
275 <a name="g-uri-list-extract-uris"></a><h3>g_uri_list_extract_uris ()</h3>
276 <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> ** g_uri_list_extract_uris (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *uri_list</code></em>);</pre>
278 Splits an URI list conforming to the text/uri-list
279 mime type defined in RFC 2483 into individual URIs,
280 discarding any comments. The URIs are not validated.
282 <div class="variablelist"><table border="0">
283 <col align="left" valign="top">
286 <td><p><span class="term"><em class="parameter"><code>uri_list</code></em> :</span></p></td>
290 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
291 <td>a newly allocated <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>-terminated list of
292 strings holding the individual URIs. The array should
293 be freed with <a class="link" href="glib-String-Utility-Functions.html#g-strfreev" title="g_strfreev ()"><code class="function">g_strfreev()</code></a>.</td>
297 <p class="since">Since 2.6</p>
300 <div class="refsect2">
301 <a name="g-filename-from-uri"></a><h3>g_filename_from_uri ()</h3>
302 <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * g_filename_from_uri (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *uri</code></em>,
303 <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> **hostname</code></em>,
304 <em class="parameter"><code><a class="link" href="glib-Error-Reporting.html#GError" title="struct GError"><span class="type">GError</span></a> **error</code></em>);</pre>
306 Converts an escaped ASCII-encoded URI to a local filename in the
307 encoding used for filenames.
309 <div class="variablelist"><table border="0">
310 <col align="left" valign="top">
313 <td><p><span class="term"><em class="parameter"><code>uri</code></em> :</span></p></td>
314 <td>a uri describing a filename (escaped, encoded in ASCII).</td>
317 <td><p><span class="term"><em class="parameter"><code>hostname</code></em> :</span></p></td>
318 <td>Location to store hostname for the URI, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>.
319 If there is no hostname in the URI, <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> will be
320 stored in this location. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
324 <td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
325 <td>location to store the error occurring, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> to ignore
326 errors. Any of the errors in <a class="link" href="glib-Character-Set-Conversion.html#GConvertError" title="enum GConvertError"><span class="type">GConvertError</span></a> may occur.</td>
329 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
330 <td>a newly-allocated string holding the resulting
331 filename, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> on an error.</td>
337 <div class="refsect2">
338 <a name="g-filename-to-uri"></a><h3>g_filename_to_uri ()</h3>
339 <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * g_filename_to_uri (<em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *filename</code></em>,
340 <em class="parameter"><code>const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="type">gchar</span></a> *hostname</code></em>,
341 <em class="parameter"><code><a class="link" href="glib-Error-Reporting.html#GError" title="struct GError"><span class="type">GError</span></a> **error</code></em>);</pre>
343 Converts an absolute filename to an escaped ASCII-encoded URI, with the path
344 component following Section 3.3. of RFC 2396.
346 <div class="variablelist"><table border="0">
347 <col align="left" valign="top">
350 <td><p><span class="term"><em class="parameter"><code>filename</code></em> :</span></p></td>
351 <td>an absolute filename specified in the GLib file name encoding,
352 which is the on-disk file name bytes on Unix, and UTF-8 on
356 <td><p><span class="term"><em class="parameter"><code>hostname</code></em> :</span></p></td>
357 <td>A UTF-8 encoded hostname, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> for none. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
361 <td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
362 <td>location to store the error occurring, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> to ignore
363 errors. Any of the errors in <a class="link" href="glib-Character-Set-Conversion.html#GConvertError" title="enum GConvertError"><span class="type">GConvertError</span></a> may occur.</td>
366 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
367 <td>a newly-allocated string holding the resulting
368 URI, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> on an error.</td>
377 Generated by GTK-Doc V1.18</div>