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.
45 	 *         If there is no hostname in the URI, %NULL will be
46 	 *         stored in this location.
47 	 *
48 	 * Returns: 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 retStr = 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 		scope(exit) Str.freeString(retStr);
68 		return Str.toString(retStr);
69 	}
70 
71 	/**
72 	 * Converts an absolute filename to an escaped ASCII-encoded URI, with the path
73 	 * component following Section 3.3. of RFC 2396.
74 	 *
75 	 * Params:
76 	 *     filename = an absolute filename specified in the GLib file
77 	 *         name encoding, which is the on-disk file name bytes on Unix, and UTF-8
78 	 *         on Windows
79 	 *     hostname = A UTF-8 encoded hostname, or %NULL for none.
80 	 *
81 	 * Returns: a newly-allocated string holding the resulting
82 	 *     URI, or %NULL on an error.
83 	 *
84 	 * Throws: GException on failure.
85 	 */
86 	public static string filenameToUri(string filename, string hostname)
87 	{
88 		GError* err = null;
89 		
90 		auto retStr = g_filename_to_uri(Str.toStringz(filename), Str.toStringz(hostname), &err);
91 		
92 		if (err !is null)
93 		{
94 			throw new GException( new ErrorG(err) );
95 		}
96 		
97 		scope(exit) Str.freeString(retStr);
98 		return Str.toString(retStr);
99 	}
100 
101 	/**
102 	 * Escapes a string for use in a URI.
103 	 *
104 	 * Normally all characters that are not "unreserved" (i.e. ASCII alphanumerical
105 	 * characters plus dash, dot, underscore and tilde) are escaped.
106 	 * But if you specify characters in @reserved_chars_allowed they are not
107 	 * escaped. This is useful for the "reserved" characters in the URI
108 	 * specification, since those are allowed unescaped in some portions of
109 	 * a URI.
110 	 *
111 	 * Params:
112 	 *     unescaped = the unescaped input string.
113 	 *     reservedCharsAllowed = a string of reserved characters that
114 	 *         are allowed to be used, or %NULL.
115 	 *     allowUtf8 = %TRUE if the result can include UTF-8 characters.
116 	 *
117 	 * Returns: an escaped version of @unescaped. The returned string should be
118 	 *     freed when no longer needed.
119 	 *
120 	 * Since: 2.16
121 	 */
122 	public static string uriEscapeString(string unescaped, string reservedCharsAllowed, bool allowUtf8)
123 	{
124 		auto retStr = g_uri_escape_string(Str.toStringz(unescaped), Str.toStringz(reservedCharsAllowed), allowUtf8);
125 		
126 		scope(exit) Str.freeString(retStr);
127 		return Str.toString(retStr);
128 	}
129 
130 	/**
131 	 * Splits an URI list conforming to the text/uri-list
132 	 * mime type defined in RFC 2483 into individual URIs,
133 	 * discarding any comments. The URIs are not validated.
134 	 *
135 	 * Params:
136 	 *     uriList = an URI list
137 	 *
138 	 * Returns: a newly allocated %NULL-terminated list
139 	 *     of strings holding the individual URIs. The array should be freed
140 	 *     with g_strfreev().
141 	 *
142 	 * Since: 2.6
143 	 */
144 	public static string[] uriListExtractUris(string uriList)
145 	{
146 		auto retStr = g_uri_list_extract_uris(Str.toStringz(uriList));
147 		
148 		scope(exit) Str.freeStringArray(retStr);
149 		return Str.toStringArray(retStr);
150 	}
151 
152 	/**
153 	 * Gets the scheme portion of a URI string. RFC 3986 decodes the scheme as:
154 	 * |[
155 	 * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
156 	 * ]|
157 	 * Common schemes include "file", "http", "svn+ssh", etc.
158 	 *
159 	 * Params:
160 	 *     uri = a valid URI.
161 	 *
162 	 * Returns: The "Scheme" component of the URI, or %NULL on error.
163 	 *     The returned string should be freed when no longer needed.
164 	 *
165 	 * Since: 2.16
166 	 */
167 	public static string uriParseScheme(string uri)
168 	{
169 		auto retStr = g_uri_parse_scheme(Str.toStringz(uri));
170 		
171 		scope(exit) Str.freeString(retStr);
172 		return Str.toString(retStr);
173 	}
174 
175 	/**
176 	 * Unescapes a segment of an escaped string.
177 	 *
178 	 * If any of the characters in @illegal_characters or the character zero appears
179 	 * as an escaped character in @escaped_string then that is an error and %NULL
180 	 * will be returned. This is useful it you want to avoid for instance having a
181 	 * slash being expanded in an escaped path element, which might confuse pathname
182 	 * handling.
183 	 *
184 	 * Params:
185 	 *     escapedString = A string, may be %NULL
186 	 *     escapedStringEnd = Pointer to end of @escaped_string, may be %NULL
187 	 *     illegalCharacters = An optional string of illegal characters not to be allowed, may be %NULL
188 	 *
189 	 * Returns: an unescaped version of @escaped_string or %NULL on error.
190 	 *     The returned string should be freed when no longer needed.  As a
191 	 *     special case if %NULL is given for @escaped_string, this function
192 	 *     will return %NULL.
193 	 *
194 	 * Since: 2.16
195 	 */
196 	public static string uriUnescapeSegment(string escapedString, string escapedStringEnd, string illegalCharacters)
197 	{
198 		auto retStr = g_uri_unescape_segment(Str.toStringz(escapedString), Str.toStringz(escapedStringEnd), Str.toStringz(illegalCharacters));
199 		
200 		scope(exit) Str.freeString(retStr);
201 		return Str.toString(retStr);
202 	}
203 
204 	/**
205 	 * Unescapes a whole escaped string.
206 	 *
207 	 * If any of the characters in @illegal_characters or the character zero appears
208 	 * as an escaped character in @escaped_string then that is an error and %NULL
209 	 * will be returned. This is useful it you want to avoid for instance having a
210 	 * slash being expanded in an escaped path element, which might confuse pathname
211 	 * handling.
212 	 *
213 	 * Params:
214 	 *     escapedString = an escaped string to be unescaped.
215 	 *     illegalCharacters = a string of illegal characters not to be
216 	 *         allowed, or %NULL.
217 	 *
218 	 * Returns: an unescaped version of @escaped_string. The returned string
219 	 *     should be freed when no longer needed.
220 	 *
221 	 * Since: 2.16
222 	 */
223 	public static string uriUnescapeString(string escapedString, string illegalCharacters)
224 	{
225 		auto retStr = g_uri_unescape_string(Str.toStringz(escapedString), Str.toStringz(illegalCharacters));
226 		
227 		scope(exit) Str.freeString(retStr);
228 		return Str.toString(retStr);
229 	}
230 }