Improve GTimeZone test coverage
[glib.git] / gio / gproxyaddress.c
blob7796d8b6ecd7ae50f8104646a72577c85a46fec4
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 **/
46 G_DEFINE_TYPE (GProxyAddress, g_proxy_address, G_TYPE_INET_SOCKET_ADDRESS);
48 enum
50 PROP_0,
51 PROP_PROTOCOL,
52 PROP_DESTINATION_PROTOCOL,
53 PROP_DESTINATION_HOSTNAME,
54 PROP_DESTINATION_PORT,
55 PROP_USERNAME,
56 PROP_PASSWORD,
57 PROP_URI
60 struct _GProxyAddressPrivate
62 gchar *uri;
63 gchar *protocol;
64 gchar *username;
65 gchar *password;
66 gchar *dest_protocol;
67 gchar *dest_hostname;
68 guint16 dest_port;
71 static void
72 g_proxy_address_finalize (GObject *object)
74 GProxyAddress *proxy = G_PROXY_ADDRESS (object);
76 g_free (proxy->priv->uri);
77 g_free (proxy->priv->protocol);
78 g_free (proxy->priv->username);
79 g_free (proxy->priv->password);
80 g_free (proxy->priv->dest_hostname);
81 g_free (proxy->priv->dest_protocol);
83 G_OBJECT_CLASS (g_proxy_address_parent_class)->finalize (object);
86 static void
87 g_proxy_address_set_property (GObject *object,
88 guint prop_id,
89 const GValue *value,
90 GParamSpec *pspec)
92 GProxyAddress *proxy = G_PROXY_ADDRESS (object);
94 switch (prop_id)
96 case PROP_PROTOCOL:
97 g_free (proxy->priv->protocol);
98 proxy->priv->protocol = g_value_dup_string (value);
99 break;
101 case PROP_DESTINATION_PROTOCOL:
102 g_free (proxy->priv->dest_protocol);
103 proxy->priv->dest_protocol = g_value_dup_string (value);
104 break;
106 case PROP_DESTINATION_HOSTNAME:
107 g_free (proxy->priv->dest_hostname);
108 proxy->priv->dest_hostname = g_value_dup_string (value);
109 break;
111 case PROP_DESTINATION_PORT:
112 proxy->priv->dest_port = g_value_get_uint (value);
113 break;
115 case PROP_USERNAME:
116 g_free (proxy->priv->username);
117 proxy->priv->username = g_value_dup_string (value);
118 break;
120 case PROP_PASSWORD:
121 g_free (proxy->priv->password);
122 proxy->priv->password = g_value_dup_string (value);
123 break;
125 case PROP_URI:
126 g_free (proxy->priv->uri);
127 proxy->priv->uri = g_value_dup_string (value);
128 break;
130 default:
131 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
135 static void
136 g_proxy_address_get_property (GObject *object,
137 guint prop_id,
138 GValue *value,
139 GParamSpec *pspec)
141 GProxyAddress *proxy = G_PROXY_ADDRESS (object);
143 switch (prop_id)
145 case PROP_PROTOCOL:
146 g_value_set_string (value, proxy->priv->protocol);
147 break;
149 case PROP_DESTINATION_PROTOCOL:
150 g_value_set_string (value, proxy->priv->dest_protocol);
151 break;
153 case PROP_DESTINATION_HOSTNAME:
154 g_value_set_string (value, proxy->priv->dest_hostname);
155 break;
157 case PROP_DESTINATION_PORT:
158 g_value_set_uint (value, proxy->priv->dest_port);
159 break;
161 case PROP_USERNAME:
162 g_value_set_string (value, proxy->priv->username);
163 break;
165 case PROP_PASSWORD:
166 g_value_set_string (value, proxy->priv->password);
167 break;
169 case PROP_URI:
170 g_value_set_string (value, proxy->priv->uri);
171 break;
173 default:
174 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
178 static void
179 g_proxy_address_class_init (GProxyAddressClass *klass)
181 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
183 g_type_class_add_private (klass, sizeof (GProxyAddressPrivate));
185 gobject_class->finalize = g_proxy_address_finalize;
186 gobject_class->set_property = g_proxy_address_set_property;
187 gobject_class->get_property = g_proxy_address_get_property;
189 g_object_class_install_property (gobject_class,
190 PROP_PROTOCOL,
191 g_param_spec_string ("protocol",
192 P_("Protocol"),
193 P_("The proxy protocol"),
194 NULL,
195 G_PARAM_READWRITE |
196 G_PARAM_CONSTRUCT_ONLY |
197 G_PARAM_STATIC_STRINGS));
199 g_object_class_install_property (gobject_class,
200 PROP_USERNAME,
201 g_param_spec_string ("username",
202 P_("Username"),
203 P_("The proxy username"),
204 NULL,
205 G_PARAM_READWRITE |
206 G_PARAM_CONSTRUCT_ONLY |
207 G_PARAM_STATIC_STRINGS));
209 g_object_class_install_property (gobject_class,
210 PROP_PASSWORD,
211 g_param_spec_string ("password",
212 P_("Password"),
213 P_("The proxy password"),
214 NULL,
215 G_PARAM_READWRITE |
216 G_PARAM_CONSTRUCT_ONLY |
217 G_PARAM_STATIC_STRINGS));
220 * GProxyAddress:destination-protocol:
222 * The protocol being spoke to the destination host, or %NULL if
223 * the #GProxyAddress doesn't know.
225 * Since: 2.34
227 g_object_class_install_property (gobject_class,
228 PROP_DESTINATION_PROTOCOL,
229 g_param_spec_string ("destination-protocol",
230 P_("Destionation Protocol"),
231 P_("The proxy destination protocol"),
232 NULL,
233 G_PARAM_READWRITE |
234 G_PARAM_CONSTRUCT_ONLY |
235 G_PARAM_STATIC_STRINGS));
237 g_object_class_install_property (gobject_class,
238 PROP_DESTINATION_HOSTNAME,
239 g_param_spec_string ("destination-hostname",
240 P_("Destination Hostname"),
241 P_("The proxy destination hostname"),
242 NULL,
243 G_PARAM_READWRITE |
244 G_PARAM_CONSTRUCT_ONLY |
245 G_PARAM_STATIC_STRINGS));
247 g_object_class_install_property (gobject_class,
248 PROP_DESTINATION_PORT,
249 g_param_spec_uint ("destination-port",
250 P_("Destination Port"),
251 P_("The proxy destination port"),
252 0, 65535, 0,
253 G_PARAM_READWRITE |
254 G_PARAM_CONSTRUCT_ONLY |
255 G_PARAM_STATIC_STRINGS));
258 * GProxyAddress:uri:
260 * The URI string that the proxy was constructed from (or %NULL
261 * if the creator didn't specify this).
263 * Since: 2.34
265 g_object_class_install_property (gobject_class,
266 PROP_URI,
267 g_param_spec_string ("uri",
268 P_("URI"),
269 P_("The proxy's URI"),
270 NULL,
271 G_PARAM_READWRITE |
272 G_PARAM_CONSTRUCT_ONLY |
273 G_PARAM_STATIC_STRINGS));
276 static void
277 g_proxy_address_init (GProxyAddress *proxy)
279 proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy,
280 G_TYPE_PROXY_ADDRESS,
281 GProxyAddressPrivate);
282 proxy->priv->protocol = NULL;
283 proxy->priv->username = NULL;
284 proxy->priv->password = NULL;
285 proxy->priv->dest_hostname = NULL;
286 proxy->priv->dest_port = 0;
290 * g_proxy_address_new:
291 * @inetaddr: The proxy server #GInetAddress.
292 * @port: The proxy server port.
293 * @protocol: The proxy protocol to support, in lower case (e.g. socks, http).
294 * @dest_hostname: The destination hostname the the proxy should tunnel to.
295 * @dest_port: The destination port to tunnel to.
296 * @username: (allow-none): The username to authenticate to the proxy server
297 * (or %NULL).
298 * @password: (allow-none): The password to authenticate to the proxy server
299 * (or %NULL).
301 * Creates a new #GProxyAddress for @inetaddr with @protocol that should
302 * tunnel through @dest_hostname and @dest_port.
304 * (Note that this method doesn't set the #GProxyAddress:uri or
305 * #GProxyAddress:destination-protocol fields; use g_object_new()
306 * directly if you want to set those.)
308 * Returns: a new #GProxyAddress
310 * Since: 2.26
312 GSocketAddress *
313 g_proxy_address_new (GInetAddress *inetaddr,
314 guint16 port,
315 const gchar *protocol,
316 const gchar *dest_hostname,
317 guint16 dest_port,
318 const gchar *username,
319 const gchar *password)
321 return g_object_new (G_TYPE_PROXY_ADDRESS,
322 "address", inetaddr,
323 "port", port,
324 "protocol", protocol,
325 "destination-hostname", dest_hostname,
326 "destination-port", dest_port,
327 "username", username,
328 "password", password,
329 NULL);
334 * g_proxy_address_get_protocol:
335 * @proxy: a #GProxyAddress
337 * Gets @proxy's protocol. eg, "socks" or "http"
339 * Returns: the @proxy's protocol
341 * Since: 2.26
343 const gchar *
344 g_proxy_address_get_protocol (GProxyAddress *proxy)
346 return proxy->priv->protocol;
350 * g_proxy_address_get_destination_protocol:
351 * @proxy: a #GProxyAddress
353 * Gets the protocol that is being spoken to the destination
354 * server; eg, "http" or "ftp".
356 * Returns: the @proxy's destination protocol
358 * Since: 2.34
360 const gchar *
361 g_proxy_address_get_destination_protocol (GProxyAddress *proxy)
363 return proxy->priv->dest_protocol;
367 * g_proxy_address_get_destination_hostname:
368 * @proxy: a #GProxyAddress
370 * Gets @proxy's destination hostname; that is, the name of the host
371 * that will be connected to via the proxy, not the name of the proxy
372 * itself.
374 * Returns: the @proxy's destination hostname
376 * Since: 2.26
378 const gchar *
379 g_proxy_address_get_destination_hostname (GProxyAddress *proxy)
381 return proxy->priv->dest_hostname;
385 * g_proxy_address_get_destination_port:
386 * @proxy: a #GProxyAddress
388 * Gets @proxy's destination port; that is, the port on the
389 * destination host that will be connected to via the proxy, not the
390 * port number of the proxy itself.
392 * Returns: the @proxy's destination port
394 * Since: 2.26
396 guint16
397 g_proxy_address_get_destination_port (GProxyAddress *proxy)
399 return proxy->priv->dest_port;
403 * g_proxy_address_get_username:
404 * @proxy: a #GProxyAddress
406 * Gets @proxy's username.
408 * Returns: the @proxy's username
410 * Since: 2.26
412 const gchar *
413 g_proxy_address_get_username (GProxyAddress *proxy)
415 return proxy->priv->username;
419 * g_proxy_address_get_password:
420 * @proxy: a #GProxyAddress
422 * Gets @proxy's password.
424 * Returns: the @proxy's password
426 * Since: 2.26
428 const gchar *
429 g_proxy_address_get_password (GProxyAddress *proxy)
431 return proxy->priv->password;
436 * g_proxy_address_get_uri:
437 * @proxy: a #GProxyAddress
439 * Gets the proxy URI that @proxy was constructed from.
441 * Returns: the @proxy's URI, or %NULL if unknown
443 * Since: 2.34
445 const gchar *
446 g_proxy_address_get_uri (GProxyAddress *proxy)
448 return proxy->priv->uri;