comparison libpurple/dnssrv.h @ 31426:08dcd2d4f0b7

Added PurpleSrvTxtQueryUiOps which allow UIs to specify their own mechanisms to resolve SRV and/or TXT queries. Additionally, some functions and datatypes have been renamed to show which are SRV only, which TXT only, and which are used by both.
author thijsalkemade@gmail.com
date Thu, 24 Mar 2011 23:22:29 +0000
parents 63cb8c4f3c66
children 0eceb1304f53 3448f64d197c
comparison
equal deleted inserted replaced
31409:5043fc53f957 31426:08dcd2d4f0b7
26 26
27 #ifdef __cplusplus 27 #ifdef __cplusplus
28 extern "C" { 28 extern "C" {
29 #endif 29 #endif
30 30
31 typedef struct _PurpleSrvQueryData PurpleSrvQueryData; 31 typedef struct _PurpleSrvTxtQueryData PurpleSrvTxtQueryData;
32 typedef struct _PurpleSrvResponse PurpleSrvResponse; 32 typedef struct _PurpleSrvResponse PurpleSrvResponse;
33 typedef struct _PurpleTxtResponse PurpleTxtResponse; 33 typedef struct _PurpleTxtResponse PurpleTxtResponse;
34 34
35 /* For compatibility, should be removed for 3.0.0
36 */
37 typedef struct _PurpleSrvTxtQueryData PurpleSrvQueryData;
38
35 #include <glib.h> 39 #include <glib.h>
40
41 enum PurpleDnsType {
42 PurpleDnsTypeTxt = 16,
43 PurpleDnsTypeSrv = 33
44 };
36 45
37 struct _PurpleSrvResponse { 46 struct _PurpleSrvResponse {
38 char hostname[256]; 47 char hostname[256];
39 int port; 48 int port;
40 int weight; 49 int weight;
41 int pref; 50 int pref;
42 }; 51 };
43 52
53 struct _PurpleTxtResponse {
54 char *content;
55 };
56
57 typedef void (*PurpleSrvTxtQueryResolvedCallback) (PurpleSrvTxtQueryData *query_data, GList *records);
58 typedef void (*PurpleSrvTxtQueryFailedCallback) (PurpleSrvTxtQueryData *query_data, const gchar *error_message);
59
60 /**
61 * SRV Request UI operations; UIs should implement this if they want to do SRV
62 * lookups themselves, rather than relying on the core.
63 *
64 * @see @ref ui-ops
65 */
66 typedef struct
67 {
68 /** If implemented, return TRUE if the UI takes responsibility for SRV
69 * queries. When returning FALSE, the standard implementation is used.
70 * These callbacks MUST be called asynchronously. */
71 gboolean (*resolve)(PurpleSrvTxtQueryData *query_data,
72 PurpleSrvTxtQueryResolvedCallback resolved_cb,
73 PurpleSrvTxtQueryFailedCallback failed_cb);
74
75 /** Called just before @a query_data is freed; this should cancel any
76 * further use of @a query_data the UI would make. Unneeded if
77 * #resolve_host is not implemented.
78 */
79 void (*destroy)(PurpleSrvTxtQueryData *query_data);
80
81 void (*_purple_reserved1)(void);
82 void (*_purple_reserved2)(void);
83 void (*_purple_reserved3)(void);
84 void (*_purple_reserved4)(void);
85 } PurpleSrvTxtQueryUiOps;
86
44 /** 87 /**
45 * @param resp An array of PurpleSrvResponse of size results. The array 88 * @param resp An array of PurpleSrvResponse of size results. The array
46 * is sorted based on the order described in the DNS SRV RFC. 89 * is sorted based on the order described in the DNS SRV RFC.
47 * Users of this API should try each record in resp in order, 90 * Users of this API should try each record in resp in order,
48 * starting at the beginning. 91 * starting at the beginning.
64 * @param transport Name of the transport ("tcp" or "udp") 107 * @param transport Name of the transport ("tcp" or "udp")
65 * @param domain Domain name to query (e.g. "blubb.com") 108 * @param domain Domain name to query (e.g. "blubb.com")
66 * @param cb A callback which will be called with the results 109 * @param cb A callback which will be called with the results
67 * @param extradata Extra data to be passed to the callback 110 * @param extradata Extra data to be passed to the callback
68 */ 111 */
69 PurpleSrvQueryData *purple_srv_resolve(const char *protocol, const char *transport, const char *domain, PurpleSrvCallback cb, gpointer extradata); 112 PurpleSrvTxtQueryData *purple_srv_resolve(const char *protocol, const char *transport, const char *domain, PurpleSrvCallback cb, gpointer extradata);
70 113
71 /** 114 /**
72 * Cancel an SRV DNS query. 115 * Cancel an SRV or DNS query.
73 * 116 *
74 * @param query_data The request to cancel. 117 * @param query_data The request to cancel.
75 */ 118 */
76 void purple_srv_cancel(PurpleSrvQueryData *query_data); 119 void purple_srv_cancel(PurpleSrvTxtQueryData *query_data);
77 120
78 /** 121 /**
79 * Queries an TXT record. 122 * Queries an TXT record.
80 * 123 *
81 * @param owner Name of the protocol (e.g. "_xmppconnect") 124 * @param owner Name of the protocol (e.g. "_xmppconnect")
83 * @param cb A callback which will be called with the results 126 * @param cb A callback which will be called with the results
84 * @param extradata Extra data to be passed to the callback 127 * @param extradata Extra data to be passed to the callback
85 * 128 *
86 * @since 2.6.0 129 * @since 2.6.0
87 */ 130 */
88 PurpleSrvQueryData *purple_txt_resolve(const char *owner, const char *domain, PurpleTxtCallback cb, gpointer extradata); 131 PurpleSrvTxtQueryData *purple_txt_resolve(const char *owner, const char *domain, PurpleTxtCallback cb, gpointer extradata);
89 132
90 /** 133 /**
91 * Cancel an TXT DNS query. 134 * Cancel an TXT DNS query.
92 * 135 *
93 * @param query_data The request to cancel. 136 * @param query_data The request to cancel.
94 * @since 2.6.0 137 * @since 2.6.0
95 */ 138 */
96 void purple_txt_cancel(PurpleSrvQueryData *query_data); 139 void purple_txt_cancel(PurpleSrvTxtQueryData *query_data);
97 140
98 /** 141 /**
99 * Get the value of the current TXT record. 142 * Get the value of the current TXT record.
100 * 143 *
101 * @param response The TXT response record 144 * @param response The TXT response record
109 * 152 *
110 * @param response The PurpleTxtResponse to destroy. 153 * @param response The PurpleTxtResponse to destroy.
111 * @since 2.6.0 154 * @since 2.6.0
112 */ 155 */
113 void purple_txt_response_destroy(PurpleTxtResponse *response); 156 void purple_txt_response_destroy(PurpleTxtResponse *response);
157
158 /**
159 * Cancel a SRV/TXT query and destroy the associated data structure.
160 *
161 * @param query_data The SRV/TXT query to cancel. This data structure
162 * is freed by this function.
163 */
164 void purple_srv_txt_query_destroy(PurpleSrvTxtQueryData *query_data);
165
166 /**
167 * Sets the UI operations structure to be used when doing a SRV/TXT
168 * resolve. The UI operations need only be set if the UI wants to
169 * handle the resolve itself; otherwise, leave it as NULL.
170 *
171 * @param ops The UI operations structure.
172 */
173 void purple_srv_txt_query_set_ui_ops(PurpleSrvTxtQueryUiOps *ops);
174
175 /**
176 * Returns the UI operations structure to be used when doing a SRV/TXT
177 * resolve.
178 *
179 * @return The UI operations structure.
180 */
181 PurpleSrvTxtQueryUiOps *purple_srv_txt_query_get_ui_ops(void);
182
183 /**
184 * Get the query from a PurpleDnsQueryData
185 *
186 * @param query_data The SRV/TXT query
187 * @return The query.
188 */
189 char *purple_srv_txt_query_get_query(PurpleSrvTxtQueryData *query_data);
190
191 /**
192 * Get the type from a PurpleDnsQueryData (TXT or SRV)
193 *
194 * @param query_data The query
195 * @return The query.
196 */
197 int purple_srv_txt_query_get_type(PurpleSrvTxtQueryData *query_data);
114 198
115 #ifdef __cplusplus 199 #ifdef __cplusplus
116 } 200 }
117 #endif 201 #endif
118 202