mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-02 07:23:41 +02:00
gsocketconnectable: Add a to_string() virtual method
Add string serialisation functions for GNetworkAddress, GSocketAddress, GUnixSocketAddress, GInetSocketAddress, GNetworkService and GSocketConnectable. These are intended for use in debug output, not for serialisation in network or disc protocols. They are implemented as a new virtual method on GSocketConnectable: g_socket_connectable_to_string(). GInetSocketAddress and GUnixSocketAddress now implement GSocketConnectable directly to implement to_string(). Previously they implemented it via their abstract parent class, GSocketAddress. https://bugzilla.gnome.org/show_bug.cgi?id=737116
This commit is contained in:
@@ -86,6 +86,7 @@ static void g_network_address_get_property (GObject *object,
|
||||
static void g_network_address_connectable_iface_init (GSocketConnectableIface *iface);
|
||||
static GSocketAddressEnumerator *g_network_address_connectable_enumerate (GSocketConnectable *connectable);
|
||||
static GSocketAddressEnumerator *g_network_address_connectable_proxy_enumerate (GSocketConnectable *connectable);
|
||||
static gchar *g_network_address_connectable_to_string (GSocketConnectable *connectable);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GNetworkAddress, g_network_address, G_TYPE_OBJECT,
|
||||
G_ADD_PRIVATE (GNetworkAddress)
|
||||
@@ -145,6 +146,7 @@ g_network_address_connectable_iface_init (GSocketConnectableIface *connectable_i
|
||||
{
|
||||
connectable_iface->enumerate = g_network_address_connectable_enumerate;
|
||||
connectable_iface->proxy_enumerate = g_network_address_connectable_proxy_enumerate;
|
||||
connectable_iface->to_string = g_network_address_connectable_to_string;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1111,3 +1113,27 @@ g_network_address_connectable_proxy_enumerate (GSocketConnectable *connectable)
|
||||
|
||||
return proxy_enum;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
g_network_address_connectable_to_string (GSocketConnectable *connectable)
|
||||
{
|
||||
GNetworkAddress *addr;
|
||||
const gchar *scheme;
|
||||
guint16 port;
|
||||
GString *out; /* owned */
|
||||
|
||||
addr = G_NETWORK_ADDRESS (connectable);
|
||||
out = g_string_new ("");
|
||||
|
||||
scheme = g_network_address_get_scheme (addr);
|
||||
if (scheme != NULL)
|
||||
g_string_append_printf (out, "%s:", scheme);
|
||||
|
||||
g_string_append (out, g_network_address_get_hostname (addr));
|
||||
|
||||
port = g_network_address_get_port (addr);
|
||||
if (port != 0)
|
||||
g_string_append_printf (out, ":%u", port);
|
||||
|
||||
return g_string_free (out, FALSE);
|
||||
}
|
||||
|
Reference in New Issue
Block a user