glib/tests: Fix non-debug build of slice test
[glib.git] / gio / gproxyaddress.c
blob8d7a3bf2f3b3de45d22ac2c3cdb4c7c7ee62293f
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>
23 #include <config.h>
24 #include <glib.h>
25 #include <string.h>
27 #include <gio/gsocketaddress.h>
29 #include "gproxyaddress.h"
30 #include "glibintl.h"
32 /**
33 * SECTION:gproxyaddress
34 * @short_description: An internet address with proxy information
36 * Support for proxied #GInetSocketAddress.
39 /**
40 * GProxyAddress:
42 * A #GInetSocketAddress representing a connection via a proxy server
44 * Since: 2.26
45 **/
47 enum
49 PROP_0,
50 PROP_PROTOCOL,
51 PROP_DESTINATION_PROTOCOL,
52 PROP_DESTINATION_HOSTNAME,
53 PROP_DESTINATION_PORT,
54 PROP_USERNAME,
55 PROP_PASSWORD,
56 PROP_URI
59 struct _GProxyAddressPrivate
61 gchar *uri;
62 gchar *protocol;
63 gchar *username;
64 gchar *password;
65 gchar *dest_protocol;
66 gchar *dest_hostname;
67 guint16 dest_port;
70 G_DEFINE_TYPE_WITH_PRIVATE (GProxyAddress, g_proxy_address, G_TYPE_INET_SOCKET_ADDRESS)
72 static void
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);
87 static void
88 g_proxy_address_set_property (GObject *object,
89 guint prop_id,
90 const GValue *value,
91 GParamSpec *pspec)
93 GProxyAddress *proxy = G_PROXY_ADDRESS (object);
95 switch (prop_id)
97 case PROP_PROTOCOL:
98 g_free (proxy->priv->protocol);
99 proxy->priv->protocol = g_value_dup_string (value);
100 break;
102 case PROP_DESTINATION_PROTOCOL:
103 g_free (proxy->priv->dest_protocol);
104 proxy->priv->dest_protocol = g_value_dup_string (value);
105 break;
107 case PROP_DESTINATION_HOSTNAME:
108 g_free (proxy->priv->dest_hostname);
109 proxy->priv->dest_hostname = g_value_dup_string (value);
110 break;
112 case PROP_DESTINATION_PORT:
113 proxy->priv->dest_port = g_value_get_uint (value);
114 break;
116 case PROP_USERNAME:
117 g_free (proxy->priv->username);
118 proxy->priv->username = g_value_dup_string (value);
119 break;
121 case PROP_PASSWORD:
122 g_free (proxy->priv->password);
123 proxy->priv->password = g_value_dup_string (value);
124 break;
126 case PROP_URI:
127 g_free (proxy->priv->uri);
128 proxy->priv->uri = g_value_dup_string (value);
129 break;
131 default:
132 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
136 static void
137 g_proxy_address_get_property (GObject *object,
138 guint prop_id,
139 GValue *value,
140 GParamSpec *pspec)
142 GProxyAddress *proxy = G_PROXY_ADDRESS (object);
144 switch (prop_id)
146 case PROP_PROTOCOL:
147 g_value_set_string (value, proxy->priv->protocol);
148 break;
150 case PROP_DESTINATION_PROTOCOL:
151 g_value_set_string (value, proxy->priv->dest_protocol);
152 break;
154 case PROP_DESTINATION_HOSTNAME:
155 g_value_set_string (value, proxy->priv->dest_hostname);
156 break;
158 case PROP_DESTINATION_PORT:
159 g_value_set_uint (value, proxy->priv->dest_port);
160 break;
162 case PROP_USERNAME:
163 g_value_set_string (value, proxy->priv->username);
164 break;
166 case PROP_PASSWORD:
167 g_value_set_string (value, proxy->priv->password);
168 break;
170 case PROP_URI:
171 g_value_set_string (value, proxy->priv->uri);
172 break;
174 default:
175 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
179 static void
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,
189 PROP_PROTOCOL,
190 g_param_spec_string ("protocol",
191 P_("Protocol"),
192 P_("The proxy protocol"),
193 NULL,
194 G_PARAM_READWRITE |
195 G_PARAM_CONSTRUCT_ONLY |
196 G_PARAM_STATIC_STRINGS));
198 g_object_class_install_property (gobject_class,
199 PROP_USERNAME,
200 g_param_spec_string ("username",
201 P_("Username"),
202 P_("The proxy username"),
203 NULL,
204 G_PARAM_READWRITE |
205 G_PARAM_CONSTRUCT_ONLY |
206 G_PARAM_STATIC_STRINGS));
208 g_object_class_install_property (gobject_class,
209 PROP_PASSWORD,
210 g_param_spec_string ("password",
211 P_("Password"),
212 P_("The proxy password"),
213 NULL,
214 G_PARAM_READWRITE |
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.
224 * Since: 2.34
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"),
231 NULL,
232 G_PARAM_READWRITE |
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"),
241 NULL,
242 G_PARAM_READWRITE |
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"),
251 0, 65535, 0,
252 G_PARAM_READWRITE |
253 G_PARAM_CONSTRUCT_ONLY |
254 G_PARAM_STATIC_STRINGS));
257 * GProxyAddress:uri:
259 * The URI string that the proxy was constructed from (or %NULL
260 * if the creator didn't specify this).
262 * Since: 2.34
264 g_object_class_install_property (gobject_class,
265 PROP_URI,
266 g_param_spec_string ("uri",
267 P_("URI"),
268 P_("The proxy's URI"),
269 NULL,
270 G_PARAM_READWRITE |
271 G_PARAM_CONSTRUCT_ONLY |
272 G_PARAM_STATIC_STRINGS));
275 static void
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
294 * (or %NULL).
295 * @password: (allow-none): The password to authenticate to the proxy server
296 * (or %NULL).
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
307 * Since: 2.26
309 GSocketAddress *
310 g_proxy_address_new (GInetAddress *inetaddr,
311 guint16 port,
312 const gchar *protocol,
313 const gchar *dest_hostname,
314 guint16 dest_port,
315 const gchar *username,
316 const gchar *password)
318 return g_object_new (G_TYPE_PROXY_ADDRESS,
319 "address", inetaddr,
320 "port", port,
321 "protocol", protocol,
322 "destination-hostname", dest_hostname,
323 "destination-port", dest_port,
324 "username", username,
325 "password", password,
326 NULL);
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
338 * Since: 2.26
340 const gchar *
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
355 * Since: 2.34
357 const gchar *
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
369 * itself.
371 * Returns: the @proxy's destination hostname
373 * Since: 2.26
375 const gchar *
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
391 * Since: 2.26
393 guint16
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
407 * Since: 2.26
409 const gchar *
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
423 * Since: 2.26
425 const gchar *
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
440 * Since: 2.34
442 const gchar *
443 g_proxy_address_get_uri (GProxyAddress *proxy)
445 return proxy->priv->uri;