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.UnixConnection;
26 
27 private import gio.AsyncResultIF;
28 private import gio.Cancellable;
29 private import gio.Credentials;
30 private import gio.SocketConnection;
31 private import gio.c.functions;
32 public  import gio.c.types;
33 private import glib.ErrorG;
34 private import glib.GException;
35 private import gobject.ObjectG;
36 public  import gtkc.giotypes;
37 
38 
39 /**
40  * This is the subclass of #GSocketConnection that is created
41  * for UNIX domain sockets.
42  * 
43  * It contains functions to do some of the UNIX socket specific
44  * functionality like passing file descriptors.
45  * 
46  * Note that `<gio/gunixconnection.h>` belongs to the UNIX-specific
47  * GIO interfaces, thus you have to use the `gio-unix-2.0.pc`
48  * pkg-config file when using it.
49  */
50 public class UnixConnection : SocketConnection
51 {
52 	/** the main Gtk struct */
53 	protected GUnixConnection* gUnixConnection;
54 
55 	/** Get the main Gtk struct */
56 	public GUnixConnection* getUnixConnectionStruct(bool transferOwnership = false)
57 	{
58 		if (transferOwnership)
59 			ownedRef = false;
60 		return gUnixConnection;
61 	}
62 
63 	/** the main Gtk struct as a void* */
64 	protected override void* getStruct()
65 	{
66 		return cast(void*)gUnixConnection;
67 	}
68 
69 	/**
70 	 * Sets our main struct and passes it to the parent class.
71 	 */
72 	public this (GUnixConnection* gUnixConnection, bool ownedRef = false)
73 	{
74 		this.gUnixConnection = gUnixConnection;
75 		super(cast(GSocketConnection*)gUnixConnection, ownedRef);
76 	}
77 
78 
79 	/** */
80 	public static GType getType()
81 	{
82 		return g_unix_connection_get_type();
83 	}
84 
85 	/**
86 	 * Receives credentials from the sending end of the connection.  The
87 	 * sending end has to call g_unix_connection_send_credentials() (or
88 	 * similar) for this to work.
89 	 *
90 	 * As well as reading the credentials this also reads (and discards) a
91 	 * single byte from the stream, as this is required for credentials
92 	 * passing to work on some implementations.
93 	 *
94 	 * Other ways to exchange credentials with a foreign peer includes the
95 	 * #GUnixCredentialsMessage type and g_socket_get_credentials() function.
96 	 *
97 	 * Params:
98 	 *     cancellable = A #GCancellable or %NULL.
99 	 *
100 	 * Returns: Received credentials on success (free with
101 	 *     g_object_unref()), %NULL if @error is set.
102 	 *
103 	 * Since: 2.26
104 	 *
105 	 * Throws: GException on failure.
106 	 */
107 	public Credentials receiveCredentials(Cancellable cancellable)
108 	{
109 		GError* err = null;
110 
111 		auto p = g_unix_connection_receive_credentials(gUnixConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
112 
113 		if (err !is null)
114 		{
115 			throw new GException( new ErrorG(err) );
116 		}
117 
118 		if(p is null)
119 		{
120 			return null;
121 		}
122 
123 		return ObjectG.getDObject!(Credentials)(cast(GCredentials*) p, true);
124 	}
125 
126 	/**
127 	 * Asynchronously receive credentials.
128 	 *
129 	 * For more details, see g_unix_connection_receive_credentials() which is
130 	 * the synchronous version of this call.
131 	 *
132 	 * When the operation is finished, @callback will be called. You can then call
133 	 * g_unix_connection_receive_credentials_finish() to get the result of the operation.
134 	 *
135 	 * Params:
136 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
137 	 *     callback = a #GAsyncReadyCallback to call when the request is satisfied
138 	 *     userData = the data to pass to callback function
139 	 *
140 	 * Since: 2.32
141 	 */
142 	public void receiveCredentialsAsync(Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
143 	{
144 		g_unix_connection_receive_credentials_async(gUnixConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
145 	}
146 
147 	/**
148 	 * Finishes an asynchronous receive credentials operation started with
149 	 * g_unix_connection_receive_credentials_async().
150 	 *
151 	 * Params:
152 	 *     result = a #GAsyncResult.
153 	 *
154 	 * Returns: a #GCredentials, or %NULL on error.
155 	 *     Free the returned object with g_object_unref().
156 	 *
157 	 * Since: 2.32
158 	 *
159 	 * Throws: GException on failure.
160 	 */
161 	public Credentials receiveCredentialsFinish(AsyncResultIF result)
162 	{
163 		GError* err = null;
164 
165 		auto p = g_unix_connection_receive_credentials_finish(gUnixConnection, (result is null) ? null : result.getAsyncResultStruct(), &err);
166 
167 		if (err !is null)
168 		{
169 			throw new GException( new ErrorG(err) );
170 		}
171 
172 		if(p is null)
173 		{
174 			return null;
175 		}
176 
177 		return ObjectG.getDObject!(Credentials)(cast(GCredentials*) p, true);
178 	}
179 
180 	/**
181 	 * Receives a file descriptor from the sending end of the connection.
182 	 * The sending end has to call g_unix_connection_send_fd() for this
183 	 * to work.
184 	 *
185 	 * As well as reading the fd this also reads a single byte from the
186 	 * stream, as this is required for fd passing to work on some
187 	 * implementations.
188 	 *
189 	 * Params:
190 	 *     cancellable = optional #GCancellable object, %NULL to ignore
191 	 *
192 	 * Returns: a file descriptor on success, -1 on error.
193 	 *
194 	 * Since: 2.22
195 	 *
196 	 * Throws: GException on failure.
197 	 */
198 	public int receiveFd(Cancellable cancellable)
199 	{
200 		GError* err = null;
201 
202 		auto p = g_unix_connection_receive_fd(gUnixConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
203 
204 		if (err !is null)
205 		{
206 			throw new GException( new ErrorG(err) );
207 		}
208 
209 		return p;
210 	}
211 
212 	/**
213 	 * Passes the credentials of the current user the receiving side
214 	 * of the connection. The receiving end has to call
215 	 * g_unix_connection_receive_credentials() (or similar) to accept the
216 	 * credentials.
217 	 *
218 	 * As well as sending the credentials this also writes a single NUL
219 	 * byte to the stream, as this is required for credentials passing to
220 	 * work on some implementations.
221 	 *
222 	 * Other ways to exchange credentials with a foreign peer includes the
223 	 * #GUnixCredentialsMessage type and g_socket_get_credentials() function.
224 	 *
225 	 * Params:
226 	 *     cancellable = A #GCancellable or %NULL.
227 	 *
228 	 * Returns: %TRUE on success, %FALSE if @error is set.
229 	 *
230 	 * Since: 2.26
231 	 *
232 	 * Throws: GException on failure.
233 	 */
234 	public bool sendCredentials(Cancellable cancellable)
235 	{
236 		GError* err = null;
237 
238 		auto p = g_unix_connection_send_credentials(gUnixConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
239 
240 		if (err !is null)
241 		{
242 			throw new GException( new ErrorG(err) );
243 		}
244 
245 		return p;
246 	}
247 
248 	/**
249 	 * Asynchronously send credentials.
250 	 *
251 	 * For more details, see g_unix_connection_send_credentials() which is
252 	 * the synchronous version of this call.
253 	 *
254 	 * When the operation is finished, @callback will be called. You can then call
255 	 * g_unix_connection_send_credentials_finish() to get the result of the operation.
256 	 *
257 	 * Params:
258 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
259 	 *     callback = a #GAsyncReadyCallback to call when the request is satisfied
260 	 *     userData = the data to pass to callback function
261 	 *
262 	 * Since: 2.32
263 	 */
264 	public void sendCredentialsAsync(Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
265 	{
266 		g_unix_connection_send_credentials_async(gUnixConnection, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
267 	}
268 
269 	/**
270 	 * Finishes an asynchronous send credentials operation started with
271 	 * g_unix_connection_send_credentials_async().
272 	 *
273 	 * Params:
274 	 *     result = a #GAsyncResult.
275 	 *
276 	 * Returns: %TRUE if the operation was successful, otherwise %FALSE.
277 	 *
278 	 * Since: 2.32
279 	 *
280 	 * Throws: GException on failure.
281 	 */
282 	public bool sendCredentialsFinish(AsyncResultIF result)
283 	{
284 		GError* err = null;
285 
286 		auto p = g_unix_connection_send_credentials_finish(gUnixConnection, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
287 
288 		if (err !is null)
289 		{
290 			throw new GException( new ErrorG(err) );
291 		}
292 
293 		return p;
294 	}
295 
296 	/**
297 	 * Passes a file descriptor to the receiving side of the
298 	 * connection. The receiving end has to call g_unix_connection_receive_fd()
299 	 * to accept the file descriptor.
300 	 *
301 	 * As well as sending the fd this also writes a single byte to the
302 	 * stream, as this is required for fd passing to work on some
303 	 * implementations.
304 	 *
305 	 * Params:
306 	 *     fd = a file descriptor
307 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
308 	 *
309 	 * Returns: a %TRUE on success, %NULL on error.
310 	 *
311 	 * Since: 2.22
312 	 *
313 	 * Throws: GException on failure.
314 	 */
315 	public bool sendFd(int fd, Cancellable cancellable)
316 	{
317 		GError* err = null;
318 
319 		auto p = g_unix_connection_send_fd(gUnixConnection, fd, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
320 
321 		if (err !is null)
322 		{
323 			throw new GException( new ErrorG(err) );
324 		}
325 
326 		return p;
327 	}
328 }