gdbus tests: remove buggy use of GMainLoop
[glib.git] / gio / gproxyaddress.c
blob68ef29420f89c751962028237ff8dc45af29e6a6
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_HOSTNAME,
53 PROP_DESTINATION_PORT,
54 PROP_USERNAME,
55 PROP_PASSWORD
58 struct _GProxyAddressPrivate
60 gchar *protocol;
61 gchar *username;
62 gchar *password;
63 gchar *dest_hostname;
64 guint16 dest_port;
67 static void
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);
80 static void
81 g_proxy_address_set_property (GObject *object,
82 guint prop_id,
83 const GValue *value,
84 GParamSpec *pspec)
86 GProxyAddress *proxy = G_PROXY_ADDRESS (object);
88 switch (prop_id)
90 case PROP_PROTOCOL:
91 g_free (proxy->priv->protocol);
92 proxy->priv->protocol = g_value_dup_string (value);
93 break;
95 case PROP_DESTINATION_HOSTNAME:
96 g_free (proxy->priv->dest_hostname);
97 proxy->priv->dest_hostname = g_value_dup_string (value);
98 break;
100 case PROP_DESTINATION_PORT:
101 proxy->priv->dest_port = g_value_get_uint (value);
102 break;
104 case PROP_USERNAME:
105 g_free (proxy->priv->username);
106 proxy->priv->username = g_value_dup_string (value);
107 break;
109 case PROP_PASSWORD:
110 g_free (proxy->priv->password);
111 proxy->priv->password = g_value_dup_string (value);
112 break;
114 default:
115 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
119 static void
120 g_proxy_address_get_property (GObject *object,
121 guint prop_id,
122 GValue *value,
123 GParamSpec *pspec)
125 GProxyAddress *proxy = G_PROXY_ADDRESS (object);
127 switch (prop_id)
129 case PROP_PROTOCOL:
130 g_value_set_string (value, proxy->priv->protocol);
131 break;
133 case PROP_DESTINATION_HOSTNAME:
134 g_value_set_string (value, proxy->priv->dest_hostname);
135 break;
137 case PROP_DESTINATION_PORT:
138 g_value_set_uint (value, proxy->priv->dest_port);
139 break;
141 case PROP_USERNAME:
142 g_value_set_string (value, proxy->priv->username);
143 break;
145 case PROP_PASSWORD:
146 g_value_set_string (value, proxy->priv->password);
147 break;
149 default:
150 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
154 static void
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,
166 PROP_PROTOCOL,
167 g_param_spec_string ("protocol",
168 P_("Protocol"),
169 P_("The proxy protocol"),
170 NULL,
171 G_PARAM_READWRITE |
172 G_PARAM_CONSTRUCT_ONLY |
173 G_PARAM_STATIC_STRINGS));
175 g_object_class_install_property (gobject_class,
176 PROP_USERNAME,
177 g_param_spec_string ("username",
178 P_("Username"),
179 P_("The proxy username"),
180 NULL,
181 G_PARAM_READWRITE |
182 G_PARAM_CONSTRUCT_ONLY |
183 G_PARAM_STATIC_STRINGS));
185 g_object_class_install_property (gobject_class,
186 PROP_PASSWORD,
187 g_param_spec_string ("password",
188 P_("Password"),
189 P_("The proxy password"),
190 NULL,
191 G_PARAM_READWRITE |
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"),
200 NULL,
201 G_PARAM_READWRITE |
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"),
210 0, 65535, 0,
211 G_PARAM_READWRITE |
212 G_PARAM_CONSTRUCT_ONLY |
213 G_PARAM_STATIC_STRINGS));
216 static void
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
237 * (or %NULL).
238 * @password: (allow-none): The password to authenticate to the proxy server
239 * (or %NULL).
241 * Creates a new #GProxyAddress for @inetaddr with @protocol that should
242 * tunnel through @dest_hostname and @dest_port.
244 * Returns: a new #GProxyAddress
246 * Since: 2.26
248 GSocketAddress *
249 g_proxy_address_new (GInetAddress *inetaddr,
250 guint16 port,
251 const gchar *protocol,
252 const gchar *dest_hostname,
253 guint16 dest_port,
254 const gchar *username,
255 const gchar *password)
257 return g_object_new (G_TYPE_PROXY_ADDRESS,
258 "address", inetaddr,
259 "port", port,
260 "protocol", protocol,
261 "destination-hostname", dest_hostname,
262 "destination-port", dest_port,
263 "username", username,
264 "password", password,
265 NULL);
270 * g_proxy_address_get_protocol:
271 * @proxy: a #GProxyAddress
273 * Gets @proxy's protocol.
275 * Returns: the @proxy's protocol
277 * Since: 2.26
279 const gchar *
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
293 * Since: 2.26
295 const gchar *
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
309 * Since: 2.26
311 guint16
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
325 * Since: 2.26
327 const gchar *
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
341 * Since: 2.26
343 const gchar *
344 g_proxy_address_get_password (GProxyAddress *proxy)
346 return proxy->priv->password;