annotate libgaim/dnsquery.c @ 15155:ff431329a01b

[gaim-migrate @ 17941] Update Bonjour to use Evan's snazzy new notify_user_info stuff committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 10 Dec 2006 09:02:48 +0000
parents 51685370de57
children 5e7764d15345
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;
14649
4ee6553079b5 [gaim-migrate @ 17395]
Mark Doliner <mark@kingant.net>
parents: 14510
diff changeset
70 static GSList *queued_requests = NULL;
14287
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
14649
4ee6553079b5 [gaim-migrate @ 17395]
Mark Doliner <mark@kingant.net>
parents: 14510
diff changeset
454 if (queued_requests == NULL)
14287
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
14649
4ee6553079b5 [gaim-migrate @ 17395]
Mark Doliner <mark@kingant.net>
parents: 14510
diff changeset
458 query_data = queued_requests->data;
4ee6553079b5 [gaim-migrate @ 17395]
Mark Doliner <mark@kingant.net>
parents: 14510
diff changeset
459 queued_requests = g_slist_delete_link(queued_requests, queued_requests);
14287
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 /*
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
462 * 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
463 * 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
464 * set to the GaimDnsQueryResolverProcess. Otherwise, resolver
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
465 * 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
466 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
467 while (free_dns_children != NULL)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
468 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
469 resolver = free_dns_children->data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
470 free_dns_children = g_slist_remove(free_dns_children, resolver);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
471
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
472 if (send_dns_request_to_child(query_data, resolver))
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
473 /* We found an acceptable child, yay */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
474 break;
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
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
477 /* We need to create a new DNS request child */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
478 if (query_data->resolver == NULL)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
479 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
480 if (number_of_dns_children >= MAX_DNS_CHILDREN)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
481 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
482 /* Apparently all our children are busy */
14649
4ee6553079b5 [gaim-migrate @ 17395]
Mark Doliner <mark@kingant.net>
parents: 14510
diff changeset
483 queued_requests = g_slist_prepend(queued_requests, query_data);
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
484 return;
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
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
487 resolver = gaim_dnsquery_resolver_new(gaim_debug_is_enabled());
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
488 if (resolver == NULL)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
489 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
490 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
491 return;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
492 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
493 if (!send_dns_request_to_child(query_data, resolver))
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
494 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
495 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
496 return;
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
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
500 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
501 GAIM_INPUT_READ, host_resolved, query_data);
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 /*
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
505 * End the functions for dealing with the DNS child processes.
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
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
508 static void
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
509 host_resolved(gpointer data, gint source, GaimInputCondition cond)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
510 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
511 GaimDnsQueryData *query_data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
512 int rc, err;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
513 GSList *hosts = NULL;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
514 struct sockaddr *addr = NULL;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
515 size_t addrlen;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
516 char message[1024];
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
517
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
518 query_data = data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
519
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
520 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
521 gaim_input_remove(query_data->resolver->inpa);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
522 query_data->resolver->inpa = 0;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
523
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
524 rc = read(query_data->resolver->fd_out, &err, sizeof(err));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
525 if ((rc == 4) && (err != 0))
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
526 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
527 #ifdef HAVE_GETADDRINFO
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14358
diff changeset
528 g_snprintf(message, sizeof(message), _("Error resolving %s:\n%s"),
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
529 query_data->hostname, gai_strerror(err));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
530 #else
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
531 g_snprintf(message, sizeof(message), _("Error resolving %s: %d"),
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
532 query_data->hostname, err);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
533 #endif
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
534 gaim_dnsquery_failed(query_data, message);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
535
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
536 } else if (rc > 0) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
537 /* Success! */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
538 while (rc > 0) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
539 rc = read(query_data->resolver->fd_out, &addrlen, sizeof(addrlen));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
540 if (rc > 0 && addrlen > 0) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
541 addr = g_malloc(addrlen);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
542 rc = read(query_data->resolver->fd_out, addr, addrlen);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
543 hosts = g_slist_append(hosts, GINT_TO_POINTER(addrlen));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
544 hosts = g_slist_append(hosts, addr);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
545 } else {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
546 break;
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 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
549 /* wait4(resolver->dns_pid, NULL, WNOHANG, NULL); */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
550 gaim_dnsquery_resolved(query_data, hosts);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
551
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
552 } else if (rc == -1) {
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14358
diff changeset
553 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
554 gaim_dnsquery_failed(query_data, message);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
555
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
556 } else if (rc == 0) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
557 g_snprintf(message, sizeof(message), _("EOF while reading from resolver process"));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
558 gaim_dnsquery_failed(query_data, message);
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
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
561 handle_next_queued_request();
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
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
564 static gboolean
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
565 resolve_host(gpointer data)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
566 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
567 GaimDnsQueryData *query_data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
568
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
569 query_data = data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
570 query_data->timeout = 0;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
571
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
572 handle_next_queued_request();
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
573
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
574 return FALSE;
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
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
577 GaimDnsQueryData *
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
578 gaim_dnsquery_a(const char *hostname, int port,
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
579 GaimDnsQueryConnectFunction callback, gpointer data)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
580 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
581 GaimDnsQueryData *query_data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
582
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
583 g_return_val_if_fail(hostname != NULL, NULL);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
584 g_return_val_if_fail(port != 0, NULL);
14358
fdf65b672b87 [gaim-migrate @ 17064]
Mark Doliner <mark@kingant.net>
parents: 14287
diff changeset
585 g_return_val_if_fail(callback != NULL, NULL);
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
586
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
587 query_data = g_new(GaimDnsQueryData, 1);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
588 query_data->hostname = g_strdup(hostname);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
589 g_strstrip(query_data->hostname);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
590 query_data->port = port;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
591 query_data->callback = callback;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
592 query_data->data = data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
593 query_data->resolver = NULL;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
594
14466
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
595 if (strlen(query_data->hostname) == 0)
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
596 {
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
597 gaim_dnsquery_destroy(query_data);
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
598 g_return_val_if_reached(NULL);
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
599 }
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
600
14649
4ee6553079b5 [gaim-migrate @ 17395]
Mark Doliner <mark@kingant.net>
parents: 14510
diff changeset
601 queued_requests = g_slist_append(queued_requests, query_data);
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
602
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
603 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
604
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
605 query_data->timeout = gaim_timeout_add(0, resolve_host, query_data);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
606
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
607 return query_data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
608 }
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 #elif defined _WIN32 /* end __unix__ || __APPLE__ */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
611
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 * Windows!
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
614 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
615
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
616 static gboolean
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
617 dns_main_thread_cb(gpointer data)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
618 {
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
619 GaimDnsQueryData *query_data;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
620
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
621 query_data = data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
622
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
623 if (query_data->error_message != NULL)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
624 gaim_dnsquery_failed(query_data, query_data->error_message);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
625 else
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
626 {
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
627 GSList *hosts;
14244
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
628
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
629 /* 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
630 hosts = query_data->hosts;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
631 query_data->hosts = NULL;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
632 gaim_dnsquery_resolved(query_data, hosts);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
633 }
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
634
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
635 return FALSE;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
636 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
637
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
638 static gpointer
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
639 dns_thread(gpointer data)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
640 {
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
641 GaimDnsQueryData *query_data;
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
642 #ifdef HAVE_GETADDRINFO
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
643 int rc;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
644 struct addrinfo hints, *res, *tmp;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
645 char servname[20];
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
646 #else
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
647 struct sockaddr_in sin;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
648 struct hostent *hp;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
649 #endif
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
650
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
651 query_data = data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
652
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
653 #ifdef HAVE_GETADDRINFO
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
654 g_snprintf(servname, sizeof(servname), "%d", query_data->port);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
655 memset(&hints,0,sizeof(hints));
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
656
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
657 /*
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
658 * This is only used to convert a service
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
659 * name to a port number. As we know we are
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
660 * passing a number already, we know this
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
661 * value will not be really used by the C
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
662 * library.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
663 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
664 hints.ai_socktype = SOCK_STREAM;
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
665 if ((rc = getaddrinfo(query_data->hostname, servname, &hints, &res)) == 0) {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
666 tmp = res;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
667 while(res) {
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
668 query_data->hosts = g_slist_append(query_data->hosts,
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
669 GSIZE_TO_POINTER(res->ai_addrlen));
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
670 query_data->hosts = g_slist_append(query_data->hosts,
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
671 g_memdup(res->ai_addr, res->ai_addrlen));
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
672 res = res->ai_next;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
673 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
674 freeaddrinfo(tmp);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
675 } else {
14392
92eb7a040663 [gaim-migrate @ 17099]
Mark Doliner <mark@kingant.net>
parents: 14358
diff changeset
676 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
677 }
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
678 #else
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
679 if ((hp = gethostbyname(query_data->hostname))) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
680 memset(&sin, 0, sizeof(struct sockaddr_in));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
681 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
682 sin.sin_family = hp->h_addrtype;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
683 sin.sin_port = htons(query_data->port);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
684
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
685 query_data->hosts = g_slist_append(query_data->hosts,
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
686 GSIZE_TO_POINTER(sizeof(sin)));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
687 query_data->hosts = g_slist_append(query_data->hosts,
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
688 g_memdup(&sin, sizeof(sin)));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
689 } else {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
690 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
691 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
692 #endif
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
693
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
694 /* back to main thread */
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
695 g_idle_add(dns_main_thread_cb, query_data);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
696
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
697 return 0;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
698 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
699
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
700 static gboolean
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
701 resolve_host(gpointer data)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
702 {
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
703 GaimDnsQueryData *query_data;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
704 struct sockaddr_in sin;
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
705 GError *err = NULL;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
706
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
707 query_data = data;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
708 query_data->timeout = 0;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
709
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
710 if (inet_aton(query_data->hostname, &sin.sin_addr))
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
711 {
14244
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
712 /*
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
713 * The given "hostname" is actually an IP address, so we
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
714 * don't need to do anything.
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
715 */
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
716 GSList *hosts = NULL;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
717 sin.sin_family = AF_INET;
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
718 sin.sin_port = htons(query_data->port);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
719 hosts = g_slist_append(hosts, GINT_TO_POINTER(sizeof(sin)));
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
720 hosts = g_slist_append(hosts, g_memdup(&sin, sizeof(sin)));
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
721 gaim_dnsquery_resolved(query_data, hosts);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
722 }
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
723 else
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
724 {
14244
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
725 /*
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
726 * Spin off a separate thread to perform the DNS lookup so
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
727 * that we don't block the UI.
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
728 */
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
729 query_data->resolver = g_thread_create(dns_thread,
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
730 query_data, FALSE, &err);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
731 if (query_data->resolver == NULL)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
732 {
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
733 char message[1024];
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
734 g_snprintf(message, sizeof(message), _("Thread creation failure: %s"),
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
735 err ? err->message : _("Unknown reason"));
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
736 g_error_free(err);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
737 gaim_dnsquery_failed(query_data, message);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
738 }
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
739 }
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 return FALSE;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
742 }
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 GaimDnsQueryData *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
745 gaim_dnsquery_a(const char *hostname, int port,
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
746 GaimDnsQueryConnectFunction callback, gpointer data)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
747 {
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
748 GaimDnsQueryData *query_data;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
749
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
750 g_return_val_if_fail(hostname != NULL, NULL);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
751 g_return_val_if_fail(port != 0, NULL);
14358
fdf65b672b87 [gaim-migrate @ 17064]
Mark Doliner <mark@kingant.net>
parents: 14287
diff changeset
752 g_return_val_if_fail(callback != NULL, NULL);
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
753
14244
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
754 gaim_debug_info("dnsquery", "Performing DNS lookup for %s\n", hostname);
935f8b258d1b [gaim-migrate @ 16926]
Mark Doliner <mark@kingant.net>
parents: 14238
diff changeset
755
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
756 query_data = g_new(GaimDnsQueryData, 1);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
757 query_data->hostname = g_strdup(hostname);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
758 g_strstrip(query_data->hostname);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
759 query_data->port = port;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
760 query_data->callback = callback;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
761 query_data->data = data;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
762 query_data->error_message = NULL;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
763 query_data->hosts = NULL;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
764
14466
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
765 if (strlen(query_data->hostname) == 0)
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
766 {
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
767 gaim_dnsquery_destroy(query_data);
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
768 g_return_val_if_reached(NULL);
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
769 }
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
770
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
771 /* Don't call the callback before returning */
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
772 query_data->timeout = gaim_timeout_add(0, resolve_host, query_data);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
773
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
774 return query_data;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
775 }
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
776
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
777 #else /* not __unix__ or __APPLE__ or _WIN32 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
778
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 * 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
781 * fail-safe name resolution code, which is blocking.
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
782 */
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 static gboolean
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
785 resolve_host(gpointer data)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
786 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
787 GaimDnsQueryData *query_data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
788 struct sockaddr_in sin;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
789 GSList *hosts = NULL;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
790
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
791 query_data = data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
792 query_data->timeout = 0;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
793
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
794 if (!inet_aton(query_data->hostname, &sin.sin_addr)) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
795 struct hostent *hp;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
796 if(!(hp = gethostbyname(query_data->hostname))) {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
797 char message[1024];
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
798 g_snprintf(message, sizeof(message), _("Error resolving %s: %d"),
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
799 query_data->hostname, h_errno);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
800 gaim_dnsquery_failed(query_data, message);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
801 return FALSE;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
802 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
803 memset(&sin, 0, sizeof(struct sockaddr_in));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
804 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
805 sin.sin_family = hp->h_addrtype;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
806 } else
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
807 sin.sin_family = AF_INET;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
808 sin.sin_port = htons(query_data->port);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
809
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
810 hosts = g_slist_append(hosts, GINT_TO_POINTER(sizeof(sin)));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
811 hosts = g_slist_append(hosts, g_memdup(&sin, sizeof(sin)));
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
812
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
813 gaim_dnsquery_resolved(query_data, hosts);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
814
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
815 return FALSE;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
816 }
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 GaimDnsQueryData *
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
819 gaim_dnsquery_a(const char *hostname, int port,
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
820 GaimDnsQueryConnectFunction callback, gpointer data)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
821 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
822 GaimDnsQueryData *query_data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
823
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
824 g_return_val_if_fail(hostname != NULL, NULL);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
825 g_return_val_if_fail(port != 0, NULL);
14466
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
826 g_return_val_if_fail(callback != NULL, NULL);
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
827
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
828 query_data = g_new(GaimDnsQueryData, 1);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
829 query_data->hostname = g_strdup(hostname);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
830 g_strstrip(query_data->hostname);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
831 query_data->port = port;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
832 query_data->callback = callback;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
833 query_data->data = data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
834
14466
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
835 if (strlen(query_data->hostname) == 0)
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
836 {
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
837 gaim_dnsquery_destroy(query_data);
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
838 g_return_val_if_reached(NULL);
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
839 }
5a09940b88f7 [gaim-migrate @ 17180]
Mark Doliner <mark@kingant.net>
parents: 14392
diff changeset
840
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
841 /* Don't call the callback before returning */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
842 query_data->timeout = gaim_timeout_add(0, resolve_host, query_data);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
843
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
844 return query_data;
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
845 }
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 #endif /* not __unix__ or __APPLE__ or _WIN32 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
848
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
849 void
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
850 gaim_dnsquery_destroy(GaimDnsQueryData *query_data)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
851 {
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
852 #if defined(__unix__) || defined(__APPLE__)
14649
4ee6553079b5 [gaim-migrate @ 17395]
Mark Doliner <mark@kingant.net>
parents: 14510
diff changeset
853 queued_requests = g_slist_remove(queued_requests, query_data);
14510
1d73e11d8787 [gaim-migrate @ 17230]
Mark Doliner <mark@kingant.net>
parents: 14466
diff changeset
854
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
855 if (query_data->resolver != NULL)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
856 /*
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
857 * Ideally we would tell our resolver child to stop resolving
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
858 * 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
859 * linked list. However, it's hard to tell children stuff,
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
860 * they just don't listen.
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
861 */
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
862 gaim_dnsquery_resolver_destroy(query_data->resolver);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
863 #elif defined _WIN32 /* end __unix__ || __APPLE__ */
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
864 if (query_data->resolver != NULL)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
865 {
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 * 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
868 * just set the callback to NULL and let the DNS lookup
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
869 * finish.
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
870 */
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
871 query_data->callback = NULL;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
872 return;
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
873 }
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 while (query_data->hosts != NULL)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
876 {
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
877 /* Discard the length... */
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
878 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
879 /* Free the address... */
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
880 g_free(query_data->hosts->data);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
881 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
882 }
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
883 g_free(query_data->error_message);
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
884 #endif
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
885
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
886 if (query_data->timeout > 0)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
887 gaim_timeout_remove(query_data->timeout);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
888
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
889 g_free(query_data->hostname);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
890 g_free(query_data);
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
891 }
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 void
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
894 gaim_dnsquery_init(void)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
895 {
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
896 }
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
897
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
898 void
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
899 gaim_dnsquery_uninit(void)
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
900 {
14287
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
901 #if defined(__unix__) || defined(__APPLE__)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
902 while (free_dns_children != NULL)
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
903 {
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
904 gaim_dnsquery_resolver_destroy(free_dns_children->data);
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
905 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
906 }
e01a8316b08b [gaim-migrate @ 16974]
Mark Doliner <mark@kingant.net>
parents: 14263
diff changeset
907 #endif
14238
f189327b9968 [gaim-migrate @ 16920]
Mark Doliner <mark@kingant.net>
parents: 14192
diff changeset
908 }