| 
									
										
										
										
											2010-05-07 15:55:54 -04:00
										 |  |  | /* GIO - GLib Input, Output and Streaming Library
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (C) 2010 Collabora, Ltd. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2022-05-18 09:12:45 +01:00
										 |  |  |  * SPDX-License-Identifier: LGPL-2.1-or-later | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2010-05-07 15:55:54 -04:00
										 |  |  |  * This library is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  * License as published by the Free Software Foundation; either | 
					
						
							| 
									
										
										
										
											2017-05-27 18:21:30 +02:00
										 |  |  |  * version 2.1 of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2010-05-07 15:55:54 -04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This library is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  * Lesser General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Lesser General | 
					
						
							| 
									
										
										
										
											2014-01-23 12:58:29 +01:00
										 |  |  |  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							| 
									
										
										
										
											2010-05-07 15:55:54 -04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Author: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "config.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "gdummyproxyresolver.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <glib.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "gasyncresult.h"
 | 
					
						
							|  |  |  | #include "gcancellable.h"
 | 
					
						
							|  |  |  | #include "gproxyresolver.h"
 | 
					
						
							| 
									
										
										
										
											2012-08-02 15:48:22 -04:00
										 |  |  | #include "gtask.h"
 | 
					
						
							| 
									
										
										
										
											2010-05-07 15:55:54 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "giomodule.h"
 | 
					
						
							|  |  |  | #include "giomodule-priv.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct _GDummyProxyResolver { | 
					
						
							|  |  |  |   GObject parent_instance; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void g_dummy_proxy_resolver_iface_init (GProxyResolverInterface *iface); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define g_dummy_proxy_resolver_get_type _g_dummy_proxy_resolver_get_type
 | 
					
						
							|  |  |  | G_DEFINE_TYPE_WITH_CODE (GDummyProxyResolver, g_dummy_proxy_resolver, G_TYPE_OBJECT, | 
					
						
							|  |  |  | 			 G_IMPLEMENT_INTERFACE (G_TYPE_PROXY_RESOLVER, | 
					
						
							|  |  |  | 						g_dummy_proxy_resolver_iface_init) | 
					
						
							|  |  |  | 			 _g_io_modules_ensure_extension_points_registered (); | 
					
						
							|  |  |  | 			 g_io_extension_point_implement (G_PROXY_RESOLVER_EXTENSION_POINT_NAME, | 
					
						
							|  |  |  | 							 g_define_type_id, | 
					
						
							|  |  |  | 							 "dummy", | 
					
						
							|  |  |  | 							 -100)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | g_dummy_proxy_resolver_finalize (GObject *object) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   /* must chain up */ | 
					
						
							|  |  |  |   G_OBJECT_CLASS (g_dummy_proxy_resolver_parent_class)->finalize (object); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | g_dummy_proxy_resolver_init (GDummyProxyResolver *resolver) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static gboolean | 
					
						
							|  |  |  | g_dummy_proxy_resolver_is_supported (GProxyResolver *resolver) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return TRUE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static gchar ** | 
					
						
							|  |  |  | g_dummy_proxy_resolver_lookup (GProxyResolver  *resolver, | 
					
						
							|  |  |  | 			       const gchar     *uri, | 
					
						
							|  |  |  | 			       GCancellable    *cancellable, | 
					
						
							|  |  |  | 			       GError         **error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   gchar **proxies; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (g_cancellable_set_error_if_cancelled (cancellable, error)) | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   proxies = g_new0 (gchar *, 2); | 
					
						
							|  |  |  |   proxies[0] = g_strdup ("direct://"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return proxies; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | g_dummy_proxy_resolver_lookup_async (GProxyResolver      *resolver, | 
					
						
							|  |  |  | 				     const gchar         *uri, | 
					
						
							|  |  |  | 				     GCancellable        *cancellable, | 
					
						
							|  |  |  | 				     GAsyncReadyCallback  callback, | 
					
						
							|  |  |  | 				     gpointer             user_data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GError *error = NULL; | 
					
						
							| 
									
										
										
										
											2012-08-02 15:48:22 -04:00
										 |  |  |   GTask *task; | 
					
						
							| 
									
										
										
										
											2010-05-07 15:55:54 -04:00
										 |  |  |   gchar **proxies; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-02 15:48:22 -04:00
										 |  |  |   task = g_task_new (resolver, cancellable, callback, user_data); | 
					
						
							| 
									
										
										
										
											2016-06-16 19:39:38 -04:00
										 |  |  |   g_task_set_source_tag (task, g_dummy_proxy_resolver_lookup_async); | 
					
						
							| 
									
										
										
										
											2010-05-07 15:55:54 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-02 15:48:22 -04:00
										 |  |  |   proxies = g_dummy_proxy_resolver_lookup (resolver, uri, cancellable, &error); | 
					
						
							|  |  |  |   if (proxies) | 
					
						
							|  |  |  |     g_task_return_pointer (task, proxies, (GDestroyNotify) g_strfreev); | 
					
						
							| 
									
										
										
										
											2010-05-07 15:55:54 -04:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2012-08-02 15:48:22 -04:00
										 |  |  |     g_task_return_error (task, error); | 
					
						
							|  |  |  |   g_object_unref (task); | 
					
						
							| 
									
										
										
										
											2010-05-07 15:55:54 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static gchar ** | 
					
						
							|  |  |  | g_dummy_proxy_resolver_lookup_finish (GProxyResolver     *resolver, | 
					
						
							|  |  |  | 				      GAsyncResult       *result, | 
					
						
							|  |  |  | 				      GError            **error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-08-02 15:48:22 -04:00
										 |  |  |   g_return_val_if_fail (g_task_is_valid (result, resolver), NULL); | 
					
						
							| 
									
										
										
										
											2010-05-07 15:55:54 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-02 15:48:22 -04:00
										 |  |  |   return g_task_propagate_pointer (G_TASK (result), error); | 
					
						
							| 
									
										
										
										
											2010-05-07 15:55:54 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | g_dummy_proxy_resolver_class_init (GDummyProxyResolverClass *resolver_class) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GObjectClass *object_class; | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   object_class = G_OBJECT_CLASS (resolver_class); | 
					
						
							|  |  |  |   object_class->finalize = g_dummy_proxy_resolver_finalize; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | g_dummy_proxy_resolver_iface_init (GProxyResolverInterface *iface) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   iface->is_supported = g_dummy_proxy_resolver_is_supported; | 
					
						
							|  |  |  |   iface->lookup = g_dummy_proxy_resolver_lookup; | 
					
						
							|  |  |  |   iface->lookup_async = g_dummy_proxy_resolver_lookup_async; | 
					
						
							|  |  |  |   iface->lookup_finish = g_dummy_proxy_resolver_lookup_finish; | 
					
						
							|  |  |  | } |