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