1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module glib.URI;
26 
27 private import glib.ErrorG;
28 private import glib.GException;
29 private import glib.Str;
30 private import gtkc.glib;
31 public  import gtkc.glibtypes;
32 
33 
34 /** */
35 public struct URI
36 {
37 
38 	/**
39 	 * Converts an escaped ASCII-encoded URI to a local filename in the
40 	 * encoding used for filenames.
41 	 *
42 	 * Params:
43 	 *     uri = a uri describing a filename (escaped, encoded in ASCII).
44 	 *     hostname = Location to store hostname for the URI, or %NULL.
45 	 *         If there is no hostname in the URI, %NULL will be
46 	 *         stored in this location.
47 	 *
48 	 * Return: a newly-allocated string holding
49 	 *     the resulting filename, or %NULL on an error.
50 	 *
51 	 * Throws: GException on failure.
52 	 */
53 	public static string filenameFromUri(string uri, out string hostname)
54 	{
55 		char* outhostname = null;
56 		GError* err = null;
57 		
58 		auto p = g_filename_from_uri(Str.toStringz(uri), &outhostname, &err);
59 		
60 		if (err !is null)
61 		{
62 			throw new GException( new ErrorG(err) );
63 		}
64 		
65 		hostname = Str.toString(outhostname);
66 		
67 		return Str.toString(p);
68 	}
69 
70 	/**
71 	 * Converts an absolute filename to an escaped ASCII-encoded URI, with the path
72 	 * component following Section 3.3. of RFC 2396.
73 	 *
74 	 * Params:
75 	 *     filename = an absolute filename specified in the GLib file name encoding,
76 	 *         which is the on-disk file name bytes on Unix, and UTF-8 on
77 	 *         Windows
78 	 *     hostname = A UTF-8 encoded hostname, or %NULL for none.
79 	 *
80 	 * Return: a newly-allocated string holding the resulting
81 	 *     URI, or %NULL on an error.
82 	 *
83 	 * Throws: GException on failure.
84 	 */
85 	public static string filenameToUri(string filename, string hostname)
86 	{
87 		GError* err = null;
88 		
89 		auto p = g_filename_to_uri(Str.toStringz(filename), Str.toStringz(hostname), &err);
90 		
91 		if (err !is null)
92 		{
93 			throw new GException( new ErrorG(err) );
94 		}
95 		
96 		return Str.toString(p);
97 	}
98 
99 	/**
100 	 * Escapes a string for use in a URI.
101 	 *
102 	 * Normally all characters that are not "unreserved" (i.e. ASCII alphanumerical
103 	 * characters plus dash, dot, underscore and tilde) are escaped.
104 	 * But if you specify characters in @reserved_chars_allowed they are not
105 	 * escaped. This is useful for the "reserved" characters in the URI
106 	 * specification, since those are allowed unescaped in some portions of
107 	 * a URI.
108 	 *
109 	 * Params:
110 	 *     unescaped = the unescaped input string.
111 	 *     reservedCharsAllowed = a string of reserved characters that
112 	 *         are allowed to be used, or %NULL.
113 	 *     allowUtf8 = %TRUE if the result can include UTF-8 characters.
114 	 *
115 	 * Return: an escaped version of @unescaped. The returned string should be
116 	 *     freed when no longer needed.
117 	 *
118 	 * Since: 2.16
119 	 */
120 	public static string uriEscapeString(string unescaped, string reservedCharsAllowed, bool allowUtf8)
121 	{
122 		return Str.toString(g_uri_escape_string(Str.toStringz(unescaped), Str.toStringz(reservedCharsAllowed), allowUtf8));
123 	}
124 
125 	/**
126 	 * Splits an URI list conforming to the text/uri-list
127 	 * mime type defined in RFC 2483 into individual URIs,
128 	 * discarding any comments. The URIs are not validated.
129 	 *
130 	 * Params:
131 	 *     uriList = an URI list
132 	 *
133 	 * Return: a newly allocated %NULL-terminated list
134 	 *     of strings holding the individual URIs. The array should be freed
135 	 *     with g_strfreev().
136 	 *
137 	 * Since: 2.6
138 	 */
139 	public static string[] uriListExtractUris(string uriList)
140 	{
141 		return Str.toStringArray(g_uri_list_extract_uris(Str.toStringz(uriList)));
142 	}
143 
144 	/**
145 	 * Gets the scheme portion of a URI string. RFC 3986 decodes the scheme as:
146 	 * |[
147 	 * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
148 	 * ]|
149 	 * Common schemes include "file", "http", "svn+ssh", etc.
150 	 *
151 	 * Params:
152 	 *     uri = a valid URI.
153 	 *
154 	 * Return: The "Scheme" component of the URI, or %NULL on error.
155 	 *     The returned string should be freed when no longer needed.
156 	 *
157 	 * Since: 2.16
158 	 */
159 	public static string uriParseScheme(string uri)
160 	{
161 		return Str.toString(g_uri_parse_scheme(Str.toStringz(uri)));
162 	}
163 
164 	/**
165 	 * Unescapes a segment of an escaped string.
166 	 *
167 	 * If any of the characters in @illegal_characters or the character zero appears
168 	 * as an escaped character in @escaped_string then that is an error and %NULL
169 	 * will be returned. This is useful it you want to avoid for instance having a
170 	 * slash being expanded in an escaped path element, which might confuse pathname
171 	 * handling.
172 	 *
173 	 * Params:
174 	 *     escapedString = A string, may be %NULL
175 	 *     escapedStringEnd = Pointer to end of @escaped_string, may be %NULL
176 	 *     illegalCharacters = An optional string of illegal characters not to be allowed, may be %NULL
177 	 *
178 	 * Return: an unescaped version of @escaped_string or %NULL on error.
179 	 *     The returned string should be freed when no longer needed.  As a
180 	 *     special case if %NULL is given for @escaped_string, this function
181 	 *     will return %NULL.
182 	 *
183 	 * Since: 2.16
184 	 */
185 	public static string uriUnescapeSegment(string escapedString, string escapedStringEnd, string illegalCharacters)
186 	{
187 		return Str.toString(g_uri_unescape_segment(Str.toStringz(escapedString), Str.toStringz(escapedStringEnd), Str.toStringz(illegalCharacters)));
188 	}
189 
190 	/**
191 	 * Unescapes a whole escaped string.
192 	 *
193 	 * If any of the characters in @illegal_characters or the character zero appears
194 	 * as an escaped character in @escaped_string then that is an error and %NULL
195 	 * will be returned. This is useful it you want to avoid for instance having a
196 	 * slash being expanded in an escaped path element, which might confuse pathname
197 	 * handling.
198 	 *
199 	 * Params:
200 	 *     escapedString = an escaped string to be unescaped.
201 	 *     illegalCharacters = a string of illegal characters not to be
202 	 *         allowed, or %NULL.
203 	 *
204 	 * Return: an unescaped version of @escaped_string. The returned string
205 	 *     should be freed when no longer needed.
206 	 *
207 	 * Since: 2.16
208 	 */
209 	public static string uriUnescapeString(string escapedString, string illegalCharacters)
210 	{
211 		return Str.toString(g_uri_unescape_string(Str.toStringz(escapedString), Str.toStringz(illegalCharacters)));
212 	}
213 }