1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gio.DBusAuthObserver;
26 
27 private import gio.Credentials;
28 private import gio.IOStream;
29 private import gio.c.functions;
30 public  import gio.c.types;
31 private import glib.ConstructionException;
32 private import glib.Str;
33 private import gobject.ObjectG;
34 private import gobject.Signals;
35 public  import gtkc.giotypes;
36 private import std.algorithm;
37 
38 
39 /**
40  * The #GDBusAuthObserver type provides a mechanism for participating
41  * in how a #GDBusServer (or a #GDBusConnection) authenticates remote
42  * peers. Simply instantiate a #GDBusAuthObserver and connect to the
43  * signals you are interested in. Note that new signals may be added
44  * in the future
45  * 
46  * ## Controlling Authentication # {#auth-observer}
47  * 
48  * For example, if you only want to allow D-Bus connections from
49  * processes owned by the same uid as the server, you would use a
50  * signal handler like the following:
51  * 
52  * |[<!-- language="C" -->
53  * static gboolean
54  * on_authorize_authenticated_peer (GDBusAuthObserver *observer,
55  * GIOStream         *stream,
56  * GCredentials      *credentials,
57  * gpointer           user_data)
58  * {
59  * gboolean authorized;
60  * 
61  * authorized = FALSE;
62  * if (credentials != NULL)
63  * {
64  * GCredentials *own_credentials;
65  * own_credentials = g_credentials_new ();
66  * if (g_credentials_is_same_user (credentials, own_credentials, NULL))
67  * authorized = TRUE;
68  * g_object_unref (own_credentials);
69  * }
70  * 
71  * return authorized;
72  * }
73  * ]|
74  *
75  * Since: 2.26
76  */
77 public class DBusAuthObserver : ObjectG
78 {
79 	/** the main Gtk struct */
80 	protected GDBusAuthObserver* gDBusAuthObserver;
81 
82 	/** Get the main Gtk struct */
83 	public GDBusAuthObserver* getDBusAuthObserverStruct(bool transferOwnership = false)
84 	{
85 		if (transferOwnership)
86 			ownedRef = false;
87 		return gDBusAuthObserver;
88 	}
89 
90 	/** the main Gtk struct as a void* */
91 	protected override void* getStruct()
92 	{
93 		return cast(void*)gDBusAuthObserver;
94 	}
95 
96 	/**
97 	 * Sets our main struct and passes it to the parent class.
98 	 */
99 	public this (GDBusAuthObserver* gDBusAuthObserver, bool ownedRef = false)
100 	{
101 		this.gDBusAuthObserver = gDBusAuthObserver;
102 		super(cast(GObject*)gDBusAuthObserver, ownedRef);
103 	}
104 
105 
106 	/** */
107 	public static GType getType()
108 	{
109 		return g_dbus_auth_observer_get_type();
110 	}
111 
112 	/**
113 	 * Creates a new #GDBusAuthObserver object.
114 	 *
115 	 * Returns: A #GDBusAuthObserver. Free with g_object_unref().
116 	 *
117 	 * Since: 2.26
118 	 *
119 	 * Throws: ConstructionException GTK+ fails to create the object.
120 	 */
121 	public this()
122 	{
123 		auto p = g_dbus_auth_observer_new();
124 
125 		if(p is null)
126 		{
127 			throw new ConstructionException("null returned by new");
128 		}
129 
130 		this(cast(GDBusAuthObserver*) p, true);
131 	}
132 
133 	/**
134 	 * Emits the #GDBusAuthObserver::allow-mechanism signal on @observer.
135 	 *
136 	 * Params:
137 	 *     mechanism = The name of the mechanism, e.g. `DBUS_COOKIE_SHA1`.
138 	 *
139 	 * Returns: %TRUE if @mechanism can be used to authenticate the other peer, %FALSE if not.
140 	 *
141 	 * Since: 2.34
142 	 */
143 	public bool allowMechanism(string mechanism)
144 	{
145 		return g_dbus_auth_observer_allow_mechanism(gDBusAuthObserver, Str.toStringz(mechanism)) != 0;
146 	}
147 
148 	/**
149 	 * Emits the #GDBusAuthObserver::authorize-authenticated-peer signal on @observer.
150 	 *
151 	 * Params:
152 	 *     stream = A #GIOStream for the #GDBusConnection.
153 	 *     credentials = Credentials received from the peer or %NULL.
154 	 *
155 	 * Returns: %TRUE if the peer is authorized, %FALSE if not.
156 	 *
157 	 * Since: 2.26
158 	 */
159 	public bool authorizeAuthenticatedPeer(IOStream stream, Credentials credentials)
160 	{
161 		return g_dbus_auth_observer_authorize_authenticated_peer(gDBusAuthObserver, (stream is null) ? null : stream.getIOStreamStruct(), (credentials is null) ? null : credentials.getCredentialsStruct()) != 0;
162 	}
163 
164 	/**
165 	 * Emitted to check if @mechanism is allowed to be used.
166 	 *
167 	 * Params:
168 	 *     mechanism = The name of the mechanism, e.g. `DBUS_COOKIE_SHA1`.
169 	 *
170 	 * Returns: %TRUE if @mechanism can be used to authenticate the other peer, %FALSE if not.
171 	 *
172 	 * Since: 2.34
173 	 */
174 	gulong addOnAllowMechanism(bool delegate(string, DBusAuthObserver) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
175 	{
176 		return Signals.connect(this, "allow-mechanism", dlg, connectFlags ^ ConnectFlags.SWAPPED);
177 	}
178 
179 	/**
180 	 * Emitted to check if a peer that is successfully authenticated
181 	 * is authorized.
182 	 *
183 	 * Params:
184 	 *     stream = A #GIOStream for the #GDBusConnection.
185 	 *     credentials = Credentials received from the peer or %NULL.
186 	 *
187 	 * Returns: %TRUE if the peer is authorized, %FALSE if not.
188 	 *
189 	 * Since: 2.26
190 	 */
191 	gulong addOnAuthorizeAuthenticatedPeer(bool delegate(IOStream, Credentials, DBusAuthObserver) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
192 	{
193 		return Signals.connect(this, "authorize-authenticated-peer", dlg, connectFlags ^ ConnectFlags.SWAPPED);
194 	}
195 }