1 /**
2 Internet protocol (IP) support functions like 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.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 /**
23 Internet protocol (IP) support functions like DNS resolution.
24 
25 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.
26 */
27 @GodotBaseClass struct IPSingleton
28 {
29 	enum string _GODOT_internal_name = "IP";
30 public:
31 @nogc nothrow:
32 	union { godot_object _godot_object; GodotObject _GODOT_base; }
33 	alias _GODOT_base this;
34 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
35 	package(godot) __gshared bool _classBindingInitialized = false;
36 	package(godot) static struct _classBinding
37 	{
38 		__gshared:
39 		godot_object _singleton;
40 		immutable char* _singletonName = "IP";
41 		@GodotName("resolve_hostname") GodotMethod!(String, String, long) resolveHostname;
42 		@GodotName("resolve_hostname_queue_item") GodotMethod!(long, String, long) resolveHostnameQueueItem;
43 		@GodotName("get_resolve_item_status") GodotMethod!(IP.ResolverStatus, long) getResolveItemStatus;
44 		@GodotName("get_resolve_item_address") GodotMethod!(String, long) getResolveItemAddress;
45 		@GodotName("erase_resolve_item") GodotMethod!(void, long) eraseResolveItem;
46 		@GodotName("get_local_addresses") GodotMethod!(Array) getLocalAddresses;
47 		@GodotName("clear_cache") GodotMethod!(void, String) clearCache;
48 	}
49 	bool opEquals(in IPSingleton other) const { return _godot_object.ptr is other._godot_object.ptr; }
50 	IPSingleton opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
51 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
52 	mixin baseCasts;
53 	static IPSingleton _new()
54 	{
55 		static godot_class_constructor constructor;
56 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("IP");
57 		if(constructor is null) return typeof(this).init;
58 		return cast(IPSingleton)(constructor());
59 	}
60 	@disable new(size_t s);
61 	/// 
62 	enum ResolverStatus : int
63 	{
64 		/**
65 		DNS hostname resolver status: No status.
66 		*/
67 		resolverStatusNone = 0,
68 		/**
69 		DNS hostname resolver status: Waiting.
70 		*/
71 		resolverStatusWaiting = 1,
72 		/**
73 		DNS hostname resolver status: Done.
74 		*/
75 		resolverStatusDone = 2,
76 		/**
77 		DNS hostname resolver status: Error.
78 		*/
79 		resolverStatusError = 3,
80 	}
81 	/// 
82 	enum Type : int
83 	{
84 		/**
85 		Address type: None.
86 		*/
87 		typeNone = 0,
88 		/**
89 		Address type: Internet protocol version 4 (IPv4).
90 		*/
91 		typeIpv4 = 1,
92 		/**
93 		Address type: Internet protocol version 6 (IPv6).
94 		*/
95 		typeIpv6 = 2,
96 		/**
97 		Address type: Any.
98 		*/
99 		typeAny = 3,
100 	}
101 	/// 
102 	enum Constants : int
103 	{
104 		/**
105 		Invalid ID constant. Returned if `RESOLVER_MAX_QUERIES` is exceeded.
106 		*/
107 		resolverInvalidId = -1,
108 		typeNone = 0,
109 		resolverStatusNone = 0,
110 		resolverStatusWaiting = 1,
111 		typeIpv4 = 1,
112 		resolverStatusDone = 2,
113 		typeIpv6 = 2,
114 		resolverStatusError = 3,
115 		typeAny = 3,
116 		/**
117 		Maximum number of concurrent DNS resolver queries allowed, `RESOLVER_INVALID_ID` is returned if exceeded.
118 		*/
119 		resolverMaxQueries = 32,
120 	}
121 	/**
122 	Returns a given hostname's IPv4 or IPv6 address when resolved (blocking-type method). The address type returned depends on the TYPE_* constant given as "ip_type".
123 	*/
124 	String resolveHostname(StringArg0)(in StringArg0 host, in long ip_type = 3)
125 	{
126 		checkClassBinding!(typeof(this))();
127 		return ptrcall!(String)(_classBinding.resolveHostname, _godot_object, host, ip_type);
128 	}
129 	/**
130 	Creates a queue item to resolve a hostname to an IPv4 or IPv6 address depending on the TYPE_* constant given as "ip_type". Returns the queue ID if successful, or RESOLVER_INVALID_ID on error.
131 	*/
132 	long resolveHostnameQueueItem(StringArg0)(in StringArg0 host, in long ip_type = 3)
133 	{
134 		checkClassBinding!(typeof(this))();
135 		return ptrcall!(long)(_classBinding.resolveHostnameQueueItem, _godot_object, host, ip_type);
136 	}
137 	/**
138 	Returns a queued hostname's status as a RESOLVER_STATUS_* constant, given its queue "id".
139 	*/
140 	IP.ResolverStatus getResolveItemStatus(in long id) const
141 	{
142 		checkClassBinding!(typeof(this))();
143 		return ptrcall!(IP.ResolverStatus)(_classBinding.getResolveItemStatus, _godot_object, id);
144 	}
145 	/**
146 	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)).
147 	*/
148 	String getResolveItemAddress(in long id) const
149 	{
150 		checkClassBinding!(typeof(this))();
151 		return ptrcall!(String)(_classBinding.getResolveItemAddress, _godot_object, id);
152 	}
153 	/**
154 	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.
155 	*/
156 	void eraseResolveItem(in long id)
157 	{
158 		checkClassBinding!(typeof(this))();
159 		ptrcall!(void)(_classBinding.eraseResolveItem, _godot_object, id);
160 	}
161 	/**
162 	Returns all of the user's current IPv4 and IPv6 addresses as an array.
163 	*/
164 	Array getLocalAddresses() const
165 	{
166 		checkClassBinding!(typeof(this))();
167 		return ptrcall!(Array)(_classBinding.getLocalAddresses, _godot_object);
168 	}
169 	/**
170 	Removes all of a "hostname"'s cached references. If no "hostname" is given then all cached IP addresses are removed.
171 	*/
172 	void clearCache(StringArg0)(in StringArg0 hostname = "")
173 	{
174 		checkClassBinding!(typeof(this))();
175 		ptrcall!(void)(_classBinding.clearCache, _godot_object, hostname);
176 	}
177 }
178 /// Returns: the IPSingleton
179 @property @nogc nothrow pragma(inline, true)
180 IPSingleton IP()
181 {
182 	checkClassBinding!IPSingleton();
183 	return IPSingleton(IPSingleton._classBinding._singleton);
184 }