1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2010 Collabora, Ltd.
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.1 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, see <http://www.gnu.org/licenses/>.
18 * Authors: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
25 #include <gio/gsocketaddress.h>
27 #include "gproxyaddress.h"
31 * SECTION:gproxyaddress
32 * @short_description: An internet address with proxy information
35 * Support for proxied #GInetSocketAddress.
41 * A #GInetSocketAddress representing a connection via a proxy server
49 * Class structure for #GProxyAddress.
58 PROP_DESTINATION_PROTOCOL,
59 PROP_DESTINATION_HOSTNAME,
60 PROP_DESTINATION_PORT,
66 struct _GProxyAddressPrivate
77 G_DEFINE_TYPE_WITH_PRIVATE (GProxyAddress, g_proxy_address, G_TYPE_INET_SOCKET_ADDRESS)
80 g_proxy_address_finalize (GObject *object)
82 GProxyAddress *proxy = G_PROXY_ADDRESS (object);
84 g_free (proxy->priv->uri);
85 g_free (proxy->priv->protocol);
86 g_free (proxy->priv->username);
87 g_free (proxy->priv->password);
88 g_free (proxy->priv->dest_hostname);
89 g_free (proxy->priv->dest_protocol);
91 G_OBJECT_CLASS (g_proxy_address_parent_class)->finalize (object);
95 g_proxy_address_set_property (GObject *object,
100 GProxyAddress *proxy = G_PROXY_ADDRESS (object);
105 g_free (proxy->priv->protocol);
106 proxy->priv->protocol = g_value_dup_string (value);
109 case PROP_DESTINATION_PROTOCOL:
110 g_free (proxy->priv->dest_protocol);
111 proxy->priv->dest_protocol = g_value_dup_string (value);
114 case PROP_DESTINATION_HOSTNAME:
115 g_free (proxy->priv->dest_hostname);
116 proxy->priv->dest_hostname = g_value_dup_string (value);
119 case PROP_DESTINATION_PORT:
120 proxy->priv->dest_port = g_value_get_uint (value);
124 g_free (proxy->priv->username);
125 proxy->priv->username = g_value_dup_string (value);
129 g_free (proxy->priv->password);
130 proxy->priv->password = g_value_dup_string (value);
134 g_free (proxy->priv->uri);
135 proxy->priv->uri = g_value_dup_string (value);
139 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
144 g_proxy_address_get_property (GObject *object,
149 GProxyAddress *proxy = G_PROXY_ADDRESS (object);
154 g_value_set_string (value, proxy->priv->protocol);
157 case PROP_DESTINATION_PROTOCOL:
158 g_value_set_string (value, proxy->priv->dest_protocol);
161 case PROP_DESTINATION_HOSTNAME:
162 g_value_set_string (value, proxy->priv->dest_hostname);
165 case PROP_DESTINATION_PORT:
166 g_value_set_uint (value, proxy->priv->dest_port);
170 g_value_set_string (value, proxy->priv->username);
174 g_value_set_string (value, proxy->priv->password);
178 g_value_set_string (value, proxy->priv->uri);
182 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
187 g_proxy_address_class_init (GProxyAddressClass *klass)
189 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
191 gobject_class->finalize = g_proxy_address_finalize;
192 gobject_class->set_property = g_proxy_address_set_property;
193 gobject_class->get_property = g_proxy_address_get_property;
195 g_object_class_install_property (gobject_class,
197 g_param_spec_string ("protocol",
199 P_("The proxy protocol"),
202 G_PARAM_CONSTRUCT_ONLY |
203 G_PARAM_STATIC_STRINGS));
205 g_object_class_install_property (gobject_class,
207 g_param_spec_string ("username",
209 P_("The proxy username"),
212 G_PARAM_CONSTRUCT_ONLY |
213 G_PARAM_STATIC_STRINGS));
215 g_object_class_install_property (gobject_class,
217 g_param_spec_string ("password",
219 P_("The proxy password"),
222 G_PARAM_CONSTRUCT_ONLY |
223 G_PARAM_STATIC_STRINGS));
226 * GProxyAddress:destination-protocol:
228 * The protocol being spoke to the destination host, or %NULL if
229 * the #GProxyAddress doesn't know.
233 g_object_class_install_property (gobject_class,
234 PROP_DESTINATION_PROTOCOL,
235 g_param_spec_string ("destination-protocol",
236 P_("Destionation Protocol"),
237 P_("The proxy destination protocol"),
240 G_PARAM_CONSTRUCT_ONLY |
241 G_PARAM_STATIC_STRINGS));
243 g_object_class_install_property (gobject_class,
244 PROP_DESTINATION_HOSTNAME,
245 g_param_spec_string ("destination-hostname",
246 P_("Destination Hostname"),
247 P_("The proxy destination hostname"),
250 G_PARAM_CONSTRUCT_ONLY |
251 G_PARAM_STATIC_STRINGS));
253 g_object_class_install_property (gobject_class,
254 PROP_DESTINATION_PORT,
255 g_param_spec_uint ("destination-port",
256 P_("Destination Port"),
257 P_("The proxy destination port"),
260 G_PARAM_CONSTRUCT_ONLY |
261 G_PARAM_STATIC_STRINGS));
266 * The URI string that the proxy was constructed from (or %NULL
267 * if the creator didn't specify this).
271 g_object_class_install_property (gobject_class,
273 g_param_spec_string ("uri",
275 P_("The proxy’s URI"),
278 G_PARAM_CONSTRUCT_ONLY |
279 G_PARAM_STATIC_STRINGS));
283 g_proxy_address_init (GProxyAddress *proxy)
285 proxy->priv = g_proxy_address_get_instance_private (proxy);
286 proxy->priv->protocol = NULL;
287 proxy->priv->username = NULL;
288 proxy->priv->password = NULL;
289 proxy->priv->dest_hostname = NULL;
290 proxy->priv->dest_port = 0;
294 * g_proxy_address_new:
295 * @inetaddr: The proxy server #GInetAddress.
296 * @port: The proxy server port.
297 * @protocol: The proxy protocol to support, in lower case (e.g. socks, http).
298 * @dest_hostname: The destination hostname the proxy should tunnel to.
299 * @dest_port: The destination port to tunnel to.
300 * @username: (nullable): The username to authenticate to the proxy server
302 * @password: (nullable): The password to authenticate to the proxy server
305 * Creates a new #GProxyAddress for @inetaddr with @protocol that should
306 * tunnel through @dest_hostname and @dest_port.
308 * (Note that this method doesn't set the #GProxyAddress:uri or
309 * #GProxyAddress:destination-protocol fields; use g_object_new()
310 * directly if you want to set those.)
312 * Returns: a new #GProxyAddress
317 g_proxy_address_new (GInetAddress *inetaddr,
319 const gchar *protocol,
320 const gchar *dest_hostname,
322 const gchar *username,
323 const gchar *password)
325 return g_object_new (G_TYPE_PROXY_ADDRESS,
328 "protocol", protocol,
329 "destination-hostname", dest_hostname,
330 "destination-port", dest_port,
331 "username", username,
332 "password", password,
338 * g_proxy_address_get_protocol:
339 * @proxy: a #GProxyAddress
341 * Gets @proxy's protocol. eg, "socks" or "http"
343 * Returns: the @proxy's protocol
348 g_proxy_address_get_protocol (GProxyAddress *proxy)
350 return proxy->priv->protocol;
354 * g_proxy_address_get_destination_protocol:
355 * @proxy: a #GProxyAddress
357 * Gets the protocol that is being spoken to the destination
358 * server; eg, "http" or "ftp".
360 * Returns: the @proxy's destination protocol
365 g_proxy_address_get_destination_protocol (GProxyAddress *proxy)
367 return proxy->priv->dest_protocol;
371 * g_proxy_address_get_destination_hostname:
372 * @proxy: a #GProxyAddress
374 * Gets @proxy's destination hostname; that is, the name of the host
375 * that will be connected to via the proxy, not the name of the proxy
378 * Returns: the @proxy's destination hostname
383 g_proxy_address_get_destination_hostname (GProxyAddress *proxy)
385 return proxy->priv->dest_hostname;
389 * g_proxy_address_get_destination_port:
390 * @proxy: a #GProxyAddress
392 * Gets @proxy's destination port; that is, the port on the
393 * destination host that will be connected to via the proxy, not the
394 * port number of the proxy itself.
396 * Returns: the @proxy's destination port
401 g_proxy_address_get_destination_port (GProxyAddress *proxy)
403 return proxy->priv->dest_port;
407 * g_proxy_address_get_username:
408 * @proxy: a #GProxyAddress
410 * Gets @proxy's username.
412 * Returns: the @proxy's username
417 g_proxy_address_get_username (GProxyAddress *proxy)
419 return proxy->priv->username;
423 * g_proxy_address_get_password:
424 * @proxy: a #GProxyAddress
426 * Gets @proxy's password.
428 * Returns: the @proxy's password
433 g_proxy_address_get_password (GProxyAddress *proxy)
435 return proxy->priv->password;
440 * g_proxy_address_get_uri:
441 * @proxy: a #GProxyAddress
443 * Gets the proxy URI that @proxy was constructed from.
445 * Returns: the @proxy's URI, or %NULL if unknown
450 g_proxy_address_get_uri (GProxyAddress *proxy)
452 return proxy->priv->uri;