1 /** 2 SSL Stream peer. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.streampeerssl; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 import godot.classdb; 23 import godot.streampeer; 24 import godot.reference; 25 /** 26 SSL Stream peer. 27 28 This object can be used to connect to SSL servers. 29 */ 30 @GodotBaseClass struct StreamPeerSSL 31 { 32 enum string _GODOT_internal_name = "StreamPeerSSL"; 33 public: 34 @nogc nothrow: 35 union { godot_object _godot_object; StreamPeer _GODOT_base; } 36 alias _GODOT_base this; 37 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 38 package(godot) __gshared bool _classBindingInitialized = false; 39 package(godot) static struct _classBinding 40 { 41 __gshared: 42 @GodotName("poll") GodotMethod!(void) poll; 43 @GodotName("accept_stream") GodotMethod!(GodotError, StreamPeer) acceptStream; 44 @GodotName("connect_to_stream") GodotMethod!(GodotError, StreamPeer, bool, String) connectToStream; 45 @GodotName("get_status") GodotMethod!(StreamPeerSSL.Status) getStatus; 46 @GodotName("disconnect_from_stream") GodotMethod!(void) disconnectFromStream; 47 @GodotName("set_blocking_handshake_enabled") GodotMethod!(void, bool) setBlockingHandshakeEnabled; 48 @GodotName("is_blocking_handshake_enabled") GodotMethod!(bool) isBlockingHandshakeEnabled; 49 } 50 bool opEquals(in StreamPeerSSL other) const { return _godot_object.ptr is other._godot_object.ptr; } 51 StreamPeerSSL opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 52 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 53 mixin baseCasts; 54 static StreamPeerSSL _new() 55 { 56 static godot_class_constructor constructor; 57 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("StreamPeerSSL"); 58 if(constructor is null) return typeof(this).init; 59 return cast(StreamPeerSSL)(constructor()); 60 } 61 @disable new(size_t s); 62 /// 63 enum Status : int 64 { 65 /** 66 A status representing a `StreamPeerSSL` that is disconnected. 67 */ 68 statusDisconnected = 0, 69 /** 70 71 */ 72 statusHandshaking = 1, 73 /** 74 A status representing a `StreamPeerSSL` that is connected to a host. 75 */ 76 statusConnected = 2, 77 /** 78 79 */ 80 statusError = 3, 81 /** 82 An error status that shows a mismatch in the SSL certificate domain presented by the host and the domain requested for validation. 83 */ 84 statusErrorHostnameMismatch = 4, 85 } 86 /// 87 enum Constants : int 88 { 89 statusDisconnected = 0, 90 statusHandshaking = 1, 91 statusConnected = 2, 92 statusError = 3, 93 statusErrorHostnameMismatch = 4, 94 } 95 /** 96 Poll the connection to check for incoming bytes. Call this right before "get_available_bytes()" for it to work properly. 97 */ 98 void poll() 99 { 100 checkClassBinding!(typeof(this))(); 101 ptrcall!(void)(_classBinding.poll, _godot_object); 102 } 103 /** 104 105 */ 106 GodotError acceptStream(StreamPeer base) 107 { 108 checkClassBinding!(typeof(this))(); 109 return ptrcall!(GodotError)(_classBinding.acceptStream, _godot_object, base); 110 } 111 /** 112 Connect to a peer using an underlying $(D StreamPeer) "stream", when "validate_certs" is true, `StreamPeerSSL` will validate that the certificate presented by the peer matches the "for_hostname". 113 */ 114 GodotError connectToStream(StringArg2)(StreamPeer stream, in bool validate_certs = false, in StringArg2 for_hostname = "") 115 { 116 checkClassBinding!(typeof(this))(); 117 return ptrcall!(GodotError)(_classBinding.connectToStream, _godot_object, stream, validate_certs, for_hostname); 118 } 119 /** 120 Return the status of the connection, one of STATUS_* enum. 121 */ 122 StreamPeerSSL.Status getStatus() const 123 { 124 checkClassBinding!(typeof(this))(); 125 return ptrcall!(StreamPeerSSL.Status)(_classBinding.getStatus, _godot_object); 126 } 127 /** 128 Disconnect from host. 129 */ 130 void disconnectFromStream() 131 { 132 checkClassBinding!(typeof(this))(); 133 ptrcall!(void)(_classBinding.disconnectFromStream, _godot_object); 134 } 135 /** 136 137 */ 138 void setBlockingHandshakeEnabled(in bool enabled) 139 { 140 checkClassBinding!(typeof(this))(); 141 ptrcall!(void)(_classBinding.setBlockingHandshakeEnabled, _godot_object, enabled); 142 } 143 /** 144 145 */ 146 bool isBlockingHandshakeEnabled() const 147 { 148 checkClassBinding!(typeof(this))(); 149 return ptrcall!(bool)(_classBinding.isBlockingHandshakeEnabled, _godot_object); 150 } 151 /** 152 153 */ 154 @property bool blockingHandshake() 155 { 156 return isBlockingHandshakeEnabled(); 157 } 158 /// ditto 159 @property void blockingHandshake(bool v) 160 { 161 setBlockingHandshakeEnabled(v); 162 } 163 }