/src/glib/gio/gdummyproxyresolver.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* GIO - GLib Input, Output and Streaming Library |
2 | | * |
3 | | * Copyright (C) 2010 Collabora, Ltd. |
4 | | * |
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.1 of the License, or (at your option) any later version. |
9 | | * |
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. |
14 | | * |
15 | | * You should have received a copy of the GNU Lesser General |
16 | | * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. |
17 | | * |
18 | | * Author: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> |
19 | | */ |
20 | | |
21 | | #include "config.h" |
22 | | |
23 | | #include "gdummyproxyresolver.h" |
24 | | |
25 | | #include <glib.h> |
26 | | |
27 | | #include "gasyncresult.h" |
28 | | #include "gcancellable.h" |
29 | | #include "gproxyresolver.h" |
30 | | #include "gtask.h" |
31 | | |
32 | | #include "giomodule.h" |
33 | | #include "giomodule-priv.h" |
34 | | |
35 | | struct _GDummyProxyResolver { |
36 | | GObject parent_instance; |
37 | | }; |
38 | | |
39 | | static void g_dummy_proxy_resolver_iface_init (GProxyResolverInterface *iface); |
40 | | |
41 | | #define g_dummy_proxy_resolver_get_type _g_dummy_proxy_resolver_get_type |
42 | | G_DEFINE_TYPE_WITH_CODE (GDummyProxyResolver, g_dummy_proxy_resolver, G_TYPE_OBJECT, |
43 | | G_IMPLEMENT_INTERFACE (G_TYPE_PROXY_RESOLVER, |
44 | | g_dummy_proxy_resolver_iface_init) |
45 | | _g_io_modules_ensure_extension_points_registered (); |
46 | | g_io_extension_point_implement (G_PROXY_RESOLVER_EXTENSION_POINT_NAME, |
47 | | g_define_type_id, |
48 | | "dummy", |
49 | | -100)) |
50 | | |
51 | | static void |
52 | | g_dummy_proxy_resolver_finalize (GObject *object) |
53 | 0 | { |
54 | | /* must chain up */ |
55 | 0 | G_OBJECT_CLASS (g_dummy_proxy_resolver_parent_class)->finalize (object); |
56 | 0 | } |
57 | | |
58 | | static void |
59 | | g_dummy_proxy_resolver_init (GDummyProxyResolver *resolver) |
60 | 0 | { |
61 | 0 | } |
62 | | |
63 | | static gboolean |
64 | | g_dummy_proxy_resolver_is_supported (GProxyResolver *resolver) |
65 | 0 | { |
66 | 0 | return TRUE; |
67 | 0 | } |
68 | | |
69 | | static gchar ** |
70 | | g_dummy_proxy_resolver_lookup (GProxyResolver *resolver, |
71 | | const gchar *uri, |
72 | | GCancellable *cancellable, |
73 | | GError **error) |
74 | 0 | { |
75 | 0 | gchar **proxies; |
76 | |
|
77 | 0 | if (g_cancellable_set_error_if_cancelled (cancellable, error)) |
78 | 0 | return NULL; |
79 | | |
80 | 0 | proxies = g_new0 (gchar *, 2); |
81 | 0 | proxies[0] = g_strdup ("direct://"); |
82 | |
|
83 | 0 | return proxies; |
84 | 0 | } |
85 | | |
86 | | static void |
87 | | g_dummy_proxy_resolver_lookup_async (GProxyResolver *resolver, |
88 | | const gchar *uri, |
89 | | GCancellable *cancellable, |
90 | | GAsyncReadyCallback callback, |
91 | | gpointer user_data) |
92 | 0 | { |
93 | 0 | GError *error = NULL; |
94 | 0 | GTask *task; |
95 | 0 | gchar **proxies; |
96 | |
|
97 | 0 | task = g_task_new (resolver, cancellable, callback, user_data); |
98 | 0 | g_task_set_source_tag (task, g_dummy_proxy_resolver_lookup_async); |
99 | |
|
100 | 0 | proxies = g_dummy_proxy_resolver_lookup (resolver, uri, cancellable, &error); |
101 | 0 | if (proxies) |
102 | 0 | g_task_return_pointer (task, proxies, (GDestroyNotify) g_strfreev); |
103 | 0 | else |
104 | 0 | g_task_return_error (task, error); |
105 | 0 | g_object_unref (task); |
106 | 0 | } |
107 | | |
108 | | static gchar ** |
109 | | g_dummy_proxy_resolver_lookup_finish (GProxyResolver *resolver, |
110 | | GAsyncResult *result, |
111 | | GError **error) |
112 | 0 | { |
113 | 0 | g_return_val_if_fail (g_task_is_valid (result, resolver), NULL); |
114 | | |
115 | 0 | return g_task_propagate_pointer (G_TASK (result), error); |
116 | 0 | } |
117 | | |
118 | | static void |
119 | | g_dummy_proxy_resolver_class_init (GDummyProxyResolverClass *resolver_class) |
120 | 0 | { |
121 | 0 | GObjectClass *object_class; |
122 | | |
123 | 0 | object_class = G_OBJECT_CLASS (resolver_class); |
124 | 0 | object_class->finalize = g_dummy_proxy_resolver_finalize; |
125 | 0 | } |
126 | | |
127 | | static void |
128 | | g_dummy_proxy_resolver_iface_init (GProxyResolverInterface *iface) |
129 | 0 | { |
130 | 0 | iface->is_supported = g_dummy_proxy_resolver_is_supported; |
131 | 0 | iface->lookup = g_dummy_proxy_resolver_lookup; |
132 | 0 | iface->lookup_async = g_dummy_proxy_resolver_lookup_async; |
133 | 0 | iface->lookup_finish = g_dummy_proxy_resolver_lookup_finish; |
134 | 0 | } |