1 /**
2 Internet protocol (IP) support functions such as DNS resolution.
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.ip;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.traits;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.globalenums;
22 import godot.object;
23 /**
24 Internet protocol (IP) support functions such as DNS resolution.
25 
26 IP contains support functions for the Internet Protocol (IP). TCP/IP support is in different classes (see $(D StreamPeerTCP) and $(D TCP_Server)). IP provides DNS hostname resolution support, both blocking and threaded.
27 */
28 @GodotBaseClass struct IPSingleton
29 {
30 	package(godot) enum string _GODOT_internal_name = "IP";
31 public:
32 @nogc nothrow:
33 	union { /** */ godot_object _godot_object; /** */ GodotObject _GODOT_base; }
34 	alias _GODOT_base this;
35 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
36 	package(godot) __gshared bool _classBindingInitialized = false;
37 	package(godot) static struct GDNativeClassBinding
38 	{
39 		__gshared:
40 		godot_object _singleton;
41 		immutable char* _singletonName = "IP";
42 		@GodotName("clear_cache") GodotMethod!(void, String) clearCache;
43 		@GodotName("erase_resolve_item") GodotMethod!(void, long) eraseResolveItem;
44 		@GodotName("get_local_addresses") GodotMethod!(Array) getLocalAddresses;
45 		@GodotName("get_local_interfaces") GodotMethod!(Array) getLocalInterfaces;
46 		@GodotName("get_resolve_item_address") GodotMethod!(String, long) getResolveItemAddress;
47 		@GodotName("get_resolve_item_status") GodotMethod!(IP.ResolverStatus, long) getResolveItemStatus;
48 		@GodotName("resolve_hostname") GodotMethod!(String, String, long) resolveHostname;
49 		@GodotName("resolve_hostname_queue_item") GodotMethod!(long, String, long) resolveHostnameQueueItem;
50 	}
51 	/// 
52 	pragma(inline, true) bool opEquals(in IPSingleton other) const
53 	{ return _godot_object.ptr is other._godot_object.ptr; }
54 	/// 
55 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
56 	{ _godot_object.ptr = n; return null; }
57 	/// 
58 	pragma(inline, true) bool opEquals(typeof(null) n) const
59 	{ return _godot_object.ptr is n; }
60 	/// 
61 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
62 	mixin baseCasts;
63 	/// Construct a new instance of IPSingleton.
64 	/// Note: use `memnew!IPSingleton` instead.
65 	static IPSingleton _new()
66 	{
67 		static godot_class_constructor constructor;
68 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("IP");
69 		if(constructor is null) return typeof(this).init;
70 		return cast(IPSingleton)(constructor());
71 	}
72 	@disable new(size_t s);
73 	/// 
74 	enum ResolverStatus : int
75 	{
76 		/**
77 		DNS hostname resolver status: No status.
78 		*/
79 		resolverStatusNone = 0,
80 		/**
81 		DNS hostname resolver status: Waiting.
82 		*/
83 		resolverStatusWaiting = 1,
84 		/**
85 		DNS hostname resolver status: Done.
86 		*/
87 		resolverStatusDone = 2,
88 		/**
89 		DNS hostname resolver status: Error.
90 		*/
91 		resolverStatusError = 3,
92 	}
93 	/// 
94 	enum Type : int
95 	{
96 		/**
97 		Address type: None.
98 		*/
99 		typeNone = 0,
100 		/**
101 		Address type: Internet protocol version 4 (IPv4).
102 		*/
103 		typeIpv4 = 1,
104 		/**
105 		Address type: Internet protocol version 6 (IPv6).
106 		*/
107 		typeIpv6 = 2,
108 		/**
109 		Address type: Any.
110 		*/
111 		typeAny = 3,
112 	}
113 	/// 
114 	enum Constants : int
115 	{
116 		/**
117 		Invalid ID constant. Returned if $(D constant RESOLVER_MAX_QUERIES) is exceeded.
118 		*/
119 		resolverInvalidId = -1,
120 		typeNone = 0,
121 		resolverStatusNone = 0,
122 		resolverStatusWaiting = 1,
123 		typeIpv4 = 1,
124 		resolverStatusDone = 2,
125 		typeIpv6 = 2,
126 		resolverStatusError = 3,
127 		typeAny = 3,
128 		/**
129 		Maximum number of concurrent DNS resolver queries allowed, $(D constant RESOLVER_INVALID_ID) is returned if exceeded.
130 		*/
131 		resolverMaxQueries = 32,
132 	}
133 	/**
134 	Removes all of a `hostname`'s cached references. If no `hostname` is given, all cached IP addresses are removed.
135 	*/
136 	void clearCache(in String hostname = gs!"")
137 	{
138 		checkClassBinding!(typeof(this))();
139 		ptrcall!(void)(GDNativeClassBinding.clearCache, _godot_object, hostname);
140 	}
141 	/**
142 	Removes a given item `id` from the queue. This should be used to free a queue after it has completed to enable more queries to happen.
143 	*/
144 	void eraseResolveItem(in long id)
145 	{
146 		checkClassBinding!(typeof(this))();
147 		ptrcall!(void)(GDNativeClassBinding.eraseResolveItem, _godot_object, id);
148 	}
149 	/**
150 	Returns all the user's current IPv4 and IPv6 addresses as an array.
151 	*/
152 	Array getLocalAddresses() const
153 	{
154 		checkClassBinding!(typeof(this))();
155 		return ptrcall!(Array)(GDNativeClassBinding.getLocalAddresses, _godot_object);
156 	}
157 	/**
158 	Returns all network adapters as an array.
159 	Each adapter is a dictionary of the form:
160 	
161 	
162 	{
163 	    "index": "1", # Interface index.
164 	    "name": "eth0", # Interface name.
165 	    "friendly": "Ethernet One", # A friendly name (might be empty).
166 	    "addresses": $(D "192.168.1.101"), # An array of IP addresses associated to this interface.
167 	}
168 	
169 	
170 	*/
171 	Array getLocalInterfaces() const
172 	{
173 		checkClassBinding!(typeof(this))();
174 		return ptrcall!(Array)(GDNativeClassBinding.getLocalInterfaces, _godot_object);
175 	}
176 	/**
177 	Returns a queued hostname's IP address, given its queue `id`. Returns an empty string on error or if resolution hasn't happened yet (see $(D getResolveItemStatus)).
178 	*/
179 	String getResolveItemAddress(in long id) const
180 	{
181 		checkClassBinding!(typeof(this))();
182 		return ptrcall!(String)(GDNativeClassBinding.getResolveItemAddress, _godot_object, id);
183 	}
184 	/**
185 	Returns a queued hostname's status as a $(D resolverstatus) constant, given its queue `id`.
186 	*/
187 	IP.ResolverStatus getResolveItemStatus(in long id) const
188 	{
189 		checkClassBinding!(typeof(this))();
190 		return ptrcall!(IP.ResolverStatus)(GDNativeClassBinding.getResolveItemStatus, _godot_object, id);
191 	}
192 	/**
193 	Returns a given hostname's IPv4 or IPv6 address when resolved (blocking-type method). The address type returned depends on the $(D type) constant given as `ip_type`.
194 	*/
195 	String resolveHostname(in String host, in long ip_type = 3)
196 	{
197 		checkClassBinding!(typeof(this))();
198 		return ptrcall!(String)(GDNativeClassBinding.resolveHostname, _godot_object, host, ip_type);
199 	}
200 	/**
201 	Creates a queue item to resolve a hostname to an IPv4 or IPv6 address depending on the $(D type) constant given as `ip_type`. Returns the queue ID if successful, or $(D constant RESOLVER_INVALID_ID) on error.
202 	*/
203 	long resolveHostnameQueueItem(in String host, in long ip_type = 3)
204 	{
205 		checkClassBinding!(typeof(this))();
206 		return ptrcall!(long)(GDNativeClassBinding.resolveHostnameQueueItem, _godot_object, host, ip_type);
207 	}
208 }
209 /// Returns: the IPSingleton
210 @property @nogc nothrow pragma(inline, true)
211 IPSingleton IP()
212 {
213 	checkClassBinding!IPSingleton();
214 	return IPSingleton(IPSingleton.GDNativeClassBinding._singleton);
215 }