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