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.DtlsConnectionT;
26 
27 public  import gio.AsyncResultIF;
28 public  import gio.Cancellable;
29 public  import gio.TlsCertificate;
30 public  import gio.TlsDatabase;
31 public  import gio.TlsInteraction;
32 public  import glib.ErrorG;
33 public  import glib.GException;
34 public  import gobject.ObjectG;
35 public  import gobject.Signals;
36 public  import gtkc.gdktypes;
37 public  import gtkc.gio;
38 public  import gtkc.giotypes;
39 
40 
41 /** */
42 public template DtlsConnectionT(TStruct)
43 {
44 	/** Get the main Gtk struct */
45 	public GDtlsConnection* getDtlsConnectionStruct()
46 	{
47 		return cast(GDtlsConnection*)getStruct();
48 	}
49 
50 
51 	/** */
52 	public bool close(Cancellable cancellable)
53 	{
54 		GError* err = null;
55 		
56 		auto p = g_dtls_connection_close(getDtlsConnectionStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
57 		
58 		if (err !is null)
59 		{
60 			throw new GException( new ErrorG(err) );
61 		}
62 		
63 		return p;
64 	}
65 
66 	/** */
67 	public void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
68 	{
69 		g_dtls_connection_close_async(getDtlsConnectionStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
70 	}
71 
72 	/** */
73 	public bool closeFinish(AsyncResultIF result)
74 	{
75 		GError* err = null;
76 		
77 		auto p = g_dtls_connection_close_finish(getDtlsConnectionStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
78 		
79 		if (err !is null)
80 		{
81 			throw new GException( new ErrorG(err) );
82 		}
83 		
84 		return p;
85 	}
86 
87 	/** */
88 	public bool emitAcceptCertificate(TlsCertificate peerCert, GTlsCertificateFlags errors)
89 	{
90 		return g_dtls_connection_emit_accept_certificate(getDtlsConnectionStruct(), (peerCert is null) ? null : peerCert.getTlsCertificateStruct(), errors) != 0;
91 	}
92 
93 	/** */
94 	public TlsCertificate getCertificate()
95 	{
96 		auto p = g_dtls_connection_get_certificate(getDtlsConnectionStruct());
97 		
98 		if(p is null)
99 		{
100 			return null;
101 		}
102 		
103 		return ObjectG.getDObject!(TlsCertificate)(cast(GTlsCertificate*) p);
104 	}
105 
106 	/** */
107 	public TlsDatabase getDatabase()
108 	{
109 		auto p = g_dtls_connection_get_database(getDtlsConnectionStruct());
110 		
111 		if(p is null)
112 		{
113 			return null;
114 		}
115 		
116 		return ObjectG.getDObject!(TlsDatabase)(cast(GTlsDatabase*) p);
117 	}
118 
119 	/** */
120 	public TlsInteraction getInteraction()
121 	{
122 		auto p = g_dtls_connection_get_interaction(getDtlsConnectionStruct());
123 		
124 		if(p is null)
125 		{
126 			return null;
127 		}
128 		
129 		return ObjectG.getDObject!(TlsInteraction)(cast(GTlsInteraction*) p);
130 	}
131 
132 	/** */
133 	public TlsCertificate getPeerCertificate()
134 	{
135 		auto p = g_dtls_connection_get_peer_certificate(getDtlsConnectionStruct());
136 		
137 		if(p is null)
138 		{
139 			return null;
140 		}
141 		
142 		return ObjectG.getDObject!(TlsCertificate)(cast(GTlsCertificate*) p);
143 	}
144 
145 	/** */
146 	public GTlsCertificateFlags getPeerCertificateErrors()
147 	{
148 		return g_dtls_connection_get_peer_certificate_errors(getDtlsConnectionStruct());
149 	}
150 
151 	/** */
152 	public GTlsRehandshakeMode getRehandshakeMode()
153 	{
154 		return g_dtls_connection_get_rehandshake_mode(getDtlsConnectionStruct());
155 	}
156 
157 	/** */
158 	public bool getRequireCloseNotify()
159 	{
160 		return g_dtls_connection_get_require_close_notify(getDtlsConnectionStruct()) != 0;
161 	}
162 
163 	/** */
164 	public bool handshake(Cancellable cancellable)
165 	{
166 		GError* err = null;
167 		
168 		auto p = g_dtls_connection_handshake(getDtlsConnectionStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
169 		
170 		if (err !is null)
171 		{
172 			throw new GException( new ErrorG(err) );
173 		}
174 		
175 		return p;
176 	}
177 
178 	/** */
179 	public void handshakeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
180 	{
181 		g_dtls_connection_handshake_async(getDtlsConnectionStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
182 	}
183 
184 	/** */
185 	public bool handshakeFinish(AsyncResultIF result)
186 	{
187 		GError* err = null;
188 		
189 		auto p = g_dtls_connection_handshake_finish(getDtlsConnectionStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
190 		
191 		if (err !is null)
192 		{
193 			throw new GException( new ErrorG(err) );
194 		}
195 		
196 		return p;
197 	}
198 
199 	/** */
200 	public void setCertificate(TlsCertificate certificate)
201 	{
202 		g_dtls_connection_set_certificate(getDtlsConnectionStruct(), (certificate is null) ? null : certificate.getTlsCertificateStruct());
203 	}
204 
205 	/** */
206 	public void setDatabase(TlsDatabase database)
207 	{
208 		g_dtls_connection_set_database(getDtlsConnectionStruct(), (database is null) ? null : database.getTlsDatabaseStruct());
209 	}
210 
211 	/** */
212 	public void setInteraction(TlsInteraction interaction)
213 	{
214 		g_dtls_connection_set_interaction(getDtlsConnectionStruct(), (interaction is null) ? null : interaction.getTlsInteractionStruct());
215 	}
216 
217 	/** */
218 	public void setRehandshakeMode(GTlsRehandshakeMode mode)
219 	{
220 		g_dtls_connection_set_rehandshake_mode(getDtlsConnectionStruct(), mode);
221 	}
222 
223 	/** */
224 	public void setRequireCloseNotify(bool requireCloseNotify)
225 	{
226 		g_dtls_connection_set_require_close_notify(getDtlsConnectionStruct(), requireCloseNotify);
227 	}
228 
229 	/** */
230 	public bool shutdown(bool shutdownRead, bool shutdownWrite, Cancellable cancellable)
231 	{
232 		GError* err = null;
233 		
234 		auto p = g_dtls_connection_shutdown(getDtlsConnectionStruct(), shutdownRead, shutdownWrite, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
235 		
236 		if (err !is null)
237 		{
238 			throw new GException( new ErrorG(err) );
239 		}
240 		
241 		return p;
242 	}
243 
244 	/** */
245 	public void shutdownAsync(bool shutdownRead, bool shutdownWrite, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
246 	{
247 		g_dtls_connection_shutdown_async(getDtlsConnectionStruct(), shutdownRead, shutdownWrite, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
248 	}
249 
250 	/** */
251 	public bool shutdownFinish(AsyncResultIF result)
252 	{
253 		GError* err = null;
254 		
255 		auto p = g_dtls_connection_shutdown_finish(getDtlsConnectionStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
256 		
257 		if (err !is null)
258 		{
259 			throw new GException( new ErrorG(err) );
260 		}
261 		
262 		return p;
263 	}
264 
265 	int[string] connectedSignals;
266 
267 	bool delegate(TlsCertificate, GTlsCertificateFlags, DtlsConnectionIF)[] _onAcceptCertificateListeners;
268 	@property bool delegate(TlsCertificate, GTlsCertificateFlags, DtlsConnectionIF)[] onAcceptCertificateListeners()
269 	{
270 		return _onAcceptCertificateListeners;
271 	}
272 	/** */
273 	void addOnAcceptCertificate(bool delegate(TlsCertificate, GTlsCertificateFlags, DtlsConnectionIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
274 	{
275 		if ( "accept-certificate" !in connectedSignals )
276 		{
277 			Signals.connectData(
278 				this,
279 				"accept-certificate",
280 				cast(GCallback)&callBackAcceptCertificate,
281 				cast(void*)cast(DtlsConnectionIF)this,
282 				null,
283 				connectFlags);
284 			connectedSignals["accept-certificate"] = 1;
285 		}
286 		_onAcceptCertificateListeners ~= dlg;
287 	}
288 	extern(C) static int callBackAcceptCertificate(GDtlsConnection* dtlsconnectionStruct, GTlsCertificate* object, GTlsCertificateFlags p0, DtlsConnectionIF _dtlsconnection)
289 	{
290 		foreach ( bool delegate(TlsCertificate, GTlsCertificateFlags, DtlsConnectionIF) dlg; _dtlsconnection.onAcceptCertificateListeners )
291 		{
292 			if ( dlg(ObjectG.getDObject!(TlsCertificate)(object), p0, _dtlsconnection) )
293 			{
294 				return 1;
295 			}
296 		}
297 		
298 		return 0;
299 	}
300 }