applied changes from fb4435d514398a0b1febebe8bf46339e2c2b52b6
[pidgin-git.git] / libpurple / dnsquery.h
blobdde19983f6bdcbf3dadc975c1ca306916df69c49
1 /**
2 * @file dnsquery.h DNS query API
3 * @ingroup core
4 */
6 /* purple
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_
29 #include <glib.h>
30 #include "eventloop.h"
31 #include "account.h"
33 /**
34 * An opaque structure representing a DNS query. The hostname and port
35 * associated with the query can be retrieved using
36 * purple_dnsquery_get_host() and purple_dnsquery_get_port().
38 typedef struct _PurpleDnsQueryData PurpleDnsQueryData;
40 /**
41 * The "hosts" parameter is a linked list containing pairs of
42 * one size_t addrlen and one struct sockaddr *addr. It should
43 * be free'd by the callback function.
45 typedef void (*PurpleDnsQueryConnectFunction)(GSList *hosts, gpointer data, const char *error_message);
47 /**
48 * Callbacks used by the UI if it handles resolving DNS
50 typedef void (*PurpleDnsQueryResolvedCallback) (PurpleDnsQueryData *query_data, GSList *hosts);
51 typedef void (*PurpleDnsQueryFailedCallback) (PurpleDnsQueryData *query_data, const gchar *error_message);
53 /**
54 * DNS Request UI operations; UIs should implement this if they want to do DNS
55 * lookups themselves, rather than relying on the core.
57 * @see @ref ui-ops
59 typedef struct
61 /** If implemented, return TRUE if the UI takes responsibility for DNS
62 * queries. When returning FALSE, the standard implementation is used. */
63 gboolean (*resolve_host)(PurpleDnsQueryData *query_data,
64 PurpleDnsQueryResolvedCallback resolved_cb,
65 PurpleDnsQueryFailedCallback failed_cb);
67 /** Called just before @a query_data is freed; this should cancel any
68 * further use of @a query_data the UI would make. Unneeded if
69 * #resolve_host is not implemented.
71 void (*destroy)(PurpleDnsQueryData *query_data);
73 void (*_purple_reserved1)(void);
74 void (*_purple_reserved2)(void);
75 void (*_purple_reserved3)(void);
76 void (*_purple_reserved4)(void);
77 } PurpleDnsQueryUiOps;
79 #ifdef __cplusplus
80 extern "C" {
81 #endif
83 /**************************************************************************/
84 /** @name DNS query API */
85 /**************************************************************************/
86 /*@{*/
88 /**
89 * Perform an asynchronous DNS query.
91 * @param account the account that the query is being done for (or NULL)
92 * @param hostname The hostname to resolve.
93 * @param port A port number which is stored in the struct sockaddr.
94 * @param callback The callback function to call after resolving.
95 * @param data Extra data to pass to the callback function.
97 * @return NULL if there was an error, otherwise return a reference to
98 * a data structure that can be used to cancel the pending
99 * DNS query, if needed.
101 * @since 2.8.0
103 PurpleDnsQueryData *purple_dnsquery_a_account(PurpleAccount *account, const char *hostname, int port, PurpleDnsQueryConnectFunction callback, gpointer data);
105 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_DNSQUERY_C_)
107 * Perform an asynchronous DNS query.
109 * @param hostname The hostname to resolve.
110 * @param port A port number which is stored in the struct sockaddr.
111 * @param callback The callback function to call after resolving.
112 * @param data Extra data to pass to the callback function.
114 * @return NULL if there was an error, otherwise return a reference to
115 * a data structure that can be used to cancel the pending
116 * DNS query, if needed.
118 * @deprecated Use purple_dnsquery_a_account instead
120 PurpleDnsQueryData *purple_dnsquery_a(const char *hostname, int port, PurpleDnsQueryConnectFunction callback, gpointer data);
121 #endif
124 * Cancel a DNS query and destroy the associated data structure.
126 * @param query_data The DNS query to cancel. This data structure
127 * is freed by this function.
129 void purple_dnsquery_destroy(PurpleDnsQueryData *query_data);
132 * Sets the UI operations structure to be used when doing a DNS
133 * resolve. The UI operations need only be set if the UI wants to
134 * handle the resolve itself; otherwise, leave it as NULL.
136 * @param ops The UI operations structure.
138 void purple_dnsquery_set_ui_ops(PurpleDnsQueryUiOps *ops);
141 * Returns the UI operations structure to be used when doing a DNS
142 * resolve.
144 * @return The UI operations structure.
146 PurpleDnsQueryUiOps *purple_dnsquery_get_ui_ops(void);
149 * Get the host associated with a PurpleDnsQueryData
151 * @param query_data The DNS query
152 * @return The host.
154 char *purple_dnsquery_get_host(PurpleDnsQueryData *query_data);
157 * Get the port associated with a PurpleDnsQueryData
159 * @param query_data The DNS query
160 * @return The port.
162 unsigned short purple_dnsquery_get_port(PurpleDnsQueryData *query_data);
165 * Initializes the DNS query subsystem.
167 void purple_dnsquery_init(void);
170 * Uninitializes the DNS query subsystem.
172 void purple_dnsquery_uninit(void);
174 /*@}*/
176 #ifdef __cplusplus
178 #endif
180 #endif /* _PURPLE_DNSQUERY_H_ */