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.TlsInteraction; 26 27 private import gio.AsyncResultIF; 28 private import gio.Cancellable; 29 private import gio.TlsConnection; 30 private import gio.TlsPassword; 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 * #GTlsInteraction provides a mechanism for the TLS connection and database 40 * code to interact with the user. It can be used to ask the user for passwords. 41 * 42 * To use a #GTlsInteraction with a TLS connection use 43 * g_tls_connection_set_interaction(). 44 * 45 * Callers should instantiate a derived class that implements the various 46 * interaction methods to show the required dialogs. 47 * 48 * Callers should use the 'invoke' functions like 49 * g_tls_interaction_invoke_ask_password() to run interaction methods. These 50 * functions make sure that the interaction is invoked in the main loop 51 * and not in the current thread, if the current thread is not running the 52 * main loop. 53 * 54 * Derived classes can choose to implement whichever interactions methods they'd 55 * like to support by overriding those virtual methods in their class 56 * initialization function. Any interactions not implemented will return 57 * %G_TLS_INTERACTION_UNHANDLED. If a derived class implements an async method, 58 * it must also implement the corresponding finish method. 59 * 60 * Since: 2.30 61 */ 62 public class TlsInteraction : ObjectG 63 { 64 /** the main Gtk struct */ 65 protected GTlsInteraction* gTlsInteraction; 66 67 /** Get the main Gtk struct */ 68 public GTlsInteraction* getTlsInteractionStruct(bool transferOwnership = false) 69 { 70 if (transferOwnership) 71 ownedRef = false; 72 return gTlsInteraction; 73 } 74 75 /** the main Gtk struct as a void* */ 76 protected override void* getStruct() 77 { 78 return cast(void*)gTlsInteraction; 79 } 80 81 /** 82 * Sets our main struct and passes it to the parent class. 83 */ 84 public this (GTlsInteraction* gTlsInteraction, bool ownedRef = false) 85 { 86 this.gTlsInteraction = gTlsInteraction; 87 super(cast(GObject*)gTlsInteraction, ownedRef); 88 } 89 90 91 /** */ 92 public static GType getType() 93 { 94 return g_tls_interaction_get_type(); 95 } 96 97 /** 98 * Run synchronous interaction to ask the user for a password. In general, 99 * g_tls_interaction_invoke_ask_password() should be used instead of this 100 * function. 101 * 102 * Derived subclasses usually implement a password prompt, although they may 103 * also choose to provide a password from elsewhere. The @password value will 104 * be filled in and then @callback will be called. Alternatively the user may 105 * abort this password request, which will usually abort the TLS connection. 106 * 107 * If the interaction is cancelled by the cancellation object, or by the 108 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that 109 * contains a %G_IO_ERROR_CANCELLED error code. Certain implementations may 110 * not support immediate cancellation. 111 * 112 * Params: 113 * password = a #GTlsPassword object 114 * cancellable = an optional #GCancellable cancellation object 115 * 116 * Returns: The status of the ask password interaction. 117 * 118 * Since: 2.30 119 * 120 * Throws: GException on failure. 121 */ 122 public GTlsInteractionResult askPassword(TlsPassword password, Cancellable cancellable) 123 { 124 GError* err = null; 125 126 auto __p = g_tls_interaction_ask_password(gTlsInteraction, (password is null) ? null : password.getTlsPasswordStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 127 128 if (err !is null) 129 { 130 throw new GException( new ErrorG(err) ); 131 } 132 133 return __p; 134 } 135 136 /** 137 * Run asynchronous interaction to ask the user for a password. In general, 138 * g_tls_interaction_invoke_ask_password() should be used instead of this 139 * function. 140 * 141 * Derived subclasses usually implement a password prompt, although they may 142 * also choose to provide a password from elsewhere. The @password value will 143 * be filled in and then @callback will be called. Alternatively the user may 144 * abort this password request, which will usually abort the TLS connection. 145 * 146 * If the interaction is cancelled by the cancellation object, or by the 147 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that 148 * contains a %G_IO_ERROR_CANCELLED error code. Certain implementations may 149 * not support immediate cancellation. 150 * 151 * Certain implementations may not support immediate cancellation. 152 * 153 * Params: 154 * password = a #GTlsPassword object 155 * cancellable = an optional #GCancellable cancellation object 156 * callback = will be called when the interaction completes 157 * userData = data to pass to the @callback 158 * 159 * Since: 2.30 160 */ 161 public void askPasswordAsync(TlsPassword password, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 162 { 163 g_tls_interaction_ask_password_async(gTlsInteraction, (password is null) ? null : password.getTlsPasswordStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 164 } 165 166 /** 167 * Complete an ask password user interaction request. This should be once 168 * the g_tls_interaction_ask_password_async() completion callback is called. 169 * 170 * If %G_TLS_INTERACTION_HANDLED is returned, then the #GTlsPassword passed 171 * to g_tls_interaction_ask_password() will have its password filled in. 172 * 173 * If the interaction is cancelled by the cancellation object, or by the 174 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that 175 * contains a %G_IO_ERROR_CANCELLED error code. 176 * 177 * Params: 178 * result = the result passed to the callback 179 * 180 * Returns: The status of the ask password interaction. 181 * 182 * Since: 2.30 183 * 184 * Throws: GException on failure. 185 */ 186 public GTlsInteractionResult askPasswordFinish(AsyncResultIF result) 187 { 188 GError* err = null; 189 190 auto __p = g_tls_interaction_ask_password_finish(gTlsInteraction, (result is null) ? null : result.getAsyncResultStruct(), &err); 191 192 if (err !is null) 193 { 194 throw new GException( new ErrorG(err) ); 195 } 196 197 return __p; 198 } 199 200 /** 201 * Invoke the interaction to ask the user for a password. It invokes this 202 * interaction in the main loop, specifically the #GMainContext returned by 203 * g_main_context_get_thread_default() when the interaction is created. This 204 * is called by called by #GTlsConnection or #GTlsDatabase to ask the user 205 * for a password. 206 * 207 * Derived subclasses usually implement a password prompt, although they may 208 * also choose to provide a password from elsewhere. The @password value will 209 * be filled in and then @callback will be called. Alternatively the user may 210 * abort this password request, which will usually abort the TLS connection. 211 * 212 * The implementation can either be a synchronous (eg: modal dialog) or an 213 * asynchronous one (eg: modeless dialog). This function will take care of 214 * calling which ever one correctly. 215 * 216 * If the interaction is cancelled by the cancellation object, or by the 217 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that 218 * contains a %G_IO_ERROR_CANCELLED error code. Certain implementations may 219 * not support immediate cancellation. 220 * 221 * Params: 222 * password = a #GTlsPassword object 223 * cancellable = an optional #GCancellable cancellation object 224 * 225 * Returns: The status of the ask password interaction. 226 * 227 * Since: 2.30 228 * 229 * Throws: GException on failure. 230 */ 231 public GTlsInteractionResult invokeAskPassword(TlsPassword password, Cancellable cancellable) 232 { 233 GError* err = null; 234 235 auto __p = g_tls_interaction_invoke_ask_password(gTlsInteraction, (password is null) ? null : password.getTlsPasswordStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 236 237 if (err !is null) 238 { 239 throw new GException( new ErrorG(err) ); 240 } 241 242 return __p; 243 } 244 245 /** 246 * Invoke the interaction to ask the user to choose a certificate to 247 * use with the connection. It invokes this interaction in the main 248 * loop, specifically the #GMainContext returned by 249 * g_main_context_get_thread_default() when the interaction is 250 * created. This is called by called by #GTlsConnection when the peer 251 * requests a certificate during the handshake. 252 * 253 * Derived subclasses usually implement a certificate selector, 254 * although they may also choose to provide a certificate from 255 * elsewhere. Alternatively the user may abort this certificate 256 * request, which may or may not abort the TLS connection. 257 * 258 * The implementation can either be a synchronous (eg: modal dialog) or an 259 * asynchronous one (eg: modeless dialog). This function will take care of 260 * calling which ever one correctly. 261 * 262 * If the interaction is cancelled by the cancellation object, or by the 263 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that 264 * contains a %G_IO_ERROR_CANCELLED error code. Certain implementations may 265 * not support immediate cancellation. 266 * 267 * Params: 268 * connection = a #GTlsConnection object 269 * flags = flags providing more information about the request 270 * cancellable = an optional #GCancellable cancellation object 271 * 272 * Returns: The status of the certificate request interaction. 273 * 274 * Since: 2.40 275 * 276 * Throws: GException on failure. 277 */ 278 public GTlsInteractionResult invokeRequestCertificate(TlsConnection connection, GTlsCertificateRequestFlags flags, Cancellable cancellable) 279 { 280 GError* err = null; 281 282 auto __p = g_tls_interaction_invoke_request_certificate(gTlsInteraction, (connection is null) ? null : connection.getTlsConnectionStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 283 284 if (err !is null) 285 { 286 throw new GException( new ErrorG(err) ); 287 } 288 289 return __p; 290 } 291 292 /** 293 * Run synchronous interaction to ask the user to choose a certificate to use 294 * with the connection. In general, g_tls_interaction_invoke_request_certificate() 295 * should be used instead of this function. 296 * 297 * Derived subclasses usually implement a certificate selector, although they may 298 * also choose to provide a certificate from elsewhere. Alternatively the user may 299 * abort this certificate request, which will usually abort the TLS connection. 300 * 301 * If %G_TLS_INTERACTION_HANDLED is returned, then the #GTlsConnection 302 * passed to g_tls_interaction_request_certificate() will have had its 303 * #GTlsConnection:certificate filled in. 304 * 305 * If the interaction is cancelled by the cancellation object, or by the 306 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that 307 * contains a %G_IO_ERROR_CANCELLED error code. Certain implementations may 308 * not support immediate cancellation. 309 * 310 * Params: 311 * connection = a #GTlsConnection object 312 * flags = flags providing more information about the request 313 * cancellable = an optional #GCancellable cancellation object 314 * 315 * Returns: The status of the request certificate interaction. 316 * 317 * Since: 2.40 318 * 319 * Throws: GException on failure. 320 */ 321 public GTlsInteractionResult requestCertificate(TlsConnection connection, GTlsCertificateRequestFlags flags, Cancellable cancellable) 322 { 323 GError* err = null; 324 325 auto __p = g_tls_interaction_request_certificate(gTlsInteraction, (connection is null) ? null : connection.getTlsConnectionStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 326 327 if (err !is null) 328 { 329 throw new GException( new ErrorG(err) ); 330 } 331 332 return __p; 333 } 334 335 /** 336 * Run asynchronous interaction to ask the user for a certificate to use with 337 * the connection. In general, g_tls_interaction_invoke_request_certificate() should 338 * be used instead of this function. 339 * 340 * Derived subclasses usually implement a certificate selector, although they may 341 * also choose to provide a certificate from elsewhere. @callback will be called 342 * when the operation completes. Alternatively the user may abort this certificate 343 * request, which will usually abort the TLS connection. 344 * 345 * Params: 346 * connection = a #GTlsConnection object 347 * flags = flags providing more information about the request 348 * cancellable = an optional #GCancellable cancellation object 349 * callback = will be called when the interaction completes 350 * userData = data to pass to the @callback 351 * 352 * Since: 2.40 353 */ 354 public void requestCertificateAsync(TlsConnection connection, GTlsCertificateRequestFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 355 { 356 g_tls_interaction_request_certificate_async(gTlsInteraction, (connection is null) ? null : connection.getTlsConnectionStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 357 } 358 359 /** 360 * Complete a request certificate user interaction request. This should be once 361 * the g_tls_interaction_request_certificate_async() completion callback is called. 362 * 363 * If %G_TLS_INTERACTION_HANDLED is returned, then the #GTlsConnection 364 * passed to g_tls_interaction_request_certificate_async() will have had its 365 * #GTlsConnection:certificate filled in. 366 * 367 * If the interaction is cancelled by the cancellation object, or by the 368 * user then %G_TLS_INTERACTION_FAILED will be returned with an error that 369 * contains a %G_IO_ERROR_CANCELLED error code. 370 * 371 * Params: 372 * result = the result passed to the callback 373 * 374 * Returns: The status of the request certificate interaction. 375 * 376 * Since: 2.40 377 * 378 * Throws: GException on failure. 379 */ 380 public GTlsInteractionResult requestCertificateFinish(AsyncResultIF result) 381 { 382 GError* err = null; 383 384 auto __p = g_tls_interaction_request_certificate_finish(gTlsInteraction, (result is null) ? null : result.getAsyncResultStruct(), &err); 385 386 if (err !is null) 387 { 388 throw new GException( new ErrorG(err) ); 389 } 390 391 return __p; 392 } 393 }