1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{Credentials, SocketControlMessage};
use glib::{prelude::*, translate::*};

glib::wrapper! {
    /// This [`SocketControlMessage`][crate::SocketControlMessage] contains a [`Credentials`][crate::Credentials]
    /// instance.  It may be sent using [`SocketExtManual::send_message()`][crate::prelude::SocketExtManual::send_message()] and received
    /// using [`SocketExtManual::receive_message()`][crate::prelude::SocketExtManual::receive_message()] over UNIX sockets (ie: sockets in
    /// the `G_SOCKET_FAMILY_UNIX` family).
    ///
    /// For an easier way to send and receive credentials over
    /// stream-oriented UNIX sockets, see
    /// `Gio::UnixConnection::send_credentials()` and
    /// `Gio::UnixConnection::receive_credentials()`. To receive credentials of
    /// a foreign process connected to a socket, use
    /// [`SocketExt::credentials()`][crate::prelude::SocketExt::credentials()].
    ///
    /// Since GLib 2.72, `GUnixCredentialMessage` is available on all platforms. It
    /// requires underlying system support (such as Windows 10 with `AF_UNIX`) at run
    /// time.
    ///
    /// Before GLib 2.72, `<gio/gunixcredentialsmessage.h>` belonged to the UNIX-specific
    /// GIO interfaces, thus you had to use the `gio-unix-2.0.pc` pkg-config file
    /// when using it. This is no longer necessary since GLib 2.72.
    ///
    /// ## Properties
    ///
    ///
    /// #### `credentials`
    ///  The credentials stored in the message.
    ///
    /// Readable | Writeable | Construct Only
    ///
    /// # Implements
    ///
    /// [`UnixCredentialsMessageExt`][trait@crate::prelude::UnixCredentialsMessageExt], [`SocketControlMessageExt`][trait@crate::prelude::SocketControlMessageExt], [`trait@glib::ObjectExt`], [`SocketControlMessageExtManual`][trait@crate::prelude::SocketControlMessageExtManual]
    #[doc(alias = "GUnixCredentialsMessage")]
    pub struct UnixCredentialsMessage(Object<ffi::GUnixCredentialsMessage, ffi::GUnixCredentialsMessageClass>) @extends SocketControlMessage;

    match fn {
        type_ => || ffi::g_unix_credentials_message_get_type(),
    }
}

impl UnixCredentialsMessage {
    pub const NONE: Option<&'static UnixCredentialsMessage> = None;

    /// Creates a new #GUnixCredentialsMessage with credentials matching the current processes.
    ///
    /// # Returns
    ///
    /// a new #GUnixCredentialsMessage
    #[doc(alias = "g_unix_credentials_message_new")]
    pub fn new() -> UnixCredentialsMessage {
        unsafe {
            SocketControlMessage::from_glib_full(ffi::g_unix_credentials_message_new())
                .unsafe_cast()
        }
    }

    /// Creates a new #GUnixCredentialsMessage holding @credentials.
    /// ## `credentials`
    /// A #GCredentials object.
    ///
    /// # Returns
    ///
    /// a new #GUnixCredentialsMessage
    #[doc(alias = "g_unix_credentials_message_new_with_credentials")]
    #[doc(alias = "new_with_credentials")]
    pub fn with_credentials(credentials: &Credentials) -> UnixCredentialsMessage {
        unsafe {
            SocketControlMessage::from_glib_full(
                ffi::g_unix_credentials_message_new_with_credentials(credentials.to_glib_none().0),
            )
            .unsafe_cast()
        }
    }

    /// Checks if passing #GCredentials on a #GSocket is supported on this platform.
    ///
    /// # Returns
    ///
    /// [`true`] if supported, [`false`] otherwise
    #[doc(alias = "g_unix_credentials_message_is_supported")]
    pub fn is_supported() -> bool {
        unsafe { from_glib(ffi::g_unix_credentials_message_is_supported()) }
    }
}

impl Default for UnixCredentialsMessage {
    fn default() -> Self {
        Self::new()
    }
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::UnixCredentialsMessage>> Sealed for T {}
}

/// Trait containing all [`struct@UnixCredentialsMessage`] methods.
///
/// # Implementors
///
/// [`UnixCredentialsMessage`][struct@crate::UnixCredentialsMessage]
pub trait UnixCredentialsMessageExt:
    IsA<UnixCredentialsMessage> + sealed::Sealed + 'static
{
    /// Gets the credentials stored in @self.
    ///
    /// # Returns
    ///
    /// A #GCredentials instance. Do not free, it is owned by @self.
    #[doc(alias = "g_unix_credentials_message_get_credentials")]
    #[doc(alias = "get_credentials")]
    fn credentials(&self) -> Credentials {
        unsafe {
            from_glib_none(ffi::g_unix_credentials_message_get_credentials(
                self.as_ref().to_glib_none().0,
            ))
        }
    }
}

impl<O: IsA<UnixCredentialsMessage>> UnixCredentialsMessageExt for O {}