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