Commit fc03ecce authored by Nicolas Dufresne's avatar Nicolas Dufresne

Implemented proxy_enumerate() for all Connectables

This patch implements method proxy_enumerate from GSocketConnectable for
all connectables (GNetworkAddress, GNetworkService, GInetSocketAddress
and GUnixSocketAddress).
Reviewed-by: Dan Winship's avatarDan Winship <danw@gnome.org>
parent f82f484b
......@@ -1698,6 +1698,8 @@ g_network_service_new
g_network_service_get_service
g_network_service_get_protocol
g_network_service_get_domain
g_network_service_get_scheme
g_network_service_set_scheme
<SUBSECTION Standard>
GNetworkServiceClass
GNetworkServicePrivate
......
......@@ -1242,6 +1242,8 @@ g_network_service_get_type G_GNUC_CONST
g_network_service_get_service
g_network_service_get_protocol
g_network_service_get_domain
g_network_service_get_scheme
g_network_service_set_scheme
g_network_service_new
#endif
#endif
......
......@@ -30,6 +30,7 @@
#include "ginetaddress.h"
#include "ginetsocketaddress.h"
#include "gnetworkingprivate.h"
#include "gproxyaddressenumerator.h"
#include "gresolver.h"
#include "gsimpleasyncresult.h"
#include "gsocketaddressenumerator.h"
......@@ -82,8 +83,9 @@ static void g_network_address_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
static void g_network_address_connectable_iface_init (GSocketConnectableIface *iface);
static GSocketAddressEnumerator *g_network_address_connectable_enumerate (GSocketConnectable *connectable);
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);
G_DEFINE_TYPE_WITH_CODE (GNetworkAddress, g_network_address, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_TYPE_SOCKET_CONNECTABLE,
......@@ -151,6 +153,7 @@ static void
g_network_address_connectable_iface_init (GSocketConnectableIface *connectable_iface)
{
connectable_iface->enumerate = g_network_address_connectable_enumerate;
connectable_iface->proxy_enumerate = g_network_address_connectable_proxy_enumerate;
}
static void
......@@ -909,3 +912,24 @@ g_network_address_connectable_enumerate (GSocketConnectable *connectable)
return (GSocketAddressEnumerator *)addr_enum;
}
static GSocketAddressEnumerator *
g_network_address_connectable_proxy_enumerate (GSocketConnectable *connectable)
{
GNetworkAddress *self = G_NETWORK_ADDRESS (connectable);
GSocketAddressEnumerator *proxy_enum;
gchar *uri;
uri = g_strdup_printf ("%s://%s:%u",
self->priv->scheme ? self->priv->scheme : "none",
self->priv->hostname, self->priv->port);
proxy_enum = g_object_new (G_TYPE_PROXY_ADDRESS_ENUMERATOR,
"connectable", connectable,
"uri", uri,
NULL);
g_free (uri);
return proxy_enum;
}
This diff is collapsed.
......@@ -62,6 +62,8 @@ GSocketConnectable *g_network_service_new (const gchar *service,
const gchar *g_network_service_get_service (GNetworkService *srv);
const gchar *g_network_service_get_protocol (GNetworkService *srv);
const gchar *g_network_service_get_domain (GNetworkService *srv);
const gchar *g_network_service_get_scheme (GNetworkService *srv);
void g_network_service_set_scheme (GNetworkService *srv, const gchar *scheme);
G_END_DECLS
......
......@@ -28,6 +28,7 @@
#include "ginetaddress.h"
#include "ginetsocketaddress.h"
#include "gnetworkingprivate.h"
#include "gproxyaddressenumerator.h"
#include "gsocketaddressenumerator.h"
#include "gsocketconnectable.h"
#include "glibintl.h"
......@@ -62,8 +63,9 @@ enum
PROP_FAMILY
};
static void g_socket_address_connectable_iface_init (GSocketConnectableIface *iface);
static GSocketAddressEnumerator *g_socket_address_connectable_enumerate (GSocketConnectable *connectable);
static void g_socket_address_connectable_iface_init (GSocketConnectableIface *iface);
static GSocketAddressEnumerator *g_socket_address_connectable_enumerate (GSocketConnectable *connectable);
static GSocketAddressEnumerator *g_socket_address_connectable_proxy_enumerate (GSocketConnectable *connectable);
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GSocketAddress, g_socket_address, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_TYPE_SOCKET_CONNECTABLE,
......@@ -125,6 +127,7 @@ static void
g_socket_address_connectable_iface_init (GSocketConnectableIface *connectable_iface)
{
connectable_iface->enumerate = g_socket_address_connectable_enumerate;
connectable_iface->proxy_enumerate = g_socket_address_connectable_proxy_enumerate;
}
static void
......@@ -351,3 +354,38 @@ g_socket_address_connectable_enumerate (GSocketConnectable *connectable)
return (GSocketAddressEnumerator *)sockaddr_enum;
}
static GSocketAddressEnumerator *
g_socket_address_connectable_proxy_enumerate (GSocketConnectable *connectable)
{
GSocketAddressEnumerator *addr_enum = NULL;
if (G_IS_INET_SOCKET_ADDRESS (connectable) &&
!G_IS_PROXY_ADDRESS (connectable))
{
GInetAddress *addr;
guint port;
gchar *uri;
gchar *ip;
g_object_get (connectable, "address", &addr, "port", &port, NULL);
ip = g_inet_address_to_string (addr);
uri = g_strdup_printf ("none://%s:%u", ip, port);
addr_enum = g_object_new (G_TYPE_PROXY_ADDRESS_ENUMERATOR,
"connectable", connectable,
"uri", uri,
NULL);
g_object_unref (addr);
g_free (ip);
g_free (uri);
}
else
{
addr_enum = g_socket_address_connectable_enumerate (connectable);
}
return addr_enum;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment