comparison src/proxy.c @ 10619:4ab7dec04c38

[gaim-migrate @ 12086] Use g_thread based asynchronous DNS lookup on all platforms. It seems to me that configure.ac should need to be modified to specify gthread as a module on AM_PATH_GTK_2_0(), but it seems to be ok as it is. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Tue, 22 Feb 2005 05:45:45 +0000
parents 351449bb5a74
children 06f5cc17cddc
comparison
equal deleted inserted replaced
10618:9eb3b224face 10619:4ab7dec04c38
187 * Proxy API 187 * Proxy API
188 **************************************************************************/ 188 **************************************************************************/
189 typedef void (*dns_callback_t)(GSList *hosts, gpointer data, 189 typedef void (*dns_callback_t)(GSList *hosts, gpointer data,
190 const char *error_message); 190 const char *error_message);
191 191
192 #ifdef __unix__ 192 #if 0
193 193
194 /* This structure represents both a pending DNS request and 194 /* This structure represents both a pending DNS request and
195 * a free child process. 195 * a free child process.
196 */ 196 */
197 typedef struct { 197 typedef struct {
632 req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req); 632 req->inpa = gaim_input_add(req->fd_out, GAIM_INPUT_READ, host_resolved, req);
633 633
634 return 0; 634 return 0;
635 } 635 }
636 636
637 #elif defined _WIN32 /* end __unix__ */ 637 #elif defined G_THREADS_ENABLED
638
639 /* Note: The below win32 implementation is actually platform independent.
640 Perhaps this can be used in place of the above platform dependent code.
641 */
642 638
643 typedef struct _dns_tdata { 639 typedef struct _dns_tdata {
644 char *hostname; 640 char *hostname;
645 int port; 641 int port;
646 dns_callback_t callback; 642 dns_callback_t callback;
660 g_free(td); 656 g_free(td);
661 return FALSE; 657 return FALSE;
662 } 658 }
663 659
664 static gpointer dns_thread(gpointer data) { 660 static gpointer dns_thread(gpointer data) {
661
662 #if HAVE_GETADDRINFO
663 int rc;
664 struct addrinfo hints, *res, *tmp;
665 char servname[20];
666 #else
665 struct sockaddr_in sin; 667 struct sockaddr_in sin;
668 struct hostent *hp;
669 #endif
666 dns_tdata *td = (dns_tdata*)data; 670 dns_tdata *td = (dns_tdata*)data;
667 struct hostent *hp; 671
668 672 #if HAVE_GETADDRINFO
673 g_snprintf(servname, sizeof(servname), "%d", td->port);
674 memset(&hints,0,sizeof(hints));
675
676 /* This is only used to convert a service
677 * name to a port number. As we know we are
678 * passing a number already, we know this
679 * value will not be really used by the C
680 * library.
681 */
682 hints.ai_socktype = SOCK_STREAM;
683 if ((rc = getaddrinfo(td->hostname, servname, &hints, &res)) == 0) {
684 tmp = res;
685 while(res) {
686 td->hosts = g_slist_append(td->hosts,
687 GSIZE_TO_POINTER(res->ai_addrlen));
688 td->hosts = g_slist_append(td->hosts,
689 g_memdup(res->ai_addr, res->ai_addrlen));
690 res = res->ai_next;
691 }
692 freeaddrinfo(tmp);
693 } else {
694 td->errmsg = g_strdup_printf("DNS getaddrinfo(\"%s\", \"%s\") error: %d", td->hostname, servname, rc);
695 }
696 #else
669 if ((hp = gethostbyname(td->hostname))) { 697 if ((hp = gethostbyname(td->hostname))) {
670 memset(&sin, 0, sizeof(struct sockaddr_in)); 698 memset(&sin, 0, sizeof(struct sockaddr_in));
671 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length); 699 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length);
672 sin.sin_family = hp->h_addrtype; 700 sin.sin_family = hp->h_addrtype;
673 sin.sin_port = htons(td->port); 701 sin.sin_port = htons(td->port);
674 702
675 td->hosts = g_slist_append(td->hosts, 703 td->hosts = g_slist_append(td->hosts,
676 GINT_TO_POINTER(sizeof(sin))); 704 GSIZE_TO_POINTER(sizeof(sin)));
677 td->hosts = g_slist_append(td->hosts, 705 td->hosts = g_slist_append(td->hosts,
678 g_memdup(&sin, sizeof(sin))); 706 g_memdup(&sin, sizeof(sin)));
679 } else { 707 } else {
680 td->errmsg = g_strdup_printf("DNS error: %d", errno); 708 td->errmsg = g_strdup_printf("DNS gethostbyname(\"%s\") error: %d", td->hostname, h_errno);
681 } 709 }
710 #endif
682 /* back to main thread */ 711 /* back to main thread */
683 g_idle_add(dns_main_thread_cb, td); 712 g_idle_add(dns_main_thread_cb, td);
684 return 0; 713 return 0;
685 } 714 }
686 715
715 return -1; 744 return -1;
716 } 745 }
717 return 0; 746 return 0;
718 } 747 }
719 748
720 #else /* not __unix__ or _WIN32 */ 749 #else /* not G_THREADS_ENABLED */
721 750
722 typedef struct { 751 typedef struct {
723 gpointer data; 752 gpointer data;
724 size_t addrlen; 753 size_t addrlen;
725 struct sockaddr *addr; 754 struct sockaddr *addr;
1889 proxy_pref_cb, NULL); 1918 proxy_pref_cb, NULL);
1890 gaim_prefs_connect_callback(handle, "/core/proxy/username", 1919 gaim_prefs_connect_callback(handle, "/core/proxy/username",
1891 proxy_pref_cb, NULL); 1920 proxy_pref_cb, NULL);
1892 gaim_prefs_connect_callback(handle, "/core/proxy/password", 1921 gaim_prefs_connect_callback(handle, "/core/proxy/password",
1893 proxy_pref_cb, NULL); 1922 proxy_pref_cb, NULL);
1894 #ifdef _WIN32
1895 if(!g_thread_supported()) 1923 if(!g_thread_supported())
1896 g_thread_init(NULL); 1924 g_thread_init(NULL);
1897 #endif
1898 } 1925 }
1899 1926
1900 void * 1927 void *
1901 gaim_proxy_get_handle() 1928 gaim_proxy_get_handle()
1902 { 1929 {