pidgin: 545dd338: Add new DNS-related API to perform looku...
datallah at pidgin.im
datallah at pidgin.im
Tue Apr 19 01:12:13 EDT 2011
----------------------------------------------------------------------
Revision: 545dd3386c0c8b1556984514b859317f7ec392d8
Parent: f9ed9968030c167eb2a7d562c69b04efbe00ca5d
Author: datallah at pidgin.im
Date: 04/19/11 00:58:17
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/545dd3386c0c8b1556984514b859317f7ec392d8
Changelog:
Add new DNS-related API to perform lookups in the context of an account.
Combined with the new "Tor/Privacy" proxy setting, this allows us to prevent
DNS lookups when the user has selected a proxy that they may want to use to
for privacy.
Refs #11110
Changes against parent f9ed9968030c167eb2a7d562c69b04efbe00ca5d
patched libpurple/dnsquery.c
patched libpurple/dnsquery.h
patched libpurple/dnssrv.c
patched libpurple/dnssrv.h
patched libpurple/proxy.c
patched libpurple/proxy.h
-------------- next part --------------
============================================================
--- libpurple/proxy.c cd7f69a4fa40b265b853aeb94236d26868994e4d
+++ libpurple/proxy.c dd9485fbf7910ffe950e667772da2f6ba8b627cb
@@ -69,6 +69,7 @@ struct _PurpleProxyConnectData {
guchar *read_buffer;
gsize read_buf_len;
gsize read_len;
+ PurpleAccount *account;
};
static const char * const socks5errors[] = {
@@ -1367,7 +1368,8 @@ s4_canwrite(gpointer data, gint source,
proxy_do_write(connect_data, connect_data->fd, PURPLE_INPUT_WRITE);
} else {
- connect_data->query_data = purple_dnsquery_a(connect_data->host,
+ connect_data->query_data = purple_dnsquery_a_account(
+ connect_data->account, connect_data->host,
connect_data->port, s4_host_resolved, connect_data);
if (connect_data->query_data == NULL) {
@@ -2282,6 +2284,7 @@ purple_proxy_connect(void *handle, Purpl
connect_data->host = g_strdup(host);
connect_data->port = port;
connect_data->gpi = purple_proxy_get_setup(account);
+ connect_data->account = account;
if ((purple_proxy_info_get_type(connect_data->gpi) != PURPLE_PROXY_NONE) &&
(purple_proxy_info_get_host(connect_data->gpi) == NULL ||
@@ -2313,7 +2316,7 @@ purple_proxy_connect(void *handle, Purpl
return NULL;
}
- connect_data->query_data = purple_dnsquery_a(connecthost,
+ connect_data->query_data = purple_dnsquery_a_account(account, connecthost,
connectport, connection_host_resolved, connect_data);
if (connect_data->query_data == NULL)
{
@@ -2349,6 +2352,7 @@ purple_proxy_connect_udp(void *handle, P
connect_data->host = g_strdup(host);
connect_data->port = port;
connect_data->gpi = purple_proxy_get_setup(account);
+ connect_data->account = account;
if ((purple_proxy_info_get_type(connect_data->gpi) != PURPLE_PROXY_NONE) &&
(purple_proxy_info_get_host(connect_data->gpi) == NULL ||
@@ -2380,7 +2384,7 @@ purple_proxy_connect_udp(void *handle, P
return NULL;
}
- connect_data->query_data = purple_dnsquery_a(connecthost,
+ connect_data->query_data = purple_dnsquery_a_account(account, connecthost,
connectport, connection_host_resolved, connect_data);
if (connect_data->query_data == NULL)
{
@@ -2402,6 +2406,19 @@ purple_proxy_connect_socks5(void *handle
PurpleProxyConnectFunction connect_cb,
gpointer data)
{
+ return purple_proxy_connect_socks5_account(NULL, handle, gpi,
+ host, port, connect_cb, data);
+}
+/*
+ * Combine some of this code with purple_proxy_connect()
+ */
+PurpleProxyConnectData *
+purple_proxy_connect_socks5_account(void *handle, PurpleAccount *account,
+ PurpleProxyInfo *gpi,
+ const char *host, int port,
+ PurpleProxyConnectFunction connect_cb,
+ gpointer data)
+{
PurpleProxyConnectData *connect_data;
g_return_val_if_fail(host != NULL, NULL);
@@ -2417,9 +2434,11 @@ purple_proxy_connect_socks5(void *handle
connect_data->host = g_strdup(host);
connect_data->port = port;
connect_data->gpi = gpi;
+ connect_data->account = account;
connect_data->query_data =
- purple_dnsquery_a(purple_proxy_info_get_host(gpi),
+ purple_dnsquery_a_account(account,
+ purple_proxy_info_get_host(gpi),
purple_proxy_info_get_port(gpi),
connection_host_resolved, connect_data);
if (connect_data->query_data == NULL)
============================================================
--- libpurple/proxy.h 4a8c88eb338d336a593479cd387bbfb93f862b86
+++ libpurple/proxy.h ceae59ba93647845733eed2c844f5f3bdb8f5007
@@ -307,10 +307,39 @@ PurpleProxyConnectData *purple_proxy_con
* opaque data structure that can be used to cancel
* the pending connection, if needed.
*/
+PurpleProxyConnectData *purple_proxy_connect_socks5_account(void *handle,
+ PurpleAccount *account, PurpleProxyInfo *gpi,
+ const char *host, int port,
+ PurpleProxyConnectFunction connect_cb, gpointer data);
+
+#ifndef PURPLE_DISABLE_DEPRECATED
+/**
+ * Makes a connection through a SOCKS5 proxy.
+ *
+ * @param handle A handle that should be associated with this
+ * connection attempt. The handle can be used
+ * to cancel the connection attempt using the
+ * purple_proxy_connect_cancel_with_handle()
+ * function.
+ * @param gpi The PurpleProxyInfo specifying the proxy settings
+ * @param host The destination host.
+ * @param port The destination port.
+ * @param connect_cb The function to call when the connection is
+ * established. If the connection failed then
+ * fd will be -1 and error message will be set
+ * to something descriptive (hopefully).
+ * @param data User-defined data.
+ *
+ * @return NULL if there was an error, or a reference to an
+ * opaque data structure that can be used to cancel
+ * the pending connection, if needed.
+ * @deprecated Use purple_proxy_connect_socks5_account instead
+ */
PurpleProxyConnectData *purple_proxy_connect_socks5(void *handle,
PurpleProxyInfo *gpi,
const char *host, int port,
PurpleProxyConnectFunction connect_cb, gpointer data);
+#endif
/**
* Cancel an in-progress connection attempt. This should be called
============================================================
--- libpurple/dnssrv.c a4e795801cf99bd5bed043d77348c64eee9a5a0f
+++ libpurple/dnssrv.c cba00135fe0c523deb64591125d43bbf9ed1c311
@@ -674,11 +674,22 @@ PurpleSrvTxtQueryData *
#endif
PurpleSrvTxtQueryData *
-purple_srv_resolve(const char *protocol, const char *transport, const char *domain, PurpleSrvCallback cb, gpointer extradata)
+purple_srv_resolve(const char *protocol, const char *transport,
+ const char *domain, PurpleSrvCallback cb, gpointer extradata)
{
+ return purple_srv_resolve_account(NULL, protocol, transport, domain,
+ cb, extradata);
+}
+
+PurpleSrvTxtQueryData *
+purple_srv_resolve_account(PurpleAccount *account, const char *protocol,
+ const char *transport, const char *domain, PurpleSrvCallback cb,
+ gpointer extradata)
+{
char *query;
char *hostname;
PurpleSrvTxtQueryData *query_data;
+ PurpleProxyType proxy_type;
#ifndef _WIN32
PurpleSrvInternalQuery internal_query;
int in[2], out[2];
@@ -694,6 +705,14 @@ purple_srv_resolve(const char *protocol,
g_return_val_if_reached(NULL);
}
+ proxy_type = purple_proxy_info_get_type(
+ purple_proxy_get_setup(account));
+ if (proxy_type == PURPLE_PROXY_TOR) {
+ purple_debug_info("dnssrv", "Aborting SRV lookup in Tor Proxy mode.");
+ cb(NULL, 0, extradata);
+ return NULL;
+ }
+
#ifdef USE_IDN
if (!dns_str_is_ascii(domain)) {
int ret = purple_network_convert_idn_to_ascii(domain, &hostname);
@@ -795,11 +814,20 @@ purple_srv_resolve(const char *protocol,
#endif
}
-PurpleSrvTxtQueryData *purple_txt_resolve(const char *owner, const char *domain, PurpleTxtCallback cb, gpointer extradata)
+PurpleSrvTxtQueryData *purple_txt_resolve(const char *owner,
+ const char *domain, PurpleTxtCallback cb, gpointer extradata)
{
+ return purple_txt_resolve_account(NULL, owner, domain, cb, extradata);
+}
+
+PurpleSrvTxtQueryData *purple_txt_resolve_account(PurpleAccount *account,
+ const char *owner, const char *domain, PurpleTxtCallback cb,
+ gpointer extradata)
+{
char *query;
char *hostname;
PurpleSrvTxtQueryData *query_data;
+ PurpleProxyType proxy_type;
#ifndef _WIN32
PurpleSrvInternalQuery internal_query;
int in[2], out[2];
@@ -809,6 +837,14 @@ PurpleSrvTxtQueryData *purple_txt_resolv
static gboolean initialized = FALSE;
#endif
+ proxy_type = purple_proxy_info_get_type(
+ purple_proxy_get_setup(account));
+ if (proxy_type == PURPLE_PROXY_TOR) {
+ purple_debug_info("dnssrv", "Aborting TXT lookup in Tor Proxy mode.");
+ cb(NULL, extradata);
+ return NULL;
+ }
+
#ifdef USE_IDN
if (!dns_str_is_ascii(domain)) {
int ret = purple_network_convert_idn_to_ascii(domain, &hostname);
============================================================
--- libpurple/dnssrv.h ffd16af4046c57fb98dc652c812b4c1f3531cc4f
+++ libpurple/dnssrv.h e40d82c3321a74f9efdcde650f43ddc6ce179938
@@ -103,13 +103,31 @@ typedef void (*PurpleTxtCallback)(GList
/**
* Queries an SRV record.
*
+ * @param account the account that the query is being done for (or NULL)
* @param protocol Name of the protocol (e.g. "sip")
* @param transport Name of the transport ("tcp" or "udp")
* @param domain Domain name to query (e.g. "blubb.com")
* @param cb A callback which will be called with the results
* @param extradata Extra data to be passed to the callback
+ *
+ * @since 2.8.0
*/
+PurpleSrvTxtQueryData *purple_srv_resolve_account(PurpleAccount *account, const char *protocol, const char *transport, const char *domain, PurpleSrvCallback cb, gpointer extradata);
+
+#ifndef PURPLE_DISABLE_DEPRECATED
+/**
+ * Queries an SRV record.
+ *
+ * @param protocol Name of the protocol (e.g. "sip")
+ * @param transport Name of the transport ("tcp" or "udp")
+ * @param domain Domain name to query (e.g. "blubb.com")
+ * @param cb A callback which will be called with the results
+ * @param extradata Extra data to be passed to the callback
+ *
+ * @deprecated Use purple_srv_resolve_account instead
+ */
PurpleSrvTxtQueryData *purple_srv_resolve(const char *protocol, const char *transport, const char *domain, PurpleSrvCallback cb, gpointer extradata);
+#endif
/**
* Cancel an SRV or DNS query.
@@ -121,14 +139,31 @@ void purple_srv_cancel(PurpleSrvTxtQuery
/**
* Queries an TXT record.
*
+ * @param account the account that the query is being done for (or NULL)
* @param owner Name of the protocol (e.g. "_xmppconnect")
* @param domain Domain name to query (e.g. "blubb.com")
* @param cb A callback which will be called with the results
* @param extradata Extra data to be passed to the callback
*
+ * @since 2.8.0
+ */
+PurpleSrvTxtQueryData *purple_txt_resolve_account(PurpleAccount *account, const char *owner, const char *domain, PurpleTxtCallback cb, gpointer extradata);
+
+#ifndef PURPLE_DISABLE_DEPRECATED
+/**
+ * Queries an TXT record.
+ *
+ * @param owner Name of the protocol (e.g. "_xmppconnect")
+ * @param domain Domain name to query (e.g. "blubb.com")
+ * @param cb A callback which will be called with the results
+ * @param extradata Extra data to be passed to the callback
+ *
+ * @deprecated Use purple_txt_resolve_account instead
+ *
* @since 2.6.0
*/
PurpleSrvTxtQueryData *purple_txt_resolve(const char *owner, const char *domain, PurpleTxtCallback cb, gpointer extradata);
+#endif
/**
* Cancel an TXT DNS query.
============================================================
--- libpurple/dnsquery.c e23a1cdf587234a7b21bfbb1e22debeec4b4f17e
+++ libpurple/dnsquery.c 67bb94b47bc890d206582227262970f859477244
@@ -54,6 +54,7 @@ struct _PurpleDnsQueryData {
PurpleDnsQueryConnectFunction callback;
gpointer data;
guint timeout;
+ PurpleAccount *account;
#if defined(PURPLE_DNSQUERY_USE_FORK)
PurpleDnsQueryResolverProcess *resolver;
@@ -861,6 +862,7 @@ initiate_resolving(gpointer data)
initiate_resolving(gpointer data)
{
PurpleDnsQueryData *query_data;
+ PurpleProxyType proxy_type;
query_data = data;
query_data->timeout = 0;
@@ -869,6 +871,14 @@ initiate_resolving(gpointer data)
/* resolve_ip calls purple_dnsquery_resolved */
return FALSE;
+ proxy_type = purple_proxy_info_get_type(
+ purple_proxy_get_setup(query_data->account));
+ if (proxy_type == PURPLE_PROXY_TOR) {
+ purple_dnsquery_failed(query_data,
+ _("Aborting DNS lookup in Tor Proxy mode."));
+ return FALSE;
+ }
+
if (purple_dnsquery_ui_resolve(query_data))
/* The UI is handling the resolve; we're done */
return FALSE;
@@ -878,9 +888,8 @@ initiate_resolving(gpointer data)
return FALSE;
}
-
PurpleDnsQueryData *
-purple_dnsquery_a(const char *hostname, int port,
+purple_dnsquery_a_account(PurpleAccount *account, const char *hostname, int port,
PurpleDnsQueryConnectFunction callback, gpointer data)
{
PurpleDnsQueryData *query_data;
@@ -897,6 +906,7 @@ purple_dnsquery_a(const char *hostname,
query_data->port = port;
query_data->callback = callback;
query_data->data = data;
+ query_data->account = account;
if (*query_data->hostname == '\0')
{
@@ -909,6 +919,12 @@ purple_dnsquery_a(const char *hostname,
return query_data;
}
+PurpleDnsQueryData *
+purple_dnsquery_a(const char *hostname, int port,
+ PurpleDnsQueryConnectFunction callback, gpointer data)
+{
+ return purple_dnsquery_a_account(NULL, hostname, port, callback, data);
+}
void
purple_dnsquery_destroy(PurpleDnsQueryData *query_data)
============================================================
--- libpurple/dnsquery.h 5b75e45455b1faddc365998a81122db7c4823f31
+++ libpurple/dnsquery.h 7225dfc6bca4865f4b54e9103ba60aeea279cffc
@@ -88,6 +88,7 @@ extern "C" {
/**
* Perform an asynchronous DNS query.
*
+ * @param account the account that the query is being done for (or NULL)
* @param hostname The hostname to resolve.
* @param port A port number which is stored in the struct sockaddr.
* @param callback The callback function to call after resolving.
@@ -96,8 +97,28 @@ extern "C" {
* @return NULL if there was an error, otherwise return a reference to
* a data structure that can be used to cancel the pending
* DNS query, if needed.
+ *
+ * @since 2.8.0
*/
+PurpleDnsQueryData *purple_dnsquery_a_account(PurpleAccount *account, const char *hostname, int port, PurpleDnsQueryConnectFunction callback, gpointer data);
+
+#ifndef PURPLE_DISABLE_DEPRECATED
+/**
+ * Perform an asynchronous DNS query.
+ *
+ * @param hostname The hostname to resolve.
+ * @param port A port number which is stored in the struct sockaddr.
+ * @param callback The callback function to call after resolving.
+ * @param data Extra data to pass to the callback function.
+ *
+ * @return NULL if there was an error, otherwise return a reference to
+ * a data structure that can be used to cancel the pending
+ * DNS query, if needed.
+ *
+ * @deprecated Use purple_dnsquery_a_account instead
+ */
PurpleDnsQueryData *purple_dnsquery_a(const char *hostname, int port, PurpleDnsQueryConnectFunction callback, gpointer data);
+#endif
/**
* Cancel a DNS query and destroy the associated data structure.
More information about the Commits
mailing list