comparison libpurple/dnsquery.c @ 23212:1e87376e77f2

merge of '50ee8ea93d28a742019b72de39c81427af3ca785' and 'e7d6a0a271d8fe8435f200e0f1ec123053e57493'
author Evan Schoenberg <evan.s@dreskin.net>
date Tue, 27 May 2008 01:38:35 +0000
parents 313b87adb730
children f085e284f2df
comparison
equal deleted inserted replaced
23211:bda7c7c4d4b2 23212:1e87376e77f2
30 #include "dnsquery.h" 30 #include "dnsquery.h"
31 #include "notify.h" 31 #include "notify.h"
32 #include "prefs.h" 32 #include "prefs.h"
33 #include "util.h" 33 #include "util.h"
34 34
35 #if (defined(__APPLE__) || defined (__unix__)) && !defined(__osf__)
36 #define PURPLE_DNSQUERY_USE_FORK
37 #endif
35 /************************************************************************** 38 /**************************************************************************
36 * DNS query API 39 * DNS query API
37 **************************************************************************/ 40 **************************************************************************/
38 41
39 static PurpleDnsQueryUiOps *dns_query_ui_ops = NULL; 42 static PurpleDnsQueryUiOps *dns_query_ui_ops = NULL;
45 int port; 48 int port;
46 PurpleDnsQueryConnectFunction callback; 49 PurpleDnsQueryConnectFunction callback;
47 gpointer data; 50 gpointer data;
48 guint timeout; 51 guint timeout;
49 52
50 #if defined(__unix__) || defined(__APPLE__) 53 #if defined(PURPLE_DNSQUERY_USE_FORK)
51 PurpleDnsQueryResolverProcess *resolver; 54 PurpleDnsQueryResolverProcess *resolver;
52 #elif defined _WIN32 /* end __unix__ || __APPLE__ */ 55 #elif defined _WIN32 /* end PURPLE_DNSQUERY_USE_FORK */
53 GThread *resolver; 56 GThread *resolver;
54 GSList *hosts; 57 GSList *hosts;
55 gchar *error_message; 58 gchar *error_message;
56 #endif 59 #endif
57 }; 60 };
58 61
59 #if defined(__unix__) || defined(__APPLE__) 62 #if defined(PURPLE_DNSQUERY_USE_FORK)
60 63
61 #define MAX_DNS_CHILDREN 4 64 #define MAX_DNS_CHILDREN 4
62 65
63 /* 66 /*
64 * This structure keeps a reference to a child resolver process. 67 * This structure keeps a reference to a child resolver process.
129 } 132 }
130 133
131 return FALSE; 134 return FALSE;
132 } 135 }
133 136
134 #if defined(__unix__) || defined(__APPLE__) 137 #if defined(PURPLE_DNSQUERY_USE_FORK)
135 138
136 /* 139 /*
137 * Unix! 140 * Unix!
138 */ 141 */
139 142
647 query_data->timeout = purple_timeout_add(0, resolve_host, query_data); 650 query_data->timeout = purple_timeout_add(0, resolve_host, query_data);
648 651
649 return query_data; 652 return query_data;
650 } 653 }
651 654
652 #elif defined _WIN32 /* end __unix__ || __APPLE__ */ 655 #elif defined _WIN32 /* end PURPLE_DNSQUERY_USE_FORK */
653 656
654 /* 657 /*
655 * Windows! 658 * Windows!
656 */ 659 */
657 660
819 query_data->timeout = purple_timeout_add(0, resolve_host, query_data); 822 query_data->timeout = purple_timeout_add(0, resolve_host, query_data);
820 823
821 return query_data; 824 return query_data;
822 } 825 }
823 826
824 #else /* not __unix__ or __APPLE__ or _WIN32 */ 827 #else /* not PURPLE_DNSQUERY_USE_FORK or _WIN32 */
825 828
826 /* 829 /*
827 * We weren't able to do anything fancier above, so use the 830 * We weren't able to do anything fancier above, so use the
828 * fail-safe name resolution code, which is blocking. 831 * fail-safe name resolution code, which is blocking.
829 */ 832 */
895 query_data->timeout = purple_timeout_add(0, resolve_host, query_data); 898 query_data->timeout = purple_timeout_add(0, resolve_host, query_data);
896 899
897 return query_data; 900 return query_data;
898 } 901 }
899 902
900 #endif /* not __unix__ or __APPLE__ or _WIN32 */ 903 #endif /* not PURPLE_DNSQUERY_USE_FORK or _WIN32 */
901 904
902 void 905 void
903 purple_dnsquery_destroy(PurpleDnsQueryData *query_data) 906 purple_dnsquery_destroy(PurpleDnsQueryData *query_data)
904 { 907 {
905 PurpleDnsQueryUiOps *ops = purple_dnsquery_get_ui_ops(); 908 PurpleDnsQueryUiOps *ops = purple_dnsquery_get_ui_ops();
906 909
907 if (ops && ops->destroy) 910 if (ops && ops->destroy)
908 ops->destroy(query_data); 911 ops->destroy(query_data);
909 912
910 #if defined(__unix__) || defined(__APPLE__) 913 #if defined(PURPLE_DNSQUERY_USE_FORK)
911 queued_requests = g_slist_remove(queued_requests, query_data); 914 queued_requests = g_slist_remove(queued_requests, query_data);
912 915
913 if (query_data->resolver != NULL) 916 if (query_data->resolver != NULL)
914 /* 917 /*
915 * Ideally we would tell our resolver child to stop resolving 918 * Ideally we would tell our resolver child to stop resolving
916 * shit and then we would add it back to the free_dns_children 919 * shit and then we would add it back to the free_dns_children
917 * linked list. However, it's hard to tell children stuff, 920 * linked list. However, it's hard to tell children stuff,
918 * they just don't listen. 921 * they just don't listen.
919 */ 922 */
920 purple_dnsquery_resolver_destroy(query_data->resolver); 923 purple_dnsquery_resolver_destroy(query_data->resolver);
921 #elif defined _WIN32 /* end __unix__ || __APPLE__ */ 924 #elif defined _WIN32 /* end PURPLE_DNSQUERY_USE_FORK */
922 if (query_data->resolver != NULL) 925 if (query_data->resolver != NULL)
923 { 926 {
924 /* 927 /*
925 * It's not really possible to kill a thread. So instead we 928 * It's not really possible to kill a thread. So instead we
926 * just set the callback to NULL and let the DNS lookup 929 * just set the callback to NULL and let the DNS lookup
985 } 988 }
986 989
987 void 990 void
988 purple_dnsquery_uninit(void) 991 purple_dnsquery_uninit(void)
989 { 992 {
990 #if defined(__unix__) || defined(__APPLE__) 993 #if defined(PURPLE_DNSQUERY_USE_FORK)
991 while (free_dns_children != NULL) 994 while (free_dns_children != NULL)
992 { 995 {
993 purple_dnsquery_resolver_destroy(free_dns_children->data); 996 purple_dnsquery_resolver_destroy(free_dns_children->data);
994 free_dns_children = g_slist_remove(free_dns_children, free_dns_children->data); 997 free_dns_children = g_slist_remove(free_dns_children, free_dns_children->data);
995 } 998 }