# HG changeset patch # User Mark Doliner # Date 1155886817 0 # Node ID c3c792958635adaf36fca159250bbb1cac46e24b # Parent ccb670ba3b4f48f7412bba8b77ace9751f15f28e [gaim-migrate @ 16835] Change the DNS query function to return a struct that will eventually allow the query to be canceled. Also rename two of the DNS query things committer: Tailor Script diff -r ccb670ba3b4f -r c3c792958635 src/dnsquery.c --- a/src/dnsquery.c Fri Aug 18 07:22:55 2006 +0000 +++ b/src/dnsquery.c Fri Aug 18 07:40:17 2006 +0000 @@ -35,6 +35,9 @@ * DNS query API **************************************************************************/ +struct _GaimDnsQueryData { +}; + #if defined(__unix__) || defined(__APPLE__) #define MAX_DNS_CHILDREN 4 @@ -46,7 +49,7 @@ typedef struct { char *host; int port; - GaimProxyDnsConnectFunction callback; + GaimDnsQueryConnectFunction callback; gpointer data; guint inpa; int fd_in, fd_out; @@ -65,7 +68,7 @@ typedef struct { dns_params_t params; - GaimProxyDnsConnectFunction callback; + GaimDnsQueryConnectFunction callback; gpointer data; } queued_dns_request_t; @@ -473,8 +476,8 @@ * End the functions for dealing with the DNS child processes. */ -int -gaim_gethostbyname_async(const char *hostname, int port, GaimProxyDnsConnectFunction callback, gpointer data) +GaimDnsQueryData * +gaim_dnsquery_a(const char *hostname, int port, GaimDnsQueryConnectFunction callback, gpointer data) { pending_dns_request_t *req = NULL; dns_params_t dns_params; @@ -521,14 +524,14 @@ gaim_debug_info("dns", "DNS query for '%s' queued\n", dns_params.hostname); - return 0; + return (GaimDnsQueryData *)1; } req = gaim_dns_new_resolverthread(show_debug); if (req == NULL) { gaim_debug_error("proxy", "oh dear, this is going to explode, I give up\n"); - return -1; + return NULL; } send_dns_request_to_child(req, &dns_params); } @@ -539,7 +542,7 @@ req->data = data; req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); - return 0; + return (GaimDnsQueryData *)1; } #elif defined _WIN32 /* end __unix__ || __APPLE__ */ @@ -547,7 +550,7 @@ typedef struct _dns_tdata { char *hostname; int port; - GaimProxyDnsConnectFunction callback; + GaimDnsQueryConnectFunction callback; gpointer data; GSList *hosts; char *errmsg; @@ -621,9 +624,9 @@ return 0; } -int -gaim_gethostbyname_async(const char *hostname, int port, - GaimProxyDnsConnectFunction callback, gpointer data) +GaimDnsQueryData * +gaim_dnsquery_a(const char *hostname, int port, + GaimDnsQueryConnectFunction callback, gpointer data) { dns_tdata *td; struct sockaddr_in sin; @@ -636,7 +639,7 @@ hosts = g_slist_append(hosts, GINT_TO_POINTER(sizeof(sin))); hosts = g_slist_append(hosts, g_memdup(&sin, sizeof(sin))); callback(hosts, data, NULL); - return 0; + return (GaimDnsQueryData *)1; } gaim_debug_info("dns", "DNS Lookup for: %s\n", hostname); @@ -651,9 +654,9 @@ g_error_free(err); g_free(td->hostname); g_free(td); - return -1; + return NULL; } - return 0; + return (GaimDnsQueryData *)1; } #else /* not __unix__ or __APPLE__ or _WIN32 */ @@ -662,7 +665,7 @@ gpointer data; size_t addrlen; struct sockaddr *addr; - GaimProxyDnsConnectFunction callback; + GaimDnsQueryConnectFunction callback; } pending_dns_request_t; static gboolean host_resolved(gpointer data) @@ -676,9 +679,9 @@ return FALSE; } -int -gaim_gethostbyname_async(const char *hostname, int port, - GaimProxyDnsConnectFunction callback, gpointer data) +GaimDnsQueryData * +gaim_dnsquery_a(const char *hostname, int port, + GaimDnsQueryConnectFunction callback, gpointer data) { struct sockaddr_in sin; pending_dns_request_t *req; @@ -689,7 +692,7 @@ gaim_debug_error("dns", "gaim_gethostbyname(\"%s\", %d) failed: %d\n", hostname, port, h_errno); - return -1; + return NULL; } memset(&sin, 0, sizeof(struct sockaddr_in)); memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); @@ -704,7 +707,7 @@ req->data = data; req->callback = callback; gaim_timeout_add(10, host_resolved, req); - return 0; + return (GaimDnsQueryData *)1; } #endif /* not __unix__ or __APPLE__ or _WIN32 */ diff -r ccb670ba3b4f -r c3c792958635 src/dnsquery.h --- a/src/dnsquery.h Fri Aug 18 07:22:55 2006 +0000 +++ b/src/dnsquery.h Fri Aug 18 07:40:17 2006 +0000 @@ -28,11 +28,13 @@ #include #include "eventloop.h" +typedef struct _GaimDnsQueryData GaimDnsQueryData; + /** * The "hosts" parameter is a linked list containing pairs of * one size_t addrlen and one struct sockaddr *addr. */ -typedef void (*GaimProxyDnsConnectFunction)(GSList *hosts, gpointer data, const char *error_message); +typedef void (*GaimDnsQueryConnectFunction)(GSList *hosts, gpointer data, const char *error_message); #include "account.h" @@ -54,9 +56,11 @@ * @param callback Callback to call after resolving * @param data Extra data for the callback function * - * @return Zero indicates the connection is pending. Any other value indicates failure. + * @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. */ -int gaim_gethostbyname_async(const char *hostname, int port, GaimProxyDnsConnectFunction callback, gpointer data); +GaimDnsQueryData *gaim_dnsquery_a(const char *hostname, int port, GaimDnsQueryConnectFunction callback, gpointer data); /*@}*/ diff -r ccb670ba3b4f -r c3c792958635 src/protocols/simple/simple.c --- a/src/protocols/simple/simple.c Fri Aug 18 07:22:55 2006 +0000 +++ b/src/protocols/simple/simple.c Fri Aug 18 07:40:17 2006 +0000 @@ -1622,7 +1622,7 @@ } else { /* UDP */ gaim_debug_info("simple", "using udp with server %s and port %d\n", hostname, port); - gaim_gethostbyname_async(hostname, port, simple_udp_host_resolved, sip); + gaim_dnsquery_a(hostname, port, simple_udp_host_resolved, sip); } } diff -r ccb670ba3b4f -r c3c792958635 src/proxy.c --- a/src/proxy.c Fri Aug 18 07:22:55 2006 +0000 +++ b/src/proxy.c Fri Aug 18 07:40:17 2006 +0000 @@ -47,6 +47,7 @@ int fd; guint inpa; GaimProxyInfo *gpi; + GaimDnsQueryData *query_data; /** * This contains alternating length/char* values. The char* @@ -1695,8 +1696,9 @@ return NULL; } - if (gaim_gethostbyname_async(connecthost, - connectport, connection_host_resolved, connect_info) != 0) + connect_info->query_data = gaim_dnsquery_a(connecthost, + connectport, connection_host_resolved, connect_info); + if (connect_info->query_data == NULL) { gaim_proxy_connect_info_destroy(connect_info); return NULL; @@ -1728,8 +1730,11 @@ connect_info->port = port; connect_info->gpi = gpi; - if (gaim_gethostbyname_async(gaim_proxy_info_get_host(gpi), - gaim_proxy_info_get_port(gpi), connection_host_resolved, connect_info) != 0) + connect_info->query_data = + gaim_dnsquery_a(gaim_proxy_info_get_host(gpi), + gaim_proxy_info_get_port(gpi), + connection_host_resolved, connect_info); + if (connect_info->query_data == NULL) { gaim_proxy_connect_info_destroy(connect_info); return NULL; diff -r ccb670ba3b4f -r c3c792958635 src/stun.c --- a/src/stun.c Fri Aug 18 07:22:55 2006 +0000 +++ b/src/stun.c Fri Aug 18 07:40:17 2006 +0000 @@ -360,7 +360,7 @@ gaim_debug_info("stun", "got %d SRV responses, server: %s, port: %d\n", results, servername, port); - gaim_gethostbyname_async(servername, port, hbn_cb, NULL); + gaim_dnsquery_a(servername, port, hbn_cb, NULL); g_free(resp); }