2 * @file dnsquery.h DNS query API
8 * Purple is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 #ifndef _PURPLE_DNSQUERY_H_
27 #define _PURPLE_DNSQUERY_H_
30 #include "eventloop.h"
33 typedef struct _PurpleDnsQueryData PurpleDnsQueryData;
36 * The "hosts" parameter is a linked list containing pairs of
37 * one size_t addrlen and one struct sockaddr *addr. It should
38 * be free'd by the callback function.
40 typedef void (*PurpleDnsQueryConnectFunction)(GSList *hosts, gpointer data, const char *error_message);
43 * Callbacks used by the UI if it handles resolving DNS
45 typedef void (*PurpleDnsQueryResolvedCallback) (PurpleDnsQueryData *query_data, GSList *hosts);
46 typedef void (*PurpleDnsQueryFailedCallback) (PurpleDnsQueryData *query_data, const gchar *error_message);
49 * DNS Request UI operations; UIs should implement this if they want to do DNS
50 * lookups themselves, rather than relying on the core.
56 /** If implemented, the UI is responsible for DNS queries */
57 gboolean (*resolve_host)(PurpleDnsQueryData *query_data,
58 PurpleDnsQueryResolvedCallback resolved_cb,
59 PurpleDnsQueryFailedCallback failed_cb);
61 /** Called just before @a query_data is freed; this should cancel any
62 * further use of @a query_data the UI would make. Unneeded if
63 * #resolve_host is not implemented.
65 void (*destroy)(PurpleDnsQueryData *query_data);
67 void (*_purple_reserved1)(void);
68 void (*_purple_reserved2)(void);
69 void (*_purple_reserved3)(void);
70 void (*_purple_reserved4)(void);
71 } PurpleDnsQueryUiOps;
77 /**************************************************************************/
78 /** @name DNS query API */
79 /**************************************************************************/
83 * Perform an asynchronous DNS query.
85 * @param hostname The hostname to resolve.
86 * @param port A port number which is stored in the struct sockaddr.
87 * @param callback The callback function to call after resolving.
88 * @param data Extra data to pass to the callback function.
90 * @return NULL if there was an error, otherwise return a reference to
91 * a data structure that can be used to cancel the pending
92 * DNS query, if needed.
94 PurpleDnsQueryData *purple_dnsquery_a(const char *hostname, int port, PurpleDnsQueryConnectFunction callback, gpointer data);
97 * Cancel a DNS query and destroy the associated data structure.
99 * @param query_data The DNS query to cancel. This data structure
100 * is freed by this function.
102 void purple_dnsquery_destroy(PurpleDnsQueryData *query_data);
105 * Sets the UI operations structure to be used when doing a DNS
106 * resolve. The UI operations need only be set if the UI wants to
107 * handle the resolve itself; otherwise, leave it as NULL.
109 * @param ops The UI operations structure.
111 void purple_dnsquery_set_ui_ops(PurpleDnsQueryUiOps *ops);
114 * Returns the UI operations structure to be used when doing a DNS
117 * @return The UI operations structure.
119 PurpleDnsQueryUiOps *purple_dnsquery_get_ui_ops(void);
122 * Get the host associated with a PurpleDnsQueryData
124 * @param query_data The DNS query
127 char *purple_dnsquery_get_host(PurpleDnsQueryData *query_data);
130 * Get the port associated with a PurpleDnsQueryData
132 * @param query_data The DNS query
135 unsigned short purple_dnsquery_get_port(PurpleDnsQueryData *query_data);
138 * Initializes the DNS query subsystem.
140 void purple_dnsquery_init(void);
143 * Uninitializes the DNS query subsystem.
145 void purple_dnsquery_uninit(void);
153 #endif /* _PURPLE_DNSQUERY_H_ */