1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2008 Christian Kellner, Samuel Cormier-Iijima
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Authors: Christian Kellner <gicmo@gnome.org>
21 * Samuel Cormier-Iijima <sciyoshi@gmail.com>
28 #include "gunixsocketaddress.h"
30 #include "gnetworkingprivate.h"
35 * SECTION:gunixsocketaddress
36 * @short_description: Unix socket addresses
38 * Support for UNIX-domain (aka local) sockets.
44 * A UNIX-domain (local) socket address, corresponding to a
45 * <type>struct sockaddr_un</type>.
47 G_DEFINE_TYPE (GUnixSocketAddress, g_unix_socket_address, G_TYPE_SOCKET_ADDRESS);
55 struct _GUnixSocketAddressPrivate
61 g_unix_socket_address_finalize (GObject *object)
63 GUnixSocketAddress *address G_GNUC_UNUSED = G_UNIX_SOCKET_ADDRESS (object);
65 g_free (address->priv->path);
67 if (G_OBJECT_CLASS (g_unix_socket_address_parent_class)->finalize)
68 (G_OBJECT_CLASS (g_unix_socket_address_parent_class)->finalize) (object);
72 g_unix_socket_address_dispose (GObject *object)
74 GUnixSocketAddress *address G_GNUC_UNUSED = G_UNIX_SOCKET_ADDRESS (object);
76 if (G_OBJECT_CLASS (g_unix_socket_address_parent_class)->dispose)
77 (*G_OBJECT_CLASS (g_unix_socket_address_parent_class)->dispose) (object);
81 g_unix_socket_address_get_property (GObject *object,
86 GUnixSocketAddress *address = G_UNIX_SOCKET_ADDRESS (object);
91 g_value_set_string (value, address->priv->path);
95 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
100 g_unix_socket_address_get_family (GSocketAddress *address)
102 g_assert (PF_UNIX == G_SOCKET_FAMILY_UNIX);
104 return G_SOCKET_FAMILY_UNIX;
108 g_unix_socket_address_set_property (GObject *object,
113 GUnixSocketAddress *address = G_UNIX_SOCKET_ADDRESS (object);
118 g_free (address->priv->path);
119 address->priv->path = g_value_dup_string (value);
123 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
128 g_unix_socket_address_get_native_size (GSocketAddress *address)
130 return sizeof (struct sockaddr_un);
134 g_unix_socket_address_to_native (GSocketAddress *address,
138 GUnixSocketAddress *addr = G_UNIX_SOCKET_ADDRESS (address);
139 struct sockaddr_un *sock;
141 if (destlen < sizeof (*sock))
144 sock = (struct sockaddr_un *) dest;
145 sock->sun_family = AF_UNIX;
146 g_strlcpy (sock->sun_path, addr->priv->path, sizeof (sock->sun_path));
152 g_unix_socket_address_class_init (GUnixSocketAddressClass *klass)
154 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
155 GSocketAddressClass *gsocketaddress_class = G_SOCKET_ADDRESS_CLASS (klass);
157 g_type_class_add_private (klass, sizeof (GUnixSocketAddressPrivate));
159 gobject_class->finalize = g_unix_socket_address_finalize;
160 gobject_class->dispose = g_unix_socket_address_dispose;
161 gobject_class->set_property = g_unix_socket_address_set_property;
162 gobject_class->get_property = g_unix_socket_address_get_property;
164 gsocketaddress_class->get_family = g_unix_socket_address_get_family;
165 gsocketaddress_class->to_native = g_unix_socket_address_to_native;
166 gsocketaddress_class->get_native_size = g_unix_socket_address_get_native_size;
168 g_object_class_install_property (gobject_class,
170 g_param_spec_string ("path",
172 P_("UNIX socket path"),
174 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
178 g_unix_socket_address_init (GUnixSocketAddress *address)
180 address->priv = G_TYPE_INSTANCE_GET_PRIVATE (address,
181 G_TYPE_UNIX_SOCKET_ADDRESS,
182 GUnixSocketAddressPrivate);
184 address->priv->path = NULL;
188 * g_unix_socket_address_new:
189 * @path: the socket path
191 * Creates a new #GUnixSocketAddress for @path.
193 * Returns: a new #GUnixSocketAddress
198 g_unix_socket_address_new (const gchar *path)
200 return g_object_new (G_TYPE_UNIX_SOCKET_ADDRESS,
205 #define __G_UNIX_SOCKET_ADDRESS_C__
206 #include "gioaliasdef.c"