* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
*
* Author: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
*/
#include "gsocketaddressenumerator.h"
#include "gsocketconnectable.h"
-G_DEFINE_TYPE (GProxyAddressEnumerator, g_proxy_address_enumerator, G_TYPE_SOCKET_ADDRESS_ENUMERATOR);
-
#define GET_PRIVATE(o) (G_PROXY_ADDRESS_ENUMERATOR (o)->priv)
enum
{
PROP_0,
PROP_URI,
- PROP_CONNECTABLE
+ PROP_DEFAULT_PORT,
+ PROP_CONNECTABLE,
+ PROP_PROXY_RESOLVER
};
struct _GProxyAddressEnumeratorPrivate
{
/* Destination address */
GSocketConnectable *connectable;
- gchar *dest_uri;
- gchar *dest_hostname;
- guint16 dest_port;
+ gchar *dest_uri;
+ guint16 default_port;
+ gchar *dest_hostname;
+ guint16 dest_port;
GList *dest_ips;
/* Proxy enumeration */
- gchar **proxies;
- gchar **next_proxy;
+ GProxyResolver *proxy_resolver;
+ gchar **proxies;
+ gchar **next_proxy;
GSocketAddressEnumerator *addr_enum;
GSocketAddress *proxy_address;
const gchar *proxy_uri;
- gchar *proxy_type;
- gchar *proxy_username;
- gchar *proxy_password;
+ gchar *proxy_type;
+ gchar *proxy_username;
+ gchar *proxy_password;
gboolean supports_hostname;
- GList *next_dest_ip;
+ GList *next_dest_ip;
GError *last_error;
};
+G_DEFINE_TYPE_WITH_PRIVATE (GProxyAddressEnumerator, g_proxy_address_enumerator, G_TYPE_SOCKET_ADDRESS_ENUMERATOR)
+
static void
save_userinfo (GProxyAddressEnumeratorPrivate *priv,
const gchar *proxy)
if (priv->proxies == NULL)
{
- GProxyResolver *resolver = g_proxy_resolver_get_default ();
- priv->proxies = g_proxy_resolver_lookup (resolver,
+ priv->proxies = g_proxy_resolver_lookup (priv->proxy_resolver,
priv->dest_uri,
cancellable,
error);
if (priv->proxies == NULL)
{
- GProxyResolver *resolver = g_proxy_resolver_get_default ();
- g_proxy_resolver_lookup_async (resolver,
+ g_proxy_resolver_lookup_async (priv->proxy_resolver,
priv->dest_uri,
cancellable,
proxy_lookup_cb,
}
static void
+g_proxy_address_enumerator_constructed (GObject *object)
+{
+ GProxyAddressEnumeratorPrivate *priv = GET_PRIVATE (object);
+ GSocketConnectable *conn;
+ guint port;
+
+ if (priv->dest_uri)
+ {
+ conn = g_network_address_parse_uri (priv->dest_uri, priv->default_port, NULL);
+ if (conn)
+ {
+ g_object_get (conn,
+ "hostname", &priv->dest_hostname,
+ "port", &port,
+ NULL);
+ priv->dest_port = port;
+
+ g_object_unref (conn);
+ }
+ else
+ g_warning ("Invalid URI '%s'", priv->dest_uri);
+ }
+
+ G_OBJECT_CLASS (g_proxy_address_enumerator_parent_class)->constructed (object);
+}
+
+static void
g_proxy_address_enumerator_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GProxyAddressEnumeratorPrivate *priv = GET_PRIVATE (object);
switch (property_id)
{
- case PROP_URI:
- g_value_set_string (value, priv->dest_uri);
- break;
+ case PROP_URI:
+ g_value_set_string (value, priv->dest_uri);
+ break;
- case PROP_CONNECTABLE:
- g_value_set_object (value, priv->connectable);
- break;
+ case PROP_DEFAULT_PORT:
+ g_value_set_uint (value, priv->default_port);
+ break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ case PROP_CONNECTABLE:
+ g_value_set_object (value, priv->connectable);
+ break;
+
+ case PROP_PROXY_RESOLVER:
+ g_value_set_object (value, priv->proxy_resolver);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
g_proxy_address_enumerator_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
GProxyAddressEnumeratorPrivate *priv = GET_PRIVATE (object);
switch (property_id)
{
- case PROP_URI:
- {
- const gchar *uri;
-
- g_free (priv->dest_hostname);
- priv->dest_hostname = NULL;
- priv->dest_port = 0;
-
- g_free (priv->dest_uri);
- priv->dest_uri = NULL;
-
- uri = g_value_get_string (value);
-
- if (uri)
- {
- GSocketConnectable *conn;
-
- conn = g_network_address_parse_uri (uri, 0, NULL);
- if (conn)
- {
- guint port;
-
- priv->dest_uri = g_strdup (uri);
-
- g_object_get (conn,
- "hostname", &priv->dest_hostname,
- "port", &port,
- NULL);
-
- priv->dest_port = port;
- g_object_unref (conn);
- }
- else
- g_warning ("Invalid URI '%s'", uri);
- }
-
- break;
- }
-
- case PROP_CONNECTABLE:
- priv->connectable = g_value_dup_object (value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ case PROP_URI:
+ priv->dest_uri = g_value_dup_string (value);
+ break;
+
+ case PROP_DEFAULT_PORT:
+ priv->default_port = g_value_get_uint (value);
+ break;
+
+ case PROP_CONNECTABLE:
+ priv->connectable = g_value_dup_object (value);
+ break;
+
+ case PROP_PROXY_RESOLVER:
+ if (priv->proxy_resolver)
+ g_object_unref (priv->proxy_resolver);
+ priv->proxy_resolver = g_value_get_object (value);
+ if (!priv->proxy_resolver)
+ priv->proxy_resolver = g_proxy_resolver_get_default ();
+ g_object_ref (priv->proxy_resolver);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
if (priv->connectable)
g_object_unref (priv->connectable);
+ if (priv->proxy_resolver)
+ g_object_unref (priv->proxy_resolver);
+
g_free (priv->dest_uri);
g_free (priv->dest_hostname);
static void
g_proxy_address_enumerator_init (GProxyAddressEnumerator *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
- G_TYPE_PROXY_ADDRESS_ENUMERATOR,
- GProxyAddressEnumeratorPrivate);
+ self->priv = g_proxy_address_enumerator_get_instance_private (self);
}
static void
GObjectClass *object_class = G_OBJECT_CLASS (proxy_enumerator_class);
GSocketAddressEnumeratorClass *enumerator_class = G_SOCKET_ADDRESS_ENUMERATOR_CLASS (proxy_enumerator_class);
- g_type_class_add_private (enumerator_class,
- sizeof (GProxyAddressEnumeratorPrivate));
-
+ object_class->constructed = g_proxy_address_enumerator_constructed;
object_class->set_property = g_proxy_address_enumerator_set_property;
object_class->get_property = g_proxy_address_enumerator_get_property;
object_class->finalize = g_proxy_address_enumerator_finalize;
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
+ /**
+ * GProxyAddressEnumerator:default-port:
+ *
+ * The default port to use if #GProxyAddressEnumerator:uri does not
+ * specify one.
+ *
+ * Since: 2.38
+ */
+ g_object_class_install_property (object_class,
+ PROP_DEFAULT_PORT,
+ g_param_spec_uint ("default-port",
+ P_("Default port"),
+ P_("The default port to use if uri does not specify one"),
+ 0, 65535, 0,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
g_object_class_install_property (object_class,
PROP_CONNECTABLE,
g_param_spec_object ("connectable",
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GProxyAddressEnumerator:proxy-resolver:
+ *
+ * The proxy resolver to use.
+ *
+ * Since: 2.36
+ */
+ g_object_class_install_property (object_class,
+ PROP_PROXY_RESOLVER,
+ g_param_spec_object ("proxy-resolver",
+ P_("Proxy resolver"),
+ P_("The proxy resolver to use."),
+ G_TYPE_PROXY_RESOLVER,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS));
}