1 | /* GIO - GLib Input, Output and Streaming Library |
2 | * |
3 | * Copyright (C) 2008 Red Hat, Inc. |
4 | * Copyright (C) 2018 Igalia S.L. |
5 | * |
6 | * SPDX-License-Identifier: LGPL-2.1-or-later |
7 | * |
8 | * This library is free software; you can redistribute it and/or |
9 | * modify it under the terms of the GNU Lesser General Public |
10 | * License as published by the Free Software Foundation; either |
11 | * version 2.1 of the License, or (at your option) any later version. |
12 | * |
13 | * This library is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | * Lesser General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU Lesser General |
19 | * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. |
20 | */ |
21 | |
22 | #ifndef __G_RESOLVER_H__ |
23 | #define __G_RESOLVER_H__ |
24 | |
25 | #if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION) |
26 | #error "Only <gio/gio.h> can be included directly." |
27 | #endif |
28 | |
29 | #include <gio/giotypes.h> |
30 | |
31 | G_BEGIN_DECLS |
32 | |
33 | #define G_TYPE_RESOLVER (g_resolver_get_type ()) |
34 | #define G_RESOLVER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_RESOLVER, GResolver)) |
35 | #define G_RESOLVER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_RESOLVER, GResolverClass)) |
36 | #define G_IS_RESOLVER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_RESOLVER)) |
37 | #define G_IS_RESOLVER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_RESOLVER)) |
38 | #define G_RESOLVER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_RESOLVER, GResolverClass)) |
39 | |
40 | typedef struct _GResolverPrivate GResolverPrivate; |
41 | typedef struct _GResolverClass GResolverClass; |
42 | |
43 | struct _GResolver { |
44 | GObject parent_instance; |
45 | |
46 | GResolverPrivate *priv; |
47 | }; |
48 | |
49 | /** |
50 | * GResolverNameLookupFlags: |
51 | * @G_RESOLVER_NAME_LOOKUP_FLAGS_DEFAULT: default behavior (same as g_resolver_lookup_by_name()) |
52 | * @G_RESOLVER_NAME_LOOKUP_FLAGS_IPV4_ONLY: only resolve ipv4 addresses |
53 | * @G_RESOLVER_NAME_LOOKUP_FLAGS_IPV6_ONLY: only resolve ipv6 addresses |
54 | * |
55 | * Flags to modify lookup behavior. |
56 | * |
57 | * Since: 2.60 |
58 | */ |
59 | typedef enum { |
60 | G_RESOLVER_NAME_LOOKUP_FLAGS_DEFAULT = 0, |
61 | G_RESOLVER_NAME_LOOKUP_FLAGS_IPV4_ONLY = 1 << 0, |
62 | G_RESOLVER_NAME_LOOKUP_FLAGS_IPV6_ONLY = 1 << 1, |
63 | } GResolverNameLookupFlags; |
64 | |
65 | struct _GResolverClass { |
66 | GObjectClass parent_class; |
67 | |
68 | /* Signals */ |
69 | void ( *reload) (GResolver *resolver); |
70 | |
71 | /* Virtual methods */ |
72 | GList * ( *lookup_by_name) (GResolver *resolver, |
73 | const gchar *hostname, |
74 | GCancellable *cancellable, |
75 | GError **error); |
76 | void ( *lookup_by_name_async) (GResolver *resolver, |
77 | const gchar *hostname, |
78 | GCancellable *cancellable, |
79 | GAsyncReadyCallback callback, |
80 | gpointer user_data); |
81 | GList * ( *lookup_by_name_finish) (GResolver *resolver, |
82 | GAsyncResult *result, |
83 | GError **error); |
84 | |
85 | gchar * ( *lookup_by_address) (GResolver *resolver, |
86 | GInetAddress *address, |
87 | GCancellable *cancellable, |
88 | GError **error); |
89 | void ( *lookup_by_address_async) (GResolver *resolver, |
90 | GInetAddress *address, |
91 | GCancellable *cancellable, |
92 | GAsyncReadyCallback callback, |
93 | gpointer user_data); |
94 | gchar * ( *lookup_by_address_finish) (GResolver *resolver, |
95 | GAsyncResult *result, |
96 | GError **error); |
97 | |
98 | GList * ( *lookup_service) (GResolver *resolver, |
99 | const gchar *rrname, |
100 | GCancellable *cancellable, |
101 | GError **error); |
102 | void ( *lookup_service_async) (GResolver *resolver, |
103 | const gchar *rrname, |
104 | GCancellable *cancellable, |
105 | GAsyncReadyCallback callback, |
106 | gpointer user_data); |
107 | GList * ( *lookup_service_finish) (GResolver *resolver, |
108 | GAsyncResult *result, |
109 | GError **error); |
110 | |
111 | GList * ( *lookup_records) (GResolver *resolver, |
112 | const gchar *rrname, |
113 | GResolverRecordType record_type, |
114 | GCancellable *cancellable, |
115 | GError **error); |
116 | |
117 | void ( *lookup_records_async) (GResolver *resolver, |
118 | const gchar *rrname, |
119 | GResolverRecordType record_type, |
120 | GCancellable *cancellable, |
121 | GAsyncReadyCallback callback, |
122 | gpointer user_data); |
123 | |
124 | GList * ( *lookup_records_finish) (GResolver *resolver, |
125 | GAsyncResult *result, |
126 | GError **error); |
127 | /** |
128 | * GResolverClass::lookup_by_name_with_flags_async: |
129 | * @resolver: a #GResolver |
130 | * @hostname: the hostname to resolve |
131 | * @flags: extra #GResolverNameLookupFlags to modify the lookup |
132 | * @cancellable: (nullable): a #GCancellable |
133 | * @callback: (scope async): a #GAsyncReadyCallback to call when completed |
134 | * @user_data: data to pass to @callback |
135 | * |
136 | * Asynchronous version of GResolverClass::lookup_by_name_with_flags |
137 | * |
138 | * GResolverClass::lookup_by_name_with_flags_finish will be called to get |
139 | * the result. |
140 | * |
141 | * Since: 2.60 |
142 | */ |
143 | void ( *lookup_by_name_with_flags_async) (GResolver *resolver, |
144 | const gchar *hostname, |
145 | GResolverNameLookupFlags flags, |
146 | GCancellable *cancellable, |
147 | GAsyncReadyCallback callback, |
148 | gpointer user_data); |
149 | /** |
150 | * GResolverClass::lookup_by_name_with_flags_finish: |
151 | * @resolver: a #GResolver |
152 | * @result: a #GAsyncResult |
153 | * @error: (nullable): a pointer to a %NULL #GError |
154 | * |
155 | * Gets the result from GResolverClass::lookup_by_name_with_flags_async |
156 | * |
157 | * Returns: (element-type GInetAddress) (transfer full): List of #GInetAddress. |
158 | * Since: 2.60 |
159 | */ |
160 | GList * ( *lookup_by_name_with_flags_finish) (GResolver *resolver, |
161 | GAsyncResult *result, |
162 | GError **error); |
163 | /** |
164 | * GResolverClass::lookup_by_name_with_flags: |
165 | * @resolver: a #GResolver |
166 | * @hostname: the hostname to resolve |
167 | * @flags: extra #GResolverNameLookupFlags to modify the lookup |
168 | * @cancellable: (nullable): a #GCancellable |
169 | * @error: (nullable): a pointer to a %NULL #GError |
170 | * |
171 | * This is identical to GResolverClass::lookup_by_name except it takes |
172 | * @flags which modifies the behavior of the lookup. See #GResolverNameLookupFlags |
173 | * for more details. |
174 | * |
175 | * Returns: (element-type GInetAddress) (transfer full): List of #GInetAddress. |
176 | * Since: 2.60 |
177 | */ |
178 | GList * ( *lookup_by_name_with_flags) (GResolver *resolver, |
179 | const gchar *hostname, |
180 | GResolverNameLookupFlags flags, |
181 | GCancellable *cancellable, |
182 | GError **error); |
183 | |
184 | }; |
185 | |
186 | GIO_AVAILABLE_IN_ALL |
187 | GType g_resolver_get_type (void) G_GNUC_CONST; |
188 | GIO_AVAILABLE_IN_ALL |
189 | GResolver *g_resolver_get_default (void); |
190 | GIO_AVAILABLE_IN_ALL |
191 | void g_resolver_set_default (GResolver *resolver); |
192 | GIO_AVAILABLE_IN_ALL |
193 | GList *g_resolver_lookup_by_name (GResolver *resolver, |
194 | const gchar *hostname, |
195 | GCancellable *cancellable, |
196 | GError **error); |
197 | GIO_AVAILABLE_IN_ALL |
198 | void g_resolver_lookup_by_name_async (GResolver *resolver, |
199 | const gchar *hostname, |
200 | GCancellable *cancellable, |
201 | GAsyncReadyCallback callback, |
202 | gpointer user_data); |
203 | GIO_AVAILABLE_IN_ALL |
204 | GList *g_resolver_lookup_by_name_finish (GResolver *resolver, |
205 | GAsyncResult *result, |
206 | GError **error); |
207 | GIO_AVAILABLE_IN_2_60 |
208 | void g_resolver_lookup_by_name_with_flags_async (GResolver *resolver, |
209 | const gchar *hostname, |
210 | GResolverNameLookupFlags flags, |
211 | GCancellable *cancellable, |
212 | GAsyncReadyCallback callback, |
213 | gpointer user_data); |
214 | GIO_AVAILABLE_IN_2_60 |
215 | GList *g_resolver_lookup_by_name_with_flags_finish (GResolver *resolver, |
216 | GAsyncResult *result, |
217 | GError **error); |
218 | GIO_AVAILABLE_IN_2_60 |
219 | GList *g_resolver_lookup_by_name_with_flags (GResolver *resolver, |
220 | const gchar *hostname, |
221 | GResolverNameLookupFlags flags, |
222 | GCancellable *cancellable, |
223 | GError **error); |
224 | GIO_AVAILABLE_IN_ALL |
225 | void g_resolver_free_addresses (GList *addresses); |
226 | GIO_AVAILABLE_IN_ALL |
227 | gchar *g_resolver_lookup_by_address (GResolver *resolver, |
228 | GInetAddress *address, |
229 | GCancellable *cancellable, |
230 | GError **error); |
231 | GIO_AVAILABLE_IN_ALL |
232 | void g_resolver_lookup_by_address_async (GResolver *resolver, |
233 | GInetAddress *address, |
234 | GCancellable *cancellable, |
235 | GAsyncReadyCallback callback, |
236 | gpointer user_data); |
237 | GIO_AVAILABLE_IN_ALL |
238 | gchar *g_resolver_lookup_by_address_finish (GResolver *resolver, |
239 | GAsyncResult *result, |
240 | GError **error); |
241 | GIO_AVAILABLE_IN_ALL |
242 | GList *g_resolver_lookup_service (GResolver *resolver, |
243 | const gchar *service, |
244 | const gchar *protocol, |
245 | const gchar *domain, |
246 | GCancellable *cancellable, |
247 | GError **error); |
248 | GIO_AVAILABLE_IN_ALL |
249 | void g_resolver_lookup_service_async (GResolver *resolver, |
250 | const gchar *service, |
251 | const gchar *protocol, |
252 | const gchar *domain, |
253 | GCancellable *cancellable, |
254 | GAsyncReadyCallback callback, |
255 | gpointer user_data); |
256 | GIO_AVAILABLE_IN_ALL |
257 | GList *g_resolver_lookup_service_finish (GResolver *resolver, |
258 | GAsyncResult *result, |
259 | GError **error); |
260 | GIO_AVAILABLE_IN_2_34 |
261 | GList *g_resolver_lookup_records (GResolver *resolver, |
262 | const gchar *rrname, |
263 | GResolverRecordType record_type, |
264 | GCancellable *cancellable, |
265 | GError **error); |
266 | GIO_AVAILABLE_IN_2_34 |
267 | void g_resolver_lookup_records_async (GResolver *resolver, |
268 | const gchar *rrname, |
269 | GResolverRecordType record_type, |
270 | GCancellable *cancellable, |
271 | GAsyncReadyCallback callback, |
272 | gpointer user_data); |
273 | GIO_AVAILABLE_IN_2_34 |
274 | GList *g_resolver_lookup_records_finish (GResolver *resolver, |
275 | GAsyncResult *result, |
276 | GError **error); |
277 | GIO_AVAILABLE_IN_ALL |
278 | void g_resolver_free_targets (GList *targets); |
279 | |
280 | GIO_AVAILABLE_IN_2_78 |
281 | unsigned g_resolver_get_timeout (GResolver *resolver); |
282 | GIO_AVAILABLE_IN_2_78 |
283 | void g_resolver_set_timeout (GResolver *resolver, |
284 | unsigned timeout_ms); |
285 | |
286 | /** |
287 | * G_RESOLVER_ERROR: |
288 | * |
289 | * Error domain for #GResolver. Errors in this domain will be from the |
290 | * #GResolverError enumeration. See #GError for more information on |
291 | * error domains. |
292 | */ |
293 | #define G_RESOLVER_ERROR (g_resolver_error_quark ()) |
294 | GIO_AVAILABLE_IN_ALL |
295 | GQuark g_resolver_error_quark (void); |
296 | |
297 | G_END_DECLS |
298 | |
299 | #endif /* __G_RESOLVER_H__ */ |
300 | |