glib/auto/uri.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, translate::*, Bytes, Error, UriFlags, UriHideFlags};
6
7crate::wrapper! {
8 /// The `GUri` type and related functions can be used to parse URIs into
9 /// their components, and build valid URIs from individual components.
10 ///
11 /// Since `GUri` only represents absolute URIs, all `GUri`s will have a
12 /// URI scheme, so [`scheme()`][Self::scheme()] will always return a non-`NULL`
13 /// answer. Likewise, by definition, all URIs have a path component, so
14 /// [`path()`][Self::path()] will always return a non-`NULL` string (which may
15 /// be empty).
16 ///
17 /// If the URI string has an
18 /// [‘authority’ component](https://tools.ietf.org/html/rfc3986#section-3) (that
19 /// is, if the scheme is followed by `://` rather than just `:`), then the
20 /// `GUri` will contain a hostname, and possibly a port and ‘userinfo’.
21 /// Additionally, depending on how the `GUri` was constructed/parsed (for example,
22 /// using the `G_URI_FLAGS_HAS_PASSWORD` and `G_URI_FLAGS_HAS_AUTH_PARAMS` flags),
23 /// the userinfo may be split out into a username, password, and
24 /// additional authorization-related parameters.
25 ///
26 /// Normally, the components of a `GUri` will have all `%`-encoded
27 /// characters decoded. However, if you construct/parse a `GUri` with
28 /// `G_URI_FLAGS_ENCODED`, then the `%`-encoding will be preserved instead in
29 /// the userinfo, path, and query fields (and in the host field if also
30 /// created with `G_URI_FLAGS_NON_DNS`). In particular, this is necessary if
31 /// the URI may contain binary data or non-UTF-8 text, or if decoding
32 /// the components might change the interpretation of the URI.
33 ///
34 /// For example, with the encoded flag:
35 ///
36 /// **⚠️ The following code is in c ⚠️**
37 ///
38 /// ```c
39 /// g_autoptr(GUri) uri = g_uri_parse ("http://host/path?query=http%3A%2F%2Fhost%2Fpath%3Fparam%3Dvalue", G_URI_FLAGS_ENCODED, &err);
40 /// g_assert_cmpstr (g_uri_get_query (uri), ==, "query=http%3A%2F%2Fhost%2Fpath%3Fparam%3Dvalue");
41 /// ```
42 ///
43 /// While the default `%`-decoding behaviour would give:
44 ///
45 /// **⚠️ The following code is in c ⚠️**
46 ///
47 /// ```c
48 /// g_autoptr(GUri) uri = g_uri_parse ("http://host/path?query=http%3A%2F%2Fhost%2Fpath%3Fparam%3Dvalue", G_URI_FLAGS_NONE, &err);
49 /// g_assert_cmpstr (g_uri_get_query (uri), ==, "query=http://host/path?param=value");
50 /// ```
51 ///
52 /// During decoding, if an invalid UTF-8 string is encountered, parsing will fail
53 /// with an error indicating the bad string location:
54 ///
55 /// **⚠️ The following code is in c ⚠️**
56 ///
57 /// ```c
58 /// g_autoptr(GUri) uri = g_uri_parse ("http://host/path?query=http%3A%2F%2Fhost%2Fpath%3Fbad%3D%00alue", G_URI_FLAGS_NONE, &err);
59 /// g_assert_error (err, G_URI_ERROR, G_URI_ERROR_BAD_QUERY);
60 /// ```
61 ///
62 /// You should pass `G_URI_FLAGS_ENCODED` or `G_URI_FLAGS_ENCODED_QUERY` if you
63 /// need to handle that case manually. In particular, if the query string
64 /// contains `=` characters that are `%`-encoded, you should let
65 /// `GLib::Uri::parse_params()` do the decoding once of the query.
66 ///
67 /// `GUri` is immutable once constructed, and can safely be accessed from
68 /// multiple threads. Its reference counting is atomic.
69 ///
70 /// Note that the scope of `GUri` is to help manipulate URIs in various applications,
71 /// following [RFC 3986](https://tools.ietf.org/html/rfc3986). In particular,
72 /// it doesn't intend to cover web browser needs, and doesn’t implement the
73 /// [WHATWG URL](https://url.spec.whatwg.org/) standard. No APIs are provided to
74 /// help prevent
75 /// [homograph attacks](https://en.wikipedia.org/wiki/IDN_homograph_attack), so
76 /// `GUri` is not suitable for formatting URIs for display to the user for making
77 /// security-sensitive decisions.
78 ///
79 /// ## Relative and absolute URIs
80 ///
81 /// As defined in [RFC 3986](https://tools.ietf.org/html/rfc3986#section-4), the
82 /// hierarchical nature of URIs means that they can either be ‘relative
83 /// references’ (sometimes referred to as ‘relative URIs’) or ‘URIs’ (for
84 /// clarity, ‘URIs’ are referred to in this documentation as
85 /// ‘absolute URIs’ — although
86 /// [in contrast to RFC 3986](https://tools.ietf.org/html/rfc3986#section-4.3),
87 /// fragment identifiers are always allowed).
88 ///
89 /// Relative references have one or more components of the URI missing. In
90 /// particular, they have no scheme. Any other component, such as hostname,
91 /// query, etc. may be missing, apart from a path, which has to be specified (but
92 /// may be empty). The path may be relative, starting with `./` rather than `/`.
93 ///
94 /// For example, a valid relative reference is `./path?query`,
95 /// `/?query#fragment` or `//example.com`.
96 ///
97 /// Absolute URIs have a scheme specified. Any other components of the URI which
98 /// are missing are specified as explicitly unset in the URI, rather than being
99 /// resolved relative to a base URI using [`parse_relative()`][Self::parse_relative()].
100 ///
101 /// For example, a valid absolute URI is `file:///home/bob` or
102 /// `https://search.com?query=string`.
103 ///
104 /// A `GUri` instance is always an absolute URI. A string may be an absolute URI
105 /// or a relative reference; see the documentation for individual functions as to
106 /// what forms they accept.
107 ///
108 /// ## Parsing URIs
109 ///
110 /// The most minimalist APIs for parsing URIs are [`split()`][Self::split()] and
111 /// [`split_with_user()`][Self::split_with_user()]. These split a URI into its component
112 /// parts, and return the parts; the difference between the two is that
113 /// [`split()`][Self::split()] treats the ‘userinfo’ component of the URI as a
114 /// single element, while [`split_with_user()`][Self::split_with_user()] can (depending on the
115 /// [`UriFlags`][crate::UriFlags] you pass) treat it as containing a username, password,
116 /// and authentication parameters. Alternatively, [`split_network()`][Self::split_network()]
117 /// can be used when you are only interested in the components that are
118 /// needed to initiate a network connection to the service (scheme,
119 /// host, and port).
120 ///
121 /// [`parse()`][Self::parse()] is similar to [`split()`][Self::split()], but instead of
122 /// returning individual strings, it returns a `GUri` structure (and it requires
123 /// that the URI be an absolute URI).
124 ///
125 /// [`resolve_relative()`][Self::resolve_relative()] and [`parse_relative()`][Self::parse_relative()] allow
126 /// you to resolve a relative URI relative to a base URI.
127 /// [`resolve_relative()`][Self::resolve_relative()] takes two strings and returns a string,
128 /// and [`parse_relative()`][Self::parse_relative()] takes a `GUri` and a string and returns a
129 /// `GUri`.
130 ///
131 /// All of the parsing functions take a [`UriFlags`][crate::UriFlags] argument describing
132 /// exactly how to parse the URI; see the documentation for that type
133 /// for more details on the specific flags that you can pass. If you
134 /// need to choose different flags based on the type of URI, you can
135 /// use [`peek_scheme()`][Self::peek_scheme()] on the URI string to check the scheme
136 /// first, and use that to decide what flags to parse it with.
137 ///
138 /// For example, you might want to use `G_URI_PARAMS_WWW_FORM` when parsing the
139 /// params for a web URI, so compare the result of [`peek_scheme()`][Self::peek_scheme()]
140 /// against `http` and `https`.
141 ///
142 /// ## Building URIs
143 ///
144 /// [`join()`][Self::join()] and [`join_with_user()`][Self::join_with_user()] can be used to construct
145 /// valid URI strings from a set of component strings. They are the
146 /// inverse of [`split()`][Self::split()] and [`split_with_user()`][Self::split_with_user()].
147 ///
148 /// Similarly, [`build()`][Self::build()] and [`build_with_user()`][Self::build_with_user()] can be
149 /// used to construct a `GUri` from a set of component strings.
150 ///
151 /// As with the parsing functions, the building functions take a
152 /// [`UriFlags`][crate::UriFlags] argument. In particular, it is important to keep in mind
153 /// whether the URI components you are using are already `%`-encoded. If so,
154 /// you must pass the `G_URI_FLAGS_ENCODED` flag.
155 ///
156 /// ## `file://` URIs
157 ///
158 /// Note that Windows and Unix both define special rules for parsing
159 /// `file://` URIs (involving non-UTF-8 character sets on Unix, and the
160 /// interpretation of path separators on Windows). `GUri` does not
161 /// implement these rules. Use [`filename_from_uri()`][crate::filename_from_uri()] and
162 /// [`filename_to_uri()`][crate::filename_to_uri()] if you want to properly convert between
163 /// `file://` URIs and local filenames.
164 ///
165 /// ## URI Equality
166 ///
167 /// Note that there is no `g_uri_equal ()` function, because comparing
168 /// URIs usefully requires scheme-specific knowledge that `GUri` does
169 /// not have. `GUri` can help with normalization if you use the various
170 /// encoded [`UriFlags`][crate::UriFlags] as well as `G_URI_FLAGS_SCHEME_NORMALIZE`
171 /// however it is not comprehensive.
172 /// For example, `data:,foo` and `data:;base64,Zm9v` resolve to the same
173 /// thing according to the `data:` URI specification which GLib does not
174 /// handle.
175 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
176 pub struct Uri(Shared<ffi::GUri>);
177
178 match fn {
179 ref => |ptr| ffi::g_uri_ref(ptr),
180 unref => |ptr| ffi::g_uri_unref(ptr),
181 type_ => || ffi::g_uri_get_type(),
182 }
183}
184
185impl Uri {
186 /// Gets @self's authentication parameters, which may contain
187 /// `%`-encoding, depending on the flags with which @self was created.
188 /// (If @self was not created with [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS] then this will
189 /// be [`None`].)
190 ///
191 /// Depending on the URI scheme, g_uri_parse_params() may be useful for
192 /// further parsing this information.
193 ///
194 /// # Returns
195 ///
196 /// @self's authentication parameters.
197 #[doc(alias = "g_uri_get_auth_params")]
198 #[doc(alias = "get_auth_params")]
199 pub fn auth_params(&self) -> Option<crate::GString> {
200 unsafe { from_glib_none(ffi::g_uri_get_auth_params(self.to_glib_none().0)) }
201 }
202
203 /// Gets @self's flags set upon construction.
204 ///
205 /// # Returns
206 ///
207 /// @self's flags.
208 #[doc(alias = "g_uri_get_flags")]
209 #[doc(alias = "get_flags")]
210 pub fn flags(&self) -> UriFlags {
211 unsafe { from_glib(ffi::g_uri_get_flags(self.to_glib_none().0)) }
212 }
213
214 /// Gets @self's fragment, which may contain `%`-encoding, depending on
215 /// the flags with which @self was created.
216 ///
217 /// # Returns
218 ///
219 /// @self's fragment.
220 #[doc(alias = "g_uri_get_fragment")]
221 #[doc(alias = "get_fragment")]
222 pub fn fragment(&self) -> Option<crate::GString> {
223 unsafe { from_glib_none(ffi::g_uri_get_fragment(self.to_glib_none().0)) }
224 }
225
226 /// Gets @self's host. This will never have `%`-encoded characters,
227 /// unless it is non-UTF-8 (which can only be the case if @self was
228 /// created with [`UriFlags::NON_DNS`][crate::UriFlags::NON_DNS]).
229 ///
230 /// If @self contained an IPv6 address literal, this value will be just
231 /// that address, without the brackets around it that are necessary in
232 /// the string form of the URI. Note that in this case there may also
233 /// be a scope ID attached to the address. Eg, `fe80::1234%``em1` (or
234 /// `fe80::1234%``25em1` if the string is still encoded).
235 ///
236 /// # Returns
237 ///
238 /// @self's host.
239 #[doc(alias = "g_uri_get_host")]
240 #[doc(alias = "get_host")]
241 pub fn host(&self) -> Option<crate::GString> {
242 unsafe { from_glib_none(ffi::g_uri_get_host(self.to_glib_none().0)) }
243 }
244
245 /// Gets @self's password, which may contain `%`-encoding, depending on
246 /// the flags with which @self was created. (If @self was not created
247 /// with [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] then this will be [`None`].)
248 ///
249 /// # Returns
250 ///
251 /// @self's password.
252 #[doc(alias = "g_uri_get_password")]
253 #[doc(alias = "get_password")]
254 pub fn password(&self) -> Option<crate::GString> {
255 unsafe { from_glib_none(ffi::g_uri_get_password(self.to_glib_none().0)) }
256 }
257
258 /// Gets @self's path, which may contain `%`-encoding, depending on the
259 /// flags with which @self was created.
260 ///
261 /// # Returns
262 ///
263 /// @self's path.
264 #[doc(alias = "g_uri_get_path")]
265 #[doc(alias = "get_path")]
266 pub fn path(&self) -> crate::GString {
267 unsafe { from_glib_none(ffi::g_uri_get_path(self.to_glib_none().0)) }
268 }
269
270 /// Gets @self's port.
271 ///
272 /// # Returns
273 ///
274 /// @self's port, or `-1` if no port was specified.
275 #[doc(alias = "g_uri_get_port")]
276 #[doc(alias = "get_port")]
277 pub fn port(&self) -> i32 {
278 unsafe { ffi::g_uri_get_port(self.to_glib_none().0) }
279 }
280
281 /// Gets @self's query, which may contain `%`-encoding, depending on the
282 /// flags with which @self was created.
283 ///
284 /// For queries consisting of a series of `name=value` parameters,
285 /// #GUriParamsIter or g_uri_parse_params() may be useful.
286 ///
287 /// # Returns
288 ///
289 /// @self's query.
290 #[doc(alias = "g_uri_get_query")]
291 #[doc(alias = "get_query")]
292 pub fn query(&self) -> Option<crate::GString> {
293 unsafe { from_glib_none(ffi::g_uri_get_query(self.to_glib_none().0)) }
294 }
295
296 /// Gets @self's scheme. Note that this will always be all-lowercase,
297 /// regardless of the string or strings that @self was created from.
298 ///
299 /// # Returns
300 ///
301 /// @self's scheme.
302 #[doc(alias = "g_uri_get_scheme")]
303 #[doc(alias = "get_scheme")]
304 pub fn scheme(&self) -> crate::GString {
305 unsafe { from_glib_none(ffi::g_uri_get_scheme(self.to_glib_none().0)) }
306 }
307
308 /// Gets the ‘username’ component of @self's userinfo, which may contain
309 /// `%`-encoding, depending on the flags with which @self was created.
310 /// If @self was not created with [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] or
311 /// [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS], this is the same as g_uri_get_userinfo().
312 ///
313 /// # Returns
314 ///
315 /// @self's user.
316 #[doc(alias = "g_uri_get_user")]
317 #[doc(alias = "get_user")]
318 pub fn user(&self) -> Option<crate::GString> {
319 unsafe { from_glib_none(ffi::g_uri_get_user(self.to_glib_none().0)) }
320 }
321
322 /// Gets @self's userinfo, which may contain `%`-encoding, depending on
323 /// the flags with which @self was created.
324 ///
325 /// # Returns
326 ///
327 /// @self's userinfo.
328 #[doc(alias = "g_uri_get_userinfo")]
329 #[doc(alias = "get_userinfo")]
330 pub fn userinfo(&self) -> Option<crate::GString> {
331 unsafe { from_glib_none(ffi::g_uri_get_userinfo(self.to_glib_none().0)) }
332 }
333
334 /// Parses @uri_ref according to @flags and, if it is a
335 /// [relative URI](#relative-and-absolute-uris), resolves it relative to @self.
336 /// If the result is not a valid absolute URI, it will be discarded, and an error
337 /// returned.
338 /// ## `uri_ref`
339 /// a string representing a relative or absolute URI
340 /// ## `flags`
341 /// flags describing how to parse @uri_ref
342 ///
343 /// # Returns
344 ///
345 /// a new #GUri, or NULL on error.
346 #[doc(alias = "g_uri_parse_relative")]
347 pub fn parse_relative(&self, uri_ref: &str, flags: UriFlags) -> Result<Uri, crate::Error> {
348 unsafe {
349 let mut error = std::ptr::null_mut();
350 let ret = ffi::g_uri_parse_relative(
351 self.to_glib_none().0,
352 uri_ref.to_glib_none().0,
353 flags.into_glib(),
354 &mut error,
355 );
356 if error.is_null() {
357 Ok(from_glib_full(ret))
358 } else {
359 Err(from_glib_full(error))
360 }
361 }
362 }
363
364 /// Returns a string representing @self.
365 ///
366 /// This is not guaranteed to return a string which is identical to the
367 /// string that @self was parsed from. However, if the source URI was
368 /// syntactically correct (according to RFC 3986), and it was parsed
369 /// with [`UriFlags::ENCODED`][crate::UriFlags::ENCODED], then g_uri_to_string() is guaranteed to return
370 /// a string which is at least semantically equivalent to the source
371 /// URI (according to RFC 3986).
372 ///
373 /// If @self might contain sensitive details, such as authentication parameters,
374 /// or private data in its query string, and the returned string is going to be
375 /// logged, then consider using g_uri_to_string_partial() to redact parts.
376 ///
377 /// # Returns
378 ///
379 /// a string representing @self,
380 /// which the caller must free.
381 #[doc(alias = "g_uri_to_string")]
382 #[doc(alias = "to_string")]
383 pub fn to_str(&self) -> crate::GString {
384 unsafe { from_glib_full(ffi::g_uri_to_string(self.to_glib_none().0)) }
385 }
386
387 /// Returns a string representing @self, subject to the options in
388 /// @flags. See g_uri_to_string() and #GUriHideFlags for more details.
389 /// ## `flags`
390 /// flags describing what parts of @self to hide
391 ///
392 /// # Returns
393 ///
394 /// a string representing
395 /// @self, which the caller must free.
396 #[doc(alias = "g_uri_to_string_partial")]
397 pub fn to_string_partial(&self, flags: UriHideFlags) -> crate::GString {
398 unsafe {
399 from_glib_full(ffi::g_uri_to_string_partial(
400 self.to_glib_none().0,
401 flags.into_glib(),
402 ))
403 }
404 }
405
406 /// Creates a new #GUri from the given components according to @flags.
407 ///
408 /// See also g_uri_build_with_user(), which allows specifying the
409 /// components of the "userinfo" separately.
410 /// ## `flags`
411 /// flags describing how to build the #GUri
412 /// ## `scheme`
413 /// the URI scheme
414 /// ## `userinfo`
415 /// the userinfo component, or [`None`]
416 /// ## `host`
417 /// the host component, or [`None`]
418 /// ## `port`
419 /// the port, or `-1`
420 /// ## `path`
421 /// the path component
422 /// ## `query`
423 /// the query component, or [`None`]
424 /// ## `fragment`
425 /// the fragment, or [`None`]
426 ///
427 /// # Returns
428 ///
429 /// a new #GUri
430 #[doc(alias = "g_uri_build")]
431 pub fn build(
432 flags: UriFlags,
433 scheme: &str,
434 userinfo: Option<&str>,
435 host: Option<&str>,
436 port: i32,
437 path: &str,
438 query: Option<&str>,
439 fragment: Option<&str>,
440 ) -> Uri {
441 unsafe {
442 from_glib_full(ffi::g_uri_build(
443 flags.into_glib(),
444 scheme.to_glib_none().0,
445 userinfo.to_glib_none().0,
446 host.to_glib_none().0,
447 port,
448 path.to_glib_none().0,
449 query.to_glib_none().0,
450 fragment.to_glib_none().0,
451 ))
452 }
453 }
454
455 /// Creates a new #GUri from the given components according to @flags
456 /// ([`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] is added unconditionally). The @flags must be
457 /// coherent with the passed values, in particular use `%`-encoded values with
458 /// [`UriFlags::ENCODED`][crate::UriFlags::ENCODED].
459 ///
460 /// In contrast to g_uri_build(), this allows specifying the components
461 /// of the ‘userinfo’ field separately. Note that @user must be non-[`None`]
462 /// if either @password or @auth_params is non-[`None`].
463 /// ## `flags`
464 /// flags describing how to build the #GUri
465 /// ## `scheme`
466 /// the URI scheme
467 /// ## `user`
468 /// the user component of the userinfo, or [`None`]
469 /// ## `password`
470 /// the password component of the userinfo, or [`None`]
471 /// ## `auth_params`
472 /// the auth params of the userinfo, or [`None`]
473 /// ## `host`
474 /// the host component, or [`None`]
475 /// ## `port`
476 /// the port, or `-1`
477 /// ## `path`
478 /// the path component
479 /// ## `query`
480 /// the query component, or [`None`]
481 /// ## `fragment`
482 /// the fragment, or [`None`]
483 ///
484 /// # Returns
485 ///
486 /// a new #GUri
487 #[doc(alias = "g_uri_build_with_user")]
488 pub fn build_with_user(
489 flags: UriFlags,
490 scheme: &str,
491 user: Option<&str>,
492 password: Option<&str>,
493 auth_params: Option<&str>,
494 host: Option<&str>,
495 port: i32,
496 path: &str,
497 query: Option<&str>,
498 fragment: Option<&str>,
499 ) -> Uri {
500 unsafe {
501 from_glib_full(ffi::g_uri_build_with_user(
502 flags.into_glib(),
503 scheme.to_glib_none().0,
504 user.to_glib_none().0,
505 password.to_glib_none().0,
506 auth_params.to_glib_none().0,
507 host.to_glib_none().0,
508 port,
509 path.to_glib_none().0,
510 query.to_glib_none().0,
511 fragment.to_glib_none().0,
512 ))
513 }
514 }
515
516 /// Escapes arbitrary data for use in a URI.
517 ///
518 /// Normally all characters that are not ‘unreserved’ (i.e. ASCII
519 /// alphanumerical characters plus dash, dot, underscore and tilde) are
520 /// escaped. But if you specify characters in @reserved_chars_allowed
521 /// they are not escaped. This is useful for the ‘reserved’ characters
522 /// in the URI specification, since those are allowed unescaped in some
523 /// portions of a URI.
524 ///
525 /// Though technically incorrect, this will also allow escaping nul
526 /// bytes as `%``00`.
527 /// ## `unescaped`
528 /// the unescaped input data.
529 /// ## `reserved_chars_allowed`
530 /// a string of reserved
531 /// characters that are allowed to be used, or [`None`].
532 ///
533 /// # Returns
534 ///
535 /// an escaped version of @unescaped.
536 /// The returned string should be freed when no longer needed.
537 #[doc(alias = "g_uri_escape_bytes")]
538 pub fn escape_bytes(unescaped: &[u8], reserved_chars_allowed: Option<&str>) -> crate::GString {
539 let length = unescaped.len() as _;
540 unsafe {
541 from_glib_full(ffi::g_uri_escape_bytes(
542 unescaped.to_glib_none().0,
543 length,
544 reserved_chars_allowed.to_glib_none().0,
545 ))
546 }
547 }
548
549 /// Escapes a string for use in a URI.
550 ///
551 /// Normally all characters that are not "unreserved" (i.e. ASCII
552 /// alphanumerical characters plus dash, dot, underscore and tilde) are
553 /// escaped. But if you specify characters in @reserved_chars_allowed
554 /// they are not escaped. This is useful for the "reserved" characters
555 /// in the URI specification, since those are allowed unescaped in some
556 /// portions of a URI.
557 /// ## `unescaped`
558 /// the unescaped input string.
559 /// ## `reserved_chars_allowed`
560 /// a string of reserved
561 /// characters that are allowed to be used, or [`None`].
562 /// ## `allow_utf8`
563 /// [`true`] if the result can include UTF-8 characters.
564 ///
565 /// # Returns
566 ///
567 /// an escaped version of @unescaped. The
568 /// returned string should be freed when no longer needed.
569 #[doc(alias = "g_uri_escape_string")]
570 pub fn escape_string(
571 unescaped: &str,
572 reserved_chars_allowed: Option<&str>,
573 allow_utf8: bool,
574 ) -> crate::GString {
575 unsafe {
576 from_glib_full(ffi::g_uri_escape_string(
577 unescaped.to_glib_none().0,
578 reserved_chars_allowed.to_glib_none().0,
579 allow_utf8.into_glib(),
580 ))
581 }
582 }
583
584 /// Parses @uri_string according to @flags, to determine whether it is a valid
585 /// [absolute URI](#relative-and-absolute-uris), i.e. it does not need to be resolved
586 /// relative to another URI using g_uri_parse_relative().
587 ///
588 /// If it’s not a valid URI, an error is returned explaining how it’s invalid.
589 ///
590 /// See g_uri_split(), and the definition of #GUriFlags, for more
591 /// information on the effect of @flags.
592 /// ## `uri_string`
593 /// a string containing an absolute URI
594 /// ## `flags`
595 /// flags for parsing @uri_string
596 ///
597 /// # Returns
598 ///
599 /// [`true`] if @uri_string is a valid absolute URI, [`false`] on error.
600 #[doc(alias = "g_uri_is_valid")]
601 pub fn is_valid(uri_string: &str, flags: UriFlags) -> Result<(), crate::Error> {
602 unsafe {
603 let mut error = std::ptr::null_mut();
604 let is_ok =
605 ffi::g_uri_is_valid(uri_string.to_glib_none().0, flags.into_glib(), &mut error);
606 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
607 if error.is_null() {
608 Ok(())
609 } else {
610 Err(from_glib_full(error))
611 }
612 }
613 }
614
615 /// Joins the given components together according to @flags to create
616 /// an absolute URI string. @path may not be [`None`] (though it may be the empty
617 /// string).
618 ///
619 /// When @host is present, @path must either be empty or begin with a slash (`/`)
620 /// character. When @host is not present, @path cannot begin with two slash
621 /// characters (`//`). See
622 /// [RFC 3986, section 3](https://tools.ietf.org/html/rfc3986#section-3).
623 ///
624 /// See also g_uri_join_with_user(), which allows specifying the
625 /// components of the ‘userinfo’ separately.
626 ///
627 /// [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] and [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS] are ignored if set
628 /// in @flags.
629 /// ## `flags`
630 /// flags describing how to build the URI string
631 /// ## `scheme`
632 /// the URI scheme, or [`None`]
633 /// ## `userinfo`
634 /// the userinfo component, or [`None`]
635 /// ## `host`
636 /// the host component, or [`None`]
637 /// ## `port`
638 /// the port, or `-1`
639 /// ## `path`
640 /// the path component
641 /// ## `query`
642 /// the query component, or [`None`]
643 /// ## `fragment`
644 /// the fragment, or [`None`]
645 ///
646 /// # Returns
647 ///
648 /// an absolute URI string
649 #[doc(alias = "g_uri_join")]
650 pub fn join(
651 flags: UriFlags,
652 scheme: Option<&str>,
653 userinfo: Option<&str>,
654 host: Option<&str>,
655 port: i32,
656 path: &str,
657 query: Option<&str>,
658 fragment: Option<&str>,
659 ) -> crate::GString {
660 unsafe {
661 from_glib_full(ffi::g_uri_join(
662 flags.into_glib(),
663 scheme.to_glib_none().0,
664 userinfo.to_glib_none().0,
665 host.to_glib_none().0,
666 port,
667 path.to_glib_none().0,
668 query.to_glib_none().0,
669 fragment.to_glib_none().0,
670 ))
671 }
672 }
673
674 /// Joins the given components together according to @flags to create
675 /// an absolute URI string. @path may not be [`None`] (though it may be the empty
676 /// string).
677 ///
678 /// In contrast to g_uri_join(), this allows specifying the components
679 /// of the ‘userinfo’ separately. It otherwise behaves the same.
680 ///
681 /// [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] and [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS] are ignored if set
682 /// in @flags.
683 /// ## `flags`
684 /// flags describing how to build the URI string
685 /// ## `scheme`
686 /// the URI scheme, or [`None`]
687 /// ## `user`
688 /// the user component of the userinfo, or [`None`]
689 /// ## `password`
690 /// the password component of the userinfo, or
691 /// [`None`]
692 /// ## `auth_params`
693 /// the auth params of the userinfo, or
694 /// [`None`]
695 /// ## `host`
696 /// the host component, or [`None`]
697 /// ## `port`
698 /// the port, or `-1`
699 /// ## `path`
700 /// the path component
701 /// ## `query`
702 /// the query component, or [`None`]
703 /// ## `fragment`
704 /// the fragment, or [`None`]
705 ///
706 /// # Returns
707 ///
708 /// an absolute URI string
709 #[doc(alias = "g_uri_join_with_user")]
710 pub fn join_with_user(
711 flags: UriFlags,
712 scheme: Option<&str>,
713 user: Option<&str>,
714 password: Option<&str>,
715 auth_params: Option<&str>,
716 host: Option<&str>,
717 port: i32,
718 path: &str,
719 query: Option<&str>,
720 fragment: Option<&str>,
721 ) -> crate::GString {
722 unsafe {
723 from_glib_full(ffi::g_uri_join_with_user(
724 flags.into_glib(),
725 scheme.to_glib_none().0,
726 user.to_glib_none().0,
727 password.to_glib_none().0,
728 auth_params.to_glib_none().0,
729 host.to_glib_none().0,
730 port,
731 path.to_glib_none().0,
732 query.to_glib_none().0,
733 fragment.to_glib_none().0,
734 ))
735 }
736 }
737
738 /// Splits an URI list conforming to the text/uri-list
739 /// mime type defined in RFC 2483 into individual URIs,
740 /// discarding any comments. The URIs are not validated.
741 /// ## `uri_list`
742 /// an URI list
743 ///
744 /// # Returns
745 ///
746 /// a newly allocated [`None`]-terminated list
747 /// of strings holding the individual URIs. The array should be freed
748 /// with g_strfreev().
749 #[doc(alias = "g_uri_list_extract_uris")]
750 pub fn list_extract_uris(uri_list: &str) -> Vec<crate::GString> {
751 unsafe {
752 FromGlibPtrContainer::from_glib_full(ffi::g_uri_list_extract_uris(
753 uri_list.to_glib_none().0,
754 ))
755 }
756 }
757
758 /// Parses @uri_string according to @flags. If the result is not a
759 /// valid [absolute URI](#relative-and-absolute-uris), it will be discarded, and an
760 /// error returned.
761 /// ## `uri_string`
762 /// a string representing an absolute URI
763 /// ## `flags`
764 /// flags describing how to parse @uri_string
765 ///
766 /// # Returns
767 ///
768 /// a new #GUri, or NULL on error.
769 #[doc(alias = "g_uri_parse")]
770 pub fn parse(uri_string: &str, flags: UriFlags) -> Result<Uri, crate::Error> {
771 unsafe {
772 let mut error = std::ptr::null_mut();
773 let ret = ffi::g_uri_parse(uri_string.to_glib_none().0, flags.into_glib(), &mut error);
774 if error.is_null() {
775 Ok(from_glib_full(ret))
776 } else {
777 Err(from_glib_full(error))
778 }
779 }
780 }
781
782 //#[doc(alias = "g_uri_parse_params")]
783 //pub fn parse_params(params: &str, separators: &str, flags: UriParamsFlags) -> Result</*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 }, crate::Error> {
784 // unsafe { TODO: call ffi:g_uri_parse_params() }
785 //}
786
787 /// Gets the scheme portion of a URI string.
788 /// [RFC 3986](https://tools.ietf.org/html/rfc3986#section-3) decodes the scheme
789 /// as:
790 ///
791 /// ```text
792 /// URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
793 /// ```
794 /// Common schemes include `file`, `https`, `svn+ssh`, etc.
795 /// ## `uri`
796 /// a valid URI.
797 ///
798 /// # Returns
799 ///
800 /// The ‘scheme’ component of the URI, or
801 /// [`None`] on error. The returned string should be freed when no longer needed.
802 #[doc(alias = "g_uri_parse_scheme")]
803 pub fn parse_scheme(uri: &str) -> Option<crate::GString> {
804 unsafe { from_glib_full(ffi::g_uri_parse_scheme(uri.to_glib_none().0)) }
805 }
806
807 /// Gets the scheme portion of a URI string.
808 /// [RFC 3986](https://tools.ietf.org/html/rfc3986#section-3) decodes the scheme
809 /// as:
810 ///
811 /// ```text
812 /// URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
813 /// ```
814 /// Common schemes include `file`, `https`, `svn+ssh`, etc.
815 ///
816 /// Unlike g_uri_parse_scheme(), the returned scheme is normalized to
817 /// all-lowercase and does not need to be freed.
818 /// ## `uri`
819 /// a valid URI.
820 ///
821 /// # Returns
822 ///
823 /// The ‘scheme’ component of the URI, or
824 /// [`None`] on error. The returned string is normalized to all-lowercase, and
825 /// interned via g_intern_string(), so it does not need to be freed.
826 #[doc(alias = "g_uri_peek_scheme")]
827 pub fn peek_scheme(uri: &str) -> Option<crate::GString> {
828 unsafe { from_glib_none(ffi::g_uri_peek_scheme(uri.to_glib_none().0)) }
829 }
830
831 /// Parses @uri_ref according to @flags and, if it is a
832 /// [relative URI](#relative-and-absolute-uris), resolves it relative to
833 /// @base_uri_string. If the result is not a valid absolute URI, it will be
834 /// discarded, and an error returned.
835 ///
836 /// (If @base_uri_string is [`None`], this just returns @uri_ref, or
837 /// [`None`] if @uri_ref is invalid or not absolute.)
838 /// ## `base_uri_string`
839 /// a string representing a base URI
840 /// ## `uri_ref`
841 /// a string representing a relative or absolute URI
842 /// ## `flags`
843 /// flags describing how to parse @uri_ref
844 ///
845 /// # Returns
846 ///
847 /// the resolved URI string,
848 /// or NULL on error.
849 #[doc(alias = "g_uri_resolve_relative")]
850 pub fn resolve_relative(
851 base_uri_string: Option<&str>,
852 uri_ref: &str,
853 flags: UriFlags,
854 ) -> Result<crate::GString, crate::Error> {
855 unsafe {
856 let mut error = std::ptr::null_mut();
857 let ret = ffi::g_uri_resolve_relative(
858 base_uri_string.to_glib_none().0,
859 uri_ref.to_glib_none().0,
860 flags.into_glib(),
861 &mut error,
862 );
863 if error.is_null() {
864 Ok(from_glib_full(ret))
865 } else {
866 Err(from_glib_full(error))
867 }
868 }
869 }
870
871 /// Parses @uri_ref (which can be an
872 /// [absolute or relative URI](#relative-and-absolute-uris)) according to @flags, and
873 /// returns the pieces. Any component that doesn't appear in @uri_ref will be
874 /// returned as [`None`] (but note that all URIs always have a path component,
875 /// though it may be the empty string).
876 ///
877 /// If @flags contains [`UriFlags::ENCODED`][crate::UriFlags::ENCODED], then `%`-encoded characters in
878 /// @uri_ref will remain encoded in the output strings. (If not,
879 /// then all such characters will be decoded.) Note that decoding will
880 /// only work if the URI components are ASCII or UTF-8, so you will
881 /// need to use [`UriFlags::ENCODED`][crate::UriFlags::ENCODED] if they are not.
882 ///
883 /// Note that the [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] and
884 /// [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS] @flags are ignored by g_uri_split(),
885 /// since it always returns only the full userinfo; use
886 /// g_uri_split_with_user() if you want it split up.
887 /// ## `uri_ref`
888 /// a string containing a relative or absolute URI
889 /// ## `flags`
890 /// flags for parsing @uri_ref
891 ///
892 /// # Returns
893 ///
894 /// [`true`] if @uri_ref parsed successfully, [`false`]
895 /// on error.
896 ///
897 /// ## `scheme`
898 /// on return, contains
899 /// the scheme (converted to lowercase), or [`None`]
900 ///
901 /// ## `userinfo`
902 /// on return, contains
903 /// the userinfo, or [`None`]
904 ///
905 /// ## `host`
906 /// on return, contains the
907 /// host, or [`None`]
908 ///
909 /// ## `port`
910 /// on return, contains the
911 /// port, or `-1`
912 ///
913 /// ## `path`
914 /// on return, contains the
915 /// path
916 ///
917 /// ## `query`
918 /// on return, contains the
919 /// query, or [`None`]
920 ///
921 /// ## `fragment`
922 /// on return, contains
923 /// the fragment, or [`None`]
924 #[doc(alias = "g_uri_split")]
925 pub fn split(
926 uri_ref: &str,
927 flags: UriFlags,
928 ) -> Result<
929 (
930 Option<crate::GString>,
931 Option<crate::GString>,
932 Option<crate::GString>,
933 i32,
934 crate::GString,
935 Option<crate::GString>,
936 Option<crate::GString>,
937 ),
938 crate::Error,
939 > {
940 unsafe {
941 let mut scheme = std::ptr::null_mut();
942 let mut userinfo = std::ptr::null_mut();
943 let mut host = std::ptr::null_mut();
944 let mut port = std::mem::MaybeUninit::uninit();
945 let mut path = std::ptr::null_mut();
946 let mut query = std::ptr::null_mut();
947 let mut fragment = std::ptr::null_mut();
948 let mut error = std::ptr::null_mut();
949 let is_ok = ffi::g_uri_split(
950 uri_ref.to_glib_none().0,
951 flags.into_glib(),
952 &mut scheme,
953 &mut userinfo,
954 &mut host,
955 port.as_mut_ptr(),
956 &mut path,
957 &mut query,
958 &mut fragment,
959 &mut error,
960 );
961 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
962 if error.is_null() {
963 Ok((
964 from_glib_full(scheme),
965 from_glib_full(userinfo),
966 from_glib_full(host),
967 port.assume_init(),
968 from_glib_full(path),
969 from_glib_full(query),
970 from_glib_full(fragment),
971 ))
972 } else {
973 Err(from_glib_full(error))
974 }
975 }
976 }
977
978 /// Parses @uri_string (which must be an [absolute URI](#relative-and-absolute-uris))
979 /// according to @flags, and returns the pieces relevant to connecting to a host.
980 /// See the documentation for g_uri_split() for more details; this is
981 /// mostly a wrapper around that function with simpler arguments.
982 /// However, it will return an error if @uri_string is a relative URI,
983 /// or does not contain a hostname component.
984 /// ## `uri_string`
985 /// a string containing an absolute URI
986 /// ## `flags`
987 /// flags for parsing @uri_string
988 ///
989 /// # Returns
990 ///
991 /// [`true`] if @uri_string parsed successfully,
992 /// [`false`] on error.
993 ///
994 /// ## `scheme`
995 /// on return, contains
996 /// the scheme (converted to lowercase), or [`None`]
997 ///
998 /// ## `host`
999 /// on return, contains the
1000 /// host, or [`None`]
1001 ///
1002 /// ## `port`
1003 /// on return, contains the
1004 /// port, or `-1`
1005 #[doc(alias = "g_uri_split_network")]
1006 pub fn split_network(
1007 uri_string: &str,
1008 flags: UriFlags,
1009 ) -> Result<(Option<crate::GString>, Option<crate::GString>, i32), crate::Error> {
1010 unsafe {
1011 let mut scheme = std::ptr::null_mut();
1012 let mut host = std::ptr::null_mut();
1013 let mut port = std::mem::MaybeUninit::uninit();
1014 let mut error = std::ptr::null_mut();
1015 let is_ok = ffi::g_uri_split_network(
1016 uri_string.to_glib_none().0,
1017 flags.into_glib(),
1018 &mut scheme,
1019 &mut host,
1020 port.as_mut_ptr(),
1021 &mut error,
1022 );
1023 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
1024 if error.is_null() {
1025 Ok((
1026 from_glib_full(scheme),
1027 from_glib_full(host),
1028 port.assume_init(),
1029 ))
1030 } else {
1031 Err(from_glib_full(error))
1032 }
1033 }
1034 }
1035
1036 /// Parses @uri_ref (which can be an
1037 /// [absolute or relative URI](#relative-and-absolute-uris)) according to @flags, and
1038 /// returns the pieces. Any component that doesn't appear in @uri_ref will be
1039 /// returned as [`None`] (but note that all URIs always have a path component,
1040 /// though it may be the empty string).
1041 ///
1042 /// See g_uri_split(), and the definition of #GUriFlags, for more
1043 /// information on the effect of @flags. Note that @password will only
1044 /// be parsed out if @flags contains [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD], and
1045 /// @auth_params will only be parsed out if @flags contains
1046 /// [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS].
1047 /// ## `uri_ref`
1048 /// a string containing a relative or absolute URI
1049 /// ## `flags`
1050 /// flags for parsing @uri_ref
1051 ///
1052 /// # Returns
1053 ///
1054 /// [`true`] if @uri_ref parsed successfully, [`false`]
1055 /// on error.
1056 ///
1057 /// ## `scheme`
1058 /// on return, contains
1059 /// the scheme (converted to lowercase), or [`None`]
1060 ///
1061 /// ## `user`
1062 /// on return, contains
1063 /// the user, or [`None`]
1064 ///
1065 /// ## `password`
1066 /// on return, contains
1067 /// the password, or [`None`]
1068 ///
1069 /// ## `auth_params`
1070 /// on return, contains
1071 /// the auth_params, or [`None`]
1072 ///
1073 /// ## `host`
1074 /// on return, contains the
1075 /// host, or [`None`]
1076 ///
1077 /// ## `port`
1078 /// on return, contains the
1079 /// port, or `-1`
1080 ///
1081 /// ## `path`
1082 /// on return, contains the
1083 /// path
1084 ///
1085 /// ## `query`
1086 /// on return, contains the
1087 /// query, or [`None`]
1088 ///
1089 /// ## `fragment`
1090 /// on return, contains
1091 /// the fragment, or [`None`]
1092 #[doc(alias = "g_uri_split_with_user")]
1093 pub fn split_with_user(
1094 uri_ref: &str,
1095 flags: UriFlags,
1096 ) -> Result<
1097 (
1098 Option<crate::GString>,
1099 Option<crate::GString>,
1100 Option<crate::GString>,
1101 Option<crate::GString>,
1102 Option<crate::GString>,
1103 i32,
1104 crate::GString,
1105 Option<crate::GString>,
1106 Option<crate::GString>,
1107 ),
1108 crate::Error,
1109 > {
1110 unsafe {
1111 let mut scheme = std::ptr::null_mut();
1112 let mut user = std::ptr::null_mut();
1113 let mut password = std::ptr::null_mut();
1114 let mut auth_params = std::ptr::null_mut();
1115 let mut host = std::ptr::null_mut();
1116 let mut port = std::mem::MaybeUninit::uninit();
1117 let mut path = std::ptr::null_mut();
1118 let mut query = std::ptr::null_mut();
1119 let mut fragment = std::ptr::null_mut();
1120 let mut error = std::ptr::null_mut();
1121 let is_ok = ffi::g_uri_split_with_user(
1122 uri_ref.to_glib_none().0,
1123 flags.into_glib(),
1124 &mut scheme,
1125 &mut user,
1126 &mut password,
1127 &mut auth_params,
1128 &mut host,
1129 port.as_mut_ptr(),
1130 &mut path,
1131 &mut query,
1132 &mut fragment,
1133 &mut error,
1134 );
1135 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
1136 if error.is_null() {
1137 Ok((
1138 from_glib_full(scheme),
1139 from_glib_full(user),
1140 from_glib_full(password),
1141 from_glib_full(auth_params),
1142 from_glib_full(host),
1143 port.assume_init(),
1144 from_glib_full(path),
1145 from_glib_full(query),
1146 from_glib_full(fragment),
1147 ))
1148 } else {
1149 Err(from_glib_full(error))
1150 }
1151 }
1152 }
1153
1154 /// Unescapes a segment of an escaped string as binary data.
1155 ///
1156 /// Note that in contrast to g_uri_unescape_string(), this does allow
1157 /// nul bytes to appear in the output.
1158 ///
1159 /// If any of the characters in @illegal_characters appears as an escaped
1160 /// character in @escaped_string, then that is an error and [`None`] will be
1161 /// returned. This is useful if you want to avoid for instance having a slash
1162 /// being expanded in an escaped path element, which might confuse pathname
1163 /// handling.
1164 /// ## `escaped_string`
1165 /// A URI-escaped string
1166 /// ## `length`
1167 /// the length (in bytes) of @escaped_string to escape, or `-1` if it
1168 /// is nul-terminated.
1169 /// ## `illegal_characters`
1170 /// a string of illegal characters
1171 /// not to be allowed, or [`None`].
1172 ///
1173 /// # Returns
1174 ///
1175 /// an unescaped version of @escaped_string
1176 /// or [`None`] on error (if decoding failed, using [`UriError::Failed`][crate::UriError::Failed] error
1177 /// code). The returned #GBytes should be unreffed when no longer needed.
1178 #[doc(alias = "g_uri_unescape_bytes")]
1179 pub fn unescape_bytes(
1180 escaped_string: &str,
1181 illegal_characters: Option<&str>,
1182 ) -> Result<Bytes, crate::Error> {
1183 let length = escaped_string.len() as _;
1184 unsafe {
1185 let mut error = std::ptr::null_mut();
1186 let ret = ffi::g_uri_unescape_bytes(
1187 escaped_string.to_glib_none().0,
1188 length,
1189 illegal_characters.to_glib_none().0,
1190 &mut error,
1191 );
1192 if error.is_null() {
1193 Ok(from_glib_full(ret))
1194 } else {
1195 Err(from_glib_full(error))
1196 }
1197 }
1198 }
1199
1200 /// Unescapes a segment of an escaped string.
1201 ///
1202 /// If any of the characters in @illegal_characters or the NUL
1203 /// character appears as an escaped character in @escaped_string, then
1204 /// that is an error and [`None`] will be returned. This is useful if you
1205 /// want to avoid for instance having a slash being expanded in an
1206 /// escaped path element, which might confuse pathname handling.
1207 ///
1208 /// Note: `NUL` byte is not accepted in the output, in contrast to
1209 /// g_uri_unescape_bytes().
1210 /// ## `escaped_string`
1211 /// A string, may be [`None`]
1212 /// ## `escaped_string_end`
1213 /// Pointer to end of @escaped_string,
1214 /// may be [`None`]
1215 /// ## `illegal_characters`
1216 /// An optional string of illegal
1217 /// characters not to be allowed, may be [`None`]
1218 ///
1219 /// # Returns
1220 ///
1221 /// an unescaped version of @escaped_string,
1222 /// or [`None`] on error. The returned string should be freed when no longer
1223 /// needed. As a special case if [`None`] is given for @escaped_string, this
1224 /// function will return [`None`].
1225 #[doc(alias = "g_uri_unescape_segment")]
1226 pub fn unescape_segment(
1227 escaped_string: Option<&str>,
1228 escaped_string_end: Option<&str>,
1229 illegal_characters: Option<&str>,
1230 ) -> Option<crate::GString> {
1231 unsafe {
1232 from_glib_full(ffi::g_uri_unescape_segment(
1233 escaped_string.to_glib_none().0,
1234 escaped_string_end.to_glib_none().0,
1235 illegal_characters.to_glib_none().0,
1236 ))
1237 }
1238 }
1239
1240 /// Unescapes a whole escaped string.
1241 ///
1242 /// If any of the characters in @illegal_characters or the NUL
1243 /// character appears as an escaped character in @escaped_string, then
1244 /// that is an error and [`None`] will be returned. This is useful if you
1245 /// want to avoid for instance having a slash being expanded in an
1246 /// escaped path element, which might confuse pathname handling.
1247 /// ## `escaped_string`
1248 /// an escaped string to be unescaped.
1249 /// ## `illegal_characters`
1250 /// a string of illegal characters
1251 /// not to be allowed, or [`None`].
1252 ///
1253 /// # Returns
1254 ///
1255 /// an unescaped version of @escaped_string.
1256 /// The returned string should be freed when no longer needed.
1257 #[doc(alias = "g_uri_unescape_string")]
1258 pub fn unescape_string(
1259 escaped_string: &str,
1260 illegal_characters: Option<&str>,
1261 ) -> Option<crate::GString> {
1262 unsafe {
1263 from_glib_full(ffi::g_uri_unescape_string(
1264 escaped_string.to_glib_none().0,
1265 illegal_characters.to_glib_none().0,
1266 ))
1267 }
1268 }
1269}
1270
1271impl std::fmt::Display for Uri {
1272 #[inline]
1273 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1274 f.write_str(&self.to_str())
1275 }
1276}
1277
1278unsafe impl Send for Uri {}
1279unsafe impl Sync for Uri {}