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 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, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Authors: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
27 #include <gio/gsocketaddress.h>
29 #include "gproxyaddress.h"
33 * SECTION:gproxyaddress
34 * @short_description: An internet address with proxy information
36 * Support for proxied #GInetSocketAddress.
42 * A #GInetSocketAddress representing a connection via a proxy server
51 PROP_DESTINATION_PROTOCOL,
52 PROP_DESTINATION_HOSTNAME,
53 PROP_DESTINATION_PORT,
59 struct _GProxyAddressPrivate
70 G_DEFINE_TYPE_WITH_PRIVATE (GProxyAddress, g_proxy_address, G_TYPE_INET_SOCKET_ADDRESS)
73 g_proxy_address_finalize (GObject *object)
75 GProxyAddress *proxy = G_PROXY_ADDRESS (object);
77 g_free (proxy->priv->uri);
78 g_free (proxy->priv->protocol);
79 g_free (proxy->priv->username);
80 g_free (proxy->priv->password);
81 g_free (proxy->priv->dest_hostname);
82 g_free (proxy->priv->dest_protocol);
84 G_OBJECT_CLASS (g_proxy_address_parent_class)->finalize (object);
88 g_proxy_address_set_property (GObject *object,
93 GProxyAddress *proxy = G_PROXY_ADDRESS (object);
98 g_free (proxy->priv->protocol);
99 proxy->priv->protocol = g_value_dup_string (value);
102 case PROP_DESTINATION_PROTOCOL:
103 g_free (proxy->priv->dest_protocol);
104 proxy->priv->dest_protocol = g_value_dup_string (value);
107 case PROP_DESTINATION_HOSTNAME:
108 g_free (proxy->priv->dest_hostname);
109 proxy->priv->dest_hostname = g_value_dup_string (value);
112 case PROP_DESTINATION_PORT:
113 proxy->priv->dest_port = g_value_get_uint (value);
117 g_free (proxy->priv->username);
118 proxy->priv->username = g_value_dup_string (value);
122 g_free (proxy->priv->password);
123 proxy->priv->password = g_value_dup_string (value);
127 g_free (proxy->priv->uri);
128 proxy->priv->uri = g_value_dup_string (value);
132 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
137 g_proxy_address_get_property (GObject *object,
142 GProxyAddress *proxy = G_PROXY_ADDRESS (object);
147 g_value_set_string (value, proxy->priv->protocol);
150 case PROP_DESTINATION_PROTOCOL:
151 g_value_set_string (value, proxy->priv->dest_protocol);
154 case PROP_DESTINATION_HOSTNAME:
155 g_value_set_string (value, proxy->priv->dest_hostname);
158 case PROP_DESTINATION_PORT:
159 g_value_set_uint (value, proxy->priv->dest_port);
163 g_value_set_string (value, proxy->priv->username);
167 g_value_set_string (value, proxy->priv->password);
171 g_value_set_string (value, proxy->priv->uri);
175 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
180 g_proxy_address_class_init (GProxyAddressClass *klass)
182 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
184 gobject_class->finalize = g_proxy_address_finalize;
185 gobject_class->set_property = g_proxy_address_set_property;
186 gobject_class->get_property = g_proxy_address_get_property;
188 g_object_class_install_property (gobject_class,
190 g_param_spec_string ("protocol",
192 P_("The proxy protocol"),
195 G_PARAM_CONSTRUCT_ONLY |
196 G_PARAM_STATIC_STRINGS));
198 g_object_class_install_property (gobject_class,
200 g_param_spec_string ("username",
202 P_("The proxy username"),
205 G_PARAM_CONSTRUCT_ONLY |
206 G_PARAM_STATIC_STRINGS));
208 g_object_class_install_property (gobject_class,
210 g_param_spec_string ("password",
212 P_("The proxy password"),
215 G_PARAM_CONSTRUCT_ONLY |
216 G_PARAM_STATIC_STRINGS));
219 * GProxyAddress:destination-protocol:
221 * The protocol being spoke to the destination host, or %NULL if
222 * the #GProxyAddress doesn't know.
226 g_object_class_install_property (gobject_class,
227 PROP_DESTINATION_PROTOCOL,
228 g_param_spec_string ("destination-protocol",
229 P_("Destionation Protocol"),
230 P_("The proxy destination protocol"),
233 G_PARAM_CONSTRUCT_ONLY |
234 G_PARAM_STATIC_STRINGS));
236 g_object_class_install_property (gobject_class,
237 PROP_DESTINATION_HOSTNAME,
238 g_param_spec_string ("destination-hostname",
239 P_("Destination Hostname"),
240 P_("The proxy destination hostname"),
243 G_PARAM_CONSTRUCT_ONLY |
244 G_PARAM_STATIC_STRINGS));
246 g_object_class_install_property (gobject_class,
247 PROP_DESTINATION_PORT,
248 g_param_spec_uint ("destination-port",
249 P_("Destination Port"),
250 P_("The proxy destination port"),
253 G_PARAM_CONSTRUCT_ONLY |
254 G_PARAM_STATIC_STRINGS));
259 * The URI string that the proxy was constructed from (or %NULL
260 * if the creator didn't specify this).
264 g_object_class_install_property (gobject_class,
266 g_param_spec_string ("uri",
268 P_("The proxy's URI"),
271 G_PARAM_CONSTRUCT_ONLY |
272 G_PARAM_STATIC_STRINGS));
276 g_proxy_address_init (GProxyAddress *proxy)
278 proxy->priv = g_proxy_address_get_instance_private (proxy);
279 proxy->priv->protocol = NULL;
280 proxy->priv->username = NULL;
281 proxy->priv->password = NULL;
282 proxy->priv->dest_hostname = NULL;
283 proxy->priv->dest_port = 0;
287 * g_proxy_address_new:
288 * @inetaddr: The proxy server #GInetAddress.
289 * @port: The proxy server port.
290 * @protocol: The proxy protocol to support, in lower case (e.g. socks, http).
291 * @dest_hostname: The destination hostname the proxy should tunnel to.
292 * @dest_port: The destination port to tunnel to.
293 * @username: (allow-none): The username to authenticate to the proxy server
295 * @password: (allow-none): The password to authenticate to the proxy server
298 * Creates a new #GProxyAddress for @inetaddr with @protocol that should
299 * tunnel through @dest_hostname and @dest_port.
301 * (Note that this method doesn't set the #GProxyAddress:uri or
302 * #GProxyAddress:destination-protocol fields; use g_object_new()
303 * directly if you want to set those.)
305 * Returns: a new #GProxyAddress
310 g_proxy_address_new (GInetAddress *inetaddr,
312 const gchar *protocol,
313 const gchar *dest_hostname,
315 const gchar *username,
316 const gchar *password)
318 return g_object_new (G_TYPE_PROXY_ADDRESS,
321 "protocol", protocol,
322 "destination-hostname", dest_hostname,
323 "destination-port", dest_port,
324 "username", username,
325 "password", password,
331 * g_proxy_address_get_protocol:
332 * @proxy: a #GProxyAddress
334 * Gets @proxy's protocol. eg, "socks" or "http"
336 * Returns: the @proxy's protocol
341 g_proxy_address_get_protocol (GProxyAddress *proxy)
343 return proxy->priv->protocol;
347 * g_proxy_address_get_destination_protocol:
348 * @proxy: a #GProxyAddress
350 * Gets the protocol that is being spoken to the destination
351 * server; eg, "http" or "ftp".
353 * Returns: the @proxy's destination protocol
358 g_proxy_address_get_destination_protocol (GProxyAddress *proxy)
360 return proxy->priv->dest_protocol;
364 * g_proxy_address_get_destination_hostname:
365 * @proxy: a #GProxyAddress
367 * Gets @proxy's destination hostname; that is, the name of the host
368 * that will be connected to via the proxy, not the name of the proxy
371 * Returns: the @proxy's destination hostname
376 g_proxy_address_get_destination_hostname (GProxyAddress *proxy)
378 return proxy->priv->dest_hostname;
382 * g_proxy_address_get_destination_port:
383 * @proxy: a #GProxyAddress
385 * Gets @proxy's destination port; that is, the port on the
386 * destination host that will be connected to via the proxy, not the
387 * port number of the proxy itself.
389 * Returns: the @proxy's destination port
394 g_proxy_address_get_destination_port (GProxyAddress *proxy)
396 return proxy->priv->dest_port;
400 * g_proxy_address_get_username:
401 * @proxy: a #GProxyAddress
403 * Gets @proxy's username.
405 * Returns: the @proxy's username
410 g_proxy_address_get_username (GProxyAddress *proxy)
412 return proxy->priv->username;
416 * g_proxy_address_get_password:
417 * @proxy: a #GProxyAddress
419 * Gets @proxy's password.
421 * Returns: the @proxy's password
426 g_proxy_address_get_password (GProxyAddress *proxy)
428 return proxy->priv->password;
433 * g_proxy_address_get_uri:
434 * @proxy: a #GProxyAddress
436 * Gets the proxy URI that @proxy was constructed from.
438 * Returns: the @proxy's URI, or %NULL if unknown
443 g_proxy_address_get_uri (GProxyAddress *proxy)
445 return proxy->priv->uri;