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    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
71    pub struct Uri(Shared<ffi::GUri>);
72
73    match fn {
74        ref => |ptr| ffi::g_uri_ref(ptr),
75        unref => |ptr| ffi::g_uri_unref(ptr),
76        type_ => || ffi::g_uri_get_type(),
77    }
78}
79
80impl Uri {
81    /// Gets @self's authentication parameters, which may contain
82    /// `%`-encoding, depending on the flags with which @self was created.
83    /// (If @self was not created with [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS] then this will
84    /// be [`None`].)
85    ///
86    /// Depending on the URI scheme, g_uri_parse_params() may be useful for
87    /// further parsing this information.
88    ///
89    /// # Returns
90    ///
91    /// @self's authentication parameters.
92    #[doc(alias = "g_uri_get_auth_params")]
93    #[doc(alias = "get_auth_params")]
94    pub fn auth_params(&self) -> Option<crate::GString> {
95        unsafe { from_glib_none(ffi::g_uri_get_auth_params(self.to_glib_none().0)) }
96    }
97
98    /// Gets @self's flags set upon construction.
99    ///
100    /// # Returns
101    ///
102    /// @self's flags.
103    #[doc(alias = "g_uri_get_flags")]
104    #[doc(alias = "get_flags")]
105    pub fn flags(&self) -> UriFlags {
106        unsafe { from_glib(ffi::g_uri_get_flags(self.to_glib_none().0)) }
107    }
108
109    /// Gets @self's fragment, which may contain `%`-encoding, depending on
110    /// the flags with which @self was created.
111    ///
112    /// # Returns
113    ///
114    /// @self's fragment.
115    #[doc(alias = "g_uri_get_fragment")]
116    #[doc(alias = "get_fragment")]
117    pub fn fragment(&self) -> Option<crate::GString> {
118        unsafe { from_glib_none(ffi::g_uri_get_fragment(self.to_glib_none().0)) }
119    }
120
121    /// Gets @self's host. This will never have `%`-encoded characters,
122    /// unless it is non-UTF-8 (which can only be the case if @self was
123    /// created with [`UriFlags::NON_DNS`][crate::UriFlags::NON_DNS]).
124    ///
125    /// If @self contained an IPv6 address literal, this value will be just
126    /// that address, without the brackets around it that are necessary in
127    /// the string form of the URI. Note that in this case there may also
128    /// be a scope ID attached to the address. Eg, `fe80::1234%``em1` (or
129    /// `fe80::1234%``25em1` if the string is still encoded).
130    ///
131    /// # Returns
132    ///
133    /// @self's host.
134    #[doc(alias = "g_uri_get_host")]
135    #[doc(alias = "get_host")]
136    pub fn host(&self) -> Option<crate::GString> {
137        unsafe { from_glib_none(ffi::g_uri_get_host(self.to_glib_none().0)) }
138    }
139
140    /// Gets @self's password, which may contain `%`-encoding, depending on
141    /// the flags with which @self was created. (If @self was not created
142    /// with [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] then this will be [`None`].)
143    ///
144    /// # Returns
145    ///
146    /// @self's password.
147    #[doc(alias = "g_uri_get_password")]
148    #[doc(alias = "get_password")]
149    pub fn password(&self) -> Option<crate::GString> {
150        unsafe { from_glib_none(ffi::g_uri_get_password(self.to_glib_none().0)) }
151    }
152
153    /// Gets @self's path, which may contain `%`-encoding, depending on the
154    /// flags with which @self was created.
155    ///
156    /// # Returns
157    ///
158    /// @self's path.
159    #[doc(alias = "g_uri_get_path")]
160    #[doc(alias = "get_path")]
161    pub fn path(&self) -> crate::GString {
162        unsafe { from_glib_none(ffi::g_uri_get_path(self.to_glib_none().0)) }
163    }
164
165    /// Gets @self's port.
166    ///
167    /// # Returns
168    ///
169    /// @self's port, or `-1` if no port was specified.
170    #[doc(alias = "g_uri_get_port")]
171    #[doc(alias = "get_port")]
172    pub fn port(&self) -> i32 {
173        unsafe { ffi::g_uri_get_port(self.to_glib_none().0) }
174    }
175
176    /// Gets @self's query, which may contain `%`-encoding, depending on the
177    /// flags with which @self was created.
178    ///
179    /// For queries consisting of a series of `name=value` parameters,
180    /// #GUriParamsIter or g_uri_parse_params() may be useful.
181    ///
182    /// # Returns
183    ///
184    /// @self's query.
185    #[doc(alias = "g_uri_get_query")]
186    #[doc(alias = "get_query")]
187    pub fn query(&self) -> Option<crate::GString> {
188        unsafe { from_glib_none(ffi::g_uri_get_query(self.to_glib_none().0)) }
189    }
190
191    /// Gets @self's scheme. Note that this will always be all-lowercase,
192    /// regardless of the string or strings that @self was created from.
193    ///
194    /// # Returns
195    ///
196    /// @self's scheme.
197    #[doc(alias = "g_uri_get_scheme")]
198    #[doc(alias = "get_scheme")]
199    pub fn scheme(&self) -> crate::GString {
200        unsafe { from_glib_none(ffi::g_uri_get_scheme(self.to_glib_none().0)) }
201    }
202
203    ///  component of @self's userinfo, which may contain
204    /// `%`-encoding, depending on the flags with which @self was created.
205    /// If @self was not created with [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] or
206    /// [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS], this is the same as g_uri_get_userinfo().
207    ///
208    /// # Returns
209    ///
210    /// @self's user.
211    #[doc(alias = "g_uri_get_user")]
212    #[doc(alias = "get_user")]
213    pub fn user(&self) -> Option<crate::GString> {
214        unsafe { from_glib_none(ffi::g_uri_get_user(self.to_glib_none().0)) }
215    }
216
217    /// Gets @self's userinfo, which may contain `%`-encoding, depending on
218    /// the flags with which @self was created.
219    ///
220    /// # Returns
221    ///
222    /// @self's userinfo.
223    #[doc(alias = "g_uri_get_userinfo")]
224    #[doc(alias = "get_userinfo")]
225    pub fn userinfo(&self) -> Option<crate::GString> {
226        unsafe { from_glib_none(ffi::g_uri_get_userinfo(self.to_glib_none().0)) }
227    }
228
229    /// Parses @uri_ref according to @flags and, if it is a
230    /// [relative URI](#relative-and-absolute-uris), resolves it relative to @self.
231    /// If the result is not a valid absolute URI, it will be discarded, and an error
232    /// returned.
233    /// ## `uri_ref`
234    /// a string representing a relative or absolute URI
235    /// ## `flags`
236    /// flags describing how to parse @uri_ref
237    ///
238    /// # Returns
239    ///
240    /// a new #GUri, or NULL on error.
241    #[doc(alias = "g_uri_parse_relative")]
242    pub fn parse_relative(&self, uri_ref: &str, flags: UriFlags) -> Result<Uri, crate::Error> {
243        unsafe {
244            let mut error = std::ptr::null_mut();
245            let ret = ffi::g_uri_parse_relative(
246                self.to_glib_none().0,
247                uri_ref.to_glib_none().0,
248                flags.into_glib(),
249                &mut error,
250            );
251            if error.is_null() {
252                Ok(from_glib_full(ret))
253            } else {
254                Err(from_glib_full(error))
255            }
256        }
257    }
258
259    /// Returns a string representing @self.
260    ///
261    /// This is not guaranteed to return a string which is identical to the
262    /// string that @self was parsed from. However, if the source URI was
263    /// syntactically correct (according to RFC 3986), and it was parsed
264    /// with [`UriFlags::ENCODED`][crate::UriFlags::ENCODED], then g_uri_to_string() is guaranteed to return
265    /// a string which is at least semantically equivalent to the source
266    /// URI (according to RFC 3986).
267    ///
268    /// If @self might contain sensitive details, such as authentication parameters,
269    /// or private data in its query string, and the returned string is going to be
270    /// logged, then consider using g_uri_to_string_partial() to redact parts.
271    ///
272    /// # Returns
273    ///
274    /// a string representing @self,
275    ///     which the caller must free.
276    #[doc(alias = "g_uri_to_string")]
277    #[doc(alias = "to_string")]
278    pub fn to_str(&self) -> crate::GString {
279        unsafe { from_glib_full(ffi::g_uri_to_string(self.to_glib_none().0)) }
280    }
281
282    /// Returns a string representing @self, subject to the options in
283    /// @flags. See g_uri_to_string() and #GUriHideFlags for more details.
284    /// ## `flags`
285    /// flags describing what parts of @self to hide
286    ///
287    /// # Returns
288    ///
289    /// a string representing
290    ///     @self, which the caller must free.
291    #[doc(alias = "g_uri_to_string_partial")]
292    pub fn to_string_partial(&self, flags: UriHideFlags) -> crate::GString {
293        unsafe {
294            from_glib_full(ffi::g_uri_to_string_partial(
295                self.to_glib_none().0,
296                flags.into_glib(),
297            ))
298        }
299    }
300
301    /// Creates a new #GUri from the given components according to @flags.
302    ///
303    /// See also g_uri_build_with_user(), which allows specifying the
304    /// components of the "userinfo" separately.
305    /// ## `flags`
306    /// flags describing how to build the #GUri
307    /// ## `scheme`
308    /// the URI scheme
309    /// ## `userinfo`
310    /// the userinfo component, or [`None`]
311    /// ## `host`
312    /// the host component, or [`None`]
313    /// ## `port`
314    /// the port, or `-1`
315    /// ## `path`
316    /// the path component
317    /// ## `query`
318    /// the query component, or [`None`]
319    /// ## `fragment`
320    /// the fragment, or [`None`]
321    ///
322    /// # Returns
323    ///
324    /// a new #GUri
325    #[doc(alias = "g_uri_build")]
326    pub fn build(
327        flags: UriFlags,
328        scheme: &str,
329        userinfo: Option<&str>,
330        host: Option<&str>,
331        port: i32,
332        path: &str,
333        query: Option<&str>,
334        fragment: Option<&str>,
335    ) -> Uri {
336        unsafe {
337            from_glib_full(ffi::g_uri_build(
338                flags.into_glib(),
339                scheme.to_glib_none().0,
340                userinfo.to_glib_none().0,
341                host.to_glib_none().0,
342                port,
343                path.to_glib_none().0,
344                query.to_glib_none().0,
345                fragment.to_glib_none().0,
346            ))
347        }
348    }
349
350    ///  field separately. Note that @user must be non-[`None`]
351    /// if either @password or @auth_params is non-[`None`].
352    /// ## `flags`
353    /// flags describing how to build the #GUri
354    /// ## `scheme`
355    /// the URI scheme
356    /// ## `user`
357    /// the user component of the userinfo, or [`None`]
358    /// ## `password`
359    /// the password component of the userinfo, or [`None`]
360    /// ## `auth_params`
361    /// the auth params of the userinfo, or [`None`]
362    /// ## `host`
363    /// the host component, or [`None`]
364    /// ## `port`
365    /// the port, or `-1`
366    /// ## `path`
367    /// the path component
368    /// ## `query`
369    /// the query component, or [`None`]
370    /// ## `fragment`
371    /// the fragment, or [`None`]
372    ///
373    /// # Returns
374    ///
375    /// a new #GUri
376    #[doc(alias = "g_uri_build_with_user")]
377    pub fn build_with_user(
378        flags: UriFlags,
379        scheme: &str,
380        user: Option<&str>,
381        password: Option<&str>,
382        auth_params: Option<&str>,
383        host: Option<&str>,
384        port: i32,
385        path: &str,
386        query: Option<&str>,
387        fragment: Option<&str>,
388    ) -> Uri {
389        unsafe {
390            from_glib_full(ffi::g_uri_build_with_user(
391                flags.into_glib(),
392                scheme.to_glib_none().0,
393                user.to_glib_none().0,
394                password.to_glib_none().0,
395                auth_params.to_glib_none().0,
396                host.to_glib_none().0,
397                port,
398                path.to_glib_none().0,
399                query.to_glib_none().0,
400                fragment.to_glib_none().0,
401            ))
402        }
403    }
404
405    ///  characters
406    /// in the URI specification, since those are allowed unescaped in some
407    /// portions of a URI.
408    ///
409    /// Though technically incorrect, this will also allow escaping nul
410    /// bytes as `%``00`.
411    /// ## `unescaped`
412    /// the unescaped input data.
413    /// ## `reserved_chars_allowed`
414    /// a string of reserved
415    ///   characters that are allowed to be used, or [`None`].
416    ///
417    /// # Returns
418    ///
419    /// an escaped version of @unescaped.
420    ///     The returned string should be freed when no longer needed.
421    #[doc(alias = "g_uri_escape_bytes")]
422    pub fn escape_bytes(unescaped: &[u8], reserved_chars_allowed: Option<&str>) -> crate::GString {
423        let length = unescaped.len() as _;
424        unsafe {
425            from_glib_full(ffi::g_uri_escape_bytes(
426                unescaped.to_glib_none().0,
427                length,
428                reserved_chars_allowed.to_glib_none().0,
429            ))
430        }
431    }
432
433    /// Escapes a string for use in a URI.
434    ///
435    /// Normally all characters that are not "unreserved" (i.e. ASCII
436    /// alphanumerical characters plus dash, dot, underscore and tilde) are
437    /// escaped. But if you specify characters in @reserved_chars_allowed
438    /// they are not escaped. This is useful for the "reserved" characters
439    /// in the URI specification, since those are allowed unescaped in some
440    /// portions of a URI.
441    /// ## `unescaped`
442    /// the unescaped input string.
443    /// ## `reserved_chars_allowed`
444    /// a string of reserved
445    ///   characters that are allowed to be used, or [`None`].
446    /// ## `allow_utf8`
447    /// [`true`] if the result can include UTF-8 characters.
448    ///
449    /// # Returns
450    ///
451    /// an escaped version of @unescaped. The
452    /// returned string should be freed when no longer needed.
453    #[doc(alias = "g_uri_escape_string")]
454    pub fn escape_string(
455        unescaped: &str,
456        reserved_chars_allowed: Option<&str>,
457        allow_utf8: bool,
458    ) -> crate::GString {
459        unsafe {
460            from_glib_full(ffi::g_uri_escape_string(
461                unescaped.to_glib_none().0,
462                reserved_chars_allowed.to_glib_none().0,
463                allow_utf8.into_glib(),
464            ))
465        }
466    }
467
468    /// s invalid.
469    ///
470    /// See g_uri_split(), and the definition of #GUriFlags, for more
471    /// information on the effect of @flags.
472    /// ## `uri_string`
473    /// a string containing an absolute URI
474    /// ## `flags`
475    /// flags for parsing @uri_string
476    ///
477    /// # Returns
478    ///
479    /// [`true`] if @uri_string is a valid absolute URI, [`false`] on error.
480    #[doc(alias = "g_uri_is_valid")]
481    pub fn is_valid(uri_string: &str, flags: UriFlags) -> Result<(), crate::Error> {
482        unsafe {
483            let mut error = std::ptr::null_mut();
484            let is_ok =
485                ffi::g_uri_is_valid(uri_string.to_glib_none().0, flags.into_glib(), &mut error);
486            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
487            if error.is_null() {
488                Ok(())
489            } else {
490                Err(from_glib_full(error))
491            }
492        }
493    }
494
495    ///  separately.
496    ///
497    /// [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] and [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS] are ignored if set
498    /// in @flags.
499    /// ## `flags`
500    /// flags describing how to build the URI string
501    /// ## `scheme`
502    /// the URI scheme, or [`None`]
503    /// ## `userinfo`
504    /// the userinfo component, or [`None`]
505    /// ## `host`
506    /// the host component, or [`None`]
507    /// ## `port`
508    /// the port, or `-1`
509    /// ## `path`
510    /// the path component
511    /// ## `query`
512    /// the query component, or [`None`]
513    /// ## `fragment`
514    /// the fragment, or [`None`]
515    ///
516    /// # Returns
517    ///
518    /// an absolute URI string
519    #[doc(alias = "g_uri_join")]
520    pub fn join(
521        flags: UriFlags,
522        scheme: Option<&str>,
523        userinfo: Option<&str>,
524        host: Option<&str>,
525        port: i32,
526        path: &str,
527        query: Option<&str>,
528        fragment: Option<&str>,
529    ) -> crate::GString {
530        unsafe {
531            from_glib_full(ffi::g_uri_join(
532                flags.into_glib(),
533                scheme.to_glib_none().0,
534                userinfo.to_glib_none().0,
535                host.to_glib_none().0,
536                port,
537                path.to_glib_none().0,
538                query.to_glib_none().0,
539                fragment.to_glib_none().0,
540            ))
541        }
542    }
543
544    ///  separately. It otherwise behaves the same.
545    ///
546    /// [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] and [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS] are ignored if set
547    /// in @flags.
548    /// ## `flags`
549    /// flags describing how to build the URI string
550    /// ## `scheme`
551    /// the URI scheme, or [`None`]
552    /// ## `user`
553    /// the user component of the userinfo, or [`None`]
554    /// ## `password`
555    /// the password component of the userinfo, or
556    ///   [`None`]
557    /// ## `auth_params`
558    /// the auth params of the userinfo, or
559    ///   [`None`]
560    /// ## `host`
561    /// the host component, or [`None`]
562    /// ## `port`
563    /// the port, or `-1`
564    /// ## `path`
565    /// the path component
566    /// ## `query`
567    /// the query component, or [`None`]
568    /// ## `fragment`
569    /// the fragment, or [`None`]
570    ///
571    /// # Returns
572    ///
573    /// an absolute URI string
574    #[doc(alias = "g_uri_join_with_user")]
575    pub fn join_with_user(
576        flags: UriFlags,
577        scheme: Option<&str>,
578        user: Option<&str>,
579        password: Option<&str>,
580        auth_params: Option<&str>,
581        host: Option<&str>,
582        port: i32,
583        path: &str,
584        query: Option<&str>,
585        fragment: Option<&str>,
586    ) -> crate::GString {
587        unsafe {
588            from_glib_full(ffi::g_uri_join_with_user(
589                flags.into_glib(),
590                scheme.to_glib_none().0,
591                user.to_glib_none().0,
592                password.to_glib_none().0,
593                auth_params.to_glib_none().0,
594                host.to_glib_none().0,
595                port,
596                path.to_glib_none().0,
597                query.to_glib_none().0,
598                fragment.to_glib_none().0,
599            ))
600        }
601    }
602
603    /// Splits an URI list conforming to the text/uri-list
604    /// mime type defined in RFC 2483 into individual URIs,
605    /// discarding any comments. The URIs are not validated.
606    /// ## `uri_list`
607    /// an URI list
608    ///
609    /// # Returns
610    ///
611    /// a newly allocated [`None`]-terminated list
612    ///   of strings holding the individual URIs. The array should be freed
613    ///   with g_strfreev().
614    #[doc(alias = "g_uri_list_extract_uris")]
615    pub fn list_extract_uris(uri_list: &str) -> Vec<crate::GString> {
616        unsafe {
617            FromGlibPtrContainer::from_glib_full(ffi::g_uri_list_extract_uris(
618                uri_list.to_glib_none().0,
619            ))
620        }
621    }
622
623    /// Parses @uri_string according to @flags. If the result is not a
624    /// valid [absolute URI](#relative-and-absolute-uris), it will be discarded, and an
625    /// error returned.
626    /// ## `uri_string`
627    /// a string representing an absolute URI
628    /// ## `flags`
629    /// flags describing how to parse @uri_string
630    ///
631    /// # Returns
632    ///
633    /// a new #GUri, or NULL on error.
634    #[doc(alias = "g_uri_parse")]
635    pub fn parse(uri_string: &str, flags: UriFlags) -> Result<Uri, crate::Error> {
636        unsafe {
637            let mut error = std::ptr::null_mut();
638            let ret = ffi::g_uri_parse(uri_string.to_glib_none().0, flags.into_glib(), &mut error);
639            if error.is_null() {
640                Ok(from_glib_full(ret))
641            } else {
642                Err(from_glib_full(error))
643            }
644        }
645    }
646
647    //#[doc(alias = "g_uri_parse_params")]
648    //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> {
649    //    unsafe { TODO: call ffi:g_uri_parse_params() }
650    //}
651
652    /// Gets the scheme portion of a URI string.
653    /// [RFC 3986](https://tools.ietf.org/html/rfc3986#section-3) decodes the scheme
654    /// as:
655    ///
656    /// ```text
657    /// URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
658    /// ```
659    /// Common schemes include `file`, `https`, `svn+ssh`, etc.
660    /// ## `uri`
661    /// a valid URI.
662    ///
663    /// # Returns
664    ///
665    ///  component of the URI, or
666    ///     [`None`] on error. The returned string should be freed when no longer needed.
667    #[doc(alias = "g_uri_parse_scheme")]
668    pub fn parse_scheme(uri: &str) -> Option<crate::GString> {
669        unsafe { from_glib_full(ffi::g_uri_parse_scheme(uri.to_glib_none().0)) }
670    }
671
672    /// Gets the scheme portion of a URI string.
673    /// [RFC 3986](https://tools.ietf.org/html/rfc3986#section-3) decodes the scheme
674    /// as:
675    ///
676    /// ```text
677    /// URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
678    /// ```
679    /// Common schemes include `file`, `https`, `svn+ssh`, etc.
680    ///
681    /// Unlike g_uri_parse_scheme(), the returned scheme is normalized to
682    /// all-lowercase and does not need to be freed.
683    /// ## `uri`
684    /// a valid URI.
685    ///
686    /// # Returns
687    ///
688    ///  component of the URI, or
689    ///     [`None`] on error. The returned string is normalized to all-lowercase, and
690    ///     interned via g_intern_string(), so it does not need to be freed.
691    #[doc(alias = "g_uri_peek_scheme")]
692    pub fn peek_scheme(uri: &str) -> Option<crate::GString> {
693        unsafe { from_glib_none(ffi::g_uri_peek_scheme(uri.to_glib_none().0)) }
694    }
695
696    /// Parses @uri_ref according to @flags and, if it is a
697    /// [relative URI](#relative-and-absolute-uris), resolves it relative to
698    /// @base_uri_string. If the result is not a valid absolute URI, it will be
699    /// discarded, and an error returned.
700    ///
701    /// (If @base_uri_string is [`None`], this just returns @uri_ref, or
702    /// [`None`] if @uri_ref is invalid or not absolute.)
703    /// ## `base_uri_string`
704    /// a string representing a base URI
705    /// ## `uri_ref`
706    /// a string representing a relative or absolute URI
707    /// ## `flags`
708    /// flags describing how to parse @uri_ref
709    ///
710    /// # Returns
711    ///
712    /// the resolved URI string,
713    /// or NULL on error.
714    #[doc(alias = "g_uri_resolve_relative")]
715    pub fn resolve_relative(
716        base_uri_string: Option<&str>,
717        uri_ref: &str,
718        flags: UriFlags,
719    ) -> Result<crate::GString, crate::Error> {
720        unsafe {
721            let mut error = std::ptr::null_mut();
722            let ret = ffi::g_uri_resolve_relative(
723                base_uri_string.to_glib_none().0,
724                uri_ref.to_glib_none().0,
725                flags.into_glib(),
726                &mut error,
727            );
728            if error.is_null() {
729                Ok(from_glib_full(ret))
730            } else {
731                Err(from_glib_full(error))
732            }
733        }
734    }
735
736    /// Parses @uri_ref (which can be an
737    /// [absolute or relative URI](#relative-and-absolute-uris)) according to @flags, and
738    /// returns the pieces. Any component that doesn't appear in @uri_ref will be
739    /// returned as [`None`] (but note that all URIs always have a path component,
740    /// though it may be the empty string).
741    ///
742    /// If @flags contains [`UriFlags::ENCODED`][crate::UriFlags::ENCODED], then `%`-encoded characters in
743    /// @uri_ref will remain encoded in the output strings. (If not,
744    /// then all such characters will be decoded.) Note that decoding will
745    /// only work if the URI components are ASCII or UTF-8, so you will
746    /// need to use [`UriFlags::ENCODED`][crate::UriFlags::ENCODED] if they are not.
747    ///
748    /// Note that the [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD] and
749    /// [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS] @flags are ignored by g_uri_split(),
750    /// since it always returns only the full userinfo; use
751    /// g_uri_split_with_user() if you want it split up.
752    /// ## `uri_ref`
753    /// a string containing a relative or absolute URI
754    /// ## `flags`
755    /// flags for parsing @uri_ref
756    ///
757    /// # Returns
758    ///
759    /// [`true`] if @uri_ref parsed successfully, [`false`]
760    ///   on error.
761    ///
762    /// ## `scheme`
763    /// on return, contains
764    ///    the scheme (converted to lowercase), or [`None`]
765    ///
766    /// ## `userinfo`
767    /// on return, contains
768    ///    the userinfo, or [`None`]
769    ///
770    /// ## `host`
771    /// on return, contains the
772    ///    host, or [`None`]
773    ///
774    /// ## `port`
775    /// on return, contains the
776    ///    port, or `-1`
777    ///
778    /// ## `path`
779    /// on return, contains the
780    ///    path
781    ///
782    /// ## `query`
783    /// on return, contains the
784    ///    query, or [`None`]
785    ///
786    /// ## `fragment`
787    /// on return, contains
788    ///    the fragment, or [`None`]
789    #[doc(alias = "g_uri_split")]
790    pub fn split(
791        uri_ref: &str,
792        flags: UriFlags,
793    ) -> Result<
794        (
795            Option<crate::GString>,
796            Option<crate::GString>,
797            Option<crate::GString>,
798            i32,
799            crate::GString,
800            Option<crate::GString>,
801            Option<crate::GString>,
802        ),
803        crate::Error,
804    > {
805        unsafe {
806            let mut scheme = std::ptr::null_mut();
807            let mut userinfo = std::ptr::null_mut();
808            let mut host = std::ptr::null_mut();
809            let mut port = std::mem::MaybeUninit::uninit();
810            let mut path = std::ptr::null_mut();
811            let mut query = std::ptr::null_mut();
812            let mut fragment = std::ptr::null_mut();
813            let mut error = std::ptr::null_mut();
814            let is_ok = ffi::g_uri_split(
815                uri_ref.to_glib_none().0,
816                flags.into_glib(),
817                &mut scheme,
818                &mut userinfo,
819                &mut host,
820                port.as_mut_ptr(),
821                &mut path,
822                &mut query,
823                &mut fragment,
824                &mut error,
825            );
826            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
827            if error.is_null() {
828                Ok((
829                    from_glib_full(scheme),
830                    from_glib_full(userinfo),
831                    from_glib_full(host),
832                    port.assume_init(),
833                    from_glib_full(path),
834                    from_glib_full(query),
835                    from_glib_full(fragment),
836                ))
837            } else {
838                Err(from_glib_full(error))
839            }
840        }
841    }
842
843    /// Parses @uri_string (which must be an [absolute URI](#relative-and-absolute-uris))
844    /// according to @flags, and returns the pieces relevant to connecting to a host.
845    /// See the documentation for g_uri_split() for more details; this is
846    /// mostly a wrapper around that function with simpler arguments.
847    /// However, it will return an error if @uri_string is a relative URI,
848    /// or does not contain a hostname component.
849    /// ## `uri_string`
850    /// a string containing an absolute URI
851    /// ## `flags`
852    /// flags for parsing @uri_string
853    ///
854    /// # Returns
855    ///
856    /// [`true`] if @uri_string parsed successfully,
857    ///   [`false`] on error.
858    ///
859    /// ## `scheme`
860    /// on return, contains
861    ///    the scheme (converted to lowercase), or [`None`]
862    ///
863    /// ## `host`
864    /// on return, contains the
865    ///    host, or [`None`]
866    ///
867    /// ## `port`
868    /// on return, contains the
869    ///    port, or `-1`
870    #[doc(alias = "g_uri_split_network")]
871    pub fn split_network(
872        uri_string: &str,
873        flags: UriFlags,
874    ) -> Result<(Option<crate::GString>, Option<crate::GString>, i32), crate::Error> {
875        unsafe {
876            let mut scheme = std::ptr::null_mut();
877            let mut host = std::ptr::null_mut();
878            let mut port = std::mem::MaybeUninit::uninit();
879            let mut error = std::ptr::null_mut();
880            let is_ok = ffi::g_uri_split_network(
881                uri_string.to_glib_none().0,
882                flags.into_glib(),
883                &mut scheme,
884                &mut host,
885                port.as_mut_ptr(),
886                &mut error,
887            );
888            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
889            if error.is_null() {
890                Ok((
891                    from_glib_full(scheme),
892                    from_glib_full(host),
893                    port.assume_init(),
894                ))
895            } else {
896                Err(from_glib_full(error))
897            }
898        }
899    }
900
901    /// Parses @uri_ref (which can be an
902    /// [absolute or relative URI](#relative-and-absolute-uris)) according to @flags, and
903    /// returns the pieces. Any component that doesn't appear in @uri_ref will be
904    /// returned as [`None`] (but note that all URIs always have a path component,
905    /// though it may be the empty string).
906    ///
907    /// See g_uri_split(), and the definition of #GUriFlags, for more
908    /// information on the effect of @flags. Note that @password will only
909    /// be parsed out if @flags contains [`UriFlags::HAS_PASSWORD`][crate::UriFlags::HAS_PASSWORD], and
910    /// @auth_params will only be parsed out if @flags contains
911    /// [`UriFlags::HAS_AUTH_PARAMS`][crate::UriFlags::HAS_AUTH_PARAMS].
912    /// ## `uri_ref`
913    /// a string containing a relative or absolute URI
914    /// ## `flags`
915    /// flags for parsing @uri_ref
916    ///
917    /// # Returns
918    ///
919    /// [`true`] if @uri_ref parsed successfully, [`false`]
920    ///   on error.
921    ///
922    /// ## `scheme`
923    /// on return, contains
924    ///    the scheme (converted to lowercase), or [`None`]
925    ///
926    /// ## `user`
927    /// on return, contains
928    ///    the user, or [`None`]
929    ///
930    /// ## `password`
931    /// on return, contains
932    ///    the password, or [`None`]
933    ///
934    /// ## `auth_params`
935    /// on return, contains
936    ///    the auth_params, or [`None`]
937    ///
938    /// ## `host`
939    /// on return, contains the
940    ///    host, or [`None`]
941    ///
942    /// ## `port`
943    /// on return, contains the
944    ///    port, or `-1`
945    ///
946    /// ## `path`
947    /// on return, contains the
948    ///    path
949    ///
950    /// ## `query`
951    /// on return, contains the
952    ///    query, or [`None`]
953    ///
954    /// ## `fragment`
955    /// on return, contains
956    ///    the fragment, or [`None`]
957    #[doc(alias = "g_uri_split_with_user")]
958    pub fn split_with_user(
959        uri_ref: &str,
960        flags: UriFlags,
961    ) -> Result<
962        (
963            Option<crate::GString>,
964            Option<crate::GString>,
965            Option<crate::GString>,
966            Option<crate::GString>,
967            Option<crate::GString>,
968            i32,
969            crate::GString,
970            Option<crate::GString>,
971            Option<crate::GString>,
972        ),
973        crate::Error,
974    > {
975        unsafe {
976            let mut scheme = std::ptr::null_mut();
977            let mut user = std::ptr::null_mut();
978            let mut password = std::ptr::null_mut();
979            let mut auth_params = std::ptr::null_mut();
980            let mut host = std::ptr::null_mut();
981            let mut port = std::mem::MaybeUninit::uninit();
982            let mut path = std::ptr::null_mut();
983            let mut query = std::ptr::null_mut();
984            let mut fragment = std::ptr::null_mut();
985            let mut error = std::ptr::null_mut();
986            let is_ok = ffi::g_uri_split_with_user(
987                uri_ref.to_glib_none().0,
988                flags.into_glib(),
989                &mut scheme,
990                &mut user,
991                &mut password,
992                &mut auth_params,
993                &mut host,
994                port.as_mut_ptr(),
995                &mut path,
996                &mut query,
997                &mut fragment,
998                &mut error,
999            );
1000            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
1001            if error.is_null() {
1002                Ok((
1003                    from_glib_full(scheme),
1004                    from_glib_full(user),
1005                    from_glib_full(password),
1006                    from_glib_full(auth_params),
1007                    from_glib_full(host),
1008                    port.assume_init(),
1009                    from_glib_full(path),
1010                    from_glib_full(query),
1011                    from_glib_full(fragment),
1012                ))
1013            } else {
1014                Err(from_glib_full(error))
1015            }
1016        }
1017    }
1018
1019    /// Unescapes a segment of an escaped string as binary data.
1020    ///
1021    /// Note that in contrast to g_uri_unescape_string(), this does allow
1022    /// nul bytes to appear in the output.
1023    ///
1024    /// If any of the characters in @illegal_characters appears as an escaped
1025    /// character in @escaped_string, then that is an error and [`None`] will be
1026    /// returned. This is useful if you want to avoid for instance having a slash
1027    /// being expanded in an escaped path element, which might confuse pathname
1028    /// handling.
1029    /// ## `escaped_string`
1030    /// A URI-escaped string
1031    /// ## `length`
1032    /// the length (in bytes) of @escaped_string to escape, or `-1` if it
1033    ///   is nul-terminated.
1034    /// ## `illegal_characters`
1035    /// a string of illegal characters
1036    ///   not to be allowed, or [`None`].
1037    ///
1038    /// # Returns
1039    ///
1040    /// an unescaped version of @escaped_string
1041    ///     or [`None`] on error (if decoding failed, using [`UriError::Failed`][crate::UriError::Failed] error
1042    ///     code). The returned #GBytes should be unreffed when no longer needed.
1043    #[doc(alias = "g_uri_unescape_bytes")]
1044    pub fn unescape_bytes(
1045        escaped_string: &str,
1046        illegal_characters: Option<&str>,
1047    ) -> Result<Bytes, crate::Error> {
1048        let length = escaped_string.len() as _;
1049        unsafe {
1050            let mut error = std::ptr::null_mut();
1051            let ret = ffi::g_uri_unescape_bytes(
1052                escaped_string.to_glib_none().0,
1053                length,
1054                illegal_characters.to_glib_none().0,
1055                &mut error,
1056            );
1057            if error.is_null() {
1058                Ok(from_glib_full(ret))
1059            } else {
1060                Err(from_glib_full(error))
1061            }
1062        }
1063    }
1064
1065    /// Unescapes a segment of an escaped string.
1066    ///
1067    /// If any of the characters in @illegal_characters or the NUL
1068    /// character appears as an escaped character in @escaped_string, then
1069    /// that is an error and [`None`] will be returned. This is useful if you
1070    /// want to avoid for instance having a slash being expanded in an
1071    /// escaped path element, which might confuse pathname handling.
1072    ///
1073    /// Note: `NUL` byte is not accepted in the output, in contrast to
1074    /// g_uri_unescape_bytes().
1075    /// ## `escaped_string`
1076    /// A string, may be [`None`]
1077    /// ## `escaped_string_end`
1078    /// Pointer to end of @escaped_string,
1079    ///   may be [`None`]
1080    /// ## `illegal_characters`
1081    /// An optional string of illegal
1082    ///   characters not to be allowed, may be [`None`]
1083    ///
1084    /// # Returns
1085    ///
1086    /// an unescaped version of @escaped_string,
1087    /// or [`None`] on error. The returned string should be freed when no longer
1088    /// needed.  As a special case if [`None`] is given for @escaped_string, this
1089    /// function will return [`None`].
1090    #[doc(alias = "g_uri_unescape_segment")]
1091    pub fn unescape_segment(
1092        escaped_string: Option<&str>,
1093        escaped_string_end: Option<&str>,
1094        illegal_characters: Option<&str>,
1095    ) -> Option<crate::GString> {
1096        unsafe {
1097            from_glib_full(ffi::g_uri_unescape_segment(
1098                escaped_string.to_glib_none().0,
1099                escaped_string_end.to_glib_none().0,
1100                illegal_characters.to_glib_none().0,
1101            ))
1102        }
1103    }
1104
1105    /// Unescapes a whole escaped string.
1106    ///
1107    /// If any of the characters in @illegal_characters or the NUL
1108    /// character appears as an escaped character in @escaped_string, then
1109    /// that is an error and [`None`] will be returned. This is useful if you
1110    /// want to avoid for instance having a slash being expanded in an
1111    /// escaped path element, which might confuse pathname handling.
1112    /// ## `escaped_string`
1113    /// an escaped string to be unescaped.
1114    /// ## `illegal_characters`
1115    /// a string of illegal characters
1116    ///   not to be allowed, or [`None`].
1117    ///
1118    /// # Returns
1119    ///
1120    /// an unescaped version of @escaped_string.
1121    /// The returned string should be freed when no longer needed.
1122    #[doc(alias = "g_uri_unescape_string")]
1123    pub fn unescape_string(
1124        escaped_string: &str,
1125        illegal_characters: Option<&str>,
1126    ) -> Option<crate::GString> {
1127        unsafe {
1128            from_glib_full(ffi::g_uri_unescape_string(
1129                escaped_string.to_glib_none().0,
1130                illegal_characters.to_glib_none().0,
1131            ))
1132        }
1133    }
1134}
1135
1136impl std::fmt::Display for Uri {
1137    #[inline]
1138    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1139        f.write_str(&self.to_str())
1140    }
1141}
1142
1143unsafe impl Send for Uri {}
1144unsafe impl Sync for Uri {}