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
46 G_DEFINE_TYPE (GProxyAddress, g_proxy_address, G_TYPE_INET_SOCKET_ADDRESS);
52 PROP_DESTINATION_HOSTNAME,
53 PROP_DESTINATION_PORT,
58 struct _GProxyAddressPrivate
68 g_proxy_address_finalize (GObject *object)
70 GProxyAddress *proxy = G_PROXY_ADDRESS (object);
72 g_free (proxy->priv->protocol);
73 g_free (proxy->priv->username);
74 g_free (proxy->priv->password);
75 g_free (proxy->priv->dest_hostname);
77 G_OBJECT_CLASS (g_proxy_address_parent_class)->finalize (object);
81 g_proxy_address_set_property (GObject *object,
86 GProxyAddress *proxy = G_PROXY_ADDRESS (object);
91 g_free (proxy->priv->protocol);
92 proxy->priv->protocol = g_value_dup_string (value);
95 case PROP_DESTINATION_HOSTNAME:
96 g_free (proxy->priv->dest_hostname);
97 proxy->priv->dest_hostname = g_value_dup_string (value);
100 case PROP_DESTINATION_PORT:
101 proxy->priv->dest_port = g_value_get_uint (value);
105 g_free (proxy->priv->username);
106 proxy->priv->username = g_value_dup_string (value);
110 g_free (proxy->priv->password);
111 proxy->priv->password = g_value_dup_string (value);
115 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
120 g_proxy_address_get_property (GObject *object,
125 GProxyAddress *proxy = G_PROXY_ADDRESS (object);
130 g_value_set_string (value, proxy->priv->protocol);
133 case PROP_DESTINATION_HOSTNAME:
134 g_value_set_string (value, proxy->priv->dest_hostname);
137 case PROP_DESTINATION_PORT:
138 g_value_set_uint (value, proxy->priv->dest_port);
142 g_value_set_string (value, proxy->priv->username);
146 g_value_set_string (value, proxy->priv->password);
150 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
155 g_proxy_address_class_init (GProxyAddressClass *klass)
157 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
159 g_type_class_add_private (klass, sizeof (GProxyAddressPrivate));
161 gobject_class->finalize = g_proxy_address_finalize;
162 gobject_class->set_property = g_proxy_address_set_property;
163 gobject_class->get_property = g_proxy_address_get_property;
165 g_object_class_install_property (gobject_class,
167 g_param_spec_string ("protocol",
169 P_("The proxy protocol"),
172 G_PARAM_CONSTRUCT_ONLY |
173 G_PARAM_STATIC_STRINGS));
175 g_object_class_install_property (gobject_class,
177 g_param_spec_string ("username",
179 P_("The proxy username"),
182 G_PARAM_CONSTRUCT_ONLY |
183 G_PARAM_STATIC_STRINGS));
185 g_object_class_install_property (gobject_class,
187 g_param_spec_string ("password",
189 P_("The proxy password"),
192 G_PARAM_CONSTRUCT_ONLY |
193 G_PARAM_STATIC_STRINGS));
195 g_object_class_install_property (gobject_class,
196 PROP_DESTINATION_HOSTNAME,
197 g_param_spec_string ("destination-hostname",
198 P_("Destination Hostname"),
199 P_("The proxy destination hostname"),
202 G_PARAM_CONSTRUCT_ONLY |
203 G_PARAM_STATIC_STRINGS));
205 g_object_class_install_property (gobject_class,
206 PROP_DESTINATION_PORT,
207 g_param_spec_uint ("destination-port",
208 P_("Destination Port"),
209 P_("The proxy destination port"),
212 G_PARAM_CONSTRUCT_ONLY |
213 G_PARAM_STATIC_STRINGS));
217 g_proxy_address_init (GProxyAddress *proxy)
219 proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy,
220 G_TYPE_PROXY_ADDRESS,
221 GProxyAddressPrivate);
222 proxy->priv->protocol = NULL;
223 proxy->priv->username = NULL;
224 proxy->priv->password = NULL;
225 proxy->priv->dest_hostname = NULL;
226 proxy->priv->dest_port = 0;
230 * g_proxy_address_new:
231 * @inetaddr: The proxy server #GInetAddress.
232 * @port: The proxy server port.
233 * @protocol: The proxy protocol to support, in lower case (e.g. socks, http).
234 * @dest_hostname: The destination hostname the the proxy should tunnel to.
235 * @dest_port: The destination port to tunnel to.
236 * @username: (allow-none): The username to authenticate to the proxy server
238 * @password: (allow-none): The password to authenticate to the proxy server
241 * Creates a new #GProxyAddress for @inetaddr with @protocol that should
242 * tunnel through @dest_hostname and @dest_port.
244 * Returns: a new #GProxyAddress
249 g_proxy_address_new (GInetAddress *inetaddr,
251 const gchar *protocol,
252 const gchar *dest_hostname,
254 const gchar *username,
255 const gchar *password)
257 return g_object_new (G_TYPE_PROXY_ADDRESS,
260 "protocol", protocol,
261 "destination-hostname", dest_hostname,
262 "destination-port", dest_port,
263 "username", username,
264 "password", password,
270 * g_proxy_address_get_protocol:
271 * @proxy: a #GProxyAddress
273 * Gets @proxy's protocol.
275 * Returns: the @proxy's protocol
280 g_proxy_address_get_protocol (GProxyAddress *proxy)
282 return proxy->priv->protocol;
286 * g_proxy_address_get_destination_hostname
287 * @proxy: a #GProxyAddress
289 * Gets @proxy's destination hostname.
291 * Returns: the @proxy's destination hostname
296 g_proxy_address_get_destination_hostname (GProxyAddress *proxy)
298 return proxy->priv->dest_hostname;
302 * g_proxy_address_get_destination_port
303 * @proxy: a #GProxyAddress
305 * Gets @proxy's destination port.
307 * Returns: the @proxy's destination port
312 g_proxy_address_get_destination_port (GProxyAddress *proxy)
314 return proxy->priv->dest_port;
318 * g_proxy_address_get_username
319 * @proxy: a #GProxyAddress
321 * Gets @proxy's username.
323 * Returns: the @proxy's username
328 g_proxy_address_get_username (GProxyAddress *proxy)
330 return proxy->priv->username;
334 * g_proxy_address_get_password
335 * @proxy: a #GProxyAddress
337 * Gets @proxy's password.
339 * Returns: the @proxy's password
344 g_proxy_address_get_password (GProxyAddress *proxy)
346 return proxy->priv->password;