annotate libgaim/dnsquery.c @ 14607:f23506e8f812

[gaim-migrate @ 17335] Get rid of some checks to make sure gc is valid. They shouldn't be necessary (and a lot of them were poorly implemented anyway). Let me know if you notice any crashes. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 22 Sep 2006 05:42:01 +0000
parents 1d73e11d8787
children 4ee6553079b5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1 /**
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
2 * @file dnsquery.c DNS query API
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
3 * @ingroup core
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
4 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
5 * gaim
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
6 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
7 * Gaim is the legal property of its developers, whose names are too numerous
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
8 * to list here. Please refer to the COPYRIGHT file distributed with this
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
9 * source distribution.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
10 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
14 * (at your option) any later version.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
15 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
19 * GNU General Public License for more details.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
20 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
24 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
25 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
26
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
27 #include "internal.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
28 #include "debug.h"
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
29 #include "dnsquery.h"
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
30 #include "notify.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
31 #include "prefs.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
32 #include "util.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
33
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
34 /**************************************************************************
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
35 * DNS query API
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
36 **************************************************************************/
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
37
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
38 typedef struct _GaimDnsQueryResolverProcess GaimDnsQueryResolverProcess;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
39
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
40 struct _GaimDnsQueryData {
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
41 char *hostname;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
42 int port;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
43 GaimDnsQueryConnectFunction callback;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
44 gpointer data;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
45 guint timeout;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
46
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
47 #if defined(__unix__) || defined(__APPLE__)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
48 GaimDnsQueryResolverProcess *resolver;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
49 #elif defined _WIN32 /* end __unix__ || __APPLE__ */
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
50 GThread *resolver;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
51 GSList *hosts;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
52 gchar *error_message;
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
53 #endif
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
54 };
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
55
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
56 #if defined(__unix__) || defined(__APPLE__)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
57
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
58 #define MAX_DNS_CHILDREN 4
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
59
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
60 /*
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
61 * This structure keeps a reference to a child resolver process.
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
62 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
63 struct _GaimDnsQueryResolverProcess {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
64 guint inpa;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
65 int fd_in, fd_out;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
66 pid_t dns_pid;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
67 };
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
68
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
69 static GSList *free_dns_children = NULL;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
70 static GQueue *queued_requests = NULL;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
71
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
72 static int number_of_dns_children = 0;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
73
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
74 /*
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
75 * This is a convenience struct used to pass data to
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
76 * the child resolver process.
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
77 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
78 typedef struct {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
79 char hostname[512];
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
80 int port;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
81 } dns_params_t;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
82 #endif
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
83
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
84 static void
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
85 gaim_dnsquery_resolved(GaimDnsQueryData *query_data, GSList *hosts)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
86 {
14244
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
87 gaim_debug_info("dnsquery", "IP resolved for %s\n", query_data->hostname);
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
88 if (query_data->callback != NULL)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
89 query_data->callback(hosts, query_data->data, NULL);
14358
fdf65b672b87 [gaim-migrate @ 17064]
Mark Doliner <mark@kingant.net>
parents: 14287
diff changeset
90 else
fdf65b672b87 [gaim-migrate @ 17064]
Mark Doliner <mark@kingant.net>
parents: 14287
diff changeset
91 {
fdf65b672b87 [gaim-migrate @ 17064]
Mark Doliner <mark@kingant.net>
parents: 14287
diff changeset
92 /*
fdf65b672b87 [gaim-migrate @ 17064]
Mark Doliner <mark@kingant.net>
parents: 14287
diff changeset
93 * Callback is a required parameter, but it can get set to
fdf65b672b87 [gaim-migrate @ 17064]
Mark Doliner <mark@kingant.net>
parents: 14287
diff changeset
94 * NULL if we cancel a thread-based DNS lookup. So we need
fdf65b672b87 [gaim-migrate @ 17064]
Mark Doliner <mark@kingant.net>
parents: 14287
diff changeset
95 * to free hosts.
fdf65b672b87 [gaim-migrate @ 17064]
Mark Doliner <mark@kingant.net>
parents: 14287
diff changeset
96 */
fdf65b672b87 [gaim-migrate @ 17064]
Mark Doliner <mark@kingant.net>
parents: 14287
diff changeset
97 while (hosts != NULL)
fdf65b672b87 [gaim-migrate @ 17064]
Mark Doliner <mark@kingant.net>
parents: 14287
diff changeset
98 {
fdf65b672b87 [gaim-migrate @ 17064]
Mark Doliner <mark@kingant.net>
parents: 14287
diff changeset
99 hosts = g_slist_remove(hosts, hosts->data);
fdf65b672b87 [gaim-migrate @ 17064]
Mark Doliner <mark@kingant.net>
parents: 14287
diff changeset
100 g_free(hosts->data);
fdf65b672b87 [gaim-migrate @ 17064]
Mark Doliner <mark@kingant.net>
parents: 14287
diff changeset
101 hosts = g_slist_remove(hosts, hosts->data);
fdf65b672b87 [gaim-migrate @ 17064]
Mark Doliner <mark@kingant.net>
parents: 14287
diff changeset
102 }
fdf65b672b87 [gaim-migrate @ 17064]
Mark Doliner <mark@kingant.net>
parents: 14287
diff changeset
103 }
fdf65b672b87 [gaim-migrate @ 17064]
Mark Doliner <mark@kingant.net>
parents: 14287
diff changeset
104
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
105 gaim_dnsquery_destroy(query_data);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
106 }
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
107
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
108 static void
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
109 gaim_dnsquery_failed(GaimDnsQueryData *query_data, const gchar *error_message)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
110 {
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
111 gaim_debug_info("dnsquery", "%s\n", error_message);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
112 if (query_data->callback != NULL)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
113 query_data->callback(NULL, query_data->data, error_message);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
114 gaim_dnsquery_destroy(query_data);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
115 }
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
116
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
117 #if defined(__unix__) || defined(__APPLE__)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
118
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
119 /*
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
120 * Unix!
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
121 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
122
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
123 /*
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
124 * Begin the DNS resolver child process functions.
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
125 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
126 #ifdef HAVE_SIGNAL_H
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
127 static void
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
128 trap_gdb_bug()
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
129 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
130 const char *message =
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
131 "Gaim's DNS child got a SIGTRAP signal.\n"
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
132 "This can be caused by trying to run gaim inside gdb.\n"
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
133 "There is a known gdb bug which prevents this. Supposedly gaim\n"
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
134 "should have detected you were using gdb and used an ugly hack,\n"
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
135 "check cope_with_gdb_brokenness() in dnsquery.c.\n\n"
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
136 "For more info about this bug, see http://sources.redhat.com/ml/gdb/2001-07/msg00349.html\n";
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
137 fputs("\n* * *\n",stderr);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
138 fputs(message,stderr);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
139 fputs("* * *\n\n",stderr);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
140 execlp("xmessage","xmessage","-center", message, NULL);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
141 _exit(1);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
142 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
143 #endif
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
144
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
145 static void
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
146 gaim_dnsquery_resolver_run(int child_out, int child_in, gboolean show_debug)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
147 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
148 dns_params_t dns_params;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
149 const size_t zero = 0;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
150 int rc;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
151 #ifdef HAVE_GETADDRINFO
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
152 struct addrinfo hints, *res, *tmp;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
153 char servname[20];
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
154 #else
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
155 struct sockaddr_in sin;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
156 const size_t addrlen = sizeof(sin);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
157 #endif
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
158
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
159 #ifdef HAVE_SIGNAL_H
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
160 signal(SIGHUP, SIG_DFL);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
161 signal(SIGINT, SIG_DFL);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
162 signal(SIGQUIT, SIG_DFL);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
163 signal(SIGCHLD, SIG_DFL);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
164 signal(SIGTERM, SIG_DFL);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
165 signal(SIGTRAP, trap_gdb_bug);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
166 #endif
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
167
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
168 /*
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
169 * We resolve 1 host name for each iteration of this
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
170 * while loop.
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
171 *
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
172 * The top half of this reads in the hostname and port
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
173 * number from the socket with our parent. The bottom
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
174 * half of this resolves the IP (blocking) and sends
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
175 * the result back to our parent, when finished.
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
176 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
177 while (1) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
178 const char ch = 'Y';
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
179 fd_set fds;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
180 struct timeval tv = { .tv_sec = 40 , .tv_usec = 0 };
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
181 FD_ZERO(&fds);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
182 FD_SET(child_in, &fds);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
183 rc = select(child_in + 1, &fds, NULL, NULL, &tv);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
184 if (!rc) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
185 if (show_debug)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
186 printf("dns[%d]: nobody needs me... =(\n", getpid());
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
187 break;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
188 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
189 rc = read(child_in, &dns_params, sizeof(dns_params_t));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
190 if (rc < 0) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
191 perror("read()");
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
192 break;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
193 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
194 if (rc == 0) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
195 if (show_debug)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
196 printf("dns[%d]: Oops, father has gone, wait for me, wait...!\n", getpid());
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
197 _exit(0);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
198 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
199 if (dns_params.hostname[0] == '\0') {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
200 printf("dns[%d]: hostname = \"\" (port = %d)!!!\n", getpid(), dns_params.port);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
201 _exit(1);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
202 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
203 /* Tell our parent that we read the data successfully */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
204 write(child_out, &ch, sizeof(ch));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
205
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
206 /* We have the hostname and port, now resolve the IP */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
207
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
208 #ifdef HAVE_GETADDRINFO
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
209 g_snprintf(servname, sizeof(servname), "%d", dns_params.port);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
210 memset(&hints, 0, sizeof(hints));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
211
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
212 /* This is only used to convert a service
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
213 * name to a port number. As we know we are
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
214 * passing a number already, we know this
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
215 * value will not be really used by the C
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
216 * library.
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
217 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
218 hints.ai_socktype = SOCK_STREAM;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
219 rc = getaddrinfo(dns_params.hostname, servname, &hints, &res);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
220 write(child_out, &rc, sizeof(rc));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
221 if (rc != 0) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
222 close(child_out);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
223 if (show_debug)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
224 printf("dns[%d] Error: getaddrinfo returned %d\n",
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
225 getpid(), rc);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
226 dns_params.hostname[0] = '\0';
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
227 continue;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
228 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
229 tmp = res;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
230 while (res) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
231 size_t ai_addrlen = res->ai_addrlen;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
232 write(child_out, &ai_addrlen, sizeof(ai_addrlen));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
233 write(child_out, res->ai_addr, res->ai_addrlen);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
234 res = res->ai_next;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
235 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
236 freeaddrinfo(tmp);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
237 write(child_out, &zero, sizeof(zero));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
238 #else
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
239 if (!inet_aton(dns_params.hostname, &sin.sin_addr)) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
240 struct hostent *hp;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
241 if (!(hp = gethostbyname(dns_params.hostname))) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
242 write(child_out, &h_errno, sizeof(int));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
243 close(child_out);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
244 if (show_debug)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
245 printf("DNS Error: %d\n", h_errno);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
246 _exit(0);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
247 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
248 memset(&sin, 0, sizeof(struct sockaddr_in));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
249 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
250 sin.sin_family = hp->h_addrtype;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
251 } else
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
252 sin.sin_family = AF_INET;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
253
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
254 sin.sin_port = htons(dns_params.port);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
255 write(child_out, &addrlen, sizeof(addrlen));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
256 write(child_out, &sin, addrlen);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
257 write(child_out, &zero, sizeof(zero));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
258 #endif
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
259 dns_params.hostname[0] = '\0';
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
260 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
261
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
262 close(child_out);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
263 close(child_in);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
264
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
265 _exit(0);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
266 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
267 /*
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
268 * End the DNS resolver child process functions.
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
269 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
270
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
271 /*
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
272 * Begin the functions for dealing with the DNS child processes.
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
273 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
274 static void
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
275 cope_with_gdb_brokenness()
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
276 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
277 #ifdef __linux__
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
278 static gboolean already_done = FALSE;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
279 char s[256], e[512];
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
280 int n;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
281 pid_t ppid;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
282
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
283 if(already_done)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
284 return;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
285 already_done = TRUE;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
286 ppid = getppid();
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
287 snprintf(s, sizeof(s), "/proc/%d/exe", ppid);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
288 n = readlink(s, e, sizeof(e));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
289 if(n < 0)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
290 return;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
291
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
292 e[MIN(n,sizeof(e)-1)] = '\0';
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
293
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
294 if(strstr(e,"gdb")) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
295 gaim_debug_info("dns",
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
296 "Debugger detected, performing useless query...\n");
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
297 gethostbyname("x.x.x.x.x");
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
298 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
299 #endif
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
300 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
301
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
302 static void
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
303 gaim_dnsquery_resolver_destroy(GaimDnsQueryResolverProcess *resolver)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
304 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
305 g_return_if_fail(resolver != NULL);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
306
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
307 /*
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
308 * We might as well attempt to kill our child process. It really
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
309 * doesn't matter if this fails, because children will expire on
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
310 * their own after a few seconds.
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
311 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
312 if (resolver->dns_pid > 0)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
313 kill(resolver->dns_pid, SIGKILL);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
314
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
315 if (resolver->inpa != 0)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
316 gaim_input_remove(resolver->inpa);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
317
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
318 close(resolver->fd_in);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
319 close(resolver->fd_out);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
320
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
321 g_free(resolver);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
322
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
323 number_of_dns_children--;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
324 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
325
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
326 static GaimDnsQueryResolverProcess *
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
327 gaim_dnsquery_resolver_new(gboolean show_debug)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
328 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
329 GaimDnsQueryResolverProcess *resolver;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
330 int child_out[2], child_in[2];
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
331
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
332 /* Create pipes for communicating with the child process */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
333 if (pipe(child_out) || pipe(child_in)) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
334 gaim_debug_error("dns",
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
335 "Could not create pipes: %s\n", strerror(errno));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
336 return NULL;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
337 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
338
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
339 resolver = g_new(GaimDnsQueryResolverProcess, 1);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
340 resolver->inpa = 0;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
341
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
342 cope_with_gdb_brokenness();
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
343
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
344 /* "Go fork and multiply." --Tommy Caldwell (Emily's dad, not the climber) */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
345 resolver->dns_pid = fork();
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
346
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
347 /* If we are the child process... */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
348 if (resolver->dns_pid == 0) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
349 /* We should not access the parent's side of the pipes, so close them */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
350 close(child_out[0]);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
351 close(child_in[1]);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
352
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
353 gaim_dnsquery_resolver_run(child_out[1], child_in[0], show_debug);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
354 /* The thread calls _exit() rather than returning, so we never get here */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
355 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
356
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
357 /* We should not access the child's side of the pipes, so close them */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
358 close(child_out[1]);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
359 close(child_in[0]);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
360 if (resolver->dns_pid == -1) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
361 gaim_debug_error("dns",
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
362 "Could not create child process for DNS: %s\n",
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
363 strerror(errno));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
364 gaim_dnsquery_resolver_destroy(resolver);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
365 return NULL;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
366 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
367
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
368 resolver->fd_out = child_out[0];
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
369 resolver->fd_in = child_in[1];
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
370 number_of_dns_children++;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
371 gaim_debug_info("dns",
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
372 "Created new DNS child %d, there are now %d children.\n",
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
373 resolver->dns_pid, number_of_dns_children);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
374
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
375 return resolver;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
376 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
377
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
378 /**
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
379 * @return TRUE if the request was sent succesfully. FALSE
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
380 * if the request could not be sent. This isn't
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
381 * necessarily an error. If the child has expired,
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
382 * for example, we won't be able to send the message.
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
383 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
384 static gboolean
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
385 send_dns_request_to_child(GaimDnsQueryData *query_data,
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
386 GaimDnsQueryResolverProcess *resolver)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
387 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
388 pid_t pid;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
389 dns_params_t dns_params;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
390 int rc;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
391 char ch;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
392
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
393 /* This waitpid might return the child's PID if it has recently
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
394 * exited, or it might return an error if it exited "long
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
395 * enough" ago that it has already been reaped; in either
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
396 * instance, we can't use it. */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
397 pid = waitpid(resolver->dns_pid, NULL, WNOHANG);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
398 if (pid > 0) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
399 gaim_debug_warning("dns", "DNS child %d no longer exists\n",
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
400 resolver->dns_pid);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
401 gaim_dnsquery_resolver_destroy(resolver);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
402 return FALSE;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
403 } else if (pid < 0) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
404 gaim_debug_warning("dns", "Wait for DNS child %d failed: %s\n",
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
405 resolver->dns_pid, strerror(errno));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
406 gaim_dnsquery_resolver_destroy(resolver);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
407 return FALSE;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
408 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
409
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
410 /* Copy the hostname and port into a single data structure */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
411 strncpy(dns_params.hostname, query_data->hostname, sizeof(dns_params.hostname) - 1);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
412 dns_params.hostname[sizeof(dns_params.hostname) - 1] = '\0';
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
413 dns_params.port = query_data->port;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
414
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
415 /* Send the data structure to the child */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
416 rc = write(resolver->fd_in, &dns_params, sizeof(dns_params));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
417 if (rc < 0) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
418 gaim_debug_error("dns", "Unable to write to DNS child %d: %d\n",
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
419 resolver->dns_pid, strerror(errno));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
420 gaim_dnsquery_resolver_destroy(resolver);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
421 return FALSE;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
422 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
423
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
424 g_return_val_if_fail(rc == sizeof(dns_params), -1);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
425
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
426 /* Did you hear me? (This avoids some race conditions) */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
427 rc = read(resolver->fd_out, &ch, sizeof(ch));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
428 if (rc != 1 || ch != 'Y')
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
429 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
430 gaim_debug_warning("dns",
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
431 "DNS child %d not responding. Killing it!\n",
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
432 resolver->dns_pid);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
433 gaim_dnsquery_resolver_destroy(resolver);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
434 return FALSE;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
435 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
436
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
437 gaim_debug_info("dns",
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
438 "Successfully sent DNS request to child %d\n",
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
439 resolver->dns_pid);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
440
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
441 query_data->resolver = resolver;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
442
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
443 return TRUE;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
444 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
445
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
446 static void host_resolved(gpointer data, gint source, GaimInputCondition cond);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
447
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
448 static void
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
449 handle_next_queued_request()
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
450 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
451 GaimDnsQueryData *query_data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
452 GaimDnsQueryResolverProcess *resolver;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
453
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
454 if ((queued_requests == NULL) || (g_queue_is_empty(queued_requests)))
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
455 /* No more DNS queries, yay! */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
456 return;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
457
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
458 query_data = g_queue_pop_head(queued_requests);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
459
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
460 /*
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
461 * If we have any children, attempt to have them perform the DNS
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
462 * query. If we're able to send the query then resolver will be
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
463 * set to the GaimDnsQueryResolverProcess. Otherwise, resolver
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
464 * will be NULL and we'll need to create a new DNS request child.
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
465 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
466 while (free_dns_children != NULL)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
467 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
468 resolver = free_dns_children->data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
469 free_dns_children = g_slist_remove(free_dns_children, resolver);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
470
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
471 if (send_dns_request_to_child(query_data, resolver))
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
472 /* We found an acceptable child, yay */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
473 break;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
474 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
475
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
476 /* We need to create a new DNS request child */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
477 if (query_data->resolver == NULL)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
478 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
479 if (number_of_dns_children >= MAX_DNS_CHILDREN)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
480 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
481 /* Apparently all our children are busy */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
482 g_queue_push_head(queued_requests, query_data);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
483 return;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
484 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
485
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
486 resolver = gaim_dnsquery_resolver_new(gaim_debug_is_enabled());
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
487 if (resolver == NULL)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
488 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
489 gaim_dnsquery_failed(query_data, _("Unable to create new resolver process\n"));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
490 return;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
491 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
492 if (!send_dns_request_to_child(query_data, resolver))
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
493 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
494 gaim_dnsquery_failed(query_data, _("Unable to send request to resolver process\n"));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
495 return;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
496 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
497 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
498
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
499 query_data->resolver->inpa = gaim_input_add(query_data->resolver->fd_out,
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
500 GAIM_INPUT_READ, host_resolved, query_data);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
501 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
502
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
503 /*
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
504 * End the functions for dealing with the DNS child processes.
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
505 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
506
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
507 static void
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
508 host_resolved(gpointer data, gint source, GaimInputCondition cond)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
509 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
510 GaimDnsQueryData *query_data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
511 int rc, err;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
512 GSList *hosts = NULL;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
513 struct sockaddr *addr = NULL;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
514 size_t addrlen;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
515 char message[1024];
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
516
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
517 query_data = data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
518
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
519 gaim_debug_info("dns", "Got response for '%s'\n", query_data->hostname);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
520 gaim_input_remove(query_data->resolver->inpa);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
521 query_data->resolver->inpa = 0;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
522
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
523 rc = read(query_data->resolver->fd_out, &err, sizeof(err));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
524 if ((rc == 4) && (err != 0))
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
525 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
526 #ifdef HAVE_GETADDRINFO
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14358
diff changeset
527 g_snprintf(message, sizeof(message), _("Error resolving %s:\n%s"),
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
528 query_data->hostname, gai_strerror(err));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
529 #else
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
530 g_snprintf(message, sizeof(message), _("Error resolving %s: %d"),
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
531 query_data->hostname, err);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
532 #endif
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
533 gaim_dnsquery_failed(query_data, message);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
534
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
535 } else if (rc > 0) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
536 /* Success! */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
537 while (rc > 0) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
538 rc = read(query_data->resolver->fd_out, &addrlen, sizeof(addrlen));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
539 if (rc > 0 && addrlen > 0) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
540 addr = g_malloc(addrlen);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
541 rc = read(query_data->resolver->fd_out, addr, addrlen);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
542 hosts = g_slist_append(hosts, GINT_TO_POINTER(addrlen));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
543 hosts = g_slist_append(hosts, addr);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
544 } else {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
545 break;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
546 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
547 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
548 /* wait4(resolver->dns_pid, NULL, WNOHANG, NULL); */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
549 gaim_dnsquery_resolved(query_data, hosts);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
550
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
551 } else if (rc == -1) {
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14358
diff changeset
552 g_snprintf(message, sizeof(message), _("Error reading from resolver process:\n%s"), strerror(errno));
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
553 gaim_dnsquery_failed(query_data, message);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
554
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
555 } else if (rc == 0) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
556 g_snprintf(message, sizeof(message), _("EOF while reading from resolver process"));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
557 gaim_dnsquery_failed(query_data, message);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
558 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
559
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
560 handle_next_queued_request();
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
561 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
562
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
563 static gboolean
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
564 resolve_host(gpointer data)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
565 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
566 GaimDnsQueryData *query_data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
567
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
568 query_data = data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
569 query_data->timeout = 0;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
570
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
571 handle_next_queued_request();
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
572
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
573 return FALSE;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
574 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
575
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
576 GaimDnsQueryData *
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
577 gaim_dnsquery_a(const char *hostname, int port,
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
578 GaimDnsQueryConnectFunction callback, gpointer data)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
579 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
580 GaimDnsQueryData *query_data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
581
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
582 g_return_val_if_fail(hostname != NULL, NULL);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
583 g_return_val_if_fail(port != 0, NULL);
14358
fdf65b672b87 [gaim-migrate @ 17064]
Mark Doliner <mark@kingant.net>
parents: 14287
diff changeset
584 g_return_val_if_fail(callback != NULL, NULL);
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
585
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
586 query_data = g_new(GaimDnsQueryData, 1);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
587 query_data->hostname = g_strdup(hostname);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
588 g_strstrip(query_data->hostname);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
589 query_data->port = port;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
590 query_data->callback = callback;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
591 query_data->data = data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
592 query_data->resolver = NULL;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
593
14466
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
594 if (strlen(query_data->hostname) == 0)
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
595 {
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
596 gaim_dnsquery_destroy(query_data);
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
597 g_return_val_if_reached(NULL);
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
598 }
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
599
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
600 if (!queued_requests)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
601 queued_requests = g_queue_new();
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
602 g_queue_push_tail(queued_requests, query_data);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
603
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
604 gaim_debug_info("dns", "DNS query for '%s' queued\n", query_data->hostname);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
605
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
606 query_data->timeout = gaim_timeout_add(0, resolve_host, query_data);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
607
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
608 return query_data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
609 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
610
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
611 #elif defined _WIN32 /* end __unix__ || __APPLE__ */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
612
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
613 /*
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
614 * Windows!
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
615 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
616
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
617 static gboolean
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
618 dns_main_thread_cb(gpointer data)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
619 {
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
620 GaimDnsQueryData *query_data;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
621
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
622 query_data = data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
623
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
624 if (query_data->error_message != NULL)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
625 gaim_dnsquery_failed(query_data, query_data->error_message);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
626 else
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
627 {
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
628 GSList *hosts;
14244
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
629
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
630 /* We don't want gaim_dns_query_resolved() to free(hosts) */
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
631 hosts = query_data->hosts;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
632 query_data->hosts = NULL;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
633 gaim_dnsquery_resolved(query_data, hosts);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
634 }
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
635
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
636 return FALSE;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
637 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
638
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
639 static gpointer
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
640 dns_thread(gpointer data)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
641 {
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
642 GaimDnsQueryData *query_data;
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
643 #ifdef HAVE_GETADDRINFO
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
644 int rc;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
645 struct addrinfo hints, *res, *tmp;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
646 char servname[20];
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
647 #else
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
648 struct sockaddr_in sin;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
649 struct hostent *hp;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
650 #endif
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
651
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
652 query_data = data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
653
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
654 #ifdef HAVE_GETADDRINFO
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
655 g_snprintf(servname, sizeof(servname), "%d", query_data->port);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
656 memset(&hints,0,sizeof(hints));
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
657
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
658 /*
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
659 * This is only used to convert a service
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
660 * name to a port number. As we know we are
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
661 * passing a number already, we know this
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
662 * value will not be really used by the C
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
663 * library.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
664 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
665 hints.ai_socktype = SOCK_STREAM;
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
666 if ((rc = getaddrinfo(query_data->hostname, servname, &hints, &res)) == 0) {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
667 tmp = res;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
668 while(res) {
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
669 query_data->hosts = g_slist_append(query_data->hosts,
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
670 GSIZE_TO_POINTER(res->ai_addrlen));
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
671 query_data->hosts = g_slist_append(query_data->hosts,
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
672 g_memdup(res->ai_addr, res->ai_addrlen));
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
673 res = res->ai_next;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
674 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
675 freeaddrinfo(tmp);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
676 } else {
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14358
diff changeset
677 query_data->error_message = g_strdup_printf(_("Error resolving %s:\n%s"), query_data->hostname, gai_strerror(rc));
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
678 }
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
679 #else
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
680 if ((hp = gethostbyname(query_data->hostname))) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
681 memset(&sin, 0, sizeof(struct sockaddr_in));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
682 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
683 sin.sin_family = hp->h_addrtype;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
684 sin.sin_port = htons(query_data->port);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
685
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
686 query_data->hosts = g_slist_append(query_data->hosts,
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
687 GSIZE_TO_POINTER(sizeof(sin)));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
688 query_data->hosts = g_slist_append(query_data->hosts,
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
689 g_memdup(&sin, sizeof(sin)));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
690 } else {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
691 query_data->error_message = g_strdup_printf(_("Error resolving %s: %d"), query_data->hostname, h_errno);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
692 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
693 #endif
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
694
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
695 /* back to main thread */
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
696 g_idle_add(dns_main_thread_cb, query_data);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
697
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
698 return 0;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
699 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
700
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
701 static gboolean
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
702 resolve_host(gpointer data)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
703 {
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
704 GaimDnsQueryData *query_data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
705 struct sockaddr_in sin;
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
706 GError *err = NULL;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
707
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
708 query_data = data;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
709 query_data->timeout = 0;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
710
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
711 if (inet_aton(query_data->hostname, &sin.sin_addr))
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
712 {
14244
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
713 /*
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
714 * The given "hostname" is actually an IP address, so we
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
715 * don't need to do anything.
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
716 */
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
717 GSList *hosts = NULL;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
718 sin.sin_family = AF_INET;
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
719 sin.sin_port = htons(query_data->port);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
720 hosts = g_slist_append(hosts, GINT_TO_POINTER(sizeof(sin)));
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
721 hosts = g_slist_append(hosts, g_memdup(&sin, sizeof(sin)));
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
722 gaim_dnsquery_resolved(query_data, hosts);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
723 }
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
724 else
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
725 {
14244
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
726 /*
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
727 * Spin off a separate thread to perform the DNS lookup so
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
728 * that we don't block the UI.
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
729 */
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
730 query_data->resolver = g_thread_create(dns_thread,
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
731 query_data, FALSE, &err);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
732 if (query_data->resolver == NULL)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
733 {
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
734 char message[1024];
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
735 g_snprintf(message, sizeof(message), _("Thread creation failure: %s"),
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
736 err ? err->message : _("Unknown reason"));
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
737 g_error_free(err);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
738 gaim_dnsquery_failed(query_data, message);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
739 }
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
740 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
741
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
742 return FALSE;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
743 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
744
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
745 GaimDnsQueryData *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
746 gaim_dnsquery_a(const char *hostname, int port,
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
747 GaimDnsQueryConnectFunction callback, gpointer data)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
748 {
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
749 GaimDnsQueryData *query_data;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
750
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
751 g_return_val_if_fail(hostname != NULL, NULL);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
752 g_return_val_if_fail(port != 0, NULL);
14358
fdf65b672b87 [gaim-migrate @ 17064]
Mark Doliner <mark@kingant.net>
parents: 14287
diff changeset
753 g_return_val_if_fail(callback != NULL, NULL);
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
754
14244
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
755 gaim_debug_info("dnsquery", "Performing DNS lookup for %s\n", hostname);
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
756
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
757 query_data = g_new(GaimDnsQueryData, 1);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
758 query_data->hostname = g_strdup(hostname);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
759 g_strstrip(query_data->hostname);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
760 query_data->port = port;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
761 query_data->callback = callback;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
762 query_data->data = data;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
763 query_data->error_message = NULL;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
764 query_data->hosts = NULL;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
765
14466
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
766 if (strlen(query_data->hostname) == 0)
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
767 {
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
768 gaim_dnsquery_destroy(query_data);
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
769 g_return_val_if_reached(NULL);
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
770 }
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
771
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
772 /* Don't call the callback before returning */
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
773 query_data->timeout = gaim_timeout_add(0, resolve_host, query_data);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
774
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
775 return query_data;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
776 }
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
777
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
778 #else /* not __unix__ or __APPLE__ or _WIN32 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
779
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
780 /*
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
781 * We weren't able to do anything fancier above, so use the
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
782 * fail-safe name resolution code, which is blocking.
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
783 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
784
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
785 static gboolean
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
786 resolve_host(gpointer data)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
787 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
788 GaimDnsQueryData *query_data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
789 struct sockaddr_in sin;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
790 GSList *hosts = NULL;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
791
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
792 query_data = data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
793 query_data->timeout = 0;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
794
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
795 if (!inet_aton(query_data->hostname, &sin.sin_addr)) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
796 struct hostent *hp;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
797 if(!(hp = gethostbyname(query_data->hostname))) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
798 char message[1024];
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
799 g_snprintf(message, sizeof(message), _("Error resolving %s: %d"),
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
800 query_data->hostname, h_errno);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
801 gaim_dnsquery_failed(query_data, message);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
802 return FALSE;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
803 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
804 memset(&sin, 0, sizeof(struct sockaddr_in));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
805 memcpy(&sin.sin_addr.s_addr, hp->h_addr, hp->h_length);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
806 sin.sin_family = hp->h_addrtype;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
807 } else
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
808 sin.sin_family = AF_INET;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
809 sin.sin_port = htons(query_data->port);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
810
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
811 hosts = g_slist_append(hosts, GINT_TO_POINTER(sizeof(sin)));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
812 hosts = g_slist_append(hosts, g_memdup(&sin, sizeof(sin)));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
813
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
814 gaim_dnsquery_resolved(query_data, hosts);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
815
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
816 return FALSE;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
817 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
818
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
819 GaimDnsQueryData *
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
820 gaim_dnsquery_a(const char *hostname, int port,
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
821 GaimDnsQueryConnectFunction callback, gpointer data)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
822 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
823 GaimDnsQueryData *query_data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
824
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
825 g_return_val_if_fail(hostname != NULL, NULL);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
826 g_return_val_if_fail(port != 0, NULL);
14466
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
827 g_return_val_if_fail(callback != NULL, NULL);
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
828
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
829 query_data = g_new(GaimDnsQueryData, 1);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
830 query_data->hostname = g_strdup(hostname);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
831 g_strstrip(query_data->hostname);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
832 query_data->port = port;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
833 query_data->callback = callback;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
834 query_data->data = data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
835
14466
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
836 if (strlen(query_data->hostname) == 0)
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
837 {
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
838 gaim_dnsquery_destroy(query_data);
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
839 g_return_val_if_reached(NULL);
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
840 }
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
841
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
842 /* Don't call the callback before returning */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
843 query_data->timeout = gaim_timeout_add(0, resolve_host, query_data);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
844
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
845 return query_data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
846 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
847
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
848 #endif /* not __unix__ or __APPLE__ or _WIN32 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
849
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
850 void
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
851 gaim_dnsquery_destroy(GaimDnsQueryData *query_data)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
852 {
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
853 #if defined(__unix__) || defined(__APPLE__)
14510
1d73e11d8787 [gaim-migrate @ 17230]
Mark Doliner <mark@kingant.net>
parents: 14466
diff changeset
854 g_queue_remove(queued_requests, query_data);
1d73e11d8787 [gaim-migrate @ 17230]
Mark Doliner <mark@kingant.net>
parents: 14466
diff changeset
855
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
856 if (query_data->resolver != NULL)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
857 /*
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
858 * Ideally we would tell our resolver child to stop resolving
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
859 * shit and then we would add it back to the free_dns_children
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
860 * linked list. However, it's hard to tell children stuff,
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
861 * they just don't listen.
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
862 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
863 gaim_dnsquery_resolver_destroy(query_data->resolver);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
864 #elif defined _WIN32 /* end __unix__ || __APPLE__ */
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
865 if (query_data->resolver != NULL)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
866 {
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
867 /*
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
868 * It's not really possible to kill a thread. So instead we
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
869 * just set the callback to NULL and let the DNS lookup
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
870 * finish.
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
871 */
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
872 query_data->callback = NULL;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
873 return;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
874 }
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
875
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
876 while (query_data->hosts != NULL)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
877 {
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
878 /* Discard the length... */
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
879 query_data->hosts = g_slist_remove(query_data->hosts, query_data->hosts->data);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
880 /* Free the address... */
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
881 g_free(query_data->hosts->data);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
882 query_data->hosts = g_slist_remove(query_data->hosts, query_data->hosts->data);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
883 }
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
884 g_free(query_data->error_message);
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
885 #endif
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
886
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
887 if (query_data->timeout > 0)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
888 gaim_timeout_remove(query_data->timeout);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
889
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
890 g_free(query_data->hostname);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
891 g_free(query_data);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
892 }
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
893
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
894 void
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
895 gaim_dnsquery_init(void)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
896 {
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
897 #ifdef _WIN32
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
898 if (!g_thread_supported())
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
899 g_thread_init(NULL);
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
900 #endif
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
901 }
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
902
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
903 void
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
904 gaim_dnsquery_uninit(void)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
905 {
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
906 #if defined(__unix__) || defined(__APPLE__)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
907 while (free_dns_children != NULL)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
908 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
909 gaim_dnsquery_resolver_destroy(free_dns_children->data);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
910 free_dns_children = g_slist_remove(free_dns_children, free_dns_children->data);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
911 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
912 #endif
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
913 }