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.InetAddressMask;
26 
27 private import gio.InetAddress;
28 private import gio.InitableIF;
29 private import gio.InitableT;
30 private import glib.ConstructionException;
31 private import glib.ErrorG;
32 private import glib.GException;
33 private import glib.Str;
34 private import gobject.ObjectG;
35 private import gtkc.gio;
36 public  import gtkc.giotypes;
37 
38 
39 /**
40  * #GInetAddressMask represents a range of IPv4 or IPv6 addresses
41  * described by a base address and a length indicating how many bits
42  * of the base address are relevant for matching purposes. These are
43  * often given in string form. Eg, "10.0.0.0/8", or "fe80::/10".
44  *
45  * Since: 2.32
46  */
47 public class InetAddressMask : ObjectG, InitableIF
48 {
49 	/** the main Gtk struct */
50 	protected GInetAddressMask* gInetAddressMask;
51 
52 	/** Get the main Gtk struct */
53 	public GInetAddressMask* getInetAddressMaskStruct(bool transferOwnership = false)
54 	{
55 		if (transferOwnership)
56 			ownedRef = false;
57 		return gInetAddressMask;
58 	}
59 
60 	/** the main Gtk struct as a void* */
61 	protected override void* getStruct()
62 	{
63 		return cast(void*)gInetAddressMask;
64 	}
65 
66 	protected override void setStruct(GObject* obj)
67 	{
68 		gInetAddressMask = cast(GInetAddressMask*)obj;
69 		super.setStruct(obj);
70 	}
71 
72 	/**
73 	 * Sets our main struct and passes it to the parent class.
74 	 */
75 	public this (GInetAddressMask* gInetAddressMask, bool ownedRef = false)
76 	{
77 		this.gInetAddressMask = gInetAddressMask;
78 		super(cast(GObject*)gInetAddressMask, ownedRef);
79 	}
80 
81 	// add the Initable capabilities
82 	mixin InitableT!(GInetAddressMask);
83 
84 
85 	/** */
86 	public static GType getType()
87 	{
88 		return g_inet_address_mask_get_type();
89 	}
90 
91 	/**
92 	 * Creates a new #GInetAddressMask representing all addresses whose
93 	 * first @length bits match @addr.
94 	 *
95 	 * Params:
96 	 *     addr = a #GInetAddress
97 	 *     length = number of bits of @addr to use
98 	 *
99 	 * Returns: a new #GInetAddressMask, or %NULL on error
100 	 *
101 	 * Since: 2.32
102 	 *
103 	 * Throws: GException on failure.
104 	 * Throws: ConstructionException GTK+ fails to create the object.
105 	 */
106 	public this(InetAddress addr, uint length)
107 	{
108 		GError* err = null;
109 		
110 		auto p = g_inet_address_mask_new((addr is null) ? null : addr.getInetAddressStruct(), length, &err);
111 		
112 		if (err !is null)
113 		{
114 			throw new GException( new ErrorG(err) );
115 		}
116 		
117 		if(p is null)
118 		{
119 			throw new ConstructionException("null returned by new");
120 		}
121 		
122 		this(cast(GInetAddressMask*) p, true);
123 	}
124 
125 	/**
126 	 * Parses @mask_string as an IP address and (optional) length, and
127 	 * creates a new #GInetAddressMask. The length, if present, is
128 	 * delimited by a "/". If it is not present, then the length is
129 	 * assumed to be the full length of the address.
130 	 *
131 	 * Params:
132 	 *     maskString = an IP address or address/length string
133 	 *
134 	 * Returns: a new #GInetAddressMask corresponding to @string, or %NULL
135 	 *     on error.
136 	 *
137 	 * Since: 2.32
138 	 *
139 	 * Throws: GException on failure.
140 	 * Throws: ConstructionException GTK+ fails to create the object.
141 	 */
142 	public this(string maskString)
143 	{
144 		GError* err = null;
145 		
146 		auto p = g_inet_address_mask_new_from_string(Str.toStringz(maskString), &err);
147 		
148 		if (err !is null)
149 		{
150 			throw new GException( new ErrorG(err) );
151 		}
152 		
153 		if(p is null)
154 		{
155 			throw new ConstructionException("null returned by new_from_string");
156 		}
157 		
158 		this(cast(GInetAddressMask*) p, true);
159 	}
160 
161 	/**
162 	 * Tests if @mask and @mask2 are the same mask.
163 	 *
164 	 * Params:
165 	 *     mask2 = another #GInetAddressMask
166 	 *
167 	 * Returns: whether @mask and @mask2 are the same mask
168 	 *
169 	 * Since: 2.32
170 	 */
171 	public bool equal(InetAddressMask mask2)
172 	{
173 		return g_inet_address_mask_equal(gInetAddressMask, (mask2 is null) ? null : mask2.getInetAddressMaskStruct()) != 0;
174 	}
175 
176 	/**
177 	 * Gets @mask's base address
178 	 *
179 	 * Returns: @mask's base address
180 	 *
181 	 * Since: 2.32
182 	 */
183 	public InetAddress getAddress()
184 	{
185 		auto p = g_inet_address_mask_get_address(gInetAddressMask);
186 		
187 		if(p is null)
188 		{
189 			return null;
190 		}
191 		
192 		return ObjectG.getDObject!(InetAddress)(cast(GInetAddress*) p);
193 	}
194 
195 	/**
196 	 * Gets the #GSocketFamily of @mask's address
197 	 *
198 	 * Returns: the #GSocketFamily of @mask's address
199 	 *
200 	 * Since: 2.32
201 	 */
202 	public GSocketFamily getFamily()
203 	{
204 		return g_inet_address_mask_get_family(gInetAddressMask);
205 	}
206 
207 	/**
208 	 * Gets @mask's length
209 	 *
210 	 * Returns: @mask's length
211 	 *
212 	 * Since: 2.32
213 	 */
214 	public uint getLength()
215 	{
216 		return g_inet_address_mask_get_length(gInetAddressMask);
217 	}
218 
219 	/**
220 	 * Tests if @address falls within the range described by @mask.
221 	 *
222 	 * Params:
223 	 *     address = a #GInetAddress
224 	 *
225 	 * Returns: whether @address falls within the range described by
226 	 *     @mask.
227 	 *
228 	 * Since: 2.32
229 	 */
230 	public bool matches(InetAddress address)
231 	{
232 		return g_inet_address_mask_matches(gInetAddressMask, (address is null) ? null : address.getInetAddressStruct()) != 0;
233 	}
234 
235 	/**
236 	 * Converts @mask back to its corresponding string form.
237 	 *
238 	 * Returns: a string corresponding to @mask.
239 	 *
240 	 * Since: 2.32
241 	 */
242 	public override string toString()
243 	{
244 		auto retStr = g_inet_address_mask_to_string(gInetAddressMask);
245 		
246 		scope(exit) Str.freeString(retStr);
247 		return Str.toString(retStr);
248 	}
249 }