1// Package gio was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gio
3
4import (
5 "unsafe"
6
7 "github.com/ebitengine/purego"
8
9 "github.com/bnema/puregotk/pkg/core"
10 "github.com/bnema/puregotk/v4/glib"
11 "github.com/bnema/puregotk/v4/gobject"
12 "github.com/bnema/puregotk/v4/gobject/types"
13)
14
15// `GDBusAuthObserver` provides a mechanism for participating
16// in how a [class@Gio.DBusServer] (or a [class@Gio.DBusConnection])
17// authenticates remote peers.
18//
19// Simply instantiate a `GDBusAuthObserver` and connect to the
20// signals you are interested in. Note that new signals may be added
21// in the future.
22//
23// ## Controlling Authentication Mechanisms
24//
25// By default, a `GDBusServer` or server-side `GDBusConnection` will allow
26// any authentication mechanism to be used. If you only want to allow D-Bus
27// connections with the `EXTERNAL` mechanism, which makes use of credentials
28// passing and is the recommended mechanism for modern Unix platforms such
29// as Linux and the BSD family, you would use a signal handler like this:
30//
31// ```c
32// static gboolean
33// on_allow_mechanism (GDBusAuthObserver *observer,
34//
35// const gchar *mechanism,
36// gpointer user_data)
37//
38// {
39// if (g_strcmp0 (mechanism, "EXTERNAL") == 0)
40// {
41// return TRUE;
42// }
43//
44// return FALSE;
45// }
46//
47// ```
48//
49// ## Controlling Authorization
50//
51// By default, a `GDBusServer` or server-side `GDBusConnection` will accept
52// connections from any successfully authenticated user (but not from
53// anonymous connections using the `ANONYMOUS` mechanism). If you only
54// want to allow D-Bus connections from processes owned by the same uid
55// as the server, since GLib 2.68, you should use the
56// `G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER` flag. It’s equivalent
57// to the following signal handler:
58//
59// ```c
60// static gboolean
61// on_authorize_authenticated_peer (GDBusAuthObserver *observer,
62//
63// GIOStream *stream,
64// GCredentials *credentials,
65// gpointer user_data)
66//
67// {
68// gboolean authorized;
69//
70// authorized = FALSE;
71// if (credentials != NULL)
72// {
73// GCredentials *own_credentials;
74// own_credentials = g_credentials_new ();
75// if (g_credentials_is_same_user (credentials, own_credentials, NULL))
76// authorized = TRUE;
77// g_object_unref (own_credentials);
78// }
79//
80// return authorized;
81// }
82//
83// ```
84type DBusAuthObserver struct {
85 gobject.Object
86}
87
88var xDBusAuthObserverGLibType func() types.GType
89
90func DBusAuthObserverGLibType() types.GType {
91 return xDBusAuthObserverGLibType()
92}
93
94func DBusAuthObserverNewFromInternalPtr(ptr uintptr) *DBusAuthObserver {
95 cls := &DBusAuthObserver{}
96 cls.Ptr = ptr
97 return cls
98}
99
100var xNewDBusAuthObserver func() uintptr
101
102// Creates a new #GDBusAuthObserver object.
103func NewDBusAuthObserver() *DBusAuthObserver {
104 var cls *DBusAuthObserver
105
106 cret := xNewDBusAuthObserver()
107
108 if cret == 0 {
109 return nil
110 }
111 cls = &DBusAuthObserver{}
112 cls.Ptr = cret
113 return cls
114}
115
116var xDBusAuthObserverAllowMechanism func(uintptr, string) bool
117
118// Emits the #GDBusAuthObserver::allow-mechanism signal on @observer.
119func (x *DBusAuthObserver) AllowMechanism(MechanismVar string) bool {
120
121 cret := xDBusAuthObserverAllowMechanism(x.GoPointer(), MechanismVar)
122 return cret
123}
124
125var xDBusAuthObserverAuthorizeAuthenticatedPeer func(uintptr, uintptr, uintptr) bool
126
127// Emits the #GDBusAuthObserver::authorize-authenticated-peer signal on @observer.
128func (x *DBusAuthObserver) AuthorizeAuthenticatedPeer(StreamVar *IOStream, CredentialsVar *Credentials) bool {
129
130 cret := xDBusAuthObserverAuthorizeAuthenticatedPeer(x.GoPointer(), StreamVar.GoPointer(), CredentialsVar.GoPointer())
131 return cret
132}
133
134func (c *DBusAuthObserver) GoPointer() uintptr {
135 if c == nil {
136 return 0
137 }
138 return c.Ptr
139}
140
141func (c *DBusAuthObserver) SetGoPointer(ptr uintptr) {
142 c.Ptr = ptr
143}
144
145// Emitted to check if @mechanism is allowed to be used.
146func (x *DBusAuthObserver) ConnectAllowMechanism(cb *func(DBusAuthObserver, string) bool) uint {
147 cbPtr := uintptr(unsafe.Pointer(cb))
148 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
149 handlerID := gobject.SignalConnect(x.GoPointer(), "allow-mechanism", cbRefPtr)
150 glib.SaveHandlerMapping(handlerID, cbPtr)
151 return handlerID
152 }
153
154 fcb := func(clsPtr uintptr, MechanismVarp uintptr) bool {
155 fa := DBusAuthObserver{}
156 fa.Ptr = clsPtr
157 cbFn := *cb
158
159 return cbFn(fa, core.GoString(MechanismVarp))
160
161 }
162 cbRefPtr := purego.NewCallback(fcb)
163 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
164 handlerID := gobject.SignalConnect(x.GoPointer(), "allow-mechanism", cbRefPtr)
165 glib.SaveHandlerMapping(handlerID, cbPtr)
166 return handlerID
167}
168
169// Emitted to check if a peer that is successfully authenticated
170// is authorized.
171func (x *DBusAuthObserver) ConnectAuthorizeAuthenticatedPeer(cb *func(DBusAuthObserver, uintptr, uintptr) bool) uint {
172 cbPtr := uintptr(unsafe.Pointer(cb))
173 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
174 handlerID := gobject.SignalConnect(x.GoPointer(), "authorize-authenticated-peer", cbRefPtr)
175 glib.SaveHandlerMapping(handlerID, cbPtr)
176 return handlerID
177 }
178
179 fcb := func(clsPtr uintptr, StreamVarp uintptr, CredentialsVarp uintptr) bool {
180 fa := DBusAuthObserver{}
181 fa.Ptr = clsPtr
182 cbFn := *cb
183
184 return cbFn(fa, StreamVarp, CredentialsVarp)
185
186 }
187 cbRefPtr := purego.NewCallback(fcb)
188 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
189 handlerID := gobject.SignalConnect(x.GoPointer(), "authorize-authenticated-peer", cbRefPtr)
190 glib.SaveHandlerMapping(handlerID, cbPtr)
191 return handlerID
192}
193
194func init() {
195 core.SetPackageName("GIO", "gio-2.0")
196 core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"})
197 var libs []uintptr
198 for _, libPath := range core.GetPaths("GIO") {
199 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
200 if err != nil {
201 panic(err)
202 }
203 libs = append(libs, lib)
204 }
205
206 core.PuregoSafeRegister(&xDBusAuthObserverGLibType, libs, "g_dbus_auth_observer_get_type")
207
208 core.PuregoSafeRegister(&xNewDBusAuthObserver, libs, "g_dbus_auth_observer_new")
209
210 core.PuregoSafeRegister(&xDBusAuthObserverAllowMechanism, libs, "g_dbus_auth_observer_allow_mechanism")
211 core.PuregoSafeRegister(&xDBusAuthObserverAuthorizeAuthenticatedPeer, libs, "g_dbus_auth_observer_authorize_authenticated_peer")
212
213}