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  * Conversion parameters:
26  * inFile  = GDBusAuthObserver.html
27  * outPack = gio
28  * outFile = DBusAuthObserver
29  * strct   = GDBusAuthObserver
30  * realStrct=
31  * ctorStrct=
32  * clss    = DBusAuthObserver
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_dbus_auth_observer_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- gio.Credentials
48  * 	- gio.IOStream
49  * structWrap:
50  * 	- GCredentials* -> Credentials
51  * 	- GIOStream* -> IOStream
52  * module aliases:
53  * local aliases:
54  * overrides:
55  */
56 
57 module gio.DBusAuthObserver;
58 
59 public  import gtkc.giotypes;
60 
61 private import gtkc.gio;
62 private import glib.ConstructionException;
63 private import gobject.ObjectG;
64 
65 private import gobject.Signals;
66 public  import gtkc.gdktypes;
67 private import glib.Str;
68 private import gio.Credentials;
69 private import gio.IOStream;
70 
71 
72 private import gobject.ObjectG;
73 
74 /**
75  * The GDBusAuthObserver type provides a mechanism for participating
76  * in how a GDBusServer (or a GDBusConnection) authenticates remote
77  * peers. Simply instantiate a GDBusAuthObserver and connect to the
78  * signals you are interested in. Note that new signals may be added
79  * in the future
80  *
81  * For example, if you only want to allow D-Bus connections from
82  * processes owned by the same uid as the server, you would use a
83  * signal handler like the following:
84  *
85  * $(DDOC_COMMENT example)
86  */
87 public class DBusAuthObserver : ObjectG
88 {
89 	
90 	/** the main Gtk struct */
91 	protected GDBusAuthObserver* gDBusAuthObserver;
92 	
93 	
94 	/** Get the main Gtk struct */
95 	public GDBusAuthObserver* getDBusAuthObserverStruct()
96 	{
97 		return gDBusAuthObserver;
98 	}
99 	
100 	
101 	/** the main Gtk struct as a void* */
102 	protected override void* getStruct()
103 	{
104 		return cast(void*)gDBusAuthObserver;
105 	}
106 	
107 	/**
108 	 * Sets our main struct and passes it to the parent class
109 	 */
110 	public this (GDBusAuthObserver* gDBusAuthObserver)
111 	{
112 		super(cast(GObject*)gDBusAuthObserver);
113 		this.gDBusAuthObserver = gDBusAuthObserver;
114 	}
115 	
116 	protected override void setStruct(GObject* obj)
117 	{
118 		super.setStruct(obj);
119 		gDBusAuthObserver = cast(GDBusAuthObserver*)obj;
120 	}
121 	
122 	/**
123 	 */
124 	int[string] connectedSignals;
125 	
126 	bool delegate(string, DBusAuthObserver)[] onAllowMechanismListeners;
127 	/**
128 	 * Emitted to check if mechanism is allowed to be used.
129 	 * TRUE if mechanism can be used to authenticate the other peer, FALSE if not.
130 	 * Since 2.34
131 	 */
132 	void addOnAllowMechanism(bool delegate(string, DBusAuthObserver) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
133 	{
134 		if ( !("allow-mechanism" in connectedSignals) )
135 		{
136 			Signals.connectData(
137 			getStruct(),
138 			"allow-mechanism",
139 			cast(GCallback)&callBackAllowMechanism,
140 			cast(void*)this,
141 			null,
142 			connectFlags);
143 			connectedSignals["allow-mechanism"] = 1;
144 		}
145 		onAllowMechanismListeners ~= dlg;
146 	}
147 	extern(C) static gboolean callBackAllowMechanism(GDBusAuthObserver* observerStruct, gchar* mechanism, DBusAuthObserver _dBusAuthObserver)
148 	{
149 		foreach ( bool delegate(string, DBusAuthObserver) dlg ; _dBusAuthObserver.onAllowMechanismListeners )
150 		{
151 			if ( dlg(Str.toString(mechanism), _dBusAuthObserver) )
152 			{
153 				return 1;
154 			}
155 		}
156 		
157 		return 0;
158 	}
159 	
160 	bool delegate(IOStream, Credentials, DBusAuthObserver)[] onAuthorizeAuthenticatedPeerListeners;
161 	/**
162 	 * Emitted to check if a peer that is successfully authenticated
163 	 * is authorized.
164 	 * TRUE if the peer is authorized, FALSE if not.
165 	 * Since 2.26
166 	 */
167 	void addOnAuthorizeAuthenticatedPeer(bool delegate(IOStream, Credentials, DBusAuthObserver) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
168 	{
169 		if ( !("authorize-authenticated-peer" in connectedSignals) )
170 		{
171 			Signals.connectData(
172 			getStruct(),
173 			"authorize-authenticated-peer",
174 			cast(GCallback)&callBackAuthorizeAuthenticatedPeer,
175 			cast(void*)this,
176 			null,
177 			connectFlags);
178 			connectedSignals["authorize-authenticated-peer"] = 1;
179 		}
180 		onAuthorizeAuthenticatedPeerListeners ~= dlg;
181 	}
182 	extern(C) static gboolean callBackAuthorizeAuthenticatedPeer(GDBusAuthObserver* observerStruct, GIOStream* stream, GCredentials* credentials, DBusAuthObserver _dBusAuthObserver)
183 	{
184 		foreach ( bool delegate(IOStream, Credentials, DBusAuthObserver) dlg ; _dBusAuthObserver.onAuthorizeAuthenticatedPeerListeners )
185 		{
186 			if ( dlg(ObjectG.getDObject!(IOStream)(stream), ObjectG.getDObject!(Credentials)(credentials), _dBusAuthObserver) )
187 			{
188 				return 1;
189 			}
190 		}
191 		
192 		return 0;
193 	}
194 	
195 	
196 	/**
197 	 * Creates a new GDBusAuthObserver object.
198 	 * Since 2.26
199 	 * Throws: ConstructionException GTK+ fails to create the object.
200 	 */
201 	public this ()
202 	{
203 		// GDBusAuthObserver * g_dbus_auth_observer_new (void);
204 		auto p = g_dbus_auth_observer_new();
205 		if(p is null)
206 		{
207 			throw new ConstructionException("null returned by g_dbus_auth_observer_new()");
208 		}
209 		this(cast(GDBusAuthObserver*) p);
210 	}
211 	
212 	/**
213 	 * Emits the "authorize-authenticated-peer" signal on observer.
214 	 * Since 2.26
215 	 * Params:
216 	 * stream = A GIOStream for the GDBusConnection.
217 	 * credentials = Credentials received from the peer or NULL. [allow-none]
218 	 * Returns: TRUE if the peer is authorized, FALSE if not.
219 	 */
220 	public int authorizeAuthenticatedPeer(IOStream stream, Credentials credentials)
221 	{
222 		// gboolean g_dbus_auth_observer_authorize_authenticated_peer  (GDBusAuthObserver *observer,  GIOStream *stream,  GCredentials *credentials);
223 		return g_dbus_auth_observer_authorize_authenticated_peer(gDBusAuthObserver, (stream is null) ? null : stream.getIOStreamStruct(), (credentials is null) ? null : credentials.getCredentialsStruct());
224 	}
225 	
226 	/**
227 	 * Emits the "allow-mechanism" signal on observer.
228 	 * Since 2.34
229 	 * Signal Details
230 	 * The "allow-mechanism" signal
231 	 * gboolean user_function (GDBusAuthObserver *observer,
232 	 *  gchar *mechanism,
233 	 *  gpointer user_data) : Run Last
234 	 * Emitted to check if mechanism is allowed to be used.
235 	 * Since 2.34
236 	 * Params:
237 	 * mechanism = The name of the mechanism, e.g. DBUS_COOKIE_SHA1.
238 	 * mechanism = The name of the mechanism, e.g. DBUS_COOKIE_SHA1.
239 	 * Returns: TRUE if mechanism can be used to authenticate the other peer, FALSE if not.Returns: TRUE if mechanism can be used to authenticate the other peer, FALSE if not.
240 	 */
241 	public int allowMechanism(string mechanism)
242 	{
243 		// gboolean g_dbus_auth_observer_allow_mechanism  (GDBusAuthObserver *observer,  const gchar *mechanism);
244 		return g_dbus_auth_observer_allow_mechanism(gDBusAuthObserver, Str.toStringz(mechanism));
245 	}
246 }