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.UnixSocketAddress;
26 
27 private import gio.SocketAddress;
28 private import glib.ConstructionException;
29 private import glib.Str;
30 private import gobject.ObjectG;
31 private import gtkc.gio;
32 public  import gtkc.giotypes;
33 
34 
35 /**
36  * Support for UNIX-domain (also known as local) sockets.
37  * 
38  * UNIX domain sockets are generally visible in the filesystem.
39  * However, some systems support abstract socket names which are not
40  * visible in the filesystem and not affected by the filesystem
41  * permissions, visibility, etc. Currently this is only supported
42  * under Linux. If you attempt to use abstract sockets on other
43  * systems, function calls may return %G_IO_ERROR_NOT_SUPPORTED
44  * errors. You can use g_unix_socket_address_abstract_names_supported()
45  * to see if abstract names are supported.
46  * 
47  * Note that `<gio/gunixsocketaddress.h>` belongs to the UNIX-specific GIO
48  * interfaces, thus you have to use the `gio-unix-2.0.pc` pkg-config file
49  * when using it.
50  */
51 public class UnixSocketAddress : SocketAddress
52 {
53 	/** the main Gtk struct */
54 	protected GUnixSocketAddress* gUnixSocketAddress;
55 
56 	/** Get the main Gtk struct */
57 	public GUnixSocketAddress* getUnixSocketAddressStruct()
58 	{
59 		return gUnixSocketAddress;
60 	}
61 
62 	/** the main Gtk struct as a void* */
63 	protected override void* getStruct()
64 	{
65 		return cast(void*)gUnixSocketAddress;
66 	}
67 
68 	protected override void setStruct(GObject* obj)
69 	{
70 		gUnixSocketAddress = cast(GUnixSocketAddress*)obj;
71 		super.setStruct(obj);
72 	}
73 
74 	/**
75 	 * Sets our main struct and passes it to the parent class.
76 	 */
77 	public this (GUnixSocketAddress* gUnixSocketAddress, bool ownedRef = false)
78 	{
79 		this.gUnixSocketAddress = gUnixSocketAddress;
80 		super(cast(GSocketAddress*)gUnixSocketAddress, ownedRef);
81 	}
82 
83 
84 	/** */
85 	public static GType getType()
86 	{
87 		return g_unix_socket_address_get_type();
88 	}
89 
90 	/**
91 	 * Creates a new #GUnixSocketAddress for @path.
92 	 *
93 	 * To create abstract socket addresses, on systems that support that,
94 	 * use g_unix_socket_address_new_abstract().
95 	 *
96 	 * Params:
97 	 *     path = the socket path
98 	 *
99 	 * Return: a new #GUnixSocketAddress
100 	 *
101 	 * Since: 2.22
102 	 *
103 	 * Throws: ConstructionException GTK+ fails to create the object.
104 	 */
105 	public this(string path)
106 	{
107 		auto p = g_unix_socket_address_new(Str.toStringz(path));
108 		
109 		if(p is null)
110 		{
111 			throw new ConstructionException("null returned by new");
112 		}
113 		
114 		this(cast(GUnixSocketAddress*) p, true);
115 	}
116 
117 	/**
118 	 * Creates a new #GUnixSocketAddress of type @type with name @path.
119 	 *
120 	 * If @type is %G_UNIX_SOCKET_ADDRESS_PATH, this is equivalent to
121 	 * calling g_unix_socket_address_new().
122 	 *
123 	 * If @path_type is %G_UNIX_SOCKET_ADDRESS_ABSTRACT, then @path_len
124 	 * bytes of @path will be copied to the socket's path, and only those
125 	 * bytes will be considered part of the name. (If @path_len is -1,
126 	 * then @path is assumed to be NUL-terminated.) For example, if @path
127 	 * was "test", then calling g_socket_address_get_native_size() on the
128 	 * returned socket would return 7 (2 bytes of overhead, 1 byte for the
129 	 * abstract-socket indicator byte, and 4 bytes for the name "test").
130 	 *
131 	 * If @path_type is %G_UNIX_SOCKET_ADDRESS_ABSTRACT_PADDED, then
132 	 * @path_len bytes of @path will be copied to the socket's path, the
133 	 * rest of the path will be padded with 0 bytes, and the entire
134 	 * zero-padded buffer will be considered the name. (As above, if
135 	 * @path_len is -1, then @path is assumed to be NUL-terminated.) In
136 	 * this case, g_socket_address_get_native_size() will always return
137 	 * the full size of a `struct sockaddr_un`, although
138 	 * g_unix_socket_address_get_path_len() will still return just the
139 	 * length of @path.
140 	 *
141 	 * %G_UNIX_SOCKET_ADDRESS_ABSTRACT is preferred over
142 	 * %G_UNIX_SOCKET_ADDRESS_ABSTRACT_PADDED for new programs. Of course,
143 	 * when connecting to a server created by another process, you must
144 	 * use the appropriate type corresponding to how that process created
145 	 * its listening socket.
146 	 *
147 	 * Params:
148 	 *     path = the name
149 	 *     pathLen = the length of @path, or -1
150 	 *     type = a #GUnixSocketAddressType
151 	 *
152 	 * Return: a new #GUnixSocketAddress
153 	 *
154 	 * Since: 2.26
155 	 *
156 	 * Throws: ConstructionException GTK+ fails to create the object.
157 	 */
158 	public this(string path, GUnixSocketAddressType type)
159 	{
160 		auto p = g_unix_socket_address_new_with_type(Str.toStringz(path), cast(int)path.length, type);
161 		
162 		if(p is null)
163 		{
164 			throw new ConstructionException("null returned by new_with_type");
165 		}
166 		
167 		this(cast(GUnixSocketAddress*) p, true);
168 	}
169 
170 	/**
171 	 * Checks if abstract UNIX domain socket names are supported.
172 	 *
173 	 * Return: %TRUE if supported, %FALSE otherwise
174 	 *
175 	 * Since: 2.22
176 	 */
177 	public static bool abstractNamesSupported()
178 	{
179 		return g_unix_socket_address_abstract_names_supported() != 0;
180 	}
181 
182 	/**
183 	 * Gets @address's type.
184 	 *
185 	 * Return: a #GUnixSocketAddressType
186 	 *
187 	 * Since: 2.26
188 	 */
189 	public GUnixSocketAddressType getAddressType()
190 	{
191 		return g_unix_socket_address_get_address_type(gUnixSocketAddress);
192 	}
193 
194 	/**
195 	 * Tests if @address is abstract.
196 	 *
197 	 * Deprecated: Use g_unix_socket_address_get_address_type()
198 	 *
199 	 * Return: %TRUE if the address is abstract, %FALSE otherwise
200 	 *
201 	 * Since: 2.22
202 	 */
203 	public bool getIsAbstract()
204 	{
205 		return g_unix_socket_address_get_is_abstract(gUnixSocketAddress) != 0;
206 	}
207 
208 	/**
209 	 * Gets @address's path, or for abstract sockets the "name".
210 	 *
211 	 * Guaranteed to be zero-terminated, but an abstract socket
212 	 * may contain embedded zeros, and thus you should use
213 	 * g_unix_socket_address_get_path_len() to get the true length
214 	 * of this string.
215 	 *
216 	 * Return: the path for @address
217 	 *
218 	 * Since: 2.22
219 	 */
220 	public string getPath()
221 	{
222 		return Str.toString(g_unix_socket_address_get_path(gUnixSocketAddress));
223 	}
224 
225 	/**
226 	 * Gets the length of @address's path.
227 	 *
228 	 * For details, see g_unix_socket_address_get_path().
229 	 *
230 	 * Return: the length of the path
231 	 *
232 	 * Since: 2.22
233 	 */
234 	public size_t getPathLen()
235 	{
236 		return g_unix_socket_address_get_path_len(gUnixSocketAddress);
237 	}
238 }