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