gio/auto/credentials.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::ffi;
6use glib::translate::*;
7
8glib::wrapper! {
9 /// The `GCredentials` type is a reference-counted wrapper for native
10 /// credentials.
11 ///
12 /// The information in `GCredentials` is typically used for identifying,
13 /// authenticating and authorizing other processes.
14 ///
15 /// Some operating systems supports looking up the credentials of the remote
16 /// peer of a communication endpoint - see e.g. [`SocketExt::credentials()`][crate::prelude::SocketExt::credentials()].
17 ///
18 /// Some operating systems supports securely sending and receiving
19 /// credentials over a Unix Domain Socket, see [`UnixCredentialsMessage`][crate::UnixCredentialsMessage],
20 /// [`UnixConnectionExt::send_credentials()`][crate::prelude::UnixConnectionExt::send_credentials()] and
21 /// [`UnixConnectionExt::receive_credentials()`][crate::prelude::UnixConnectionExt::receive_credentials()] for details.
22 ///
23 /// On Linux, the native credential type is a `struct ucred` - see the
24 /// [`unix(7)` man page](man:unix(7)) for details. This corresponds to
25 /// `G_CREDENTIALS_TYPE_LINUX_UCRED`.
26 ///
27 /// On Apple operating systems (including iOS, tvOS, and macOS), the native credential
28 /// type is a `struct xucred`. This corresponds to `G_CREDENTIALS_TYPE_APPLE_XUCRED`.
29 ///
30 /// On FreeBSD, Debian GNU/kFreeBSD, and GNU/Hurd, the native credential type is a
31 /// `struct cmsgcred`. This corresponds to `G_CREDENTIALS_TYPE_FREEBSD_CMSGCRED`.
32 ///
33 /// On NetBSD, the native credential type is a `struct unpcbid`.
34 /// This corresponds to `G_CREDENTIALS_TYPE_NETBSD_UNPCBID`.
35 ///
36 /// On OpenBSD, the native credential type is a `struct sockpeercred`.
37 /// This corresponds to `G_CREDENTIALS_TYPE_OPENBSD_SOCKPEERCRED`.
38 ///
39 /// On Solaris (including OpenSolaris and its derivatives), the native credential type
40 /// is a `ucred_t`. This corresponds to `G_CREDENTIALS_TYPE_SOLARIS_UCRED`.
41 ///
42 /// Since GLib 2.72, on Windows, the native credentials may contain the PID of a
43 /// process. This corresponds to `G_CREDENTIALS_TYPE_WIN32_PID`.
44 ///
45 /// # Implements
46 ///
47 /// [`trait@glib::ObjectExt`]
48 #[doc(alias = "GCredentials")]
49 pub struct Credentials(Object<ffi::GCredentials, ffi::GCredentialsClass>);
50
51 match fn {
52 type_ => || ffi::g_credentials_get_type(),
53 }
54}
55
56impl Credentials {
57 /// Creates a new #GCredentials object with credentials matching the
58 /// the current process.
59 ///
60 /// # Returns
61 ///
62 /// A #GCredentials. Free with g_object_unref().
63 #[doc(alias = "g_credentials_new")]
64 pub fn new() -> Credentials {
65 unsafe { from_glib_full(ffi::g_credentials_new()) }
66 }
67
68 /// Checks if @self and @other_credentials is the same user.
69 ///
70 /// This operation can fail if #GCredentials is not supported on the
71 /// the OS.
72 /// ## `other_credentials`
73 /// A #GCredentials.
74 ///
75 /// # Returns
76 ///
77 /// [`true`] if @self and @other_credentials has the same
78 /// user, [`false`] otherwise or if @error is set.
79 #[doc(alias = "g_credentials_is_same_user")]
80 pub fn is_same_user(&self, other_credentials: &Credentials) -> Result<(), glib::Error> {
81 unsafe {
82 let mut error = std::ptr::null_mut();
83 let is_ok = ffi::g_credentials_is_same_user(
84 self.to_glib_none().0,
85 other_credentials.to_glib_none().0,
86 &mut error,
87 );
88 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
89 if error.is_null() {
90 Ok(())
91 } else {
92 Err(from_glib_full(error))
93 }
94 }
95 }
96
97 /// Creates a human-readable textual representation of @self
98 /// that can be used in logging and debug messages. The format of the
99 /// returned string may change in future GLib release.
100 ///
101 /// # Returns
102 ///
103 /// A string that should be freed with g_free().
104 #[doc(alias = "g_credentials_to_string")]
105 #[doc(alias = "to_string")]
106 pub fn to_str(&self) -> glib::GString {
107 unsafe { from_glib_full(ffi::g_credentials_to_string(self.to_glib_none().0)) }
108 }
109}
110
111impl Default for Credentials {
112 fn default() -> Self {
113 Self::new()
114 }
115}
116
117impl std::fmt::Display for Credentials {
118 #[inline]
119 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
120 f.write_str(&self.to_str())
121 }
122}