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 public struct URI
35 {
36 	/**
37 	 */
38 
39 	/**
40 	 * Converts an escaped ASCII-encoded URI to a local filename in the
41 	 * encoding used for filenames.
42 	 *
43 	 * Params:
44 	 *     uri = a uri describing a filename (escaped, encoded in ASCII).
45 	 *     hostname = Location to store hostname for the URI, or %NULL.
46 	 *         If there is no hostname in the URI, %NULL will be
47 	 *         stored in this location.
48 	 *
49 	 * Return: a newly-allocated string holding
50 	 *     the resulting filename, or %NULL on an error.
51 	 *
52 	 * Throws: GException on failure.
53 	 */
54 	public static string filenameFromUri(string uri, out string hostname)
55 	{
56 		char* outhostname = null;
57 		GError* err = null;
58 		
59 		auto p = g_filename_from_uri(Str.toStringz(uri), &outhostname, &err);
60 		
61 		if (err !is null)
62 		{
63 			throw new GException( new ErrorG(err) );
64 		}
65 		
66 		hostname = Str.toString(outhostname);
67 		
68 		return Str.toString(p);
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 name encoding,
77 	 *         which is the on-disk file name bytes on Unix, and UTF-8 on
78 	 *         Windows
79 	 *     hostname = A UTF-8 encoded hostname, or %NULL for none.
80 	 *
81 	 * Return: 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 p = 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 		return Str.toString(p);
98 	}
99 
100 	/**
101 	 * Escapes a string for use in a URI.
102 	 *
103 	 * Normally all characters that are not "unreserved" (i.e. ASCII alphanumerical
104 	 * characters plus dash, dot, underscore and tilde) are escaped.
105 	 * But if you specify characters in @reserved_chars_allowed they are not
106 	 * escaped. This is useful for the "reserved" characters in the URI
107 	 * specification, since those are allowed unescaped in some portions of
108 	 * a URI.
109 	 *
110 	 * Params:
111 	 *     unescaped = the unescaped input string.
112 	 *     reservedCharsAllowed = a string of reserved characters that
113 	 *         are allowed to be used, or %NULL.
114 	 *     allowUtf8 = %TRUE if the result can include UTF-8 characters.
115 	 *
116 	 * Return: an escaped version of @unescaped. The returned string should be
117 	 *     freed when no longer needed.
118 	 *
119 	 * Since: 2.16
120 	 */
121 	public static string uriEscapeString(string unescaped, string reservedCharsAllowed, bool allowUtf8)
122 	{
123 		return Str.toString(g_uri_escape_string(Str.toStringz(unescaped), Str.toStringz(reservedCharsAllowed), allowUtf8));
124 	}
125 
126 	/**
127 	 * Splits an URI list conforming to the text/uri-list
128 	 * mime type defined in RFC 2483 into individual URIs,
129 	 * discarding any comments. The URIs are not validated.
130 	 *
131 	 * Params:
132 	 *     uriList = an URI list
133 	 *
134 	 * Return: a newly allocated %NULL-terminated list
135 	 *     of strings holding the individual URIs. The array should be freed
136 	 *     with g_strfreev().
137 	 *
138 	 * Since: 2.6
139 	 */
140 	public static string[] uriListExtractUris(string uriList)
141 	{
142 		return Str.toStringArray(g_uri_list_extract_uris(Str.toStringz(uriList)));
143 	}
144 
145 	/**
146 	 * Gets the scheme portion of a URI string. RFC 3986 decodes the scheme as:
147 	 * |[
148 	 * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
149 	 * ]|
150 	 * Common schemes include "file", "http", "svn+ssh", etc.
151 	 *
152 	 * Params:
153 	 *     uri = a valid URI.
154 	 *
155 	 * Return: The "Scheme" component of the URI, or %NULL on error.
156 	 *     The returned string should be freed when no longer needed.
157 	 *
158 	 * Since: 2.16
159 	 */
160 	public static string uriParseScheme(string uri)
161 	{
162 		return Str.toString(g_uri_parse_scheme(Str.toStringz(uri)));
163 	}
164 
165 	/**
166 	 * Unescapes a segment of an escaped string.
167 	 *
168 	 * If any of the characters in @illegal_characters or the character zero appears
169 	 * as an escaped character in @escaped_string then that is an error and %NULL
170 	 * will be returned. This is useful it you want to avoid for instance having a
171 	 * slash being expanded in an escaped path element, which might confuse pathname
172 	 * handling.
173 	 *
174 	 * Params:
175 	 *     escapedString = A string, may be %NULL
176 	 *     escapedStringEnd = Pointer to end of @escaped_string, may be %NULL
177 	 *     illegalCharacters = An optional string of illegal characters not to be allowed, may be %NULL
178 	 *
179 	 * Return: an unescaped version of @escaped_string or %NULL on error.
180 	 *     The returned string should be freed when no longer needed.  As a
181 	 *     special case if %NULL is given for @escaped_string, this function
182 	 *     will return %NULL.
183 	 *
184 	 * Since: 2.16
185 	 */
186 	public static string uriUnescapeSegment(string escapedString, string escapedStringEnd, string illegalCharacters)
187 	{
188 		return Str.toString(g_uri_unescape_segment(Str.toStringz(escapedString), Str.toStringz(escapedStringEnd), Str.toStringz(illegalCharacters)));
189 	}
190 
191 	/**
192 	 * Unescapes a whole escaped string.
193 	 *
194 	 * If any of the characters in @illegal_characters or the character zero appears
195 	 * as an escaped character in @escaped_string then that is an error and %NULL
196 	 * will be returned. This is useful it you want to avoid for instance having a
197 	 * slash being expanded in an escaped path element, which might confuse pathname
198 	 * handling.
199 	 *
200 	 * Params:
201 	 *     escapedString = an escaped string to be unescaped.
202 	 *     illegalCharacters = a string of illegal characters not to be
203 	 *         allowed, or %NULL.
204 	 *
205 	 * Return: an unescaped version of @escaped_string. The returned string
206 	 *     should be freed when no longer needed.
207 	 *
208 	 * Since: 2.16
209 	 */
210 	public static string uriUnescapeString(string escapedString, string illegalCharacters)
211 	{
212 		return Str.toString(g_uri_unescape_string(Str.toStringz(escapedString), Str.toStringz(illegalCharacters)));
213 	}
214 }