mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-24 14:36:13 +01:00
gio: Add more information to GProxyAddress
Add two new methods to GProxyAddress for recovering information about the destination URI that the proxy was created for (and modify GProxyAddressEnumerator to set that information when creating the GProxyAddress).
This commit is contained in:
parent
8c7025e723
commit
bcaa0a3820
@ -3154,11 +3154,13 @@ g_proxy_resolver_get_type
|
||||
<TITLE>GProxyAddress</TITLE>
|
||||
GProxyAddress
|
||||
GProxyAddressClass
|
||||
g_proxy_address_get_destination_protocol
|
||||
g_proxy_address_get_destination_hostname
|
||||
g_proxy_address_get_destination_port
|
||||
g_proxy_address_get_password
|
||||
g_proxy_address_get_protocol
|
||||
g_proxy_address_get_username
|
||||
g_proxy_address_get_uri
|
||||
g_proxy_address_new
|
||||
<SUBSECTION Standard>
|
||||
G_PROXY_ADDRESS
|
||||
|
@ -881,10 +881,12 @@ g_proxy_resolver_lookup_finish
|
||||
g_proxy_address_get_type
|
||||
g_proxy_address_new
|
||||
g_proxy_address_get_protocol
|
||||
g_proxy_address_get_destination_protocol
|
||||
g_proxy_address_get_destination_hostname
|
||||
g_proxy_address_get_destination_port
|
||||
g_proxy_address_get_username
|
||||
g_proxy_address_get_password
|
||||
g_proxy_address_get_uri
|
||||
g_proxy_address_enumerator_get_type
|
||||
g_resolver_error_quark
|
||||
g_resolver_free_addresses
|
||||
|
@ -49,17 +49,21 @@ enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_PROTOCOL,
|
||||
PROP_DESTINATION_PROTOCOL,
|
||||
PROP_DESTINATION_HOSTNAME,
|
||||
PROP_DESTINATION_PORT,
|
||||
PROP_USERNAME,
|
||||
PROP_PASSWORD
|
||||
PROP_PASSWORD,
|
||||
PROP_URI
|
||||
};
|
||||
|
||||
struct _GProxyAddressPrivate
|
||||
{
|
||||
gchar *uri;
|
||||
gchar *protocol;
|
||||
gchar *username;
|
||||
gchar *password;
|
||||
gchar *dest_protocol;
|
||||
gchar *dest_hostname;
|
||||
guint16 dest_port;
|
||||
};
|
||||
@ -69,19 +73,21 @@ g_proxy_address_finalize (GObject *object)
|
||||
{
|
||||
GProxyAddress *proxy = G_PROXY_ADDRESS (object);
|
||||
|
||||
g_free (proxy->priv->uri);
|
||||
g_free (proxy->priv->protocol);
|
||||
g_free (proxy->priv->username);
|
||||
g_free (proxy->priv->password);
|
||||
g_free (proxy->priv->dest_hostname);
|
||||
g_free (proxy->priv->dest_protocol);
|
||||
|
||||
G_OBJECT_CLASS (g_proxy_address_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
g_proxy_address_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GProxyAddress *proxy = G_PROXY_ADDRESS (object);
|
||||
|
||||
@ -92,6 +98,11 @@ g_proxy_address_set_property (GObject *object,
|
||||
proxy->priv->protocol = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
case PROP_DESTINATION_PROTOCOL:
|
||||
g_free (proxy->priv->dest_protocol);
|
||||
proxy->priv->dest_protocol = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
case PROP_DESTINATION_HOSTNAME:
|
||||
g_free (proxy->priv->dest_hostname);
|
||||
proxy->priv->dest_hostname = g_value_dup_string (value);
|
||||
@ -111,6 +122,11 @@ g_proxy_address_set_property (GObject *object,
|
||||
proxy->priv->password = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
case PROP_URI:
|
||||
g_free (proxy->priv->uri);
|
||||
proxy->priv->uri = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
@ -130,6 +146,10 @@ g_proxy_address_get_property (GObject *object,
|
||||
g_value_set_string (value, proxy->priv->protocol);
|
||||
break;
|
||||
|
||||
case PROP_DESTINATION_PROTOCOL:
|
||||
g_value_set_string (value, proxy->priv->dest_protocol);
|
||||
break;
|
||||
|
||||
case PROP_DESTINATION_HOSTNAME:
|
||||
g_value_set_string (value, proxy->priv->dest_hostname);
|
||||
break;
|
||||
@ -146,6 +166,10 @@ g_proxy_address_get_property (GObject *object,
|
||||
g_value_set_string (value, proxy->priv->password);
|
||||
break;
|
||||
|
||||
case PROP_URI:
|
||||
g_value_set_string (value, proxy->priv->uri);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
@ -192,6 +216,24 @@ g_proxy_address_class_init (GProxyAddressClass *klass)
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/**
|
||||
* GProxyAddress:destination-protocol:
|
||||
*
|
||||
* The protocol being spoke to the destination host, or %NULL if
|
||||
* the #GProxyAddress doesn't know.
|
||||
*
|
||||
* Since: 2.34
|
||||
*/
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_DESTINATION_PROTOCOL,
|
||||
g_param_spec_string ("destination-protocol",
|
||||
P_("Destionation Protocol"),
|
||||
P_("The proxy destination protocol"),
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_DESTINATION_HOSTNAME,
|
||||
g_param_spec_string ("destination-hostname",
|
||||
@ -211,6 +253,24 @@ g_proxy_address_class_init (GProxyAddressClass *klass)
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/**
|
||||
* GProxyAddress:uri:
|
||||
*
|
||||
* The URI string that the proxy was constructed from (or %NULL
|
||||
* if the creator didn't specify this).
|
||||
*
|
||||
* Since: 2.34
|
||||
*/
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_URI,
|
||||
g_param_spec_string ("uri",
|
||||
P_("URI"),
|
||||
P_("The proxy's URI"),
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -241,6 +301,10 @@ g_proxy_address_init (GProxyAddress *proxy)
|
||||
* Creates a new #GProxyAddress for @inetaddr with @protocol that should
|
||||
* tunnel through @dest_hostname and @dest_port.
|
||||
*
|
||||
* (Note that this method doesn't set the #GProxyAddress:uri or
|
||||
* #GProxyAddress:destination-protocol fields; use g_object_new()
|
||||
* directly if you want to set those.)
|
||||
*
|
||||
* Returns: a new #GProxyAddress
|
||||
*
|
||||
* Since: 2.26
|
||||
@ -270,7 +334,7 @@ g_proxy_address_new (GInetAddress *inetaddr,
|
||||
* g_proxy_address_get_protocol:
|
||||
* @proxy: a #GProxyAddress
|
||||
*
|
||||
* Gets @proxy's protocol.
|
||||
* Gets @proxy's protocol. eg, "socks" or "http"
|
||||
*
|
||||
* Returns: the @proxy's protocol
|
||||
*
|
||||
@ -282,11 +346,30 @@ g_proxy_address_get_protocol (GProxyAddress *proxy)
|
||||
return proxy->priv->protocol;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_proxy_address_get_destination_protocol:
|
||||
* @proxy: a #GProxyAddress
|
||||
*
|
||||
* Gets the protocol that is being spoken to the destination
|
||||
* server; eg, "http" or "ftp".
|
||||
*
|
||||
* Returns: the @proxy's destination protocol
|
||||
*
|
||||
* Since: 2.34
|
||||
*/
|
||||
const gchar *
|
||||
g_proxy_address_get_destination_protocol (GProxyAddress *proxy)
|
||||
{
|
||||
return proxy->priv->dest_protocol;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_proxy_address_get_destination_hostname:
|
||||
* @proxy: a #GProxyAddress
|
||||
*
|
||||
* Gets @proxy's destination hostname.
|
||||
* Gets @proxy's destination hostname; that is, the name of the host
|
||||
* that will be connected to via the proxy, not the name of the proxy
|
||||
* itself.
|
||||
*
|
||||
* Returns: the @proxy's destination hostname
|
||||
*
|
||||
@ -302,7 +385,9 @@ g_proxy_address_get_destination_hostname (GProxyAddress *proxy)
|
||||
* g_proxy_address_get_destination_port:
|
||||
* @proxy: a #GProxyAddress
|
||||
*
|
||||
* Gets @proxy's destination port.
|
||||
* Gets @proxy's destination port; that is, the port on the
|
||||
* destination host that will be connected to via the proxy, not the
|
||||
* port number of the proxy itself.
|
||||
*
|
||||
* Returns: the @proxy's destination port
|
||||
*
|
||||
@ -345,3 +430,20 @@ g_proxy_address_get_password (GProxyAddress *proxy)
|
||||
{
|
||||
return proxy->priv->password;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* g_proxy_address_get_uri:
|
||||
* @proxy: a #GProxyAddress
|
||||
*
|
||||
* Gets the proxy URI that @proxy was constructed from.
|
||||
*
|
||||
* Returns: the @proxy's URI, or %NULL if unknown
|
||||
*
|
||||
* Since: 2.34
|
||||
*/
|
||||
const gchar *
|
||||
g_proxy_address_get_uri (GProxyAddress *proxy)
|
||||
{
|
||||
return proxy->priv->uri;
|
||||
}
|
||||
|
@ -66,11 +66,16 @@ GSocketAddress *g_proxy_address_new (GInetAddress *inetaddr,
|
||||
const gchar *password);
|
||||
|
||||
const gchar *g_proxy_address_get_protocol (GProxyAddress *proxy);
|
||||
GLIB_AVAILABLE_IN_2_34
|
||||
const gchar *g_proxy_address_get_destination_protocol (GProxyAddress *proxy);
|
||||
const gchar *g_proxy_address_get_destination_hostname (GProxyAddress *proxy);
|
||||
guint16 g_proxy_address_get_destination_port (GProxyAddress *proxy);
|
||||
const gchar *g_proxy_address_get_username (GProxyAddress *proxy);
|
||||
const gchar *g_proxy_address_get_password (GProxyAddress *proxy);
|
||||
|
||||
GLIB_AVAILABLE_IN_2_34
|
||||
const gchar *g_proxy_address_get_uri (GProxyAddress *proxy);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_PROXY_ADDRESS_H__ */
|
||||
|
@ -64,6 +64,7 @@ struct _GProxyAddressEnumeratorPrivate
|
||||
gchar **next_proxy;
|
||||
GSocketAddressEnumerator *addr_enum;
|
||||
GSocketAddress *proxy_address;
|
||||
const gchar *proxy_uri;
|
||||
gchar *proxy_type;
|
||||
gchar *proxy_username;
|
||||
gchar *proxy_password;
|
||||
@ -122,12 +123,11 @@ next_enumerator (GProxyAddressEnumeratorPrivate *priv)
|
||||
while (priv->addr_enum == NULL && *priv->next_proxy)
|
||||
{
|
||||
GSocketConnectable *connectable = NULL;
|
||||
const gchar *proxy_uri;
|
||||
GProxy *proxy;
|
||||
|
||||
proxy_uri = *priv->next_proxy++;
|
||||
priv->proxy_uri = *priv->next_proxy++;
|
||||
g_free (priv->proxy_type);
|
||||
priv->proxy_type = g_uri_parse_scheme (proxy_uri);
|
||||
priv->proxy_type = g_uri_parse_scheme (priv->proxy_uri);
|
||||
|
||||
if (priv->proxy_type == NULL)
|
||||
continue;
|
||||
@ -153,16 +153,16 @@ next_enumerator (GProxyAddressEnumeratorPrivate *priv)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
connectable = g_network_address_parse_uri (proxy_uri, 0, &error);
|
||||
connectable = g_network_address_parse_uri (priv->proxy_uri, 0, &error);
|
||||
|
||||
if (error)
|
||||
{
|
||||
g_warning ("Invalid proxy URI '%s': %s",
|
||||
proxy_uri, error->message);
|
||||
priv->proxy_uri, error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
save_userinfo (priv, proxy_uri);
|
||||
save_userinfo (priv, priv->proxy_uri);
|
||||
}
|
||||
|
||||
if (connectable)
|
||||
@ -198,6 +198,7 @@ g_proxy_address_enumerator_next (GSocketAddressEnumerator *enumerator,
|
||||
while (result == NULL && (*priv->next_proxy || priv->addr_enum))
|
||||
{
|
||||
gchar *dest_hostname;
|
||||
gchar *dest_protocol;
|
||||
GInetSocketAddress *inetsaddr;
|
||||
GInetAddress *inetaddr;
|
||||
guint16 port;
|
||||
@ -271,7 +272,7 @@ g_proxy_address_enumerator_next (GSocketAddressEnumerator *enumerator,
|
||||
{
|
||||
dest_hostname = g_strdup (priv->dest_hostname);
|
||||
}
|
||||
|
||||
dest_protocol = g_uri_parse_scheme (priv->dest_uri);
|
||||
|
||||
g_return_val_if_fail (G_IS_INET_SOCKET_ADDRESS (priv->proxy_address),
|
||||
NULL);
|
||||
@ -280,13 +281,19 @@ g_proxy_address_enumerator_next (GSocketAddressEnumerator *enumerator,
|
||||
inetaddr = g_inet_socket_address_get_address (inetsaddr);
|
||||
port = g_inet_socket_address_get_port (inetsaddr);
|
||||
|
||||
result = g_proxy_address_new (inetaddr, port,
|
||||
priv->proxy_type,
|
||||
dest_hostname, priv->dest_port,
|
||||
priv->proxy_username,
|
||||
priv->proxy_password);
|
||||
|
||||
result = g_object_new (G_TYPE_PROXY_ADDRESS,
|
||||
"address", inetaddr,
|
||||
"port", port,
|
||||
"protocol", priv->proxy_type,
|
||||
"destination-protocol", dest_protocol,
|
||||
"destination-hostname", dest_hostname,
|
||||
"destination-port", priv->dest_port,
|
||||
"username", priv->proxy_username,
|
||||
"password", priv->proxy_password,
|
||||
"uri", priv->proxy_uri,
|
||||
NULL);
|
||||
g_free (dest_hostname);
|
||||
g_free (dest_protocol);
|
||||
|
||||
if (priv->supports_hostname || priv->next_dest_ip == NULL)
|
||||
{
|
||||
@ -340,7 +347,7 @@ save_result (GProxyAddressEnumeratorPrivate *priv)
|
||||
}
|
||||
else
|
||||
{
|
||||
gchar *dest_hostname;
|
||||
gchar *dest_hostname, *dest_protocol;
|
||||
GInetSocketAddress *inetsaddr;
|
||||
GInetAddress *inetaddr;
|
||||
guint16 port;
|
||||
@ -361,6 +368,7 @@ save_result (GProxyAddressEnumeratorPrivate *priv)
|
||||
{
|
||||
dest_hostname = g_strdup (priv->dest_hostname);
|
||||
}
|
||||
dest_protocol = g_uri_parse_scheme (priv->dest_uri);
|
||||
|
||||
g_return_if_fail (G_IS_INET_SOCKET_ADDRESS (priv->proxy_address));
|
||||
|
||||
@ -368,13 +376,19 @@ save_result (GProxyAddressEnumeratorPrivate *priv)
|
||||
inetaddr = g_inet_socket_address_get_address (inetsaddr);
|
||||
port = g_inet_socket_address_get_port (inetsaddr);
|
||||
|
||||
result = g_proxy_address_new (inetaddr, port,
|
||||
priv->proxy_type,
|
||||
dest_hostname, priv->dest_port,
|
||||
priv->proxy_username,
|
||||
priv->proxy_password);
|
||||
|
||||
result = g_object_new (G_TYPE_PROXY_ADDRESS,
|
||||
"address", inetaddr,
|
||||
"port", port,
|
||||
"protocol", priv->proxy_type,
|
||||
"destination-protocol", dest_protocol,
|
||||
"destination-hostname", dest_hostname,
|
||||
"destination-port", priv->dest_port,
|
||||
"username", priv->proxy_username,
|
||||
"password", priv->proxy_password,
|
||||
"uri", priv->proxy_uri,
|
||||
NULL);
|
||||
g_free (dest_hostname);
|
||||
g_free (dest_protocol);
|
||||
|
||||
if (priv->supports_hostname || priv->next_dest_ip == NULL)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user