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