Skip to main content

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::{Bytes, Error, UriFlags, UriHideFlags, ffi, translate::*};
6
7crate::wrapper! {
8    ///  component of the URI as a
9    /// single element, while [`split_with_user()`][Self::split_with_user()] can (depending on the
10    /// [`UriFlags`][crate::UriFlags] you pass) treat it as containing a username, password,
11    /// and authentication parameters. Alternatively, [`split_network()`][Self::split_network()]
12    /// can be used when you are only interested in the components that are
13    /// needed to initiate a network connection to the service (scheme,
14    /// host, and port).
15    ///
16    /// [`parse()`][Self::parse()] is similar to [`split()`][Self::split()], but instead of
17    /// returning individual strings, it returns a `GUri` structure (and it requires
18    /// that the URI be an absolute URI).
19    ///
20    /// [`resolve_relative()`][Self::resolve_relative()] and [`parse_relative()`][Self::parse_relative()] allow
21    /// you to resolve a relative URI relative to a base URI.
22    /// [`resolve_relative()`][Self::resolve_relative()] takes two strings and returns a string,
23    /// and [`parse_relative()`][Self::parse_relative()] takes a `GUri` and a string and returns a
24    /// `GUri`.
25    ///
26    /// All of the parsing functions take a [`UriFlags`][crate::UriFlags] argument describing
27    /// exactly how to parse the URI; see the documentation for that type
28    /// for more details on the specific flags that you can pass. If you
29    /// need to choose different flags based on the type of URI, you can
30    /// use [`peek_scheme()`][Self::peek_scheme()] on the URI string to check the scheme
31    /// first, and use that to decide what flags to parse it with.
32    ///
33    /// For example, you might want to use `G_URI_PARAMS_WWW_FORM` when parsing the
34    /// params for a web URI, so compare the result of [`peek_scheme()`][Self::peek_scheme()]
35    /// against `http` and `https`.
36    ///
37    /// ## Building URIs
38    ///
39    /// [`join()`][Self::join()] and [`join_with_user()`][Self::join_with_user()] can be used to construct
40    /// valid URI strings from a set of component strings. They are the
41    /// inverse of [`split()`][Self::split()] and [`split_with_user()`][Self::split_with_user()].
42    ///
43    /// Similarly, [`build()`][Self::build()] and [`build_with_user()`][Self::build_with_user()] can be
44    /// used to construct a `GUri` from a set of component strings.
45    ///
46    /// As with the parsing functions, the building functions take a
47    /// [`UriFlags`][crate::UriFlags] argument. In particular, it is important to keep in mind
48    /// whether the URI components you are using are already `%`-encoded. If so,
49    /// you must pass the `G_URI_FLAGS_ENCODED` flag.
50    ///
51    /// ## `file://` URIs
52    ///
53    /// Note that Windows and Unix both define special rules for parsing
54    /// `file://` URIs (involving non-UTF-8 character sets on Unix, and the
55    /// interpretation of path separators on Windows). `GUri` does not
56    /// implement these rules. Use [`filename_from_uri()`][crate::filename_from_uri()] and
57    /// [`filename_to_uri()`][crate::filename_to_uri()] if you want to properly convert between
58    /// `file://` URIs and local filenames.
59    ///
60    /// ## URI Equality
61    ///
62    /// Note that there is no `g_uri_equal ()` function, because comparing
63    /// URIs usefully requires scheme-specific knowledge that `GUri` does
64    /// not have. `GUri` can help with normalization if you use the various
65    /// encoded [`UriFlags`][crate::UriFlags] as well as `G_URI_FLAGS_SCHEME_NORMALIZE`
66    /// however it is not comprehensive.
67    /// For example, `data:,foo` and `data:;base64,Zm9v` resolve to the same
68    /// thing according to the `data:` URI specification which GLib does not
69    /// handle.
70    // rustdoc-stripper-ignore-next-stop
71    ///  component of the URI as a
72    /// single element, while [`split_with_user()`][Self::split_with_user()] can (depending on the
73    /// [`UriFlags`][crate::UriFlags] you pass) treat it as containing a username, password,
74    /// and authentication parameters. Alternatively, [`split_network()`][Self::split_network()]
75    /// can be used when you are only interested in the components that are
76    /// needed to initiate a network connection to the service (scheme,
77    /// host, and port).
78    ///
79    /// [`parse()`][Self::parse()] is similar to [`split()`][Self::split()], but instead of
80    /// returning individual strings, it returns a `GUri` structure (and it requires
81    /// that the URI be an absolute URI).
82    ///
83    /// [`resolve_relative()`][Self::resolve_relative()] and [`parse_relative()`][Self::parse_relative()] allow
84    /// you to resolve a relative URI relative to a base URI.
85    /// [`resolve_relative()`][Self::resolve_relative()] takes two strings and returns a string,
86    /// and [`parse_relative()`][Self::parse_relative()] takes a `GUri` and a string and returns a
87    /// `GUri`.
88    ///
89    /// All of the parsing functions take a [`UriFlags`][crate::UriFlags] argument describing
90    /// exactly how to parse the URI; see the documentation for that type
91    /// for more details on the specific flags that you can pass. If you
92    /// need to choose different flags based on the type of URI, you can
93    /// use [`peek_scheme()`][Self::peek_scheme()] on the URI string to check the scheme
94    /// first, and use that to decide what flags to parse it with.
95    ///
96    /// For example, you might want to use `G_URI_PARAMS_WWW_FORM` when parsing the
97    /// params for a web URI, so compare the result of [`peek_scheme()`][Self::peek_scheme()]
98    /// against `http` and `https`.
99    ///
100    /// ## Building URIs
101    ///
102    /// [`join()`][Self::join()] and [`join_with_user()`][Self::join_with_user()] can be used to construct
103    /// valid URI strings from a set of component strings. They are the
104    /// inverse of [`split()`][Self::split()] and [`split_with_user()`][Self::split_with_user()].
105    ///
106    /// Similarly, [`build()`][Self::build()] and [`build_with_user()`][Self::build_with_user()] can be
107    /// used to construct a `GUri` from a set of component strings.
108    ///
109    /// As with the parsing functions, the building functions take a
110    /// [`UriFlags`][crate::UriFlags] argument. In particular, it is important to keep in mind
111    /// whether the URI components you are using are already `%`-encoded. If so,
112    /// you must pass the `G_URI_FLAGS_ENCODED` flag.
113    ///
114    /// ## `file://` URIs
115    ///
116    /// Note that Windows and Unix both define special rules for parsing
117    /// `file://` URIs (involving non-UTF-8 character sets on Unix, and the
118    /// interpretation of path separators on Windows). `GUri` does not
119    /// implement these rules. Use [`filename_from_uri()`][crate::filename_from_uri()] and
120    /// [`filename_to_uri()`][crate::filename_to_uri()] if you want to properly convert between
121    /// `file://` URIs and local filenames.
122    ///
123    /// ## URI Equality
124    ///
125    /// Note that there is no `g_uri_equal ()` function, because comparing
126    /// URIs usefully requires scheme-specific knowledge that `GUri` does
127    /// not have. `GUri` can help with normalization if you use the various
128    /// encoded [`UriFlags`][crate::UriFlags] as well as `G_URI_FLAGS_SCHEME_NORMALIZE`
129    /// however it is not comprehensive.
130    /// For example, `data:,foo` and `data:;base64,Zm9v` resolve to the same
131    /// thing according to the `data:` URI specification which GLib does not
132    /// handle.
133    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
134    pub struct Uri(Shared<ffi::GUri>);
135
136    match fn {
137        ref => |ptr| ffi::g_uri_ref(ptr),
138        unref => |ptr| ffi::g_uri_unref(ptr),
139        type_ => || ffi::g_uri_get_type(),
140    }
141}
142
143impl Uri {
144    /// Gets @self's authentication parameters, which may contain
145    /// `%`-encoding, depending on the flags with which @self was created.
146    /// (If @self was not created with [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS] then this will
147    /// be [`None`].)
148    ///
149    /// Depending on the URI scheme, g_uri_parse_params() may be useful for
150    /// further parsing this information.
151    ///
152    /// # Returns
153    ///
154    /// @self's authentication parameters.
155    // rustdoc-stripper-ignore-next-stop
156    /// Gets @self's authentication parameters, which may contain
157    /// `%`-encoding, depending on the flags with which @self was created.
158    /// (If @self was not created with [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS] then this will
159    /// be [`None`].)
160    ///
161    /// Depending on the URI scheme, g_uri_parse_params() may be useful for
162    /// further parsing this information.
163    ///
164    /// # Returns
165    ///
166    /// @self's authentication parameters.
167    #[doc(alias = "g_uri_get_auth_params")]
168    #[doc(alias = "get_auth_params")]
169    pub fn auth_params(&self) -> Option<crate::GString> {
170        unsafe { from_glib_none(ffi::g_uri_get_auth_params(self.to_glib_none().0)) }
171    }
172
173    /// Gets @self's flags set upon construction.
174    ///
175    /// # Returns
176    ///
177    /// @self's flags.
178    // rustdoc-stripper-ignore-next-stop
179    /// Gets @self's flags set upon construction.
180    ///
181    /// # Returns
182    ///
183    /// @self's flags.
184    #[doc(alias = "g_uri_get_flags")]
185    #[doc(alias = "get_flags")]
186    pub fn flags(&self) -> UriFlags {
187        unsafe { from_glib(ffi::g_uri_get_flags(self.to_glib_none().0)) }
188    }
189
190    /// Gets @self's fragment, which may contain `%`-encoding, depending on
191    /// the flags with which @self was created.
192    ///
193    /// # Returns
194    ///
195    /// @self's fragment.
196    // rustdoc-stripper-ignore-next-stop
197    /// Gets @self's fragment, which may contain `%`-encoding, depending on
198    /// the flags with which @self was created.
199    ///
200    /// # Returns
201    ///
202    /// @self's fragment.
203    #[doc(alias = "g_uri_get_fragment")]
204    #[doc(alias = "get_fragment")]
205    pub fn fragment(&self) -> Option<crate::GString> {
206        unsafe { from_glib_none(ffi::g_uri_get_fragment(self.to_glib_none().0)) }
207    }
208
209    /// Gets @self's host. This will never have `%`-encoded characters,
210    /// unless it is non-UTF-8 (which can only be the case if @self was
211    /// created with [`UriFlags::NON_DNS`][crate::UriFlags::NON_DNS]).
212    ///
213    /// If @self contained an IPv6 address literal, this value will be just
214    /// that address, without the brackets around it that are necessary in
215    /// the string form of the URI. Note that in this case there may also
216    /// be a scope ID attached to the address. Eg, `fe80::1234%``em1` (or
217    /// `fe80::1234%``25em1` if the string is still encoded).
218    ///
219    /// # Returns
220    ///
221    /// @self's host.
222    // rustdoc-stripper-ignore-next-stop
223    /// Gets @self's host. This will never have `%`-encoded characters,
224    /// unless it is non-UTF-8 (which can only be the case if @self was
225    /// created with [`UriFlags::NON_DNS`][crate::UriFlags::NON_DNS]).
226    ///
227    /// If @self contained an IPv6 address literal, this value will be just
228    /// that address, without the brackets around it that are necessary in
229    /// the string form of the URI. Note that in this case there may also
230    /// be a scope ID attached to the address. Eg, `fe80::1234%``em1` (or
231    /// `fe80::1234%``25em1` if the string is still encoded).
232    ///
233    /// # Returns
234    ///
235    /// @self's host.
236    #[doc(alias = "g_uri_get_host")]
237    #[doc(alias = "get_host")]
238    pub fn host(&self) -> Option<crate::GString> {
239        unsafe { from_glib_none(ffi::g_uri_get_host(self.to_glib_none().0)) }
240    }
241
242    /// Gets @self's password, which may contain `%`-encoding, depending on
243    /// the flags with which @self was created. (If @self was not created
244    /// with [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] then this will be [`None`].)
245    ///
246    /// # Returns
247    ///
248    /// @self's password.
249    // rustdoc-stripper-ignore-next-stop
250    /// Gets @self's password, which may contain `%`-encoding, depending on
251    /// the flags with which @self was created. (If @self was not created
252    /// with [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] then this will be [`None`].)
253    ///
254    /// # Returns
255    ///
256    /// @self's password.
257    #[doc(alias = "g_uri_get_password")]
258    #[doc(alias = "get_password")]
259    pub fn password(&self) -> Option<crate::GString> {
260        unsafe { from_glib_none(ffi::g_uri_get_password(self.to_glib_none().0)) }
261    }
262
263    /// Gets @self's path, which may contain `%`-encoding, depending on the
264    /// flags with which @self was created.
265    ///
266    /// # Returns
267    ///
268    /// @self's path.
269    // rustdoc-stripper-ignore-next-stop
270    /// Gets @self's path, which may contain `%`-encoding, depending on the
271    /// flags with which @self was created.
272    ///
273    /// # Returns
274    ///
275    /// @self's path.
276    #[doc(alias = "g_uri_get_path")]
277    #[doc(alias = "get_path")]
278    pub fn path(&self) -> crate::GString {
279        unsafe { from_glib_none(ffi::g_uri_get_path(self.to_glib_none().0)) }
280    }
281
282    /// Gets @self's port.
283    ///
284    /// # Returns
285    ///
286    /// @self's port, or `-1` if no port was specified.
287    // rustdoc-stripper-ignore-next-stop
288    /// Gets @self's port.
289    ///
290    /// # Returns
291    ///
292    /// @self's port, or `-1` if no port was specified.
293    #[doc(alias = "g_uri_get_port")]
294    #[doc(alias = "get_port")]
295    pub fn port(&self) -> i32 {
296        unsafe { ffi::g_uri_get_port(self.to_glib_none().0) }
297    }
298
299    /// Gets @self's query, which may contain `%`-encoding, depending on the
300    /// flags with which @self was created.
301    ///
302    /// For queries consisting of a series of `name=value` parameters,
303    /// #GUriParamsIter or g_uri_parse_params() may be useful.
304    ///
305    /// # Returns
306    ///
307    /// @self's query.
308    // rustdoc-stripper-ignore-next-stop
309    /// Gets @self's query, which may contain `%`-encoding, depending on the
310    /// flags with which @self was created.
311    ///
312    /// For queries consisting of a series of `name=value` parameters,
313    /// #GUriParamsIter or g_uri_parse_params() may be useful.
314    ///
315    /// # Returns
316    ///
317    /// @self's query.
318    #[doc(alias = "g_uri_get_query")]
319    #[doc(alias = "get_query")]
320    pub fn query(&self) -> Option<crate::GString> {
321        unsafe { from_glib_none(ffi::g_uri_get_query(self.to_glib_none().0)) }
322    }
323
324    /// Gets @self's scheme. Note that this will always be all-lowercase,
325    /// regardless of the string or strings that @self was created from.
326    ///
327    /// # Returns
328    ///
329    /// @self's scheme.
330    // rustdoc-stripper-ignore-next-stop
331    /// Gets @self's scheme. Note that this will always be all-lowercase,
332    /// regardless of the string or strings that @self was created from.
333    ///
334    /// # Returns
335    ///
336    /// @self's scheme.
337    #[doc(alias = "g_uri_get_scheme")]
338    #[doc(alias = "get_scheme")]
339    pub fn scheme(&self) -> crate::GString {
340        unsafe { from_glib_none(ffi::g_uri_get_scheme(self.to_glib_none().0)) }
341    }
342
343    ///  component of @self's userinfo, which may contain
344    /// `%`-encoding, depending on the flags with which @self was created.
345    /// If @self was not created with [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] or
346    /// [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS], this is the same as g_uri_get_userinfo().
347    ///
348    /// # Returns
349    ///
350    /// @self's user.
351    // rustdoc-stripper-ignore-next-stop
352    ///  component of @self's userinfo, which may contain
353    /// `%`-encoding, depending on the flags with which @self was created.
354    /// If @self was not created with [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] or
355    /// [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS], this is the same as g_uri_get_userinfo().
356    ///
357    /// # Returns
358    ///
359    /// @self's user.
360    #[doc(alias = "g_uri_get_user")]
361    #[doc(alias = "get_user")]
362    pub fn user(&self) -> Option<crate::GString> {
363        unsafe { from_glib_none(ffi::g_uri_get_user(self.to_glib_none().0)) }
364    }
365
366    /// Gets @self's userinfo, which may contain `%`-encoding, depending on
367    /// the flags with which @self was created.
368    ///
369    /// # Returns
370    ///
371    /// @self's userinfo.
372    // rustdoc-stripper-ignore-next-stop
373    /// Gets @self's userinfo, which may contain `%`-encoding, depending on
374    /// the flags with which @self was created.
375    ///
376    /// # Returns
377    ///
378    /// @self's userinfo.
379    #[doc(alias = "g_uri_get_userinfo")]
380    #[doc(alias = "get_userinfo")]
381    pub fn userinfo(&self) -> Option<crate::GString> {
382        unsafe { from_glib_none(ffi::g_uri_get_userinfo(self.to_glib_none().0)) }
383    }
384
385    /// Parses @uri_ref according to @flags and, if it is a
386    /// [relative URI](#relative-and-absolute-uris), resolves it relative to @self.
387    /// If the result is not a valid absolute URI, it will be discarded, and an error
388    /// returned.
389    /// ## `uri_ref`
390    /// a string representing a relative or absolute URI
391    /// ## `flags`
392    /// flags describing how to parse @uri_ref
393    ///
394    /// # Returns
395    ///
396    /// a new #GUri, or NULL on error.
397    // rustdoc-stripper-ignore-next-stop
398    /// Parses @uri_ref according to @flags and, if it is a
399    /// [relative URI](#relative-and-absolute-uris), resolves it relative to @self.
400    /// If the result is not a valid absolute URI, it will be discarded, and an error
401    /// returned.
402    /// ## `uri_ref`
403    /// a string representing a relative or absolute URI
404    /// ## `flags`
405    /// flags describing how to parse @uri_ref
406    ///
407    /// # Returns
408    ///
409    /// a new #GUri, or NULL on error.
410    #[doc(alias = "g_uri_parse_relative")]
411    pub fn parse_relative(&self, uri_ref: &str, flags: UriFlags) -> Result<Uri, crate::Error> {
412        unsafe {
413            let mut error = std::ptr::null_mut();
414            let ret = ffi::g_uri_parse_relative(
415                self.to_glib_none().0,
416                uri_ref.to_glib_none().0,
417                flags.into_glib(),
418                &mut error,
419            );
420            if error.is_null() {
421                Ok(from_glib_full(ret))
422            } else {
423                Err(from_glib_full(error))
424            }
425        }
426    }
427
428    /// Returns a string representing @self.
429    ///
430    /// This is not guaranteed to return a string which is identical to the
431    /// string that @self was parsed from. However, if the source URI was
432    /// syntactically correct (according to RFC 3986), and it was parsed
433    /// with [`UriFlags::ENCODED`][crate::UriFlags::ENCODED], then g_uri_to_string() is guaranteed to return
434    /// a string which is at least semantically equivalent to the source
435    /// URI (according to RFC 3986).
436    ///
437    /// If @self might contain sensitive details, such as authentication parameters,
438    /// or private data in its query string, and the returned string is going to be
439    /// logged, then consider using g_uri_to_string_partial() to redact parts.
440    ///
441    /// # Returns
442    ///
443    /// a string representing @self,
444    ///     which the caller must free.
445    // rustdoc-stripper-ignore-next-stop
446    /// Returns a string representing @self.
447    ///
448    /// This is not guaranteed to return a string which is identical to the
449    /// string that @self was parsed from. However, if the source URI was
450    /// syntactically correct (according to RFC 3986), and it was parsed
451    /// with [`UriFlags::ENCODED`][crate::UriFlags::ENCODED], then g_uri_to_string() is guaranteed to return
452    /// a string which is at least semantically equivalent to the source
453    /// URI (according to RFC 3986).
454    ///
455    /// If @self might contain sensitive details, such as authentication parameters,
456    /// or private data in its query string, and the returned string is going to be
457    /// logged, then consider using g_uri_to_string_partial() to redact parts.
458    ///
459    /// # Returns
460    ///
461    /// a string representing @self,
462    ///     which the caller must free.
463    #[doc(alias = "g_uri_to_string")]
464    #[doc(alias = "to_string")]
465    pub fn to_str(&self) -> crate::GString {
466        unsafe { from_glib_full(ffi::g_uri_to_string(self.to_glib_none().0)) }
467    }
468
469    /// Returns a string representing @self, subject to the options in
470    /// @flags. See g_uri_to_string() and #GUriHideFlags for more details.
471    /// ## `flags`
472    /// flags describing what parts of @self to hide
473    ///
474    /// # Returns
475    ///
476    /// a string representing
477    ///     @self, which the caller must free.
478    // rustdoc-stripper-ignore-next-stop
479    /// Returns a string representing @self, subject to the options in
480    /// @flags. See g_uri_to_string() and #GUriHideFlags for more details.
481    /// ## `flags`
482    /// flags describing what parts of @self to hide
483    ///
484    /// # Returns
485    ///
486    /// a string representing
487    ///     @self, which the caller must free.
488    #[doc(alias = "g_uri_to_string_partial")]
489    pub fn to_string_partial(&self, flags: UriHideFlags) -> crate::GString {
490        unsafe {
491            from_glib_full(ffi::g_uri_to_string_partial(
492                self.to_glib_none().0,
493                flags.into_glib(),
494            ))
495        }
496    }
497
498    /// Creates a new #GUri from the given components according to @flags.
499    ///
500    /// See also g_uri_build_with_user(), which allows specifying the
501    /// components of the "userinfo" separately.
502    /// ## `flags`
503    /// flags describing how to build the #GUri
504    /// ## `scheme`
505    /// the URI scheme
506    /// ## `userinfo`
507    /// the userinfo component, or [`None`]
508    /// ## `host`
509    /// the host component, or [`None`]
510    /// ## `port`
511    /// the port, or `-1`
512    /// ## `path`
513    /// the path component
514    /// ## `query`
515    /// the query component, or [`None`]
516    /// ## `fragment`
517    /// the fragment, or [`None`]
518    ///
519    /// # Returns
520    ///
521    /// a new #GUri
522    // rustdoc-stripper-ignore-next-stop
523    /// Creates a new #GUri from the given components according to @flags.
524    ///
525    /// See also g_uri_build_with_user(), which allows specifying the
526    /// components of the "userinfo" separately.
527    /// ## `flags`
528    /// flags describing how to build the #GUri
529    /// ## `scheme`
530    /// the URI scheme
531    /// ## `userinfo`
532    /// the userinfo component, or [`None`]
533    /// ## `host`
534    /// the host component, or [`None`]
535    /// ## `port`
536    /// the port, or `-1`
537    /// ## `path`
538    /// the path component
539    /// ## `query`
540    /// the query component, or [`None`]
541    /// ## `fragment`
542    /// the fragment, or [`None`]
543    ///
544    /// # Returns
545    ///
546    /// a new #GUri
547    #[doc(alias = "g_uri_build")]
548    pub fn build(
549        flags: UriFlags,
550        scheme: &str,
551        userinfo: Option<&str>,
552        host: Option<&str>,
553        port: i32,
554        path: &str,
555        query: Option<&str>,
556        fragment: Option<&str>,
557    ) -> Uri {
558        unsafe {
559            from_glib_full(ffi::g_uri_build(
560                flags.into_glib(),
561                scheme.to_glib_none().0,
562                userinfo.to_glib_none().0,
563                host.to_glib_none().0,
564                port,
565                path.to_glib_none().0,
566                query.to_glib_none().0,
567                fragment.to_glib_none().0,
568            ))
569        }
570    }
571
572    ///  field separately. Note that @user must be non-[`None`]
573    /// if either @password or @auth_params is non-[`None`].
574    /// ## `flags`
575    /// flags describing how to build the #GUri
576    /// ## `scheme`
577    /// the URI scheme
578    /// ## `user`
579    /// the user component of the userinfo, or [`None`]
580    /// ## `password`
581    /// the password component of the userinfo, or [`None`]
582    /// ## `auth_params`
583    /// the auth params of the userinfo, or [`None`]
584    /// ## `host`
585    /// the host component, or [`None`]
586    /// ## `port`
587    /// the port, or `-1`
588    /// ## `path`
589    /// the path component
590    /// ## `query`
591    /// the query component, or [`None`]
592    /// ## `fragment`
593    /// the fragment, or [`None`]
594    ///
595    /// # Returns
596    ///
597    /// a new #GUri
598    // rustdoc-stripper-ignore-next-stop
599    ///  field separately. Note that @user must be non-[`None`]
600    /// if either @password or @auth_params is non-[`None`].
601    /// ## `flags`
602    /// flags describing how to build the #GUri
603    /// ## `scheme`
604    /// the URI scheme
605    /// ## `user`
606    /// the user component of the userinfo, or [`None`]
607    /// ## `password`
608    /// the password component of the userinfo, or [`None`]
609    /// ## `auth_params`
610    /// the auth params of the userinfo, or [`None`]
611    /// ## `host`
612    /// the host component, or [`None`]
613    /// ## `port`
614    /// the port, or `-1`
615    /// ## `path`
616    /// the path component
617    /// ## `query`
618    /// the query component, or [`None`]
619    /// ## `fragment`
620    /// the fragment, or [`None`]
621    ///
622    /// # Returns
623    ///
624    /// a new #GUri
625    #[doc(alias = "g_uri_build_with_user")]
626    pub fn build_with_user(
627        flags: UriFlags,
628        scheme: &str,
629        user: Option<&str>,
630        password: Option<&str>,
631        auth_params: Option<&str>,
632        host: Option<&str>,
633        port: i32,
634        path: &str,
635        query: Option<&str>,
636        fragment: Option<&str>,
637    ) -> Uri {
638        unsafe {
639            from_glib_full(ffi::g_uri_build_with_user(
640                flags.into_glib(),
641                scheme.to_glib_none().0,
642                user.to_glib_none().0,
643                password.to_glib_none().0,
644                auth_params.to_glib_none().0,
645                host.to_glib_none().0,
646                port,
647                path.to_glib_none().0,
648                query.to_glib_none().0,
649                fragment.to_glib_none().0,
650            ))
651        }
652    }
653
654    ///  characters
655    /// in the URI specification, since those are allowed unescaped in some
656    /// portions of a URI.
657    ///
658    /// Though technically incorrect, this will also allow escaping nul
659    /// bytes as `%``00`.
660    /// ## `unescaped`
661    /// the unescaped input data.
662    /// ## `reserved_chars_allowed`
663    /// a string of reserved
664    ///   characters that are allowed to be used, or [`None`].
665    ///
666    /// # Returns
667    ///
668    /// an escaped version of @unescaped.
669    ///     The returned string should be freed when no longer needed.
670    // rustdoc-stripper-ignore-next-stop
671    ///  characters
672    /// in the URI specification, since those are allowed unescaped in some
673    /// portions of a URI.
674    ///
675    /// Though technically incorrect, this will also allow escaping nul
676    /// bytes as `%``00`.
677    /// ## `unescaped`
678    /// the unescaped input data.
679    /// ## `reserved_chars_allowed`
680    /// a string of reserved
681    ///   characters that are allowed to be used, or [`None`].
682    ///
683    /// # Returns
684    ///
685    /// an escaped version of @unescaped.
686    ///     The returned string should be freed when no longer needed.
687    #[doc(alias = "g_uri_escape_bytes")]
688    pub fn escape_bytes(unescaped: &[u8], reserved_chars_allowed: Option<&str>) -> crate::GString {
689        let length = unescaped.len() as _;
690        unsafe {
691            from_glib_full(ffi::g_uri_escape_bytes(
692                unescaped.to_glib_none().0,
693                length,
694                reserved_chars_allowed.to_glib_none().0,
695            ))
696        }
697    }
698
699    /// Escapes a string for use in a URI.
700    ///
701    /// Normally all characters that are not "unreserved" (i.e. ASCII
702    /// alphanumerical characters plus dash, dot, underscore and tilde) are
703    /// escaped. But if you specify characters in @reserved_chars_allowed
704    /// they are not escaped. This is useful for the "reserved" characters
705    /// in the URI specification, since those are allowed unescaped in some
706    /// portions of a URI.
707    /// ## `unescaped`
708    /// the unescaped input string.
709    /// ## `reserved_chars_allowed`
710    /// a string of reserved
711    ///   characters that are allowed to be used, or [`None`].
712    /// ## `allow_utf8`
713    /// [`true`] if the result can include UTF-8 characters.
714    ///
715    /// # Returns
716    ///
717    /// an escaped version of @unescaped. The
718    /// returned string should be freed when no longer needed.
719    // rustdoc-stripper-ignore-next-stop
720    /// Escapes a string for use in a URI.
721    ///
722    /// Normally all characters that are not "unreserved" (i.e. ASCII
723    /// alphanumerical characters plus dash, dot, underscore and tilde) are
724    /// escaped. But if you specify characters in @reserved_chars_allowed
725    /// they are not escaped. This is useful for the "reserved" characters
726    /// in the URI specification, since those are allowed unescaped in some
727    /// portions of a URI.
728    /// ## `unescaped`
729    /// the unescaped input string.
730    /// ## `reserved_chars_allowed`
731    /// a string of reserved
732    ///   characters that are allowed to be used, or [`None`].
733    /// ## `allow_utf8`
734    /// [`true`] if the result can include UTF-8 characters.
735    ///
736    /// # Returns
737    ///
738    /// an escaped version of @unescaped. The
739    /// returned string should be freed when no longer needed.
740    #[doc(alias = "g_uri_escape_string")]
741    pub fn escape_string(
742        unescaped: &str,
743        reserved_chars_allowed: Option<&str>,
744        allow_utf8: bool,
745    ) -> crate::GString {
746        unsafe {
747            from_glib_full(ffi::g_uri_escape_string(
748                unescaped.to_glib_none().0,
749                reserved_chars_allowed.to_glib_none().0,
750                allow_utf8.into_glib(),
751            ))
752        }
753    }
754
755    /// s invalid.
756    ///
757    /// See g_uri_split(), and the definition of #GUriFlags, for more
758    /// information on the effect of @flags.
759    /// ## `uri_string`
760    /// a string containing an absolute URI
761    /// ## `flags`
762    /// flags for parsing @uri_string
763    ///
764    /// # Returns
765    ///
766    /// [`true`] if @uri_string is a valid absolute URI, [`false`] on error.
767    // rustdoc-stripper-ignore-next-stop
768    /// s invalid.
769    ///
770    /// See g_uri_split(), and the definition of #GUriFlags, for more
771    /// information on the effect of @flags.
772    /// ## `uri_string`
773    /// a string containing an absolute URI
774    /// ## `flags`
775    /// flags for parsing @uri_string
776    ///
777    /// # Returns
778    ///
779    /// [`true`] if @uri_string is a valid absolute URI, [`false`] on error.
780    #[doc(alias = "g_uri_is_valid")]
781    pub fn is_valid(uri_string: &str, flags: UriFlags) -> Result<(), crate::Error> {
782        unsafe {
783            let mut error = std::ptr::null_mut();
784            let is_ok =
785                ffi::g_uri_is_valid(uri_string.to_glib_none().0, flags.into_glib(), &mut error);
786            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
787            if error.is_null() {
788                Ok(())
789            } else {
790                Err(from_glib_full(error))
791            }
792        }
793    }
794
795    ///  separately.
796    ///
797    /// [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] and [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS] are ignored if set
798    /// in @flags.
799    /// ## `flags`
800    /// flags describing how to build the URI string
801    /// ## `scheme`
802    /// the URI scheme, or [`None`]
803    /// ## `userinfo`
804    /// the userinfo component, or [`None`]
805    /// ## `host`
806    /// the host component, or [`None`]
807    /// ## `port`
808    /// the port, or `-1`
809    /// ## `path`
810    /// the path component
811    /// ## `query`
812    /// the query component, or [`None`]
813    /// ## `fragment`
814    /// the fragment, or [`None`]
815    ///
816    /// # Returns
817    ///
818    /// an absolute URI string
819    // rustdoc-stripper-ignore-next-stop
820    ///  separately.
821    ///
822    /// [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] and [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS] are ignored if set
823    /// in @flags.
824    /// ## `flags`
825    /// flags describing how to build the URI string
826    /// ## `scheme`
827    /// the URI scheme, or [`None`]
828    /// ## `userinfo`
829    /// the userinfo component, or [`None`]
830    /// ## `host`
831    /// the host component, or [`None`]
832    /// ## `port`
833    /// the port, or `-1`
834    /// ## `path`
835    /// the path component
836    /// ## `query`
837    /// the query component, or [`None`]
838    /// ## `fragment`
839    /// the fragment, or [`None`]
840    ///
841    /// # Returns
842    ///
843    /// an absolute URI string
844    #[doc(alias = "g_uri_join")]
845    pub fn join(
846        flags: UriFlags,
847        scheme: Option<&str>,
848        userinfo: Option<&str>,
849        host: Option<&str>,
850        port: i32,
851        path: &str,
852        query: Option<&str>,
853        fragment: Option<&str>,
854    ) -> crate::GString {
855        unsafe {
856            from_glib_full(ffi::g_uri_join(
857                flags.into_glib(),
858                scheme.to_glib_none().0,
859                userinfo.to_glib_none().0,
860                host.to_glib_none().0,
861                port,
862                path.to_glib_none().0,
863                query.to_glib_none().0,
864                fragment.to_glib_none().0,
865            ))
866        }
867    }
868
869    ///  separately. It otherwise behaves the same.
870    ///
871    /// [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] and [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS] are ignored if set
872    /// in @flags.
873    /// ## `flags`
874    /// flags describing how to build the URI string
875    /// ## `scheme`
876    /// the URI scheme, or [`None`]
877    /// ## `user`
878    /// the user component of the userinfo, or [`None`]
879    /// ## `password`
880    /// the password component of the userinfo, or
881    ///   [`None`]
882    /// ## `auth_params`
883    /// the auth params of the userinfo, or
884    ///   [`None`]
885    /// ## `host`
886    /// the host component, or [`None`]
887    /// ## `port`
888    /// the port, or `-1`
889    /// ## `path`
890    /// the path component
891    /// ## `query`
892    /// the query component, or [`None`]
893    /// ## `fragment`
894    /// the fragment, or [`None`]
895    ///
896    /// # Returns
897    ///
898    /// an absolute URI string
899    // rustdoc-stripper-ignore-next-stop
900    ///  separately. It otherwise behaves the same.
901    ///
902    /// [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] and [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS] are ignored if set
903    /// in @flags.
904    /// ## `flags`
905    /// flags describing how to build the URI string
906    /// ## `scheme`
907    /// the URI scheme, or [`None`]
908    /// ## `user`
909    /// the user component of the userinfo, or [`None`]
910    /// ## `password`
911    /// the password component of the userinfo, or
912    ///   [`None`]
913    /// ## `auth_params`
914    /// the auth params of the userinfo, or
915    ///   [`None`]
916    /// ## `host`
917    /// the host component, or [`None`]
918    /// ## `port`
919    /// the port, or `-1`
920    /// ## `path`
921    /// the path component
922    /// ## `query`
923    /// the query component, or [`None`]
924    /// ## `fragment`
925    /// the fragment, or [`None`]
926    ///
927    /// # Returns
928    ///
929    /// an absolute URI string
930    #[doc(alias = "g_uri_join_with_user")]
931    pub fn join_with_user(
932        flags: UriFlags,
933        scheme: Option<&str>,
934        user: Option<&str>,
935        password: Option<&str>,
936        auth_params: Option<&str>,
937        host: Option<&str>,
938        port: i32,
939        path: &str,
940        query: Option<&str>,
941        fragment: Option<&str>,
942    ) -> crate::GString {
943        unsafe {
944            from_glib_full(ffi::g_uri_join_with_user(
945                flags.into_glib(),
946                scheme.to_glib_none().0,
947                user.to_glib_none().0,
948                password.to_glib_none().0,
949                auth_params.to_glib_none().0,
950                host.to_glib_none().0,
951                port,
952                path.to_glib_none().0,
953                query.to_glib_none().0,
954                fragment.to_glib_none().0,
955            ))
956        }
957    }
958
959    /// Splits an URI list conforming to the text/uri-list
960    /// mime type defined in RFC 2483 into individual URIs,
961    /// discarding any comments. The URIs are not validated.
962    /// ## `uri_list`
963    /// an URI list
964    ///
965    /// # Returns
966    ///
967    /// a newly allocated [`None`]-terminated list
968    ///   of strings holding the individual URIs. The array should be freed
969    ///   with g_strfreev().
970    // rustdoc-stripper-ignore-next-stop
971    /// Splits an URI list conforming to the text/uri-list
972    /// mime type defined in RFC 2483 into individual URIs,
973    /// discarding any comments. The URIs are not validated.
974    /// ## `uri_list`
975    /// an URI list
976    ///
977    /// # Returns
978    ///
979    /// a newly allocated [`None`]-terminated list
980    ///   of strings holding the individual URIs. The array should be freed
981    ///   with g_strfreev().
982    #[doc(alias = "g_uri_list_extract_uris")]
983    pub fn list_extract_uris(uri_list: &str) -> Vec<crate::GString> {
984        unsafe {
985            FromGlibPtrContainer::from_glib_full(ffi::g_uri_list_extract_uris(
986                uri_list.to_glib_none().0,
987            ))
988        }
989    }
990
991    /// Parses @uri_string according to @flags. If the result is not a
992    /// valid [absolute URI](#relative-and-absolute-uris), it will be discarded, and an
993    /// error returned.
994    /// ## `uri_string`
995    /// a string representing an absolute URI
996    /// ## `flags`
997    /// flags describing how to parse @uri_string
998    ///
999    /// # Returns
1000    ///
1001    /// a new #GUri, or NULL on error.
1002    // rustdoc-stripper-ignore-next-stop
1003    /// Parses @uri_string according to @flags. If the result is not a
1004    /// valid [absolute URI](#relative-and-absolute-uris), it will be discarded, and an
1005    /// error returned.
1006    /// ## `uri_string`
1007    /// a string representing an absolute URI
1008    /// ## `flags`
1009    /// flags describing how to parse @uri_string
1010    ///
1011    /// # Returns
1012    ///
1013    /// a new #GUri, or NULL on error.
1014    #[doc(alias = "g_uri_parse")]
1015    pub fn parse(uri_string: &str, flags: UriFlags) -> Result<Uri, crate::Error> {
1016        unsafe {
1017            let mut error = std::ptr::null_mut();
1018            let ret = ffi::g_uri_parse(uri_string.to_glib_none().0, flags.into_glib(), &mut error);
1019            if error.is_null() {
1020                Ok(from_glib_full(ret))
1021            } else {
1022                Err(from_glib_full(error))
1023            }
1024        }
1025    }
1026
1027    //#[doc(alias = "g_uri_parse_params")]
1028    //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> {
1029    //    unsafe { TODO: call ffi:g_uri_parse_params() }
1030    //}
1031
1032    /// Gets the scheme portion of a URI string.
1033    /// [RFC 3986](https://tools.ietf.org/html/rfc3986#section-3) decodes the scheme
1034    /// as:
1035    ///
1036    /// ```text
1037    /// URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
1038    /// ```
1039    /// Common schemes include `file`, `https`, `svn+ssh`, etc.
1040    /// ## `uri`
1041    /// a valid URI.
1042    ///
1043    /// # Returns
1044    ///
1045    ///  component of the URI, or
1046    ///     [`None`] on error. The returned string should be freed when no longer needed.
1047    // rustdoc-stripper-ignore-next-stop
1048    /// Gets the scheme portion of a URI string.
1049    /// [RFC 3986](https://tools.ietf.org/html/rfc3986#section-3) decodes the scheme
1050    /// as:
1051    ///
1052    /// ```text
1053    /// URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
1054    /// ```
1055    /// Common schemes include `file`, `https`, `svn+ssh`, etc.
1056    /// ## `uri`
1057    /// a valid URI.
1058    ///
1059    /// # Returns
1060    ///
1061    ///  component of the URI, or
1062    ///     [`None`] on error. The returned string should be freed when no longer needed.
1063    #[doc(alias = "g_uri_parse_scheme")]
1064    pub fn parse_scheme(uri: &str) -> Option<crate::GString> {
1065        unsafe { from_glib_full(ffi::g_uri_parse_scheme(uri.to_glib_none().0)) }
1066    }
1067
1068    /// Gets the scheme portion of a URI string.
1069    /// [RFC 3986](https://tools.ietf.org/html/rfc3986#section-3) decodes the scheme
1070    /// as:
1071    ///
1072    /// ```text
1073    /// URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
1074    /// ```
1075    /// Common schemes include `file`, `https`, `svn+ssh`, etc.
1076    ///
1077    /// Unlike g_uri_parse_scheme(), the returned scheme is normalized to
1078    /// all-lowercase and does not need to be freed.
1079    /// ## `uri`
1080    /// a valid URI.
1081    ///
1082    /// # Returns
1083    ///
1084    ///  component of the URI, or
1085    ///     [`None`] on error. The returned string is normalized to all-lowercase, and
1086    ///     interned via g_intern_string(), so it does not need to be freed.
1087    // rustdoc-stripper-ignore-next-stop
1088    /// Gets the scheme portion of a URI string.
1089    /// [RFC 3986](https://tools.ietf.org/html/rfc3986#section-3) decodes the scheme
1090    /// as:
1091    ///
1092    /// ```text
1093    /// URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
1094    /// ```
1095    /// Common schemes include `file`, `https`, `svn+ssh`, etc.
1096    ///
1097    /// Unlike g_uri_parse_scheme(), the returned scheme is normalized to
1098    /// all-lowercase and does not need to be freed.
1099    /// ## `uri`
1100    /// a valid URI.
1101    ///
1102    /// # Returns
1103    ///
1104    ///  component of the URI, or
1105    ///     [`None`] on error. The returned string is normalized to all-lowercase, and
1106    ///     interned via g_intern_string(), so it does not need to be freed.
1107    #[doc(alias = "g_uri_peek_scheme")]
1108    pub fn peek_scheme(uri: &str) -> Option<crate::GString> {
1109        unsafe { from_glib_none(ffi::g_uri_peek_scheme(uri.to_glib_none().0)) }
1110    }
1111
1112    /// Parses @uri_ref according to @flags and, if it is a
1113    /// [relative URI](#relative-and-absolute-uris), resolves it relative to
1114    /// @base_uri_string. If the result is not a valid absolute URI, it will be
1115    /// discarded, and an error returned.
1116    ///
1117    /// (If @base_uri_string is [`None`], this just returns @uri_ref, or
1118    /// [`None`] if @uri_ref is invalid or not absolute.)
1119    /// ## `base_uri_string`
1120    /// a string representing a base URI
1121    /// ## `uri_ref`
1122    /// a string representing a relative or absolute URI
1123    /// ## `flags`
1124    /// flags describing how to parse @uri_ref
1125    ///
1126    /// # Returns
1127    ///
1128    /// the resolved URI string,
1129    /// or NULL on error.
1130    // rustdoc-stripper-ignore-next-stop
1131    /// Parses @uri_ref according to @flags and, if it is a
1132    /// [relative URI](#relative-and-absolute-uris), resolves it relative to
1133    /// @base_uri_string. If the result is not a valid absolute URI, it will be
1134    /// discarded, and an error returned.
1135    ///
1136    /// (If @base_uri_string is [`None`], this just returns @uri_ref, or
1137    /// [`None`] if @uri_ref is invalid or not absolute.)
1138    /// ## `base_uri_string`
1139    /// a string representing a base URI
1140    /// ## `uri_ref`
1141    /// a string representing a relative or absolute URI
1142    /// ## `flags`
1143    /// flags describing how to parse @uri_ref
1144    ///
1145    /// # Returns
1146    ///
1147    /// the resolved URI string,
1148    /// or NULL on error.
1149    #[doc(alias = "g_uri_resolve_relative")]
1150    pub fn resolve_relative(
1151        base_uri_string: Option<&str>,
1152        uri_ref: &str,
1153        flags: UriFlags,
1154    ) -> Result<crate::GString, crate::Error> {
1155        unsafe {
1156            let mut error = std::ptr::null_mut();
1157            let ret = ffi::g_uri_resolve_relative(
1158                base_uri_string.to_glib_none().0,
1159                uri_ref.to_glib_none().0,
1160                flags.into_glib(),
1161                &mut error,
1162            );
1163            if error.is_null() {
1164                Ok(from_glib_full(ret))
1165            } else {
1166                Err(from_glib_full(error))
1167            }
1168        }
1169    }
1170
1171    /// Parses @uri_ref (which can be an
1172    /// [absolute or relative URI](#relative-and-absolute-uris)) according to @flags, and
1173    /// returns the pieces. Any component that doesn't appear in @uri_ref will be
1174    /// returned as [`None`] (but note that all URIs always have a path component,
1175    /// though it may be the empty string).
1176    ///
1177    /// If @flags contains [`UriFlags::ENCODED`][crate::UriFlags::ENCODED], then `%`-encoded characters in
1178    /// @uri_ref will remain encoded in the output strings. (If not,
1179    /// then all such characters will be decoded.) Note that decoding will
1180    /// only work if the URI components are ASCII or UTF-8, so you will
1181    /// need to use [`UriFlags::ENCODED`][crate::UriFlags::ENCODED] if they are not.
1182    ///
1183    /// Note that the [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] and
1184    /// [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS] @flags are ignored by g_uri_split(),
1185    /// since it always returns only the full userinfo; use
1186    /// g_uri_split_with_user() if you want it split up.
1187    /// ## `uri_ref`
1188    /// a string containing a relative or absolute URI
1189    /// ## `flags`
1190    /// flags for parsing @uri_ref
1191    ///
1192    /// # Returns
1193    ///
1194    /// [`true`] if @uri_ref parsed successfully, [`false`]
1195    ///   on error.
1196    ///
1197    /// ## `scheme`
1198    /// on return, contains
1199    ///    the scheme (converted to lowercase), or [`None`]
1200    ///
1201    /// ## `userinfo`
1202    /// on return, contains
1203    ///    the userinfo, or [`None`]
1204    ///
1205    /// ## `host`
1206    /// on return, contains the
1207    ///    host, or [`None`]
1208    ///
1209    /// ## `port`
1210    /// on return, contains the
1211    ///    port, or `-1`
1212    ///
1213    /// ## `path`
1214    /// on return, contains the
1215    ///    path
1216    ///
1217    /// ## `query`
1218    /// on return, contains the
1219    ///    query, or [`None`]
1220    ///
1221    /// ## `fragment`
1222    /// on return, contains
1223    ///    the fragment, or [`None`]
1224    // rustdoc-stripper-ignore-next-stop
1225    /// Parses @uri_ref (which can be an
1226    /// [absolute or relative URI](#relative-and-absolute-uris)) according to @flags, and
1227    /// returns the pieces. Any component that doesn't appear in @uri_ref will be
1228    /// returned as [`None`] (but note that all URIs always have a path component,
1229    /// though it may be the empty string).
1230    ///
1231    /// If @flags contains [`UriFlags::ENCODED`][crate::UriFlags::ENCODED], then `%`-encoded characters in
1232    /// @uri_ref will remain encoded in the output strings. (If not,
1233    /// then all such characters will be decoded.) Note that decoding will
1234    /// only work if the URI components are ASCII or UTF-8, so you will
1235    /// need to use [`UriFlags::ENCODED`][crate::UriFlags::ENCODED] if they are not.
1236    ///
1237    /// Note that the [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] and
1238    /// [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS] @flags are ignored by g_uri_split(),
1239    /// since it always returns only the full userinfo; use
1240    /// g_uri_split_with_user() if you want it split up.
1241    /// ## `uri_ref`
1242    /// a string containing a relative or absolute URI
1243    /// ## `flags`
1244    /// flags for parsing @uri_ref
1245    ///
1246    /// # Returns
1247    ///
1248    /// [`true`] if @uri_ref parsed successfully, [`false`]
1249    ///   on error.
1250    ///
1251    /// ## `scheme`
1252    /// on return, contains
1253    ///    the scheme (converted to lowercase), or [`None`]
1254    ///
1255    /// ## `userinfo`
1256    /// on return, contains
1257    ///    the userinfo, or [`None`]
1258    ///
1259    /// ## `host`
1260    /// on return, contains the
1261    ///    host, or [`None`]
1262    ///
1263    /// ## `port`
1264    /// on return, contains the
1265    ///    port, or `-1`
1266    ///
1267    /// ## `path`
1268    /// on return, contains the
1269    ///    path
1270    ///
1271    /// ## `query`
1272    /// on return, contains the
1273    ///    query, or [`None`]
1274    ///
1275    /// ## `fragment`
1276    /// on return, contains
1277    ///    the fragment, or [`None`]
1278    #[doc(alias = "g_uri_split")]
1279    pub fn split(
1280        uri_ref: &str,
1281        flags: UriFlags,
1282    ) -> Result<
1283        (
1284            Option<crate::GString>,
1285            Option<crate::GString>,
1286            Option<crate::GString>,
1287            i32,
1288            crate::GString,
1289            Option<crate::GString>,
1290            Option<crate::GString>,
1291        ),
1292        crate::Error,
1293    > {
1294        unsafe {
1295            let mut scheme = std::ptr::null_mut();
1296            let mut userinfo = std::ptr::null_mut();
1297            let mut host = std::ptr::null_mut();
1298            let mut port = std::mem::MaybeUninit::uninit();
1299            let mut path = std::ptr::null_mut();
1300            let mut query = std::ptr::null_mut();
1301            let mut fragment = std::ptr::null_mut();
1302            let mut error = std::ptr::null_mut();
1303            let is_ok = ffi::g_uri_split(
1304                uri_ref.to_glib_none().0,
1305                flags.into_glib(),
1306                &mut scheme,
1307                &mut userinfo,
1308                &mut host,
1309                port.as_mut_ptr(),
1310                &mut path,
1311                &mut query,
1312                &mut fragment,
1313                &mut error,
1314            );
1315            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
1316            if error.is_null() {
1317                Ok((
1318                    from_glib_full(scheme),
1319                    from_glib_full(userinfo),
1320                    from_glib_full(host),
1321                    port.assume_init(),
1322                    from_glib_full(path),
1323                    from_glib_full(query),
1324                    from_glib_full(fragment),
1325                ))
1326            } else {
1327                Err(from_glib_full(error))
1328            }
1329        }
1330    }
1331
1332    /// Parses @uri_string (which must be an [absolute URI](#relative-and-absolute-uris))
1333    /// according to @flags, and returns the pieces relevant to connecting to a host.
1334    /// See the documentation for g_uri_split() for more details; this is
1335    /// mostly a wrapper around that function with simpler arguments.
1336    /// However, it will return an error if @uri_string is a relative URI,
1337    /// or does not contain a hostname component.
1338    /// ## `uri_string`
1339    /// a string containing an absolute URI
1340    /// ## `flags`
1341    /// flags for parsing @uri_string
1342    ///
1343    /// # Returns
1344    ///
1345    /// [`true`] if @uri_string parsed successfully,
1346    ///   [`false`] on error.
1347    ///
1348    /// ## `scheme`
1349    /// on return, contains
1350    ///    the scheme (converted to lowercase), or [`None`]
1351    ///
1352    /// ## `host`
1353    /// on return, contains the
1354    ///    host, or [`None`]
1355    ///
1356    /// ## `port`
1357    /// on return, contains the
1358    ///    port, or `-1`
1359    // rustdoc-stripper-ignore-next-stop
1360    /// Parses @uri_string (which must be an [absolute URI](#relative-and-absolute-uris))
1361    /// according to @flags, and returns the pieces relevant to connecting to a host.
1362    /// See the documentation for g_uri_split() for more details; this is
1363    /// mostly a wrapper around that function with simpler arguments.
1364    /// However, it will return an error if @uri_string is a relative URI,
1365    /// or does not contain a hostname component.
1366    /// ## `uri_string`
1367    /// a string containing an absolute URI
1368    /// ## `flags`
1369    /// flags for parsing @uri_string
1370    ///
1371    /// # Returns
1372    ///
1373    /// [`true`] if @uri_string parsed successfully,
1374    ///   [`false`] on error.
1375    ///
1376    /// ## `scheme`
1377    /// on return, contains
1378    ///    the scheme (converted to lowercase), or [`None`]
1379    ///
1380    /// ## `host`
1381    /// on return, contains the
1382    ///    host, or [`None`]
1383    ///
1384    /// ## `port`
1385    /// on return, contains the
1386    ///    port, or `-1`
1387    #[doc(alias = "g_uri_split_network")]
1388    pub fn split_network(
1389        uri_string: &str,
1390        flags: UriFlags,
1391    ) -> Result<(Option<crate::GString>, Option<crate::GString>, i32), crate::Error> {
1392        unsafe {
1393            let mut scheme = std::ptr::null_mut();
1394            let mut host = std::ptr::null_mut();
1395            let mut port = std::mem::MaybeUninit::uninit();
1396            let mut error = std::ptr::null_mut();
1397            let is_ok = ffi::g_uri_split_network(
1398                uri_string.to_glib_none().0,
1399                flags.into_glib(),
1400                &mut scheme,
1401                &mut host,
1402                port.as_mut_ptr(),
1403                &mut error,
1404            );
1405            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
1406            if error.is_null() {
1407                Ok((
1408                    from_glib_full(scheme),
1409                    from_glib_full(host),
1410                    port.assume_init(),
1411                ))
1412            } else {
1413                Err(from_glib_full(error))
1414            }
1415        }
1416    }
1417
1418    /// Parses @uri_ref (which can be an
1419    /// [absolute or relative URI](#relative-and-absolute-uris)) according to @flags, and
1420    /// returns the pieces. Any component that doesn't appear in @uri_ref will be
1421    /// returned as [`None`] (but note that all URIs always have a path component,
1422    /// though it may be the empty string).
1423    ///
1424    /// See g_uri_split(), and the definition of #GUriFlags, for more
1425    /// information on the effect of @flags. Note that @password will only
1426    /// be parsed out if @flags contains [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD], and
1427    /// @auth_params will only be parsed out if @flags contains
1428    /// [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS].
1429    /// ## `uri_ref`
1430    /// a string containing a relative or absolute URI
1431    /// ## `flags`
1432    /// flags for parsing @uri_ref
1433    ///
1434    /// # Returns
1435    ///
1436    /// [`true`] if @uri_ref parsed successfully, [`false`]
1437    ///   on error.
1438    ///
1439    /// ## `scheme`
1440    /// on return, contains
1441    ///    the scheme (converted to lowercase), or [`None`]
1442    ///
1443    /// ## `user`
1444    /// on return, contains
1445    ///    the user, or [`None`]
1446    ///
1447    /// ## `password`
1448    /// on return, contains
1449    ///    the password, or [`None`]
1450    ///
1451    /// ## `auth_params`
1452    /// on return, contains
1453    ///    the auth_params, or [`None`]
1454    ///
1455    /// ## `host`
1456    /// on return, contains the
1457    ///    host, or [`None`]
1458    ///
1459    /// ## `port`
1460    /// on return, contains the
1461    ///    port, or `-1`
1462    ///
1463    /// ## `path`
1464    /// on return, contains the
1465    ///    path
1466    ///
1467    /// ## `query`
1468    /// on return, contains the
1469    ///    query, or [`None`]
1470    ///
1471    /// ## `fragment`
1472    /// on return, contains
1473    ///    the fragment, or [`None`]
1474    // rustdoc-stripper-ignore-next-stop
1475    /// Parses @uri_ref (which can be an
1476    /// [absolute or relative URI](#relative-and-absolute-uris)) according to @flags, and
1477    /// returns the pieces. Any component that doesn't appear in @uri_ref will be
1478    /// returned as [`None`] (but note that all URIs always have a path component,
1479    /// though it may be the empty string).
1480    ///
1481    /// See g_uri_split(), and the definition of #GUriFlags, for more
1482    /// information on the effect of @flags. Note that @password will only
1483    /// be parsed out if @flags contains [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD], and
1484    /// @auth_params will only be parsed out if @flags contains
1485    /// [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS].
1486    /// ## `uri_ref`
1487    /// a string containing a relative or absolute URI
1488    /// ## `flags`
1489    /// flags for parsing @uri_ref
1490    ///
1491    /// # Returns
1492    ///
1493    /// [`true`] if @uri_ref parsed successfully, [`false`]
1494    ///   on error.
1495    ///
1496    /// ## `scheme`
1497    /// on return, contains
1498    ///    the scheme (converted to lowercase), or [`None`]
1499    ///
1500    /// ## `user`
1501    /// on return, contains
1502    ///    the user, or [`None`]
1503    ///
1504    /// ## `password`
1505    /// on return, contains
1506    ///    the password, or [`None`]
1507    ///
1508    /// ## `auth_params`
1509    /// on return, contains
1510    ///    the auth_params, or [`None`]
1511    ///
1512    /// ## `host`
1513    /// on return, contains the
1514    ///    host, or [`None`]
1515    ///
1516    /// ## `port`
1517    /// on return, contains the
1518    ///    port, or `-1`
1519    ///
1520    /// ## `path`
1521    /// on return, contains the
1522    ///    path
1523    ///
1524    /// ## `query`
1525    /// on return, contains the
1526    ///    query, or [`None`]
1527    ///
1528    /// ## `fragment`
1529    /// on return, contains
1530    ///    the fragment, or [`None`]
1531    #[doc(alias = "g_uri_split_with_user")]
1532    pub fn split_with_user(
1533        uri_ref: &str,
1534        flags: UriFlags,
1535    ) -> Result<
1536        (
1537            Option<crate::GString>,
1538            Option<crate::GString>,
1539            Option<crate::GString>,
1540            Option<crate::GString>,
1541            Option<crate::GString>,
1542            i32,
1543            crate::GString,
1544            Option<crate::GString>,
1545            Option<crate::GString>,
1546        ),
1547        crate::Error,
1548    > {
1549        unsafe {
1550            let mut scheme = std::ptr::null_mut();
1551            let mut user = std::ptr::null_mut();
1552            let mut password = std::ptr::null_mut();
1553            let mut auth_params = std::ptr::null_mut();
1554            let mut host = std::ptr::null_mut();
1555            let mut port = std::mem::MaybeUninit::uninit();
1556            let mut path = std::ptr::null_mut();
1557            let mut query = std::ptr::null_mut();
1558            let mut fragment = std::ptr::null_mut();
1559            let mut error = std::ptr::null_mut();
1560            let is_ok = ffi::g_uri_split_with_user(
1561                uri_ref.to_glib_none().0,
1562                flags.into_glib(),
1563                &mut scheme,
1564                &mut user,
1565                &mut password,
1566                &mut auth_params,
1567                &mut host,
1568                port.as_mut_ptr(),
1569                &mut path,
1570                &mut query,
1571                &mut fragment,
1572                &mut error,
1573            );
1574            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
1575            if error.is_null() {
1576                Ok((
1577                    from_glib_full(scheme),
1578                    from_glib_full(user),
1579                    from_glib_full(password),
1580                    from_glib_full(auth_params),
1581                    from_glib_full(host),
1582                    port.assume_init(),
1583                    from_glib_full(path),
1584                    from_glib_full(query),
1585                    from_glib_full(fragment),
1586                ))
1587            } else {
1588                Err(from_glib_full(error))
1589            }
1590        }
1591    }
1592
1593    /// Unescapes a segment of an escaped string as binary data.
1594    ///
1595    /// Note that in contrast to g_uri_unescape_string(), this does allow
1596    /// nul bytes to appear in the output.
1597    ///
1598    /// If any of the characters in @illegal_characters appears as an escaped
1599    /// character in @escaped_string, then that is an error and [`None`] will be
1600    /// returned. This is useful if you want to avoid for instance having a slash
1601    /// being expanded in an escaped path element, which might confuse pathname
1602    /// handling.
1603    /// ## `escaped_string`
1604    /// A URI-escaped string
1605    /// ## `length`
1606    /// the length (in bytes) of @escaped_string to escape, or `-1` if it
1607    ///   is nul-terminated.
1608    /// ## `illegal_characters`
1609    /// a string of illegal characters
1610    ///   not to be allowed, or [`None`].
1611    ///
1612    /// # Returns
1613    ///
1614    /// an unescaped version of @escaped_string
1615    ///     or [`None`] on error (if decoding failed, using [`UriError::Failed`][crate::UriError::Failed] error
1616    ///     code). The returned #GBytes should be unreffed when no longer needed.
1617    // rustdoc-stripper-ignore-next-stop
1618    /// Unescapes a segment of an escaped string as binary data.
1619    ///
1620    /// Note that in contrast to g_uri_unescape_string(), this does allow
1621    /// nul bytes to appear in the output.
1622    ///
1623    /// If any of the characters in @illegal_characters appears as an escaped
1624    /// character in @escaped_string, then that is an error and [`None`] will be
1625    /// returned. This is useful if you want to avoid for instance having a slash
1626    /// being expanded in an escaped path element, which might confuse pathname
1627    /// handling.
1628    /// ## `escaped_string`
1629    /// A URI-escaped string
1630    /// ## `length`
1631    /// the length (in bytes) of @escaped_string to escape, or `-1` if it
1632    ///   is nul-terminated.
1633    /// ## `illegal_characters`
1634    /// a string of illegal characters
1635    ///   not to be allowed, or [`None`].
1636    ///
1637    /// # Returns
1638    ///
1639    /// an unescaped version of @escaped_string
1640    ///     or [`None`] on error (if decoding failed, using [`UriError::Failed`][crate::UriError::Failed] error
1641    ///     code). The returned #GBytes should be unreffed when no longer needed.
1642    #[doc(alias = "g_uri_unescape_bytes")]
1643    pub fn unescape_bytes(
1644        escaped_string: &str,
1645        illegal_characters: Option<&str>,
1646    ) -> Result<Bytes, crate::Error> {
1647        let length = escaped_string.len() as _;
1648        unsafe {
1649            let mut error = std::ptr::null_mut();
1650            let ret = ffi::g_uri_unescape_bytes(
1651                escaped_string.to_glib_none().0,
1652                length,
1653                illegal_characters.to_glib_none().0,
1654                &mut error,
1655            );
1656            if error.is_null() {
1657                Ok(from_glib_full(ret))
1658            } else {
1659                Err(from_glib_full(error))
1660            }
1661        }
1662    }
1663
1664    /// Unescapes a segment of an escaped string.
1665    ///
1666    /// If any of the characters in @illegal_characters or the NUL
1667    /// character appears as an escaped character in @escaped_string, then
1668    /// that is an error and [`None`] will be returned. This is useful if you
1669    /// want to avoid for instance having a slash being expanded in an
1670    /// escaped path element, which might confuse pathname handling.
1671    ///
1672    /// Note: `NUL` byte is not accepted in the output, in contrast to
1673    /// g_uri_unescape_bytes().
1674    /// ## `escaped_string`
1675    /// A string, may be [`None`]
1676    /// ## `escaped_string_end`
1677    /// Pointer to end of @escaped_string,
1678    ///   may be [`None`]
1679    /// ## `illegal_characters`
1680    /// An optional string of illegal
1681    ///   characters not to be allowed, may be [`None`]
1682    ///
1683    /// # Returns
1684    ///
1685    /// an unescaped version of @escaped_string,
1686    /// or [`None`] on error. The returned string should be freed when no longer
1687    /// needed.  As a special case if [`None`] is given for @escaped_string, this
1688    /// function will return [`None`].
1689    // rustdoc-stripper-ignore-next-stop
1690    /// Unescapes a segment of an escaped string.
1691    ///
1692    /// If any of the characters in @illegal_characters or the NUL
1693    /// character appears as an escaped character in @escaped_string, then
1694    /// that is an error and [`None`] will be returned. This is useful if you
1695    /// want to avoid for instance having a slash being expanded in an
1696    /// escaped path element, which might confuse pathname handling.
1697    ///
1698    /// Note: `NUL` byte is not accepted in the output, in contrast to
1699    /// g_uri_unescape_bytes().
1700    /// ## `escaped_string`
1701    /// A string, may be [`None`]
1702    /// ## `escaped_string_end`
1703    /// Pointer to end of @escaped_string,
1704    ///   may be [`None`]
1705    /// ## `illegal_characters`
1706    /// An optional string of illegal
1707    ///   characters not to be allowed, may be [`None`]
1708    ///
1709    /// # Returns
1710    ///
1711    /// an unescaped version of @escaped_string,
1712    /// or [`None`] on error. The returned string should be freed when no longer
1713    /// needed.  As a special case if [`None`] is given for @escaped_string, this
1714    /// function will return [`None`].
1715    #[doc(alias = "g_uri_unescape_segment")]
1716    pub fn unescape_segment(
1717        escaped_string: Option<&str>,
1718        escaped_string_end: Option<&str>,
1719        illegal_characters: Option<&str>,
1720    ) -> Option<crate::GString> {
1721        unsafe {
1722            from_glib_full(ffi::g_uri_unescape_segment(
1723                escaped_string.to_glib_none().0,
1724                escaped_string_end.to_glib_none().0,
1725                illegal_characters.to_glib_none().0,
1726            ))
1727        }
1728    }
1729
1730    /// Unescapes a whole escaped string.
1731    ///
1732    /// If any of the characters in @illegal_characters or the NUL
1733    /// character appears as an escaped character in @escaped_string, then
1734    /// that is an error and [`None`] will be returned. This is useful if you
1735    /// want to avoid for instance having a slash being expanded in an
1736    /// escaped path element, which might confuse pathname handling.
1737    /// ## `escaped_string`
1738    /// an escaped string to be unescaped.
1739    /// ## `illegal_characters`
1740    /// a string of illegal characters
1741    ///   not to be allowed, or [`None`].
1742    ///
1743    /// # Returns
1744    ///
1745    /// an unescaped version of @escaped_string.
1746    /// The returned string should be freed when no longer needed.
1747    // rustdoc-stripper-ignore-next-stop
1748    /// Unescapes a whole escaped string.
1749    ///
1750    /// If any of the characters in @illegal_characters or the NUL
1751    /// character appears as an escaped character in @escaped_string, then
1752    /// that is an error and [`None`] will be returned. This is useful if you
1753    /// want to avoid for instance having a slash being expanded in an
1754    /// escaped path element, which might confuse pathname handling.
1755    /// ## `escaped_string`
1756    /// an escaped string to be unescaped.
1757    /// ## `illegal_characters`
1758    /// a string of illegal characters
1759    ///   not to be allowed, or [`None`].
1760    ///
1761    /// # Returns
1762    ///
1763    /// an unescaped version of @escaped_string.
1764    /// The returned string should be freed when no longer needed.
1765    #[doc(alias = "g_uri_unescape_string")]
1766    pub fn unescape_string(
1767        escaped_string: &str,
1768        illegal_characters: Option<&str>,
1769    ) -> Option<crate::GString> {
1770        unsafe {
1771            from_glib_full(ffi::g_uri_unescape_string(
1772                escaped_string.to_glib_none().0,
1773                illegal_characters.to_glib_none().0,
1774            ))
1775        }
1776    }
1777}
1778
1779impl std::fmt::Display for Uri {
1780    #[inline]
1781    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1782        f.write_str(&self.to_str())
1783    }
1784}
1785
1786unsafe impl Send for Uri {}
1787unsafe impl Sync for Uri {}